{"version":3,"file":"vector_store_constructor.mjs","names":[],"sources":["../../../src/batteries/vector/vector_store_constructor.ts"],"sourcesContent":["/**\n * @module @nhtio/adk/batteries/vector/vector_store_constructor\n */\n\nimport { validator } from '@nhtio/validation'\nimport type { BaseVectorStore } from './contract'\nimport type { BaseVectorStoreOptions } from './types'\n\n/**\n * Constructor signature for any {@link BaseVectorStore} adapter (the class itself or a subclass).\n *\n * @remarks\n * Re-declared at the contract level so the factory's `client` resolver can recognise a valid\n * adapter constructor without value-importing {@link BaseVectorStore} into modules where that\n * would be awkward, mirroring `SpooledArtifactConstructorLike`.\n */\nexport type VectorStoreConstructorLike<O extends BaseVectorStoreOptions = BaseVectorStoreOptions> =\n  new (options: O) => BaseVectorStore\n\n/**\n * The instance methods every {@link BaseVectorStore} subclass carries on its prototype — the\n * data plane (execute*), the schema plane, the connection lifecycle, and `asCallable` (which the\n * factory invokes to build the callable store). A duck-typed value is a valid adapter when its\n * prototype provides all of them.\n */\nconst VECTOR_STORE_METHODS = [\n  'isAvailable',\n  'connect',\n  'close',\n  'executeSearch',\n  'executeUpsert',\n  'executeDelete',\n  'createCollection',\n  'dropCollection',\n  'hasCollection',\n  'renameCollection',\n  'asCallable',\n] as const\n\n/**\n * Validator schema for a {@link VectorStoreConstructorLike} value.\n *\n * @remarks\n * Invoked at validate-time, so inspecting the constructor's prototype is safe. The check is\n * duck-typed: the value must be a function whose `prototype` carries every canonical adapter\n * instance method. This mirrors `spooledArtifactConstructorSchema`'s cross-realm-safe\n * pattern — `instanceof BaseVectorStore` would be tighter but would couple this contract to the\n * class value and reject structurally-valid (e.g. cross-realm) adapters.\n */\nexport const vectorStoreConstructorSchema = validator\n  .any()\n  .required()\n  .custom((value, helpers) => {\n    if (typeof value !== 'function') return helpers.error('any.invalid')\n    const proto = (value as { prototype?: unknown }).prototype\n    if (proto === undefined || proto === null) return helpers.error('any.invalid')\n    if (\n      VECTOR_STORE_METHODS.every((m) => typeof (proto as Record<string, unknown>)[m] === 'function')\n    ) {\n      return value\n    }\n    return helpers.error('any.invalid')\n  })\n\n/**\n * Returns `true` if `value` is a constructor whose prototype carries every canonical\n * {@link BaseVectorStore} instance method. Duck-typed; does not use `instanceof`.\n */\nexport const implementsVectorStoreConstructor = (\n  value: unknown\n): value is VectorStoreConstructorLike => {\n  // `.required()` on the schema makes the validator reject undefined/null itself (without it,\n  // `validator.any()` skips `.custom()` for an \"absent\" value and would wrongly pass).\n  const { error } = vectorStoreConstructorSchema.validate(value, { abortEarly: true })\n  return !error\n}\n"],"mappings":";;;;;;;;;;;AAyBA,IAAM,uBAAuB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;AAYA,IAAa,+BAA+B,UACzC,IAAI,EACJ,SAAS,EACT,QAAQ,OAAO,YAAY;CAC1B,IAAI,OAAO,UAAU,YAAY,OAAO,QAAQ,MAAM,aAAa;CACnE,MAAM,QAAS,MAAkC;CACjD,IAAI,UAAU,KAAA,KAAa,UAAU,MAAM,OAAO,QAAQ,MAAM,aAAa;CAC7E,IACE,qBAAqB,OAAO,MAAM,OAAQ,MAAkC,OAAO,UAAU,GAE7F,OAAO;CAET,OAAO,QAAQ,MAAM,aAAa;AACpC,CAAC;;;;;AAMH,IAAa,oCACX,UACwC;CAGxC,MAAM,EAAE,UAAU,6BAA6B,SAAS,OAAO,EAAE,YAAY,KAAK,CAAC;CACnF,OAAO,CAAC;AACV"}