ts-prorm-orm 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +83 -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 +711 -0
- package/dist/index.js +19 -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,820 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model class for the ORM
|
|
3
|
+
* Represents a database table with CRUD operations, validations, and hooks
|
|
4
|
+
*
|
|
5
|
+
* Usage examples:
|
|
6
|
+
*
|
|
7
|
+
* // 1. Define methods in model options
|
|
8
|
+
* const User = prorm.define('User', {
|
|
9
|
+
* firstName: Prorm.STRING,
|
|
10
|
+
* lastName: Prorm.STRING,
|
|
11
|
+
* }, {
|
|
12
|
+
* classMethods: {
|
|
13
|
+
* findByEmail: function(email: string) {
|
|
14
|
+
* return this.findOne({ where: { email } });
|
|
15
|
+
* }
|
|
16
|
+
* },
|
|
17
|
+
* instanceMethods: {
|
|
18
|
+
* getFullName: function() {
|
|
19
|
+
* return this.firstName + ' ' + this.lastName;
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // 2. Add methods after model definition
|
|
25
|
+
* User.addMethod('classMethod', 'findByUsername', function(username: string) {
|
|
26
|
+
* return this.findOne({ where: { username } });
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* User.addMethod('instanceMethod', 'getFullName', function() {
|
|
30
|
+
* return this.get('firstName') + ' ' + this.get('lastName');
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Usage:
|
|
34
|
+
* const user = await User.findByEmail('test@example.com');
|
|
35
|
+
* console.log(user.getFullName()); // Instance method call
|
|
36
|
+
* const userByName = await User.findByUsername('john'); // Class method call
|
|
37
|
+
*/
|
|
38
|
+
import { ModelStatic, ModelOptions, AttributeOptions, FindOptions, CreateOptions, UpdateOptions, DestroyOptions, SaveOptions, Transaction, HookHandler, ValidationErrorItem, BulkCreateOptions, CountOptions, UpsertOptions, IncrementDecrementOptions, FindOrCreateOptions, ReloadOptions } from '../types';
|
|
39
|
+
import { Prorm } from '../prorm';
|
|
40
|
+
interface ValidationResult {
|
|
41
|
+
valid: boolean;
|
|
42
|
+
errors: ValidationErrorItem[];
|
|
43
|
+
}
|
|
44
|
+
declare class ModelValidator {
|
|
45
|
+
private validations;
|
|
46
|
+
private modelName;
|
|
47
|
+
constructor(validations: Record<string, any>, modelName: string);
|
|
48
|
+
validate(data: Record<string, any>): ValidationResult;
|
|
49
|
+
private validateField;
|
|
50
|
+
}
|
|
51
|
+
declare class ModelInstance<T = any> {
|
|
52
|
+
isNewRecord: boolean;
|
|
53
|
+
isDirty: boolean;
|
|
54
|
+
primaryKey?: string;
|
|
55
|
+
transaction?: Transaction;
|
|
56
|
+
_previousDataValues: Record<string, any>;
|
|
57
|
+
dataValues: Record<string, any>;
|
|
58
|
+
private model;
|
|
59
|
+
private prorm;
|
|
60
|
+
private _changed;
|
|
61
|
+
private _previousChanged;
|
|
62
|
+
private _includes;
|
|
63
|
+
private _validationErrors;
|
|
64
|
+
private _validationCache;
|
|
65
|
+
private _self;
|
|
66
|
+
constructor(model: ModelStatic<any>, prorm: Prorm, values?: Record<string, any>, options?: {
|
|
67
|
+
isNewRecord?: boolean;
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* Create a Proxy-based instance for backward compatibility
|
|
71
|
+
* Allows accessing fields directly like instance.fieldName
|
|
72
|
+
*/
|
|
73
|
+
private static createProxyInstance;
|
|
74
|
+
private castValuesFromDatabase;
|
|
75
|
+
private castValuesForDatabase;
|
|
76
|
+
private getDefaultValues;
|
|
77
|
+
private updatePrimaryKey;
|
|
78
|
+
/**
|
|
79
|
+
* Get the raw value from the instance's dataValues
|
|
80
|
+
* Returns the value directly from the dataValues object without any processing
|
|
81
|
+
*
|
|
82
|
+
* @param key - The attribute name to retrieve
|
|
83
|
+
* @returns The raw value stored in dataValues, or undefined if not set
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* // Get raw value
|
|
87
|
+
* const email = user.getDataValue('email');
|
|
88
|
+
*/
|
|
89
|
+
getDataValue(key: string): any;
|
|
90
|
+
/**
|
|
91
|
+
* Set a value directly in dataValues, bypassing accessors
|
|
92
|
+
* Sets the value without calling any setters and triggers change tracking
|
|
93
|
+
*
|
|
94
|
+
* @param key - The attribute name to set
|
|
95
|
+
* @param value - The value to set
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* // Set raw value directly
|
|
99
|
+
* user.setDataValue('email', 'new@example.com');
|
|
100
|
+
*/
|
|
101
|
+
setDataValue(key: string, value: any): void;
|
|
102
|
+
/**
|
|
103
|
+
* Get an attribute value with accessor support
|
|
104
|
+
* Handles virtual fields by calling their getter functions
|
|
105
|
+
*
|
|
106
|
+
* @param key - The attribute name to retrieve
|
|
107
|
+
* @returns The attribute value, or undefined if not set
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* // Get attribute value
|
|
111
|
+
* const name = user.get('firstName');
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* // Get virtual field value (calls the virtual getter)
|
|
115
|
+
* const fullName = user.get('fullName');
|
|
116
|
+
*/
|
|
117
|
+
get(key: string): any;
|
|
118
|
+
/**
|
|
119
|
+
* Get a value at a JSON path within a JSON/JSONB column
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* // Get nested value from JSON column
|
|
123
|
+
* user.getJsonPath('settings.theme')
|
|
124
|
+
* // Returns: 'dark'
|
|
125
|
+
*
|
|
126
|
+
* // For data column like: { address: { city: 'NYC' } }
|
|
127
|
+
* user.getJsonPath('data.address.city')
|
|
128
|
+
* // Returns: 'NYC'
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
getJsonPath(path: string): any;
|
|
132
|
+
/**
|
|
133
|
+
* Get the raw value without any processing
|
|
134
|
+
* Returns the value directly from dataValues without virtual getter or JSON parsing
|
|
135
|
+
*
|
|
136
|
+
* @param key - The attribute name to retrieve
|
|
137
|
+
* @returns The raw value from dataValues, or undefined if not set
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* // Get raw value without processing
|
|
141
|
+
* const rawEmail = user.getRaw('email');
|
|
142
|
+
*/
|
|
143
|
+
getRaw(key: string): any;
|
|
144
|
+
/**
|
|
145
|
+
* Set an attribute value with mutator support
|
|
146
|
+
* Handles virtual field setters and auto-parses JSON strings
|
|
147
|
+
*
|
|
148
|
+
* @param key - The attribute name to set
|
|
149
|
+
* @param value - The value to set
|
|
150
|
+
* @returns The instance for chaining
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* // Set a single attribute
|
|
154
|
+
* user.set('email', 'new@example.com');
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* // Chain multiple sets
|
|
158
|
+
* user.set('firstName', 'John').set('lastName', 'Doe');
|
|
159
|
+
*/
|
|
160
|
+
set(key: string, value: any): ModelInstance<T>;
|
|
161
|
+
/**
|
|
162
|
+
* Set multiple attribute values at once
|
|
163
|
+
* Iterates through the provided key-value pairs and sets each attribute
|
|
164
|
+
*
|
|
165
|
+
* @param values - An object containing attribute names and their values
|
|
166
|
+
* @returns The instance for chaining
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* // Set multiple attributes
|
|
170
|
+
* user.setAttributes({
|
|
171
|
+
* firstName: 'John',
|
|
172
|
+
* lastName: 'Doe',
|
|
173
|
+
* email: 'john@example.com'
|
|
174
|
+
* });
|
|
175
|
+
*/
|
|
176
|
+
setAttributes(values: Record<string, any>): ModelInstance<T>;
|
|
177
|
+
/**
|
|
178
|
+
* Check if a field has changed since last save
|
|
179
|
+
* Returns a boolean if key is provided, or array of all changed field names otherwise
|
|
180
|
+
*
|
|
181
|
+
* @param key - Optional attribute name to check specific field
|
|
182
|
+
* @returns True if the field has changed, or array of changed field names if no key provided
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* // Check specific field
|
|
186
|
+
* const hasChanged = user.changed('email');
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* // Get all changed fields
|
|
190
|
+
* const changedFields = user.changed();
|
|
191
|
+
*/
|
|
192
|
+
changed(key?: string): boolean | string[];
|
|
193
|
+
/**
|
|
194
|
+
* Get the previous value of a field before changes
|
|
195
|
+
* Returns the value from before the most recent change, or all previous values if no key provided
|
|
196
|
+
*
|
|
197
|
+
* @param key - Optional attribute name to get previous value
|
|
198
|
+
* @returns The previous value, or an object of all previous values if no key provided
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* // Get previous value of specific field
|
|
202
|
+
* const oldEmail = user.previous('email');
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* // Get all previous values
|
|
206
|
+
* const allPrevious = user.previous();
|
|
207
|
+
*/
|
|
208
|
+
previous(key?: string): any;
|
|
209
|
+
/**
|
|
210
|
+
* Check if a specific field has changed
|
|
211
|
+
* @param key - The field name to check
|
|
212
|
+
* @returns true if the field has changed, false otherwise
|
|
213
|
+
*/
|
|
214
|
+
isChanged(key: string): boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Get the previous value of a specific field (including recent changes)
|
|
217
|
+
* @param key - The field name
|
|
218
|
+
* @returns The previous value or undefined if not changed
|
|
219
|
+
*/
|
|
220
|
+
getPreviousValue(key: string): any;
|
|
221
|
+
/**
|
|
222
|
+
* Get all changed fields with their new and old values
|
|
223
|
+
* @returns Object with changed field names as keys and {previous, current} as values
|
|
224
|
+
*/
|
|
225
|
+
getChangedFields(): Record<string, {
|
|
226
|
+
previous: any;
|
|
227
|
+
current: any;
|
|
228
|
+
}>;
|
|
229
|
+
/**
|
|
230
|
+
* Check if the record has any modifications
|
|
231
|
+
* @returns true if any field has been modified
|
|
232
|
+
*/
|
|
233
|
+
isDirtyRecord(): boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Check if the record or a specific field has changes
|
|
236
|
+
* @param key - Optional field name to check specific field
|
|
237
|
+
* @returns true if the record has any changes, or if the specific field has changed
|
|
238
|
+
*/
|
|
239
|
+
hasChanges(key?: string): boolean;
|
|
240
|
+
/**
|
|
241
|
+
* Validate the instance and return boolean result synchronously
|
|
242
|
+
* Uses caching to improve performance on repeated calls
|
|
243
|
+
* @returns true if validation passes, false if there are errors
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* if (user.isValid()) {
|
|
247
|
+
* console.log('Valid!');
|
|
248
|
+
* }
|
|
249
|
+
*/
|
|
250
|
+
isValid(): boolean;
|
|
251
|
+
/**
|
|
252
|
+
* Get only the changed fields with their new (current) values
|
|
253
|
+
* @returns Object with field names as keys and new values
|
|
254
|
+
*/
|
|
255
|
+
getChanges(): Record<string, any>;
|
|
256
|
+
/**
|
|
257
|
+
* Reset all change tracking (mark as not dirty)
|
|
258
|
+
* Typically called after save
|
|
259
|
+
*/
|
|
260
|
+
resetChangeTracking(): void;
|
|
261
|
+
/**
|
|
262
|
+
* Get a snapshot of the current values
|
|
263
|
+
* @returns Copy of dataValues
|
|
264
|
+
*/
|
|
265
|
+
getSnapshot(): Record<string, any>;
|
|
266
|
+
/**
|
|
267
|
+
* Restore values from a snapshot
|
|
268
|
+
* @param snapshot - The snapshot to restore from
|
|
269
|
+
*/
|
|
270
|
+
restoreFromSnapshot(snapshot: Record<string, any>): void;
|
|
271
|
+
/**
|
|
272
|
+
* Get the diff between current and previous values
|
|
273
|
+
* @returns Object with all differences
|
|
274
|
+
*/
|
|
275
|
+
getDiff(): Record<string, {
|
|
276
|
+
from: any;
|
|
277
|
+
to: any;
|
|
278
|
+
}>;
|
|
279
|
+
/**
|
|
280
|
+
* Reset all changes and restore original values
|
|
281
|
+
* @returns void
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* user.name = 'New Name';
|
|
285
|
+
* user.reset(); // Reverts to original values
|
|
286
|
+
*/
|
|
287
|
+
reset(): void;
|
|
288
|
+
getInclude(alias: string): ModelInstance[] | undefined;
|
|
289
|
+
setInclude(alias: string, instances: ModelInstance[]): void;
|
|
290
|
+
toJSON(options?: {
|
|
291
|
+
includeAll?: boolean;
|
|
292
|
+
exclude?: string[];
|
|
293
|
+
include?: string[];
|
|
294
|
+
/** Only include these specific attributes */
|
|
295
|
+
attributes?: string[];
|
|
296
|
+
/** When true, bypass all transformations (no virtual fields, no hidden filtering) */
|
|
297
|
+
raw?: boolean;
|
|
298
|
+
/** Clone the result before returning (prevents mutation) */
|
|
299
|
+
clone?: boolean;
|
|
300
|
+
/** Handle duplicate column names from joined tables */
|
|
301
|
+
duplicateColumns?: Record<string, string>;
|
|
302
|
+
/** Map of table aliases to their model for resolving duplicate columns */
|
|
303
|
+
includedModels?: Map<string, ModelStatic<any>>;
|
|
304
|
+
}): Record<string, any>;
|
|
305
|
+
private buildJSONResult;
|
|
306
|
+
private getAttributesToInclude;
|
|
307
|
+
private invokeToJSONHook;
|
|
308
|
+
/**
|
|
309
|
+
* Validate the instance
|
|
310
|
+
*
|
|
311
|
+
* @param options - Can be:
|
|
312
|
+
* - undefined or null: validate all fields
|
|
313
|
+
* - string[]: validate specific fields (e.g., ['email', 'name'])
|
|
314
|
+
* - object: { fields?: string[], hooks?: boolean }
|
|
315
|
+
* - fields: specific fields to validate
|
|
316
|
+
* - hooks: whether to run beforeValidate/afterValidate hooks (default: false)
|
|
317
|
+
*
|
|
318
|
+
* @returns Promise<{ valid: boolean, errors: ValidationErrorItem[] }>
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* // Validate all fields
|
|
322
|
+
* const result = await user.validate();
|
|
323
|
+
* if (!result.valid) console.log(result.errors);
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* // Validate specific fields
|
|
327
|
+
* const result = await user.validate(['email', 'name']);
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* // Validate with hooks
|
|
331
|
+
* const result = await user.validate({ hooks: true });
|
|
332
|
+
*/
|
|
333
|
+
validate(options?: string[] | {
|
|
334
|
+
fields?: string[];
|
|
335
|
+
hooks?: boolean;
|
|
336
|
+
}): Promise<{
|
|
337
|
+
valid: boolean;
|
|
338
|
+
errors: ValidationErrorItem[];
|
|
339
|
+
}>;
|
|
340
|
+
/**
|
|
341
|
+
* Validate synchronously
|
|
342
|
+
*
|
|
343
|
+
* @param options - Optional field names to validate or options object
|
|
344
|
+
* @returns ValidationResult - Object with valid status and errors
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* const result = user.validateSync();
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* // Validate specific fields
|
|
351
|
+
* const result = user.validateSync(['email', 'name']);
|
|
352
|
+
*/
|
|
353
|
+
validateSync(options?: string[] | {
|
|
354
|
+
fields?: string[];
|
|
355
|
+
}): {
|
|
356
|
+
valid: boolean;
|
|
357
|
+
errors: ValidationErrorItem[];
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* Validate a specific field on the instance
|
|
361
|
+
*
|
|
362
|
+
* @param field - The field name to validate
|
|
363
|
+
* @returns ValidationErrorItem[] - Array of validation errors (empty if valid)
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* const errors = user.validateField('email');
|
|
367
|
+
* if (errors.length > 0) console.log(errors[0].message);
|
|
368
|
+
*/
|
|
369
|
+
validateField(field: string): ValidationErrorItem[];
|
|
370
|
+
isValidSync(): boolean;
|
|
371
|
+
getValidationErrors(): Promise<ValidationErrorItem[]>;
|
|
372
|
+
save(options?: SaveOptions): Promise<this>;
|
|
373
|
+
/**
|
|
374
|
+
* Reload the instance from the database.
|
|
375
|
+
* This fetches the current data from the database and updates the instance,
|
|
376
|
+
* overwriting any local changes.
|
|
377
|
+
*
|
|
378
|
+
* @param options - Reload options
|
|
379
|
+
* @returns Promise resolving to this instance
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* const user = await User.findByPk(1);
|
|
383
|
+
* user.name = 'New Name';
|
|
384
|
+
* await user.reload(); // Reloads from DB, overwrites local changes
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* // Reload with specific attributes
|
|
388
|
+
* await user.reload({ attributes: ['id', 'name', 'email'] });
|
|
389
|
+
*/
|
|
390
|
+
reload(options?: ReloadOptions): Promise<this>;
|
|
391
|
+
destroy(options?: DestroyOptions): Promise<void>;
|
|
392
|
+
restore(options?: any): Promise<void>;
|
|
393
|
+
/**
|
|
394
|
+
* Reload the instance from the database.
|
|
395
|
+
* Re-fetches the record using the primary key and updates dataValues with fresh data.
|
|
396
|
+
* Resets all changed fields.
|
|
397
|
+
*
|
|
398
|
+
* @param options - Options for reload
|
|
399
|
+
* @param options.attributes - Optional array of attribute names to reload.
|
|
400
|
+
* If not provided, reloads all attributes.
|
|
401
|
+
* @param options.transaction - Optional transaction to use
|
|
402
|
+
* @param options.logging - Optional custom logging function
|
|
403
|
+
* @param options hooks - Whether to run hooks (default: true)
|
|
404
|
+
*
|
|
405
|
+
* @returns The reloaded instance
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* // Reload only specific attributes
|
|
409
|
+
* await user.reload({ attributes: ['id', 'name'] });
|
|
410
|
+
*/
|
|
411
|
+
/**
|
|
412
|
+
* Increment one or more numeric fields on the instance.
|
|
413
|
+
*
|
|
414
|
+
* @param fields - The field(s) to increment. Can be:
|
|
415
|
+
* - A single field name: 'age'
|
|
416
|
+
* - An array of field names: ['age', 'score']
|
|
417
|
+
* - An object with field names as keys and increment values: { age: 1, score: 5 }
|
|
418
|
+
* @param options - Options including:
|
|
419
|
+
* - by: The amount to increment by (default: 1)
|
|
420
|
+
* - transaction: Transaction to use
|
|
421
|
+
* - logging: Custom logging function
|
|
422
|
+
* - hooks: Whether to run hooks
|
|
423
|
+
*
|
|
424
|
+
* @returns The updated instance
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* // Increment a single field by 1 (default)
|
|
428
|
+
* await user.increment('age');
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* // Increment a field by a specific amount
|
|
432
|
+
* await user.increment('age', { by: 5 });
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* // Increment multiple fields by 1 each
|
|
436
|
+
* await user.increment(['age', 'score']);
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* // Increment multiple fields by different amounts
|
|
440
|
+
* await user.increment({ age: 1, score: 5 });
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* // Increment with transaction
|
|
444
|
+
* await user.increment('balance', { by: 100, transaction });
|
|
445
|
+
*/
|
|
446
|
+
increment(fields: string | string[] | Record<string, number>, options?: IncrementDecrementOptions): Promise<this>;
|
|
447
|
+
/**
|
|
448
|
+
* Decrement one or more numeric fields on the instance.
|
|
449
|
+
*
|
|
450
|
+
* @param fields - The field(s) to decrement. Can be:
|
|
451
|
+
* - A single field name: 'age'
|
|
452
|
+
* - An array of field names: ['age', 'score']
|
|
453
|
+
* - An object with field names as keys and decrement values: { age: 1, score: 5 }
|
|
454
|
+
* @param options - Options including:
|
|
455
|
+
* - by: The amount to decrement by (default: 1)
|
|
456
|
+
* - transaction: Transaction to use
|
|
457
|
+
* - logging: Custom logging function
|
|
458
|
+
* - hooks: Whether to run hooks
|
|
459
|
+
*
|
|
460
|
+
* @returns The updated instance
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* // Decrement a single field by 1 (default)
|
|
464
|
+
* await user.decrement('age');
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* // Decrement a field by a specific amount
|
|
468
|
+
* await user.decrement('balance', { by: 100 });
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* // Decrement multiple fields by 1 each
|
|
472
|
+
* await user.decrement(['age', 'score']);
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
* // Decrement multiple fields by different amounts
|
|
476
|
+
* await user.decrement({ age: 1, score: 5 });
|
|
477
|
+
*
|
|
478
|
+
* @example
|
|
479
|
+
* // Decrement with transaction
|
|
480
|
+
* await user.decrement('balance', { by: 50, transaction });
|
|
481
|
+
*/
|
|
482
|
+
decrement(fields: string | string[] | Record<string, number>, options?: IncrementDecrementOptions): Promise<this>;
|
|
483
|
+
/**
|
|
484
|
+
* Internal method to handle increment/decrement operations
|
|
485
|
+
*/
|
|
486
|
+
private _incrementDecrement;
|
|
487
|
+
/**
|
|
488
|
+
* Run a raw query from instance context
|
|
489
|
+
* Uses the model's connection for executing custom queries
|
|
490
|
+
*
|
|
491
|
+
* @param sql - SQL query to execute
|
|
492
|
+
* @param options - Query options including replacements, raw mode, and transaction
|
|
493
|
+
* @returns Query result
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* // Run a raw query on an instance
|
|
497
|
+
* const user = await User.findById(1);
|
|
498
|
+
* const result = await user.$query('SELECT * FROM orders WHERE user_id = ?', {
|
|
499
|
+
* replacements: [user.id]
|
|
500
|
+
* });
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* // Run raw query with model mapping
|
|
504
|
+
* const orders = await user.$query('SELECT * FROM orders WHERE user_id = ?', {
|
|
505
|
+
* replacements: [user.id],
|
|
506
|
+
* model: Order
|
|
507
|
+
* });
|
|
508
|
+
*/
|
|
509
|
+
$query(sql: string, options?: {
|
|
510
|
+
replacements?: Record<string, unknown> | unknown[];
|
|
511
|
+
raw?: boolean;
|
|
512
|
+
model?: ModelStatic<any>;
|
|
513
|
+
transaction?: Transaction;
|
|
514
|
+
}): Promise<any>;
|
|
515
|
+
private runHook;
|
|
516
|
+
/**
|
|
517
|
+
* Get a related instance for a hasOne or belongsTo association
|
|
518
|
+
*
|
|
519
|
+
* @param associationName - The name of the association (e.g., 'profile', 'address')
|
|
520
|
+
* @param options - Find options to pass to the query
|
|
521
|
+
* @returns The associated instance or null
|
|
522
|
+
*
|
|
523
|
+
* @example
|
|
524
|
+
* const profile = await user.getRelated('profile');
|
|
525
|
+
* const address = await user.getRelated('address', { where: { active: true } });
|
|
526
|
+
*/
|
|
527
|
+
getRelated(associationName: string, options?: FindOptions): Promise<ModelInstance<any> | null>;
|
|
528
|
+
/**
|
|
529
|
+
* Set a related instance for a hasOne or belongsTo association
|
|
530
|
+
*
|
|
531
|
+
* @param associationName - The name of the association (e.g., 'profile', 'address')
|
|
532
|
+
* @param value - The instance to set, null to remove association, or a foreign key value
|
|
533
|
+
* @param options - Options including save: false to skip saving
|
|
534
|
+
* @returns The updated instance
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* await user.setRelated('profile', newProfile);
|
|
538
|
+
* await user.setRelated('address', null); // Remove association
|
|
539
|
+
* await user.setRelated('address', 5); // Set by foreign key value
|
|
540
|
+
*/
|
|
541
|
+
setRelated(associationName: string, value: ModelInstance<any> | null | number | string, options?: {
|
|
542
|
+
save?: boolean;
|
|
543
|
+
}): Promise<this>;
|
|
544
|
+
/**
|
|
545
|
+
* Create and associate a new related instance
|
|
546
|
+
*
|
|
547
|
+
* @param associationName - The name of the association (e.g., 'profile', 'address')
|
|
548
|
+
* @param values - The values to create the new instance with
|
|
549
|
+
* @param options - Create options
|
|
550
|
+
* @returns The created associated instance
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* const profile = await user.createRelated('profile', { bio: 'Hello world' });
|
|
554
|
+
* const address = await user.createRelated('address', { city: 'NYC', country: 'USA' });
|
|
555
|
+
*/
|
|
556
|
+
createRelated(associationName: string, values?: Record<string, any>, options?: CreateOptions): Promise<ModelInstance<any>>;
|
|
557
|
+
/**
|
|
558
|
+
* Check if an associated instance exists
|
|
559
|
+
*
|
|
560
|
+
* @param associationName - The name of the association (e.g., 'profile', 'address')
|
|
561
|
+
* @param options - Count options
|
|
562
|
+
* @returns True if associated record exists
|
|
563
|
+
*
|
|
564
|
+
* @example
|
|
565
|
+
* const hasProfile = await user.hasRelated('profile');
|
|
566
|
+
* const hasAddress = await user.hasRelated('address');
|
|
567
|
+
*/
|
|
568
|
+
hasRelated(associationName: string, options?: FindOptions): Promise<boolean>;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Create a Model class for a given table
|
|
572
|
+
*/
|
|
573
|
+
export declare function createModel<T extends Record<string, any>>(prorm: Prorm, modelName: string, attributes: Record<string, AttributeOptions>, options?: ModelOptions): ModelStatic<any>;
|
|
574
|
+
/**
|
|
575
|
+
* Base Model class for decorator-based model definitions
|
|
576
|
+
*
|
|
577
|
+
* This class can be extended to create models using TypeScript decorators:
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* ```typescript
|
|
581
|
+
* import { Model, DataTypes } from 'orm';
|
|
582
|
+
* import { Table, Attribute, PrimaryKey, AutoIncrement } from 'orm/decorators';
|
|
583
|
+
*
|
|
584
|
+
* @Table({ tableName: 'users' })
|
|
585
|
+
* export class User extends Model {
|
|
586
|
+
* @Attribute(DataTypes.INTEGER)
|
|
587
|
+
* @PrimaryKey
|
|
588
|
+
* @AutoIncrement
|
|
589
|
+
* declare id: number;
|
|
590
|
+
*
|
|
591
|
+
* @Attribute(DataTypes.STRING)
|
|
592
|
+
* declare name: string;
|
|
593
|
+
* }
|
|
594
|
+
*
|
|
595
|
+
* // Then initialize with prorm:
|
|
596
|
+
* prorm.addModel(User);
|
|
597
|
+
* await User.sync();
|
|
598
|
+
* ```
|
|
599
|
+
*/
|
|
600
|
+
declare class ModelClass {
|
|
601
|
+
static prorm?: Prorm;
|
|
602
|
+
static modelName?: string;
|
|
603
|
+
static tableName?: string;
|
|
604
|
+
static schema?: string;
|
|
605
|
+
static rawAttributes?: Record<string, any>;
|
|
606
|
+
static associations?: Record<string, any>;
|
|
607
|
+
static options?: ModelOptions;
|
|
608
|
+
static primaryKeyAttribute?: string;
|
|
609
|
+
static _scopes?: Record<string, any>;
|
|
610
|
+
/**
|
|
611
|
+
* Associations declared via User.hasMany(...)/.belongsTo(...)/etc before the model
|
|
612
|
+
* has been registered with prorm.addModel(). Queued here and replayed by
|
|
613
|
+
* Prorm.addModel() once the model (and its prorm/models[name] entry) exists, so
|
|
614
|
+
* association calls can be made either before or after addModel().
|
|
615
|
+
*/
|
|
616
|
+
static _pendingAssociations?: Array<{
|
|
617
|
+
type: 'hasOne' | 'hasMany' | 'belongsTo' | 'belongsToMany';
|
|
618
|
+
target: any;
|
|
619
|
+
options?: any;
|
|
620
|
+
}>;
|
|
621
|
+
private static _queuePendingAssociation;
|
|
622
|
+
/**
|
|
623
|
+
* Scopes added via User.addScope(...) before the model has been registered with
|
|
624
|
+
* prorm.addModel(). Merged into the model's options.scopes by Prorm.addModel() so
|
|
625
|
+
* addScope() can be called either before or after addModel().
|
|
626
|
+
*/
|
|
627
|
+
static _pendingScopes?: Record<string, any>;
|
|
628
|
+
static addScope(scopeName: string, scopeDef: any): void;
|
|
629
|
+
static hasMany(target: any, options?: any): any;
|
|
630
|
+
static belongsTo(target: any, options?: any): any;
|
|
631
|
+
static hasOne(target: any, options?: any): any;
|
|
632
|
+
static belongsToMany(target: any, options?: any): any;
|
|
633
|
+
static getAttributes(): string[];
|
|
634
|
+
static getTableName(): string;
|
|
635
|
+
static getPrimaryKeyAttribute(): string | undefined;
|
|
636
|
+
static findOne(findOptions?: FindOptions): Promise<ModelInstance | null>;
|
|
637
|
+
static findAll(findOptions?: FindOptions): Promise<ModelInstance[]>;
|
|
638
|
+
static findByPk(id: number | string, options?: FindOptions): Promise<ModelInstance | null>;
|
|
639
|
+
static findOrCreate(options: FindOrCreateOptions): Promise<[ModelInstance, boolean]>;
|
|
640
|
+
static findOrBuild(options: FindOrCreateOptions): Promise<[ModelInstance, boolean]>;
|
|
641
|
+
static findOrInitialize(options: FindOrCreateOptions): Promise<[ModelInstance, boolean]>;
|
|
642
|
+
/**
|
|
643
|
+
* Get the model attribute name for a database column (static version)
|
|
644
|
+
* @param columnName - The database column name
|
|
645
|
+
* @returns The model attribute name (or the column name if no mapping exists)
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
* User.getAttributeName('first_name'); // 'firstName' if field: 'first_name' is set
|
|
649
|
+
* User.getAttributeName('id'); // 'id'
|
|
650
|
+
*/
|
|
651
|
+
static getAttributeName(columnName: string): string;
|
|
652
|
+
static build(values?: Record<string, any>, options?: Record<string, any>): ModelInstance;
|
|
653
|
+
static create(values?: Record<string, any>, options?: CreateOptions): Promise<any>;
|
|
654
|
+
static update(values: Record<string, any>, options: UpdateOptions): Promise<[number, any]>;
|
|
655
|
+
static destroy(options: DestroyOptions): Promise<number>;
|
|
656
|
+
static count(options?: CountOptions): Promise<number>;
|
|
657
|
+
static bulkCreate(records: Record<string, any>[], options?: BulkCreateOptions): Promise<ModelInstance[]>;
|
|
658
|
+
static upsert(values: Record<string, any>, options?: UpsertOptions): Promise<[ModelInstance, boolean]>;
|
|
659
|
+
static hook(hookName: string, handler: HookHandler): typeof ModelClass;
|
|
660
|
+
static addHook(hookName: string, handler: HookHandler): typeof ModelClass;
|
|
661
|
+
static beforeCreate(handler: HookHandler): typeof ModelClass;
|
|
662
|
+
static afterCreate(handler: HookHandler): typeof ModelClass;
|
|
663
|
+
static beforeUpdate(handler: HookHandler): typeof ModelClass;
|
|
664
|
+
static afterUpdate(handler: HookHandler): typeof ModelClass;
|
|
665
|
+
static beforeDestroy(handler: HookHandler): typeof ModelClass;
|
|
666
|
+
static afterDestroy(handler: HookHandler): typeof ModelClass;
|
|
667
|
+
/**
|
|
668
|
+
* Check if a hook is registered on the model
|
|
669
|
+
* @param hookName - The name of the hook (e.g., 'beforeCreate', 'afterSave')
|
|
670
|
+
* @returns True if the hook is registered, false otherwise
|
|
671
|
+
*/
|
|
672
|
+
static hasHook(hookName: string): boolean;
|
|
673
|
+
/**
|
|
674
|
+
* Check if a hook is registered on the model (alias for hasHook)
|
|
675
|
+
* @param hookName - The name of the hook (e.g., 'beforeCreate', 'afterSave')
|
|
676
|
+
* @returns True if the hook is registered, false otherwise
|
|
677
|
+
*/
|
|
678
|
+
static hasHooks(hookName: string): boolean;
|
|
679
|
+
/**
|
|
680
|
+
* Remove a hook from the model
|
|
681
|
+
* @param hookName - The name of the hook (e.g., 'beforeCreate', 'afterSave')
|
|
682
|
+
* @param hookOrHookId - Optional: The specific hook callback function OR hook ID to remove. If not provided, removes all hooks of this type
|
|
683
|
+
* @returns The model for chaining
|
|
684
|
+
*/
|
|
685
|
+
static removeHook(hookName: string, hookOrHookId?: string | HookHandler): typeof ModelClass;
|
|
686
|
+
}
|
|
687
|
+
export { ModelClass as Model, ModelInstance, ModelValidator };
|
|
688
|
+
export type { ValidationResult };
|
|
689
|
+
declare const _default: {
|
|
690
|
+
createModel: typeof createModel;
|
|
691
|
+
ModelClass: typeof ModelClass;
|
|
692
|
+
Op: {
|
|
693
|
+
readonly and: symbol;
|
|
694
|
+
readonly or: symbol;
|
|
695
|
+
readonly not: symbol;
|
|
696
|
+
readonly eq: symbol;
|
|
697
|
+
readonly is: symbol;
|
|
698
|
+
readonly ne: symbol;
|
|
699
|
+
readonly gt: symbol;
|
|
700
|
+
readonly gte: symbol;
|
|
701
|
+
readonly lt: symbol;
|
|
702
|
+
readonly lte: symbol;
|
|
703
|
+
readonly like: symbol;
|
|
704
|
+
readonly notLike: symbol;
|
|
705
|
+
readonly iLike: symbol;
|
|
706
|
+
readonly notILike: symbol;
|
|
707
|
+
readonly startsWith: symbol;
|
|
708
|
+
readonly notStartsWith: symbol;
|
|
709
|
+
readonly endsWith: symbol;
|
|
710
|
+
readonly notEndsWith: symbol;
|
|
711
|
+
readonly substring: symbol;
|
|
712
|
+
readonly notSubstring: symbol;
|
|
713
|
+
readonly col: symbol;
|
|
714
|
+
readonly in: symbol;
|
|
715
|
+
readonly notIn: symbol;
|
|
716
|
+
readonly between: symbol;
|
|
717
|
+
readonly notBetween: symbol;
|
|
718
|
+
readonly isNull: symbol;
|
|
719
|
+
readonly isNotNull: symbol;
|
|
720
|
+
readonly exists: symbol;
|
|
721
|
+
readonly notExists: symbol;
|
|
722
|
+
readonly regexp: symbol;
|
|
723
|
+
readonly notRegexp: symbol;
|
|
724
|
+
readonly iRegexp: symbol;
|
|
725
|
+
readonly notIRegexp: symbol;
|
|
726
|
+
readonly any: symbol;
|
|
727
|
+
readonly all: symbol;
|
|
728
|
+
readonly containsKey: symbol;
|
|
729
|
+
readonly containsKeyPath: symbol;
|
|
730
|
+
readonly containsPath: symbol;
|
|
731
|
+
readonly strictLeft: symbol;
|
|
732
|
+
readonly strictRight: symbol;
|
|
733
|
+
readonly noExtendRight: symbol;
|
|
734
|
+
readonly noExtendLeft: symbol;
|
|
735
|
+
readonly adj: symbol;
|
|
736
|
+
readonly notAdj: symbol;
|
|
737
|
+
readonly arrayContains: symbol;
|
|
738
|
+
readonly arrayContainedBy: symbol;
|
|
739
|
+
readonly arrayOverlaps: symbol;
|
|
740
|
+
readonly arrayAny: symbol;
|
|
741
|
+
readonly arrayAll: symbol;
|
|
742
|
+
readonly contains: symbol;
|
|
743
|
+
readonly containedBy: symbol;
|
|
744
|
+
readonly keyExists: symbol;
|
|
745
|
+
readonly overlap: symbol;
|
|
746
|
+
readonly match: symbol;
|
|
747
|
+
readonly $json: symbol;
|
|
748
|
+
readonly jsonPath: symbol;
|
|
749
|
+
readonly jsonContains: symbol;
|
|
750
|
+
readonly jsonHasKey: symbol;
|
|
751
|
+
readonly jsonbExtract: symbol;
|
|
752
|
+
readonly jsonbExtractText: symbol;
|
|
753
|
+
readonly jsonbExtractPath: symbol;
|
|
754
|
+
readonly jsonbExtractPathText: symbol;
|
|
755
|
+
readonly jsonConcat: symbol;
|
|
756
|
+
readonly jsonDelete: symbol;
|
|
757
|
+
readonly jsonDeletePath: symbol;
|
|
758
|
+
readonly jsonPathExists: symbol;
|
|
759
|
+
readonly jsonPathQuery: symbol;
|
|
760
|
+
readonly jsonTypeOf: symbol;
|
|
761
|
+
readonly json: (path: string) => symbol;
|
|
762
|
+
readonly key: (pathOrOptions: string | {
|
|
763
|
+
path: string;
|
|
764
|
+
value?: any;
|
|
765
|
+
}) => Record<string, any>;
|
|
766
|
+
readonly literal: (value: string) => import("..").LiteralValue;
|
|
767
|
+
readonly cast: (value: any, type: string) => import("./operators").CastExpression;
|
|
768
|
+
readonly extract: (field: any, part: import("..").ExtractPart) => import("./operators").ExtractExpression;
|
|
769
|
+
readonly conv: (value: any, from: string | null | undefined, to: string) => import("./operators").ConvExpression;
|
|
770
|
+
readonly where: (column: {
|
|
771
|
+
$col: string;
|
|
772
|
+
} | string, operator: any, value?: any) => {
|
|
773
|
+
$where: {
|
|
774
|
+
$col: string;
|
|
775
|
+
[key: string]: any;
|
|
776
|
+
};
|
|
777
|
+
} | Record<string, any>;
|
|
778
|
+
readonly asc: (field: string) => import("./operators").OrderExpression;
|
|
779
|
+
readonly desc: (field: string) => import("./operators").OrderExpression;
|
|
780
|
+
readonly random: () => import("./operators").OrderExpression;
|
|
781
|
+
readonly isNotNullPredicate: (value: any) => boolean;
|
|
782
|
+
readonly matchAgainst: (columns: string | string[], options?: {
|
|
783
|
+
mode?: "natural" | "boolean";
|
|
784
|
+
}) => {
|
|
785
|
+
$match: {
|
|
786
|
+
columns: string[];
|
|
787
|
+
mode: "natural" | "boolean";
|
|
788
|
+
};
|
|
789
|
+
};
|
|
790
|
+
readonly matchFulltext: (columns: string | string[]) => {
|
|
791
|
+
$match: {
|
|
792
|
+
columns: string[];
|
|
793
|
+
mode: "natural";
|
|
794
|
+
};
|
|
795
|
+
};
|
|
796
|
+
readonly toTsvector: (column: string, config?: string) => {
|
|
797
|
+
$tsvector: {
|
|
798
|
+
column: string;
|
|
799
|
+
config: string;
|
|
800
|
+
};
|
|
801
|
+
};
|
|
802
|
+
readonly toTsquery: (query: string, config?: string) => {
|
|
803
|
+
$tsquery: {
|
|
804
|
+
query: string;
|
|
805
|
+
config: string;
|
|
806
|
+
};
|
|
807
|
+
};
|
|
808
|
+
readonly stDistance: symbol;
|
|
809
|
+
readonly stWithin: symbol;
|
|
810
|
+
readonly stContains: symbol;
|
|
811
|
+
readonly stIntersects: symbol;
|
|
812
|
+
readonly stDWithin: symbol;
|
|
813
|
+
readonly stCrosses: symbol;
|
|
814
|
+
readonly stOverlaps: symbol;
|
|
815
|
+
readonly stTouches: symbol;
|
|
816
|
+
readonly stEquals: symbol;
|
|
817
|
+
readonly stIsValid: symbol;
|
|
818
|
+
};
|
|
819
|
+
};
|
|
820
|
+
export default _default;
|