@rainbow-o23/n1 1.0.59 → 1.0.60

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/index.cjs CHANGED
@@ -399,7 +399,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
399
399
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
400
400
  PERFORMANCE OF THIS SOFTWARE.
401
401
  ***************************************************************************** */
402
- /* global Reflect, Promise, SuppressedError, Symbol */
402
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
403
403
 
404
404
 
405
405
  function __decorate(decorators, target, key, desc) {
@@ -813,6 +813,12 @@ class AbstractPipeline extends AbstractPipelineExecution {
813
813
  const options = this.buildStepOptions();
814
814
  return await Promise.all(this.getStepBuilders().map(async (builder) => await builder.create(options)));
815
815
  }
816
+ defendPipelineRequest(request) {
817
+ if (request.$context == null) {
818
+ request.$context = new PipelineExecutionContext();
819
+ }
820
+ return request;
821
+ }
816
822
  convertRequestToPipelineData(request) {
817
823
  return {
818
824
  content: request.payload,
@@ -825,16 +831,8 @@ class AbstractPipeline extends AbstractPipelineExecution {
825
831
  $context: result.$context
826
832
  };
827
833
  }
828
- createTraceId(request) {
829
- const { traceId } = request.$context ?? {};
830
- if (traceId == null || traceId.trim().length === 0) {
831
- return nanoid.nanoid(16);
832
- }
833
- else {
834
- return traceId;
835
- }
836
- }
837
834
  async perform(request) {
835
+ request = this.defendPipelineRequest(request);
838
836
  const $context = request.$context;
839
837
  const traceId = $context.traceId;
840
838
  const response = await this.measurePerformance(traceId, 'PIPELINE')
package/index.js CHANGED
@@ -397,7 +397,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
397
397
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
398
398
  PERFORMANCE OF THIS SOFTWARE.
399
399
  ***************************************************************************** */
400
- /* global Reflect, Promise, SuppressedError, Symbol */
400
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
401
401
 
402
402
 
403
403
  function __decorate(decorators, target, key, desc) {
@@ -811,6 +811,12 @@ class AbstractPipeline extends AbstractPipelineExecution {
811
811
  const options = this.buildStepOptions();
812
812
  return await Promise.all(this.getStepBuilders().map(async (builder) => await builder.create(options)));
813
813
  }
814
+ defendPipelineRequest(request) {
815
+ if (request.$context == null) {
816
+ request.$context = new PipelineExecutionContext();
817
+ }
818
+ return request;
819
+ }
814
820
  convertRequestToPipelineData(request) {
815
821
  return {
816
822
  content: request.payload,
@@ -823,16 +829,8 @@ class AbstractPipeline extends AbstractPipelineExecution {
823
829
  $context: result.$context
824
830
  };
825
831
  }
826
- createTraceId(request) {
827
- const { traceId } = request.$context ?? {};
828
- if (traceId == null || traceId.trim().length === 0) {
829
- return nanoid(16);
830
- }
831
- else {
832
- return traceId;
833
- }
834
- }
835
832
  async perform(request) {
833
+ request = this.defendPipelineRequest(request);
836
834
  const $context = request.$context;
837
835
  const traceId = $context.traceId;
838
836
  const response = await this.measurePerformance(traceId, 'PIPELINE')
@@ -5,7 +5,7 @@ import { PipelineStep, PipelineStepBuilder, PipelineStepData, PipelineStepOption
5
5
  export type PipelineRequestPayload = any;
6
6
  export interface PipelineRequest<C = PipelineRequestPayload> {
7
7
  payload: C;
8
- $context: PipelineExecutionContext;
8
+ $context?: PipelineExecutionContext;
9
9
  }
10
10
  export type PipelineResponsePayload = any;
11
11
  export interface PipelineResponse<C = PipelineResponsePayload> {
@@ -30,9 +30,9 @@ export declare abstract class AbstractPipeline<In = any, Out = any> extends Abst
30
30
  protected abstract getStepBuilders(): Array<PipelineStepBuilder>;
31
31
  protected buildStepOptions(): Pick<PipelineStepOptions, 'config' | 'logger'>;
32
32
  createSteps(): Promise<Array<PipelineStep>>;
33
+ protected defendPipelineRequest(request: PipelineRequest<In>): Required<PipelineRequest<In>>;
33
34
  convertRequestToPipelineData<I, FirstStepIn>(request: PipelineRequest<I>): PipelineStepData<FirstStepIn>;
34
35
  convertPipelineDataToResponse<LastStepOut, O>(result: PipelineStepData<LastStepOut>): PipelineResponse<O>;
35
- protected createTraceId(request: PipelineRequest<In>): string;
36
36
  perform(request: PipelineRequest<In>): Promise<PipelineResponse<Out>>;
37
37
  }
38
38
  export declare abstract class AbstractStaticPipeline<In = any, Out = any> extends AbstractPipeline<In, Out> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rainbow-o23/n1",
3
- "version": "1.0.59",
3
+ "version": "1.0.60",
4
4
  "description": "o23 interfaces",
5
5
  "main": "index.cjs",
6
6
  "module": "index.js",
@@ -1,4 +1,3 @@
1
- import {nanoid} from 'nanoid';
2
1
  import {Config, Logger} from '../utils';
3
2
  import {AbstractPipelineExecution, PipelineExecutionOptions} from './pipeline-execution';
4
3
  import {PipelineExecutionContext} from './pipeline-execution-context';
@@ -16,7 +15,7 @@ export type PipelineRequestPayload = any;
16
15
 
17
16
  export interface PipelineRequest<C = PipelineRequestPayload> {
18
17
  payload: C;
19
- $context: PipelineExecutionContext;
18
+ $context?: PipelineExecutionContext;
20
19
  }
21
20
 
22
21
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -78,6 +77,13 @@ export abstract class AbstractPipeline<In = any, Out = any> extends AbstractPipe
78
77
  return await Promise.all(this.getStepBuilders().map(async builder => await builder.create(options)));
79
78
  }
80
79
 
80
+ protected defendPipelineRequest(request: PipelineRequest<In>): Required<PipelineRequest<In>> {
81
+ if (request.$context == null) {
82
+ request.$context = new PipelineExecutionContext();
83
+ }
84
+ return request as Required<PipelineRequest<In>>;
85
+ }
86
+
81
87
  public convertRequestToPipelineData<I, FirstStepIn>(request: PipelineRequest<I>): PipelineStepData<FirstStepIn> {
82
88
  return {
83
89
  content: request.payload as unknown as FirstStepIn,
@@ -92,15 +98,6 @@ export abstract class AbstractPipeline<In = any, Out = any> extends AbstractPipe
92
98
  };
93
99
  }
94
100
 
95
- protected createTraceId(request: PipelineRequest<In>): string {
96
- const {traceId} = request.$context ?? {};
97
- if (traceId == null || traceId.trim().length === 0) {
98
- return nanoid(16);
99
- } else {
100
- return traceId;
101
- }
102
- }
103
-
104
101
  /**
105
102
  * perform pipeline.
106
103
  * - first step use request as input,
@@ -108,6 +105,7 @@ export abstract class AbstractPipeline<In = any, Out = any> extends AbstractPipe
108
105
  * - use last step's result as response.
109
106
  */
110
107
  public async perform(request: PipelineRequest<In>): Promise<PipelineResponse<Out>> {
108
+ request = this.defendPipelineRequest(request);
111
109
  const $context = request.$context;
112
110
  const traceId = $context.traceId;
113
111
  const response = await this.measurePerformance(traceId, 'PIPELINE')