proto.io 0.0.172 → 0.0.174
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 +2 -2
- package/dist/adapters/file/database.mjs +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 +9 -2
- package/dist/adapters/storage/progres.js +58 -5
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +58 -5
- 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 +75 -3
- package/dist/index.js +242 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +243 -13
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{index-BYbMU-Ao.mjs → index--ifyu-GL.mjs} +139 -1
- package/dist/internals/index--ifyu-GL.mjs.map +1 -0
- package/dist/internals/{index-B1wqSio6.mjs → index-C3fbOqmn.mjs} +2 -2
- package/dist/internals/{index-B1wqSio6.mjs.map → index-C3fbOqmn.mjs.map} +1 -1
- package/dist/internals/index-CE5tdYK8.d.ts +1816 -0
- package/dist/internals/index-CE5tdYK8.d.ts.map +1 -0
- package/dist/internals/{index-K0jhERvZ.d.ts → index-CGX3qcjQ.d.ts} +2 -2
- package/dist/internals/index-CGX3qcjQ.d.ts.map +1 -0
- package/dist/internals/{index-CVutVPmd.js → index-DXuW8UiB.js} +139 -1
- package/dist/internals/index-DXuW8UiB.js.map +1 -0
- package/dist/internals/{index-CzfsyXvb.js → index-Dc3V_Bzw.js} +2 -2
- package/dist/internals/{index-CzfsyXvb.js.map → index-Dc3V_Bzw.js.map} +1 -1
- package/dist/internals/{index-D0hHgn2P.mjs → index-R0gbIGc-.mjs} +289 -2
- package/dist/internals/index-R0gbIGc-.mjs.map +1 -0
- package/dist/internals/{index-BJP46VGq.js → index-S_gTMQBh.js} +289 -2
- package/dist/internals/index-S_gTMQBh.js.map +1 -0
- package/dist/internals/{index-DchUjNEf.d.ts → index-uwXdnxqN.d.ts} +2 -2
- package/dist/internals/index-uwXdnxqN.d.ts.map +1 -0
- package/dist/internals/{random-BCpwYpyw.mjs → random-DPRG8oW6.mjs} +3 -3
- package/dist/internals/{random-BCpwYpyw.mjs.map → random-DPRG8oW6.mjs.map} +1 -1
- package/dist/internals/{random-Dytum6Nh.js → random-DVOUDDGg.js} +3 -3
- package/dist/internals/{random-Dytum6Nh.js.map → random-DVOUDDGg.js.map} +1 -1
- package/package.json +1 -1
- package/dist/internals/index-BJP46VGq.js.map +0 -1
- package/dist/internals/index-BYbMU-Ao.mjs.map +0 -1
- package/dist/internals/index-BhWRmBiq.d.ts +0 -726
- package/dist/internals/index-BhWRmBiq.d.ts.map +0 -1
- package/dist/internals/index-CVutVPmd.js.map +0 -1
- package/dist/internals/index-D0hHgn2P.mjs.map +0 -1
- package/dist/internals/index-DchUjNEf.d.ts.map +0 -1
- package/dist/internals/index-K0jhERvZ.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
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-DPRG8oW6.mjs';
|
|
4
4
|
import { P as PVK } from './internals/private-BUpLAMZi.mjs';
|
|
5
5
|
import { prototypes, asyncStream, asyncIterableToArray, isBinaryData, base64ToBuffer } from '@o2ter/utils-js';
|
|
6
|
-
import { T as TQuery, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, P as ProtoType, s as serialize, d as deserialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-
|
|
7
|
-
export { c as ProtoClient, e as classExtends, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser } from './internals/index-
|
|
8
|
-
import { i as isPointer, a as isRelation, d as decodeUpdateOp, T as TObject, b as isShape, c as defaultObjectKeyTypes, e as isPrimitive } from './internals/index-
|
|
6
|
+
import { T as TQuery, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, P as ProtoType, s as serialize, d as deserialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-R0gbIGc-.mjs';
|
|
7
|
+
export { c as ProtoClient, e as classExtends, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser } from './internals/index-R0gbIGc-.mjs';
|
|
8
|
+
import { i as isPointer, a as isRelation, d as decodeUpdateOp, T as TObject, b as isShape, c as defaultObjectKeyTypes, e as isPrimitive } from './internals/index--ifyu-GL.mjs';
|
|
9
9
|
import jwt from 'jsonwebtoken';
|
|
10
10
|
import { Blob } from 'node:buffer';
|
|
11
11
|
import { Readable } from 'node:stream';
|
|
12
12
|
import { scrypt } from 'node:crypto';
|
|
13
13
|
import { promisify } from 'util';
|
|
14
14
|
import { randomBytes, randomUUID } from '@o2ter/crypto-js';
|
|
15
|
-
import { Q as QuerySelector } from './internals/index-
|
|
15
|
+
import { Q as QuerySelector } from './internals/index-C3fbOqmn.mjs';
|
|
16
16
|
import queryType from 'query-types';
|
|
17
17
|
import busboy from 'busboy';
|
|
18
18
|
export { Decimal } from 'decimal.js';
|
|
@@ -183,6 +183,13 @@ const dispatcher = (proto, options, disableSecurity) => {
|
|
|
183
183
|
throw Error('No permission');
|
|
184
184
|
return proto.storage.atomic((storage) => storage.updateOne(_validator.decodeQuery(normalize(query), 'update'), normalize(_validator.validateFields(query.className, update, 'update', QueryValidator.patterns.path))));
|
|
185
185
|
},
|
|
186
|
+
async updateMany(query, update) {
|
|
187
|
+
QueryValidator.recursiveCheck(query, update);
|
|
188
|
+
const _validator = await validator();
|
|
189
|
+
if (!_validator.validateCLPs(query.className, 'update'))
|
|
190
|
+
throw Error('No permission');
|
|
191
|
+
return proto.storage.atomic((storage) => storage.updateMany(_validator.decodeQuery(normalize(query), 'update'), normalize(_validator.validateFields(query.className, update, 'update', QueryValidator.patterns.path))));
|
|
192
|
+
},
|
|
186
193
|
async upsertOne(query, update, setOnInsert) {
|
|
187
194
|
QueryValidator.recursiveCheck(query, update, setOnInsert);
|
|
188
195
|
const _validator = await validator();
|
|
@@ -202,6 +209,25 @@ const dispatcher = (proto, options, disableSecurity) => {
|
|
|
202
209
|
}
|
|
203
210
|
}
|
|
204
211
|
},
|
|
212
|
+
async upsertMany(query, update, setOnInsert) {
|
|
213
|
+
QueryValidator.recursiveCheck(query, update, setOnInsert);
|
|
214
|
+
const _validator = await validator();
|
|
215
|
+
if (!_validator.validateCLPs(query.className, 'create', 'update'))
|
|
216
|
+
throw Error('No permission');
|
|
217
|
+
const _query = _validator.decodeQuery(normalize(query), 'update');
|
|
218
|
+
const _update = normalize(_validator.validateFields(query.className, update, 'update', QueryValidator.patterns.path));
|
|
219
|
+
const _setOnInsert = normalize(_validator.validateFields(query.className, setOnInsert, 'create', QueryValidator.patterns.name));
|
|
220
|
+
while (true) {
|
|
221
|
+
try {
|
|
222
|
+
return await proto.storage.atomic((storage) => storage.upsertMany(_query, _update, _setOnInsert), { lockTable: query.className, retry: true });
|
|
223
|
+
}
|
|
224
|
+
catch (e) {
|
|
225
|
+
if (proto.storage.isDuplicateIdError(e))
|
|
226
|
+
continue;
|
|
227
|
+
throw e;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
},
|
|
205
231
|
async deleteOne(query) {
|
|
206
232
|
QueryValidator.recursiveCheck(query);
|
|
207
233
|
const _validator = await validator();
|
|
@@ -383,7 +409,12 @@ class _ProtoQuery extends TQuery {
|
|
|
383
409
|
if (!result)
|
|
384
410
|
throw Error('Unable to insert document');
|
|
385
411
|
if (_.isFunction(afterSave)) {
|
|
386
|
-
|
|
412
|
+
try {
|
|
413
|
+
await afterSave(proxy(Object.setPrototypeOf({ object: result.clone(), context }, options?.session ?? this._proto)));
|
|
414
|
+
}
|
|
415
|
+
catch (e) {
|
|
416
|
+
console.error(e);
|
|
417
|
+
}
|
|
387
418
|
}
|
|
388
419
|
return result;
|
|
389
420
|
}
|
|
@@ -411,7 +442,14 @@ class _ProtoQuery extends TQuery {
|
|
|
411
442
|
matches: this[PVK].options.matches,
|
|
412
443
|
}, _.map(objects, x => _.fromPairs([...x._set_entries()])));
|
|
413
444
|
if (_.isFunction(afterSave)) {
|
|
414
|
-
await Promise.all(_.map(objects, object =>
|
|
445
|
+
await Promise.all(_.map(objects, async (object) => {
|
|
446
|
+
try {
|
|
447
|
+
await afterSave(proxy(Object.setPrototypeOf({ object: object.clone(), context }, options?.session ?? this._proto)));
|
|
448
|
+
}
|
|
449
|
+
catch (e) {
|
|
450
|
+
console.error(e);
|
|
451
|
+
}
|
|
452
|
+
}));
|
|
415
453
|
}
|
|
416
454
|
return objects.length;
|
|
417
455
|
}
|
|
@@ -436,10 +474,49 @@ class _ProtoQuery extends TQuery {
|
|
|
436
474
|
}
|
|
437
475
|
const result = this._objectMethods(await this._dispatcher(options).updateOne(this._queryOptions, update));
|
|
438
476
|
if (result && _.isFunction(afterSave)) {
|
|
439
|
-
|
|
477
|
+
try {
|
|
478
|
+
await afterSave(proxy(Object.setPrototypeOf({ object: result.clone(), context }, options?.session ?? this._proto)));
|
|
479
|
+
}
|
|
480
|
+
catch (e) {
|
|
481
|
+
console.error(e);
|
|
482
|
+
}
|
|
440
483
|
}
|
|
441
484
|
return result;
|
|
442
485
|
}
|
|
486
|
+
async updateMany(update, options) {
|
|
487
|
+
const context = options?.context ?? {};
|
|
488
|
+
const silent = _.castArray(options?.silent ?? []);
|
|
489
|
+
const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[PVK].triggers?.beforeSave?.[this.className];
|
|
490
|
+
const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[PVK].triggers?.afterSave?.[this.className];
|
|
491
|
+
if (_.isFunction(beforeSave) || _.isFunction(afterSave)) {
|
|
492
|
+
const objects = this._objectMethods(await asyncIterableToArray(this._dispatcher(options).find(this._queryOptions)));
|
|
493
|
+
if (_.isEmpty(objects))
|
|
494
|
+
return 0;
|
|
495
|
+
if (_.isFunction(beforeSave)) {
|
|
496
|
+
await Promise.all(_.map(objects, object => beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
|
|
497
|
+
}
|
|
498
|
+
if (!_.isFunction(afterSave)) {
|
|
499
|
+
return this._dispatcher(options).updateMany({
|
|
500
|
+
...this._queryOptions,
|
|
501
|
+
filter: { _id: { $in: _.map(objects, x => x.objectId) } },
|
|
502
|
+
}, update);
|
|
503
|
+
}
|
|
504
|
+
const updated = _.compact(await Promise.all(_.map(objects, x => this._dispatcher(options).updateOne({
|
|
505
|
+
...this._queryOptions,
|
|
506
|
+
filter: { _id: { $eq: x.objectId } },
|
|
507
|
+
}, update))));
|
|
508
|
+
await Promise.all(_.map(updated, async (object) => {
|
|
509
|
+
try {
|
|
510
|
+
await afterSave(proxy(Object.setPrototypeOf({ object: object.clone(), context }, options?.session ?? this._proto)));
|
|
511
|
+
}
|
|
512
|
+
catch (e) {
|
|
513
|
+
console.error(e);
|
|
514
|
+
}
|
|
515
|
+
}));
|
|
516
|
+
return updated.length;
|
|
517
|
+
}
|
|
518
|
+
return this._dispatcher(options).updateMany(this._queryOptions, update);
|
|
519
|
+
}
|
|
443
520
|
async upsertOne(update, setOnInsert, options) {
|
|
444
521
|
const context = options?.context ?? {};
|
|
445
522
|
const silent = _.castArray(options?.silent ?? []);
|
|
@@ -474,10 +551,68 @@ class _ProtoQuery extends TQuery {
|
|
|
474
551
|
if (!result)
|
|
475
552
|
throw Error('Unable to upsert document');
|
|
476
553
|
if (_.isFunction(afterSave)) {
|
|
477
|
-
|
|
554
|
+
try {
|
|
555
|
+
await afterSave(proxy(Object.setPrototypeOf({ object: result.clone(), context }, options?.session ?? this._proto)));
|
|
556
|
+
}
|
|
557
|
+
catch (e) {
|
|
558
|
+
console.error(e);
|
|
559
|
+
}
|
|
478
560
|
}
|
|
479
561
|
return result;
|
|
480
562
|
}
|
|
563
|
+
async upsertMany(update, setOnInsert, options) {
|
|
564
|
+
const context = options?.context ?? {};
|
|
565
|
+
const silent = _.castArray(options?.silent ?? []);
|
|
566
|
+
const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[PVK].triggers?.beforeSave?.[this.className];
|
|
567
|
+
const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[PVK].triggers?.afterSave?.[this.className];
|
|
568
|
+
if (_.isFunction(beforeSave) || _.isFunction(afterSave)) {
|
|
569
|
+
const objects = this._objectMethods(await asyncIterableToArray(this._dispatcher(options).find(this._queryOptions)));
|
|
570
|
+
if (!_.isEmpty(objects) && _.isFunction(beforeSave)) {
|
|
571
|
+
await Promise.all(_.map(objects, object => beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
|
|
572
|
+
}
|
|
573
|
+
if (_.isEmpty(objects)) {
|
|
574
|
+
const result = await this._dispatcher(options).insert({
|
|
575
|
+
className: this.className,
|
|
576
|
+
includes: this[PVK].options.includes,
|
|
577
|
+
matches: this[PVK].options.matches,
|
|
578
|
+
}, setOnInsert);
|
|
579
|
+
if (!result)
|
|
580
|
+
throw Error('Unable to insert document');
|
|
581
|
+
if (_.isFunction(afterSave)) {
|
|
582
|
+
try {
|
|
583
|
+
await afterSave(proxy(Object.setPrototypeOf({ object: result.clone(), context }, options?.session ?? this._proto)));
|
|
584
|
+
}
|
|
585
|
+
catch (e) {
|
|
586
|
+
console.error(e);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
return { updated: 0, inserted: 1 };
|
|
590
|
+
}
|
|
591
|
+
if (!_.isFunction(afterSave)) {
|
|
592
|
+
return {
|
|
593
|
+
inserted: 0,
|
|
594
|
+
updated: await this._dispatcher(options).updateMany({
|
|
595
|
+
...this._queryOptions,
|
|
596
|
+
filter: { _id: { $in: _.map(objects, x => x.objectId) } },
|
|
597
|
+
}, update),
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
const updated = _.compact(await Promise.all(_.map(objects, x => this._dispatcher(options).updateOne({
|
|
601
|
+
...this._queryOptions,
|
|
602
|
+
filter: { _id: { $eq: x.objectId } },
|
|
603
|
+
}, update))));
|
|
604
|
+
await Promise.all(_.map(updated, async (object) => {
|
|
605
|
+
try {
|
|
606
|
+
await afterSave(proxy(Object.setPrototypeOf({ object: object.clone(), context }, options?.session ?? this._proto)));
|
|
607
|
+
}
|
|
608
|
+
catch (e) {
|
|
609
|
+
console.error(e);
|
|
610
|
+
}
|
|
611
|
+
}));
|
|
612
|
+
return { updated: updated.length, inserted: 0 };
|
|
613
|
+
}
|
|
614
|
+
return this._dispatcher(options).upsertMany(this._queryOptions, update, setOnInsert);
|
|
615
|
+
}
|
|
481
616
|
async deleteOne(options) {
|
|
482
617
|
const context = options?.context ?? {};
|
|
483
618
|
const silent = _.castArray(options?.silent ?? []);
|
|
@@ -498,7 +633,12 @@ class _ProtoQuery extends TQuery {
|
|
|
498
633
|
result = this._objectMethods(await this._dispatcher(options).deleteOne(this._queryOptions));
|
|
499
634
|
}
|
|
500
635
|
if (result && _.isFunction(afterDelete)) {
|
|
501
|
-
|
|
636
|
+
try {
|
|
637
|
+
await afterDelete(proxy(Object.setPrototypeOf({ object: result.clone(), context }, options?.session ?? this._proto)));
|
|
638
|
+
}
|
|
639
|
+
catch (e) {
|
|
640
|
+
console.error(e);
|
|
641
|
+
}
|
|
502
642
|
}
|
|
503
643
|
return result;
|
|
504
644
|
}
|
|
@@ -519,7 +659,14 @@ class _ProtoQuery extends TQuery {
|
|
|
519
659
|
filter: { _id: { $in: _.map(objects, x => x.objectId) } },
|
|
520
660
|
});
|
|
521
661
|
if (_.isFunction(afterDelete)) {
|
|
522
|
-
await Promise.all(_.map(objects, object =>
|
|
662
|
+
await Promise.all(_.map(objects, async (object) => {
|
|
663
|
+
try {
|
|
664
|
+
await afterDelete(proxy(Object.setPrototypeOf({ object: object.clone(), context }, options?.session ?? this._proto)));
|
|
665
|
+
}
|
|
666
|
+
catch (e) {
|
|
667
|
+
console.error(e);
|
|
668
|
+
}
|
|
669
|
+
}));
|
|
523
670
|
}
|
|
524
671
|
return objects.length;
|
|
525
672
|
}
|
|
@@ -1442,8 +1589,8 @@ class ProtoService extends ProtoType {
|
|
|
1442
1589
|
}
|
|
1443
1590
|
async userRoles(user) {
|
|
1444
1591
|
const self = this;
|
|
1592
|
+
const { inheritKeys, resolver } = self[PVK].options.roleResolver;
|
|
1445
1593
|
const defaultResolver = async () => {
|
|
1446
|
-
const inheritKeys = self[PVK].options.roleResolver?.inheritKeys ?? [];
|
|
1447
1594
|
const schema = self.schema;
|
|
1448
1595
|
const userKeys = _.filter(inheritKeys, k => {
|
|
1449
1596
|
const type = resolveDataType(schema, 'Role', k);
|
|
@@ -1468,7 +1615,6 @@ class ProtoService extends ProtoType {
|
|
|
1468
1615
|
}
|
|
1469
1616
|
return roles;
|
|
1470
1617
|
};
|
|
1471
|
-
const resolver = self[PVK].options.roleResolver?.resolver;
|
|
1472
1618
|
if (resolver)
|
|
1473
1619
|
return resolver(user, defaultResolver);
|
|
1474
1620
|
return defaultResolver();
|
|
@@ -1776,7 +1922,9 @@ var classesRoute = (router, proto) => {
|
|
|
1776
1922
|
case 'insert': return query.insert(attributes, opts);
|
|
1777
1923
|
case 'insertMany': return query.insertMany(attributes, opts);
|
|
1778
1924
|
case 'updateOne': return query.updateOne(update, opts);
|
|
1925
|
+
case 'updateMany': return query.updateMany(update, opts);
|
|
1779
1926
|
case 'upsertOne': return query.upsertOne(update, setOnInsert, opts);
|
|
1927
|
+
case 'upsertMany': return query.upsertMany(update, setOnInsert, opts);
|
|
1780
1928
|
case 'deleteOne': return query.deleteOne(opts);
|
|
1781
1929
|
case 'deleteMany': return query.deleteMany(opts);
|
|
1782
1930
|
default: throw Error('Invalid operation');
|
|
@@ -1880,6 +2028,16 @@ var classesRoute = (router, proto) => {
|
|
|
1880
2028
|
const payload = proto.connect(req);
|
|
1881
2029
|
await response(res, async () => payload.refs(payload.Object(name, id), { master: payload.isMaster }));
|
|
1882
2030
|
});
|
|
2031
|
+
router.patch('/classes/:name', Server.text({ type: '*/*' }), async (req, res) => {
|
|
2032
|
+
res.setHeader('Cache-Control', ['no-cache', 'no-store']);
|
|
2033
|
+
const { name } = req.params;
|
|
2034
|
+
const classes = proto.classes();
|
|
2035
|
+
if (!_.includes(classes, name))
|
|
2036
|
+
return void res.sendStatus(404);
|
|
2037
|
+
const payload = proto.connect(req);
|
|
2038
|
+
const update = _.mapValues(deserialize(req.body), v => ({ $set: v }));
|
|
2039
|
+
await response(res, () => createQuery(payload, req, false).updateMany(update, { master: payload.isMaster }));
|
|
2040
|
+
});
|
|
1883
2041
|
router.patch('/classes/:name/:id', Server.text({ type: '*/*' }), async (req, res) => {
|
|
1884
2042
|
res.setHeader('Cache-Control', ['no-cache', 'no-store']);
|
|
1885
2043
|
const { name, id } = req.params;
|
|
@@ -2271,19 +2429,84 @@ var configRoute = (router, proto) => {
|
|
|
2271
2429
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
2272
2430
|
// THE SOFTWARE.
|
|
2273
2431
|
//
|
|
2432
|
+
/**
|
|
2433
|
+
* Schema definition utility functions.
|
|
2434
|
+
*/
|
|
2274
2435
|
const schema = _.assign((x) => x, {
|
|
2436
|
+
/**
|
|
2437
|
+
* Defines a boolean schema.
|
|
2438
|
+
* @param defaultValue - The default value for the boolean.
|
|
2439
|
+
* @returns The boolean schema.
|
|
2440
|
+
*/
|
|
2275
2441
|
boolean: (defaultValue) => ({ type: 'boolean', default: defaultValue }),
|
|
2442
|
+
/**
|
|
2443
|
+
* Defines a number schema.
|
|
2444
|
+
* @param defaultValue - The default value for the number.
|
|
2445
|
+
* @returns The number schema.
|
|
2446
|
+
*/
|
|
2276
2447
|
number: (defaultValue) => ({ type: 'number', default: defaultValue }),
|
|
2448
|
+
/**
|
|
2449
|
+
* Defines a decimal schema.
|
|
2450
|
+
* @param defaultValue - The default value for the decimal.
|
|
2451
|
+
* @returns The decimal schema.
|
|
2452
|
+
*/
|
|
2277
2453
|
decimal: (defaultValue) => ({ type: 'decimal', default: defaultValue }),
|
|
2454
|
+
/**
|
|
2455
|
+
* Defines a string schema.
|
|
2456
|
+
* @param defaultValue - The default value for the string.
|
|
2457
|
+
* @returns The string schema.
|
|
2458
|
+
*/
|
|
2278
2459
|
string: (defaultValue) => ({ type: 'string', default: defaultValue }),
|
|
2460
|
+
/**
|
|
2461
|
+
* Defines a date schema.
|
|
2462
|
+
* @param defaultValue - The default value for the date.
|
|
2463
|
+
* @returns The date schema.
|
|
2464
|
+
*/
|
|
2279
2465
|
date: (defaultValue) => ({ type: 'date', default: defaultValue }),
|
|
2466
|
+
/**
|
|
2467
|
+
* Defines an object schema.
|
|
2468
|
+
* @param defaultValue - The default value for the object.
|
|
2469
|
+
* @returns The object schema.
|
|
2470
|
+
*/
|
|
2280
2471
|
object: (defaultValue) => ({ type: 'object', default: defaultValue }),
|
|
2472
|
+
/**
|
|
2473
|
+
* Defines an array schema.
|
|
2474
|
+
* @param defaultValue - The default value for the array.
|
|
2475
|
+
* @returns The array schema.
|
|
2476
|
+
*/
|
|
2281
2477
|
array: (defaultValue) => ({ type: 'array', default: defaultValue }),
|
|
2478
|
+
/**
|
|
2479
|
+
* Defines a vector schema.
|
|
2480
|
+
* @param dimension - The dimension of the vector.
|
|
2481
|
+
* @param defaultValue - The default value for the vector.
|
|
2482
|
+
* @returns The vector schema.
|
|
2483
|
+
*/
|
|
2282
2484
|
vector: (dimension, defaultValue) => ({ type: 'vector', dimension, default: defaultValue }),
|
|
2485
|
+
/**
|
|
2486
|
+
* Defines a shape schema.
|
|
2487
|
+
* @param shape - The shape definition.
|
|
2488
|
+
* @returns The shape schema.
|
|
2489
|
+
*/
|
|
2283
2490
|
shape: (shape) => ({ type: 'shape', shape }),
|
|
2491
|
+
/**
|
|
2492
|
+
* Defines a pointer schema.
|
|
2493
|
+
* @param target - The target of the pointer.
|
|
2494
|
+
* @returns The pointer schema.
|
|
2495
|
+
*/
|
|
2284
2496
|
pointer: (target) => ({ type: 'pointer', target }),
|
|
2497
|
+
/**
|
|
2498
|
+
* Defines a relation schema.
|
|
2499
|
+
* @param target - The target of the relation.
|
|
2500
|
+
* @param foreignField - The foreign field of the relation.
|
|
2501
|
+
* @returns The relation schema.
|
|
2502
|
+
*/
|
|
2285
2503
|
relation: (target, foreignField) => ({ type: 'relation', target, foreignField }),
|
|
2286
2504
|
});
|
|
2505
|
+
/**
|
|
2506
|
+
* Creates a ProtoRoute.
|
|
2507
|
+
* @param options - The options for the ProtoRoute.
|
|
2508
|
+
* @returns A promise that resolves to a Router.
|
|
2509
|
+
*/
|
|
2287
2510
|
const ProtoRoute = async (options) => {
|
|
2288
2511
|
const proto = options.proto instanceof ProtoService ? options.proto : new ProtoService(options.proto);
|
|
2289
2512
|
await proto[PVK].prepare();
|
|
@@ -2306,6 +2529,13 @@ const ProtoRoute = async (options) => {
|
|
|
2306
2529
|
configRoute(router, proto);
|
|
2307
2530
|
return router;
|
|
2308
2531
|
};
|
|
2532
|
+
/**
|
|
2533
|
+
* Registers a ProtoSocket.
|
|
2534
|
+
* @param proto - The ProtoService instance.
|
|
2535
|
+
* @param server - The server instance.
|
|
2536
|
+
* @param endpoint - The optional endpoint.
|
|
2537
|
+
* @returns The socket.io instance.
|
|
2538
|
+
*/
|
|
2309
2539
|
const registerProtoSocket = (proto, server, endpoint) => {
|
|
2310
2540
|
const io = endpoint ? server.socket().of(endpoint) : server.socket();
|
|
2311
2541
|
io.on('connection', async (socket) => {
|