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,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RavenDB store implementation for the Prorm NoSQL layer.
|
|
3
|
+
*
|
|
4
|
+
* RavenDB is a transactional, multi-model document database with a
|
|
5
|
+
* unit-of-work session API (store/load/delete + saveChanges) and a fluent,
|
|
6
|
+
* indexed query builder. It does not fit the SQL-shaped `Dialect` interface,
|
|
7
|
+
* so this class implements the minimal `NoSqlStore` marker interface for
|
|
8
|
+
* connection lifecycle and exposes RavenDB's real session CRUD plus `query`
|
|
9
|
+
* API through a small document-CRUD convenience layer. Each operation opens
|
|
10
|
+
* its own short-lived session and commits with `saveChanges()`.
|
|
11
|
+
*
|
|
12
|
+
* Uses the official `ravendb` driver. That driver is an optional peer
|
|
13
|
+
* dependency and is loaded lazily inside `connect()` so importing this module
|
|
14
|
+
* never requires it to be installed. Tests inject a pre-built mock
|
|
15
|
+
* `DocumentStore` via `options.client`, which bypasses the lazy `require`
|
|
16
|
+
* entirely - no real driver and no network are needed.
|
|
17
|
+
*/
|
|
18
|
+
import { NoSqlStore } from '../store';
|
|
19
|
+
/** A native `DocumentStore` handle, left untyped because the driver is an
|
|
20
|
+
* optional dependency not imported here. */
|
|
21
|
+
type DocumentStore = any;
|
|
22
|
+
/** One `[field, direction]` ordering term, e.g. `['createdAt', 'DESC']`. */
|
|
23
|
+
export type OrderTerm = [string, 'ASC' | 'DESC'] | string;
|
|
24
|
+
/** Options for {@link RavenDbStore.findAll}/{@link RavenDbStore.findOne}. */
|
|
25
|
+
export interface RavenFindOptions {
|
|
26
|
+
/** Ordering terms applied in sequence. A bare string sorts ascending. */
|
|
27
|
+
order?: OrderTerm | OrderTerm[];
|
|
28
|
+
/** Maximum number of documents to return (`take`). */
|
|
29
|
+
limit?: number;
|
|
30
|
+
/** Number of leading documents to skip (`skip`, offset). */
|
|
31
|
+
offset?: number;
|
|
32
|
+
}
|
|
33
|
+
/** A group-aggregation request for {@link RavenDbStore.aggregate}. */
|
|
34
|
+
export interface RavenAggregateOptions {
|
|
35
|
+
/** ORM `where` filter applied before grouping. */
|
|
36
|
+
where?: Record<string | symbol, unknown>;
|
|
37
|
+
/** Field(s) to group by. Omit for a single whole-collection group. */
|
|
38
|
+
groupBy?: string | string[];
|
|
39
|
+
/** Emit a `count` per group. */
|
|
40
|
+
count?: boolean;
|
|
41
|
+
/** Fields to `sum` per group, keyed by output name → source field. */
|
|
42
|
+
sum?: Record<string, string>;
|
|
43
|
+
/** Fields to `avg` per group, keyed by output name → source field. */
|
|
44
|
+
avg?: Record<string, string>;
|
|
45
|
+
/** Fields to `min` per group, keyed by output name → source field. */
|
|
46
|
+
min?: Record<string, string>;
|
|
47
|
+
/** Fields to `max` per group, keyed by output name → source field. */
|
|
48
|
+
max?: Record<string, string>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Connection options for `RavenDbStore`.
|
|
52
|
+
*
|
|
53
|
+
* `urls` and `database` configure the underlying `DocumentStore`. When a
|
|
54
|
+
* pre-built `client` is supplied (e.g. in tests), `connect()` uses it directly
|
|
55
|
+
* and skips loading the `ravendb` driver.
|
|
56
|
+
*/
|
|
57
|
+
export interface RavenDbStoreOptions {
|
|
58
|
+
urls?: string[];
|
|
59
|
+
database?: string;
|
|
60
|
+
/** A pre-built `DocumentStore` to use instead of the driver. */
|
|
61
|
+
client?: DocumentStore;
|
|
62
|
+
}
|
|
63
|
+
export declare class RavenDbStore implements NoSqlStore {
|
|
64
|
+
readonly name = "ravendb";
|
|
65
|
+
readonly library = "ravendb";
|
|
66
|
+
private readonly options;
|
|
67
|
+
private store;
|
|
68
|
+
private connected;
|
|
69
|
+
constructor(options?: RavenDbStoreOptions);
|
|
70
|
+
connect(): Promise<void>;
|
|
71
|
+
disconnect(): Promise<void>;
|
|
72
|
+
isConnected(): boolean;
|
|
73
|
+
getClient(): DocumentStore;
|
|
74
|
+
private requireStore;
|
|
75
|
+
/** Store a document in `collection`; returns the id used. */
|
|
76
|
+
insert(collection: string, doc: Record<string, unknown>): Promise<unknown>;
|
|
77
|
+
/** Load a document by id. */
|
|
78
|
+
get(_collection: string, id: string): Promise<unknown>;
|
|
79
|
+
/** Load, merge `patch`, and save; returns the updated entity. */
|
|
80
|
+
update(_collection: string, id: string, patch: Record<string, unknown>): Promise<unknown>;
|
|
81
|
+
/** Delete a document by id. */
|
|
82
|
+
delete(_collection: string, id: string): Promise<unknown>;
|
|
83
|
+
/**
|
|
84
|
+
* Query `collection` with an ORM `where` clause. The `where` object accepts
|
|
85
|
+
* the full ORM operator surface (`Op.gt`, `Op.in`, `Op.between`, `Op.like`,
|
|
86
|
+
* `Op.and`/`Op.or`, ...), translated to native RavenDB session-query
|
|
87
|
+
* conditions - so a plain `{ field: value }` still behaves as equality, but
|
|
88
|
+
* richer queries no longer require hand-written RQL. Bare-field values are
|
|
89
|
+
* ANDed together (Op.* comparisons expand per field).
|
|
90
|
+
*/
|
|
91
|
+
query(collection: string, where?: Record<string | symbol, unknown>): Promise<unknown[]>;
|
|
92
|
+
/**
|
|
93
|
+
* Fetch all documents in `collection` matching an ORM `where` clause, with
|
|
94
|
+
* optional ordering, offset (`skip`), and limit (`take`).
|
|
95
|
+
*/
|
|
96
|
+
findAll<T = unknown>(collection: string, where?: Record<string | symbol, unknown>, options?: RavenFindOptions): Promise<T[]>;
|
|
97
|
+
/** Fetch the first document in `collection` matching an ORM `where` clause (respecting `order`), or `null`. */
|
|
98
|
+
findOne<T = unknown>(collection: string, where?: Record<string | symbol, unknown>, options?: Omit<RavenFindOptions, 'limit'>): Promise<T | null>;
|
|
99
|
+
/** Count documents in `collection` matching an ORM `where` clause. */
|
|
100
|
+
count(collection: string, where?: Record<string | symbol, unknown>): Promise<number>;
|
|
101
|
+
/**
|
|
102
|
+
* Store multiple documents in a single session/transaction (one
|
|
103
|
+
* `saveChanges()`). Returns the ids assigned to each document, in order.
|
|
104
|
+
*/
|
|
105
|
+
bulkInsert(collection: string, docs: Record<string, unknown>[]): Promise<string[]>;
|
|
106
|
+
/**
|
|
107
|
+
* Insert-or-update by id: loads the document, merges `doc` into it if it
|
|
108
|
+
* exists, otherwise stores `doc` fresh - all in one session. Returns the id.
|
|
109
|
+
*/
|
|
110
|
+
upsert(collection: string, doc: Record<string, unknown>, id?: string): Promise<string>;
|
|
111
|
+
/**
|
|
112
|
+
* Update every document in `collection` matching an ORM `where` clause,
|
|
113
|
+
* merging `patch` into each, in a single session/transaction. Returns the
|
|
114
|
+
* number of documents updated.
|
|
115
|
+
*/
|
|
116
|
+
updateWhere(collection: string, where: Record<string | symbol, unknown>, patch: Record<string, unknown>): Promise<number>;
|
|
117
|
+
/**
|
|
118
|
+
* Delete every document in `collection` matching an ORM `where` clause, in a
|
|
119
|
+
* single session/transaction. Returns the number of documents deleted.
|
|
120
|
+
*/
|
|
121
|
+
deleteWhere(collection: string, where: Record<string | symbol, unknown>): Promise<number>;
|
|
122
|
+
/**
|
|
123
|
+
* Grouped aggregation over `collection` (`count`/`sum`/`avg`/`min`/`max`),
|
|
124
|
+
* with an optional ORM `where` pre-filter. Computed client-side over the
|
|
125
|
+
* matched documents so callers get standard `GROUP BY`-style results without
|
|
126
|
+
* hand-writing an RQL `group by`/index. Returns one entry per group:
|
|
127
|
+
* `{ group, ...aggregates }`.
|
|
128
|
+
*/
|
|
129
|
+
aggregate(collection: string, options?: RavenAggregateOptions): Promise<Array<Record<string, unknown>>>;
|
|
130
|
+
/**
|
|
131
|
+
* Run `fn` inside a single RavenDB session (unit of work), passing the
|
|
132
|
+
* session so multiple store/load/delete operations commit atomically with
|
|
133
|
+
* one `saveChanges()`. RavenDB sessions are ACID transactions, so this is
|
|
134
|
+
* the native way to make multi-document changes all-or-nothing.
|
|
135
|
+
*/
|
|
136
|
+
withTransaction<T>(fn: (session: any) => Promise<T>): Promise<T>;
|
|
137
|
+
}
|
|
138
|
+
export default RavenDbStore;
|
|
@@ -19,6 +19,105 @@
|
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.RavenDbStore = void 0;
|
|
21
21
|
const errors_1 = require("../../errors");
|
|
22
|
+
const operators_1 = require("../../operators");
|
|
23
|
+
const where_1 = require("./where");
|
|
24
|
+
/** Whether `order` is a single `[field, direction]` tuple rather than a list of terms. */
|
|
25
|
+
function isSingleOrderTerm(order) {
|
|
26
|
+
return order.length === 2 && typeof order[0] === 'string' && (order[1] === 'ASC' || order[1] === 'DESC');
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Apply a {@link WhereNode} tree to a RavenDB session query builder `q`,
|
|
30
|
+
* emitting `whereEquals`/`whereGreaterThan`/`whereIn`/... conditions and
|
|
31
|
+
* grouping `Op.and`/`Op.or` with `openSubclause`/`closeSubclause` +
|
|
32
|
+
* `andAlso`/`orElse`. This lets callers pass ORM `where` clauses instead of
|
|
33
|
+
* hand-writing RQL.
|
|
34
|
+
*/
|
|
35
|
+
function applyRavenWhere(q, node) {
|
|
36
|
+
switch (node.kind) {
|
|
37
|
+
case 'true':
|
|
38
|
+
return q;
|
|
39
|
+
case 'and':
|
|
40
|
+
return applyRavenGroup(q, node.nodes, 'andAlso');
|
|
41
|
+
case 'or':
|
|
42
|
+
return applyRavenGroup(q, node.nodes, 'orElse');
|
|
43
|
+
case 'not':
|
|
44
|
+
return applyRavenWhere(q.not(), node.node);
|
|
45
|
+
case 'cmp':
|
|
46
|
+
return applyRavenCmp(q, node.field, node.op, node.value);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function applyRavenGroup(q, nodes, combinator) {
|
|
50
|
+
const meaningful = nodes.filter((n) => n.kind !== 'true');
|
|
51
|
+
if (meaningful.length === 0)
|
|
52
|
+
return q;
|
|
53
|
+
if (meaningful.length === 1)
|
|
54
|
+
return applyRavenWhere(q, meaningful[0]);
|
|
55
|
+
let out = q.openSubclause();
|
|
56
|
+
meaningful.forEach((n, i) => {
|
|
57
|
+
if (i > 0)
|
|
58
|
+
out = out[combinator]();
|
|
59
|
+
out = applyRavenWhere(out, n);
|
|
60
|
+
});
|
|
61
|
+
return out.closeSubclause();
|
|
62
|
+
}
|
|
63
|
+
function applyRavenCmp(q, field, op, value) {
|
|
64
|
+
switch (op) {
|
|
65
|
+
case operators_1.Op.eq:
|
|
66
|
+
return q.whereEquals(field, value);
|
|
67
|
+
case operators_1.Op.ne:
|
|
68
|
+
return q.whereNotEquals(field, value);
|
|
69
|
+
case operators_1.Op.gt:
|
|
70
|
+
return q.whereGreaterThan(field, value);
|
|
71
|
+
case operators_1.Op.gte:
|
|
72
|
+
return q.whereGreaterThanOrEqual(field, value);
|
|
73
|
+
case operators_1.Op.lt:
|
|
74
|
+
return q.whereLessThan(field, value);
|
|
75
|
+
case operators_1.Op.lte:
|
|
76
|
+
return q.whereLessThanOrEqual(field, value);
|
|
77
|
+
case operators_1.Op.in:
|
|
78
|
+
return q.whereIn(field, value);
|
|
79
|
+
case operators_1.Op.notIn:
|
|
80
|
+
return q.not().whereIn(field, value);
|
|
81
|
+
case operators_1.Op.between: {
|
|
82
|
+
const [lo, hi] = value;
|
|
83
|
+
return q.whereBetween(field, lo, hi);
|
|
84
|
+
}
|
|
85
|
+
case operators_1.Op.notBetween: {
|
|
86
|
+
const [lo, hi] = value;
|
|
87
|
+
return q.not().whereBetween(field, lo, hi);
|
|
88
|
+
}
|
|
89
|
+
case operators_1.Op.isNull:
|
|
90
|
+
return q.whereEquals(field, null);
|
|
91
|
+
case operators_1.Op.isNotNull:
|
|
92
|
+
return q.whereExists(field).andAlso().not().whereEquals(field, null);
|
|
93
|
+
case operators_1.Op.startsWith:
|
|
94
|
+
return q.whereStartsWith(field, value);
|
|
95
|
+
case operators_1.Op.endsWith:
|
|
96
|
+
return q.whereEndsWith(field, value);
|
|
97
|
+
case operators_1.Op.like:
|
|
98
|
+
case operators_1.Op.iLike:
|
|
99
|
+
return q.whereRegex(field, (0, where_1.likeToRegex)(String(value)).replace(/^\^|\$$/g, ''));
|
|
100
|
+
case operators_1.Op.notLike:
|
|
101
|
+
case operators_1.Op.notILike:
|
|
102
|
+
return q.not().whereRegex(field, (0, where_1.likeToRegex)(String(value)).replace(/^\^|\$$/g, ''));
|
|
103
|
+
case operators_1.Op.regexp:
|
|
104
|
+
case operators_1.Op.iRegexp:
|
|
105
|
+
return q.whereRegex(field, String(value));
|
|
106
|
+
case operators_1.Op.notRegexp:
|
|
107
|
+
case operators_1.Op.notIRegexp:
|
|
108
|
+
return q.not().whereRegex(field, String(value));
|
|
109
|
+
case operators_1.Op.substring:
|
|
110
|
+
case operators_1.Op.contains:
|
|
111
|
+
return q.whereRegex(field, escapeRegexRql(String(value)));
|
|
112
|
+
default:
|
|
113
|
+
throw new errors_1.DatabaseError(`RavenDB: unsupported where operator "${op.toString()}"`, {
|
|
114
|
+
code: errors_1.ErrorCodes.QUERY_ERROR,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function escapeRegexRql(s) {
|
|
119
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
120
|
+
}
|
|
22
121
|
class RavenDbStore {
|
|
23
122
|
constructor(options = {}) {
|
|
24
123
|
this.name = 'ravendb';
|
|
@@ -141,27 +240,242 @@ class RavenDbStore {
|
|
|
141
240
|
}
|
|
142
241
|
}
|
|
143
242
|
/**
|
|
144
|
-
* Query `collection
|
|
145
|
-
*
|
|
146
|
-
*
|
|
243
|
+
* Query `collection` with an ORM `where` clause. The `where` object accepts
|
|
244
|
+
* the full ORM operator surface (`Op.gt`, `Op.in`, `Op.between`, `Op.like`,
|
|
245
|
+
* `Op.and`/`Op.or`, ...), translated to native RavenDB session-query
|
|
246
|
+
* conditions - so a plain `{ field: value }` still behaves as equality, but
|
|
247
|
+
* richer queries no longer require hand-written RQL. Bare-field values are
|
|
248
|
+
* ANDed together (Op.* comparisons expand per field).
|
|
147
249
|
*/
|
|
148
|
-
async query(collection,
|
|
250
|
+
async query(collection, where = {}) {
|
|
251
|
+
return this.findAll(collection, where);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Fetch all documents in `collection` matching an ORM `where` clause, with
|
|
255
|
+
* optional ordering, offset (`skip`), and limit (`take`).
|
|
256
|
+
*/
|
|
257
|
+
async findAll(collection, where = {}, options = {}) {
|
|
149
258
|
const store = this.requireStore();
|
|
150
259
|
try {
|
|
151
260
|
const session = store.openSession();
|
|
152
|
-
let q = session.query({ collection });
|
|
153
|
-
|
|
154
|
-
|
|
261
|
+
let q = applyRavenWhere(session.query({ collection }), (0, where_1.parseWhere)(where));
|
|
262
|
+
if (options.order !== undefined) {
|
|
263
|
+
const terms = Array.isArray(options.order) && !isSingleOrderTerm(options.order)
|
|
264
|
+
? options.order
|
|
265
|
+
: [options.order];
|
|
266
|
+
for (const term of terms) {
|
|
267
|
+
if (typeof term === 'string')
|
|
268
|
+
q = q.orderBy(term);
|
|
269
|
+
else
|
|
270
|
+
q = term[1] === 'DESC' ? q.orderByDescending(term[0]) : q.orderBy(term[0]);
|
|
271
|
+
}
|
|
155
272
|
}
|
|
273
|
+
if (typeof options.offset === 'number')
|
|
274
|
+
q = q.skip(options.offset);
|
|
275
|
+
if (typeof options.limit === 'number')
|
|
276
|
+
q = q.take(options.limit);
|
|
277
|
+
const results = await q.all();
|
|
278
|
+
return (results ?? []);
|
|
279
|
+
}
|
|
280
|
+
catch (err) {
|
|
281
|
+
throw wrapDatabaseError(err, 'RavenDB findAll failed');
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/** Fetch the first document in `collection` matching an ORM `where` clause (respecting `order`), or `null`. */
|
|
285
|
+
async findOne(collection, where = {}, options = {}) {
|
|
286
|
+
const rows = await this.findAll(collection, where, { ...options, limit: 1 });
|
|
287
|
+
return rows.length > 0 ? rows[0] : null;
|
|
288
|
+
}
|
|
289
|
+
/** Count documents in `collection` matching an ORM `where` clause. */
|
|
290
|
+
async count(collection, where = {}) {
|
|
291
|
+
const store = this.requireStore();
|
|
292
|
+
try {
|
|
293
|
+
const session = store.openSession();
|
|
294
|
+
const q = applyRavenWhere(session.query({ collection }), (0, where_1.parseWhere)(where));
|
|
295
|
+
if (typeof q.count === 'function')
|
|
296
|
+
return await q.count();
|
|
156
297
|
const results = await q.all();
|
|
157
|
-
return results ?? [];
|
|
298
|
+
return (results ?? []).length;
|
|
299
|
+
}
|
|
300
|
+
catch (err) {
|
|
301
|
+
throw wrapDatabaseError(err, 'RavenDB count failed');
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Store multiple documents in a single session/transaction (one
|
|
306
|
+
* `saveChanges()`). Returns the ids assigned to each document, in order.
|
|
307
|
+
*/
|
|
308
|
+
async bulkInsert(collection, docs) {
|
|
309
|
+
const store = this.requireStore();
|
|
310
|
+
try {
|
|
311
|
+
const session = store.openSession();
|
|
312
|
+
const ids = [];
|
|
313
|
+
for (const doc of docs) {
|
|
314
|
+
const id = (doc.id ?? `${collection}/${genId()}`);
|
|
315
|
+
await session.store(doc, id);
|
|
316
|
+
ids.push(id);
|
|
317
|
+
}
|
|
318
|
+
await session.saveChanges();
|
|
319
|
+
return ids;
|
|
158
320
|
}
|
|
159
321
|
catch (err) {
|
|
160
|
-
throw wrapDatabaseError(err, 'RavenDB
|
|
322
|
+
throw wrapDatabaseError(err, 'RavenDB bulkInsert failed');
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Insert-or-update by id: loads the document, merges `doc` into it if it
|
|
327
|
+
* exists, otherwise stores `doc` fresh - all in one session. Returns the id.
|
|
328
|
+
*/
|
|
329
|
+
async upsert(collection, doc, id) {
|
|
330
|
+
const store = this.requireStore();
|
|
331
|
+
try {
|
|
332
|
+
const resolvedId = (id ?? doc.id ?? `${collection}/${genId()}`);
|
|
333
|
+
const session = store.openSession();
|
|
334
|
+
const existing = await session.load(resolvedId);
|
|
335
|
+
if (existing) {
|
|
336
|
+
Object.assign(existing, doc);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
await session.store(doc, resolvedId);
|
|
340
|
+
}
|
|
341
|
+
await session.saveChanges();
|
|
342
|
+
return resolvedId;
|
|
343
|
+
}
|
|
344
|
+
catch (err) {
|
|
345
|
+
throw wrapDatabaseError(err, 'RavenDB upsert failed');
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Update every document in `collection` matching an ORM `where` clause,
|
|
350
|
+
* merging `patch` into each, in a single session/transaction. Returns the
|
|
351
|
+
* number of documents updated.
|
|
352
|
+
*/
|
|
353
|
+
async updateWhere(collection, where, patch) {
|
|
354
|
+
const store = this.requireStore();
|
|
355
|
+
try {
|
|
356
|
+
const session = store.openSession();
|
|
357
|
+
const q = applyRavenWhere(session.query({ collection }), (0, where_1.parseWhere)(where));
|
|
358
|
+
const matches = (await q.all()) ?? [];
|
|
359
|
+
for (const entity of matches) {
|
|
360
|
+
Object.assign(entity, patch);
|
|
361
|
+
}
|
|
362
|
+
await session.saveChanges();
|
|
363
|
+
return matches.length;
|
|
364
|
+
}
|
|
365
|
+
catch (err) {
|
|
366
|
+
throw wrapDatabaseError(err, 'RavenDB updateWhere failed');
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Delete every document in `collection` matching an ORM `where` clause, in a
|
|
371
|
+
* single session/transaction. Returns the number of documents deleted.
|
|
372
|
+
*/
|
|
373
|
+
async deleteWhere(collection, where) {
|
|
374
|
+
const store = this.requireStore();
|
|
375
|
+
try {
|
|
376
|
+
const session = store.openSession();
|
|
377
|
+
const q = applyRavenWhere(session.query({ collection }), (0, where_1.parseWhere)(where));
|
|
378
|
+
const matches = (await q.all()) ?? [];
|
|
379
|
+
for (const entity of matches) {
|
|
380
|
+
await session.delete(entity);
|
|
381
|
+
}
|
|
382
|
+
await session.saveChanges();
|
|
383
|
+
return matches.length;
|
|
384
|
+
}
|
|
385
|
+
catch (err) {
|
|
386
|
+
throw wrapDatabaseError(err, 'RavenDB deleteWhere failed');
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Grouped aggregation over `collection` (`count`/`sum`/`avg`/`min`/`max`),
|
|
391
|
+
* with an optional ORM `where` pre-filter. Computed client-side over the
|
|
392
|
+
* matched documents so callers get standard `GROUP BY`-style results without
|
|
393
|
+
* hand-writing an RQL `group by`/index. Returns one entry per group:
|
|
394
|
+
* `{ group, ...aggregates }`.
|
|
395
|
+
*/
|
|
396
|
+
async aggregate(collection, options = {}) {
|
|
397
|
+
const docs = await this.findAll(collection, options.where ?? {});
|
|
398
|
+
const groupFields = options.groupBy
|
|
399
|
+
? Array.isArray(options.groupBy)
|
|
400
|
+
? options.groupBy
|
|
401
|
+
: [options.groupBy]
|
|
402
|
+
: [];
|
|
403
|
+
const groups = new Map();
|
|
404
|
+
for (const doc of docs) {
|
|
405
|
+
const keyParts = groupFields.map((f) => getPath(doc, f));
|
|
406
|
+
const key = groupFields.length === 0 ? null : groupFields.length === 1 ? keyParts[0] : keyParts;
|
|
407
|
+
const mapKey = JSON.stringify(key ?? null);
|
|
408
|
+
const bucket = groups.get(mapKey) ?? { key, rows: [] };
|
|
409
|
+
bucket.rows.push(doc);
|
|
410
|
+
groups.set(mapKey, bucket);
|
|
411
|
+
}
|
|
412
|
+
const hasOtherAgg = !!(options.sum || options.avg || options.min || options.max);
|
|
413
|
+
const result = [];
|
|
414
|
+
for (const { key, rows } of groups.values()) {
|
|
415
|
+
const entry = { group: key };
|
|
416
|
+
if (options.count || !hasOtherAgg) {
|
|
417
|
+
entry.count = rows.length;
|
|
418
|
+
}
|
|
419
|
+
for (const [out, src] of Object.entries(options.sum ?? {}))
|
|
420
|
+
entry[out] = sumBy(rows, src);
|
|
421
|
+
for (const [out, src] of Object.entries(options.avg ?? {}))
|
|
422
|
+
entry[out] = rows.length ? sumBy(rows, src) / rows.length : null;
|
|
423
|
+
for (const [out, src] of Object.entries(options.min ?? {}))
|
|
424
|
+
entry[out] = minBy(rows, src);
|
|
425
|
+
for (const [out, src] of Object.entries(options.max ?? {}))
|
|
426
|
+
entry[out] = maxBy(rows, src);
|
|
427
|
+
result.push(entry);
|
|
428
|
+
}
|
|
429
|
+
return result;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Run `fn` inside a single RavenDB session (unit of work), passing the
|
|
433
|
+
* session so multiple store/load/delete operations commit atomically with
|
|
434
|
+
* one `saveChanges()`. RavenDB sessions are ACID transactions, so this is
|
|
435
|
+
* the native way to make multi-document changes all-or-nothing.
|
|
436
|
+
*/
|
|
437
|
+
async withTransaction(fn) {
|
|
438
|
+
const store = this.requireStore();
|
|
439
|
+
const session = store.openSession();
|
|
440
|
+
try {
|
|
441
|
+
const result = await fn(session);
|
|
442
|
+
await session.saveChanges();
|
|
443
|
+
return result;
|
|
444
|
+
}
|
|
445
|
+
catch (err) {
|
|
446
|
+
throw wrapDatabaseError(err, 'RavenDB transaction failed');
|
|
161
447
|
}
|
|
162
448
|
}
|
|
163
449
|
}
|
|
164
450
|
exports.RavenDbStore = RavenDbStore;
|
|
451
|
+
function getPath(obj, path) {
|
|
452
|
+
return path.split('.').reduce((acc, part) => (acc == null ? undefined : acc[part]), obj);
|
|
453
|
+
}
|
|
454
|
+
function sumBy(rows, field) {
|
|
455
|
+
return rows.reduce((acc, r) => acc + Number(getPath(r, field) ?? 0), 0);
|
|
456
|
+
}
|
|
457
|
+
function minBy(rows, field) {
|
|
458
|
+
let min;
|
|
459
|
+
for (const r of rows) {
|
|
460
|
+
const v = getPath(r, field);
|
|
461
|
+
if (v == null)
|
|
462
|
+
continue;
|
|
463
|
+
if (min === undefined || v < min)
|
|
464
|
+
min = v;
|
|
465
|
+
}
|
|
466
|
+
return min ?? null;
|
|
467
|
+
}
|
|
468
|
+
function maxBy(rows, field) {
|
|
469
|
+
let max;
|
|
470
|
+
for (const r of rows) {
|
|
471
|
+
const v = getPath(r, field);
|
|
472
|
+
if (v == null)
|
|
473
|
+
continue;
|
|
474
|
+
if (max === undefined || v > max)
|
|
475
|
+
max = v;
|
|
476
|
+
}
|
|
477
|
+
return max ?? null;
|
|
478
|
+
}
|
|
165
479
|
function genId() {
|
|
166
480
|
return `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 10)}`;
|
|
167
481
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** A single field comparison, e.g. `age >= 18`. */
|
|
2
|
+
export interface CmpNode {
|
|
3
|
+
kind: 'cmp';
|
|
4
|
+
field: string;
|
|
5
|
+
op: symbol;
|
|
6
|
+
value: unknown;
|
|
7
|
+
}
|
|
8
|
+
/** A normalized boolean tree produced by {@link parseWhere}. */
|
|
9
|
+
export type WhereNode = CmpNode | {
|
|
10
|
+
kind: 'and';
|
|
11
|
+
nodes: WhereNode[];
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'or';
|
|
14
|
+
nodes: WhereNode[];
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'not';
|
|
17
|
+
node: WhereNode;
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'true';
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Parse an ORM `where` object into a {@link WhereNode} tree.
|
|
23
|
+
*
|
|
24
|
+
* - String keys are field conditions: a scalar means equality, an array means
|
|
25
|
+
* `Op.in`, and a nested `{ [Op.*]: value }` object expands to one comparison
|
|
26
|
+
* per operator.
|
|
27
|
+
* - `Op.and`/`Op.or` take an array of sub-`where` objects; `Op.not` negates a
|
|
28
|
+
* single sub-`where`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseWhere(where: Record<string | symbol, unknown> | undefined | null): WhereNode;
|
|
31
|
+
/** Escape a string for safe inclusion in a regular expression. */
|
|
32
|
+
export declare function escapeRegex(s: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Translate a SQL `LIKE`/`ILIKE` pattern into an anchored regular expression
|
|
35
|
+
* (`%` → `.*`, `_` → `.`), so stores that only speak regex can honor ORM
|
|
36
|
+
* `Op.like` queries without the caller hand-writing a pattern.
|
|
37
|
+
*/
|
|
38
|
+
export declare function likeToRegex(pattern: string, caseInsensitive?: boolean): string;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseWhere = parseWhere;
|
|
4
|
+
exports.escapeRegex = escapeRegex;
|
|
5
|
+
exports.likeToRegex = likeToRegex;
|
|
6
|
+
/**
|
|
7
|
+
* ORM where-clause parser for the RavenDB store.
|
|
8
|
+
*
|
|
9
|
+
* Turns the ORM's `where` shape (plain-object field conditions, `Op.*`
|
|
10
|
+
* comparison symbols, and `Op.and`/`Op.or`/`Op.not` logical symbols) into a
|
|
11
|
+
* small, store-agnostic {@link WhereNode} tree that the store then renders to
|
|
12
|
+
* a RavenDB session query. This is what lets callers write standard ORM
|
|
13
|
+
* queries (`{ age: { [Op.gte]: 18 } }`) instead of hand-building ReQL row
|
|
14
|
+
* predicates.
|
|
15
|
+
*/
|
|
16
|
+
const operators_1 = require("../../operators");
|
|
17
|
+
/** Whether `v` is a plain object carrying `Op.*` comparison symbols (e.g. `{ [Op.gt]: 5 }`). */
|
|
18
|
+
function hasOpSymbols(v) {
|
|
19
|
+
return (v !== null &&
|
|
20
|
+
typeof v === 'object' &&
|
|
21
|
+
!Array.isArray(v) &&
|
|
22
|
+
Object.getOwnPropertySymbols(v).length > 0);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parse an ORM `where` object into a {@link WhereNode} tree.
|
|
26
|
+
*
|
|
27
|
+
* - String keys are field conditions: a scalar means equality, an array means
|
|
28
|
+
* `Op.in`, and a nested `{ [Op.*]: value }` object expands to one comparison
|
|
29
|
+
* per operator.
|
|
30
|
+
* - `Op.and`/`Op.or` take an array of sub-`where` objects; `Op.not` negates a
|
|
31
|
+
* single sub-`where`.
|
|
32
|
+
*/
|
|
33
|
+
function parseWhere(where) {
|
|
34
|
+
if (!where)
|
|
35
|
+
return { kind: 'true' };
|
|
36
|
+
const nodes = [];
|
|
37
|
+
for (const sym of Object.getOwnPropertySymbols(where)) {
|
|
38
|
+
const val = where[sym];
|
|
39
|
+
if (sym === operators_1.Op.and) {
|
|
40
|
+
nodes.push({ kind: 'and', nodes: asArray(val).map(parseWhere) });
|
|
41
|
+
}
|
|
42
|
+
else if (sym === operators_1.Op.or) {
|
|
43
|
+
nodes.push({ kind: 'or', nodes: asArray(val).map(parseWhere) });
|
|
44
|
+
}
|
|
45
|
+
else if (sym === operators_1.Op.not) {
|
|
46
|
+
nodes.push({ kind: 'not', node: parseWhere(val) });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
for (const field of Object.keys(where)) {
|
|
50
|
+
const val = where[field];
|
|
51
|
+
if (hasOpSymbols(val)) {
|
|
52
|
+
for (const opSym of Object.getOwnPropertySymbols(val)) {
|
|
53
|
+
nodes.push({ kind: 'cmp', field, op: opSym, value: val[opSym] });
|
|
54
|
+
}
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (Array.isArray(val)) {
|
|
58
|
+
nodes.push({ kind: 'cmp', field, op: operators_1.Op.in, value: val });
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
nodes.push({ kind: 'cmp', field, op: operators_1.Op.eq, value: val });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (nodes.length === 0)
|
|
65
|
+
return { kind: 'true' };
|
|
66
|
+
if (nodes.length === 1)
|
|
67
|
+
return nodes[0];
|
|
68
|
+
return { kind: 'and', nodes };
|
|
69
|
+
}
|
|
70
|
+
function asArray(v) {
|
|
71
|
+
return (Array.isArray(v) ? v : [v]);
|
|
72
|
+
}
|
|
73
|
+
/** Escape a string for safe inclusion in a regular expression. */
|
|
74
|
+
function escapeRegex(s) {
|
|
75
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Translate a SQL `LIKE`/`ILIKE` pattern into an anchored regular expression
|
|
79
|
+
* (`%` → `.*`, `_` → `.`), so stores that only speak regex can honor ORM
|
|
80
|
+
* `Op.like` queries without the caller hand-writing a pattern.
|
|
81
|
+
*/
|
|
82
|
+
function likeToRegex(pattern, caseInsensitive = false) {
|
|
83
|
+
let out = '';
|
|
84
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
85
|
+
const ch = pattern[i];
|
|
86
|
+
if (ch === '%')
|
|
87
|
+
out += '.*';
|
|
88
|
+
else if (ch === '_')
|
|
89
|
+
out += '.';
|
|
90
|
+
else
|
|
91
|
+
out += escapeRegex(ch);
|
|
92
|
+
}
|
|
93
|
+
return `${caseInsensitive ? '(?i)' : ''}^${out}$`;
|
|
94
|
+
}
|