{
  "version": 3,
  "sources": ["../../src/modules/diviner-boundwitness/applyBoundWitnessDivinerQueryPayload.ts", "../../src/modules/diviner-boundwitness/MemoryBoundWitnessDiviner.ts", "../../src/modules/diviner-boundwitness/BoundWitnessDiviner.ts", "../../src/modules/diviner-boundwitness/Config.ts", "../../src/modules/diviner-boundwitness/Schema.ts", "../../src/modules/diviner-boundwitness/Query.ts"],
  "sourcesContent": ["import {\n  assertEx, containsAll,\n  exists, hexFromHexString,\n} from '@ariestools/sdk'\nimport type {\n  BoundWitness, Payload, WithStorageMeta,\n} from '@xyo-network/sdk-protocol'\nimport {\n  isBoundWitness, PayloadBuilder, SequenceConstants,\n} from '@xyo-network/sdk-protocol'\n\nimport type { BoundWitnessDivinerQueryPayload } from './Query.ts'\n\n// eslint-disable-next-line complexity\nexport const applyBoundWitnessDivinerQueryPayload = (filter?: BoundWitnessDivinerQueryPayload, payloads: WithStorageMeta<Payload>[] = []): BoundWitness[] => {\n  if (!filter) return []\n  const {\n    addresses, cursor, destination, limit, order = 'desc', payload_hashes, payload_schemas, sourceQuery,\n  } = filter\n\n  const sortedPayloads = PayloadBuilder.sortByStorageMeta(payloads, order === 'desc' ? -1 : 1)\n  const parsedCursor = cursor ?? ((order === 'desc') ? SequenceConstants.maxLocalSequence : SequenceConstants.minLocalSequence)\n  const parsedOffset = (order === 'desc')\n    ? sortedPayloads.findIndex(bw => bw._sequence < parsedCursor)\n    : sortedPayloads.findIndex(bw => bw._sequence > parsedCursor)\n  if (parsedOffset === -1) return []\n  const payloadSubset = sortedPayloads.slice(parsedOffset)\n\n  let bws = payloadSubset.filter(isBoundWitness)\n  const allAddresses = addresses?.map(address => hexFromHexString(address)).filter(exists)\n  if (allAddresses?.length) bws = bws.filter(bw => containsAll<string>(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?.$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 as { $destination?: string | 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  const parsedLimit = limit ?? bws.length\n  return bws.slice(0, parsedLimit)\n}\n", "import { assertEx } from '@ariestools/sdk'\nimport { type BoundWitness, isBoundWitness } from '@xyo-network/sdk-protocol'\nimport { isStorageMeta } from '@xyo-network/sdk-protocol'\n\nimport { applyBoundWitnessDivinerQueryPayload } from './applyBoundWitnessDivinerQueryPayload.ts'\nimport { BoundWitnessDiviner } from './BoundWitnessDiviner.ts'\nimport type { BoundWitnessDivinerParams } from './Params.ts'\nimport { type BoundWitnessDivinerQueryPayload, isBoundWitnessDivinerQueryPayload } from './Query.ts'\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\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  protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\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 bws = ((await archivist?.next({ limit: 10_000 })) ?? []).filter(x => isBoundWitness(x) && isStorageMeta(x))\n    return applyBoundWitnessDivinerQueryPayload(filter, bws) as TOut[]\n  }\n}\n", "import type { BoundWitness, Schema } from '@xyo-network/sdk-protocol'\n\nimport { AbstractDiviner } from '#diviner-abstract'\nimport type { DivinerInstance, DivinerModuleEventData } from '#diviner-model'\n\nimport { BoundWitnessDivinerConfigSchema } from './Config.ts'\nimport type { BoundWitnessDivinerParams } from './Params.ts'\nimport type { BoundWitnessDivinerQueryPayload } from './Query.ts'\n\nexport abstract class BoundWitnessDiviner<\n  TParams extends BoundWitnessDivinerParams = BoundWitnessDivinerParams,\n  TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n  TOut extends BoundWitness = BoundWitness,\n  TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n    DivinerInstance<TParams, TIn, TOut>,\n    TIn,\n    TOut\n  >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n  static override readonly configSchemas: Schema[] = [...super.configSchemas, BoundWitnessDivinerConfigSchema]\n  static override readonly defaultConfigSchema: Schema = BoundWitnessDivinerConfigSchema\n}\n", "import {\n  zodAsFactory, zodIsFactory, zodToFactory,\n} from '@ariestools/sdk'\nimport { asSchema, type Payload } from '@xyo-network/sdk-protocol'\nimport * as z from 'zod/mini'\n\nimport type { DivinerConfig } from '#diviner-model'\nimport { DivinerConfigZod } from '#diviner-model'\n\nimport { BoundWitnessDivinerSchema } from './Schema.ts'\n\nexport const BoundWitnessDivinerConfigSchema: string & {\n  readonly __schema: true\n} = asSchema(`${BoundWitnessDivinerSchema}.config`, true)\nexport type BoundWitnessDivinerConfigSchema = typeof BoundWitnessDivinerConfigSchema\n\nexport const BoundWitnessDivinerConfigZod: z.ZodMiniObject<\n  Omit<(typeof DivinerConfigZod)['shape'], 'schema'> & {\n    schema: z.ZodMiniLiteral<BoundWitnessDivinerConfigSchema>\n  },\n  z.core.$strip\n> = z.extend(DivinerConfigZod, { schema: z.literal(BoundWitnessDivinerConfigSchema) })\n\nexport type BoundWitnessDivinerConfigBase = z.infer<typeof BoundWitnessDivinerConfigZod>\n\nexport const isBoundWitnessDivinerConfig: ReturnType<typeof zodIsFactory<BoundWitnessDivinerConfigBase>> = zodIsFactory(BoundWitnessDivinerConfigZod)\nexport const asBoundWitnessDivinerConfig: ReturnType<typeof zodAsFactory<BoundWitnessDivinerConfigBase>> = zodAsFactory(BoundWitnessDivinerConfigZod, 'asBoundWitnessDivinerConfig')\nexport const toBoundWitnessDivinerConfig: ReturnType<typeof zodToFactory<BoundWitnessDivinerConfigBase>> = zodToFactory(BoundWitnessDivinerConfigZod, 'toBoundWitnessDivinerConfig')\n\nexport type BoundWitnessDivinerConfig<T extends Payload = Payload> = DivinerConfig<\n  T & {\n    schema: BoundWitnessDivinerConfigSchema\n  }\n>\n", "import { asSchema } from '@xyo-network/sdk-protocol'\n\nexport const BoundWitnessDivinerSchema: 'network.xyo.diviner.boundwitness' & {\n  readonly __schema: true\n} = asSchema('network.xyo.diviner.boundwitness', true)\nexport type BoundWitnessDivinerSchema = typeof BoundWitnessDivinerSchema\n", "import {\n  zodAsFactory, zodIsFactory, zodToFactory,\n} from '@ariestools/sdk'\nimport {\n  asSchema, PayloadZodOfSchema, QueryFieldsZod,\n} from '@xyo-network/sdk-protocol'\nimport * as z from 'zod/mini'\n\nimport type { BoundWitnessDivinerPredicate } from './Predicate.ts'\nimport { BoundWitnessDivinerSchema } from './Schema.ts'\n\nexport const BoundWitnessDivinerQuerySchema: string & {\n  readonly __schema: true\n} = asSchema(`${BoundWitnessDivinerSchema}.query`, true)\nexport type BoundWitnessDivinerQuerySchema = typeof BoundWitnessDivinerQuerySchema\n\nexport const BoundWitnessDivinerQueryPayloadZod: z.ZodMiniIntersection<\n  z.ZodMiniObject<\n    & { schema: z.ZodMiniLiteral<BoundWitnessDivinerQuerySchema> }\n    & (typeof QueryFieldsZod)['shape'],\n    z.core.$strip\n  >,\n  z.ZodMiniCustom<BoundWitnessDivinerPredicate, BoundWitnessDivinerPredicate>\n> = z.intersection(\n  z.extend(PayloadZodOfSchema(BoundWitnessDivinerQuerySchema), { ...QueryFieldsZod.shape }),\n  z.custom<BoundWitnessDivinerPredicate>(),\n)\n\nexport type BoundWitnessDivinerQueryPayload = z.infer<typeof BoundWitnessDivinerQueryPayloadZod>\n\nexport const isBoundWitnessDivinerQueryPayload: ReturnType<typeof zodIsFactory<BoundWitnessDivinerQueryPayload>> = zodIsFactory(BoundWitnessDivinerQueryPayloadZod)\nexport const asBoundWitnessDivinerQueryPayload: ReturnType<typeof zodAsFactory<BoundWitnessDivinerQueryPayload>> = zodAsFactory(BoundWitnessDivinerQueryPayloadZod, 'asBoundWitnessDivinerQueryPayload')\nexport const toBoundWitnessDivinerQueryPayload: ReturnType<typeof zodToFactory<BoundWitnessDivinerQueryPayload>> = zodToFactory(BoundWitnessDivinerQueryPayloadZod, 'toBoundWitnessDivinerQueryPayload')\n"],
  "mappings": ";AA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AA,EACtF,UAAqC;AACzC;AAIO,IAAM,oCAAsGC,cAAa,kCAAkC;AAC3J,IAAM,oCAAsGC,cAAa,oCAAoC,mCAAmC;AAChM,IAAM,oCAAsGC,cAAa,oCAAoC,mCAAmC;;;AJ2BhM,IAAM,4BAAN,cAIG,oBAAwC;AAAA,EAChD,MAAyB,cAAc,UAAmC;AACxE,UAAM,SAASC,UAAS,UAAU,OAAO,iCAAiC,GAAG,IAAI,GAAG,MAAM,uBAAuB;AACjH,QAAI,CAAC,OAAQ,QAAO,CAAC;AACrB,UAAM,YAAYA,UAAS,MAAM,KAAK,kBAAkB,GAAG,MAAM,6BAA6B;AAC9F,UAAM,OAAQ,MAAM,WAAW,KAAK,EAAE,OAAO,IAAO,CAAC,KAAM,CAAC,GAAG,OAAO,OAAKC,gBAAe,CAAC,KAAK,cAAc,CAAC,CAAC;AAChH,WAAO,qCAAqC,QAAQ,GAAG;AAAA,EACzD;AACF;",
  "names": ["assertEx", "isBoundWitness", "asSchema", "asSchema", "zodAsFactory", "zodIsFactory", "zodToFactory", "asSchema", "z", "asSchema", "zodIsFactory", "zodAsFactory", "zodToFactory", "assertEx", "isBoundWitness"]
}
