@lunora/bindings 1.0.0-alpha.7 → 1.0.0-alpha.9

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,9 +1,9 @@
1
1
  /**
2
- * Minimal structural projection of `VectorizeIndex` so unit tests can pass a
3
- * plain-object double and the real Cloudflare binding satisfies the same shape.
4
- * Mirrors the surface documented at
5
- * https://developers.cloudflare.com/vectorize/reference/client-api/.
6
- */
2
+ * Minimal structural projection of `VectorizeIndex` so unit tests can pass a
3
+ * plain-object double and the real Cloudflare binding satisfies the same shape.
4
+ * Mirrors the surface documented at
5
+ * https://developers.cloudflare.com/vectorize/reference/client-api/.
6
+ */
7
7
  interface VectorizeIndexLike {
8
8
  deleteByIds: (ids: ReadonlyArray<string>) => Promise<VectorizeDeleteMutation>;
9
9
  describe?: () => Promise<VectorizeIndexDetails>;
@@ -51,17 +51,17 @@ interface VectorizeIndexDetails {
51
51
  vectorsCount: number;
52
52
  }
53
53
  /**
54
- * Bring-your-own-embedder: a user-supplied async fn that converts a single
55
- * source value (a row, a chunk, an arbitrary string) into a numeric vector.
56
- * The runtime calls this at upsert time so we don't couple to any provider.
57
- */
54
+ * Bring-your-own-embedder: a user-supplied async fn that converts a single
55
+ * source value (a row, a chunk, an arbitrary string) into a numeric vector.
56
+ * The runtime calls this at upsert time so we don't couple to any provider.
57
+ */
58
58
  type EmbedFunction<TInput = unknown> = (input: TInput) => Promise<ReadonlyArray<number>> | ReadonlyArray<number>;
59
59
  interface LunoraVectorsOptions {
60
60
  /**
61
- * Map of logical index name -> Vectorize binding. Most apps wire one
62
- * binding per index; multi-index apps register all of them here so calls
63
- * like `vectors.query("docs-body", ...)` can resolve to the right binding.
64
- */
61
+ * Map of logical index name -> Vectorize binding. Most apps wire one
62
+ * binding per index; multi-index apps register all of them here so calls
63
+ * like `vectors.query("docs-body", ...)` can resolve to the right binding.
64
+ */
65
65
  indexes: Record<string, VectorizeIndexLike>;
66
66
  }
67
67
  interface UpsertInput<TInput = unknown> {
@@ -91,9 +91,9 @@ interface LunoraVectors {
91
91
  upsertMany: <TInput>(indexName: string, inputs: ReadonlyArray<UpsertInput<TInput>>) => Promise<VectorizeUpsertMutation>;
92
92
  }
93
93
  /**
94
- * `(input: string) => vector`. Matches `@lunora/server`'s `VectorEmbedder` so
95
- * the bridged surface is assignable to the server's `VectorSearch` contract.
96
- */
94
+ * `(input: string) => vector`. Matches `@lunora/server`'s `VectorEmbedder` so
95
+ * the bridged surface is assignable to the server's `VectorSearch` contract.
96
+ */
97
97
  type VectorEmbedderLike = (input: string) => Promise<ReadonlyArray<number>> | ReadonlyArray<number>;
98
98
  interface VectorMatchLike {
99
99
  id: string;
@@ -115,11 +115,11 @@ interface VectorQueryInputLike {
115
115
  input?: string;
116
116
  namespace?: string;
117
117
  /**
118
- * How much stored metadata to return on matches. Defaults to `"indexed"`
119
- * (only fields declared as index metadata) rather than `"all"`, so a query
120
- * never leaks arbitrary stored fields by default. Callers that genuinely
121
- * need every field opt in with `"all"`; pass `"none"` to drop metadata.
122
- */
118
+ * How much stored metadata to return on matches. Defaults to `"indexed"`
119
+ * (only fields declared as index metadata) rather than `"all"`, so a query
120
+ * never leaks arbitrary stored fields by default. Callers that genuinely
121
+ * need every field opt in with `"all"`; pass `"none"` to drop metadata.
122
+ */
123
123
  returnMetadata?: "none" | "indexed" | "all";
124
124
  topK?: number;
125
125
  vector?: ReadonlyArray<number>;
@@ -132,10 +132,10 @@ interface VectorUpsertInputLike {
132
132
  namespace?: string;
133
133
  }
134
134
  /**
135
- * Structural mirror of `@lunora/server`'s `VectorSearch`. Declared here so the
136
- * adapter never imports `@lunora/server` (keeps the dependency edge one-way:
137
- * the generated DO depends on both, neither depends on the other).
138
- */
135
+ * Structural mirror of `@lunora/server`'s `VectorSearch`. Declared here so the
136
+ * adapter never imports `@lunora/server` (keeps the dependency edge one-way:
137
+ * the generated DO depends on both, neither depends on the other).
138
+ */
139
139
  interface VectorSearchLike {
140
140
  deleteByIds: (indexName: string, ids: ReadonlyArray<string>) => Promise<void>;
141
141
  getByIds: (indexName: string, ids: ReadonlyArray<string>) => Promise<ReadonlyArray<VectorRecordLike>>;
@@ -144,11 +144,11 @@ interface VectorSearchLike {
144
144
  upsertNow: (indexName: string, input: VectorUpsertInputLike) => Promise<void>;
145
145
  }
146
146
  /**
147
- * Bridge `LunoraVectors` (returns Vectorize mutation receipts) to the server's
148
- * `VectorSearch` contract (void mutations, server match/record shapes). Both
149
- * `upsert` and `upsertNow` write inline — this design has no post-commit queue,
150
- * so "now" and "deferred" collapse to the same synchronous call.
151
- */
147
+ * Bridge `LunoraVectors` (returns Vectorize mutation receipts) to the server's
148
+ * `VectorSearch` contract (void mutations, server match/record shapes). Both
149
+ * `upsert` and `upsertNow` write inline — this design has no post-commit queue,
150
+ * so "now" and "deferred" collapse to the same synchronous call.
151
+ */
152
152
  declare const createContextVectors: (lunora: LunoraVectors) => VectorSearchLike;
153
153
  /** A single row mutation observed by the ctx-db, fed to {@link createVectorSyncHook}. */
154
154
  interface WriteEvent {
@@ -176,43 +176,43 @@ interface VectorIndexDefinitionLike {
176
176
  table: string;
177
177
  }
178
178
  /**
179
- * Structural mirror of `@lunora/server`'s `Schema`, narrowed to the fields the
180
- * sync hook reads. Carries live `embed`/`select` closures, so the hook must be
181
- * built from the imported `schema` value — never a serialized descriptor.
182
- */
179
+ * Structural mirror of `@lunora/server`'s `Schema`, narrowed to the fields the
180
+ * sync hook reads. Carries live `embed`/`select` closures, so the hook must be
181
+ * built from the imported `schema` value — never a serialized descriptor.
182
+ */
183
183
  interface SchemaLike {
184
184
  tables: Record<string, TableDefinitionLike>;
185
185
  vectorIndexes: Record<string, VectorIndexDefinitionLike>;
186
186
  }
187
187
  /**
188
- * Build a {@link WriteHook} that keeps Vectorize in sync with row writes. On
189
- * insert/update it embeds each matching index's source (Shape A `row[field]`,
190
- * Shape B `select(row)`) and upserts; on delete it removes the row's id from
191
- * every index sourced from the table. Runs inline within the write path.
192
- *
193
- * Tenant isolation — IMPORTANT: Vectorize indexes are account-global and shared
194
- * by every shard DO. Without a `namespace`, a multi-tenant sharded app has NO
195
- * isolation between tenants in the vector index — one tenant's vectors are
196
- * queryable by another (ids/scores leak existence + semantic similarity even
197
- * when no metadata is indexed). The caller MUST pass `options.namespace` (the
198
- * shard / tenant key) so upserts are scoped, and MUST apply the same namespace
199
- * on the query side — query-side namespace filtering is mandatory, not optional.
200
- * The namespace is threaded onto upserts here; pass it from the shard DO that
201
- * owns this hook. Any namespace-less sync emits a one-time-per-index dev warning
202
- * (regardless of whether metadata is present); a genuinely single-tenant app
203
- * suppresses it with `allowSharedNamespace: true`.
204
- *
205
- * Consistency — IMPORTANT: this hook runs inline within the mutation but talks
206
- * to Vectorize, which is external and non-transactional. The per-index calls
207
- * fan out; if one fails after others have already applied, the SQLite write may
208
- * roll back while the applied Vectorize mutations cannot — leaving SQLite and
209
- * Vectorize diverged. We mitigate, not eliminate: upserts/deletes are
210
- * idempotent (keyed by row id), so a retry of the same write converges; and on
211
- * a fan-out failure we attempt a best-effort compensating delete of the row's
212
- * id from every affected index before re-throwing. A delete after a failed
213
- * upsert can itself fail — this is best-effort, the authoritative recovery is
214
- * re-running the (idempotent) write.
215
- */
188
+ * Build a {@link WriteHook} that keeps Vectorize in sync with row writes. On
189
+ * insert/update it embeds each matching index's source (Shape A `row[field]`,
190
+ * Shape B `select(row)`) and upserts; on delete it removes the row's id from
191
+ * every index sourced from the table. Runs inline within the write path.
192
+ *
193
+ * Tenant isolation — IMPORTANT: Vectorize indexes are account-global and shared
194
+ * by every shard DO. Without a `namespace`, a multi-tenant sharded app has NO
195
+ * isolation between tenants in the vector index — one tenant's vectors are
196
+ * queryable by another (ids/scores leak existence + semantic similarity even
197
+ * when no metadata is indexed). The caller MUST pass `options.namespace` (the
198
+ * shard / tenant key) so upserts are scoped, and MUST apply the same namespace
199
+ * on the query side — query-side namespace filtering is mandatory, not optional.
200
+ * The namespace is threaded onto upserts here; pass it from the shard DO that
201
+ * owns this hook. Any namespace-less sync emits a one-time-per-index dev warning
202
+ * (regardless of whether metadata is present); a genuinely single-tenant app
203
+ * suppresses it with `allowSharedNamespace: true`.
204
+ *
205
+ * Consistency — IMPORTANT: this hook runs inline within the mutation but talks
206
+ * to Vectorize, which is external and non-transactional. The per-index calls
207
+ * fan out; if one fails after others have already applied, the SQLite write may
208
+ * roll back while the applied Vectorize mutations cannot — leaving SQLite and
209
+ * Vectorize diverged. We mitigate, not eliminate: upserts/deletes are
210
+ * idempotent (keyed by row id), so a retry of the same write converges; and on
211
+ * a fan-out failure we attempt a best-effort compensating delete of the row's
212
+ * id from every affected index before re-throwing. A delete after a failed
213
+ * upsert can itself fail — this is best-effort, the authoritative recovery is
214
+ * re-running the (idempotent) write.
215
+ */
216
216
  declare const createVectorSyncHook: (options: {
217
217
  allowSharedNamespace?: boolean;
218
218
  namespace?: string;
@@ -220,11 +220,11 @@ declare const createVectorSyncHook: (options: {
220
220
  vectors: VectorSearchLike;
221
221
  }) => WriteHook;
222
222
  /**
223
- * One vector index as the generated `LUNORA_VECTOR_INDEXES` registry describes
224
- * it — the static schema shape, independent of any live binding. Structurally
225
- * the codegen `LunoraVectorIndex`, restated here so this package stays free of a
226
- * dependency on `@lunora/codegen`.
227
- */
223
+ * One vector index as the generated `LUNORA_VECTOR_INDEXES` registry describes
224
+ * it — the static schema shape, independent of any live binding. Structurally
225
+ * the codegen `LunoraVectorIndex`, restated here so this package stays free of a
226
+ * dependency on `@lunora/codegen`.
227
+ */
228
228
  interface VectorIndexRegistryEntry {
229
229
  dimensions?: number;
230
230
  field?: string;
@@ -245,9 +245,9 @@ interface VectorAdminQueryMatch {
245
245
  score: number;
246
246
  }
247
247
  /**
248
- * The admin introspector the worker passes to `createWorker({ vectorIntrospector })`.
249
- * `queryIndex` is present only when at least one embedder is wired.
250
- */
248
+ * The admin introspector the worker passes to `createWorker({ vectorIntrospector })`.
249
+ * `queryIndex` is present only when at least one embedder is wired.
250
+ */
251
251
  interface VectorAdminIntrospector {
252
252
  listIndexes: () => Promise<VectorAdminIndexSummary[]>;
253
253
  queryIndex?: (options: {
@@ -260,11 +260,11 @@ interface VectorAdminIntrospector {
260
260
  }
261
261
  interface VectorAdminIntrospectorOptions {
262
262
  /**
263
- * Per-index embedder (text → vector), keyed by index name. Supply the
264
- * schema's embedders to enable studio similarity queries; omit it (or leave
265
- * an index out) and that index lists read-only — `queryIndex` is withheld
266
- * entirely when no embedder is provided.
267
- */
263
+ * Per-index embedder (text → vector), keyed by index name. Supply the
264
+ * schema's embedders to enable studio similarity queries; omit it (or leave
265
+ * an index out) and that index lists read-only — `queryIndex` is withheld
266
+ * entirely when no embedder is provided.
267
+ */
268
268
  embedders?: Record<string, EmbedFunction<string>>;
269
269
  /** Live Vectorize bindings keyed by index name, from `env`. */
270
270
  indexes: Record<string, VectorizeIndexLike>;
@@ -272,14 +272,14 @@ interface VectorAdminIntrospectorOptions {
272
272
  registry: ReadonlyArray<VectorIndexRegistryEntry>;
273
273
  }
274
274
  /**
275
- * Build the read-only Vectorize introspector backing the studio's vector
276
- * browser. `listIndexes` returns the static registry, enriching each entry with
277
- * live `describe()` stats when the matching binding is present (a binding that
278
- * throws or lacks `describe` degrades to the static shape rather than failing
279
- * the whole list). `queryIndex` embeds the query text via the index's embedder
280
- * and runs an ANN search; it is omitted when no embedders are configured, so the
281
- * worker reports `VECTOR_QUERY_UNSUPPORTED` rather than half-answering.
282
- */
275
+ * Build the read-only Vectorize introspector backing the studio's vector
276
+ * browser. `listIndexes` returns the static registry, enriching each entry with
277
+ * live `describe()` stats when the matching binding is present (a binding that
278
+ * throws or lacks `describe` degrades to the static shape rather than failing
279
+ * the whole list). `queryIndex` embeds the query text via the index's embedder
280
+ * and runs an ANN search; it is omitted when no embedders are configured, so the
281
+ * worker reports `VECTOR_QUERY_UNSUPPORTED` rather than half-answering.
282
+ */
283
283
  declare const createVectorAdminIntrospector: (options: VectorAdminIntrospectorOptions) => VectorAdminIntrospector;
284
284
  declare const createVectors: (options: LunoraVectorsOptions) => LunoraVectors;
285
285
  export { type EmbedFunction, type LunoraVectors, type LunoraVectorsOptions, type QueryInput, type SchemaLike, type TableDefinitionLike, type TableVectorIndexLike, type UpsertInput, type VectorAdminIndexSummary, type VectorAdminIntrospector, type VectorAdminIntrospectorOptions, type VectorAdminQueryMatch, type VectorEmbedderLike, type VectorIndexDefinitionLike, type VectorIndexRegistryEntry, type VectorMatchLike, type VectorMatchesLike, type VectorMetric, type VectorQueryInputLike, type VectorRecordLike, type VectorSearchLike, type VectorUpsertInputLike, type VectorizeDeleteMutation, type VectorizeIndexDetails, type VectorizeIndexLike, type VectorizeMatch, type VectorizeMatches, type VectorizeQueryOptions, type VectorizeUpsertMutation, type VectorizeVector, type WriteEvent, type WriteHook, createContextVectors, createVectorAdminIntrospector, createVectorSyncHook, createVectors };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/bindings",
3
- "version": "1.0.0-alpha.7",
3
+ "version": "1.0.0-alpha.9",
4
4
  "description": "Lightweight Cloudflare binding helpers for Lunora — ctx.kv, ctx.images, ctx.analytics, ctx.pipelines, ctx.vectors, ctx.r2sql — one install, per-binding subpaths",
5
5
  "keywords": [
6
6
  "analytics",
@@ -64,7 +64,7 @@
64
64
  "access": "public"
65
65
  },
66
66
  "dependencies": {
67
- "@lunora/errors": "1.0.0-alpha.4"
67
+ "@lunora/errors": "1.0.0-alpha.6"
68
68
  },
69
69
  "engines": {
70
70
  "node": "^22.15.0 || >=24.11.0"