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
package/dist/nested-write.js
CHANGED
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
import { CircularRelationError, describeTargetForMessage, NotFoundError, RelationError, UnsupportedFeatureError, ValidationError, } from './errors.js';
|
|
15
15
|
import { markInternalRowSelector } from './query/compound-unique.js';
|
|
16
16
|
import { resolveExcludedFromCreate } from './query/expr.js';
|
|
17
|
-
import { isPlainRecord, setOwn } from './query/filters.js';
|
|
18
|
-
import {
|
|
17
|
+
import { columnOperandKind, columnTypeToken, isPlainRecord, setOwn } from './query/filters.js';
|
|
18
|
+
import { assertArrayWrite } from './query/writes.js';
|
|
19
|
+
import { markInternalCombinator, resolveColumnName } from './query-utils.js';
|
|
19
20
|
import { normalizeKeyColumns } from './schema.js';
|
|
20
21
|
const MAX_DEPTH = 10;
|
|
21
22
|
const CREATE_ONLY_OPS = new Set(['create', 'connect', 'connectOrCreate']);
|
|
@@ -123,6 +124,73 @@ function isRelationEntry(meta, key, value) {
|
|
|
123
124
|
!Array.isArray(value) &&
|
|
124
125
|
!(value instanceof Date));
|
|
125
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Where each operation of a relation payload carries rows of the related
|
|
129
|
+
* table, by the keys the engine reads them from: `create` is a row or a list
|
|
130
|
+
* of them, `connectOrCreate` holds one under `create`, `update` under `data`,
|
|
131
|
+
* and `upsert` under `create` and `update`. `updateMany` holds one under
|
|
132
|
+
* `data` as `update` does (the operation itself is refused by name). `connect`,
|
|
133
|
+
* `disconnect`, `set` and `delete` name rows that exist and write none, and a
|
|
134
|
+
* `where` is a selector, never a row.
|
|
135
|
+
*/
|
|
136
|
+
const PAYLOAD_ROWS = [
|
|
137
|
+
['create', null],
|
|
138
|
+
['connectOrCreate', ['create']],
|
|
139
|
+
['update', ['data']],
|
|
140
|
+
['updateMany', ['data']],
|
|
141
|
+
['upsert', ['create', 'update']],
|
|
142
|
+
];
|
|
143
|
+
/**
|
|
144
|
+
* {@link assertArrayWrite} over every row a nested write will write,
|
|
145
|
+
* before it opens a transaction: the engine binds each level's rows only when
|
|
146
|
+
* it reaches them, after the rows above are written. `rows` is a row of
|
|
147
|
+
* `table` or a list of them. A key is a relation exactly when the engine reads
|
|
148
|
+
* it as one ({@link isRelationEntry}) and its payload is followed by
|
|
149
|
+
* {@link PAYLOAD_ROWS}; any other key naming a column is a value and is never
|
|
150
|
+
* descended into, so neither a JSON document nor a column named like an
|
|
151
|
+
* operation (`data`, `create`, `set`) is taken for a payload. An update's
|
|
152
|
+
* `{ set }` is checked as the value it writes.
|
|
153
|
+
*
|
|
154
|
+
* The same walk refuses a tree that is too deep, with the error a read gives
|
|
155
|
+
* for the same depth. The engine counts depth only along a chain of `create`
|
|
156
|
+
* operations that themselves nest, so a row at the last level, or a chain
|
|
157
|
+
* through `update`, `upsert` or `connectOrCreate`, was written however deep it
|
|
158
|
+
* sat, and the tree returned to the caller then stopped at the read limit
|
|
159
|
+
* without those rows. A write is accepted only when its whole tree can be
|
|
160
|
+
* returned.
|
|
161
|
+
*/
|
|
162
|
+
export function assertNestedArrayWrites(schema, table, rows, depth = 0, path = []) {
|
|
163
|
+
const meta = schema.tables[table];
|
|
164
|
+
if (!meta)
|
|
165
|
+
return;
|
|
166
|
+
for (const row of toArray(rows)) {
|
|
167
|
+
if (!isPlainRecord(row))
|
|
168
|
+
continue;
|
|
169
|
+
if (depth > MAX_DEPTH)
|
|
170
|
+
throw new CircularRelationError(path);
|
|
171
|
+
for (const [key, value] of Object.entries(row)) {
|
|
172
|
+
if (isRelationEntry(meta, key, value)) {
|
|
173
|
+
const to = meta.relations[key].to;
|
|
174
|
+
const below = [...path, key];
|
|
175
|
+
for (const [op, at] of PAYLOAD_ROWS) {
|
|
176
|
+
for (const item of toArray(value[op])) {
|
|
177
|
+
if (at === null)
|
|
178
|
+
assertNestedArrayWrites(schema, to, item, depth + 1, below);
|
|
179
|
+
else if (isPlainRecord(item))
|
|
180
|
+
for (const k of at)
|
|
181
|
+
assertNestedArrayWrites(schema, to, item[k], depth + 1, below);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const column = resolveColumnName(meta, key);
|
|
187
|
+
if (column === undefined)
|
|
188
|
+
continue;
|
|
189
|
+
const written = isPlainRecord(value) && Object.hasOwn(value, 'set') ? value.set : value;
|
|
190
|
+
assertArrayWrite(columnOperandKind(meta, column), columnTypeToken(meta, column), table, key, written);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
126
194
|
/**
|
|
127
195
|
* Split rows destined for `createMany` into CONTIGUOUS runs that each name the
|
|
128
196
|
* same fields.
|
|
@@ -267,6 +335,13 @@ function singleToOneItem(value, op, relName, rel) {
|
|
|
267
335
|
throw new ValidationError(`Nested ${op} on "${relName}" received ${value.length} items, but "${relName}" is a single "${rel.to}" ` +
|
|
268
336
|
`row. Pass one object, for example \`${op}: { ... }\`.`);
|
|
269
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* The operations whose rows {@link readBackWith} follows into deeper levels:
|
|
340
|
+
* every one that can write a row of the related table. A `connectOrCreate`
|
|
341
|
+
* that finds its row writes none; the levels requested for its `create` then
|
|
342
|
+
* return that existing row's related rows, as any relation read does.
|
|
343
|
+
*/
|
|
344
|
+
const READ_BACK_OPS = new Set(['create', 'connectOrCreate', 'update', 'upsert']);
|
|
270
345
|
/**
|
|
271
346
|
* The `with` clause that reads back the tree a nested write just wrote.
|
|
272
347
|
*
|
|
@@ -290,20 +365,20 @@ function readBackWith(schema, tableName, relations, depth = 0) {
|
|
|
290
365
|
if (!rel)
|
|
291
366
|
continue;
|
|
292
367
|
// Every payload this relation was written with: `create` / `update` /
|
|
293
|
-
// `upsert`
|
|
294
|
-
// relations of the TARGET table. `connect` / `disconnect` /
|
|
295
|
-
// existing rows and write no nested data, so they contribute
|
|
368
|
+
// `upsert` / `connectOrCreate` carry rows (or arrays of them) whose own
|
|
369
|
+
// keys may name relations of the TARGET table. `connect` / `disconnect` /
|
|
370
|
+
// `set` name existing rows and write no nested data, so they contribute
|
|
371
|
+
// nothing here.
|
|
296
372
|
const nested = {};
|
|
297
|
-
for (const
|
|
298
|
-
|
|
299
|
-
if (payload === undefined)
|
|
373
|
+
for (const [op, at] of PAYLOAD_ROWS) {
|
|
374
|
+
if (!READ_BACK_OPS.has(op))
|
|
300
375
|
continue;
|
|
301
|
-
for (const item of toArray(
|
|
302
|
-
//
|
|
303
|
-
//
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
376
|
+
for (const item of toArray(ops[op])) {
|
|
377
|
+
// Where the written rows sit is decided by the OPERATION, as the
|
|
378
|
+
// engine reads it, never by the row's own keys: a child column named
|
|
379
|
+
// `data`, `create` or `update` is a value of a created row, not a
|
|
380
|
+
// wrapper around one.
|
|
381
|
+
const bodies = at === null ? [item] : isPlainRecord(item) ? at.map((k) => item[k]) : [];
|
|
307
382
|
for (const body of bodies) {
|
|
308
383
|
if (!isPlainRecord(body))
|
|
309
384
|
continue;
|
|
@@ -311,7 +386,18 @@ function readBackWith(schema, tableName, relations, depth = 0) {
|
|
|
311
386
|
if (!child)
|
|
312
387
|
continue;
|
|
313
388
|
for (const [k, v] of Object.entries(extractRelationFields(body, child).relations)) {
|
|
314
|
-
|
|
389
|
+
// Every sibling row counts, not the last one: two rows that both
|
|
390
|
+
// write the same relation with the same operation each bring their
|
|
391
|
+
// own deeper relations, so their payloads are kept side by side, in
|
|
392
|
+
// a list this walk owns and appends to (never a copy per sibling).
|
|
393
|
+
const into = nested[k] ?? {};
|
|
394
|
+
nested[k] = into;
|
|
395
|
+
for (const [op, payload] of Object.entries(v)) {
|
|
396
|
+
const list = Object.hasOwn(into, op) ? into[op] : [];
|
|
397
|
+
into[op] = list;
|
|
398
|
+
for (const one of toArray(payload))
|
|
399
|
+
list.push(one);
|
|
400
|
+
}
|
|
315
401
|
}
|
|
316
402
|
}
|
|
317
403
|
}
|
|
@@ -837,7 +923,7 @@ async function processManyToMany(ctx, rel, relName, ops, parentRow) {
|
|
|
837
923
|
* The E001 raised when a nested delete/update/disconnect target is not a child
|
|
838
924
|
* of this parent (it belongs to another parent, or does not exist at all).
|
|
839
925
|
* Matches Prisma's behavior: the nested where is scoped to the relation, so a
|
|
840
|
-
* row outside the relation is
|
|
926
|
+
* row outside the relation is "not found".
|
|
841
927
|
*/
|
|
842
928
|
function notRelatedToParent(op, relName, rel, target) {
|
|
843
929
|
// Object form, not the legacy string one: `err.table` / `err.where` /
|
|
@@ -898,7 +984,7 @@ export async function executeNestedCreate(ctx, tableName, data, depth = 0, path
|
|
|
898
984
|
}
|
|
899
985
|
// belongsTo relations put the foreign key on the PARENT row, so they must be
|
|
900
986
|
// resolved BEFORE the parent is inserted, otherwise a NOT NULL FK column
|
|
901
|
-
// fails on the initial INSERT.
|
|
987
|
+
// fails on the initial INSERT. Resolve each belongsTo op (create/connect/
|
|
902
988
|
// connectOrCreate) to its referenced row and fold the FK values into the
|
|
903
989
|
// parent's own INSERT.
|
|
904
990
|
const belongsToFks = {};
|
|
@@ -954,9 +1040,10 @@ export async function executeNestedCreate(ctx, tableName, data, depth = 0, path
|
|
|
954
1040
|
/**
|
|
955
1041
|
* Tree-walking update: updates the parent row with scalar data, then
|
|
956
1042
|
* processes each relation operation (create, connect, connectOrCreate,
|
|
957
|
-
* disconnect, set, delete), and reads back the full tree.
|
|
1043
|
+
* disconnect, set, delete), and reads back the full tree. `optimisticLock`
|
|
1044
|
+
* is the top-level `update`'s, checked and bumped by the parent's UPDATE.
|
|
958
1045
|
*/
|
|
959
|
-
export async function executeNestedUpdate(ctx, tableName, where, data, depth = 0, path = [], returnShape) {
|
|
1046
|
+
export async function executeNestedUpdate(ctx, tableName, where, data, depth = 0, path = [], returnShape, optimisticLock) {
|
|
960
1047
|
if (depth > MAX_DEPTH) {
|
|
961
1048
|
throw new CircularRelationError(path);
|
|
962
1049
|
}
|
|
@@ -974,10 +1061,15 @@ export async function executeNestedUpdate(ctx, tableName, where, data, depth = 0
|
|
|
974
1061
|
}
|
|
975
1062
|
validateOps(relName, ops, true, rel);
|
|
976
1063
|
}
|
|
977
|
-
// Update parent row
|
|
1064
|
+
// Update the parent row first, before any relation operation, so a missing
|
|
1065
|
+
// row or a lock conflict leaves nothing to undo. With `optimisticLock` the
|
|
1066
|
+
// versioned UPDATE runs even when `data` has only relation writes: it is the
|
|
1067
|
+
// version check, and a relation-only write changes the row's version too.
|
|
978
1068
|
let parentRow;
|
|
979
|
-
if (Object.keys(scalars).length > 0) {
|
|
980
|
-
parentRow = (await ctx.tx
|
|
1069
|
+
if (optimisticLock || Object.keys(scalars).length > 0) {
|
|
1070
|
+
parentRow = (await ctx.tx
|
|
1071
|
+
.table(tableName)
|
|
1072
|
+
.update({ where, data: scalars, ...(optimisticLock && { optimisticLock }) }));
|
|
981
1073
|
}
|
|
982
1074
|
else {
|
|
983
1075
|
parentRow = (await ctx.tx.table(tableName).findUnique({ where }));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { NotificationHubHandler, NotificationHubSubscribeOptions } from '../notification-hub.js';
|
|
2
|
+
export declare function asError(error: unknown): Error;
|
|
3
|
+
/** No payload queue: one handler and one lifecycle observer per consumer. */
|
|
4
|
+
export declare class ConsumerDelivery {
|
|
5
|
+
private readonly handler;
|
|
6
|
+
private readonly options;
|
|
7
|
+
private readonly fallback;
|
|
8
|
+
active: boolean;
|
|
9
|
+
private handling;
|
|
10
|
+
private observing;
|
|
11
|
+
private overflow;
|
|
12
|
+
private reconnect;
|
|
13
|
+
private resync;
|
|
14
|
+
private error;
|
|
15
|
+
constructor(handler: NotificationHubHandler, options: NotificationHubSubscribeOptions, fallback: (error: Error) => void);
|
|
16
|
+
stop(): void;
|
|
17
|
+
deliver(payload: string): void;
|
|
18
|
+
report(error: Error): void;
|
|
19
|
+
restored(): void;
|
|
20
|
+
private flush;
|
|
21
|
+
private observe;
|
|
22
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
export function asError(error) {
|
|
2
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
3
|
+
}
|
|
4
|
+
/** No payload queue: one handler and one lifecycle observer per consumer. */
|
|
5
|
+
export class ConsumerDelivery {
|
|
6
|
+
handler;
|
|
7
|
+
options;
|
|
8
|
+
fallback;
|
|
9
|
+
active = true;
|
|
10
|
+
handling = false;
|
|
11
|
+
observing = false;
|
|
12
|
+
overflow = false;
|
|
13
|
+
reconnect = false;
|
|
14
|
+
resync = false;
|
|
15
|
+
error;
|
|
16
|
+
constructor(handler, options, fallback) {
|
|
17
|
+
this.handler = handler;
|
|
18
|
+
this.options = options;
|
|
19
|
+
this.fallback = fallback;
|
|
20
|
+
}
|
|
21
|
+
stop() {
|
|
22
|
+
this.active = false;
|
|
23
|
+
this.error = undefined;
|
|
24
|
+
this.overflow = this.reconnect = this.resync = false;
|
|
25
|
+
}
|
|
26
|
+
deliver(payload) {
|
|
27
|
+
if (!this.active)
|
|
28
|
+
return;
|
|
29
|
+
if (this.handling) {
|
|
30
|
+
this.overflow = true;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const result = this.handler(payload);
|
|
35
|
+
if (result && typeof result.then === 'function') {
|
|
36
|
+
this.handling = true;
|
|
37
|
+
void Promise.resolve(result)
|
|
38
|
+
.catch((error) => this.report(asError(error)))
|
|
39
|
+
.finally(() => {
|
|
40
|
+
this.handling = false;
|
|
41
|
+
this.flush();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
this.report(asError(error));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
report(error) {
|
|
50
|
+
if (!this.active)
|
|
51
|
+
return;
|
|
52
|
+
if (!this.options.onError) {
|
|
53
|
+
this.fallback(error);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
this.error = error;
|
|
57
|
+
this.flush();
|
|
58
|
+
}
|
|
59
|
+
restored() {
|
|
60
|
+
if (!this.active)
|
|
61
|
+
return;
|
|
62
|
+
this.reconnect = this.resync = true;
|
|
63
|
+
this.flush();
|
|
64
|
+
}
|
|
65
|
+
flush() {
|
|
66
|
+
if (!this.active || this.observing)
|
|
67
|
+
return;
|
|
68
|
+
this.observing = true;
|
|
69
|
+
void this.observe().finally(() => {
|
|
70
|
+
this.observing = false;
|
|
71
|
+
if (this.active && (this.error || this.reconnect || this.resync || (!this.handling && this.overflow)))
|
|
72
|
+
this.flush();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async observe() {
|
|
76
|
+
while (this.active) {
|
|
77
|
+
let callback;
|
|
78
|
+
if (this.error) {
|
|
79
|
+
const error = this.error;
|
|
80
|
+
this.error = undefined;
|
|
81
|
+
callback = () => this.options.onError?.(error);
|
|
82
|
+
}
|
|
83
|
+
else if (this.reconnect) {
|
|
84
|
+
this.reconnect = false;
|
|
85
|
+
callback = this.options.onReconnect;
|
|
86
|
+
}
|
|
87
|
+
else if (this.resync || (!this.handling && this.overflow)) {
|
|
88
|
+
const reason = this.resync ? 'reconnect' : 'overflow';
|
|
89
|
+
if (this.resync)
|
|
90
|
+
this.resync = false;
|
|
91
|
+
else
|
|
92
|
+
this.overflow = false;
|
|
93
|
+
callback = () => this.options.onResync?.(reason);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
await callback?.();
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
this.fallback(asError(error));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { PgCompatPool } from './pg-types.js';
|
|
2
|
+
import { type ListenReconnectOptions, type Subscription } from './realtime.js';
|
|
3
|
+
export type NotificationResyncReason = 'reconnect' | 'overflow';
|
|
4
|
+
export type NotificationHubHandler = (payload: string) => void | Promise<void>;
|
|
5
|
+
export interface NotificationHubSubscribeOptions {
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
onError?: (error: Error) => void | Promise<void>;
|
|
8
|
+
/** Restores the bounded reconnect snapshot; concurrently added subscriptions await their own readiness. */
|
|
9
|
+
onReconnect?: () => void | Promise<void>;
|
|
10
|
+
/** Reread the source of truth; lost notifications are never replayed. */
|
|
11
|
+
onResync?: (reason: NotificationResyncReason) => void | Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export interface NotificationHubOptions {
|
|
14
|
+
/** Caller asserts actual backend session affinity, not merely a logical checkout. */
|
|
15
|
+
endpoint: 'direct' | 'session-pool';
|
|
16
|
+
/** External by default. Only 'owned' calls pool.end(), once, on close(). */
|
|
17
|
+
ownership?: 'external' | 'owned';
|
|
18
|
+
reconnect?: boolean | ListenReconnectOptions;
|
|
19
|
+
/** Positive integer limits, including pending subscriptions. Defaults: 128 / 1024. */
|
|
20
|
+
maxChannels?: number;
|
|
21
|
+
maxSubscriptions?: number;
|
|
22
|
+
/** Fallback for connection/handler/observer failures. Async calls are coalesced. */
|
|
23
|
+
onError?: (error: Error) => void | Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export interface NotificationHubStats {
|
|
26
|
+
readonly channels: number;
|
|
27
|
+
readonly subscriptions: number;
|
|
28
|
+
readonly connected: boolean;
|
|
29
|
+
readonly reconnecting: boolean;
|
|
30
|
+
readonly closed: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface NotificationHub {
|
|
33
|
+
/** Resolves after LISTEN is acknowledged. Abort rejects pending readiness promptly. */
|
|
34
|
+
subscribe(channel: string, handler: NotificationHubHandler, options?: NotificationHubSubscribeOptions): Promise<Subscription>;
|
|
35
|
+
readonly stats: NotificationHubStats;
|
|
36
|
+
/** Waits for late checkouts; configure a finite driver connection timeout. Idempotent. */
|
|
37
|
+
close(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
type Pool = Pick<PgCompatPool, 'connect' | 'end'>;
|
|
40
|
+
export declare function createNotificationHub(pool: Pool, options: NotificationHubOptions): NotificationHub;
|
|
41
|
+
export {};
|