openapi-typesafe 0.0.0 → 1.0.0-rc.0
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/LICENSE +22 -0
- package/README.md +71 -1
- package/bin/cli.js +4 -0
- package/dist/adapters/node-file-system/node-file-system.cjs +46 -0
- package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -0
- package/dist/adapters/node-file-system/node-file-system.mjs +40 -0
- package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -0
- package/dist/adapters/redocly-loader/alias-limit.cjs +16 -0
- package/dist/adapters/redocly-loader/alias-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/alias-limit.mjs +14 -0
- package/dist/adapters/redocly-loader/alias-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/allowed-hosts.cjs +42 -0
- package/dist/adapters/redocly-loader/allowed-hosts.cjs.map +1 -0
- package/dist/adapters/redocly-loader/allowed-hosts.mjs +40 -0
- package/dist/adapters/redocly-loader/allowed-hosts.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs +53 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs +51 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs.map +1 -0
- package/dist/adapters/redocly-loader/malformed-refs.cjs +41 -0
- package/dist/adapters/redocly-loader/malformed-refs.cjs.map +1 -0
- package/dist/adapters/redocly-loader/malformed-refs.mjs +38 -0
- package/dist/adapters/redocly-loader/malformed-refs.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-config-source.cjs +42 -0
- package/dist/adapters/redocly-loader/redocly-config-source.cjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-config-source.mjs +35 -0
- package/dist/adapters/redocly-loader/redocly-config-source.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +169 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +167 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -0
- package/dist/adapters/redocly-loader/ref-access.cjs +107 -0
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -0
- package/dist/adapters/redocly-loader/ref-access.mjs +99 -0
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -0
- package/dist/adapters/redocly-loader/ref-holders.cjs +31 -0
- package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -0
- package/dist/adapters/redocly-loader/ref-holders.mjs +29 -0
- package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-fetch.cjs +60 -0
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-fetch.mjs +56 -0
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-load-errors.cjs +87 -0
- package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-load-errors.mjs +77 -0
- package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-source.cjs +104 -0
- package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-source.mjs +98 -0
- package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -0
- package/dist/adapters/redocly-loader/unsupported-keys.cjs +62 -0
- package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -0
- package/dist/adapters/redocly-loader/unsupported-keys.mjs +58 -0
- package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -0
- package/dist/adapters/terminal-logger/terminal-logger.cjs +67 -0
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -0
- package/dist/adapters/terminal-logger/terminal-logger.mjs +59 -0
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/footer-nodes.cjs +21 -0
- package/dist/adapters/type-ast-bridge/footer-nodes.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/footer-nodes.mjs +17 -0
- package/dist/adapters/type-ast-bridge/footer-nodes.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/ir-declarations-to-typescript.cjs +75 -0
- package/dist/adapters/type-ast-bridge/ir-declarations-to-typescript.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/ir-declarations-to-typescript.mjs +71 -0
- package/dist/adapters/type-ast-bridge/ir-declarations-to-typescript.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs +145 -0
- package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs +139 -0
- package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/lazy-node.cjs +23 -0
- package/dist/adapters/type-ast-bridge/lazy-node.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/lazy-node.mjs +21 -0
- package/dist/adapters/type-ast-bridge/lazy-node.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/load-typescript.cjs +57 -0
- package/dist/adapters/type-ast-bridge/load-typescript.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/load-typescript.mjs +51 -0
- package/dist/adapters/type-ast-bridge/load-typescript.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/print-typescript.cjs +21 -0
- package/dist/adapters/type-ast-bridge/print-typescript.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/print-typescript.mjs +19 -0
- package/dist/adapters/type-ast-bridge/print-typescript.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/typescript-raw-text.cjs +33 -0
- package/dist/adapters/type-ast-bridge/typescript-raw-text.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/typescript-raw-text.mjs +29 -0
- package/dist/adapters/type-ast-bridge/typescript-raw-text.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs +204 -0
- package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs +201 -0
- package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs.map +1 -0
- package/dist/api/ast-to-string.cjs +39 -0
- package/dist/api/ast-to-string.cjs.map +1 -0
- package/dist/api/ast-to-string.mjs +37 -0
- package/dist/api/ast-to-string.mjs.map +1 -0
- package/dist/api/comment-header.cjs +11 -0
- package/dist/api/comment-header.cjs.map +1 -0
- package/dist/api/comment-header.mjs +9 -0
- package/dist/api/comment-header.mjs.map +1 -0
- package/dist/api/default-ports.cjs +38 -0
- package/dist/api/default-ports.cjs.map +1 -0
- package/dist/api/default-ports.mjs +28 -0
- package/dist/api/default-ports.mjs.map +1 -0
- package/dist/api/discriminator-enum.cjs +44 -0
- package/dist/api/discriminator-enum.cjs.map +1 -0
- package/dist/api/discriminator-enum.mjs +42 -0
- package/dist/api/discriminator-enum.mjs.map +1 -0
- package/dist/api/discriminator-scan.cjs +168 -0
- package/dist/api/discriminator-scan.cjs.map +1 -0
- package/dist/api/discriminator-scan.mjs +165 -0
- package/dist/api/discriminator-scan.mjs.map +1 -0
- package/dist/api/document-declarations.cjs +28 -0
- package/dist/api/document-declarations.cjs.map +1 -0
- package/dist/api/document-declarations.mjs +26 -0
- package/dist/api/document-declarations.mjs.map +1 -0
- package/dist/api/document-refs.cjs +53 -0
- package/dist/api/document-refs.cjs.map +1 -0
- package/dist/api/document-refs.mjs +50 -0
- package/dist/api/document-refs.mjs.map +1 -0
- package/dist/api/document-run.cjs +107 -0
- package/dist/api/document-run.cjs.map +1 -0
- package/dist/api/document-run.mjs +101 -0
- package/dist/api/document-run.mjs.map +1 -0
- package/dist/api/footer-entry.cjs +18 -0
- package/dist/api/footer-entry.cjs.map +1 -0
- package/dist/api/footer-entry.mjs +15 -0
- package/dist/api/footer-entry.mjs.map +1 -0
- package/dist/api/footer-sink.cjs +53 -0
- package/dist/api/footer-sink.cjs.map +1 -0
- package/dist/api/footer-sink.mjs +51 -0
- package/dist/api/footer-sink.mjs.map +1 -0
- package/dist/api/legacy-callback-warning.cjs +25 -0
- package/dist/api/legacy-callback-warning.cjs.map +1 -0
- package/dist/api/legacy-callback-warning.mjs +22 -0
- package/dist/api/legacy-callback-warning.mjs.map +1 -0
- package/dist/api/legacy-ts-helpers.cjs +203 -0
- package/dist/api/legacy-ts-helpers.cjs.map +1 -0
- package/dist/api/legacy-ts-helpers.mjs +187 -0
- package/dist/api/legacy-ts-helpers.mjs.map +1 -0
- package/dist/api/legacy-utils.cjs +65 -0
- package/dist/api/legacy-utils.cjs.map +1 -0
- package/dist/api/legacy-utils.mjs +50 -0
- package/dist/api/legacy-utils.mjs.map +1 -0
- package/dist/api/openapi-ts.cjs +40 -0
- package/dist/api/openapi-ts.cjs.map +1 -0
- package/dist/api/openapi-ts.mjs +34 -0
- package/dist/api/openapi-ts.mjs.map +1 -0
- package/dist/api/schema-callbacks.cjs +140 -0
- package/dist/api/schema-callbacks.cjs.map +1 -0
- package/dist/api/schema-callbacks.mjs +136 -0
- package/dist/api/schema-callbacks.mjs.map +1 -0
- package/dist/api/string-to-ast.cjs +21 -0
- package/dist/api/string-to-ast.cjs.map +1 -0
- package/dist/api/string-to-ast.mjs +18 -0
- package/dist/api/string-to-ast.mjs.map +1 -0
- package/dist/api/transform-context.cjs +82 -0
- package/dist/api/transform-context.cjs.map +1 -0
- package/dist/api/transform-context.mjs +65 -0
- package/dist/api/transform-context.mjs.map +1 -0
- package/dist/api/transform-schema.cjs +31 -0
- package/dist/api/transform-schema.cjs.map +1 -0
- package/dist/api/transform-schema.mjs +26 -0
- package/dist/api/transform-schema.mjs.map +1 -0
- package/dist/api/type-helpers.cjs +85 -0
- package/dist/api/type-helpers.cjs.map +1 -0
- package/dist/api/type-helpers.mjs +66 -0
- package/dist/api/type-helpers.mjs.map +1 -0
- package/dist/api/unsupported-feature-warnings.cjs +17 -0
- package/dist/api/unsupported-feature-warnings.cjs.map +1 -0
- package/dist/api/unsupported-feature-warnings.mjs +15 -0
- package/dist/api/unsupported-feature-warnings.mjs.map +1 -0
- package/dist/application/print/comment-writer.cjs +95 -0
- package/dist/application/print/comment-writer.cjs.map +1 -0
- package/dist/application/print/comment-writer.mjs +93 -0
- package/dist/application/print/comment-writer.mjs.map +1 -0
- package/dist/application/print/declaration-printer.cjs +83 -0
- package/dist/application/print/declaration-printer.cjs.map +1 -0
- package/dist/application/print/declaration-printer.mjs +81 -0
- package/dist/application/print/declaration-printer.mjs.map +1 -0
- package/dist/application/print/literal-text.cjs +52 -0
- package/dist/application/print/literal-text.cjs.map +1 -0
- package/dist/application/print/literal-text.mjs +48 -0
- package/dist/application/print/literal-text.mjs.map +1 -0
- package/dist/application/print/print-nodes.cjs +38 -0
- package/dist/application/print/print-nodes.cjs.map +1 -0
- package/dist/application/print/print-nodes.mjs +36 -0
- package/dist/application/print/print-nodes.mjs.map +1 -0
- package/dist/application/print/print-options.cjs +6 -0
- package/dist/application/print/print-options.cjs.map +1 -0
- package/dist/application/print/print-options.mjs +4 -0
- package/dist/application/print/print-options.mjs.map +1 -0
- package/dist/application/print/text-writer.cjs +63 -0
- package/dist/application/print/text-writer.cjs.map +1 -0
- package/dist/application/print/text-writer.mjs +60 -0
- package/dist/application/print/text-writer.mjs.map +1 -0
- package/dist/application/print/type-printer.cjs +214 -0
- package/dist/application/print/type-printer.cjs.map +1 -0
- package/dist/application/print/type-printer.mjs +210 -0
- package/dist/application/print/type-printer.mjs.map +1 -0
- package/dist/application/stack-overflow.cjs +36 -0
- package/dist/application/stack-overflow.cjs.map +1 -0
- package/dist/application/stack-overflow.mjs +31 -0
- package/dist/application/stack-overflow.mjs.map +1 -0
- package/dist/application/transform/document/components.cjs +104 -0
- package/dist/application/transform/document/components.cjs.map +1 -0
- package/dist/application/transform/document/components.mjs +102 -0
- package/dist/application/transform/document/components.mjs.map +1 -0
- package/dist/application/transform/document/defs-root.cjs +18 -0
- package/dist/application/transform/document/defs-root.cjs.map +1 -0
- package/dist/application/transform/document/defs-root.mjs +16 -0
- package/dist/application/transform/document/defs-root.mjs.map +1 -0
- package/dist/application/transform/document/document-member.cjs +13 -0
- package/dist/application/transform/document/document-member.cjs.map +1 -0
- package/dist/application/transform/document/document-member.mjs +11 -0
- package/dist/application/transform/document/document-member.mjs.map +1 -0
- package/dist/application/transform/document/document.cjs +86 -0
- package/dist/application/transform/document/document.cjs.map +1 -0
- package/dist/application/transform/document/document.mjs +83 -0
- package/dist/application/transform/document/document.mjs.map +1 -0
- package/dist/application/transform/document/header.cjs +27 -0
- package/dist/application/transform/document/header.cjs.map +1 -0
- package/dist/application/transform/document/header.mjs +25 -0
- package/dist/application/transform/document/header.mjs.map +1 -0
- package/dist/application/transform/document/kept-deprecated.cjs +96 -0
- package/dist/application/transform/document/kept-deprecated.cjs.map +1 -0
- package/dist/application/transform/document/kept-deprecated.mjs +94 -0
- package/dist/application/transform/document/kept-deprecated.mjs.map +1 -0
- package/dist/application/transform/document/media-type.cjs +42 -0
- package/dist/application/transform/document/media-type.cjs.map +1 -0
- package/dist/application/transform/document/media-type.mjs +38 -0
- package/dist/application/transform/document/media-type.mjs.map +1 -0
- package/dist/application/transform/document/operation.cjs +45 -0
- package/dist/application/transform/document/operation.cjs.map +1 -0
- package/dist/application/transform/document/operation.mjs +43 -0
- package/dist/application/transform/document/operation.mjs.map +1 -0
- package/dist/application/transform/document/parameter.cjs +25 -0
- package/dist/application/transform/document/parameter.cjs.map +1 -0
- package/dist/application/transform/document/parameter.mjs +23 -0
- package/dist/application/transform/document/parameter.mjs.map +1 -0
- package/dist/application/transform/document/parameters.cjs +114 -0
- package/dist/application/transform/document/parameters.cjs.map +1 -0
- package/dist/application/transform/document/parameters.mjs +112 -0
- package/dist/application/transform/document/parameters.mjs.map +1 -0
- package/dist/application/transform/document/path-item-conflicts.cjs +51 -0
- package/dist/application/transform/document/path-item-conflicts.cjs.map +1 -0
- package/dist/application/transform/document/path-item-conflicts.mjs +49 -0
- package/dist/application/transform/document/path-item-conflicts.mjs.map +1 -0
- package/dist/application/transform/document/path-item.cjs +82 -0
- package/dist/application/transform/document/path-item.cjs.map +1 -0
- package/dist/application/transform/document/path-item.mjs +80 -0
- package/dist/application/transform/document/path-item.mjs.map +1 -0
- package/dist/application/transform/document/path-key-overlaps.cjs +57 -0
- package/dist/application/transform/document/path-key-overlaps.cjs.map +1 -0
- package/dist/application/transform/document/path-key-overlaps.mjs +55 -0
- package/dist/application/transform/document/path-key-overlaps.mjs.map +1 -0
- package/dist/application/transform/document/paths-enum.cjs +75 -0
- package/dist/application/transform/document/paths-enum.cjs.map +1 -0
- package/dist/application/transform/document/paths-enum.mjs +72 -0
- package/dist/application/transform/document/paths-enum.mjs.map +1 -0
- package/dist/application/transform/document/paths.cjs +127 -0
- package/dist/application/transform/document/paths.cjs.map +1 -0
- package/dist/application/transform/document/paths.mjs +125 -0
- package/dist/application/transform/document/paths.mjs.map +1 -0
- package/dist/application/transform/document/request-body.cjs +36 -0
- package/dist/application/transform/document/request-body.cjs.map +1 -0
- package/dist/application/transform/document/request-body.mjs +34 -0
- package/dist/application/transform/document/request-body.mjs.map +1 -0
- package/dist/application/transform/document/response.cjs +59 -0
- package/dist/application/transform/document/response.cjs.map +1 -0
- package/dist/application/transform/document/response.mjs +57 -0
- package/dist/application/transform/document/response.mjs.map +1 -0
- package/dist/application/transform/document/responses.cjs +23 -0
- package/dist/application/transform/document/responses.cjs.map +1 -0
- package/dist/application/transform/document/responses.mjs +21 -0
- package/dist/application/transform/document/responses.mjs.map +1 -0
- package/dist/application/transform/document/root-type-aliases.cjs +69 -0
- package/dist/application/transform/document/root-type-aliases.cjs.map +1 -0
- package/dist/application/transform/document/root-type-aliases.mjs +65 -0
- package/dist/application/transform/document/root-type-aliases.mjs.map +1 -0
- package/dist/application/transform/document/webhooks.cjs +19 -0
- package/dist/application/transform/document/webhooks.cjs.map +1 -0
- package/dist/application/transform/document/webhooks.mjs +17 -0
- package/dist/application/transform/document/webhooks.mjs.map +1 -0
- package/dist/application/transform/document-entries.cjs +17 -0
- package/dist/application/transform/document-entries.cjs.map +1 -0
- package/dist/application/transform/document-entries.mjs +14 -0
- package/dist/application/transform/document-entries.mjs.map +1 -0
- package/dist/application/transform/footer/document-footer.cjs +88 -0
- package/dist/application/transform/footer/document-footer.cjs.map +1 -0
- package/dist/application/transform/footer/document-footer.mjs +86 -0
- package/dist/application/transform/footer/document-footer.mjs.map +1 -0
- package/dist/application/transform/footer/enum-naming.cjs +121 -0
- package/dist/application/transform/footer/enum-naming.cjs.map +1 -0
- package/dist/application/transform/footer/enum-naming.mjs +115 -0
- package/dist/application/transform/footer/enum-naming.mjs.map +1 -0
- package/dist/application/transform/helper-types.cjs +68 -0
- package/dist/application/transform/helper-types.cjs.map +1 -0
- package/dist/application/transform/helper-types.mjs +65 -0
- package/dist/application/transform/helper-types.mjs.map +1 -0
- package/dist/application/transform/literal-type.cjs +36 -0
- package/dist/application/transform/literal-type.cjs.map +1 -0
- package/dist/application/transform/literal-type.mjs +34 -0
- package/dist/application/transform/literal-type.mjs.map +1 -0
- package/dist/application/transform/numbered-names.cjs +18 -0
- package/dist/application/transform/numbered-names.cjs.map +1 -0
- package/dist/application/transform/numbered-names.mjs +16 -0
- package/dist/application/transform/numbered-names.mjs.map +1 -0
- package/dist/application/transform/ref-type.cjs +57 -0
- package/dist/application/transform/ref-type.cjs.map +1 -0
- package/dist/application/transform/ref-type.mjs +54 -0
- package/dist/application/transform/ref-type.mjs.map +1 -0
- package/dist/application/transform/schema/array-type.cjs +105 -0
- package/dist/application/transform/schema/array-type.cjs.map +1 -0
- package/dist/application/transform/schema/array-type.mjs +103 -0
- package/dist/application/transform/schema/array-type.mjs.map +1 -0
- package/dist/application/transform/schema/composition-type.cjs +107 -0
- package/dist/application/transform/schema/composition-type.cjs.map +1 -0
- package/dist/application/transform/schema/composition-type.mjs +105 -0
- package/dist/application/transform/schema/composition-type.mjs.map +1 -0
- package/dist/application/transform/schema/core-type.cjs +84 -0
- package/dist/application/transform/schema/core-type.cjs.map +1 -0
- package/dist/application/transform/schema/core-type.mjs +82 -0
- package/dist/application/transform/schema/core-type.mjs.map +1 -0
- package/dist/application/transform/schema/discriminator-property.cjs +21 -0
- package/dist/application/transform/schema/discriminator-property.cjs.map +1 -0
- package/dist/application/transform/schema/discriminator-property.mjs +19 -0
- package/dist/application/transform/schema/discriminator-property.mjs.map +1 -0
- package/dist/application/transform/schema/enum-rule.cjs +107 -0
- package/dist/application/transform/schema/enum-rule.cjs.map +1 -0
- package/dist/application/transform/schema/enum-rule.mjs +105 -0
- package/dist/application/transform/schema/enum-rule.mjs.map +1 -0
- package/dist/application/transform/schema/object-type.cjs +173 -0
- package/dist/application/transform/schema/object-type.cjs.map +1 -0
- package/dist/application/transform/schema/object-type.mjs +170 -0
- package/dist/application/transform/schema/object-type.mjs.map +1 -0
- package/dist/application/transform/schema/presence-members.cjs +59 -0
- package/dist/application/transform/schema/presence-members.cjs.map +1 -0
- package/dist/application/transform/schema/presence-members.mjs +57 -0
- package/dist/application/transform/schema/presence-members.mjs.map +1 -0
- package/dist/application/transform/schema/schema-transform.cjs +72 -0
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -0
- package/dist/application/transform/schema/schema-transform.mjs +68 -0
- package/dist/application/transform/schema/schema-transform.mjs.map +1 -0
- package/dist/application/transform/schema/unevaluated-properties.cjs +61 -0
- package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -0
- package/dist/application/transform/schema/unevaluated-properties.mjs +59 -0
- package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -0
- package/dist/application/transform/schema-comment.cjs +84 -0
- package/dist/application/transform/schema-comment.cjs.map +1 -0
- package/dist/application/transform/schema-comment.mjs +81 -0
- package/dist/application/transform/schema-comment.mjs.map +1 -0
- package/dist/application/transform/shared-types.cjs +8 -0
- package/dist/application/transform/shared-types.cjs.map +1 -0
- package/dist/application/transform/shared-types.mjs +6 -0
- package/dist/application/transform/shared-types.mjs.map +1 -0
- package/dist/application/transform/type-combinators.cjs +49 -0
- package/dist/application/transform/type-combinators.cjs.map +1 -0
- package/dist/application/transform/type-combinators.mjs +42 -0
- package/dist/application/transform/type-combinators.mjs.map +1 -0
- package/dist/cli/cli-arguments.cjs +137 -0
- package/dist/cli/cli-arguments.cjs.map +1 -0
- package/dist/cli/cli-arguments.mjs +129 -0
- package/dist/cli/cli-arguments.mjs.map +1 -0
- package/dist/cli/cli-errors.cjs +80 -0
- package/dist/cli/cli-errors.cjs.map +1 -0
- package/dist/cli/cli-errors.mjs +76 -0
- package/dist/cli/cli-errors.mjs.map +1 -0
- package/dist/cli/cli-output.cjs +37 -0
- package/dist/cli/cli-output.cjs.map +1 -0
- package/dist/cli/cli-output.mjs +30 -0
- package/dist/cli/cli-output.mjs.map +1 -0
- package/dist/cli/docs-links.cjs +6 -0
- package/dist/cli/docs-links.cjs.map +1 -0
- package/dist/cli/docs-links.mjs +4 -0
- package/dist/cli/docs-links.mjs.map +1 -0
- package/dist/cli/fix-option.cjs +19 -0
- package/dist/cli/fix-option.cjs.map +1 -0
- package/dist/cli/fix-option.mjs +16 -0
- package/dist/cli/fix-option.mjs.map +1 -0
- package/dist/cli/help-text.cjs +44 -0
- package/dist/cli/help-text.cjs.map +1 -0
- package/dist/cli/help-text.mjs +42 -0
- package/dist/cli/help-text.mjs.map +1 -0
- package/dist/cli/main.cjs +62 -0
- package/dist/cli/main.cjs.map +1 -0
- package/dist/cli/main.d.cts +2 -0
- package/dist/cli/main.d.mts +2 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.mjs +54 -0
- package/dist/cli/main.mjs.map +1 -0
- package/dist/cli/redocly-apis.cjs +65 -0
- package/dist/cli/redocly-apis.cjs.map +1 -0
- package/dist/cli/redocly-apis.mjs +62 -0
- package/dist/cli/redocly-apis.mjs.map +1 -0
- package/dist/cli/ref-limits.cjs +14 -0
- package/dist/cli/ref-limits.cjs.map +1 -0
- package/dist/cli/ref-limits.mjs +12 -0
- package/dist/cli/ref-limits.mjs.map +1 -0
- package/dist/cli/run-cli.cjs +100 -0
- package/dist/cli/run-cli.cjs.map +1 -0
- package/dist/cli/run-cli.mjs +98 -0
- package/dist/cli/run-cli.mjs.map +1 -0
- package/dist/domain/assert-never.cjs +8 -0
- package/dist/domain/assert-never.cjs.map +1 -0
- package/dist/domain/assert-never.mjs +6 -0
- package/dist/domain/assert-never.mjs.map +1 -0
- package/dist/domain/errors.cjs +50 -0
- package/dist/domain/errors.cjs.map +1 -0
- package/dist/domain/errors.mjs +46 -0
- package/dist/domain/errors.mjs.map +1 -0
- package/dist/domain/ir/constructors.cjs +89 -0
- package/dist/domain/ir/constructors.cjs.map +1 -0
- package/dist/domain/ir/constructors.mjs +71 -0
- package/dist/domain/ir/constructors.mjs.map +1 -0
- package/dist/domain/ir/identifier-text.cjs +29 -0
- package/dist/domain/ir/identifier-text.cjs.map +1 -0
- package/dist/domain/ir/identifier-text.mjs +25 -0
- package/dist/domain/ir/identifier-text.mjs.map +1 -0
- package/dist/domain/ir/newer-identifier-ranges.cjs +109 -0
- package/dist/domain/ir/newer-identifier-ranges.cjs.map +1 -0
- package/dist/domain/ir/newer-identifier-ranges.mjs +106 -0
- package/dist/domain/ir/newer-identifier-ranges.mjs.map +1 -0
- package/dist/domain/ir/normalize.cjs +32 -0
- package/dist/domain/ir/normalize.cjs.map +1 -0
- package/dist/domain/ir/normalize.mjs +29 -0
- package/dist/domain/ir/normalize.mjs.map +1 -0
- package/dist/domain/ir/property-name.cjs +19 -0
- package/dist/domain/ir/property-name.cjs.map +1 -0
- package/dist/domain/ir/property-name.mjs +16 -0
- package/dist/domain/ir/property-name.mjs.map +1 -0
- package/dist/domain/ir/raw-text-escapes.cjs +25 -0
- package/dist/domain/ir/raw-text-escapes.cjs.map +1 -0
- package/dist/domain/ir/raw-text-escapes.mjs +22 -0
- package/dist/domain/ir/raw-text-escapes.mjs.map +1 -0
- package/dist/domain/openapi/alias-expansion.cjs +50 -0
- package/dist/domain/openapi/alias-expansion.cjs.map +1 -0
- package/dist/domain/openapi/alias-expansion.mjs +45 -0
- package/dist/domain/openapi/alias-expansion.mjs.map +1 -0
- package/dist/domain/openapi/binary-content.cjs +48 -0
- package/dist/domain/openapi/binary-content.cjs.map +1 -0
- package/dist/domain/openapi/binary-content.mjs +45 -0
- package/dist/domain/openapi/binary-content.mjs.map +1 -0
- package/dist/domain/openapi/components-object.cjs +29 -0
- package/dist/domain/openapi/components-object.cjs.map +1 -0
- package/dist/domain/openapi/components-object.mjs +24 -0
- package/dist/domain/openapi/components-object.mjs.map +1 -0
- package/dist/domain/openapi/json-pointer.cjs +31 -0
- package/dist/domain/openapi/json-pointer.cjs.map +1 -0
- package/dist/domain/openapi/json-pointer.mjs +27 -0
- package/dist/domain/openapi/json-pointer.mjs.map +1 -0
- package/dist/domain/openapi/media-type-object.cjs +14 -0
- package/dist/domain/openapi/media-type-object.cjs.map +1 -0
- package/dist/domain/openapi/media-type-object.mjs +11 -0
- package/dist/domain/openapi/media-type-object.mjs.map +1 -0
- package/dist/domain/openapi/parameter-object.cjs +13 -0
- package/dist/domain/openapi/parameter-object.cjs.map +1 -0
- package/dist/domain/openapi/parameter-object.mjs +10 -0
- package/dist/domain/openapi/parameter-object.mjs.map +1 -0
- package/dist/domain/openapi/path-item-object.cjs +35 -0
- package/dist/domain/openapi/path-item-object.cjs.map +1 -0
- package/dist/domain/openapi/path-item-object.mjs +30 -0
- package/dist/domain/openapi/path-item-object.mjs.map +1 -0
- package/dist/domain/openapi/unsupported-features.cjs +87 -0
- package/dist/domain/openapi/unsupported-features.cjs.map +1 -0
- package/dist/domain/openapi/unsupported-features.mjs +84 -0
- package/dist/domain/openapi/unsupported-features.mjs.map +1 -0
- package/dist/domain/output-fixes.cjs +66 -0
- package/dist/domain/output-fixes.cjs.map +1 -0
- package/dist/domain/output-fixes.mjs +59 -0
- package/dist/domain/output-fixes.mjs.map +1 -0
- package/dist/index.cjs +98 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +812 -0
- package/dist/index.d.mts +812 -0
- package/dist/index.d.ts +812 -0
- package/dist/index.mjs +27 -0
- package/dist/index.mjs.map +1 -0
- package/dist/transform/components-object.cjs +14 -0
- package/dist/transform/components-object.cjs.map +1 -0
- package/dist/transform/components-object.mjs +10 -0
- package/dist/transform/components-object.mjs.map +1 -0
- package/dist/transform/header-object.cjs +12 -0
- package/dist/transform/header-object.cjs.map +1 -0
- package/dist/transform/header-object.mjs +10 -0
- package/dist/transform/header-object.mjs.map +1 -0
- package/dist/transform/media-type-object.cjs +12 -0
- package/dist/transform/media-type-object.cjs.map +1 -0
- package/dist/transform/media-type-object.mjs +10 -0
- package/dist/transform/media-type-object.mjs.map +1 -0
- package/dist/transform/operation-object.cjs +26 -0
- package/dist/transform/operation-object.cjs.map +1 -0
- package/dist/transform/operation-object.mjs +21 -0
- package/dist/transform/operation-object.mjs.map +1 -0
- package/dist/transform/parameter-object.cjs +12 -0
- package/dist/transform/parameter-object.cjs.map +1 -0
- package/dist/transform/parameter-object.mjs +10 -0
- package/dist/transform/parameter-object.mjs.map +1 -0
- package/dist/transform/path-item-object.cjs +12 -0
- package/dist/transform/path-item-object.cjs.map +1 -0
- package/dist/transform/path-item-object.mjs +10 -0
- package/dist/transform/path-item-object.mjs.map +1 -0
- package/dist/transform/paths-object.cjs +11 -0
- package/dist/transform/paths-object.cjs.map +1 -0
- package/dist/transform/paths-object.mjs +9 -0
- package/dist/transform/paths-object.mjs.map +1 -0
- package/dist/transform/request-body-object.cjs +12 -0
- package/dist/transform/request-body-object.cjs.map +1 -0
- package/dist/transform/request-body-object.mjs +10 -0
- package/dist/transform/request-body-object.mjs.map +1 -0
- package/dist/transform/response-object.cjs +12 -0
- package/dist/transform/response-object.cjs.map +1 -0
- package/dist/transform/response-object.mjs +10 -0
- package/dist/transform/response-object.mjs.map +1 -0
- package/dist/transform/responses-object.cjs +12 -0
- package/dist/transform/responses-object.cjs.map +1 -0
- package/dist/transform/responses-object.mjs +10 -0
- package/dist/transform/responses-object.mjs.map +1 -0
- package/dist/transform/schema-object.cjs +21 -0
- package/dist/transform/schema-object.cjs.map +1 -0
- package/dist/transform/schema-object.mjs +16 -0
- package/dist/transform/schema-object.mjs.map +1 -0
- package/package.json +115 -4
- package/src/adapters/node-file-system/node-file-system.ts +44 -0
- package/src/adapters/redocly-loader/alias-limit.ts +20 -0
- package/src/adapters/redocly-loader/allowed-hosts.ts +62 -0
- package/src/adapters/redocly-loader/bundled-ref-repair.ts +65 -0
- package/src/adapters/redocly-loader/malformed-refs.ts +61 -0
- package/src/adapters/redocly-loader/redocly-config-source.ts +43 -0
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +246 -0
- package/src/adapters/redocly-loader/ref-access.ts +146 -0
- package/src/adapters/redocly-loader/ref-holders.ts +43 -0
- package/src/adapters/redocly-loader/remote-fetch.ts +104 -0
- package/src/adapters/redocly-loader/schema-load-errors.ts +124 -0
- package/src/adapters/redocly-loader/schema-source.ts +151 -0
- package/src/adapters/redocly-loader/unsupported-keys.ts +102 -0
- package/src/adapters/terminal-logger/terminal-logger.ts +98 -0
- package/src/adapters/type-ast-bridge/footer-nodes.ts +38 -0
- package/src/adapters/type-ast-bridge/ir-declarations-to-typescript.ts +100 -0
- package/src/adapters/type-ast-bridge/ir-to-typescript.ts +220 -0
- package/src/adapters/type-ast-bridge/lazy-node.ts +24 -0
- package/src/adapters/type-ast-bridge/load-typescript.ts +84 -0
- package/src/adapters/type-ast-bridge/print-typescript.ts +33 -0
- package/src/adapters/type-ast-bridge/typescript-raw-text.ts +49 -0
- package/src/adapters/type-ast-bridge/typescript-to-ir.ts +280 -0
- package/src/adapters/type-ast-bridge/typescript-types.ts +8 -0
- package/src/api/ast-to-string.ts +59 -0
- package/src/api/comment-header.ts +7 -0
- package/src/api/default-ports.ts +44 -0
- package/src/api/discriminator-enum.ts +76 -0
- package/src/api/discriminator-scan.ts +272 -0
- package/src/api/document-declarations.ts +41 -0
- package/src/api/document-refs.ts +71 -0
- package/src/api/document-run.ts +159 -0
- package/src/api/footer-entry.ts +23 -0
- package/src/api/footer-sink.ts +67 -0
- package/src/api/legacy-callback-warning.ts +29 -0
- package/src/api/legacy-ts-helpers.ts +311 -0
- package/src/api/legacy-utils.ts +118 -0
- package/src/api/openapi-ts.ts +62 -0
- package/src/api/schema-callbacks.ts +211 -0
- package/src/api/string-to-ast.ts +27 -0
- package/src/api/transform-context.ts +87 -0
- package/src/api/transform-schema.ts +39 -0
- package/src/api/type-helpers.ts +130 -0
- package/src/api/unsupported-feature-warnings.ts +26 -0
- package/src/application/ports/file-system.ts +12 -0
- package/src/application/ports/logger.ts +16 -0
- package/src/application/ports/redocly-config-source.ts +16 -0
- package/src/application/ports/schema-loader.ts +32 -0
- package/src/application/print/comment-writer.ts +91 -0
- package/src/application/print/declaration-printer.ts +100 -0
- package/src/application/print/literal-text.ts +62 -0
- package/src/application/print/print-nodes.ts +62 -0
- package/src/application/print/print-options.ts +11 -0
- package/src/application/print/text-writer.ts +83 -0
- package/src/application/print/type-printer.ts +281 -0
- package/src/application/stack-overflow.ts +54 -0
- package/src/application/transform/document/components.ts +189 -0
- package/src/application/transform/document/defs-root.ts +25 -0
- package/src/application/transform/document/document-member.ts +20 -0
- package/src/application/transform/document/document.ts +157 -0
- package/src/application/transform/document/header.ts +34 -0
- package/src/application/transform/document/kept-deprecated.ts +135 -0
- package/src/application/transform/document/media-type.ts +78 -0
- package/src/application/transform/document/operation.ts +64 -0
- package/src/application/transform/document/parameter.ts +45 -0
- package/src/application/transform/document/parameters.ts +200 -0
- package/src/application/transform/document/path-item-conflicts.ts +79 -0
- package/src/application/transform/document/path-item.ts +168 -0
- package/src/application/transform/document/path-key-overlaps.ts +112 -0
- package/src/application/transform/document/paths-enum.ts +127 -0
- package/src/application/transform/document/paths.ts +211 -0
- package/src/application/transform/document/request-body.ts +50 -0
- package/src/application/transform/document/response.ts +109 -0
- package/src/application/transform/document/responses.ts +29 -0
- package/src/application/transform/document/root-type-aliases.ts +106 -0
- package/src/application/transform/document/webhooks.ts +22 -0
- package/src/application/transform/document-entries.ts +28 -0
- package/src/application/transform/footer/document-footer.ts +127 -0
- package/src/application/transform/footer/enum-naming.ts +181 -0
- package/src/application/transform/helper-types.ts +92 -0
- package/src/application/transform/literal-type.ts +54 -0
- package/src/application/transform/numbered-names.ts +20 -0
- package/src/application/transform/ref-type.ts +97 -0
- package/src/application/transform/schema/array-type.ts +152 -0
- package/src/application/transform/schema/composition-type.ts +183 -0
- package/src/application/transform/schema/core-type.ts +115 -0
- package/src/application/transform/schema/discriminator-property.ts +28 -0
- package/src/application/transform/schema/enum-rule.ts +157 -0
- package/src/application/transform/schema/object-type.ts +271 -0
- package/src/application/transform/schema/presence-members.ts +96 -0
- package/src/application/transform/schema/schema-context.ts +110 -0
- package/src/application/transform/schema/schema-rule.ts +29 -0
- package/src/application/transform/schema/schema-transform.ts +99 -0
- package/src/application/transform/schema/unevaluated-properties.ts +105 -0
- package/src/application/transform/schema-comment.ts +116 -0
- package/src/application/transform/shared-types.ts +9 -0
- package/src/application/transform/transform-context.ts +51 -0
- package/src/application/transform/type-combinators.ts +57 -0
- package/src/cli/cli-arguments.ts +198 -0
- package/src/cli/cli-dependencies.ts +42 -0
- package/src/cli/cli-errors.ts +125 -0
- package/src/cli/cli-output.ts +53 -0
- package/src/cli/docs-links.ts +6 -0
- package/src/cli/fix-option.ts +29 -0
- package/src/cli/help-text.ts +52 -0
- package/src/cli/main.ts +67 -0
- package/src/cli/redocly-apis.ts +91 -0
- package/src/cli/ref-limits.ts +16 -0
- package/src/cli/run-cli.ts +114 -0
- package/src/domain/assert-never.ts +8 -0
- package/src/domain/errors.ts +74 -0
- package/src/domain/ir/constructors.ts +137 -0
- package/src/domain/ir/identifier-text.ts +49 -0
- package/src/domain/ir/newer-identifier-ranges.ts +109 -0
- package/src/domain/ir/nodes.ts +224 -0
- package/src/domain/ir/normalize.ts +51 -0
- package/src/domain/ir/property-name.ts +28 -0
- package/src/domain/ir/raw-text-escapes.ts +37 -0
- package/src/domain/openapi/alias-expansion.ts +72 -0
- package/src/domain/openapi/binary-content.ts +74 -0
- package/src/domain/openapi/components-object.ts +52 -0
- package/src/domain/openapi/document-object.ts +12 -0
- package/src/domain/openapi/header-object.ts +9 -0
- package/src/domain/openapi/json-pointer.ts +46 -0
- package/src/domain/openapi/media-type-object.ts +26 -0
- package/src/domain/openapi/operation-object.ts +13 -0
- package/src/domain/openapi/parameter-object.ts +30 -0
- package/src/domain/openapi/path-item-object.ts +70 -0
- package/src/domain/openapi/request-body-object.ts +7 -0
- package/src/domain/openapi/response-object.ts +14 -0
- package/src/domain/openapi/schema-object.ts +59 -0
- package/src/domain/openapi/unsupported-features.ts +139 -0
- package/src/domain/output-fixes.ts +95 -0
- package/src/index.ts +67 -0
- package/src/transform/components-object.ts +25 -0
- package/src/transform/header-object.ts +19 -0
- package/src/transform/media-type-object.ts +19 -0
- package/src/transform/operation-object.ts +36 -0
- package/src/transform/parameter-object.ts +19 -0
- package/src/transform/parameters-array.ts +19 -0
- package/src/transform/path-item-object.ts +22 -0
- package/src/transform/paths-enum.ts +8 -0
- package/src/transform/paths-object.ts +15 -0
- package/src/transform/request-body-object.ts +19 -0
- package/src/transform/response-object.ts +19 -0
- package/src/transform/responses-object.ts +19 -0
- package/src/transform/schema-object.ts +36 -0
- package/src/transform/webhooks-object.ts +15 -0
- package/src/types/generator-options.ts +267 -0
- package/src/types/openapi-common.ts +100 -0
- package/src/types/openapi-document.ts +196 -0
- package/src/types/openapi-path-item.ts +130 -0
- package/src/types/openapi-request.ts +209 -0
- package/src/types/openapi-response.ts +81 -0
- package/src/types/openapi-schema.ts +169 -0
- package/src/types/openapi-security.ts +116 -0
- package/src/types.ts +12 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
IrArrayType,
|
|
3
|
+
IrBooleanLiteralType,
|
|
4
|
+
IrComment,
|
|
5
|
+
IrIndexedAccessType,
|
|
6
|
+
IrIndexSignature,
|
|
7
|
+
IrIntersectionType,
|
|
8
|
+
IrKeyword,
|
|
9
|
+
IrKeywordType,
|
|
10
|
+
IrMember,
|
|
11
|
+
IrNumberLiteralType,
|
|
12
|
+
IrObjectType,
|
|
13
|
+
IrPropertyName,
|
|
14
|
+
IrPropertySignature,
|
|
15
|
+
IrRawType,
|
|
16
|
+
IrReadonlyType,
|
|
17
|
+
IrReferenceType,
|
|
18
|
+
IrStringEncoding,
|
|
19
|
+
IrStringLiteralType,
|
|
20
|
+
IrTupleElement,
|
|
21
|
+
IrTupleType,
|
|
22
|
+
IrType,
|
|
23
|
+
IrUnionType,
|
|
24
|
+
} from "./nodes.js";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Constructors of IR nodes. They build exactly the node asked for: no flattening, de-duplication or
|
|
28
|
+
* sorting happens here (ENGINEERING_PLAN §4.2). Callers that need those call the functions in
|
|
29
|
+
* `normalize.ts` explicitly, at the same places the original generator does.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export function irKeyword(keyword: IrKeyword): IrKeywordType {
|
|
33
|
+
return { kind: "keyword", keyword };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function irString(value: string, encoding: IrStringEncoding): IrStringLiteralType {
|
|
37
|
+
return { kind: "stringLiteral", value, encoding };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Throws on NaN and infinities: they have no literal type. */
|
|
41
|
+
export function irNumber(value: number): IrNumberLiteralType {
|
|
42
|
+
if (!Number.isFinite(value)) {
|
|
43
|
+
throw new RangeError(`A number literal type needs a finite number, got ${value}`);
|
|
44
|
+
}
|
|
45
|
+
return { kind: "numberLiteral", value };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function irBoolean(value: boolean): IrBooleanLiteralType {
|
|
49
|
+
return { kind: "booleanLiteral", value };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function irReference(name: string, typeArguments: readonly IrType[] = []): IrReferenceType {
|
|
53
|
+
return { kind: "reference", name, typeArguments };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function irArray(element: IrType): IrArrayType {
|
|
57
|
+
return { kind: "array", element };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function irTuple(elements: readonly IrTupleElement[]): IrTupleType {
|
|
61
|
+
return { kind: "tuple", elements };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function irTupleElement(type: IrType, isRest = false): IrTupleElement {
|
|
65
|
+
return { type, isRest };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function irUnion(types: readonly IrType[]): IrUnionType {
|
|
69
|
+
return { kind: "union", types };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function irIntersection(types: readonly IrType[]): IrIntersectionType {
|
|
73
|
+
return { kind: "intersection", types };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function irObject(members: readonly IrMember[]): IrObjectType {
|
|
77
|
+
return { kind: "object", members };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function irIndexedAccess(object: IrType, index: IrType): IrIndexedAccessType {
|
|
81
|
+
return { kind: "indexedAccess", object, index };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function irReadonly(type: IrType): IrReadonlyType {
|
|
85
|
+
return { kind: "readonly", type };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Type text printed as is. The original builds some types from text (template literal path keys,
|
|
90
|
+
* root type aliases); keeping them as text keeps their exact spelling.
|
|
91
|
+
*/
|
|
92
|
+
export function irRaw(text: string, origin?: unknown): IrRawType {
|
|
93
|
+
return origin === undefined ? { kind: "raw", text } : { kind: "raw", text, origin };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Options of a property signature; omitted flags are false and there are no comments. */
|
|
97
|
+
export interface IrPropertyOptions {
|
|
98
|
+
readonly isOptional?: boolean;
|
|
99
|
+
readonly isReadonly?: boolean;
|
|
100
|
+
readonly comments?: readonly IrComment[];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function irProperty(
|
|
104
|
+
name: IrPropertyName,
|
|
105
|
+
type: IrType,
|
|
106
|
+
options: IrPropertyOptions = {},
|
|
107
|
+
): IrPropertySignature {
|
|
108
|
+
return {
|
|
109
|
+
kind: "property",
|
|
110
|
+
name,
|
|
111
|
+
type,
|
|
112
|
+
isOptional: options.isOptional ?? false,
|
|
113
|
+
isReadonly: options.isReadonly ?? false,
|
|
114
|
+
comments: options.comments ?? [],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** `[name: string]: type` (a `string` key, the only kind the generator writes). */
|
|
119
|
+
export function irStringIndexSignature(
|
|
120
|
+
parameterName: string,
|
|
121
|
+
type: IrType,
|
|
122
|
+
isReadonly = false,
|
|
123
|
+
): IrIndexSignature {
|
|
124
|
+
return {
|
|
125
|
+
kind: "indexSignature",
|
|
126
|
+
parameterName,
|
|
127
|
+
parameterType: irKeyword("string"),
|
|
128
|
+
type,
|
|
129
|
+
isReadonly,
|
|
130
|
+
comments: [],
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** `Record<key, value>`. */
|
|
135
|
+
export function irRecord(key: IrType, value: IrType): IrReferenceType {
|
|
136
|
+
return irReference("Record", [key, value]);
|
|
137
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { NEWER_IDENTIFIER_PART, NEWER_IDENTIFIER_START } from "./newer-identifier-ranges.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Identifier rules of ECMAScript (Unicode `ID_Start` / `ID_Continue`, plus `$`, `_`, ZWNJ and
|
|
5
|
+
* ZWJ), for names built from document text, without the characters that TypeScript's scanner
|
|
6
|
+
* does not know yet. Node.js follows a newer Unicode version than TypeScript's identifier tables,
|
|
7
|
+
* so a name such as `Name` (Unicode 17) passed here and failed to parse with "Invalid
|
|
8
|
+
* character" (ADR-019). Removing the newer characters also gives the same names on every
|
|
9
|
+
* supported Node.js version.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const IDENTIFIER_START_RE = new RegExp(
|
|
13
|
+
`^[[\\p{ID_Start}$_]--[${NEWER_IDENTIFIER_START.join("")}]]`,
|
|
14
|
+
"v",
|
|
15
|
+
);
|
|
16
|
+
const INVALID_IDENTIFIER_PART_RE = new RegExp(
|
|
17
|
+
`[^[\\p{ID_Continue}$\\u{200C}\\u{200D}]--[${NEWER_IDENTIFIER_PART.join("")}]]`,
|
|
18
|
+
"gv",
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
/** Whether the text starts with a character that may start an identifier. */
|
|
22
|
+
export function hasIdentifierStart(text: string): boolean {
|
|
23
|
+
return IDENTIFIER_START_RE.test(text);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The text with each character that cannot be part of an identifier replaced by `_`. */
|
|
27
|
+
export function withIdentifierParts(text: string): string {
|
|
28
|
+
return text.replace(INVALID_IDENTIFIER_PART_RE, "_");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The names TypeScript does not accept as a type alias name: reserved words, strict mode and
|
|
33
|
+
* module reserved words, and predefined type names (`void`, `string`, …). Checked with the
|
|
34
|
+
* TypeScript 6.0 compiler on `export type <name> = 1;` in a module.
|
|
35
|
+
*/
|
|
36
|
+
const RESERVED_TYPE_NAMES: ReadonlySet<string> = new Set(
|
|
37
|
+
(
|
|
38
|
+
"any as await bigint boolean break case catch class const continue debugger default delete " +
|
|
39
|
+
"do else enum export extends false finally for function if implements import in instanceof " +
|
|
40
|
+
"interface let never new null number object package private protected public return static " +
|
|
41
|
+
"string super switch symbol this throw true try typeof undefined unknown var void while with " +
|
|
42
|
+
"yield"
|
|
43
|
+
).split(" "),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
/** Whether TypeScript rejects the text as the name of a type alias. */
|
|
47
|
+
export function isReservedTypeName(text: string): boolean {
|
|
48
|
+
return RESERVED_TYPE_NAMES.has(text);
|
|
49
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Generated by scripts/identifier-ranges.ts (Node.js 26.0.0, Unicode
|
|
2
|
+
// 17.0, TypeScript 5.9.3). Do not edit.
|
|
3
|
+
|
|
4
|
+
/** `ID_Start` code points that TypeScript's scanner does not accept, as regex class items. */
|
|
5
|
+
export const NEWER_IDENTIFIER_START: readonly string[] = [
|
|
6
|
+
"\\u{88F}",
|
|
7
|
+
"\\u{C5C}",
|
|
8
|
+
"\\u{CDC}",
|
|
9
|
+
"\\u{1C89}-\\u{1C8A}",
|
|
10
|
+
"\\u{A7CB}-\\u{A7CF}",
|
|
11
|
+
"\\u{A7D2}",
|
|
12
|
+
"\\u{A7D4}",
|
|
13
|
+
"\\u{A7DA}-\\u{A7DC}",
|
|
14
|
+
"\\u{A7F1}",
|
|
15
|
+
"\\u{105C0}-\\u{105F3}",
|
|
16
|
+
"\\u{10940}-\\u{10959}",
|
|
17
|
+
"\\u{10D4A}-\\u{10D65}",
|
|
18
|
+
"\\u{10D6F}-\\u{10D85}",
|
|
19
|
+
"\\u{10EC2}-\\u{10EC7}",
|
|
20
|
+
"\\u{11380}-\\u{11389}",
|
|
21
|
+
"\\u{1138B}",
|
|
22
|
+
"\\u{1138E}",
|
|
23
|
+
"\\u{11390}-\\u{113B5}",
|
|
24
|
+
"\\u{113B7}",
|
|
25
|
+
"\\u{113D1}",
|
|
26
|
+
"\\u{113D3}",
|
|
27
|
+
"\\u{11BC0}-\\u{11BE0}",
|
|
28
|
+
"\\u{11DB0}-\\u{11DDB}",
|
|
29
|
+
"\\u{13460}-\\u{143FA}",
|
|
30
|
+
"\\u{16100}-\\u{1611D}",
|
|
31
|
+
"\\u{16D40}-\\u{16D6C}",
|
|
32
|
+
"\\u{16EA0}-\\u{16EB8}",
|
|
33
|
+
"\\u{16EBB}-\\u{16ED3}",
|
|
34
|
+
"\\u{16FF2}-\\u{16FF6}",
|
|
35
|
+
"\\u{187F8}-\\u{187FF}",
|
|
36
|
+
"\\u{18CFF}",
|
|
37
|
+
"\\u{18D09}-\\u{18D1E}",
|
|
38
|
+
"\\u{18D80}-\\u{18DF2}",
|
|
39
|
+
"\\u{1E5D0}-\\u{1E5ED}",
|
|
40
|
+
"\\u{1E5F0}",
|
|
41
|
+
"\\u{1E6C0}-\\u{1E6DE}",
|
|
42
|
+
"\\u{1E6E0}-\\u{1E6E2}",
|
|
43
|
+
"\\u{1E6E4}-\\u{1E6E5}",
|
|
44
|
+
"\\u{1E6E7}-\\u{1E6ED}",
|
|
45
|
+
"\\u{1E6F0}-\\u{1E6F4}",
|
|
46
|
+
"\\u{1E6FE}-\\u{1E6FF}",
|
|
47
|
+
"\\u{2B73A}-\\u{2B73F}",
|
|
48
|
+
"\\u{2CEA2}-\\u{2CEAD}",
|
|
49
|
+
"\\u{323B0}-\\u{33479}",
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
/** `ID_Continue` code points that TypeScript's scanner does not accept, as regex class items. */
|
|
53
|
+
export const NEWER_IDENTIFIER_PART: readonly string[] = [
|
|
54
|
+
"\\u{88F}",
|
|
55
|
+
"\\u{897}",
|
|
56
|
+
"\\u{C5C}",
|
|
57
|
+
"\\u{CDC}",
|
|
58
|
+
"\\u{1ACF}-\\u{1ADD}",
|
|
59
|
+
"\\u{1AE0}-\\u{1AEB}",
|
|
60
|
+
"\\u{1C89}-\\u{1C8A}",
|
|
61
|
+
"\\u{A7CB}-\\u{A7CF}",
|
|
62
|
+
"\\u{A7D2}",
|
|
63
|
+
"\\u{A7D4}",
|
|
64
|
+
"\\u{A7DA}-\\u{A7DC}",
|
|
65
|
+
"\\u{A7F1}",
|
|
66
|
+
"\\u{105C0}-\\u{105F3}",
|
|
67
|
+
"\\u{10940}-\\u{10959}",
|
|
68
|
+
"\\u{10D40}-\\u{10D65}",
|
|
69
|
+
"\\u{10D69}-\\u{10D6D}",
|
|
70
|
+
"\\u{10D6F}-\\u{10D85}",
|
|
71
|
+
"\\u{10EC2}-\\u{10EC7}",
|
|
72
|
+
"\\u{10EFA}-\\u{10EFC}",
|
|
73
|
+
"\\u{11380}-\\u{11389}",
|
|
74
|
+
"\\u{1138B}",
|
|
75
|
+
"\\u{1138E}",
|
|
76
|
+
"\\u{11390}-\\u{113B5}",
|
|
77
|
+
"\\u{113B7}-\\u{113C0}",
|
|
78
|
+
"\\u{113C2}",
|
|
79
|
+
"\\u{113C5}",
|
|
80
|
+
"\\u{113C7}-\\u{113CA}",
|
|
81
|
+
"\\u{113CC}-\\u{113D3}",
|
|
82
|
+
"\\u{113E1}-\\u{113E2}",
|
|
83
|
+
"\\u{116D0}-\\u{116E3}",
|
|
84
|
+
"\\u{11B60}-\\u{11B67}",
|
|
85
|
+
"\\u{11BC0}-\\u{11BE0}",
|
|
86
|
+
"\\u{11BF0}-\\u{11BF9}",
|
|
87
|
+
"\\u{11DB0}-\\u{11DDB}",
|
|
88
|
+
"\\u{11DE0}-\\u{11DE9}",
|
|
89
|
+
"\\u{11F5A}",
|
|
90
|
+
"\\u{13460}-\\u{143FA}",
|
|
91
|
+
"\\u{16100}-\\u{16139}",
|
|
92
|
+
"\\u{16D40}-\\u{16D6C}",
|
|
93
|
+
"\\u{16D70}-\\u{16D79}",
|
|
94
|
+
"\\u{16EA0}-\\u{16EB8}",
|
|
95
|
+
"\\u{16EBB}-\\u{16ED3}",
|
|
96
|
+
"\\u{16FF2}-\\u{16FF6}",
|
|
97
|
+
"\\u{187F8}-\\u{187FF}",
|
|
98
|
+
"\\u{18CFF}",
|
|
99
|
+
"\\u{18D09}-\\u{18D1E}",
|
|
100
|
+
"\\u{18D80}-\\u{18DF2}",
|
|
101
|
+
"\\u{1CCF0}-\\u{1CCF9}",
|
|
102
|
+
"\\u{1E5D0}-\\u{1E5FA}",
|
|
103
|
+
"\\u{1E6C0}-\\u{1E6DE}",
|
|
104
|
+
"\\u{1E6E0}-\\u{1E6F5}",
|
|
105
|
+
"\\u{1E6FE}-\\u{1E6FF}",
|
|
106
|
+
"\\u{2B73A}-\\u{2B73F}",
|
|
107
|
+
"\\u{2CEA2}-\\u{2CEAD}",
|
|
108
|
+
"\\u{323B0}-\\u{33479}",
|
|
109
|
+
];
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type IR: the closed set of immutable nodes that describes the TypeScript types and declarations
|
|
3
|
+
* the generator emits (ENGINEERING_PLAN §4.2, ADR-002). Nodes are plain readonly data with a `kind`
|
|
4
|
+
* discriminator; every consumer dispatches with an exhaustive `switch`, so a new kind breaks the
|
|
5
|
+
* build wherever it must be handled.
|
|
6
|
+
*
|
|
7
|
+
* Utility types (`Omit`, `Record`, `WithRequired`, `Extract`) are `reference` nodes with type
|
|
8
|
+
* arguments, built by named constructors: the printer has nothing special to do for them.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Keyword types. `null` is a keyword here; TypeScript models it as a literal type. */
|
|
12
|
+
export type IrKeyword =
|
|
13
|
+
| "string"
|
|
14
|
+
| "number"
|
|
15
|
+
| "boolean"
|
|
16
|
+
| "null"
|
|
17
|
+
| "undefined"
|
|
18
|
+
| "unknown"
|
|
19
|
+
| "never";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* How a string literal is written.
|
|
23
|
+
* - `json`: `JSON.stringify` text, non-ASCII kept as is. The original writes literal types this way
|
|
24
|
+
* to keep UTF-8 readable (TypeScript issue 36174).
|
|
25
|
+
* - `escaped`: TypeScript printer escaping, non-ASCII as `\uXXXX`. The original writes
|
|
26
|
+
* indexed-access keys and quoted property names this way.
|
|
27
|
+
*/
|
|
28
|
+
export type IrStringEncoding = "json" | "escaped";
|
|
29
|
+
|
|
30
|
+
export interface IrKeywordType {
|
|
31
|
+
readonly kind: "keyword";
|
|
32
|
+
readonly keyword: IrKeyword;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface IrStringLiteralType {
|
|
36
|
+
readonly kind: "stringLiteral";
|
|
37
|
+
readonly value: string;
|
|
38
|
+
readonly encoding: IrStringEncoding;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Finite number; a negative value prints with a leading minus sign. */
|
|
42
|
+
export interface IrNumberLiteralType {
|
|
43
|
+
readonly kind: "numberLiteral";
|
|
44
|
+
readonly value: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface IrBooleanLiteralType {
|
|
48
|
+
readonly kind: "booleanLiteral";
|
|
49
|
+
readonly value: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** A named type, optionally with type arguments: `components`, `Record<string, never>`. */
|
|
53
|
+
export interface IrReferenceType {
|
|
54
|
+
readonly kind: "reference";
|
|
55
|
+
readonly name: string;
|
|
56
|
+
readonly typeArguments: readonly IrType[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface IrArrayType {
|
|
60
|
+
readonly kind: "array";
|
|
61
|
+
readonly element: IrType;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A tuple element; `isRest` prints `...T`. */
|
|
65
|
+
export interface IrTupleElement {
|
|
66
|
+
readonly type: IrType;
|
|
67
|
+
readonly isRest: boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface IrTupleType {
|
|
71
|
+
readonly kind: "tuple";
|
|
72
|
+
readonly elements: readonly IrTupleElement[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface IrUnionType {
|
|
76
|
+
readonly kind: "union";
|
|
77
|
+
readonly types: readonly IrType[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface IrIntersectionType {
|
|
81
|
+
readonly kind: "intersection";
|
|
82
|
+
readonly types: readonly IrType[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface IrObjectType {
|
|
86
|
+
readonly kind: "object";
|
|
87
|
+
readonly members: readonly IrMember[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** `object[index]`, for example `components["schemas"]`. */
|
|
91
|
+
export interface IrIndexedAccessType {
|
|
92
|
+
readonly kind: "indexedAccess";
|
|
93
|
+
readonly object: IrType;
|
|
94
|
+
readonly index: IrType;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** `readonly T` (the only type operator the generator emits). */
|
|
98
|
+
export interface IrReadonlyType {
|
|
99
|
+
readonly kind: "readonly";
|
|
100
|
+
readonly type: IrType;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Text printed as is. Escape hatch for types that come from outside the IR, for example output of
|
|
105
|
+
* legacy `ts.Node` callbacks converted by the type-AST bridge (ENGINEERING_PLAN 6.3). The text is
|
|
106
|
+
* written as if it started at column 0: each line after the first gets the indentation of the
|
|
107
|
+
* position where the type is printed. Known limit: this also indents the continuation lines of a
|
|
108
|
+
* template literal that spans lines, which TypeScript keeps verbatim (ADR-004).
|
|
109
|
+
*/
|
|
110
|
+
export interface IrRawType {
|
|
111
|
+
readonly kind: "raw";
|
|
112
|
+
readonly text: string;
|
|
113
|
+
/**
|
|
114
|
+
* The outside node the text was printed from, opaque to the IR. While the Node API still
|
|
115
|
+
* returns `ts.Node`s (until Phase 6), the bridge hands this node back unchanged, exactly as the
|
|
116
|
+
* original did. Removed with the reverse bridge in Phase 6.
|
|
117
|
+
*/
|
|
118
|
+
readonly origin?: unknown;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type IrType =
|
|
122
|
+
| IrKeywordType
|
|
123
|
+
| IrStringLiteralType
|
|
124
|
+
| IrNumberLiteralType
|
|
125
|
+
| IrBooleanLiteralType
|
|
126
|
+
| IrReferenceType
|
|
127
|
+
| IrArrayType
|
|
128
|
+
| IrTupleType
|
|
129
|
+
| IrUnionType
|
|
130
|
+
| IrIntersectionType
|
|
131
|
+
| IrObjectType
|
|
132
|
+
| IrIndexedAccessType
|
|
133
|
+
| IrReadonlyType
|
|
134
|
+
| IrRawType;
|
|
135
|
+
|
|
136
|
+
/** A comment printed on its own line before a node; a node may have several, printed in order. */
|
|
137
|
+
export type IrComment =
|
|
138
|
+
/** `/*text*\/`: `text` is the comment body, for example `* @description Hello `. */
|
|
139
|
+
| { readonly kind: "block"; readonly text: string }
|
|
140
|
+
/** `//text`. */
|
|
141
|
+
| { readonly kind: "line"; readonly text: string };
|
|
142
|
+
|
|
143
|
+
/** Property key: identifier, quoted string, or number, as decided by `toPropertyName`. */
|
|
144
|
+
export type IrPropertyName =
|
|
145
|
+
| { readonly kind: "identifier"; readonly text: string }
|
|
146
|
+
| { readonly kind: "string"; readonly value: string }
|
|
147
|
+
| { readonly kind: "number"; readonly text: string };
|
|
148
|
+
|
|
149
|
+
export interface IrPropertySignature {
|
|
150
|
+
readonly kind: "property";
|
|
151
|
+
readonly name: IrPropertyName;
|
|
152
|
+
readonly type: IrType;
|
|
153
|
+
readonly isOptional: boolean;
|
|
154
|
+
readonly isReadonly: boolean;
|
|
155
|
+
readonly comments: readonly IrComment[];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** `[parameterName: parameterType]: type`. */
|
|
159
|
+
export interface IrIndexSignature {
|
|
160
|
+
readonly kind: "indexSignature";
|
|
161
|
+
readonly parameterName: string;
|
|
162
|
+
readonly parameterType: IrType;
|
|
163
|
+
readonly type: IrType;
|
|
164
|
+
readonly isReadonly: boolean;
|
|
165
|
+
readonly comments: readonly IrComment[];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export type IrMember = IrPropertySignature | IrIndexSignature;
|
|
169
|
+
|
|
170
|
+
export interface IrInterfaceDeclaration {
|
|
171
|
+
readonly kind: "interface";
|
|
172
|
+
readonly name: string;
|
|
173
|
+
readonly isExported: boolean;
|
|
174
|
+
readonly members: readonly IrMember[];
|
|
175
|
+
readonly comments: readonly IrComment[];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface IrTypeAliasDeclaration {
|
|
179
|
+
readonly kind: "typeAlias";
|
|
180
|
+
readonly name: string;
|
|
181
|
+
readonly isExported: boolean;
|
|
182
|
+
readonly type: IrType;
|
|
183
|
+
readonly comments: readonly IrComment[];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** `name` is printed as given (already sanitized or quoted by the enum naming rules). */
|
|
187
|
+
export interface IrEnumMember {
|
|
188
|
+
readonly name: string;
|
|
189
|
+
readonly value: string | number;
|
|
190
|
+
readonly comments: readonly IrComment[];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface IrEnumDeclaration {
|
|
194
|
+
readonly kind: "enum";
|
|
195
|
+
readonly name: string;
|
|
196
|
+
readonly isExported: boolean;
|
|
197
|
+
readonly members: readonly IrEnumMember[];
|
|
198
|
+
readonly comments: readonly IrComment[];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** `const name: type = [values];` (the `--enum-values` and `--make-paths-enum` arrays). */
|
|
202
|
+
export interface IrConstArrayDeclaration {
|
|
203
|
+
readonly kind: "constArray";
|
|
204
|
+
readonly name: string;
|
|
205
|
+
readonly isExported: boolean;
|
|
206
|
+
readonly type: IrType;
|
|
207
|
+
readonly values: readonly (string | number)[];
|
|
208
|
+
readonly comments: readonly IrComment[];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** A declaration printed as is: footer helpers and injected code. */
|
|
212
|
+
export interface IrRawDeclaration {
|
|
213
|
+
readonly kind: "rawDeclaration";
|
|
214
|
+
readonly text: string;
|
|
215
|
+
/** The type name the text declares, when known (helper types), so the footer can find it. */
|
|
216
|
+
readonly name?: string;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export type IrDeclaration =
|
|
220
|
+
| IrInterfaceDeclaration
|
|
221
|
+
| IrTypeAliasDeclaration
|
|
222
|
+
| IrEnumDeclaration
|
|
223
|
+
| IrConstArrayDeclaration
|
|
224
|
+
| IrRawDeclaration;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { IrKeyword, IrType } from "./nodes.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Keywords that `dedupeTypes` removes when repeated. The original (`tsDedupe`) treats these as
|
|
5
|
+
* primitives; `unknown` is not one of them and is kept even when repeated.
|
|
6
|
+
*/
|
|
7
|
+
const DEDUPLICATED_KEYWORDS: ReadonlySet<IrKeyword> = new Set([
|
|
8
|
+
"boolean",
|
|
9
|
+
"never",
|
|
10
|
+
"null",
|
|
11
|
+
"number",
|
|
12
|
+
"string",
|
|
13
|
+
"undefined",
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Remove repeated primitive keywords from a union or intersection member list, keeping the first
|
|
18
|
+
* occurrence and the order. Literals, references and object types are never removed, even when
|
|
19
|
+
* equal: this matches the original `tsDedupe`, which compares only node kinds of primitives.
|
|
20
|
+
*/
|
|
21
|
+
export function dedupeTypes(types: readonly IrType[]): IrType[] {
|
|
22
|
+
const seenKeywords = new Set<IrKeyword>();
|
|
23
|
+
const kept: IrType[] = [];
|
|
24
|
+
for (const type of types) {
|
|
25
|
+
if (type.kind === "keyword" && DEDUPLICATED_KEYWORDS.has(type.keyword)) {
|
|
26
|
+
if (seenKeywords.has(type.keyword)) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
seenKeywords.add(type.keyword);
|
|
30
|
+
}
|
|
31
|
+
kept.push(type);
|
|
32
|
+
}
|
|
33
|
+
return kept;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The collation the original `getEntries` uses for `alphabetize`. Natural order: `a2` sorts before
|
|
38
|
+
* `a10`. It is locale-based on purpose, to stay byte-compatible with the original output.
|
|
39
|
+
*/
|
|
40
|
+
const ALPHABETIZE_COLLATOR = new Intl.Collator("en-us", { numeric: true });
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Sort `[key, value]` entries by key like the original `alphabetize` option (ENGINEERING_PLAN 4.1
|
|
44
|
+
* `sortMembers`). The original sorts source entries before it builds members, so transformers call
|
|
45
|
+
* this on entries, not on finished IR members. The sort is stable and returns a new array.
|
|
46
|
+
*/
|
|
47
|
+
export function sortEntriesByKey<T>(entries: readonly (readonly [string, T])[]): [string, T][] {
|
|
48
|
+
return entries
|
|
49
|
+
.map(([key, value]): [string, T] => [key, value])
|
|
50
|
+
.sort(([left], [right]) => ALPHABETIZE_COLLATOR.compare(left, right));
|
|
51
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { IrPropertyName } from "./nodes.js";
|
|
2
|
+
|
|
3
|
+
/** A name that can be written without quotes. */
|
|
4
|
+
export const JS_PROPERTY_INDEX_RE = /^[A-Za-z_$][A-Za-z_$0-9]*$/;
|
|
5
|
+
|
|
6
|
+
function isNonNegativeNumberText(index: string): boolean {
|
|
7
|
+
return String(Number(index)) === index && index[0] !== "-";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Choose how a property key is written, following the original `tsPropertyIndex`: non-negative
|
|
12
|
+
* numbers (and strings that are exactly such a number) unquoted, valid identifiers unquoted,
|
|
13
|
+
* everything else as a quoted string. Negative numbers become strings because `-1` is not a valid
|
|
14
|
+
* property key.
|
|
15
|
+
*/
|
|
16
|
+
export function toPropertyName(index: string | number): IrPropertyName {
|
|
17
|
+
if (typeof index === "number") {
|
|
18
|
+
return index < 0
|
|
19
|
+
? { kind: "string", value: String(index) }
|
|
20
|
+
: { kind: "number", text: String(index) };
|
|
21
|
+
}
|
|
22
|
+
if (isNonNegativeNumberText(index)) {
|
|
23
|
+
return { kind: "number", text: index };
|
|
24
|
+
}
|
|
25
|
+
return JS_PROPERTY_INDEX_RE.test(index)
|
|
26
|
+
? { kind: "identifier", text: index }
|
|
27
|
+
: { kind: "string", value: index };
|
|
28
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escapes for document text that the transformer writes into raw type text (threat model,
|
|
3
|
+
* docs/security/threat-model.md). Without them, a name or path from the document could end the
|
|
4
|
+
* literal early and add its own code to the generated file. Only the characters that would end or
|
|
5
|
+
* change the literal are escaped, so output for every other name stays byte-identical.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Line terminators end a single-quoted string; TypeScript reads U+2028 and U+2029 as such too. */
|
|
9
|
+
const SINGLE_QUOTED_ESCAPES: ReadonlyMap<string, string> = new Map([
|
|
10
|
+
["\\", "\\\\"],
|
|
11
|
+
["'", "\\'"],
|
|
12
|
+
["\n", "\\n"],
|
|
13
|
+
["\r", "\\r"],
|
|
14
|
+
["\u2028", "\\u2028"],
|
|
15
|
+
["\u2029", "\\u2029"],
|
|
16
|
+
]);
|
|
17
|
+
const SINGLE_QUOTED_SPECIAL_RE = /[\\'\n\r\u2028\u2029]/g;
|
|
18
|
+
|
|
19
|
+
/** The text between the quotes of a single-quoted string literal with this value. */
|
|
20
|
+
export function escapeSingleQuotedText(value: string): string {
|
|
21
|
+
return value.replace(SINGLE_QUOTED_SPECIAL_RE, (char) => SINGLE_QUOTED_ESCAPES.get(char) ?? char);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A backslash, a backtick, or the `${` that would start a placeholder. A raw carriage return is
|
|
26
|
+
* read as a line feed inside a template literal, so it is written as an escape.
|
|
27
|
+
*/
|
|
28
|
+
const TEMPLATE_SPECIAL_RE = /\\|`|\$\{|\r/g;
|
|
29
|
+
|
|
30
|
+
function escapeTemplateSpecial(special: string): string {
|
|
31
|
+
return special === "\r" ? "\\r" : `\\${special}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Template literal text (between placeholders) that reads back as exactly this value. */
|
|
35
|
+
export function escapeTemplateText(value: string): string {
|
|
36
|
+
return value.replace(TEMPLATE_SPECIAL_RE, escapeTemplateSpecial);
|
|
37
|
+
}
|