proto.io 0.0.209 → 0.0.210
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/database.d.ts +2 -2
- package/dist/adapters/file/database.js +1 -1
- package/dist/adapters/file/database.mjs +1 -1
- 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/adapters/storage/progres.js +22 -28
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +22 -28
- package/dist/adapters/storage/progres.mjs.map +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/client.js +2 -1
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +3 -2
- package/dist/client.mjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +135 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +128 -16
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{base-DbSaGX_u.d.ts → base-C1ndp06_.d.ts} +2 -2
- package/dist/internals/base-C1ndp06_.d.ts.map +1 -0
- package/dist/internals/{chunk-bYrnqXiI.d.ts → chunk-DF4KyvgB.d.ts} +3 -3
- package/dist/internals/chunk-DF4KyvgB.d.ts.map +1 -0
- package/dist/internals/const-C3I6cfav.js +42 -0
- package/dist/internals/const-C3I6cfav.js.map +1 -0
- package/dist/internals/const-Dkp7Nsv5.mjs +34 -0
- package/dist/internals/const-Dkp7Nsv5.mjs.map +1 -0
- package/dist/internals/index-B8TESzd9.js.map +1 -1
- package/dist/internals/{index-Eo70ZAdZ.mjs → index-BgSBzm-K.mjs} +94 -20
- package/dist/internals/index-BgSBzm-K.mjs.map +1 -0
- package/dist/internals/{index-CK1snZyh.js → index-Clo9hepf.js} +99 -29
- package/dist/internals/index-Clo9hepf.js.map +1 -0
- package/dist/internals/{index-CkAvNaAe.js → index-D8O7SinR.js} +50 -3
- package/dist/internals/index-D8O7SinR.js.map +1 -0
- package/dist/internals/{index-Dn1IkLDx.d.ts → index-DIRjiWPh.d.ts} +19 -1
- package/dist/internals/index-DIRjiWPh.d.ts.map +1 -0
- package/dist/internals/{index-DlY33lfO.mjs → index-DPPLcZx8.mjs} +51 -4
- package/dist/internals/index-DPPLcZx8.mjs.map +1 -0
- package/dist/internals/index-al1N-qi7.mjs.map +1 -1
- package/dist/internals/{index-Dx36qTUa.d.ts → index-l-Mk0lCc.d.ts} +2 -2
- package/dist/internals/index-l-Mk0lCc.d.ts.map +1 -0
- package/dist/internals/{random-B0V0EnjP.js → random-CyU_Y2Ay.js} +2 -2
- package/dist/internals/{random-B0V0EnjP.js.map → random-CyU_Y2Ay.js.map} +1 -1
- package/dist/internals/{random-ZgzzM5v_.mjs → random-ycCeBd0S.mjs} +2 -2
- package/dist/internals/{random-ZgzzM5v_.mjs.map → random-ycCeBd0S.mjs.map} +1 -1
- package/package.json +1 -1
- package/dist/internals/base-DbSaGX_u.d.ts.map +0 -1
- package/dist/internals/chunk-bYrnqXiI.d.ts.map +0 -1
- package/dist/internals/index-CK1snZyh.js.map +0 -1
- package/dist/internals/index-CkAvNaAe.js.map +0 -1
- package/dist/internals/index-DlY33lfO.mjs.map +0 -1
- package/dist/internals/index-Dn1IkLDx.d.ts.map +0 -1
- package/dist/internals/index-Dx36qTUa.d.ts.map +0 -1
- package/dist/internals/index-Eo70ZAdZ.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import { Server } from '@o2ter/server-js';
|
|
3
|
-
import { Q as QueryValidator, r as resolveColumn, a as resolveDataType, g as generateId } from './internals/random-
|
|
3
|
+
import { Q as QueryValidator, r as resolveColumn, a as resolveDataType, g as generateId } from './internals/random-ycCeBd0S.mjs';
|
|
4
4
|
import { P as PVK } from './internals/private-CNw40LZ7.mjs';
|
|
5
5
|
import { prototypes, asyncStream, isBinaryData, base64ToBuffer } from '@o2ter/utils-js';
|
|
6
|
-
import {
|
|
7
|
-
export {
|
|
6
|
+
import { L as LiveQuerySubscription, T as TQuery, d as deserialize, s as serialize, a as TUser, P as ProtoType, _ as _logLevels } from './internals/index-BgSBzm-K.mjs';
|
|
7
|
+
export { b as ProtoClient, c as classExtends, h as isFile, j as isJob, e as isObject, i as isQuery, g as isRole, f as isUser } from './internals/index-BgSBzm-K.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';
|
|
@@ -12,8 +12,9 @@ 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 { P as PROTO_NOTY_MSG, a as PROTO_LIVEQUERY_MSG, M as MASTER_USER_HEADER_NAME, b as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/const-Dkp7Nsv5.mjs';
|
|
16
|
+
import { Q as QuerySelector } from './internals/index-DPPLcZx8.mjs';
|
|
15
17
|
export { Decimal } from 'decimal.js';
|
|
16
|
-
import { Q as QuerySelector } from './internals/index-DlY33lfO.mjs';
|
|
17
18
|
import queryType from 'query-types';
|
|
18
19
|
import busboy from 'busboy';
|
|
19
20
|
import 'axios';
|
|
@@ -335,6 +336,17 @@ class _ProtoQuery extends TQuery {
|
|
|
335
336
|
})();
|
|
336
337
|
}
|
|
337
338
|
}
|
|
339
|
+
if (this._proto.schema[this.className]?.liveQuery) {
|
|
340
|
+
(async () => {
|
|
341
|
+
try {
|
|
342
|
+
await this._proto[PVK].publishLiveQuery(this._proto, 'create', _.filter(objects, x => x.__v === 0));
|
|
343
|
+
await this._proto[PVK].publishLiveQuery(this._proto, 'update', _.filter(objects, x => x.__v !== 0));
|
|
344
|
+
}
|
|
345
|
+
catch (e) {
|
|
346
|
+
this._proto.logger.error(e);
|
|
347
|
+
}
|
|
348
|
+
})();
|
|
349
|
+
}
|
|
338
350
|
}
|
|
339
351
|
_on_delete(objects) {
|
|
340
352
|
const traggers = this._proto[PVK].triggers[this.className]?.delete ?? [];
|
|
@@ -350,6 +362,16 @@ class _ProtoQuery extends TQuery {
|
|
|
350
362
|
})();
|
|
351
363
|
}
|
|
352
364
|
}
|
|
365
|
+
if (this._proto.schema[this.className]?.liveQuery) {
|
|
366
|
+
(async () => {
|
|
367
|
+
try {
|
|
368
|
+
await this._proto[PVK].publishLiveQuery(this._proto, 'delete', objects);
|
|
369
|
+
}
|
|
370
|
+
catch (e) {
|
|
371
|
+
this._proto.logger.error(e);
|
|
372
|
+
}
|
|
373
|
+
})();
|
|
374
|
+
}
|
|
353
375
|
}
|
|
354
376
|
async insertMany(values, options) {
|
|
355
377
|
const objs = this._objectMethods(await this._dispatcher(options).insert({
|
|
@@ -395,6 +417,9 @@ class ProtoQuery extends _ProtoQuery {
|
|
|
395
417
|
clone[PVK].options = options ?? { ...this[PVK].options };
|
|
396
418
|
return clone;
|
|
397
419
|
}
|
|
420
|
+
subscribe() {
|
|
421
|
+
return new LiveQuerySubscription(this.className, this._proto, this[PVK].options.filter ?? []);
|
|
422
|
+
}
|
|
398
423
|
}
|
|
399
424
|
class ProtoRelationQuery extends _ProtoQuery {
|
|
400
425
|
constructor(proto, opts) {
|
|
@@ -412,6 +437,9 @@ class ProtoRelationQuery extends _ProtoQuery {
|
|
|
412
437
|
clone[PVK].options = options ?? { ...this[PVK].options };
|
|
413
438
|
return clone;
|
|
414
439
|
}
|
|
440
|
+
subscribe() {
|
|
441
|
+
throw Error('Unable to subscribe to relationship query');
|
|
442
|
+
}
|
|
415
443
|
}
|
|
416
444
|
|
|
417
445
|
//
|
|
@@ -752,6 +780,7 @@ const mergeSchema = (...schemas) => _.reduce(schemas, (acc, schema) => ({
|
|
|
752
780
|
]),
|
|
753
781
|
...(s.indexes ?? []),
|
|
754
782
|
],
|
|
783
|
+
liveQuery: acc[className]?.liveQuery || s.liveQuery,
|
|
755
784
|
})),
|
|
756
785
|
}), {});
|
|
757
786
|
class ProtoInternal {
|
|
@@ -1023,9 +1052,39 @@ class ProtoInternal {
|
|
|
1023
1052
|
const { _rperm } = payload;
|
|
1024
1053
|
(async () => {
|
|
1025
1054
|
try {
|
|
1026
|
-
if (isMaster
|
|
1027
|
-
|
|
1028
|
-
|
|
1055
|
+
if (!isMaster && !_.some(await roles, x => _.includes(_rperm, x)))
|
|
1056
|
+
return;
|
|
1057
|
+
await callback(payload);
|
|
1058
|
+
}
|
|
1059
|
+
catch (e) {
|
|
1060
|
+
proto.logger.error(e);
|
|
1061
|
+
}
|
|
1062
|
+
})();
|
|
1063
|
+
}),
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
async publishLiveQuery(proto, event, objects) {
|
|
1067
|
+
if (_.isEmpty(objects))
|
|
1068
|
+
return;
|
|
1069
|
+
return this.options.pubsub.publish(PROTO_LIVEQUERY_MSG, JSON.parse(serialize({ event, objects }, { objAttrs: TObject.defaultKeys })));
|
|
1070
|
+
}
|
|
1071
|
+
_liveQuery(proto, callback) {
|
|
1072
|
+
const isMaster = proto.isMaster;
|
|
1073
|
+
const roles = isMaster ? [] : this._perms(proto);
|
|
1074
|
+
return {
|
|
1075
|
+
remove: this.options.pubsub.subscribe(PROTO_LIVEQUERY_MSG, payload => {
|
|
1076
|
+
const { event, objects } = deserialize(JSON.stringify(payload));
|
|
1077
|
+
(async () => {
|
|
1078
|
+
try {
|
|
1079
|
+
const _roles = await roles;
|
|
1080
|
+
const payload = proto.rebind(_.filter(objects, object => {
|
|
1081
|
+
if (isMaster)
|
|
1082
|
+
return true;
|
|
1083
|
+
const acl = object.acl();
|
|
1084
|
+
const clp = proto.schema[object.className].classLevelPermissions?.get ?? ['*'];
|
|
1085
|
+
return _.some(_roles, x => _.includes(clp, x) && _.includes(acl.read, x));
|
|
1086
|
+
}));
|
|
1087
|
+
await callback(event, payload);
|
|
1029
1088
|
}
|
|
1030
1089
|
catch (e) {
|
|
1031
1090
|
proto.logger.error(e);
|
|
@@ -1034,6 +1093,26 @@ class ProtoInternal {
|
|
|
1034
1093
|
}),
|
|
1035
1094
|
};
|
|
1036
1095
|
}
|
|
1096
|
+
liveQuery(proto, event, className, filter, callback) {
|
|
1097
|
+
const _filter = _.isEmpty(filter) ? true : QuerySelector.decode(filter);
|
|
1098
|
+
return this._liveQuery(proto, (ev, objs) => {
|
|
1099
|
+
if (event !== ev)
|
|
1100
|
+
return;
|
|
1101
|
+
for (const object of objs) {
|
|
1102
|
+
if (className !== object.className)
|
|
1103
|
+
continue;
|
|
1104
|
+
(async () => {
|
|
1105
|
+
try {
|
|
1106
|
+
if (_filter === true || _filter.eval(object))
|
|
1107
|
+
await callback(object);
|
|
1108
|
+
}
|
|
1109
|
+
catch (e) {
|
|
1110
|
+
proto.logger.error(e);
|
|
1111
|
+
}
|
|
1112
|
+
})();
|
|
1113
|
+
}
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1037
1116
|
validateCLPs(className, acls, keys) {
|
|
1038
1117
|
if (!_.has(this.options.schema, className))
|
|
1039
1118
|
throw Error('No permission');
|
|
@@ -1637,10 +1716,10 @@ class ProtoService extends ProtoType {
|
|
|
1637
1716
|
}
|
|
1638
1717
|
listen(callback, selector) {
|
|
1639
1718
|
const _selector = !_.isNil(selector) ? QuerySelector.decode(selector) : undefined;
|
|
1640
|
-
return this[PVK].listen(this, data => {
|
|
1719
|
+
return this[PVK].listen(this, async (data) => {
|
|
1641
1720
|
if (_selector && !_selector.eval(data))
|
|
1642
1721
|
return;
|
|
1643
|
-
callback(data);
|
|
1722
|
+
await callback(data);
|
|
1644
1723
|
});
|
|
1645
1724
|
}
|
|
1646
1725
|
refs(object, options) {
|
|
@@ -2511,15 +2590,34 @@ const ProtoRoute = async (options) => {
|
|
|
2511
2590
|
const registerProtoSocket = (proto, server, endpoint) => {
|
|
2512
2591
|
const io = endpoint ? server.socket().of(endpoint) : server.socket();
|
|
2513
2592
|
io.on('connection', async (socket) => {
|
|
2514
|
-
let
|
|
2593
|
+
let events = {};
|
|
2594
|
+
let queries = {};
|
|
2515
2595
|
const connect = async (token) => {
|
|
2516
2596
|
const payload = await proto.connectWithSessionToken(token);
|
|
2517
|
-
const { remove } = payload.listen(data => {
|
|
2518
|
-
const ids = _.keys(_.pickBy(
|
|
2597
|
+
const { remove: remove_basic } = payload.listen(data => {
|
|
2598
|
+
const ids = _.keys(_.pickBy(events, v => v instanceof QuerySelector ? v.eval(data) : v));
|
|
2599
|
+
const payload = JSON.parse(serialize(data));
|
|
2519
2600
|
if (!_.isEmpty(ids))
|
|
2520
|
-
socket.emit('
|
|
2601
|
+
socket.emit('ON_EV_NOTIFY', { ids, data: payload });
|
|
2602
|
+
});
|
|
2603
|
+
const { remove: remove_livequery } = payload[PVK]._liveQuery(payload, (ev, objs) => {
|
|
2604
|
+
const ids = {};
|
|
2605
|
+
for (const obj of objs) {
|
|
2606
|
+
ids[obj.objectId] = _.keys(_.pickBy(queries, v => {
|
|
2607
|
+
if (v.event !== ev || v.className !== obj.className)
|
|
2608
|
+
return false;
|
|
2609
|
+
return v.filter instanceof QuerySelector ? v.filter.eval(obj) : v.filter;
|
|
2610
|
+
}));
|
|
2611
|
+
}
|
|
2612
|
+
if (_.isEmpty(ids))
|
|
2613
|
+
return;
|
|
2614
|
+
const payload = JSON.parse(serialize(_.filter(objs, obj => !_.isEmpty(ids[obj.objectId]))));
|
|
2615
|
+
socket.emit('ON_EV_LIVEQUERY', { ids, data: payload });
|
|
2521
2616
|
});
|
|
2522
|
-
return
|
|
2617
|
+
return () => {
|
|
2618
|
+
remove_basic();
|
|
2619
|
+
remove_livequery();
|
|
2620
|
+
};
|
|
2523
2621
|
};
|
|
2524
2622
|
const { token } = socket.handshake.auth;
|
|
2525
2623
|
let remove = connect(token);
|
|
@@ -2530,8 +2628,8 @@ const registerProtoSocket = (proto, server, endpoint) => {
|
|
|
2530
2628
|
socket.on('disconnect', () => {
|
|
2531
2629
|
remove.then(rm => rm());
|
|
2532
2630
|
});
|
|
2533
|
-
socket.on('
|
|
2534
|
-
|
|
2631
|
+
socket.on('EV_NOTIFY', (payload) => {
|
|
2632
|
+
events = _.mapValues(payload, v => {
|
|
2535
2633
|
if (_.isBoolean(v))
|
|
2536
2634
|
return true;
|
|
2537
2635
|
try {
|
|
@@ -2543,6 +2641,20 @@ const registerProtoSocket = (proto, server, endpoint) => {
|
|
|
2543
2641
|
}
|
|
2544
2642
|
});
|
|
2545
2643
|
});
|
|
2644
|
+
socket.on('EV_LIVEQUERY', (payload) => {
|
|
2645
|
+
queries = _.mapValues(payload, v => {
|
|
2646
|
+
const { event = '', className = '', filter } = v ?? {};
|
|
2647
|
+
if (_.isBoolean(v))
|
|
2648
|
+
return { event, className, filter: true };
|
|
2649
|
+
try {
|
|
2650
|
+
return { event, className, filter: QuerySelector.decode(filter) };
|
|
2651
|
+
}
|
|
2652
|
+
catch (error) {
|
|
2653
|
+
proto.logger.error(error);
|
|
2654
|
+
return { event, className, filter: false };
|
|
2655
|
+
}
|
|
2656
|
+
});
|
|
2657
|
+
});
|
|
2546
2658
|
});
|
|
2547
2659
|
return io;
|
|
2548
2660
|
};
|