ts-prorm-orm 1.1.0 → 1.2.1
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/CHANGELOG.md +95 -0
- package/README.md +194 -72
- package/dist/audit/history-query.d.ts +35 -0
- package/dist/audit/index.d.ts +16 -0
- package/dist/audit/logger.d.ts +126 -0
- package/dist/cache/cache-manager.d.ts +341 -0
- package/dist/cache/index.d.ts +8 -0
- package/dist/cache/redis-cluster-cache.d.ts +164 -0
- package/dist/cache/redis-cluster-cache.js +19 -36
- package/dist/cli/cloud.d.ts +55 -0
- package/dist/cli/cloud.js +318 -0
- package/dist/cli/commands/auth.d.ts +2 -0
- package/dist/cli/commands/auth.js +345 -0
- package/dist/cli/commands/billing.d.ts +2 -0
- package/dist/cli/commands/billing.js +135 -0
- package/dist/cli/commands/code.d.ts +2 -0
- package/dist/cli/commands/code.js +168 -0
- package/dist/cli/commands/config.d.ts +2 -0
- package/dist/cli/commands/config.js +154 -0
- package/dist/cli/commands/db.d.ts +2 -0
- package/dist/cli/commands/db.js +189 -0
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.js +22 -0
- package/dist/cli/commands/keys.d.ts +2 -0
- package/dist/cli/commands/keys.js +100 -0
- package/dist/cli/commands/misc.d.ts +2 -0
- package/dist/cli/commands/misc.js +282 -0
- package/dist/cli/commands/pull.d.ts +2 -0
- package/dist/cli/commands/pull.js +306 -0
- package/dist/cli/commands/runners.d.ts +2 -0
- package/dist/cli/commands/runners.js +218 -0
- package/dist/cli/commands/scaffold.d.ts +2 -0
- package/dist/cli/commands/scaffold.js +383 -0
- package/dist/cli/commands/secrets.d.ts +2 -0
- package/dist/cli/commands/secrets.js +162 -0
- package/dist/cli/commands/store.d.ts +2 -0
- package/dist/cli/commands/store.js +274 -0
- package/dist/cli/commands/system.d.ts +10 -0
- package/dist/cli/commands/system.js +169 -0
- package/dist/cli/commands/teams.d.ts +2 -0
- package/dist/cli/commands/teams.js +189 -0
- package/dist/cli/commands/user.d.ts +2 -0
- package/dist/cli/commands/user.js +171 -0
- package/dist/cli/framework.d.ts +103 -0
- package/dist/cli/framework.js +436 -0
- package/dist/cli/io.d.ts +26 -0
- package/dist/cli/io.js +181 -0
- package/dist/cli/keychain.d.ts +10 -0
- package/dist/cli/keychain.js +101 -0
- package/dist/cli/prompt.d.ts +20 -0
- package/dist/cli/prompt.js +111 -0
- package/dist/cli.d.ts +214 -0
- package/dist/cli.js +72 -5
- package/dist/compliance/audit-trail.d.ts +66 -0
- package/dist/compliance/backup-verification.d.ts +279 -0
- package/dist/compliance/breach-detector.d.ts +197 -0
- package/dist/compliance/consent-record.d.ts +107 -0
- package/dist/compliance/consent-versioning.d.ts +169 -0
- package/dist/compliance/cross-border-log.d.ts +254 -0
- package/dist/compliance/data-classifier.d.ts +127 -0
- package/dist/compliance/data-lineage.d.ts +268 -0
- package/dist/compliance/data-masker.d.ts +110 -0
- package/dist/compliance/data-portability.d.ts +98 -0
- package/dist/compliance/data-retention.d.ts +108 -0
- package/dist/compliance/dsar-workflow.d.ts +175 -0
- package/dist/compliance/field-encryption.d.ts +84 -0
- package/dist/compliance/immutable-record.d.ts +84 -0
- package/dist/compliance/index.d.ts +93 -0
- package/dist/compliance/privacy-impact-assessment.d.ts +196 -0
- package/dist/compliance/pseudonymization.d.ts +96 -0
- package/dist/compliance/query-firewall.d.ts +661 -0
- package/dist/compliance/rate-limiter.d.ts +203 -0
- package/dist/compliance/right-to-erasure.d.ts +96 -0
- package/dist/compliance/row-level-security.d.ts +152 -0
- package/dist/compliance/security-decorator.d.ts +388 -0
- package/dist/compliance/security-monitor.d.ts +170 -0
- package/dist/compliance/sensitive-data-discovery.d.ts +151 -0
- package/dist/compliance/session-isolation.d.ts +286 -0
- package/dist/compliance/tls-enforcer.d.ts +51 -0
- package/dist/compliance/worm-storage.d.ts +225 -0
- package/dist/connection-manager.d.ts +130 -0
- package/dist/connection-pool.d.ts +311 -0
- package/dist/decorators/audit.d.ts +49 -0
- package/dist/decorators/check.d.ts +218 -0
- package/dist/decorators/collate.d.ts +346 -0
- package/dist/decorators/comment.d.ts +51 -0
- package/dist/decorators/database-settings.d.ts +193 -0
- package/dist/decorators/default.d.ts +148 -0
- package/dist/decorators/encryption.d.ts +175 -0
- package/dist/decorators/engine.d.ts +97 -0
- package/dist/decorators/fk-constraints.d.ts +387 -0
- package/dist/decorators/foreign-table.d.ts +57 -0
- package/dist/decorators/generated.d.ts +232 -0
- package/dist/decorators/hstore.d.ts +96 -0
- package/dist/decorators/index.d.ts +57 -0
- package/dist/decorators/index.js +14 -30
- package/dist/decorators/json-column.d.ts +47 -0
- package/dist/decorators/jsonb.d.ts +83 -0
- package/dist/decorators/orm-decorators.d.ts +274 -0
- package/dist/decorators/permissions.d.ts +192 -0
- package/dist/decorators/procedure.d.ts +168 -0
- package/dist/decorators/procedure.js +31 -7
- package/dist/decorators/query-options.d.ts +527 -0
- package/dist/decorators/range.d.ts +122 -0
- package/dist/decorators/set-column.d.ts +43 -0
- package/dist/decorators/spatial.d.ts +60 -0
- package/dist/decorators/storage.d.ts +561 -0
- package/dist/decorators/timezone.d.ts +319 -0
- package/dist/decorators/trigger.d.ts +50 -0
- package/dist/decorators/uuid.d.ts +102 -0
- package/dist/decorators/view.d.ts +213 -0
- package/dist/diagrams/chen-diagram.d.ts +70 -0
- package/dist/diagrams/chen-diagram.js +33 -31
- package/dist/diagrams/class-diagram.d.ts +78 -0
- package/dist/diagrams/class-diagram.js +23 -27
- package/dist/diagrams/dependency-diagram.d.ts +82 -0
- package/dist/diagrams/dependency-diagram.js +18 -9
- package/dist/diagrams/er-diagram.d.ts +82 -0
- package/dist/diagrams/er-diagram.js +174 -231
- package/dist/diagrams/flow-diagram.d.ts +70 -0
- package/dist/diagrams/flow-diagram.js +23 -18
- package/dist/diagrams/gantt-diagram.d.ts +67 -0
- package/dist/diagrams/gantt-diagram.js +20 -18
- package/dist/diagrams/index-diagram.d.ts +61 -0
- package/dist/diagrams/index-diagram.js +36 -31
- package/dist/diagrams/index.d.ts +155 -0
- package/dist/diagrams/index.js +7 -1
- package/dist/diagrams/migration-diagram.d.ts +67 -0
- package/dist/diagrams/migration-diagram.js +45 -57
- package/dist/diagrams/model-diagram.d.ts +85 -0
- package/dist/diagrams/model-diagram.js +225 -287
- package/dist/diagrams/package-diagram.d.ts +69 -0
- package/dist/diagrams/package-diagram.js +30 -32
- package/dist/diagrams/palette.d.ts +138 -0
- package/dist/diagrams/palette.js +134 -25
- package/dist/diagrams/relational-diagram.d.ts +82 -0
- package/dist/diagrams/relational-diagram.js +51 -59
- package/dist/diagrams/schemadoc-diagram.d.ts +57 -0
- package/dist/diagrams/schemadoc-diagram.js +36 -28
- package/dist/diagrams/sequence-diagram.d.ts +61 -0
- package/dist/diagrams/sequence-diagram.js +20 -11
- package/dist/diagrams/state-diagram.d.ts +85 -0
- package/dist/diagrams/state-diagram.js +21 -17
- package/dist/diagrams/svg-dom.d.ts +62 -0
- package/dist/diagrams/svg-dom.js +11 -0
- package/dist/diagrams/tree-diagram.d.ts +47 -0
- package/dist/diagrams/tree-diagram.js +19 -10
- package/dist/dialects/clickhouse/index.d.ts +660 -0
- package/dist/dialects/clickhouse/index.js +107 -2
- package/dist/dialects/cockroachdb/index.d.ts +1708 -0
- package/dist/dialects/cockroachdb/index.js +139 -10
- package/dist/dialects/cratedb/index.d.ts +262 -0
- package/dist/dialects/cratedb/index.js +148 -0
- package/dist/dialects/databricks/index.d.ts +397 -0
- package/dist/dialects/databricks/index.js +233 -11
- package/dist/dialects/db2/index.d.ts +729 -0
- package/dist/dialects/db2/index.js +152 -2
- package/dist/dialects/dialect.d.ts +1653 -0
- package/dist/dialects/duckdb/index.d.ts +440 -0
- package/dist/dialects/duckdb/index.js +21 -37
- package/dist/dialects/exasol/index.d.ts +197 -0
- package/dist/dialects/exasol/index.js +14 -0
- package/dist/dialects/firebird/index.d.ts +286 -0
- package/dist/dialects/firebird/index.js +135 -0
- package/dist/dialects/greenplum/index.d.ts +336 -0
- package/dist/dialects/greenplum/index.js +168 -0
- package/dist/dialects/hana/index.d.ts +512 -0
- package/dist/dialects/hana/index.js +17 -35
- package/dist/dialects/mariadb/index.d.ts +1241 -0
- package/dist/dialects/mariadb/index.js +181 -43
- package/dist/dialects/mssql/index.d.ts +729 -0
- package/dist/dialects/mssql/index.js +76 -7
- package/dist/dialects/mysql/index.d.ts +1233 -0
- package/dist/dialects/mysql/index.js +87 -19
- package/dist/dialects/oracle/index.d.ts +1222 -0
- package/dist/dialects/oracle/index.js +210 -9
- package/dist/dialects/postgres/index.d.ts +1598 -0
- package/dist/dialects/postgres/index.js +34 -13
- package/dist/dialects/query-stream-helper.d.ts +58 -0
- package/dist/dialects/questdb/index.d.ts +430 -0
- package/dist/dialects/questdb/index.js +292 -0
- package/dist/dialects/redshift/index.d.ts +933 -0
- package/dist/dialects/redshift/index.js +17 -5
- package/dist/dialects/singlestore/index.d.ts +233 -0
- package/dist/dialects/singlestore/index.js +53 -0
- package/dist/dialects/snowflake/index.d.ts +727 -0
- package/dist/dialects/snowflake/index.js +154 -5
- package/dist/dialects/spanner/index.d.ts +660 -0
- package/dist/dialects/spanner/index.js +43 -21
- package/dist/dialects/sqlite/index.d.ts +1133 -0
- package/dist/dialects/sqlite/index.js +168 -30
- package/dist/dialects/tidb/index.d.ts +226 -0
- package/dist/dialects/tidb/index.js +10 -0
- package/dist/dialects/timescaledb/index.d.ts +286 -0
- package/dist/dialects/timescaledb/index.js +179 -0
- package/dist/dialects/trino/index.d.ts +230 -0
- package/dist/dialects/trino/index.js +85 -10
- package/dist/dialects/turso/index.d.ts +98 -0
- package/dist/dialects/turso/index.js +10 -0
- package/dist/dialects/vertica/index.d.ts +321 -0
- package/dist/dialects/vertica/index.js +161 -0
- package/dist/dialects/yugabytedb/index.d.ts +276 -0
- package/dist/dialects/yugabytedb/index.js +121 -0
- package/dist/errors/index.d.ts +378 -0
- package/dist/errors/index.js +29 -1
- package/dist/errors/utils.d.ts +53 -0
- package/dist/errors.d.ts +5 -0
- package/dist/extensions/catalog/cloud-warehouse-features.d.ts +27 -0
- package/dist/extensions/catalog/mssql-features.d.ts +20 -0
- package/dist/extensions/catalog/mysql-mariadb-plugins.d.ts +18 -0
- package/dist/extensions/catalog/oracle-db2-features.d.ts +17 -0
- package/dist/extensions/catalog/postgres-extensions.d.ts +15 -0
- package/dist/extensions/index.d.ts +34 -0
- package/dist/extensions/types.d.ts +43 -0
- package/dist/external-fields/adapters.d.ts +50 -0
- package/dist/external-fields/adapters.js +227 -0
- package/dist/external-fields/decorator.d.ts +77 -0
- package/dist/external-fields/decorator.js +80 -0
- package/dist/external-fields/index.d.ts +10 -0
- package/dist/external-fields/index.js +19 -0
- package/dist/external-fields/runtime.d.ts +39 -0
- package/dist/external-fields/runtime.js +221 -0
- package/dist/foreign-data.d.ts +168 -0
- package/dist/graph/base-graph-dialect.d.ts +250 -0
- package/dist/graph/base-graph-dialect.js +539 -0
- package/dist/graph/dgraph/index.d.ts +65 -0
- package/dist/graph/dgraph/index.js +559 -0
- package/dist/graph/gremlin/index.d.ts +59 -0
- package/dist/graph/gremlin/index.js +378 -0
- package/dist/graph/index.d.ts +60 -0
- package/dist/graph/index.js +67 -0
- package/dist/graph/neo4j/index.d.ts +50 -0
- package/dist/graph/neo4j/index.js +462 -0
- package/dist/graph/types.d.ts +213 -0
- package/dist/graph/types.js +234 -0
- package/dist/hooks/hooks-manager.d.ts +189 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/index.d.ts +713 -0
- package/dist/index.js +36 -4
- package/dist/logging.d.ts +183 -0
- package/dist/migrations/index.d.ts +9 -0
- package/dist/migrations/migration.d.ts +143 -0
- package/dist/migrations/migrator.d.ts +199 -0
- package/dist/migrations/prormmigration.d.ts +131 -0
- package/dist/migrations/query-interface.d.ts +335 -0
- package/dist/migrations/seeder.d.ts +167 -0
- package/dist/models/associations.d.ts +131 -0
- package/dist/models/associations.js +7 -2
- package/dist/models/constraints.d.ts +175 -0
- package/dist/models/data-types.d.ts +1656 -0
- package/dist/models/decorators.d.ts +328 -0
- package/dist/models/decorators.js +61 -82
- package/dist/models/eager-load.d.ts +86 -0
- package/dist/models/eager-load.js +369 -0
- package/dist/models/index.d.ts +13 -0
- package/dist/models/indexes.d.ts +325 -0
- package/dist/models/methods.d.ts +419 -0
- package/dist/models/model-manager.d.ts +76 -0
- package/dist/models/model.d.ts +820 -0
- package/dist/models/model.js +15 -101
- package/dist/models/operators.d.ts +29 -0
- package/dist/models/scopes.d.ts +71 -0
- package/dist/models/typescript-types.d.ts +177 -0
- package/dist/nosql/aerospike/index.d.ts +126 -0
- package/dist/nosql/allegrograph/index.d.ts +86 -0
- package/dist/nosql/arangodb/index.d.ts +285 -0
- package/dist/nosql/arangodb/index.js +274 -2
- package/dist/nosql/arangodb/where.d.ts +38 -0
- package/dist/nosql/arangodb/where.js +94 -0
- package/dist/nosql/azure-blob/index.d.ts +104 -0
- package/dist/nosql/beanstalkd/index.d.ts +88 -0
- package/dist/nosql/beequeue/index.d.ts +99 -0
- package/dist/nosql/bigchaindb/index.d.ts +113 -0
- package/dist/nosql/bigtable/index.d.ts +144 -0
- package/dist/nosql/blazegraph/index.d.ts +88 -0
- package/dist/nosql/bullmq/index.d.ts +83 -0
- package/dist/nosql/cassandra/index.d.ts +119 -0
- package/dist/nosql/chroma/index.d.ts +151 -0
- package/dist/nosql/cloudflare-kv/index.d.ts +120 -0
- package/dist/nosql/coherence/index.d.ts +91 -0
- package/dist/nosql/cosmosdb/index.d.ts +78 -0
- package/dist/nosql/couchbase/index.d.ts +103 -0
- package/dist/nosql/dax/index.d.ts +118 -0
- package/dist/nosql/deno-kv/index.d.ts +109 -0
- package/dist/nosql/dgraph/index.d.ts +80 -0
- package/dist/nosql/doris/index.d.ts +88 -0
- package/dist/nosql/druid/index.d.ts +95 -0
- package/dist/nosql/dynamodb/index.d.ts +643 -0
- package/dist/nosql/dynamodb/index.js +423 -0
- package/dist/nosql/elasticsearch/index.d.ts +239 -0
- package/dist/nosql/etcd/index.d.ts +243 -0
- package/dist/nosql/eventhubs/index.d.ts +89 -0
- package/dist/nosql/eventstore/index.d.ts +102 -0
- package/dist/nosql/faunadb/index.d.ts +141 -0
- package/dist/nosql/faunadb/index.js +329 -0
- package/dist/nosql/firestore/index.d.ts +67 -0
- package/dist/nosql/fluree/index.d.ts +88 -0
- package/dist/nosql/fuseki/index.d.ts +94 -0
- package/dist/nosql/gcs/index.d.ts +62 -0
- package/dist/nosql/gearman/index.d.ts +77 -0
- package/dist/nosql/geode/index.d.ts +93 -0
- package/dist/nosql/graphdb/index.d.ts +86 -0
- package/dist/nosql/graylog/index.d.ts +118 -0
- package/dist/nosql/gridgain/index.d.ts +78 -0
- package/dist/nosql/hazelcast/index.d.ts +73 -0
- package/dist/nosql/hbase/index.d.ts +123 -0
- package/dist/nosql/ignite/index.d.ts +80 -0
- package/dist/nosql/immudb/index.d.ts +131 -0
- package/dist/nosql/index.d.ts +215 -0
- package/dist/nosql/infinispan/index.d.ts +95 -0
- package/dist/nosql/influxdb/flux-compiler.d.ts +23 -0
- package/dist/nosql/influxdb/flux-compiler.js +170 -0
- package/dist/nosql/influxdb/index.d.ts +300 -0
- package/dist/nosql/influxdb/index.js +0 -0
- package/dist/nosql/kafka/index.d.ts +113 -0
- package/dist/nosql/keyspaces/index.d.ts +122 -0
- package/dist/nosql/kinesis/index.d.ts +121 -0
- package/dist/nosql/leveldb/index.d.ts +112 -0
- package/dist/nosql/leveldb/index.js +103 -1
- package/dist/nosql/lmdb/index.d.ts +76 -0
- package/dist/nosql/loki/index.d.ts +126 -0
- package/dist/nosql/marklogic/index.d.ts +76 -0
- package/dist/nosql/materialize/index.d.ts +91 -0
- package/dist/nosql/meilisearch/index.d.ts +76 -0
- package/dist/nosql/memcached/index.d.ts +138 -0
- package/dist/nosql/milvus/index.d.ts +167 -0
- package/dist/nosql/minio/index.d.ts +122 -0
- package/dist/nosql/momento/index.d.ts +99 -0
- package/dist/nosql/mongodb/index.d.ts +265 -0
- package/dist/nosql/mongodb/index.js +139 -0
- package/dist/nosql/mongodb/where.d.ts +8 -0
- package/dist/nosql/mongodb/where.js +181 -0
- package/dist/nosql/nats/index.d.ts +139 -0
- package/dist/nosql/nedb/index.d.ts +79 -0
- package/dist/nosql/neo4j/index.d.ts +217 -0
- package/dist/nosql/neo4j/index.js +26 -14
- package/dist/nosql/neptune/index.d.ts +234 -0
- package/dist/nosql/neptune/index.js +23 -9
- package/dist/nosql/nsq/index.d.ts +93 -0
- package/dist/nosql/opensearch/index.d.ts +97 -0
- package/dist/nosql/orientdb/index.d.ts +72 -0
- package/dist/nosql/papertrail/index.d.ts +120 -0
- package/dist/nosql/pinecone/index.d.ts +148 -0
- package/dist/nosql/pinot/index.d.ts +90 -0
- package/dist/nosql/pouchdb/index.d.ts +95 -0
- package/dist/nosql/prometheus/index.d.ts +112 -0
- package/dist/nosql/provendb/index.d.ts +143 -0
- package/dist/nosql/provendb/index.js +262 -0
- package/dist/nosql/pubsub/index.d.ts +83 -0
- package/dist/nosql/pulsar/index.d.ts +105 -0
- package/dist/nosql/qdrant/index.d.ts +231 -0
- package/dist/nosql/qldb/index.d.ts +182 -0
- package/dist/nosql/qldb/index.js +302 -1
- package/dist/nosql/r2/index.d.ts +160 -0
- package/dist/nosql/rabbitmq/index.d.ts +131 -0
- package/dist/nosql/ravendb/index.d.ts +138 -0
- package/dist/nosql/ravendb/index.js +323 -9
- package/dist/nosql/ravendb/where.d.ts +38 -0
- package/dist/nosql/ravendb/where.js +94 -0
- package/dist/nosql/redis/index.d.ts +267 -0
- package/dist/nosql/redis/index.js +19 -5
- package/dist/nosql/redpanda/index.d.ts +117 -0
- package/dist/nosql/resque/index.d.ts +91 -0
- package/dist/nosql/rethinkdb/index.d.ts +194 -0
- package/dist/nosql/rethinkdb/index.js +290 -0
- package/dist/nosql/rethinkdb/where.d.ts +38 -0
- package/dist/nosql/rethinkdb/where.js +94 -0
- package/dist/nosql/rocksdb/document-layer.d.ts +162 -0
- package/dist/nosql/rocksdb/document-layer.js +338 -0
- package/dist/nosql/rocksdb/index.d.ts +112 -0
- package/dist/nosql/rocksdb/index.js +103 -1
- package/dist/nosql/rocksdb/where-match.d.ts +21 -0
- package/dist/nosql/rocksdb/where-match.js +238 -0
- package/dist/nosql/rockset/index.d.ts +84 -0
- package/dist/nosql/s3/index.d.ts +170 -0
- package/dist/nosql/scylladb/index.d.ts +117 -0
- package/dist/nosql/signoz/index.d.ts +116 -0
- package/dist/nosql/sns/index.d.ts +99 -0
- package/dist/nosql/solr/index.d.ts +129 -0
- package/dist/nosql/splunk/index.d.ts +125 -0
- package/dist/nosql/sqs/index.d.ts +116 -0
- package/dist/nosql/stardog/index.d.ts +86 -0
- package/dist/nosql/starrocks/index.d.ts +89 -0
- package/dist/nosql/store.d.ts +23 -0
- package/dist/nosql/sumologic/index.d.ts +119 -0
- package/dist/nosql/surrealdb/index.d.ts +156 -0
- package/dist/nosql/surrealdb/index.js +174 -1
- package/dist/nosql/surrealdb/query-compiler.d.ts +26 -0
- package/dist/nosql/surrealdb/query-compiler.js +193 -0
- package/dist/nosql/terminusdb/index.d.ts +95 -0
- package/dist/nosql/tigergraph/index.d.ts +314 -0
- package/dist/nosql/typesense/index.d.ts +82 -0
- package/dist/nosql/unqlite/index.d.ts +68 -0
- package/dist/nosql/upstash/index.d.ts +80 -0
- package/dist/nosql/vercel-kv/index.d.ts +82 -0
- package/dist/nosql/victoriametrics/index.d.ts +129 -0
- package/dist/nosql/virtuoso/index.d.ts +87 -0
- package/dist/nosql/weaviate/index.d.ts +196 -0
- package/dist/operators/index.d.ts +7 -0
- package/dist/operators.d.ts +2947 -0
- package/dist/operators.js +46 -1
- package/dist/prisma-migrate/index.d.ts +28 -0
- package/dist/prisma-migrate/migration-generator.d.ts +21 -0
- package/dist/prisma-migrate/model-generator.d.ts +12 -0
- package/dist/prisma-migrate/relations.d.ts +28 -0
- package/dist/prisma-migrate/schema-parser.d.ts +42 -0
- package/dist/prisma-migrate/type-mapper.d.ts +20 -0
- package/dist/prorm.d.ts +2093 -0
- package/dist/prorm.js +721 -302
- package/dist/query-builders/cte-builder.d.ts +104 -0
- package/dist/query-builders/functions/aggregate.d.ts +199 -0
- package/dist/query-builders/functions/conditional.d.ts +195 -0
- package/dist/query-builders/functions/datetime.d.ts +202 -0
- package/dist/query-builders/functions/fulltext.d.ts +220 -0
- package/dist/query-builders/functions/index.d.ts +17 -0
- package/dist/query-builders/functions/json.d.ts +157 -0
- package/dist/query-builders/functions/math.d.ts +215 -0
- package/dist/query-builders/functions/string.d.ts +233 -0
- package/dist/query-builders/functions/window.d.ts +209 -0
- package/dist/query-builders/include-builder.d.ts +85 -0
- package/dist/query-builders/index-expression-builder.d.ts +153 -0
- package/dist/query-builders/index.d.ts +121 -0
- package/dist/query-builders/index.js +10 -0
- package/dist/query-builders/insert-builder.d.ts +62 -0
- package/dist/query-builders/model-helpers.d.ts +28 -0
- package/dist/query-builders/order-limit-builder.d.ts +84 -0
- package/dist/query-builders/sql-compiler.d.ts +562 -0
- package/dist/query-builders/subquery-builder.d.ts +133 -0
- package/dist/query-builders/update-builder.d.ts +71 -0
- package/dist/query-builders/view-builder.d.ts +189 -0
- package/dist/query-builders/where-builder.d.ts +124 -0
- package/dist/query-interface.d.ts +407 -0
- package/dist/query-interface.js +84 -0
- package/dist/query-optimizers/batch-optimizer.d.ts +175 -0
- package/dist/query-optimizers/explain-plans.d.ts +187 -0
- package/dist/query-optimizers/index.d.ts +27 -0
- package/dist/query-optimizers/prepared-statement-cache.d.ts +252 -0
- package/dist/query-optimizers/query-hints.d.ts +201 -0
- package/dist/query-optimizers/query-optimizer.d.ts +162 -0
- package/dist/query-optimizers/slow-query-logger.d.ts +186 -0
- package/dist/replica-manager.d.ts +235 -0
- package/dist/schema/index.d.ts +7 -0
- package/dist/schema/migration-generator.d.ts +74 -0
- package/dist/schema/schema-differ.d.ts +114 -0
- package/dist/schema/types.d.ts +246 -0
- package/dist/schema-objects.d.ts +78 -0
- package/dist/schema-objects.js +203 -0
- package/dist/sql-constants.d.ts +240 -0
- package/dist/sqlite-advanced.d.ts +572 -0
- package/dist/streams/index.d.ts +5 -0
- package/dist/streams/transforms.d.ts +120 -0
- package/dist/transaction.d.ts +221 -0
- package/dist/types/index.d.ts +3123 -0
- package/dist/user-management.d.ts +141 -0
- package/dist/utils/date.d.ts +149 -0
- package/dist/utils/index.d.ts +359 -0
- package/dist/utils/string.d.ts +88 -0
- package/dist/validators/index.d.ts +7 -0
- package/dist/validators/validator.d.ts +306 -0
- package/package.json +20 -5
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document/query layer for embedded ordered key-value stores (RocksDB, LevelDB).
|
|
3
|
+
*
|
|
4
|
+
* The raw stores only expose `put`/`get`/`del`/`batch`/ordered-iteration. That
|
|
5
|
+
* is a great substrate, but it forces users to hand-roll key design, secondary
|
|
6
|
+
* indexes, range scans and in-memory filtering every time they want to store
|
|
7
|
+
* and query documents. This module lifts the KV surface into the ORM's model
|
|
8
|
+
* API (`findAll`/`findOne`/`findByPk`/`create`/`bulkCreate`/`update`/`destroy`/
|
|
9
|
+
* `count`/`truncate`/associations/transactions) so callers never touch a raw
|
|
10
|
+
* iterator or design a keyspace by hand.
|
|
11
|
+
*
|
|
12
|
+
* ## Key design
|
|
13
|
+
*
|
|
14
|
+
* Documents live under a per-collection prefix:
|
|
15
|
+
*
|
|
16
|
+
* `<collection>\x01<pk>` -> JSON document
|
|
17
|
+
*
|
|
18
|
+
* A prefix range scan (`gte: "<collection>\x01"`, `lt: "<collection>\x02"`)
|
|
19
|
+
* therefore yields exactly the documents of one collection, in primary-key
|
|
20
|
+
* order. `where`/`order`/`limit`/`offset` and the full ORM operator set are
|
|
21
|
+
* evaluated in-memory over the decoded documents, which keeps every standard
|
|
22
|
+
* operator (ranges, `in`, `like`, `between`, `and`/`or`/`not`, ...) correct
|
|
23
|
+
* without maintaining a bespoke index per operator. `create`/`bulkCreate`/
|
|
24
|
+
* `update`/`destroy`/`truncate` compile to atomic `batch()` writes, which also
|
|
25
|
+
* gives us transactional multi-document writes.
|
|
26
|
+
*/
|
|
27
|
+
import { matchWhere, applyOrder, type WhereClause, type OrderSpec } from './where-match';
|
|
28
|
+
export { matchWhere, applyOrder };
|
|
29
|
+
export type { WhereClause, OrderSpec } from './where-match';
|
|
30
|
+
/** A decoded document. Always carries its primary-key field. */
|
|
31
|
+
export type Doc = Record<string, unknown>;
|
|
32
|
+
/** Minimal ordered-KV surface the document layer needs from a backing store. */
|
|
33
|
+
export interface KvBackend {
|
|
34
|
+
get(key: string): Promise<unknown>;
|
|
35
|
+
put(key: string, value: unknown): Promise<void>;
|
|
36
|
+
del(key: string): Promise<void>;
|
|
37
|
+
batch(ops: Array<{
|
|
38
|
+
type: 'put';
|
|
39
|
+
key: string;
|
|
40
|
+
value: unknown;
|
|
41
|
+
} | {
|
|
42
|
+
type: 'del';
|
|
43
|
+
key: string;
|
|
44
|
+
}>): Promise<void>;
|
|
45
|
+
/** Ordered iteration over `[key, value]` pairs whose key is in `[gte, lt)`. */
|
|
46
|
+
scanRange(gte: string, lt: string): AsyncIterable<[string, unknown]>;
|
|
47
|
+
}
|
|
48
|
+
/** Options accepted by {@link KvDocumentLayer.findAll} and friends. */
|
|
49
|
+
export interface FindOptions {
|
|
50
|
+
where?: WhereClause;
|
|
51
|
+
/** `[[field, 'ASC'|'DESC'], ...]`, `['field', ...]`, or a single `'field'`. */
|
|
52
|
+
order?: OrderSpec;
|
|
53
|
+
limit?: number;
|
|
54
|
+
offset?: number;
|
|
55
|
+
/** Return only these fields (plus the primary key) on each row. */
|
|
56
|
+
attributes?: string[];
|
|
57
|
+
/** Eager-load related documents from other collections. */
|
|
58
|
+
include?: IncludeSpec[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Declarative association join. Because embedded KV stores carry no schema,
|
|
62
|
+
* the relationship is described explicitly instead of being read from model
|
|
63
|
+
* metadata - this is what lets associations work through the ORM API without
|
|
64
|
+
* the caller writing their own cross-collection iteration.
|
|
65
|
+
*/
|
|
66
|
+
export interface IncludeSpec {
|
|
67
|
+
/** Property name to attach the loaded record(s) under. */
|
|
68
|
+
as: string;
|
|
69
|
+
/** Collection to load the related document(s) from. */
|
|
70
|
+
collection: string;
|
|
71
|
+
/** Field on the *parent* document holding the join value. Defaults to the parent PK. */
|
|
72
|
+
localKey?: string;
|
|
73
|
+
/** Field on the *related* document matched against `localKey`. Defaults to the related PK. */
|
|
74
|
+
foreignKey?: string;
|
|
75
|
+
/** `true` (default) attaches a single record (or `null`); `false` attaches an array. */
|
|
76
|
+
single?: boolean;
|
|
77
|
+
/** Optional extra filter applied to the related documents. */
|
|
78
|
+
where?: WhereClause;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Maps the ORM model API onto a single ordered-KV backend. One instance
|
|
82
|
+
* services every collection; the collection name is passed per call. The
|
|
83
|
+
* `primaryKey` is the document field used to form keys (default `'id'`).
|
|
84
|
+
*/
|
|
85
|
+
export declare class KvDocumentLayer {
|
|
86
|
+
private readonly backend;
|
|
87
|
+
private readonly primaryKey;
|
|
88
|
+
constructor(backend: KvBackend, primaryKey?: string);
|
|
89
|
+
private docKey;
|
|
90
|
+
private prefixRange;
|
|
91
|
+
private requirePk;
|
|
92
|
+
/** Load every decoded document of a collection, in primary-key order. */
|
|
93
|
+
private scanAll;
|
|
94
|
+
/** Fetch one document by primary key, or `null` if absent. */
|
|
95
|
+
findByPk(collection: string, pk: unknown, options?: FindOptions): Promise<Doc | null>;
|
|
96
|
+
/** Return all documents matching `where`, honoring order/limit/offset/include. */
|
|
97
|
+
findAll(collection: string, options?: FindOptions): Promise<Doc[]>;
|
|
98
|
+
/** Return the first document matching `where` (respecting order), or `null`. */
|
|
99
|
+
findOne(collection: string, options?: FindOptions): Promise<Doc | null>;
|
|
100
|
+
/** Count documents matching `where` (no filter counts the whole collection). */
|
|
101
|
+
count(collection: string, where?: WhereClause): Promise<number>;
|
|
102
|
+
/** Insert a single document. Returns the stored document. */
|
|
103
|
+
create(collection: string, data: Doc): Promise<Doc>;
|
|
104
|
+
/** Insert many documents atomically. Returns the stored documents. */
|
|
105
|
+
bulkCreate(collection: string, rows: Doc[]): Promise<Doc[]>;
|
|
106
|
+
/**
|
|
107
|
+
* Merge `values` into every document matching `where` (all documents when
|
|
108
|
+
* `where` is omitted). Returns the number of documents updated.
|
|
109
|
+
*/
|
|
110
|
+
update(collection: string, values: Doc, where?: WhereClause): Promise<number>;
|
|
111
|
+
/**
|
|
112
|
+
* Delete every document matching `where` (all documents when `where` is
|
|
113
|
+
* omitted). Returns the number of documents deleted.
|
|
114
|
+
*/
|
|
115
|
+
destroy(collection: string, where?: WhereClause): Promise<number>;
|
|
116
|
+
/** Delete every document in a collection. Returns the number deleted. */
|
|
117
|
+
truncate(collection: string): Promise<number>;
|
|
118
|
+
/**
|
|
119
|
+
* Upsert: replace the document with the same primary key (or insert it).
|
|
120
|
+
* Returns the stored document.
|
|
121
|
+
*/
|
|
122
|
+
upsert(collection: string, data: Doc): Promise<Doc>;
|
|
123
|
+
/**
|
|
124
|
+
* Increment numeric `fields` on the document identified by `pk`.
|
|
125
|
+
* `fields` maps field name to the (default `1`) delta. Returns the new doc.
|
|
126
|
+
*/
|
|
127
|
+
increment(collection: string, pk: unknown, fields: Record<string, number> | string[]): Promise<Doc | null>;
|
|
128
|
+
/**
|
|
129
|
+
* Run `fn` and apply all writes it stages atomically. `fn` receives a
|
|
130
|
+
* transaction handle whose `create`/`bulkCreate`/`update`/`destroy` stage
|
|
131
|
+
* `batch` operations instead of writing immediately; on success they are
|
|
132
|
+
* committed in one atomic `batch()`. Reads inside the transaction see the
|
|
133
|
+
* committed store (writes are not visible until commit), mirroring the KV
|
|
134
|
+
* driver's own single-batch atomicity guarantee.
|
|
135
|
+
*/
|
|
136
|
+
transaction<T>(fn: (tx: KvTransaction) => Promise<T>): Promise<T>;
|
|
137
|
+
/** Internal: stage-free access used by KvTransaction for reads/keys. */
|
|
138
|
+
_docKey(collection: string, pk: unknown): string;
|
|
139
|
+
_encode(value: unknown): string;
|
|
140
|
+
_requirePk(doc: Doc, collection: string): unknown;
|
|
141
|
+
_backend(): KvBackend;
|
|
142
|
+
_scanAll(collection: string): Promise<Doc[]>;
|
|
143
|
+
_pk(): string;
|
|
144
|
+
/** Attach related documents to each parent row per the include specs. */
|
|
145
|
+
private loadIncludes;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Transaction handle: stages `put`/`del` operations and commits them in a
|
|
149
|
+
* single atomic `batch()`. Reads delegate to the committed store.
|
|
150
|
+
*/
|
|
151
|
+
export declare class KvTransaction {
|
|
152
|
+
private readonly layer;
|
|
153
|
+
private readonly ops;
|
|
154
|
+
private committed;
|
|
155
|
+
constructor(layer: KvDocumentLayer);
|
|
156
|
+
create(collection: string, data: Doc): this;
|
|
157
|
+
bulkCreate(collection: string, rows: Doc[]): this;
|
|
158
|
+
update(collection: string, values: Doc, where?: WhereClause): Promise<this>;
|
|
159
|
+
destroy(collection: string, where?: WhereClause): Promise<this>;
|
|
160
|
+
/** Commit staged operations atomically. Called automatically by `transaction()`. */
|
|
161
|
+
commit(): Promise<void>;
|
|
162
|
+
}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Document/query layer for embedded ordered key-value stores (RocksDB, LevelDB).
|
|
4
|
+
*
|
|
5
|
+
* The raw stores only expose `put`/`get`/`del`/`batch`/ordered-iteration. That
|
|
6
|
+
* is a great substrate, but it forces users to hand-roll key design, secondary
|
|
7
|
+
* indexes, range scans and in-memory filtering every time they want to store
|
|
8
|
+
* and query documents. This module lifts the KV surface into the ORM's model
|
|
9
|
+
* API (`findAll`/`findOne`/`findByPk`/`create`/`bulkCreate`/`update`/`destroy`/
|
|
10
|
+
* `count`/`truncate`/associations/transactions) so callers never touch a raw
|
|
11
|
+
* iterator or design a keyspace by hand.
|
|
12
|
+
*
|
|
13
|
+
* ## Key design
|
|
14
|
+
*
|
|
15
|
+
* Documents live under a per-collection prefix:
|
|
16
|
+
*
|
|
17
|
+
* `<collection>\x01<pk>` -> JSON document
|
|
18
|
+
*
|
|
19
|
+
* A prefix range scan (`gte: "<collection>\x01"`, `lt: "<collection>\x02"`)
|
|
20
|
+
* therefore yields exactly the documents of one collection, in primary-key
|
|
21
|
+
* order. `where`/`order`/`limit`/`offset` and the full ORM operator set are
|
|
22
|
+
* evaluated in-memory over the decoded documents, which keeps every standard
|
|
23
|
+
* operator (ranges, `in`, `like`, `between`, `and`/`or`/`not`, ...) correct
|
|
24
|
+
* without maintaining a bespoke index per operator. `create`/`bulkCreate`/
|
|
25
|
+
* `update`/`destroy`/`truncate` compile to atomic `batch()` writes, which also
|
|
26
|
+
* gives us transactional multi-document writes.
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.KvTransaction = exports.KvDocumentLayer = exports.applyOrder = exports.matchWhere = void 0;
|
|
30
|
+
const where_match_1 = require("./where-match");
|
|
31
|
+
Object.defineProperty(exports, "matchWhere", { enumerable: true, get: function () { return where_match_1.matchWhere; } });
|
|
32
|
+
Object.defineProperty(exports, "applyOrder", { enumerable: true, get: function () { return where_match_1.applyOrder; } });
|
|
33
|
+
const SEP = '\x01';
|
|
34
|
+
function encodeValue(value) {
|
|
35
|
+
return JSON.stringify(value);
|
|
36
|
+
}
|
|
37
|
+
function decodeValue(value) {
|
|
38
|
+
if (typeof value === 'string') {
|
|
39
|
+
return JSON.parse(value);
|
|
40
|
+
}
|
|
41
|
+
if (value instanceof Uint8Array || Buffer.isBuffer(value)) {
|
|
42
|
+
return JSON.parse(Buffer.from(value).toString('utf8'));
|
|
43
|
+
}
|
|
44
|
+
// Some drivers deserialize JSON automatically; accept plain objects too.
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
function project(doc, attributes, pk) {
|
|
48
|
+
if (!attributes || attributes.length === 0)
|
|
49
|
+
return doc;
|
|
50
|
+
const out = {};
|
|
51
|
+
for (const field of attributes) {
|
|
52
|
+
if (field in doc)
|
|
53
|
+
out[field] = doc[field];
|
|
54
|
+
}
|
|
55
|
+
// Always retain the primary key so records stay addressable.
|
|
56
|
+
if (!(pk in out) && pk in doc)
|
|
57
|
+
out[pk] = doc[pk];
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Maps the ORM model API onto a single ordered-KV backend. One instance
|
|
62
|
+
* services every collection; the collection name is passed per call. The
|
|
63
|
+
* `primaryKey` is the document field used to form keys (default `'id'`).
|
|
64
|
+
*/
|
|
65
|
+
class KvDocumentLayer {
|
|
66
|
+
constructor(backend, primaryKey = 'id') {
|
|
67
|
+
this.backend = backend;
|
|
68
|
+
this.primaryKey = primaryKey;
|
|
69
|
+
}
|
|
70
|
+
docKey(collection, pk) {
|
|
71
|
+
return `${collection}${SEP}${String(pk)}`;
|
|
72
|
+
}
|
|
73
|
+
prefixRange(collection) {
|
|
74
|
+
const gte = `${collection}${SEP}`;
|
|
75
|
+
// '\x02' is the next byte after the '\x01' separator, so this upper bound
|
|
76
|
+
// excludes every key of any other collection while including all of ours.
|
|
77
|
+
const lt = `${collection}\x02`;
|
|
78
|
+
return [gte, lt];
|
|
79
|
+
}
|
|
80
|
+
requirePk(doc, collection) {
|
|
81
|
+
const pk = doc[this.primaryKey];
|
|
82
|
+
if (pk === undefined || pk === null) {
|
|
83
|
+
throw new TypeError(`Document for collection "${collection}" is missing primary key "${this.primaryKey}"`);
|
|
84
|
+
}
|
|
85
|
+
return pk;
|
|
86
|
+
}
|
|
87
|
+
/** Load every decoded document of a collection, in primary-key order. */
|
|
88
|
+
async scanAll(collection) {
|
|
89
|
+
const [gte, lt] = this.prefixRange(collection);
|
|
90
|
+
const docs = [];
|
|
91
|
+
for await (const [, value] of this.backend.scanRange(gte, lt)) {
|
|
92
|
+
docs.push(decodeValue(value));
|
|
93
|
+
}
|
|
94
|
+
return docs;
|
|
95
|
+
}
|
|
96
|
+
/** Fetch one document by primary key, or `null` if absent. */
|
|
97
|
+
async findByPk(collection, pk, options = {}) {
|
|
98
|
+
let raw;
|
|
99
|
+
try {
|
|
100
|
+
raw = await this.backend.get(this.docKey(collection, pk));
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return null; // NotFound in abstract-level throws; treat as absent.
|
|
104
|
+
}
|
|
105
|
+
if (raw === undefined || raw === null)
|
|
106
|
+
return null;
|
|
107
|
+
const doc = decodeValue(raw);
|
|
108
|
+
const withIncludes = options.include ? await this.loadIncludes([doc], options.include) : [doc];
|
|
109
|
+
return project(withIncludes[0], options.attributes, this.primaryKey);
|
|
110
|
+
}
|
|
111
|
+
/** Return all documents matching `where`, honoring order/limit/offset/include. */
|
|
112
|
+
async findAll(collection, options = {}) {
|
|
113
|
+
let rows = await this.scanAll(collection);
|
|
114
|
+
if (options.where) {
|
|
115
|
+
rows = rows.filter((doc) => (0, where_match_1.matchWhere)(doc, options.where));
|
|
116
|
+
}
|
|
117
|
+
if (options.order) {
|
|
118
|
+
rows = (0, where_match_1.applyOrder)(rows, options.order);
|
|
119
|
+
}
|
|
120
|
+
const offset = options.offset ?? 0;
|
|
121
|
+
if (offset > 0)
|
|
122
|
+
rows = rows.slice(offset);
|
|
123
|
+
if (typeof options.limit === 'number')
|
|
124
|
+
rows = rows.slice(0, options.limit);
|
|
125
|
+
if (options.include)
|
|
126
|
+
rows = await this.loadIncludes(rows, options.include);
|
|
127
|
+
if (options.attributes)
|
|
128
|
+
rows = rows.map((doc) => project(doc, options.attributes, this.primaryKey));
|
|
129
|
+
return rows;
|
|
130
|
+
}
|
|
131
|
+
/** Return the first document matching `where` (respecting order), or `null`. */
|
|
132
|
+
async findOne(collection, options = {}) {
|
|
133
|
+
const rows = await this.findAll(collection, { ...options, limit: 1 });
|
|
134
|
+
return rows.length > 0 ? rows[0] : null;
|
|
135
|
+
}
|
|
136
|
+
/** Count documents matching `where` (no filter counts the whole collection). */
|
|
137
|
+
async count(collection, where) {
|
|
138
|
+
const rows = await this.scanAll(collection);
|
|
139
|
+
if (!where)
|
|
140
|
+
return rows.length;
|
|
141
|
+
let n = 0;
|
|
142
|
+
for (const doc of rows)
|
|
143
|
+
if ((0, where_match_1.matchWhere)(doc, where))
|
|
144
|
+
n++;
|
|
145
|
+
return n;
|
|
146
|
+
}
|
|
147
|
+
/** Insert a single document. Returns the stored document. */
|
|
148
|
+
async create(collection, data) {
|
|
149
|
+
const pk = this.requirePk(data, collection);
|
|
150
|
+
await this.backend.put(this.docKey(collection, pk), encodeValue(data));
|
|
151
|
+
return data;
|
|
152
|
+
}
|
|
153
|
+
/** Insert many documents atomically. Returns the stored documents. */
|
|
154
|
+
async bulkCreate(collection, rows) {
|
|
155
|
+
const ops = rows.map((data) => {
|
|
156
|
+
const pk = this.requirePk(data, collection);
|
|
157
|
+
return { type: 'put', key: this.docKey(collection, pk), value: encodeValue(data) };
|
|
158
|
+
});
|
|
159
|
+
await this.backend.batch(ops);
|
|
160
|
+
return rows;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Merge `values` into every document matching `where` (all documents when
|
|
164
|
+
* `where` is omitted). Returns the number of documents updated.
|
|
165
|
+
*/
|
|
166
|
+
async update(collection, values, where) {
|
|
167
|
+
const rows = await this.scanAll(collection);
|
|
168
|
+
const ops = [];
|
|
169
|
+
for (const doc of rows) {
|
|
170
|
+
if (where && !(0, where_match_1.matchWhere)(doc, where))
|
|
171
|
+
continue;
|
|
172
|
+
const merged = { ...doc, ...values };
|
|
173
|
+
// Keep the primary key stable even if `values` tries to change it.
|
|
174
|
+
merged[this.primaryKey] = doc[this.primaryKey];
|
|
175
|
+
ops.push({ type: 'put', key: this.docKey(collection, doc[this.primaryKey]), value: encodeValue(merged) });
|
|
176
|
+
}
|
|
177
|
+
if (ops.length > 0)
|
|
178
|
+
await this.backend.batch(ops);
|
|
179
|
+
return ops.length;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Delete every document matching `where` (all documents when `where` is
|
|
183
|
+
* omitted). Returns the number of documents deleted.
|
|
184
|
+
*/
|
|
185
|
+
async destroy(collection, where) {
|
|
186
|
+
const rows = await this.scanAll(collection);
|
|
187
|
+
const ops = [];
|
|
188
|
+
for (const doc of rows) {
|
|
189
|
+
if (where && !(0, where_match_1.matchWhere)(doc, where))
|
|
190
|
+
continue;
|
|
191
|
+
ops.push({ type: 'del', key: this.docKey(collection, doc[this.primaryKey]) });
|
|
192
|
+
}
|
|
193
|
+
if (ops.length > 0)
|
|
194
|
+
await this.backend.batch(ops);
|
|
195
|
+
return ops.length;
|
|
196
|
+
}
|
|
197
|
+
/** Delete every document in a collection. Returns the number deleted. */
|
|
198
|
+
async truncate(collection) {
|
|
199
|
+
return this.destroy(collection);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Upsert: replace the document with the same primary key (or insert it).
|
|
203
|
+
* Returns the stored document.
|
|
204
|
+
*/
|
|
205
|
+
async upsert(collection, data) {
|
|
206
|
+
return this.create(collection, data);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Increment numeric `fields` on the document identified by `pk`.
|
|
210
|
+
* `fields` maps field name to the (default `1`) delta. Returns the new doc.
|
|
211
|
+
*/
|
|
212
|
+
async increment(collection, pk, fields) {
|
|
213
|
+
const doc = await this.findByPk(collection, pk);
|
|
214
|
+
if (!doc)
|
|
215
|
+
return null;
|
|
216
|
+
const deltas = Array.isArray(fields)
|
|
217
|
+
? Object.fromEntries(fields.map((f) => [f, 1]))
|
|
218
|
+
: fields;
|
|
219
|
+
for (const [field, delta] of Object.entries(deltas)) {
|
|
220
|
+
doc[field] = (typeof doc[field] === 'number' ? doc[field] : 0) + delta;
|
|
221
|
+
}
|
|
222
|
+
await this.backend.put(this.docKey(collection, pk), encodeValue(doc));
|
|
223
|
+
return doc;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Run `fn` and apply all writes it stages atomically. `fn` receives a
|
|
227
|
+
* transaction handle whose `create`/`bulkCreate`/`update`/`destroy` stage
|
|
228
|
+
* `batch` operations instead of writing immediately; on success they are
|
|
229
|
+
* committed in one atomic `batch()`. Reads inside the transaction see the
|
|
230
|
+
* committed store (writes are not visible until commit), mirroring the KV
|
|
231
|
+
* driver's own single-batch atomicity guarantee.
|
|
232
|
+
*/
|
|
233
|
+
async transaction(fn) {
|
|
234
|
+
const tx = new KvTransaction(this);
|
|
235
|
+
const result = await fn(tx);
|
|
236
|
+
await tx.commit();
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
/** Internal: stage-free access used by KvTransaction for reads/keys. */
|
|
240
|
+
_docKey(collection, pk) {
|
|
241
|
+
return this.docKey(collection, pk);
|
|
242
|
+
}
|
|
243
|
+
_encode(value) {
|
|
244
|
+
return encodeValue(value);
|
|
245
|
+
}
|
|
246
|
+
_requirePk(doc, collection) {
|
|
247
|
+
return this.requirePk(doc, collection);
|
|
248
|
+
}
|
|
249
|
+
_backend() {
|
|
250
|
+
return this.backend;
|
|
251
|
+
}
|
|
252
|
+
async _scanAll(collection) {
|
|
253
|
+
return this.scanAll(collection);
|
|
254
|
+
}
|
|
255
|
+
_pk() {
|
|
256
|
+
return this.primaryKey;
|
|
257
|
+
}
|
|
258
|
+
/** Attach related documents to each parent row per the include specs. */
|
|
259
|
+
async loadIncludes(rows, includes) {
|
|
260
|
+
if (rows.length === 0)
|
|
261
|
+
return rows;
|
|
262
|
+
for (const inc of includes) {
|
|
263
|
+
const localKey = inc.localKey ?? this.primaryKey;
|
|
264
|
+
const foreignKey = inc.foreignKey ?? this.primaryKey;
|
|
265
|
+
const single = inc.single ?? true;
|
|
266
|
+
const related = await this.scanAll(inc.collection);
|
|
267
|
+
const filtered = inc.where ? related.filter((d) => (0, where_match_1.matchWhere)(d, inc.where)) : related;
|
|
268
|
+
// Index related docs by their foreign key value for O(1) attachment.
|
|
269
|
+
const byKey = new Map();
|
|
270
|
+
for (const rel of filtered) {
|
|
271
|
+
const k = String(rel[foreignKey]);
|
|
272
|
+
const bucket = byKey.get(k);
|
|
273
|
+
if (bucket)
|
|
274
|
+
bucket.push(rel);
|
|
275
|
+
else
|
|
276
|
+
byKey.set(k, [rel]);
|
|
277
|
+
}
|
|
278
|
+
for (const parent of rows) {
|
|
279
|
+
const matches = byKey.get(String(parent[localKey])) ?? [];
|
|
280
|
+
parent[inc.as] = single ? matches[0] ?? null : matches;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return rows;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
exports.KvDocumentLayer = KvDocumentLayer;
|
|
287
|
+
/**
|
|
288
|
+
* Transaction handle: stages `put`/`del` operations and commits them in a
|
|
289
|
+
* single atomic `batch()`. Reads delegate to the committed store.
|
|
290
|
+
*/
|
|
291
|
+
class KvTransaction {
|
|
292
|
+
constructor(layer) {
|
|
293
|
+
this.layer = layer;
|
|
294
|
+
this.ops = [];
|
|
295
|
+
this.committed = false;
|
|
296
|
+
}
|
|
297
|
+
create(collection, data) {
|
|
298
|
+
const pk = this.layer._requirePk(data, collection);
|
|
299
|
+
this.ops.push({ type: 'put', key: this.layer._docKey(collection, pk), value: this.layer._encode(data) });
|
|
300
|
+
return this;
|
|
301
|
+
}
|
|
302
|
+
bulkCreate(collection, rows) {
|
|
303
|
+
for (const data of rows)
|
|
304
|
+
this.create(collection, data);
|
|
305
|
+
return this;
|
|
306
|
+
}
|
|
307
|
+
async update(collection, values, where) {
|
|
308
|
+
const rows = await this.layer._scanAll(collection);
|
|
309
|
+
const pk = this.layer._pk();
|
|
310
|
+
for (const doc of rows) {
|
|
311
|
+
if (where && !(0, where_match_1.matchWhere)(doc, where))
|
|
312
|
+
continue;
|
|
313
|
+
const merged = { ...doc, ...values };
|
|
314
|
+
merged[pk] = doc[pk];
|
|
315
|
+
this.ops.push({ type: 'put', key: this.layer._docKey(collection, doc[pk]), value: this.layer._encode(merged) });
|
|
316
|
+
}
|
|
317
|
+
return this;
|
|
318
|
+
}
|
|
319
|
+
async destroy(collection, where) {
|
|
320
|
+
const rows = await this.layer._scanAll(collection);
|
|
321
|
+
const pk = this.layer._pk();
|
|
322
|
+
for (const doc of rows) {
|
|
323
|
+
if (where && !(0, where_match_1.matchWhere)(doc, where))
|
|
324
|
+
continue;
|
|
325
|
+
this.ops.push({ type: 'del', key: this.layer._docKey(collection, doc[pk]) });
|
|
326
|
+
}
|
|
327
|
+
return this;
|
|
328
|
+
}
|
|
329
|
+
/** Commit staged operations atomically. Called automatically by `transaction()`. */
|
|
330
|
+
async commit() {
|
|
331
|
+
if (this.committed)
|
|
332
|
+
return;
|
|
333
|
+
this.committed = true;
|
|
334
|
+
if (this.ops.length > 0)
|
|
335
|
+
await this.layer._backend().batch(this.ops);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
exports.KvTransaction = KvTransaction;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { NoSqlStore } from '../store';
|
|
2
|
+
import { KvDocumentLayer, type Doc, type FindOptions, type KvTransaction } from './document-layer';
|
|
3
|
+
import type { WhereClause } from './where-match';
|
|
4
|
+
export { KvDocumentLayer, KvTransaction, type Doc, type FindOptions, type IncludeSpec, } from './document-layer';
|
|
5
|
+
export type { WhereClause, OrderSpec } from './where-match';
|
|
6
|
+
/** A single entry in a `batch()` write: a `put` (with value) or a `del`. */
|
|
7
|
+
export type RocksDBBatchOp = {
|
|
8
|
+
type: 'put';
|
|
9
|
+
key: string;
|
|
10
|
+
value: unknown;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'del';
|
|
13
|
+
key: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Minimal structural type for the pieces of a `rocksdb` client this store
|
|
17
|
+
* uses. Kept local (rather than importing from `rocksdb`) so this module
|
|
18
|
+
* type-checks without the optional driver installed.
|
|
19
|
+
*/
|
|
20
|
+
export interface RocksDBClientLike {
|
|
21
|
+
put(key: string, value: unknown): Promise<void>;
|
|
22
|
+
get(key: string): Promise<unknown>;
|
|
23
|
+
del(key: string): Promise<void>;
|
|
24
|
+
batch(ops: RocksDBBatchOp[]): Promise<void>;
|
|
25
|
+
iterator(options?: Record<string, unknown>): AsyncIterable<[unknown, unknown]>;
|
|
26
|
+
close(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/** Connection options for `RocksDBStore`. */
|
|
29
|
+
export interface RocksDBStoreOptions {
|
|
30
|
+
/** Filesystem path for the RocksDB database directory. Defaults to `'./data/rocksdb'`. */
|
|
31
|
+
path?: string;
|
|
32
|
+
/**
|
|
33
|
+
* A pre-built `rocksdb` client (or a compatible mock). When provided,
|
|
34
|
+
* `connect()` uses it directly and skips `require('rocksdb')` entirely —
|
|
35
|
+
* this is how tests inject a mock without the real driver installed.
|
|
36
|
+
*/
|
|
37
|
+
client?: RocksDBClientLike;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* `RocksDBStore` wraps a `rocksdb` client and exposes its embedded KV surface:
|
|
41
|
+
* `put`/`get`/`del` for single keys, `batch` for atomic multi-key writes,
|
|
42
|
+
* and `list` for ordered key iteration (optionally by prefix).
|
|
43
|
+
*/
|
|
44
|
+
export declare class RocksDBStore implements NoSqlStore {
|
|
45
|
+
readonly name = "rocksdb";
|
|
46
|
+
readonly library = "rocksdb";
|
|
47
|
+
private readonly options;
|
|
48
|
+
private readonly path;
|
|
49
|
+
private client;
|
|
50
|
+
private connected;
|
|
51
|
+
constructor(options?: RocksDBStoreOptions);
|
|
52
|
+
connect(): Promise<void>;
|
|
53
|
+
disconnect(): Promise<void>;
|
|
54
|
+
isConnected(): boolean;
|
|
55
|
+
/** Returns the underlying `rocksdb` client for anything not wrapped here. */
|
|
56
|
+
getClient(): RocksDBClientLike;
|
|
57
|
+
private requireClient;
|
|
58
|
+
private wrapError;
|
|
59
|
+
/** Writes (or overwrites) the value at `key`. */
|
|
60
|
+
put(key: string, value: unknown): Promise<void>;
|
|
61
|
+
/** Reads the value at `key`. */
|
|
62
|
+
get(key: string): Promise<unknown>;
|
|
63
|
+
/** Deletes the value at `key`. */
|
|
64
|
+
del(key: string): Promise<void>;
|
|
65
|
+
/** Applies a list of `put`/`del` operations as a single atomic batch. */
|
|
66
|
+
batch(ops: RocksDBBatchOp[]): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Lists keys in order. With `prefix`, restricts to keys `>= prefix` and
|
|
69
|
+
* `< prefix + '\xff'` (a standard prefix-scan range for byte-ordered keys).
|
|
70
|
+
*/
|
|
71
|
+
list(prefix?: string): Promise<string[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Ordered iteration over `[key, value]` pairs whose key is in `[gte, lt)`.
|
|
74
|
+
* Values are returned as stored (JSON strings, when written through the
|
|
75
|
+
* document layer). Used internally by the document layer's range scans.
|
|
76
|
+
*/
|
|
77
|
+
scanRange(gte: string, lt: string): AsyncIterable<[string, unknown]>;
|
|
78
|
+
private docLayer;
|
|
79
|
+
private kvBackend;
|
|
80
|
+
/**
|
|
81
|
+
* Returns a document layer bound to this store, keyed by `primaryKey`
|
|
82
|
+
* (default `'id'`). Exposes the full ORM model API
|
|
83
|
+
* (`findAll`/`findOne`/`findByPk`/`create`/`bulkCreate`/`update`/`destroy`/
|
|
84
|
+
* `count`/`truncate`/`upsert`/`increment`/`transaction`).
|
|
85
|
+
*/
|
|
86
|
+
documents(primaryKey?: string): KvDocumentLayer;
|
|
87
|
+
/** ORM `findAll` over a collection: where/order/limit/offset/include. */
|
|
88
|
+
findAll(collection: string, options?: FindOptions): Promise<Doc[]>;
|
|
89
|
+
/** ORM `findOne` over a collection. */
|
|
90
|
+
findOne(collection: string, options?: FindOptions): Promise<Doc | null>;
|
|
91
|
+
/** ORM `findByPk` over a collection. */
|
|
92
|
+
findByPk(collection: string, pk: unknown, options?: FindOptions): Promise<Doc | null>;
|
|
93
|
+
/** ORM `count` over a collection. */
|
|
94
|
+
count(collection: string, where?: WhereClause): Promise<number>;
|
|
95
|
+
/** ORM `create` for a single document. */
|
|
96
|
+
create(collection: string, data: Doc): Promise<Doc>;
|
|
97
|
+
/** ORM `bulkCreate` for many documents (atomic batch). */
|
|
98
|
+
bulkCreate(collection: string, rows: Doc[]): Promise<Doc[]>;
|
|
99
|
+
/** ORM `update`: merge `values` into documents matching `where`. */
|
|
100
|
+
updateWhere(collection: string, values: Doc, where?: WhereClause): Promise<number>;
|
|
101
|
+
/** ORM `destroy`: delete documents matching `where`. */
|
|
102
|
+
destroy(collection: string, where?: WhereClause): Promise<number>;
|
|
103
|
+
/** ORM `truncate`: delete every document in a collection. */
|
|
104
|
+
truncate(collection: string): Promise<number>;
|
|
105
|
+
/** Upsert a document by primary key. */
|
|
106
|
+
upsert(collection: string, data: Doc): Promise<Doc>;
|
|
107
|
+
/** Atomically increment numeric fields of one document. */
|
|
108
|
+
increment(collection: string, pk: unknown, fields: Record<string, number> | string[]): Promise<Doc | null>;
|
|
109
|
+
/** Run a function inside an atomic multi-document transaction (single batch commit). */
|
|
110
|
+
transaction<T>(fn: (tx: KvTransaction) => Promise<T>): Promise<T>;
|
|
111
|
+
}
|
|
112
|
+
export default RocksDBStore;
|