prostgles-server 2.0.328 → 2.0.330
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Prostgles.js +1 -1
- package/dist/Prostgles.js.map +1 -1
- package/dist/PublishParser.d.ts +5 -5
- package/dist/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser.js +4 -3
- package/dist/PublishParser.js.map +1 -1
- package/dist/TableConfig.d.ts +4 -3
- package/dist/TableConfig.d.ts.map +1 -1
- package/dist/TableConfig.js +18 -17
- package/dist/TableConfig.js.map +1 -1
- package/dist/validation.d.ts +7 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +87 -1
- package/dist/validation.js.map +1 -1
- package/lib/Prostgles.js +1 -1
- package/lib/Prostgles.ts +1 -1
- package/lib/PublishParser.d.ts +5 -5
- package/lib/PublishParser.d.ts.map +1 -1
- package/lib/PublishParser.js +4 -3
- package/lib/PublishParser.ts +10 -8
- package/lib/TableConfig.d.ts +4 -3
- package/lib/TableConfig.d.ts.map +1 -1
- package/lib/TableConfig.js +18 -17
- package/lib/TableConfig.ts +26 -22
- package/lib/validation.d.ts +7 -0
- package/lib/validation.d.ts.map +1 -1
- package/lib/validation.js +87 -1
- package/lib/validation.ts +94 -1
- package/package.json +3 -3
- package/tests/client/PID.txt +1 -1
- package/tests/client/package-lock.json +15 -15
- package/tests/client/package.json +1 -1
- package/tests/isomorphic_queries.d.ts.map +1 -1
- package/tests/isomorphic_queries.js +36 -0
- package/tests/isomorphic_queries.ts +38 -0
- package/tests/server/package-lock.json +5 -5
package/lib/validation.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { asName, getKeys, isEmpty, isObject } from "prostgles-types";
|
|
1
|
+
import { AnyObject, asName, getKeys, isEmpty, isObject } from "prostgles-types";
|
|
2
2
|
import { asValue } from "./PubSubManager";
|
|
3
|
+
import { BaseColumn, ColumnConfig, JSONBColumnDef } from "./TableConfig";
|
|
3
4
|
|
|
4
5
|
type BaseOptions = {
|
|
5
6
|
optional?: boolean;
|
|
6
7
|
nullable?: boolean;
|
|
8
|
+
description?: string;
|
|
9
|
+
title?: string;
|
|
7
10
|
};
|
|
8
11
|
|
|
9
12
|
type SimpleType = BaseOptions & ({
|
|
@@ -203,3 +206,93 @@ export function getJSONBSchemaTSTypes(schema: ValidationSchema | OneOfTypes, col
|
|
|
203
206
|
return (colOpts.nullable? `null | ` : "") + getSchemaTSTypes(schema, leading, isOneOf);
|
|
204
207
|
}
|
|
205
208
|
}
|
|
209
|
+
|
|
210
|
+
// type JSONSchema =
|
|
211
|
+
const getJSONSchemaObject = <T extends ValidationSchema>(objDef: T): Record<keyof T, any> => {
|
|
212
|
+
const resultType: Record<keyof T, any> = {} as any;
|
|
213
|
+
|
|
214
|
+
return getKeys(objDef).reduce((a, k) => {
|
|
215
|
+
const itemSchema: FieldType = objDef[k];
|
|
216
|
+
const { nullable, optional, description, title } = itemSchema;
|
|
217
|
+
let item = {} as any;
|
|
218
|
+
|
|
219
|
+
if("type" in itemSchema){
|
|
220
|
+
const { type } = itemSchema;
|
|
221
|
+
/**
|
|
222
|
+
* Is primitive or any
|
|
223
|
+
*/
|
|
224
|
+
if(typeof type === "string"){
|
|
225
|
+
const arrayType = type.endsWith("[]")? type.slice(0, -2) : undefined;
|
|
226
|
+
if(arrayType){
|
|
227
|
+
item = {
|
|
228
|
+
type: "array",
|
|
229
|
+
items: { type: arrayType === "any"? {} : arrayType }
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
item = {
|
|
233
|
+
type: type === "any"? {} : type
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Is object
|
|
239
|
+
*/
|
|
240
|
+
} else {
|
|
241
|
+
item = {
|
|
242
|
+
type: "object",
|
|
243
|
+
properties: getJSONSchemaObject(type)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
} else if("oneOf" in itemSchema) {
|
|
249
|
+
item = {
|
|
250
|
+
type: "array",
|
|
251
|
+
items: {
|
|
252
|
+
"type": typeof itemSchema.oneOf[0]!,
|
|
253
|
+
"enum": itemSchema.oneOf //.concat(nullable? [null] : [])
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
} else if("oneOfTypes" in itemSchema) {
|
|
257
|
+
item = {
|
|
258
|
+
oneOf: itemSchema.oneOfTypes.map(t => getJSONSchemaObject(t))
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
throw "Unexpected jsonbSchema"
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if(nullable){
|
|
265
|
+
const nullDef = { type: "null" }
|
|
266
|
+
if(item.oneOf) item.oneOf.push(nullDef)
|
|
267
|
+
else item = {
|
|
268
|
+
oneOf: [item, nullDef]
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
...a,
|
|
274
|
+
[k]: {
|
|
275
|
+
...item,
|
|
276
|
+
required: !optional,
|
|
277
|
+
description,
|
|
278
|
+
title,
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}, resultType)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function getJSONBSchemaAsJSONSchema(tableName: string, columnConfig: BaseColumn<{ en: 1 }> & JSONBColumnDef): AnyObject {
|
|
285
|
+
|
|
286
|
+
const schema = columnConfig.jsonbSchema;
|
|
287
|
+
const jSchema = isOneOfTypes(schema)? getJSONSchemaObject({ d: schema }).d : getJSONSchemaObject(schema as ValidationSchema);
|
|
288
|
+
|
|
289
|
+
return {
|
|
290
|
+
"$id": tableName ?? "???",
|
|
291
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
292
|
+
"title": tableName,
|
|
293
|
+
"type": "object",
|
|
294
|
+
description: columnConfig.info?.hint ,
|
|
295
|
+
...jSchema
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.330",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"check-disk-space": "^3.3.1",
|
|
32
32
|
"file-type": "^17.1.4",
|
|
33
33
|
"pg-promise": "^10.11.1",
|
|
34
|
-
"prostgles-types": "^1.5.
|
|
34
|
+
"prostgles-types": "^1.5.179",
|
|
35
35
|
"sharp": "^0.31.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
@@ -39,6 +39,6 @@
|
|
|
39
39
|
"@types/bluebird": "^3.5.36",
|
|
40
40
|
"@types/node": "^18.0.3",
|
|
41
41
|
"@types/sharp": "^0.30.4",
|
|
42
|
-
"typescript": "^4.
|
|
42
|
+
"typescript": "^4.8.4"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/tests/client/PID.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
48447
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@types/node": "^14.14.16",
|
|
13
|
-
"prostgles-client": "^1.5.
|
|
13
|
+
"prostgles-client": "^1.5.183",
|
|
14
14
|
"prostgles-types": "^1.5.68",
|
|
15
15
|
"socket.io-client": "^4.5.1"
|
|
16
16
|
}
|
|
@@ -67,17 +67,17 @@
|
|
|
67
67
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
|
68
68
|
},
|
|
69
69
|
"node_modules/prostgles-client": {
|
|
70
|
-
"version": "1.5.
|
|
71
|
-
"resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.
|
|
72
|
-
"integrity": "sha512-
|
|
70
|
+
"version": "1.5.183",
|
|
71
|
+
"resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.183.tgz",
|
|
72
|
+
"integrity": "sha512-X0w6/HcrauIFI1fgk/lLDnXiQ4f1HsILFHqctPAAnNMGOXosVuAtUMuktAIODYhGomBizodQw5MN7ufkqMER5Q==",
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"prostgles-types": "^1.5.
|
|
74
|
+
"prostgles-types": "^1.5.179"
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
77
|
"node_modules/prostgles-types": {
|
|
78
|
-
"version": "1.5.
|
|
79
|
-
"resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.
|
|
80
|
-
"integrity": "sha512-
|
|
78
|
+
"version": "1.5.179",
|
|
79
|
+
"resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.179.tgz",
|
|
80
|
+
"integrity": "sha512-ciAxlwoEloybfMjTiOU1w/N3nguCwlcWFTKJ1bD7XHm3VXaLKJraQelOPJPeYr27ujo5iYWJzWBy6GT2yM0wbQ=="
|
|
81
81
|
},
|
|
82
82
|
"node_modules/socket.io-client": {
|
|
83
83
|
"version": "4.5.1",
|
|
@@ -176,17 +176,17 @@
|
|
|
176
176
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
|
177
177
|
},
|
|
178
178
|
"prostgles-client": {
|
|
179
|
-
"version": "1.5.
|
|
180
|
-
"resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.
|
|
181
|
-
"integrity": "sha512-
|
|
179
|
+
"version": "1.5.183",
|
|
180
|
+
"resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.183.tgz",
|
|
181
|
+
"integrity": "sha512-X0w6/HcrauIFI1fgk/lLDnXiQ4f1HsILFHqctPAAnNMGOXosVuAtUMuktAIODYhGomBizodQw5MN7ufkqMER5Q==",
|
|
182
182
|
"requires": {
|
|
183
|
-
"prostgles-types": "^1.5.
|
|
183
|
+
"prostgles-types": "^1.5.179"
|
|
184
184
|
}
|
|
185
185
|
},
|
|
186
186
|
"prostgles-types": {
|
|
187
|
-
"version": "1.5.
|
|
188
|
-
"resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.
|
|
189
|
-
"integrity": "sha512-
|
|
187
|
+
"version": "1.5.179",
|
|
188
|
+
"resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.179.tgz",
|
|
189
|
+
"integrity": "sha512-ciAxlwoEloybfMjTiOU1w/N3nguCwlcWFTKJ1bD7XHm3VXaLKJraQelOPJPeYr27ujo5iYWJzWBy6GT2yM0wbQ=="
|
|
190
190
|
},
|
|
191
191
|
"socket.io-client": {
|
|
192
192
|
"version": "4.5.1",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isomorphic_queries.d.ts","sourceRoot":"","sources":["isomorphic_queries.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE,GAAG,CAAC,EAAE,QAAQ,iBAYzE;AACD,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,GAAG,EAAE,GAAG,CAAC,EAAE,QAAQ,oBAW7F;AAED,wBAA8B,UAAU,CAAC,EAAE,EAAE,QAAQ,CAAC,eAAe,CAAC,GAAG,QAAQ,CAAC,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"isomorphic_queries.d.ts","sourceRoot":"","sources":["isomorphic_queries.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE,GAAG,CAAC,EAAE,QAAQ,iBAYzE;AACD,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,GAAG,EAAE,GAAG,CAAC,EAAE,QAAQ,oBAW7F;AAED,wBAA8B,UAAU,CAAC,EAAE,EAAE,QAAQ,CAAC,eAAe,CAAC,GAAG,QAAQ,CAAC,eAAe,CAAC,iBA23BjG"}
|
|
@@ -594,6 +594,42 @@ async function isomorphic(db) {
|
|
|
594
594
|
// Perfect
|
|
595
595
|
}
|
|
596
596
|
});
|
|
597
|
+
await tryRun("jsonb JSON Schema validation", async () => {
|
|
598
|
+
const cols = await db.tjson.getColumns();
|
|
599
|
+
assert_1.strict.deepEqual({
|
|
600
|
+
'$id': 'tjson',
|
|
601
|
+
'$schema': 'https://json-schema.org/draft/2020-12/schema',
|
|
602
|
+
title: 'tjson',
|
|
603
|
+
type: 'object',
|
|
604
|
+
a: { type: 'boolean', required: true },
|
|
605
|
+
arr: {
|
|
606
|
+
type: 'array',
|
|
607
|
+
items: { type: 'string', enum: ['1', '2', '3'] },
|
|
608
|
+
required: true
|
|
609
|
+
},
|
|
610
|
+
arr1: {
|
|
611
|
+
type: 'array',
|
|
612
|
+
items: { type: 'number', enum: [1, 2, 3] },
|
|
613
|
+
required: true
|
|
614
|
+
},
|
|
615
|
+
arr2: { type: 'array', items: { type: 'integer' }, required: true },
|
|
616
|
+
arrStr: {
|
|
617
|
+
oneOf: [
|
|
618
|
+
{ type: 'array', items: { type: 'string' } },
|
|
619
|
+
{ type: 'null' }
|
|
620
|
+
],
|
|
621
|
+
required: false
|
|
622
|
+
},
|
|
623
|
+
o: {
|
|
624
|
+
oneOf: [
|
|
625
|
+
{ o1: { type: 'integer', required: true } },
|
|
626
|
+
{ o2: { type: 'boolean', required: true } },
|
|
627
|
+
{ type: 'null' }
|
|
628
|
+
],
|
|
629
|
+
required: false
|
|
630
|
+
}
|
|
631
|
+
}, cols.find(c => c.name === "json").jsonSchema);
|
|
632
|
+
});
|
|
597
633
|
await tryRun("Exists filter example", async () => {
|
|
598
634
|
const fo = await db.items.findOne(), f = await db.items.find();
|
|
599
635
|
assert_1.strict.deepStrictEqual(fo, { h: null, id: 1, name: 'a' }, "findOne query failed");
|
|
@@ -677,6 +677,44 @@ export default async function isomorphic(db: Required<DBHandlerServer> | Require
|
|
|
677
677
|
// Perfect
|
|
678
678
|
}
|
|
679
679
|
});
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
await tryRun("jsonb JSON Schema validation", async () => {
|
|
683
|
+
const cols = await db.tjson.getColumns!();
|
|
684
|
+
assert.deepEqual({
|
|
685
|
+
'$id': 'tjson',
|
|
686
|
+
'$schema': 'https://json-schema.org/draft/2020-12/schema',
|
|
687
|
+
title: 'tjson',
|
|
688
|
+
type: 'object',
|
|
689
|
+
a: { type: 'boolean', required: true },
|
|
690
|
+
arr: {
|
|
691
|
+
type: 'array',
|
|
692
|
+
items: { type: 'string', enum: [ '1', '2', '3' ] },
|
|
693
|
+
required: true
|
|
694
|
+
},
|
|
695
|
+
arr1: {
|
|
696
|
+
type: 'array',
|
|
697
|
+
items: { type: 'number', enum: [ 1, 2, 3 ] },
|
|
698
|
+
required: true
|
|
699
|
+
},
|
|
700
|
+
arr2: { type: 'array', items: { type: 'integer' }, required: true },
|
|
701
|
+
arrStr: {
|
|
702
|
+
oneOf: [
|
|
703
|
+
{ type: 'array', items: { type: 'string' } },
|
|
704
|
+
{ type: 'null' }
|
|
705
|
+
],
|
|
706
|
+
required: false
|
|
707
|
+
},
|
|
708
|
+
o: {
|
|
709
|
+
oneOf: [
|
|
710
|
+
{ o1: { type: 'integer', required: true } },
|
|
711
|
+
{ o2: { type: 'boolean', required: true } },
|
|
712
|
+
{ type: 'null' }
|
|
713
|
+
],
|
|
714
|
+
required: false
|
|
715
|
+
}
|
|
716
|
+
}, cols.find(c => c.name === "json").jsonSchema)
|
|
717
|
+
})
|
|
680
718
|
|
|
681
719
|
await tryRun("Exists filter example", async () => {
|
|
682
720
|
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"../..": {
|
|
23
23
|
"name": "prostgles-server",
|
|
24
|
-
"version": "2.0.
|
|
24
|
+
"version": "2.0.329",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@aws-sdk/client-s3": "^3.121.0",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"check-disk-space": "^3.3.1",
|
|
32
32
|
"file-type": "^17.1.4",
|
|
33
33
|
"pg-promise": "^10.11.1",
|
|
34
|
-
"prostgles-types": "^1.5.
|
|
34
|
+
"prostgles-types": "^1.5.179",
|
|
35
35
|
"sharp": "^0.31.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@types/bluebird": "^3.5.36",
|
|
40
40
|
"@types/node": "^18.0.3",
|
|
41
41
|
"@types/sharp": "^0.30.4",
|
|
42
|
-
"typescript": "^4.
|
|
42
|
+
"typescript": "^4.8.4"
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"node_modules/@types/component-emitter": {
|
|
@@ -1375,9 +1375,9 @@
|
|
|
1375
1375
|
"check-disk-space": "^3.3.1",
|
|
1376
1376
|
"file-type": "^17.1.4",
|
|
1377
1377
|
"pg-promise": "^10.11.1",
|
|
1378
|
-
"prostgles-types": "^1.5.
|
|
1378
|
+
"prostgles-types": "^1.5.179",
|
|
1379
1379
|
"sharp": "^0.31.0",
|
|
1380
|
-
"typescript": "^4.
|
|
1380
|
+
"typescript": "^4.8.4"
|
|
1381
1381
|
}
|
|
1382
1382
|
},
|
|
1383
1383
|
"proxy-addr": {
|