@xyo-network/diviner-boundwitness-indexeddb 2.106.0 → 2.107.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.
- package/dist/browser/Config.d.cts +0 -16
- package/dist/browser/Config.d.cts.map +1 -1
- package/dist/browser/Config.d.mts +0 -16
- package/dist/browser/Config.d.mts.map +1 -1
- package/dist/browser/Config.d.ts +0 -16
- package/dist/browser/Config.d.ts.map +1 -1
- package/dist/browser/Diviner.d.cts +0 -23
- package/dist/browser/Diviner.d.cts.map +1 -1
- package/dist/browser/Diviner.d.mts +0 -23
- package/dist/browser/Diviner.d.mts.map +1 -1
- package/dist/browser/Diviner.d.ts +0 -23
- package/dist/browser/Diviner.d.ts.map +1 -1
- package/dist/browser/index.cjs +1 -171
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +1 -150
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/Config.d.cts +0 -16
- package/dist/neutral/Config.d.cts.map +1 -1
- package/dist/neutral/Config.d.mts +0 -16
- package/dist/neutral/Config.d.mts.map +1 -1
- package/dist/neutral/Config.d.ts +0 -16
- package/dist/neutral/Config.d.ts.map +1 -1
- package/dist/neutral/Diviner.d.cts +0 -23
- package/dist/neutral/Diviner.d.cts.map +1 -1
- package/dist/neutral/Diviner.d.mts +0 -23
- package/dist/neutral/Diviner.d.mts.map +1 -1
- package/dist/neutral/Diviner.d.ts +0 -23
- package/dist/neutral/Diviner.d.ts.map +1 -1
- package/dist/neutral/index.cjs +1 -171
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +1 -150
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/Config.d.cts +0 -16
- package/dist/node/Config.d.cts.map +1 -1
- package/dist/node/Config.d.mts +0 -16
- package/dist/node/Config.d.mts.map +1 -1
- package/dist/node/Config.d.ts +0 -16
- package/dist/node/Config.d.ts.map +1 -1
- package/dist/node/Diviner.d.cts +0 -23
- package/dist/node/Diviner.d.cts.map +1 -1
- package/dist/node/Diviner.d.mts +0 -23
- package/dist/node/Diviner.d.mts.map +1 -1
- package/dist/node/Diviner.d.ts +0 -23
- package/dist/node/Diviner.d.ts.map +1 -1
- package/dist/node/index.cjs +1 -185
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +1 -158
- package/dist/node/index.js.map +1 -1
- package/package.json +18 -18
|
@@ -3,28 +3,12 @@ import { DivinerConfig } from '@xyo-network/diviner-model';
|
|
|
3
3
|
export declare const IndexedDbBoundWitnessDivinerConfigSchema: "network.xyo.diviner.boundwitness.indexeddb.config";
|
|
4
4
|
export type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema;
|
|
5
5
|
export type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{
|
|
6
|
-
/**
|
|
7
|
-
* The database name
|
|
8
|
-
*/
|
|
9
6
|
dbName?: string;
|
|
10
|
-
/**
|
|
11
|
-
* The version of the DB, defaults to 1
|
|
12
|
-
*/
|
|
13
7
|
dbVersion?: number;
|
|
14
8
|
schema: IndexedDbBoundWitnessDivinerConfigSchema;
|
|
15
|
-
/**
|
|
16
|
-
* The storage configuration
|
|
17
|
-
* // TODO: Hoist to main diviner config
|
|
18
|
-
*/
|
|
19
9
|
storage?: {
|
|
20
|
-
/**
|
|
21
|
-
* The indexes to create on the object store
|
|
22
|
-
*/
|
|
23
10
|
indexes?: IndexDescription[];
|
|
24
11
|
};
|
|
25
|
-
/**
|
|
26
|
-
* The name of the object store
|
|
27
|
-
*/
|
|
28
12
|
storeName?: string;
|
|
29
13
|
}>;
|
|
30
14
|
//# sourceMappingURL=Config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,eAAO,MAAM,wCAAwC,qDAA0D,CAAA;AAC/G,MAAM,MAAM,wCAAwC,GAAG,OAAO,wCAAwC,CAAA;AAEtG,MAAM,MAAM,kCAAkC,GAAG,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,eAAO,MAAM,wCAAwC,qDAA0D,CAAA;AAC/G,MAAM,MAAM,wCAAwC,GAAG,OAAO,wCAAwC,CAAA;AAEtG,MAAM,MAAM,kCAAkC,GAAG,aAAa,CAAC;IAI7D,MAAM,CAAC,EAAE,MAAM,CAAA;IAIf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,wCAAwC,CAAA;IAKhD,OAAO,CAAC,EAAE;QAIR,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;KAC7B,CAAA;IAID,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAC,CAAA"}
|
|
@@ -3,28 +3,12 @@ import { DivinerConfig } from '@xyo-network/diviner-model';
|
|
|
3
3
|
export declare const IndexedDbBoundWitnessDivinerConfigSchema: "network.xyo.diviner.boundwitness.indexeddb.config";
|
|
4
4
|
export type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema;
|
|
5
5
|
export type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{
|
|
6
|
-
/**
|
|
7
|
-
* The database name
|
|
8
|
-
*/
|
|
9
6
|
dbName?: string;
|
|
10
|
-
/**
|
|
11
|
-
* The version of the DB, defaults to 1
|
|
12
|
-
*/
|
|
13
7
|
dbVersion?: number;
|
|
14
8
|
schema: IndexedDbBoundWitnessDivinerConfigSchema;
|
|
15
|
-
/**
|
|
16
|
-
* The storage configuration
|
|
17
|
-
* // TODO: Hoist to main diviner config
|
|
18
|
-
*/
|
|
19
9
|
storage?: {
|
|
20
|
-
/**
|
|
21
|
-
* The indexes to create on the object store
|
|
22
|
-
*/
|
|
23
10
|
indexes?: IndexDescription[];
|
|
24
11
|
};
|
|
25
|
-
/**
|
|
26
|
-
* The name of the object store
|
|
27
|
-
*/
|
|
28
12
|
storeName?: string;
|
|
29
13
|
}>;
|
|
30
14
|
//# sourceMappingURL=Config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,eAAO,MAAM,wCAAwC,qDAA0D,CAAA;AAC/G,MAAM,MAAM,wCAAwC,GAAG,OAAO,wCAAwC,CAAA;AAEtG,MAAM,MAAM,kCAAkC,GAAG,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,eAAO,MAAM,wCAAwC,qDAA0D,CAAA;AAC/G,MAAM,MAAM,wCAAwC,GAAG,OAAO,wCAAwC,CAAA;AAEtG,MAAM,MAAM,kCAAkC,GAAG,aAAa,CAAC;IAI7D,MAAM,CAAC,EAAE,MAAM,CAAA;IAIf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,wCAAwC,CAAA;IAKhD,OAAO,CAAC,EAAE;QAIR,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;KAC7B,CAAA;IAID,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAC,CAAA"}
|
package/dist/browser/Config.d.ts
CHANGED
|
@@ -3,28 +3,12 @@ import { DivinerConfig } from '@xyo-network/diviner-model';
|
|
|
3
3
|
export declare const IndexedDbBoundWitnessDivinerConfigSchema: "network.xyo.diviner.boundwitness.indexeddb.config";
|
|
4
4
|
export type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema;
|
|
5
5
|
export type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{
|
|
6
|
-
/**
|
|
7
|
-
* The database name
|
|
8
|
-
*/
|
|
9
6
|
dbName?: string;
|
|
10
|
-
/**
|
|
11
|
-
* The version of the DB, defaults to 1
|
|
12
|
-
*/
|
|
13
7
|
dbVersion?: number;
|
|
14
8
|
schema: IndexedDbBoundWitnessDivinerConfigSchema;
|
|
15
|
-
/**
|
|
16
|
-
* The storage configuration
|
|
17
|
-
* // TODO: Hoist to main diviner config
|
|
18
|
-
*/
|
|
19
9
|
storage?: {
|
|
20
|
-
/**
|
|
21
|
-
* The indexes to create on the object store
|
|
22
|
-
*/
|
|
23
10
|
indexes?: IndexDescription[];
|
|
24
11
|
};
|
|
25
|
-
/**
|
|
26
|
-
* The name of the object store
|
|
27
|
-
*/
|
|
28
12
|
storeName?: string;
|
|
29
13
|
}>;
|
|
30
14
|
//# sourceMappingURL=Config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,eAAO,MAAM,wCAAwC,qDAA0D,CAAA;AAC/G,MAAM,MAAM,wCAAwC,GAAG,OAAO,wCAAwC,CAAA;AAEtG,MAAM,MAAM,kCAAkC,GAAG,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,eAAO,MAAM,wCAAwC,qDAA0D,CAAA;AAC/G,MAAM,MAAM,wCAAwC,GAAG,OAAO,wCAAwC,CAAA;AAEtG,MAAM,MAAM,kCAAkC,GAAG,aAAa,CAAC;IAI7D,MAAM,CAAC,EAAE,MAAM,CAAA;IAIf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,wCAAwC,CAAA;IAKhD,OAAO,CAAC,EAAE;QAIR,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;KAC7B,CAAA;IAID,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAC,CAAA"}
|
|
@@ -6,35 +6,12 @@ import { IndexedDbBoundWitnessDivinerParams } from './Params';
|
|
|
6
6
|
export declare class IndexedDbBoundWitnessDiviner<TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams, TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload, TOut extends BoundWitness = BoundWitness> extends BoundWitnessDiviner<TParams, TIn, TOut> {
|
|
7
7
|
static readonly configSchemas: Schema[];
|
|
8
8
|
static readonly defaultConfigSchema: Schema;
|
|
9
|
-
/**
|
|
10
|
-
* The database name. If not supplied via config, it defaults
|
|
11
|
-
* to the archivist's name and if archivist's name is not supplied,
|
|
12
|
-
* it defaults to `archivist`. This behavior
|
|
13
|
-
* biases towards a single, isolated DB per archivist which seems to
|
|
14
|
-
* make the most sense for 99% of use cases.
|
|
15
|
-
*/
|
|
16
9
|
get dbName(): string;
|
|
17
|
-
/**
|
|
18
|
-
* The database version. If not supplied via config, it defaults to 1.
|
|
19
|
-
*/
|
|
20
10
|
get dbVersion(): number;
|
|
21
|
-
/**
|
|
22
|
-
* The name of the object store. If not supplied via config, it defaults
|
|
23
|
-
* to `payloads`.
|
|
24
|
-
*/
|
|
25
11
|
get storeName(): string;
|
|
26
12
|
protected divineHandler(payloads?: TIn[]): Promise<TOut[]>;
|
|
27
13
|
protected startHandler(): Promise<boolean>;
|
|
28
|
-
/**
|
|
29
|
-
* Checks that the desired DB/objectStore exists and is initialized to the correct version
|
|
30
|
-
* @returns The initialized DB or undefined if it does not exist in the desired state
|
|
31
|
-
*/
|
|
32
14
|
private tryGetInitializedDb;
|
|
33
|
-
/**
|
|
34
|
-
* Executes a callback with the initialized DB and then closes the db
|
|
35
|
-
* @param callback The method to execute with the initialized DB
|
|
36
|
-
* @returns
|
|
37
|
-
*/
|
|
38
15
|
private tryUseDb;
|
|
39
16
|
}
|
|
40
17
|
//# sourceMappingURL=Diviner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAE5H,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAInD,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAmB7D,qBAAa,4BAA4B,CACvC,OAAO,SAAS,kCAAkC,GAAG,kCAAkC,EACvF,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,YAAY,GAAG,YAAY,CACxC,SAAQ,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/C,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAqE;IACrH,gBAAyB,mBAAmB,EAAE,MAAM,CAA2C;
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAE5H,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAInD,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAmB7D,qBAAa,4BAA4B,CACvC,OAAO,SAAS,kCAAkC,GAAG,kCAAkC,EACvF,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,YAAY,GAAG,YAAY,CACxC,SAAQ,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/C,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAqE;IACrH,gBAAyB,mBAAmB,EAAE,MAAM,CAA2C;IAS/F,IAAI,MAAM,WAET;IAKD,IAAI,SAAS,WAEZ;IAMD,IAAI,SAAS,WAEZ;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cA8DhD,YAAY;YAYvB,mBAAmB;YA6BnB,QAAQ;CAcvB"}
|
|
@@ -6,35 +6,12 @@ import { IndexedDbBoundWitnessDivinerParams } from './Params';
|
|
|
6
6
|
export declare class IndexedDbBoundWitnessDiviner<TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams, TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload, TOut extends BoundWitness = BoundWitness> extends BoundWitnessDiviner<TParams, TIn, TOut> {
|
|
7
7
|
static readonly configSchemas: Schema[];
|
|
8
8
|
static readonly defaultConfigSchema: Schema;
|
|
9
|
-
/**
|
|
10
|
-
* The database name. If not supplied via config, it defaults
|
|
11
|
-
* to the archivist's name and if archivist's name is not supplied,
|
|
12
|
-
* it defaults to `archivist`. This behavior
|
|
13
|
-
* biases towards a single, isolated DB per archivist which seems to
|
|
14
|
-
* make the most sense for 99% of use cases.
|
|
15
|
-
*/
|
|
16
9
|
get dbName(): string;
|
|
17
|
-
/**
|
|
18
|
-
* The database version. If not supplied via config, it defaults to 1.
|
|
19
|
-
*/
|
|
20
10
|
get dbVersion(): number;
|
|
21
|
-
/**
|
|
22
|
-
* The name of the object store. If not supplied via config, it defaults
|
|
23
|
-
* to `payloads`.
|
|
24
|
-
*/
|
|
25
11
|
get storeName(): string;
|
|
26
12
|
protected divineHandler(payloads?: TIn[]): Promise<TOut[]>;
|
|
27
13
|
protected startHandler(): Promise<boolean>;
|
|
28
|
-
/**
|
|
29
|
-
* Checks that the desired DB/objectStore exists and is initialized to the correct version
|
|
30
|
-
* @returns The initialized DB or undefined if it does not exist in the desired state
|
|
31
|
-
*/
|
|
32
14
|
private tryGetInitializedDb;
|
|
33
|
-
/**
|
|
34
|
-
* Executes a callback with the initialized DB and then closes the db
|
|
35
|
-
* @param callback The method to execute with the initialized DB
|
|
36
|
-
* @returns
|
|
37
|
-
*/
|
|
38
15
|
private tryUseDb;
|
|
39
16
|
}
|
|
40
17
|
//# sourceMappingURL=Diviner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAE5H,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAInD,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAmB7D,qBAAa,4BAA4B,CACvC,OAAO,SAAS,kCAAkC,GAAG,kCAAkC,EACvF,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,YAAY,GAAG,YAAY,CACxC,SAAQ,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/C,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAqE;IACrH,gBAAyB,mBAAmB,EAAE,MAAM,CAA2C;
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAE5H,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAInD,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAmB7D,qBAAa,4BAA4B,CACvC,OAAO,SAAS,kCAAkC,GAAG,kCAAkC,EACvF,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,YAAY,GAAG,YAAY,CACxC,SAAQ,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/C,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAqE;IACrH,gBAAyB,mBAAmB,EAAE,MAAM,CAA2C;IAS/F,IAAI,MAAM,WAET;IAKD,IAAI,SAAS,WAEZ;IAMD,IAAI,SAAS,WAEZ;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cA8DhD,YAAY;YAYvB,mBAAmB;YA6BnB,QAAQ;CAcvB"}
|
|
@@ -6,35 +6,12 @@ import { IndexedDbBoundWitnessDivinerParams } from './Params';
|
|
|
6
6
|
export declare class IndexedDbBoundWitnessDiviner<TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams, TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload, TOut extends BoundWitness = BoundWitness> extends BoundWitnessDiviner<TParams, TIn, TOut> {
|
|
7
7
|
static readonly configSchemas: Schema[];
|
|
8
8
|
static readonly defaultConfigSchema: Schema;
|
|
9
|
-
/**
|
|
10
|
-
* The database name. If not supplied via config, it defaults
|
|
11
|
-
* to the archivist's name and if archivist's name is not supplied,
|
|
12
|
-
* it defaults to `archivist`. This behavior
|
|
13
|
-
* biases towards a single, isolated DB per archivist which seems to
|
|
14
|
-
* make the most sense for 99% of use cases.
|
|
15
|
-
*/
|
|
16
9
|
get dbName(): string;
|
|
17
|
-
/**
|
|
18
|
-
* The database version. If not supplied via config, it defaults to 1.
|
|
19
|
-
*/
|
|
20
10
|
get dbVersion(): number;
|
|
21
|
-
/**
|
|
22
|
-
* The name of the object store. If not supplied via config, it defaults
|
|
23
|
-
* to `payloads`.
|
|
24
|
-
*/
|
|
25
11
|
get storeName(): string;
|
|
26
12
|
protected divineHandler(payloads?: TIn[]): Promise<TOut[]>;
|
|
27
13
|
protected startHandler(): Promise<boolean>;
|
|
28
|
-
/**
|
|
29
|
-
* Checks that the desired DB/objectStore exists and is initialized to the correct version
|
|
30
|
-
* @returns The initialized DB or undefined if it does not exist in the desired state
|
|
31
|
-
*/
|
|
32
14
|
private tryGetInitializedDb;
|
|
33
|
-
/**
|
|
34
|
-
* Executes a callback with the initialized DB and then closes the db
|
|
35
|
-
* @param callback The method to execute with the initialized DB
|
|
36
|
-
* @returns
|
|
37
|
-
*/
|
|
38
15
|
private tryUseDb;
|
|
39
16
|
}
|
|
40
17
|
//# sourceMappingURL=Diviner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAE5H,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAInD,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172 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// src/index.ts
|
|
22
|
-
var src_exports = {};
|
|
23
|
-
__export(src_exports, {
|
|
24
|
-
IndexedDbBoundWitnessDiviner: () => IndexedDbBoundWitnessDiviner,
|
|
25
|
-
IndexedDbBoundWitnessDivinerConfigSchema: () => IndexedDbBoundWitnessDivinerConfigSchema,
|
|
26
|
-
IndexedDbBoundWitnessDivinerSchema: () => IndexedDbBoundWitnessDivinerSchema
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(src_exports);
|
|
29
|
-
|
|
30
|
-
// src/Schema.ts
|
|
31
|
-
var import_diviner_boundwitness_model = require("@xyo-network/diviner-boundwitness-model");
|
|
32
|
-
var IndexedDbBoundWitnessDivinerSchema = `${import_diviner_boundwitness_model.BoundWitnessDivinerSchema}.indexeddb`;
|
|
33
|
-
|
|
34
|
-
// src/Config.ts
|
|
35
|
-
var IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config`;
|
|
36
|
-
|
|
37
|
-
// src/Diviner.ts
|
|
38
|
-
var import_array = require("@xylabs/array");
|
|
39
|
-
var import_exists = require("@xylabs/exists");
|
|
40
|
-
var import_archivist_indexeddb = require("@xyo-network/archivist-indexeddb");
|
|
41
|
-
var import_boundwitness_model = require("@xyo-network/boundwitness-model");
|
|
42
|
-
var import_diviner_boundwitness_abstract = require("@xyo-network/diviner-boundwitness-abstract");
|
|
43
|
-
var import_diviner_boundwitness_model2 = require("@xyo-network/diviner-boundwitness-model");
|
|
44
|
-
var import_payload_builder = require("@xyo-network/payload-builder");
|
|
45
|
-
var import_idb = require("idb");
|
|
46
|
-
var bwValueFilter = /* @__PURE__ */ __name((key, values) => {
|
|
47
|
-
if (!values || values?.length === 0) return void 0;
|
|
48
|
-
return (bw) => {
|
|
49
|
-
if (!bw) return false;
|
|
50
|
-
return (0, import_array.containsAll)(bw[key], values);
|
|
51
|
-
};
|
|
52
|
-
}, "bwValueFilter");
|
|
53
|
-
var IndexedDbBoundWitnessDiviner = class extends import_diviner_boundwitness_abstract.BoundWitnessDiviner {
|
|
54
|
-
static {
|
|
55
|
-
__name(this, "IndexedDbBoundWitnessDiviner");
|
|
56
|
-
}
|
|
57
|
-
static configSchemas = [
|
|
58
|
-
...super.configSchemas,
|
|
59
|
-
IndexedDbBoundWitnessDivinerConfigSchema
|
|
60
|
-
];
|
|
61
|
-
static defaultConfigSchema = IndexedDbBoundWitnessDivinerConfigSchema;
|
|
62
|
-
/**
|
|
63
|
-
* The database name. If not supplied via config, it defaults
|
|
64
|
-
* to the archivist's name and if archivist's name is not supplied,
|
|
65
|
-
* it defaults to `archivist`. This behavior
|
|
66
|
-
* biases towards a single, isolated DB per archivist which seems to
|
|
67
|
-
* make the most sense for 99% of use cases.
|
|
68
|
-
*/
|
|
69
|
-
get dbName() {
|
|
70
|
-
return this.config?.dbName ?? this.config?.archivist ?? import_archivist_indexeddb.IndexedDbArchivist.defaultDbName;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* The database version. If not supplied via config, it defaults to 1.
|
|
74
|
-
*/
|
|
75
|
-
get dbVersion() {
|
|
76
|
-
return this.config?.dbVersion ?? import_archivist_indexeddb.IndexedDbArchivist.defaultDbVersion;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* The name of the object store. If not supplied via config, it defaults
|
|
80
|
-
* to `payloads`.
|
|
81
|
-
*/
|
|
82
|
-
get storeName() {
|
|
83
|
-
return this.config?.storeName ?? import_archivist_indexeddb.IndexedDbArchivist.defaultStoreName;
|
|
84
|
-
}
|
|
85
|
-
async divineHandler(payloads) {
|
|
86
|
-
const query = payloads?.filter(import_diviner_boundwitness_model2.isBoundWitnessDivinerQueryPayload)?.pop();
|
|
87
|
-
if (!query) return [];
|
|
88
|
-
const result = await this.tryUseDb(async (db) => {
|
|
89
|
-
const { addresses, payload_hashes, payload_schemas, limit, offset, order } = query;
|
|
90
|
-
const tx = db.transaction(this.storeName, "readonly");
|
|
91
|
-
const store = tx.objectStore(this.storeName);
|
|
92
|
-
const results = [];
|
|
93
|
-
let parsedOffset = offset ?? 0;
|
|
94
|
-
const parsedLimit = limit ?? 10;
|
|
95
|
-
const direction = order === "desc" ? "prev" : "next";
|
|
96
|
-
const valueFilters = [
|
|
97
|
-
bwValueFilter("addresses", addresses),
|
|
98
|
-
bwValueFilter("payload_hashes", payload_hashes),
|
|
99
|
-
bwValueFilter("payload_schemas", payload_schemas)
|
|
100
|
-
].filter(import_exists.exists);
|
|
101
|
-
let cursor = await store.index(import_archivist_indexeddb.IndexedDbArchivist.schemaIndexName).openCursor(IDBKeyRange.only(import_boundwitness_model.BoundWitnessSchema), direction);
|
|
102
|
-
if (valueFilters.length === 0) {
|
|
103
|
-
while (cursor && parsedOffset > 0) {
|
|
104
|
-
cursor = await cursor.advance(parsedOffset);
|
|
105
|
-
parsedOffset = 0;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
while (cursor && results.length < parsedLimit) {
|
|
109
|
-
const value = cursor.value;
|
|
110
|
-
if (value) {
|
|
111
|
-
if (valueFilters.length > 0) {
|
|
112
|
-
if (valueFilters.every((filter) => filter(value))) {
|
|
113
|
-
results.push(value);
|
|
114
|
-
}
|
|
115
|
-
} else {
|
|
116
|
-
results.push(value);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
try {
|
|
120
|
-
cursor = await cursor.continue();
|
|
121
|
-
} catch {
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
await tx.done;
|
|
126
|
-
return await Promise.all(results.filter(import_boundwitness_model.isBoundWitness).map((bw) => {
|
|
127
|
-
return import_payload_builder.PayloadBuilder.build(bw);
|
|
128
|
-
}));
|
|
129
|
-
});
|
|
130
|
-
return result ?? [];
|
|
131
|
-
}
|
|
132
|
-
async startHandler() {
|
|
133
|
-
await super.startHandler();
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Checks that the desired DB/objectStore exists and is initialized to the correct version
|
|
138
|
-
* @returns The initialized DB or undefined if it does not exist in the desired state
|
|
139
|
-
*/
|
|
140
|
-
async tryGetInitializedDb() {
|
|
141
|
-
const dbs = await indexedDB.databases();
|
|
142
|
-
const dbExists = dbs.some((db) => {
|
|
143
|
-
return db.name === this.dbName && db.version === this.dbVersion;
|
|
144
|
-
});
|
|
145
|
-
if (dbExists) {
|
|
146
|
-
const db = await (0, import_idb.openDB)(this.dbName, this.dbVersion);
|
|
147
|
-
const storeExists = db.objectStoreNames.contains(this.storeName);
|
|
148
|
-
if (storeExists) {
|
|
149
|
-
return db;
|
|
150
|
-
} else {
|
|
151
|
-
db.close();
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Executes a callback with the initialized DB and then closes the db
|
|
157
|
-
* @param callback The method to execute with the initialized DB
|
|
158
|
-
* @returns
|
|
159
|
-
*/
|
|
160
|
-
async tryUseDb(callback) {
|
|
161
|
-
const db = await this.tryGetInitializedDb();
|
|
162
|
-
if (db) {
|
|
163
|
-
try {
|
|
164
|
-
return await callback(db);
|
|
165
|
-
} finally {
|
|
166
|
-
db.close();
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return void 0;
|
|
170
|
-
}
|
|
171
|
-
};
|
|
1
|
+
"use strict";var c=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var h=(s,e)=>c(s,"name",{value:e,configurable:!0});var U=(s,e)=>{for(var t in e)c(s,t,{get:e[t],enumerable:!0})},$=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of F(e))!G.call(s,i)&&i!==t&&c(s,i,{get:()=>e[i],enumerable:!(r=A(e,i))||r.enumerable});return s};var k=s=>$(c({},"__esModule",{value:!0}),s);var q={};U(q,{IndexedDbBoundWitnessDiviner:()=>y,IndexedDbBoundWitnessDivinerConfigSchema:()=>m,IndexedDbBoundWitnessDivinerSchema:()=>p});module.exports=k(q);var D=require("@xyo-network/diviner-boundwitness-model"),p=`${D.BoundWitnessDivinerSchema}.indexeddb`;var m=`${p}.config`;var g=require("@xylabs/array"),v=require("@xylabs/exists"),a=require("@xyo-network/archivist-indexeddb"),f=require("@xyo-network/boundwitness-model"),w=require("@xyo-network/diviner-boundwitness-abstract"),N=require("@xyo-network/diviner-boundwitness-model"),B=require("@xyo-network/payload-builder"),S=require("idb");var b=h((s,e)=>{if(!(!e||e?.length===0))return t=>t?(0,g.containsAll)(t[s],e):!1},"bwValueFilter"),y=class extends w.BoundWitnessDiviner{static{h(this,"IndexedDbBoundWitnessDiviner")}static configSchemas=[...super.configSchemas,m];static defaultConfigSchema=m;get dbName(){return this.config?.dbName??this.config?.archivist??a.IndexedDbArchivist.defaultDbName}get dbVersion(){return this.config?.dbVersion??a.IndexedDbArchivist.defaultDbVersion}get storeName(){return this.config?.storeName??a.IndexedDbArchivist.defaultStoreName}async divineHandler(e){let t=e?.filter(N.isBoundWitnessDivinerQueryPayload)?.pop();return t?await this.tryUseDb(async i=>{let{addresses:I,payload_hashes:W,payload_schemas:V,limit:C,offset:E,order:_}=t,x=i.transaction(this.storeName,"readonly"),H=x.objectStore(this.storeName),d=[],l=E??0,P=C??10,j=_==="desc"?"prev":"next",u=[b("addresses",I),b("payload_hashes",W),b("payload_schemas",V)].filter(v.exists),n=await H.index(a.IndexedDbArchivist.schemaIndexName).openCursor(IDBKeyRange.only(f.BoundWitnessSchema),j);if(u.length===0)for(;n&&l>0;)n=await n.advance(l),l=0;for(;n&&d.length<P;){let o=n.value;o&&(u.length>0?u.every(z=>z(o))&&d.push(o):d.push(o));try{n=await n.continue()}catch{break}}return await x.done,await Promise.all(d.filter(f.isBoundWitness).map(o=>B.PayloadBuilder.build(o)))})??[]:[]}async startHandler(){return await super.startHandler(),!0}async tryGetInitializedDb(){if((await indexedDB.databases()).some(r=>r.name===this.dbName&&r.version===this.dbVersion)){let r=await(0,S.openDB)(this.dbName,this.dbVersion);if(r.objectStoreNames.contains(this.storeName))return r;r.close()}}async tryUseDb(e){let t=await this.tryGetInitializedDb();if(t)try{return await e(t)}finally{t.close()}}};
|
|
172
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts"],"sourcesContent":["export * from './Config'\nexport * from './Diviner'\nexport * from './Params'\nexport * from './Schema'\n","import { BoundWitnessDivinerSchema } from '@xyo-network/diviner-boundwitness-model'\n\nexport const IndexedDbBoundWitnessDivinerSchema = `${BoundWitnessDivinerSchema}.indexeddb` as const\nexport type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema\n","import { IndexDescription } from '@xyo-network/archivist-model'\nimport { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbBoundWitnessDivinerSchema } from './Schema'\n\nexport const IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config` as const\nexport type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema\n\nexport type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{\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: IndexedDbBoundWitnessDivinerConfigSchema\n /**\n * The storage configuration\n * // TODO: Hoist to main diviner config\n */\n storage?: {\n /**\n * The indexes to create on the object store\n */\n indexes?: IndexDescription[]\n }\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n","import { containsAll } from '@xylabs/array'\nimport { exists } from '@xylabs/exists'\nimport { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'\nimport { BoundWitness, BoundWitnessSchema, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport { BoundWitnessDivinerQueryPayload, isBoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Schema } from '@xyo-network/payload-model'\nimport { IDBPDatabase, openDB } from 'idb'\n\nimport { IndexedDbBoundWitnessDivinerConfigSchema } from './Config'\nimport { IndexedDbBoundWitnessDivinerParams } from './Params'\n\ninterface BoundWitnessStore {\n [s: string]: BoundWitness\n}\n\ntype ValueFilter = (bw?: BoundWitness | null) => boolean\n\nconst bwValueFilter = (\n key: keyof Pick<BoundWitness, 'addresses' | 'payload_hashes' | 'payload_schemas'>,\n values?: string[],\n): ValueFilter | undefined => {\n if (!values || values?.length === 0) return undefined\n return (bw) => {\n if (!bw) return false\n return containsAll(bw[key], values)\n }\n}\n\nexport class IndexedDbBoundWitnessDiviner<\n TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, IndexedDbBoundWitnessDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = IndexedDbBoundWitnessDivinerConfigSchema\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the archivist's name and if archivist's name is not supplied,\n * 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 return this.config?.dbName ?? this.config?.archivist ?? IndexedDbArchivist.defaultDbName\n }\n\n /**\n * The database version. If not supplied via config, it defaults to 1.\n */\n get dbVersion() {\n return this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion\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 return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n const query = payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop()\n if (!query) return []\n\n const result = await this.tryUseDb(async (db) => {\n const { addresses, payload_hashes, payload_schemas, limit, offset, order } = query\n const tx = db.transaction(this.storeName, 'readonly')\n const store = tx.objectStore(this.storeName)\n const results: TOut[] = []\n let parsedOffset = offset ?? 0\n const parsedLimit = limit ?? 10\n const direction: IDBCursorDirection = order === 'desc' ? 'prev' : 'next'\n const valueFilters: ValueFilter[] = [\n bwValueFilter('addresses', addresses),\n bwValueFilter('payload_hashes', payload_hashes),\n bwValueFilter('payload_schemas', payload_schemas),\n ].filter(exists)\n // Only iterate over BWs\n let cursor = await store.index(IndexedDbArchivist.schemaIndexName).openCursor(IDBKeyRange.only(BoundWitnessSchema), direction)\n\n // If we're filtering on more than just the schema, we need to\n // iterate through all the results\n if (valueFilters.length === 0) {\n // Skip records until the offset is reached\n while (cursor && parsedOffset > 0) {\n cursor = await cursor.advance(parsedOffset)\n parsedOffset = 0 // Reset offset after skipping\n }\n }\n // Collect results up to the limit\n while (cursor && results.length < parsedLimit) {\n const value = cursor.value\n if (value) {\n // If we're filtering on more than just the schema\n if (valueFilters.length > 0) {\n // Ensure all filters pass\n if (valueFilters.every((filter) => filter(value))) {\n // Then save the value\n results.push(value)\n }\n } else {\n // Otherwise just save the value\n results.push(value)\n }\n }\n try {\n cursor = await cursor.continue()\n } catch {\n break\n }\n }\n await tx.done\n // Remove any metadata before returning to the client\n return await Promise.all(\n results.filter(isBoundWitness).map((bw) => {\n return PayloadBuilder.build(bw)\n }),\n )\n })\n return result ?? []\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // NOTE: Do not eager initialize the DB here. It will cause the\n // DB to be created by this process and then the DB will be\n // in a bad state for other processes that need to create the DB.\n return true\n }\n\n /**\n * Checks that the desired DB/objectStore exists and is initialized to the correct version\n * @returns The initialized DB or undefined if it does not exist in the desired state\n */\n private async tryGetInitializedDb(): Promise<IDBPDatabase<BoundWitnessStore> | undefined> {\n // Enumerate the DBs\n const dbs = await indexedDB.databases()\n // Check that the DB exists at the desired version\n const dbExists = dbs.some((db) => {\n return db.name === this.dbName && db.version === this.dbVersion\n })\n // If the DB exists at the desired version\n if (dbExists) {\n // If the db does exist, open it\n const db = await openDB<BoundWitnessStore>(this.dbName, this.dbVersion)\n // Check that the desired objectStore exists\n const storeExists = db.objectStoreNames.contains(this.storeName)\n // If the correct db/version/objectStore exists\n if (storeExists) {\n return db\n } else {\n // Otherwise close the db so the process that is going to update the\n // db can open it\n db.close()\n }\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 tryUseDb<T>(callback: (db: IDBPDatabase<BoundWitnessStore>) => Promise<T> | T): Promise<T | undefined> {\n // Get the initialized DB\n const db = await this.tryGetInitializedDb()\n if (db) {\n try {\n // Perform the callback\n return await callback(db)\n } finally {\n // Close the DB\n db.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AAErC,UAAMC,WAAWH,IAAII,KAAK,CAAC1C,OAAAA;AACzB,aAAOA,GAAG2C,SAAS,KAAK5D,UAAUiB,GAAG4C,YAAY,KAAKxD;IACxD,CAAA;AAEA,QAAIqD,UAAU;AAEZ,YAAMzC,KAAK,UAAM6C,mBAA0B,KAAK9D,QAAQ,KAAKK,SAAS;AAEtE,YAAM0D,cAAc9C,GAAG+C,iBAAiBC,SAAS,KAAK1D,SAAS;AAE/D,UAAIwD,aAAa;AACf,eAAO9C;MACT,OAAO;AAGLA,WAAGiD,MAAK;MACV;IACF;EACF;;;;;;EAOA,MAAclD,SAAYmD,UAA2F;AAEnH,UAAMlD,KAAK,MAAM,KAAKqC,oBAAmB;AACzC,QAAIrC,IAAI;AACN,UAAI;AAEF,eAAO,MAAMkD,SAASlD,EAAAA;MACxB,UAAA;AAEEA,WAAGiD,MAAK;MACV;IACF;AACA,WAAO1E;EACT;AACF;","names":["IndexedDbBoundWitnessDivinerSchema","BoundWitnessDivinerSchema","IndexedDbBoundWitnessDivinerConfigSchema","IndexedDbBoundWitnessDivinerSchema","import_diviner_boundwitness_model","bwValueFilter","key","values","length","undefined","bw","containsAll","IndexedDbBoundWitnessDiviner","BoundWitnessDiviner","configSchemas","IndexedDbBoundWitnessDivinerConfigSchema","defaultConfigSchema","dbName","config","archivist","IndexedDbArchivist","defaultDbName","dbVersion","defaultDbVersion","storeName","defaultStoreName","divineHandler","payloads","query","filter","isBoundWitnessDivinerQueryPayload","pop","result","tryUseDb","db","addresses","payload_hashes","payload_schemas","limit","offset","order","tx","transaction","store","objectStore","results","parsedOffset","parsedLimit","direction","valueFilters","exists","cursor","index","schemaIndexName","openCursor","IDBKeyRange","only","BoundWitnessSchema","advance","value","every","push","continue","done","Promise","all","isBoundWitness","map","PayloadBuilder","build","startHandler","tryGetInitializedDb","dbs","indexedDB","databases","dbExists","some","name","version","openDB","storeExists","objectStoreNames","contains","close","callback"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts"],"sourcesContent":["export * from './Config'\nexport * from './Diviner'\nexport * from './Params'\nexport * from './Schema'\n","import { BoundWitnessDivinerSchema } from '@xyo-network/diviner-boundwitness-model'\n\nexport const IndexedDbBoundWitnessDivinerSchema = `${BoundWitnessDivinerSchema}.indexeddb` as const\nexport type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema\n","import { IndexDescription } from '@xyo-network/archivist-model'\nimport { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbBoundWitnessDivinerSchema } from './Schema'\n\nexport const IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config` as const\nexport type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema\n\nexport type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{\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: IndexedDbBoundWitnessDivinerConfigSchema\n /**\n * The storage configuration\n * // TODO: Hoist to main diviner config\n */\n storage?: {\n /**\n * The indexes to create on the object store\n */\n indexes?: IndexDescription[]\n }\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n","import { containsAll } from '@xylabs/array'\nimport { exists } from '@xylabs/exists'\nimport { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'\nimport { BoundWitness, BoundWitnessSchema, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport { BoundWitnessDivinerQueryPayload, isBoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Schema } from '@xyo-network/payload-model'\nimport { IDBPDatabase, openDB } from 'idb'\n\nimport { IndexedDbBoundWitnessDivinerConfigSchema } from './Config'\nimport { IndexedDbBoundWitnessDivinerParams } from './Params'\n\ninterface BoundWitnessStore {\n [s: string]: BoundWitness\n}\n\ntype ValueFilter = (bw?: BoundWitness | null) => boolean\n\nconst bwValueFilter = (\n key: keyof Pick<BoundWitness, 'addresses' | 'payload_hashes' | 'payload_schemas'>,\n values?: string[],\n): ValueFilter | undefined => {\n if (!values || values?.length === 0) return undefined\n return (bw) => {\n if (!bw) return false\n return containsAll(bw[key], values)\n }\n}\n\nexport class IndexedDbBoundWitnessDiviner<\n TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, IndexedDbBoundWitnessDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = IndexedDbBoundWitnessDivinerConfigSchema\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the archivist's name and if archivist's name is not supplied,\n * 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 return this.config?.dbName ?? this.config?.archivist ?? IndexedDbArchivist.defaultDbName\n }\n\n /**\n * The database version. If not supplied via config, it defaults to 1.\n */\n get dbVersion() {\n return this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion\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 return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n const query = payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop()\n if (!query) return []\n\n const result = await this.tryUseDb(async (db) => {\n const { addresses, payload_hashes, payload_schemas, limit, offset, order } = query\n const tx = db.transaction(this.storeName, 'readonly')\n const store = tx.objectStore(this.storeName)\n const results: TOut[] = []\n let parsedOffset = offset ?? 0\n const parsedLimit = limit ?? 10\n const direction: IDBCursorDirection = order === 'desc' ? 'prev' : 'next'\n const valueFilters: ValueFilter[] = [\n bwValueFilter('addresses', addresses),\n bwValueFilter('payload_hashes', payload_hashes),\n bwValueFilter('payload_schemas', payload_schemas),\n ].filter(exists)\n // Only iterate over BWs\n let cursor = await store.index(IndexedDbArchivist.schemaIndexName).openCursor(IDBKeyRange.only(BoundWitnessSchema), direction)\n\n // If we're filtering on more than just the schema, we need to\n // iterate through all the results\n if (valueFilters.length === 0) {\n // Skip records until the offset is reached\n while (cursor && parsedOffset > 0) {\n cursor = await cursor.advance(parsedOffset)\n parsedOffset = 0 // Reset offset after skipping\n }\n }\n // Collect results up to the limit\n while (cursor && results.length < parsedLimit) {\n const value = cursor.value\n if (value) {\n // If we're filtering on more than just the schema\n if (valueFilters.length > 0) {\n // Ensure all filters pass\n if (valueFilters.every((filter) => filter(value))) {\n // Then save the value\n results.push(value)\n }\n } else {\n // Otherwise just save the value\n results.push(value)\n }\n }\n try {\n cursor = await cursor.continue()\n } catch {\n break\n }\n }\n await tx.done\n // Remove any metadata before returning to the client\n return await Promise.all(\n results.filter(isBoundWitness).map((bw) => {\n return PayloadBuilder.build(bw)\n }),\n )\n })\n return result ?? []\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // NOTE: Do not eager initialize the DB here. It will cause the\n // DB to be created by this process and then the DB will be\n // in a bad state for other processes that need to create the DB.\n return true\n }\n\n /**\n * Checks that the desired DB/objectStore exists and is initialized to the correct version\n * @returns The initialized DB or undefined if it does not exist in the desired state\n */\n private async tryGetInitializedDb(): Promise<IDBPDatabase<BoundWitnessStore> | undefined> {\n // Enumerate the DBs\n const dbs = await indexedDB.databases()\n // Check that the DB exists at the desired version\n const dbExists = dbs.some((db) => {\n return db.name === this.dbName && db.version === this.dbVersion\n })\n // If the DB exists at the desired version\n if (dbExists) {\n // If the db does exist, open it\n const db = await openDB<BoundWitnessStore>(this.dbName, this.dbVersion)\n // Check that the desired objectStore exists\n const storeExists = db.objectStoreNames.contains(this.storeName)\n // If the correct db/version/objectStore exists\n if (storeExists) {\n return db\n } else {\n // Otherwise close the db so the process that is going to update the\n // db can open it\n db.close()\n }\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 tryUseDb<T>(callback: (db: IDBPDatabase<BoundWitnessStore>) => Promise<T> | T): Promise<T | undefined> {\n // Get the initialized DB\n const db = await this.tryGetInitializedDb()\n if (db) {\n try {\n // Perform the callback\n return await callback(db)\n } finally {\n // Close the DB\n db.close()\n }\n }\n return undefined\n }\n}\n"],"mappings":"4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kCAAAE,EAAA,6CAAAC,EAAA,uCAAAC,IAAA,eAAAC,EAAAL,GCAA,IAAAM,EAA0C,mDAE7BC,EAAqC,GAAGC,2BAAAA,aCG9C,IAAMC,EAA2C,GAAGC,CAAAA,UCL3D,IAAAC,EAA4B,yBAC5BC,EAAuB,0BACvBC,EAAmC,4CACnCC,EAAiE,2CACjEC,EAAoC,sDACpCC,EAAmF,mDACnFC,EAA+B,wCAE/BC,EAAqC,eAWrC,IAAMC,EAAgBC,EAAA,CACpBC,EACAC,IAAAA,CAEA,GAAI,GAACA,GAAUA,GAAQC,SAAW,GAClC,OAAQC,GACDA,KACEC,eAAYD,EAAGH,CAAAA,EAAMC,CAAAA,EADZ,EAGpB,EATsB,iBAWTI,EAAN,cAIGC,qBAAAA,CAlCV,MAkCUA,CAAAA,EAAAA,qCACR,OAAyBC,cAA0B,IAAI,MAAMA,cAAeC,GAC5E,OAAyBC,oBAA8BD,EASvD,IAAIE,QAAS,CACX,OAAO,KAAKC,QAAQD,QAAU,KAAKC,QAAQC,WAAaC,qBAAmBC,aAC7E,CAKA,IAAIC,WAAY,CACd,OAAO,KAAKJ,QAAQI,WAAaF,qBAAmBG,gBACtD,CAMA,IAAIC,WAAY,CACd,OAAO,KAAKN,QAAQM,WAAaJ,qBAAmBK,gBACtD,CAEA,MAAyBC,cAA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AAA,EAzDE,CAAA,CA0DrB,CAEA,MAAyB2D,cAAe,CACtC,aAAM,MAAMA,aAAAA,EAIL,EACT,CAMA,MAAcC,qBAA4E,CAQxF,IANY,MAAMC,UAAUC,UAAS,GAEhBC,KAAMxC,GAClBA,EAAGyC,OAAS,KAAKzD,QAAUgB,EAAG0C,UAAY,KAAKrD,SACxD,EAEc,CAEZ,IAAMW,EAAK,QAAM2C,UAA0B,KAAK3D,OAAQ,KAAKK,SAAS,EAItE,GAFoBW,EAAG4C,iBAAiBC,SAAS,KAAKtD,SAAS,EAG7D,OAAOS,EAIPA,EAAG8C,MAAK,CAEZ,CACF,CAOA,MAAc/C,SAAYgD,EAA2F,CAEnH,IAAM/C,EAAK,MAAM,KAAKqC,oBAAmB,EACzC,GAAIrC,EACF,GAAI,CAEF,OAAO,MAAM+C,EAAS/C,CAAAA,CACxB,QAAA,CAEEA,EAAG8C,MAAK,CACV,CAGJ,CACF","names":["src_exports","__export","IndexedDbBoundWitnessDiviner","IndexedDbBoundWitnessDivinerConfigSchema","IndexedDbBoundWitnessDivinerSchema","__toCommonJS","import_diviner_boundwitness_model","IndexedDbBoundWitnessDivinerSchema","BoundWitnessDivinerSchema","IndexedDbBoundWitnessDivinerConfigSchema","IndexedDbBoundWitnessDivinerSchema","import_array","import_exists","import_archivist_indexeddb","import_boundwitness_model","import_diviner_boundwitness_abstract","import_diviner_boundwitness_model","import_payload_builder","import_idb","bwValueFilter","__name","key","values","length","bw","containsAll","IndexedDbBoundWitnessDiviner","BoundWitnessDiviner","configSchemas","IndexedDbBoundWitnessDivinerConfigSchema","defaultConfigSchema","dbName","config","archivist","IndexedDbArchivist","defaultDbName","dbVersion","defaultDbVersion","storeName","defaultStoreName","divineHandler","payloads","query","filter","isBoundWitnessDivinerQueryPayload","pop","tryUseDb","db","addresses","payload_hashes","payload_schemas","limit","offset","order","tx","transaction","store","objectStore","results","parsedOffset","parsedLimit","direction","valueFilters","exists","cursor","index","schemaIndexName","openCursor","IDBKeyRange","only","BoundWitnessSchema","advance","value","every","push","continue","done","Promise","all","isBoundWitness","map","PayloadBuilder","build","startHandler","tryGetInitializedDb","indexedDB","databases","some","name","version","openDB","objectStoreNames","contains","close","callback"]}
|
package/dist/browser/index.js
CHANGED
|
@@ -1,151 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
-
// src/Schema.ts
|
|
5
|
-
import { BoundWitnessDivinerSchema } from "@xyo-network/diviner-boundwitness-model";
|
|
6
|
-
var IndexedDbBoundWitnessDivinerSchema = `${BoundWitnessDivinerSchema}.indexeddb`;
|
|
7
|
-
|
|
8
|
-
// src/Config.ts
|
|
9
|
-
var IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config`;
|
|
10
|
-
|
|
11
|
-
// src/Diviner.ts
|
|
12
|
-
import { containsAll } from "@xylabs/array";
|
|
13
|
-
import { exists } from "@xylabs/exists";
|
|
14
|
-
import { IndexedDbArchivist } from "@xyo-network/archivist-indexeddb";
|
|
15
|
-
import { BoundWitnessSchema, isBoundWitness } from "@xyo-network/boundwitness-model";
|
|
16
|
-
import { BoundWitnessDiviner } from "@xyo-network/diviner-boundwitness-abstract";
|
|
17
|
-
import { isBoundWitnessDivinerQueryPayload } from "@xyo-network/diviner-boundwitness-model";
|
|
18
|
-
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
19
|
-
import { openDB } from "idb";
|
|
20
|
-
var bwValueFilter = /* @__PURE__ */ __name((key, values) => {
|
|
21
|
-
if (!values || values?.length === 0) return void 0;
|
|
22
|
-
return (bw) => {
|
|
23
|
-
if (!bw) return false;
|
|
24
|
-
return containsAll(bw[key], values);
|
|
25
|
-
};
|
|
26
|
-
}, "bwValueFilter");
|
|
27
|
-
var IndexedDbBoundWitnessDiviner = class extends BoundWitnessDiviner {
|
|
28
|
-
static {
|
|
29
|
-
__name(this, "IndexedDbBoundWitnessDiviner");
|
|
30
|
-
}
|
|
31
|
-
static configSchemas = [
|
|
32
|
-
...super.configSchemas,
|
|
33
|
-
IndexedDbBoundWitnessDivinerConfigSchema
|
|
34
|
-
];
|
|
35
|
-
static defaultConfigSchema = IndexedDbBoundWitnessDivinerConfigSchema;
|
|
36
|
-
/**
|
|
37
|
-
* The database name. If not supplied via config, it defaults
|
|
38
|
-
* to the archivist's name and if archivist's name is not supplied,
|
|
39
|
-
* it defaults to `archivist`. This behavior
|
|
40
|
-
* biases towards a single, isolated DB per archivist which seems to
|
|
41
|
-
* make the most sense for 99% of use cases.
|
|
42
|
-
*/
|
|
43
|
-
get dbName() {
|
|
44
|
-
return this.config?.dbName ?? this.config?.archivist ?? IndexedDbArchivist.defaultDbName;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* The database version. If not supplied via config, it defaults to 1.
|
|
48
|
-
*/
|
|
49
|
-
get dbVersion() {
|
|
50
|
-
return this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* The name of the object store. If not supplied via config, it defaults
|
|
54
|
-
* to `payloads`.
|
|
55
|
-
*/
|
|
56
|
-
get storeName() {
|
|
57
|
-
return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName;
|
|
58
|
-
}
|
|
59
|
-
async divineHandler(payloads) {
|
|
60
|
-
const query = payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop();
|
|
61
|
-
if (!query) return [];
|
|
62
|
-
const result = await this.tryUseDb(async (db) => {
|
|
63
|
-
const { addresses, payload_hashes, payload_schemas, limit, offset, order } = query;
|
|
64
|
-
const tx = db.transaction(this.storeName, "readonly");
|
|
65
|
-
const store = tx.objectStore(this.storeName);
|
|
66
|
-
const results = [];
|
|
67
|
-
let parsedOffset = offset ?? 0;
|
|
68
|
-
const parsedLimit = limit ?? 10;
|
|
69
|
-
const direction = order === "desc" ? "prev" : "next";
|
|
70
|
-
const valueFilters = [
|
|
71
|
-
bwValueFilter("addresses", addresses),
|
|
72
|
-
bwValueFilter("payload_hashes", payload_hashes),
|
|
73
|
-
bwValueFilter("payload_schemas", payload_schemas)
|
|
74
|
-
].filter(exists);
|
|
75
|
-
let cursor = await store.index(IndexedDbArchivist.schemaIndexName).openCursor(IDBKeyRange.only(BoundWitnessSchema), direction);
|
|
76
|
-
if (valueFilters.length === 0) {
|
|
77
|
-
while (cursor && parsedOffset > 0) {
|
|
78
|
-
cursor = await cursor.advance(parsedOffset);
|
|
79
|
-
parsedOffset = 0;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
while (cursor && results.length < parsedLimit) {
|
|
83
|
-
const value = cursor.value;
|
|
84
|
-
if (value) {
|
|
85
|
-
if (valueFilters.length > 0) {
|
|
86
|
-
if (valueFilters.every((filter) => filter(value))) {
|
|
87
|
-
results.push(value);
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
results.push(value);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
try {
|
|
94
|
-
cursor = await cursor.continue();
|
|
95
|
-
} catch {
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
await tx.done;
|
|
100
|
-
return await Promise.all(results.filter(isBoundWitness).map((bw) => {
|
|
101
|
-
return PayloadBuilder.build(bw);
|
|
102
|
-
}));
|
|
103
|
-
});
|
|
104
|
-
return result ?? [];
|
|
105
|
-
}
|
|
106
|
-
async startHandler() {
|
|
107
|
-
await super.startHandler();
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Checks that the desired DB/objectStore exists and is initialized to the correct version
|
|
112
|
-
* @returns The initialized DB or undefined if it does not exist in the desired state
|
|
113
|
-
*/
|
|
114
|
-
async tryGetInitializedDb() {
|
|
115
|
-
const dbs = await indexedDB.databases();
|
|
116
|
-
const dbExists = dbs.some((db) => {
|
|
117
|
-
return db.name === this.dbName && db.version === this.dbVersion;
|
|
118
|
-
});
|
|
119
|
-
if (dbExists) {
|
|
120
|
-
const db = await openDB(this.dbName, this.dbVersion);
|
|
121
|
-
const storeExists = db.objectStoreNames.contains(this.storeName);
|
|
122
|
-
if (storeExists) {
|
|
123
|
-
return db;
|
|
124
|
-
} else {
|
|
125
|
-
db.close();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Executes a callback with the initialized DB and then closes the db
|
|
131
|
-
* @param callback The method to execute with the initialized DB
|
|
132
|
-
* @returns
|
|
133
|
-
*/
|
|
134
|
-
async tryUseDb(callback) {
|
|
135
|
-
const db = await this.tryGetInitializedDb();
|
|
136
|
-
if (db) {
|
|
137
|
-
try {
|
|
138
|
-
return await callback(db);
|
|
139
|
-
} finally {
|
|
140
|
-
db.close();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return void 0;
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
export {
|
|
147
|
-
IndexedDbBoundWitnessDiviner,
|
|
148
|
-
IndexedDbBoundWitnessDivinerConfigSchema,
|
|
149
|
-
IndexedDbBoundWitnessDivinerSchema
|
|
150
|
-
};
|
|
1
|
+
var W=Object.defineProperty;var m=(n,e)=>W(n,"name",{value:e,configurable:!0});import{BoundWitnessDivinerSchema as V}from"@xyo-network/diviner-boundwitness-model";var p=`${V}.indexeddb`;var f=`${p}.config`;import{containsAll as C}from"@xylabs/array";import{exists as E}from"@xylabs/exists";import{IndexedDbArchivist as a}from"@xyo-network/archivist-indexeddb";import{BoundWitnessSchema as _,isBoundWitness as H}from"@xyo-network/boundwitness-model";import{BoundWitnessDiviner as P}from"@xyo-network/diviner-boundwitness-abstract";import{isBoundWitnessDivinerQueryPayload as j}from"@xyo-network/diviner-boundwitness-model";import{PayloadBuilder as z}from"@xyo-network/payload-builder";import{openDB as A}from"idb";var l=m((n,e)=>{if(!(!e||e?.length===0))return t=>t?C(t[n],e):!1},"bwValueFilter"),b=class extends P{static{m(this,"IndexedDbBoundWitnessDiviner")}static configSchemas=[...super.configSchemas,f];static defaultConfigSchema=f;get dbName(){return this.config?.dbName??this.config?.archivist??a.defaultDbName}get dbVersion(){return this.config?.dbVersion??a.defaultDbVersion}get storeName(){return this.config?.storeName??a.defaultStoreName}async divineHandler(e){let t=e?.filter(j)?.pop();return t?await this.tryUseDb(async u=>{let{addresses:y,payload_hashes:x,payload_schemas:D,limit:g,offset:v,order:w}=t,h=u.transaction(this.storeName,"readonly"),N=h.objectStore(this.storeName),o=[],d=v??0,B=g??10,S=w==="desc"?"prev":"next",c=[l("addresses",y),l("payload_hashes",x),l("payload_schemas",D)].filter(E),r=await N.index(a.schemaIndexName).openCursor(IDBKeyRange.only(_),S);if(c.length===0)for(;r&&d>0;)r=await r.advance(d),d=0;for(;r&&o.length<B;){let i=r.value;i&&(c.length>0?c.every(I=>I(i))&&o.push(i):o.push(i));try{r=await r.continue()}catch{break}}return await h.done,await Promise.all(o.filter(H).map(i=>z.build(i)))})??[]:[]}async startHandler(){return await super.startHandler(),!0}async tryGetInitializedDb(){if((await indexedDB.databases()).some(s=>s.name===this.dbName&&s.version===this.dbVersion)){let s=await A(this.dbName,this.dbVersion);if(s.objectStoreNames.contains(this.storeName))return s;s.close()}}async tryUseDb(e){let t=await this.tryGetInitializedDb();if(t)try{return await e(t)}finally{t.close()}}};export{b as IndexedDbBoundWitnessDiviner,f as IndexedDbBoundWitnessDivinerConfigSchema,p as IndexedDbBoundWitnessDivinerSchema};
|
|
151
2
|
//# sourceMappingURL=index.js.map
|