openapi-typesafe 1.0.0-rc.3 → 1.0.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1972 -0
- package/dist/adapters/node-file-system/file-claims.cjs +105 -0
- package/dist/adapters/node-file-system/file-claims.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-claims.mjs +95 -0
- package/dist/adapters/node-file-system/file-claims.mjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.cjs +82 -0
- package/dist/adapters/node-file-system/file-identity.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.mjs +74 -0
- package/dist/adapters/node-file-system/file-identity.mjs.map +1 -0
- package/dist/adapters/node-file-system/node-file-system.cjs +97 -14
- package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
- package/dist/adapters/node-file-system/node-file-system.mjs +97 -14
- 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 +48 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +45 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs +2 -2
- package/dist/adapters/redocly-loader/bundled-ref-repair.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/loaded-documents.cjs +28 -0
- package/dist/adapters/redocly-loader/loaded-documents.cjs.map +1 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs +21 -0
- package/dist/adapters/redocly-loader/loaded-documents.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-named-components.cjs +137 -0
- package/dist/adapters/redocly-loader/query-named-components.cjs.map +1 -0
- package/dist/adapters/redocly-loader/query-named-components.mjs +134 -0
- package/dist/adapters/redocly-loader/query-named-components.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +40 -29
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +38 -27
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +45 -4
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +45 -4
- 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 +53 -12
- package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-body-limit.cjs +50 -0
- package/dist/adapters/redocly-loader/remote-body-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs +48 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-fetch.cjs +40 -9
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +40 -9
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.cjs +61 -0
- package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs +58 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-load-errors.cjs +32 -8
- package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-load-errors.mjs +32 -9
- package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.cjs +18 -9
- package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.mjs +20 -11
- package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.cjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.mjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.cjs +10 -4
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.mjs +10 -4
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
- package/dist/api/default-ports.cjs +14 -2
- package/dist/api/default-ports.cjs.map +1 -1
- package/dist/api/default-ports.mjs +14 -2
- package/dist/api/default-ports.mjs.map +1 -1
- package/dist/api/discriminator-enum-parent.cjs +2 -2
- package/dist/api/discriminator-enum-parent.cjs.map +1 -1
- package/dist/api/discriminator-enum-parent.mjs +3 -3
- package/dist/api/discriminator-enum-parent.mjs.map +1 -1
- package/dist/api/discriminator-other-owners.cjs +5 -3
- package/dist/api/discriminator-other-owners.cjs.map +1 -1
- package/dist/api/discriminator-other-owners.mjs +5 -3
- package/dist/api/discriminator-other-owners.mjs.map +1 -1
- package/dist/api/discriminator-patch.cjs +5 -1
- package/dist/api/discriminator-patch.cjs.map +1 -1
- package/dist/api/discriminator-patch.mjs +5 -1
- package/dist/api/discriminator-patch.mjs.map +1 -1
- package/dist/api/discriminator-scan.cjs +15 -8
- package/dist/api/discriminator-scan.cjs.map +1 -1
- package/dist/api/discriminator-scan.mjs +15 -8
- package/dist/api/discriminator-scan.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 -12
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +6 -12
- package/dist/api/document-run.mjs.map +1 -1
- package/dist/api/legacy-utils.cjs.map +1 -1
- package/dist/api/legacy-utils.mjs.map +1 -1
- package/dist/api/openapi-ts.cjs +9 -6
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +10 -8
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/ref-limit-options.cjs +63 -0
- package/dist/api/ref-limit-options.cjs.map +1 -0
- package/dist/api/ref-limit-options.mjs +57 -0
- package/dist/api/ref-limit-options.mjs.map +1 -0
- package/dist/api/schema-callbacks.cjs +36 -12
- package/dist/api/schema-callbacks.cjs.map +1 -1
- package/dist/api/schema-callbacks.mjs +36 -12
- package/dist/api/schema-callbacks.mjs.map +1 -1
- package/dist/api/transform-context.cjs +7 -3
- package/dist/api/transform-context.cjs.map +1 -1
- package/dist/api/transform-context.mjs +7 -3
- package/dist/api/transform-context.mjs.map +1 -1
- package/dist/api/transform-schema.cjs +47 -10
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +48 -11
- package/dist/api/transform-schema.mjs.map +1 -1
- package/dist/application/print/text-writer.cjs +10 -3
- package/dist/application/print/text-writer.cjs.map +1 -1
- package/dist/application/print/text-writer.mjs +10 -3
- package/dist/application/print/text-writer.mjs.map +1 -1
- package/dist/application/stack-overflow.cjs +2 -1
- package/dist/application/stack-overflow.cjs.map +1 -1
- package/dist/application/stack-overflow.mjs +2 -1
- package/dist/application/stack-overflow.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/components.cjs +1 -1
- package/dist/application/transform/document/components.cjs.map +1 -1
- package/dist/application/transform/document/components.mjs +2 -2
- package/dist/application/transform/document/components.mjs.map +1 -1
- package/dist/application/transform/document/declared-type-names.cjs +23 -0
- package/dist/application/transform/document/declared-type-names.cjs.map +1 -0
- package/dist/application/transform/document/declared-type-names.mjs +20 -0
- package/dist/application/transform/document/declared-type-names.mjs.map +1 -0
- package/dist/application/transform/document/defs-root.cjs +1 -1
- package/dist/application/transform/document/defs-root.cjs.map +1 -1
- package/dist/application/transform/document/defs-root.mjs +2 -2
- package/dist/application/transform/document/defs-root.mjs.map +1 -1
- package/dist/application/transform/document/document.cjs +7 -2
- package/dist/application/transform/document/document.cjs.map +1 -1
- package/dist/application/transform/document/document.mjs +6 -3
- package/dist/application/transform/document/document.mjs.map +1 -1
- package/dist/application/transform/document/enum-names-given-back.cjs +62 -0
- package/dist/application/transform/document/enum-names-given-back.cjs.map +1 -0
- package/dist/application/transform/document/enum-names-given-back.mjs +58 -0
- package/dist/application/transform/document/enum-names-given-back.mjs.map +1 -0
- 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/global-type-references.cjs +1 -0
- package/dist/application/transform/document/global-type-references.cjs.map +1 -1
- package/dist/application/transform/document/global-type-references.mjs +1 -1
- package/dist/application/transform/document/global-type-references.mjs.map +1 -1
- 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/media-type.cjs +2 -2
- package/dist/application/transform/document/media-type.cjs.map +1 -1
- package/dist/application/transform/document/media-type.mjs +3 -3
- package/dist/application/transform/document/media-type.mjs.map +1 -1
- package/dist/application/transform/document/operation-keys-written.cjs +26 -0
- package/dist/application/transform/document/operation-keys-written.cjs.map +1 -0
- package/dist/application/transform/document/operation-keys-written.mjs +24 -0
- package/dist/application/transform/document/operation-keys-written.mjs.map +1 -0
- package/dist/application/transform/document/operation.cjs +1 -1
- package/dist/application/transform/document/operation.cjs.map +1 -1
- package/dist/application/transform/document/operation.mjs +2 -2
- package/dist/application/transform/document/operation.mjs.map +1 -1
- package/dist/application/transform/document/parameter-entries.cjs +34 -0
- package/dist/application/transform/document/parameter-entries.cjs.map +1 -0
- package/dist/application/transform/document/parameter-entries.mjs +30 -0
- package/dist/application/transform/document/parameter-entries.mjs.map +1 -0
- package/dist/application/transform/document/parameter.cjs +12 -4
- package/dist/application/transform/document/parameter.cjs.map +1 -1
- package/dist/application/transform/document/parameter.mjs +13 -5
- package/dist/application/transform/document/parameter.mjs.map +1 -1
- package/dist/application/transform/document/parameters.cjs +29 -34
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +29 -34
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/path-item.cjs +15 -17
- package/dist/application/transform/document/path-item.cjs.map +1 -1
- package/dist/application/transform/document/path-item.mjs +15 -19
- 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 +70 -0
- package/dist/application/transform/document/path-template-refs.cjs.map +1 -0
- package/dist/application/transform/document/path-template-refs.mjs +67 -0
- package/dist/application/transform/document/path-template-refs.mjs.map +1 -0
- package/dist/application/transform/document/paths-enum.cjs +8 -6
- package/dist/application/transform/document/paths-enum.cjs.map +1 -1
- package/dist/application/transform/document/paths-enum.mjs +8 -7
- package/dist/application/transform/document/paths-enum.mjs.map +1 -1
- package/dist/application/transform/document/paths.cjs +43 -67
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +42 -68
- package/dist/application/transform/document/paths.mjs.map +1 -1
- package/dist/application/transform/document/referenced-parameter.cjs +80 -0
- package/dist/application/transform/document/referenced-parameter.cjs.map +1 -0
- package/dist/application/transform/document/referenced-parameter.mjs +78 -0
- package/dist/application/transform/document/referenced-parameter.mjs.map +1 -0
- package/dist/application/transform/document/request-body.cjs +1 -1
- package/dist/application/transform/document/request-body.cjs.map +1 -1
- package/dist/application/transform/document/request-body.mjs +2 -2
- package/dist/application/transform/document/request-body.mjs.map +1 -1
- package/dist/application/transform/document/response.cjs +2 -2
- package/dist/application/transform/document/response.cjs.map +1 -1
- package/dist/application/transform/document/response.mjs +3 -3
- package/dist/application/transform/document/response.mjs.map +1 -1
- package/dist/application/transform/document/responses.cjs +1 -1
- package/dist/application/transform/document/responses.cjs.map +1 -1
- package/dist/application/transform/document/responses.mjs +2 -2
- package/dist/application/transform/document/responses.mjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.cjs +8 -23
- package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.mjs +8 -24
- package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
- package/dist/application/transform/document/type-resolution.cjs +3 -1
- package/dist/application/transform/document/type-resolution.cjs.map +1 -1
- package/dist/application/transform/document/type-resolution.mjs +3 -1
- package/dist/application/transform/document/type-resolution.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 +10 -3
- package/dist/application/transform/document/webhooks.mjs.map +1 -1
- package/dist/application/transform/footer/document-footer.cjs +16 -5
- package/dist/application/transform/footer/document-footer.cjs.map +1 -1
- package/dist/application/transform/footer/document-footer.mjs +16 -5
- package/dist/application/transform/footer/document-footer.mjs.map +1 -1
- package/dist/application/transform/footer/enum-name-claims.cjs +48 -0
- package/dist/application/transform/footer/enum-name-claims.cjs.map +1 -0
- package/dist/application/transform/footer/enum-name-claims.mjs +46 -0
- package/dist/application/transform/footer/enum-name-claims.mjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.cjs +23 -0
- package/dist/application/transform/footer/operation-keys.cjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.mjs +21 -0
- package/dist/application/transform/footer/operation-keys.mjs.map +1 -0
- package/dist/application/transform/footer/type-evaluation.cjs +4 -4
- package/dist/application/transform/footer/type-evaluation.cjs.map +1 -1
- package/dist/application/transform/footer/type-evaluation.mjs +4 -4
- package/dist/application/transform/footer/type-evaluation.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/numbered-names.cjs +9 -0
- package/dist/application/transform/numbered-names.cjs.map +1 -1
- package/dist/application/transform/numbered-names.mjs +9 -1
- package/dist/application/transform/numbered-names.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs +5 -5
- package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs +3 -3
- package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.cjs +47 -66
- package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.mjs +36 -50
- 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 +68 -13
- package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/original-index.mjs +70 -15
- 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 +52 -0
- package/dist/application/transform/ref-pointer/property-shape.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/property-shape.mjs +45 -0
- package/dist/application/transform/ref-pointer/property-shape.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/typed-walk.cjs +79 -21
- package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/typed-walk.mjs +76 -18
- package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -1
- package/dist/application/transform/ref-type.cjs +2 -1
- package/dist/application/transform/ref-type.cjs.map +1 -1
- package/dist/application/transform/ref-type.mjs +2 -1
- package/dist/application/transform/ref-type.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/composition-type.cjs +1 -1
- package/dist/application/transform/schema/composition-type.cjs.map +1 -1
- package/dist/application/transform/schema/composition-type.mjs +2 -2
- package/dist/application/transform/schema/composition-type.mjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.cjs +1 -1
- package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.mjs +2 -2
- package/dist/application/transform/schema/enum-rule.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 +18 -8
- package/dist/application/transform/schema/object-type.cjs.map +1 -1
- package/dist/application/transform/schema/object-type.mjs +19 -9
- package/dist/application/transform/schema/object-type.mjs.map +1 -1
- package/dist/application/transform/schema/ref-siblings.cjs +47 -0
- package/dist/application/transform/schema/ref-siblings.cjs.map +1 -0
- package/dist/application/transform/schema/ref-siblings.mjs +45 -0
- package/dist/application/transform/schema/ref-siblings.mjs.map +1 -0
- package/dist/application/transform/schema/schema-transform.cjs +6 -3
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.mjs +6 -3
- 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/application/transform/schema-comment.cjs +5 -1
- package/dist/application/transform/schema-comment.cjs.map +1 -1
- package/dist/application/transform/schema-comment.mjs +5 -1
- package/dist/application/transform/schema-comment.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 +57 -9
- package/dist/cli/api-settings.cjs.map +1 -1
- package/dist/cli/api-settings.mjs +56 -11
- package/dist/cli/api-settings.mjs.map +1 -1
- package/dist/cli/api-writes.cjs +72 -0
- package/dist/cli/api-writes.cjs.map +1 -0
- package/dist/cli/api-writes.mjs +69 -0
- package/dist/cli/api-writes.mjs.map +1 -0
- package/dist/cli/cli-arguments.cjs +51 -11
- package/dist/cli/cli-arguments.cjs.map +1 -1
- package/dist/cli/cli-arguments.mjs +51 -11
- package/dist/cli/cli-arguments.mjs.map +1 -1
- package/dist/cli/cli-errors.cjs +29 -1
- package/dist/cli/cli-errors.cjs.map +1 -1
- package/dist/cli/cli-errors.mjs +29 -2
- package/dist/cli/cli-errors.mjs.map +1 -1
- package/dist/cli/cli-output.cjs +111 -4
- package/dist/cli/cli-output.cjs.map +1 -1
- package/dist/cli/cli-output.mjs +104 -5
- package/dist/cli/cli-output.mjs.map +1 -1
- package/dist/cli/main.cjs +13 -3
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.mjs +14 -4
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +94 -37
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +99 -42
- 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 +37 -14
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +39 -16
- package/dist/cli/run-cli.mjs.map +1 -1
- package/dist/domain/append-all.cjs +10 -0
- package/dist/domain/append-all.cjs.map +1 -0
- package/dist/domain/append-all.mjs +8 -0
- package/dist/domain/append-all.mjs.map +1 -0
- package/dist/domain/cause-secrets.cjs +52 -0
- package/dist/domain/cause-secrets.cjs.map +1 -0
- package/dist/domain/cause-secrets.mjs +50 -0
- package/dist/domain/cause-secrets.mjs.map +1 -0
- package/dist/domain/errors.cjs +11 -3
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +11 -3
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/ir/identifier-text.cjs.map +1 -1
- package/dist/domain/ir/identifier-text.mjs +1 -1
- package/dist/domain/ir/identifier-text.mjs.map +1 -1
- package/dist/domain/ir/ir-shape.cjs +187 -0
- package/dist/domain/ir/ir-shape.cjs.map +1 -0
- package/dist/domain/ir/ir-shape.mjs +184 -0
- package/dist/domain/ir/ir-shape.mjs.map +1 -0
- package/dist/domain/ir/newer-identifier-ranges.cjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.cjs.map +1 -1
- package/dist/domain/ir/newer-identifier-ranges.mjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.mjs.map +1 -1
- package/dist/domain/location-text.cjs +9 -0
- package/dist/domain/location-text.cjs.map +1 -0
- package/dist/domain/location-text.mjs +7 -0
- package/dist/domain/location-text.mjs.map +1 -0
- package/dist/domain/openapi/alias-expansion.cjs +3 -1
- package/dist/domain/openapi/alias-expansion.cjs.map +1 -1
- package/dist/domain/openapi/alias-expansion.mjs +3 -1
- package/dist/domain/openapi/alias-expansion.mjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.cjs +3 -3
- package/dist/domain/openapi/discriminated-union.cjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.mjs +4 -4
- package/dist/domain/openapi/discriminated-union.mjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.cjs +10 -6
- package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.mjs +11 -7
- package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -1
- 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/openapi/json-pointer.cjs +43 -1
- package/dist/domain/openapi/json-pointer.cjs.map +1 -1
- package/dist/domain/openapi/json-pointer.mjs +40 -2
- package/dist/domain/openapi/json-pointer.mjs.map +1 -1
- package/dist/domain/openapi/schema-dialect.cjs +15 -0
- package/dist/domain/openapi/schema-dialect.cjs.map +1 -0
- package/dist/domain/openapi/schema-dialect.mjs +12 -0
- package/dist/domain/openapi/schema-dialect.mjs.map +1 -0
- package/dist/domain/openapi/unsupported-features.cjs +1 -1
- package/dist/domain/openapi/unsupported-features.cjs.map +1 -1
- package/dist/domain/openapi/unsupported-features.mjs +2 -2
- package/dist/domain/openapi/unsupported-features.mjs.map +1 -1
- package/dist/domain/output-fixes.cjs +20 -0
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +20 -0
- 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/url-secrets.cjs +48 -0
- package/dist/domain/url-secrets.cjs.map +1 -0
- package/dist/domain/url-secrets.mjs +45 -0
- package/dist/domain/url-secrets.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 +46 -20
- package/dist/index.d.mts +46 -20
- package/dist/index.d.ts +46 -20
- package/package.json +4 -5
- package/src/adapters/node-file-system/file-claims.ts +138 -0
- package/src/adapters/node-file-system/file-identity.ts +137 -0
- package/src/adapters/node-file-system/node-file-system.ts +158 -18
- package/src/adapters/pipe-safe-writer/pipe-safe-writer.ts +29 -0
- package/src/adapters/redocly-loader/bundled-mapping-copies.ts +60 -0
- package/src/adapters/redocly-loader/bundled-ref-repair.ts +2 -2
- package/src/adapters/redocly-loader/component-schemas.ts +19 -0
- package/src/adapters/redocly-loader/loaded-documents.ts +46 -0
- package/src/adapters/redocly-loader/mapping-schema-names.ts +25 -0
- package/src/adapters/redocly-loader/query-named-components.ts +201 -0
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +64 -38
- package/src/adapters/redocly-loader/ref-access.ts +51 -4
- package/src/adapters/redocly-loader/ref-holders.ts +76 -15
- package/src/adapters/redocly-loader/remote-body-limit.ts +66 -0
- package/src/adapters/redocly-loader/remote-fetch.ts +85 -13
- package/src/adapters/redocly-loader/remote-node-limit.ts +102 -0
- package/src/adapters/redocly-loader/schema-load-errors.ts +52 -13
- package/src/adapters/redocly-loader/schema-source.ts +35 -11
- package/src/adapters/redocly-loader/unsupported-keys.ts +3 -7
- package/src/adapters/terminal-logger/terminal-logger.ts +17 -6
- package/src/api/default-ports.ts +33 -4
- package/src/api/discriminator-enum-parent.ts +3 -3
- package/src/api/discriminator-other-owners.ts +5 -3
- package/src/api/discriminator-patch.ts +5 -1
- package/src/api/discriminator-scan.ts +16 -8
- package/src/api/document-refs.ts +29 -1
- package/src/api/document-run.ts +10 -19
- package/src/api/legacy-utils.ts +5 -1
- package/src/api/openapi-ts.ts +26 -8
- package/src/api/ref-limit-options.ts +76 -0
- package/src/api/run-context.ts +3 -0
- package/src/api/schema-callbacks.ts +60 -17
- package/src/api/transform-context.ts +7 -3
- package/src/api/transform-schema.ts +79 -12
- package/src/application/ports/file-system.ts +47 -0
- package/src/application/ports/schema-loader.ts +11 -1
- package/src/application/print/text-writer.ts +10 -3
- package/src/application/stack-overflow.ts +9 -5
- package/src/application/transform/declared-value-types.ts +42 -0
- package/src/application/transform/document/components.ts +2 -2
- package/src/application/transform/document/declared-type-names.ts +36 -0
- package/src/application/transform/document/defs-root.ts +2 -2
- package/src/application/transform/document/document.ts +8 -5
- package/src/application/transform/document/enum-names-given-back.ts +91 -0
- package/src/application/transform/document/exploded-query-values.ts +88 -0
- package/src/application/transform/document/global-type-references.ts +1 -1
- package/src/application/transform/document/header.ts +25 -5
- package/src/application/transform/document/media-type.ts +4 -3
- package/src/application/transform/document/operation-keys-written.ts +27 -0
- package/src/application/transform/document/operation.ts +2 -2
- package/src/application/transform/document/parameter-entries.ts +70 -0
- package/src/application/transform/document/parameter.ts +21 -9
- package/src/application/transform/document/parameters.ts +56 -66
- package/src/application/transform/document/path-item.ts +16 -34
- package/src/application/transform/document/path-template-key.ts +152 -0
- package/src/application/transform/document/path-template-refs.ts +106 -0
- package/src/application/transform/document/paths-enum.ts +24 -10
- package/src/application/transform/document/paths.ts +59 -125
- package/src/application/transform/document/referenced-parameter.ts +146 -0
- package/src/application/transform/document/request-body.ts +2 -2
- package/src/application/transform/document/response.ts +3 -3
- package/src/application/transform/document/responses.ts +2 -2
- package/src/application/transform/document/root-type-aliases.ts +17 -38
- package/src/application/transform/document/type-resolution.ts +2 -1
- package/src/application/transform/document/webhooks.ts +19 -6
- package/src/application/transform/footer/document-footer.ts +36 -9
- package/src/application/transform/footer/enum-name-claims.ts +62 -0
- package/src/application/transform/footer/operation-keys.ts +28 -0
- package/src/application/transform/footer/type-evaluation.ts +4 -4
- package/src/application/transform/helper-types.ts +8 -7
- package/src/application/transform/numbered-names.ts +15 -0
- package/src/application/transform/ref-pointer/generated-location.ts +3 -3
- package/src/application/transform/ref-pointer/generated-shape.ts +67 -78
- 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 +100 -17
- 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 +97 -0
- package/src/application/transform/ref-pointer/typed-walk.ts +117 -25
- package/src/application/transform/ref-type.ts +2 -1
- package/src/application/transform/schema/access-flags.ts +5 -2
- package/src/application/transform/schema/composition-type.ts +2 -2
- package/src/application/transform/schema/enum-rule.ts +6 -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 +22 -12
- package/src/application/transform/schema/ref-siblings.ts +76 -0
- package/src/application/transform/schema/schema-context.ts +3 -0
- package/src/application/transform/schema/schema-transform.ts +6 -3
- package/src/application/transform/schema/unevaluated-properties.ts +4 -44
- package/src/application/transform/schema-comment.ts +5 -1
- package/src/application/transform/transform-context.ts +5 -0
- package/src/cli/api-logger.ts +17 -0
- package/src/cli/api-settings.ts +80 -13
- package/src/cli/api-writes.ts +117 -0
- package/src/cli/cli-arguments.ts +90 -14
- package/src/cli/cli-dependencies.ts +26 -4
- package/src/cli/cli-errors.ts +42 -1
- package/src/cli/cli-output.ts +195 -15
- package/src/cli/main.ts +14 -5
- package/src/cli/redocly-apis.ts +177 -52
- package/src/cli/ref-limits.ts +21 -2
- package/src/cli/run-cli.ts +76 -15
- package/src/domain/append-all.ts +10 -0
- package/src/domain/cause-secrets.ts +86 -0
- package/src/domain/errors.ts +16 -5
- package/src/domain/ir/identifier-text.ts +6 -5
- package/src/domain/ir/ir-shape.ts +299 -0
- package/src/domain/ir/newer-identifier-ranges.ts +183 -30
- package/src/domain/location-text.ts +12 -0
- package/src/domain/openapi/alias-expansion.ts +4 -1
- package/src/domain/openapi/discriminated-union.ts +6 -4
- package/src/domain/openapi/discriminator-conflicts.ts +21 -7
- package/src/domain/openapi/document-object.ts +2 -0
- package/src/domain/openapi/document-places.ts +78 -0
- package/src/domain/openapi/json-pointer.ts +96 -7
- package/src/domain/openapi/schema-dialect.ts +22 -0
- package/src/domain/openapi/unsupported-features.ts +2 -2
- package/src/domain/output-fixes.ts +28 -2
- package/src/domain/terminal-text.ts +44 -0
- package/src/domain/url-secrets.ts +72 -0
- package/src/domain/warnings.ts +1 -0
- package/src/types/generator-options.ts +1 -1
- package/dist/cli/main.d.cts +0 -2
- package/dist/cli/main.d.mts +0 -2
- package/dist/cli/main.d.ts +0 -2
- package/dist/domain/url-credentials.cjs +0 -10
- package/dist/domain/url-credentials.cjs.map +0 -1
- package/dist/domain/url-credentials.mjs +0 -8
- package/dist/domain/url-credentials.mjs.map +0 -1
- package/src/domain/url-credentials.ts +0 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.cjs","sources":["../../../../src/application/transform/document/components.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport {\n hasIdentifierStart,\n isReservedTypeName,\n withIdentifierParts,\n} from \"../../../domain/ir/identifier-text.js\";\nimport type {\n IrPropertySignature,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {\n COMPONENT_KINDS,\n type ComponentKind,\n type ComponentsObject,\n DECLARED_COMPONENT_KINDS,\n isEnumSchema,\n singularizeComponentKind,\n} from \"../../../domain/openapi/components-object.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { type DeprecatedEntryFilter, documentEntries } from \"../document-entries.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { schemaCommentOptionsOf, withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { headerType } from \"./header.js\";\nimport { contentEntryType } from \"./media-type.js\";\nimport { parameterType } from \"./parameter.js\";\nimport { pathItemType } from \"./path-item.js\";\nimport { requestBodyType } from \"./request-body.js\";\nimport { responseType } from \"./response.js\";\nimport { rootTypeAlias } from \"./root-type-aliases.js\";\n\ntype ComponentTransform = (\n item: never,\n location: SchemaLocation,\n context: TransformContext,\n) => IrType;\n\nconst COMPONENT_TRANSFORMS: Readonly<Record<ComponentKind, ComponentTransform>> = {\n schemas: transformSchema,\n responses: responseType,\n parameters: parameterType,\n requestBodies: requestBodyType,\n headers: headerType,\n pathItems: pathItemType,\n mediaTypes: contentEntryType,\n};\n\n/** The `components` type and the `--root-types` aliases. */\nexport interface ComponentsResult {\n readonly type: IrType;\n readonly rootTypes: readonly IrTypeAliasDeclaration[];\n}\n\n/** One component; the `transform` callback may replace its type, as for nested schemas. */\nfunction componentMember(\n kind: ComponentKind,\n name: string,\n item: unknown,\n context: TransformContext,\n): IrPropertySignature {\n const location = { path: createRef([\"components\", kind, name]), schema: item };\n const type = COMPONENT_TRANSFORMS[kind](item as never, location, context);\n const custom = context.callbacks.transform(item, location);\n const property = irProperty(toPropertyName(name), custom?.type ?? type, {\n isOptional: custom?.isOptional ?? false,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, item, schemaCommentOptionsOf(context.options.fixes));\n}\n\n/**\n * The root alias name: `SchemaPet`, `ResponseNotFound`, … A taken name gets `_2`, `_3`, … The\n * original checks for conflicts before it removes the schema prefix, and so does this; for a clash\n * of exported names see `addRootAlias`.\n *\n * The original could build a name that is no identifier, so the generated file did not parse\n * (research/legacy-bugs.md, item 16): a kept casing keeps spaces and symbols, which become `_`;\n * and a name without the prefix can start with a digit, so it keeps the prefix (`Schema1`). A\n * kept casing without the prefix can also give a reserved name (`void`, `class`), which keeps the\n * prefix too (`Schemavoid`).\n */\nfunction rootTypeName(\n kind: ComponentKind,\n name: string,\n aliases: Readonly<Record<string, IrTypeAliasDeclaration>>,\n context: TransformContext,\n): string {\n const { options, casing } = context;\n const prefix = casing.pascalCase(singularizeComponentKind(kind));\n const isSchema = kind === \"schemas\";\n const base = withIdentifierParts(\n options.rootTypesKeepCasing && isSchema ? name : casing.pascalCase(name),\n );\n const exportedName = (alias: string): string => {\n const unprefixed = alias.replace(prefix, \"\");\n const isUnprefixed = options.rootTypesNoSchemaPrefix && isSchema;\n const isTypeName = hasIdentifierStart(unprefixed) && !isReservedTypeName(unprefixed);\n return isUnprefixed && isTypeName ? unprefixed : alias;\n };\n let alias = `${prefix}${base}`;\n for (let counter = 2; aliases[alias] !== undefined; counter++) {\n alias = `${prefix}${base}_${counter}`;\n }\n return exportedName(alias);\n}\n\n/**\n * Add a root alias. When its exported name is taken (two schemas of one PascalCase name without\n * the prefix), the later schema takes the name, as in the original. Without the\n * `root-type-numbering` fix the earlier one then has no alias: that output is valid, so a number\n * for it would change it (backlog 30). With the fix the earlier alias is kept aside and follows\n * the others under the same name; `renameTakenAliases` numbers it once every name is known.\n */\nfunction addRootAlias(request: ComponentsRequest, alias: IrTypeAliasDeclaration): void {\n const { aliases, displaced } = request;\n const previous = aliases[alias.name];\n if (previous !== undefined && displaced !== null) {\n displaced.push(previous);\n }\n aliases[alias.name] = alias;\n}\n\n/** `--root-types` skips enum schemas under `--enum`: the enum itself is exported. */\nfunction hasRootType(kind: ComponentKind, item: unknown, context: TransformContext): boolean {\n const { options } = context;\n return options.rootTypes && !(options.enum && kind === \"schemas\" && isEnumSchema(item));\n}\n\n/** The components of one run, and the deprecated ones that kept output still references. */\ninterface ComponentsRequest {\n readonly components: ComponentsObject;\n readonly isKept: DeprecatedEntryFilter;\n readonly aliases: Record<string, IrTypeAliasDeclaration>;\n /** With the `root-type-numbering` fix: the aliases a later schema took the name of, in order. */\n readonly displaced: IrTypeAliasDeclaration[] | null;\n}\n\nfunction kindMember(\n kind: ComponentKind,\n request: ComponentsRequest,\n context: TransformContext,\n): IrPropertySignature {\n const { components, isKept, aliases } = request;\n const startedAt = context.diagnostics.now();\n const items: IrPropertySignature[] = [];\n for (const [name, item] of documentEntries(components[kind] ?? {}, context.options, isKept)) {\n items.push(componentMember(kind, name, item, context));\n if (hasRootType(kind, item, context)) {\n addRootAlias(request, rootTypeAlias(rootTypeName(kind, name, aliases, context), kind, name));\n }\n }\n const type = items.length > 0 ? irObject(items) : irKeyword(\"never\");\n context.diagnostics.debug(\n `Transformed components → ${kind}`,\n context.diagnostics.now() - startedAt,\n );\n return irProperty(toPropertyName(kind), type);\n}\n\n/**\n * The `components` interface body (OpenAPI 3.1 §4.8.7), one member per component kind. With\n * `--exclude-deprecated`, `kept` holds the deprecated components that kept output references\n * (`keptDeprecatedComponents`); they stay, so no reference names a missing key.\n */\nexport function componentsType(\n components: ComponentsObject,\n context: TransformContext,\n kept: ReadonlySet<object> = new Set(),\n): ComponentsResult {\n // A plain object, as in the original: its key order (integer-like names first) is the\n // output order.\n const aliases: Record<string, IrTypeAliasDeclaration> = {};\n const displaced = context.options.fixes.has(FIX.ROOT_TYPE_NUMBERING) ? [] : null;\n const isKept = (item: unknown) => kept.has(item as object);\n const request = { components, isKept, aliases, displaced };\n const declaredKinds = DECLARED_COMPONENT_KINDS.filter((kind) => components[kind] !== undefined);\n const members = [...COMPONENT_KINDS, ...declaredKinds].map((kind) =>\n kindMember(kind, request, context),\n );\n const rootTypes = Object.values(aliases);\n return {\n type: irObject(members),\n rootTypes: [...rootTypes, ...(displaced ?? [])],\n };\n}\n"],"names":["transformSchema","responseType","parameterType","requestBodyType","headerType","pathItemType","contentEntryType","createRef","irProperty","toPropertyName","withSchemaComment","schemaCommentOptionsOf","singularizeComponentKind","withIdentifierParts","alias","hasIdentifierStart","isReservedTypeName","isEnumSchema","documentEntries","rootTypeAlias","irObject","irKeyword","FIX","DECLARED_COMPONENT_KINDS","COMPONENT_KINDS"],"mappings":";;;;;;;;;;;;;;;;;;;AAyCA,MAAM,oBAAA,GAA4E;AAAA,EAChF,OAAA,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ClB;AAGlB,EAAA,MAAM,UAAkD,EAAC;AACzD,EAAA,MAAM,SAAA,GAAY,QAAQ,OAAA,CAAQ,KAAA,CAAM,IAAIa,eAAA,CAAI,mBAAmB,CAAA,GAAI,EAAC,GAAI,IAAA;AAC5E,EAAA,MAAM,MAAA,GAAS,CAAC,IAAA,KAAkB,IAAA,CAAK,IAAI,IAAc,CAAA;AACzD,EAAA,MAAM,OAAA,GAAU,EAAE,UAAA,EAAY,MAAA,EAAQ,SAAS,SAAA,EAAU;AACzD,EAAA,MAAM,aAAA,GAAgBC,0CAAyB,MAAA,CAAO,CAAC,SAAS,UAAA,CAAW,IAAI,MAAM,MAAS,CAAA;AAC9F,EAAA,MAAM,UAAU,CAAC,GAAGC,gCAAA,EAAiB,GAAG,aAAa,CAAA,CAAE,GAAA;AAAA,IAAI,CAAC,IAAA,KAC1D,UAAA,CAAW,IAAA,EAAM,SAAS,OAAO;AAAA,GACnC;AACA,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,MAAA,CAAO,OAAO,CAAA;AACvC,EAAA,OAAO;AAAA,IACL,IAAA,EAAMJ,sBAAS,OAAO,CAAA;AAAA,IACtB,WAAW,CAAC,GAAG,WAAW,GAAI,SAAA,IAAa,EAAG;AAAA,GAChD;AACF;;"}
|
|
1
|
+
{"version":3,"file":"components.cjs","sources":["../../../../src/application/transform/document/components.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport {\n hasIdentifierStart,\n isReservedTypeName,\n withIdentifierParts,\n} from \"../../../domain/ir/identifier-text.js\";\nimport type {\n IrPropertySignature,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {\n COMPONENT_KINDS,\n type ComponentKind,\n type ComponentsObject,\n DECLARED_COMPONENT_KINDS,\n isEnumSchema,\n singularizeComponentKind,\n} from \"../../../domain/openapi/components-object.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { type DeprecatedEntryFilter, documentEntries } from \"../document-entries.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { schemaCommentOptionsOf, withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { headerType } from \"./header.js\";\nimport { contentEntryType } from \"./media-type.js\";\nimport { parameterType } from \"./parameter.js\";\nimport { pathItemType } from \"./path-item.js\";\nimport { requestBodyType } from \"./request-body.js\";\nimport { responseType } from \"./response.js\";\nimport { rootTypeAlias } from \"./root-type-aliases.js\";\n\ntype ComponentTransform = (\n item: never,\n location: SchemaLocation,\n context: TransformContext,\n) => IrType;\n\nconst COMPONENT_TRANSFORMS: Readonly<Record<ComponentKind, ComponentTransform>> = {\n schemas: transformSchema,\n responses: responseType,\n parameters: parameterType,\n requestBodies: requestBodyType,\n headers: headerType,\n pathItems: pathItemType,\n mediaTypes: contentEntryType,\n};\n\n/** The `components` type and the `--root-types` aliases. */\nexport interface ComponentsResult {\n readonly type: IrType;\n readonly rootTypes: readonly IrTypeAliasDeclaration[];\n}\n\n/** One component; the `transform` callback may replace its type, as for nested schemas. */\nfunction componentMember(\n kind: ComponentKind,\n name: string,\n item: unknown,\n context: TransformContext,\n): IrPropertySignature {\n const location = { path: appendPointer(ROOT_POINTER, [\"components\", kind, name]), schema: item };\n const type = COMPONENT_TRANSFORMS[kind](item as never, location, context);\n const custom = context.callbacks.transform(item, location);\n const property = irProperty(toPropertyName(name), custom?.type ?? type, {\n isOptional: custom?.isOptional ?? false,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, item, schemaCommentOptionsOf(context.options.fixes));\n}\n\n/**\n * The root alias name: `SchemaPet`, `ResponseNotFound`, … A taken name gets `_2`, `_3`, … The\n * original checks for conflicts before it removes the schema prefix, and so does this; for a clash\n * of exported names see `addRootAlias`.\n *\n * The original could build a name that is no identifier, so the generated file did not parse\n * (research/legacy-bugs.md, item 16): a kept casing keeps spaces and symbols, which become `_`;\n * and a name without the prefix can start with a digit, so it keeps the prefix (`Schema1`). A\n * kept casing without the prefix can also give a reserved name (`void`, `class`), which keeps the\n * prefix too (`Schemavoid`).\n */\nfunction rootTypeName(\n kind: ComponentKind,\n name: string,\n aliases: Readonly<Record<string, IrTypeAliasDeclaration>>,\n context: TransformContext,\n): string {\n const { options, casing } = context;\n const prefix = casing.pascalCase(singularizeComponentKind(kind));\n const isSchema = kind === \"schemas\";\n const base = withIdentifierParts(\n options.rootTypesKeepCasing && isSchema ? name : casing.pascalCase(name),\n );\n const exportedName = (alias: string): string => {\n const unprefixed = alias.replace(prefix, \"\");\n const isUnprefixed = options.rootTypesNoSchemaPrefix && isSchema;\n const isTypeName = hasIdentifierStart(unprefixed) && !isReservedTypeName(unprefixed);\n return isUnprefixed && isTypeName ? unprefixed : alias;\n };\n let alias = `${prefix}${base}`;\n for (let counter = 2; aliases[alias] !== undefined; counter++) {\n alias = `${prefix}${base}_${counter}`;\n }\n return exportedName(alias);\n}\n\n/**\n * Add a root alias. When its exported name is taken (two schemas of one PascalCase name without\n * the prefix), the later schema takes the name, as in the original. Without the\n * `root-type-numbering` fix the earlier one then has no alias: that output is valid, so a number\n * for it would change it (backlog 30). With the fix the earlier alias is kept aside and follows\n * the others under the same name; `renameTakenAliases` numbers it once every name is known.\n */\nfunction addRootAlias(request: ComponentsRequest, alias: IrTypeAliasDeclaration): void {\n const { aliases, displaced } = request;\n const previous = aliases[alias.name];\n if (previous !== undefined && displaced !== null) {\n displaced.push(previous);\n }\n aliases[alias.name] = alias;\n}\n\n/** `--root-types` skips enum schemas under `--enum`: the enum itself is exported. */\nfunction hasRootType(kind: ComponentKind, item: unknown, context: TransformContext): boolean {\n const { options } = context;\n return options.rootTypes && !(options.enum && kind === \"schemas\" && isEnumSchema(item));\n}\n\n/** The components of one run, and the deprecated ones that kept output still references. */\ninterface ComponentsRequest {\n readonly components: ComponentsObject;\n readonly isKept: DeprecatedEntryFilter;\n readonly aliases: Record<string, IrTypeAliasDeclaration>;\n /** With the `root-type-numbering` fix: the aliases a later schema took the name of, in order. */\n readonly displaced: IrTypeAliasDeclaration[] | null;\n}\n\nfunction kindMember(\n kind: ComponentKind,\n request: ComponentsRequest,\n context: TransformContext,\n): IrPropertySignature {\n const { components, isKept, aliases } = request;\n const startedAt = context.diagnostics.now();\n const items: IrPropertySignature[] = [];\n for (const [name, item] of documentEntries(components[kind] ?? {}, context.options, isKept)) {\n items.push(componentMember(kind, name, item, context));\n if (hasRootType(kind, item, context)) {\n addRootAlias(request, rootTypeAlias(rootTypeName(kind, name, aliases, context), kind, name));\n }\n }\n const type = items.length > 0 ? irObject(items) : irKeyword(\"never\");\n context.diagnostics.debug(\n `Transformed components → ${kind}`,\n context.diagnostics.now() - startedAt,\n );\n return irProperty(toPropertyName(kind), type);\n}\n\n/**\n * The `components` interface body (OpenAPI 3.1 §4.8.7), one member per component kind. With\n * `--exclude-deprecated`, `kept` holds the deprecated components that kept output references\n * (`keptDeprecatedComponents`); they stay, so no reference names a missing key.\n */\nexport function componentsType(\n components: ComponentsObject,\n context: TransformContext,\n kept: ReadonlySet<object> = new Set(),\n): ComponentsResult {\n // A plain object, as in the original: its key order (integer-like names first) is the\n // output order.\n const aliases: Record<string, IrTypeAliasDeclaration> = {};\n const displaced = context.options.fixes.has(FIX.ROOT_TYPE_NUMBERING) ? [] : null;\n const isKept = (item: unknown) => kept.has(item as object);\n const request = { components, isKept, aliases, displaced };\n const declaredKinds = DECLARED_COMPONENT_KINDS.filter((kind) => components[kind] !== undefined);\n const members = [...COMPONENT_KINDS, ...declaredKinds].map((kind) =>\n kindMember(kind, request, context),\n );\n const rootTypes = Object.values(aliases);\n return {\n type: irObject(members),\n rootTypes: [...rootTypes, ...(displaced ?? [])],\n };\n}\n"],"names":["transformSchema","responseType","parameterType","requestBodyType","headerType","pathItemType","contentEntryType","appendPointer","ROOT_POINTER","irProperty","toPropertyName","withSchemaComment","schemaCommentOptionsOf","singularizeComponentKind","withIdentifierParts","alias","hasIdentifierStart","isReservedTypeName","isEnumSchema","documentEntries","rootTypeAlias","irObject","irKeyword","FIX","DECLARED_COMPONENT_KINDS","COMPONENT_KINDS"],"mappings":";;;;;;;;;;;;;;;;;;;AAyCA,MAAM,oBAAA,GAA4E;AAAA,EAChF,OAAA,EAASA,+BAAA;AAAA,EACT,SAAA,EAAWC,qBAAA;AAAA,EACX,UAAA,EAAYC,uBAAA;AAAA,EACZ,aAAA,EAAeC,2BAAA;AAAA,EACf,OAAA,EAASC,iBAAA;AAAA,EACT,SAAA,EAAWC,qBAAA;AAAA,EACX,UAAA,EAAYC;AACd,CAAA;AASA,SAAS,eAAA,CACP,IAAA,EACA,IAAA,EACA,IAAA,EACA,OAAA,EACqB;AACrB,EAAA,MAAM,QAAA,GAAW,EAAE,IAAA,EAAMC,yBAAA,CAAcC,wBAAA,EAAc,CAAC,YAAA,EAAc,IAAA,EAAM,IAAI,CAAC,CAAA,EAAG,MAAA,EAAQ,IAAA,EAAK;AAC/F,EAAA,MAAM,OAAO,oBAAA,CAAqB,IAAI,CAAA,CAAE,IAAA,EAAe,UAAU,OAAO,CAAA;AACxE,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,SAAA,CAAU,SAAA,CAAU,MAAM,QAAQ,CAAA;AACzD,EAAA,MAAM,WAAWC,uBAAA,CAAWC,2BAAA,CAAe,IAAI,CAAA,EAAG,MAAA,EAAQ,QAAQ,IAAA,EAAM;AAAA,IACtE,UAAA,EAAY,QAAQ,UAAA,IAAc,KAAA;AAAA,IAClC,UAAA,EAAY,QAAQ,OAAA,CAAQ;AAAA,GAC7B,CAAA;AACD,EAAA,OAAOC,gCAAkB,QAAA,EAAU,IAAA,EAAMC,qCAAuB,OAAA,CAAQ,OAAA,CAAQ,KAAK,CAAC,CAAA;AACxF;AAaA,SAAS,YAAA,CACP,IAAA,EACA,IAAA,EACA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AAA,CAAY,KAAA;AAAA,IAClB,iCAA4B,IAAI,CAAA,CAAA;AAAA,IAChC,OAAA,CAAQ,WAAA,CAAY,GAAA,EAAI,GAAI;AAAA,GAC9B;AACA,EAAA,OAAOb,uBAAA,CAAWC,2BAAA,CAAe,IAAI,CAAA,EAAG,IAAI,CAAA;AAC9C;AAOO,SAAS,eACd,UAAA,EACA,OAAA,EACA,IAAA,mBAA4B,IAAI,KAAI,EAClB;AAGlB,EAAA,MAAM,UAAkD,EAAC;AACzD,EAAA,MAAM,SAAA,GAAY,QAAQ,OAAA,CAAQ,KAAA,CAAM,IAAIa,eAAA,CAAI,mBAAmB,CAAA,GAAI,EAAC,GAAI,IAAA;AAC5E,EAAA,MAAM,MAAA,GAAS,CAAC,IAAA,KAAkB,IAAA,CAAK,IAAI,IAAc,CAAA;AACzD,EAAA,MAAM,OAAA,GAAU,EAAE,UAAA,EAAY,MAAA,EAAQ,SAAS,SAAA,EAAU;AACzD,EAAA,MAAM,aAAA,GAAgBC,0CAAyB,MAAA,CAAO,CAAC,SAAS,UAAA,CAAW,IAAI,MAAM,MAAS,CAAA;AAC9F,EAAA,MAAM,UAAU,CAAC,GAAGC,gCAAA,EAAiB,GAAG,aAAa,CAAA,CAAE,GAAA;AAAA,IAAI,CAAC,IAAA,KAC1D,UAAA,CAAW,IAAA,EAAM,SAAS,OAAO;AAAA,GACnC;AACA,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,MAAA,CAAO,OAAO,CAAA;AACvC,EAAA,OAAO;AAAA,IACL,IAAA,EAAMJ,sBAAS,OAAO,CAAA;AAAA,IACtB,WAAW,CAAC,GAAG,WAAW,GAAI,SAAA,IAAa,EAAG;AAAA,GAChD;AACF;;"}
|
|
@@ -2,7 +2,7 @@ import { irObject, irProperty, irKeyword } from '../../../domain/ir/constructors
|
|
|
2
2
|
import { withIdentifierParts, hasIdentifierStart, isReservedTypeName } from '../../../domain/ir/identifier-text.mjs';
|
|
3
3
|
import { toPropertyName } from '../../../domain/ir/property-name.mjs';
|
|
4
4
|
import { DECLARED_COMPONENT_KINDS, COMPONENT_KINDS, isEnumSchema, singularizeComponentKind } from '../../../domain/openapi/components-object.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import { appendPointer, ROOT_POINTER } from '../../../domain/openapi/json-pointer.mjs';
|
|
6
6
|
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
7
7
|
import { documentEntries } from '../document-entries.mjs';
|
|
8
8
|
import { transformSchema } from '../schema/schema-transform.mjs';
|
|
@@ -25,7 +25,7 @@ const COMPONENT_TRANSFORMS = {
|
|
|
25
25
|
mediaTypes: contentEntryType
|
|
26
26
|
};
|
|
27
27
|
function componentMember(kind, name, item, context) {
|
|
28
|
-
const location = { path:
|
|
28
|
+
const location = { path: appendPointer(ROOT_POINTER, ["components", kind, name]), schema: item };
|
|
29
29
|
const type = COMPONENT_TRANSFORMS[kind](item, location, context);
|
|
30
30
|
const custom = context.callbacks.transform(item, location);
|
|
31
31
|
const property = irProperty(toPropertyName(name), custom?.type ?? type, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.mjs","sources":["../../../../src/application/transform/document/components.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport {\n hasIdentifierStart,\n isReservedTypeName,\n withIdentifierParts,\n} from \"../../../domain/ir/identifier-text.js\";\nimport type {\n IrPropertySignature,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {\n COMPONENT_KINDS,\n type ComponentKind,\n type ComponentsObject,\n DECLARED_COMPONENT_KINDS,\n isEnumSchema,\n singularizeComponentKind,\n} from \"../../../domain/openapi/components-object.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { type DeprecatedEntryFilter, documentEntries } from \"../document-entries.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { schemaCommentOptionsOf, withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { headerType } from \"./header.js\";\nimport { contentEntryType } from \"./media-type.js\";\nimport { parameterType } from \"./parameter.js\";\nimport { pathItemType } from \"./path-item.js\";\nimport { requestBodyType } from \"./request-body.js\";\nimport { responseType } from \"./response.js\";\nimport { rootTypeAlias } from \"./root-type-aliases.js\";\n\ntype ComponentTransform = (\n item: never,\n location: SchemaLocation,\n context: TransformContext,\n) => IrType;\n\nconst COMPONENT_TRANSFORMS: Readonly<Record<ComponentKind, ComponentTransform>> = {\n schemas: transformSchema,\n responses: responseType,\n parameters: parameterType,\n requestBodies: requestBodyType,\n headers: headerType,\n pathItems: pathItemType,\n mediaTypes: contentEntryType,\n};\n\n/** The `components` type and the `--root-types` aliases. */\nexport interface ComponentsResult {\n readonly type: IrType;\n readonly rootTypes: readonly IrTypeAliasDeclaration[];\n}\n\n/** One component; the `transform` callback may replace its type, as for nested schemas. */\nfunction componentMember(\n kind: ComponentKind,\n name: string,\n item: unknown,\n context: TransformContext,\n): IrPropertySignature {\n const location = { path: createRef([\"components\", kind, name]), schema: item };\n const type = COMPONENT_TRANSFORMS[kind](item as never, location, context);\n const custom = context.callbacks.transform(item, location);\n const property = irProperty(toPropertyName(name), custom?.type ?? type, {\n isOptional: custom?.isOptional ?? false,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, item, schemaCommentOptionsOf(context.options.fixes));\n}\n\n/**\n * The root alias name: `SchemaPet`, `ResponseNotFound`, … A taken name gets `_2`, `_3`, … The\n * original checks for conflicts before it removes the schema prefix, and so does this; for a clash\n * of exported names see `addRootAlias`.\n *\n * The original could build a name that is no identifier, so the generated file did not parse\n * (research/legacy-bugs.md, item 16): a kept casing keeps spaces and symbols, which become `_`;\n * and a name without the prefix can start with a digit, so it keeps the prefix (`Schema1`). A\n * kept casing without the prefix can also give a reserved name (`void`, `class`), which keeps the\n * prefix too (`Schemavoid`).\n */\nfunction rootTypeName(\n kind: ComponentKind,\n name: string,\n aliases: Readonly<Record<string, IrTypeAliasDeclaration>>,\n context: TransformContext,\n): string {\n const { options, casing } = context;\n const prefix = casing.pascalCase(singularizeComponentKind(kind));\n const isSchema = kind === \"schemas\";\n const base = withIdentifierParts(\n options.rootTypesKeepCasing && isSchema ? name : casing.pascalCase(name),\n );\n const exportedName = (alias: string): string => {\n const unprefixed = alias.replace(prefix, \"\");\n const isUnprefixed = options.rootTypesNoSchemaPrefix && isSchema;\n const isTypeName = hasIdentifierStart(unprefixed) && !isReservedTypeName(unprefixed);\n return isUnprefixed && isTypeName ? unprefixed : alias;\n };\n let alias = `${prefix}${base}`;\n for (let counter = 2; aliases[alias] !== undefined; counter++) {\n alias = `${prefix}${base}_${counter}`;\n }\n return exportedName(alias);\n}\n\n/**\n * Add a root alias. When its exported name is taken (two schemas of one PascalCase name without\n * the prefix), the later schema takes the name, as in the original. Without the\n * `root-type-numbering` fix the earlier one then has no alias: that output is valid, so a number\n * for it would change it (backlog 30). With the fix the earlier alias is kept aside and follows\n * the others under the same name; `renameTakenAliases` numbers it once every name is known.\n */\nfunction addRootAlias(request: ComponentsRequest, alias: IrTypeAliasDeclaration): void {\n const { aliases, displaced } = request;\n const previous = aliases[alias.name];\n if (previous !== undefined && displaced !== null) {\n displaced.push(previous);\n }\n aliases[alias.name] = alias;\n}\n\n/** `--root-types` skips enum schemas under `--enum`: the enum itself is exported. */\nfunction hasRootType(kind: ComponentKind, item: unknown, context: TransformContext): boolean {\n const { options } = context;\n return options.rootTypes && !(options.enum && kind === \"schemas\" && isEnumSchema(item));\n}\n\n/** The components of one run, and the deprecated ones that kept output still references. */\ninterface ComponentsRequest {\n readonly components: ComponentsObject;\n readonly isKept: DeprecatedEntryFilter;\n readonly aliases: Record<string, IrTypeAliasDeclaration>;\n /** With the `root-type-numbering` fix: the aliases a later schema took the name of, in order. */\n readonly displaced: IrTypeAliasDeclaration[] | null;\n}\n\nfunction kindMember(\n kind: ComponentKind,\n request: ComponentsRequest,\n context: TransformContext,\n): IrPropertySignature {\n const { components, isKept, aliases } = request;\n const startedAt = context.diagnostics.now();\n const items: IrPropertySignature[] = [];\n for (const [name, item] of documentEntries(components[kind] ?? {}, context.options, isKept)) {\n items.push(componentMember(kind, name, item, context));\n if (hasRootType(kind, item, context)) {\n addRootAlias(request, rootTypeAlias(rootTypeName(kind, name, aliases, context), kind, name));\n }\n }\n const type = items.length > 0 ? irObject(items) : irKeyword(\"never\");\n context.diagnostics.debug(\n `Transformed components → ${kind}`,\n context.diagnostics.now() - startedAt,\n );\n return irProperty(toPropertyName(kind), type);\n}\n\n/**\n * The `components` interface body (OpenAPI 3.1 §4.8.7), one member per component kind. With\n * `--exclude-deprecated`, `kept` holds the deprecated components that kept output references\n * (`keptDeprecatedComponents`); they stay, so no reference names a missing key.\n */\nexport function componentsType(\n components: ComponentsObject,\n context: TransformContext,\n kept: ReadonlySet<object> = new Set(),\n): ComponentsResult {\n // A plain object, as in the original: its key order (integer-like names first) is the\n // output order.\n const aliases: Record<string, IrTypeAliasDeclaration> = {};\n const displaced = context.options.fixes.has(FIX.ROOT_TYPE_NUMBERING) ? [] : null;\n const isKept = (item: unknown) => kept.has(item as object);\n const request = { components, isKept, aliases, displaced };\n const declaredKinds = DECLARED_COMPONENT_KINDS.filter((kind) => components[kind] !== undefined);\n const members = [...COMPONENT_KINDS, ...declaredKinds].map((kind) =>\n kindMember(kind, request, context),\n );\n const rootTypes = Object.values(aliases);\n return {\n type: irObject(members),\n rootTypes: [...rootTypes, ...(displaced ?? [])],\n };\n}\n"],"names":["alias"],"mappings":";;;;;;;;;;;;;;;;;AAyCA,MAAM,oBAAA,GAA4E;AAAA,EAChF,OAAA,EAAS,eAAA;AAAA,EACT,SAAA,EAAW,YAAA;AAAA,EACX,UAAA,EAAY,aAAA;AAAA,EACZ,aAAA,EAAe,eAAA;AAAA,EACf,OAAA,EAAS,UAA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MAAM,MAAA,GAAS,CAAC,IAAA,KAAkB,IAAA,CAAK,IAAI,IAAc,CAAA;AACzD,EAAA,MAAM,OAAA,GAAU,EAAE,UAAA,EAAY,MAAA,EAAQ,SAAS,SAAA,EAAU;AACzD,EAAA,MAAM,aAAA,GAAgB,yBAAyB,MAAA,CAAO,CAAC,SAAS,UAAA,CAAW,IAAI,MAAM,MAAS,CAAA;AAC9F,EAAA,MAAM,UAAU,CAAC,GAAG,eAAA,EAAiB,GAAG,aAAa,CAAA,CAAE,GAAA;AAAA,IAAI,CAAC,IAAA,KAC1D,UAAA,CAAW,IAAA,EAAM,SAAS,OAAO;AAAA,GACnC;AACA,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,MAAA,CAAO,OAAO,CAAA;AACvC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,SAAS,OAAO,CAAA;AAAA,IACtB,WAAW,CAAC,GAAG,WAAW,GAAI,SAAA,IAAa,EAAG;AAAA,GAChD;AACF;;"}
|
|
1
|
+
{"version":3,"file":"components.mjs","sources":["../../../../src/application/transform/document/components.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport {\n hasIdentifierStart,\n isReservedTypeName,\n withIdentifierParts,\n} from \"../../../domain/ir/identifier-text.js\";\nimport type {\n IrPropertySignature,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {\n COMPONENT_KINDS,\n type ComponentKind,\n type ComponentsObject,\n DECLARED_COMPONENT_KINDS,\n isEnumSchema,\n singularizeComponentKind,\n} from \"../../../domain/openapi/components-object.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { type DeprecatedEntryFilter, documentEntries } from \"../document-entries.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { schemaCommentOptionsOf, withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { headerType } from \"./header.js\";\nimport { contentEntryType } from \"./media-type.js\";\nimport { parameterType } from \"./parameter.js\";\nimport { pathItemType } from \"./path-item.js\";\nimport { requestBodyType } from \"./request-body.js\";\nimport { responseType } from \"./response.js\";\nimport { rootTypeAlias } from \"./root-type-aliases.js\";\n\ntype ComponentTransform = (\n item: never,\n location: SchemaLocation,\n context: TransformContext,\n) => IrType;\n\nconst COMPONENT_TRANSFORMS: Readonly<Record<ComponentKind, ComponentTransform>> = {\n schemas: transformSchema,\n responses: responseType,\n parameters: parameterType,\n requestBodies: requestBodyType,\n headers: headerType,\n pathItems: pathItemType,\n mediaTypes: contentEntryType,\n};\n\n/** The `components` type and the `--root-types` aliases. */\nexport interface ComponentsResult {\n readonly type: IrType;\n readonly rootTypes: readonly IrTypeAliasDeclaration[];\n}\n\n/** One component; the `transform` callback may replace its type, as for nested schemas. */\nfunction componentMember(\n kind: ComponentKind,\n name: string,\n item: unknown,\n context: TransformContext,\n): IrPropertySignature {\n const location = { path: appendPointer(ROOT_POINTER, [\"components\", kind, name]), schema: item };\n const type = COMPONENT_TRANSFORMS[kind](item as never, location, context);\n const custom = context.callbacks.transform(item, location);\n const property = irProperty(toPropertyName(name), custom?.type ?? type, {\n isOptional: custom?.isOptional ?? false,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, item, schemaCommentOptionsOf(context.options.fixes));\n}\n\n/**\n * The root alias name: `SchemaPet`, `ResponseNotFound`, … A taken name gets `_2`, `_3`, … The\n * original checks for conflicts before it removes the schema prefix, and so does this; for a clash\n * of exported names see `addRootAlias`.\n *\n * The original could build a name that is no identifier, so the generated file did not parse\n * (research/legacy-bugs.md, item 16): a kept casing keeps spaces and symbols, which become `_`;\n * and a name without the prefix can start with a digit, so it keeps the prefix (`Schema1`). A\n * kept casing without the prefix can also give a reserved name (`void`, `class`), which keeps the\n * prefix too (`Schemavoid`).\n */\nfunction rootTypeName(\n kind: ComponentKind,\n name: string,\n aliases: Readonly<Record<string, IrTypeAliasDeclaration>>,\n context: TransformContext,\n): string {\n const { options, casing } = context;\n const prefix = casing.pascalCase(singularizeComponentKind(kind));\n const isSchema = kind === \"schemas\";\n const base = withIdentifierParts(\n options.rootTypesKeepCasing && isSchema ? name : casing.pascalCase(name),\n );\n const exportedName = (alias: string): string => {\n const unprefixed = alias.replace(prefix, \"\");\n const isUnprefixed = options.rootTypesNoSchemaPrefix && isSchema;\n const isTypeName = hasIdentifierStart(unprefixed) && !isReservedTypeName(unprefixed);\n return isUnprefixed && isTypeName ? unprefixed : alias;\n };\n let alias = `${prefix}${base}`;\n for (let counter = 2; aliases[alias] !== undefined; counter++) {\n alias = `${prefix}${base}_${counter}`;\n }\n return exportedName(alias);\n}\n\n/**\n * Add a root alias. When its exported name is taken (two schemas of one PascalCase name without\n * the prefix), the later schema takes the name, as in the original. Without the\n * `root-type-numbering` fix the earlier one then has no alias: that output is valid, so a number\n * for it would change it (backlog 30). With the fix the earlier alias is kept aside and follows\n * the others under the same name; `renameTakenAliases` numbers it once every name is known.\n */\nfunction addRootAlias(request: ComponentsRequest, alias: IrTypeAliasDeclaration): void {\n const { aliases, displaced } = request;\n const previous = aliases[alias.name];\n if (previous !== undefined && displaced !== null) {\n displaced.push(previous);\n }\n aliases[alias.name] = alias;\n}\n\n/** `--root-types` skips enum schemas under `--enum`: the enum itself is exported. */\nfunction hasRootType(kind: ComponentKind, item: unknown, context: TransformContext): boolean {\n const { options } = context;\n return options.rootTypes && !(options.enum && kind === \"schemas\" && isEnumSchema(item));\n}\n\n/** The components of one run, and the deprecated ones that kept output still references. */\ninterface ComponentsRequest {\n readonly components: ComponentsObject;\n readonly isKept: DeprecatedEntryFilter;\n readonly aliases: Record<string, IrTypeAliasDeclaration>;\n /** With the `root-type-numbering` fix: the aliases a later schema took the name of, in order. */\n readonly displaced: IrTypeAliasDeclaration[] | null;\n}\n\nfunction kindMember(\n kind: ComponentKind,\n request: ComponentsRequest,\n context: TransformContext,\n): IrPropertySignature {\n const { components, isKept, aliases } = request;\n const startedAt = context.diagnostics.now();\n const items: IrPropertySignature[] = [];\n for (const [name, item] of documentEntries(components[kind] ?? {}, context.options, isKept)) {\n items.push(componentMember(kind, name, item, context));\n if (hasRootType(kind, item, context)) {\n addRootAlias(request, rootTypeAlias(rootTypeName(kind, name, aliases, context), kind, name));\n }\n }\n const type = items.length > 0 ? irObject(items) : irKeyword(\"never\");\n context.diagnostics.debug(\n `Transformed components → ${kind}`,\n context.diagnostics.now() - startedAt,\n );\n return irProperty(toPropertyName(kind), type);\n}\n\n/**\n * The `components` interface body (OpenAPI 3.1 §4.8.7), one member per component kind. With\n * `--exclude-deprecated`, `kept` holds the deprecated components that kept output references\n * (`keptDeprecatedComponents`); they stay, so no reference names a missing key.\n */\nexport function componentsType(\n components: ComponentsObject,\n context: TransformContext,\n kept: ReadonlySet<object> = new Set(),\n): ComponentsResult {\n // A plain object, as in the original: its key order (integer-like names first) is the\n // output order.\n const aliases: Record<string, IrTypeAliasDeclaration> = {};\n const displaced = context.options.fixes.has(FIX.ROOT_TYPE_NUMBERING) ? [] : null;\n const isKept = (item: unknown) => kept.has(item as object);\n const request = { components, isKept, aliases, displaced };\n const declaredKinds = DECLARED_COMPONENT_KINDS.filter((kind) => components[kind] !== undefined);\n const members = [...COMPONENT_KINDS, ...declaredKinds].map((kind) =>\n kindMember(kind, request, context),\n );\n const rootTypes = Object.values(aliases);\n return {\n type: irObject(members),\n rootTypes: [...rootTypes, ...(displaced ?? [])],\n };\n}\n"],"names":["alias"],"mappings":";;;;;;;;;;;;;;;;;AAyCA,MAAM,oBAAA,GAA4E;AAAA,EAChF,OAAA,EAAS,eAAA;AAAA,EACT,SAAA,EAAW,YAAA;AAAA,EACX,UAAA,EAAY,aAAA;AAAA,EACZ,aAAA,EAAe,eAAA;AAAA,EACf,OAAA,EAAS,UAAA;AAAA,EACT,SAAA,EAAW,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AAS,CAAC,IAAA,KAAkB,IAAA,CAAK,IAAI,IAAc,CAAA;AACzD,EAAA,MAAM,OAAA,GAAU,EAAE,UAAA,EAAY,MAAA,EAAQ,SAAS,SAAA,EAAU;AACzD,EAAA,MAAM,aAAA,GAAgB,yBAAyB,MAAA,CAAO,CAAC,SAAS,UAAA,CAAW,IAAI,MAAM,MAAS,CAAA;AAC9F,EAAA,MAAM,UAAU,CAAC,GAAG,eAAA,EAAiB,GAAG,aAAa,CAAA,CAAE,GAAA;AAAA,IAAI,CAAC,IAAA,KAC1D,UAAA,CAAW,IAAA,EAAM,SAAS,OAAO;AAAA,GACnC;AACA,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,MAAA,CAAO,OAAO,CAAA;AACvC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,SAAS,OAAO,CAAA;AAAA,IACtB,WAAW,CAAC,GAAG,WAAW,GAAI,SAAA,IAAa,EAAG;AAAA,GAChD;AACF;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const RAW_TYPE_DECLARATION_RE = /^(?:export\s+)?(?:declare\s+)?(?:type|interface|enum|const\s+enum|class)\s+([A-Za-z_$][\w$]*)/gm;
|
|
4
|
+
function typeNamesInText(text) {
|
|
5
|
+
return [...text.matchAll(RAW_TYPE_DECLARATION_RE)].map((match) => match[1] ?? "");
|
|
6
|
+
}
|
|
7
|
+
function typeNamesOf(declaration) {
|
|
8
|
+
switch (declaration.kind) {
|
|
9
|
+
case "rawDeclaration":
|
|
10
|
+
return declaration.name === void 0 ? typeNamesInText(declaration.text) : [declaration.name];
|
|
11
|
+
case "constArray":
|
|
12
|
+
return [];
|
|
13
|
+
default:
|
|
14
|
+
return [declaration.name];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function typeNamesDeclaredBy(declarations) {
|
|
18
|
+
return new Set(declarations.flatMap(typeNamesOf));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.typeNamesDeclaredBy = typeNamesDeclaredBy;
|
|
22
|
+
exports.typeNamesInText = typeNamesInText;
|
|
23
|
+
//# sourceMappingURL=declared-type-names.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declared-type-names.cjs","sources":["../../../../src/application/transform/document/declared-type-names.ts"],"sourcesContent":["import type { IrDeclaration } from \"../../../domain/ir/nodes.js\";\n\n/**\n * The type names that declarations of the output take. Two declarations of one type name do not\n * compile (TS2300, TS2567), or merge into one type without an error (two enums, two interfaces).\n */\n\n/**\n * A declaration at the start of a line of raw text: the helper types, the `--read-write-markers`\n * types, `inject` text and footer nodes from user code. A `const` lives in the value namespace.\n */\nconst RAW_TYPE_DECLARATION_RE =\n /^(?:export\\s+)?(?:declare\\s+)?(?:type|interface|enum|const\\s+enum|class)\\s+([A-Za-z_$][\\w$]*)/gm;\n\n/** The type names that raw declaration text declares. */\nexport function typeNamesInText(text: string): string[] {\n return [...text.matchAll(RAW_TYPE_DECLARATION_RE)].map((match) => match[1] ?? \"\");\n}\n\nfunction typeNamesOf(declaration: IrDeclaration): readonly string[] {\n switch (declaration.kind) {\n case \"rawDeclaration\":\n return declaration.name === undefined\n ? typeNamesInText(declaration.text)\n : [declaration.name];\n case \"constArray\":\n return [];\n default:\n return [declaration.name];\n }\n}\n\n/** Every type name the declarations take; `--enum-values` arrays are values, so they take none. */\nexport function typeNamesDeclaredBy(declarations: readonly IrDeclaration[]): Set<string> {\n return new Set(declarations.flatMap(typeNamesOf));\n}\n"],"names":[],"mappings":";;AAWA,MAAM,uBAAA,GACJ,iGAAA;AAGK,SAAS,gBAAgB,IAAA,EAAwB;AACtD,EAAA,OAAO,CAAC,GAAG,IAAA,CAAK,QAAA,CAAS,uBAAuB,CAAC,CAAA,CAAE,GAAA,CAAI,CAAC,KAAA,KAAU,KAAA,CAAM,CAAC,KAAK,EAAE,CAAA;AAClF;AAEA,SAAS,YAAY,WAAA,EAA+C;AAClE,EAAA,QAAQ,YAAY,IAAA;AAAM,IACxB,KAAK,gBAAA;AACH,MAAA,OAAO,WAAA,CAAY,SAAS,MAAA,GACxB,eAAA,CAAgB,YAAY,IAAI,CAAA,GAChC,CAAC,WAAA,CAAY,IAAI,CAAA;AAAA,IACvB,KAAK,YAAA;AACH,MAAA,OAAO,EAAC;AAAA,IACV;AACE,MAAA,OAAO,CAAC,YAAY,IAAI,CAAA;AAAA;AAE9B;AAGO,SAAS,oBAAoB,YAAA,EAAqD;AACvF,EAAA,OAAO,IAAI,GAAA,CAAI,YAAA,CAAa,OAAA,CAAQ,WAAW,CAAC,CAAA;AAClD;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const RAW_TYPE_DECLARATION_RE = /^(?:export\s+)?(?:declare\s+)?(?:type|interface|enum|const\s+enum|class)\s+([A-Za-z_$][\w$]*)/gm;
|
|
2
|
+
function typeNamesInText(text) {
|
|
3
|
+
return [...text.matchAll(RAW_TYPE_DECLARATION_RE)].map((match) => match[1] ?? "");
|
|
4
|
+
}
|
|
5
|
+
function typeNamesOf(declaration) {
|
|
6
|
+
switch (declaration.kind) {
|
|
7
|
+
case "rawDeclaration":
|
|
8
|
+
return declaration.name === void 0 ? typeNamesInText(declaration.text) : [declaration.name];
|
|
9
|
+
case "constArray":
|
|
10
|
+
return [];
|
|
11
|
+
default:
|
|
12
|
+
return [declaration.name];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function typeNamesDeclaredBy(declarations) {
|
|
16
|
+
return new Set(declarations.flatMap(typeNamesOf));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { typeNamesDeclaredBy, typeNamesInText };
|
|
20
|
+
//# sourceMappingURL=declared-type-names.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declared-type-names.mjs","sources":["../../../../src/application/transform/document/declared-type-names.ts"],"sourcesContent":["import type { IrDeclaration } from \"../../../domain/ir/nodes.js\";\n\n/**\n * The type names that declarations of the output take. Two declarations of one type name do not\n * compile (TS2300, TS2567), or merge into one type without an error (two enums, two interfaces).\n */\n\n/**\n * A declaration at the start of a line of raw text: the helper types, the `--read-write-markers`\n * types, `inject` text and footer nodes from user code. A `const` lives in the value namespace.\n */\nconst RAW_TYPE_DECLARATION_RE =\n /^(?:export\\s+)?(?:declare\\s+)?(?:type|interface|enum|const\\s+enum|class)\\s+([A-Za-z_$][\\w$]*)/gm;\n\n/** The type names that raw declaration text declares. */\nexport function typeNamesInText(text: string): string[] {\n return [...text.matchAll(RAW_TYPE_DECLARATION_RE)].map((match) => match[1] ?? \"\");\n}\n\nfunction typeNamesOf(declaration: IrDeclaration): readonly string[] {\n switch (declaration.kind) {\n case \"rawDeclaration\":\n return declaration.name === undefined\n ? typeNamesInText(declaration.text)\n : [declaration.name];\n case \"constArray\":\n return [];\n default:\n return [declaration.name];\n }\n}\n\n/** Every type name the declarations take; `--enum-values` arrays are values, so they take none. */\nexport function typeNamesDeclaredBy(declarations: readonly IrDeclaration[]): Set<string> {\n return new Set(declarations.flatMap(typeNamesOf));\n}\n"],"names":[],"mappings":"AAWA,MAAM,uBAAA,GACJ,iGAAA;AAGK,SAAS,gBAAgB,IAAA,EAAwB;AACtD,EAAA,OAAO,CAAC,GAAG,IAAA,CAAK,QAAA,CAAS,uBAAuB,CAAC,CAAA,CAAE,GAAA,CAAI,CAAC,KAAA,KAAU,KAAA,CAAM,CAAC,KAAK,EAAE,CAAA;AAClF;AAEA,SAAS,YAAY,WAAA,EAA+C;AAClE,EAAA,QAAQ,YAAY,IAAA;AAAM,IACxB,KAAK,gBAAA;AACH,MAAA,OAAO,WAAA,CAAY,SAAS,MAAA,GACxB,eAAA,CAAgB,YAAY,IAAI,CAAA,GAChC,CAAC,WAAA,CAAY,IAAI,CAAA;AAAA,IACvB,KAAK,YAAA;AACH,MAAA,OAAO,EAAC;AAAA,IACV;AACE,MAAA,OAAO,CAAC,YAAY,IAAI,CAAA;AAAA;AAE9B;AAGO,SAAS,oBAAoB,YAAA,EAAqD;AACvF,EAAA,OAAO,IAAI,GAAA,CAAI,YAAA,CAAa,OAAA,CAAQ,WAAW,CAAC,CAAA;AAClD;;"}
|
|
@@ -7,7 +7,7 @@ const schemaTransform = require('../schema/schema-transform.cjs');
|
|
|
7
7
|
|
|
8
8
|
function defsRootType(defs, context) {
|
|
9
9
|
const members = Object.entries(defs).map(([name, schema]) => {
|
|
10
|
-
const location = { path: jsonPointer.
|
|
10
|
+
const location = { path: jsonPointer.appendPointer(jsonPointer.ROOT_POINTER, ["$defs", name]), schema };
|
|
11
11
|
const type = schemaTransform.transformSchema(schema, location, context);
|
|
12
12
|
return constructors.irProperty(propertyName.toPropertyName(name), type, { isReadonly: context.options.immutable });
|
|
13
13
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defs-root.cjs","sources":["../../../../src/application/transform/document/defs-root.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrObjectType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"defs-root.cjs","sources":["../../../../src/application/transform/document/defs-root.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrObjectType } 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 { Schema } from \"../../../domain/openapi/schema-object.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport type { TransformContext } from \"../transform-context.js\";\n\n/**\n * The root `$defs` type: one required member per named subschema, so `#/$defs/<name>` refs\n * (`$defs[\"<name>\"]`) resolve. The original transformed the whole `$defs` map as one schema,\n * which gave `Record<string, never>` and made every such ref `never` (research/legacy-bugs.md,\n * item 18).\n */\nexport function defsRootType(\n defs: Readonly<Record<string, Schema>>,\n context: TransformContext,\n): IrObjectType {\n const members = Object.entries(defs).map(([name, schema]) => {\n const location = { path: appendPointer(ROOT_POINTER, [\"$defs\", name]), schema };\n const type = transformSchema(schema, location, context);\n return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n"],"names":["appendPointer","ROOT_POINTER","transformSchema","irProperty","toPropertyName","irObject"],"mappings":";;;;;;;AAcO,SAAS,YAAA,CACd,MACA,OAAA,EACc;AACd,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,CAAE,IAAI,CAAC,CAAC,IAAA,EAAM,MAAM,CAAA,KAAM;AAC3D,IAAA,MAAM,QAAA,GAAW,EAAE,IAAA,EAAMA,yBAAA,CAAcC,wBAAA,EAAc,CAAC,OAAA,EAAS,IAAI,CAAC,CAAA,EAAG,MAAA,EAAO;AAC9E,IAAA,MAAM,IAAA,GAAOC,+BAAA,CAAgB,MAAA,EAAQ,QAAA,EAAU,OAAO,CAAA;AACtD,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;;"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { irProperty, irObject } from '../../../domain/ir/constructors.mjs';
|
|
2
2
|
import { toPropertyName } from '../../../domain/ir/property-name.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { appendPointer, ROOT_POINTER } from '../../../domain/openapi/json-pointer.mjs';
|
|
4
4
|
import { transformSchema } from '../schema/schema-transform.mjs';
|
|
5
5
|
|
|
6
6
|
function defsRootType(defs, context) {
|
|
7
7
|
const members = Object.entries(defs).map(([name, schema]) => {
|
|
8
|
-
const location = { path:
|
|
8
|
+
const location = { path: appendPointer(ROOT_POINTER, ["$defs", name]), schema };
|
|
9
9
|
const type = transformSchema(schema, location, context);
|
|
10
10
|
return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });
|
|
11
11
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defs-root.mjs","sources":["../../../../src/application/transform/document/defs-root.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrObjectType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"defs-root.mjs","sources":["../../../../src/application/transform/document/defs-root.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrObjectType } 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 { Schema } from \"../../../domain/openapi/schema-object.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport type { TransformContext } from \"../transform-context.js\";\n\n/**\n * The root `$defs` type: one required member per named subschema, so `#/$defs/<name>` refs\n * (`$defs[\"<name>\"]`) resolve. The original transformed the whole `$defs` map as one schema,\n * which gave `Record<string, never>` and made every such ref `never` (research/legacy-bugs.md,\n * item 18).\n */\nexport function defsRootType(\n defs: Readonly<Record<string, Schema>>,\n context: TransformContext,\n): IrObjectType {\n const members = Object.entries(defs).map(([name, schema]) => {\n const location = { path: appendPointer(ROOT_POINTER, [\"$defs\", name]), schema };\n const type = transformSchema(schema, location, context);\n return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n"],"names":[],"mappings":";;;;;AAcO,SAAS,YAAA,CACd,MACA,OAAA,EACc;AACd,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,CAAE,IAAI,CAAC,CAAC,IAAA,EAAM,MAAM,CAAA,KAAM;AAC3D,IAAA,MAAM,QAAA,GAAW,EAAE,IAAA,EAAM,aAAA,CAAc,YAAA,EAAc,CAAC,OAAA,EAAS,IAAI,CAAC,CAAA,EAAG,MAAA,EAAO;AAC9E,IAAA,MAAM,IAAA,GAAO,eAAA,CAAgB,MAAA,EAAQ,QAAA,EAAU,OAAO,CAAA;AACtD,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;;"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const appendAll = require('../../../domain/append-all.cjs');
|
|
3
4
|
const constructors = require('../../../domain/ir/constructors.cjs');
|
|
4
5
|
const helperTypes = require('../helper-types.cjs');
|
|
5
6
|
const components = require('./components.cjs');
|
|
6
7
|
const declaredTypes = require('./declared-types.cjs');
|
|
7
8
|
const defsRoot = require('./defs-root.cjs');
|
|
8
9
|
const keptDeprecated$1 = require('./kept-deprecated.cjs');
|
|
10
|
+
const pathItem = require('./path-item.cjs');
|
|
9
11
|
const paths = require('./paths.cjs');
|
|
10
12
|
const pathsEnum = require('./paths-enum.cjs');
|
|
11
13
|
const webhooks = require('./webhooks.cjs');
|
|
@@ -90,7 +92,7 @@ function documentBody(document, context, footer = NO_FOOTER) {
|
|
|
90
92
|
if (inject !== "") {
|
|
91
93
|
declarations.push({ kind: "rawDeclaration", text: inject });
|
|
92
94
|
}
|
|
93
|
-
|
|
95
|
+
appendAll.appendAll(declarations, rootsDeclarations(document, context, footer));
|
|
94
96
|
return declarations;
|
|
95
97
|
}
|
|
96
98
|
function documentClosing(document, context, hasOperations) {
|
|
@@ -99,11 +101,14 @@ function documentClosing(document, context, hasOperations) {
|
|
|
99
101
|
declarations.push(emptyAlias(OPERATIONS_NAME));
|
|
100
102
|
}
|
|
101
103
|
if (context.options.makePathsEnum && document.paths) {
|
|
102
|
-
|
|
104
|
+
const isIncluded = (operation) => pathItem.isIncludedOperation(operation, context);
|
|
105
|
+
declarations.push(pathsEnum.apiPathsEnumDeclaration(document.paths, isIncluded));
|
|
103
106
|
}
|
|
104
107
|
return declarations;
|
|
105
108
|
}
|
|
106
109
|
|
|
110
|
+
exports.OPERATIONS_NAME = OPERATIONS_NAME;
|
|
111
|
+
exports.ROOT_KEYS = ROOT_KEYS;
|
|
107
112
|
exports.documentBody = documentBody;
|
|
108
113
|
exports.documentClosing = documentClosing;
|
|
109
114
|
//# sourceMappingURL=document.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.cjs","sources":["../../../../src/application/transform/document/document.ts"],"sourcesContent":["import { irKeyword, irObject, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrIntersectionType,\n IrObjectType,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport type { ComponentsObject } from \"../../../domain/openapi/components-object.js\";\nimport type { DocumentObject } from \"../../../domain/openapi/document-object.js\";\nimport type { PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { READ_WRITE_MARKER_TYPES } from \"../helper-types.js\";\nimport type { TransformContext, TransformOptions } from \"../transform-context.js\";\nimport { componentsType } from \"./components.js\";\nimport { type DeclaredTypeLookup, declaredTypeLookup } from \"./declared-types.js\";\nimport { defsRootType } from \"./defs-root.js\";\nimport { keptDeprecatedComponents } from \"./kept-deprecated.js\";\nimport { pathMembers, pathsObjectType } from \"./paths.js\";\nimport { apiPathsEnumDeclaration } from \"./paths-enum.js\";\nimport { webhooksType } from \"./webhooks.js\";\n\n/** The root types, in output order. */\nconst ROOT_KEYS = Object.freeze([\"paths\", \"webhooks\", \"components\", \"$defs\"] as const);\ntype RootKey = (typeof ROOT_KEYS)[number];\n\nconst OPERATIONS_NAME = \"operations\";\n/** The type of a root without members: `Record<string, never>`. */\nconst EMPTY_ROOT_TYPE = irRecord(irKeyword(\"string\"), irKeyword(\"never\"));\n\n/** A root's type and the declarations that follow it (the `--root-types` aliases). */\ninterface RootResult {\n readonly type: IrType;\n readonly aliases: readonly IrTypeAliasDeclaration[];\n /**\n * The root's final type, for a root that reads the types the whole file declares (`paths`, whose\n * overlap check follows references). `type` then only tells whether the root has members.\n */\n readonly withDeclaredTypes?: (lookup: DeclaredTypeLookup) => IrType;\n}\n\ntype RootTransform = (\n node: object,\n context: TransformContext,\n document: DocumentObject,\n) => RootResult;\n\n/** Without `--exclude-deprecated` nothing is left out, so the scan is skipped. */\nfunction keptDeprecated(document: DocumentObject, context: TransformContext): ReadonlySet<object> {\n return context.options.excludeDeprecated\n ? keptDeprecatedComponents(document, context.refs)\n : new Set();\n}\n\nconst ROOT_TRANSFORMS: Readonly<Record<RootKey, RootTransform>> = {\n paths: (node, context) => {\n const members = pathMembers(node as PathsObject, context);\n return {\n type: irObject(members.map(({ member }) => member)),\n aliases: [],\n withDeclaredTypes: (lookup) => pathsObjectType(members, lookup),\n };\n },\n webhooks: (node, context) => ({ type: webhooksType(node as PathsObject, context), aliases: [] }),\n components: (node, context, document) => {\n const kept = keptDeprecated(document, context);\n const { type, rootTypes } = componentsType(node as ComponentsObject, context, kept);\n return { type, aliases: rootTypes };\n },\n $defs: (node, context) => ({\n type: defsRootType(node as NonNullable<DocumentObject[\"$defs\"]>, context),\n aliases: [],\n }),\n};\n\nfunction emptyAlias(name: string): IrTypeAliasDeclaration {\n return { kind: \"typeAlias\", name, isExported: true, type: EMPTY_ROOT_TYPE, comments: [] };\n}\n\n/** A root type that declares something: an object with members, or an intersection of them. */\ntype RootBodyType = IrObjectType | IrIntersectionType;\n\nfunction isRootBody(type: IrType): type is RootBodyType {\n return (type.kind === \"object\" && type.members.length > 0) || type.kind === \"intersection\";\n}\n\n/**\n * A root with members: an interface, or a type alias with `--export-type`. An intersection (the\n * `paths` of overlapping `--path-params-as-types` keys) can only be a type alias.\n */\nfunction rootDeclaration(\n name: RootKey,\n type: RootBodyType,\n options: TransformOptions,\n): IrDeclaration {\n return options.exportType || type.kind === \"intersection\"\n ? { kind: \"typeAlias\", name, isExported: true, type, comments: [] }\n : { kind: \"interface\", name, isExported: true, members: type.members, comments: [] };\n}\n\n/**\n * The declarations of one root: its type, then its aliases. `finish` gives the root's declaration\n * again from the types the whole file declares, for a root with `withDeclaredTypes`.\n */\ninterface RootDeclarations {\n readonly declarations: readonly IrDeclaration[];\n readonly finish?: (lookup: DeclaredTypeLookup) => IrDeclaration;\n}\n\n/**\n * The declarations of one root. A root that is missing, or whose type has no members, is\n * `Record<string, never>`. Only an object type (or the `paths` intersection) counts as having\n * members: a callback type the IR keeps as raw text does not (ADR-004).\n */\nfunction rootDeclarations(\n root: RootKey,\n document: DocumentObject,\n context: TransformContext,\n): RootDeclarations {\n const node: unknown = document[root];\n if (!node || typeof node !== \"object\") {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root)] };\n }\n const startedAt = context.diagnostics.now();\n const { type, aliases, withDeclaredTypes } = ROOT_TRANSFORMS[root](node, context, document);\n if (!isRootBody(type)) {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root), ...aliases] };\n }\n const declaration = rootDeclaration(root, type, context.options);\n context.diagnostics.debug(`${root} done`, context.diagnostics.now() - startedAt);\n const finish =\n withDeclaredTypes &&\n ((lookup: DeclaredTypeLookup) => {\n const finished = withDeclaredTypes(lookup);\n return isRootBody(finished) ? rootDeclaration(root, finished, context.options) : declaration;\n });\n return { declarations: [declaration, ...aliases], ...(finish ? { finish } : {}) };\n}\n\n/**\n * Every root's declarations in output order. A root with `finish` gets its declaration from the\n * types of the other roots and of the footer (the `operations` interface), which exist only once\n * every root is transformed.\n */\nfunction rootsDeclarations(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[],\n): IrDeclaration[] {\n const roots = ROOT_KEYS.map((root) => rootDeclarations(root, document, context));\n const transformed = roots.flatMap(({ declarations }) => declarations);\n if (roots.every(({ finish }) => finish === undefined)) {\n return transformed;\n }\n const lookup = declaredTypeLookup([...transformed, ...footer()]);\n return roots.flatMap(({ declarations, finish }) => {\n const [declaration, ...aliases] = declarations;\n return finish === undefined || declaration === undefined\n ? declarations\n : [finish(lookup), ...aliases];\n });\n}\n\n/**\n * The `inject` text as written (ADR-010, decision 4), without the blank lines around it. The\n * original reprinted it with the TypeScript printer; text without code printed nothing then.\n */\nfunction withoutBlankLinesAround(text: string): string {\n return text.replace(/^(?:[ \\t]*\\r?\\n)+/, \"\").trimEnd();\n}\n\n/** No footer declarations: the roots' references to `operations` stay unresolved. */\nconst NO_FOOTER = (): readonly IrDeclaration[] => [];\n\n/**\n * The document's declarations before the footer: helper types, injected code, then one root type\n * per root key with the aliases that follow it. `footer` reads the footer's declarations once the\n * roots are transformed.\n */\nexport function documentBody(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[] = NO_FOOTER,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (context.options.readWriteMarkers) {\n declarations.push({ kind: \"rawDeclaration\", text: READ_WRITE_MARKER_TYPES });\n }\n const inject = withoutBlankLinesAround(context.options.inject ?? \"\");\n if (inject !== \"\") {\n declarations.push({ kind: \"rawDeclaration\", text: inject });\n }\n declarations.push(...rootsDeclarations(document, context, footer));\n return declarations;\n}\n\n/**\n * The declarations after the footer: an empty `operations` type when the footer has no\n * operations, and the `--make-paths-enum` enum.\n */\nexport function documentClosing(\n document: DocumentObject,\n context: TransformContext,\n hasOperations: boolean,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (!hasOperations) {\n declarations.push(emptyAlias(OPERATIONS_NAME));\n }\n if (context.options.makePathsEnum && document.paths) {\n declarations.push(apiPathsEnumDeclaration(document.paths));\n }\n return declarations;\n}\n"],"names":["irRecord","irKeyword","keptDeprecatedComponents","pathMembers","irObject","pathsObjectType","webhooksType","componentsType","defsRootType","declaredTypeL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AAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,QAAQ,CAAA;AAAA,EAC5D;AACA,EAAA,YAAA,CAAa,KAAK,GAAG,iBAAA,CAAkB,QAAA,EAAU,OAAA,EAAS,MAAM,CAAC,CAAA;AACjE,EAAA,OAAO,YAAA;AACT;AAMO,SAAS,eAAA,CACd,QAAA,EACA,OAAA,EACA,aAAA,EACiB;AACjB,EAAA,MAAM,eAAgC,EAAC;AACvC,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,YAAA,CAAa,IAAA,CAAK,UAAA,CAAW,eAAe,CAAC,CAAA;AAAA,EAC/C;AACA,EAAA,IAAI,OAAA,CAAQ,OAAA,CAAQ,aAAA,IAAiB,QAAA,CAAS,KAAA,EAAO;AACnD,IAAA,YAAA,CAAa,IAAA,CAAKC,iCAAA,CAAwB,QAAA,CAAS,KAAK,CAAC,CAAA;AAAA,EAC3D;AACA,EAAA,OAAO,YAAA;AACT;;;"}
|
|
1
|
+
{"version":3,"file":"document.cjs","sources":["../../../../src/application/transform/document/document.ts"],"sourcesContent":["import { appendAll } from \"../../../domain/append-all.js\";\nimport { irKeyword, irObject, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrIntersectionType,\n IrObjectType,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport type { ComponentsObject } from \"../../../domain/openapi/components-object.js\";\nimport type { DocumentObject } from \"../../../domain/openapi/document-object.js\";\nimport type { OperationEntry, PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { READ_WRITE_MARKER_TYPES } from \"../helper-types.js\";\nimport type { TransformContext, TransformOptions } from \"../transform-context.js\";\nimport { componentsType } from \"./components.js\";\nimport { type DeclaredTypeLookup, declaredTypeLookup } from \"./declared-types.js\";\nimport { defsRootType } from \"./defs-root.js\";\nimport { keptDeprecatedComponents } from \"./kept-deprecated.js\";\nimport { isIncludedOperation } from \"./path-item.js\";\nimport { pathMembers, pathsObjectType } from \"./paths.js\";\nimport { apiPathsEnumDeclaration } from \"./paths-enum.js\";\nimport { webhooksType } from \"./webhooks.js\";\n\n/** The root types, in output order. */\nexport const ROOT_KEYS = Object.freeze([\"paths\", \"webhooks\", \"components\", \"$defs\"] as const);\ntype RootKey = (typeof ROOT_KEYS)[number];\n\nexport const OPERATIONS_NAME = \"operations\";\n/** The type of a root without members: `Record<string, never>`. */\nconst EMPTY_ROOT_TYPE = irRecord(irKeyword(\"string\"), irKeyword(\"never\"));\n\n/** A root's type and the declarations that follow it (the `--root-types` aliases). */\ninterface RootResult {\n readonly type: IrType;\n readonly aliases: readonly IrTypeAliasDeclaration[];\n /**\n * The root's final type, for a root that reads the types the whole file declares (`paths`, whose\n * overlap check follows references). `type` then only tells whether the root has members.\n */\n readonly withDeclaredTypes?: (lookup: DeclaredTypeLookup) => IrType;\n}\n\ntype RootTransform = (\n node: object,\n context: TransformContext,\n document: DocumentObject,\n) => RootResult;\n\n/** Without `--exclude-deprecated` nothing is left out, so the scan is skipped. */\nfunction keptDeprecated(document: DocumentObject, context: TransformContext): ReadonlySet<object> {\n return context.options.excludeDeprecated\n ? keptDeprecatedComponents(document, context.refs)\n : new Set();\n}\n\nconst ROOT_TRANSFORMS: Readonly<Record<RootKey, RootTransform>> = {\n paths: (node, context) => {\n const members = pathMembers(node as PathsObject, context);\n return {\n type: irObject(members.map(({ member }) => member)),\n aliases: [],\n withDeclaredTypes: (lookup) => pathsObjectType(members, lookup),\n };\n },\n webhooks: (node, context) => ({ type: webhooksType(node as PathsObject, context), aliases: [] }),\n components: (node, context, document) => {\n const kept = keptDeprecated(document, context);\n const { type, rootTypes } = componentsType(node as ComponentsObject, context, kept);\n return { type, aliases: rootTypes };\n },\n $defs: (node, context) => ({\n type: defsRootType(node as NonNullable<DocumentObject[\"$defs\"]>, context),\n aliases: [],\n }),\n};\n\nfunction emptyAlias(name: string): IrTypeAliasDeclaration {\n return { kind: \"typeAlias\", name, isExported: true, type: EMPTY_ROOT_TYPE, comments: [] };\n}\n\n/** A root type that declares something: an object with members, or an intersection of them. */\ntype RootBodyType = IrObjectType | IrIntersectionType;\n\nfunction isRootBody(type: IrType): type is RootBodyType {\n return (type.kind === \"object\" && type.members.length > 0) || type.kind === \"intersection\";\n}\n\n/**\n * A root with members: an interface, or a type alias with `--export-type`. An intersection (the\n * `paths` of overlapping `--path-params-as-types` keys) can only be a type alias.\n */\nfunction rootDeclaration(\n name: RootKey,\n type: RootBodyType,\n options: TransformOptions,\n): IrDeclaration {\n return options.exportType || type.kind === \"intersection\"\n ? { kind: \"typeAlias\", name, isExported: true, type, comments: [] }\n : { kind: \"interface\", name, isExported: true, members: type.members, comments: [] };\n}\n\n/**\n * The declarations of one root: its type, then its aliases. `finish` gives the root's declaration\n * again from the types the whole file declares, for a root with `withDeclaredTypes`.\n */\ninterface RootDeclarations {\n readonly declarations: readonly IrDeclaration[];\n readonly finish?: (lookup: DeclaredTypeLookup) => IrDeclaration;\n}\n\n/**\n * The declarations of one root. A root that is missing, or whose type has no members, is\n * `Record<string, never>`. Only an object type (or the `paths` intersection) counts as having\n * members: a callback type the IR keeps as raw text does not (ADR-004).\n */\nfunction rootDeclarations(\n root: RootKey,\n document: DocumentObject,\n context: TransformContext,\n): RootDeclarations {\n const node: unknown = document[root];\n if (!node || typeof node !== \"object\") {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root)] };\n }\n const startedAt = context.diagnostics.now();\n const { type, aliases, withDeclaredTypes } = ROOT_TRANSFORMS[root](node, context, document);\n if (!isRootBody(type)) {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root), ...aliases] };\n }\n const declaration = rootDeclaration(root, type, context.options);\n context.diagnostics.debug(`${root} done`, context.diagnostics.now() - startedAt);\n const finish =\n withDeclaredTypes &&\n ((lookup: DeclaredTypeLookup) => {\n const finished = withDeclaredTypes(lookup);\n return isRootBody(finished) ? rootDeclaration(root, finished, context.options) : declaration;\n });\n return { declarations: [declaration, ...aliases], ...(finish ? { finish } : {}) };\n}\n\n/**\n * Every root's declarations in output order. A root with `finish` gets its declaration from the\n * types of the other roots and of the footer (the `operations` interface), which exist only once\n * every root is transformed.\n */\nfunction rootsDeclarations(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[],\n): IrDeclaration[] {\n const roots = ROOT_KEYS.map((root) => rootDeclarations(root, document, context));\n const transformed = roots.flatMap(({ declarations }) => declarations);\n if (roots.every(({ finish }) => finish === undefined)) {\n return transformed;\n }\n const lookup = declaredTypeLookup([...transformed, ...footer()]);\n return roots.flatMap(({ declarations, finish }) => {\n const [declaration, ...aliases] = declarations;\n return finish === undefined || declaration === undefined\n ? declarations\n : [finish(lookup), ...aliases];\n });\n}\n\n/**\n * The `inject` text as written (ADR-010, decision 4), without the blank lines around it. The\n * original reprinted it with the TypeScript printer; text without code printed nothing then.\n */\nfunction withoutBlankLinesAround(text: string): string {\n return text.replace(/^(?:[ \\t]*\\r?\\n)+/, \"\").trimEnd();\n}\n\n/** No footer declarations: the roots' references to `operations` stay unresolved. */\nconst NO_FOOTER = (): readonly IrDeclaration[] => [];\n\n/**\n * The document's declarations before the footer: helper types, injected code, then one root type\n * per root key with the aliases that follow it. `footer` reads the footer's declarations once the\n * roots are transformed.\n */\nexport function documentBody(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[] = NO_FOOTER,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (context.options.readWriteMarkers) {\n declarations.push({ kind: \"rawDeclaration\", text: READ_WRITE_MARKER_TYPES });\n }\n const inject = withoutBlankLinesAround(context.options.inject ?? \"\");\n if (inject !== \"\") {\n declarations.push({ kind: \"rawDeclaration\", text: inject });\n }\n appendAll(declarations, rootsDeclarations(document, context, footer));\n return declarations;\n}\n\n/**\n * The declarations after the footer: an empty `operations` type when the footer has no\n * operations, and the `--make-paths-enum` enum.\n */\nexport function documentClosing(\n document: DocumentObject,\n context: TransformContext,\n hasOperations: boolean,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (!hasOperations) {\n declarations.push(emptyAlias(OPERATIONS_NAME));\n }\n if (context.options.makePathsEnum && document.paths) {\n const isIncluded = (operation: OperationEntry) => isIncludedOperation(operation, context);\n declarations.push(apiPathsEnumDeclaration(document.paths, isIncluded));\n }\n return declarations;\n}\n"],"names":["irRecord","irKeyword","keptDeprecatedComponents","pathMembers","irObject","pathsObjectType","webhooksType","componentsType","defsRootType","declaredTypeLookup","READ_WRITE_MARKER_TYPES","appendAll","isIncludedOperation","apiPathsEnumDeclaration"],"mappings":";;;;;;;;;;;;;;AAwBO,MAAM,SAAA,GAAY,OAAO,MAAA,CAAO,CAAC,SAAS,UAAA,EAAY,YAAA,EAAc,OAAO,CAAU;AAGrF,MAAM,eAAA,GAAkB;AAE/B,MAAM,kBAAkBA,qBAAA,CAASC,sBAAA,CAAU,QAAQ,CAAA,EAAGA,sBAAA,CAAU,OAAO,CAAC,CAAA;AAoBxE,SAAS,cAAA,CAAe,UAA0B,OAAA,EAAgD;AAChG,EAAA,OAAO,OAAA,CAAQ,QAAQ,iBAAA,GACnBC,yCAAA,CAAyB,UAAU,OAAA,CAAQ,IAAI,CAAA,mBAC/C,IAAI,GAAA,EAAI;AACd;AAEA,MAAM,eAAA,GAA4D;AAAA,EAChE,KAAA,EAAO,CAAC,IAAA,EAAM,OAAA,KAAY;AACxB,IAAA,MAAM,OAAA,GAAUC,iBAAA,CAAY,IAAA,EAAqB,OAAO,CAAA;AACxD,IAAA,OAAO;AAAA,MACL,IAAA,EAAMC,sBAAS,OAAA,CAAQ,GAAA,CAAI,CAAC,EAAE,MAAA,EAAO,KAAM,MAAM,CAAC,CAAA;AAAA,MAClD,SAAS,EAAC;AAAA,MACV,iBAAA,EAAmB,CAAC,MAAA,KAAWC,qBAAA,CAAgB,SAAS,MAAM;AAAA,KAChE;AAAA,EACF,CAAA;AAAA,EACA,QAAA,EAAU,CAAC,IAAA,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MAAM,eAAgC,EAAC;AACvC,EAAA,IAAI,OAAA,CAAQ,QAAQ,gBAAA,EAAkB;AACpC,IAAA,YAAA,CAAa,KAAK,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAMC,qCAAyB,CAAA;AAAA,EAC7E;AACA,EAAA,MAAM,MAAA,GAAS,uBAAA,CAAwB,OAAA,CAAQ,OAAA,CAAQ,UAAU,EAAE,CAAA;AACnE,EAAA,IAAI,WAAW,EAAA,EAAI;AACjB,IAAA,YAAA,CAAa,KAAK,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,QAAQ,CAAA;AAAA,EAC5D;AACA,EAAAC,mBAAA,CAAU,YAAA,EAAc,iBAAA,CAAkB,QAAA,EAAU,OAAA,EAAS,MAAM,CAAC,CAAA;AACpE,EAAA,OAAO,YAAA;AACT;AAMO,SAAS,eAAA,CACd,QAAA,EACA,OAAA,EACA,aAAA,EACiB;AACjB,EAAA,MAAM,eAAgC,EAAC;AACvC,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,YAAA,CAAa,IAAA,CAAK,UAAA,CAAW,eAAe,CAAC,CAAA;AAAA,EAC/C;AACA,EAAA,IAAI,OAAA,CAAQ,OAAA,CAAQ,aAAA,IAAiB,QAAA,CAAS,KAAA,EAAO;AACnD,IAAA,MAAM,UAAA,GAAa,CAAC,SAAA,KAA8BC,4BAAA,CAAoB,WAAW,OAAO,CAAA;AACxF,IAAA,YAAA,CAAa,IAAA,CAAKC,iCAAA,CAAwB,QAAA,CAAS,KAAA,EAAO,UAAU,CAAC,CAAA;AAAA,EACvE;AACA,EAAA,OAAO,YAAA;AACT;;;;;"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { appendAll } from '../../../domain/append-all.mjs';
|
|
1
2
|
import { irRecord, irObject, irKeyword } from '../../../domain/ir/constructors.mjs';
|
|
2
3
|
import { READ_WRITE_MARKER_TYPES } from '../helper-types.mjs';
|
|
3
4
|
import { componentsType } from './components.mjs';
|
|
4
5
|
import { declaredTypeLookup } from './declared-types.mjs';
|
|
5
6
|
import { defsRootType } from './defs-root.mjs';
|
|
6
7
|
import { keptDeprecatedComponents } from './kept-deprecated.mjs';
|
|
8
|
+
import { isIncludedOperation } from './path-item.mjs';
|
|
7
9
|
import { pathMembers, pathsObjectType } from './paths.mjs';
|
|
8
10
|
import { apiPathsEnumDeclaration } from './paths-enum.mjs';
|
|
9
11
|
import { webhooksType } from './webhooks.mjs';
|
|
@@ -88,7 +90,7 @@ function documentBody(document, context, footer = NO_FOOTER) {
|
|
|
88
90
|
if (inject !== "") {
|
|
89
91
|
declarations.push({ kind: "rawDeclaration", text: inject });
|
|
90
92
|
}
|
|
91
|
-
declarations
|
|
93
|
+
appendAll(declarations, rootsDeclarations(document, context, footer));
|
|
92
94
|
return declarations;
|
|
93
95
|
}
|
|
94
96
|
function documentClosing(document, context, hasOperations) {
|
|
@@ -97,10 +99,11 @@ function documentClosing(document, context, hasOperations) {
|
|
|
97
99
|
declarations.push(emptyAlias(OPERATIONS_NAME));
|
|
98
100
|
}
|
|
99
101
|
if (context.options.makePathsEnum && document.paths) {
|
|
100
|
-
|
|
102
|
+
const isIncluded = (operation) => isIncludedOperation(operation, context);
|
|
103
|
+
declarations.push(apiPathsEnumDeclaration(document.paths, isIncluded));
|
|
101
104
|
}
|
|
102
105
|
return declarations;
|
|
103
106
|
}
|
|
104
107
|
|
|
105
|
-
export { documentBody, documentClosing };
|
|
108
|
+
export { OPERATIONS_NAME, ROOT_KEYS, documentBody, documentClosing };
|
|
106
109
|
//# sourceMappingURL=document.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.mjs","sources":["../../../../src/application/transform/document/document.ts"],"sourcesContent":["import { irKeyword, irObject, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrIntersectionType,\n IrObjectType,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport type { ComponentsObject } from \"../../../domain/openapi/components-object.js\";\nimport type { DocumentObject } from \"../../../domain/openapi/document-object.js\";\nimport type { PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { READ_WRITE_MARKER_TYPES } from \"../helper-types.js\";\nimport type { TransformContext, TransformOptions } from \"../transform-context.js\";\nimport { componentsType } from \"./components.js\";\nimport { type DeclaredTypeLookup, declaredTypeLookup } from \"./declared-types.js\";\nimport { defsRootType } from \"./defs-root.js\";\nimport { keptDeprecatedComponents } from \"./kept-deprecated.js\";\nimport { pathMembers, pathsObjectType } from \"./paths.js\";\nimport { apiPathsEnumDeclaration } from \"./paths-enum.js\";\nimport { webhooksType } from \"./webhooks.js\";\n\n/** The root types, in output order. */\nconst ROOT_KEYS = Object.freeze([\"paths\", \"webhooks\", \"components\", \"$defs\"] as const);\ntype RootKey = (typeof ROOT_KEYS)[number];\n\nconst OPERATIONS_NAME = \"operations\";\n/** The type of a root without members: `Record<string, never>`. */\nconst EMPTY_ROOT_TYPE = irRecord(irKeyword(\"string\"), irKeyword(\"never\"));\n\n/** A root's type and the declarations that follow it (the `--root-types` aliases). */\ninterface RootResult {\n readonly type: IrType;\n readonly aliases: readonly IrTypeAliasDeclaration[];\n /**\n * The root's final type, for a root that reads the types the whole file declares (`paths`, whose\n * overlap check follows references). `type` then only tells whether the root has members.\n */\n readonly withDeclaredTypes?: (lookup: DeclaredTypeLookup) => IrType;\n}\n\ntype RootTransform = (\n node: object,\n context: TransformContext,\n document: DocumentObject,\n) => RootResult;\n\n/** Without `--exclude-deprecated` nothing is left out, so the scan is skipped. */\nfunction keptDeprecated(document: DocumentObject, context: TransformContext): ReadonlySet<object> {\n return context.options.excludeDeprecated\n ? keptDeprecatedComponents(document, context.refs)\n : new Set();\n}\n\nconst ROOT_TRANSFORMS: Readonly<Record<RootKey, RootTransform>> = {\n paths: (node, context) => {\n const members = pathMembers(node as PathsObject, context);\n return {\n type: irObject(members.map(({ member }) => member)),\n aliases: [],\n withDeclaredTypes: (lookup) => pathsObjectType(members, lookup),\n };\n },\n webhooks: (node, context) => ({ type: webhooksType(node as PathsObject, context), aliases: [] }),\n components: (node, context, document) => {\n const kept = keptDeprecated(document, context);\n const { type, rootTypes } = componentsType(node as ComponentsObject, context, kept);\n return { type, aliases: rootTypes };\n },\n $defs: (node, context) => ({\n type: defsRootType(node as NonNullable<DocumentObject[\"$defs\"]>, context),\n aliases: [],\n }),\n};\n\nfunction emptyAlias(name: string): IrTypeAliasDeclaration {\n return { kind: \"typeAlias\", name, isExported: true, type: EMPTY_ROOT_TYPE, comments: [] };\n}\n\n/** A root type that declares something: an object with members, or an intersection of them. */\ntype RootBodyType = IrObjectType | IrIntersectionType;\n\nfunction isRootBody(type: IrType): type is RootBodyType {\n return (type.kind === \"object\" && type.members.length > 0) || type.kind === \"intersection\";\n}\n\n/**\n * A root with members: an interface, or a type alias with `--export-type`. An intersection (the\n * `paths` of overlapping `--path-params-as-types` keys) can only be a type alias.\n */\nfunction rootDeclaration(\n name: RootKey,\n type: RootBodyType,\n options: TransformOptions,\n): IrDeclaration {\n return options.exportType || type.kind === \"intersection\"\n ? { kind: \"typeAlias\", name, isExported: true, type, comments: [] }\n : { kind: \"interface\", name, isExported: true, members: type.members, comments: [] };\n}\n\n/**\n * The declarations of one root: its type, then its aliases. `finish` gives the root's declaration\n * again from the types the whole file declares, for a root with `withDeclaredTypes`.\n */\ninterface RootDeclarations {\n readonly declarations: readonly IrDeclaration[];\n readonly finish?: (lookup: DeclaredTypeLookup) => IrDeclaration;\n}\n\n/**\n * The declarations of one root. A root that is missing, or whose type has no members, is\n * `Record<string, never>`. Only an object type (or the `paths` intersection) counts as having\n * members: a callback type the IR keeps as raw text does not (ADR-004).\n */\nfunction rootDeclarations(\n root: RootKey,\n document: DocumentObject,\n context: TransformContext,\n): RootDeclarations {\n const node: unknown = document[root];\n if (!node || typeof node !== \"object\") {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root)] };\n }\n const startedAt = context.diagnostics.now();\n const { type, aliases, withDeclaredTypes } = ROOT_TRANSFORMS[root](node, context, document);\n if (!isRootBody(type)) {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root), ...aliases] };\n }\n const declaration = rootDeclaration(root, type, context.options);\n context.diagnostics.debug(`${root} done`, context.diagnostics.now() - startedAt);\n const finish =\n withDeclaredTypes &&\n ((lookup: DeclaredTypeLookup) => {\n const finished = withDeclaredTypes(lookup);\n return isRootBody(finished) ? rootDeclaration(root, finished, context.options) : declaration;\n });\n return { declarations: [declaration, ...aliases], ...(finish ? { finish } : {}) };\n}\n\n/**\n * Every root's declarations in output order. A root with `finish` gets its declaration from the\n * types of the other roots and of the footer (the `operations` interface), which exist only once\n * every root is transformed.\n */\nfunction rootsDeclarations(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[],\n): IrDeclaration[] {\n const roots = ROOT_KEYS.map((root) => rootDeclarations(root, document, context));\n const transformed = roots.flatMap(({ declarations }) => declarations);\n if (roots.every(({ finish }) => finish === undefined)) {\n return transformed;\n }\n const lookup = declaredTypeLookup([...transformed, ...footer()]);\n return roots.flatMap(({ declarations, finish }) => {\n const [declaration, ...aliases] = declarations;\n return finish === undefined || declaration === undefined\n ? declarations\n : [finish(lookup), ...aliases];\n });\n}\n\n/**\n * The `inject` text as written (ADR-010, decision 4), without the blank lines around it. The\n * original reprinted it with the TypeScript printer; text without code printed nothing then.\n */\nfunction withoutBlankLinesAround(text: string): string {\n return text.replace(/^(?:[ \\t]*\\r?\\n)+/, \"\").trimEnd();\n}\n\n/** No footer declarations: the roots' references to `operations` stay unresolved. */\nconst NO_FOOTER = (): readonly IrDeclaration[] => [];\n\n/**\n * The document's declarations before the footer: helper types, injected code, then one root type\n * per root key with the aliases that follow it. `footer` reads the footer's declarations once the\n * roots are transformed.\n */\nexport function documentBody(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[] = NO_FOOTER,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (context.options.readWriteMarkers) {\n declarations.push({ kind: \"rawDeclaration\", text: READ_WRITE_MARKER_TYPES });\n }\n const inject = withoutBlankLinesAround(context.options.inject ?? \"\");\n if (inject !== \"\") {\n declarations.push({ kind: \"rawDeclaration\", text: inject });\n }\n declarations.push(...rootsDeclarations(document, context, footer));\n return declarations;\n}\n\n/**\n * The declarations after the footer: an empty `operations` type when the footer has no\n * operations, and the `--make-paths-enum` enum.\n */\nexport function documentClosing(\n document: DocumentObject,\n context: TransformContext,\n hasOperations: boolean,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (!hasOperations) {\n declarations.push(emptyAlias(OPERATIONS_NAME));\n }\n if (context.options.makePathsEnum && document.paths) {\n declarations.push(apiPathsEnumDeclaration(document.paths));\n }\n return declarations;\n}\n"],"names":[],"mappings":";;;;;;;;;;AAsBA,MAAM,SAAA,GAAY,OAAO,MAAA,CAAO,CAAC,SAAS,UAAA,EAAY,YAAA,EAAc,OAAO,CAAU,CAAA;AAGrF,MAAM,eAAA,GAAkB,YAAA;AAExB,MAAM,kBAAkB,QAAA,CAAS,SAAA,CAAU,QAAQ,CAAA,EAAG,SAAA,CAAU,OAAO,CAAC,CAAA;AAoBxE,SAAS,cAAA,CAAe,UAA0B,OAAA,EAAgD;AAChG,EAAA,OAAO,OAAA,CAAQ,QAAQ,iBAAA,GACnB,wBAAA,CAAyB,UAAU,OAAA,CAAQ,IAAI,CAAA,mBAC/C,IAAI,GAAA,EAAI;AACd;AAEA,MAAM,eAAA,GAA4D;AAAA,EAChE,KAAA,EAAO,CAAC,IAAA,EAAM,OAAA,KAAY;AACxB,IAAA,MAAM,OAAA,GAAU,WAAA,CAAY,IAAA,EAAqB,OAAO,CAAA;AACxD,IAAA,OAAO;AAAA,MACL,IAAA,EAAM,SAAS,OAAA,CAAQ,GAAA,CAAI,CAAC,EAAE,MAAA,EAAO,KAAM,MAAM,CAAC,CAAA;AAAA,MAClD,SAA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EAAQ;AACvD;AAGA,MAAM,SAAA,GAAY,MAAgC,EAAC;AAO5C,SAAS,YAAA,CACd,QAAA,EACA,OAAA,EACA,MAAA,GAAyC,SAAA,EACxB;AACjB,EAAA,MAAM,eAAgC,EAAC;AACvC,EAAA,IAAI,OAAA,CAAQ,QAAQ,gBAAA,EAAkB;AACpC,IAAA,YAAA,CAAa,KAAK,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,yBAAyB,CAAA;AAAA,EAC7E;AACA,EAAA,MAAM,MAAA,GAAS,uBAAA,CAAwB,OAAA,CAAQ,OAAA,CAAQ,UAAU,EAAE,CAAA;AACnE,EAAA,IAAI,WAAW,EAAA,EAAI;AACjB,IAAA,YAAA,CAAa,KAAK,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,QAAQ,CAAA;AAAA,EAC5D;AACA,EAAA,YAAA,CAAa,KAAK,GAAG,iBAAA,CAAkB,QAAA,EAAU,OAAA,EAAS,MAAM,CAAC,CAAA;AACjE,EAAA,OAAO,YAAA;AACT;AAMO,SAAS,eAAA,CACd,QAAA,EACA,OAAA,EACA,aAAA,EACiB;AACjB,EAAA,MAAM,eAAgC,EAAC;AACvC,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,YAAA,CAAa,IAAA,CAAK,UAAA,CAAW,eAAe,CAAC,CAAA;AAAA,EAC/C;AACA,EAAA,IAAI,OAAA,CAAQ,OAAA,CAAQ,aAAA,IAAiB,QAAA,CAAS,KAAA,EAAO;AACnD,IAAA,YAAA,CAAa,IAAA,CAAK,uBAAA,CAAwB,QAAA,CAAS,KAAK,CAAC,CAAA;AAAA,EAC3D;AACA,EAAA,OAAO,YAAA;AACT;;"}
|
|
1
|
+
{"version":3,"file":"document.mjs","sources":["../../../../src/application/transform/document/document.ts"],"sourcesContent":["import { appendAll } from \"../../../domain/append-all.js\";\nimport { irKeyword, irObject, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrIntersectionType,\n IrObjectType,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport type { ComponentsObject } from \"../../../domain/openapi/components-object.js\";\nimport type { DocumentObject } from \"../../../domain/openapi/document-object.js\";\nimport type { OperationEntry, PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { READ_WRITE_MARKER_TYPES } from \"../helper-types.js\";\nimport type { TransformContext, TransformOptions } from \"../transform-context.js\";\nimport { componentsType } from \"./components.js\";\nimport { type DeclaredTypeLookup, declaredTypeLookup } from \"./declared-types.js\";\nimport { defsRootType } from \"./defs-root.js\";\nimport { keptDeprecatedComponents } from \"./kept-deprecated.js\";\nimport { isIncludedOperation } from \"./path-item.js\";\nimport { pathMembers, pathsObjectType } from \"./paths.js\";\nimport { apiPathsEnumDeclaration } from \"./paths-enum.js\";\nimport { webhooksType } from \"./webhooks.js\";\n\n/** The root types, in output order. */\nexport const ROOT_KEYS = Object.freeze([\"paths\", \"webhooks\", \"components\", \"$defs\"] as const);\ntype RootKey = (typeof ROOT_KEYS)[number];\n\nexport const OPERATIONS_NAME = \"operations\";\n/** The type of a root without members: `Record<string, never>`. */\nconst EMPTY_ROOT_TYPE = irRecord(irKeyword(\"string\"), irKeyword(\"never\"));\n\n/** A root's type and the declarations that follow it (the `--root-types` aliases). */\ninterface RootResult {\n readonly type: IrType;\n readonly aliases: readonly IrTypeAliasDeclaration[];\n /**\n * The root's final type, for a root that reads the types the whole file declares (`paths`, whose\n * overlap check follows references). `type` then only tells whether the root has members.\n */\n readonly withDeclaredTypes?: (lookup: DeclaredTypeLookup) => IrType;\n}\n\ntype RootTransform = (\n node: object,\n context: TransformContext,\n document: DocumentObject,\n) => RootResult;\n\n/** Without `--exclude-deprecated` nothing is left out, so the scan is skipped. */\nfunction keptDeprecated(document: DocumentObject, context: TransformContext): ReadonlySet<object> {\n return context.options.excludeDeprecated\n ? keptDeprecatedComponents(document, context.refs)\n : new Set();\n}\n\nconst ROOT_TRANSFORMS: Readonly<Record<RootKey, RootTransform>> = {\n paths: (node, context) => {\n const members = pathMembers(node as PathsObject, context);\n return {\n type: irObject(members.map(({ member }) => member)),\n aliases: [],\n withDeclaredTypes: (lookup) => pathsObjectType(members, lookup),\n };\n },\n webhooks: (node, context) => ({ type: webhooksType(node as PathsObject, context), aliases: [] }),\n components: (node, context, document) => {\n const kept = keptDeprecated(document, context);\n const { type, rootTypes } = componentsType(node as ComponentsObject, context, kept);\n return { type, aliases: rootTypes };\n },\n $defs: (node, context) => ({\n type: defsRootType(node as NonNullable<DocumentObject[\"$defs\"]>, context),\n aliases: [],\n }),\n};\n\nfunction emptyAlias(name: string): IrTypeAliasDeclaration {\n return { kind: \"typeAlias\", name, isExported: true, type: EMPTY_ROOT_TYPE, comments: [] };\n}\n\n/** A root type that declares something: an object with members, or an intersection of them. */\ntype RootBodyType = IrObjectType | IrIntersectionType;\n\nfunction isRootBody(type: IrType): type is RootBodyType {\n return (type.kind === \"object\" && type.members.length > 0) || type.kind === \"intersection\";\n}\n\n/**\n * A root with members: an interface, or a type alias with `--export-type`. An intersection (the\n * `paths` of overlapping `--path-params-as-types` keys) can only be a type alias.\n */\nfunction rootDeclaration(\n name: RootKey,\n type: RootBodyType,\n options: TransformOptions,\n): IrDeclaration {\n return options.exportType || type.kind === \"intersection\"\n ? { kind: \"typeAlias\", name, isExported: true, type, comments: [] }\n : { kind: \"interface\", name, isExported: true, members: type.members, comments: [] };\n}\n\n/**\n * The declarations of one root: its type, then its aliases. `finish` gives the root's declaration\n * again from the types the whole file declares, for a root with `withDeclaredTypes`.\n */\ninterface RootDeclarations {\n readonly declarations: readonly IrDeclaration[];\n readonly finish?: (lookup: DeclaredTypeLookup) => IrDeclaration;\n}\n\n/**\n * The declarations of one root. A root that is missing, or whose type has no members, is\n * `Record<string, never>`. Only an object type (or the `paths` intersection) counts as having\n * members: a callback type the IR keeps as raw text does not (ADR-004).\n */\nfunction rootDeclarations(\n root: RootKey,\n document: DocumentObject,\n context: TransformContext,\n): RootDeclarations {\n const node: unknown = document[root];\n if (!node || typeof node !== \"object\") {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root)] };\n }\n const startedAt = context.diagnostics.now();\n const { type, aliases, withDeclaredTypes } = ROOT_TRANSFORMS[root](node, context, document);\n if (!isRootBody(type)) {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root), ...aliases] };\n }\n const declaration = rootDeclaration(root, type, context.options);\n context.diagnostics.debug(`${root} done`, context.diagnostics.now() - startedAt);\n const finish =\n withDeclaredTypes &&\n ((lookup: DeclaredTypeLookup) => {\n const finished = withDeclaredTypes(lookup);\n return isRootBody(finished) ? rootDeclaration(root, finished, context.options) : declaration;\n });\n return { declarations: [declaration, ...aliases], ...(finish ? { finish } : {}) };\n}\n\n/**\n * Every root's declarations in output order. A root with `finish` gets its declaration from the\n * types of the other roots and of the footer (the `operations` interface), which exist only once\n * every root is transformed.\n */\nfunction rootsDeclarations(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[],\n): IrDeclaration[] {\n const roots = ROOT_KEYS.map((root) => rootDeclarations(root, document, context));\n const transformed = roots.flatMap(({ declarations }) => declarations);\n if (roots.every(({ finish }) => finish === undefined)) {\n return transformed;\n }\n const lookup = declaredTypeLookup([...transformed, ...footer()]);\n return roots.flatMap(({ declarations, finish }) => {\n const [declaration, ...aliases] = declarations;\n return finish === undefined || declaration === undefined\n ? declarations\n : [finish(lookup), ...aliases];\n });\n}\n\n/**\n * The `inject` text as written (ADR-010, decision 4), without the blank lines around it. The\n * original reprinted it with the TypeScript printer; text without code printed nothing then.\n */\nfunction withoutBlankLinesAround(text: string): string {\n return text.replace(/^(?:[ \\t]*\\r?\\n)+/, \"\").trimEnd();\n}\n\n/** No footer declarations: the roots' references to `operations` stay unresolved. */\nconst NO_FOOTER = (): readonly IrDeclaration[] => [];\n\n/**\n * The document's declarations before the footer: helper types, injected code, then one root type\n * per root key with the aliases that follow it. `footer` reads the footer's declarations once the\n * roots are transformed.\n */\nexport function documentBody(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[] = NO_FOOTER,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (context.options.readWriteMarkers) {\n declarations.push({ kind: \"rawDeclaration\", text: READ_WRITE_MARKER_TYPES });\n }\n const inject = withoutBlankLinesAround(context.options.inject ?? \"\");\n if (inject !== \"\") {\n declarations.push({ kind: \"rawDeclaration\", text: inject });\n }\n appendAll(declarations, rootsDeclarations(document, context, footer));\n return declarations;\n}\n\n/**\n * The declarations after the footer: an empty `operations` type when the footer has no\n * operations, and the `--make-paths-enum` enum.\n */\nexport function documentClosing(\n document: DocumentObject,\n context: TransformContext,\n hasOperations: boolean,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (!hasOperations) {\n declarations.push(emptyAlias(OPERATIONS_NAME));\n }\n if (context.options.makePathsEnum && document.paths) {\n const isIncluded = (operation: OperationEntry) => isIncludedOperation(operation, context);\n declarations.push(apiPathsEnumDeclaration(document.paths, isIncluded));\n }\n return declarations;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAwBO,MAAM,SAAA,GAAY,OAAO,MAAA,CAAO,CAAC,SAAS,UAAA,EAAY,YAAA,EAAc,OAAO,CAAU;AAGrF,MAAM,eAAA,GAAkB;AAE/B,MAAM,kBAAkB,QAAA,CAAS,SAAA,CAAU,QAAQ,CAAA,EAAG,SAAA,CAAU,OAAO,CAAC,CAAA;AAoBxE,SAAS,cAAA,CAAe,UAA0B,OAAA,EAAgD;AAChG,EAAA,OAAO,OAAA,CAAQ,QAAQ,iBAAA,GACnB,wBAAA,CAAyB,UAAU,OAAA,CAAQ,IAAI,CAAA,mBAC/C,IAAI,GAAA,EAAI;AACd;AAEA,MAAM,eAAA,GAA4D;AAAA,EAChE,KAAA,EAAO,CAAC,IAAA,EAAM,OAAA,KAAY;AACxB,IAAA,MAAM,OAAA,GAAU,WAAA,C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wB,QAAA,CAAS,KAAA,EAAO,UAAU,CAAC,CAAA;AAAA,EACvE;AACA,EAAA,OAAO,YAAA;AACT;;"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const helperTypes = require('../helper-types.cjs');
|
|
4
|
+
const declaredTypeNames = require('./declared-type-names.cjs');
|
|
5
|
+
const document = require('./document.cjs');
|
|
6
|
+
const globalTypeReferences = require('./global-type-references.cjs');
|
|
7
|
+
const pathsEnum = require('./paths-enum.cjs');
|
|
8
|
+
const rootTypeAliases = require('./root-type-aliases.cjs');
|
|
9
|
+
|
|
10
|
+
const NAMES_THE_OUTPUT_MAY_NEED = /* @__PURE__ */ new Set([
|
|
11
|
+
...globalTypeReferences.GLOBAL_TYPE_NAMES,
|
|
12
|
+
...Object.values(helperTypes.HELPER_TYPES).map(({ name }) => name),
|
|
13
|
+
...declaredTypeNames.typeNamesInText(helperTypes.READ_WRITE_MARKER_TYPES),
|
|
14
|
+
pathsEnum.API_PATHS_NAME,
|
|
15
|
+
...document.ROOT_KEYS,
|
|
16
|
+
document.OPERATIONS_NAME
|
|
17
|
+
]);
|
|
18
|
+
function namesTheOutputNeeds({ body, footer, closing }) {
|
|
19
|
+
const others = [
|
|
20
|
+
...body.filter((declaration) => !rootTypeAliases.isRootTypeAlias(declaration)),
|
|
21
|
+
...footer.filter((declaration) => declaration.kind !== "enum"),
|
|
22
|
+
...closing
|
|
23
|
+
];
|
|
24
|
+
return /* @__PURE__ */ new Set([
|
|
25
|
+
...globalTypeReferences.globalTypeReferences([...body, ...footer, ...closing]),
|
|
26
|
+
...declaredTypeNames.typeNamesDeclaredBy(others)
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
const SKIPPED_KEYS = /* @__PURE__ */ new Set(["origin"]);
|
|
30
|
+
const ENUM_REFERENCE_RE = /^(typeof )?([^.]+)(\..*)?$/s;
|
|
31
|
+
function renamedReference(name, renames) {
|
|
32
|
+
const match = ENUM_REFERENCE_RE.exec(name);
|
|
33
|
+
const renamed = match === null ? void 0 : renames.get(match[2] ?? "");
|
|
34
|
+
return renamed === void 0 ? name : `${match?.[1] ?? ""}${renamed}${match?.[3] ?? ""}`;
|
|
35
|
+
}
|
|
36
|
+
function isNode(value) {
|
|
37
|
+
return typeof value === "object" && value !== null;
|
|
38
|
+
}
|
|
39
|
+
function renamedNode(value, renames) {
|
|
40
|
+
if (Array.isArray(value)) {
|
|
41
|
+
return value.map((item) => renamedNode(item, renames));
|
|
42
|
+
}
|
|
43
|
+
if (!isNode(value)) {
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
const node = Object.fromEntries(
|
|
47
|
+
Object.entries(value).map(([key, child]) => [
|
|
48
|
+
key,
|
|
49
|
+
SKIPPED_KEYS.has(key) ? child : renamedNode(child, renames)
|
|
50
|
+
])
|
|
51
|
+
);
|
|
52
|
+
const isNamed = (node.kind === "reference" || node.kind === "enum") && typeof node.name === "string";
|
|
53
|
+
return isNamed ? { ...node, name: renamedReference(node.name, renames) } : node;
|
|
54
|
+
}
|
|
55
|
+
function withEnumsRenamed(declarations, renames) {
|
|
56
|
+
return renames.size === 0 ? [...declarations] : renamedNode(declarations, renames);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
exports.NAMES_THE_OUTPUT_MAY_NEED = NAMES_THE_OUTPUT_MAY_NEED;
|
|
60
|
+
exports.namesTheOutputNeeds = namesTheOutputNeeds;
|
|
61
|
+
exports.withEnumsRenamed = withEnumsRenamed;
|
|
62
|
+
//# sourceMappingURL=enum-names-given-back.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum-names-given-back.cjs","sources":["../../../../src/application/transform/document/enum-names-given-back.ts"],"sourcesContent":["import type { IrDeclaration } from \"../../../domain/ir/nodes.js\";\nimport { HELPER_TYPES, READ_WRITE_MARKER_TYPES } from \"../helper-types.js\";\nimport { typeNamesDeclaredBy, typeNamesInText } from \"./declared-type-names.js\";\nimport { OPERATIONS_NAME, ROOT_KEYS } from \"./document.js\";\nimport { GLOBAL_TYPE_NAMES, globalTypeReferences } from \"./global-type-references.js\";\nimport { API_PATHS_NAME } from \"./paths-enum.js\";\nimport { isRootTypeAlias } from \"./root-type-aliases.js\";\n\n/**\n * The second step of naming `--enum` declarations (`EnumNameClaims`): once the output is known,\n * an enum that gave way to a name the output turned out not to need gets that name back.\n */\n\n/**\n * The type names the output of a document may need, besides its enums: the global types it may\n * refer to and the names the generator declares itself. An enum avoids them until the end.\n */\nexport const NAMES_THE_OUTPUT_MAY_NEED: ReadonlySet<string> = new Set([\n ...GLOBAL_TYPE_NAMES,\n ...Object.values(HELPER_TYPES).map(({ name }) => name),\n ...typeNamesInText(READ_WRITE_MARKER_TYPES),\n API_PATHS_NAME,\n ...ROOT_KEYS,\n OPERATIONS_NAME,\n]);\n\n/** The parts of a transformed document; the footer holds only IR declarations here. */\nexport interface DocumentParts {\n readonly body: readonly IrDeclaration[];\n readonly footer: readonly IrDeclaration[];\n readonly closing: readonly IrDeclaration[];\n}\n\n/**\n * The type names the output needs besides its enums: the globals it refers to, and the names of\n * its other declarations. Root aliases give way to enums (`renameTakenAliases`), so they count\n * for nothing.\n */\nexport function namesTheOutputNeeds({ body, footer, closing }: DocumentParts): Set<string> {\n const others = [\n ...body.filter((declaration) => !isRootTypeAlias(declaration)),\n ...footer.filter((declaration) => declaration.kind !== \"enum\"),\n ...closing,\n ];\n return new Set([\n ...globalTypeReferences([...body, ...footer, ...closing]),\n ...typeNamesDeclaredBy(others),\n ]);\n}\n\n/** `origin` holds the compiler node a raw type was printed from; it is not IR. */\nconst SKIPPED_KEYS: ReadonlySet<string> = new Set([\"origin\"]);\n\n/** The enum references the generator writes: `Name`, `Name.member` and `typeof Name`. */\nconst ENUM_REFERENCE_RE = /^(typeof )?([^.]+)(\\..*)?$/s;\n\nfunction renamedReference(name: string, renames: ReadonlyMap<string, string>): string {\n const match = ENUM_REFERENCE_RE.exec(name);\n const renamed = match === null ? undefined : renames.get(match[2] ?? \"\");\n return renamed === undefined ? name : `${match?.[1] ?? \"\"}${renamed}${match?.[3] ?? \"\"}`;\n}\n\nfunction isNode(value: unknown): value is Readonly<Record<string, unknown>> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction renamedNode(value: unknown, renames: ReadonlyMap<string, string>): unknown {\n if (Array.isArray(value)) {\n return value.map((item) => renamedNode(item, renames));\n }\n if (!isNode(value)) {\n return value;\n }\n const node = Object.fromEntries(\n Object.entries(value).map(([key, child]) => [\n key,\n SKIPPED_KEYS.has(key) ? child : renamedNode(child, renames),\n ]),\n );\n const isNamed =\n (node.kind === \"reference\" || node.kind === \"enum\") && typeof node.name === \"string\";\n return isNamed ? { ...node, name: renamedReference(node.name as string, renames) } : node;\n}\n\n/** The declarations with each enum in `renames` (old name to new) renamed, references too. */\nexport function withEnumsRenamed<T extends IrDeclaration>(\n declarations: readonly T[],\n renames: ReadonlyMap<string, string>,\n): T[] {\n return renames.size === 0 ? [...declarations] : (renamedNode(declarations, renames) as T[]);\n}\n"],"names":["GLOBAL_TYPE_NAMES","HELPER_TYPES","typeNamesInText","READ_WRITE_MARKER_TYPES","API_PATHS_NAME","ROOT_KEYS","OPERATIONS_NAME","isRootTypeAlias","globalTypeReferences","typeNamesDeclaredBy"],"mappings":";;;;;;;;;AAiBO,MAAM,yBAAA,uBAAqD,GAAA,CAAI;AAAA,EACpE,GAAGA,sCAAA;AAAA,EACH,GAAG,MAAA,CAAO,MAAA,CAAOC,wBAAY,CAAA,CAAE,IAAI,CAAC,EAAE,IAAA,EAAK,KAAM,IAAI,CAAA;AAAA,EACrD,GAAGC,kCAAgBC,mCAAuB,CAAA;AAAA,EAC1CC,wBAAA;AAAA,EACA,GAAGC,kBAAA;AAAA,EACHC;AACF,CAAC;AAcM,SAAS,mBAAA,CAAoB,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAQ,EAA+B;AACzF,EAAA,MAAM,MAAA,GAAS;AAAA,IACb,GAAG,KA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