turbine-orm 0.93.1 → 0.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -23
- package/dist/adapters/cockroachdb.d.ts +3 -3
- package/dist/adapters/cockroachdb.js +7 -11
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/yugabytedb.js +1 -1
- package/dist/better-sqlite3.d.ts +132 -0
- package/dist/better-sqlite3.js +303 -0
- package/dist/catalog-metadata.d.ts +250 -0
- package/dist/catalog-metadata.js +730 -0
- package/dist/cjs/adapters/cockroachdb.d.ts +3 -3
- package/dist/cjs/adapters/cockroachdb.js +7 -11
- package/dist/cjs/adapters/index.d.ts +1 -1
- package/dist/cjs/adapters/yugabytedb.js +1 -1
- package/dist/cjs/better-sqlite3.d.ts +132 -0
- package/dist/cjs/better-sqlite3.js +311 -0
- package/dist/cjs/catalog-metadata.d.ts +250 -0
- package/dist/cjs/catalog-metadata.js +747 -0
- package/dist/cjs/cli/compile-query.d.ts +6 -3
- package/dist/cjs/cli/compile-query.js +24 -3
- package/dist/cjs/cli/config.d.ts +35 -10
- package/dist/cjs/cli/config.js +173 -42
- package/dist/cjs/cli/d1-config.d.ts +14 -0
- package/dist/cjs/cli/d1-config.js +9 -0
- package/dist/cjs/cli/d1-local.d.ts +31 -0
- package/dist/cjs/cli/d1-local.js +298 -0
- package/dist/cjs/cli/d1-migrations.d.ts +16 -0
- package/dist/cjs/cli/d1-migrations.js +156 -0
- package/dist/cjs/cli/d1-project.d.ts +23 -0
- package/dist/cjs/cli/d1-project.js +314 -0
- package/dist/cjs/cli/d1-seed.d.ts +35 -0
- package/dist/cjs/cli/d1-seed.js +220 -0
- package/dist/cjs/cli/destructive.js +1 -2
- package/dist/cjs/cli/error-catalog.d.ts +3 -3
- package/dist/cjs/cli/error-catalog.js +21 -3
- package/dist/cjs/cli/index.d.ts +13 -8
- package/dist/cjs/cli/index.js +503 -71
- package/dist/cjs/cli/libsql-migrate-command.d.ts +5 -0
- package/dist/cjs/cli/libsql-migrate-command.js +82 -0
- package/dist/cjs/cli/libsql-migrate-status.d.ts +33 -0
- package/dist/cjs/cli/libsql-migrate-status.js +189 -0
- package/dist/cjs/cli/libsql-migrate.d.ts +14 -0
- package/dist/cjs/cli/libsql-migrate.js +522 -0
- package/dist/cjs/cli/libsql-project-config.d.ts +11 -0
- package/dist/cjs/cli/libsql-project-config.js +59 -0
- package/dist/cjs/cli/libsql-project.d.ts +52 -0
- package/dist/cjs/cli/libsql-project.js +409 -0
- package/dist/cjs/cli/libsql-seed-command.d.ts +29 -0
- package/dist/cjs/cli/libsql-seed-command.js +93 -0
- package/dist/cjs/cli/loader.d.ts +6 -5
- package/dist/cjs/cli/loader.js +53 -9
- package/dist/cjs/cli/mcp.d.ts +16 -1
- package/dist/cjs/cli/mcp.js +219 -125
- package/dist/cjs/cli/migrate.d.ts +2 -2
- package/dist/cjs/cli/migrate.js +29 -14
- package/dist/cjs/cli/mssql-doctor.d.ts +44 -0
- package/dist/cjs/cli/mssql-doctor.js +277 -0
- package/dist/cjs/cli/mssql-migrate-command.d.ts +9 -0
- package/dist/cjs/cli/mssql-migrate-command.js +230 -0
- package/dist/cjs/cli/mssql-migrate-connection.d.ts +51 -0
- package/dist/cjs/cli/mssql-migrate-connection.js +255 -0
- package/dist/cjs/cli/mssql-migrate-sql.d.ts +12 -0
- package/dist/cjs/cli/mssql-migrate-sql.js +282 -0
- package/dist/cjs/cli/mssql-migrate.d.ts +45 -0
- package/dist/cjs/cli/mssql-migrate.js +296 -0
- package/dist/cjs/cli/mssql-project.d.ts +34 -0
- package/dist/cjs/cli/mssql-project.js +171 -0
- package/dist/cjs/cli/mssql-seed.d.ts +7 -0
- package/dist/cjs/cli/mssql-seed.js +78 -0
- package/dist/cjs/cli/mssql-tools.d.ts +37 -0
- package/dist/cjs/cli/mssql-tools.js +354 -0
- package/dist/cjs/cli/mysql-doctor.d.ts +48 -0
- package/dist/cjs/cli/mysql-doctor.js +323 -0
- package/dist/cjs/cli/mysql-migrate-command.d.ts +7 -0
- package/dist/cjs/cli/mysql-migrate-command.js +290 -0
- package/dist/cjs/cli/mysql-migrate-sql.d.ts +18 -0
- package/dist/cjs/cli/mysql-migrate-sql.js +166 -0
- package/dist/cjs/cli/mysql-migrate.d.ts +77 -0
- package/dist/cjs/cli/mysql-migrate.js +619 -0
- package/dist/cjs/cli/mysql-project.d.ts +49 -0
- package/dist/cjs/cli/mysql-project.js +284 -0
- package/dist/cjs/cli/mysql-push-command.d.ts +7 -0
- package/dist/cjs/cli/mysql-push-command.js +94 -0
- package/dist/cjs/cli/mysql-push.d.ts +15 -0
- package/dist/cjs/cli/mysql-push.js +98 -0
- package/dist/cjs/cli/mysql-schema-command.d.ts +5 -0
- package/dist/cjs/cli/mysql-schema-command.js +58 -0
- package/dist/cjs/cli/mysql-schema-ddl.d.ts +37 -0
- package/dist/cjs/cli/mysql-schema-ddl.js +234 -0
- package/dist/cjs/cli/mysql-schema-snapshot.d.ts +21 -0
- package/dist/cjs/cli/mysql-schema-snapshot.js +127 -0
- package/dist/cjs/cli/mysql-schema.d.ts +27 -0
- package/dist/cjs/cli/mysql-schema.js +206 -0
- package/dist/cjs/cli/mysql-seed-loader.cjs +58 -0
- package/dist/cjs/cli/mysql-seed-loader.d.cts +3 -0
- package/dist/cjs/cli/mysql-seed.d.ts +6 -0
- package/dist/cjs/cli/mysql-seed.js +83 -0
- package/dist/cjs/cli/mysql-tools.d.ts +44 -0
- package/dist/cjs/cli/mysql-tools.js +336 -0
- package/dist/cjs/cli/no-follow.d.ts +29 -0
- package/dist/cjs/cli/no-follow.js +73 -0
- package/dist/cjs/cli/pii-predicate-guard.d.ts +1 -1
- package/dist/cjs/cli/pii-predicate-guard.js +2 -2
- package/dist/cjs/cli/pii-tags.d.ts +2 -2
- package/dist/cjs/cli/pii-tags.js +1 -1
- package/dist/cjs/cli/prisma-schema.js +2 -2
- package/dist/cjs/cli/sql-statements.d.ts +1 -1
- package/dist/cjs/cli/sql-statements.js +1 -1
- package/dist/cjs/cli/sqlite-doctor.d.ts +35 -0
- package/dist/cjs/cli/sqlite-doctor.js +400 -0
- package/dist/cjs/cli/sqlite-migrate-command.d.ts +4 -0
- package/dist/cjs/cli/sqlite-migrate-command.js +175 -0
- package/dist/cjs/cli/sqlite-migrate.d.ts +61 -0
- package/dist/cjs/cli/sqlite-migrate.js +692 -0
- package/dist/cjs/cli/sqlite-project.d.ts +42 -0
- package/dist/cjs/cli/sqlite-project.js +254 -0
- package/dist/cjs/cli/sqlite-schema-command.d.ts +4 -0
- package/dist/cjs/cli/sqlite-schema-command.js +82 -0
- package/dist/cjs/cli/sqlite-schema-ddl.d.ts +25 -0
- package/dist/cjs/cli/sqlite-schema-ddl.js +252 -0
- package/dist/cjs/cli/sqlite-schema.d.ts +25 -0
- package/dist/cjs/cli/sqlite-schema.js +334 -0
- package/dist/cjs/cli/sqlite-seed.d.ts +4 -0
- package/dist/cjs/cli/sqlite-seed.js +94 -0
- package/dist/cjs/cli/sqlite-tools.d.ts +24 -0
- package/dist/cjs/cli/sqlite-tools.js +169 -0
- package/dist/cjs/cli/studio.js +9 -9
- package/dist/cjs/cli/tool-capabilities.d.ts +72 -0
- package/dist/cjs/cli/tool-capabilities.js +120 -0
- package/dist/cjs/cli/tool-command.d.ts +11 -0
- package/dist/cjs/cli/tool-command.js +49 -0
- package/dist/cjs/cli/ui.d.ts +1 -1
- package/dist/cjs/cli/ui.js +1 -1
- package/dist/cjs/client.d.ts +20 -20
- package/dist/cjs/client.js +65 -344
- package/dist/cjs/connection-url.d.ts +1 -1
- package/dist/cjs/connection-url.js +1 -1
- package/dist/cjs/core.d.ts +58 -0
- package/dist/cjs/core.js +225 -0
- package/dist/cjs/d1/catalog-metadata.d.ts +5 -0
- package/dist/cjs/d1/catalog-metadata.js +230 -0
- package/dist/cjs/d1/catalog.d.ts +15 -0
- package/dist/cjs/d1/catalog.js +88 -0
- package/dist/cjs/d1/generate.d.ts +8 -0
- package/dist/cjs/d1/generate.js +163 -0
- package/dist/cjs/d1/introspect.d.ts +21 -0
- package/dist/cjs/d1/introspect.js +74 -0
- package/dist/cjs/d1/migrate.d.ts +29 -0
- package/dist/cjs/d1/migrate.js +222 -0
- package/dist/cjs/d1/migrations/sql.d.ts +2 -0
- package/dist/cjs/d1/migrations/sql.js +109 -0
- package/dist/cjs/d1/pool.d.ts +14 -0
- package/dist/cjs/d1/pool.js +90 -0
- package/dist/cjs/d1/sql.d.ts +5 -0
- package/dist/cjs/d1/sql.js +140 -0
- package/dist/cjs/d1/sqlite-dialect.d.ts +16 -0
- package/dist/cjs/d1/sqlite-dialect.js +579 -0
- package/dist/cjs/d1/types.d.ts +29 -0
- package/dist/cjs/d1/types.js +2 -0
- package/dist/cjs/d1.d.ts +53 -0
- package/dist/cjs/d1.js +220 -0
- package/dist/cjs/dialect.d.ts +33 -5
- package/dist/cjs/dialect.js +8 -6
- package/dist/cjs/errors.d.ts +38 -1
- package/dist/cjs/errors.js +72 -18
- package/dist/cjs/generate.d.ts +19 -3
- package/dist/cjs/generate.js +330 -97
- package/dist/cjs/global-filters-config.js +4 -4
- package/dist/cjs/index-advisor.js +6 -6
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/introspect.d.ts +59 -356
- package/dist/cjs/introspect.js +158 -984
- package/dist/cjs/libsql/bindings.d.ts +2 -0
- package/dist/cjs/libsql/bindings.js +78 -0
- package/dist/cjs/libsql/dialect.d.ts +3 -0
- package/dist/cjs/libsql/dialect.js +48 -0
- package/dist/cjs/libsql/generate.d.ts +4 -0
- package/dist/cjs/libsql/generate.js +56 -0
- package/dist/cjs/libsql/introspect.d.ts +16 -0
- package/dist/cjs/libsql/introspect.js +295 -0
- package/dist/cjs/libsql/pool.d.ts +42 -0
- package/dist/cjs/libsql/pool.js +275 -0
- package/dist/cjs/libsql/seed-cleanup.d.ts +2 -0
- package/dist/cjs/libsql/seed-cleanup.js +19 -0
- package/dist/cjs/libsql/values.d.ts +20 -0
- package/dist/cjs/libsql/values.js +75 -0
- package/dist/cjs/libsql-seed.d.ts +19 -0
- package/dist/cjs/libsql-seed.js +50 -0
- package/dist/cjs/libsql.d.ts +28 -0
- package/dist/cjs/libsql.js +88 -0
- package/dist/cjs/live-query.d.ts +33 -0
- package/dist/cjs/live-query.js +172 -0
- package/dist/cjs/log-codes.d.ts +1 -1
- package/dist/cjs/log-codes.js +4 -0
- package/dist/cjs/mssql-seed.d.ts +27 -0
- package/dist/cjs/mssql-seed.js +118 -0
- package/dist/cjs/mssql.d.ts +7 -7
- package/dist/cjs/mssql.js +365 -53
- package/dist/cjs/mysql-seed.d.ts +25 -0
- package/dist/cjs/mysql-seed.js +169 -0
- package/dist/cjs/mysql.d.ts +18 -6
- package/dist/cjs/mysql.js +602 -94
- package/dist/cjs/neon-http/client.d.ts +95 -0
- package/dist/cjs/neon-http/client.js +291 -0
- package/dist/cjs/neon-http/sql.d.ts +3 -0
- package/dist/cjs/neon-http/sql.js +116 -0
- package/dist/cjs/neon-http.d.ts +5 -0
- package/dist/cjs/neon-http.js +8 -0
- package/dist/cjs/neon-ws/load-driver.cjs +44 -0
- package/dist/cjs/neon-ws/load-driver.d.cts +9 -0
- package/dist/cjs/neon-ws/recovery.d.ts +14 -0
- package/dist/cjs/neon-ws/recovery.js +69 -0
- package/dist/cjs/neon-ws/snapshot.d.ts +3 -0
- package/dist/cjs/neon-ws/snapshot.js +17 -0
- package/dist/cjs/neon-ws/transport.d.ts +112 -0
- package/dist/cjs/neon-ws/transport.js +290 -0
- package/dist/cjs/neon-ws.d.ts +26 -0
- package/dist/cjs/neon-ws.js +189 -0
- package/dist/cjs/nested-write.d.ts +34 -3
- package/dist/cjs/nested-write.js +117 -24
- package/dist/cjs/notification-hub/consumer.d.ts +22 -0
- package/dist/cjs/notification-hub/consumer.js +111 -0
- package/dist/cjs/notification-hub.d.ts +41 -0
- package/dist/cjs/notification-hub.js +373 -0
- package/dist/cjs/pg-catalog-text.d.ts +96 -0
- package/dist/cjs/pg-catalog-text.js +213 -0
- package/dist/cjs/pg-types.d.ts +46 -2
- package/dist/cjs/pipeline-submittable.d.ts +15 -5
- package/dist/cjs/pipeline-submittable.js +103 -48
- package/dist/cjs/pipeline.d.ts +5 -2
- package/dist/cjs/pipeline.js +111 -41
- package/dist/cjs/plan-divergence.d.ts +1 -1
- package/dist/cjs/plan-divergence.js +1 -1
- package/dist/cjs/powdb-introspect.d.ts +1 -1
- package/dist/cjs/powdb-introspect.js +5 -5
- package/dist/cjs/powdb-shared.d.ts +5 -5
- package/dist/cjs/powdb-shared.js +6 -5
- package/dist/cjs/powdb.d.ts +28 -10
- package/dist/cjs/powdb.js +80 -28
- package/dist/cjs/powql.d.ts +50 -28
- package/dist/cjs/powql.js +47 -33
- package/dist/cjs/prisma-compat.js +4 -5
- package/dist/cjs/prisma-schema-fingerprint.d.ts +1 -1
- package/dist/cjs/prisma-schema-fingerprint.js +1 -1
- package/dist/cjs/query/aggregates.d.ts +0 -13
- package/dist/cjs/query/aggregates.js +105 -238
- package/dist/cjs/query/batched-loader.d.ts +1 -1
- package/dist/cjs/query/batched-loader.js +18 -20
- package/dist/cjs/query/builder.d.ts +108 -144
- package/dist/cjs/query/builder.js +592 -893
- package/dist/cjs/query/compound-unique.d.ts +18 -3
- package/dist/cjs/query/compound-unique.js +110 -43
- package/dist/cjs/query/cursor-tuple.d.ts +17 -0
- package/dist/cjs/query/cursor-tuple.js +121 -0
- package/dist/cjs/query/expr.d.ts +2 -0
- package/dist/cjs/query/expr.js +40 -23
- package/dist/cjs/query/filters.d.ts +39 -7
- package/dist/cjs/query/filters.js +77 -19
- package/dist/cjs/query/normalize-args.d.ts +1 -1
- package/dist/cjs/query/normalize-args.js +7 -5
- package/dist/cjs/query/option-surface.d.ts +1 -1
- package/dist/cjs/query/option-surface.js +5 -3
- package/dist/cjs/query/pg-type-parsers.d.ts +126 -0
- package/dist/cjs/query/pg-type-parsers.js +306 -0
- package/dist/cjs/query/relation-names.d.ts +4 -2
- package/dist/cjs/query/relation-names.js +21 -12
- package/dist/cjs/query/relations.d.ts +19 -7
- package/dist/cjs/query/relations.js +329 -260
- package/dist/cjs/query/row-lock.js +3 -3
- package/dist/cjs/query/sql-comment.js +3 -3
- package/dist/cjs/query/stream-idle.d.ts +11 -1
- package/dist/cjs/query/stream-idle.js +53 -13
- package/dist/cjs/query/stream-signal.d.ts +21 -0
- package/dist/cjs/query/stream-signal.js +132 -0
- package/dist/cjs/query/temporal-parsers.d.ts +101 -0
- package/dist/cjs/query/temporal-parsers.js +362 -0
- package/dist/cjs/query/types.d.ts +67 -20
- package/dist/cjs/query/utils.d.ts +2 -878
- package/dist/cjs/query/utils.js +25 -2058
- package/dist/cjs/query/warn-registry.d.ts +1 -1
- package/dist/cjs/query/warn-registry.js +1 -1
- package/dist/cjs/query/where-compile.d.ts +4 -1
- package/dist/cjs/query/where-compile.js +18 -14
- package/dist/cjs/query/where.d.ts +14 -7
- package/dist/cjs/query/where.js +244 -436
- package/dist/cjs/query/writes.d.ts +33 -2
- package/dist/cjs/query/writes.js +104 -77
- package/dist/cjs/query-utils.d.ts +687 -0
- package/dist/cjs/query-utils.js +1444 -0
- package/dist/cjs/realtime.d.ts +1 -1
- package/dist/cjs/realtime.js +3 -3
- package/dist/cjs/schema-builder.js +2 -2
- package/dist/cjs/schema-metadata.d.ts +13 -3
- package/dist/cjs/schema-metadata.js +33 -5
- package/dist/cjs/schema-sql.d.ts +15 -24
- package/dist/cjs/schema-sql.js +53 -63
- package/dist/cjs/schema.d.ts +37 -2
- package/dist/cjs/schema.js +29 -2
- package/dist/cjs/seed.js +5 -5
- package/dist/cjs/serverless.d.ts +24 -71
- package/dist/cjs/serverless.js +24 -71
- package/dist/cjs/sql.d.ts +111 -0
- package/dist/cjs/sql.js +335 -0
- package/dist/cjs/sqlite-seed.d.ts +17 -0
- package/dist/cjs/sqlite-seed.js +31 -0
- package/dist/cjs/sqlite.d.ts +32 -19
- package/dist/cjs/sqlite.js +865 -652
- package/dist/cjs/supplied-pool-types.js +10 -9
- package/dist/cjs/transaction-control.js +6 -1
- package/dist/cjs/transaction-outcome.d.ts +61 -0
- package/dist/cjs/transaction-outcome.js +239 -0
- package/dist/cjs/transaction-state.d.ts +82 -13
- package/dist/cjs/transaction-state.js +222 -56
- package/dist/cjs/transaction-transport.d.ts +38 -0
- package/dist/cjs/transaction-transport.js +157 -0
- package/dist/cjs/typed-sql.d.ts +1 -1
- package/dist/cjs/typed-sql.js +1 -1
- package/dist/cli/compile-query.d.ts +6 -3
- package/dist/cli/compile-query.js +25 -4
- package/dist/cli/config.d.ts +35 -10
- package/dist/cli/config.js +170 -43
- package/dist/cli/d1-config.d.ts +14 -0
- package/dist/cli/d1-config.js +6 -0
- package/dist/cli/d1-local.d.ts +31 -0
- package/dist/cli/d1-local.js +285 -0
- package/dist/cli/d1-migrations.d.ts +16 -0
- package/dist/cli/d1-migrations.js +151 -0
- package/dist/cli/d1-project.d.ts +23 -0
- package/dist/cli/d1-project.js +304 -0
- package/dist/cli/d1-seed.d.ts +35 -0
- package/dist/cli/d1-seed.js +213 -0
- package/dist/cli/destructive.js +1 -2
- package/dist/cli/error-catalog.d.ts +3 -3
- package/dist/cli/error-catalog.js +21 -3
- package/dist/cli/index.d.ts +13 -8
- package/dist/cli/index.js +500 -71
- package/dist/cli/libsql-migrate-command.d.ts +5 -0
- package/dist/cli/libsql-migrate-command.js +77 -0
- package/dist/cli/libsql-migrate-status.d.ts +33 -0
- package/dist/cli/libsql-migrate-status.js +182 -0
- package/dist/cli/libsql-migrate.d.ts +14 -0
- package/dist/cli/libsql-migrate.js +516 -0
- package/dist/cli/libsql-project-config.d.ts +11 -0
- package/dist/cli/libsql-project-config.js +55 -0
- package/dist/cli/libsql-project.d.ts +52 -0
- package/dist/cli/libsql-project.js +391 -0
- package/dist/cli/libsql-seed-command.d.ts +29 -0
- package/dist/cli/libsql-seed-command.js +85 -0
- package/dist/cli/loader.d.ts +6 -5
- package/dist/cli/loader.js +50 -9
- package/dist/cli/mcp.d.ts +16 -1
- package/dist/cli/mcp.js +220 -127
- package/dist/cli/migrate.d.ts +2 -2
- package/dist/cli/migrate.js +29 -14
- package/dist/cli/mssql-doctor.d.ts +44 -0
- package/dist/cli/mssql-doctor.js +237 -0
- package/dist/cli/mssql-migrate-command.d.ts +9 -0
- package/dist/cli/mssql-migrate-command.js +192 -0
- package/dist/cli/mssql-migrate-connection.d.ts +51 -0
- package/dist/cli/mssql-migrate-connection.js +245 -0
- package/dist/cli/mssql-migrate-sql.d.ts +12 -0
- package/dist/cli/mssql-migrate-sql.js +275 -0
- package/dist/cli/mssql-migrate.d.ts +45 -0
- package/dist/cli/mssql-migrate.js +290 -0
- package/dist/cli/mssql-project.d.ts +34 -0
- package/dist/cli/mssql-project.js +160 -0
- package/dist/cli/mssql-seed.d.ts +7 -0
- package/dist/cli/mssql-seed.js +73 -0
- package/dist/cli/mssql-tools.d.ts +37 -0
- package/dist/cli/mssql-tools.js +341 -0
- package/dist/cli/mysql-doctor.d.ts +48 -0
- package/dist/cli/mysql-doctor.js +316 -0
- package/dist/cli/mysql-migrate-command.d.ts +7 -0
- package/dist/cli/mysql-migrate-command.js +285 -0
- package/dist/cli/mysql-migrate-sql.d.ts +18 -0
- package/dist/cli/mysql-migrate-sql.js +162 -0
- package/dist/cli/mysql-migrate.d.ts +77 -0
- package/dist/cli/mysql-migrate.js +606 -0
- package/dist/cli/mysql-project.d.ts +49 -0
- package/dist/cli/mysql-project.js +272 -0
- package/dist/cli/mysql-push-command.d.ts +7 -0
- package/dist/cli/mysql-push-command.js +89 -0
- package/dist/cli/mysql-push.d.ts +15 -0
- package/dist/cli/mysql-push.js +95 -0
- package/dist/cli/mysql-schema-command.d.ts +5 -0
- package/dist/cli/mysql-schema-command.js +54 -0
- package/dist/cli/mysql-schema-ddl.d.ts +37 -0
- package/dist/cli/mysql-schema-ddl.js +227 -0
- package/dist/cli/mysql-schema-snapshot.d.ts +21 -0
- package/dist/cli/mysql-schema-snapshot.js +119 -0
- package/dist/cli/mysql-schema.d.ts +27 -0
- package/dist/cli/mysql-schema.js +200 -0
- package/dist/cli/mysql-seed-loader.cjs +25 -0
- package/dist/cli/mysql-seed-loader.d.cts +3 -0
- package/dist/cli/mysql-seed.d.ts +6 -0
- package/dist/cli/mysql-seed.js +75 -0
- package/dist/cli/mysql-tools.d.ts +44 -0
- package/dist/cli/mysql-tools.js +290 -0
- package/dist/cli/no-follow.d.ts +29 -0
- package/dist/cli/no-follow.js +67 -0
- package/dist/cli/pii-predicate-guard.d.ts +1 -1
- package/dist/cli/pii-predicate-guard.js +2 -2
- package/dist/cli/pii-tags.d.ts +2 -2
- package/dist/cli/pii-tags.js +1 -1
- package/dist/cli/prisma-schema.js +2 -2
- package/dist/cli/sql-statements.d.ts +1 -1
- package/dist/cli/sql-statements.js +1 -1
- package/dist/cli/sqlite-doctor.d.ts +35 -0
- package/dist/cli/sqlite-doctor.js +392 -0
- package/dist/cli/sqlite-migrate-command.d.ts +4 -0
- package/dist/cli/sqlite-migrate-command.js +171 -0
- package/dist/cli/sqlite-migrate.d.ts +61 -0
- package/dist/cli/sqlite-migrate.js +681 -0
- package/dist/cli/sqlite-project.d.ts +42 -0
- package/dist/cli/sqlite-project.js +244 -0
- package/dist/cli/sqlite-schema-command.d.ts +4 -0
- package/dist/cli/sqlite-schema-command.js +79 -0
- package/dist/cli/sqlite-schema-ddl.d.ts +25 -0
- package/dist/cli/sqlite-schema-ddl.js +248 -0
- package/dist/cli/sqlite-schema.d.ts +25 -0
- package/dist/cli/sqlite-schema.js +330 -0
- package/dist/cli/sqlite-seed.d.ts +4 -0
- package/dist/cli/sqlite-seed.js +57 -0
- package/dist/cli/sqlite-tools.d.ts +24 -0
- package/dist/cli/sqlite-tools.js +163 -0
- package/dist/cli/studio.js +9 -9
- package/dist/cli/tool-capabilities.d.ts +72 -0
- package/dist/cli/tool-capabilities.js +114 -0
- package/dist/cli/tool-command.d.ts +11 -0
- package/dist/cli/tool-command.js +45 -0
- package/dist/cli/ui.d.ts +1 -1
- package/dist/cli/ui.js +1 -1
- package/dist/client.d.ts +20 -20
- package/dist/client.js +62 -341
- package/dist/connection-url.d.ts +1 -1
- package/dist/connection-url.js +1 -1
- package/dist/core.d.ts +58 -0
- package/dist/core.js +220 -0
- package/dist/d1/catalog-metadata.d.ts +5 -0
- package/dist/d1/catalog-metadata.js +227 -0
- package/dist/d1/catalog.d.ts +15 -0
- package/dist/d1/catalog.js +82 -0
- package/dist/d1/generate.d.ts +8 -0
- package/dist/d1/generate.js +160 -0
- package/dist/d1/introspect.d.ts +21 -0
- package/dist/d1/introspect.js +71 -0
- package/dist/d1/migrate.d.ts +29 -0
- package/dist/d1/migrate.js +217 -0
- package/dist/d1/migrations/sql.d.ts +2 -0
- package/dist/d1/migrations/sql.js +106 -0
- package/dist/d1/pool.d.ts +14 -0
- package/dist/d1/pool.js +86 -0
- package/dist/d1/sql.d.ts +5 -0
- package/dist/d1/sql.js +135 -0
- package/dist/d1/sqlite-dialect.d.ts +16 -0
- package/dist/d1/sqlite-dialect.js +572 -0
- package/dist/d1/types.d.ts +29 -0
- package/dist/d1/types.js +1 -0
- package/dist/d1.d.ts +53 -0
- package/dist/d1.js +215 -0
- package/dist/dialect.d.ts +33 -5
- package/dist/dialect.js +6 -4
- package/dist/errors.d.ts +38 -1
- package/dist/errors.js +68 -17
- package/dist/generate.d.ts +19 -3
- package/dist/generate.js +330 -97
- package/dist/global-filters-config.js +2 -2
- package/dist/index-advisor.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/introspect.d.ts +59 -356
- package/dist/introspect.js +116 -943
- package/dist/libsql/bindings.d.ts +2 -0
- package/dist/libsql/bindings.js +75 -0
- package/dist/libsql/dialect.d.ts +3 -0
- package/dist/libsql/dialect.js +45 -0
- package/dist/libsql/generate.d.ts +4 -0
- package/dist/libsql/generate.js +53 -0
- package/dist/libsql/introspect.d.ts +16 -0
- package/dist/libsql/introspect.js +289 -0
- package/dist/libsql/pool.d.ts +42 -0
- package/dist/libsql/pool.js +270 -0
- package/dist/libsql/seed-cleanup.d.ts +2 -0
- package/dist/libsql/seed-cleanup.js +15 -0
- package/dist/libsql/values.d.ts +20 -0
- package/dist/libsql/values.js +68 -0
- package/dist/libsql-seed.d.ts +19 -0
- package/dist/libsql-seed.js +46 -0
- package/dist/libsql.d.ts +28 -0
- package/dist/libsql.js +79 -0
- package/dist/live-query.d.ts +33 -0
- package/dist/live-query.js +169 -0
- package/dist/log-codes.d.ts +1 -1
- package/dist/log-codes.js +4 -0
- package/dist/mssql-seed.d.ts +27 -0
- package/dist/mssql-seed.js +114 -0
- package/dist/mssql.d.ts +7 -7
- package/dist/mssql.js +366 -54
- package/dist/mysql-seed.d.ts +25 -0
- package/dist/mysql-seed.js +165 -0
- package/dist/mysql.d.ts +18 -6
- package/dist/mysql.js +603 -95
- package/dist/neon-http/client.d.ts +95 -0
- package/dist/neon-http/client.js +286 -0
- package/dist/neon-http/sql.d.ts +3 -0
- package/dist/neon-http/sql.js +112 -0
- package/dist/neon-http.d.ts +5 -0
- package/dist/neon-http.js +2 -0
- package/dist/neon-ws/load-driver.cjs +11 -0
- package/dist/neon-ws/load-driver.d.cts +9 -0
- package/dist/neon-ws/recovery.d.ts +14 -0
- package/dist/neon-ws/recovery.js +66 -0
- package/dist/neon-ws/snapshot.d.ts +3 -0
- package/dist/neon-ws/snapshot.js +15 -0
- package/dist/neon-ws/transport.d.ts +112 -0
- package/dist/neon-ws/transport.js +286 -0
- package/dist/neon-ws.d.ts +26 -0
- package/dist/neon-ws.js +182 -0
- package/dist/nested-write.d.ts +34 -3
- package/dist/nested-write.js +114 -22
- package/dist/notification-hub/consumer.d.ts +22 -0
- package/dist/notification-hub/consumer.js +106 -0
- package/dist/notification-hub.d.ts +41 -0
- package/dist/notification-hub.js +370 -0
- package/dist/pg-catalog-text.d.ts +96 -0
- package/dist/pg-catalog-text.js +208 -0
- package/dist/pg-types.d.ts +46 -2
- package/dist/pipeline-submittable.d.ts +15 -5
- package/dist/pipeline-submittable.js +105 -50
- package/dist/pipeline.d.ts +5 -2
- package/dist/pipeline.js +113 -43
- package/dist/plan-divergence.d.ts +1 -1
- package/dist/plan-divergence.js +1 -1
- package/dist/powdb-introspect.d.ts +1 -1
- package/dist/powdb-introspect.js +5 -5
- package/dist/powdb-shared.d.ts +5 -5
- package/dist/powdb-shared.js +6 -5
- package/dist/powdb.d.ts +28 -10
- package/dist/powdb.js +80 -28
- package/dist/powql.d.ts +50 -28
- package/dist/powql.js +49 -35
- package/dist/prisma-compat.js +4 -5
- package/dist/prisma-schema-fingerprint.d.ts +1 -1
- package/dist/prisma-schema-fingerprint.js +1 -1
- package/dist/query/aggregates.d.ts +0 -13
- package/dist/query/aggregates.js +97 -230
- package/dist/query/batched-loader.d.ts +1 -1
- package/dist/query/batched-loader.js +5 -7
- package/dist/query/builder.d.ts +108 -144
- package/dist/query/builder.js +563 -864
- package/dist/query/compound-unique.d.ts +18 -3
- package/dist/query/compound-unique.js +99 -33
- package/dist/query/cursor-tuple.d.ts +17 -0
- package/dist/query/cursor-tuple.js +114 -0
- package/dist/query/expr.d.ts +2 -0
- package/dist/query/expr.js +32 -16
- package/dist/query/filters.d.ts +39 -7
- package/dist/query/filters.js +69 -14
- package/dist/query/normalize-args.d.ts +1 -1
- package/dist/query/normalize-args.js +4 -2
- package/dist/query/option-surface.d.ts +1 -1
- package/dist/query/option-surface.js +4 -2
- package/dist/query/pg-type-parsers.d.ts +126 -0
- package/dist/query/pg-type-parsers.js +296 -0
- package/dist/query/relation-names.d.ts +4 -2
- package/dist/query/relation-names.js +15 -7
- package/dist/query/relations.d.ts +19 -7
- package/dist/query/relations.js +293 -227
- package/dist/query/row-lock.js +1 -1
- package/dist/query/sql-comment.js +1 -1
- package/dist/query/stream-idle.d.ts +11 -1
- package/dist/query/stream-idle.js +51 -13
- package/dist/query/stream-signal.d.ts +21 -0
- package/dist/query/stream-signal.js +125 -0
- package/dist/query/temporal-parsers.d.ts +101 -0
- package/dist/query/temporal-parsers.js +354 -0
- package/dist/query/types.d.ts +67 -20
- package/dist/query/utils.d.ts +2 -878
- package/dist/query/utils.js +5 -2003
- package/dist/query/warn-registry.d.ts +1 -1
- package/dist/query/warn-registry.js +1 -1
- package/dist/query/where-compile.d.ts +4 -1
- package/dist/query/where-compile.js +14 -10
- package/dist/query/where.d.ts +14 -7
- package/dist/query/where.js +236 -430
- package/dist/query/writes.d.ts +33 -2
- package/dist/query/writes.js +90 -65
- package/dist/query-utils.d.ts +687 -0
- package/dist/query-utils.js +1390 -0
- package/dist/realtime.d.ts +1 -1
- package/dist/realtime.js +3 -3
- package/dist/schema-builder.js +2 -2
- package/dist/schema-metadata.d.ts +13 -3
- package/dist/schema-metadata.js +33 -5
- package/dist/schema-sql.d.ts +15 -24
- package/dist/schema-sql.js +50 -60
- package/dist/schema.d.ts +37 -2
- package/dist/schema.js +29 -2
- package/dist/seed.js +5 -5
- package/dist/serverless.d.ts +24 -71
- package/dist/serverless.js +24 -71
- package/dist/sql.d.ts +111 -0
- package/dist/sql.js +321 -0
- package/dist/sqlite-seed.d.ts +17 -0
- package/dist/sqlite-seed.js +27 -0
- package/dist/sqlite.d.ts +32 -19
- package/dist/sqlite.js +859 -648
- package/dist/supplied-pool-types.js +2 -1
- package/dist/transaction-control.js +6 -1
- package/dist/transaction-outcome.d.ts +61 -0
- package/dist/transaction-outcome.js +234 -0
- package/dist/transaction-state.d.ts +82 -13
- package/dist/transaction-state.js +220 -57
- package/dist/transaction-transport.d.ts +38 -0
- package/dist/transaction-transport.js +153 -0
- package/dist/typed-sql.d.ts +1 -1
- package/dist/typed-sql.js +1 -1
- package/package.json +239 -13
- package/skills/turbine-orm/SKILL.md +6 -5
|
@@ -467,7 +467,7 @@ function searchPathListValue(schema, alsoResolveIn) {
|
|
|
467
467
|
* layout (`public, extensions`) a `citext` / `vector` / `hstore` / `postgis`
|
|
468
468
|
* column, an extension opclass in a CREATE INDEX, or a CHECK calling an
|
|
469
469
|
* extension function all failed under a pin that the same DDL did not need
|
|
470
|
-
* without one.
|
|
470
|
+
* without one. Both checks use this predicate to keep that decision consistent.
|
|
471
471
|
*
|
|
472
472
|
* The inherited path cannot be read before the connection exists, so
|
|
473
473
|
* `alsoResolveIn` is the caller's job: connect once unpinned, `SHOW
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supplied-transport query client. This entry resolves no database driver.
|
|
3
|
+
* Transactions, streaming cursors and realtime require a transport-specific
|
|
4
|
+
* entry with an explicit session contract.
|
|
5
|
+
*/
|
|
6
|
+
import type { PgCompatPool } from './pg-types.js';
|
|
7
|
+
import { QueryInterface } from './query/builder.js';
|
|
8
|
+
import type { MiddlewareFn, QueryInterfaceOptions } from './query/deferred.js';
|
|
9
|
+
import type { SchemaMetadata } from './schema.js';
|
|
10
|
+
import { TypedSqlQuery } from './typed-sql.js';
|
|
11
|
+
export type { Dialect } from './dialect.js';
|
|
12
|
+
export type { PgCompatPool, PgCompatPoolClient, PgCompatQueryResult } from './pg-types.js';
|
|
13
|
+
export type { QueryInterface, QueryInterfaceOptions, SchemaMetadata };
|
|
14
|
+
export type CoreOptions = Omit<QueryInterfaceOptions, '_txScoped' | '_onQuery' | '_sqlCommenter' | 'queryInterfaceFactory'> & {
|
|
15
|
+
/** Caller retains the pool by default. Client ownership closes it once. */
|
|
16
|
+
ownership?: 'caller' | 'client';
|
|
17
|
+
/** Decode PostgreSQL relation wire values using this transport's parser. */
|
|
18
|
+
getTypeParser?: (oid: number, format: 'text') => (value: string) => unknown;
|
|
19
|
+
};
|
|
20
|
+
/** Ordinary SQL execution on an explicitly supplied transport. */
|
|
21
|
+
export declare class CoreClient {
|
|
22
|
+
readonly pool: PgCompatPool;
|
|
23
|
+
readonly schema: SchemaMetadata;
|
|
24
|
+
private readonly accessors;
|
|
25
|
+
private readonly middlewares;
|
|
26
|
+
private readonly options;
|
|
27
|
+
private readonly dialect;
|
|
28
|
+
private readonly queryPool;
|
|
29
|
+
private readonly pending;
|
|
30
|
+
private readonly ownsPool;
|
|
31
|
+
private closed;
|
|
32
|
+
private closing?;
|
|
33
|
+
constructor(pool: PgCompatPool, schema: SchemaMetadata, options?: CoreOptions);
|
|
34
|
+
private unsupported;
|
|
35
|
+
private assertOpen;
|
|
36
|
+
private execute;
|
|
37
|
+
table<T extends object = Record<string, unknown>>(name: string): QueryInterface<T>;
|
|
38
|
+
$use(middleware: MiddlewareFn): void;
|
|
39
|
+
sql<T extends Record<string, unknown> = Record<string, unknown>>(strings: TemplateStringsArray, ...values: unknown[]): TypedSqlQuery<T>;
|
|
40
|
+
raw<T extends Record<string, unknown> = Record<string, unknown>>(strings: TemplateStringsArray, ...values: unknown[]): Promise<T[]>;
|
|
41
|
+
rawUnsafe<T extends Record<string, unknown> = Record<string, unknown>>(text: string, ...values: unknown[]): Promise<T[]>;
|
|
42
|
+
rawQuery<T extends object = Record<string, unknown>>(text: string, values?: readonly unknown[]): Promise<{
|
|
43
|
+
rows: T[];
|
|
44
|
+
rowCount: number | null;
|
|
45
|
+
}>;
|
|
46
|
+
private rawParams;
|
|
47
|
+
$transaction(..._args: unknown[]): never;
|
|
48
|
+
transaction(..._args: unknown[]): never;
|
|
49
|
+
pipeline(..._args: unknown[]): never;
|
|
50
|
+
$listen(..._args: unknown[]): never;
|
|
51
|
+
$notify(..._args: unknown[]): never;
|
|
52
|
+
$withSession(..._args: unknown[]): never;
|
|
53
|
+
$connection(..._args: unknown[]): never;
|
|
54
|
+
/** Seal immediately, drain admitted work, and close only a client-owned pool. */
|
|
55
|
+
disconnect(): Promise<void>;
|
|
56
|
+
end(): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
export declare function turbineCore(pool: PgCompatPool, schema: SchemaMetadata, options?: CoreOptions): CoreClient;
|
package/dist/cjs/core.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Supplied-transport query client. This entry resolves no database driver.
|
|
4
|
+
* Transactions, streaming cursors and realtime require a transport-specific
|
|
5
|
+
* entry with an explicit session contract.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.CoreClient = void 0;
|
|
9
|
+
exports.turbineCore = turbineCore;
|
|
10
|
+
const dialect_js_1 = require("./dialect.js");
|
|
11
|
+
const errors_js_1 = require("./errors.js");
|
|
12
|
+
const global_filters_config_js_1 = require("./global-filters-config.js");
|
|
13
|
+
const nested_write_js_1 = require("./nested-write.js");
|
|
14
|
+
const builder_js_1 = require("./query/builder.js");
|
|
15
|
+
const query_utils_js_1 = require("./query-utils.js");
|
|
16
|
+
const transaction_control_js_1 = require("./transaction-control.js");
|
|
17
|
+
const typed_sql_js_1 = require("./typed-sql.js");
|
|
18
|
+
/** Ordinary SQL execution on an explicitly supplied transport. */
|
|
19
|
+
class CoreClient {
|
|
20
|
+
pool;
|
|
21
|
+
schema;
|
|
22
|
+
accessors = new Map();
|
|
23
|
+
middlewares = [];
|
|
24
|
+
options;
|
|
25
|
+
dialect;
|
|
26
|
+
queryPool;
|
|
27
|
+
pending = new Set();
|
|
28
|
+
ownsPool;
|
|
29
|
+
closed = false;
|
|
30
|
+
closing;
|
|
31
|
+
constructor(pool, schema, options = {}) {
|
|
32
|
+
this.pool = pool;
|
|
33
|
+
this.schema = schema;
|
|
34
|
+
if (!pool ||
|
|
35
|
+
typeof pool.query !== 'function' ||
|
|
36
|
+
typeof pool.connect !== 'function' ||
|
|
37
|
+
typeof pool.end !== 'function') {
|
|
38
|
+
throw new errors_js_1.ValidationError('turbineCore requires a supplied pool with query(), connect() and end().');
|
|
39
|
+
}
|
|
40
|
+
if (!schema || typeof schema !== 'object' || !schema.tables || !schema.enums) {
|
|
41
|
+
throw new errors_js_1.ValidationError('turbineCore requires schema metadata with tables and enums.');
|
|
42
|
+
}
|
|
43
|
+
if (options.ownership !== undefined && options.ownership !== 'caller' && options.ownership !== 'client') {
|
|
44
|
+
throw new errors_js_1.ValidationError('ownership must be caller or client.');
|
|
45
|
+
}
|
|
46
|
+
this.ownsPool = options.ownership === 'client';
|
|
47
|
+
const dialect = options.dialect ?? dialect_js_1.postgresDialect;
|
|
48
|
+
(0, dialect_js_1.assertDialectCapabilities)(dialect);
|
|
49
|
+
// A pg-free client never borrows an unrelated module copy's native parser.
|
|
50
|
+
// Other dialects retain their adapter-owned wire rules verbatim.
|
|
51
|
+
this.dialect = {
|
|
52
|
+
...dialect,
|
|
53
|
+
capabilities: { ...dialect.capabilities, backendCancel: false },
|
|
54
|
+
rowLockModes: [],
|
|
55
|
+
supportsListenNotify: false,
|
|
56
|
+
supportsRLS: false,
|
|
57
|
+
supportsAdvisoryLock: false,
|
|
58
|
+
supportsPlanCacheMode: false,
|
|
59
|
+
...(dialect === dialect_js_1.postgresDialect
|
|
60
|
+
? {
|
|
61
|
+
jsonWireRule: (type) => {
|
|
62
|
+
const oid = (0, query_utils_js_1.jsonWireCoercionOid)(type);
|
|
63
|
+
if (oid === undefined)
|
|
64
|
+
return undefined;
|
|
65
|
+
return {
|
|
66
|
+
sql: (ref) => `${ref}::text`,
|
|
67
|
+
decode: (value) => {
|
|
68
|
+
if (typeof value !== 'string')
|
|
69
|
+
return value;
|
|
70
|
+
if (!options.getTypeParser)
|
|
71
|
+
throw this.unsupported('PostgreSQL relation wire decoding; supply getTypeParser');
|
|
72
|
+
return options.getTypeParser(oid, 'text')(value);
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
: {}),
|
|
78
|
+
};
|
|
79
|
+
const globalFilters = (0, global_filters_config_js_1.normalizeGlobalFilters)(options.globalFilters, schema, {
|
|
80
|
+
QueryInterface: builder_js_1.QueryInterface,
|
|
81
|
+
dialect: this.dialect,
|
|
82
|
+
utcTimestamps: options.utcTimestamps,
|
|
83
|
+
});
|
|
84
|
+
this.options = { ...options, dialect: this.dialect, globalFilters, preparedStatements: false };
|
|
85
|
+
// Internal options are never accepted from untyped callers either.
|
|
86
|
+
delete this.options._txScoped;
|
|
87
|
+
delete this.options.queryInterfaceFactory;
|
|
88
|
+
delete this.options._onQuery;
|
|
89
|
+
delete this.options._sqlCommenter;
|
|
90
|
+
this.queryPool = {
|
|
91
|
+
query: (text, values) => this.execute(text, values),
|
|
92
|
+
connect: async () => {
|
|
93
|
+
throw this.unsupported('Connection checkout / implicit transactions');
|
|
94
|
+
},
|
|
95
|
+
end: () => this.disconnect(),
|
|
96
|
+
};
|
|
97
|
+
for (const name of Object.keys(schema.tables)) {
|
|
98
|
+
const accessor = (0, global_filters_config_js_1.tableAccessorName)(name);
|
|
99
|
+
if (!(accessor in this))
|
|
100
|
+
Object.defineProperty(this, accessor, { enumerable: true, get: () => this.table(name) });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
unsupported(feature) {
|
|
104
|
+
return new errors_js_1.UnsupportedFeatureError(feature, this.dialect?.name ?? 'supplied transport', 'Use a transport-specific entry with the required session contract.');
|
|
105
|
+
}
|
|
106
|
+
assertOpen() {
|
|
107
|
+
if (this.closed)
|
|
108
|
+
throw new errors_js_1.ValidationError('This supplied-transport client has been disconnected.');
|
|
109
|
+
}
|
|
110
|
+
execute(text, values = []) {
|
|
111
|
+
this.assertOpen();
|
|
112
|
+
const control = (0, transaction_control_js_1.findTransactionControl)(text, this.dialect.capabilities.statementSyntax ?? 'postgresql')[0];
|
|
113
|
+
if (control)
|
|
114
|
+
throw this.unsupported(`${control.label} transaction control`);
|
|
115
|
+
const operation = Promise.resolve()
|
|
116
|
+
.then(() => this.pool.query(text, values))
|
|
117
|
+
.catch((error) => {
|
|
118
|
+
throw (0, errors_js_1.wrapPgError)(error);
|
|
119
|
+
});
|
|
120
|
+
this.pending.add(operation);
|
|
121
|
+
void operation.then(() => this.pending.delete(operation), () => this.pending.delete(operation));
|
|
122
|
+
return operation;
|
|
123
|
+
}
|
|
124
|
+
table(name) {
|
|
125
|
+
this.assertOpen();
|
|
126
|
+
let accessor = this.accessors.get(name);
|
|
127
|
+
if (!accessor) {
|
|
128
|
+
const qi = new builder_js_1.QueryInterface(this.queryPool, name, this.schema, this.middlewares, this.options);
|
|
129
|
+
const client = this;
|
|
130
|
+
accessor = new Proxy(qi, {
|
|
131
|
+
get(target, key, receiver) {
|
|
132
|
+
const member = Reflect.get(target, key, receiver);
|
|
133
|
+
if (typeof member !== 'function')
|
|
134
|
+
return member;
|
|
135
|
+
if (key === 'findManyStream' || key === 'findManyStreamBatches') {
|
|
136
|
+
// biome-ignore lint/correctness/useYield: refusal is deferred until iterator consumption.
|
|
137
|
+
return async function* () {
|
|
138
|
+
client.assertOpen();
|
|
139
|
+
throw client.unsupported('Streaming cursors');
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return (...args) => {
|
|
143
|
+
client.assertOpen();
|
|
144
|
+
const input = args[0];
|
|
145
|
+
const meta = client.schema.tables[name];
|
|
146
|
+
if (meta && (key === 'create' || key === 'update' || key === 'upsert')) {
|
|
147
|
+
if ([input?.data, input?.create, input?.update].some((data) => data && (0, nested_write_js_1.hasRelationFields)(data, meta)) ||
|
|
148
|
+
(key === 'upsert' && target.upsertNeedsLookup(input))) {
|
|
149
|
+
throw client.unsupported('Implicit transactions for nested writes / lookup-first upserts');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return Reflect.apply(member, target, args);
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
this.accessors.set(name, accessor);
|
|
157
|
+
}
|
|
158
|
+
return accessor;
|
|
159
|
+
}
|
|
160
|
+
$use(middleware) {
|
|
161
|
+
this.assertOpen();
|
|
162
|
+
this.middlewares.push(middleware);
|
|
163
|
+
}
|
|
164
|
+
sql(strings, ...values) {
|
|
165
|
+
this.assertOpen();
|
|
166
|
+
const { sql, params } = (0, typed_sql_js_1.buildTypedSql)(strings, values, this.dialect);
|
|
167
|
+
return new typed_sql_js_1.TypedSqlQuery(this.queryPool, sql, this.rawParams(params), false);
|
|
168
|
+
}
|
|
169
|
+
async raw(strings, ...values) {
|
|
170
|
+
return await this.sql(strings, ...values);
|
|
171
|
+
}
|
|
172
|
+
async rawUnsafe(text, ...values) {
|
|
173
|
+
return (await this.rawQuery(text, values)).rows;
|
|
174
|
+
}
|
|
175
|
+
async rawQuery(text, values = []) {
|
|
176
|
+
if (typeof text !== 'string' || !text.trim())
|
|
177
|
+
throw new errors_js_1.ValidationError('rawQuery requires nonempty SQL text.');
|
|
178
|
+
const result = await this.execute(text, this.rawParams([...values]));
|
|
179
|
+
return { rows: result.rows, rowCount: result.rowCount };
|
|
180
|
+
}
|
|
181
|
+
rawParams(values) {
|
|
182
|
+
return this.dialect.capabilities.utcTimestampRewrite && this.options.utcTimestamps !== false
|
|
183
|
+
? (0, typed_sql_js_1.utcDateParams)(values, 'rawQuery')
|
|
184
|
+
: values;
|
|
185
|
+
}
|
|
186
|
+
$transaction(..._args) {
|
|
187
|
+
throw this.unsupported('Interactive / callback / deferred transactions');
|
|
188
|
+
}
|
|
189
|
+
transaction(..._args) {
|
|
190
|
+
throw this.unsupported('Interactive transactions');
|
|
191
|
+
}
|
|
192
|
+
pipeline(..._args) {
|
|
193
|
+
throw this.unsupported('Extended-query pipelines');
|
|
194
|
+
}
|
|
195
|
+
$listen(..._args) {
|
|
196
|
+
throw this.unsupported('LISTEN realtime');
|
|
197
|
+
}
|
|
198
|
+
$notify(..._args) {
|
|
199
|
+
throw this.unsupported('NOTIFY realtime');
|
|
200
|
+
}
|
|
201
|
+
$withSession(..._args) {
|
|
202
|
+
throw this.unsupported('Pinned session context');
|
|
203
|
+
}
|
|
204
|
+
$connection(..._args) {
|
|
205
|
+
throw this.unsupported('Pinned driver connections');
|
|
206
|
+
}
|
|
207
|
+
/** Seal immediately, drain admitted work, and close only a client-owned pool. */
|
|
208
|
+
disconnect() {
|
|
209
|
+
if (this.closing)
|
|
210
|
+
return this.closing;
|
|
211
|
+
this.closed = true;
|
|
212
|
+
this.closing = Promise.allSettled([...this.pending]).then(async () => {
|
|
213
|
+
if (this.ownsPool)
|
|
214
|
+
await this.pool.end();
|
|
215
|
+
});
|
|
216
|
+
return this.closing;
|
|
217
|
+
}
|
|
218
|
+
end() {
|
|
219
|
+
return this.disconnect();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
exports.CoreClient = CoreClient;
|
|
223
|
+
function turbineCore(pool, schema, options) {
|
|
224
|
+
return new CoreClient(pool, schema, options);
|
|
225
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** SQLite catalog facts normalized for the D1 value contract, never a SQLite transport. */
|
|
2
|
+
import { type SchemaMetadata } from '../schema.js';
|
|
3
|
+
import { type D1CatalogSnapshot } from './catalog.js';
|
|
4
|
+
import type { D1IntrospectOptions } from './introspect.js';
|
|
5
|
+
export declare function d1CatalogMetadata(snapshot: D1CatalogSnapshot, options: D1IntrospectOptions): SchemaMetadata;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** SQLite catalog facts normalized for the D1 value contract, never a SQLite transport. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.d1CatalogMetadata = d1CatalogMetadata;
|
|
5
|
+
const catalog_metadata_js_1 = require("../catalog-metadata.js");
|
|
6
|
+
const errors_js_1 = require("../errors.js");
|
|
7
|
+
const schema_js_1 = require("../schema.js");
|
|
8
|
+
const catalog_js_1 = require("./catalog.js");
|
|
9
|
+
const sqlite_dialect_js_1 = require("./sqlite-dialect.js");
|
|
10
|
+
/** Native D1 INTEGER results are numbers. Decimal affinity may retain nonnumeric TEXT. */
|
|
11
|
+
function d1ColumnType(declared, nullable) {
|
|
12
|
+
if (/^(numeric|decimal)/i.test(declared))
|
|
13
|
+
return nullable ? 'number | string | null' : 'number | string';
|
|
14
|
+
return (0, sqlite_dialect_js_1.sqliteTypeToTs)(declared, nullable);
|
|
15
|
+
}
|
|
16
|
+
const sqliteName = (name) => name.replace(/[A-Z]/g, (letter) => letter.toLowerCase());
|
|
17
|
+
function isSqliteDateType(type) {
|
|
18
|
+
return (0, schema_js_1.isDateType)(type.toLowerCase()) || /(timestamp|datetime|date)/i.test(type);
|
|
19
|
+
}
|
|
20
|
+
function d1CatalogMetadata(snapshot, options) {
|
|
21
|
+
const catalog = (sql) => snapshot.read(sql);
|
|
22
|
+
// ----- Tables (skip SQLite internal + the migration tracking table) -----
|
|
23
|
+
const catalogTables = catalog(catalog_js_1.CATALOG_TABLES);
|
|
24
|
+
const views = catalog(catalog_js_1.CATALOG_VIEWS);
|
|
25
|
+
if (views.some((view) => options.include?.includes(view.name)))
|
|
26
|
+
throw new errors_js_1.UnsupportedFeatureError('View introspection', 'd1', 'Only main base tables are implemented.');
|
|
27
|
+
const candidateTables = catalogTables.map((t) => t.name);
|
|
28
|
+
const tableDefinitions = new Map(catalogTables.map((t) => [t.name, t.sql ?? '']));
|
|
29
|
+
// include / exclude + default bookkeeping-table exclusions, shared with
|
|
30
|
+
// every other introspector via applyTableFilters.
|
|
31
|
+
const tableNames = (0, catalog_metadata_js_1.applyTableFilters)(candidateTables, options);
|
|
32
|
+
const tableSet = new Set(tableNames);
|
|
33
|
+
const flagsList = catalog('PRAGMA main.table_list');
|
|
34
|
+
for (const name of tableNames) {
|
|
35
|
+
if (flagsList.find((t) => t.name === name)?.type !== 'table')
|
|
36
|
+
throw new errors_js_1.UnsupportedFeatureError('Virtual or shadow table introspection', 'd1', (0, catalog_metadata_js_1.printableCatalogName)(name));
|
|
37
|
+
}
|
|
38
|
+
const tableFlags = new Map(flagsList.map((t) => [t.name, t]));
|
|
39
|
+
const columnsByTable = new Map();
|
|
40
|
+
const pkByTable = new Map();
|
|
41
|
+
const uniqueByTable = new Map();
|
|
42
|
+
const relationUniqueByTable = new Map();
|
|
43
|
+
const indexesByTable = new Map();
|
|
44
|
+
const foreignKeys = [];
|
|
45
|
+
for (const tableName of tableNames) {
|
|
46
|
+
// ----- Columns + primary key -----
|
|
47
|
+
// table_xinfo also exposes computed columns (hidden = 2/3). Virtual-table
|
|
48
|
+
// hidden inputs (1) are not ordinary projected/writable columns.
|
|
49
|
+
const cols = catalog(`PRAGMA main.table_xinfo(${(0, catalog_js_1.q)(tableName)})`).filter((c) => c.hidden !== 1);
|
|
50
|
+
const idxList = catalog(`PRAGMA main.index_list(${(0, catalog_js_1.q)(tableName)})`);
|
|
51
|
+
const flags = tableFlags.get(tableName);
|
|
52
|
+
const primaryColumns = cols.filter((c) => c.pk > 0);
|
|
53
|
+
// Only a sole INTEGER PK on a rowid table aliases the rowid. A separate
|
|
54
|
+
// PK index distinguishes the historical inline PRIMARY KEY DESC exception
|
|
55
|
+
// without parsing DDL; INT/BIGINT and WITHOUT ROWID keys never qualify.
|
|
56
|
+
const rowidKey = flags?.wr === 0 && primaryColumns.length === 1 && !idxList.some((idx) => idx.origin === 'pk')
|
|
57
|
+
? primaryColumns.find((c) => c.type.toUpperCase() === 'INTEGER')?.name
|
|
58
|
+
: undefined;
|
|
59
|
+
const colMeta = [];
|
|
60
|
+
const pkCols = [];
|
|
61
|
+
for (const c of cols) {
|
|
62
|
+
const declared = c.type || '';
|
|
63
|
+
const generated = c.hidden === 2 || c.hidden === 3;
|
|
64
|
+
const nullable = c.notnull === 0 && c.name !== rowidKey && !(c.pk > 0 && (flags?.wr === 1 || flags?.strict === 1));
|
|
65
|
+
colMeta.push({
|
|
66
|
+
name: c.name,
|
|
67
|
+
field: options.keepColumnNames ? c.name : (0, schema_js_1.snakeToCamel)(c.name),
|
|
68
|
+
dialectType: declared,
|
|
69
|
+
pgType: declared,
|
|
70
|
+
tsType: d1ColumnType(declared, nullable),
|
|
71
|
+
nullable,
|
|
72
|
+
defaultValue: c.dflt_value,
|
|
73
|
+
hasDefault: c.dflt_value !== null || c.name === rowidKey || generated,
|
|
74
|
+
...(c.name === rowidKey ? { isGenerated: true } : {}),
|
|
75
|
+
// This existing flag means computed/non-writable to the generator and
|
|
76
|
+
// write guards, which is true for both SQLite VIRTUAL and STORED values.
|
|
77
|
+
...(generated ? { isGeneratedStored: true } : {}),
|
|
78
|
+
isArray: false,
|
|
79
|
+
arrayType: undefined,
|
|
80
|
+
pgArrayType: 'text[]',
|
|
81
|
+
});
|
|
82
|
+
if (c.pk > 0)
|
|
83
|
+
pkCols.push({ name: c.name, order: c.pk });
|
|
84
|
+
}
|
|
85
|
+
columnsByTable.set(tableName, colMeta);
|
|
86
|
+
pkByTable.set(tableName, pkCols.sort((a, b) => a.order - b.order).map((p) => p.name));
|
|
87
|
+
// ----- Foreign keys -----
|
|
88
|
+
const fks = catalog(`PRAGMA main.foreign_key_list(${(0, catalog_js_1.q)(tableName)})`);
|
|
89
|
+
// Group by FK id (composite FKs share an id), ordered by seq.
|
|
90
|
+
const fkById = new Map();
|
|
91
|
+
for (const fk of fks.sort((a, b) => a.id - b.id || a.seq - b.seq)) {
|
|
92
|
+
let entry = fkById.get(fk.id);
|
|
93
|
+
if (!entry) {
|
|
94
|
+
entry = {
|
|
95
|
+
sourceTable: tableName,
|
|
96
|
+
sourceColumns: [],
|
|
97
|
+
targetTable: tableNames.find((name) => sqliteName(name) === sqliteName(fk.table)) ?? fk.table,
|
|
98
|
+
targetColumns: [],
|
|
99
|
+
constraintName: `fk_${tableName}_${fk.id}`,
|
|
100
|
+
};
|
|
101
|
+
fkById.set(fk.id, entry);
|
|
102
|
+
}
|
|
103
|
+
entry.sourceColumns.push(fk.from);
|
|
104
|
+
// `to` is null when the FK references the target's PK implicitly.
|
|
105
|
+
if (fk.to !== null)
|
|
106
|
+
entry.targetColumns.push(fk.to);
|
|
107
|
+
}
|
|
108
|
+
for (const entry of fkById.values()) {
|
|
109
|
+
if (!tableSet.has(entry.targetTable))
|
|
110
|
+
continue;
|
|
111
|
+
if (entry.targetColumns.length === 0) {
|
|
112
|
+
// Implicit reference → the target table's primary key.
|
|
113
|
+
const targetPk = catalog(`PRAGMA main.table_xinfo(${(0, catalog_js_1.q)(entry.targetTable)})`)
|
|
114
|
+
.filter((c) => c.pk > 0)
|
|
115
|
+
.sort((a, b) => a.pk - b.pk)
|
|
116
|
+
.map((c) => c.name);
|
|
117
|
+
entry.targetColumns = targetPk;
|
|
118
|
+
}
|
|
119
|
+
if (tableSet.has(entry.targetTable)) {
|
|
120
|
+
if (entry.targetColumns.length !== entry.sourceColumns.length)
|
|
121
|
+
throw new errors_js_1.ValidationError(`Unresolvable D1 foreign key: ${(0, catalog_metadata_js_1.printableCatalogName)(entry.constraintName)}.`);
|
|
122
|
+
foreignKeys.push(entry);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// ----- Indexes + unique constraints -----
|
|
126
|
+
const idxMeta = [];
|
|
127
|
+
const uniques = [];
|
|
128
|
+
// An index's collation can differ from the relation comparison's column
|
|
129
|
+
// collation: UNIQUE BINARY can admit both 'a' and 'A' under NOCASE joins.
|
|
130
|
+
// Column collations are absent from table_xinfo. Conservatively keep the
|
|
131
|
+
// to-many shape if the table/index DDL mentions COLLATE (even in a comment
|
|
132
|
+
// or identifier), rather than promise a to-one on incomplete facts.
|
|
133
|
+
const tableHasCollation = /\bCOLLATE\b/i.test(tableDefinitions.get(tableName) ?? '');
|
|
134
|
+
const relationUniques = tableHasCollation ? [] : [pkByTable.get(tableName) ?? []];
|
|
135
|
+
for (const idx of idxList) {
|
|
136
|
+
const keys = catalog(`PRAGMA main.index_info(${(0, catalog_js_1.q)(idx.name)})`).sort((a, b) => a.seqno - b.seqno);
|
|
137
|
+
const plain = keys.length > 0 && keys.every((c) => c.cid >= 0 && c.name !== null);
|
|
138
|
+
// Expression keys have no column name. Never let their null catalog
|
|
139
|
+
// placeholders reach metadata/codegen or treat the remaining names as a
|
|
140
|
+
// unique set. Keep the real DDL for partial/expression index consumers.
|
|
141
|
+
// `columns` must describe a complete plain key: shared consumers also
|
|
142
|
+
// derive compound selectors from it without parsing the definition.
|
|
143
|
+
const idxCols = plain ? keys.map((c) => c.name) : [];
|
|
144
|
+
const indexSource = catalog(`SELECT sql FROM main.sqlite_master WHERE type = 'index' AND name = ${(0, catalog_js_1.literal)(idx.name)}`)[0];
|
|
145
|
+
idxMeta.push({
|
|
146
|
+
name: idx.name,
|
|
147
|
+
columns: idxCols,
|
|
148
|
+
unique: idx.unique === 1,
|
|
149
|
+
// Internal auto-index DDL is unavailable. Never synthesize executable DDL.
|
|
150
|
+
definition: indexSource?.sql ?? '',
|
|
151
|
+
...(idx.partial === 1 ? { partial: true } : {}),
|
|
152
|
+
});
|
|
153
|
+
if (idx.unique === 1 && idx.partial === 0 && plain) {
|
|
154
|
+
uniques.push(idxCols);
|
|
155
|
+
if (!tableHasCollation && !/\bCOLLATE\b/i.test(indexSource?.sql ?? ''))
|
|
156
|
+
relationUniques.push(idxCols);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
indexesByTable.set(tableName, idxMeta);
|
|
160
|
+
uniqueByTable.set(tableName, uniques);
|
|
161
|
+
relationUniqueByTable.set(tableName, relationUniques);
|
|
162
|
+
}
|
|
163
|
+
// SQLite resolves FK identifiers with ASCII case folding. Preserve the actual
|
|
164
|
+
// catalog spelling in metadata and refuse unresolved in-scope references.
|
|
165
|
+
for (const fk of foreignKeys) {
|
|
166
|
+
const resolve = (table, name) => {
|
|
167
|
+
const column = columnsByTable.get(table)?.find((c) => sqliteName(c.name) === sqliteName(name));
|
|
168
|
+
if (!column)
|
|
169
|
+
throw new errors_js_1.ValidationError(`Unresolvable D1 foreign key: ${(0, catalog_metadata_js_1.printableCatalogName)(fk.constraintName)}.`);
|
|
170
|
+
return column.name;
|
|
171
|
+
};
|
|
172
|
+
fk.sourceColumns = fk.sourceColumns.map((name) => resolve(fk.sourceTable, name));
|
|
173
|
+
fk.targetColumns = fk.targetColumns.map((name) => resolve(fk.targetTable, name));
|
|
174
|
+
}
|
|
175
|
+
// ----- Build relations from foreign keys (belongsTo + hasMany + m2m) -----
|
|
176
|
+
// Reuse the established engine naming, field-collision and conservative
|
|
177
|
+
// junction policies. A to-one is decided per foreign key before naming, so
|
|
178
|
+
// it is named as PostgreSQL names it (`users.profile`).
|
|
179
|
+
for (const [tableName, cols] of columnsByTable)
|
|
180
|
+
(0, catalog_metadata_js_1.assertDistinctColumnFields)(tableName, cols);
|
|
181
|
+
const relationsByTable = (0, catalog_metadata_js_1.deriveEngineRelations)(tableNames, foreignKeys, pkByTable, columnsByTable, options.logger, options.legacyToManyUniques
|
|
182
|
+
? undefined
|
|
183
|
+
: (0, catalog_metadata_js_1.sqliteToOneForeignKey)(columnsByTable, relationUniqueByTable, tableDefinitions, tableFlags));
|
|
184
|
+
// ----- Assemble TableMetadata -----
|
|
185
|
+
const tables = (0, catalog_metadata_js_1.nullRecord)();
|
|
186
|
+
for (const tableName of tableNames) {
|
|
187
|
+
const columns = columnsByTable.get(tableName) ?? [];
|
|
188
|
+
const columnMap = (0, catalog_metadata_js_1.nullRecord)();
|
|
189
|
+
const reverseColumnMap = (0, catalog_metadata_js_1.nullRecord)();
|
|
190
|
+
const dateColumns = new Set();
|
|
191
|
+
const dialectTypes = (0, catalog_metadata_js_1.nullRecord)();
|
|
192
|
+
const pgTypes = (0, catalog_metadata_js_1.nullRecord)();
|
|
193
|
+
const allColumns = [];
|
|
194
|
+
for (const col of columns) {
|
|
195
|
+
columnMap[col.field] = col.name;
|
|
196
|
+
reverseColumnMap[col.name] = col.field;
|
|
197
|
+
allColumns.push(col.name);
|
|
198
|
+
dialectTypes[col.name] = col.dialectType ?? col.pgType;
|
|
199
|
+
pgTypes[col.name] = col.pgType;
|
|
200
|
+
if (isSqliteDateType(col.dialectType ?? col.pgType))
|
|
201
|
+
dateColumns.add(col.name);
|
|
202
|
+
}
|
|
203
|
+
tables[tableName] = {
|
|
204
|
+
name: tableName,
|
|
205
|
+
columns,
|
|
206
|
+
columnMap,
|
|
207
|
+
reverseColumnMap,
|
|
208
|
+
dateColumns,
|
|
209
|
+
dialectTypes,
|
|
210
|
+
pgTypes,
|
|
211
|
+
allColumns,
|
|
212
|
+
primaryKey: pkByTable.get(tableName) ?? [],
|
|
213
|
+
uniqueColumns: uniqueByTable.get(tableName) ?? [],
|
|
214
|
+
relations: relationsByTable.get(tableName) ?? (0, catalog_metadata_js_1.nullRecord)(),
|
|
215
|
+
indexes: indexesByTable.get(tableName) ?? [],
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
const schema = { tables, enums: (0, catalog_metadata_js_1.nullRecord)() };
|
|
219
|
+
// Shared renaming also supports raw-name metadata. Check the actual field
|
|
220
|
+
// names here before handing camelCase metadata to that helper.
|
|
221
|
+
for (const [name, renames] of Object.entries(options.relationNames ?? {})) {
|
|
222
|
+
for (const [from, to] of Object.entries(renames)) {
|
|
223
|
+
if (from !== to && tables[name]?.columns.some((column) => column.field === to))
|
|
224
|
+
throw new errors_js_1.ValidationError(`relationNames: a column already uses field "${(0, catalog_metadata_js_1.printableCatalogName)(to)}" on "${(0, catalog_metadata_js_1.printableCatalogName)(name)}".`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const result = options.relationNames ? (0, catalog_metadata_js_1.applyRelationRenames)(schema, options.relationNames) : schema;
|
|
228
|
+
(0, catalog_metadata_js_1.assertSafeCatalogSchema)(result);
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { D1DatabaseBinding } from './types.js';
|
|
2
|
+
export declare const CATALOG_TABLES = "d1:main-tables";
|
|
3
|
+
export declare const CATALOG_VIEWS = "d1:main-views";
|
|
4
|
+
export declare const q: (name: string) => string;
|
|
5
|
+
export declare const literal: (value: string) => string;
|
|
6
|
+
export interface D1CatalogSnapshot {
|
|
7
|
+
read<T>(query: string): T[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Discovery plans identifiers only. All metadata facts come from ONE native
|
|
11
|
+
* sequential atomic batch. Its manifest must equal discovery and its final
|
|
12
|
+
* manifest, otherwise refuse. No schema_version (D1 forbids it), BEGIN, session,
|
|
13
|
+
* transaction pinning, retries, or caller-owned binding lifecycle operations.
|
|
14
|
+
*/
|
|
15
|
+
export declare function collectD1Catalog(binding: D1DatabaseBinding): Promise<D1CatalogSnapshot>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.literal = exports.q = exports.CATALOG_VIEWS = exports.CATALOG_TABLES = void 0;
|
|
4
|
+
exports.collectD1Catalog = collectD1Catalog;
|
|
5
|
+
/** Native D1 catalog collection. No connection/session emulation or writes. */
|
|
6
|
+
const errors_js_1 = require("../errors.js");
|
|
7
|
+
const MANIFEST = 'SELECT type, name, tbl_name, rootpage, sql FROM main.sqlite_master ORDER BY type, name';
|
|
8
|
+
exports.CATALOG_TABLES = 'd1:main-tables';
|
|
9
|
+
exports.CATALOG_VIEWS = 'd1:main-views';
|
|
10
|
+
const q = (name) => `"${name.replace(/"/g, '""')}"`;
|
|
11
|
+
exports.q = q;
|
|
12
|
+
const literal = (value) => `'${value.replace(/'/g, "''")}'`;
|
|
13
|
+
exports.literal = literal;
|
|
14
|
+
function resultRows(result) {
|
|
15
|
+
if (result?.success !== true || !Array.isArray(result.results))
|
|
16
|
+
throw new errors_js_1.InvariantError('d1-catalog-result', `Unsuccessful or malformed D1 catalog result: ${result?.error ?? 'no error detail'}.`);
|
|
17
|
+
return result.results;
|
|
18
|
+
}
|
|
19
|
+
function manifestRows(result) {
|
|
20
|
+
const rows = resultRows(result);
|
|
21
|
+
if (rows.some((row) => typeof row.type !== 'string' ||
|
|
22
|
+
typeof row.name !== 'string' ||
|
|
23
|
+
typeof row.tbl_name !== 'string' ||
|
|
24
|
+
typeof row.rootpage !== 'number' ||
|
|
25
|
+
!(row.sql === null || typeof row.sql === 'string')))
|
|
26
|
+
throw new errors_js_1.InvariantError('d1-catalog-manifest', 'Malformed D1 schema manifest.');
|
|
27
|
+
return rows;
|
|
28
|
+
}
|
|
29
|
+
const userObject = (name) => !/^(sqlite_|_cf_)/i.test(name);
|
|
30
|
+
/**
|
|
31
|
+
* Discovery plans identifiers only. All metadata facts come from ONE native
|
|
32
|
+
* sequential atomic batch. Its manifest must equal discovery and its final
|
|
33
|
+
* manifest, otherwise refuse. No schema_version (D1 forbids it), BEGIN, session,
|
|
34
|
+
* transaction pinning, retries, or caller-owned binding lifecycle operations.
|
|
35
|
+
*/
|
|
36
|
+
async function collectD1Catalog(binding) {
|
|
37
|
+
const discovered = manifestRows(await binding.prepare(MANIFEST).all());
|
|
38
|
+
const tables = discovered.filter((row) => row.type === 'table' && userObject(row.name));
|
|
39
|
+
// WITHOUT ROWID primary-key indexes have index_list entries without a
|
|
40
|
+
// sqlite_master row. Discover names; never synthesize auto-index names.
|
|
41
|
+
const plannedIndexes = tables.length
|
|
42
|
+
? await binding.batch(tables.map((table) => binding.prepare(`PRAGMA main.index_list(${(0, exports.q)(table.name)})`)))
|
|
43
|
+
: [];
|
|
44
|
+
if (!Array.isArray(plannedIndexes) || plannedIndexes.length !== tables.length)
|
|
45
|
+
throw new errors_js_1.InvariantError('d1-catalog-plan', 'D1 index discovery count differs from its statement count.');
|
|
46
|
+
const indexNames = plannedIndexes.flatMap((result) => resultRows(result).map((row) => row.name));
|
|
47
|
+
const queries = [MANIFEST, 'PRAGMA main.table_list'];
|
|
48
|
+
for (const table of tables) {
|
|
49
|
+
for (const pragma of ['table_xinfo', 'foreign_key_list', 'index_list'])
|
|
50
|
+
queries.push(`PRAGMA main.${pragma}(${(0, exports.q)(table.name)})`);
|
|
51
|
+
}
|
|
52
|
+
for (const name of indexNames)
|
|
53
|
+
queries.push(`PRAGMA main.index_info(${(0, exports.q)(name)})`);
|
|
54
|
+
queries.push('PRAGMA main.table_list', MANIFEST);
|
|
55
|
+
const results = await binding.batch(queries.map((sql) => binding.prepare(sql)));
|
|
56
|
+
if (!Array.isArray(results) || results.length !== queries.length)
|
|
57
|
+
throw new errors_js_1.InvariantError('d1-catalog-batch', 'D1 catalog batch result count differs from its statement count.');
|
|
58
|
+
const rows = results.map((result) => resultRows(result));
|
|
59
|
+
const fingerprint = (value) => JSON.stringify(value);
|
|
60
|
+
if (fingerprint(discovered) !== fingerprint(manifestRows(results[0])) ||
|
|
61
|
+
fingerprint(discovered) !== fingerprint(manifestRows(results.at(-1))) ||
|
|
62
|
+
fingerprint(rows[1]) !== fingerprint(rows.at(-2)))
|
|
63
|
+
throw new errors_js_1.ValidationError('The D1 catalog changed during introspection. Retry after schema changes finish.');
|
|
64
|
+
const data = new Map();
|
|
65
|
+
queries.forEach((sql, index) => {
|
|
66
|
+
data.set(sql, rows[index]);
|
|
67
|
+
});
|
|
68
|
+
// These projections are derived from the validated native batch manifest.
|
|
69
|
+
data.set(exports.CATALOG_TABLES, tables.map(({ name, sql }) => ({ name, sql })));
|
|
70
|
+
data.set(exports.CATALOG_VIEWS, discovered.filter((row) => row.type === 'view' && userObject(row.name)));
|
|
71
|
+
tables.forEach((table, index) => {
|
|
72
|
+
if (fingerprint(data.get(`PRAGMA main.index_list(${(0, exports.q)(table.name)})`)) !==
|
|
73
|
+
fingerprint(resultRows(plannedIndexes[index])))
|
|
74
|
+
throw new errors_js_1.ValidationError('The D1 catalog changed during introspection. Retry after schema changes finish.');
|
|
75
|
+
});
|
|
76
|
+
for (const name of indexNames)
|
|
77
|
+
data.set(`SELECT sql FROM main.sqlite_master WHERE type = 'index' AND name = ${(0, exports.literal)(name)}`, [
|
|
78
|
+
{ sql: discovered.find((row) => row.type === 'index' && row.name === name)?.sql ?? null },
|
|
79
|
+
]);
|
|
80
|
+
return {
|
|
81
|
+
read(sql) {
|
|
82
|
+
const value = data.get(sql);
|
|
83
|
+
if (!value)
|
|
84
|
+
throw new errors_js_1.InvariantError('d1-catalog-plan', 'Catalog metadata requested an uncollected fact.');
|
|
85
|
+
return value;
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type GenerateFileOptions } from '../generate.js';
|
|
2
|
+
import type { SchemaMetadata } from '../schema.js';
|
|
3
|
+
export type GenerateD1Options = Omit<GenerateFileOptions, 'target' | 'exactNativeIntegers'> & {
|
|
4
|
+
/** Keep database column names instead of camelCase fields. */
|
|
5
|
+
keepColumnNames?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/** Emit the established types/metadata and an actual synchronous turbineD1 factory. */
|
|
8
|
+
export declare function generateD1Files(schema: SchemaMetadata, options?: GenerateD1Options): Record<'index.ts' | 'types.ts' | 'metadata.ts', string>;
|