proto.io 0.0.172 → 0.0.173
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/filesystem.d.ts +2 -2
- package/dist/adapters/file/google-cloud-storage.d.ts +2 -2
- package/dist/adapters/storage/progres.d.ts +8 -1
- package/dist/adapters/storage/progres.js +55 -2
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +55 -2
- package/dist/adapters/storage/progres.mjs.map +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/client.js +1 -1
- package/dist/client.mjs +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +108 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +109 -4
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{index-K0jhERvZ.d.ts → index-BJnQhKf3.d.ts} +2 -2
- package/dist/internals/index-BJnQhKf3.d.ts.map +1 -0
- package/dist/internals/{index-D0hHgn2P.mjs → index-BZNPlw1L.mjs} +20 -1
- package/dist/internals/index-BZNPlw1L.mjs.map +1 -0
- package/dist/internals/{index-BJP46VGq.js → index-CIecB6mS.js} +20 -1
- package/dist/internals/index-CIecB6mS.js.map +1 -0
- package/dist/internals/{index-DchUjNEf.d.ts → index-Cpv1DoEI.d.ts} +2 -2
- package/dist/internals/index-Cpv1DoEI.d.ts.map +1 -0
- package/dist/internals/{index-BhWRmBiq.d.ts → index-lX-M76Tn.d.ts} +11 -1
- package/dist/internals/index-lX-M76Tn.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/internals/index-BJP46VGq.js.map +0 -1
- package/dist/internals/index-BhWRmBiq.d.ts.map +0 -1
- package/dist/internals/index-D0hHgn2P.mjs.map +0 -1
- package/dist/internals/index-DchUjNEf.d.ts.map +0 -1
- package/dist/internals/index-K0jhERvZ.d.ts.map +0 -1
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-Cpv1DoEI.js';
|
|
2
|
+
export { c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-Cpv1DoEI.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-lX-M76Tn.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-CIecB6mS.js');
|
|
6
6
|
var Decimal = require('decimal.js');
|
|
7
7
|
require('./internals/index-CVutVPmd.js');
|
|
8
8
|
require('lodash');
|
package/dist/client.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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-BZNPlw1L.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-BZNPlw1L.mjs';
|
|
3
3
|
export { Decimal } from 'decimal.js';
|
|
4
4
|
import './internals/index-BYbMU-Ao.mjs';
|
|
5
5
|
import 'lodash';
|
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-lX-M76Tn.js';
|
|
5
|
+
export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-lX-M76Tn.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-Cpv1DoEI.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-Dytum6Nh.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-CIecB6mS.js');
|
|
11
11
|
var index$1 = require('./internals/index-CVutVPmd.js');
|
|
12
12
|
var jwt = require('jsonwebtoken');
|
|
13
13
|
var node_buffer = require('node:buffer');
|
|
@@ -186,6 +186,13 @@ const dispatcher = (proto, options, disableSecurity) => {
|
|
|
186
186
|
throw Error('No permission');
|
|
187
187
|
return proto.storage.atomic((storage) => storage.updateOne(_validator.decodeQuery(normalize(query), 'update'), normalize(_validator.validateFields(query.className, update, 'update', random.QueryValidator.patterns.path))));
|
|
188
188
|
},
|
|
189
|
+
async updateMany(query, update) {
|
|
190
|
+
random.QueryValidator.recursiveCheck(query, update);
|
|
191
|
+
const _validator = await validator();
|
|
192
|
+
if (!_validator.validateCLPs(query.className, 'update'))
|
|
193
|
+
throw Error('No permission');
|
|
194
|
+
return proto.storage.atomic((storage) => storage.updateMany(_validator.decodeQuery(normalize(query), 'update'), normalize(_validator.validateFields(query.className, update, 'update', random.QueryValidator.patterns.path))));
|
|
195
|
+
},
|
|
189
196
|
async upsertOne(query, update, setOnInsert) {
|
|
190
197
|
random.QueryValidator.recursiveCheck(query, update, setOnInsert);
|
|
191
198
|
const _validator = await validator();
|
|
@@ -205,6 +212,25 @@ const dispatcher = (proto, options, disableSecurity) => {
|
|
|
205
212
|
}
|
|
206
213
|
}
|
|
207
214
|
},
|
|
215
|
+
async upsertMany(query, update, setOnInsert) {
|
|
216
|
+
random.QueryValidator.recursiveCheck(query, update, setOnInsert);
|
|
217
|
+
const _validator = await validator();
|
|
218
|
+
if (!_validator.validateCLPs(query.className, 'create', 'update'))
|
|
219
|
+
throw Error('No permission');
|
|
220
|
+
const _query = _validator.decodeQuery(normalize(query), 'update');
|
|
221
|
+
const _update = normalize(_validator.validateFields(query.className, update, 'update', random.QueryValidator.patterns.path));
|
|
222
|
+
const _setOnInsert = normalize(_validator.validateFields(query.className, setOnInsert, 'create', random.QueryValidator.patterns.name));
|
|
223
|
+
while (true) {
|
|
224
|
+
try {
|
|
225
|
+
return await proto.storage.atomic((storage) => storage.upsertMany(_query, _update, _setOnInsert), { lockTable: query.className, retry: true });
|
|
226
|
+
}
|
|
227
|
+
catch (e) {
|
|
228
|
+
if (proto.storage.isDuplicateIdError(e))
|
|
229
|
+
continue;
|
|
230
|
+
throw e;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
},
|
|
208
234
|
async deleteOne(query) {
|
|
209
235
|
random.QueryValidator.recursiveCheck(query);
|
|
210
236
|
const _validator = await validator();
|
|
@@ -443,6 +469,33 @@ class _ProtoQuery extends index.TQuery {
|
|
|
443
469
|
}
|
|
444
470
|
return result;
|
|
445
471
|
}
|
|
472
|
+
async updateMany(update, options) {
|
|
473
|
+
const context = options?.context ?? {};
|
|
474
|
+
const silent = _.castArray(options?.silent ?? []);
|
|
475
|
+
const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
|
|
476
|
+
const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[_private.PVK].triggers?.afterSave?.[this.className];
|
|
477
|
+
if (_.isFunction(beforeSave) || _.isFunction(afterSave)) {
|
|
478
|
+
const objects = this._objectMethods(await utilsJs.asyncIterableToArray(this._dispatcher(options).find(this._queryOptions)));
|
|
479
|
+
if (_.isEmpty(objects))
|
|
480
|
+
return 0;
|
|
481
|
+
if (_.isFunction(beforeSave)) {
|
|
482
|
+
await Promise.all(_.map(objects, object => beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
|
|
483
|
+
}
|
|
484
|
+
if (!_.isFunction(afterSave)) {
|
|
485
|
+
return this._dispatcher(options).updateMany({
|
|
486
|
+
...this._queryOptions,
|
|
487
|
+
filter: { _id: { $in: _.map(objects, x => x.objectId) } },
|
|
488
|
+
}, update);
|
|
489
|
+
}
|
|
490
|
+
const updated = await Promise.all(_.map(objects, x => this._dispatcher(options).updateOne({
|
|
491
|
+
...this._queryOptions,
|
|
492
|
+
filter: { _id: { $eq: x.objectId } },
|
|
493
|
+
}, update)));
|
|
494
|
+
await Promise.all(_.map(updated, object => afterSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
|
|
495
|
+
return updated.length;
|
|
496
|
+
}
|
|
497
|
+
return this._dispatcher(options).updateMany(this._queryOptions, update);
|
|
498
|
+
}
|
|
446
499
|
async upsertOne(update, setOnInsert, options) {
|
|
447
500
|
const context = options?.context ?? {};
|
|
448
501
|
const silent = _.castArray(options?.silent ?? []);
|
|
@@ -481,6 +534,47 @@ class _ProtoQuery extends index.TQuery {
|
|
|
481
534
|
}
|
|
482
535
|
return result;
|
|
483
536
|
}
|
|
537
|
+
async upsertMany(update, setOnInsert, options) {
|
|
538
|
+
const context = options?.context ?? {};
|
|
539
|
+
const silent = _.castArray(options?.silent ?? []);
|
|
540
|
+
const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
|
|
541
|
+
const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[_private.PVK].triggers?.afterSave?.[this.className];
|
|
542
|
+
if (_.isFunction(beforeSave) || _.isFunction(afterSave)) {
|
|
543
|
+
const objects = this._objectMethods(await utilsJs.asyncIterableToArray(this._dispatcher(options).find(this._queryOptions)));
|
|
544
|
+
if (!_.isEmpty(objects) && _.isFunction(beforeSave)) {
|
|
545
|
+
await Promise.all(_.map(objects, object => beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
|
|
546
|
+
}
|
|
547
|
+
if (_.isEmpty(objects)) {
|
|
548
|
+
const result = await this._dispatcher(options).insert({
|
|
549
|
+
className: this.className,
|
|
550
|
+
includes: this[_private.PVK].options.includes,
|
|
551
|
+
matches: this[_private.PVK].options.matches,
|
|
552
|
+
}, setOnInsert);
|
|
553
|
+
if (!result)
|
|
554
|
+
throw Error('Unable to insert document');
|
|
555
|
+
if (_.isFunction(afterSave)) {
|
|
556
|
+
await afterSave(proxy(Object.setPrototypeOf({ object: result, context }, options?.session ?? this._proto)));
|
|
557
|
+
}
|
|
558
|
+
return { updated: 0, inserted: 1 };
|
|
559
|
+
}
|
|
560
|
+
if (!_.isFunction(afterSave)) {
|
|
561
|
+
return {
|
|
562
|
+
inserted: 0,
|
|
563
|
+
updated: await this._dispatcher(options).updateMany({
|
|
564
|
+
...this._queryOptions,
|
|
565
|
+
filter: { _id: { $in: _.map(objects, x => x.objectId) } },
|
|
566
|
+
}, update),
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
const updated = await Promise.all(_.map(objects, x => this._dispatcher(options).updateOne({
|
|
570
|
+
...this._queryOptions,
|
|
571
|
+
filter: { _id: { $eq: x.objectId } },
|
|
572
|
+
}, update)));
|
|
573
|
+
await Promise.all(_.map(updated, object => afterSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
|
|
574
|
+
return { updated: updated.length, inserted: 0 };
|
|
575
|
+
}
|
|
576
|
+
return this._dispatcher(options).upsertMany(this._queryOptions, update, setOnInsert);
|
|
577
|
+
}
|
|
484
578
|
async deleteOne(options) {
|
|
485
579
|
const context = options?.context ?? {};
|
|
486
580
|
const silent = _.castArray(options?.silent ?? []);
|
|
@@ -1445,8 +1539,8 @@ class ProtoService extends index.ProtoType {
|
|
|
1445
1539
|
}
|
|
1446
1540
|
async userRoles(user) {
|
|
1447
1541
|
const self = this;
|
|
1542
|
+
const { inheritKeys, resolver } = self[_private.PVK].options.roleResolver;
|
|
1448
1543
|
const defaultResolver = async () => {
|
|
1449
|
-
const inheritKeys = self[_private.PVK].options.roleResolver?.inheritKeys ?? [];
|
|
1450
1544
|
const schema = self.schema;
|
|
1451
1545
|
const userKeys = _.filter(inheritKeys, k => {
|
|
1452
1546
|
const type = random.resolveDataType(schema, 'Role', k);
|
|
@@ -1471,7 +1565,6 @@ class ProtoService extends index.ProtoType {
|
|
|
1471
1565
|
}
|
|
1472
1566
|
return roles;
|
|
1473
1567
|
};
|
|
1474
|
-
const resolver = self[_private.PVK].options.roleResolver?.resolver;
|
|
1475
1568
|
if (resolver)
|
|
1476
1569
|
return resolver(user, defaultResolver);
|
|
1477
1570
|
return defaultResolver();
|
|
@@ -1779,7 +1872,9 @@ var classesRoute = (router, proto) => {
|
|
|
1779
1872
|
case 'insert': return query.insert(attributes, opts);
|
|
1780
1873
|
case 'insertMany': return query.insertMany(attributes, opts);
|
|
1781
1874
|
case 'updateOne': return query.updateOne(update, opts);
|
|
1875
|
+
case 'updateMany': return query.updateMany(update, opts);
|
|
1782
1876
|
case 'upsertOne': return query.upsertOne(update, setOnInsert, opts);
|
|
1877
|
+
case 'upsertMany': return query.upsertMany(update, setOnInsert, opts);
|
|
1783
1878
|
case 'deleteOne': return query.deleteOne(opts);
|
|
1784
1879
|
case 'deleteMany': return query.deleteMany(opts);
|
|
1785
1880
|
default: throw Error('Invalid operation');
|
|
@@ -1883,6 +1978,16 @@ var classesRoute = (router, proto) => {
|
|
|
1883
1978
|
const payload = proto.connect(req);
|
|
1884
1979
|
await response(res, async () => payload.refs(payload.Object(name, id), { master: payload.isMaster }));
|
|
1885
1980
|
});
|
|
1981
|
+
router.patch('/classes/:name', serverJs.Server.text({ type: '*/*' }), async (req, res) => {
|
|
1982
|
+
res.setHeader('Cache-Control', ['no-cache', 'no-store']);
|
|
1983
|
+
const { name } = req.params;
|
|
1984
|
+
const classes = proto.classes();
|
|
1985
|
+
if (!_.includes(classes, name))
|
|
1986
|
+
return void res.sendStatus(404);
|
|
1987
|
+
const payload = proto.connect(req);
|
|
1988
|
+
const update = _.mapValues(index.deserialize(req.body), v => ({ $set: v }));
|
|
1989
|
+
await response(res, () => createQuery(payload, req, false).updateMany(update, { master: payload.isMaster }));
|
|
1990
|
+
});
|
|
1886
1991
|
router.patch('/classes/:name/:id', serverJs.Server.text({ type: '*/*' }), async (req, res) => {
|
|
1887
1992
|
res.setHeader('Cache-Control', ['no-cache', 'no-store']);
|
|
1888
1993
|
const { name, id } = req.params;
|