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
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertMssqlProjectCommand = assertMssqlProjectCommand;
|
|
4
|
+
exports.introspectMssqlProject = introspectMssqlProject;
|
|
5
|
+
exports.generateMssqlProject = generateMssqlProject;
|
|
6
|
+
exports.mssqlConfigTemplate = mssqlConfigTemplate;
|
|
7
|
+
exports.initMssqlProject = initMssqlProject;
|
|
8
|
+
exports.cmdMssqlInit = cmdMssqlInit;
|
|
9
|
+
exports.cmdMssqlGenerate = cmdMssqlGenerate;
|
|
10
|
+
exports.cmdMssqlStatus = cmdMssqlStatus;
|
|
11
|
+
exports.showMssqlHelp = showMssqlHelp;
|
|
12
|
+
/** SQL Server database-first project lifecycle. Migration execution has its own command adapter. */
|
|
13
|
+
const node_fs_1 = require("node:fs");
|
|
14
|
+
const node_path_1 = require("node:path");
|
|
15
|
+
const errors_js_1 = require("../errors.js");
|
|
16
|
+
const generate_js_1 = require("../generate.js");
|
|
17
|
+
const introspect_js_1 = require("../introspect.js");
|
|
18
|
+
const mssql_js_1 = require("../mssql.js");
|
|
19
|
+
const config_js_1 = require("./config.js");
|
|
20
|
+
const ui_js_1 = require("./ui.js");
|
|
21
|
+
function checkConfig(config, args) {
|
|
22
|
+
if ((0, config_js_1.resolveCliEngine)(config.engine) !== 'mssql') {
|
|
23
|
+
throw new errors_js_1.ValidationError('SQL Server project commands require engine "mssql".');
|
|
24
|
+
}
|
|
25
|
+
(0, config_js_1.validateCliEngineUrl)('mssql', config.url);
|
|
26
|
+
if (config.adapter !== undefined)
|
|
27
|
+
throw new errors_js_1.ValidationError('PostgreSQL adapters cannot be used with MSSQL.');
|
|
28
|
+
for (const key of ['include', 'exclude']) {
|
|
29
|
+
if (!Array.isArray(config[key]) || !config[key].every((value) => typeof value === 'string' && value.length > 0)) {
|
|
30
|
+
throw new errors_js_1.ValidationError(`MSSQL config ${key} must be an array of nonempty table names.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (!config.schema || config.schema.includes('\0') || (0, config_js_1.looksLikeSchemaFilePath)(config.schema)) {
|
|
34
|
+
throw new errors_js_1.ValidationError('MSSQL schema must be a SQL Server namespace (default dbo), not a schema file.');
|
|
35
|
+
}
|
|
36
|
+
if (args.withSchema || config.schemaFileConfigured) {
|
|
37
|
+
throw new errors_js_1.ValidationError('MSSQL CLI projects are database-first; schemaFile and --with-schema are not supported.');
|
|
38
|
+
}
|
|
39
|
+
if (args.includeViews) {
|
|
40
|
+
throw new errors_js_1.ValidationError('MSSQL CLI introspection does not support includeViews.');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Refuse unsupported commands before PostgreSQL handlers or drivers can run. */
|
|
44
|
+
function assertMssqlProjectCommand(command) {
|
|
45
|
+
if (['init', 'generate', 'gen', 'g', 'pull', 'status', 'info', 'seed', 's', 'migrate', 'migration', 'm'].includes(command))
|
|
46
|
+
return;
|
|
47
|
+
throw new errors_js_1.ValidationError(`Command "${command}" is not supported for MSSQL. SQL Server CLI supports init, pull/generate, status, callback seed and SQL-first migrate; code-first push/diff and PostgreSQL tools are not implemented.`);
|
|
48
|
+
}
|
|
49
|
+
/** Existing native catalog reader owns the short-lived connection and cleanup. */
|
|
50
|
+
async function introspectMssqlProject(config, args = {}) {
|
|
51
|
+
checkConfig(config, args);
|
|
52
|
+
if (!config.url)
|
|
53
|
+
throw new errors_js_1.ValidationError('MSSQL requires a database URL. Set DATABASE_URL or pass --url mssql://host/database.');
|
|
54
|
+
const metadata = await (0, mssql_js_1.introspectMssql)({
|
|
55
|
+
connectionString: config.url,
|
|
56
|
+
schema: config.schema,
|
|
57
|
+
include: config.include,
|
|
58
|
+
exclude: config.exclude,
|
|
59
|
+
legacyToManyUniques: config.legacyToManyUniques,
|
|
60
|
+
});
|
|
61
|
+
const schema = config.relationNames ? (0, introspect_js_1.applyRelationRenames)(metadata, config.relationNames) : metadata;
|
|
62
|
+
(0, introspect_js_1.assertSafeCatalogSchema)(schema);
|
|
63
|
+
return schema;
|
|
64
|
+
}
|
|
65
|
+
async function generateMssqlProject(config, args = {}) {
|
|
66
|
+
const schema = await introspectMssqlProject(config, args);
|
|
67
|
+
if (Object.keys(schema.tables).length === 0 && !args.allowEmpty) {
|
|
68
|
+
throw new errors_js_1.ValidationError('MSSQL introspection matched 0 tables; check schema/include/exclude or pass --allow-empty.');
|
|
69
|
+
}
|
|
70
|
+
let columnTypes = config.columnTypes;
|
|
71
|
+
if (columnTypes && (config.include.length || config.exclude.length)) {
|
|
72
|
+
// A valid override for an omitted table is irrelevant; a typo must still fail.
|
|
73
|
+
const catalog = await introspectMssqlProject({ ...config, include: [], exclude: [], relationNames: undefined }, args);
|
|
74
|
+
columnTypes = Object.fromEntries(Object.entries(columnTypes).filter(([key]) => {
|
|
75
|
+
const table = key.slice(0, key.lastIndexOf('.'));
|
|
76
|
+
const column = key.slice(key.lastIndexOf('.') + 1);
|
|
77
|
+
return Object.hasOwn(schema.tables, table) || !catalog.tables[table]?.columns.some((c) => c.name === column);
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
schema,
|
|
82
|
+
...(0, generate_js_1.generate)({
|
|
83
|
+
target: 'mssql',
|
|
84
|
+
schema,
|
|
85
|
+
exactNativeIntegers: config.exactNativeIntegers,
|
|
86
|
+
outDir: config.out,
|
|
87
|
+
connectionString: config.url,
|
|
88
|
+
importExtension: config.importExtension,
|
|
89
|
+
keepColumnNames: config.keepColumnNames,
|
|
90
|
+
columnTypes,
|
|
91
|
+
noTimestamp: args.noTimestamp,
|
|
92
|
+
zod: args.zod,
|
|
93
|
+
}),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** Credentials stay in the environment; all project settings survive initialization. */
|
|
97
|
+
function mssqlConfigTemplate(config) {
|
|
98
|
+
const settings = {
|
|
99
|
+
engine: 'mssql',
|
|
100
|
+
schema: config.schema,
|
|
101
|
+
out: config.out,
|
|
102
|
+
include: config.include,
|
|
103
|
+
exclude: config.exclude,
|
|
104
|
+
importExtension: config.importExtension,
|
|
105
|
+
keepColumnNames: config.keepColumnNames,
|
|
106
|
+
legacyToManyUniques: config.legacyToManyUniques,
|
|
107
|
+
relationNames: config.relationNames,
|
|
108
|
+
columnTypes: config.columnTypes,
|
|
109
|
+
};
|
|
110
|
+
return `import type { TurbineCliConfig } from 'turbine-orm/cli';
|
|
111
|
+
|
|
112
|
+
// Install the optional driver: npm i mssql. Set DATABASE_URL in your environment.
|
|
113
|
+
const config: TurbineCliConfig = {
|
|
114
|
+
...${JSON.stringify(settings, null, 2)},
|
|
115
|
+
url: process.env.DATABASE_URL,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export default config;
|
|
119
|
+
`;
|
|
120
|
+
}
|
|
121
|
+
/** Add config exclusively and optionally generate from an existing database. Never writes SQL. */
|
|
122
|
+
async function initMssqlProject(config, args = {}) {
|
|
123
|
+
checkConfig(config, args);
|
|
124
|
+
const created = [];
|
|
125
|
+
if (!(0, config_js_1.findConfigFile)()) {
|
|
126
|
+
const path = (0, node_path_1.resolve)('turbine.config.ts');
|
|
127
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(path), { recursive: true });
|
|
128
|
+
try {
|
|
129
|
+
(0, node_fs_1.writeFileSync)(path, mssqlConfigTemplate(config), { encoding: 'utf8', flag: 'wx' });
|
|
130
|
+
created.push(path);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (error.code !== 'EEXIST')
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const occupied = ['index.ts', 'metadata.ts', 'types.ts', 'zod.ts'].some((file) => (0, node_fs_1.existsSync)((0, node_path_1.resolve)(config.out, file)));
|
|
138
|
+
const generated = config.url && !args.skipGenerate && !occupied ? await generateMssqlProject(config, args) : undefined;
|
|
139
|
+
return { created, generated };
|
|
140
|
+
}
|
|
141
|
+
async function cmdMssqlInit(args, config) {
|
|
142
|
+
(0, ui_js_1.banner)();
|
|
143
|
+
const result = await initMssqlProject(config, args);
|
|
144
|
+
for (const path of result.created)
|
|
145
|
+
(0, ui_js_1.success)(`Created ${(0, introspect_js_1.printableCatalogName)(path)}`);
|
|
146
|
+
if (result.generated)
|
|
147
|
+
(0, ui_js_1.success)(`Generated ${result.generated.files.join(', ')} in ${(0, introspect_js_1.printableCatalogName)(result.generated.outDir)}`);
|
|
148
|
+
(0, ui_js_1.info)('Install mssql and set DATABASE_URL; run turbine pull to generate from an existing SQL Server database.');
|
|
149
|
+
(0, ui_js_1.info)('Init preserves existing config and generated files. SQL-first migrate is separate; code-first push/diff is not supported.');
|
|
150
|
+
}
|
|
151
|
+
async function cmdMssqlGenerate(args, config) {
|
|
152
|
+
(0, ui_js_1.banner)();
|
|
153
|
+
const result = await generateMssqlProject(config, args);
|
|
154
|
+
(0, ui_js_1.label)('SQL Server schema', (0, introspect_js_1.printableCatalogName)(config.schema));
|
|
155
|
+
(0, ui_js_1.success)(`Found ${Object.keys(result.schema.tables).length} tables`);
|
|
156
|
+
(0, ui_js_1.success)(`Generated ${result.files.join(', ')} in ${(0, introspect_js_1.printableCatalogName)(result.outDir)}`);
|
|
157
|
+
}
|
|
158
|
+
async function cmdMssqlStatus(args, config) {
|
|
159
|
+
(0, ui_js_1.banner)();
|
|
160
|
+
const schema = await introspectMssqlProject(config, args);
|
|
161
|
+
(0, ui_js_1.label)('SQL Server schema', (0, introspect_js_1.printableCatalogName)(config.schema));
|
|
162
|
+
(0, ui_js_1.label)('Tables', String(Object.keys(schema.tables).length));
|
|
163
|
+
for (const table of Object.values(schema.tables))
|
|
164
|
+
(0, ui_js_1.label)((0, introspect_js_1.printableCatalogName)(table.name), `${table.columns.length} columns`);
|
|
165
|
+
}
|
|
166
|
+
function showMssqlHelp() {
|
|
167
|
+
console.log('SQL Server: turbine init|pull|generate|status --engine mssql --schema dbo --url mssql://host/database');
|
|
168
|
+
console.log('Install optional mssql driver. Generated turbine(target, options) is asynchronous.');
|
|
169
|
+
console.log('SQL-first migrations: turbine migrate create|up|deploy|down|status --engine mssql. Callback seeds: turbine seed --engine mssql. No push/diff or code-first schema.');
|
|
170
|
+
console.log('Native URL connections use encrypt: false, trustServerCertificate: true; query parameters are refused.');
|
|
171
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ResolvedConfig } from './config.js';
|
|
2
|
+
import type { CliArgs } from './index.js';
|
|
3
|
+
export declare function showMssqlSeedHelp(): void;
|
|
4
|
+
/** Call before loading config, too: the generic parser consumes missing operands. */
|
|
5
|
+
export declare function assertMssqlSeedArguments(args: CliArgs, rawArgs?: readonly string[]): void;
|
|
6
|
+
/** The full CLI injects its native JS/TS importer in both ESM and CJS builds. */
|
|
7
|
+
export declare function cmdMssqlSeed(args: CliArgs, config: ResolvedConfig, importModule: (specifier: string) => Promise<unknown>): Promise<void>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.showMssqlSeedHelp = showMssqlSeedHelp;
|
|
4
|
+
exports.assertMssqlSeedArguments = assertMssqlSeedArguments;
|
|
5
|
+
exports.cmdMssqlSeed = cmdMssqlSeed;
|
|
6
|
+
/** Trusted local SQL Server callback modules, using an injected native importer. */
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const node_url_1 = require("node:url");
|
|
10
|
+
const errors_js_1 = require("../errors.js");
|
|
11
|
+
const mssql_seed_js_1 = require("../mssql-seed.js");
|
|
12
|
+
const config_js_1 = require("./config.js");
|
|
13
|
+
const loader_js_1 = require("./loader.js");
|
|
14
|
+
const mssql_project_js_1 = require("./mssql-project.js");
|
|
15
|
+
const ui_js_1 = require("./ui.js");
|
|
16
|
+
function showMssqlSeedHelp() {
|
|
17
|
+
(0, ui_js_1.banner)();
|
|
18
|
+
(0, ui_js_1.info)('turbine seed --engine mssql [--url mssql://host/database] [--schema dbo] [--verbose]');
|
|
19
|
+
(0, ui_js_1.info)('Run the trusted JS/TS default callback selected by config seedFile (legacy seed) or discovery.');
|
|
20
|
+
(0, ui_js_1.info)('Export default defineMssqlSeed(async (tx) => { ... }) from turbine-orm/mssql/seed.');
|
|
21
|
+
(0, ui_js_1.info)('TypeScript requires project-local tsx. Await every table operation and nested $transaction.');
|
|
22
|
+
(0, ui_js_1.info)('Native unqualified table resolution must match the configured schema. No session schema is changed.');
|
|
23
|
+
(0, ui_js_1.info)('Callback failure rolls back transactional DML; imports, external connections and module effects are excluded.');
|
|
24
|
+
(0, ui_js_1.info)('No implicit init seed, SQL files, dry-run, preview, positional arguments or PostgreSQL-only flags.');
|
|
25
|
+
}
|
|
26
|
+
/** Call before loading config, too: the generic parser consumes missing operands. */
|
|
27
|
+
function assertMssqlSeedArguments(args, rawArgs) {
|
|
28
|
+
const supported = new Set(['command', 'positional', 'engine', 'url', 'schema', 'verbose', 'help']);
|
|
29
|
+
for (const key of Object.keys(args)) {
|
|
30
|
+
if (!supported.has(key))
|
|
31
|
+
throw new errors_js_1.ValidationError(`SQL Server seed does not support option "${key}".`);
|
|
32
|
+
}
|
|
33
|
+
if (args.positional.length)
|
|
34
|
+
throw new errors_js_1.ValidationError('SQL Server seed takes no positional arguments. Set seedFile in config.');
|
|
35
|
+
for (const key of ['url', 'schema']) {
|
|
36
|
+
if (Object.hasOwn(args, key) && !args[key]?.trim()) {
|
|
37
|
+
throw new errors_js_1.ValidationError(`SQL Server seed --${key} requires a value.`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (rawArgs) {
|
|
41
|
+
for (let i = 1; i < rawArgs.length; i++) {
|
|
42
|
+
const token = rawArgs[i];
|
|
43
|
+
if (['--url', '-u', '--schema', '-s', '--engine'].includes(token)) {
|
|
44
|
+
const value = rawArgs[++i];
|
|
45
|
+
if (!value?.trim() || value.startsWith('-'))
|
|
46
|
+
throw new errors_js_1.ValidationError(`SQL Server seed ${token} requires a value.`);
|
|
47
|
+
}
|
|
48
|
+
else if (!['--verbose', '-v', '--help', '-h'].includes(token)) {
|
|
49
|
+
throw new errors_js_1.ValidationError('SQL Server seed takes only --engine, --url, --schema, --verbose and --help.');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** The full CLI injects its native JS/TS importer in both ESM and CJS builds. */
|
|
55
|
+
async function cmdMssqlSeed(args, config, importModule) {
|
|
56
|
+
assertMssqlSeedArguments(args);
|
|
57
|
+
const seedFile = (0, config_js_1.resolveSeedFile)(config);
|
|
58
|
+
if (!seedFile || !(0, node_fs_1.existsSync)(seedFile) || !(0, node_fs_1.statSync)(seedFile).isFile()) {
|
|
59
|
+
throw new errors_js_1.ValidationError('SQL Server seed file not found. Set seedFile in config or create seed.ts or seed.js.');
|
|
60
|
+
}
|
|
61
|
+
if (!/\.(?:[cm]?ts|[cm]?js)$/i.test(seedFile)) {
|
|
62
|
+
throw new errors_js_1.ValidationError(`Unsupported SQL Server seed extension "${(0, node_path_1.extname)(seedFile)}". Use a trusted JS/TS default callback; SQL files are not supported.`);
|
|
63
|
+
}
|
|
64
|
+
const schema = await (0, mssql_project_js_1.introspectMssqlProject)(config);
|
|
65
|
+
if ((0, loader_js_1.needsTsLoader)(seedFile)) {
|
|
66
|
+
const status = await (0, loader_js_1.registerTsLoader)();
|
|
67
|
+
if (status !== 'registered' && status !== 'already') {
|
|
68
|
+
throw new errors_js_1.ValidationError(`Cannot load TypeScript SQL Server seed (${status}). Install tsx in this project or use .js/.mjs/.cjs.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
(0, ui_js_1.banner)();
|
|
72
|
+
(0, ui_js_1.label)('Seed file', (0, node_path_1.relative)(process.cwd(), seedFile) || seedFile);
|
|
73
|
+
const fn = (0, config_js_1.unwrapModuleDefault)(await importModule((0, node_url_1.pathToFileURL)(seedFile).href));
|
|
74
|
+
if (typeof fn !== 'function')
|
|
75
|
+
throw new errors_js_1.ValidationError('SQL Server seed module must export a callable default callback receiving tx.');
|
|
76
|
+
await (0, mssql_seed_js_1.runMssqlSeed)(config.url, schema, fn, { schema: config.schema });
|
|
77
|
+
(0, ui_js_1.success)('Seed completed');
|
|
78
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** SQL Server catalog-only tools. Native handles never escape this module. */
|
|
2
|
+
import type { PgCompatPool, PgCompatPoolClient } from '../pg-types.js';
|
|
3
|
+
import type { IndexMetadata, SchemaMetadata } from '../schema.js';
|
|
4
|
+
import type { MssqlDoctorCatalog } from './mssql-doctor.js';
|
|
5
|
+
/** Provenance retained from existing fixed catalog reads, not a visibility guarantee. */
|
|
6
|
+
export declare function mssqlToolDoctorCatalog(metadata: SchemaMetadata): MssqlDoctorCatalog | undefined;
|
|
7
|
+
export declare const MSSQL_CATALOG_TOOLS: readonly string[];
|
|
8
|
+
export declare function mssqlToolSupported(name: string): boolean;
|
|
9
|
+
/** Resolution only: discovery does not evaluate the driver or open a connection. */
|
|
10
|
+
export declare function mssqlToolRuntime(): {
|
|
11
|
+
available: boolean;
|
|
12
|
+
minimumNode: null;
|
|
13
|
+
reason: string | null;
|
|
14
|
+
};
|
|
15
|
+
export declare const mssqlToolTransport: Readonly<{
|
|
16
|
+
kind: "mssql-catalog-only";
|
|
17
|
+
sessions: true;
|
|
18
|
+
transactions: false;
|
|
19
|
+
cursors: false;
|
|
20
|
+
pipeline: false;
|
|
21
|
+
readOnlyEnforcement: "fixed-catalog-queries-only";
|
|
22
|
+
statementTimeout: "native-request-30s";
|
|
23
|
+
ownership: "one-owned-pool-per-call";
|
|
24
|
+
note: "No native read-only transaction or database permission enforcement is asserted. Data and explain execution are refused; catalog reads are not a consistent snapshot.";
|
|
25
|
+
}>;
|
|
26
|
+
/** Native flags only; expressions, definitions and filter literals are withheld. */
|
|
27
|
+
export declare function mssqlToolIndexSummary(index: IndexMetadata): Record<string, unknown> | undefined;
|
|
28
|
+
/** Await native cleanup in the dispatcher; PgCompat release() itself returns void. */
|
|
29
|
+
export declare function releaseMssqlToolClient(client: PgCompatPoolClient): Promise<void>;
|
|
30
|
+
/** Lazy optional transport. An application-owned native pool is never accepted. */
|
|
31
|
+
export declare function createMssqlToolPool(url: string, schema: string): PgCompatPool;
|
|
32
|
+
/** Only an active owned token can reach the fixed native introspector. */
|
|
33
|
+
export declare function introspectMssqlToolClient(client: PgCompatPoolClient, options: {
|
|
34
|
+
include?: string[];
|
|
35
|
+
exclude?: string[];
|
|
36
|
+
legacyToManyUniques?: boolean;
|
|
37
|
+
}): Promise<SchemaMetadata>;
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** SQL Server catalog-only tools. Native handles never escape this module. */
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.mssqlToolTransport = exports.MSSQL_CATALOG_TOOLS = void 0;
|
|
8
|
+
exports.mssqlToolDoctorCatalog = mssqlToolDoctorCatalog;
|
|
9
|
+
exports.mssqlToolSupported = mssqlToolSupported;
|
|
10
|
+
exports.mssqlToolRuntime = mssqlToolRuntime;
|
|
11
|
+
exports.mssqlToolIndexSummary = mssqlToolIndexSummary;
|
|
12
|
+
exports.releaseMssqlToolClient = releaseMssqlToolClient;
|
|
13
|
+
exports.createMssqlToolPool = createMssqlToolPool;
|
|
14
|
+
exports.introspectMssqlToolClient = introspectMssqlToolClient;
|
|
15
|
+
const errors_js_1 = require("../errors.js");
|
|
16
|
+
const mssql_js_1 = require("../mssql.js");
|
|
17
|
+
const optional_peer_import_cjs_1 = __importDefault(require("../optional-peer-import.cjs"));
|
|
18
|
+
const sessions = new WeakMap();
|
|
19
|
+
const doctorCatalogs = new WeakMap();
|
|
20
|
+
/** Provenance retained from existing fixed catalog reads, not a visibility guarantee. */
|
|
21
|
+
function mssqlToolDoctorCatalog(metadata) {
|
|
22
|
+
return doctorCatalogs.get(metadata);
|
|
23
|
+
}
|
|
24
|
+
const summaries = new WeakMap();
|
|
25
|
+
exports.MSSQL_CATALOG_TOOLS = Object.freeze([
|
|
26
|
+
'doctor_report',
|
|
27
|
+
'schema_overview',
|
|
28
|
+
'table_detail',
|
|
29
|
+
'relation_graph',
|
|
30
|
+
'find_join_path',
|
|
31
|
+
'compile_query',
|
|
32
|
+
'explain_error',
|
|
33
|
+
'engine_capabilities',
|
|
34
|
+
]);
|
|
35
|
+
function mssqlToolSupported(name) {
|
|
36
|
+
return exports.MSSQL_CATALOG_TOOLS.includes(name);
|
|
37
|
+
}
|
|
38
|
+
/** Resolution only: discovery does not evaluate the driver or open a connection. */
|
|
39
|
+
function mssqlToolRuntime() {
|
|
40
|
+
const available = optional_peer_import_cjs_1.default.peerPackageVersion('mssql') !== null;
|
|
41
|
+
return {
|
|
42
|
+
available,
|
|
43
|
+
minimumNode: null,
|
|
44
|
+
reason: available ? null : "SQL Server catalog tools require the optional peer 'mssql'. Install it: npm i mssql.",
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
exports.mssqlToolTransport = Object.freeze({
|
|
48
|
+
kind: 'mssql-catalog-only',
|
|
49
|
+
sessions: true,
|
|
50
|
+
transactions: false,
|
|
51
|
+
cursors: false,
|
|
52
|
+
pipeline: false,
|
|
53
|
+
readOnlyEnforcement: 'fixed-catalog-queries-only',
|
|
54
|
+
statementTimeout: 'native-request-30s',
|
|
55
|
+
ownership: 'one-owned-pool-per-call',
|
|
56
|
+
note: 'No native read-only transaction or database permission enforcement is asserted. Data and explain execution are refused; catalog reads are not a consistent snapshot.',
|
|
57
|
+
});
|
|
58
|
+
/** Native flags only; expressions, definitions and filter literals are withheld. */
|
|
59
|
+
function mssqlToolIndexSummary(index) {
|
|
60
|
+
return summaries.get(index);
|
|
61
|
+
}
|
|
62
|
+
function configFor(url, schema) {
|
|
63
|
+
if (typeof schema !== 'string' ||
|
|
64
|
+
!schema ||
|
|
65
|
+
schema.length > 128 ||
|
|
66
|
+
[...schema].some((ch) => ch.charCodeAt(0) < 32 || ch.charCodeAt(0) === 127)) {
|
|
67
|
+
throw new errors_js_1.ValidationError('SQL Server tools require a schema identifier of 1–128 characters without controls.');
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
if (typeof url !== 'string')
|
|
71
|
+
throw new Error('invalid URL');
|
|
72
|
+
const parsed = new URL(url);
|
|
73
|
+
const database = decodeURIComponent(parsed.pathname.slice(1));
|
|
74
|
+
if (parsed.protocol !== 'mssql:' ||
|
|
75
|
+
!parsed.hostname ||
|
|
76
|
+
!database ||
|
|
77
|
+
database.includes('/') ||
|
|
78
|
+
parsed.search ||
|
|
79
|
+
parsed.hash) {
|
|
80
|
+
throw new Error('invalid URL');
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
server: parsed.hostname,
|
|
84
|
+
port: parsed.port ? Number(parsed.port) : 1433,
|
|
85
|
+
database,
|
|
86
|
+
user: decodeURIComponent(parsed.username),
|
|
87
|
+
password: decodeURIComponent(parsed.password),
|
|
88
|
+
pool: { min: 0, max: 1 },
|
|
89
|
+
connectionTimeout: 15_000,
|
|
90
|
+
requestTimeout: 30_000,
|
|
91
|
+
options: { encrypt: false, trustServerCertificate: true, useUTC: true },
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// Driver/URL diagnostics may contain credentials. Never echo them.
|
|
96
|
+
throw new errors_js_1.ValidationError('SQL Server tools require mssql://host/database without query parameters or fragment.');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function loadDriver() {
|
|
100
|
+
let module;
|
|
101
|
+
try {
|
|
102
|
+
module = await (0, optional_peer_import_cjs_1.default)('mssql');
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
throw new errors_js_1.ConnectionError("SQL Server catalog tools require the optional peer 'mssql'. Install it: npm i mssql.");
|
|
106
|
+
}
|
|
107
|
+
const driver = (module?.default ?? module);
|
|
108
|
+
if (typeof driver?.ConnectionPool !== 'function') {
|
|
109
|
+
throw new errors_js_1.ConnectionError('SQL Server catalog driver is missing ConnectionPool.');
|
|
110
|
+
}
|
|
111
|
+
return driver;
|
|
112
|
+
}
|
|
113
|
+
function refuseQuery() {
|
|
114
|
+
throw new errors_js_1.ValidationError('SQL Server tools accept fixed catalog reads only; arbitrary SQL and data execution are refused.');
|
|
115
|
+
}
|
|
116
|
+
/** Await native cleanup in the dispatcher; PgCompat release() itself returns void. */
|
|
117
|
+
async function releaseMssqlToolClient(client) {
|
|
118
|
+
const session = sessions.get(client);
|
|
119
|
+
if (!session)
|
|
120
|
+
throw new errors_js_1.ValidationError('SQL Server tools require an owned catalog connection.');
|
|
121
|
+
await session.release();
|
|
122
|
+
}
|
|
123
|
+
/** Lazy optional transport. An application-owned native pool is never accepted. */
|
|
124
|
+
function createMssqlToolPool(url, schema) {
|
|
125
|
+
const config = configFor(url, schema);
|
|
126
|
+
let closed = false;
|
|
127
|
+
const active = new Set();
|
|
128
|
+
const pending = new Set();
|
|
129
|
+
const cleanup = new Set();
|
|
130
|
+
let cleanupFailure;
|
|
131
|
+
async function connect() {
|
|
132
|
+
if (closed)
|
|
133
|
+
throw new errors_js_1.ValidationError('SQL Server tool transport is closed.');
|
|
134
|
+
const driver = await loadDriver();
|
|
135
|
+
if (closed)
|
|
136
|
+
throw new errors_js_1.ValidationError('SQL Server tool transport is closed.');
|
|
137
|
+
let native;
|
|
138
|
+
try {
|
|
139
|
+
native = new driver.ConnectionPool(config);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
throw new errors_js_1.ConnectionError('SQL Server catalog connection construction failed.');
|
|
143
|
+
}
|
|
144
|
+
let poolError;
|
|
145
|
+
native.on('error', (error) => {
|
|
146
|
+
poolError = error;
|
|
147
|
+
});
|
|
148
|
+
let ready;
|
|
149
|
+
let closing;
|
|
150
|
+
const session = {
|
|
151
|
+
schema,
|
|
152
|
+
active: true,
|
|
153
|
+
busy: false,
|
|
154
|
+
async exec(sql, params) {
|
|
155
|
+
if (!session.active || closed)
|
|
156
|
+
throw new errors_js_1.ValidationError('SQL Server tool connection was released.');
|
|
157
|
+
if (poolError !== undefined)
|
|
158
|
+
throw new errors_js_1.ConnectionError('SQL Server catalog connection failed.');
|
|
159
|
+
try {
|
|
160
|
+
const request = native.request();
|
|
161
|
+
for (let i = 0; i < params.length; i++)
|
|
162
|
+
request.input(`p${i + 1}`, params[i]);
|
|
163
|
+
const response = await request.query(sql);
|
|
164
|
+
if (!session.active || closed || poolError !== undefined)
|
|
165
|
+
throw new Error('inactive catalog connection');
|
|
166
|
+
return response.recordset ?? [];
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
throw new errors_js_1.ConnectionError('SQL Server catalog read failed. Check connection and catalog visibility permissions.');
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
release() {
|
|
173
|
+
session.active = false;
|
|
174
|
+
if (!closing) {
|
|
175
|
+
closing = (async () => {
|
|
176
|
+
try {
|
|
177
|
+
await ready.catch(() => undefined);
|
|
178
|
+
await session.work?.catch(() => undefined);
|
|
179
|
+
await native.close();
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
throw new errors_js_1.ConnectionError('SQL Server catalog connection cleanup failed.');
|
|
183
|
+
}
|
|
184
|
+
finally {
|
|
185
|
+
active.delete(session);
|
|
186
|
+
}
|
|
187
|
+
})();
|
|
188
|
+
cleanup.add(closing);
|
|
189
|
+
// release() is also callable through the synchronous PgCompat interface.
|
|
190
|
+
void closing
|
|
191
|
+
.catch((error) => {
|
|
192
|
+
cleanupFailure ??= error;
|
|
193
|
+
})
|
|
194
|
+
.finally(() => cleanup.delete(closing));
|
|
195
|
+
}
|
|
196
|
+
return closing;
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
active.add(session);
|
|
200
|
+
ready = Promise.resolve().then(() => native.connect());
|
|
201
|
+
try {
|
|
202
|
+
await ready;
|
|
203
|
+
if (closed)
|
|
204
|
+
throw new errors_js_1.ValidationError('SQL Server tool transport is closed.');
|
|
205
|
+
if (poolError !== undefined)
|
|
206
|
+
throw new errors_js_1.ConnectionError('SQL Server catalog connection failed.');
|
|
207
|
+
const client = {
|
|
208
|
+
query: refuseQuery,
|
|
209
|
+
release() {
|
|
210
|
+
void session.release();
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
sessions.set(client, session);
|
|
214
|
+
return client;
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
await session.release();
|
|
218
|
+
if (error instanceof errors_js_1.ValidationError || error instanceof errors_js_1.ConnectionError)
|
|
219
|
+
throw error;
|
|
220
|
+
throw new errors_js_1.ConnectionError('SQL Server catalog connection failed.');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
query: refuseQuery,
|
|
225
|
+
connect() {
|
|
226
|
+
const opening = connect();
|
|
227
|
+
pending.add(opening);
|
|
228
|
+
void opening.finally(() => pending.delete(opening)).catch(() => undefined);
|
|
229
|
+
return opening;
|
|
230
|
+
},
|
|
231
|
+
async end() {
|
|
232
|
+
closed = true;
|
|
233
|
+
await Promise.allSettled([...pending]);
|
|
234
|
+
for (const session of active)
|
|
235
|
+
void session.release();
|
|
236
|
+
await Promise.allSettled(cleanup);
|
|
237
|
+
if (cleanupFailure !== undefined)
|
|
238
|
+
throw cleanupFailure;
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
// These reads fetch flags and identifiers, never computed/default/filter SQL text.
|
|
243
|
+
const COLUMN_FLAGS = `SELECT s.name AS TABLE_SCHEMA, t.name AS TABLE_NAME, c.name AS COLUMN_NAME,
|
|
244
|
+
c.is_computed AS IS_COMPUTED, c.is_identity AS IS_IDENTITY
|
|
245
|
+
FROM sys.columns c JOIN sys.tables t ON t.object_id = c.object_id
|
|
246
|
+
JOIN sys.schemas s ON s.schema_id = t.schema_id
|
|
247
|
+
WHERE s.name = @p1 ORDER BY t.name, c.column_id`;
|
|
248
|
+
const INDEX_FLAGS = `SELECT t.name AS TABLE_NAME, i.name AS INDEX_NAME,
|
|
249
|
+
i.is_primary_key AS IS_PRIMARY_KEY, i.is_unique AS IS_UNIQUE,
|
|
250
|
+
i.has_filter AS HAS_FILTER, i.is_disabled AS IS_DISABLED,
|
|
251
|
+
i.is_hypothetical AS IS_HYPOTHETICAL, i.type_desc AS INDEX_TYPE,
|
|
252
|
+
c.name AS COLUMN_NAME, c.is_computed AS IS_COMPUTED,
|
|
253
|
+
ic.is_included_column AS IS_INCLUDED, ic.key_ordinal AS KEY_ORDINAL
|
|
254
|
+
FROM sys.indexes i JOIN sys.tables t ON t.object_id = i.object_id
|
|
255
|
+
JOIN sys.schemas s ON s.schema_id = t.schema_id
|
|
256
|
+
JOIN sys.index_columns ic ON ic.object_id = i.object_id AND ic.index_id = i.index_id
|
|
257
|
+
JOIN sys.columns c ON c.object_id = ic.object_id AND c.column_id = ic.column_id
|
|
258
|
+
WHERE s.name = @p1 AND i.name IS NOT NULL
|
|
259
|
+
ORDER BY t.name, i.name, ic.key_ordinal, ic.index_column_id`;
|
|
260
|
+
const bit = (value) => value === true || value === 1 || value === '1';
|
|
261
|
+
async function readMetadata(session, options) {
|
|
262
|
+
const columns = await session.exec(COLUMN_FLAGS, [session.schema]);
|
|
263
|
+
const indexes = await session.exec(INDEX_FLAGS, [session.schema]);
|
|
264
|
+
const metadata = await (0, mssql_js_1.introspectMssqlWith)(session.exec, session.schema, options);
|
|
265
|
+
const tri = (rows, key) => {
|
|
266
|
+
if (!rows.length || rows.some((row) => ![true, false, 0, 1, '0', '1'].includes(row[key])))
|
|
267
|
+
return null;
|
|
268
|
+
return rows.some((row) => bit(row[key]));
|
|
269
|
+
};
|
|
270
|
+
const namespaces = new Set(columns.map((row) => row.TABLE_SCHEMA));
|
|
271
|
+
const namespace = namespaces.size === 1 && typeof columns[0]?.TABLE_SCHEMA === 'string' ? columns[0].TABLE_SCHEMA : null;
|
|
272
|
+
const primaryKeys = Object.create(null);
|
|
273
|
+
for (const table of Object.values(metadata.tables)) {
|
|
274
|
+
const rows = indexes.filter((row) => row.TABLE_NAME === table.name && bit(row.IS_PRIMARY_KEY));
|
|
275
|
+
const keys = rows
|
|
276
|
+
.filter((row) => !bit(row.IS_INCLUDED) && Number(row.KEY_ORDINAL) > 0)
|
|
277
|
+
.sort((a, b) => Number(a.KEY_ORDINAL) - Number(b.KEY_ORDINAL));
|
|
278
|
+
const orderedKeysKnown = tri(rows, 'IS_INCLUDED') !== null &&
|
|
279
|
+
tri(rows, 'HAS_FILTER') === false &&
|
|
280
|
+
tri(keys, 'IS_COMPUTED') === false &&
|
|
281
|
+
new Set(rows.map((row) => row.INDEX_NAME)).size === 1 &&
|
|
282
|
+
keys.length > 0 &&
|
|
283
|
+
keys.length === table.primaryKey.length &&
|
|
284
|
+
keys.every((row, i) => Number(row.KEY_ORDINAL) === i + 1 && row.COLUMN_NAME === table.primaryKey[i]);
|
|
285
|
+
primaryKeys[table.name] = {
|
|
286
|
+
disabled: tri(rows, 'IS_DISABLED'),
|
|
287
|
+
hypothetical: tri(rows, 'IS_HYPOTHETICAL'),
|
|
288
|
+
orderedKeysKnown,
|
|
289
|
+
method: rows[0]?.INDEX_TYPE === 'CLUSTERED' || rows[0]?.INDEX_TYPE === 'NONCLUSTERED' ? rows[0].INDEX_TYPE : null,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
doctorCatalogs.set(metadata, { namespace, primaryKeys });
|
|
293
|
+
for (const table of Object.values(metadata.tables)) {
|
|
294
|
+
delete table.checks;
|
|
295
|
+
for (const column of table.columns) {
|
|
296
|
+
delete column.defaultValue;
|
|
297
|
+
delete column.generationExpression;
|
|
298
|
+
const flags = columns.find((row) => row.TABLE_NAME === table.name && row.COLUMN_NAME === column.name);
|
|
299
|
+
if (flags) {
|
|
300
|
+
column.isGenerated = bit(flags.IS_IDENTITY);
|
|
301
|
+
column.isGeneratedStored ||= bit(flags.IS_COMPUTED);
|
|
302
|
+
}
|
|
303
|
+
column.hasDefault ||= column.isGenerated === true || column.isGeneratedStored === true;
|
|
304
|
+
}
|
|
305
|
+
for (const index of table.indexes) {
|
|
306
|
+
const flags = indexes.filter((row) => row.TABLE_NAME === table.name && row.INDEX_NAME === index.name);
|
|
307
|
+
const partial = tri(flags, 'HAS_FILTER');
|
|
308
|
+
const keys = flags
|
|
309
|
+
.filter((row) => !bit(row.IS_INCLUDED) && Number(row.KEY_ORDINAL) > 0)
|
|
310
|
+
.sort((a, b) => Number(a.KEY_ORDINAL) - Number(b.KEY_ORDINAL));
|
|
311
|
+
const computed = tri(keys, 'IS_COMPUTED');
|
|
312
|
+
const orderedKeysKnown = tri(flags, 'IS_INCLUDED') !== null &&
|
|
313
|
+
keys.length === index.columns.length &&
|
|
314
|
+
keys.length > 0 &&
|
|
315
|
+
keys.every((row, i) => Number(row.KEY_ORDINAL) === i + 1 && row.COLUMN_NAME === index.columns[i]);
|
|
316
|
+
// All index definitions are withheld, including expression-like column names.
|
|
317
|
+
index.definition = '(definition withheld)';
|
|
318
|
+
summaries.set(index, {
|
|
319
|
+
name: index.name,
|
|
320
|
+
columns: [...index.columns],
|
|
321
|
+
unique: index.unique,
|
|
322
|
+
nativeUnique: tri(flags, 'IS_UNIQUE'),
|
|
323
|
+
partial,
|
|
324
|
+
disabled: tri(flags, 'IS_DISABLED'),
|
|
325
|
+
hypothetical: tri(flags, 'IS_HYPOTHETICAL'),
|
|
326
|
+
computed,
|
|
327
|
+
orderedKeysKnown,
|
|
328
|
+
method: flags.length > 0 && flags.every((row) => row.INDEX_TYPE === flags[0].INDEX_TYPE)
|
|
329
|
+
? flags[0].INDEX_TYPE
|
|
330
|
+
: null,
|
|
331
|
+
includedColumns: flags.filter((row) => bit(row.IS_INCLUDED)).map((row) => String(row.COLUMN_NAME)),
|
|
332
|
+
definitionWithheld: true,
|
|
333
|
+
definition: index.definition,
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return metadata;
|
|
338
|
+
}
|
|
339
|
+
/** Only an active owned token can reach the fixed native introspector. */
|
|
340
|
+
async function introspectMssqlToolClient(client, options) {
|
|
341
|
+
const session = sessions.get(client);
|
|
342
|
+
if (!session?.active)
|
|
343
|
+
throw new errors_js_1.ValidationError('SQL Server tools require an active owned catalog connection.');
|
|
344
|
+
if (session.busy)
|
|
345
|
+
throw new errors_js_1.ValidationError('SQL Server catalog introspection is already active on this connection.');
|
|
346
|
+
session.busy = true;
|
|
347
|
+
session.work = readMetadata(session, options);
|
|
348
|
+
try {
|
|
349
|
+
return await session.work;
|
|
350
|
+
}
|
|
351
|
+
finally {
|
|
352
|
+
session.busy = false;
|
|
353
|
+
}
|
|
354
|
+
}
|