openapi-typesafe 1.0.0-rc.3 → 1.0.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1831 -0
- package/dist/adapters/node-file-system/file-claims.cjs +105 -0
- package/dist/adapters/node-file-system/file-claims.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-claims.mjs +95 -0
- package/dist/adapters/node-file-system/file-claims.mjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.cjs +82 -0
- package/dist/adapters/node-file-system/file-identity.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.mjs +74 -0
- package/dist/adapters/node-file-system/file-identity.mjs.map +1 -0
- package/dist/adapters/node-file-system/node-file-system.cjs +90 -14
- package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
- package/dist/adapters/node-file-system/node-file-system.mjs +90 -14
- package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +75 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +72 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs +2 -2
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs.map +1 -1
- package/dist/adapters/redocly-loader/loaded-documents.cjs +28 -0
- package/dist/adapters/redocly-loader/loaded-documents.cjs.map +1 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs +21 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +14 -15
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +12 -13
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +31 -3
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +31 -3
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.cjs +2 -2
- package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.mjs +3 -3
- package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-body-limit.cjs +50 -0
- package/dist/adapters/redocly-loader/remote-body-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs +48 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-fetch.cjs +35 -6
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +35 -6
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.cjs +47 -0
- package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs +44 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-load-errors.cjs +32 -8
- package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-load-errors.mjs +32 -9
- package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.cjs +11 -7
- package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.mjs +12 -8
- package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.cjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.mjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.cjs +6 -4
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.mjs +6 -4
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
- package/dist/api/default-ports.cjs +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-run.cjs +2 -2
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +2 -2
- 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 +8 -4
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +8 -5
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/schema-callbacks.cjs +36 -12
- package/dist/api/schema-callbacks.cjs.map +1 -1
- package/dist/api/schema-callbacks.mjs +36 -12
- package/dist/api/schema-callbacks.mjs.map +1 -1
- package/dist/api/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 +40 -10
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +41 -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/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 +4 -1
- package/dist/application/transform/document/document.cjs.map +1 -1
- package/dist/application/transform/document/document.mjs +3 -2
- package/dist/application/transform/document/document.mjs.map +1 -1
- package/dist/application/transform/document/enum-names-given-back.cjs +62 -0
- package/dist/application/transform/document/enum-names-given-back.cjs.map +1 -0
- package/dist/application/transform/document/enum-names-given-back.mjs +58 -0
- package/dist/application/transform/document/enum-names-given-back.mjs.map +1 -0
- package/dist/application/transform/document/global-type-references.cjs +1 -0
- package/dist/application/transform/document/global-type-references.cjs.map +1 -1
- package/dist/application/transform/document/global-type-references.mjs +1 -1
- package/dist/application/transform/document/global-type-references.mjs.map +1 -1
- package/dist/application/transform/document/media-type.cjs +2 -2
- package/dist/application/transform/document/media-type.cjs.map +1 -1
- package/dist/application/transform/document/media-type.mjs +3 -3
- package/dist/application/transform/document/media-type.mjs.map +1 -1
- package/dist/application/transform/document/operation-keys-written.cjs +26 -0
- package/dist/application/transform/document/operation-keys-written.cjs.map +1 -0
- package/dist/application/transform/document/operation-keys-written.mjs +24 -0
- package/dist/application/transform/document/operation-keys-written.mjs.map +1 -0
- package/dist/application/transform/document/operation.cjs +1 -1
- package/dist/application/transform/document/operation.cjs.map +1 -1
- package/dist/application/transform/document/operation.mjs +2 -2
- package/dist/application/transform/document/operation.mjs.map +1 -1
- package/dist/application/transform/document/parameter-entries.cjs +34 -0
- package/dist/application/transform/document/parameter-entries.cjs.map +1 -0
- package/dist/application/transform/document/parameter-entries.mjs +30 -0
- package/dist/application/transform/document/parameter-entries.mjs.map +1 -0
- package/dist/application/transform/document/parameter.cjs +12 -4
- package/dist/application/transform/document/parameter.cjs.map +1 -1
- package/dist/application/transform/document/parameter.mjs +13 -5
- package/dist/application/transform/document/parameter.mjs.map +1 -1
- package/dist/application/transform/document/parameters.cjs +6 -29
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +6 -29
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/path-item.cjs +11 -14
- package/dist/application/transform/document/path-item.cjs.map +1 -1
- package/dist/application/transform/document/path-item.mjs +12 -16
- package/dist/application/transform/document/path-item.mjs.map +1 -1
- package/dist/application/transform/document/paths-enum.cjs +1 -0
- package/dist/application/transform/document/paths-enum.cjs.map +1 -1
- package/dist/application/transform/document/paths-enum.mjs +1 -1
- package/dist/application/transform/document/paths-enum.mjs.map +1 -1
- package/dist/application/transform/document/paths.cjs +5 -1
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +6 -2
- package/dist/application/transform/document/paths.mjs.map +1 -1
- package/dist/application/transform/document/referenced-parameter.cjs +80 -0
- package/dist/application/transform/document/referenced-parameter.cjs.map +1 -0
- package/dist/application/transform/document/referenced-parameter.mjs +78 -0
- package/dist/application/transform/document/referenced-parameter.mjs.map +1 -0
- package/dist/application/transform/document/request-body.cjs +1 -1
- package/dist/application/transform/document/request-body.cjs.map +1 -1
- package/dist/application/transform/document/request-body.mjs +2 -2
- package/dist/application/transform/document/request-body.mjs.map +1 -1
- package/dist/application/transform/document/response.cjs +2 -2
- package/dist/application/transform/document/response.cjs.map +1 -1
- package/dist/application/transform/document/response.mjs +3 -3
- package/dist/application/transform/document/response.mjs.map +1 -1
- package/dist/application/transform/document/responses.cjs +1 -1
- package/dist/application/transform/document/responses.cjs.map +1 -1
- package/dist/application/transform/document/responses.mjs +2 -2
- package/dist/application/transform/document/responses.mjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.cjs +8 -23
- package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.mjs +8 -24
- package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
- package/dist/application/transform/document/type-resolution.cjs +3 -1
- package/dist/application/transform/document/type-resolution.cjs.map +1 -1
- package/dist/application/transform/document/type-resolution.mjs +3 -1
- package/dist/application/transform/document/type-resolution.mjs.map +1 -1
- package/dist/application/transform/document/webhooks.cjs +1 -1
- package/dist/application/transform/document/webhooks.cjs.map +1 -1
- package/dist/application/transform/document/webhooks.mjs +2 -2
- package/dist/application/transform/document/webhooks.mjs.map +1 -1
- package/dist/application/transform/footer/document-footer.cjs +10 -2
- package/dist/application/transform/footer/document-footer.cjs.map +1 -1
- package/dist/application/transform/footer/document-footer.mjs +10 -2
- package/dist/application/transform/footer/document-footer.mjs.map +1 -1
- package/dist/application/transform/footer/enum-name-claims.cjs +48 -0
- package/dist/application/transform/footer/enum-name-claims.cjs.map +1 -0
- package/dist/application/transform/footer/enum-name-claims.mjs +46 -0
- package/dist/application/transform/footer/enum-name-claims.mjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.cjs +23 -0
- package/dist/application/transform/footer/operation-keys.cjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.mjs +21 -0
- package/dist/application/transform/footer/operation-keys.mjs.map +1 -0
- package/dist/application/transform/footer/type-evaluation.cjs +4 -4
- package/dist/application/transform/footer/type-evaluation.cjs.map +1 -1
- package/dist/application/transform/footer/type-evaluation.mjs +4 -4
- package/dist/application/transform/footer/type-evaluation.mjs.map +1 -1
- package/dist/application/transform/helper-types.cjs +1 -1
- package/dist/application/transform/helper-types.cjs.map +1 -1
- package/dist/application/transform/helper-types.mjs +1 -1
- package/dist/application/transform/helper-types.mjs.map +1 -1
- package/dist/application/transform/numbered-names.cjs +9 -0
- package/dist/application/transform/numbered-names.cjs.map +1 -1
- package/dist/application/transform/numbered-names.mjs +9 -1
- package/dist/application/transform/numbered-names.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs +2 -2
- package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
- package/dist/application/transform/ref-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/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/object-type.cjs +3 -3
- package/dist/application/transform/schema/object-type.cjs.map +1 -1
- package/dist/application/transform/schema/object-type.mjs +4 -4
- package/dist/application/transform/schema/object-type.mjs.map +1 -1
- package/dist/application/transform/schema/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 +4 -2
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.mjs +4 -2
- package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
- package/dist/application/transform/schema-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-settings.cjs +62 -6
- package/dist/cli/api-settings.cjs.map +1 -1
- package/dist/cli/api-settings.mjs +60 -7
- package/dist/cli/api-settings.mjs.map +1 -1
- package/dist/cli/api-writes.cjs +72 -0
- package/dist/cli/api-writes.cjs.map +1 -0
- package/dist/cli/api-writes.mjs +69 -0
- package/dist/cli/api-writes.mjs.map +1 -0
- package/dist/cli/cli-errors.cjs +12 -1
- package/dist/cli/cli-errors.cjs.map +1 -1
- package/dist/cli/cli-errors.mjs +12 -1
- package/dist/cli/cli-errors.mjs.map +1 -1
- package/dist/cli/cli-output.cjs +106 -1
- package/dist/cli/cli-output.cjs.map +1 -1
- package/dist/cli/cli-output.mjs +99 -2
- package/dist/cli/cli-output.mjs.map +1 -1
- package/dist/cli/main.cjs +5 -1
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.mjs +6 -2
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +82 -36
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +85 -39
- package/dist/cli/redocly-apis.mjs.map +1 -1
- package/dist/cli/run-cli.cjs +13 -7
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +14 -8
- package/dist/cli/run-cli.mjs.map +1 -1
- package/dist/domain/append-all.cjs +10 -0
- package/dist/domain/append-all.cjs.map +1 -0
- package/dist/domain/append-all.mjs +8 -0
- package/dist/domain/append-all.mjs.map +1 -0
- package/dist/domain/cause-secrets.cjs +37 -0
- package/dist/domain/cause-secrets.cjs.map +1 -0
- package/dist/domain/cause-secrets.mjs +35 -0
- package/dist/domain/cause-secrets.mjs.map +1 -0
- package/dist/domain/errors.cjs +9 -3
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +9 -3
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/ir/identifier-text.cjs.map +1 -1
- package/dist/domain/ir/identifier-text.mjs +1 -1
- package/dist/domain/ir/identifier-text.mjs.map +1 -1
- package/dist/domain/ir/ir-shape.cjs +187 -0
- package/dist/domain/ir/ir-shape.cjs.map +1 -0
- package/dist/domain/ir/ir-shape.mjs +184 -0
- package/dist/domain/ir/ir-shape.mjs.map +1 -0
- package/dist/domain/ir/newer-identifier-ranges.cjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.cjs.map +1 -1
- package/dist/domain/ir/newer-identifier-ranges.mjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.mjs.map +1 -1
- package/dist/domain/openapi/alias-expansion.cjs +3 -1
- package/dist/domain/openapi/alias-expansion.cjs.map +1 -1
- package/dist/domain/openapi/alias-expansion.mjs +3 -1
- package/dist/domain/openapi/alias-expansion.mjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.cjs +3 -3
- package/dist/domain/openapi/discriminated-union.cjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.mjs +4 -4
- package/dist/domain/openapi/discriminated-union.mjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.cjs +10 -6
- package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.mjs +11 -7
- package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -1
- package/dist/domain/openapi/json-pointer.cjs +43 -1
- package/dist/domain/openapi/json-pointer.cjs.map +1 -1
- package/dist/domain/openapi/json-pointer.mjs +40 -2
- package/dist/domain/openapi/json-pointer.mjs.map +1 -1
- package/dist/domain/openapi/schema-dialect.cjs +15 -0
- package/dist/domain/openapi/schema-dialect.cjs.map +1 -0
- package/dist/domain/openapi/schema-dialect.mjs +12 -0
- package/dist/domain/openapi/schema-dialect.mjs.map +1 -0
- package/dist/domain/openapi/unsupported-features.cjs +1 -1
- package/dist/domain/openapi/unsupported-features.cjs.map +1 -1
- package/dist/domain/openapi/unsupported-features.mjs +2 -2
- package/dist/domain/openapi/unsupported-features.mjs.map +1 -1
- package/dist/domain/output-fixes.cjs +14 -0
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +14 -0
- package/dist/domain/output-fixes.mjs.map +1 -1
- package/dist/domain/url-secrets.cjs +48 -0
- package/dist/domain/url-secrets.cjs.map +1 -0
- package/dist/domain/url-secrets.mjs +45 -0
- package/dist/domain/url-secrets.mjs.map +1 -0
- package/dist/index.d.cts +22 -4
- package/dist/index.d.mts +22 -4
- package/dist/index.d.ts +22 -4
- 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 +145 -18
- package/src/adapters/redocly-loader/bundled-mapping-copies.ts +95 -0
- package/src/adapters/redocly-loader/bundled-ref-repair.ts +2 -2
- package/src/adapters/redocly-loader/loaded-documents.ts +46 -0
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +18 -24
- package/src/adapters/redocly-loader/ref-access.ts +37 -3
- package/src/adapters/redocly-loader/ref-holders.ts +3 -3
- package/src/adapters/redocly-loader/remote-body-limit.ts +66 -0
- package/src/adapters/redocly-loader/remote-fetch.ts +74 -11
- package/src/adapters/redocly-loader/remote-node-limit.ts +62 -0
- package/src/adapters/redocly-loader/schema-load-errors.ts +52 -13
- package/src/adapters/redocly-loader/schema-source.ts +20 -8
- package/src/adapters/redocly-loader/unsupported-keys.ts +3 -7
- package/src/adapters/terminal-logger/terminal-logger.ts +10 -5
- package/src/api/default-ports.ts +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-run.ts +4 -3
- package/src/api/legacy-utils.ts +5 -1
- package/src/api/openapi-ts.ts +20 -5
- 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 +64 -12
- package/src/application/ports/file-system.ts +39 -0
- package/src/application/ports/schema-loader.ts +11 -1
- package/src/application/print/text-writer.ts +10 -3
- package/src/application/stack-overflow.ts +9 -5
- package/src/application/transform/document/components.ts +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 +4 -3
- package/src/application/transform/document/enum-names-given-back.ts +91 -0
- package/src/application/transform/document/global-type-references.ts +1 -1
- package/src/application/transform/document/media-type.ts +4 -3
- package/src/application/transform/document/operation-keys-written.ts +27 -0
- package/src/application/transform/document/operation.ts +2 -2
- package/src/application/transform/document/parameter-entries.ts +70 -0
- package/src/application/transform/document/parameter.ts +21 -9
- package/src/application/transform/document/parameters.ts +11 -56
- package/src/application/transform/document/path-item.ts +13 -31
- package/src/application/transform/document/paths-enum.ts +1 -1
- package/src/application/transform/document/paths.ts +6 -2
- package/src/application/transform/document/referenced-parameter.ts +146 -0
- package/src/application/transform/document/request-body.ts +2 -2
- package/src/application/transform/document/response.ts +3 -3
- package/src/application/transform/document/responses.ts +2 -2
- package/src/application/transform/document/root-type-aliases.ts +17 -38
- package/src/application/transform/document/type-resolution.ts +2 -1
- package/src/application/transform/document/webhooks.ts +2 -2
- package/src/application/transform/footer/document-footer.ts +18 -1
- package/src/application/transform/footer/enum-name-claims.ts +62 -0
- package/src/application/transform/footer/operation-keys.ts +28 -0
- package/src/application/transform/footer/type-evaluation.ts +4 -4
- package/src/application/transform/helper-types.ts +6 -5
- package/src/application/transform/numbered-names.ts +15 -0
- package/src/application/transform/ref-pointer/generated-location.ts +2 -2
- package/src/application/transform/ref-type.ts +2 -1
- 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/object-type.ts +4 -4
- 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 +4 -2
- package/src/application/transform/schema-comment.ts +5 -1
- package/src/application/transform/transform-context.ts +5 -0
- package/src/cli/api-settings.ts +82 -7
- package/src/cli/api-writes.ts +117 -0
- package/src/cli/cli-dependencies.ts +21 -4
- package/src/cli/cli-errors.ts +20 -1
- package/src/cli/cli-output.ts +186 -7
- package/src/cli/main.ts +6 -3
- package/src/cli/redocly-apis.ts +153 -48
- package/src/cli/run-cli.ts +37 -8
- package/src/domain/append-all.ts +10 -0
- package/src/domain/cause-secrets.ts +52 -0
- package/src/domain/errors.ts +14 -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/openapi/alias-expansion.ts +4 -1
- package/src/domain/openapi/discriminated-union.ts +6 -4
- package/src/domain/openapi/discriminator-conflicts.ts +21 -7
- package/src/domain/openapi/document-object.ts +2 -0
- package/src/domain/openapi/json-pointer.ts +96 -7
- package/src/domain/openapi/schema-dialect.ts +22 -0
- package/src/domain/openapi/unsupported-features.ts +2 -2
- package/src/domain/output-fixes.ts +21 -2
- package/src/domain/url-secrets.ts +72 -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
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const constructors = require('../../../domain/ir/constructors.cjs');
|
|
4
4
|
const rawTextEscapes = require('../../../domain/ir/raw-text-escapes.cjs');
|
|
5
|
+
const numberedNames = require('../numbered-names.cjs');
|
|
6
|
+
const declaredTypeNames = require('./declared-type-names.cjs');
|
|
5
7
|
const globalTypeReferences = require('./global-type-references.cjs');
|
|
6
8
|
|
|
7
9
|
const REFERENCE_PREFIX = "components['";
|
|
@@ -19,16 +21,6 @@ function rootTypeAlias(name, kind, item) {
|
|
|
19
21
|
function isRootTypeAlias(declaration) {
|
|
20
22
|
return declaration.kind === "typeAlias" && declaration.type.kind === "raw" && declaration.type.text.startsWith(REFERENCE_PREFIX);
|
|
21
23
|
}
|
|
22
|
-
function footerTypeNames(declarations) {
|
|
23
|
-
return new Set(
|
|
24
|
-
declarations.flatMap((declaration) => {
|
|
25
|
-
if (declaration.kind === "enum") {
|
|
26
|
-
return [declaration.name];
|
|
27
|
-
}
|
|
28
|
-
return declaration.kind === "rawDeclaration" && declaration.name !== void 0 ? [declaration.name] : [];
|
|
29
|
-
})
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
24
|
function declaredNames(declarations) {
|
|
33
25
|
return new Set(
|
|
34
26
|
declarations.flatMap(
|
|
@@ -36,19 +28,11 @@ function declaredNames(declarations) {
|
|
|
36
28
|
)
|
|
37
29
|
);
|
|
38
30
|
}
|
|
39
|
-
function freeName(name, taken) {
|
|
40
|
-
let candidate = `${name}_2`;
|
|
41
|
-
for (let counter = 3; taken.has(candidate); counter++) {
|
|
42
|
-
candidate = `${name}_${counter}`;
|
|
43
|
-
}
|
|
44
|
-
return candidate;
|
|
45
|
-
}
|
|
46
31
|
function renameTakenAliases(body, footer, closing = []) {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const taken = declaredNames([...body, ...footer, ...closing]);
|
|
32
|
+
const all = [...body, ...footer, ...closing];
|
|
33
|
+
const others = all.filter((declaration) => !isRootTypeAlias(declaration));
|
|
34
|
+
const reserved = /* @__PURE__ */ new Set([...declaredTypeNames.typeNamesDeclaredBy(others), ...globalTypeReferences.globalTypeReferences(all)]);
|
|
35
|
+
const taken = /* @__PURE__ */ new Set([...declaredNames(all), ...declaredTypeNames.typeNamesDeclaredBy(all)]);
|
|
52
36
|
const aliasNames = /* @__PURE__ */ new Set();
|
|
53
37
|
return body.map((declaration) => {
|
|
54
38
|
if (!isRootTypeAlias(declaration)) {
|
|
@@ -59,12 +43,13 @@ function renameTakenAliases(body, footer, closing = []) {
|
|
|
59
43
|
if (!isRepeated && !reserved.has(declaration.name)) {
|
|
60
44
|
return declaration;
|
|
61
45
|
}
|
|
62
|
-
const name =
|
|
46
|
+
const name = numberedNames.freeNumberedName(declaration.name, taken);
|
|
63
47
|
taken.add(name);
|
|
64
48
|
return { ...declaration, name };
|
|
65
49
|
});
|
|
66
50
|
}
|
|
67
51
|
|
|
52
|
+
exports.isRootTypeAlias = isRootTypeAlias;
|
|
68
53
|
exports.renameTakenAliases = renameTakenAliases;
|
|
69
54
|
exports.rootTypeAlias = rootTypeAlias;
|
|
70
55
|
//# sourceMappingURL=root-type-aliases.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root-type-aliases.cjs","sources":["../../../../src/application/transform/document/root-type-aliases.ts"],"sourcesContent":["import { irRaw } from \"../../../domain/ir/constructors.js\";\nimport type { IrDeclaration, IrTypeAliasDeclaration } from \"../../../domain/ir/nodes.js\";\nimport { escapeSingleQuotedText } from \"../../../domain/ir/raw-text-escapes.js\";\nimport type { ComponentKind } from \"../../../domain/openapi/components-object.js\";\nimport { globalTypeReferences } from \"./global-type-references.js\";\n\n/** The `--root-types` aliases: `export type Pet = components['schemas']['Pet'];`. */\n\nconst REFERENCE_PREFIX = \"components['\";\n\n/** The alias of one component. */\nexport function rootTypeAlias(\n name: string,\n kind: ComponentKind,\n item: string,\n): IrTypeAliasDeclaration {\n return {\n kind: \"typeAlias\",\n name,\n isExported: true,\n // The original writes the reference as text, with single quotes, and did not escape the\n // name: a quote in it could add code to the generated file (intentional fix).\n type: irRaw(`${REFERENCE_PREFIX}${kind}']['${escapeSingleQuotedText(item)}']`),\n comments: [],\n };\n}\n\
|
|
1
|
+
{"version":3,"file":"root-type-aliases.cjs","sources":["../../../../src/application/transform/document/root-type-aliases.ts"],"sourcesContent":["import { irRaw } from \"../../../domain/ir/constructors.js\";\nimport type { IrDeclaration, IrTypeAliasDeclaration } from \"../../../domain/ir/nodes.js\";\nimport { escapeSingleQuotedText } from \"../../../domain/ir/raw-text-escapes.js\";\nimport type { ComponentKind } from \"../../../domain/openapi/components-object.js\";\nimport { freeNumberedName } from \"../numbered-names.js\";\nimport { typeNamesDeclaredBy } from \"./declared-type-names.js\";\nimport { globalTypeReferences } from \"./global-type-references.js\";\n\n/** The `--root-types` aliases: `export type Pet = components['schemas']['Pet'];`. */\n\nconst REFERENCE_PREFIX = \"components['\";\n\n/** The alias of one component. */\nexport function rootTypeAlias(\n name: string,\n kind: ComponentKind,\n item: string,\n): IrTypeAliasDeclaration {\n return {\n kind: \"typeAlias\",\n name,\n isExported: true,\n // The original writes the reference as text, with single quotes, and did not escape the\n // name: a quote in it could add code to the generated file (intentional fix).\n type: irRaw(`${REFERENCE_PREFIX}${kind}']['${escapeSingleQuotedText(item)}']`),\n comments: [],\n };\n}\n\n/** Whether the declaration is a `--root-types` alias, which gives way to every other name. */\nexport function isRootTypeAlias(declaration: IrDeclaration): declaration is IrTypeAliasDeclaration {\n return (\n declaration.kind === \"typeAlias\" &&\n declaration.type.kind === \"raw\" &&\n declaration.type.text.startsWith(REFERENCE_PREFIX)\n );\n}\n\nfunction declaredNames(declarations: readonly IrDeclaration[]): Set<string> {\n return new Set(\n declarations.flatMap((declaration) =>\n \"name\" in declaration && declaration.name !== undefined ? [declaration.name] : [],\n ),\n );\n}\n\n/**\n * Rename each root alias whose name another declaration of the output also takes (an enum, a\n * helper type, the `--make-paths-enum` enum `ApiPaths`, a root interface, `--read-write-markers`\n * or `inject` types), or that shadows a TypeScript global type the output refers to (`Record` in\n * `Record<string, never>`), to the next free `Name_2`, `Name_3`, … (the suffix `--root-types` uses\n * for its own conflicts). The others and the globals keep their names, because the generated\n * types refer to them. Before, the output did not compile (enums: upstream #2099, #2341, #2206;\n * helpers: a schema named `WithRequired`, roadmap R11; globals: TS2315; `ApiPaths`: TS2567).\n * Other declarations are returned unchanged.\n *\n * With the `root-type-numbering` fix (ADR-021, roadmap R13, backlog 30) the body also holds the\n * aliases a later schema of one exported name took the name from, after the other aliases and\n * under that same name. Each gets the next free number in body order, after the alias that kept\n * the name got its own: so the fix only adds exports, and every other alias keeps the name it has\n * without the fix.\n */\nexport function renameTakenAliases<T extends IrDeclaration>(\n body: readonly T[],\n footer: readonly IrDeclaration[],\n closing: readonly IrDeclaration[] = [],\n): T[] {\n const all = [...body, ...footer, ...closing];\n const others = all.filter((declaration) => !isRootTypeAlias(declaration));\n const reserved = new Set([...typeNamesDeclaredBy(others), ...globalTypeReferences(all)]);\n const taken = new Set([...declaredNames(all), ...typeNamesDeclaredBy(all)]);\n const aliasNames = new Set<string>();\n return body.map((declaration) => {\n if (!isRootTypeAlias(declaration)) {\n return declaration;\n }\n const isRepeated = aliasNames.has(declaration.name);\n aliasNames.add(declaration.name);\n if (!isRepeated && !reserved.has(declaration.name)) {\n return declaration;\n }\n const name = freeNumberedName(declaration.name, taken);\n taken.add(name);\n return { ...declaration, name };\n });\n}\n"],"names":["irRaw","escapeSingleQuotedText","type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A,CAAqB,GAAG,CAAC,CAAC,CAAA;AACvF,EAAA,MAAM,KAAA,mBAAQ,IAAI,GAAA,CAAI,CAAC,GAAG,aAAA,CAAc,GAAG,CAAA,EAAG,GAAGD,qCAAA,CAAoB,GAAG,CAAC,CAAC,CAAA;AAC1E,EAAA,MAAM,UAAA,uBAAiB,GAAA,EAAY;AACnC,EAAA,OAAO,IAAA,CAAK,GAAA,CAAI,CAAC,WAAA,KAAgB;AAC/B,IAAA,IAAI,CAAC,eAAA,CAAgB,WAAW,CAAA,EAAG;AACjC,MAAA,OAAO,WAAA;AAAA,IACT;AACA,IAAA,MAAM,UAAA,GAAa,UAAA,CAAW,GAAA,CAAI,WAAA,CAAY,IAAI,CAAA;AAClD,IAAA,UAAA,CAAW,GAAA,CAAI,YAAY,IAAI,CAAA;AAC/B,IAAA,IAAI,CAAC,UAAA,IAAc,CAAC,SAAS,GAAA,CAAI,WAAA,CAAY,IAAI,CAAA,EAAG;AAClD,MAAA,OAAO,WAAA;AAAA,IACT;AACA,IAAA,MAAM,IAAA,GAAOE,8BAAA,CAAiB,WAAA,CAAY,IAAA,EAAM,KAAK,CAAA;AACrD,IAAA,KAAA,CAAM,IAAI,IAAI,CAAA;AACd,IAAA,OAAO,EAAE,GAAG,WAAA,EAAa,IAAA,EAAK;AAAA,EAChC,CAAC,CAAA;AACH;;;;"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { irRaw } from '../../../domain/ir/constructors.mjs';
|
|
2
2
|
import { escapeSingleQuotedText } from '../../../domain/ir/raw-text-escapes.mjs';
|
|
3
|
+
import { freeNumberedName } from '../numbered-names.mjs';
|
|
4
|
+
import { typeNamesDeclaredBy } from './declared-type-names.mjs';
|
|
3
5
|
import { globalTypeReferences } from './global-type-references.mjs';
|
|
4
6
|
|
|
5
7
|
const REFERENCE_PREFIX = "components['";
|
|
@@ -17,16 +19,6 @@ function rootTypeAlias(name, kind, item) {
|
|
|
17
19
|
function isRootTypeAlias(declaration) {
|
|
18
20
|
return declaration.kind === "typeAlias" && declaration.type.kind === "raw" && declaration.type.text.startsWith(REFERENCE_PREFIX);
|
|
19
21
|
}
|
|
20
|
-
function footerTypeNames(declarations) {
|
|
21
|
-
return new Set(
|
|
22
|
-
declarations.flatMap((declaration) => {
|
|
23
|
-
if (declaration.kind === "enum") {
|
|
24
|
-
return [declaration.name];
|
|
25
|
-
}
|
|
26
|
-
return declaration.kind === "rawDeclaration" && declaration.name !== void 0 ? [declaration.name] : [];
|
|
27
|
-
})
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
22
|
function declaredNames(declarations) {
|
|
31
23
|
return new Set(
|
|
32
24
|
declarations.flatMap(
|
|
@@ -34,19 +26,11 @@ function declaredNames(declarations) {
|
|
|
34
26
|
)
|
|
35
27
|
);
|
|
36
28
|
}
|
|
37
|
-
function freeName(name, taken) {
|
|
38
|
-
let candidate = `${name}_2`;
|
|
39
|
-
for (let counter = 3; taken.has(candidate); counter++) {
|
|
40
|
-
candidate = `${name}_${counter}`;
|
|
41
|
-
}
|
|
42
|
-
return candidate;
|
|
43
|
-
}
|
|
44
29
|
function renameTakenAliases(body, footer, closing = []) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const taken = declaredNames([...body, ...footer, ...closing]);
|
|
30
|
+
const all = [...body, ...footer, ...closing];
|
|
31
|
+
const others = all.filter((declaration) => !isRootTypeAlias(declaration));
|
|
32
|
+
const reserved = /* @__PURE__ */ new Set([...typeNamesDeclaredBy(others), ...globalTypeReferences(all)]);
|
|
33
|
+
const taken = /* @__PURE__ */ new Set([...declaredNames(all), ...typeNamesDeclaredBy(all)]);
|
|
50
34
|
const aliasNames = /* @__PURE__ */ new Set();
|
|
51
35
|
return body.map((declaration) => {
|
|
52
36
|
if (!isRootTypeAlias(declaration)) {
|
|
@@ -57,11 +41,11 @@ function renameTakenAliases(body, footer, closing = []) {
|
|
|
57
41
|
if (!isRepeated && !reserved.has(declaration.name)) {
|
|
58
42
|
return declaration;
|
|
59
43
|
}
|
|
60
|
-
const name =
|
|
44
|
+
const name = freeNumberedName(declaration.name, taken);
|
|
61
45
|
taken.add(name);
|
|
62
46
|
return { ...declaration, name };
|
|
63
47
|
});
|
|
64
48
|
}
|
|
65
49
|
|
|
66
|
-
export { renameTakenAliases, rootTypeAlias };
|
|
50
|
+
export { isRootTypeAlias, renameTakenAliases, rootTypeAlias };
|
|
67
51
|
//# sourceMappingURL=root-type-aliases.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root-type-aliases.mjs","sources":["../../../../src/application/transform/document/root-type-aliases.ts"],"sourcesContent":["import { irRaw } from \"../../../domain/ir/constructors.js\";\nimport type { IrDeclaration, IrTypeAliasDeclaration } from \"../../../domain/ir/nodes.js\";\nimport { escapeSingleQuotedText } from \"../../../domain/ir/raw-text-escapes.js\";\nimport type { ComponentKind } from \"../../../domain/openapi/components-object.js\";\nimport { globalTypeReferences } from \"./global-type-references.js\";\n\n/** The `--root-types` aliases: `export type Pet = components['schemas']['Pet'];`. */\n\nconst REFERENCE_PREFIX = \"components['\";\n\n/** The alias of one component. */\nexport function rootTypeAlias(\n name: string,\n kind: ComponentKind,\n item: string,\n): IrTypeAliasDeclaration {\n return {\n kind: \"typeAlias\",\n name,\n isExported: true,\n // The original writes the reference as text, with single quotes, and did not escape the\n // name: a quote in it could add code to the generated file (intentional fix).\n type: irRaw(`${REFERENCE_PREFIX}${kind}']['${escapeSingleQuotedText(item)}']`),\n comments: [],\n };\n}\n\
|
|
1
|
+
{"version":3,"file":"root-type-aliases.mjs","sources":["../../../../src/application/transform/document/root-type-aliases.ts"],"sourcesContent":["import { irRaw } from \"../../../domain/ir/constructors.js\";\nimport type { IrDeclaration, IrTypeAliasDeclaration } from \"../../../domain/ir/nodes.js\";\nimport { escapeSingleQuotedText } from \"../../../domain/ir/raw-text-escapes.js\";\nimport type { ComponentKind } from \"../../../domain/openapi/components-object.js\";\nimport { freeNumberedName } from \"../numbered-names.js\";\nimport { typeNamesDeclaredBy } from \"./declared-type-names.js\";\nimport { globalTypeReferences } from \"./global-type-references.js\";\n\n/** The `--root-types` aliases: `export type Pet = components['schemas']['Pet'];`. */\n\nconst REFERENCE_PREFIX = \"components['\";\n\n/** The alias of one component. */\nexport function rootTypeAlias(\n name: string,\n kind: ComponentKind,\n item: string,\n): IrTypeAliasDeclaration {\n return {\n kind: \"typeAlias\",\n name,\n isExported: true,\n // The original writes the reference as text, with single quotes, and did not escape the\n // name: a quote in it could add code to the generated file (intentional fix).\n type: irRaw(`${REFERENCE_PREFIX}${kind}']['${escapeSingleQuotedText(item)}']`),\n comments: [],\n };\n}\n\n/** Whether the declaration is a `--root-types` alias, which gives way to every other name. */\nexport function isRootTypeAlias(declaration: IrDeclaration): declaration is IrTypeAliasDeclaration {\n return (\n declaration.kind === \"typeAlias\" &&\n declaration.type.kind === \"raw\" &&\n declaration.type.text.startsWith(REFERENCE_PREFIX)\n );\n}\n\nfunction declaredNames(declarations: readonly IrDeclaration[]): Set<string> {\n return new Set(\n declarations.flatMap((declaration) =>\n \"name\" in declaration && declaration.name !== undefined ? [declaration.name] : [],\n ),\n );\n}\n\n/**\n * Rename each root alias whose name another declaration of the output also takes (an enum, a\n * helper type, the `--make-paths-enum` enum `ApiPaths`, a root interface, `--read-write-markers`\n * or `inject` types), or that shadows a TypeScript global type the output refers to (`Record` in\n * `Record<string, never>`), to the next free `Name_2`, `Name_3`, … (the suffix `--root-types` uses\n * for its own conflicts). The others and the globals keep their names, because the generated\n * types refer to them. Before, the output did not compile (enums: upstream #2099, #2341, #2206;\n * helpers: a schema named `WithRequired`, roadmap R11; globals: TS2315; `ApiPaths`: TS2567).\n * Other declarations are returned unchanged.\n *\n * With the `root-type-numbering` fix (ADR-021, roadmap R13, backlog 30) the body also holds the\n * aliases a later schema of one exported name took the name from, after the other aliases and\n * under that same name. Each gets the next free number in body order, after the alias that kept\n * the name got its own: so the fix only adds exports, and every other alias keeps the name it has\n * without the fix.\n */\nexport function renameTakenAliases<T extends IrDeclaration>(\n body: readonly T[],\n footer: readonly IrDeclaration[],\n closing: readonly IrDeclaration[] = [],\n): T[] {\n const all = [...body, ...footer, ...closing];\n const others = all.filter((declaration) => !isRootTypeAlias(declaration));\n const reserved = new Set([...typeNamesDeclaredBy(others), ...globalTypeReferences(all)]);\n const taken = new Set([...declaredNames(all), ...typeNamesDeclaredBy(all)]);\n const aliasNames = new Set<string>();\n return body.map((declaration) => {\n if (!isRootTypeAlias(declaration)) {\n return declaration;\n }\n const isRepeated = aliasNames.has(declaration.name);\n aliasNames.add(declaration.name);\n if (!isRepeated && !reserved.has(declaration.name)) {\n return declaration;\n }\n const name = freeNumberedName(declaration.name, taken);\n taken.add(name);\n return { ...declaration, name };\n });\n}\n"],"names":[],"mappings":";;;;;;AAUA,MAAM,gBAAA,GAAmB,cAAA;AAGlB,SAAS,aAAA,CACd,IAAA,EACA,IAAA,EACA,IAAA,EACwB;AACxB,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,WAAA;AAAA,IACN,IAAA;AAAA,IACA,UAAA,EAAY,IAAA;AAAA;AAAA;AAAA,IAGZ,IAAA,EAAM,KAAA,CAAM,CAAA,EAAG,gBAAgB,CAAA,EAAG,IAAI,CAAA,IAAA,EAAO,sBAAA,CAAuB,IAAI,CAAC,CAAA,EAAA,CAAI,CAAA;AAAA,IAC7E,UAAU;AAAC,GACb;AACF;AAGO,SAAS,gBAAgB,WAAA,EAAmE;AACjG,EAAA,OACE,WAAA,CAAY,IAAA,KAAS,WAAA,IACrB,WAAA,CAAY,IAAA,CAAK,IAAA,KAAS,KAAA,IAC1B,WAAA,CAAY,IAAA,CAAK,IAAA,CAAK,UAAA,CAAW,gBAAgB,CAAA;AAErD;AAEA,SAAS,cAAc,YAAA,EAAqD;AAC1E,EAAA,OAAO,IAAI,GAAA;AAAA,IACT,YAAA,CAAa,OAAA;AAAA,MAAQ,CAAC,WAAA,KACpB,MAAA,IAAU,WAAA,IAAe,WA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AAa,IAAA,EAAK;AAAA,EAChC,CAAC,CAAA;AACH;;"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const appendAll = require('../../../domain/append-all.cjs');
|
|
4
|
+
|
|
3
5
|
const UNDEFINED = { kind: "keyword", keyword: "undefined" };
|
|
4
6
|
function nameOf(member) {
|
|
5
7
|
return member.name.kind === "string" ? member.name.value : member.name.text;
|
|
@@ -117,7 +119,7 @@ class TypeResolution {
|
|
|
117
119
|
if (objects === null) {
|
|
118
120
|
return null;
|
|
119
121
|
}
|
|
120
|
-
|
|
122
|
+
appendAll.appendAll(parts, objects);
|
|
121
123
|
}
|
|
122
124
|
return parts;
|
|
123
125
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-resolution.cjs","sources":["../../../../src/application/transform/document/type-resolution.ts"],"sourcesContent":["import type {\n IrIndexSignature,\n IrMember,\n IrObjectType,\n IrPropertySignature,\n IrType,\n} from \"../../../domain/ir/nodes.js\";\nimport type { DeclaredTypeLookup } from \"./declared-types.js\";\n\n/**\n * The types the `--path-params-as-types` overlap check compares, as TypeScript sees them:\n * references followed to the declarations of the document, `T[\"key\"]` and `T[number]` read from\n * `T`, and an intersection of object types merged into one object.\n */\n\nconst UNDEFINED: IrType = { kind: \"keyword\", keyword: \"undefined\" };\n\nexport function nameOf(member: IrPropertySignature): string {\n return member.name.kind === \"string\" ? member.name.value : member.name.text;\n}\n\nexport function propertiesOf(type: IrObjectType): Map<string, IrPropertySignature> {\n const properties = type.members.filter(\n (member: IrMember): member is IrPropertySignature => member.kind === \"property\",\n );\n return new Map(properties.map((property) => [nameOf(property), property]));\n}\n\nexport function indexSignaturesOf(type: IrObjectType): IrIndexSignature[] {\n return type.members.filter(\n (member: IrMember): member is IrIndexSignature => member.kind === \"indexSignature\",\n );\n}\n\n/** The type read from a property: an optional one may be `undefined`. */\nexport function readType(property: IrPropertySignature): IrType {\n return property.isOptional ? { kind: \"union\", types: [property.type, UNDEFINED] } : property.type;\n}\n\n/**\n * `T[number]` for an array `T`, as the generator writes for an item of an array response: the\n * element type, readonly or not. A tuple's is the union of its elements, which is not modelled.\n */\nfunction arrayElement(type: IrType): IrType | null {\n const list = type.kind === \"readonly\" ? type.type : type;\n return list.kind === \"array\" ? list.element : null;\n}\n\n/** One property for two of the same name in an intersection. */\nfunction mergedProperty(\n first: IrPropertySignature,\n second: IrPropertySignature,\n): IrPropertySignature {\n return {\n ...first,\n type: { kind: \"intersection\", types: [first.type, second.type] },\n isOptional: first.isOptional && second.isOptional,\n isReadonly: first.isReadonly || second.isReadonly,\n };\n}\n\n/** Resolves types once each, for one comparison. */\nexport class TypeResolution {\n private readonly lookup: DeclaredTypeLookup;\n private readonly resolvedTypes = new Map<IrType, IrType>();\n\n constructor(lookup: DeclaredTypeLookup) {\n this.lookup = lookup;\n }\n\n /** The type a reference names, followed through references to references; computed once. */\n resolved(type: IrType): IrType {\n const known = this.resolvedTypes.get(type);\n if (known !== undefined) {\n return known;\n }\n // A type that reaches itself while it is resolved stays as it is written there.\n this.resolvedTypes.set(type, type);\n const seen = new Set<IrType>();\n let current = type;\n while (!seen.has(current)) {\n seen.add(current);\n const named = this.lookup(current) ?? this.indexedProperty(current);\n if (named === null) {\n break;\n }\n current = named;\n }\n const result = current.kind === \"intersection\" ? (this.merged(current) ?? current) : current;\n this.resolvedTypes.set(type, result);\n return result;\n }\n\n /**\n * `T[\"key\"]` read from the object type `T` resolves to, which the lookup does not do for an\n * object it reached through another lookup (`paths[\"/a/{id}\"][\"get\"]`). An optional property\n * reads as `T | undefined`; `T[number]` is the element of the array `T`.\n */\n private indexedProperty(type: IrType): IrType | null {\n if (type.kind !== \"indexedAccess\") {\n return null;\n }\n const { index } = type;\n if (index.kind === \"keyword\" && index.keyword === \"number\") {\n return arrayElement(this.resolved(type.object));\n }\n const object = this.resolved(type.object);\n if (index.kind !== \"stringLiteral\" || object.kind !== \"object\") {\n return null;\n }\n const property = propertiesOf(object).get(index.value);\n return property === undefined ? null : readType(property);\n }\n\n /**\n * An intersection of object types as the one object TypeScript makes of it: a property in\n * several parts has the intersection of their types, and is optional only when it is in each.\n * Null when a part is no object type.\n */\n private merged(type: IrType): IrObjectType | null {\n const parts = this.objectParts(type);\n if (parts === null) {\n return null;\n }\n const properties = new Map<string, IrPropertySignature>();\n const indexes: IrIndexSignature[] = [];\n for (const member of parts.flatMap((part) => part.members)) {\n if (member.kind === \"indexSignature\") {\n indexes.push(member);\n continue;\n }\n const name = nameOf(member);\n const other = properties.get(name);\n properties.set(name, other === undefined ? member : mergedProperty(other, member));\n }\n return { kind: \"object\", members: [...properties.values(), ...indexes] };\n }\n\n /**\n * The object types an intersection is made of, nested ones flattened; null for any other, and\n * for an intersection that contains itself, which TypeScript does not merge either.\n */\n private objectParts(\n type: IrType,\n visiting: ReadonlySet<IrType> = new Set(),\n ): IrObjectType[] | null {\n if (type.kind === \"object\") {\n return [type];\n }\n if (type.kind !== \"intersection\" || visiting.has(type)) {\n return null;\n }\n const parts: IrObjectType[] = [];\n for (const part of type.types) {\n const objects = this.objectParts(this.resolved(part), new Set([...visiting, type]));\n if (objects === null) {\n return null;\n }\n parts.push(...objects);\n }\n return parts;\n }\n}\n"],"names":[],"mappings":";;AAeA,MAAM,SAAA,GAAoB,EAAE,IAAA,EAAM,SAAA,EAAW,SAAS,WAAA,EAAY;AAE3D,SAAS,OAAO,MAAA,EAAqC;AAC1D,EAAA,OAAO,MAAA,CAAO,KAAK,IAAA,KAAS,QAAA,GAAW,OAAO,IAAA,CAAK,KAAA,GAAQ,OAAO,IAAA,CAAK,IAAA;AACzE;AAEO,SAAS,aAAa,IAAA,EAAsD;AACjF,EAAA,MAAM,UAAA,GAAa,KAAK,OAAA,CAAQ,MAAA;AAAA,IAC9B,CAAC,MAAA,KAAoD,MAAA,CAAO,IAAA,KAAS;AAAA,GACvE;AACA,EAAA,OAAO,IAAI,GAAA,CAAI,UAAA,CAAW,GAAA,CAAI,CAA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AAA,EACA,QAAA,mBAAgC,IAAI,KAAI,EACjB;AACvB,IAAA,IAAI,IAAA,CAAK,SAAS,QAAA,EAAU;AAC1B,MAAA,OAAO,CAAC,IAAI,CAAA;AAAA,IACd;AACA,IAAA,IAAI,KAAK,IAAA,KAAS,cAAA,IAAkB,QAAA,CAAS,GAAA,CAAI,IAAI,CAAA,EAAG;AACtD,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,MAAM,QAAwB,EAAC;AAC/B,IAAA,KAAA,MAAW,IAAA,IAAQ,KAAK,KAAA,EAAO;AAC7B,MAAA,MAAM,OAAA,GAAU,IAAA,CAAK,WAAA,CAAY,IAAA,CAAK,SAAS,IAAI,CAAA,kBAAG,IAAI,GAAA,CAAI,CAAC,GAAG,QAAA,EAAU,IAAI,CAAC,CAAC,CAAA;AAClF,MAAA,IAAI,YAAY,IAAA,EAAM;AACpB,QAAA,OAAO,IAAA;AAAA,MACT;AACA,MAAA,KAAA,CAAM,IAAA,CAAK,GAAG,OAAO,CAAA;AAAA,IACvB;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AACF;;;;;;"}
|
|
1
|
+
{"version":3,"file":"type-resolution.cjs","sources":["../../../../src/application/transform/document/type-resolution.ts"],"sourcesContent":["import { appendAll } from \"../../../domain/append-all.js\";\nimport type {\n IrIndexSignature,\n IrMember,\n IrObjectType,\n IrPropertySignature,\n IrType,\n} from \"../../../domain/ir/nodes.js\";\nimport type { DeclaredTypeLookup } from \"./declared-types.js\";\n\n/**\n * The types the `--path-params-as-types` overlap check compares, as TypeScript sees them:\n * references followed to the declarations of the document, `T[\"key\"]` and `T[number]` read from\n * `T`, and an intersection of object types merged into one object.\n */\n\nconst UNDEFINED: IrType = { kind: \"keyword\", keyword: \"undefined\" };\n\nexport function nameOf(member: IrPropertySignature): string {\n return member.name.kind === \"string\" ? member.name.value : member.name.text;\n}\n\nexport function propertiesOf(type: IrObjectType): Map<string, IrPropertySignature> {\n const properties = type.members.filter(\n (member: IrMember): member is IrPropertySignature => member.kind === \"property\",\n );\n return new Map(properties.map((property) => [nameOf(property), property]));\n}\n\nexport function indexSignaturesOf(type: IrObjectType): IrIndexSignature[] {\n return type.members.filter(\n (member: IrMember): member is IrIndexSignature => member.kind === \"indexSignature\",\n );\n}\n\n/** The type read from a property: an optional one may be `undefined`. */\nexport function readType(property: IrPropertySignature): IrType {\n return property.isOptional ? { kind: \"union\", types: [property.type, UNDEFINED] } : property.type;\n}\n\n/**\n * `T[number]` for an array `T`, as the generator writes for an item of an array response: the\n * element type, readonly or not. A tuple's is the union of its elements, which is not modelled.\n */\nfunction arrayElement(type: IrType): IrType | null {\n const list = type.kind === \"readonly\" ? type.type : type;\n return list.kind === \"array\" ? list.element : null;\n}\n\n/** One property for two of the same name in an intersection. */\nfunction mergedProperty(\n first: IrPropertySignature,\n second: IrPropertySignature,\n): IrPropertySignature {\n return {\n ...first,\n type: { kind: \"intersection\", types: [first.type, second.type] },\n isOptional: first.isOptional && second.isOptional,\n isReadonly: first.isReadonly || second.isReadonly,\n };\n}\n\n/** Resolves types once each, for one comparison. */\nexport class TypeResolution {\n private readonly lookup: DeclaredTypeLookup;\n private readonly resolvedTypes = new Map<IrType, IrType>();\n\n constructor(lookup: DeclaredTypeLookup) {\n this.lookup = lookup;\n }\n\n /** The type a reference names, followed through references to references; computed once. */\n resolved(type: IrType): IrType {\n const known = this.resolvedTypes.get(type);\n if (known !== undefined) {\n return known;\n }\n // A type that reaches itself while it is resolved stays as it is written there.\n this.resolvedTypes.set(type, type);\n const seen = new Set<IrType>();\n let current = type;\n while (!seen.has(current)) {\n seen.add(current);\n const named = this.lookup(current) ?? this.indexedProperty(current);\n if (named === null) {\n break;\n }\n current = named;\n }\n const result = current.kind === \"intersection\" ? (this.merged(current) ?? current) : current;\n this.resolvedTypes.set(type, result);\n return result;\n }\n\n /**\n * `T[\"key\"]` read from the object type `T` resolves to, which the lookup does not do for an\n * object it reached through another lookup (`paths[\"/a/{id}\"][\"get\"]`). An optional property\n * reads as `T | undefined`; `T[number]` is the element of the array `T`.\n */\n private indexedProperty(type: IrType): IrType | null {\n if (type.kind !== \"indexedAccess\") {\n return null;\n }\n const { index } = type;\n if (index.kind === \"keyword\" && index.keyword === \"number\") {\n return arrayElement(this.resolved(type.object));\n }\n const object = this.resolved(type.object);\n if (index.kind !== \"stringLiteral\" || object.kind !== \"object\") {\n return null;\n }\n const property = propertiesOf(object).get(index.value);\n return property === undefined ? null : readType(property);\n }\n\n /**\n * An intersection of object types as the one object TypeScript makes of it: a property in\n * several parts has the intersection of their types, and is optional only when it is in each.\n * Null when a part is no object type.\n */\n private merged(type: IrType): IrObjectType | null {\n const parts = this.objectParts(type);\n if (parts === null) {\n return null;\n }\n const properties = new Map<string, IrPropertySignature>();\n const indexes: IrIndexSignature[] = [];\n for (const member of parts.flatMap((part) => part.members)) {\n if (member.kind === \"indexSignature\") {\n indexes.push(member);\n continue;\n }\n const name = nameOf(member);\n const other = properties.get(name);\n properties.set(name, other === undefined ? member : mergedProperty(other, member));\n }\n return { kind: \"object\", members: [...properties.values(), ...indexes] };\n }\n\n /**\n * The object types an intersection is made of, nested ones flattened; null for any other, and\n * for an intersection that contains itself, which TypeScript does not merge either.\n */\n private objectParts(\n type: IrType,\n visiting: ReadonlySet<IrType> = new Set(),\n ): IrObjectType[] | null {\n if (type.kind === \"object\") {\n return [type];\n }\n if (type.kind !== \"intersection\" || visiting.has(type)) {\n return null;\n }\n const parts: IrObjectType[] = [];\n for (const part of type.types) {\n const objects = this.objectParts(this.resolved(part), new Set([...visiting, type]));\n if (objects === null) {\n return null;\n }\n appendAll(parts, objects);\n }\n return parts;\n }\n}\n"],"names":["appendAll"],"mappings":";;;;AAgBA,MAAM,SAAA,GAAoB,EAAE,IAAA,EAAM,SAAA,EAAW,SAAS,WAAA,EAAY;AAE3D,SAAS,OAAO,MAAA,EAAqC;AAC1D,EAAA,OAAO,MAAA,CAAO,KAAK,IAAA,KAAS,QAAA,GAAW,OAAO,IAAA,CAAK,KAA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AAA,GAAY,SAAS,cAAA,CAAe,KAAA,EAAO,MAAM,CAAC,CAAA;AAAA,IACnF;AACA,IAAA,OAAO,EAAE,IAAA,EAAM,QAAA,EAAU,OAAA,EAAS,CAAC,GAAG,UAAA,CAAW,MAAA,EAAO,EAAG,GAAG,OAAO,CAAA,EAAE;AAAA,EACzE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,WAAA,CACN,IAAA,EACA,QAAA,mBAAgC,IAAI,KAAI,EACjB;AACvB,IAAA,IAAI,IAAA,CAAK,SAAS,QAAA,EAAU;AAC1B,MAAA,OAAO,CAAC,IAAI,CAAA;AAAA,IACd;AACA,IAAA,IAAI,KAAK,IAAA,KAAS,cAAA,IAAkB,QAAA,CAAS,GAAA,CAAI,IAAI,CAAA,EAAG;AACtD,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,MAAM,QAAwB,EAAC;AAC/B,IAAA,KAAA,MAAW,IAAA,IAAQ,KAAK,KAAA,EAAO;AAC7B,MAAA,MAAM,OAAA,GAAU,IAAA,CAAK,WAAA,CAAY,IAAA,CAAK,SAAS,IAAI,CAAA,kBAAG,IAAI,GAAA,CAAI,CAAC,GAAG,QAAA,EAAU,IAAI,CAAC,CAAC,CAAA;AAClF,MAAA,IAAI,YAAY,IAAA,EAAM;AACpB,QAAA,OAAO,IAAA;AAAA,MACT;AACA,MAAAA,mBAAA,CAAU,OAAO,OAAO,CAAA;AAAA,IAC1B;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AACF;;;;;;"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { appendAll } from '../../../domain/append-all.mjs';
|
|
2
|
+
|
|
1
3
|
const UNDEFINED = { kind: "keyword", keyword: "undefined" };
|
|
2
4
|
function nameOf(member) {
|
|
3
5
|
return member.name.kind === "string" ? member.name.value : member.name.text;
|
|
@@ -115,7 +117,7 @@ class TypeResolution {
|
|
|
115
117
|
if (objects === null) {
|
|
116
118
|
return null;
|
|
117
119
|
}
|
|
118
|
-
parts
|
|
120
|
+
appendAll(parts, objects);
|
|
119
121
|
}
|
|
120
122
|
return parts;
|
|
121
123
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-resolution.mjs","sources":["../../../../src/application/transform/document/type-resolution.ts"],"sourcesContent":["import type {\n IrIndexSignature,\n IrMember,\n IrObjectType,\n IrPropertySignature,\n IrType,\n} from \"../../../domain/ir/nodes.js\";\nimport type { DeclaredTypeLookup } from \"./declared-types.js\";\n\n/**\n * The types the `--path-params-as-types` overlap check compares, as TypeScript sees them:\n * references followed to the declarations of the document, `T[\"key\"]` and `T[number]` read from\n * `T`, and an intersection of object types merged into one object.\n */\n\nconst UNDEFINED: IrType = { kind: \"keyword\", keyword: \"undefined\" };\n\nexport function nameOf(member: IrPropertySignature): string {\n return member.name.kind === \"string\" ? member.name.value : member.name.text;\n}\n\nexport function propertiesOf(type: IrObjectType): Map<string, IrPropertySignature> {\n const properties = type.members.filter(\n (member: IrMember): member is IrPropertySignature => member.kind === \"property\",\n );\n return new Map(properties.map((property) => [nameOf(property), property]));\n}\n\nexport function indexSignaturesOf(type: IrObjectType): IrIndexSignature[] {\n return type.members.filter(\n (member: IrMember): member is IrIndexSignature => member.kind === \"indexSignature\",\n );\n}\n\n/** The type read from a property: an optional one may be `undefined`. */\nexport function readType(property: IrPropertySignature): IrType {\n return property.isOptional ? { kind: \"union\", types: [property.type, UNDEFINED] } : property.type;\n}\n\n/**\n * `T[number]` for an array `T`, as the generator writes for an item of an array response: the\n * element type, readonly or not. A tuple's is the union of its elements, which is not modelled.\n */\nfunction arrayElement(type: IrType): IrType | null {\n const list = type.kind === \"readonly\" ? type.type : type;\n return list.kind === \"array\" ? list.element : null;\n}\n\n/** One property for two of the same name in an intersection. */\nfunction mergedProperty(\n first: IrPropertySignature,\n second: IrPropertySignature,\n): IrPropertySignature {\n return {\n ...first,\n type: { kind: \"intersection\", types: [first.type, second.type] },\n isOptional: first.isOptional && second.isOptional,\n isReadonly: first.isReadonly || second.isReadonly,\n };\n}\n\n/** Resolves types once each, for one comparison. */\nexport class TypeResolution {\n private readonly lookup: DeclaredTypeLookup;\n private readonly resolvedTypes = new Map<IrType, IrType>();\n\n constructor(lookup: DeclaredTypeLookup) {\n this.lookup = lookup;\n }\n\n /** The type a reference names, followed through references to references; computed once. */\n resolved(type: IrType): IrType {\n const known = this.resolvedTypes.get(type);\n if (known !== undefined) {\n return known;\n }\n // A type that reaches itself while it is resolved stays as it is written there.\n this.resolvedTypes.set(type, type);\n const seen = new Set<IrType>();\n let current = type;\n while (!seen.has(current)) {\n seen.add(current);\n const named = this.lookup(current) ?? this.indexedProperty(current);\n if (named === null) {\n break;\n }\n current = named;\n }\n const result = current.kind === \"intersection\" ? (this.merged(current) ?? current) : current;\n this.resolvedTypes.set(type, result);\n return result;\n }\n\n /**\n * `T[\"key\"]` read from the object type `T` resolves to, which the lookup does not do for an\n * object it reached through another lookup (`paths[\"/a/{id}\"][\"get\"]`). An optional property\n * reads as `T | undefined`; `T[number]` is the element of the array `T`.\n */\n private indexedProperty(type: IrType): IrType | null {\n if (type.kind !== \"indexedAccess\") {\n return null;\n }\n const { index } = type;\n if (index.kind === \"keyword\" && index.keyword === \"number\") {\n return arrayElement(this.resolved(type.object));\n }\n const object = this.resolved(type.object);\n if (index.kind !== \"stringLiteral\" || object.kind !== \"object\") {\n return null;\n }\n const property = propertiesOf(object).get(index.value);\n return property === undefined ? null : readType(property);\n }\n\n /**\n * An intersection of object types as the one object TypeScript makes of it: a property in\n * several parts has the intersection of their types, and is optional only when it is in each.\n * Null when a part is no object type.\n */\n private merged(type: IrType): IrObjectType | null {\n const parts = this.objectParts(type);\n if (parts === null) {\n return null;\n }\n const properties = new Map<string, IrPropertySignature>();\n const indexes: IrIndexSignature[] = [];\n for (const member of parts.flatMap((part) => part.members)) {\n if (member.kind === \"indexSignature\") {\n indexes.push(member);\n continue;\n }\n const name = nameOf(member);\n const other = properties.get(name);\n properties.set(name, other === undefined ? member : mergedProperty(other, member));\n }\n return { kind: \"object\", members: [...properties.values(), ...indexes] };\n }\n\n /**\n * The object types an intersection is made of, nested ones flattened; null for any other, and\n * for an intersection that contains itself, which TypeScript does not merge either.\n */\n private objectParts(\n type: IrType,\n visiting: ReadonlySet<IrType> = new Set(),\n ): IrObjectType[] | null {\n if (type.kind === \"object\") {\n return [type];\n }\n if (type.kind !== \"intersection\" || visiting.has(type)) {\n return null;\n }\n const parts: IrObjectType[] = [];\n for (const part of type.types) {\n const objects = this.objectParts(this.resolved(part), new Set([...visiting, type]));\n if (objects === null) {\n return null;\n }\n parts.push(...objects);\n }\n return parts;\n }\n}\n"],"names":[],"mappings":"AAeA,MAAM,SAAA,GAAoB,EAAE,IAAA,EAAM,SAAA,EAAW,SAAS,WAAA,EAAY;AAE3D,SAAS,OAAO,MAAA,EAAqC;AAC1D,EAAA,OAAO,MAAA,CAAO,KAAK,IAAA,KAAS,QAAA,GAAW,OAAO,IAAA,CAAK,KAAA,GAAQ,OAAO,IAAA,CAAK,IAAA;AACzE;AAEO,SAAS,aAAa,IAAA,EAAsD;AACjF,EAAA,MAAM,UAAA,GAAa,KAAK,OAAA,CAAQ,MAAA;AAAA,IAC9B,CAAC,MAAA,KAAoD,MAAA,CAAO,IAAA,KAAS;AAAA,GACvE;AACA,EAAA,OAAO,IAAI,GAAA,CAAI,UAAA,CAAW,GAAA,CAAI,CAAC,QAAA,KAAa,CAAC,MAAA,CAAO,QAAQ,CAAA,EAAG,QAAQ,CAAC,CAAC,CAAA;AAC3E;AAEO,SAAS,kBAAkB,IAAA,EAAwC;AACxE,EAAA,OAAO,KAAK,OAAA,CAAQ,MAAA;AAAA,IAClB,CAAC,MAAA,KAAiD,MAAA,CAAO,IAAA,KAAS;AAAA,GACpE;AACF;AAGO,SAAS,SAAS,QAAA,EAAuC;AAC9D,EAAA,OAAO,QAAA,CAAS,UAAA,GAAa,EAAE,IAAA,EAAM,OAAA,EAAS,KAAA,EAAO,CAAC,QAAA,CAAS,IAAA,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,GAAU,IAAA,CAAK,WAAA,CAAY,IAAA,CAAK,SAAS,IAAI,CAAA,kBAAG,IAAI,GAAA,CAAI,CAAC,GAAG,QAAA,EAAU,IAAI,CAAC,CAAC,CAAA;AAClF,MAAA,IAAI,YAAY,IAAA,EAAM;AACpB,QAAA,OAAO,IAAA;AAAA,MACT;AACA,MAAA,KAAA,CAAM,IAAA,CAAK,GAAG,OAAO,CAAA;AAAA,IACvB;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AACF;;"}
|
|
1
|
+
{"version":3,"file":"type-resolution.mjs","sources":["../../../../src/application/transform/document/type-resolution.ts"],"sourcesContent":["import { appendAll } from \"../../../domain/append-all.js\";\nimport type {\n IrIndexSignature,\n IrMember,\n IrObjectType,\n IrPropertySignature,\n IrType,\n} from \"../../../domain/ir/nodes.js\";\nimport type { DeclaredTypeLookup } from \"./declared-types.js\";\n\n/**\n * The types the `--path-params-as-types` overlap check compares, as TypeScript sees them:\n * references followed to the declarations of the document, `T[\"key\"]` and `T[number]` read from\n * `T`, and an intersection of object types merged into one object.\n */\n\nconst UNDEFINED: IrType = { kind: \"keyword\", keyword: \"undefined\" };\n\nexport function nameOf(member: IrPropertySignature): string {\n return member.name.kind === \"string\" ? member.name.value : member.name.text;\n}\n\nexport function propertiesOf(type: IrObjectType): Map<string, IrPropertySignature> {\n const properties = type.members.filter(\n (member: IrMember): member is IrPropertySignature => member.kind === \"property\",\n );\n return new Map(properties.map((property) => [nameOf(property), property]));\n}\n\nexport function indexSignaturesOf(type: IrObjectType): IrIndexSignature[] {\n return type.members.filter(\n (member: IrMember): member is IrIndexSignature => member.kind === \"indexSignature\",\n );\n}\n\n/** The type read from a property: an optional one may be `undefined`. */\nexport function readType(property: IrPropertySignature): IrType {\n return property.isOptional ? { kind: \"union\", types: [property.type, UNDEFINED] } : property.type;\n}\n\n/**\n * `T[number]` for an array `T`, as the generator writes for an item of an array response: the\n * element type, readonly or not. A tuple's is the union of its elements, which is not modelled.\n */\nfunction arrayElement(type: IrType): IrType | null {\n const list = type.kind === \"readonly\" ? type.type : type;\n return list.kind === \"array\" ? list.element : null;\n}\n\n/** One property for two of the same name in an intersection. */\nfunction mergedProperty(\n first: IrPropertySignature,\n second: IrPropertySignature,\n): IrPropertySignature {\n return {\n ...first,\n type: { kind: \"intersection\", types: [first.type, second.type] },\n isOptional: first.isOptional && second.isOptional,\n isReadonly: first.isReadonly || second.isReadonly,\n };\n}\n\n/** Resolves types once each, for one comparison. */\nexport class TypeResolution {\n private readonly lookup: DeclaredTypeLookup;\n private readonly resolvedTypes = new Map<IrType, IrType>();\n\n constructor(lookup: DeclaredTypeLookup) {\n this.lookup = lookup;\n }\n\n /** The type a reference names, followed through references to references; computed once. */\n resolved(type: IrType): IrType {\n const known = this.resolvedTypes.get(type);\n if (known !== undefined) {\n return known;\n }\n // A type that reaches itself while it is resolved stays as it is written there.\n this.resolvedTypes.set(type, type);\n const seen = new Set<IrType>();\n let current = type;\n while (!seen.has(current)) {\n seen.add(current);\n const named = this.lookup(current) ?? this.indexedProperty(current);\n if (named === null) {\n break;\n }\n current = named;\n }\n const result = current.kind === \"intersection\" ? (this.merged(current) ?? current) : current;\n this.resolvedTypes.set(type, result);\n return result;\n }\n\n /**\n * `T[\"key\"]` read from the object type `T` resolves to, which the lookup does not do for an\n * object it reached through another lookup (`paths[\"/a/{id}\"][\"get\"]`). An optional property\n * reads as `T | undefined`; `T[number]` is the element of the array `T`.\n */\n private indexedProperty(type: IrType): IrType | null {\n if (type.kind !== \"indexedAccess\") {\n return null;\n }\n const { index } = type;\n if (index.kind === \"keyword\" && index.keyword === \"number\") {\n return arrayElement(this.resolved(type.object));\n }\n const object = this.resolved(type.object);\n if (index.kind !== \"stringLiteral\" || object.kind !== \"object\") {\n return null;\n }\n const property = propertiesOf(object).get(index.value);\n return property === undefined ? null : readType(property);\n }\n\n /**\n * An intersection of object types as the one object TypeScript makes of it: a property in\n * several parts has the intersection of their types, and is optional only when it is in each.\n * Null when a part is no object type.\n */\n private merged(type: IrType): IrObjectType | null {\n const parts = this.objectParts(type);\n if (parts === null) {\n return null;\n }\n const properties = new Map<string, IrPropertySignature>();\n const indexes: IrIndexSignature[] = [];\n for (const member of parts.flatMap((part) => part.members)) {\n if (member.kind === \"indexSignature\") {\n indexes.push(member);\n continue;\n }\n const name = nameOf(member);\n const other = properties.get(name);\n properties.set(name, other === undefined ? member : mergedProperty(other, member));\n }\n return { kind: \"object\", members: [...properties.values(), ...indexes] };\n }\n\n /**\n * The object types an intersection is made of, nested ones flattened; null for any other, and\n * for an intersection that contains itself, which TypeScript does not merge either.\n */\n private objectParts(\n type: IrType,\n visiting: ReadonlySet<IrType> = new Set(),\n ): IrObjectType[] | null {\n if (type.kind === \"object\") {\n return [type];\n }\n if (type.kind !== \"intersection\" || visiting.has(type)) {\n return null;\n }\n const parts: IrObjectType[] = [];\n for (const part of type.types) {\n const objects = this.objectParts(this.resolved(part), new Set([...visiting, type]));\n if (objects === null) {\n return null;\n }\n appendAll(parts, objects);\n }\n return parts;\n }\n}\n"],"names":[],"mappings":";;AAgBA,MAAM,SAAA,GAAoB,EAAE,IAAA,EAAM,SAAA,EAAW,SAAS,WAAA,EAAY;AAE3D,SAAS,OAAO,MAAA,EAAqC;AAC1D,EAAA,OAAO,MAAA,CAAO,KAAK,IAAA,KAAS,QAAA,GAAW,OAAO,IAAA,CAAK,KAAA,GAAQ,OAAO,IAAA,CAAK,IAAA;AACzE;AAEO,SAAS,aAAa,IAAA,EAAsD;AACjF,EAAA,MAAM,UAAA,GAAa,KAAK,OAAA,CAAQ,MAAA;AAAA,IAC9B,CAAC,MAAA,KAAoD,MAAA,CAAO,IAAA,KAAS;AAAA,GACvE;AACA,EAAA,OAAO,IAAI,GAAA,CAAI,UAAA,CAAW,GAAA,CAAI,CAAC,QAAA,KAAa,CAAC,MAAA,CAAO,QAAQ,CAAA,EAAG,QAAQ,CAAC,CAAC,CAAA;AAC3E;AAEO,SAAS,kBAAkB,IAAA,EAAwC;AACxE,EAAA,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AA,IACd;AACA,IAAA,IAAI,KAAK,IAAA,KAAS,cAAA,IAAkB,QAAA,CAAS,GAAA,CAAI,IAAI,CAAA,EAAG;AACtD,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,MAAM,QAAwB,EAAC;AAC/B,IAAA,KAAA,MAAW,IAAA,IAAQ,KAAK,KAAA,EAAO;AAC7B,MAAA,MAAM,OAAA,GAAU,IAAA,CAAK,WAAA,CAAY,IAAA,CAAK,SAAS,IAAI,CAAA,kBAAG,IAAI,GAAA,CAAI,CAAC,GAAG,QAAA,EAAU,IAAI,CAAC,CAAC,CAAA;AAClF,MAAA,IAAI,YAAY,IAAA,EAAM;AACpB,QAAA,OAAO,IAAA;AAAA,MACT;AACA,MAAA,SAAA,CAAU,OAAO,OAAO,CAAA;AAAA,IAC1B;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AACF;;"}
|
|
@@ -8,7 +8,7 @@ const pathItem = require('./path-item.cjs');
|
|
|
8
8
|
|
|
9
9
|
function webhooksType(webhooks, context) {
|
|
10
10
|
const members = documentEntries.documentEntries(webhooks, context.options).map(([name, pathItem$1]) => {
|
|
11
|
-
const location = { path: jsonPointer.
|
|
11
|
+
const location = { path: jsonPointer.appendPointer(jsonPointer.ROOT_POINTER, ["webhooks", name]) };
|
|
12
12
|
const type = pathItem.pathItemType(pathItem$1, location, context);
|
|
13
13
|
return constructors.irProperty(propertyName.toPropertyName(name), type, { isReadonly: context.options.immutable });
|
|
14
14
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.cjs","sources":["../../../../src/application/transform/document/webhooks.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"webhooks.cjs","sources":["../../../../src/application/transform/document/webhooks.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport type { PathItemObject, PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { pathItemType } from \"./path-item.js\";\n\n/**\n * The `webhooks` interface body (OpenAPI 3.1 §4.8.1): one path item per webhook name. Unlike\n * `paths`, a `$ref` entry is read as a path item (so every method is `never`), as in the original,\n * and members carry no JSDoc.\n */\nexport function webhooksType(webhooks: PathsObject, context: TransformContext): IrType {\n const members = documentEntries(webhooks, context.options).map(([name, pathItem]) => {\n const location = { path: appendPointer(ROOT_POINTER, [\"webhooks\", name]) };\n const type = pathItemType(pathItem as PathItemObject, location, context);\n return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n"],"names":["documentEntries","pathItem","appendPointer","ROOT_POINTER","pathItemType","irProperty","toPropertyName","irObject"],"mappings":";;;;;;;;AAcO,SAAS,YAAA,CAAa,UAAuB,OAAA,EAAmC;AACrF,EAAA,MAAM,OAAA,GAAUA,+BAAA,CAAgB,QAAA,EAAU,OAAA,CAAQ,OAAO,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,IAAA,EAAMC,UAAQ,CAAA,KAAM;AACnF,IAAA,MAAM,QAAA,GAAW,EAAE,IAAA,EAAMC,yBAAA,CAAcC,0BAAc,CAAC,UAAA,EAAY,IAAI,CAAC,CAAA,EAAE;AACzE,IAAA,MAAM,IAAA,GAAOC,qBAAA,CAAaH,UAAA,EAA4B,QAAA,EAAU,OAAO,CAAA;AACvE,IAAA,OAAOI,uBAAA,CAAWC,2BAAA,CAAe,IAAI,CAAA,EAAG,IAAA,EAAM,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EACzF,CAAC,CAAA;AACD,EAAA,OAAOC,sBAAS,OAAO,CAAA;AACzB;;"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { irProperty, irObject } from '../../../domain/ir/constructors.mjs';
|
|
2
2
|
import { toPropertyName } from '../../../domain/ir/property-name.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { appendPointer, ROOT_POINTER } from '../../../domain/openapi/json-pointer.mjs';
|
|
4
4
|
import { documentEntries } from '../document-entries.mjs';
|
|
5
5
|
import { pathItemType } from './path-item.mjs';
|
|
6
6
|
|
|
7
7
|
function webhooksType(webhooks, context) {
|
|
8
8
|
const members = documentEntries(webhooks, context.options).map(([name, pathItem]) => {
|
|
9
|
-
const location = { path:
|
|
9
|
+
const location = { path: appendPointer(ROOT_POINTER, ["webhooks", name]) };
|
|
10
10
|
const type = pathItemType(pathItem, location, context);
|
|
11
11
|
return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });
|
|
12
12
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.mjs","sources":["../../../../src/application/transform/document/webhooks.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"webhooks.mjs","sources":["../../../../src/application/transform/document/webhooks.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport type { PathItemObject, PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { pathItemType } from \"./path-item.js\";\n\n/**\n * The `webhooks` interface body (OpenAPI 3.1 §4.8.1): one path item per webhook name. Unlike\n * `paths`, a `$ref` entry is read as a path item (so every method is `never`), as in the original,\n * and members carry no JSDoc.\n */\nexport function webhooksType(webhooks: PathsObject, context: TransformContext): IrType {\n const members = documentEntries(webhooks, context.options).map(([name, pathItem]) => {\n const location = { path: appendPointer(ROOT_POINTER, [\"webhooks\", name]) };\n const type = pathItemType(pathItem as PathItemObject, location, context);\n return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n"],"names":[],"mappings":";;;;;;AAcO,SAAS,YAAA,CAAa,UAAuB,OAAA,EAAmC;AACrF,EAAA,MAAM,OAAA,GAAU,eAAA,CAAgB,QAAA,EAAU,OAAA,CAAQ,OAAO,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,IAAA,EAAM,QAAQ,CAAA,KAAM;AACnF,IAAA,MAAM,QAAA,GAAW,EAAE,IAAA,EAAM,aAAA,CAAc,cAAc,CAAC,UAAA,EAAY,IAAI,CAAC,CAAA,EAAE;AACzE,IAAA,MAAM,IAAA,GAAO,YAAA,CAAa,QAAA,EAA4B,QAAA,EAAU,OAAO,CAAA;AACvE,IAAA,OAAO,UAAA,CAAW,cAAA,CAAe,IAAI,CAAA,EAAG,IAAA,EAAM,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EACzF,CAAC,CAAA;AACD,EAAA,OAAO,SAAS,OAAO,CAAA;AACzB;;"}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const constructors = require('../../../domain/ir/constructors.cjs');
|
|
4
4
|
const helperTypes = require('../helper-types.cjs');
|
|
5
|
+
const enumNameClaims = require('./enum-name-claims.cjs');
|
|
5
6
|
const enumNaming = require('./enum-naming.cjs');
|
|
7
|
+
const operationKeys = require('./operation-keys.cjs');
|
|
6
8
|
const sharedEnumNames = require('./shared-enum-names.cjs');
|
|
7
9
|
|
|
8
10
|
function dedupeKey(request) {
|
|
@@ -39,19 +41,22 @@ class RunFooter {
|
|
|
39
41
|
sink;
|
|
40
42
|
isDedupingEnums;
|
|
41
43
|
sharedNames;
|
|
42
|
-
|
|
44
|
+
names;
|
|
45
|
+
constructor(sink, isDedupingEnums, sharedNames = sharedEnumNames.FIRST_SCHEMA_NAMES, names = { enums: new enumNameClaims.EnumNameClaims(), operations: new operationKeys.OperationKeys() }) {
|
|
43
46
|
this.sink = sink;
|
|
44
47
|
this.isDedupingEnums = isDedupingEnums;
|
|
45
48
|
this.sharedNames = sharedNames;
|
|
49
|
+
this.names = names;
|
|
46
50
|
}
|
|
47
51
|
addEnum(request) {
|
|
48
52
|
const ownName = this.naming.enumName(request.name);
|
|
49
53
|
const key = this.isDedupingEnums ? dedupeKey(request) : null;
|
|
50
|
-
const
|
|
54
|
+
const sharedName = key === null ? ownName : this.sharedNames.nameOf(key, ownName, request);
|
|
51
55
|
const known = key === null ? void 0 : this.enumNamesByKey.get(key);
|
|
52
56
|
if (known !== void 0) {
|
|
53
57
|
return known;
|
|
54
58
|
}
|
|
59
|
+
const name = this.names.enums.nameFor(sharedName, request.name);
|
|
55
60
|
const declared = request.values.length > 0 ? declarationKey(name, request) : null;
|
|
56
61
|
if (declared !== null && this.declaredEnums.has(declared)) {
|
|
57
62
|
return name;
|
|
@@ -136,6 +141,9 @@ class RunFooter {
|
|
|
136
141
|
addOperation(build) {
|
|
137
142
|
this.sink.addOperation(build);
|
|
138
143
|
}
|
|
144
|
+
operationKey(operationId) {
|
|
145
|
+
return this.names.operations.keyFor(operationId);
|
|
146
|
+
}
|
|
139
147
|
require(helper) {
|
|
140
148
|
if (!this.sink.hasTypeAlias(helper.name)) {
|
|
141
149
|
this.sink.add({ kind: "rawDeclaration", name: helper.name, text: helper.text });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-footer.cjs","sources":["../../../../src/application/transform/footer/document-footer.ts"],"sourcesContent":["import { irReference } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrEnumDeclaration,\n IrPropertySignature,\n IrType,\n} from \"../../../domain/ir/nodes.js\";\nimport { HELPER_TYPES, type HelperType } from \"../helper-types.js\";\nimport type {\n EnumDeclarationRequest,\n EnumMemberMetadata,\n EnumValuesRequest,\n} from \"../schema/schema-context.js\";\nimport type { DocumentFooter } from \"../transform-context.js\";\nimport {\n type DeclaredMembers,\n EnumNaming,\n enumDeclaration,\n withoutDeclaredMembers,\n} from \"./enum-naming.js\";\nimport { FIRST_SCHEMA_NAMES, type SharedEnumNames } from \"./shared-enum-names.js\";\n\n/** Where footer declarations go, in order: the run's `ctx.injectFooter`, open to user code. */\nexport interface FooterSink {\n /** Whether a type alias with this name is declared already (by the generator or a user). */\n hasTypeAlias(name: string): boolean;\n add(declaration: IrDeclaration): void;\n /** Add a member to the `operations` interface, declared first if needed; see `DocumentFooter`. */\n addOperation(build: () => IrPropertySignature): void;\n}\n\n/**\n * The `--dedupe-enums` key of the original: the values in default sort order, each paired with\n * the metadata at its sorted position (not the value's own metadata), as the original does.\n */\nfunction dedupeKey(request: EnumDeclarationRequest): string {\n return [...request.values]\n .sort(compareAsStrings)\n .map((value, index) => metadataKey(String(value), request.metadata[index]))\n .join(\",\");\n}\n\n/** `Array.prototype.sort` without a comparator: compares the values as strings. */\nfunction compareAsStrings(left: string | number, right: string | number): number {\n const leftText = String(left);\n const rightText = String(right);\n if (leftText === rightText) {\n return 0;\n }\n return leftText < rightText ? -1 : 1;\n}\n\nfunction metadataKey(value: string, metadata: EnumMemberMetadata | undefined): string {\n return `${metadata?.name ?? value}:${metadata?.description || \"\"}`;\n}\n\n/** Separates a repeated `--enum-values` array name from its number, as root type aliases do. */\nconst ENUM_VALUES_NUMBER_SEPARATOR = \"_\";\n\n/** The whole declaration: an equal key means the same enum, member for member. */\nfunction declarationKey(name: string, request: EnumDeclarationRequest): string {\n return JSON.stringify([name, request.values, request.metadata]);\n}\n\n/**\n * The footer of one run: enums (deduplicated with `--dedupe-enums`), `--enum-values` arrays, the\n * helper types they need, and the `operations` interface. Replaces the original's module-level\n * `enumCache`, so runs no longer share enums (research/legacy-bugs.md, item 3).\n */\nexport class RunFooter implements DocumentFooter {\n private readonly naming = new EnumNaming();\n private readonly enumNamesByKey = new Map<string, string>();\n /** Declarations added already: the same one twice fails with \"Duplicate identifier\". */\n private readonly declaredEnums = new Set<string>();\n /** The member names of each declared enum, by value. */\n private readonly membersByEnum = new Map<string, Map<string | number, string>>();\n /** The members of each declared enum name, by member name. */\n private readonly declaredMembers = new Map<string, Map<string, string | number>>();\n /** `--enum-values` arrays added already: their declared name by name, type and values. */\n private readonly declaredEnumValues = new Map<string, string>();\n /** The declared `--enum-values` array names. */\n private readonly enumValuesNames = new Set<string>();\n private readonly sink: FooterSink;\n private readonly isDedupingEnums: boolean;\n private readonly sharedNames: SharedEnumNames;\n\n constructor(\n sink: FooterSink,\n isDedupingEnums: boolean,\n sharedNames: SharedEnumNames = FIRST_SCHEMA_NAMES,\n ) {\n this.sink = sink;\n this.isDedupingEnums = isDedupingEnums;\n this.sharedNames = sharedNames;\n }\n\n addEnum(request: EnumDeclarationRequest): string {\n // The name is built before the cache lookup: it advances the naming state either way.\n const ownName = this.naming.enumName(request.name);\n const key = this.isDedupingEnums ? dedupeKey(request) : null;\n // Every schema of a shared enum goes to `sharedNames`, the later ones too.\n const name = key === null ? ownName : this.sharedNames.nameOf(key, ownName, request);\n const known = key === null ? undefined : this.enumNamesByKey.get(key);\n if (known !== undefined) {\n return known;\n }\n // Only a repeated member fails to compile; two empty declarations merge, so they stay.\n const declared = request.values.length > 0 ? declarationKey(name, request) : null;\n if (declared !== null && this.declaredEnums.has(declared)) {\n return name;\n }\n if (declared !== null) {\n this.declaredEnums.add(declared);\n }\n const declaration = this.withoutRepeats(enumDeclaration(name, request, this.naming));\n if (declaration !== null) {\n this.record(declaration);\n this.sink.add(declaration);\n }\n if (key !== null) {\n this.enumNamesByKey.set(key, name);\n }\n return name;\n }\n\n /** The declaration without members an earlier one of the name has; null when none is left. */\n private withoutRepeats(declaration: IrEnumDeclaration): IrEnumDeclaration | null {\n const earlier: DeclaredMembers | undefined = this.declaredMembers.get(declaration.name);\n if (earlier === undefined) {\n return declaration;\n }\n const merged = withoutDeclaredMembers(declaration, earlier);\n // Two empty declarations merge into one empty enum, which compiles, so the second stays.\n return merged.members.length === 0 && declaration.members.length > 0 ? null : merged;\n }\n\n /** The members of a declaration; the first member of a value names it. */\n private record(declaration: IrEnumDeclaration): void {\n const byName = this.declaredMembers.get(declaration.name) ?? new Map();\n const byValue = this.membersByEnum.get(declaration.name) ?? new Map();\n for (const member of declaration.members) {\n byName.set(member.name, member.value);\n if (!byValue.has(member.value)) {\n byValue.set(member.value, member.name);\n }\n }\n this.declaredMembers.set(declaration.name, byName);\n this.membersByEnum.set(declaration.name, byValue);\n }\n\n enumMembers(name: string): ReadonlyMap<string | number, string> {\n return this.membersByEnum.get(name) ?? new Map();\n }\n\n addEnumValues(request: EnumValuesRequest): void {\n const baseName = this.naming.arrayName(request.name);\n // The same array twice fails with \"Cannot redeclare\"; a schema typed twice adds it twice.\n const declared = JSON.stringify([baseName, request.type, request.values]);\n if (this.declaredEnumValues.has(declared)) {\n return;\n }\n const name = this.freeEnumValuesName(baseName);\n this.declaredEnumValues.set(declared, name);\n this.enumValuesNames.add(name);\n this.require(HELPER_TYPES.flattenedDeepRequired);\n this.require(HELPER_TYPES.readonlyArray);\n this.sink.add({\n kind: \"constArray\",\n name,\n isExported: true,\n type: readonlyArrayOf(request.type),\n values: request.values,\n comments: [],\n });\n }\n\n /**\n * Another array may have the name: `Discount/type` and `discount/type`, or a property and an\n * inline `allOf` item of one schema, typed at one location. A redeclared `const` does not\n * compile, so a later one gets the next number (`discountTypeValues_2`). Every unnumbered name\n * ends with `Values`, so a number never takes a name that a later array needs.\n */\n private freeEnumValuesName(name: string): string {\n let candidate = name;\n for (let count = 2; this.enumValuesNames.has(candidate); count++) {\n candidate = `${name}${ENUM_VALUES_NUMBER_SEPARATOR}${count}`;\n }\n return candidate;\n }\n\n requireWithRequired(): void {\n this.require(HELPER_TYPES.withRequired);\n }\n\n requirePropertyValues(): void {\n this.require(HELPER_TYPES.propertyValues);\n }\n\n addOperation(build: () => IrPropertySignature): void {\n this.sink.addOperation(build);\n }\n\n private require(helper: HelperType): void {\n if (!this.sink.hasTypeAlias(helper.name)) {\n this.sink.add({ kind: \"rawDeclaration\", name: helper.name, text: helper.text });\n }\n }\n}\n\nfunction readonlyArrayOf(type: IrType): IrType {\n return irReference(HELPER_TYPES.readonlyArray.name, [type]);\n}\n"],"names":["EnumNaming","FIRST_SCHEMA_NAMES","enumDeclaration","withoutDeclaredMembers","HELPER_TYPES","irReference"],"mappings":";;;;;;;AAmCA,SAAS,UAAU,OAAA,EAAyC;AAC1D,EAAA,OAAO,CAAC,GAAG,OAAA,CAAQ,MAAM,EACtB,IAAA,CAAK,gBAAgB,CAAA,CACrB,GAAA,CAAI,CAAC,KAAA,EAAO,UAAU,WAAA,CAAY,MAAA,CAAO,KAAK,CAAA,EAAG,OAAA,CAAQ,QAAA,CAAS,KAAK,CAAC,CAAC,CAAA,CACzE,IAAA,CAAK,GAAG,CAAA;AACb;AAGA,SAAS,gBAAA,CAAiB,MAAuB,KAAA,EAAgC;AAC/E,EAAA,MAAM,QAAA,GAAW,OAAO,IAAI,CAAA;AAC5B,EAAA,MAAM,SAAA,GAAY,OAAO,KAAK,CAAA;AAC9B,EAAA,IAAI,aAAa,SAAA,EAAW;AAC1B,IAAA,OAAO,CAAA;AAAA,EACT;AACA,EAAA,OAAO,QAAA,GAAW,YAAY,EAAA,GAAK,CAAA;AACrC;AAEA,SAAS,WAAA,CAAY,OAAe,QAAA,EAAkD;AACpF,EAAA,OAAO,GAAG,QAAA,EAAU,IAAA,IAAQ,KAAK,CAAA,CAAA,EAAI,QAAA,EAAU,eAAe,EAAE,CAAA,CAAA;AAClE;AAGA,MAAM,4BAAA,GAA+B,GAAA;AAGrC,SAAS,cAAA,CAAe,MAAc,OAAA,EAAyC;AAC7E,EA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C,MAAA,IAAA,CAAK,IAAA,CAAK,GAAA,CAAI,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,MAAA,CAAO,IAAA,EAAM,IAAA,EAAM,MAAA,CAAO,IAAA,EAAM,CAAA;AAAA,IAChF;AAAA,EACF;AACF;AAEA,SAAS,gBAAgB,IAAA,EAAsB;AAC7C,EAAA,OAAOC,yBAAYD,wBAAA,CAAa,aAAA,CAAc,IAAA,EAAM,CAAC,IAAI,CAAC,CAAA;AAC5D;;"}
|
|
1
|
+
{"version":3,"file":"document-footer.cjs","sources":["../../../../src/application/transform/footer/document-footer.ts"],"sourcesContent":["import { irReference } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrEnumDeclaration,\n IrPropertySignature,\n IrType,\n} from \"../../../domain/ir/nodes.js\";\nimport { HELPER_TYPES, type HelperType } from \"../helper-types.js\";\nimport type {\n EnumDeclarationRequest,\n EnumMemberMetadata,\n EnumValuesRequest,\n} from \"../schema/schema-context.js\";\nimport type { DocumentFooter } from \"../transform-context.js\";\nimport { EnumNameClaims } from \"./enum-name-claims.js\";\nimport {\n type DeclaredMembers,\n EnumNaming,\n enumDeclaration,\n withoutDeclaredMembers,\n} from \"./enum-naming.js\";\nimport { OperationKeys } from \"./operation-keys.js\";\nimport { FIRST_SCHEMA_NAMES, type SharedEnumNames } from \"./shared-enum-names.js\";\n\n/** Where footer declarations go, in order: the run's `ctx.injectFooter`, open to user code. */\nexport interface FooterSink {\n /** Whether a type alias with this name is declared already (by the generator or a user). */\n hasTypeAlias(name: string): boolean;\n add(declaration: IrDeclaration): void;\n /** Add a member to the `operations` interface, declared first if needed; see `DocumentFooter`. */\n addOperation(build: () => IrPropertySignature): void;\n}\n\n/**\n * The `--dedupe-enums` key of the original: the values in default sort order, each paired with\n * the metadata at its sorted position (not the value's own metadata), as the original does.\n */\nfunction dedupeKey(request: EnumDeclarationRequest): string {\n return [...request.values]\n .sort(compareAsStrings)\n .map((value, index) => metadataKey(String(value), request.metadata[index]))\n .join(\",\");\n}\n\n/** `Array.prototype.sort` without a comparator: compares the values as strings. */\nfunction compareAsStrings(left: string | number, right: string | number): number {\n const leftText = String(left);\n const rightText = String(right);\n if (leftText === rightText) {\n return 0;\n }\n return leftText < rightText ? -1 : 1;\n}\n\nfunction metadataKey(value: string, metadata: EnumMemberMetadata | undefined): string {\n return `${metadata?.name ?? value}:${metadata?.description || \"\"}`;\n}\n\n/** Separates a repeated `--enum-values` array name from its number, as root type aliases do. */\nconst ENUM_VALUES_NUMBER_SEPARATOR = \"_\";\n\n/** The whole declaration: an equal key means the same enum, member for member. */\nfunction declarationKey(name: string, request: EnumDeclarationRequest): string {\n return JSON.stringify([name, request.values, request.metadata]);\n}\n\n/** The naming state a run's footer shares with the rest of the run. */\nexport interface RunFooterNames {\n readonly enums: EnumNameClaims;\n readonly operations: OperationKeys;\n}\n\n/**\n * The footer of one run: enums (deduplicated with `--dedupe-enums`), `--enum-values` arrays, the\n * helper types they need, and the `operations` interface. Replaces the original's module-level\n * `enumCache`, so runs no longer share enums (research/legacy-bugs.md, item 3).\n */\nexport class RunFooter implements DocumentFooter {\n private readonly naming = new EnumNaming();\n private readonly enumNamesByKey = new Map<string, string>();\n /** Declarations added already: the same one twice fails with \"Duplicate identifier\". */\n private readonly declaredEnums = new Set<string>();\n /** The member names of each declared enum, by value. */\n private readonly membersByEnum = new Map<string, Map<string | number, string>>();\n /** The members of each declared enum name, by member name. */\n private readonly declaredMembers = new Map<string, Map<string, string | number>>();\n /** `--enum-values` arrays added already: their declared name by name, type and values. */\n private readonly declaredEnumValues = new Map<string, string>();\n /** The declared `--enum-values` array names. */\n private readonly enumValuesNames = new Set<string>();\n private readonly sink: FooterSink;\n private readonly isDedupingEnums: boolean;\n private readonly sharedNames: SharedEnumNames;\n private readonly names: RunFooterNames;\n\n constructor(\n sink: FooterSink,\n isDedupingEnums: boolean,\n sharedNames: SharedEnumNames = FIRST_SCHEMA_NAMES,\n names: RunFooterNames = { enums: new EnumNameClaims(), operations: new OperationKeys() },\n ) {\n this.sink = sink;\n this.isDedupingEnums = isDedupingEnums;\n this.sharedNames = sharedNames;\n this.names = names;\n }\n\n addEnum(request: EnumDeclarationRequest): string {\n // The name is built before the cache lookup: it advances the naming state either way.\n const ownName = this.naming.enumName(request.name);\n const key = this.isDedupingEnums ? dedupeKey(request) : null;\n // Every schema of a shared enum goes to `sharedNames`, the later ones too.\n const sharedName = key === null ? ownName : this.sharedNames.nameOf(key, ownName, request);\n const known = key === null ? undefined : this.enumNamesByKey.get(key);\n if (known !== undefined) {\n return known;\n }\n // The owner is the schema location: its requests share one enum, with `--dedupe-enums` too.\n const name = this.names.enums.nameFor(sharedName, request.name);\n // Only a repeated member fails to compile; two empty declarations merge, so they stay.\n const declared = request.values.length > 0 ? declarationKey(name, request) : null;\n if (declared !== null && this.declaredEnums.has(declared)) {\n return name;\n }\n if (declared !== null) {\n this.declaredEnums.add(declared);\n }\n const declaration = this.withoutRepeats(enumDeclaration(name, request, this.naming));\n if (declaration !== null) {\n this.record(declaration);\n this.sink.add(declaration);\n }\n if (key !== null) {\n this.enumNamesByKey.set(key, name);\n }\n return name;\n }\n\n /** The declaration without members an earlier one of the name has; null when none is left. */\n private withoutRepeats(declaration: IrEnumDeclaration): IrEnumDeclaration | null {\n const earlier: DeclaredMembers | undefined = this.declaredMembers.get(declaration.name);\n if (earlier === undefined) {\n return declaration;\n }\n const merged = withoutDeclaredMembers(declaration, earlier);\n // Two empty declarations merge into one empty enum, which compiles, so the second stays.\n return merged.members.length === 0 && declaration.members.length > 0 ? null : merged;\n }\n\n /** The members of a declaration; the first member of a value names it. */\n private record(declaration: IrEnumDeclaration): void {\n const byName = this.declaredMembers.get(declaration.name) ?? new Map();\n const byValue = this.membersByEnum.get(declaration.name) ?? new Map();\n for (const member of declaration.members) {\n byName.set(member.name, member.value);\n if (!byValue.has(member.value)) {\n byValue.set(member.value, member.name);\n }\n }\n this.declaredMembers.set(declaration.name, byName);\n this.membersByEnum.set(declaration.name, byValue);\n }\n\n enumMembers(name: string): ReadonlyMap<string | number, string> {\n return this.membersByEnum.get(name) ?? new Map();\n }\n\n addEnumValues(request: EnumValuesRequest): void {\n const baseName = this.naming.arrayName(request.name);\n // The same array twice fails with \"Cannot redeclare\"; a schema typed twice adds it twice.\n const declared = JSON.stringify([baseName, request.type, request.values]);\n if (this.declaredEnumValues.has(declared)) {\n return;\n }\n const name = this.freeEnumValuesName(baseName);\n this.declaredEnumValues.set(declared, name);\n this.enumValuesNames.add(name);\n this.require(HELPER_TYPES.flattenedDeepRequired);\n this.require(HELPER_TYPES.readonlyArray);\n this.sink.add({\n kind: \"constArray\",\n name,\n isExported: true,\n type: readonlyArrayOf(request.type),\n values: request.values,\n comments: [],\n });\n }\n\n /**\n * Another array may have the name: `Discount/type` and `discount/type`, or a property and an\n * inline `allOf` item of one schema, typed at one location. A redeclared `const` does not\n * compile, so a later one gets the next number (`discountTypeValues_2`). Every unnumbered name\n * ends with `Values`, so a number never takes a name that a later array needs.\n */\n private freeEnumValuesName(name: string): string {\n let candidate = name;\n for (let count = 2; this.enumValuesNames.has(candidate); count++) {\n candidate = `${name}${ENUM_VALUES_NUMBER_SEPARATOR}${count}`;\n }\n return candidate;\n }\n\n requireWithRequired(): void {\n this.require(HELPER_TYPES.withRequired);\n }\n\n requirePropertyValues(): void {\n this.require(HELPER_TYPES.propertyValues);\n }\n\n addOperation(build: () => IrPropertySignature): void {\n this.sink.addOperation(build);\n }\n\n operationKey(operationId: string): string {\n return this.names.operations.keyFor(operationId);\n }\n\n private require(helper: HelperType): void {\n if (!this.sink.hasTypeAlias(helper.name)) {\n this.sink.add({ kind: \"rawDeclaration\", name: helper.name, text: helper.text });\n }\n }\n}\n\nfunction readonlyArrayOf(type: IrType): IrType {\n return irReference(HELPER_TYPES.readonlyArray.name, [type]);\n}\n"],"names":["EnumNaming","FIRST_SCHEMA_NAMES","EnumNameClaims","OperationKeys","enumDeclaration","withoutDeclaredMembers","HELPER_TYPES","ir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,CAAI,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,MAAA,CAAO,IAAA,EAAM,IAAA,EAAM,MAAA,CAAO,IAAA,EAAM,CAAA;AAAA,IAChF;AAAA,EACF;AACF;AAEA,SAAS,gBAAgB,IAAA,EAAsB;AAC7C,EAAA,OAAOC,yBAAYD,wBAAA,CAAa,aAAA,CAAc,IAAA,EAAM,CAAC,IAAI,CAAC,CAAA;AAC5D;;"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { irReference } from '../../../domain/ir/constructors.mjs';
|
|
2
2
|
import { HELPER_TYPES } from '../helper-types.mjs';
|
|
3
|
+
import { EnumNameClaims } from './enum-name-claims.mjs';
|
|
3
4
|
import { EnumNaming, enumDeclaration, withoutDeclaredMembers } from './enum-naming.mjs';
|
|
5
|
+
import { OperationKeys } from './operation-keys.mjs';
|
|
4
6
|
import { FIRST_SCHEMA_NAMES } from './shared-enum-names.mjs';
|
|
5
7
|
|
|
6
8
|
function dedupeKey(request) {
|
|
@@ -37,19 +39,22 @@ class RunFooter {
|
|
|
37
39
|
sink;
|
|
38
40
|
isDedupingEnums;
|
|
39
41
|
sharedNames;
|
|
40
|
-
|
|
42
|
+
names;
|
|
43
|
+
constructor(sink, isDedupingEnums, sharedNames = FIRST_SCHEMA_NAMES, names = { enums: new EnumNameClaims(), operations: new OperationKeys() }) {
|
|
41
44
|
this.sink = sink;
|
|
42
45
|
this.isDedupingEnums = isDedupingEnums;
|
|
43
46
|
this.sharedNames = sharedNames;
|
|
47
|
+
this.names = names;
|
|
44
48
|
}
|
|
45
49
|
addEnum(request) {
|
|
46
50
|
const ownName = this.naming.enumName(request.name);
|
|
47
51
|
const key = this.isDedupingEnums ? dedupeKey(request) : null;
|
|
48
|
-
const
|
|
52
|
+
const sharedName = key === null ? ownName : this.sharedNames.nameOf(key, ownName, request);
|
|
49
53
|
const known = key === null ? void 0 : this.enumNamesByKey.get(key);
|
|
50
54
|
if (known !== void 0) {
|
|
51
55
|
return known;
|
|
52
56
|
}
|
|
57
|
+
const name = this.names.enums.nameFor(sharedName, request.name);
|
|
53
58
|
const declared = request.values.length > 0 ? declarationKey(name, request) : null;
|
|
54
59
|
if (declared !== null && this.declaredEnums.has(declared)) {
|
|
55
60
|
return name;
|
|
@@ -134,6 +139,9 @@ class RunFooter {
|
|
|
134
139
|
addOperation(build) {
|
|
135
140
|
this.sink.addOperation(build);
|
|
136
141
|
}
|
|
142
|
+
operationKey(operationId) {
|
|
143
|
+
return this.names.operations.keyFor(operationId);
|
|
144
|
+
}
|
|
137
145
|
require(helper) {
|
|
138
146
|
if (!this.sink.hasTypeAlias(helper.name)) {
|
|
139
147
|
this.sink.add({ kind: "rawDeclaration", name: helper.name, text: helper.text });
|