proto.io 0.0.225 → 0.0.226

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.
@@ -1,7 +1,7 @@
1
- import { P as ProtoService } from '../../internals/index-Bi9H_aYC.js';
1
+ import { P as ProtoService } from '../../internals/index-1ZK5N4yb.js';
2
2
  import OSS from 'ali-oss';
3
- import { a as FileStorageOptions } from '../../internals/base-DPYj2_4S.js';
4
- import { F as FileChunkStorageBase } from '../../internals/chunk-B9XHpR52.js';
3
+ import { a as FileStorageOptions } from '../../internals/base-DSo02iAX.js';
4
+ import { F as FileChunkStorageBase } from '../../internals/chunk-BhwfdCdq.js';
5
5
  import '@o2ter/utils-js';
6
6
  import 'jsonwebtoken';
7
7
  import '@o2ter/server-js';
@@ -1,5 +1,5 @@
1
- import { T as TSchema, P as ProtoService } from '../../internals/index-Bi9H_aYC.js';
2
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/base-DPYj2_4S.js';
1
+ import { T as TSchema, P as ProtoService } from '../../internals/index-1ZK5N4yb.js';
2
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/base-DSo02iAX.js';
3
3
  import '@o2ter/utils-js';
4
4
  import 'jsonwebtoken';
5
5
  import '@o2ter/server-js';
@@ -1,6 +1,6 @@
1
- import { P as ProtoService } from '../../internals/index-Bi9H_aYC.js';
2
- import { a as FileStorageOptions } from '../../internals/base-DPYj2_4S.js';
3
- import { F as FileChunkStorageBase } from '../../internals/chunk-B9XHpR52.js';
1
+ import { P as ProtoService } from '../../internals/index-1ZK5N4yb.js';
2
+ import { a as FileStorageOptions } from '../../internals/base-DSo02iAX.js';
3
+ import { F as FileChunkStorageBase } from '../../internals/chunk-BhwfdCdq.js';
4
4
  import '@o2ter/utils-js';
5
5
  import 'jsonwebtoken';
6
6
  import '@o2ter/server-js';
@@ -1,8 +1,8 @@
1
1
  import * as _google_cloud_storage from '@google-cloud/storage';
2
2
  import { File, Storage } from '@google-cloud/storage';
3
- import { P as ProtoService } from '../../internals/index-Bi9H_aYC.js';
4
- import { a as FileStorageOptions } from '../../internals/base-DPYj2_4S.js';
5
- import { F as FileChunkStorageBase } from '../../internals/chunk-B9XHpR52.js';
3
+ import { P as ProtoService } from '../../internals/index-1ZK5N4yb.js';
4
+ import { a as FileStorageOptions } from '../../internals/base-DSo02iAX.js';
5
+ import { F as FileChunkStorageBase } from '../../internals/chunk-BhwfdCdq.js';
6
6
  import '@o2ter/utils-js';
7
7
  import 'jsonwebtoken';
8
8
  import '@o2ter/server-js';
@@ -1,5 +1,5 @@
1
1
  import { Pool, PoolClient, PoolConfig } from 'pg';
2
- import { c as TValueWithoutObject, T as TSchema, q as TValueWithUndefined, r as TValue, t as TUpdateOp, F as FieldSelectorExpression, Q as QueryExpression, R as RelationOptions, u as QuerySelector, v as DecodedQuery, w as FindOptions, x as DecodedSortOption, y as QueryAccumulator, I as InsertOptions, z as TStorage, A as TransactionOptions, k as TObject, B as QueryRandomOptions, C as TPubSub } from '../../internals/index-Bi9H_aYC.js';
2
+ import { c as TValueWithoutObject, T as TSchema, q as TValueWithUndefined, r as TValue, t as TUpdateOp, F as FieldSelectorExpression, Q as QueryExpression, R as RelationOptions, u as QuerySelector, v as DecodedQuery, w as FindOptions, x as DecodedSortOption, y as QueryAccumulator, I as InsertOptions, z as TStorage, A as TransactionOptions, k as TObject, B as QueryRandomOptions, C as TPubSub } from '../../internals/index-1ZK5N4yb.js';
3
3
  import * as _o2ter_utils_js from '@o2ter/utils-js';
4
4
  import { asyncStream } from '@o2ter/utils-js';
5
5
  import 'jsonwebtoken';
package/dist/client.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { P as ProtoClient } from './internals/index-y_bUWp3C.js';
2
- export { c as classExtends } from './internals/index-y_bUWp3C.js';
3
- export { D as DeserializeOptions, S as SerializeOptions, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-Bi9H_aYC.js';
1
+ import { P as ProtoClient } from './internals/index-Cj45GkKv.js';
2
+ export { c as classExtends } from './internals/index-Cj45GkKv.js';
3
+ export { D as DeserializeOptions, S as SerializeOptions, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-1ZK5N4yb.js';
4
4
  export { Decimal } from 'decimal.js';
5
5
  import '@o2ter/utils-js';
6
6
  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 { P as ProtoService, a as ProtoServiceOptions, b as ProtoServiceKeyOptions, T as TSchema, c as TValueWithoutObject } from './internals/index-Bi9H_aYC.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-Bi9H_aYC.js';
4
+ import { P as ProtoService, a as ProtoServiceOptions, b as ProtoServiceKeyOptions, T as TSchema, c as TValueWithoutObject } from './internals/index-1ZK5N4yb.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-1ZK5N4yb.js';
6
6
  import Decimal from 'decimal.js';
7
7
  export { Decimal } from 'decimal.js';
8
- export { P as ProtoClient, c as classExtends } from './internals/index-y_bUWp3C.js';
8
+ export { P as ProtoClient, c as classExtends } from './internals/index-Cj45GkKv.js';
9
9
  import '@o2ter/utils-js';
10
10
  import 'jsonwebtoken';
11
11
  import 'lodash';
package/dist/index.js CHANGED
@@ -265,6 +265,7 @@ const proxy = (x) => {
265
265
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
266
266
  // THE SOFTWARE.
267
267
  //
268
+ const afterCommitTasks = new WeakMap();
268
269
  class _ProtoQuery extends index.TQuery {
269
270
  _proto;
270
271
  _opts;
@@ -383,6 +384,15 @@ class _ProtoQuery extends index.TQuery {
383
384
  })();
384
385
  }
385
386
  }
387
+ _do_tasks(session, task) {
388
+ const registers = session && afterCommitTasks.get(session);
389
+ if (!_.isNil(registers)) {
390
+ registers.push(task);
391
+ }
392
+ else {
393
+ task();
394
+ }
395
+ }
386
396
  async insertMany(values, options) {
387
397
  const objs = this._objectMethods(await this._dispatcher(options).insert({
388
398
  className: this.className,
@@ -390,30 +400,38 @@ class _ProtoQuery extends index.TQuery {
390
400
  matches: this[_private.PVK].options.matches,
391
401
  groupMatches: this[_private.PVK].options.groupMatches,
392
402
  }, values));
393
- this._on_upsert(objs);
394
- if (!options?.silent || !options.master)
395
- this._on_upsert_traggers(objs);
403
+ this._do_tasks(options?.session, () => {
404
+ this._on_upsert(objs);
405
+ if (!options?.silent || !options.master)
406
+ this._on_upsert_traggers(objs);
407
+ });
396
408
  return objs;
397
409
  }
398
410
  async updateMany(update, options) {
399
411
  const objs = this._objectMethods(await this._dispatcher(options).update(this._queryOptions, update));
400
- this._on_upsert(objs);
401
- if (!options?.silent || !options.master)
402
- this._on_upsert_traggers(objs);
412
+ this._do_tasks(options?.session, () => {
413
+ this._on_upsert(objs);
414
+ if (!options?.silent || !options.master)
415
+ this._on_upsert_traggers(objs);
416
+ });
403
417
  return objs;
404
418
  }
405
419
  async upsertMany(update, setOnInsert, options) {
406
420
  const objs = this._objectMethods(await this._dispatcher(options).upsert(this._queryOptions, update, setOnInsert));
407
- this._on_upsert(objs);
408
- if (!options?.silent || !options.master)
409
- this._on_upsert_traggers(objs);
421
+ this._do_tasks(options?.session, () => {
422
+ this._on_upsert(objs);
423
+ if (!options?.silent || !options.master)
424
+ this._on_upsert_traggers(objs);
425
+ });
410
426
  return objs;
411
427
  }
412
428
  async deleteMany(options) {
413
429
  const objs = this._objectMethods(await this._dispatcher(options).delete(this._queryOptions));
414
- this._on_delete(objs);
415
- if (!options?.silent || !options.master)
416
- this._on_delete_traggers(objs);
430
+ this._do_tasks(options?.session, () => {
431
+ this._on_delete(objs);
432
+ if (!options?.silent || !options.master)
433
+ this._on_delete_traggers(objs);
434
+ });
417
435
  return objs;
418
436
  }
419
437
  }
@@ -1749,8 +1767,18 @@ class ProtoService extends index.ProtoType {
1749
1767
  lockTable(className, update) {
1750
1768
  return this.storage.lockTable(className, update);
1751
1769
  }
1752
- withTransaction(callback, options) {
1753
- return this.storage.withTransaction((storage) => callback(_.create(this, { _storage: storage })), options);
1770
+ async withTransaction(callback, options) {
1771
+ const tasks = afterCommitTasks.get(this) ?? [];
1772
+ const result = await this.storage.withTransaction((storage) => {
1773
+ const payload = _.create(this, { _storage: storage });
1774
+ afterCommitTasks.set(payload, tasks);
1775
+ return callback(payload);
1776
+ }, options);
1777
+ if (!afterCommitTasks.has(this)) {
1778
+ for (const task of tasks)
1779
+ task();
1780
+ }
1781
+ return result;
1754
1782
  }
1755
1783
  generateUploadToken(options = {}) {
1756
1784
  return this[_private.PVK].jwtSign({