@xyo-network/diviner-boundwitness-memory 2.104.0 → 2.104.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/index.cjs +6 -12
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +6 -12
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/index.cjs +6 -12
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +6 -12
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/index.cjs +10 -19
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +10 -19
- package/dist/node/index.js.map +1 -1
- package/package.json +12 -12
package/dist/browser/index.cjs
CHANGED
|
@@ -45,22 +45,16 @@ var MemoryBoundWitnessDiviner = class extends import_diviner_boundwitness_abstra
|
|
|
45
45
|
static defaultConfigSchema = import_diviner_boundwitness_model.BoundWitnessDivinerConfigSchema;
|
|
46
46
|
async divineHandler(payloads) {
|
|
47
47
|
const filter = (0, import_assert.assertEx)(payloads?.filter(import_diviner_boundwitness_model.isBoundWitnessDivinerQueryPayload)?.pop(), () => "Missing query payload");
|
|
48
|
-
if (!filter)
|
|
49
|
-
return [];
|
|
48
|
+
if (!filter) return [];
|
|
50
49
|
const archivist = (0, import_assert.assertEx)(await this.archivistInstance(), () => "Unable to resolve archivist");
|
|
51
50
|
const { addresses, payload_hashes, payload_schemas, limit, offset, order = "desc", sourceQuery, destination, timestamp } = filter;
|
|
52
51
|
let bws = (await archivist?.all?.() ?? []).filter(import_boundwitness_model.isBoundWitness);
|
|
53
|
-
if (order === "desc")
|
|
54
|
-
bws = bws.reverse();
|
|
52
|
+
if (order === "desc") bws = bws.reverse();
|
|
55
53
|
const allAddresses = addresses?.map((address) => (0, import_hex.hexFromHexString)(address)).filter(import_exists.exists);
|
|
56
|
-
if (allAddresses?.length)
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
if (payload_schemas?.length)
|
|
61
|
-
bws = bws.filter((bw) => (0, import_array.containsAll)(bw.payload_schemas, payload_schemas));
|
|
62
|
-
if (sourceQuery)
|
|
63
|
-
bws = bws.filter((bw) => bw?.$meta?.sourceQuery === sourceQuery);
|
|
54
|
+
if (allAddresses?.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.addresses, allAddresses));
|
|
55
|
+
if (payload_hashes?.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.payload_hashes, payload_hashes));
|
|
56
|
+
if (payload_schemas?.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.payload_schemas, payload_schemas));
|
|
57
|
+
if (sourceQuery) bws = bws.filter((bw) => bw?.$meta?.sourceQuery === sourceQuery);
|
|
64
58
|
if (destination && Array.isArray(destination) && destination?.length > 0) {
|
|
65
59
|
const targetFilter = (0, import_assert.assertEx)(destination, () => "Missing destination");
|
|
66
60
|
bws = bws.filter((bw) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/MemoryBoundWitnessDiviner.ts"],"sourcesContent":["export * from './MemoryBoundWitnessDiviner'\n","import { containsAll } from '@xylabs/array'\nimport { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { hexFromHexString } from '@xylabs/hex'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport {\n BoundWitnessDivinerConfigSchema,\n BoundWitnessDivinerParams,\n BoundWitnessDivinerQueryPayload,\n isBoundWitnessDivinerQueryPayload,\n} from '@xyo-network/diviner-boundwitness-model'\nimport { Schema, WithMeta } from '@xyo-network/payload-model'\n\nexport interface EqualityComparisonOperators {\n /**\n * 'Not Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value does not match the provided string.\n * Example: field != 'value'\n */\n '!=': string\n\n /**\n * 'Less Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than the provided string.\n * Example: field < 'value'\n */\n '<': string\n\n /**\n * 'Less Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than or equal to the provided string.\n * Example: field <= 'value'\n */\n '<=': string\n\n /**\n * 'Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value matches the provided string exactly.\n * Example: field = 'value'\n */\n '=': string\n\n /**\n * 'Greater Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than the provided string.\n * Example: field > 'value'\n */\n '>': string\n\n /**\n * 'Greater Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than or equal to the provided string.\n * Example: field >= 'value'\n */\n '>=': string\n}\n\ntype WithTimestamp = BoundWitness & { timestamp: number }\nconst hasTimestamp = (bw: BoundWitness): bw is WithTimestamp => bw.timestamp !== undefined\n\nexport class MemoryBoundWitnessDiviner<\n TParams extends BoundWitnessDivinerParams = BoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, BoundWitnessDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = BoundWitnessDivinerConfigSchema\n\n protected override async divineHandler(payloads?: TIn[]) {\n const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => 'Missing query payload')\n if (!filter) return []\n const archivist = assertEx(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const { addresses, payload_hashes, payload_schemas, limit, offset, order = 'desc', sourceQuery, destination, timestamp } = filter\n let bws = ((await archivist?.all?.()) ?? []).filter(isBoundWitness) as WithMeta<BoundWitness>[]\n if (order === 'desc') bws = bws.reverse()\n const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists)\n if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses))\n if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes))\n if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas))\n if (sourceQuery) bws = bws.filter((bw) => (bw?.$meta as { sourceQuery?: string })?.sourceQuery === sourceQuery)\n // If there's a destination filter of the right kind\n if (destination && Array.isArray(destination) && destination?.length > 0) {\n const targetFilter = assertEx(destination, () => 'Missing destination')\n // Find all BWs that satisfy the destination constraint\n bws = bws.filter((bw) => {\n const targetDestinationField = (bw?.$meta as { destination?: string[] })?.destination\n // If the destination field is an array and contains at least one element\n return targetDestinationField !== undefined && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ?\n // Check that the targetDestinationField contains all the elements in the targetFilter\n containsAll(targetFilter, targetDestinationField ?? [])\n // Otherwise, filter it out\n : false\n })\n }\n if (timestamp !== undefined) {\n bws =\n order === 'desc' ?\n bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp)\n : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp)\n }\n const parsedLimit = limit ?? bws.length\n const parsedOffset = offset ?? 0\n return bws.slice(parsedOffset, parsedLimit) as WithMeta<TOut>[]\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,mBAA4B;AAC5B,oBAAyB;AACzB,oBAAuB;AACvB,iBAAiC;AACjC,gCAA6C;AAC7C,2CAAoC;AACpC,wCAKO;AAsDP,IAAMA,eAAe,wBAACC,OAA0CA,GAAGC,cAAcC,QAA5D;AAEd,IAAMC,4BAAN,cAIGC,yDAAAA;EAvEV,OAuEUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,MAAyBE,cAAcC,UAAkB;AACvD,UAAMC,aAASC,wBAASF,UAAUC,OAAOE,mEAAAA,GAAoCC,IAAAA,GAAO,MAAM,uBAAA;AAC1F,QAAI,CAACH
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/MemoryBoundWitnessDiviner.ts"],"sourcesContent":["export * from './MemoryBoundWitnessDiviner'\n","import { containsAll } from '@xylabs/array'\nimport { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { hexFromHexString } from '@xylabs/hex'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport {\n BoundWitnessDivinerConfigSchema,\n BoundWitnessDivinerParams,\n BoundWitnessDivinerQueryPayload,\n isBoundWitnessDivinerQueryPayload,\n} from '@xyo-network/diviner-boundwitness-model'\nimport { Schema, WithMeta } from '@xyo-network/payload-model'\n\nexport interface EqualityComparisonOperators {\n /**\n * 'Not Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value does not match the provided string.\n * Example: field != 'value'\n */\n '!=': string\n\n /**\n * 'Less Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than the provided string.\n * Example: field < 'value'\n */\n '<': string\n\n /**\n * 'Less Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than or equal to the provided string.\n * Example: field <= 'value'\n */\n '<=': string\n\n /**\n * 'Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value matches the provided string exactly.\n * Example: field = 'value'\n */\n '=': string\n\n /**\n * 'Greater Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than the provided string.\n * Example: field > 'value'\n */\n '>': string\n\n /**\n * 'Greater Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than or equal to the provided string.\n * Example: field >= 'value'\n */\n '>=': string\n}\n\ntype WithTimestamp = BoundWitness & { timestamp: number }\nconst hasTimestamp = (bw: BoundWitness): bw is WithTimestamp => bw.timestamp !== undefined\n\nexport class MemoryBoundWitnessDiviner<\n TParams extends BoundWitnessDivinerParams = BoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, BoundWitnessDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = BoundWitnessDivinerConfigSchema\n\n protected override async divineHandler(payloads?: TIn[]) {\n const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => 'Missing query payload')\n if (!filter) return []\n const archivist = assertEx(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const { addresses, payload_hashes, payload_schemas, limit, offset, order = 'desc', sourceQuery, destination, timestamp } = filter\n let bws = ((await archivist?.all?.()) ?? []).filter(isBoundWitness) as WithMeta<BoundWitness>[]\n if (order === 'desc') bws = bws.reverse()\n const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists)\n if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses))\n if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes))\n if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas))\n if (sourceQuery) bws = bws.filter((bw) => (bw?.$meta as { sourceQuery?: string })?.sourceQuery === sourceQuery)\n // If there's a destination filter of the right kind\n if (destination && Array.isArray(destination) && destination?.length > 0) {\n const targetFilter = assertEx(destination, () => 'Missing destination')\n // Find all BWs that satisfy the destination constraint\n bws = bws.filter((bw) => {\n const targetDestinationField = (bw?.$meta as { destination?: string[] })?.destination\n // If the destination field is an array and contains at least one element\n return targetDestinationField !== undefined && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ?\n // Check that the targetDestinationField contains all the elements in the targetFilter\n containsAll(targetFilter, targetDestinationField ?? [])\n // Otherwise, filter it out\n : false\n })\n }\n if (timestamp !== undefined) {\n bws =\n order === 'desc' ?\n bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp)\n : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp)\n }\n const parsedLimit = limit ?? bws.length\n const parsedOffset = offset ?? 0\n return bws.slice(parsedOffset, parsedLimit) as WithMeta<TOut>[]\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,mBAA4B;AAC5B,oBAAyB;AACzB,oBAAuB;AACvB,iBAAiC;AACjC,gCAA6C;AAC7C,2CAAoC;AACpC,wCAKO;AAsDP,IAAMA,eAAe,wBAACC,OAA0CA,GAAGC,cAAcC,QAA5D;AAEd,IAAMC,4BAAN,cAIGC,yDAAAA;EAvEV,OAuEUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,MAAyBE,cAAcC,UAAkB;AACvD,UAAMC,aAASC,wBAASF,UAAUC,OAAOE,mEAAAA,GAAoCC,IAAAA,GAAO,MAAM,uBAAA;AAC1F,QAAI,CAACH,OAAQ,QAAO,CAAA;AACpB,UAAMI,gBAAYH,wBAAS,MAAM,KAAKI,kBAAiB,GAAI,MAAM,6BAAA;AACjE,UAAM,EAAEC,WAAWC,gBAAgBC,iBAAiBC,OAAOC,QAAQC,QAAQ,QAAQC,aAAaC,aAAatB,UAAS,IAAKS;AAC3H,QAAIc,OAAQ,MAAMV,WAAWW,MAAAA,KAAY,CAAA,GAAIf,OAAOgB,wCAAAA;AACpD,QAAIL,UAAU,OAAQG,OAAMA,IAAIG,QAAO;AACvC,UAAMC,eAAeZ,WAAWa,IAAI,CAACC,gBAAYC,6BAAiBD,OAAAA,CAAAA,EAAUpB,OAAOsB,oBAAAA;AACnF,QAAIJ,cAAcK,OAAQT,OAAMA,IAAId,OAAO,CAACV,WAAOkC,0BAAYlC,GAAGgB,WAAWY,YAAAA,CAAAA;AAC7E,QAAIX,gBAAgBgB,OAAQT,OAAMA,IAAId,OAAO,CAACV,WAAOkC,0BAAYlC,GAAGiB,gBAAgBA,cAAAA,CAAAA;AACpF,QAAIC,iBAAiBe,OAAQT,OAAMA,IAAId,OAAO,CAACV,WAAOkC,0BAAYlC,GAAGkB,iBAAiBA,eAAAA,CAAAA;AACtF,QAAII,YAAaE,OAAMA,IAAId,OAAO,CAACV,OAAQA,IAAImC,OAAoCb,gBAAgBA,WAAAA;AAEnG,QAAIC,eAAea,MAAMC,QAAQd,WAAAA,KAAgBA,aAAaU,SAAS,GAAG;AACxE,YAAMK,mBAAe3B,wBAASY,aAAa,MAAM,qBAAA;AAEjDC,YAAMA,IAAId,OAAO,CAACV,OAAAA;AAChB,cAAMuC,yBAA0BvC,IAAImC,OAAsCZ;AAE1E,eAAOgB,2BAA2BrC,UAAakC,MAAMC,QAAQE,sBAAAA,KAA2BA,uBAAuBN,SAAS;;cAEpHC,0BAAYI,cAAcC,0BAA0B,CAAA,CAAE;YAEtD;MACN,CAAA;IACF;AACA,QAAItC,cAAcC,QAAW;AAC3BsB,YACEH,UAAU,SACRG,IAAId,OAAOX,YAAAA,EAAcW,OAAO,CAACV,OAAOA,GAAGC,aAAaA,SAAAA,IACxDuB,IAAId,OAAOX,YAAAA,EAAcW,OAAO,CAACV,OAAOA,GAAGC,aAAaA,SAAAA;IAC9D;AACA,UAAMuC,cAAcrB,SAASK,IAAIS;AACjC,UAAMQ,eAAerB,UAAU;AAC/B,WAAOI,IAAIkB,MAAMD,cAAcD,WAAAA;EACjC;AACF;","names":["hasTimestamp","bw","timestamp","undefined","MemoryBoundWitnessDiviner","BoundWitnessDiviner","configSchemas","BoundWitnessDivinerConfigSchema","defaultConfigSchema","divineHandler","payloads","filter","assertEx","isBoundWitnessDivinerQueryPayload","pop","archivist","archivistInstance","addresses","payload_hashes","payload_schemas","limit","offset","order","sourceQuery","destination","bws","all","isBoundWitness","reverse","allAddresses","map","address","hexFromHexString","exists","length","containsAll","$meta","Array","isArray","targetFilter","targetDestinationField","parsedLimit","parsedOffset","slice"]}
|
package/dist/browser/index.js
CHANGED
|
@@ -21,22 +21,16 @@ var MemoryBoundWitnessDiviner = class extends BoundWitnessDiviner {
|
|
|
21
21
|
static defaultConfigSchema = BoundWitnessDivinerConfigSchema;
|
|
22
22
|
async divineHandler(payloads) {
|
|
23
23
|
const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => "Missing query payload");
|
|
24
|
-
if (!filter)
|
|
25
|
-
return [];
|
|
24
|
+
if (!filter) return [];
|
|
26
25
|
const archivist = assertEx(await this.archivistInstance(), () => "Unable to resolve archivist");
|
|
27
26
|
const { addresses, payload_hashes, payload_schemas, limit, offset, order = "desc", sourceQuery, destination, timestamp } = filter;
|
|
28
27
|
let bws = (await archivist?.all?.() ?? []).filter(isBoundWitness);
|
|
29
|
-
if (order === "desc")
|
|
30
|
-
bws = bws.reverse();
|
|
28
|
+
if (order === "desc") bws = bws.reverse();
|
|
31
29
|
const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists);
|
|
32
|
-
if (allAddresses?.length)
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
if (payload_schemas?.length)
|
|
37
|
-
bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas));
|
|
38
|
-
if (sourceQuery)
|
|
39
|
-
bws = bws.filter((bw) => bw?.$meta?.sourceQuery === sourceQuery);
|
|
30
|
+
if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses));
|
|
31
|
+
if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes));
|
|
32
|
+
if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas));
|
|
33
|
+
if (sourceQuery) bws = bws.filter((bw) => bw?.$meta?.sourceQuery === sourceQuery);
|
|
40
34
|
if (destination && Array.isArray(destination) && destination?.length > 0) {
|
|
41
35
|
const targetFilter = assertEx(destination, () => "Missing destination");
|
|
42
36
|
bws = bws.filter((bw) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/MemoryBoundWitnessDiviner.ts"],"sourcesContent":["import { containsAll } from '@xylabs/array'\nimport { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { hexFromHexString } from '@xylabs/hex'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport {\n BoundWitnessDivinerConfigSchema,\n BoundWitnessDivinerParams,\n BoundWitnessDivinerQueryPayload,\n isBoundWitnessDivinerQueryPayload,\n} from '@xyo-network/diviner-boundwitness-model'\nimport { Schema, WithMeta } from '@xyo-network/payload-model'\n\nexport interface EqualityComparisonOperators {\n /**\n * 'Not Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value does not match the provided string.\n * Example: field != 'value'\n */\n '!=': string\n\n /**\n * 'Less Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than the provided string.\n * Example: field < 'value'\n */\n '<': string\n\n /**\n * 'Less Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than or equal to the provided string.\n * Example: field <= 'value'\n */\n '<=': string\n\n /**\n * 'Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value matches the provided string exactly.\n * Example: field = 'value'\n */\n '=': string\n\n /**\n * 'Greater Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than the provided string.\n * Example: field > 'value'\n */\n '>': string\n\n /**\n * 'Greater Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than or equal to the provided string.\n * Example: field >= 'value'\n */\n '>=': string\n}\n\ntype WithTimestamp = BoundWitness & { timestamp: number }\nconst hasTimestamp = (bw: BoundWitness): bw is WithTimestamp => bw.timestamp !== undefined\n\nexport class MemoryBoundWitnessDiviner<\n TParams extends BoundWitnessDivinerParams = BoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, BoundWitnessDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = BoundWitnessDivinerConfigSchema\n\n protected override async divineHandler(payloads?: TIn[]) {\n const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => 'Missing query payload')\n if (!filter) return []\n const archivist = assertEx(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const { addresses, payload_hashes, payload_schemas, limit, offset, order = 'desc', sourceQuery, destination, timestamp } = filter\n let bws = ((await archivist?.all?.()) ?? []).filter(isBoundWitness) as WithMeta<BoundWitness>[]\n if (order === 'desc') bws = bws.reverse()\n const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists)\n if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses))\n if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes))\n if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas))\n if (sourceQuery) bws = bws.filter((bw) => (bw?.$meta as { sourceQuery?: string })?.sourceQuery === sourceQuery)\n // If there's a destination filter of the right kind\n if (destination && Array.isArray(destination) && destination?.length > 0) {\n const targetFilter = assertEx(destination, () => 'Missing destination')\n // Find all BWs that satisfy the destination constraint\n bws = bws.filter((bw) => {\n const targetDestinationField = (bw?.$meta as { destination?: string[] })?.destination\n // If the destination field is an array and contains at least one element\n return targetDestinationField !== undefined && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ?\n // Check that the targetDestinationField contains all the elements in the targetFilter\n containsAll(targetFilter, targetDestinationField ?? [])\n // Otherwise, filter it out\n : false\n })\n }\n if (timestamp !== undefined) {\n bws =\n order === 'desc' ?\n bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp)\n : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp)\n }\n const parsedLimit = limit ?? bws.length\n const parsedOffset = offset ?? 0\n return bws.slice(parsedOffset, parsedLimit) as WithMeta<TOut>[]\n }\n}\n"],"mappings":";;;;AAAA,SAASA,mBAAmB;AAC5B,SAASC,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,wBAAwB;AACjC,SAAuBC,sBAAsB;AAC7C,SAASC,2BAA2B;AACpC,SACEC,iCAGAC,yCACK;AAsDP,IAAMC,eAAe,wBAACC,OAA0CA,GAAGC,cAAcC,QAA5D;AAEd,IAAMC,4BAAN,cAIGC,oBAAAA;EAvEV,OAuEUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,MAAyBE,cAAcC,UAAkB;AACvD,UAAMC,SAASC,SAASF,UAAUC,OAAOE,iCAAAA,GAAoCC,IAAAA,GAAO,MAAM,uBAAA;AAC1F,QAAI,CAACH
|
|
1
|
+
{"version":3,"sources":["../../src/MemoryBoundWitnessDiviner.ts"],"sourcesContent":["import { containsAll } from '@xylabs/array'\nimport { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { hexFromHexString } from '@xylabs/hex'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport {\n BoundWitnessDivinerConfigSchema,\n BoundWitnessDivinerParams,\n BoundWitnessDivinerQueryPayload,\n isBoundWitnessDivinerQueryPayload,\n} from '@xyo-network/diviner-boundwitness-model'\nimport { Schema, WithMeta } from '@xyo-network/payload-model'\n\nexport interface EqualityComparisonOperators {\n /**\n * 'Not Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value does not match the provided string.\n * Example: field != 'value'\n */\n '!=': string\n\n /**\n * 'Less Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than the provided string.\n * Example: field < 'value'\n */\n '<': string\n\n /**\n * 'Less Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than or equal to the provided string.\n * Example: field <= 'value'\n */\n '<=': string\n\n /**\n * 'Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value matches the provided string exactly.\n * Example: field = 'value'\n */\n '=': string\n\n /**\n * 'Greater Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than the provided string.\n * Example: field > 'value'\n */\n '>': string\n\n /**\n * 'Greater Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than or equal to the provided string.\n * Example: field >= 'value'\n */\n '>=': string\n}\n\ntype WithTimestamp = BoundWitness & { timestamp: number }\nconst hasTimestamp = (bw: BoundWitness): bw is WithTimestamp => bw.timestamp !== undefined\n\nexport class MemoryBoundWitnessDiviner<\n TParams extends BoundWitnessDivinerParams = BoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, BoundWitnessDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = BoundWitnessDivinerConfigSchema\n\n protected override async divineHandler(payloads?: TIn[]) {\n const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => 'Missing query payload')\n if (!filter) return []\n const archivist = assertEx(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const { addresses, payload_hashes, payload_schemas, limit, offset, order = 'desc', sourceQuery, destination, timestamp } = filter\n let bws = ((await archivist?.all?.()) ?? []).filter(isBoundWitness) as WithMeta<BoundWitness>[]\n if (order === 'desc') bws = bws.reverse()\n const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists)\n if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses))\n if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes))\n if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas))\n if (sourceQuery) bws = bws.filter((bw) => (bw?.$meta as { sourceQuery?: string })?.sourceQuery === sourceQuery)\n // If there's a destination filter of the right kind\n if (destination && Array.isArray(destination) && destination?.length > 0) {\n const targetFilter = assertEx(destination, () => 'Missing destination')\n // Find all BWs that satisfy the destination constraint\n bws = bws.filter((bw) => {\n const targetDestinationField = (bw?.$meta as { destination?: string[] })?.destination\n // If the destination field is an array and contains at least one element\n return targetDestinationField !== undefined && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ?\n // Check that the targetDestinationField contains all the elements in the targetFilter\n containsAll(targetFilter, targetDestinationField ?? [])\n // Otherwise, filter it out\n : false\n })\n }\n if (timestamp !== undefined) {\n bws =\n order === 'desc' ?\n bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp)\n : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp)\n }\n const parsedLimit = limit ?? bws.length\n const parsedOffset = offset ?? 0\n return bws.slice(parsedOffset, parsedLimit) as WithMeta<TOut>[]\n }\n}\n"],"mappings":";;;;AAAA,SAASA,mBAAmB;AAC5B,SAASC,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,wBAAwB;AACjC,SAAuBC,sBAAsB;AAC7C,SAASC,2BAA2B;AACpC,SACEC,iCAGAC,yCACK;AAsDP,IAAMC,eAAe,wBAACC,OAA0CA,GAAGC,cAAcC,QAA5D;AAEd,IAAMC,4BAAN,cAIGC,oBAAAA;EAvEV,OAuEUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,MAAyBE,cAAcC,UAAkB;AACvD,UAAMC,SAASC,SAASF,UAAUC,OAAOE,iCAAAA,GAAoCC,IAAAA,GAAO,MAAM,uBAAA;AAC1F,QAAI,CAACH,OAAQ,QAAO,CAAA;AACpB,UAAMI,YAAYH,SAAS,MAAM,KAAKI,kBAAiB,GAAI,MAAM,6BAAA;AACjE,UAAM,EAAEC,WAAWC,gBAAgBC,iBAAiBC,OAAOC,QAAQC,QAAQ,QAAQC,aAAaC,aAAatB,UAAS,IAAKS;AAC3H,QAAIc,OAAQ,MAAMV,WAAWW,MAAAA,KAAY,CAAA,GAAIf,OAAOgB,cAAAA;AACpD,QAAIL,UAAU,OAAQG,OAAMA,IAAIG,QAAO;AACvC,UAAMC,eAAeZ,WAAWa,IAAI,CAACC,YAAYC,iBAAiBD,OAAAA,CAAAA,EAAUpB,OAAOsB,MAAAA;AACnF,QAAIJ,cAAcK,OAAQT,OAAMA,IAAId,OAAO,CAACV,OAAOkC,YAAYlC,GAAGgB,WAAWY,YAAAA,CAAAA;AAC7E,QAAIX,gBAAgBgB,OAAQT,OAAMA,IAAId,OAAO,CAACV,OAAOkC,YAAYlC,GAAGiB,gBAAgBA,cAAAA,CAAAA;AACpF,QAAIC,iBAAiBe,OAAQT,OAAMA,IAAId,OAAO,CAACV,OAAOkC,YAAYlC,GAAGkB,iBAAiBA,eAAAA,CAAAA;AACtF,QAAII,YAAaE,OAAMA,IAAId,OAAO,CAACV,OAAQA,IAAImC,OAAoCb,gBAAgBA,WAAAA;AAEnG,QAAIC,eAAea,MAAMC,QAAQd,WAAAA,KAAgBA,aAAaU,SAAS,GAAG;AACxE,YAAMK,eAAe3B,SAASY,aAAa,MAAM,qBAAA;AAEjDC,YAAMA,IAAId,OAAO,CAACV,OAAAA;AAChB,cAAMuC,yBAA0BvC,IAAImC,OAAsCZ;AAE1E,eAAOgB,2BAA2BrC,UAAakC,MAAMC,QAAQE,sBAAAA,KAA2BA,uBAAuBN,SAAS;;UAEpHC,YAAYI,cAAcC,0BAA0B,CAAA,CAAE;YAEtD;MACN,CAAA;IACF;AACA,QAAItC,cAAcC,QAAW;AAC3BsB,YACEH,UAAU,SACRG,IAAId,OAAOX,YAAAA,EAAcW,OAAO,CAACV,OAAOA,GAAGC,aAAaA,SAAAA,IACxDuB,IAAId,OAAOX,YAAAA,EAAcW,OAAO,CAACV,OAAOA,GAAGC,aAAaA,SAAAA;IAC9D;AACA,UAAMuC,cAAcrB,SAASK,IAAIS;AACjC,UAAMQ,eAAerB,UAAU;AAC/B,WAAOI,IAAIkB,MAAMD,cAAcD,WAAAA;EACjC;AACF;","names":["containsAll","assertEx","exists","hexFromHexString","isBoundWitness","BoundWitnessDiviner","BoundWitnessDivinerConfigSchema","isBoundWitnessDivinerQueryPayload","hasTimestamp","bw","timestamp","undefined","MemoryBoundWitnessDiviner","BoundWitnessDiviner","configSchemas","BoundWitnessDivinerConfigSchema","defaultConfigSchema","divineHandler","payloads","filter","assertEx","isBoundWitnessDivinerQueryPayload","pop","archivist","archivistInstance","addresses","payload_hashes","payload_schemas","limit","offset","order","sourceQuery","destination","bws","all","isBoundWitness","reverse","allAddresses","map","address","hexFromHexString","exists","length","containsAll","$meta","Array","isArray","targetFilter","targetDestinationField","parsedLimit","parsedOffset","slice"]}
|
package/dist/neutral/index.cjs
CHANGED
|
@@ -45,22 +45,16 @@ var MemoryBoundWitnessDiviner = class extends import_diviner_boundwitness_abstra
|
|
|
45
45
|
static defaultConfigSchema = import_diviner_boundwitness_model.BoundWitnessDivinerConfigSchema;
|
|
46
46
|
async divineHandler(payloads) {
|
|
47
47
|
const filter = (0, import_assert.assertEx)(payloads?.filter(import_diviner_boundwitness_model.isBoundWitnessDivinerQueryPayload)?.pop(), () => "Missing query payload");
|
|
48
|
-
if (!filter)
|
|
49
|
-
return [];
|
|
48
|
+
if (!filter) return [];
|
|
50
49
|
const archivist = (0, import_assert.assertEx)(await this.archivistInstance(), () => "Unable to resolve archivist");
|
|
51
50
|
const { addresses, payload_hashes, payload_schemas, limit, offset, order = "desc", sourceQuery, destination, timestamp } = filter;
|
|
52
51
|
let bws = (await archivist?.all?.() ?? []).filter(import_boundwitness_model.isBoundWitness);
|
|
53
|
-
if (order === "desc")
|
|
54
|
-
bws = bws.reverse();
|
|
52
|
+
if (order === "desc") bws = bws.reverse();
|
|
55
53
|
const allAddresses = addresses?.map((address) => (0, import_hex.hexFromHexString)(address)).filter(import_exists.exists);
|
|
56
|
-
if (allAddresses?.length)
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
if (payload_schemas?.length)
|
|
61
|
-
bws = bws.filter((bw) => (0, import_array.containsAll)(bw.payload_schemas, payload_schemas));
|
|
62
|
-
if (sourceQuery)
|
|
63
|
-
bws = bws.filter((bw) => bw?.$meta?.sourceQuery === sourceQuery);
|
|
54
|
+
if (allAddresses?.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.addresses, allAddresses));
|
|
55
|
+
if (payload_hashes?.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.payload_hashes, payload_hashes));
|
|
56
|
+
if (payload_schemas?.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.payload_schemas, payload_schemas));
|
|
57
|
+
if (sourceQuery) bws = bws.filter((bw) => bw?.$meta?.sourceQuery === sourceQuery);
|
|
64
58
|
if (destination && Array.isArray(destination) && destination?.length > 0) {
|
|
65
59
|
const targetFilter = (0, import_assert.assertEx)(destination, () => "Missing destination");
|
|
66
60
|
bws = bws.filter((bw) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/MemoryBoundWitnessDiviner.ts"],"sourcesContent":["export * from './MemoryBoundWitnessDiviner'\n","import { containsAll } from '@xylabs/array'\nimport { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { hexFromHexString } from '@xylabs/hex'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport {\n BoundWitnessDivinerConfigSchema,\n BoundWitnessDivinerParams,\n BoundWitnessDivinerQueryPayload,\n isBoundWitnessDivinerQueryPayload,\n} from '@xyo-network/diviner-boundwitness-model'\nimport { Schema, WithMeta } from '@xyo-network/payload-model'\n\nexport interface EqualityComparisonOperators {\n /**\n * 'Not Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value does not match the provided string.\n * Example: field != 'value'\n */\n '!=': string\n\n /**\n * 'Less Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than the provided string.\n * Example: field < 'value'\n */\n '<': string\n\n /**\n * 'Less Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than or equal to the provided string.\n * Example: field <= 'value'\n */\n '<=': string\n\n /**\n * 'Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value matches the provided string exactly.\n * Example: field = 'value'\n */\n '=': string\n\n /**\n * 'Greater Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than the provided string.\n * Example: field > 'value'\n */\n '>': string\n\n /**\n * 'Greater Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than or equal to the provided string.\n * Example: field >= 'value'\n */\n '>=': string\n}\n\ntype WithTimestamp = BoundWitness & { timestamp: number }\nconst hasTimestamp = (bw: BoundWitness): bw is WithTimestamp => bw.timestamp !== undefined\n\nexport class MemoryBoundWitnessDiviner<\n TParams extends BoundWitnessDivinerParams = BoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, BoundWitnessDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = BoundWitnessDivinerConfigSchema\n\n protected override async divineHandler(payloads?: TIn[]) {\n const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => 'Missing query payload')\n if (!filter) return []\n const archivist = assertEx(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const { addresses, payload_hashes, payload_schemas, limit, offset, order = 'desc', sourceQuery, destination, timestamp } = filter\n let bws = ((await archivist?.all?.()) ?? []).filter(isBoundWitness) as WithMeta<BoundWitness>[]\n if (order === 'desc') bws = bws.reverse()\n const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists)\n if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses))\n if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes))\n if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas))\n if (sourceQuery) bws = bws.filter((bw) => (bw?.$meta as { sourceQuery?: string })?.sourceQuery === sourceQuery)\n // If there's a destination filter of the right kind\n if (destination && Array.isArray(destination) && destination?.length > 0) {\n const targetFilter = assertEx(destination, () => 'Missing destination')\n // Find all BWs that satisfy the destination constraint\n bws = bws.filter((bw) => {\n const targetDestinationField = (bw?.$meta as { destination?: string[] })?.destination\n // If the destination field is an array and contains at least one element\n return targetDestinationField !== undefined && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ?\n // Check that the targetDestinationField contains all the elements in the targetFilter\n containsAll(targetFilter, targetDestinationField ?? [])\n // Otherwise, filter it out\n : false\n })\n }\n if (timestamp !== undefined) {\n bws =\n order === 'desc' ?\n bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp)\n : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp)\n }\n const parsedLimit = limit ?? bws.length\n const parsedOffset = offset ?? 0\n return bws.slice(parsedOffset, parsedLimit) as WithMeta<TOut>[]\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,mBAA4B;AAC5B,oBAAyB;AACzB,oBAAuB;AACvB,iBAAiC;AACjC,gCAA6C;AAC7C,2CAAoC;AACpC,wCAKO;AAsDP,IAAMA,eAAe,wBAACC,OAA0CA,GAAGC,cAAcC,QAA5D;AAEd,IAAMC,4BAAN,cAIGC,yDAAAA;EAvEV,OAuEUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,MAAyBE,cAAcC,UAAkB;AACvD,UAAMC,aAASC,wBAASF,UAAUC,OAAOE,mEAAAA,GAAoCC,IAAAA,GAAO,MAAM,uBAAA;AAC1F,QAAI,CAACH
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/MemoryBoundWitnessDiviner.ts"],"sourcesContent":["export * from './MemoryBoundWitnessDiviner'\n","import { containsAll } from '@xylabs/array'\nimport { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { hexFromHexString } from '@xylabs/hex'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport {\n BoundWitnessDivinerConfigSchema,\n BoundWitnessDivinerParams,\n BoundWitnessDivinerQueryPayload,\n isBoundWitnessDivinerQueryPayload,\n} from '@xyo-network/diviner-boundwitness-model'\nimport { Schema, WithMeta } from '@xyo-network/payload-model'\n\nexport interface EqualityComparisonOperators {\n /**\n * 'Not Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value does not match the provided string.\n * Example: field != 'value'\n */\n '!=': string\n\n /**\n * 'Less Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than the provided string.\n * Example: field < 'value'\n */\n '<': string\n\n /**\n * 'Less Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than or equal to the provided string.\n * Example: field <= 'value'\n */\n '<=': string\n\n /**\n * 'Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value matches the provided string exactly.\n * Example: field = 'value'\n */\n '=': string\n\n /**\n * 'Greater Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than the provided string.\n * Example: field > 'value'\n */\n '>': string\n\n /**\n * 'Greater Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than or equal to the provided string.\n * Example: field >= 'value'\n */\n '>=': string\n}\n\ntype WithTimestamp = BoundWitness & { timestamp: number }\nconst hasTimestamp = (bw: BoundWitness): bw is WithTimestamp => bw.timestamp !== undefined\n\nexport class MemoryBoundWitnessDiviner<\n TParams extends BoundWitnessDivinerParams = BoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, BoundWitnessDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = BoundWitnessDivinerConfigSchema\n\n protected override async divineHandler(payloads?: TIn[]) {\n const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => 'Missing query payload')\n if (!filter) return []\n const archivist = assertEx(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const { addresses, payload_hashes, payload_schemas, limit, offset, order = 'desc', sourceQuery, destination, timestamp } = filter\n let bws = ((await archivist?.all?.()) ?? []).filter(isBoundWitness) as WithMeta<BoundWitness>[]\n if (order === 'desc') bws = bws.reverse()\n const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists)\n if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses))\n if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes))\n if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas))\n if (sourceQuery) bws = bws.filter((bw) => (bw?.$meta as { sourceQuery?: string })?.sourceQuery === sourceQuery)\n // If there's a destination filter of the right kind\n if (destination && Array.isArray(destination) && destination?.length > 0) {\n const targetFilter = assertEx(destination, () => 'Missing destination')\n // Find all BWs that satisfy the destination constraint\n bws = bws.filter((bw) => {\n const targetDestinationField = (bw?.$meta as { destination?: string[] })?.destination\n // If the destination field is an array and contains at least one element\n return targetDestinationField !== undefined && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ?\n // Check that the targetDestinationField contains all the elements in the targetFilter\n containsAll(targetFilter, targetDestinationField ?? [])\n // Otherwise, filter it out\n : false\n })\n }\n if (timestamp !== undefined) {\n bws =\n order === 'desc' ?\n bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp)\n : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp)\n }\n const parsedLimit = limit ?? bws.length\n const parsedOffset = offset ?? 0\n return bws.slice(parsedOffset, parsedLimit) as WithMeta<TOut>[]\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,mBAA4B;AAC5B,oBAAyB;AACzB,oBAAuB;AACvB,iBAAiC;AACjC,gCAA6C;AAC7C,2CAAoC;AACpC,wCAKO;AAsDP,IAAMA,eAAe,wBAACC,OAA0CA,GAAGC,cAAcC,QAA5D;AAEd,IAAMC,4BAAN,cAIGC,yDAAAA;EAvEV,OAuEUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,MAAyBE,cAAcC,UAAkB;AACvD,UAAMC,aAASC,wBAASF,UAAUC,OAAOE,mEAAAA,GAAoCC,IAAAA,GAAO,MAAM,uBAAA;AAC1F,QAAI,CAACH,OAAQ,QAAO,CAAA;AACpB,UAAMI,gBAAYH,wBAAS,MAAM,KAAKI,kBAAiB,GAAI,MAAM,6BAAA;AACjE,UAAM,EAAEC,WAAWC,gBAAgBC,iBAAiBC,OAAOC,QAAQC,QAAQ,QAAQC,aAAaC,aAAatB,UAAS,IAAKS;AAC3H,QAAIc,OAAQ,MAAMV,WAAWW,MAAAA,KAAY,CAAA,GAAIf,OAAOgB,wCAAAA;AACpD,QAAIL,UAAU,OAAQG,OAAMA,IAAIG,QAAO;AACvC,UAAMC,eAAeZ,WAAWa,IAAI,CAACC,gBAAYC,6BAAiBD,OAAAA,CAAAA,EAAUpB,OAAOsB,oBAAAA;AACnF,QAAIJ,cAAcK,OAAQT,OAAMA,IAAId,OAAO,CAACV,WAAOkC,0BAAYlC,GAAGgB,WAAWY,YAAAA,CAAAA;AAC7E,QAAIX,gBAAgBgB,OAAQT,OAAMA,IAAId,OAAO,CAACV,WAAOkC,0BAAYlC,GAAGiB,gBAAgBA,cAAAA,CAAAA;AACpF,QAAIC,iBAAiBe,OAAQT,OAAMA,IAAId,OAAO,CAACV,WAAOkC,0BAAYlC,GAAGkB,iBAAiBA,eAAAA,CAAAA;AACtF,QAAII,YAAaE,OAAMA,IAAId,OAAO,CAACV,OAAQA,IAAImC,OAAoCb,gBAAgBA,WAAAA;AAEnG,QAAIC,eAAea,MAAMC,QAAQd,WAAAA,KAAgBA,aAAaU,SAAS,GAAG;AACxE,YAAMK,mBAAe3B,wBAASY,aAAa,MAAM,qBAAA;AAEjDC,YAAMA,IAAId,OAAO,CAACV,OAAAA;AAChB,cAAMuC,yBAA0BvC,IAAImC,OAAsCZ;AAE1E,eAAOgB,2BAA2BrC,UAAakC,MAAMC,QAAQE,sBAAAA,KAA2BA,uBAAuBN,SAAS;;cAEpHC,0BAAYI,cAAcC,0BAA0B,CAAA,CAAE;YAEtD;MACN,CAAA;IACF;AACA,QAAItC,cAAcC,QAAW;AAC3BsB,YACEH,UAAU,SACRG,IAAId,OAAOX,YAAAA,EAAcW,OAAO,CAACV,OAAOA,GAAGC,aAAaA,SAAAA,IACxDuB,IAAId,OAAOX,YAAAA,EAAcW,OAAO,CAACV,OAAOA,GAAGC,aAAaA,SAAAA;IAC9D;AACA,UAAMuC,cAAcrB,SAASK,IAAIS;AACjC,UAAMQ,eAAerB,UAAU;AAC/B,WAAOI,IAAIkB,MAAMD,cAAcD,WAAAA;EACjC;AACF;","names":["hasTimestamp","bw","timestamp","undefined","MemoryBoundWitnessDiviner","BoundWitnessDiviner","configSchemas","BoundWitnessDivinerConfigSchema","defaultConfigSchema","divineHandler","payloads","filter","assertEx","isBoundWitnessDivinerQueryPayload","pop","archivist","archivistInstance","addresses","payload_hashes","payload_schemas","limit","offset","order","sourceQuery","destination","bws","all","isBoundWitness","reverse","allAddresses","map","address","hexFromHexString","exists","length","containsAll","$meta","Array","isArray","targetFilter","targetDestinationField","parsedLimit","parsedOffset","slice"]}
|
package/dist/neutral/index.js
CHANGED
|
@@ -21,22 +21,16 @@ var MemoryBoundWitnessDiviner = class extends BoundWitnessDiviner {
|
|
|
21
21
|
static defaultConfigSchema = BoundWitnessDivinerConfigSchema;
|
|
22
22
|
async divineHandler(payloads) {
|
|
23
23
|
const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => "Missing query payload");
|
|
24
|
-
if (!filter)
|
|
25
|
-
return [];
|
|
24
|
+
if (!filter) return [];
|
|
26
25
|
const archivist = assertEx(await this.archivistInstance(), () => "Unable to resolve archivist");
|
|
27
26
|
const { addresses, payload_hashes, payload_schemas, limit, offset, order = "desc", sourceQuery, destination, timestamp } = filter;
|
|
28
27
|
let bws = (await archivist?.all?.() ?? []).filter(isBoundWitness);
|
|
29
|
-
if (order === "desc")
|
|
30
|
-
bws = bws.reverse();
|
|
28
|
+
if (order === "desc") bws = bws.reverse();
|
|
31
29
|
const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists);
|
|
32
|
-
if (allAddresses?.length)
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
if (payload_schemas?.length)
|
|
37
|
-
bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas));
|
|
38
|
-
if (sourceQuery)
|
|
39
|
-
bws = bws.filter((bw) => bw?.$meta?.sourceQuery === sourceQuery);
|
|
30
|
+
if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses));
|
|
31
|
+
if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes));
|
|
32
|
+
if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas));
|
|
33
|
+
if (sourceQuery) bws = bws.filter((bw) => bw?.$meta?.sourceQuery === sourceQuery);
|
|
40
34
|
if (destination && Array.isArray(destination) && destination?.length > 0) {
|
|
41
35
|
const targetFilter = assertEx(destination, () => "Missing destination");
|
|
42
36
|
bws = bws.filter((bw) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/MemoryBoundWitnessDiviner.ts"],"sourcesContent":["import { containsAll } from '@xylabs/array'\nimport { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { hexFromHexString } from '@xylabs/hex'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport {\n BoundWitnessDivinerConfigSchema,\n BoundWitnessDivinerParams,\n BoundWitnessDivinerQueryPayload,\n isBoundWitnessDivinerQueryPayload,\n} from '@xyo-network/diviner-boundwitness-model'\nimport { Schema, WithMeta } from '@xyo-network/payload-model'\n\nexport interface EqualityComparisonOperators {\n /**\n * 'Not Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value does not match the provided string.\n * Example: field != 'value'\n */\n '!=': string\n\n /**\n * 'Less Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than the provided string.\n * Example: field < 'value'\n */\n '<': string\n\n /**\n * 'Less Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than or equal to the provided string.\n * Example: field <= 'value'\n */\n '<=': string\n\n /**\n * 'Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value matches the provided string exactly.\n * Example: field = 'value'\n */\n '=': string\n\n /**\n * 'Greater Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than the provided string.\n * Example: field > 'value'\n */\n '>': string\n\n /**\n * 'Greater Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than or equal to the provided string.\n * Example: field >= 'value'\n */\n '>=': string\n}\n\ntype WithTimestamp = BoundWitness & { timestamp: number }\nconst hasTimestamp = (bw: BoundWitness): bw is WithTimestamp => bw.timestamp !== undefined\n\nexport class MemoryBoundWitnessDiviner<\n TParams extends BoundWitnessDivinerParams = BoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, BoundWitnessDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = BoundWitnessDivinerConfigSchema\n\n protected override async divineHandler(payloads?: TIn[]) {\n const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => 'Missing query payload')\n if (!filter) return []\n const archivist = assertEx(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const { addresses, payload_hashes, payload_schemas, limit, offset, order = 'desc', sourceQuery, destination, timestamp } = filter\n let bws = ((await archivist?.all?.()) ?? []).filter(isBoundWitness) as WithMeta<BoundWitness>[]\n if (order === 'desc') bws = bws.reverse()\n const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists)\n if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses))\n if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes))\n if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas))\n if (sourceQuery) bws = bws.filter((bw) => (bw?.$meta as { sourceQuery?: string })?.sourceQuery === sourceQuery)\n // If there's a destination filter of the right kind\n if (destination && Array.isArray(destination) && destination?.length > 0) {\n const targetFilter = assertEx(destination, () => 'Missing destination')\n // Find all BWs that satisfy the destination constraint\n bws = bws.filter((bw) => {\n const targetDestinationField = (bw?.$meta as { destination?: string[] })?.destination\n // If the destination field is an array and contains at least one element\n return targetDestinationField !== undefined && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ?\n // Check that the targetDestinationField contains all the elements in the targetFilter\n containsAll(targetFilter, targetDestinationField ?? [])\n // Otherwise, filter it out\n : false\n })\n }\n if (timestamp !== undefined) {\n bws =\n order === 'desc' ?\n bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp)\n : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp)\n }\n const parsedLimit = limit ?? bws.length\n const parsedOffset = offset ?? 0\n return bws.slice(parsedOffset, parsedLimit) as WithMeta<TOut>[]\n }\n}\n"],"mappings":";;;;AAAA,SAASA,mBAAmB;AAC5B,SAASC,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,wBAAwB;AACjC,SAAuBC,sBAAsB;AAC7C,SAASC,2BAA2B;AACpC,SACEC,iCAGAC,yCACK;AAsDP,IAAMC,eAAe,wBAACC,OAA0CA,GAAGC,cAAcC,QAA5D;AAEd,IAAMC,4BAAN,cAIGC,oBAAAA;EAvEV,OAuEUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,MAAyBE,cAAcC,UAAkB;AACvD,UAAMC,SAASC,SAASF,UAAUC,OAAOE,iCAAAA,GAAoCC,IAAAA,GAAO,MAAM,uBAAA;AAC1F,QAAI,CAACH
|
|
1
|
+
{"version":3,"sources":["../../src/MemoryBoundWitnessDiviner.ts"],"sourcesContent":["import { containsAll } from '@xylabs/array'\nimport { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { hexFromHexString } from '@xylabs/hex'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport {\n BoundWitnessDivinerConfigSchema,\n BoundWitnessDivinerParams,\n BoundWitnessDivinerQueryPayload,\n isBoundWitnessDivinerQueryPayload,\n} from '@xyo-network/diviner-boundwitness-model'\nimport { Schema, WithMeta } from '@xyo-network/payload-model'\n\nexport interface EqualityComparisonOperators {\n /**\n * 'Not Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value does not match the provided string.\n * Example: field != 'value'\n */\n '!=': string\n\n /**\n * 'Less Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than the provided string.\n * Example: field < 'value'\n */\n '<': string\n\n /**\n * 'Less Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than or equal to the provided string.\n * Example: field <= 'value'\n */\n '<=': string\n\n /**\n * 'Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value matches the provided string exactly.\n * Example: field = 'value'\n */\n '=': string\n\n /**\n * 'Greater Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than the provided string.\n * Example: field > 'value'\n */\n '>': string\n\n /**\n * 'Greater Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than or equal to the provided string.\n * Example: field >= 'value'\n */\n '>=': string\n}\n\ntype WithTimestamp = BoundWitness & { timestamp: number }\nconst hasTimestamp = (bw: BoundWitness): bw is WithTimestamp => bw.timestamp !== undefined\n\nexport class MemoryBoundWitnessDiviner<\n TParams extends BoundWitnessDivinerParams = BoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, BoundWitnessDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = BoundWitnessDivinerConfigSchema\n\n protected override async divineHandler(payloads?: TIn[]) {\n const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => 'Missing query payload')\n if (!filter) return []\n const archivist = assertEx(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const { addresses, payload_hashes, payload_schemas, limit, offset, order = 'desc', sourceQuery, destination, timestamp } = filter\n let bws = ((await archivist?.all?.()) ?? []).filter(isBoundWitness) as WithMeta<BoundWitness>[]\n if (order === 'desc') bws = bws.reverse()\n const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists)\n if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses))\n if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes))\n if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas))\n if (sourceQuery) bws = bws.filter((bw) => (bw?.$meta as { sourceQuery?: string })?.sourceQuery === sourceQuery)\n // If there's a destination filter of the right kind\n if (destination && Array.isArray(destination) && destination?.length > 0) {\n const targetFilter = assertEx(destination, () => 'Missing destination')\n // Find all BWs that satisfy the destination constraint\n bws = bws.filter((bw) => {\n const targetDestinationField = (bw?.$meta as { destination?: string[] })?.destination\n // If the destination field is an array and contains at least one element\n return targetDestinationField !== undefined && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ?\n // Check that the targetDestinationField contains all the elements in the targetFilter\n containsAll(targetFilter, targetDestinationField ?? [])\n // Otherwise, filter it out\n : false\n })\n }\n if (timestamp !== undefined) {\n bws =\n order === 'desc' ?\n bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp)\n : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp)\n }\n const parsedLimit = limit ?? bws.length\n const parsedOffset = offset ?? 0\n return bws.slice(parsedOffset, parsedLimit) as WithMeta<TOut>[]\n }\n}\n"],"mappings":";;;;AAAA,SAASA,mBAAmB;AAC5B,SAASC,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,wBAAwB;AACjC,SAAuBC,sBAAsB;AAC7C,SAASC,2BAA2B;AACpC,SACEC,iCAGAC,yCACK;AAsDP,IAAMC,eAAe,wBAACC,OAA0CA,GAAGC,cAAcC,QAA5D;AAEd,IAAMC,4BAAN,cAIGC,oBAAAA;EAvEV,OAuEUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,MAAyBE,cAAcC,UAAkB;AACvD,UAAMC,SAASC,SAASF,UAAUC,OAAOE,iCAAAA,GAAoCC,IAAAA,GAAO,MAAM,uBAAA;AAC1F,QAAI,CAACH,OAAQ,QAAO,CAAA;AACpB,UAAMI,YAAYH,SAAS,MAAM,KAAKI,kBAAiB,GAAI,MAAM,6BAAA;AACjE,UAAM,EAAEC,WAAWC,gBAAgBC,iBAAiBC,OAAOC,QAAQC,QAAQ,QAAQC,aAAaC,aAAatB,UAAS,IAAKS;AAC3H,QAAIc,OAAQ,MAAMV,WAAWW,MAAAA,KAAY,CAAA,GAAIf,OAAOgB,cAAAA;AACpD,QAAIL,UAAU,OAAQG,OAAMA,IAAIG,QAAO;AACvC,UAAMC,eAAeZ,WAAWa,IAAI,CAACC,YAAYC,iBAAiBD,OAAAA,CAAAA,EAAUpB,OAAOsB,MAAAA;AACnF,QAAIJ,cAAcK,OAAQT,OAAMA,IAAId,OAAO,CAACV,OAAOkC,YAAYlC,GAAGgB,WAAWY,YAAAA,CAAAA;AAC7E,QAAIX,gBAAgBgB,OAAQT,OAAMA,IAAId,OAAO,CAACV,OAAOkC,YAAYlC,GAAGiB,gBAAgBA,cAAAA,CAAAA;AACpF,QAAIC,iBAAiBe,OAAQT,OAAMA,IAAId,OAAO,CAACV,OAAOkC,YAAYlC,GAAGkB,iBAAiBA,eAAAA,CAAAA;AACtF,QAAII,YAAaE,OAAMA,IAAId,OAAO,CAACV,OAAQA,IAAImC,OAAoCb,gBAAgBA,WAAAA;AAEnG,QAAIC,eAAea,MAAMC,QAAQd,WAAAA,KAAgBA,aAAaU,SAAS,GAAG;AACxE,YAAMK,eAAe3B,SAASY,aAAa,MAAM,qBAAA;AAEjDC,YAAMA,IAAId,OAAO,CAACV,OAAAA;AAChB,cAAMuC,yBAA0BvC,IAAImC,OAAsCZ;AAE1E,eAAOgB,2BAA2BrC,UAAakC,MAAMC,QAAQE,sBAAAA,KAA2BA,uBAAuBN,SAAS;;UAEpHC,YAAYI,cAAcC,0BAA0B,CAAA,CAAE;YAEtD;MACN,CAAA;IACF;AACA,QAAItC,cAAcC,QAAW;AAC3BsB,YACEH,UAAU,SACRG,IAAId,OAAOX,YAAAA,EAAcW,OAAO,CAACV,OAAOA,GAAGC,aAAaA,SAAAA,IACxDuB,IAAId,OAAOX,YAAAA,EAAcW,OAAO,CAACV,OAAOA,GAAGC,aAAaA,SAAAA;IAC9D;AACA,UAAMuC,cAAcrB,SAASK,IAAIS;AACjC,UAAMQ,eAAerB,UAAU;AAC/B,WAAOI,IAAIkB,MAAMD,cAAcD,WAAAA;EACjC;AACF;","names":["containsAll","assertEx","exists","hexFromHexString","isBoundWitness","BoundWitnessDiviner","BoundWitnessDivinerConfigSchema","isBoundWitnessDivinerQueryPayload","hasTimestamp","bw","timestamp","undefined","MemoryBoundWitnessDiviner","BoundWitnessDiviner","configSchemas","BoundWitnessDivinerConfigSchema","defaultConfigSchema","divineHandler","payloads","filter","assertEx","isBoundWitnessDivinerQueryPayload","pop","archivist","archivistInstance","addresses","payload_hashes","payload_schemas","limit","offset","order","sourceQuery","destination","bws","all","isBoundWitness","reverse","allAddresses","map","address","hexFromHexString","exists","length","containsAll","$meta","Array","isArray","targetFilter","targetDestinationField","parsedLimit","parsedOffset","slice"]}
|
package/dist/node/index.cjs
CHANGED
|
@@ -20,10 +20,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
20
20
|
return to;
|
|
21
21
|
};
|
|
22
22
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
-
var __publicField = (obj, key, value) =>
|
|
24
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
25
|
-
return value;
|
|
26
|
-
};
|
|
23
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
27
24
|
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
28
25
|
|
|
29
26
|
// src/index.ts
|
|
@@ -46,25 +43,19 @@ var _MemoryBoundWitnessDiviner = class _MemoryBoundWitnessDiviner extends import
|
|
|
46
43
|
async divineHandler(payloads) {
|
|
47
44
|
var _a, _b;
|
|
48
45
|
const filter = (0, import_assert.assertEx)((_a = payloads == null ? void 0 : payloads.filter(import_diviner_boundwitness_model.isBoundWitnessDivinerQueryPayload)) == null ? void 0 : _a.pop(), () => "Missing query payload");
|
|
49
|
-
if (!filter)
|
|
50
|
-
return [];
|
|
46
|
+
if (!filter) return [];
|
|
51
47
|
const archivist = (0, import_assert.assertEx)(await this.archivistInstance(), () => "Unable to resolve archivist");
|
|
52
48
|
const { addresses, payload_hashes, payload_schemas, limit, offset, order = "desc", sourceQuery, destination, timestamp } = filter;
|
|
53
49
|
let bws = (await ((_b = archivist == null ? void 0 : archivist.all) == null ? void 0 : _b.call(archivist)) ?? []).filter(import_boundwitness_model.isBoundWitness);
|
|
54
|
-
if (order === "desc")
|
|
55
|
-
bws = bws.reverse();
|
|
50
|
+
if (order === "desc") bws = bws.reverse();
|
|
56
51
|
const allAddresses = addresses == null ? void 0 : addresses.map((address) => (0, import_hex.hexFromHexString)(address)).filter(import_exists.exists);
|
|
57
|
-
if (allAddresses == null ? void 0 : allAddresses.length)
|
|
58
|
-
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
bws = bws.filter((bw) => {
|
|
65
|
-
var _a2;
|
|
66
|
-
return ((_a2 = bw == null ? void 0 : bw.$meta) == null ? void 0 : _a2.sourceQuery) === sourceQuery;
|
|
67
|
-
});
|
|
52
|
+
if (allAddresses == null ? void 0 : allAddresses.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.addresses, allAddresses));
|
|
53
|
+
if (payload_hashes == null ? void 0 : payload_hashes.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.payload_hashes, payload_hashes));
|
|
54
|
+
if (payload_schemas == null ? void 0 : payload_schemas.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.payload_schemas, payload_schemas));
|
|
55
|
+
if (sourceQuery) bws = bws.filter((bw) => {
|
|
56
|
+
var _a2;
|
|
57
|
+
return ((_a2 = bw == null ? void 0 : bw.$meta) == null ? void 0 : _a2.sourceQuery) === sourceQuery;
|
|
58
|
+
});
|
|
68
59
|
if (destination && Array.isArray(destination) && (destination == null ? void 0 : destination.length) > 0) {
|
|
69
60
|
const targetFilter = (0, import_assert.assertEx)(destination, () => "Missing destination");
|
|
70
61
|
bws = bws.filter((bw) => {
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/MemoryBoundWitnessDiviner.ts"],"sourcesContent":["export * from './MemoryBoundWitnessDiviner'\n","import { containsAll } from '@xylabs/array'\nimport { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { hexFromHexString } from '@xylabs/hex'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport {\n BoundWitnessDivinerConfigSchema,\n BoundWitnessDivinerParams,\n BoundWitnessDivinerQueryPayload,\n isBoundWitnessDivinerQueryPayload,\n} from '@xyo-network/diviner-boundwitness-model'\nimport { Schema, WithMeta } from '@xyo-network/payload-model'\n\nexport interface EqualityComparisonOperators {\n /**\n * 'Not Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value does not match the provided string.\n * Example: field != 'value'\n */\n '!=': string\n\n /**\n * 'Less Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than the provided string.\n * Example: field < 'value'\n */\n '<': string\n\n /**\n * 'Less Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than or equal to the provided string.\n * Example: field <= 'value'\n */\n '<=': string\n\n /**\n * 'Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value matches the provided string exactly.\n * Example: field = 'value'\n */\n '=': string\n\n /**\n * 'Greater Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than the provided string.\n * Example: field > 'value'\n */\n '>': string\n\n /**\n * 'Greater Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than or equal to the provided string.\n * Example: field >= 'value'\n */\n '>=': string\n}\n\ntype WithTimestamp = BoundWitness & { timestamp: number }\nconst hasTimestamp = (bw: BoundWitness): bw is WithTimestamp => bw.timestamp !== undefined\n\nexport class MemoryBoundWitnessDiviner<\n TParams extends BoundWitnessDivinerParams = BoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, BoundWitnessDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = BoundWitnessDivinerConfigSchema\n\n protected override async divineHandler(payloads?: TIn[]) {\n const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => 'Missing query payload')\n if (!filter) return []\n const archivist = assertEx(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const { addresses, payload_hashes, payload_schemas, limit, offset, order = 'desc', sourceQuery, destination, timestamp } = filter\n let bws = ((await archivist?.all?.()) ?? []).filter(isBoundWitness) as WithMeta<BoundWitness>[]\n if (order === 'desc') bws = bws.reverse()\n const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists)\n if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses))\n if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes))\n if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas))\n if (sourceQuery) bws = bws.filter((bw) => (bw?.$meta as { sourceQuery?: string })?.sourceQuery === sourceQuery)\n // If there's a destination filter of the right kind\n if (destination && Array.isArray(destination) && destination?.length > 0) {\n const targetFilter = assertEx(destination, () => 'Missing destination')\n // Find all BWs that satisfy the destination constraint\n bws = bws.filter((bw) => {\n const targetDestinationField = (bw?.$meta as { destination?: string[] })?.destination\n // If the destination field is an array and contains at least one element\n return targetDestinationField !== undefined && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ?\n // Check that the targetDestinationField contains all the elements in the targetFilter\n containsAll(targetFilter, targetDestinationField ?? [])\n // Otherwise, filter it out\n : false\n })\n }\n if (timestamp !== undefined) {\n bws =\n order === 'desc' ?\n bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp)\n : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp)\n }\n const parsedLimit = limit ?? bws.length\n const parsedOffset = offset ?? 0\n return bws.slice(parsedOffset, parsedLimit) as WithMeta<TOut>[]\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/MemoryBoundWitnessDiviner.ts"],"sourcesContent":["export * from './MemoryBoundWitnessDiviner'\n","import { containsAll } from '@xylabs/array'\nimport { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { hexFromHexString } from '@xylabs/hex'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport {\n BoundWitnessDivinerConfigSchema,\n BoundWitnessDivinerParams,\n BoundWitnessDivinerQueryPayload,\n isBoundWitnessDivinerQueryPayload,\n} from '@xyo-network/diviner-boundwitness-model'\nimport { Schema, WithMeta } from '@xyo-network/payload-model'\n\nexport interface EqualityComparisonOperators {\n /**\n * 'Not Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value does not match the provided string.\n * Example: field != 'value'\n */\n '!=': string\n\n /**\n * 'Less Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than the provided string.\n * Example: field < 'value'\n */\n '<': string\n\n /**\n * 'Less Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than or equal to the provided string.\n * Example: field <= 'value'\n */\n '<=': string\n\n /**\n * 'Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value matches the provided string exactly.\n * Example: field = 'value'\n */\n '=': string\n\n /**\n * 'Greater Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than the provided string.\n * Example: field > 'value'\n */\n '>': string\n\n /**\n * 'Greater Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than or equal to the provided string.\n * Example: field >= 'value'\n */\n '>=': string\n}\n\ntype WithTimestamp = BoundWitness & { timestamp: number }\nconst hasTimestamp = (bw: BoundWitness): bw is WithTimestamp => bw.timestamp !== undefined\n\nexport class MemoryBoundWitnessDiviner<\n TParams extends BoundWitnessDivinerParams = BoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, BoundWitnessDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = BoundWitnessDivinerConfigSchema\n\n protected override async divineHandler(payloads?: TIn[]) {\n const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => 'Missing query payload')\n if (!filter) return []\n const archivist = assertEx(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const { addresses, payload_hashes, payload_schemas, limit, offset, order = 'desc', sourceQuery, destination, timestamp } = filter\n let bws = ((await archivist?.all?.()) ?? []).filter(isBoundWitness) as WithMeta<BoundWitness>[]\n if (order === 'desc') bws = bws.reverse()\n const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists)\n if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses))\n if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes))\n if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas))\n if (sourceQuery) bws = bws.filter((bw) => (bw?.$meta as { sourceQuery?: string })?.sourceQuery === sourceQuery)\n // If there's a destination filter of the right kind\n if (destination && Array.isArray(destination) && destination?.length > 0) {\n const targetFilter = assertEx(destination, () => 'Missing destination')\n // Find all BWs that satisfy the destination constraint\n bws = bws.filter((bw) => {\n const targetDestinationField = (bw?.$meta as { destination?: string[] })?.destination\n // If the destination field is an array and contains at least one element\n return targetDestinationField !== undefined && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ?\n // Check that the targetDestinationField contains all the elements in the targetFilter\n containsAll(targetFilter, targetDestinationField ?? [])\n // Otherwise, filter it out\n : false\n })\n }\n if (timestamp !== undefined) {\n bws =\n order === 'desc' ?\n bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp)\n : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp)\n }\n const parsedLimit = limit ?? bws.length\n const parsedOffset = offset ?? 0\n return bws.slice(parsedOffset, parsedLimit) as WithMeta<TOut>[]\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,mBAA4B;AAC5B,oBAAyB;AACzB,oBAAuB;AACvB,iBAAiC;AACjC,gCAA6C;AAC7C,2CAAoC;AACpC,wCAKO;AAsDP,IAAMA,eAAe,wBAACC,OAA0CA,GAAGC,cAAcC,QAA5D;AAEd,IAAMC,6BAAN,MAAMA,mCAIHC,yDAAAA;EAIR,MAAyBC,cAAcC,UAAkB;AA3E3D;AA4EI,UAAMC,aAASC,yBAASF,0CAAUC,OAAOE,yEAAjBH,mBAAqDI,OAAO,MAAM,uBAAA;AAC1F,QAAI,CAACH,OAAQ,QAAO,CAAA;AACpB,UAAMI,gBAAYH,wBAAS,MAAM,KAAKI,kBAAiB,GAAI,MAAM,6BAAA;AACjE,UAAM,EAAEC,WAAWC,gBAAgBC,iBAAiBC,OAAOC,QAAQC,QAAQ,QAAQC,aAAaC,aAAanB,UAAS,IAAKM;AAC3H,QAAIc,OAAQ,QAAMV,4CAAWW,QAAXX,uCAAuB,CAAA,GAAIJ,OAAOgB,wCAAAA;AACpD,QAAIL,UAAU,OAAQG,OAAMA,IAAIG,QAAO;AACvC,UAAMC,eAAeZ,uCAAWa,IAAI,CAACC,gBAAYC,6BAAiBD,OAAAA,GAAUpB,OAAOsB;AACnF,QAAIJ,6CAAcK,OAAQT,OAAMA,IAAId,OAAO,CAACP,WAAO+B,0BAAY/B,GAAGa,WAAWY,YAAAA,CAAAA;AAC7E,QAAIX,iDAAgBgB,OAAQT,OAAMA,IAAId,OAAO,CAACP,WAAO+B,0BAAY/B,GAAGc,gBAAgBA,cAAAA,CAAAA;AACpF,QAAIC,mDAAiBe,OAAQT,OAAMA,IAAId,OAAO,CAACP,WAAO+B,0BAAY/B,GAAGe,iBAAiBA,eAAAA,CAAAA;AACtF,QAAII,YAAaE,OAAMA,IAAId,OAAO,CAACP,OAAAA;AAtFvC,UAAAgC;AAsF+ChC,eAAAA,MAAAA,yBAAIiC,UAAJjC,gBAAAA,IAAwCmB,iBAAgBA;KAAAA;AAEnG,QAAIC,eAAec,MAAMC,QAAQf,WAAAA,MAAgBA,2CAAaU,UAAS,GAAG;AACxE,YAAMM,mBAAe5B,wBAASY,aAAa,MAAM,qBAAA;AAEjDC,YAAMA,IAAId,OAAO,CAACP,OAAAA;AA3FxB,YAAAgC;AA4FQ,cAAMK,0BAA0BrC,MAAAA,yBAAIiC,UAAJjC,gBAAAA,IAA0CoB;AAE1E,eAAOiB,2BAA2BnC,UAAagC,MAAMC,QAAQE,sBAAAA,KAA2BA,uBAAuBP,SAAS;;cAEpHC,0BAAYK,cAAcC,0BAA0B,CAAA,CAAE;YAEtD;MACN,CAAA;IACF;AACA,QAAIpC,cAAcC,QAAW;AAC3BmB,YACEH,UAAU,SACRG,IAAId,OAAOR,YAAAA,EAAcQ,OAAO,CAACP,OAAOA,GAAGC,aAAaA,SAAAA,IACxDoB,IAAId,OAAOR,YAAAA,EAAcQ,OAAO,CAACP,OAAOA,GAAGC,aAAaA,SAAAA;IAC9D;AACA,UAAMqC,cAActB,SAASK,IAAIS;AACjC,UAAMS,eAAetB,UAAU;AAC/B,WAAOI,IAAImB,MAAMD,cAAcD,WAAAA;EACjC;AACF;AAxCUlC;AACR,cALWD,4BAKcsC,iBAA0B;KAAI,mEAAMA;EAAeC;;AAC5E,cANWvC,4BAMcwC,uBAA8BD;AANlD,IAAMvC,4BAAN;","names":["hasTimestamp","bw","timestamp","undefined","MemoryBoundWitnessDiviner","BoundWitnessDiviner","divineHandler","payloads","filter","assertEx","isBoundWitnessDivinerQueryPayload","pop","archivist","archivistInstance","addresses","payload_hashes","payload_schemas","limit","offset","order","sourceQuery","destination","bws","all","isBoundWitness","reverse","allAddresses","map","address","hexFromHexString","exists","length","containsAll","_a","$meta","Array","isArray","targetFilter","targetDestinationField","parsedLimit","parsedOffset","slice","configSchemas","BoundWitnessDivinerConfigSchema","defaultConfigSchema"]}
|
package/dist/node/index.js
CHANGED
|
@@ -3,10 +3,7 @@ var __getProtoOf = Object.getPrototypeOf;
|
|
|
3
3
|
var __reflectGet = Reflect.get;
|
|
4
4
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
5
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __publicField = (obj, key, value) =>
|
|
7
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
-
return value;
|
|
9
|
-
};
|
|
6
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
7
|
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
11
8
|
|
|
12
9
|
// src/MemoryBoundWitnessDiviner.ts
|
|
@@ -22,25 +19,19 @@ var _MemoryBoundWitnessDiviner = class _MemoryBoundWitnessDiviner extends BoundW
|
|
|
22
19
|
async divineHandler(payloads) {
|
|
23
20
|
var _a, _b;
|
|
24
21
|
const filter = assertEx((_a = payloads == null ? void 0 : payloads.filter(isBoundWitnessDivinerQueryPayload)) == null ? void 0 : _a.pop(), () => "Missing query payload");
|
|
25
|
-
if (!filter)
|
|
26
|
-
return [];
|
|
22
|
+
if (!filter) return [];
|
|
27
23
|
const archivist = assertEx(await this.archivistInstance(), () => "Unable to resolve archivist");
|
|
28
24
|
const { addresses, payload_hashes, payload_schemas, limit, offset, order = "desc", sourceQuery, destination, timestamp } = filter;
|
|
29
25
|
let bws = (await ((_b = archivist == null ? void 0 : archivist.all) == null ? void 0 : _b.call(archivist)) ?? []).filter(isBoundWitness);
|
|
30
|
-
if (order === "desc")
|
|
31
|
-
bws = bws.reverse();
|
|
26
|
+
if (order === "desc") bws = bws.reverse();
|
|
32
27
|
const allAddresses = addresses == null ? void 0 : addresses.map((address) => hexFromHexString(address)).filter(exists);
|
|
33
|
-
if (allAddresses == null ? void 0 : allAddresses.length)
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
bws = bws.filter((bw) => {
|
|
41
|
-
var _a2;
|
|
42
|
-
return ((_a2 = bw == null ? void 0 : bw.$meta) == null ? void 0 : _a2.sourceQuery) === sourceQuery;
|
|
43
|
-
});
|
|
28
|
+
if (allAddresses == null ? void 0 : allAddresses.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses));
|
|
29
|
+
if (payload_hashes == null ? void 0 : payload_hashes.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes));
|
|
30
|
+
if (payload_schemas == null ? void 0 : payload_schemas.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas));
|
|
31
|
+
if (sourceQuery) bws = bws.filter((bw) => {
|
|
32
|
+
var _a2;
|
|
33
|
+
return ((_a2 = bw == null ? void 0 : bw.$meta) == null ? void 0 : _a2.sourceQuery) === sourceQuery;
|
|
34
|
+
});
|
|
44
35
|
if (destination && Array.isArray(destination) && (destination == null ? void 0 : destination.length) > 0) {
|
|
45
36
|
const targetFilter = assertEx(destination, () => "Missing destination");
|
|
46
37
|
bws = bws.filter((bw) => {
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/MemoryBoundWitnessDiviner.ts"],"sourcesContent":["import { containsAll } from '@xylabs/array'\nimport { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { hexFromHexString } from '@xylabs/hex'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport {\n BoundWitnessDivinerConfigSchema,\n BoundWitnessDivinerParams,\n BoundWitnessDivinerQueryPayload,\n isBoundWitnessDivinerQueryPayload,\n} from '@xyo-network/diviner-boundwitness-model'\nimport { Schema, WithMeta } from '@xyo-network/payload-model'\n\nexport interface EqualityComparisonOperators {\n /**\n * 'Not Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value does not match the provided string.\n * Example: field != 'value'\n */\n '!=': string\n\n /**\n * 'Less Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than the provided string.\n * Example: field < 'value'\n */\n '<': string\n\n /**\n * 'Less Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than or equal to the provided string.\n * Example: field <= 'value'\n */\n '<=': string\n\n /**\n * 'Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value matches the provided string exactly.\n * Example: field = 'value'\n */\n '=': string\n\n /**\n * 'Greater Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than the provided string.\n * Example: field > 'value'\n */\n '>': string\n\n /**\n * 'Greater Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than or equal to the provided string.\n * Example: field >= 'value'\n */\n '>=': string\n}\n\ntype WithTimestamp = BoundWitness & { timestamp: number }\nconst hasTimestamp = (bw: BoundWitness): bw is WithTimestamp => bw.timestamp !== undefined\n\nexport class MemoryBoundWitnessDiviner<\n TParams extends BoundWitnessDivinerParams = BoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, BoundWitnessDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = BoundWitnessDivinerConfigSchema\n\n protected override async divineHandler(payloads?: TIn[]) {\n const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => 'Missing query payload')\n if (!filter) return []\n const archivist = assertEx(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const { addresses, payload_hashes, payload_schemas, limit, offset, order = 'desc', sourceQuery, destination, timestamp } = filter\n let bws = ((await archivist?.all?.()) ?? []).filter(isBoundWitness) as WithMeta<BoundWitness>[]\n if (order === 'desc') bws = bws.reverse()\n const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists)\n if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses))\n if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes))\n if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas))\n if (sourceQuery) bws = bws.filter((bw) => (bw?.$meta as { sourceQuery?: string })?.sourceQuery === sourceQuery)\n // If there's a destination filter of the right kind\n if (destination && Array.isArray(destination) && destination?.length > 0) {\n const targetFilter = assertEx(destination, () => 'Missing destination')\n // Find all BWs that satisfy the destination constraint\n bws = bws.filter((bw) => {\n const targetDestinationField = (bw?.$meta as { destination?: string[] })?.destination\n // If the destination field is an array and contains at least one element\n return targetDestinationField !== undefined && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ?\n // Check that the targetDestinationField contains all the elements in the targetFilter\n containsAll(targetFilter, targetDestinationField ?? [])\n // Otherwise, filter it out\n : false\n })\n }\n if (timestamp !== undefined) {\n bws =\n order === 'desc' ?\n bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp)\n : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp)\n }\n const parsedLimit = limit ?? bws.length\n const parsedOffset = offset ?? 0\n return bws.slice(parsedOffset, parsedLimit) as WithMeta<TOut>[]\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/MemoryBoundWitnessDiviner.ts"],"sourcesContent":["import { containsAll } from '@xylabs/array'\nimport { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { hexFromHexString } from '@xylabs/hex'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport {\n BoundWitnessDivinerConfigSchema,\n BoundWitnessDivinerParams,\n BoundWitnessDivinerQueryPayload,\n isBoundWitnessDivinerQueryPayload,\n} from '@xyo-network/diviner-boundwitness-model'\nimport { Schema, WithMeta } from '@xyo-network/payload-model'\n\nexport interface EqualityComparisonOperators {\n /**\n * 'Not Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value does not match the provided string.\n * Example: field != 'value'\n */\n '!=': string\n\n /**\n * 'Less Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than the provided string.\n * Example: field < 'value'\n */\n '<': string\n\n /**\n * 'Less Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically less than or equal to the provided string.\n * Example: field <= 'value'\n */\n '<=': string\n\n /**\n * 'Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value matches the provided string exactly.\n * Example: field = 'value'\n */\n '=': string\n\n /**\n * 'Greater Than' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than the provided string.\n * Example: field > 'value'\n */\n '>': string\n\n /**\n * 'Greater Than or Equal To' comparison operator.\n * Compares the field with the specified string value,\n * selecting records where the field value is lexicographically greater than or equal to the provided string.\n * Example: field >= 'value'\n */\n '>=': string\n}\n\ntype WithTimestamp = BoundWitness & { timestamp: number }\nconst hasTimestamp = (bw: BoundWitness): bw is WithTimestamp => bw.timestamp !== undefined\n\nexport class MemoryBoundWitnessDiviner<\n TParams extends BoundWitnessDivinerParams = BoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, BoundWitnessDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = BoundWitnessDivinerConfigSchema\n\n protected override async divineHandler(payloads?: TIn[]) {\n const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => 'Missing query payload')\n if (!filter) return []\n const archivist = assertEx(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const { addresses, payload_hashes, payload_schemas, limit, offset, order = 'desc', sourceQuery, destination, timestamp } = filter\n let bws = ((await archivist?.all?.()) ?? []).filter(isBoundWitness) as WithMeta<BoundWitness>[]\n if (order === 'desc') bws = bws.reverse()\n const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists)\n if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses))\n if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes))\n if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas))\n if (sourceQuery) bws = bws.filter((bw) => (bw?.$meta as { sourceQuery?: string })?.sourceQuery === sourceQuery)\n // If there's a destination filter of the right kind\n if (destination && Array.isArray(destination) && destination?.length > 0) {\n const targetFilter = assertEx(destination, () => 'Missing destination')\n // Find all BWs that satisfy the destination constraint\n bws = bws.filter((bw) => {\n const targetDestinationField = (bw?.$meta as { destination?: string[] })?.destination\n // If the destination field is an array and contains at least one element\n return targetDestinationField !== undefined && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ?\n // Check that the targetDestinationField contains all the elements in the targetFilter\n containsAll(targetFilter, targetDestinationField ?? [])\n // Otherwise, filter it out\n : false\n })\n }\n if (timestamp !== undefined) {\n bws =\n order === 'desc' ?\n bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp)\n : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp)\n }\n const parsedLimit = limit ?? bws.length\n const parsedOffset = offset ?? 0\n return bws.slice(parsedOffset, parsedLimit) as WithMeta<TOut>[]\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,mBAAmB;AAC5B,SAASC,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,wBAAwB;AACjC,SAAuBC,sBAAsB;AAC7C,SAASC,2BAA2B;AACpC,SACEC,iCAGAC,yCACK;AAsDP,IAAMC,eAAe,wBAACC,OAA0CA,GAAGC,cAAcC,QAA5D;AAEd,IAAMC,6BAAN,MAAMA,mCAIHC,oBAAAA;EAIR,MAAyBC,cAAcC,UAAkB;AA3E3D;AA4EI,UAAMC,SAASC,UAASF,0CAAUC,OAAOE,uCAAjBH,mBAAqDI,OAAO,MAAM,uBAAA;AAC1F,QAAI,CAACH,OAAQ,QAAO,CAAA;AACpB,UAAMI,YAAYH,SAAS,MAAM,KAAKI,kBAAiB,GAAI,MAAM,6BAAA;AACjE,UAAM,EAAEC,WAAWC,gBAAgBC,iBAAiBC,OAAOC,QAAQC,QAAQ,QAAQC,aAAaC,aAAanB,UAAS,IAAKM;AAC3H,QAAIc,OAAQ,QAAMV,4CAAWW,QAAXX,uCAAuB,CAAA,GAAIJ,OAAOgB,cAAAA;AACpD,QAAIL,UAAU,OAAQG,OAAMA,IAAIG,QAAO;AACvC,UAAMC,eAAeZ,uCAAWa,IAAI,CAACC,YAAYC,iBAAiBD,OAAAA,GAAUpB,OAAOsB;AACnF,QAAIJ,6CAAcK,OAAQT,OAAMA,IAAId,OAAO,CAACP,OAAO+B,YAAY/B,GAAGa,WAAWY,YAAAA,CAAAA;AAC7E,QAAIX,iDAAgBgB,OAAQT,OAAMA,IAAId,OAAO,CAACP,OAAO+B,YAAY/B,GAAGc,gBAAgBA,cAAAA,CAAAA;AACpF,QAAIC,mDAAiBe,OAAQT,OAAMA,IAAId,OAAO,CAACP,OAAO+B,YAAY/B,GAAGe,iBAAiBA,eAAAA,CAAAA;AACtF,QAAII,YAAaE,OAAMA,IAAId,OAAO,CAACP,OAAAA;AAtFvC,UAAAgC;AAsF+ChC,eAAAA,MAAAA,yBAAIiC,UAAJjC,gBAAAA,IAAwCmB,iBAAgBA;KAAAA;AAEnG,QAAIC,eAAec,MAAMC,QAAQf,WAAAA,MAAgBA,2CAAaU,UAAS,GAAG;AACxE,YAAMM,eAAe5B,SAASY,aAAa,MAAM,qBAAA;AAEjDC,YAAMA,IAAId,OAAO,CAACP,OAAAA;AA3FxB,YAAAgC;AA4FQ,cAAMK,0BAA0BrC,MAAAA,yBAAIiC,UAAJjC,gBAAAA,IAA0CoB;AAE1E,eAAOiB,2BAA2BnC,UAAagC,MAAMC,QAAQE,sBAAAA,KAA2BA,uBAAuBP,SAAS;;UAEpHC,YAAYK,cAAcC,0BAA0B,CAAA,CAAE;YAEtD;MACN,CAAA;IACF;AACA,QAAIpC,cAAcC,QAAW;AAC3BmB,YACEH,UAAU,SACRG,IAAId,OAAOR,YAAAA,EAAcQ,OAAO,CAACP,OAAOA,GAAGC,aAAaA,SAAAA,IACxDoB,IAAId,OAAOR,YAAAA,EAAcQ,OAAO,CAACP,OAAOA,GAAGC,aAAaA,SAAAA;IAC9D;AACA,UAAMqC,cAActB,SAASK,IAAIS;AACjC,UAAMS,eAAetB,UAAU;AAC/B,WAAOI,IAAImB,MAAMD,cAAcD,WAAAA;EACjC;AACF;AAxCUlC;AACR,cALWD,4BAKcsC,iBAA0B;KAAI,mEAAMA;EAAeC;;AAC5E,cANWvC,4BAMcwC,uBAA8BD;AANlD,IAAMvC,4BAAN;","names":["containsAll","assertEx","exists","hexFromHexString","isBoundWitness","BoundWitnessDiviner","BoundWitnessDivinerConfigSchema","isBoundWitnessDivinerQueryPayload","hasTimestamp","bw","timestamp","undefined","MemoryBoundWitnessDiviner","BoundWitnessDiviner","divineHandler","payloads","filter","assertEx","isBoundWitnessDivinerQueryPayload","pop","archivist","archivistInstance","addresses","payload_hashes","payload_schemas","limit","offset","order","sourceQuery","destination","bws","all","isBoundWitness","reverse","allAddresses","map","address","hexFromHexString","exists","length","containsAll","_a","$meta","Array","isArray","targetFilter","targetDestinationField","parsedLimit","parsedOffset","slice","configSchemas","BoundWitnessDivinerConfigSchema","defaultConfigSchema"]}
|
package/package.json
CHANGED
|
@@ -14,19 +14,19 @@
|
|
|
14
14
|
"@xylabs/assert": "^3.5.1",
|
|
15
15
|
"@xylabs/exists": "^3.5.1",
|
|
16
16
|
"@xylabs/hex": "^3.5.1",
|
|
17
|
-
"@xyo-network/boundwitness-model": "~2.104.
|
|
18
|
-
"@xyo-network/diviner-boundwitness-abstract": "~2.104.
|
|
19
|
-
"@xyo-network/diviner-boundwitness-model": "~2.104.
|
|
20
|
-
"@xyo-network/payload-model": "~2.104.
|
|
17
|
+
"@xyo-network/boundwitness-model": "~2.104.1",
|
|
18
|
+
"@xyo-network/diviner-boundwitness-abstract": "~2.104.1",
|
|
19
|
+
"@xyo-network/diviner-boundwitness-model": "~2.104.1",
|
|
20
|
+
"@xyo-network/payload-model": "~2.104.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@xylabs/ts-scripts-yarn3": "^3.
|
|
24
|
-
"@xylabs/tsconfig": "^3.
|
|
25
|
-
"@xyo-network/account": "~2.104.
|
|
26
|
-
"@xyo-network/archivist-memory": "~2.104.
|
|
27
|
-
"@xyo-network/boundwitness-builder": "~2.104.
|
|
28
|
-
"@xyo-network/node-memory": "~2.104.
|
|
29
|
-
"@xyo-network/payload-builder": "~2.104.
|
|
23
|
+
"@xylabs/ts-scripts-yarn3": "^3.11.2",
|
|
24
|
+
"@xylabs/tsconfig": "^3.11.2",
|
|
25
|
+
"@xyo-network/account": "~2.104.1",
|
|
26
|
+
"@xyo-network/archivist-memory": "~2.104.1",
|
|
27
|
+
"@xyo-network/boundwitness-builder": "~2.104.1",
|
|
28
|
+
"@xyo-network/node-memory": "~2.104.1",
|
|
29
|
+
"@xyo-network/payload-builder": "~2.104.1",
|
|
30
30
|
"typescript": "^5.4.5"
|
|
31
31
|
},
|
|
32
32
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
@@ -68,6 +68,6 @@
|
|
|
68
68
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
69
69
|
},
|
|
70
70
|
"sideEffects": false,
|
|
71
|
-
"version": "2.104.
|
|
71
|
+
"version": "2.104.1",
|
|
72
72
|
"type": "module"
|
|
73
73
|
}
|