proto.io 0.0.147 → 0.0.149
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/adapters/file/database.d.ts +2 -2
- package/dist/adapters/file/database.js +2 -2
- package/dist/adapters/file/database.mjs +2 -2
- package/dist/adapters/file/filesystem.d.ts +2 -2
- package/dist/adapters/file/google-cloud-storage.d.ts +2 -2
- package/dist/adapters/storage/progres.d.ts +3 -1
- package/dist/adapters/storage/progres.js +6 -3
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +6 -3
- package/dist/adapters/storage/progres.mjs.map +1 -1
- package/dist/client.d.ts +3 -5
- package/dist/client.js +2 -2
- package/dist/client.mjs +3 -3
- package/dist/index.d.ts +3 -5
- package/dist/index.js +73 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -65
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{index-EOtjV6U_.mjs → index-BmRuvHVZ.mjs} +11 -1
- package/dist/internals/index-BmRuvHVZ.mjs.map +1 -0
- package/dist/internals/index-BqFdBhFc.js.map +1 -1
- package/dist/internals/{index-BDB4idmt.d.ts → index-BuXVzVd8.d.ts} +3 -2
- package/dist/internals/index-BuXVzVd8.d.ts.map +1 -0
- package/dist/internals/index-CKgKjs8z.d.ts +60 -0
- package/dist/internals/index-CKgKjs8z.d.ts.map +1 -0
- package/dist/internals/{index-DZS2c96L.js → index-CSNRyhjB.js} +2 -2
- package/dist/internals/{index-DZS2c96L.js.map → index-CSNRyhjB.js.map} +1 -1
- package/dist/internals/{index-C6zdNpc_.js → index-CVutVPmd.js} +11 -1
- package/dist/internals/{index-C6zdNpc_.js.map → index-CVutVPmd.js.map} +1 -1
- package/dist/internals/{index-CT01T3qs.js → index-D1YGwuNK.js} +26 -4
- package/dist/internals/index-D1YGwuNK.js.map +1 -0
- package/dist/internals/{index-BWztjrw_.d.ts → index-DnREUbmG.d.ts} +9 -90
- package/dist/internals/index-DnREUbmG.d.ts.map +1 -0
- package/dist/internals/index-be1VYBY2.mjs.map +1 -1
- package/dist/internals/{index-Do-zNOpD.mjs → index-c-CaNuVY.mjs} +26 -4
- package/dist/internals/index-c-CaNuVY.mjs.map +1 -0
- package/dist/internals/{index-DTZ5uRgF.mjs → index-tU-lsQqj.mjs} +2 -2
- package/dist/internals/{index-DTZ5uRgF.mjs.map → index-tU-lsQqj.mjs.map} +1 -1
- package/dist/internals/{random-XGNkddOu.js → random-DBDmz54D.js} +3 -3
- package/dist/internals/{random-XGNkddOu.js.map → random-DBDmz54D.js.map} +1 -1
- package/dist/internals/{random-BjV_01xP.mjs → random-KZTFMK9-.mjs} +3 -3
- package/dist/internals/{random-BjV_01xP.mjs.map → random-KZTFMK9-.mjs.map} +1 -1
- package/package.json +4 -4
- package/dist/internals/index-BDB4idmt.d.ts.map +0 -1
- package/dist/internals/index-BWztjrw_.d.ts.map +0 -1
- package/dist/internals/index-CT01T3qs.js.map +0 -1
- package/dist/internals/index-Do-zNOpD.mjs.map +0 -1
- package/dist/internals/index-EOtjV6U_.mjs.map +0 -1
- package/dist/internals/index-bbPCIbir.d.ts +0 -116
- package/dist/internals/index-bbPCIbir.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import { Server } from '@o2ter/server-js';
|
|
3
|
-
import { Q as QueryValidator, g as generateId } from './internals/random-
|
|
3
|
+
import { Q as QueryValidator, g as generateId } from './internals/random-KZTFMK9-.mjs';
|
|
4
4
|
import { P as PVK } from './internals/private-BUpLAMZi.mjs';
|
|
5
5
|
import { asyncStream, asyncIterableToArray, isBinaryData, base64ToBuffer } from '@o2ter/utils-js';
|
|
6
|
-
import { T as TQuery, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, P as ProtoType, s as serialize, d as deserialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-
|
|
7
|
-
export { c as ProtoClient, e as classExtends, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser } from './internals/index-
|
|
8
|
-
import { d as decodeUpdateOp, T as TObject, i as isShape, a as isPointer, b as isRelation, c as defaultObjectKeyTypes, e as isPrimitive } from './internals/index-
|
|
6
|
+
import { T as TQuery, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, P as ProtoType, s as serialize, d as deserialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-c-CaNuVY.mjs';
|
|
7
|
+
export { c as ProtoClient, e as classExtends, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser } from './internals/index-c-CaNuVY.mjs';
|
|
8
|
+
import { d as decodeUpdateOp, T as TObject, i as isShape, a as isPointer, b as isRelation, c as defaultObjectKeyTypes, e as isPrimitive } from './internals/index-BmRuvHVZ.mjs';
|
|
9
9
|
import jwt from 'jsonwebtoken';
|
|
10
10
|
import { Blob } from 'node:buffer';
|
|
11
11
|
import { Readable } from 'node:stream';
|
|
12
12
|
import { scrypt } from 'node:crypto';
|
|
13
13
|
import { promisify } from 'util';
|
|
14
14
|
import { randomBytes, randomUUID } from '@o2ter/crypto-js';
|
|
15
|
-
import { Q as QuerySelector } from './internals/index-
|
|
15
|
+
import { Q as QuerySelector } from './internals/index-tU-lsQqj.mjs';
|
|
16
16
|
import queryType from 'query-types';
|
|
17
17
|
import busboy from 'busboy';
|
|
18
18
|
export { Decimal } from 'decimal.js';
|
|
@@ -135,12 +135,22 @@ const dispatcher = (proto, options, disableSecurity) => {
|
|
|
135
135
|
const _matches = _validator.decodeMatches(options.className, options.matches ?? {}, _includes);
|
|
136
136
|
if (!_validator.validateCLPs(options.className, 'create'))
|
|
137
137
|
throw Error('No permission');
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
138
|
+
const _attrs = normalize(_validator.validateFields(options.className, attrs, 'create', QueryValidator.patterns.path));
|
|
139
|
+
while (true) {
|
|
140
|
+
try {
|
|
141
|
+
return await proto.storage.atomic((storage) => storage.insert({
|
|
142
|
+
className: options.className,
|
|
143
|
+
includes: _includes,
|
|
144
|
+
matches: _matches,
|
|
145
|
+
objectIdSize: proto[PVK].options.objectIdSize
|
|
146
|
+
}, _attrs), { lockTable: options.className });
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
if (proto.storage.isDuplicateIdError(e))
|
|
150
|
+
continue;
|
|
151
|
+
throw e;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
144
154
|
},
|
|
145
155
|
async insertMany(options, values) {
|
|
146
156
|
QueryValidator.recursiveCheck(values);
|
|
@@ -149,12 +159,22 @@ const dispatcher = (proto, options, disableSecurity) => {
|
|
|
149
159
|
const _matches = _validator.decodeMatches(options.className, options.matches ?? {}, _includes);
|
|
150
160
|
if (!_validator.validateCLPs(options.className, 'create'))
|
|
151
161
|
throw Error('No permission');
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
162
|
+
const _attrs = normalize(_.map(values, attr => _validator.validateFields(options.className, attr, 'create', QueryValidator.patterns.path)));
|
|
163
|
+
while (true) {
|
|
164
|
+
try {
|
|
165
|
+
return await proto.storage.atomic((storage) => storage.insertMany({
|
|
166
|
+
className: options.className,
|
|
167
|
+
includes: _includes,
|
|
168
|
+
matches: _matches,
|
|
169
|
+
objectIdSize: proto[PVK].options.objectIdSize
|
|
170
|
+
}, _attrs), { lockTable: options.className });
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
if (proto.storage.isDuplicateIdError(e))
|
|
174
|
+
continue;
|
|
175
|
+
throw e;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
158
178
|
},
|
|
159
179
|
async updateOne(query, update) {
|
|
160
180
|
QueryValidator.recursiveCheck(query, update);
|
|
@@ -168,7 +188,19 @@ const dispatcher = (proto, options, disableSecurity) => {
|
|
|
168
188
|
const _validator = await validator();
|
|
169
189
|
if (!_validator.validateCLPs(query.className, 'create', 'update'))
|
|
170
190
|
throw Error('No permission');
|
|
171
|
-
|
|
191
|
+
const _query = _validator.decodeQuery(normalize(query), 'update');
|
|
192
|
+
const _update = normalize(_validator.validateFields(query.className, update, 'update', QueryValidator.patterns.path));
|
|
193
|
+
const _setOnInsert = normalize(_validator.validateFields(query.className, setOnInsert, 'create', QueryValidator.patterns.name));
|
|
194
|
+
while (true) {
|
|
195
|
+
try {
|
|
196
|
+
return await proto.storage.atomic((storage) => storage.upsertOne(_query, _update, _setOnInsert));
|
|
197
|
+
}
|
|
198
|
+
catch (e) {
|
|
199
|
+
if (proto.storage.isDuplicateIdError(e))
|
|
200
|
+
continue;
|
|
201
|
+
throw e;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
172
204
|
},
|
|
173
205
|
async deleteOne(query) {
|
|
174
206
|
QueryValidator.recursiveCheck(query);
|
|
@@ -316,9 +348,10 @@ class ProtoQuery extends TQuery {
|
|
|
316
348
|
});
|
|
317
349
|
}
|
|
318
350
|
async insert(attrs, options) {
|
|
319
|
-
const beforeSave = this._proto[PVK].triggers?.beforeSave?.[this.className];
|
|
320
|
-
const afterSave = this._proto[PVK].triggers?.afterSave?.[this.className];
|
|
321
351
|
const context = options?.context ?? {};
|
|
352
|
+
const silent = _.castArray(options?.silent ?? []);
|
|
353
|
+
const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[PVK].triggers?.beforeSave?.[this.className];
|
|
354
|
+
const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[PVK].triggers?.afterSave?.[this.className];
|
|
322
355
|
const object = this._proto.Object(this.className);
|
|
323
356
|
for (const [key, value] of _.toPairs(attrs)) {
|
|
324
357
|
object[PVK].mutated[key] = { $set: value };
|
|
@@ -329,7 +362,7 @@ class ProtoQuery extends TQuery {
|
|
|
329
362
|
className: this.className,
|
|
330
363
|
includes: this[PVK].options.includes,
|
|
331
364
|
matches: this[PVK].options.matches,
|
|
332
|
-
}, _.fromPairs([...object.
|
|
365
|
+
}, _.fromPairs([...object._set_entries()])));
|
|
333
366
|
if (!result)
|
|
334
367
|
throw Error('Unable to insert document');
|
|
335
368
|
if (_.isFunction(afterSave)) {
|
|
@@ -338,9 +371,10 @@ class ProtoQuery extends TQuery {
|
|
|
338
371
|
return result;
|
|
339
372
|
}
|
|
340
373
|
async insertMany(values, options) {
|
|
341
|
-
const beforeSave = this._proto[PVK].triggers?.beforeSave?.[this.className];
|
|
342
|
-
const afterSave = this._proto[PVK].triggers?.afterSave?.[this.className];
|
|
343
374
|
const context = options?.context ?? {};
|
|
375
|
+
const silent = _.castArray(options?.silent ?? []);
|
|
376
|
+
const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[PVK].triggers?.beforeSave?.[this.className];
|
|
377
|
+
const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[PVK].triggers?.afterSave?.[this.className];
|
|
344
378
|
if (_.isFunction(beforeSave) || _.isFunction(afterSave)) {
|
|
345
379
|
const objects = _.map(values, attr => {
|
|
346
380
|
const object = this._proto.Object(this.className);
|
|
@@ -358,7 +392,7 @@ class ProtoQuery extends TQuery {
|
|
|
358
392
|
className: this.className,
|
|
359
393
|
includes: this[PVK].options.includes,
|
|
360
394
|
matches: this[PVK].options.matches,
|
|
361
|
-
}, _.map(objects, x => _.fromPairs([...x.
|
|
395
|
+
}, _.map(objects, x => _.fromPairs([...x._set_entries()])));
|
|
362
396
|
if (_.isFunction(afterSave)) {
|
|
363
397
|
await Promise.all(_.map(objects, object => afterSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
|
|
364
398
|
}
|
|
@@ -371,9 +405,10 @@ class ProtoQuery extends TQuery {
|
|
|
371
405
|
}, values);
|
|
372
406
|
}
|
|
373
407
|
async updateOne(update, options) {
|
|
374
|
-
const beforeSave = this._proto[PVK].triggers?.beforeSave?.[this.className];
|
|
375
|
-
const afterSave = this._proto[PVK].triggers?.afterSave?.[this.className];
|
|
376
408
|
const context = options?.context ?? {};
|
|
409
|
+
const silent = _.castArray(options?.silent ?? []);
|
|
410
|
+
const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[PVK].triggers?.beforeSave?.[this.className];
|
|
411
|
+
const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[PVK].triggers?.afterSave?.[this.className];
|
|
377
412
|
if (_.isFunction(beforeSave)) {
|
|
378
413
|
const object = this._objectMethods(_.first(await asyncIterableToArray(this._dispatcher(options).find({ ...this._queryOptions, limit: 1 }))));
|
|
379
414
|
if (!object)
|
|
@@ -389,9 +424,10 @@ class ProtoQuery extends TQuery {
|
|
|
389
424
|
return result;
|
|
390
425
|
}
|
|
391
426
|
async upsertOne(update, setOnInsert, options) {
|
|
392
|
-
const beforeSave = this._proto[PVK].triggers?.beforeSave?.[this.className];
|
|
393
|
-
const afterSave = this._proto[PVK].triggers?.afterSave?.[this.className];
|
|
394
427
|
const context = options?.context ?? {};
|
|
428
|
+
const silent = _.castArray(options?.silent ?? []);
|
|
429
|
+
const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[PVK].triggers?.beforeSave?.[this.className];
|
|
430
|
+
const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[PVK].triggers?.afterSave?.[this.className];
|
|
395
431
|
if (_.isFunction(beforeSave)) {
|
|
396
432
|
let object = this._objectMethods(_.first(await asyncIterableToArray(this._dispatcher(options).find({ ...this._queryOptions, limit: 1 }))));
|
|
397
433
|
if (object) {
|
|
@@ -426,9 +462,10 @@ class ProtoQuery extends TQuery {
|
|
|
426
462
|
return result;
|
|
427
463
|
}
|
|
428
464
|
async deleteOne(options) {
|
|
429
|
-
const beforeDelete = this._proto[PVK].triggers?.beforeDelete?.[this.className];
|
|
430
|
-
const afterDelete = this._proto[PVK].triggers?.afterDelete?.[this.className];
|
|
431
465
|
const context = options?.context ?? {};
|
|
466
|
+
const silent = _.castArray(options?.silent ?? []);
|
|
467
|
+
const beforeDelete = _.includes(silent, 'beforeDelete') ? null : this._proto[PVK].triggers?.beforeDelete?.[this.className];
|
|
468
|
+
const afterDelete = _.includes(silent, 'afterDelete') ? null : this._proto[PVK].triggers?.afterDelete?.[this.className];
|
|
432
469
|
let result;
|
|
433
470
|
if (_.isFunction(beforeDelete)) {
|
|
434
471
|
const object = this._objectMethods(_.first(await asyncIterableToArray(this._dispatcher(options).find({ ...this._queryOptions, limit: 1 }))));
|
|
@@ -449,9 +486,10 @@ class ProtoQuery extends TQuery {
|
|
|
449
486
|
return result;
|
|
450
487
|
}
|
|
451
488
|
async deleteMany(options) {
|
|
452
|
-
const beforeDelete = this._proto[PVK].triggers?.beforeDelete?.[this.className];
|
|
453
|
-
const afterDelete = this._proto[PVK].triggers?.afterDelete?.[this.className];
|
|
454
489
|
const context = options?.context ?? {};
|
|
490
|
+
const silent = _.castArray(options?.silent ?? []);
|
|
491
|
+
const beforeDelete = _.includes(silent, 'beforeDelete') ? null : this._proto[PVK].triggers?.beforeDelete?.[this.className];
|
|
492
|
+
const afterDelete = _.includes(silent, 'afterDelete') ? null : this._proto[PVK].triggers?.afterDelete?.[this.className];
|
|
455
493
|
if (_.isFunction(beforeDelete) || _.isFunction(afterDelete)) {
|
|
456
494
|
const objects = this._objectMethods(await asyncIterableToArray(this._dispatcher(options).find(this._queryOptions)));
|
|
457
495
|
if (_.isEmpty(objects))
|
|
@@ -911,7 +949,7 @@ class ProtoInternal {
|
|
|
911
949
|
object.set('nonce', nonce);
|
|
912
950
|
const created = await proto.Query('File')
|
|
913
951
|
.includes(...object.keys())
|
|
914
|
-
.insert(_.fromPairs([...object.
|
|
952
|
+
.insert(_.fromPairs([...object._set_entries()]), options);
|
|
915
953
|
if (created) {
|
|
916
954
|
object[PVK].attributes = created.attributes;
|
|
917
955
|
object[PVK].mutated = {};
|
|
@@ -925,31 +963,16 @@ class ProtoInternal {
|
|
|
925
963
|
}
|
|
926
964
|
}
|
|
927
965
|
async saveFile(proto, object, options) {
|
|
928
|
-
const beforeSave = this.triggers?.beforeSaveFile;
|
|
929
|
-
const afterSave = this.triggers?.afterSaveFile;
|
|
930
|
-
const context = options?.context ?? {};
|
|
931
|
-
if (_.isFunction(beforeSave)) {
|
|
932
|
-
await beforeSave(proxy(Object.setPrototypeOf({ object, context }, proto)));
|
|
933
|
-
}
|
|
934
966
|
if (object.objectId) {
|
|
935
967
|
object = await this.updateFile(proto, object, options);
|
|
936
968
|
}
|
|
937
969
|
else {
|
|
938
970
|
object = await this.createFile(proto, object, options);
|
|
939
971
|
}
|
|
940
|
-
if (_.isFunction(afterSave)) {
|
|
941
|
-
await afterSave(proxy(Object.setPrototypeOf({ object, context }, proto)));
|
|
942
|
-
}
|
|
943
972
|
return object;
|
|
944
973
|
}
|
|
945
974
|
async deleteFile(proto, object, options) {
|
|
946
|
-
const beforeDelete = this.triggers?.beforeDeleteFile;
|
|
947
|
-
const afterDelete = this.triggers?.afterDeleteFile;
|
|
948
975
|
object = await object.fetchIfNeeded(['token'], options);
|
|
949
|
-
const context = options?.context ?? {};
|
|
950
|
-
if (_.isFunction(beforeDelete)) {
|
|
951
|
-
await beforeDelete(proxy(Object.setPrototypeOf({ object, context }, proto)));
|
|
952
|
-
}
|
|
953
976
|
const deleted = await proto.Query('File')
|
|
954
977
|
.equalTo('_id', object.objectId)
|
|
955
978
|
.deleteOne(options);
|
|
@@ -959,9 +982,6 @@ class ProtoInternal {
|
|
|
959
982
|
object[PVK].extra = {};
|
|
960
983
|
}
|
|
961
984
|
this.destroyFileData(proto, object.token);
|
|
962
|
-
if (_.isFunction(afterDelete)) {
|
|
963
|
-
await afterDelete(proxy(Object.setPrototypeOf({ object, context }, proto)));
|
|
964
|
-
}
|
|
965
985
|
return object;
|
|
966
986
|
}
|
|
967
987
|
fileData(proto, object, options) {
|
|
@@ -1264,6 +1284,7 @@ const schedule = (proto) => {
|
|
|
1264
1284
|
// THE SOFTWARE.
|
|
1265
1285
|
//
|
|
1266
1286
|
class ProtoService extends ProtoType {
|
|
1287
|
+
/** @internal */
|
|
1267
1288
|
[PVK];
|
|
1268
1289
|
_storage;
|
|
1269
1290
|
_schedule = schedule(this);
|
|
@@ -1409,18 +1430,6 @@ class ProtoService extends ProtoType {
|
|
|
1409
1430
|
this[PVK].triggers.afterDelete = {};
|
|
1410
1431
|
this[PVK].triggers.afterDelete[name] = callback;
|
|
1411
1432
|
}
|
|
1412
|
-
beforeSaveFile(callback) {
|
|
1413
|
-
this[PVK].triggers.beforeSaveFile = callback;
|
|
1414
|
-
}
|
|
1415
|
-
afterSaveFile(callback) {
|
|
1416
|
-
this[PVK].triggers.afterSaveFile = callback;
|
|
1417
|
-
}
|
|
1418
|
-
beforeDeleteFile(callback) {
|
|
1419
|
-
this[PVK].triggers.beforeDeleteFile = callback;
|
|
1420
|
-
}
|
|
1421
|
-
afterDeleteFile(callback) {
|
|
1422
|
-
this[PVK].triggers.afterDeleteFile = callback;
|
|
1423
|
-
}
|
|
1424
1433
|
lockTable(className, update) {
|
|
1425
1434
|
return this.storage.lockTable(className, update);
|
|
1426
1435
|
}
|
|
@@ -1587,11 +1596,11 @@ var classesRoute = (router, proto) => {
|
|
|
1587
1596
|
if (!_.includes(classes, name))
|
|
1588
1597
|
return res.sendStatus(404);
|
|
1589
1598
|
await response(res, async () => {
|
|
1590
|
-
const { operation, context, random, attributes, update, setOnInsert, ...options } = deserialize(req.body);
|
|
1599
|
+
const { operation, context, silent, random, attributes, update, setOnInsert, ...options } = deserialize(req.body);
|
|
1591
1600
|
const payload = proto.connect(req);
|
|
1592
1601
|
const query = payload.Query(name);
|
|
1593
1602
|
query[PVK].options = options;
|
|
1594
|
-
const opts = { master: payload.isMaster, context };
|
|
1603
|
+
const opts = { master: payload.isMaster, context, silent };
|
|
1595
1604
|
switch (operation) {
|
|
1596
1605
|
case 'explain':
|
|
1597
1606
|
if (!payload.isMaster)
|