proto.io 0.0.217 → 0.0.219
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 +2 -2
- package/dist/adapters/file/database.mjs +2 -2
- 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 +38 -38
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +38 -38
- package/dist/adapters/storage/progres.mjs.map +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/client.js +2 -2
- package/dist/client.mjs +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +27 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -28
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{base-CWnOBKD5.d.ts → base-C1uAg1dD.d.ts} +2 -2
- package/dist/internals/base-C1uAg1dD.d.ts.map +1 -0
- package/dist/internals/{chunk-CNNSQpRF.d.ts → chunk-CpgqvFNO.d.ts} +3 -3
- package/dist/internals/chunk-CpgqvFNO.d.ts.map +1 -0
- package/dist/internals/{index-Bs8n7Q8f.d.ts → index-82GLvDiN.d.ts} +18 -18
- package/dist/internals/index-82GLvDiN.d.ts.map +1 -0
- package/dist/internals/{index-B8TESzd9.js → index-CLKTEIj0.js} +2 -2
- package/dist/internals/index-CLKTEIj0.js.map +1 -0
- package/dist/internals/{index-BRIlS3mY.d.ts → index-CWhqANZM.d.ts} +3 -3
- package/dist/internals/index-CWhqANZM.d.ts.map +1 -0
- package/dist/internals/{index-DfqABzjr.mjs → index-CZ5fKgiJ.mjs} +26 -26
- package/dist/internals/index-CZ5fKgiJ.mjs.map +1 -0
- package/dist/internals/{index-BzDsTt4R.mjs → index-gWcE22mf.mjs} +2 -2
- package/dist/internals/index-gWcE22mf.mjs.map +1 -0
- package/dist/internals/{index-DylUjD_1.js → index-xHeu-AjT.js} +26 -26
- package/dist/internals/index-xHeu-AjT.js.map +1 -0
- package/dist/internals/{validator-mcBCJP4P.js → validator-B5yHpyvb.js} +10 -10
- package/dist/internals/validator-B5yHpyvb.js.map +1 -0
- package/dist/internals/{validator-CEcBF4Cn.mjs → validator-DX2nXeQo.mjs} +10 -10
- package/dist/internals/validator-DX2nXeQo.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/internals/base-CWnOBKD5.d.ts.map +0 -1
- package/dist/internals/chunk-CNNSQpRF.d.ts.map +0 -1
- package/dist/internals/index-B8TESzd9.js.map +0 -1
- package/dist/internals/index-BRIlS3mY.d.ts.map +0 -1
- package/dist/internals/index-Bs8n7Q8f.d.ts.map +0 -1
- package/dist/internals/index-BzDsTt4R.mjs.map +0 -1
- package/dist/internals/index-DfqABzjr.mjs.map +0 -1
- package/dist/internals/index-DylUjD_1.js.map +0 -1
- package/dist/internals/validator-CEcBF4Cn.mjs.map +0 -1
- package/dist/internals/validator-mcBCJP4P.js.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import { Server } from '@o2ter/server-js';
|
|
3
|
-
import { Q as QueryValidator, a as QueryExpression, r as resolveColumn, b as resolveDataType, c as QuerySelector } from './internals/validator-
|
|
3
|
+
import { Q as QueryValidator, a as QueryExpression, r as resolveColumn, b as resolveDataType, c as QuerySelector } from './internals/validator-DX2nXeQo.mjs';
|
|
4
4
|
import { P as PVK } from './internals/private-CNw40LZ7.mjs';
|
|
5
5
|
import { prototypes, asyncStream, isBinaryData, base64ToBuffer } from '@o2ter/utils-js';
|
|
6
|
-
import { L as LiveQuerySubscription, T as TQuery, d as deserialize, s as serialize, a as TUser, P as ProtoType, _ as _logLevels } from './internals/index-
|
|
7
|
-
export { b as ProtoClient, c as classExtends } from './internals/index-
|
|
8
|
-
import { i as isPointer, a as isRelation, T as TObject, b as isShape, d as defaultObjectKeyTypes, c as isPrimitive } from './internals/index-
|
|
6
|
+
import { L as LiveQuerySubscription, T as TQuery, d as deserialize, s as serialize, a as TUser, P as ProtoType, _ as _logLevels } from './internals/index-CZ5fKgiJ.mjs';
|
|
7
|
+
export { b as ProtoClient, c as classExtends } from './internals/index-CZ5fKgiJ.mjs';
|
|
8
|
+
import { i as isPointer, a as isRelation, T as TObject, b as isShape, d as defaultObjectKeyTypes, c as isPrimitive } from './internals/index-gWcE22mf.mjs';
|
|
9
9
|
import jwt from 'jsonwebtoken';
|
|
10
10
|
import { Blob } from 'node:buffer';
|
|
11
11
|
import { Readable } from 'node:stream';
|
|
@@ -79,7 +79,7 @@ const normalize = (x) => {
|
|
|
79
79
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
80
80
|
// THE SOFTWARE.
|
|
81
81
|
//
|
|
82
|
-
const fetchUserPerms = async (proto) => _.uniq(_.compact([..._.map(await proto.currentRoles(), x => `role:${x}`), (await proto.currentUser())?.
|
|
82
|
+
const fetchUserPerms = async (proto) => _.uniq(_.compact([..._.map(await proto.currentRoles(), x => `role:${x}`), (await proto.currentUser())?.id]));
|
|
83
83
|
const dispatcher = (proto, options) => {
|
|
84
84
|
const acls = async () => options.master ? [] : await fetchUserPerms(proto);
|
|
85
85
|
const validator = async () => new QueryValidator(proto, await acls(), {
|
|
@@ -849,34 +849,34 @@ class ProtoInternal {
|
|
|
849
849
|
return callback(proxy(payload ?? proto));
|
|
850
850
|
}
|
|
851
851
|
async varifyPassword(proto, user, password, options) {
|
|
852
|
-
if (!user.
|
|
852
|
+
if (!user.id)
|
|
853
853
|
throw Error('Invalid user object');
|
|
854
854
|
const _user = await proto.InsecureQuery('User')
|
|
855
|
-
.equalTo('_id', user.
|
|
855
|
+
.equalTo('_id', user.id)
|
|
856
856
|
.includes('_id', 'password')
|
|
857
857
|
.first(options);
|
|
858
858
|
const { alg, ...opts } = _user?.get('password') ?? {};
|
|
859
859
|
return varifyPassword(alg, password, opts);
|
|
860
860
|
}
|
|
861
861
|
async setPassword(proto, user, password, options) {
|
|
862
|
-
if (!user.
|
|
862
|
+
if (!user.id)
|
|
863
863
|
throw Error('Invalid user object');
|
|
864
864
|
if (_.isEmpty(password))
|
|
865
865
|
throw Error('Invalid password');
|
|
866
866
|
const { alg, ...opts } = this.options.passwordHashOptions;
|
|
867
867
|
const hashed = await passwordHash(alg, password, opts);
|
|
868
868
|
await proto.InsecureQuery('User')
|
|
869
|
-
.equalTo('_id', user.
|
|
869
|
+
.equalTo('_id', user.id)
|
|
870
870
|
.includes('_id')
|
|
871
871
|
.updateOne({
|
|
872
872
|
password: { $set: hashed },
|
|
873
873
|
}, options);
|
|
874
874
|
}
|
|
875
875
|
async unsetPassword(proto, user, options) {
|
|
876
|
-
if (!user.
|
|
876
|
+
if (!user.id)
|
|
877
877
|
throw Error('Invalid user object');
|
|
878
878
|
await proto.InsecureQuery('User')
|
|
879
|
-
.equalTo('_id', user.
|
|
879
|
+
.equalTo('_id', user.id)
|
|
880
880
|
.includes('_id')
|
|
881
881
|
.updateOne({
|
|
882
882
|
password: { $set: {} },
|
|
@@ -887,7 +887,7 @@ class ProtoInternal {
|
|
|
887
887
|
throw Error('Invalid filename');
|
|
888
888
|
}
|
|
889
889
|
const updated = await proto.Query(object.className)
|
|
890
|
-
.equalTo('_id', object.
|
|
890
|
+
.equalTo('_id', object.id)
|
|
891
891
|
.includes(...object.keys())
|
|
892
892
|
.updateOne(object[PVK].mutated, options);
|
|
893
893
|
if (updated) {
|
|
@@ -967,7 +967,7 @@ class ProtoInternal {
|
|
|
967
967
|
}
|
|
968
968
|
}
|
|
969
969
|
async saveFile(proto, object, options) {
|
|
970
|
-
if (object.
|
|
970
|
+
if (object.id) {
|
|
971
971
|
object = await this.updateFile(proto, object, options);
|
|
972
972
|
}
|
|
973
973
|
else {
|
|
@@ -978,7 +978,7 @@ class ProtoInternal {
|
|
|
978
978
|
async deleteFile(proto, object, options) {
|
|
979
979
|
object = await object.fetchIfNeeded(['token'], options);
|
|
980
980
|
const deleted = await proto.Query('File')
|
|
981
|
-
.equalTo('_id', object.
|
|
981
|
+
.equalTo('_id', object.id)
|
|
982
982
|
.deleteOne(options);
|
|
983
983
|
if (deleted) {
|
|
984
984
|
object[PVK].attributes = deleted.attributes;
|
|
@@ -1387,11 +1387,11 @@ const signUser = async (proto, res, user, options) => {
|
|
|
1387
1387
|
sessionId: session?.sessionId ?? randomUUID(),
|
|
1388
1388
|
createdAt: session?.createdAt?.getTime() ?? Date.now(),
|
|
1389
1389
|
loginedAt: user ? session?.loginedAt?.getTime() ?? Date.now() : undefined,
|
|
1390
|
-
user: user?.
|
|
1390
|
+
user: user?.id,
|
|
1391
1391
|
cookieOptions,
|
|
1392
1392
|
}, options?.jwtSignOptions ?? 'login');
|
|
1393
1393
|
res.cookie(AUTH_COOKIE_KEY, token, cookieOptions);
|
|
1394
|
-
sessionInfoMap.set(res.req, user ? await fetchSessionInfo(proto, user.
|
|
1394
|
+
sessionInfoMap.set(res.req, user ? await fetchSessionInfo(proto, user.id) : {});
|
|
1395
1395
|
};
|
|
1396
1396
|
|
|
1397
1397
|
//
|
|
@@ -1539,13 +1539,13 @@ class ProtoService extends ProtoType {
|
|
|
1539
1539
|
return new ProtoQuery(className, this, {});
|
|
1540
1540
|
}
|
|
1541
1541
|
Relation(object, key) {
|
|
1542
|
-
const
|
|
1543
|
-
if (!
|
|
1542
|
+
const id = object.id;
|
|
1543
|
+
if (!id)
|
|
1544
1544
|
throw Error('Invalid object');
|
|
1545
1545
|
return new ProtoRelationQuery(this, {
|
|
1546
1546
|
relatedBy: {
|
|
1547
1547
|
className: object.className,
|
|
1548
|
-
|
|
1548
|
+
id: id,
|
|
1549
1549
|
key,
|
|
1550
1550
|
},
|
|
1551
1551
|
});
|
|
@@ -1611,10 +1611,10 @@ class ProtoService extends ProtoType {
|
|
|
1611
1611
|
while (!_.isEmpty(queue)) {
|
|
1612
1612
|
queue = await self.Query('Role')
|
|
1613
1613
|
.or(_.map(_.uniq(['roles', ...roleKeys]), k => q => q.isIntersect(k, queue)))
|
|
1614
|
-
.notContainedIn('_id', _.compact(_.map(roles, x => x.
|
|
1614
|
+
.notContainedIn('_id', _.compact(_.map(roles, x => x.id)))
|
|
1615
1615
|
.includes('name')
|
|
1616
1616
|
.find({ master: true });
|
|
1617
|
-
roles = _.uniqBy([...roles, ...queue], x => x.
|
|
1617
|
+
roles = _.uniqBy([...roles, ...queue], x => x.id);
|
|
1618
1618
|
}
|
|
1619
1619
|
return roles;
|
|
1620
1620
|
};
|
|
@@ -1623,7 +1623,7 @@ class ProtoService extends ProtoType {
|
|
|
1623
1623
|
return defaultResolver();
|
|
1624
1624
|
}
|
|
1625
1625
|
async becomeUser(req, user, options) {
|
|
1626
|
-
if (!user.
|
|
1626
|
+
if (!user.id)
|
|
1627
1627
|
throw Error('Invalid user object');
|
|
1628
1628
|
if (req.res)
|
|
1629
1629
|
await signUser(this, req.res, user, options);
|
|
@@ -1725,7 +1725,7 @@ class ProtoService extends ProtoType {
|
|
|
1725
1725
|
});
|
|
1726
1726
|
}
|
|
1727
1727
|
refs(object, options) {
|
|
1728
|
-
if (!object.
|
|
1728
|
+
if (!object.id)
|
|
1729
1729
|
throw Error('Invalid object');
|
|
1730
1730
|
const self = this;
|
|
1731
1731
|
return asyncStream(async function* () {
|
|
@@ -1889,7 +1889,7 @@ const verifyRelatedBy = (relatedBy) => {
|
|
|
1889
1889
|
return;
|
|
1890
1890
|
if (!_.isString(relatedBy.className) || _.isEmpty(relatedBy.className))
|
|
1891
1891
|
throw Error('Invalid option');
|
|
1892
|
-
if (!_.isString(relatedBy.
|
|
1892
|
+
if (!_.isString(relatedBy.id) || _.isEmpty(relatedBy.id))
|
|
1893
1893
|
throw Error('Invalid option');
|
|
1894
1894
|
if (!_.isString(relatedBy.key) || _.isEmpty(relatedBy.key))
|
|
1895
1895
|
throw Error('Invalid option');
|
|
@@ -1900,7 +1900,7 @@ var classesRoute = (router, proto) => {
|
|
|
1900
1900
|
const { operation, random, attributes, update, setOnInsert, relatedBy, silent, ...options } = deserialize(req.body);
|
|
1901
1901
|
verifyRelatedBy(relatedBy);
|
|
1902
1902
|
const payload = proto.connect(req);
|
|
1903
|
-
const query = relatedBy ? payload.Relation(payload.Object(relatedBy.className, relatedBy.
|
|
1903
|
+
const query = relatedBy ? payload.Relation(payload.Object(relatedBy.className, relatedBy.id), relatedBy.key) : payload.Query(name);
|
|
1904
1904
|
query[PVK].options = options;
|
|
1905
1905
|
const opts = { master: payload.isMaster, silent };
|
|
1906
1906
|
if (_.includes(['File', '_Job', '_JobScope'], name) &&
|
|
@@ -1963,7 +1963,7 @@ var classesRoute = (router, proto) => {
|
|
|
1963
1963
|
const { name } = req.params;
|
|
1964
1964
|
const { filter, sort, includes, skip, limit, relatedBy, } = req.query;
|
|
1965
1965
|
verifyRelatedBy(relatedBy);
|
|
1966
|
-
const query = relatedBy ? payload.Relation(payload.Object(relatedBy.className, relatedBy.
|
|
1966
|
+
const query = relatedBy ? payload.Relation(payload.Object(relatedBy.className, relatedBy.id), relatedBy.key) : payload.Query(name);
|
|
1967
1967
|
query[PVK].options.filter = !_.isEmpty(filter) && _.isString(filter) ? _.castArray(deserialize(filter)) : [];
|
|
1968
1968
|
query[PVK].options.sort = _.isPlainObject(sort) && _.every(_.values(sort), _.isNumber) ? sort : undefined;
|
|
1969
1969
|
query[PVK].options.includes = _.isArray(includes) && _.every(includes, _.isString) ? includes : undefined;
|
|
@@ -2601,7 +2601,7 @@ const registerProtoSocket = (proto, server, endpoint) => {
|
|
|
2601
2601
|
const { remove: remove_livequery } = payload[PVK]._liveQuery(payload, (ev, objs) => {
|
|
2602
2602
|
const ids = {};
|
|
2603
2603
|
for (const obj of objs) {
|
|
2604
|
-
ids[obj.
|
|
2604
|
+
ids[obj.id] = _.keys(_.pickBy(queries, v => {
|
|
2605
2605
|
if (v.event !== ev || v.className !== obj.className)
|
|
2606
2606
|
return false;
|
|
2607
2607
|
return v.filter instanceof QuerySelector ? v.filter.eval(obj) : v.filter;
|
|
@@ -2609,7 +2609,7 @@ const registerProtoSocket = (proto, server, endpoint) => {
|
|
|
2609
2609
|
}
|
|
2610
2610
|
if (_.isEmpty(ids))
|
|
2611
2611
|
return;
|
|
2612
|
-
const payload = JSON.parse(serialize(_.filter(objs, obj => !_.isEmpty(ids[obj.
|
|
2612
|
+
const payload = JSON.parse(serialize(_.filter(objs, obj => !_.isEmpty(ids[obj.id]))));
|
|
2613
2613
|
socket.emit('ON_EV_LIVEQUERY', { ids, data: payload });
|
|
2614
2614
|
});
|
|
2615
2615
|
return () => {
|