openapi-typesafe 1.0.0-rc.4 → 1.0.0-rc.6
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 +214 -0
- package/dist/adapters/node-file-system/node-file-system.cjs +7 -0
- package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
- package/dist/adapters/node-file-system/node-file-system.mjs +7 -0
- package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs +19 -0
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs.map +1 -0
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs +17 -0
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +5 -32
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +6 -33
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -1
- package/dist/adapters/redocly-loader/component-schemas.cjs +17 -0
- package/dist/adapters/redocly-loader/component-schemas.cjs.map +1 -0
- package/dist/adapters/redocly-loader/component-schemas.mjs +14 -0
- package/dist/adapters/redocly-loader/component-schemas.mjs.map +1 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.cjs +22 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.cjs.map +1 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.mjs +20 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.mjs.map +1 -0
- package/dist/adapters/redocly-loader/query-document-names.cjs +50 -0
- package/dist/adapters/redocly-loader/query-document-names.cjs.map +1 -0
- package/dist/adapters/redocly-loader/query-document-names.mjs +48 -0
- package/dist/adapters/redocly-loader/query-document-names.mjs.map +1 -0
- package/dist/adapters/redocly-loader/query-named-components.cjs +129 -0
- package/dist/adapters/redocly-loader/query-named-components.cjs.map +1 -0
- package/dist/adapters/redocly-loader/query-named-components.mjs +126 -0
- package/dist/adapters/redocly-loader/query-named-components.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-config-source.cjs +3 -0
- package/dist/adapters/redocly-loader/redocly-config-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-config-source.mjs +4 -1
- package/dist/adapters/redocly-loader/redocly-config-source.mjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +39 -18
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +40 -19
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +25 -4
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +26 -5
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.cjs +52 -10
- package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.mjs +52 -11
- package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.cjs +20 -3
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +20 -4
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.cjs +17 -3
- package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.mjs +17 -3
- package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.cjs +7 -2
- package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.mjs +8 -3
- package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.cjs +7 -3
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.mjs +7 -3
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
- package/dist/api/cwd-option.cjs +58 -0
- package/dist/api/cwd-option.cjs.map +1 -0
- package/dist/api/cwd-option.mjs +52 -0
- package/dist/api/cwd-option.mjs.map +1 -0
- package/dist/api/default-ports.cjs +15 -7
- package/dist/api/default-ports.cjs.map +1 -1
- package/dist/api/default-ports.mjs +14 -8
- package/dist/api/default-ports.mjs.map +1 -1
- package/dist/api/document-refs.cjs +16 -1
- package/dist/api/document-refs.cjs.map +1 -1
- package/dist/api/document-refs.mjs +16 -1
- package/dist/api/document-refs.mjs.map +1 -1
- package/dist/api/document-run.cjs +6 -26
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +5 -21
- package/dist/api/document-run.mjs.map +1 -1
- package/dist/api/legacy-utils.cjs +1 -1
- package/dist/api/legacy-utils.cjs.map +1 -1
- package/dist/api/legacy-utils.mjs +1 -1
- package/dist/api/legacy-utils.mjs.map +1 -1
- package/dist/api/openapi-ts.cjs +1 -2
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +2 -3
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/option-errors.cjs +24 -0
- package/dist/api/option-errors.cjs.map +1 -0
- package/dist/api/option-errors.mjs +21 -0
- package/dist/api/option-errors.mjs.map +1 -0
- package/dist/api/ref-limit-options.cjs +58 -0
- package/dist/api/ref-limit-options.cjs.map +1 -0
- package/dist/api/ref-limit-options.mjs +52 -0
- package/dist/api/ref-limit-options.mjs.map +1 -0
- package/dist/api/transform-schema.cjs +12 -5
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +12 -5
- package/dist/api/transform-schema.mjs.map +1 -1
- package/dist/application/transform/declared-value-types.cjs +36 -0
- package/dist/application/transform/declared-value-types.cjs.map +1 -0
- package/dist/application/transform/declared-value-types.mjs +34 -0
- package/dist/application/transform/declared-value-types.mjs.map +1 -0
- package/dist/application/transform/document/document.cjs +3 -1
- package/dist/application/transform/document/document.cjs.map +1 -1
- package/dist/application/transform/document/document.mjs +3 -1
- package/dist/application/transform/document/document.mjs.map +1 -1
- package/dist/application/transform/document/exploded-query-values.cjs +63 -0
- package/dist/application/transform/document/exploded-query-values.cjs.map +1 -0
- package/dist/application/transform/document/exploded-query-values.mjs +59 -0
- package/dist/application/transform/document/exploded-query-values.mjs.map +1 -0
- package/dist/application/transform/document/header.cjs +11 -3
- package/dist/application/transform/document/header.cjs.map +1 -1
- package/dist/application/transform/document/header.mjs +10 -2
- package/dist/application/transform/document/header.mjs.map +1 -1
- package/dist/application/transform/document/parameter.cjs +1 -1
- package/dist/application/transform/document/parameter.cjs.map +1 -1
- package/dist/application/transform/document/parameter.mjs +1 -1
- package/dist/application/transform/document/parameter.mjs.map +1 -1
- package/dist/application/transform/document/parameters.cjs +23 -5
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +23 -5
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/path-item.cjs +4 -3
- package/dist/application/transform/document/path-item.cjs.map +1 -1
- package/dist/application/transform/document/path-item.mjs +4 -4
- package/dist/application/transform/document/path-item.mjs.map +1 -1
- package/dist/application/transform/document/path-template-key.cjs +84 -0
- package/dist/application/transform/document/path-template-key.cjs.map +1 -0
- package/dist/application/transform/document/path-template-key.mjs +79 -0
- package/dist/application/transform/document/path-template-key.mjs.map +1 -0
- package/dist/application/transform/document/path-template-refs.cjs +80 -0
- package/dist/application/transform/document/path-template-refs.cjs.map +1 -0
- package/dist/application/transform/document/path-template-refs.mjs +77 -0
- package/dist/application/transform/document/path-template-refs.mjs.map +1 -0
- package/dist/application/transform/document/paths-enum.cjs +7 -6
- package/dist/application/transform/document/paths-enum.cjs.map +1 -1
- package/dist/application/transform/document/paths-enum.mjs +7 -6
- package/dist/application/transform/document/paths-enum.mjs.map +1 -1
- package/dist/application/transform/document/paths.cjs +38 -66
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +36 -66
- package/dist/application/transform/document/paths.mjs.map +1 -1
- package/dist/application/transform/document/webhooks.cjs +10 -3
- package/dist/application/transform/document/webhooks.cjs.map +1 -1
- package/dist/application/transform/document/webhooks.mjs +9 -2
- package/dist/application/transform/document/webhooks.mjs.map +1 -1
- package/dist/application/transform/footer/document-footer.cjs +6 -3
- package/dist/application/transform/footer/document-footer.cjs.map +1 -1
- package/dist/application/transform/footer/document-footer.mjs +6 -3
- package/dist/application/transform/footer/document-footer.mjs.map +1 -1
- package/dist/application/transform/helper-types.cjs +3 -3
- package/dist/application/transform/helper-types.cjs.map +1 -1
- package/dist/application/transform/helper-types.mjs +3 -3
- package/dist/application/transform/helper-types.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs +4 -4
- package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.cjs +63 -64
- package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.mjs +57 -53
- package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/inline-cycles.cjs +2 -2
- package/dist/application/transform/ref-pointer/inline-cycles.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/inline-cycles.mjs +1 -1
- package/dist/application/transform/ref-pointer/inline-cycles.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/located-node.cjs +23 -0
- package/dist/application/transform/ref-pointer/located-node.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/located-node.mjs +18 -0
- package/dist/application/transform/ref-pointer/located-node.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/original-index.cjs +69 -14
- package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/original-index.mjs +71 -16
- package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs +2 -2
- package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-walk.cjs +54 -13
- package/dist/application/transform/ref-pointer/pointer-walk.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-walk.mjs +46 -7
- package/dist/application/transform/ref-pointer/pointer-walk.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/property-shape.cjs +57 -0
- package/dist/application/transform/ref-pointer/property-shape.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/property-shape.mjs +49 -0
- package/dist/application/transform/ref-pointer/property-shape.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/typed-walk.cjs +90 -22
- package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/typed-walk.mjs +87 -19
- package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -1
- package/dist/application/transform/schema/access-flags.cjs.map +1 -1
- package/dist/application/transform/schema/access-flags.mjs.map +1 -1
- package/dist/application/transform/schema/index-signature-type.cjs +21 -0
- package/dist/application/transform/schema/index-signature-type.cjs.map +1 -0
- package/dist/application/transform/schema/index-signature-type.mjs +19 -0
- package/dist/application/transform/schema/index-signature-type.mjs.map +1 -0
- package/dist/application/transform/schema/input-location.cjs +23 -0
- package/dist/application/transform/schema/input-location.cjs.map +1 -0
- package/dist/application/transform/schema/input-location.mjs +21 -0
- package/dist/application/transform/schema/input-location.mjs.map +1 -0
- package/dist/application/transform/schema/object-type.cjs +15 -5
- package/dist/application/transform/schema/object-type.cjs.map +1 -1
- package/dist/application/transform/schema/object-type.mjs +15 -5
- package/dist/application/transform/schema/object-type.mjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.cjs +2 -1
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.mjs +2 -1
- package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs +2 -30
- package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.mjs +3 -31
- package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
- package/dist/cli/api-logger.cjs +13 -0
- package/dist/cli/api-logger.cjs.map +1 -0
- package/dist/cli/api-logger.mjs +11 -0
- package/dist/cli/api-logger.mjs.map +1 -0
- package/dist/cli/api-settings.cjs +10 -17
- package/dist/cli/api-settings.cjs.map +1 -1
- package/dist/cli/api-settings.mjs +10 -17
- package/dist/cli/api-settings.mjs.map +1 -1
- package/dist/cli/api-writes.cjs +7 -1
- package/dist/cli/api-writes.cjs.map +1 -1
- package/dist/cli/api-writes.mjs +7 -1
- package/dist/cli/api-writes.mjs.map +1 -1
- package/dist/cli/cli-arguments.cjs +32 -74
- package/dist/cli/cli-arguments.cjs.map +1 -1
- package/dist/cli/cli-arguments.mjs +28 -70
- package/dist/cli/cli-arguments.mjs.map +1 -1
- package/dist/cli/cli-errors.cjs +18 -0
- package/dist/cli/cli-errors.cjs.map +1 -1
- package/dist/cli/cli-errors.mjs +18 -1
- package/dist/cli/cli-errors.mjs.map +1 -1
- package/dist/cli/cli-flag-names.cjs +77 -0
- package/dist/cli/cli-flag-names.cjs.map +1 -0
- package/dist/cli/cli-flag-names.mjs +64 -0
- package/dist/cli/cli-flag-names.mjs.map +1 -0
- package/dist/cli/cli-output.cjs +13 -6
- package/dist/cli/cli-output.cjs.map +1 -1
- package/dist/cli/cli-output.mjs +14 -7
- package/dist/cli/cli-output.mjs.map +1 -1
- package/dist/cli/main.cjs +11 -5
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.mjs +11 -5
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +33 -12
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +35 -14
- package/dist/cli/redocly-apis.mjs.map +1 -1
- package/dist/cli/ref-limits.cjs +15 -1
- package/dist/cli/ref-limits.cjs.map +1 -1
- package/dist/cli/ref-limits.mjs +15 -2
- package/dist/cli/ref-limits.mjs.map +1 -1
- package/dist/cli/run-cli.cjs +24 -7
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +25 -8
- package/dist/cli/run-cli.mjs.map +1 -1
- package/dist/cli/written-flags.cjs +83 -0
- package/dist/cli/written-flags.cjs.map +1 -0
- package/dist/cli/written-flags.mjs +77 -0
- package/dist/cli/written-flags.mjs.map +1 -0
- package/dist/domain/cause-secrets.cjs +31 -16
- package/dist/domain/cause-secrets.cjs.map +1 -1
- package/dist/domain/cause-secrets.mjs +31 -16
- package/dist/domain/cause-secrets.mjs.map +1 -1
- package/dist/domain/errors.cjs +3 -0
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +3 -0
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/location-text.cjs +15 -0
- package/dist/domain/location-text.cjs.map +1 -0
- package/dist/domain/location-text.mjs +13 -0
- package/dist/domain/location-text.mjs.map +1 -0
- package/dist/domain/openapi/document-places.cjs +55 -0
- package/dist/domain/openapi/document-places.cjs.map +1 -0
- package/dist/domain/openapi/document-places.mjs +53 -0
- package/dist/domain/openapi/document-places.mjs.map +1 -0
- package/dist/domain/output-fixes.cjs +8 -2
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +8 -2
- package/dist/domain/output-fixes.mjs.map +1 -1
- package/dist/domain/terminal-text.cjs +31 -0
- package/dist/domain/terminal-text.cjs.map +1 -0
- package/dist/domain/terminal-text.mjs +29 -0
- package/dist/domain/terminal-text.mjs.map +1 -0
- package/dist/domain/warnings.cjs +1 -0
- package/dist/domain/warnings.cjs.map +1 -1
- package/dist/domain/warnings.mjs +1 -0
- package/dist/domain/warnings.mjs.map +1 -1
- package/dist/index.d.cts +29 -18
- package/dist/index.d.mts +29 -18
- package/dist/index.d.ts +29 -18
- package/package.json +1 -1
- package/src/adapters/node-file-system/node-file-system.ts +14 -1
- package/src/adapters/pipe-safe-writer/pipe-safe-writer.ts +29 -0
- package/src/adapters/redocly-loader/bundled-mapping-copies.ts +7 -42
- package/src/adapters/redocly-loader/component-schemas.ts +19 -0
- package/src/adapters/redocly-loader/mapping-schema-names.ts +25 -0
- package/src/adapters/redocly-loader/query-document-names.ts +79 -0
- package/src/adapters/redocly-loader/query-named-components.ts +200 -0
- package/src/adapters/redocly-loader/redocly-config-source.ts +11 -1
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +63 -17
- package/src/adapters/redocly-loader/ref-access.ts +32 -5
- package/src/adapters/redocly-loader/ref-holders.ts +75 -14
- package/src/adapters/redocly-loader/remote-fetch.ts +37 -2
- package/src/adapters/redocly-loader/remote-node-limit.ts +44 -4
- package/src/adapters/redocly-loader/schema-source.ts +15 -3
- package/src/adapters/terminal-logger/terminal-logger.ts +10 -4
- package/src/api/cwd-option.ts +76 -0
- package/src/api/default-ports.ts +33 -10
- package/src/api/document-refs.ts +29 -1
- package/src/api/document-run.ts +7 -32
- package/src/api/legacy-utils.ts +1 -1
- package/src/api/openapi-ts.ts +20 -4
- package/src/api/option-errors.ts +22 -0
- package/src/api/ref-limit-options.ts +69 -0
- package/src/api/transform-schema.ts +20 -5
- package/src/application/ports/file-system.ts +8 -0
- package/src/application/ports/redocly-config-source.ts +5 -0
- package/src/application/transform/declared-value-types.ts +42 -0
- package/src/application/transform/document/document.ts +4 -2
- package/src/application/transform/document/exploded-query-values.ts +88 -0
- package/src/application/transform/document/header.ts +25 -5
- package/src/application/transform/document/parameter.ts +4 -4
- package/src/application/transform/document/parameters.ts +45 -10
- package/src/application/transform/document/path-item.ts +3 -3
- package/src/application/transform/document/path-template-key.ts +152 -0
- package/src/application/transform/document/path-template-refs.ts +127 -0
- package/src/application/transform/document/paths-enum.ts +23 -9
- package/src/application/transform/document/paths.ts +53 -123
- package/src/application/transform/document/webhooks.ts +18 -5
- package/src/application/transform/footer/document-footer.ts +18 -8
- package/src/application/transform/helper-types.ts +4 -4
- package/src/application/transform/ref-pointer/generated-location.ts +1 -1
- package/src/application/transform/ref-pointer/generated-shape.ts +115 -83
- package/src/application/transform/ref-pointer/inline-cycles.ts +1 -1
- package/src/application/transform/ref-pointer/located-node.ts +38 -0
- package/src/application/transform/ref-pointer/original-index.ts +106 -20
- package/src/application/transform/ref-pointer/pointer-type.ts +1 -1
- package/src/application/transform/ref-pointer/pointer-walk.ts +82 -8
- package/src/application/transform/ref-pointer/property-shape.ts +106 -0
- package/src/application/transform/ref-pointer/typed-walk.ts +143 -29
- package/src/application/transform/schema/access-flags.ts +5 -2
- package/src/application/transform/schema/index-signature-type.ts +31 -0
- package/src/application/transform/schema/input-location.ts +35 -0
- package/src/application/transform/schema/object-type.ts +18 -8
- package/src/application/transform/schema/schema-transform.ts +2 -1
- package/src/application/transform/schema/unevaluated-properties.ts +4 -44
- package/src/cli/api-logger.ts +17 -0
- package/src/cli/api-settings.ts +12 -20
- package/src/cli/api-writes.ts +11 -3
- package/src/cli/cli-arguments.ts +57 -92
- package/src/cli/cli-dependencies.ts +7 -2
- package/src/cli/cli-errors.ts +23 -0
- package/src/cli/cli-flag-names.ts +99 -0
- package/src/cli/cli-output.ts +31 -16
- package/src/cli/main.ts +12 -5
- package/src/cli/redocly-apis.ts +56 -20
- package/src/cli/ref-limits.ts +21 -2
- package/src/cli/run-cli.ts +39 -7
- package/src/cli/written-flags.ts +131 -0
- package/src/domain/cause-secrets.ts +59 -25
- package/src/domain/errors.ts +3 -0
- package/src/domain/location-text.ts +27 -0
- package/src/domain/openapi/document-places.ts +78 -0
- package/src/domain/output-fixes.ts +9 -2
- package/src/domain/terminal-text.ts +44 -0
- package/src/domain/warnings.ts +1 -0
|
@@ -1,71 +1,48 @@
|
|
|
1
1
|
import { irObject, irIntersection, irProperty, irRaw } from '../../../domain/ir/constructors.mjs';
|
|
2
2
|
import { toPropertyName } from '../../../domain/ir/property-name.mjs';
|
|
3
|
-
import { escapeTemplateText } from '../../../domain/ir/raw-text-escapes.mjs';
|
|
4
3
|
import { appendPointer, ROOT_POINTER } from '../../../domain/openapi/json-pointer.mjs';
|
|
5
|
-
import { pathItemOperations } from '../../../domain/openapi/path-item-object.mjs';
|
|
6
|
-
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
7
4
|
import { documentEntries } from '../document-entries.mjs';
|
|
8
5
|
import { refType } from '../ref-type.mjs';
|
|
9
6
|
import { NO_DECLARED_TYPES } from './declared-types.mjs';
|
|
10
7
|
import { documentMember } from './document-member.mjs';
|
|
11
8
|
import { pathItemType } from './path-item.mjs';
|
|
12
9
|
import { coveringTemplateKeys } from './path-key-overlaps.mjs';
|
|
13
|
-
import {
|
|
10
|
+
import { plainUrlOf, pathTemplateParts, booleanExpandedKeys, templateText } from './path-template-key.mjs';
|
|
14
11
|
import { assignabilityProof } from './type-assignability.mjs';
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
["integer", "number"],
|
|
20
|
-
["boolean", "boolean"]
|
|
21
|
-
]);
|
|
22
|
-
const STRING_PLACEHOLDER = "string";
|
|
23
|
-
function resolvedParameter(parameter, context) {
|
|
24
|
-
return "$ref" in parameter && parameter.$ref ? context.refs.resolve(parameter.$ref) : parameter;
|
|
13
|
+
function pathKeyOf(parts) {
|
|
14
|
+
const plainUrl = plainUrlOf(parts);
|
|
15
|
+
return plainUrl === null ? { kind: "template", parts } : literalKey(plainUrl);
|
|
25
16
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function pathParameters(pathItem, context) {
|
|
35
|
-
const byName = /* @__PURE__ */ new Map();
|
|
36
|
-
addPathParameters(pathItem.parameters ?? [], byName, context);
|
|
37
|
-
for (const { operation: entry } of pathItemOperations(pathItem)) {
|
|
38
|
-
const operation = entry.$ref ? context.refs.resolve(entry.$ref) : entry;
|
|
39
|
-
addPathParameters(operation?.parameters ?? [], byName, context);
|
|
17
|
+
function keyMember(url, parts, type, isReadonly) {
|
|
18
|
+
const key = pathKeyOf(parts);
|
|
19
|
+
if (key.kind === "literal") {
|
|
20
|
+
const member2 = irProperty(toPropertyName(key.url), type, { isReadonly });
|
|
21
|
+
return { url, member: member2, key, type };
|
|
40
22
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
23
|
+
const member = {
|
|
24
|
+
kind: "indexSignature",
|
|
25
|
+
parameterName: "path",
|
|
26
|
+
parameterType: irRaw(templateText(parts)),
|
|
27
|
+
type,
|
|
28
|
+
isReadonly,
|
|
29
|
+
comments: []
|
|
30
|
+
};
|
|
31
|
+
return { url, member, key, type };
|
|
49
32
|
}
|
|
50
|
-
function
|
|
51
|
-
const
|
|
52
|
-
if (!
|
|
53
|
-
return
|
|
33
|
+
function isUntakenKey(url, key, takenUrls) {
|
|
34
|
+
const isExpandedUrl = key.kind === "literal" && key.url !== url;
|
|
35
|
+
if (!isExpandedUrl) {
|
|
36
|
+
return true;
|
|
54
37
|
}
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return { match, type: PLACEHOLDERS.get(schema?.type) ?? STRING_PLACEHOLDER };
|
|
59
|
-
});
|
|
60
|
-
return context.options.fixes.has(FIX.PATH_PARAM_TYPE_NAMES) ? splitTemplateParts(url, matches) : replacedTemplateParts(url, matches);
|
|
38
|
+
const isTaken = takenUrls.has(key.url);
|
|
39
|
+
takenUrls.add(key.url);
|
|
40
|
+
return !isTaken;
|
|
61
41
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
(part) => part.kind === "text" ? escapeTemplateText(part.text) : placeholderText(part.type)
|
|
65
|
-
).join("");
|
|
66
|
-
return `\`${text}\``;
|
|
42
|
+
function withoutTakenUrls(url, members, takenUrls) {
|
|
43
|
+
return members.filter(({ key }) => isUntakenKey(url, key, takenUrls));
|
|
67
44
|
}
|
|
68
|
-
function
|
|
45
|
+
function pathItemMembers(url, pathItem, context) {
|
|
69
46
|
const isReadonly = context.options.immutable;
|
|
70
47
|
const type = pathItemType(
|
|
71
48
|
pathItem,
|
|
@@ -74,18 +51,10 @@ function pathItemMember(url, pathItem, context) {
|
|
|
74
51
|
);
|
|
75
52
|
const parts = context.options.pathParamsAsTypes && url.includes("{") ? pathTemplateParts(url, pathItem, context) : null;
|
|
76
53
|
if (parts === null) {
|
|
77
|
-
const
|
|
78
|
-
return { url, member
|
|
54
|
+
const member = irProperty(toPropertyName(url), type, { isReadonly });
|
|
55
|
+
return [{ url, member, key: literalKey(url), type }];
|
|
79
56
|
}
|
|
80
|
-
|
|
81
|
-
kind: "indexSignature",
|
|
82
|
-
parameterName: "path",
|
|
83
|
-
parameterType: irRaw(templateText(parts)),
|
|
84
|
-
type,
|
|
85
|
-
isReadonly,
|
|
86
|
-
comments: []
|
|
87
|
-
};
|
|
88
|
-
return { url, member, key: { kind: "template", parts }, type };
|
|
57
|
+
return booleanExpandedKeys(parts).map((key) => keyMember(url, key, type, isReadonly));
|
|
89
58
|
}
|
|
90
59
|
function literalKey(url) {
|
|
91
60
|
return { kind: "literal", url };
|
|
@@ -126,6 +95,7 @@ function pathsObjectType(paths, lookup = NO_DECLARED_TYPES) {
|
|
|
126
95
|
}
|
|
127
96
|
function pathMembers(paths, context) {
|
|
128
97
|
const members = [];
|
|
98
|
+
const takenUrls = new Set(Object.keys(paths));
|
|
129
99
|
for (const [url, pathItem] of documentEntries(paths, context.options)) {
|
|
130
100
|
if (!pathItem || typeof pathItem !== "object") {
|
|
131
101
|
continue;
|
|
@@ -137,9 +107,9 @@ function pathMembers(paths, context) {
|
|
|
137
107
|
continue;
|
|
138
108
|
}
|
|
139
109
|
const startedAt = context.diagnostics.now();
|
|
140
|
-
const
|
|
141
|
-
members.push(
|
|
142
|
-
if (
|
|
110
|
+
const pathMembersOfUrl = pathItemMembers(url, pathItem, context);
|
|
111
|
+
members.push(...withoutTakenUrls(url, pathMembersOfUrl, takenUrls));
|
|
112
|
+
if (pathMembersOfUrl[0]?.key.kind === "literal" && pathMembersOfUrl[0].key.url === url) {
|
|
143
113
|
context.diagnostics.debug(`Transformed path "${url}"`, context.diagnostics.now() - startedAt);
|
|
144
114
|
}
|
|
145
115
|
}
|
|
@@ -149,5 +119,5 @@ function pathsType(paths, context) {
|
|
|
149
119
|
return pathsObjectType(pathMembers(paths, context));
|
|
150
120
|
}
|
|
151
121
|
|
|
152
|
-
export { pathMembers, pathsObjectType, pathsType };
|
|
122
|
+
export { isUntakenKey, pathKeyOf, pathMembers, pathsObjectType, pathsType };
|
|
153
123
|
//# sourceMappingURL=paths.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.mjs","sources":["../../../../src/application/transform/document/paths.ts"],"sourcesContent":["import { irIntersection, irObject, irProperty, irRaw } from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { escapeTemplateText } from \"../../../domain/ir/raw-text-escapes.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport type { OperationObject } from \"../../../domain/openapi/operation-object.js\";\nimport type {\n ParameterObject,\n ParameterOrReference,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport {\n type PathItemObject,\n type PathsObject,\n pathItemOperations,\n} from \"../../../domain/openapi/path-item-object.js\";\nimport type { ReferenceSchema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { refType } from \"../ref-type.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { type DeclaredTypeLookup, NO_DECLARED_TYPES } from \"./declared-types.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { pathItemType } from \"./path-item.js\";\nimport {\n type CoverRejection,\n coveringTemplateKeys,\n type PathKey,\n type PathKeyPart,\n type PathPlaceholder,\n} from \"./path-key-overlaps.js\";\nimport {\n type PathParameterMatch,\n placeholderText,\n replacedTemplateParts,\n} from \"./path-template-replace.js\";\nimport { assignabilityProof } from \"./type-assignability.js\";\n\n/** `[^{}]` keeps the scan linear: `[^}]` retried from every `{` of a long run of them. */\nconst PATH_PARAMETER_RE = /\\{[^{}]+\\}/g;\n\n/** Placeholders by parameter schema type; anything else is a string placeholder. */\nconst PLACEHOLDERS: ReadonlyMap<unknown, PathPlaceholder> = new Map([\n [\"number\", \"number\"],\n [\"integer\", \"number\"],\n [\"boolean\", \"boolean\"],\n]);\nconst STRING_PLACEHOLDER: PathPlaceholder = \"string\";\n\nfunction resolvedParameter(\n parameter: ParameterOrReference,\n context: TransformContext,\n): ParameterObject | undefined {\n return \"$ref\" in parameter && parameter.$ref\n ? (context.refs.resolve(parameter.$ref) as ParameterObject | undefined)\n : (parameter as ParameterObject);\n}\n\nfunction addPathParameters(\n parameters: readonly ParameterOrReference[],\n byName: Map<string, ParameterObject>,\n context: TransformContext,\n): void {\n for (const parameter of parameters) {\n const resolved = resolvedParameter(parameter, context);\n if (resolved && resolved.in === \"path\") {\n byName.set(resolved.name, resolved);\n }\n }\n}\n\n/** Path parameters of the path item and of its operations; later definitions win. */\nfunction pathParameters(\n pathItem: PathItemObject,\n context: TransformContext,\n): Map<string, ParameterObject> {\n const byName = new Map<string, ParameterObject>();\n addPathParameters(pathItem.parameters ?? [], byName, context);\n for (const { operation: entry } of pathItemOperations(pathItem)) {\n const operation = (entry as ReferenceSchema).$ref\n ? (context.refs.resolve((entry as ReferenceSchema).$ref) as OperationObject | undefined)\n : (entry as OperationObject);\n addPathParameters(operation?.parameters ?? [], byName, context);\n }\n return byName;\n}\n\n/** Each `{name}` of the URL and its own placeholder, from the URL split at the matches. */\nfunction splitTemplateParts(url: string, matches: readonly PathParameterMatch[]): PathKeyPart[] {\n return url.split(PATH_PARAMETER_RE).flatMap((text, index): PathKeyPart[] => {\n const type = matches[index]?.type;\n const textPart: PathKeyPart = { kind: \"text\", text };\n return type === undefined ? [textPart] : [textPart, { kind: \"placeholder\", type }];\n });\n}\n\n/**\n * `--path-params-as-types`: the URL as template parts, each `{name}` replaced by a placeholder for\n * its parameter's type, the way the original replaces them unless the `path-param-type-names` fix\n * is on (see `replacedTemplateParts`). Null when the URL has no complete `{…}` placeholder.\n */\nfunction pathTemplateParts(\n url: string,\n pathItem: PathItemObject,\n context: TransformContext,\n): PathKeyPart[] | null {\n const found = url.match(PATH_PARAMETER_RE);\n if (!found) {\n return null;\n }\n const parameters = pathParameters(pathItem, context);\n const matches = found.map((match): PathParameterMatch => {\n const schema = parameters.get(match.slice(1, -1))?.schema as SchemaObject | undefined;\n return { match, type: PLACEHOLDERS.get(schema?.type) ?? STRING_PLACEHOLDER };\n });\n return context.options.fixes.has(FIX.PATH_PARAM_TYPE_NAMES)\n ? splitTemplateParts(url, matches)\n : replacedTemplateParts(url, matches);\n}\n\n/**\n * The template literal type of the parts. The original escaped only backticks: a backslash or\n * `${` in the URL could end the literal or open a placeholder, and add code to the generated file\n * (intentional fix). So the text parts are escaped.\n */\nfunction templateText(parts: readonly PathKeyPart[]): string {\n const text = parts\n .map((part) =>\n part.kind === \"text\" ? escapeTemplateText(part.text) : placeholderText(part.type),\n )\n .join(\"\");\n return `\\`${text}\\``;\n}\n\n/** A path's member, its key and its path item type for the overlap check. */\nexport interface PathMember {\n readonly url: string;\n readonly member: IrMember;\n readonly key: PathKey;\n readonly type: IrType;\n}\n\nfunction pathItemMember(\n url: string,\n pathItem: PathItemObject,\n context: TransformContext,\n): PathMember {\n const isReadonly = context.options.immutable;\n const type = pathItemType(\n pathItem,\n { path: appendPointer(ROOT_POINTER, [\"paths\", url]) },\n context,\n );\n const parts =\n context.options.pathParamsAsTypes && url.includes(\"{\")\n ? pathTemplateParts(url, pathItem, context)\n : null;\n if (parts === null) {\n const member = irProperty(toPropertyName(url), type, { isReadonly });\n return { url, member, key: literalKey(url), type };\n }\n const member: IrMember = {\n kind: \"indexSignature\",\n parameterName: \"path\",\n parameterType: irRaw(templateText(parts)),\n type,\n isReadonly,\n comments: [],\n };\n return { url, member, key: { kind: \"template\", parts }, type };\n}\n\nfunction literalKey(url: string): PathKey {\n return { kind: \"literal\", url };\n}\n\nconst PATHS_TYPE_NAME = \"paths\";\n\n/** The URL of `paths[\"/apps/{id}\"]`, or null for any other type. */\nfunction pathsIndexOf(type: IrType): string | null {\n if (type.kind !== \"indexedAccess\" || type.index.kind !== \"stringLiteral\") {\n return null;\n }\n const { object } = type;\n const isPaths =\n object.kind === \"reference\" &&\n object.name === PATHS_TYPE_NAME &&\n object.typeArguments.length === 0;\n return isPaths ? type.index.value : null;\n}\n\n/**\n * The lookup, and `paths[\"/apps/{id}\"]` as that path's item. The declarations cannot read it: a\n * templated path is no property of `paths`, and TypeScript finds it through the signature.\n */\nfunction withPathItems(\n paths: readonly PathMember[],\n lookup: DeclaredTypeLookup,\n): DeclaredTypeLookup {\n const byUrl = new Map(paths.map((path) => [path.url, path.type]));\n return (type) => {\n const url = pathsIndexOf(type);\n return (url === null ? undefined : byUrl.get(url)) ?? lookup(type);\n };\n}\n\n/**\n * The rejection of a covered path item: only one proven not assignable to the signature's type\n * counts (ADR-028). A pair the proof cannot decide keeps the original output, which may well\n * compile (`Record<string, never>` fits `{ [key: string]: unknown }`).\n */\nfunction rejectionOf(paths: readonly PathMember[], lookup: DeclaredTypeLookup): CoverRejection {\n const relate = assignabilityProof(withPathItems(paths, lookup));\n return (coveringIndex, coveredIndex) => {\n const coveringPath = paths[coveringIndex];\n const coveredPath = paths[coveredIndex];\n return (\n coveringPath !== undefined &&\n coveredPath !== undefined &&\n relate(coveredPath.type, coveringPath.type) === \"rejected\"\n );\n };\n}\n\n/**\n * The members as one object type. When an index signature covers another key, TypeScript checks\n * the covered key's type against it. Where that check surely fails (TS2411, TS2413), each such\n * signature gets an object of its own in an intersection: an intersection does not check its parts\n * against each other, and every key has the type it had in the one object. Output that compiles\n * keeps the one object. The lookup reads the types that path items reference; without it, a\n * reference decides nothing.\n */\nexport function pathsObjectType(\n paths: readonly PathMember[],\n lookup: DeclaredTypeLookup = NO_DECLARED_TYPES,\n): IrType {\n const keys = paths.map(({ key }) => key);\n const covering = coveringTemplateKeys(keys, rejectionOf(paths, lookup));\n if (covering.size === 0) {\n return irObject(paths.map(({ member }) => member));\n }\n const rest = paths.filter((_, index) => !covering.has(index)).map(({ member }) => member);\n const own = paths\n .filter((_, index) => covering.has(index))\n .map(({ member }) => irObject([member]));\n return irIntersection([irObject(rest), ...own]);\n}\n\n/** The members of the `paths` interface (OpenAPI 3.1 §4.8.8): one per path, by URL. */\nexport function pathMembers(paths: PathsObject, context: TransformContext): PathMember[] {\n const members: PathMember[] = [];\n for (const [url, pathItem] of documentEntries(paths, context.options)) {\n if (!pathItem || typeof pathItem !== \"object\") {\n continue;\n }\n if (\"$ref\" in pathItem) {\n const options = { isReadonly: context.options.immutable };\n const member = documentMember(url, refType(pathItem.$ref), pathItem, options);\n members.push({ url, member, key: literalKey(url), type: member.type });\n continue;\n }\n const startedAt = context.diagnostics.now();\n const path = pathItemMember(url, pathItem, context);\n members.push(path);\n // The original reports only paths written as properties.\n if (path.member.kind === \"property\") {\n context.diagnostics.debug(`Transformed path \"${url}\"`, context.diagnostics.now() - startedAt);\n }\n }\n return members;\n}\n\n/**\n * The `paths` interface body, with only the path items' own types for the overlap check. The\n * document transform checks the overlaps again once the referenced types are declared.\n */\nexport function pathsType(paths: PathsObject, context: TransformContext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, irProperty, irRaw } from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport type { PathItemObject, PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { refType } from \"../ref-type.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { type DeclaredTypeLookup, NO_DECLARED_TYPES } from \"./declared-types.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { pathItemType } from \"./path-item.js\";\nimport {\n type CoverRejection,\n coveringTemplateKeys,\n type PathKey,\n type PathKeyPart,\n} from \"./path-key-overlaps.js\";\nimport {\n booleanExpandedKeys,\n pathTemplateParts,\n plainUrlOf,\n templateText,\n} from \"./path-template-key.js\";\nimport { assignabilityProof } from \"./type-assignability.js\";\n\n/** A path's member, its key and its path item type for the overlap check. */\nexport interface PathMember {\n readonly url: string;\n readonly member: IrMember;\n readonly key: PathKey;\n readonly type: IrType;\n}\n\n/** The key of the parts: a plain URL, or a template with placeholders left. */\nexport function pathKeyOf(parts: readonly PathKeyPart[]): PathKey {\n const plainUrl = plainUrlOf(parts);\n return plainUrl === null ? { kind: \"template\", parts } : literalKey(plainUrl);\n}\n\n/** The member of one key of a path: a property for a plain URL, else an index signature. */\nfunction keyMember(url: string, parts: readonly PathKeyPart[], type: IrType, isReadonly: boolean) {\n const key = pathKeyOf(parts);\n if (key.kind === \"literal\") {\n const member = irProperty(toPropertyName(key.url), type, { isReadonly });\n return { url, member, key, type };\n }\n const member: IrMember = {\n kind: \"indexSignature\",\n parameterName: \"path\",\n parameterType: irRaw(templateText(parts)),\n type,\n isReadonly,\n comments: [],\n };\n return { url, member, key, type };\n}\n\n/**\n * Whether a key of the path at `url` is written. A URL that `${boolean}` keys give is not when it\n * is taken already: by a path of the document, which OpenAPI matches before a template (Paths\n * Object), or by the keys of an earlier path. A property written twice does not compile (TS2300).\n * `takenUrls` starts with the document's URLs and gets each expanded URL, in document order.\n */\nexport function isUntakenKey(url: string, key: PathKey, takenUrls: Set<string>): boolean {\n const isExpandedUrl = key.kind === \"literal\" && key.url !== url;\n if (!isExpandedUrl) {\n return true;\n }\n const isTaken = takenUrls.has(key.url);\n takenUrls.add(key.url);\n return !isTaken;\n}\n\nfunction withoutTakenUrls(url: string, members: readonly PathMember[], takenUrls: Set<string>) {\n return members.filter(({ key }) => isUntakenKey(url, key, takenUrls));\n}\n\n/** The members of a path: one, or one per key of its `${boolean}` placeholders. */\nfunction pathItemMembers(\n url: string,\n pathItem: PathItemObject,\n context: TransformContext,\n): PathMember[] {\n const isReadonly = context.options.immutable;\n const type = pathItemType(\n pathItem,\n { path: appendPointer(ROOT_POINTER, [\"paths\", url]) },\n context,\n );\n const parts =\n context.options.pathParamsAsTypes && url.includes(\"{\")\n ? pathTemplateParts(url, pathItem, context)\n : null;\n if (parts === null) {\n const member = irProperty(toPropertyName(url), type, { isReadonly });\n return [{ url, member, key: literalKey(url), type }];\n }\n return booleanExpandedKeys(parts).map((key) => keyMember(url, key, type, isReadonly));\n}\n\nfunction literalKey(url: string): PathKey {\n return { kind: \"literal\", url };\n}\n\nconst PATHS_TYPE_NAME = \"paths\";\n\n/** The URL of `paths[\"/apps/{id}\"]`, or null for any other type. */\nfunction pathsIndexOf(type: IrType): string | null {\n if (type.kind !== \"indexedAccess\" || type.index.kind !== \"stringLiteral\") {\n return null;\n }\n const { object } = type;\n const isPaths =\n object.kind === \"reference\" &&\n object.name === PATHS_TYPE_NAME &&\n object.typeArguments.length === 0;\n return isPaths ? type.index.value : null;\n}\n\n/**\n * The lookup, and `paths[\"/apps/{id}\"]` as that path's item. The declarations cannot read it: a\n * templated path is no property of `paths`, and TypeScript finds it through the signature.\n */\nfunction withPathItems(\n paths: readonly PathMember[],\n lookup: DeclaredTypeLookup,\n): DeclaredTypeLookup {\n const byUrl = new Map(paths.map((path) => [path.url, path.type]));\n return (type) => {\n const url = pathsIndexOf(type);\n return (url === null ? undefined : byUrl.get(url)) ?? lookup(type);\n };\n}\n\n/**\n * The rejection of a covered path item: only one proven not assignable to the signature's type\n * counts (ADR-028). A pair the proof cannot decide keeps the original output, which may well\n * compile (`Record<string, never>` fits `{ [key: string]: unknown }`).\n */\nfunction rejectionOf(paths: readonly PathMember[], lookup: DeclaredTypeLookup): CoverRejection {\n const relate = assignabilityProof(withPathItems(paths, lookup));\n return (coveringIndex, coveredIndex) => {\n const coveringPath = paths[coveringIndex];\n const coveredPath = paths[coveredIndex];\n return (\n coveringPath !== undefined &&\n coveredPath !== undefined &&\n relate(coveredPath.type, coveringPath.type) === \"rejected\"\n );\n };\n}\n\n/**\n * The members as one object type. When an index signature covers another key, TypeScript checks\n * the covered key's type against it. Where that check surely fails (TS2411, TS2413), each such\n * signature gets an object of its own in an intersection: an intersection does not check its parts\n * against each other, and every key has the type it had in the one object. Output that compiles\n * keeps the one object. The lookup reads the types that path items reference; without it, a\n * reference decides nothing.\n */\nexport function pathsObjectType(\n paths: readonly PathMember[],\n lookup: DeclaredTypeLookup = NO_DECLARED_TYPES,\n): IrType {\n const keys = paths.map(({ key }) => key);\n const covering = coveringTemplateKeys(keys, rejectionOf(paths, lookup));\n if (covering.size === 0) {\n return irObject(paths.map(({ member }) => member));\n }\n const rest = paths.filter((_, index) => !covering.has(index)).map(({ member }) => member);\n const own = paths\n .filter((_, index) => covering.has(index))\n .map(({ member }) => irObject([member]));\n return irIntersection([irObject(rest), ...own]);\n}\n\n/** The members of the `paths` interface (OpenAPI 3.1 §4.8.8): one per path, by URL. */\nexport function pathMembers(paths: PathsObject, context: TransformContext): PathMember[] {\n const members: PathMember[] = [];\n const takenUrls = new Set(Object.keys(paths));\n for (const [url, pathItem] of documentEntries(paths, context.options)) {\n if (!pathItem || typeof pathItem !== \"object\") {\n continue;\n }\n if (\"$ref\" in pathItem) {\n const options = { isReadonly: context.options.immutable };\n const member = documentMember(url, refType(pathItem.$ref), pathItem, options);\n members.push({ url, member, key: literalKey(url), type: member.type });\n continue;\n }\n const startedAt = context.diagnostics.now();\n const pathMembersOfUrl = pathItemMembers(url, pathItem, context);\n members.push(...withoutTakenUrls(url, pathMembersOfUrl, takenUrls));\n // The original reports only paths written as properties.\n if (pathMembersOfUrl[0]?.key.kind === \"literal\" && pathMembersOfUrl[0].key.url === url) {\n context.diagnostics.debug(`Transformed path \"${url}\"`, context.diagnostics.now() - startedAt);\n }\n }\n return members;\n}\n\n/**\n * The `paths` interface body, with only the path items' own types for the overlap check. The\n * document transform checks the overlaps again once the referenced types are declared.\n */\nexport function pathsType(paths: PathsObject, context: TransformContext): IrType {\n return pathsObjectType(pathMembers(paths, context));\n}\n"],"names":["member"],"mappings":";;;;;;;;;;;;AAkCO,SAAS,UAAU,KAAA,EAAwC;AAChE,EAAA,MAAM,QAAA,GAAW,WAAW,KAAK,CAAA;AACjC,EAAA,OAAO,QAAA,KAAa,OAAO,EAAE,IAAA,EAAM,YAAY,KAAA,EAAM,GAAI,WAAW,QAAQ,CAAA;AAC9E;AAGA,SAAS,SAAA,CAAU,GAAA,EAAa,KAAA,EAA+B,IAAA,EAAc,UAAA,EAAqB;AAChG,EAAA,MAAM,GAAA,GAAM,UAAU,KAAK,CAAA;AAC3B,EAAA,IAAI,GAAA,CAAI,SAAS,SAAA,EAAW;AAC1B,IAAA,MAAMA,OAAAA,GAAS,WAAW,cAAA,CAAe,GAAA,CAAI,GAAG,CAAA,EAAG,IAAA,EAAM,EAAE,UAAA,EAAY,CAAA;AACvE,IAAA,OAAO,EAAE,GAAA,EAAK,MAAA,EAAAA,OAAAA,EAAQ,KAAK,IAAA,EAAK;AAAA,EAClC;AACA,EAAA,MAAM,MAAA,GAAmB;AAAA,IACvB,IAAA,EAAM,gBAAA;AAAA,IACN,aAAA,EAAe,MAAA;AAAA,IACf,aAAA,EAAe,KAAA,CAAM,YAAA,CAAa,KAAK,CAAC,CAAA;AAAA,IACxC,IAAA;A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AA,EAAK;AACtF,MAAA,OAAA,CAAQ,WAAA,CAAY,MAAM,CAAA,kBAAA,EAAqB,GAAG,KAAK,OAAA,CAAQ,WAAA,CAAY,GAAA,EAAI,GAAI,SAAS,CAAA;AAAA,IAC9F;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAMO,SAAS,SAAA,CAAU,OAAoB,OAAA,EAAmC;AAC/E,EAAA,OAAO,eAAA,CAAgB,WAAA,CAAY,KAAA,EAAO,OAAO,CAAC,CAAA;AACpD;;"}
|
|
@@ -4,16 +4,23 @@ const constructors = require('../../../domain/ir/constructors.cjs');
|
|
|
4
4
|
const propertyName = require('../../../domain/ir/property-name.cjs');
|
|
5
5
|
const jsonPointer = require('../../../domain/openapi/json-pointer.cjs');
|
|
6
6
|
const documentEntries = require('../document-entries.cjs');
|
|
7
|
+
const refType = require('../ref-type.cjs');
|
|
7
8
|
const pathItem = require('./path-item.cjs');
|
|
8
9
|
|
|
9
10
|
function webhooksType(webhooks, context) {
|
|
10
|
-
const members = documentEntries.documentEntries(webhooks, context.options).map(([name, pathItem
|
|
11
|
-
const
|
|
12
|
-
const type = pathItem.pathItemType(pathItem$1, location, context);
|
|
11
|
+
const members = documentEntries.documentEntries(webhooks, context.options).map(([name, pathItem]) => {
|
|
12
|
+
const type = webhookType(name, pathItem, context);
|
|
13
13
|
return constructors.irProperty(propertyName.toPropertyName(name), type, { isReadonly: context.options.immutable });
|
|
14
14
|
});
|
|
15
15
|
return constructors.irObject(members);
|
|
16
16
|
}
|
|
17
|
+
function webhookType(name, pathItem$1, context) {
|
|
18
|
+
if (typeof pathItem$1 === "object" && pathItem$1 !== null && "$ref" in pathItem$1) {
|
|
19
|
+
return refType.refType(pathItem$1.$ref);
|
|
20
|
+
}
|
|
21
|
+
const location = { path: jsonPointer.appendPointer(jsonPointer.ROOT_POINTER, ["webhooks", name]) };
|
|
22
|
+
return pathItem.pathItemType(pathItem$1, location, context);
|
|
23
|
+
}
|
|
17
24
|
|
|
18
25
|
exports.webhooksType = webhooksType;
|
|
19
26
|
//# sourceMappingURL=webhooks.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.cjs","sources":["../../../../src/application/transform/document/webhooks.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport type { PathItemObject, PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { pathItemType } from \"./path-item.js\";\n\n/**\n * The `webhooks` interface body (OpenAPI 3.1 §4.8.1): one path item per webhook name.
|
|
1
|
+
{"version":3,"file":"webhooks.cjs","sources":["../../../../src/application/transform/document/webhooks.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport type { PathItemObject, PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { refType } from \"../ref-type.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { pathItemType } from \"./path-item.js\";\n\n/**\n * The `webhooks` interface body (OpenAPI 3.1 §4.8.1): one path item per webhook name. A `$ref`\n * entry (often to `components/pathItems`) is the type it points at, as in `paths`; the original\n * read it as a path item, so every method was `never`. Members carry no JSDoc.\n */\nexport function webhooksType(webhooks: PathsObject, context: TransformContext): IrType {\n const members = documentEntries(webhooks, context.options).map(([name, pathItem]) => {\n const type = webhookType(name, pathItem, context);\n return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n\nfunction webhookType(\n name: string,\n pathItem: PathsObject[string],\n context: TransformContext,\n): IrType {\n // A document may hold any value here; one that is no object is read as a path item, as before.\n if (typeof pathItem === \"object\" && pathItem !== null && \"$ref\" in pathItem) {\n return refType(pathItem.$ref);\n }\n const location = { path: appendPointer(ROOT_POINTER, [\"webhooks\", name]) };\n return pathItemType(pathItem as PathItemObject, location, context);\n}\n"],"names":["documentEntries","irProperty","toPropertyName","irObject","pathItem","refType","appendPointer","ROOT_POINTER","pathItemType"],"mappings":";;;;;;;;;AAeO,SAAS,YAAA,CAAa,UAAuB,OAAA,EAAmC;AACrF,EAAA,MAAM,OAAA,GAAUA,+BAAA,CAAgB,QAAA,EAAU,OAAA,CAAQ,OAAO,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,IAAA,EAAM,QAAQ,CAAA,KAAM;AACnF,IAAA,MAAM,IAAA,GAAO,WAAA,CAAY,IAAA,EAAM,QAAA,EAAU,OAAO,CAAA;AAChD,IAAA,OAAOC,uBAAA,CAAWC,2BAAA,CAAe,IAAI,CAAA,EAAG,IAAA,EAAM,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EACzF,CAAC,CAAA;AACD,EAAA,OAAOC,sBAAS,OAAO,CAAA;AACzB;AAEA,SAAS,WAAA,CACP,IAAA,EACAC,UAAA,EACA,OAAA,EACQ;AAER,EAAA,IAAI,OAAOA,UAAA,KAAa,QAAA,IAAYA,UAAA,KAAa,IAAA,IAAQ,UAAUA,UAAA,EAAU;AAC3E,IAAA,OAAOC,eAAA,CAAQD,WAAS,IAAI,CAAA;AAAA,EAC9B;AACA,EAAA,MAAM,QAAA,GAAW,EAAE,IAAA,EAAME,yBAAA,CAAcC,0BAAc,CAAC,UAAA,EAAY,IAAI,CAAC,CAAA,EAAE;AACzE,EAAA,OAAOC,qBAAA,CAAaJ,UAAA,EAA4B,QAAA,EAAU,OAAO,CAAA;AACnE;;"}
|
|
@@ -2,16 +2,23 @@ import { irProperty, irObject } from '../../../domain/ir/constructors.mjs';
|
|
|
2
2
|
import { toPropertyName } from '../../../domain/ir/property-name.mjs';
|
|
3
3
|
import { appendPointer, ROOT_POINTER } from '../../../domain/openapi/json-pointer.mjs';
|
|
4
4
|
import { documentEntries } from '../document-entries.mjs';
|
|
5
|
+
import { refType } from '../ref-type.mjs';
|
|
5
6
|
import { pathItemType } from './path-item.mjs';
|
|
6
7
|
|
|
7
8
|
function webhooksType(webhooks, context) {
|
|
8
9
|
const members = documentEntries(webhooks, context.options).map(([name, pathItem]) => {
|
|
9
|
-
const
|
|
10
|
-
const type = pathItemType(pathItem, location, context);
|
|
10
|
+
const type = webhookType(name, pathItem, context);
|
|
11
11
|
return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });
|
|
12
12
|
});
|
|
13
13
|
return irObject(members);
|
|
14
14
|
}
|
|
15
|
+
function webhookType(name, pathItem, context) {
|
|
16
|
+
if (typeof pathItem === "object" && pathItem !== null && "$ref" in pathItem) {
|
|
17
|
+
return refType(pathItem.$ref);
|
|
18
|
+
}
|
|
19
|
+
const location = { path: appendPointer(ROOT_POINTER, ["webhooks", name]) };
|
|
20
|
+
return pathItemType(pathItem, location, context);
|
|
21
|
+
}
|
|
15
22
|
|
|
16
23
|
export { webhooksType };
|
|
17
24
|
//# sourceMappingURL=webhooks.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.mjs","sources":["../../../../src/application/transform/document/webhooks.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport type { PathItemObject, PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { pathItemType } from \"./path-item.js\";\n\n/**\n * The `webhooks` interface body (OpenAPI 3.1 §4.8.1): one path item per webhook name.
|
|
1
|
+
{"version":3,"file":"webhooks.mjs","sources":["../../../../src/application/transform/document/webhooks.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport type { PathItemObject, PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { refType } from \"../ref-type.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { pathItemType } from \"./path-item.js\";\n\n/**\n * The `webhooks` interface body (OpenAPI 3.1 §4.8.1): one path item per webhook name. A `$ref`\n * entry (often to `components/pathItems`) is the type it points at, as in `paths`; the original\n * read it as a path item, so every method was `never`. Members carry no JSDoc.\n */\nexport function webhooksType(webhooks: PathsObject, context: TransformContext): IrType {\n const members = documentEntries(webhooks, context.options).map(([name, pathItem]) => {\n const type = webhookType(name, pathItem, context);\n return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n\nfunction webhookType(\n name: string,\n pathItem: PathsObject[string],\n context: TransformContext,\n): IrType {\n // A document may hold any value here; one that is no object is read as a path item, as before.\n if (typeof pathItem === \"object\" && pathItem !== null && \"$ref\" in pathItem) {\n return refType(pathItem.$ref);\n }\n const location = { path: appendPointer(ROOT_POINTER, [\"webhooks\", name]) };\n return pathItemType(pathItem as PathItemObject, location, context);\n}\n"],"names":[],"mappings":";;;;;;;AAeO,SAAS,YAAA,CAAa,UAAuB,OAAA,EAAmC;AACrF,EAAA,MAAM,OAAA,GAAU,eAAA,CAAgB,QAAA,EAAU,OAAA,CAAQ,OAAO,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,IAAA,EAAM,QAAQ,CAAA,KAAM;AACnF,IAAA,MAAM,IAAA,GAAO,WAAA,CAAY,IAAA,EAAM,QAAA,EAAU,OAAO,CAAA;AAChD,IAAA,OAAO,UAAA,CAAW,cAAA,CAAe,IAAI,CAAA,EAAG,IAAA,EAAM,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EACzF,CAAC,CAAA;AACD,EAAA,OAAO,SAAS,OAAO,CAAA;AACzB;AAEA,SAAS,WAAA,CACP,IAAA,EACA,QAAA,EACA,OAAA,EACQ;AAER,EAAA,IAAI,OAAO,QAAA,KAAa,QAAA,IAAY,QAAA,KAAa,IAAA,IAAQ,UAAU,QAAA,EAAU;AAC3E,IAAA,OAAO,OAAA,CAAQ,SAAS,IAAI,CAAA;AAAA,EAC9B;AACA,EAAA,MAAM,QAAA,GAAW,EAAE,IAAA,EAAM,aAAA,CAAc,cAAc,CAAC,UAAA,EAAY,IAAI,CAAC,CAAA,EAAE;AACzE,EAAA,OAAO,YAAA,CAAa,QAAA,EAA4B,QAAA,EAAU,OAAO,CAAA;AACnE;;"}
|
|
@@ -8,7 +8,10 @@ const operationKeys = require('./operation-keys.cjs');
|
|
|
8
8
|
const sharedEnumNames = require('./shared-enum-names.cjs');
|
|
9
9
|
|
|
10
10
|
function dedupeKey(request) {
|
|
11
|
-
|
|
11
|
+
const sorted = [...request.values].sort(compareAsStrings);
|
|
12
|
+
const originalPairs = sorted.map((value, index) => memberKey(value, request.metadata[index]));
|
|
13
|
+
const ownPairs = request.values.map((value, index) => ({ value, member: memberKey(value, request.metadata[index]) })).sort((left, right) => compareAsStrings(left.value, right.value)).map(({ member }) => member);
|
|
14
|
+
return JSON.stringify([originalPairs, ownPairs]);
|
|
12
15
|
}
|
|
13
16
|
function compareAsStrings(left, right) {
|
|
14
17
|
const leftText = String(left);
|
|
@@ -18,8 +21,8 @@ function compareAsStrings(left, right) {
|
|
|
18
21
|
}
|
|
19
22
|
return leftText < rightText ? -1 : 1;
|
|
20
23
|
}
|
|
21
|
-
function
|
|
22
|
-
return
|
|
24
|
+
function memberKey(value, metadata) {
|
|
25
|
+
return [value, metadata?.name ?? null, metadata?.description || null];
|
|
23
26
|
}
|
|
24
27
|
const ENUM_VALUES_NUMBER_SEPARATOR = "_";
|
|
25
28
|
function declarationKey(name, request) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-footer.cjs","sources":["../../../../src/application/transform/footer/document-footer.ts"],"sourcesContent":["import { irReference } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrEnumDeclaration,\n IrPropertySignature,\n IrType,\n} from \"../../../domain/ir/nodes.js\";\nimport { HELPER_TYPES, type HelperType } from \"../helper-types.js\";\nimport type {\n EnumDeclarationRequest,\n EnumMemberMetadata,\n EnumValuesRequest,\n} from \"../schema/schema-context.js\";\nimport type { DocumentFooter } from \"../transform-context.js\";\nimport { EnumNameClaims } from \"./enum-name-claims.js\";\nimport {\n type DeclaredMembers,\n EnumNaming,\n enumDeclaration,\n withoutDeclaredMembers,\n} from \"./enum-naming.js\";\nimport { OperationKeys } from \"./operation-keys.js\";\nimport { FIRST_SCHEMA_NAMES, type SharedEnumNames } from \"./shared-enum-names.js\";\n\n/** Where footer declarations go, in order: the run's `ctx.injectFooter`, open to user code. */\nexport interface FooterSink {\n /** Whether a type alias with this name is declared already (by the generator or a user). */\n hasTypeAlias(name: string): boolean;\n add(declaration: IrDeclaration): void;\n /** Add a member to the `operations` interface, declared first if needed; see `DocumentFooter`. */\n addOperation(build: () => IrPropertySignature): void;\n}\n\n/**\n * The `--dedupe-enums` key of the original: the values in default sort order, each paired with\n * the metadata at its sorted position (not the value's own metadata), as the original does.\n */\nfunction dedupeKey(request: EnumDeclarationRequest): string {\n return [...request.values]\n .sort(compareAsStrings)\n .map((value, index) => metadataKey(String(value), request.metadata[index]))\n .join(\",\");\n}\n\n/** `Array.prototype.sort` without a comparator: compares the values as strings. */\nfunction compareAsStrings(left: string | number, right: string | number): number {\n const leftText = String(left);\n const rightText = String(right);\n if (leftText === rightText) {\n return 0;\n }\n return leftText < rightText ? -1 : 1;\n}\n\nfunction metadataKey(value: string, metadata: EnumMemberMetadata | undefined): string {\n return `${metadata?.name ?? value}:${metadata?.description || \"\"}`;\n}\n\n/** Separates a repeated `--enum-values` array name from its number, as root type aliases do. */\nconst ENUM_VALUES_NUMBER_SEPARATOR = \"_\";\n\n/** The whole declaration: an equal key means the same enum, member for member. */\nfunction declarationKey(name: string, request: EnumDeclarationRequest): string {\n return JSON.stringify([name, request.values, request.metadata]);\n}\n\n/** The naming state a run's footer shares with the rest of the run. */\nexport interface RunFooterNames {\n readonly enums: EnumNameClaims;\n readonly operations: OperationKeys;\n}\n\n/**\n * The footer of one run: enums (deduplicated with `--dedupe-enums`), `--enum-values` arrays, the\n * helper types they need, and the `operations` interface. Replaces the original's module-level\n * `enumCache`, so runs no longer share enums (research/legacy-bugs.md, item 3).\n */\nexport class RunFooter implements DocumentFooter {\n private readonly naming = new EnumNaming();\n private readonly enumNamesByKey = new Map<string, string>();\n /** Declarations added already: the same one twice fails with \"Duplicate identifier\". */\n private readonly declaredEnums = new Set<string>();\n /** The member names of each declared enum, by value. */\n private readonly membersByEnum = new Map<string, Map<string | number, string>>();\n /** The members of each declared enum name, by member name. */\n private readonly declaredMembers = new Map<string, Map<string, string | number>>();\n /** `--enum-values` arrays added already: their declared name by name, type and values. */\n private readonly declaredEnumValues = new Map<string, string>();\n /** The declared `--enum-values` array names. */\n private readonly enumValuesNames = new Set<string>();\n private readonly sink: FooterSink;\n private readonly isDedupingEnums: boolean;\n private readonly sharedNames: SharedEnumNames;\n private readonly names: RunFooterNames;\n\n constructor(\n sink: FooterSink,\n isDedupingEnums: boolean,\n sharedNames: SharedEnumNames = FIRST_SCHEMA_NAMES,\n names: RunFooterNames = { enums: new EnumNameClaims(), operations: new OperationKeys() },\n ) {\n this.sink = sink;\n this.isDedupingEnums = isDedupingEnums;\n this.sharedNames = sharedNames;\n this.names = names;\n }\n\n addEnum(request: EnumDeclarationRequest): string {\n // The name is built before the cache lookup: it advances the naming state either way.\n const ownName = this.naming.enumName(request.name);\n const key = this.isDedupingEnums ? dedupeKey(request) : null;\n // Every schema of a shared enum goes to `sharedNames`, the later ones too.\n const sharedName = key === null ? ownName : this.sharedNames.nameOf(key, ownName, request);\n const known = key === null ? undefined : this.enumNamesByKey.get(key);\n if (known !== undefined) {\n return known;\n }\n // The owner is the schema location: its requests share one enum, with `--dedupe-enums` too.\n const name = this.names.enums.nameFor(sharedName, request.name);\n // Only a repeated member fails to compile; two empty declarations merge, so they stay.\n const declared = request.values.length > 0 ? declarationKey(name, request) : null;\n if (declared !== null && this.declaredEnums.has(declared)) {\n return name;\n }\n if (declared !== null) {\n this.declaredEnums.add(declared);\n }\n const declaration = this.withoutRepeats(enumDeclaration(name, request, this.naming));\n if (declaration !== null) {\n this.record(declaration);\n this.sink.add(declaration);\n }\n if (key !== null) {\n this.enumNamesByKey.set(key, name);\n }\n return name;\n }\n\n /** The declaration without members an earlier one of the name has; null when none is left. */\n private withoutRepeats(declaration: IrEnumDeclaration): IrEnumDeclaration | null {\n const earlier: DeclaredMembers | undefined = this.declaredMembers.get(declaration.name);\n if (earlier === undefined) {\n return declaration;\n }\n const merged = withoutDeclaredMembers(declaration, earlier);\n // Two empty declarations merge into one empty enum, which compiles, so the second stays.\n return merged.members.length === 0 && declaration.members.length > 0 ? null : merged;\n }\n\n /** The members of a declaration; the first member of a value names it. */\n private record(declaration: IrEnumDeclaration): void {\n const byName = this.declaredMembers.get(declaration.name) ?? new Map();\n const byValue = this.membersByEnum.get(declaration.name) ?? new Map();\n for (const member of declaration.members) {\n byName.set(member.name, member.value);\n if (!byValue.has(member.value)) {\n byValue.set(member.value, member.name);\n }\n }\n this.declaredMembers.set(declaration.name, byName);\n this.membersByEnum.set(declaration.name, byValue);\n }\n\n enumMembers(name: string): ReadonlyMap<string | number, string> {\n return this.membersByEnum.get(name) ?? new Map();\n }\n\n addEnumValues(request: EnumValuesRequest): void {\n const baseName = this.naming.arrayName(request.name);\n // The same array twice fails with \"Cannot redeclare\"; a schema typed twice adds it twice.\n const declared = JSON.stringify([baseName, request.type, request.values]);\n if (this.declaredEnumValues.has(declared)) {\n return;\n }\n const name = this.freeEnumValuesName(baseName);\n this.declaredEnumValues.set(declared, name);\n this.enumValuesNames.add(name);\n this.require(HELPER_TYPES.flattenedDeepRequired);\n this.require(HELPER_TYPES.readonlyArray);\n this.sink.add({\n kind: \"constArray\",\n name,\n isExported: true,\n type: readonlyArrayOf(request.type),\n values: request.values,\n comments: [],\n });\n }\n\n /**\n * Another array may have the name: `Discount/type` and `discount/type`, or a property and an\n * inline `allOf` item of one schema, typed at one location. A redeclared `const` does not\n * compile, so a later one gets the next number (`discountTypeValues_2`). Every unnumbered name\n * ends with `Values`, so a number never takes a name that a later array needs.\n */\n private freeEnumValuesName(name: string): string {\n let candidate = name;\n for (let count = 2; this.enumValuesNames.has(candidate); count++) {\n candidate = `${name}${ENUM_VALUES_NUMBER_SEPARATOR}${count}`;\n }\n return candidate;\n }\n\n requireWithRequired(): void {\n this.require(HELPER_TYPES.withRequired);\n }\n\n requirePropertyValues(): void {\n this.require(HELPER_TYPES.propertyValues);\n }\n\n addOperation(build: () => IrPropertySignature): void {\n this.sink.addOperation(build);\n }\n\n operationKey(operationId: string): string {\n return this.names.operations.keyFor(operationId);\n }\n\n private require(helper: HelperType): void {\n if (!this.sink.hasTypeAlias(helper.name)) {\n this.sink.add({ kind: \"rawDeclaration\", name: helper.name, text: helper.text });\n }\n }\n}\n\nfunction readonlyArrayOf(type: IrType): IrType {\n return irReference(HELPER_TYPES.readonlyArray.name, [type]);\n}\n"],"names":["EnumNaming","FIRST_SCHEMA_NAMES","EnumNameClaims","OperationKeys","enumDeclaration","withoutDeclaredMembers","HELPER_TYPES","irReference"],"mappings":";;;;;;;;;AAqCA,SAAS,UAAU,OAAA,EAAyC;AAC1D,EAAA,OAAO,CAAC,GAAG,OAAA,CAAQ,MAAM,EACtB,IAAA,CAAK,gBAAgB,CAAA,CACrB,GAAA,CA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SAAS,gBAAgB,IAAA,EAAsB;AAC7C,EAAA,OAAOC,yBAAYD,wBAAA,CAAa,aAAA,CAAc,IAAA,EAAM,CAAC,IAAI,CAAC,CAAA;AAC5D;;"}
|
|
1
|
+
{"version":3,"file":"document-footer.cjs","sources":["../../../../src/application/transform/footer/document-footer.ts"],"sourcesContent":["import { irReference } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrEnumDeclaration,\n IrPropertySignature,\n IrType,\n} from \"../../../domain/ir/nodes.js\";\nimport { HELPER_TYPES, type HelperType } from \"../helper-types.js\";\nimport type {\n EnumDeclarationRequest,\n EnumMemberMetadata,\n EnumValuesRequest,\n} from \"../schema/schema-context.js\";\nimport type { DocumentFooter } from \"../transform-context.js\";\nimport { EnumNameClaims } from \"./enum-name-claims.js\";\nimport {\n type DeclaredMembers,\n EnumNaming,\n enumDeclaration,\n withoutDeclaredMembers,\n} from \"./enum-naming.js\";\nimport { OperationKeys } from \"./operation-keys.js\";\nimport { FIRST_SCHEMA_NAMES, type SharedEnumNames } from \"./shared-enum-names.js\";\n\n/** Where footer declarations go, in order: the run's `ctx.injectFooter`, open to user code. */\nexport interface FooterSink {\n /** Whether a type alias with this name is declared already (by the generator or a user). */\n hasTypeAlias(name: string): boolean;\n add(declaration: IrDeclaration): void;\n /** Add a member to the `operations` interface, declared first if needed; see `DocumentFooter`. */\n addOperation(build: () => IrPropertySignature): void;\n}\n\n/**\n * The `--dedupe-enums` key. Two enums share a declaration only when the original shares it and\n * each value has the same name and description in both. The original key pairs the values in\n * default sort order with the metadata at the sorted position, not with the value's own metadata,\n * so `[desc, asc]` and `[asc, desc]`, both named `[Desc, Asc]`, shared one declaration, and one of\n * them typed `asc` as `Desc = \"desc\"`. The original also joined `name:description` texts with\n * `,`, and a member name stood in for its value, so enums with other values (`\"1\"` and `1`, `A`\n * and `1` both named `Active`, `[\"a\", \"b\"]` and `[\"a:,b\"]`) shared one key. As JSON, an equal key\n * means the same values and metadata; enums the original kept apart still are.\n */\nfunction dedupeKey(request: EnumDeclarationRequest): string {\n const sorted = [...request.values].sort(compareAsStrings);\n const originalPairs = sorted.map((value, index) => memberKey(value, request.metadata[index]));\n const ownPairs = request.values\n .map((value, index) => ({ value, member: memberKey(value, request.metadata[index]) }))\n .sort((left, right) => compareAsStrings(left.value, right.value))\n .map(({ member }) => member);\n return JSON.stringify([originalPairs, ownPairs]);\n}\n\n/** `Array.prototype.sort` without a comparator: compares the values as strings. */\nfunction compareAsStrings(left: string | number, right: string | number): number {\n const leftText = String(left);\n const rightText = String(right);\n if (leftText === rightText) {\n return 0;\n }\n return leftText < rightText ? -1 : 1;\n}\n\n/** One member: the value (JSON keeps `\"1\"` and `1` apart), its name and its description. */\nfunction memberKey(value: string | number, metadata: EnumMemberMetadata | undefined) {\n return [value, metadata?.name ?? null, metadata?.description || null];\n}\n\n/** Separates a repeated `--enum-values` array name from its number, as root type aliases do. */\nconst ENUM_VALUES_NUMBER_SEPARATOR = \"_\";\n\n/** The whole declaration: an equal key means the same enum, member for member. */\nfunction declarationKey(name: string, request: EnumDeclarationRequest): string {\n return JSON.stringify([name, request.values, request.metadata]);\n}\n\n/** The naming state a run's footer shares with the rest of the run. */\nexport interface RunFooterNames {\n readonly enums: EnumNameClaims;\n readonly operations: OperationKeys;\n}\n\n/**\n * The footer of one run: enums (deduplicated with `--dedupe-enums`), `--enum-values` arrays, the\n * helper types they need, and the `operations` interface. Replaces the original's module-level\n * `enumCache`, so runs no longer share enums (research/legacy-bugs.md, item 3).\n */\nexport class RunFooter implements DocumentFooter {\n private readonly naming = new EnumNaming();\n private readonly enumNamesByKey = new Map<string, string>();\n /** Declarations added already: the same one twice fails with \"Duplicate identifier\". */\n private readonly declaredEnums = new Set<string>();\n /** The member names of each declared enum, by value. */\n private readonly membersByEnum = new Map<string, Map<string | number, string>>();\n /** The members of each declared enum name, by member name. */\n private readonly declaredMembers = new Map<string, Map<string, string | number>>();\n /** `--enum-values` arrays added already: their declared name by name, type and values. */\n private readonly declaredEnumValues = new Map<string, string>();\n /** The declared `--enum-values` array names. */\n private readonly enumValuesNames = new Set<string>();\n private readonly sink: FooterSink;\n private readonly isDedupingEnums: boolean;\n private readonly sharedNames: SharedEnumNames;\n private readonly names: RunFooterNames;\n\n constructor(\n sink: FooterSink,\n isDedupingEnums: boolean,\n sharedNames: SharedEnumNames = FIRST_SCHEMA_NAMES,\n names: RunFooterNames = { enums: new EnumNameClaims(), operations: new OperationKeys() },\n ) {\n this.sink = sink;\n this.isDedupingEnums = isDedupingEnums;\n this.sharedNames = sharedNames;\n this.names = names;\n }\n\n addEnum(request: EnumDeclarationRequest): string {\n // The name is built before the cache lookup: it advances the naming state either way.\n const ownName = this.naming.enumName(request.name);\n const key = this.isDedupingEnums ? dedupeKey(request) : null;\n // Every schema of a shared enum goes to `sharedNames`, the later ones too.\n const sharedName = key === null ? ownName : this.sharedNames.nameOf(key, ownName, request);\n const known = key === null ? undefined : this.enumNamesByKey.get(key);\n if (known !== undefined) {\n return known;\n }\n // The owner is the schema location: its requests share one enum, with `--dedupe-enums` too.\n const name = this.names.enums.nameFor(sharedName, request.name);\n // Only a repeated member fails to compile; two empty declarations merge, so they stay.\n const declared = request.values.length > 0 ? declarationKey(name, request) : null;\n if (declared !== null && this.declaredEnums.has(declared)) {\n return name;\n }\n if (declared !== null) {\n this.declaredEnums.add(declared);\n }\n const declaration = this.withoutRepeats(enumDeclaration(name, request, this.naming));\n if (declaration !== null) {\n this.record(declaration);\n this.sink.add(declaration);\n }\n if (key !== null) {\n this.enumNamesByKey.set(key, name);\n }\n return name;\n }\n\n /** The declaration without members an earlier one of the name has; null when none is left. */\n private withoutRepeats(declaration: IrEnumDeclaration): IrEnumDeclaration | null {\n const earlier: DeclaredMembers | undefined = this.declaredMembers.get(declaration.name);\n if (earlier === undefined) {\n return declaration;\n }\n const merged = withoutDeclaredMembers(declaration, earlier);\n // Two empty declarations merge into one empty enum, which compiles, so the second stays.\n return merged.members.length === 0 && declaration.members.length > 0 ? null : merged;\n }\n\n /** The members of a declaration; the first member of a value names it. */\n private record(declaration: IrEnumDeclaration): void {\n const byName = this.declaredMembers.get(declaration.name) ?? new Map();\n const byValue = this.membersByEnum.get(declaration.name) ?? new Map();\n for (const member of declaration.members) {\n byName.set(member.name, member.value);\n if (!byValue.has(member.value)) {\n byValue.set(member.value, member.name);\n }\n }\n this.declaredMembers.set(declaration.name, byName);\n this.membersByEnum.set(declaration.name, byValue);\n }\n\n enumMembers(name: string): ReadonlyMap<string | number, string> {\n return this.membersByEnum.get(name) ?? new Map();\n }\n\n addEnumValues(request: EnumValuesRequest): void {\n const baseName = this.naming.arrayName(request.name);\n // The same array twice fails with \"Cannot redeclare\"; a schema typed twice adds it twice.\n const declared = JSON.stringify([baseName, request.type, request.values]);\n if (this.declaredEnumValues.has(declared)) {\n return;\n }\n const name = this.freeEnumValuesName(baseName);\n this.declaredEnumValues.set(declared, name);\n this.enumValuesNames.add(name);\n this.require(HELPER_TYPES.flattenedDeepRequired);\n this.require(HELPER_TYPES.readonlyArray);\n this.sink.add({\n kind: \"constArray\",\n name,\n isExported: true,\n type: readonlyArrayOf(request.type),\n values: request.values,\n comments: [],\n });\n }\n\n /**\n * Another array may have the name: `Discount/type` and `discount/type`, or a property and an\n * inline `allOf` item of one schema, typed at one location. A redeclared `const` does not\n * compile, so a later one gets the next number (`discountTypeValues_2`). Every unnumbered name\n * ends with `Values`, so a number never takes a name that a later array needs.\n */\n private freeEnumValuesName(name: string): string {\n let candidate = name;\n for (let count = 2; this.enumValuesNames.has(candidate); count++) {\n candidate = `${name}${ENUM_VALUES_NUMBER_SEPARATOR}${count}`;\n }\n return candidate;\n }\n\n requireWithRequired(): void {\n this.require(HELPER_TYPES.withRequired);\n }\n\n requirePropertyValues(): void {\n this.require(HELPER_TYPES.propertyValues);\n }\n\n addOperation(build: () => IrPropertySignature): void {\n this.sink.addOperation(build);\n }\n\n operationKey(operationId: string): string {\n return this.names.operations.keyFor(operationId);\n }\n\n private require(helper: HelperType): void {\n if (!this.sink.hasTypeAlias(helper.name)) {\n this.sink.add({ kind: \"rawDeclaration\", name: helper.name, text: helper.text });\n }\n }\n}\n\nfunction readonlyArrayOf(type: IrType): IrType {\n return irReference(HELPER_TYPES.readonlyArray.name, [type]);\n}\n"],"names":["EnumNaming","FIRST_SCHEMA_NAMES","EnumNameClaims","OperationKeys","enumDeclaration","withoutDeclaredMembers","HELPER_TYPES","irReference"],"mappings":";;;;;;;;;AA2CA,SAAS,UAAU,OAAA,EAAyC;AAC1D,EAAA,MAAM,SAAS,CAAC,GAAG,QAAQ,MAAM,CAAA,CAAE,KAAK,gBAAgB,CAAA;AACxD,EAAA,MAAM,aAAA,GAAgB,MAAA,CAAO,GAAA,CAAI,CAAC,KAAA,EAAO,KAAA,KAAU,SAAA,CAAU,KAAA,EAAO,OAAA,CAAQ,QAAA,CAAS,KAAK,CAAC,CAAC,CAAA;AAC5F,EAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,MAAA,CACtB,GAAA,CAAI,CAAC,KAAA,EAAO,KAAA,MAAW,EAAE,KAAA,EAAO,QAAQ,SAAA,CAAU,KAAA,EAAO,OAAA,CAAQ,QAAA,CAAS,KAAK,CAAC,CAAA,EAAE,CAAE,CAAA,CACpF,KAAK,CAAC,IAAA,EAAM,KAAA,KAAU,gBAAA,CAAiB,KAAK,KAAA,EAAO,KAAA,CAAM,KAAK,CAAC,EAC/D,GAAA,CAAI,CAAC,EAAE,MAAA,OAAa,MAAM,CAAA;AAC7B,EAAA,OAAO,IAAA,CAAK,SAAA,CAAU,CAAC,aAAA,EAAe,QAAQ,CAAC,CAAA;AACjD;AAGA,SAAS,gBAAA,CAAiB,MAAuB,KAAA,EAAgC;AAC/E,EAAA,MAAM,QAAA,GAAW,OAAO,IAAI,CAAA;AAC5B,EAAA,MAAM,SAAA,GAAY,OAAO,KAAK,CAAA;AAC9B,EAAA,IAAI,aAAa,SAAA,EAAW;AAC1B,IAAA,OAAO,CAAA;AAAA,EACT;AACA,EAAA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AAA,EAAG,IAAI,CAAA,EAAG,4BAA4B,GAAG,KAAK,CAAA,CAAA;AAAA,IAC5D;AACA,IAAA,OAAO,SAAA;AAAA,EACT;AAAA,EAEA,mBAAA,GAA4B;AAC1B,IAAA,IAAA,CAAK,OAAA,CAAQA,yBAAa,YAAY,CAAA;AAAA,EACxC;AAAA,EAEA,qBAAA,GAA8B;AAC5B,IAAA,IAAA,CAAK,OAAA,CAAQA,yBAAa,cAAc,CAAA;AAAA,EAC1C;AAAA,EAEA,aAAa,KAAA,EAAwC;AACnD,IAAA,IAAA,CAAK,IAAA,CAAK,aAAa,KAAK,CAAA;AAAA,EAC9B;AAAA,EAEA,aAAa,WAAA,EAA6B;AACxC,IAAA,OAAO,IAAA,CAAK,KAAA,CAAM,UAAA,CAAW,MAAA,CAAO,WAAW,CAAA;AAAA,EACjD;AAAA,EAEQ,QAAQ,MAAA,EAA0B;AACxC,IAAA,IAAI,CAAC,IAAA,CAAK,IAAA,CAAK,YAAA,CAAa,MAAA,CAAO,IAAI,CAAA,EAAG;AACxC,MAAA,IAAA,CAAK,IAAA,CAAK,GAAA,CAAI,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,MAAA,CAAO,IAAA,EAAM,IAAA,EAAM,MAAA,CAAO,IAAA,EAAM,CAAA;AAAA,IAChF;AAAA,EACF;AACF;AAEA,SAAS,gBAAgB,IAAA,EAAsB;AAC7C,EAAA,OAAOC,yBAAYD,wBAAA,CAAa,aAAA,CAAc,IAAA,EAAM,CAAC,IAAI,CAAC,CAAA;AAC5D;;"}
|
|
@@ -6,7 +6,10 @@ import { OperationKeys } from './operation-keys.mjs';
|
|
|
6
6
|
import { FIRST_SCHEMA_NAMES } from './shared-enum-names.mjs';
|
|
7
7
|
|
|
8
8
|
function dedupeKey(request) {
|
|
9
|
-
|
|
9
|
+
const sorted = [...request.values].sort(compareAsStrings);
|
|
10
|
+
const originalPairs = sorted.map((value, index) => memberKey(value, request.metadata[index]));
|
|
11
|
+
const ownPairs = request.values.map((value, index) => ({ value, member: memberKey(value, request.metadata[index]) })).sort((left, right) => compareAsStrings(left.value, right.value)).map(({ member }) => member);
|
|
12
|
+
return JSON.stringify([originalPairs, ownPairs]);
|
|
10
13
|
}
|
|
11
14
|
function compareAsStrings(left, right) {
|
|
12
15
|
const leftText = String(left);
|
|
@@ -16,8 +19,8 @@ function compareAsStrings(left, right) {
|
|
|
16
19
|
}
|
|
17
20
|
return leftText < rightText ? -1 : 1;
|
|
18
21
|
}
|
|
19
|
-
function
|
|
20
|
-
return
|
|
22
|
+
function memberKey(value, metadata) {
|
|
23
|
+
return [value, metadata?.name ?? null, metadata?.description || null];
|
|
21
24
|
}
|
|
22
25
|
const ENUM_VALUES_NUMBER_SEPARATOR = "_";
|
|
23
26
|
function declarationKey(name, request) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-footer.mjs","sources":["../../../../src/application/transform/footer/document-footer.ts"],"sourcesContent":["import { irReference } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrEnumDeclaration,\n IrPropertySignature,\n IrType,\n} from \"../../../domain/ir/nodes.js\";\nimport { HELPER_TYPES, type HelperType } from \"../helper-types.js\";\nimport type {\n EnumDeclarationRequest,\n EnumMemberMetadata,\n EnumValuesRequest,\n} from \"../schema/schema-context.js\";\nimport type { DocumentFooter } from \"../transform-context.js\";\nimport { EnumNameClaims } from \"./enum-name-claims.js\";\nimport {\n type DeclaredMembers,\n EnumNaming,\n enumDeclaration,\n withoutDeclaredMembers,\n} from \"./enum-naming.js\";\nimport { OperationKeys } from \"./operation-keys.js\";\nimport { FIRST_SCHEMA_NAMES, type SharedEnumNames } from \"./shared-enum-names.js\";\n\n/** Where footer declarations go, in order: the run's `ctx.injectFooter`, open to user code. */\nexport interface FooterSink {\n /** Whether a type alias with this name is declared already (by the generator or a user). */\n hasTypeAlias(name: string): boolean;\n add(declaration: IrDeclaration): void;\n /** Add a member to the `operations` interface, declared first if needed; see `DocumentFooter`. */\n addOperation(build: () => IrPropertySignature): void;\n}\n\n/**\n * The `--dedupe-enums` key of the original: the values in default sort order, each paired with\n * the metadata at its sorted position (not the value's own metadata), as the original does.\n */\nfunction dedupeKey(request: EnumDeclarationRequest): string {\n return [...request.values]\n .sort(compareAsStrings)\n .map((value, index) => metadataKey(String(value), request.metadata[index]))\n .join(\",\");\n}\n\n/** `Array.prototype.sort` without a comparator: compares the values as strings. */\nfunction compareAsStrings(left: string | number, right: string | number): number {\n const leftText = String(left);\n const rightText = String(right);\n if (leftText === rightText) {\n return 0;\n }\n return leftText < rightText ? -1 : 1;\n}\n\nfunction metadataKey(value: string, metadata: EnumMemberMetadata | undefined): string {\n return `${metadata?.name ?? value}:${metadata?.description || \"\"}`;\n}\n\n/** Separates a repeated `--enum-values` array name from its number, as root type aliases do. */\nconst ENUM_VALUES_NUMBER_SEPARATOR = \"_\";\n\n/** The whole declaration: an equal key means the same enum, member for member. */\nfunction declarationKey(name: string, request: EnumDeclarationRequest): string {\n return JSON.stringify([name, request.values, request.metadata]);\n}\n\n/** The naming state a run's footer shares with the rest of the run. */\nexport interface RunFooterNames {\n readonly enums: EnumNameClaims;\n readonly operations: OperationKeys;\n}\n\n/**\n * The footer of one run: enums (deduplicated with `--dedupe-enums`), `--enum-values` arrays, the\n * helper types they need, and the `operations` interface. Replaces the original's module-level\n * `enumCache`, so runs no longer share enums (research/legacy-bugs.md, item 3).\n */\nexport class RunFooter implements DocumentFooter {\n private readonly naming = new EnumNaming();\n private readonly enumNamesByKey = new Map<string, string>();\n /** Declarations added already: the same one twice fails with \"Duplicate identifier\". */\n private readonly declaredEnums = new Set<string>();\n /** The member names of each declared enum, by value. */\n private readonly membersByEnum = new Map<string, Map<string | number, string>>();\n /** The members of each declared enum name, by member name. */\n private readonly declaredMembers = new Map<string, Map<string, string | number>>();\n /** `--enum-values` arrays added already: their declared name by name, type and values. */\n private readonly declaredEnumValues = new Map<string, string>();\n /** The declared `--enum-values` array names. */\n private readonly enumValuesNames = new Set<string>();\n private readonly sink: FooterSink;\n private readonly isDedupingEnums: boolean;\n private readonly sharedNames: SharedEnumNames;\n private readonly names: RunFooterNames;\n\n constructor(\n sink: FooterSink,\n isDedupingEnums: boolean,\n sharedNames: SharedEnumNames = FIRST_SCHEMA_NAMES,\n names: RunFooterNames = { enums: new EnumNameClaims(), operations: new OperationKeys() },\n ) {\n this.sink = sink;\n this.isDedupingEnums = isDedupingEnums;\n this.sharedNames = sharedNames;\n this.names = names;\n }\n\n addEnum(request: EnumDeclarationRequest): string {\n // The name is built before the cache lookup: it advances the naming state either way.\n const ownName = this.naming.enumName(request.name);\n const key = this.isDedupingEnums ? dedupeKey(request) : null;\n // Every schema of a shared enum goes to `sharedNames`, the later ones too.\n const sharedName = key === null ? ownName : this.sharedNames.nameOf(key, ownName, request);\n const known = key === null ? undefined : this.enumNamesByKey.get(key);\n if (known !== undefined) {\n return known;\n }\n // The owner is the schema location: its requests share one enum, with `--dedupe-enums` too.\n const name = this.names.enums.nameFor(sharedName, request.name);\n // Only a repeated member fails to compile; two empty declarations merge, so they stay.\n const declared = request.values.length > 0 ? declarationKey(name, request) : null;\n if (declared !== null && this.declaredEnums.has(declared)) {\n return name;\n }\n if (declared !== null) {\n this.declaredEnums.add(declared);\n }\n const declaration = this.withoutRepeats(enumDeclaration(name, request, this.naming));\n if (declaration !== null) {\n this.record(declaration);\n this.sink.add(declaration);\n }\n if (key !== null) {\n this.enumNamesByKey.set(key, name);\n }\n return name;\n }\n\n /** The declaration without members an earlier one of the name has; null when none is left. */\n private withoutRepeats(declaration: IrEnumDeclaration): IrEnumDeclaration | null {\n const earlier: DeclaredMembers | undefined = this.declaredMembers.get(declaration.name);\n if (earlier === undefined) {\n return declaration;\n }\n const merged = withoutDeclaredMembers(declaration, earlier);\n // Two empty declarations merge into one empty enum, which compiles, so the second stays.\n return merged.members.length === 0 && declaration.members.length > 0 ? null : merged;\n }\n\n /** The members of a declaration; the first member of a value names it. */\n private record(declaration: IrEnumDeclaration): void {\n const byName = this.declaredMembers.get(declaration.name) ?? new Map();\n const byValue = this.membersByEnum.get(declaration.name) ?? new Map();\n for (const member of declaration.members) {\n byName.set(member.name, member.value);\n if (!byValue.has(member.value)) {\n byValue.set(member.value, member.name);\n }\n }\n this.declaredMembers.set(declaration.name, byName);\n this.membersByEnum.set(declaration.name, byValue);\n }\n\n enumMembers(name: string): ReadonlyMap<string | number, string> {\n return this.membersByEnum.get(name) ?? new Map();\n }\n\n addEnumValues(request: EnumValuesRequest): void {\n const baseName = this.naming.arrayName(request.name);\n // The same array twice fails with \"Cannot redeclare\"; a schema typed twice adds it twice.\n const declared = JSON.stringify([baseName, request.type, request.values]);\n if (this.declaredEnumValues.has(declared)) {\n return;\n }\n const name = this.freeEnumValuesName(baseName);\n this.declaredEnumValues.set(declared, name);\n this.enumValuesNames.add(name);\n this.require(HELPER_TYPES.flattenedDeepRequired);\n this.require(HELPER_TYPES.readonlyArray);\n this.sink.add({\n kind: \"constArray\",\n name,\n isExported: true,\n type: readonlyArrayOf(request.type),\n values: request.values,\n comments: [],\n });\n }\n\n /**\n * Another array may have the name: `Discount/type` and `discount/type`, or a property and an\n * inline `allOf` item of one schema, typed at one location. A redeclared `const` does not\n * compile, so a later one gets the next number (`discountTypeValues_2`). Every unnumbered name\n * ends with `Values`, so a number never takes a name that a later array needs.\n */\n private freeEnumValuesName(name: string): string {\n let candidate = name;\n for (let count = 2; this.enumValuesNames.has(candidate); count++) {\n candidate = `${name}${ENUM_VALUES_NUMBER_SEPARATOR}${count}`;\n }\n return candidate;\n }\n\n requireWithRequired(): void {\n this.require(HELPER_TYPES.withRequired);\n }\n\n requirePropertyValues(): void {\n this.require(HELPER_TYPES.propertyValues);\n }\n\n addOperation(build: () => IrPropertySignature): void {\n this.sink.addOperation(build);\n }\n\n operationKey(operationId: string): string {\n return this.names.operations.keyFor(operationId);\n }\n\n private require(helper: HelperType): void {\n if (!this.sink.hasTypeAlias(helper.name)) {\n this.sink.add({ kind: \"rawDeclaration\", name: helper.name, text: helper.text });\n }\n }\n}\n\nfunction readonlyArrayOf(type: IrType): IrType {\n return irReference(HELPER_TYPES.readonlyArray.name, [type]);\n}\n"],"names":[],"mappings":";;;;;;;AAqCA,SAAS,UAAU,OAAA,EAAyC;AAC1D,EAAA,OAAO,CAAC,GAAG,OAAA,CAAQ,MAAM,EACtB,IAAA,CAAK,gBAAgB,CAAA,CACrB,GAAA,CAAI,CAAC,KAAA,EAAO,UAAU,WAAA,CAAY,MAAA,CAAO,KAAK,CAAA,EAAG,OAAA,CAAQ,QAAA,CAAS,KAAK,CAAC,CAAC,CAAA,CACzE,IAAA,CAAK,GAAG,CAAA;AACb;AAGA,SAAS,gBAAA,CAAiB,MAAuB,KAAA,EAAgC;AAC/E,EAAA,MAAM,QAAA,GAAW,OAAO,IAAI,CAAA;AAC5B,EAAA,MAAM,SAAA,GAAY,OAAO,KAAK,CAAA;AAC9B,EAAA,IAAI,aAAa,SAAA,EAAW;AAC1B,IAAA,OAAO,CAAA;AAAA,EACT;AACA,EAAA,OAAO,QAAA,GAAW,YAAY,EAAA,GAAK,CAAA;AACrC;AAEA,SAAS,WAAA,CAAY,OAAe,QAAA,EAAkD;AACpF,EAAA,OAAO,GAAG,QAAA,EAAU,IAAA,IAAQ,KAAK,CAAA,CAAA,EAAI,QAAA,EAAU,eAAe,EAAE,CAAA,CAAA;AAClE;AAGA,MAAM,4BAAA,GAA+B,GAAA;AAGrC,SAAS,cAAA,CAAe,MAAc,OAAA,EAAyC;AAC7E,EAAA,OAAO,IAAA,CAAK,UAAU,CAAC,IAAA,EAAM,QAAQ,MAAA,EAAQ,OAAA,CAAQ,QAAQ,CAAC,CAAA;AAChE;AAaO,MAAM,SAAA,CAAoC;AAAA,EAC9B,MAAA,GAAS,IAAI,UAAA,EAAW;AAAA,EACxB,cAAA,uBAAqB,GAAA,EAAoB;AAAA;AAAA,EAEzC,aAAA,uBAAoB,GAAA,EAAY;AAAA;AAAA,EAEhC,aAAA,uBAAoB,G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IAAA,CAAK,YAAA,CAAa,MAAA,CAAO,IAAI,CAAA,EAAG;AACxC,MAAA,IAAA,CAAK,IAAA,CAAK,GAAA,CAAI,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,MAAA,CAAO,IAAA,EAAM,IAAA,EAAM,MAAA,CAAO,IAAA,EAAM,CAAA;AAAA,IAChF;AAAA,EACF;AACF;AAEA,SAAS,gBAAgB,IAAA,EAAsB;AAC7C,EAAA,OAAO,YAAY,YAAA,CAAa,aAAA,CAAc,IAAA,EAAM,CAAC,IAAI,CAAC,CAAA;AAC5D;;"}
|
|
1
|
+
{"version":3,"file":"document-footer.mjs","sources":["../../../../src/application/transform/footer/document-footer.ts"],"sourcesContent":["import { irReference } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrEnumDeclaration,\n IrPropertySignature,\n IrType,\n} from \"../../../domain/ir/nodes.js\";\nimport { HELPER_TYPES, type HelperType } from \"../helper-types.js\";\nimport type {\n EnumDeclarationRequest,\n EnumMemberMetadata,\n EnumValuesRequest,\n} from \"../schema/schema-context.js\";\nimport type { DocumentFooter } from \"../transform-context.js\";\nimport { EnumNameClaims } from \"./enum-name-claims.js\";\nimport {\n type DeclaredMembers,\n EnumNaming,\n enumDeclaration,\n withoutDeclaredMembers,\n} from \"./enum-naming.js\";\nimport { OperationKeys } from \"./operation-keys.js\";\nimport { FIRST_SCHEMA_NAMES, type SharedEnumNames } from \"./shared-enum-names.js\";\n\n/** Where footer declarations go, in order: the run's `ctx.injectFooter`, open to user code. */\nexport interface FooterSink {\n /** Whether a type alias with this name is declared already (by the generator or a user). */\n hasTypeAlias(name: string): boolean;\n add(declaration: IrDeclaration): void;\n /** Add a member to the `operations` interface, declared first if needed; see `DocumentFooter`. */\n addOperation(build: () => IrPropertySignature): void;\n}\n\n/**\n * The `--dedupe-enums` key. Two enums share a declaration only when the original shares it and\n * each value has the same name and description in both. The original key pairs the values in\n * default sort order with the metadata at the sorted position, not with the value's own metadata,\n * so `[desc, asc]` and `[asc, desc]`, both named `[Desc, Asc]`, shared one declaration, and one of\n * them typed `asc` as `Desc = \"desc\"`. The original also joined `name:description` texts with\n * `,`, and a member name stood in for its value, so enums with other values (`\"1\"` and `1`, `A`\n * and `1` both named `Active`, `[\"a\", \"b\"]` and `[\"a:,b\"]`) shared one key. As JSON, an equal key\n * means the same values and metadata; enums the original kept apart still are.\n */\nfunction dedupeKey(request: EnumDeclarationRequest): string {\n const sorted = [...request.values].sort(compareAsStrings);\n const originalPairs = sorted.map((value, index) => memberKey(value, request.metadata[index]));\n const ownPairs = request.values\n .map((value, index) => ({ value, member: memberKey(value, request.metadata[index]) }))\n .sort((left, right) => compareAsStrings(left.value, right.value))\n .map(({ member }) => member);\n return JSON.stringify([originalPairs, ownPairs]);\n}\n\n/** `Array.prototype.sort` without a comparator: compares the values as strings. */\nfunction compareAsStrings(left: string | number, right: string | number): number {\n const leftText = String(left);\n const rightText = String(right);\n if (leftText === rightText) {\n return 0;\n }\n return leftText < rightText ? -1 : 1;\n}\n\n/** One member: the value (JSON keeps `\"1\"` and `1` apart), its name and its description. */\nfunction memberKey(value: string | number, metadata: EnumMemberMetadata | undefined) {\n return [value, metadata?.name ?? null, metadata?.description || null];\n}\n\n/** Separates a repeated `--enum-values` array name from its number, as root type aliases do. */\nconst ENUM_VALUES_NUMBER_SEPARATOR = \"_\";\n\n/** The whole declaration: an equal key means the same enum, member for member. */\nfunction declarationKey(name: string, request: EnumDeclarationRequest): string {\n return JSON.stringify([name, request.values, request.metadata]);\n}\n\n/** The naming state a run's footer shares with the rest of the run. */\nexport interface RunFooterNames {\n readonly enums: EnumNameClaims;\n readonly operations: OperationKeys;\n}\n\n/**\n * The footer of one run: enums (deduplicated with `--dedupe-enums`), `--enum-values` arrays, the\n * helper types they need, and the `operations` interface. Replaces the original's module-level\n * `enumCache`, so runs no longer share enums (research/legacy-bugs.md, item 3).\n */\nexport class RunFooter implements DocumentFooter {\n private readonly naming = new EnumNaming();\n private readonly enumNamesByKey = new Map<string, string>();\n /** Declarations added already: the same one twice fails with \"Duplicate identifier\". */\n private readonly declaredEnums = new Set<string>();\n /** The member names of each declared enum, by value. */\n private readonly membersByEnum = new Map<string, Map<string | number, string>>();\n /** The members of each declared enum name, by member name. */\n private readonly declaredMembers = new Map<string, Map<string, string | number>>();\n /** `--enum-values` arrays added already: their declared name by name, type and values. */\n private readonly declaredEnumValues = new Map<string, string>();\n /** The declared `--enum-values` array names. */\n private readonly enumValuesNames = new Set<string>();\n private readonly sink: FooterSink;\n private readonly isDedupingEnums: boolean;\n private readonly sharedNames: SharedEnumNames;\n private readonly names: RunFooterNames;\n\n constructor(\n sink: FooterSink,\n isDedupingEnums: boolean,\n sharedNames: SharedEnumNames = FIRST_SCHEMA_NAMES,\n names: RunFooterNames = { enums: new EnumNameClaims(), operations: new OperationKeys() },\n ) {\n this.sink = sink;\n this.isDedupingEnums = isDedupingEnums;\n this.sharedNames = sharedNames;\n this.names = names;\n }\n\n addEnum(request: EnumDeclarationRequest): string {\n // The name is built before the cache lookup: it advances the naming state either way.\n const ownName = this.naming.enumName(request.name);\n const key = this.isDedupingEnums ? dedupeKey(request) : null;\n // Every schema of a shared enum goes to `sharedNames`, the later ones too.\n const sharedName = key === null ? ownName : this.sharedNames.nameOf(key, ownName, request);\n const known = key === null ? undefined : this.enumNamesByKey.get(key);\n if (known !== undefined) {\n return known;\n }\n // The owner is the schema location: its requests share one enum, with `--dedupe-enums` too.\n const name = this.names.enums.nameFor(sharedName, request.name);\n // Only a repeated member fails to compile; two empty declarations merge, so they stay.\n const declared = request.values.length > 0 ? declarationKey(name, request) : null;\n if (declared !== null && this.declaredEnums.has(declared)) {\n return name;\n }\n if (declared !== null) {\n this.declaredEnums.add(declared);\n }\n const declaration = this.withoutRepeats(enumDeclaration(name, request, this.naming));\n if (declaration !== null) {\n this.record(declaration);\n this.sink.add(declaration);\n }\n if (key !== null) {\n this.enumNamesByKey.set(key, name);\n }\n return name;\n }\n\n /** The declaration without members an earlier one of the name has; null when none is left. */\n private withoutRepeats(declaration: IrEnumDeclaration): IrEnumDeclaration | null {\n const earlier: DeclaredMembers | undefined = this.declaredMembers.get(declaration.name);\n if (earlier === undefined) {\n return declaration;\n }\n const merged = withoutDeclaredMembers(declaration, earlier);\n // Two empty declarations merge into one empty enum, which compiles, so the second stays.\n return merged.members.length === 0 && declaration.members.length > 0 ? null : merged;\n }\n\n /** The members of a declaration; the first member of a value names it. */\n private record(declaration: IrEnumDeclaration): void {\n const byName = this.declaredMembers.get(declaration.name) ?? new Map();\n const byValue = this.membersByEnum.get(declaration.name) ?? new Map();\n for (const member of declaration.members) {\n byName.set(member.name, member.value);\n if (!byValue.has(member.value)) {\n byValue.set(member.value, member.name);\n }\n }\n this.declaredMembers.set(declaration.name, byName);\n this.membersByEnum.set(declaration.name, byValue);\n }\n\n enumMembers(name: string): ReadonlyMap<string | number, string> {\n return this.membersByEnum.get(name) ?? new Map();\n }\n\n addEnumValues(request: EnumValuesRequest): void {\n const baseName = this.naming.arrayName(request.name);\n // The same array twice fails with \"Cannot redeclare\"; a schema typed twice adds it twice.\n const declared = JSON.stringify([baseName, request.type, request.values]);\n if (this.declaredEnumValues.has(declared)) {\n return;\n }\n const name = this.freeEnumValuesName(baseName);\n this.declaredEnumValues.set(declared, name);\n this.enumValuesNames.add(name);\n this.require(HELPER_TYPES.flattenedDeepRequired);\n this.require(HELPER_TYPES.readonlyArray);\n this.sink.add({\n kind: \"constArray\",\n name,\n isExported: true,\n type: readonlyArrayOf(request.type),\n values: request.values,\n comments: [],\n });\n }\n\n /**\n * Another array may have the name: `Discount/type` and `discount/type`, or a property and an\n * inline `allOf` item of one schema, typed at one location. A redeclared `const` does not\n * compile, so a later one gets the next number (`discountTypeValues_2`). Every unnumbered name\n * ends with `Values`, so a number never takes a name that a later array needs.\n */\n private freeEnumValuesName(name: string): string {\n let candidate = name;\n for (let count = 2; this.enumValuesNames.has(candidate); count++) {\n candidate = `${name}${ENUM_VALUES_NUMBER_SEPARATOR}${count}`;\n }\n return candidate;\n }\n\n requireWithRequired(): void {\n this.require(HELPER_TYPES.withRequired);\n }\n\n requirePropertyValues(): void {\n this.require(HELPER_TYPES.propertyValues);\n }\n\n addOperation(build: () => IrPropertySignature): void {\n this.sink.addOperation(build);\n }\n\n operationKey(operationId: string): string {\n return this.names.operations.keyFor(operationId);\n }\n\n private require(helper: HelperType): void {\n if (!this.sink.hasTypeAlias(helper.name)) {\n this.sink.add({ kind: \"rawDeclaration\", name: helper.name, text: helper.text });\n }\n }\n}\n\nfunction readonlyArrayOf(type: IrType): IrType {\n return irReference(HELPER_TYPES.readonlyArray.name, [type]);\n}\n"],"names":[],"mappings":";;;;;;;AA2CA,SAAS,UAAU,OAAA,EAAyC;AAC1D,EAAA,MAAM,SAAS,CAAC,GAAG,QAAQ,MAAM,CAAA,CAAE,KAAK,gBAAgB,CAAA;AACxD,EAAA,MAAM,aAAA,GAAgB,MAAA,CAAO,GAAA,CAAI,CAAC,KAAA,EAAO,KAAA,KAAU,SAAA,CAAU,KAAA,EAAO,OAAA,CAAQ,QAAA,CAAS,KAAK,CAAC,CAAC,CAAA;AAC5F,EAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,MAAA,CACtB,GAAA,CAAI,CAAC,KAAA,EAAO,KAAA,MAAW,EAAE,KAAA,EAAO,QAAQ,SAAA,CAAU,KAAA,EAAO,OAAA,CAAQ,QAAA,CAAS,KAAK,CAAC,CAAA,EAAE,CAAE,CAAA,CACpF,KAAK,CAAC,IAAA,EAAM,KAAA,KAAU,gBAAA,CAAiB,KAAK,KAAA,EAAO,KAAA,CAAM,KAAK,CAAC,EAC/D,GAAA,CAAI,CAAC,EAAE,MAAA,OAAa,MAAM,CAAA;AAC7B,EAAA,OAAO,IAAA,CAAK,SAAA,CAAU,CAAC,aAAA,EAAe,QAAQ,CAAC,CAAA;AACjD;AAGA,SAAS,gBAAA,CAAiB,MAAuB,KAAA,EAAgC;AAC/E,EAAA,MAAM,QAAA,GAAW,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48
48
|
"type ReadWriteLeaf = ReadWritePrimitive | ((...args: never) => unknown);",
|
|
49
|
-
"type ReadWriteMarkedKeys<T, Marker> = {",
|
|
50
|
-
" [K in keyof T
|
|
51
|
-
"}
|
|
49
|
+
"type ReadWriteMarkedKeys<T, Marker> = keyof {",
|
|
50
|
+
" [K in keyof T as 0 extends 1 & T[K] ? never : NonNullable<T[K]> extends never ? never : NonNullable<T[K]> extends Marker ? K : never]: never;",
|
|
51
|
+
"};",
|
|
52
52
|
'type ReadWriteResolveArray<T extends readonly unknown[], Resolved extends "read" | "write"> = T[number][] extends T ? T extends unknown[] ? ReadWriteResolve<T[number], Resolved>[] : readonly ReadWriteResolve<T[number], Resolved>[] : {',
|
|
53
53
|
" [K in keyof T]: ReadWriteResolve<T[K], Resolved>;",
|
|
54
54
|
"};",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper-types.cjs","sources":["../../../src/application/transform/helper-types.ts"],"sourcesContent":["/**\n * The helper type aliases the generator adds to the footer, declared once each. The text is the\n * original's source text as the TypeScript printer printed it, so printing it as written gives\n * the original output (ENGINEERING_PLAN 6.2 and 6.6), except for the fixes noted below.\n */\nexport interface HelperType {\n readonly name: string;\n readonly text: string;\n}\n\nfunction lines(...parts: readonly string[]): string {\n return parts.join(\"\\n\");\n}\n\nexport const HELPER_TYPES = {\n withRequired: {\n name: \"WithRequired\",\n text: lines(\"type WithRequired<T, K extends keyof T> = T & {\", \" [P in K]-?: T[P];\", \"};\"),\n },\n // `unevaluated-properties` (roadmap R11): the value types of every member of a union, so a\n // `$ref` to a `oneOf` schema gives the values of each variant, not only of the shared keys.\n propertyValues: {\n name: \"PropertyValues\",\n text: \"type PropertyValues<T> = T extends unknown ? T[keyof T] : never;\",\n },\n // Task 7.4 changes the original text on purpose: `readonly unknown[]` also flattens the arrays\n // of `--immutable` (upstream #2714, #2749), and `NonNullable` looks through nullable parents\n // (upstream #2737). The old text did not compile for those schemas.\n flattenedDeepRequired: {\n name: \"FlattenedDeepRequired\",\n text: lines(\n \"type FlattenedDeepRequired<T> = {\",\n \" [K in keyof T]-?: FlattenedDeepRequired<T[K] extends readonly unknown[] | undefined | \" +\n \"null ? Extract<T[K], readonly unknown[]>[number] : NonNullable<T[K]>>;\",\n \"};\",\n ),\n },\n // `readonly unknown[]`: a readonly array value type stays as is (upstream #2749).\n readonlyArray: {\n name: \"ReadonlyArray\",\n text: lines(\n \"type ReadonlyArray<T> = [\",\n \" Exclude<T, undefined>\",\n \"] extends [\",\n \" readonly unknown[]\",\n \"] ? Readonly<Exclude<T, undefined>> : Readonly<Exclude<T, undefined>[]>;\",\n ),\n },\n} as const satisfies Readonly<Record<string, HelperType>>;\n\n/**\n * The `--read-write-markers` helper types, written before the root types. Task 7.6 replaces the\n * original text on purpose (ADR-014): primitives (also branded), readonly arrays, tuples,\n * intersected arrays, null-only and `any` properties keep their types (upstream #2615, #2620,\n * #2632, #2717, #2765). The declarations equal the `Readable` / `Writable` that\n * openapi-typesafe-fetch declares (`test/api/read-write-marker-types.test.ts`); the text is what\n * the TypeScript printer prints.\n */\nexport const READ_WRITE_MARKER_TYPES = lines(\n \"export type $Read<T> = {\",\n \" readonly $read: T;\",\n \"};\",\n \"export type $Write<T> = {\",\n \" readonly $write: T;\",\n \"};\",\n \"type ReadWritePrimitive = string | number | boolean | bigint | symbol | null | undefined;\",\n \"type ReadWriteLeaf = ReadWritePrimitive | ((...args: never) => unknown);\",\n \"type ReadWriteMarkedKeys<T, Marker> = {\",\n \" [K in keyof T
|
|
1
|
+
{"version":3,"file":"helper-types.cjs","sources":["../../../src/application/transform/helper-types.ts"],"sourcesContent":["/**\n * The helper type aliases the generator adds to the footer, declared once each. The text is the\n * original's source text as the TypeScript printer printed it, so printing it as written gives\n * the original output (ENGINEERING_PLAN 6.2 and 6.6), except for the fixes noted below.\n */\nexport interface HelperType {\n readonly name: string;\n readonly text: string;\n}\n\nfunction lines(...parts: readonly string[]): string {\n return parts.join(\"\\n\");\n}\n\nexport const HELPER_TYPES = {\n withRequired: {\n name: \"WithRequired\",\n text: lines(\"type WithRequired<T, K extends keyof T> = T & {\", \" [P in K]-?: T[P];\", \"};\"),\n },\n // `unevaluated-properties` (roadmap R11): the value types of every member of a union, so a\n // `$ref` to a `oneOf` schema gives the values of each variant, not only of the shared keys.\n propertyValues: {\n name: \"PropertyValues\",\n text: \"type PropertyValues<T> = T extends unknown ? T[keyof T] : never;\",\n },\n // Task 7.4 changes the original text on purpose: `readonly unknown[]` also flattens the arrays\n // of `--immutable` (upstream #2714, #2749), and `NonNullable` looks through nullable parents\n // (upstream #2737). The old text did not compile for those schemas.\n flattenedDeepRequired: {\n name: \"FlattenedDeepRequired\",\n text: lines(\n \"type FlattenedDeepRequired<T> = {\",\n \" [K in keyof T]-?: FlattenedDeepRequired<T[K] extends readonly unknown[] | undefined | \" +\n \"null ? Extract<T[K], readonly unknown[]>[number] : NonNullable<T[K]>>;\",\n \"};\",\n ),\n },\n // `readonly unknown[]`: a readonly array value type stays as is (upstream #2749).\n readonlyArray: {\n name: \"ReadonlyArray\",\n text: lines(\n \"type ReadonlyArray<T> = [\",\n \" Exclude<T, undefined>\",\n \"] extends [\",\n \" readonly unknown[]\",\n \"] ? Readonly<Exclude<T, undefined>> : Readonly<Exclude<T, undefined>[]>;\",\n ),\n },\n} as const satisfies Readonly<Record<string, HelperType>>;\n\n/**\n * The `--read-write-markers` helper types, written before the root types. Task 7.6 replaces the\n * original text on purpose (ADR-014): primitives (also branded), readonly arrays, tuples,\n * intersected arrays, null-only and `any` properties keep their types (upstream #2615, #2620,\n * #2632, #2717, #2765). The declarations equal the `Readable` / `Writable` that\n * openapi-typesafe-fetch declares (`test/api/read-write-marker-types.test.ts`); the text is what\n * the TypeScript printer prints.\n */\nexport const READ_WRITE_MARKER_TYPES = lines(\n \"export type $Read<T> = {\",\n \" readonly $read: T;\",\n \"};\",\n \"export type $Write<T> = {\",\n \" readonly $write: T;\",\n \"};\",\n \"type ReadWritePrimitive = string | number | boolean | bigint | symbol | null | undefined;\",\n \"type ReadWriteLeaf = ReadWritePrimitive | ((...args: never) => unknown);\",\n \"type ReadWriteMarkedKeys<T, Marker> = keyof {\",\n \" [K in keyof T as 0 extends 1 & T[K] ? never : NonNullable<T[K]> extends never ? never : \" +\n \"NonNullable<T[K]> extends Marker ? K : never]: never;\",\n \"};\",\n 'type ReadWriteResolveArray<T extends readonly unknown[], Resolved extends \"read\" | ' +\n '\"write\"> = T[number][] extends T ? T extends unknown[] ? ReadWriteResolve<T[number], ' +\n \"Resolved>[] : readonly ReadWriteResolve<T[number], Resolved>[] : {\",\n \" [K in keyof T]: ReadWriteResolve<T[K], Resolved>;\",\n \"};\",\n 'type ReadWriteResolve<T, Resolved extends \"read\" | \"write\"> = Resolved extends \"read\" ? ' +\n \"Readable<T> : Writable<T>;\",\n \"export type Readable<T> = T extends $Write<any> ? never : T extends $Read<infer U> ? \" +\n \"Readable<U> : T extends ReadWriteLeaf ? T : T extends readonly unknown[] ? \" +\n 'ReadWriteResolveArray<T, \"read\"> : T extends object ? {',\n \" [K in keyof T as K extends ReadWriteMarkedKeys<T, $Write<any>> ? never : K]: \" +\n \"Readable<T[K]>;\",\n \"} : T;\",\n \"export type Writable<T> = T extends $Read<any> ? never : T extends $Write<infer U> ? \" +\n \"Writable<U> : T extends ReadWriteLeaf ? T : T extends readonly unknown[] ? \" +\n 'ReadWriteResolveArray<T, \"write\"> : T extends object ? {',\n \" [K in keyof T as K extends ReadWriteMarkedKeys<T, $Read<any>> ? never : K]: \" +\n \"Writable<T[K]>;\",\n \"} & {\",\n \" [K in ReadWriteMarkedKeys<T, $Read<any>>]?: never;\",\n \"} : T;\",\n);\n"],"names":[],"mappings":";;AAUA,SAAS,SAAS,KAAA,EAAkC;AAClD,EAAA,OAAO,KAAA,CAAM,KAAK,IAAI,CAAA;AACxB;AAEO,MAAM,YAAA,GAAe;AAAA,EAC1B,YAAA,EAAc;AAAA,IACZ,IAAA,EAAM,cAAA;AAAA,IACN,IAAA,EAAM,KAAA,CAAM,iDAAA,EAAmD,uBAAA,EAAyB,IAAI;AAAA,GAC9F;AAAA;AAAA;AAAA,EAGA,cAAA,EAAgB;AAAA,IACd,IAAA,EAAM,gBAAA;AAAA,IACN,IAAA,EAAM;AAAA,GACR;AAAA;AAAA;AAAA;AAAA,EAIA,qBAAA,EAAuB;AAAA,IACrB,IAAA,EAAM,uBAAA;AAAA,IACN,IAAA,EAAM,KAAA;AAAA,MACJ,mCAAA;AAAA,MACA,kKAAA;AAAA,MAEA;AAAA;AACF,GACF;AAAA;AAAA,EAEA,aAAA,EAAe;AAAA,IACb,IAAA,EAAM,eAAA;AAAA,IACN,IAAA,EAAM,KAAA;AAAA,MACJ,2BAAA;AAAA,MACA,2BAAA;AAAA,MACA,aAAA;AAAA,MACA,wBAAA;AAAA,MACA;AAAA;AACF;AAEJ;AAUO,MAAM,uBAAA,GAA0B,KAAA;AAAA,EACrC,0BAAA;AAAA,EACA,wBAAA;AAAA,EACA,IAAA;AAAA,EACA,2BAAA;AAAA,EACA,yBAAA;AAAA,EACA,IAAA;AAAA,EACA,2FAAA;AAAA,EACA,0EAAA;AAAA,EACA,+CAAA;AAAA,EACA,mJAAA;AAAA,EAEA,IAAA;AAAA,EACA,4OAAA;AAAA,EAGA,uDAAA;AAAA,EACA,IAAA;AAAA,EACA,oHAAA;AAAA,EAEA,yNAAA;AAAA,EAGA,kGAAA;AAAA,EAEA,QAAA;AAAA,EACA,0NAAA;AAAA,EAGA,iGAAA;AAAA,EAEA,OAAA;AAAA,EACA,wDAAA;AAAA,EACA;AACF;;;"}
|
|
@@ -44,9 +44,9 @@ const READ_WRITE_MARKER_TYPES = lines(
|
|
|
44
44
|
"};",
|
|
45
45
|
"type ReadWritePrimitive = string | number | boolean | bigint | symbol | null | undefined;",
|
|
46
46
|
"type ReadWriteLeaf = ReadWritePrimitive | ((...args: never) => unknown);",
|
|
47
|
-
"type ReadWriteMarkedKeys<T, Marker> = {",
|
|
48
|
-
" [K in keyof T
|
|
49
|
-
"}
|
|
47
|
+
"type ReadWriteMarkedKeys<T, Marker> = keyof {",
|
|
48
|
+
" [K in keyof T as 0 extends 1 & T[K] ? never : NonNullable<T[K]> extends never ? never : NonNullable<T[K]> extends Marker ? K : never]: never;",
|
|
49
|
+
"};",
|
|
50
50
|
'type ReadWriteResolveArray<T extends readonly unknown[], Resolved extends "read" | "write"> = T[number][] extends T ? T extends unknown[] ? ReadWriteResolve<T[number], Resolved>[] : readonly ReadWriteResolve<T[number], Resolved>[] : {',
|
|
51
51
|
" [K in keyof T]: ReadWriteResolve<T[K], Resolved>;",
|
|
52
52
|
"};",
|