proto.io 0.0.206 → 0.0.207

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 (54) hide show
  1. package/dist/adapters/file/aliyun-oss.d.ts +3 -3
  2. package/dist/adapters/file/database.d.ts +2 -2
  3. package/dist/adapters/file/database.js +3 -3
  4. package/dist/adapters/file/database.js.map +1 -1
  5. package/dist/adapters/file/database.mjs +3 -3
  6. package/dist/adapters/file/database.mjs.map +1 -1
  7. package/dist/adapters/file/filesystem.d.ts +3 -3
  8. package/dist/adapters/file/google-cloud-storage.d.ts +3 -3
  9. package/dist/adapters/storage/progres.d.ts +9 -17
  10. package/dist/adapters/storage/progres.js +24 -101
  11. package/dist/adapters/storage/progres.js.map +1 -1
  12. package/dist/adapters/storage/progres.mjs +24 -101
  13. package/dist/adapters/storage/progres.mjs.map +1 -1
  14. package/dist/client.d.ts +3 -3
  15. package/dist/client.js +2 -2
  16. package/dist/client.mjs +3 -3
  17. package/dist/index.d.ts +3 -3
  18. package/dist/index.js +24 -107
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.mjs +25 -108
  21. package/dist/index.mjs.map +1 -1
  22. package/dist/internals/{base-Be7PFKEC.d.ts → base-DHkvlTFy.d.ts} +2 -2
  23. package/dist/internals/base-DHkvlTFy.d.ts.map +1 -0
  24. package/dist/internals/{chunk-CEQtSsWb.d.ts → chunk-C7kDLOLD.d.ts} +3 -3
  25. package/dist/internals/chunk-C7kDLOLD.d.ts.map +1 -0
  26. package/dist/internals/{index-CsmAYB_t.js → index-B8TESzd9.js} +1 -2
  27. package/dist/internals/{index-CsmAYB_t.js.map → index-B8TESzd9.js.map} +1 -1
  28. package/dist/internals/{index-BFZlY3IO.js → index-BRzKDwPs.js} +44 -2
  29. package/dist/internals/index-BRzKDwPs.js.map +1 -0
  30. package/dist/internals/{index-CURcwPBG.d.ts → index-CKcESGqE.d.ts} +2 -2
  31. package/dist/internals/index-CKcESGqE.d.ts.map +1 -0
  32. package/dist/internals/{index-CyPxh5dl.js → index-CkAvNaAe.js} +2 -2
  33. package/dist/internals/{index-CyPxh5dl.js.map → index-CkAvNaAe.js.map} +1 -1
  34. package/dist/internals/{index-CSnRU_KQ.mjs → index-DAkcqabS.mjs} +44 -2
  35. package/dist/internals/index-DAkcqabS.mjs.map +1 -0
  36. package/dist/internals/{index-iRVgw566.mjs → index-DlY33lfO.mjs} +2 -2
  37. package/dist/internals/{index-iRVgw566.mjs.map → index-DlY33lfO.mjs.map} +1 -1
  38. package/dist/internals/{index-DnbbpIaO.d.ts → index-PLz89AWF.d.ts} +14 -19
  39. package/dist/internals/index-PLz89AWF.d.ts.map +1 -0
  40. package/dist/internals/{index-DpN9tcbY.mjs → index-al1N-qi7.mjs} +2 -2
  41. package/dist/internals/{index-DpN9tcbY.mjs.map → index-al1N-qi7.mjs.map} +1 -1
  42. package/dist/internals/{random-D7S1XD7F.js → random-B0V0EnjP.js} +3 -3
  43. package/dist/internals/random-B0V0EnjP.js.map +1 -0
  44. package/dist/internals/{random-BnGB_bVS.mjs → random-ZgzzM5v_.mjs} +3 -3
  45. package/dist/internals/random-ZgzzM5v_.mjs.map +1 -0
  46. package/package.json +1 -1
  47. package/dist/internals/base-Be7PFKEC.d.ts.map +0 -1
  48. package/dist/internals/chunk-CEQtSsWb.d.ts.map +0 -1
  49. package/dist/internals/index-BFZlY3IO.js.map +0 -1
  50. package/dist/internals/index-CSnRU_KQ.mjs.map +0 -1
  51. package/dist/internals/index-CURcwPBG.d.ts.map +0 -1
  52. package/dist/internals/index-DnbbpIaO.d.ts.map +0 -1
  53. package/dist/internals/random-BnGB_bVS.mjs.map +0 -1
  54. package/dist/internals/random-D7S1XD7F.js.map +0 -1
package/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { P as ProtoClient } from './internals/index-CURcwPBG.js';
2
- export { c as classExtends, e as isFile, f as isJob, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-CURcwPBG.js';
1
+ import { P as ProtoClient } from './internals/index-CKcESGqE.js';
2
+ export { c as classExtends, e as isFile, f as isJob, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-CKcESGqE.js';
3
3
  export { Decimal } from 'decimal.js';
4
- export { D as DeserializeOptions, S as SerializeOptions, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-DnbbpIaO.js';
4
+ export { D as DeserializeOptions, S as SerializeOptions, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-PLz89AWF.js';
5
5
  import '@o2ter/utils-js';
6
6
  import 'socket.io-client';
7
7
  import '@socket.io/component-emitter';
package/dist/client.js CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./internals/index-BFZlY3IO.js');
5
+ var index = require('./internals/index-BRzKDwPs.js');
6
6
  var Decimal = require('decimal.js');
7
7
  require('@o2ter/utils-js');
8
8
  require('./internals/private-Ciddhure.js');
9
9
  require('lodash');
10
- require('./internals/index-CsmAYB_t.js');
10
+ require('./internals/index-B8TESzd9.js');
11
11
  require('axios');
12
12
  require('@o2ter/server-js/dist/const');
13
13
  require('socket.io-client');
package/dist/client.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { e as ProtoClient } from './internals/index-CSnRU_KQ.mjs';
2
- export { f as classExtends, d as deserialize, k as isFile, l as isJob, g as isObject, i as isQuery, j as isRole, h as isUser, s as serialize } from './internals/index-CSnRU_KQ.mjs';
1
+ import { e as ProtoClient } from './internals/index-DAkcqabS.mjs';
2
+ export { f as classExtends, d as deserialize, k as isFile, l as isJob, g as isObject, i as isQuery, j as isRole, h as isUser, s as serialize } from './internals/index-DAkcqabS.mjs';
3
3
  export { Decimal } from 'decimal.js';
4
4
  import '@o2ter/utils-js';
5
5
  import './internals/private-CNw40LZ7.mjs';
6
6
  import 'lodash';
7
- import './internals/index-DpN9tcbY.mjs';
7
+ import './internals/index-al1N-qi7.mjs';
8
8
  import 'axios';
9
9
  import '@o2ter/server-js/dist/const';
10
10
  import 'socket.io-client';
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as socket_io from 'socket.io';
2
2
  import { Router } from 'express';
3
3
  import { Server } from '@o2ter/server-js';
4
- import { T as TSchema, a as TValueWithoutObject, P as ProtoService, b as ProtoServiceOptions, c as ProtoServiceKeyOptions } from './internals/index-DnbbpIaO.js';
5
- export { D as DeserializeOptions, S as SerializeOptions, d as TFileStorage, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-DnbbpIaO.js';
4
+ import { T as TSchema, a as TValueWithoutObject, P as ProtoService, b as ProtoServiceOptions, c as ProtoServiceKeyOptions } from './internals/index-PLz89AWF.js';
5
+ export { D as DeserializeOptions, S as SerializeOptions, d as TFileStorage, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-PLz89AWF.js';
6
6
  import Decimal from 'decimal.js';
7
7
  export { Decimal } from 'decimal.js';
8
- export { P as ProtoClient, c as classExtends, e as isFile, f as isJob, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-CURcwPBG.js';
8
+ export { P as ProtoClient, c as classExtends, e as isFile, f as isJob, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-CKcESGqE.js';
9
9
  import '@o2ter/utils-js';
10
10
  import 'jsonwebtoken';
11
11
  import 'lodash';
package/dist/index.js CHANGED
@@ -4,11 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _ = require('lodash');
6
6
  var serverJs = require('@o2ter/server-js');
7
- var random = require('./internals/random-D7S1XD7F.js');
7
+ var random = require('./internals/random-B0V0EnjP.js');
8
8
  var _private = require('./internals/private-Ciddhure.js');
9
9
  var utilsJs = require('@o2ter/utils-js');
10
- var index = require('./internals/index-BFZlY3IO.js');
11
- var index$1 = require('./internals/index-CsmAYB_t.js');
10
+ var index = require('./internals/index-BRzKDwPs.js');
11
+ var index$1 = require('./internals/index-B8TESzd9.js');
12
12
  var jwt = require('jsonwebtoken');
13
13
  var node_buffer = require('node:buffer');
14
14
  var node_stream = require('node:stream');
@@ -16,7 +16,7 @@ var node_crypto = require('node:crypto');
16
16
  var util = require('util');
17
17
  var cryptoJs = require('@o2ter/crypto-js');
18
18
  var Decimal = require('decimal.js');
19
- var index$2 = require('./internals/index-CyPxh5dl.js');
19
+ var index$2 = require('./internals/index-CkAvNaAe.js');
20
20
  var queryType = require('query-types');
21
21
  var busboy = require('busboy');
22
22
  require('axios');
@@ -88,6 +88,7 @@ const dispatcher = (proto, options) => {
88
88
  master: options.master ?? false,
89
89
  disableSecurity: options.disableSecurity,
90
90
  });
91
+ const createFile = options.createFile;
91
92
  return {
92
93
  async explain(query) {
93
94
  random.QueryValidator.recursiveCheck(query);
@@ -134,35 +135,9 @@ const dispatcher = (proto, options) => {
134
135
  throw Error('No permission');
135
136
  return proto.storage.random(decoded, opts);
136
137
  },
137
- async insert(options, attrs) {
138
- random.QueryValidator.recursiveCheck(attrs);
139
- const _validator = await validator();
140
- _validator.validateCountMatches(options.className, options.countMatches ?? []);
141
- const _includes = _validator.decodeIncludes(options.className, options.includes ?? ['*']);
142
- const _matches = _validator.decodeMatches(options.className, options.matches ?? {}, _includes);
143
- if (!_validator.validateCLPs(options.className, 'create'))
144
- throw Error('No permission');
145
- const _attrs = normalize(_validator.validateFields(options.className, attrs, 'create', random.QueryValidator.patterns.path));
146
- while (true) {
147
- try {
148
- return await proto.storage.atomic((storage) => storage.insert({
149
- className: options.className,
150
- includes: _includes,
151
- matches: _matches,
152
- countMatches: options.countMatches ?? [],
153
- objectIdSize: proto[_private.PVK].options.objectIdSize
154
- }, _attrs), { lockTable: options.className, retry: true });
155
- }
156
- catch (e) {
157
- if (proto.storage.isDuplicateIdError(e))
158
- continue;
159
- throw e;
160
- }
161
- }
162
- },
163
- async insertMany(options, values) {
164
- if (options.className === 'File')
165
- throw Error('File is not support insertMany');
138
+ async insert(options, values) {
139
+ if (!createFile && options.className === 'File')
140
+ throw Error('File is not support insert');
166
141
  random.QueryValidator.recursiveCheck(values);
167
142
  const _validator = await validator();
168
143
  _validator.validateCountMatches(options.className, options.countMatches ?? []);
@@ -173,7 +148,7 @@ const dispatcher = (proto, options) => {
173
148
  const _attrs = normalize(_.map(values, attr => _validator.validateFields(options.className, attr, 'create', random.QueryValidator.patterns.path)));
174
149
  while (true) {
175
150
  try {
176
- return await proto.storage.atomic((storage) => storage.insertMany({
151
+ return await proto.storage.atomic((storage) => storage.insert({
177
152
  className: options.className,
178
153
  includes: _includes,
179
154
  matches: _matches,
@@ -188,44 +163,16 @@ const dispatcher = (proto, options) => {
188
163
  }
189
164
  }
190
165
  },
191
- async updateOne(query, update) {
166
+ async update(query, update) {
192
167
  random.QueryValidator.recursiveCheck(query, update);
193
168
  const _validator = await validator();
194
169
  if (!_validator.validateCLPs(query.className, 'update'))
195
170
  throw Error('No permission');
196
- return proto.storage.atomic((storage) => storage.updateOne(_validator.decodeQuery(normalize(query), 'update'), normalize(_validator.validateFields(query.className, update, 'update', random.QueryValidator.patterns.path))));
197
- },
198
- async updateMany(query, update) {
199
- random.QueryValidator.recursiveCheck(query, update);
200
- const _validator = await validator();
201
- if (!_validator.validateCLPs(query.className, 'update'))
202
- throw Error('No permission');
203
- return proto.storage.atomic((storage) => storage.updateMany(_validator.decodeQuery(normalize(query), 'update'), normalize(_validator.validateFields(query.className, update, 'update', random.QueryValidator.patterns.path))));
204
- },
205
- async upsertOne(query, update, setOnInsert) {
206
- if (query.className === 'File')
207
- throw Error('File is not support upsertOne');
208
- random.QueryValidator.recursiveCheck(query, update, setOnInsert);
209
- const _validator = await validator();
210
- if (!_validator.validateCLPs(query.className, 'create', 'update'))
211
- throw Error('No permission');
212
- const _query = _validator.decodeQuery(normalize(query), 'update');
213
- const _update = normalize(_validator.validateFields(query.className, update, 'update', random.QueryValidator.patterns.path));
214
- const _setOnInsert = normalize(_validator.validateFields(query.className, setOnInsert, 'create', random.QueryValidator.patterns.path));
215
- while (true) {
216
- try {
217
- return await proto.storage.atomic((storage) => storage.upsertOne(_query, _update, _setOnInsert), { lockTable: query.className, retry: true });
218
- }
219
- catch (e) {
220
- if (proto.storage.isDuplicateIdError(e))
221
- continue;
222
- throw e;
223
- }
224
- }
171
+ return proto.storage.atomic((storage) => storage.update(_validator.decodeQuery(normalize(query), 'update'), normalize(_validator.validateFields(query.className, update, 'update', random.QueryValidator.patterns.path))));
225
172
  },
226
- async upsertMany(query, update, setOnInsert) {
173
+ async upsert(query, update, setOnInsert) {
227
174
  if (query.className === 'File')
228
- throw Error('File is not support upsertOne');
175
+ throw Error('File is not support upsert');
229
176
  random.QueryValidator.recursiveCheck(query, update, setOnInsert);
230
177
  const _validator = await validator();
231
178
  if (!_validator.validateCLPs(query.className, 'create', 'update'))
@@ -235,7 +182,7 @@ const dispatcher = (proto, options) => {
235
182
  const _setOnInsert = normalize(_validator.validateFields(query.className, setOnInsert, 'create', random.QueryValidator.patterns.path));
236
183
  while (true) {
237
184
  try {
238
- return await proto.storage.atomic((storage) => storage.upsertMany(_query, _update, _setOnInsert), { lockTable: query.className, retry: true });
185
+ return await proto.storage.atomic((storage) => storage.upsert(_query, _update, _setOnInsert), { lockTable: query.className, retry: true });
239
186
  }
240
187
  catch (e) {
241
188
  if (proto.storage.isDuplicateIdError(e))
@@ -244,19 +191,12 @@ const dispatcher = (proto, options) => {
244
191
  }
245
192
  }
246
193
  },
247
- async deleteOne(query) {
248
- random.QueryValidator.recursiveCheck(query);
249
- const _validator = await validator();
250
- if (!_validator.validateCLPs(query.className, 'delete'))
251
- throw Error('No permission');
252
- return proto.storage.atomic((storage) => storage.deleteOne(_validator.decodeQuery(normalize(query), 'update')));
253
- },
254
- async deleteMany(query) {
194
+ async delete(query) {
255
195
  random.QueryValidator.recursiveCheck(query);
256
196
  const _validator = await validator();
257
197
  if (!_validator.validateCLPs(query.className, 'delete'))
258
198
  throw Error('No permission');
259
- return proto.storage.atomic((storage) => storage.deleteMany(_validator.decodeQuery(normalize(query), 'update')));
199
+ return proto.storage.atomic((storage) => storage.delete(_validator.decodeQuery(normalize(query), 'update')));
260
200
  },
261
201
  };
262
202
  };
@@ -311,6 +251,7 @@ class _ProtoQuery extends index.TQuery {
311
251
  return dispatcher(_serviceOf(options) ?? this._proto, {
312
252
  ...options ?? {},
313
253
  disableSecurity: !!this._opts.insecure,
254
+ createFile: !!this._opts.createFile,
314
255
  });
315
256
  }
316
257
  explain(options) {
@@ -346,45 +287,22 @@ class _ProtoQuery extends index.TQuery {
346
287
  yield self._objectMethods(object);
347
288
  });
348
289
  }
349
- async insert(attrs, options) {
350
- const result = this._objectMethods(await this._dispatcher(options).insert({
351
- className: this.className,
352
- includes: this[_private.PVK].options.includes,
353
- matches: this[_private.PVK].options.matches,
354
- countMatches: this[_private.PVK].options.countMatches,
355
- }, attrs));
356
- if (!result)
357
- throw Error('Unable to insert document');
358
- return result;
359
- }
360
290
  async insertMany(values, options) {
361
- return this._objectMethods(await this._dispatcher(options).insertMany({
291
+ return this._objectMethods(await this._dispatcher(options).insert({
362
292
  className: this.className,
363
293
  includes: this[_private.PVK].options.includes,
364
294
  matches: this[_private.PVK].options.matches,
365
295
  countMatches: this[_private.PVK].options.countMatches,
366
296
  }, values));
367
297
  }
368
- async updateOne(update, options) {
369
- return this._objectMethods(await this._dispatcher(options).updateOne(this._queryOptions, update));
370
- }
371
298
  async updateMany(update, options) {
372
- return this._objectMethods(await this._dispatcher(options).updateMany(this._queryOptions, update));
373
- }
374
- async upsertOne(update, setOnInsert, options) {
375
- const result = this._objectMethods(await this._dispatcher(options).upsertOne(this._queryOptions, update, setOnInsert));
376
- if (!result)
377
- throw Error('Unable to upsert document');
378
- return result;
299
+ return this._objectMethods(await this._dispatcher(options).update(this._queryOptions, update));
379
300
  }
380
301
  async upsertMany(update, setOnInsert, options) {
381
- return this._objectMethods(await this._dispatcher(options).upsertMany(this._queryOptions, update, setOnInsert));
382
- }
383
- async deleteOne(options) {
384
- return this._objectMethods(await this._dispatcher(options).deleteOne(this._queryOptions));
302
+ return this._objectMethods(await this._dispatcher(options).upsert(this._queryOptions, update, setOnInsert));
385
303
  }
386
304
  async deleteMany(options) {
387
- return this._objectMethods(await this._dispatcher(options).deleteMany(this._queryOptions));
305
+ return this._objectMethods(await this._dispatcher(options).delete(this._queryOptions));
388
306
  }
389
307
  }
390
308
  class ProtoQuery extends _ProtoQuery {
@@ -961,9 +879,8 @@ class ProtoInternal {
961
879
  object.set('size', file.size);
962
880
  if (nonce)
963
881
  object.set('nonce', nonce);
964
- const created = await proto.Query('File')
965
- .includes(...object.keys())
966
- .insert(_.fromPairs([...object._set_entries()]), options);
882
+ const query = new ProtoQuery('File', proto, { createFile: true });
883
+ const created = await query.includes(...object.keys()).insert(_.fromPairs([...object._set_entries()]), options);
967
884
  if (created) {
968
885
  object[_private.PVK].attributes = created.attributes;
969
886
  object[_private.PVK].mutated = {};
@@ -1679,7 +1596,7 @@ class ProtoService extends index.ProtoType {
1679
1596
  await this.fileStorage.destroy(this, token);
1680
1597
  }
1681
1598
  }
1682
- await this.storage.deleteMany({
1599
+ await this.storage.delete({
1683
1600
  className,
1684
1601
  filter: index$2.QuerySelector.decode({ _expired_at: { $lt: time } }),
1685
1602
  includes: ['_id', '_expired_at'],