@rainbow-o23/n3 1.0.55 → 1.0.57

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/README.md CHANGED
@@ -492,9 +492,16 @@ Array<TypeOrmEntityToLoad>;
492
492
 
493
493
  ##### Environment Parameters
494
494
 
495
- | Name | Type | Default Value | Comments |
496
- |-------------------------|--------|---------------|-------------|
497
- | `typeorm.DB.fetch.size` | number | 20 | Fetch size. |
495
+ | Name | Type | Default Value | Comments |
496
+ |-----------------------------------|---------|---------------|----------------------------------------|
497
+ | `typeorm.DB.fetch.size` | number | 20 | Fetch size. |
498
+ | `typeorm.DB.stream.pause.enabled` | boolean | false | Pause and resume result stream or not. |
499
+
500
+ ##### Constructor Parameters
501
+
502
+ | Name | Type | Default Value | Comments |
503
+ |--------------------|---------|---------------|----------------------------------------|
504
+ | pauseStreamEnabled | boolean | | Pause and resume result stream or not. |
498
505
 
499
506
  ##### Request and Response
500
507
 
package/index.cjs CHANGED
@@ -2223,6 +2223,7 @@ class TypeOrmLoadManyBySQLUseCursorPipelineStep extends AbstractTypeOrmBySQLPipe
2223
2223
  _streamToSnippet;
2224
2224
  _streamToFunc;
2225
2225
  _stepBuilders;
2226
+ _pauseStreamEnabled;
2226
2227
  constructor(options) {
2227
2228
  super(options);
2228
2229
  const config = this.getConfig();
@@ -2237,6 +2238,7 @@ class TypeOrmLoadManyBySQLUseCursorPipelineStep extends AbstractTypeOrmBySQLPipe
2237
2238
  }
2238
2239
  });
2239
2240
  this._stepBuilders = options.steps;
2241
+ this._pauseStreamEnabled = options.pauseStreamEnabled ?? config.getBoolean(`typeorm.${this.getDataSourceName()}.stream.pause.enabled`, false);
2240
2242
  }
2241
2243
  getFetchSize() {
2242
2244
  return this._fetchSize;
@@ -2250,6 +2252,9 @@ class TypeOrmLoadManyBySQLUseCursorPipelineStep extends AbstractTypeOrmBySQLPipe
2250
2252
  getStepBuilders() {
2251
2253
  return this._stepBuilders ?? [];
2252
2254
  }
2255
+ isPauseStreamEnabled() {
2256
+ return this._pauseStreamEnabled;
2257
+ }
2253
2258
  async doPerform(basis, request) {
2254
2259
  const { sql, params } = this.getSql(basis, basis?.params);
2255
2260
  return await this.autoTrans(async (runner) => {
@@ -2312,7 +2317,9 @@ class TypeOrmLoadManyBySQLUseCursorPipelineStep extends AbstractTypeOrmBySQLPipe
2312
2317
  reject(e);
2313
2318
  });
2314
2319
  readable.on('data', async (data) => {
2315
- readable.pause();
2320
+ if (this.isPauseStreamEnabled()) {
2321
+ readable.pause();
2322
+ }
2316
2323
  rows.push(data);
2317
2324
  await pipe({
2318
2325
  resolve, reject: async (e) => {
@@ -2320,7 +2327,9 @@ class TypeOrmLoadManyBySQLUseCursorPipelineStep extends AbstractTypeOrmBySQLPipe
2320
2327
  reject(e);
2321
2328
  }, end: false
2322
2329
  });
2323
- readable.resume();
2330
+ if (this.isPauseStreamEnabled()) {
2331
+ readable.resume();
2332
+ }
2324
2333
  });
2325
2334
  };
2326
2335
  return new Promise((resolve, reject) => read({ resolve, reject }));
package/index.js CHANGED
@@ -2221,6 +2221,7 @@ class TypeOrmLoadManyBySQLUseCursorPipelineStep extends AbstractTypeOrmBySQLPipe
2221
2221
  _streamToSnippet;
2222
2222
  _streamToFunc;
2223
2223
  _stepBuilders;
2224
+ _pauseStreamEnabled;
2224
2225
  constructor(options) {
2225
2226
  super(options);
2226
2227
  const config = this.getConfig();
@@ -2235,6 +2236,7 @@ class TypeOrmLoadManyBySQLUseCursorPipelineStep extends AbstractTypeOrmBySQLPipe
2235
2236
  }
2236
2237
  });
2237
2238
  this._stepBuilders = options.steps;
2239
+ this._pauseStreamEnabled = options.pauseStreamEnabled ?? config.getBoolean(`typeorm.${this.getDataSourceName()}.stream.pause.enabled`, false);
2238
2240
  }
2239
2241
  getFetchSize() {
2240
2242
  return this._fetchSize;
@@ -2248,6 +2250,9 @@ class TypeOrmLoadManyBySQLUseCursorPipelineStep extends AbstractTypeOrmBySQLPipe
2248
2250
  getStepBuilders() {
2249
2251
  return this._stepBuilders ?? [];
2250
2252
  }
2253
+ isPauseStreamEnabled() {
2254
+ return this._pauseStreamEnabled;
2255
+ }
2251
2256
  async doPerform(basis, request) {
2252
2257
  const { sql, params } = this.getSql(basis, basis?.params);
2253
2258
  return await this.autoTrans(async (runner) => {
@@ -2310,7 +2315,9 @@ class TypeOrmLoadManyBySQLUseCursorPipelineStep extends AbstractTypeOrmBySQLPipe
2310
2315
  reject(e);
2311
2316
  });
2312
2317
  readable.on('data', async (data) => {
2313
- readable.pause();
2318
+ if (this.isPauseStreamEnabled()) {
2319
+ readable.pause();
2320
+ }
2314
2321
  rows.push(data);
2315
2322
  await pipe({
2316
2323
  resolve, reject: async (e) => {
@@ -2318,7 +2325,9 @@ class TypeOrmLoadManyBySQLUseCursorPipelineStep extends AbstractTypeOrmBySQLPipe
2318
2325
  reject(e);
2319
2326
  }, end: false
2320
2327
  });
2321
- readable.resume();
2328
+ if (this.isPauseStreamEnabled()) {
2329
+ readable.resume();
2330
+ }
2322
2331
  });
2323
2332
  };
2324
2333
  return new Promise((resolve, reject) => read({ resolve, reject }));
@@ -8,17 +8,20 @@ export interface TypeOrmLoadManyBySQLUseCursorPipelineStepOptions<In = PipelineS
8
8
  fetchSize?: number;
9
9
  streamTo?: ScriptFuncOrBody<StreamToFunc<In, Item>>;
10
10
  steps?: Array<PipelineStepBuilder>;
11
+ pauseStreamEnabled?: boolean;
11
12
  }
12
13
  export declare class TypeOrmLoadManyBySQLUseCursorPipelineStep<In = PipelineStepPayload, Out = PipelineStepPayload, InFragment = Undefinable<TypeOrmLoadBasis>, OutFragment = Out, Item = any> extends AbstractTypeOrmBySQLPipelineStep<In, Out, Undefinable<TypeOrmLoadBasis>, OutFragment> {
13
14
  private readonly _fetchSize;
14
15
  private readonly _streamToSnippet;
15
16
  private readonly _streamToFunc;
16
17
  private readonly _stepBuilders;
18
+ private readonly _pauseStreamEnabled;
17
19
  constructor(options: TypeOrmLoadManyBySQLUseCursorPipelineStepOptions<In, Out, InFragment, OutFragment>);
18
20
  protected getFetchSize(): number;
19
21
  getStreamToSnippet(): ScriptFuncOrBody<StreamToFunc<In, Item>>;
20
22
  protected generateVariableNames(): Array<string>;
21
23
  protected getStepBuilders(): Array<PipelineStepBuilder>;
24
+ protected isPauseStreamEnabled(): boolean;
22
25
  protected doPerform(basis: Undefinable<TypeOrmLoadBasis>, request: PipelineStepData<In>): Promise<Undefinable<OutFragment>>;
23
26
  protected getFetchDataVariableName(): string;
24
27
  protected getRequestVariableName(): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rainbow-o23/n3",
3
- "version": "1.0.55",
3
+ "version": "1.0.57",
4
4
  "description": "o23 pipelines",
5
5
  "main": "index.cjs",
6
6
  "module": "index.js",
@@ -21,7 +21,7 @@
21
21
  "url": "https://github.com/InsureMO/rainbow-o23/issues"
22
22
  },
23
23
  "dependencies": {
24
- "@rainbow-o23/n1": "1.0.55",
24
+ "@rainbow-o23/n1": "1.0.57",
25
25
  "node-fetch": "2.6.7",
26
26
  "typeorm": "^0.3.20",
27
27
  "typescript": "5.5.4"
@@ -22,6 +22,7 @@ export interface TypeOrmLoadManyBySQLUseCursorPipelineStepOptions<In = PipelineS
22
22
  fetchSize?: number;
23
23
  streamTo?: ScriptFuncOrBody<StreamToFunc<In, Item>>;
24
24
  steps?: Array<PipelineStepBuilder>;
25
+ pauseStreamEnabled?: boolean;
25
26
  }
26
27
 
27
28
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -31,6 +32,7 @@ export class TypeOrmLoadManyBySQLUseCursorPipelineStep<In = PipelineStepPayload,
31
32
  private readonly _streamToSnippet: ScriptFuncOrBody<StreamToFunc<In, Item>>;
32
33
  private readonly _streamToFunc: StreamToFunc<In, Item>;
33
34
  private readonly _stepBuilders: Array<PipelineStepBuilder>;
35
+ private readonly _pauseStreamEnabled: boolean;
34
36
 
35
37
  public constructor(options: TypeOrmLoadManyBySQLUseCursorPipelineStepOptions<In, Out, InFragment, OutFragment>) {
36
38
  super(options);
@@ -47,6 +49,10 @@ export class TypeOrmLoadManyBySQLUseCursorPipelineStep<In = PipelineStepPayload,
47
49
  }
48
50
  });
49
51
  this._stepBuilders = options.steps;
52
+ // for unknown reason, in some environment if the pause and resume functions of readable invoked,
53
+ // only the first row are returns and end event invoked immediately
54
+ // so default disable it.
55
+ this._pauseStreamEnabled = options.pauseStreamEnabled ?? config.getBoolean(`typeorm.${this.getDataSourceName()}.stream.pause.enabled`, false);
50
56
  }
51
57
 
52
58
  protected getFetchSize(): number {
@@ -65,6 +71,10 @@ export class TypeOrmLoadManyBySQLUseCursorPipelineStep<In = PipelineStepPayload,
65
71
  return this._stepBuilders ?? [];
66
72
  }
67
73
 
74
+ protected isPauseStreamEnabled(): boolean {
75
+ return this._pauseStreamEnabled;
76
+ }
77
+
68
78
  protected async doPerform(basis: Undefinable<TypeOrmLoadBasis>, request: PipelineStepData<In>): Promise<Undefinable<OutFragment>> {
69
79
  const {sql, params} = this.getSql(basis, basis?.params);
70
80
  return await this.autoTrans<OutFragment>(async (runner) => {
@@ -136,7 +146,9 @@ export class TypeOrmLoadManyBySQLUseCursorPipelineStep<In = PipelineStepPayload,
136
146
  reject(e);
137
147
  });
138
148
  readable.on('data', async (data) => {
139
- readable.pause();
149
+ if (this.isPauseStreamEnabled()) {
150
+ readable.pause();
151
+ }
140
152
  rows.push(data);
141
153
  await pipe({
142
154
  resolve, reject: async (e: Error) => {
@@ -144,7 +156,9 @@ export class TypeOrmLoadManyBySQLUseCursorPipelineStep<In = PipelineStepPayload,
144
156
  reject(e);
145
157
  }, end: false
146
158
  });
147
- readable.resume();
159
+ if (this.isPauseStreamEnabled()) {
160
+ readable.resume();
161
+ }
148
162
  });
149
163
  };
150
164
  return new Promise<OutFragment>((resolve, reject) => read({resolve, reject}));
@@ -9,7 +9,8 @@ describe('TypeORM Cursor Suite', () => {
9
9
  process.env.CFG_TYPEORM_TEST_HOST = 'localhost';
10
10
  process.env.CFG_TYPEORM_TEST_USERNAME = 'o23';
11
11
  process.env.CFG_TYPEORM_TEST_PASSWORD = 'o23';
12
- const type = 'pg' + 'sql';
12
+ // process.env.CFG_TYPEORM_TEST_STREAM_PAUSE_ENABLED = 'true'
13
+ const type = 'my' + 'sql';
13
14
  if (type === 'mysql') {
14
15
  process.env.CFG_TYPEORM_TEST_TYPE = 'mysql';
15
16
  process.env.CFG_TYPEORM_TEST_PORT = '3306';