@keetanetwork/anchor 0.0.61 → 0.0.62

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.
@@ -67,7 +67,7 @@ export default class KeetaAnchorQueueStorageDriverPostgres {
67
67
  // Version 1: Initial schema
68
68
  if (currentVersion < 1) {
69
69
  logger?.debug('Applying schema version 1: Initial tables and indexes');
70
- await client.query('BEGIN');
70
+ await client.query('BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED');
71
71
  try {
72
72
  await client.query(`
73
73
  CREATE TABLE IF NOT EXISTS ${this.tableNameEntries} (
@@ -108,15 +108,15 @@ export default class KeetaAnchorQueueStorageDriverPostgres {
108
108
  // Version 2: Partition-aware composite indexes
109
109
  if (currentVersion < 2) {
110
110
  logger?.debug('Applying schema version 2: Partition-aware composite indexes');
111
- // Create new partition-aware indexes (CONCURRENTLY must be outside transaction)
112
- logger?.debug('Creating partition-aware indexes...');
113
- await client.query(`CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_${this.tableNameEntries}_path_status ON ${this.tableNameEntries}(path, status)`);
114
- await client.query(`CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_${this.tableNameEntries}_path_updated ON ${this.tableNameEntries}(path, updated)`);
115
- await client.query(`CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_${this.tableNameEntries}_path_status_updated ON ${this.tableNameEntries}(path, status, updated)`);
116
- await client.query(`CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_${this.tableNameIdempotentKeys}_path_idempotent_id ON ${this.tableNameIdempotentKeys}(path, idempotent_id)`);
117
111
  // Now drop old indexes and record version
118
- await client.query('BEGIN');
112
+ await client.query('BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED');
119
113
  try {
114
+ // Create new partition-aware indexes
115
+ logger?.debug('Creating partition-aware indexes...');
116
+ await client.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableNameEntries}_path_status ON ${this.tableNameEntries}(path, status)`);
117
+ await client.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableNameEntries}_path_updated ON ${this.tableNameEntries}(path, updated)`);
118
+ await client.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableNameEntries}_path_status_updated ON ${this.tableNameEntries}(path, status, updated)`);
119
+ await client.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableNameIdempotentKeys}_path_idempotent_id ON ${this.tableNameIdempotentKeys}(path, idempotent_id)`);
120
120
  // Drop old indexes that are now redundant (these will fail gracefully if indexes don't exist)
121
121
  logger?.debug('Dropping old single-column indexes...');
122
122
  await client.query(`DROP INDEX IF EXISTS idx_${this.tableNameEntries}_status`);
@@ -181,21 +181,25 @@ export default class KeetaAnchorQueueStorageDriverPostgres {
181
181
  }
182
182
  catch (error) {
183
183
  lastError = error;
184
+ let detectedRetryableError = false;
184
185
  if (error instanceof Error) {
185
186
  const errorCode = 'code' in error ? error.code : null;
186
187
  if (errorCode === '40001' || errorCode === '40P01') {
187
- logger?.debug('Serialization failure or deadlock detected');
188
188
  // Track serialization retries for instrumentation
189
189
  this.serializationRetryCount++;
190
- const minBackoff = 100;
191
- const maxBackoff = 30_000;
192
- const backoffIntervalSize = Math.min(maxBackoff - minBackoff, (retry + 50) ** 2);
193
- const backoff = Math.round((Math.random() * backoffIntervalSize)) + minBackoff;
194
- this.methodLogger('runWithRetry')?.debug(`Retrying DB operation in ${backoff}ms (retry #${retry}) from`, new Error().stack);
195
- await asleep(backoff);
196
- continue;
190
+ detectedRetryableError = true;
191
+ logger?.debug('Detected retryable error with code', errorCode);
197
192
  }
198
193
  }
194
+ if (detectedRetryableError) {
195
+ const minBackoff = 100;
196
+ const maxBackoff = 30_000;
197
+ const backoffIntervalSize = Math.min(maxBackoff - minBackoff, (retry + 50) ** 2);
198
+ const backoff = Math.round((Math.random() * backoffIntervalSize)) + minBackoff;
199
+ this.methodLogger('runWithRetry')?.debug(`Retrying DB operation in ${backoff}ms (retry #${retry}) from`, new Error().stack);
200
+ await asleep(backoff);
201
+ continue;
202
+ }
199
203
  throw (error);
200
204
  }
201
205
  }
@@ -222,7 +226,7 @@ export default class KeetaAnchorQueueStorageDriverPostgres {
222
226
  const client = await pool.connect();
223
227
  try {
224
228
  logger?.debug('Starting DB transaction');
225
- await client.query('BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE');
229
+ await client.query('BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED');
226
230
  logger?.debug('DB transaction started');
227
231
  if (debugForceIndexScan) {
228
232
  await client.query('SET LOCAL enable_seqscan TO off');
@@ -253,28 +257,6 @@ export default class KeetaAnchorQueueStorageDriverPostgres {
253
257
  async add(request, info) {
254
258
  return (await this.dbTransaction('add', async (client, logger) => {
255
259
  let entryID = ConvertStringToRequestID(info?.id);
256
- if (entryID) {
257
- const existingEntry = await client.query(`SELECT id FROM ${this.tableNameEntries} WHERE id = $1 AND path = $2`, [entryID, this.pathStr]);
258
- if (existingEntry.rows.length > 0) {
259
- logger?.debug(`Request with id ${String(entryID)} already exists, ignoring`);
260
- return (entryID);
261
- }
262
- await this.toctouDelay?.();
263
- }
264
- const idempotentIDs = info?.idempotentKeys;
265
- if (idempotentIDs) {
266
- const matchingIdempotentEntries = new Set();
267
- for (const idempotentID of idempotentIDs) {
268
- const idempotentEntryExists = await client.query(`SELECT idempotent_id FROM ${this.tableNameIdempotentKeys} WHERE idempotent_id = $1 AND path = $2`, [idempotentID, this.pathStr]);
269
- if (idempotentEntryExists.rows.length > 0) {
270
- matchingIdempotentEntries.add(idempotentID);
271
- }
272
- }
273
- if (matchingIdempotentEntries.size !== 0) {
274
- throw (new Errors.IdempotentExistsError('One or more idempotent entries already exist in the queue', matchingIdempotentEntries));
275
- }
276
- await this.toctouDelay?.();
277
- }
278
260
  entryID ??= ConvertStringToRequestID(crypto.randomUUID());
279
261
  logger?.debug(`Enqueuing request with id ${String(entryID)}`);
280
262
  const currentTime = Date.now();
@@ -283,12 +265,34 @@ export default class KeetaAnchorQueueStorageDriverPostgres {
283
265
  * The status to use for the new entry
284
266
  */
285
267
  const status = info?.status ?? 'pending';
286
- await client.query(`INSERT INTO ${this.tableNameEntries} (id, path, request, output, last_error, status, created, updated, worker, failures)
287
- VALUES ($1, $2, $3, NULL, NULL, $4, $5, $6, NULL, 0)`, [entryID, this.pathStr, requestJSON, status, currentTime, currentTime]);
268
+ const insertedEntry = await client.query(`
269
+ INSERT INTO ${this.tableNameEntries} (
270
+ id, path, request, output, last_error, status,
271
+ created, updated, worker, failures
272
+ ) VALUES ($1, $2, $3, NULL, NULL, $4, $5, $6, NULL, 0)
273
+ ON CONFLICT (id, path) DO NOTHING
274
+ RETURNING id`, [entryID, this.pathStr, requestJSON, status, currentTime, currentTime]);
275
+ if (insertedEntry.rows.length === 0) {
276
+ logger?.debug(`Request with id ${String(entryID)} already exists, ignoring`);
277
+ return (entryID);
278
+ }
279
+ await this.toctouDelay?.();
280
+ const idempotentIDs = info?.idempotentKeys;
288
281
  if (idempotentIDs && idempotentIDs.size > 0) {
289
- for (const idempotentID of idempotentIDs) {
290
- await client.query(`INSERT INTO ${this.tableNameIdempotentKeys} (entry_id, path, idempotent_id) VALUES ($1, $2, $3)`, [entryID, this.pathStr, idempotentID]);
282
+ const keys = Array.from(idempotentIDs);
283
+ const insertedKeys = await client.query(`
284
+ INSERT INTO ${this.tableNameIdempotentKeys}(entry_id, path, idempotent_id)
285
+ SELECT $1, $2, unnest($3::text[])
286
+ ON CONFLICT (idempotent_id, path) DO NOTHING
287
+ RETURNING idempotent_id`, [entryID, this.pathStr, keys]);
288
+ const foundKeySet = new Set(keys);
289
+ for (const row of insertedKeys.rows) {
290
+ foundKeySet.delete(ConvertStringToRequestID(row.idempotent_id));
291
+ }
292
+ if (insertedKeys.rows.length !== keys.length) {
293
+ throw (new Errors.IdempotentExistsError('One or more idempotent entries already exist in the queue', foundKeySet));
291
294
  }
295
+ await this.toctouDelay?.();
292
296
  }
293
297
  return (entryID);
294
298
  }));
@@ -1 +1 @@
1
- {"version":3,"file":"queue_postg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ACD,0BAA0B,EAAE,GAAW,EAAE;gBACxC,OAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;YACtC,CAAC;YACD,4BAA4B,EAAE,GAAS,EAAE;gBACxC,IAAI,CAAC,uBAAuB,GAAG,CAAC,CAAC;YAClC,CAAC;YACD,yBAAyB,EAAE,GAAS,EAAE;gBACrC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;YACjC,CAAC;YACD,0BAA0B,EAAE,GAAS,EAAE;gBACtC,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC;YAClC,CAAC;SACD,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["// cspell:ignore seqscan\n\nimport type {\n\tKeetaAnchorQueueStorageDriver,\n\tKeetaAnchorQueueStorageDriverConstructor,\n\tKeetaAnchorQueueRequest,\n\tKeetaAnchorQueueRequestID,\n\tKeetaAnchorQueueEntry,\n\tKeetaAnchorQueueEntryExtra,\n\tKeetaAnchorQueueEntryAncillaryData,\n\tKeetaAnchorQueueStatus,\n\tKeetaAnchorQueueFilter,\n\tKeetaAnchorQueueWorkerID\n} from '../index.ts';\nimport {\n\tMethodLogger,\n\tManageStatusUpdates,\n\tConvertStringToRequestID\n} from '../internal.js';\nimport { Errors } from '../common.js';\n\nimport { asleep } from '../../utils/asleep.js';\n\nimport type { Logger } from '../../log/index.ts';\nimport type { JSONSerializable } from '../../utils/json.js';\n\nimport type * as pg from 'pg';\n\ntype QueueEntryRow = {\n\tid: string;\n\trequest: string;\n\toutput: string | null;\n\tlast_error: string | null;\n\tstatus: KeetaAnchorQueueStatus;\n\tcreated: Date;\n\tupdated: Date;\n\tworker: number | null;\n\tfailures: number;\n};\n\ntype IdempotentRow = {\n\tidempotent_id: string;\n};\n\ntype KeetaAnchorQueueStorageDriverPostgresOptions = {\n\t/**\n\t * Function that returns a Postgres connection pool.\n\t */\n\tpool: () => Promise<pg.Pool>;\n\n\t/**\n\t * The prefix to use for the database tables. Defaults to 'queue',\n\t * resulting in table names 'queue_entries', 'queue_idempotent_keys',\n\t * and `queue_schema_version`.\n\t */\n\ttablePrefix?: string | undefined;\n};\n\nexport default class KeetaAnchorQueueStorageDriverPostgres<QueueRequest extends JSONSerializable = JSONSerializable, QueueResult extends JSONSerializable = JSONSerializable> implements KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult> {\n\tprivate readonly logger: Logger | undefined;\n\tprivate poolInternal: (() => Promise<pg.Pool>) | null = null;\n\tprivate tablePrefix: string | undefined;\n\tprivate tableNameEntries: string;\n\tprivate tableNameSchemaVersion: string;\n\tprivate tableNameIdempotentKeys: string;\n\tprivate dbInitializationPromise: Promise<boolean> | null = null;\n\tprivate serializationRetryCount = 0;\n\tprivate debugForceIndexScan = false;\n\n\treadonly name = 'KeetaAnchorQueueStorageDriverPostgres';\n\treadonly id: string;\n\treadonly path: string[] = [];\n\tprivate readonly pathStr: string;\n\tprivate toctouDelay: (() => Promise<void>) | undefined = undefined;\n\n\tconstructor(options: NonNullable<ConstructorParameters<KeetaAnchorQueueStorageDriverConstructor<QueueRequest, QueueResult>>[0]> & KeetaAnchorQueueStorageDriverPostgresOptions) {\n\t\tthis.id = options?.id ?? crypto.randomUUID();\n\t\tthis.logger = options?.logger;\n\t\tthis.tablePrefix = options?.tablePrefix;\n\t\tthis.poolInternal = options.pool;\n\t\tthis.path = options.path ?? [];\n\t\tthis.pathStr = ['root', ...this.path].join('.');\n\t\tObject.freeze(this.path);\n\n\t\tthis.tableNameEntries = `${this.tablePrefix ?? 'queue'}_entries`;\n\t\tthis.tableNameIdempotentKeys = `${this.tablePrefix ?? 'queue'}_idempotent_keys`;\n\t\tthis.tableNameSchemaVersion = `${this.tablePrefix ?? 'queue'}_schema_version`;\n\n\t\tthis.methodLogger('new')?.debug('Initialized Postgres queue storage driver');\n\t}\n\n\tprivate async initializeDBConnection(pool: pg.Pool): Promise<pg.Pool> {\n\t\tconst logger = this.methodLogger('initializeDBConnection');\n\n\t\tif (this.dbInitializationPromise !== null) {\n\t\t\tlogger?.debug('DB schema initialization already in progress or completed, waiting for it to finish');\n\n\t\t\tawait this.dbInitializationPromise;\n\t\t\treturn(pool);\n\t\t}\n\n\t\tthis.dbInitializationPromise = (async () => {\n\t\t\tlogger?.debug('Initializing DB schema for queue storage driver on tables', [this.tableNameEntries, this.tableNameIdempotentKeys]);\n\n\t\t\tconst client = await pool.connect();\n\t\t\ttry {\n\t\t\t\t/*\n\t\t\t\t * Random lock key (32-bit integer), to ensure\n\t\t\t\t * that multiple instances of this driver\n\t\t\t\t * (potentially across different\n\t\t\t\t * instances/process) will run the migration\n\t\t\t\t * sequentially to avoid multiple concurrent\n\t\t\t\t * migrations from competing with each other\n\t\t\t\t * and causing delays\n\t\t\t\t */\n\t\t\t\tconst lockId = 0x24995E48;\n\t\t\t\tlogger?.debug('Acquiring advisory lock for schema migration');\n\t\t\t\tawait client.query('SELECT pg_advisory_lock($1)', [lockId]);\n\n\t\t\t\ttry {\n\t\t\t\t\t// Create schema version table if it doesn't exist\n\t\t\t\t\tawait client.query(`\n\t\t\t\t\t\tCREATE TABLE IF NOT EXISTS ${this.tableNameSchemaVersion} (\n\t\t\t\t\t\t\tversion INTEGER NOT NULL,\n\t\t\t\t\t\t\tapplied_at BIGINT NOT NULL,\n\t\t\t\t\t\t\tPRIMARY KEY (version)\n\t\t\t\t\t\t)`);\n\n\t\t\t\t\t// Check current schema version\n\t\t\t\t\tconst versionResult = await client.query<{ version: number }>(`SELECT MAX(version) as version FROM ${this.tableNameSchemaVersion}`);\n\t\t\t\t\tconst currentVersion = versionResult.rows[0]?.version ?? 0;\n\n\t\t\t\t\tlogger?.debug(`Current queue schema version: ${currentVersion}`);\n\n\t\t\t\t\t// Version 1: Initial schema\n\t\t\t\t\tif (currentVersion < 1) {\n\t\t\t\t\t\tlogger?.debug('Applying schema version 1: Initial tables and indexes');\n\n\t\t\t\t\t\tawait client.query('BEGIN');\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait client.query(`\n\t\t\t\t\t\t\t\tCREATE TABLE IF NOT EXISTS ${this.tableNameEntries} (\n\t\t\t\t\t\t\t\t\tid TEXT NOT NULL,\n\t\t\t\t\t\t\t\t\tpath TEXT NOT NULL,\n\t\t\t\t\t\t\t\t\trequest TEXT NOT NULL,\n\t\t\t\t\t\t\t\t\toutput TEXT,\n\t\t\t\t\t\t\t\t\tlast_error TEXT,\n\t\t\t\t\t\t\t\t\tstatus TEXT NOT NULL,\n\t\t\t\t\t\t\t\t\tcreated BIGINT NOT NULL,\n\t\t\t\t\t\t\t\t\tupdated BIGINT NOT NULL,\n\t\t\t\t\t\t\t\t\tworker BIGINT,\n\t\t\t\t\t\t\t\t\tfailures INTEGER NOT NULL DEFAULT 0,\n\t\t\t\t\t\t\t\t\tPRIMARY KEY (id, path)\n\t\t\t\t\t\t\t\t)`);\n\n\t\t\t\t\t\t\tawait client.query(`\n\t\t\t\t\t\t\t\tCREATE TABLE IF NOT EXISTS ${this.tableNameIdempotentKeys} (\n\t\t\t\t\t\t\t\t\tentry_id TEXT NOT NULL,\n\t\t\t\t\t\t\t\t\tidempotent_id TEXT NOT NULL,\n\t\t\t\t\t\t\t\t\tpath TEXT NOT NULL,\n\t\t\t\t\t\t\t\t\tUNIQUE (idempotent_id, path),\n\t\t\t\t\t\t\t\t\tPRIMARY KEY (entry_id, idempotent_id, path),\n\t\t\t\t\t\t\t\t\tFOREIGN KEY (entry_id, path) REFERENCES ${this.tableNameEntries}(id, path)\n\t\t\t\t\t\t\t\t)`);\n\n\t\t\t\t\t\t\t// Old single-column indexes (for pre-version-2 schemas)\n\t\t\t\t\t\t\tawait client.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableNameEntries}_status ON ${this.tableNameEntries}(status)`);\n\t\t\t\t\t\t\tawait client.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableNameEntries}_updated ON ${this.tableNameEntries}(updated)`);\n\t\t\t\t\t\t\tawait client.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableNameIdempotentKeys}_idempotent_id ON ${this.tableNameIdempotentKeys}(idempotent_id)`);\n\n\t\t\t\t\t\t\tawait client.query(`INSERT INTO ${this.tableNameSchemaVersion} (version, applied_at) VALUES (1, $1)`, [Date.now()]);\n\t\t\t\t\t\t\tawait client.query('COMMIT');\n\t\t\t\t\t\t\tlogger?.debug('Applied schema version 1');\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tawait client.query('ROLLBACK');\n\t\t\t\t\t\t\tthrow(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Version 2: Partition-aware composite indexes\n\t\t\t\t\tif (currentVersion < 2) {\n\t\t\t\t\t\tlogger?.debug('Applying schema version 2: Partition-aware composite indexes');\n\n\t\t\t\t\t\t// Create new partition-aware indexes (CONCURRENTLY must be outside transaction)\n\t\t\t\t\t\tlogger?.debug('Creating partition-aware indexes...');\n\t\t\t\t\t\tawait client.query(`CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_${this.tableNameEntries}_path_status ON ${this.tableNameEntries}(path, status)`);\n\t\t\t\t\t\tawait client.query(`CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_${this.tableNameEntries}_path_updated ON ${this.tableNameEntries}(path, updated)`);\n\t\t\t\t\t\tawait client.query(`CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_${this.tableNameEntries}_path_status_updated ON ${this.tableNameEntries}(path, status, updated)`);\n\t\t\t\t\t\tawait client.query(`CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_${this.tableNameIdempotentKeys}_path_idempotent_id ON ${this.tableNameIdempotentKeys}(path, idempotent_id)`);\n\n\t\t\t\t\t\t// Now drop old indexes and record version\n\t\t\t\t\t\tawait client.query('BEGIN');\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Drop old indexes that are now redundant (these will fail gracefully if indexes don't exist)\n\t\t\t\t\t\t\tlogger?.debug('Dropping old single-column indexes...');\n\t\t\t\t\t\t\tawait client.query(`DROP INDEX IF EXISTS idx_${this.tableNameEntries}_status`);\n\t\t\t\t\t\t\tawait client.query(`DROP INDEX IF EXISTS idx_${this.tableNameEntries}_updated`);\n\t\t\t\t\t\t\tawait client.query(`DROP INDEX IF EXISTS idx_${this.tableNameIdempotentKeys}_idempotent_id`);\n\n\t\t\t\t\t\t\tawait client.query(`INSERT INTO ${this.tableNameSchemaVersion} (version, applied_at) VALUES (2, $1)`, [Date.now()]);\n\t\t\t\t\t\t\tawait client.query('COMMIT');\n\t\t\t\t\t\t\tlogger?.debug('Applied schema version 2');\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tawait client.query('ROLLBACK');\n\t\t\t\t\t\t\tthrow(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tlogger?.debug('Schema is up to date');\n\t\t\t\t} finally {\n\t\t\t\t\t// Always release the advisory lock\n\t\t\t\t\t// Note: Advisory locks are session-based and auto-release on disconnect,\n\t\t\t\t\t// but we explicitly unlock for clarity and to avoid holding locks longer than needed\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlogger?.debug('Releasing advisory lock');\n\t\t\t\t\t\tawait client.query('SELECT pg_advisory_unlock($1)', [lockId]);\n\t\t\t\t\t} catch (unlockError) {\n\t\t\t\t\t\t// Log but don't throw - the lock will be auto-released when connection closes\n\t\t\t\t\t\tlogger?.debug('Failed to explicitly release advisory lock (will auto-release on disconnect):', unlockError);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tclient.release();\n\t\t\t}\n\n\t\t\tlogger?.debug('Completed DB schema initialization for queue storage driver');\n\n\t\t\treturn(true);\n\t\t})();\n\n\t\tawait this.dbInitializationPromise;\n\n\t\treturn(pool);\n\t}\n\n\tprivate methodLogger(method: string): Logger | undefined {\n\t\treturn(MethodLogger(this.logger, {\n\t\t\tclass: 'KeetaAnchorQueueStorageDriverPostgres',\n\t\t\tfile: 'src/lib/queue/drivers/queue_postgres.ts',\n\t\t\tmethod: method,\n\t\t\tinstanceID: this.id\n\t\t}));\n\t}\n\n\tprivate async runWithRetry<T>(fn: () => Promise<T>): Promise<T> {\n\t\tconst logger = this.methodLogger('runWithRetry');\n\n\t\tlet lastError: unknown;\n\t\tfor (let retry = 0; retry < 16; retry++) {\n\t\t\tif (this.poolInternal === null) {\n\t\t\t\tthis.methodLogger('runWithRetry')?.debug('Aborting DB operation retries because the instance was destroyed');\n\n\t\t\t\tif (lastError !== undefined) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/only-throw-error\n\t\t\t\t\tthrow(lastError);\n\t\t\t\t}\n\t\t\t\tthrow(new Error('Aborting because the instance was destroyed'));\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\treturn(await fn());\n\t\t\t} catch (error: unknown) {\n\t\t\t\tlastError = error;\n\n\t\t\t\tif (error instanceof Error) {\n\t\t\t\t\tconst errorCode = 'code' in error ? error.code : null;\n\t\t\t\t\tif (errorCode === '40001' || errorCode === '40P01') {\n\t\t\t\t\t\tlogger?.debug('Serialization failure or deadlock detected');\n\n\t\t\t\t\t\t// Track serialization retries for instrumentation\n\t\t\t\t\t\tthis.serializationRetryCount++;\n\n\t\t\t\t\t\tconst minBackoff = 100;\n\t\t\t\t\t\tconst maxBackoff = 30_000;\n\t\t\t\t\t\tconst backoffIntervalSize = Math.min(maxBackoff - minBackoff, (retry + 50) ** 2);\n\t\t\t\t\t\tconst backoff = Math.round((Math.random() * backoffIntervalSize)) + minBackoff;\n\n\t\t\t\t\t\tthis.methodLogger('runWithRetry')?.debug(`Retrying DB operation in ${backoff}ms (retry #${retry}) from`, new Error().stack);\n\t\t\t\t\t\tawait asleep(backoff);\n\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthrow(error);\n\t\t\t}\n\t\t}\n\t\tthrow(lastError);\n\t}\n\n\tprivate async newDBConnection(): Promise<pg.Pool> {\n\t\tif (this.poolInternal === null) {\n\t\t\tthrow(new Error('Database connection is not available'));\n\t\t}\n\n\t\treturn(await this.runWithRetry(async () => {\n\t\t\tif (this.poolInternal === null) {\n\t\t\t\tthrow(new Error('Database connection is not available'));\n\t\t\t}\n\n\t\t\tthis.methodLogger('newDBConnection')?.debug('Getting DB pool');\n\t\t\tconst pool = await this.poolInternal();\n\n\t\t\treturn(await this.initializeDBConnection(pool));\n\t\t}));\n\t}\n\n\tprivate async dbTransaction<T>(className: string, fn: (client: pg.PoolClient, logger: Logger | undefined) => Promise<T>): Promise<T> {\n\t\tconst pool = await this.newDBConnection();\n\t\tconst logger = this.methodLogger(className);\n\n\t\tconst debugForceIndexScan = this.debugForceIndexScan;\n\n\t\tconst result = await this.runWithRetry(async function() {\n\t\t\tconst client = await pool.connect();\n\n\t\t\ttry {\n\t\t\t\tlogger?.debug('Starting DB transaction');\n\t\t\t\tawait client.query('BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE');\n\t\t\t\tlogger?.debug('DB transaction started');\n\n\t\t\t\tif (debugForceIndexScan) {\n\t\t\t\t\tawait client.query('SET LOCAL enable_seqscan TO off');\n\t\t\t\t}\n\n\t\t\t\tconst retval = await fn(client, logger);\n\n\t\t\t\tlogger?.debug('Committing DB transaction');\n\t\t\t\tawait client.query('COMMIT');\n\t\t\t\tlogger?.debug('DB transaction committed');\n\n\t\t\t\treturn(retval);\n\t\t\t} catch (error: unknown) {\n\t\t\t\ttry {\n\t\t\t\t\tlogger?.debug('Rolling back DB transaction due to error:', error);\n\t\t\t\t\tawait client.query('ROLLBACK');\n\t\t\t\t\tlogger?.debug('DB transaction rolled back');\n\t\t\t\t} catch {\n\t\t\t\t\tlogger?.debug('Error rolling back DB transaction !!');\n\t\t\t\t}\n\t\t\t\tthrow(error);\n\t\t\t} finally {\n\t\t\t\tclient.release();\n\t\t\t}\n\t\t});\n\n\t\treturn(result);\n\t}\n\n\tasync add(request: KeetaAnchorQueueRequest<QueueRequest>, info?: KeetaAnchorQueueEntryExtra): Promise<KeetaAnchorQueueRequestID> {\n\t\treturn(await this.dbTransaction('add', async (client, logger): Promise<KeetaAnchorQueueRequestID> => {\n\t\t\tlet entryID = ConvertStringToRequestID(info?.id);\n\t\t\tif (entryID) {\n\t\t\t\tconst existingEntry = await client.query<{ id: string }>(`SELECT id FROM ${this.tableNameEntries} WHERE id = $1 AND path = $2`, [entryID, this.pathStr]);\n\t\t\t\tif (existingEntry.rows.length > 0) {\n\t\t\t\t\tlogger?.debug(`Request with id ${String(entryID)} already exists, ignoring`);\n\t\t\t\t\treturn(entryID);\n\t\t\t\t}\n\n\t\t\t\tawait this.toctouDelay?.();\n\t\t\t}\n\n\t\t\tconst idempotentIDs = info?.idempotentKeys;\n\t\t\tif (idempotentIDs) {\n\t\t\t\tconst matchingIdempotentEntries = new Set<KeetaAnchorQueueRequestID>();\n\t\t\t\tfor (const idempotentID of idempotentIDs) {\n\t\t\t\t\tconst idempotentEntryExists = await client.query<IdempotentRow>(\n\t\t\t\t\t\t`SELECT idempotent_id FROM ${this.tableNameIdempotentKeys} WHERE idempotent_id = $1 AND path = $2`,\n\t\t\t\t\t\t[idempotentID, this.pathStr]\n\t\t\t\t\t);\n\t\t\t\t\tif (idempotentEntryExists.rows.length > 0) {\n\t\t\t\t\t\tmatchingIdempotentEntries.add(idempotentID);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (matchingIdempotentEntries.size !== 0) {\n\t\t\t\t\tthrow(new Errors.IdempotentExistsError('One or more idempotent entries already exist in the queue', matchingIdempotentEntries));\n\t\t\t\t}\n\n\t\t\t\tawait this.toctouDelay?.();\n\t\t\t}\n\n\t\t\tentryID ??= ConvertStringToRequestID(crypto.randomUUID());\n\n\t\t\tlogger?.debug(`Enqueuing request with id ${String(entryID)}`);\n\n\t\t\tconst currentTime = Date.now();\n\t\t\tconst requestJSON = JSON.stringify(request);\n\n\t\t\t/**\n\t\t\t * The status to use for the new entry\n\t\t\t */\n\t\t\tconst status = info?.status ?? 'pending';\n\n\t\t\tawait client.query(\n\t\t\t\t`INSERT INTO ${this.tableNameEntries} (id, path, request, output, last_error, status, created, updated, worker, failures)\n\t\t\t\t VALUES ($1, $2, $3, NULL, NULL, $4, $5, $6, NULL, 0)`,\n\t\t\t\t[entryID, this.pathStr, requestJSON, status, currentTime, currentTime]\n\t\t\t);\n\n\t\t\tif (idempotentIDs && idempotentIDs.size > 0) {\n\t\t\t\tfor (const idempotentID of idempotentIDs) {\n\t\t\t\t\tawait client.query(`INSERT INTO ${this.tableNameIdempotentKeys} (entry_id, path, idempotent_id) VALUES ($1, $2, $3)`, [entryID, this.pathStr, idempotentID]);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn(entryID);\n\t\t}));\n\t}\n\n\tasync setStatus(id: KeetaAnchorQueueRequestID, status: KeetaAnchorQueueStatus, ancillary?: KeetaAnchorQueueEntryAncillaryData<QueueResult>): Promise<void> {\n\t\tconst { oldStatus } = ancillary ?? {};\n\n\t\treturn(await this.dbTransaction('setStatus', async (client, logger): Promise<void> => {\n\t\t\tconst existingEntry = await client.query<{ status: KeetaAnchorQueueStatus; failures: number; last_error: string | null; output: string | null }>(`SELECT status, failures, last_error, output FROM ${this.tableNameEntries} WHERE id = $1 AND path = $2 FOR UPDATE`, [id, this.pathStr]);\n\t\t\tif (existingEntry.rows.length === 0) {\n\t\t\t\tthrow(new Error(`Request with ID ${String(id)} not found`));\n\t\t\t}\n\n\t\t\tawait this.toctouDelay?.();\n\n\t\t\tconst currentEntry = existingEntry.rows[0];\n\t\t\tif (!currentEntry) {\n\t\t\t\tthrow(new Error(`Request with ID ${String(id)} not found`));\n\t\t\t}\n\n\t\t\tconst newEntry = ManageStatusUpdates<QueueResult>(id, currentEntry, status, ancillary, logger);\n\t\t\tconst currentTime = newEntry.updated.getTime();\n\t\t\tconst workerValue = newEntry.worker;\n\t\t\tconst newFailures = newEntry.failures ?? currentEntry.failures;\n\t\t\tconst newLastError = newEntry.lastError !== undefined ? newEntry.lastError : currentEntry.last_error;\n\t\t\tconst newOutput = newEntry.output !== undefined ? JSON.stringify(newEntry.output) : currentEntry.output;\n\n\t\t\tlet updateQuery: string;\n\t\t\tlet updateParams: (KeetaAnchorQueueRequestID | string | number | null)[];\n\n\t\t\tif (oldStatus) {\n\t\t\t\tupdateQuery = `UPDATE ${this.tableNameEntries}\n\t\t\t\t SET status = $1, updated = $2, worker = $3, failures = $4, last_error = $5, output = $6\n\t\t\t\t WHERE id = $7 AND path = $8 AND status = $9`;\n\t\t\t\tupdateParams = [status, currentTime, workerValue, newFailures, newLastError, newOutput, id, this.pathStr, oldStatus];\n\t\t\t} else {\n\t\t\t\tupdateQuery = `UPDATE ${this.tableNameEntries}\n\t\t\t\t SET status = $1, updated = $2, worker = $3, failures = $4, last_error = $5, output = $6\n\t\t\t\t WHERE id = $7 AND path = $8`;\n\t\t\t\tupdateParams = [status, currentTime, workerValue, newFailures, newLastError, newOutput, id, this.pathStr];\n\t\t\t}\n\n\t\t\tconst result = await client.query(updateQuery, updateParams);\n\n\t\t\tawait this.toctouDelay?.();\n\n\t\t\tif (oldStatus && result.rowCount === 0) {\n\t\t\t\tconst currentEntry = await client.query<{ status: KeetaAnchorQueueStatus }>(`SELECT status FROM ${this.tableNameEntries} WHERE id = $1 AND path = $2`, [id, this.pathStr]);\n\t\t\t\tconst currentStatus = currentEntry.rows[0]?.status;\n\t\t\t\tif (currentEntry.rows.length > 0) {\n\t\t\t\t\tif (currentStatus === undefined) {\n\t\t\t\t\t\tthrow(new Error(`internal error: could not retrieve current status for request with ID ${String(id)}`));\n\t\t\t\t\t}\n\t\t\t\t\tthrow(new Errors.IncorrectStateAssertedError(id, oldStatus, currentStatus));\n\t\t\t\t} else {\n\t\t\t\t\tthrow(new Error(`Request with ID ${String(id)} not found`));\n\t\t\t\t}\n\t\t\t}\n\t\t}));\n\t}\n\n\tasync get(id: KeetaAnchorQueueRequestID): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult> | null> {\n\t\treturn(await this.dbTransaction('get', async (client): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult> | null> => {\n\t\t\tconst row = await client.query<QueueEntryRow>(\n\t\t\t\t`SELECT id, request, output, last_error, status, created, updated, worker, failures\n\t\t\t\t FROM ${this.tableNameEntries} WHERE id = $1 AND path = $2`,\n\t\t\t\t[id, this.pathStr]\n\t\t\t);\n\n\t\t\tif (row.rows.length === 0) {\n\t\t\t\treturn(null);\n\t\t\t}\n\n\t\t\tconst entry = row.rows[0];\n\t\t\tif (!entry) {\n\t\t\t\treturn(null);\n\t\t\t}\n\n\t\t\tconst idempotentRows = await client.query<IdempotentRow>(\n\t\t\t\t`SELECT idempotent_id FROM ${this.tableNameIdempotentKeys} WHERE entry_id = $1 AND path = $2`,\n\t\t\t\t[id, this.pathStr]\n\t\t\t);\n\n\t\t\tconst idempotentKeys = idempotentRows.rows.length > 0\n\t\t\t\t? new Set(idempotentRows.rows.map(function(idempotentRow: IdempotentRow) {\n\t\t\t\t\treturn(ConvertStringToRequestID(idempotentRow.idempotent_id));\n\t\t\t\t}))\n\t\t\t\t: undefined;\n\n\t\t\treturn({\n\t\t\t\tid: ConvertStringToRequestID(entry.id),\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\trequest: JSON.parse(entry.request) as QueueRequest,\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\toutput: entry.output ? JSON.parse(entry.output) as QueueResult : null,\n\t\t\t\tlastError: entry.last_error,\n\t\t\t\tstatus: entry.status,\n\t\t\t\tcreated: new Date(Number(entry.created)),\n\t\t\t\tupdated: new Date(Number(entry.updated)),\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\tworker: entry.worker as unknown as KeetaAnchorQueueWorkerID | null,\n\t\t\t\tfailures: entry.failures,\n\t\t\t\tidempotentKeys: idempotentKeys\n\t\t\t});\n\t\t}));\n\t}\n\n\tasync query(filter?: KeetaAnchorQueueFilter): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult>[]> {\n\t\treturn(await this.dbTransaction('query', async (client, logger): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult>[]> => {\n\t\t\tlogger?.debug(`Querying queue with id ${this.id} with filter:`, filter);\n\n\t\t\tconst conditions: string[] = [];\n\t\t\tconst params: (string | number)[] = [];\n\t\t\tlet paramIndex = 1;\n\n\t\t\tconditions.push(`path = $${paramIndex++}`);\n\t\t\tparams.push(this.pathStr);\n\n\t\t\tif (filter?.status) {\n\t\t\t\tconditions.push(`status = $${paramIndex++}`);\n\t\t\t\tparams.push(filter.status);\n\t\t\t}\n\n\t\t\tif (filter?.updatedBefore) {\n\t\t\t\tconditions.push(`updated < $${paramIndex++}`);\n\t\t\t\tparams.push(filter.updatedBefore.getTime());\n\t\t\t}\n\n\t\t\tlet query = `SELECT id, request, output, last_error, status, created, updated, worker, failures FROM ${this.tableNameEntries}`;\n\n\t\t\tif (conditions.length > 0) {\n\t\t\t\tquery += ' WHERE ' + conditions.join(' AND ');\n\t\t\t}\n\n\t\t\t// Use random ordering to prevent multiple workers from contending for the same rows\n\t\t\t// This spreads the load when multiple workers query simultaneously\n\t\t\tquery += ' ORDER BY RANDOM()';\n\n\t\t\tif (filter?.limit !== undefined) {\n\t\t\t\tquery += ` LIMIT $${paramIndex++}`;\n\t\t\t\tparams.push(filter.limit);\n\t\t\t}\n\n\t\t\tconst rows = await client.query<QueueEntryRow>(query, params);\n\n\t\t\tconst entries: KeetaAnchorQueueEntry<QueueRequest, QueueResult>[] = [];\n\n\t\t\tfor (const row of rows.rows) {\n\t\t\t\tconst idempotentRows = await client.query<IdempotentRow>(\n\t\t\t\t\t`SELECT idempotent_id FROM ${this.tableNameIdempotentKeys} WHERE entry_id = $1 AND path = $2`,\n\t\t\t\t\t[row.id, this.pathStr]\n\t\t\t\t);\n\n\t\t\t\tconst idempotentKeys = idempotentRows.rows.length > 0\n\t\t\t\t\t? new Set(idempotentRows.rows.map(function(idempotentRow: IdempotentRow) {\n\t\t\t\t\t\treturn(ConvertStringToRequestID(idempotentRow.idempotent_id));\n\t\t\t\t\t}))\n\t\t\t\t\t: undefined;\n\n\t\t\t\tentries.push({\n\t\t\t\t\tid: ConvertStringToRequestID(row.id),\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\trequest: JSON.parse(row.request) as QueueRequest,\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\toutput: row.output ? JSON.parse(row.output) as QueueResult : null,\n\t\t\t\t\tlastError: row.last_error,\n\t\t\t\t\tstatus: row.status,\n\t\t\t\t\tcreated: new Date(Number(row.created)),\n\t\t\t\t\tupdated: new Date(Number(row.updated)),\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\tworker: row.worker as unknown as KeetaAnchorQueueWorkerID | null,\n\t\t\t\t\tfailures: row.failures,\n\t\t\t\t\tidempotentKeys: idempotentKeys\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlogger?.debug(`Queried queue with id ${this.id} with filter:`, filter, '-- found', entries.length, 'entries');\n\n\t\t\treturn(entries);\n\t\t}));\n\t}\n\n\tasync partition(path: string) : Promise<KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult>> {\n\t\tthis.methodLogger('partition')?.debug(`Creating partitioned queue storage driver for path: ${path}`);\n\n\t\tif (this.poolInternal === null) {\n\t\t\tthrow(new Error('Asked to partition but the instance has been destroyed'));\n\t\t}\n\n\t\tconst retval = new KeetaAnchorQueueStorageDriverPostgres<QueueRequest, QueueResult>({\n\t\t\tid: `${this.id}::${path}`,\n\t\t\tlogger: this.logger,\n\t\t\tpool: this.poolInternal,\n\t\t\tpath: [...this.path, path],\n\t\t\ttablePrefix: this.tablePrefix\n\t\t});\n\n\t\treturn(retval);\n\t}\n\n\tasync destroy(): Promise<void> {\n\t\tthis.methodLogger('destroy')?.debug('Destroying instance');\n\n\t\tthis.poolInternal = null;\n\t}\n\n\tasync [Symbol.asyncDispose](): Promise<void> {\n\t\treturn(await this.destroy());\n\t}\n\n\t/** @internal */\n\t_Testing(key: string): {\n\t\tsetToctouDelay(delay: number): void;\n\t\tunsetToctouDelay(): void;\n\t\tgetSerializationRetryCount(): number;\n\t\tresetSerializationRetryCount(): void;\n\t\tenableDebugForceIndexScan(): void;\n\t\tdisableDebugForceIndexScan(): void;\n\t} {\n\t\tif (key !== 'bc81abf8-e43b-490b-b486-744fb49a5082') {\n\t\t\tthrow(new Error('This is a testing only method'));\n\t\t}\n\n\t\treturn({\n\t\t\tsetToctouDelay: (delay: number): void => {\n\t\t\t\tthis.toctouDelay = async (): Promise<void> => {\n\t\t\t\t\treturn(await asleep(delay));\n\t\t\t\t};\n\t\t\t},\n\t\t\tunsetToctouDelay: (): void => {\n\t\t\t\tthis.toctouDelay = undefined;\n\t\t\t},\n\t\t\tgetSerializationRetryCount: (): number => {\n\t\t\t\treturn(this.serializationRetryCount);\n\t\t\t},\n\t\t\tresetSerializationRetryCount: (): void => {\n\t\t\t\tthis.serializationRetryCount = 0;\n\t\t\t},\n\t\t\tenableDebugForceIndexScan: (): void => {\n\t\t\t\tthis.debugForceIndexScan = true;\n\t\t\t},\n\t\t\tdisableDebugForceIndexScan: (): void => {\n\t\t\t\tthis.debugForceIndexScan = false;\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
1
+ {"version":3,"file":"queue_postgres.js","sourceRoot":"","sources":["../../../../src/lib/queue/drivers/queue_postgres.ts"],"names":[],"mappings":"AAcA,OAAO,EACN,YAAY,EACZ,mBAAmB,EACnB,wBAAwB,EACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAqC/C,MAAM,CAAC,OAAO,OAAO,qCAAqC;IACxC,MAAM,CAAqB;IACpC,YAAY,GAAoC,IAAI,CAAC;IACrD,WAAW,CAAqB;IAChC,gBAAgB,CAAS;IACzB,sBAA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IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QAC1B,OAAM,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9B,CAAC;IAED,gBAAgB;IAChB,QAAQ,CAAC,GAAW;QAQnB,IAAI,GAAG,KAAK,sCAAsC,EAAE,CAAC;YACpD,MAAK,CAAC,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC,CAAC;QACnD,CAAC;QAED,OAAM,CAAC;YACN,cAAc,EAAE,CAAC,KAAa,EAAQ,EAAE;gBACvC,IAAI,CAAC,WAAW,GAAG,KAAK,IAAmB,EAAE;oBAC5C,OAAM,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC7B,CAAC,CAAC;YACH,CAAC;YACD,gBAAgB,EAAE,GAAS,EAAE;gBAC5B,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;YAC9B,CAAC;YACD,0BAA0B,EAAE,GAAW,EAAE;gBACxC,OAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;YACtC,CAAC;YACD,4BAA4B,EAAE,GAAS,EAAE;gBACxC,IAAI,CAAC,uBAAuB,GAAG,CAAC,CAAC;YAClC,CAAC;YACD,yBAAyB,EAAE,GAAS,EAAE;gBACrC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;YACjC,CAAC;YACD,0BAA0B,EAAE,GAAS,EAAE;gBACtC,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC;YAClC,CAAC;SACD,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["// cspell:ignore seqscan\n\nimport type {\n\tKeetaAnchorQueueStorageDriver,\n\tKeetaAnchorQueueStorageDriverConstructor,\n\tKeetaAnchorQueueRequest,\n\tKeetaAnchorQueueRequestID,\n\tKeetaAnchorQueueEntry,\n\tKeetaAnchorQueueEntryExtra,\n\tKeetaAnchorQueueEntryAncillaryData,\n\tKeetaAnchorQueueStatus,\n\tKeetaAnchorQueueFilter,\n\tKeetaAnchorQueueWorkerID\n} from '../index.ts';\nimport {\n\tMethodLogger,\n\tManageStatusUpdates,\n\tConvertStringToRequestID\n} from '../internal.js';\nimport { Errors } from '../common.js';\n\nimport { asleep } from '../../utils/asleep.js';\n\nimport type { Logger } from '../../log/index.ts';\nimport type { JSONSerializable } from '../../utils/json.js';\n\nimport type * as pg from 'pg';\n\ntype QueueEntryRow = {\n\tid: string;\n\trequest: string;\n\toutput: string | null;\n\tlast_error: string | null;\n\tstatus: KeetaAnchorQueueStatus;\n\tcreated: Date;\n\tupdated: Date;\n\tworker: number | null;\n\tfailures: number;\n};\n\ntype IdempotentRow = {\n\tidempotent_id: string;\n};\n\ntype KeetaAnchorQueueStorageDriverPostgresOptions = {\n\t/**\n\t * Function that returns a Postgres connection pool.\n\t */\n\tpool: () => Promise<pg.Pool>;\n\n\t/**\n\t * The prefix to use for the database tables. Defaults to 'queue',\n\t * resulting in table names 'queue_entries', 'queue_idempotent_keys',\n\t * and `queue_schema_version`.\n\t */\n\ttablePrefix?: string | undefined;\n};\n\nexport default class KeetaAnchorQueueStorageDriverPostgres<QueueRequest extends JSONSerializable = JSONSerializable, QueueResult extends JSONSerializable = JSONSerializable> implements KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult> {\n\tprivate readonly logger: Logger | undefined;\n\tprivate poolInternal: (() => Promise<pg.Pool>) | null = null;\n\tprivate tablePrefix: string | undefined;\n\tprivate tableNameEntries: string;\n\tprivate tableNameSchemaVersion: string;\n\tprivate tableNameIdempotentKeys: string;\n\tprivate dbInitializationPromise: Promise<boolean> | null = null;\n\tprivate serializationRetryCount = 0;\n\tprivate debugForceIndexScan = false;\n\n\treadonly name = 'KeetaAnchorQueueStorageDriverPostgres';\n\treadonly id: string;\n\treadonly path: string[] = [];\n\tprivate readonly pathStr: string;\n\tprivate toctouDelay: (() => Promise<void>) | undefined = undefined;\n\n\tconstructor(options: NonNullable<ConstructorParameters<KeetaAnchorQueueStorageDriverConstructor<QueueRequest, QueueResult>>[0]> & KeetaAnchorQueueStorageDriverPostgresOptions) {\n\t\tthis.id = options?.id ?? crypto.randomUUID();\n\t\tthis.logger = options?.logger;\n\t\tthis.tablePrefix = options?.tablePrefix;\n\t\tthis.poolInternal = options.pool;\n\t\tthis.path = options.path ?? [];\n\t\tthis.pathStr = ['root', ...this.path].join('.');\n\t\tObject.freeze(this.path);\n\n\t\tthis.tableNameEntries = `${this.tablePrefix ?? 'queue'}_entries`;\n\t\tthis.tableNameIdempotentKeys = `${this.tablePrefix ?? 'queue'}_idempotent_keys`;\n\t\tthis.tableNameSchemaVersion = `${this.tablePrefix ?? 'queue'}_schema_version`;\n\n\t\tthis.methodLogger('new')?.debug('Initialized Postgres queue storage driver');\n\t}\n\n\tprivate async initializeDBConnection(pool: pg.Pool): Promise<pg.Pool> {\n\t\tconst logger = this.methodLogger('initializeDBConnection');\n\n\t\tif (this.dbInitializationPromise !== null) {\n\t\t\tlogger?.debug('DB schema initialization already in progress or completed, waiting for it to finish');\n\n\t\t\tawait this.dbInitializationPromise;\n\t\t\treturn(pool);\n\t\t}\n\n\t\tthis.dbInitializationPromise = (async () => {\n\t\t\tlogger?.debug('Initializing DB schema for queue storage driver on tables', [this.tableNameEntries, this.tableNameIdempotentKeys]);\n\n\t\t\tconst client = await pool.connect();\n\t\t\ttry {\n\t\t\t\t/*\n\t\t\t\t * Random lock key (32-bit integer), to ensure\n\t\t\t\t * that multiple instances of this driver\n\t\t\t\t * (potentially across different\n\t\t\t\t * instances/process) will run the migration\n\t\t\t\t * sequentially to avoid multiple concurrent\n\t\t\t\t * migrations from competing with each other\n\t\t\t\t * and causing delays\n\t\t\t\t */\n\t\t\t\tconst lockId = 0x24995E48;\n\t\t\t\tlogger?.debug('Acquiring advisory lock for schema migration');\n\t\t\t\tawait client.query('SELECT pg_advisory_lock($1)', [lockId]);\n\n\t\t\t\ttry {\n\t\t\t\t\t// Create schema version table if it doesn't exist\n\t\t\t\t\tawait client.query(`\n\t\t\t\t\t\tCREATE TABLE IF NOT EXISTS ${this.tableNameSchemaVersion} (\n\t\t\t\t\t\t\tversion INTEGER NOT NULL,\n\t\t\t\t\t\t\tapplied_at BIGINT NOT NULL,\n\t\t\t\t\t\t\tPRIMARY KEY (version)\n\t\t\t\t\t\t)`);\n\n\t\t\t\t\t// Check current schema version\n\t\t\t\t\tconst versionResult = await client.query<{ version: number }>(`SELECT MAX(version) as version FROM ${this.tableNameSchemaVersion}`);\n\t\t\t\t\tconst currentVersion = versionResult.rows[0]?.version ?? 0;\n\n\t\t\t\t\tlogger?.debug(`Current queue schema version: ${currentVersion}`);\n\n\t\t\t\t\t// Version 1: Initial schema\n\t\t\t\t\tif (currentVersion < 1) {\n\t\t\t\t\t\tlogger?.debug('Applying schema version 1: Initial tables and indexes');\n\n\t\t\t\t\t\tawait client.query('BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED');\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait client.query(`\n\t\t\t\t\t\t\t\tCREATE TABLE IF NOT EXISTS ${this.tableNameEntries} (\n\t\t\t\t\t\t\t\t\tid TEXT NOT NULL,\n\t\t\t\t\t\t\t\t\tpath TEXT NOT NULL,\n\t\t\t\t\t\t\t\t\trequest TEXT NOT NULL,\n\t\t\t\t\t\t\t\t\toutput TEXT,\n\t\t\t\t\t\t\t\t\tlast_error TEXT,\n\t\t\t\t\t\t\t\t\tstatus TEXT NOT NULL,\n\t\t\t\t\t\t\t\t\tcreated BIGINT NOT NULL,\n\t\t\t\t\t\t\t\t\tupdated BIGINT NOT NULL,\n\t\t\t\t\t\t\t\t\tworker BIGINT,\n\t\t\t\t\t\t\t\t\tfailures INTEGER NOT NULL DEFAULT 0,\n\t\t\t\t\t\t\t\t\tPRIMARY KEY (id, path)\n\t\t\t\t\t\t\t\t)`);\n\n\t\t\t\t\t\t\tawait client.query(`\n\t\t\t\t\t\t\t\tCREATE TABLE IF NOT EXISTS ${this.tableNameIdempotentKeys} (\n\t\t\t\t\t\t\t\t\tentry_id TEXT NOT NULL,\n\t\t\t\t\t\t\t\t\tidempotent_id TEXT NOT NULL,\n\t\t\t\t\t\t\t\t\tpath TEXT NOT NULL,\n\t\t\t\t\t\t\t\t\tUNIQUE (idempotent_id, path),\n\t\t\t\t\t\t\t\t\tPRIMARY KEY (entry_id, idempotent_id, path),\n\t\t\t\t\t\t\t\t\tFOREIGN KEY (entry_id, path) REFERENCES ${this.tableNameEntries}(id, path)\n\t\t\t\t\t\t\t\t)`);\n\n\t\t\t\t\t\t\t// Old single-column indexes (for pre-version-2 schemas)\n\t\t\t\t\t\t\tawait client.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableNameEntries}_status ON ${this.tableNameEntries}(status)`);\n\t\t\t\t\t\t\tawait client.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableNameEntries}_updated ON ${this.tableNameEntries}(updated)`);\n\t\t\t\t\t\t\tawait client.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableNameIdempotentKeys}_idempotent_id ON ${this.tableNameIdempotentKeys}(idempotent_id)`);\n\n\t\t\t\t\t\t\tawait client.query(`INSERT INTO ${this.tableNameSchemaVersion} (version, applied_at) VALUES (1, $1)`, [Date.now()]);\n\t\t\t\t\t\t\tawait client.query('COMMIT');\n\t\t\t\t\t\t\tlogger?.debug('Applied schema version 1');\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tawait client.query('ROLLBACK');\n\t\t\t\t\t\t\tthrow(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Version 2: Partition-aware composite indexes\n\t\t\t\t\tif (currentVersion < 2) {\n\t\t\t\t\t\tlogger?.debug('Applying schema version 2: Partition-aware composite indexes');\n\n\t\t\t\t\t\t// Now drop old indexes and record version\n\t\t\t\t\t\tawait client.query('BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED');\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Create new partition-aware indexes\n\t\t\t\t\t\t\tlogger?.debug('Creating partition-aware indexes...');\n\n\t\t\t\t\t\t\tawait client.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableNameEntries}_path_status ON ${this.tableNameEntries}(path, status)`);\n\t\t\t\t\t\t\tawait client.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableNameEntries}_path_updated ON ${this.tableNameEntries}(path, updated)`);\n\t\t\t\t\t\t\tawait client.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableNameEntries}_path_status_updated ON ${this.tableNameEntries}(path, status, updated)`);\n\t\t\t\t\t\t\tawait client.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableNameIdempotentKeys}_path_idempotent_id ON ${this.tableNameIdempotentKeys}(path, idempotent_id)`);\n\n\t\t\t\t\t\t\t// Drop old indexes that are now redundant (these will fail gracefully if indexes don't exist)\n\t\t\t\t\t\t\tlogger?.debug('Dropping old single-column indexes...');\n\t\t\t\t\t\t\tawait client.query(`DROP INDEX IF EXISTS idx_${this.tableNameEntries}_status`);\n\t\t\t\t\t\t\tawait client.query(`DROP INDEX IF EXISTS idx_${this.tableNameEntries}_updated`);\n\t\t\t\t\t\t\tawait client.query(`DROP INDEX IF EXISTS idx_${this.tableNameIdempotentKeys}_idempotent_id`);\n\n\t\t\t\t\t\t\tawait client.query(`INSERT INTO ${this.tableNameSchemaVersion} (version, applied_at) VALUES (2, $1)`, [Date.now()]);\n\t\t\t\t\t\t\tawait client.query('COMMIT');\n\t\t\t\t\t\t\tlogger?.debug('Applied schema version 2');\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tawait client.query('ROLLBACK');\n\t\t\t\t\t\t\tthrow(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tlogger?.debug('Schema is up to date');\n\t\t\t\t} finally {\n\t\t\t\t\t// Always release the advisory lock\n\t\t\t\t\t// Note: Advisory locks are session-based and auto-release on disconnect,\n\t\t\t\t\t// but we explicitly unlock for clarity and to avoid holding locks longer than needed\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlogger?.debug('Releasing advisory lock');\n\t\t\t\t\t\tawait client.query('SELECT pg_advisory_unlock($1)', [lockId]);\n\t\t\t\t\t} catch (unlockError) {\n\t\t\t\t\t\t// Log but don't throw - the lock will be auto-released when connection closes\n\t\t\t\t\t\tlogger?.debug('Failed to explicitly release advisory lock (will auto-release on disconnect):', unlockError);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tclient.release();\n\t\t\t}\n\n\t\t\tlogger?.debug('Completed DB schema initialization for queue storage driver');\n\n\t\t\treturn(true);\n\t\t})();\n\n\t\tawait this.dbInitializationPromise;\n\n\t\treturn(pool);\n\t}\n\n\tprivate methodLogger(method: string): Logger | undefined {\n\t\treturn(MethodLogger(this.logger, {\n\t\t\tclass: 'KeetaAnchorQueueStorageDriverPostgres',\n\t\t\tfile: 'src/lib/queue/drivers/queue_postgres.ts',\n\t\t\tmethod: method,\n\t\t\tinstanceID: this.id\n\t\t}));\n\t}\n\n\tprivate async runWithRetry<T>(fn: () => Promise<T>): Promise<T> {\n\t\tconst logger = this.methodLogger('runWithRetry');\n\n\t\tlet lastError: unknown;\n\t\tfor (let retry = 0; retry < 16; retry++) {\n\t\t\tif (this.poolInternal === null) {\n\t\t\t\tthis.methodLogger('runWithRetry')?.debug('Aborting DB operation retries because the instance was destroyed');\n\n\t\t\t\tif (lastError !== undefined) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/only-throw-error\n\t\t\t\t\tthrow(lastError);\n\t\t\t\t}\n\t\t\t\tthrow(new Error('Aborting because the instance was destroyed'));\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\treturn(await fn());\n\t\t\t} catch (error: unknown) {\n\t\t\t\tlastError = error;\n\n\t\t\t\tlet detectedRetryableError = false;\n\t\t\t\tif (error instanceof Error) {\n\t\t\t\t\tconst errorCode = 'code' in error ? error.code : null;\n\t\t\t\t\tif (errorCode === '40001' || errorCode === '40P01') {\n\t\t\t\t\t\t// Track serialization retries for instrumentation\n\t\t\t\t\t\tthis.serializationRetryCount++;\n\n\t\t\t\t\t\tdetectedRetryableError = true;\n\t\t\t\t\t\tlogger?.debug('Detected retryable error with code', errorCode);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (detectedRetryableError) {\n\t\t\t\t\tconst minBackoff = 100;\n\t\t\t\t\tconst maxBackoff = 30_000;\n\t\t\t\t\tconst backoffIntervalSize = Math.min(maxBackoff - minBackoff, (retry + 50) ** 2);\n\t\t\t\t\tconst backoff = Math.round((Math.random() * backoffIntervalSize)) + minBackoff;\n\n\t\t\t\t\tthis.methodLogger('runWithRetry')?.debug(`Retrying DB operation in ${backoff}ms (retry #${retry}) from`, new Error().stack);\n\t\t\t\t\tawait asleep(backoff);\n\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tthrow(error);\n\t\t\t}\n\t\t}\n\t\tthrow(lastError);\n\t}\n\n\tprivate async newDBConnection(): Promise<pg.Pool> {\n\t\tif (this.poolInternal === null) {\n\t\t\tthrow(new Error('Database connection is not available'));\n\t\t}\n\n\t\treturn(await this.runWithRetry(async () => {\n\t\t\tif (this.poolInternal === null) {\n\t\t\t\tthrow(new Error('Database connection is not available'));\n\t\t\t}\n\n\t\t\tthis.methodLogger('newDBConnection')?.debug('Getting DB pool');\n\t\t\tconst pool = await this.poolInternal();\n\n\t\t\treturn(await this.initializeDBConnection(pool));\n\t\t}));\n\t}\n\n\tprivate async dbTransaction<T>(className: string, fn: (client: pg.PoolClient, logger: Logger | undefined) => Promise<T>): Promise<T> {\n\t\tconst pool = await this.newDBConnection();\n\t\tconst logger = this.methodLogger(className);\n\n\t\tconst debugForceIndexScan = this.debugForceIndexScan;\n\n\t\tconst result = await this.runWithRetry(async function() {\n\t\t\tconst client = await pool.connect();\n\n\t\t\ttry {\n\t\t\t\tlogger?.debug('Starting DB transaction');\n\t\t\t\tawait client.query('BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED');\n\t\t\t\tlogger?.debug('DB transaction started');\n\n\t\t\t\tif (debugForceIndexScan) {\n\t\t\t\t\tawait client.query('SET LOCAL enable_seqscan TO off');\n\t\t\t\t}\n\n\t\t\t\tconst retval = await fn(client, logger);\n\n\t\t\t\tlogger?.debug('Committing DB transaction');\n\t\t\t\tawait client.query('COMMIT');\n\t\t\t\tlogger?.debug('DB transaction committed');\n\n\t\t\t\treturn(retval);\n\t\t\t} catch (error: unknown) {\n\t\t\t\ttry {\n\t\t\t\t\tlogger?.debug('Rolling back DB transaction due to error:', error);\n\t\t\t\t\tawait client.query('ROLLBACK');\n\t\t\t\t\tlogger?.debug('DB transaction rolled back');\n\t\t\t\t} catch {\n\t\t\t\t\tlogger?.debug('Error rolling back DB transaction !!');\n\t\t\t\t}\n\t\t\t\tthrow(error);\n\t\t\t} finally {\n\t\t\t\tclient.release();\n\t\t\t}\n\t\t});\n\n\t\treturn(result);\n\t}\n\n\tasync add(request: KeetaAnchorQueueRequest<QueueRequest>, info?: KeetaAnchorQueueEntryExtra): Promise<KeetaAnchorQueueRequestID> {\n\t\treturn(await this.dbTransaction('add', async (client, logger): Promise<KeetaAnchorQueueRequestID> => {\n\t\t\tlet entryID = ConvertStringToRequestID(info?.id);\n\t\t\tentryID ??= ConvertStringToRequestID(crypto.randomUUID());\n\n\t\t\tlogger?.debug(`Enqueuing request with id ${String(entryID)}`);\n\n\t\t\tconst currentTime = Date.now();\n\t\t\tconst requestJSON = JSON.stringify(request);\n\n\t\t\t/**\n\t\t\t * The status to use for the new entry\n\t\t\t */\n\t\t\tconst status = info?.status ?? 'pending';\n\n\n\t\t\tconst insertedEntry = await client.query<{ id: string }>(`\n\t\t\t\tINSERT INTO ${this.tableNameEntries} (\n\t\t\t\t\tid, path, request, output, last_error, status,\n\t\t\t\t\tcreated, updated, worker, failures\n\t\t\t\t) VALUES ($1, $2, $3, NULL, NULL, $4, $5, $6, NULL, 0)\n\t\t\t\tON CONFLICT (id, path) DO NOTHING\n\t\t\t\tRETURNING id`,\n\t\t\t[entryID, this.pathStr, requestJSON, status, currentTime, currentTime]);\n\n\t\t\tif (insertedEntry.rows.length === 0) {\n\t\t\t\tlogger?.debug(`Request with id ${String(entryID)} already exists, ignoring`);\n\t\t\t\treturn(entryID);\n\t\t\t}\n\n\t\t\tawait this.toctouDelay?.();\n\n\t\t\tconst idempotentIDs = info?.idempotentKeys;\n\t\t\tif (idempotentIDs && idempotentIDs.size > 0) {\n\t\t\t\tconst keys = Array.from(idempotentIDs);\n\n\t\t\t\tconst insertedKeys = await client.query<{ idempotent_id: string }>(`\n\t\t\t\t\tINSERT INTO ${this.tableNameIdempotentKeys}(entry_id, path, idempotent_id)\n\t\t\t\t\tSELECT $1, $2, unnest($3::text[])\n\t\t\t\t\tON CONFLICT (idempotent_id, path) DO NOTHING\n\t\t\t\t\tRETURNING idempotent_id`,\n\t\t\t\t[entryID, this.pathStr, keys]);\n\n\t\t\t\tconst foundKeySet = new Set(keys);\n\t\t\t\tfor (const row of insertedKeys.rows) {\n\t\t\t\t\tfoundKeySet.delete(ConvertStringToRequestID(row.idempotent_id));\n\t\t\t\t}\n\n\t\t\t\tif (insertedKeys.rows.length !== keys.length) {\n\t\t\t\t\tthrow(new Errors.IdempotentExistsError('One or more idempotent entries already exist in the queue', foundKeySet));\n\t\t\t\t}\n\n\t\t\t\tawait this.toctouDelay?.();\n\t\t\t}\n\n\t\t\treturn(entryID);\n\t\t}));\n\t}\n\n\tasync setStatus(id: KeetaAnchorQueueRequestID, status: KeetaAnchorQueueStatus, ancillary?: KeetaAnchorQueueEntryAncillaryData<QueueResult>): Promise<void> {\n\t\tconst { oldStatus } = ancillary ?? {};\n\n\t\treturn(await this.dbTransaction('setStatus', async (client, logger): Promise<void> => {\n\t\t\tconst existingEntry = await client.query<{ status: KeetaAnchorQueueStatus; failures: number; last_error: string | null; output: string | null }>(`SELECT status, failures, last_error, output FROM ${this.tableNameEntries} WHERE id = $1 AND path = $2 FOR UPDATE`, [id, this.pathStr]);\n\t\t\tif (existingEntry.rows.length === 0) {\n\t\t\t\tthrow(new Error(`Request with ID ${String(id)} not found`));\n\t\t\t}\n\n\t\t\tawait this.toctouDelay?.();\n\n\t\t\tconst currentEntry = existingEntry.rows[0];\n\t\t\tif (!currentEntry) {\n\t\t\t\tthrow(new Error(`Request with ID ${String(id)} not found`));\n\t\t\t}\n\n\t\t\tconst newEntry = ManageStatusUpdates<QueueResult>(id, currentEntry, status, ancillary, logger);\n\t\t\tconst currentTime = newEntry.updated.getTime();\n\t\t\tconst workerValue = newEntry.worker;\n\t\t\tconst newFailures = newEntry.failures ?? currentEntry.failures;\n\t\t\tconst newLastError = newEntry.lastError !== undefined ? newEntry.lastError : currentEntry.last_error;\n\t\t\tconst newOutput = newEntry.output !== undefined ? JSON.stringify(newEntry.output) : currentEntry.output;\n\n\t\t\tlet updateQuery: string;\n\t\t\tlet updateParams: (KeetaAnchorQueueRequestID | string | number | null)[];\n\n\t\t\tif (oldStatus) {\n\t\t\t\tupdateQuery = `UPDATE ${this.tableNameEntries}\n\t\t\t\t SET status = $1, updated = $2, worker = $3, failures = $4, last_error = $5, output = $6\n\t\t\t\t WHERE id = $7 AND path = $8 AND status = $9`;\n\t\t\t\tupdateParams = [status, currentTime, workerValue, newFailures, newLastError, newOutput, id, this.pathStr, oldStatus];\n\t\t\t} else {\n\t\t\t\tupdateQuery = `UPDATE ${this.tableNameEntries}\n\t\t\t\t SET status = $1, updated = $2, worker = $3, failures = $4, last_error = $5, output = $6\n\t\t\t\t WHERE id = $7 AND path = $8`;\n\t\t\t\tupdateParams = [status, currentTime, workerValue, newFailures, newLastError, newOutput, id, this.pathStr];\n\t\t\t}\n\n\t\t\tconst result = await client.query(updateQuery, updateParams);\n\n\t\t\tawait this.toctouDelay?.();\n\n\t\t\tif (oldStatus && result.rowCount === 0) {\n\t\t\t\tconst currentEntry = await client.query<{ status: KeetaAnchorQueueStatus }>(`SELECT status FROM ${this.tableNameEntries} WHERE id = $1 AND path = $2`, [id, this.pathStr]);\n\t\t\t\tconst currentStatus = currentEntry.rows[0]?.status;\n\t\t\t\tif (currentEntry.rows.length > 0) {\n\t\t\t\t\tif (currentStatus === undefined) {\n\t\t\t\t\t\tthrow(new Error(`internal error: could not retrieve current status for request with ID ${String(id)}`));\n\t\t\t\t\t}\n\t\t\t\t\tthrow(new Errors.IncorrectStateAssertedError(id, oldStatus, currentStatus));\n\t\t\t\t} else {\n\t\t\t\t\tthrow(new Error(`Request with ID ${String(id)} not found`));\n\t\t\t\t}\n\t\t\t}\n\t\t}));\n\t}\n\n\tasync get(id: KeetaAnchorQueueRequestID): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult> | null> {\n\t\treturn(await this.dbTransaction('get', async (client): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult> | null> => {\n\t\t\tconst row = await client.query<QueueEntryRow>(\n\t\t\t\t`SELECT id, request, output, last_error, status, created, updated, worker, failures\n\t\t\t\t FROM ${this.tableNameEntries} WHERE id = $1 AND path = $2`,\n\t\t\t\t[id, this.pathStr]\n\t\t\t);\n\n\t\t\tif (row.rows.length === 0) {\n\t\t\t\treturn(null);\n\t\t\t}\n\n\t\t\tconst entry = row.rows[0];\n\t\t\tif (!entry) {\n\t\t\t\treturn(null);\n\t\t\t}\n\n\t\t\tconst idempotentRows = await client.query<IdempotentRow>(\n\t\t\t\t`SELECT idempotent_id FROM ${this.tableNameIdempotentKeys} WHERE entry_id = $1 AND path = $2`,\n\t\t\t\t[id, this.pathStr]\n\t\t\t);\n\n\t\t\tconst idempotentKeys = idempotentRows.rows.length > 0\n\t\t\t\t? new Set(idempotentRows.rows.map(function(idempotentRow: IdempotentRow) {\n\t\t\t\t\treturn(ConvertStringToRequestID(idempotentRow.idempotent_id));\n\t\t\t\t}))\n\t\t\t\t: undefined;\n\n\t\t\treturn({\n\t\t\t\tid: ConvertStringToRequestID(entry.id),\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\trequest: JSON.parse(entry.request) as QueueRequest,\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\toutput: entry.output ? JSON.parse(entry.output) as QueueResult : null,\n\t\t\t\tlastError: entry.last_error,\n\t\t\t\tstatus: entry.status,\n\t\t\t\tcreated: new Date(Number(entry.created)),\n\t\t\t\tupdated: new Date(Number(entry.updated)),\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\tworker: entry.worker as unknown as KeetaAnchorQueueWorkerID | null,\n\t\t\t\tfailures: entry.failures,\n\t\t\t\tidempotentKeys: idempotentKeys\n\t\t\t});\n\t\t}));\n\t}\n\n\tasync query(filter?: KeetaAnchorQueueFilter): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult>[]> {\n\t\treturn(await this.dbTransaction('query', async (client, logger): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult>[]> => {\n\t\t\tlogger?.debug(`Querying queue with id ${this.id} with filter:`, filter);\n\n\t\t\tconst conditions: string[] = [];\n\t\t\tconst params: (string | number)[] = [];\n\t\t\tlet paramIndex = 1;\n\n\t\t\tconditions.push(`path = $${paramIndex++}`);\n\t\t\tparams.push(this.pathStr);\n\n\t\t\tif (filter?.status) {\n\t\t\t\tconditions.push(`status = $${paramIndex++}`);\n\t\t\t\tparams.push(filter.status);\n\t\t\t}\n\n\t\t\tif (filter?.updatedBefore) {\n\t\t\t\tconditions.push(`updated < $${paramIndex++}`);\n\t\t\t\tparams.push(filter.updatedBefore.getTime());\n\t\t\t}\n\n\t\t\tlet query = `SELECT id, request, output, last_error, status, created, updated, worker, failures FROM ${this.tableNameEntries}`;\n\n\t\t\tif (conditions.length > 0) {\n\t\t\t\tquery += ' WHERE ' + conditions.join(' AND ');\n\t\t\t}\n\n\t\t\t// Use random ordering to prevent multiple workers from contending for the same rows\n\t\t\t// This spreads the load when multiple workers query simultaneously\n\t\t\tquery += ' ORDER BY RANDOM()';\n\n\t\t\tif (filter?.limit !== undefined) {\n\t\t\t\tquery += ` LIMIT $${paramIndex++}`;\n\t\t\t\tparams.push(filter.limit);\n\t\t\t}\n\n\t\t\tconst rows = await client.query<QueueEntryRow>(query, params);\n\n\t\t\tconst entries: KeetaAnchorQueueEntry<QueueRequest, QueueResult>[] = [];\n\n\t\t\tfor (const row of rows.rows) {\n\t\t\t\tconst idempotentRows = await client.query<IdempotentRow>(\n\t\t\t\t\t`SELECT idempotent_id FROM ${this.tableNameIdempotentKeys} WHERE entry_id = $1 AND path = $2`,\n\t\t\t\t\t[row.id, this.pathStr]\n\t\t\t\t);\n\n\t\t\t\tconst idempotentKeys = idempotentRows.rows.length > 0\n\t\t\t\t\t? new Set(idempotentRows.rows.map(function(idempotentRow: IdempotentRow) {\n\t\t\t\t\t\treturn(ConvertStringToRequestID(idempotentRow.idempotent_id));\n\t\t\t\t\t}))\n\t\t\t\t\t: undefined;\n\n\t\t\t\tentries.push({\n\t\t\t\t\tid: ConvertStringToRequestID(row.id),\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\trequest: JSON.parse(row.request) as QueueRequest,\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\toutput: row.output ? JSON.parse(row.output) as QueueResult : null,\n\t\t\t\t\tlastError: row.last_error,\n\t\t\t\t\tstatus: row.status,\n\t\t\t\t\tcreated: new Date(Number(row.created)),\n\t\t\t\t\tupdated: new Date(Number(row.updated)),\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\tworker: row.worker as unknown as KeetaAnchorQueueWorkerID | null,\n\t\t\t\t\tfailures: row.failures,\n\t\t\t\t\tidempotentKeys: idempotentKeys\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlogger?.debug(`Queried queue with id ${this.id} with filter:`, filter, '-- found', entries.length, 'entries');\n\n\t\t\treturn(entries);\n\t\t}));\n\t}\n\n\tasync partition(path: string) : Promise<KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult>> {\n\t\tthis.methodLogger('partition')?.debug(`Creating partitioned queue storage driver for path: ${path}`);\n\n\t\tif (this.poolInternal === null) {\n\t\t\tthrow(new Error('Asked to partition but the instance has been destroyed'));\n\t\t}\n\n\t\tconst retval = new KeetaAnchorQueueStorageDriverPostgres<QueueRequest, QueueResult>({\n\t\t\tid: `${this.id}::${path}`,\n\t\t\tlogger: this.logger,\n\t\t\tpool: this.poolInternal,\n\t\t\tpath: [...this.path, path],\n\t\t\ttablePrefix: this.tablePrefix\n\t\t});\n\n\t\treturn(retval);\n\t}\n\n\tasync destroy(): Promise<void> {\n\t\tthis.methodLogger('destroy')?.debug('Destroying instance');\n\n\t\tthis.poolInternal = null;\n\t}\n\n\tasync [Symbol.asyncDispose](): Promise<void> {\n\t\treturn(await this.destroy());\n\t}\n\n\t/** @internal */\n\t_Testing(key: string): {\n\t\tsetToctouDelay(delay: number): void;\n\t\tunsetToctouDelay(): void;\n\t\tgetSerializationRetryCount(): number;\n\t\tresetSerializationRetryCount(): void;\n\t\tenableDebugForceIndexScan(): void;\n\t\tdisableDebugForceIndexScan(): void;\n\t} {\n\t\tif (key !== 'bc81abf8-e43b-490b-b486-744fb49a5082') {\n\t\t\tthrow(new Error('This is a testing only method'));\n\t\t}\n\n\t\treturn({\n\t\t\tsetToctouDelay: (delay: number): void => {\n\t\t\t\tthis.toctouDelay = async (): Promise<void> => {\n\t\t\t\t\treturn(await asleep(delay));\n\t\t\t\t};\n\t\t\t},\n\t\t\tunsetToctouDelay: (): void => {\n\t\t\t\tthis.toctouDelay = undefined;\n\t\t\t},\n\t\t\tgetSerializationRetryCount: (): number => {\n\t\t\t\treturn(this.serializationRetryCount);\n\t\t\t},\n\t\t\tresetSerializationRetryCount: (): void => {\n\t\t\t\tthis.serializationRetryCount = 0;\n\t\t\t},\n\t\t\tenableDebugForceIndexScan: (): void => {\n\t\t\t\tthis.debugForceIndexScan = true;\n\t\t\t},\n\t\t\tdisableDebugForceIndexScan: (): void => {\n\t\t\t\tthis.debugForceIndexScan = false;\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"token-metadata.d.ts","sourceRoot":"","sources":["../../src/lib/token-metadata.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,aAAa;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAGD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,aAAa,EAAE,eAAe,CAAC;IAC9E,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC;CAC/B;AAgCD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,GAAG,aAAa,GAAG,aAAa,CAYtG;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,aAAa,GAAG,iBAAiB,GAAG,MAAM,CAKvF"}
1
+ {"version":3,"file":"token-metadata.d.ts","sourceRoot":"","sources":["../../src/lib/token-metadata.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,aAAa;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,aAAa,EAAE,eAAe,CAAC;IAC9E,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC;CAC/B;AAgCD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,GAAG,aAAa,GAAG,aAAa,CAYtG;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,aAAa,GAAG,iBAAiB,GAAG,MAAM,CAKvF"}
@@ -9,7 +9,7 @@ function parseDecimalPlaces(input) {
9
9
  }
10
10
  value = Number(value);
11
11
  }
12
- if (Number.isNaN(value) || value < 0 || !Number.isInteger(value)) {
12
+ if (!Number.isFinite(value) || value < 0 || value > 1024 || !Number.isInteger(value)) {
13
13
  valid = false;
14
14
  }
15
15
  if (!valid) {
@@ -1 +1 @@
1
- {"version":3,"file":"token-metadata.js","sourceRoot":"","sources":["../../src/lib/token-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAYnG,SAAS,kBAAkB,CAAC,KAAsB;IACjD,IAAI,KAAK,GAAG,IAAI,CAAC;IAEjB,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACzB,KAAK,GAAG,KAAK,CAAC;QACf,CAAC;QAED,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QAClE,KAAK,GAAG,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,MAAK,CAAC,IAAI,8BAA8B,CAAC;YACxC,MAAM,EAAE;gBACP;oBACC,IAAI,EAAE,eAAe;oBACrB,OAAO,EAAE,gCAAgC,KAAK,EAAE;iBAChD;aACD;SACD,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAM,CAAC,KAAK,CAAC,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAmD;IACtF,IAAI,OAAO,CAAC;IACZ,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,GAAG,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACjD,CAAC;SAAM,CAAC;QACP,OAAO,GAAG,OAAO,CAAC;IACnB,CAAC;IAED,OAAM,CAAC;QACN,GAAG,OAAO;QACV,aAAa,EAAE,kBAAkB,CAAC,OAAO,CAAC,aAAa,CAAC;KACxD,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAA2C;IAC9E,2FAA2F;IAC3F,MAAM,UAAU,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACjD,MAAM,OAAO,GAAG,0BAA0B,CAAC,UAAU,CAAC,CAAC;IACvD,OAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import { KeetaAnchorUserValidationError } from \"./error.js\";\nimport { parseTokenMetadataJSON, stringifyTokenMetadataJSON } from \"./token-metadata.generated.js\";\n\nexport interface TokenMetadata {\n\tdecimalPlaces: number;\n\tlogoURI?: string;\n}\n\n\nexport interface TokenMetadataJSON extends Omit<TokenMetadata, \"decimalPlaces\"> {\n\tdecimalPlaces: number | string;\n}\n\nfunction parseDecimalPlaces(input: number | string): number {\n\tlet valid = true;\n\n\tlet value = input;\n\tif (typeof value === 'string') {\n\t\tif (value.trim() === '') {\n\t\t\tvalid = false;\n\t\t}\n\n\t\tvalue = Number(value);\n\t}\n\n\tif (Number.isNaN(value) || value < 0 || !Number.isInteger(value)) {\n\t\tvalid = false;\n\t}\n\n\tif (!valid) {\n\t\tthrow(new KeetaAnchorUserValidationError({\n\t\t\tfields: [\n\t\t\t\t{\n\t\t\t\t\tpath: 'decimalPlaces',\n\t\t\t\t\tmessage: `Invalid decimalPlaces value: ${input}`\n\t\t\t\t}\n\t\t\t]\n\t\t}));\n\t}\n\n\treturn(value);\n}\n\n/**\n * Parse token metadata from a base64-encoded JSON string or a TokenMetadataJSON object, returning a TokenMetadata object.\n * @param encoded the value to parse\n * @returns the parsed TokenMetadata object\n */\nexport function decodeTokenMetadata(encoded: string | TokenMetadataJSON | TokenMetadata): TokenMetadata {\n\tlet decoded;\n\tif (typeof encoded === \"string\") {\n\t\tdecoded = parseTokenMetadataJSON(atob(encoded));\n\t} else {\n\t\tdecoded = encoded;\n\t}\n\n\treturn({\n\t\t...decoded,\n\t\tdecimalPlaces: parseDecimalPlaces(decoded.decimalPlaces)\n\t});\n}\n\n/**\n * Encodes token metadata into a base64-encoded JSON string.\n *\n * @param metadata - The token metadata to encode {@link TokenMetadata}\n * @returns The base64-encoded JSON string containing the token metadata\n */\nexport function encodeTokenMetadata(metadata: TokenMetadata | TokenMetadataJSON): string {\n\t// Normalize metadata so that decimalPlaces is always a number, ensuring canonical encoding\n\tconst normalized = decodeTokenMetadata(metadata);\n\tconst payload = stringifyTokenMetadataJSON(normalized);\n\treturn(btoa(payload));\n}\n"]}
1
+ {"version":3,"file":"token-metadata.js","sourceRoot":"","sources":["../../src/lib/token-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAWnG,SAAS,kBAAkB,CAAC,KAAsB;IACjD,IAAI,KAAK,GAAG,IAAI,CAAC;IAEjB,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACzB,KAAK,GAAG,KAAK,CAAC;QACf,CAAC;QAED,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QACtF,KAAK,GAAG,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,MAAK,CAAC,IAAI,8BAA8B,CAAC;YACxC,MAAM,EAAE;gBACP;oBACC,IAAI,EAAE,eAAe;oBACrB,OAAO,EAAE,gCAAgC,KAAK,EAAE;iBAChD;aACD;SACD,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAM,CAAC,KAAK,CAAC,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAmD;IACtF,IAAI,OAAO,CAAC;IACZ,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,GAAG,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACjD,CAAC;SAAM,CAAC;QACP,OAAO,GAAG,OAAO,CAAC;IACnB,CAAC;IAED,OAAM,CAAC;QACN,GAAG,OAAO;QACV,aAAa,EAAE,kBAAkB,CAAC,OAAO,CAAC,aAAa,CAAC;KACxD,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAA2C;IAC9E,2FAA2F;IAC3F,MAAM,UAAU,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACjD,MAAM,OAAO,GAAG,0BAA0B,CAAC,UAAU,CAAC,CAAC;IACvD,OAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import { KeetaAnchorUserValidationError } from \"./error.js\";\nimport { parseTokenMetadataJSON, stringifyTokenMetadataJSON } from \"./token-metadata.generated.js\";\n\nexport interface TokenMetadata {\n\tdecimalPlaces: number;\n\tlogoURI?: string;\n}\n\nexport interface TokenMetadataJSON extends Omit<TokenMetadata, \"decimalPlaces\"> {\n\tdecimalPlaces: number | string;\n}\n\nfunction parseDecimalPlaces(input: number | string): number {\n\tlet valid = true;\n\n\tlet value = input;\n\tif (typeof value === 'string') {\n\t\tif (value.trim() === '') {\n\t\t\tvalid = false;\n\t\t}\n\n\t\tvalue = Number(value);\n\t}\n\n\tif (!Number.isFinite(value) || value < 0 || value > 1024 || !Number.isInteger(value)) {\n\t\tvalid = false;\n\t}\n\n\tif (!valid) {\n\t\tthrow(new KeetaAnchorUserValidationError({\n\t\t\tfields: [\n\t\t\t\t{\n\t\t\t\t\tpath: 'decimalPlaces',\n\t\t\t\t\tmessage: `Invalid decimalPlaces value: ${input}`\n\t\t\t\t}\n\t\t\t]\n\t\t}));\n\t}\n\n\treturn(value);\n}\n\n/**\n * Parse token metadata from a base64-encoded JSON string or a TokenMetadataJSON object, returning a TokenMetadata object.\n * @param encoded the value to parse\n * @returns the parsed TokenMetadata object\n */\nexport function decodeTokenMetadata(encoded: string | TokenMetadataJSON | TokenMetadata): TokenMetadata {\n\tlet decoded;\n\tif (typeof encoded === \"string\") {\n\t\tdecoded = parseTokenMetadataJSON(atob(encoded));\n\t} else {\n\t\tdecoded = encoded;\n\t}\n\n\treturn({\n\t\t...decoded,\n\t\tdecimalPlaces: parseDecimalPlaces(decoded.decimalPlaces)\n\t});\n}\n\n/**\n * Encodes token metadata into a base64-encoded JSON string.\n *\n * @param metadata - The token metadata to encode {@link TokenMetadata}\n * @returns The base64-encoded JSON string containing the token metadata\n */\nexport function encodeTokenMetadata(metadata: TokenMetadata | TokenMetadataJSON): string {\n\t// Normalize metadata so that decimalPlaces is always a number, ensuring canonical encoding\n\tconst normalized = decodeTokenMetadata(metadata);\n\tconst payload = stringifyTokenMetadataJSON(normalized);\n\treturn(btoa(payload));\n}\n"]}
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@keetanetwork/anchor",
3
- "version": "0.0.61",
3
+ "version": "0.0.62",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@keetanetwork/anchor",
9
- "version": "0.0.61",
9
+ "version": "0.0.62",
10
10
  "license": "SEE LICENSE IN LICENSE",
11
11
  "dependencies": {
12
12
  "@keetanetwork/currency-info": "1.2.5",
13
- "@keetanetwork/keetanet-client": "0.16.1",
13
+ "@keetanetwork/keetanet-client": "0.16.2",
14
14
  "typia": "9.5.0"
15
15
  },
16
16
  "engines": {
@@ -185,8 +185,8 @@
185
185
  "license": "ISC"
186
186
  },
187
187
  "node_modules/@keetanetwork/keetanet-client": {
188
- "version": "0.16.1",
189
- "integrity": "sha512-SS31ZlQvz/qvcZf039K3COjSje3FiQOPBbhB0xAfn2Mwrc+QSqvM/FEi/3uWZdEWqeu4+cziUi1vMRReBUMGwA==",
188
+ "version": "0.16.2",
189
+ "integrity": "sha512-ifhICBG8k4r1Fyi+SaMgu9DUCIHuu5iV/YVmn2NKCwF7U+6kOoEJeRgrVyan9Vd8tF+xHtrj2O8dIwAWu44x9w==",
190
190
  "license": "see LICENSE",
191
191
  "dependencies": {
192
192
  "secp256k1": "5.0.1"
@@ -218,8 +218,8 @@
218
218
  "optional": true
219
219
  },
220
220
  "node_modules/@protobufjs/codegen": {
221
- "version": "2.0.4",
222
- "integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==",
221
+ "version": "2.0.5",
222
+ "integrity": "sha512-zgXFLzW3Ap33e6d0Wlj4MGIm6Ce8O89n/apUaGNB/jx+hw+ruWEp7EwGUshdLKVRCxZW12fp9r40E1mQrf/34g==",
223
223
  "license": "BSD-3-Clause",
224
224
  "optional": true
225
225
  },
@@ -246,8 +246,8 @@
246
246
  "optional": true
247
247
  },
248
248
  "node_modules/@protobufjs/inquire": {
249
- "version": "1.1.0",
250
- "integrity": "sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==",
249
+ "version": "1.1.1",
250
+ "integrity": "sha512-mnzgDV26ueAvk7rsbt9L7bE0SuAoqyuys/sMMrmVcN5x9VsxpcG3rqAUSgDyLp0UZlmNfIbQ4fHfCtreVBk8Ew==",
251
251
  "license": "BSD-3-Clause",
252
252
  "optional": true
253
253
  },
@@ -264,8 +264,8 @@
264
264
  "optional": true
265
265
  },
266
266
  "node_modules/@protobufjs/utf8": {
267
- "version": "1.1.0",
268
- "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==",
267
+ "version": "1.1.1",
268
+ "integrity": "sha512-oOAWABowe8EAbMyWKM0tYDKi8Yaox52D+HWZhAIJqQXbqe0xI/GV7FhLWqlEKreMkfDjshR5FKgi3mnle0h6Eg==",
269
269
  "license": "BSD-3-Clause",
270
270
  "optional": true
271
271
  },
@@ -1688,22 +1688,22 @@
1688
1688
  }
1689
1689
  },
1690
1690
  "node_modules/protobufjs": {
1691
- "version": "7.5.3",
1692
- "integrity": "sha512-sildjKwVqOI2kmFDiXQ6aEB0fjYTafpEvIBs8tOR8qI4spuL9OPROLVu2qZqi/xgCfsHIwVqlaF8JBjWFHnKbw==",
1691
+ "version": "7.5.7",
1692
+ "integrity": "sha512-NGnrxS/nLKUo5nkbVQxlC71sB4hdfImdYIbFeSCidxtwATx0AHRPcANSLd0q5Bb2BkoSWo2iisQhGg5/r+ihbA==",
1693
1693
  "hasInstallScript": true,
1694
1694
  "license": "BSD-3-Clause",
1695
1695
  "optional": true,
1696
1696
  "dependencies": {
1697
1697
  "@protobufjs/aspromise": "^1.1.2",
1698
1698
  "@protobufjs/base64": "^1.1.2",
1699
- "@protobufjs/codegen": "^2.0.4",
1699
+ "@protobufjs/codegen": "^2.0.5",
1700
1700
  "@protobufjs/eventemitter": "^1.1.0",
1701
1701
  "@protobufjs/fetch": "^1.1.0",
1702
1702
  "@protobufjs/float": "^1.0.2",
1703
- "@protobufjs/inquire": "^1.1.0",
1703
+ "@protobufjs/inquire": "^1.1.1",
1704
1704
  "@protobufjs/path": "^1.1.2",
1705
1705
  "@protobufjs/pool": "^1.1.0",
1706
- "@protobufjs/utf8": "^1.1.0",
1706
+ "@protobufjs/utf8": "^1.1.1",
1707
1707
  "@types/node": ">=13.7.0",
1708
1708
  "long": "^5.0.0"
1709
1709
  },
@@ -1924,8 +1924,8 @@
1924
1924
  }
1925
1925
  },
1926
1926
  "node_modules/teeny-request/node_modules/@tootallnate/once": {
1927
- "version": "2.0.0",
1928
- "integrity": "sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==",
1927
+ "version": "2.0.1",
1928
+ "integrity": "sha512-HqmEUIGRJ5fSXchkVgR5F7qn48bDBzv0kWj/Kfu5e6uci4UlEeng4331LnBkWffb++Ei3FOVLxo8JJWMFBDMeQ==",
1929
1929
  "license": "MIT",
1930
1930
  "optional": true,
1931
1931
  "engines": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keetanetwork/anchor",
3
- "version": "0.0.61",
3
+ "version": "0.0.62",
4
4
  "description": "KeetaNetwork Network Anchor",
5
5
  "main": "client/index.js",
6
6
  "scripts": {
@@ -24,7 +24,7 @@
24
24
  "sideEffects": false,
25
25
  "dependencies": {
26
26
  "@keetanetwork/currency-info": "1.2.5",
27
- "@keetanetwork/keetanet-client": "0.16.1",
27
+ "@keetanetwork/keetanet-client": "0.16.2",
28
28
  "typia": "9.5.0"
29
29
  },
30
30
  "engines": {
@@ -84,8 +84,9 @@ declare class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
84
84
  readonly serviceInfo: KeetaFXServiceInfo;
85
85
  readonly providerID: ProviderID;
86
86
  readonly conversion: ConversionInputCanonical;
87
+ readonly options: Pick<AccountOptions, 'account'> | undefined;
87
88
  private readonly parent;
88
- constructor(serviceInfo: KeetaFXServiceInfo, providerID: ProviderID, conversion: ConversionInputCanonical, parent: KeetaFXAnchorClient);
89
+ constructor(serviceInfo: KeetaFXServiceInfo, providerID: ProviderID, conversion: ConversionInputCanonical, parent: KeetaFXAnchorClient, options?: Pick<AccountOptions, 'account'>);
89
90
  getEstimate(): Promise<KeetaFXAnchorEstimate>;
90
91
  /**
91
92
  * Get a quote from the provider. If an estimate is provided, it will
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/services/fx/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EACX,UAAU,IAAI,kBAAkB,EAChC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,QAAQ,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAyB,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAI1G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAQ9D,OAAO,KAAK,EACX,eAAe,EACf,wBAAwB,EAExB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,4BAA4B,EAC5B,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,6BAA6B,CAAC;AAEtF;;GAEG;AACH,KAAK,UAAU,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;AAEhD,KAAK,cAAc,GAAG;IACrB;;;;OAIG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC;IAClD;;;;OAIG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC;CACnD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACvC;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;OAGG;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CAAC,yBAAyB,EAAE,GAAG,IAAI,CAAC;IAe9K,YAAY,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,GAAE,IAAI,CAAC,mBAAmB,EAAE,oBAAoB,CAAM,EAAE,cAAc,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,iCAAiC,EAAE,GAAG,IAAI,CAAC;IA2DjM,SAAS,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,GAAE,cAAmB,EAAE,cAAc,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,8BAA8B,EAAE,GAAG,IAAI,CAAC;IAkB1J,oBAAoB,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,GAAE,cAAmB,EAAE,cAAc,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,CAAC,8BAA8B,GAAG,iCAAiC,CAAC,EAAE,GAAG,IAAI,CAAC;IAkD3M,SAAS,CAAC,KAAK,SAAS,eAAe,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,yBAAyB,GAAG,IAAI,CAAC,CAAC;CA2D1I;AAED,eAAe,mBAAmB,CAAC"}
@@ -106,14 +106,16 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
106
106
  serviceInfo;
107
107
  providerID;
108
108
  conversion;
109
+ options;
109
110
  parent;
110
- constructor(serviceInfo, providerID, conversion, parent) {
111
+ constructor(serviceInfo, providerID, conversion, parent, options) {
111
112
  const parentPrivate = parent._internals(KeetaFXAnchorClientAccessToken);
112
113
  super(parentPrivate);
113
114
  this.serviceInfo = serviceInfo;
114
115
  this.providerID = providerID;
115
116
  this.conversion = conversion;
116
117
  this.parent = parent;
118
+ this.options = options;
117
119
  }
118
120
  #parseConversionRequest(input) {
119
121
  return ({
@@ -298,7 +300,7 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
298
300
  throw (new Error('Invalid affinity in conversion request'));
299
301
  }
300
302
  /* Construct the required operations for the swap request */
301
- const builder = this.client.initBuilder();
303
+ const builder = this.client.initBuilder(this.options);
302
304
  if ('quote' in input) {
303
305
  /* If cost is required then send the required amount as well */
304
306
  if (input.quote.cost.amount > 0) {
@@ -590,7 +592,7 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
590
592
  return (null);
591
593
  }
592
594
  const providers = typedFxServiceEntries(providerEndpoints).map(([providerID, serviceInfo]) => {
593
- return (new KeetaFXAnchorProviderBase(serviceInfo, providerID, conversion, this));
595
+ return (new KeetaFXAnchorProviderBase(serviceInfo, providerID, conversion, this, options));
594
596
  });
595
597
  return (providers);
596
598
  }