proto.io 0.0.182 → 0.0.184
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.js +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 +19 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -7
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{index-BnDahEvz.js → index-BEK58Z0z.js} +3 -3
- package/dist/internals/index-BEK58Z0z.js.map +1 -0
- package/dist/internals/{index-CmJh3t_k.mjs → index-CQdNVgOu.mjs} +3 -3
- package/dist/internals/index-CQdNVgOu.mjs.map +1 -0
- package/dist/internals/{index-cKx59cIc.d.ts → index-CT5PbMDJ.d.ts} +2 -2
- package/dist/internals/index-CT5PbMDJ.d.ts.map +1 -0
- package/dist/internals/{index-BZupzq1Y.d.ts → index-CWGYv9An.d.ts} +2 -2
- package/dist/internals/index-CWGYv9An.d.ts.map +1 -0
- package/dist/internals/{index-YpB-hXxf.d.ts → index-CvKCWBvj.d.ts} +16 -16
- package/dist/internals/index-CvKCWBvj.d.ts.map +1 -0
- package/dist/internals/{random-CDtFUuES.js → random-80Vpxbxh.js} +9 -11
- package/dist/internals/random-80Vpxbxh.js.map +1 -0
- package/dist/internals/{random-BSyWEK8G.mjs → random-BtYyzHJD.mjs} +9 -11
- package/dist/internals/random-BtYyzHJD.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/internals/index-BZupzq1Y.d.ts.map +0 -1
- package/dist/internals/index-BnDahEvz.js.map +0 -1
- package/dist/internals/index-CmJh3t_k.mjs.map +0 -1
- package/dist/internals/index-YpB-hXxf.d.ts.map +0 -1
- package/dist/internals/index-cKx59cIc.d.ts.map +0 -1
- package/dist/internals/random-BSyWEK8G.mjs.map +0 -1
- package/dist/internals/random-CDtFUuES.js.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import { Server } from '@o2ter/server-js';
|
|
3
|
-
import { Q as QueryValidator, r as resolveColumn, a as resolveDataType, g as generateId } from './internals/random-
|
|
3
|
+
import { Q as QueryValidator, r as resolveColumn, a as resolveDataType, g as generateId } from './internals/random-BtYyzHJD.mjs';
|
|
4
4
|
import { P as PVK } from './internals/private-CNw40LZ7.mjs';
|
|
5
5
|
import { asyncStream, prototypes, isBinaryData, base64ToBuffer } from '@o2ter/utils-js';
|
|
6
|
-
import { T as TQuery, P as PROTO_NOTY_MSG, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, c as ProtoType, s as serialize, d as deserialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-
|
|
7
|
-
export { e as ProtoClient, f as classExtends, k as isFile, g as isObject, i as isQuery, j as isRole, h as isUser } from './internals/index-
|
|
6
|
+
import { T as TQuery, P as PROTO_NOTY_MSG, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, c as ProtoType, s as serialize, d as deserialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-CQdNVgOu.mjs';
|
|
7
|
+
export { e as ProtoClient, f as classExtends, k as isFile, g as isObject, i as isQuery, j as isRole, h as isUser } from './internals/index-CQdNVgOu.mjs';
|
|
8
8
|
import { i as isPointer, a as isRelation, T as TObject, b as isShape, d as defaultObjectKeyTypes, c as isPrimitive } from './internals/index-DyjcBbS1.mjs';
|
|
9
9
|
import jwt from 'jsonwebtoken';
|
|
10
10
|
import { Blob } from 'node:buffer';
|
|
@@ -79,9 +79,12 @@ const normalize = (x) => {
|
|
|
79
79
|
// THE SOFTWARE.
|
|
80
80
|
//
|
|
81
81
|
const fetchUserPerms = async (proto) => _.uniq(_.compact([..._.map(await proto.currentRoles(), x => `role:${x}`), (await proto.currentUser())?.objectId]));
|
|
82
|
-
const dispatcher = (proto, options
|
|
82
|
+
const dispatcher = (proto, options) => {
|
|
83
83
|
const acls = async () => options.master ? [] : await fetchUserPerms(proto);
|
|
84
|
-
const validator = async () => new QueryValidator(proto, await acls(),
|
|
84
|
+
const validator = async () => new QueryValidator(proto, await acls(), {
|
|
85
|
+
master: options.master ?? false,
|
|
86
|
+
disableSecurity: options.disableSecurity,
|
|
87
|
+
});
|
|
85
88
|
return {
|
|
86
89
|
async explain(query) {
|
|
87
90
|
QueryValidator.recursiveCheck(query);
|
|
@@ -315,11 +318,17 @@ class _ProtoQuery extends TQuery {
|
|
|
315
318
|
};
|
|
316
319
|
}
|
|
317
320
|
_dispatcher(options) {
|
|
321
|
+
const schema = this._proto.schema[this.className];
|
|
322
|
+
if (_.isNil(schema))
|
|
323
|
+
throw Error('Invalid className');
|
|
318
324
|
if (this._opts.insecure) {
|
|
319
325
|
if (options?.master !== true)
|
|
320
326
|
throw Error('No permission');
|
|
321
327
|
}
|
|
322
|
-
return dispatcher(_serviceOf(options) ?? this._proto,
|
|
328
|
+
return dispatcher(_serviceOf(options) ?? this._proto, {
|
|
329
|
+
...options ?? {},
|
|
330
|
+
disableSecurity: !!this._opts.insecure,
|
|
331
|
+
});
|
|
323
332
|
}
|
|
324
333
|
explain(options) {
|
|
325
334
|
return this._dispatcher(options).explain(this._queryOptions);
|
|
@@ -725,6 +734,8 @@ const validateForeignField = (schema, key, dataType) => {
|
|
|
725
734
|
throw Error(`Invalid foreign field: ${key}`);
|
|
726
735
|
};
|
|
727
736
|
const validateShapedObject = (schema, dataType) => {
|
|
737
|
+
if (_.isEmpty(dataType.shape))
|
|
738
|
+
throw Error('Invalid empty shape');
|
|
728
739
|
for (const [key, type] of _.entries(dataType.shape)) {
|
|
729
740
|
if (!key.match(QueryValidator.patterns.name))
|
|
730
741
|
throw Error(`Invalid field name: ${key}`);
|
|
@@ -1299,7 +1310,8 @@ const fetchSessionInfo = async (proto, userId) => {
|
|
|
1299
1310
|
const cache = userCacheMap.get(proto[PVK]);
|
|
1300
1311
|
if (_.isNil(cache[userId]))
|
|
1301
1312
|
cache[userId] = (async () => {
|
|
1302
|
-
const
|
|
1313
|
+
const _user = _.isString(userId) ? await proto.Query('User').get(userId, { master: true }) : undefined;
|
|
1314
|
+
const user = proto.req ? await proto[PVK].options.userResolver(proto, _user) : _user;
|
|
1303
1315
|
const _roles = user instanceof TUser ? _.filter(await proto.userRoles(user), x => !_.isEmpty(x.name)) : [];
|
|
1304
1316
|
cache[userId] = undefined;
|
|
1305
1317
|
return { user, _roles };
|
|
@@ -1451,6 +1463,7 @@ class ProtoService extends ProtoType {
|
|
|
1451
1463
|
constructor(options) {
|
|
1452
1464
|
super();
|
|
1453
1465
|
this[PVK] = new ProtoInternal({
|
|
1466
|
+
userResolver: (_req, user) => user,
|
|
1454
1467
|
roleResolver: {},
|
|
1455
1468
|
objectIdSize: 10,
|
|
1456
1469
|
maxFetchLimit: 1000,
|