ai-database 2.1.3 → 2.3.0

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.
Files changed (260) hide show
  1. package/CHANGELOG.md +35 -1
  2. package/README.md +880 -669
  3. package/dist/actions.d.ts +2 -2
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +1 -1
  6. package/dist/actions.js.map +1 -1
  7. package/dist/ai-promise-db.d.ts +49 -23
  8. package/dist/ai-promise-db.d.ts.map +1 -1
  9. package/dist/ai-promise-db.js +91 -63
  10. package/dist/ai-promise-db.js.map +1 -1
  11. package/dist/authorization.d.ts.map +1 -1
  12. package/dist/authorization.js +38 -30
  13. package/dist/authorization.js.map +1 -1
  14. package/dist/cascade-orchestrator.d.ts +404 -0
  15. package/dist/cascade-orchestrator.d.ts.map +1 -0
  16. package/dist/cascade-orchestrator.js +828 -0
  17. package/dist/cascade-orchestrator.js.map +1 -0
  18. package/dist/cascade-write-strategy.d.ts +584 -0
  19. package/dist/cascade-write-strategy.d.ts.map +1 -0
  20. package/dist/cascade-write-strategy.js +590 -0
  21. package/dist/cascade-write-strategy.js.map +1 -0
  22. package/dist/ch-adapter.d.ts +358 -0
  23. package/dist/ch-adapter.d.ts.map +1 -0
  24. package/dist/ch-adapter.js +929 -0
  25. package/dist/ch-adapter.js.map +1 -0
  26. package/dist/client/index.d.ts +42 -0
  27. package/dist/client/index.d.ts.map +1 -0
  28. package/dist/client/index.js +43 -0
  29. package/dist/client/index.js.map +1 -0
  30. package/dist/client.d.ts +266 -0
  31. package/dist/client.d.ts.map +1 -0
  32. package/dist/client.js +81 -0
  33. package/dist/client.js.map +1 -0
  34. package/dist/constants.d.ts +64 -1
  35. package/dist/constants.d.ts.map +1 -1
  36. package/dist/constants.js +52 -2
  37. package/dist/constants.js.map +1 -1
  38. package/dist/dataloader.d.ts +99 -0
  39. package/dist/dataloader.d.ts.map +1 -0
  40. package/dist/dataloader.js +225 -0
  41. package/dist/dataloader.js.map +1 -0
  42. package/dist/db-provider-port.d.ts +501 -0
  43. package/dist/db-provider-port.d.ts.map +1 -0
  44. package/dist/db-provider-port.js +113 -0
  45. package/dist/db-provider-port.js.map +1 -0
  46. package/dist/digital-objects-provider.d.ts +49 -0
  47. package/dist/digital-objects-provider.d.ts.map +1 -0
  48. package/dist/digital-objects-provider.js +55 -0
  49. package/dist/digital-objects-provider.js.map +1 -0
  50. package/dist/do-sqlite-adapter.d.ts +402 -0
  51. package/dist/do-sqlite-adapter.d.ts.map +1 -0
  52. package/dist/do-sqlite-adapter.js +745 -0
  53. package/dist/do-sqlite-adapter.js.map +1 -0
  54. package/dist/docs-rels/custom-types.d.ts +134 -0
  55. package/dist/docs-rels/custom-types.d.ts.map +1 -0
  56. package/dist/docs-rels/custom-types.js +70 -0
  57. package/dist/docs-rels/custom-types.js.map +1 -0
  58. package/dist/docs-rels/index.d.ts +16 -0
  59. package/dist/docs-rels/index.d.ts.map +1 -0
  60. package/dist/docs-rels/index.js +16 -0
  61. package/dist/docs-rels/index.js.map +1 -0
  62. package/dist/docs-rels/migrations/index.d.ts +30 -0
  63. package/dist/docs-rels/migrations/index.d.ts.map +1 -0
  64. package/dist/docs-rels/migrations/index.js +128 -0
  65. package/dist/docs-rels/migrations/index.js.map +1 -0
  66. package/dist/docs-rels/schema.d.ts +2961 -0
  67. package/dist/docs-rels/schema.d.ts.map +1 -0
  68. package/dist/docs-rels/schema.js +244 -0
  69. package/dist/docs-rels/schema.js.map +1 -0
  70. package/dist/durable-clickhouse.d.ts.map +1 -1
  71. package/dist/durable-clickhouse.js +16 -13
  72. package/dist/durable-clickhouse.js.map +1 -1
  73. package/dist/durable-promise.d.ts.map +1 -1
  74. package/dist/durable-promise.js +34 -15
  75. package/dist/durable-promise.js.map +1 -1
  76. package/dist/errors.d.ts +127 -0
  77. package/dist/errors.d.ts.map +1 -0
  78. package/dist/errors.js +210 -0
  79. package/dist/errors.js.map +1 -0
  80. package/dist/eventbridge.d.ts +117 -0
  81. package/dist/eventbridge.d.ts.map +1 -0
  82. package/dist/eventbridge.js +238 -0
  83. package/dist/eventbridge.js.map +1 -0
  84. package/dist/events.d.ts +2 -2
  85. package/dist/events.d.ts.map +1 -1
  86. package/dist/events.js +1 -1
  87. package/dist/events.js.map +1 -1
  88. package/dist/execution-queue.d.ts.map +1 -1
  89. package/dist/execution-queue.js +4 -5
  90. package/dist/execution-queue.js.map +1 -1
  91. package/dist/index.d.ts +35 -8
  92. package/dist/index.d.ts.map +1 -1
  93. package/dist/index.js +106 -6
  94. package/dist/index.js.map +1 -1
  95. package/dist/linguistic.d.ts +3 -108
  96. package/dist/linguistic.d.ts.map +1 -1
  97. package/dist/linguistic.js +3 -372
  98. package/dist/linguistic.js.map +1 -1
  99. package/dist/logger.d.ts +132 -0
  100. package/dist/logger.d.ts.map +1 -0
  101. package/dist/logger.js +137 -0
  102. package/dist/logger.js.map +1 -0
  103. package/dist/memory-provider.d.ts +128 -0
  104. package/dist/memory-provider.d.ts.map +1 -1
  105. package/dist/memory-provider.js +592 -257
  106. package/dist/memory-provider.js.map +1 -1
  107. package/dist/pg-adapter.d.ts +424 -0
  108. package/dist/pg-adapter.d.ts.map +1 -0
  109. package/dist/pg-adapter.js +921 -0
  110. package/dist/pg-adapter.js.map +1 -0
  111. package/dist/pipelines-iceberg-emitter.d.ts +327 -0
  112. package/dist/pipelines-iceberg-emitter.d.ts.map +1 -0
  113. package/dist/pipelines-iceberg-emitter.js +351 -0
  114. package/dist/pipelines-iceberg-emitter.js.map +1 -0
  115. package/dist/provider-capabilities.d.ts +146 -0
  116. package/dist/provider-capabilities.d.ts.map +1 -0
  117. package/dist/provider-capabilities.js +214 -0
  118. package/dist/provider-capabilities.js.map +1 -0
  119. package/dist/rdb-provider-adapter.d.ts +195 -0
  120. package/dist/rdb-provider-adapter.d.ts.map +1 -0
  121. package/dist/rdb-provider-adapter.js +291 -0
  122. package/dist/rdb-provider-adapter.js.map +1 -0
  123. package/dist/schema/cascade.d.ts +48 -17
  124. package/dist/schema/cascade.d.ts.map +1 -1
  125. package/dist/schema/cascade.js +477 -278
  126. package/dist/schema/cascade.js.map +1 -1
  127. package/dist/schema/definition-caches.d.ts +24 -0
  128. package/dist/schema/definition-caches.d.ts.map +1 -0
  129. package/dist/schema/definition-caches.js +26 -0
  130. package/dist/schema/definition-caches.js.map +1 -0
  131. package/dist/schema/dependency-graph.d.ts +21 -109
  132. package/dist/schema/dependency-graph.d.ts.map +1 -1
  133. package/dist/schema/dependency-graph.js +25 -333
  134. package/dist/schema/dependency-graph.js.map +1 -1
  135. package/dist/schema/diff.d.ts +103 -0
  136. package/dist/schema/diff.d.ts.map +1 -0
  137. package/dist/schema/diff.js +329 -0
  138. package/dist/schema/diff.js.map +1 -0
  139. package/dist/schema/entity-operations.d.ts +99 -0
  140. package/dist/schema/entity-operations.d.ts.map +1 -0
  141. package/dist/schema/entity-operations.js +818 -0
  142. package/dist/schema/entity-operations.js.map +1 -0
  143. package/dist/schema/index.d.ts +28 -34
  144. package/dist/schema/index.d.ts.map +1 -1
  145. package/dist/schema/index.js +454 -521
  146. package/dist/schema/index.js.map +1 -1
  147. package/dist/schema/migration.d.ts +205 -0
  148. package/dist/schema/migration.d.ts.map +1 -0
  149. package/dist/schema/migration.js +327 -0
  150. package/dist/schema/migration.js.map +1 -0
  151. package/dist/schema/nl-query-generator.d.ts +68 -0
  152. package/dist/schema/nl-query-generator.d.ts.map +1 -0
  153. package/dist/schema/nl-query-generator.js +362 -0
  154. package/dist/schema/nl-query-generator.js.map +1 -0
  155. package/dist/schema/nl-query.d.ts +65 -0
  156. package/dist/schema/nl-query.d.ts.map +1 -0
  157. package/dist/schema/nl-query.js +178 -0
  158. package/dist/schema/nl-query.js.map +1 -0
  159. package/dist/schema/parse.d.ts.map +1 -1
  160. package/dist/schema/parse.js +144 -89
  161. package/dist/schema/parse.js.map +1 -1
  162. package/dist/schema/provider.d.ts +37 -0
  163. package/dist/schema/provider.d.ts.map +1 -1
  164. package/dist/schema/provider.js +15 -7
  165. package/dist/schema/provider.js.map +1 -1
  166. package/dist/schema/resolve.d.ts +46 -5
  167. package/dist/schema/resolve.d.ts.map +1 -1
  168. package/dist/schema/resolve.js +237 -95
  169. package/dist/schema/resolve.js.map +1 -1
  170. package/dist/schema/search-utils.d.ts +76 -0
  171. package/dist/schema/search-utils.d.ts.map +1 -0
  172. package/dist/schema/search-utils.js +86 -0
  173. package/dist/schema/search-utils.js.map +1 -0
  174. package/dist/schema/seed.d.ts +53 -0
  175. package/dist/schema/seed.d.ts.map +1 -0
  176. package/dist/schema/seed.js +94 -0
  177. package/dist/schema/seed.js.map +1 -0
  178. package/dist/schema/semantic.d.ts +10 -0
  179. package/dist/schema/semantic.d.ts.map +1 -1
  180. package/dist/schema/semantic.js +192 -86
  181. package/dist/schema/semantic.js.map +1 -1
  182. package/dist/schema/sub-apis.d.ts +52 -0
  183. package/dist/schema/sub-apis.d.ts.map +1 -0
  184. package/dist/schema/sub-apis.js +216 -0
  185. package/dist/schema/sub-apis.js.map +1 -0
  186. package/dist/schema/system-entities.d.ts +42 -0
  187. package/dist/schema/system-entities.d.ts.map +1 -0
  188. package/dist/schema/system-entities.js +101 -0
  189. package/dist/schema/system-entities.js.map +1 -0
  190. package/dist/schema/types.d.ts +91 -9
  191. package/dist/schema/types.d.ts.map +1 -1
  192. package/dist/schema/union-fallback.d.ts.map +1 -1
  193. package/dist/schema/union-fallback.js +21 -15
  194. package/dist/schema/union-fallback.js.map +1 -1
  195. package/dist/schema/value-generators/ai.d.ts +54 -0
  196. package/dist/schema/value-generators/ai.d.ts.map +1 -0
  197. package/dist/schema/value-generators/ai.js +136 -0
  198. package/dist/schema/value-generators/ai.js.map +1 -0
  199. package/dist/schema/value-generators/index.d.ts +126 -0
  200. package/dist/schema/value-generators/index.d.ts.map +1 -0
  201. package/dist/schema/value-generators/index.js +219 -0
  202. package/dist/schema/value-generators/index.js.map +1 -0
  203. package/dist/schema/value-generators/placeholder.d.ts +52 -0
  204. package/dist/schema/value-generators/placeholder.d.ts.map +1 -0
  205. package/dist/schema/value-generators/placeholder.js +328 -0
  206. package/dist/schema/value-generators/placeholder.js.map +1 -0
  207. package/dist/schema/value-generators/types.d.ts +116 -0
  208. package/dist/schema/value-generators/types.d.ts.map +1 -0
  209. package/dist/schema/value-generators/types.js +11 -0
  210. package/dist/schema/value-generators/types.js.map +1 -0
  211. package/dist/schema/version.d.ts +111 -0
  212. package/dist/schema/version.d.ts.map +1 -0
  213. package/dist/schema/version.js +190 -0
  214. package/dist/schema/version.js.map +1 -0
  215. package/dist/schema.d.ts +1095 -24
  216. package/dist/schema.d.ts.map +1 -1
  217. package/dist/schema.js +2852 -40
  218. package/dist/schema.js.map +1 -1
  219. package/dist/semantic-vectors.d.ts +39 -0
  220. package/dist/semantic-vectors.d.ts.map +1 -0
  221. package/dist/semantic-vectors.js +334 -0
  222. package/dist/semantic-vectors.js.map +1 -0
  223. package/dist/semantic.d.ts +29 -1
  224. package/dist/semantic.d.ts.map +1 -1
  225. package/dist/semantic.js +26 -16
  226. package/dist/semantic.js.map +1 -1
  227. package/dist/telemetry.d.ts +128 -0
  228. package/dist/telemetry.d.ts.map +1 -0
  229. package/dist/telemetry.js +305 -0
  230. package/dist/telemetry.js.map +1 -0
  231. package/dist/tests.d.ts.map +1 -1
  232. package/dist/tests.js +30 -22
  233. package/dist/tests.js.map +1 -1
  234. package/dist/type-guards.d.ts +50 -5
  235. package/dist/type-guards.d.ts.map +1 -1
  236. package/dist/type-guards.js +87 -16
  237. package/dist/type-guards.js.map +1 -1
  238. package/dist/types.d.ts +33 -245
  239. package/dist/types.d.ts.map +1 -1
  240. package/dist/types.js +62 -72
  241. package/dist/types.js.map +1 -1
  242. package/dist/validation.d.ts +2 -5
  243. package/dist/validation.d.ts.map +1 -1
  244. package/dist/validation.js +65 -93
  245. package/dist/validation.js.map +1 -1
  246. package/dist/worker/db-provider.d.ts +168 -0
  247. package/dist/worker/db-provider.d.ts.map +1 -0
  248. package/dist/worker/db-provider.js +277 -0
  249. package/dist/worker/db-provider.js.map +1 -0
  250. package/dist/worker/index.d.ts +35 -0
  251. package/dist/worker/index.d.ts.map +1 -0
  252. package/dist/worker/index.js +37 -0
  253. package/dist/worker/index.js.map +1 -0
  254. package/dist/worker.d.ts +779 -0
  255. package/dist/worker.d.ts.map +1 -0
  256. package/dist/worker.js +2786 -0
  257. package/dist/worker.js.map +1 -0
  258. package/package.json +46 -16
  259. package/src/docs-rels/migrations/0001-init.sql +125 -0
  260. package/LICENSE +0 -21
@@ -0,0 +1,501 @@
1
+ /**
2
+ * DBProvider Port — SVO-shaped storage contract
3
+ *
4
+ * This module is the canonical reference for the `DBProvider` port shape and its
5
+ * declared capability tiers. It refines the structural interface in
6
+ * `./schema/provider.ts` (kept for backward compatibility) with:
7
+ *
8
+ * - **Tier model from ADR-0003**: Tier 1+2 are universal (every adapter
9
+ * supports them); Tier 3 (analytics) and Tier 4 (vector search) are
10
+ * declared per-adapter via `ProviderTierCapabilities`.
11
+ * - **SVO-aligned Action recording** that carries Frame roles
12
+ * (`subject`, `object`, `recipient`, `source`, `destination`,
13
+ * `instrument`, `topic`, `cause`, `manner`) per `digital-objects` and
14
+ * CONTEXT.md.
15
+ * - **Sharding model declaration** so the cascade write strategy can pick
16
+ * the right adapter for a workload (per-cascade DO SQLite vs.
17
+ * partitioned Postgres vs. unsharded).
18
+ *
19
+ * The shape is **additive**: every existing `DBProvider` implementation in
20
+ * this package (MemoryProvider, RDBProviderAdapter, DigitalObjectsProvider)
21
+ * remains valid without changes. Capability declarations are optional —
22
+ * absence implies "Tier 1+2 only, sharding `unsharded`, no analytics, no
23
+ * vector search". Adapters declare richer capabilities by attaching a
24
+ * `capabilities: ProviderTierCapabilities` getter.
25
+ *
26
+ * @see {@link ../docs/adr/0003-storage-strategy-pg-clickhouse-default.md}
27
+ * @see {@link ./schema/provider.ts} for the live structural interface
28
+ * @packageDocumentation
29
+ */
30
+ import type { DBProvider, Transaction } from './schema/provider.js';
31
+ import type { ListOptions, SearchOptions, SemanticSearchOptions, HybridSearchOptions } from './schema/types.js';
32
+ /**
33
+ * Frame role taxonomy — the closed set of complement roles a Verb may take.
34
+ *
35
+ * Mirrors `digital-objects` `FrameRole` exactly. Re-declared here so callers
36
+ * of `ai-database` can express role-bearing queries against the port without
37
+ * a hard dependency on `digital-objects` types.
38
+ *
39
+ * `subject`/`object` are the primary SVO axes; the rest are filled
40
+ * optionally per a Verb's declared Frame. The literal `when`/`where`
41
+ * (timestamp/location) are carried directly on Action and are not Frame
42
+ * roles.
43
+ *
44
+ * @see CONTEXT.md "Frame roles (closed taxonomy)"
45
+ */
46
+ export type FrameRole = 'subject' | 'object' | 'recipient' | 'source' | 'destination' | 'instrument' | 'topic' | 'cause' | 'manner';
47
+ /**
48
+ * Sharding strategy a DBProvider adapter exposes to callers.
49
+ *
50
+ * Cascade generation (the `ai-database` moat) writes thousands of entities
51
+ * + relations per cascade. Knowing the adapter's sharding shape lets the
52
+ * cascade write strategy pick the correct fan-out:
53
+ *
54
+ * - `'per-cascade'` — Each cascade gets its own database/shard. Native to
55
+ * Cloudflare Durable Objects: one DO per cascade gives full single-DO
56
+ * throughput in parallel across many active cascades. Read-back during
57
+ * traversal stays inside the same shard (no cross-shard hot-path reads).
58
+ *
59
+ * - `'partitioned-by-tenant'` — Adapter partitions on a tenant/namespace
60
+ * key. Native shape for multi-tenant Postgres (schema-per-tenant or
61
+ * partitioned table). Cascades within one tenant share a partition;
62
+ * different tenants are isolated.
63
+ *
64
+ * - `'unsharded'` — One global store. Default for in-memory / dev / single
65
+ * small Postgres deployments. Cascade-throughput hits the adapter's
66
+ * single-writer ceiling.
67
+ *
68
+ * Adapters MAY declare a custom string for future strategies (e.g.,
69
+ * `'per-tenant-do'`). The union is open via `string` for forward
70
+ * compatibility.
71
+ *
72
+ * @see ADR-0003 "Cascade generation is the moat — and dictates the storage shape"
73
+ */
74
+ export type ShardingModel = 'per-cascade' | 'partitioned-by-tenant' | 'unsharded' | (string & {});
75
+ /**
76
+ * Similarity metric supported by a vector-search-capable adapter.
77
+ *
78
+ * Adapters that support vector search declare which metrics their backend
79
+ * can compute. Callers that need a specific metric must verify support
80
+ * before issuing the query.
81
+ *
82
+ * - `'cosine'` — Cosine similarity (most common; pgvector, CH, Vectorize).
83
+ * - `'l2'` — Euclidean / L2 distance.
84
+ * - `'dot'` — Dot product (inner product); pgvector and CH support this.
85
+ * - `'hamming'` — For binary embeddings (rare; declare only if implemented).
86
+ */
87
+ export type VectorSimilarityMetric = 'cosine' | 'l2' | 'dot' | 'hamming';
88
+ /**
89
+ * Tier 4 — vector search capability declaration.
90
+ *
91
+ * Adapters declare:
92
+ * - The maximum embedding dimension they accept on a single index.
93
+ * - The similarity metrics they support natively.
94
+ * - Whether the implementation is native to the transactional store
95
+ * (e.g., `pgvector`) or runs as a sidecar (e.g., DO SQLite + Vectorize
96
+ * sidecar binding). Sidecar adapters add operational cost (per-deployment
97
+ * binding) but the cascade workload still benefits.
98
+ *
99
+ * Per ADR-0003: pgvector is native; CH has vector functions; DO SQLite
100
+ * requires Vectorize sidecar; libSQL/Turso has native vectors; R2 vector
101
+ * search is explicitly out of scope.
102
+ */
103
+ export interface VectorSearchCapability {
104
+ /**
105
+ * Maximum embedding dimension the adapter can index in a single vector
106
+ * column / index. Common values: 1536 (OpenAI ada-002), 3072
107
+ * (text-embedding-3-large), 384 (sentence-transformers).
108
+ */
109
+ maxDimensions: number;
110
+ /**
111
+ * Similarity metrics supported by the adapter. Order is informational
112
+ * (first metric is typically the recommended/cheapest).
113
+ */
114
+ metrics: ReadonlyArray<VectorSimilarityMetric>;
115
+ /**
116
+ * Whether the vector index lives in the transactional store (`'native'`)
117
+ * or in a separate service/binding (`'sidecar'`).
118
+ *
119
+ * Sidecar implementations require additional configuration at deployment
120
+ * time and may have different consistency / latency characteristics from
121
+ * the primary store. Stack B (DO SQLite + Vectorize) is `'sidecar'`.
122
+ */
123
+ implementation: 'native' | 'sidecar';
124
+ }
125
+ /**
126
+ * Tier 3 — analytics capability declaration.
127
+ *
128
+ * Adapters that can serve aggregations, time-series rollups, and
129
+ * large-scan analytical queries efficiently declare this. Examples:
130
+ *
131
+ * - **ClickHouse** — full Tier 3 (aggregations, windows, time-series).
132
+ * - **Postgres** — declares Tier 3 with caveats (works at moderate scale;
133
+ * long scans contend with transactional load).
134
+ * - **DO SQLite** — should NOT declare Tier 3 (per-DO limit; cross-DB
135
+ * queries hard).
136
+ * - **MemoryProvider** — does not declare Tier 3.
137
+ *
138
+ * The shape is intentionally minimal in this bead. Future beads may add
139
+ * fine-grained sub-flags (`hasWindowFunctions`, `hasJoins`,
140
+ * `hasTimeSeries`) — they fit additively under this object.
141
+ */
142
+ export interface AnalyticsCapability {
143
+ /** True when the adapter can run aggregations efficiently. */
144
+ hasAggregations: boolean;
145
+ /**
146
+ * True when the adapter supports time-series functions (window
147
+ * aggregates over time, sessionization). ClickHouse yes; raw Postgres
148
+ * yes with caveats; DO SQLite no; R2 SQL not yet (per ADR-0003).
149
+ */
150
+ hasTimeSeries: boolean;
151
+ /**
152
+ * True when large scans (millions of rows) are part of the supported
153
+ * workload. ClickHouse yes; Postgres conditional; DO SQLite no.
154
+ */
155
+ hasLargeScans: boolean;
156
+ }
157
+ /**
158
+ * Tier-model capability declaration attached to a DBProvider implementation.
159
+ *
160
+ * Per ADR-0003, every adapter satisfies Tier 1 (entity CRUD) and Tier 2
161
+ * (graph traversal across Action subject/object/recipient roles) — these
162
+ * are not declared, they are expected. This object declares the
163
+ * **opt-in** tiers.
164
+ *
165
+ * Adapters expose this via a `capabilities` property on their DBProvider
166
+ * implementation. Callers introspect via {@link getProviderCapabilities}
167
+ * which falls back to the `'unsharded'` / no-Tier-3 / no-Tier-4 default
168
+ * for adapters that haven't declared.
169
+ */
170
+ export interface ProviderTierCapabilities {
171
+ /** Stable adapter identifier (`'memory'`, `'pg+pgvector'`, `'clickhouse'`, `'do-sqlite'`, etc.). */
172
+ adapter: string;
173
+ /** Sharding strategy the adapter implements. See {@link ShardingModel}. */
174
+ shardingModel: ShardingModel;
175
+ /**
176
+ * Tier 3 — analytics. Absent => not supported (callers should fall back
177
+ * or refuse). Present => the adapter promises the declared sub-flags.
178
+ */
179
+ analytics?: AnalyticsCapability;
180
+ /**
181
+ * Tier 4 — vector search. Absent => not supported. Present => the
182
+ * adapter promises the declared dimension cap, metrics, and
183
+ * implementation shape.
184
+ */
185
+ vectorSearch?: VectorSearchCapability;
186
+ /**
187
+ * True if the adapter supports the SVO Action-recording surface
188
+ * ({@link DBProviderSVO.recordAction} and friends). Defaults to false
189
+ * for backward compatibility — existing adapters expose Actions through
190
+ * `relate()` / `DBProviderExtended.createAction()` instead.
191
+ */
192
+ hasActionRecording?: boolean;
193
+ /**
194
+ * True if the adapter exposes a Verb registry
195
+ * ({@link DBProviderSVO.defineVerb} and friends). Like
196
+ * `hasActionRecording`, defaults to false; the Verb registry today
197
+ * lives in `digital-objects` and adapters wrapping it surface it
198
+ * upstream.
199
+ */
200
+ hasVerbRegistry?: boolean;
201
+ }
202
+ /**
203
+ * SVO-aligned Action record carrying Frame roles.
204
+ *
205
+ * Wire-shape compatible with `digital-objects` `Action`: same `id`,
206
+ * `verb`, `subject`, `object`, `roles`, `data`, `status`, `createdAt`,
207
+ * `completedAt`. Re-declared here to avoid an upward dependency on
208
+ * `digital-objects`.
209
+ *
210
+ * Adapters that declare `hasActionRecording: true` produce records of
211
+ * this shape and accept queries against role slots.
212
+ */
213
+ export interface SVOAction<T extends Record<string, unknown> = Record<string, unknown>> {
214
+ /** Unique action id. */
215
+ id: string;
216
+ /**
217
+ * Verb name (references a Verb in the registry). Examples: `'create'`,
218
+ * `'approve'`, `'send'`. The Verb's Frame describes which roles are
219
+ * meaningful for this Verb.
220
+ */
221
+ verb: string;
222
+ /** Thing id of the subject (actor / who-acts). Required for transitive Actions. */
223
+ subject?: string;
224
+ /** Thing id of the direct object (what-is-acted-on). */
225
+ object?: string;
226
+ /**
227
+ * Remaining Frame slots. Values are Thing ids (`ThingRef`) for
228
+ * entity-shaped roles, or strings for `manner` enum values. Unused
229
+ * slots are absent rather than null.
230
+ */
231
+ roles?: Partial<Record<Exclude<FrameRole, 'subject' | 'object'>, string>>;
232
+ /** Optional payload / metadata for the Action (Verb-specific). */
233
+ data?: T;
234
+ /** Action lifecycle status. */
235
+ status: 'pending' | 'active' | 'completed' | 'failed' | 'cancelled';
236
+ /** When the Action record was created. */
237
+ createdAt: Date;
238
+ /** When the Action transitioned to a terminal status (completed/failed/cancelled). */
239
+ completedAt?: Date;
240
+ }
241
+ /**
242
+ * Filter for querying Actions by Frame role.
243
+ *
244
+ * Every field is optional; the adapter ANDs them. To find every Action
245
+ * Priya took as `subject` regardless of Verb: `{ subject: 'priya' }`.
246
+ * To find every `approve` Action Priya took on a refund:
247
+ * `{ verb: 'approve', subject: 'priya', object: 'refund-123' }`.
248
+ */
249
+ export interface ActionQuery {
250
+ /** Filter by Verb name. */
251
+ verb?: string;
252
+ /** Filter by `subject` Thing id. */
253
+ subject?: string;
254
+ /** Filter by `object` Thing id. */
255
+ object?: string;
256
+ /**
257
+ * Filter by any Frame role. Keys are role names (`'recipient'`,
258
+ * `'source'`, ...); values are Thing ids (or `manner` strings).
259
+ * Adapters MUST evaluate exact equality on the role slot.
260
+ */
261
+ role?: Partial<Record<FrameRole, string>>;
262
+ /** Filter by status. */
263
+ status?: SVOAction['status'] | SVOAction['status'][];
264
+ /** Created-at lower bound (inclusive). */
265
+ since?: Date;
266
+ /** Created-at upper bound (inclusive). */
267
+ until?: Date;
268
+ /** Pagination. */
269
+ limit?: number;
270
+ /** Pagination. */
271
+ offset?: number;
272
+ }
273
+ /**
274
+ * Verb definition input for the optional Verb registry.
275
+ *
276
+ * Mirrors `digital-objects` `VerbDefinition` — adapters that wrap
277
+ * `digital-objects` (e.g., `DigitalObjectsProvider`) forward this
278
+ * directly. The Frame is opaque to `ai-database` here (string
279
+ * key/value); strict typing comes from the upstream `digital-objects`
280
+ * type when callers import it.
281
+ */
282
+ export interface VerbDefinitionInput {
283
+ name: string;
284
+ action?: string;
285
+ act?: string;
286
+ activity?: string;
287
+ event?: string;
288
+ reverseBy?: string;
289
+ reverseAt?: string;
290
+ reverseIn?: string;
291
+ inverse?: string;
292
+ description?: string;
293
+ frame?: Record<string, unknown>;
294
+ source?: string;
295
+ canonical?: boolean;
296
+ }
297
+ /**
298
+ * Verb record returned by the registry.
299
+ */
300
+ export interface VerbRecord {
301
+ name: string;
302
+ action: string;
303
+ act: string;
304
+ activity: string;
305
+ event: string;
306
+ reverseBy?: string;
307
+ reverseAt?: string;
308
+ reverseIn?: string;
309
+ inverse?: string;
310
+ description?: string;
311
+ frame?: Record<string, unknown>;
312
+ source?: string;
313
+ canonical?: boolean;
314
+ createdAt: Date;
315
+ }
316
+ /**
317
+ * SVO-aligned port surface — the **declared** Tier-2-Verbs portion of the port.
318
+ *
319
+ * Adapters may implement none, some, or all of these methods. Callers
320
+ * MUST check `capabilities.hasActionRecording` and
321
+ * `capabilities.hasVerbRegistry` (or use the type guards in this module)
322
+ * before invoking.
323
+ *
324
+ * **Invariants**:
325
+ * - {@link recordAction} returns the persisted Action; callers may use
326
+ * the returned `id` for traversal queries.
327
+ * - {@link queryActions} ordering: by `createdAt` ascending unless the
328
+ * adapter documents otherwise. (`limit`/`offset` apply post-ordering.)
329
+ * - All role values reference Thing ids that the adapter MAY validate
330
+ * (foreign-key-style) — adapters MUST NOT silently rewrite ids.
331
+ *
332
+ * **Error modes**:
333
+ * - Unknown Verb when calling {@link recordAction}: adapters SHOULD
334
+ * reject with a typed error (e.g., `EntityNotFoundError` for the
335
+ * Verb). They MAY auto-define unknown Verbs if `hasVerbRegistry`;
336
+ * callers should not depend on either behavior.
337
+ * - Pagination out of range returns an empty array, never throws.
338
+ */
339
+ export interface DBProviderSVO {
340
+ /**
341
+ * Record an Action against the SVO ontology. Returns the persisted
342
+ * record. The `id` is adapter-generated unless the caller provides one
343
+ * via `data.id` (uncommon).
344
+ *
345
+ * Required when `capabilities.hasActionRecording` is `true`.
346
+ */
347
+ recordAction<T extends Record<string, unknown> = Record<string, unknown>>(input: Omit<SVOAction<T>, 'id' | 'createdAt' | 'status'> & {
348
+ status?: SVOAction['status'];
349
+ }): Promise<SVOAction<T>>;
350
+ /**
351
+ * Query Actions by Verb / role / status / time window. See
352
+ * {@link ActionQuery} for filter semantics.
353
+ *
354
+ * Required when `capabilities.hasActionRecording` is `true`.
355
+ */
356
+ queryActions<T extends Record<string, unknown> = Record<string, unknown>>(query?: ActionQuery): Promise<SVOAction<T>[]>;
357
+ /**
358
+ * Define (register) a Verb. No-op if a Verb with the same `name`
359
+ * already exists with identical conjugations; rejects if conjugations
360
+ * conflict.
361
+ *
362
+ * Required when `capabilities.hasVerbRegistry` is `true`.
363
+ */
364
+ defineVerb(def: VerbDefinitionInput): Promise<VerbRecord>;
365
+ /**
366
+ * Get a Verb by name. Returns `null` if not registered.
367
+ *
368
+ * Required when `capabilities.hasVerbRegistry` is `true`.
369
+ */
370
+ getVerb(name: string): Promise<VerbRecord | null>;
371
+ /**
372
+ * List all registered Verbs. Order is adapter-defined unless documented.
373
+ *
374
+ * Required when `capabilities.hasVerbRegistry` is `true`.
375
+ */
376
+ listVerbs(): Promise<VerbRecord[]>;
377
+ }
378
+ /**
379
+ * A single vector search hit. Returned by adapters that declare
380
+ * `capabilities.vectorSearch`.
381
+ */
382
+ export interface VectorSearchHit<T extends Record<string, unknown> = Record<string, unknown>> {
383
+ /** The matching Thing record (with `$id` / `$type` injected by the adapter). */
384
+ entity: T & {
385
+ $id: string;
386
+ $type: string;
387
+ };
388
+ /** Similarity score in the metric the query used (higher is more similar). */
389
+ score: number;
390
+ }
391
+ /**
392
+ * Tier-4 vector search method shape. Adapters that declare
393
+ * `capabilities.vectorSearch` MUST implement this.
394
+ */
395
+ export interface VectorSearchPort {
396
+ /**
397
+ * Search for the nearest entities to a query embedding.
398
+ *
399
+ * The query embedding's length MUST be `<=` the adapter's
400
+ * `capabilities.vectorSearch.maxDimensions`. The metric MUST be one of
401
+ * `capabilities.vectorSearch.metrics`.
402
+ */
403
+ vectorSearch<T extends Record<string, unknown> = Record<string, unknown>>(type: string, queryEmbedding: number[], options?: {
404
+ metric?: VectorSimilarityMetric;
405
+ limit?: number;
406
+ minScore?: number;
407
+ }): Promise<VectorSearchHit<T>[]>;
408
+ }
409
+ /**
410
+ * Tier-3 analytics surface. Concrete shape is intentionally narrow at
411
+ * port level — full schema lives with the analytics adapter
412
+ * (ClickHouse). This declaration exists so callers can detect and
413
+ * route Tier-3 queries to a capable adapter.
414
+ */
415
+ export interface AnalyticsPort {
416
+ /**
417
+ * Run a Tier-3 aggregation query. The query string is adapter-specific
418
+ * (SQL-shaped for CH/PG; declarative DSL for future R2 SQL). Callers
419
+ * that want portability use the upstream cascade-analytics helpers
420
+ * rather than calling this directly.
421
+ *
422
+ * The shape is intentionally minimal in this bead. Future beads
423
+ * (`aip-j3il`, `aip-peb5`) refine it.
424
+ */
425
+ analyticsQuery(query: string, params?: Record<string, unknown>): Promise<Array<Record<string, unknown>>>;
426
+ }
427
+ /**
428
+ * The full port surface a fully-loaded adapter (e.g., Stack A PG +
429
+ * pgvector + analytics, Stack B DO SQLite + Vectorize) can satisfy.
430
+ *
431
+ * Most adapters satisfy a subset. The structural `DBProvider` from
432
+ * `./schema/provider.ts` remains the *required* baseline; everything
433
+ * else is declared.
434
+ *
435
+ * The optional `capabilities` getter is the canonical way to expose
436
+ * tier capability declarations.
437
+ */
438
+ export interface DBProviderPort extends DBProvider {
439
+ /**
440
+ * Tier capability declaration (sharding, analytics, vectorSearch,
441
+ * SVO-recording flags). Optional for backward compatibility — absence
442
+ * is interpreted by {@link getProviderCapabilities} as Tier 1+2 only,
443
+ * `unsharded`.
444
+ */
445
+ capabilities?: ProviderTierCapabilities | (() => ProviderTierCapabilities);
446
+ }
447
+ /**
448
+ * Default capability declaration for adapters that don't expose one.
449
+ * `'unsharded'`, no Tier 3, no Tier 4, no SVO action recording, no Verb
450
+ * registry. Backward-compatible with every adapter shipped before this
451
+ * port refinement.
452
+ */
453
+ export declare const DEFAULT_TIER_CAPABILITIES: ProviderTierCapabilities;
454
+ /**
455
+ * Read the capability declaration from a provider, falling back to
456
+ * {@link DEFAULT_TIER_CAPABILITIES} when none is attached.
457
+ *
458
+ * Handles both forms — `capabilities` as a static object or as a getter
459
+ * function — without forcing adapters to choose one shape.
460
+ *
461
+ * @example
462
+ * ```ts
463
+ * const caps = getProviderCapabilities(provider)
464
+ * if (caps.vectorSearch && caps.vectorSearch.metrics.includes('cosine')) {
465
+ * // safe to issue cosine vector search
466
+ * }
467
+ * ```
468
+ */
469
+ export declare function getProviderCapabilities(provider: DBProvider): ProviderTierCapabilities;
470
+ /**
471
+ * Type guard: does this provider satisfy the SVO Action-recording
472
+ * surface ({@link DBProviderSVO.recordAction}, {@link DBProviderSVO.queryActions})?
473
+ *
474
+ * Checks both the runtime methods and the `capabilities.hasActionRecording`
475
+ * flag — adapters should keep them in sync.
476
+ */
477
+ export declare function hasActionRecording(provider: DBProvider): provider is DBProvider & Pick<DBProviderSVO, 'recordAction' | 'queryActions'>;
478
+ /**
479
+ * Type guard: does this provider satisfy the Verb registry surface?
480
+ */
481
+ export declare function hasVerbRegistry(provider: DBProvider): provider is DBProvider & Pick<DBProviderSVO, 'defineVerb' | 'getVerb' | 'listVerbs'>;
482
+ /**
483
+ * Type guard: does this provider implement Tier-4 vector search?
484
+ *
485
+ * Checks the runtime method *and* requires the capability declaration
486
+ * to advertise `vectorSearch` — both must agree before callers can
487
+ * route queries.
488
+ */
489
+ export declare function hasVectorSearch(provider: DBProvider): provider is DBProvider & VectorSearchPort;
490
+ /**
491
+ * Type guard: does this provider implement Tier-3 analytics?
492
+ */
493
+ export declare function hasAnalytics(provider: DBProvider): provider is DBProvider & AnalyticsPort;
494
+ /**
495
+ * Re-export the structural `DBProvider` and `Transaction` interfaces from
496
+ * `./schema/provider.ts`. Importing them through this module signals
497
+ * "I'm using the SVO-shaped port surface", but they're the same types
498
+ * adapters have always implemented.
499
+ */
500
+ export type { DBProvider, Transaction, ListOptions, SearchOptions, SemanticSearchOptions, HybridSearchOptions, };
501
+ //# sourceMappingURL=db-provider-port.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db-provider-port.d.ts","sourceRoot":"","sources":["../src/db-provider-port.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,mBAAmB,CAAA;AAM1B;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,SAAS,GACjB,SAAS,GACT,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,aAAa,GACb,YAAY,GACZ,OAAO,GACP,OAAO,GACP,QAAQ,CAAA;AAMZ;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,uBAAuB,GAAG,WAAW,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAMjG;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,sBAAsB,GAAG,QAAQ,GAAG,IAAI,GAAG,KAAK,GAAG,SAAS,CAAA;AAExE;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAA;IAErB;;;OAGG;IACH,OAAO,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAA;IAE9C;;;;;;;OAOG;IACH,cAAc,EAAE,QAAQ,GAAG,SAAS,CAAA;CACrC;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,mBAAmB;IAClC,8DAA8D;IAC9D,eAAe,EAAE,OAAO,CAAA;IAExB;;;;OAIG;IACH,aAAa,EAAE,OAAO,CAAA;IAEtB;;;OAGG;IACH,aAAa,EAAE,OA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,CAAC,QAAQ,EAAE,UAAU,GAAG,wBAAwB,CAMtF;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,UAAU,GACnB,QAAQ,IAAI,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,cAAc,GAAG,cAAc,CAAC,CAG/E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,UAAU,GACnB,QAAQ,IAAI,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,YAAY,GAAG,SAAS,GAAG,WAAW,CAAC,CAOtF;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,UAAU,GAAG,QAAQ,IAAI,UAAU,GAAG,gBAAgB,CAK/F;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,UAAU,GAAG,QAAQ,IAAI,UAAU,GAAG,aAAa,CAKzF;AAMD;;;;;GAKG;AACH,YAAY,EACV,UAAU,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,mBAAmB,GACpB,CAAA"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * DBProvider Port — SVO-shaped storage contract
3
+ *
4
+ * This module is the canonical reference for the `DBProvider` port shape and its
5
+ * declared capability tiers. It refines the structural interface in
6
+ * `./schema/provider.ts` (kept for backward compatibility) with:
7
+ *
8
+ * - **Tier model from ADR-0003**: Tier 1+2 are universal (every adapter
9
+ * supports them); Tier 3 (analytics) and Tier 4 (vector search) are
10
+ * declared per-adapter via `ProviderTierCapabilities`.
11
+ * - **SVO-aligned Action recording** that carries Frame roles
12
+ * (`subject`, `object`, `recipient`, `source`, `destination`,
13
+ * `instrument`, `topic`, `cause`, `manner`) per `digital-objects` and
14
+ * CONTEXT.md.
15
+ * - **Sharding model declaration** so the cascade write strategy can pick
16
+ * the right adapter for a workload (per-cascade DO SQLite vs.
17
+ * partitioned Postgres vs. unsharded).
18
+ *
19
+ * The shape is **additive**: every existing `DBProvider` implementation in
20
+ * this package (MemoryProvider, RDBProviderAdapter, DigitalObjectsProvider)
21
+ * remains valid without changes. Capability declarations are optional —
22
+ * absence implies "Tier 1+2 only, sharding `unsharded`, no analytics, no
23
+ * vector search". Adapters declare richer capabilities by attaching a
24
+ * `capabilities: ProviderTierCapabilities` getter.
25
+ *
26
+ * @see {@link ../docs/adr/0003-storage-strategy-pg-clickhouse-default.md}
27
+ * @see {@link ./schema/provider.ts} for the live structural interface
28
+ * @packageDocumentation
29
+ */
30
+ // =============================================================================
31
+ // Capability discovery helpers
32
+ // =============================================================================
33
+ /**
34
+ * Default capability declaration for adapters that don't expose one.
35
+ * `'unsharded'`, no Tier 3, no Tier 4, no SVO action recording, no Verb
36
+ * registry. Backward-compatible with every adapter shipped before this
37
+ * port refinement.
38
+ */
39
+ export const DEFAULT_TIER_CAPABILITIES = {
40
+ adapter: 'unknown',
41
+ shardingModel: 'unsharded',
42
+ hasActionRecording: false,
43
+ hasVerbRegistry: false,
44
+ };
45
+ /**
46
+ * Read the capability declaration from a provider, falling back to
47
+ * {@link DEFAULT_TIER_CAPABILITIES} when none is attached.
48
+ *
49
+ * Handles both forms — `capabilities` as a static object or as a getter
50
+ * function — without forcing adapters to choose one shape.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * const caps = getProviderCapabilities(provider)
55
+ * if (caps.vectorSearch && caps.vectorSearch.metrics.includes('cosine')) {
56
+ * // safe to issue cosine vector search
57
+ * }
58
+ * ```
59
+ */
60
+ export function getProviderCapabilities(provider) {
61
+ const port = provider;
62
+ const raw = port.capabilities;
63
+ if (typeof raw === 'function')
64
+ return raw();
65
+ if (raw)
66
+ return raw;
67
+ return DEFAULT_TIER_CAPABILITIES;
68
+ }
69
+ /**
70
+ * Type guard: does this provider satisfy the SVO Action-recording
71
+ * surface ({@link DBProviderSVO.recordAction}, {@link DBProviderSVO.queryActions})?
72
+ *
73
+ * Checks both the runtime methods and the `capabilities.hasActionRecording`
74
+ * flag — adapters should keep them in sync.
75
+ */
76
+ export function hasActionRecording(provider) {
77
+ const p = provider;
78
+ return typeof p.recordAction === 'function' && typeof p.queryActions === 'function';
79
+ }
80
+ /**
81
+ * Type guard: does this provider satisfy the Verb registry surface?
82
+ */
83
+ export function hasVerbRegistry(provider) {
84
+ const p = provider;
85
+ return (typeof p.defineVerb === 'function' &&
86
+ typeof p.getVerb === 'function' &&
87
+ typeof p.listVerbs === 'function');
88
+ }
89
+ /**
90
+ * Type guard: does this provider implement Tier-4 vector search?
91
+ *
92
+ * Checks the runtime method *and* requires the capability declaration
93
+ * to advertise `vectorSearch` — both must agree before callers can
94
+ * route queries.
95
+ */
96
+ export function hasVectorSearch(provider) {
97
+ const p = provider;
98
+ if (typeof p.vectorSearch !== 'function')
99
+ return false;
100
+ const caps = getProviderCapabilities(provider);
101
+ return caps.vectorSearch !== undefined;
102
+ }
103
+ /**
104
+ * Type guard: does this provider implement Tier-3 analytics?
105
+ */
106
+ export function hasAnalytics(provider) {
107
+ const p = provider;
108
+ if (typeof p.analyticsQuery !== 'function')
109
+ return false;
110
+ const caps = getProviderCapabilities(provider);
111
+ return caps.analytics !== undefined;
112
+ }
113
+ //# sourceMappingURL=db-provider-port.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db-provider-port.js","sourceRoot":"","sources":["../src/db-provider-port.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAugBH,gFAAgF;AAChF,+BAA+B;AAC/B,gFAAgF;AAEhF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAA6B;IACjE,OAAO,EAAE,SAAS;IAClB,aAAa,EAAE,WAAW;IAC1B,kBAAkB,EAAE,KAAK;IACzB,eAAe,EAAE,KAAK;CACvB,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAoB;IAC1D,MAAM,IAAI,GAAG,QAA0B,CAAA;IACvC,MAAM,GAAG,GAAG,IAAI,CAAC,YAA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*
4
+ * This module provides a wrapper that uses digital-objects as a storage backend
5
+ * for ai-database. It creates a MemoryProvider from digital-objects and wraps it
6
+ * with the DBProviderAdapter to provide the ai-database DBProvider interface.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { DB } from 'ai-database'
11
+ * import { createDigitalObjectsProvider } from 'ai-database'
12
+ *
13
+ * const provider = createDigitalObjectsProvider()
14
+ *
15
+ * const { db } = DB({
16
+ * User: {
17
+ * name: 'string',
18
+ * email: 'string',
19
+ * }
20
+ * }, { provider })
21
+ *
22
+ * await db.User.create({ name: 'John', email: 'john@example.com' })
23
+ * ```
24
+ *
25
+ * @packageDocumentation
26
+ */
27
+ import type { DBProvider } from './schema/provider.js';
28
+ /**
29
+ * Creates a DBProvider backed by digital-objects storage.
30
+ *
31
+ * This function creates an in-memory DigitalObjectsProvider and wraps it
32
+ * with the DBProviderAdapter to provide the ai-database DBProvider interface.
33
+ *
34
+ * @returns A DBProvider that uses digital-objects as the storage backend
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const provider = createDigitalObjectsProvider()
39
+ *
40
+ * // Use with DB factory
41
+ * const { db } = DB(schema, { provider })
42
+ *
43
+ * // Or use directly
44
+ * await provider.create('User', 'user-1', { name: 'John' })
45
+ * const user = await provider.get('User', 'user-1')
46
+ * ```
47
+ */
48
+ export declare function createDigitalObjectsProvider(): DBProvider;
49
+ //# sourceMappingURL=digital-objects-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"digital-objects-provider.d.ts","sourceRoot":"","sources":["../src/digital-objects-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,4BAA4B,IAAI,UAAU,CAQzD"}