@xyo-network/archivist-indexeddb 3.16.1 → 3.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,6 +46,7 @@ var IndexedDbArchivistConfigSchema = `${IndexedDbArchivistSchema}.config`;
46
46
  var IndexedDbArchivist = class extends AbstractArchivist {
47
47
  _dbName;
48
48
  _dbVersion;
49
+ _payloadCount = 0;
49
50
  _storeName;
50
51
  /**
51
52
  * The database name. If not supplied via config, it defaults
@@ -116,10 +117,12 @@ var IndexedDbArchivist = class extends AbstractArchivist {
116
117
  }
117
118
  async allHandler() {
118
119
  const payloads = await this.useDb((db) => db.getAll(this.storeName));
120
+ this._payloadCount = payloads.length;
119
121
  return payloads;
120
122
  }
121
123
  async clearHandler() {
122
124
  await this.useDb((db) => db.clear(this.storeName));
125
+ this._payloadCount = 0;
123
126
  }
124
127
  async deleteHandler(hashes) {
125
128
  const uniqueHashes = [...new Set(hashes)];
@@ -142,7 +145,9 @@ var IndexedDbArchivist = class extends AbstractArchivist {
142
145
  );
143
146
  return found.filter(exists).filter((hash) => uniqueHashes.includes(hash));
144
147
  });
145
- return payloadsToDelete.filter((payload) => deletedHashes.includes(payload._hash) || deletedHashes.includes(payload._dataHash));
148
+ const deletedPayloads = payloadsToDelete.filter((payload) => deletedHashes.includes(payload._hash) || deletedHashes.includes(payload._dataHash));
149
+ this._payloadCount = this._payloadCount - deletedPayloads.length;
150
+ return deletedPayloads;
146
151
  }
147
152
  async getFromCursor(db, storeName, order = "asc", limit = 10, cursor, open) {
148
153
  return await withReadOnlyStore(db, storeName, async (store) => {
@@ -228,6 +233,7 @@ var IndexedDbArchivist = class extends AbstractArchivist {
228
233
  }
229
234
  })
230
235
  );
236
+ this._payloadCount = this._payloadCount + inserted.length;
231
237
  return inserted;
232
238
  } else {
233
239
  throw new Error("Failed to get store");
@@ -246,9 +252,13 @@ var IndexedDbArchivist = class extends AbstractArchivist {
246
252
  return await this.getFromCursor(db, this.storeName, order, limit ?? 10, cursor, open);
247
253
  });
248
254
  }
255
+ payloadCountHandler() {
256
+ return this._payloadCount;
257
+ }
249
258
  async startHandler() {
250
259
  await super.startHandler();
251
- await this.useDb(() => {
260
+ this._payloadCount = await this.useDb(async (db) => {
261
+ return await db.count(this.storeName);
252
262
  });
253
263
  return true;
254
264
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Archivist.ts","../../src/Schema.ts","../../src/Config.ts"],"sourcesContent":["import { uniq } from '@xylabs/array'\nimport { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Hash, Hex } from '@xylabs/hex'\nimport {\n ObjectStore,\n withDb,\n withReadOnlyStore, withReadWriteStore,\n} from '@xylabs/indexed-db'\nimport { isDefined, isUndefined } from '@xylabs/typeof'\nimport { AbstractArchivist, StorageClassLabel } from '@xyo-network/archivist-abstract'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistModuleEventData,\n ArchivistNextOptions,\n ArchivistNextQuerySchema,\n buildStandardIndexName,\n IndexDescription,\n} from '@xyo-network/archivist-model'\nimport { creatableModule } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport {\n Payload, Schema, WithStorageMeta,\n} from '@xyo-network/payload-model'\nimport { IDBPCursorWithValue, IDBPDatabase } from 'idb'\n\nimport { IndexedDbArchivistConfigSchema } from './Config.ts'\nimport { IndexedDbArchivistParams } from './Params.ts'\n\nexport interface PayloadStore {\n [s: string]: WithStorageMeta\n}\n\n@creatableModule()\nexport class IndexedDbArchivist<\n TParams extends IndexedDbArchivistParams = IndexedDbArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n> extends AbstractArchivist<TParams, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, IndexedDbArchivistConfigSchema]\n static override readonly defaultConfigSchema: Schema = IndexedDbArchivistConfigSchema\n static readonly defaultDbName = 'archivist'\n static readonly defaultDbVersion = 1\n static readonly defaultStoreName = 'payloads'\n static override readonly labels = { ...super.labels, [StorageClassLabel]: 'disk' }\n\n private static readonly dataHashIndex: IndexDescription = {\n key: { _dataHash: 1 }, multiEntry: false, unique: false,\n }\n\n private static readonly hashIndex: IndexDescription = {\n key: { _hash: 1 }, multiEntry: false, unique: true,\n }\n\n private static readonly schemaIndex: IndexDescription = {\n key: { schema: 1 }, multiEntry: false, unique: false,\n }\n\n private static readonly sequenceIndex: IndexDescription = {\n key: { _sequence: 1 }, multiEntry: false, unique: true,\n }\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n static readonly hashIndexName = buildStandardIndexName(IndexedDbArchivist.hashIndex)\n // eslint-disable-next-line @typescript-eslint/member-ordering\n static readonly dataHashIndexName = buildStandardIndexName(IndexedDbArchivist.dataHashIndex)\n // eslint-disable-next-line @typescript-eslint/member-ordering\n static readonly schemaIndexName = buildStandardIndexName(IndexedDbArchivist.schemaIndex)\n // eslint-disable-next-line @typescript-eslint/member-ordering\n static readonly sequenceIndexName = buildStandardIndexName(IndexedDbArchivist.sequenceIndex)\n\n private _dbName?: string\n private _dbVersion?: number\n private _storeName?: string\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the module name (not guaranteed to be unique) and if module\n * name is not supplied, it defaults to `archivist`. This behavior\n * biases towards a single, isolated DB per archivist which seems to\n * make the most sense for 99% of use cases.\n */\n get dbName() {\n if (isUndefined(this._dbName)) {\n if (isDefined(this.config?.dbName)) {\n this._dbName = this.config?.dbName\n } else {\n if (isDefined(this.config?.name)) {\n this.logger?.warn('No dbName provided, using module name: ', this.config?.name)\n this._dbName = this.config?.name\n } else {\n this.logger?.warn('No dbName provided, using default name: ', IndexedDbArchivist.defaultDbName)\n this._dbName = IndexedDbArchivist.defaultDbName\n }\n }\n }\n return assertEx(this._dbName)\n }\n\n /**\n * The database version. If not supplied via config, it defaults to 1.\n */\n get dbVersion() {\n this._dbVersion = this._dbVersion ?? this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion\n return this._dbVersion\n }\n\n override get queries() {\n return [\n ArchivistNextQuerySchema,\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuerySchema,\n ...super.queries,\n ]\n }\n\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`.\n */\n get storeName() {\n if (isUndefined(this._storeName)) {\n if (isDefined(this.config?.storeName)) {\n this._storeName = this.config?.storeName\n } else {\n this.logger?.warn('No storeName provided, using default name: ', IndexedDbArchivist.defaultStoreName)\n this._storeName = IndexedDbArchivist.defaultStoreName\n }\n }\n return assertEx(this._storeName)\n }\n\n /**\n * The indexes to create on the store\n */\n private get indexes() {\n return [\n IndexedDbArchivist.dataHashIndex,\n IndexedDbArchivist.hashIndex,\n IndexedDbArchivist.schemaIndex,\n IndexedDbArchivist.sequenceIndex,\n ...(this.config?.storage?.indexes ?? []),\n ]\n }\n\n protected override async allHandler(): Promise<WithStorageMeta<Payload>[]> {\n // Get all payloads from the store\n const payloads = await this.useDb(db => db.getAll(this.storeName))\n // Remove any metadata before returning to the client\n return payloads\n }\n\n protected override async clearHandler(): Promise<void> {\n await this.useDb(db => db.clear(this.storeName))\n }\n\n protected override async deleteHandler(hashes: Hash[]): Promise<WithStorageMeta<Payload>[]> {\n // Filter duplicates to prevent unnecessary DB queries\n const uniqueHashes = [...new Set(hashes)]\n const pairs = await PayloadBuilder.hashPairs(await this.getHandler(uniqueHashes))\n const payloadsToDelete = await Promise.all(pairs.map(([payload]) => payload))\n const hashesToDelete = (await Promise.all(pairs.map(async (pair) => {\n const dataHash0 = await PayloadBuilder.dataHash(pair[0])\n return [dataHash0, pair[1]]\n }))).flat()\n // Remove any duplicates\n const distinctHashes = [...new Set(hashesToDelete)]\n const deletedHashes = await this.useDb(async (db) => {\n // Only return hashes that were successfully deleted\n const found = await Promise.all(\n distinctHashes.map(async (hash) => {\n // Check if the hash exists\n const existing\n = (await db.getKeyFromIndex(this.storeName, IndexedDbArchivist.hashIndexName, hash))\n ?? (await db.getKeyFromIndex(this.storeName, IndexedDbArchivist.dataHashIndexName, hash))\n // If it does exist\n if (isDefined(existing)) {\n // Delete it\n await db.delete(this.storeName, existing)\n // Return the hash so it gets added to the list of deleted hashes\n return hash\n }\n }),\n )\n return found.filter(exists).filter(hash => uniqueHashes.includes(hash))\n })\n return payloadsToDelete.filter(payload => deletedHashes.includes(payload._hash) || deletedHashes.includes(payload._dataHash))\n }\n\n protected async getFromCursor(\n db: IDBPDatabase<ObjectStore>,\n storeName: string,\n order: 'asc' | 'desc' = 'asc',\n limit: number = 10,\n cursor?: Hex,\n open?: boolean,\n ): Promise<WithStorageMeta[]> {\n // TODO: We have to handle the case where the cursor is not found, and then find the correct cursor to start with (thunked cursor)\n\n return await withReadOnlyStore(db, storeName, async (store) => {\n const sequenceIndex = assertEx(store?.index(IndexedDbArchivist.sequenceIndexName), () => 'Failed to get sequence index')\n let sequenceCursor: IDBPCursorWithValue<ObjectStore, [string]> | null | undefined\n const parsedCursor = isDefined(cursor)\n ? order === 'asc'\n ? IDBKeyRange.lowerBound(cursor, open)\n : IDBKeyRange.upperBound(cursor, open)\n : null\n\n sequenceCursor = await sequenceIndex.openCursor(\n parsedCursor,\n order === 'desc' ? 'prev' : 'next',\n )\n\n let remaining = limit\n const result: WithStorageMeta[] = []\n while (remaining > 0) {\n const value = sequenceCursor?.value\n if (value) {\n result.push(value)\n }\n try {\n sequenceCursor = await sequenceCursor?.advance(1)\n } catch {\n break\n }\n if (sequenceCursor === null) {\n break\n }\n remaining--\n }\n return result\n })\n }\n\n /**\n * Uses an index to get a payload by the index value, but returns the value with the primary key (from the root store)\n * @param db The db instance to use\n * @param storeName The name of the store to use\n * @param indexName The index to use\n * @param key The key to get from the index\n * @returns The primary key and the payload, or undefined if not found\n */\n protected async getFromIndexWithPrimaryKey(\n db: IDBPDatabase<ObjectStore>,\n storeName: string,\n indexName: string,\n key: IDBValidKey,\n ): Promise<[number, WithStorageMeta] | undefined> {\n return await withReadOnlyStore(db, storeName, async (store) => {\n if (store) {\n const index = store.index(indexName)\n const cursor = await index.openCursor(key)\n if (cursor) {\n const singleValue = cursor.value\n // NOTE: It's known to be a number because we are using IndexedDB supplied auto-incrementing keys\n if (typeof cursor.primaryKey !== 'number') {\n throw new TypeError('primaryKey must be a number')\n }\n\n return [cursor.primaryKey, singleValue]\n }\n }\n })\n }\n\n protected override async getHandler(hashes: string[]): Promise<WithStorageMeta[]> {\n const payloads = await this.useDb(db =>\n Promise.all(\n // Filter duplicates to prevent unnecessary DB queries\n uniq(hashes).map(async (hash) => {\n // Find by hash\n const payload = await this.getFromIndexWithPrimaryKey(db, this.storeName, IndexedDbArchivist.hashIndexName, hash)\n // If found, return\n if (payload) return payload\n // Otherwise, find by data hash\n return this.getFromIndexWithPrimaryKey(db, this.storeName, IndexedDbArchivist.dataHashIndexName, hash)\n }),\n ))\n\n const found = new Set<string>()\n return (\n payloads\n // Filter out not found\n .filter(exists)\n // Sort by primary key\n .sort((a, b) => a![0] - b![0])\n // Filter out duplicates by hash\n .filter(([_key, payload]) => {\n if (found.has(payload._hash)) {\n return false\n } else {\n found.add(payload._hash)\n return true\n }\n })\n // Return just the payloads\n .map(([_key, payload]) => payload)\n )\n }\n\n protected override async insertHandler(payloads: WithStorageMeta<Payload>[]): Promise<WithStorageMeta<Payload>[]> {\n return await this.useDb(async (db) => {\n // Perform all inserts via a single transaction to ensure atomicity\n // with respect to checking for the pre-existence of the hash.\n // This is done to prevent duplicate root hashes due to race\n // conditions between checking vs insertion.\n return await withReadWriteStore(db, this.storeName, async (store) => {\n // Return only the payloads that were successfully inserted\n if (store) {\n const inserted: WithStorageMeta<Payload>[] = []\n await Promise.all(\n payloads.map(async (payload) => {\n // only insert if hash does not already exist\n if (!await store.index(IndexedDbArchivist.hashIndexName).get(payload._hash)) {\n // Insert the payload\n await store.put(payload)\n // Add it to the inserted list\n inserted.push(payload)\n }\n }),\n )\n return inserted\n } else {\n throw new Error('Failed to get store')\n }\n })\n })\n }\n\n protected override async nextHandler(options?: ArchivistNextOptions): Promise<WithStorageMeta<Payload>[]> {\n const {\n limit, cursor, order, open = true,\n } = options ?? {}\n return await this.useDb(async (db) => {\n return await this.getFromCursor(db, this.storeName, order, limit ?? 10, cursor, open)\n })\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // NOTE: We could defer this creation to first access but we\n // want to fail fast here in case something is wrong\n await this.useDb(() => {})\n return true\n }\n\n /**\n * Executes a callback with the initialized DB and then closes the db\n * @param callback The method to execute with the initialized DB\n * @returns\n */\n private async useDb<T>(callback: (db: IDBPDatabase<ObjectStore>) => Promise<T> | T): Promise<T> {\n return await withDb<ObjectStore, T>(this.dbName, async (db) => {\n return await callback(db)\n }, { [this.storeName]: this.indexes }, this.logger)\n }\n}\n","export const IndexedDbArchivistSchema = 'network.xyo.archivist.indexeddb' as const\nexport type IndexedDbArchivistSchema = typeof IndexedDbArchivistSchema\n","import type { ArchivistConfig } from '@xyo-network/archivist-model'\n\nimport { IndexedDbArchivistSchema } from './Schema.ts'\n\nexport type IndexedDbArchivistConfigSchema = `${IndexedDbArchivistSchema}.config`\nexport const IndexedDbArchivistConfigSchema: IndexedDbArchivistConfigSchema = `${IndexedDbArchivistSchema}.config`\n\nexport type IndexedDbArchivistConfig<TStoreName extends string = string> = ArchivistConfig<{\n /**\n * The database name\n */\n dbName?: string\n /**\n * The version of the DB, defaults to 1\n */\n dbVersion?: number\n schema: IndexedDbArchivistConfigSchema\n /**\n * The name of the object store\n */\n storeName?: TStoreName\n}>\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY;AACrB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAEvB;AAAA,EAEE;AAAA,EACA;AAAA,EAAmB;AAAA,OACd;AACP,SAAS,WAAW,mBAAmB;AACvC,SAAS,mBAAmB,yBAAyB;AACrD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,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,iBAAkC;AAAA,EACxD,KAAK,EAAE,WAAW,EAAE;AAAA,EAAG,YAAY;AAAA,EAAO,QAAQ;AACpD;AAEA,cAfW,oBAea,aAA8B;AAAA,EACpD,KAAK,EAAE,OAAO,EAAE;AAAA,EAAG,YAAY;AAAA,EAAO,QAAQ;AAChD;AAEA,cAnBW,oBAmBa,eAAgC;AAAA,EACtD,KAAK,EAAE,QAAQ,EAAE;AAAA,EAAG,YAAY;AAAA,EAAO,QAAQ;AACjD;AAEA,cAvBW,oBAuBa,iBAAkC;AAAA,EACxD,KAAK,EAAE,WAAW,EAAE;AAAA,EAAG,YAAY;AAAA,EAAO,QAAQ;AACpD;AAAA;AAGA,cA5BW,oBA4BK,iBAAgB,uBAAuB,mBAAmB,SAAS;AAAA;AAEnF,cA9BW,oBA8BK,qBAAoB,uBAAuB,mBAAmB,aAAa;AAAA;AAE3F,cAhCW,oBAgCK,mBAAkB,uBAAuB,mBAAmB,WAAW;AAAA;AAEvF,cAlCW,oBAkCK,qBAAoB,uBAAuB,mBAAmB,aAAa;AAlChF,qBAAN;AAAA,EADN,gBAAgB;AAAA,GACJ;","names":[]}
1
+ {"version":3,"sources":["../../src/Archivist.ts","../../src/Schema.ts","../../src/Config.ts"],"sourcesContent":["import { uniq } from '@xylabs/array'\nimport { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Hash, Hex } from '@xylabs/hex'\nimport {\n ObjectStore,\n withDb,\n withReadOnlyStore, withReadWriteStore,\n} from '@xylabs/indexed-db'\nimport { isDefined, isUndefined } from '@xylabs/typeof'\nimport { AbstractArchivist, StorageClassLabel } from '@xyo-network/archivist-abstract'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistModuleEventData,\n ArchivistNextOptions,\n ArchivistNextQuerySchema,\n buildStandardIndexName,\n IndexDescription,\n} from '@xyo-network/archivist-model'\nimport { creatableModule } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport {\n Payload, Schema, WithStorageMeta,\n} from '@xyo-network/payload-model'\nimport { IDBPCursorWithValue, IDBPDatabase } from 'idb'\n\nimport { IndexedDbArchivistConfigSchema } from './Config.ts'\nimport { IndexedDbArchivistParams } from './Params.ts'\n\nexport interface PayloadStore {\n [s: string]: WithStorageMeta\n}\n\n@creatableModule()\nexport class IndexedDbArchivist<\n TParams extends IndexedDbArchivistParams = IndexedDbArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n> extends AbstractArchivist<TParams, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, IndexedDbArchivistConfigSchema]\n static override readonly defaultConfigSchema: Schema = IndexedDbArchivistConfigSchema\n static readonly defaultDbName = 'archivist'\n static readonly defaultDbVersion = 1\n static readonly defaultStoreName = 'payloads'\n static override readonly labels = { ...super.labels, [StorageClassLabel]: 'disk' }\n\n private static readonly dataHashIndex: IndexDescription = {\n key: { _dataHash: 1 }, multiEntry: false, unique: false,\n }\n\n private static readonly hashIndex: IndexDescription = {\n key: { _hash: 1 }, multiEntry: false, unique: true,\n }\n\n private static readonly schemaIndex: IndexDescription = {\n key: { schema: 1 }, multiEntry: false, unique: false,\n }\n\n private static readonly sequenceIndex: IndexDescription = {\n key: { _sequence: 1 }, multiEntry: false, unique: true,\n }\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n static readonly hashIndexName = buildStandardIndexName(IndexedDbArchivist.hashIndex)\n // eslint-disable-next-line @typescript-eslint/member-ordering\n static readonly dataHashIndexName = buildStandardIndexName(IndexedDbArchivist.dataHashIndex)\n // eslint-disable-next-line @typescript-eslint/member-ordering\n static readonly schemaIndexName = buildStandardIndexName(IndexedDbArchivist.schemaIndex)\n // eslint-disable-next-line @typescript-eslint/member-ordering\n static readonly sequenceIndexName = buildStandardIndexName(IndexedDbArchivist.sequenceIndex)\n\n private _dbName?: string\n private _dbVersion?: number\n private _payloadCount = 0\n private _storeName?: string\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the module name (not guaranteed to be unique) and if module\n * name is not supplied, it defaults to `archivist`. This behavior\n * biases towards a single, isolated DB per archivist which seems to\n * make the most sense for 99% of use cases.\n */\n get dbName() {\n if (isUndefined(this._dbName)) {\n if (isDefined(this.config?.dbName)) {\n this._dbName = this.config?.dbName\n } else {\n if (isDefined(this.config?.name)) {\n this.logger?.warn('No dbName provided, using module name: ', this.config?.name)\n this._dbName = this.config?.name\n } else {\n this.logger?.warn('No dbName provided, using default name: ', IndexedDbArchivist.defaultDbName)\n this._dbName = IndexedDbArchivist.defaultDbName\n }\n }\n }\n return assertEx(this._dbName)\n }\n\n /**\n * The database version. If not supplied via config, it defaults to 1.\n */\n get dbVersion() {\n this._dbVersion = this._dbVersion ?? this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion\n return this._dbVersion\n }\n\n override get queries() {\n return [\n ArchivistNextQuerySchema,\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuerySchema,\n ...super.queries,\n ]\n }\n\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`.\n */\n get storeName() {\n if (isUndefined(this._storeName)) {\n if (isDefined(this.config?.storeName)) {\n this._storeName = this.config?.storeName\n } else {\n this.logger?.warn('No storeName provided, using default name: ', IndexedDbArchivist.defaultStoreName)\n this._storeName = IndexedDbArchivist.defaultStoreName\n }\n }\n return assertEx(this._storeName)\n }\n\n /**\n * The indexes to create on the store\n */\n private get indexes() {\n return [\n IndexedDbArchivist.dataHashIndex,\n IndexedDbArchivist.hashIndex,\n IndexedDbArchivist.schemaIndex,\n IndexedDbArchivist.sequenceIndex,\n ...(this.config?.storage?.indexes ?? []),\n ]\n }\n\n protected override async allHandler(): Promise<WithStorageMeta<Payload>[]> {\n // Get all payloads from the store\n const payloads = await this.useDb(db => db.getAll(this.storeName))\n // Remove any metadata before returning to the client\n this._payloadCount = payloads.length\n return payloads\n }\n\n protected override async clearHandler(): Promise<void> {\n await this.useDb(db => db.clear(this.storeName))\n this._payloadCount = 0\n }\n\n protected override async deleteHandler(hashes: Hash[]): Promise<WithStorageMeta<Payload>[]> {\n // Filter duplicates to prevent unnecessary DB queries\n const uniqueHashes = [...new Set(hashes)]\n const pairs = await PayloadBuilder.hashPairs(await this.getHandler(uniqueHashes))\n const payloadsToDelete = await Promise.all(pairs.map(([payload]) => payload))\n const hashesToDelete = (await Promise.all(pairs.map(async (pair) => {\n const dataHash0 = await PayloadBuilder.dataHash(pair[0])\n return [dataHash0, pair[1]]\n }))).flat()\n // Remove any duplicates\n const distinctHashes = [...new Set(hashesToDelete)]\n const deletedHashes = await this.useDb(async (db) => {\n // Only return hashes that were successfully deleted\n const found = await Promise.all(\n distinctHashes.map(async (hash) => {\n // Check if the hash exists\n const existing\n = (await db.getKeyFromIndex(this.storeName, IndexedDbArchivist.hashIndexName, hash))\n ?? (await db.getKeyFromIndex(this.storeName, IndexedDbArchivist.dataHashIndexName, hash))\n // If it does exist\n if (isDefined(existing)) {\n // Delete it\n await db.delete(this.storeName, existing)\n // Return the hash so it gets added to the list of deleted hashes\n return hash\n }\n }),\n )\n return found.filter(exists).filter(hash => uniqueHashes.includes(hash))\n })\n const deletedPayloads = payloadsToDelete.filter(payload => deletedHashes.includes(payload._hash) || deletedHashes.includes(payload._dataHash))\n this._payloadCount = this._payloadCount - deletedPayloads.length\n return deletedPayloads\n }\n\n protected async getFromCursor(\n db: IDBPDatabase<ObjectStore>,\n storeName: string,\n order: 'asc' | 'desc' = 'asc',\n limit: number = 10,\n cursor?: Hex,\n open?: boolean,\n ): Promise<WithStorageMeta[]> {\n // TODO: We have to handle the case where the cursor is not found, and then find the correct cursor to start with (thunked cursor)\n\n return await withReadOnlyStore(db, storeName, async (store) => {\n const sequenceIndex = assertEx(store?.index(IndexedDbArchivist.sequenceIndexName), () => 'Failed to get sequence index')\n let sequenceCursor: IDBPCursorWithValue<ObjectStore, [string]> | null | undefined\n const parsedCursor = isDefined(cursor)\n ? order === 'asc'\n ? IDBKeyRange.lowerBound(cursor, open)\n : IDBKeyRange.upperBound(cursor, open)\n : null\n\n sequenceCursor = await sequenceIndex.openCursor(\n parsedCursor,\n order === 'desc' ? 'prev' : 'next',\n )\n\n let remaining = limit\n const result: WithStorageMeta[] = []\n while (remaining > 0) {\n const value = sequenceCursor?.value\n if (value) {\n result.push(value)\n }\n try {\n sequenceCursor = await sequenceCursor?.advance(1)\n } catch {\n break\n }\n if (sequenceCursor === null) {\n break\n }\n remaining--\n }\n return result\n })\n }\n\n /**\n * Uses an index to get a payload by the index value, but returns the value with the primary key (from the root store)\n * @param db The db instance to use\n * @param storeName The name of the store to use\n * @param indexName The index to use\n * @param key The key to get from the index\n * @returns The primary key and the payload, or undefined if not found\n */\n protected async getFromIndexWithPrimaryKey(\n db: IDBPDatabase<ObjectStore>,\n storeName: string,\n indexName: string,\n key: IDBValidKey,\n ): Promise<[number, WithStorageMeta] | undefined> {\n return await withReadOnlyStore(db, storeName, async (store) => {\n if (store) {\n const index = store.index(indexName)\n const cursor = await index.openCursor(key)\n if (cursor) {\n const singleValue = cursor.value\n // NOTE: It's known to be a number because we are using IndexedDB supplied auto-incrementing keys\n if (typeof cursor.primaryKey !== 'number') {\n throw new TypeError('primaryKey must be a number')\n }\n\n return [cursor.primaryKey, singleValue]\n }\n }\n })\n }\n\n protected override async getHandler(hashes: string[]): Promise<WithStorageMeta[]> {\n const payloads = await this.useDb(db =>\n Promise.all(\n // Filter duplicates to prevent unnecessary DB queries\n uniq(hashes).map(async (hash) => {\n // Find by hash\n const payload = await this.getFromIndexWithPrimaryKey(db, this.storeName, IndexedDbArchivist.hashIndexName, hash)\n // If found, return\n if (payload) return payload\n // Otherwise, find by data hash\n return this.getFromIndexWithPrimaryKey(db, this.storeName, IndexedDbArchivist.dataHashIndexName, hash)\n }),\n ))\n\n const found = new Set<string>()\n return (\n payloads\n // Filter out not found\n .filter(exists)\n // Sort by primary key\n .sort((a, b) => a![0] - b![0])\n // Filter out duplicates by hash\n .filter(([_key, payload]) => {\n if (found.has(payload._hash)) {\n return false\n } else {\n found.add(payload._hash)\n return true\n }\n })\n // Return just the payloads\n .map(([_key, payload]) => payload)\n )\n }\n\n protected override async insertHandler(payloads: WithStorageMeta<Payload>[]): Promise<WithStorageMeta<Payload>[]> {\n return await this.useDb(async (db) => {\n // Perform all inserts via a single transaction to ensure atomicity\n // with respect to checking for the pre-existence of the hash.\n // This is done to prevent duplicate root hashes due to race\n // conditions between checking vs insertion.\n return await withReadWriteStore(db, this.storeName, async (store) => {\n // Return only the payloads that were successfully inserted\n if (store) {\n const inserted: WithStorageMeta<Payload>[] = []\n await Promise.all(\n payloads.map(async (payload) => {\n // only insert if hash does not already exist\n if (!await store.index(IndexedDbArchivist.hashIndexName).get(payload._hash)) {\n // Insert the payload\n await store.put(payload)\n // Add it to the inserted list\n inserted.push(payload)\n }\n }),\n )\n this._payloadCount = this._payloadCount + inserted.length\n return inserted\n } else {\n throw new Error('Failed to get store')\n }\n })\n })\n }\n\n protected override async nextHandler(options?: ArchivistNextOptions): Promise<WithStorageMeta<Payload>[]> {\n const {\n limit, cursor, order, open = true,\n } = options ?? {}\n return await this.useDb(async (db) => {\n return await this.getFromCursor(db, this.storeName, order, limit ?? 10, cursor, open)\n })\n }\n\n protected override payloadCountHandler() {\n return this._payloadCount\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // NOTE: We could defer this creation to first access but we\n // want to fail fast here in case something is wrong\n // also, gets current payloadCount\n this._payloadCount = await this.useDb(async (db) => {\n return await db.count(this.storeName)\n })\n return true\n }\n\n /**\n * Executes a callback with the initialized DB and then closes the db\n * @param callback The method to execute with the initialized DB\n * @returns\n */\n private async useDb<T>(callback: (db: IDBPDatabase<ObjectStore>) => Promise<T> | T): Promise<T> {\n return await withDb<ObjectStore, T>(this.dbName, async (db) => {\n return await callback(db)\n }, { [this.storeName]: this.indexes }, this.logger)\n }\n}\n","export const IndexedDbArchivistSchema = 'network.xyo.archivist.indexeddb' as const\nexport type IndexedDbArchivistSchema = typeof IndexedDbArchivistSchema\n","import type { ArchivistConfig } from '@xyo-network/archivist-model'\n\nimport { IndexedDbArchivistSchema } from './Schema.ts'\n\nexport type IndexedDbArchivistConfigSchema = `${IndexedDbArchivistSchema}.config`\nexport const IndexedDbArchivistConfigSchema: IndexedDbArchivistConfigSchema = `${IndexedDbArchivistSchema}.config`\n\nexport type IndexedDbArchivistConfig<TStoreName extends string = string> = ArchivistConfig<{\n /**\n * The database name\n */\n dbName?: string\n /**\n * The version of the DB, defaults to 1\n */\n dbVersion?: number\n schema: IndexedDbArchivistConfigSchema\n /**\n * The name of the object store\n */\n storeName?: TStoreName\n}>\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY;AACrB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAEvB;AAAA,EAEE;AAAA,EACA;AAAA,EAAmB;AAAA,OACd;AACP,SAAS,WAAW,mBAAmB;AACvC,SAAS,mBAAmB,yBAAyB;AACrD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;;;ACvBxB,IAAM,2BAA2B;;;ACKjC,IAAM,iCAAiE,GAAG,wBAAwB;;;AFgClG,IAAM,qBAAN,cAGG,kBAAuC;AAAA,EAiCvC;AAAA,EACA;AAAA,EACA,gBAAgB;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASR,IAAI,SAAS;AACX,QAAI,YAAY,KAAK,OAAO,GAAG;AAC7B,UAAI,UAAU,KAAK,QAAQ,MAAM,GAAG;AAClC,aAAK,UAAU,KAAK,QAAQ;AAAA,MAC9B,OAAO;AACL,YAAI,UAAU,KAAK,QAAQ,IAAI,GAAG;AAChC,eAAK,QAAQ,KAAK,2CAA2C,KAAK,QAAQ,IAAI;AAC9E,eAAK,UAA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E;AAAA,EAAG,YAAY;AAAA,EAAO,QAAQ;AACjD;AAEA,cAvBW,oBAuBa,iBAAkC;AAAA,EACxD,KAAK,EAAE,WAAW,EAAE;AAAA,EAAG,YAAY;AAAA,EAAO,QAAQ;AACpD;AAAA;AAGA,cA5BW,oBA4BK,iBAAgB,uBAAuB,mBAAmB,SAAS;AAAA;AAEnF,cA9BW,oBA8BK,qBAAoB,uBAAuB,mBAAmB,aAAa;AAAA;AAE3F,cAhCW,oBAgCK,mBAAkB,uBAAuB,mBAAmB,WAAW;AAAA;AAEvF,cAlCW,oBAkCK,qBAAoB,uBAAuB,mBAAmB,aAAa;AAlChF,qBAAN;AAAA,EADN,gBAAgB;AAAA,GACJ;","names":[]}
@@ -27,6 +27,7 @@ export declare class IndexedDbArchivist<TParams extends IndexedDbArchivistParams
27
27
  static readonly sequenceIndexName: string;
28
28
  private _dbName?;
29
29
  private _dbVersion?;
30
+ private _payloadCount;
30
31
  private _storeName?;
31
32
  /**
32
33
  * The database name. If not supplied via config, it defaults
@@ -66,6 +67,7 @@ export declare class IndexedDbArchivist<TParams extends IndexedDbArchivistParams
66
67
  protected getHandler(hashes: string[]): Promise<WithStorageMeta[]>;
67
68
  protected insertHandler(payloads: WithStorageMeta<Payload>[]): Promise<WithStorageMeta<Payload>[]>;
68
69
  protected nextHandler(options?: ArchivistNextOptions): Promise<WithStorageMeta<Payload>[]>;
70
+ protected payloadCountHandler(): number;
69
71
  protected startHandler(): Promise<boolean>;
70
72
  /**
71
73
  * Executes a callback with the initialized DB and then closes the db
@@ -1 +1 @@
1
- {"version":3,"file":"Archivist.d.ts","sourceRoot":"","sources":["../../src/Archivist.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EACL,WAAW,EAGZ,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,iBAAiB,EAAqB,MAAM,iCAAiC,CAAA;AACtF,OAAO,EAKL,wBAAw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AC,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;cA8BxF,WAAW,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;cAStF,mBAAmB;cAIb,YAAY;IAWrC;;;;OAIG;YACW,KAAK;CAKpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/archivist-indexeddb",
3
- "version": "3.16.1",
3
+ "version": "3.17.1",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -29,33 +29,33 @@
29
29
  "module": "dist/browser/index.mjs",
30
30
  "types": "dist/types/index.d.ts",
31
31
  "dependencies": {
32
- "@xylabs/array": "^4.9.18",
33
- "@xylabs/assert": "^4.9.18",
34
- "@xylabs/exists": "^4.9.18",
35
- "@xylabs/hex": "^4.9.18",
36
- "@xylabs/indexed-db": "^4.9.18",
37
- "@xylabs/typeof": "^4.9.18",
38
- "@xyo-network/archivist-abstract": "^3.16.1",
39
- "@xyo-network/archivist-model": "^3.16.1",
40
- "@xyo-network/module-model": "^3.16.1",
41
- "@xyo-network/payload-builder": "^3.16.1",
42
- "@xyo-network/payload-model": "^3.16.1",
32
+ "@xylabs/array": "^4.11.2",
33
+ "@xylabs/assert": "^4.11.2",
34
+ "@xylabs/exists": "^4.11.2",
35
+ "@xylabs/hex": "^4.11.2",
36
+ "@xylabs/indexed-db": "^4.11.2",
37
+ "@xylabs/typeof": "^4.11.2",
38
+ "@xyo-network/archivist-abstract": "^3.17.1",
39
+ "@xyo-network/archivist-model": "^3.17.1",
40
+ "@xyo-network/module-model": "^3.17.1",
41
+ "@xyo-network/payload-builder": "^3.17.1",
42
+ "@xyo-network/payload-model": "^3.17.1",
43
43
  "idb": "^8.0.3"
44
44
  },
45
45
  "devDependencies": {
46
- "@xylabs/delay": "^4.9.18",
47
- "@xylabs/object": "^4.9.18",
48
- "@xylabs/ts-scripts-yarn3": "^6.5.6",
49
- "@xylabs/tsconfig": "^6.5.6",
50
- "@xyo-network/account": "^3.16.1",
51
- "@xyo-network/account-model": "^3.16.1",
52
- "@xyo-network/archivist-acceptance-tests": "^3.16.1",
53
- "@xyo-network/id-payload-plugin": "^3.16.1",
54
- "@xyo-network/payload-wrapper": "^3.16.1",
46
+ "@xylabs/delay": "^4.11.2",
47
+ "@xylabs/object": "^4.11.2",
48
+ "@xylabs/ts-scripts-yarn3": "^6.5.7",
49
+ "@xylabs/tsconfig": "^6.5.7",
50
+ "@xyo-network/account": "^3.17.1",
51
+ "@xyo-network/account-model": "^3.17.1",
52
+ "@xyo-network/archivist-acceptance-tests": "^3.17.1",
53
+ "@xyo-network/id-payload-plugin": "^3.17.1",
54
+ "@xyo-network/payload-wrapper": "^3.17.1",
55
55
  "fake-indexeddb": "^6.0.1",
56
56
  "typescript": "^5.8.3",
57
57
  "uuid": "^11.1.0",
58
- "vitest": "^3.1.3"
58
+ "vitest": "^3.1.4"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public"
package/src/Archivist.ts CHANGED
@@ -73,6 +73,7 @@ export class IndexedDbArchivist<
73
73
 
74
74
  private _dbName?: string
75
75
  private _dbVersion?: number
76
+ private _payloadCount = 0
76
77
  private _storeName?: string
77
78
 
78
79
  /**
@@ -151,11 +152,13 @@ export class IndexedDbArchivist<
151
152
  // Get all payloads from the store
152
153
  const payloads = await this.useDb(db => db.getAll(this.storeName))
153
154
  // Remove any metadata before returning to the client
155
+ this._payloadCount = payloads.length
154
156
  return payloads
155
157
  }
156
158
 
157
159
  protected override async clearHandler(): Promise<void> {
158
160
  await this.useDb(db => db.clear(this.storeName))
161
+ this._payloadCount = 0
159
162
  }
160
163
 
161
164
  protected override async deleteHandler(hashes: Hash[]): Promise<WithStorageMeta<Payload>[]> {
@@ -188,7 +191,9 @@ export class IndexedDbArchivist<
188
191
  )
189
192
  return found.filter(exists).filter(hash => uniqueHashes.includes(hash))
190
193
  })
191
- return payloadsToDelete.filter(payload => deletedHashes.includes(payload._hash) || deletedHashes.includes(payload._dataHash))
194
+ const deletedPayloads = payloadsToDelete.filter(payload => deletedHashes.includes(payload._hash) || deletedHashes.includes(payload._dataHash))
195
+ this._payloadCount = this._payloadCount - deletedPayloads.length
196
+ return deletedPayloads
192
197
  }
193
198
 
194
199
  protected async getFromCursor(
@@ -323,6 +328,7 @@ export class IndexedDbArchivist<
323
328
  }
324
329
  }),
325
330
  )
331
+ this._payloadCount = this._payloadCount + inserted.length
326
332
  return inserted
327
333
  } else {
328
334
  throw new Error('Failed to get store')
@@ -340,11 +346,18 @@ export class IndexedDbArchivist<
340
346
  })
341
347
  }
342
348
 
349
+ protected override payloadCountHandler() {
350
+ return this._payloadCount
351
+ }
352
+
343
353
  protected override async startHandler() {
344
354
  await super.startHandler()
345
355
  // NOTE: We could defer this creation to first access but we
346
356
  // want to fail fast here in case something is wrong
347
- await this.useDb(() => {})
357
+ // also, gets current payloadCount
358
+ this._payloadCount = await this.useDb(async (db) => {
359
+ return await db.count(this.storeName)
360
+ })
348
361
  return true
349
362
  }
350
363