@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
package/README.md CHANGED
@@ -434,9 +434,10 @@ A single unified factory binds all servers to your repository registry. Per-repo
434
434
  import { createServers } from "@lpdjs/firestore-repo-service";
435
435
  import { onRequest } from "firebase-functions/v2/https";
436
436
  import { BigQueryAdapter } from "@lpdjs/firestore-repo-service/sync/bigquery";
437
+ import { MeilisearchAdapter } from "@lpdjs/firestore-repo-service/sync/meilisearch";
437
438
  import { BigQuery } from "@google-cloud/bigquery";
438
439
  import { PubSub } from "@google-cloud/pubsub";
439
- import * as firestoreTriggers from "firebase-functions/v2/firestore";
440
+ import { onDocumentWritten } from "firebase-functions/v2/firestore";
440
441
  import * as pubsubHandler from "firebase-functions/v2/pubsub";
441
442
 
442
443
  const servers = createServers(repos, {
@@ -458,7 +459,7 @@ export const admin = servers.admin({
458
459
  },
459
460
  });
460
461
 
461
- // CRUD REST API (Hono-based)
462
+ // CRUD REST API (Hono-based) with Before Rules & Missing Index detection
462
463
  export const api = servers.crud({
463
464
  basePath: "/api",
464
465
  middlewares: [
@@ -468,25 +469,45 @@ export const api = servers.crud({
468
469
  }
469
470
  ],
470
471
  repos: {
471
- posts: { path: "posts", allowDelete: true },
472
+ posts: {
473
+ path: "posts",
474
+ allowDelete: true,
475
+ rules: [
476
+ {
477
+ description: "Cannot cancel a paid post",
478
+ run: ({ before, changes }) => !(changes.status === "cancelled" && before.isPaid),
479
+ },
480
+ ],
481
+ },
472
482
  users: { path: "users" },
473
483
  },
484
+ indexesError: ({ repoName, indexUrl }) => {
485
+ console.warn(`[Index Required] ${repoName}: ${indexUrl}`);
486
+ },
474
487
  openapi: {
475
488
  title: "My API",
476
489
  version: "1.0.0",
477
- // Optional: Protect /docs and /openapi.json using firebaseDocsAuth or custom middleware
478
490
  },
479
491
  });
480
492
 
481
- // Firestore → BigQuery sync (triggers + worker + admin Cloud Functions)
493
+ // Firestore → Storage Sync (BigQuery & Meilisearch multi-adapter fan-out)
482
494
  export const { functions } = servers.sync({
483
- deps: { firestoreTriggers, pubsubHandler, pubsub: new PubSub() },
484
- adapter: new BigQueryAdapter({
485
- bigquery: new BigQuery({ projectId: "my-project" }),
486
- projectId: "my-project",
487
- datasetId: "firestore_sync",
488
- maxStaleness: "INTERVAL 15 MINUTE",
489
- }),
495
+ deps: { firestoreTriggers: { onDocumentWritten }, pubsubHandler, pubsub: new PubSub() },
496
+ adapters: [
497
+ new BigQueryAdapter({
498
+ bigquery: new BigQuery({ projectId: "my-project" }),
499
+ projectId: "my-project",
500
+ datasetId: "firestore_sync",
501
+ maxStaleness: "INTERVAL 15 MINUTE",
502
+ }),
503
+ new MeilisearchAdapter({
504
+ host: "http://localhost:7700",
505
+ apiKey: "masterKey",
506
+ indexesSettings: {
507
+ users: { searchableAttributes: ["name", "email"], filterableAttributes: ["role"] },
508
+ },
509
+ }),
510
+ ],
490
511
  topicPrefix: "firestore-sync",
491
512
  autoMigrate: true,
492
513
  admin: {
@@ -494,25 +515,19 @@ export const { functions } = servers.sync({
494
515
  featuresFlag: { healthCheck: true, manualSync: true, configCheck: true },
495
516
  },
496
517
  repos: {
497
- users: { tableName: "users", columnMap: { docId: "user_id" } },
518
+ users: { tableName: "users", columnMap: { docId: "user_id" }, adapters: ["bigquery", "meilisearch"] },
498
519
  posts: { columnMap: { docId: "post_id" } },
499
520
  comments: { triggerPath: "posts/{postId}/comments/{docId}" },
500
521
  },
501
522
  });
502
523
 
503
- // Spread Cloud Functions into your exports
524
+ // Spread Cloud Functions into your exports (1 onSync trigger per repo + 1 worker per repo)
504
525
  export const {
505
- users_onCreate,
506
- users_onUpdate,
507
- users_onDelete,
526
+ users_onSync,
508
527
  sync_users,
509
- posts_onCreate,
510
- posts_onUpdate,
511
- posts_onDelete,
528
+ posts_onSync,
512
529
  sync_posts,
513
- comments_onCreate,
514
- comments_onUpdate,
515
- comments_onDelete,
530
+ comments_onSync,
516
531
  sync_comments,
517
532
  adminsync,
518
533
  } = functions;
@@ -522,13 +537,16 @@ When `onRequest` is passed to `createServers`, `servers.admin()` and `servers.cr
522
537
 
523
538
  The sync admin endpoint (`/`) exposes a UI for health checks, force-sync, queue inspection, and GCP config verification.
524
539
 
525
- For a custom SQL backend, implement the `SqlAdapter` interface:
540
+ For custom storage or search backends, implement the universal `SyncAdapter` interface:
526
541
 
527
542
  ```typescript
528
- import type { SqlAdapter } from "@lpdjs/firestore-repo-service/sync";
543
+ import type { SyncAdapter } from "@lpdjs/firestore-repo-service/sync";
529
544
 
530
- class MyAdapter implements SqlAdapter {
531
- // tableExists, getTableColumns, createTable, upsertRows, deleteRows, executeRaw
545
+ class MyCustomAdapter implements SyncAdapter {
546
+ readonly name = "custom";
547
+ async targetExists(targetName: string): Promise<boolean> { /* ... */ }
548
+ async upsert(targetName: string, items: Record<string, unknown>[], primaryKey: string): Promise<void> { /* ... */ }
549
+ async delete(targetName: string, primaryKey: string, ids: string[]): Promise<void> { /* ... */ }
532
550
  }
533
551
  ```
534
552
 
@@ -1,5 +1,5 @@
1
- import { S as SyncQueue } from './queue-DO0af0iY.js';
2
- import { F as FirestoreSyncConfig, S as SyncEvent } from './types-BaFkMwNb.js';
1
+ import { S as SyncQueue } from './queue-BWi6TBmf.js';
2
+ import { F as FirestoreSyncConfig, S as SyncEvent } from './types-BRPhmKFW.js';
3
3
  import { O as OpenAPIDocument } from './openapi-BTu_1vSc.js';
4
4
  import * as firebase_functions_v2_https from 'firebase-functions/v2/https';
5
5
  import { onRequest, HttpsOptions } from 'firebase-functions/v2/https';
@@ -1,5 +1,5 @@
1
- import { S as SyncQueue } from './queue-LLW6fbO6.cjs';
2
- import { F as FirestoreSyncConfig, S as SyncEvent } from './types-CbNcdNkb.cjs';
1
+ import { S as SyncQueue } from './queue-B9jCT62h.cjs';
2
+ import { F as FirestoreSyncConfig, S as SyncEvent } from './types-LZ8dyfBz.cjs';
3
3
  import { O as OpenAPIDocument } from './openapi-CoKsSOIU.cjs';
4
4
  import * as firebase_functions_v2_https from 'firebase-functions/v2/https';
5
5
  import { onRequest, HttpsOptions } from 'firebase-functions/v2/https';