openapi-typesafe 1.0.0-rc.3 → 1.0.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1972 -0
- package/dist/adapters/node-file-system/file-claims.cjs +105 -0
- package/dist/adapters/node-file-system/file-claims.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-claims.mjs +95 -0
- package/dist/adapters/node-file-system/file-claims.mjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.cjs +82 -0
- package/dist/adapters/node-file-system/file-identity.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.mjs +74 -0
- package/dist/adapters/node-file-system/file-identity.mjs.map +1 -0
- package/dist/adapters/node-file-system/node-file-system.cjs +97 -14
- package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
- package/dist/adapters/node-file-system/node-file-system.mjs +97 -14
- package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs +19 -0
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs.map +1 -0
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs +17 -0
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +48 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +45 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs +2 -2
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs.map +1 -1
- package/dist/adapters/redocly-loader/component-schemas.cjs +17 -0
- package/dist/adapters/redocly-loader/component-schemas.cjs.map +1 -0
- package/dist/adapters/redocly-loader/component-schemas.mjs +14 -0
- package/dist/adapters/redocly-loader/component-schemas.mjs.map +1 -0
- package/dist/adapters/redocly-loader/loaded-documents.cjs +28 -0
- package/dist/adapters/redocly-loader/loaded-documents.cjs.map +1 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs +21 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs.map +1 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.cjs +22 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.cjs.map +1 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.mjs +20 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.mjs.map +1 -0
- package/dist/adapters/redocly-loader/query-named-components.cjs +137 -0
- package/dist/adapters/redocly-loader/query-named-components.cjs.map +1 -0
- package/dist/adapters/redocly-loader/query-named-components.mjs +134 -0
- package/dist/adapters/redocly-loader/query-named-components.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +40 -29
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +38 -27
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +45 -4
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +45 -4
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.cjs +52 -10
- package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.mjs +53 -12
- package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-body-limit.cjs +50 -0
- package/dist/adapters/redocly-loader/remote-body-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs +48 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-fetch.cjs +40 -9
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +40 -9
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.cjs +61 -0
- package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs +58 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-load-errors.cjs +32 -8
- package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-load-errors.mjs +32 -9
- package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.cjs +18 -9
- package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.mjs +20 -11
- package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.cjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.mjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.cjs +10 -4
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.mjs +10 -4
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
- package/dist/api/default-ports.cjs +14 -2
- package/dist/api/default-ports.cjs.map +1 -1
- package/dist/api/default-ports.mjs +14 -2
- package/dist/api/default-ports.mjs.map +1 -1
- package/dist/api/discriminator-enum-parent.cjs +2 -2
- package/dist/api/discriminator-enum-parent.cjs.map +1 -1
- package/dist/api/discriminator-enum-parent.mjs +3 -3
- package/dist/api/discriminator-enum-parent.mjs.map +1 -1
- package/dist/api/discriminator-other-owners.cjs +5 -3
- package/dist/api/discriminator-other-owners.cjs.map +1 -1
- package/dist/api/discriminator-other-owners.mjs +5 -3
- package/dist/api/discriminator-other-owners.mjs.map +1 -1
- package/dist/api/discriminator-patch.cjs +5 -1
- package/dist/api/discriminator-patch.cjs.map +1 -1
- package/dist/api/discriminator-patch.mjs +5 -1
- package/dist/api/discriminator-patch.mjs.map +1 -1
- package/dist/api/discriminator-scan.cjs +15 -8
- package/dist/api/discriminator-scan.cjs.map +1 -1
- package/dist/api/discriminator-scan.mjs +15 -8
- package/dist/api/discriminator-scan.mjs.map +1 -1
- package/dist/api/document-refs.cjs +16 -1
- package/dist/api/document-refs.cjs.map +1 -1
- package/dist/api/document-refs.mjs +16 -1
- package/dist/api/document-refs.mjs.map +1 -1
- package/dist/api/document-run.cjs +6 -12
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +6 -12
- package/dist/api/document-run.mjs.map +1 -1
- package/dist/api/legacy-utils.cjs.map +1 -1
- package/dist/api/legacy-utils.mjs.map +1 -1
- package/dist/api/openapi-ts.cjs +9 -6
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +10 -8
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/ref-limit-options.cjs +63 -0
- package/dist/api/ref-limit-options.cjs.map +1 -0
- package/dist/api/ref-limit-options.mjs +57 -0
- package/dist/api/ref-limit-options.mjs.map +1 -0
- package/dist/api/schema-callbacks.cjs +36 -12
- package/dist/api/schema-callbacks.cjs.map +1 -1
- package/dist/api/schema-callbacks.mjs +36 -12
- package/dist/api/schema-callbacks.mjs.map +1 -1
- package/dist/api/transform-context.cjs +7 -3
- package/dist/api/transform-context.cjs.map +1 -1
- package/dist/api/transform-context.mjs +7 -3
- package/dist/api/transform-context.mjs.map +1 -1
- package/dist/api/transform-schema.cjs +47 -10
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +48 -11
- package/dist/api/transform-schema.mjs.map +1 -1
- package/dist/application/print/text-writer.cjs +10 -3
- package/dist/application/print/text-writer.cjs.map +1 -1
- package/dist/application/print/text-writer.mjs +10 -3
- package/dist/application/print/text-writer.mjs.map +1 -1
- package/dist/application/stack-overflow.cjs +2 -1
- package/dist/application/stack-overflow.cjs.map +1 -1
- package/dist/application/stack-overflow.mjs +2 -1
- package/dist/application/stack-overflow.mjs.map +1 -1
- package/dist/application/transform/declared-value-types.cjs +36 -0
- package/dist/application/transform/declared-value-types.cjs.map +1 -0
- package/dist/application/transform/declared-value-types.mjs +34 -0
- package/dist/application/transform/declared-value-types.mjs.map +1 -0
- package/dist/application/transform/document/components.cjs +1 -1
- package/dist/application/transform/document/components.cjs.map +1 -1
- package/dist/application/transform/document/components.mjs +2 -2
- package/dist/application/transform/document/components.mjs.map +1 -1
- package/dist/application/transform/document/declared-type-names.cjs +23 -0
- package/dist/application/transform/document/declared-type-names.cjs.map +1 -0
- package/dist/application/transform/document/declared-type-names.mjs +20 -0
- package/dist/application/transform/document/declared-type-names.mjs.map +1 -0
- package/dist/application/transform/document/defs-root.cjs +1 -1
- package/dist/application/transform/document/defs-root.cjs.map +1 -1
- package/dist/application/transform/document/defs-root.mjs +2 -2
- package/dist/application/transform/document/defs-root.mjs.map +1 -1
- package/dist/application/transform/document/document.cjs +7 -2
- package/dist/application/transform/document/document.cjs.map +1 -1
- package/dist/application/transform/document/document.mjs +6 -3
- package/dist/application/transform/document/document.mjs.map +1 -1
- package/dist/application/transform/document/enum-names-given-back.cjs +62 -0
- package/dist/application/transform/document/enum-names-given-back.cjs.map +1 -0
- package/dist/application/transform/document/enum-names-given-back.mjs +58 -0
- package/dist/application/transform/document/enum-names-given-back.mjs.map +1 -0
- package/dist/application/transform/document/exploded-query-values.cjs +63 -0
- package/dist/application/transform/document/exploded-query-values.cjs.map +1 -0
- package/dist/application/transform/document/exploded-query-values.mjs +59 -0
- package/dist/application/transform/document/exploded-query-values.mjs.map +1 -0
- package/dist/application/transform/document/global-type-references.cjs +1 -0
- package/dist/application/transform/document/global-type-references.cjs.map +1 -1
- package/dist/application/transform/document/global-type-references.mjs +1 -1
- package/dist/application/transform/document/global-type-references.mjs.map +1 -1
- package/dist/application/transform/document/header.cjs +11 -3
- package/dist/application/transform/document/header.cjs.map +1 -1
- package/dist/application/transform/document/header.mjs +10 -2
- package/dist/application/transform/document/header.mjs.map +1 -1
- package/dist/application/transform/document/media-type.cjs +2 -2
- package/dist/application/transform/document/media-type.cjs.map +1 -1
- package/dist/application/transform/document/media-type.mjs +3 -3
- package/dist/application/transform/document/media-type.mjs.map +1 -1
- package/dist/application/transform/document/operation-keys-written.cjs +26 -0
- package/dist/application/transform/document/operation-keys-written.cjs.map +1 -0
- package/dist/application/transform/document/operation-keys-written.mjs +24 -0
- package/dist/application/transform/document/operation-keys-written.mjs.map +1 -0
- package/dist/application/transform/document/operation.cjs +1 -1
- package/dist/application/transform/document/operation.cjs.map +1 -1
- package/dist/application/transform/document/operation.mjs +2 -2
- package/dist/application/transform/document/operation.mjs.map +1 -1
- package/dist/application/transform/document/parameter-entries.cjs +34 -0
- package/dist/application/transform/document/parameter-entries.cjs.map +1 -0
- package/dist/application/transform/document/parameter-entries.mjs +30 -0
- package/dist/application/transform/document/parameter-entries.mjs.map +1 -0
- package/dist/application/transform/document/parameter.cjs +12 -4
- package/dist/application/transform/document/parameter.cjs.map +1 -1
- package/dist/application/transform/document/parameter.mjs +13 -5
- package/dist/application/transform/document/parameter.mjs.map +1 -1
- package/dist/application/transform/document/parameters.cjs +29 -34
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +29 -34
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/path-item.cjs +15 -17
- package/dist/application/transform/document/path-item.cjs.map +1 -1
- package/dist/application/transform/document/path-item.mjs +15 -19
- package/dist/application/transform/document/path-item.mjs.map +1 -1
- package/dist/application/transform/document/path-template-key.cjs +84 -0
- package/dist/application/transform/document/path-template-key.cjs.map +1 -0
- package/dist/application/transform/document/path-template-key.mjs +79 -0
- package/dist/application/transform/document/path-template-key.mjs.map +1 -0
- package/dist/application/transform/document/path-template-refs.cjs +70 -0
- package/dist/application/transform/document/path-template-refs.cjs.map +1 -0
- package/dist/application/transform/document/path-template-refs.mjs +67 -0
- package/dist/application/transform/document/path-template-refs.mjs.map +1 -0
- package/dist/application/transform/document/paths-enum.cjs +8 -6
- package/dist/application/transform/document/paths-enum.cjs.map +1 -1
- package/dist/application/transform/document/paths-enum.mjs +8 -7
- package/dist/application/transform/document/paths-enum.mjs.map +1 -1
- package/dist/application/transform/document/paths.cjs +43 -67
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +42 -68
- package/dist/application/transform/document/paths.mjs.map +1 -1
- package/dist/application/transform/document/referenced-parameter.cjs +80 -0
- package/dist/application/transform/document/referenced-parameter.cjs.map +1 -0
- package/dist/application/transform/document/referenced-parameter.mjs +78 -0
- package/dist/application/transform/document/referenced-parameter.mjs.map +1 -0
- package/dist/application/transform/document/request-body.cjs +1 -1
- package/dist/application/transform/document/request-body.cjs.map +1 -1
- package/dist/application/transform/document/request-body.mjs +2 -2
- package/dist/application/transform/document/request-body.mjs.map +1 -1
- package/dist/application/transform/document/response.cjs +2 -2
- package/dist/application/transform/document/response.cjs.map +1 -1
- package/dist/application/transform/document/response.mjs +3 -3
- package/dist/application/transform/document/response.mjs.map +1 -1
- package/dist/application/transform/document/responses.cjs +1 -1
- package/dist/application/transform/document/responses.cjs.map +1 -1
- package/dist/application/transform/document/responses.mjs +2 -2
- package/dist/application/transform/document/responses.mjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.cjs +8 -23
- package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.mjs +8 -24
- package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
- package/dist/application/transform/document/type-resolution.cjs +3 -1
- package/dist/application/transform/document/type-resolution.cjs.map +1 -1
- package/dist/application/transform/document/type-resolution.mjs +3 -1
- package/dist/application/transform/document/type-resolution.mjs.map +1 -1
- package/dist/application/transform/document/webhooks.cjs +10 -3
- package/dist/application/transform/document/webhooks.cjs.map +1 -1
- package/dist/application/transform/document/webhooks.mjs +10 -3
- package/dist/application/transform/document/webhooks.mjs.map +1 -1
- package/dist/application/transform/footer/document-footer.cjs +16 -5
- package/dist/application/transform/footer/document-footer.cjs.map +1 -1
- package/dist/application/transform/footer/document-footer.mjs +16 -5
- package/dist/application/transform/footer/document-footer.mjs.map +1 -1
- package/dist/application/transform/footer/enum-name-claims.cjs +48 -0
- package/dist/application/transform/footer/enum-name-claims.cjs.map +1 -0
- package/dist/application/transform/footer/enum-name-claims.mjs +46 -0
- package/dist/application/transform/footer/enum-name-claims.mjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.cjs +23 -0
- package/dist/application/transform/footer/operation-keys.cjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.mjs +21 -0
- package/dist/application/transform/footer/operation-keys.mjs.map +1 -0
- package/dist/application/transform/footer/type-evaluation.cjs +4 -4
- package/dist/application/transform/footer/type-evaluation.cjs.map +1 -1
- package/dist/application/transform/footer/type-evaluation.mjs +4 -4
- package/dist/application/transform/footer/type-evaluation.mjs.map +1 -1
- package/dist/application/transform/helper-types.cjs +3 -3
- package/dist/application/transform/helper-types.cjs.map +1 -1
- package/dist/application/transform/helper-types.mjs +3 -3
- package/dist/application/transform/helper-types.mjs.map +1 -1
- package/dist/application/transform/numbered-names.cjs +9 -0
- package/dist/application/transform/numbered-names.cjs.map +1 -1
- package/dist/application/transform/numbered-names.mjs +9 -1
- package/dist/application/transform/numbered-names.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs +5 -5
- package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs +3 -3
- package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.cjs +47 -66
- package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.mjs +36 -50
- package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/inline-cycles.cjs +2 -2
- package/dist/application/transform/ref-pointer/inline-cycles.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/inline-cycles.mjs +1 -1
- package/dist/application/transform/ref-pointer/inline-cycles.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/located-node.cjs +23 -0
- package/dist/application/transform/ref-pointer/located-node.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/located-node.mjs +18 -0
- package/dist/application/transform/ref-pointer/located-node.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/original-index.cjs +68 -13
- package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/original-index.mjs +70 -15
- package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs +2 -2
- package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-walk.cjs +54 -13
- package/dist/application/transform/ref-pointer/pointer-walk.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-walk.mjs +46 -7
- package/dist/application/transform/ref-pointer/pointer-walk.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/property-shape.cjs +52 -0
- package/dist/application/transform/ref-pointer/property-shape.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/property-shape.mjs +45 -0
- package/dist/application/transform/ref-pointer/property-shape.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/typed-walk.cjs +79 -21
- package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/typed-walk.mjs +76 -18
- package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -1
- package/dist/application/transform/ref-type.cjs +2 -1
- package/dist/application/transform/ref-type.cjs.map +1 -1
- package/dist/application/transform/ref-type.mjs +2 -1
- package/dist/application/transform/ref-type.mjs.map +1 -1
- package/dist/application/transform/schema/access-flags.cjs.map +1 -1
- package/dist/application/transform/schema/access-flags.mjs.map +1 -1
- package/dist/application/transform/schema/composition-type.cjs +1 -1
- package/dist/application/transform/schema/composition-type.cjs.map +1 -1
- package/dist/application/transform/schema/composition-type.mjs +2 -2
- package/dist/application/transform/schema/composition-type.mjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.cjs +1 -1
- package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.mjs +2 -2
- package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
- package/dist/application/transform/schema/index-signature-type.cjs +21 -0
- package/dist/application/transform/schema/index-signature-type.cjs.map +1 -0
- package/dist/application/transform/schema/index-signature-type.mjs +19 -0
- package/dist/application/transform/schema/index-signature-type.mjs.map +1 -0
- package/dist/application/transform/schema/input-location.cjs +23 -0
- package/dist/application/transform/schema/input-location.cjs.map +1 -0
- package/dist/application/transform/schema/input-location.mjs +21 -0
- package/dist/application/transform/schema/input-location.mjs.map +1 -0
- package/dist/application/transform/schema/object-type.cjs +18 -8
- package/dist/application/transform/schema/object-type.cjs.map +1 -1
- package/dist/application/transform/schema/object-type.mjs +19 -9
- package/dist/application/transform/schema/object-type.mjs.map +1 -1
- package/dist/application/transform/schema/ref-siblings.cjs +47 -0
- package/dist/application/transform/schema/ref-siblings.cjs.map +1 -0
- package/dist/application/transform/schema/ref-siblings.mjs +45 -0
- package/dist/application/transform/schema/ref-siblings.mjs.map +1 -0
- package/dist/application/transform/schema/schema-transform.cjs +6 -3
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.mjs +6 -3
- package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs +2 -30
- package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.mjs +3 -31
- package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
- package/dist/application/transform/schema-comment.cjs +5 -1
- package/dist/application/transform/schema-comment.cjs.map +1 -1
- package/dist/application/transform/schema-comment.mjs +5 -1
- package/dist/application/transform/schema-comment.mjs.map +1 -1
- package/dist/cli/api-logger.cjs +13 -0
- package/dist/cli/api-logger.cjs.map +1 -0
- package/dist/cli/api-logger.mjs +11 -0
- package/dist/cli/api-logger.mjs.map +1 -0
- package/dist/cli/api-settings.cjs +57 -9
- package/dist/cli/api-settings.cjs.map +1 -1
- package/dist/cli/api-settings.mjs +56 -11
- package/dist/cli/api-settings.mjs.map +1 -1
- package/dist/cli/api-writes.cjs +72 -0
- package/dist/cli/api-writes.cjs.map +1 -0
- package/dist/cli/api-writes.mjs +69 -0
- package/dist/cli/api-writes.mjs.map +1 -0
- package/dist/cli/cli-arguments.cjs +51 -11
- package/dist/cli/cli-arguments.cjs.map +1 -1
- package/dist/cli/cli-arguments.mjs +51 -11
- package/dist/cli/cli-arguments.mjs.map +1 -1
- package/dist/cli/cli-errors.cjs +29 -1
- package/dist/cli/cli-errors.cjs.map +1 -1
- package/dist/cli/cli-errors.mjs +29 -2
- package/dist/cli/cli-errors.mjs.map +1 -1
- package/dist/cli/cli-output.cjs +111 -4
- package/dist/cli/cli-output.cjs.map +1 -1
- package/dist/cli/cli-output.mjs +104 -5
- package/dist/cli/cli-output.mjs.map +1 -1
- package/dist/cli/main.cjs +13 -3
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.mjs +14 -4
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +94 -37
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +99 -42
- package/dist/cli/redocly-apis.mjs.map +1 -1
- package/dist/cli/ref-limits.cjs +15 -1
- package/dist/cli/ref-limits.cjs.map +1 -1
- package/dist/cli/ref-limits.mjs +15 -2
- package/dist/cli/ref-limits.mjs.map +1 -1
- package/dist/cli/run-cli.cjs +37 -14
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +39 -16
- package/dist/cli/run-cli.mjs.map +1 -1
- package/dist/domain/append-all.cjs +10 -0
- package/dist/domain/append-all.cjs.map +1 -0
- package/dist/domain/append-all.mjs +8 -0
- package/dist/domain/append-all.mjs.map +1 -0
- package/dist/domain/cause-secrets.cjs +52 -0
- package/dist/domain/cause-secrets.cjs.map +1 -0
- package/dist/domain/cause-secrets.mjs +50 -0
- package/dist/domain/cause-secrets.mjs.map +1 -0
- package/dist/domain/errors.cjs +11 -3
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +11 -3
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/ir/identifier-text.cjs.map +1 -1
- package/dist/domain/ir/identifier-text.mjs +1 -1
- package/dist/domain/ir/identifier-text.mjs.map +1 -1
- package/dist/domain/ir/ir-shape.cjs +187 -0
- package/dist/domain/ir/ir-shape.cjs.map +1 -0
- package/dist/domain/ir/ir-shape.mjs +184 -0
- package/dist/domain/ir/ir-shape.mjs.map +1 -0
- package/dist/domain/ir/newer-identifier-ranges.cjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.cjs.map +1 -1
- package/dist/domain/ir/newer-identifier-ranges.mjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.mjs.map +1 -1
- package/dist/domain/location-text.cjs +9 -0
- package/dist/domain/location-text.cjs.map +1 -0
- package/dist/domain/location-text.mjs +7 -0
- package/dist/domain/location-text.mjs.map +1 -0
- package/dist/domain/openapi/alias-expansion.cjs +3 -1
- package/dist/domain/openapi/alias-expansion.cjs.map +1 -1
- package/dist/domain/openapi/alias-expansion.mjs +3 -1
- package/dist/domain/openapi/alias-expansion.mjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.cjs +3 -3
- package/dist/domain/openapi/discriminated-union.cjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.mjs +4 -4
- package/dist/domain/openapi/discriminated-union.mjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.cjs +10 -6
- package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.mjs +11 -7
- package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -1
- package/dist/domain/openapi/document-places.cjs +55 -0
- package/dist/domain/openapi/document-places.cjs.map +1 -0
- package/dist/domain/openapi/document-places.mjs +53 -0
- package/dist/domain/openapi/document-places.mjs.map +1 -0
- package/dist/domain/openapi/json-pointer.cjs +43 -1
- package/dist/domain/openapi/json-pointer.cjs.map +1 -1
- package/dist/domain/openapi/json-pointer.mjs +40 -2
- package/dist/domain/openapi/json-pointer.mjs.map +1 -1
- package/dist/domain/openapi/schema-dialect.cjs +15 -0
- package/dist/domain/openapi/schema-dialect.cjs.map +1 -0
- package/dist/domain/openapi/schema-dialect.mjs +12 -0
- package/dist/domain/openapi/schema-dialect.mjs.map +1 -0
- package/dist/domain/openapi/unsupported-features.cjs +1 -1
- package/dist/domain/openapi/unsupported-features.cjs.map +1 -1
- package/dist/domain/openapi/unsupported-features.mjs +2 -2
- package/dist/domain/openapi/unsupported-features.mjs.map +1 -1
- package/dist/domain/output-fixes.cjs +20 -0
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +20 -0
- package/dist/domain/output-fixes.mjs.map +1 -1
- package/dist/domain/terminal-text.cjs +31 -0
- package/dist/domain/terminal-text.cjs.map +1 -0
- package/dist/domain/terminal-text.mjs +29 -0
- package/dist/domain/terminal-text.mjs.map +1 -0
- package/dist/domain/url-secrets.cjs +48 -0
- package/dist/domain/url-secrets.cjs.map +1 -0
- package/dist/domain/url-secrets.mjs +45 -0
- package/dist/domain/url-secrets.mjs.map +1 -0
- package/dist/domain/warnings.cjs +1 -0
- package/dist/domain/warnings.cjs.map +1 -1
- package/dist/domain/warnings.mjs +1 -0
- package/dist/domain/warnings.mjs.map +1 -1
- package/dist/index.d.cts +46 -20
- package/dist/index.d.mts +46 -20
- package/dist/index.d.ts +46 -20
- package/package.json +4 -5
- package/src/adapters/node-file-system/file-claims.ts +138 -0
- package/src/adapters/node-file-system/file-identity.ts +137 -0
- package/src/adapters/node-file-system/node-file-system.ts +158 -18
- package/src/adapters/pipe-safe-writer/pipe-safe-writer.ts +29 -0
- package/src/adapters/redocly-loader/bundled-mapping-copies.ts +60 -0
- package/src/adapters/redocly-loader/bundled-ref-repair.ts +2 -2
- package/src/adapters/redocly-loader/component-schemas.ts +19 -0
- package/src/adapters/redocly-loader/loaded-documents.ts +46 -0
- package/src/adapters/redocly-loader/mapping-schema-names.ts +25 -0
- package/src/adapters/redocly-loader/query-named-components.ts +201 -0
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +64 -38
- package/src/adapters/redocly-loader/ref-access.ts +51 -4
- package/src/adapters/redocly-loader/ref-holders.ts +76 -15
- package/src/adapters/redocly-loader/remote-body-limit.ts +66 -0
- package/src/adapters/redocly-loader/remote-fetch.ts +85 -13
- package/src/adapters/redocly-loader/remote-node-limit.ts +102 -0
- package/src/adapters/redocly-loader/schema-load-errors.ts +52 -13
- package/src/adapters/redocly-loader/schema-source.ts +35 -11
- package/src/adapters/redocly-loader/unsupported-keys.ts +3 -7
- package/src/adapters/terminal-logger/terminal-logger.ts +17 -6
- package/src/api/default-ports.ts +33 -4
- package/src/api/discriminator-enum-parent.ts +3 -3
- package/src/api/discriminator-other-owners.ts +5 -3
- package/src/api/discriminator-patch.ts +5 -1
- package/src/api/discriminator-scan.ts +16 -8
- package/src/api/document-refs.ts +29 -1
- package/src/api/document-run.ts +10 -19
- package/src/api/legacy-utils.ts +5 -1
- package/src/api/openapi-ts.ts +26 -8
- package/src/api/ref-limit-options.ts +76 -0
- package/src/api/run-context.ts +3 -0
- package/src/api/schema-callbacks.ts +60 -17
- package/src/api/transform-context.ts +7 -3
- package/src/api/transform-schema.ts +79 -12
- package/src/application/ports/file-system.ts +47 -0
- package/src/application/ports/schema-loader.ts +11 -1
- package/src/application/print/text-writer.ts +10 -3
- package/src/application/stack-overflow.ts +9 -5
- package/src/application/transform/declared-value-types.ts +42 -0
- package/src/application/transform/document/components.ts +2 -2
- package/src/application/transform/document/declared-type-names.ts +36 -0
- package/src/application/transform/document/defs-root.ts +2 -2
- package/src/application/transform/document/document.ts +8 -5
- package/src/application/transform/document/enum-names-given-back.ts +91 -0
- package/src/application/transform/document/exploded-query-values.ts +88 -0
- package/src/application/transform/document/global-type-references.ts +1 -1
- package/src/application/transform/document/header.ts +25 -5
- package/src/application/transform/document/media-type.ts +4 -3
- package/src/application/transform/document/operation-keys-written.ts +27 -0
- package/src/application/transform/document/operation.ts +2 -2
- package/src/application/transform/document/parameter-entries.ts +70 -0
- package/src/application/transform/document/parameter.ts +21 -9
- package/src/application/transform/document/parameters.ts +56 -66
- package/src/application/transform/document/path-item.ts +16 -34
- package/src/application/transform/document/path-template-key.ts +152 -0
- package/src/application/transform/document/path-template-refs.ts +106 -0
- package/src/application/transform/document/paths-enum.ts +24 -10
- package/src/application/transform/document/paths.ts +59 -125
- package/src/application/transform/document/referenced-parameter.ts +146 -0
- package/src/application/transform/document/request-body.ts +2 -2
- package/src/application/transform/document/response.ts +3 -3
- package/src/application/transform/document/responses.ts +2 -2
- package/src/application/transform/document/root-type-aliases.ts +17 -38
- package/src/application/transform/document/type-resolution.ts +2 -1
- package/src/application/transform/document/webhooks.ts +19 -6
- package/src/application/transform/footer/document-footer.ts +36 -9
- package/src/application/transform/footer/enum-name-claims.ts +62 -0
- package/src/application/transform/footer/operation-keys.ts +28 -0
- package/src/application/transform/footer/type-evaluation.ts +4 -4
- package/src/application/transform/helper-types.ts +8 -7
- package/src/application/transform/numbered-names.ts +15 -0
- package/src/application/transform/ref-pointer/generated-location.ts +3 -3
- package/src/application/transform/ref-pointer/generated-shape.ts +67 -78
- package/src/application/transform/ref-pointer/inline-cycles.ts +1 -1
- package/src/application/transform/ref-pointer/located-node.ts +38 -0
- package/src/application/transform/ref-pointer/original-index.ts +100 -17
- package/src/application/transform/ref-pointer/pointer-type.ts +1 -1
- package/src/application/transform/ref-pointer/pointer-walk.ts +82 -8
- package/src/application/transform/ref-pointer/property-shape.ts +97 -0
- package/src/application/transform/ref-pointer/typed-walk.ts +117 -25
- package/src/application/transform/ref-type.ts +2 -1
- package/src/application/transform/schema/access-flags.ts +5 -2
- package/src/application/transform/schema/composition-type.ts +2 -2
- package/src/application/transform/schema/enum-rule.ts +6 -2
- package/src/application/transform/schema/index-signature-type.ts +31 -0
- package/src/application/transform/schema/input-location.ts +35 -0
- package/src/application/transform/schema/object-type.ts +22 -12
- package/src/application/transform/schema/ref-siblings.ts +76 -0
- package/src/application/transform/schema/schema-context.ts +3 -0
- package/src/application/transform/schema/schema-transform.ts +6 -3
- package/src/application/transform/schema/unevaluated-properties.ts +4 -44
- package/src/application/transform/schema-comment.ts +5 -1
- package/src/application/transform/transform-context.ts +5 -0
- package/src/cli/api-logger.ts +17 -0
- package/src/cli/api-settings.ts +80 -13
- package/src/cli/api-writes.ts +117 -0
- package/src/cli/cli-arguments.ts +90 -14
- package/src/cli/cli-dependencies.ts +26 -4
- package/src/cli/cli-errors.ts +42 -1
- package/src/cli/cli-output.ts +195 -15
- package/src/cli/main.ts +14 -5
- package/src/cli/redocly-apis.ts +177 -52
- package/src/cli/ref-limits.ts +21 -2
- package/src/cli/run-cli.ts +76 -15
- package/src/domain/append-all.ts +10 -0
- package/src/domain/cause-secrets.ts +86 -0
- package/src/domain/errors.ts +16 -5
- package/src/domain/ir/identifier-text.ts +6 -5
- package/src/domain/ir/ir-shape.ts +299 -0
- package/src/domain/ir/newer-identifier-ranges.ts +183 -30
- package/src/domain/location-text.ts +12 -0
- package/src/domain/openapi/alias-expansion.ts +4 -1
- package/src/domain/openapi/discriminated-union.ts +6 -4
- package/src/domain/openapi/discriminator-conflicts.ts +21 -7
- package/src/domain/openapi/document-object.ts +2 -0
- package/src/domain/openapi/document-places.ts +78 -0
- package/src/domain/openapi/json-pointer.ts +96 -7
- package/src/domain/openapi/schema-dialect.ts +22 -0
- package/src/domain/openapi/unsupported-features.ts +2 -2
- package/src/domain/output-fixes.ts +28 -2
- package/src/domain/terminal-text.ts +44 -0
- package/src/domain/url-secrets.ts +72 -0
- package/src/domain/warnings.ts +1 -0
- package/src/types/generator-options.ts +1 -1
- package/dist/cli/main.d.cts +0 -2
- package/dist/cli/main.d.mts +0 -2
- package/dist/cli/main.d.ts +0 -2
- package/dist/domain/url-credentials.cjs +0 -10
- package/dist/domain/url-credentials.cjs.map +0 -1
- package/dist/domain/url-credentials.mjs +0 -8
- package/dist/domain/url-credentials.mjs.map +0 -1
- package/src/domain/url-credentials.ts +0 -18
package/dist/cli/cli-output.mjs
CHANGED
|
@@ -1,19 +1,114 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
3
3
|
import { formatDuration } from '../adapters/terminal-logger/terminal-logger.mjs';
|
|
4
|
+
import { hasUrlScheme } from '../domain/location-text.mjs';
|
|
5
|
+
import { terminalSafeText } from '../domain/terminal-text.mjs';
|
|
6
|
+
import { redactUnparsedUrl, redactUrlSecrets } from '../domain/url-secrets.mjs';
|
|
4
7
|
import { cliError } from './cli-errors.mjs';
|
|
5
8
|
|
|
6
|
-
const URL_SCHEME = /^[a-z][a-z\d+.-]+:/i;
|
|
7
9
|
function resolveLocationUrl(location, base) {
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
+
if (hasUrlScheme(location)) {
|
|
11
|
+
const url = URL.parse(location, base.href);
|
|
12
|
+
if (url === null) {
|
|
13
|
+
const shown = redactUnparsedUrl(location);
|
|
14
|
+
throw cliError("CLI_LOCATION_INVALID", `The location ${shown} is not a valid URL`);
|
|
15
|
+
}
|
|
16
|
+
return url;
|
|
10
17
|
}
|
|
11
18
|
const baseDirectory = fileURLToPath(new URL(".", base));
|
|
12
19
|
return pathToFileURL(path.resolve(baseDirectory, location));
|
|
13
20
|
}
|
|
21
|
+
const FILE_PROTOCOL = "file:";
|
|
22
|
+
const DIRECTORY_SEGMENTS = /* @__PURE__ */ new Set([".", ".."]);
|
|
23
|
+
function namesDirectory(location, file) {
|
|
24
|
+
const lastSegment = location.split(path.sep).flatMap((part) => part.split("/")).at(-1);
|
|
25
|
+
return lastSegment === "" || DIRECTORY_SEGMENTS.has(lastSegment ?? "") || file.pathname.endsWith("/");
|
|
26
|
+
}
|
|
27
|
+
function invalidOutput(output, reason) {
|
|
28
|
+
return cliError("CLI_OUTPUT_INVALID", `The output ${output} ${reason}`);
|
|
29
|
+
}
|
|
30
|
+
function outputUrlOf(run, output, base) {
|
|
31
|
+
const file = parseLocationUrl(output, base);
|
|
32
|
+
if (file?.protocol !== FILE_PROTOCOL) {
|
|
33
|
+
throw invalidOutput(
|
|
34
|
+
output,
|
|
35
|
+
"is not a local file. Write the types to a file path or a file: URL."
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
if (!isLocalFile(file)) {
|
|
39
|
+
throw invalidOutput(output, "names no file on this computer. Use a file path instead.");
|
|
40
|
+
}
|
|
41
|
+
if (namesDirectory(output, file) || run.deps.files.isDirectory(file)) {
|
|
42
|
+
throw invalidOutput(output, "is a directory. Name the file to write the types to in it.");
|
|
43
|
+
}
|
|
44
|
+
return file;
|
|
45
|
+
}
|
|
46
|
+
function isLocalFile(file) {
|
|
47
|
+
try {
|
|
48
|
+
fileURLToPath(file);
|
|
49
|
+
return true;
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function outputFileOf(run, named, base) {
|
|
55
|
+
return { ...named, file: outputUrlOf(run, named.output, base) };
|
|
56
|
+
}
|
|
57
|
+
function filesAtOutput(run, output, files) {
|
|
58
|
+
return files.filter(
|
|
59
|
+
({ location }) => location.protocol === FILE_PROTOCOL && run.deps.files.isSameFile(location, output.file)
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
function displayPathOf(run, location) {
|
|
63
|
+
return path.relative(fileURLToPath(run.deps.cwd), fileURLToPath(location)) || ".";
|
|
64
|
+
}
|
|
65
|
+
function redoclyConfigFiles(run, redocly) {
|
|
66
|
+
if (!redocly.configFile) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
const location = resolveLocationUrl(redocly.configFile, run.deps.cwd);
|
|
70
|
+
return [{ name: `Redocly config ${displayPathOf(run, location)}`, location }];
|
|
71
|
+
}
|
|
72
|
+
function filesReadBy(run, types, owner) {
|
|
73
|
+
return types.localFiles.map((location) => ({
|
|
74
|
+
name: `schema ${displayPathOf(run, location)} that ${owner} reads`,
|
|
75
|
+
location
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
function ensureOutputIsNotSchema(run, output, schemas) {
|
|
79
|
+
const [schema] = filesAtOutput(run, output, schemas);
|
|
80
|
+
if (schema) {
|
|
81
|
+
throw cliError(
|
|
82
|
+
"CLI_OUTPUT_IS_INPUT",
|
|
83
|
+
`The output ${output.output} is the ${schema.name}: writing the types would overwrite it. Choose another output file.`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function ensureOutputIsOwn(run, output, otherOutputs) {
|
|
88
|
+
const clashes = filesAtOutput(run, output, otherOutputs);
|
|
89
|
+
if (clashes.length > 0) {
|
|
90
|
+
throw duplicateOutputError(
|
|
91
|
+
output,
|
|
92
|
+
clashes.map(({ name }) => name)
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function duplicateOutputError(output, others) {
|
|
97
|
+
return cliError(
|
|
98
|
+
"CLI_OUTPUT_DUPLICATE",
|
|
99
|
+
`The output ${output.output} of API ${output.source} is also the output of ${others.join(", ")}: they would overwrite each other. Give each API its own output file.`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
function parseLocationUrl(location, base) {
|
|
103
|
+
if (hasUrlScheme(location)) {
|
|
104
|
+
return URL.parse(location, base.href) ?? void 0;
|
|
105
|
+
}
|
|
106
|
+
return resolveLocationUrl(location, base);
|
|
107
|
+
}
|
|
14
108
|
function printDone(run, output) {
|
|
15
109
|
const { style, now } = run.deps;
|
|
16
|
-
const
|
|
110
|
+
const source = terminalSafeText(redactUrlSecrets(output.source));
|
|
111
|
+
const target = style.green(`${source} \u2192 ${style.bold(terminalSafeText(output.output))}`);
|
|
17
112
|
const duration = style.dim(`[${formatDuration(now() - run.startedAt)}]`);
|
|
18
113
|
run.deps.console.info(`\u{1F680} ${target} ${duration}`);
|
|
19
114
|
}
|
|
@@ -30,6 +125,10 @@ function emitOutput(run, output, contents) {
|
|
|
30
125
|
run.deps.files.writeText(output.file, contents);
|
|
31
126
|
printDone(run, output);
|
|
32
127
|
}
|
|
128
|
+
function writeOutput(run, output, types, readFiles) {
|
|
129
|
+
ensureOutputIsNotSchema(run, output, readFiles);
|
|
130
|
+
emitOutput(run, output, types.contents);
|
|
131
|
+
}
|
|
33
132
|
|
|
34
|
-
export { emitOutput, resolveLocationUrl };
|
|
133
|
+
export { duplicateOutputError, emitOutput, ensureOutputIsNotSchema, ensureOutputIsOwn, filesReadBy, outputFileOf, parseLocationUrl, redoclyConfigFiles, resolveLocationUrl, writeOutput };
|
|
35
134
|
//# sourceMappingURL=cli-output.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-output.mjs","sources":["../../src/cli/cli-output.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { formatDuration } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { CliArguments } from \"./cli-arguments.js\";\nimport type { CliDependencies } from \"./cli-dependencies.js\";\nimport { cliError } from \"./cli-errors.js\";\n\n/** Writing one generated file, or checking it with `--check`, and the line printed for it. */\n\n/** One CLI run: its dependencies, its arguments and when it started. */\nexport interface CliRun {\n readonly deps: CliDependencies;\n readonly args: CliArguments;\n readonly startedAt: number;\n}\n\n/** A generated file: `source` names the schema and `output` is the path as the user wrote it. */\nexport interface OutputFile {\n readonly source: string;\n readonly output: string;\n readonly file: URL;\n}\n\n/**\n * A scheme of two or more characters (`https:`, `file:`). One letter is a Windows drive (`C:`), so\n * `C:\\\\specs\\\\api.yaml` stays a path.\n */\nconst URL_SCHEME = /^[a-z][a-z\\d+.-]+:/i;\n\n/**\n * The URL of a location the user wrote: a URL as it is, else a file path, absolute or relative to\n * the directory of `base` (a directory or file URL). A path is not parsed as a URL, so `#`, `?` and\n * `%` are part of the file name.\n */\nexport function resolveLocationUrl(location: string, base: URL): URL {\n if (URL_SCHEME.test(location)) {\n return new URL(location);\n }\n const baseDirectory = fileURLToPath(new URL(\".\", base));\n return pathToFileURL(path.resolve(baseDirectory, location));\n}\n\nfunction printDone(run: CliRun, output: OutputFile): void {\n const { style, now } = run.deps;\n const target = style.green(`${output.source} → ${style.bold(output.output)}`);\n const duration = style.dim(`[${formatDuration(now() - run.startedAt)}]`);\n run.deps.console.info(`🚀 ${target} ${duration}`);\n}\n\n/**\n * With `--check`, fail with `OUTPUT_STALE` when the file differs from `contents` and leave it\n * alone otherwise. Without it, write the file and print where it went.\n */\nexport function emitOutput(run: CliRun, output: OutputFile, contents: string): void {\n if (run.args.isCheck) {\n if (run.deps.files.readText(output.file) !== contents) {\n // The original message, then the file: with several APIs it tells which one is stale.\n throw cliError(\n \"OUTPUT_STALE\",\n `Generated types are not up-to-date! ${output.output} differs from its schema.`,\n );\n }\n return;\n }\n run.deps.files.writeText(output.file, contents);\n printDone(run, output);\n}\n"],"names":[],"mappings":";;;;;AA2BA,MAAM,UAAA,GAAa,qBAAA;AAOZ,SAAS,kBAAA,CAAmB,UAAkB,IAAA,EAAgB;AACnE,EAAA,IAAI,UAAA,CAAW,IAAA,CAAK,QAAQ,CAAA,EAAG;AAC7B,IAAA,O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K,MAAM,CAAA;AACvB;;"}
|
|
1
|
+
{"version":3,"file":"cli-output.mjs","sources":["../../src/cli/cli-output.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { formatDuration } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport { hasUrlScheme } from \"../domain/location-text.js\";\nimport { terminalSafeText } from \"../domain/terminal-text.js\";\nimport { redactUnparsedUrl, redactUrlSecrets } from \"../domain/url-secrets.js\";\nimport type { CliArguments } from \"./cli-arguments.js\";\nimport type { CliDependencies, GeneratedTypes } from \"./cli-dependencies.js\";\nimport { cliError } from \"./cli-errors.js\";\n\n/** Writing one generated file, or checking it with `--check`, and the line printed for it. */\n\n/** One CLI run: its dependencies, its arguments and when it started. */\nexport interface CliRun {\n readonly deps: CliDependencies;\n readonly args: CliArguments;\n readonly startedAt: number;\n}\n\n/** An output as the user wrote it: `source` names the schema, `output` is the path or URL. */\nexport interface NamedOutput {\n readonly source: string;\n readonly output: string;\n}\n\n/** A generated file: an output with the location of its local file. */\nexport interface OutputFile extends NamedOutput {\n readonly file: URL;\n}\n\n/**\n * The URL of a location the user wrote: a URL, else a file path, absolute or relative to the\n * directory of `base` (a directory or file URL). A relative `file:` URL (`file:api.yaml`) resolves\n * against `base` too, as in openapi-typescript. A path is not parsed as a URL, so `#`, `?` and `%`\n * are part of the file name. A location with a scheme that does not parse as a URL\n * (`http://[::1/x`) fails with `CLI_LOCATION_INVALID`.\n */\nexport function resolveLocationUrl(location: string, base: URL): URL {\n if (hasUrlScheme(location)) {\n const url = URL.parse(location, base.href);\n if (url === null) {\n const shown = redactUnparsedUrl(location);\n throw cliError(\"CLI_LOCATION_INVALID\", `The location ${shown} is not a valid URL`);\n }\n return url;\n }\n const baseDirectory = fileURLToPath(new URL(\".\", base));\n return pathToFileURL(path.resolve(baseDirectory, location));\n}\n\nconst FILE_PROTOCOL = \"file:\";\n\n/** Segments that name a directory: the directory itself and its parent. */\nconst DIRECTORY_SEGMENTS: ReadonlySet<string> = new Set([\".\", \"..\"]);\n\n/**\n * Whether the location names a directory as written, before resolving drops the sign: a trailing\n * `/` (or `\\\\` on Windows), or a last segment `.` or `..` (`-o gen/.`, `-o a/b/..`). For a URL\n * the parsed path tells it too, since the URL parser drops `.`, `..` and their `%2E` forms.\n */\nfunction namesDirectory(location: string, file: URL): boolean {\n const lastSegment = location\n .split(path.sep)\n .flatMap((part) => part.split(\"/\"))\n .at(-1);\n return (\n lastSegment === \"\" || DIRECTORY_SEGMENTS.has(lastSegment ?? \"\") || file.pathname.endsWith(\"/\")\n );\n}\n\nfunction invalidOutput(output: string, reason: string): Error {\n return cliError(\"CLI_OUTPUT_INVALID\", `The output ${output} ${reason}`);\n}\n\n/** The URL of the output, if it is a local file that can be written; it may not exist yet. */\nfunction outputUrlOf(run: CliRun, output: string, base: URL): URL {\n const file = parseLocationUrl(output, base);\n if (file?.protocol !== FILE_PROTOCOL) {\n throw invalidOutput(\n output,\n \"is not a local file. Write the types to a file path or a file: URL.\",\n );\n }\n if (!isLocalFile(file)) {\n throw invalidOutput(output, \"names no file on this computer. Use a file path instead.\");\n }\n if (namesDirectory(output, file) || run.deps.files.isDirectory(file)) {\n throw invalidOutput(output, \"is a directory. Name the file to write the types to in it.\");\n }\n return file;\n}\n\n/** A `file:` URL with a host, or with an encoded slash, names no path on this platform. */\nfunction isLocalFile(file: URL): boolean {\n try {\n fileURLToPath(file);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * The output file of `source`, as the user wrote it in `output`, relative to `base`. Fails with\n * `CLI_OUTPUT_INVALID` before anything is generated when it is not a local file (a URL of\n * another scheme) or is a directory (a trailing separator, a last segment `.` or `..`, or a\n * directory on disk). Without this check, `-o dir/` and `-o dir/.` wrote a file named `dir`.\n */\nexport function outputFileOf(run: CliRun, named: NamedOutput, base: URL): OutputFile {\n return { ...named, file: outputUrlOf(run, named.output, base) };\n}\n\n/** A file the CLI reads or writes: `name` is how an error names it, `location` where it is. */\nexport interface NamedFile {\n readonly name: string;\n readonly location: URL;\n}\n\n/** The `files` that are the local file `output`, also through a link or in another letter case. */\nfunction filesAtOutput(run: CliRun, output: OutputFile, files: readonly NamedFile[]): NamedFile[] {\n return files.filter(\n ({ location }) =>\n location.protocol === FILE_PROTOCOL && run.deps.files.isSameFile(location, output.file),\n );\n}\n\n/** A location as a path relative to the working directory, as error messages name files. */\nfunction displayPathOf(run: CliRun, location: URL): string {\n return path.relative(fileURLToPath(run.deps.cwd), fileURLToPath(location)) || \".\";\n}\n\n/** The Redocly config file the run read, if any: no output may replace it. */\nexport function redoclyConfigFiles(run: CliRun, redocly: RedoclyConfig): NamedFile[] {\n if (!redocly.configFile) {\n return [];\n }\n const location = resolveLocationUrl(redocly.configFile, run.deps.cwd);\n return [{ name: `Redocly config ${displayPathOf(run, location)}`, location }];\n}\n\n/** The local files that `owner` (a schema or an API) was generated from, `$ref`'d ones too. */\nexport function filesReadBy(run: CliRun, types: GeneratedTypes, owner: string): NamedFile[] {\n return types.localFiles.map((location) => ({\n name: `schema ${displayPathOf(run, location)} that ${owner} reads`,\n location,\n }));\n}\n\n/**\n * Fail with `CLI_OUTPUT_IS_INPUT` when `output` is one of the `schemas` (or the Redocly config).\n * Writing it would replace that file with the types, which upstream did without a word. The CLI\n * checks the files it knows before generating, so nothing is loaded or written, and the files\n * that `$ref`s loaded after generating, before anything is written.\n */\nexport function ensureOutputIsNotSchema(\n run: CliRun,\n output: OutputFile,\n schemas: readonly NamedFile[],\n): void {\n const [schema] = filesAtOutput(run, output, schemas);\n if (schema) {\n throw cliError(\n \"CLI_OUTPUT_IS_INPUT\",\n `The output ${output.output} is the ${schema.name}: writing the types would ` +\n \"overwrite it. Choose another output file.\",\n );\n }\n}\n\n/**\n * Fail with `CLI_OUTPUT_DUPLICATE` when the output of an API is also one of `otherOutputs`.\n * Whichever write came last would win, so every API with that output fails, before anything is\n * generated.\n */\nexport function ensureOutputIsOwn(\n run: CliRun,\n output: OutputFile,\n otherOutputs: readonly NamedFile[],\n): void {\n const clashes = filesAtOutput(run, output, otherOutputs);\n if (clashes.length > 0) {\n throw duplicateOutputError(\n output,\n clashes.map(({ name }) => name),\n );\n }\n}\n\n/** `CLI_OUTPUT_DUPLICATE` for `output`, which is also the output of the `others` (named). */\nexport function duplicateOutputError(output: NamedOutput, others: readonly string[]): Error {\n return cliError(\n \"CLI_OUTPUT_DUPLICATE\",\n `The output ${output.output} of API ${output.source} is also the output of ` +\n `${others.join(\", \")}: they would overwrite each other. Give each API its own output file.`,\n );\n}\n\n/** As `resolveLocationUrl`, but undefined for a URL that does not parse instead of a throw. */\nexport function parseLocationUrl(location: string, base: URL): URL | undefined {\n if (hasUrlScheme(location)) {\n return URL.parse(location, base.href) ?? undefined;\n }\n return resolveLocationUrl(location, base);\n}\n\n/**\n * The line for a written file. It goes to the job log, so a source URL shows no secrets, and a\n * line break or escape sequence in a name cannot start a forged line.\n */\nfunction printDone(run: CliRun, output: OutputFile): void {\n const { style, now } = run.deps;\n const source = terminalSafeText(redactUrlSecrets(output.source));\n const target = style.green(`${source} → ${style.bold(terminalSafeText(output.output))}`);\n const duration = style.dim(`[${formatDuration(now() - run.startedAt)}]`);\n run.deps.console.info(`🚀 ${target} ${duration}`);\n}\n\n/**\n * With `--check`, fail with `OUTPUT_STALE` when the file differs from `contents` and leave it\n * alone otherwise. Without it, write the file and print where it went.\n */\nexport function emitOutput(run: CliRun, output: OutputFile, contents: string): void {\n if (run.args.isCheck) {\n if (run.deps.files.readText(output.file) !== contents) {\n // The original message, then the file: with several APIs it tells which one is stale.\n throw cliError(\n \"OUTPUT_STALE\",\n `Generated types are not up-to-date! ${output.output} differs from its schema.`,\n );\n }\n return;\n }\n run.deps.files.writeText(output.file, contents);\n printDone(run, output);\n}\n\n/** Write (or `--check`) the types, unless the output is one of the files the run read. */\nexport function writeOutput(\n run: CliRun,\n output: OutputFile,\n types: GeneratedTypes,\n readFiles: readonly N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,KAAA,CAAM,GAAA,CAAI,CAAA,CAAA,EAAI,cAAA,CAAe,KAAI,GAAI,GAAA,CAAI,SAAS,CAAC,CAAA,CAAA,CAAG,CAAA;AACvE,EAAA,GAAA,CAAI,KAAK,OAAA,CAAQ,IAAA,CAAK,aAAM,MAAM,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAE,CAAA;AAClD;AAMO,SAAS,UAAA,CAAW,GAAA,EAAa,MAAA,EAAoB,QAAA,EAAwB;AAClF,EAAA,IAAI,GAAA,CAAI,KAAK,OAAA,EAAS;AACpB,IAAA,IAAI,IAAI,IAAA,CAAK,KAAA,CAAM,SAAS,MAAA,CAAO,IAAI,MAAM,QAAA,EAAU;AAErD,MAAA,MAAM,QAAA;AAAA,QACJ,cAAA;AAAA,QACA,CAAA,oCAAA,EAAuC,OAAO,MAAM,CAAA,yBAAA;AAAA,OACtD;AAAA,IACF;AACA,IAAA;AAAA,EACF;AACA,EAAA,GAAA,CAAI,IAAA,CAAK,KAAA,CAAM,SAAA,CAAU,MAAA,CAAO,MAAM,QAAQ,CAAA;AAC9C,EAAA,SAAA,CAAU,KAAK,MAAM,CAAA;AACvB;AAGO,SAAS,WAAA,CACd,GAAA,EACA,MAAA,EACA,KAAA,EACA,SAAA,EACM;AACN,EAAA,uBAAA,CAAwB,GAAA,EAAK,QAAQ,SAAS,CAAA;AAC9C,EAAA,UAAA,CAAW,GAAA,EAAK,MAAA,EAAQ,KAAA,CAAM,QAAQ,CAAA;AACxC;;"}
|
package/dist/cli/main.cjs
CHANGED
|
@@ -5,11 +5,14 @@ const node_tty = require('node:tty');
|
|
|
5
5
|
const node_url = require('node:url');
|
|
6
6
|
const colors = require('ansi-colors');
|
|
7
7
|
const nodeFileSystem = require('../adapters/node-file-system/node-file-system.cjs');
|
|
8
|
+
const pipeSafeWriter = require('../adapters/pipe-safe-writer/pipe-safe-writer.cjs');
|
|
8
9
|
const redoclyConfigSource = require('../adapters/redocly-loader/redocly-config-source.cjs');
|
|
9
10
|
const astToString = require('../api/ast-to-string.cjs');
|
|
10
11
|
const commentHeader = require('../api/comment-header.cjs');
|
|
11
12
|
const defaultPorts = require('../api/default-ports.cjs');
|
|
12
13
|
const openapiTs = require('../api/openapi-ts.cjs');
|
|
14
|
+
const terminalText = require('../domain/terminal-text.cjs');
|
|
15
|
+
const apiLogger = require('./api-logger.cjs');
|
|
13
16
|
const runCli = require('./run-cli.cjs');
|
|
14
17
|
|
|
15
18
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -33,13 +36,20 @@ function terminalStyle() {
|
|
|
33
36
|
};
|
|
34
37
|
}
|
|
35
38
|
const STDIN_DESCRIPTOR = 0;
|
|
36
|
-
const generateTypes = async (source, options) =>
|
|
39
|
+
const generateTypes = async (source, options, apiName) => {
|
|
40
|
+
const terminalLogger = defaultPorts.defaultLogger(options.silent ?? false);
|
|
41
|
+
const logger = apiName === void 0 ? terminalLogger : apiLogger.apiLogger(terminalLogger, apiName);
|
|
42
|
+
const ports = await openapiTs.defaultGeneratorPorts(options, logger);
|
|
43
|
+
const { declarations, localFiles } = await openapiTs.generateDocument(source, options, ports);
|
|
44
|
+
return { contents: `${commentHeader.COMMENT_HEADER}${astToString.astToString(declarations)}`, localFiles };
|
|
45
|
+
};
|
|
37
46
|
function terminalConsole() {
|
|
38
47
|
return {
|
|
39
48
|
// biome-ignore lint/suspicious/noConsole: the CLI's own output lines
|
|
40
49
|
info: (text) => console.info(text),
|
|
50
|
+
// A notice names flags and API names as written, so it is shown as one plain line.
|
|
41
51
|
// biome-ignore lint/suspicious/noConsole: the CLI's own notices
|
|
42
|
-
notice: (text) => console.warn(text)
|
|
52
|
+
notice: (text) => console.warn(terminalText.terminalSafeText(text))
|
|
43
53
|
};
|
|
44
54
|
}
|
|
45
55
|
function processDependencies() {
|
|
@@ -49,7 +59,7 @@ function processDependencies() {
|
|
|
49
59
|
version: readVersion(),
|
|
50
60
|
logger: defaultPorts.defaultLogger(false),
|
|
51
61
|
console: terminalConsole(),
|
|
52
|
-
writeStdout: (
|
|
62
|
+
writeStdout: pipeSafeWriter.createPipeSafeWriter(process.stdout),
|
|
53
63
|
stdin: () => process.stdin,
|
|
54
64
|
// `isatty` reads the descriptor without opening `process.stdin`, which would keep the
|
|
55
65
|
// process alive.
|
package/dist/cli/main.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.cjs","sources":["../../src/cli/main.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { isatty } from \"node:tty\";\nimport { pathToFileURL } from \"node:url\";\nimport colors from \"ansi-colors\";\nimport { createNodeFileSystem } from \"../adapters/node-file-system/node-file-system.js\";\nimport { createRedoclyConfigSource } from \"../adapters/redocly-loader/redocly-config-source.js\";\nimport { astToString } from \"../api/ast-to-string.js\";\nimport { COMMENT_HEADER } from \"../api/comment-header.js\";\nimport { defaultLogger, monotonicNow, terminalSupportsColor } from \"../api/default-ports.js\";\nimport
|
|
1
|
+
{"version":3,"file":"main.cjs","sources":["../../src/cli/main.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { isatty } from \"node:tty\";\nimport { pathToFileURL } from \"node:url\";\nimport colors from \"ansi-colors\";\nimport { createNodeFileSystem } from \"../adapters/node-file-system/node-file-system.js\";\nimport { createPipeSafeWriter } from \"../adapters/pipe-safe-writer/pipe-safe-writer.js\";\nimport { createRedoclyConfigSource } from \"../adapters/redocly-loader/redocly-config-source.js\";\nimport { astToString } from \"../api/ast-to-string.js\";\nimport { COMMENT_HEADER } from \"../api/comment-header.js\";\nimport { defaultLogger, monotonicNow, terminalSupportsColor } from \"../api/default-ports.js\";\nimport { defaultGeneratorPorts, generateDocument } from \"../api/openapi-ts.js\";\nimport { terminalSafeText } from \"../domain/terminal-text.js\";\nimport { apiLogger } from \"./api-logger.js\";\nimport type { CliConsole, CliDependencies, GenerateTypes, TextStyle } from \"./cli-dependencies.js\";\nimport { runCli } from \"./run-cli.js\";\n\n/**\n * The CLI's composition root (ENGINEERING_PLAN 4.5, ADR-012): the only CLI module that touches the\n * process. `bin/cli.js` imports the built copy of this module.\n */\n\n/** The same path from `src/cli/` and from the built `dist/cli/`. */\nconst PACKAGE_JSON = new URL(\"../../package.json\", import.meta.url);\n\nfunction readVersion(): string {\n const packageJson: { version: string } = JSON.parse(fs.readFileSync(PACKAGE_JSON, \"utf8\"));\n return packageJson.version;\n}\n\nfunction terminalStyle(): TextStyle {\n const palette = colors.create();\n palette.enabled = terminalSupportsColor();\n return {\n bold: (text) => palette.bold(text),\n green: (text) => palette.green(text),\n dim: (text) => palette.dim(text),\n };\n}\n\nconst STDIN_DESCRIPTOR = 0;\n\nconst generateTypes: GenerateTypes = async (source, options, apiName) => {\n const terminalLogger = defaultLogger(options.silent ?? false);\n const logger = apiName === undefined ? terminalLogger : apiLogger(terminalLogger, apiName);\n const ports = await defaultGeneratorPorts(options, logger);\n const { declarations, localFiles } = await generateDocument(source, options, ports);\n return { contents: `${COMMENT_HEADER}${astToString(declarations)}`, localFiles };\n};\n\nfunction terminalConsole(): CliConsole {\n return {\n // biome-ignore lint/suspicious/noConsole: the CLI's own output lines\n info: (text) => console.info(text),\n // A notice names flags and API names as written, so it is shown as one plain line.\n // biome-ignore lint/suspicious/noConsole: the CLI's own notices\n notice: (text) => console.warn(terminalSafeText(text)),\n };\n}\n\nfunction processDependencies(): CliDependencies {\n const cwd = process.cwd();\n return {\n cwd: pathToFileURL(`${cwd}/`),\n version: readVersion(),\n logger: defaultLogger(false),\n console: terminalConsole(),\n writeStdout: createPipeSafeWriter(process.stdout),\n stdin: () => process.stdin,\n // `isatty` reads the descriptor without opening `process.stdin`, which would keep the\n // process alive.\n isStdinTerminal: () => isatty(STDIN_DESCRIPTOR),\n files: createNodeFileSystem(),\n redoclyConfigs: createRedoclyConfigSource(cwd),\n generate: generateTypes,\n now: monotonicNow,\n style: terminalStyle(),\n };\n}\n\nrunCli(process.argv.slice(2), processDependencies()).then((exitCode) => {\n process.exitCode = exitCode;\n});\n"],"names":["fs","colors","terminalSupportsColor","defaultLogger","apiLogger","defaultGeneratorPorts","generateDocument","COMMENT_HEADER","astToString","terminalSafeText","pathToFileURL","createPipeSafeWriter","isatty","createNodeFileSystem","createRedoclyConfigSource","monotonicNow","runCli"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,oBAAA,EAAsB,8PAAe,CAAA;AAElE,SAAS,WAAA,GAAsB;AAC7B,EAAA,MAAM,cAAmC,IAAA,CAAK,KAAA,CAAMA,YAAG,YAAA,CAAa,YAAA,EAAc,MAAM,CAAC,CAAA;AACzF,EAAA,OAAO,WAAA,CAAY,OAAA;AACrB;AAEA,SAAS,aAAA,GAA2B;AAClC,EAAA,MAAM,OAAA,GAAUC,gBAAO,MAAA,EAAO;AAC9B,EAAA,OAAA,CAAQ,UAAUC,kCAAA,EAAsB;AACxC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,CAAC,IAAA,KAAS,OAAA,CAAQ,KAAK,IAAI,CAAA;AAAA,IACjC,KAAA,EAAO,CAAC,IAAA,KAAS,OAAA,CAAQ,MAAM,IAAI,CAAA;AAAA,IACnC,GAAA,EAAK,CAAC,IAAA,KAAS,OAAA,CAAQ,IAAI,IAAI;AAAA,GACjC;AACF;AAEA,MAAM,gBAAA,GAAmB,CAAA;AAEzB,MAAM,aAAA,GAA+B,OAAO,MAAA,EAAQ,OAAA,EAAS,OAAA,KAAY;AACvE,EAAA,MAAM,cAAA,GAAiBC,0BAAA,CAAc,OAAA,CAAQ,MAAA,IAAU,KAAK,CAAA;AAC5D,EAAA,MAAM,SAAS,OAAA,KAAY,MAAA,GAAY,cAAA,GAAiBC,mBAAA,CAAU,gBAAgB,OAAO,CAAA;AACzF,EAAA,MAAM,KAAA,GAAQ,MAAMC,+BAAA,CAAsB,OAAA,EAAS,MAAM,CAAA;AACzD,EAAA,MAAM,EAAE,cAAc,UAAA,EAAW,GAAI,MAAMC,0BAAA,CAAiB,MA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"}
|
package/dist/cli/main.mjs
CHANGED
|
@@ -3,11 +3,14 @@ import { isatty } from 'node:tty';
|
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
import colors from 'ansi-colors';
|
|
5
5
|
import { createNodeFileSystem } from '../adapters/node-file-system/node-file-system.mjs';
|
|
6
|
+
import { createPipeSafeWriter } from '../adapters/pipe-safe-writer/pipe-safe-writer.mjs';
|
|
6
7
|
import { createRedoclyConfigSource } from '../adapters/redocly-loader/redocly-config-source.mjs';
|
|
7
8
|
import { astToString } from '../api/ast-to-string.mjs';
|
|
8
9
|
import { COMMENT_HEADER } from '../api/comment-header.mjs';
|
|
9
10
|
import { monotonicNow, defaultLogger, terminalSupportsColor } from '../api/default-ports.mjs';
|
|
10
|
-
import
|
|
11
|
+
import { defaultGeneratorPorts, generateDocument } from '../api/openapi-ts.mjs';
|
|
12
|
+
import { terminalSafeText } from '../domain/terminal-text.mjs';
|
|
13
|
+
import { apiLogger } from './api-logger.mjs';
|
|
11
14
|
import { runCli } from './run-cli.mjs';
|
|
12
15
|
|
|
13
16
|
const PACKAGE_JSON = new URL("../../package.json", import.meta.url);
|
|
@@ -25,13 +28,20 @@ function terminalStyle() {
|
|
|
25
28
|
};
|
|
26
29
|
}
|
|
27
30
|
const STDIN_DESCRIPTOR = 0;
|
|
28
|
-
const generateTypes = async (source, options) =>
|
|
31
|
+
const generateTypes = async (source, options, apiName) => {
|
|
32
|
+
const terminalLogger = defaultLogger(options.silent ?? false);
|
|
33
|
+
const logger = apiName === void 0 ? terminalLogger : apiLogger(terminalLogger, apiName);
|
|
34
|
+
const ports = await defaultGeneratorPorts(options, logger);
|
|
35
|
+
const { declarations, localFiles } = await generateDocument(source, options, ports);
|
|
36
|
+
return { contents: `${COMMENT_HEADER}${astToString(declarations)}`, localFiles };
|
|
37
|
+
};
|
|
29
38
|
function terminalConsole() {
|
|
30
39
|
return {
|
|
31
40
|
// biome-ignore lint/suspicious/noConsole: the CLI's own output lines
|
|
32
41
|
info: (text) => console.info(text),
|
|
42
|
+
// A notice names flags and API names as written, so it is shown as one plain line.
|
|
33
43
|
// biome-ignore lint/suspicious/noConsole: the CLI's own notices
|
|
34
|
-
notice: (text) => console.warn(text)
|
|
44
|
+
notice: (text) => console.warn(terminalSafeText(text))
|
|
35
45
|
};
|
|
36
46
|
}
|
|
37
47
|
function processDependencies() {
|
|
@@ -41,7 +51,7 @@ function processDependencies() {
|
|
|
41
51
|
version: readVersion(),
|
|
42
52
|
logger: defaultLogger(false),
|
|
43
53
|
console: terminalConsole(),
|
|
44
|
-
writeStdout: (
|
|
54
|
+
writeStdout: createPipeSafeWriter(process.stdout),
|
|
45
55
|
stdin: () => process.stdin,
|
|
46
56
|
// `isatty` reads the descriptor without opening `process.stdin`, which would keep the
|
|
47
57
|
// process alive.
|
package/dist/cli/main.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.mjs","sources":["../../src/cli/main.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { isatty } from \"node:tty\";\nimport { pathToFileURL } from \"node:url\";\nimport colors from \"ansi-colors\";\nimport { createNodeFileSystem } from \"../adapters/node-file-system/node-file-system.js\";\nimport { createRedoclyConfigSource } from \"../adapters/redocly-loader/redocly-config-source.js\";\nimport { astToString } from \"../api/ast-to-string.js\";\nimport { COMMENT_HEADER } from \"../api/comment-header.js\";\nimport { defaultLogger, monotonicNow, terminalSupportsColor } from \"../api/default-ports.js\";\nimport
|
|
1
|
+
{"version":3,"file":"main.mjs","sources":["../../src/cli/main.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { isatty } from \"node:tty\";\nimport { pathToFileURL } from \"node:url\";\nimport colors from \"ansi-colors\";\nimport { createNodeFileSystem } from \"../adapters/node-file-system/node-file-system.js\";\nimport { createPipeSafeWriter } from \"../adapters/pipe-safe-writer/pipe-safe-writer.js\";\nimport { createRedoclyConfigSource } from \"../adapters/redocly-loader/redocly-config-source.js\";\nimport { astToString } from \"../api/ast-to-string.js\";\nimport { COMMENT_HEADER } from \"../api/comment-header.js\";\nimport { defaultLogger, monotonicNow, terminalSupportsColor } from \"../api/default-ports.js\";\nimport { defaultGeneratorPorts, generateDocument } from \"../api/openapi-ts.js\";\nimport { terminalSafeText } from \"../domain/terminal-text.js\";\nimport { apiLogger } from \"./api-logger.js\";\nimport type { CliConsole, CliDependencies, GenerateTypes, TextStyle } from \"./cli-dependencies.js\";\nimport { runCli } from \"./run-cli.js\";\n\n/**\n * The CLI's composition root (ENGINEERING_PLAN 4.5, ADR-012): the only CLI module that touches the\n * process. `bin/cli.js` imports the built copy of this module.\n */\n\n/** The same path from `src/cli/` and from the built `dist/cli/`. */\nconst PACKAGE_JSON = new URL(\"../../package.json\", import.meta.url);\n\nfunction readVersion(): string {\n const packageJson: { version: string } = JSON.parse(fs.readFileSync(PACKAGE_JSON, \"utf8\"));\n return packageJson.version;\n}\n\nfunction terminalStyle(): TextStyle {\n const palette = colors.create();\n palette.enabled = terminalSupportsColor();\n return {\n bold: (text) => palette.bold(text),\n green: (text) => palette.green(text),\n dim: (text) => palette.dim(text),\n };\n}\n\nconst STDIN_DESCRIPTOR = 0;\n\nconst generateTypes: GenerateTypes = async (source, options, apiName) => {\n const terminalLogger = defaultLogger(options.silent ?? false);\n const logger = apiName === undefined ? terminalLogger : apiLogger(terminalLogger, apiName);\n const ports = await defaultGeneratorPorts(options, logger);\n const { declarations, localFiles } = await generateDocument(source, options, ports);\n return { contents: `${COMMENT_HEADER}${astToString(declarations)}`, localFiles };\n};\n\nfunction terminalConsole(): CliConsole {\n return {\n // biome-ignore lint/suspicious/noConsole: the CLI's own output lines\n info: (text) => console.info(text),\n // A notice names flags and API names as written, so it is shown as one plain line.\n // biome-ignore lint/suspicious/noConsole: the CLI's own notices\n notice: (text) => console.warn(terminalSafeText(text)),\n };\n}\n\nfunction processDependencies(): CliDependencies {\n const cwd = process.cwd();\n return {\n cwd: pathToFileURL(`${cwd}/`),\n version: readVersion(),\n logger: defaultLogger(false),\n console: terminalConsole(),\n writeStdout: createPipeSafeWriter(process.stdout),\n stdin: () => process.stdin,\n // `isatty` reads the descriptor without opening `process.stdin`, which would keep the\n // process alive.\n isStdinTerminal: () => isatty(STDIN_DESCRIPTOR),\n files: createNodeFileSystem(),\n redoclyConfigs: createRedoclyConfigSource(cwd),\n generate: generateTypes,\n now: monotonicNow,\n style: terminalStyle(),\n };\n}\n\nrunCli(process.argv.slice(2), processDependencies()).then((exitCode) => {\n process.exitCode = exitCode;\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAsBA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,oBAAA,EAAsB,YAAY,GAAG,CAAA;AAElE,SAAS,WAAA,GAAsB;AAC7B,EAAA,MAAM,cAAmC,IAAA,CAAK,KAAA,CAAM,GAAG,YAAA,CAAa,YAAA,EAAc,MAAM,CAAC,CAAA;AACzF,EAAA,OAAO,WAAA,CAAY,OAAA;AACrB;AAEA,SAAS,aAAA,GAA2B;AAClC,EAAA,MAAM,OAAA,GAAU,OAAO,MAAA,EAAO;AAC9B,EAAA,OAAA,CAAQ,UAAU,qBAAA,EAAsB;AACxC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,CAAC,IAAA,KAAS,OAAA,CAAQ,KAAK,IAAI,CAAA;AAAA,IACjC,KAAA,EAAO,CAAC,IAAA,KAAS,OAAA,CAAQ,MAAM,IAAI,CAAA;AAAA,IACnC,GAAA,EAAK,CAAC,IAAA,KAAS,OAAA,CAAQ,IAAI,IAAI;AAAA,GACjC;AACF;AAEA,MAAM,gBAAA,GAAmB,CAAA;AAEzB,MAAM,aAAA,GAA+B,OAAO,MAAA,EAAQ,OAAA,EAAS,OAAA,KAAY;AACvE,EAAA,MAAM,cAAA,GAAiB,aAAA,CAAc,OAAA,CAAQ,MAAA,IAAU,KAAK,CAAA;AAC5D,EAAA,MAAM,SAAS,OAAA,KAAY,MAAA,GAAY,cAAA,GAAiB,SAAA,CAAU,gBAAgB,OAAO,CAA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,CAAC,CAAA,EAAG,qBAAqB,CAAA,CAAE,IAAA,CAAK,CAAC,QAAA,KAAa;AACtE,EAAA,OAAA,CAAQ,QAAA,GAAW,QAAA;AACrB,CAAC,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const scule = require('scule');
|
|
4
3
|
const apiSettings = require('./api-settings.cjs');
|
|
4
|
+
const apiWrites = require('./api-writes.cjs');
|
|
5
5
|
const cliArguments = require('./cli-arguments.cjs');
|
|
6
6
|
const cliErrors = require('./cli-errors.cjs');
|
|
7
7
|
const cliOutput = require('./cli-output.cjs');
|
|
@@ -12,60 +12,117 @@ const refLimits = require('./ref-limits.cjs');
|
|
|
12
12
|
const REDOCLY_CONFIG_KEY = "x-openapi-ts";
|
|
13
13
|
function redoclyApisOf(redocly) {
|
|
14
14
|
return Object.entries(redocly.apis ?? {}).map(([name, api]) => {
|
|
15
|
-
const
|
|
16
|
-
return { name, root:
|
|
15
|
+
const fields = api;
|
|
16
|
+
return { name, root: fields.root, settings: fields[REDOCLY_CONFIG_KEY] };
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
function hasRedoclyApis(redocly) {
|
|
20
20
|
return Object.keys(redocly.apis ?? {}).length > 0;
|
|
21
21
|
}
|
|
22
|
-
function apiFlags(settings) {
|
|
23
|
-
const flags = {};
|
|
24
|
-
for (const name of cliArguments.GENERATOR_FLAGS) {
|
|
25
|
-
const value = typeof settings[name] === "boolean" ? settings[name] : settings[scule.kebabCase(name)];
|
|
26
|
-
if (typeof value === "boolean") {
|
|
27
|
-
flags[name] = value;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return flags;
|
|
31
|
-
}
|
|
32
|
-
function apiFixNames(settings) {
|
|
33
|
-
return fixOption.fixNamesOf(settings[apiSettings.FIX_SETTING]);
|
|
34
|
-
}
|
|
35
22
|
function configRootOf(redocly, cwd) {
|
|
36
23
|
return redocly.configFile ? cliOutput.resolveLocationUrl(redocly.configFile, cwd) : cwd;
|
|
37
24
|
}
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
function isSettingsMap(value) {
|
|
26
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27
|
+
}
|
|
28
|
+
function apiTarget(api, configRoot) {
|
|
29
|
+
const { name, root, settings } = api;
|
|
30
|
+
if (settings !== void 0 && !isSettingsMap(settings)) {
|
|
31
|
+
throw cliErrors.cliError("CLI_CONFIG_INVALID", `API ${name}: \`${REDOCLY_CONFIG_KEY}\` must be a map`);
|
|
32
|
+
}
|
|
33
|
+
if (!settings?.[apiSettings.OUTPUT_SETTING]) {
|
|
40
34
|
throw cliErrors.cliError(
|
|
41
35
|
"CLI_CONFIG_OUTPUT_MISSING",
|
|
42
|
-
`API ${
|
|
36
|
+
`API ${name} is missing an \`${REDOCLY_CONFIG_KEY}.output\` key. See ${docsLinks.MULTIPLE_SCHEMAS_DOCS_URL}`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
if (typeof root !== "string" || root === "") {
|
|
40
|
+
throw cliErrors.cliError(
|
|
41
|
+
"CLI_CONFIG_INVALID",
|
|
42
|
+
`API ${name}: \`root\` in redocly.yaml must be the path or URL of its schema`
|
|
43
43
|
);
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
return { name, root, settings, configRoot };
|
|
46
|
+
}
|
|
47
|
+
function apiOptions(run, apiRun, target) {
|
|
48
|
+
const { name, settings, configRoot } = target;
|
|
49
|
+
const flags = { ...run.args.generatorFlags, ...apiSettings.apiFlags(name, settings) };
|
|
50
|
+
for (const notice of cliArguments.ineffectiveFlagNotices(flags)) {
|
|
51
|
+
run.deps.console.notice(`API ${name}: ${notice}`);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
...flags,
|
|
55
|
+
...apiRun.refLimits,
|
|
56
|
+
...apiSettings.apiRefLimitOptions(name, settings, configRoot),
|
|
57
|
+
...fixOption.fixOption(apiSettings.apiFixNames(name, settings) ?? run.args.fix),
|
|
58
|
+
redocly: apiRun.redocly
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function otherOutputs(files, apiName) {
|
|
62
|
+
return [...files.outputs].filter(([name]) => name !== apiName).map(([name, location]) => ({ name: `API ${name}`, location }));
|
|
63
|
+
}
|
|
64
|
+
async function generateApi(run, apiRun, target) {
|
|
65
|
+
const { files } = apiRun;
|
|
66
|
+
for (const warning of apiSettings.unknownSettingWarnings(target.name, target.settings)) {
|
|
46
67
|
run.deps.logger.warn(warning);
|
|
47
68
|
}
|
|
48
|
-
const output =
|
|
69
|
+
const output = apiSettings.apiOutputOf(target.name, target.settings);
|
|
70
|
+
const outputFile = cliOutput.outputFileOf(run, { source: target.name, output }, target.configRoot);
|
|
71
|
+
cliOutput.ensureOutputIsNotSchema(run, outputFile, files.schemas);
|
|
72
|
+
cliOutput.ensureOutputIsOwn(run, outputFile, otherOutputs(files, target.name));
|
|
73
|
+
const source = cliOutput.resolveLocationUrl(target.root, target.configRoot);
|
|
74
|
+
const options = apiOptions(run, apiRun, target);
|
|
75
|
+
try {
|
|
76
|
+
const types = await run.deps.generate(source, options, target.name);
|
|
77
|
+
return { name: target.name, outputFile, types };
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw new cliErrors.ApiFailure(target.name, error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function configFilesOf(run, redocly, apis) {
|
|
49
83
|
const configRoot = configRootOf(redocly, run.deps.cwd);
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
84
|
+
const roots = apis.flatMap(({ name, root }) => {
|
|
85
|
+
const location = typeof root === "string" ? cliOutput.parseLocationUrl(root, configRoot) : void 0;
|
|
86
|
+
return location ? [{ name: `schema ${root} of API ${name}`, location }] : [];
|
|
87
|
+
});
|
|
88
|
+
const outputs = /* @__PURE__ */ new Map();
|
|
89
|
+
for (const api of apis) {
|
|
90
|
+
const output = isSettingsMap(api.settings) ? api.settings[apiSettings.OUTPUT_SETTING] : void 0;
|
|
91
|
+
const location = typeof output === "string" ? cliOutput.parseLocationUrl(output, configRoot) : void 0;
|
|
92
|
+
if (location) {
|
|
93
|
+
outputs.set(api.name, location);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const schemas = [...roots, ...cliOutput.redoclyConfigFiles(run, redocly)];
|
|
97
|
+
return { configRoot, files: { schemas, outputs } };
|
|
98
|
+
}
|
|
99
|
+
async function settledInTurn(items, task) {
|
|
100
|
+
const results = [];
|
|
101
|
+
for (const item of items) {
|
|
102
|
+
try {
|
|
103
|
+
results.push({ status: "fulfilled", value: await task(item) });
|
|
104
|
+
} catch (reason) {
|
|
105
|
+
results.push({ status: "rejected", reason });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return results;
|
|
64
109
|
}
|
|
65
110
|
async function generateRedoclyApis(run, redocly) {
|
|
66
111
|
const apis = redoclyApisOf(redocly);
|
|
67
|
-
const
|
|
68
|
-
|
|
112
|
+
const { configRoot, files } = configFilesOf(run, redocly, apis);
|
|
113
|
+
const apiRun = { redocly, files, refLimits: refLimits.refLimitOptions(run.args, run.deps.cwd) };
|
|
114
|
+
const results = await settledInTurn(
|
|
115
|
+
apis,
|
|
116
|
+
(api) => generateApi(run, apiRun, apiTarget(api, configRoot))
|
|
117
|
+
);
|
|
118
|
+
const generated = results.flatMap(
|
|
119
|
+
(result) => result.status === "fulfilled" ? [result.value] : []
|
|
120
|
+
);
|
|
121
|
+
const readFiles = generated.flatMap(({ name, types }) => cliOutput.filesReadBy(run, types, `API ${name}`));
|
|
122
|
+
const writeFailures = apiWrites.writeGeneratedApis(run, generated, readFiles);
|
|
123
|
+
return results.flatMap(
|
|
124
|
+
(result) => result.status === "rejected" ? [result.reason] : writeFailures.get(result.value.name) ?? []
|
|
125
|
+
);
|
|
69
126
|
}
|
|
70
127
|
|
|
71
128
|
exports.generateRedoclyApis = generateRedoclyApis;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redocly-apis.cjs","sources":["../../src/cli/redocly-apis.ts"],"sourcesContent":["import { kebabCase } from \"scule\";\nimport type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport type { OutputFixName } from \"../domain/output-fixes.js\";\nimport type { GeneratorOptions } from \"../types.js\";\nimport {\n type ApiSettings,\n apiRefLimitOptions,\n FIX_SETTING,\n OUTPUT_SETTING,\n unknownSettingWarnings,\n} from \"./api-settings.js\";\nimport { GENERATOR_FLAGS, type GeneratorFlags } from \"./cli-arguments.js\";\nimport { cliError } from \"./cli-errors.js\";\nimport { type CliRun, emitOutput, resolveLocationUrl } from \"./cli-output.js\";\nimport { MULTIPLE_SCHEMAS_DOCS_URL } from \"./docs-links.js\";\nimport { fixNamesOf, fixOption } from \"./fix-option.js\";\nimport { refLimitOptions } from \"./ref-limits.js\";\n\n/** The `apis` of a Redocly config: each API is generated into its `x-openapi-ts.output`. */\n\n/** The key of an API's openapi-typesafe settings in `redocly.yaml`. */\nconst REDOCLY_CONFIG_KEY = \"x-openapi-ts\";\n\ninterface RedoclyApi {\n readonly name: string;\n readonly root: string;\n readonly settings: ApiSettings | undefined;\n}\n\nfunction redoclyApisOf(redocly: RedoclyConfig): RedoclyApi[] {\n return Object.entries(redocly.apis ?? {}).map(([name, api]) => {\n const settings = (api as Record<string, unknown>)[REDOCLY_CONFIG_KEY];\n return { name, root: api.root, settings: settings as ApiSettings | undefined };\n });\n}\n\nexport function hasRedoclyApis(redocly: RedoclyConfig): boolean {\n return Object.keys(redocly.apis ?? {}).length > 0;\n}\n\n/** The boolean flags an API sets, in camelCase or kebab-case; they win over the CLI's flags. */\nfunction apiFlags(settings: ApiSettings): GeneratorFlags {\n const flags: Partial<Record<(typeof GENERATOR_FLAGS)[number], boolean>> = {};\n for (const name of GENERATOR_FLAGS) {\n const value = typeof settings[name] === \"boolean\" ? settings[name] : settings[kebabCase(name)];\n if (typeof value === \"boolean\") {\n flags[name] = value;\n }\n }\n return flags;\n}\n\n/** The API's `fix` names; they replace the CLI's `--fix`, as its boolean settings win (ADR-021). */\nfunction apiFixNames(settings: ApiSettings): readonly OutputFixName[] | undefined {\n return fixNamesOf(settings[FIX_SETTING]);\n}\n\n/** Paths in the config are relative to the config file; without a file, to the working dir. */\nfunction configRootOf(redocly: RedoclyConfig, cwd: URL): URL {\n return redocly.configFile ? resolveLocationUrl(redocly.configFile, cwd) : cwd;\n}\n\nasync function generateApi(run: CliRun, redocly: RedoclyConfig, api: RedoclyApi): Promise<void> {\n if (!api.settings?.[OUTPUT_SETTING]) {\n throw cliError(\n \"CLI_CONFIG_OUTPUT_MISSING\",\n `API ${api.name} is missing an \\`${REDOCLY_CONFIG_KEY}.output\\` key. ` +\n `See ${MULTIPLE_SCHEMAS_DOCS_URL}`,\n );\n }\n for (const warning of unknownSettingWarnings(api.name, api.settings)) {\n run.deps.logger.warn(warning);\n }\n const output = String(api.settings[OUTPUT_SETTING]);\n const configRoot = configRootOf(redocly, run.deps.cwd);\n const options: GeneratorOptions = {\n ...run.args.generatorFlags,\n ...apiFlags(api.settings),\n ...refLimitOptions(run.args, run.deps.cwd),\n ...apiRefLimitOptions(api.name, api.settings, configRoot),\n ...fixOption(apiFixNames(api.settings) ?? run.args.fix),\n redocly,\n };\n const contents = await run.deps.generate(resolveLocationUrl(api.root, configRoot), options);\n emitOutput(\n run,\n { source: api.name, output, file: resolveLocationUrl(output, configRoot) },\n contents,\n );\n}\n\n/**\n * Generate every API of the config, concurrently. Every API is generated or checked even when\n * another fails, so `--check` reports a stale output wherever it is; the failures are returned\n * in the order of the config.\n */\nexport async function generateRedoclyApis(run: CliRun, redocly: RedoclyConfig): Promise<unknown[]> {\n const apis = redoclyApisOf(redocly);\n const results = await Promise.allSettled(apis.map((api) => generateApi(run, redocly, api)));\n return results.flatMap((result) => (result.status === \"rejected\" ? [result.reason] : []));\n}\n"],"names":["GENERATOR_FLAGS","kebabCase","fixNamesOf","FIX_SETTING","resolveLocationUrl","OUTPUT_SETTING","cliError","MULTIPLE_SCHEMAS_DOCS_URL","unknownSettingWarnings","refLimitOptions","apiRefLimitOptions","fixOption","emitOutput"],"mappings":";;;;;;;;;;;AAqBA,MAAM,kBAAA,GAAqB,cAAA;AAQ3B,SAAS,cAAc,OAAA,EAAsC;AAC3D,EAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,OAAA,CAAQ,IAAA,IAAQ,EAAE,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,IAAA,EAAM,GAAG,CAAA,KAAM;AAC7D,IAAA,MAAM,QAAA,GAAY,IAAgC,kBAAkB,CAAA;AACpE,IAAA,OAAO,EAAE,IAAA,EAAM,IAAA,EAAM,GAAA,CAAI,MAAM,QAAA,EAA8C;AAAA,EAC/E,CAAC,CAAA;AACH;AAEO,SAAS,eAAe,OAAA,EAAiC;AAC9D,EAAA,OAAO,OAAO,IAAA,CAAK,OAAA,CAAQ,QAAQ,EAAE,EAAE,MAAA,GAAS,CAAA;AAClD;AAGA,SAAS,SAAS,QAAA,EAAuC;AACvD,EAAA,MAAM,QAAoE,EAAC;AAC3E,EAAA,KAAA,MAAW,QAAQA,4BAAA,EAAiB;AAClC,IAAA,MAAM,KAAA,GAAQ,OAAO,QAAA,CAAS,IAAI,CAAA,KAAM,SAAA,GAAY,QAAA,CAAS,IAAI,CAAA,GAAI,QAAA,CAASC,eAAA,CAAU,IAAI,CAAC,CAAA;AAC7F,IAAA,IAAI,OAAO,UAAU,SAAA,EAAW;AAC9B,MAAA,KAAA,CAAM,IAAI,CAAA,GAAI,KAAA;AAAA,IAChB;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT;AAGA,SAAS,YAAY,QAAA,EAA6D;AAChF,EAAA,OAAOC,oBAAA,CAAW,QAAA,CAASC,uBAAW,CAAC,CAAA;AACzC;AAGA,SA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QAAA,GAAW,MAAM,GAAA,CAAI,IAAA,CAAK,QAAA,CAASP,6BAAmB,GAAA,CAAI,IAAA,EAAM,UAAU,CAAA,EAAG,OAAO,CAAA;AAC1F,EAAAQ,oBAAA;AAAA,IACE,GAAA;AAAA,IACA,EAAE,QAAQ,GAAA,CAAI,IAAA,EAAM,QAAQ,IAAA,EAAMR,4BAAA,CAAmB,MAAA,EAAQ,UAAU,CAAA,EAAE;AAAA,IACzE;AAAA,GACF;AACF;AAOA,eAAsB,mBAAA,CAAoB,KAAa,OAAA,EAA4C;AACjG,EAAA,MAAM,IAAA,GAAO,cAAc,OAAO,CAAA;AAClC,EAAA,MAAM,OAAA,GAAU,MAAM,OAAA,CAAQ,UAAA,CAAW,IAAA,CAAK,GAAA,CAAI,CAAC,GAAA,KAAQ,WAAA,CAAY,GAAA,EAAK,OAAA,EAAS,GAAG,CAAC,CAAC,CAAA;AAC1F,EAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,CAAC,MAAA,KAAY,MAAA,CAAO,MAAA,KAAW,UAAA,GAAa,CAAC,MAAA,CAAO,MAAM,CAAA,GAAI,EAAG,CAAA;AAC1F;;;"}
|
|
1
|
+
{"version":3,"file":"redocly-apis.cjs","sources":["../../src/cli/redocly-apis.ts"],"sourcesContent":["import type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport type { GeneratorOptions } from \"../types.js\";\nimport {\n type ApiSettings,\n apiFixNames,\n apiFlags,\n apiOutputOf,\n apiRefLimitOptions,\n OUTPUT_SETTING,\n unknownSettingWarnings,\n} from \"./api-settings.js\";\nimport { type GeneratedApi, writeGeneratedApis } from \"./api-writes.js\";\nimport { ineffectiveFlagNotices } from \"./cli-arguments.js\";\nimport { ApiFailure, cliError } from \"./cli-errors.js\";\nimport {\n type CliRun,\n ensureOutputIsNotSchema,\n ensureOutputIsOwn,\n filesReadBy,\n type NamedFile,\n outputFileOf,\n parseLocationUrl,\n redoclyConfigFiles,\n resolveLocationUrl,\n} from \"./cli-output.js\";\nimport { MULTIPLE_SCHEMAS_DOCS_URL } from \"./docs-links.js\";\nimport { fixOption } from \"./fix-option.js\";\nimport { type RefLimitOptions, refLimitOptions } from \"./ref-limits.js\";\n\n/** The `apis` of a Redocly config: each API is generated into its `x-openapi-ts.output`. */\n\n/** The key of an API's openapi-typesafe settings in `redocly.yaml`. */\nconst REDOCLY_CONFIG_KEY = \"x-openapi-ts\";\n\n/** An API of the config as written: `root` and the settings are not checked yet. */\ninterface RedoclyApi {\n readonly name: string;\n readonly root: unknown;\n readonly settings: unknown;\n}\n\nfunction redoclyApisOf(redocly: RedoclyConfig): RedoclyApi[] {\n return Object.entries(redocly.apis ?? {}).map(([name, api]) => {\n const fields = api as Readonly<Record<string, unknown>>;\n return { name, root: fields.root, settings: fields[REDOCLY_CONFIG_KEY] };\n });\n}\n\nexport function hasRedoclyApis(redocly: RedoclyConfig): boolean {\n return Object.keys(redocly.apis ?? {}).length > 0;\n}\n\n/** Paths in the config are relative to the config file; without a file, to the working dir. */\nfunction configRootOf(redocly: RedoclyConfig, cwd: URL): URL {\n return redocly.configFile ? resolveLocationUrl(redocly.configFile, cwd) : cwd;\n}\n\n/** An API whose root and settings are usable, and the directory its paths are relative to. */\ninterface ApiTarget {\n readonly name: string;\n readonly root: string;\n readonly settings: ApiSettings;\n readonly configRoot: URL;\n}\n\nfunction isSettingsMap(value: unknown): value is ApiSettings {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * The API with its settings. Fails with `CLI_CONFIG_OUTPUT_MISSING` when they name no output, and\n * with `CLI_CONFIG_INVALID` when they are no map or `root` is no path or URL; only this API then\n * fails, the others are still generated.\n */\nfunction apiTarget(api: RedoclyApi, configRoot: URL): ApiTarget {\n const { name, root, settings } = api;\n if (settings !== undefined && !isSettingsMap(settings)) {\n throw cliError(\"CLI_CONFIG_INVALID\", `API ${name}: \\`${REDOCLY_CONFIG_KEY}\\` must be a map`);\n }\n if (!settings?.[OUTPUT_SETTING]) {\n throw cliError(\n \"CLI_CONFIG_OUTPUT_MISSING\",\n `API ${name} is missing an \\`${REDOCLY_CONFIG_KEY}.output\\` key. ` +\n `See ${MULTIPLE_SCHEMAS_DOCS_URL}`,\n );\n }\n if (typeof root !== \"string\" || root === \"\") {\n throw cliError(\n \"CLI_CONFIG_INVALID\",\n `API ${name}: \\`root\\` in redocly.yaml must be the path or URL of its schema`,\n );\n }\n return { name, root, settings, configRoot };\n}\n\n/**\n * What every API of a run shares: the config, the files of all APIs, and the reference limits of\n * the command line, which are checked once before any API, so an invalid flag fails the run once.\n */\ninterface ApiRun {\n readonly redocly: RedoclyConfig;\n readonly files: ConfigFiles;\n readonly refLimits: RefLimitOptions;\n}\n\n/**\n * The generator options of one API: its own settings win over the CLI's flags. A flag that has\n * no effect with the merged flags is named for this API, since its settings may turn on the flag\n * that the command line lacks, or set one that has no effect themselves.\n */\nfunction apiOptions(run: CliRun, apiRun: ApiRun, target: ApiTarget): GeneratorOptions {\n const { name, settings, configRoot } = target;\n const flags = { ...run.args.generatorFlags, ...apiFlags(name, settings) };\n for (const notice of ineffectiveFlagNotices(flags)) {\n run.deps.console.notice(`API ${name}: ${notice}`);\n }\n return {\n ...flags,\n ...apiRun.refLimits,\n ...apiRefLimitOptions(name, settings, configRoot),\n ...fixOption(apiFixNames(name, settings) ?? run.args.fix),\n redocly: apiRun.redocly,\n };\n}\n\n/** The schemas and outputs of every API of the config, keyed by API name for the outputs. */\ninterface ConfigFiles {\n readonly schemas: readonly NamedFile[];\n readonly outputs: ReadonlyMap<string, URL>;\n}\n\n/** The outputs of the other APIs, as `ensureOutputIsOwn` names them. */\nfunction otherOutputs(files: ConfigFiles, apiName: string): NamedFile[] {\n return [...files.outputs]\n .filter(([name]) => name !== apiName)\n .map(([name, location]) => ({ name: `API ${name}`, location }));\n}\n\n/**\n * Generate the types of one API. Its output must not be a file the run reads before any API is\n * loaded (the root of any API, the Redocly config) nor another API's output.\n */\nasync function generateApi(run: CliRun, apiRun: ApiRun, target: ApiTarget): Promise<GeneratedApi> {\n const { files } = apiRun;\n for (const warning of unknownSettingWarnings(target.name, target.settings)) {\n run.deps.logger.warn(warning);\n }\n const output = apiOutputOf(target.name, target.settings);\n const outputFile = outputFileOf(run, { source: target.name, output }, target.configRoot);\n ensureOutputIsNotSchema(run, outputFile, files.schemas);\n ensureOutputIsOwn(run, outputFile, otherOutputs(files, target.name));\n const source = resolveLocationUrl(target.root, target.configRoot);\n const options = apiOptions(run, apiRun, target);\n try {\n const types = await run.deps.generate(source, options, target.name);\n return { name: target.name, outputFile, types };\n } catch (error) {\n throw new ApiFailure(target.name, error);\n }\n}\n\n/**\n * The schema and the output of every API, and the config file itself. A location that is no\n * text or no valid URL is left out: it is no file that an output could be, and its own API fails\n * on it, not every API.\n */\nfunction configFilesOf(run: CliRun, redocly: RedoclyConfig, apis: readonly RedoclyApi[]) {\n const configRoot = configRootOf(redocly, run.deps.cwd);\n const roots = apis.flatMap(({ name, root }) => {\n const location = typeof root === \"string\" ? parseLocationUrl(root, configRoot) : undefined;\n return location ? [{ name: `schema ${root} of API ${name}`, location }] : [];\n });\n const outputs = new Map<string, URL>();\n for (const api of apis) {\n const output = isSettingsMap(api.settings) ? api.settings[OUTPUT_SETTING] : undefined;\n const location = typeof output === \"string\" ? parseLocationUrl(output, configRoot) : undefined;\n if (location) {\n outputs.set(api.name, location);\n }\n }\n const schemas = [...roots, ...redoclyConfigFiles(run, redocly)];\n return { configRoot, files: { schemas, outputs } satisfies ConfigFiles };\n}\n\n/** What `task` gives for each item, run one after another: the next starts when one settles. */\nasync function settledInTurn<T, R>(\n items: readonly T[],\n task: (item: T) => Promise<R>,\n): Promise<PromiseSettledResult<R>[]> {\n const results: PromiseSettledResult<R>[] = [];\n for (const item of items) {\n try {\n results.push({ status: \"fulfilled\", value: await task(item) });\n } catch (reason) {\n results.push({ status: \"rejected\", reason });\n }\n }\n return results;\n}\n\n/**\n * Generate every API of the config, one after another in the order of the config, then write\n * them. One at a time, so a run takes the memory of its largest API, not the sum of all of them,\n * and the work of one API cannot hold up the fetches of another until their timeout ends them.\n * Nothing is written until every API is read and every output is claimed, so no output can\n * replace a file that another API still reads; an output that is a file any API read (a `$ref`'d\n * schema) fails with `CLI_OUTPUT_IS_INPUT`. Every API is generated or checked even when another\n * fails, so `--check` reports a stale output wherever it is; the failures are returned in the\n * order of the config.\n */\nexport async function generateRedoclyApis(run: CliRun, redocly: RedoclyConfig): Promise<unknown[]> {\n const apis = redoclyApisOf(redocly);\n const { configRoot, files } = configFilesOf(run, redocly, apis);\n const apiRun = { redocly, files, refLimits: refLimitOptions(run.args, run.deps.cwd) };\n const results = await settledInTurn(apis, (api) =>\n generateApi(run, apiRun, apiTarget(api, configRoot)),\n );\n const generated = results.flatMap((result) =>\n result.status === \"fulfilled\" ? [result.value] : [],\n );\n const readFiles = generated.flatMap(({ name, types }) => filesReadBy(run, types, `API ${name}`));\n const writeFailures = writeGeneratedApis(run, generated, readFiles);\n return results.flatMap((result) =>\n result.status === \"rejected\" ? [result.reason] : (writeFailures.get(result.value.name) ?? []),\n );\n}\n"],"names":["resolveLocationUrl","cliError","OUTPUT_SETTING","MULTIPLE_SCHEMAS_DOCS_URL","apiFlags","ineffectiveFlagNotices","apiRefLimitOptions","fixOption","apiFixNames","unknownSettingWarnings","apiOutputOf","outputFileOf","ensureOutputIsNotSchema","ensureOutputIsOwn","ApiFailure","parseLocationUrl","redoclyConfigFiles","refLimitOptions","filesReadBy","writeGeneratedApis"],"mappings":";;;;;;;;;;;AAgCA,MAAM,kBAAA,GAAqB,cAAA;AAS3B,SAAS,cAAc,OAAA,EAAsC;AAC3D,EAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,OAAA,CAAQ,IAAA,IAAQ,EAAE,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,IAAA,EAAM,GAAG,CAAA,KAAM;AAC7D,IAAA,MAAM,MAAA,GAAS,GAAA;AACf,IAAA,OAAO,EAAE,MAAM,IAAA,EAAM,MAAA,CAAO,M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