Skip to content

Commit

Permalink
minor fix post rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
psubram3 committed Nov 25, 2024
1 parent 574a0cd commit 6edace6
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/packages/external-source/external-source.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Express, Request, Response } from 'express';
import type {
DerivationGroupInsertInput,
ExternalSourceTypeInsertInput,
CreateExternalSourceResponse,
ExternalEventTypeInsertInput,
ExternalEvent,
ExternalSourceInsertInput,
CreateExternalSourceEventTypeResponse,
GetSourceEventTypeAttributeSchemasResponse,
AttributeSchema,
DerivationGroupInsertInput,
ExternalSourceInsertInput,
} from '../../types/external-source.js';
import Ajv from 'ajv';
import { getEnv } from '../../env.js';
Expand All @@ -33,7 +33,7 @@ const refreshLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
});

export function updateSchemaWithDefs(defs: { event_types: any, source_type: any }) {//: Ajv.ValidateFunction | undefined {
export function updateSchemaWithDefs(defs: { event_types: any, source_type: any }): Ajv.ValidateFunction {
// build if statement
const ifThenElse: { [key: string]: any } = {

Expand Down Expand Up @@ -172,6 +172,7 @@ async function uploadExternalSourceEventTypes(req: Request, res: Response) {
}

logger.info(`POST /uploadExternalSourceEventTypes: Uploaded attribute schema(s) are VALID`);
console.log(parsedEventTypes, parsedSourceTypes);

Check failure

Code scanning / CodeQL

Use of externally-controlled format string High

Format string depends on a
user-provided value
.

// extract the external sources and event types
const externalSourceTypeInput: ExternalSourceTypeInsertInput[] = [];
Expand All @@ -180,15 +181,15 @@ async function uploadExternalSourceEventTypes(req: Request, res: Response) {
const event_type_keys = Object.keys(parsedEventTypes);
for (const external_event_type of event_type_keys) {
externalEventTypeInput.push({
attribute_schema: event_types[external_event_type],
attribute_schema: parsedEventTypes[external_event_type],
name: external_event_type
})
}

const source_type_keys = Object.keys(parsedSourceTypes);
for (const external_source_type of source_type_keys) {
externalSourceTypeInput.push({
attribute_schema: source_types[external_source_type],
attribute_schema: parsedSourceTypes[external_source_type],
name: external_source_type
})
}
Expand Down Expand Up @@ -280,7 +281,7 @@ async function uploadExternalSource(req: Request, res: Response) {
});

const attributeSchemaJson = await attributeSchemas.json();
const { external_event_type, external_source_type } = attributeSchemaJson.data;
const { external_event_type, external_source_type } = attributeSchemaJson.data as GetSourceEventTypeAttributeSchemasResponse;

if (external_event_type.length === 0 || external_source_type.length === 0) {
logger.error(
Expand All @@ -290,18 +291,17 @@ async function uploadExternalSource(req: Request, res: Response) {
return;
}

const defs: { event_types: any, source_type: any } = {
event_types: {

const { external_event_type, external_source_type } = attributeSchemaJson.data as GetSourceEventTypeAttributeSchemasResponse;
const eventTypeNamesMappedToSchemas = external_event_type.reduce((acc: Record<string, AttributeSchema>, eventType: ExternalEventTypeInsertInput ) => {
acc[eventType.name] = eventType.attribute_schema;
return acc;
}, {});
const sourceTypeNamesMappedToSchemas = external_source_type.reduce((acc: Record<string, AttributeSchema>, sourceType: ExternalSourceTypeInsertInput ) => {
acc[sourceType.name] = sourceType.attribute_schema;
return acc;
}, {});
}, {});

console.log(external_event_type, external_source_type)
console.log(eventTypeNamesMappedToSchemas, sourceTypeNamesMappedToSchemas)

// Assemble megaschema from attribute schemas
const compiledExternalSourceMegaschema: Ajv.ValidateFunction = updateSchemaWithDefs({ event_types: eventTypeNamesMappedToSchemas, source_type: sourceTypeNamesMappedToSchemas });
Expand Down

0 comments on commit 6edace6

Please sign in to comment.