proto.io 0.0.164 → 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/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 +2 -2
- package/dist/adapters/file/filesystem.js.map +1 -1
- package/dist/adapters/file/filesystem.mjs.map +1 -1
- package/dist/adapters/file/google-cloud-storage.d.ts +2 -2
- package/dist/adapters/file/google-cloud-storage.js.map +1 -1
- package/dist/adapters/file/google-cloud-storage.mjs.map +1 -1
- package/dist/adapters/storage/progres.d.ts +16 -13
- package/dist/adapters/storage/progres.js +136 -81
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +138 -83
- package/dist/adapters/storage/progres.mjs.map +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/client.js +1 -1
- package/dist/client.mjs +3 -3
- package/dist/index.d.ts +7 -12
- package/dist/index.js +84 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -50
- 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-BsuUdR0W.d.ts → index-BQggoDNX.d.ts} +2 -2
- package/dist/internals/index-BQggoDNX.d.ts.map +1 -0
- package/dist/internals/{index-ByfpVHca.mjs → index-BYbMU-Ao.mjs} +2 -2
- package/dist/internals/{index-ByfpVHca.mjs.map → index-BYbMU-Ao.mjs.map} +1 -1
- package/dist/internals/{index-S5Bq-KsU.mjs → index-BejQNqvC.mjs} +2 -2
- package/dist/internals/{index-S5Bq-KsU.mjs.map → index-BejQNqvC.mjs.map} +1 -1
- package/dist/internals/index-BqFdBhFc.js.map +1 -1
- package/dist/internals/index-CSNRyhjB.js.map +1 -1
- package/dist/internals/{index-BoP4kl2R.mjs → index-CUJMde7V.mjs} +6 -22
- package/dist/internals/index-CUJMde7V.mjs.map +1 -0
- package/dist/internals/index-CVutVPmd.js.map +1 -1
- package/dist/internals/index-be1VYBY2.mjs.map +1 -1
- package/dist/internals/{index-BeV63sFw.d.ts → index-rkqvel7o.d.ts} +2 -2
- package/dist/internals/index-rkqvel7o.d.ts.map +1 -0
- package/dist/internals/{index-YdOGTHp1.d.ts → index-y8EePsDY.d.ts} +10 -6
- package/dist/internals/index-y8EePsDY.d.ts.map +1 -0
- package/dist/internals/{random-w8WDYQEe.mjs → random-DrURPPxr.mjs} +5 -10
- package/dist/internals/random-DrURPPxr.mjs.map +1 -0
- package/dist/internals/{random-uT4D0y_q.js → random-q0PeamQE.js} +3 -8
- package/dist/internals/random-q0PeamQE.js.map +1 -0
- package/package.json +20 -20
- package/dist/internals/index-BeV63sFw.d.ts.map +0 -1
- package/dist/internals/index-BoP4kl2R.mjs.map +0 -1
- package/dist/internals/index-BsuUdR0W.d.ts.map +0 -1
- package/dist/internals/index-Dz3jvqxZ.js.map +0 -1
- package/dist/internals/index-YdOGTHp1.d.ts.map +0 -1
- package/dist/internals/random-uT4D0y_q.js.map +0 -1
- package/dist/internals/random-w8WDYQEe.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, 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,7 +1,7 @@
|
|
|
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
|
-
import './internals/index-
|
|
4
|
+
import './internals/index-BYbMU-Ao.mjs';
|
|
5
5
|
import 'lodash';
|
|
6
6
|
import './internals/private-BUpLAMZi.mjs';
|
|
7
7
|
import '@o2ter/utils-js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import * as socket_io from 'socket.io';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-YdOGTHp1.js';
|
|
2
|
+
import { Router } from 'express';
|
|
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-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';
|
|
7
6
|
import Decimal from 'decimal.js';
|
|
8
7
|
export { Decimal } from 'decimal.js';
|
|
9
|
-
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';
|
|
10
9
|
import '@o2ter/utils-js';
|
|
11
10
|
import 'jsonwebtoken';
|
|
12
11
|
import 'lodash';
|
|
@@ -62,14 +61,10 @@ declare const schema: ((x: Record<string, TSchema>) => Record<string, TSchema>)
|
|
|
62
61
|
readonly foreignField: string | undefined;
|
|
63
62
|
};
|
|
64
63
|
};
|
|
65
|
-
type AdapterHandler<E, Handler extends RequestHandler = RequestHandler> = Handler extends (req: infer Req, ...args: infer Rest) => void ? (req: ProtoService<E> & {
|
|
66
|
-
req: Req;
|
|
67
|
-
}, ...args: Rest) => void : never;
|
|
68
64
|
declare const ProtoRoute: <E>(options: {
|
|
69
|
-
adapters?: AdapterHandler<E>[];
|
|
70
65
|
proto: ProtoService<E> | (ProtoServiceOptions<E> & ProtoServiceKeyOptions);
|
|
71
|
-
}) => Promise<
|
|
72
|
-
declare const registerProtoSocket: <E>(proto: ProtoService<E>, server: Server, endpoint?: string) => socket_io.Server<
|
|
66
|
+
}) => Promise<Router>;
|
|
67
|
+
declare const registerProtoSocket: <E>(proto: ProtoService<E>, server: Server, endpoint?: string) => socket_io.Server<socket_io.DefaultEventsMap, socket_io.DefaultEventsMap, socket_io.DefaultEventsMap, any> | socket_io.Namespace<socket_io.DefaultEventsMap, socket_io.DefaultEventsMap, socket_io.DefaultEventsMap, any>;
|
|
73
68
|
|
|
74
69
|
export { ProtoRoute, ProtoService, ProtoRoute as default, registerProtoSocket, schema };
|
|
75
70
|
//# sourceMappingURL=index.d.ts.map
|
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-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');
|
|
@@ -783,8 +783,10 @@ const validateShapedObject = (schema, dataType) => {
|
|
|
783
783
|
}
|
|
784
784
|
};
|
|
785
785
|
const validateSchemaName = (schema) => {
|
|
786
|
-
|
|
787
|
-
|
|
786
|
+
for (const name of ['_Schema', '_Config']) {
|
|
787
|
+
if (!_.isNil(schema[name]))
|
|
788
|
+
throw Error('Reserved name of class');
|
|
789
|
+
}
|
|
788
790
|
for (const [, _schema] of _.toPairs(schema)) {
|
|
789
791
|
for (const [key] of _.toPairs(_schema.fields)) {
|
|
790
792
|
if (_.includes(index$1.TObject.defaultKeys, key))
|
|
@@ -856,6 +858,12 @@ class ProtoInternal {
|
|
|
856
858
|
validateSchemaName(options.schema);
|
|
857
859
|
const schema = mergeSchema(defaultSchema, options.fileStorage.schema, options.schema);
|
|
858
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
|
+
}
|
|
859
867
|
this.options = {
|
|
860
868
|
...options,
|
|
861
869
|
schema,
|
|
@@ -1294,29 +1302,7 @@ const signUser = async (proto, res, user, options) => {
|
|
|
1294
1302
|
//
|
|
1295
1303
|
const scheduleOp = {
|
|
1296
1304
|
expireDocument: async (proto) => {
|
|
1297
|
-
|
|
1298
|
-
if (className === 'File') {
|
|
1299
|
-
const found = proto.storage.find({
|
|
1300
|
-
className: 'File',
|
|
1301
|
-
filter: index$2.QuerySelector.decode({ _expired_at: { $lt: new Date() } }),
|
|
1302
|
-
matches: {},
|
|
1303
|
-
includes: ['_id', '_expired_at', 'token'],
|
|
1304
|
-
objectIdSize: 0
|
|
1305
|
-
});
|
|
1306
|
-
for await (const item of found) {
|
|
1307
|
-
const token = item.get('token');
|
|
1308
|
-
if (!_.isEmpty(token))
|
|
1309
|
-
await proto.fileStorage.destroy(proto, token);
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
await proto.storage.deleteMany({
|
|
1313
|
-
className,
|
|
1314
|
-
filter: index$2.QuerySelector.decode({ _expired_at: { $lt: new Date() } }),
|
|
1315
|
-
includes: ['_id', '_expired_at'],
|
|
1316
|
-
matches: {},
|
|
1317
|
-
objectIdSize: 0
|
|
1318
|
-
});
|
|
1319
|
-
}
|
|
1305
|
+
await proto.gc();
|
|
1320
1306
|
}
|
|
1321
1307
|
};
|
|
1322
1308
|
const schedule = (proto) => {
|
|
@@ -1378,6 +1364,7 @@ class ProtoService extends index.ProtoType {
|
|
|
1378
1364
|
constructor(options) {
|
|
1379
1365
|
super();
|
|
1380
1366
|
this[_private.PVK] = new ProtoInternal({
|
|
1367
|
+
roleInheritKeys: [],
|
|
1381
1368
|
objectIdSize: 10,
|
|
1382
1369
|
maxFetchLimit: 1000,
|
|
1383
1370
|
maxUploadSize: 20 * 1024 * 1024,
|
|
@@ -1463,6 +1450,32 @@ class ProtoService extends index.ProtoType {
|
|
|
1463
1450
|
const payload = _.create(this, { session });
|
|
1464
1451
|
return _.assign(payload, _.isFunction(attrs) ? attrs(payload) : attrs);
|
|
1465
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
|
+
}
|
|
1466
1479
|
async becomeUser(req, user, options) {
|
|
1467
1480
|
if (!user.objectId)
|
|
1468
1481
|
throw Error('Invalid user object');
|
|
@@ -1567,6 +1580,31 @@ class ProtoService extends index.ProtoType {
|
|
|
1567
1580
|
yield self.rebind(object);
|
|
1568
1581
|
});
|
|
1569
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
|
+
}
|
|
1570
1608
|
}
|
|
1571
1609
|
|
|
1572
1610
|
//
|
|
@@ -1752,7 +1790,7 @@ var classesRoute = (router, proto) => {
|
|
|
1752
1790
|
const { name } = req.params;
|
|
1753
1791
|
const classes = proto.classes();
|
|
1754
1792
|
if (!_.includes(classes, name))
|
|
1755
|
-
return res.sendStatus(404);
|
|
1793
|
+
return void res.sendStatus(404);
|
|
1756
1794
|
await response(res, () => defaultHandler(req));
|
|
1757
1795
|
});
|
|
1758
1796
|
router.post('/relation', serverJs.Server.text({ type: '*/*' }), async (req, res) => {
|
|
@@ -1784,7 +1822,7 @@ var classesRoute = (router, proto) => {
|
|
|
1784
1822
|
const { name } = req.params;
|
|
1785
1823
|
const classes = proto.classes();
|
|
1786
1824
|
if (!_.includes(classes, name))
|
|
1787
|
-
return res.sendStatus(404);
|
|
1825
|
+
return void res.sendStatus(404);
|
|
1788
1826
|
const payload = proto.connect(req);
|
|
1789
1827
|
await response(res, async () => createQuery(payload, req, true).find({ master: payload.isMaster }));
|
|
1790
1828
|
});
|
|
@@ -1798,7 +1836,7 @@ var classesRoute = (router, proto) => {
|
|
|
1798
1836
|
const { name } = req.params;
|
|
1799
1837
|
const classes = proto.classes();
|
|
1800
1838
|
if (!_.includes(classes, name))
|
|
1801
|
-
return res.sendStatus(404);
|
|
1839
|
+
return void res.sendStatus(404);
|
|
1802
1840
|
const payload = proto.connect(req);
|
|
1803
1841
|
const { weight } = req.query;
|
|
1804
1842
|
if (_.isEmpty(weight) || !_.isString(weight))
|
|
@@ -1818,7 +1856,7 @@ var classesRoute = (router, proto) => {
|
|
|
1818
1856
|
const { name } = req.params;
|
|
1819
1857
|
const classes = proto.classes();
|
|
1820
1858
|
if (!_.includes(classes, name))
|
|
1821
|
-
return res.sendStatus(404);
|
|
1859
|
+
return void res.sendStatus(404);
|
|
1822
1860
|
const payload = proto.connect(req);
|
|
1823
1861
|
await response(res, async () => createQuery(payload, req, true).nonrefs({ master: payload.isMaster }));
|
|
1824
1862
|
});
|
|
@@ -1832,7 +1870,7 @@ var classesRoute = (router, proto) => {
|
|
|
1832
1870
|
const { name, id } = req.params;
|
|
1833
1871
|
const classes = proto.classes();
|
|
1834
1872
|
if (!_.includes(classes, name))
|
|
1835
|
-
return res.sendStatus(404);
|
|
1873
|
+
return void res.sendStatus(404);
|
|
1836
1874
|
const payload = proto.connect(req);
|
|
1837
1875
|
await response(res, () => payload.Query(name).get(id, { master: payload.isMaster }));
|
|
1838
1876
|
});
|
|
@@ -1841,7 +1879,7 @@ var classesRoute = (router, proto) => {
|
|
|
1841
1879
|
const { name, id } = req.params;
|
|
1842
1880
|
const classes = proto.classes();
|
|
1843
1881
|
if (!_.includes(classes, name))
|
|
1844
|
-
return res.sendStatus(404);
|
|
1882
|
+
return void res.sendStatus(404);
|
|
1845
1883
|
const payload = proto.connect(req);
|
|
1846
1884
|
await response(res, async () => payload.refs(payload.Object(name, id), { master: payload.isMaster }));
|
|
1847
1885
|
});
|
|
@@ -1850,7 +1888,7 @@ var classesRoute = (router, proto) => {
|
|
|
1850
1888
|
const { name, id } = req.params;
|
|
1851
1889
|
const classes = proto.classes();
|
|
1852
1890
|
if (!_.includes(classes, name))
|
|
1853
|
-
return res.sendStatus(404);
|
|
1891
|
+
return void res.sendStatus(404);
|
|
1854
1892
|
const payload = proto.connect(req);
|
|
1855
1893
|
const query = payload.Query(name).equalTo('_id', id);
|
|
1856
1894
|
const update = _.mapValues(index.deserialize(req.body), v => ({ $set: v }));
|
|
@@ -1859,29 +1897,29 @@ var classesRoute = (router, proto) => {
|
|
|
1859
1897
|
router.delete('/classes/:name', serverJs.Server.text({ type: '*/*' }), async (req, res) => {
|
|
1860
1898
|
res.setHeader('Cache-Control', ['no-cache', 'no-store']);
|
|
1861
1899
|
if (!_.isEmpty(req.body))
|
|
1862
|
-
return res.sendStatus(400);
|
|
1900
|
+
return void res.sendStatus(400);
|
|
1863
1901
|
const { name } = req.params;
|
|
1864
1902
|
const classes = proto.classes();
|
|
1865
1903
|
if (!_.includes(classes, name))
|
|
1866
|
-
return res.sendStatus(404);
|
|
1904
|
+
return void res.sendStatus(404);
|
|
1867
1905
|
const payload = proto.connect(req);
|
|
1868
1906
|
await response(res, () => createQuery(payload, req, false).deleteMany({ master: payload.isMaster }));
|
|
1869
1907
|
});
|
|
1870
1908
|
router.delete('/relation', serverJs.Server.text({ type: '*/*' }), async (req, res) => {
|
|
1871
1909
|
res.setHeader('Cache-Control', ['no-cache', 'no-store']);
|
|
1872
1910
|
if (!_.isEmpty(req.body))
|
|
1873
|
-
return res.sendStatus(400);
|
|
1911
|
+
return void res.sendStatus(400);
|
|
1874
1912
|
const payload = proto.connect(req);
|
|
1875
1913
|
await response(res, () => createQuery(payload, req, false).deleteMany({ master: payload.isMaster }));
|
|
1876
1914
|
});
|
|
1877
1915
|
router.delete('/classes/:name/:id', serverJs.Server.text({ type: '*/*' }), async (req, res) => {
|
|
1878
1916
|
res.setHeader('Cache-Control', ['no-cache', 'no-store']);
|
|
1879
1917
|
if (!_.isEmpty(req.body))
|
|
1880
|
-
return res.sendStatus(400);
|
|
1918
|
+
return void res.sendStatus(400);
|
|
1881
1919
|
const { name, id } = req.params;
|
|
1882
1920
|
const classes = proto.classes();
|
|
1883
1921
|
if (!_.includes(classes, name))
|
|
1884
|
-
return res.sendStatus(404);
|
|
1922
|
+
return void res.sendStatus(404);
|
|
1885
1923
|
const payload = proto.connect(req);
|
|
1886
1924
|
const query = payload.Query(name).equalTo('_id', id);
|
|
1887
1925
|
await response(res, () => query.deleteOne({ master: payload.isMaster }));
|
|
@@ -1918,7 +1956,7 @@ var functionRoute = (router, proto) => {
|
|
|
1918
1956
|
res.setHeader('Cache-Control', ['no-cache', 'no-store']);
|
|
1919
1957
|
const { name } = req.params;
|
|
1920
1958
|
if (_.isNil(proto[_private.PVK].functions[name]))
|
|
1921
|
-
return res.sendStatus(404);
|
|
1959
|
+
return void res.sendStatus(404);
|
|
1922
1960
|
await response(res, () => {
|
|
1923
1961
|
const payload = proto.connect(req, x => ({
|
|
1924
1962
|
params: null,
|
|
@@ -1930,7 +1968,7 @@ var functionRoute = (router, proto) => {
|
|
|
1930
1968
|
res.setHeader('Cache-Control', ['no-cache', 'no-store']);
|
|
1931
1969
|
const { name } = req.params;
|
|
1932
1970
|
if (_.isNil(proto[_private.PVK].functions[name]))
|
|
1933
|
-
return res.sendStatus(404);
|
|
1971
|
+
return void res.sendStatus(404);
|
|
1934
1972
|
await response(res, () => {
|
|
1935
1973
|
const payload = proto.connect(req, x => ({
|
|
1936
1974
|
params: x.rebind(index.deserialize(req.body, { objAttrs: index$1.TObject.defaultReadonlyKeys })),
|
|
@@ -1992,9 +2030,9 @@ var filesRoute = (router, proto) => {
|
|
|
1992
2030
|
const query = payload.Query('File').equalTo('_id', id);
|
|
1993
2031
|
const file = await query.first({ master: payload.isMaster });
|
|
1994
2032
|
if (!file || file.filename !== name)
|
|
1995
|
-
return res.sendStatus(404);
|
|
2033
|
+
return void res.sendStatus(404);
|
|
1996
2034
|
if (_.isNil(file.token) || _.isNil(file.size) || _.isNil(file.type))
|
|
1997
|
-
return res.sendStatus(404);
|
|
2035
|
+
return void res.sendStatus(404);
|
|
1998
2036
|
const ranges = req.range(file.size);
|
|
1999
2037
|
const match = req.headers['if-none-match'];
|
|
2000
2038
|
if (match === `"${id}"`) {
|
|
@@ -2149,7 +2187,7 @@ var schemaRoute = (router, proto) => {
|
|
|
2149
2187
|
res.setHeader('Cache-Control', ['no-cache', 'no-store']);
|
|
2150
2188
|
const { name } = req.params;
|
|
2151
2189
|
if (_.isNil(proto.schema[name]))
|
|
2152
|
-
return res.sendStatus(404);
|
|
2190
|
+
return void res.sendStatus(404);
|
|
2153
2191
|
const payload = proto.connect(req);
|
|
2154
2192
|
await response(res, () => {
|
|
2155
2193
|
if (!payload.isMaster)
|
|
@@ -2250,10 +2288,9 @@ const schema = _.assign((x) => x, {
|
|
|
2250
2288
|
relation: (target, foreignField) => ({ type: 'relation', target, foreignField }),
|
|
2251
2289
|
});
|
|
2252
2290
|
const ProtoRoute = async (options) => {
|
|
2253
|
-
const
|
|
2254
|
-
const proto = _proto instanceof ProtoService ? _proto : new ProtoService(_proto);
|
|
2291
|
+
const proto = options.proto instanceof ProtoService ? options.proto : new ProtoService(options.proto);
|
|
2255
2292
|
await proto[_private.PVK].prepare();
|
|
2256
|
-
const router = serverJs.Server.Router().use(authHandler(proto),
|
|
2293
|
+
const router = serverJs.Server.Router().use(authHandler(proto), (req, res, next) => {
|
|
2257
2294
|
const payload = proto.connect(req);
|
|
2258
2295
|
if (!payload.isInvalidMasterToken)
|
|
2259
2296
|
return next();
|