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.
Files changed (49) hide show
  1. package/dist/adapters/file/database.d.ts +2 -2
  2. package/dist/adapters/file/database.js +2 -2
  3. package/dist/adapters/file/database.mjs +2 -2
  4. package/dist/adapters/file/filesystem.d.ts +2 -2
  5. package/dist/adapters/file/google-cloud-storage.d.ts +2 -2
  6. package/dist/adapters/storage/progres.d.ts +9 -2
  7. package/dist/adapters/storage/progres.js +58 -5
  8. package/dist/adapters/storage/progres.js.map +1 -1
  9. package/dist/adapters/storage/progres.mjs +58 -5
  10. package/dist/adapters/storage/progres.mjs.map +1 -1
  11. package/dist/client.d.ts +3 -3
  12. package/dist/client.js +2 -2
  13. package/dist/client.mjs +3 -3
  14. package/dist/index.d.ts +75 -3
  15. package/dist/index.js +242 -12
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +243 -13
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/internals/{index-BYbMU-Ao.mjs → index--ifyu-GL.mjs} +139 -1
  20. package/dist/internals/index--ifyu-GL.mjs.map +1 -0
  21. package/dist/internals/{index-B1wqSio6.mjs → index-C3fbOqmn.mjs} +2 -2
  22. package/dist/internals/{index-B1wqSio6.mjs.map → index-C3fbOqmn.mjs.map} +1 -1
  23. package/dist/internals/index-CE5tdYK8.d.ts +1816 -0
  24. package/dist/internals/index-CE5tdYK8.d.ts.map +1 -0
  25. package/dist/internals/{index-K0jhERvZ.d.ts → index-CGX3qcjQ.d.ts} +2 -2
  26. package/dist/internals/index-CGX3qcjQ.d.ts.map +1 -0
  27. package/dist/internals/{index-CVutVPmd.js → index-DXuW8UiB.js} +139 -1
  28. package/dist/internals/index-DXuW8UiB.js.map +1 -0
  29. package/dist/internals/{index-CzfsyXvb.js → index-Dc3V_Bzw.js} +2 -2
  30. package/dist/internals/{index-CzfsyXvb.js.map → index-Dc3V_Bzw.js.map} +1 -1
  31. package/dist/internals/{index-D0hHgn2P.mjs → index-R0gbIGc-.mjs} +289 -2
  32. package/dist/internals/index-R0gbIGc-.mjs.map +1 -0
  33. package/dist/internals/{index-BJP46VGq.js → index-S_gTMQBh.js} +289 -2
  34. package/dist/internals/index-S_gTMQBh.js.map +1 -0
  35. package/dist/internals/{index-DchUjNEf.d.ts → index-uwXdnxqN.d.ts} +2 -2
  36. package/dist/internals/index-uwXdnxqN.d.ts.map +1 -0
  37. package/dist/internals/{random-BCpwYpyw.mjs → random-DPRG8oW6.mjs} +3 -3
  38. package/dist/internals/{random-BCpwYpyw.mjs.map → random-DPRG8oW6.mjs.map} +1 -1
  39. package/dist/internals/{random-Dytum6Nh.js → random-DVOUDDGg.js} +3 -3
  40. package/dist/internals/{random-Dytum6Nh.js.map → random-DVOUDDGg.js.map} +1 -1
  41. package/package.json +1 -1
  42. package/dist/internals/index-BJP46VGq.js.map +0 -1
  43. package/dist/internals/index-BYbMU-Ao.mjs.map +0 -1
  44. package/dist/internals/index-BhWRmBiq.d.ts +0 -726
  45. package/dist/internals/index-BhWRmBiq.d.ts.map +0 -1
  46. package/dist/internals/index-CVutVPmd.js.map +0 -1
  47. package/dist/internals/index-D0hHgn2P.mjs.map +0 -1
  48. package/dist/internals/index-DchUjNEf.d.ts.map +0 -1
  49. package/dist/internals/index-K0jhERvZ.d.ts.map +0 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-CVutVPmd.js');
3
+ var index = require('./index-DXuW8UiB.js');
4
4
  var _ = require('lodash');
5
5
  var Decimal = require('decimal.js');
6
6
  var utilsJs = require('@o2ter/utils-js');
@@ -47,9 +47,17 @@ const mergeOpts = (lhs, rhs) => {
47
47
  },
48
48
  };
49
49
  };
50
+ /**
51
+ * Base class for query filters.
52
+ */
50
53
  class TQueryFilterBase {
51
54
  /** @internal */
52
55
  [_private.PVK] = { options: {} };
56
+ /**
57
+ * Applies a filter to the query.
58
+ * @param filter - The filter to apply.
59
+ * @returns The current instance for chaining.
60
+ */
53
61
  filter(filter) {
54
62
  if (_.isNil(this[_private.PVK].options.filter)) {
55
63
  this[_private.PVK].options.filter = filter;
@@ -62,70 +70,193 @@ class TQueryFilterBase {
62
70
  }
63
71
  return this;
64
72
  }
73
+ /**
74
+ * Applies an equality filter to the query.
75
+ * @param key - The key to filter.
76
+ * @param value - The value to filter.
77
+ * @returns The current instance for chaining.
78
+ */
65
79
  equalTo(key, value) {
66
80
  return this.filter({ [key]: { $eq: value ?? null } });
67
81
  }
82
+ /**
83
+ * Applies a not equal filter to the query.
84
+ * @param key - The key to filter.
85
+ * @param value - The value to filter.
86
+ * @returns The current instance for chaining.
87
+ */
68
88
  notEqualTo(key, value) {
69
89
  return this.filter({ [key]: { $ne: value ?? null } });
70
90
  }
91
+ /**
92
+ * Applies a less than filter to the query.
93
+ * @param key - The key to filter.
94
+ * @param value - The value to filter.
95
+ * @returns The current instance for chaining.
96
+ */
71
97
  lessThan(key, value) {
72
98
  return this.filter({ [key]: { $lt: value ?? null } });
73
99
  }
100
+ /**
101
+ * Applies a greater than filter to the query.
102
+ * @param key - The key to filter.
103
+ * @param value - The value to filter.
104
+ * @returns The current instance for chaining.
105
+ */
74
106
  greaterThan(key, value) {
75
107
  return this.filter({ [key]: { $gt: value ?? null } });
76
108
  }
109
+ /**
110
+ * Applies a less than or equal to filter to the query.
111
+ * @param key - The key to filter.
112
+ * @param value - The value to filter.
113
+ * @returns The current instance for chaining.
114
+ */
77
115
  lessThanOrEqualTo(key, value) {
78
116
  return this.filter({ [key]: { $lte: value ?? null } });
79
117
  }
118
+ /**
119
+ * Applies a greater than or equal to filter to the query.
120
+ * @param key - The key to filter.
121
+ * @param value - The value to filter.
122
+ * @returns The current instance for chaining.
123
+ */
80
124
  greaterThanOrEqualTo(key, value) {
81
125
  return this.filter({ [key]: { $gte: value ?? null } });
82
126
  }
127
+ /**
128
+ * Applies a pattern filter to the query.
129
+ * @param key - The key to filter.
130
+ * @param value - The pattern to filter.
131
+ * @returns The current instance for chaining.
132
+ */
83
133
  pattern(key, value) {
84
134
  return this.filter({ [key]: { $pattern: value ?? null } });
85
135
  }
136
+ /**
137
+ * Applies a starts with filter to the query.
138
+ * @param key - The key to filter.
139
+ * @param value - The value to filter.
140
+ * @returns The current instance for chaining.
141
+ */
86
142
  startsWith(key, value) {
87
143
  return this.filter({ [key]: { $starts: value ?? null } });
88
144
  }
145
+ /**
146
+ * Applies an ends with filter to the query.
147
+ * @param key - The key to filter.
148
+ * @param value - The value to filter.
149
+ * @returns The current instance for chaining.
150
+ */
89
151
  endsWith(key, value) {
90
152
  return this.filter({ [key]: { $ends: value ?? null } });
91
153
  }
154
+ /**
155
+ * Applies a size filter to the query.
156
+ * @param key - The key to filter.
157
+ * @param value - The value to filter.
158
+ * @returns The current instance for chaining.
159
+ */
92
160
  size(key, value) {
93
161
  return this.filter({ [key]: { $size: value } });
94
162
  }
163
+ /**
164
+ * Applies an empty filter to the query.
165
+ * @param key - The key to filter.
166
+ * @returns The current instance for chaining.
167
+ */
95
168
  empty(key) {
96
169
  return this.filter({ [key]: { $empty: true } });
97
170
  }
171
+ /**
172
+ * Applies a not empty filter to the query.
173
+ * @param key - The key to filter.
174
+ * @returns The current instance for chaining.
175
+ */
98
176
  notEmpty(key) {
99
177
  return this.filter({ [key]: { $empty: false } });
100
178
  }
179
+ /**
180
+ * Filters the query to include only documents where the specified key contains any of the specified values.
181
+ * @param key - The key to check for values.
182
+ * @param value - The array of values to check for.
183
+ * @returns The current instance for chaining.
184
+ */
101
185
  containsIn(key, value) {
102
186
  return this.filter({ [key]: { $in: value } });
103
187
  }
188
+ /**
189
+ * Filters the query to exclude documents where the specified key contains any of the specified values.
190
+ * @param key - The key to check for values.
191
+ * @param value - The array of values to exclude.
192
+ * @returns The current instance for chaining.
193
+ */
104
194
  notContainsIn(key, value) {
105
195
  return this.filter({ [key]: { $nin: value } });
106
196
  }
197
+ /**
198
+ * Filters the query to include only documents where the specified key is a subset of the specified values.
199
+ * @param key - The key to check for subset.
200
+ * @param value - The array of values to check against.
201
+ * @returns The current instance for chaining.
202
+ */
107
203
  isSubset(key, value) {
108
204
  return this.filter({ [key]: { $subset: value } });
109
205
  }
206
+ /**
207
+ * Filters the query to include only documents where the specified key is a superset of the specified values.
208
+ * @param key - The key to check for superset.
209
+ * @param value - The array of values to check against.
210
+ * @returns The current instance for chaining.
211
+ */
110
212
  isSuperset(key, value) {
111
213
  return this.filter({ [key]: { $superset: value } });
112
214
  }
215
+ /**
216
+ * Filters the query to include only documents where the specified key is disjoint from the specified values.
217
+ * @param key - The key to check for disjoint.
218
+ * @param value - The array of values to check against.
219
+ * @returns The current instance for chaining.
220
+ */
113
221
  isDisjoint(key, value) {
114
222
  return this.filter({ [key]: { $not: { $intersect: value } } });
115
223
  }
224
+ /**
225
+ * Filters the query to include only documents where the specified key intersects with the specified values.
226
+ * @param key - The key to check for intersection.
227
+ * @param value - The array of values to check against.
228
+ * @returns The current instance for chaining.
229
+ */
116
230
  isIntersect(key, value) {
117
231
  return this.filter({ [key]: { $intersect: value } });
118
232
  }
233
+ /**
234
+ * Filters the query to include only documents where every element of the specified key matches the provided callback query.
235
+ * @param key - The key to check for every element.
236
+ * @param callback - The callback query to apply to each element.
237
+ * @returns The current instance for chaining.
238
+ */
119
239
  every(key, callback) {
120
240
  const query = new TQueryFilterBase();
121
241
  callback(query);
122
242
  return this.filter({ [key]: { $every: { $and: _.castArray(query[_private.PVK].options.filter) } } });
123
243
  }
244
+ /**
245
+ * Filters the query to include only documents where some elements of the specified key match the provided callback query.
246
+ * @param key - The key to check for some elements.
247
+ * @param callback - The callback query to apply to each element.
248
+ * @returns The current instance for chaining.
249
+ */
124
250
  some(key, callback) {
125
251
  const query = new TQueryFilterBase();
126
252
  callback(query);
127
253
  return this.filter({ [key]: { $some: { $and: _.castArray(query[_private.PVK].options.filter) } } });
128
254
  }
255
+ /**
256
+ * Filters the query to include only documents that match all of the provided callback queries.
257
+ * @param callbacks - The callback queries to apply.
258
+ * @returns The current instance for chaining.
259
+ */
129
260
  and(...callbacks) {
130
261
  return this.filter({
131
262
  $and: _.flatMap(_.flatten(callbacks), callback => {
@@ -135,6 +266,11 @@ class TQueryFilterBase {
135
266
  }),
136
267
  });
137
268
  }
269
+ /**
270
+ * Filters the query to include only documents that match any of the provided callback queries.
271
+ * @param callbacks - The callback queries to apply.
272
+ * @returns The current instance for chaining.
273
+ */
138
274
  or(...callbacks) {
139
275
  return this.filter({
140
276
  $or: _.map(_.flatten(callbacks), callback => {
@@ -146,6 +282,11 @@ class TQueryFilterBase {
146
282
  }),
147
283
  });
148
284
  }
285
+ /**
286
+ * Filters the query to include only documents that do not match any of the provided callback queries.
287
+ * @param callbacks - The callback queries to apply.
288
+ * @returns The current instance for chaining.
289
+ */
149
290
  nor(...callbacks) {
150
291
  return this.filter({
151
292
  $nor: _.map(_.flatten(callbacks), callback => {
@@ -161,22 +302,43 @@ class TQueryFilterBase {
161
302
  class TQueryBase extends TQueryFilterBase {
162
303
  /** @internal */
163
304
  [_private.PVK] = { options: {} };
305
+ /**
306
+ * Sorts the query results.
307
+ * @param sort - The sorting criteria.
308
+ * @returns The current instance for chaining.
309
+ */
164
310
  sort(sort) {
165
311
  this[_private.PVK].options.sort = sort;
166
312
  return this;
167
313
  }
314
+ /**
315
+ * Skips the specified number of results.
316
+ * @param skip - The number of results to skip.
317
+ * @returns The current instance for chaining.
318
+ */
168
319
  skip(skip) {
169
320
  if (!_.isSafeInteger(skip) || skip < 0)
170
321
  throw Error('Invalid skip number');
171
322
  this[_private.PVK].options.skip = skip;
172
323
  return this;
173
324
  }
325
+ /**
326
+ * Limits the number of results.
327
+ * @param limit - The maximum number of results to return.
328
+ * @returns The current instance for chaining.
329
+ */
174
330
  limit(limit) {
175
331
  if (!_.isSafeInteger(limit) || limit < 0)
176
332
  throw Error('Invalid limit number');
177
333
  this[_private.PVK].options.limit = limit;
178
334
  return this;
179
335
  }
336
+ /**
337
+ * Performs a nested query on a specific key.
338
+ * @param key - The key to match.
339
+ * @param callback - The callback function to execute.
340
+ * @returns The current instance for chaining.
341
+ */
180
342
  match(key, callback) {
181
343
  const query = new TQueryBase();
182
344
  callback(query);
@@ -219,27 +381,62 @@ class TQueryBase extends TQueryFilterBase {
219
381
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
220
382
  // THE SOFTWARE.
221
383
  //
384
+ /**
385
+ * Abstract base class for queries.
386
+ */
222
387
  class TQuery extends TQueryBase {
223
388
  /** @internal */
224
389
  [_private.PVK] = { options: {} };
390
+ /**
391
+ * Adds fields to include in the query.
392
+ * @param includes - The fields to include.
393
+ * @returns The query instance.
394
+ */
225
395
  includes(...includes) {
226
396
  this[_private.PVK].options.includes = this[_private.PVK].options.includes ? [...this[_private.PVK].options.includes, ...includes] : includes;
227
397
  return this;
228
398
  }
399
+ /**
400
+ * Gets a record by its ID.
401
+ * @param id - The ID of the record.
402
+ * @param options - Extra options for the query.
403
+ * @returns A promise that resolves to the record or undefined.
404
+ */
229
405
  async get(id, options) {
230
406
  return _.first(await this.clone().equalTo('_id', id).limit(1).find(options));
231
407
  }
408
+ /**
409
+ * Gets the first record.
410
+ * @param options - Extra options for the query.
411
+ * @returns A promise that resolves to the first record or undefined.
412
+ */
232
413
  async first(options) {
233
414
  return _.first(await this.clone().limit(1).find(options));
234
415
  }
416
+ /**
417
+ * Gets a random record.
418
+ * @param opts - Options for the random selection.
419
+ * @param options - Extra options for the query.
420
+ * @returns A promise that resolves to the random record or undefined.
421
+ */
235
422
  async randomOne(opts, options) {
236
423
  return _.first(await this.clone().limit(1).random(opts, options));
237
424
  }
425
+ /**
426
+ * Checks if any records exist.
427
+ * @param options - Extra options for the query.
428
+ * @returns A promise that resolves to a boolean indicating if any records exist.
429
+ */
238
430
  async exists(options) {
239
431
  const query = this.clone();
240
432
  this[_private.PVK].options.includes = [];
241
433
  return !_.isNil(await query.limit(1).find(options));
242
434
  }
435
+ /**
436
+ * Iterates over each batch of records.
437
+ * @param callback - The callback to execute for each batch.
438
+ * @param options - Extra options for the query.
439
+ */
243
440
  async eachBatch(callback, options) {
244
441
  const sorting = this[_private.PVK].options.sort ?? {};
245
442
  const batchSize = options?.batchSize ?? 100;
@@ -255,6 +452,7 @@ class TQuery extends TQueryBase {
255
452
  const keys = _.keys(sorting);
256
453
  let batch = [];
257
454
  while (true) {
455
+ options?.abortSignal?.throwIfAborted();
258
456
  const q = _.isEmpty(batch) ? query : query.clone()
259
457
  .filter(keys.length > 1 ? {
260
458
  $expr: {
@@ -272,6 +470,11 @@ class TQuery extends TQueryBase {
272
470
  await callback(batch);
273
471
  }
274
472
  }
473
+ /**
474
+ * Iterates over each record.
475
+ * @param callback - The callback to execute for each record.
476
+ * @param options - Extra options for the query.
477
+ */
275
478
  async each(callback, options) {
276
479
  await this.eachBatch(async (batch) => {
277
480
  for (const object of batch) {
@@ -364,22 +567,46 @@ class TUser extends index.TObject {
364
567
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
365
568
  // THE SOFTWARE.
366
569
  //
570
+ /**
571
+ * Class representing a Role.
572
+ * @extends TObject
573
+ */
367
574
  class TRole extends index.TObject {
368
575
  constructor(attributes) {
369
576
  super('Role', attributes);
370
577
  }
578
+ /**
579
+ * Get the name of the role.
580
+ * @return {string | undefined} The name of the role.
581
+ */
371
582
  get name() {
372
583
  return this.get('name');
373
584
  }
585
+ /**
586
+ * Get the users associated with the role.
587
+ * @return {TUser[]} The users associated with the role.
588
+ */
374
589
  get users() {
375
590
  return this.get('users') ?? [];
376
591
  }
592
+ /**
593
+ * Set the users associated with the role.
594
+ * @param {TUser[]} value - The users to associate with the role.
595
+ */
377
596
  set users(value) {
378
597
  this.set('users', value);
379
598
  }
599
+ /**
600
+ * Get the roles associated with the role.
601
+ * @return {TRole[]} The roles associated with the role.
602
+ */
380
603
  get roles() {
381
604
  return this.get('roles') ?? [];
382
605
  }
606
+ /**
607
+ * Set the roles associated with the role.
608
+ * @param {TRole[]} value - The roles to associate with the role.
609
+ */
383
610
  set roles(value) {
384
611
  this.set('roles', value);
385
612
  }
@@ -409,19 +636,38 @@ class TRole extends index.TObject {
409
636
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
410
637
  // THE SOFTWARE.
411
638
  //
639
+ /**
640
+ * Class representing a file.
641
+ */
412
642
  class TFile extends index.TObject {
413
643
  constructor(attributes) {
414
644
  super('File', attributes);
415
645
  }
646
+ /**
647
+ * Gets the filename of the file.
648
+ * @returns The filename.
649
+ */
416
650
  get filename() {
417
651
  return this.get('filename');
418
652
  }
653
+ /**
654
+ * Gets the size of the file.
655
+ * @returns The size of the file.
656
+ */
419
657
  get size() {
420
658
  return this.get('size');
421
659
  }
660
+ /**
661
+ * Gets the type of the file.
662
+ * @returns The type of the file.
663
+ */
422
664
  get type() {
423
665
  return this.get('type');
424
666
  }
667
+ /**
668
+ * Gets the token of the file.
669
+ * @returns The token of the file.
670
+ */
425
671
  get token() {
426
672
  return this.get('token');
427
673
  }
@@ -655,6 +901,10 @@ const applyObjectMethods = (object, proto) => {
655
901
  // THE SOFTWARE.
656
902
  //
657
903
  class ProtoType {
904
+ /**
905
+ * Checks if the server is online.
906
+ * @returns A promise that resolves to a boolean indicating if the server is online.
907
+ */
658
908
  async online() {
659
909
  try {
660
910
  const res = await axios({
@@ -668,14 +918,32 @@ class ProtoType {
668
918
  return false;
669
919
  }
670
920
  }
921
+ /**
922
+ * Rebinds an object to the proto instance.
923
+ * @param object - The object to rebind.
924
+ * @returns The rebinded object.
925
+ */
671
926
  rebind(object) {
672
927
  return applyObjectMethods(object, this);
673
928
  }
929
+ /**
930
+ * Creates a new object.
931
+ * @param className - The name of the class to create.
932
+ * @param objectId - The ID of the object to create.
933
+ * @returns The created object.
934
+ */
674
935
  Object(className, objectId) {
675
936
  const attrs = objectId ? { _id: objectId } : {};
676
937
  const obj = isObjKey(className, TObjectTypes) ? new TObjectTypes[className](attrs) : new index.TObject(className, attrs);
677
938
  return this.rebind(obj);
678
939
  }
940
+ /**
941
+ * Creates a new file object.
942
+ * @param filename - The name of the file.
943
+ * @param data - The file data.
944
+ * @param type - The type of the file.
945
+ * @returns The created file object.
946
+ */
679
947
  File(filename, data, type) {
680
948
  const file = this.Object('File');
681
949
  file.set('filename', filename);
@@ -930,6 +1198,15 @@ class _ProtoClientQuery extends TQuery {
930
1198
  ...this._queryOptions,
931
1199
  }, this._requestOpt(options));
932
1200
  }
1201
+ updateMany(update, options) {
1202
+ return this._proto[_private.PVK].request(this._proto, {
1203
+ operation: 'updateMany',
1204
+ context: options?.context ?? {},
1205
+ silent: options?.silent,
1206
+ update,
1207
+ ...this._queryOptions,
1208
+ }, this._requestOpt(options));
1209
+ }
933
1210
  upsertOne(update, setOnInsert, options) {
934
1211
  return this._proto[_private.PVK].request(this._proto, {
935
1212
  operation: 'upsertOne',
@@ -940,6 +1217,16 @@ class _ProtoClientQuery extends TQuery {
940
1217
  ...this._queryOptions,
941
1218
  }, this._requestOpt(options));
942
1219
  }
1220
+ upsertMany(update, setOnInsert, options) {
1221
+ return this._proto[_private.PVK].request(this._proto, {
1222
+ operation: 'upsertMany',
1223
+ context: options?.context ?? {},
1224
+ silent: options?.silent,
1225
+ update,
1226
+ setOnInsert,
1227
+ ...this._queryOptions,
1228
+ }, this._requestOpt(options));
1229
+ }
943
1230
  deleteOne(options) {
944
1231
  return this._proto[_private.PVK].request(this._proto, {
945
1232
  operation: 'deleteOne',
@@ -1528,4 +1815,4 @@ exports.isQuery = isQuery;
1528
1815
  exports.isRole = isRole;
1529
1816
  exports.isUser = isUser;
1530
1817
  exports.serialize = serialize;
1531
- //# sourceMappingURL=index-BJP46VGq.js.map
1818
+ //# sourceMappingURL=index-S_gTMQBh.js.map