proto.io 0.0.208 → 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 +6 -6
- package/dist/adapters/file/aliyun-oss.js +14 -13
- package/dist/adapters/file/aliyun-oss.js.map +1 -1
- package/dist/adapters/file/aliyun-oss.mjs +14 -13
- 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/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 +159 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +152 -24
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{base-wSknxBv7.d.ts → base-C1ndp06_.d.ts} +2 -2
- package/dist/internals/base-C1ndp06_.d.ts.map +1 -0
- 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-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-C_BXf1Er.d.ts → chunk-DF4KyvgB.d.ts} +6 -6
- package/dist/internals/chunk-DF4KyvgB.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/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-BvwYz4Yp.mjs → index-BgSBzm-K.mjs} +95 -20
- package/dist/internals/index-BgSBzm-K.mjs.map +1 -0
- package/dist/internals/{index-DVUiXLfI.js → index-Clo9hepf.js} +101 -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-A-hoMfDO.d.ts → index-DIRjiWPh.d.ts} +32 -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-iqOd-Wdg.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-wSknxBv7.d.ts.map +0 -1
- package/dist/internals/chunk-BuMQw4dz.js.map +0 -1
- package/dist/internals/chunk-C_BXf1Er.d.ts.map +0 -1
- package/dist/internals/chunk-DxYhYVky.mjs.map +0 -1
- package/dist/internals/index-A-hoMfDO.d.ts.map +0 -1
- package/dist/internals/index-BvwYz4Yp.mjs.map +0 -1
- package/dist/internals/index-CkAvNaAe.js.map +0 -1
- package/dist/internals/index-DVUiXLfI.js.map +0 -1
- package/dist/internals/index-DlY33lfO.mjs.map +0 -1
- package/dist/internals/index-iqOd-Wdg.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, 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-l-Mk0lCc.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-l-Mk0lCc.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-DIRjiWPh.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-Clo9hepf.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-BgSBzm-K.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-BgSBzm-K.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-DIRjiWPh.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-DIRjiWPh.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-l-Mk0lCc.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-Clo9hepf.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');
|
|
@@ -333,11 +334,22 @@ class _ProtoQuery extends index.TQuery {
|
|
|
333
334
|
await tragger(proxy(Object.setPrototypeOf({ object: obj }, this._proto)));
|
|
334
335
|
}
|
|
335
336
|
catch (e) {
|
|
336
|
-
|
|
337
|
+
this._proto.logger.error(e);
|
|
337
338
|
}
|
|
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 ?? [];
|
|
@@ -348,11 +360,21 @@ class _ProtoQuery extends index.TQuery {
|
|
|
348
360
|
await tragger(proxy(Object.setPrototypeOf({ object: obj }, this._proto)));
|
|
349
361
|
}
|
|
350
362
|
catch (e) {
|
|
351
|
-
|
|
363
|
+
this._proto.logger.error(e);
|
|
352
364
|
}
|
|
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 {
|
|
@@ -975,7 +1004,7 @@ class ProtoInternal {
|
|
|
975
1004
|
await proto.fileStorage.destroy(proto, id);
|
|
976
1005
|
}
|
|
977
1006
|
catch (e) {
|
|
978
|
-
|
|
1007
|
+
proto.logger.error(e);
|
|
979
1008
|
}
|
|
980
1009
|
})();
|
|
981
1010
|
}
|
|
@@ -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,21 +1051,71 @@ 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);
|
|
1032
1061
|
}
|
|
1033
1062
|
catch (e) {
|
|
1034
|
-
|
|
1063
|
+
proto.logger.error(e);
|
|
1035
1064
|
}
|
|
1036
1065
|
})();
|
|
1037
1066
|
}),
|
|
1038
1067
|
};
|
|
1039
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(_.filter(objects, object => {
|
|
1084
|
+
if (isMaster)
|
|
1085
|
+
return true;
|
|
1086
|
+
const acl = object.acl();
|
|
1087
|
+
const clp = proto.schema[object.className].classLevelPermissions?.get ?? ['*'];
|
|
1088
|
+
return _.some(_roles, x => _.includes(clp, x) && _.includes(acl.read, x));
|
|
1089
|
+
}));
|
|
1090
|
+
await callback(event, payload);
|
|
1091
|
+
}
|
|
1092
|
+
catch (e) {
|
|
1093
|
+
proto.logger.error(e);
|
|
1094
|
+
}
|
|
1095
|
+
})();
|
|
1096
|
+
}),
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
liveQuery(proto, event, className, filter, callback) {
|
|
1100
|
+
const _filter = _.isEmpty(filter) ? true : index$2.QuerySelector.decode(filter);
|
|
1101
|
+
return this._liveQuery(proto, (ev, objs) => {
|
|
1102
|
+
if (event !== ev)
|
|
1103
|
+
return;
|
|
1104
|
+
for (const object of objs) {
|
|
1105
|
+
if (className !== object.className)
|
|
1106
|
+
continue;
|
|
1107
|
+
(async () => {
|
|
1108
|
+
try {
|
|
1109
|
+
if (_filter === true || _filter.eval(object))
|
|
1110
|
+
await callback(object);
|
|
1111
|
+
}
|
|
1112
|
+
catch (e) {
|
|
1113
|
+
proto.logger.error(e);
|
|
1114
|
+
}
|
|
1115
|
+
})();
|
|
1116
|
+
}
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1040
1119
|
validateCLPs(className, acls, keys) {
|
|
1041
1120
|
if (!_.has(this.options.schema, className))
|
|
1042
1121
|
throw Error('No permission');
|
|
@@ -1232,8 +1311,8 @@ const _session = (proto, request) => {
|
|
|
1232
1311
|
if (parts.length === 2 && parts[0] === 'Bearer')
|
|
1233
1312
|
authorization = parts[1];
|
|
1234
1313
|
}
|
|
1235
|
-
else if (request.cookies[
|
|
1236
|
-
authorization = request.cookies[
|
|
1314
|
+
else if (request.cookies[_const.AUTH_COOKIE_KEY]) {
|
|
1315
|
+
authorization = request.cookies[_const.AUTH_COOKIE_KEY];
|
|
1237
1316
|
}
|
|
1238
1317
|
if (_.isEmpty(authorization))
|
|
1239
1318
|
return;
|
|
@@ -1294,8 +1373,8 @@ const session = async (proto, request) => {
|
|
|
1294
1373
|
};
|
|
1295
1374
|
};
|
|
1296
1375
|
const sessionIsMaster = (proto, request) => {
|
|
1297
|
-
const user = request.header(
|
|
1298
|
-
const pass = request.header(
|
|
1376
|
+
const user = request.header(_const.MASTER_USER_HEADER_NAME);
|
|
1377
|
+
const pass = request.header(_const.MASTER_PASS_HEADER_NAME);
|
|
1299
1378
|
if (_.isEmpty(user) || _.isEmpty(pass))
|
|
1300
1379
|
return false;
|
|
1301
1380
|
return _.some(proto[_private.PVK].options.masterUsers, x => x.user === user && x.pass === pass) ? 'valid' : 'invalid';
|
|
@@ -1312,7 +1391,7 @@ const signUser = async (proto, res, user, options) => {
|
|
|
1312
1391
|
user: user?.objectId,
|
|
1313
1392
|
cookieOptions,
|
|
1314
1393
|
}, options?.jwtSignOptions ?? 'login');
|
|
1315
|
-
res.cookie(
|
|
1394
|
+
res.cookie(_const.AUTH_COOKIE_KEY, token, cookieOptions);
|
|
1316
1395
|
sessionInfoMap.set(res.req, user ? await fetchSessionInfo(proto, user.objectId) : {});
|
|
1317
1396
|
};
|
|
1318
1397
|
|
|
@@ -1361,7 +1440,7 @@ const schedule = (proto) => {
|
|
|
1361
1440
|
await task(proto);
|
|
1362
1441
|
}
|
|
1363
1442
|
catch (e) {
|
|
1364
|
-
|
|
1443
|
+
proto.logger.error(`Errors on schedule ${op}: ${e}`);
|
|
1365
1444
|
}
|
|
1366
1445
|
}
|
|
1367
1446
|
running = false;
|
|
@@ -1431,6 +1510,7 @@ class ProtoService extends index.ProtoType {
|
|
|
1431
1510
|
keySize: 64,
|
|
1432
1511
|
saltSize: 64,
|
|
1433
1512
|
},
|
|
1513
|
+
logger: {},
|
|
1434
1514
|
...options,
|
|
1435
1515
|
});
|
|
1436
1516
|
}
|
|
@@ -1438,6 +1518,21 @@ class ProtoService extends index.ProtoType {
|
|
|
1438
1518
|
this._schedule.destroy();
|
|
1439
1519
|
this[_private.PVK].shutdown();
|
|
1440
1520
|
}
|
|
1521
|
+
get logger() {
|
|
1522
|
+
const logger = this[_private.PVK].options.logger;
|
|
1523
|
+
const loggerLevel = logger.loggerLevel ?? 'warn';
|
|
1524
|
+
const callbacks = _.map(index._logLevels, (x, i) => [x, (...args) => {
|
|
1525
|
+
if (loggerLevel !== 'all' && _.indexOf(index._logLevels, loggerLevel) < i)
|
|
1526
|
+
return;
|
|
1527
|
+
const func = logger[x] ?? console[x];
|
|
1528
|
+
if (_.isFunction(func))
|
|
1529
|
+
func(...args);
|
|
1530
|
+
}]);
|
|
1531
|
+
return {
|
|
1532
|
+
loggerLevel,
|
|
1533
|
+
..._.fromPairs(callbacks),
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1441
1536
|
classes() {
|
|
1442
1537
|
return _.keys(this[_private.PVK].options.schema);
|
|
1443
1538
|
}
|
|
@@ -1624,10 +1719,10 @@ class ProtoService extends index.ProtoType {
|
|
|
1624
1719
|
}
|
|
1625
1720
|
listen(callback, selector) {
|
|
1626
1721
|
const _selector = !_.isNil(selector) ? index$2.QuerySelector.decode(selector) : undefined;
|
|
1627
|
-
return this[_private.PVK].listen(this, data => {
|
|
1722
|
+
return this[_private.PVK].listen(this, async (data) => {
|
|
1628
1723
|
if (_selector && !_selector.eval(data))
|
|
1629
1724
|
return;
|
|
1630
|
-
callback(data);
|
|
1725
|
+
await callback(data);
|
|
1631
1726
|
});
|
|
1632
1727
|
}
|
|
1633
1728
|
refs(object, options) {
|
|
@@ -1701,7 +1796,7 @@ var authHandler = (proto) => async (req, res, next) => {
|
|
|
1701
1796
|
return next();
|
|
1702
1797
|
}
|
|
1703
1798
|
catch (e) {
|
|
1704
|
-
|
|
1799
|
+
proto.logger.error(e);
|
|
1705
1800
|
return next(new Error('Internal server error'));
|
|
1706
1801
|
}
|
|
1707
1802
|
};
|
|
@@ -2113,7 +2208,7 @@ var filesRoute = (router, proto) => {
|
|
|
2113
2208
|
res.setHeader('Cache-Control', ['no-cache', 'no-store']);
|
|
2114
2209
|
await response(res, async () => {
|
|
2115
2210
|
const payload = proto.connect(req);
|
|
2116
|
-
const uploadToken = req.header(
|
|
2211
|
+
const uploadToken = req.header(_const.UPLOAD_TOKEN_HEADER_NAME);
|
|
2117
2212
|
const { maxUploadSize } = payload[_private.PVK].varifyUploadToken(payload, uploadToken, payload.isMaster);
|
|
2118
2213
|
const { attributes, file } = await decodeFormStream(req, (file, info) => proto.fileStorage.create(proto, file, info, maxUploadSize));
|
|
2119
2214
|
try {
|
|
@@ -2154,7 +2249,7 @@ var filesRoute = (router, proto) => {
|
|
|
2154
2249
|
res.setHeader('Content-Length', endBytes - startBytes + 1);
|
|
2155
2250
|
res.setHeader('Content-Range', `bytes ${startBytes}-${endBytes}/${file.size}`);
|
|
2156
2251
|
res.status(206);
|
|
2157
|
-
stream = payload.fileStorage.fileData(payload, file.token, startBytes, endBytes);
|
|
2252
|
+
stream = payload.fileStorage.fileData(payload, file.token, startBytes, endBytes + 1);
|
|
2158
2253
|
}
|
|
2159
2254
|
else {
|
|
2160
2255
|
res.setHeader('Content-Length', file.size);
|
|
@@ -2498,15 +2593,34 @@ const ProtoRoute = async (options) => {
|
|
|
2498
2593
|
const registerProtoSocket = (proto, server, endpoint) => {
|
|
2499
2594
|
const io = endpoint ? server.socket().of(endpoint) : server.socket();
|
|
2500
2595
|
io.on('connection', async (socket) => {
|
|
2501
|
-
let
|
|
2596
|
+
let events = {};
|
|
2597
|
+
let queries = {};
|
|
2502
2598
|
const connect = async (token) => {
|
|
2503
2599
|
const payload = await proto.connectWithSessionToken(token);
|
|
2504
|
-
const { remove } = payload.listen(data => {
|
|
2505
|
-
const ids = _.keys(_.pickBy(
|
|
2600
|
+
const { remove: remove_basic } = payload.listen(data => {
|
|
2601
|
+
const ids = _.keys(_.pickBy(events, v => v instanceof index$2.QuerySelector ? v.eval(data) : v));
|
|
2602
|
+
const payload = JSON.parse(index.serialize(data));
|
|
2506
2603
|
if (!_.isEmpty(ids))
|
|
2507
|
-
socket.emit('
|
|
2604
|
+
socket.emit('ON_EV_NOTIFY', { ids, data: payload });
|
|
2508
2605
|
});
|
|
2509
|
-
|
|
2606
|
+
const { remove: remove_livequery } = payload[_private.PVK]._liveQuery(payload, (ev, objs) => {
|
|
2607
|
+
const ids = {};
|
|
2608
|
+
for (const obj of objs) {
|
|
2609
|
+
ids[obj.objectId] = _.keys(_.pickBy(queries, v => {
|
|
2610
|
+
if (v.event !== ev || v.className !== obj.className)
|
|
2611
|
+
return false;
|
|
2612
|
+
return v.filter instanceof index$2.QuerySelector ? v.filter.eval(obj) : v.filter;
|
|
2613
|
+
}));
|
|
2614
|
+
}
|
|
2615
|
+
if (_.isEmpty(ids))
|
|
2616
|
+
return;
|
|
2617
|
+
const payload = JSON.parse(index.serialize(_.filter(objs, obj => !_.isEmpty(ids[obj.objectId]))));
|
|
2618
|
+
socket.emit('ON_EV_LIVEQUERY', { ids, data: payload });
|
|
2619
|
+
});
|
|
2620
|
+
return () => {
|
|
2621
|
+
remove_basic();
|
|
2622
|
+
remove_livequery();
|
|
2623
|
+
};
|
|
2510
2624
|
};
|
|
2511
2625
|
const { token } = socket.handshake.auth;
|
|
2512
2626
|
let remove = connect(token);
|
|
@@ -2517,19 +2631,33 @@ const registerProtoSocket = (proto, server, endpoint) => {
|
|
|
2517
2631
|
socket.on('disconnect', () => {
|
|
2518
2632
|
remove.then(rm => rm());
|
|
2519
2633
|
});
|
|
2520
|
-
socket.on('
|
|
2521
|
-
|
|
2634
|
+
socket.on('EV_NOTIFY', (payload) => {
|
|
2635
|
+
events = _.mapValues(payload, v => {
|
|
2522
2636
|
if (_.isBoolean(v))
|
|
2523
2637
|
return true;
|
|
2524
2638
|
try {
|
|
2525
2639
|
return index$2.QuerySelector.decode(v);
|
|
2526
2640
|
}
|
|
2527
2641
|
catch (error) {
|
|
2528
|
-
|
|
2642
|
+
proto.logger.error(error);
|
|
2529
2643
|
return false;
|
|
2530
2644
|
}
|
|
2531
2645
|
});
|
|
2532
2646
|
});
|
|
2647
|
+
socket.on('EV_LIVEQUERY', (payload) => {
|
|
2648
|
+
queries = _.mapValues(payload, v => {
|
|
2649
|
+
const { event = '', className = '', filter } = v ?? {};
|
|
2650
|
+
if (_.isBoolean(v))
|
|
2651
|
+
return { event, className, filter: true };
|
|
2652
|
+
try {
|
|
2653
|
+
return { event, className, filter: index$2.QuerySelector.decode(filter) };
|
|
2654
|
+
}
|
|
2655
|
+
catch (error) {
|
|
2656
|
+
proto.logger.error(error);
|
|
2657
|
+
return { event, className, filter: false };
|
|
2658
|
+
}
|
|
2659
|
+
});
|
|
2660
|
+
});
|
|
2533
2661
|
});
|
|
2534
2662
|
return io;
|
|
2535
2663
|
};
|