proto.io 0.0.174 → 0.0.175
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.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 +1 -1
- package/dist/adapters/storage/progres.mjs +3 -3
- package/dist/client.d.ts +3 -3
- package/dist/client.js +1 -1
- package/dist/client.mjs +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +46 -311
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -316
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{index-uwXdnxqN.d.ts → index-B9CWU0y7.d.ts} +32 -2
- package/dist/internals/index-B9CWU0y7.d.ts.map +1 -0
- package/dist/internals/{index-R0gbIGc-.mjs → index-BPbXumUi.mjs} +18 -44
- package/dist/internals/index-BPbXumUi.mjs.map +1 -0
- package/dist/internals/{index-CGX3qcjQ.d.ts → index-BQqYdjaH.d.ts} +2 -2
- package/dist/internals/index-BQqYdjaH.d.ts.map +1 -0
- package/dist/internals/{index-CE5tdYK8.d.ts → index-BYZpj31o.d.ts} +17 -68
- package/dist/internals/index-BYZpj31o.d.ts.map +1 -0
- package/dist/internals/{index--ifyu-GL.mjs → index-CTsc042s.mjs} +2 -2
- package/dist/internals/{index--ifyu-GL.mjs.map → index-CTsc042s.mjs.map} +1 -1
- package/dist/internals/{index-S_gTMQBh.js → index-CvA0tbwx.js} +17 -43
- package/dist/internals/index-CvA0tbwx.js.map +1 -0
- package/dist/internals/{index-C3fbOqmn.mjs → index-DHQhYGsJ.mjs} +2 -2
- package/dist/internals/{index-C3fbOqmn.mjs.map → index-DHQhYGsJ.mjs.map} +1 -1
- package/dist/internals/{random-DPRG8oW6.mjs → random-BMQpRlGH.mjs} +3 -3
- package/dist/internals/{random-DPRG8oW6.mjs.map → random-BMQpRlGH.mjs.map} +1 -1
- package/package.json +1 -1
- package/dist/internals/index-CE5tdYK8.d.ts.map +0 -1
- package/dist/internals/index-CGX3qcjQ.d.ts.map +0 -1
- package/dist/internals/index-R0gbIGc-.mjs.map +0 -1
- package/dist/internals/index-S_gTMQBh.js.map +0 -1
- package/dist/internals/index-uwXdnxqN.d.ts.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TSchema, P as ProtoService } from '../../internals/index-
|
|
2
|
-
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-
|
|
1
|
+
import { T as TSchema, P as ProtoService } from '../../internals/index-BYZpj31o.js';
|
|
2
|
+
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-BQqYdjaH.js';
|
|
3
3
|
import '@o2ter/utils-js';
|
|
4
4
|
import 'jsonwebtoken';
|
|
5
5
|
import '@o2ter/server-js';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import { F as FileStorageBase } from '../../internals/index-be1VYBY2.mjs';
|
|
3
|
-
import { Q as QuerySelector } from '../../internals/index-
|
|
3
|
+
import { Q as QuerySelector } from '../../internals/index-DHQhYGsJ.mjs';
|
|
4
4
|
import { bufferToBase64, base64ToBuffer } from '@o2ter/utils-js';
|
|
5
5
|
import 'util';
|
|
6
6
|
import 'zlib';
|
|
7
7
|
import '../../internals/private-BUpLAMZi.mjs';
|
|
8
|
-
import '../../internals/index
|
|
8
|
+
import '../../internals/index-CTsc042s.mjs';
|
|
9
9
|
import 'decimal.js';
|
|
10
10
|
|
|
11
11
|
//
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as ProtoService } from '../../internals/index-
|
|
2
|
-
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-
|
|
1
|
+
import { P as ProtoService } from '../../internals/index-BYZpj31o.js';
|
|
2
|
+
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-BQqYdjaH.js';
|
|
3
3
|
import '@o2ter/utils-js';
|
|
4
4
|
import 'jsonwebtoken';
|
|
5
5
|
import '@o2ter/server-js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _google_cloud_storage from '@google-cloud/storage';
|
|
2
2
|
import { Storage } from '@google-cloud/storage';
|
|
3
|
-
import { P as ProtoService } from '../../internals/index-
|
|
4
|
-
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-
|
|
3
|
+
import { P as ProtoService } from '../../internals/index-BYZpj31o.js';
|
|
4
|
+
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-BQqYdjaH.js';
|
|
5
5
|
import '@o2ter/utils-js';
|
|
6
6
|
import 'jsonwebtoken';
|
|
7
7
|
import '@o2ter/server-js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Pool, PoolClient, PoolConfig } from 'pg';
|
|
2
|
-
import { _ as _TValue, o as EventData, T as TSchema, Q as QuerySelector, p as DecodedQuery, F as FindOptions, R as RelationOptions, q as DecodedSortOption, I as InsertOptions, r as TValue, t as FindOneOptions, u as TUpdateOp, v as FieldSelectorExpression, w as QueryExpression, x as TStorage, y as TransactionOptions, h as TObject, z as TQueryRandomOptions, A as TPubSub } from '../../internals/index-
|
|
2
|
+
import { _ as _TValue, o as EventData, T as TSchema, Q as QuerySelector, p as DecodedQuery, F as FindOptions, R as RelationOptions, q as DecodedSortOption, I as InsertOptions, r as TValue, t as FindOneOptions, u as TUpdateOp, v as FieldSelectorExpression, w as QueryExpression, x as TStorage, y as TransactionOptions, h as TObject, z as TQueryRandomOptions, A as TPubSub } from '../../internals/index-BYZpj31o.js';
|
|
3
3
|
import * as _o2ter_utils_js from '@o2ter/utils-js';
|
|
4
4
|
import { asyncStream } from '@o2ter/utils-js';
|
|
5
5
|
import 'jsonwebtoken';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import { i as isPointer, a as isRelation, b as isShape,
|
|
2
|
+
import { i as isPointer, a as isRelation, b as isShape, e as decodeUpdateOp, s as shapePaths, c as isPrimitive, T as TObject, f as isVector, _ as _encodeValue, g as _decodeValue, h as dimensionOf, j as _typeof } from '../../internals/index-CTsc042s.mjs';
|
|
3
3
|
import { Pool, types } from 'pg';
|
|
4
4
|
import QueryStream from 'pg-query-stream';
|
|
5
5
|
import { asyncStream } from '@o2ter/utils-js';
|
|
6
6
|
import Decimal from 'decimal.js';
|
|
7
7
|
import { escapeLiteral, escapeIdentifier } from 'pg/lib/utils';
|
|
8
|
-
import { a as QueryCoditionalSelector, b as QueryFieldSelector, c as QueryExpressionSelector, d as QueryDistanceExpression, e as QueryCoditionalExpression, f as QueryComparisonExpression, g as QueryNotExpression, h as QueryArrayExpression, i as QueryValueExpression, j as QueryKeyExpression, Q as QuerySelector, F as FieldSelectorExpression } from '../../internals/index-
|
|
8
|
+
import { a as QueryCoditionalSelector, b as QueryFieldSelector, c as QueryExpressionSelector, d as QueryDistanceExpression, e as QueryCoditionalExpression, f as QueryComparisonExpression, g as QueryNotExpression, h as QueryArrayExpression, i as QueryValueExpression, j as QueryKeyExpression, Q as QuerySelector, F as FieldSelectorExpression } from '../../internals/index-DHQhYGsJ.mjs';
|
|
9
9
|
import '@o2ter/crypto-js';
|
|
10
|
-
import { r as resolveColumn, a as resolveDataType, g as generateId, Q as QueryValidator } from '../../internals/random-
|
|
10
|
+
import { r as resolveColumn, a as resolveDataType, g as generateId, Q as QueryValidator } from '../../internals/random-BMQpRlGH.mjs';
|
|
11
11
|
import { P as PVK } from '../../internals/private-BUpLAMZi.mjs';
|
|
12
12
|
|
|
13
13
|
//
|
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { P as ProtoClient } from './internals/index-
|
|
2
|
-
export { c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-
|
|
1
|
+
import { P as ProtoClient } from './internals/index-B9CWU0y7.js';
|
|
2
|
+
export { c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-B9CWU0y7.js';
|
|
3
3
|
export { Decimal } from 'decimal.js';
|
|
4
|
-
export { D as DeserializeOptions, S as SerializeOptions, d as TSerializable, e as deserialize, s as serialize } from './internals/index-
|
|
4
|
+
export { D as DeserializeOptions, S as SerializeOptions, d as TSerializable, e as deserialize, s as serialize } from './internals/index-BYZpj31o.js';
|
|
5
5
|
import '@o2ter/utils-js';
|
|
6
6
|
import 'socket.io-client';
|
|
7
7
|
import '@socket.io/component-emitter';
|
package/dist/client.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./internals/index-
|
|
5
|
+
var index = require('./internals/index-CvA0tbwx.js');
|
|
6
6
|
var Decimal = require('decimal.js');
|
|
7
7
|
require('./internals/index-DXuW8UiB.js');
|
|
8
8
|
require('lodash');
|
package/dist/client.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { c as ProtoClient } from './internals/index-
|
|
2
|
-
export { e as classExtends, d as deserialize, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser, s as serialize } from './internals/index-
|
|
1
|
+
import { c as ProtoClient } from './internals/index-BPbXumUi.mjs';
|
|
2
|
+
export { e as classExtends, d as deserialize, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser, s as serialize } from './internals/index-BPbXumUi.mjs';
|
|
3
3
|
export { Decimal } from 'decimal.js';
|
|
4
|
-
import './internals/index
|
|
4
|
+
import './internals/index-CTsc042s.mjs';
|
|
5
5
|
import 'lodash';
|
|
6
6
|
import './internals/private-BUpLAMZi.mjs';
|
|
7
7
|
import '@o2ter/utils-js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as socket_io from 'socket.io';
|
|
2
2
|
import { Router } from 'express';
|
|
3
3
|
import { Server } from '@o2ter/server-js';
|
|
4
|
-
import { T as TSchema, _ as _TValue, P as ProtoService, a as ProtoServiceOptions, b as ProtoServiceKeyOptions } from './internals/index-
|
|
5
|
-
export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-
|
|
4
|
+
import { T as TSchema, _ as _TValue, P as ProtoService, a as ProtoServiceOptions, b as ProtoServiceKeyOptions } from './internals/index-BYZpj31o.js';
|
|
5
|
+
export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-BYZpj31o.js';
|
|
6
6
|
import Decimal from 'decimal.js';
|
|
7
7
|
export { Decimal } from 'decimal.js';
|
|
8
|
-
export { P as ProtoClient, c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-
|
|
8
|
+
export { P as ProtoClient, c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-B9CWU0y7.js';
|
|
9
9
|
import '@o2ter/utils-js';
|
|
10
10
|
import 'jsonwebtoken';
|
|
11
11
|
import 'lodash';
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var serverJs = require('@o2ter/server-js');
|
|
|
7
7
|
var random = require('./internals/random-DVOUDDGg.js');
|
|
8
8
|
var _private = require('./internals/private-CSB1Ep4g.js');
|
|
9
9
|
var utilsJs = require('@o2ter/utils-js');
|
|
10
|
-
var index = require('./internals/index-
|
|
10
|
+
var index = require('./internals/index-CvA0tbwx.js');
|
|
11
11
|
var index$1 = require('./internals/index-DXuW8UiB.js');
|
|
12
12
|
var jwt = require('jsonwebtoken');
|
|
13
13
|
var node_buffer = require('node:buffer');
|
|
@@ -248,46 +248,6 @@ const dispatcher = (proto, options, disableSecurity) => {
|
|
|
248
248
|
};
|
|
249
249
|
};
|
|
250
250
|
|
|
251
|
-
//
|
|
252
|
-
// proxy.ts
|
|
253
|
-
//
|
|
254
|
-
// The MIT License
|
|
255
|
-
// Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
|
|
256
|
-
//
|
|
257
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
258
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
259
|
-
// in the Software without restriction, including without limitation the rights
|
|
260
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
261
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
262
|
-
// furnished to do so, subject to the following conditions:
|
|
263
|
-
//
|
|
264
|
-
// The above copyright notice and this permission notice shall be included in
|
|
265
|
-
// all copies or substantial portions of the Software.
|
|
266
|
-
//
|
|
267
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
268
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
269
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
270
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
271
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
272
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
273
|
-
// THE SOFTWARE.
|
|
274
|
-
//
|
|
275
|
-
const proxy = (x) => {
|
|
276
|
-
const self = x;
|
|
277
|
-
const proxy = _.create(self);
|
|
278
|
-
for (const name of _.uniq(_.flatMap(utilsJs.prototypes(proxy), x => Object.getOwnPropertyNames(x)))) {
|
|
279
|
-
if (name === 'constructor')
|
|
280
|
-
continue;
|
|
281
|
-
if (_.isFunction(self[name])) {
|
|
282
|
-
proxy[name] = self[name].bind(self);
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
Object.defineProperty(proxy, name, { get: () => self[name] });
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return proxy;
|
|
289
|
-
};
|
|
290
|
-
|
|
291
251
|
//
|
|
292
252
|
// options.ts
|
|
293
253
|
//
|
|
@@ -394,68 +354,16 @@ class _ProtoQuery extends index.TQuery {
|
|
|
394
354
|
});
|
|
395
355
|
}
|
|
396
356
|
async insert(attrs, options) {
|
|
397
|
-
const context = options?.context ?? {};
|
|
398
|
-
const silent = _.castArray(options?.silent ?? []);
|
|
399
|
-
const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
|
|
400
|
-
const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[_private.PVK].triggers?.afterSave?.[this.className];
|
|
401
|
-
const object = this._proto.Object(this.className);
|
|
402
|
-
for (const [key, value] of _.toPairs(attrs)) {
|
|
403
|
-
object[_private.PVK].mutated[key] = { $set: value };
|
|
404
|
-
}
|
|
405
|
-
if (_.isFunction(beforeSave))
|
|
406
|
-
await beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)));
|
|
407
357
|
const result = this._objectMethods(await this._dispatcher(options).insert({
|
|
408
358
|
className: this.className,
|
|
409
359
|
includes: this[_private.PVK].options.includes,
|
|
410
360
|
matches: this[_private.PVK].options.matches,
|
|
411
|
-
},
|
|
361
|
+
}, attrs));
|
|
412
362
|
if (!result)
|
|
413
363
|
throw Error('Unable to insert document');
|
|
414
|
-
if (_.isFunction(afterSave)) {
|
|
415
|
-
try {
|
|
416
|
-
await afterSave(proxy(Object.setPrototypeOf({ object: result.clone(), context }, options?.session ?? this._proto)));
|
|
417
|
-
}
|
|
418
|
-
catch (e) {
|
|
419
|
-
console.error(e);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
364
|
return result;
|
|
423
365
|
}
|
|
424
366
|
async insertMany(values, options) {
|
|
425
|
-
const context = options?.context ?? {};
|
|
426
|
-
const silent = _.castArray(options?.silent ?? []);
|
|
427
|
-
const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
|
|
428
|
-
const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[_private.PVK].triggers?.afterSave?.[this.className];
|
|
429
|
-
if (_.isFunction(beforeSave) || _.isFunction(afterSave)) {
|
|
430
|
-
const objects = _.map(values, attr => {
|
|
431
|
-
const object = this._proto.Object(this.className);
|
|
432
|
-
for (const [key, value] of _.toPairs(attr)) {
|
|
433
|
-
object[_private.PVK].mutated[key] = { $set: value };
|
|
434
|
-
}
|
|
435
|
-
return object;
|
|
436
|
-
});
|
|
437
|
-
if (_.isEmpty(objects))
|
|
438
|
-
return 0;
|
|
439
|
-
if (_.isFunction(beforeSave)) {
|
|
440
|
-
await Promise.all(_.map(objects, object => beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
|
|
441
|
-
}
|
|
442
|
-
await this._dispatcher(options).insertMany({
|
|
443
|
-
className: this.className,
|
|
444
|
-
includes: this[_private.PVK].options.includes,
|
|
445
|
-
matches: this[_private.PVK].options.matches,
|
|
446
|
-
}, _.map(objects, x => _.fromPairs([...x._set_entries()])));
|
|
447
|
-
if (_.isFunction(afterSave)) {
|
|
448
|
-
await Promise.all(_.map(objects, async (object) => {
|
|
449
|
-
try {
|
|
450
|
-
await afterSave(proxy(Object.setPrototypeOf({ object: object.clone(), context }, options?.session ?? this._proto)));
|
|
451
|
-
}
|
|
452
|
-
catch (e) {
|
|
453
|
-
console.error(e);
|
|
454
|
-
}
|
|
455
|
-
}));
|
|
456
|
-
}
|
|
457
|
-
return objects.length;
|
|
458
|
-
}
|
|
459
367
|
return this._dispatcher(options).insertMany({
|
|
460
368
|
className: this.className,
|
|
461
369
|
includes: this[_private.PVK].options.includes,
|
|
@@ -463,216 +371,24 @@ class _ProtoQuery extends index.TQuery {
|
|
|
463
371
|
}, values);
|
|
464
372
|
}
|
|
465
373
|
async updateOne(update, options) {
|
|
466
|
-
|
|
467
|
-
const silent = _.castArray(options?.silent ?? []);
|
|
468
|
-
const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
|
|
469
|
-
const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[_private.PVK].triggers?.afterSave?.[this.className];
|
|
470
|
-
if (_.isFunction(beforeSave)) {
|
|
471
|
-
const object = this._objectMethods(_.first(await utilsJs.asyncIterableToArray(this._dispatcher(options).find({ ...this._queryOptions, limit: 1 }))));
|
|
472
|
-
if (!object)
|
|
473
|
-
return undefined;
|
|
474
|
-
object[_private.PVK].mutated = update;
|
|
475
|
-
await beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)));
|
|
476
|
-
update = object[_private.PVK].mutated;
|
|
477
|
-
}
|
|
478
|
-
const result = this._objectMethods(await this._dispatcher(options).updateOne(this._queryOptions, update));
|
|
479
|
-
if (result && _.isFunction(afterSave)) {
|
|
480
|
-
try {
|
|
481
|
-
await afterSave(proxy(Object.setPrototypeOf({ object: result.clone(), context }, options?.session ?? this._proto)));
|
|
482
|
-
}
|
|
483
|
-
catch (e) {
|
|
484
|
-
console.error(e);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
return result;
|
|
374
|
+
return this._objectMethods(await this._dispatcher(options).updateOne(this._queryOptions, update));
|
|
488
375
|
}
|
|
489
376
|
async updateMany(update, options) {
|
|
490
|
-
const context = options?.context ?? {};
|
|
491
|
-
const silent = _.castArray(options?.silent ?? []);
|
|
492
|
-
const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
|
|
493
|
-
const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[_private.PVK].triggers?.afterSave?.[this.className];
|
|
494
|
-
if (_.isFunction(beforeSave) || _.isFunction(afterSave)) {
|
|
495
|
-
const objects = this._objectMethods(await utilsJs.asyncIterableToArray(this._dispatcher(options).find(this._queryOptions)));
|
|
496
|
-
if (_.isEmpty(objects))
|
|
497
|
-
return 0;
|
|
498
|
-
if (_.isFunction(beforeSave)) {
|
|
499
|
-
await Promise.all(_.map(objects, object => beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
|
|
500
|
-
}
|
|
501
|
-
if (!_.isFunction(afterSave)) {
|
|
502
|
-
return this._dispatcher(options).updateMany({
|
|
503
|
-
...this._queryOptions,
|
|
504
|
-
filter: { _id: { $in: _.map(objects, x => x.objectId) } },
|
|
505
|
-
}, update);
|
|
506
|
-
}
|
|
507
|
-
const updated = _.compact(await Promise.all(_.map(objects, x => this._dispatcher(options).updateOne({
|
|
508
|
-
...this._queryOptions,
|
|
509
|
-
filter: { _id: { $eq: x.objectId } },
|
|
510
|
-
}, update))));
|
|
511
|
-
await Promise.all(_.map(updated, async (object) => {
|
|
512
|
-
try {
|
|
513
|
-
await afterSave(proxy(Object.setPrototypeOf({ object: object.clone(), context }, options?.session ?? this._proto)));
|
|
514
|
-
}
|
|
515
|
-
catch (e) {
|
|
516
|
-
console.error(e);
|
|
517
|
-
}
|
|
518
|
-
}));
|
|
519
|
-
return updated.length;
|
|
520
|
-
}
|
|
521
377
|
return this._dispatcher(options).updateMany(this._queryOptions, update);
|
|
522
378
|
}
|
|
523
379
|
async upsertOne(update, setOnInsert, options) {
|
|
524
|
-
const context = options?.context ?? {};
|
|
525
|
-
const silent = _.castArray(options?.silent ?? []);
|
|
526
|
-
const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
|
|
527
|
-
const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[_private.PVK].triggers?.afterSave?.[this.className];
|
|
528
|
-
if (_.isFunction(beforeSave)) {
|
|
529
|
-
let object = this._objectMethods(_.first(await utilsJs.asyncIterableToArray(this._dispatcher(options).find({ ...this._queryOptions, limit: 1 }))));
|
|
530
|
-
if (object) {
|
|
531
|
-
object[_private.PVK].mutated = update;
|
|
532
|
-
}
|
|
533
|
-
else {
|
|
534
|
-
object = this._proto.Object(this.className);
|
|
535
|
-
for (const [key, value] of _.toPairs(setOnInsert)) {
|
|
536
|
-
object[_private.PVK].mutated[key] = { $set: value };
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
await beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)));
|
|
540
|
-
if (object.objectId) {
|
|
541
|
-
update = object[_private.PVK].mutated;
|
|
542
|
-
}
|
|
543
|
-
else {
|
|
544
|
-
setOnInsert = {};
|
|
545
|
-
for (const [key, update] of _.toPairs(object[_private.PVK].mutated)) {
|
|
546
|
-
const [op, value] = index$1.decodeUpdateOp(update);
|
|
547
|
-
if (op === '$set') {
|
|
548
|
-
setOnInsert[key] = value;
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
380
|
const result = this._objectMethods(await this._dispatcher(options).upsertOne(this._queryOptions, update, setOnInsert));
|
|
554
381
|
if (!result)
|
|
555
382
|
throw Error('Unable to upsert document');
|
|
556
|
-
if (_.isFunction(afterSave)) {
|
|
557
|
-
try {
|
|
558
|
-
await afterSave(proxy(Object.setPrototypeOf({ object: result.clone(), context }, options?.session ?? this._proto)));
|
|
559
|
-
}
|
|
560
|
-
catch (e) {
|
|
561
|
-
console.error(e);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
383
|
return result;
|
|
565
384
|
}
|
|
566
385
|
async upsertMany(update, setOnInsert, options) {
|
|
567
|
-
const context = options?.context ?? {};
|
|
568
|
-
const silent = _.castArray(options?.silent ?? []);
|
|
569
|
-
const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
|
|
570
|
-
const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[_private.PVK].triggers?.afterSave?.[this.className];
|
|
571
|
-
if (_.isFunction(beforeSave) || _.isFunction(afterSave)) {
|
|
572
|
-
const objects = this._objectMethods(await utilsJs.asyncIterableToArray(this._dispatcher(options).find(this._queryOptions)));
|
|
573
|
-
if (!_.isEmpty(objects) && _.isFunction(beforeSave)) {
|
|
574
|
-
await Promise.all(_.map(objects, object => beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
|
|
575
|
-
}
|
|
576
|
-
if (_.isEmpty(objects)) {
|
|
577
|
-
const result = await this._dispatcher(options).insert({
|
|
578
|
-
className: this.className,
|
|
579
|
-
includes: this[_private.PVK].options.includes,
|
|
580
|
-
matches: this[_private.PVK].options.matches,
|
|
581
|
-
}, setOnInsert);
|
|
582
|
-
if (!result)
|
|
583
|
-
throw Error('Unable to insert document');
|
|
584
|
-
if (_.isFunction(afterSave)) {
|
|
585
|
-
try {
|
|
586
|
-
await afterSave(proxy(Object.setPrototypeOf({ object: result.clone(), context }, options?.session ?? this._proto)));
|
|
587
|
-
}
|
|
588
|
-
catch (e) {
|
|
589
|
-
console.error(e);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
return { updated: 0, inserted: 1 };
|
|
593
|
-
}
|
|
594
|
-
if (!_.isFunction(afterSave)) {
|
|
595
|
-
return {
|
|
596
|
-
inserted: 0,
|
|
597
|
-
updated: await this._dispatcher(options).updateMany({
|
|
598
|
-
...this._queryOptions,
|
|
599
|
-
filter: { _id: { $in: _.map(objects, x => x.objectId) } },
|
|
600
|
-
}, update),
|
|
601
|
-
};
|
|
602
|
-
}
|
|
603
|
-
const updated = _.compact(await Promise.all(_.map(objects, x => this._dispatcher(options).updateOne({
|
|
604
|
-
...this._queryOptions,
|
|
605
|
-
filter: { _id: { $eq: x.objectId } },
|
|
606
|
-
}, update))));
|
|
607
|
-
await Promise.all(_.map(updated, async (object) => {
|
|
608
|
-
try {
|
|
609
|
-
await afterSave(proxy(Object.setPrototypeOf({ object: object.clone(), context }, options?.session ?? this._proto)));
|
|
610
|
-
}
|
|
611
|
-
catch (e) {
|
|
612
|
-
console.error(e);
|
|
613
|
-
}
|
|
614
|
-
}));
|
|
615
|
-
return { updated: updated.length, inserted: 0 };
|
|
616
|
-
}
|
|
617
386
|
return this._dispatcher(options).upsertMany(this._queryOptions, update, setOnInsert);
|
|
618
387
|
}
|
|
619
388
|
async deleteOne(options) {
|
|
620
|
-
|
|
621
|
-
const silent = _.castArray(options?.silent ?? []);
|
|
622
|
-
const beforeDelete = _.includes(silent, 'beforeDelete') ? null : this._proto[_private.PVK].triggers?.beforeDelete?.[this.className];
|
|
623
|
-
const afterDelete = _.includes(silent, 'afterDelete') ? null : this._proto[_private.PVK].triggers?.afterDelete?.[this.className];
|
|
624
|
-
let result;
|
|
625
|
-
if (_.isFunction(beforeDelete)) {
|
|
626
|
-
const object = this._objectMethods(_.first(await utilsJs.asyncIterableToArray(this._dispatcher(options).find({ ...this._queryOptions, limit: 1 }))));
|
|
627
|
-
if (!object)
|
|
628
|
-
return undefined;
|
|
629
|
-
await beforeDelete(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)));
|
|
630
|
-
result = this._objectMethods(await this._dispatcher(options).deleteOne({
|
|
631
|
-
...this._queryOptions,
|
|
632
|
-
filter: { _id: { $eq: object.objectId } },
|
|
633
|
-
}));
|
|
634
|
-
}
|
|
635
|
-
else {
|
|
636
|
-
result = this._objectMethods(await this._dispatcher(options).deleteOne(this._queryOptions));
|
|
637
|
-
}
|
|
638
|
-
if (result && _.isFunction(afterDelete)) {
|
|
639
|
-
try {
|
|
640
|
-
await afterDelete(proxy(Object.setPrototypeOf({ object: result.clone(), context }, options?.session ?? this._proto)));
|
|
641
|
-
}
|
|
642
|
-
catch (e) {
|
|
643
|
-
console.error(e);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
return result;
|
|
389
|
+
return this._objectMethods(await this._dispatcher(options).deleteOne(this._queryOptions));
|
|
647
390
|
}
|
|
648
391
|
async deleteMany(options) {
|
|
649
|
-
const context = options?.context ?? {};
|
|
650
|
-
const silent = _.castArray(options?.silent ?? []);
|
|
651
|
-
const beforeDelete = _.includes(silent, 'beforeDelete') ? null : this._proto[_private.PVK].triggers?.beforeDelete?.[this.className];
|
|
652
|
-
const afterDelete = _.includes(silent, 'afterDelete') ? null : this._proto[_private.PVK].triggers?.afterDelete?.[this.className];
|
|
653
|
-
if (_.isFunction(beforeDelete) || _.isFunction(afterDelete)) {
|
|
654
|
-
const objects = this._objectMethods(await utilsJs.asyncIterableToArray(this._dispatcher(options).find(this._queryOptions)));
|
|
655
|
-
if (_.isEmpty(objects))
|
|
656
|
-
return 0;
|
|
657
|
-
if (_.isFunction(beforeDelete)) {
|
|
658
|
-
await Promise.all(_.map(objects, object => beforeDelete(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
|
|
659
|
-
}
|
|
660
|
-
await this._dispatcher(options).deleteMany({
|
|
661
|
-
...this._queryOptions,
|
|
662
|
-
filter: { _id: { $in: _.map(objects, x => x.objectId) } },
|
|
663
|
-
});
|
|
664
|
-
if (_.isFunction(afterDelete)) {
|
|
665
|
-
await Promise.all(_.map(objects, async (object) => {
|
|
666
|
-
try {
|
|
667
|
-
await afterDelete(proxy(Object.setPrototypeOf({ object: object.clone(), context }, options?.session ?? this._proto)));
|
|
668
|
-
}
|
|
669
|
-
catch (e) {
|
|
670
|
-
console.error(e);
|
|
671
|
-
}
|
|
672
|
-
}));
|
|
673
|
-
}
|
|
674
|
-
return objects.length;
|
|
675
|
-
}
|
|
676
392
|
return this._dispatcher(options).deleteMany(this._queryOptions);
|
|
677
393
|
}
|
|
678
394
|
}
|
|
@@ -873,6 +589,46 @@ const varifyPassword = async (alg, password, options) => {
|
|
|
873
589
|
}
|
|
874
590
|
};
|
|
875
591
|
|
|
592
|
+
//
|
|
593
|
+
// proxy.ts
|
|
594
|
+
//
|
|
595
|
+
// The MIT License
|
|
596
|
+
// Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
|
|
597
|
+
//
|
|
598
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
599
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
600
|
+
// in the Software without restriction, including without limitation the rights
|
|
601
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
602
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
603
|
+
// furnished to do so, subject to the following conditions:
|
|
604
|
+
//
|
|
605
|
+
// The above copyright notice and this permission notice shall be included in
|
|
606
|
+
// all copies or substantial portions of the Software.
|
|
607
|
+
//
|
|
608
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
609
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
610
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
611
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
612
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
613
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
614
|
+
// THE SOFTWARE.
|
|
615
|
+
//
|
|
616
|
+
const proxy = (x) => {
|
|
617
|
+
const self = x;
|
|
618
|
+
const proxy = _.create(self);
|
|
619
|
+
for (const name of _.uniq(_.flatMap(utilsJs.prototypes(proxy), x => Object.getOwnPropertyNames(x)))) {
|
|
620
|
+
if (name === 'constructor')
|
|
621
|
+
continue;
|
|
622
|
+
if (_.isFunction(self[name])) {
|
|
623
|
+
proxy[name] = self[name].bind(self);
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
Object.defineProperty(proxy, name, { get: () => self[name] });
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
return proxy;
|
|
630
|
+
};
|
|
631
|
+
|
|
876
632
|
//
|
|
877
633
|
// internal.ts
|
|
878
634
|
//
|
|
@@ -993,7 +749,6 @@ const mergeSchema = (...schemas) => _.reduce(schemas, (acc, schema) => ({
|
|
|
993
749
|
class ProtoInternal {
|
|
994
750
|
options;
|
|
995
751
|
functions = {};
|
|
996
|
-
triggers = {};
|
|
997
752
|
constructor(options) {
|
|
998
753
|
validateSchemaName(options.schema);
|
|
999
754
|
const schema = mergeSchema(defaultSchema, options.fileStorage.schema, options.schema);
|
|
@@ -1670,26 +1425,6 @@ class ProtoService extends index.ProtoType {
|
|
|
1670
1425
|
define(name, callback, options) {
|
|
1671
1426
|
this[_private.PVK].functions[name] = options ? { callback, ...options } : callback;
|
|
1672
1427
|
}
|
|
1673
|
-
beforeSave(name, callback) {
|
|
1674
|
-
if (!this[_private.PVK].triggers.beforeSave)
|
|
1675
|
-
this[_private.PVK].triggers.beforeSave = {};
|
|
1676
|
-
this[_private.PVK].triggers.beforeSave[name] = callback;
|
|
1677
|
-
}
|
|
1678
|
-
afterSave(name, callback) {
|
|
1679
|
-
if (!this[_private.PVK].triggers.afterSave)
|
|
1680
|
-
this[_private.PVK].triggers.afterSave = {};
|
|
1681
|
-
this[_private.PVK].triggers.afterSave[name] = callback;
|
|
1682
|
-
}
|
|
1683
|
-
beforeDelete(name, callback) {
|
|
1684
|
-
if (!this[_private.PVK].triggers.beforeDelete)
|
|
1685
|
-
this[_private.PVK].triggers.beforeDelete = {};
|
|
1686
|
-
this[_private.PVK].triggers.beforeDelete[name] = callback;
|
|
1687
|
-
}
|
|
1688
|
-
afterDelete(name, callback) {
|
|
1689
|
-
if (!this[_private.PVK].triggers.afterDelete)
|
|
1690
|
-
this[_private.PVK].triggers.afterDelete = {};
|
|
1691
|
-
this[_private.PVK].triggers.afterDelete[name] = callback;
|
|
1692
|
-
}
|
|
1693
1428
|
lockTable(className, update) {
|
|
1694
1429
|
return this.storage.lockTable(className, update);
|
|
1695
1430
|
}
|
|
@@ -1886,12 +1621,12 @@ const verifyRelatedBy = (relatedBy) => {
|
|
|
1886
1621
|
var classesRoute = (router, proto) => {
|
|
1887
1622
|
const defaultHandler = async (req) => {
|
|
1888
1623
|
const { name } = req.params;
|
|
1889
|
-
const { operation,
|
|
1624
|
+
const { operation, random, attributes, update, setOnInsert, relatedBy, ...options } = index.deserialize(req.body);
|
|
1890
1625
|
verifyRelatedBy(relatedBy);
|
|
1891
1626
|
const payload = proto.connect(req);
|
|
1892
1627
|
const query = relatedBy ? payload.Relation(payload.Object(relatedBy.className, relatedBy.objectId), relatedBy.key) : payload.Query(name);
|
|
1893
1628
|
query[_private.PVK].options = options;
|
|
1894
|
-
const opts = { master: payload.isMaster
|
|
1629
|
+
const opts = { master: payload.isMaster };
|
|
1895
1630
|
switch (operation) {
|
|
1896
1631
|
case 'explain':
|
|
1897
1632
|
if (!payload.isMaster)
|