@xyo-network/archivist-indexeddb 7.4.1 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/Archivist.d.ts.map +1 -1
- package/dist/browser/index.mjs +25 -23
- package/dist/browser/index.mjs.map +2 -2
- package/package.json +14 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Archivist.d.ts","sourceRoot":"","sources":["../../src/Archivist.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAKzD,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAKhD,OAAO,EAAE,iBAAiB,EAAqB,MAAM,qCAAqC,CAAA;AAC1F,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EAErB,MAAM,kCAAkC,CAAA;AAUzC,OAAO,KAAK,EACV,OAAO,EAAE,MAAM,EAAE,eAAe,EACjC,MAAM,2BAA2B,CAAA;AAElC,OAAO,KAAK,EAAuB,YAAY,EAAE,MAAM,KAAK,CAAA;AAG5D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAE3D,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC,CAAA;AAEnE,qBACa,kBAAkB,CAC7B,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,EACnE,UAAU,SAAS,wBAAwB,GAAG,wBAAwB,CACtE,SAAQ,iBAAiB,CAAC,OAAO,EAAE,UAAU,CAAC;IAC9C,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAA2D;IAC3G,gBAAyB,mBAAmB,EAAE,MAAM,CAAiC;IACrF,MAAM,CAAC,QAAQ,CAAC,aAAa,eAAc;IAC3C,MAAM,CAAC,QAAQ,CAAC,gBAAgB,KAAI;IACpC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,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;cAoBxB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;cAkCxD,aAAa,CAAC,QAAQ,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;cAgCxF,WAAW,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;cAStF,mBAAmB,IAAI,MAAM;cAIvB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAUtD;;;;OAIG;YACW,KAAK;CAKpB"}
|
package/dist/browser/index.mjs
CHANGED
|
@@ -98,7 +98,7 @@ var IndexedDbArchivist = class extends AbstractArchivist {
|
|
|
98
98
|
* The database version. If not supplied via config, it defaults to 1.
|
|
99
99
|
*/
|
|
100
100
|
get dbVersion() {
|
|
101
|
-
this._dbVersion
|
|
101
|
+
this._dbVersion ??= this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion;
|
|
102
102
|
return this._dbVersion;
|
|
103
103
|
}
|
|
104
104
|
get queries() {
|
|
@@ -151,10 +151,11 @@ var IndexedDbArchivist = class extends AbstractArchivist {
|
|
|
151
151
|
const uniqueHashes = [...new Set(hashes)];
|
|
152
152
|
const pairs = await PayloadBuilder.hashPairs(await this.getHandler(uniqueHashes));
|
|
153
153
|
const payloadsToDelete = pairs.map(([payload]) => payload);
|
|
154
|
-
const
|
|
154
|
+
const hashPairs = await Promise.all(pairs.map(async (pair) => {
|
|
155
155
|
const dataHash0 = await PayloadBuilder.dataHash(pair[0]);
|
|
156
156
|
return [dataHash0, pair[1]];
|
|
157
|
-
}))
|
|
157
|
+
}));
|
|
158
|
+
const hashesToDelete = hashPairs.flat();
|
|
158
159
|
const distinctHashes = [...new Set(hashesToDelete)];
|
|
159
160
|
const deletedHashes = await this.useDb(async (db) => {
|
|
160
161
|
const found = await Promise.all(
|
|
@@ -169,7 +170,7 @@ var IndexedDbArchivist = class extends AbstractArchivist {
|
|
|
169
170
|
return found.filter(exists).filter((hash) => uniqueHashes.includes(hash));
|
|
170
171
|
});
|
|
171
172
|
const deletedPayloads = payloadsToDelete.filter((payload) => deletedHashes.includes(payload._hash) || deletedHashes.includes(payload._dataHash));
|
|
172
|
-
this._payloadCount
|
|
173
|
+
this._payloadCount -= deletedPayloads.length;
|
|
173
174
|
return deletedPayloads;
|
|
174
175
|
}
|
|
175
176
|
async getFromCursor(db, storeName, order = "asc", limit = 10, cursor, open) {
|
|
@@ -185,7 +186,7 @@ var IndexedDbArchivist = class extends AbstractArchivist {
|
|
|
185
186
|
const result = [];
|
|
186
187
|
while (remaining > 0) {
|
|
187
188
|
const value = sequenceCursor?.value;
|
|
188
|
-
if (value) {
|
|
189
|
+
if (isDefined(value)) {
|
|
189
190
|
result.push(value);
|
|
190
191
|
}
|
|
191
192
|
try {
|
|
@@ -211,16 +212,17 @@ var IndexedDbArchivist = class extends AbstractArchivist {
|
|
|
211
212
|
*/
|
|
212
213
|
async getFromIndexWithPrimaryKey(db, storeName, indexName, key) {
|
|
213
214
|
return await withReadOnlyStore(db, storeName, async (store) => {
|
|
214
|
-
if (store) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return [cursor.primaryKey, singleValue];
|
|
215
|
+
if (!store) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const index = store.index(indexName);
|
|
219
|
+
const cursor = await index.openCursor(key);
|
|
220
|
+
if (cursor) {
|
|
221
|
+
if (typeof cursor.primaryKey !== "number") {
|
|
222
|
+
throw new TypeError("primaryKey must be a number");
|
|
223
223
|
}
|
|
224
|
+
const singleValue = cursor.value;
|
|
225
|
+
return [cursor.primaryKey, singleValue];
|
|
224
226
|
}
|
|
225
227
|
});
|
|
226
228
|
}
|
|
@@ -237,10 +239,9 @@ var IndexedDbArchivist = class extends AbstractArchivist {
|
|
|
237
239
|
return payloads.filter(exists).toSorted((a, b) => a[0] - b[0]).filter(([_key, payload]) => {
|
|
238
240
|
if (found.has(payload._hash)) {
|
|
239
241
|
return false;
|
|
240
|
-
} else {
|
|
241
|
-
found.add(payload._hash);
|
|
242
|
-
return true;
|
|
243
242
|
}
|
|
243
|
+
found.add(payload._hash);
|
|
244
|
+
return true;
|
|
244
245
|
}).map(([_key, payload]) => payload);
|
|
245
246
|
}
|
|
246
247
|
async insertHandler(payloads) {
|
|
@@ -250,17 +251,18 @@ var IndexedDbArchivist = class extends AbstractArchivist {
|
|
|
250
251
|
const inserted = [];
|
|
251
252
|
await Promise.all(
|
|
252
253
|
payloads.map(async (payload) => {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
const existingPayload = await store.index(IndexedDbArchivist.hashIndexName).get(payload._hash);
|
|
255
|
+
if (isDefined(existingPayload)) {
|
|
256
|
+
return;
|
|
256
257
|
}
|
|
258
|
+
await store.put(payload);
|
|
259
|
+
inserted.push(payload);
|
|
257
260
|
})
|
|
258
261
|
);
|
|
259
|
-
this._payloadCount
|
|
262
|
+
this._payloadCount += inserted.length;
|
|
260
263
|
return inserted;
|
|
261
|
-
} else {
|
|
262
|
-
throw new Error("Failed to get store");
|
|
263
264
|
}
|
|
265
|
+
throw new Error("Failed to get store");
|
|
264
266
|
});
|
|
265
267
|
});
|
|
266
268
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Archivist.ts", "../../src/Config.ts", "../../src/Schema.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-return */\nimport type { ObjectStore } from '@ariestools/indexed-db'\nimport {\n withDb,\n withReadOnlyStore, withReadWriteStore,\n} from '@ariestools/indexed-db'\nimport type { Hash, Hex } from '@ariestools/sdk'\nimport {\n assertEx,\n exists, isDefined, isUndefined, uniq,\n} from '@ariestools/sdk'\nimport { AbstractArchivist, StorageClassLabel } from '@xyo-network/sdk/archivist-abstract'\nimport type {\n ArchivistModuleEventData,\n ArchivistNextOptions,\n IndexDescription,\n} from '@xyo-network/sdk/archivist-model'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistNextQuerySchema,\n buildStandardIndexName,\n} from '@xyo-network/sdk/archivist-model'\nimport { creatableModule } from '@xyo-network/sdk/module-model'\nimport type {\n Payload, Schema, WithStorageMeta,\n} from '@xyo-network/sdk-protocol'\nimport { PayloadBuilder } from '@xyo-network/sdk-protocol'\nimport type { IDBPCursorWithValue, IDBPDatabase } from 'idb'\n\nimport { IndexedDbArchivistConfigSchema } from './Config.ts'\nimport type { IndexedDbArchivistParams } from './Params.ts'\n\nexport type PayloadStore = Record<string, WithStorageMeta<Payload>>\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: {\n 'network.xyo.storage.class': string\n } = { ...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: string = buildStandardIndexName(IndexedDbArchivist.hashIndex)\n // eslint-disable-next-line @typescript-eslint/member-ordering\n static readonly dataHashIndexName: string = buildStandardIndexName(IndexedDbArchivist.dataHashIndex)\n // eslint-disable-next-line @typescript-eslint/member-ordering\n static readonly schemaIndexName: string = buildStandardIndexName(IndexedDbArchivist.schemaIndex)\n // eslint-disable-next-line @typescript-eslint/member-ordering\n static readonly sequenceIndexName: string = 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(): string {\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(): number {\n this._dbVersion = this._dbVersion ?? this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion\n return this._dbVersion\n }\n\n override get queries(): Schema[] {\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(): string {\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 = 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 = 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 // 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 .toSorted((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(): number {\n return this._payloadCount\n }\n\n protected override async startHandler(): Promise<void> {\n await super.startHandler()\n // 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 }\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", "import {\n zodAsFactory, zodIsFactory, zodToFactory,\n} from '@ariestools/sdk'\nimport type { ArchivistConfig } from '@xyo-network/sdk/archivist-model'\nimport { ArchivistConfigZod } from '@xyo-network/sdk/archivist-model'\nimport { asSchema } from '@xyo-network/sdk-protocol'\nimport * as z from 'zod/mini'\n\nimport { IndexedDbArchivistSchema } from './Schema.ts'\n\nexport const IndexedDbArchivistConfigSchema: string & {\n readonly __schema: true\n} = asSchema(`${IndexedDbArchivistSchema}.config`, true)\nexport type IndexedDbArchivistConfigSchema = typeof IndexedDbArchivistConfigSchema\n\nexport const IndexedDbArchivistConfigZod: z.ZodMiniObject<\n & Omit<(typeof ArchivistConfigZod)['shape'], 'schema'>\n & {\n dbName: z.ZodMiniOptional<z.ZodMiniString<string>>\n dbVersion: z.ZodMiniOptional<z.ZodMiniNumber<number>>\n schema: z.ZodMiniLiteral<IndexedDbArchivistConfigSchema>\n storeName: z.ZodMiniOptional<z.ZodMiniString<string>>\n },\n z.core.$strip\n> = z.extend(ArchivistConfigZod, {\n dbName: z.optional(z.string()),\n dbVersion: z.optional(z.number()),\n schema: z.literal(IndexedDbArchivistConfigSchema),\n storeName: z.optional(z.string()),\n})\n\nexport type IndexedDbArchivistConfigBase = z.infer<typeof IndexedDbArchivistConfigZod>\n\nexport const isIndexedDbArchivistConfig: ReturnType<typeof zodIsFactory<IndexedDbArchivistConfigBase>> = zodIsFactory(IndexedDbArchivistConfigZod)\nexport const asIndexedDbArchivistConfig: ReturnType<typeof zodAsFactory<IndexedDbArchivistConfigBase>> = zodAsFactory(IndexedDbArchivistConfigZod, 'asIndexedDbArchivistConfig')\nexport const toIndexedDbArchivistConfig: ReturnType<typeof zodToFactory<IndexedDbArchivistConfigBase>> = zodToFactory(IndexedDbArchivistConfigZod, 'toIndexedDbArchivistConfig')\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", "import { asSchema } from '@xyo-network/sdk-protocol'\n\nexport const IndexedDbArchivistSchema: 'network.xyo.archivist.indexeddb' & {\n readonly __schema: true\n} = asSchema('network.xyo.archivist.indexeddb', true)\nexport type IndexedDbArchivistSchema = typeof IndexedDbArchivistSchema\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EAAmB;AAAA,OACd;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EAAQ;AAAA,EAAW;AAAA,EAAa;AAAA,OAC3B;AACP,SAAS,mBAAmB,yBAAyB;AAMrD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAIhC,SAAS,sBAAsB;;;AC7B/B;AAAA,EACE;AAAA,EAAc;AAAA,EAAc;AAAA,OACvB;AAEP,SAAS,0BAA0B;AACnC,SAAS,YAAAA,iBAAgB;AACzB,YAAY,OAAO;;;ACNnB,SAAS,gBAAgB;AAElB,IAAM,2BAET,SAAS,mCAAmC,IAAI;;;ADM7C,IAAM,iCAETC,UAAS,GAAG,wBAAwB,WAAW,IAAI;AAGhD,IAAM,8BASP,SAAO,oBAAoB;AAAA,EAC/B,QAAU,WAAW,SAAO,CAAC;AAAA,EAC7B,WAAa,WAAW,SAAO,CAAC;AAAA,EAChC,QAAU,UAAQ,8BAA8B;AAAA,EAChD,WAAa,WAAW,SAAO,CAAC;AAClC,CAAC;AAIM,IAAM,6BAA4F,aAAa,2BAA2B;AAC1I,IAAM,6BAA4F,aAAa,6BAA6B,4BAA4B;AACxK,IAAM,6BAA4F,aAAa,6BAA6B,4BAA4B;;;ADGxK,IAAM,qBAAN,cAGG,kBAAuC;AAAA,EAmCvC;AAAA,EACA;AAAA,EACA,gBAAgB;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASR,IAAI,SAAiB;AACnB,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,UAAU,KAAK,QAAQ;AAAA,QAC9B,OAAO;AACL,eAAK,QAAQ,KAAK,4CAA4C,mBAAmB,aAAa;AAC9F,eAAK,UAAU,mBAAmB;AAAA,QACpC;AAAA,MACF;AAAA,IACF;AACA,WAAO,SAAS,KAAK,OAAO;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,YAAoB;AACtB,SAAK,
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-return */\nimport type { ObjectStore } from '@ariestools/indexed-db'\nimport {\n withDb,\n withReadOnlyStore, withReadWriteStore,\n} from '@ariestools/indexed-db'\nimport type { Hash, Hex } from '@ariestools/sdk'\nimport {\n assertEx,\n exists, isDefined, isUndefined, uniq,\n} from '@ariestools/sdk'\nimport { AbstractArchivist, StorageClassLabel } from '@xyo-network/sdk/archivist-abstract'\nimport type {\n ArchivistModuleEventData,\n ArchivistNextOptions,\n IndexDescription,\n} from '@xyo-network/sdk/archivist-model'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistNextQuerySchema,\n buildStandardIndexName,\n} from '@xyo-network/sdk/archivist-model'\nimport { creatableModule } from '@xyo-network/sdk/module-model'\nimport type {\n Payload, Schema, WithStorageMeta,\n} from '@xyo-network/sdk-protocol'\nimport { PayloadBuilder } from '@xyo-network/sdk-protocol'\nimport type { IDBPCursorWithValue, IDBPDatabase } from 'idb'\n\nimport { IndexedDbArchivistConfigSchema } from './Config.ts'\nimport type { IndexedDbArchivistParams } from './Params.ts'\n\nexport type PayloadStore = Record<string, WithStorageMeta<Payload>>\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: {\n 'network.xyo.storage.class': string\n } = { ...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: string = buildStandardIndexName(IndexedDbArchivist.hashIndex)\n // eslint-disable-next-line @typescript-eslint/member-ordering\n static readonly dataHashIndexName: string = buildStandardIndexName(IndexedDbArchivist.dataHashIndex)\n // eslint-disable-next-line @typescript-eslint/member-ordering\n static readonly schemaIndexName: string = buildStandardIndexName(IndexedDbArchivist.schemaIndex)\n // eslint-disable-next-line @typescript-eslint/member-ordering\n static readonly sequenceIndexName: string = 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(): string {\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(): number {\n this._dbVersion ??= this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion\n return this._dbVersion\n }\n\n override get queries(): Schema[] {\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(): string {\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 = pairs.map(([payload]) => payload)\n const hashPairs = await Promise.all(pairs.map(async (pair) => {\n const dataHash0 = await PayloadBuilder.dataHash(pair[0])\n return [dataHash0, pair[1]]\n }))\n const hashesToDelete = hashPairs.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 -= 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 = 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 (isDefined(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 return\n }\n\n const index = store.index(indexName)\n const cursor = await index.openCursor(key)\n if (cursor) {\n // 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 const singleValue = cursor.value\n return [cursor.primaryKey, singleValue]\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 .toSorted((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 }\n found.add(payload._hash)\n return true\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 const existingPayload = await store.index(IndexedDbArchivist.hashIndexName).get(payload._hash)\n if (isDefined(existingPayload)) {\n return\n }\n\n // Insert the payload\n await store.put(payload)\n // Add it to the inserted list\n inserted.push(payload)\n }),\n )\n this._payloadCount += inserted.length\n return inserted\n }\n throw new Error('Failed to get store')\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(): number {\n return this._payloadCount\n }\n\n protected override async startHandler(): Promise<void> {\n await super.startHandler()\n // 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 }\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", "import {\n zodAsFactory, zodIsFactory, zodToFactory,\n} from '@ariestools/sdk'\nimport type { ArchivistConfig } from '@xyo-network/sdk/archivist-model'\nimport { ArchivistConfigZod } from '@xyo-network/sdk/archivist-model'\nimport { asSchema } from '@xyo-network/sdk-protocol'\nimport * as z from 'zod/mini'\n\nimport { IndexedDbArchivistSchema } from './Schema.ts'\n\nexport const IndexedDbArchivistConfigSchema: string & {\n readonly __schema: true\n} = asSchema(`${IndexedDbArchivistSchema}.config`, true)\nexport type IndexedDbArchivistConfigSchema = typeof IndexedDbArchivistConfigSchema\n\nexport const IndexedDbArchivistConfigZod: z.ZodMiniObject<\n & Omit<(typeof ArchivistConfigZod)['shape'], 'schema'>\n & {\n dbName: z.ZodMiniOptional<z.ZodMiniString<string>>\n dbVersion: z.ZodMiniOptional<z.ZodMiniNumber<number>>\n schema: z.ZodMiniLiteral<IndexedDbArchivistConfigSchema>\n storeName: z.ZodMiniOptional<z.ZodMiniString<string>>\n },\n z.core.$strip\n> = z.extend(ArchivistConfigZod, {\n dbName: z.optional(z.string()),\n dbVersion: z.optional(z.number()),\n schema: z.literal(IndexedDbArchivistConfigSchema),\n storeName: z.optional(z.string()),\n})\n\nexport type IndexedDbArchivistConfigBase = z.infer<typeof IndexedDbArchivistConfigZod>\n\nexport const isIndexedDbArchivistConfig: ReturnType<typeof zodIsFactory<IndexedDbArchivistConfigBase>> = zodIsFactory(IndexedDbArchivistConfigZod)\nexport const asIndexedDbArchivistConfig: ReturnType<typeof zodAsFactory<IndexedDbArchivistConfigBase>> = zodAsFactory(IndexedDbArchivistConfigZod, 'asIndexedDbArchivistConfig')\nexport const toIndexedDbArchivistConfig: ReturnType<typeof zodToFactory<IndexedDbArchivistConfigBase>> = zodToFactory(IndexedDbArchivistConfigZod, 'toIndexedDbArchivistConfig')\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", "import { asSchema } from '@xyo-network/sdk-protocol'\n\nexport const IndexedDbArchivistSchema: 'network.xyo.archivist.indexeddb' & {\n readonly __schema: true\n} = asSchema('network.xyo.archivist.indexeddb', true)\nexport type IndexedDbArchivistSchema = typeof IndexedDbArchivistSchema\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EAAmB;AAAA,OACd;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EAAQ;AAAA,EAAW;AAAA,EAAa;AAAA,OAC3B;AACP,SAAS,mBAAmB,yBAAyB;AAMrD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAIhC,SAAS,sBAAsB;;;AC7B/B;AAAA,EACE;AAAA,EAAc;AAAA,EAAc;AAAA,OACvB;AAEP,SAAS,0BAA0B;AACnC,SAAS,YAAAA,iBAAgB;AACzB,YAAY,OAAO;;;ACNnB,SAAS,gBAAgB;AAElB,IAAM,2BAET,SAAS,mCAAmC,IAAI;;;ADM7C,IAAM,iCAETC,UAAS,GAAG,wBAAwB,WAAW,IAAI;AAGhD,IAAM,8BASP,SAAO,oBAAoB;AAAA,EAC/B,QAAU,WAAW,SAAO,CAAC;AAAA,EAC7B,WAAa,WAAW,SAAO,CAA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AAS,GAAG,KAAK,QAAQ,GAAG,KAAK,MAAM;AAAA,EACpD;AACF;AAjVE,cAJW,oBAIc,iBAA0B,CAAC,GAAG,mDAAM,kBAAe,8BAA8B;AAC1G,cALW,oBAKc,uBAA8B;AACvD,cANW,oBAMK,iBAAgB;AAChC,cAPW,oBAOK,oBAAmB;AACnC,cARW,oBAQK,oBAAmB;AACnC,cATW,oBASc,UAErB,EAAE,GAAG,mDAAM,WAAQ,CAAC,iBAAiB,GAAG,OAAO;AAEnD,cAbW,oBAaa,iBAAkC;AAAA,EACxD,KAAK,EAAE,WAAW,EAAE;AAAA,EAAG,YAAY;AAAA,EAAO,QAAQ;AACpD;AAEA,cAjBW,oBAiBa,aAA8B;AAAA,EACpD,KAAK,EAAE,OAAO,EAAE;AAAA,EAAG,YAAY;AAAA,EAAO,QAAQ;AAChD;AAEA,cArBW,oBAqBa,eAAgC;AAAA,EACtD,KAAK,EAAE,QAAQ,EAAE;AAAA,EAAG,YAAY;AAAA,EAAO,QAAQ;AACjD;AAEA,cAzBW,oBAyBa,iBAAkC;AAAA,EACxD,KAAK,EAAE,WAAW,EAAE;AAAA,EAAG,YAAY;AAAA,EAAO,QAAQ;AACpD;AAAA;AAGA,cA9BW,oBA8BK,iBAAwB,uBAAuB,mBAAmB,SAAS;AAAA;AAE3F,cAhCW,oBAgCK,qBAA4B,uBAAuB,mBAAmB,aAAa;AAAA;AAEnG,cAlCW,oBAkCK,mBAA0B,uBAAuB,mBAAmB,WAAW;AAAA;AAE/F,cApCW,oBAoCK,qBAA4B,uBAAuB,mBAAmB,aAAa;AApCxF,qBAAN;AAAA,EADN,gBAAgB;AAAA,GACJ;",
|
|
6
6
|
"names": ["asSchema", "asSchema"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/archivist-indexeddb",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -35,34 +35,34 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@ariestools/indexed-db": "~8.0.3",
|
|
38
|
-
"@xyo-network/sdk": "~
|
|
38
|
+
"@xyo-network/sdk": "~8.0.0",
|
|
39
39
|
"idb": "~8.0.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@ariestools/sdk": "~
|
|
43
|
-
"@ariestools/toolchain": "~
|
|
44
|
-
"@ariestools/tsconfig": "~
|
|
42
|
+
"@ariestools/sdk": "~9.0.0",
|
|
43
|
+
"@ariestools/toolchain": "~10.0.7",
|
|
44
|
+
"@ariestools/tsconfig": "~10.0.7",
|
|
45
45
|
"@opentelemetry/api": "~1.9.1",
|
|
46
46
|
"@opentelemetry/sdk-trace-base": "~2.11.0",
|
|
47
|
-
"@xyo-network/archivist-acceptance-tests": "~
|
|
48
|
-
"@xyo-network/sdk-protocol": "~
|
|
47
|
+
"@xyo-network/archivist-acceptance-tests": "~8.0.0",
|
|
48
|
+
"@xyo-network/sdk-protocol": "~8.0.0",
|
|
49
49
|
"eslint": "~10.10.0",
|
|
50
50
|
"eslint-import-resolver-typescript": "~4.4.5",
|
|
51
51
|
"fake-indexeddb": "~6.2.5",
|
|
52
52
|
"tslib": "~2.8.1",
|
|
53
53
|
"typescript": "~6.0.3",
|
|
54
54
|
"uuid": "~14.0.2",
|
|
55
|
-
"vite": "~8.
|
|
56
|
-
"vitest": "~5.0.
|
|
57
|
-
"zod": "~4.5
|
|
55
|
+
"vite": "~8.3.0",
|
|
56
|
+
"vitest": "~5.0.1",
|
|
57
|
+
"zod": "~4.6.5"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@ariestools/sdk": "^
|
|
61
|
-
"@xyo-network/sdk-protocol": "^
|
|
62
|
-
"zod": "^4.
|
|
60
|
+
"@ariestools/sdk": "^9.0",
|
|
61
|
+
"@xyo-network/sdk-protocol": "^8.0",
|
|
62
|
+
"zod": "^4.6"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
|
-
"node": "^
|
|
65
|
+
"node": "^26"
|
|
66
66
|
},
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public"
|