@lpdjs/firestore-repo-service 2.6.57 → 3.0.1

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 (64) hide show
  1. package/README.md +45 -27
  2. package/dist/{create-servers-BxkVVkg9.d.cts → create-servers-Cbvzs_ou.d.cts} +5 -5
  3. package/dist/{create-servers-B84cbslf.d.ts → create-servers-aWdDTcSu.d.ts} +5 -5
  4. package/dist/{firebase-auth-DZ8lb2Ec.d.cts → firebase-auth-Ds5P0kXT.d.cts} +1 -1
  5. package/dist/{firebase-auth-DZ8lb2Ec.d.ts → firebase-auth-Ds5P0kXT.d.ts} +1 -1
  6. package/dist/index.cjs +97 -85
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +9 -9
  9. package/dist/index.d.ts +9 -9
  10. package/dist/index.js +97 -85
  11. package/dist/index.js.map +1 -1
  12. package/dist/llms-full.txt +237 -263
  13. package/dist/llms.txt +5 -4
  14. package/dist/{openapi-BpbfjSHK.d.ts → openapi-BTu_1vSc.d.ts} +1 -1
  15. package/dist/{openapi-DG7aQUlX.d.cts → openapi-CoKsSOIU.d.cts} +1 -1
  16. package/dist/{queue-B4uwef6c.d.ts → queue-BQxyuEXb.d.ts} +8 -23
  17. package/dist/{queue-CQyWCQBk.d.cts → queue-CMiKvIW1.d.cts} +8 -23
  18. package/dist/rules-B3b-BZLf.d.cts +30 -0
  19. package/dist/rules-BJMT0N0i.d.ts +30 -0
  20. package/dist/servers/admin/index.d.cts +402 -6
  21. package/dist/servers/admin/index.d.ts +402 -6
  22. package/dist/servers/auth/index.d.cts +1 -1
  23. package/dist/servers/auth/index.d.ts +1 -1
  24. package/dist/servers/crud/index.cjs +2 -2
  25. package/dist/servers/crud/index.cjs.map +1 -1
  26. package/dist/servers/crud/index.d.cts +7 -6
  27. package/dist/servers/crud/index.d.ts +7 -6
  28. package/dist/servers/crud/index.js +2 -2
  29. package/dist/servers/crud/index.js.map +1 -1
  30. package/dist/servers/hono/index.d.cts +3 -3
  31. package/dist/servers/hono/index.d.ts +3 -3
  32. package/dist/servers/index.cjs +106 -94
  33. package/dist/servers/index.cjs.map +1 -1
  34. package/dist/servers/index.d.cts +10 -9
  35. package/dist/servers/index.d.ts +10 -9
  36. package/dist/servers/index.js +106 -94
  37. package/dist/servers/index.js.map +1 -1
  38. package/dist/sync/bigquery.cjs +5 -5
  39. package/dist/sync/bigquery.cjs.map +1 -1
  40. package/dist/sync/bigquery.d.cts +28 -3
  41. package/dist/sync/bigquery.d.ts +28 -3
  42. package/dist/sync/bigquery.js +5 -5
  43. package/dist/sync/bigquery.js.map +1 -1
  44. package/dist/sync/index.cjs +74 -54
  45. package/dist/sync/index.cjs.map +1 -1
  46. package/dist/sync/index.d.cts +63 -17
  47. package/dist/sync/index.d.ts +63 -17
  48. package/dist/sync/index.js +74 -54
  49. package/dist/sync/index.js.map +1 -1
  50. package/dist/sync/meilisearch.cjs +4 -0
  51. package/dist/sync/meilisearch.cjs.map +1 -0
  52. package/dist/sync/meilisearch.d.cts +114 -0
  53. package/dist/sync/meilisearch.d.ts +114 -0
  54. package/dist/sync/meilisearch.js +4 -0
  55. package/dist/sync/meilisearch.js.map +1 -0
  56. package/dist/{types-CE-EfugW.d.cts → types-B2e-T8EM.d.cts} +160 -8
  57. package/dist/{types-B4dMmfet.d.cts → types-BIZz3sxN.d.cts} +1 -1
  58. package/dist/{types-DT7Nypd_.d.ts → types-BbFZ57eK.d.ts} +101 -41
  59. package/dist/{types-DyKJJ9UQ.d.ts → types-DSMiiOrU.d.ts} +1 -1
  60. package/dist/{types-cY03CMya.d.ts → types-XRjVKN9r.d.ts} +160 -8
  61. package/dist/{types-BwH1C-wi.d.cts → types-zFrp8RnM.d.cts} +101 -41
  62. package/package.json +19 -1
  63. package/dist/index-D47y5giY.d.ts +0 -469
  64. package/dist/index-dW_7jrlK.d.cts +0 -469
@@ -1,7 +1,8 @@
1
- import { A as AuthExtension } from './firebase-auth-DZ8lb2Ec.cjs';
2
- import { onDocumentCreated, onDocumentUpdated, onDocumentDeleted } from 'firebase-functions/v2/firestore';
1
+ import { b as AuthExtension } from './firebase-auth-Ds5P0kXT.cjs';
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.
@@ -200,9 +257,7 @@ type TypedRepoSyncConfigs<M> = {
200
257
  };
201
258
  /** Firestore trigger constructors from `firebase-functions/v2/firestore`. */
202
259
  interface FirestoreTriggersDep {
203
- onDocumentCreated: typeof onDocumentCreated;
204
- onDocumentUpdated: typeof onDocumentUpdated;
205
- onDocumentDeleted: typeof onDocumentDeleted;
260
+ onDocumentWritten: typeof onDocumentWritten;
206
261
  }
207
262
  /** PubSub handler from `firebase-functions/v2/pubsub`. */
208
263
  interface PubSubHandlerDep {
@@ -238,13 +293,20 @@ interface SyncTriggersConfig<M = Record<string, any>> {
238
293
  interface SyncWorkerConfig<M = Record<string, any>> {
239
294
  /** External dependencies — PubSub handler + client */
240
295
  deps: Pick<SyncDeps, "pubsubHandler" | "pubsub">;
241
- /** SQL adapter to flush data to */
242
- adapter: SqlAdapter;
296
+ /**
297
+ * Adapter(s) to flush data to. Accepts a single adapter, an array of adapters,
298
+ * or a lazy factory returning one or more adapters.
299
+ */
300
+ adapter?: OrFactory<SyncAdapter | SyncAdapter[]>;
301
+ /**
302
+ * Explicit array of adapters to flush data to.
303
+ */
304
+ adapters?: OrFactory<SyncAdapter>[];
243
305
  /** Max rows per flush batch (default: 100) */
244
306
  batchSize?: number;
245
307
  /** Flush interval in ms (default: 5000) */
246
308
  flushIntervalMs?: number;
247
- /** Auto-create/migrate tables on first event (default: false) */
309
+ /** Auto-create/migrate tables or indexes on first event (default: false) */
248
310
  autoMigrate?: boolean;
249
311
  /** PubSub topic prefix (default: "firestore-sync") */
250
312
  topicPrefix?: string;
@@ -258,11 +320,6 @@ interface SyncWorkerConfig<M = Record<string, any>> {
258
320
  * Cloud Functions v2 options forwarded to `onMessagePublished()` for every
259
321
  * worker handler. Use to tune `concurrency`, `maxInstances`, `minInstances`,
260
322
  * `memory`, `timeoutSeconds`, `region`, `cpu`, etc.
261
- *
262
- * Example:
263
- * ```ts
264
- * workerOptions: { concurrency: 10, maxInstances: 10, memory: "512MiB" }
265
- * ```
266
323
  */
267
324
  workerOptions?: SyncWorkerOptions;
268
325
  /** Per-repo overrides */
@@ -289,9 +346,9 @@ interface adminsyncBasicAuth {
289
346
  interface adminsyncFeaturesFlag {
290
347
  /** Allow force-syncing an entire collection (default: false) */
291
348
  manualSync?: boolean;
292
- /** Schema health check: expected vs actual SQL columns (default: false) */
349
+ /** Schema health check: expected vs actual storage structure (default: false) */
293
350
  healthCheck?: boolean;
294
- /** GCP config check: verify APIs, topics, tables, and IAM (default: false) */
351
+ /** GCP / target config check: verify APIs, topics, targets, and IAM (default: false) */
295
352
  configCheck?: boolean;
296
353
  }
297
354
  /**
@@ -339,18 +396,21 @@ interface FirestoreSyncConfig<M = Record<string, any>> {
339
396
  pubsub: OrFactory<PubSubClientDep>;
340
397
  };
341
398
  /**
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).
399
+ * Sync adapter(s) to flush data to (e.g. BigQueryAdapter, MeilisearchAdapter).
400
+ * Can be a single adapter, an array of adapters, or a lazy factory.
401
+ */
402
+ adapter?: OrFactory<SyncAdapter | SyncAdapter[]>;
403
+ /**
404
+ * Explicit array of adapters to flush data to.
345
405
  */
346
- adapter: OrFactory<SqlAdapter>;
406
+ adapters?: OrFactory<SyncAdapter>[];
347
407
  /** PubSub topic name prefix (topics will be `{prefix}-{repoName}`) */
348
408
  topicPrefix?: string;
349
409
  /** Max rows per flush batch (default: 100) */
350
410
  batchSize?: number;
351
411
  /** Flush interval in ms (default: 5000) */
352
412
  flushIntervalMs?: number;
353
- /** Auto-create/migrate tables on first event (default: false) */
413
+ /** Auto-create/migrate tables or indexes on first event (default: false) */
354
414
  autoMigrate?: boolean;
355
415
  /**
356
416
  * Cloud Functions v2 options forwarded to `onMessagePublished()` for every
@@ -359,7 +419,7 @@ interface FirestoreSyncConfig<M = Record<string, any>> {
359
419
  */
360
420
  workerOptions?: SyncWorkerOptions;
361
421
  /**
362
- * Optional sync admin endpoint. When provided, a `adminsync` handler is
422
+ * Optional sync admin endpoint. When provided, an `adminsync` handler is
363
423
  * added to `sync.functions` exposing health-check, force-sync, and queue
364
424
  * inspection endpoints behind authentication.
365
425
  */
@@ -368,4 +428,4 @@ interface FirestoreSyncConfig<M = Record<string, any>> {
368
428
  repos?: TypedRepoSyncConfigs<M>;
369
429
  }
370
430
 
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 };
431
+ 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.57",
3
+ "version": "3.0.1",
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",