@lunora/server 1.0.0-alpha.81 → 1.0.0-alpha.83

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.
package/dist/index.d.mts CHANGED
@@ -1757,7 +1757,8 @@ interface TableBuilder<Shape extends Record<string, Validator> = Record<string,
1757
1757
  * `filterFields` (at most 16) lists the columns `.eq()` may narrow by inside
1758
1758
  * the search. `language` selects the text analysis (accent folding always,
1759
1759
  * plus that language's stopwords). `staged: true` skips the migration-time
1760
- * backfill on a large existing table. `strategy: "native"` uses the engine's
1760
+ * backfill on a large existing table pre-existing rows stay unsearchable
1761
+ * until `__lunora_admin__:backfillSearch` is run against the deployment. `strategy: "native"` uses the engine's
1761
1762
  * own full-text index where it has one (Postgres) — faster on large corpora,
1762
1763
  * at the cost of the engine ranking rather than the shared scorer.
1763
1764
  */
package/dist/index.d.ts CHANGED
@@ -1757,7 +1757,8 @@ interface TableBuilder<Shape extends Record<string, Validator> = Record<string,
1757
1757
  * `filterFields` (at most 16) lists the columns `.eq()` may narrow by inside
1758
1758
  * the search. `language` selects the text analysis (accent folding always,
1759
1759
  * plus that language's stopwords). `staged: true` skips the migration-time
1760
- * backfill on a large existing table. `strategy: "native"` uses the engine's
1760
+ * backfill on a large existing table pre-existing rows stay unsearchable
1761
+ * until `__lunora_admin__:backfillSearch` is run against the deployment. `strategy: "native"` uses the engine's
1761
1762
  * own full-text index where it has one (Postgres) — faster on large corpora,
1762
1763
  * at the cost of the engine ranking rather than the shared scorer.
1763
1764
  */
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{initLunora as t}from"./packem_shared/initLunora-B2sfmFJ6.mjs";import{createSecrets as i}from"./packem_shared/createSecrets-CyrEddTF.mjs";import{LunoraEnvError as f,defineEnv as s,redactSecrets as m}from"./packem_shared/LunoraEnvError-ByvihJFy.mjs";import{LunoraError as p}from"./packem_shared/LunoraError-DcKdk9Ti.mjs";import{bindOrm as c,bindTableFacade as l}from"./packem_shared/bindOrm-lWdeDi9P.mjs";import{httpAction as E,httpRoute as g,httpRouter as S,isSafeHeaderValue as R,serveStorageObject as h}from"./packem_shared/httpAction-D3b9-YiY.mjs";import{defineIdentity as I}from"./packem_shared/defineIdentity-DwkNKwYa.mjs";import{onConnect as b,onDisconnect as A,onShardInit as T}from"./packem_shared/onConnect-BLRoOpv2.mjs";import{DEFAULT_LIMIT as M,DEFAULT_MAX_LIMIT as _,clampLimit as D,defineListArgs as F}from"./packem_shared/DEFAULT_LIMIT-DC-M6faS.mjs";import{defineMigration as C}from"./packem_shared/defineMigration-7GI9Qbtd.mjs";import{defineMutator as V}from"./packem_shared/defineMutator-DKy8UtbB.mjs";import{c as O,d as U,a as j,b as w,e as B,f as W,g as H,h as J,i as Q,j as X,k as q,m as z}from"./packem_shared/plugin-DQcLxTx1.mjs";import{PRESENCE_DEFAULT_TTL_MS as K,PRESENCE_TABLE as Y,definePresence as Z,presenceExtension as $}from"./packem_shared/PRESENCE_DEFAULT_TTL_MS-BpSPSCwL.mjs";import{protectPublic as re}from"./packem_shared/protectPublic-Bo4G9xaV.mjs";import{onQueryChange as te}from"./packem_shared/onQueryChange-gepYD6KC.mjs";import{defineShape as ie}from"./packem_shared/defineShape-DYxbNl5W.mjs";import{anyApi as fe}from"./types.mjs";import{cronJobs as me}from"@lunora/scheduler";import{ValidationError as pe,v as xe}from"@lunora/values";import{allowAll as le,deny as ue,isDeny as Ee,toWhereInput as ge}from"./packem_shared/allowAll-DkRAgItV.mjs";import{asBucketStorage as Re}from"./packem_shared/asBucketStorage-BthCnWop.mjs";import{buildMaskRegistry as Le}from"./packem_shared/buildMaskRegistry-72SL8fJn.mjs";import{buildRlsReadRegistry as Pe,composeShapeReadWhere as be}from"./packem_shared/buildRlsReadRegistry-Deq8inqS.mjs";import{createPolicyDsl as Te,definePermission as ye,definePolicies as Me,definePolicy as _e,defineRole as De}from"./packem_shared/createPolicyDsl-DNfByAUX.mjs";import{defineStorageRule as ke,defineStorageRules as Ce}from"./packem_shared/defineStorageRule-BvxHVq3b.mjs";import{mask as Ve}from"./packem_shared/mask-CfHNITgg.mjs";import{r as Oe}from"./packem_shared/middleware-DEW0yLvU.mjs";import{storageRules as je}from"./packem_shared/storageRules-CyaiZ0av.mjs";const e="0.0.0";export{M as DEFAULT_LIMIT,_ as DEFAULT_MAX_LIMIT,f as LunoraEnvError,p as LunoraError,K as PRESENCE_DEFAULT_TTL_MS,Y as PRESENCE_TABLE,e as VERSION,pe as ValidationError,le as allowAll,fe as anyApi,Re as asBucketStorage,c as bindOrm,l as bindTableFacade,Le as buildMaskRegistry,Pe as buildRlsReadRegistry,D as clampLimit,O as composePluginMiddleware,be as composeShapeReadWhere,Te as createPolicyDsl,i as createSecrets,me as cronJobs,U as defineAggregateIndex,j as defineComponent,s as defineEnv,I as defineIdentity,F as defineListArgs,C as defineMigration,V as defineMutator,ye as definePermission,w as definePlugin,Me as definePolicies,_e as definePolicy,Z as definePresence,B as defineRankIndex,De as defineRole,W as defineSchema,H as defineSchemaExtension,ie as defineShape,ke as defineStorageRule,Ce as defineStorageRules,J as defineTable,Q as defineVectorIndex,ue as deny,E as httpAction,g as httpRoute,S as httpRouter,X as indexFieldsFromSchema,t as initLunora,q as installPlugins,Ee as isDeny,R as isSafeHeaderValue,Ve as mask,z as mergeSchemaExtension,b as onConnect,A as onDisconnect,te as onQueryChange,T as onShardInit,$ as presenceExtension,re as protectPublic,m as redactSecrets,Oe as rls,h as serveStorageObject,je as storageRules,ge as toWhereInput,xe as v};
1
+ import{initLunora as t}from"./packem_shared/initLunora-B2sfmFJ6.mjs";import{createSecrets as i}from"./packem_shared/createSecrets-CyrEddTF.mjs";import{LunoraEnvError as f,defineEnv as s,redactSecrets as m}from"./packem_shared/LunoraEnvError-ByvihJFy.mjs";import{LunoraError as p}from"./packem_shared/LunoraError-DcKdk9Ti.mjs";import{bindOrm as c,bindTableFacade as l}from"./packem_shared/bindOrm-lWdeDi9P.mjs";import{httpAction as E,httpRoute as g,httpRouter as S,isSafeHeaderValue as R,serveStorageObject as h}from"./packem_shared/httpAction-D3b9-YiY.mjs";import{defineIdentity as I}from"./packem_shared/defineIdentity-DwkNKwYa.mjs";import{onConnect as b,onDisconnect as A,onShardInit as T}from"./packem_shared/onConnect-BLRoOpv2.mjs";import{DEFAULT_LIMIT as M,DEFAULT_MAX_LIMIT as _,clampLimit as D,defineListArgs as F}from"./packem_shared/DEFAULT_LIMIT-DC-M6faS.mjs";import{defineMigration as C}from"./packem_shared/defineMigration-7GI9Qbtd.mjs";import{defineMutator as V}from"./packem_shared/defineMutator-DKy8UtbB.mjs";import{c as O,d as U,a as j,b as w,e as B,f as W,g as H,h as J,i as Q,j as X,k as q,m as z}from"./packem_shared/plugin-DQcLxTx1.mjs";import{PRESENCE_DEFAULT_TTL_MS as K,PRESENCE_TABLE as Y,definePresence as Z,presenceExtension as $}from"./packem_shared/PRESENCE_DEFAULT_TTL_MS-BpSPSCwL.mjs";import{protectPublic as re}from"./packem_shared/protectPublic-Bo4G9xaV.mjs";import{onQueryChange as te}from"./packem_shared/onQueryChange-DDxYz2CF.mjs";import{defineShape as ie}from"./packem_shared/defineShape-DYxbNl5W.mjs";import{anyApi as fe}from"./types.mjs";import{cronJobs as me}from"@lunora/scheduler";import{ValidationError as pe,v as xe}from"@lunora/values";import{allowAll as le,deny as ue,isDeny as Ee,toWhereInput as ge}from"./packem_shared/allowAll-DkRAgItV.mjs";import{asBucketStorage as Re}from"./packem_shared/asBucketStorage-BthCnWop.mjs";import{buildMaskRegistry as Le}from"./packem_shared/buildMaskRegistry-72SL8fJn.mjs";import{buildRlsReadRegistry as Pe,composeShapeReadWhere as be}from"./packem_shared/buildRlsReadRegistry-Deq8inqS.mjs";import{createPolicyDsl as Te,definePermission as ye,definePolicies as Me,definePolicy as _e,defineRole as De}from"./packem_shared/createPolicyDsl-DNfByAUX.mjs";import{defineStorageRule as ke,defineStorageRules as Ce}from"./packem_shared/defineStorageRule-BvxHVq3b.mjs";import{mask as Ve}from"./packem_shared/mask-Da7q82ZC.mjs";import{r as Oe}from"./packem_shared/middleware-DEW0yLvU.mjs";import{storageRules as je}from"./packem_shared/storageRules-CyaiZ0av.mjs";const e="0.0.0";export{M as DEFAULT_LIMIT,_ as DEFAULT_MAX_LIMIT,f as LunoraEnvError,p as LunoraError,K as PRESENCE_DEFAULT_TTL_MS,Y as PRESENCE_TABLE,e as VERSION,pe as ValidationError,le as allowAll,fe as anyApi,Re as asBucketStorage,c as bindOrm,l as bindTableFacade,Le as buildMaskRegistry,Pe as buildRlsReadRegistry,D as clampLimit,O as composePluginMiddleware,be as composeShapeReadWhere,Te as createPolicyDsl,i as createSecrets,me as cronJobs,U as defineAggregateIndex,j as defineComponent,s as defineEnv,I as defineIdentity,F as defineListArgs,C as defineMigration,V as defineMutator,ye as definePermission,w as definePlugin,Me as definePolicies,_e as definePolicy,Z as definePresence,B as defineRankIndex,De as defineRole,W as defineSchema,H as defineSchemaExtension,ie as defineShape,ke as defineStorageRule,Ce as defineStorageRules,J as defineTable,Q as defineVectorIndex,ue as deny,E as httpAction,g as httpRoute,S as httpRouter,X as indexFieldsFromSchema,t as initLunora,q as installPlugins,Ee as isDeny,R as isSafeHeaderValue,Ve as mask,z as mergeSchemaExtension,b as onConnect,A as onDisconnect,te as onQueryChange,T as onShardInit,$ as presenceExtension,re as protectPublic,m as redactSecrets,Oe as rls,h as serveStorageObject,je as storageRules,ge as toWhereInput,xe as v};
@@ -0,0 +1 @@
1
+ const n=2166136261,o=16777619,S=(F,e=2166136261)=>{let t=e;for(let a=0;a<F.length;a+=1)t^=F.codePointAt(a)??0,t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")};export{n as F,o as a,S as f};
@@ -0,0 +1 @@
1
+ import{f as B}from"./fnv1a-D6VtE8WR.mjs";import{LunoraError as P}from"./LunoraError-DcKdk9Ti.mjs";import{bindTableFacade as E,bindOrm as _}from"./bindOrm-lWdeDi9P.mjs";import{i as D,a as K,o as v,b as q}from"./middleware-DEW0yLvU.mjs";import{tagMaskMiddleware as m}from"./buildMaskRegistry-72SL8fJn.mjs";const G=(i,e,c)=>{try{return i==="redact"?null:i==="hash"?e==null?e:typeof e=="bigint"?B(e.toString()):B(typeof e=="string"?e:JSON.stringify(e)):i(e,c)}catch{return null}},a=(i,e,c)=>{const y={...i};for(const[h,g]of Object.entries(e))h in y&&(y[h]=G(g,i[h],{...c,column:h,row:i}));return y},W=(i,e,c)=>({...i,page:i.page.map(y=>a(y,e,c))}),U=(i,e,c,y)=>{if(typeof i!="function")return;const h=new Set,g=()=>new Proxy({},{get:()=>f=>(typeof f=="string"&&h.add(f),g())});i(g());for(const f of h)if(f in e)throw new P("MASK_UNSUPPORTED",`${y}() filtering "${c}" by masked column "${f}" is not supported`)},L=(i,e,c,y)=>{const h=i.rankBefore,g=i.rankPageRows,f=(r,n)=>{const t=e.get(r);return t?n.map(o=>a(o,t,c)):n},p=r=>{const n=r?.relationMask;return{...r,relationMask:n===void 0?f:(t,o)=>n(t,f(t,o))}},k=(r,n,t,o)=>{const s=e.get(r);if(!s)return;const d=y?.[r]?.[o]?.[n];if(!d)return;const w=d.find($=>$ in s);if(w!==void 0)throw new P("MASK_UNSUPPORTED",`${t}() reading "${r}" via index "${n}" would order rows by masked column "${w}" — use an index whose declared fields are all unmasked, or unmask the column`)},l=(r,n,t)=>({async*[Symbol.asyncIterator](){for await(const o of{[Symbol.asyncIterator]:()=>r[Symbol.asyncIterator]()})yield a(o,n,c)},collect:async()=>(await r.collect()).map(s=>a(s,n,c)),collectWithScores:async()=>(await r.collectWithScores()).map(s=>{const d=a(s.document,n,c);return"distanceMeters"in s?{distanceMeters:null,document:d}:{document:d,score:s.score}}),filter:o=>l(r.filter(s=>o(a(s,n,c))),n,t),first:async()=>{const o=await r.first();return o?a(o,n,c):null},order:o=>l(r.order(o),n,t),paginate:async o=>W(await r.paginate(o),n,c),take:async o=>(await r.take(o)).map(d=>a(d,n,c)),unique:async()=>{const o=await r.unique();return o?a(o,n,c):null},withIndex:(o,s)=>(k(t,o,"withIndex","index"),U(s,n,t,"withIndex"),l(r.withIndex(o,s),n,t)),withSearchIndex:(o,s)=>(U(s,n,t,"withSearchIndex"),l(r.withSearchIndex(o,s),n,t)),withGeoIndex:(o,s)=>(k(t,o,"withGeoIndex","geo"),l(r.withGeoIndex(o,s),n,t))}),S=async(r,n)=>{if(i.lookupById){const w=await i.lookupById(r,n);return w?{row:w.row,tableName:e.has(w.tableName)?w.tableName:void 0}:{row:null,tableName:void 0}}const t=await i.get(r,n);if(!t)return{row:null,tableName:void 0};const o=n!==void 0&&e.has(n)?[n]:[],s=n===void 0?[...e.keys()]:o,d=await Promise.all(s.map(async w=>(await i.findFirst(w,{limit:1,where:{_id:r}}))?._id===r?w:void 0));return{row:t,tableName:d.find(w=>w!==void 0)}},M=(r,n,t)=>{const o=e.get(r);if(!o)return;const s=n.find(d=>typeof d=="string"&&d in o);if(s!==void 0)throw new P("MASK_UNSUPPORTED",`${t}() over masked column "${s}" on "${r}" is not supported`)},R=(r,n)=>{if(!(!r||typeof r!="object"||Array.isArray(r)))for(const[t,o]of Object.entries(r))if(t==="AND"||t==="OR"){if(Array.isArray(o))for(const s of o)R(s,n)}else t==="NOT"?R(o,n):t.startsWith("__")||n.add(t)},u=(r,n,t)=>{const o=e.get(r);if(!o||n===void 0)return;const s=new Set;R(n,s);for(const d of s)if(d in o)throw new P("MASK_UNSUPPORTED",`${t}() filtering "${r}" by masked column "${d}" is not supported`)},I=(r,n,t)=>{const o=e.get(r);if(!(!o||!Array.isArray(n))){for(const s of n)if(s&&typeof s=="object"&&!Array.isArray(s)){for(const d of Object.keys(s))if(d in o)throw new P("MASK_UNSUPPORTED",`${t}() ordering "${r}" by masked column "${d}" is not supported`)}}},F=r=>r&&typeof r=="object"&&!Array.isArray(r)?r:void 0,A=(r,n,t)=>{const o=F(n);u(r,o?.where,t),u(r,o?.baseWhere,t)},O={...i,async deleteWhere(r,n,t){if(u(r,n,"deleteMany({ where })"),i.deleteWhere===void 0)throw new P("INTERNAL",`ctx.db.${r}.deleteMany({ where }) is unavailable: this writer has no where-based delete`);return i.deleteWhere(r,n,t)},async patchWhere(r,n,t){if(u(r,n.where,"patchMany({ where })"),i.patchWhere===void 0)throw new P("INTERNAL",`ctx.db.${r}.patchMany({ where }) is unavailable: this writer has no where-based patch`);return i.patchWhere(r,n,t)},aggregate(r,n){return M(r,[n.field],"aggregate"),u(r,n.where,"aggregate"),i.aggregate(r,n)},count(r,n){const t=F(n),o=t&&("where"in t||"baseWhere"in t||"restrictsCounts"in t)?t.where:n;return u(r,o,"count"),t&&u(r,t.baseWhere,"count"),i.count(r,n)},async findFirst(r,n){u(r,n?.where,"findFirst"),u(r,n?.baseWhere,"findFirst"),I(r,n?.orderBy,"findFirst");const t=await i.findFirst(r,p(n)),o=e.get(r);return t&&o?a(t,o,c):t},async findFirstOrThrow(r,n){u(r,n?.where,"findFirstOrThrow"),u(r,n?.baseWhere,"findFirstOrThrow"),I(r,n?.orderBy,"findFirstOrThrow");const t=await i.findFirstOrThrow(r,p(n)),o=e.get(r);return o?a(t,o,c):t},async findMany(r,n){u(r,n?.where,"findMany"),u(r,n?.baseWhere,"findMany"),I(r,n?.orderBy,"findMany");const t=await i.findMany(r,p(n)),o=e.get(r);return o?W(t,o,c):t},async get(r,n){const{row:t,tableName:o}=await S(r,n),s=o===void 0?void 0:e.get(o);return!t||!s?t:a(t,s,c)},async lookupById(r,n){const t=await i.lookupById?.(r,n);if(!t)return null;const o=e.get(t.tableName);return{row:o?a(t.row,o,c):t.row,tableName:t.tableName}},groupBy(r,n){return M(r,[...n.by,n.agg?.field],"groupBy"),u(r,n.where,"groupBy"),i.groupBy(r,n)},query(r){const n=i.query(r),t=e.get(r);return t?l(n,t,r):n},async rank(r,n,t){return A(r,t,"rank"),k(r,n,"rank","rank"),i.rank(r,n,t)},async rankPage(r,n,t){A(r,t,"rankPage"),k(r,n,"rankPage","rank");const o=await i.rankPage(r,n,t),s=e.get(r);return s?W(o,s,c):o},...v("rankBefore",h,r=>(n,t,o)=>(A(n,o,"rankBefore"),k(n,t,"rankBefore","rank"),r(n,t,o))),...v("rankPageRows",g,r=>async(n,t,o)=>{A(n,o,"rankPageRows"),k(n,t,"rankPageRows","rank");const s=await r(n,t,o),d=e.get(n);return d?{...s,rows:s.rows.map(w=>({...w,doc:a(w.doc,d,c)}))}:s})},j=O;for(const r of e.keys())q(i[r])&&(j[r]=E(O,r));return O},V=(i,e={})=>{const c=new Map(Object.entries(i)),y=D(e.roles),h=async({ctx:f,next:p})=>{const k={auth:await K(f.auth??{},y),ctx:f};if(e.bypass?.(k))return p();const l=L(f.db,c,k,e.indexFields),S={db:l},{orm:M}=f;return M!==null&&typeof M=="object"&&(S.orm=_(l)),p({ctx:S})},g=new Map;for(const[f,p]of c)g.set(f,new Set(Object.keys(p)));return m(h,{columns:g})};export{V as mask};
@@ -0,0 +1 @@
1
+ import{f as c,F as f,a as y}from"./fnv1a-D6VtE8WR.mjs";const p=t=>`${c(t,f)}${c(t,y)}`,u=(t,n)=>t<n?-1:t>n?1:0,o=t=>{if(t===void 0)return"null";if(typeof t=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(typeof t=="number"){if(Number.isNaN(t))return"nan";if(t===1/0)return"inf";if(t===-1/0)return"-inf";if(Object.is(t,-0))return"-0"}if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(r=>o(r)).join(",")}]`;const n=Object.getPrototypeOf(t);if(n!==null&&n!==Object.prototype){const r=t.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${r} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const e=t,s=Object.keys(e).toSorted(u),i=[];for(const r of s){const a=e[r];a!==void 0&&i.push(`${JSON.stringify(r)}:${o(a)}`)}return`{${i.join(",")}}`},g=(t,n)=>({args:{},handler:async(e,s)=>{const i=await t(e),r=p(o(i));return r===s?.previousDigest?{digest:r,ran:!1}:(await n(e,i),{digest:r,ran:!0})},kind:"mutation",lifecycle:"reactor",visibility:"internal"});export{g as onQueryChange};
package/dist/types.d.mts CHANGED
@@ -199,7 +199,13 @@ interface SearchIndexDefinition {
199
199
  * added to a populated table works immediately. On a very large table that
200
200
  * scan is expensive to run inside a deploy: `staged: true` maintains the
201
201
  * index on write only and leaves the initial population to an out-of-band
202
- * `backfillSearchIndexes`.
202
+ * run.
203
+ *
204
+ * That run is mandatory, not optional — until it happens, every row written
205
+ * BEFORE the deploy is unsearchable. Drive it against a deployment with
206
+ * `lunora run '__lunora_admin__:backfillSearch' --args '{"maxPages":20}'`,
207
+ * repeating until the response reports `done: true`; progress is durable, so
208
+ * each call resumes where the last stopped.
203
209
  */
204
210
  staged?: boolean;
205
211
  /**
package/dist/types.d.ts CHANGED
@@ -199,7 +199,13 @@ interface SearchIndexDefinition {
199
199
  * added to a populated table works immediately. On a very large table that
200
200
  * scan is expensive to run inside a deploy: `staged: true` maintains the
201
201
  * index on write only and leaves the initial population to an out-of-band
202
- * `backfillSearchIndexes`.
202
+ * run.
203
+ *
204
+ * That run is mandatory, not optional — until it happens, every row written
205
+ * BEFORE the deploy is unsearchable. Drive it against a deployment with
206
+ * `lunora run '__lunora_admin__:backfillSearch' --args '{"maxPages":20}'`,
207
+ * repeating until the response reports `done: true`; progress is durable, so
208
+ * each call resumes where the last stopped.
203
209
  */
204
210
  staged?: boolean;
205
211
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/server",
3
- "version": "1.0.0-alpha.81",
3
+ "version": "1.0.0-alpha.83",
4
4
  "description": "Server primitives for Lunora: defineSchema, defineTable, query, mutation, and action",
5
5
  "keywords": [
6
6
  "backend",
@@ -66,9 +66,9 @@
66
66
  "access": "public"
67
67
  },
68
68
  "dependencies": {
69
- "@lunora/errors": "1.0.0-alpha.22",
70
- "@lunora/scheduler": "1.0.0-alpha.37",
71
- "@lunora/values": "1.0.0-alpha.27",
69
+ "@lunora/errors": "1.0.0-alpha.23",
70
+ "@lunora/scheduler": "1.0.0-alpha.38",
71
+ "@lunora/values": "1.0.0-alpha.28",
72
72
  "drizzle-orm": "^0.45.2",
73
73
  "hono": "^4.13.1"
74
74
  },
@@ -1 +0,0 @@
1
- import{LunoraError as P}from"./LunoraError-DcKdk9Ti.mjs";import{bindTableFacade as j,bindOrm as E}from"./bindOrm-lWdeDi9P.mjs";import{i as _,a as D,o as v,b as K}from"./middleware-DEW0yLvU.mjs";import{tagMaskMiddleware as q}from"./buildMaskRegistry-72SL8fJn.mjs";const G=e=>{let i=2166136261;for(let c=0;c<e.length;c+=1)i^=e.codePointAt(c)??0,i=Math.imul(i,16777619);return(i>>>0).toString(16).padStart(8,"0")},L=(e,i,c)=>{try{return e==="redact"?null:e==="hash"?i==null?i:G(typeof i=="string"?i:JSON.stringify(i)):e(i,c)}catch{return null}},a=(e,i,c)=>{const y={...e};for(const[h,g]of Object.entries(i))h in y&&(y[h]=L(g,e[h],{...c,column:h,row:e}));return y},W=(e,i,c)=>({...e,page:e.page.map(y=>a(y,i,c))}),B=(e,i,c,y)=>{if(typeof e!="function")return;const h=new Set,g=()=>new Proxy({},{get:()=>f=>(typeof f=="string"&&h.add(f),g())});e(g());for(const f of h)if(f in i)throw new P("MASK_UNSUPPORTED",`${y}() filtering "${c}" by masked column "${f}" is not supported`)},m=(e,i,c,y)=>{const h=e.rankBefore,g=e.rankPageRows,f=(r,n)=>{const t=i.get(r);return t?n.map(o=>a(o,t,c)):n},p=r=>{const n=r?.relationMask;return{...r,relationMask:n===void 0?f:(t,o)=>n(t,f(t,o))}},k=(r,n,t,o)=>{const s=i.get(r);if(!s)return;const d=y?.[r]?.[o]?.[n];if(!d)return;const w=d.find($=>$ in s);if(w!==void 0)throw new P("MASK_UNSUPPORTED",`${t}() reading "${r}" via index "${n}" would order rows by masked column "${w}" — use an index whose declared fields are all unmasked, or unmask the column`)},l=(r,n,t)=>({async*[Symbol.asyncIterator](){for await(const o of{[Symbol.asyncIterator]:()=>r[Symbol.asyncIterator]()})yield a(o,n,c)},collect:async()=>(await r.collect()).map(s=>a(s,n,c)),collectWithScores:async()=>(await r.collectWithScores()).map(s=>{const d=a(s.document,n,c);return"distanceMeters"in s?{distanceMeters:null,document:d}:{document:d,score:s.score}}),filter:o=>l(r.filter(s=>o(a(s,n,c))),n,t),first:async()=>{const o=await r.first();return o?a(o,n,c):null},order:o=>l(r.order(o),n,t),paginate:async o=>W(await r.paginate(o),n,c),take:async o=>(await r.take(o)).map(d=>a(d,n,c)),unique:async()=>{const o=await r.unique();return o?a(o,n,c):null},withIndex:(o,s)=>(k(t,o,"withIndex","index"),B(s,n,t,"withIndex"),l(r.withIndex(o,s),n,t)),withSearchIndex:(o,s)=>(B(s,n,t,"withSearchIndex"),l(r.withSearchIndex(o,s),n,t)),withGeoIndex:(o,s)=>(k(t,o,"withGeoIndex","geo"),l(r.withGeoIndex(o,s),n,t))}),S=async(r,n)=>{if(e.lookupById){const w=await e.lookupById(r,n);return w?{row:w.row,tableName:i.has(w.tableName)?w.tableName:void 0}:{row:null,tableName:void 0}}const t=await e.get(r,n);if(!t)return{row:null,tableName:void 0};const o=n!==void 0&&i.has(n)?[n]:[],s=n===void 0?[...i.keys()]:o,d=await Promise.all(s.map(async w=>(await e.findFirst(w,{limit:1,where:{_id:r}}))?._id===r?w:void 0));return{row:t,tableName:d.find(w=>w!==void 0)}},M=(r,n,t)=>{const o=i.get(r);if(!o)return;const s=n.find(d=>typeof d=="string"&&d in o);if(s!==void 0)throw new P("MASK_UNSUPPORTED",`${t}() over masked column "${s}" on "${r}" is not supported`)},R=(r,n)=>{if(!(!r||typeof r!="object"||Array.isArray(r)))for(const[t,o]of Object.entries(r))if(t==="AND"||t==="OR"){if(Array.isArray(o))for(const s of o)R(s,n)}else t==="NOT"?R(o,n):t.startsWith("__")||n.add(t)},u=(r,n,t)=>{const o=i.get(r);if(!o||n===void 0)return;const s=new Set;R(n,s);for(const d of s)if(d in o)throw new P("MASK_UNSUPPORTED",`${t}() filtering "${r}" by masked column "${d}" is not supported`)},I=(r,n,t)=>{const o=i.get(r);if(!(!o||!Array.isArray(n))){for(const s of n)if(s&&typeof s=="object"&&!Array.isArray(s)){for(const d of Object.keys(s))if(d in o)throw new P("MASK_UNSUPPORTED",`${t}() ordering "${r}" by masked column "${d}" is not supported`)}}},F=r=>r&&typeof r=="object"&&!Array.isArray(r)?r:void 0,A=(r,n,t)=>{const o=F(n);u(r,o?.where,t),u(r,o?.baseWhere,t)},O={...e,async deleteWhere(r,n,t){if(u(r,n,"deleteMany({ where })"),e.deleteWhere===void 0)throw new P("INTERNAL",`ctx.db.${r}.deleteMany({ where }) is unavailable: this writer has no where-based delete`);return e.deleteWhere(r,n,t)},async patchWhere(r,n,t){if(u(r,n.where,"patchMany({ where })"),e.patchWhere===void 0)throw new P("INTERNAL",`ctx.db.${r}.patchMany({ where }) is unavailable: this writer has no where-based patch`);return e.patchWhere(r,n,t)},aggregate(r,n){return M(r,[n.field],"aggregate"),u(r,n.where,"aggregate"),e.aggregate(r,n)},count(r,n){const t=F(n),o=t&&("where"in t||"baseWhere"in t||"restrictsCounts"in t)?t.where:n;return u(r,o,"count"),t&&u(r,t.baseWhere,"count"),e.count(r,n)},async findFirst(r,n){u(r,n?.where,"findFirst"),u(r,n?.baseWhere,"findFirst"),I(r,n?.orderBy,"findFirst");const t=await e.findFirst(r,p(n)),o=i.get(r);return t&&o?a(t,o,c):t},async findFirstOrThrow(r,n){u(r,n?.where,"findFirstOrThrow"),u(r,n?.baseWhere,"findFirstOrThrow"),I(r,n?.orderBy,"findFirstOrThrow");const t=await e.findFirstOrThrow(r,p(n)),o=i.get(r);return o?a(t,o,c):t},async findMany(r,n){u(r,n?.where,"findMany"),u(r,n?.baseWhere,"findMany"),I(r,n?.orderBy,"findMany");const t=await e.findMany(r,p(n)),o=i.get(r);return o?W(t,o,c):t},async get(r,n){const{row:t,tableName:o}=await S(r,n),s=o===void 0?void 0:i.get(o);return!t||!s?t:a(t,s,c)},async lookupById(r,n){const t=await e.lookupById?.(r,n);if(!t)return null;const o=i.get(t.tableName);return{row:o?a(t.row,o,c):t.row,tableName:t.tableName}},groupBy(r,n){return M(r,[...n.by,n.agg?.field],"groupBy"),u(r,n.where,"groupBy"),e.groupBy(r,n)},query(r){const n=e.query(r),t=i.get(r);return t?l(n,t,r):n},async rank(r,n,t){return A(r,t,"rank"),k(r,n,"rank","rank"),e.rank(r,n,t)},async rankPage(r,n,t){A(r,t,"rankPage"),k(r,n,"rankPage","rank");const o=await e.rankPage(r,n,t),s=i.get(r);return s?W(o,s,c):o},...v("rankBefore",h,r=>(n,t,o)=>(A(n,o,"rankBefore"),k(n,t,"rankBefore","rank"),r(n,t,o))),...v("rankPageRows",g,r=>async(n,t,o)=>{A(n,o,"rankPageRows"),k(n,t,"rankPageRows","rank");const s=await r(n,t,o),d=i.get(n);return d?{...s,rows:s.rows.map(w=>({...w,doc:a(w.doc,d,c)}))}:s})},U=O;for(const r of i.keys())K(e[r])&&(U[r]=j(O,r));return O},Q=(e,i={})=>{const c=new Map(Object.entries(e)),y=_(i.roles),h=async({ctx:f,next:p})=>{const k={auth:await D(f.auth??{},y),ctx:f};if(i.bypass?.(k))return p();const l=m(f.db,c,k,i.indexFields),S={db:l},{orm:M}=f;return M!==null&&typeof M=="object"&&(S.orm=E(l)),p({ctx:S})},g=new Map;for(const[f,p]of c)g.set(f,new Set(Object.keys(p)));return q(h,{columns:g})};export{Q as mask};
@@ -1 +0,0 @@
1
- const c=(t,e)=>{let r=e;for(let i=0;i<t.length;i+=1)r^=t.codePointAt(i)??0,r=Math.imul(r,16777619)>>>0;return r.toString(16).padStart(8,"0")},f=t=>`${c(t,2166136261)}${c(t,16777619)}`,y=(t,e)=>t<e?-1:t>e?1:0,s=t=>{if(t===void 0)return"null";if(typeof t=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(typeof t=="number"){if(Number.isNaN(t))return"nan";if(t===1/0)return"inf";if(t===-1/0)return"-inf";if(Object.is(t,-0))return"-0"}if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(n=>s(n)).join(",")}]`;const e=Object.getPrototypeOf(t);if(e!==null&&e!==Object.prototype){const n=t.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${n} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const r=t,i=Object.keys(r).toSorted(y),o=[];for(const n of i){const a=r[n];a!==void 0&&o.push(`${JSON.stringify(n)}:${s(a)}`)}return`{${o.join(",")}}`},p=(t,e)=>({args:{},handler:async(r,i)=>{const o=await t(r),n=f(s(o));return n===i?.previousDigest?{digest:n,ran:!1}:(await e(r,o),{digest:n,ran:!0})},kind:"mutation",lifecycle:"reactor",visibility:"internal"});export{p as onQueryChange};