proto.io 0.0.209 → 0.0.211
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 +134 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -16
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{base-DbSaGX_u.d.ts → base-BCWOHUaQ.d.ts} +2 -2
- package/dist/internals/base-BCWOHUaQ.d.ts.map +1 -0
- package/dist/internals/{chunk-bYrnqXiI.d.ts → chunk-2pKgkO5-.d.ts} +3 -3
- package/dist/internals/chunk-2pKgkO5-.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-Dx36qTUa.d.ts → index-8AdKlZUU.d.ts} +2 -2
- package/dist/internals/index-8AdKlZUU.d.ts.map +1 -0
- package/dist/internals/index-B8TESzd9.js.map +1 -1
- package/dist/internals/{index-CK1snZyh.js → index-Btxxs0KS.js} +106 -29
- package/dist/internals/index-Btxxs0KS.js.map +1 -0
- package/dist/internals/{index-Eo70ZAdZ.mjs → index-CoeDMG5V.mjs} +101 -20
- package/dist/internals/index-CoeDMG5V.mjs.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-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-Dn1IkLDx.d.ts → index-lTzbCO8S.d.ts} +24 -1
- package/dist/internals/index-lTzbCO8S.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/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { P as ProtoClient } from './internals/index-
|
|
2
|
-
export { c as classExtends, e as isFile, f as isJob, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-
|
|
1
|
+
import { P as ProtoClient } from './internals/index-8AdKlZUU.js';
|
|
2
|
+
export { c as classExtends, e as isFile, f as isJob, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-8AdKlZUU.js';
|
|
3
3
|
export { Decimal } from 'decimal.js';
|
|
4
|
-
export { D as DeserializeOptions, S as SerializeOptions, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-
|
|
4
|
+
export { D as DeserializeOptions, S as SerializeOptions, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-lTzbCO8S.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,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./internals/index-
|
|
5
|
+
var index = require('./internals/index-Btxxs0KS.js');
|
|
6
6
|
var Decimal = require('decimal.js');
|
|
7
7
|
require('@o2ter/utils-js');
|
|
8
8
|
require('./internals/private-Ciddhure.js');
|
|
9
9
|
require('lodash');
|
|
10
10
|
require('./internals/index-B8TESzd9.js');
|
|
11
11
|
require('axios');
|
|
12
|
+
require('./internals/const-C3I6cfav.js');
|
|
12
13
|
require('@o2ter/server-js/dist/const');
|
|
13
14
|
require('socket.io-client');
|
|
14
15
|
require('@o2ter/crypto-js');
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sources":["../../src/client/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport { ProtoClient } from './proto';\n\nexport * from '../common';\n\nexport { ProtoClient };\n\nexport default ProtoClient;"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.js","sources":["../../src/client/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport { ProtoClient } from './proto';\n\nexport * from '../common';\n\nexport { ProtoClient };\n\nexport default ProtoClient;"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;"}
|
package/dist/client.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { b as ProtoClient } from './internals/index-CoeDMG5V.mjs';
|
|
2
|
+
export { c as classExtends, d as deserialize, h as isFile, j as isJob, e as isObject, i as isQuery, g as isRole, f as isUser, s as serialize } from './internals/index-CoeDMG5V.mjs';
|
|
3
3
|
export { Decimal } from 'decimal.js';
|
|
4
4
|
import '@o2ter/utils-js';
|
|
5
5
|
import './internals/private-CNw40LZ7.mjs';
|
|
6
6
|
import 'lodash';
|
|
7
7
|
import './internals/index-al1N-qi7.mjs';
|
|
8
8
|
import 'axios';
|
|
9
|
+
import './internals/const-Dkp7Nsv5.mjs';
|
|
9
10
|
import '@o2ter/server-js/dist/const';
|
|
10
11
|
import 'socket.io-client';
|
|
11
12
|
import '@o2ter/crypto-js';
|
package/dist/client.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.mjs","sources":["../../src/client/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport { ProtoClient } from './proto';\n\nexport * from '../common';\n\nexport { ProtoClient };\n\nexport default ProtoClient;"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.mjs","sources":["../../src/client/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport { ProtoClient } from './proto';\n\nexport * from '../common';\n\nexport { ProtoClient };\n\nexport default ProtoClient;"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;"}
|
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, a as TValueWithoutObject, P as ProtoService, b as ProtoServiceOptions, c as ProtoServiceKeyOptions } from './internals/index-
|
|
5
|
-
export { D as DeserializeOptions, S as SerializeOptions, d as TFileStorage, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-
|
|
4
|
+
import { T as TSchema, a as TValueWithoutObject, P as ProtoService, b as ProtoServiceOptions, c as ProtoServiceKeyOptions } from './internals/index-lTzbCO8S.js';
|
|
5
|
+
export { D as DeserializeOptions, S as SerializeOptions, d as TFileStorage, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-lTzbCO8S.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, f as isJob, 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, f as isJob, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-8AdKlZUU.js';
|
|
9
9
|
import '@o2ter/utils-js';
|
|
10
10
|
import 'jsonwebtoken';
|
|
11
11
|
import 'lodash';
|
package/dist/index.js
CHANGED
|
@@ -4,10 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var _ = require('lodash');
|
|
6
6
|
var serverJs = require('@o2ter/server-js');
|
|
7
|
-
var random = require('./internals/random-
|
|
7
|
+
var random = require('./internals/random-CyU_Y2Ay.js');
|
|
8
8
|
var _private = require('./internals/private-Ciddhure.js');
|
|
9
9
|
var utilsJs = require('@o2ter/utils-js');
|
|
10
|
-
var index = require('./internals/index-
|
|
10
|
+
var index = require('./internals/index-Btxxs0KS.js');
|
|
11
11
|
var index$1 = require('./internals/index-B8TESzd9.js');
|
|
12
12
|
var jwt = require('jsonwebtoken');
|
|
13
13
|
var node_buffer = require('node:buffer');
|
|
@@ -15,8 +15,9 @@ var node_stream = require('node:stream');
|
|
|
15
15
|
var node_crypto = require('node:crypto');
|
|
16
16
|
var util = require('util');
|
|
17
17
|
var cryptoJs = require('@o2ter/crypto-js');
|
|
18
|
+
var _const = require('./internals/const-C3I6cfav.js');
|
|
19
|
+
var index$2 = require('./internals/index-D8O7SinR.js');
|
|
18
20
|
var Decimal = require('decimal.js');
|
|
19
|
-
var index$2 = require('./internals/index-CkAvNaAe.js');
|
|
20
21
|
var queryType = require('query-types');
|
|
21
22
|
var busboy = require('busboy');
|
|
22
23
|
require('axios');
|
|
@@ -338,6 +339,17 @@ class _ProtoQuery extends index.TQuery {
|
|
|
338
339
|
})();
|
|
339
340
|
}
|
|
340
341
|
}
|
|
342
|
+
if (this._proto.schema[this.className]?.liveQuery) {
|
|
343
|
+
(async () => {
|
|
344
|
+
try {
|
|
345
|
+
await this._proto[_private.PVK].publishLiveQuery(this._proto, 'create', _.filter(objects, x => x.__v === 0));
|
|
346
|
+
await this._proto[_private.PVK].publishLiveQuery(this._proto, 'update', _.filter(objects, x => x.__v !== 0));
|
|
347
|
+
}
|
|
348
|
+
catch (e) {
|
|
349
|
+
this._proto.logger.error(e);
|
|
350
|
+
}
|
|
351
|
+
})();
|
|
352
|
+
}
|
|
341
353
|
}
|
|
342
354
|
_on_delete(objects) {
|
|
343
355
|
const traggers = this._proto[_private.PVK].triggers[this.className]?.delete ?? [];
|
|
@@ -353,6 +365,16 @@ class _ProtoQuery extends index.TQuery {
|
|
|
353
365
|
})();
|
|
354
366
|
}
|
|
355
367
|
}
|
|
368
|
+
if (this._proto.schema[this.className]?.liveQuery) {
|
|
369
|
+
(async () => {
|
|
370
|
+
try {
|
|
371
|
+
await this._proto[_private.PVK].publishLiveQuery(this._proto, 'delete', objects);
|
|
372
|
+
}
|
|
373
|
+
catch (e) {
|
|
374
|
+
this._proto.logger.error(e);
|
|
375
|
+
}
|
|
376
|
+
})();
|
|
377
|
+
}
|
|
356
378
|
}
|
|
357
379
|
async insertMany(values, options) {
|
|
358
380
|
const objs = this._objectMethods(await this._dispatcher(options).insert({
|
|
@@ -398,6 +420,9 @@ class ProtoQuery extends _ProtoQuery {
|
|
|
398
420
|
clone[_private.PVK].options = options ?? { ...this[_private.PVK].options };
|
|
399
421
|
return clone;
|
|
400
422
|
}
|
|
423
|
+
subscribe() {
|
|
424
|
+
return new index.LiveQuerySubscription(this.className, this._proto, this[_private.PVK].options.filter ?? []);
|
|
425
|
+
}
|
|
401
426
|
}
|
|
402
427
|
class ProtoRelationQuery extends _ProtoQuery {
|
|
403
428
|
constructor(proto, opts) {
|
|
@@ -415,6 +440,9 @@ class ProtoRelationQuery extends _ProtoQuery {
|
|
|
415
440
|
clone[_private.PVK].options = options ?? { ...this[_private.PVK].options };
|
|
416
441
|
return clone;
|
|
417
442
|
}
|
|
443
|
+
subscribe() {
|
|
444
|
+
throw Error('Unable to subscribe to relationship query');
|
|
445
|
+
}
|
|
418
446
|
}
|
|
419
447
|
|
|
420
448
|
//
|
|
@@ -755,6 +783,7 @@ const mergeSchema = (...schemas) => _.reduce(schemas, (acc, schema) => ({
|
|
|
755
783
|
]),
|
|
756
784
|
...(s.indexes ?? []),
|
|
757
785
|
],
|
|
786
|
+
liveQuery: acc[className]?.liveQuery || s.liveQuery,
|
|
758
787
|
})),
|
|
759
788
|
}), {});
|
|
760
789
|
class ProtoInternal {
|
|
@@ -1011,7 +1040,7 @@ class ProtoInternal {
|
|
|
1011
1040
|
if (data._rperm && (!_.isArray(data._rperm) || !_.every(data._rperm, _.isString))) {
|
|
1012
1041
|
throw Error('Invalid data type');
|
|
1013
1042
|
}
|
|
1014
|
-
return this.options.pubsub.publish(
|
|
1043
|
+
return this.options.pubsub.publish(_const.PROTO_NOTY_MSG, {
|
|
1015
1044
|
...data,
|
|
1016
1045
|
_id: this.generateId(),
|
|
1017
1046
|
_created_at: new Date(),
|
|
@@ -1022,13 +1051,42 @@ class ProtoInternal {
|
|
|
1022
1051
|
const isMaster = proto.isMaster;
|
|
1023
1052
|
const roles = isMaster ? [] : this._perms(proto);
|
|
1024
1053
|
return {
|
|
1025
|
-
remove: this.options.pubsub.subscribe(
|
|
1054
|
+
remove: this.options.pubsub.subscribe(_const.PROTO_NOTY_MSG, payload => {
|
|
1026
1055
|
const { _rperm } = payload;
|
|
1027
1056
|
(async () => {
|
|
1028
1057
|
try {
|
|
1029
|
-
if (isMaster
|
|
1030
|
-
|
|
1031
|
-
|
|
1058
|
+
if (!isMaster && !_.some(await roles, x => _.includes(_rperm, x)))
|
|
1059
|
+
return;
|
|
1060
|
+
await callback(payload);
|
|
1061
|
+
}
|
|
1062
|
+
catch (e) {
|
|
1063
|
+
proto.logger.error(e);
|
|
1064
|
+
}
|
|
1065
|
+
})();
|
|
1066
|
+
}),
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
async publishLiveQuery(proto, event, objects) {
|
|
1070
|
+
if (_.isEmpty(objects))
|
|
1071
|
+
return;
|
|
1072
|
+
return this.options.pubsub.publish(_const.PROTO_LIVEQUERY_MSG, JSON.parse(index.serialize({ event, objects }, { objAttrs: index$1.TObject.defaultKeys })));
|
|
1073
|
+
}
|
|
1074
|
+
_liveQuery(proto, callback) {
|
|
1075
|
+
const isMaster = proto.isMaster;
|
|
1076
|
+
const roles = isMaster ? [] : this._perms(proto);
|
|
1077
|
+
return {
|
|
1078
|
+
remove: this.options.pubsub.subscribe(_const.PROTO_LIVEQUERY_MSG, payload => {
|
|
1079
|
+
const { event, objects } = index.deserialize(JSON.stringify(payload));
|
|
1080
|
+
(async () => {
|
|
1081
|
+
try {
|
|
1082
|
+
const _roles = await roles;
|
|
1083
|
+
const payload = proto.rebind(isMaster ? objects : _.filter(objects, object => {
|
|
1084
|
+
const acl = object.acl();
|
|
1085
|
+
const clp = proto.schema[object.className].classLevelPermissions?.get ?? ['*'];
|
|
1086
|
+
return _.some(_roles, x => _.includes(clp, x) && _.includes(acl.read, x));
|
|
1087
|
+
}));
|
|
1088
|
+
if (!_.isEmpty(payload))
|
|
1089
|
+
await callback(event, payload);
|
|
1032
1090
|
}
|
|
1033
1091
|
catch (e) {
|
|
1034
1092
|
proto.logger.error(e);
|
|
@@ -1037,6 +1095,26 @@ class ProtoInternal {
|
|
|
1037
1095
|
}),
|
|
1038
1096
|
};
|
|
1039
1097
|
}
|
|
1098
|
+
liveQuery(proto, event, className, filter, callback) {
|
|
1099
|
+
const _filter = _.isEmpty(filter) ? true : index$2.QuerySelector.decode(filter);
|
|
1100
|
+
return this._liveQuery(proto, (ev, objs) => {
|
|
1101
|
+
if (event !== ev)
|
|
1102
|
+
return;
|
|
1103
|
+
for (const object of objs) {
|
|
1104
|
+
if (className !== object.className)
|
|
1105
|
+
continue;
|
|
1106
|
+
(async () => {
|
|
1107
|
+
try {
|
|
1108
|
+
if (_filter === true || _filter.eval(object))
|
|
1109
|
+
await callback(object);
|
|
1110
|
+
}
|
|
1111
|
+
catch (e) {
|
|
1112
|
+
proto.logger.error(e);
|
|
1113
|
+
}
|
|
1114
|
+
})();
|
|
1115
|
+
}
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1040
1118
|
validateCLPs(className, acls, keys) {
|
|
1041
1119
|
if (!_.has(this.options.schema, className))
|
|
1042
1120
|
throw Error('No permission');
|
|
@@ -1232,8 +1310,8 @@ const _session = (proto, request) => {
|
|
|
1232
1310
|
if (parts.length === 2 && parts[0] === 'Bearer')
|
|
1233
1311
|
authorization = parts[1];
|
|
1234
1312
|
}
|
|
1235
|
-
else if (request.cookies[
|
|
1236
|
-
authorization = request.cookies[
|
|
1313
|
+
else if (request.cookies[_const.AUTH_COOKIE_KEY]) {
|
|
1314
|
+
authorization = request.cookies[_const.AUTH_COOKIE_KEY];
|
|
1237
1315
|
}
|
|
1238
1316
|
if (_.isEmpty(authorization))
|
|
1239
1317
|
return;
|
|
@@ -1294,8 +1372,8 @@ const session = async (proto, request) => {
|
|
|
1294
1372
|
};
|
|
1295
1373
|
};
|
|
1296
1374
|
const sessionIsMaster = (proto, request) => {
|
|
1297
|
-
const user = request.header(
|
|
1298
|
-
const pass = request.header(
|
|
1375
|
+
const user = request.header(_const.MASTER_USER_HEADER_NAME);
|
|
1376
|
+
const pass = request.header(_const.MASTER_PASS_HEADER_NAME);
|
|
1299
1377
|
if (_.isEmpty(user) || _.isEmpty(pass))
|
|
1300
1378
|
return false;
|
|
1301
1379
|
return _.some(proto[_private.PVK].options.masterUsers, x => x.user === user && x.pass === pass) ? 'valid' : 'invalid';
|
|
@@ -1312,7 +1390,7 @@ const signUser = async (proto, res, user, options) => {
|
|
|
1312
1390
|
user: user?.objectId,
|
|
1313
1391
|
cookieOptions,
|
|
1314
1392
|
}, options?.jwtSignOptions ?? 'login');
|
|
1315
|
-
res.cookie(
|
|
1393
|
+
res.cookie(_const.AUTH_COOKIE_KEY, token, cookieOptions);
|
|
1316
1394
|
sessionInfoMap.set(res.req, user ? await fetchSessionInfo(proto, user.objectId) : {});
|
|
1317
1395
|
};
|
|
1318
1396
|
|
|
@@ -1640,10 +1718,10 @@ class ProtoService extends index.ProtoType {
|
|
|
1640
1718
|
}
|
|
1641
1719
|
listen(callback, selector) {
|
|
1642
1720
|
const _selector = !_.isNil(selector) ? index$2.QuerySelector.decode(selector) : undefined;
|
|
1643
|
-
return this[_private.PVK].listen(this, data => {
|
|
1721
|
+
return this[_private.PVK].listen(this, async (data) => {
|
|
1644
1722
|
if (_selector && !_selector.eval(data))
|
|
1645
1723
|
return;
|
|
1646
|
-
callback(data);
|
|
1724
|
+
await callback(data);
|
|
1647
1725
|
});
|
|
1648
1726
|
}
|
|
1649
1727
|
refs(object, options) {
|
|
@@ -2129,7 +2207,7 @@ var filesRoute = (router, proto) => {
|
|
|
2129
2207
|
res.setHeader('Cache-Control', ['no-cache', 'no-store']);
|
|
2130
2208
|
await response(res, async () => {
|
|
2131
2209
|
const payload = proto.connect(req);
|
|
2132
|
-
const uploadToken = req.header(
|
|
2210
|
+
const uploadToken = req.header(_const.UPLOAD_TOKEN_HEADER_NAME);
|
|
2133
2211
|
const { maxUploadSize } = payload[_private.PVK].varifyUploadToken(payload, uploadToken, payload.isMaster);
|
|
2134
2212
|
const { attributes, file } = await decodeFormStream(req, (file, info) => proto.fileStorage.create(proto, file, info, maxUploadSize));
|
|
2135
2213
|
try {
|
|
@@ -2514,15 +2592,34 @@ const ProtoRoute = async (options) => {
|
|
|
2514
2592
|
const registerProtoSocket = (proto, server, endpoint) => {
|
|
2515
2593
|
const io = endpoint ? server.socket().of(endpoint) : server.socket();
|
|
2516
2594
|
io.on('connection', async (socket) => {
|
|
2517
|
-
let
|
|
2595
|
+
let events = {};
|
|
2596
|
+
let queries = {};
|
|
2518
2597
|
const connect = async (token) => {
|
|
2519
2598
|
const payload = await proto.connectWithSessionToken(token);
|
|
2520
|
-
const { remove } = payload.listen(data => {
|
|
2521
|
-
const ids = _.keys(_.pickBy(
|
|
2599
|
+
const { remove: remove_basic } = payload.listen(data => {
|
|
2600
|
+
const ids = _.keys(_.pickBy(events, v => v instanceof index$2.QuerySelector ? v.eval(data) : v));
|
|
2601
|
+
const payload = JSON.parse(index.serialize(data));
|
|
2522
2602
|
if (!_.isEmpty(ids))
|
|
2523
|
-
socket.emit('
|
|
2603
|
+
socket.emit('ON_EV_NOTIFY', { ids, data: payload });
|
|
2604
|
+
});
|
|
2605
|
+
const { remove: remove_livequery } = payload[_private.PVK]._liveQuery(payload, (ev, objs) => {
|
|
2606
|
+
const ids = {};
|
|
2607
|
+
for (const obj of objs) {
|
|
2608
|
+
ids[obj.objectId] = _.keys(_.pickBy(queries, v => {
|
|
2609
|
+
if (v.event !== ev || v.className !== obj.className)
|
|
2610
|
+
return false;
|
|
2611
|
+
return v.filter instanceof index$2.QuerySelector ? v.filter.eval(obj) : v.filter;
|
|
2612
|
+
}));
|
|
2613
|
+
}
|
|
2614
|
+
if (_.isEmpty(ids))
|
|
2615
|
+
return;
|
|
2616
|
+
const payload = JSON.parse(index.serialize(_.filter(objs, obj => !_.isEmpty(ids[obj.objectId]))));
|
|
2617
|
+
socket.emit('ON_EV_LIVEQUERY', { ids, data: payload });
|
|
2524
2618
|
});
|
|
2525
|
-
return
|
|
2619
|
+
return () => {
|
|
2620
|
+
remove_basic();
|
|
2621
|
+
remove_livequery();
|
|
2622
|
+
};
|
|
2526
2623
|
};
|
|
2527
2624
|
const { token } = socket.handshake.auth;
|
|
2528
2625
|
let remove = connect(token);
|
|
@@ -2533,8 +2630,8 @@ const registerProtoSocket = (proto, server, endpoint) => {
|
|
|
2533
2630
|
socket.on('disconnect', () => {
|
|
2534
2631
|
remove.then(rm => rm());
|
|
2535
2632
|
});
|
|
2536
|
-
socket.on('
|
|
2537
|
-
|
|
2633
|
+
socket.on('EV_NOTIFY', (payload) => {
|
|
2634
|
+
events = _.mapValues(payload, v => {
|
|
2538
2635
|
if (_.isBoolean(v))
|
|
2539
2636
|
return true;
|
|
2540
2637
|
try {
|
|
@@ -2546,6 +2643,20 @@ const registerProtoSocket = (proto, server, endpoint) => {
|
|
|
2546
2643
|
}
|
|
2547
2644
|
});
|
|
2548
2645
|
});
|
|
2646
|
+
socket.on('EV_LIVEQUERY', (payload) => {
|
|
2647
|
+
queries = _.mapValues(payload, v => {
|
|
2648
|
+
const { event = '', className = '', filter } = v ?? {};
|
|
2649
|
+
if (_.isBoolean(v))
|
|
2650
|
+
return { event, className, filter: true };
|
|
2651
|
+
try {
|
|
2652
|
+
return { event, className, filter: index$2.QuerySelector.decode(filter) };
|
|
2653
|
+
}
|
|
2654
|
+
catch (error) {
|
|
2655
|
+
proto.logger.error(error);
|
|
2656
|
+
return { event, className, filter: false };
|
|
2657
|
+
}
|
|
2658
|
+
});
|
|
2659
|
+
});
|
|
2549
2660
|
});
|
|
2550
2661
|
return io;
|
|
2551
2662
|
};
|