prostgles-server 2.0.162 → 2.0.163
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/DboBuilder.d.ts +28 -3
- package/dist/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder.js +147 -64
- package/dist/DboBuilder.js.map +1 -1
- package/dist/Prostgles.d.ts +17 -2
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +1 -1
- package/dist/Prostgles.js.map +1 -1
- package/lib/DboBuilder.ts +184 -68
- package/lib/Prostgles.ts +19 -4
- package/package.json +2 -2
- package/tests/client/PID.txt +1 -1
- package/tests/client/package-lock.json +15 -15
- package/tests/client/package.json +1 -1
- package/tests/client_only_queries.js +29 -8
- package/tests/client_only_queries.ts +35 -9
- package/tests/isomorphic_queries.js +5 -2
- package/tests/isomorphic_queries.ts +12 -4
- package/tests/server/index.js +9 -0
- package/tests/server/index.ts +9 -0
- package/tests/server/package-lock.json +3 -3
package/lib/Prostgles.ts
CHANGED
|
@@ -107,6 +107,7 @@ export type UpdateRequestDataBatch = {
|
|
|
107
107
|
export type UpdateRequestData = UpdateRequestDataOne | UpdateRequestDataBatch;
|
|
108
108
|
|
|
109
109
|
export type ValidateRow = (row: AnyObject) => AnyObject | Promise<AnyObject>;
|
|
110
|
+
export type ValidateUpdateRow = (args: { update: AnyObject, filter: AnyObject }) => AnyObject | Promise<AnyObject>;
|
|
110
111
|
|
|
111
112
|
export type SelectRule = {
|
|
112
113
|
|
|
@@ -166,9 +167,21 @@ export type InsertRule = {
|
|
|
166
167
|
export type UpdateRule = {
|
|
167
168
|
|
|
168
169
|
/**
|
|
169
|
-
* Fields allowed to be updated. Tip: Use false to exclude field
|
|
170
|
+
* Fields allowed to be updated. Tip: Use false/0 to exclude field
|
|
170
171
|
*/
|
|
171
172
|
fields: FieldFilter;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Row level FGAC
|
|
176
|
+
* Used when the editable fields change based on the updated row
|
|
177
|
+
* If specified then the fields from the first matching filter table.count({ ...filter, ...updateFilter }) > 0 will be used
|
|
178
|
+
* If none matching then the "fields" will be used
|
|
179
|
+
* Specify in decreasing order of specificity otherwise a more general filter will match first
|
|
180
|
+
*/
|
|
181
|
+
dynamicFields?: {
|
|
182
|
+
filter: AnyObject;
|
|
183
|
+
fields: FieldFilter;
|
|
184
|
+
}[];
|
|
172
185
|
|
|
173
186
|
/**
|
|
174
187
|
* Filter added to every query (e.g. user_id) to restrict access
|
|
@@ -194,8 +207,10 @@ export type UpdateRule = {
|
|
|
194
207
|
/**
|
|
195
208
|
* Validation logic to check/update data for each request
|
|
196
209
|
*/
|
|
197
|
-
validate?:
|
|
198
|
-
|
|
210
|
+
validate?: ValidateUpdateRow;
|
|
211
|
+
|
|
212
|
+
};
|
|
213
|
+
|
|
199
214
|
export type DeleteRule = {
|
|
200
215
|
|
|
201
216
|
/**
|
|
@@ -1065,7 +1080,7 @@ const RULE_TO_METHODS = [
|
|
|
1065
1080
|
methods: RULE_METHODS.update,
|
|
1066
1081
|
no_limits: <UpdateRule>{ fields: "*", filterFields: "*", returningFields: "*" },
|
|
1067
1082
|
table_only: true,
|
|
1068
|
-
allowed_params: <Array<keyof UpdateRule>>["fields", "filterFields", "forcedFilter", "forcedData", "returningFields", "validate"] ,
|
|
1083
|
+
allowed_params: <Array<keyof UpdateRule>>["fields", "filterFields", "forcedFilter", "forcedData", "returningFields", "validate", "dynamicFields"] ,
|
|
1069
1084
|
hint: ` expecting "*" | true | { fields: string | string[] | {} }`
|
|
1070
1085
|
},
|
|
1071
1086
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.163",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"bluebird": "^3.7.2",
|
|
30
30
|
"file-type": "^16.5.3",
|
|
31
31
|
"pg-promise": "^10.11.1",
|
|
32
|
-
"prostgles-types": "^1.5.
|
|
32
|
+
"prostgles-types": "^1.5.134",
|
|
33
33
|
"sharp": "^0.30.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
package/tests/client/PID.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
18727
|
|
@@ -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.147",
|
|
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.147",
|
|
71
|
+
"resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.147.tgz",
|
|
72
|
+
"integrity": "sha512-OHKHn9/Ynv/v3QSB53ZvhVvWp4pWsrLIy8ZDXloQprB8IUXSS2SdCWnbdkBoD9JH9Z4tUBoq88lTdS7G1KZY3w==",
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"prostgles-types": "^1.5.
|
|
74
|
+
"prostgles-types": "^1.5.133"
|
|
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.133",
|
|
79
|
+
"resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.133.tgz",
|
|
80
|
+
"integrity": "sha512-WVSuoiWAo1hgDl+9QSBPVhszwhxuX1WRi6CdE4epede1eD2Q5rQfO22bli0BBCQXyhE6l/A0Tt6UxhAIlDDSmw=="
|
|
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.147",
|
|
180
|
+
"resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.147.tgz",
|
|
181
|
+
"integrity": "sha512-OHKHn9/Ynv/v3QSB53ZvhVvWp4pWsrLIy8ZDXloQprB8IUXSS2SdCWnbdkBoD9JH9Z4tUBoq88lTdS7G1KZY3w==",
|
|
182
182
|
"requires": {
|
|
183
|
-
"prostgles-types": "^1.5.
|
|
183
|
+
"prostgles-types": "^1.5.133"
|
|
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.133",
|
|
188
|
+
"resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.133.tgz",
|
|
189
|
+
"integrity": "sha512-WVSuoiWAo1hgDl+9QSBPVhszwhxuX1WRi6CdE4epede1eD2Q5rQfO22bli0BBCQXyhE6l/A0Tt6UxhAIlDDSmw=="
|
|
190
190
|
},
|
|
191
191
|
"socket.io-client": {
|
|
192
192
|
"version": "4.5.1",
|
|
@@ -170,6 +170,14 @@ async function client_only(db, auth, log, methods) {
|
|
|
170
170
|
{ id: 1, public: 'public data' },
|
|
171
171
|
{ id: 2, public: 'public data' }
|
|
172
172
|
]);
|
|
173
|
+
const cols = await db.insert_rules.getColumns();
|
|
174
|
+
assert_1.strict.equal(cols.filter(({ insert, update: u, select: s, delete: d }) => insert && !u && !s && !d).length, 3, "Validated getColumns failed");
|
|
175
|
+
/* Validated insert */
|
|
176
|
+
const expectB = await db.insert_rules.insert({ name: "a" }, { returning: "*" });
|
|
177
|
+
assert_1.strict.deepStrictEqual(expectB, { name: "b" }, "Validated insert failed");
|
|
178
|
+
/* forced UUID insert */
|
|
179
|
+
const row = await db.uuid_text.insert({}, { returning: "*" });
|
|
180
|
+
assert_1.strict.equal(row.id, 'c81089e1-c4c1-45d7-a73d-e2d613cb7c3e');
|
|
173
181
|
});
|
|
174
182
|
// await tryRun("Duplicate subscription", async () => {
|
|
175
183
|
// return new Promise(async (resolve, reject) => {
|
|
@@ -193,14 +201,6 @@ async function client_only(db, auth, log, methods) {
|
|
|
193
201
|
// });
|
|
194
202
|
// })
|
|
195
203
|
// })
|
|
196
|
-
const cols = await db.insert_rules.getColumns();
|
|
197
|
-
assert_1.strict.equal(cols.filter(({ insert, update: u, select: s, delete: d }) => insert && !u && !s && !d).length, 3, "Validated getColumns failed");
|
|
198
|
-
/* Validated insert */
|
|
199
|
-
const expectB = await db.insert_rules.insert({ name: "a" }, { returning: "*" });
|
|
200
|
-
assert_1.strict.deepStrictEqual(expectB, { name: "b" }, "Validated insert failed");
|
|
201
|
-
/* forced UUID insert */
|
|
202
|
-
const row = await db.uuid_text.insert({}, { returning: "*" });
|
|
203
|
-
assert_1.strict.equal(row.id, 'c81089e1-c4c1-45d7-a73d-e2d613cb7c3e');
|
|
204
204
|
await testRealtime();
|
|
205
205
|
// auth.login({ username: "john", password: "secret" });
|
|
206
206
|
// await tout();
|
|
@@ -214,6 +214,27 @@ async function client_only(db, auth, log, methods) {
|
|
|
214
214
|
{ id: 1, public: 'public data' },
|
|
215
215
|
{ id: 2, public: 'public data' }
|
|
216
216
|
]);
|
|
217
|
+
const dynamicCols = await db.uuid_text.getColumns(undefined, {
|
|
218
|
+
rule: "update",
|
|
219
|
+
filter: {
|
|
220
|
+
id: 'c81089e1-c4c1-45d7-a73d-e2d613cb7c3e'
|
|
221
|
+
},
|
|
222
|
+
data: {
|
|
223
|
+
id: "dwadwa"
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
assert_1.strict.equal(dynamicCols.length, 1);
|
|
227
|
+
assert_1.strict.equal(dynamicCols[0].name, "id");
|
|
228
|
+
const defaultCols = await db.uuid_text.getColumns(undefined, {
|
|
229
|
+
rule: "update",
|
|
230
|
+
filter: {
|
|
231
|
+
id: 'not matching'
|
|
232
|
+
},
|
|
233
|
+
data: {
|
|
234
|
+
id: "dwadwa"
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
throw defaultCols.map(c => c.name);
|
|
217
238
|
}, log);
|
|
218
239
|
}
|
|
219
240
|
}
|
|
@@ -201,6 +201,18 @@ export default async function client_only(db: DBHandlerClient, auth: Auth, log:
|
|
|
201
201
|
{ id: 1, public: 'public data' },
|
|
202
202
|
{ id: 2, public: 'public data' }
|
|
203
203
|
]);
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
const cols = await db.insert_rules.getColumns();
|
|
207
|
+
assert.equal(cols.filter(({ insert, update: u, select: s, delete: d }) => insert && !u && !s && !d).length, 3, "Validated getColumns failed")
|
|
208
|
+
|
|
209
|
+
/* Validated insert */
|
|
210
|
+
const expectB = await db.insert_rules.insert({ name: "a" }, { returning: "*" });
|
|
211
|
+
assert.deepStrictEqual(expectB, { name: "b" }, "Validated insert failed");
|
|
212
|
+
|
|
213
|
+
/* forced UUID insert */
|
|
214
|
+
const row: any = await db.uuid_text.insert({}, {returning: "*"});
|
|
215
|
+
assert.equal(row.id, 'c81089e1-c4c1-45d7-a73d-e2d613cb7c3e');
|
|
204
216
|
});
|
|
205
217
|
|
|
206
218
|
// await tryRun("Duplicate subscription", async () => {
|
|
@@ -228,16 +240,7 @@ export default async function client_only(db: DBHandlerClient, auth: Auth, log:
|
|
|
228
240
|
// })
|
|
229
241
|
// })
|
|
230
242
|
|
|
231
|
-
const cols = await db.insert_rules.getColumns();
|
|
232
|
-
assert.equal(cols.filter(({ insert, update: u, select: s, delete: d }) => insert && !u && !s && !d).length, 3, "Validated getColumns failed")
|
|
233
|
-
|
|
234
|
-
/* Validated insert */
|
|
235
|
-
const expectB = await db.insert_rules.insert({ name: "a" }, { returning: "*" });
|
|
236
|
-
assert.deepStrictEqual(expectB, { name: "b" }, "Validated insert failed");
|
|
237
243
|
|
|
238
|
-
/* forced UUID insert */
|
|
239
|
-
const row: any = await db.uuid_text.insert({}, {returning: "*"});
|
|
240
|
-
assert.equal(row.id, 'c81089e1-c4c1-45d7-a73d-e2d613cb7c3e')
|
|
241
244
|
|
|
242
245
|
await testRealtime();
|
|
243
246
|
|
|
@@ -254,6 +257,29 @@ export default async function client_only(db: DBHandlerClient, auth: Auth, log:
|
|
|
254
257
|
{ id: 1, public: 'public data' },
|
|
255
258
|
{ id: 2, public: 'public data' }
|
|
256
259
|
]);
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
const dynamicCols = await db.uuid_text.getColumns(undefined, {
|
|
263
|
+
rule: "update",
|
|
264
|
+
filter: {
|
|
265
|
+
id: 'c81089e1-c4c1-45d7-a73d-e2d613cb7c3e'
|
|
266
|
+
},
|
|
267
|
+
data: {
|
|
268
|
+
id: "dwadwa"
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
assert.equal(dynamicCols.length, 1);
|
|
272
|
+
assert.equal(dynamicCols[0].name, "id");
|
|
273
|
+
const defaultCols = await db.uuid_text.getColumns(undefined, {
|
|
274
|
+
rule: "update",
|
|
275
|
+
filter: {
|
|
276
|
+
id: 'not matching'
|
|
277
|
+
},
|
|
278
|
+
data: {
|
|
279
|
+
id: "dwadwa"
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
throw defaultCols.map(c => c.name);
|
|
257
283
|
}, log);
|
|
258
284
|
}
|
|
259
285
|
|
|
@@ -87,7 +87,7 @@ async function isomorphic(db) {
|
|
|
87
87
|
await tryRun("getColumns definition", async () => {
|
|
88
88
|
const res = await db.tr2.getColumns("fr");
|
|
89
89
|
// console.log(JSON.stringify(res, null, 2))
|
|
90
|
-
|
|
90
|
+
const expected = [
|
|
91
91
|
{
|
|
92
92
|
"label": "Id",
|
|
93
93
|
"name": "id",
|
|
@@ -180,7 +180,10 @@ async function isomorphic(db) {
|
|
|
180
180
|
"update": true,
|
|
181
181
|
"delete": true
|
|
182
182
|
}
|
|
183
|
-
]
|
|
183
|
+
];
|
|
184
|
+
assert_1.strict.deepStrictEqual(res, expected);
|
|
185
|
+
const resDynamic = await db.tr2.getColumns("fr", { rule: "update", filter: {}, data: { t2: "a" } });
|
|
186
|
+
assert_1.strict.deepStrictEqual(resDynamic, expected);
|
|
184
187
|
});
|
|
185
188
|
await tryRun("$unnest_words", async () => {
|
|
186
189
|
const res = await db.various.find({}, { returnType: "values", select: { name: "$unnest_words" } });
|
|
@@ -73,9 +73,7 @@ export default async function isomorphic(db: Partial<DbHandler> | Partial<DBHand
|
|
|
73
73
|
await tryRun("getColumns definition", async () => {
|
|
74
74
|
const res = await db.tr2.getColumns("fr");
|
|
75
75
|
// console.log(JSON.stringify(res, null, 2))
|
|
76
|
-
|
|
77
|
-
res,
|
|
78
|
-
[
|
|
76
|
+
const expected = [
|
|
79
77
|
{
|
|
80
78
|
"label": "Id",
|
|
81
79
|
"name": "id",
|
|
@@ -168,7 +166,17 @@ export default async function isomorphic(db: Partial<DbHandler> | Partial<DBHand
|
|
|
168
166
|
"update": true,
|
|
169
167
|
"delete": true
|
|
170
168
|
}
|
|
171
|
-
]
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
assert.deepStrictEqual(
|
|
172
|
+
res,
|
|
173
|
+
expected
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const resDynamic = await db.tr2.getColumns("fr", { rule: "update", filter: {}, data: { t2: "a" } });
|
|
177
|
+
assert.deepStrictEqual(
|
|
178
|
+
resDynamic,
|
|
179
|
+
expected
|
|
172
180
|
);
|
|
173
181
|
});
|
|
174
182
|
|
package/tests/server/index.js
CHANGED
|
@@ -268,6 +268,15 @@ const dbConnection = {
|
|
|
268
268
|
forcedData: {
|
|
269
269
|
id: 'c81089e1-c4c1-45d7-a73d-e2d613cb7c3e'
|
|
270
270
|
}
|
|
271
|
+
},
|
|
272
|
+
update: {
|
|
273
|
+
fields: [],
|
|
274
|
+
dynamicFields: [{
|
|
275
|
+
fields: { id: 1 },
|
|
276
|
+
filter: {
|
|
277
|
+
id: 'c81089e1-c4c1-45d7-a73d-e2d613cb7c3e'
|
|
278
|
+
}
|
|
279
|
+
}]
|
|
271
280
|
}
|
|
272
281
|
}
|
|
273
282
|
};
|
package/tests/server/index.ts
CHANGED
|
@@ -290,6 +290,15 @@ const dbConnection = {
|
|
|
290
290
|
forcedData: {
|
|
291
291
|
id: 'c81089e1-c4c1-45d7-a73d-e2d613cb7c3e'
|
|
292
292
|
}
|
|
293
|
+
},
|
|
294
|
+
update: {
|
|
295
|
+
fields: [],
|
|
296
|
+
dynamicFields: [{
|
|
297
|
+
fields: { id: 1 },
|
|
298
|
+
filter: {
|
|
299
|
+
id: 'c81089e1-c4c1-45d7-a73d-e2d613cb7c3e'
|
|
300
|
+
}
|
|
301
|
+
}]
|
|
293
302
|
}
|
|
294
303
|
}
|
|
295
304
|
};
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"../..": {
|
|
23
23
|
"name": "prostgles-server",
|
|
24
|
-
"version": "2.0.
|
|
24
|
+
"version": "2.0.162",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@aws-sdk/client-s3": "^3.95.0",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"bluebird": "^3.7.2",
|
|
30
30
|
"file-type": "^16.5.3",
|
|
31
31
|
"pg-promise": "^10.11.1",
|
|
32
|
-
"prostgles-types": "^1.5.
|
|
32
|
+
"prostgles-types": "^1.5.134",
|
|
33
33
|
"sharp": "^0.30.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
@@ -1371,7 +1371,7 @@
|
|
|
1371
1371
|
"bluebird": "^3.7.2",
|
|
1372
1372
|
"file-type": "^16.5.3",
|
|
1373
1373
|
"pg-promise": "^10.11.1",
|
|
1374
|
-
"prostgles-types": "^1.5.
|
|
1374
|
+
"prostgles-types": "^1.5.134",
|
|
1375
1375
|
"sharp": "^0.30.5",
|
|
1376
1376
|
"typescript": "^4.7.2"
|
|
1377
1377
|
}
|