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.
- package/CHANGELOG.md +1111 -0
- package/LICENSE +21 -0
- package/README.md +573 -0
- package/dist/audit/history-query.js +180 -0
- package/dist/audit/index.js +23 -0
- package/dist/audit/logger.js +236 -0
- package/dist/cache/cache-manager.js +84 -0
- package/dist/cache/index.js +16 -0
- package/dist/cache/redis-cluster-cache.js +557 -0
- package/dist/cli.js +2200 -0
- package/dist/compliance/audit-trail.js +68 -0
- package/dist/compliance/backup-verification.js +685 -0
- package/dist/compliance/breach-detector.js +505 -0
- package/dist/compliance/consent-record.js +227 -0
- package/dist/compliance/consent-versioning.js +331 -0
- package/dist/compliance/cross-border-log.js +530 -0
- package/dist/compliance/data-classifier.js +258 -0
- package/dist/compliance/data-lineage.js +565 -0
- package/dist/compliance/data-masker.js +303 -0
- package/dist/compliance/data-portability.js +265 -0
- package/dist/compliance/data-retention.js +195 -0
- package/dist/compliance/dsar-workflow.js +342 -0
- package/dist/compliance/field-encryption.js +223 -0
- package/dist/compliance/immutable-record.js +148 -0
- package/dist/compliance/index.js +260 -0
- package/dist/compliance/privacy-impact-assessment.js +364 -0
- package/dist/compliance/pseudonymization.js +269 -0
- package/dist/compliance/query-firewall.js +1182 -0
- package/dist/compliance/rate-limiter.js +580 -0
- package/dist/compliance/right-to-erasure.js +117 -0
- package/dist/compliance/row-level-security.js +246 -0
- package/dist/compliance/security-decorator.js +574 -0
- package/dist/compliance/security-monitor.js +525 -0
- package/dist/compliance/sensitive-data-discovery.js +476 -0
- package/dist/compliance/session-isolation.js +472 -0
- package/dist/compliance/tls-enforcer.js +108 -0
- package/dist/compliance/worm-storage.js +712 -0
- package/dist/connection-manager.js +198 -0
- package/dist/connection-pool.js +519 -0
- package/dist/decorators/audit.js +136 -0
- package/dist/decorators/belongs-to-many.js +115 -0
- package/dist/decorators/belongs-to.js +115 -0
- package/dist/decorators/check.js +435 -0
- package/dist/decorators/collate.js +329 -0
- package/dist/decorators/comment.js +205 -0
- package/dist/decorators/database-settings.js +236 -0
- package/dist/decorators/default.js +244 -0
- package/dist/decorators/encryption.js +235 -0
- package/dist/decorators/engine.js +97 -0
- package/dist/decorators/fk-constraints.js +594 -0
- package/dist/decorators/foreign-table.js +136 -0
- package/dist/decorators/generated.js +274 -0
- package/dist/decorators/has-many.js +127 -0
- package/dist/decorators/has-one.js +116 -0
- package/dist/decorators/hstore.js +129 -0
- package/dist/decorators/index.js +355 -0
- package/dist/decorators/json-column.js +83 -0
- package/dist/decorators/jsonb.js +101 -0
- package/dist/decorators/orm-decorators.js +425 -0
- package/dist/decorators/permissions.js +294 -0
- package/dist/decorators/procedure.js +210 -0
- package/dist/decorators/query-options.js +556 -0
- package/dist/decorators/range.js +167 -0
- package/dist/decorators/set-column.js +83 -0
- package/dist/decorators/spatial.js +114 -0
- package/dist/decorators/storage.js +580 -0
- package/dist/decorators/timezone.js +512 -0
- package/dist/decorators/trigger.js +90 -0
- package/dist/decorators/uuid.js +135 -0
- package/dist/decorators/view.js +258 -0
- package/dist/diagrams/chen-diagram.js +354 -0
- package/dist/diagrams/class-diagram.js +384 -0
- package/dist/diagrams/dependency-diagram.js +432 -0
- package/dist/diagrams/er-diagram.js +605 -0
- package/dist/diagrams/flow-diagram.js +394 -0
- package/dist/diagrams/gantt-diagram.js +411 -0
- package/dist/diagrams/index-diagram.js +353 -0
- package/dist/diagrams/index.js +184 -0
- package/dist/diagrams/migration-diagram.js +316 -0
- package/dist/diagrams/model-diagram.js +616 -0
- package/dist/diagrams/package-diagram.js +376 -0
- package/dist/diagrams/palette.js +85 -0
- package/dist/diagrams/relational-diagram.js +455 -0
- package/dist/diagrams/schemadoc-diagram.js +309 -0
- package/dist/diagrams/sequence-diagram.js +307 -0
- package/dist/diagrams/state-diagram.js +344 -0
- package/dist/diagrams/svg-dom.js +111 -0
- package/dist/diagrams/tree-diagram.js +250 -0
- package/dist/dialects/clickhouse/index.js +1742 -0
- package/dist/dialects/cockroachdb/index.js +4677 -0
- package/dist/dialects/cratedb/index.js +441 -0
- package/dist/dialects/databricks/index.js +517 -0
- package/dist/dialects/db2/index.js +2225 -0
- package/dist/dialects/dialect.js +720 -0
- package/dist/dialects/duckdb/index.js +2014 -0
- package/dist/dialects/exasol/index.js +357 -0
- package/dist/dialects/firebird/index.js +495 -0
- package/dist/dialects/greenplum/index.js +457 -0
- package/dist/dialects/hana/index.js +1741 -0
- package/dist/dialects/mariadb/index.js +3590 -0
- package/dist/dialects/mssql/index.js +2296 -0
- package/dist/dialects/mysql/index.js +4058 -0
- package/dist/dialects/oracle/index.js +2999 -0
- package/dist/dialects/postgres/index.js +5319 -0
- package/dist/dialects/query-stream-helper.js +152 -0
- package/dist/dialects/questdb/index.js +433 -0
- package/dist/dialects/redshift/index.js +2277 -0
- package/dist/dialects/singlestore/index.js +354 -0
- package/dist/dialects/snowflake/index.js +2082 -0
- package/dist/dialects/spanner/index.js +1768 -0
- package/dist/dialects/sqlite/index.js +3382 -0
- package/dist/dialects/tidb/index.js +377 -0
- package/dist/dialects/timescaledb/index.js +164 -0
- package/dist/dialects/trino/index.js +420 -0
- package/dist/dialects/turso/index.js +227 -0
- package/dist/dialects/vertica/index.js +317 -0
- package/dist/dialects/yugabytedb/index.js +424 -0
- package/dist/errors/index.js +472 -0
- package/dist/errors/utils.js +340 -0
- package/dist/errors.js +21 -0
- package/dist/extensions/catalog/cloud-warehouse-features.js +207 -0
- package/dist/extensions/catalog/mssql-features.js +147 -0
- package/dist/extensions/catalog/mysql-mariadb-plugins.js +229 -0
- package/dist/extensions/catalog/oracle-db2-features.js +196 -0
- package/dist/extensions/catalog/postgres-extensions.js +516 -0
- package/dist/extensions/index.js +71 -0
- package/dist/extensions/types.js +13 -0
- package/dist/foreign-data.js +173 -0
- package/dist/hooks/hooks-manager.js +350 -0
- package/dist/hooks/index.js +37 -0
- package/dist/index.js +463 -0
- package/dist/logging.js +335 -0
- package/dist/migrations/index.js +40 -0
- package/dist/migrations/migration.js +196 -0
- package/dist/migrations/migrator.js +411 -0
- package/dist/migrations/prormmigration.js +275 -0
- package/dist/migrations/query-interface.js +435 -0
- package/dist/migrations/seeder.js +353 -0
- package/dist/models/associations.js +852 -0
- package/dist/models/constraints.js +288 -0
- package/dist/models/data-types.js +2518 -0
- package/dist/models/decorators.js +445 -0
- package/dist/models/index.js +33 -0
- package/dist/models/indexes.js +531 -0
- package/dist/models/methods.js +382 -0
- package/dist/models/model-manager.js +103 -0
- package/dist/models/model.js +5349 -0
- package/dist/models/operators.js +67 -0
- package/dist/models/scopes.js +189 -0
- package/dist/models/typescript-types.js +26 -0
- package/dist/nosql/aerospike/index.js +205 -0
- package/dist/nosql/allegrograph/index.js +169 -0
- package/dist/nosql/arangodb/index.js +364 -0
- package/dist/nosql/azure-blob/index.js +206 -0
- package/dist/nosql/beanstalkd/index.js +231 -0
- package/dist/nosql/beequeue/index.js +210 -0
- package/dist/nosql/bigchaindb/index.js +195 -0
- package/dist/nosql/bigtable/index.js +224 -0
- package/dist/nosql/blazegraph/index.js +173 -0
- package/dist/nosql/bullmq/index.js +191 -0
- package/dist/nosql/cassandra/index.js +174 -0
- package/dist/nosql/chroma/index.js +190 -0
- package/dist/nosql/cloudflare-kv/index.js +220 -0
- package/dist/nosql/coherence/index.js +200 -0
- package/dist/nosql/cosmosdb/index.js +157 -0
- package/dist/nosql/couchbase/index.js +213 -0
- package/dist/nosql/dax/index.js +212 -0
- package/dist/nosql/deno-kv/index.js +206 -0
- package/dist/nosql/dgraph/index.js +171 -0
- package/dist/nosql/doris/index.js +169 -0
- package/dist/nosql/druid/index.js +162 -0
- package/dist/nosql/dynamodb/index.js +937 -0
- package/dist/nosql/elasticsearch/index.js +377 -0
- package/dist/nosql/etcd/index.js +502 -0
- package/dist/nosql/eventhubs/index.js +213 -0
- package/dist/nosql/eventstore/index.js +254 -0
- package/dist/nosql/faunadb/index.js +188 -0
- package/dist/nosql/firestore/index.js +177 -0
- package/dist/nosql/fluree/index.js +148 -0
- package/dist/nosql/fuseki/index.js +170 -0
- package/dist/nosql/gcs/index.js +172 -0
- package/dist/nosql/gearman/index.js +160 -0
- package/dist/nosql/geode/index.js +196 -0
- package/dist/nosql/graphdb/index.js +169 -0
- package/dist/nosql/graylog/index.js +188 -0
- package/dist/nosql/gridgain/index.js +171 -0
- package/dist/nosql/hazelcast/index.js +162 -0
- package/dist/nosql/hbase/index.js +230 -0
- package/dist/nosql/ignite/index.js +173 -0
- package/dist/nosql/immudb/index.js +184 -0
- package/dist/nosql/index.js +232 -0
- package/dist/nosql/infinispan/index.js +200 -0
- package/dist/nosql/influxdb/index.js +0 -0
- package/dist/nosql/kafka/index.js +234 -0
- package/dist/nosql/keyspaces/index.js +189 -0
- package/dist/nosql/kinesis/index.js +253 -0
- package/dist/nosql/leveldb/index.js +153 -0
- package/dist/nosql/lmdb/index.js +160 -0
- package/dist/nosql/loki/index.js +201 -0
- package/dist/nosql/marklogic/index.js +204 -0
- package/dist/nosql/materialize/index.js +145 -0
- package/dist/nosql/meilisearch/index.js +154 -0
- package/dist/nosql/memcached/index.js +223 -0
- package/dist/nosql/milvus/index.js +410 -0
- package/dist/nosql/minio/index.js +265 -0
- package/dist/nosql/momento/index.js +179 -0
- package/dist/nosql/mongodb/index.js +461 -0
- package/dist/nosql/nats/index.js +247 -0
- package/dist/nosql/nedb/index.js +164 -0
- package/dist/nosql/neo4j/index.js +450 -0
- package/dist/nosql/neptune/index.js +470 -0
- package/dist/nosql/nsq/index.js +200 -0
- package/dist/nosql/opensearch/index.js +186 -0
- package/dist/nosql/orientdb/index.js +175 -0
- package/dist/nosql/papertrail/index.js +200 -0
- package/dist/nosql/pinecone/index.js +0 -0
- package/dist/nosql/pinot/index.js +133 -0
- package/dist/nosql/pouchdb/index.js +172 -0
- package/dist/nosql/prometheus/index.js +174 -0
- package/dist/nosql/provendb/index.js +147 -0
- package/dist/nosql/pubsub/index.js +187 -0
- package/dist/nosql/pulsar/index.js +232 -0
- package/dist/nosql/qdrant/index.js +295 -0
- package/dist/nosql/qldb/index.js +192 -0
- package/dist/nosql/r2/index.js +281 -0
- package/dist/nosql/rabbitmq/index.js +237 -0
- package/dist/nosql/ravendb/index.js +175 -0
- package/dist/nosql/redis/index.js +607 -0
- package/dist/nosql/redpanda/index.js +237 -0
- package/dist/nosql/resque/index.js +203 -0
- package/dist/nosql/rethinkdb/index.js +232 -0
- package/dist/nosql/rocksdb/index.js +152 -0
- package/dist/nosql/rockset/index.js +126 -0
- package/dist/nosql/s3/index.js +298 -0
- package/dist/nosql/scylladb/index.js +178 -0
- package/dist/nosql/signoz/index.js +227 -0
- package/dist/nosql/sns/index.js +201 -0
- package/dist/nosql/solr/index.js +231 -0
- package/dist/nosql/splunk/index.js +227 -0
- package/dist/nosql/sqs/index.js +246 -0
- package/dist/nosql/stardog/index.js +169 -0
- package/dist/nosql/starrocks/index.js +170 -0
- package/dist/nosql/store.js +2 -0
- package/dist/nosql/sumologic/index.js +213 -0
- package/dist/nosql/surrealdb/index.js +179 -0
- package/dist/nosql/terminusdb/index.js +151 -0
- package/dist/nosql/tigergraph/index.js +469 -0
- package/dist/nosql/typesense/index.js +148 -0
- package/dist/nosql/unqlite/index.js +157 -0
- package/dist/nosql/upstash/index.js +167 -0
- package/dist/nosql/vercel-kv/index.js +166 -0
- package/dist/nosql/victoriametrics/index.js +213 -0
- package/dist/nosql/virtuoso/index.js +169 -0
- package/dist/nosql/weaviate/index.js +276 -0
- package/dist/operators/index.js +108 -0
- package/dist/operators.js +2690 -0
- package/dist/prisma-migrate/index.js +38 -0
- package/dist/prisma-migrate/migration-generator.js +125 -0
- package/dist/prisma-migrate/model-generator.js +172 -0
- package/dist/prisma-migrate/relations.js +100 -0
- package/dist/prisma-migrate/schema-parser.js +167 -0
- package/dist/prisma-migrate/type-mapper.js +40 -0
- package/dist/prorm.js +6832 -0
- package/dist/query-builders/cte-builder.js +80 -0
- package/dist/query-builders/functions/aggregate.js +390 -0
- package/dist/query-builders/functions/conditional.js +503 -0
- package/dist/query-builders/functions/datetime.js +695 -0
- package/dist/query-builders/functions/fulltext.js +439 -0
- package/dist/query-builders/functions/index.js +93 -0
- package/dist/query-builders/functions/json.js +427 -0
- package/dist/query-builders/functions/math.js +399 -0
- package/dist/query-builders/functions/string.js +518 -0
- package/dist/query-builders/functions/window.js +328 -0
- package/dist/query-builders/include-builder.js +323 -0
- package/dist/query-builders/index-expression-builder.js +242 -0
- package/dist/query-builders/index.js +161 -0
- package/dist/query-builders/insert-builder.js +164 -0
- package/dist/query-builders/model-helpers.js +38 -0
- package/dist/query-builders/order-limit-builder.js +239 -0
- package/dist/query-builders/sql-compiler.js +2040 -0
- package/dist/query-builders/subquery-builder.js +152 -0
- package/dist/query-builders/update-builder.js +182 -0
- package/dist/query-builders/view-builder.js +218 -0
- package/dist/query-builders/where-builder.js +1532 -0
- package/dist/query-interface.js +622 -0
- package/dist/query-optimizers/batch-optimizer.js +426 -0
- package/dist/query-optimizers/explain-plans.js +415 -0
- package/dist/query-optimizers/index.js +51 -0
- package/dist/query-optimizers/prepared-statement-cache.js +423 -0
- package/dist/query-optimizers/query-hints.js +438 -0
- package/dist/query-optimizers/query-optimizer.js +278 -0
- package/dist/query-optimizers/slow-query-logger.js +271 -0
- package/dist/replica-manager.js +507 -0
- package/dist/schema/index.js +15 -0
- package/dist/schema/migration-generator.js +374 -0
- package/dist/schema/schema-differ.js +549 -0
- package/dist/schema/types.js +6 -0
- package/dist/sql-constants.js +300 -0
- package/dist/sqlite-advanced.js +1047 -0
- package/dist/streams/index.js +12 -0
- package/dist/streams/transforms.js +178 -0
- package/dist/transaction.js +456 -0
- package/dist/types/index.js +180 -0
- package/dist/user-management.js +127 -0
- package/dist/utils/date.js +300 -0
- package/dist/utils/index.js +1079 -0
- package/dist/utils/string.js +161 -0
- package/dist/validators/index.js +19 -0
- package/dist/validators/validator.js +911 -0
- package/package.json +190 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BigtableStore = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Google Cloud Bigtable store.
|
|
6
|
+
*
|
|
7
|
+
* Bigtable is Google's fully-managed wide-column store — the system the
|
|
8
|
+
* original Bigtable paper describes and that HBase was later modelled on.
|
|
9
|
+
* Data is a sparse, sorted map addressed by `(row key, column family, column
|
|
10
|
+
* qualifier, timestamp)`: rows are keyed by an arbitrary byte-string row key
|
|
11
|
+
* (stored in lexicographic order), grouped into a small set of column
|
|
12
|
+
* families, with an unbounded number of qualifiers per family. There is no
|
|
13
|
+
* fixed schema beyond the family list, no joins, no secondary indexes, and no
|
|
14
|
+
* arbitrary WHERE filtering — reads are single-row lookups by key or range/
|
|
15
|
+
* filter scans over the sorted key space. None of that fits the SQL-shaped
|
|
16
|
+
* `Dialect` interface (`src/dialects/dialect.ts`), so this store implements
|
|
17
|
+
* the minimal `NoSqlStore` marker interface (`src/nosql/store.ts`) and exposes
|
|
18
|
+
* Bigtable's own row operations directly.
|
|
19
|
+
*
|
|
20
|
+
* Built on the official `@google-cloud/bigtable` client. That client is
|
|
21
|
+
* resource-oriented: a `Bigtable` instance resolves to an `instance(id)`,
|
|
22
|
+
* which resolves to a `table(id)`, on which `insert`/`getRows`/`row(key)`/
|
|
23
|
+
* `createTable` operate. This store caches the resolved table handles and
|
|
24
|
+
* exposes flat `insertRow`/`getRow`/`deleteRow`/`readRows`/`createTable`
|
|
25
|
+
* methods over them. The driver is an optional peer dependency loaded lazily
|
|
26
|
+
* inside `connect()` (via `require`) so importing this module never forces the
|
|
27
|
+
* driver to be installed; tests inject a pre-built mock `client` instead.
|
|
28
|
+
*/
|
|
29
|
+
const errors_1 = require("../../errors");
|
|
30
|
+
/**
|
|
31
|
+
* `BigtableStore` wraps a `@google-cloud/bigtable` client and exposes
|
|
32
|
+
* Bigtable's row surface: `insertRow`/`getRow`/`deleteRow` for single-row
|
|
33
|
+
* operations, `readRows` for range/filter scans, and `createTable` for
|
|
34
|
+
* defining a table's column families. Instance and table ids are resolved once
|
|
35
|
+
* and the resulting handles cached per table id.
|
|
36
|
+
*/
|
|
37
|
+
class BigtableStore {
|
|
38
|
+
constructor(options = {}) {
|
|
39
|
+
this.name = 'bigtable';
|
|
40
|
+
this.library = '@google-cloud/bigtable';
|
|
41
|
+
this.client = null;
|
|
42
|
+
this.instance = null;
|
|
43
|
+
this.tables = new Map();
|
|
44
|
+
this.connected = false;
|
|
45
|
+
this.options = options;
|
|
46
|
+
}
|
|
47
|
+
// ---------------------------------------------------------------------
|
|
48
|
+
// NoSqlStore lifecycle
|
|
49
|
+
// ---------------------------------------------------------------------
|
|
50
|
+
async connect() {
|
|
51
|
+
if (this.connected && this.client) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
let client = this.options.client;
|
|
56
|
+
if (!client) {
|
|
57
|
+
// Lazy-load the optional driver so importing this module never
|
|
58
|
+
// requires `@google-cloud/bigtable` to be installed. Tests inject a
|
|
59
|
+
// mock `client` above and never reach this branch.
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
61
|
+
const { Bigtable } = require('@google-cloud/bigtable');
|
|
62
|
+
client = new Bigtable({
|
|
63
|
+
projectId: this.options.projectId,
|
|
64
|
+
...this.options.clientOptions,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
this.client = client;
|
|
68
|
+
// Resolve the instance handle once; individual table handles are
|
|
69
|
+
// resolved lazily/cached in tableFor().
|
|
70
|
+
if (this.options.instanceId) {
|
|
71
|
+
this.instance = client.instance(this.options.instanceId);
|
|
72
|
+
}
|
|
73
|
+
this.connected = true;
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
this.client = null;
|
|
77
|
+
this.instance = null;
|
|
78
|
+
this.connected = false;
|
|
79
|
+
const parent = err instanceof Error ? err : new Error(String(err));
|
|
80
|
+
throw new errors_1.ConnectionError(`Unable to connect to Bigtable: ${parent.message}`, {
|
|
81
|
+
parent,
|
|
82
|
+
database: 'bigtable',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The Bigtable client manages its own gRPC channel pool and does not expose
|
|
88
|
+
* a public close on the surface this store depends on, so `disconnect()`
|
|
89
|
+
* drops the cached handles and flips `connected` to false.
|
|
90
|
+
*/
|
|
91
|
+
async disconnect() {
|
|
92
|
+
this.tables.clear();
|
|
93
|
+
this.instance = null;
|
|
94
|
+
this.client = null;
|
|
95
|
+
this.connected = false;
|
|
96
|
+
}
|
|
97
|
+
isConnected() {
|
|
98
|
+
return this.connected && this.client !== null;
|
|
99
|
+
}
|
|
100
|
+
/** Returns the underlying `Bigtable` client for anything not wrapped here. */
|
|
101
|
+
getClient() {
|
|
102
|
+
return this.requireClient();
|
|
103
|
+
}
|
|
104
|
+
requireClient() {
|
|
105
|
+
if (!this.client || !this.connected) {
|
|
106
|
+
throw new errors_1.ConnectionError('Bigtable client is not connected. Call connect() first.', {
|
|
107
|
+
database: 'bigtable',
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return this.client;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Resolves (and caches) the `Table` handle for `table` (or the configured
|
|
114
|
+
* default `tableId`) within the configured instance. Requires both an
|
|
115
|
+
* instance id and a table id to be resolvable.
|
|
116
|
+
*/
|
|
117
|
+
tableFor(table) {
|
|
118
|
+
const client = this.requireClient();
|
|
119
|
+
if (!this.instance) {
|
|
120
|
+
if (!this.options.instanceId) {
|
|
121
|
+
throw new errors_1.DatabaseError('Bigtable instanceId is required to resolve a table', {
|
|
122
|
+
original: 'missing instanceId',
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
this.instance = client.instance(this.options.instanceId);
|
|
126
|
+
}
|
|
127
|
+
const tableId = table ?? this.options.tableId;
|
|
128
|
+
if (!tableId) {
|
|
129
|
+
throw new errors_1.DatabaseError('Bigtable tableId is required (pass a table name or set options.tableId)', {
|
|
130
|
+
original: 'missing tableId',
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
let handle = this.tables.get(tableId);
|
|
134
|
+
if (!handle) {
|
|
135
|
+
handle = this.instance.table(tableId);
|
|
136
|
+
this.tables.set(tableId, handle);
|
|
137
|
+
}
|
|
138
|
+
return handle;
|
|
139
|
+
}
|
|
140
|
+
wrapError(action, err) {
|
|
141
|
+
const parent = err instanceof Error ? err : new Error(String(err));
|
|
142
|
+
return errors_1.DatabaseError.from(parent, { message: `Bigtable ${action} failed: ${parent.message}` });
|
|
143
|
+
}
|
|
144
|
+
// ---------------------------------------------------------------------
|
|
145
|
+
// Row operations
|
|
146
|
+
// ---------------------------------------------------------------------
|
|
147
|
+
/**
|
|
148
|
+
* Inserts (writes) a single row via `table.insert(...)`. `data` maps column
|
|
149
|
+
* families to `{ qualifier: value }` maps, e.g.
|
|
150
|
+
* `{ cf: { name: 'alice', age: 30 } }`. Passed to the driver as a single
|
|
151
|
+
* `{ key, data }` insert entry.
|
|
152
|
+
*/
|
|
153
|
+
async insertRow(table, key, data) {
|
|
154
|
+
const handle = this.tableFor(table);
|
|
155
|
+
try {
|
|
156
|
+
return await handle.insert([{ key, data }]);
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
throw this.wrapError(`insertRow on '${table}' key '${key}'`, err);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** Reads a single row by key via `table.row(key).get()`, returning the row data. */
|
|
163
|
+
async getRow(table, key) {
|
|
164
|
+
const handle = this.tableFor(table);
|
|
165
|
+
try {
|
|
166
|
+
return await handle.row(key).get();
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
throw this.wrapError(`getRow on '${table}' key '${key}'`, err);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/** Deletes an entire row (all its cells) via `table.row(key).delete()`. */
|
|
173
|
+
async deleteRow(table, key) {
|
|
174
|
+
const handle = this.tableFor(table);
|
|
175
|
+
try {
|
|
176
|
+
return await handle.row(key).delete();
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
throw this.wrapError(`deleteRow on '${table}' key '${key}'`, err);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Reads multiple rows via `table.getRows(options)`. `options` (ranges, keys,
|
|
184
|
+
* prefix, limit, filter) is forwarded straight to the client. Since Bigtable
|
|
185
|
+
* keeps row keys sorted, a `ranges`/`prefix` scan reads an efficient
|
|
186
|
+
* contiguous slice of the key space. Returns the rows as the driver
|
|
187
|
+
* surfaces them.
|
|
188
|
+
*/
|
|
189
|
+
async readRows(table, opts = {}) {
|
|
190
|
+
const handle = this.tableFor(table);
|
|
191
|
+
try {
|
|
192
|
+
return await handle.getRows(opts);
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
throw this.wrapError(`readRows on '${table}'`, err);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// ---------------------------------------------------------------------
|
|
199
|
+
// Table lifecycle
|
|
200
|
+
// ---------------------------------------------------------------------
|
|
201
|
+
/**
|
|
202
|
+
* Creates a table with the given column families via `table.create(...)`.
|
|
203
|
+
* `families` is the list of column family names (e.g. `['cf', 'meta']`),
|
|
204
|
+
* passed to the client as its `families` create option. A table must declare
|
|
205
|
+
* its families up front — unlike qualifiers, families cannot be added
|
|
206
|
+
* implicitly at write time.
|
|
207
|
+
*/
|
|
208
|
+
async createTable(table, families) {
|
|
209
|
+
const handle = this.tableFor(table);
|
|
210
|
+
if (!families || families.length === 0) {
|
|
211
|
+
throw new errors_1.DatabaseError('createTable() requires at least one column family', {
|
|
212
|
+
original: 'empty families list',
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
return await handle.create({ families });
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
throw this.wrapError(`createTable '${table}'`, err);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
exports.BigtableStore = BigtableStore;
|
|
224
|
+
exports.default = BigtableStore;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Blazegraph store implementation.
|
|
4
|
+
*
|
|
5
|
+
* Blazegraph is a high-performance RDF triplestore. It speaks the SPARQL 1.1
|
|
6
|
+
* Protocol over HTTP: a namespace exposes a single combined SPARQL endpoint
|
|
7
|
+
* (`/blazegraph/namespace/<ns>/sparql`) used for both queries and updates
|
|
8
|
+
* (dispatched by request content-type). There is no SQL-shaped surface, so it
|
|
9
|
+
* implements the minimal `NoSqlStore` marker interface (`src/nosql/store.ts`)
|
|
10
|
+
* rather than the SQL `Dialect` interface.
|
|
11
|
+
*
|
|
12
|
+
* ## No canonical driver - HTTP over `fetch`
|
|
13
|
+
*
|
|
14
|
+
* Blazegraph has no dedicated npm client; it is just a SPARQL/HTTP endpoint.
|
|
15
|
+
* This store talks to the server with the global `fetch`. For tests (and for
|
|
16
|
+
* callers who want their own transport) an alternative client can be injected
|
|
17
|
+
* via `BlazegraphStoreOptions.client`; when omitted, a tiny internal client
|
|
18
|
+
* over `fetch` + `endpoint` is built at connect time.
|
|
19
|
+
*
|
|
20
|
+
* ## Surface
|
|
21
|
+
*
|
|
22
|
+
* - `query(sparql)` -> POST to `/blazegraph/namespace/<ns>/sparql`, bindings
|
|
23
|
+
* - `update(sparql)` -> POST to the same endpoint
|
|
24
|
+
* - `ask(sparql)` -> POST an ASK query, returns the boolean
|
|
25
|
+
* - `add(triples)` -> `INSERT DATA { ... }` update
|
|
26
|
+
* - `drop(graph?)` -> `DROP GRAPH <g>` / `DROP ALL` update
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.BlazegraphStore = exports.DEFAULT_BLAZEGRAPH_NAMESPACE = exports.DEFAULT_BLAZEGRAPH_ENDPOINT = void 0;
|
|
30
|
+
exports.createFetchClient = createFetchClient;
|
|
31
|
+
const errors_1 = require("../../errors");
|
|
32
|
+
/** Default Blazegraph base URL. */
|
|
33
|
+
exports.DEFAULT_BLAZEGRAPH_ENDPOINT = 'http://localhost:9999';
|
|
34
|
+
/** Default namespace. */
|
|
35
|
+
exports.DEFAULT_BLAZEGRAPH_NAMESPACE = 'kb';
|
|
36
|
+
/** Build a `fetch`-backed SPARQL client for the given endpoint. */
|
|
37
|
+
function createFetchClient(endpoint, headers) {
|
|
38
|
+
const base = endpoint.endsWith('/') ? endpoint : `${endpoint}/`;
|
|
39
|
+
const buildUrl = (path) => new URL(path.replace(/^\//, ''), base).toString();
|
|
40
|
+
return {
|
|
41
|
+
async query(path, sparql) {
|
|
42
|
+
const res = await fetch(buildUrl(path), {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/sparql-query',
|
|
46
|
+
Accept: 'application/sparql-results+json',
|
|
47
|
+
...(headers ?? {}),
|
|
48
|
+
},
|
|
49
|
+
body: sparql,
|
|
50
|
+
});
|
|
51
|
+
if (!res.ok)
|
|
52
|
+
throw new Error(`HTTP ${res.status} ${res.statusText}`);
|
|
53
|
+
return res.json();
|
|
54
|
+
},
|
|
55
|
+
async update(path, sparql) {
|
|
56
|
+
const res = await fetch(buildUrl(path), {
|
|
57
|
+
method: 'POST',
|
|
58
|
+
headers: { 'Content-Type': 'application/sparql-update', ...(headers ?? {}) },
|
|
59
|
+
body: sparql,
|
|
60
|
+
});
|
|
61
|
+
if (!res.ok)
|
|
62
|
+
throw new Error(`HTTP ${res.status} ${res.statusText}`);
|
|
63
|
+
const text = await res.text();
|
|
64
|
+
return text || undefined;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* `BlazegraphStore` wraps a Blazegraph namespace's combined SPARQL endpoint
|
|
70
|
+
* behind the `NoSqlStore` lifecycle.
|
|
71
|
+
*/
|
|
72
|
+
class BlazegraphStore {
|
|
73
|
+
constructor(options = {}) {
|
|
74
|
+
this.name = 'blazegraph';
|
|
75
|
+
this.library = 'fetch';
|
|
76
|
+
this.client = null;
|
|
77
|
+
this.connected = false;
|
|
78
|
+
this.endpoint = options.endpoint ?? exports.DEFAULT_BLAZEGRAPH_ENDPOINT;
|
|
79
|
+
this.namespace = options.namespace ?? exports.DEFAULT_BLAZEGRAPH_NAMESPACE;
|
|
80
|
+
this.injectedClient = options.client;
|
|
81
|
+
this.headers = options.headers;
|
|
82
|
+
}
|
|
83
|
+
/** Combined SPARQL endpoint path for the configured namespace. */
|
|
84
|
+
get sparqlPath() {
|
|
85
|
+
return `/blazegraph/namespace/${this.namespace}/sparql`;
|
|
86
|
+
}
|
|
87
|
+
/** SPARQL query endpoint path (same combined endpoint). */
|
|
88
|
+
get queryPath() {
|
|
89
|
+
return this.sparqlPath;
|
|
90
|
+
}
|
|
91
|
+
/** SPARQL update endpoint path (same combined endpoint). */
|
|
92
|
+
get updatePath() {
|
|
93
|
+
return this.sparqlPath;
|
|
94
|
+
}
|
|
95
|
+
// ---------------------------------------------------------------------
|
|
96
|
+
// Connection lifecycle
|
|
97
|
+
// ---------------------------------------------------------------------
|
|
98
|
+
async connect() {
|
|
99
|
+
if (this.connected && this.client)
|
|
100
|
+
return;
|
|
101
|
+
this.client = this.injectedClient ?? createFetchClient(this.endpoint, this.headers);
|
|
102
|
+
this.connected = true;
|
|
103
|
+
}
|
|
104
|
+
async disconnect() {
|
|
105
|
+
this.client = null;
|
|
106
|
+
this.connected = false;
|
|
107
|
+
}
|
|
108
|
+
isConnected() {
|
|
109
|
+
return this.connected && this.client !== null;
|
|
110
|
+
}
|
|
111
|
+
/** Returns the underlying (internal or injected) SPARQL HTTP client. */
|
|
112
|
+
getClient() {
|
|
113
|
+
return this.requireClient();
|
|
114
|
+
}
|
|
115
|
+
requireClient() {
|
|
116
|
+
if (!this.client) {
|
|
117
|
+
throw new errors_1.ConnectionError('Not connected to Blazegraph', {
|
|
118
|
+
database: 'blazegraph',
|
|
119
|
+
host: this.endpoint,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return this.client;
|
|
123
|
+
}
|
|
124
|
+
// ---------------------------------------------------------------------
|
|
125
|
+
// SPARQL surface
|
|
126
|
+
// ---------------------------------------------------------------------
|
|
127
|
+
/** Runs a SPARQL SELECT/CONSTRUCT query; returns the result bindings. */
|
|
128
|
+
async query(sparql) {
|
|
129
|
+
const client = this.requireClient();
|
|
130
|
+
try {
|
|
131
|
+
const body = await client.query(this.queryPath, sparql);
|
|
132
|
+
return body?.results?.bindings ?? [];
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
const parent = err instanceof Error ? err : new Error(String(err));
|
|
136
|
+
throw errors_1.DatabaseError.from(parent, { message: `Blazegraph query failed: ${parent.message}`, sql: sparql });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** Runs a SPARQL ASK query; returns the boolean answer. */
|
|
140
|
+
async ask(sparql) {
|
|
141
|
+
const client = this.requireClient();
|
|
142
|
+
try {
|
|
143
|
+
const body = await client.query(this.queryPath, sparql);
|
|
144
|
+
return Boolean(body?.boolean);
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
const parent = err instanceof Error ? err : new Error(String(err));
|
|
148
|
+
throw errors_1.DatabaseError.from(parent, { message: `Blazegraph ask failed: ${parent.message}`, sql: sparql });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** Runs a SPARQL UPDATE (INSERT/DELETE/DROP/...). */
|
|
152
|
+
async update(sparql) {
|
|
153
|
+
const client = this.requireClient();
|
|
154
|
+
try {
|
|
155
|
+
return await client.update(this.updatePath, sparql);
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
const parent = err instanceof Error ? err : new Error(String(err));
|
|
159
|
+
throw errors_1.DatabaseError.from(parent, { message: `Blazegraph update failed: ${parent.message}`, sql: sparql });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** Inserts triples via `INSERT DATA { ... }`. Accepts a triple string or array. */
|
|
163
|
+
async add(triples, graph) {
|
|
164
|
+
const body = Array.isArray(triples) ? triples.join('\n') : triples;
|
|
165
|
+
const inner = graph ? `GRAPH <${graph}> { ${body} }` : body;
|
|
166
|
+
return this.update(`INSERT DATA { ${inner} }`);
|
|
167
|
+
}
|
|
168
|
+
/** Drops a named graph, or all graphs when no graph is given. */
|
|
169
|
+
async drop(graph) {
|
|
170
|
+
return this.update(graph ? `DROP GRAPH <${graph}>` : 'DROP ALL');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
exports.BlazegraphStore = BlazegraphStore;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BullMQ job/task-queue store.
|
|
4
|
+
*
|
|
5
|
+
* BullMQ is a Redis-backed queue: a `Queue` object adds jobs to a named
|
|
6
|
+
* queue, and a `Worker` object pulls jobs from that queue and runs a handler.
|
|
7
|
+
* Each queue is a distinct object bound to a name, so this store caches one
|
|
8
|
+
* `Queue` (and, once `process()`d, one `Worker`) per queue name. BullMQ is
|
|
9
|
+
* not a database and does not fit the SQL-shaped `Dialect` interface, so this
|
|
10
|
+
* class implements the minimal `NoSqlStore` marker interface and exposes
|
|
11
|
+
* BullMQ's real add/process/getJob operations instead.
|
|
12
|
+
*
|
|
13
|
+
* Uses the `bullmq` driver. It is an optional peer loaded lazily (via
|
|
14
|
+
* `require`) inside `connect()`, so importing this module does not require it
|
|
15
|
+
* to be installed unless you actually connect. A pre-built driver module
|
|
16
|
+
* (providing `Queue` and `Worker` constructors) can be injected via
|
|
17
|
+
* `BullMQStoreOptions.client`, in which case `connect()` adopts it and skips
|
|
18
|
+
* the `require` entirely (used by the unit tests to inject mocks).
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.BullMQStore = void 0;
|
|
22
|
+
const errors_1 = require("../../errors");
|
|
23
|
+
function wrapConnectionError(err) {
|
|
24
|
+
const parent = err instanceof Error ? err : new Error(String(err));
|
|
25
|
+
const message = /econnrefused/i.test(parent.message)
|
|
26
|
+
? 'Connection refused'
|
|
27
|
+
: `Unable to connect to BullMQ: ${parent.message}`;
|
|
28
|
+
return new errors_1.ConnectionError(message, { parent, database: 'bullmq' });
|
|
29
|
+
}
|
|
30
|
+
function wrapDatabaseError(err, action) {
|
|
31
|
+
const parent = err instanceof Error ? err : new Error(String(err));
|
|
32
|
+
return errors_1.DatabaseError.from(parent, { message: `BullMQ ${action} failed: ${parent.message}` });
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* `BullMQStore` manages a pool of BullMQ `Queue`/`Worker` objects keyed by
|
|
36
|
+
* queue name and exposes the common queue surface
|
|
37
|
+
* (`enqueue`/`process`/`getJob`/`remove`/`stats`).
|
|
38
|
+
*/
|
|
39
|
+
class BullMQStore {
|
|
40
|
+
constructor(options = {}) {
|
|
41
|
+
this.name = 'bullmq';
|
|
42
|
+
this.library = 'bullmq';
|
|
43
|
+
this.driver = null;
|
|
44
|
+
this.connected = false;
|
|
45
|
+
this.queues = new Map();
|
|
46
|
+
this.workers = new Map();
|
|
47
|
+
this.options = options;
|
|
48
|
+
}
|
|
49
|
+
// ---------------------------------------------------------------------
|
|
50
|
+
// Connection lifecycle
|
|
51
|
+
// ---------------------------------------------------------------------
|
|
52
|
+
async connect() {
|
|
53
|
+
if (this.connected && this.driver) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
// BullMQ has no single connection to open; "connecting" just resolves
|
|
58
|
+
// the driver module. Per-queue Redis connections open lazily when the
|
|
59
|
+
// first Queue/Worker for a name is constructed.
|
|
60
|
+
this.driver = this.options.client != null ? this.options.client : require('bullmq');
|
|
61
|
+
this.connected = true;
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
this.driver = null;
|
|
65
|
+
this.connected = false;
|
|
66
|
+
throw wrapConnectionError(err);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async disconnect() {
|
|
70
|
+
for (const worker of this.workers.values()) {
|
|
71
|
+
try {
|
|
72
|
+
if (worker && typeof worker.close === 'function')
|
|
73
|
+
await worker.close();
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Ignore teardown errors.
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const queue of this.queues.values()) {
|
|
80
|
+
try {
|
|
81
|
+
if (queue && typeof queue.close === 'function')
|
|
82
|
+
await queue.close();
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// Ignore teardown errors.
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
this.workers.clear();
|
|
89
|
+
this.queues.clear();
|
|
90
|
+
this.driver = null;
|
|
91
|
+
this.connected = false;
|
|
92
|
+
}
|
|
93
|
+
isConnected() {
|
|
94
|
+
return this.connected && this.driver !== null;
|
|
95
|
+
}
|
|
96
|
+
/** Returns the underlying `bullmq` driver module (with `Queue`/`Worker`). */
|
|
97
|
+
getClient() {
|
|
98
|
+
return this.requireDriver();
|
|
99
|
+
}
|
|
100
|
+
requireDriver() {
|
|
101
|
+
if (!this.driver) {
|
|
102
|
+
throw new errors_1.ConnectionError('Not connected to BullMQ', { database: 'bullmq' });
|
|
103
|
+
}
|
|
104
|
+
return this.driver;
|
|
105
|
+
}
|
|
106
|
+
get connectionOpts() {
|
|
107
|
+
return this.options.connection ?? { host: '127.0.0.1', port: 6379 };
|
|
108
|
+
}
|
|
109
|
+
/** Get (creating and caching on first use) the `Queue` for a queue name. */
|
|
110
|
+
getQueue(name) {
|
|
111
|
+
const driver = this.requireDriver();
|
|
112
|
+
let queue = this.queues.get(name);
|
|
113
|
+
if (!queue) {
|
|
114
|
+
queue = new driver.Queue(name, { connection: this.connectionOpts });
|
|
115
|
+
this.queues.set(name, queue);
|
|
116
|
+
}
|
|
117
|
+
return queue;
|
|
118
|
+
}
|
|
119
|
+
// ---------------------------------------------------------------------
|
|
120
|
+
// Queue operations
|
|
121
|
+
// ---------------------------------------------------------------------
|
|
122
|
+
/**
|
|
123
|
+
* Add a job to the named queue via `queue.add(name, data, opts)`. Returns
|
|
124
|
+
* the id BullMQ assigns to the job.
|
|
125
|
+
*/
|
|
126
|
+
async enqueue(queue, jobData, opts = {}) {
|
|
127
|
+
try {
|
|
128
|
+
const { name, ...jobOpts } = opts;
|
|
129
|
+
const q = this.getQueue(queue);
|
|
130
|
+
const job = await q.add(name ?? queue, jobData, jobOpts);
|
|
131
|
+
return job?.id;
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
throw wrapDatabaseError(err, 'enqueue');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Register a `Worker` for the named queue that runs `handler(job)` for each
|
|
139
|
+
* job. One worker is cached per queue name; a second `process()` on the
|
|
140
|
+
* same name returns the existing worker.
|
|
141
|
+
*/
|
|
142
|
+
async process(queue, handler, opts = {}) {
|
|
143
|
+
try {
|
|
144
|
+
const existing = this.workers.get(queue);
|
|
145
|
+
if (existing)
|
|
146
|
+
return existing;
|
|
147
|
+
const driver = this.requireDriver();
|
|
148
|
+
const worker = new driver.Worker(queue, handler, {
|
|
149
|
+
connection: this.connectionOpts,
|
|
150
|
+
...opts,
|
|
151
|
+
});
|
|
152
|
+
this.workers.set(queue, worker);
|
|
153
|
+
return worker;
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
throw wrapDatabaseError(err, 'process');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/** Fetch a job by id from the named queue (`null` if it no longer exists). */
|
|
160
|
+
async getJob(queue, id) {
|
|
161
|
+
try {
|
|
162
|
+
return await this.getQueue(queue).getJob(id);
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
throw wrapDatabaseError(err, 'getJob');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** Remove a job by id from the named queue. */
|
|
169
|
+
async remove(queue, id) {
|
|
170
|
+
try {
|
|
171
|
+
const job = await this.getQueue(queue).getJob(id);
|
|
172
|
+
if (job && typeof job.remove === 'function') {
|
|
173
|
+
await job.remove();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
throw wrapDatabaseError(err, 'remove');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/** Return job counts by state (`waiting`/`active`/`completed`/`failed`/...). */
|
|
181
|
+
async stats(queue) {
|
|
182
|
+
try {
|
|
183
|
+
return await this.getQueue(queue).getJobCounts();
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
throw wrapDatabaseError(err, 'stats');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.BullMQStore = BullMQStore;
|
|
191
|
+
exports.default = BullMQStore;
|