@skmtc/core 0.0.595 → 0.0.596

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.
@@ -2,7 +2,7 @@ import "../_dnt.polyfills.js";
2
2
  import type { OpenAPIV3 } from 'openapi-types';
3
3
  import { OasDocument } from '../oas/document/Document.js';
4
4
  import type * as log from '../deps/jsr.io/@std/log/0.224.8/mod.js';
5
- import type { StackTrail } from './StackTrail.js';
5
+ import type { StackTrail, TraceOptions } from './StackTrail.js';
6
6
  type ConstructorArgs = {
7
7
  documentObject: OpenAPIV3.Document;
8
8
  logger: log.Logger;
@@ -18,7 +18,7 @@ export declare class ParseContext {
18
18
  stackTrail: StackTrail;
19
19
  constructor({ documentObject, logger, stackTrail }: ConstructorArgs);
20
20
  parse(): OasDocument;
21
- trace<T>(token: string | string[], fn: () => T): T;
21
+ trace<T>(token: string | string[], fn: () => T, options?: TraceOptions): T;
22
22
  logSkippedFields(skipped: Record<string, unknown>): void;
23
23
  }
24
24
  export declare const parseSchema: (schema: string) => OpenAPIV3.Document<{}>;
@@ -1 +1 @@
1
- {"version":3,"file":"ParseContext.d.ts","sourceRoot":"","sources":["../../src/context/ParseContext.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAG9C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,KAAK,KAAK,GAAG,MAAM,wCAAwC,CAAA;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAGjD,KAAK,eAAe,GAAG;IACrB,cAAc,EAAE,SAAS,CAAC,QAAQ,CAAA;IAClC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAA;IAClB,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,WAAW,EAAE,WAAW,CAAA;CACzB,CAAA;A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U,EAAE,EAAE,eAAe;IAOnE,KAAK;IASL,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,CAAC;IAI1E,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAUlD;AAED,eAAO,MAAM,WAAW,WAAY,MAAM,2BAMzC,CAAA"}
@@ -41,8 +41,8 @@ export class ParseContext {
41
41
  });
42
42
  return this.oasDocument;
43
43
  }
44
- trace(token, fn) {
45
- return tracer(this.stackTrail, token, fn);
44
+ trace(token, fn, options) {
45
+ return tracer(this.stackTrail, token, fn, options);
46
46
  }
47
47
  logSkippedFields(skipped) {
48
48
  Object.entries(skipped).forEach(([key, value]) => {
@@ -1,11 +1,16 @@
1
1
  import "../_dnt.polyfills.js";
2
+ export type TraceOptions = {
3
+ checkCycles?: boolean;
4
+ };
2
5
  export declare class StackTrail {
3
6
  #private;
4
7
  constructor(stack?: (string | number)[]);
5
8
  clone(): StackTrail;
6
9
  slice(start: number, end?: number): StackTrail;
7
10
  get stackTrail(): (string | number)[];
8
- append(frame: string | string[]): StackTrail;
11
+ append(frame: string | string[], options?: TraceOptions): StackTrail;
12
+ checkCycles(frame: string | string[]): boolean;
13
+ checkCyclesArray(frames: string[]): boolean;
9
14
  getParentOf(frame: string): string | undefined;
10
15
  remove(frame: string | string[]): StackTrail;
11
16
  static join(...stacks: (StackTrail | string)[]): string;
@@ -1 +1 @@
1
- {"version":3,"file":"StackTrail.d.ts","sourceRoot":"","sources":["../../src/context/StackTrail.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,qBAAa,UAAU;;gBAGT,KAAK,GAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAO;IAI3C,KAAK;IAIL,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM;IAIjC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,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;IAYvC,QAAQ;CAOT"}
@@ -25,7 +25,10 @@ export class StackTrail {
25
25
  get stackTrail() {
26
26
  return __classPrivateFieldGet(this, _StackTrail_stack, "f");
27
27
  }
28
- append(frame) {
28
+ append(frame, options) {
29
+ if (options?.checkCycles && this.checkCycles(frame)) {
30
+ throw new Error(`Cycle detected in stack trail: ${this}`);
31
+ }
29
32
  if (typeof frame === 'string') {
30
33
  __classPrivateFieldGet(this, _StackTrail_stack, "f").push(frame);
31
34
  return this;
@@ -36,6 +39,25 @@ export class StackTrail {
36
39
  }
37
40
  throw new Error(`Unexpected stack frame: ${frame}`);
38
41
  }
42
+ checkCycles(frame) {
43
+ if (typeof frame === 'string') {
44
+ return __classPrivateFieldGet(this, _StackTrail_stack, "f").includes(frame);
45
+ }
46
+ return this.checkCyclesArray(frame);
47
+ }
48
+ checkCyclesArray(frames) {
49
+ if (frames.length === 0) {
50
+ return false;
51
+ }
52
+ const lastFrame = frames[frames.length - 1];
53
+ const indexOfLastFrame = __classPrivateFieldGet(this, _StackTrail_stack, "f").indexOf(lastFrame);
54
+ if (indexOfLastFrame === -1) {
55
+ return false;
56
+ }
57
+ return frames.toReversed().every((frame, index) => {
58
+ return frame === __classPrivateFieldGet(this, _StackTrail_stack, "f")[indexOfLastFrame - index];
59
+ });
60
+ }
39
61
  getParentOf(frame) {
40
62
  const lastItemIndex = this.stackTrail.length - 1;
41
63
  if (this.stackTrail?.[lastItemIndex] === frame &&
@@ -1,3 +1,3 @@
1
- import type { StackTrail } from '../context/StackTrail.js';
2
- export declare const tracer: <T>(stackTrail: StackTrail, token: string | string[], fn: () => T) => T;
1
+ import type { StackTrail, TraceOptions } from '../context/StackTrail.js';
2
+ export declare const tracer: <T>(stackTrail: StackTrail, token: string | string[], fn: () => T, options?: TraceOptions) => T;
3
3
  //# sourceMappingURL=tracer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tracer.d.ts","sourceRoot":"","sources":["../../src/helpers/tracer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,eAAO,MAAM,MAAM,GAAI,CAAC,cACV,UAAU,SACf,MAAM,GAAG,MAAM,EAAE,MACpB,MAAM,CAAC,MASZ,CAAA"}
1
+ {"version":3,"file":"tracer.d.ts","sourceRoot":"","sources":["../../src/helpers/tracer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAExE,eAAO,MAAM,MAAM,GAAI,CAAC,cACV,UAAU,SACf,MAAM,GAAG,MAAM,EAAE,MACpB,MAAM,CAAC,YACD,YAAY,MASvB,CAAA"}
@@ -1,5 +1,5 @@
1
- export const tracer = (stackTrail, token, fn) => {
2
- stackTrail.append(token);
1
+ export const tracer = (stackTrail, token, fn, options) => {
2
+ stackTrail.append(token, options);
3
3
  const result = fn();
4
4
  stackTrail.remove(token);
5
5
  return result;
@@ -1 +1 @@
1
- {"version":3,"file":"toComponentsV3.d.ts","sourceRoot":"","sources":["../../../src/oas/components/toComponentsV3.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAGjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAI/C,KAAK,kBAAkB,GAAG;IACxB,UAAU,EAAE,SAAS,CAAC,gBAAgB,GAAG,SAAS,CAAA;IAClD,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,cAAc,4BAGxB,kBAAkB,KAAG,aAAa,GAAG,SAgCvC,CAAA"}
1
+ {"version":3,"file":"toComponentsV3.d.ts","sourceRoot":"","sources":["../../../src/oas/components/toComponentsV3.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAGjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAI/C,KAAK,kBAAkB,GAAG;IACxB,UAAU,EAAE,SAAS,CAAC,gBAAgB,GAAG,SAAS,CAAA;IAClD,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,cAAc,4BAGxB,kBAAkB,KAAG,aAAa,GAAG,SAsDvC,CAAA"}
@@ -13,20 +13,33 @@ export const toComponentsV3 = ({ components, context }) => {
13
13
  const { schemas, responses, parameters, examples, requestBodies, headers, ...skipped } = components;
14
14
  const extensionFields = toSpecificationExtensionsV3({ skipped, context });
15
15
  const fields = {
16
- schemas: context.trace('schemas', () => toOptionalSchemasV3({ schemas, context })),
17
- responses: context.trace('responses', () => toOptionalResponsesV3({ responses, context })),
16
+ schemas: context.trace('schemas', () => toOptionalSchemasV3({ schemas, context }), {
17
+ checkCycles: true
18
+ }),
19
+ responses: context.trace('responses', () => toOptionalResponsesV3({ responses, context }), {
20
+ checkCycles: true
21
+ }),
18
22
  parameters: context.trace('parameters', () => toOptionalParametersV3({
19
23
  parameters,
20
24
  context
21
- })),
25
+ }), {
26
+ checkCycles: true
27
+ }),
22
28
  examples: toExamplesV3({
23
29
  examples,
24
30
  example: undefined,
25
31
  exampleKey: 'TEMP',
26
- context
32
+ context,
33
+ options: {
34
+ checkCycles: true
35
+ }
36
+ }),
37
+ requestBodies: context.trace('requestBodies', () => toRequestBodiesV3({ requestBodies, context }), {
38
+ checkCycles: true
39
+ }),
40
+ headers: context.trace('headers', () => toHeadersV3({ headers, context }), {
41
+ checkCycles: true
27
42
  }),
28
- requestBodies: context.trace('requestBodies', () => toRequestBodiesV3({ requestBodies, context })),
29
- headers: context.trace('headers', () => toHeadersV3({ headers, context })),
30
43
  extensionFields
31
44
  };
32
45
  return new OasComponents(fields);
@@ -2,6 +2,7 @@ import type { ParseContext } from '../../context/ParseContext.js';
2
2
  import type { OpenAPIV3 } from 'openapi-types';
3
3
  import { OasExample } from './Example.js';
4
4
  import type { OasRef } from '../ref/Ref.js';
5
+ import type { TraceOptions } from '../../context/StackTrail.js';
5
6
  type ToExampleSimpleV3Args = {
6
7
  example: unknown;
7
8
  };
@@ -11,8 +12,9 @@ export type ToExamplesV3Args = {
11
12
  examples: Record<string, OpenAPIV3.ExampleObject | OpenAPIV3.ReferenceObject> | undefined;
12
13
  exampleKey: string;
13
14
  context: ParseContext;
15
+ options?: TraceOptions;
14
16
  };
15
- export declare const toExamplesV3: ({ example, examples, exampleKey, context }: ToExamplesV3Args) => Record<string, OasExample | OasRef<"example">> | undefined;
17
+ export declare const toExamplesV3: ({ example, examples, exampleKey, context, options }: ToExamplesV3Args) => Record<string, OasExample | OasRef<"example">> | undefined;
16
18
  type ToExampleV3Args = {
17
19
  example: OpenAPIV3.ExampleObject | OpenAPIV3.ReferenceObject;
18
20
  context: ParseContext;
@@ -1 +1 @@
1
- {"version":3,"file":"toExamplesV3.d.ts","sourceRoot":"","sources":["../../../src/oas/example/toExamplesV3.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAG9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAG3C,KAAK,qBAAqB,GAAG;IAC3B,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,iBAAiB,gBAE3B,qBAAqB,KAAG,UAAU,GAAG,MAAM,CAAC,SAAS,CAQvD,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,SAAS,CAAC,aAAa,GAAG,SAAS,CAAA;IAC5C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,aAAa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AAO,EAAE,YAAY,CAAA;IACrB,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,YAAY,wDAMtB,gBAAgB,KAAG,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,SA0BtE,CAAA;AAED,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,SAAS,CAAC,aAAa,GAAG,SAAS,CAAC,eAAe,CAAA;IAC5D,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,WAAW,yBAGrB,eAAe,KAAG,UAAU,GAAG,MAAM,CAAC,SAAS,CAejD,CAAA"}
@@ -10,13 +10,13 @@ export const toExampleSimpleV3 = ({ example }) => {
10
10
  };
11
11
  return new OasExample(fields);
12
12
  };
13
- export const toExamplesV3 = ({ example, examples, exampleKey, context }) => {
13
+ export const toExamplesV3 = ({ example, examples, exampleKey, context, options }) => {
14
14
  if (example && examples) {
15
15
  context.logger.warn(`Both example and examples are defined for ${exampleKey}`);
16
16
  }
17
17
  if (example) {
18
18
  return {
19
- [exampleKey]: context.trace('example', () => toExampleSimpleV3({ example }))
19
+ [exampleKey]: context.trace('example', () => toExampleSimpleV3({ example }), options)
20
20
  };
21
21
  }
22
22
  if (examples) {
@@ -24,7 +24,7 @@ export const toExamplesV3 = ({ example, examples, exampleKey, context }) => {
24
24
  return Object.fromEntries(Object.entries(examples).map(([key, value]) => {
25
25
  return [key, context.trace(key, () => toExampleV3({ example: value, context }))];
26
26
  }));
27
- });
27
+ }, options);
28
28
  }
29
29
  return undefined;
30
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.0.595",
3
+ "version": "0.0.596",
4
4
  "main": "./script/mod.js",
5
5
  "module": "./esm/mod.js",
6
6
  "exports": {
@@ -2,7 +2,7 @@ import "../_dnt.polyfills.js";
2
2
  import type { OpenAPIV3 } from 'openapi-types';
3
3
  import { OasDocument } from '../oas/document/Document.js';
4
4
  import type * as log from '../deps/jsr.io/@std/log/0.224.8/mod.js';
5
- import type { StackTrail } from './StackTrail.js';
5
+ import type { StackTrail, TraceOptions } from './StackTrail.js';
6
6
  type ConstructorArgs = {
7
7
  documentObject: OpenAPIV3.Document;
8
8
  logger: log.Logger;
@@ -18,7 +18,7 @@ export declare class ParseContext {
18
18
  stackTrail: StackTrail;
19
19
  constructor({ documentObject, logger, stackTrail }: ConstructorArgs);
20
20
  parse(): OasDocument;
21
- trace<T>(token: string | string[], fn: () => T): T;
21
+ trace<T>(token: string | string[], fn: () => T, options?: TraceOptions): T;
22
22
  logSkippedFields(skipped: Record<string, unknown>): void;
23
23
  }
24
24
  export declare const parseSchema: (schema: string) => OpenAPIV3.Document<{}>;
@@ -1 +1 @@
1
- {"version":3,"file":"ParseContext.d.ts","sourceRoot":"","sources":["../../src/context/ParseContext.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAG9C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,KAAK,KAAK,GAAG,MAAM,wCAAwC,CAAA;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAGjD,KAAK,eAAe,GAAG;IACrB,cAAc,EAAE,SAAS,CAAC,QAAQ,CAAA;IAClC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAA;IAClB,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,WAAW,EAAE,WAAW,CAAA;CACzB,CAAA;AAED,qBAAa,YAAY;IACvB,cAAc,EAAE,SAAS,CAAC,QAAQ,CAAA;IAClC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAA;IAClB,WAAW,EAAE,WAAW,CAAA;IACxB,UAAU,EAAE,UAAU,CAAA;gBAEV,EAAE,cAAc,EAA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,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAUlD;AAED,eAAO,MAAM,WAAW,WAAY,MAAM,2BAMzC,CAAA"}
@@ -44,8 +44,8 @@ class ParseContext {
44
44
  });
45
45
  return this.oasDocument;
46
46
  }
47
- trace(token, fn) {
48
- return (0, tracer_js_1.tracer)(this.stackTrail, token, fn);
47
+ trace(token, fn, options) {
48
+ return (0, tracer_js_1.tracer)(this.stackTrail, token, fn, options);
49
49
  }
50
50
  logSkippedFields(skipped) {
51
51
  Object.entries(skipped).forEach(([key, value]) => {
@@ -1,11 +1,16 @@
1
1
  import "../_dnt.polyfills.js";
2
+ export type TraceOptions = {
3
+ checkCycles?: boolean;
4
+ };
2
5
  export declare class StackTrail {
3
6
  #private;
4
7
  constructor(stack?: (string | number)[]);
5
8
  clone(): StackTrail;
6
9
  slice(start: number, end?: number): StackTrail;
7
10
  get stackTrail(): (string | number)[];
8
- append(frame: string | string[]): StackTrail;
11
+ append(frame: string | string[], options?: TraceOptions): StackTrail;
12
+ checkCycles(frame: string | string[]): boolean;
13
+ checkCyclesArray(frames: string[]): boolean;
9
14
  getParentOf(frame: string): string | undefined;
10
15
  remove(frame: string | string[]): StackTrail;
11
16
  static join(...stacks: (StackTrail | string)[]): string;
@@ -1 +1 @@
1
- {"version":3,"file":"StackTrail.d.ts","sourceRoot":"","sources":["../../src/context/StackTrail.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,qBAAa,UAAU;;gBAGT,KAAK,GAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAO;IAI3C,KAAK;IAIL,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM;IAIjC,IAAI,UAAU,wBAEb;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU;IAgB5C,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAW9C,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU;IAsB5C,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC,UAAU,GAAG,MAAM,CAAC,EAAE,GAAG,MAAM;IAIvD,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;IAYvC,QAAQ;CAOT"}
1
+ {"version":3,"file":"StackTrail.d.ts","sourceRoot":"","sources":["../../src/context/StackTrail.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,MAAM,MAAM,YAAY,GAAG;IACzB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,qBAAa,UAAU;;gBAGT,KAAK,GAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAO;IAI3C,KAAK;IAIL,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM;IAIjC,IAAI,UAAU,wBAEb;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,UAAU;IAoBpE,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO;IAQ9C,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO;IAkB3C,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAW9C,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU;IAsB5C,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC,UAAU,GAAG,MAAM,CAAC,EAAE,GAAG,MAAM;IAIvD,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;IAYvC,QAAQ;CAOT"}
@@ -28,7 +28,10 @@ class StackTrail {
28
28
  get stackTrail() {
29
29
  return __classPrivateFieldGet(this, _StackTrail_stack, "f");
30
30
  }
31
- append(frame) {
31
+ append(frame, options) {
32
+ if (options?.checkCycles && this.checkCycles(frame)) {
33
+ throw new Error(`Cycle detected in stack trail: ${this}`);
34
+ }
32
35
  if (typeof frame === 'string') {
33
36
  __classPrivateFieldGet(this, _StackTrail_stack, "f").push(frame);
34
37
  return this;
@@ -39,6 +42,25 @@ class StackTrail {
39
42
  }
40
43
  throw new Error(`Unexpected stack frame: ${frame}`);
41
44
  }
45
+ checkCycles(frame) {
46
+ if (typeof frame === 'string') {
47
+ return __classPrivateFieldGet(this, _StackTrail_stack, "f").includes(frame);
48
+ }
49
+ return this.checkCyclesArray(frame);
50
+ }
51
+ checkCyclesArray(frames) {
52
+ if (frames.length === 0) {
53
+ return false;
54
+ }
55
+ const lastFrame = frames[frames.length - 1];
56
+ const indexOfLastFrame = __classPrivateFieldGet(this, _StackTrail_stack, "f").indexOf(lastFrame);
57
+ if (indexOfLastFrame === -1) {
58
+ return false;
59
+ }
60
+ return frames.toReversed().every((frame, index) => {
61
+ return frame === __classPrivateFieldGet(this, _StackTrail_stack, "f")[indexOfLastFrame - index];
62
+ });
63
+ }
42
64
  getParentOf(frame) {
43
65
  const lastItemIndex = this.stackTrail.length - 1;
44
66
  if (this.stackTrail?.[lastItemIndex] === frame &&
@@ -1,3 +1,3 @@
1
- import type { StackTrail } from '../context/StackTrail.js';
2
- export declare const tracer: <T>(stackTrail: StackTrail, token: string | string[], fn: () => T) => T;
1
+ import type { StackTrail, TraceOptions } from '../context/StackTrail.js';
2
+ export declare const tracer: <T>(stackTrail: StackTrail, token: string | string[], fn: () => T, options?: TraceOptions) => T;
3
3
  //# sourceMappingURL=tracer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tracer.d.ts","sourceRoot":"","sources":["../../src/helpers/tracer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,eAAO,MAAM,MAAM,GAAI,CAAC,cACV,UAAU,SACf,MAAM,GAAG,MAAM,EAAE,MACpB,MAAM,CAAC,MASZ,CAAA"}
1
+ {"version":3,"file":"tracer.d.ts","sourceRoot":"","sources":["../../src/helpers/tracer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAExE,eAAO,MAAM,MAAM,GAAI,CAAC,cACV,UAAU,SACf,MAAM,GAAG,MAAM,EAAE,MACpB,MAAM,CAAC,YACD,YAAY,MASvB,CAAA"}
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tracer = void 0;
4
- const tracer = (stackTrail, token, fn) => {
5
- stackTrail.append(token);
4
+ const tracer = (stackTrail, token, fn, options) => {
5
+ stackTrail.append(token, options);
6
6
  const result = fn();
7
7
  stackTrail.remove(token);
8
8
  return result;
@@ -1 +1 @@
1
- {"version":3,"file":"toComponentsV3.d.ts","sourceRoot":"","sources":["../../../src/oas/components/toComponentsV3.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAGjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAI/C,KAAK,kBAAkB,GAAG;IACxB,UAAU,EAAE,SAAS,CAAC,gBAAgB,GAAG,SAAS,CAAA;IAClD,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,cAAc,4BAGxB,kBAAkB,KAAG,aAAa,GAAG,SAgCvC,CAAA"}
1
+ {"version":3,"file":"toComponentsV3.d.ts","sourceRoot":"","sources":["../../../src/oas/components/toComponentsV3.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAGjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAI/C,KAAK,kBAAkB,GAAG;IACxB,UAAU,EAAE,SAAS,CAAC,gBAAgB,GAAG,SAAS,CAAA;IAClD,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,cAAc,4BAGxB,kBAAkB,KAAG,aAAa,GAAG,SAsDvC,CAAA"}
@@ -16,20 +16,33 @@ const toComponentsV3 = ({ components, context }) => {
16
16
  const { schemas, responses, parameters, examples, requestBodies, headers, ...skipped } = components;
17
17
  const extensionFields = (0, toSpecificationExtensionsV3_js_1.toSpecificationExtensionsV3)({ skipped, context });
18
18
  const fields = {
19
- schemas: context.trace('schemas', () => (0, toSchemasV3_js_1.toOptionalSchemasV3)({ schemas, context })),
20
- responses: context.trace('responses', () => (0, toResponseV3_js_1.toOptionalResponsesV3)({ responses, context })),
19
+ schemas: context.trace('schemas', () => (0, toSchemasV3_js_1.toOptionalSchemasV3)({ schemas, context }), {
20
+ checkCycles: true
21
+ }),
22
+ responses: context.trace('responses', () => (0, toResponseV3_js_1.toOptionalResponsesV3)({ responses, context }), {
23
+ checkCycles: true
24
+ }),
21
25
  parameters: context.trace('parameters', () => (0, toParameterV3_js_1.toOptionalParametersV3)({
22
26
  parameters,
23
27
  context
24
- })),
28
+ }), {
29
+ checkCycles: true
30
+ }),
25
31
  examples: (0, toExamplesV3_js_1.toExamplesV3)({
26
32
  examples,
27
33
  example: undefined,
28
34
  exampleKey: 'TEMP',
29
- context
35
+ context,
36
+ options: {
37
+ checkCycles: true
38
+ }
39
+ }),
40
+ requestBodies: context.trace('requestBodies', () => (0, toRequestBodiesV3_js_1.toRequestBodiesV3)({ requestBodies, context }), {
41
+ checkCycles: true
42
+ }),
43
+ headers: context.trace('headers', () => (0, toHeadersV3_js_1.toHeadersV3)({ headers, context }), {
44
+ checkCycles: true
30
45
  }),
31
- requestBodies: context.trace('requestBodies', () => (0, toRequestBodiesV3_js_1.toRequestBodiesV3)({ requestBodies, context })),
32
- headers: context.trace('headers', () => (0, toHeadersV3_js_1.toHeadersV3)({ headers, context })),
33
46
  extensionFields
34
47
  };
35
48
  return new Components_js_1.OasComponents(fields);
@@ -2,6 +2,7 @@ import type { ParseContext } from '../../context/ParseContext.js';
2
2
  import type { OpenAPIV3 } from 'openapi-types';
3
3
  import { OasExample } from './Example.js';
4
4
  import type { OasRef } from '../ref/Ref.js';
5
+ import type { TraceOptions } from '../../context/StackTrail.js';
5
6
  type ToExampleSimpleV3Args = {
6
7
  example: unknown;
7
8
  };
@@ -11,8 +12,9 @@ export type ToExamplesV3Args = {
11
12
  examples: Record<string, OpenAPIV3.ExampleObject | OpenAPIV3.ReferenceObject> | undefined;
12
13
  exampleKey: string;
13
14
  context: ParseContext;
15
+ options?: TraceOptions;
14
16
  };
15
- export declare const toExamplesV3: ({ example, examples, exampleKey, context }: ToExamplesV3Args) => Record<string, OasExample | OasRef<"example">> | undefined;
17
+ export declare const toExamplesV3: ({ example, examples, exampleKey, context, options }: ToExamplesV3Args) => Record<string, OasExample | OasRef<"example">> | undefined;
16
18
  type ToExampleV3Args = {
17
19
  example: OpenAPIV3.ExampleObject | OpenAPIV3.ReferenceObject;
18
20
  context: ParseContext;
@@ -1 +1 @@
1
- {"version":3,"file":"toExamplesV3.d.ts","sourceRoot":"","sources":["../../../src/oas/example/toExamplesV3.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAG9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAG3C,KAAK,qBAAqB,GAAG;IAC3B,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,iBAAiB,gBAE3B,qBAAqB,KAAG,UAAU,GAAG,MAAM,CAAC,SAAS,CAQvD,CAAA;AAED,MAAM,M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,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,aAAa,GAAG,SAAS,CAAC,eAAe,CAAC,GAAG,SAAS,CAAA;IACzF,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,YAAY,CAAA;IACrB,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,YAAY,wDAMtB,gBAAgB,KAAG,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,SA0BtE,CAAA;AAED,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,SAAS,CAAC,aAAa,GAAG,SAAS,CAAC,eAAe,CAAA;IAC5D,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,WAAW,yBAGrB,eAAe,KAAG,UAAU,GAAG,MAAM,CAAC,SAAS,CAejD,CAAA"}
@@ -14,13 +14,13 @@ const toExampleSimpleV3 = ({ example }) => {
14
14
  return new Example_js_1.OasExample(fields);
15
15
  };
16
16
  exports.toExampleSimpleV3 = toExampleSimpleV3;
17
- const toExamplesV3 = ({ example, examples, exampleKey, context }) => {
17
+ const toExamplesV3 = ({ example, examples, exampleKey, context, options }) => {
18
18
  if (example && examples) {
19
19
  context.logger.warn(`Both example and examples are defined for ${exampleKey}`);
20
20
  }
21
21
  if (example) {
22
22
  return {
23
- [exampleKey]: context.trace('example', () => (0, exports.toExampleSimpleV3)({ example }))
23
+ [exampleKey]: context.trace('example', () => (0, exports.toExampleSimpleV3)({ example }), options)
24
24
  };
25
25
  }
26
26
  if (examples) {
@@ -28,7 +28,7 @@ const toExamplesV3 = ({ example, examples, exampleKey, context }) => {
28
28
  return Object.fromEntries(Object.entries(examples).map(([key, value]) => {
29
29
  return [key, context.trace(key, () => (0, exports.toExampleV3)({ example: value, context }))];
30
30
  }));
31
- });
31
+ }, options);
32
32
  }
33
33
  return undefined;
34
34
  };