proto.io 0.0.207 → 0.0.208
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/aliyun-oss.d.ts +3 -3
- package/dist/adapters/file/aliyun-oss.js +2 -2
- package/dist/adapters/file/aliyun-oss.js.map +1 -1
- package/dist/adapters/file/aliyun-oss.mjs +2 -2
- package/dist/adapters/file/aliyun-oss.mjs.map +1 -1
- package/dist/adapters/file/database.d.ts +2 -2
- package/dist/adapters/file/filesystem.d.ts +3 -3
- package/dist/adapters/file/google-cloud-storage.d.ts +3 -3
- package/dist/adapters/storage/progres.d.ts +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 +105 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +107 -45
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{base-DHkvlTFy.d.ts → base-wSknxBv7.d.ts} +2 -2
- package/dist/internals/base-wSknxBv7.d.ts.map +1 -0
- package/dist/internals/{chunk-C7kDLOLD.d.ts → chunk-C_BXf1Er.d.ts} +3 -3
- package/dist/internals/chunk-C_BXf1Er.d.ts.map +1 -0
- package/dist/internals/{index-PLz89AWF.d.ts → index-A-hoMfDO.d.ts} +35 -2
- package/dist/internals/index-A-hoMfDO.d.ts.map +1 -0
- package/dist/internals/{index-DAkcqabS.mjs → index-BvwYz4Yp.mjs} +17 -17
- package/dist/internals/index-BvwYz4Yp.mjs.map +1 -0
- package/dist/internals/{index-BRzKDwPs.js → index-DVUiXLfI.js} +17 -17
- package/dist/internals/index-DVUiXLfI.js.map +1 -0
- package/dist/internals/{index-CKcESGqE.d.ts → index-iqOd-Wdg.d.ts} +2 -2
- package/dist/internals/index-iqOd-Wdg.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/internals/base-DHkvlTFy.d.ts.map +0 -1
- package/dist/internals/chunk-C7kDLOLD.d.ts.map +0 -1
- package/dist/internals/index-BRzKDwPs.js.map +0 -1
- package/dist/internals/index-CKcESGqE.d.ts.map +0 -1
- package/dist/internals/index-DAkcqabS.mjs.map +0 -1
- package/dist/internals/index-PLz89AWF.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -2,9 +2,9 @@ import _ from 'lodash';
|
|
|
2
2
|
import { Server } from '@o2ter/server-js';
|
|
3
3
|
import { Q as QueryValidator, r as resolveColumn, a as resolveDataType, g as generateId } from './internals/random-ZgzzM5v_.mjs';
|
|
4
4
|
import { P as PVK } from './internals/private-CNw40LZ7.mjs';
|
|
5
|
-
import {
|
|
6
|
-
import { T as TQuery, d as deserialize, P as PROTO_NOTY_MSG, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, c as ProtoType, s as serialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-
|
|
7
|
-
export { e as ProtoClient, f as classExtends, k as isFile, l as isJob, g as isObject, i as isQuery, j as isRole, h as isUser } from './internals/index-
|
|
5
|
+
import { prototypes, asyncStream, isBinaryData, base64ToBuffer } from '@o2ter/utils-js';
|
|
6
|
+
import { T as TQuery, d as deserialize, P as PROTO_NOTY_MSG, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, c as ProtoType, s as serialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-BvwYz4Yp.mjs';
|
|
7
|
+
export { e as ProtoClient, f as classExtends, k as isFile, l as isJob, g as isObject, i as isQuery, j as isRole, h as isUser } from './internals/index-BvwYz4Yp.mjs';
|
|
8
8
|
import { i as isPointer, a as isRelation, T as TObject, b as isShape, d as defaultObjectKeyTypes, c as isPrimitive } from './internals/index-al1N-qi7.mjs';
|
|
9
9
|
import jwt from 'jsonwebtoken';
|
|
10
10
|
import { Blob } from 'node:buffer';
|
|
@@ -198,6 +198,42 @@ const dispatcher = (proto, options) => {
|
|
|
198
198
|
};
|
|
199
199
|
};
|
|
200
200
|
|
|
201
|
+
//
|
|
202
|
+
// proxy.ts
|
|
203
|
+
//
|
|
204
|
+
// The MIT License
|
|
205
|
+
// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
|
|
206
|
+
//
|
|
207
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
208
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
209
|
+
// in the Software without restriction, including without limitation the rights
|
|
210
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
211
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
212
|
+
// furnished to do so, subject to the following conditions:
|
|
213
|
+
//
|
|
214
|
+
// The above copyright notice and this permission notice shall be included in
|
|
215
|
+
// all copies or substantial portions of the Software.
|
|
216
|
+
//
|
|
217
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
218
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
219
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
220
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
221
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
222
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
223
|
+
// THE SOFTWARE.
|
|
224
|
+
//
|
|
225
|
+
const proxy = (x) => {
|
|
226
|
+
const self = x;
|
|
227
|
+
const proxy = _.create(self);
|
|
228
|
+
for (const name of _.uniq(_.flatMap(prototypes(proxy), x => Object.getOwnPropertyNames(x)))) {
|
|
229
|
+
if (name === 'constructor')
|
|
230
|
+
continue;
|
|
231
|
+
const value = _.isFunction(self[name]) ? self[name].bind(self) : self[name];
|
|
232
|
+
Object.defineProperty(proxy, name, { get: () => value });
|
|
233
|
+
}
|
|
234
|
+
return proxy;
|
|
235
|
+
};
|
|
236
|
+
|
|
201
237
|
//
|
|
202
238
|
// methods.ts
|
|
203
239
|
//
|
|
@@ -284,22 +320,65 @@ class _ProtoQuery extends TQuery {
|
|
|
284
320
|
yield self._objectMethods(object);
|
|
285
321
|
});
|
|
286
322
|
}
|
|
323
|
+
_on_upsert(objects) {
|
|
324
|
+
const createTraggers = this._proto[PVK].triggers[this.className]?.create ?? [];
|
|
325
|
+
const updateTraggers = this._proto[PVK].triggers[this.className]?.update ?? [];
|
|
326
|
+
for (const obj of objects) {
|
|
327
|
+
for (const tragger of obj.__v === 0 ? createTraggers : updateTraggers) {
|
|
328
|
+
(async () => {
|
|
329
|
+
try {
|
|
330
|
+
await tragger(proxy(Object.setPrototypeOf({ object: obj }, this._proto)));
|
|
331
|
+
}
|
|
332
|
+
catch (e) {
|
|
333
|
+
console.error(e);
|
|
334
|
+
}
|
|
335
|
+
})();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
_on_delete(objects) {
|
|
340
|
+
const traggers = this._proto[PVK].triggers[this.className]?.delete ?? [];
|
|
341
|
+
for (const obj of objects) {
|
|
342
|
+
for (const tragger of traggers) {
|
|
343
|
+
(async () => {
|
|
344
|
+
try {
|
|
345
|
+
await tragger(proxy(Object.setPrototypeOf({ object: obj }, this._proto)));
|
|
346
|
+
}
|
|
347
|
+
catch (e) {
|
|
348
|
+
console.error(e);
|
|
349
|
+
}
|
|
350
|
+
})();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
287
354
|
async insertMany(values, options) {
|
|
288
|
-
|
|
355
|
+
const objs = this._objectMethods(await this._dispatcher(options).insert({
|
|
289
356
|
className: this.className,
|
|
290
357
|
includes: this[PVK].options.includes,
|
|
291
358
|
matches: this[PVK].options.matches,
|
|
292
359
|
countMatches: this[PVK].options.countMatches,
|
|
293
360
|
}, values));
|
|
361
|
+
if (!options?.silent)
|
|
362
|
+
this._on_upsert(objs);
|
|
363
|
+
return objs;
|
|
294
364
|
}
|
|
295
365
|
async updateMany(update, options) {
|
|
296
|
-
|
|
366
|
+
const objs = this._objectMethods(await this._dispatcher(options).update(this._queryOptions, update));
|
|
367
|
+
if (!options?.silent)
|
|
368
|
+
this._on_upsert(objs);
|
|
369
|
+
return objs;
|
|
297
370
|
}
|
|
298
371
|
async upsertMany(update, setOnInsert, options) {
|
|
299
|
-
|
|
372
|
+
const objs = this._objectMethods(await this._dispatcher(options).upsert(this._queryOptions, update, setOnInsert));
|
|
373
|
+
if (!options?.silent)
|
|
374
|
+
this._on_upsert(objs);
|
|
375
|
+
return objs;
|
|
300
376
|
}
|
|
301
377
|
async deleteMany(options) {
|
|
302
|
-
|
|
378
|
+
const objs = this._objectMethods(await this._dispatcher(options).delete(this._queryOptions));
|
|
379
|
+
if (!options?.silent)
|
|
380
|
+
this._on_delete(objs);
|
|
381
|
+
return objs;
|
|
303
382
|
}
|
|
304
383
|
}
|
|
305
384
|
class ProtoQuery extends _ProtoQuery {
|
|
@@ -554,42 +633,6 @@ const varifyPassword = async (alg, password, options) => {
|
|
|
554
633
|
}
|
|
555
634
|
};
|
|
556
635
|
|
|
557
|
-
//
|
|
558
|
-
// proxy.ts
|
|
559
|
-
//
|
|
560
|
-
// The MIT License
|
|
561
|
-
// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
|
|
562
|
-
//
|
|
563
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
564
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
565
|
-
// in the Software without restriction, including without limitation the rights
|
|
566
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
567
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
568
|
-
// furnished to do so, subject to the following conditions:
|
|
569
|
-
//
|
|
570
|
-
// The above copyright notice and this permission notice shall be included in
|
|
571
|
-
// all copies or substantial portions of the Software.
|
|
572
|
-
//
|
|
573
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
574
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
575
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
576
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
577
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
578
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
579
|
-
// THE SOFTWARE.
|
|
580
|
-
//
|
|
581
|
-
const proxy = (x) => {
|
|
582
|
-
const self = x;
|
|
583
|
-
const proxy = _.create(self);
|
|
584
|
-
for (const name of _.uniq(_.flatMap(prototypes(proxy), x => Object.getOwnPropertyNames(x)))) {
|
|
585
|
-
if (name === 'constructor')
|
|
586
|
-
continue;
|
|
587
|
-
const value = _.isFunction(self[name]) ? self[name].bind(self) : self[name];
|
|
588
|
-
Object.defineProperty(proxy, name, { get: () => value });
|
|
589
|
-
}
|
|
590
|
-
return proxy;
|
|
591
|
-
};
|
|
592
|
-
|
|
593
636
|
//
|
|
594
637
|
// internal.ts
|
|
595
638
|
//
|
|
@@ -714,6 +757,7 @@ const mergeSchema = (...schemas) => _.reduce(schemas, (acc, schema) => ({
|
|
|
714
757
|
class ProtoInternal {
|
|
715
758
|
options;
|
|
716
759
|
functions = {};
|
|
760
|
+
triggers = {};
|
|
717
761
|
jobs = {};
|
|
718
762
|
jobRunner = new JobRunner();
|
|
719
763
|
constructor(options) {
|
|
@@ -1529,6 +1573,24 @@ class ProtoService extends ProtoType {
|
|
|
1529
1573
|
define(name, callback, options) {
|
|
1530
1574
|
this[PVK].functions[name] = options ? { callback, ...options } : callback;
|
|
1531
1575
|
}
|
|
1576
|
+
afterCreate(className, callback) {
|
|
1577
|
+
if (_.isNil(this[PVK].triggers[className])) {
|
|
1578
|
+
this[PVK].triggers[className] = { create: [], update: [], delete: [] };
|
|
1579
|
+
}
|
|
1580
|
+
this[PVK].triggers[className].create.push(callback);
|
|
1581
|
+
}
|
|
1582
|
+
afterUpdate(className, callback) {
|
|
1583
|
+
if (_.isNil(this[PVK].triggers[className])) {
|
|
1584
|
+
this[PVK].triggers[className] = { create: [], update: [], delete: [] };
|
|
1585
|
+
}
|
|
1586
|
+
this[PVK].triggers[className].update.push(callback);
|
|
1587
|
+
}
|
|
1588
|
+
afterDelete(className, callback) {
|
|
1589
|
+
if (_.isNil(this[PVK].triggers[className])) {
|
|
1590
|
+
this[PVK].triggers[className] = { create: [], update: [], delete: [] };
|
|
1591
|
+
}
|
|
1592
|
+
this[PVK].triggers[className].delete.push(callback);
|
|
1593
|
+
}
|
|
1532
1594
|
scheduleJob(name, params, options) {
|
|
1533
1595
|
return this[PVK].scheduleJob(this, name, params, options);
|
|
1534
1596
|
}
|
|
@@ -1738,12 +1800,12 @@ const verifyRelatedBy = (relatedBy) => {
|
|
|
1738
1800
|
var classesRoute = (router, proto) => {
|
|
1739
1801
|
const defaultHandler = async (req) => {
|
|
1740
1802
|
const { name } = req.params;
|
|
1741
|
-
const { operation, random, attributes, update, setOnInsert, relatedBy, ...options } = deserialize(req.body);
|
|
1803
|
+
const { operation, random, attributes, update, setOnInsert, relatedBy, silent, ...options } = deserialize(req.body);
|
|
1742
1804
|
verifyRelatedBy(relatedBy);
|
|
1743
1805
|
const payload = proto.connect(req);
|
|
1744
1806
|
const query = relatedBy ? payload.Relation(payload.Object(relatedBy.className, relatedBy.objectId), relatedBy.key) : payload.Query(name);
|
|
1745
1807
|
query[PVK].options = options;
|
|
1746
|
-
const opts = { master: payload.isMaster };
|
|
1808
|
+
const opts = { master: payload.isMaster, silent };
|
|
1747
1809
|
if (_.includes(['File', '_Job', '_JobScope'], name) &&
|
|
1748
1810
|
_.includes(['insert', 'insertMany', 'upsertOne', 'upsertMany'], operation))
|
|
1749
1811
|
throw Error('Invaild operation');
|