proto.io 0.0.173 → 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 +2 -2
- package/dist/adapters/storage/progres.js +3 -3
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +3 -3
- 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 +142 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +143 -18
- 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-lX-M76Tn.d.ts → index-CE5tdYK8.d.ts} +1082 -2
- package/dist/internals/index-CE5tdYK8.d.ts.map +1 -0
- package/dist/internals/{index-BJnQhKf3.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-BZNPlw1L.mjs → index-R0gbIGc-.mjs} +270 -2
- package/dist/internals/index-R0gbIGc-.mjs.map +1 -0
- package/dist/internals/{index-CIecB6mS.js → index-S_gTMQBh.js} +270 -2
- package/dist/internals/index-S_gTMQBh.js.map +1 -0
- package/dist/internals/{index-Cpv1DoEI.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-BJnQhKf3.d.ts.map +0 -1
- package/dist/internals/index-BYbMU-Ao.mjs.map +0 -1
- package/dist/internals/index-BZNPlw1L.mjs.map +0 -1
- package/dist/internals/index-CIecB6mS.js.map +0 -1
- package/dist/internals/index-CVutVPmd.js.map +0 -1
- package/dist/internals/index-Cpv1DoEI.d.ts.map +0 -1
- package/dist/internals/index-lX-M76Tn.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';
|
|
@@ -409,7 +409,12 @@ class _ProtoQuery extends TQuery {
|
|
|
409
409
|
if (!result)
|
|
410
410
|
throw Error('Unable to insert document');
|
|
411
411
|
if (_.isFunction(afterSave)) {
|
|
412
|
-
|
|
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
|
+
}
|
|
413
418
|
}
|
|
414
419
|
return result;
|
|
415
420
|
}
|
|
@@ -437,7 +442,14 @@ class _ProtoQuery extends TQuery {
|
|
|
437
442
|
matches: this[PVK].options.matches,
|
|
438
443
|
}, _.map(objects, x => _.fromPairs([...x._set_entries()])));
|
|
439
444
|
if (_.isFunction(afterSave)) {
|
|
440
|
-
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
|
+
}));
|
|
441
453
|
}
|
|
442
454
|
return objects.length;
|
|
443
455
|
}
|
|
@@ -462,7 +474,12 @@ class _ProtoQuery extends TQuery {
|
|
|
462
474
|
}
|
|
463
475
|
const result = this._objectMethods(await this._dispatcher(options).updateOne(this._queryOptions, update));
|
|
464
476
|
if (result && _.isFunction(afterSave)) {
|
|
465
|
-
|
|
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
|
+
}
|
|
466
483
|
}
|
|
467
484
|
return result;
|
|
468
485
|
}
|
|
@@ -484,11 +501,18 @@ class _ProtoQuery extends TQuery {
|
|
|
484
501
|
filter: { _id: { $in: _.map(objects, x => x.objectId) } },
|
|
485
502
|
}, update);
|
|
486
503
|
}
|
|
487
|
-
const updated = await Promise.all(_.map(objects, x => this._dispatcher(options).updateOne({
|
|
504
|
+
const updated = _.compact(await Promise.all(_.map(objects, x => this._dispatcher(options).updateOne({
|
|
488
505
|
...this._queryOptions,
|
|
489
506
|
filter: { _id: { $eq: x.objectId } },
|
|
490
|
-
}, update)));
|
|
491
|
-
await Promise.all(_.map(updated, object =>
|
|
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
|
+
}));
|
|
492
516
|
return updated.length;
|
|
493
517
|
}
|
|
494
518
|
return this._dispatcher(options).updateMany(this._queryOptions, update);
|
|
@@ -527,7 +551,12 @@ class _ProtoQuery extends TQuery {
|
|
|
527
551
|
if (!result)
|
|
528
552
|
throw Error('Unable to upsert document');
|
|
529
553
|
if (_.isFunction(afterSave)) {
|
|
530
|
-
|
|
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
|
+
}
|
|
531
560
|
}
|
|
532
561
|
return result;
|
|
533
562
|
}
|
|
@@ -550,7 +579,12 @@ class _ProtoQuery extends TQuery {
|
|
|
550
579
|
if (!result)
|
|
551
580
|
throw Error('Unable to insert document');
|
|
552
581
|
if (_.isFunction(afterSave)) {
|
|
553
|
-
|
|
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
|
+
}
|
|
554
588
|
}
|
|
555
589
|
return { updated: 0, inserted: 1 };
|
|
556
590
|
}
|
|
@@ -563,11 +597,18 @@ class _ProtoQuery extends TQuery {
|
|
|
563
597
|
}, update),
|
|
564
598
|
};
|
|
565
599
|
}
|
|
566
|
-
const updated = await Promise.all(_.map(objects, x => this._dispatcher(options).updateOne({
|
|
600
|
+
const updated = _.compact(await Promise.all(_.map(objects, x => this._dispatcher(options).updateOne({
|
|
567
601
|
...this._queryOptions,
|
|
568
602
|
filter: { _id: { $eq: x.objectId } },
|
|
569
|
-
}, update)));
|
|
570
|
-
await Promise.all(_.map(updated, object =>
|
|
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
|
+
}));
|
|
571
612
|
return { updated: updated.length, inserted: 0 };
|
|
572
613
|
}
|
|
573
614
|
return this._dispatcher(options).upsertMany(this._queryOptions, update, setOnInsert);
|
|
@@ -592,7 +633,12 @@ class _ProtoQuery extends TQuery {
|
|
|
592
633
|
result = this._objectMethods(await this._dispatcher(options).deleteOne(this._queryOptions));
|
|
593
634
|
}
|
|
594
635
|
if (result && _.isFunction(afterDelete)) {
|
|
595
|
-
|
|
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
|
+
}
|
|
596
642
|
}
|
|
597
643
|
return result;
|
|
598
644
|
}
|
|
@@ -613,7 +659,14 @@ class _ProtoQuery extends TQuery {
|
|
|
613
659
|
filter: { _id: { $in: _.map(objects, x => x.objectId) } },
|
|
614
660
|
});
|
|
615
661
|
if (_.isFunction(afterDelete)) {
|
|
616
|
-
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
|
+
}));
|
|
617
670
|
}
|
|
618
671
|
return objects.length;
|
|
619
672
|
}
|
|
@@ -2376,19 +2429,84 @@ var configRoute = (router, proto) => {
|
|
|
2376
2429
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
2377
2430
|
// THE SOFTWARE.
|
|
2378
2431
|
//
|
|
2432
|
+
/**
|
|
2433
|
+
* Schema definition utility functions.
|
|
2434
|
+
*/
|
|
2379
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
|
+
*/
|
|
2380
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
|
+
*/
|
|
2381
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
|
+
*/
|
|
2382
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
|
+
*/
|
|
2383
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
|
+
*/
|
|
2384
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
|
+
*/
|
|
2385
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
|
+
*/
|
|
2386
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
|
+
*/
|
|
2387
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
|
+
*/
|
|
2388
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
|
+
*/
|
|
2389
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
|
+
*/
|
|
2390
2503
|
relation: (target, foreignField) => ({ type: 'relation', target, foreignField }),
|
|
2391
2504
|
});
|
|
2505
|
+
/**
|
|
2506
|
+
* Creates a ProtoRoute.
|
|
2507
|
+
* @param options - The options for the ProtoRoute.
|
|
2508
|
+
* @returns A promise that resolves to a Router.
|
|
2509
|
+
*/
|
|
2392
2510
|
const ProtoRoute = async (options) => {
|
|
2393
2511
|
const proto = options.proto instanceof ProtoService ? options.proto : new ProtoService(options.proto);
|
|
2394
2512
|
await proto[PVK].prepare();
|
|
@@ -2411,6 +2529,13 @@ const ProtoRoute = async (options) => {
|
|
|
2411
2529
|
configRoute(router, proto);
|
|
2412
2530
|
return router;
|
|
2413
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
|
+
*/
|
|
2414
2539
|
const registerProtoSocket = (proto, server, endpoint) => {
|
|
2415
2540
|
const io = endpoint ? server.socket().of(endpoint) : server.socket();
|
|
2416
2541
|
io.on('connection', async (socket) => {
|