ts-prorm-orm 1.1.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.
Files changed (310) hide show
  1. package/CHANGELOG.md +1111 -0
  2. package/LICENSE +21 -0
  3. package/README.md +573 -0
  4. package/dist/audit/history-query.js +180 -0
  5. package/dist/audit/index.js +23 -0
  6. package/dist/audit/logger.js +236 -0
  7. package/dist/cache/cache-manager.js +84 -0
  8. package/dist/cache/index.js +16 -0
  9. package/dist/cache/redis-cluster-cache.js +557 -0
  10. package/dist/cli.js +2200 -0
  11. package/dist/compliance/audit-trail.js +68 -0
  12. package/dist/compliance/backup-verification.js +685 -0
  13. package/dist/compliance/breach-detector.js +505 -0
  14. package/dist/compliance/consent-record.js +227 -0
  15. package/dist/compliance/consent-versioning.js +331 -0
  16. package/dist/compliance/cross-border-log.js +530 -0
  17. package/dist/compliance/data-classifier.js +258 -0
  18. package/dist/compliance/data-lineage.js +565 -0
  19. package/dist/compliance/data-masker.js +303 -0
  20. package/dist/compliance/data-portability.js +265 -0
  21. package/dist/compliance/data-retention.js +195 -0
  22. package/dist/compliance/dsar-workflow.js +342 -0
  23. package/dist/compliance/field-encryption.js +223 -0
  24. package/dist/compliance/immutable-record.js +148 -0
  25. package/dist/compliance/index.js +260 -0
  26. package/dist/compliance/privacy-impact-assessment.js +364 -0
  27. package/dist/compliance/pseudonymization.js +269 -0
  28. package/dist/compliance/query-firewall.js +1182 -0
  29. package/dist/compliance/rate-limiter.js +580 -0
  30. package/dist/compliance/right-to-erasure.js +117 -0
  31. package/dist/compliance/row-level-security.js +246 -0
  32. package/dist/compliance/security-decorator.js +574 -0
  33. package/dist/compliance/security-monitor.js +525 -0
  34. package/dist/compliance/sensitive-data-discovery.js +476 -0
  35. package/dist/compliance/session-isolation.js +472 -0
  36. package/dist/compliance/tls-enforcer.js +108 -0
  37. package/dist/compliance/worm-storage.js +712 -0
  38. package/dist/connection-manager.js +198 -0
  39. package/dist/connection-pool.js +519 -0
  40. package/dist/decorators/audit.js +136 -0
  41. package/dist/decorators/belongs-to-many.js +115 -0
  42. package/dist/decorators/belongs-to.js +115 -0
  43. package/dist/decorators/check.js +435 -0
  44. package/dist/decorators/collate.js +329 -0
  45. package/dist/decorators/comment.js +205 -0
  46. package/dist/decorators/database-settings.js +236 -0
  47. package/dist/decorators/default.js +244 -0
  48. package/dist/decorators/encryption.js +235 -0
  49. package/dist/decorators/engine.js +97 -0
  50. package/dist/decorators/fk-constraints.js +594 -0
  51. package/dist/decorators/foreign-table.js +136 -0
  52. package/dist/decorators/generated.js +274 -0
  53. package/dist/decorators/has-many.js +127 -0
  54. package/dist/decorators/has-one.js +116 -0
  55. package/dist/decorators/hstore.js +129 -0
  56. package/dist/decorators/index.js +355 -0
  57. package/dist/decorators/json-column.js +83 -0
  58. package/dist/decorators/jsonb.js +101 -0
  59. package/dist/decorators/orm-decorators.js +425 -0
  60. package/dist/decorators/permissions.js +294 -0
  61. package/dist/decorators/procedure.js +210 -0
  62. package/dist/decorators/query-options.js +556 -0
  63. package/dist/decorators/range.js +167 -0
  64. package/dist/decorators/set-column.js +83 -0
  65. package/dist/decorators/spatial.js +114 -0
  66. package/dist/decorators/storage.js +580 -0
  67. package/dist/decorators/timezone.js +512 -0
  68. package/dist/decorators/trigger.js +90 -0
  69. package/dist/decorators/uuid.js +135 -0
  70. package/dist/decorators/view.js +258 -0
  71. package/dist/diagrams/chen-diagram.js +354 -0
  72. package/dist/diagrams/class-diagram.js +384 -0
  73. package/dist/diagrams/dependency-diagram.js +432 -0
  74. package/dist/diagrams/er-diagram.js +605 -0
  75. package/dist/diagrams/flow-diagram.js +394 -0
  76. package/dist/diagrams/gantt-diagram.js +411 -0
  77. package/dist/diagrams/index-diagram.js +353 -0
  78. package/dist/diagrams/index.js +184 -0
  79. package/dist/diagrams/migration-diagram.js +316 -0
  80. package/dist/diagrams/model-diagram.js +616 -0
  81. package/dist/diagrams/package-diagram.js +376 -0
  82. package/dist/diagrams/palette.js +85 -0
  83. package/dist/diagrams/relational-diagram.js +455 -0
  84. package/dist/diagrams/schemadoc-diagram.js +309 -0
  85. package/dist/diagrams/sequence-diagram.js +307 -0
  86. package/dist/diagrams/state-diagram.js +344 -0
  87. package/dist/diagrams/svg-dom.js +111 -0
  88. package/dist/diagrams/tree-diagram.js +250 -0
  89. package/dist/dialects/clickhouse/index.js +1742 -0
  90. package/dist/dialects/cockroachdb/index.js +4677 -0
  91. package/dist/dialects/cratedb/index.js +441 -0
  92. package/dist/dialects/databricks/index.js +517 -0
  93. package/dist/dialects/db2/index.js +2225 -0
  94. package/dist/dialects/dialect.js +720 -0
  95. package/dist/dialects/duckdb/index.js +2014 -0
  96. package/dist/dialects/exasol/index.js +357 -0
  97. package/dist/dialects/firebird/index.js +495 -0
  98. package/dist/dialects/greenplum/index.js +457 -0
  99. package/dist/dialects/hana/index.js +1741 -0
  100. package/dist/dialects/mariadb/index.js +3590 -0
  101. package/dist/dialects/mssql/index.js +2296 -0
  102. package/dist/dialects/mysql/index.js +4058 -0
  103. package/dist/dialects/oracle/index.js +2999 -0
  104. package/dist/dialects/postgres/index.js +5319 -0
  105. package/dist/dialects/query-stream-helper.js +152 -0
  106. package/dist/dialects/questdb/index.js +433 -0
  107. package/dist/dialects/redshift/index.js +2277 -0
  108. package/dist/dialects/singlestore/index.js +354 -0
  109. package/dist/dialects/snowflake/index.js +2082 -0
  110. package/dist/dialects/spanner/index.js +1768 -0
  111. package/dist/dialects/sqlite/index.js +3382 -0
  112. package/dist/dialects/tidb/index.js +377 -0
  113. package/dist/dialects/timescaledb/index.js +164 -0
  114. package/dist/dialects/trino/index.js +420 -0
  115. package/dist/dialects/turso/index.js +227 -0
  116. package/dist/dialects/vertica/index.js +317 -0
  117. package/dist/dialects/yugabytedb/index.js +424 -0
  118. package/dist/errors/index.js +472 -0
  119. package/dist/errors/utils.js +340 -0
  120. package/dist/errors.js +21 -0
  121. package/dist/extensions/catalog/cloud-warehouse-features.js +207 -0
  122. package/dist/extensions/catalog/mssql-features.js +147 -0
  123. package/dist/extensions/catalog/mysql-mariadb-plugins.js +229 -0
  124. package/dist/extensions/catalog/oracle-db2-features.js +196 -0
  125. package/dist/extensions/catalog/postgres-extensions.js +516 -0
  126. package/dist/extensions/index.js +71 -0
  127. package/dist/extensions/types.js +13 -0
  128. package/dist/foreign-data.js +173 -0
  129. package/dist/hooks/hooks-manager.js +350 -0
  130. package/dist/hooks/index.js +37 -0
  131. package/dist/index.js +463 -0
  132. package/dist/logging.js +335 -0
  133. package/dist/migrations/index.js +40 -0
  134. package/dist/migrations/migration.js +196 -0
  135. package/dist/migrations/migrator.js +411 -0
  136. package/dist/migrations/prormmigration.js +275 -0
  137. package/dist/migrations/query-interface.js +435 -0
  138. package/dist/migrations/seeder.js +353 -0
  139. package/dist/models/associations.js +852 -0
  140. package/dist/models/constraints.js +288 -0
  141. package/dist/models/data-types.js +2518 -0
  142. package/dist/models/decorators.js +445 -0
  143. package/dist/models/index.js +33 -0
  144. package/dist/models/indexes.js +531 -0
  145. package/dist/models/methods.js +382 -0
  146. package/dist/models/model-manager.js +103 -0
  147. package/dist/models/model.js +5349 -0
  148. package/dist/models/operators.js +67 -0
  149. package/dist/models/scopes.js +189 -0
  150. package/dist/models/typescript-types.js +26 -0
  151. package/dist/nosql/aerospike/index.js +205 -0
  152. package/dist/nosql/allegrograph/index.js +169 -0
  153. package/dist/nosql/arangodb/index.js +364 -0
  154. package/dist/nosql/azure-blob/index.js +206 -0
  155. package/dist/nosql/beanstalkd/index.js +231 -0
  156. package/dist/nosql/beequeue/index.js +210 -0
  157. package/dist/nosql/bigchaindb/index.js +195 -0
  158. package/dist/nosql/bigtable/index.js +224 -0
  159. package/dist/nosql/blazegraph/index.js +173 -0
  160. package/dist/nosql/bullmq/index.js +191 -0
  161. package/dist/nosql/cassandra/index.js +174 -0
  162. package/dist/nosql/chroma/index.js +190 -0
  163. package/dist/nosql/cloudflare-kv/index.js +220 -0
  164. package/dist/nosql/coherence/index.js +200 -0
  165. package/dist/nosql/cosmosdb/index.js +157 -0
  166. package/dist/nosql/couchbase/index.js +213 -0
  167. package/dist/nosql/dax/index.js +212 -0
  168. package/dist/nosql/deno-kv/index.js +206 -0
  169. package/dist/nosql/dgraph/index.js +171 -0
  170. package/dist/nosql/doris/index.js +169 -0
  171. package/dist/nosql/druid/index.js +162 -0
  172. package/dist/nosql/dynamodb/index.js +937 -0
  173. package/dist/nosql/elasticsearch/index.js +377 -0
  174. package/dist/nosql/etcd/index.js +502 -0
  175. package/dist/nosql/eventhubs/index.js +213 -0
  176. package/dist/nosql/eventstore/index.js +254 -0
  177. package/dist/nosql/faunadb/index.js +188 -0
  178. package/dist/nosql/firestore/index.js +177 -0
  179. package/dist/nosql/fluree/index.js +148 -0
  180. package/dist/nosql/fuseki/index.js +170 -0
  181. package/dist/nosql/gcs/index.js +172 -0
  182. package/dist/nosql/gearman/index.js +160 -0
  183. package/dist/nosql/geode/index.js +196 -0
  184. package/dist/nosql/graphdb/index.js +169 -0
  185. package/dist/nosql/graylog/index.js +188 -0
  186. package/dist/nosql/gridgain/index.js +171 -0
  187. package/dist/nosql/hazelcast/index.js +162 -0
  188. package/dist/nosql/hbase/index.js +230 -0
  189. package/dist/nosql/ignite/index.js +173 -0
  190. package/dist/nosql/immudb/index.js +184 -0
  191. package/dist/nosql/index.js +232 -0
  192. package/dist/nosql/infinispan/index.js +200 -0
  193. package/dist/nosql/influxdb/index.js +0 -0
  194. package/dist/nosql/kafka/index.js +234 -0
  195. package/dist/nosql/keyspaces/index.js +189 -0
  196. package/dist/nosql/kinesis/index.js +253 -0
  197. package/dist/nosql/leveldb/index.js +153 -0
  198. package/dist/nosql/lmdb/index.js +160 -0
  199. package/dist/nosql/loki/index.js +201 -0
  200. package/dist/nosql/marklogic/index.js +204 -0
  201. package/dist/nosql/materialize/index.js +145 -0
  202. package/dist/nosql/meilisearch/index.js +154 -0
  203. package/dist/nosql/memcached/index.js +223 -0
  204. package/dist/nosql/milvus/index.js +410 -0
  205. package/dist/nosql/minio/index.js +265 -0
  206. package/dist/nosql/momento/index.js +179 -0
  207. package/dist/nosql/mongodb/index.js +461 -0
  208. package/dist/nosql/nats/index.js +247 -0
  209. package/dist/nosql/nedb/index.js +164 -0
  210. package/dist/nosql/neo4j/index.js +450 -0
  211. package/dist/nosql/neptune/index.js +470 -0
  212. package/dist/nosql/nsq/index.js +200 -0
  213. package/dist/nosql/opensearch/index.js +186 -0
  214. package/dist/nosql/orientdb/index.js +175 -0
  215. package/dist/nosql/papertrail/index.js +200 -0
  216. package/dist/nosql/pinecone/index.js +0 -0
  217. package/dist/nosql/pinot/index.js +133 -0
  218. package/dist/nosql/pouchdb/index.js +172 -0
  219. package/dist/nosql/prometheus/index.js +174 -0
  220. package/dist/nosql/provendb/index.js +147 -0
  221. package/dist/nosql/pubsub/index.js +187 -0
  222. package/dist/nosql/pulsar/index.js +232 -0
  223. package/dist/nosql/qdrant/index.js +295 -0
  224. package/dist/nosql/qldb/index.js +192 -0
  225. package/dist/nosql/r2/index.js +281 -0
  226. package/dist/nosql/rabbitmq/index.js +237 -0
  227. package/dist/nosql/ravendb/index.js +175 -0
  228. package/dist/nosql/redis/index.js +607 -0
  229. package/dist/nosql/redpanda/index.js +237 -0
  230. package/dist/nosql/resque/index.js +203 -0
  231. package/dist/nosql/rethinkdb/index.js +232 -0
  232. package/dist/nosql/rocksdb/index.js +152 -0
  233. package/dist/nosql/rockset/index.js +126 -0
  234. package/dist/nosql/s3/index.js +298 -0
  235. package/dist/nosql/scylladb/index.js +178 -0
  236. package/dist/nosql/signoz/index.js +227 -0
  237. package/dist/nosql/sns/index.js +201 -0
  238. package/dist/nosql/solr/index.js +231 -0
  239. package/dist/nosql/splunk/index.js +227 -0
  240. package/dist/nosql/sqs/index.js +246 -0
  241. package/dist/nosql/stardog/index.js +169 -0
  242. package/dist/nosql/starrocks/index.js +170 -0
  243. package/dist/nosql/store.js +2 -0
  244. package/dist/nosql/sumologic/index.js +213 -0
  245. package/dist/nosql/surrealdb/index.js +179 -0
  246. package/dist/nosql/terminusdb/index.js +151 -0
  247. package/dist/nosql/tigergraph/index.js +469 -0
  248. package/dist/nosql/typesense/index.js +148 -0
  249. package/dist/nosql/unqlite/index.js +157 -0
  250. package/dist/nosql/upstash/index.js +167 -0
  251. package/dist/nosql/vercel-kv/index.js +166 -0
  252. package/dist/nosql/victoriametrics/index.js +213 -0
  253. package/dist/nosql/virtuoso/index.js +169 -0
  254. package/dist/nosql/weaviate/index.js +276 -0
  255. package/dist/operators/index.js +108 -0
  256. package/dist/operators.js +2690 -0
  257. package/dist/prisma-migrate/index.js +38 -0
  258. package/dist/prisma-migrate/migration-generator.js +125 -0
  259. package/dist/prisma-migrate/model-generator.js +172 -0
  260. package/dist/prisma-migrate/relations.js +100 -0
  261. package/dist/prisma-migrate/schema-parser.js +167 -0
  262. package/dist/prisma-migrate/type-mapper.js +40 -0
  263. package/dist/prorm.js +6832 -0
  264. package/dist/query-builders/cte-builder.js +80 -0
  265. package/dist/query-builders/functions/aggregate.js +390 -0
  266. package/dist/query-builders/functions/conditional.js +503 -0
  267. package/dist/query-builders/functions/datetime.js +695 -0
  268. package/dist/query-builders/functions/fulltext.js +439 -0
  269. package/dist/query-builders/functions/index.js +93 -0
  270. package/dist/query-builders/functions/json.js +427 -0
  271. package/dist/query-builders/functions/math.js +399 -0
  272. package/dist/query-builders/functions/string.js +518 -0
  273. package/dist/query-builders/functions/window.js +328 -0
  274. package/dist/query-builders/include-builder.js +323 -0
  275. package/dist/query-builders/index-expression-builder.js +242 -0
  276. package/dist/query-builders/index.js +161 -0
  277. package/dist/query-builders/insert-builder.js +164 -0
  278. package/dist/query-builders/model-helpers.js +38 -0
  279. package/dist/query-builders/order-limit-builder.js +239 -0
  280. package/dist/query-builders/sql-compiler.js +2040 -0
  281. package/dist/query-builders/subquery-builder.js +152 -0
  282. package/dist/query-builders/update-builder.js +182 -0
  283. package/dist/query-builders/view-builder.js +218 -0
  284. package/dist/query-builders/where-builder.js +1532 -0
  285. package/dist/query-interface.js +622 -0
  286. package/dist/query-optimizers/batch-optimizer.js +426 -0
  287. package/dist/query-optimizers/explain-plans.js +415 -0
  288. package/dist/query-optimizers/index.js +51 -0
  289. package/dist/query-optimizers/prepared-statement-cache.js +423 -0
  290. package/dist/query-optimizers/query-hints.js +438 -0
  291. package/dist/query-optimizers/query-optimizer.js +278 -0
  292. package/dist/query-optimizers/slow-query-logger.js +271 -0
  293. package/dist/replica-manager.js +507 -0
  294. package/dist/schema/index.js +15 -0
  295. package/dist/schema/migration-generator.js +374 -0
  296. package/dist/schema/schema-differ.js +549 -0
  297. package/dist/schema/types.js +6 -0
  298. package/dist/sql-constants.js +300 -0
  299. package/dist/sqlite-advanced.js +1047 -0
  300. package/dist/streams/index.js +12 -0
  301. package/dist/streams/transforms.js +178 -0
  302. package/dist/transaction.js +456 -0
  303. package/dist/types/index.js +180 -0
  304. package/dist/user-management.js +127 -0
  305. package/dist/utils/date.js +300 -0
  306. package/dist/utils/index.js +1079 -0
  307. package/dist/utils/string.js +161 -0
  308. package/dist/validators/index.js +19 -0
  309. package/dist/validators/validator.js +911 -0
  310. package/package.json +190 -0
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ /**
3
+ * Memcached store implementation.
4
+ *
5
+ * Memcached is a distributed in-memory key-value cache. It has no query
6
+ * language, no secondary indexes and no persistence, so it does not fit the
7
+ * SQL-shaped `Dialect` interface. This class implements the minimal
8
+ * `NoSqlStore` marker interface and exposes Memcached's real operations
9
+ * (set/get/delete/add/replace/increment/decrement/flush) as a typed,
10
+ * promise-based API instead of forcing them into a `query(sql)` shape.
11
+ *
12
+ * Uses the `memjs` driver. The driver is loaded lazily inside `connect()`
13
+ * (or supplied pre-built via the `client` option) so importing this module
14
+ * never requires `memjs` to be installed unless a Memcached store is
15
+ * actually connected.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.MemcachedStore = void 0;
19
+ const errors_1 = require("../../errors");
20
+ function wrapConnectionError(err, host) {
21
+ const parent = err instanceof Error ? err : new Error(String(err));
22
+ const message = /econnrefused/i.test(parent.message)
23
+ ? 'Connection refused'
24
+ : `Unable to connect to Memcached: ${parent.message}`;
25
+ return new errors_1.ConnectionError(message, { parent, database: 'memcached', host });
26
+ }
27
+ function wrapDatabaseError(err, action) {
28
+ const parent = err instanceof Error ? err : new Error(String(err));
29
+ return errors_1.DatabaseError.from(parent, { message: `Memcached ${action} failed: ${parent.message}` });
30
+ }
31
+ /**
32
+ * Serialize a value for storage. Strings and Buffers are stored verbatim;
33
+ * everything else (numbers, booleans, objects, arrays) is JSON-encoded so
34
+ * it round-trips through `get(key, { decode: 'json' })`.
35
+ */
36
+ function serialize(value) {
37
+ if (typeof value === 'string' || Buffer.isBuffer(value)) {
38
+ return value;
39
+ }
40
+ return JSON.stringify(value);
41
+ }
42
+ /**
43
+ * `MemcachedStore` wraps a `memjs` client and exposes Memcached's key-value
44
+ * operations as a typed, promise-based API.
45
+ */
46
+ class MemcachedStore {
47
+ constructor(options = {}) {
48
+ this.name = 'memcached';
49
+ this.library = 'memjs';
50
+ this.client = null;
51
+ this.connected = false;
52
+ this.options = options;
53
+ }
54
+ // ---------------------------------------------------------------------
55
+ // Connection lifecycle
56
+ // ---------------------------------------------------------------------
57
+ async connect() {
58
+ if (this.connected && this.client) {
59
+ return;
60
+ }
61
+ try {
62
+ if (this.options.client) {
63
+ // A pre-built client was injected - use it as-is and skip the
64
+ // lazy require entirely (tests inject a mock this way).
65
+ this.client = this.options.client;
66
+ }
67
+ else {
68
+ // Lazily load memjs so importing this module never requires the
69
+ // driver unless a store is actually connected.
70
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
71
+ const memjs = require('memjs');
72
+ this.client = memjs.Client.create(this.options.servers, this.options.options);
73
+ }
74
+ this.connected = true;
75
+ }
76
+ catch (err) {
77
+ this.client = null;
78
+ this.connected = false;
79
+ throw wrapConnectionError(err, this.options.servers);
80
+ }
81
+ }
82
+ async disconnect() {
83
+ if (this.client) {
84
+ if (typeof this.client.close === 'function') {
85
+ this.client.close();
86
+ }
87
+ else if (typeof this.client.quit === 'function') {
88
+ this.client.quit();
89
+ }
90
+ this.client = null;
91
+ }
92
+ this.connected = false;
93
+ }
94
+ /** Alias for `disconnect()`, mirroring memjs's own `quit()`/`close()` naming. */
95
+ async quit() {
96
+ return this.disconnect();
97
+ }
98
+ isConnected() {
99
+ return this.connected && this.client !== null;
100
+ }
101
+ /** Returns the underlying `memjs` client for anything not wrapped here. */
102
+ getClient() {
103
+ return this.requireClient();
104
+ }
105
+ requireClient() {
106
+ if (!this.client) {
107
+ throw new errors_1.ConnectionError('Not connected to Memcached', { database: 'memcached' });
108
+ }
109
+ return this.client;
110
+ }
111
+ // ---------------------------------------------------------------------
112
+ // Key-value operations
113
+ // ---------------------------------------------------------------------
114
+ /**
115
+ * Store `value` under `key`, overwriting any existing value. Strings and
116
+ * Buffers are stored verbatim; other values are JSON-serialized (see
117
+ * `serialize`). Returns memjs's boolean success flag.
118
+ */
119
+ async set(key, value, options) {
120
+ const client = this.requireClient();
121
+ try {
122
+ return await client.set(key, serialize(value), options);
123
+ }
124
+ catch (err) {
125
+ throw wrapDatabaseError(err, 'SET');
126
+ }
127
+ }
128
+ /**
129
+ * Read `key`. Returns `null` if the key is missing. By default returns the
130
+ * raw `Buffer`; pass `{ decode: 'string' }` or `{ decode: 'json' }` to
131
+ * decode the stored value.
132
+ */
133
+ async get(key, options = {}) {
134
+ const client = this.requireClient();
135
+ try {
136
+ const result = await client.get(key);
137
+ const value = result ? result.value : null;
138
+ if (value === null || value === undefined) {
139
+ return null;
140
+ }
141
+ switch (options.decode) {
142
+ case 'string':
143
+ return value.toString('utf8');
144
+ case 'json':
145
+ return JSON.parse(value.toString('utf8'));
146
+ case 'buffer':
147
+ default:
148
+ return value;
149
+ }
150
+ }
151
+ catch (err) {
152
+ throw wrapDatabaseError(err, 'GET');
153
+ }
154
+ }
155
+ /** Delete `key`. Returns memjs's boolean success flag. */
156
+ async delete(key) {
157
+ const client = this.requireClient();
158
+ try {
159
+ return await client.delete(key);
160
+ }
161
+ catch (err) {
162
+ throw wrapDatabaseError(err, 'DELETE');
163
+ }
164
+ }
165
+ /**
166
+ * Store `value` under `key` only if the key does not already exist
167
+ * (Memcached `add`). Returns `false` if the key was already present.
168
+ */
169
+ async add(key, value, options) {
170
+ const client = this.requireClient();
171
+ try {
172
+ return await client.add(key, serialize(value), options);
173
+ }
174
+ catch (err) {
175
+ throw wrapDatabaseError(err, 'ADD');
176
+ }
177
+ }
178
+ /**
179
+ * Store `value` under `key` only if the key already exists (Memcached
180
+ * `replace`). Returns `false` if the key was missing.
181
+ */
182
+ async replace(key, value, options) {
183
+ const client = this.requireClient();
184
+ try {
185
+ return await client.replace(key, serialize(value), options);
186
+ }
187
+ catch (err) {
188
+ throw wrapDatabaseError(err, 'REPLACE');
189
+ }
190
+ }
191
+ /** Atomically increment the numeric value at `key` by `amount`. */
192
+ async increment(key, amount, options) {
193
+ const client = this.requireClient();
194
+ try {
195
+ return await client.increment(key, amount, options);
196
+ }
197
+ catch (err) {
198
+ throw wrapDatabaseError(err, 'INCREMENT');
199
+ }
200
+ }
201
+ /** Atomically decrement the numeric value at `key` by `amount`. */
202
+ async decrement(key, amount, options) {
203
+ const client = this.requireClient();
204
+ try {
205
+ return await client.decrement(key, amount, options);
206
+ }
207
+ catch (err) {
208
+ throw wrapDatabaseError(err, 'DECREMENT');
209
+ }
210
+ }
211
+ /** Flush (delete) all keys across every configured server. */
212
+ async flush() {
213
+ const client = this.requireClient();
214
+ try {
215
+ return await client.flush();
216
+ }
217
+ catch (err) {
218
+ throw wrapDatabaseError(err, 'FLUSH');
219
+ }
220
+ }
221
+ }
222
+ exports.MemcachedStore = MemcachedStore;
223
+ exports.default = MemcachedStore;
@@ -0,0 +1,410 @@
1
+ "use strict";
2
+ /**
3
+ * Milvus store implementation.
4
+ *
5
+ * Milvus is a vector database: collections are defined by a field schema
6
+ * (a primary key, one or more vector fields with a fixed dimension, and
7
+ * optional scalar fields) rather than rows of arbitrary SQL types, queries
8
+ * are approximate-nearest-neighbor searches (or scalar filter expressions)
9
+ * rather than `SELECT ... WHERE`, and there is no join/transaction-log
10
+ * concept. None of that fits the SQL-shaped `Dialect` interface, so this
11
+ * class implements the minimal `NoSqlStore` marker interface
12
+ * (`src/nosql/store.ts`) and exposes Milvus's real operations (collection
13
+ * management, index management, insert/upsert, vector search, scalar
14
+ * query, delete, and partitions) grouped the way the underlying SDK groups
15
+ * them, instead of forcing everything into a `query(sql)` shape.
16
+ *
17
+ * Uses the official `@zilliz/milvus2-sdk-node` gRPC client.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.MilvusStore = void 0;
21
+ const milvus2_sdk_node_1 = require("@zilliz/milvus2-sdk-node");
22
+ const errors_1 = require("../../errors");
23
+ function isSuccess(errorCode) {
24
+ return errorCode === undefined || errorCode === milvus2_sdk_node_1.ErrorCode.SUCCESS || errorCode === 0;
25
+ }
26
+ function checkStatus(status, action) {
27
+ if (!status)
28
+ return;
29
+ if (!isSuccess(status.error_code)) {
30
+ throw new errors_1.DatabaseError(`Milvus ${action} failed: ${status.reason || status.error_code}`, {
31
+ original: status.reason,
32
+ });
33
+ }
34
+ }
35
+ function wrapConnectionError(err, address) {
36
+ const parent = err instanceof Error ? err : new Error(String(err));
37
+ const message = /econnrefused/i.test(parent.message)
38
+ ? 'Connection refused'
39
+ : `Unable to connect to Milvus: ${parent.message}`;
40
+ return new errors_1.ConnectionError(message, { parent, database: 'milvus', host: address });
41
+ }
42
+ function wrapDatabaseError(err, message) {
43
+ if (err instanceof errors_1.DatabaseError) {
44
+ return err;
45
+ }
46
+ const parent = err instanceof Error ? err : new Error(String(err));
47
+ const combined = message ? `${message}: ${parent.message}` : parent.message;
48
+ return errors_1.DatabaseError.from(parent, { message: combined });
49
+ }
50
+ /** Convert an `IndexDescription` (the raw wire shape) to the friendlier `MilvusIndexInfo`. */
51
+ function toIndexInfo(desc) {
52
+ const params = Object.fromEntries((desc.params || []).map((p) => [p.key, p.value]));
53
+ return {
54
+ indexName: desc.index_name,
55
+ fieldName: desc.field_name,
56
+ indexType: params.index_type,
57
+ metricType: params.metric_type,
58
+ state: desc.state,
59
+ indexedRows: desc.indexed_rows,
60
+ totalRows: desc.total_rows,
61
+ };
62
+ }
63
+ /**
64
+ * `MilvusStore` wraps `@zilliz/milvus2-sdk-node`'s `MilvusClient` and exposes
65
+ * Milvus's collection/index/data/partition operations as a typed,
66
+ * promise-based API.
67
+ */
68
+ class MilvusStore {
69
+ constructor(options) {
70
+ this.name = 'milvus';
71
+ this.library = '@zilliz/milvus2-sdk-node';
72
+ this.client = null;
73
+ this.connected = false;
74
+ this.options = options;
75
+ }
76
+ // ---------------------------------------------------------------------
77
+ // Connection lifecycle
78
+ // ---------------------------------------------------------------------
79
+ async connect() {
80
+ if (this.connected && this.client) {
81
+ return;
82
+ }
83
+ try {
84
+ const client = new milvus2_sdk_node_1.MilvusClient(this.options);
85
+ const health = await client.checkHealth();
86
+ if (!health.isHealthy) {
87
+ throw new Error('Milvus server reported unhealthy');
88
+ }
89
+ this.client = client;
90
+ this.connected = true;
91
+ }
92
+ catch (err) {
93
+ this.client = null;
94
+ this.connected = false;
95
+ throw wrapConnectionError(err, this.options.address);
96
+ }
97
+ }
98
+ async disconnect() {
99
+ if (this.client) {
100
+ try {
101
+ await this.client.closeConnection();
102
+ }
103
+ catch {
104
+ // ignore - we're tearing down anyway
105
+ }
106
+ this.client = null;
107
+ }
108
+ this.connected = false;
109
+ }
110
+ isConnected() {
111
+ return this.connected && this.client !== null;
112
+ }
113
+ /** Returns the underlying `MilvusClient` for anything not wrapped here. */
114
+ getClient() {
115
+ return this.requireClient();
116
+ }
117
+ requireClient() {
118
+ if (!this.client) {
119
+ throw new errors_1.ConnectionError('Not connected to Milvus', { database: 'milvus' });
120
+ }
121
+ return this.client;
122
+ }
123
+ async exec(fn, action) {
124
+ const client = this.requireClient();
125
+ try {
126
+ return await fn(client);
127
+ }
128
+ catch (err) {
129
+ throw wrapDatabaseError(err, `Milvus ${action} failed`);
130
+ }
131
+ }
132
+ // ---------------------------------------------------------------------
133
+ // Collection management
134
+ // ---------------------------------------------------------------------
135
+ /** Create a collection with an explicit field schema (primary key + one or more vector fields + optional scalars). */
136
+ async createCollection(collectionName, fields, options = {}) {
137
+ return this.exec(async (c) => {
138
+ const req = {
139
+ collection_name: collectionName,
140
+ description: options.description,
141
+ shards_num: options.shardsNum,
142
+ consistency_level: options.consistencyLevel,
143
+ enable_dynamic_field: options.enableDynamicField,
144
+ fields: fields.map((f) => ({
145
+ name: f.name,
146
+ data_type: f.data_type,
147
+ is_primary_key: f.is_primary_key,
148
+ autoID: f.autoID,
149
+ is_partition_key: f.is_partition_key,
150
+ description: f.description,
151
+ type_params: {
152
+ ...(f.dim !== undefined ? { dim: f.dim } : {}),
153
+ ...(f.max_length !== undefined ? { max_length: f.max_length } : {}),
154
+ },
155
+ })),
156
+ };
157
+ const status = await c.createCollection(req);
158
+ checkStatus(status, `createCollection(${collectionName})`);
159
+ }, 'createCollection');
160
+ }
161
+ async dropCollection(collectionName) {
162
+ return this.exec(async (c) => {
163
+ const req = { collection_name: collectionName };
164
+ const status = await c.dropCollection(req);
165
+ checkStatus(status, `dropCollection(${collectionName})`);
166
+ }, 'dropCollection');
167
+ }
168
+ async hasCollection(collectionName) {
169
+ return this.exec(async (c) => {
170
+ const res = await c.hasCollection({ collection_name: collectionName });
171
+ checkStatus(res.status, `hasCollection(${collectionName})`);
172
+ return Boolean(res.value);
173
+ }, 'hasCollection');
174
+ }
175
+ async describeCollection(collectionName) {
176
+ return this.exec(async (c) => {
177
+ const res = await c.describeCollection({ collection_name: collectionName });
178
+ checkStatus(res.status, `describeCollection(${collectionName})`);
179
+ return res;
180
+ }, 'describeCollection');
181
+ }
182
+ /** List all collections. */
183
+ async listCollections() {
184
+ return this.exec(async (c) => {
185
+ const res = await c.showCollections();
186
+ checkStatus(res.status, 'listCollections');
187
+ return res.data;
188
+ }, 'listCollections');
189
+ }
190
+ /** Load a collection's data into query nodes' memory so it can be searched/queried. */
191
+ async loadCollection(collectionName, replicaNumber) {
192
+ return this.exec(async (c) => {
193
+ const req = { collection_name: collectionName, replica_number: replicaNumber };
194
+ const status = await c.loadCollection(req);
195
+ checkStatus(status, `loadCollection(${collectionName})`);
196
+ }, 'loadCollection');
197
+ }
198
+ /** Release a collection's data from memory (it remains persisted; reload with `loadCollection()` to search it again). */
199
+ async releaseCollection(collectionName) {
200
+ return this.exec(async (c) => {
201
+ const req = { collection_name: collectionName };
202
+ const status = await c.releaseCollection(req);
203
+ checkStatus(status, `releaseCollection(${collectionName})`);
204
+ }, 'releaseCollection');
205
+ }
206
+ async getCollectionStatistics(collectionName) {
207
+ return this.exec(async (c) => {
208
+ const res = await c.getCollectionStatistics({ collection_name: collectionName });
209
+ checkStatus(res.status, `getCollectionStatistics(${collectionName})`);
210
+ return res.data;
211
+ }, 'getCollectionStatistics');
212
+ }
213
+ // ---------------------------------------------------------------------
214
+ // Index management
215
+ // ---------------------------------------------------------------------
216
+ async createIndex(collectionName, options) {
217
+ return this.exec(async (c) => {
218
+ const req = {
219
+ collection_name: collectionName,
220
+ field_name: options.fieldName,
221
+ index_type: options.indexType,
222
+ metric_type: options.metricType,
223
+ index_name: options.indexName,
224
+ params: options.params,
225
+ };
226
+ const status = await c.createIndex(req);
227
+ checkStatus(status, `createIndex(${collectionName}.${options.fieldName})`);
228
+ }, 'createIndex');
229
+ }
230
+ async dropIndex(collectionName, fieldName, indexName) {
231
+ return this.exec(async (c) => {
232
+ const status = await c.dropIndex({ collection_name: collectionName, field_name: fieldName, index_name: indexName });
233
+ checkStatus(status, `dropIndex(${collectionName})`);
234
+ }, 'dropIndex');
235
+ }
236
+ async describeIndex(collectionName, fieldName) {
237
+ return this.exec(async (c) => {
238
+ const res = await c.describeIndex({ collection_name: collectionName, field_name: fieldName });
239
+ checkStatus(res.status, `describeIndex(${collectionName})`);
240
+ return res.index_descriptions.map(toIndexInfo);
241
+ }, 'describeIndex');
242
+ }
243
+ async listIndexes(collectionName) {
244
+ return this.exec(async (c) => {
245
+ const res = await c.listIndexes({ collection_name: collectionName });
246
+ checkStatus(res.status, `listIndexes(${collectionName})`);
247
+ return res.indexes;
248
+ }, 'listIndexes');
249
+ }
250
+ // ---------------------------------------------------------------------
251
+ // Data: insert / upsert
252
+ // ---------------------------------------------------------------------
253
+ async insert(collectionName, rows, options = {}) {
254
+ return this.exec(async (c) => {
255
+ const res = await c.insert({ collection_name: collectionName, data: rows, partition_name: options.partitionName });
256
+ checkStatus(res.status, `insert(${collectionName})`);
257
+ return res;
258
+ }, 'insert');
259
+ }
260
+ async upsert(collectionName, rows, options = {}) {
261
+ return this.exec(async (c) => {
262
+ const res = await c.upsert({ collection_name: collectionName, data: rows, partition_name: options.partitionName });
263
+ checkStatus(res.status, `upsert(${collectionName})`);
264
+ return res;
265
+ }, 'upsert');
266
+ }
267
+ // ---------------------------------------------------------------------
268
+ // Vector search
269
+ // ---------------------------------------------------------------------
270
+ /**
271
+ * Approximate-nearest-neighbor search against a vector field. Ranks by
272
+ * the collection's index metric (`L2`/`IP`/`COSINE`/...), optionally
273
+ * narrowed by a scalar `filter` expression evaluated alongside the
274
+ * vector comparison.
275
+ */
276
+ async search(collectionName, options) {
277
+ return this.exec(async (c) => {
278
+ const req = {
279
+ collection_name: collectionName,
280
+ data: options.vector,
281
+ anns_field: options.annsField,
282
+ limit: options.limit ?? 10,
283
+ filter: options.filter,
284
+ output_fields: options.outputFields,
285
+ partition_names: options.partitionNames,
286
+ metric_type: options.metricType,
287
+ offset: options.offset,
288
+ };
289
+ const res = await c.search(req);
290
+ checkStatus(res.status, `search(${collectionName})`);
291
+ const hits = res.results;
292
+ return hits.map((hit) => ({ ...hit, id: hit.id, score: hit.score }));
293
+ }, 'search');
294
+ }
295
+ // ---------------------------------------------------------------------
296
+ // Scalar query
297
+ // ---------------------------------------------------------------------
298
+ /** Scalar-only lookup (no vector similarity) via a filter expression and/or primary key list. */
299
+ async query(collectionName, options = {}) {
300
+ return this.exec(async (c) => {
301
+ const req = {
302
+ collection_name: collectionName,
303
+ filter: options.filter,
304
+ ids: options.ids,
305
+ output_fields: options.outputFields,
306
+ partition_names: options.partitionNames,
307
+ limit: options.limit,
308
+ offset: options.offset,
309
+ };
310
+ const res = await c.query(req);
311
+ checkStatus(res.status, `query(${collectionName})`);
312
+ return res.data;
313
+ }, 'query');
314
+ }
315
+ /** Fetch specific rows by primary key. Equivalent to `query()` with `ids` set, using Milvus's dedicated `Get` RPC. */
316
+ async get(collectionName, ids, outputFields) {
317
+ return this.exec(async (c) => {
318
+ const res = await c.get({
319
+ collection_name: collectionName,
320
+ ids: ids,
321
+ output_fields: outputFields,
322
+ });
323
+ checkStatus(res.status, `get(${collectionName})`);
324
+ return res.data;
325
+ }, 'get');
326
+ }
327
+ /** Count rows matching an optional filter expression (all rows if omitted). */
328
+ async count(collectionName, filter) {
329
+ return this.exec(async (c) => {
330
+ const res = await c.count({ collection_name: collectionName, expr: filter });
331
+ checkStatus(res.status, `count(${collectionName})`);
332
+ return res.data;
333
+ }, 'count');
334
+ }
335
+ // ---------------------------------------------------------------------
336
+ // Delete
337
+ // ---------------------------------------------------------------------
338
+ async deleteByIds(collectionName, ids, partitionName) {
339
+ return this.exec(async (c) => {
340
+ const res = await c.delete({
341
+ collection_name: collectionName,
342
+ ids: ids,
343
+ partition_name: partitionName,
344
+ });
345
+ checkStatus(res.status, `delete(${collectionName})`);
346
+ return res;
347
+ }, 'delete');
348
+ }
349
+ async deleteByFilter(collectionName, filter, partitionName) {
350
+ return this.exec(async (c) => {
351
+ const res = await c.delete({ collection_name: collectionName, filter, partition_name: partitionName });
352
+ checkStatus(res.status, `delete(${collectionName})`);
353
+ return res;
354
+ }, 'delete');
355
+ }
356
+ // ---------------------------------------------------------------------
357
+ // Partitions
358
+ // ---------------------------------------------------------------------
359
+ async createPartition(collectionName, partitionName) {
360
+ return this.exec(async (c) => {
361
+ const status = await c.createPartition({ collection_name: collectionName, partition_name: partitionName });
362
+ checkStatus(status, `createPartition(${collectionName}.${partitionName})`);
363
+ }, 'createPartition');
364
+ }
365
+ async dropPartition(collectionName, partitionName) {
366
+ return this.exec(async (c) => {
367
+ const status = await c.dropPartition({ collection_name: collectionName, partition_name: partitionName });
368
+ checkStatus(status, `dropPartition(${collectionName}.${partitionName})`);
369
+ }, 'dropPartition');
370
+ }
371
+ async hasPartition(collectionName, partitionName) {
372
+ return this.exec(async (c) => {
373
+ const res = await c.hasPartition({ collection_name: collectionName, partition_name: partitionName });
374
+ checkStatus(res.status, `hasPartition(${collectionName}.${partitionName})`);
375
+ return Boolean(res.value);
376
+ }, 'hasPartition');
377
+ }
378
+ async listPartitions(collectionName) {
379
+ return this.exec(async (c) => {
380
+ const res = await c.listPartitions({ collection_name: collectionName });
381
+ checkStatus(res.status, `listPartitions(${collectionName})`);
382
+ return res.partition_names;
383
+ }, 'listPartitions');
384
+ }
385
+ async loadPartitions(collectionName, partitionNames, replicaNumber) {
386
+ return this.exec(async (c) => {
387
+ const status = await c.loadPartitions({
388
+ collection_name: collectionName,
389
+ partition_names: partitionNames,
390
+ replica_number: replicaNumber,
391
+ });
392
+ checkStatus(status, `loadPartitions(${collectionName})`);
393
+ }, 'loadPartitions');
394
+ }
395
+ async releasePartitions(collectionName, partitionNames) {
396
+ return this.exec(async (c) => {
397
+ const status = await c.releasePartitions({ collection_name: collectionName, partition_names: partitionNames });
398
+ checkStatus(status, `releasePartitions(${collectionName})`);
399
+ }, 'releasePartitions');
400
+ }
401
+ async getPartitionStatistics(collectionName, partitionName) {
402
+ return this.exec(async (c) => {
403
+ const res = await c.getPartitionStatistics({ collection_name: collectionName, partition_name: partitionName });
404
+ checkStatus(res.status, `getPartitionStatistics(${collectionName}.${partitionName})`);
405
+ return res.data;
406
+ }, 'getPartitionStatistics');
407
+ }
408
+ }
409
+ exports.MilvusStore = MilvusStore;
410
+ exports.default = MilvusStore;