openapi-typesafe 1.0.0-rc.2 → 1.0.0-rc.4
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 +1831 -0
- package/dist/adapters/node-deprecations/node-deprecations.cjs +14 -0
- package/dist/adapters/node-deprecations/node-deprecations.cjs.map +1 -0
- package/dist/adapters/node-deprecations/node-deprecations.mjs +12 -0
- package/dist/adapters/node-deprecations/node-deprecations.mjs.map +1 -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 +90 -14
- package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
- package/dist/adapters/node-file-system/node-file-system.mjs +90 -14
- package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +75 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +72 -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/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/redocly-schema-loader.cjs +14 -15
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +12 -13
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +31 -3
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +31 -3
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.cjs +2 -2
- package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.mjs +3 -3
- 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 +35 -6
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +35 -6
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.cjs +47 -0
- package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs +44 -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 +11 -7
- package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.mjs +12 -8
- 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 +6 -4
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.mjs +6 -4
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
- package/dist/api/default-ports.cjs +19 -2
- package/dist/api/default-ports.cjs.map +1 -1
- package/dist/api/default-ports.mjs +19 -3
- package/dist/api/default-ports.mjs.map +1 -1
- package/dist/api/discriminator-conflict-warnings.cjs +1 -1
- package/dist/api/discriminator-conflict-warnings.cjs.map +1 -1
- package/dist/api/discriminator-conflict-warnings.mjs +2 -2
- package/dist/api/discriminator-conflict-warnings.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 +8 -4
- package/dist/api/discriminator-patch.cjs.map +1 -1
- package/dist/api/discriminator-patch.mjs +9 -5
- package/dist/api/discriminator-patch.mjs.map +1 -1
- package/dist/api/discriminator-scan.cjs +17 -10
- package/dist/api/discriminator-scan.cjs.map +1 -1
- package/dist/api/discriminator-scan.mjs +18 -11
- package/dist/api/discriminator-scan.mjs.map +1 -1
- package/dist/api/document-run.cjs +4 -3
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +4 -3
- package/dist/api/document-run.mjs.map +1 -1
- package/dist/api/legacy-callback-warning.cjs +7 -4
- package/dist/api/legacy-callback-warning.cjs.map +1 -1
- package/dist/api/legacy-callback-warning.mjs +8 -5
- package/dist/api/legacy-callback-warning.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 -5
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +10 -7
- package/dist/api/openapi-ts.mjs.map +1 -1
- 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/string-to-ast.cjs +7 -9
- package/dist/api/string-to-ast.cjs.map +1 -1
- package/dist/api/string-to-ast.mjs +8 -9
- package/dist/api/string-to-ast.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 +42 -12
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +44 -14
- 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/document/components.cjs +2 -2
- package/dist/application/transform/document/components.cjs.map +1 -1
- package/dist/application/transform/document/components.mjs +4 -4
- 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 +4 -1
- package/dist/application/transform/document/document.cjs.map +1 -1
- package/dist/application/transform/document/document.mjs +3 -2
- 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/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/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 +7 -30
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +8 -31
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/path-item.cjs +11 -14
- package/dist/application/transform/document/path-item.cjs.map +1 -1
- package/dist/application/transform/document/path-item.mjs +12 -16
- package/dist/application/transform/document/path-item.mjs.map +1 -1
- package/dist/application/transform/document/paths-enum.cjs +1 -0
- package/dist/application/transform/document/paths-enum.cjs.map +1 -1
- package/dist/application/transform/document/paths-enum.mjs +1 -1
- package/dist/application/transform/document/paths-enum.mjs.map +1 -1
- package/dist/application/transform/document/paths.cjs +6 -2
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +8 -4
- 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 +1 -1
- package/dist/application/transform/document/webhooks.cjs.map +1 -1
- package/dist/application/transform/document/webhooks.mjs +2 -2
- package/dist/application/transform/document/webhooks.mjs.map +1 -1
- package/dist/application/transform/footer/document-footer.cjs +10 -2
- package/dist/application/transform/footer/document-footer.cjs.map +1 -1
- package/dist/application/transform/footer/document-footer.mjs +10 -2
- 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 +1 -1
- package/dist/application/transform/helper-types.cjs.map +1 -1
- package/dist/application/transform/helper-types.mjs +1 -1
- 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 +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs +2 -2
- package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs +2 -2
- package/dist/application/transform/ref-pointer/pointer-type.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 +1 -1
- package/dist/application/transform/schema/access-flags.cjs.map +1 -1
- package/dist/application/transform/schema/access-flags.mjs +2 -2
- package/dist/application/transform/schema/access-flags.mjs.map +1 -1
- package/dist/application/transform/schema/array-type.cjs +2 -2
- package/dist/application/transform/schema/array-type.cjs.map +1 -1
- package/dist/application/transform/schema/array-type.mjs +3 -3
- package/dist/application/transform/schema/array-type.mjs.map +1 -1
- package/dist/application/transform/schema/composition-type.cjs +4 -4
- package/dist/application/transform/schema/composition-type.cjs.map +1 -1
- package/dist/application/transform/schema/composition-type.mjs +6 -6
- package/dist/application/transform/schema/composition-type.mjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.cjs +4 -6
- package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.mjs +6 -8
- package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
- package/dist/application/transform/schema/object-type.cjs +3 -3
- package/dist/application/transform/schema/object-type.cjs.map +1 -1
- package/dist/application/transform/schema/object-type.mjs +4 -4
- package/dist/application/transform/schema/object-type.mjs.map +1 -1
- package/dist/application/transform/schema/presence-members.cjs +1 -1
- package/dist/application/transform/schema/presence-members.cjs.map +1 -1
- package/dist/application/transform/schema/presence-members.mjs +2 -2
- package/dist/application/transform/schema/presence-members.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/required-variants.cjs +2 -2
- package/dist/application/transform/schema/required-variants.cjs.map +1 -1
- package/dist/application/transform/schema/required-variants.mjs +3 -3
- package/dist/application/transform/schema/required-variants.mjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.cjs +4 -2
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.mjs +4 -2
- package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.mjs +2 -2
- package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
- package/dist/application/transform/schema-comment.cjs +6 -2
- package/dist/application/transform/schema-comment.cjs.map +1 -1
- package/dist/application/transform/schema-comment.mjs +7 -3
- package/dist/application/transform/schema-comment.mjs.map +1 -1
- package/dist/cli/api-settings.cjs +62 -6
- package/dist/cli/api-settings.cjs.map +1 -1
- package/dist/cli/api-settings.mjs +60 -7
- 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-errors.cjs +12 -1
- package/dist/cli/cli-errors.cjs.map +1 -1
- package/dist/cli/cli-errors.mjs +12 -1
- package/dist/cli/cli-errors.mjs.map +1 -1
- package/dist/cli/cli-output.cjs +106 -1
- package/dist/cli/cli-output.cjs.map +1 -1
- package/dist/cli/cli-output.mjs +99 -2
- package/dist/cli/cli-output.mjs.map +1 -1
- package/dist/cli/main.cjs +5 -1
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.mjs +6 -2
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +82 -36
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +85 -39
- package/dist/cli/redocly-apis.mjs.map +1 -1
- package/dist/cli/run-cli.cjs +13 -7
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +14 -8
- 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 +37 -0
- package/dist/domain/cause-secrets.cjs.map +1 -0
- package/dist/domain/cause-secrets.mjs +35 -0
- package/dist/domain/cause-secrets.mjs.map +1 -0
- package/dist/domain/deprecations.cjs +11 -0
- package/dist/domain/deprecations.cjs.map +1 -0
- package/dist/domain/deprecations.mjs +9 -0
- package/dist/domain/deprecations.mjs.map +1 -0
- package/dist/domain/errors.cjs +9 -3
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +9 -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/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/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 +25 -14
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +25 -13
- package/dist/domain/output-fixes.mjs.map +1 -1
- 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 +0 -1
- package/dist/domain/warnings.cjs.map +1 -1
- package/dist/domain/warnings.mjs +0 -1
- package/dist/domain/warnings.mjs.map +1 -1
- package/dist/index.cjs +2 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -20
- package/dist/index.d.mts +57 -20
- package/dist/index.d.ts +57 -20
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -6
- package/src/adapters/node-deprecations/node-deprecations.ts +14 -0
- 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 +145 -18
- package/src/adapters/redocly-loader/bundled-mapping-copies.ts +95 -0
- package/src/adapters/redocly-loader/bundled-ref-repair.ts +2 -2
- package/src/adapters/redocly-loader/loaded-documents.ts +46 -0
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +18 -24
- package/src/adapters/redocly-loader/ref-access.ts +37 -3
- package/src/adapters/redocly-loader/ref-holders.ts +3 -3
- package/src/adapters/redocly-loader/remote-body-limit.ts +66 -0
- package/src/adapters/redocly-loader/remote-fetch.ts +74 -11
- package/src/adapters/redocly-loader/remote-node-limit.ts +62 -0
- package/src/adapters/redocly-loader/schema-load-errors.ts +52 -13
- package/src/adapters/redocly-loader/schema-source.ts +20 -8
- package/src/adapters/redocly-loader/unsupported-keys.ts +3 -7
- package/src/adapters/terminal-logger/terminal-logger.ts +10 -5
- package/src/api/default-ports.ts +40 -4
- package/src/api/discriminator-conflict-warnings.ts +2 -2
- package/src/api/discriminator-enum-parent.ts +3 -3
- package/src/api/discriminator-other-owners.ts +5 -3
- package/src/api/discriminator-patch.ts +9 -6
- package/src/api/discriminator-scan.ts +19 -11
- package/src/api/document-run.ts +9 -3
- package/src/api/legacy-callback-warning.ts +13 -6
- package/src/api/legacy-utils.ts +5 -1
- package/src/api/openapi-ts.ts +26 -7
- package/src/api/run-context.ts +6 -0
- package/src/api/schema-callbacks.ts +60 -17
- package/src/api/string-to-ast.ts +11 -15
- package/src/api/transform-context.ts +7 -3
- package/src/api/transform-schema.ts +67 -15
- package/src/application/ports/deprecation-reporter.ts +9 -0
- package/src/application/ports/file-system.ts +39 -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/document/components.ts +4 -4
- 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 +4 -3
- package/src/application/transform/document/enum-names-given-back.ts +91 -0
- package/src/application/transform/document/global-type-references.ts +1 -1
- 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 +13 -58
- package/src/application/transform/document/path-item.ts +13 -31
- package/src/application/transform/document/paths-enum.ts +1 -1
- package/src/application/transform/document/paths.ts +8 -4
- 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 +2 -2
- package/src/application/transform/footer/document-footer.ts +18 -1
- 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 +6 -5
- package/src/application/transform/numbered-names.ts +15 -0
- package/src/application/transform/ref-pointer/generated-location.ts +2 -2
- package/src/application/transform/ref-pointer/pointer-type.ts +2 -4
- package/src/application/transform/ref-type.ts +2 -1
- package/src/application/transform/schema/access-flags.ts +2 -2
- package/src/application/transform/schema/array-type.ts +3 -5
- package/src/application/transform/schema/composition-type.ts +6 -6
- package/src/application/transform/schema/enum-rule.ts +10 -8
- package/src/application/transform/schema/object-type.ts +4 -4
- package/src/application/transform/schema/presence-members.ts +2 -2
- package/src/application/transform/schema/ref-siblings.ts +76 -0
- package/src/application/transform/schema/required-variants.ts +3 -3
- package/src/application/transform/schema/schema-context.ts +3 -0
- package/src/application/transform/schema/schema-transform.ts +4 -2
- package/src/application/transform/schema/unevaluated-properties.ts +2 -2
- package/src/application/transform/schema-comment.ts +7 -3
- package/src/application/transform/transform-context.ts +5 -0
- package/src/cli/api-settings.ts +82 -7
- package/src/cli/api-writes.ts +117 -0
- package/src/cli/cli-dependencies.ts +21 -4
- package/src/cli/cli-errors.ts +20 -1
- package/src/cli/cli-output.ts +186 -7
- package/src/cli/main.ts +6 -3
- package/src/cli/redocly-apis.ts +153 -48
- package/src/cli/run-cli.ts +37 -8
- package/src/domain/append-all.ts +10 -0
- package/src/domain/cause-secrets.ts +52 -0
- package/src/domain/deprecations.ts +15 -0
- package/src/domain/errors.ts +22 -7
- 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/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/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 +37 -18
- package/src/domain/url-secrets.ts +72 -0
- package/src/domain/warnings.ts +0 -1
- package/src/index.ts +2 -6
- 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":"document-run.mjs","sources":["../../src/api/document-run.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type { Config as RedoclyConfig } from \"@redocly/openapi-core\";\nimport { sourceEmptyError } from \"../adapters/redocly-loader/schema-load-errors.js\";\nimport type { Logger } from \"../application/ports/logger.js\";\nimport type { RefAccess, SchemaLoader } from \"../application/ports/schema-loader.js\";\nimport { withStackOverflowReported } from \"../application/stack-overflow.js\";\nimport {\n ineffectiveFixNotices,\n type OutputFix,\n outputFixNamesOf,\n resolveOutputFixes,\n} from \"../domain/output-fixes.js\";\nimport { WARNING_CODES, warningText } from \"../domain/warnings.js\";\nimport type { GeneratorOptions, OpenAPI3, SchemaSource } from \"../types.js\";\nimport { processCwd } from \"./default-ports.js\";\nimport { warnDiscriminatorValueConflicts } from \"./discriminator-conflict-warnings.js\";\nimport { findDiscriminators } from \"./discriminator-scan.js\";\nimport { resolveDocumentRef } from \"./document-refs.js\";\nimport { warnIdenticalPathTemplates } from \"./path-template-warnings.js\";\nimport type { RunContext } from \"./run-context.js\";\nimport { warnUnsupportedFeatures } from \"./unsupported-feature-warnings.js\";\n\n/** The ports of one generator run, wired by the Node API or the CLI (ENGINEERING_PLAN 4.5). */\nexport interface GeneratorPorts {\n readonly loader: SchemaLoader;\n readonly logger: Logger;\n /** The Redocly config the loader uses; the run's context exposes it as `ctx.redoc`. */\n readonly redoc: RedoclyConfig;\n /** A monotonic time in milliseconds, for debug durations. */\n readonly now: () => number;\n}\n\n/** A validated, bundled document and the context of one generator run. */\nexport interface DocumentRun {\n readonly schema: OpenAPI3;\n readonly ctx: RunContext;\n}\n\n/** The context fields that are user flags, with the original defaults. */\ntype ContextFlags = Omit<\n RunContext,\n | \"discriminators\"\n | \"injectFooter\"\n | \"redoc\"\n | \"resolve\"\n | \"runFooter\"\n | \"legacyCallbackWarnings\"\n | \"logger\"\n | \"fix\"\n>;\n\n/**\n * The directory that relative `$ref`s of an inline source resolve against, as a URL that ends in\n * a slash. A path is resolved and encoded (`#`, `%`, spaces); a URL without the slash gets one.\n */\nfunction sourceCwd(options: GeneratorOptions): URL {\n const { cwd } = options;\n if (cwd instanceof URL) {\n return cwd.pathname.endsWith(\"/\") ? cwd : new URL(`${cwd.pathname}/`, cwd);\n }\n const directory = path.resolve(cwd === undefined ? processCwd() : cwd.toString());\n return pathToFileURL(path.join(directory, path.sep));\n}\n\n/** The `$ref` limits of the options; a relative local root resolves against the cwd. */\nfunction refAccessOf(options: GeneratorOptions, cwd: URL): RefAccess {\n const { localRefRoot, remoteRefHosts } = options;\n const localRoot =\n typeof localRefRoot === \"string\"\n ? pathToFileURL(path.resolve(fileURLToPath(cwd), localRefRoot))\n : localRefRoot;\n return {\n ...(localRoot === undefined ? {} : { localRoot }),\n ...(remoteRefHosts === undefined ? {} : { remoteHosts: remoteRefHosts }),\n };\n}\n\nfunction callbackOptions(options: GeneratorOptions) {\n return {\n irCallbacks: options.irCallbacks === true,\n postTransform: typeof options.postTransform === \"function\" ? options.postTransform : undefined,\n transform: typeof options.transform === \"function\" ? options.transform : undefined,\n transformProperty:\n typeof options.transformProperty === \"function\" ? options.transformProperty : undefined,\n };\n}\n\nfunction contextFlags(options: GeneratorOptions): ContextFlags {\n return {\n additionalProperties: options.additionalProperties ?? false,\n alphabetize: options.alphabetize ?? false,\n arrayLength: options.arrayLength ?? false,\n binaryAsBlob: options.binaryAsBlob ?? false,\n defaultNonNullable: options.defaultNonNullable ?? true,\n emptyObjectsUnknown: options.emptyObjectsUnknown ?? false,\n enum: options.enum ?? false,\n enumValues: options.enumValues ?? false,\n conditionalEnums: options.conditionalEnums ?? false,\n dedupeEnums: options.dedupeEnums ?? false,\n excludeDeprecated: options.excludeDeprecated ?? false,\n exportType: options.exportType ?? false,\n immutable: options.immutable ?? false,\n rootTypes: options.rootTypes ?? false,\n rootTypesNoSchemaPrefix: options.rootTypesNoSchemaPrefix ?? false,\n rootTypesKeepCasing: options.rootTypesKeepCasing ?? false,\n pathParamsAsTypes: options.pathParamsAsTypes ?? false,\n propertiesRequiredByDefault: options.propertiesRequiredByDefault ?? false,\n silent: options.silent ?? false,\n ...(options.inject === undefined ? {} : { inject: options.inject }),\n makePathsEnum: options.makePathsEnum ?? false,\n generatePathParams: options.generatePathParams ?? false,\n readWriteMarkers: options.readWriteMarkers ?? false,\n ...callbackOptions(options),\n };\n}\n\n/**\n * The fixes of the options, `all` expanded; fails with `OPTION_FIX_UNKNOWN` for another name.\n * A fix named without the option it needs is reported, since it changes nothing.\n */\nfunction outputFixesOf(options: GeneratorOptions, logger: Logger): readonly OutputFix[] {\n const names = outputFixNamesOf(options.fix ?? []);\n for (const notice of ineffectiveFixNotices(names, (option) => options[option] === true)) {\n logger.warn(warningText(notice, WARNING_CODES.FIX_NEEDS_OPTION));\n }\n return [...resolveOutputFixes(names)];\n}\n\n/** The warnings about the loaded document itself, before it is transformed. */\nfunction warnAboutDocument(schema: OpenAPI3, fix: readonly OutputFix[], logger: Logger): void {\n withStackOverflowReported(\"transform\", () => warnUnsupportedFeatures(schema, logger));\n withStackOverflowReported(\"transform\", () =>\n warnDiscriminatorValueConflicts(schema, fix, logger),\n );\n warnIdenticalPathTemplates(schema, logger);\n}\n\n/**\n * Load the source through the ports, then build the run's context from the options. The fix names\n * are checked first, so a typo fails before the document is read.\n */\nexport async function createDocumentRun(\n source: SchemaSource,\n options: GeneratorOptions,\n ports: GeneratorPorts,\n): Promise<DocumentRun> {\n if (!source) {\n throw sourceEmptyError(\"Empty schema. Please specify a URL, file path, or Redocly Config\");\n }\n const { logger } = ports;\n const fix = outputFixesOf(options, logger);\n const silent = options.silent ?? false;\n const cwd = sourceCwd(options);\n const schema = await ports.loader.load({\n source,\n cwd,\n shouldLint: options.lint ?? true,\n refAccess: refAccessOf(options, cwd),\n });\n warnAboutDocument(schema, fix, logger);\n const ctx: RunContext = {\n ...contextFlags(options),\n fix,\n // The scan walks every schema before the transform does, so on a larger stack, where loading\n // passed, it is the first step to run out.\n discriminators: withStackOverflowReported(\"transform\", () =>\n findDiscriminators(schema, {\n silent,\n logger,\n fixes: new Set(fix),\n }),\n ),\n injectFooter: [],\n redoc: ports.redoc,\n resolve: ($ref) => resolveDocumentRef(schema, $ref, { silent, logger }),\n logger,\n };\n return { schema, ctx };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAwDA,SAAS,UAAU,OAAA,EAAgC;AACjD,EAAA,MAAM,EAAE,KAAI,GAAI,OAAA;AAChB,EAAA,IAAI,eAAe,GAAA,EAAK;AACtB,IAAA,OAAO,GAAA,CAAI,QAAA,CAAS,QAAA,CAAS,GAAG,CAAA,GAAI,GAAA,GAAM,IAAI,GAAA,CAAI,CAAA,EAAG,GAAA,CAAI,QAAQ,CAAA,CAAA,CAAA,EAAK,GAAG,CAAA;AAAA,EAC3E;AACA,EAAA,MAAM,SAAA,GAAY,KAAK,OAAA,CAAQ,GAAA,KAAQ,SAAY,UAAA,EAAW,GAAI,GAAA,CAAI,QAAA,EAAU,CAAA;AAChF,EAAA,OAAO,cAAc,IAAA,CAAK,IAAA,CAAK,SAAA,EAAW,IAAA,CAAK,GAAG,CAAC,CAAA;AACrD;AAGA,SAAS,WAAA,CAAY,SAA2B,GAAA,EAAqB;AACnE,EAAA,MAAM,EAAE,YAAA,EAAc,cAAA,EAAe,GAAI,OAAA;AACzC,EAAA,MAAM,SAAA,GACJ,OAAO,YAAA,KAAiB,QAAA,GACpB,aAAA,CAAc,IAAA,CAAK,OAAA,CAAQ,aAAA,CAAc,GAAG,CAAA,EAAG,YAAY,CAAC,CAAA,GAC5D,YAAA;AACN,EAAA,OAAO;AAAA,IACL,GAAI,SAAA,KAAc,MAAA,GAAY,EAAC,GAAI,EAAE,SAAA,EAAU;AAAA,IAC/C,GAAI,cAAA,KAAmB,MAAA,GAAY,EAAC,GAAI,EAAE,aAAa,cAAA;AAAe,GACxE;AACF;AAEA,SAAS,gBAAgB,OAAA,EAA2B;AAClD,EAAA,OAAO;AAAA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A,KAAA,EACsB;AACtB,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,iBAAiB,kEAAkE,CAAA;AAAA,EAC3F;AACA,EAAA,MAAM,EAAE,QAAO,GAAI,KAAA;AACnB,EAAA,MAAM,GAAA,GAAM,aAAA,CAAc,OAAA,EAAS,MAAM,CAAA;AACzC,EAAA,MAAM,MAAA,GAAS,QAAQ,MAAA,IAAU,KAAA;AACjC,EAAA,MAAM,GAAA,GAAM,UAAU,OAAO,CAAA;AAC7B,EAAA,MAAM,MAAA,GAAS,MAAM,KAAA,CAAM,MAAA,CAAO,IAAA,CAAK;AAAA,IACrC,MAAA;AAAA,IACA,GAAA;AAAA,IACA,UAAA,EAAY,QAAQ,IAAA,IAAQ,IAAA;AAAA,IAC5B,SAAA,EAAW,WAAA,CAAY,OAAA,EAAS,GAAG;AAAA,GACpC,CAAA;AACD,EAAA,iBAAA,CAAkB,MAAA,EAAQ,KAAK,MAAM,CAAA;AACrC,EAAA,MAAM,GAAA,GAAkB;AAAA,IACtB,GAAG,aAAa,OAAO,CAAA;AAAA,IACvB,GAAA;AAAA;AAAA;AAAA,IAGA,cAAA,EAAgB,yBAAA;AAAA,MAA0B,WAAA;AAAA,MAAa,MACrD,mBAAmB,MAAA,EAAQ;AAAA,QACzB,MAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,IAAI,GAAA,CAAI,GAAG;AAAA,OACnB;AAAA,KACH;AAAA,IACA,cAAc,EAAC;AAAA,IACf,OAAO,KAAA,CAAM,KAAA;AAAA,IACb,OAAA,EAAS,CAAC,IAAA,KAAS,kBAAA,CAAmB,QAAQ,IAAA,EAAM,EAAE,MAAA,EAAQ,MAAA,EAAQ,CAAA;AAAA,IACtE;AAAA,GACF;AACA,EAAA,OAAO,EAAE,QAAQ,GAAA,EAAI;AACvB;;"}
|
|
1
|
+
{"version":3,"file":"document-run.mjs","sources":["../../src/api/document-run.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type { Config as RedoclyConfig } from \"@redocly/openapi-core\";\nimport { sourceEmptyError } from \"../adapters/redocly-loader/schema-load-errors.js\";\nimport type { DeprecationReporter } from \"../application/ports/deprecation-reporter.js\";\nimport type { Logger } from \"../application/ports/logger.js\";\nimport type { RefAccess, SchemaLoader } from \"../application/ports/schema-loader.js\";\nimport { withStackOverflowReported } from \"../application/stack-overflow.js\";\nimport {\n ineffectiveFixNotices,\n type OutputFix,\n outputFixNamesOf,\n resolveOutputFixes,\n} from \"../domain/output-fixes.js\";\nimport { WARNING_CODES, warningText } from \"../domain/warnings.js\";\nimport type { GeneratorOptions, OpenAPI3, SchemaSource } from \"../types.js\";\nimport { processCwd } from \"./default-ports.js\";\nimport { warnDiscriminatorValueConflicts } from \"./discriminator-conflict-warnings.js\";\nimport { findDiscriminators } from \"./discriminator-scan.js\";\nimport { resolveDocumentRef } from \"./document-refs.js\";\nimport { warnIdenticalPathTemplates } from \"./path-template-warnings.js\";\nimport type { RunContext } from \"./run-context.js\";\nimport { warnUnsupportedFeatures } from \"./unsupported-feature-warnings.js\";\n\n/** The ports of one generator run, wired by the Node API or the CLI (ENGINEERING_PLAN 4.5). */\nexport interface GeneratorPorts {\n readonly loader: SchemaLoader;\n readonly logger: Logger;\n /** Where the run reports the deprecated callback forms (ADR-004). */\n readonly deprecations: DeprecationReporter;\n /** The Redocly config the loader uses; the run's context exposes it as `ctx.redoc`. */\n readonly redoc: RedoclyConfig;\n /** A monotonic time in milliseconds, for debug durations. */\n readonly now: () => number;\n}\n\n/** A validated, bundled document, the local files it was read from, and the run's context. */\nexport interface DocumentRun {\n readonly schema: OpenAPI3;\n readonly localFiles: readonly URL[];\n readonly ctx: RunContext;\n}\n\n/** The context fields that are user flags, with the original defaults. */\ntype ContextFlags = Omit<\n RunContext,\n | \"discriminators\"\n | \"injectFooter\"\n | \"redoc\"\n | \"resolve\"\n | \"runFooter\"\n | \"legacyCallbackWarnings\"\n | \"logger\"\n | \"deprecations\"\n | \"fix\"\n>;\n\n/**\n * The directory that relative `$ref`s of an inline source resolve against, as a URL that ends in\n * a slash. A path is resolved and encoded (`#`, `%`, spaces); a URL without the slash gets one.\n */\nfunction sourceCwd(options: GeneratorOptions): URL {\n const { cwd } = options;\n if (cwd instanceof URL) {\n return cwd.pathname.endsWith(\"/\") ? cwd : new URL(`${cwd.pathname}/`, cwd);\n }\n const directory = path.resolve(cwd === undefined ? processCwd() : cwd.toString());\n return pathToFileURL(path.join(directory, path.sep));\n}\n\n/** The `$ref` limits of the options; a relative local root resolves against the cwd. */\nfunction refAccessOf(options: GeneratorOptions, cwd: URL): RefAccess {\n const { localRefRoot, remoteRefHosts } = options;\n const localRoot =\n typeof localRefRoot === \"string\"\n ? pathToFileURL(path.resolve(fileURLToPath(cwd), localRefRoot))\n : localRefRoot;\n return {\n ...(localRoot === undefined ? {} : { localRoot }),\n ...(remoteRefHosts === undefined ? {} : { remoteHosts: remoteRefHosts }),\n };\n}\n\nfunction callbackOptions(options: GeneratorOptions) {\n return {\n irCallbacks: options.irCallbacks === true,\n postTransform: typeof options.postTransform === \"function\" ? options.postTransform : undefined,\n transform: typeof options.transform === \"function\" ? options.transform : undefined,\n transformProperty:\n typeof options.transformProperty === \"function\" ? options.transformProperty : undefined,\n };\n}\n\nfunction contextFlags(options: GeneratorOptions): ContextFlags {\n return {\n additionalProperties: options.additionalProperties ?? false,\n alphabetize: options.alphabetize ?? false,\n arrayLength: options.arrayLength ?? false,\n binaryAsBlob: options.binaryAsBlob ?? false,\n defaultNonNullable: options.defaultNonNullable ?? true,\n emptyObjectsUnknown: options.emptyObjectsUnknown ?? false,\n enum: options.enum ?? false,\n enumValues: options.enumValues ?? false,\n conditionalEnums: options.conditionalEnums ?? false,\n dedupeEnums: options.dedupeEnums ?? false,\n excludeDeprecated: options.excludeDeprecated ?? false,\n exportType: options.exportType ?? false,\n immutable: options.immutable ?? false,\n rootTypes: options.rootTypes ?? false,\n rootTypesNoSchemaPrefix: options.rootTypesNoSchemaPrefix ?? false,\n rootTypesKeepCasing: options.rootTypesKeepCasing ?? false,\n pathParamsAsTypes: options.pathParamsAsTypes ?? false,\n propertiesRequiredByDefault: options.propertiesRequiredByDefault ?? false,\n silent: options.silent ?? false,\n ...(options.inject === undefined ? {} : { inject: options.inject }),\n makePathsEnum: options.makePathsEnum ?? false,\n generatePathParams: options.generatePathParams ?? false,\n readWriteMarkers: options.readWriteMarkers ?? false,\n ...callbackOptions(options),\n };\n}\n\n/**\n * The fixes of the options, `all` expanded; fails with `OPTION_FIX_UNKNOWN` for another name.\n * A fix named without the option it needs is reported, since it changes nothing.\n */\nfunction outputFixesOf(options: GeneratorOptions, logger: Logger): readonly OutputFix[] {\n const names = outputFixNamesOf(options.fix ?? []);\n for (const notice of ineffectiveFixNotices(names, (option) => options[option] === true)) {\n logger.warn(warningText(notice, WARNING_CODES.FIX_NEEDS_OPTION));\n }\n return [...resolveOutputFixes(names)];\n}\n\n/** The warnings about the loaded document itself, before it is transformed. */\nfunction warnAboutDocument(schema: OpenAPI3, fix: readonly OutputFix[], logger: Logger): void {\n withStackOverflowReported(\"transform\", () => warnUnsupportedFeatures(schema, logger));\n withStackOverflowReported(\"transform\", () =>\n warnDiscriminatorValueConflicts(schema, fix, logger),\n );\n warnIdenticalPathTemplates(schema, logger);\n}\n\n/**\n * Load the source through the ports, then build the run's context from the options. The fix names\n * are checked first, so a typo fails before the document is read.\n */\nexport async function createDocumentRun(\n source: SchemaSource,\n options: GeneratorOptions,\n ports: GeneratorPorts,\n): Promise<DocumentRun> {\n if (!source) {\n throw sourceEmptyError(\"Empty schema. Please specify a URL, file path, or Redocly Config\");\n }\n const { logger } = ports;\n const fix = outputFixesOf(options, logger);\n const silent = options.silent ?? false;\n const cwd = sourceCwd(options);\n const { document: schema, localFiles } = await ports.loader.load({\n source,\n cwd,\n shouldLint: options.lint ?? true,\n refAccess: refAccessOf(options, cwd),\n });\n warnAboutDocument(schema, fix, logger);\n const ctx: RunContext = {\n ...contextFlags(options),\n fix,\n // The scan walks every schema before the transform does, so on a larger stack, where loading\n // passed, it is the first step to run out.\n discriminators: withStackOverflowReported(\"transform\", () =>\n findDiscriminators(schema, {\n silent,\n logger,\n fixes: new Set(fix),\n }),\n ),\n injectFooter: [],\n redoc: ports.redoc,\n resolve: ($ref) => resolveDocumentRef(schema, $ref, { silent, logger }),\n logger,\n deprecations: ports.deprecations,\n };\n return { schema, localFiles, ctx };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AA6DA,SAAS,UAAU,OAAA,EAAgC;AACjD,EAAA,MAAM,EAAE,KAAI,GAAI,OAAA;AAChB,EAAA,IAAI,eAAe,GAAA,EAAK;AACtB,IAAA,OAAO,GAAA,CAAI,QAAA,CAAS,QAAA,CAAS,GAAG,CAAA,GAAI,GAAA,GAAM,IAAI,GAAA,CAAI,CAAA,EAAG,GAAA,CAAI,QAAQ,CAAA,CAAA,CAAA,EAAK,GAAG,CAAA;AAAA,EAC3E;AACA,EAAA,MAAM,SAAA,GAAY,KAAK,OAAA,CAAQ,GAAA,KAAQ,SAAY,UAAA,EAAW,GAAI,GAAA,CAAI,QAAA,EAAU,CAAA;AAChF,EAAA,OAAO,cAAc,IAAA,CAAK,IAAA,CAAK,SAAA,EAAW,IAAA,CAAK,GAAG,CAAC,CAAA;AACrD;AAGA,SAAS,WAAA,CAAY,SAA2B,GAAA,EAAqB;AACnE,EAAA,MAAM,EAAE,YAAA,EAAc,cAAA,EAAe,GAAI,OAAA;AACzC,EAAA,MAAM,SAAA,GACJ,OAAO,YAAA,KAAiB,QAAA,GACpB,aAAA,CAAc,IAAA,CAAK,OAAA,CAAQ,aAAA,CAAc,GAAG,CAAA,EAAG,YAAY,CAAC,CAAA,GAC5D,YAAA;AACN,EAAA,OAAO;AAAA,IACL,GAAI,SAAA,KAAc,MAAA,GAAY,EAAC,GAAI,EAAE,SAAA,EAAU;AAAA,IAC/C,GAAI,cAAA,KAAmB,MAAA,GAAY,EAAC,GAAI,EAAE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;AACA,EAAA,OAAO,EAAE,MAAA,EAAQ,UAAA,EAAY,GAAA,EAAI;AACnC;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const deprecations = require('../domain/deprecations.cjs');
|
|
4
4
|
const defaultPorts = require('./default-ports.cjs');
|
|
5
5
|
|
|
6
6
|
const IR_CALLBACKS_GUIDE_URL = "https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs/node.md#ir-callbacks";
|
|
@@ -9,6 +9,11 @@ const USES = {
|
|
|
9
9
|
postTransform: "`postTransform` receives TypeScript nodes",
|
|
10
10
|
transformProperty: "`transformProperty` receives TypeScript nodes"
|
|
11
11
|
};
|
|
12
|
+
const CODES = {
|
|
13
|
+
transform: deprecations.DEPRECATION_CODES.OPENAPI_TYPESAFE_DEP_TS_TRANSFORM,
|
|
14
|
+
postTransform: deprecations.DEPRECATION_CODES.OPENAPI_TYPESAFE_DEP_TS_POST_TRANSFORM,
|
|
15
|
+
transformProperty: deprecations.DEPRECATION_CODES.OPENAPI_TYPESAFE_DEP_TS_TRANSFORM_PROPERTY
|
|
16
|
+
};
|
|
12
17
|
function message(name) {
|
|
13
18
|
return `${USES[name]}. This form works in 1.x through the TypeScript bridge and is removed in 2.0. Use irCallbacks: true and return IR or type text instead: ${IR_CALLBACKS_GUIDE_URL}`;
|
|
14
19
|
}
|
|
@@ -18,9 +23,7 @@ function warnLegacyCallback(ctx, name) {
|
|
|
18
23
|
return;
|
|
19
24
|
}
|
|
20
25
|
ctx.legacyCallbackWarnings.add(name);
|
|
21
|
-
(ctx.
|
|
22
|
-
warnings.warningText(message(name), warnings.WARNING_CODES.LEGACY_CALLBACK_DEPRECATED)
|
|
23
|
-
);
|
|
26
|
+
(ctx.deprecations ?? defaultPorts.defaultDeprecationReporter()).report(CODES[name], message(name));
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
exports.IR_CALLBACKS_GUIDE_URL = IR_CALLBACKS_GUIDE_URL;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy-callback-warning.cjs","sources":["../../src/api/legacy-callback-warning.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"legacy-callback-warning.cjs","sources":["../../src/api/legacy-callback-warning.ts"],"sourcesContent":["import { DEPRECATION_CODES, type DeprecationCode } from \"../domain/deprecations.js\";\nimport type { LegacyCallbackName } from \"../types.js\";\nimport { defaultDeprecationReporter } from \"./default-ports.js\";\nimport type { RunContext } from \"./run-context.js\";\n\n/** Where the IR callbacks are documented; the warning points users there. */\nexport const IR_CALLBACKS_GUIDE_URL =\n \"https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs/node.md#ir-callbacks\";\n\nconst USES: Readonly<Record<LegacyCallbackName, string>> = {\n transform: \"`transform` returned a TypeScript node\",\n postTransform: \"`postTransform` receives TypeScript nodes\",\n transformProperty: \"`transformProperty` receives TypeScript nodes\",\n};\n\nconst CODES: Readonly<Record<LegacyCallbackName, DeprecationCode>> = {\n transform: DEPRECATION_CODES.OPENAPI_TYPESAFE_DEP_TS_TRANSFORM,\n postTransform: DEPRECATION_CODES.OPENAPI_TYPESAFE_DEP_TS_POST_TRANSFORM,\n transformProperty: DEPRECATION_CODES.OPENAPI_TYPESAFE_DEP_TS_TRANSFORM_PROPERTY,\n};\n\nfunction message(name: LegacyCallbackName): string {\n return (\n `${USES[name]}. This form works in 1.x through the TypeScript bridge and is removed in 2.0. ` +\n `Use irCallbacks: true and return IR or type text instead: ${IR_CALLBACKS_GUIDE_URL}`\n );\n}\n\n/**\n * Report a deprecated callback form once per run and callback, as a deprecation (not through the\n * logger, so `silent` does not hide it). The Node.js reporter shows each code once per process.\n */\nexport function warnLegacyCallback(ctx: RunContext, name: LegacyCallbackName): void {\n ctx.legacyCallbackWarnings ??= new Set();\n if (ctx.legacyCallbackWarnings.has(name)) {\n return;\n }\n ctx.legacyCallbackWarnings.add(name);\n (ctx.deprecations ?? defaultDeprecationReporter()).report(CODES[name], message(name));\n}\n"],"names":["DEPRECATION_CODES","defaultDeprecationReporter"],"mappings":";;;;;AAMO,MAAM,sBAAA,GACX;AAEF,MAAM,IAAA,GAAqD;AAAA,EACzD,SAAA,EAAW,wCAAA;AAAA,EACX,aAAA,EAAe,2CAAA;AAAA,EACf,iBAAA,EAAmB;AACrB,CAAA;AAEA,MAAM,KAAA,GAA+D;AAAA,EACnE,WAAWA,8BAAA,CAAkB,iCAAA;AAAA,EAC7B,eAAeA,8BAAA,CAAkB,sCAAA;AAAA,EACjC,mBAAmBA,8BAAA,CAAkB;AACvC,CAAA;AAEA,SAAS,QAAQ,IAAA,EAAkC;AACjD,EAAA,OACE,CAAA,EAAG,IAAA,CAAK,IAAI,CAAC,2IACgD,sBAAsB,CAAA,CAAA;AAEvF;AAMO,SAAS,kBAAA,CAAmB,KAAiB,IAAA,EAAgC;AAClF,EAAA,GAAA,CAAI,sBAAA,yBAA+B,GAAA,EAAI;AACvC,EAAA,IAAI,GAAA,CAAI,sBAAA,CAAuB,GAAA,CAAI,IAAI,CAAA,EAAG;AACxC,IAAA;AAAA,EACF;AACA,EAAA,GAAA,CAAI,sBAAA,CAAuB,IAAI,IAAI,CAAA;AACnC,EAAA,CAAC,GAAA,CAAI,YAAA,IAAgBC,uCAAA,EAA2B,EAAG,MAAA,CAAO,MAAM,IAAI,CAAA,EAAG,OAAA,CAAQ,IAAI,CAAC,CAAA;AACtF;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { DEPRECATION_CODES } from '../domain/deprecations.mjs';
|
|
2
|
+
import { defaultDeprecationReporter } from './default-ports.mjs';
|
|
3
3
|
|
|
4
4
|
const IR_CALLBACKS_GUIDE_URL = "https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs/node.md#ir-callbacks";
|
|
5
5
|
const USES = {
|
|
@@ -7,6 +7,11 @@ const USES = {
|
|
|
7
7
|
postTransform: "`postTransform` receives TypeScript nodes",
|
|
8
8
|
transformProperty: "`transformProperty` receives TypeScript nodes"
|
|
9
9
|
};
|
|
10
|
+
const CODES = {
|
|
11
|
+
transform: DEPRECATION_CODES.OPENAPI_TYPESAFE_DEP_TS_TRANSFORM,
|
|
12
|
+
postTransform: DEPRECATION_CODES.OPENAPI_TYPESAFE_DEP_TS_POST_TRANSFORM,
|
|
13
|
+
transformProperty: DEPRECATION_CODES.OPENAPI_TYPESAFE_DEP_TS_TRANSFORM_PROPERTY
|
|
14
|
+
};
|
|
10
15
|
function message(name) {
|
|
11
16
|
return `${USES[name]}. This form works in 1.x through the TypeScript bridge and is removed in 2.0. Use irCallbacks: true and return IR or type text instead: ${IR_CALLBACKS_GUIDE_URL}`;
|
|
12
17
|
}
|
|
@@ -16,9 +21,7 @@ function warnLegacyCallback(ctx, name) {
|
|
|
16
21
|
return;
|
|
17
22
|
}
|
|
18
23
|
ctx.legacyCallbackWarnings.add(name);
|
|
19
|
-
(ctx.
|
|
20
|
-
warningText(message(name), WARNING_CODES.LEGACY_CALLBACK_DEPRECATED)
|
|
21
|
-
);
|
|
24
|
+
(ctx.deprecations ?? defaultDeprecationReporter()).report(CODES[name], message(name));
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
export { IR_CALLBACKS_GUIDE_URL, warnLegacyCallback };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy-callback-warning.mjs","sources":["../../src/api/legacy-callback-warning.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"legacy-callback-warning.mjs","sources":["../../src/api/legacy-callback-warning.ts"],"sourcesContent":["import { DEPRECATION_CODES, type DeprecationCode } from \"../domain/deprecations.js\";\nimport type { LegacyCallbackName } from \"../types.js\";\nimport { defaultDeprecationReporter } from \"./default-ports.js\";\nimport type { RunContext } from \"./run-context.js\";\n\n/** Where the IR callbacks are documented; the warning points users there. */\nexport const IR_CALLBACKS_GUIDE_URL =\n \"https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs/node.md#ir-callbacks\";\n\nconst USES: Readonly<Record<LegacyCallbackName, string>> = {\n transform: \"`transform` returned a TypeScript node\",\n postTransform: \"`postTransform` receives TypeScript nodes\",\n transformProperty: \"`transformProperty` receives TypeScript nodes\",\n};\n\nconst CODES: Readonly<Record<LegacyCallbackName, DeprecationCode>> = {\n transform: DEPRECATION_CODES.OPENAPI_TYPESAFE_DEP_TS_TRANSFORM,\n postTransform: DEPRECATION_CODES.OPENAPI_TYPESAFE_DEP_TS_POST_TRANSFORM,\n transformProperty: DEPRECATION_CODES.OPENAPI_TYPESAFE_DEP_TS_TRANSFORM_PROPERTY,\n};\n\nfunction message(name: LegacyCallbackName): string {\n return (\n `${USES[name]}. This form works in 1.x through the TypeScript bridge and is removed in 2.0. ` +\n `Use irCallbacks: true and return IR or type text instead: ${IR_CALLBACKS_GUIDE_URL}`\n );\n}\n\n/**\n * Report a deprecated callback form once per run and callback, as a deprecation (not through the\n * logger, so `silent` does not hide it). The Node.js reporter shows each code once per process.\n */\nexport function warnLegacyCallback(ctx: RunContext, name: LegacyCallbackName): void {\n ctx.legacyCallbackWarnings ??= new Set();\n if (ctx.legacyCallbackWarnings.has(name)) {\n return;\n }\n ctx.legacyCallbackWarnings.add(name);\n (ctx.deprecations ?? defaultDeprecationReporter()).report(CODES[name], message(name));\n}\n"],"names":[],"mappings":";;;AAMO,MAAM,sBAAA,GACX;AAEF,MAAM,IAAA,GAAqD;AAAA,EACzD,SAAA,EAAW,wCAAA;AAAA,EACX,aAAA,EAAe,2CAAA;AAAA,EACf,iBAAA,EAAmB;AACrB,CAAA;AAEA,MAAM,KAAA,GAA+D;AAAA,EACnE,WAAW,iBAAA,CAAkB,iCAAA;AAAA,EAC7B,eAAe,iBAAA,CAAkB,sCAAA;AAAA,EACjC,mBAAmB,iBAAA,CAAkB;AACvC,CAAA;AAEA,SAAS,QAAQ,IAAA,EAAkC;AACjD,EAAA,OACE,CAAA,EAAG,IAAA,CAAK,IAAI,CAAC,2IACgD,sBAAsB,CAAA,CAAA;AAEvF;AAMO,SAAS,kBAAA,CAAmB,KAAiB,IAAA,EAAgC;AAClF,EAAA,GAAA,CAAI,sBAAA,yBAA+B,GAAA,EAAI;AACvC,EAAA,IAAI,GAAA,CAAI,sBAAA,CAAuB,GAAA,CAAI,IAAI,CAAA,EAAG;AACxC,IAAA;AAAA,EACF;AACA,EAAA,GAAA,CAAI,sBAAA,CAAuB,IAAI,IAAI,CAAA;AACnC,EAAA,CAAC,GAAA,CAAI,YAAA,IAAgB,0BAAA,EAA2B,EAAG,MAAA,CAAO,MAAM,IAAI,CAAA,EAAG,OAAA,CAAQ,IAAI,CAAC,CAAA;AACtF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy-utils.cjs","sources":["../../src/api/legacy-utils.ts"],"sourcesContent":["import colors from \"ansi-colors\";\nimport { formatDuration } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { DebugGroup } from \"../application/ports/logger.js\";\nimport { discriminatorProperty } from \"../application/transform/schema/discriminator-property.js\";\nimport type { IrPropertySignature } from \"../domain/ir/nodes.js\";\nimport { createRef as createDomainRef } from \"../domain/openapi/json-pointer.js\";\nimport type { DiscriminatorObject } from \"../types.js\";\nimport { defaultLogger, terminalSupportsColor } from \"./default-ports.js\";\nimport { type ResolveRefOptions, resolveDocumentRef, walkDocument } from \"./document-refs.js\";\n\n/**\n * The original's exported utilities, kept for 1.x (ADR-004, decision 9). The generator itself\n * logs through the Logger port; `debug`, `warn` and `error` here write through the default one.\n */\n\n// The exported `c` is the shared ansi-colors instance, switched off at import when the terminal has\n// no colors, as the original did. The generator's own logger uses a separate instance.\nif (!terminalSupportsColor()) {\n colors.enabled = false;\n}\n\n/**\n * The shared ansi-colors instance.\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9). Use a color library directly.\n */\nexport const c = colors;\n\n/**\n * The discriminator property of a schema at `path`, typed as its discriminator value. Returns IR\n * (task 6.2), like the exported transformers.\n */\nexport function createDiscriminatorProperty(\n discriminator: DiscriminatorObject,\n { path, readonly = false }: { path: string; readonly?: boolean },\n): IrPropertySignature {\n return discriminatorProperty(discriminator, path, readonly);\n}\n\n
|
|
1
|
+
{"version":3,"file":"legacy-utils.cjs","sources":["../../src/api/legacy-utils.ts"],"sourcesContent":["import colors from \"ansi-colors\";\nimport { formatDuration } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { DebugGroup } from \"../application/ports/logger.js\";\nimport { discriminatorProperty } from \"../application/transform/schema/discriminator-property.js\";\nimport type { IrPropertySignature } from \"../domain/ir/nodes.js\";\nimport { createRef as createDomainRef } from \"../domain/openapi/json-pointer.js\";\nimport type { DiscriminatorObject } from \"../types.js\";\nimport { defaultLogger, terminalSupportsColor } from \"./default-ports.js\";\nimport { type ResolveRefOptions, resolveDocumentRef, walkDocument } from \"./document-refs.js\";\n\n/**\n * The original's exported utilities, kept for 1.x (ADR-004, decision 9). The generator itself\n * logs through the Logger port; `debug`, `warn` and `error` here write through the default one.\n */\n\n// The exported `c` is the shared ansi-colors instance, switched off at import when the terminal has\n// no colors, as the original did. The generator's own logger uses a separate instance.\nif (!terminalSupportsColor()) {\n colors.enabled = false;\n}\n\n/**\n * The shared ansi-colors instance.\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9). Use a color library directly.\n */\nexport const c = colors;\n\n/**\n * The discriminator property of a schema at `path`, typed as its discriminator value. Returns IR\n * (task 6.2), like the exported transformers.\n */\nexport function createDiscriminatorProperty(\n discriminator: DiscriminatorObject,\n { path, readonly = false }: { path: string; readonly?: boolean },\n): IrPropertySignature {\n return discriminatorProperty(discriminator, path, readonly);\n}\n\n/**\n * Create a $ref pointer (even from other $refs). A part that contains `#/` is read as a `$ref`\n * and contributes its decoded segments, so it throws URIError for a malformed percent escape; any\n * other part is one segment. To append raw document keys, escape each one instead.\n */\nexport function createRef(parts: (number | string | undefined | null)[]): string {\n return createDomainRef(parts);\n}\n\n/**\n * Print debug message (cribbed from the `debug` package, but without all the bells & whistles\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9).\n */\nexport function debug(msg: string, group?: string, time?: number) {\n // Any group name was accepted; one the logger does not know prints in white, as before.\n defaultLogger(false).debug(msg, group as DebugGroup | undefined, time);\n}\n\n/**\n * Print error message\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9).\n */\nexport function error(msg: string) {\n defaultLogger(false).error(msg);\n}\n\n/** Format a performance log in a friendly format */\nexport function formatTime(t: number) {\n return typeof t === \"number\" ? formatDuration(t) : t;\n}\n\n/** Call Object.entries() and optionally sort */\nexport function getEntries<T>(\n obj: ArrayLike<T> | Record<string, T>,\n options?: {\n alphabetize?: boolean;\n excludeDeprecated?: boolean;\n },\n) {\n let entries = Object.entries(obj);\n if (options?.alphabetize) {\n entries.sort(([a], [b]) => a.localeCompare(b, \"en-us\", { numeric: true }));\n }\n if (options?.excludeDeprecated) {\n entries = entries.filter(\n ([, v]) => !(v && typeof v === \"object\" && \"deprecated\" in v && v.deprecated),\n );\n }\n return entries;\n}\n\nexport type { ResolveRefOptions } from \"./document-refs.js\";\n\n/**\n * resolve a $ref in a schema\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9).\n */\nexport function resolveRef<T>(\n schema: unknown,\n $ref: string,\n options: ResolveRefOptions,\n): T | undefined {\n return resolveDocumentRef<T>(schema, $ref, options);\n}\n\n/**\n * Walk through any JSON-serializable (i.e. non-circular) object\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9).\n */\nexport function walk(\n obj: unknown,\n cb: (value: Record<string, unknown>, path: (string | number)[]) => void,\n path: (string | number)[] = [],\n): void {\n walkDocument(obj, cb, path);\n}\n\n/**\n * Print warning message\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9).\n */\nexport function warn(msg: string, silent = false) {\n defaultLogger(silent).warn(msg);\n}\n"],"names":["terminalSupportsColor","colors","discriminatorProperty","createDomainRef","default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AAA,IAAK,OAAO,CAAA,KAAM,QAAA,IAAY,YAAA,IAAgB,CAAA,IAAK,CAAA,CAAE,UAAA;AAAA,KACpE;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAQO,SAAS,UAAA,CACd,MAAA,EACA,IAAA,EACA,OAAA,EACe;AACf,EAAA,OAAOC,+BAAA,CAAsB,MAAA,EAAQ,IAAA,EAAM,OAAO,CAAA;AACpD;AAMO,SAAS,IAAA,CACd,GAAA,EACA,EAAA,EACA,IAAA,GAA4B,EAAC,EACvB;AACN,EAAAC,yBAAA,CAAa,GAAA,EAAK,IAAI,IAAI,CAAA;AAC5B;AAMO,SAAS,IAAA,CAAK,GAAA,EAAa,MAAA,GAAS,KAAA,EAAO;AAChD,EAAAH,0BAAA,CAAc,MAAM,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA;AAChC;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy-utils.mjs","sources":["../../src/api/legacy-utils.ts"],"sourcesContent":["import colors from \"ansi-colors\";\nimport { formatDuration } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { DebugGroup } from \"../application/ports/logger.js\";\nimport { discriminatorProperty } from \"../application/transform/schema/discriminator-property.js\";\nimport type { IrPropertySignature } from \"../domain/ir/nodes.js\";\nimport { createRef as createDomainRef } from \"../domain/openapi/json-pointer.js\";\nimport type { DiscriminatorObject } from \"../types.js\";\nimport { defaultLogger, terminalSupportsColor } from \"./default-ports.js\";\nimport { type ResolveRefOptions, resolveDocumentRef, walkDocument } from \"./document-refs.js\";\n\n/**\n * The original's exported utilities, kept for 1.x (ADR-004, decision 9). The generator itself\n * logs through the Logger port; `debug`, `warn` and `error` here write through the default one.\n */\n\n// The exported `c` is the shared ansi-colors instance, switched off at import when the terminal has\n// no colors, as the original did. The generator's own logger uses a separate instance.\nif (!terminalSupportsColor()) {\n colors.enabled = false;\n}\n\n/**\n * The shared ansi-colors instance.\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9). Use a color library directly.\n */\nexport const c = colors;\n\n/**\n * The discriminator property of a schema at `path`, typed as its discriminator value. Returns IR\n * (task 6.2), like the exported transformers.\n */\nexport function createDiscriminatorProperty(\n discriminator: DiscriminatorObject,\n { path, readonly = false }: { path: string; readonly?: boolean },\n): IrPropertySignature {\n return discriminatorProperty(discriminator, path, readonly);\n}\n\n
|
|
1
|
+
{"version":3,"file":"legacy-utils.mjs","sources":["../../src/api/legacy-utils.ts"],"sourcesContent":["import colors from \"ansi-colors\";\nimport { formatDuration } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { DebugGroup } from \"../application/ports/logger.js\";\nimport { discriminatorProperty } from \"../application/transform/schema/discriminator-property.js\";\nimport type { IrPropertySignature } from \"../domain/ir/nodes.js\";\nimport { createRef as createDomainRef } from \"../domain/openapi/json-pointer.js\";\nimport type { DiscriminatorObject } from \"../types.js\";\nimport { defaultLogger, terminalSupportsColor } from \"./default-ports.js\";\nimport { type ResolveRefOptions, resolveDocumentRef, walkDocument } from \"./document-refs.js\";\n\n/**\n * The original's exported utilities, kept for 1.x (ADR-004, decision 9). The generator itself\n * logs through the Logger port; `debug`, `warn` and `error` here write through the default one.\n */\n\n// The exported `c` is the shared ansi-colors instance, switched off at import when the terminal has\n// no colors, as the original did. The generator's own logger uses a separate instance.\nif (!terminalSupportsColor()) {\n colors.enabled = false;\n}\n\n/**\n * The shared ansi-colors instance.\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9). Use a color library directly.\n */\nexport const c = colors;\n\n/**\n * The discriminator property of a schema at `path`, typed as its discriminator value. Returns IR\n * (task 6.2), like the exported transformers.\n */\nexport function createDiscriminatorProperty(\n discriminator: DiscriminatorObject,\n { path, readonly = false }: { path: string; readonly?: boolean },\n): IrPropertySignature {\n return discriminatorProperty(discriminator, path, readonly);\n}\n\n/**\n * Create a $ref pointer (even from other $refs). A part that contains `#/` is read as a `$ref`\n * and contributes its decoded segments, so it throws URIError for a malformed percent escape; any\n * other part is one segment. To append raw document keys, escape each one instead.\n */\nexport function createRef(parts: (number | string | undefined | null)[]): string {\n return createDomainRef(parts);\n}\n\n/**\n * Print debug message (cribbed from the `debug` package, but without all the bells & whistles\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9).\n */\nexport function debug(msg: string, group?: string, time?: number) {\n // Any group name was accepted; one the logger does not know prints in white, as before.\n defaultLogger(false).debug(msg, group as DebugGroup | undefined, time);\n}\n\n/**\n * Print error message\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9).\n */\nexport function error(msg: string) {\n defaultLogger(false).error(msg);\n}\n\n/** Format a performance log in a friendly format */\nexport function formatTime(t: number) {\n return typeof t === \"number\" ? formatDuration(t) : t;\n}\n\n/** Call Object.entries() and optionally sort */\nexport function getEntries<T>(\n obj: ArrayLike<T> | Record<string, T>,\n options?: {\n alphabetize?: boolean;\n excludeDeprecated?: boolean;\n },\n) {\n let entries = Object.entries(obj);\n if (options?.alphabetize) {\n entries.sort(([a], [b]) => a.localeCompare(b, \"en-us\", { numeric: true }));\n }\n if (options?.excludeDeprecated) {\n entries = entries.filter(\n ([, v]) => !(v && typeof v === \"object\" && \"deprecated\" in v && v.deprecated),\n );\n }\n return entries;\n}\n\nexport type { ResolveRefOptions } from \"./document-refs.js\";\n\n/**\n * resolve a $ref in a schema\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9).\n */\nexport function resolveRef<T>(\n schema: unknown,\n $ref: string,\n options: ResolveRefOptions,\n): T | undefined {\n return resolveDocumentRef<T>(schema, $ref, options);\n}\n\n/**\n * Walk through any JSON-serializable (i.e. non-circular) object\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9).\n */\nexport function walk(\n obj: unknown,\n cb: (value: Record<string, unknown>, path: (string | number)[]) => void,\n path: (string | number)[] = [],\n): void {\n walkDocument(obj, cb, path);\n}\n\n/**\n * Print warning message\n * @deprecated Kept for 1.x; removed in 2.0 (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GAAG,CAAC,CAAA,KAAM,EAAE,CAAA,IAAK,OAAO,CAAA,KAAM,QAAA,IAAY,YAAA,IAAgB,CAAA,IAAK,CAAA,CAAE,UAAA;AAAA,KACpE;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAQO,SAAS,UAAA,CACd,MAAA,EACA,IAAA,EACA,OAAA,EACe;AACf,EAAA,OAAO,kBAAA,CAAsB,MAAA,EAAQ,IAAA,EAAM,OAAO,CAAA;AACpD;AAMO,SAAS,IAAA,CACd,GAAA,EACA,EAAA,EACA,IAAA,GAA4B,EAAC,EACvB;AACN,EAAA,YAAA,CAAa,GAAA,EAAK,IAAI,IAAI,CAAA;AAC5B;AAMO,SAAS,IAAA,CAAK,GAAA,EAAa,MAAA,GAAS,KAAA,EAAO;AAChD,EAAA,aAAA,CAAc,MAAM,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA;AAChC;;"}
|
package/dist/api/openapi-ts.cjs
CHANGED
|
@@ -8,16 +8,19 @@ const defaultPorts = require('./default-ports.cjs');
|
|
|
8
8
|
const documentRun = require('./document-run.cjs');
|
|
9
9
|
const transformSchema = require('./transform-schema.cjs');
|
|
10
10
|
|
|
11
|
-
async function
|
|
12
|
-
const { schema, ctx } = await documentRun.createDocumentRun(source, options, ports);
|
|
11
|
+
async function generateDocument(source, options, ports) {
|
|
12
|
+
const { schema, localFiles, ctx } = await documentRun.createDocumentRun(source, options, ports);
|
|
13
13
|
const startedAt = ports.now();
|
|
14
|
-
const
|
|
14
|
+
const declarations = stackOverflow.withStackOverflowReported("transform", () => transformSchema.default(schema, ctx));
|
|
15
15
|
ports.logger.debug(
|
|
16
16
|
"Completed AST transformation for entire document",
|
|
17
17
|
"ts",
|
|
18
18
|
ports.now() - startedAt
|
|
19
19
|
);
|
|
20
|
-
return
|
|
20
|
+
return { declarations, localFiles };
|
|
21
|
+
}
|
|
22
|
+
async function generateDeclarations(source, options, ports) {
|
|
23
|
+
return (await generateDocument(source, options, ports)).declarations;
|
|
21
24
|
}
|
|
22
25
|
async function defaultGeneratorPorts(options) {
|
|
23
26
|
const logger = defaultPorts.defaultLogger(options.silent ?? false);
|
|
@@ -29,7 +32,7 @@ async function defaultGeneratorPorts(options) {
|
|
|
29
32
|
remoteRefTimeoutMs: defaultPorts.REMOTE_REF_TIMEOUT_MS,
|
|
30
33
|
remoteDocumentLimits: defaultPorts.DEFAULT_REMOTE_DOCUMENT_LIMITS
|
|
31
34
|
});
|
|
32
|
-
return { loader, logger, redoc, now: defaultPorts.monotonicNow };
|
|
35
|
+
return { loader, logger, deprecations: defaultPorts.defaultDeprecationReporter(), redoc, now: defaultPorts.monotonicNow };
|
|
33
36
|
}
|
|
34
37
|
async function openapiTS(source, options = {}) {
|
|
35
38
|
return generateDeclarations(source, options, await defaultGeneratorPorts(options));
|
|
@@ -38,4 +41,5 @@ async function openapiTS(source, options = {}) {
|
|
|
38
41
|
exports.default = openapiTS;
|
|
39
42
|
exports.defaultGeneratorPorts = defaultGeneratorPorts;
|
|
40
43
|
exports.generateDeclarations = generateDeclarations;
|
|
44
|
+
exports.generateDocument = generateDocument;
|
|
41
45
|
//# sourceMappingURL=openapi-ts.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi-ts.cjs","sources":["../../src/api/openapi-ts.ts"],"sourcesContent":["import { createRedoclySchemaLoader } from \"../adapters/redocly-loader/redocly-schema-loader.js\";\nimport { withStackOverflowReported } from \"../application/stack-overflow.js\";\nimport type { IrDeclaration } from \"../domain/ir/nodes.js\";\nimport type { GeneratorOptions, SchemaSource } from \"../types.js\";\nimport {\n DEFAULT_REMOTE_DOCUMENT_LIMITS,\n defaultLogger,\n defaultRedoclyConfig,\n monotonicNow,\n REMOTE_REF_TIMEOUT_MS,\n} from \"./default-ports.js\";\nimport { createDocumentRun, type GeneratorPorts } from \"./document-run.js\";\nimport transformSchema from \"./transform-schema.js\";\n\n/**\n * The Node API's composition root (ENGINEERING_PLAN 4.5): `openapiTS` wires the default adapters;\n * `generateDeclarations` runs with any ports, which is how the CLI calls it.\n */\n\n/** Load, validate and bundle the source, then transform it into IR declarations. */\nexport async function
|
|
1
|
+
{"version":3,"file":"openapi-ts.cjs","sources":["../../src/api/openapi-ts.ts"],"sourcesContent":["import { createRedoclySchemaLoader } from \"../adapters/redocly-loader/redocly-schema-loader.js\";\nimport { withStackOverflowReported } from \"../application/stack-overflow.js\";\nimport type { IrDeclaration } from \"../domain/ir/nodes.js\";\nimport type { GeneratorOptions, SchemaSource } from \"../types.js\";\nimport {\n DEFAULT_REMOTE_DOCUMENT_LIMITS,\n defaultDeprecationReporter,\n defaultLogger,\n defaultRedoclyConfig,\n monotonicNow,\n REMOTE_REF_TIMEOUT_MS,\n} from \"./default-ports.js\";\nimport { createDocumentRun, type GeneratorPorts } from \"./document-run.js\";\nimport transformSchema from \"./transform-schema.js\";\n\n/**\n * The Node API's composition root (ENGINEERING_PLAN 4.5): `openapiTS` wires the default adapters;\n * `generateDeclarations` runs with any ports, which is how the CLI calls it.\n */\n\n/** The declarations of one document, and the local files it was read from. */\nexport interface GeneratedDocument {\n readonly declarations: IrDeclaration[];\n readonly localFiles: readonly URL[];\n}\n\n/** Load, validate and bundle the source, then transform it into IR declarations. */\nexport async function generateDocument(\n source: SchemaSource,\n options: GeneratorOptions,\n ports: GeneratorPorts,\n): Promise<GeneratedDocument> {\n const { schema, localFiles, ctx } = await createDocumentRun(source, options, ports);\n const startedAt = ports.now();\n const declarations = withStackOverflowReported(\"transform\", () => transformSchema(schema, ctx));\n ports.logger.debug(\n \"Completed AST transformation for entire document\",\n \"ts\",\n ports.now() - startedAt,\n );\n return { declarations, localFiles };\n}\n\n/** As `generateDocument`, the declarations only. */\nexport async function generateDeclarations(\n source: SchemaSource,\n options: GeneratorOptions,\n ports: GeneratorPorts,\n): Promise<IrDeclaration[]> {\n return (await generateDocument(source, options, ports)).declarations;\n}\n\n/**\n * The default ports: the terminal logger, Node.js deprecation warnings, the given or default\n * Redocly config, Redocly loading.\n */\nexport async function defaultGeneratorPorts(options: GeneratorOptions): Promise<GeneratorPorts> {\n const logger = defaultLogger(options.silent ?? false);\n const redoc = options.redocly ?? (await defaultRedoclyConfig());\n const loader = createRedoclySchemaLoader({\n redoc,\n logger,\n now: monotonicNow,\n remoteRefTimeoutMs: REMOTE_REF_TIMEOUT_MS,\n remoteDocumentLimits: DEFAULT_REMOTE_DOCUMENT_LIMITS,\n });\n return { loader, logger, deprecations: defaultDeprecationReporter(), redoc, now: monotonicNow };\n}\n\n/**\n * Convert an OpenAPI schema to TypeScript declarations (IR nodes; print them with `astToString`)\n * @param {string|URL|object|Readable} source OpenAPI schema source:\n * - YAML: string\n * - JSON: parsed object\n * - URL: URL to a YAML or JSON file (local or remote)\n * - Readable: Readable stream of YAML or JSON\n */\nexport default async function openapiTS(\n source: SchemaSource,\n options: GeneratorOptions = {},\n): Promise<IrDeclaration[]> {\n return generateDeclarations(source, options, await defaultGeneratorPorts(options));\n}\n"],"names":["createDocumentRun","withStackOverflowReported","transformSchema","defaultLogger","defaultRedoclyConfig","createRedoclySchemaLoader","monotonicNow","REMOTE_REF_TIMEOUT_MS","DEFAULT_REMOTE_DOCUMENT_LIMITS","defaultDeprecationReporter"],"mappings":";;;;;;;;;;AA2BA,eAAsB,gBAAA,CACpB,MAAA,EACA,OAAA,EACA,KAAA,EAC4B;AAC5B,EAAA,MAAM,EAAE,QAAQ,UAAA,EAAY,GAAA,KAAQ,MAAMA,6BAAA,CAAkB,MAAA,EAAQ,OAAA,EAAS,KAAK,CAAA;AAClF,EAAA,MAAM,SAAA,GAAY,MAAM,GAAA,EAAI;AAC5B,EAAA,MAAM,eAAeC,uCAAA,CAA0B,WAAA,EAAa,MAAMC,uBAAA,CAAgB,MAAA,EAAQ,GAAG,CAAC,CAAA;AAC9F,EAAA,KAAA,CAAM,MAAA,CAAO,KAAA;AAAA,IACX,kDAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA,CAAM,KAAI,GAAI;AAAA,GAChB;AACA,EAAA,OAAO,EAAE,cAAc,UAAA,EAAW;AACpC;AAGA,eAAsB,oBAAA,CACpB,MAAA,EACA,OAAA,EACA,KAAA,EAC0B;AAC1B,EAAA,OAAA,CAAQ,MAAM,gBAAA,CAAiB,MAAA,EAAQ,OAAA,EAAS,KAAK,CAAA,EAAG,YAAA;AAC1D;AAMA,eAAsB,sBAAsB,OAAA,EAAoD;AAC9F,EAAA,MAAM,MAAA,GAASC,0BAAA,CAAc,OAAA,CAAQ,MAAA,IAAU,KAAK,CAAA;AACpD,EAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,OAAA,IAAY,MAAMC,iCAAA,EAAqB;AAC7D,EAAA,MAAM,SAASC,6CAAA,CAA0B;AAAA,IACvC,KAAA;AAAA,IACA,MAAA;AAAA,IACA,GAAA,EAAKC,yBAAA;AAAA,IACL,kBAAA,EAAoBC,kCAAA;AAAA,IACpB,oBAAA,EAAsBC;AAAA,GACvB,CAAA;AACD,EAAA,OAAO,EAAE,QAAQ,MAAA,EAAQ,YAAA,EAAcC,yCAA2B,EAAG,KAAA,EAAO,KAAKH,yBAAA,EAAa;AAChG;AAUA,eAA8B,SAAA,CAC5B,MAAA,EACA,OAAA,GAA4B,EAAC,EACH;AAC1B,EAAA,OAAO,qBAAqB,MAAA,EAAQ,OAAA,EAAS,MAAM,qBAAA,CAAsB,OAAO,CAAC,CAAA;AACnF;;;;;"}
|
package/dist/api/openapi-ts.mjs
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { createRedoclySchemaLoader } from '../adapters/redocly-loader/redocly-schema-loader.mjs';
|
|
2
2
|
import { withStackOverflowReported } from '../application/stack-overflow.mjs';
|
|
3
|
-
import { defaultLogger, defaultRedoclyConfig, monotonicNow, DEFAULT_REMOTE_DOCUMENT_LIMITS, REMOTE_REF_TIMEOUT_MS } from './default-ports.mjs';
|
|
3
|
+
import { defaultLogger, defaultRedoclyConfig, monotonicNow, defaultDeprecationReporter, DEFAULT_REMOTE_DOCUMENT_LIMITS, REMOTE_REF_TIMEOUT_MS } from './default-ports.mjs';
|
|
4
4
|
import { createDocumentRun } from './document-run.mjs';
|
|
5
5
|
import transformSchema from './transform-schema.mjs';
|
|
6
6
|
|
|
7
|
-
async function
|
|
8
|
-
const { schema, ctx } = await createDocumentRun(source, options, ports);
|
|
7
|
+
async function generateDocument(source, options, ports) {
|
|
8
|
+
const { schema, localFiles, ctx } = await createDocumentRun(source, options, ports);
|
|
9
9
|
const startedAt = ports.now();
|
|
10
|
-
const
|
|
10
|
+
const declarations = withStackOverflowReported("transform", () => transformSchema(schema, ctx));
|
|
11
11
|
ports.logger.debug(
|
|
12
12
|
"Completed AST transformation for entire document",
|
|
13
13
|
"ts",
|
|
14
14
|
ports.now() - startedAt
|
|
15
15
|
);
|
|
16
|
-
return
|
|
16
|
+
return { declarations, localFiles };
|
|
17
|
+
}
|
|
18
|
+
async function generateDeclarations(source, options, ports) {
|
|
19
|
+
return (await generateDocument(source, options, ports)).declarations;
|
|
17
20
|
}
|
|
18
21
|
async function defaultGeneratorPorts(options) {
|
|
19
22
|
const logger = defaultLogger(options.silent ?? false);
|
|
@@ -25,11 +28,11 @@ async function defaultGeneratorPorts(options) {
|
|
|
25
28
|
remoteRefTimeoutMs: REMOTE_REF_TIMEOUT_MS,
|
|
26
29
|
remoteDocumentLimits: DEFAULT_REMOTE_DOCUMENT_LIMITS
|
|
27
30
|
});
|
|
28
|
-
return { loader, logger, redoc, now: monotonicNow };
|
|
31
|
+
return { loader, logger, deprecations: defaultDeprecationReporter(), redoc, now: monotonicNow };
|
|
29
32
|
}
|
|
30
33
|
async function openapiTS(source, options = {}) {
|
|
31
34
|
return generateDeclarations(source, options, await defaultGeneratorPorts(options));
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
export { openapiTS as default, defaultGeneratorPorts, generateDeclarations };
|
|
37
|
+
export { openapiTS as default, defaultGeneratorPorts, generateDeclarations, generateDocument };
|
|
35
38
|
//# sourceMappingURL=openapi-ts.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi-ts.mjs","sources":["../../src/api/openapi-ts.ts"],"sourcesContent":["import { createRedoclySchemaLoader } from \"../adapters/redocly-loader/redocly-schema-loader.js\";\nimport { withStackOverflowReported } from \"../application/stack-overflow.js\";\nimport type { IrDeclaration } from \"../domain/ir/nodes.js\";\nimport type { GeneratorOptions, SchemaSource } from \"../types.js\";\nimport {\n DEFAULT_REMOTE_DOCUMENT_LIMITS,\n defaultLogger,\n defaultRedoclyConfig,\n monotonicNow,\n REMOTE_REF_TIMEOUT_MS,\n} from \"./default-ports.js\";\nimport { createDocumentRun, type GeneratorPorts } from \"./document-run.js\";\nimport transformSchema from \"./transform-schema.js\";\n\n/**\n * The Node API's composition root (ENGINEERING_PLAN 4.5): `openapiTS` wires the default adapters;\n * `generateDeclarations` runs with any ports, which is how the CLI calls it.\n */\n\n/** Load, validate and bundle the source, then transform it into IR declarations. */\nexport async function
|
|
1
|
+
{"version":3,"file":"openapi-ts.mjs","sources":["../../src/api/openapi-ts.ts"],"sourcesContent":["import { createRedoclySchemaLoader } from \"../adapters/redocly-loader/redocly-schema-loader.js\";\nimport { withStackOverflowReported } from \"../application/stack-overflow.js\";\nimport type { IrDeclaration } from \"../domain/ir/nodes.js\";\nimport type { GeneratorOptions, SchemaSource } from \"../types.js\";\nimport {\n DEFAULT_REMOTE_DOCUMENT_LIMITS,\n defaultDeprecationReporter,\n defaultLogger,\n defaultRedoclyConfig,\n monotonicNow,\n REMOTE_REF_TIMEOUT_MS,\n} from \"./default-ports.js\";\nimport { createDocumentRun, type GeneratorPorts } from \"./document-run.js\";\nimport transformSchema from \"./transform-schema.js\";\n\n/**\n * The Node API's composition root (ENGINEERING_PLAN 4.5): `openapiTS` wires the default adapters;\n * `generateDeclarations` runs with any ports, which is how the CLI calls it.\n */\n\n/** The declarations of one document, and the local files it was read from. */\nexport interface GeneratedDocument {\n readonly declarations: IrDeclaration[];\n readonly localFiles: readonly URL[];\n}\n\n/** Load, validate and bundle the source, then transform it into IR declarations. */\nexport async function generateDocument(\n source: SchemaSource,\n options: GeneratorOptions,\n ports: GeneratorPorts,\n): Promise<GeneratedDocument> {\n const { schema, localFiles, ctx } = await createDocumentRun(source, options, ports);\n const startedAt = ports.now();\n const declarations = withStackOverflowReported(\"transform\", () => transformSchema(schema, ctx));\n ports.logger.debug(\n \"Completed AST transformation for entire document\",\n \"ts\",\n ports.now() - startedAt,\n );\n return { declarations, localFiles };\n}\n\n/** As `generateDocument`, the declarations only. */\nexport async function generateDeclarations(\n source: SchemaSource,\n options: GeneratorOptions,\n ports: GeneratorPorts,\n): Promise<IrDeclaration[]> {\n return (await generateDocument(source, options, ports)).declarations;\n}\n\n/**\n * The default ports: the terminal logger, Node.js deprecation warnings, the given or default\n * Redocly config, Redocly loading.\n */\nexport async function defaultGeneratorPorts(options: GeneratorOptions): Promise<GeneratorPorts> {\n const logger = defaultLogger(options.silent ?? false);\n const redoc = options.redocly ?? (await defaultRedoclyConfig());\n const loader = createRedoclySchemaLoader({\n redoc,\n logger,\n now: monotonicNow,\n remoteRefTimeoutMs: REMOTE_REF_TIMEOUT_MS,\n remoteDocumentLimits: DEFAULT_REMOTE_DOCUMENT_LIMITS,\n });\n return { loader, logger, deprecations: defaultDeprecationReporter(), redoc, now: monotonicNow };\n}\n\n/**\n * Convert an OpenAPI schema to TypeScript declarations (IR nodes; print them with `astToString`)\n * @param {string|URL|object|Readable} source OpenAPI schema source:\n * - YAML: string\n * - JSON: parsed object\n * - URL: URL to a YAML or JSON file (local or remote)\n * - Readable: Readable stream of YAML or JSON\n */\nexport default async function openapiTS(\n source: SchemaSource,\n options: GeneratorOptions = {},\n): Promise<IrDeclaration[]> {\n return generateDeclarations(source, options, await defaultGeneratorPorts(options));\n}\n"],"names":[],"mappings":";;;;;;AA2BA,eAAsB,gBAAA,CACpB,MAAA,EACA,OAAA,EACA,KAAA,EAC4B;AAC5B,EAAA,MAAM,EAAE,QAAQ,UAAA,EAAY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escript = require('../adapters/type-ast-bridge/load-typescript.cjs'
|
|
|
5
5
|
const typescriptToIr = require('../adapters/type-ast-bridge/typescript-to-ir.cjs');
|
|
6
6
|
const errors = require('../domain/errors.cjs');
|
|
7
7
|
const constructors = require('../domain/ir/constructors.cjs');
|
|
8
|
+
const irShape = require('../domain/ir/ir-shape.cjs');
|
|
8
9
|
const legacyCallbackWarning = require('./legacy-callback-warning.cjs');
|
|
9
10
|
const typeHelpers = require('./type-helpers.cjs');
|
|
10
11
|
|
|
12
|
+
const LEGACY_PROPERTY_PROBLEM = "a property with syntax the generator cannot read";
|
|
11
13
|
class UnreadablePropertyError extends errors.OpenAPITypesafeError {
|
|
12
|
-
constructor(path) {
|
|
14
|
+
constructor(path, problem = LEGACY_PROPERTY_PROBLEM) {
|
|
13
15
|
super({
|
|
14
16
|
code: errors.ERROR_CODES.CALLBACK_RESULT_UNREADABLE,
|
|
15
|
-
message: `transformProperty at ${path} returned
|
|
17
|
+
message: `transformProperty at ${path} returned ${problem}`,
|
|
16
18
|
details: { callback: "transformProperty", path }
|
|
17
19
|
});
|
|
18
20
|
this.name = "UnreadablePropertyError";
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
class UnreadableTypeError extends errors.OpenAPITypesafeError {
|
|
22
|
-
constructor(callback, path) {
|
|
24
|
+
constructor(callback, path, expected = "a TypeScript node") {
|
|
23
25
|
super({
|
|
24
26
|
code: errors.ERROR_CODES.CALLBACK_RESULT_UNREADABLE,
|
|
25
|
-
message: `${callback} at ${path} returned a value that is not
|
|
27
|
+
message: `${callback} at ${path} returned a value that is not ${expected}`,
|
|
26
28
|
details: { callback, path }
|
|
27
29
|
});
|
|
28
30
|
this.name = "UnreadableTypeError";
|
|
29
31
|
}
|
|
30
32
|
}
|
|
33
|
+
const IR_TYPE_EXPECTED = "an IR type or non-empty type text";
|
|
34
|
+
const IR_PROPERTY_PROBLEM = "a value that is not an IR property the generator can print";
|
|
31
35
|
function nodeOptions(ctx, location) {
|
|
32
36
|
return { ...location, ctx };
|
|
33
37
|
}
|
|
34
38
|
function schemaCallbacks(ctx) {
|
|
35
39
|
return ctx.irCallbacks ? irSchemaCallbacks(ctx) : legacySchemaCallbacks(ctx);
|
|
36
40
|
}
|
|
37
|
-
function fromCallbackType(type) {
|
|
38
|
-
|
|
41
|
+
function fromCallbackType(callback, type, location) {
|
|
42
|
+
const candidate = typeof type === "string" ? constructors.irRaw(type) : type;
|
|
43
|
+
if (!irShape.isPrintableIrType(candidate)) {
|
|
44
|
+
throw new UnreadableTypeError(callback, location.path, IR_TYPE_EXPECTED);
|
|
45
|
+
}
|
|
46
|
+
return candidate;
|
|
39
47
|
}
|
|
40
|
-
function irCustomType(result) {
|
|
48
|
+
function irCustomType(result, location) {
|
|
41
49
|
if (result === void 0 || result === null) {
|
|
42
50
|
return null;
|
|
43
51
|
}
|
|
44
52
|
if (typeof result === "object" && "schema" in result) {
|
|
45
|
-
|
|
53
|
+
const { schema, questionToken } = result;
|
|
54
|
+
return {
|
|
55
|
+
type: fromCallbackType("transform", schema, location),
|
|
56
|
+
isOptional: Boolean(questionToken)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return { type: fromCallbackType("transform", result, location), isOptional: false };
|
|
60
|
+
}
|
|
61
|
+
function irProperty(result, location) {
|
|
62
|
+
if (result === void 0 || result === null) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (!irShape.isPrintableIrProperty(result)) {
|
|
66
|
+
throw new UnreadablePropertyError(location.path, IR_PROPERTY_PROBLEM);
|
|
46
67
|
}
|
|
47
|
-
return
|
|
68
|
+
return result;
|
|
48
69
|
}
|
|
49
70
|
function irSchemaCallbacks(ctx) {
|
|
50
71
|
const transform = ctx.transform;
|
|
51
72
|
const postTransform = ctx.postTransform;
|
|
52
73
|
const transformProperty = ctx.transformProperty;
|
|
53
74
|
return {
|
|
54
|
-
transform: (schema, location) => transform ? irCustomType(transform(schema, nodeOptions(ctx, location))) : null,
|
|
75
|
+
transform: (schema, location) => transform ? irCustomType(transform(schema, nodeOptions(ctx, location)), location) : null,
|
|
55
76
|
postTransform(type, location) {
|
|
56
77
|
const result = postTransform?.(type, nodeOptions(ctx, location));
|
|
57
|
-
return result === void 0 ? null : fromCallbackType(result);
|
|
78
|
+
return result === void 0 ? null : fromCallbackType("postTransform", result, location);
|
|
58
79
|
},
|
|
59
|
-
transformProperty: (property, schema, location) => transformProperty
|
|
80
|
+
transformProperty: (property, schema, location) => transformProperty ? irProperty(
|
|
81
|
+
transformProperty(property, schema, nodeOptions(ctx, location)),
|
|
82
|
+
location
|
|
83
|
+
) : null
|
|
60
84
|
};
|
|
61
85
|
}
|
|
62
86
|
function readResultType(callback, result, location) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-callbacks.cjs","sources":["../../src/api/schema-callbacks.ts"],"sourcesContent":["import { toPropertySignature, toTypeNode } from \"../adapters/type-ast-bridge/ir-to-typescript.js\";\nimport { loadTypeScript } from \"../adapters/type-ast-bridge/load-typescript.js\";\nimport { fromPropertySignature } from \"../adapters/type-ast-bridge/typescript-to-ir.js\";\nimport type { ts } from \"../adapters/type-ast-bridge/typescript-types.js\";\nimport type {\n CustomType,\n SchemaCallbacks,\n SchemaLocation,\n} from \"../application/transform/schema/schema-context.js\";\nimport { ERROR_CODES, OpenAPITypesafeError } from \"../domain/errors.js\";\nimport { irRaw } from \"../domain/ir/constructors.js\";\nimport type { IrPropertySignature, IrType } from \"../domain/ir/nodes.js\";\nimport type {\n GlobalContext,\n IrCallbackType,\n IrPostTransform,\n IrTransform,\n IrTransformProperty,\n LegacyCallbackOptions,\n SchemaObject,\n TransformNodeOptions,\n} from \"../types.js\";\nimport { warnLegacyCallback } from \"./legacy-callback-warning.js\";\nimport { toIrType } from \"./type-helpers.js\";\n\n/**\n * The user's schema callbacks as the transformers call them (ENGINEERING_PLAN 6.3, ADR-004).\n * With `irCallbacks: true` they receive and return IR; otherwise they receive TypeScript nodes and\n * their results are read by the bridge.\n */\n\nexport class UnreadablePropertyError extends OpenAPITypesafeError {\n constructor(path: string | undefined) {\n super({\n code: ERROR_CODES.CALLBACK_RESULT_UNREADABLE,\n message:\n `transformProperty at ${path} returned a property ` +\n \"with syntax the generator cannot read\",\n details: { callback: \"transformProperty\", path },\n });\n this.name = \"UnreadablePropertyError\";\n }\n}\n\n/** A `transform` or `postTransform` result that is neither IR nor a TypeScript node. */\nexport class UnreadableTypeError extends OpenAPITypesafeError {\n constructor(callback: \"transform\" | \"postTransform\", path: string | undefined) {\n super({\n code: ERROR_CODES.CALLBACK_RESULT_UNREADABLE,\n message: `${callback} at ${path} returned a value that is not a TypeScript node`,\n details: { callback, path },\n });\n this.name = \"UnreadableTypeError\";\n }\n}\n\nfunction nodeOptions(ctx: GlobalContext, location: SchemaLocation): TransformNodeOptions {\n return { ...location, ctx } as TransformNodeOptions;\n}\n\n/** The callbacks of the run: IR callbacks when the run asks for them, legacy ones otherwise. */\nexport function schemaCallbacks(ctx: GlobalContext): SchemaCallbacks {\n return ctx.irCallbacks ? irSchemaCallbacks(ctx) : legacySchemaCallbacks(ctx);\n}\n\n/** An IR callback type; text is a raw type, printed as written. */\nfunction fromCallbackType(type: IrCallbackType): IrType {\n return typeof type === \"string\" ? irRaw(type) : type;\n}\n\nfunction irCustomType(result: ReturnType<IrTransform>): CustomType | null {\n if (result === undefined || result === null) {\n return null;\n }\n if (typeof result === \"object\" && \"schema\" in result) {\n return { type: fromCallbackType(result.schema), isOptional: Boolean(result.questionToken) };\n }\n return { type: fromCallbackType(result), isOptional: false };\n}\n\n/**\n * The context fields hold either callback form; `irCallbacks` says which one, so the casts below\n * only name the form the user declared with `OpenAPITSIrOptions`.\n */\nfunction irSchemaCallbacks(ctx: GlobalContext): SchemaCallbacks {\n const transform = ctx.transform as IrTransform | undefined;\n const postTransform = ctx.postTransform as IrPostTransform | undefined;\n const transformProperty = ctx.transformProperty as IrTransformProperty | undefined;\n return {\n transform: (schema, location) =>\n transform\n ? irCustomType(transform(schema as SchemaObject, nodeOptions(ctx, location)))\n : null,\n postTransform(type, location) {\n const result = postTransform?.(type, nodeOptions(ctx, location));\n return result === undefined ? null : fromCallbackType(result);\n },\n transformProperty: (property, schema, location) =>\n transformProperty?.(property, schema as SchemaObject, nodeOptions(ctx, location)) ?? null,\n };\n}\n\ntype LegacyTransform = NonNullable<LegacyCallbackOptions[\"transform\"]>;\ntype LegacyPostTransform = NonNullable<LegacyCallbackOptions[\"postTransform\"]>;\ntype LegacyTransformProperty = NonNullable<LegacyCallbackOptions[\"transformProperty\"]>;\n\n/** A legacy result type: IR from the helpers as it is; a TypeScript node through the bridge. */\n/**\n * IR nodes have a string `kind`, TypeScript nodes a number. JavaScript callers can return any\n * value, and anything else would crash the TypeScript printer later.\n */\nfunction readResultType(\n callback: \"transform\" | \"postTransform\",\n result: unknown,\n location: SchemaLocation,\n): IrType {\n const kind = (result as { kind?: unknown }).kind;\n if (typeof kind !== \"string\" && typeof kind !== \"number\") {\n throw new UnreadableTypeError(callback, location.path);\n }\n return toIrType(result as IrType | ts.TypeNode);\n}\n\nfunction legacyResultType(ctx: GlobalContext, type: unknown, location: SchemaLocation): IrType {\n const result = readResultType(\"transform\", type, location);\n if (typeof (type as { kind: unknown }).kind !== \"string\") {\n warnLegacyCallback(ctx, \"transform\");\n }\n return result;\n}\n\nfunction legacyCustomType(\n ctx: GlobalContext,\n result: ReturnType<LegacyTransform>,\n location: SchemaLocation,\n): CustomType | null {\n if (!result || typeof result !== \"object\") {\n return null;\n }\n if (\"schema\" in result) {\n return {\n type: legacyResultType(ctx, result.schema, location),\n isOptional: Boolean(result.questionToken),\n };\n }\n return { type: legacyResultType(ctx, result, location), isOptional: false };\n}\n\n/** See `irSchemaCallbacks` for the casts; `typeof` checks keep the original's tolerance. */\nfunction legacySchemaCallbacks(ctx: GlobalContext): SchemaCallbacks {\n const transform = ctx.transform as LegacyTransform | undefined;\n const postTransform = ctx.postTransform as LegacyPostTransform | undefined;\n return {\n transform: (schema, location) =>\n typeof transform === \"function\"\n ? legacyCustomType(\n ctx,\n transform(schema as SchemaObject, nodeOptions(ctx, location)),\n location,\n )\n : null,\n postTransform(type, location) {\n if (typeof postTransform !== \"function\") {\n return null;\n }\n warnLegacyCallback(ctx, \"postTransform\");\n const result = postTransform(toTypeNode(loadTypeScript(), type), nodeOptions(ctx, location));\n return result ? readResultType(\"postTransform\", result, location) : null;\n },\n transformProperty: (property, schema, location) =>\n legacyTransformProperty(ctx, property, schema, location),\n };\n}\n\nfunction isIrProperty(\n property: IrPropertySignature | ts.PropertySignature,\n): property is IrPropertySignature {\n return typeof property.kind === \"string\";\n}\n\nfunction legacyTransformProperty(\n ctx: GlobalContext,\n property: IrPropertySignature,\n schema: unknown,\n location: SchemaLocation,\n): IrPropertySignature | null {\n const transformProperty = ctx.transformProperty as LegacyTransformProperty | undefined;\n if (typeof transformProperty !== \"function\") {\n return null;\n }\n warnLegacyCallback(ctx, \"transformProperty\");\n const ts = loadTypeScript();\n const options = nodeOptions(ctx, location);\n const result = transformProperty(\n toPropertySignature(ts, property),\n schema as SchemaObject,\n options,\n );\n if (!result) {\n return null;\n }\n if (isIrProperty(result)) {\n return result;\n }\n // JavaScript callers can return any value, so check the node kind before reading it.\n const converted = ts.isPropertySignature(result) ? fromPropertySignature(ts, result) : null;\n if (converted === null) {\n throw new UnreadablePropertyError(location.path);\n }\n return converted;\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","irRaw","toIrType","warnLegacyCallback","toTypeNode","loadTypeScript","toPropertySignature","fromPropertySignature"],"mappings":";;;;;;;;;;AA+BO,MAAM,gCAAgCA,2BAAA,CAAqB;AAAA,EAChE,YAAY,IAAA,EAA0B;AACpC,IAAA,KAAA,CAAM;AAAA,MACJ,MAAMC,kBAAA,CAAY,0BAAA;AAAA,MAClB,OAAA,EACE,wBAAwB,IAAI,CAAA,0DAAA,CAAA;AAAA,MAE9B,OAAA,EAAS,EAAE,QAAA,EAAU,mBAAA,EAAqB,IAAA;AAAK,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,OAAO,SAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"schema-callbacks.cjs","sources":["../../src/api/schema-callbacks.ts"],"sourcesContent":["import { toPropertySignature, toTypeNode } from \"../adapters/type-ast-bridge/ir-to-typescript.js\";\nimport { loadTypeScript } from \"../adapters/type-ast-bridge/load-typescript.js\";\nimport { fromPropertySignature } from \"../adapters/type-ast-bridge/typescript-to-ir.js\";\nimport type { ts } from \"../adapters/type-ast-bridge/typescript-types.js\";\nimport type {\n CustomType,\n SchemaCallbacks,\n SchemaLocation,\n} from \"../application/transform/schema/schema-context.js\";\nimport { ERROR_CODES, OpenAPITypesafeError } from \"../domain/errors.js\";\nimport { irRaw } from \"../domain/ir/constructors.js\";\nimport { isPrintableIrProperty, isPrintableIrType } from \"../domain/ir/ir-shape.js\";\nimport type { IrPropertySignature, IrType } from \"../domain/ir/nodes.js\";\nimport type {\n GlobalContext,\n IrPostTransform,\n IrTransform,\n IrTransformProperty,\n LegacyCallbackOptions,\n SchemaObject,\n TransformNodeOptions,\n} from \"../types.js\";\nimport { warnLegacyCallback } from \"./legacy-callback-warning.js\";\nimport { toIrType } from \"./type-helpers.js\";\n\n/**\n * The user's schema callbacks as the transformers call them (ENGINEERING_PLAN 6.3, ADR-004).\n * With `irCallbacks: true` they receive and return IR; otherwise they receive TypeScript nodes and\n * their results are read by the bridge.\n */\n\n/** What a legacy `transformProperty` result fails to be. */\nconst LEGACY_PROPERTY_PROBLEM = \"a property with syntax the generator cannot read\";\n\n/** A `transformProperty` result the generator cannot print as a property. */\nexport class UnreadablePropertyError extends OpenAPITypesafeError {\n constructor(path: string | undefined, problem = LEGACY_PROPERTY_PROBLEM) {\n super({\n code: ERROR_CODES.CALLBACK_RESULT_UNREADABLE,\n message: `transformProperty at ${path} returned ${problem}`,\n details: { callback: \"transformProperty\", path },\n });\n this.name = \"UnreadablePropertyError\";\n }\n}\n\n/** A `transform` or `postTransform` result that is neither IR nor a TypeScript node. */\nexport class UnreadableTypeError extends OpenAPITypesafeError {\n constructor(\n callback: \"transform\" | \"postTransform\",\n path: string | undefined,\n expected = \"a TypeScript node\",\n ) {\n super({\n code: ERROR_CODES.CALLBACK_RESULT_UNREADABLE,\n message: `${callback} at ${path} returned a value that is not ${expected}`,\n details: { callback, path },\n });\n this.name = \"UnreadableTypeError\";\n }\n}\n\n/** What an IR type result must be (docs/node.md, IR callbacks). */\nconst IR_TYPE_EXPECTED = \"an IR type or non-empty type text\";\n\n/** What an IR property result must be. */\nconst IR_PROPERTY_PROBLEM = \"a value that is not an IR property the generator can print\";\n\nfunction nodeOptions(ctx: GlobalContext, location: SchemaLocation): TransformNodeOptions {\n return { ...location, ctx } as TransformNodeOptions;\n}\n\n/** The callbacks of the run: IR callbacks when the run asks for them, legacy ones otherwise. */\nexport function schemaCallbacks(ctx: GlobalContext): SchemaCallbacks {\n return ctx.irCallbacks ? irSchemaCallbacks(ctx) : legacySchemaCallbacks(ctx);\n}\n\n/**\n * An IR callback type; text is a raw type, printed as written. Any other value, and IR the\n * printer cannot write as TypeScript, fails with `CALLBACK_RESULT_UNREADABLE` (`ir-shape.ts`).\n */\nfunction fromCallbackType(\n callback: \"transform\" | \"postTransform\",\n type: unknown,\n location: SchemaLocation,\n): IrType {\n const candidate = typeof type === \"string\" ? irRaw(type) : type;\n if (!isPrintableIrType(candidate)) {\n throw new UnreadableTypeError(callback, location.path, IR_TYPE_EXPECTED);\n }\n return candidate;\n}\n\nfunction irCustomType(result: unknown, location: SchemaLocation): CustomType | null {\n if (result === undefined || result === null) {\n return null;\n }\n if (typeof result === \"object\" && \"schema\" in result) {\n const { schema, questionToken } = result as { schema: unknown; questionToken?: unknown };\n return {\n type: fromCallbackType(\"transform\", schema, location),\n isOptional: Boolean(questionToken),\n };\n }\n return { type: fromCallbackType(\"transform\", result, location), isOptional: false };\n}\n\nfunction irProperty(result: unknown, location: SchemaLocation): IrPropertySignature | null {\n if (result === undefined || result === null) {\n return null;\n }\n if (!isPrintableIrProperty(result)) {\n throw new UnreadablePropertyError(location.path, IR_PROPERTY_PROBLEM);\n }\n return result;\n}\n\n/**\n * The context fields hold either callback form; `irCallbacks` says which one, so the casts below\n * only name the form the user declared with `OpenAPITSIrOptions`. The results are checked, since\n * JavaScript callers can return any value.\n */\nfunction irSchemaCallbacks(ctx: GlobalContext): SchemaCallbacks {\n const transform = ctx.transform as IrTransform | undefined;\n const postTransform = ctx.postTransform as IrPostTransform | undefined;\n const transformProperty = ctx.transformProperty as IrTransformProperty | undefined;\n return {\n transform: (schema, location) =>\n transform\n ? irCustomType(transform(schema as SchemaObject, nodeOptions(ctx, location)), location)\n : null,\n postTransform(type, location) {\n const result = postTransform?.(type, nodeOptions(ctx, location));\n return result === undefined ? null : fromCallbackType(\"postTransform\", result, location);\n },\n transformProperty: (property, schema, location) =>\n transformProperty\n ? irProperty(\n transformProperty(property, schema as SchemaObject, nodeOptions(ctx, location)),\n location,\n )\n : null,\n };\n}\n\ntype LegacyTransform = NonNullable<LegacyCallbackOptions[\"transform\"]>;\ntype LegacyPostTransform = NonNullable<LegacyCallbackOptions[\"postTransform\"]>;\ntype LegacyTransformProperty = NonNullable<LegacyCallbackOptions[\"transformProperty\"]>;\n\n/** A legacy result type: IR from the helpers as it is; a TypeScript node through the bridge. */\n/**\n * IR nodes have a string `kind`, TypeScript nodes a number. JavaScript callers can return any\n * value, and anything else would crash the TypeScript printer later.\n */\nfunction readResultType(\n callback: \"transform\" | \"postTransform\",\n result: unknown,\n location: SchemaLocation,\n): IrType {\n const kind = (result as { kind?: unknown }).kind;\n if (typeof kind !== \"string\" && typeof kind !== \"number\") {\n throw new UnreadableTypeError(callback, location.path);\n }\n return toIrType(result as IrType | ts.TypeNode);\n}\n\nfunction legacyResultType(ctx: GlobalContext, type: unknown, location: SchemaLocation): IrType {\n const result = readResultType(\"transform\", type, location);\n if (typeof (type as { kind: unknown }).kind !== \"string\") {\n warnLegacyCallback(ctx, \"transform\");\n }\n return result;\n}\n\nfunction legacyCustomType(\n ctx: GlobalContext,\n result: ReturnType<LegacyTransform>,\n location: SchemaLocation,\n): CustomType | null {\n if (!result || typeof result !== \"object\") {\n return null;\n }\n if (\"schema\" in result) {\n return {\n type: legacyResultType(ctx, result.schema, location),\n isOptional: Boolean(result.questionToken),\n };\n }\n return { type: legacyResultType(ctx, result, location), isOptional: false };\n}\n\n/** See `irSchemaCallbacks` for the casts; `typeof` checks keep the original's tolerance. */\nfunction legacySchemaCallbacks(ctx: GlobalContext): SchemaCallbacks {\n const transform = ctx.transform as LegacyTransform | undefined;\n const postTransform = ctx.postTransform as LegacyPostTransform | undefined;\n return {\n transform: (schema, location) =>\n typeof transform === \"function\"\n ? legacyCustomType(\n ctx,\n transform(schema as SchemaObject, nodeOptions(ctx, location)),\n location,\n )\n : null,\n postTransform(type, location) {\n if (typeof postTransform !== \"function\") {\n return null;\n }\n warnLegacyCallback(ctx, \"postTransform\");\n const result = postTransform(toTypeNode(loadTypeScript(), type), nodeOptions(ctx, location));\n return result ? readResultType(\"postTransform\", result, location) : null;\n },\n transformProperty: (property, schema, location) =>\n legacyTransformProperty(ctx, property, schema, location),\n };\n}\n\nfunction isIrProperty(\n property: IrPropertySignature | ts.PropertySignature,\n): property is IrPropertySignature {\n return typeof property.kind === \"string\";\n}\n\nfunction legacyTransformProperty(\n ctx: GlobalContext,\n property: IrPropertySignature,\n schema: unknown,\n location: SchemaLocation,\n): IrPropertySignature | null {\n const transformProperty = ctx.transformProperty as LegacyTransformProperty | undefined;\n if (typeof transformProperty !== \"function\") {\n return null;\n }\n warnLegacyCallback(ctx, \"transformProperty\");\n const ts = loadTypeScript();\n const options = nodeOptions(ctx, location);\n const result = transformProperty(\n toPropertySignature(ts, property),\n schema as SchemaObject,\n options,\n );\n if (!result) {\n return null;\n }\n if (isIrProperty(result)) {\n return result;\n }\n // JavaScript callers can return any value, so check the node kind before reading it.\n const converted = ts.isPropertySignature(result) ? fromPropertySignature(ts, result) : null;\n if (converted === null) {\n throw new UnreadablePropertyError(location.path);\n }\n return converted;\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","irRaw","isPrintableIrType","isPrintableIrProperty","toIrType","warnLegacyCallback","toTypeNode","loadTypeScript","toPropertySignature","fromPropertySignature"],"mappings":";;;;;;;;;;;AAgCA,MAAM,uBAAA,GAA0B,kDAAA;AAGzB,MAAM,gCAAgCA,2BAAA,CAAqB;AAAA,EAChE,WAAA,CAAY,IAAA,EAA0B,OAAA,GAAU,uBAAA,EAAyB;AACvE,IAAA,KAAA,CAAM;AAAA,MACJ,MAAMC,kBAAA,CAAY,0BAAA;AAAA,MAClB,OAAA,EAAS,CAAA,qBAAA,EAAwB,IAAI,CAAA,UAAA,EAAa,OAAO,CAAA,CAAA;AAAA,MACzD,OAAA,EAAS,EAAE,QAAA,EAAU,mBAAA,EAAqB,IAAA;AAAK,KAChD,CAAA;AACD,IAAA,IAAA,CAAK,IAAA,GAAO,yBAAA;AAAA,EACd;AACF;AAGO,MAAM,4BAA4BD,2BAAA,CAAqB;AAAA,EAC5D,WAAA,CACE,QAAA,EACA,IAAA,EACA,QAAA,GAAW,mBAAA,EACX;AACA,IAAA,KAAA,CAAM;AAAA,MACJ,MAAMC,kBAAA,CAAY,0BAAA;AAAA,MAClB,SAAS,CAAA,EAAG,QAAQ,CAAA,IAAA,EAAO,IAAI,iCAAiC,QAAQ,CAAA,CAAA;AAAA,MACxE,OAAA,EAAS,EAAE,QAAA,EAAU,IAAA;AAAK,KAC3B,CAAA;AACD,IAAA,IAAA,CAAK,IAAA,GAAO,qBAAA;AAAA,EACd;AACF;AAGA,MAAM,gBAAA,GAAmB,mCAAA;AAGzB,MAAM,mBAAA,GAAsB,4DAAA;AAE5B,SAAS,WAAA,CAAY,KAAoB,QAAA,EAAgD;AACvF,EAAA,OAAO,EAAE,GAAG,QAAA,EAAU,GAAA,EAAI;AAC5B;AAGO,SAAS,gBAAgB,GAAA,EAAqC;AACnE,EAAA,OAAO,IAAI,WAAA,GAAc,iBAAA,CAAkB,GAAG,CAAA,GAAI,s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,CAAS,IAAI,CAAA;AAAA,EACjD;AACA,EAAA,OAAO,SAAA;AACT;;;;"}
|
|
@@ -3,58 +3,82 @@ import { loadTypeScript } from '../adapters/type-ast-bridge/load-typescript.mjs'
|
|
|
3
3
|
import { fromPropertySignature } from '../adapters/type-ast-bridge/typescript-to-ir.mjs';
|
|
4
4
|
import { OpenAPITypesafeError, ERROR_CODES } from '../domain/errors.mjs';
|
|
5
5
|
import { irRaw } from '../domain/ir/constructors.mjs';
|
|
6
|
+
import { isPrintableIrProperty, isPrintableIrType } from '../domain/ir/ir-shape.mjs';
|
|
6
7
|
import { warnLegacyCallback } from './legacy-callback-warning.mjs';
|
|
7
8
|
import { toIrType } from './type-helpers.mjs';
|
|
8
9
|
|
|
10
|
+
const LEGACY_PROPERTY_PROBLEM = "a property with syntax the generator cannot read";
|
|
9
11
|
class UnreadablePropertyError extends OpenAPITypesafeError {
|
|
10
|
-
constructor(path) {
|
|
12
|
+
constructor(path, problem = LEGACY_PROPERTY_PROBLEM) {
|
|
11
13
|
super({
|
|
12
14
|
code: ERROR_CODES.CALLBACK_RESULT_UNREADABLE,
|
|
13
|
-
message: `transformProperty at ${path} returned
|
|
15
|
+
message: `transformProperty at ${path} returned ${problem}`,
|
|
14
16
|
details: { callback: "transformProperty", path }
|
|
15
17
|
});
|
|
16
18
|
this.name = "UnreadablePropertyError";
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
class UnreadableTypeError extends OpenAPITypesafeError {
|
|
20
|
-
constructor(callback, path) {
|
|
22
|
+
constructor(callback, path, expected = "a TypeScript node") {
|
|
21
23
|
super({
|
|
22
24
|
code: ERROR_CODES.CALLBACK_RESULT_UNREADABLE,
|
|
23
|
-
message: `${callback} at ${path} returned a value that is not
|
|
25
|
+
message: `${callback} at ${path} returned a value that is not ${expected}`,
|
|
24
26
|
details: { callback, path }
|
|
25
27
|
});
|
|
26
28
|
this.name = "UnreadableTypeError";
|
|
27
29
|
}
|
|
28
30
|
}
|
|
31
|
+
const IR_TYPE_EXPECTED = "an IR type or non-empty type text";
|
|
32
|
+
const IR_PROPERTY_PROBLEM = "a value that is not an IR property the generator can print";
|
|
29
33
|
function nodeOptions(ctx, location) {
|
|
30
34
|
return { ...location, ctx };
|
|
31
35
|
}
|
|
32
36
|
function schemaCallbacks(ctx) {
|
|
33
37
|
return ctx.irCallbacks ? irSchemaCallbacks(ctx) : legacySchemaCallbacks(ctx);
|
|
34
38
|
}
|
|
35
|
-
function fromCallbackType(type) {
|
|
36
|
-
|
|
39
|
+
function fromCallbackType(callback, type, location) {
|
|
40
|
+
const candidate = typeof type === "string" ? irRaw(type) : type;
|
|
41
|
+
if (!isPrintableIrType(candidate)) {
|
|
42
|
+
throw new UnreadableTypeError(callback, location.path, IR_TYPE_EXPECTED);
|
|
43
|
+
}
|
|
44
|
+
return candidate;
|
|
37
45
|
}
|
|
38
|
-
function irCustomType(result) {
|
|
46
|
+
function irCustomType(result, location) {
|
|
39
47
|
if (result === void 0 || result === null) {
|
|
40
48
|
return null;
|
|
41
49
|
}
|
|
42
50
|
if (typeof result === "object" && "schema" in result) {
|
|
43
|
-
|
|
51
|
+
const { schema, questionToken } = result;
|
|
52
|
+
return {
|
|
53
|
+
type: fromCallbackType("transform", schema, location),
|
|
54
|
+
isOptional: Boolean(questionToken)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return { type: fromCallbackType("transform", result, location), isOptional: false };
|
|
58
|
+
}
|
|
59
|
+
function irProperty(result, location) {
|
|
60
|
+
if (result === void 0 || result === null) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
if (!isPrintableIrProperty(result)) {
|
|
64
|
+
throw new UnreadablePropertyError(location.path, IR_PROPERTY_PROBLEM);
|
|
44
65
|
}
|
|
45
|
-
return
|
|
66
|
+
return result;
|
|
46
67
|
}
|
|
47
68
|
function irSchemaCallbacks(ctx) {
|
|
48
69
|
const transform = ctx.transform;
|
|
49
70
|
const postTransform = ctx.postTransform;
|
|
50
71
|
const transformProperty = ctx.transformProperty;
|
|
51
72
|
return {
|
|
52
|
-
transform: (schema, location) => transform ? irCustomType(transform(schema, nodeOptions(ctx, location))) : null,
|
|
73
|
+
transform: (schema, location) => transform ? irCustomType(transform(schema, nodeOptions(ctx, location)), location) : null,
|
|
53
74
|
postTransform(type, location) {
|
|
54
75
|
const result = postTransform?.(type, nodeOptions(ctx, location));
|
|
55
|
-
return result === void 0 ? null : fromCallbackType(result);
|
|
76
|
+
return result === void 0 ? null : fromCallbackType("postTransform", result, location);
|
|
56
77
|
},
|
|
57
|
-
transformProperty: (property, schema, location) => transformProperty
|
|
78
|
+
transformProperty: (property, schema, location) => transformProperty ? irProperty(
|
|
79
|
+
transformProperty(property, schema, nodeOptions(ctx, location)),
|
|
80
|
+
location
|
|
81
|
+
) : null
|
|
58
82
|
};
|
|
59
83
|
}
|
|
60
84
|
function readResultType(callback, result, location) {
|