From 0bdbd677f4f6bda830b26bca0c5490ed4f69204d Mon Sep 17 00:00:00 2001 From: Syd Amir Date: Tue, 16 Jul 2024 23:41:33 +0330 Subject: [PATCH 1/4] :arrow_up: upgrade superstruct --- src/npmDeps.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/npmDeps.ts b/src/npmDeps.ts index 984c07ff..4209ca1f 100644 --- a/src/npmDeps.ts +++ b/src/npmDeps.ts @@ -1,2 +1,2 @@ -export * from "npm:superstruct@1.0.3"; +export * from "npm:superstruct@2.0.2"; export * from "npm:mongodb@6.3.0"; From 892c3c361e6d0b3d12e97da0d49ea14c3a8ff34c Mon Sep 17 00:00:00 2001 From: Syd Amir Date: Tue, 16 Jul 2024 23:42:09 +0330 Subject: [PATCH 2/4] :art: make optional feild optional in declaration --- src/types/generateTypesFromStruct.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/types/generateTypesFromStruct.ts b/src/types/generateTypesFromStruct.ts index 5eaabe3f..e9020a20 100644 --- a/src/types/generateTypesFromStruct.ts +++ b/src/types/generateTypesFromStruct.ts @@ -8,6 +8,15 @@ export const generateTypesFromStruct = ( }, ) => { let returnStr = ""; + + const schemaStructValidate = schemaStruct.validate(undefined)[0]; + + if (schemaStructValidate === undefined || schemaStructValidate === null) { + if (keyname && !keyname.endsWith("?")) { + keyname = `${keyname}?`; + } + } + if (schemaStruct.type === "object") { returnStr = returnStr + (keyname ? `${keyname}: {\n` : `{\n`); for (const key in schemaStruct.schema as Object) { From 7c15f77c4cea48f9dd7cf921cd666658983edb13 Mon Sep 17 00:00:00 2001 From: Syd Amir Date: Tue, 16 Jul 2024 23:43:03 +0330 Subject: [PATCH 3/4] :rotating_light: make get object not optional --- src/models/selectStruct.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/models/selectStruct.ts b/src/models/selectStruct.ts index c11646e6..22f3394c 100644 --- a/src/models/selectStruct.ts +++ b/src/models/selectStruct.ts @@ -35,7 +35,7 @@ export const selectStructFns = (schemasObj: TSchemas) => { }; } - const mainRelations = ( + const numDepthIterateRelations = ( schema: keyof TSchemas, depth: number, pureObj: Record, @@ -45,30 +45,30 @@ export const selectStructFns = (schemasObj: TSchemas) => { for (const property in foundedSchema.mainRelations) { returnObj = { ...returnObj, - [property]: selectStruct( + [property]: optional(selectStruct( foundedSchema.mainRelations[property].schemaName, depth, - ), + )), }; } for (const property in foundedSchema.relatedRelations) { returnObj = { ...returnObj, - [property]: selectStruct( + [property]: optional(selectStruct( foundedSchema.relatedRelations[property].schemaName, depth, - ), + )), }; } - return optional(object(returnObj as ObjectSchema)); + return object(returnObj as ObjectSchema); }; const numberDepth = (depth: number, pureObj: Record) => { depth--; return depth > -1 - ? mainRelations(schema, depth, pureObj) - : optional(object(pureObj)); + ? numDepthIterateRelations(schema, depth, pureObj) + : object(pureObj); }; const objectDepth = (depth: any, pureObj: Record) => { @@ -79,24 +79,24 @@ export const selectStructFns = (schemasObj: TSchemas) => { checkRelation(depth, property) && (pureObj = { ...pureObj, - [property]: selectStruct( + [property]: optional(selectStruct( foundedSchema.mainRelations[property].schemaName, depth[property], - ), + )), }); } for (const property in foundedSchema.relatedRelations) { checkRelation(depth, property) && (pureObj = { ...pureObj, - [property]: selectStruct( + [property]: optional(selectStruct( foundedSchema.relatedRelations[property].schemaName, depth[property], - ), + )), }); } - return optional(object(pureObj)); + return object(pureObj); }; const completeObj = typeof depth === "number" From 902379e1966b7cc6b59b92a9d16fff3c8c1021fe Mon Sep 17 00:00:00 2001 From: Syd Amir Date: Tue, 16 Jul 2024 23:54:35 +0330 Subject: [PATCH 4/4] :bug: fixed generate schema inputs --- src/lesan.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lesan.ts b/src/lesan.ts index c86a2556..d62524a4 100644 --- a/src/lesan.ts +++ b/src/lesan.ts @@ -18,6 +18,6 @@ export const lesan = () => { odm: { ...odm(schemasObj) }, runServer: lesanServer(schemasObj, actsObj), contextFns, - generateSchemTypes: () => generateSchemTypes(schemasObj), + generateSchemTypes: () => generateSchemTypes(schemasObj, actsObj), }; };