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,373 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNotificationHub = createNotificationHub;
|
|
4
|
+
/** Optional, bounded PostgreSQL notification multiplexing. No driver import. */
|
|
5
|
+
const connection_guard_js_1 = require("./connection-guard.js");
|
|
6
|
+
const errors_js_1 = require("./errors.js");
|
|
7
|
+
const logger_js_1 = require("./logger.js");
|
|
8
|
+
const consumer_js_1 = require("./notification-hub/consumer.js");
|
|
9
|
+
const realtime_js_1 = require("./realtime.js");
|
|
10
|
+
function positiveInteger(value, name) {
|
|
11
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > 2_147_483_647) {
|
|
12
|
+
throw new errors_js_1.ValidationError(`Notification hub ${name} must be a positive integer no larger than 2147483647`);
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
/** Channels already pass validateChannel's ASCII identifier rule. */
|
|
17
|
+
function quoted(channel) {
|
|
18
|
+
return `"${channel.replace(/"/g, '""')}"`;
|
|
19
|
+
}
|
|
20
|
+
function cancelled() {
|
|
21
|
+
const error = new Error('Notification subscription cancelled');
|
|
22
|
+
error.name = 'AbortError';
|
|
23
|
+
return error;
|
|
24
|
+
}
|
|
25
|
+
function createNotificationHub(pool, options) {
|
|
26
|
+
if (options?.endpoint !== 'direct' && options?.endpoint !== 'session-pool') {
|
|
27
|
+
throw new errors_js_1.ConnectionError('Notification hub requires an explicit direct or session-pool endpoint contract. ' +
|
|
28
|
+
'PgBouncer transaction pooling supports NOTIFY but not LISTEN; stateless HTTP cannot LISTEN. ' +
|
|
29
|
+
'A checked-out logical client does not prove backend session affinity.');
|
|
30
|
+
}
|
|
31
|
+
if (options.ownership !== undefined && options.ownership !== 'external' && options.ownership !== 'owned') {
|
|
32
|
+
throw new errors_js_1.ValidationError('Notification hub ownership must be external or owned');
|
|
33
|
+
}
|
|
34
|
+
if (!pool || typeof pool.connect !== 'function' || typeof pool.end !== 'function') {
|
|
35
|
+
throw new errors_js_1.ValidationError('Notification hub requires a pool with connect() and end()');
|
|
36
|
+
}
|
|
37
|
+
if (options.reconnect !== undefined &&
|
|
38
|
+
typeof options.reconnect !== 'boolean' &&
|
|
39
|
+
(typeof options.reconnect !== 'object' || options.reconnect === null)) {
|
|
40
|
+
throw new errors_js_1.ValidationError('Notification hub reconnect must be a boolean or backoff options');
|
|
41
|
+
}
|
|
42
|
+
if (options.onError !== undefined && typeof options.onError !== 'function') {
|
|
43
|
+
throw new errors_js_1.ValidationError('Notification hub onError must be a function');
|
|
44
|
+
}
|
|
45
|
+
const maxChannels = positiveInteger(options.maxChannels ?? 128, 'maxChannels');
|
|
46
|
+
const maxSubscriptions = positiveInteger(options.maxSubscriptions ?? 1024, 'maxSubscriptions');
|
|
47
|
+
const retry = options.reconnect !== false;
|
|
48
|
+
const backoff = typeof options.reconnect === 'object' ? options.reconnect : {};
|
|
49
|
+
const initialDelay = positiveInteger(backoff.initialDelayMs ?? 100, 'initialDelayMs');
|
|
50
|
+
const maxDelay = positiveInteger(backoff.maxDelayMs ?? 30_000, 'maxDelayMs');
|
|
51
|
+
if (maxDelay < initialDelay)
|
|
52
|
+
throw new errors_js_1.ValidationError('Notification hub maxDelayMs must be at least initialDelayMs');
|
|
53
|
+
const owned = options.ownership === 'owned';
|
|
54
|
+
const onError = options.onError;
|
|
55
|
+
const channels = new Map();
|
|
56
|
+
let count = 0;
|
|
57
|
+
let generation = 0;
|
|
58
|
+
let current;
|
|
59
|
+
let closed = false;
|
|
60
|
+
let dirty = false;
|
|
61
|
+
let work;
|
|
62
|
+
let closing;
|
|
63
|
+
let timer;
|
|
64
|
+
let delay = initialDelay;
|
|
65
|
+
let reporting = false;
|
|
66
|
+
let failures = 0;
|
|
67
|
+
const consumersNow = () => [...channels.values()].flatMap((consumers) => [...consumers]);
|
|
68
|
+
const fallback = (error) => {
|
|
69
|
+
if (reporting)
|
|
70
|
+
return;
|
|
71
|
+
if (!onError) {
|
|
72
|
+
(0, logger_js_1.logTo)(logger_js_1.consoleLogger, 'warn', 'Notification hub failure:', { code: 'listen-lost', error });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
reporting = true;
|
|
76
|
+
try {
|
|
77
|
+
const result = onError(error);
|
|
78
|
+
if (result && typeof result.then === 'function') {
|
|
79
|
+
void Promise.resolve(result)
|
|
80
|
+
.catch(() => { })
|
|
81
|
+
.finally(() => {
|
|
82
|
+
reporting = false;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else
|
|
86
|
+
reporting = false;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
reporting = false;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const cancelTimer = () => {
|
|
93
|
+
if (timer !== undefined)
|
|
94
|
+
clearTimeout(timer);
|
|
95
|
+
timer = undefined;
|
|
96
|
+
};
|
|
97
|
+
const remove = (consumer, error = cancelled()) => {
|
|
98
|
+
if (!consumer.delivery.active)
|
|
99
|
+
return;
|
|
100
|
+
consumer.delivery.stop();
|
|
101
|
+
consumer.detachAbort();
|
|
102
|
+
const set = channels.get(consumer.channel);
|
|
103
|
+
set.delete(consumer);
|
|
104
|
+
if (!set.size)
|
|
105
|
+
channels.delete(consumer.channel);
|
|
106
|
+
count--;
|
|
107
|
+
if (!consumer.ready)
|
|
108
|
+
consumer.reject(error);
|
|
109
|
+
if (!count)
|
|
110
|
+
cancelTimer();
|
|
111
|
+
kick();
|
|
112
|
+
};
|
|
113
|
+
const drop = (connection, destroy) => {
|
|
114
|
+
if (current !== connection)
|
|
115
|
+
return;
|
|
116
|
+
current = undefined;
|
|
117
|
+
connection.client.removeListener('notification', connection.notification);
|
|
118
|
+
connection.client.removeListener('end', connection.end);
|
|
119
|
+
connection.guard.release(destroy);
|
|
120
|
+
};
|
|
121
|
+
const schedule = () => {
|
|
122
|
+
if (closed || !count || !retry || timer !== undefined)
|
|
123
|
+
return;
|
|
124
|
+
timer = setTimeout(() => {
|
|
125
|
+
timer = undefined;
|
|
126
|
+
kick();
|
|
127
|
+
}, delay);
|
|
128
|
+
timer.unref?.();
|
|
129
|
+
delay = Math.min(delay * 2, maxDelay);
|
|
130
|
+
};
|
|
131
|
+
const failure = (error) => {
|
|
132
|
+
failures++;
|
|
133
|
+
let reported = false;
|
|
134
|
+
for (const consumer of consumersNow()) {
|
|
135
|
+
if (consumer.delivery.active) {
|
|
136
|
+
consumer.delivery.report(error);
|
|
137
|
+
reported = true;
|
|
138
|
+
if (!consumer.ready || !retry)
|
|
139
|
+
remove(consumer, error);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (!reported)
|
|
143
|
+
fallback(error);
|
|
144
|
+
schedule();
|
|
145
|
+
};
|
|
146
|
+
const lost = (connection, error) => {
|
|
147
|
+
if (current !== connection)
|
|
148
|
+
return;
|
|
149
|
+
drop(connection, error);
|
|
150
|
+
delay = initialDelay;
|
|
151
|
+
failure((0, consumer_js_1.asError)((0, errors_js_1.wrapPgError)(error)));
|
|
152
|
+
};
|
|
153
|
+
const open = async () => {
|
|
154
|
+
const client = (await pool.connect());
|
|
155
|
+
if (closed || !count) {
|
|
156
|
+
(0, connection_guard_js_1.guardCheckout)(client).release(true);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (typeof client.on !== 'function' || typeof client.removeListener !== 'function') {
|
|
160
|
+
(0, connection_guard_js_1.guardCheckout)(client).release(true);
|
|
161
|
+
throw new errors_js_1.ConnectionError('Notification hub requires native notification, error and end events on a persistent client');
|
|
162
|
+
}
|
|
163
|
+
const connection = {
|
|
164
|
+
client,
|
|
165
|
+
guard: undefined,
|
|
166
|
+
channels: new Set(),
|
|
167
|
+
generation: ++generation,
|
|
168
|
+
notification(message) {
|
|
169
|
+
if (current !== connection)
|
|
170
|
+
return;
|
|
171
|
+
for (const consumer of [...(channels.get(message.channel) ?? [])]) {
|
|
172
|
+
// Reconnect gaps are covered by resync, never by a notification buffer.
|
|
173
|
+
if (consumer.generation === connection.generation)
|
|
174
|
+
consumer.delivery.deliver(message.payload ?? '');
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
end() {
|
|
178
|
+
lost(connection, new errors_js_1.ConnectionError('Notification listener connection ended'));
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
connection.guard = (0, connection_guard_js_1.guardCheckout)(client, (error) => lost(connection, error));
|
|
182
|
+
current = connection;
|
|
183
|
+
client.on('notification', connection.notification);
|
|
184
|
+
client.on('end', connection.end);
|
|
185
|
+
};
|
|
186
|
+
const reconcile = async () => {
|
|
187
|
+
if (closed || !count) {
|
|
188
|
+
cancelTimer();
|
|
189
|
+
const connection = current;
|
|
190
|
+
if (connection) {
|
|
191
|
+
try {
|
|
192
|
+
await connection.client.query('UNLISTEN *');
|
|
193
|
+
drop(connection);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
drop(connection, true);
|
|
197
|
+
fallback((0, consumer_js_1.asError)(error));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (!current) {
|
|
203
|
+
if (timer !== undefined)
|
|
204
|
+
return;
|
|
205
|
+
await open();
|
|
206
|
+
}
|
|
207
|
+
const connection = current;
|
|
208
|
+
if (!connection)
|
|
209
|
+
return;
|
|
210
|
+
// A stable, bounded snapshot prevents churn during awaited LISTENs from
|
|
211
|
+
// extending a live Map iterator and accumulating stale server channels.
|
|
212
|
+
const desired = new Set(channels.keys());
|
|
213
|
+
const query = async (sql) => {
|
|
214
|
+
await connection.client.query(sql);
|
|
215
|
+
if (current !== connection)
|
|
216
|
+
throw new errors_js_1.ConnectionError('Notification listener lost during channel reconciliation');
|
|
217
|
+
};
|
|
218
|
+
for (const channel of connection.channels) {
|
|
219
|
+
if (!desired.has(channel)) {
|
|
220
|
+
await query(`UNLISTEN ${quoted(channel)}`);
|
|
221
|
+
connection.channels.delete(channel);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
for (const channel of desired) {
|
|
225
|
+
if (!connection.channels.has(channel)) {
|
|
226
|
+
await query(`LISTEN ${quoted(channel)}`);
|
|
227
|
+
connection.channels.add(channel);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (closed || !count) {
|
|
231
|
+
dirty = true;
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
delay = initialDelay;
|
|
235
|
+
for (const consumer of consumersNow()) {
|
|
236
|
+
if (consumer.delivery.active) {
|
|
237
|
+
if (!connection.channels.has(consumer.channel)) {
|
|
238
|
+
dirty = true;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
const restored = consumer.ready && consumer.generation !== connection.generation;
|
|
242
|
+
consumer.generation = connection.generation;
|
|
243
|
+
if (!consumer.ready) {
|
|
244
|
+
consumer.ready = true;
|
|
245
|
+
consumer.resolve(consumer.subscription);
|
|
246
|
+
}
|
|
247
|
+
if (restored)
|
|
248
|
+
consumer.delivery.restored();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
const drain = async () => {
|
|
253
|
+
while (dirty) {
|
|
254
|
+
dirty = false;
|
|
255
|
+
const before = failures;
|
|
256
|
+
try {
|
|
257
|
+
await reconcile();
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
// Event loss already reported its cause. Query/checkout failures still need reporting.
|
|
261
|
+
if (before !== failures)
|
|
262
|
+
continue;
|
|
263
|
+
if (current)
|
|
264
|
+
drop(current, true);
|
|
265
|
+
failure((0, consumer_js_1.asError)((0, errors_js_1.wrapPgError)(error)));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
function kick() {
|
|
270
|
+
dirty = true;
|
|
271
|
+
if (work)
|
|
272
|
+
return;
|
|
273
|
+
work = Promise.resolve()
|
|
274
|
+
.then(drain)
|
|
275
|
+
.finally(() => {
|
|
276
|
+
work = undefined;
|
|
277
|
+
if (dirty)
|
|
278
|
+
kick();
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
const settled = async () => {
|
|
282
|
+
while (work)
|
|
283
|
+
await work;
|
|
284
|
+
};
|
|
285
|
+
return {
|
|
286
|
+
get stats() {
|
|
287
|
+
return Object.freeze({
|
|
288
|
+
channels: channels.size,
|
|
289
|
+
subscriptions: count,
|
|
290
|
+
connected: !!current,
|
|
291
|
+
reconnecting: timer !== undefined || (!!count && !current),
|
|
292
|
+
closed,
|
|
293
|
+
});
|
|
294
|
+
},
|
|
295
|
+
async subscribe(channel, handler, subscribeOptions = {}) {
|
|
296
|
+
(0, realtime_js_1.validateChannel)(channel);
|
|
297
|
+
if (closed)
|
|
298
|
+
throw new errors_js_1.ConnectionError('Notification hub is closed');
|
|
299
|
+
if (typeof handler !== 'function')
|
|
300
|
+
throw new errors_js_1.ValidationError('Notification hub handler must be a function');
|
|
301
|
+
for (const name of ['onError', 'onReconnect', 'onResync']) {
|
|
302
|
+
if (subscribeOptions[name] !== undefined && typeof subscribeOptions[name] !== 'function') {
|
|
303
|
+
throw new errors_js_1.ValidationError(`Notification hub ${name} must be a function`);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (subscribeOptions.signal !== undefined &&
|
|
307
|
+
(!subscribeOptions.signal ||
|
|
308
|
+
typeof subscribeOptions.signal.aborted !== 'boolean' ||
|
|
309
|
+
typeof subscribeOptions.signal.addEventListener !== 'function' ||
|
|
310
|
+
typeof subscribeOptions.signal.removeEventListener !== 'function')) {
|
|
311
|
+
throw new errors_js_1.ValidationError('Notification hub signal must be an AbortSignal');
|
|
312
|
+
}
|
|
313
|
+
if (subscribeOptions.signal?.aborted)
|
|
314
|
+
throw cancelled();
|
|
315
|
+
if (count >= maxSubscriptions || (!channels.has(channel) && channels.size >= maxChannels)) {
|
|
316
|
+
throw new errors_js_1.ValidationError('Notification hub subscription or channel limit exceeded');
|
|
317
|
+
}
|
|
318
|
+
let resolve;
|
|
319
|
+
let reject;
|
|
320
|
+
const ready = new Promise((accept, refuse) => {
|
|
321
|
+
resolve = accept;
|
|
322
|
+
reject = refuse;
|
|
323
|
+
});
|
|
324
|
+
const consumer = {
|
|
325
|
+
channel,
|
|
326
|
+
resolve,
|
|
327
|
+
reject,
|
|
328
|
+
generation: 0,
|
|
329
|
+
ready: false,
|
|
330
|
+
delivery: new consumer_js_1.ConsumerDelivery(handler, { ...subscribeOptions }, fallback),
|
|
331
|
+
detachAbort: () => { },
|
|
332
|
+
subscription: {
|
|
333
|
+
channel,
|
|
334
|
+
async unsubscribe() {
|
|
335
|
+
remove(consumer);
|
|
336
|
+
await settled();
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
let consumers = channels.get(channel);
|
|
341
|
+
if (!consumers) {
|
|
342
|
+
consumers = new Set();
|
|
343
|
+
channels.set(channel, consumers);
|
|
344
|
+
}
|
|
345
|
+
consumers.add(consumer);
|
|
346
|
+
count++;
|
|
347
|
+
const signal = subscribeOptions.signal;
|
|
348
|
+
if (signal) {
|
|
349
|
+
const abort = () => remove(consumer);
|
|
350
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
351
|
+
consumer.detachAbort = () => signal.removeEventListener('abort', abort);
|
|
352
|
+
}
|
|
353
|
+
kick();
|
|
354
|
+
return ready;
|
|
355
|
+
},
|
|
356
|
+
close() {
|
|
357
|
+
if (closing)
|
|
358
|
+
return closing;
|
|
359
|
+
closed = true;
|
|
360
|
+
cancelTimer();
|
|
361
|
+
for (const consumers of channels.values())
|
|
362
|
+
for (const consumer of consumers)
|
|
363
|
+
remove(consumer, new errors_js_1.ConnectionError('Notification hub is closed'));
|
|
364
|
+
kick();
|
|
365
|
+
closing = (async () => {
|
|
366
|
+
await settled();
|
|
367
|
+
if (owned)
|
|
368
|
+
await pool.end();
|
|
369
|
+
})();
|
|
370
|
+
return closing;
|
|
371
|
+
},
|
|
372
|
+
};
|
|
373
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading the SQL text the PostgreSQL catalog renders.
|
|
3
|
+
*
|
|
4
|
+
* A pure leaf with ZERO imports, so introspect.ts, schema-sql.ts and
|
|
5
|
+
* cli/mcp.ts read the same rules without a new import edge between them.
|
|
6
|
+
*
|
|
7
|
+
* ## Why this file exists
|
|
8
|
+
*
|
|
9
|
+
* Three catalog facts reach Turbine only as text: an index's structure
|
|
10
|
+
* (`pg_indexes.indexdef`, which is `pg_get_indexdef`), a column's default
|
|
11
|
+
* (`information_schema.columns.column_default`) and a CHECK constraint
|
|
12
|
+
* (`pg_get_constraintdef`). Each used to be read with an unanchored search over
|
|
13
|
+
* the whole string, and the string also carries identifiers and literals the
|
|
14
|
+
* user chose. An index named `"USING btree (kind)"` supplied the key list of an
|
|
15
|
+
* index over `slug`; a column named `"owner_id DESC"` lost its suffix to an
|
|
16
|
+
* ordering-word regex and became `owner_id`; a default of `'nextval(fake)'`
|
|
17
|
+
* read as a sequence; a CHECK's `'a b'` compared equal to `'a b'`. The first
|
|
18
|
+
* two decide whether `findUnique`, `update` and `delete` accept a `where`, and
|
|
19
|
+
* whether a foreign key is a to-one relation, so a wrong answer deleted rows.
|
|
20
|
+
*
|
|
21
|
+
* So the text is LEXED the way PostgreSQL writes it, and every question is
|
|
22
|
+
* asked of tokens: a quoted identifier (doubled `""` inside), a string literal
|
|
23
|
+
* (doubled `''`), a bare word, a single `(`, `)`, `,` or `.`, or a run of
|
|
24
|
+
* operator characters. A word inside a quoted identifier or a literal is never
|
|
25
|
+
* a keyword, and a paren inside one never opens a group.
|
|
26
|
+
*
|
|
27
|
+
* Not `cli/sql-statements.ts`: that tokenizer splits a migration file into
|
|
28
|
+
* statements and hands back text views of each, not tokens, and library code
|
|
29
|
+
* imports one CLI file only. This one reads a single statement or expression
|
|
30
|
+
* the catalog wrote, which has no comments and no dollar quotes.
|
|
31
|
+
*
|
|
32
|
+
* ## The contract every caller relies on
|
|
33
|
+
*
|
|
34
|
+
* When the text does not have the shape PostgreSQL renders, the reader says it
|
|
35
|
+
* cannot read it (`null`), and the caller treats that as the answer that claims
|
|
36
|
+
* least: not unique, no columns to trust, partial, not a sequence. Nothing here
|
|
37
|
+
* falls back to a looser search, because the input a reader cannot parse is
|
|
38
|
+
* exactly the one it must not vouch for.
|
|
39
|
+
*/
|
|
40
|
+
/** One entry of an index's key list. */
|
|
41
|
+
export interface IndexKey {
|
|
42
|
+
/**
|
|
43
|
+
* The column it indexes, unquoted (`"A"` is `A`, `"q""x"` is `q"x`), or
|
|
44
|
+
* `null` when the entry is an expression (`lower(email)`, `((a + b))`).
|
|
45
|
+
*/
|
|
46
|
+
column: string | null;
|
|
47
|
+
/**
|
|
48
|
+
* For a column, the COLLATE clause and operator class after its name, token
|
|
49
|
+
* by token as written (`['COLLATE', '"C"', 'text_pattern_ops']`). Ordering
|
|
50
|
+
* words (`ASC` / `DESC` / `NULLS FIRST` / `NULLS LAST`) are not modifiers:
|
|
51
|
+
* they change no equality. Empty for a bare column and for an expression.
|
|
52
|
+
*/
|
|
53
|
+
modifiers: string[];
|
|
54
|
+
}
|
|
55
|
+
/** What an index definition states. */
|
|
56
|
+
export interface IndexDefinition {
|
|
57
|
+
/** The statement reads `CREATE UNIQUE INDEX`, whatever its keys are. */
|
|
58
|
+
unique: boolean;
|
|
59
|
+
/** The key list, in order. Never empty. INCLUDE / STORING columns are not keys. */
|
|
60
|
+
keys: IndexKey[];
|
|
61
|
+
/** The index has a top-level `WHERE` predicate (a partial index). */
|
|
62
|
+
partial: boolean;
|
|
63
|
+
/** Offset of that `WHERE` in the definition, or -1. */
|
|
64
|
+
whereAt: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Read a `pg_get_indexdef` text: `CREATE [UNIQUE] INDEX <name> ON [ONLY]
|
|
68
|
+
* <qualified table> USING <method> (<keys>) [INCLUDE | STORING (...)] [NULLS
|
|
69
|
+
* [NOT] DISTINCT] [WITH (...)] [TABLESPACE <name>] [WHERE <predicate>]`.
|
|
70
|
+
* CockroachDB's `pg_indexes` renders the same statement with a three-part
|
|
71
|
+
* table name, `ASC` after every key and `STORING` for INCLUDE.
|
|
72
|
+
*
|
|
73
|
+
* Returns `null` for any text not of that shape (see the module contract).
|
|
74
|
+
*/
|
|
75
|
+
export declare function readIndexDefinition(text: string): IndexDefinition | null;
|
|
76
|
+
/**
|
|
77
|
+
* Whether a column default IS a sequence call, as PostgreSQL renders one:
|
|
78
|
+
* `nextval('users_id_seq'::regclass)`, possibly cast and parenthesised
|
|
79
|
+
* (`(nextval('s'::regclass))::integer`), with the argument possibly a cast text
|
|
80
|
+
* (`nextval(('s'::text)::regclass)`). The whole default must be that call: the
|
|
81
|
+
* pattern is anchored at both ends and reads the argument as one complete
|
|
82
|
+
* literal, so `'nextval(fake)'::text` is a string default, and one that does
|
|
83
|
+
* arithmetic on the call, `(nextval('s'::regclass) + 1)`, is not the
|
|
84
|
+
* sequence's own value.
|
|
85
|
+
*/
|
|
86
|
+
export declare function isSequenceDefault(text: string): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* A default or CHECK expression in the form two spellings of it are compared
|
|
89
|
+
* in: whitespace runs collapsed to one space and bare words (keywords, unquoted
|
|
90
|
+
* names, function names) lower-cased, which leaves string literals and quoted
|
|
91
|
+
* identifiers as written. `'UPPER'` and `'upper'` are different values and
|
|
92
|
+
* `"Col"` and `"col"` different columns, while `NOW()` and `now()`, or a
|
|
93
|
+
* re-indented expression, are the same text. Text that does not lex is
|
|
94
|
+
* returned trimmed, so it compares exactly.
|
|
95
|
+
*/
|
|
96
|
+
export declare function foldSqlText(text: string): string;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Reading the SQL text the PostgreSQL catalog renders.
|
|
4
|
+
*
|
|
5
|
+
* A pure leaf with ZERO imports, so introspect.ts, schema-sql.ts and
|
|
6
|
+
* cli/mcp.ts read the same rules without a new import edge between them.
|
|
7
|
+
*
|
|
8
|
+
* ## Why this file exists
|
|
9
|
+
*
|
|
10
|
+
* Three catalog facts reach Turbine only as text: an index's structure
|
|
11
|
+
* (`pg_indexes.indexdef`, which is `pg_get_indexdef`), a column's default
|
|
12
|
+
* (`information_schema.columns.column_default`) and a CHECK constraint
|
|
13
|
+
* (`pg_get_constraintdef`). Each used to be read with an unanchored search over
|
|
14
|
+
* the whole string, and the string also carries identifiers and literals the
|
|
15
|
+
* user chose. An index named `"USING btree (kind)"` supplied the key list of an
|
|
16
|
+
* index over `slug`; a column named `"owner_id DESC"` lost its suffix to an
|
|
17
|
+
* ordering-word regex and became `owner_id`; a default of `'nextval(fake)'`
|
|
18
|
+
* read as a sequence; a CHECK's `'a b'` compared equal to `'a b'`. The first
|
|
19
|
+
* two decide whether `findUnique`, `update` and `delete` accept a `where`, and
|
|
20
|
+
* whether a foreign key is a to-one relation, so a wrong answer deleted rows.
|
|
21
|
+
*
|
|
22
|
+
* So the text is LEXED the way PostgreSQL writes it, and every question is
|
|
23
|
+
* asked of tokens: a quoted identifier (doubled `""` inside), a string literal
|
|
24
|
+
* (doubled `''`), a bare word, a single `(`, `)`, `,` or `.`, or a run of
|
|
25
|
+
* operator characters. A word inside a quoted identifier or a literal is never
|
|
26
|
+
* a keyword, and a paren inside one never opens a group.
|
|
27
|
+
*
|
|
28
|
+
* Not `cli/sql-statements.ts`: that tokenizer splits a migration file into
|
|
29
|
+
* statements and hands back text views of each, not tokens, and library code
|
|
30
|
+
* imports one CLI file only. This one reads a single statement or expression
|
|
31
|
+
* the catalog wrote, which has no comments and no dollar quotes.
|
|
32
|
+
*
|
|
33
|
+
* ## The contract every caller relies on
|
|
34
|
+
*
|
|
35
|
+
* When the text does not have the shape PostgreSQL renders, the reader says it
|
|
36
|
+
* cannot read it (`null`), and the caller treats that as the answer that claims
|
|
37
|
+
* least: not unique, no columns to trust, partial, not a sequence. Nothing here
|
|
38
|
+
* falls back to a looser search, because the input a reader cannot parse is
|
|
39
|
+
* exactly the one it must not vouch for.
|
|
40
|
+
*/
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.readIndexDefinition = readIndexDefinition;
|
|
43
|
+
exports.isSequenceDefault = isSequenceDefault;
|
|
44
|
+
exports.foldSqlText = foldSqlText;
|
|
45
|
+
// One alternative per token kind, in priority order, each kind its own capture
|
|
46
|
+
// group: whitespace, string literal, quoted identifier, bare word. A lone `(`,
|
|
47
|
+
// `)`, `,` or `.` and a run of operator characters are punctuation. Every
|
|
48
|
+
// alternative that can contain a quote is quote-aware, and `'`, `"` and `$` are
|
|
49
|
+
// in no other class, so an unterminated literal or identifier matches nothing
|
|
50
|
+
// and the lex fails rather than reading on. So does a `$` quote, which the
|
|
51
|
+
// catalog never renders, and an `E'...'` string with a backslash-escaped quote,
|
|
52
|
+
// which PostgreSQL never renders here and CockroachDB only inside an expression
|
|
53
|
+
// or a predicate: the definition then does not read, and claims least. The
|
|
54
|
+
// literal patterns are linear: their branches start with different characters.
|
|
55
|
+
// PostgreSQL quotes every identifier that is not plain lower-case ASCII, so a
|
|
56
|
+
// non-ASCII letter outside quotes is read as punctuation: in a key that makes
|
|
57
|
+
// an expression, the reading that claims less.
|
|
58
|
+
const TOKEN = /(\s+)|('(?:''|[^'])*')|("(?:""|[^"])*")|(\w[\w$]*)|[(),.]|[^\s\w$'"(),.]+/y;
|
|
59
|
+
function lex(text) {
|
|
60
|
+
const out = [];
|
|
61
|
+
for (let at = 0; at < text.length; at = TOKEN.lastIndex) {
|
|
62
|
+
TOKEN.lastIndex = at;
|
|
63
|
+
const m = TOKEN.exec(text);
|
|
64
|
+
if (!m)
|
|
65
|
+
return null;
|
|
66
|
+
out.push({ k: m[1] ? ' ' : m[2] ? 's' : m[3] ? 'q' : m[4] ? 'w' : 'p', t: m[0], at });
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
/** The index of the `)` closing the `(` at `i`, or -1. */
|
|
71
|
+
function closing(t, i) {
|
|
72
|
+
if (t[i]?.t !== '(')
|
|
73
|
+
return -1;
|
|
74
|
+
for (let depth = 0; i < t.length; i++) {
|
|
75
|
+
if (t[i].t === '(')
|
|
76
|
+
depth++;
|
|
77
|
+
else if (t[i].t === ')' && --depth === 0)
|
|
78
|
+
return i;
|
|
79
|
+
}
|
|
80
|
+
return -1;
|
|
81
|
+
}
|
|
82
|
+
/** The (upper-cased) bare word at `i`, or `''` for anything else. */
|
|
83
|
+
const wordAt = (t, i) => (t[i]?.k === 'w' ? t[i].t.toUpperCase() : '');
|
|
84
|
+
/** Past a possibly qualified name (`a`, `"A"`, `s."T"`) starting at `i`, or -1. */
|
|
85
|
+
function pastName(t, i) {
|
|
86
|
+
for (;;) {
|
|
87
|
+
if (t[i]?.k !== 'w' && t[i]?.k !== 'q')
|
|
88
|
+
return -1;
|
|
89
|
+
if (t[++i]?.t !== '.')
|
|
90
|
+
return i;
|
|
91
|
+
i++;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Read a `pg_get_indexdef` text: `CREATE [UNIQUE] INDEX <name> ON [ONLY]
|
|
96
|
+
* <qualified table> USING <method> (<keys>) [INCLUDE | STORING (...)] [NULLS
|
|
97
|
+
* [NOT] DISTINCT] [WITH (...)] [TABLESPACE <name>] [WHERE <predicate>]`.
|
|
98
|
+
* CockroachDB's `pg_indexes` renders the same statement with a three-part
|
|
99
|
+
* table name, `ASC` after every key and `STORING` for INCLUDE.
|
|
100
|
+
*
|
|
101
|
+
* Returns `null` for any text not of that shape (see the module contract).
|
|
102
|
+
*/
|
|
103
|
+
function readIndexDefinition(text) {
|
|
104
|
+
const t = lex(text)?.filter((x) => x.k !== ' ');
|
|
105
|
+
if (!t)
|
|
106
|
+
return null;
|
|
107
|
+
let i = 0;
|
|
108
|
+
const word = (w) => wordAt(t, i) === w && ++i > 0;
|
|
109
|
+
const name = () => {
|
|
110
|
+
i = pastName(t, i);
|
|
111
|
+
return i >= 0;
|
|
112
|
+
};
|
|
113
|
+
if (!word('CREATE'))
|
|
114
|
+
return null;
|
|
115
|
+
const unique = word('UNIQUE');
|
|
116
|
+
if (!word('INDEX') || !name() || !word('ON'))
|
|
117
|
+
return null;
|
|
118
|
+
word('ONLY');
|
|
119
|
+
if (!name() || !word('USING') || !name())
|
|
120
|
+
return null;
|
|
121
|
+
const end = closing(t, i);
|
|
122
|
+
if (end < 0)
|
|
123
|
+
return null;
|
|
124
|
+
const keys = [];
|
|
125
|
+
for (let start = i + 1, j = start; j <= end; j++) {
|
|
126
|
+
if (j < end && t[j].t === '(')
|
|
127
|
+
j = closing(t, j);
|
|
128
|
+
else if (j === end || t[j].t === ',') {
|
|
129
|
+
if (j === start)
|
|
130
|
+
return null;
|
|
131
|
+
keys.push(readKey(t.slice(start, j)));
|
|
132
|
+
start = j + 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
let whereAt = -1;
|
|
136
|
+
for (i = end + 1; i < t.length && whereAt < 0;) {
|
|
137
|
+
if (word('INCLUDE') || word('STORING') || word('WITH')) {
|
|
138
|
+
i = closing(t, i) + 1; // 0 when the group does not close
|
|
139
|
+
if (!i)
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
else if (word('NULLS')) {
|
|
143
|
+
word('NOT');
|
|
144
|
+
if (!word('DISTINCT'))
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
else if (word('TABLESPACE')) {
|
|
148
|
+
if (!name())
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
else if (wordAt(t, i) === 'WHERE' && i < t.length - 1) {
|
|
152
|
+
// The predicate runs to the end; what it says is never read, only that
|
|
153
|
+
// it exists, which already claims the least.
|
|
154
|
+
whereAt = t[i].at;
|
|
155
|
+
}
|
|
156
|
+
else
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
return { unique, keys, partial: whereAt >= 0, whereAt };
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* One key entry: `{ column | expression } [COLLATE name] [opclass [(params)]]
|
|
163
|
+
* [ASC | DESC] [NULLS FIRST | LAST]`. The column is the LEADING token, read as
|
|
164
|
+
* a token, so the ordering words in `"owner_id DESC"` stay part of the name. A
|
|
165
|
+
* key is a column only when what follows that token is names (the COLLATE
|
|
166
|
+
* clause, the opclass, the ordering words) and an opclass parameter list;
|
|
167
|
+
* anything else (a function call, a cast, an operator) makes it an expression.
|
|
168
|
+
* The ordering words are left out of `modifiers` as PostgreSQL writes them,
|
|
169
|
+
* upper-case; an opclass that happens to be named `first` is written lower-case.
|
|
170
|
+
*/
|
|
171
|
+
function readKey(k) {
|
|
172
|
+
const head = k[0];
|
|
173
|
+
let j = 1;
|
|
174
|
+
let column = head.k === 'q' || head.k === 'w';
|
|
175
|
+
while (column && j < k.length) {
|
|
176
|
+
// pastName answers -1 and closing() + 1 answers 0 when there is no such thing.
|
|
177
|
+
j = k[j].t === '(' && j > 1 ? closing(k, j) + 1 : pastName(k, j);
|
|
178
|
+
column = j > 0;
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
column: column ? (head.k === 'q' ? head.t.slice(1, -1).replace(/""/g, '"') : head.t) : null,
|
|
182
|
+
modifiers: column ? k.slice(1).flatMap((x) => (/^(ASC|DESC|NULLS|FIRST|LAST)$/.test(x.t) ? [] : [x.t])) : [],
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
// ---------------------------------------------------------------------------
|
|
186
|
+
// Default and CHECK expressions
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
188
|
+
/**
|
|
189
|
+
* Whether a column default IS a sequence call, as PostgreSQL renders one:
|
|
190
|
+
* `nextval('users_id_seq'::regclass)`, possibly cast and parenthesised
|
|
191
|
+
* (`(nextval('s'::regclass))::integer`), with the argument possibly a cast text
|
|
192
|
+
* (`nextval(('s'::text)::regclass)`). The whole default must be that call: the
|
|
193
|
+
* pattern is anchored at both ends and reads the argument as one complete
|
|
194
|
+
* literal, so `'nextval(fake)'::text` is a string default, and one that does
|
|
195
|
+
* arithmetic on the call, `(nextval('s'::regclass) + 1)`, is not the
|
|
196
|
+
* sequence's own value.
|
|
197
|
+
*/
|
|
198
|
+
function isSequenceDefault(text) {
|
|
199
|
+
return /^\(*nextval\(\(*'(''|[^'])*'(::\w+)?\)*::regclass\)+(::[\w ]+(\(\d+(,\d+)?\))?)*$/i.test(text.trim());
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* A default or CHECK expression in the form two spellings of it are compared
|
|
203
|
+
* in: whitespace runs collapsed to one space and bare words (keywords, unquoted
|
|
204
|
+
* names, function names) lower-cased, which leaves string literals and quoted
|
|
205
|
+
* identifiers as written. `'UPPER'` and `'upper'` are different values and
|
|
206
|
+
* `"Col"` and `"col"` different columns, while `NOW()` and `now()`, or a
|
|
207
|
+
* re-indented expression, are the same text. Text that does not lex is
|
|
208
|
+
* returned trimmed, so it compares exactly.
|
|
209
|
+
*/
|
|
210
|
+
function foldSqlText(text) {
|
|
211
|
+
const t = lex(text);
|
|
212
|
+
return (t ? t.map((x) => (x.k === 'w' ? x.t.toLowerCase() : x.k === ' ' ? ' ' : x.t)).join('') : text).trim();
|
|
213
|
+
}
|