proto.io 0.0.207 → 0.0.209
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 +6 -6
- package/dist/adapters/file/aliyun-oss.js +16 -15
- package/dist/adapters/file/aliyun-oss.js.map +1 -1
- package/dist/adapters/file/aliyun-oss.mjs +16 -15
- package/dist/adapters/file/aliyun-oss.mjs.map +1 -1
- package/dist/adapters/file/database.d.ts +3 -3
- package/dist/adapters/file/database.js +2 -2
- package/dist/adapters/file/database.js.map +1 -1
- package/dist/adapters/file/database.mjs +2 -2
- package/dist/adapters/file/database.mjs.map +1 -1
- package/dist/adapters/file/filesystem.d.ts +5 -5
- package/dist/adapters/file/filesystem.js +11 -7
- package/dist/adapters/file/filesystem.js.map +1 -1
- package/dist/adapters/file/filesystem.mjs +11 -7
- package/dist/adapters/file/filesystem.mjs.map +1 -1
- package/dist/adapters/file/google-cloud-storage.d.ts +6 -6
- package/dist/adapters/file/google-cloud-storage.js +23 -13
- package/dist/adapters/file/google-cloud-storage.js.map +1 -1
- package/dist/adapters/file/google-cloud-storage.mjs +23 -13
- package/dist/adapters/file/google-cloud-storage.mjs.map +1 -1
- 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 +127 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +129 -51
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{base-CfQi0T0I.mjs → base-DYc1_peK.mjs} +3 -3
- package/dist/internals/{base-CfQi0T0I.mjs.map → base-DYc1_peK.mjs.map} +1 -1
- package/dist/internals/{base-DHkvlTFy.d.ts → base-DbSaGX_u.d.ts} +2 -2
- package/dist/internals/base-DbSaGX_u.d.ts.map +1 -0
- package/dist/internals/{base-BFKQpiws.js → base-NsJYo2MG.js} +3 -3
- package/dist/internals/{base-BFKQpiws.js.map → base-NsJYo2MG.js.map} +1 -1
- package/dist/internals/{chunk-BuMQw4dz.js → chunk-BuKmyceG.js} +5 -3
- package/dist/internals/chunk-BuKmyceG.js.map +1 -0
- package/dist/internals/{chunk-C7kDLOLD.d.ts → chunk-bYrnqXiI.d.ts} +6 -6
- package/dist/internals/chunk-bYrnqXiI.d.ts.map +1 -0
- package/dist/internals/{chunk-DxYhYVky.mjs → chunk-bpt1C6W4.mjs} +5 -3
- package/dist/internals/chunk-bpt1C6W4.mjs.map +1 -0
- package/dist/internals/{index-BRzKDwPs.js → index-CK1snZyh.js} +19 -17
- package/dist/internals/index-CK1snZyh.js.map +1 -0
- package/dist/internals/{index-PLz89AWF.d.ts → index-Dn1IkLDx.d.ts} +48 -2
- package/dist/internals/index-Dn1IkLDx.d.ts.map +1 -0
- package/dist/internals/{index-CKcESGqE.d.ts → index-Dx36qTUa.d.ts} +2 -2
- package/dist/internals/index-Dx36qTUa.d.ts.map +1 -0
- package/dist/internals/{index-DAkcqabS.mjs → index-Eo70ZAdZ.mjs} +19 -18
- package/dist/internals/index-Eo70ZAdZ.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/internals/base-DHkvlTFy.d.ts.map +0 -1
- package/dist/internals/chunk-BuMQw4dz.js.map +0 -1
- package/dist/internals/chunk-C7kDLOLD.d.ts.map +0 -1
- package/dist/internals/chunk-DxYhYVky.mjs.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, _ as _logLevels, s as serialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-Eo70ZAdZ.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-Eo70ZAdZ.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
|
+
this._proto.logger.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
|
+
this._proto.logger.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) {
|
|
@@ -928,7 +972,7 @@ class ProtoInternal {
|
|
|
928
972
|
await proto.fileStorage.destroy(proto, id);
|
|
929
973
|
}
|
|
930
974
|
catch (e) {
|
|
931
|
-
|
|
975
|
+
proto.logger.error(e);
|
|
932
976
|
}
|
|
933
977
|
})();
|
|
934
978
|
}
|
|
@@ -984,7 +1028,7 @@ class ProtoInternal {
|
|
|
984
1028
|
}
|
|
985
1029
|
}
|
|
986
1030
|
catch (e) {
|
|
987
|
-
|
|
1031
|
+
proto.logger.error(e);
|
|
988
1032
|
}
|
|
989
1033
|
})();
|
|
990
1034
|
}),
|
|
@@ -1314,7 +1358,7 @@ const schedule = (proto) => {
|
|
|
1314
1358
|
await task(proto);
|
|
1315
1359
|
}
|
|
1316
1360
|
catch (e) {
|
|
1317
|
-
|
|
1361
|
+
proto.logger.error(`Errors on schedule ${op}: ${e}`);
|
|
1318
1362
|
}
|
|
1319
1363
|
}
|
|
1320
1364
|
running = false;
|
|
@@ -1384,6 +1428,7 @@ class ProtoService extends ProtoType {
|
|
|
1384
1428
|
keySize: 64,
|
|
1385
1429
|
saltSize: 64,
|
|
1386
1430
|
},
|
|
1431
|
+
logger: {},
|
|
1387
1432
|
...options,
|
|
1388
1433
|
});
|
|
1389
1434
|
}
|
|
@@ -1391,6 +1436,21 @@ class ProtoService extends ProtoType {
|
|
|
1391
1436
|
this._schedule.destroy();
|
|
1392
1437
|
this[PVK].shutdown();
|
|
1393
1438
|
}
|
|
1439
|
+
get logger() {
|
|
1440
|
+
const logger = this[PVK].options.logger;
|
|
1441
|
+
const loggerLevel = logger.loggerLevel ?? 'warn';
|
|
1442
|
+
const callbacks = _.map(_logLevels, (x, i) => [x, (...args) => {
|
|
1443
|
+
if (loggerLevel !== 'all' && _.indexOf(_logLevels, loggerLevel) < i)
|
|
1444
|
+
return;
|
|
1445
|
+
const func = logger[x] ?? console[x];
|
|
1446
|
+
if (_.isFunction(func))
|
|
1447
|
+
func(...args);
|
|
1448
|
+
}]);
|
|
1449
|
+
return {
|
|
1450
|
+
loggerLevel,
|
|
1451
|
+
..._.fromPairs(callbacks),
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1394
1454
|
classes() {
|
|
1395
1455
|
return _.keys(this[PVK].options.schema);
|
|
1396
1456
|
}
|
|
@@ -1529,6 +1589,24 @@ class ProtoService extends ProtoType {
|
|
|
1529
1589
|
define(name, callback, options) {
|
|
1530
1590
|
this[PVK].functions[name] = options ? { callback, ...options } : callback;
|
|
1531
1591
|
}
|
|
1592
|
+
afterCreate(className, callback) {
|
|
1593
|
+
if (_.isNil(this[PVK].triggers[className])) {
|
|
1594
|
+
this[PVK].triggers[className] = { create: [], update: [], delete: [] };
|
|
1595
|
+
}
|
|
1596
|
+
this[PVK].triggers[className].create.push(callback);
|
|
1597
|
+
}
|
|
1598
|
+
afterUpdate(className, callback) {
|
|
1599
|
+
if (_.isNil(this[PVK].triggers[className])) {
|
|
1600
|
+
this[PVK].triggers[className] = { create: [], update: [], delete: [] };
|
|
1601
|
+
}
|
|
1602
|
+
this[PVK].triggers[className].update.push(callback);
|
|
1603
|
+
}
|
|
1604
|
+
afterDelete(className, callback) {
|
|
1605
|
+
if (_.isNil(this[PVK].triggers[className])) {
|
|
1606
|
+
this[PVK].triggers[className] = { create: [], update: [], delete: [] };
|
|
1607
|
+
}
|
|
1608
|
+
this[PVK].triggers[className].delete.push(callback);
|
|
1609
|
+
}
|
|
1532
1610
|
scheduleJob(name, params, options) {
|
|
1533
1611
|
return this[PVK].scheduleJob(this, name, params, options);
|
|
1534
1612
|
}
|
|
@@ -1636,7 +1714,7 @@ var authHandler = (proto) => async (req, res, next) => {
|
|
|
1636
1714
|
return next();
|
|
1637
1715
|
}
|
|
1638
1716
|
catch (e) {
|
|
1639
|
-
|
|
1717
|
+
proto.logger.error(e);
|
|
1640
1718
|
return next(new Error('Internal server error'));
|
|
1641
1719
|
}
|
|
1642
1720
|
};
|
|
@@ -1738,12 +1816,12 @@ const verifyRelatedBy = (relatedBy) => {
|
|
|
1738
1816
|
var classesRoute = (router, proto) => {
|
|
1739
1817
|
const defaultHandler = async (req) => {
|
|
1740
1818
|
const { name } = req.params;
|
|
1741
|
-
const { operation, random, attributes, update, setOnInsert, relatedBy, ...options } = deserialize(req.body);
|
|
1819
|
+
const { operation, random, attributes, update, setOnInsert, relatedBy, silent, ...options } = deserialize(req.body);
|
|
1742
1820
|
verifyRelatedBy(relatedBy);
|
|
1743
1821
|
const payload = proto.connect(req);
|
|
1744
1822
|
const query = relatedBy ? payload.Relation(payload.Object(relatedBy.className, relatedBy.objectId), relatedBy.key) : payload.Query(name);
|
|
1745
1823
|
query[PVK].options = options;
|
|
1746
|
-
const opts = { master: payload.isMaster };
|
|
1824
|
+
const opts = { master: payload.isMaster, silent };
|
|
1747
1825
|
if (_.includes(['File', '_Job', '_JobScope'], name) &&
|
|
1748
1826
|
_.includes(['insert', 'insertMany', 'upsertOne', 'upsertMany'], operation))
|
|
1749
1827
|
throw Error('Invaild operation');
|
|
@@ -2089,7 +2167,7 @@ var filesRoute = (router, proto) => {
|
|
|
2089
2167
|
res.setHeader('Content-Length', endBytes - startBytes + 1);
|
|
2090
2168
|
res.setHeader('Content-Range', `bytes ${startBytes}-${endBytes}/${file.size}`);
|
|
2091
2169
|
res.status(206);
|
|
2092
|
-
stream = payload.fileStorage.fileData(payload, file.token, startBytes, endBytes);
|
|
2170
|
+
stream = payload.fileStorage.fileData(payload, file.token, startBytes, endBytes + 1);
|
|
2093
2171
|
}
|
|
2094
2172
|
else {
|
|
2095
2173
|
res.setHeader('Content-Length', file.size);
|
|
@@ -2460,7 +2538,7 @@ const registerProtoSocket = (proto, server, endpoint) => {
|
|
|
2460
2538
|
return QuerySelector.decode(v);
|
|
2461
2539
|
}
|
|
2462
2540
|
catch (error) {
|
|
2463
|
-
|
|
2541
|
+
proto.logger.error(error);
|
|
2464
2542
|
return false;
|
|
2465
2543
|
}
|
|
2466
2544
|
});
|