@prisma/orm-mysql 0.0.0-stage → 8.0.0-rc.21-dev.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +44 -2
- package/dist/adapter.d.mts +1 -0
- package/dist/adapter.mjs +2 -0
- package/dist/adapter__adapter.d.mts +1 -0
- package/dist/adapter__adapter.mjs +2 -0
- package/dist/adapter__codec-types.d.mts +1 -0
- package/dist/adapter__codec-types.mjs +2 -0
- package/dist/adapter__control.d.mts +3 -0
- package/dist/adapter__control.mjs +3 -0
- package/dist/adapter__runtime.d.mts +3 -0
- package/dist/adapter__runtime.mjs +3 -0
- package/dist/builder.d.mts +1 -0
- package/dist/builder.mjs +2 -0
- package/dist/builder__runtime.d.mts +1 -0
- package/dist/builder__runtime.mjs +2 -0
- package/dist/builder__types.d.mts +1 -0
- package/dist/builder__types.mjs +2 -0
- package/dist/components.d.mts +1 -0
- package/dist/components.mjs +2 -0
- package/dist/components__authoring.d.mts +1 -0
- package/dist/components__authoring.mjs +2 -0
- package/dist/components__codec.d.mts +1 -0
- package/dist/components__codec.mjs +2 -0
- package/dist/components__components.d.mts +1 -0
- package/dist/components__components.mjs +2 -0
- package/dist/components__control.d.mts +1 -0
- package/dist/components__control.mjs +2 -0
- package/dist/components__emission.d.mts +1 -0
- package/dist/components__emission.mjs +2 -0
- package/dist/components__execution.d.mts +1 -0
- package/dist/components__execution.mjs +2 -0
- package/dist/components__ir.d.mts +1 -0
- package/dist/components__ir.mjs +2 -0
- package/dist/components__psl-ast.d.mts +1 -0
- package/dist/components__psl-ast.mjs +2 -0
- package/dist/components__runtime.d.mts +1 -0
- package/dist/components__runtime.mjs +2 -0
- package/dist/components__utils.d.mts +1 -0
- package/dist/components__utils.mjs +2 -0
- package/dist/config.d.mts +22 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +41 -0
- package/dist/config.mjs.map +1 -0
- package/dist/contract-builder.d.mts +192 -0
- package/dist/contract-builder.d.mts.map +1 -0
- package/dist/contract-builder.mjs +37 -0
- package/dist/contract-builder.mjs.map +1 -0
- package/dist/contract.d.mts +1 -0
- package/dist/contract.mjs +2 -0
- package/dist/contract__apply-specifier-default-control-policy.d.mts +1 -0
- package/dist/contract__apply-specifier-default-control-policy.mjs +2 -0
- package/dist/contract__contract-validation-error.d.mts +1 -0
- package/dist/contract__contract-validation-error.mjs +2 -0
- package/dist/contract__default-namespace.d.mts +1 -0
- package/dist/contract__default-namespace.mjs +2 -0
- package/dist/contract__enum-accessor.d.mts +1 -0
- package/dist/contract__enum-accessor.mjs +2 -0
- package/dist/contract__hashing-utils.d.mts +1 -0
- package/dist/contract__hashing-utils.mjs +2 -0
- package/dist/contract__hashing.d.mts +1 -0
- package/dist/contract__hashing.mjs +2 -0
- package/dist/contract__is-plain-record.d.mts +1 -0
- package/dist/contract__is-plain-record.mjs +2 -0
- package/dist/contract__resolve-domain-model.d.mts +1 -0
- package/dist/contract__resolve-domain-model.mjs +2 -0
- package/dist/contract__types.d.mts +1 -0
- package/dist/contract__types.mjs +2 -0
- package/dist/contract__validate-domain.d.mts +1 -0
- package/dist/contract__validate-domain.mjs +2 -0
- package/dist/contract__validate-once.d.mts +1 -0
- package/dist/contract__validate-once.mjs +2 -0
- package/dist/contract__validate-storage.d.mts +1 -0
- package/dist/contract__validate-storage.mjs +2 -0
- package/dist/control.d.mts +12 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +22 -0
- package/dist/control.mjs.map +1 -0
- package/dist/driver.d.mts +1 -0
- package/dist/driver.mjs +2 -0
- package/dist/driver__control.d.mts +3 -0
- package/dist/driver__control.mjs +3 -0
- package/dist/driver__runtime.d.mts +3 -0
- package/dist/driver__runtime.mjs +3 -0
- package/dist/family-contract.d.mts +1 -0
- package/dist/family-contract.mjs +2 -0
- package/dist/family-contract__authored-check-naming.d.mts +1 -0
- package/dist/family-contract__authored-check-naming.mjs +2 -0
- package/dist/family-contract__canonicalization-hooks.d.mts +1 -0
- package/dist/family-contract__canonicalization-hooks.mjs +2 -0
- package/dist/family-contract__check-expressions.d.mts +1 -0
- package/dist/family-contract__check-expressions.mjs +2 -0
- package/dist/family-contract__codec-json-type.d.mts +1 -0
- package/dist/family-contract__codec-json-type.mjs +2 -0
- package/dist/family-contract__contract-view.d.mts +1 -0
- package/dist/family-contract__contract-view.mjs +2 -0
- package/dist/family-contract__data-type-support.d.mts +1 -0
- package/dist/family-contract__data-type-support.mjs +2 -0
- package/dist/family-contract__data-type.d.mts +1 -0
- package/dist/family-contract__data-type.mjs +2 -0
- package/dist/family-contract__entity-handle-lowering-hook.d.mts +1 -0
- package/dist/family-contract__entity-handle-lowering-hook.mjs +2 -0
- package/dist/family-contract__entity-kinds.d.mts +1 -0
- package/dist/family-contract__entity-kinds.mjs +2 -0
- package/dist/family-contract__factories.d.mts +1 -0
- package/dist/family-contract__factories.mjs +2 -0
- package/dist/family-contract__foreign-key-materialization.d.mts +1 -0
- package/dist/family-contract__foreign-key-materialization.mjs +2 -0
- package/dist/family-contract__generated-id-column-aliases.d.mts +1 -0
- package/dist/family-contract__generated-id-column-aliases.mjs +2 -0
- package/dist/family-contract__index-naming.d.mts +1 -0
- package/dist/family-contract__index-naming.mjs +2 -0
- package/dist/family-contract__index-type-validation.d.mts +1 -0
- package/dist/family-contract__index-type-validation.mjs +2 -0
- package/dist/family-contract__index-types.d.mts +1 -0
- package/dist/family-contract__index-types.mjs +2 -0
- package/dist/family-contract__referential-action-sql.d.mts +1 -0
- package/dist/family-contract__referential-action-sql.mjs +2 -0
- package/dist/family-contract__resolve-storage-table.d.mts +1 -0
- package/dist/family-contract__resolve-storage-table.mjs +2 -0
- package/dist/family-contract__sql-expression.d.mts +1 -0
- package/dist/family-contract__sql-expression.mjs +2 -0
- package/dist/family-contract__types.d.mts +1 -0
- package/dist/family-contract__types.mjs +2 -0
- package/dist/family-contract__validators.d.mts +1 -0
- package/dist/family-contract__validators.mjs +2 -0
- package/dist/family-contract__value-set-derivation-hook.d.mts +1 -0
- package/dist/family-contract__value-set-derivation-hook.mjs +2 -0
- package/dist/family-runtime.d.mts +1 -0
- package/dist/family-runtime.mjs +2 -0
- package/dist/family-runtime__internal__prepared-query.d.mts +1 -0
- package/dist/family-runtime__internal__prepared-query.mjs +2 -0
- package/dist/family__control-adapter.d.mts +1 -0
- package/dist/family__control-adapter.mjs +2 -0
- package/dist/family__control.d.mts +3 -0
- package/dist/family__control.mjs +3 -0
- package/dist/family__diff.d.mts +1 -0
- package/dist/family__diff.mjs +2 -0
- package/dist/family__ir.d.mts +1 -0
- package/dist/family__ir.mjs +2 -0
- package/dist/family__migration.d.mts +1 -0
- package/dist/family__migration.mjs +2 -0
- package/dist/family__pack.d.mts +3 -0
- package/dist/family__pack.mjs +3 -0
- package/dist/family__psl-build.d.mts +1 -0
- package/dist/family__psl-build.mjs +2 -0
- package/dist/family__psl-infer.d.mts +1 -0
- package/dist/family__psl-infer.mjs +2 -0
- package/dist/family__runtime.d.mts +3 -0
- package/dist/family__runtime.mjs +3 -0
- package/dist/family__verify.d.mts +1 -0
- package/dist/family__verify.mjs +2 -0
- package/dist/migration-tools__aggregate.d.mts +1 -0
- package/dist/migration-tools__aggregate.mjs +2 -0
- package/dist/migration-tools__contract-snapshot-store.d.mts +1 -0
- package/dist/migration-tools__contract-snapshot-store.mjs +2 -0
- package/dist/migration-tools__hash.d.mts +1 -0
- package/dist/migration-tools__hash.mjs +2 -0
- package/dist/migration-tools__io.d.mts +1 -0
- package/dist/migration-tools__io.mjs +2 -0
- package/dist/migration-tools__spaces.d.mts +1 -0
- package/dist/migration-tools__spaces.mjs +2 -0
- package/dist/migration.d.mts +1 -0
- package/dist/migration.mjs +2 -0
- package/dist/mysql-static-Dv4HuJDi-CoURZL0Y.mjs +83 -0
- package/dist/mysql-static-Dv4HuJDi-CoURZL0Y.mjs.map +1 -0
- package/dist/mysql-uiFioAtk-BuXtMcWO.d.mts +100 -0
- package/dist/mysql-uiFioAtk-BuXtMcWO.d.mts.map +1 -0
- package/dist/orm-client.d.mts +1 -0
- package/dist/orm-client.mjs +2 -0
- package/dist/relational-core.d.mts +1 -0
- package/dist/relational-core.mjs +2 -0
- package/dist/relational-core__aggregate-descriptor-registry.d.mts +1 -0
- package/dist/relational-core__aggregate-descriptor-registry.mjs +2 -0
- package/dist/relational-core__ast.d.mts +1 -0
- package/dist/relational-core__ast.mjs +2 -0
- package/dist/relational-core__codec-descriptor-registry.d.mts +1 -0
- package/dist/relational-core__codec-descriptor-registry.mjs +2 -0
- package/dist/relational-core__collection-methods.d.mts +1 -0
- package/dist/relational-core__collection-methods.mjs +2 -0
- package/dist/relational-core__contract-free.d.mts +1 -0
- package/dist/relational-core__contract-free.mjs +2 -0
- package/dist/relational-core__expression.d.mts +1 -0
- package/dist/relational-core__expression.mjs +2 -0
- package/dist/relational-core__functions.d.mts +1 -0
- package/dist/relational-core__functions.mjs +2 -0
- package/dist/relational-core__index-reference.d.mts +1 -0
- package/dist/relational-core__index-reference.mjs +2 -0
- package/dist/relational-core__middleware.d.mts +1 -0
- package/dist/relational-core__middleware.mjs +2 -0
- package/dist/relational-core__plan.d.mts +1 -0
- package/dist/relational-core__plan.mjs +2 -0
- package/dist/relational-core__query-lane-context.d.mts +1 -0
- package/dist/relational-core__query-lane-context.mjs +2 -0
- package/dist/relational-core__types.d.mts +1 -0
- package/dist/relational-core__types.mjs +2 -0
- package/dist/runtime.d.mts +24 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +266 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/schema-ir__types.d.mts +1 -0
- package/dist/schema-ir__types.mjs +2 -0
- package/dist/static.d.mts +25 -0
- package/dist/static.d.mts.map +1 -0
- package/dist/static.mjs +2 -0
- package/dist/target__codec-descriptor.d.mts +1 -0
- package/dist/target__codec-descriptor.mjs +2 -0
- package/dist/target__codec-ids.d.mts +1 -0
- package/dist/target__codec-ids.mjs +2 -0
- package/dist/target__codec-types.d.mts +1 -0
- package/dist/target__codec-types.mjs +2 -0
- package/dist/target__codecs.d.mts +1 -0
- package/dist/target__codecs.mjs +2 -0
- package/dist/target__contract-free.d.mts +1 -0
- package/dist/target__contract-free.mjs +2 -0
- package/dist/target__control-tables.d.mts +1 -0
- package/dist/target__control-tables.mjs +2 -0
- package/dist/target__control.d.mts +3 -0
- package/dist/target__control.mjs +3 -0
- package/dist/target__data-types.d.mts +1 -0
- package/dist/target__data-types.mjs +2 -0
- package/dist/target__ddl.d.mts +1 -0
- package/dist/target__ddl.mjs +2 -0
- package/dist/target__default-normalizer.d.mts +1 -0
- package/dist/target__default-normalizer.mjs +2 -0
- package/dist/target__errors.d.mts +1 -0
- package/dist/target__errors.mjs +2 -0
- package/dist/target__marker-lock.d.mts +1 -0
- package/dist/target__marker-lock.mjs +2 -0
- package/dist/target__migration.d.mts +1 -0
- package/dist/target__migration.mjs +2 -0
- package/dist/target__pack.d.mts +3 -0
- package/dist/target__pack.mjs +3 -0
- package/dist/target__runtime.d.mts +3 -0
- package/dist/target__runtime.mjs +3 -0
- package/dist/target__sql-utils.d.mts +1 -0
- package/dist/target__sql-utils.mjs +2 -0
- package/dist/utils.d.mts +1 -0
- package/dist/utils.mjs +2 -0
- package/dist/utils__abortable.d.mts +1 -0
- package/dist/utils__abortable.mjs +2 -0
- package/dist/utils__array-equal.d.mts +1 -0
- package/dist/utils__array-equal.mjs +2 -0
- package/dist/utils__assertions.d.mts +1 -0
- package/dist/utils__assertions.mjs +2 -0
- package/dist/utils__canonical-stringify.d.mts +1 -0
- package/dist/utils__canonical-stringify.mjs +2 -0
- package/dist/utils__casts.d.mts +1 -0
- package/dist/utils__casts.mjs +2 -0
- package/dist/utils__defined.d.mts +1 -0
- package/dist/utils__defined.mjs +2 -0
- package/dist/utils__hash-content.d.mts +1 -0
- package/dist/utils__hash-content.mjs +2 -0
- package/dist/utils__internal-error.d.mts +1 -0
- package/dist/utils__internal-error.mjs +2 -0
- package/dist/utils__json.d.mts +1 -0
- package/dist/utils__json.mjs +2 -0
- package/dist/utils__promise.d.mts +1 -0
- package/dist/utils__promise.mjs +2 -0
- package/dist/utils__redact-db-url.d.mts +1 -0
- package/dist/utils__redact-db-url.mjs +2 -0
- package/dist/utils__result.d.mts +1 -0
- package/dist/utils__result.mjs +2 -0
- package/dist/utils__simplify-deep.d.mts +1 -0
- package/dist/utils__simplify-deep.mjs +2 -0
- package/dist/utils__structured-error.d.mts +1 -0
- package/dist/utils__structured-error.mjs +2 -0
- package/dist/utils__suppress-idle-connection-errors.d.mts +1 -0
- package/dist/utils__suppress-idle-connection-errors.mjs +2 -0
- package/dist/utils__text.d.mts +1 -0
- package/dist/utils__text.mjs +2 -0
- package/dist/utils__types.d.mts +1 -0
- package/dist/utils__types.mjs +2 -0
- package/dist/vite-plugin-contract-emit.d.mts +1 -0
- package/dist/vite-plugin-contract-emit.mjs +2 -0
- package/package.json +175 -3
- package/skills/prisma-8/SKILL.md +100 -0
- package/skills/prisma-8/references/build.md +142 -0
- package/skills/prisma-8/references/contract.md +548 -0
- package/skills/prisma-8/references/debug.md +150 -0
- package/skills/prisma-8/references/feedback.md +251 -0
- package/skills/prisma-8/references/migration-model.md +179 -0
- package/skills/prisma-8/references/migration-review.md +211 -0
- package/skills/prisma-8/references/migrations.md +622 -0
- package/skills/prisma-8/references/queries-mongo.md +238 -0
- package/skills/prisma-8/references/queries-postgres.md +710 -0
- package/skills/prisma-8/references/queries.md +253 -0
- package/skills/prisma-8/references/quickstart.md +317 -0
- package/skills/prisma-8/references/runtime.md +463 -0
- package/skills/prisma-8/references/supabase.md +234 -0
- package/skills/prisma-8/references/upgrade-app.md +102 -0
- package/skills/prisma-8/references/upgrade-extension.md +108 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.10-to-0.11/instructions.md +56 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.11-to-0.12/instructions.md +381 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.11-to-0.12/re-emit-closed-mongo-contracts.ts +202 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.11-to-0.12/re-emit-domain-namespaced-contracts.ts +201 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.11-to-0.12/re-emit-postgres-public-default.ts +198 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.11-to-0.12/strip-migration-labels-hints.ts +340 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.12-to-0.13/instructions.md +339 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.12-to-0.13/re-emit-mti-variant-link-columns.ts +229 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.13-to-0.14/instructions.md +543 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.13-to-0.14/migration-op-factories-to-methods.ts +290 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.13-to-0.14/uuid-preset-rename.ts +43 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.14-to-0.15/instructions.md +359 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.15-to-0.16/instructions.md +173 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.16-to-0.17/instructions.md +805 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.16-to-0.17/strip-sha256-hash-prefixes.ts +382 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.17-to-8.0.0-rc.1/instructions.md +72 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.7-to-0.8/instructions.md +8 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.8-to-0.9/instructions.md +36 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.8-to-0.9/strip-inline-contracts.ts +226 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.9-to-0.10/instructions.md +86 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.9-to-0.10/stamp-storage-types-kind.ts +360 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.1-to-8.0.0-rc.2/instructions.md +588 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.10-to-8.0.0-rc.11/instructions.md +34 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/instructions.md +639 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/scripts/multifile-psl/add-use-prisma-8-directive.mjs +60 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/scripts/psl-verbatim-table-names/add-model-map.mjs +256 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/instructions.md +332 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts +193 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.13-to-8.0.0-rc.14/instructions.md +489 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/instructions.md +1368 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/scripts/data-type-in-contract/data-type-in-contract.ts +1492 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.15-to-8.0.0-rc.16/instructions.md +108 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.16-to-8.0.0-rc.17/instructions.md +755 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/instructions.md +973 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/scripts/sql-expression-literals-psl/rewrite-sql-strings.mjs +271 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +1862 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/client-takes-contract-value/contract-from-json.ts +597 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/data-type-values/data-type-values.ts +1120 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/default-generators-to-on-create/rewrite-default-generators.mjs +86 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/mongo-field-storage-names/mongo-field-storage-names.ts +304 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/remove-nocheck/remove-nocheck.ts +2462 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +513 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/scripts/expand-type-aliases/expand-type-aliases.ts +1206 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.2-to-8.0.0-rc.3/instructions.md +5 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.20-to-8.0.0-rc.21/instructions.md +802 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.3-to-8.0.0-rc.4/instructions.md +158 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.4-to-8.0.0-rc.5/instructions.md +42 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.5-to-8.0.0-rc.6/instructions.md +157 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.6-to-8.0.0-rc.7/instructions.md +33 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.7-to-8.0.0-rc.8/instructions.md +36 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.8-to-8.0.0-rc.9/instructions.md +63 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.9-to-8.0.0-rc.10/instructions.md +84 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.10-to-0.11/instructions.md +276 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/instructions.md +738 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/migrate-contract-testing-imports.ts +97 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/regenerate-extension-public-baseline.ts +223 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/strip-migration-labels-hints.ts +340 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.12-to-0.13/instructions.md +266 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.13-to-0.14/instructions.md +522 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.13-to-0.14/migration-op-factories-to-methods.ts +290 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.13-to-0.14/uuid-preset-rename.ts +43 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.14-to-0.15/instructions.md +803 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.15-to-0.16/instructions.md +219 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.16-to-0.17/instructions.md +731 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.16-to-0.17/strip-sha256-hash-prefixes.ts +382 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.17-to-8.0.0-rc.1/instructions.md +194 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.7-to-0.8/instructions.md +8 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.8-to-0.9/instructions.md +57 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.8-to-0.9/strip-inline-contracts.ts +226 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.9-to-0.10/instructions.md +150 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.9-to-0.10/stamp-storage-types-kind.ts +360 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.1-to-8.0.0-rc.2/instructions.md +746 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.10-to-8.0.0-rc.11/instructions.md +34 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/instructions.md +857 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/scripts/psl-verbatim-table-names/add-model-map.mjs +256 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/instructions.md +504 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts +193 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.13-to-8.0.0-rc.14/instructions.md +143 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/instructions.md +2168 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/scripts/data-type-in-contract/data-type-in-contract.ts +1492 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.15-to-8.0.0-rc.16/instructions.md +223 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.16-to-8.0.0-rc.17/instructions.md +583 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/instructions.md +1008 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +2186 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/client-takes-contract-value/contract-from-json.ts +597 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/data-type-values/data-type-values.ts +1120 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/default-generators-to-on-create/rewrite-default-generators.mjs +86 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/mongo-field-storage-names/mongo-field-storage-names.ts +304 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/remove-nocheck/remove-nocheck.ts +2462 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +381 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/scripts/expand-type-aliases/expand-type-aliases.ts +1206 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.2-to-8.0.0-rc.3/instructions.md +5 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.20-to-8.0.0-rc.21/instructions.md +570 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.3-to-8.0.0-rc.4/instructions.md +137 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.4-to-8.0.0-rc.5/instructions.md +129 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.5-to-8.0.0-rc.6/instructions.md +102 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.6-to-8.0.0-rc.7/instructions.md +33 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.7-to-8.0.0-rc.8/instructions.md +35 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.8-to-8.0.0-rc.9/instructions.md +86 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.9-to-8.0.0-rc.10/instructions.md +63 -0
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
// Moves every Prisma 8 client call that passes `contractJson` to a contract value:
|
|
2
|
+
// postgres<Contract>({ contractJson, url })
|
|
3
|
+
// becomes
|
|
4
|
+
// export const contract = contractFromJson<Contract>(contractJson);
|
|
5
|
+
// postgres({ contract, url })
|
|
6
|
+
//
|
|
7
|
+
// Usage: node contract-from-json.ts [project-root] [--typescript <path to the typescript package>]
|
|
8
|
+
//
|
|
9
|
+
// The script reads source files with the TypeScript compiler, which it loads from the project.
|
|
10
|
+
// It rewrites each source file it can move, and prints it. In a module with a default export, such
|
|
11
|
+
// as a Worker entry, it declares `contract` without `export` and says so. It prints to stderr, with the reason,
|
|
12
|
+
// each file that passes `contractJson` to a client but that it did not move: a test file, a file
|
|
13
|
+
// that already has another binding named `contract`, a file whose clients use different contracts,
|
|
14
|
+
// a file whose `contractJson` value is not readable at the top of the file, or a call it cannot
|
|
15
|
+
// read. A `contract` destructured from the moved call is dropped from the destructuring. It exits 1 when it printed such a file, and changes nothing and exits 1
|
|
16
|
+
// when TypeScript is not installed or an argument is wrong. It skips node_modules, dist, build and every directory whose
|
|
17
|
+
// name starts with a dot, such as .git, .agents or .claude, and links that lead nowhere.
|
|
18
|
+
|
|
19
|
+
import { readdirSync, readFileSync, realpathSync, statSync, writeFileSync } from 'node:fs';
|
|
20
|
+
import { createRequire } from 'node:module';
|
|
21
|
+
import { join, relative, resolve } from 'node:path';
|
|
22
|
+
import type * as TS from 'typescript';
|
|
23
|
+
|
|
24
|
+
const SOURCE_FILE = /\.(?:ts|tsx|mts|cts)$/;
|
|
25
|
+
const TEST_FILE = /\.(?:test|spec)(?:-d)?\.[cm]?tsx?$/;
|
|
26
|
+
const TEST_DIRECTORIES = new Set(['test', 'tests', '__tests__']);
|
|
27
|
+
const SKIPPED_DIRECTORIES = new Set(['node_modules', 'dist', 'build']);
|
|
28
|
+
const FACADE_ENTRY =
|
|
29
|
+
/^@prisma\/orm-(postgres|sqlite|mongo)\/(?:runtime|serverless|static|query-builder)$/;
|
|
30
|
+
const SUPABASE_ENTRY = '@prisma/orm-extension-supabase/runtime';
|
|
31
|
+
const FACTORY_EXPORTS = new Set(['default', 'supabase', 'mongoQuery']);
|
|
32
|
+
const DETECTION =
|
|
33
|
+
/(?<![\w$.])(?:postgres|postgresServerless|sqlite|supabase|mongo|postgresStatic|sqliteStatic|mongoStatic|mongoQuery)(?:<[^<>()]*(?:<[^<>()]*>[^<>()]*)*>)?\(\s*\{(?:(?:[^{}]|\{[^{}]*\})*?,)?\s*contractJson\s*[,}:]/;
|
|
34
|
+
|
|
35
|
+
interface Edit {
|
|
36
|
+
readonly start: number;
|
|
37
|
+
readonly end: number;
|
|
38
|
+
readonly text: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface MovedCall {
|
|
42
|
+
readonly node: TS.CallExpression;
|
|
43
|
+
readonly edits: readonly Edit[];
|
|
44
|
+
readonly typeArguments: string;
|
|
45
|
+
readonly json: string;
|
|
46
|
+
readonly jsonNames: readonly string[];
|
|
47
|
+
readonly staticEntry: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type Outcome =
|
|
51
|
+
| { readonly kind: 'unchanged' }
|
|
52
|
+
| { readonly kind: 'rewritten'; readonly source: string; readonly exported: boolean }
|
|
53
|
+
| { readonly kind: 'refused'; readonly reason: string };
|
|
54
|
+
|
|
55
|
+
function staticEntryOf(specifier: string): string | undefined {
|
|
56
|
+
const facade = FACADE_ENTRY.exec(specifier);
|
|
57
|
+
if (facade !== null) return `@prisma/orm-${facade[1]}/static`;
|
|
58
|
+
return specifier === SUPABASE_ENTRY ? '@prisma/orm-postgres/static' : undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function specifierOf(ts: typeof TS, statement: TS.ImportDeclaration): string {
|
|
62
|
+
return ts.isStringLiteral(statement.moduleSpecifier) ? statement.moduleSpecifier.text : '';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function compareSpecifiers(left: string, right: string): number {
|
|
66
|
+
const rank = (specifier: string) =>
|
|
67
|
+
specifier.startsWith('node:') ? 0 : specifier.startsWith('.') ? 2 : 1;
|
|
68
|
+
return rank(left) - rank(right) || (left < right ? -1 : left > right ? 1 : 0);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function factoriesOf(ts: typeof TS, imports: readonly TS.ImportDeclaration[]) {
|
|
72
|
+
const factories = new Map<string, string>();
|
|
73
|
+
for (const statement of imports) {
|
|
74
|
+
const clause = statement.importClause;
|
|
75
|
+
const staticEntry = staticEntryOf(specifierOf(ts, statement));
|
|
76
|
+
if (clause === undefined || clause.isTypeOnly || staticEntry === undefined) continue;
|
|
77
|
+
if (clause.name !== undefined) factories.set(clause.name.text, staticEntry);
|
|
78
|
+
const bindings = clause.namedBindings;
|
|
79
|
+
if (bindings === undefined || !ts.isNamedImports(bindings)) continue;
|
|
80
|
+
for (const element of bindings.elements) {
|
|
81
|
+
const imported = (element.propertyName ?? element.name).text;
|
|
82
|
+
if (!element.isTypeOnly && FACTORY_EXPORTS.has(imported)) {
|
|
83
|
+
factories.set(element.name.text, staticEntry);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return factories;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function topLevelNames(ts: typeof TS, sourceFile: TS.SourceFile) {
|
|
91
|
+
const imported = new Set<string>();
|
|
92
|
+
const declared = new Set<string>();
|
|
93
|
+
for (const statement of sourceFile.statements) {
|
|
94
|
+
if (ts.isImportDeclaration(statement)) {
|
|
95
|
+
const clause = statement.importClause;
|
|
96
|
+
if (clause?.name !== undefined) imported.add(clause.name.text);
|
|
97
|
+
const bindings = clause?.namedBindings;
|
|
98
|
+
if (bindings !== undefined && ts.isNamespaceImport(bindings))
|
|
99
|
+
imported.add(bindings.name.text);
|
|
100
|
+
else for (const element of bindings?.elements ?? []) imported.add(element.name.text);
|
|
101
|
+
} else if (ts.isVariableStatement(statement)) {
|
|
102
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
103
|
+
for (const name of bindingNames(ts, declaration.name)) declared.add(name);
|
|
104
|
+
}
|
|
105
|
+
} else if (
|
|
106
|
+
(ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) &&
|
|
107
|
+
statement.name !== undefined
|
|
108
|
+
) {
|
|
109
|
+
declared.add(statement.name.text);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { imported, declared };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function bindingIdentifiers(ts: typeof TS, name: TS.BindingName): TS.Identifier[] {
|
|
116
|
+
if (ts.isIdentifier(name)) return [name];
|
|
117
|
+
return name.elements.flatMap((element) =>
|
|
118
|
+
ts.isOmittedExpression(element) ? [] : bindingIdentifiers(ts, element.name),
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function bindingNames(ts: typeof TS, name: TS.BindingName): string[] {
|
|
123
|
+
return bindingIdentifiers(ts, name).map((identifier) => identifier.text);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function bindingsOf(ts: typeof TS, root: TS.Node, wanted: string): TS.Node[] {
|
|
127
|
+
const found: TS.Node[] = [];
|
|
128
|
+
const visit = (node: TS.Node): void => {
|
|
129
|
+
const binding = ownBindingOf(ts, node, wanted);
|
|
130
|
+
if (binding !== undefined) found.push(binding);
|
|
131
|
+
ts.forEachChild(node, visit);
|
|
132
|
+
};
|
|
133
|
+
visit(root);
|
|
134
|
+
return found;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function ownBindingOf(ts: typeof TS, node: TS.Node, wanted: string): TS.Node | undefined {
|
|
138
|
+
if (ts.isVariableDeclaration(node) || ts.isParameter(node)) {
|
|
139
|
+
return bindingIdentifiers(ts, node.name).find((name) => name.text === wanted);
|
|
140
|
+
}
|
|
141
|
+
if (
|
|
142
|
+
(ts.isFunctionDeclaration(node) ||
|
|
143
|
+
ts.isFunctionExpression(node) ||
|
|
144
|
+
ts.isClassDeclaration(node) ||
|
|
145
|
+
ts.isClassExpression(node) ||
|
|
146
|
+
ts.isEnumDeclaration(node) ||
|
|
147
|
+
ts.isModuleDeclaration(node) ||
|
|
148
|
+
ts.isImportEqualsDeclaration(node) ||
|
|
149
|
+
ts.isExportSpecifier(node) ||
|
|
150
|
+
ts.isNamespaceExport(node) ||
|
|
151
|
+
ts.isImportSpecifier(node) ||
|
|
152
|
+
ts.isNamespaceImport(node) ||
|
|
153
|
+
ts.isImportClause(node)) &&
|
|
154
|
+
node.name !== undefined &&
|
|
155
|
+
ts.isIdentifier(node.name) &&
|
|
156
|
+
node.name.text === wanted
|
|
157
|
+
) {
|
|
158
|
+
return node.name;
|
|
159
|
+
}
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Whether `identifier` names a variable the file declares at its top level. */
|
|
164
|
+
function isTopLevelVariable(ts: typeof TS, identifier: TS.Node): boolean {
|
|
165
|
+
let node = identifier.parent;
|
|
166
|
+
while (
|
|
167
|
+
ts.isBindingElement(node) ||
|
|
168
|
+
ts.isObjectBindingPattern(node) ||
|
|
169
|
+
ts.isArrayBindingPattern(node)
|
|
170
|
+
)
|
|
171
|
+
node = node.parent;
|
|
172
|
+
return (
|
|
173
|
+
ts.isVariableDeclaration(node) &&
|
|
174
|
+
ts.isVariableDeclarationList(node.parent) &&
|
|
175
|
+
ts.isVariableStatement(node.parent.parent) &&
|
|
176
|
+
ts.isSourceFile(node.parent.parent.parent)
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function topLevelStatementOf(ts: typeof TS, node: TS.Node): TS.Node | undefined {
|
|
181
|
+
let current = node;
|
|
182
|
+
while (current.parent !== undefined && !ts.isSourceFile(current.parent)) current = current.parent;
|
|
183
|
+
return current.parent === undefined ? undefined : current;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** The edit that drops `contract` from `const { ..., contract } = client(...)`, whose value the moved declaration now holds. */
|
|
187
|
+
function destructuredContractEdit(
|
|
188
|
+
ts: typeof TS,
|
|
189
|
+
sourceFile: TS.SourceFile,
|
|
190
|
+
call: TS.CallExpression,
|
|
191
|
+
exported: boolean,
|
|
192
|
+
): { readonly binding: TS.Node; readonly edit: Edit } | undefined {
|
|
193
|
+
const declaration = call.parent;
|
|
194
|
+
if (!ts.isVariableDeclaration(declaration) || declaration.initializer !== call) return undefined;
|
|
195
|
+
const pattern = declaration.name;
|
|
196
|
+
if (!ts.isObjectBindingPattern(pattern)) return undefined;
|
|
197
|
+
if (pattern.elements.some((element) => element.dotDotDotToken !== undefined)) return undefined;
|
|
198
|
+
const index = pattern.elements.findIndex(
|
|
199
|
+
(element) =>
|
|
200
|
+
element.propertyName === undefined &&
|
|
201
|
+
element.initializer === undefined &&
|
|
202
|
+
ts.isIdentifier(element.name) &&
|
|
203
|
+
element.name.text === 'contract',
|
|
204
|
+
);
|
|
205
|
+
const element = pattern.elements[index];
|
|
206
|
+
if (element === undefined) return undefined;
|
|
207
|
+
const statement = declaration.parent.parent;
|
|
208
|
+
const isExported =
|
|
209
|
+
ts.isVariableStatement(statement) &&
|
|
210
|
+
(ts.getModifiers(statement)?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) ?? false);
|
|
211
|
+
if (isExported && !exported) return undefined;
|
|
212
|
+
if (pattern.elements.length === 1) {
|
|
213
|
+
if (
|
|
214
|
+
!ts.isVariableStatement(statement) ||
|
|
215
|
+
isExported ||
|
|
216
|
+
statement.declarationList.declarations.length !== 1
|
|
217
|
+
)
|
|
218
|
+
return undefined;
|
|
219
|
+
return {
|
|
220
|
+
binding: element.name,
|
|
221
|
+
edit: { start: statement.getStart(sourceFile), end: call.getStart(sourceFile), text: '' },
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
const next = pattern.elements[index + 1];
|
|
225
|
+
const previous = pattern.elements[index - 1];
|
|
226
|
+
const edit =
|
|
227
|
+
next !== undefined
|
|
228
|
+
? { start: element.getStart(sourceFile), end: next.getStart(sourceFile), text: '' }
|
|
229
|
+
: { start: previous?.end ?? element.getStart(sourceFile), end: element.end, text: '' };
|
|
230
|
+
return { binding: element.name, edit };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function isReference(ts: typeof TS, identifier: TS.Identifier): boolean {
|
|
234
|
+
const parent = identifier.parent;
|
|
235
|
+
return !(
|
|
236
|
+
(ts.isPropertyAccessExpression(parent) && parent.name === identifier) ||
|
|
237
|
+
(ts.isQualifiedName(parent) && parent.right === identifier) ||
|
|
238
|
+
((ts.isPropertyAssignment(parent) ||
|
|
239
|
+
ts.isMethodDeclaration(parent) ||
|
|
240
|
+
ts.isGetAccessorDeclaration(parent) ||
|
|
241
|
+
ts.isSetAccessorDeclaration(parent)) &&
|
|
242
|
+
parent.name === identifier)
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function identifiersIn(ts: typeof TS, node: TS.Node): string[] {
|
|
247
|
+
const names: string[] = [];
|
|
248
|
+
const visit = (child: TS.Node): void => {
|
|
249
|
+
if (ts.isIdentifier(child) && isReference(ts, child)) names.push(child.text);
|
|
250
|
+
ts.forEachChild(child, visit);
|
|
251
|
+
};
|
|
252
|
+
visit(node);
|
|
253
|
+
return names;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function contractJsonProperty(ts: typeof TS, object: TS.ObjectLiteralExpression) {
|
|
257
|
+
return object.properties.find(
|
|
258
|
+
(property): property is TS.ShorthandPropertyAssignment | TS.PropertyAssignment =>
|
|
259
|
+
(ts.isShorthandPropertyAssignment(property) || ts.isPropertyAssignment(property)) &&
|
|
260
|
+
(ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)) &&
|
|
261
|
+
property.name.text === 'contractJson',
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function movedCalls(
|
|
266
|
+
ts: typeof TS,
|
|
267
|
+
sourceFile: TS.SourceFile,
|
|
268
|
+
factories: ReadonlyMap<string, string>,
|
|
269
|
+
): MovedCall[] {
|
|
270
|
+
const source = sourceFile.text;
|
|
271
|
+
const calls: MovedCall[] = [];
|
|
272
|
+
const visit = (node: TS.Node): void => {
|
|
273
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
|
|
274
|
+
const staticEntry = factories.get(node.expression.text);
|
|
275
|
+
const [options] = node.arguments;
|
|
276
|
+
const property =
|
|
277
|
+
options !== undefined && ts.isObjectLiteralExpression(options)
|
|
278
|
+
? contractJsonProperty(ts, options)
|
|
279
|
+
: undefined;
|
|
280
|
+
if (staticEntry !== undefined && property !== undefined) {
|
|
281
|
+
const edits: Edit[] = [
|
|
282
|
+
{ start: property.getStart(sourceFile), end: property.end, text: 'contract' },
|
|
283
|
+
];
|
|
284
|
+
const typeArguments = node.typeArguments;
|
|
285
|
+
if (typeArguments !== undefined) {
|
|
286
|
+
edits.push({
|
|
287
|
+
start: node.expression.end,
|
|
288
|
+
end: source.indexOf('>', typeArguments.end) + 1,
|
|
289
|
+
text: '',
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
calls.push({
|
|
293
|
+
node,
|
|
294
|
+
edits,
|
|
295
|
+
typeArguments:
|
|
296
|
+
typeArguments === undefined
|
|
297
|
+
? ''
|
|
298
|
+
: `<${typeArguments.map((type) => type.getText(sourceFile)).join(', ')}>`,
|
|
299
|
+
json: ts.isPropertyAssignment(property)
|
|
300
|
+
? property.initializer.getText(sourceFile)
|
|
301
|
+
: 'contractJson',
|
|
302
|
+
jsonNames: ts.isPropertyAssignment(property)
|
|
303
|
+
? identifiersIn(ts, property.initializer)
|
|
304
|
+
: ['contractJson'],
|
|
305
|
+
staticEntry,
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
ts.forEachChild(node, visit);
|
|
310
|
+
};
|
|
311
|
+
visit(sourceFile);
|
|
312
|
+
return calls;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function importEdit(
|
|
316
|
+
ts: typeof TS,
|
|
317
|
+
sourceFile: TS.SourceFile,
|
|
318
|
+
imports: readonly TS.ImportDeclaration[],
|
|
319
|
+
staticEntry: string,
|
|
320
|
+
style: { readonly quote: string; readonly semicolon: string; readonly eol: string },
|
|
321
|
+
): Edit | { readonly after: string } {
|
|
322
|
+
const existing = imports.find(
|
|
323
|
+
(statement) =>
|
|
324
|
+
specifierOf(ts, statement) === staticEntry &&
|
|
325
|
+
statement.importClause !== undefined &&
|
|
326
|
+
!statement.importClause.isTypeOnly,
|
|
327
|
+
);
|
|
328
|
+
const clause = existing?.importClause;
|
|
329
|
+
const bindings = clause?.namedBindings;
|
|
330
|
+
if (bindings !== undefined && ts.isNamedImports(bindings)) {
|
|
331
|
+
const first = bindings.elements[0];
|
|
332
|
+
return first === undefined
|
|
333
|
+
? { start: bindings.getStart(sourceFile), end: bindings.end, text: '{ contractFromJson }' }
|
|
334
|
+
: {
|
|
335
|
+
start: first.getStart(sourceFile),
|
|
336
|
+
end: first.getStart(sourceFile),
|
|
337
|
+
text: 'contractFromJson, ',
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
if (clause?.name !== undefined && bindings === undefined) {
|
|
341
|
+
return { start: clause.name.end, end: clause.name.end, text: ', { contractFromJson }' };
|
|
342
|
+
}
|
|
343
|
+
const line = `import { contractFromJson } from ${style.quote}${staticEntry}${style.quote}${style.semicolon}`;
|
|
344
|
+
const before = imports.find(
|
|
345
|
+
(statement) =>
|
|
346
|
+
statement.importClause !== undefined &&
|
|
347
|
+
compareSpecifiers(specifierOf(ts, statement), staticEntry) > 0,
|
|
348
|
+
);
|
|
349
|
+
if (before === undefined) return { after: `${style.eol}${line}` };
|
|
350
|
+
const at = before.getStart(sourceFile);
|
|
351
|
+
return { start: at, end: at, text: `${line}${style.eol}` };
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export function moveFile(ts: typeof TS, fileName: string, source: string): Outcome {
|
|
355
|
+
const sourceFile = ts.createSourceFile(
|
|
356
|
+
fileName,
|
|
357
|
+
source,
|
|
358
|
+
ts.ScriptTarget.Latest,
|
|
359
|
+
true,
|
|
360
|
+
fileName.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS,
|
|
361
|
+
);
|
|
362
|
+
const imports = sourceFile.statements.filter(ts.isImportDeclaration);
|
|
363
|
+
const calls = movedCalls(ts, sourceFile, factoriesOf(ts, imports));
|
|
364
|
+
const first = calls[0];
|
|
365
|
+
if (first === undefined) {
|
|
366
|
+
return DETECTION.test(source)
|
|
367
|
+
? {
|
|
368
|
+
kind: 'refused',
|
|
369
|
+
reason: 'it passes contractJson to a client in a form the script cannot read',
|
|
370
|
+
}
|
|
371
|
+
: { kind: 'unchanged' };
|
|
372
|
+
}
|
|
373
|
+
if (
|
|
374
|
+
calls.some(
|
|
375
|
+
(call) =>
|
|
376
|
+
call.json !== first.json ||
|
|
377
|
+
call.typeArguments !== first.typeArguments ||
|
|
378
|
+
call.staticEntry !== first.staticEntry,
|
|
379
|
+
)
|
|
380
|
+
) {
|
|
381
|
+
return {
|
|
382
|
+
kind: 'refused',
|
|
383
|
+
reason: 'its clients use different contracts; give each its own contractFromJson value',
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
const names = topLevelNames(ts, sourceFile);
|
|
387
|
+
const topLevelStatement = topLevelStatementOf(ts, first.node);
|
|
388
|
+
const inner = first.jsonNames.find(
|
|
389
|
+
(name) =>
|
|
390
|
+
topLevelStatement !== undefined &&
|
|
391
|
+
bindingsOf(ts, topLevelStatement, name).some((found) => !isTopLevelVariable(ts, found)),
|
|
392
|
+
);
|
|
393
|
+
if (inner !== undefined) {
|
|
394
|
+
return {
|
|
395
|
+
kind: 'refused',
|
|
396
|
+
reason: `its contractJson value uses ${inner}, which is a parameter or local binding where the client is created, not a value the top of the file can read; pass contract: contractFromJson${first.typeArguments}(${first.json}) to the call instead of contractJson, and import contractFromJson from ${first.staticEntry}`,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
const exported = !hasDefaultExport(ts, sourceFile);
|
|
400
|
+
const destructured = calls
|
|
401
|
+
.map((call) => destructuredContractEdit(ts, sourceFile, call.node, exported))
|
|
402
|
+
.filter((found) => found !== undefined);
|
|
403
|
+
const binding = bindingsOf(ts, sourceFile, 'contract').find(
|
|
404
|
+
(found) => !destructured.some((entry) => entry.binding === found),
|
|
405
|
+
);
|
|
406
|
+
if (binding !== undefined) {
|
|
407
|
+
const line = sourceFile.getLineAndCharacterOfPosition(binding.getStart(sourceFile)).line + 1;
|
|
408
|
+
return {
|
|
409
|
+
kind: 'refused',
|
|
410
|
+
reason: ts.isExportSpecifier(binding.parent)
|
|
411
|
+
? `it exports contract in an export statement (line ${line}); remove contract from that statement and run the script again`
|
|
412
|
+
: `it already has a binding named contract (line ${line}); rename that binding and run the script again`,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
const local = first.jsonNames.find((name) => names.declared.has(name));
|
|
416
|
+
if (local !== undefined) {
|
|
417
|
+
return {
|
|
418
|
+
kind: 'refused',
|
|
419
|
+
reason: `its contractJson value uses ${local}, which the file declares after its imports; declare the contract value after ${local} by hand`,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const lastImport = imports.at(-1);
|
|
424
|
+
if (lastImport === undefined) {
|
|
425
|
+
return { kind: 'refused', reason: 'it imports no client' };
|
|
426
|
+
}
|
|
427
|
+
const firstImport = imports[0];
|
|
428
|
+
const firstImportText = firstImport?.getText(sourceFile) ?? '';
|
|
429
|
+
const style = {
|
|
430
|
+
quote: firstImport?.moduleSpecifier.getText(sourceFile).startsWith('"') ? '"' : "'",
|
|
431
|
+
semicolon: firstImportText.endsWith(';') ? ';' : '',
|
|
432
|
+
eol: source.includes('\r\n') ? '\r\n' : '\n',
|
|
433
|
+
};
|
|
434
|
+
const edits: Edit[] = [
|
|
435
|
+
...calls.flatMap((call) => call.edits),
|
|
436
|
+
...destructured.map((entry) => entry.edit),
|
|
437
|
+
];
|
|
438
|
+
const staticImport = importEdit(ts, sourceFile, imports, first.staticEntry, style);
|
|
439
|
+
const importedAfter = 'after' in staticImport ? staticImport.after : '';
|
|
440
|
+
if ('start' in staticImport) edits.push(staticImport);
|
|
441
|
+
|
|
442
|
+
let afterImports = lastImport.end;
|
|
443
|
+
while (source[afterImports] === '\r' || source[afterImports] === '\n') afterImports++;
|
|
444
|
+
const declaration = `${exported ? 'export ' : ''}const contract = contractFromJson${first.typeArguments}(${first.json})${style.semicolon}`;
|
|
445
|
+
edits.push({
|
|
446
|
+
start: lastImport.end,
|
|
447
|
+
end: afterImports,
|
|
448
|
+
text: `${importedAfter}${style.eol}${style.eol}${declaration}${style.eol}${afterImports < source.length ? style.eol : ''}`,
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
let moved = source;
|
|
452
|
+
for (const edit of [...edits].sort((left, right) => right.start - left.start)) {
|
|
453
|
+
moved = moved.slice(0, edit.start) + edit.text + moved.slice(edit.end);
|
|
454
|
+
}
|
|
455
|
+
return { kind: 'rewritten', source: moved, exported };
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function hasDefaultExport(ts: typeof TS, sourceFile: TS.SourceFile): boolean {
|
|
459
|
+
return sourceFile.statements.some(
|
|
460
|
+
(statement) =>
|
|
461
|
+
(ts.isExportAssignment(statement) && !statement.isExportEquals) ||
|
|
462
|
+
(ts.isExportDeclaration(statement) &&
|
|
463
|
+
statement.exportClause !== undefined &&
|
|
464
|
+
ts.isNamedExports(statement.exportClause) &&
|
|
465
|
+
statement.exportClause.elements.some((element) => element.name.text === 'default')) ||
|
|
466
|
+
(ts.canHaveModifiers(statement) &&
|
|
467
|
+
(ts.getModifiers(statement)?.some((m) => m.kind === ts.SyntaxKind.DefaultKeyword) ??
|
|
468
|
+
false)),
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function isTestPath(path: string): boolean {
|
|
473
|
+
return TEST_FILE.test(path) || path.split(/[\\/]/).some((part) => TEST_DIRECTORIES.has(part));
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function isDirectory(path: string): boolean {
|
|
477
|
+
try {
|
|
478
|
+
return statSync(path).isDirectory();
|
|
479
|
+
} catch {
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function isFile(path: string): boolean {
|
|
485
|
+
try {
|
|
486
|
+
return statSync(path).isFile();
|
|
487
|
+
} catch {
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** Each source file under `root`, once, by the first path that reaches it; a link to a directory already visited is not followed again. */
|
|
493
|
+
function sourceFiles(root: string): string[] {
|
|
494
|
+
const visited = new Set<string>();
|
|
495
|
+
const found = new Map<string, string>();
|
|
496
|
+
const visit = (directory: string): void => {
|
|
497
|
+
const realDirectory = realpathSync(directory);
|
|
498
|
+
if (visited.has(realDirectory)) return;
|
|
499
|
+
visited.add(realDirectory);
|
|
500
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
501
|
+
const path = join(directory, entry.name);
|
|
502
|
+
if (entry.isDirectory() || (entry.isSymbolicLink() && isDirectory(path))) {
|
|
503
|
+
if (!SKIPPED_DIRECTORIES.has(entry.name) && !entry.name.startsWith('.')) visit(path);
|
|
504
|
+
} else if (
|
|
505
|
+
(entry.isFile() || (entry.isSymbolicLink() && isFile(path))) &&
|
|
506
|
+
SOURCE_FILE.test(entry.name) &&
|
|
507
|
+
!entry.name.endsWith('.d.ts')
|
|
508
|
+
) {
|
|
509
|
+
const realFile = realpathSync(path);
|
|
510
|
+
if (!found.has(realFile)) found.set(realFile, path);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
visit(root);
|
|
515
|
+
return [...found.values()];
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function loadTypeScript(root: string, explicit: string | undefined): typeof TS | undefined {
|
|
519
|
+
const require = createRequire(join(root, 'package.json'));
|
|
520
|
+
try {
|
|
521
|
+
return require(explicit ?? 'typescript');
|
|
522
|
+
} catch {
|
|
523
|
+
return undefined;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
const USAGE =
|
|
528
|
+
'Usage: node contract-from-json.ts [project-root] [--typescript <path to the typescript package>]';
|
|
529
|
+
|
|
530
|
+
function parseArgs(args: readonly string[]): {
|
|
531
|
+
readonly root: string;
|
|
532
|
+
readonly typescript: string | undefined;
|
|
533
|
+
readonly errors: string[];
|
|
534
|
+
} {
|
|
535
|
+
const errors: string[] = [];
|
|
536
|
+
const positional: string[] = [];
|
|
537
|
+
let typescript: string | undefined;
|
|
538
|
+
for (let index = 0; index < args.length; index++) {
|
|
539
|
+
const arg = args[index] ?? '';
|
|
540
|
+
if (arg === '--typescript') {
|
|
541
|
+
const path = args[++index];
|
|
542
|
+
if (path === undefined || path.startsWith('-'))
|
|
543
|
+
errors.push('--typescript: needs the path to the typescript package');
|
|
544
|
+
else typescript = resolve(path);
|
|
545
|
+
} else if (arg.startsWith('-')) errors.push(`${arg}: unknown option`);
|
|
546
|
+
else positional.push(arg);
|
|
547
|
+
}
|
|
548
|
+
if (positional.length > 1) errors.push(`expected one project root, got ${positional.length}`);
|
|
549
|
+
const root = resolve(positional[0] ?? process.cwd());
|
|
550
|
+
if (errors.length === 0 && !isDirectory(root)) errors.push(`${root}: not a directory`);
|
|
551
|
+
if (errors.length > 0) errors.push(USAGE);
|
|
552
|
+
return { root, typescript, errors };
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
function main(): number {
|
|
556
|
+
const { root, typescript, errors } = parseArgs(process.argv.slice(2));
|
|
557
|
+
if (errors.length > 0) {
|
|
558
|
+
process.stderr.write(`${errors.join('\n')}\n`);
|
|
559
|
+
return 1;
|
|
560
|
+
}
|
|
561
|
+
const ts = loadTypeScript(root, typescript);
|
|
562
|
+
if (ts === undefined) {
|
|
563
|
+
process.stderr.write(
|
|
564
|
+
`TypeScript is not installed in ${root}. Install it (for example pnpm add -D typescript) and run the script again, or move each client by hand as the guide describes. No file was changed.\n`,
|
|
565
|
+
);
|
|
566
|
+
return 1;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
let refused = 0;
|
|
570
|
+
for (const path of sourceFiles(root).sort()) {
|
|
571
|
+
const name = relative(root, path).split('\\').join('/');
|
|
572
|
+
const source = readFileSync(path, 'utf8');
|
|
573
|
+
const outcome: Outcome = isTestPath(name)
|
|
574
|
+
? DETECTION.test(source)
|
|
575
|
+
? {
|
|
576
|
+
kind: 'refused',
|
|
577
|
+
reason:
|
|
578
|
+
'it is a test file; import the contract value from the module that creates the client',
|
|
579
|
+
}
|
|
580
|
+
: { kind: 'unchanged' }
|
|
581
|
+
: moveFile(ts, path, source);
|
|
582
|
+
if (outcome.kind === 'rewritten') {
|
|
583
|
+
writeFileSync(path, outcome.source);
|
|
584
|
+
process.stdout.write(
|
|
585
|
+
outcome.exported
|
|
586
|
+
? `${name}: moved to contractFromJson\n`
|
|
587
|
+
: `${name}: moved to contractFromJson; contract is not exported, because the module has a default export (a Worker treats every named export of its entry module as an entrypoint); a module that needs the value gets it from a separate module\n`,
|
|
588
|
+
);
|
|
589
|
+
} else if (outcome.kind === 'refused') {
|
|
590
|
+
refused++;
|
|
591
|
+
process.stderr.write(`${name}: not moved, because ${outcome.reason}\n`);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
return refused === 0 ? 0 : 1;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
process.exitCode = main();
|