Skip to content

Commit

Permalink
fix jsonb_record type
Browse files Browse the repository at this point in the history
  • Loading branch information
prostgles committed Oct 12, 2023
1 parent da5688b commit 2f9978b
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 34 deletions.
5 changes: 3 additions & 2 deletions lib/JSONBValidation/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ export function getJSONBSchemaTSTypes(schema: JSONB.JSONBSchema, colOpts: ColOpt
return `${fieldType.nullable ? `null | ` : ""} ( ${getFieldType(arrayOf, true, undefined, depth + 1)} )[]`;

} else if (fieldType?.record) {
const { keysEnum, values } = fieldType.record;
const { keysEnum, values, partial } = fieldType.record;
// TODO: ensure props with undefined values are not allowed in the TS type
return `${fieldType.nullable ? `null |` : ""} Partial<Record<${keysEnum?.map(v => asValue(v)).join(" | ") ?? "string"}, ${!values? "any" : getFieldType(values, true, undefined, depth + 1)}>>`
const getRecord = (v: string) => partial? `Partial<Record<${v}>>` : `Record<${v}>`;
return `${fieldType.nullable ? `null |` : ""} ${getRecord(`${keysEnum?.map(v => asValue(v)).join(" | ") ?? "string"}, ${!values? "any" : getFieldType(values, true, undefined, depth + 1)}`)}>>`

} else if(fieldType?.lookup){

Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prostgles-server",
"version": "4.1.83",
"version": "4.1.84",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -41,7 +41,7 @@
"check-disk-space": "^3.3.1",
"file-type": "^17.1.4",
"pg-promise": "^11.3.0",
"prostgles-types": "^4.0.41"
"prostgles-types": "^4.0.42"
},
"devDependencies": {
"@types/bluebird": "^3.5.36",
Expand Down
2 changes: 1 addition & 1 deletion tests/client/PID.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1733501
1745085
30 changes: 15 additions & 15 deletions tests/client/package-lock.json

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

2 changes: 1 addition & 1 deletion tests/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"license": "ISC",
"dependencies": {
"@types/node": "^14.14.16",
"prostgles-client": "^4.0.25",
"prostgles-client": "^4.0.26",
"socket.io-client": "^4.7.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion tests/server/DBoGenerated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ export type DBSchemaGenerated = {
| { ok: string; }
| { err: string; }
| { loading: { loaded: number; total: number; }; }
table_config?: null | { referencedTables?: ( { name: string; minFiles: number; } )[]; recType?: null | Partial<Record<'a' | 'b', { bools: boolean[]; }>>; };
table_config?: null | { referencedTables?: ( { name: string; minFiles: number; } )[]; recType?: null | Record<'a' | 'b', { bools: boolean[]; }>>>; };
};
};
tr1: {
Expand Down
6 changes: 3 additions & 3 deletions tests/server/package-lock.json

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

0 comments on commit 2f9978b

Please sign in to comment.