@xyo-network/diviner-boundwitness-memory 2.107.3 → 2.107.5

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.
@@ -1,2 +1,77 @@
1
- "use strict";var d=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var h=(s,i)=>d(s,"name",{value:i,configurable:!0});var E=(s,i)=>{for(var r in i)d(s,r,{get:i[r],enumerable:!0})},I=(s,i,r,f)=>{if(i&&typeof i=="object"||typeof i=="function")for(let a of $(i))!q.call(s,a)&&a!==r&&d(s,a,{get:()=>i[a],enumerable:!(f=H(i,a))||f.enumerable});return s};var L=s=>I(d({},"__esModule",{value:!0}),s);var M={};E(M,{MemoryBoundWitnessDiviner:()=>u});module.exports=L(M);var n=require("@xylabs/array"),c=require("@xylabs/assert"),_=require("@xylabs/exists"),w=require("@xylabs/hex"),B=require("@xyo-network/boundwitness-model"),D=require("@xyo-network/diviner-boundwitness-abstract"),o=require("@xyo-network/diviner-boundwitness-model");var S=h(s=>s.timestamp!==void 0,"hasTimestamp"),u=class extends D.BoundWitnessDiviner{static{h(this,"MemoryBoundWitnessDiviner")}static configSchemas=[...super.configSchemas,o.BoundWitnessDivinerConfigSchema];static defaultConfigSchema=o.BoundWitnessDivinerConfigSchema;async divineHandler(i){let r=(0,c.assertEx)(i?.filter(o.isBoundWitnessDivinerQueryPayload)?.pop(),()=>"Missing query payload");if(!r)return[];let f=(0,c.assertEx)(await this.archivistInstance(),()=>"Unable to resolve archivist"),{addresses:a,payload_hashes:g,payload_schemas:y,limit:F,offset:Q,order:v="desc",sourceQuery:x,destination:l,timestamp:p}=r,e=(await f?.all?.()??[]).filter(B.isBoundWitness);v==="desc"&&(e=e.reverse());let A=a?.map(t=>(0,w.hexFromHexString)(t)).filter(_.exists);if(A?.length&&(e=e.filter(t=>(0,n.containsAll)(t.addresses,A))),g?.length&&(e=e.filter(t=>(0,n.containsAll)(t.payload_hashes,g))),y?.length&&(e=e.filter(t=>(0,n.containsAll)(t.payload_schemas,y))),x&&(e=e.filter(t=>t?.$meta?.sourceQuery===x)),l&&Array.isArray(l)&&l?.length>0){let t=(0,c.assertEx)(l,()=>"Missing destination");e=e.filter(C=>{let m=C?.$meta?.destination;return m!==void 0&&Array.isArray(m)&&m.length>0?(0,n.containsAll)(t,m??[]):!1})}p!==void 0&&(e=v==="desc"?e.filter(S).filter(t=>t.timestamp<=p):e.filter(S).filter(t=>t.timestamp>=p));let W=F??e.length,b=Q??0;return e.slice(b,W)}};
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ MemoryBoundWitnessDiviner: () => MemoryBoundWitnessDiviner
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+
28
+ // src/MemoryBoundWitnessDiviner.ts
29
+ var import_array = require("@xylabs/array");
30
+ var import_assert = require("@xylabs/assert");
31
+ var import_exists = require("@xylabs/exists");
32
+ var import_hex = require("@xylabs/hex");
33
+ var import_boundwitness_model = require("@xyo-network/boundwitness-model");
34
+ var import_diviner_boundwitness_abstract = require("@xyo-network/diviner-boundwitness-abstract");
35
+ var import_diviner_boundwitness_model = require("@xyo-network/diviner-boundwitness-model");
36
+ var hasTimestamp = /* @__PURE__ */ __name((bw) => bw.timestamp !== void 0, "hasTimestamp");
37
+ var MemoryBoundWitnessDiviner = class extends import_diviner_boundwitness_abstract.BoundWitnessDiviner {
38
+ static {
39
+ __name(this, "MemoryBoundWitnessDiviner");
40
+ }
41
+ static configSchemas = [
42
+ ...super.configSchemas,
43
+ import_diviner_boundwitness_model.BoundWitnessDivinerConfigSchema
44
+ ];
45
+ static defaultConfigSchema = import_diviner_boundwitness_model.BoundWitnessDivinerConfigSchema;
46
+ // eslint-disable-next-line complexity
47
+ async divineHandler(payloads) {
48
+ const filter = (0, import_assert.assertEx)(payloads?.filter(import_diviner_boundwitness_model.isBoundWitnessDivinerQueryPayload)?.pop(), () => "Missing query payload");
49
+ if (!filter) return [];
50
+ const archivist = (0, import_assert.assertEx)(await this.archivistInstance(), () => "Unable to resolve archivist");
51
+ const { addresses, payload_hashes, payload_schemas, limit, offset, order = "desc", sourceQuery, destination, timestamp } = filter;
52
+ let bws = (await archivist?.all?.() ?? []).filter(import_boundwitness_model.isBoundWitness);
53
+ if (order === "desc") bws = bws.reverse();
54
+ const allAddresses = addresses?.map((address) => (0, import_hex.hexFromHexString)(address)).filter(import_exists.exists);
55
+ if (allAddresses?.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.addresses, allAddresses));
56
+ if (payload_hashes?.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.payload_hashes, payload_hashes));
57
+ if (payload_schemas?.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.payload_schemas, payload_schemas));
58
+ if (sourceQuery) bws = bws.filter((bw) => bw?.$meta?.sourceQuery === sourceQuery);
59
+ if (destination && Array.isArray(destination) && destination?.length > 0) {
60
+ const targetFilter = (0, import_assert.assertEx)(destination, () => "Missing destination");
61
+ bws = bws.filter((bw) => {
62
+ const targetDestinationField = bw?.$meta?.destination;
63
+ return targetDestinationField !== void 0 && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ? (
64
+ // Check that the targetDestinationField contains all the elements in the targetFilter
65
+ (0, import_array.containsAll)(targetFilter, targetDestinationField ?? [])
66
+ ) : false;
67
+ });
68
+ }
69
+ if (timestamp !== void 0) {
70
+ bws = order === "desc" ? bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp) : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp);
71
+ }
72
+ const parsedLimit = limit ?? bws.length;
73
+ const parsedOffset = offset ?? 0;
74
+ return bws.slice(parsedOffset, parsedLimit);
75
+ }
76
+ };
2
77
  //# sourceMappingURL=index.cjs.map
@@ -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 // eslint-disable-next-line complexity\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":"4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAA4B,yBAC5BC,EAAyB,0BACzBC,EAAuB,0BACvBC,EAAiC,uBACjCC,EAA6C,2CAC7CC,EAAoC,sDACpCC,EAKO,mDAsDP,IAAMC,EAAeC,EAACC,GAA0CA,EAAGC,YAAcC,OAA5D,gBAERC,EAAN,cAIGC,qBAAAA,CAvEV,MAuEUA,CAAAA,EAAAA,kCACR,OAAyBC,cAA0B,IAAI,MAAMA,cAAeC,mCAC5E,OAAyBC,oBAA8BD,kCAGvD,MAAyBE,cAAcC,EAAkB,CACvD,IAAMC,KAASC,YAASF,GAAUC,OAAOE,mCAAAA,GAAoCC,IAAAA,EAAO,IAAM,uBAAA,EAC1F,GAAI,CAACH,EAAQ,MAAO,CAAA,EACpB,IAAMI,KAAYH,YAAS,MAAM,KAAKI,kBAAiB,EAAI,IAAM,6BAA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AE9D,IAAMuC,EAAcrB,GAASK,EAAIS,OAC3BQ,EAAerB,GAAU,EAC/B,OAAOI,EAAIkB,MAAMD,EAAcD,CAAAA,CACjC,CACF","names":["src_exports","__export","MemoryBoundWitnessDiviner","__toCommonJS","import_array","import_assert","import_exists","import_hex","import_boundwitness_model","import_diviner_boundwitness_abstract","import_diviner_boundwitness_model","hasTimestamp","__name","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"]}
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 // eslint-disable-next-line complexity\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;;EAGvD,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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aA,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"]}
@@ -1,2 +1,56 @@
1
- var F=Object.defineProperty;var f=(i,n)=>F(i,"name",{value:n,configurable:!0});import{containsAll as a}from"@xylabs/array";import{assertEx as l}from"@xylabs/assert";import{exists as Q}from"@xylabs/exists";import{hexFromHexString as W}from"@xylabs/hex";import{isBoundWitness as b}from"@xyo-network/boundwitness-model";import{BoundWitnessDiviner as C}from"@xyo-network/diviner-boundwitness-abstract";import{BoundWitnessDivinerConfigSchema as g,isBoundWitnessDivinerQueryPayload as H}from"@xyo-network/diviner-boundwitness-model";var y=f(i=>i.timestamp!==void 0,"hasTimestamp"),v=class extends C{static{f(this,"MemoryBoundWitnessDiviner")}static configSchemas=[...super.configSchemas,g];static defaultConfigSchema=g;async divineHandler(n){let m=l(n?.filter(H)?.pop(),()=>"Missing query payload");if(!m)return[];let x=l(await this.archivistInstance(),()=>"Unable to resolve archivist"),{addresses:A,payload_hashes:d,payload_schemas:c,limit:S,offset:_,order:p="desc",sourceQuery:h,destination:s,timestamp:o}=m,e=(await x?.all?.()??[]).filter(b);p==="desc"&&(e=e.reverse());let u=A?.map(t=>W(t)).filter(Q);if(u?.length&&(e=e.filter(t=>a(t.addresses,u))),d?.length&&(e=e.filter(t=>a(t.payload_hashes,d))),c?.length&&(e=e.filter(t=>a(t.payload_schemas,c))),h&&(e=e.filter(t=>t?.$meta?.sourceQuery===h)),s&&Array.isArray(s)&&s?.length>0){let t=l(s,()=>"Missing destination");e=e.filter(D=>{let r=D?.$meta?.destination;return r!==void 0&&Array.isArray(r)&&r.length>0?a(t,r??[]):!1})}o!==void 0&&(e=p==="desc"?e.filter(y).filter(t=>t.timestamp<=o):e.filter(y).filter(t=>t.timestamp>=o));let w=S??e.length,B=_??0;return e.slice(B,w)}};export{v as MemoryBoundWitnessDiviner};
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/MemoryBoundWitnessDiviner.ts
5
+ import { containsAll } from "@xylabs/array";
6
+ import { assertEx } from "@xylabs/assert";
7
+ import { exists } from "@xylabs/exists";
8
+ import { hexFromHexString } from "@xylabs/hex";
9
+ import { isBoundWitness } from "@xyo-network/boundwitness-model";
10
+ import { BoundWitnessDiviner } from "@xyo-network/diviner-boundwitness-abstract";
11
+ import { BoundWitnessDivinerConfigSchema, isBoundWitnessDivinerQueryPayload } from "@xyo-network/diviner-boundwitness-model";
12
+ var hasTimestamp = /* @__PURE__ */ __name((bw) => bw.timestamp !== void 0, "hasTimestamp");
13
+ var MemoryBoundWitnessDiviner = class extends BoundWitnessDiviner {
14
+ static {
15
+ __name(this, "MemoryBoundWitnessDiviner");
16
+ }
17
+ static configSchemas = [
18
+ ...super.configSchemas,
19
+ BoundWitnessDivinerConfigSchema
20
+ ];
21
+ static defaultConfigSchema = BoundWitnessDivinerConfigSchema;
22
+ // eslint-disable-next-line complexity
23
+ async divineHandler(payloads) {
24
+ const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => "Missing query payload");
25
+ if (!filter) return [];
26
+ const archivist = assertEx(await this.archivistInstance(), () => "Unable to resolve archivist");
27
+ const { addresses, payload_hashes, payload_schemas, limit, offset, order = "desc", sourceQuery, destination, timestamp } = filter;
28
+ let bws = (await archivist?.all?.() ?? []).filter(isBoundWitness);
29
+ if (order === "desc") bws = bws.reverse();
30
+ const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists);
31
+ if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses));
32
+ if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes));
33
+ if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas));
34
+ if (sourceQuery) bws = bws.filter((bw) => bw?.$meta?.sourceQuery === sourceQuery);
35
+ if (destination && Array.isArray(destination) && destination?.length > 0) {
36
+ const targetFilter = assertEx(destination, () => "Missing destination");
37
+ bws = bws.filter((bw) => {
38
+ const targetDestinationField = bw?.$meta?.destination;
39
+ return targetDestinationField !== void 0 && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ? (
40
+ // Check that the targetDestinationField contains all the elements in the targetFilter
41
+ containsAll(targetFilter, targetDestinationField ?? [])
42
+ ) : false;
43
+ });
44
+ }
45
+ if (timestamp !== void 0) {
46
+ bws = order === "desc" ? bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp) : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp);
47
+ }
48
+ const parsedLimit = limit ?? bws.length;
49
+ const parsedOffset = offset ?? 0;
50
+ return bws.slice(parsedOffset, parsedLimit);
51
+ }
52
+ };
53
+ export {
54
+ MemoryBoundWitnessDiviner
55
+ };
2
56
  //# sourceMappingURL=index.js.map
@@ -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 // eslint-disable-next-line complexity\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":"+EAAA,OAASA,eAAAA,MAAmB,gBAC5B,OAASC,YAAAA,MAAgB,iBACzB,OAASC,UAAAA,M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OAAoCb,cAAgBA,CAAAA,GAE/FC,GAAea,MAAMC,QAAQd,CAAAA,GAAgBA,GAAaU,OAAS,EAAG,CACxE,IAAMK,EAAe3B,EAASY,EAAa,IAAM,qBAAA,EAEjDC,EAAMA,EAAId,OAAQV,GAAAA,CAChB,IAAMuC,EAA0BvC,GAAImC,OAAsCZ,YAE1E,OAAOgB,IAA2BrC,QAAakC,MAAMC,QAAQE,CAAAA,GAA2BA,EAAuBN,OAAS,EAEpHC,EAAYI,EAAcC,GAA0B,CAAA,CAAE,EAEtD,EACN,CAAA,CACF,CACItC,IAAcC,SAChBsB,EACEH,IAAU,OACRG,EAAId,OAAOZ,CAAAA,EAAcY,OAAQV,GAAOA,EAAGC,WAAaA,CAAAA,EACxDuB,EAAId,OAAOZ,CAAAA,EAAcY,OAAQV,GAAOA,EAAGC,WAAaA,CAAAA,GAE9D,IAAMuC,EAAcrB,GAASK,EAAIS,OAC3BQ,EAAerB,GAAU,EAC/B,OAAOI,EAAIkB,MAAMD,EAAcD,CAAAA,CACjC,CACF","names":["containsAll","assertEx","exists","hexFromHexString","isBoundWitness","BoundWitnessDiviner","BoundWitnessDivinerConfigSchema","isBoundWitnessDivinerQueryPayload","hasTimestamp","__name","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"]}
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 // eslint-disable-next-line complexity\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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oCb,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"]}
@@ -1,2 +1,77 @@
1
- "use strict";var d=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var h=(s,i)=>d(s,"name",{value:i,configurable:!0});var E=(s,i)=>{for(var r in i)d(s,r,{get:i[r],enumerable:!0})},I=(s,i,r,f)=>{if(i&&typeof i=="object"||typeof i=="function")for(let a of $(i))!q.call(s,a)&&a!==r&&d(s,a,{get:()=>i[a],enumerable:!(f=H(i,a))||f.enumerable});return s};var L=s=>I(d({},"__esModule",{value:!0}),s);var M={};E(M,{MemoryBoundWitnessDiviner:()=>u});module.exports=L(M);var n=require("@xylabs/array"),c=require("@xylabs/assert"),_=require("@xylabs/exists"),w=require("@xylabs/hex"),B=require("@xyo-network/boundwitness-model"),D=require("@xyo-network/diviner-boundwitness-abstract"),o=require("@xyo-network/diviner-boundwitness-model");var S=h(s=>s.timestamp!==void 0,"hasTimestamp"),u=class extends D.BoundWitnessDiviner{static{h(this,"MemoryBoundWitnessDiviner")}static configSchemas=[...super.configSchemas,o.BoundWitnessDivinerConfigSchema];static defaultConfigSchema=o.BoundWitnessDivinerConfigSchema;async divineHandler(i){let r=(0,c.assertEx)(i?.filter(o.isBoundWitnessDivinerQueryPayload)?.pop(),()=>"Missing query payload");if(!r)return[];let f=(0,c.assertEx)(await this.archivistInstance(),()=>"Unable to resolve archivist"),{addresses:a,payload_hashes:g,payload_schemas:y,limit:F,offset:Q,order:v="desc",sourceQuery:x,destination:l,timestamp:p}=r,e=(await f?.all?.()??[]).filter(B.isBoundWitness);v==="desc"&&(e=e.reverse());let A=a?.map(t=>(0,w.hexFromHexString)(t)).filter(_.exists);if(A?.length&&(e=e.filter(t=>(0,n.containsAll)(t.addresses,A))),g?.length&&(e=e.filter(t=>(0,n.containsAll)(t.payload_hashes,g))),y?.length&&(e=e.filter(t=>(0,n.containsAll)(t.payload_schemas,y))),x&&(e=e.filter(t=>t?.$meta?.sourceQuery===x)),l&&Array.isArray(l)&&l?.length>0){let t=(0,c.assertEx)(l,()=>"Missing destination");e=e.filter(C=>{let m=C?.$meta?.destination;return m!==void 0&&Array.isArray(m)&&m.length>0?(0,n.containsAll)(t,m??[]):!1})}p!==void 0&&(e=v==="desc"?e.filter(S).filter(t=>t.timestamp<=p):e.filter(S).filter(t=>t.timestamp>=p));let W=F??e.length,b=Q??0;return e.slice(b,W)}};
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ MemoryBoundWitnessDiviner: () => MemoryBoundWitnessDiviner
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+
28
+ // src/MemoryBoundWitnessDiviner.ts
29
+ var import_array = require("@xylabs/array");
30
+ var import_assert = require("@xylabs/assert");
31
+ var import_exists = require("@xylabs/exists");
32
+ var import_hex = require("@xylabs/hex");
33
+ var import_boundwitness_model = require("@xyo-network/boundwitness-model");
34
+ var import_diviner_boundwitness_abstract = require("@xyo-network/diviner-boundwitness-abstract");
35
+ var import_diviner_boundwitness_model = require("@xyo-network/diviner-boundwitness-model");
36
+ var hasTimestamp = /* @__PURE__ */ __name((bw) => bw.timestamp !== void 0, "hasTimestamp");
37
+ var MemoryBoundWitnessDiviner = class extends import_diviner_boundwitness_abstract.BoundWitnessDiviner {
38
+ static {
39
+ __name(this, "MemoryBoundWitnessDiviner");
40
+ }
41
+ static configSchemas = [
42
+ ...super.configSchemas,
43
+ import_diviner_boundwitness_model.BoundWitnessDivinerConfigSchema
44
+ ];
45
+ static defaultConfigSchema = import_diviner_boundwitness_model.BoundWitnessDivinerConfigSchema;
46
+ // eslint-disable-next-line complexity
47
+ async divineHandler(payloads) {
48
+ const filter = (0, import_assert.assertEx)(payloads?.filter(import_diviner_boundwitness_model.isBoundWitnessDivinerQueryPayload)?.pop(), () => "Missing query payload");
49
+ if (!filter) return [];
50
+ const archivist = (0, import_assert.assertEx)(await this.archivistInstance(), () => "Unable to resolve archivist");
51
+ const { addresses, payload_hashes, payload_schemas, limit, offset, order = "desc", sourceQuery, destination, timestamp } = filter;
52
+ let bws = (await archivist?.all?.() ?? []).filter(import_boundwitness_model.isBoundWitness);
53
+ if (order === "desc") bws = bws.reverse();
54
+ const allAddresses = addresses?.map((address) => (0, import_hex.hexFromHexString)(address)).filter(import_exists.exists);
55
+ if (allAddresses?.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.addresses, allAddresses));
56
+ if (payload_hashes?.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.payload_hashes, payload_hashes));
57
+ if (payload_schemas?.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.payload_schemas, payload_schemas));
58
+ if (sourceQuery) bws = bws.filter((bw) => bw?.$meta?.sourceQuery === sourceQuery);
59
+ if (destination && Array.isArray(destination) && destination?.length > 0) {
60
+ const targetFilter = (0, import_assert.assertEx)(destination, () => "Missing destination");
61
+ bws = bws.filter((bw) => {
62
+ const targetDestinationField = bw?.$meta?.destination;
63
+ return targetDestinationField !== void 0 && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ? (
64
+ // Check that the targetDestinationField contains all the elements in the targetFilter
65
+ (0, import_array.containsAll)(targetFilter, targetDestinationField ?? [])
66
+ ) : false;
67
+ });
68
+ }
69
+ if (timestamp !== void 0) {
70
+ bws = order === "desc" ? bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp) : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp);
71
+ }
72
+ const parsedLimit = limit ?? bws.length;
73
+ const parsedOffset = offset ?? 0;
74
+ return bws.slice(parsedOffset, parsedLimit);
75
+ }
76
+ };
2
77
  //# sourceMappingURL=index.cjs.map
@@ -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 // eslint-disable-next-line complexity\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":"4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAA4B,yBAC5BC,EAAyB,0BACzBC,EAAuB,0BACvBC,EAAiC,uBACjCC,EAA6C,2CAC7CC,EAAoC,sDACpCC,EAKO,mDAsDP,IAAMC,EAAeC,EAACC,GAA0CA,EAAGC,YAAcC,OAA5D,gBAERC,EAAN,cAIGC,qBAAAA,CAvEV,MAuEUA,CAAAA,EAAAA,kCACR,OAAyBC,cAA0B,IAAI,MAAMA,cAAeC,mCAC5E,OAAyBC,oBAA8BD,kCAGvD,MAAyBE,cAAcC,EAAkB,CACvD,IAAMC,KAASC,YAASF,GAAUC,OAAOE,mCAAAA,GAAoCC,IAAAA,EAAO,IAAM,uBAAA,EAC1F,GAAI,CAACH,EAAQ,MAAO,CAAA,EACpB,IAAMI,KAAYH,YAAS,MAAM,KAAKI,kBAAiB,EAAI,IAAM,6BAAA,EAC3D,CAAEC,UAAAA,EAAWC,eAAAA,EAAgBC,gBAAAA,EAAiBC,MAAAA,EAAOC,OAAAA,EAAQC,MAAAA,EAAQ,OAAQC,YAAAA,EAAaC,YAAAA,EAAatB,UAAAA,CAAS,EAAKS,EACvHc,GAAQ,MAAMV,GAAWW,MAAAA,GAAY,CAAA,GAAIf,OAAOgB,gBAAAA,EAChDL,IAAU,SAAQG,EAAMA,EAAIG,QAAO,GACvC,IAAMC,EAAeZ,GAAWa,IAAKC,MAAYC,oBAAiBD,CAAAA,CAAAA,EAAUpB,OAAOsB,QAAAA,EAMnF,GALIJ,GAAcK,SAAQT,EAAMA,EAAId,OAAQV,MAAOkC,eAAYlC,EAAGgB,UAAWY,CAAAA,CAAAA,GACzEX,GAAgBgB,SAAQT,EAAMA,EAAId,OAAQV,MAAOkC,eAAYlC,EAAGiB,eAAgBA,CAAAA,CAAAA,GAChFC,GAAiBe,SAAQT,EAAMA,EAAId,OAAQV,MAAOkC,eAAYlC,EAAGkB,gBAAiBA,CAAAA,CAAAA,GAClFI,IAAaE,EAAMA,EAAId,OAAQV,GAAQA,GAAImC,OAAoCb,cAAgBA,CAAAA,GAE/FC,GAAea,MAAMC,QAAQd,CAAAA,GAAgBA,GAAaU,OAAS,EAAG,CACxE,IAAMK,KAAe3B,YAASY,EAAa,IAAM,qBAAA,EAEjDC,EAAMA,EAAId,OAAQV,GAAAA,CAChB,IAAMuC,EAA0BvC,GAAImC,OAAsCZ,YAE1E,OAAOgB,IAA2BrC,QAAakC,MAAMC,QAAQE,CAAAA,GAA2BA,EAAuBN,OAAS,KAEpHC,eAAYI,EAAcC,GAA0B,CAAA,CAAE,EAEtD,EACN,CAAA,CACF,CACItC,IAAcC,SAChBsB,EACEH,IAAU,OACRG,EAAId,OAAOZ,CAAAA,EAAcY,OAAQV,GAAOA,EAAGC,WAAaA,CAAAA,EACxDuB,EAAId,OAAOZ,CAAAA,EAAcY,OAAQV,GAAOA,EAAGC,WAAaA,CAAAA,GAE9D,IAAMuC,EAAcrB,GAASK,EAAIS,OAC3BQ,EAAerB,GAAU,EAC/B,OAAOI,EAAIkB,MAAMD,EAAcD,CAAAA,CACjC,CACF","names":["src_exports","__export","MemoryBoundWitnessDiviner","__toCommonJS","import_array","import_assert","import_exists","import_hex","import_boundwitness_model","import_diviner_boundwitness_abstract","import_diviner_boundwitness_model","hasTimestamp","__name","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"]}
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 // eslint-disable-next-line complexity\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;;EAGvD,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,OA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nessDiviner","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"]}
@@ -1,2 +1,56 @@
1
- var F=Object.defineProperty;var f=(i,n)=>F(i,"name",{value:n,configurable:!0});import{containsAll as a}from"@xylabs/array";import{assertEx as l}from"@xylabs/assert";import{exists as Q}from"@xylabs/exists";import{hexFromHexString as W}from"@xylabs/hex";import{isBoundWitness as b}from"@xyo-network/boundwitness-model";import{BoundWitnessDiviner as C}from"@xyo-network/diviner-boundwitness-abstract";import{BoundWitnessDivinerConfigSchema as g,isBoundWitnessDivinerQueryPayload as H}from"@xyo-network/diviner-boundwitness-model";var y=f(i=>i.timestamp!==void 0,"hasTimestamp"),v=class extends C{static{f(this,"MemoryBoundWitnessDiviner")}static configSchemas=[...super.configSchemas,g];static defaultConfigSchema=g;async divineHandler(n){let m=l(n?.filter(H)?.pop(),()=>"Missing query payload");if(!m)return[];let x=l(await this.archivistInstance(),()=>"Unable to resolve archivist"),{addresses:A,payload_hashes:d,payload_schemas:c,limit:S,offset:_,order:p="desc",sourceQuery:h,destination:s,timestamp:o}=m,e=(await x?.all?.()??[]).filter(b);p==="desc"&&(e=e.reverse());let u=A?.map(t=>W(t)).filter(Q);if(u?.length&&(e=e.filter(t=>a(t.addresses,u))),d?.length&&(e=e.filter(t=>a(t.payload_hashes,d))),c?.length&&(e=e.filter(t=>a(t.payload_schemas,c))),h&&(e=e.filter(t=>t?.$meta?.sourceQuery===h)),s&&Array.isArray(s)&&s?.length>0){let t=l(s,()=>"Missing destination");e=e.filter(D=>{let r=D?.$meta?.destination;return r!==void 0&&Array.isArray(r)&&r.length>0?a(t,r??[]):!1})}o!==void 0&&(e=p==="desc"?e.filter(y).filter(t=>t.timestamp<=o):e.filter(y).filter(t=>t.timestamp>=o));let w=S??e.length,B=_??0;return e.slice(B,w)}};export{v as MemoryBoundWitnessDiviner};
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/MemoryBoundWitnessDiviner.ts
5
+ import { containsAll } from "@xylabs/array";
6
+ import { assertEx } from "@xylabs/assert";
7
+ import { exists } from "@xylabs/exists";
8
+ import { hexFromHexString } from "@xylabs/hex";
9
+ import { isBoundWitness } from "@xyo-network/boundwitness-model";
10
+ import { BoundWitnessDiviner } from "@xyo-network/diviner-boundwitness-abstract";
11
+ import { BoundWitnessDivinerConfigSchema, isBoundWitnessDivinerQueryPayload } from "@xyo-network/diviner-boundwitness-model";
12
+ var hasTimestamp = /* @__PURE__ */ __name((bw) => bw.timestamp !== void 0, "hasTimestamp");
13
+ var MemoryBoundWitnessDiviner = class extends BoundWitnessDiviner {
14
+ static {
15
+ __name(this, "MemoryBoundWitnessDiviner");
16
+ }
17
+ static configSchemas = [
18
+ ...super.configSchemas,
19
+ BoundWitnessDivinerConfigSchema
20
+ ];
21
+ static defaultConfigSchema = BoundWitnessDivinerConfigSchema;
22
+ // eslint-disable-next-line complexity
23
+ async divineHandler(payloads) {
24
+ const filter = assertEx(payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop(), () => "Missing query payload");
25
+ if (!filter) return [];
26
+ const archivist = assertEx(await this.archivistInstance(), () => "Unable to resolve archivist");
27
+ const { addresses, payload_hashes, payload_schemas, limit, offset, order = "desc", sourceQuery, destination, timestamp } = filter;
28
+ let bws = (await archivist?.all?.() ?? []).filter(isBoundWitness);
29
+ if (order === "desc") bws = bws.reverse();
30
+ const allAddresses = addresses?.map((address) => hexFromHexString(address)).filter(exists);
31
+ if (allAddresses?.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses));
32
+ if (payload_hashes?.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes));
33
+ if (payload_schemas?.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas));
34
+ if (sourceQuery) bws = bws.filter((bw) => bw?.$meta?.sourceQuery === sourceQuery);
35
+ if (destination && Array.isArray(destination) && destination?.length > 0) {
36
+ const targetFilter = assertEx(destination, () => "Missing destination");
37
+ bws = bws.filter((bw) => {
38
+ const targetDestinationField = bw?.$meta?.destination;
39
+ return targetDestinationField !== void 0 && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ? (
40
+ // Check that the targetDestinationField contains all the elements in the targetFilter
41
+ containsAll(targetFilter, targetDestinationField ?? [])
42
+ ) : false;
43
+ });
44
+ }
45
+ if (timestamp !== void 0) {
46
+ bws = order === "desc" ? bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp) : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp);
47
+ }
48
+ const parsedLimit = limit ?? bws.length;
49
+ const parsedOffset = offset ?? 0;
50
+ return bws.slice(parsedOffset, parsedLimit);
51
+ }
52
+ };
53
+ export {
54
+ MemoryBoundWitnessDiviner
55
+ };
2
56
  //# sourceMappingURL=index.js.map
@@ -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 // eslint-disable-next-line complexity\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":"+EAAA,OAASA,eAAAA,MAAmB,gBAC5B,OAASC,YAAAA,MAAgB,iBACzB,OAASC,UAAAA,MAAc,iBACvB,OAASC,oBAAAA,MAAwB,cACjC,OAAuBC,kBAAAA,MAAsB,kCAC7C,OAASC,uBAAAA,MAA2B,6CACpC,OACEC,mCAAAA,EAGAC,qCAAAA,MACK,0CAsDP,IAAMC,EAAeC,EAACC,GAA0CA,EAAGC,YAAcC,OAA5D,gBAERC,EAAN,cAIGC,CAAAA,CAvEV,MAuEUA,CAAAA,EAAAA,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AAQE,CAAAA,GAA2BA,EAAuBN,OAAS,EAEpHC,EAAYI,EAAcC,GAA0B,CAAA,CAAE,EAEtD,EACN,CAAA,CACF,CACItC,IAAcC,SAChBsB,EACEH,IAAU,OACRG,EAAId,OAAOZ,CAAAA,EAAcY,OAAQV,GAAOA,EAAGC,WAAaA,CAAAA,EACxDuB,EAAId,OAAOZ,CAAAA,EAAcY,OAAQV,GAAOA,EAAGC,WAAaA,CAAAA,GAE9D,IAAMuC,EAAcrB,GAASK,EAAIS,OAC3BQ,EAAerB,GAAU,EAC/B,OAAOI,EAAIkB,MAAMD,EAAcD,CAAAA,CACjC,CACF","names":["containsAll","assertEx","exists","hexFromHexString","isBoundWitness","BoundWitnessDiviner","BoundWitnessDivinerConfigSchema","isBoundWitnessDivinerQueryPayload","hasTimestamp","__name","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"]}
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 // eslint-disable-next-line complexity\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,OAA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C,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"]}
@@ -1,2 +1,90 @@
1
- "use strict";var m=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var R=Reflect.get;var V=(e,t,s)=>t in e?m(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var A=(e,t)=>m(e,"name",{value:t,configurable:!0});var X=(e,t)=>{for(var s in t)m(e,s,{get:t[s],enumerable:!0})},Y=(e,t,s,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let f of J(t))!N.call(e,f)&&f!==s&&m(e,f,{get:()=>t[f],enumerable:!(n=G(t,f))||n.enumerable});return e};var Z=e=>Y(m({},"__esModule",{value:!0}),e);var F=(e,t,s)=>V(e,typeof t!="symbol"?t+"":t,s);var E=(e,t,s)=>R(K(e),s,t);var v={};X(v,{MemoryBoundWitnessDiviner:()=>Q});module.exports=Z(v);var c=require("@xylabs/array"),x=require("@xylabs/assert"),L=require("@xylabs/exists"),O=require("@xylabs/hex"),P=require("@xyo-network/boundwitness-model"),T=require("@xyo-network/diviner-boundwitness-abstract"),p=require("@xyo-network/diviner-boundwitness-model");var I=A(e=>e.timestamp!==void 0,"hasTimestamp"),a=class a extends T.BoundWitnessDiviner{async divineHandler(t){var $,q;let s=(0,x.assertEx)(($=t==null?void 0:t.filter(p.isBoundWitnessDivinerQueryPayload))==null?void 0:$.pop(),()=>"Missing query payload");if(!s)return[];let n=(0,x.assertEx)(await this.archivistInstance(),()=>"Unable to resolve archivist"),{addresses:f,payload_hashes:g,payload_schemas:d,limit:U,offset:j,order:C="desc",sourceQuery:H,destination:o,timestamp:S}=s,i=(await((q=n==null?void 0:n.all)==null?void 0:q.call(n))??[]).filter(P.isBoundWitness);C==="desc"&&(i=i.reverse());let h=f==null?void 0:f.map(r=>(0,O.hexFromHexString)(r)).filter(L.exists);if(h!=null&&h.length&&(i=i.filter(r=>(0,c.containsAll)(r.addresses,h))),g!=null&&g.length&&(i=i.filter(r=>(0,c.containsAll)(r.payload_hashes,g))),d!=null&&d.length&&(i=i.filter(r=>(0,c.containsAll)(r.payload_schemas,d))),H&&(i=i.filter(r=>{var l;return((l=r==null?void 0:r.$meta)==null?void 0:l.sourceQuery)===H})),o&&Array.isArray(o)&&(o==null?void 0:o.length)>0){let r=(0,x.assertEx)(o,()=>"Missing destination");i=i.filter(l=>{var y;let u=(y=l==null?void 0:l.$meta)==null?void 0:y.destination;return u!==void 0&&Array.isArray(u)&&u.length>0?(0,c.containsAll)(r,u??[]):!1})}S!==void 0&&(i=C==="desc"?i.filter(I).filter(r=>r.timestamp<=S):i.filter(I).filter(r=>r.timestamp>=S));let k=U??i.length,z=j??0;return i.slice(z,k)}};A(a,"MemoryBoundWitnessDiviner"),F(a,"configSchemas",[...E(a,a,"configSchemas"),p.BoundWitnessDivinerConfigSchema]),F(a,"defaultConfigSchema",p.BoundWitnessDivinerConfigSchema);var Q=a;0&&(module.exports={MemoryBoundWitnessDiviner});
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __reflectGet = Reflect.get;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
24
+ var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
25
+
26
+ // src/index.ts
27
+ var src_exports = {};
28
+ __export(src_exports, {
29
+ MemoryBoundWitnessDiviner: () => MemoryBoundWitnessDiviner
30
+ });
31
+ module.exports = __toCommonJS(src_exports);
32
+
33
+ // src/MemoryBoundWitnessDiviner.ts
34
+ var import_array = require("@xylabs/array");
35
+ var import_assert = require("@xylabs/assert");
36
+ var import_exists = require("@xylabs/exists");
37
+ var import_hex = require("@xylabs/hex");
38
+ var import_boundwitness_model = require("@xyo-network/boundwitness-model");
39
+ var import_diviner_boundwitness_abstract = require("@xyo-network/diviner-boundwitness-abstract");
40
+ var import_diviner_boundwitness_model = require("@xyo-network/diviner-boundwitness-model");
41
+ var hasTimestamp = /* @__PURE__ */ __name((bw) => bw.timestamp !== void 0, "hasTimestamp");
42
+ var _MemoryBoundWitnessDiviner = class _MemoryBoundWitnessDiviner extends import_diviner_boundwitness_abstract.BoundWitnessDiviner {
43
+ // eslint-disable-next-line complexity
44
+ async divineHandler(payloads) {
45
+ var _a, _b;
46
+ 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");
47
+ if (!filter) return [];
48
+ const archivist = (0, import_assert.assertEx)(await this.archivistInstance(), () => "Unable to resolve archivist");
49
+ const { addresses, payload_hashes, payload_schemas, limit, offset, order = "desc", sourceQuery, destination, timestamp } = filter;
50
+ let bws = (await ((_b = archivist == null ? void 0 : archivist.all) == null ? void 0 : _b.call(archivist)) ?? []).filter(import_boundwitness_model.isBoundWitness);
51
+ if (order === "desc") bws = bws.reverse();
52
+ const allAddresses = addresses == null ? void 0 : addresses.map((address) => (0, import_hex.hexFromHexString)(address)).filter(import_exists.exists);
53
+ if (allAddresses == null ? void 0 : allAddresses.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.addresses, allAddresses));
54
+ if (payload_hashes == null ? void 0 : payload_hashes.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.payload_hashes, payload_hashes));
55
+ if (payload_schemas == null ? void 0 : payload_schemas.length) bws = bws.filter((bw) => (0, import_array.containsAll)(bw.payload_schemas, payload_schemas));
56
+ if (sourceQuery) bws = bws.filter((bw) => {
57
+ var _a2;
58
+ return ((_a2 = bw == null ? void 0 : bw.$meta) == null ? void 0 : _a2.sourceQuery) === sourceQuery;
59
+ });
60
+ if (destination && Array.isArray(destination) && (destination == null ? void 0 : destination.length) > 0) {
61
+ const targetFilter = (0, import_assert.assertEx)(destination, () => "Missing destination");
62
+ bws = bws.filter((bw) => {
63
+ var _a2;
64
+ const targetDestinationField = (_a2 = bw == null ? void 0 : bw.$meta) == null ? void 0 : _a2.destination;
65
+ return targetDestinationField !== void 0 && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ? (
66
+ // Check that the targetDestinationField contains all the elements in the targetFilter
67
+ (0, import_array.containsAll)(targetFilter, targetDestinationField ?? [])
68
+ ) : false;
69
+ });
70
+ }
71
+ if (timestamp !== void 0) {
72
+ bws = order === "desc" ? bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp) : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp);
73
+ }
74
+ const parsedLimit = limit ?? bws.length;
75
+ const parsedOffset = offset ?? 0;
76
+ return bws.slice(parsedOffset, parsedLimit);
77
+ }
78
+ };
79
+ __name(_MemoryBoundWitnessDiviner, "MemoryBoundWitnessDiviner");
80
+ __publicField(_MemoryBoundWitnessDiviner, "configSchemas", [
81
+ ...__superGet(_MemoryBoundWitnessDiviner, _MemoryBoundWitnessDiviner, "configSchemas"),
82
+ import_diviner_boundwitness_model.BoundWitnessDivinerConfigSchema
83
+ ]);
84
+ __publicField(_MemoryBoundWitnessDiviner, "defaultConfigSchema", import_diviner_boundwitness_model.BoundWitnessDivinerConfigSchema);
85
+ var MemoryBoundWitnessDiviner = _MemoryBoundWitnessDiviner;
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ MemoryBoundWitnessDiviner
89
+ });
2
90
  //# sourceMappingURL=index.cjs.map
@@ -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 // eslint-disable-next-line complexity\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(pars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,GAAAA,MAAAA,EAAiBe,SAAQT,EAAMA,EAAId,OAAQT,MAAOiC,eAAYjC,EAAGiB,gBAAiBA,CAAAA,CAAAA,GAClFI,IAAaE,EAAMA,EAAId,OAAQT,GAAAA,CAvFvC,IAAAO,EAuF+CP,QAAAA,EAAAA,GAAAA,YAAAA,EAAIkC,QAAJlC,YAAAA,EAAwCqB,eAAgBA,EAAAA,GAE/FC,GAAea,MAAMC,QAAQd,CAAAA,IAAgBA,GAAAA,YAAAA,EAAaU,QAAS,EAAG,CACxE,IAAMK,KAAe3B,YAASY,EAAa,IAAM,qBAAA,EAEjDC,EAAMA,EAAId,OAAQT,GAAAA,CA5FxB,IAAAO,EA6FQ,IAAM+B,GAA0BtC,EAAAA,GAAAA,YAAAA,EAAIkC,QAAJlC,YAAAA,EAA0CsB,YAE1E,OAAOgB,IAA2BpC,QAAaiC,MAAMC,QAAQE,CAAAA,GAA2BA,EAAuBN,OAAS,KAEpHC,eAAYI,EAAcC,GAA0B,CAAA,CAAE,EAEtD,EACN,CAAA,CACF,CACIrC,IAAcC,SAChBqB,EACEH,IAAU,OACRG,EAAId,OAAOX,CAAAA,EAAcW,OAAQT,GAAOA,EAAGC,WAAaA,CAAAA,EACxDsB,EAAId,OAAOX,CAAAA,EAAcW,OAAQT,GAAOA,EAAGC,WAAaA,CAAAA,GAE9D,IAAMsC,EAAcrB,GAASK,EAAIS,OAC3BQ,EAAerB,GAAU,EAC/B,OAAOI,EAAIkB,MAAMD,EAAcD,CAAAA,CACjC,CACF,EAzCUnC,EAAAA,EAAAA,6BACRsC,EALWvC,EAKcwC,gBAA0B,IAAIC,EAAAC,IAAMF,iBAAeG,oCAC5EJ,EANWvC,EAMc4C,sBAA8BD,mCANlD,IAAM3C,EAAN0C","names":["src_exports","__export","MemoryBoundWitnessDiviner","__toCommonJS","import_array","import_assert","import_exists","import_hex","import_boundwitness_model","import_diviner_boundwitness_abstract","import_diviner_boundwitness_model","hasTimestamp","__name","bw","timestamp","undefined","MemoryBoundWitnessDiviner","BoundWitnessDiviner","divineHandler","payloads","_a","_b","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","__publicField","configSchemas","__superGet","_MemoryBoundWitnessDiviner","BoundWitnessDivinerConfigSchema","defaultConfigSchema"]}
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 // eslint-disable-next-line complexity\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;;EAKR,MAAyBC,cAAcC,UAAkB;AA5E3D;AA6EI,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,UAAM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cD,WAAAA;EACjC;AACF;AAzCUlC;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"]}
@@ -1,2 +1,65 @@
1
- var $=Object.defineProperty;var U=Object.getPrototypeOf;var j=Reflect.get;var k=(r,i,s)=>i in r?$(r,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[i]=s;var u=(r,i)=>$(r,"name",{value:i,configurable:!0});var x=(r,i,s)=>k(r,typeof i!="symbol"?i+"":i,s);var q=(r,i,s)=>j(U(r),s,i);import{containsAll as g}from"@xylabs/array";import{assertEx as S}from"@xylabs/assert";import{exists as z}from"@xylabs/exists";import{hexFromHexString as G}from"@xylabs/hex";import{isBoundWitness as J}from"@xyo-network/boundwitness-model";import{BoundWitnessDiviner as K}from"@xyo-network/diviner-boundwitness-abstract";import{BoundWitnessDivinerConfigSchema as y,isBoundWitnessDivinerQueryPayload as N}from"@xyo-network/diviner-boundwitness-model";var E=u(r=>r.timestamp!==void 0,"hasTimestamp"),f=class f extends K{async divineHandler(i){var Q,C;let s=S((Q=i==null?void 0:i.filter(N))==null?void 0:Q.pop(),()=>"Missing query payload");if(!s)return[];let o=S(await this.archivistInstance(),()=>"Unable to resolve archivist"),{addresses:d,payload_hashes:l,payload_schemas:m,limit:L,offset:O,order:A="desc",sourceQuery:F,destination:n,timestamp:h}=s,t=(await((C=o==null?void 0:o.all)==null?void 0:C.call(o))??[]).filter(J);A==="desc"&&(t=t.reverse());let c=d==null?void 0:d.map(e=>G(e)).filter(z);if(c!=null&&c.length&&(t=t.filter(e=>g(e.addresses,c))),l!=null&&l.length&&(t=t.filter(e=>g(e.payload_hashes,l))),m!=null&&m.length&&(t=t.filter(e=>g(e.payload_schemas,m))),F&&(t=t.filter(e=>{var a;return((a=e==null?void 0:e.$meta)==null?void 0:a.sourceQuery)===F})),n&&Array.isArray(n)&&(n==null?void 0:n.length)>0){let e=S(n,()=>"Missing destination");t=t.filter(a=>{var H;let p=(H=a==null?void 0:a.$meta)==null?void 0:H.destination;return p!==void 0&&Array.isArray(p)&&p.length>0?g(e,p??[]):!1})}h!==void 0&&(t=A==="desc"?t.filter(E).filter(e=>e.timestamp<=h):t.filter(E).filter(e=>e.timestamp>=h));let P=L??t.length,T=O??0;return t.slice(T,P)}};u(f,"MemoryBoundWitnessDiviner"),x(f,"configSchemas",[...q(f,f,"configSchemas"),y]),x(f,"defaultConfigSchema",y);var I=f;export{I as MemoryBoundWitnessDiviner};
1
+ var __defProp = Object.defineProperty;
2
+ var __getProtoOf = Object.getPrototypeOf;
3
+ var __reflectGet = Reflect.get;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+ var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
8
+
9
+ // src/MemoryBoundWitnessDiviner.ts
10
+ import { containsAll } from "@xylabs/array";
11
+ import { assertEx } from "@xylabs/assert";
12
+ import { exists } from "@xylabs/exists";
13
+ import { hexFromHexString } from "@xylabs/hex";
14
+ import { isBoundWitness } from "@xyo-network/boundwitness-model";
15
+ import { BoundWitnessDiviner } from "@xyo-network/diviner-boundwitness-abstract";
16
+ import { BoundWitnessDivinerConfigSchema, isBoundWitnessDivinerQueryPayload } from "@xyo-network/diviner-boundwitness-model";
17
+ var hasTimestamp = /* @__PURE__ */ __name((bw) => bw.timestamp !== void 0, "hasTimestamp");
18
+ var _MemoryBoundWitnessDiviner = class _MemoryBoundWitnessDiviner extends BoundWitnessDiviner {
19
+ // eslint-disable-next-line complexity
20
+ async divineHandler(payloads) {
21
+ var _a, _b;
22
+ const filter = assertEx((_a = payloads == null ? void 0 : payloads.filter(isBoundWitnessDivinerQueryPayload)) == null ? void 0 : _a.pop(), () => "Missing query payload");
23
+ if (!filter) return [];
24
+ const archivist = assertEx(await this.archivistInstance(), () => "Unable to resolve archivist");
25
+ const { addresses, payload_hashes, payload_schemas, limit, offset, order = "desc", sourceQuery, destination, timestamp } = filter;
26
+ let bws = (await ((_b = archivist == null ? void 0 : archivist.all) == null ? void 0 : _b.call(archivist)) ?? []).filter(isBoundWitness);
27
+ if (order === "desc") bws = bws.reverse();
28
+ const allAddresses = addresses == null ? void 0 : addresses.map((address) => hexFromHexString(address)).filter(exists);
29
+ if (allAddresses == null ? void 0 : allAddresses.length) bws = bws.filter((bw) => containsAll(bw.addresses, allAddresses));
30
+ if (payload_hashes == null ? void 0 : payload_hashes.length) bws = bws.filter((bw) => containsAll(bw.payload_hashes, payload_hashes));
31
+ if (payload_schemas == null ? void 0 : payload_schemas.length) bws = bws.filter((bw) => containsAll(bw.payload_schemas, payload_schemas));
32
+ if (sourceQuery) bws = bws.filter((bw) => {
33
+ var _a2;
34
+ return ((_a2 = bw == null ? void 0 : bw.$meta) == null ? void 0 : _a2.sourceQuery) === sourceQuery;
35
+ });
36
+ if (destination && Array.isArray(destination) && (destination == null ? void 0 : destination.length) > 0) {
37
+ const targetFilter = assertEx(destination, () => "Missing destination");
38
+ bws = bws.filter((bw) => {
39
+ var _a2;
40
+ const targetDestinationField = (_a2 = bw == null ? void 0 : bw.$meta) == null ? void 0 : _a2.destination;
41
+ return targetDestinationField !== void 0 && Array.isArray(targetDestinationField) && targetDestinationField.length > 0 ? (
42
+ // Check that the targetDestinationField contains all the elements in the targetFilter
43
+ containsAll(targetFilter, targetDestinationField ?? [])
44
+ ) : false;
45
+ });
46
+ }
47
+ if (timestamp !== void 0) {
48
+ bws = order === "desc" ? bws.filter(hasTimestamp).filter((bw) => bw.timestamp <= timestamp) : bws.filter(hasTimestamp).filter((bw) => bw.timestamp >= timestamp);
49
+ }
50
+ const parsedLimit = limit ?? bws.length;
51
+ const parsedOffset = offset ?? 0;
52
+ return bws.slice(parsedOffset, parsedLimit);
53
+ }
54
+ };
55
+ __name(_MemoryBoundWitnessDiviner, "MemoryBoundWitnessDiviner");
56
+ __publicField(_MemoryBoundWitnessDiviner, "configSchemas", [
57
+ ...__superGet(_MemoryBoundWitnessDiviner, _MemoryBoundWitnessDiviner, "configSchemas"),
58
+ BoundWitnessDivinerConfigSchema
59
+ ]);
60
+ __publicField(_MemoryBoundWitnessDiviner, "defaultConfigSchema", BoundWitnessDivinerConfigSchema);
61
+ var MemoryBoundWitnessDiviner = _MemoryBoundWitnessDiviner;
62
+ export {
63
+ MemoryBoundWitnessDiviner
64
+ };
2
65
  //# sourceMappingURL=index.js.map
@@ -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 // eslint-disable-next-line complexity\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":"gSAAA,OAASA,eAAAA,MAAmB,gBAC5B,OAASC,YAAAA,MAAgB,iBACzB,OAASC,UAAAA,MAAc,iBACvB,OAASC,oBAAAA,MAAwB,cACjC,OAAuBC,kBAAAA,MAAsB,kCAC7C,OAASC,uBAAAA,MAA2B,6CACpC,OACEC,mCAAAA,EAGAC,qCAAAA,MACK,0CAsDP,IAAMC,EAAeC,EAACC,GAA0CA,EAAGC,YAAcC,OAA5D,gBAERC,EAAN,MAAMA,UAIHC,CAAAA,CAKR,MAAyBC,cAAcC,EAAkB,CA5E3D,IAAAC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C,EAAMA,EAAId,OAAQT,GAAAA,CA5FxB,IAAAO,EA6FQ,IAAM+B,GAA0BtC,EAAAA,GAAAA,YAAAA,EAAIkC,QAAJlC,YAAAA,EAA0CsB,YAE1E,OAAOgB,IAA2BpC,QAAaiC,MAAMC,QAAQE,CAAAA,GAA2BA,EAAuBN,OAAS,EAEpHC,EAAYI,EAAcC,GAA0B,CAAA,CAAE,EAEtD,EACN,CAAA,CACF,CACIrC,IAAcC,SAChBqB,EACEH,IAAU,OACRG,EAAId,OAAOX,CAAAA,EAAcW,OAAQT,GAAOA,EAAGC,WAAaA,CAAAA,EACxDsB,EAAId,OAAOX,CAAAA,EAAcW,OAAQT,GAAOA,EAAGC,WAAaA,CAAAA,GAE9D,IAAMsC,EAAcrB,GAASK,EAAIS,OAC3BQ,EAAerB,GAAU,EAC/B,OAAOI,EAAIkB,MAAMD,EAAcD,CAAAA,CACjC,CACF,EAzCUnC,EAAAA,EAAAA,6BACRsC,EALWvC,EAKcwC,gBAA0B,IAAIC,EAAAC,IAAMF,iBAAeG,IAC5EJ,EANWvC,EAMc4C,sBAA8BD,GANlD,IAAM3C,EAAN0C","names":["containsAll","assertEx","exists","hexFromHexString","isBoundWitness","BoundWitnessDiviner","BoundWitnessDivinerConfigSchema","isBoundWitnessDivinerQueryPayload","hasTimestamp","__name","bw","timestamp","undefined","MemoryBoundWitnessDiviner","BoundWitnessDiviner","divineHandler","payloads","_a","_b","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","__publicField","configSchemas","__superGet","_MemoryBoundWitnessDiviner","BoundWitnessDivinerConfigSchema","defaultConfigSchema"]}
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 // eslint-disable-next-line complexity\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 pars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ACP,OAAAA;AAvFvC,UAAAgC;AAuF+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;AA5FxB,YAAAgC;AA6FQ,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;AAzCUlC;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.107.3",
18
- "@xyo-network/diviner-boundwitness-abstract": "~2.107.3",
19
- "@xyo-network/diviner-boundwitness-model": "~2.107.3",
20
- "@xyo-network/payload-model": "~2.107.3"
17
+ "@xyo-network/boundwitness-model": "~2.107.5",
18
+ "@xyo-network/diviner-boundwitness-abstract": "~2.107.5",
19
+ "@xyo-network/diviner-boundwitness-model": "~2.107.5",
20
+ "@xyo-network/payload-model": "~2.107.5"
21
21
  },
22
22
  "devDependencies": {
23
- "@xylabs/ts-scripts-yarn3": "^3.11.9",
24
- "@xylabs/tsconfig": "^3.11.9",
25
- "@xyo-network/account": "~2.107.3",
26
- "@xyo-network/archivist-memory": "~2.107.3",
27
- "@xyo-network/boundwitness-builder": "~2.107.3",
28
- "@xyo-network/node-memory": "~2.107.3",
29
- "@xyo-network/payload-builder": "~2.107.3",
23
+ "@xylabs/ts-scripts-yarn3": "^3.11.10",
24
+ "@xylabs/tsconfig": "^3.11.10",
25
+ "@xyo-network/account": "~2.107.5",
26
+ "@xyo-network/archivist-memory": "~2.107.5",
27
+ "@xyo-network/boundwitness-builder": "~2.107.5",
28
+ "@xyo-network/node-memory": "~2.107.5",
29
+ "@xyo-network/payload-builder": "~2.107.5",
30
30
  "typescript": "^5.5.2"
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.107.3",
71
+ "version": "2.107.5",
72
72
  "type": "module"
73
73
  }