@azure/provisioning-core 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +40 -0
- package/dist/browser/constructs/built-in-resources/resource-group.d.ts +50 -0
- package/dist/browser/constructs/built-in-resources/resource-group.d.ts.map +1 -0
- package/dist/browser/constructs/built-in-resources/resource-group.js +100 -0
- package/dist/browser/constructs/built-in-resources/resource-group.js.map +1 -0
- package/dist/browser/constructs/output.d.ts +80 -0
- package/dist/browser/constructs/output.d.ts.map +1 -0
- package/dist/browser/constructs/output.js +75 -0
- package/dist/browser/constructs/output.js.map +1 -0
- package/dist/browser/constructs/parameter.d.ts +77 -0
- package/dist/browser/constructs/parameter.d.ts.map +1 -0
- package/dist/browser/constructs/parameter.js +93 -0
- package/dist/browser/constructs/parameter.js.map +1 -0
- package/dist/browser/constructs/provisioning-component.d.ts +91 -0
- package/dist/browser/constructs/provisioning-component.d.ts.map +1 -0
- package/dist/browser/constructs/provisioning-component.js +150 -0
- package/dist/browser/constructs/provisioning-component.js.map +1 -0
- package/dist/browser/constructs/resource/resource-proxy.d.ts +134 -0
- package/dist/browser/constructs/resource/resource-proxy.d.ts.map +1 -0
- package/dist/browser/constructs/resource/resource-proxy.js +517 -0
- package/dist/browser/constructs/resource/resource-proxy.js.map +1 -0
- package/dist/browser/constructs/resource/resource-query.d.ts +23 -0
- package/dist/browser/constructs/resource/resource-query.d.ts.map +1 -0
- package/dist/browser/constructs/resource/resource-query.js +69 -0
- package/dist/browser/constructs/resource/resource-query.js.map +1 -0
- package/dist/browser/constructs/resource/resource-registry.d.ts +99 -0
- package/dist/browser/constructs/resource/resource-registry.d.ts.map +1 -0
- package/dist/browser/constructs/resource/resource-registry.js +51 -0
- package/dist/browser/constructs/resource/resource-registry.js.map +1 -0
- package/dist/browser/constructs/resource/resource-type-registry.d.ts +46 -0
- package/dist/browser/constructs/resource/resource-type-registry.d.ts.map +1 -0
- package/dist/browser/constructs/resource/resource-type-registry.js +156 -0
- package/dist/browser/constructs/resource/resource-type-registry.js.map +1 -0
- package/dist/browser/constructs/resource/resource-utils.d.ts +60 -0
- package/dist/browser/constructs/resource/resource-utils.d.ts.map +1 -0
- package/dist/browser/constructs/resource/resource-utils.js +75 -0
- package/dist/browser/constructs/resource/resource-utils.js.map +1 -0
- package/dist/browser/constructs/resource/resource.d.ts +460 -0
- package/dist/browser/constructs/resource/resource.d.ts.map +1 -0
- package/dist/browser/constructs/resource/resource.js +582 -0
- package/dist/browser/constructs/resource/resource.js.map +1 -0
- package/dist/browser/constructs/stack.d.ts +110 -0
- package/dist/browser/constructs/stack.d.ts.map +1 -0
- package/dist/browser/constructs/stack.js +110 -0
- package/dist/browser/constructs/stack.js.map +1 -0
- package/dist/browser/constructs/variable.d.ts +63 -0
- package/dist/browser/constructs/variable.d.ts.map +1 -0
- package/dist/browser/constructs/variable.js +74 -0
- package/dist/browser/constructs/variable.js.map +1 -0
- package/dist/browser/deployment-context/deployment-context.d.ts +27 -0
- package/dist/browser/deployment-context/deployment-context.d.ts.map +1 -0
- package/dist/browser/deployment-context/deployment-context.js +4 -0
- package/dist/browser/deployment-context/deployment-context.js.map +1 -0
- package/dist/browser/expression/ast-nodes.d.ts +100 -0
- package/dist/browser/expression/ast-nodes.d.ts.map +1 -0
- package/dist/browser/expression/ast-nodes.js +125 -0
- package/dist/browser/expression/ast-nodes.js.map +1 -0
- package/dist/browser/expression/expressions.d.ts +164 -0
- package/dist/browser/expression/expressions.d.ts.map +1 -0
- package/dist/browser/expression/expressions.js +211 -0
- package/dist/browser/expression/expressions.js.map +1 -0
- package/dist/browser/fn.d.ts +194 -0
- package/dist/browser/fn.d.ts.map +1 -0
- package/dist/browser/fn.js +334 -0
- package/dist/browser/fn.js.map +1 -0
- package/dist/browser/index.d.ts +25 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +17 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/internal.d.ts +13 -0
- package/dist/browser/internal.d.ts.map +1 -0
- package/dist/browser/internal.js +10 -0
- package/dist/browser/internal.js.map +1 -0
- package/dist/browser/naming/naming-policy.d.ts +56 -0
- package/dist/browser/naming/naming-policy.d.ts.map +1 -0
- package/dist/browser/naming/naming-policy.js +97 -0
- package/dist/browser/naming/naming-policy.js.map +1 -0
- package/dist/browser/naming/naming-rules.d.ts +15 -0
- package/dist/browser/naming/naming-rules.d.ts.map +1 -0
- package/dist/browser/naming/naming-rules.js +15 -0
- package/dist/browser/naming/naming-rules.js.map +1 -0
- package/dist/browser/package.json +8 -0
- package/dist/browser/serialization/contract/generated/ast.d.ts +508 -0
- package/dist/browser/serialization/contract/generated/ast.d.ts.map +1 -0
- package/dist/browser/serialization/contract/generated/ast.js +23 -0
- package/dist/browser/serialization/contract/generated/ast.js.map +1 -0
- package/dist/browser/serialization/contract/index.d.ts +2 -0
- package/dist/browser/serialization/contract/index.d.ts.map +1 -0
- package/dist/browser/serialization/contract/index.js +4 -0
- package/dist/browser/serialization/contract/index.js.map +1 -0
- package/dist/browser/serialization/index.d.ts +4 -0
- package/dist/browser/serialization/index.d.ts.map +1 -0
- package/dist/browser/serialization/index.js +5 -0
- package/dist/browser/serialization/index.js.map +1 -0
- package/dist/browser/serialization/json/deserialize.d.ts +24 -0
- package/dist/browser/serialization/json/deserialize.d.ts.map +1 -0
- package/dist/browser/serialization/json/deserialize.js +437 -0
- package/dist/browser/serialization/json/deserialize.js.map +1 -0
- package/dist/browser/serialization/json/encoding.d.ts +4 -0
- package/dist/browser/serialization/json/encoding.d.ts.map +1 -0
- package/dist/browser/serialization/json/encoding.js +319 -0
- package/dist/browser/serialization/json/encoding.js.map +1 -0
- package/dist/browser/serialization/json/expression.d.ts +32 -0
- package/dist/browser/serialization/json/expression.d.ts.map +1 -0
- package/dist/browser/serialization/json/expression.js +494 -0
- package/dist/browser/serialization/json/expression.js.map +1 -0
- package/dist/browser/serialization/json/lower.d.ts +41 -0
- package/dist/browser/serialization/json/lower.d.ts.map +1 -0
- package/dist/browser/serialization/json/lower.js +334 -0
- package/dist/browser/serialization/json/lower.js.map +1 -0
- package/dist/browser/serialization/json/pluralize-config.d.ts +3 -0
- package/dist/browser/serialization/json/pluralize-config.d.ts.map +1 -0
- package/dist/browser/serialization/json/pluralize-config.js +7 -0
- package/dist/browser/serialization/json/pluralize-config.js.map +1 -0
- package/dist/browser/serialization/json/serialize.d.ts +12 -0
- package/dist/browser/serialization/json/serialize.d.ts.map +1 -0
- package/dist/browser/serialization/json/serialize.js +389 -0
- package/dist/browser/serialization/json/serialize.js.map +1 -0
- package/dist/browser/serialization/json/util.d.ts +2 -0
- package/dist/browser/serialization/json/util.d.ts.map +1 -0
- package/dist/browser/serialization/json/util.js +19 -0
- package/dist/browser/serialization/json/util.js.map +1 -0
- package/dist/browser/serialization/utils.d.ts +3 -0
- package/dist/browser/serialization/utils.d.ts.map +1 -0
- package/dist/browser/serialization/utils.js +146 -0
- package/dist/browser/serialization/utils.js.map +1 -0
- package/dist/browser/shape/shape-registry.d.ts +51 -0
- package/dist/browser/shape/shape-registry.d.ts.map +1 -0
- package/dist/browser/shape/shape-registry.js +41 -0
- package/dist/browser/shape/shape-registry.js.map +1 -0
- package/dist/browser/shape/shape.d.ts +407 -0
- package/dist/browser/shape/shape.d.ts.map +1 -0
- package/dist/browser/shape/shape.js +424 -0
- package/dist/browser/shape/shape.js.map +1 -0
- package/dist/browser/shape/value-encoding.d.ts +121 -0
- package/dist/browser/shape/value-encoding.d.ts.map +1 -0
- package/dist/browser/shape/value-encoding.js +32 -0
- package/dist/browser/shape/value-encoding.js.map +1 -0
- package/dist/browser/types.d.ts +9 -0
- package/dist/browser/types.d.ts.map +1 -0
- package/dist/browser/types.js +4 -0
- package/dist/browser/types.js.map +1 -0
- package/dist/browser/util.d.ts +33 -0
- package/dist/browser/util.d.ts.map +1 -0
- package/dist/browser/util.js +74 -0
- package/dist/browser/util.js.map +1 -0
- package/dist/commonjs/constructs/built-in-resources/resource-group.d.ts +50 -0
- package/dist/commonjs/constructs/built-in-resources/resource-group.d.ts.map +1 -0
- package/dist/commonjs/constructs/built-in-resources/resource-group.js +114 -0
- package/dist/commonjs/constructs/built-in-resources/resource-group.js.map +7 -0
- package/dist/commonjs/constructs/output.d.ts +80 -0
- package/dist/commonjs/constructs/output.d.ts.map +1 -0
- package/dist/commonjs/constructs/output.js +75 -0
- package/dist/commonjs/constructs/output.js.map +7 -0
- package/dist/commonjs/constructs/parameter.d.ts +77 -0
- package/dist/commonjs/constructs/parameter.d.ts.map +1 -0
- package/dist/commonjs/constructs/parameter.js +95 -0
- package/dist/commonjs/constructs/parameter.js.map +7 -0
- package/dist/commonjs/constructs/provisioning-component.d.ts +91 -0
- package/dist/commonjs/constructs/provisioning-component.d.ts.map +1 -0
- package/dist/commonjs/constructs/provisioning-component.js +130 -0
- package/dist/commonjs/constructs/provisioning-component.js.map +7 -0
- package/dist/commonjs/constructs/resource/resource-proxy.d.ts +134 -0
- package/dist/commonjs/constructs/resource/resource-proxy.d.ts.map +1 -0
- package/dist/commonjs/constructs/resource/resource-proxy.js +456 -0
- package/dist/commonjs/constructs/resource/resource-proxy.js.map +7 -0
- package/dist/commonjs/constructs/resource/resource-query.d.ts +23 -0
- package/dist/commonjs/constructs/resource/resource-query.d.ts.map +1 -0
- package/dist/commonjs/constructs/resource/resource-query.js +68 -0
- package/dist/commonjs/constructs/resource/resource-query.js.map +7 -0
- package/dist/commonjs/constructs/resource/resource-registry.d.ts +99 -0
- package/dist/commonjs/constructs/resource/resource-registry.d.ts.map +1 -0
- package/dist/commonjs/constructs/resource/resource-registry.js +49 -0
- package/dist/commonjs/constructs/resource/resource-registry.js.map +7 -0
- package/dist/commonjs/constructs/resource/resource-type-registry.d.ts +46 -0
- package/dist/commonjs/constructs/resource/resource-type-registry.d.ts.map +1 -0
- package/dist/commonjs/constructs/resource/resource-type-registry.js +178 -0
- package/dist/commonjs/constructs/resource/resource-type-registry.js.map +7 -0
- package/dist/commonjs/constructs/resource/resource-utils.d.ts +60 -0
- package/dist/commonjs/constructs/resource/resource-utils.d.ts.map +1 -0
- package/dist/commonjs/constructs/resource/resource-utils.js +51 -0
- package/dist/commonjs/constructs/resource/resource-utils.js.map +7 -0
- package/dist/commonjs/constructs/resource/resource.d.ts +460 -0
- package/dist/commonjs/constructs/resource/resource.d.ts.map +1 -0
- package/dist/commonjs/constructs/resource/resource.js +455 -0
- package/dist/commonjs/constructs/resource/resource.js.map +7 -0
- package/dist/commonjs/constructs/stack.d.ts +110 -0
- package/dist/commonjs/constructs/stack.d.ts.map +1 -0
- package/dist/commonjs/constructs/stack.js +101 -0
- package/dist/commonjs/constructs/stack.js.map +7 -0
- package/dist/commonjs/constructs/variable.d.ts +63 -0
- package/dist/commonjs/constructs/variable.d.ts.map +1 -0
- package/dist/commonjs/constructs/variable.js +85 -0
- package/dist/commonjs/constructs/variable.js.map +7 -0
- package/dist/commonjs/deployment-context/deployment-context.d.ts +27 -0
- package/dist/commonjs/deployment-context/deployment-context.d.ts.map +1 -0
- package/dist/commonjs/deployment-context/deployment-context.js +16 -0
- package/dist/commonjs/deployment-context/deployment-context.js.map +7 -0
- package/dist/commonjs/expression/ast-nodes.d.ts +100 -0
- package/dist/commonjs/expression/ast-nodes.d.ts.map +1 -0
- package/dist/commonjs/expression/ast-nodes.js +152 -0
- package/dist/commonjs/expression/ast-nodes.js.map +7 -0
- package/dist/commonjs/expression/expressions.d.ts +164 -0
- package/dist/commonjs/expression/expressions.d.ts.map +1 -0
- package/dist/commonjs/expression/expressions.js +171 -0
- package/dist/commonjs/expression/expressions.js.map +7 -0
- package/dist/commonjs/fn.d.ts +194 -0
- package/dist/commonjs/fn.d.ts.map +1 -0
- package/dist/commonjs/fn.js +382 -0
- package/dist/commonjs/fn.js.map +7 -0
- package/dist/commonjs/index.d.ts +25 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +93 -0
- package/dist/commonjs/index.js.map +7 -0
- package/dist/commonjs/internal.d.ts +13 -0
- package/dist/commonjs/internal.d.ts.map +1 -0
- package/dist/commonjs/internal.js +88 -0
- package/dist/commonjs/internal.js.map +7 -0
- package/dist/commonjs/naming/naming-policy.d.ts +56 -0
- package/dist/commonjs/naming/naming-policy.d.ts.map +1 -0
- package/dist/commonjs/naming/naming-policy.js +99 -0
- package/dist/commonjs/naming/naming-policy.js.map +7 -0
- package/dist/commonjs/naming/naming-rules.d.ts +15 -0
- package/dist/commonjs/naming/naming-rules.d.ts.map +1 -0
- package/dist/commonjs/naming/naming-rules.js +39 -0
- package/dist/commonjs/naming/naming-rules.js.map +7 -0
- package/dist/commonjs/package.json +8 -0
- package/dist/commonjs/serialization/contract/generated/ast.d.ts +508 -0
- package/dist/commonjs/serialization/contract/generated/ast.d.ts.map +1 -0
- package/dist/commonjs/serialization/contract/generated/ast.js +40 -0
- package/dist/commonjs/serialization/contract/generated/ast.js.map +7 -0
- package/dist/commonjs/serialization/contract/index.d.ts +2 -0
- package/dist/commonjs/serialization/contract/index.d.ts.map +1 -0
- package/dist/commonjs/serialization/contract/index.js +22 -0
- package/dist/commonjs/serialization/contract/index.js.map +7 -0
- package/dist/commonjs/serialization/index.d.ts +4 -0
- package/dist/commonjs/serialization/index.d.ts.map +1 -0
- package/dist/commonjs/serialization/index.js +31 -0
- package/dist/commonjs/serialization/index.js.map +7 -0
- package/dist/commonjs/serialization/json/deserialize.d.ts +24 -0
- package/dist/commonjs/serialization/json/deserialize.d.ts.map +1 -0
- package/dist/commonjs/serialization/json/deserialize.js +385 -0
- package/dist/commonjs/serialization/json/deserialize.js.map +7 -0
- package/dist/commonjs/serialization/json/encoding.d.ts +4 -0
- package/dist/commonjs/serialization/json/encoding.d.ts.map +1 -0
- package/dist/commonjs/serialization/json/encoding.js +306 -0
- package/dist/commonjs/serialization/json/encoding.js.map +7 -0
- package/dist/commonjs/serialization/json/expression.d.ts +32 -0
- package/dist/commonjs/serialization/json/expression.d.ts.map +1 -0
- package/dist/commonjs/serialization/json/expression.js +509 -0
- package/dist/commonjs/serialization/json/expression.js.map +7 -0
- package/dist/commonjs/serialization/json/lower.d.ts +41 -0
- package/dist/commonjs/serialization/json/lower.d.ts.map +1 -0
- package/dist/commonjs/serialization/json/lower.js +272 -0
- package/dist/commonjs/serialization/json/lower.js.map +7 -0
- package/dist/commonjs/serialization/json/pluralize-config.d.ts +3 -0
- package/dist/commonjs/serialization/json/pluralize-config.d.ts.map +1 -0
- package/dist/commonjs/serialization/json/pluralize-config.js +37 -0
- package/dist/commonjs/serialization/json/pluralize-config.js.map +7 -0
- package/dist/commonjs/serialization/json/serialize.d.ts +12 -0
- package/dist/commonjs/serialization/json/serialize.d.ts.map +1 -0
- package/dist/commonjs/serialization/json/serialize.js +352 -0
- package/dist/commonjs/serialization/json/serialize.js.map +7 -0
- package/dist/commonjs/serialization/json/util.d.ts +2 -0
- package/dist/commonjs/serialization/json/util.d.ts.map +1 -0
- package/dist/commonjs/serialization/json/util.js +37 -0
- package/dist/commonjs/serialization/json/util.js.map +7 -0
- package/dist/commonjs/serialization/utils.d.ts +3 -0
- package/dist/commonjs/serialization/utils.d.ts.map +1 -0
- package/dist/commonjs/serialization/utils.js +169 -0
- package/dist/commonjs/serialization/utils.js.map +7 -0
- package/dist/commonjs/shape/shape-registry.d.ts +51 -0
- package/dist/commonjs/shape/shape-registry.d.ts.map +1 -0
- package/dist/commonjs/shape/shape-registry.js +40 -0
- package/dist/commonjs/shape/shape-registry.js.map +7 -0
- package/dist/commonjs/shape/shape.d.ts +407 -0
- package/dist/commonjs/shape/shape.d.ts.map +1 -0
- package/dist/commonjs/shape/shape.js +290 -0
- package/dist/commonjs/shape/shape.js.map +7 -0
- package/dist/commonjs/shape/value-encoding.d.ts +121 -0
- package/dist/commonjs/shape/value-encoding.d.ts.map +1 -0
- package/dist/commonjs/shape/value-encoding.js +62 -0
- package/dist/commonjs/shape/value-encoding.js.map +7 -0
- package/dist/commonjs/tsdoc-metadata.json +11 -0
- package/dist/commonjs/types.d.ts +9 -0
- package/dist/commonjs/types.d.ts.map +1 -0
- package/dist/commonjs/types.js +16 -0
- package/dist/commonjs/types.js.map +7 -0
- package/dist/commonjs/util.d.ts +33 -0
- package/dist/commonjs/util.d.ts.map +1 -0
- package/dist/commonjs/util.js +73 -0
- package/dist/commonjs/util.js.map +7 -0
- package/dist/esm/constructs/built-in-resources/resource-group.d.ts +50 -0
- package/dist/esm/constructs/built-in-resources/resource-group.d.ts.map +1 -0
- package/dist/esm/constructs/built-in-resources/resource-group.js +100 -0
- package/dist/esm/constructs/built-in-resources/resource-group.js.map +1 -0
- package/dist/esm/constructs/output.d.ts +80 -0
- package/dist/esm/constructs/output.d.ts.map +1 -0
- package/dist/esm/constructs/output.js +75 -0
- package/dist/esm/constructs/output.js.map +1 -0
- package/dist/esm/constructs/parameter.d.ts +77 -0
- package/dist/esm/constructs/parameter.d.ts.map +1 -0
- package/dist/esm/constructs/parameter.js +93 -0
- package/dist/esm/constructs/parameter.js.map +1 -0
- package/dist/esm/constructs/provisioning-component.d.ts +91 -0
- package/dist/esm/constructs/provisioning-component.d.ts.map +1 -0
- package/dist/esm/constructs/provisioning-component.js +150 -0
- package/dist/esm/constructs/provisioning-component.js.map +1 -0
- package/dist/esm/constructs/resource/resource-proxy.d.ts +134 -0
- package/dist/esm/constructs/resource/resource-proxy.d.ts.map +1 -0
- package/dist/esm/constructs/resource/resource-proxy.js +517 -0
- package/dist/esm/constructs/resource/resource-proxy.js.map +1 -0
- package/dist/esm/constructs/resource/resource-query.d.ts +23 -0
- package/dist/esm/constructs/resource/resource-query.d.ts.map +1 -0
- package/dist/esm/constructs/resource/resource-query.js +69 -0
- package/dist/esm/constructs/resource/resource-query.js.map +1 -0
- package/dist/esm/constructs/resource/resource-registry.d.ts +99 -0
- package/dist/esm/constructs/resource/resource-registry.d.ts.map +1 -0
- package/dist/esm/constructs/resource/resource-registry.js +51 -0
- package/dist/esm/constructs/resource/resource-registry.js.map +1 -0
- package/dist/esm/constructs/resource/resource-type-registry.d.ts +46 -0
- package/dist/esm/constructs/resource/resource-type-registry.d.ts.map +1 -0
- package/dist/esm/constructs/resource/resource-type-registry.js +156 -0
- package/dist/esm/constructs/resource/resource-type-registry.js.map +1 -0
- package/dist/esm/constructs/resource/resource-utils.d.ts +60 -0
- package/dist/esm/constructs/resource/resource-utils.d.ts.map +1 -0
- package/dist/esm/constructs/resource/resource-utils.js +75 -0
- package/dist/esm/constructs/resource/resource-utils.js.map +1 -0
- package/dist/esm/constructs/resource/resource.d.ts +460 -0
- package/dist/esm/constructs/resource/resource.d.ts.map +1 -0
- package/dist/esm/constructs/resource/resource.js +582 -0
- package/dist/esm/constructs/resource/resource.js.map +1 -0
- package/dist/esm/constructs/stack.d.ts +110 -0
- package/dist/esm/constructs/stack.d.ts.map +1 -0
- package/dist/esm/constructs/stack.js +110 -0
- package/dist/esm/constructs/stack.js.map +1 -0
- package/dist/esm/constructs/variable.d.ts +63 -0
- package/dist/esm/constructs/variable.d.ts.map +1 -0
- package/dist/esm/constructs/variable.js +74 -0
- package/dist/esm/constructs/variable.js.map +1 -0
- package/dist/esm/deployment-context/deployment-context.d.ts +27 -0
- package/dist/esm/deployment-context/deployment-context.d.ts.map +1 -0
- package/dist/esm/deployment-context/deployment-context.js +4 -0
- package/dist/esm/deployment-context/deployment-context.js.map +1 -0
- package/dist/esm/expression/ast-nodes.d.ts +100 -0
- package/dist/esm/expression/ast-nodes.d.ts.map +1 -0
- package/dist/esm/expression/ast-nodes.js +125 -0
- package/dist/esm/expression/ast-nodes.js.map +1 -0
- package/dist/esm/expression/expressions.d.ts +164 -0
- package/dist/esm/expression/expressions.d.ts.map +1 -0
- package/dist/esm/expression/expressions.js +211 -0
- package/dist/esm/expression/expressions.js.map +1 -0
- package/dist/esm/fn.d.ts +194 -0
- package/dist/esm/fn.d.ts.map +1 -0
- package/dist/esm/fn.js +334 -0
- package/dist/esm/fn.js.map +1 -0
- package/dist/esm/index.d.ts +25 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal.d.ts +13 -0
- package/dist/esm/internal.d.ts.map +1 -0
- package/dist/esm/internal.js +10 -0
- package/dist/esm/internal.js.map +1 -0
- package/dist/esm/naming/naming-policy.d.ts +56 -0
- package/dist/esm/naming/naming-policy.d.ts.map +1 -0
- package/dist/esm/naming/naming-policy.js +97 -0
- package/dist/esm/naming/naming-policy.js.map +1 -0
- package/dist/esm/naming/naming-rules.d.ts +15 -0
- package/dist/esm/naming/naming-rules.d.ts.map +1 -0
- package/dist/esm/naming/naming-rules.js +15 -0
- package/dist/esm/naming/naming-rules.js.map +1 -0
- package/dist/esm/package.json +8 -0
- package/dist/esm/serialization/contract/generated/ast.d.ts +508 -0
- package/dist/esm/serialization/contract/generated/ast.d.ts.map +1 -0
- package/dist/esm/serialization/contract/generated/ast.js +23 -0
- package/dist/esm/serialization/contract/generated/ast.js.map +1 -0
- package/dist/esm/serialization/contract/index.d.ts +2 -0
- package/dist/esm/serialization/contract/index.d.ts.map +1 -0
- package/dist/esm/serialization/contract/index.js +4 -0
- package/dist/esm/serialization/contract/index.js.map +1 -0
- package/dist/esm/serialization/index.d.ts +4 -0
- package/dist/esm/serialization/index.d.ts.map +1 -0
- package/dist/esm/serialization/index.js +5 -0
- package/dist/esm/serialization/index.js.map +1 -0
- package/dist/esm/serialization/json/deserialize.d.ts +24 -0
- package/dist/esm/serialization/json/deserialize.d.ts.map +1 -0
- package/dist/esm/serialization/json/deserialize.js +437 -0
- package/dist/esm/serialization/json/deserialize.js.map +1 -0
- package/dist/esm/serialization/json/encoding.d.ts +4 -0
- package/dist/esm/serialization/json/encoding.d.ts.map +1 -0
- package/dist/esm/serialization/json/encoding.js +319 -0
- package/dist/esm/serialization/json/encoding.js.map +1 -0
- package/dist/esm/serialization/json/expression.d.ts +32 -0
- package/dist/esm/serialization/json/expression.d.ts.map +1 -0
- package/dist/esm/serialization/json/expression.js +494 -0
- package/dist/esm/serialization/json/expression.js.map +1 -0
- package/dist/esm/serialization/json/lower.d.ts +41 -0
- package/dist/esm/serialization/json/lower.d.ts.map +1 -0
- package/dist/esm/serialization/json/lower.js +334 -0
- package/dist/esm/serialization/json/lower.js.map +1 -0
- package/dist/esm/serialization/json/pluralize-config.d.ts +3 -0
- package/dist/esm/serialization/json/pluralize-config.d.ts.map +1 -0
- package/dist/esm/serialization/json/pluralize-config.js +7 -0
- package/dist/esm/serialization/json/pluralize-config.js.map +1 -0
- package/dist/esm/serialization/json/serialize.d.ts +12 -0
- package/dist/esm/serialization/json/serialize.d.ts.map +1 -0
- package/dist/esm/serialization/json/serialize.js +389 -0
- package/dist/esm/serialization/json/serialize.js.map +1 -0
- package/dist/esm/serialization/json/util.d.ts +2 -0
- package/dist/esm/serialization/json/util.d.ts.map +1 -0
- package/dist/esm/serialization/json/util.js +19 -0
- package/dist/esm/serialization/json/util.js.map +1 -0
- package/dist/esm/serialization/utils.d.ts +3 -0
- package/dist/esm/serialization/utils.d.ts.map +1 -0
- package/dist/esm/serialization/utils.js +146 -0
- package/dist/esm/serialization/utils.js.map +1 -0
- package/dist/esm/shape/shape-registry.d.ts +51 -0
- package/dist/esm/shape/shape-registry.d.ts.map +1 -0
- package/dist/esm/shape/shape-registry.js +41 -0
- package/dist/esm/shape/shape-registry.js.map +1 -0
- package/dist/esm/shape/shape.d.ts +407 -0
- package/dist/esm/shape/shape.d.ts.map +1 -0
- package/dist/esm/shape/shape.js +424 -0
- package/dist/esm/shape/shape.js.map +1 -0
- package/dist/esm/shape/value-encoding.d.ts +121 -0
- package/dist/esm/shape/value-encoding.d.ts.map +1 -0
- package/dist/esm/shape/value-encoding.js +32 -0
- package/dist/esm/shape/value-encoding.js.map +1 -0
- package/dist/esm/types.d.ts +9 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +4 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/util.d.ts +33 -0
- package/dist/esm/util.d.ts.map +1 -0
- package/dist/esm/util.js +74 -0
- package/dist/esm/util.js.map +1 -0
- package/package.json +117 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { Resource } from "../constructs/resource/resource.js";
|
|
2
|
+
import type { BinaryOperator, UnaryOperator } from "../serialization/contract/index.js";
|
|
3
|
+
import type { PropertySegment } from "../types.js";
|
|
4
|
+
export type { BinaryOperator, UnaryOperator };
|
|
5
|
+
export interface FunctionCallExpressionNode<_TValue = unknown, TOperator extends string = string> {
|
|
6
|
+
readonly kind: "fn-call";
|
|
7
|
+
readonly operator: TOperator;
|
|
8
|
+
readonly args: readonly unknown[];
|
|
9
|
+
}
|
|
10
|
+
export interface SymbolicValueExpressionNode<_TValue = unknown, TPath extends string = string> {
|
|
11
|
+
readonly kind: "symbolic-value";
|
|
12
|
+
readonly path: TPath;
|
|
13
|
+
}
|
|
14
|
+
export interface IdentifierExpressionNode<_TValue = unknown> {
|
|
15
|
+
readonly kind: "identifier";
|
|
16
|
+
readonly id: string | Resource;
|
|
17
|
+
}
|
|
18
|
+
export interface PropertyAccessExpressionNode<_TValue = unknown> {
|
|
19
|
+
readonly kind: "property-access";
|
|
20
|
+
readonly base: ExpressionNode;
|
|
21
|
+
readonly property: string;
|
|
22
|
+
readonly nullish: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Optional ARM wire-path segments. When present, the serialization
|
|
25
|
+
* lowering pass rewrites this single access into a chain that walks
|
|
26
|
+
* these segments (handling renames + `@flattenProperty` hoisting).
|
|
27
|
+
* Untyped / hand-built expressions leave this `undefined` and pass
|
|
28
|
+
* through unchanged.
|
|
29
|
+
*/
|
|
30
|
+
readonly armPath?: readonly string[] | undefined;
|
|
31
|
+
}
|
|
32
|
+
export interface ArrayAccessExpressionNode<_TValue = unknown> {
|
|
33
|
+
readonly kind: "array-access";
|
|
34
|
+
readonly base: ExpressionNode;
|
|
35
|
+
/**
|
|
36
|
+
* The index into the array. A literal `number`/`string` lowers to an
|
|
37
|
+
* integer/string array-access (or a property-access for identifier-like
|
|
38
|
+
* strings) at serialize time. Any {@link ExpressionNode} is serialized
|
|
39
|
+
* recursively into the wire array-access's `index` slot — e.g. a looped
|
|
40
|
+
* `.at(loop.index)` stores the unwrapped `symbolic-value` node (emitting
|
|
41
|
+
* `sym[i]`), and a computed offset stores a `binary` / `fn-call` node
|
|
42
|
+
* (`sym[i + 1]`). `Expression<T>` proxies are always unwrapped to their
|
|
43
|
+
* raw node before landing here, per the "state holds normalized raw
|
|
44
|
+
* nodes" invariant — so a proxy is never stored directly.
|
|
45
|
+
*/
|
|
46
|
+
readonly index: ArrayAccessIndex;
|
|
47
|
+
readonly nullish: boolean;
|
|
48
|
+
readonly fromEnd: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface BinaryExpressionNode<_TValue = unknown> {
|
|
51
|
+
readonly kind: "binary";
|
|
52
|
+
readonly operator: BinaryOperator;
|
|
53
|
+
readonly left: unknown;
|
|
54
|
+
readonly right: unknown;
|
|
55
|
+
}
|
|
56
|
+
export interface UnaryExpressionNode<_TValue = unknown> {
|
|
57
|
+
readonly kind: "unary";
|
|
58
|
+
readonly operator: UnaryOperator;
|
|
59
|
+
readonly argument: unknown;
|
|
60
|
+
}
|
|
61
|
+
export interface TernaryExpressionNode<_TValue = unknown> {
|
|
62
|
+
readonly kind: "ternary";
|
|
63
|
+
readonly condition: unknown;
|
|
64
|
+
readonly trueValue: unknown;
|
|
65
|
+
readonly falseValue: unknown;
|
|
66
|
+
}
|
|
67
|
+
export interface InstanceFunctionCallExpressionNode<_TValue = unknown> {
|
|
68
|
+
readonly kind: "instance-function-call";
|
|
69
|
+
readonly base: ExpressionNode;
|
|
70
|
+
readonly name: string;
|
|
71
|
+
readonly args: readonly unknown[];
|
|
72
|
+
}
|
|
73
|
+
export interface InterpolatedStringExpressionNode<_TValue = unknown> {
|
|
74
|
+
readonly kind: "interpolated-string";
|
|
75
|
+
readonly segments: readonly unknown[];
|
|
76
|
+
}
|
|
77
|
+
export type ExpressionNode<T = unknown> = FunctionCallExpressionNode<T> | SymbolicValueExpressionNode<T> | IdentifierExpressionNode<T> | PropertyAccessExpressionNode<T> | ArrayAccessExpressionNode<T> | BinaryExpressionNode<T> | UnaryExpressionNode<T> | TernaryExpressionNode<T> | InstanceFunctionCallExpressionNode<T> | InterpolatedStringExpressionNode<T>;
|
|
78
|
+
/**
|
|
79
|
+
* The index stored on an {@link ArrayAccessExpressionNode}: a literal
|
|
80
|
+
* `number` or `string`, or a raw {@link ExpressionNode} evaluated at
|
|
81
|
+
* serialize time (e.g. a loop's `symbolic-value` index, or a `binary` /
|
|
82
|
+
* `fn-call` node for a computed offset). `Expression<T>` proxies are
|
|
83
|
+
* unwrapped to their raw node before being stored, so the proxy type is
|
|
84
|
+
* intentionally absent here.
|
|
85
|
+
*/
|
|
86
|
+
export type ArrayAccessIndex = number | string | ExpressionNode;
|
|
87
|
+
/** Tests whether a value structurally matches a raw expression AST node. */
|
|
88
|
+
export declare function isExpressionNode(value: unknown): value is ExpressionNode;
|
|
89
|
+
export declare function functionCallExpressionNode<TValue = unknown, TOperator extends string = string>(operator: TOperator, args: readonly unknown[]): FunctionCallExpressionNode<TValue, TOperator>;
|
|
90
|
+
export declare function symbolicValueExpressionNode<TValue = unknown, TPath extends string = string>(path: TPath): SymbolicValueExpressionNode<TValue, TPath>;
|
|
91
|
+
export declare function identifierExpressionNode<TValue = unknown>(identifier: string | Resource): IdentifierExpressionNode<TValue>;
|
|
92
|
+
export declare function propertyAccessExpressionNode<TValue = unknown>(base: ExpressionNode, property: string, options?: Partial<Pick<PropertyAccessExpressionNode, "armPath" | "nullish">>): PropertyAccessExpressionNode<TValue>;
|
|
93
|
+
export declare function arrayAccessExpressionNode<TValue = unknown>(base: ExpressionNode, index: ArrayAccessIndex, options?: Partial<Pick<ArrayAccessExpressionNode, "nullish" | "fromEnd">>): ArrayAccessExpressionNode<TValue>;
|
|
94
|
+
export declare function binaryExpressionNode<TValue = unknown>(operator: BinaryOperator, left: unknown, right: unknown): BinaryExpressionNode<TValue>;
|
|
95
|
+
export declare function unaryExpressionNode<TValue = unknown>(operator: UnaryOperator, argument: unknown): UnaryExpressionNode<TValue>;
|
|
96
|
+
export declare function ternaryExpressionNode<TValue = unknown>(condition: unknown, trueValue: unknown, falseValue: unknown): TernaryExpressionNode<TValue>;
|
|
97
|
+
export declare function instanceFunctionCallExpressionNode<TValue = unknown>(base: ExpressionNode, name: string, args: readonly unknown[]): InstanceFunctionCallExpressionNode<TValue>;
|
|
98
|
+
export declare function interpolatedStringExpressionNode<TValue = unknown>(segments: readonly unknown[]): InterpolatedStringExpressionNode<TValue>;
|
|
99
|
+
export declare function accessExpressionNode(base: ExpressionNode, member: PropertySegment, options?: Partial<Pick<PropertyAccessExpressionNode, "armPath" | "nullish">>): PropertyAccessExpressionNode | ArrayAccessExpressionNode;
|
|
100
|
+
//# sourceMappingURL=ast-nodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-nodes.d.ts","sourceRoot":"","sources":["../../../src/expression/ast-nodes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACxF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AAe9C,MAAM,WAAW,0BAA0B,CAAC,OAAO,GAAG,OAAO,EAAE,SAAS,SAAS,MAAM,GAAG,MAAM;IAC9F,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,2BAA2B,CAAC,OAAO,GAAG,OAAO,EAAE,KAAK,SAAS,MAAM,GAAG,M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AmB,CAAC,MAAM,CAAC,CAE7B;AAED,wBAAgB,qBAAqB,CAAC,MAAM,GAAG,OAAO,EACpD,SAAS,EAAE,OAAO,EAClB,SAAS,EAAE,OAAO,EAClB,UAAU,EAAE,OAAO,GAClB,qBAAqB,CAAC,MAAM,CAAC,CAO/B;AAED,wBAAgB,kCAAkC,CAAC,MAAM,GAAG,OAAO,EACjE,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,SAAS,OAAO,EAAE,GACvB,kCAAkC,CAAC,MAAM,CAAC,CAO5C;AAED,wBAAgB,gCAAgC,CAAC,MAAM,GAAG,OAAO,EAC/D,QAAQ,EAAE,SAAS,OAAO,EAAE,GAC3B,gCAAgC,CAAC,MAAM,CAAC,CAE1C;AAUD,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,eAAe,EACvB,OAAO,GAAE,OAAO,CAAC,IAAI,CAAC,4BAA4B,EAAE,SAAS,GAAG,SAAS,CAAC,CAAM,GAC/E,4BAA4B,GAAG,yBAAyB,CAI1D"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
// Typed as `Record<ExpressionNode["kind"], true>` so adding a new variant to
|
|
4
|
+
// `ExpressionNode` forces a compile error here until the new kind is listed.
|
|
5
|
+
const EXPRESSION_NODE_KINDS = {
|
|
6
|
+
"fn-call": true,
|
|
7
|
+
"symbolic-value": true,
|
|
8
|
+
identifier: true,
|
|
9
|
+
"property-access": true,
|
|
10
|
+
"array-access": true,
|
|
11
|
+
binary: true,
|
|
12
|
+
unary: true,
|
|
13
|
+
ternary: true,
|
|
14
|
+
"instance-function-call": true,
|
|
15
|
+
"interpolated-string": true,
|
|
16
|
+
};
|
|
17
|
+
/** Tests whether a value structurally matches a raw expression AST node. */
|
|
18
|
+
export function isExpressionNode(value) {
|
|
19
|
+
if (typeof value !== "object" ||
|
|
20
|
+
value === null ||
|
|
21
|
+
!Object.prototype.hasOwnProperty.call(value, "kind") ||
|
|
22
|
+
typeof value.kind !== "string") {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const node = value;
|
|
26
|
+
if (!Object.prototype.hasOwnProperty.call(EXPRESSION_NODE_KINDS, node.kind)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
switch (node.kind) {
|
|
30
|
+
case "fn-call":
|
|
31
|
+
return typeof node.operator === "string" && Array.isArray(node.args);
|
|
32
|
+
case "symbolic-value":
|
|
33
|
+
return typeof node.path === "string";
|
|
34
|
+
case "identifier":
|
|
35
|
+
return typeof node.id === "string" || typeof node.id === "object";
|
|
36
|
+
case "property-access":
|
|
37
|
+
return (isExpressionNode(node.base) &&
|
|
38
|
+
typeof node.property === "string" &&
|
|
39
|
+
typeof node.nullish === "boolean");
|
|
40
|
+
case "array-access":
|
|
41
|
+
return (isExpressionNode(node.base) &&
|
|
42
|
+
"index" in node &&
|
|
43
|
+
typeof node.nullish === "boolean" &&
|
|
44
|
+
typeof node.fromEnd === "boolean");
|
|
45
|
+
case "binary":
|
|
46
|
+
return typeof node.operator === "string" && "left" in node && "right" in node;
|
|
47
|
+
case "unary":
|
|
48
|
+
return typeof node.operator === "string" && "argument" in node;
|
|
49
|
+
case "ternary":
|
|
50
|
+
return "condition" in node && "trueValue" in node && "falseValue" in node;
|
|
51
|
+
case "instance-function-call":
|
|
52
|
+
return (isExpressionNode(node.base) && typeof node.name === "string" && Array.isArray(node.args));
|
|
53
|
+
case "interpolated-string":
|
|
54
|
+
return Array.isArray(node.segments);
|
|
55
|
+
default:
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
// Factory functions
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
export function functionCallExpressionNode(operator, args) {
|
|
63
|
+
return { kind: "fn-call", operator, args };
|
|
64
|
+
}
|
|
65
|
+
export function symbolicValueExpressionNode(path) {
|
|
66
|
+
return { kind: "symbolic-value", path };
|
|
67
|
+
}
|
|
68
|
+
export function identifierExpressionNode(identifier) {
|
|
69
|
+
return { kind: "identifier", id: identifier };
|
|
70
|
+
}
|
|
71
|
+
export function propertyAccessExpressionNode(base, property, options = {}) {
|
|
72
|
+
return {
|
|
73
|
+
kind: "property-access",
|
|
74
|
+
base,
|
|
75
|
+
property,
|
|
76
|
+
nullish: options.nullish ?? false,
|
|
77
|
+
...(options.armPath === undefined ? {} : { armPath: options.armPath }),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export function arrayAccessExpressionNode(base, index, options = {}) {
|
|
81
|
+
return {
|
|
82
|
+
kind: "array-access",
|
|
83
|
+
base,
|
|
84
|
+
index,
|
|
85
|
+
nullish: options.nullish ?? false,
|
|
86
|
+
fromEnd: options.fromEnd ?? false,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export function binaryExpressionNode(operator, left, right) {
|
|
90
|
+
return { kind: "binary", operator, left, right };
|
|
91
|
+
}
|
|
92
|
+
export function unaryExpressionNode(operator, argument) {
|
|
93
|
+
return { kind: "unary", operator, argument };
|
|
94
|
+
}
|
|
95
|
+
export function ternaryExpressionNode(condition, trueValue, falseValue) {
|
|
96
|
+
return {
|
|
97
|
+
kind: "ternary",
|
|
98
|
+
condition,
|
|
99
|
+
trueValue,
|
|
100
|
+
falseValue,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export function instanceFunctionCallExpressionNode(base, name, args) {
|
|
104
|
+
return {
|
|
105
|
+
kind: "instance-function-call",
|
|
106
|
+
base,
|
|
107
|
+
name,
|
|
108
|
+
args,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export function interpolatedStringExpressionNode(segments) {
|
|
112
|
+
return { kind: "interpolated-string", segments };
|
|
113
|
+
}
|
|
114
|
+
// ---------------------------------------------------------------------------
|
|
115
|
+
// Helpers
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
function isIdentifierSegment(segment) {
|
|
118
|
+
return /^[A-Za-z_][A-Za-z0-9_]*$/u.test(segment);
|
|
119
|
+
}
|
|
120
|
+
export function accessExpressionNode(base, member, options = {}) {
|
|
121
|
+
return typeof member === "number" || !isIdentifierSegment(member)
|
|
122
|
+
? arrayAccessExpressionNode(base, member, options)
|
|
123
|
+
: propertyAccessExpressionNode(base, member, options);
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=ast-nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-nodes.js","sourceRoot":"","sources":["../../../src/expression/ast-nodes.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAmIlC,6EAA6E;AAC7E,6EAA6E;AAC7E,MAAM,qBAAqB,GAAyC;IAClE,SAAS,EAAE,IAAI;IACf,gBAAgB,EAAE,IAAI;IACtB,UAAU,EAAE,IAAI;IAChB,iBAAiB,EAAE,IAAI;IACvB,cAAc,EAAE,IAAI;IACpB,MAAM,EAAE,IAAI;IACZ,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,IAAI;IACb,wBAAwB,EAAE,IAAI;IAC9B,qBAAqB,EAAE,IAAI;CAC5B,CAAC;AAEF,4EAA4E;AAC5E,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC;QACpD,OAAQ,KAA2B,CAAC,IAAI,KAAK,QAAQ,EACrD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,IAAI,GAAG,KAAgC,CAAC;IAC9C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,qBAAqB,EAAE,IAAI,CAAC,IAAc,CAAC,EAAE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../constructs/resource/resource.js\";\nimport type { BinaryOperator, UnaryOperator } from \"../serialization/contract/index.js\";\nimport type { PropertySegment } from \"../types.js\";\n\nexport type { BinaryOperator, UnaryOperator };\n\n// ---------------------------------------------------------------------------\n// Expression node interfaces (the raw discriminated union members)\n// ---------------------------------------------------------------------------\n\n// Note: every interface declares a phantom `TValue` (when otherwise it wouldn't\n// need one). `TValue` is *not* used in any field of any interface — but its\n// presence in the variant *type-parameter slot* is what allows\n// `ExpressionNode<T>` to thread `T` through to each variant, which in turn is\n// what lets `ExpressionBrand<T>` carry inference-visible `T` across project-\n// reference boundaries. Removing `TValue` and making `ExpressionNode<T>` a\n// fully-phantom alias breaks `coalesce<T>(...)` inference and the\n// `as DeploymentParameter<...>` cast in cross-project consumers (e.g. `demo`).\n\nexport interface FunctionCallExpressionNode<_TValue = unknown, TOperator extends string = string> {\n readonly kind: \"fn-call\";\n readonly operator: TOperator;\n readonly args: readonly unknown[];\n}\n\nexport interface SymbolicValueExpressionNode<_TValue = unknown, TPath extends string = string> {\n readonly kind: \"symbolic-value\";\n readonly path: TPath;\n}\n\nexport interface IdentifierExpressionNode<_TValue = unknown> {\n readonly kind: \"identifier\";\n readonly id: string | Resource;\n}\n\nexport interface PropertyAccessExpressionNode<_TValue = unknown> {\n readonly kind: \"property-access\";\n readonly base: ExpressionNode;\n readonly property: string;\n readonly nullish: boolean;\n /**\n * Optional ARM wire-path segments. When present, the serialization\n * lowering pass rewrites this single access into a chain that walks\n * these segments (handling renames + `@flattenProperty` hoisting).\n * Untyped / hand-built expressions leave this `undefined` and pass\n * through unchanged.\n */\n readonly armPath?: readonly string[] | undefined;\n}\n\nexport interface ArrayAccessExpressionNode<_TValue = unknown> {\n readonly kind: \"array-access\";\n readonly base: ExpressionNode;\n /**\n * The index into the array. A literal `number`/`string` lowers to an\n * integer/string array-access (or a property-access for identifier-like\n * strings) at serialize time. Any {@link ExpressionNode} is serialized\n * recursively into the wire array-access's `index` slot — e.g. a looped\n * `.at(loop.index)` stores the unwrapped `symbolic-value` node (emitting\n * `sym[i]`), and a computed offset stores a `binary` / `fn-call` node\n * (`sym[i + 1]`). `Expression<T>` proxies are always unwrapped to their\n * raw node before landing here, per the \"state holds normalized raw\n * nodes\" invariant — so a proxy is never stored directly.\n */\n readonly index: ArrayAccessIndex;\n readonly nullish: boolean;\n readonly fromEnd: boolean;\n}\n\nexport interface BinaryExpressionNode<_TValue = unknown> {\n readonly kind: \"binary\";\n readonly operator: BinaryOperator;\n readonly left: unknown;\n readonly right: unknown;\n}\n\nexport interface UnaryExpressionNode<_TValue = unknown> {\n readonly kind: \"unary\";\n readonly operator: UnaryOperator;\n readonly argument: unknown;\n}\n\nexport interface TernaryExpressionNode<_TValue = unknown> {\n readonly kind: \"ternary\";\n readonly condition: unknown;\n readonly trueValue: unknown;\n readonly falseValue: unknown;\n}\n\nexport interface InstanceFunctionCallExpressionNode<_TValue = unknown> {\n readonly kind: \"instance-function-call\";\n readonly base: ExpressionNode;\n readonly name: string;\n readonly args: readonly unknown[];\n}\n\nexport interface InterpolatedStringExpressionNode<_TValue = unknown> {\n readonly kind: \"interpolated-string\";\n readonly segments: readonly unknown[];\n}\n\n// ---------------------------------------------------------------------------\n// ExpressionNode union\n// ---------------------------------------------------------------------------\n\n// `T` is threaded through every variant. See the long comment above the node\n// interfaces for why this matters.\nexport type ExpressionNode<T = unknown> =\n | FunctionCallExpressionNode<T>\n | SymbolicValueExpressionNode<T>\n | IdentifierExpressionNode<T>\n | PropertyAccessExpressionNode<T>\n | ArrayAccessExpressionNode<T>\n | BinaryExpressionNode<T>\n | UnaryExpressionNode<T>\n | TernaryExpressionNode<T>\n | InstanceFunctionCallExpressionNode<T>\n | InterpolatedStringExpressionNode<T>;\n\n/**\n * The index stored on an {@link ArrayAccessExpressionNode}: a literal\n * `number` or `string`, or a raw {@link ExpressionNode} evaluated at\n * serialize time (e.g. a loop's `symbolic-value` index, or a `binary` /\n * `fn-call` node for a computed offset). `Expression<T>` proxies are\n * unwrapped to their raw node before being stored, so the proxy type is\n * intentionally absent here.\n */\nexport type ArrayAccessIndex = number | string | ExpressionNode;\n\n// Typed as `Record<ExpressionNode[\"kind\"], true>` so adding a new variant to\n// `ExpressionNode` forces a compile error here until the new kind is listed.\nconst EXPRESSION_NODE_KINDS: Record<ExpressionNode[\"kind\"], true> = {\n \"fn-call\": true,\n \"symbolic-value\": true,\n identifier: true,\n \"property-access\": true,\n \"array-access\": true,\n binary: true,\n unary: true,\n ternary: true,\n \"instance-function-call\": true,\n \"interpolated-string\": true,\n};\n\n/** Tests whether a value structurally matches a raw expression AST node. */\nexport function isExpressionNode(value: unknown): value is ExpressionNode {\n if (\n typeof value !== \"object\" ||\n value === null ||\n !Object.prototype.hasOwnProperty.call(value, \"kind\") ||\n typeof (value as { kind: unknown }).kind !== \"string\"\n ) {\n return false;\n }\n const node = value as Record<string, unknown>;\n if (!Object.prototype.hasOwnProperty.call(EXPRESSION_NODE_KINDS, node.kind as string)) {\n return false;\n }\n switch (node.kind) {\n case \"fn-call\":\n return typeof node.operator === \"string\" && Array.isArray(node.args);\n case \"symbolic-value\":\n return typeof node.path === \"string\";\n case \"identifier\":\n return typeof node.id === \"string\" || typeof node.id === \"object\";\n case \"property-access\":\n return (\n isExpressionNode(node.base) &&\n typeof node.property === \"string\" &&\n typeof node.nullish === \"boolean\"\n );\n case \"array-access\":\n return (\n isExpressionNode(node.base) &&\n \"index\" in node &&\n typeof node.nullish === \"boolean\" &&\n typeof node.fromEnd === \"boolean\"\n );\n case \"binary\":\n return typeof node.operator === \"string\" && \"left\" in node && \"right\" in node;\n case \"unary\":\n return typeof node.operator === \"string\" && \"argument\" in node;\n case \"ternary\":\n return \"condition\" in node && \"trueValue\" in node && \"falseValue\" in node;\n case \"instance-function-call\":\n return (\n isExpressionNode(node.base) && typeof node.name === \"string\" && Array.isArray(node.args)\n );\n case \"interpolated-string\":\n return Array.isArray(node.segments);\n default:\n return false;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Factory functions\n// ---------------------------------------------------------------------------\n\nexport function functionCallExpressionNode<TValue = unknown, TOperator extends string = string>(\n operator: TOperator,\n args: readonly unknown[],\n): FunctionCallExpressionNode<TValue, TOperator> {\n return { kind: \"fn-call\", operator, args };\n}\n\nexport function symbolicValueExpressionNode<TValue = unknown, TPath extends string = string>(\n path: TPath,\n): SymbolicValueExpressionNode<TValue, TPath> {\n return { kind: \"symbolic-value\", path };\n}\n\nexport function identifierExpressionNode<TValue = unknown>(\n identifier: string | Resource,\n): IdentifierExpressionNode<TValue> {\n return { kind: \"identifier\", id: identifier };\n}\n\nexport function propertyAccessExpressionNode<TValue = unknown>(\n base: ExpressionNode,\n property: string,\n options: Partial<Pick<PropertyAccessExpressionNode, \"armPath\" | \"nullish\">> = {},\n): PropertyAccessExpressionNode<TValue> {\n return {\n kind: \"property-access\",\n base,\n property,\n nullish: options.nullish ?? false,\n ...(options.armPath === undefined ? {} : { armPath: options.armPath }),\n };\n}\n\nexport function arrayAccessExpressionNode<TValue = unknown>(\n base: ExpressionNode,\n index: ArrayAccessIndex,\n options: Partial<Pick<ArrayAccessExpressionNode, \"nullish\" | \"fromEnd\">> = {},\n): ArrayAccessExpressionNode<TValue> {\n return {\n kind: \"array-access\",\n base,\n index,\n nullish: options.nullish ?? false,\n fromEnd: options.fromEnd ?? false,\n };\n}\n\nexport function binaryExpressionNode<TValue = unknown>(\n operator: BinaryOperator,\n left: unknown,\n right: unknown,\n): BinaryExpressionNode<TValue> {\n return { kind: \"binary\", operator, left, right };\n}\n\nexport function unaryExpressionNode<TValue = unknown>(\n operator: UnaryOperator,\n argument: unknown,\n): UnaryExpressionNode<TValue> {\n return { kind: \"unary\", operator, argument };\n}\n\nexport function ternaryExpressionNode<TValue = unknown>(\n condition: unknown,\n trueValue: unknown,\n falseValue: unknown,\n): TernaryExpressionNode<TValue> {\n return {\n kind: \"ternary\",\n condition,\n trueValue,\n falseValue,\n };\n}\n\nexport function instanceFunctionCallExpressionNode<TValue = unknown>(\n base: ExpressionNode,\n name: string,\n args: readonly unknown[],\n): InstanceFunctionCallExpressionNode<TValue> {\n return {\n kind: \"instance-function-call\",\n base,\n name,\n args,\n };\n}\n\nexport function interpolatedStringExpressionNode<TValue = unknown>(\n segments: readonly unknown[],\n): InterpolatedStringExpressionNode<TValue> {\n return { kind: \"interpolated-string\", segments };\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction isIdentifierSegment(segment: string): boolean {\n return /^[A-Za-z_][A-Za-z0-9_]*$/u.test(segment);\n}\n\nexport function accessExpressionNode(\n base: ExpressionNode,\n member: PropertySegment,\n options: Partial<Pick<PropertyAccessExpressionNode, \"armPath\" | \"nullish\">> = {},\n): PropertyAccessExpressionNode | ArrayAccessExpressionNode {\n return typeof member === \"number\" || !isIdentifierSegment(member)\n ? arrayAccessExpressionNode(base, member, options)\n : propertyAccessExpressionNode(base, member, options);\n}\n"]}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { type NavShape } from "../shape/shape.js";
|
|
2
|
+
import { type BinaryOperator, type ExpressionNode, type UnaryOperator } from "./ast-nodes.js";
|
|
3
|
+
/**
|
|
4
|
+
* Runtime symbol key storing the underlying `ExpressionNode` on proxies.
|
|
5
|
+
* Internal to the package — consumers should use `isExpression()` and
|
|
6
|
+
* `unwrapExpression()` instead of accessing this directly.
|
|
7
|
+
*/
|
|
8
|
+
export declare const EXPRESSION_BRAND: unique symbol;
|
|
9
|
+
/** Declared symbol type used in the `Expression<T>` interface for branding. */
|
|
10
|
+
declare const __expressionBrand: unique symbol;
|
|
11
|
+
export interface ExpressionBrand<out T> {
|
|
12
|
+
readonly [__expressionBrand]: ExpressionNode<T>;
|
|
13
|
+
}
|
|
14
|
+
declare const __expressionTag: unique symbol;
|
|
15
|
+
export interface ExpressionTag {
|
|
16
|
+
readonly [__expressionTag]?: never;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* An opaque deploy-time expression wrapping type `T`.
|
|
20
|
+
*
|
|
21
|
+
* For object types, properties of `T` are accessible as
|
|
22
|
+
* `Expression<Exclude<T[K], undefined>>`. Expression proxies always expose a
|
|
23
|
+
* symbolic property path, so TypeScript's `undefined` omission marker does not
|
|
24
|
+
* belong in the projected value type. Explicit `null` remains intact.
|
|
25
|
+
* For array types, numeric indices return `Expression<element>` and
|
|
26
|
+
* `.length` is an `Expression<number>`.
|
|
27
|
+
*
|
|
28
|
+
* Function-typed keys on `T` are intentionally NOT surfaced — an
|
|
29
|
+
* `Expression<(...)=>R>` isn't callable at the type level or meaningful
|
|
30
|
+
* at emit time. When bicep-level array/object methods are needed
|
|
31
|
+
* (concat, union, etc.), they are added explicitly via dedicated helper
|
|
32
|
+
* types (e.g. a future `ArrayExpression<T>`), not reflectively derived.
|
|
33
|
+
*
|
|
34
|
+
* `NonNullable<T>` is applied at the input boundary, so
|
|
35
|
+
* `Expression<R | undefined>` yields the same structural surface as
|
|
36
|
+
* `Expression<R>` — otherwise the `| undefined` union would distribute
|
|
37
|
+
* and collapse the object branch into `mapped | {}`, erasing the
|
|
38
|
+
* index signature / member projection.
|
|
39
|
+
*/
|
|
40
|
+
export type Expression<T = unknown> = ExpressionBrand<T> & ExpressionTag & ExpressionShape<NonNullable<T>>;
|
|
41
|
+
export type ExpressionShape<T> = T extends readonly unknown[] ? number extends T["length"] ? {
|
|
42
|
+
readonly length: Expression<number>;
|
|
43
|
+
readonly [index: number]: Expression<T[number]>;
|
|
44
|
+
} : {
|
|
45
|
+
readonly [K in Exclude<keyof T, keyof any[]>]: Expression<T[K]>;
|
|
46
|
+
} & {
|
|
47
|
+
readonly length: Expression<number>;
|
|
48
|
+
readonly [index: number]: Expression<T[number]>;
|
|
49
|
+
} : T extends object ? {
|
|
50
|
+
readonly [K in keyof T as T[K] extends (...a: any[]) => any ? never : K]-?: Expression<Exclude<T[K], undefined>>;
|
|
51
|
+
} : {};
|
|
52
|
+
/**
|
|
53
|
+
* Carries an *optional* Expression brand on an Input-shaped interface.
|
|
54
|
+
*
|
|
55
|
+
* This is the asymmetric-brand trick that makes the Input type system
|
|
56
|
+
* work without discriminated unions:
|
|
57
|
+
*
|
|
58
|
+
* - Every generated `*Input` interface extends `InputOf<Raw>` and therefore
|
|
59
|
+
* inherits the optional brand. Plain literal values (e.g. `{ foo: 1 }`)
|
|
60
|
+
* trivially satisfy it because the brand property is absent, which is
|
|
61
|
+
* permitted by an optional field.
|
|
62
|
+
* - `Expression<Raw>` carries a *required* brand of the same shape.
|
|
63
|
+
* Required-fields-satisfy-optional is part of TS structural assignability,
|
|
64
|
+
* so any `Expression<Raw>` is assignable where an `InputOf<Raw>`
|
|
65
|
+
* (and thus any `*Input` that extends it) is expected.
|
|
66
|
+
*
|
|
67
|
+
* Net effect: a single `MInput` parameter accepts both literals and
|
|
68
|
+
* whole-subtree `Expression<M>` replacements — no `MInput | Expression<M>`
|
|
69
|
+
* union is needed in the generated signatures. Callers that want to
|
|
70
|
+
* inspect whether a value is a literal or expression use `isExpression()`.
|
|
71
|
+
*/
|
|
72
|
+
export interface InputOf<out Raw> {
|
|
73
|
+
readonly [__expressionBrand]?: ExpressionNode<Raw>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Writable input form for an array container.
|
|
77
|
+
*
|
|
78
|
+
* Accepts literal `T[]`, another `InputArray<T>`, or `Expression<Raw>`.
|
|
79
|
+
* Deliberately NOT a subtype of `T[]` — passing a CDK-backed array to
|
|
80
|
+
* an API that expects a plain `Array<T>` fails at compile time, which
|
|
81
|
+
* is the correct signal (the value may actually be a Proxy wrapping an
|
|
82
|
+
* `ExpressionNode`, not a real JS array).
|
|
83
|
+
*/
|
|
84
|
+
export interface InputArray<T, Raw = readonly T[]> extends InputOf<Raw> {
|
|
85
|
+
length: number | Expression<number>;
|
|
86
|
+
[index: number]: T;
|
|
87
|
+
}
|
|
88
|
+
/** Writable input form for a `Record<string, V>` container. */
|
|
89
|
+
export interface InputRecord<V, Raw = Record<string, V>> extends InputOf<Raw> {
|
|
90
|
+
[key: string]: V;
|
|
91
|
+
}
|
|
92
|
+
/** Writable input form for a fixed-length heterogeneous tuple. */
|
|
93
|
+
export type InputTuple<T extends readonly unknown[], Raw extends readonly unknown[] = T> = InputOf<Raw> & {
|
|
94
|
+
length: T["length"] | Expression<number>;
|
|
95
|
+
[index: number]: T[number] | Expression<Raw[number]>;
|
|
96
|
+
} & {
|
|
97
|
+
[K in Exclude<keyof T, keyof any[]>]: T[K];
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Accepts either a plain value `T` or an `Expression<T>` substitution.
|
|
101
|
+
*
|
|
102
|
+
* Use this on scalar/leaf Input sites (primitives, enums, literal-only
|
|
103
|
+
* unions) where a full `InputOf<...>` structural extension doesn't apply.
|
|
104
|
+
* The result is a simple discriminated union; call `isExpression()` to
|
|
105
|
+
* branch on the runtime shape.
|
|
106
|
+
*/
|
|
107
|
+
export type ExpressionOrValue<T> = T | Expression<T>;
|
|
108
|
+
/**
|
|
109
|
+
* Asserts that a deploy-time expression resolves to a specific literal,
|
|
110
|
+
* so it can be used where a discriminator is expected.
|
|
111
|
+
*
|
|
112
|
+
* Discriminator properties on a `@discriminator` model are typed as bare
|
|
113
|
+
* literals (`kind: "cache"`) rather than `ExpressionOrValue<"cache">`.
|
|
114
|
+
* That is deliberate: TypeScript only treats a property as a discriminant
|
|
115
|
+
* when its type is a *unit* type in every constituent of the union, and a
|
|
116
|
+
* single widened arm disables narrowing for the whole union — completions
|
|
117
|
+
* then offer every variant's properties and excess-property checking
|
|
118
|
+
* degrades to "allowed if the property exists in any variant".
|
|
119
|
+
*
|
|
120
|
+
* When the discriminator genuinely isn't known until deployment, wrap the
|
|
121
|
+
* expression with this to state which variant you mean:
|
|
122
|
+
*
|
|
123
|
+
* ```ts snippet:ignore
|
|
124
|
+
* widget.properties.primaryRule = {
|
|
125
|
+
* kind: asDiscriminator(kindParam),
|
|
126
|
+
* cacheKind: "long",
|
|
127
|
+
* days: 7,
|
|
128
|
+
* };
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* Every other property is still fully checked — only the discriminator's
|
|
132
|
+
* type safety is waived. Note that the runtime cannot dispatch on a
|
|
133
|
+
* non-literal discriminator, so serialization falls back to structural
|
|
134
|
+
* variant inference; prefer a literal wherever possible.
|
|
135
|
+
*
|
|
136
|
+
* The literal is inferred from the expression's own type argument. If the
|
|
137
|
+
* expression is loosely typed (`Expression<string>`), name the variant
|
|
138
|
+
* explicitly: `asDiscriminator<"cache">(param)`.
|
|
139
|
+
*/
|
|
140
|
+
export declare function asDiscriminator<L extends string>(value: ExpressionOrValue<L>): L;
|
|
141
|
+
/**
|
|
142
|
+
* Extracts the underlying `ExpressionNode` from an `Expression<T>` value.
|
|
143
|
+
*
|
|
144
|
+
* `Expression<T>` is the public, typed handle for a deploy-time expression
|
|
145
|
+
* (backed by a Proxy at runtime); `ExpressionNode` is the raw AST node that
|
|
146
|
+
* the proxy wraps. Use this to walk / inspect / serialize the underlying
|
|
147
|
+
* tree without reaching for the brand symbol directly.
|
|
148
|
+
*/
|
|
149
|
+
export declare function unwrapExpression<T>(expr: Expression<T>): ExpressionNode<T>;
|
|
150
|
+
/**
|
|
151
|
+
* Tests whether a value is an `Expression<T>` — the typed, branded handle
|
|
152
|
+
* for a deploy-time expression (proxy-backed). Returns false for raw
|
|
153
|
+
* `ExpressionNode` data; use {@link isExpressionNode} from `./ast-nodes.js`
|
|
154
|
+
* for that.
|
|
155
|
+
*/
|
|
156
|
+
export declare function isExpression(value: unknown): value is Expression<unknown>;
|
|
157
|
+
export declare function wrapExpression<T = unknown>(expression: ExpressionNode, nav?: NavShape): Expression<T>;
|
|
158
|
+
export declare function wrapExpressionOver<TObject extends object, TValue = unknown>(target: TObject, expression: ExpressionNode): TObject & Expression<TValue>;
|
|
159
|
+
export declare function createBinaryExpression<T>(op: BinaryOperator, left: unknown, right: unknown): Expression<T>;
|
|
160
|
+
export declare function createUnaryExpression<T>(op: UnaryOperator, argument: unknown): Expression<T>;
|
|
161
|
+
export declare function createTernaryExpression<T>(condition: unknown, trueValue: unknown, falseValue: unknown): Expression<T>;
|
|
162
|
+
export declare function createFunctionCallExpression<T>(name: string, args: unknown[]): Expression<T>;
|
|
163
|
+
export {};
|
|
164
|
+
//# sourceMappingURL=expressions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../../../src/expression/expressions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAML,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,EAEnB,MAAM,gBAAgB,CAAC;AAMxB;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,OAAO,MAAmC,CAAC;AAE1E,+EAA+E;AAC/E,OAAO,CAAC,MAAM,iBAAiB,EAAE,OAAO,MAAM,CAAC;AAM/C,MAAM,WAAW,eAAe,CAAC,GAAG,CAAC,CAAC;IACpC,QAAQ,CAAC,CAAC,iBAAiB,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;CACjD;AAKD,OAAO,CAAC,MAAM,eAAe,EAAE,OAAO,MAAM,CAAC;AAC7C,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,CAAC,eAAe,CAAC,CAAC,EAAE,KAAK,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,OAAO,IAAI,eAAe,CAAC,CAAC,CAAC,GACtD,aAAa,GACb,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AAElC,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,OAAO,EAAE,GACzD,MAAM,SAAS,CAAC,CAAC,QAAQ,CAAC,GACxB;IACE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACpC,Q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AAE,MAAM,GAAG,OAAO,EACzE,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,cAAc,GACzB,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CA2D9B;AAMD,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,EAAE,EAAE,cAAc,EAClB,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,OAAO,GACb,UAAU,CAAC,CAAC,CAAC,CAEf;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,EAAE,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,GAAG,UAAU,CAAC,CAAC,CAAC,CAE5F;AAED,wBAAgB,uBAAuB,CAAC,CAAC,EACvC,SAAS,EAAE,OAAO,EAClB,SAAS,EAAE,OAAO,EAClB,UAAU,EAAE,OAAO,GAClB,UAAU,CAAC,CAAC,CAAC,CAEf;AAED,wBAAgB,4BAA4B,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,CAE5F"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { navigateShape } from "../shape/shape.js";
|
|
4
|
+
import { arrayAccessExpressionNode, binaryExpressionNode, functionCallExpressionNode, propertyAccessExpressionNode, ternaryExpressionNode, unaryExpressionNode, } from "./ast-nodes.js";
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// Brand symbol (runtime + type-only)
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
/**
|
|
9
|
+
* Runtime symbol key storing the underlying `ExpressionNode` on proxies.
|
|
10
|
+
* Internal to the package — consumers should use `isExpression()` and
|
|
11
|
+
* `unwrapExpression()` instead of accessing this directly.
|
|
12
|
+
*/
|
|
13
|
+
export const EXPRESSION_BRAND = Symbol("expression-brand");
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Discriminator escape hatch
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
/**
|
|
18
|
+
* Asserts that a deploy-time expression resolves to a specific literal,
|
|
19
|
+
* so it can be used where a discriminator is expected.
|
|
20
|
+
*
|
|
21
|
+
* Discriminator properties on a `@discriminator` model are typed as bare
|
|
22
|
+
* literals (`kind: "cache"`) rather than `ExpressionOrValue<"cache">`.
|
|
23
|
+
* That is deliberate: TypeScript only treats a property as a discriminant
|
|
24
|
+
* when its type is a *unit* type in every constituent of the union, and a
|
|
25
|
+
* single widened arm disables narrowing for the whole union — completions
|
|
26
|
+
* then offer every variant's properties and excess-property checking
|
|
27
|
+
* degrades to "allowed if the property exists in any variant".
|
|
28
|
+
*
|
|
29
|
+
* When the discriminator genuinely isn't known until deployment, wrap the
|
|
30
|
+
* expression with this to state which variant you mean:
|
|
31
|
+
*
|
|
32
|
+
* ```ts snippet:ignore
|
|
33
|
+
* widget.properties.primaryRule = {
|
|
34
|
+
* kind: asDiscriminator(kindParam),
|
|
35
|
+
* cacheKind: "long",
|
|
36
|
+
* days: 7,
|
|
37
|
+
* };
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* Every other property is still fully checked — only the discriminator's
|
|
41
|
+
* type safety is waived. Note that the runtime cannot dispatch on a
|
|
42
|
+
* non-literal discriminator, so serialization falls back to structural
|
|
43
|
+
* variant inference; prefer a literal wherever possible.
|
|
44
|
+
*
|
|
45
|
+
* The literal is inferred from the expression's own type argument. If the
|
|
46
|
+
* expression is loosely typed (`Expression<string>`), name the variant
|
|
47
|
+
* explicitly: `asDiscriminator<"cache">(param)`.
|
|
48
|
+
*/
|
|
49
|
+
export function asDiscriminator(value) {
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
// Unwrap + type guards
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
// Two distinct concepts, two distinct guards:
|
|
56
|
+
//
|
|
57
|
+
// - `isExpression(x)` — "is `x` a typed `Expression<T>` handle
|
|
58
|
+
// (the value-level, proxy-backed form)?"
|
|
59
|
+
// - `isExpressionNode(x)` — "is `x` a raw `ExpressionNode` data object
|
|
60
|
+
// (one of the AST kinds)?"
|
|
61
|
+
//
|
|
62
|
+
// These are *disjoint* — a value is either a wrapped Expression handle or a
|
|
63
|
+
// raw AST node, never both. To check the AST kind of either form, narrow
|
|
64
|
+
// via the discriminated `kind` field:
|
|
65
|
+
//
|
|
66
|
+
// if (isExpression(value)) {
|
|
67
|
+
// const node = unwrapExpression(value);
|
|
68
|
+
// if (node.kind === "fn-call") { /* node: FunctionCallExpressionNode */ }
|
|
69
|
+
// }
|
|
70
|
+
// if (isExpressionNode(value)) {
|
|
71
|
+
// if (value.kind === "binary") { /* value: BinaryExpressionNode */ }
|
|
72
|
+
// }
|
|
73
|
+
/**
|
|
74
|
+
* Extracts the underlying `ExpressionNode` from an `Expression<T>` value.
|
|
75
|
+
*
|
|
76
|
+
* `Expression<T>` is the public, typed handle for a deploy-time expression
|
|
77
|
+
* (backed by a Proxy at runtime); `ExpressionNode` is the raw AST node that
|
|
78
|
+
* the proxy wraps. Use this to walk / inspect / serialize the underlying
|
|
79
|
+
* tree without reaching for the brand symbol directly.
|
|
80
|
+
*/
|
|
81
|
+
export function unwrapExpression(expr) {
|
|
82
|
+
return expr[EXPRESSION_BRAND];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Tests whether a value is an `Expression<T>` — the typed, branded handle
|
|
86
|
+
* for a deploy-time expression (proxy-backed). Returns false for raw
|
|
87
|
+
* `ExpressionNode` data; use {@link isExpressionNode} from `./ast-nodes.js`
|
|
88
|
+
* for that.
|
|
89
|
+
*/
|
|
90
|
+
export function isExpression(value) {
|
|
91
|
+
return typeof value === "object" && value !== null && EXPRESSION_BRAND in value;
|
|
92
|
+
}
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
// Expression proxy factory
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
export function wrapExpression(expression, nav) {
|
|
97
|
+
return new Proxy(Object.create(null), {
|
|
98
|
+
get(_target, prop, _receiver) {
|
|
99
|
+
if (prop === EXPRESSION_BRAND) {
|
|
100
|
+
return expression;
|
|
101
|
+
}
|
|
102
|
+
if (prop === Symbol.toPrimitive || prop === "toString") {
|
|
103
|
+
return () => "[Expression]";
|
|
104
|
+
}
|
|
105
|
+
if (prop === "valueOf") {
|
|
106
|
+
return () => expression;
|
|
107
|
+
}
|
|
108
|
+
// Avoid being treated as a thenable / Promise
|
|
109
|
+
if (prop === "then") {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
if (typeof prop === "symbol") {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
// Numeric string → array access.
|
|
116
|
+
if (/^\d+$/u.test(prop)) {
|
|
117
|
+
const index = Number(prop);
|
|
118
|
+
const step = navigateShape(nav, index);
|
|
119
|
+
return wrapExpression(arrayAccessExpressionNode(expression, index), step.next);
|
|
120
|
+
}
|
|
121
|
+
// String property → property access. Consult the current nav
|
|
122
|
+
// shape; stamp the access with the wire armPath if an entry
|
|
123
|
+
// exists, otherwise pass through unchanged. Container navs
|
|
124
|
+
// (record/array) yield no stamp but still peel a layer.
|
|
125
|
+
const step = navigateShape(nav, prop);
|
|
126
|
+
return wrapExpression(propertyAccessExpressionNode(expression, prop, {
|
|
127
|
+
armPath: step.stamp?.armPath,
|
|
128
|
+
}), step.next);
|
|
129
|
+
},
|
|
130
|
+
has(_target, prop) {
|
|
131
|
+
return prop === EXPRESSION_BRAND;
|
|
132
|
+
},
|
|
133
|
+
ownKeys() {
|
|
134
|
+
return [];
|
|
135
|
+
},
|
|
136
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
137
|
+
if (prop === EXPRESSION_BRAND) {
|
|
138
|
+
return {
|
|
139
|
+
configurable: true,
|
|
140
|
+
enumerable: false,
|
|
141
|
+
value: expression,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
return undefined;
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
export function wrapExpressionOver(target, expression) {
|
|
149
|
+
return new Proxy(target, {
|
|
150
|
+
get(backing, prop, receiver) {
|
|
151
|
+
if (prop === EXPRESSION_BRAND) {
|
|
152
|
+
return expression;
|
|
153
|
+
}
|
|
154
|
+
if (prop === Symbol.toPrimitive || prop === "toString") {
|
|
155
|
+
return () => "[Expression]";
|
|
156
|
+
}
|
|
157
|
+
if (prop === "valueOf") {
|
|
158
|
+
return () => expression;
|
|
159
|
+
}
|
|
160
|
+
if (prop === "then") {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
if (Reflect.has(backing, prop)) {
|
|
164
|
+
return Reflect.get(backing, prop, receiver);
|
|
165
|
+
}
|
|
166
|
+
if (typeof prop === "symbol") {
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
if (/^\d+$/u.test(prop)) {
|
|
170
|
+
return wrapExpression(arrayAccessExpressionNode(expression, Number(prop)));
|
|
171
|
+
}
|
|
172
|
+
return wrapExpression(propertyAccessExpressionNode(expression, prop));
|
|
173
|
+
},
|
|
174
|
+
has(backing, prop) {
|
|
175
|
+
return prop === EXPRESSION_BRAND || Reflect.has(backing, prop);
|
|
176
|
+
},
|
|
177
|
+
ownKeys(backing) {
|
|
178
|
+
const keys = Reflect.ownKeys(backing);
|
|
179
|
+
if (!keys.includes(EXPRESSION_BRAND)) {
|
|
180
|
+
keys.push(EXPRESSION_BRAND);
|
|
181
|
+
}
|
|
182
|
+
return keys;
|
|
183
|
+
},
|
|
184
|
+
getOwnPropertyDescriptor(backing, prop) {
|
|
185
|
+
if (prop === EXPRESSION_BRAND) {
|
|
186
|
+
return {
|
|
187
|
+
configurable: true,
|
|
188
|
+
enumerable: false,
|
|
189
|
+
value: expression,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
return Reflect.getOwnPropertyDescriptor(backing, prop);
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
// ---------------------------------------------------------------------------
|
|
197
|
+
// Proxied-expression factories (return Expression<T>)
|
|
198
|
+
// ---------------------------------------------------------------------------
|
|
199
|
+
export function createBinaryExpression(op, left, right) {
|
|
200
|
+
return wrapExpression(binaryExpressionNode(op, left, right));
|
|
201
|
+
}
|
|
202
|
+
export function createUnaryExpression(op, argument) {
|
|
203
|
+
return wrapExpression(unaryExpressionNode(op, argument));
|
|
204
|
+
}
|
|
205
|
+
export function createTernaryExpression(condition, trueValue, falseValue) {
|
|
206
|
+
return wrapExpression(ternaryExpressionNode(condition, trueValue, falseValue));
|
|
207
|
+
}
|
|
208
|
+
export function createFunctionCallExpression(name, args) {
|
|
209
|
+
return wrapExpression(functionCallExpressionNode(name, args));
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=expressions.js.map
|