prostgles-server 3.0.90 → 3.0.91
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 +28 -14
- package/dist/JSONBValidation/validate_jsonb_schema_sql.js.map +1 -1
- package/dist/JSONBValidation/validation.d.ts +34 -13
- package/dist/JSONBValidation/validation.d.ts.map +1 -1
- package/dist/JSONBValidation/validation.js +45 -54
- 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 +28 -14
- package/lib/JSONBValidation/validate_jsonb_schema_sql.ts +28 -14
- package/lib/JSONBValidation/validation.d.ts +34 -13
- package/lib/JSONBValidation/validation.d.ts.map +1 -1
- package/lib/JSONBValidation/validation.js +45 -54
- package/lib/JSONBValidation/validation.ts +85 -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 +29 -8
- package/tests/server/index.js +4 -4
- package/tests/server/index.ts +4 -4
- package/tests/server/package-lock.json +1 -1
|
@@ -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,47 @@ 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
|
|
|
68
86
|
|
|
69
|
-
export type FieldTypeObj =
|
|
87
|
+
export type FieldTypeObj = StrictUnion<
|
|
70
88
|
| BasicType
|
|
71
89
|
| ObjectType
|
|
72
90
|
| EnumType
|
|
73
91
|
| OneOf
|
|
74
|
-
| ArrayOf
|
|
92
|
+
| ArrayOf
|
|
93
|
+
>;
|
|
75
94
|
|
|
76
95
|
export type FieldType =
|
|
77
96
|
| DataType
|
|
@@ -79,7 +98,7 @@ export namespace JSONB {
|
|
|
79
98
|
|
|
80
99
|
|
|
81
100
|
export type GetType<T extends FieldType | Omit<FieldTypeObj, "optional">> =
|
|
82
|
-
| T extends { type: ObjectSchema } ?
|
|
101
|
+
| T extends { type: ObjectSchema } ? GetObjectType<T["type"]> :
|
|
83
102
|
| T extends "number" | { type: "number" } ? number :
|
|
84
103
|
| T extends "boolean" | { type: "boolean" } ? boolean :
|
|
85
104
|
| T extends "integer" | { type: "integer" } ? number :
|
|
@@ -90,11 +109,13 @@ export namespace JSONB {
|
|
|
90
109
|
| T extends "integer[]" | { type: "integer[]" } ? number[] :
|
|
91
110
|
| T extends "string[]" | { type: "string[]" } ? string[] :
|
|
92
111
|
| T extends "any[]" | { type: "any[]" } ? any[] :
|
|
93
|
-
| T extends { enum: readonly any[] } ? T["enum"][number] :
|
|
112
|
+
| T extends { "enum": readonly any[] } ? T["enum"][number] :
|
|
94
113
|
|
|
95
|
-
| T extends { oneOf:
|
|
114
|
+
| T extends { oneOf: FieldType[] } ? StrictUnion<GetType<T["oneOf"][number]>> :
|
|
115
|
+
| T extends { oneOf: readonly ObjectSchema[] } ? StrictUnion<GetType<T["oneOf"][number]>> :
|
|
96
116
|
|
|
97
|
-
| T extends { arrayOf: ObjectSchema } ?
|
|
117
|
+
| T extends { arrayOf: ObjectSchema } ? GetType<T["arrayOf"]>[] :
|
|
118
|
+
| T extends { arrayOfType: ObjectSchema } ? GetType<T["arrayOfType"]>[] :
|
|
98
119
|
any;
|
|
99
120
|
|
|
100
121
|
type IsOptional<F extends FieldType> = F extends DataType? false : F extends { optional: true }? true : false;
|
|
@@ -103,7 +124,12 @@ export namespace JSONB {
|
|
|
103
124
|
export type ObjectSchema = Record<string, FieldType>;
|
|
104
125
|
export type JSONBSchema = Omit<FieldTypeObj, "optional">;
|
|
105
126
|
|
|
106
|
-
|
|
127
|
+
const dd: JSONBSchema = {
|
|
128
|
+
enum: [1],
|
|
129
|
+
type: "any"
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export type GetObjectType<S extends ObjectSchema> = (
|
|
107
133
|
{
|
|
108
134
|
[K in keyof S as IsOptional<S[K]> extends true ? K : never]?: GetType<S[K]>
|
|
109
135
|
} & {
|
|
@@ -119,9 +145,9 @@ const s: JSONB.JSONBSchema = {
|
|
|
119
145
|
type: {
|
|
120
146
|
a: { type: "boolean" },
|
|
121
147
|
c: { type: { c1: { type: "string" } } },
|
|
122
|
-
arr: {
|
|
148
|
+
arr: { arrayOfType: { d: "string" } },
|
|
123
149
|
o: {
|
|
124
|
-
|
|
150
|
+
oneOfType: [
|
|
125
151
|
{ z: { type: "integer" } },
|
|
126
152
|
{ z1: { type: "integer" } }
|
|
127
153
|
]
|
|
@@ -167,7 +193,7 @@ export function validate<T>(obj: T, key: keyof T, rawFieldType: JSONB.FieldType)
|
|
|
167
193
|
return true
|
|
168
194
|
}
|
|
169
195
|
|
|
170
|
-
export function validateSchema<S extends JSONB.ObjectSchema>(schema: S, obj: JSONB.
|
|
196
|
+
export function validateSchema<S extends JSONB.ObjectSchema>(schema: S, obj: JSONB.GetObjectType<S>, objName?: string, optional = false) {
|
|
171
197
|
if ((!schema || isEmpty(schema)) && !optional) throw new Error(`Expecting ${objName} to be defined`);
|
|
172
198
|
getKeys(schema).forEach(k => validate(obj as any, k, schema[k]));
|
|
173
199
|
}
|
|
@@ -175,63 +201,56 @@ export function validateSchema<S extends JSONB.ObjectSchema>(schema: S, obj: JSO
|
|
|
175
201
|
|
|
176
202
|
type ColOpts = { nullable?: boolean };
|
|
177
203
|
|
|
178
|
-
|
|
179
|
-
|
|
204
|
+
|
|
205
|
+
export function getJSONBSchemaTSTypes(schema: JSONB.JSONBSchema, colOpts: ColOpts, leading = ""): string {
|
|
206
|
+
|
|
207
|
+
const getFieldType = (rawFieldType: JSONB.FieldType, isOneOf = false): string => {
|
|
180
208
|
const fieldType = getFieldTypeObj(rawFieldType);
|
|
181
209
|
const nullType = (fieldType.nullable ? `null | ` : "");
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
return nullType + correctType
|
|
189
|
-
} else {
|
|
190
|
-
return nullType + getSchemaTSTypes(fieldType.type, "", true)
|
|
210
|
+
|
|
211
|
+
/** Primitives */
|
|
212
|
+
if (typeof fieldType?.type === "string") {
|
|
213
|
+
const correctType = fieldType.type.replace("integer", "number");
|
|
214
|
+
if (fieldType.allowedValues && fieldType.type.endsWith("[]")) {
|
|
215
|
+
return nullType + ` (${fieldType.allowedValues.map(v => JSON.stringify(v)).join(" | ")})[]`
|
|
191
216
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
217
|
+
return nullType + correctType;
|
|
218
|
+
|
|
219
|
+
/** Object */
|
|
220
|
+
} else if (isObject(fieldType.type)) {
|
|
221
|
+
const { type } = fieldType;
|
|
222
|
+
const spacing = isOneOf ? " " : " ";
|
|
223
|
+
let objDef = `${leading}{ \n` + getKeys(type).map(k => {
|
|
224
|
+
const fieldType = getFieldTypeObj(type[k]);
|
|
225
|
+
return `${leading}${spacing}${k}${fieldType.optional ? "?" : ""}: ` + getFieldType(fieldType) + ";";
|
|
226
|
+
}).join("\n") + ` \n${leading}}${isOneOf ? "" : ";"}`;
|
|
227
|
+
|
|
228
|
+
/** Keep single line */
|
|
229
|
+
if (isOneOf){
|
|
230
|
+
objDef = objDef.split("\n").join("");
|
|
231
|
+
}
|
|
232
|
+
return nullType + objDef;
|
|
207
233
|
|
|
208
|
-
|
|
209
|
-
|
|
234
|
+
} else if (fieldType?.enum) {
|
|
235
|
+
return nullType + fieldType.enum.map(v => asValue(v)).join(" | ");
|
|
210
236
|
|
|
211
|
-
|
|
212
|
-
}
|
|
237
|
+
} else if (fieldType?.oneOf || fieldType?.oneOfType) {
|
|
238
|
+
const oneOf = fieldType?.oneOf || fieldType?.oneOfType.map(type => ({ type }));
|
|
239
|
+
return (fieldType.nullable ? `\n${leading} | null` : "") + oneOf.map(v => `\n${leading} | ` + getFieldType(v)).join("");
|
|
213
240
|
|
|
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
|
-
}
|
|
241
|
+
} else if (fieldType?.arrayOf || fieldType?.arrayOfType) {
|
|
242
|
+
const arrayOf = fieldType?.arrayOf || { type: fieldType?.arrayOfType };
|
|
243
|
+
return (fieldType.nullable ? `\n${leading} | null` : "") + getFieldType(arrayOf) + "[]";
|
|
227
244
|
|
|
228
|
-
|
|
229
|
-
}
|
|
245
|
+
} else throw "Unexpected getSchemaTSTypes: " + JSON.stringify({ fieldType, schema }, null, 2)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return getFieldType({ ...schema as any, nullable: colOpts.nullable });
|
|
230
249
|
}
|
|
231
250
|
|
|
232
251
|
|
|
233
252
|
const getJSONSchemaObject = (rawType: JSONB.FieldType | JSONB.JSONBSchema, rootInfo?: { id: string }): JSONSchema7 => {
|
|
234
|
-
const { type, arrayOf, description, nullable, oneOf, title, ...t } =
|
|
253
|
+
const { type, arrayOf, arrayOfType, description, nullable, oneOf, oneOfType, title, ...t } =
|
|
235
254
|
typeof rawType === "string"? ({ type: rawType } satisfies JSONB.FieldTypeObj) :
|
|
236
255
|
rawType;
|
|
237
256
|
|
|
@@ -246,16 +265,15 @@ const getJSONSchemaObject = (rawType: JSONB.FieldType | JSONB.JSONBSchema, rootI
|
|
|
246
265
|
partialProps.type = typeof t.enum[0]! as any;
|
|
247
266
|
}
|
|
248
267
|
|
|
249
|
-
if(typeof type === "string" || arrayOf){
|
|
268
|
+
if(typeof type === "string" || arrayOf || arrayOfType){
|
|
250
269
|
|
|
251
270
|
/** ARRAY */
|
|
252
271
|
if(type && typeof type !== "string") {
|
|
253
272
|
throw "Not expected";
|
|
254
273
|
}
|
|
255
|
-
if(arrayOf || type?.endsWith("[]")){
|
|
256
|
-
|
|
274
|
+
if(arrayOf || arrayOfType || type?.endsWith("[]")){
|
|
257
275
|
const arrayItems =
|
|
258
|
-
arrayOf? getJSONSchemaObject({ type:
|
|
276
|
+
(arrayOf || arrayOfType)? getJSONSchemaObject(arrayOf || { type: arrayOfType }) :
|
|
259
277
|
type?.startsWith("any")? { type: undefined } :
|
|
260
278
|
{
|
|
261
279
|
type: type?.slice(0, -2) as JSONSchema7TypeName,
|
|
@@ -288,10 +306,11 @@ const getJSONSchemaObject = (rawType: JSONB.FieldType | JSONB.JSONBSchema, rootI
|
|
|
288
306
|
}
|
|
289
307
|
}, {}),
|
|
290
308
|
}
|
|
291
|
-
} else if(oneOf){
|
|
309
|
+
} else if(oneOf || oneOfType){
|
|
310
|
+
const _oneOf = oneOf || oneOfType!.map(type => ({ type }))
|
|
292
311
|
result = {
|
|
293
312
|
type: "object",
|
|
294
|
-
oneOf:
|
|
313
|
+
oneOf: _oneOf.map(t => getJSONSchemaObject(t))
|
|
295
314
|
}
|
|
296
315
|
}
|
|
297
316
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PubSubManager.d.ts","sourceRoot":"","sources":["PubSubManager.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAc,MAAM,eAAe,CAAC;AAClH,OAAO,EAAE,EAAE,EAAe,MAAM,cAAc,CAAC;AAO/C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAU,GAAG,EAAW,SAAS,
|
|
1
|
+
{"version":3,"file":"PubSubManager.d.ts","sourceRoot":"","sources":["PubSubManager.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAc,MAAM,eAAe,CAAC;AAClH,OAAO,EAAE,EAAE,EAAe,MAAM,cAAc,CAAC;AAO/C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAU,GAAG,EAAW,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE7F,OAAO,EAAE,iBAAiB,EAAY,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,SAAS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"}
|
|
@@ -37,7 +37,7 @@ const pgPromise = __importStar(require("pg-promise"));
|
|
|
37
37
|
const prostgles_types_1 = require("prostgles-types");
|
|
38
38
|
const SyncReplication_1 = require("../SyncReplication");
|
|
39
39
|
const util_1 = require("prostgles-types/dist/util");
|
|
40
|
-
|
|
40
|
+
const pgp = pgPromise({
|
|
41
41
|
promiseLib: Bluebird
|
|
42
42
|
});
|
|
43
43
|
const asValue = (v) => pgp.as.format("$1", [v]);
|
|
@@ -332,8 +332,8 @@ class PubSubManager {
|
|
|
332
332
|
return;
|
|
333
333
|
}
|
|
334
334
|
/* Throttle the subscriptions */
|
|
335
|
-
for (
|
|
336
|
-
|
|
335
|
+
for (let i = 0; i < subs.length; i++) {
|
|
336
|
+
const sub = subs[i];
|
|
337
337
|
if (this.dbo[sub.table_name] &&
|
|
338
338
|
sub.is_ready &&
|
|
339
339
|
(sub.socket_id && this.sockets[sub.socket_id]) || sub.func) {
|
|
@@ -425,7 +425,7 @@ class PubSubManager {
|
|
|
425
425
|
*/
|
|
426
426
|
async addSync(syncParams) {
|
|
427
427
|
const { socket = null, table_info = null, table_rules, synced_field = null, allow_delete = false, id_fields = [], filter = {}, params, condition = "", throttle = 0 } = syncParams || {};
|
|
428
|
-
|
|
428
|
+
const conditionParsed = parseCondition(condition);
|
|
429
429
|
if (!socket || !table_info)
|
|
430
430
|
throw "socket or table_info missing";
|
|
431
431
|
const { name: table_name } = table_info, channel_name = `${this.socketChannelPreffix}.${table_name}.${JSON.stringify(filter)}.sync`;
|
|
@@ -433,7 +433,7 @@ class PubSubManager {
|
|
|
433
433
|
throw "synced_field missing from table_rules";
|
|
434
434
|
this.upsertSocket(socket, channel_name);
|
|
435
435
|
const upsertSync = () => {
|
|
436
|
-
|
|
436
|
+
const newSync = {
|
|
437
437
|
channel_name,
|
|
438
438
|
table_name,
|
|
439
439
|
filter,
|
|
@@ -509,7 +509,7 @@ class PubSubManager {
|
|
|
509
509
|
return newSync;
|
|
510
510
|
};
|
|
511
511
|
// const { min_id, max_id, count, max_synced } = params;
|
|
512
|
-
|
|
512
|
+
const _sync = upsertSync();
|
|
513
513
|
await this.addTrigger({ table_name, condition: conditionParsed });
|
|
514
514
|
return channel_name;
|
|
515
515
|
}
|
|
@@ -625,7 +625,7 @@ class PubSubManager {
|
|
|
625
625
|
}
|
|
626
626
|
}
|
|
627
627
|
removeLocalSub(table_name, condition, func) {
|
|
628
|
-
|
|
628
|
+
const cond = parseCondition(condition);
|
|
629
629
|
if ((0, utils_1.get)(this.subs, [table_name, cond, "subs"])) {
|
|
630
630
|
this.subs[table_name][cond].subs.map((sub, i) => {
|
|
631
631
|
if (sub.func && sub.func === func) {
|
|
@@ -638,7 +638,7 @@ class PubSubManager {
|
|
|
638
638
|
}
|
|
639
639
|
}
|
|
640
640
|
getActiveListeners = () => {
|
|
641
|
-
|
|
641
|
+
const result = [];
|
|
642
642
|
const upsert = (t, c) => {
|
|
643
643
|
if (!result.find(r => r.table_name === t && r.condition === c)) {
|
|
644
644
|
result.push({ table_name: t, condition: c });
|
|
@@ -692,6 +692,7 @@ class PubSubManager {
|
|
|
692
692
|
});
|
|
693
693
|
}
|
|
694
694
|
if (!socket) {
|
|
695
|
+
// Do nothing
|
|
695
696
|
}
|
|
696
697
|
else if (!channel_name) {
|
|
697
698
|
delete this.sockets[socket.id];
|
|
@@ -712,7 +713,7 @@ class PubSubManager {
|
|
|
712
713
|
AND table_name = 'hypertable' \
|
|
713
714
|
);", { schema });
|
|
714
715
|
if (res.exists) {
|
|
715
|
-
|
|
716
|
+
const isHyperTable = await this.db.any("SELECT * FROM " + (0, prostgles_types_1.asName)(schema) + ".hypertable WHERE table_name = ${table_name};", { table_name, schema });
|
|
716
717
|
if (isHyperTable && isHyperTable.length) {
|
|
717
718
|
throw "Triggers do not work on timescaledb hypertables due to bug:\nhttps://github.com/timescale/timescaledb/issues/1084";
|
|
718
719
|
}
|
|
@@ -737,7 +738,8 @@ class PubSubManager {
|
|
|
737
738
|
addTriggerPool = undefined;
|
|
738
739
|
async addTrigger(params, viewOptions) {
|
|
739
740
|
try {
|
|
740
|
-
|
|
741
|
+
const { table_name } = { ...params };
|
|
742
|
+
let { condition } = { ...params };
|
|
741
743
|
if (!table_name)
|
|
742
744
|
throw "MISSING table_name";
|
|
743
745
|
if (!this.appID)
|
|
@@ -783,7 +785,7 @@ class PubSubManager {
|
|
|
783
785
|
}
|
|
784
786
|
}
|
|
785
787
|
exports.PubSubManager = PubSubManager;
|
|
786
|
-
const parseCondition = (condition) =>
|
|
788
|
+
const parseCondition = (condition) => condition && condition.trim().length ? condition : "TRUE";
|
|
787
789
|
var prostgles_types_2 = require("prostgles-types");
|
|
788
790
|
Object.defineProperty(exports, "pickKeys", { enumerable: true, get: function () { return prostgles_types_2.pickKeys; } });
|
|
789
791
|
Object.defineProperty(exports, "omitKeys", { enumerable: true, get: function () { return prostgles_types_2.omitKeys; } });
|
|
@@ -13,7 +13,7 @@ import * as Bluebird from "bluebird";
|
|
|
13
13
|
import * as pgPromise from 'pg-promise';
|
|
14
14
|
import pg from 'pg-promise/typescript/pg-subset';
|
|
15
15
|
|
|
16
|
-
import { SelectParams, FieldFilter, asName, WAL, isEmpty, AnyObject
|
|
16
|
+
import { SelectParams, FieldFilter, asName, WAL, isEmpty, AnyObject } from "prostgles-types";
|
|
17
17
|
|
|
18
18
|
import { ClientExpressData, syncData } from "../SyncReplication";
|
|
19
19
|
import { TableRule } from "../PublishParser";
|
|
@@ -21,7 +21,7 @@ import { find } from "prostgles-types/dist/util";
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
type PGP = pgPromise.IMain<{}, pg.IClient>;
|
|
24
|
-
|
|
24
|
+
const pgp: PGP = pgPromise({
|
|
25
25
|
promiseLib: Bluebird
|
|
26
26
|
});
|
|
27
27
|
export const asValue = (v: any) => pgp.as.format("$1", [v]);
|
|
@@ -453,8 +453,8 @@ export class PubSubManager {
|
|
|
453
453
|
}
|
|
454
454
|
|
|
455
455
|
/* Throttle the subscriptions */
|
|
456
|
-
for (
|
|
457
|
-
|
|
456
|
+
for (let i = 0; i < subs.length; i++) {
|
|
457
|
+
const sub = subs[i];
|
|
458
458
|
if (
|
|
459
459
|
this.dbo[sub.table_name] &&
|
|
460
460
|
sub.is_ready &&
|
|
@@ -563,7 +563,7 @@ export class PubSubManager {
|
|
|
563
563
|
params, condition = "", throttle = 0
|
|
564
564
|
} = syncParams || {};
|
|
565
565
|
|
|
566
|
-
|
|
566
|
+
const conditionParsed = parseCondition(condition);
|
|
567
567
|
if (!socket || !table_info) throw "socket or table_info missing";
|
|
568
568
|
|
|
569
569
|
|
|
@@ -575,7 +575,7 @@ export class PubSubManager {
|
|
|
575
575
|
this.upsertSocket(socket, channel_name);
|
|
576
576
|
|
|
577
577
|
const upsertSync = () => {
|
|
578
|
-
|
|
578
|
+
const newSync = {
|
|
579
579
|
channel_name,
|
|
580
580
|
table_name,
|
|
581
581
|
filter,
|
|
@@ -662,7 +662,7 @@ export class PubSubManager {
|
|
|
662
662
|
|
|
663
663
|
// const { min_id, max_id, count, max_synced } = params;
|
|
664
664
|
|
|
665
|
-
|
|
665
|
+
const _sync = upsertSync();
|
|
666
666
|
|
|
667
667
|
await this.addTrigger({ table_name, condition: conditionParsed });
|
|
668
668
|
|
|
@@ -808,7 +808,7 @@ export class PubSubManager {
|
|
|
808
808
|
}
|
|
809
809
|
|
|
810
810
|
removeLocalSub(table_name: string, condition: string, func: (items: object[]) => any) {
|
|
811
|
-
|
|
811
|
+
const cond = parseCondition(condition);
|
|
812
812
|
if (get(this.subs, [table_name, cond, "subs"])) {
|
|
813
813
|
this.subs[table_name][cond].subs.map((sub, i) => {
|
|
814
814
|
if (
|
|
@@ -823,7 +823,7 @@ export class PubSubManager {
|
|
|
823
823
|
}
|
|
824
824
|
|
|
825
825
|
getActiveListeners = (): { table_name: string; condition: string }[] => {
|
|
826
|
-
|
|
826
|
+
const result: { table_name: string; condition: string }[] = [];
|
|
827
827
|
const upsert = (t: string, c: string) => {
|
|
828
828
|
if (!result.find(r => r.table_name === t && r.condition === c)) {
|
|
829
829
|
result.push({ table_name: t, condition: c });
|
|
@@ -886,7 +886,7 @@ export class PubSubManager {
|
|
|
886
886
|
}
|
|
887
887
|
|
|
888
888
|
if (!socket) {
|
|
889
|
-
|
|
889
|
+
// Do nothing
|
|
890
890
|
} else if (!channel_name) {
|
|
891
891
|
delete this.sockets[socket.id];
|
|
892
892
|
} else {
|
|
@@ -909,7 +909,7 @@ export class PubSubManager {
|
|
|
909
909
|
AND table_name = 'hypertable' \
|
|
910
910
|
);", { schema });
|
|
911
911
|
if (res.exists) {
|
|
912
|
-
|
|
912
|
+
const isHyperTable = await this.db.any("SELECT * FROM " + asName(schema) + ".hypertable WHERE table_name = ${table_name};", { table_name, schema });
|
|
913
913
|
if (isHyperTable && isHyperTable.length) {
|
|
914
914
|
throw "Triggers do not work on timescaledb hypertables due to bug:\nhttps://github.com/timescale/timescaledb/issues/1084"
|
|
915
915
|
}
|
|
@@ -939,7 +939,8 @@ export class PubSubManager {
|
|
|
939
939
|
async addTrigger(params: { table_name: string; condition: string; }, viewOptions?: ViewSubscriptionOptions) {
|
|
940
940
|
try {
|
|
941
941
|
|
|
942
|
-
|
|
942
|
+
const { table_name } = { ...params }
|
|
943
|
+
let { condition } = { ...params }
|
|
943
944
|
if (!table_name) throw "MISSING table_name";
|
|
944
945
|
if (!this.appID) throw "MISSING appID";
|
|
945
946
|
|
|
@@ -999,6 +1000,6 @@ export class PubSubManager {
|
|
|
999
1000
|
}
|
|
1000
1001
|
|
|
1001
1002
|
|
|
1002
|
-
const parseCondition = (condition: string): string =>
|
|
1003
|
+
const parseCondition = (condition: string): string => condition && condition.trim().length ? condition : "TRUE"
|
|
1003
1004
|
|
|
1004
1005
|
export { pickKeys, omitKeys } from "prostgles-types"
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SessionUser } from "./AuthHandler";
|
|
2
|
-
import { ProstglesInitOptions
|
|
3
|
-
declare function prostgles<S = void, SUser extends SessionUser = SessionUser>(params: ProstglesInitOptions<S, SUser>): Promise<InitResult>;
|
|
2
|
+
import { ProstglesInitOptions } from "./Prostgles";
|
|
3
|
+
declare function prostgles<S = void, SUser extends SessionUser = SessionUser>(params: ProstglesInitOptions<S, SUser>): Promise<import("./Prostgles").InitResult>;
|
|
4
4
|
export = prostgles;
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAa,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAa,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE9D,iBAAS,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,SAAS,WAAW,GAAG,WAAW,EAAE,MAAM,EAAE,oBAAoB,CAAC,CAAC,EAAE,KAAK,CAAC,6CAI3G;AACD,SAAS,SAAS,CAAC"}
|
package/lib/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SessionUser } from "./AuthHandler";
|
|
2
|
-
import { Prostgles, ProstglesInitOptions
|
|
2
|
+
import { Prostgles, ProstglesInitOptions } from "./Prostgles";
|
|
3
3
|
|
|
4
4
|
function prostgles<S = void, SUser extends SessionUser = SessionUser>(params: ProstglesInitOptions<S, SUser>){
|
|
5
5
|
|
package/package.json
CHANGED
package/tests/client/PID.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
412208
|
|
@@ -377,20 +377,41 @@ export type DBSchemaGenerated = {
|
|
|
377
377
|
arrStr?: null | string[];
|
|
378
378
|
o?:
|
|
379
379
|
| null
|
|
380
|
-
|
|
|
381
|
-
|
|
380
|
+
| {
|
|
381
|
+
o1: number;
|
|
382
|
+
};
|
|
383
|
+
| {
|
|
384
|
+
o2: boolean;
|
|
385
|
+
};;
|
|
382
386
|
};
|
|
383
387
|
jsonOneOf?:
|
|
384
388
|
| null
|
|
385
|
-
|
|
|
386
|
-
|
|
389
|
+
| {
|
|
390
|
+
command: 'a';
|
|
391
|
+
};
|
|
392
|
+
| {
|
|
393
|
+
command: 'b';
|
|
394
|
+
option: number[];
|
|
395
|
+
};
|
|
387
396
|
status?:
|
|
388
397
|
| null
|
|
389
|
-
|
|
|
390
|
-
|
|
391
|
-
|
|
398
|
+
| {
|
|
399
|
+
ok: string;
|
|
400
|
+
};
|
|
401
|
+
| {
|
|
402
|
+
err: string;
|
|
403
|
+
};
|
|
404
|
+
| {
|
|
405
|
+
loading: {
|
|
406
|
+
loaded: number;
|
|
407
|
+
total: number;
|
|
408
|
+
};;
|
|
409
|
+
};
|
|
392
410
|
table_config?: null | {
|
|
393
|
-
referencedTables?:
|
|
411
|
+
referencedTables?: {
|
|
412
|
+
name: string;
|
|
413
|
+
minFiles: number;
|
|
414
|
+
};[];
|
|
394
415
|
};
|
|
395
416
|
};
|
|
396
417
|
};
|
package/tests/server/index.js
CHANGED
|
@@ -108,7 +108,7 @@ function dd() {
|
|
|
108
108
|
arr1: { enum: [1, 2, 3] },
|
|
109
109
|
arr2: { type: "integer[]" },
|
|
110
110
|
arrStr: { type: "string[]", optional: true, nullable: true },
|
|
111
|
-
o: { optional: true, nullable: true,
|
|
111
|
+
o: { optional: true, nullable: true, oneOfType: [
|
|
112
112
|
{ o1: "integer" },
|
|
113
113
|
{ o2: "boolean" }
|
|
114
114
|
] },
|
|
@@ -118,7 +118,7 @@ function dd() {
|
|
|
118
118
|
status: {
|
|
119
119
|
nullable: true,
|
|
120
120
|
jsonbSchema: {
|
|
121
|
-
|
|
121
|
+
oneOfType: [
|
|
122
122
|
{ ok: { type: "string" } },
|
|
123
123
|
{ err: { type: "string" } },
|
|
124
124
|
{
|
|
@@ -134,7 +134,7 @@ function dd() {
|
|
|
134
134
|
jsonOneOf: {
|
|
135
135
|
nullable: true,
|
|
136
136
|
jsonbSchema: {
|
|
137
|
-
|
|
137
|
+
oneOfType: [
|
|
138
138
|
{ command: { enum: ["a"] } },
|
|
139
139
|
{
|
|
140
140
|
command: { enum: ["b"] },
|
|
@@ -144,7 +144,7 @@ function dd() {
|
|
|
144
144
|
}
|
|
145
145
|
},
|
|
146
146
|
table_config: { nullable: true, jsonbSchemaType: {
|
|
147
|
-
referencedTables: { optional: true,
|
|
147
|
+
referencedTables: { optional: true, arrayOfType: { name: "string", minFiles: "number" } },
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
}
|