Skip to content

Commit

Permalink
Port remaining tests and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-chambers committed Jan 4, 2024
1 parent abd47f4 commit 4e5ccfe
Show file tree
Hide file tree
Showing 23 changed files with 1,616 additions and 15 deletions.
3 changes: 2 additions & 1 deletion ndc-lambda-sdk/.mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"test/**/*.test.ts"
],
"watch-files": [
"src"
"src",
"test"
]
}
73 changes: 72 additions & 1 deletion ndc-lambda-sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion ndc-lambda-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
"@types/chai": "^4.3.11",
"@types/mocha": "^10.0.6",
"chai": "^4.3.7",
"mocha": "^10.2.0"
"mocha": "^10.2.0",
"node-emoji": "^2.1.3",
"node-postgres": "^0.6.2"
}
}
2 changes: 1 addition & 1 deletion ndc-lambda-sdk/src/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function resolveArgumentValues(args: Record<string, sdk.Argument>, variableValue
});
}

function prepareArguments(args: Record<string, unknown>, functionDefinition: schema.FunctionDefinition, objectTypes: schema.ObjectTypeDefinitions): unknown[] {
export function prepareArguments(args: Record<string, unknown>, functionDefinition: schema.FunctionDefinition, objectTypes: schema.ObjectTypeDefinitions): unknown[] {
return functionDefinition.arguments.map(argDef => coerceArgumentValue(args[argDef.argumentName], argDef.type, [argDef.argumentName], objectTypes));
}

Expand Down
14 changes: 9 additions & 5 deletions ndc-lambda-sdk/src/inference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ function deriveSchemaTypeIfNullableType(tsType: ts.Type, typePath: TypePathSegme
function deriveSchemaTypeIfObjectType(tsType: ts.Type, typePath: TypePathSegment[], context: TypeDerivationContext, recursionDepth: number): Result<DerivedSchemaType, string[]> | undefined {
const info = getObjectTypeInfo(tsType, typePath, context.typeChecker, context.functionsFilePath);
if (info) {
// Shortcut recursion if the type has already been named
// Short-circuit recursion if the type has already been named
if (context.objectTypeDefinitions[info.generatedTypeName]) {
return new Ok({ typeDefinition: { type: 'named', name: info.generatedTypeName, kind: "object" }, warnings: [] });
}
Expand All @@ -316,10 +316,14 @@ function deriveSchemaTypeIfObjectType(tsType: ts.Type, typePath: TypePathSegment
});
});

return propertyResults.map(properties => {
context.objectTypeDefinitions[info.generatedTypeName] = { properties }
return { typeDefinition: { type: 'named', name: info.generatedTypeName, kind: "object" }, warnings }
})
if (propertyResults instanceof Ok) {
context.objectTypeDefinitions[info.generatedTypeName] = { properties: propertyResults.data }
return new Ok({ typeDefinition: { type: 'named', name: info.generatedTypeName, kind: "object" }, warnings })
} else {
// Remove the recursion short-circuit to ensure errors are raised if this type is encountered again
delete context.objectTypeDefinitions[info.generatedTypeName];
return new Err(propertyResults.error);
}
}
}

Expand Down
Loading

0 comments on commit 4e5ccfe

Please sign in to comment.