@shipfox/expression 1.1.0

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 (140) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +117 -0
  3. package/dist/evaluator/errors.d.ts +8 -0
  4. package/dist/evaluator/errors.d.ts.map +1 -0
  5. package/dist/evaluator/errors.js +13 -0
  6. package/dist/evaluator/errors.js.map +1 -0
  7. package/dist/evaluator/evaluate-workflow-expression.d.ts +11 -0
  8. package/dist/evaluator/evaluate-workflow-expression.d.ts.map +1 -0
  9. package/dist/evaluator/evaluate-workflow-expression.js +30 -0
  10. package/dist/evaluator/evaluate-workflow-expression.js.map +1 -0
  11. package/dist/evaluator/index.d.ts +3 -0
  12. package/dist/evaluator/index.d.ts.map +1 -0
  13. package/dist/evaluator/index.js +4 -0
  14. package/dist/evaluator/index.js.map +1 -0
  15. package/dist/expression/create-workflow-expression.d.ts +7 -0
  16. package/dist/expression/create-workflow-expression.d.ts.map +1 -0
  17. package/dist/expression/create-workflow-expression.js +156 -0
  18. package/dist/expression/create-workflow-expression.js.map +1 -0
  19. package/dist/expression/errors.d.ts +12 -0
  20. package/dist/expression/errors.d.ts.map +1 -0
  21. package/dist/expression/errors.js +13 -0
  22. package/dist/expression/errors.js.map +1 -0
  23. package/dist/expression/index.d.ts +4 -0
  24. package/dist/expression/index.d.ts.map +1 -0
  25. package/dist/expression/index.js +4 -0
  26. package/dist/expression/index.js.map +1 -0
  27. package/dist/expression/workflow-expression.d.ts +33 -0
  28. package/dist/expression/workflow-expression.d.ts.map +1 -0
  29. package/dist/expression/workflow-expression.js +3 -0
  30. package/dist/expression/workflow-expression.js.map +1 -0
  31. package/dist/index.d.ts +27 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +25 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/outputs/index.d.ts +2 -0
  36. package/dist/outputs/index.d.ts.map +1 -0
  37. package/dist/outputs/index.js +3 -0
  38. package/dist/outputs/index.js.map +1 -0
  39. package/dist/outputs/output-declarations.d.ts +39 -0
  40. package/dist/outputs/output-declarations.d.ts.map +1 -0
  41. package/dist/outputs/output-declarations.js +295 -0
  42. package/dist/outputs/output-declarations.js.map +1 -0
  43. package/dist/plan/bare-reference.d.ts +2 -0
  44. package/dist/plan/bare-reference.d.ts.map +1 -0
  45. package/dist/plan/bare-reference.js +23 -0
  46. package/dist/plan/bare-reference.js.map +1 -0
  47. package/dist/plan/context-key-access.d.ts +25 -0
  48. package/dist/plan/context-key-access.d.ts.map +1 -0
  49. package/dist/plan/context-key-access.js +249 -0
  50. package/dist/plan/context-key-access.js.map +1 -0
  51. package/dist/plan/evaluate-planned-predicate.d.ts +14 -0
  52. package/dist/plan/evaluate-planned-predicate.d.ts.map +1 -0
  53. package/dist/plan/evaluate-planned-predicate.js +31 -0
  54. package/dist/plan/evaluate-planned-predicate.js.map +1 -0
  55. package/dist/plan/evaluation-trace.d.ts +44 -0
  56. package/dist/plan/evaluation-trace.d.ts.map +1 -0
  57. package/dist/plan/evaluation-trace.js +95 -0
  58. package/dist/plan/evaluation-trace.js.map +1 -0
  59. package/dist/plan/extract-exact-context-roots.d.ts +2 -0
  60. package/dist/plan/extract-exact-context-roots.d.ts.map +1 -0
  61. package/dist/plan/extract-exact-context-roots.js +114 -0
  62. package/dist/plan/extract-exact-context-roots.js.map +1 -0
  63. package/dist/plan/fill.d.ts +3 -0
  64. package/dist/plan/fill.d.ts.map +1 -0
  65. package/dist/plan/fill.js +8 -0
  66. package/dist/plan/fill.js.map +1 -0
  67. package/dist/plan/freeze-run-command.d.ts +17 -0
  68. package/dist/plan/freeze-run-command.d.ts.map +1 -0
  69. package/dist/plan/freeze-run-command.js +33 -0
  70. package/dist/plan/freeze-run-command.js.map +1 -0
  71. package/dist/plan/freeze.d.ts +48 -0
  72. package/dist/plan/freeze.d.ts.map +1 -0
  73. package/dist/plan/freeze.js +148 -0
  74. package/dist/plan/freeze.js.map +1 -0
  75. package/dist/plan/plan-field.d.ts +26 -0
  76. package/dist/plan/plan-field.d.ts.map +1 -0
  77. package/dist/plan/plan-field.js +63 -0
  78. package/dist/plan/plan-field.js.map +1 -0
  79. package/dist/plan/predicate-shape.d.ts +2 -0
  80. package/dist/plan/predicate-shape.d.ts.map +1 -0
  81. package/dist/plan/predicate-shape.js +45 -0
  82. package/dist/plan/predicate-shape.js.map +1 -0
  83. package/dist/plan/resolved-field.d.ts +17 -0
  84. package/dist/plan/resolved-field.d.ts.map +1 -0
  85. package/dist/plan/resolved-field.js +3 -0
  86. package/dist/plan/resolved-field.js.map +1 -0
  87. package/dist/plan/route-expression.d.ts +9 -0
  88. package/dist/plan/route-expression.d.ts.map +1 -0
  89. package/dist/plan/route-expression.js +46 -0
  90. package/dist/plan/route-expression.js.map +1 -0
  91. package/dist/plan/validate-server-evaluable.d.ts +14 -0
  92. package/dist/plan/validate-server-evaluable.d.ts.map +1 -0
  93. package/dist/plan/validate-server-evaluable.js +20 -0
  94. package/dist/plan/validate-server-evaluable.js.map +1 -0
  95. package/dist/resolver/coerce-workflow-value-to-string.d.ts +2 -0
  96. package/dist/resolver/coerce-workflow-value-to-string.d.ts.map +1 -0
  97. package/dist/resolver/coerce-workflow-value-to-string.js +16 -0
  98. package/dist/resolver/coerce-workflow-value-to-string.js.map +1 -0
  99. package/dist/resolver/errors.d.ts +10 -0
  100. package/dist/resolver/errors.d.ts.map +1 -0
  101. package/dist/resolver/errors.js +12 -0
  102. package/dist/resolver/errors.js.map +1 -0
  103. package/dist/run/hoist-run-command.d.ts +33 -0
  104. package/dist/run/hoist-run-command.d.ts.map +1 -0
  105. package/dist/run/hoist-run-command.js +79 -0
  106. package/dist/run/hoist-run-command.js.map +1 -0
  107. package/dist/run/shell-quoting.d.ts +24 -0
  108. package/dist/run/shell-quoting.d.ts.map +1 -0
  109. package/dist/run/shell-quoting.js +364 -0
  110. package/dist/run/shell-quoting.js.map +1 -0
  111. package/dist/template/errors.d.ts +14 -0
  112. package/dist/template/errors.d.ts.map +1 -0
  113. package/dist/template/errors.js +14 -0
  114. package/dist/template/errors.js.map +1 -0
  115. package/dist/template/extract-cel-context-roots.d.ts +2 -0
  116. package/dist/template/extract-cel-context-roots.d.ts.map +1 -0
  117. package/dist/template/extract-cel-context-roots.js +110 -0
  118. package/dist/template/extract-cel-context-roots.js.map +1 -0
  119. package/dist/template/extract-cel-untrusted-path-accesses.d.ts +5 -0
  120. package/dist/template/extract-cel-untrusted-path-accesses.d.ts.map +1 -0
  121. package/dist/template/extract-cel-untrusted-path-accesses.js +140 -0
  122. package/dist/template/extract-cel-untrusted-path-accesses.js.map +1 -0
  123. package/dist/template/parse-workflow-template.d.ts +3 -0
  124. package/dist/template/parse-workflow-template.d.ts.map +1 -0
  125. package/dist/template/parse-workflow-template.js +111 -0
  126. package/dist/template/parse-workflow-template.js.map +1 -0
  127. package/dist/template/scan-cel-token.d.ts +3 -0
  128. package/dist/template/scan-cel-token.d.ts.map +1 -0
  129. package/dist/template/scan-cel-token.js +55 -0
  130. package/dist/template/scan-cel-token.js.map +1 -0
  131. package/dist/template/template-segment.d.ts +12 -0
  132. package/dist/template/template-segment.d.ts.map +1 -0
  133. package/dist/template/template-segment.js +3 -0
  134. package/dist/template/template-segment.js.map +1 -0
  135. package/dist/tsconfig.test.tsbuildinfo +1 -0
  136. package/dist/workflow-context/workflow-context.d.ts +458 -0
  137. package/dist/workflow-context/workflow-context.d.ts.map +1 -0
  138. package/dist/workflow-context/workflow-context.js +664 -0
  139. package/dist/workflow-context/workflow-context.js.map +1 -0
  140. package/package.json +49 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export {\n WorkflowExpressionEvaluationError,\n type WorkflowExpressionEvaluationFailureReason,\n workflowExpressionEvaluationErrorCode,\n} from './evaluator/errors.js';\nexport {\n evaluateWorkflowExpression,\n evaluateWorkflowPredicate,\n evaluateWorkflowPredicateFailClosed,\n type FailClosedPredicateOutcome,\n type WorkflowExpressionEvaluationContext,\n type WorkflowExpressionEvaluationValue,\n} from './evaluator/evaluate-workflow-expression.js';\nexport {\n createWorkflowExpression,\n unsafeWorkflowExpressionFromSource,\n} from './expression/create-workflow-expression.js';\nexport {\n InvalidWorkflowExpressionError,\n invalidWorkflowExpressionErrorCode,\n} from './expression/errors.js';\nexport type {\n CreateWorkflowExpressionParams,\n ExpressionScalarType,\n ExpressionType,\n ExpressionTypeEnvironment,\n ValidCelExpression,\n WorkflowExpression,\n WorkflowExpressionCheck,\n WorkflowExpressionCheckOptions,\n} from './expression/workflow-expression.js';\nexport {\n type CoerceStepOutputsResult,\n coerceStepOutputs,\n type JsonSchemaValidationResult,\n jsonSchemaToExpressionType,\n type OutputDeclarations,\n type OutputType,\n type OutputTypeDeclaration,\n outputDeclarationsToExpressionFields,\n outputDeclarationToExpressionType,\n outputTypes,\n type StepOutputCoercionError,\n type StepOutputCoercionErrorReason,\n validateJsonSchema,\n} from './outputs/index.js';\nexport {isBareContextReference} from './plan/bare-reference.js';\nexport {\n analyzeContextKeyAccess,\n analyzeContextRootKeyAccess,\n type ContextKeyAccessAnalysis,\n type ContextKeyAccessReference,\n type ContextKeyAccessViolation,\n type ContextRootKeyAccessAnalysis,\n type ContextRootKeyAccessReference,\n} from './plan/context-key-access.js';\nexport {evaluatePlannedPredicateAtSite} from './plan/evaluate-planned-predicate.js';\nexport {\n capTraceEntries,\n capTraceValue,\n EVALUATION_TRACE_MAX_ENTRIES,\n EVALUATION_TRACE_VALUE_CAP_BYTES,\n type EvaluationTraceEntry,\n type EvaluationTraceLimitEntry,\n type EvaluationTraceRowEntry,\n evaluationTraceEntry,\n predicateTraceEntry,\n} from './plan/evaluation-trace.js';\nexport {extractExactContextRoots} from './plan/extract-exact-context-roots.js';\nexport {\n type FrozenResolvedField,\n freezeResolvedFieldAtSite,\n resolveFieldAtSite,\n type SiteResolvedField,\n type WorkflowTemplateDiagnostic,\n type WorkflowTemplateFailurePolicy,\n} from './plan/freeze.js';\nexport {\n type FrozenPlannedRunCommand,\n freezePlannedRunCommandAtSite,\n} from './plan/freeze-run-command.js';\nexport {\n type FieldPlan,\n type FieldPlanResult,\n type PlanViolation,\n planInterpolationField,\n} from './plan/plan-field.js';\nexport {predicateSourceIsBooleanShaped} from './plan/predicate-shape.js';\nexport type {\n ResolvedField,\n ResolvedFieldDeferredSegment,\n ResolvedFieldLiteralSegment,\n ResolvedFieldSegment,\n} from './plan/resolved-field.js';\nexport {type RoutedExpression, routeExpression} from './plan/route-expression.js';\nexport {\n type ServerEvaluabilityResult,\n type ServerEvaluabilityViolation,\n validateServerEvaluable,\n} from './plan/validate-server-evaluable.js';\nexport {\n WorkflowTemplateResolutionError,\n workflowTemplateResolutionErrorCode,\n} from './resolver/errors.js';\nexport {\n type HoistedPlannedRunCommand,\n hoistPlannedRunCommand,\n type PlannedRunCommandBinding,\n type RunCommandHoistOptions,\n UnsafeRunInterpolationError,\n unsafeRunInterpolationErrorCode,\n} from './run/hoist-run-command.js';\nexport {\n InvalidWorkflowTemplateError,\n invalidWorkflowTemplateErrorCode,\n} from './template/errors.js';\nexport {extractCelContextRoots} from './template/extract-cel-context-roots.js';\nexport {extractCelUntrustedPathAccesses} from './template/extract-cel-untrusted-path-accesses.js';\nexport {parseWorkflowTemplate} from './template/parse-workflow-template.js';\nexport type {\n WorkflowTemplateExprSegment,\n WorkflowTemplateLiteralSegment,\n WorkflowTemplateSegment,\n} from './template/template-segment.js';\nexport {\n type AvailabilitySite,\n availabilitySites,\n buildTypedRootsEnvironment,\n type FillTarget,\n getWorkflowContextAvailability,\n getWorkflowContextDefinition,\n getWorkflowContextHost,\n getWorkflowContextSensitivity,\n getWorkflowContextTypeEnvironment,\n getWorkflowContextUntrustedPaths,\n getWorkflowInterpolationFieldFailurePolicy,\n getWorkflowPredicateFieldMinimumFillTarget,\n type OpenWorkflowContextDefinition,\n type ReservedRootDefinition,\n type RunnerWorkflowContextDefinition,\n resolveContextRootAvailability,\n resolveContextRootHost,\n rootsAvailableAt,\n runnerFillTarget,\n type TypedWorkflowContextDefinition,\n unavailableRootsAt,\n type WorkflowContextAvailabilityReferenceEntry,\n type WorkflowContextDefinition,\n type WorkflowContextHost,\n type WorkflowContextName,\n type WorkflowContextReservedRoot,\n type WorkflowContextSensitivity,\n type WorkflowContextShape,\n type WorkflowContextTrustTier,\n type WorkflowFieldFailurePolicy,\n type WorkflowInterpolationFailurePolicy,\n type WorkflowInterpolationField,\n type WorkflowInterpolationFieldPolicy,\n type WorkflowJobTypeOverlay,\n type WorkflowPredicateField,\n type WorkflowStepTypeOverlay,\n workflowContextAvailabilityReference,\n workflowContextDefinitions,\n workflowContextHosts,\n workflowContextNames,\n workflowContextReservedRoots,\n workflowContextRootRequiresLiteralKey,\n workflowContextSensitivities,\n workflowContextTrustTiers,\n workflowFieldFailurePolicies,\n workflowInterpolationFieldAcceptsContext,\n workflowInterpolationFieldAcceptsHost,\n workflowInterpolationFieldAcceptsTrustTier,\n workflowInterpolationFieldPolicies,\n workflowInterpolationFields,\n workflowPredicateFieldFailurePolicy,\n workflowPredicateFields,\n} from './workflow-context/workflow-context.js';\n"],"names":["WorkflowExpressionEvaluationError","workflowExpressionEvaluationErrorCode","evaluateWorkflowExpression","evaluateWorkflowPredicate","evaluateWorkflowPredicateFailClosed","createWorkflowExpression","unsafeWorkflowExpressionFromSource","InvalidWorkflowExpressionError","invalidWorkflowExpressionErrorCode","coerceStepOutputs","jsonSchemaToExpressionType","outputDeclarationsToExpressionFields","outputDeclarationToExpressionType","outputTypes","validateJsonSchema","isBareContextReference","analyzeContextKeyAccess","analyzeContextRootKeyAccess","evaluatePlannedPredicateAtSite","capTraceEntries","capTraceValue","EVALUATION_TRACE_MAX_ENTRIES","EVALUATION_TRACE_VALUE_CAP_BYTES","evaluationTraceEntry","predicateTraceEntry","extractExactContextRoots","freezeResolvedFieldAtSite","resolveFieldAtSite","freezePlannedRunCommandAtSite","planInterpolationField","predicateSourceIsBooleanShaped","routeExpression","validateServerEvaluable","WorkflowTemplateResolutionError","workflowTemplateResolutionErrorCode","hoistPlannedRunCommand","UnsafeRunInterpolationError","unsafeRunInterpolationErrorCode","InvalidWorkflowTemplateError","invalidWorkflowTemplateErrorCode","extractCelContextRoots","extractCelUntrustedPathAccesses","parseWorkflowTemplate","availabilitySites","buildTypedRootsEnvironment","getWorkflowContextAvailability","getWorkflowContextDefinition","getWorkflowContextHost","getWorkflowContextSensitivity","getWorkflowContextTypeEnvironment","getWorkflowContextUntrustedPaths","getWorkflowInterpolationFieldFailurePolicy","getWorkflowPredicateFieldMinimumFillTarget","resolveContextRootAvailability","resolveContextRootHost","rootsAvailableAt","runnerFillTarget","unavailableRootsAt","workflowContextAvailabilityReference","workflowContextDefinitions","workflowContextHosts","workflowContextNames","workflowContextReservedRoots","workflowContextRootRequiresLiteralKey","workflowContextSensitivities","workflowContextTrustTiers","workflowFieldFailurePolicies","workflowInterpolationFieldAcceptsContext","workflowInterpolationFieldAcceptsHost","workflowInterpolationFieldAcceptsTrustTier","workflowInterpolationFieldPolicies","workflowInterpolationFields","workflowPredicateFieldFailurePolicy","workflowPredicateFields"],"mappings":"AAAA,SACEA,iCAAiC,EAEjCC,qCAAqC,QAChC,wBAAwB;AAC/B,SACEC,0BAA0B,EAC1BC,yBAAyB,EACzBC,mCAAmC,QAI9B,8CAA8C;AACrD,SACEC,wBAAwB,EACxBC,kCAAkC,QAC7B,6CAA6C;AACpD,SACEC,8BAA8B,EAC9BC,kCAAkC,QAC7B,yBAAyB;AAWhC,SAEEC,iBAAiB,EAEjBC,0BAA0B,EAI1BC,oCAAoC,EACpCC,iCAAiC,EACjCC,WAAW,EAGXC,kBAAkB,QACb,qBAAqB;AAC5B,SAAQC,sBAAsB,QAAO,2BAA2B;AAChE,SACEC,uBAAuB,EACvBC,2BAA2B,QAMtB,+BAA+B;AACtC,SAAQC,8BAA8B,QAAO,uCAAuC;AACpF,SACEC,eAAe,EACfC,aAAa,EACbC,4BAA4B,EAC5BC,gCAAgC,EAIhCC,oBAAoB,EACpBC,mBAAmB,QACd,6BAA6B;AACpC,SAAQC,wBAAwB,QAAO,wCAAwC;AAC/E,SAEEC,yBAAyB,EACzBC,kBAAkB,QAIb,mBAAmB;AAC1B,SAEEC,6BAA6B,QACxB,+BAA+B;AACtC,SAIEC,sBAAsB,QACjB,uBAAuB;AAC9B,SAAQC,8BAA8B,QAAO,4BAA4B;AAOzE,SAA+BC,eAAe,QAAO,6BAA6B;AAClF,SAGEC,uBAAuB,QAClB,sCAAsC;AAC7C,SACEC,+BAA+B,EAC/BC,mCAAmC,QAC9B,uBAAuB;AAC9B,SAEEC,sBAAsB,EAGtBC,2BAA2B,EAC3BC,+BAA+B,QAC1B,6BAA6B;AACpC,SACEC,4BAA4B,EAC5BC,gCAAgC,QAC3B,uBAAuB;AAC9B,SAAQC,sBAAsB,QAAO,0CAA0C;AAC/E,SAAQC,+BAA+B,QAAO,oDAAoD;AAClG,SAAQC,qBAAqB,QAAO,wCAAwC;AAM5E,SAEEC,iBAAiB,EACjBC,0BAA0B,EAE1BC,8BAA8B,EAC9BC,4BAA4B,EAC5BC,sBAAsB,EACtBC,6BAA6B,EAC7BC,iCAAiC,EACjCC,gCAAgC,EAChCC,0CAA0C,EAC1CC,0CAA0C,EAI1CC,8BAA8B,EAC9BC,sBAAsB,EACtBC,gBAAgB,EAChBC,gBAAgB,EAEhBC,kBAAkB,EAgBlBC,oCAAoC,EACpCC,0BAA0B,EAC1BC,oBAAoB,EACpBC,oBAAoB,EACpBC,4BAA4B,EAC5BC,qCAAqC,EACrCC,4BAA4B,EAC5BC,yBAAyB,EACzBC,4BAA4B,EAC5BC,wCAAwC,EACxCC,qCAAqC,EACrCC,0CAA0C,EAC1CC,kCAAkC,EAClCC,2BAA2B,EAC3BC,mCAAmC,EACnCC,uBAAuB,QAClB,yCAAyC"}
@@ -0,0 +1,2 @@
1
+ export { type CoerceStepOutputsResult, coerceStepOutputs, type JsonSchemaValidationResult, jsonSchemaToExpressionType, type OutputDeclarations, type OutputType, type OutputTypeDeclaration, outputDeclarationsToExpressionFields, outputDeclarationToExpressionType, outputTypes, type StepOutputCoercionError, type StepOutputCoercionErrorReason, validateJsonSchema, } from './output-declarations.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/outputs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,uBAAuB,EAC5B,iBAAiB,EACjB,KAAK,0BAA0B,EAC/B,0BAA0B,EAC1B,KAAK,kBAAkB,EACvB,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,oCAAoC,EACpC,iCAAiC,EACjC,WAAW,EACX,KAAK,uBAAuB,EAC5B,KAAK,6BAA6B,EAClC,kBAAkB,GACnB,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { coerceStepOutputs, jsonSchemaToExpressionType, outputDeclarationsToExpressionFields, outputDeclarationToExpressionType, outputTypes, validateJsonSchema } from './output-declarations.js';
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/outputs/index.ts"],"sourcesContent":["export {\n type CoerceStepOutputsResult,\n coerceStepOutputs,\n type JsonSchemaValidationResult,\n jsonSchemaToExpressionType,\n type OutputDeclarations,\n type OutputType,\n type OutputTypeDeclaration,\n outputDeclarationsToExpressionFields,\n outputDeclarationToExpressionType,\n outputTypes,\n type StepOutputCoercionError,\n type StepOutputCoercionErrorReason,\n validateJsonSchema,\n} from './output-declarations.js';\n"],"names":["coerceStepOutputs","jsonSchemaToExpressionType","outputDeclarationsToExpressionFields","outputDeclarationToExpressionType","outputTypes","validateJsonSchema"],"mappings":"AAAA,SAEEA,iBAAiB,EAEjBC,0BAA0B,EAI1BC,oCAAoC,EACpCC,iCAAiC,EACjCC,WAAW,EAGXC,kBAAkB,QACb,2BAA2B"}
@@ -0,0 +1,39 @@
1
+ import { type WorkflowDocumentStepOutputType, workflowDocumentStepOutputTypes } from '@shipfox/workflow-document';
2
+ import type { ExpressionType } from '../expression/workflow-expression.js';
3
+ export type OutputType = WorkflowDocumentStepOutputType;
4
+ export interface OutputTypeDeclaration {
5
+ readonly type: OutputType;
6
+ readonly schema?: unknown;
7
+ }
8
+ export type OutputDeclarations = Readonly<Record<string, OutputTypeDeclaration>>;
9
+ export type JsonSchemaValidationResult = {
10
+ readonly ok: true;
11
+ } | {
12
+ readonly ok: false;
13
+ readonly reason: string;
14
+ };
15
+ export type StepOutputCoercionErrorReason = 'missing' | 'undeclared' | 'invalid_type' | 'invalid_json' | 'schema_invalid';
16
+ export interface StepOutputCoercionError {
17
+ readonly key: string;
18
+ readonly reason: StepOutputCoercionErrorReason;
19
+ readonly expectedType?: OutputType;
20
+ readonly message: string;
21
+ readonly schemaError?: string;
22
+ }
23
+ export type CoerceStepOutputsResult = {
24
+ readonly ok: true;
25
+ readonly output: Record<string, unknown>;
26
+ } | {
27
+ readonly ok: false;
28
+ readonly error: StepOutputCoercionError;
29
+ };
30
+ export { workflowDocumentStepOutputTypes as outputTypes };
31
+ export declare function outputDeclarationToExpressionType(declaration: OutputTypeDeclaration): ExpressionType;
32
+ export declare function outputDeclarationsToExpressionFields(declarations: OutputDeclarations): Readonly<Record<string, ExpressionType>>;
33
+ export declare function jsonSchemaToExpressionType(schema: unknown): ExpressionType;
34
+ export declare function validateJsonSchema(schema: unknown): JsonSchemaValidationResult;
35
+ export declare function coerceStepOutputs(params: {
36
+ readonly declarations: OutputDeclarations;
37
+ readonly output: Record<string, unknown> | null | undefined;
38
+ }): CoerceStepOutputsResult;
39
+ //# sourceMappingURL=output-declarations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-declarations.d.ts","sourceRoot":"","sources":["../../src/outputs/output-declarations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,8BAA8B,EACnC,+BAA+B,EAChC,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,sCAAsC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YAAY,EAAE,kBAAkB,GAC/B,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAO1C;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,OAAO,GAAG,cAAc,CA4B1E;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,0BAA0B,CAQ9E;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IACxC,QAAQ,CAAC,YAAY,EAAE,kBAAkB,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;CAC7D,GAAG,uBAAuB,CAuC1B"}
@@ -0,0 +1,295 @@
1
+ import { workflowDocumentStepOutputTypes } from '@shipfox/workflow-document';
2
+ import { Ajv } from 'ajv';
3
+ const ajv = new Ajv({
4
+ strict: false
5
+ });
6
+ const coercingAjv = new Ajv({
7
+ strict: false,
8
+ coerceTypes: true,
9
+ allErrors: true,
10
+ addUsedSchema: false
11
+ });
12
+ const jsonOutputValidatorCache = new Map();
13
+ const fallbackJsonType = {
14
+ kind: 'map'
15
+ };
16
+ export { workflowDocumentStepOutputTypes as outputTypes };
17
+ export function outputDeclarationToExpressionType(declaration) {
18
+ switch(declaration.type){
19
+ case 'string':
20
+ return 'string';
21
+ case 'number':
22
+ return 'double';
23
+ case 'boolean':
24
+ return 'bool';
25
+ case 'json':
26
+ return declaration.schema === undefined ? fallbackJsonType : jsonSchemaToExpressionType(declaration.schema);
27
+ }
28
+ }
29
+ export function outputDeclarationsToExpressionFields(declarations) {
30
+ return Object.fromEntries(Object.entries(declarations).map(([key, declaration])=>[
31
+ key,
32
+ outputDeclarationToExpressionType(declaration)
33
+ ]));
34
+ }
35
+ export function jsonSchemaToExpressionType(schema) {
36
+ if (!isPlainRecord(schema)) return fallbackJsonType;
37
+ if (hasUnsupportedCombinator(schema)) return fallbackJsonType;
38
+ const type = schema.type;
39
+ if (Array.isArray(type)) return fallbackJsonType;
40
+ switch(type){
41
+ case 'string':
42
+ return 'string';
43
+ case 'number':
44
+ return 'double';
45
+ case 'integer':
46
+ return 'int';
47
+ case 'boolean':
48
+ return 'bool';
49
+ case 'null':
50
+ return 'null';
51
+ case 'array':
52
+ return {
53
+ kind: 'list',
54
+ element: jsonSchemaToExpressionType(schema.items)
55
+ };
56
+ case 'object':
57
+ return closedObjectJsonSchemaToExpressionType(schema);
58
+ default:
59
+ return fallbackJsonType;
60
+ }
61
+ }
62
+ export function validateJsonSchema(schema) {
63
+ const valid = ajv.validateSchema(schema);
64
+ if (valid) return {
65
+ ok: true
66
+ };
67
+ return {
68
+ ok: false,
69
+ reason: ajv.errorsText(ajv.errors, {
70
+ separator: '; '
71
+ })
72
+ };
73
+ }
74
+ export function coerceStepOutputs(params) {
75
+ const declaredKeys = Object.keys(params.declarations);
76
+ const output = params.output ?? {};
77
+ for (const key of declaredKeys){
78
+ if (Object.hasOwn(output, key)) continue;
79
+ const declaration = params.declarations[key];
80
+ return {
81
+ ok: false,
82
+ error: {
83
+ key,
84
+ reason: 'missing',
85
+ ...declaration === undefined ? {} : {
86
+ expectedType: declaration.type
87
+ },
88
+ message: `Output "${key}" is required by the step output declaration.`
89
+ }
90
+ };
91
+ }
92
+ for (const key of Object.keys(output)){
93
+ if (Object.hasOwn(params.declarations, key)) continue;
94
+ return {
95
+ ok: false,
96
+ error: {
97
+ key,
98
+ reason: 'undeclared',
99
+ message: `Output "${key}" is not declared by the step output schema.`
100
+ }
101
+ };
102
+ }
103
+ const coerced = {};
104
+ for (const [key, declaration] of Object.entries(params.declarations)){
105
+ const value = output[key];
106
+ const result = coerceStepOutputValue(key, declaration, value);
107
+ if (!result.ok) return result;
108
+ coerced[key] = result.value;
109
+ }
110
+ return {
111
+ ok: true,
112
+ output: coerced
113
+ };
114
+ }
115
+ function coerceStepOutputValue(key, declaration, value) {
116
+ switch(declaration.type){
117
+ case 'string':
118
+ return coerceStringOutput(key, value);
119
+ case 'number':
120
+ return coerceNumberOutput(key, value);
121
+ case 'boolean':
122
+ return coerceBooleanOutput(key, value);
123
+ case 'json':
124
+ return coerceJsonOutput(key, declaration, value);
125
+ }
126
+ }
127
+ function coerceStringOutput(key, value) {
128
+ if (typeof value === 'string') return {
129
+ ok: true,
130
+ value
131
+ };
132
+ return invalidTypeError(key, 'string', 'must be a string');
133
+ }
134
+ function coerceNumberOutput(key, value) {
135
+ if (typeof value === 'number' && Number.isFinite(value)) return {
136
+ ok: true,
137
+ value
138
+ };
139
+ if (typeof value === 'string') {
140
+ const trimmed = value.trim();
141
+ if (trimmed !== '') {
142
+ const number = Number(trimmed);
143
+ if (Number.isFinite(number)) return {
144
+ ok: true,
145
+ value: number
146
+ };
147
+ }
148
+ }
149
+ return invalidTypeError(key, 'number', 'must be a finite number or numeric string');
150
+ }
151
+ function coerceBooleanOutput(key, value) {
152
+ if (typeof value === 'boolean') return {
153
+ ok: true,
154
+ value
155
+ };
156
+ if (value === 'true') return {
157
+ ok: true,
158
+ value: true
159
+ };
160
+ if (value === 'false') return {
161
+ ok: true,
162
+ value: false
163
+ };
164
+ return invalidTypeError(key, 'boolean', 'must be a boolean or the string "true" or "false"');
165
+ }
166
+ function coerceJsonOutput(key, declaration, value) {
167
+ const parsed = parseJsonOutputValue(key, value);
168
+ if (!parsed.ok) return parsed;
169
+ if (declaration.schema === undefined) return {
170
+ ok: true,
171
+ value: parsed.value
172
+ };
173
+ const data = {
174
+ value: cloneJsonValue(parsed.value)
175
+ };
176
+ const validate = validatorForJsonOutputSchema(declaration.schema);
177
+ if (validate(data)) return {
178
+ ok: true,
179
+ value: data.value
180
+ };
181
+ return {
182
+ ok: false,
183
+ error: {
184
+ key,
185
+ reason: 'schema_invalid',
186
+ expectedType: 'json',
187
+ message: `Output "${key}" does not match its JSON Schema.`,
188
+ schemaError: coercingAjv.errorsText(validate.errors, {
189
+ separator: '; '
190
+ })
191
+ }
192
+ };
193
+ }
194
+ function parseJsonOutputValue(key, value) {
195
+ if (typeof value !== 'string') return {
196
+ ok: true,
197
+ value
198
+ };
199
+ try {
200
+ return {
201
+ ok: true,
202
+ value: JSON.parse(value)
203
+ };
204
+ } catch {
205
+ if (looksLikeJsonContainer(value)) {
206
+ return {
207
+ ok: false,
208
+ error: {
209
+ key,
210
+ reason: 'invalid_json',
211
+ expectedType: 'json',
212
+ message: `Output "${key}" must be valid JSON.`
213
+ }
214
+ };
215
+ }
216
+ return {
217
+ ok: true,
218
+ value
219
+ };
220
+ }
221
+ }
222
+ function invalidTypeError(key, expectedType, detail) {
223
+ return {
224
+ ok: false,
225
+ error: {
226
+ key,
227
+ reason: 'invalid_type',
228
+ expectedType,
229
+ message: `Output "${key}" ${detail}.`
230
+ }
231
+ };
232
+ }
233
+ function validatorForJsonOutputSchema(schema) {
234
+ const key = stableJsonStringify(schema);
235
+ const cached = jsonOutputValidatorCache.get(key);
236
+ if (cached !== undefined) return cached;
237
+ const validate = coercingAjv.compile({
238
+ type: 'object',
239
+ properties: {
240
+ value: schema
241
+ },
242
+ required: [
243
+ 'value'
244
+ ],
245
+ additionalProperties: false
246
+ });
247
+ jsonOutputValidatorCache.set(key, validate);
248
+ return validate;
249
+ }
250
+ function closedObjectJsonSchemaToExpressionType(schema) {
251
+ const properties = schema.properties;
252
+ const required = schema.required;
253
+ // CEL object fields are required when statically typed. Optional JSON Schema
254
+ // fields would make valid runtime values fail type-checking, so keep those
255
+ // schemas opaque.
256
+ if (schema.additionalProperties !== false || !isPlainRecord(properties) || !Array.isArray(required) || !required.every((field)=>typeof field === 'string') || Object.keys(properties).some((field)=>!required.includes(field))) {
257
+ return fallbackJsonType;
258
+ }
259
+ return {
260
+ kind: 'object',
261
+ fields: Object.fromEntries(Object.entries(properties).map(([field, fieldSchema])=>[
262
+ field,
263
+ jsonSchemaToExpressionType(fieldSchema)
264
+ ]))
265
+ };
266
+ }
267
+ function hasUnsupportedCombinator(schema) {
268
+ return schema.oneOf !== undefined || schema.anyOf !== undefined || schema.allOf !== undefined || schema.not !== undefined || schema.enum !== undefined || schema.const !== undefined || schema.patternProperties !== undefined || schema.nullable === true;
269
+ }
270
+ function isPlainRecord(value) {
271
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
272
+ }
273
+ function cloneJsonValue(value) {
274
+ if (value === undefined) return undefined;
275
+ const serialized = JSON.stringify(value);
276
+ if (serialized === undefined) return value;
277
+ return JSON.parse(serialized);
278
+ }
279
+ function stableJsonStringify(value) {
280
+ return JSON.stringify(canonicalJson(value));
281
+ }
282
+ function canonicalJson(value) {
283
+ if (Array.isArray(value)) return value.map(canonicalJson);
284
+ if (!isPlainRecord(value)) return value;
285
+ return Object.fromEntries(Object.keys(value).sort().map((key)=>[
286
+ key,
287
+ canonicalJson(value[key])
288
+ ]));
289
+ }
290
+ function looksLikeJsonContainer(value) {
291
+ const trimmed = value.trimStart();
292
+ return trimmed.startsWith('{') || trimmed.startsWith('[');
293
+ }
294
+
295
+ //# sourceMappingURL=output-declarations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/outputs/output-declarations.ts"],"sourcesContent":["import {\n type WorkflowDocumentStepOutputType,\n workflowDocumentStepOutputTypes,\n} from '@shipfox/workflow-document';\nimport {Ajv, type AnySchema, type ValidateFunction} from 'ajv';\nimport type {ExpressionType} from '../expression/workflow-expression.js';\n\nexport type OutputType = WorkflowDocumentStepOutputType;\n\nexport interface OutputTypeDeclaration {\n readonly type: OutputType;\n readonly schema?: unknown;\n}\n\nexport type OutputDeclarations = Readonly<Record<string, OutputTypeDeclaration>>;\n\nexport type JsonSchemaValidationResult =\n | {readonly ok: true}\n | {readonly ok: false; readonly reason: string};\n\nexport type StepOutputCoercionErrorReason =\n | 'missing'\n | 'undeclared'\n | 'invalid_type'\n | 'invalid_json'\n | 'schema_invalid';\n\nexport interface StepOutputCoercionError {\n readonly key: string;\n readonly reason: StepOutputCoercionErrorReason;\n readonly expectedType?: OutputType;\n readonly message: string;\n readonly schemaError?: string;\n}\n\nexport type CoerceStepOutputsResult =\n | {readonly ok: true; readonly output: Record<string, unknown>}\n | {readonly ok: false; readonly error: StepOutputCoercionError};\n\nconst ajv = new Ajv({strict: false});\nconst coercingAjv = new Ajv({\n strict: false,\n coerceTypes: true,\n allErrors: true,\n addUsedSchema: false,\n});\nconst jsonOutputValidatorCache = new Map<string, ValidateFunction>();\nconst fallbackJsonType = {kind: 'map'} as const satisfies ExpressionType;\n\nexport {workflowDocumentStepOutputTypes as outputTypes};\n\nexport function outputDeclarationToExpressionType(\n declaration: OutputTypeDeclaration,\n): ExpressionType {\n switch (declaration.type) {\n case 'string':\n return 'string';\n case 'number':\n return 'double';\n case 'boolean':\n return 'bool';\n case 'json':\n return declaration.schema === undefined\n ? fallbackJsonType\n : jsonSchemaToExpressionType(declaration.schema);\n }\n}\n\nexport function outputDeclarationsToExpressionFields(\n declarations: OutputDeclarations,\n): Readonly<Record<string, ExpressionType>> {\n return Object.fromEntries(\n Object.entries(declarations).map(([key, declaration]) => [\n key,\n outputDeclarationToExpressionType(declaration),\n ]),\n );\n}\n\nexport function jsonSchemaToExpressionType(schema: unknown): ExpressionType {\n if (!isPlainRecord(schema)) return fallbackJsonType;\n if (hasUnsupportedCombinator(schema)) return fallbackJsonType;\n\n const type = schema.type;\n if (Array.isArray(type)) return fallbackJsonType;\n\n switch (type) {\n case 'string':\n return 'string';\n case 'number':\n return 'double';\n case 'integer':\n return 'int';\n case 'boolean':\n return 'bool';\n case 'null':\n return 'null';\n case 'array':\n return {\n kind: 'list',\n element: jsonSchemaToExpressionType(schema.items),\n };\n case 'object':\n return closedObjectJsonSchemaToExpressionType(schema);\n default:\n return fallbackJsonType;\n }\n}\n\nexport function validateJsonSchema(schema: unknown): JsonSchemaValidationResult {\n const valid = ajv.validateSchema(schema as AnySchema);\n if (valid) return {ok: true};\n\n return {\n ok: false,\n reason: ajv.errorsText(ajv.errors, {separator: '; '}),\n };\n}\n\nexport function coerceStepOutputs(params: {\n readonly declarations: OutputDeclarations;\n readonly output: Record<string, unknown> | null | undefined;\n}): CoerceStepOutputsResult {\n const declaredKeys = Object.keys(params.declarations);\n const output = params.output ?? {};\n\n for (const key of declaredKeys) {\n if (Object.hasOwn(output, key)) continue;\n const declaration = params.declarations[key];\n return {\n ok: false,\n error: {\n key,\n reason: 'missing',\n ...(declaration === undefined ? {} : {expectedType: declaration.type}),\n message: `Output \"${key}\" is required by the step output declaration.`,\n },\n };\n }\n\n for (const key of Object.keys(output)) {\n if (Object.hasOwn(params.declarations, key)) continue;\n return {\n ok: false,\n error: {\n key,\n reason: 'undeclared',\n message: `Output \"${key}\" is not declared by the step output schema.`,\n },\n };\n }\n\n const coerced: Record<string, unknown> = {};\n for (const [key, declaration] of Object.entries(params.declarations)) {\n const value = output[key];\n const result = coerceStepOutputValue(key, declaration, value);\n if (!result.ok) return result;\n coerced[key] = result.value;\n }\n\n return {ok: true, output: coerced};\n}\n\ntype CoerceStepOutputValueResult =\n | {readonly ok: true; readonly value: unknown}\n | {readonly ok: false; readonly error: StepOutputCoercionError};\n\nfunction coerceStepOutputValue(\n key: string,\n declaration: OutputTypeDeclaration,\n value: unknown,\n): CoerceStepOutputValueResult {\n switch (declaration.type) {\n case 'string':\n return coerceStringOutput(key, value);\n case 'number':\n return coerceNumberOutput(key, value);\n case 'boolean':\n return coerceBooleanOutput(key, value);\n case 'json':\n return coerceJsonOutput(key, declaration, value);\n }\n}\n\nfunction coerceStringOutput(key: string, value: unknown): CoerceStepOutputValueResult {\n if (typeof value === 'string') return {ok: true, value};\n return invalidTypeError(key, 'string', 'must be a string');\n}\n\nfunction coerceNumberOutput(key: string, value: unknown): CoerceStepOutputValueResult {\n if (typeof value === 'number' && Number.isFinite(value)) return {ok: true, value};\n\n if (typeof value === 'string') {\n const trimmed = value.trim();\n if (trimmed !== '') {\n const number = Number(trimmed);\n if (Number.isFinite(number)) return {ok: true, value: number};\n }\n }\n\n return invalidTypeError(key, 'number', 'must be a finite number or numeric string');\n}\n\nfunction coerceBooleanOutput(key: string, value: unknown): CoerceStepOutputValueResult {\n if (typeof value === 'boolean') return {ok: true, value};\n if (value === 'true') return {ok: true, value: true};\n if (value === 'false') return {ok: true, value: false};\n return invalidTypeError(key, 'boolean', 'must be a boolean or the string \"true\" or \"false\"');\n}\n\nfunction coerceJsonOutput(\n key: string,\n declaration: OutputTypeDeclaration,\n value: unknown,\n): CoerceStepOutputValueResult {\n const parsed = parseJsonOutputValue(key, value);\n if (!parsed.ok) return parsed;\n\n if (declaration.schema === undefined) return {ok: true, value: parsed.value};\n\n const data = {value: cloneJsonValue(parsed.value)};\n const validate = validatorForJsonOutputSchema(declaration.schema);\n if (validate(data)) return {ok: true, value: data.value};\n\n return {\n ok: false,\n error: {\n key,\n reason: 'schema_invalid',\n expectedType: 'json',\n message: `Output \"${key}\" does not match its JSON Schema.`,\n schemaError: coercingAjv.errorsText(validate.errors, {separator: '; '}),\n },\n };\n}\n\nfunction parseJsonOutputValue(key: string, value: unknown): CoerceStepOutputValueResult {\n if (typeof value !== 'string') return {ok: true, value};\n\n try {\n return {ok: true, value: JSON.parse(value) as unknown};\n } catch {\n if (looksLikeJsonContainer(value)) {\n return {\n ok: false,\n error: {\n key,\n reason: 'invalid_json',\n expectedType: 'json',\n message: `Output \"${key}\" must be valid JSON.`,\n },\n };\n }\n return {ok: true, value};\n }\n}\n\nfunction invalidTypeError(\n key: string,\n expectedType: OutputType,\n detail: string,\n): CoerceStepOutputValueResult {\n return {\n ok: false,\n error: {\n key,\n reason: 'invalid_type',\n expectedType,\n message: `Output \"${key}\" ${detail}.`,\n },\n };\n}\n\nfunction validatorForJsonOutputSchema(schema: unknown): ValidateFunction {\n const key = stableJsonStringify(schema);\n const cached = jsonOutputValidatorCache.get(key);\n if (cached !== undefined) return cached;\n\n const validate = coercingAjv.compile({\n type: 'object',\n properties: {value: schema},\n required: ['value'],\n additionalProperties: false,\n });\n jsonOutputValidatorCache.set(key, validate);\n return validate;\n}\n\nfunction closedObjectJsonSchemaToExpressionType(\n schema: Readonly<Record<string, unknown>>,\n): ExpressionType {\n const properties = schema.properties;\n const required = schema.required;\n // CEL object fields are required when statically typed. Optional JSON Schema\n // fields would make valid runtime values fail type-checking, so keep those\n // schemas opaque.\n if (\n schema.additionalProperties !== false ||\n !isPlainRecord(properties) ||\n !Array.isArray(required) ||\n !required.every((field) => typeof field === 'string') ||\n Object.keys(properties).some((field) => !required.includes(field))\n ) {\n return fallbackJsonType;\n }\n\n return {\n kind: 'object',\n fields: Object.fromEntries(\n Object.entries(properties).map(([field, fieldSchema]) => [\n field,\n jsonSchemaToExpressionType(fieldSchema),\n ]),\n ),\n };\n}\n\nfunction hasUnsupportedCombinator(schema: Readonly<Record<string, unknown>>): boolean {\n return (\n schema.oneOf !== undefined ||\n schema.anyOf !== undefined ||\n schema.allOf !== undefined ||\n schema.not !== undefined ||\n schema.enum !== undefined ||\n schema.const !== undefined ||\n schema.patternProperties !== undefined ||\n schema.nullable === true\n );\n}\n\nfunction isPlainRecord(value: unknown): value is Readonly<Record<string, unknown>> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction cloneJsonValue(value: unknown): unknown {\n if (value === undefined) return undefined;\n const serialized = JSON.stringify(value);\n if (serialized === undefined) return value;\n return JSON.parse(serialized) as unknown;\n}\n\nfunction stableJsonStringify(value: unknown): string {\n return JSON.stringify(canonicalJson(value));\n}\n\nfunction canonicalJson(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(canonicalJson);\n if (!isPlainRecord(value)) return value;\n\n return Object.fromEntries(\n Object.keys(value)\n .sort()\n .map((key) => [key, canonicalJson(value[key])]),\n );\n}\n\nfunction looksLikeJsonContainer(value: string): boolean {\n const trimmed = value.trimStart();\n return trimmed.startsWith('{') || trimmed.startsWith('[');\n}\n"],"names":["workflowDocumentStepOutputTypes","Ajv","ajv","strict","coercingAjv","coerceTypes","allErrors","addUsedSchema","jsonOutputValidatorCache","Map","fallbackJsonType","kind","outputTypes","outputDeclarationToExpressionType","declaration","type","schema","undefined","jsonSchemaToExpressionType","outputDeclarationsToExpressionFields","declarations","Object","fromEntries","entries","map","key","isPlainRecord","hasUnsupportedCombinator","Array","isArray","element","items","closedObjectJsonSchemaToExpressionType","validateJsonSchema","valid","validateSchema","ok","reason","errorsText","errors","separator","coerceStepOutputs","params","declaredKeys","keys","output","hasOwn","error","expectedType","message","coerced","value","result","coerceStepOutputValue","coerceStringOutput","coerceNumberOutput","coerceBooleanOutput","coerceJsonOutput","invalidTypeError","Number","isFinite","trimmed","trim","number","parsed","parseJsonOutputValue","data","cloneJsonValue","validate","validatorForJsonOutputSchema","schemaError","JSON","parse","looksLikeJsonContainer","detail","stableJsonStringify","cached","get","compile","properties","required","additionalProperties","set","every","field","some","includes","fields","fieldSchema","oneOf","anyOf","allOf","not","enum","const","patternProperties","nullable","serialized","stringify","canonicalJson","sort","trimStart","startsWith"],"mappings":"AAAA,SAEEA,+BAA+B,QAC1B,6BAA6B;AACpC,SAAQC,GAAG,QAA8C,MAAM;AAmC/D,MAAMC,MAAM,IAAID,IAAI;IAACE,QAAQ;AAAK;AAClC,MAAMC,cAAc,IAAIH,IAAI;IAC1BE,QAAQ;IACRE,aAAa;IACbC,WAAW;IACXC,eAAe;AACjB;AACA,MAAMC,2BAA2B,IAAIC;AACrC,MAAMC,mBAAmB;IAACC,MAAM;AAAK;AAErC,SAAQX,mCAAmCY,WAAW,GAAE;AAExD,OAAO,SAASC,kCACdC,WAAkC;IAElC,OAAQA,YAAYC,IAAI;QACtB,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAOD,YAAYE,MAAM,KAAKC,YAC1BP,mBACAQ,2BAA2BJ,YAAYE,MAAM;IACrD;AACF;AAEA,OAAO,SAASG,qCACdC,YAAgC;IAEhC,OAAOC,OAAOC,WAAW,CACvBD,OAAOE,OAAO,CAACH,cAAcI,GAAG,CAAC,CAAC,CAACC,KAAKX,YAAY,GAAK;YACvDW;YACAZ,kCAAkCC;SACnC;AAEL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AU,CAAC;AACvD"}
@@ -0,0 +1,2 @@
1
+ export declare function isBareContextReference(source: string): boolean;
2
+ //# sourceMappingURL=bare-reference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bare-reference.d.ts","sourceRoot":"","sources":["../../src/plan/bare-reference.ts"],"names":[],"mappings":"AAEA,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAM9D"}
@@ -0,0 +1,23 @@
1
+ import { parse as parseCel } from '@marcbachmann/cel-js';
2
+ export function isBareContextReference(source) {
3
+ try {
4
+ return bareMemberAccessDepth(parseCel(source).ast) > 0;
5
+ } catch {
6
+ return false;
7
+ }
8
+ }
9
+ function bareMemberAccessDepth(node) {
10
+ switch(node.op){
11
+ case 'id':
12
+ return 0;
13
+ case '.':
14
+ {
15
+ const targetDepth = bareMemberAccessDepth(node.args[0]);
16
+ return targetDepth >= 0 ? targetDepth + 1 : -1;
17
+ }
18
+ default:
19
+ return -1;
20
+ }
21
+ }
22
+
23
+ //# sourceMappingURL=bare-reference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/plan/bare-reference.ts"],"sourcesContent":["import {type ASTNode, parse as parseCel} from '@marcbachmann/cel-js';\n\nexport function isBareContextReference(source: string): boolean {\n try {\n return bareMemberAccessDepth(parseCel(source).ast) > 0;\n } catch {\n return false;\n }\n}\n\nfunction bareMemberAccessDepth(node: ASTNode): number {\n switch (node.op) {\n case 'id':\n return 0;\n case '.': {\n const targetDepth = bareMemberAccessDepth(node.args[0]);\n return targetDepth >= 0 ? targetDepth + 1 : -1;\n }\n default:\n return -1;\n }\n}\n"],"names":["parse","parseCel","isBareContextReference","source","bareMemberAccessDepth","ast","node","op","targetDepth","args"],"mappings":"AAAA,SAAsBA,SAASC,QAAQ,QAAO,uBAAuB;AAErE,OAAO,SAASC,uBAAuBC,MAAc;IACnD,IAAI;QACF,OAAOC,sBAAsBH,SAASE,QAAQE,GAAG,IAAI;IACvD,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAEA,SAASD,sBAAsBE,IAAa;IAC1C,OAAQA,KAAKC,EAAE;QACb,KAAK;YACH,OAAO;QACT,KAAK;YAAK;gBACR,MAAMC,cAAcJ,sBAAsBE,KAAKG,IAAI,CAAC,EAAE;gBACtD,OAAOD,eAAe,IAAIA,cAAc,IAAI,CAAC;YAC/C;QACA;YACE,OAAO,CAAC;IACZ;AACF"}
@@ -0,0 +1,25 @@
1
+ import type { WorkflowExpression } from '../expression/workflow-expression.js';
2
+ export interface ContextKeyAccessReference {
3
+ readonly root: 'vars' | 'secrets';
4
+ readonly store?: string;
5
+ readonly key: string;
6
+ }
7
+ export interface ContextKeyAccessViolation {
8
+ readonly root: string;
9
+ readonly source: string;
10
+ }
11
+ export interface ContextKeyAccessAnalysis {
12
+ readonly references: readonly ContextKeyAccessReference[];
13
+ readonly violations: readonly ContextKeyAccessViolation[];
14
+ }
15
+ export interface ContextRootKeyAccessReference {
16
+ readonly root: string;
17
+ readonly key: string;
18
+ }
19
+ export interface ContextRootKeyAccessAnalysis {
20
+ readonly references: readonly ContextRootKeyAccessReference[];
21
+ readonly violations: readonly ContextKeyAccessViolation[];
22
+ }
23
+ export declare function analyzeContextKeyAccess(expression: WorkflowExpression | string): ContextKeyAccessAnalysis;
24
+ export declare function analyzeContextRootKeyAccess(expression: WorkflowExpression | string, roots: readonly string[]): ContextRootKeyAccessAnalysis;
25
+ //# sourceMappingURL=context-key-access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-key-access.d.ts","sourceRoot":"","sources":["../../src/plan/context-key-access.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,sCAAsC,CAAC;AAoB7E,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,UAAU,EAAE,SAAS,yBAAyB,EAAE,CAAC;IAC1D,QAAQ,CAAC,UAAU,EAAE,SAAS,yBAAyB,EAAE,CAAC;CAC3D;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,UAAU,EAAE,SAAS,6BAA6B,EAAE,CAAC;IAC9D,QAAQ,CAAC,UAAU,EAAE,SAAS,yBAAyB,EAAE,CAAC;CAC3D;AAaD,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,kBAAkB,GAAG,MAAM,GACtC,wBAAwB,CAY1B;AAED,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,kBAAkB,GAAG,MAAM,EACvC,KAAK,EAAE,SAAS,MAAM,EAAE,GACvB,4BAA4B,CAa9B"}