@lpdjs/firestore-repo-service 2.6.58 → 3.0.2

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 (40) hide show
  1. package/README.md +45 -27
  2. package/dist/{create-servers-Cp1dwiBW.d.ts → create-servers-2Hw0pkyz.d.ts} +2 -2
  3. package/dist/{create-servers-vrDTAYk3.d.cts → create-servers-ASLcxpiS.d.cts} +2 -2
  4. package/dist/index.cjs +106 -94
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +3 -3
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.js +106 -94
  9. package/dist/index.js.map +1 -1
  10. package/dist/llms-full.txt +237 -263
  11. package/dist/llms.txt +5 -4
  12. package/dist/{queue-DO0af0iY.d.ts → queue-B9jCT62h.d.cts} +8 -23
  13. package/dist/{queue-LLW6fbO6.d.cts → queue-BWi6TBmf.d.ts} +8 -23
  14. package/dist/servers/index.cjs +104 -92
  15. package/dist/servers/index.cjs.map +1 -1
  16. package/dist/servers/index.d.cts +3 -3
  17. package/dist/servers/index.d.ts +3 -3
  18. package/dist/servers/index.js +104 -92
  19. package/dist/servers/index.js.map +1 -1
  20. package/dist/sync/bigquery.cjs +5 -5
  21. package/dist/sync/bigquery.cjs.map +1 -1
  22. package/dist/sync/bigquery.d.cts +27 -2
  23. package/dist/sync/bigquery.d.ts +27 -2
  24. package/dist/sync/bigquery.js +5 -5
  25. package/dist/sync/bigquery.js.map +1 -1
  26. package/dist/sync/index.cjs +74 -54
  27. package/dist/sync/index.cjs.map +1 -1
  28. package/dist/sync/index.d.cts +62 -16
  29. package/dist/sync/index.d.ts +62 -16
  30. package/dist/sync/index.js +74 -54
  31. package/dist/sync/index.js.map +1 -1
  32. package/dist/sync/meilisearch.cjs +4 -0
  33. package/dist/sync/meilisearch.cjs.map +1 -0
  34. package/dist/sync/meilisearch.d.cts +114 -0
  35. package/dist/sync/meilisearch.d.ts +114 -0
  36. package/dist/sync/meilisearch.js +4 -0
  37. package/dist/sync/meilisearch.js.map +1 -0
  38. package/dist/{types-BaFkMwNb.d.ts → types-BRPhmKFW.d.ts} +106 -44
  39. package/dist/{types-CbNcdNkb.d.cts → types-LZ8dyfBz.d.cts} +106 -44
  40. package/package.json +19 -1
@@ -1,7 +1,8 @@
1
1
  import { b as AuthExtension } from './firebase-auth-Ds5P0kXT.cjs';
2
- import { onDocumentCreated, onDocumentUpdated, onDocumentDeleted } from 'firebase-functions/v2/firestore';
2
+ import { onDocumentWritten } from 'firebase-functions/v2/firestore';
3
3
  import { onRequest, HttpsOptions } from 'firebase-functions/v2/https';
4
4
  import { onMessagePublished, PubSubOptions } from 'firebase-functions/v2/pubsub';
5
+ import { z } from 'zod';
5
6
 
6
7
  /**
7
8
  * Cloud Functions v2 options forwarded to `onMessagePublished()` for every
@@ -16,6 +17,65 @@ type SyncWorkerOptions = Omit<PubSubOptions, "topic">;
16
17
  type AdminHttpsOptions = HttpsOptions;
17
18
  /** A value that can be provided directly or as a lazy factory function. */
18
19
  type OrFactory<T> = T | (() => T);
20
+ /** Result returned by an adapter's healthCheck method. */
21
+ interface SyncHealthResult {
22
+ /** Overall health status for this target */
23
+ healthy: boolean;
24
+ /** Target table or index name */
25
+ targetName: string;
26
+ /** Whether the target table/index exists */
27
+ targetExists: boolean;
28
+ /** Error message if unhealthy */
29
+ error?: string | null;
30
+ /** Adapter-specific health details (e.g. column mismatch for SQL, doc counts for Search) */
31
+ details?: Record<string, unknown>;
32
+ }
33
+ /**
34
+ * Universal adapter interface that the sync worker and admin dashboard call.
35
+ * Implementations exist for BigQuery, Meilisearch, and can be written for
36
+ * PostgreSQL, Elasticsearch, Typesense, etc.
37
+ */
38
+ interface SyncAdapter {
39
+ /** Unique adapter identifier, e.g. "bigquery", "meilisearch", "postgres" */
40
+ readonly name: string;
41
+ /** Check whether the target storage (table, index, etc.) exists */
42
+ targetExists(targetName: string): Promise<boolean>;
43
+ /**
44
+ * Upsert rows/documents into target storage.
45
+ * @param targetName - SQL table name or Search index UID
46
+ * @param items - Serialized rows / documents
47
+ * @param primaryKey - Column or field name used as primary key
48
+ */
49
+ upsert(targetName: string, items: Record<string, unknown>[], primaryKey: string): Promise<void>;
50
+ /**
51
+ * Delete rows/documents by primary key IDs.
52
+ * @param targetName - SQL table name or Search index UID
53
+ * @param primaryKey - Column or field name used as primary key
54
+ * @param ids - Array of document / row IDs to delete
55
+ */
56
+ delete(targetName: string, primaryKey: string, ids: string[]): Promise<void>;
57
+ /**
58
+ * Optional: prepare/migrate target schema or create target if missing.
59
+ * For SQL: creates table and adds missing columns.
60
+ * For Meilisearch: creates index and configures filterable/sortable attributes.
61
+ */
62
+ ensureTarget?(options: {
63
+ targetName: string;
64
+ primaryKey: string;
65
+ schema?: z.ZodObject<any>;
66
+ exclude?: string[];
67
+ columnMap?: Record<string, string>;
68
+ }): Promise<void>;
69
+ /**
70
+ * Optional: custom health check for the admin dashboard.
71
+ */
72
+ healthCheck?(options: {
73
+ targetName: string;
74
+ primaryKey: string;
75
+ schema?: z.ZodObject<any>;
76
+ repoConfig?: RepoSyncConfig<string>;
77
+ }): Promise<SyncHealthResult>;
78
+ }
19
79
  /** A single column in a SQL table. */
20
80
  interface SqlColumn {
21
81
  /** Column name (snake_case recommended for SQL) */
@@ -53,7 +113,7 @@ interface SqlDialect {
53
113
  * and dialect-specific SQL types.
54
114
  */
55
115
  type LogicalType = "string" | "number" | "bigint" | "boolean" | "timestamp" | "json" | "text";
56
- /** Operations that can be synced to SQL. */
116
+ /** Operations that can be synced to target storage. */
57
117
  type SyncOperation = "INSERT" | "UPSERT" | "DELETE";
58
118
  /** A single sync event produced by a Firestore trigger and consumed by the worker. */
59
119
  interface SyncEvent {
@@ -88,14 +148,12 @@ interface SyncEvent {
88
148
  }
89
149
  /**
90
150
  * Abstract SQL adapter that the sync worker calls.
91
- * Each target database provides a concrete implementation.
151
+ * Extends the universal {@link SyncAdapter}.
92
152
  */
93
- interface SqlAdapter {
153
+ interface SqlAdapter extends SyncAdapter {
94
154
  /** The SQL dialect used by this adapter */
95
155
  readonly dialect: SqlDialect;
96
- /**
97
- * Check whether a table exists.
98
- */
156
+ /** Check whether a table exists. */
99
157
  tableExists(tableName: string): Promise<boolean>;
100
158
  /**
101
159
  * Return the column names currently present in the table.
@@ -108,26 +166,20 @@ interface SqlAdapter {
108
166
  * `number` to `string`) and fail fast with an explicit error rather than
109
167
  * letting MERGE/Storage Write fail silently on every event.
110
168
  *
111
- * Optional for backwards-compat: if the adapter does not implement it,
169
+ * Optional: if the adapter does not implement it,
112
170
  * the worker skips type-drift detection but still adds new columns.
113
171
  */
114
172
  getTableColumnsWithTypes?(tableName: string): Promise<Map<string, string>>;
115
- /**
116
- * Create a table. Should be idempotent (IF NOT EXISTS).
117
- */
173
+ /** Create a table. Should be idempotent (IF NOT EXISTS). */
118
174
  createTable(table: SqlTableDef): Promise<void>;
119
- /**
120
- * Insert rows (append-only, no dedup).
121
- */
175
+ /** Insert rows (append-only, no dedup). */
122
176
  insertRows(tableName: string, rows: Record<string, unknown>[]): Promise<void>;
123
177
  /**
124
178
  * Upsert rows (INSERT … ON CONFLICT UPDATE / MERGE).
125
179
  * `primaryKey` identifies the column(s) used for matching.
126
180
  */
127
181
  upsertRows(tableName: string, rows: Record<string, unknown>[], primaryKey: string): Promise<void>;
128
- /**
129
- * Delete rows by primary-key values.
130
- */
182
+ /** Delete rows by primary-key values. */
131
183
  deleteRows(tableName: string, primaryKey: string, ids: string[]): Promise<void>;
132
184
  /**
133
185
  * Add columns to an existing table.
@@ -150,11 +202,11 @@ interface SqlAdapter {
150
202
  }
151
203
  /** Per-repository sync options, typed to the repo's field names. */
152
204
  interface RepoSyncConfig<F extends string = string> {
153
- /** Override the SQL table name (default: repo name) */
205
+ /** Override the SQL table name or Search index UID (default: repo name) */
154
206
  tableName?: string;
155
- /** Fields to exclude from the SQL table */
207
+ /** Fields to exclude from the synced document */
156
208
  exclude?: F[];
157
- /** Field name overrides: Zod field → SQL column name */
209
+ /** Field name overrides: Zod field → Target column/field name */
158
210
  columnMap?: Partial<Record<F, string>>;
159
211
  /**
160
212
  * Explicit Firestore document path pattern for triggers.
@@ -163,6 +215,11 @@ interface RepoSyncConfig<F extends string = string> {
163
215
  * @example "posts/{postId}/comments/{docId}"
164
216
  */
165
217
  triggerPath?: string;
218
+ /**
219
+ * Optional list of target adapter names for this repo (e.g. `["bigquery", "meilisearch"]`).
220
+ * When omitted or empty, the repo is synced to all configured adapters.
221
+ */
222
+ adapters?: string[];
166
223
  }
167
224
  /**
168
225
  * Extract field names from a repo value.
@@ -177,22 +234,24 @@ type ExtractRepoFields<R> = R extends {
177
234
  } ? string & keyof S : R extends {
178
235
  type: infer T;
179
236
  } ? string & keyof T : string;
180
- /** Keys of repos where `_isGroup` is `true`. */
237
+ /** Keys of repos where `_isGroup` or `isGroup` is `true`. */
181
238
  type GroupRepoKeys<M> = {
182
239
  [K in string & keyof M]: M[K] extends {
183
240
  _isGroup: true;
241
+ } ? K : M[K] extends {
242
+ isGroup: true;
184
243
  } ? K : never;
185
244
  }[string & keyof M];
186
245
  /** Keys of repos where `_isGroup` is NOT `true`. */
187
246
  type NonGroupRepoKeys<M> = Exclude<string & keyof M, GroupRepoKeys<M>>;
188
247
  /**
189
248
  * Typed per-repo sync config map.
190
- * - Collection-group repos (`isGroup: true`): entry is **required** and
191
- * `triggerPath` is mandatory.
249
+ * - Collection-group repos (`isGroup: true`): entry is optional, but if provided,
250
+ * `triggerPath` is mandatory (since collection groups span multiple paths).
192
251
  * - Regular repos: entry is optional, all fields optional.
193
252
  */
194
253
  type TypedRepoSyncConfigs<M> = {
195
- [K in GroupRepoKeys<M>]: RepoSyncConfig<ExtractRepoFields<M[K]>> & {
254
+ [K in GroupRepoKeys<M>]?: RepoSyncConfig<ExtractRepoFields<M[K]>> & {
196
255
  triggerPath: string;
197
256
  };
198
257
  } & {
@@ -200,9 +259,7 @@ type TypedRepoSyncConfigs<M> = {
200
259
  };
201
260
  /** Firestore trigger constructors from `firebase-functions/v2/firestore`. */
202
261
  interface FirestoreTriggersDep {
203
- onDocumentCreated: typeof onDocumentCreated;
204
- onDocumentUpdated: typeof onDocumentUpdated;
205
- onDocumentDeleted: typeof onDocumentDeleted;
262
+ onDocumentWritten: typeof onDocumentWritten;
206
263
  }
207
264
  /** PubSub handler from `firebase-functions/v2/pubsub`. */
208
265
  interface PubSubHandlerDep {
@@ -238,13 +295,20 @@ interface SyncTriggersConfig<M = Record<string, any>> {
238
295
  interface SyncWorkerConfig<M = Record<string, any>> {
239
296
  /** External dependencies — PubSub handler + client */
240
297
  deps: Pick<SyncDeps, "pubsubHandler" | "pubsub">;
241
- /** SQL adapter to flush data to */
242
- adapter: SqlAdapter;
298
+ /**
299
+ * Adapter(s) to flush data to. Accepts a single adapter, an array of adapters,
300
+ * or a lazy factory returning one or more adapters.
301
+ */
302
+ adapter?: OrFactory<SyncAdapter | SyncAdapter[]>;
303
+ /**
304
+ * Explicit array of adapters to flush data to.
305
+ */
306
+ adapters?: OrFactory<SyncAdapter>[];
243
307
  /** Max rows per flush batch (default: 100) */
244
308
  batchSize?: number;
245
309
  /** Flush interval in ms (default: 5000) */
246
310
  flushIntervalMs?: number;
247
- /** Auto-create/migrate tables on first event (default: false) */
311
+ /** Auto-create/migrate tables or indexes on first event (default: false) */
248
312
  autoMigrate?: boolean;
249
313
  /** PubSub topic prefix (default: "firestore-sync") */
250
314
  topicPrefix?: string;
@@ -258,11 +322,6 @@ interface SyncWorkerConfig<M = Record<string, any>> {
258
322
  * Cloud Functions v2 options forwarded to `onMessagePublished()` for every
259
323
  * worker handler. Use to tune `concurrency`, `maxInstances`, `minInstances`,
260
324
  * `memory`, `timeoutSeconds`, `region`, `cpu`, etc.
261
- *
262
- * Example:
263
- * ```ts
264
- * workerOptions: { concurrency: 10, maxInstances: 10, memory: "512MiB" }
265
- * ```
266
325
  */
267
326
  workerOptions?: SyncWorkerOptions;
268
327
  /** Per-repo overrides */
@@ -289,9 +348,9 @@ interface adminsyncBasicAuth {
289
348
  interface adminsyncFeaturesFlag {
290
349
  /** Allow force-syncing an entire collection (default: false) */
291
350
  manualSync?: boolean;
292
- /** Schema health check: expected vs actual SQL columns (default: false) */
351
+ /** Schema health check: expected vs actual storage structure (default: false) */
293
352
  healthCheck?: boolean;
294
- /** GCP config check: verify APIs, topics, tables, and IAM (default: false) */
353
+ /** GCP / target config check: verify APIs, topics, targets, and IAM (default: false) */
295
354
  configCheck?: boolean;
296
355
  }
297
356
  /**
@@ -339,18 +398,21 @@ interface FirestoreSyncConfig<M = Record<string, any>> {
339
398
  pubsub: OrFactory<PubSubClientDep>;
340
399
  };
341
400
  /**
342
- * SQL adapter to flush data to.
343
- * Can be a factory `() => adapter` for lazy initialization
344
- * (avoids connecting to BigQuery / SQL at module-load time).
401
+ * Sync adapter(s) to flush data to (e.g. BigQueryAdapter, MeilisearchAdapter).
402
+ * Can be a single adapter, an array of adapters, or a lazy factory.
403
+ */
404
+ adapter?: OrFactory<SyncAdapter | SyncAdapter[]>;
405
+ /**
406
+ * Explicit array of adapters to flush data to.
345
407
  */
346
- adapter: OrFactory<SqlAdapter>;
408
+ adapters?: OrFactory<SyncAdapter>[];
347
409
  /** PubSub topic name prefix (topics will be `{prefix}-{repoName}`) */
348
410
  topicPrefix?: string;
349
411
  /** Max rows per flush batch (default: 100) */
350
412
  batchSize?: number;
351
413
  /** Flush interval in ms (default: 5000) */
352
414
  flushIntervalMs?: number;
353
- /** Auto-create/migrate tables on first event (default: false) */
415
+ /** Auto-create/migrate tables or indexes on first event (default: false) */
354
416
  autoMigrate?: boolean;
355
417
  /**
356
418
  * Cloud Functions v2 options forwarded to `onMessagePublished()` for every
@@ -359,7 +421,7 @@ interface FirestoreSyncConfig<M = Record<string, any>> {
359
421
  */
360
422
  workerOptions?: SyncWorkerOptions;
361
423
  /**
362
- * Optional sync admin endpoint. When provided, a `adminsync` handler is
424
+ * Optional sync admin endpoint. When provided, an `adminsync` handler is
363
425
  * added to `sync.functions` exposing health-check, force-sync, and queue
364
426
  * inspection endpoints behind authentication.
365
427
  */
@@ -368,4 +430,4 @@ interface FirestoreSyncConfig<M = Record<string, any>> {
368
430
  repos?: TypedRepoSyncConfigs<M>;
369
431
  }
370
432
 
371
- export type { AdminHttpsOptions as A, FirestoreSyncConfig as F, GenerateDDLConfig as G, LogicalType as L, OrFactory as O, PubSubClientDep as P, RepoSyncConfig as R, SyncEvent as S, SqlAdapter as a, SqlDialect as b, SqlTableDef as c, SqlColumn as d, adminsyncConfig as e, SyncTriggersConfig as f, SyncWorkerConfig as g, FirestoreTriggersDep as h, PubSubHandlerDep as i, SyncDeps as j, SyncOperation as k, SyncWorkerOptions as l, adminsyncBasicAuth as m, adminsyncFeaturesFlag as n };
433
+ export type { AdminHttpsOptions as A, FirestoreSyncConfig as F, GenerateDDLConfig as G, LogicalType as L, OrFactory as O, PubSubClientDep as P, RepoSyncConfig as R, SyncEvent as S, SyncAdapter as a, SqlAdapter as b, SqlDialect as c, SyncHealthResult as d, SqlTableDef as e, SqlColumn as f, adminsyncConfig as g, SyncTriggersConfig as h, SyncWorkerConfig as i, FirestoreTriggersDep as j, PubSubHandlerDep as k, SyncDeps as l, SyncOperation as m, SyncWorkerOptions as n, adminsyncBasicAuth as o, adminsyncFeaturesFlag as p };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lpdjs/firestore-repo-service",
3
- "version": "2.6.58",
3
+ "version": "3.0.2",
4
4
  "workspaces": [
5
5
  "test/functions"
6
6
  ],
@@ -40,6 +40,16 @@
40
40
  "default": "./dist/sync/bigquery.js"
41
41
  }
42
42
  },
43
+ "./sync/meilisearch": {
44
+ "require": {
45
+ "types": "./dist/sync/meilisearch.d.cts",
46
+ "default": "./dist/sync/meilisearch.cjs"
47
+ },
48
+ "import": {
49
+ "types": "./dist/sync/meilisearch.d.ts",
50
+ "default": "./dist/sync/meilisearch.js"
51
+ }
52
+ },
43
53
  "./history": {
44
54
  "require": {
45
55
  "types": "./dist/history/index.d.cts",
@@ -124,6 +134,9 @@
124
134
  "sync/bigquery": [
125
135
  "./dist/sync/bigquery.d.ts"
126
136
  ],
137
+ "sync/meilisearch": [
138
+ "./dist/sync/meilisearch.d.ts"
139
+ ],
127
140
  "history": [
128
141
  "./dist/history/index.d.ts"
129
142
  ]
@@ -201,6 +214,7 @@
201
214
  "@types/express": "^4.17.0 || ^5.0.0",
202
215
  "firebase-admin": "^12.0.0 || ^13.0.0 || ^14.0.0",
203
216
  "firebase-functions": "^5.0.0 || ^6.0.0 || ^7.0.0",
217
+ "meilisearch": "^0.47.0 || ^0.48.0 || ^0.49.0",
204
218
  "typescript": "^5.0.0",
205
219
  "zod": "^4"
206
220
  },
@@ -219,6 +233,9 @@
219
233
  },
220
234
  "@google-cloud/pubsub": {
221
235
  "optional": true
236
+ },
237
+ "meilisearch": {
238
+ "optional": true
222
239
  }
223
240
  },
224
241
  "devDependencies": {
@@ -230,6 +247,7 @@
230
247
  "concurrently": "^9.2.1",
231
248
  "firebase-admin": "^13.8.0",
232
249
  "firebase-functions": "^7.2.5",
250
+ "meilisearch": "^0.47.0",
233
251
  "tsup": "^8.5.1",
234
252
  "typescript": "^5.9.3",
235
253
  "wait-on": "^9.0.5",