@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
@@ -0,0 +1,4 @@
1
+ 'use strict';var c=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});function l(n){if(n.client)return n.client;if(!n.host)throw new Error("MeilisearchAdapter requires either a `client` instance or a `host` option.");try{let{MeiliSearch:e}=c("meilisearch");return new e({host:n.host,apiKey:n.apiKey})}catch(e){throw new Error(`Failed to load the "meilisearch" package. Please install it with:
2
+ bun add meilisearch # or npm install meilisearch
3
+ Original error: ${e?.message??String(e)}`)}}var o=class{constructor(e){this.name="meilisearch";this._client=null;this.options=e,e.client&&(this._client=e.client);}get client(){return this._client||(this._client=l(this.options)),this._client}async targetExists(e){try{return await this.client.getIndex(e),!0}catch(t){if(t?.code==="index_not_found"||t?.statusCode===404||t?.status===404)return false;throw t}}async upsert(e,t,i){if(t.length===0)return;await this.client.index(e).addDocuments(t,{primaryKey:i});}async delete(e,t,i){if(i.length===0)return;await this.client.index(e).deleteDocuments(i);}async ensureTarget(e){let{targetName:t,primaryKey:i}=e;await this.targetExists(t)||await this.client.createIndex(t,{primaryKey:i});let s=this.options.indexesSettings?.[t];s&&await this.client.index(t).updateSettings(s);}async healthCheck(e){let{targetName:t}=e;try{if(!await this.targetExists(t))return {healthy:!1,targetName:t,targetExists:!1,error:`Meilisearch index "${t}" does not exist`};let r=this.client.index(t),s=await r.getStats(),a=typeof r.getRawInfo=="function"?await r.getRawInfo():{};return {healthy:!0,targetName:t,targetExists:!0,error:null,details:{numberOfDocuments:s?.numberOfDocuments??0,isIndexing:s?.isIndexing??!1,fieldDistribution:s?.fieldDistribution??{},primaryKey:a?.primaryKey??e.primaryKey}}}catch(i){return {healthy:false,targetName:t,targetExists:false,error:i?.message??String(i)}}}async checkConnection(){try{let e=!0;if(typeof this.client.isHealthy=="function"){let i=await this.client.isHealthy();e=i?.status==="available"||i===!0;}else if(typeof this.client.health=="function"){let i=await this.client.health();e=i?.status==="available"||i===!0;}let t;return typeof this.client.getVersion=="function"&&(t=(await this.client.getVersion())?.pkgVersion),{healthy:e,version:t}}catch(e){return {healthy:false,error:e?.message??String(e)}}}};exports.MeilisearchAdapter=o;//# sourceMappingURL=meilisearch.cjs.map
4
+ //# sourceMappingURL=meilisearch.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/sync/adapters/meilisearch.ts"],"names":["loadMeilisearchClient","options","MeiliSearch","err","MeilisearchAdapter","targetName","items","primaryKey","_primaryKey","ids","settings","index","stats","rawInfo","isHealthy","res","version"],"mappings":"sQA2EA,SAASA,CAAAA,CAAsBC,EAAqD,CAClF,GAAIA,EAAQ,MAAA,CAAQ,OAAOA,EAAQ,MAAA,CACnC,GAAI,CAACA,CAAAA,CAAQ,IAAA,CACX,MAAM,IAAI,KAAA,CACR,4EACF,CAAA,CAEF,GAAI,CAEF,GAAM,CAAE,YAAAC,CAAY,CAAA,CAAI,EAAQ,aAAa,CAAA,CAC7C,OAAO,IAAIA,CAAAA,CAAY,CACrB,IAAA,CAAMD,CAAAA,CAAQ,KACd,MAAA,CAAQA,CAAAA,CAAQ,MAClB,CAAC,CACH,OAASE,CAAAA,CAAU,CACjB,MAAM,IAAI,KAAA,CACR,CAAA;AAAA;AAAA,gBAAA,EAEqBA,GAAK,OAAA,EAAW,MAAA,CAAOA,CAAG,CAAC,CAAA,CAClD,CACF,CACF,CAKO,IAAMC,CAAAA,CAAN,KAAgD,CAKrD,WAAA,CAAYH,EAAoC,CAJhD,IAAA,CAAS,KAAO,aAAA,CAChB,IAAA,CAAQ,OAAA,CAAkC,IAAA,CAIxC,KAAK,OAAA,CAAUA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CAAK,MAAA,CAAO,WAAU,CACxCD,CAAAA,CAAYC,GAAK,MAAA,GAAW,WAAA,EAAeA,IAAQ,CAAA,EACrD,CAAA,KAAA,GAAW,OAAO,IAAA,CAAK,MAAA,CAAO,QAAW,UAAA,CAAY,CACnD,IAAMA,CAAAA,CAAM,MAAM,KAAK,MAAA,CAAO,MAAA,EAAO,CACrCD,CAAAA,CAAYC,GAAK,MAAA,GAAW,WAAA,EAAeA,IAAQ,CAAA,EACrD,CACA,IAAIC,CAAAA,CACJ,OAAI,OAAO,IAAA,CAAK,MAAA,CAAO,YAAe,UAAA,GAEpCA,CAAAA,CAAAA,CADU,MAAM,IAAA,CAAK,MAAA,CAAO,YAAW,GAC1B,UAAA,CAAA,CAER,CAAE,OAAA,CAASF,EAAW,OAAA,CAAAE,CAAQ,CACvC,CAAA,MAAS,CAAA,CAAQ,CACf,OAAO,CAAE,QAAS,KAAA,CAAO,KAAA,CAAO,GAAG,OAAA,EAAW,MAAA,CAAO,CAAC,CAAE,CAC1D,CACF,CACF","file":"meilisearch.cjs","sourcesContent":["/**\n * Meilisearch adapter — streams Firestore changes to Meilisearch indexes.\n *\n * @example\n * ```ts\n * import { MeilisearchAdapter } from \"@lpdjs/firestore-repo-service/sync/meilisearch\";\n *\n * const adapter = new MeilisearchAdapter({\n * host: \"http://localhost:7700\",\n * apiKey: \"masterKey\",\n * indexesSettings: {\n * users: {\n * filterableAttributes: [\"role\", \"status\", \"createdAt\"],\n * sortableAttributes: [\"createdAt\", \"name\"],\n * searchableAttributes: [\"name\", \"email\"],\n * },\n * },\n * });\n * ```\n */\n\nimport type { z } from \"zod\";\nimport type { RepoSyncConfig, SyncAdapter, SyncHealthResult } from \"../types\";\n\n/**\n * Minimal structural shape of a Meilisearch client.\n */\nexport interface MeilisearchLike {\n index(indexUid: string): {\n addDocuments(documents: any[], options?: { primaryKey?: string }): Promise<any>;\n deleteDocuments(documentIds: string[] | number[]): Promise<any>;\n getStats(): Promise<any>;\n getRawInfo(): Promise<any>;\n updateSettings(settings: any): Promise<any>;\n [key: string]: any;\n };\n getIndex(indexUid: string): Promise<any>;\n createIndex(indexUid: string, options?: { primaryKey?: string }): Promise<any>;\n isHealthy?(): Promise<any>;\n health?(): Promise<any>;\n getVersion?(): Promise<any>;\n}\n\nexport interface MeilisearchIndexSettings {\n filterableAttributes?: string[];\n sortableAttributes?: string[];\n searchableAttributes?: string[];\n rankingRules?: string[];\n stopWords?: string[];\n synonyms?: Record<string, string[]>;\n distinctAttribute?: string;\n [key: string]: any;\n}\n\nexport interface MeilisearchAdapterOptions {\n /**\n * Host URL of the Meilisearch instance (e.g. `http://localhost:7700` or `https://ms-xxxx.meilisearch.io`).\n * Required if `client` is not provided.\n */\n host?: string;\n /**\n * API Key (e.g. master key or admin key) with permissions to read/write indexes.\n */\n apiKey?: string;\n /**\n * Existing pre-built Meilisearch client instance.\n */\n client?: MeilisearchLike | any;\n /**\n * Custom index settings per target index name (e.g. filterableAttributes, sortableAttributes).\n */\n indexesSettings?: Record<string, MeilisearchIndexSettings>;\n}\n\n/** Lazy-loader for the optional `meilisearch` peer dependency. */\nfunction loadMeilisearchClient(options: MeilisearchAdapterOptions): MeilisearchLike {\n if (options.client) return options.client;\n if (!options.host) {\n throw new Error(\n \"MeilisearchAdapter requires either a `client` instance or a `host` option.\",\n );\n }\n try {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const { MeiliSearch } = require(\"meilisearch\");\n return new MeiliSearch({\n host: options.host,\n apiKey: options.apiKey,\n });\n } catch (err: any) {\n throw new Error(\n `Failed to load the \"meilisearch\" package. Please install it with:\\n` +\n ` bun add meilisearch # or npm install meilisearch\\n` +\n `Original error: ${err?.message ?? String(err)}`,\n );\n }\n}\n\n/**\n * SyncAdapter implementation for Meilisearch.\n */\nexport class MeilisearchAdapter implements SyncAdapter {\n readonly name = \"meilisearch\";\n private _client: MeilisearchLike | null = null;\n private readonly options: MeilisearchAdapterOptions;\n\n constructor(options: MeilisearchAdapterOptions) {\n this.options = options;\n if (options.client) {\n this._client = options.client;\n }\n }\n\n /** Resolved Meilisearch client instance. */\n get client(): MeilisearchLike {\n if (!this._client) {\n this._client = loadMeilisearchClient(this.options);\n }\n return this._client;\n }\n\n // ---------------------------------------------------------------------------\n // SyncAdapter Methods\n // ---------------------------------------------------------------------------\n\n async targetExists(targetName: string): Promise<boolean> {\n try {\n await this.client.getIndex(targetName);\n return true;\n } catch (err: any) {\n if (\n err?.code === \"index_not_found\" ||\n err?.statusCode === 404 ||\n err?.status === 404\n ) {\n return false;\n }\n throw err;\n }\n }\n\n async upsert(\n targetName: string,\n items: Record<string, unknown>[],\n primaryKey: string,\n ): Promise<void> {\n if (items.length === 0) return;\n const index = this.client.index(targetName);\n await index.addDocuments(items, { primaryKey });\n }\n\n async delete(\n targetName: string,\n _primaryKey: string,\n ids: string[],\n ): Promise<void> {\n if (ids.length === 0) return;\n const index = this.client.index(targetName);\n await index.deleteDocuments(ids);\n }\n\n async ensureTarget(options: {\n targetName: string;\n primaryKey: string;\n schema?: z.ZodObject<any>;\n exclude?: string[];\n columnMap?: Record<string, string>;\n }): Promise<void> {\n const { targetName, primaryKey } = options;\n const exists = await this.targetExists(targetName);\n if (!exists) {\n await this.client.createIndex(targetName, { primaryKey });\n }\n\n const settings = this.options.indexesSettings?.[targetName];\n if (settings) {\n const index = this.client.index(targetName);\n await index.updateSettings(settings);\n }\n }\n\n async healthCheck(options: {\n targetName: string;\n primaryKey: string;\n schema?: z.ZodObject<any>;\n repoConfig?: RepoSyncConfig<string>;\n }): Promise<SyncHealthResult> {\n const { targetName } = options;\n try {\n const exists = await this.targetExists(targetName);\n if (!exists) {\n return {\n healthy: false,\n targetName,\n targetExists: false,\n error: `Meilisearch index \"${targetName}\" does not exist`,\n };\n }\n const index = this.client.index(targetName);\n const stats = await index.getStats();\n const rawInfo = typeof index.getRawInfo === \"function\" ? await index.getRawInfo() : {};\n\n return {\n healthy: true,\n targetName,\n targetExists: true,\n error: null,\n details: {\n numberOfDocuments: stats?.numberOfDocuments ?? 0,\n isIndexing: stats?.isIndexing ?? false,\n fieldDistribution: stats?.fieldDistribution ?? {},\n primaryKey: rawInfo?.primaryKey ?? options.primaryKey,\n },\n };\n } catch (err: any) {\n return {\n healthy: false,\n targetName,\n targetExists: false,\n error: err?.message ?? String(err),\n };\n }\n }\n\n /** Verify overall connection and connectivity to the Meilisearch instance. */\n async checkConnection(): Promise<{\n healthy: boolean;\n version?: string;\n error?: string;\n }> {\n try {\n let isHealthy = true;\n if (typeof this.client.isHealthy === \"function\") {\n const res = await this.client.isHealthy();\n isHealthy = res?.status === \"available\" || res === true;\n } else if (typeof this.client.health === \"function\") {\n const res = await this.client.health();\n isHealthy = res?.status === \"available\" || res === true;\n }\n let version: string | undefined;\n if (typeof this.client.getVersion === \"function\") {\n const v = await this.client.getVersion();\n version = v?.pkgVersion;\n }\n return { healthy: isHealthy, version };\n } catch (e: any) {\n return { healthy: false, error: e?.message ?? String(e) };\n }\n }\n}\n"]}
@@ -0,0 +1,114 @@
1
+ import { z } from 'zod';
2
+ import { a as SyncAdapter, R as RepoSyncConfig, d as SyncHealthResult } from '../types-LZ8dyfBz.cjs';
3
+ import '../firebase-auth-Ds5P0kXT.cjs';
4
+ import 'firebase-functions/v2/firestore';
5
+ import 'firebase-functions/v2/https';
6
+ import 'firebase-functions/v2/pubsub';
7
+
8
+ /**
9
+ * Meilisearch adapter — streams Firestore changes to Meilisearch indexes.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { MeilisearchAdapter } from "@lpdjs/firestore-repo-service/sync/meilisearch";
14
+ *
15
+ * const adapter = new MeilisearchAdapter({
16
+ * host: "http://localhost:7700",
17
+ * apiKey: "masterKey",
18
+ * indexesSettings: {
19
+ * users: {
20
+ * filterableAttributes: ["role", "status", "createdAt"],
21
+ * sortableAttributes: ["createdAt", "name"],
22
+ * searchableAttributes: ["name", "email"],
23
+ * },
24
+ * },
25
+ * });
26
+ * ```
27
+ */
28
+
29
+ /**
30
+ * Minimal structural shape of a Meilisearch client.
31
+ */
32
+ interface MeilisearchLike {
33
+ index(indexUid: string): {
34
+ addDocuments(documents: any[], options?: {
35
+ primaryKey?: string;
36
+ }): Promise<any>;
37
+ deleteDocuments(documentIds: string[] | number[]): Promise<any>;
38
+ getStats(): Promise<any>;
39
+ getRawInfo(): Promise<any>;
40
+ updateSettings(settings: any): Promise<any>;
41
+ [key: string]: any;
42
+ };
43
+ getIndex(indexUid: string): Promise<any>;
44
+ createIndex(indexUid: string, options?: {
45
+ primaryKey?: string;
46
+ }): Promise<any>;
47
+ isHealthy?(): Promise<any>;
48
+ health?(): Promise<any>;
49
+ getVersion?(): Promise<any>;
50
+ }
51
+ interface MeilisearchIndexSettings {
52
+ filterableAttributes?: string[];
53
+ sortableAttributes?: string[];
54
+ searchableAttributes?: string[];
55
+ rankingRules?: string[];
56
+ stopWords?: string[];
57
+ synonyms?: Record<string, string[]>;
58
+ distinctAttribute?: string;
59
+ [key: string]: any;
60
+ }
61
+ interface MeilisearchAdapterOptions {
62
+ /**
63
+ * Host URL of the Meilisearch instance (e.g. `http://localhost:7700` or `https://ms-xxxx.meilisearch.io`).
64
+ * Required if `client` is not provided.
65
+ */
66
+ host?: string;
67
+ /**
68
+ * API Key (e.g. master key or admin key) with permissions to read/write indexes.
69
+ */
70
+ apiKey?: string;
71
+ /**
72
+ * Existing pre-built Meilisearch client instance.
73
+ */
74
+ client?: MeilisearchLike | any;
75
+ /**
76
+ * Custom index settings per target index name (e.g. filterableAttributes, sortableAttributes).
77
+ */
78
+ indexesSettings?: Record<string, MeilisearchIndexSettings>;
79
+ }
80
+ /**
81
+ * SyncAdapter implementation for Meilisearch.
82
+ */
83
+ declare class MeilisearchAdapter implements SyncAdapter {
84
+ readonly name = "meilisearch";
85
+ private _client;
86
+ private readonly options;
87
+ constructor(options: MeilisearchAdapterOptions);
88
+ /** Resolved Meilisearch client instance. */
89
+ get client(): MeilisearchLike;
90
+ targetExists(targetName: string): Promise<boolean>;
91
+ upsert(targetName: string, items: Record<string, unknown>[], primaryKey: string): Promise<void>;
92
+ delete(targetName: string, _primaryKey: string, ids: string[]): Promise<void>;
93
+ ensureTarget(options: {
94
+ targetName: string;
95
+ primaryKey: string;
96
+ schema?: z.ZodObject<any>;
97
+ exclude?: string[];
98
+ columnMap?: Record<string, string>;
99
+ }): Promise<void>;
100
+ healthCheck(options: {
101
+ targetName: string;
102
+ primaryKey: string;
103
+ schema?: z.ZodObject<any>;
104
+ repoConfig?: RepoSyncConfig<string>;
105
+ }): Promise<SyncHealthResult>;
106
+ /** Verify overall connection and connectivity to the Meilisearch instance. */
107
+ checkConnection(): Promise<{
108
+ healthy: boolean;
109
+ version?: string;
110
+ error?: string;
111
+ }>;
112
+ }
113
+
114
+ export { MeilisearchAdapter, type MeilisearchAdapterOptions, type MeilisearchIndexSettings, type MeilisearchLike };
@@ -0,0 +1,114 @@
1
+ import { z } from 'zod';
2
+ import { a as SyncAdapter, R as RepoSyncConfig, d as SyncHealthResult } from '../types-BRPhmKFW.js';
3
+ import '../firebase-auth-Ds5P0kXT.js';
4
+ import 'firebase-functions/v2/firestore';
5
+ import 'firebase-functions/v2/https';
6
+ import 'firebase-functions/v2/pubsub';
7
+
8
+ /**
9
+ * Meilisearch adapter — streams Firestore changes to Meilisearch indexes.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { MeilisearchAdapter } from "@lpdjs/firestore-repo-service/sync/meilisearch";
14
+ *
15
+ * const adapter = new MeilisearchAdapter({
16
+ * host: "http://localhost:7700",
17
+ * apiKey: "masterKey",
18
+ * indexesSettings: {
19
+ * users: {
20
+ * filterableAttributes: ["role", "status", "createdAt"],
21
+ * sortableAttributes: ["createdAt", "name"],
22
+ * searchableAttributes: ["name", "email"],
23
+ * },
24
+ * },
25
+ * });
26
+ * ```
27
+ */
28
+
29
+ /**
30
+ * Minimal structural shape of a Meilisearch client.
31
+ */
32
+ interface MeilisearchLike {
33
+ index(indexUid: string): {
34
+ addDocuments(documents: any[], options?: {
35
+ primaryKey?: string;
36
+ }): Promise<any>;
37
+ deleteDocuments(documentIds: string[] | number[]): Promise<any>;
38
+ getStats(): Promise<any>;
39
+ getRawInfo(): Promise<any>;
40
+ updateSettings(settings: any): Promise<any>;
41
+ [key: string]: any;
42
+ };
43
+ getIndex(indexUid: string): Promise<any>;
44
+ createIndex(indexUid: string, options?: {
45
+ primaryKey?: string;
46
+ }): Promise<any>;
47
+ isHealthy?(): Promise<any>;
48
+ health?(): Promise<any>;
49
+ getVersion?(): Promise<any>;
50
+ }
51
+ interface MeilisearchIndexSettings {
52
+ filterableAttributes?: string[];
53
+ sortableAttributes?: string[];
54
+ searchableAttributes?: string[];
55
+ rankingRules?: string[];
56
+ stopWords?: string[];
57
+ synonyms?: Record<string, string[]>;
58
+ distinctAttribute?: string;
59
+ [key: string]: any;
60
+ }
61
+ interface MeilisearchAdapterOptions {
62
+ /**
63
+ * Host URL of the Meilisearch instance (e.g. `http://localhost:7700` or `https://ms-xxxx.meilisearch.io`).
64
+ * Required if `client` is not provided.
65
+ */
66
+ host?: string;
67
+ /**
68
+ * API Key (e.g. master key or admin key) with permissions to read/write indexes.
69
+ */
70
+ apiKey?: string;
71
+ /**
72
+ * Existing pre-built Meilisearch client instance.
73
+ */
74
+ client?: MeilisearchLike | any;
75
+ /**
76
+ * Custom index settings per target index name (e.g. filterableAttributes, sortableAttributes).
77
+ */
78
+ indexesSettings?: Record<string, MeilisearchIndexSettings>;
79
+ }
80
+ /**
81
+ * SyncAdapter implementation for Meilisearch.
82
+ */
83
+ declare class MeilisearchAdapter implements SyncAdapter {
84
+ readonly name = "meilisearch";
85
+ private _client;
86
+ private readonly options;
87
+ constructor(options: MeilisearchAdapterOptions);
88
+ /** Resolved Meilisearch client instance. */
89
+ get client(): MeilisearchLike;
90
+ targetExists(targetName: string): Promise<boolean>;
91
+ upsert(targetName: string, items: Record<string, unknown>[], primaryKey: string): Promise<void>;
92
+ delete(targetName: string, _primaryKey: string, ids: string[]): Promise<void>;
93
+ ensureTarget(options: {
94
+ targetName: string;
95
+ primaryKey: string;
96
+ schema?: z.ZodObject<any>;
97
+ exclude?: string[];
98
+ columnMap?: Record<string, string>;
99
+ }): Promise<void>;
100
+ healthCheck(options: {
101
+ targetName: string;
102
+ primaryKey: string;
103
+ schema?: z.ZodObject<any>;
104
+ repoConfig?: RepoSyncConfig<string>;
105
+ }): Promise<SyncHealthResult>;
106
+ /** Verify overall connection and connectivity to the Meilisearch instance. */
107
+ checkConnection(): Promise<{
108
+ healthy: boolean;
109
+ version?: string;
110
+ error?: string;
111
+ }>;
112
+ }
113
+
114
+ export { MeilisearchAdapter, type MeilisearchAdapterOptions, type MeilisearchIndexSettings, type MeilisearchLike };
@@ -0,0 +1,4 @@
1
+ var c=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});function l(n){if(n.client)return n.client;if(!n.host)throw new Error("MeilisearchAdapter requires either a `client` instance or a `host` option.");try{let{MeiliSearch:e}=c("meilisearch");return new e({host:n.host,apiKey:n.apiKey})}catch(e){throw new Error(`Failed to load the "meilisearch" package. Please install it with:
2
+ bun add meilisearch # or npm install meilisearch
3
+ Original error: ${e?.message??String(e)}`)}}var o=class{constructor(e){this.name="meilisearch";this._client=null;this.options=e,e.client&&(this._client=e.client);}get client(){return this._client||(this._client=l(this.options)),this._client}async targetExists(e){try{return await this.client.getIndex(e),!0}catch(t){if(t?.code==="index_not_found"||t?.statusCode===404||t?.status===404)return false;throw t}}async upsert(e,t,i){if(t.length===0)return;await this.client.index(e).addDocuments(t,{primaryKey:i});}async delete(e,t,i){if(i.length===0)return;await this.client.index(e).deleteDocuments(i);}async ensureTarget(e){let{targetName:t,primaryKey:i}=e;await this.targetExists(t)||await this.client.createIndex(t,{primaryKey:i});let s=this.options.indexesSettings?.[t];s&&await this.client.index(t).updateSettings(s);}async healthCheck(e){let{targetName:t}=e;try{if(!await this.targetExists(t))return {healthy:!1,targetName:t,targetExists:!1,error:`Meilisearch index "${t}" does not exist`};let r=this.client.index(t),s=await r.getStats(),a=typeof r.getRawInfo=="function"?await r.getRawInfo():{};return {healthy:!0,targetName:t,targetExists:!0,error:null,details:{numberOfDocuments:s?.numberOfDocuments??0,isIndexing:s?.isIndexing??!1,fieldDistribution:s?.fieldDistribution??{},primaryKey:a?.primaryKey??e.primaryKey}}}catch(i){return {healthy:false,targetName:t,targetExists:false,error:i?.message??String(i)}}}async checkConnection(){try{let e=!0;if(typeof this.client.isHealthy=="function"){let i=await this.client.isHealthy();e=i?.status==="available"||i===!0;}else if(typeof this.client.health=="function"){let i=await this.client.health();e=i?.status==="available"||i===!0;}let t;return typeof this.client.getVersion=="function"&&(t=(await this.client.getVersion())?.pkgVersion),{healthy:e,version:t}}catch(e){return {healthy:false,error:e?.message??String(e)}}}};export{o as MeilisearchAdapter};//# sourceMappingURL=meilisearch.js.map
4
+ //# sourceMappingURL=meilisearch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/sync/adapters/meilisearch.ts"],"names":["loadMeilisearchClient","options","MeiliSearch","err","MeilisearchAdapter","targetName","items","primaryKey","_primaryKey","ids","settings","index","stats","rawInfo","isHealthy","res","version"],"mappings":"yPA2EA,SAASA,CAAAA,CAAsBC,EAAqD,CAClF,GAAIA,EAAQ,MAAA,CAAQ,OAAOA,EAAQ,MAAA,CACnC,GAAI,CAACA,CAAAA,CAAQ,IAAA,CACX,MAAM,IAAI,KAAA,CACR,4EACF,CAAA,CAEF,GAAI,CAEF,GAAM,CAAE,YAAAC,CAAY,CAAA,CAAI,EAAQ,aAAa,CAAA,CAC7C,OAAO,IAAIA,CAAAA,CAAY,CACrB,IAAA,CAAMD,CAAAA,CAAQ,KACd,MAAA,CAAQA,CAAAA,CAAQ,MAClB,CAAC,CACH,OAASE,CAAAA,CAAU,CACjB,MAAM,IAAI,KAAA,CACR,CAAA;AAAA;AAA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AA,CACd,KAAA,CAAOF,GAAK,OAAA,EAAW,MAAA,CAAOA,CAAG,CACnC,CACF,CACF,CAGA,MAAM,eAAA,EAIH,CACD,GAAI,CACF,IAAIW,EAAY,CAAA,CAAA,CAChB,GAAI,OAAO,IAAA,CAAK,MAAA,CAAO,WAAc,UAAA,CAAY,CAC/C,IAAMC,CAAAA,CAAM,MAAM,IAAA,CAAK,MAAA,CAAO,WAAU,CACxCD,CAAAA,CAAYC,GAAK,MAAA,GAAW,WAAA,EAAeA,IAAQ,CAAA,EACrD,CAAA,KAAA,GAAW,OAAO,IAAA,CAAK,MAAA,CAAO,QAAW,UAAA,CAAY,CACnD,IAAMA,CAAAA,CAAM,MAAM,KAAK,MAAA,CAAO,MAAA,EAAO,CACrCD,CAAAA,CAAYC,GAAK,MAAA,GAAW,WAAA,EAAeA,IAAQ,CAAA,EACrD,CACA,IAAIC,CAAAA,CACJ,OAAI,OAAO,IAAA,CAAK,MAAA,CAAO,YAAe,UAAA,GAEpCA,CAAAA,CAAAA,CADU,MAAM,IAAA,CAAK,MAAA,CAAO,YAAW,GAC1B,UAAA,CAAA,CAER,CAAE,OAAA,CAASF,EAAW,OAAA,CAAAE,CAAQ,CACvC,CAAA,MAAS,CAAA,CAAQ,CACf,OAAO,CAAE,QAAS,KAAA,CAAO,KAAA,CAAO,GAAG,OAAA,EAAW,MAAA,CAAO,CAAC,CAAE,CAC1D,CACF,CACF","file":"meilisearch.js","sourcesContent":["/**\n * Meilisearch adapter — streams Firestore changes to Meilisearch indexes.\n *\n * @example\n * ```ts\n * import { MeilisearchAdapter } from \"@lpdjs/firestore-repo-service/sync/meilisearch\";\n *\n * const adapter = new MeilisearchAdapter({\n * host: \"http://localhost:7700\",\n * apiKey: \"masterKey\",\n * indexesSettings: {\n * users: {\n * filterableAttributes: [\"role\", \"status\", \"createdAt\"],\n * sortableAttributes: [\"createdAt\", \"name\"],\n * searchableAttributes: [\"name\", \"email\"],\n * },\n * },\n * });\n * ```\n */\n\nimport type { z } from \"zod\";\nimport type { RepoSyncConfig, SyncAdapter, SyncHealthResult } from \"../types\";\n\n/**\n * Minimal structural shape of a Meilisearch client.\n */\nexport interface MeilisearchLike {\n index(indexUid: string): {\n addDocuments(documents: any[], options?: { primaryKey?: string }): Promise<any>;\n deleteDocuments(documentIds: string[] | number[]): Promise<any>;\n getStats(): Promise<any>;\n getRawInfo(): Promise<any>;\n updateSettings(settings: any): Promise<any>;\n [key: string]: any;\n };\n getIndex(indexUid: string): Promise<any>;\n createIndex(indexUid: string, options?: { primaryKey?: string }): Promise<any>;\n isHealthy?(): Promise<any>;\n health?(): Promise<any>;\n getVersion?(): Promise<any>;\n}\n\nexport interface MeilisearchIndexSettings {\n filterableAttributes?: string[];\n sortableAttributes?: string[];\n searchableAttributes?: string[];\n rankingRules?: string[];\n stopWords?: string[];\n synonyms?: Record<string, string[]>;\n distinctAttribute?: string;\n [key: string]: any;\n}\n\nexport interface MeilisearchAdapterOptions {\n /**\n * Host URL of the Meilisearch instance (e.g. `http://localhost:7700` or `https://ms-xxxx.meilisearch.io`).\n * Required if `client` is not provided.\n */\n host?: string;\n /**\n * API Key (e.g. master key or admin key) with permissions to read/write indexes.\n */\n apiKey?: string;\n /**\n * Existing pre-built Meilisearch client instance.\n */\n client?: MeilisearchLike | any;\n /**\n * Custom index settings per target index name (e.g. filterableAttributes, sortableAttributes).\n */\n indexesSettings?: Record<string, MeilisearchIndexSettings>;\n}\n\n/** Lazy-loader for the optional `meilisearch` peer dependency. */\nfunction loadMeilisearchClient(options: MeilisearchAdapterOptions): MeilisearchLike {\n if (options.client) return options.client;\n if (!options.host) {\n throw new Error(\n \"MeilisearchAdapter requires either a `client` instance or a `host` option.\",\n );\n }\n try {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const { MeiliSearch } = require(\"meilisearch\");\n return new MeiliSearch({\n host: options.host,\n apiKey: options.apiKey,\n });\n } catch (err: any) {\n throw new Error(\n `Failed to load the \"meilisearch\" package. Please install it with:\\n` +\n ` bun add meilisearch # or npm install meilisearch\\n` +\n `Original error: ${err?.message ?? String(err)}`,\n );\n }\n}\n\n/**\n * SyncAdapter implementation for Meilisearch.\n */\nexport class MeilisearchAdapter implements SyncAdapter {\n readonly name = \"meilisearch\";\n private _client: MeilisearchLike | null = null;\n private readonly options: MeilisearchAdapterOptions;\n\n constructor(options: MeilisearchAdapterOptions) {\n this.options = options;\n if (options.client) {\n this._client = options.client;\n }\n }\n\n /** Resolved Meilisearch client instance. */\n get client(): MeilisearchLike {\n if (!this._client) {\n this._client = loadMeilisearchClient(this.options);\n }\n return this._client;\n }\n\n // ---------------------------------------------------------------------------\n // SyncAdapter Methods\n // ---------------------------------------------------------------------------\n\n async targetExists(targetName: string): Promise<boolean> {\n try {\n await this.client.getIndex(targetName);\n return true;\n } catch (err: any) {\n if (\n err?.code === \"index_not_found\" ||\n err?.statusCode === 404 ||\n err?.status === 404\n ) {\n return false;\n }\n throw err;\n }\n }\n\n async upsert(\n targetName: string,\n items: Record<string, unknown>[],\n primaryKey: string,\n ): Promise<void> {\n if (items.length === 0) return;\n const index = this.client.index(targetName);\n await index.addDocuments(items, { primaryKey });\n }\n\n async delete(\n targetName: string,\n _primaryKey: string,\n ids: string[],\n ): Promise<void> {\n if (ids.length === 0) return;\n const index = this.client.index(targetName);\n await index.deleteDocuments(ids);\n }\n\n async ensureTarget(options: {\n targetName: string;\n primaryKey: string;\n schema?: z.ZodObject<any>;\n exclude?: string[];\n columnMap?: Record<string, string>;\n }): Promise<void> {\n const { targetName, primaryKey } = options;\n const exists = await this.targetExists(targetName);\n if (!exists) {\n await this.client.createIndex(targetName, { primaryKey });\n }\n\n const settings = this.options.indexesSettings?.[targetName];\n if (settings) {\n const index = this.client.index(targetName);\n await index.updateSettings(settings);\n }\n }\n\n async healthCheck(options: {\n targetName: string;\n primaryKey: string;\n schema?: z.ZodObject<any>;\n repoConfig?: RepoSyncConfig<string>;\n }): Promise<SyncHealthResult> {\n const { targetName } = options;\n try {\n const exists = await this.targetExists(targetName);\n if (!exists) {\n return {\n healthy: false,\n targetName,\n targetExists: false,\n error: `Meilisearch index \"${targetName}\" does not exist`,\n };\n }\n const index = this.client.index(targetName);\n const stats = await index.getStats();\n const rawInfo = typeof index.getRawInfo === \"function\" ? await index.getRawInfo() : {};\n\n return {\n healthy: true,\n targetName,\n targetExists: true,\n error: null,\n details: {\n numberOfDocuments: stats?.numberOfDocuments ?? 0,\n isIndexing: stats?.isIndexing ?? false,\n fieldDistribution: stats?.fieldDistribution ?? {},\n primaryKey: rawInfo?.primaryKey ?? options.primaryKey,\n },\n };\n } catch (err: any) {\n return {\n healthy: false,\n targetName,\n targetExists: false,\n error: err?.message ?? String(err),\n };\n }\n }\n\n /** Verify overall connection and connectivity to the Meilisearch instance. */\n async checkConnection(): Promise<{\n healthy: boolean;\n version?: string;\n error?: string;\n }> {\n try {\n let isHealthy = true;\n if (typeof this.client.isHealthy === \"function\") {\n const res = await this.client.isHealthy();\n isHealthy = res?.status === \"available\" || res === true;\n } else if (typeof this.client.health === \"function\") {\n const res = await this.client.health();\n isHealthy = res?.status === \"available\" || res === true;\n }\n let version: string | undefined;\n if (typeof this.client.getVersion === \"function\") {\n const v = await this.client.getVersion();\n version = v?.pkgVersion;\n }\n return { healthy: isHealthy, version };\n } catch (e: any) {\n return { healthy: false, error: e?.message ?? String(e) };\n }\n }\n}\n"]}
@@ -1,7 +1,8 @@
1
1
  import { b as AuthExtension } from './firebase-auth-Ds5P0kXT.js';
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 };