proto.io 0.0.165 → 0.0.166
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/database.d.ts +2 -2
- package/dist/adapters/file/filesystem.d.ts +2 -2
- package/dist/adapters/file/google-cloud-storage.d.ts +2 -2
- package/dist/adapters/storage/progres.d.ts +1 -1
- package/dist/adapters/storage/progres.mjs +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 +60 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -26
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{index-Dz3jvqxZ.js → index-B-pq8xkP.js} +5 -21
- package/dist/internals/index-B-pq8xkP.js.map +1 -0
- package/dist/internals/{index-bCACA0cS.d.ts → index-BQggoDNX.d.ts} +2 -2
- package/dist/internals/index-BQggoDNX.d.ts.map +1 -0
- package/dist/internals/{index-BibByOcU.mjs → index-CUJMde7V.mjs} +5 -21
- package/dist/internals/index-CUJMde7V.mjs.map +1 -0
- package/dist/internals/{index-DaDfXlay.d.ts → index-rkqvel7o.d.ts} +2 -2
- package/dist/internals/index-rkqvel7o.d.ts.map +1 -0
- package/dist/internals/{index-RPh4TX0T.d.ts → index-y8EePsDY.d.ts} +8 -5
- package/dist/internals/index-y8EePsDY.d.ts.map +1 -0
- package/dist/internals/{random-B1P0EZO5.mjs → random-DrURPPxr.mjs} +2 -2
- package/dist/internals/{random-B1P0EZO5.mjs.map → random-DrURPPxr.mjs.map} +1 -1
- package/package.json +2 -2
- package/dist/internals/index-BibByOcU.mjs.map +0 -1
- package/dist/internals/index-DaDfXlay.d.ts.map +0 -1
- package/dist/internals/index-Dz3jvqxZ.js.map +0 -1
- package/dist/internals/index-RPh4TX0T.d.ts.map +0 -1
- package/dist/internals/index-bCACA0cS.d.ts.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TSchema, P as ProtoService } from '../../internals/index-
|
|
2
|
-
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-
|
|
1
|
+
import { T as TSchema, P as ProtoService } from '../../internals/index-y8EePsDY.js';
|
|
2
|
+
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-rkqvel7o.js';
|
|
3
3
|
import '@o2ter/utils-js';
|
|
4
4
|
import 'jsonwebtoken';
|
|
5
5
|
import '@o2ter/server-js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as ProtoService } from '../../internals/index-
|
|
2
|
-
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-
|
|
1
|
+
import { P as ProtoService } from '../../internals/index-y8EePsDY.js';
|
|
2
|
+
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-rkqvel7o.js';
|
|
3
3
|
import '@o2ter/utils-js';
|
|
4
4
|
import 'jsonwebtoken';
|
|
5
5
|
import '@o2ter/server-js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _google_cloud_storage from '@google-cloud/storage';
|
|
2
2
|
import { Storage } from '@google-cloud/storage';
|
|
3
|
-
import { P as ProtoService } from '../../internals/index-
|
|
4
|
-
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-
|
|
3
|
+
import { P as ProtoService } from '../../internals/index-y8EePsDY.js';
|
|
4
|
+
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-rkqvel7o.js';
|
|
5
5
|
import '@o2ter/utils-js';
|
|
6
6
|
import 'jsonwebtoken';
|
|
7
7
|
import '@o2ter/server-js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Pool, PoolClient, PoolConfig } from 'pg';
|
|
2
|
-
import { _ as _TValue, o as EventData, T as TSchema, Q as QuerySelector, p as DecodedQuery, F as FindOptions, R as RelationOptions, q as DecodedSortOption, I as InsertOptions, r as TValue, t as FindOneOptions, u as TUpdateOp, v as FieldSelectorExpression, w as QueryExpression, x as TStorage, y as TransactionOptions, h as TObject, z as TQueryRandomOptions, A as TPubSub } from '../../internals/index-
|
|
2
|
+
import { _ as _TValue, o as EventData, T as TSchema, Q as QuerySelector, p as DecodedQuery, F as FindOptions, R as RelationOptions, q as DecodedSortOption, I as InsertOptions, r as TValue, t as FindOneOptions, u as TUpdateOp, v as FieldSelectorExpression, w as QueryExpression, x as TStorage, y as TransactionOptions, h as TObject, z as TQueryRandomOptions, A as TPubSub } from '../../internals/index-y8EePsDY.js';
|
|
3
3
|
import * as _o2ter_utils_js from '@o2ter/utils-js';
|
|
4
4
|
import { asyncStream } from '@o2ter/utils-js';
|
|
5
5
|
import 'jsonwebtoken';
|
|
@@ -7,7 +7,7 @@ import Decimal from 'decimal.js';
|
|
|
7
7
|
import { escapeLiteral, escapeIdentifier } from 'pg/lib/utils';
|
|
8
8
|
import { a as QueryCoditionalSelector, b as QueryFieldSelector, c as QueryExpressionSelector, d as QueryDistanceExpression, e as QueryCoditionalExpression, f as QueryComparisonExpression, g as QueryNotExpression, h as QueryArrayExpression, i as QueryValueExpression, j as QueryKeyExpression, Q as QuerySelector, F as FieldSelectorExpression } from '../../internals/index-BejQNqvC.mjs';
|
|
9
9
|
import '@o2ter/crypto-js';
|
|
10
|
-
import { r as resolveColumn, a as resolveDataType, g as generateId, Q as QueryValidator } from '../../internals/random-
|
|
10
|
+
import { r as resolveColumn, a as resolveDataType, g as generateId, Q as QueryValidator } from '../../internals/random-DrURPPxr.mjs';
|
|
11
11
|
import { P as PVK } from '../../internals/private-BUpLAMZi.mjs';
|
|
12
12
|
|
|
13
13
|
//
|
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, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-
|
|
1
|
+
import { P as ProtoClient } from './internals/index-BQggoDNX.js';
|
|
2
|
+
export { c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-BQggoDNX.js';
|
|
3
3
|
export { Decimal } from 'decimal.js';
|
|
4
|
-
export { D as DeserializeOptions, S as SerializeOptions, d as TSerializable, e as deserialize, s as serialize } from './internals/index-
|
|
4
|
+
export { D as DeserializeOptions, S as SerializeOptions, d as TSerializable, e as deserialize, s as serialize } from './internals/index-y8EePsDY.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,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./internals/index-
|
|
5
|
+
var index = require('./internals/index-B-pq8xkP.js');
|
|
6
6
|
var Decimal = require('decimal.js');
|
|
7
7
|
require('./internals/index-CVutVPmd.js');
|
|
8
8
|
require('lodash');
|
package/dist/client.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as ProtoClient } from './internals/index-
|
|
2
|
-
export { e as classExtends, d as deserialize, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser, s as serialize } from './internals/index-
|
|
1
|
+
import { c as ProtoClient } from './internals/index-CUJMde7V.mjs';
|
|
2
|
+
export { e as classExtends, d as deserialize, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser, s as serialize } from './internals/index-CUJMde7V.mjs';
|
|
3
3
|
export { Decimal } from 'decimal.js';
|
|
4
4
|
import './internals/index-BYbMU-Ao.mjs';
|
|
5
5
|
import 'lodash';
|
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, _ as _TValue, P as ProtoService, a as ProtoServiceOptions, b as ProtoServiceKeyOptions } from './internals/index-
|
|
5
|
-
export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-
|
|
4
|
+
import { T as TSchema, _ as _TValue, P as ProtoService, a as ProtoServiceOptions, b as ProtoServiceKeyOptions } from './internals/index-y8EePsDY.js';
|
|
5
|
+
export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-y8EePsDY.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, 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, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-BQggoDNX.js';
|
|
9
9
|
import '@o2ter/utils-js';
|
|
10
10
|
import 'jsonwebtoken';
|
|
11
11
|
import 'lodash';
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var serverJs = require('@o2ter/server-js');
|
|
|
7
7
|
var random = require('./internals/random-q0PeamQE.js');
|
|
8
8
|
var _private = require('./internals/private-CSB1Ep4g.js');
|
|
9
9
|
var utilsJs = require('@o2ter/utils-js');
|
|
10
|
-
var index = require('./internals/index-
|
|
10
|
+
var index = require('./internals/index-B-pq8xkP.js');
|
|
11
11
|
var index$1 = require('./internals/index-CVutVPmd.js');
|
|
12
12
|
var jwt = require('jsonwebtoken');
|
|
13
13
|
var node_buffer = require('node:buffer');
|
|
@@ -858,6 +858,12 @@ class ProtoInternal {
|
|
|
858
858
|
validateSchemaName(options.schema);
|
|
859
859
|
const schema = mergeSchema(defaultSchema, options.fileStorage.schema, options.schema);
|
|
860
860
|
validateSchema(schema);
|
|
861
|
+
if (!_.every(options.roleInheritKeys, k => {
|
|
862
|
+
const type = random.resolveDataType(schema, 'Role', k);
|
|
863
|
+
return type && index$1.isRelation(type) && _.includes(['User', 'Role'], type.target);
|
|
864
|
+
})) {
|
|
865
|
+
throw Error(`Invalid role keys`);
|
|
866
|
+
}
|
|
861
867
|
this.options = {
|
|
862
868
|
...options,
|
|
863
869
|
schema,
|
|
@@ -1296,29 +1302,7 @@ const signUser = async (proto, res, user, options) => {
|
|
|
1296
1302
|
//
|
|
1297
1303
|
const scheduleOp = {
|
|
1298
1304
|
expireDocument: async (proto) => {
|
|
1299
|
-
|
|
1300
|
-
if (className === 'File') {
|
|
1301
|
-
const found = proto.storage.find({
|
|
1302
|
-
className: 'File',
|
|
1303
|
-
filter: index$2.QuerySelector.decode({ _expired_at: { $lt: new Date() } }),
|
|
1304
|
-
matches: {},
|
|
1305
|
-
includes: ['_id', '_expired_at', 'token'],
|
|
1306
|
-
objectIdSize: 0
|
|
1307
|
-
});
|
|
1308
|
-
for await (const item of found) {
|
|
1309
|
-
const token = item.get('token');
|
|
1310
|
-
if (!_.isEmpty(token))
|
|
1311
|
-
await proto.fileStorage.destroy(proto, token);
|
|
1312
|
-
}
|
|
1313
|
-
}
|
|
1314
|
-
await proto.storage.deleteMany({
|
|
1315
|
-
className,
|
|
1316
|
-
filter: index$2.QuerySelector.decode({ _expired_at: { $lt: new Date() } }),
|
|
1317
|
-
includes: ['_id', '_expired_at'],
|
|
1318
|
-
matches: {},
|
|
1319
|
-
objectIdSize: 0
|
|
1320
|
-
});
|
|
1321
|
-
}
|
|
1305
|
+
await proto.gc();
|
|
1322
1306
|
}
|
|
1323
1307
|
};
|
|
1324
1308
|
const schedule = (proto) => {
|
|
@@ -1380,6 +1364,7 @@ class ProtoService extends index.ProtoType {
|
|
|
1380
1364
|
constructor(options) {
|
|
1381
1365
|
super();
|
|
1382
1366
|
this[_private.PVK] = new ProtoInternal({
|
|
1367
|
+
roleInheritKeys: [],
|
|
1383
1368
|
objectIdSize: 10,
|
|
1384
1369
|
maxFetchLimit: 1000,
|
|
1385
1370
|
maxUploadSize: 20 * 1024 * 1024,
|
|
@@ -1465,6 +1450,32 @@ class ProtoService extends index.ProtoType {
|
|
|
1465
1450
|
const payload = _.create(this, { session });
|
|
1466
1451
|
return _.assign(payload, _.isFunction(attrs) ? attrs(payload) : attrs);
|
|
1467
1452
|
}
|
|
1453
|
+
async userRoles(user) {
|
|
1454
|
+
const roleInheritKeys = this[_private.PVK].options.roleInheritKeys;
|
|
1455
|
+
const schema = this.schema;
|
|
1456
|
+
const userKeys = _.filter(roleInheritKeys, k => {
|
|
1457
|
+
const type = random.resolveDataType(schema, 'Role', k);
|
|
1458
|
+
return !!type && index$1.isRelation(type) && type.target === 'User';
|
|
1459
|
+
});
|
|
1460
|
+
const roleKeys = _.filter(roleInheritKeys, k => {
|
|
1461
|
+
const type = random.resolveDataType(schema, 'Role', k);
|
|
1462
|
+
return !!type && index$1.isRelation(type) && type.target === 'Role';
|
|
1463
|
+
});
|
|
1464
|
+
let queue = await this.Query('Role')
|
|
1465
|
+
.or(_.map(_.uniq(['users', ...userKeys]), k => q => q.isIntersect(k, [user])))
|
|
1466
|
+
.includes('name')
|
|
1467
|
+
.find({ master: true });
|
|
1468
|
+
let roles = queue;
|
|
1469
|
+
while (!_.isEmpty(queue)) {
|
|
1470
|
+
queue = await this.Query('Role')
|
|
1471
|
+
.or(_.map(_.uniq(['roles', ...roleKeys]), k => q => q.isIntersect(k, queue)))
|
|
1472
|
+
.notContainsIn('_id', _.compact(_.map(roles, x => x.objectId)))
|
|
1473
|
+
.includes('name')
|
|
1474
|
+
.find({ master: true });
|
|
1475
|
+
roles = _.uniqBy([...roles, ...queue], x => x.objectId);
|
|
1476
|
+
}
|
|
1477
|
+
return roles;
|
|
1478
|
+
}
|
|
1468
1479
|
async becomeUser(req, user, options) {
|
|
1469
1480
|
if (!user.objectId)
|
|
1470
1481
|
throw Error('Invalid user object');
|
|
@@ -1569,6 +1580,31 @@ class ProtoService extends index.ProtoType {
|
|
|
1569
1580
|
yield self.rebind(object);
|
|
1570
1581
|
});
|
|
1571
1582
|
}
|
|
1583
|
+
async gc(classNames) {
|
|
1584
|
+
for (const className of _.castArray(classNames ?? this.classes())) {
|
|
1585
|
+
if (className === 'File') {
|
|
1586
|
+
const found = this.storage.find({
|
|
1587
|
+
className: 'File',
|
|
1588
|
+
filter: index$2.QuerySelector.decode({ _expired_at: { $lt: new Date() } }),
|
|
1589
|
+
matches: {},
|
|
1590
|
+
includes: ['_id', '_expired_at', 'token'],
|
|
1591
|
+
objectIdSize: 0
|
|
1592
|
+
});
|
|
1593
|
+
for await (const item of found) {
|
|
1594
|
+
const token = item.get('token');
|
|
1595
|
+
if (!_.isEmpty(token))
|
|
1596
|
+
await this.fileStorage.destroy(this, token);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
await this.storage.deleteMany({
|
|
1600
|
+
className,
|
|
1601
|
+
filter: index$2.QuerySelector.decode({ _expired_at: { $lt: new Date() } }),
|
|
1602
|
+
includes: ['_id', '_expired_at'],
|
|
1603
|
+
matches: {},
|
|
1604
|
+
objectIdSize: 0
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1572
1608
|
}
|
|
1573
1609
|
|
|
1574
1610
|
//
|