@skmtc/core 0.58.3 → 0.58.5

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 (39) hide show
  1. package/esm/context/BuiltOnRead.d.ts +37 -0
  2. package/esm/context/BuiltOnRead.js +199 -0
  3. package/esm/context/CoreContext.js +11 -5
  4. package/esm/context/GenerateContext.d.ts +3 -0
  5. package/esm/context/GenerateContext.js +48 -5
  6. package/esm/context/ParseContext.js +116 -11
  7. package/esm/context/Subject.d.ts +29 -2
  8. package/esm/context/Subject.js +67 -6
  9. package/esm/dsl/model/toModelProjectionBase.d.ts +4 -1
  10. package/esm/oas/document/Document.d.ts +5 -1
  11. package/esm/oas/document/Document.js +10 -1
  12. package/esm/oas/document/documentSource.d.ts +37 -0
  13. package/esm/oas/document/documentSource.js +27 -0
  14. package/esm/parse/v3-0/operation/toOperationsV3.d.ts +14 -0
  15. package/esm/parse/v3-0/operation/toOperationsV3.js +68 -67
  16. package/esm/parse/v3-1/operation/toOperationsV3.d.ts +14 -0
  17. package/esm/parse/v3-1/operation/toOperationsV3.js +68 -67
  18. package/esm/parse/v3-2/operation/toOperationsV3.d.ts +14 -0
  19. package/esm/parse/v3-2/operation/toOperationsV3.js +69 -68
  20. package/package.json +1 -1
  21. package/script/context/BuiltOnRead.d.ts +37 -0
  22. package/script/context/BuiltOnRead.js +203 -0
  23. package/script/context/CoreContext.js +11 -5
  24. package/script/context/GenerateContext.d.ts +3 -0
  25. package/script/context/GenerateContext.js +48 -5
  26. package/script/context/ParseContext.js +116 -11
  27. package/script/context/Subject.d.ts +29 -2
  28. package/script/context/Subject.js +67 -6
  29. package/script/dsl/model/toModelProjectionBase.d.ts +4 -1
  30. package/script/oas/document/Document.d.ts +5 -1
  31. package/script/oas/document/Document.js +10 -1
  32. package/script/oas/document/documentSource.d.ts +37 -0
  33. package/script/oas/document/documentSource.js +36 -0
  34. package/script/parse/v3-0/operation/toOperationsV3.d.ts +14 -0
  35. package/script/parse/v3-0/operation/toOperationsV3.js +71 -69
  36. package/script/parse/v3-1/operation/toOperationsV3.d.ts +14 -0
  37. package/script/parse/v3-1/operation/toOperationsV3.js +71 -69
  38. package/script/parse/v3-2/operation/toOperationsV3.d.ts +14 -0
  39. package/script/parse/v3-2/operation/toOperationsV3.js +72 -70
@@ -8,8 +8,10 @@ import type { OasWebhook } from '../oas/webhook/Webhook.js';
8
8
  import type { GqlOperation } from '../gql/operation/GqlOperation.js';
9
9
  import type { DeclaredProjection } from '../dsl/DeclaredProjection.js';
10
10
  import type { Reach } from '../parse/Reach.js';
11
+ import type { OperationPlace } from '../oas/document/documentSource.js';
11
12
  import { type RefParts } from '../helpers/refFns.js';
12
13
  import type { RefName } from '../types/RefName.js';
14
+ import type { Method } from '../types/Method.js';
13
15
  import type { IncludeModelRefs, IncludePaths, SkipModelRefs, SkipPaths } from '../types/Settings.js';
14
16
  import type { GqlOperationSource, ModelSource, OasOperationSource, PreviewModule, WebhookSource } from '../types/Preview.js';
15
17
  /** A generator entry, the run's context and one variant: what a subject is asked with. */
@@ -71,14 +73,39 @@ export type Subject<Entry, Filter> = PlannedSubject & {
71
73
  toPreviewModule: (args: AskArgs<Entry>) => PreviewModule | undefined;
72
74
  toSource(args: ToSourceArgs): OasOperationSource | WebhookSource | GqlOperationSource | ModelSource;
73
75
  };
74
- /** An OpenAPI operation as a subject. Its results and enrichments are at `[path][method]`. */
76
+ /** What builds an operation again from its place, and lets it go. */
77
+ export type OperationLoader = {
78
+ load(place: OperationPlace): OasOperation;
79
+ letGo(place: OperationPlace): void;
80
+ };
81
+ /**
82
+ * An OpenAPI operation as a subject. Its results and enrichments are at `[path][method]`.
83
+ *
84
+ * It holds the operation it is constructed with. In a run that builds
85
+ * operations on read, it lets that one go once the file plan is built. In
86
+ * its step, the first read builds its operation through the document, and
87
+ * it lets the operation go when the step has run.
88
+ */
75
89
  export declare class OasOperationSubject implements Subject<OasOperationEntry, IncludePaths | SkipPaths> {
90
+ #private;
76
91
  readonly type = "oasOperation";
77
- operation: OasOperation;
92
+ readonly path: string;
93
+ readonly method: Method;
78
94
  trail: string[];
79
95
  enrichmentPath: string[];
80
96
  label: string;
81
97
  constructor(operation: OasOperation);
98
+ /**
99
+ * Its operation. In a run that builds operations on read, only while its
100
+ * step runs: the first read in the step builds it.
101
+ */
102
+ get operation(): OasOperation;
103
+ /** Lets go of the operation it was constructed with: from now on, `loader` gives it. */
104
+ buildOnRead(loader: OperationLoader): void;
105
+ /** Its step starts. A step that never reads its operation, such as one with no generator, builds none. */
106
+ startStep(): void;
107
+ /** Its step has run: it lets go of the operation the step built. */
108
+ finishStep(): void;
82
109
  isSupported({ entry, context, variant }: AskArgs<OasOperationEntry>): boolean;
83
110
  matches(filter: IncludePaths | SkipPaths | undefined, variant: string): boolean;
84
111
  transform({ entry, context, variant }: AskArgs<OasOperationEntry>): void;
@@ -1,5 +1,24 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _OasOperationSubject_operation, _OasOperationSubject_loader, _OasOperationSubject_inStep;
1
13
  import { toModelKey } from '../helpers/refFns.js';
2
- /** An OpenAPI operation as a subject. Its results and enrichments are at `[path][method]`. */
14
+ /**
15
+ * An OpenAPI operation as a subject. Its results and enrichments are at `[path][method]`.
16
+ *
17
+ * It holds the operation it is constructed with. In a run that builds
18
+ * operations on read, it lets that one go once the file plan is built. In
19
+ * its step, the first read builds its operation through the document, and
20
+ * it lets the operation go when the step has run.
21
+ */
3
22
  export class OasOperationSubject {
4
23
  constructor(operation) {
5
24
  Object.defineProperty(this, "type", {
@@ -8,7 +27,13 @@ export class OasOperationSubject {
8
27
  writable: true,
9
28
  value: 'oasOperation'
10
29
  });
11
- Object.defineProperty(this, "operation", {
30
+ Object.defineProperty(this, "path", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
36
+ Object.defineProperty(this, "method", {
12
37
  enumerable: true,
13
38
  configurable: true,
14
39
  writable: true,
@@ -32,18 +57,53 @@ export class OasOperationSubject {
32
57
  writable: true,
33
58
  value: void 0
34
59
  });
35
- this.operation = operation;
60
+ _OasOperationSubject_operation.set(this, void 0);
61
+ _OasOperationSubject_loader.set(this, void 0);
62
+ /** Whether its step runs now. */
63
+ _OasOperationSubject_inStep.set(this, false);
64
+ __classPrivateFieldSet(this, _OasOperationSubject_operation, operation, "f");
65
+ this.path = operation.path;
66
+ this.method = operation.method;
36
67
  this.trail = [operation.path, operation.method];
37
68
  this.enrichmentPath = this.trail;
38
69
  this.label = `${operation.method.toUpperCase()} ${operation.path}`;
39
70
  }
71
+ /**
72
+ * Its operation. In a run that builds operations on read, only while its
73
+ * step runs: the first read in the step builds it.
74
+ */
75
+ get operation() {
76
+ if (__classPrivateFieldGet(this, _OasOperationSubject_operation, "f") === undefined && __classPrivateFieldGet(this, _OasOperationSubject_inStep, "f") && __classPrivateFieldGet(this, _OasOperationSubject_loader, "f") !== undefined) {
77
+ __classPrivateFieldSet(this, _OasOperationSubject_operation, __classPrivateFieldGet(this, _OasOperationSubject_loader, "f").load(this), "f");
78
+ }
79
+ if (__classPrivateFieldGet(this, _OasOperationSubject_operation, "f") === undefined) {
80
+ throw new Error(`The operation of ${this.label} is read outside its step, after it was let go`);
81
+ }
82
+ return __classPrivateFieldGet(this, _OasOperationSubject_operation, "f");
83
+ }
84
+ /** Lets go of the operation it was constructed with: from now on, `loader` gives it. */
85
+ buildOnRead(loader) {
86
+ __classPrivateFieldSet(this, _OasOperationSubject_loader, loader, "f");
87
+ __classPrivateFieldSet(this, _OasOperationSubject_operation, undefined, "f");
88
+ }
89
+ /** Its step starts. A step that never reads its operation, such as one with no generator, builds none. */
90
+ startStep() {
91
+ __classPrivateFieldSet(this, _OasOperationSubject_inStep, true, "f");
92
+ }
93
+ /** Its step has run: it lets go of the operation the step built. */
94
+ finishStep() {
95
+ __classPrivateFieldSet(this, _OasOperationSubject_inStep, false, "f");
96
+ if (__classPrivateFieldGet(this, _OasOperationSubject_loader, "f") !== undefined) {
97
+ __classPrivateFieldGet(this, _OasOperationSubject_loader, "f").letGo(this);
98
+ __classPrivateFieldSet(this, _OasOperationSubject_operation, undefined, "f");
99
+ }
100
+ }
40
101
  isSupported({ entry, context, variant }) {
41
102
  return (typeof entry.isSupported !== 'function' ||
42
103
  entry.isSupported({ operation: this.operation, context, variant }));
43
104
  }
44
105
  matches(filter, variant) {
45
- const { path, method } = this.operation;
46
- return matchesPathFilter({ paths: filter, path, method, variant });
106
+ return matchesPathFilter({ paths: filter, path: this.path, method: this.method, variant });
47
107
  }
48
108
  transform({ entry, context, variant }) {
49
109
  entry.transform({ context, operation: this.operation, variant });
@@ -59,12 +119,13 @@ export class OasOperationSubject {
59
119
  return projection.toExportPath({ operation: this.operation, enrichments, variant });
60
120
  }
61
121
  toNamedModels(reach) {
62
- return reach.namedByOperation(this.operation);
122
+ return reach.namedByOperation(this);
63
123
  }
64
124
  toSource({ generatorId, variant }) {
65
125
  return toOasOperationSource({ operation: this.operation, generatorId, variant });
66
126
  }
67
127
  }
128
+ _OasOperationSubject_operation = new WeakMap(), _OasOperationSubject_loader = new WeakMap(), _OasOperationSubject_inStep = new WeakMap();
68
129
  /**
69
130
  * A 3.1 webhook as a subject. Its results are at `['webhook'][name][method]`
70
131
  * and its enrichments at `[name][method]`. A filter has the shape of an
@@ -44,7 +44,10 @@ type ToEnrichmentsArgs = {
44
44
  */
45
45
  export type ModelProjectionBaseConfig<EnrichmentType = undefined, IdType extends IdentifierType = IdentifierType, ProjectionOptions = undefined> = {
46
46
  id: string;
47
- /** Pure: the cache-key name (the cache-check path runs this). */
47
+ /**
48
+ * Pure: the cache-key name. With no projection options,
49
+ * `toModelContentSettings` asks for it once in a run and keeps it.
50
+ */
48
51
  toIdentifierName: (args: ToModelIdentifierNameArgs<EnrichmentType, ProjectionOptions>) => string;
49
52
  /**
50
53
  * Context-aware, overridable: the non-`name` parts of the identifier
@@ -231,7 +231,11 @@ export declare class OasDocument {
231
231
  /** API metadata */
232
232
  get info(): OasInfo;
233
233
  get servers(): OasServer[] | undefined;
234
- /** List of all operations for the API */
234
+ /**
235
+ * List of all operations for the API. In a run with `onArtifact` the parsed
236
+ * operations are let go once the file plan is built; the first time they
237
+ * are listed after that, each is built again and kept.
238
+ */
235
239
  get operations(): OasOperation[];
236
240
  /** List of all 3.1 webhooks for the API (kept separate from operations) */
237
241
  get webhooks(): OasWebhook[];
@@ -11,6 +11,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
11
11
  };
12
12
  var _OasDocument_fields, _OasDocument_refTargets;
13
13
  import "../../_dnt.polyfills.js";
14
+ import { takeUnlistedOperations } from './documentSource.js';
14
15
  /**
15
16
  * Represents a complete OpenAPI v3 document in the SKMTC OAS processing system.
16
17
  *
@@ -289,11 +290,19 @@ export class OasDocument {
289
290
  }
290
291
  return __classPrivateFieldGet(this, _OasDocument_fields, "f").servers;
291
292
  }
292
- /** List of all operations for the API */
293
+ /**
294
+ * List of all operations for the API. In a run with `onArtifact` the parsed
295
+ * operations are let go once the file plan is built; the first time they
296
+ * are listed after that, each is built again and kept.
297
+ */
293
298
  get operations() {
294
299
  if (!__classPrivateFieldGet(this, _OasDocument_fields, "f")) {
295
300
  throw new Error(`Accessing 'operations' before fields are set`);
296
301
  }
302
+ const list = takeUnlistedOperations(this);
303
+ if (list !== undefined) {
304
+ __classPrivateFieldGet(this, _OasDocument_fields, "f").operations = list();
305
+ }
297
306
  return __classPrivateFieldGet(this, _OasDocument_fields, "f").operations;
298
307
  }
299
308
  /** List of all 3.1 webhooks for the API (kept separate from operations) */
@@ -0,0 +1,37 @@
1
+ /**
2
+ * A document whose operations and component schemas are built again when a
3
+ * generator reads them, in a run with `onArtifact`. Internal: `mod.ts` does
4
+ * not list this file.
5
+ */
6
+ import type { OasDocument } from './Document.js';
7
+ import type { OasOperation } from '../operation/Operation.js';
8
+ import type { OasSchema } from '../schema/Schema.js';
9
+ import type { OasRef } from '../ref/Ref.js';
10
+ import type { Method } from '../../types/Method.js';
11
+ import type { RefName } from '../../types/RefName.js';
12
+ /** Where an operation is in a document. An `OasOperation` fits it. */
13
+ export type OperationPlace = {
14
+ path: string;
15
+ method: Method;
16
+ };
17
+ /**
18
+ * How the parse context that parsed a document builds one of its operations
19
+ * or component schemas again from the input document. A rebuild records no
20
+ * issue and no ref.
21
+ */
22
+ export type DocumentSource = {
23
+ toOperation(place: OperationPlace): OasOperation;
24
+ toSchema(name: RefName): OasSchema | OasRef<'schema'>;
25
+ };
26
+ /** Marks a parse context, before it parses, as one of a run that gives files early. */
27
+ export declare const markPlannedParse: (parseContext: object) => void;
28
+ /** Whether `markPlannedParse` marked the parse context. */
29
+ export declare const isPlannedParse: (parseContext: object) => boolean;
30
+ /** Keeps how the parse context builds the parts of `document` again. */
31
+ export declare const setDocumentSource: (document: OasDocument, source: DocumentSource) => void;
32
+ /** How the parts of `document` are built again, or `undefined` when its run builds nothing again. */
33
+ export declare const toDocumentSource: (document: OasDocument) => DocumentSource | undefined;
34
+ /** `document` has let its parsed operations go: `list` builds every one, the first time they are listed. */
35
+ export declare const setUnlistedOperations: (document: OasDocument, list: () => OasOperation[]) => void;
36
+ /** How to list the operations of `document` that were let go, once: after that they are listed. */
37
+ export declare const takeUnlistedOperations: (document: OasDocument) => (() => OasOperation[]) | undefined;
@@ -0,0 +1,27 @@
1
+ const sources = new WeakMap();
2
+ /** The parse contexts of runs that give files early, whose documents are built on read. */
3
+ const plannedParses = new WeakSet();
4
+ /** Marks a parse context, before it parses, as one of a run that gives files early. */
5
+ export const markPlannedParse = (parseContext) => {
6
+ plannedParses.add(parseContext);
7
+ };
8
+ /** Whether `markPlannedParse` marked the parse context. */
9
+ export const isPlannedParse = (parseContext) => plannedParses.has(parseContext);
10
+ /** Each document whose parsed operations were let go, and how to list them all again. */
11
+ const unlistedOperations = new WeakMap();
12
+ /** Keeps how the parse context builds the parts of `document` again. */
13
+ export const setDocumentSource = (document, source) => {
14
+ sources.set(document, source);
15
+ };
16
+ /** How the parts of `document` are built again, or `undefined` when its run builds nothing again. */
17
+ export const toDocumentSource = (document) => sources.get(document);
18
+ /** `document` has let its parsed operations go: `list` builds every one, the first time they are listed. */
19
+ export const setUnlistedOperations = (document, list) => {
20
+ unlistedOperations.set(document, list);
21
+ };
22
+ /** How to list the operations of `document` that were let go, once: after that they are listed. */
23
+ export const takeUnlistedOperations = (document) => {
24
+ const list = unlistedOperations.get(document);
25
+ unlistedOperations.delete(document);
26
+ return list;
27
+ };
@@ -22,4 +22,18 @@ export type ToOperationsV3Args = {
22
22
  context: ParseContextType;
23
23
  };
24
24
  export declare const toOperationsV3: ({ paths, stackTrail, context }: ToOperationsV3Args) => OasOperation[];
25
+ export type ToPathOperationsV3Args = {
26
+ path: string;
27
+ pathItem: OpenAPIV3.PathItemObject;
28
+ /** The trail of the path item, with `path` already pushed. */
29
+ stackTrail: StackTrail;
30
+ context: ParseContextType;
31
+ /** Parses only the operation at this method. */
32
+ method?: Method;
33
+ };
34
+ /**
35
+ * The operations of the path item at `path`. They share one parsed path
36
+ * item. With `method`, only the operation at that method is parsed.
37
+ */
38
+ export declare const toPathOperationsV3: ({ path, pathItem, stackTrail: pathStack, context, method: only }: ToPathOperationsV3Args) => OasOperation[];
25
39
  export {};
@@ -49,74 +49,75 @@ export const toOperationV3 = ({ operation, operationInfo, stackTrail, context })
49
49
  }, context));
50
50
  };
51
51
  export const toOperationsV3 = ({ paths, stackTrail, context }) => {
52
- return Object.entries(paths).flatMap(([path, pathItem]) => {
53
- return stackTrail.trace(path, pathStack => {
54
- if (!pathItem) {
55
- return [];
56
- }
57
- const cleaned = Object.entries(pathItem).reduce(({ rest, methodObject }, [key, operation]) => {
58
- const method = toPathItemMethod(key);
59
- if (method) {
60
- const { [method]: _deleted, ...remaining } = rest;
61
- return {
62
- rest: remaining,
63
- methodObject: {
64
- ...methodObject,
65
- [method]: operation
66
- }
67
- };
52
+ return Object.entries(paths).flatMap(([path, pathItem]) => stackTrail.trace(path, pathStack => pathItem ? toPathOperationsV3({ path, pathItem, stackTrail: pathStack, context }) : []));
53
+ };
54
+ /**
55
+ * The operations of the path item at `path`. They share one parsed path
56
+ * item. With `method`, only the operation at that method is parsed.
57
+ */
58
+ export const toPathOperationsV3 = ({ path, pathItem, stackTrail: pathStack, context, method: only }) => {
59
+ const cleaned = Object.entries(pathItem).reduce(({ rest, methodObject }, [key, operation]) => {
60
+ const method = toPathItemMethod(key);
61
+ if (method) {
62
+ const { [method]: _deleted, ...remaining } = rest;
63
+ return {
64
+ rest: remaining,
65
+ methodObject: {
66
+ ...methodObject,
67
+ [method]: operation
68
68
  }
69
- return { rest, methodObject };
70
- }, {
71
- rest: pathItem,
72
- methodObject: {}
73
- });
74
- const pathItemResult = !isEmpty(cleaned.rest)
75
- ? toPathItemV3({ pathItem: cleaned.rest, stackTrail: pathStack, context })
76
- : undefined;
77
- const pathItemObject = pathItemResult?.pathItem;
78
- const brokenParameters = pathItemResult?.brokenParameters ?? [];
79
- return Object.entries(cleaned.methodObject)
80
- .map(([method, operation]) => {
81
- // Use `pathStack` (the trail with `path` already pushed),
82
- // not the outer `stackTrail` — otherwise downstream traces
83
- // record paths:<method>:... and lose the actual path
84
- // segment, which breaks `OasDocument.removeItem` and the
85
- // dependency-ref invalidation it backs.
86
- return pathStack.trace(method, st => {
87
- if (!operation) {
88
- return;
89
- }
90
- if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
91
- return undefined;
92
- }
93
- try {
94
- return toOperationV3({
95
- operation,
96
- operationInfo: {
97
- method: method,
98
- path,
99
- pathItem: pathItemObject
100
- },
101
- stackTrail: st,
102
- context
103
- });
104
- }
105
- catch (error) {
106
- const normalized = error instanceof Error ? error : new Error(String(error));
107
- context.logIssueNoKey({
108
- parent: operation,
109
- level: 'error',
110
- message: normalized.message,
111
- cause: normalized,
112
- stackTrail: st,
113
- type: 'INVALID_OPERATION'
114
- });
115
- return undefined;
116
- }
69
+ };
70
+ }
71
+ return { rest, methodObject };
72
+ }, {
73
+ rest: pathItem,
74
+ methodObject: {}
75
+ });
76
+ const pathItemResult = !isEmpty(cleaned.rest)
77
+ ? toPathItemV3({ pathItem: cleaned.rest, stackTrail: pathStack, context })
78
+ : undefined;
79
+ const pathItemObject = pathItemResult?.pathItem;
80
+ const brokenParameters = pathItemResult?.brokenParameters ?? [];
81
+ return Object.entries(cleaned.methodObject)
82
+ .filter(([method]) => only === undefined || method === only)
83
+ .map(([method, operation]) => {
84
+ // Use `pathStack` (the trail with `path` already pushed),
85
+ // not the outer `stackTrail` — otherwise downstream traces
86
+ // record paths:<method>:... and lose the actual path
87
+ // segment, which breaks `OasDocument.removeItem` and the
88
+ // dependency-ref invalidation it backs.
89
+ return pathStack.trace(method, st => {
90
+ if (!operation) {
91
+ return;
92
+ }
93
+ if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
94
+ return undefined;
95
+ }
96
+ try {
97
+ return toOperationV3({
98
+ operation,
99
+ operationInfo: {
100
+ method: method,
101
+ path,
102
+ pathItem: pathItemObject
103
+ },
104
+ stackTrail: st,
105
+ context
117
106
  });
118
- })
119
- .filter((item) => Boolean(item));
107
+ }
108
+ catch (error) {
109
+ const normalized = error instanceof Error ? error : new Error(String(error));
110
+ context.logIssueNoKey({
111
+ parent: operation,
112
+ level: 'error',
113
+ message: normalized.message,
114
+ cause: normalized,
115
+ stackTrail: st,
116
+ type: 'INVALID_OPERATION'
117
+ });
118
+ return undefined;
119
+ }
120
120
  });
121
- });
121
+ })
122
+ .filter((item) => Boolean(item));
122
123
  };
@@ -22,4 +22,18 @@ export type ToOperationsV3Args = {
22
22
  context: ParseContextType;
23
23
  };
24
24
  export declare const toOperationsV3: ({ paths, stackTrail, context }: ToOperationsV3Args) => OasOperation[];
25
+ export type ToPathOperationsV3Args = {
26
+ path: string;
27
+ pathItem: OpenAPIV3.PathItemObject;
28
+ /** The trail of the path item, with `path` already pushed. */
29
+ stackTrail: StackTrail;
30
+ context: ParseContextType;
31
+ /** Parses only the operation at this method. */
32
+ method?: Method;
33
+ };
34
+ /**
35
+ * The operations of the path item at `path`. They share one parsed path
36
+ * item. With `method`, only the operation at that method is parsed.
37
+ */
38
+ export declare const toPathOperationsV3: ({ path, pathItem, stackTrail: pathStack, context, method: only }: ToPathOperationsV3Args) => OasOperation[];
25
39
  export {};
@@ -52,74 +52,75 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
52
52
  if (!paths) {
53
53
  return [];
54
54
  }
55
- return Object.entries(paths).flatMap(([path, pathItem]) => {
56
- return stackTrail.trace(path, pathStack => {
57
- if (!pathItem) {
58
- return [];
59
- }
60
- const cleaned = Object.entries(pathItem).reduce(({ rest, methodObject }, [key, operation]) => {
61
- const method = toPathItemMethod(key);
62
- if (method) {
63
- const { [method]: _deleted, ...remaining } = rest;
64
- return {
65
- rest: remaining,
66
- methodObject: {
67
- ...methodObject,
68
- [method]: operation
69
- }
70
- };
55
+ return Object.entries(paths).flatMap(([path, pathItem]) => stackTrail.trace(path, pathStack => pathItem ? toPathOperationsV3({ path, pathItem, stackTrail: pathStack, context }) : []));
56
+ };
57
+ /**
58
+ * The operations of the path item at `path`. They share one parsed path
59
+ * item. With `method`, only the operation at that method is parsed.
60
+ */
61
+ export const toPathOperationsV3 = ({ path, pathItem, stackTrail: pathStack, context, method: only }) => {
62
+ const cleaned = Object.entries(pathItem).reduce(({ rest, methodObject }, [key, operation]) => {
63
+ const method = toPathItemMethod(key);
64
+ if (method) {
65
+ const { [method]: _deleted, ...remaining } = rest;
66
+ return {
67
+ rest: remaining,
68
+ methodObject: {
69
+ ...methodObject,
70
+ [method]: operation
71
71
  }
72
- return { rest, methodObject };
73
- }, {
74
- rest: pathItem,
75
- methodObject: {}
76
- });
77
- const pathItemResult = !isEmpty(cleaned.rest)
78
- ? toPathItemV3({ pathItem: cleaned.rest, stackTrail: pathStack, context })
79
- : undefined;
80
- const pathItemObject = pathItemResult?.pathItem;
81
- const brokenParameters = pathItemResult?.brokenParameters ?? [];
82
- return Object.entries(cleaned.methodObject)
83
- .map(([method, operation]) => {
84
- // Use `pathStack` (the trail with `path` already pushed),
85
- // not the outer `stackTrail` — otherwise downstream traces
86
- // record paths:<method>:... and lose the actual path
87
- // segment, which breaks `OasDocument.removeItem` and the
88
- // dependency-ref invalidation it backs.
89
- return pathStack.trace(method, st => {
90
- if (!operation) {
91
- return;
92
- }
93
- if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
94
- return undefined;
95
- }
96
- try {
97
- return toOperationV3({
98
- operation,
99
- operationInfo: {
100
- method: method,
101
- path,
102
- pathItem: pathItemObject
103
- },
104
- stackTrail: st,
105
- context
106
- });
107
- }
108
- catch (error) {
109
- const normalized = error instanceof Error ? error : new Error(String(error));
110
- context.logIssueNoKey({
111
- parent: operation,
112
- level: 'error',
113
- message: normalized.message,
114
- cause: normalized,
115
- stackTrail: st,
116
- type: 'INVALID_OPERATION'
117
- });
118
- return undefined;
119
- }
72
+ };
73
+ }
74
+ return { rest, methodObject };
75
+ }, {
76
+ rest: pathItem,
77
+ methodObject: {}
78
+ });
79
+ const pathItemResult = !isEmpty(cleaned.rest)
80
+ ? toPathItemV3({ pathItem: cleaned.rest, stackTrail: pathStack, context })
81
+ : undefined;
82
+ const pathItemObject = pathItemResult?.pathItem;
83
+ const brokenParameters = pathItemResult?.brokenParameters ?? [];
84
+ return Object.entries(cleaned.methodObject)
85
+ .filter(([method]) => only === undefined || method === only)
86
+ .map(([method, operation]) => {
87
+ // Use `pathStack` (the trail with `path` already pushed),
88
+ // not the outer `stackTrail` — otherwise downstream traces
89
+ // record paths:<method>:... and lose the actual path
90
+ // segment, which breaks `OasDocument.removeItem` and the
91
+ // dependency-ref invalidation it backs.
92
+ return pathStack.trace(method, st => {
93
+ if (!operation) {
94
+ return;
95
+ }
96
+ if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
97
+ return undefined;
98
+ }
99
+ try {
100
+ return toOperationV3({
101
+ operation,
102
+ operationInfo: {
103
+ method: method,
104
+ path,
105
+ pathItem: pathItemObject
106
+ },
107
+ stackTrail: st,
108
+ context
120
109
  });
121
- })
122
- .filter((item) => Boolean(item));
110
+ }
111
+ catch (error) {
112
+ const normalized = error instanceof Error ? error : new Error(String(error));
113
+ context.logIssueNoKey({
114
+ parent: operation,
115
+ level: 'error',
116
+ message: normalized.message,
117
+ cause: normalized,
118
+ stackTrail: st,
119
+ type: 'INVALID_OPERATION'
120
+ });
121
+ return undefined;
122
+ }
123
123
  });
124
- });
124
+ })
125
+ .filter((item) => Boolean(item));
125
126
  };
@@ -22,4 +22,18 @@ export type ToOperationsV3Args = {
22
22
  context: ParseContextType;
23
23
  };
24
24
  export declare const toOperationsV3: ({ paths, stackTrail, context }: ToOperationsV3Args) => OasOperation[];
25
+ export type ToPathOperationsV3Args = {
26
+ path: string;
27
+ pathItem: OpenAPIV3.PathItemObject;
28
+ /** The trail of the path item, with `path` already pushed. */
29
+ stackTrail: StackTrail;
30
+ context: ParseContextType;
31
+ /** Parses only the operation at this method. */
32
+ method?: Method;
33
+ };
34
+ /**
35
+ * The operations of the path item at `path`. They share one parsed path
36
+ * item. With `method`, only the operation at that method is parsed.
37
+ */
38
+ export declare const toPathOperationsV3: ({ path, pathItem, stackTrail: pathStack, context, method: only }: ToPathOperationsV3Args) => OasOperation[];
25
39
  export {};