proto.io 0.0.225 → 0.0.227

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 (28) 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/filesystem.d.ts +3 -3
  4. package/dist/adapters/file/google-cloud-storage.d.ts +3 -3
  5. package/dist/adapters/storage/{progres.d.ts → postgres.d.ts} +2 -2
  6. package/dist/adapters/storage/postgres.d.ts.map +1 -0
  7. package/dist/adapters/storage/{progres.js → postgres.js} +1 -1
  8. package/dist/adapters/storage/postgres.js.map +1 -0
  9. package/dist/adapters/storage/{progres.mjs → postgres.mjs} +1 -1
  10. package/dist/adapters/storage/postgres.mjs.map +1 -0
  11. package/dist/client.d.ts +3 -3
  12. package/dist/index.d.ts +3 -3
  13. package/dist/index.js +42 -14
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +42 -14
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/internals/{base-DPYj2_4S.d.ts → base-DSo02iAX.d.ts} +2 -2
  18. package/dist/internals/{base-DPYj2_4S.d.ts.map → base-DSo02iAX.d.ts.map} +1 -1
  19. package/dist/internals/{chunk-B9XHpR52.d.ts → chunk-BhwfdCdq.d.ts} +3 -3
  20. package/dist/internals/{chunk-B9XHpR52.d.ts.map → chunk-BhwfdCdq.d.ts.map} +1 -1
  21. package/dist/internals/{index-Bi9H_aYC.d.ts → index-1ZK5N4yb.d.ts} +2 -2
  22. package/dist/internals/{index-Bi9H_aYC.d.ts.map → index-1ZK5N4yb.d.ts.map} +1 -1
  23. package/dist/internals/{index-y_bUWp3C.d.ts → index-Cj45GkKv.d.ts} +2 -2
  24. package/dist/internals/{index-y_bUWp3C.d.ts.map → index-Cj45GkKv.d.ts.map} +1 -1
  25. package/package.json +1 -1
  26. package/dist/adapters/storage/progres.d.ts.map +0 -1
  27. package/dist/adapters/storage/progres.js.map +0 -1
  28. package/dist/adapters/storage/progres.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -262,6 +262,7 @@ const proxy = (x) => {
262
262
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
263
263
  // THE SOFTWARE.
264
264
  //
265
+ const afterCommitTasks = new WeakMap();
265
266
  class _ProtoQuery extends TQuery {
266
267
  _proto;
267
268
  _opts;
@@ -380,6 +381,15 @@ class _ProtoQuery extends TQuery {
380
381
  })();
381
382
  }
382
383
  }
384
+ _do_tasks(session, task) {
385
+ const registers = session && afterCommitTasks.get(session);
386
+ if (!_.isNil(registers)) {
387
+ registers.push(task);
388
+ }
389
+ else {
390
+ task();
391
+ }
392
+ }
383
393
  async insertMany(values, options) {
384
394
  const objs = this._objectMethods(await this._dispatcher(options).insert({
385
395
  className: this.className,
@@ -387,30 +397,38 @@ class _ProtoQuery extends TQuery {
387
397
  matches: this[PVK].options.matches,
388
398
  groupMatches: this[PVK].options.groupMatches,
389
399
  }, values));
390
- this._on_upsert(objs);
391
- if (!options?.silent || !options.master)
392
- this._on_upsert_traggers(objs);
400
+ this._do_tasks(options?.session, () => {
401
+ this._on_upsert(objs);
402
+ if (!options?.silent || !options.master)
403
+ this._on_upsert_traggers(objs);
404
+ });
393
405
  return objs;
394
406
  }
395
407
  async updateMany(update, options) {
396
408
  const objs = this._objectMethods(await this._dispatcher(options).update(this._queryOptions, update));
397
- this._on_upsert(objs);
398
- if (!options?.silent || !options.master)
399
- this._on_upsert_traggers(objs);
409
+ this._do_tasks(options?.session, () => {
410
+ this._on_upsert(objs);
411
+ if (!options?.silent || !options.master)
412
+ this._on_upsert_traggers(objs);
413
+ });
400
414
  return objs;
401
415
  }
402
416
  async upsertMany(update, setOnInsert, options) {
403
417
  const objs = this._objectMethods(await this._dispatcher(options).upsert(this._queryOptions, update, setOnInsert));
404
- this._on_upsert(objs);
405
- if (!options?.silent || !options.master)
406
- this._on_upsert_traggers(objs);
418
+ this._do_tasks(options?.session, () => {
419
+ this._on_upsert(objs);
420
+ if (!options?.silent || !options.master)
421
+ this._on_upsert_traggers(objs);
422
+ });
407
423
  return objs;
408
424
  }
409
425
  async deleteMany(options) {
410
426
  const objs = this._objectMethods(await this._dispatcher(options).delete(this._queryOptions));
411
- this._on_delete(objs);
412
- if (!options?.silent || !options.master)
413
- this._on_delete_traggers(objs);
427
+ this._do_tasks(options?.session, () => {
428
+ this._on_delete(objs);
429
+ if (!options?.silent || !options.master)
430
+ this._on_delete_traggers(objs);
431
+ });
414
432
  return objs;
415
433
  }
416
434
  }
@@ -1746,8 +1764,18 @@ class ProtoService extends ProtoType {
1746
1764
  lockTable(className, update) {
1747
1765
  return this.storage.lockTable(className, update);
1748
1766
  }
1749
- withTransaction(callback, options) {
1750
- return this.storage.withTransaction((storage) => callback(_.create(this, { _storage: storage })), options);
1767
+ async withTransaction(callback, options) {
1768
+ const tasks = afterCommitTasks.get(this) ?? [];
1769
+ const result = await this.storage.withTransaction((storage) => {
1770
+ const payload = _.create(this, { _storage: storage });
1771
+ afterCommitTasks.set(payload, tasks);
1772
+ return callback(payload);
1773
+ }, options);
1774
+ if (!afterCommitTasks.has(this)) {
1775
+ for (const task of tasks)
1776
+ task();
1777
+ }
1778
+ return result;
1751
1779
  }
1752
1780
  generateUploadToken(options = {}) {
1753
1781
  return this[PVK].jwtSign({