prostgles-server 3.0.90 → 3.0.92
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/DBSchemaBuilder.js +1 -2
- package/dist/DBSchemaBuilder.js.map +1 -1
- package/dist/JSONBValidation/validate_jsonb_schema_sql.d.ts.map +1 -1
- package/dist/JSONBValidation/validate_jsonb_schema_sql.js +70 -14
- package/dist/JSONBValidation/validate_jsonb_schema_sql.js.map +1 -1
- package/dist/JSONBValidation/validation.d.ts +52 -12
- package/dist/JSONBValidation/validation.d.ts.map +1 -1
- package/dist/JSONBValidation/validation.js +64 -55
- package/dist/JSONBValidation/validation.js.map +1 -1
- package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/PubSubManager.js +13 -11
- package/dist/PubSubManager/PubSubManager.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/lib/DBSchemaBuilder.js +1 -2
- package/lib/DBSchemaBuilder.ts +2 -2
- package/lib/JSONBValidation/validate_jsonb_schema_sql.d.ts.map +1 -1
- package/lib/JSONBValidation/validate_jsonb_schema_sql.js +70 -14
- package/lib/JSONBValidation/validate_jsonb_schema_sql.ts +70 -14
- package/lib/JSONBValidation/validation.d.ts +52 -12
- package/lib/JSONBValidation/validation.d.ts.map +1 -1
- package/lib/JSONBValidation/validation.js +64 -55
- package/lib/JSONBValidation/validation.ts +120 -66
- package/lib/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/lib/PubSubManager/PubSubManager.js +13 -11
- package/lib/PubSubManager/PubSubManager.ts +14 -13
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.ts +1 -1
- package/package.json +1 -1
- package/tests/client/PID.txt +1 -1
- package/tests/client_only_queries.js +1 -1
- package/tests/client_only_queries.ts +1 -1
- package/tests/server/DBoGenerated.d.ts +5 -4
- package/tests/server/index.js +7 -4
- package/tests/server/index.ts +7 -4
- package/tests/server/package-lock.json +1 -1
|
@@ -19,42 +19,73 @@ export declare namespace JSONB {
|
|
|
19
19
|
type: DataType;
|
|
20
20
|
allowedValues?: any[];
|
|
21
21
|
oneOf?: undefined;
|
|
22
|
+
oneOfType?: undefined;
|
|
22
23
|
arrayOf?: undefined;
|
|
24
|
+
arrayOfType?: undefined;
|
|
23
25
|
enum?: undefined;
|
|
24
26
|
};
|
|
25
27
|
export type ObjectType = BaseOptions & {
|
|
26
28
|
type: ObjectSchema;
|
|
27
29
|
allowedValues?: undefined;
|
|
28
30
|
oneOf?: undefined;
|
|
31
|
+
oneOfType?: undefined;
|
|
29
32
|
arrayOf?: undefined;
|
|
33
|
+
arrayOfType?: undefined;
|
|
30
34
|
enum?: undefined;
|
|
31
35
|
};
|
|
32
36
|
export type EnumType = BaseOptions & {
|
|
33
37
|
type?: undefined;
|
|
34
38
|
enum: readonly any[];
|
|
35
39
|
oneOf?: undefined;
|
|
40
|
+
oneOfType?: undefined;
|
|
36
41
|
arrayOf?: undefined;
|
|
42
|
+
arrayOfType?: undefined;
|
|
37
43
|
allowedValues?: undefined;
|
|
38
44
|
};
|
|
39
45
|
export type OneOf = BaseOptions & {
|
|
40
46
|
type?: undefined;
|
|
41
|
-
oneOf: readonly ObjectSchema[];
|
|
42
47
|
arrayOf?: undefined;
|
|
48
|
+
arrayOfType?: undefined;
|
|
43
49
|
allowedValues?: undefined;
|
|
44
50
|
enum?: undefined;
|
|
45
|
-
}
|
|
51
|
+
} & ({
|
|
52
|
+
oneOf?: undefined;
|
|
53
|
+
oneOfType: readonly ObjectSchema[];
|
|
54
|
+
} | {
|
|
55
|
+
oneOf: FieldType[];
|
|
56
|
+
oneOfType?: undefined;
|
|
57
|
+
});
|
|
46
58
|
export type ArrayOf = BaseOptions & {
|
|
47
59
|
type?: undefined;
|
|
48
|
-
arrayOf: ObjectSchema;
|
|
49
60
|
allowedValues?: undefined;
|
|
50
61
|
oneOf?: undefined;
|
|
62
|
+
oneOfType?: undefined;
|
|
51
63
|
enum?: undefined;
|
|
64
|
+
} & ({
|
|
65
|
+
arrayOf?: undefined;
|
|
66
|
+
arrayOfType: ObjectSchema;
|
|
67
|
+
} | {
|
|
68
|
+
arrayOf: FieldType;
|
|
69
|
+
arrayOfType?: undefined;
|
|
70
|
+
});
|
|
71
|
+
export type RecordType = BaseOptions & {
|
|
72
|
+
type?: undefined;
|
|
73
|
+
allowedValues?: undefined;
|
|
74
|
+
oneOf?: undefined;
|
|
75
|
+
oneOfType?: undefined;
|
|
76
|
+
arrayOf?: undefined;
|
|
77
|
+
arrayOfType?: undefined;
|
|
78
|
+
enum?: undefined;
|
|
79
|
+
record: {
|
|
80
|
+
keysEnum?: readonly string[];
|
|
81
|
+
values?: FieldType;
|
|
82
|
+
};
|
|
52
83
|
};
|
|
53
|
-
export type FieldTypeObj = BasicType | ObjectType | EnumType | OneOf | ArrayOf
|
|
84
|
+
export type FieldTypeObj = StrictUnion<BasicType | ObjectType | EnumType | OneOf | ArrayOf | RecordType>;
|
|
54
85
|
export type FieldType = DataType | FieldTypeObj;
|
|
55
86
|
export type GetType<T extends FieldType | Omit<FieldTypeObj, "optional">> = T extends {
|
|
56
87
|
type: ObjectSchema;
|
|
57
|
-
} ?
|
|
88
|
+
} ? GetObjectType<T["type"]> : T extends "number" | {
|
|
58
89
|
type: "number";
|
|
59
90
|
} ? number : T extends "boolean" | {
|
|
60
91
|
type: "boolean";
|
|
@@ -75,18 +106,28 @@ export declare namespace JSONB {
|
|
|
75
106
|
} ? string[] : T extends "any[]" | {
|
|
76
107
|
type: "any[]";
|
|
77
108
|
} ? any[] : T extends {
|
|
78
|
-
enum: readonly any[];
|
|
109
|
+
"enum": readonly any[];
|
|
79
110
|
} ? T["enum"][number] : T extends {
|
|
111
|
+
"record": RecordType["record"];
|
|
112
|
+
} ? Record<T["record"] extends {
|
|
113
|
+
keysEnum: readonly string[];
|
|
114
|
+
} ? T["record"]["keysEnum"][number] : string, T["record"] extends {
|
|
115
|
+
values: FieldType;
|
|
116
|
+
} ? GetType<T["record"]["values"]> : any> : T extends {
|
|
117
|
+
oneOf: FieldType[];
|
|
118
|
+
} ? StrictUnion<GetType<T["oneOf"][number]>> : T extends {
|
|
80
119
|
oneOf: readonly ObjectSchema[];
|
|
81
|
-
} ? StrictUnion<
|
|
120
|
+
} ? StrictUnion<GetType<T["oneOf"][number]>> : T extends {
|
|
82
121
|
arrayOf: ObjectSchema;
|
|
83
|
-
} ?
|
|
122
|
+
} ? GetType<T["arrayOf"]>[] : T extends {
|
|
123
|
+
arrayOfType: ObjectSchema;
|
|
124
|
+
} ? GetType<T["arrayOfType"]>[] : any;
|
|
84
125
|
type IsOptional<F extends FieldType> = F extends DataType ? false : F extends {
|
|
85
126
|
optional: true;
|
|
86
127
|
} ? true : false;
|
|
87
128
|
export type ObjectSchema = Record<string, FieldType>;
|
|
88
129
|
export type JSONBSchema = Omit<FieldTypeObj, "optional">;
|
|
89
|
-
export type
|
|
130
|
+
export type GetObjectType<S extends ObjectSchema> = ({
|
|
90
131
|
[K in keyof S as IsOptional<S[K]> extends true ? K : never]?: GetType<S[K]>;
|
|
91
132
|
} & {
|
|
92
133
|
[K in keyof S as IsOptional<S[K]> extends true ? never : K]: GetType<S[K]>;
|
|
@@ -95,12 +136,11 @@ export declare namespace JSONB {
|
|
|
95
136
|
export {};
|
|
96
137
|
}
|
|
97
138
|
export declare function validate<T>(obj: T, key: keyof T, rawFieldType: JSONB.FieldType): boolean;
|
|
98
|
-
export declare function validateSchema<S extends JSONB.ObjectSchema>(schema: S, obj: JSONB.
|
|
139
|
+
export declare function validateSchema<S extends JSONB.ObjectSchema>(schema: S, obj: JSONB.GetObjectType<S>, objName?: string, optional?: boolean): void;
|
|
99
140
|
type ColOpts = {
|
|
100
141
|
nullable?: boolean;
|
|
101
142
|
};
|
|
102
|
-
export declare function
|
|
103
|
-
export declare function getJSONBSchemaTSTypes(schema: JSONB.JSONBSchema, colOpts: ColOpts, leading?: string, isOneOf?: boolean): string;
|
|
143
|
+
export declare function getJSONBSchemaTSTypes(schema: JSONB.JSONBSchema, colOpts: ColOpts, leading?: string): string;
|
|
104
144
|
export declare function getJSONBSchemaAsJSONSchema(tableName: string, colName: string, columnConfig: BaseColumn<{
|
|
105
145
|
en: 1;
|
|
106
146
|
}> & JSONBColumnDef): JSONSchema7;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,aAAa,CAAC;AAGpE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIzE,QAAA,MAAM,UAAU,kIAGN,CAAC;AACX,KAAK,QAAQ,GAAG,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;AAE1C,yBAAiB,KAAK,CAAC;IAErB,MAAM,MAAM,WAAW,GAAG;QACxB;;WAEG;QACH,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB;;WAEG;QACH,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IAEF,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG;QACpC,IAAI,EAAE,QAAQ,CAAC;QACf,aAAa,CAAC,EAAE,GAAG,EAAE,CAAC;QACtB,KAAK,CAAC,EAAE,SAAS,CAAC;QAClB,OAAO,CAAC,EAAE,SAAS,CAAC;QACpB,IAAI,CAAC,EAAE,SAAS,CAAC;KAClB,CAAC;IAEF,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG;QACrC,IAAI,EAAE,YAAY,CAAC;QACnB,aAAa,CAAC,EAAE,SAAS,CAAC;QAC1B,KAAK,CAAC,EAAE,SAAS,CAAC;QAClB,OAAO,CAAC,EAAE,SAAS,CAAC;QACpB,IAAI,CAAC,EAAE,SAAS,C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C,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;;CAChH;AAiCD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,SAAS,GAAG,OAAO,CAqBxF;AAED,wBAAgB,cAAc,CAAC,CAAC,SAAS,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,UAAQ,QAGtI;AAGD,KAAK,OAAO,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAGtC,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,SAAK,GAAG,MAAM,CAgDvG;AAsGD,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,CAAC;IAAE,EAAE,EAAE,CAAC,CAAA;CAAE,CAAC,GAAG,cAAc,GAAG,WAAW,CAQhJ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getJSONBSchemaAsJSONSchema = exports.getJSONBSchemaTSTypes = exports.
|
|
3
|
+
exports.getJSONBSchemaAsJSONSchema = exports.getJSONBSchemaTSTypes = exports.validateSchema = exports.validate = exports.JSONB = void 0;
|
|
4
4
|
const prostgles_types_1 = require("prostgles-types");
|
|
5
5
|
const PubSubManager_1 = require("../PubSubManager/PubSubManager");
|
|
6
6
|
const PrimitiveTypes = ["boolean", "number", "integer", "string", "any"];
|
|
@@ -8,21 +8,32 @@ const DATA_TYPES = [
|
|
|
8
8
|
...PrimitiveTypes,
|
|
9
9
|
...PrimitiveTypes.map(v => `${v}[]`)
|
|
10
10
|
];
|
|
11
|
+
var JSONB;
|
|
12
|
+
(function (JSONB) {
|
|
13
|
+
const _r = {
|
|
14
|
+
a: [2],
|
|
15
|
+
b: [221]
|
|
16
|
+
};
|
|
17
|
+
const _dd = {
|
|
18
|
+
enum: [1],
|
|
19
|
+
type: "any"
|
|
20
|
+
};
|
|
21
|
+
})(JSONB = exports.JSONB || (exports.JSONB = {}));
|
|
11
22
|
/** tests */
|
|
12
23
|
const s = {
|
|
13
24
|
type: {
|
|
14
25
|
a: { type: "boolean" },
|
|
15
26
|
c: { type: { c1: { type: "string" } } },
|
|
16
|
-
arr: {
|
|
27
|
+
arr: { arrayOfType: { d: "string" } },
|
|
17
28
|
o: {
|
|
18
|
-
|
|
29
|
+
oneOfType: [
|
|
19
30
|
{ z: { type: "integer" } },
|
|
20
31
|
{ z1: { type: "integer" } }
|
|
21
32
|
]
|
|
22
33
|
}
|
|
23
34
|
}
|
|
24
35
|
};
|
|
25
|
-
const
|
|
36
|
+
const _ss = {
|
|
26
37
|
a: true,
|
|
27
38
|
arr: [{ d: "" }],
|
|
28
39
|
c: {
|
|
@@ -69,68 +80,55 @@ function validateSchema(schema, obj, objName, optional = false) {
|
|
|
69
80
|
(0, prostgles_types_1.getKeys)(schema).forEach(k => validate(obj, k, schema[k]));
|
|
70
81
|
}
|
|
71
82
|
exports.validateSchema = validateSchema;
|
|
72
|
-
function
|
|
73
|
-
const getFieldType = (rawFieldType) => {
|
|
83
|
+
function getJSONBSchemaTSTypes(schema, colOpts, leading = "") {
|
|
84
|
+
const getFieldType = (rawFieldType, isOneOf = false, leading = "") => {
|
|
74
85
|
const fieldType = getFieldTypeObj(rawFieldType);
|
|
75
86
|
const nullType = (fieldType.nullable ? `null | ` : "");
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
return nullType + correctType;
|
|
87
|
+
/** Primitives */
|
|
88
|
+
if (typeof fieldType?.type === "string") {
|
|
89
|
+
const correctType = fieldType.type.replace("integer", "number");
|
|
90
|
+
if (fieldType.allowedValues && fieldType.type.endsWith("[]")) {
|
|
91
|
+
return nullType + ` (${fieldType.allowedValues.map(v => JSON.stringify(v)).join(" | ")})[]`;
|
|
83
92
|
}
|
|
84
|
-
|
|
85
|
-
|
|
93
|
+
return nullType + correctType;
|
|
94
|
+
/** Object */
|
|
95
|
+
}
|
|
96
|
+
else if ((0, prostgles_types_1.isObject)(fieldType.type)) {
|
|
97
|
+
const { type } = fieldType;
|
|
98
|
+
const spacing = isOneOf ? " " : " ";
|
|
99
|
+
let objDef = `${leading}{ \n` + (0, prostgles_types_1.getKeys)(type).map(k => {
|
|
100
|
+
const fieldType = getFieldTypeObj(type[k]);
|
|
101
|
+
return `${leading}${spacing}${k}${fieldType.optional ? "?" : ""}: ` + getFieldType(fieldType, isOneOf) + ";";
|
|
102
|
+
}).join("\n") + ` \n${leading}}${isOneOf ? "" : ";"}`;
|
|
103
|
+
/** Keep single line */
|
|
104
|
+
if (isOneOf) {
|
|
105
|
+
objDef = objDef.split("\n").join("");
|
|
86
106
|
}
|
|
107
|
+
return nullType + objDef;
|
|
87
108
|
}
|
|
88
109
|
else if (fieldType?.enum) {
|
|
89
110
|
return nullType + fieldType.enum.map(v => (0, PubSubManager_1.asValue)(v)).join(" | ");
|
|
90
111
|
}
|
|
91
|
-
else if (fieldType?.oneOf) {
|
|
92
|
-
|
|
112
|
+
else if (fieldType?.oneOf || fieldType?.oneOfType) {
|
|
113
|
+
const oneOf = fieldType?.oneOf || fieldType?.oneOfType.map(type => ({ type }));
|
|
114
|
+
return (fieldType.nullable ? `\n${leading} | null` : "") + oneOf.map(v => `\n${leading} | ` + getFieldType(v, true)).join("");
|
|
115
|
+
}
|
|
116
|
+
else if (fieldType?.arrayOf || fieldType?.arrayOfType) {
|
|
117
|
+
const arrayOf = fieldType?.arrayOf || { type: fieldType?.arrayOfType };
|
|
118
|
+
return (fieldType.nullable ? `null | ` : "") + getFieldType(arrayOf, true) + "[]";
|
|
93
119
|
}
|
|
94
|
-
else if (fieldType?.
|
|
95
|
-
|
|
120
|
+
else if (fieldType?.record) {
|
|
121
|
+
const { keysEnum, values } = fieldType.record;
|
|
122
|
+
return `${fieldType.nullable ? `null |` : ""} Record<${keysEnum?.map(v => (0, PubSubManager_1.asValue)(v)).join(" | ") ?? "string"}, ${!values ? "any" : getFieldType(values, true)}>`;
|
|
96
123
|
}
|
|
97
124
|
else
|
|
98
125
|
throw "Unexpected getSchemaTSTypes: " + JSON.stringify({ fieldType, schema }, null, 2);
|
|
99
126
|
};
|
|
100
|
-
|
|
101
|
-
const res = `${leading}{ \n` + (0, prostgles_types_1.getKeys)(schema).map(k => {
|
|
102
|
-
const fieldType = getFieldTypeObj(schema[k]);
|
|
103
|
-
return `${leading}${spacing}${k}${fieldType.optional ? "?" : ""}: ` + getFieldType(fieldType) + ";";
|
|
104
|
-
}).join("\n") + ` \n${leading}}${isOneOf ? "" : ";"}`;
|
|
105
|
-
/** Keep single line */
|
|
106
|
-
if (isOneOf)
|
|
107
|
-
return res.split("\n").join("");
|
|
108
|
-
return res;
|
|
109
|
-
}
|
|
110
|
-
exports.getSchemaTSTypes = getSchemaTSTypes;
|
|
111
|
-
function getJSONBSchemaTSTypes(schema, colOpts, leading = "", isOneOf = false) {
|
|
112
|
-
if (schema.arrayOf) {
|
|
113
|
-
return (colOpts.nullable ? `\n${leading} | null` : "") + getSchemaTSTypes(schema.arrayOf, leading, isOneOf) + "[]";
|
|
114
|
-
}
|
|
115
|
-
else if (schema.enum) {
|
|
116
|
-
return (colOpts.nullable ? `\n${leading} | null` : "") + schema.enum.map(v => (0, PubSubManager_1.asValue)(v)).join(" | ");
|
|
117
|
-
}
|
|
118
|
-
else if (schema.oneOf) {
|
|
119
|
-
return (colOpts.nullable ? `\n${leading} | null` : "") + schema.oneOf.map(s => `\n${leading} | ` + getSchemaTSTypes(s, "", true)).join("");
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
if (typeof schema.type === "string") {
|
|
123
|
-
return (colOpts.nullable ? `null | ` : "") + schema.type;
|
|
124
|
-
}
|
|
125
|
-
else if (schema.type) {
|
|
126
|
-
return (colOpts.nullable ? `null | ` : "") + getSchemaTSTypes(schema.type, leading, isOneOf);
|
|
127
|
-
}
|
|
128
|
-
return "";
|
|
129
|
-
}
|
|
127
|
+
return getFieldType({ ...schema, nullable: colOpts.nullable }, undefined, leading);
|
|
130
128
|
}
|
|
131
129
|
exports.getJSONBSchemaTSTypes = getJSONBSchemaTSTypes;
|
|
132
130
|
const getJSONSchemaObject = (rawType, rootInfo) => {
|
|
133
|
-
const { type, arrayOf, description, nullable, oneOf, title, ...t } = typeof rawType === "string" ? ({ type: rawType }) :
|
|
131
|
+
const { type, arrayOf, arrayOfType, description, nullable, oneOf, oneOfType, title, record, ...t } = typeof rawType === "string" ? ({ type: rawType }) :
|
|
134
132
|
rawType;
|
|
135
133
|
let result = {};
|
|
136
134
|
const partialProps = {
|
|
@@ -141,13 +139,13 @@ const getJSONSchemaObject = (rawType, rootInfo) => {
|
|
|
141
139
|
if (t.enum?.length) {
|
|
142
140
|
partialProps.type = typeof t.enum[0];
|
|
143
141
|
}
|
|
144
|
-
if (typeof type === "string" || arrayOf) {
|
|
142
|
+
if (typeof type === "string" || arrayOf || arrayOfType) {
|
|
145
143
|
/** ARRAY */
|
|
146
144
|
if (type && typeof type !== "string") {
|
|
147
145
|
throw "Not expected";
|
|
148
146
|
}
|
|
149
|
-
if (arrayOf || type?.endsWith("[]")) {
|
|
150
|
-
const arrayItems = arrayOf ? getJSONSchemaObject({ type:
|
|
147
|
+
if (arrayOf || arrayOfType || type?.endsWith("[]")) {
|
|
148
|
+
const arrayItems = (arrayOf || arrayOfType) ? getJSONSchemaObject(arrayOf || { type: arrayOfType }) :
|
|
151
149
|
type?.startsWith("any") ? { type: undefined } :
|
|
152
150
|
{
|
|
153
151
|
type: type?.slice(0, -2),
|
|
@@ -181,10 +179,21 @@ const getJSONSchemaObject = (rawType, rootInfo) => {
|
|
|
181
179
|
}, {}),
|
|
182
180
|
};
|
|
183
181
|
}
|
|
184
|
-
else if (oneOf) {
|
|
182
|
+
else if (oneOf || oneOfType) {
|
|
183
|
+
const _oneOf = oneOf || oneOfType.map(type => ({ type }));
|
|
184
|
+
result = {
|
|
185
|
+
type: "object",
|
|
186
|
+
oneOf: _oneOf.map(t => getJSONSchemaObject(t))
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
else if (record) {
|
|
185
190
|
result = {
|
|
186
191
|
type: "object",
|
|
187
|
-
|
|
192
|
+
...(record.values && !record.keysEnum && { additionalProperties: getJSONSchemaObject(record.values) }),
|
|
193
|
+
...(record.keysEnum && { properties: record.keysEnum.reduce((a, v) => ({
|
|
194
|
+
...a,
|
|
195
|
+
[v]: !record.values ? { type: {} } : getJSONSchemaObject(record.values)
|
|
196
|
+
}), {}) })
|
|
188
197
|
};
|
|
189
198
|
}
|
|
190
199
|
if (nullable) {
|
|
@@ -30,7 +30,9 @@ export namespace JSONB {
|
|
|
30
30
|
type: DataType;
|
|
31
31
|
allowedValues?: any[];
|
|
32
32
|
oneOf?: undefined;
|
|
33
|
+
oneOfType?: undefined;
|
|
33
34
|
arrayOf?: undefined;
|
|
35
|
+
arrayOfType?: undefined;
|
|
34
36
|
enum?: undefined;
|
|
35
37
|
};
|
|
36
38
|
|
|
@@ -38,7 +40,9 @@ export namespace JSONB {
|
|
|
38
40
|
type: ObjectSchema;
|
|
39
41
|
allowedValues?: undefined;
|
|
40
42
|
oneOf?: undefined;
|
|
43
|
+
oneOfType?: undefined;
|
|
41
44
|
arrayOf?: undefined;
|
|
45
|
+
arrayOfType?: undefined;
|
|
42
46
|
enum?: undefined;
|
|
43
47
|
}
|
|
44
48
|
|
|
@@ -46,32 +50,61 @@ export namespace JSONB {
|
|
|
46
50
|
type?: undefined;
|
|
47
51
|
enum: readonly any[];
|
|
48
52
|
oneOf?: undefined;
|
|
53
|
+
oneOfType?: undefined;
|
|
49
54
|
arrayOf?: undefined;
|
|
55
|
+
arrayOfType?: undefined;
|
|
50
56
|
allowedValues?: undefined;
|
|
51
57
|
};
|
|
52
58
|
|
|
53
59
|
export type OneOf = BaseOptions & {
|
|
54
60
|
type?: undefined;
|
|
55
|
-
oneOf: readonly ObjectSchema[];
|
|
56
61
|
arrayOf?: undefined;
|
|
62
|
+
arrayOfType?: undefined;
|
|
57
63
|
allowedValues?: undefined;
|
|
58
64
|
enum?: undefined;
|
|
59
|
-
}
|
|
65
|
+
} & ({
|
|
66
|
+
oneOf?: undefined;
|
|
67
|
+
oneOfType: readonly ObjectSchema[];
|
|
68
|
+
} | {
|
|
69
|
+
oneOf: FieldType[];
|
|
70
|
+
oneOfType?: undefined;
|
|
71
|
+
})
|
|
60
72
|
export type ArrayOf = BaseOptions & {
|
|
61
73
|
type?: undefined;
|
|
62
|
-
arrayOf: ObjectSchema;
|
|
63
74
|
allowedValues?: undefined;
|
|
64
75
|
oneOf?: undefined;
|
|
76
|
+
oneOfType?: undefined;
|
|
65
77
|
enum?: undefined;
|
|
66
|
-
}
|
|
78
|
+
} & ({
|
|
79
|
+
arrayOf?: undefined;
|
|
80
|
+
arrayOfType: ObjectSchema;
|
|
81
|
+
} | {
|
|
82
|
+
arrayOf: FieldType;
|
|
83
|
+
arrayOfType?: undefined;
|
|
84
|
+
});
|
|
67
85
|
|
|
86
|
+
export type RecordType = BaseOptions & {
|
|
87
|
+
type?: undefined;
|
|
88
|
+
allowedValues?: undefined;
|
|
89
|
+
oneOf?: undefined;
|
|
90
|
+
oneOfType?: undefined;
|
|
91
|
+
arrayOf?: undefined;
|
|
92
|
+
arrayOfType?: undefined;
|
|
93
|
+
enum?: undefined;
|
|
94
|
+
record: {
|
|
95
|
+
keysEnum?: readonly string[];
|
|
96
|
+
values?: FieldType;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
68
99
|
|
|
69
|
-
export type FieldTypeObj =
|
|
100
|
+
export type FieldTypeObj = StrictUnion<
|
|
70
101
|
| BasicType
|
|
71
102
|
| ObjectType
|
|
72
103
|
| EnumType
|
|
73
104
|
| OneOf
|
|
74
|
-
| ArrayOf
|
|
105
|
+
| ArrayOf
|
|
106
|
+
| RecordType
|
|
107
|
+
>;
|
|
75
108
|
|
|
76
109
|
export type FieldType =
|
|
77
110
|
| DataType
|
|
@@ -79,7 +112,7 @@ export namespace JSONB {
|
|
|
79
112
|
|
|
80
113
|
|
|
81
114
|
export type GetType<T extends FieldType | Omit<FieldTypeObj, "optional">> =
|
|
82
|
-
| T extends { type: ObjectSchema } ?
|
|
115
|
+
| T extends { type: ObjectSchema } ? GetObjectType<T["type"]> :
|
|
83
116
|
| T extends "number" | { type: "number" } ? number :
|
|
84
117
|
| T extends "boolean" | { type: "boolean" } ? boolean :
|
|
85
118
|
| T extends "integer" | { type: "integer" } ? number :
|
|
@@ -90,20 +123,35 @@ export namespace JSONB {
|
|
|
90
123
|
| T extends "integer[]" | { type: "integer[]" } ? number[] :
|
|
91
124
|
| T extends "string[]" | { type: "string[]" } ? string[] :
|
|
92
125
|
| T extends "any[]" | { type: "any[]" } ? any[] :
|
|
93
|
-
| T extends { enum: readonly any[] } ? T["enum"][number] :
|
|
126
|
+
| T extends { "enum": readonly any[] } ? T["enum"][number] :
|
|
127
|
+
| T extends { "record": RecordType["record"] } ? Record<
|
|
128
|
+
T["record"] extends { keysEnum: readonly string[] }? T["record"]["keysEnum"][number] : string,
|
|
129
|
+
T["record"] extends { values: FieldType }? GetType<T["record"]["values"]> : any
|
|
130
|
+
> :
|
|
94
131
|
|
|
95
|
-
| T extends { oneOf:
|
|
132
|
+
| T extends { oneOf: FieldType[] } ? StrictUnion<GetType<T["oneOf"][number]>> :
|
|
133
|
+
| T extends { oneOf: readonly ObjectSchema[] } ? StrictUnion<GetType<T["oneOf"][number]>> :
|
|
96
134
|
|
|
97
|
-
| T extends { arrayOf: ObjectSchema } ?
|
|
135
|
+
| T extends { arrayOf: ObjectSchema } ? GetType<T["arrayOf"]>[] :
|
|
136
|
+
| T extends { arrayOfType: ObjectSchema } ? GetType<T["arrayOfType"]>[] :
|
|
98
137
|
any;
|
|
99
138
|
|
|
100
139
|
type IsOptional<F extends FieldType> = F extends DataType? false : F extends { optional: true }? true : false;
|
|
101
140
|
|
|
141
|
+
const _r: GetType<{ record: { keysEnum: ["a", "b"], values: "integer[]" } }> = {
|
|
142
|
+
a: [2],
|
|
143
|
+
b: [221]
|
|
144
|
+
}
|
|
102
145
|
|
|
103
146
|
export type ObjectSchema = Record<string, FieldType>;
|
|
104
147
|
export type JSONBSchema = Omit<FieldTypeObj, "optional">;
|
|
105
148
|
|
|
106
|
-
|
|
149
|
+
const _dd: JSONBSchema = {
|
|
150
|
+
enum: [1],
|
|
151
|
+
type: "any"
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export type GetObjectType<S extends ObjectSchema> = (
|
|
107
155
|
{
|
|
108
156
|
[K in keyof S as IsOptional<S[K]> extends true ? K : never]?: GetType<S[K]>
|
|
109
157
|
} & {
|
|
@@ -119,9 +167,9 @@ const s: JSONB.JSONBSchema = {
|
|
|
119
167
|
type: {
|
|
120
168
|
a: { type: "boolean" },
|
|
121
169
|
c: { type: { c1: { type: "string" } } },
|
|
122
|
-
arr: {
|
|
170
|
+
arr: { arrayOfType: { d: "string" } },
|
|
123
171
|
o: {
|
|
124
|
-
|
|
172
|
+
oneOfType: [
|
|
125
173
|
{ z: { type: "integer" } },
|
|
126
174
|
{ z1: { type: "integer" } }
|
|
127
175
|
]
|
|
@@ -129,7 +177,7 @@ const s: JSONB.JSONBSchema = {
|
|
|
129
177
|
}
|
|
130
178
|
};
|
|
131
179
|
|
|
132
|
-
const
|
|
180
|
+
const _ss: JSONB.SchemaObject<typeof s> = {
|
|
133
181
|
a: true,
|
|
134
182
|
arr: [{ d: "" }],
|
|
135
183
|
c: {
|
|
@@ -167,7 +215,7 @@ export function validate<T>(obj: T, key: keyof T, rawFieldType: JSONB.FieldType)
|
|
|
167
215
|
return true
|
|
168
216
|
}
|
|
169
217
|
|
|
170
|
-
export function validateSchema<S extends JSONB.ObjectSchema>(schema: S, obj: JSONB.
|
|
218
|
+
export function validateSchema<S extends JSONB.ObjectSchema>(schema: S, obj: JSONB.GetObjectType<S>, objName?: string, optional = false) {
|
|
171
219
|
if ((!schema || isEmpty(schema)) && !optional) throw new Error(`Expecting ${objName} to be defined`);
|
|
172
220
|
getKeys(schema).forEach(k => validate(obj as any, k, schema[k]));
|
|
173
221
|
}
|
|
@@ -175,63 +223,60 @@ export function validateSchema<S extends JSONB.ObjectSchema>(schema: S, obj: JSO
|
|
|
175
223
|
|
|
176
224
|
type ColOpts = { nullable?: boolean };
|
|
177
225
|
|
|
178
|
-
|
|
179
|
-
|
|
226
|
+
|
|
227
|
+
export function getJSONBSchemaTSTypes(schema: JSONB.JSONBSchema, colOpts: ColOpts, leading = ""): string {
|
|
228
|
+
|
|
229
|
+
const getFieldType = (rawFieldType: JSONB.FieldType, isOneOf = false, leading = ""): string => {
|
|
180
230
|
const fieldType = getFieldTypeObj(rawFieldType);
|
|
181
231
|
const nullType = (fieldType.nullable ? `null | ` : "");
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
return nullType + correctType
|
|
189
|
-
} else {
|
|
190
|
-
return nullType + getSchemaTSTypes(fieldType.type, "", true)
|
|
232
|
+
|
|
233
|
+
/** Primitives */
|
|
234
|
+
if (typeof fieldType?.type === "string") {
|
|
235
|
+
const correctType = fieldType.type.replace("integer", "number");
|
|
236
|
+
if (fieldType.allowedValues && fieldType.type.endsWith("[]")) {
|
|
237
|
+
return nullType + ` (${fieldType.allowedValues.map(v => JSON.stringify(v)).join(" | ")})[]`
|
|
191
238
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
239
|
+
return nullType + correctType;
|
|
240
|
+
|
|
241
|
+
/** Object */
|
|
242
|
+
} else if (isObject(fieldType.type)) {
|
|
243
|
+
const { type } = fieldType;
|
|
244
|
+
const spacing = isOneOf ? " " : " ";
|
|
245
|
+
let objDef = `${leading}{ \n` + getKeys(type).map(k => {
|
|
246
|
+
const fieldType = getFieldTypeObj(type[k]);
|
|
247
|
+
return `${leading}${spacing}${k}${fieldType.optional ? "?" : ""}: ` + getFieldType(fieldType, isOneOf) + ";";
|
|
248
|
+
}).join("\n") + ` \n${leading}}${isOneOf ? "" : ";"}`;
|
|
249
|
+
|
|
250
|
+
/** Keep single line */
|
|
251
|
+
if (isOneOf){
|
|
252
|
+
objDef = objDef.split("\n").join("");
|
|
253
|
+
}
|
|
254
|
+
return nullType + objDef;
|
|
202
255
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
return `${leading}${spacing}${k}${fieldType.optional ? "?" : ""}: ` + getFieldType(fieldType) + ";";
|
|
206
|
-
}).join("\n") + ` \n${leading}}${isOneOf ? "" : ";"}`;
|
|
256
|
+
} else if (fieldType?.enum) {
|
|
257
|
+
return nullType + fieldType.enum.map(v => asValue(v)).join(" | ");
|
|
207
258
|
|
|
208
|
-
|
|
209
|
-
|
|
259
|
+
} else if (fieldType?.oneOf || fieldType?.oneOfType) {
|
|
260
|
+
const oneOf = fieldType?.oneOf || fieldType?.oneOfType.map(type => ({ type }));
|
|
261
|
+
return (fieldType.nullable ? `\n${leading} | null` : "") + oneOf.map(v => `\n${leading} | ` + getFieldType(v, true)).join("");
|
|
210
262
|
|
|
211
|
-
|
|
212
|
-
}
|
|
263
|
+
} else if (fieldType?.arrayOf || fieldType?.arrayOfType) {
|
|
264
|
+
const arrayOf = fieldType?.arrayOf || { type: fieldType?.arrayOfType };
|
|
265
|
+
return (fieldType.nullable ? `null | ` : "") + getFieldType(arrayOf, true) + "[]";
|
|
213
266
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
} else if (schema.enum) {
|
|
218
|
-
return (colOpts.nullable ? `\n${leading} | null` : "") + schema.enum.map(v => asValue(v)).join(" | ")
|
|
219
|
-
} else if (schema.oneOf) {
|
|
220
|
-
return (colOpts.nullable ? `\n${leading} | null` : "") + schema.oneOf.map(s => `\n${leading} | ` + getSchemaTSTypes(s, "", true)).join("")
|
|
221
|
-
} else {
|
|
222
|
-
if(typeof schema.type === "string"){
|
|
223
|
-
return (colOpts.nullable ? `null | ` : "") + schema.type;
|
|
224
|
-
} else if(schema.type){
|
|
225
|
-
return (colOpts.nullable ? `null | ` : "") + getSchemaTSTypes(schema.type, leading, isOneOf);
|
|
226
|
-
}
|
|
267
|
+
} else if (fieldType?.record) {
|
|
268
|
+
const { keysEnum, values } = fieldType.record;
|
|
269
|
+
return `${fieldType.nullable ? `null |` : ""} Record<${keysEnum?.map(v => asValue(v)).join(" | ") ?? "string"}, ${!values? "any" : getFieldType(values, true)}>`
|
|
227
270
|
|
|
228
|
-
|
|
229
|
-
}
|
|
271
|
+
} else throw "Unexpected getSchemaTSTypes: " + JSON.stringify({ fieldType, schema }, null, 2)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return getFieldType({ ...schema as any, nullable: colOpts.nullable }, undefined, leading);
|
|
230
275
|
}
|
|
231
276
|
|
|
232
277
|
|
|
233
278
|
const getJSONSchemaObject = (rawType: JSONB.FieldType | JSONB.JSONBSchema, rootInfo?: { id: string }): JSONSchema7 => {
|
|
234
|
-
const { type, arrayOf, description, nullable, oneOf, title, ...t } =
|
|
279
|
+
const { type, arrayOf, arrayOfType, description, nullable, oneOf, oneOfType, title, record, ...t } =
|
|
235
280
|
typeof rawType === "string"? ({ type: rawType } satisfies JSONB.FieldTypeObj) :
|
|
236
281
|
rawType;
|
|
237
282
|
|
|
@@ -246,16 +291,15 @@ const getJSONSchemaObject = (rawType: JSONB.FieldType | JSONB.JSONBSchema, rootI
|
|
|
246
291
|
partialProps.type = typeof t.enum[0]! as any;
|
|
247
292
|
}
|
|
248
293
|
|
|
249
|
-
if(typeof type === "string" || arrayOf){
|
|
294
|
+
if(typeof type === "string" || arrayOf || arrayOfType){
|
|
250
295
|
|
|
251
296
|
/** ARRAY */
|
|
252
297
|
if(type && typeof type !== "string") {
|
|
253
298
|
throw "Not expected";
|
|
254
299
|
}
|
|
255
|
-
if(arrayOf || type?.endsWith("[]")){
|
|
256
|
-
|
|
300
|
+
if(arrayOf || arrayOfType || type?.endsWith("[]")){
|
|
257
301
|
const arrayItems =
|
|
258
|
-
arrayOf? getJSONSchemaObject({ type:
|
|
302
|
+
(arrayOf || arrayOfType)? getJSONSchemaObject(arrayOf || { type: arrayOfType }) :
|
|
259
303
|
type?.startsWith("any")? { type: undefined } :
|
|
260
304
|
{
|
|
261
305
|
type: type?.slice(0, -2) as JSONSchema7TypeName,
|
|
@@ -288,10 +332,20 @@ const getJSONSchemaObject = (rawType: JSONB.FieldType | JSONB.JSONBSchema, rootI
|
|
|
288
332
|
}
|
|
289
333
|
}, {}),
|
|
290
334
|
}
|
|
291
|
-
} else if(oneOf){
|
|
335
|
+
} else if(oneOf || oneOfType){
|
|
336
|
+
const _oneOf = oneOf || oneOfType!.map(type => ({ type }))
|
|
337
|
+
result = {
|
|
338
|
+
type: "object",
|
|
339
|
+
oneOf: _oneOf.map(t => getJSONSchemaObject(t))
|
|
340
|
+
}
|
|
341
|
+
} else if(record){
|
|
292
342
|
result = {
|
|
293
343
|
type: "object",
|
|
294
|
-
|
|
344
|
+
...(record.values && !record.keysEnum && { additionalProperties: getJSONSchemaObject(record.values) }),
|
|
345
|
+
...(record.keysEnum && { properties: record.keysEnum.reduce((a, v) => ({
|
|
346
|
+
...a,
|
|
347
|
+
[v]: !record.values? { type: {} } : getJSONSchemaObject(record.values)
|
|
348
|
+
}), {}) })
|
|
295
349
|
}
|
|
296
350
|
}
|
|
297
351
|
|