@lpdjs/firestore-repo-service 2.1.18 → 2.2.0

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,4 +1,5 @@
1
- import { c as SqlDialect, S as SqlAdapter, e as SqlTableDef, d as SqlColumn } from '../types-CbeFN-A9.cjs';
1
+ import { c as SqlDialect, S as SqlAdapter, e as SqlTableDef, d as SqlColumn } from '../types-Vvdx263s.cjs';
2
+ import 'firebase-functions/v2/pubsub';
2
3
 
3
4
  /** Shared BigQuery dialect singleton. */
4
5
  declare const bigqueryDialect: SqlDialect;
@@ -1,4 +1,5 @@
1
- import { c as SqlDialect, S as SqlAdapter, e as SqlTableDef, d as SqlColumn } from '../types-CbeFN-A9.js';
1
+ import { c as SqlDialect, S as SqlAdapter, e as SqlTableDef, d as SqlColumn } from '../types-Vvdx263s.js';
2
+ import 'firebase-functions/v2/pubsub';
2
3
 
3
4
  /** Shared BigQuery dialect singleton. */
4
5
  declare const bigqueryDialect: SqlDialect;
@@ -1,4 +1,4 @@
1
- 'use strict';function re(o){let e=[],t=o.replace(/[.*+?^${}()|[\]\\]/g,a=>a===":"?a:`\\${a}`).replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,(a,s)=>(e.push(s),"([^/]+)"));return {pattern:new RegExp(`^${t}$`),paramNames:e}}function se(o){let e=o.path??o.url??"/",t=e.indexOf("?");return t===-1?e:e.slice(0,t)}var L=class{constructor(){this.routes=[];this.middlewares=[];this.notFoundHandler=(e,t)=>{t.status(404).send("Not Found");};this.errorHandler=(e,t,a)=>{console.error("[MiniRouter]",e),a.status(500).send("Internal Server Error");};}use(e){return this.middlewares.push(e),this}get(e,t){return this.addRoute("GET",e,t)}post(e,t){return this.addRoute("POST",e,t)}put(e,t){return this.addRoute("PUT",e,t)}patch(e,t){return this.addRoute("PATCH",e,t)}delete(e,t){return this.addRoute("DELETE",e,t)}onNotFound(e){return this.notFoundHandler=e,this}onError(e){return this.errorHandler=e,this}addRoute(e,t,a){let{pattern:s,paramNames:u}=re(t);return this.routes.push({method:e.toUpperCase(),pattern:s,paramNames:u,handler:a}),this}async handle(e,t){let a=(e.method??"GET").toUpperCase(),s=se(e),u=null,g={};for(let R of this.routes){if(R.method!==a)continue;let b=s.match(R.pattern);if(b){u=R,g={},R.paramNames.forEach((f,d)=>{g[f]=decodeURIComponent(b[d+1]??"");});break}}let w=Object.assign(e,{params:g}),c=u?u.handler:this.notFoundHandler;try{await this.runMiddlewareChain(w,t,c);}catch(R){this.errorHandler(R,e,t);}}async runMiddlewareChain(e,t,a){let s=0,u=async()=>{if(s<this.middlewares.length){let g=this.middlewares[s++];await g(e,t,u);}else await a(e,t);};await u();}};var ae={string:"ZodString",number:"ZodNumber",bigint:"ZodBigInt",boolean:"ZodBoolean",date:"ZodDate",enum:"ZodEnum",nativeEnum:"ZodNativeEnum",literal:"ZodLiteral",object:"ZodObject",array:"ZodArray",optional:"ZodOptional",nullable:"ZodNullable",default:"ZodDefault",coerce:"ZodCoerce",union:"ZodUnion",undefined:"ZodUndefined",unknown:"ZodUnknown",any:"ZodAny",record:"ZodRecord"};function F(o){let e=o,t=e._zod?.def?.type;if(t)return ae[t]??`Zod${t.charAt(0).toUpperCase()}${t.slice(1)}`;let a=e._def?.typeName;return a||""}function V(o){let e=o;if(e._zod?.def?.innerType)return e._zod.def.innerType;if(e._def?.innerType)return e._def.innerType}function K(o){let e=o;return e.shape&&typeof e.shape=="object"?e.shape:e._zod?.def?.shape&&typeof e._zod.def.shape=="object"?e._zod.def.shape:e._def?.shape?typeof e._def.shape=="function"?e._def.shape():e._def.shape:{}}var O="__sync_version";var ie=new Set(["ZodOptional","ZodNullable","ZodDefault"]);function W(o){let e=o,t=false;for(;;){let a=F(e);if(!ie.has(a))break;(a==="ZodOptional"||a==="ZodNullable")&&(t=true);let s=V(e);if(!s)break;e=s;}return {inner:e,nullable:t}}var J={ZodString:"string",ZodNumber:"number",ZodBigInt:"bigint",ZodBoolean:"boolean",ZodDate:"timestamp",ZodEnum:"string",ZodNativeEnum:"string",ZodLiteral:"string"};function ce(o){let{inner:e}=W(o);return J[F(e)]??"json"}function Y(o,e,t,a,s,u,g,w){for(let[c,R]of Object.entries(o)){let b=t?`${t}__${c}`:c;if(s.has(c)||s.has(b))continue;let{inner:f,nullable:d}=W(R),l=F(f),i=a||d;if(l==="ZodObject"){let r=K(f);Y(r,e,b,i,s,u,g,w);continue}let n=J[l]??"json",p=b===g||c===g,S=u[b]??u[c]??b;w.push({name:S,sqlType:e.mapType(n),nullable:p?false:i,isPrimaryKey:p});}}function _(o,e,t={}){let{primaryKey:a,exclude:s=[],columnMap:u={}}=t,g=new Set(s),w=K(o),c=[];return Y(w,e,"",false,g,u,a,c),c.some(R=>R.name===O)||c.push({name:O,sqlType:e.mapType("bigint"),nullable:true,isPrimaryKey:false,description:"Monotonic publish version (Date.now() ms). Internal."}),c}function Q(o){if(o==null)return null;if(typeof o=="object"&&typeof o.toDate=="function")return o.toDate().toISOString();if(o instanceof Date)return o.toISOString();if(Buffer.isBuffer(o))return o.toString("base64");if(o instanceof Uint8Array)return Buffer.from(o).toString("base64");if(typeof o=="object"&&"latitude"in o&&"longitude"in o){let e=o;return JSON.stringify({lat:e.latitude,lng:e.longitude})}return Array.isArray(o)?JSON.stringify(o.map(Q)):o}function X(o,e,t){for(let[a,s]of Object.entries(o)){let u=e?`${e}__${a}`:a;s!=null&&typeof s=="object"&&!Array.isArray(s)&&!(s instanceof Date)&&!Buffer.isBuffer(s)&&!(s instanceof Uint8Array)&&typeof s.toDate!="function"&&!("latitude"in s&&"longitude"in s)?X(s,u,t):t[u]=Q(s);}}function Z(o,e){let t=new Set(e?.exclude),a=e?.columnMap??{},s={};X(o,"",s);let u={};for(let[g,w]of Object.entries(s)){if(t.has(g))continue;let c=g.split("__")[0];if(c!==g&&t.has(c))continue;let R=a[g]??(g.includes("__")?a[g.split("__").pop()]:void 0)??g;u[R]=w;}return u}function q(o,e){if(process.env.FUNCTIONS_EMULATOR==="true"){let s=process.env.GCLOUD_PROJECT??process.env.GOOGLE_CLOUD_PROJECT??"demo-project",u=process.env.FUNCTION_REGION??"us-central1",g=(process.env.FUNCTION_TARGET??"").replace(/\./g,"-");return `/${s}/${u}/${g}${e}`}let t=process.env.K_SERVICE,a=o.hostname??o.headers?.host??"";return t&&a.includes("cloudfunctions.net")?`/${t.toLowerCase()}${e}`:e}function D(o,e,t){return `<!DOCTYPE html>
1
+ 'use strict';function re(o){let e=[],t=o.replace(/[.*+?^${}()|[\]\\]/g,a=>a===":"?a:`\\${a}`).replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,(a,s)=>(e.push(s),"([^/]+)"));return {pattern:new RegExp(`^${t}$`),paramNames:e}}function se(o){let e=o.path??o.url??"/",t=e.indexOf("?");return t===-1?e:e.slice(0,t)}var L=class{constructor(){this.routes=[];this.middlewares=[];this.notFoundHandler=(e,t)=>{t.status(404).send("Not Found");};this.errorHandler=(e,t,a)=>{console.error("[MiniRouter]",e),a.status(500).send("Internal Server Error");};}use(e){return this.middlewares.push(e),this}get(e,t){return this.addRoute("GET",e,t)}post(e,t){return this.addRoute("POST",e,t)}put(e,t){return this.addRoute("PUT",e,t)}patch(e,t){return this.addRoute("PATCH",e,t)}delete(e,t){return this.addRoute("DELETE",e,t)}onNotFound(e){return this.notFoundHandler=e,this}onError(e){return this.errorHandler=e,this}addRoute(e,t,a){let{pattern:s,paramNames:u}=re(t);return this.routes.push({method:e.toUpperCase(),pattern:s,paramNames:u,handler:a}),this}async handle(e,t){let a=(e.method??"GET").toUpperCase(),s=se(e),u=null,g={};for(let R of this.routes){if(R.method!==a)continue;let b=s.match(R.pattern);if(b){u=R,g={},R.paramNames.forEach((f,d)=>{g[f]=decodeURIComponent(b[d+1]??"");});break}}let w=Object.assign(e,{params:g}),c=u?u.handler:this.notFoundHandler;try{await this.runMiddlewareChain(w,t,c);}catch(R){this.errorHandler(R,e,t);}}async runMiddlewareChain(e,t,a){let s=0,u=async()=>{if(s<this.middlewares.length){let g=this.middlewares[s++];await g(e,t,u);}else await a(e,t);};await u();}};var ae={string:"ZodString",number:"ZodNumber",bigint:"ZodBigInt",boolean:"ZodBoolean",date:"ZodDate",enum:"ZodEnum",nativeEnum:"ZodNativeEnum",literal:"ZodLiteral",object:"ZodObject",array:"ZodArray",optional:"ZodOptional",nullable:"ZodNullable",default:"ZodDefault",coerce:"ZodCoerce",union:"ZodUnion",undefined:"ZodUndefined",unknown:"ZodUnknown",any:"ZodAny",record:"ZodRecord"};function F(o){let e=o,t=e._zod?.def?.type;if(t)return ae[t]??`Zod${t.charAt(0).toUpperCase()}${t.slice(1)}`;let a=e._def?.typeName;return a||""}function W(o){let e=o;if(e._zod?.def?.innerType)return e._zod.def.innerType;if(e._def?.innerType)return e._def.innerType}function K(o){let e=o;return e.shape&&typeof e.shape=="object"?e.shape:e._zod?.def?.shape&&typeof e._zod.def.shape=="object"?e._zod.def.shape:e._def?.shape?typeof e._def.shape=="function"?e._def.shape():e._def.shape:{}}var O="__sync_version";var ie=new Set(["ZodOptional","ZodNullable","ZodDefault"]);function V(o){let e=o,t=false;for(;;){let a=F(e);if(!ie.has(a))break;(a==="ZodOptional"||a==="ZodNullable")&&(t=true);let s=W(e);if(!s)break;e=s;}return {inner:e,nullable:t}}var J={ZodString:"string",ZodNumber:"number",ZodBigInt:"bigint",ZodBoolean:"boolean",ZodDate:"timestamp",ZodEnum:"string",ZodNativeEnum:"string",ZodLiteral:"string"};function ce(o){let{inner:e}=V(o);return J[F(e)]??"json"}function Y(o,e,t,a,s,u,g,w){for(let[c,R]of Object.entries(o)){let b=t?`${t}__${c}`:c;if(s.has(c)||s.has(b))continue;let{inner:f,nullable:d}=V(R),l=F(f),i=a||d;if(l==="ZodObject"){let r=K(f);Y(r,e,b,i,s,u,g,w);continue}let n=J[l]??"json",p=b===g||c===g,S=u[b]??u[c]??b;w.push({name:S,sqlType:e.mapType(n),nullable:p?false:i,isPrimaryKey:p});}}function _(o,e,t={}){let{primaryKey:a,exclude:s=[],columnMap:u={}}=t,g=new Set(s),w=K(o),c=[];return Y(w,e,"",false,g,u,a,c),c.some(R=>R.name===O)||c.push({name:O,sqlType:e.mapType("bigint"),nullable:true,isPrimaryKey:false,description:"Monotonic publish version (Date.now() ms). Internal."}),c}function Q(o){if(o==null)return null;if(typeof o=="object"&&typeof o.toDate=="function")return o.toDate().toISOString();if(o instanceof Date)return o.toISOString();if(Buffer.isBuffer(o))return o.toString("base64");if(o instanceof Uint8Array)return Buffer.from(o).toString("base64");if(typeof o=="object"&&"latitude"in o&&"longitude"in o){let e=o;return JSON.stringify({lat:e.latitude,lng:e.longitude})}return Array.isArray(o)?JSON.stringify(o.map(Q)):o}function X(o,e,t){for(let[a,s]of Object.entries(o)){let u=e?`${e}__${a}`:a;s!=null&&typeof s=="object"&&!Array.isArray(s)&&!(s instanceof Date)&&!Buffer.isBuffer(s)&&!(s instanceof Uint8Array)&&typeof s.toDate!="function"&&!("latitude"in s&&"longitude"in s)?X(s,u,t):t[u]=Q(s);}}function Z(o,e){let t=new Set(e?.exclude),a=e?.columnMap??{},s={};X(o,"",s);let u={};for(let[g,w]of Object.entries(s)){if(t.has(g))continue;let c=g.split("__")[0];if(c!==g&&t.has(c))continue;let R=a[g]??(g.includes("__")?a[g.split("__").pop()]:void 0)??g;u[R]=w;}return u}function q(o,e){if(process.env.FUNCTIONS_EMULATOR==="true"){let s=process.env.GCLOUD_PROJECT??process.env.GOOGLE_CLOUD_PROJECT??"demo-project",u=process.env.FUNCTION_REGION??"us-central1",g=(process.env.FUNCTION_TARGET??"").replace(/\./g,"-");return `/${s}/${u}/${g}${e}`}let t=process.env.K_SERVICE,a=o.hostname??o.headers?.host??"";return t&&a.includes("cloudfunctions.net")?`/${t.toLowerCase()}${e}`:e}function D(o,e,t){return `<!DOCTYPE html>
2
2
  <html lang="en"><head>
3
3
  <meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
4
4
  <title>${o} \u2014 Sync Admin</title>
@@ -1,6 +1,7 @@
1
- import { S as SqlAdapter, a as SyncEvent, b as adminsyncConfig, R as RepoSyncConfig, P as PubSubClientDep, F as FirestoreSyncConfig, c as SqlDialect, d as SqlColumn, e as SqlTableDef, G as GenerateDDLConfig, L as LogicalType, f as SyncTriggersConfig, g as SyncWorkerConfig } from '../types-CbeFN-A9.cjs';
2
- export { h as FirestoreTriggersDep, O as OrFactory, i as PubSubHandlerDep, j as SyncDeps, k as SyncOperation, l as adminsyncBasicAuth, m as adminsyncFeaturesFlag } from '../types-CbeFN-A9.cjs';
1
+ import { S as SqlAdapter, a as SyncEvent, b as adminsyncConfig, R as RepoSyncConfig, P as PubSubClientDep, F as FirestoreSyncConfig, c as SqlDialect, d as SqlColumn, e as SqlTableDef, G as GenerateDDLConfig, L as LogicalType, f as SyncTriggersConfig, g as SyncWorkerConfig } from '../types-Vvdx263s.cjs';
2
+ export { h as FirestoreTriggersDep, O as OrFactory, i as PubSubHandlerDep, j as SyncDeps, k as SyncOperation, l as SyncWorkerOptions, m as adminsyncBasicAuth, n as adminsyncFeaturesFlag } from '../types-Vvdx263s.cjs';
3
3
  import { z } from 'zod';
4
+ import 'firebase-functions/v2/pubsub';
4
5
 
5
6
  /**
6
7
  * Per-repo in-memory batch buffer.
@@ -1,6 +1,7 @@
1
- import { S as SqlAdapter, a as SyncEvent, b as adminsyncConfig, R as RepoSyncConfig, P as PubSubClientDep, F as FirestoreSyncConfig, c as SqlDialect, d as SqlColumn, e as SqlTableDef, G as GenerateDDLConfig, L as LogicalType, f as SyncTriggersConfig, g as SyncWorkerConfig } from '../types-CbeFN-A9.js';
2
- export { h as FirestoreTriggersDep, O as OrFactory, i as PubSubHandlerDep, j as SyncDeps, k as SyncOperation, l as adminsyncBasicAuth, m as adminsyncFeaturesFlag } from '../types-CbeFN-A9.js';
1
+ import { S as SqlAdapter, a as SyncEvent, b as adminsyncConfig, R as RepoSyncConfig, P as PubSubClientDep, F as FirestoreSyncConfig, c as SqlDialect, d as SqlColumn, e as SqlTableDef, G as GenerateDDLConfig, L as LogicalType, f as SyncTriggersConfig, g as SyncWorkerConfig } from '../types-Vvdx263s.js';
2
+ export { h as FirestoreTriggersDep, O as OrFactory, i as PubSubHandlerDep, j as SyncDeps, k as SyncOperation, l as SyncWorkerOptions, m as adminsyncBasicAuth, n as adminsyncFeaturesFlag } from '../types-Vvdx263s.js';
3
3
  import { z } from 'zod';
4
+ import 'firebase-functions/v2/pubsub';
4
5
 
5
6
  /**
6
7
  * Per-repo in-memory batch buffer.
@@ -1,4 +1,4 @@
1
- function re(o){let e=[],t=o.replace(/[.*+?^${}()|[\]\\]/g,a=>a===":"?a:`\\${a}`).replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,(a,s)=>(e.push(s),"([^/]+)"));return {pattern:new RegExp(`^${t}$`),paramNames:e}}function se(o){let e=o.path??o.url??"/",t=e.indexOf("?");return t===-1?e:e.slice(0,t)}var L=class{constructor(){this.routes=[];this.middlewares=[];this.notFoundHandler=(e,t)=>{t.status(404).send("Not Found");};this.errorHandler=(e,t,a)=>{console.error("[MiniRouter]",e),a.status(500).send("Internal Server Error");};}use(e){return this.middlewares.push(e),this}get(e,t){return this.addRoute("GET",e,t)}post(e,t){return this.addRoute("POST",e,t)}put(e,t){return this.addRoute("PUT",e,t)}patch(e,t){return this.addRoute("PATCH",e,t)}delete(e,t){return this.addRoute("DELETE",e,t)}onNotFound(e){return this.notFoundHandler=e,this}onError(e){return this.errorHandler=e,this}addRoute(e,t,a){let{pattern:s,paramNames:u}=re(t);return this.routes.push({method:e.toUpperCase(),pattern:s,paramNames:u,handler:a}),this}async handle(e,t){let a=(e.method??"GET").toUpperCase(),s=se(e),u=null,g={};for(let R of this.routes){if(R.method!==a)continue;let b=s.match(R.pattern);if(b){u=R,g={},R.paramNames.forEach((f,d)=>{g[f]=decodeURIComponent(b[d+1]??"");});break}}let w=Object.assign(e,{params:g}),c=u?u.handler:this.notFoundHandler;try{await this.runMiddlewareChain(w,t,c);}catch(R){this.errorHandler(R,e,t);}}async runMiddlewareChain(e,t,a){let s=0,u=async()=>{if(s<this.middlewares.length){let g=this.middlewares[s++];await g(e,t,u);}else await a(e,t);};await u();}};var ae={string:"ZodString",number:"ZodNumber",bigint:"ZodBigInt",boolean:"ZodBoolean",date:"ZodDate",enum:"ZodEnum",nativeEnum:"ZodNativeEnum",literal:"ZodLiteral",object:"ZodObject",array:"ZodArray",optional:"ZodOptional",nullable:"ZodNullable",default:"ZodDefault",coerce:"ZodCoerce",union:"ZodUnion",undefined:"ZodUndefined",unknown:"ZodUnknown",any:"ZodAny",record:"ZodRecord"};function F(o){let e=o,t=e._zod?.def?.type;if(t)return ae[t]??`Zod${t.charAt(0).toUpperCase()}${t.slice(1)}`;let a=e._def?.typeName;return a||""}function V(o){let e=o;if(e._zod?.def?.innerType)return e._zod.def.innerType;if(e._def?.innerType)return e._def.innerType}function K(o){let e=o;return e.shape&&typeof e.shape=="object"?e.shape:e._zod?.def?.shape&&typeof e._zod.def.shape=="object"?e._zod.def.shape:e._def?.shape?typeof e._def.shape=="function"?e._def.shape():e._def.shape:{}}var O="__sync_version";var ie=new Set(["ZodOptional","ZodNullable","ZodDefault"]);function W(o){let e=o,t=false;for(;;){let a=F(e);if(!ie.has(a))break;(a==="ZodOptional"||a==="ZodNullable")&&(t=true);let s=V(e);if(!s)break;e=s;}return {inner:e,nullable:t}}var J={ZodString:"string",ZodNumber:"number",ZodBigInt:"bigint",ZodBoolean:"boolean",ZodDate:"timestamp",ZodEnum:"string",ZodNativeEnum:"string",ZodLiteral:"string"};function ce(o){let{inner:e}=W(o);return J[F(e)]??"json"}function Y(o,e,t,a,s,u,g,w){for(let[c,R]of Object.entries(o)){let b=t?`${t}__${c}`:c;if(s.has(c)||s.has(b))continue;let{inner:f,nullable:d}=W(R),l=F(f),i=a||d;if(l==="ZodObject"){let r=K(f);Y(r,e,b,i,s,u,g,w);continue}let n=J[l]??"json",p=b===g||c===g,S=u[b]??u[c]??b;w.push({name:S,sqlType:e.mapType(n),nullable:p?false:i,isPrimaryKey:p});}}function _(o,e,t={}){let{primaryKey:a,exclude:s=[],columnMap:u={}}=t,g=new Set(s),w=K(o),c=[];return Y(w,e,"",false,g,u,a,c),c.some(R=>R.name===O)||c.push({name:O,sqlType:e.mapType("bigint"),nullable:true,isPrimaryKey:false,description:"Monotonic publish version (Date.now() ms). Internal."}),c}function Q(o){if(o==null)return null;if(typeof o=="object"&&typeof o.toDate=="function")return o.toDate().toISOString();if(o instanceof Date)return o.toISOString();if(Buffer.isBuffer(o))return o.toString("base64");if(o instanceof Uint8Array)return Buffer.from(o).toString("base64");if(typeof o=="object"&&"latitude"in o&&"longitude"in o){let e=o;return JSON.stringify({lat:e.latitude,lng:e.longitude})}return Array.isArray(o)?JSON.stringify(o.map(Q)):o}function X(o,e,t){for(let[a,s]of Object.entries(o)){let u=e?`${e}__${a}`:a;s!=null&&typeof s=="object"&&!Array.isArray(s)&&!(s instanceof Date)&&!Buffer.isBuffer(s)&&!(s instanceof Uint8Array)&&typeof s.toDate!="function"&&!("latitude"in s&&"longitude"in s)?X(s,u,t):t[u]=Q(s);}}function Z(o,e){let t=new Set(e?.exclude),a=e?.columnMap??{},s={};X(o,"",s);let u={};for(let[g,w]of Object.entries(s)){if(t.has(g))continue;let c=g.split("__")[0];if(c!==g&&t.has(c))continue;let R=a[g]??(g.includes("__")?a[g.split("__").pop()]:void 0)??g;u[R]=w;}return u}function q(o,e){if(process.env.FUNCTIONS_EMULATOR==="true"){let s=process.env.GCLOUD_PROJECT??process.env.GOOGLE_CLOUD_PROJECT??"demo-project",u=process.env.FUNCTION_REGION??"us-central1",g=(process.env.FUNCTION_TARGET??"").replace(/\./g,"-");return `/${s}/${u}/${g}${e}`}let t=process.env.K_SERVICE,a=o.hostname??o.headers?.host??"";return t&&a.includes("cloudfunctions.net")?`/${t.toLowerCase()}${e}`:e}function D(o,e,t){return `<!DOCTYPE html>
1
+ function re(o){let e=[],t=o.replace(/[.*+?^${}()|[\]\\]/g,a=>a===":"?a:`\\${a}`).replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,(a,s)=>(e.push(s),"([^/]+)"));return {pattern:new RegExp(`^${t}$`),paramNames:e}}function se(o){let e=o.path??o.url??"/",t=e.indexOf("?");return t===-1?e:e.slice(0,t)}var L=class{constructor(){this.routes=[];this.middlewares=[];this.notFoundHandler=(e,t)=>{t.status(404).send("Not Found");};this.errorHandler=(e,t,a)=>{console.error("[MiniRouter]",e),a.status(500).send("Internal Server Error");};}use(e){return this.middlewares.push(e),this}get(e,t){return this.addRoute("GET",e,t)}post(e,t){return this.addRoute("POST",e,t)}put(e,t){return this.addRoute("PUT",e,t)}patch(e,t){return this.addRoute("PATCH",e,t)}delete(e,t){return this.addRoute("DELETE",e,t)}onNotFound(e){return this.notFoundHandler=e,this}onError(e){return this.errorHandler=e,this}addRoute(e,t,a){let{pattern:s,paramNames:u}=re(t);return this.routes.push({method:e.toUpperCase(),pattern:s,paramNames:u,handler:a}),this}async handle(e,t){let a=(e.method??"GET").toUpperCase(),s=se(e),u=null,g={};for(let R of this.routes){if(R.method!==a)continue;let b=s.match(R.pattern);if(b){u=R,g={},R.paramNames.forEach((f,d)=>{g[f]=decodeURIComponent(b[d+1]??"");});break}}let w=Object.assign(e,{params:g}),c=u?u.handler:this.notFoundHandler;try{await this.runMiddlewareChain(w,t,c);}catch(R){this.errorHandler(R,e,t);}}async runMiddlewareChain(e,t,a){let s=0,u=async()=>{if(s<this.middlewares.length){let g=this.middlewares[s++];await g(e,t,u);}else await a(e,t);};await u();}};var ae={string:"ZodString",number:"ZodNumber",bigint:"ZodBigInt",boolean:"ZodBoolean",date:"ZodDate",enum:"ZodEnum",nativeEnum:"ZodNativeEnum",literal:"ZodLiteral",object:"ZodObject",array:"ZodArray",optional:"ZodOptional",nullable:"ZodNullable",default:"ZodDefault",coerce:"ZodCoerce",union:"ZodUnion",undefined:"ZodUndefined",unknown:"ZodUnknown",any:"ZodAny",record:"ZodRecord"};function F(o){let e=o,t=e._zod?.def?.type;if(t)return ae[t]??`Zod${t.charAt(0).toUpperCase()}${t.slice(1)}`;let a=e._def?.typeName;return a||""}function W(o){let e=o;if(e._zod?.def?.innerType)return e._zod.def.innerType;if(e._def?.innerType)return e._def.innerType}function K(o){let e=o;return e.shape&&typeof e.shape=="object"?e.shape:e._zod?.def?.shape&&typeof e._zod.def.shape=="object"?e._zod.def.shape:e._def?.shape?typeof e._def.shape=="function"?e._def.shape():e._def.shape:{}}var O="__sync_version";var ie=new Set(["ZodOptional","ZodNullable","ZodDefault"]);function V(o){let e=o,t=false;for(;;){let a=F(e);if(!ie.has(a))break;(a==="ZodOptional"||a==="ZodNullable")&&(t=true);let s=W(e);if(!s)break;e=s;}return {inner:e,nullable:t}}var J={ZodString:"string",ZodNumber:"number",ZodBigInt:"bigint",ZodBoolean:"boolean",ZodDate:"timestamp",ZodEnum:"string",ZodNativeEnum:"string",ZodLiteral:"string"};function ce(o){let{inner:e}=V(o);return J[F(e)]??"json"}function Y(o,e,t,a,s,u,g,w){for(let[c,R]of Object.entries(o)){let b=t?`${t}__${c}`:c;if(s.has(c)||s.has(b))continue;let{inner:f,nullable:d}=V(R),l=F(f),i=a||d;if(l==="ZodObject"){let r=K(f);Y(r,e,b,i,s,u,g,w);continue}let n=J[l]??"json",p=b===g||c===g,S=u[b]??u[c]??b;w.push({name:S,sqlType:e.mapType(n),nullable:p?false:i,isPrimaryKey:p});}}function _(o,e,t={}){let{primaryKey:a,exclude:s=[],columnMap:u={}}=t,g=new Set(s),w=K(o),c=[];return Y(w,e,"",false,g,u,a,c),c.some(R=>R.name===O)||c.push({name:O,sqlType:e.mapType("bigint"),nullable:true,isPrimaryKey:false,description:"Monotonic publish version (Date.now() ms). Internal."}),c}function Q(o){if(o==null)return null;if(typeof o=="object"&&typeof o.toDate=="function")return o.toDate().toISOString();if(o instanceof Date)return o.toISOString();if(Buffer.isBuffer(o))return o.toString("base64");if(o instanceof Uint8Array)return Buffer.from(o).toString("base64");if(typeof o=="object"&&"latitude"in o&&"longitude"in o){let e=o;return JSON.stringify({lat:e.latitude,lng:e.longitude})}return Array.isArray(o)?JSON.stringify(o.map(Q)):o}function X(o,e,t){for(let[a,s]of Object.entries(o)){let u=e?`${e}__${a}`:a;s!=null&&typeof s=="object"&&!Array.isArray(s)&&!(s instanceof Date)&&!Buffer.isBuffer(s)&&!(s instanceof Uint8Array)&&typeof s.toDate!="function"&&!("latitude"in s&&"longitude"in s)?X(s,u,t):t[u]=Q(s);}}function Z(o,e){let t=new Set(e?.exclude),a=e?.columnMap??{},s={};X(o,"",s);let u={};for(let[g,w]of Object.entries(s)){if(t.has(g))continue;let c=g.split("__")[0];if(c!==g&&t.has(c))continue;let R=a[g]??(g.includes("__")?a[g.split("__").pop()]:void 0)??g;u[R]=w;}return u}function q(o,e){if(process.env.FUNCTIONS_EMULATOR==="true"){let s=process.env.GCLOUD_PROJECT??process.env.GOOGLE_CLOUD_PROJECT??"demo-project",u=process.env.FUNCTION_REGION??"us-central1",g=(process.env.FUNCTION_TARGET??"").replace(/\./g,"-");return `/${s}/${u}/${g}${e}`}let t=process.env.K_SERVICE,a=o.hostname??o.headers?.host??"";return t&&a.includes("cloudfunctions.net")?`/${t.toLowerCase()}${e}`:e}function D(o,e,t){return `<!DOCTYPE html>
2
2
  <html lang="en"><head>
3
3
  <meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
4
4
  <title>${o} \u2014 Sync Admin</title>
@@ -1,3 +1,5 @@
1
+ import { PubSubOptions } from 'firebase-functions/v2/pubsub';
2
+
1
3
  /**
2
4
  * Types and interfaces for the Firestore → SQL sync module.
3
5
  *
@@ -5,6 +7,13 @@
5
7
  * worker) and any SQL backend (BigQuery, PostgreSQL, …). Only the adapter
6
8
  * touches the database SDK; everything else works with these abstractions.
7
9
  */
10
+
11
+ /**
12
+ * Cloud Functions v2 options forwarded to `onMessagePublished()` for every
13
+ * sync worker handler. The `topic` field is omitted because the library sets
14
+ * it itself from `topicPrefix` + repo name.
15
+ */
16
+ type SyncWorkerOptions = Omit<PubSubOptions, "topic">;
8
17
  /** A value that can be provided directly or as a lazy factory function. */
9
18
  type OrFactory<T> = T | (() => T);
10
19
  /** A single column in a SQL table. */
@@ -223,7 +232,7 @@ interface SyncWorkerConfig<M = Record<string, any>> {
223
232
  * workerOptions: { concurrency: 10, maxInstances: 10, memory: "512MiB" }
224
233
  * ```
225
234
  */
226
- workerOptions?: Record<string, unknown>;
235
+ workerOptions?: SyncWorkerOptions;
227
236
  /** Per-repo overrides */
228
237
  repos?: TypedRepoSyncConfigs<M>;
229
238
  }
@@ -309,7 +318,7 @@ interface FirestoreSyncConfig<M = Record<string, any>> {
309
318
  * worker handler. Use to tune `concurrency`, `maxInstances`, `minInstances`,
310
319
  * `memory`, `timeoutSeconds`, `region`, `cpu`, etc.
311
320
  */
312
- workerOptions?: Record<string, unknown>;
321
+ workerOptions?: SyncWorkerOptions;
313
322
  /**
314
323
  * Optional sync admin endpoint. When provided, a `adminsync` handler is
315
324
  * added to `sync.functions` exposing health-check, force-sync, and queue
@@ -320,4 +329,4 @@ interface FirestoreSyncConfig<M = Record<string, any>> {
320
329
  repos?: TypedRepoSyncConfigs<M>;
321
330
  }
322
331
 
323
- export type { FirestoreSyncConfig as F, GenerateDDLConfig as G, LogicalType as L, OrFactory as O, PubSubClientDep as P, RepoSyncConfig as R, SqlAdapter as S, SyncEvent as a, adminsyncConfig as b, SqlDialect as c, SqlColumn as d, SqlTableDef as e, SyncTriggersConfig as f, SyncWorkerConfig as g, FirestoreTriggersDep as h, PubSubHandlerDep as i, SyncDeps as j, SyncOperation as k, adminsyncBasicAuth as l, adminsyncFeaturesFlag as m };
332
+ export type { FirestoreSyncConfig as F, GenerateDDLConfig as G, LogicalType as L, OrFactory as O, PubSubClientDep as P, RepoSyncConfig as R, SqlAdapter as S, SyncEvent as a, adminsyncConfig as b, SqlDialect as c, SqlColumn as d, SqlTableDef 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 };
@@ -1,3 +1,5 @@
1
+ import { PubSubOptions } from 'firebase-functions/v2/pubsub';
2
+
1
3
  /**
2
4
  * Types and interfaces for the Firestore → SQL sync module.
3
5
  *
@@ -5,6 +7,13 @@
5
7
  * worker) and any SQL backend (BigQuery, PostgreSQL, …). Only the adapter
6
8
  * touches the database SDK; everything else works with these abstractions.
7
9
  */
10
+
11
+ /**
12
+ * Cloud Functions v2 options forwarded to `onMessagePublished()` for every
13
+ * sync worker handler. The `topic` field is omitted because the library sets
14
+ * it itself from `topicPrefix` + repo name.
15
+ */
16
+ type SyncWorkerOptions = Omit<PubSubOptions, "topic">;
8
17
  /** A value that can be provided directly or as a lazy factory function. */
9
18
  type OrFactory<T> = T | (() => T);
10
19
  /** A single column in a SQL table. */
@@ -223,7 +232,7 @@ interface SyncWorkerConfig<M = Record<string, any>> {
223
232
  * workerOptions: { concurrency: 10, maxInstances: 10, memory: "512MiB" }
224
233
  * ```
225
234
  */
226
- workerOptions?: Record<string, unknown>;
235
+ workerOptions?: SyncWorkerOptions;
227
236
  /** Per-repo overrides */
228
237
  repos?: TypedRepoSyncConfigs<M>;
229
238
  }
@@ -309,7 +318,7 @@ interface FirestoreSyncConfig<M = Record<string, any>> {
309
318
  * worker handler. Use to tune `concurrency`, `maxInstances`, `minInstances`,
310
319
  * `memory`, `timeoutSeconds`, `region`, `cpu`, etc.
311
320
  */
312
- workerOptions?: Record<string, unknown>;
321
+ workerOptions?: SyncWorkerOptions;
313
322
  /**
314
323
  * Optional sync admin endpoint. When provided, a `adminsync` handler is
315
324
  * added to `sync.functions` exposing health-check, force-sync, and queue
@@ -320,4 +329,4 @@ interface FirestoreSyncConfig<M = Record<string, any>> {
320
329
  repos?: TypedRepoSyncConfigs<M>;
321
330
  }
322
331
 
323
- export type { FirestoreSyncConfig as F, GenerateDDLConfig as G, LogicalType as L, OrFactory as O, PubSubClientDep as P, RepoSyncConfig as R, SqlAdapter as S, SyncEvent as a, adminsyncConfig as b, SqlDialect as c, SqlColumn as d, SqlTableDef as e, SyncTriggersConfig as f, SyncWorkerConfig as g, FirestoreTriggersDep as h, PubSubHandlerDep as i, SyncDeps as j, SyncOperation as k, adminsyncBasicAuth as l, adminsyncFeaturesFlag as m };
332
+ export type { FirestoreSyncConfig as F, GenerateDDLConfig as G, LogicalType as L, OrFactory as O, PubSubClientDep as P, RepoSyncConfig as R, SqlAdapter as S, SyncEvent as a, adminsyncConfig as b, SqlDialect as c, SqlColumn as d, SqlTableDef 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lpdjs/firestore-repo-service",
3
- "version": "2.1.18",
3
+ "version": "2.2.0",
4
4
  "description": "⚡ Type-safe Firestore ORM with auto-generated repositories, advanced queries, relations with typed select, pagination with include, batch/bulk operations, aggregations and transactions.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",