@usearazzo/runner 1.0.1-alpha.31 → 1.0.1-alpha.33

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/CHANGELOG.md +27 -0
  2. package/dist/arazzo-runner.browser.js +691 -179
  3. package/dist/arazzo-runner.browser.min.js +1 -1
  4. package/package.json +6 -6
  5. package/src/action/ActionResolver.cjs +13 -12
  6. package/src/action/ActionResolver.mjs +13 -12
  7. package/src/criterion/CriterionEvaluator.cjs +13 -8
  8. package/src/criterion/CriterionEvaluator.mjs +13 -8
  9. package/src/criterion/SimpleCriterionEvaluator.cjs +5 -3
  10. package/src/criterion/SimpleCriterionEvaluator.mjs +6 -4
  11. package/src/executor/OpenAPIOperationExecutor.cjs +13 -6
  12. package/src/executor/OpenAPIOperationExecutor.mjs +14 -7
  13. package/src/executor/OpenAPIOperationLocatorNormalizer.cjs +1 -1
  14. package/src/executor/OpenAPIOperationLocatorNormalizer.mjs +1 -1
  15. package/src/executor/StepExecutor.cjs +19 -14
  16. package/src/executor/StepExecutor.mjs +19 -14
  17. package/src/executor/WorkflowExecutor.cjs +8 -8
  18. package/src/executor/WorkflowExecutor.mjs +8 -8
  19. package/src/expression/RuntimeExpressionEvaluator.cjs +52 -9
  20. package/src/expression/RuntimeExpressionEvaluator.mjs +52 -9
  21. package/src/registry/DocumentRegistry.cjs +35 -8
  22. package/src/registry/DocumentRegistry.mjs +35 -8
  23. package/src/registry/providers/ArazzoDocumentRegistryProvider.cjs +1 -0
  24. package/src/registry/providers/ArazzoDocumentRegistryProvider.mjs +1 -0
  25. package/src/registry/providers/DocumentRegistryProvider.cjs +19 -1
  26. package/src/registry/providers/DocumentRegistryProvider.mjs +19 -1
  27. package/src/registry/providers/OpenAPIDocumentRegistryProvider.cjs +1 -0
  28. package/src/registry/providers/OpenAPIDocumentRegistryProvider.mjs +1 -0
  29. package/src/resolver/ArazzoValueResolver.cjs +6 -3
  30. package/src/resolver/ArazzoValueResolver.mjs +6 -3
  31. package/src/resolver/OpenAPIOperationParameterResolver.cjs +2 -2
  32. package/src/resolver/OpenAPIOperationParameterResolver.mjs +2 -2
  33. package/src/resolver/OutputResolver.cjs +10 -3
  34. package/src/resolver/OutputResolver.mjs +10 -3
  35. package/src/resolver/RequestBodyResolver.cjs +37 -17
  36. package/src/resolver/RequestBodyResolver.mjs +37 -17
  37. package/src/resolver/WorkflowParameterResolver.cjs +2 -2
  38. package/src/resolver/WorkflowParameterResolver.mjs +2 -2
  39. package/types/runner.d.ts +88 -37
package/types/runner.d.ts CHANGED
@@ -66,14 +66,14 @@ export declare class ActionResolver {
66
66
  * `end` its author was reaching for would otherwise never happen without a
67
67
  * word said about why.
68
68
  */
69
- resolveOnSuccess(actions: StepOnSuccessElement | undefined, isCriterionMet: CriterionPredicate, scope: StepScope): SuccessActionElement[];
69
+ resolveOnSuccess(actions: StepOnSuccessElement | undefined, isCriterionMet: CriterionPredicate, scope: StepScope): Promise<SuccessActionElement[]>;
70
70
  /**
71
71
  * Returns every `onFailure` action whose criteria are all met, in list order.
72
72
  *
73
73
  * Same matching and error behavior as {@link ActionResolver.resolveOnSuccess} —
74
74
  * see there for the full rationale — mirrored for the step's other list.
75
75
  */
76
- resolveOnFailure(actions: StepOnFailureElement | undefined, isCriterionMet: CriterionPredicate, scope: StepScope): FailureActionElement[];
76
+ resolveOnFailure(actions: StepOnFailureElement | undefined, isCriterionMet: CriterionPredicate, scope: StepScope): Promise<FailureActionElement[]>;
77
77
  }
78
78
 
79
79
  /**
@@ -163,6 +163,7 @@ export declare class ArazzoDocument extends APIDocument {
163
163
  */
164
164
  export declare class ArazzoDocumentRegistryProvider extends DocumentRegistryProvider {
165
165
  #private;
166
+ readonly sourceDescriptionType = "arazzo";
166
167
  constructor(options?: ArazzoDocumentRegistryProviderOptions);
167
168
  canProvide(uri: string): Promise<boolean>;
168
169
  /**
@@ -347,7 +348,7 @@ export declare abstract class ArazzoValueResolver {
347
348
  /**
348
349
  * Resolves one authored value element by the rule above.
349
350
  */
350
- protected resolveValue(element: unknown, resolve: RuntimeExpressionResolver): unknown;
351
+ protected resolveValue(element: unknown, resolve: RuntimeExpressionResolver): Promise<unknown>;
351
352
  }
352
353
 
353
354
  /**
@@ -498,14 +499,19 @@ export declare interface ContextSource {
498
499
  }
499
500
 
500
501
  /**
501
- * Resolves a runtime expression to a value during criterion evaluation.
502
+ * Resolves a runtime expression to a value, or to a Promise of it, during
503
+ * criterion evaluation. The result is awaited, so a synchronous resolver works
504
+ * too.
502
505
  *
503
506
  * Used both for a criterion's `context` (regex/jsonpath/xpath) and for the
504
507
  * expressions embedded in a `simple` condition. It should resolve leniently —
505
508
  * an unresolvable reference returning `undefined` fails the criterion rather
506
509
  * than throwing (a common way to drive it is
507
510
  * `(expression) => runtimeExpressionEvaluator.evaluate(expression)` with a
508
- * lenient evaluator).
511
+ * lenient evaluator). An error it throws or rejects with — such as the load
512
+ * error of a `$sourceDescriptions` document that cannot be loaded — is not a
513
+ * {@link CriterionEvaluationError}, so it propagates instead of failing the
514
+ * criterion.
509
515
  * @public
510
516
  */
511
517
  export declare type CriterionContextResolver = (expression: string) => unknown;
@@ -665,7 +671,7 @@ export declare class CriterionEvaluator {
665
671
  * the expressions embedded in the condition; for the other types it resolves
666
672
  * the criterion's `context` expression that the condition is applied to.
667
673
  */
668
- evaluate(criterion: CriterionElement, resolve: CriterionContextResolver): CriterionOutcome;
674
+ evaluate(criterion: CriterionElement, resolve: CriterionContextResolver): Promise<CriterionOutcome>;
669
675
  }
670
676
 
671
677
  /**
@@ -713,15 +719,16 @@ export declare interface CriterionOutcome {
713
719
  }
714
720
 
715
721
  /**
716
- * Determines whether a single criterion of an action is met. Receives the
717
- * action declaring the criterion, so a caller can attribute the outcome to it.
722
+ * Determines whether a single criterion of an action is met, or resolves to
723
+ * whether it is. Receives the action declaring the criterion, so a caller can
724
+ * attribute the outcome to it.
718
725
  *
719
726
  * Bridged to a criterion evaluator
720
- * (`(criterion) => criterionEvaluator.evaluate(criterion, resolve).met`); an
721
- * unresolvable/failing criterion is `false`, not an error.
727
+ * (`async (criterion) => (await criterionEvaluator.evaluate(criterion, resolve)).met`);
728
+ * an unresolvable/failing criterion is `false`, not an error.
722
729
  * @public
723
730
  */
724
- export declare type CriterionPredicate = (criterion: CriterionElement, action: SelectedAction) => boolean;
731
+ export declare type CriterionPredicate = (criterion: CriterionElement, action: SelectedAction) => boolean | Promise<boolean>;
725
732
 
726
733
  /** @public */
727
734
  export declare class DocumentLoadError extends ArazzoRunnerError {
@@ -748,20 +755,24 @@ export declare class DocumentRegistry {
748
755
  * otherwise detects the format, loads via the matching provider,
749
756
  * caches, and returns it.
750
757
  *
758
+ * Concurrent calls for a document that is still loading share that one
759
+ * load instead of each fetching and parsing it. A failed load is not
760
+ * remembered: the next call tries again.
761
+ *
751
762
  * @throws DocumentLoadError - When the document cannot be read or loaded
752
763
  * @throws UnmatchedProviderError - When no provider can load the document
753
764
  */
754
765
  acquire(uri: string): Promise<APIDocument>;
755
766
  /**
756
- * Returns an already-loaded document by URI, or undefined if not cached.
767
+ * Whether a source description of `type` can be loaded at all: some provider
768
+ * loads that type, or does not say which type it loads. A source with no
769
+ * `type` may be of any type, so it can.
757
770
  *
758
- * Synchronous counterpart to `acquire`: it never loads a document, only
759
- * returns one the registry already holds, marking it most recently used like
760
- * any other access. Consumers that must resolve a reference without awaiting
761
- * (e.g. runtime expression evaluation) use this; the executor is responsible
762
- * for having acquired the document beforehand.
771
+ * Answered from the providers alone, without fetching anything — so a
772
+ * caller can skip a load that could only fail, such as an AsyncAPI source
773
+ * while no provider loads AsyncAPI.
763
774
  */
764
- get(uri: string): APIDocument | undefined;
775
+ canLoad(type: string | undefined): boolean;
765
776
  /**
766
777
  * Acquires the entry Arazzo document and marks it with `isEntry: true`.
767
778
  * Validates that the document is an Arazzo specification.
@@ -771,6 +782,10 @@ export declare class DocumentRegistry {
771
782
  * @throws InvalidEntryDocumentError - When the document is not an Arazzo document
772
783
  */
773
784
  acquireEntryDocument(uri: string): Promise<ArazzoDocument>;
785
+ /**
786
+ * Drops every cached document. A load still in progress is no longer shared:
787
+ * the next `acquire` of that document starts a fresh load.
788
+ */
774
789
  clear(): void;
775
790
  }
776
791
 
@@ -789,6 +804,15 @@ export declare interface DocumentRegistryOptions {
789
804
  * @public
790
805
  */
791
806
  export declare abstract class DocumentRegistryProvider {
807
+ /**
808
+ * The Source Description Object `type` this provider loads (`openapi`,
809
+ * `arazzo`, …), or `undefined` when it does not say — then it may load a
810
+ * source of any type.
811
+ *
812
+ * Lets the registry tell, without fetching anything, whether a source of a
813
+ * given type can be loaded at all (`DocumentRegistry.canLoad`).
814
+ */
815
+ readonly sourceDescriptionType?: string;
792
816
  /**
793
817
  * Checks if the content at the URI can be handled by this provider.
794
818
  */
@@ -904,7 +928,11 @@ export declare class ExtractionError extends ArazzoRunnerError {
904
928
  * Arazzo outcome judged by a step's `successCriteria`, never an error;
905
929
  * - throw (or reject) only on transport failure — the executor wraps the
906
930
  * error as a `ClientError`;
907
- * - honor `request.signal` when present.
931
+ * - honor `request.signal` when present;
932
+ * - encode a `FormData` body as `multipart/form-data` and set the
933
+ * `Content-Type` with its boundary, as `fetch` does — the executor removes
934
+ * the request's own multipart `Content-Type` for such a body, since only the
935
+ * encoder knows the boundary.
908
936
  *
909
937
  * Response normalization (content-type dispatch, header mapping) happens on
910
938
  * the executor side for every client, so `$response.body` semantics stay
@@ -1123,6 +1151,7 @@ export declare interface OpenAPIDocumentAssemblerOptions {
1123
1151
  */
1124
1152
  export declare class OpenAPIDocumentRegistryProvider extends DocumentRegistryProvider {
1125
1153
  #private;
1154
+ readonly sourceDescriptionType = "openapi";
1126
1155
  constructor(options?: OpenAPIDocumentRegistryProviderOptions);
1127
1156
  canProvide(uri: string): Promise<boolean>;
1128
1157
  /**
@@ -1513,7 +1542,7 @@ export declare class OpenAPIOperationParameterResolver extends StepParameterReso
1513
1542
  *
1514
1543
  * `scope` names the step in a thrown {@link ResolverError}.
1515
1544
  */
1516
- resolve(parameters: StepParametersElement | undefined, resolve: RuntimeExpressionResolver, scope: StepScope): Record<string, unknown>;
1545
+ resolve(parameters: StepParametersElement | undefined, resolve: RuntimeExpressionResolver, scope: StepScope): Promise<Record<string, unknown>>;
1517
1546
  }
1518
1547
 
1519
1548
  /**
@@ -1706,7 +1735,7 @@ export declare class OutputResolver extends ArazzoValueResolver {
1706
1735
  * {@link ResolverError}. An output value that is not a valid runtime
1707
1736
  * expression throws with reason `ResolverError.InvalidExpression`.
1708
1737
  */
1709
- resolve(outputs: StepOutputsElement | WorkflowOutputsElement | undefined, resolve: RuntimeExpressionResolver, scope: ResolverScope): Record<string, unknown>;
1738
+ resolve(outputs: StepOutputsElement | WorkflowOutputsElement | undefined, resolve: RuntimeExpressionResolver, scope: ResolverScope): Promise<Record<string, unknown>>;
1710
1739
  }
1711
1740
 
1712
1741
  /**
@@ -1777,7 +1806,7 @@ export declare class RequestBodyResolver extends ArazzoValueResolver {
1777
1806
  *
1778
1807
  * `scope` names the step in a thrown {@link ResolverError}.
1779
1808
  */
1780
- resolve(requestBody: RequestBodyElement | undefined, resolve: RuntimeExpressionResolver, scope: StepScope): ResolvedRequestBody | undefined;
1809
+ resolve(requestBody: RequestBodyElement | undefined, resolve: RuntimeExpressionResolver, scope: StepScope): Promise<ResolvedRequestBody | undefined>;
1781
1810
  }
1782
1811
 
1783
1812
  /**
@@ -2058,6 +2087,9 @@ export declare type RuntimeExpressionErrorReason = (typeof RuntimeExpressionErro
2058
2087
  * (via the registry) the source name points at. A step reference resolves to
2059
2088
  * the Step Object as authored — a locator, not the step's execution result.
2060
2089
  *
2090
+ * Evaluation is asynchronous because a `$sourceDescriptions` reference may
2091
+ * have to load the document it points at.
2092
+ *
2061
2093
  * A reference resolves to `undefined` when it is absent. Runtime values
2062
2094
  * originate from JSON (or ApiDOM), which cannot represent `undefined` — an
2063
2095
  * absent value is a missing property and an explicit null is `null` — so
@@ -2082,8 +2114,16 @@ export declare class RuntimeExpressionEvaluator {
2082
2114
  * The expression must be the bare form without surrounding braces
2083
2115
  * (e.g. `$inputs.username`, `$response.body#/pets/0/id`). In strict mode an
2084
2116
  * unresolvable reference throws; otherwise it returns `undefined`.
2117
+ *
2118
+ * A `$sourceDescriptions` reference whose document cannot be loaded is not
2119
+ * merely unresolved: unless it names a field of the Source Description Object,
2120
+ * it rejects with the load error in either mode, since nothing else can
2121
+ * produce its value.
2122
+ *
2123
+ * @throws DocumentLoadError - When a referenced source document cannot be read or loaded
2124
+ * @throws UnmatchedProviderError - When no provider can load a referenced source document
2085
2125
  */
2086
- evaluate(expression: string): unknown;
2126
+ evaluate(expression: string): Promise<unknown>;
2087
2127
  /**
2088
2128
  * Renders a template string, replacing each embedded `{expression}` with the
2089
2129
  * string form of its evaluated value. Returns a string.
@@ -2092,7 +2132,7 @@ export declare class RuntimeExpressionEvaluator {
2092
2132
  * mode, unresolvable references render as an empty string. A `{…}` that is not
2093
2133
  * a valid embedded expression (e.g. a literal JSON payload) is left unchanged.
2094
2134
  */
2095
- interpolate(template: string): string;
2135
+ interpolate(template: string): Promise<string>;
2096
2136
  /**
2097
2137
  * Resolves an Arazzo "value" string.
2098
2138
  *
@@ -2104,7 +2144,7 @@ export declare class RuntimeExpressionEvaluator {
2104
2144
  * yields the string representation of its value, not the typed value. A
2105
2145
  * string containing no expressions is returned unchanged.
2106
2146
  */
2107
- resolve(value: string): unknown;
2147
+ resolve(value: string): Promise<unknown>;
2108
2148
  }
2109
2149
 
2110
2150
  /**
@@ -2128,8 +2168,10 @@ export declare interface RuntimeExpressionEvaluatorOptions {
2128
2168
  readonly document?: ArazzoDocument;
2129
2169
  /**
2130
2170
  * The document registry, used to reach the external document a
2131
- * `$sourceDescriptions` reference points at. The referenced document must
2132
- * already be loaded — resolution is synchronous and never triggers a fetch.
2171
+ * `$sourceDescriptions` reference points at. The document is acquired from
2172
+ * it — returned from its cache, or loaded — whenever the source's `type` is
2173
+ * one the registry can load. Without a registry, `$sourceDescriptions`
2174
+ * resolves against the Source Description Object's own fields only.
2133
2175
  */
2134
2176
  readonly registry?: DocumentRegistry;
2135
2177
  }
@@ -2152,11 +2194,14 @@ export declare interface RuntimeExpressionRequestContext {
2152
2194
  }
2153
2195
 
2154
2196
  /**
2155
- * Resolves a runtime expression to its value.
2197
+ * Resolves a runtime expression to its value, or to a Promise of it.
2156
2198
  *
2157
2199
  * Bridged to a lenient runtime expression evaluator
2158
2200
  * (`(expression) => runtimeExpressionEvaluator.evaluate(expression)`), so an
2159
- * unresolvable reference yields `undefined` rather than throwing.
2201
+ * unresolvable reference yields `undefined` rather than throwing; a
2202
+ * `$sourceDescriptions` document that cannot be loaded still rejects with the
2203
+ * load error (see `RuntimeExpressionEvaluator.evaluate`). The result
2204
+ * is awaited, so a synchronous resolver works too.
2160
2205
  * @public
2161
2206
  */
2162
2207
  export declare type RuntimeExpressionResolver = (expression: string) => unknown;
@@ -2222,7 +2267,9 @@ export declare function settledResult(result: WorkflowExecutionResult): Workflow
2222
2267
  * unlike `regex`/`jsonpath`/`xpath` — it has no separate `context`. Parsing,
2223
2268
  * loose/case-insensitive comparison, and member/index navigation are delegated
2224
2269
  * to `@swaggerexpert/arazzo-criterion`; each embedded runtime expression is
2225
- * resolved through the supplied resolver.
2270
+ * resolved through the supplied resolver and awaited in turn. `&&` and `||`
2271
+ * short-circuit, so an operand that cannot change the outcome is never
2272
+ * resolved.
2226
2273
  *
2227
2274
  * An operand that resolves to `undefined` (a lenient miss) does not throw; it is
2228
2275
  * compared per the library's rules (e.g. `undefined == x` and relational
@@ -2236,7 +2283,7 @@ export declare class SimpleCriterionEvaluator {
2236
2283
  * Evaluates the simple `condition`, resolving each embedded runtime
2237
2284
  * expression via `resolve`.
2238
2285
  */
2239
- evaluate(condition: string, resolve: CriterionContextResolver): boolean;
2286
+ evaluate(condition: string, resolve: CriterionContextResolver): Promise<boolean>;
2240
2287
  }
2241
2288
 
2242
2289
  /**
@@ -2419,7 +2466,7 @@ export declare class StepExecutor {
2419
2466
  * names the step's workflow on a thrown error, as for
2420
2467
  * {@link StepExecutor.execute}.
2421
2468
  */
2422
- evaluateCriteria(step: StepElement, context: RuntimeExpressionContext, workflowId?: string): CriterionEvaluationRecord[];
2469
+ evaluateCriteria(step: StepElement, context: RuntimeExpressionContext, workflowId?: string): Promise<CriterionEvaluationRecord[]>;
2423
2470
  /**
2424
2471
  * Selects every matching `onSuccess` / `onFailure` action for the outcome, in
2425
2472
  * list order, gating each action's criteria against the context, and records
@@ -2443,7 +2490,7 @@ export declare class StepExecutor {
2443
2490
  * `workflowId` names the step's workflow on a thrown error, as for
2444
2491
  * {@link StepExecutor.execute}.
2445
2492
  */
2446
- selectActions(step: StepElement, successful: boolean, context: RuntimeExpressionContext, workflowId?: string): Pick<StepExecutionResult, 'matchedActions' | 'actionCriteria'>;
2493
+ selectActions(step: StepElement, successful: boolean, context: RuntimeExpressionContext, workflowId?: string): Promise<Pick<StepExecutionResult, 'matchedActions' | 'actionCriteria'>>;
2447
2494
  /**
2448
2495
  * The context a step's actions are taken in — see
2449
2496
  * {@link StepExecutionResult.actionContext}: `context` with
@@ -2471,7 +2518,9 @@ export declare interface StepExecutorOptions {
2471
2518
  */
2472
2519
  readonly document: ArazzoDocument;
2473
2520
  /**
2474
- * The document registry holding the already-loaded source documents.
2521
+ * The document registry the source documents are acquired from — returned
2522
+ * from its cache, or loaded when an operation, a workflow or a
2523
+ * `$sourceDescriptions` expression first needs them.
2475
2524
  */
2476
2525
  readonly registry: DocumentRegistry;
2477
2526
  /**
@@ -2510,7 +2559,7 @@ export declare abstract class StepParameterResolver extends ArazzoValueResolver
2510
2559
  * has it, the same way {@link ActionResolver.resolveOnSuccess} is handed
2511
2560
  * `scope`.
2512
2561
  */
2513
- abstract resolve(parameters: StepParametersElement | undefined, resolve: RuntimeExpressionResolver, scope: StepScope): Record<string, unknown>;
2562
+ abstract resolve(parameters: StepParametersElement | undefined, resolve: RuntimeExpressionResolver, scope: StepScope): Promise<Record<string, unknown>>;
2514
2563
  }
2515
2564
 
2516
2565
  /**
@@ -2904,7 +2953,9 @@ export declare interface WorkflowExecutorOptions {
2904
2953
  */
2905
2954
  readonly document: ArazzoDocument;
2906
2955
  /**
2907
- * The document registry holding the already-loaded source documents.
2956
+ * The document registry the source documents are acquired from — returned
2957
+ * from its cache, or loaded when an operation, a workflow or a
2958
+ * `$sourceDescriptions` expression first needs them.
2908
2959
  */
2909
2960
  readonly registry: DocumentRegistry;
2910
2961
  /**
@@ -2992,7 +3043,7 @@ export declare class WorkflowParameterResolver extends StepParameterResolver {
2992
3043
  *
2993
3044
  * `scope` names the step in a thrown {@link ResolverError}.
2994
3045
  */
2995
- resolve(parameters: StepParametersElement | SuccessActionParametersElement | FailureActionParametersElement | undefined, resolve: RuntimeExpressionResolver, scope: StepScope): Record<string, unknown>;
3046
+ resolve(parameters: StepParametersElement | SuccessActionParametersElement | FailureActionParametersElement | undefined, resolve: RuntimeExpressionResolver, scope: StepScope): Promise<Record<string, unknown>>;
2996
3047
  }
2997
3048
 
2998
3049
  /**