@lunora/sql-store 1.0.0-alpha.214 → 1.0.0-alpha.216

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 (23) hide show
  1. package/dist/index.d.mts +260 -4
  2. package/dist/index.d.ts +260 -4
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/{SEARCH_STATE_TABLE-Dw9zY5R8.mjs → SEARCH_STATE_TABLE-CH0YDOni.mjs} +1 -1
  5. package/dist/packem_shared/backfillSqlSearchIndexes-BKT_YmAk.mjs +1 -0
  6. package/dist/packem_shared/createSqlCtxDb-B2y2spnC.mjs +7 -0
  7. package/dist/packem_shared/ctx-db-search-DhPvgSgA.mjs +1 -0
  8. package/dist/packem_shared/ctx-db-search-state-CaX6vwUz.mjs +1 -0
  9. package/dist/packem_shared/{decodeBigint-prUTsk6p.mjs → decodeBigint-BZku9YxY.mjs} +1 -1
  10. package/dist/packem_shared/decodeGlobalRow-Bc_0zTWY.mjs +1 -0
  11. package/dist/packem_shared/exportSqlGlobalRows-6sS_vU9b.mjs +1 -0
  12. package/dist/packem_shared/facetSqlGlobalColumn-BEE13w0Y.mjs +1 -0
  13. package/dist/packem_shared/{runSqlAggregateMigrations-CTaYuZh9.mjs → runSqlAggregateMigrations-DY65VtGl.mjs} +1 -1
  14. package/dist/packem_shared/runSqlGlobalTableMigrations-CIbF4adm.mjs +1 -0
  15. package/dist/packem_shared/{sql-exec-DBWZFC7S.mjs → sql-exec-snQLgtvn.mjs} +1 -1
  16. package/dist/packem_shared/{value-codec-CiS1h_97.mjs → value-codec-C52YW-Do.mjs} +1 -1
  17. package/package.json +2 -2
  18. package/dist/packem_shared/backfillSqlSearchIndexes-BW2vP7-P.mjs +0 -1
  19. package/dist/packem_shared/createSqlCtxDb-CwgVezf1.mjs +0 -7
  20. package/dist/packem_shared/ctx-db-search-gBXL6_Ra.mjs +0 -1
  21. package/dist/packem_shared/ctx-db-search-state-BYatr_oi.mjs +0 -1
  22. package/dist/packem_shared/decodeGlobalRow-C0NS-YZn.mjs +0 -1
  23. package/dist/packem_shared/runSqlGlobalTableMigrations-6cXUbFbj.mjs +0 -1
@@ -1 +0,0 @@
1
- import{sql as e}from"drizzle-orm";import{a as p,q as m}from"./sql-exec-DBWZFC7S.mjs";const y=["de","en","es","fr","it","nl","none","pt"],L=i=>y.includes(i),A="a an and are as at be but by for if in into is it no not of on or such that the their then there these they this to was will with",R="aber als am an auch auf aus bei bin bis bist da dass der den des dem die das denn dir du ein eine für hat ich im in ist mit nicht noch nur oder sich sie sind über und von vor war wie wir zu zum zur",F="a al como con de del el en es la las lo los mas no o para pero por que se su sus un una uno y ya",q="au aux avec ce ces dans de des du elle en et eux il je la le les leur lui ma mais me même mes moi mon ne nos notre nous on ou par pas pour qu que qui sa se ses son sur ta te tes toi ton tu un une vos votre vous y",N="a ai al alla anche che chi ci coi col come con da dal degli dei del della di do e ed gli ha hai hanno i il in la le lo ma mi ne nei nel non o per più quale quanto se si sono su sul tra un una uno vi",_="aan al als bij dan dat de der deze die dit door een en er het hij ij in is je kan me men met mij na naar niet nog nu of om ons ook op over te tot uit van voor was wat we wij zij zijn zo",x="a ao aos as até com como da das de do dos e em entre era essa esse esta este eu foi há isso já mais mas me mesmo meu na nas no nos num numa o os ou para pela pelo por qual que quem se sem seu só sua também te tem um uma você",C=new RegExp("(?<=\\p{Script=Cyrillic})[\\u0300-\\u0305\\u0307\\u0309-\\u036F]|(?<!\\p{Script=Cyrillic})[\\u0300-\\u036F]","gu"),O=/[\u0080-\u{10FFFF}]/u,b=/[\p{L}\p{N}]+/gu,H=/[\p{Script_Extensions=Han}\p{Script_Extensions=Hiragana}\p{Script_Extensions=Katakana}\p{Script_Extensions=Hangul}]+/gu,g=/[\p{Script_Extensions=Han}\p{Script_Extensions=Hiragana}\p{Script_Extensions=Katakana}\p{Script_Extensions=Hangul}]/u,D=i=>{if(!g.test(i))return[i];const n=[];let t=0;for(const r of i.matchAll(H)){const o=r.index,s=[...r[0]];if(o>t&&n.push(i.slice(t,o)),t=o+r[0].length,s.length===1){n.push(r[0]);continue}for(let a=0;a+1<s.length;a+=1)n.push(`${String(s[a])}${String(s[a+1])}`)}return t<i.length&&n.push(i.slice(t)),n},v=i=>O.test(i)?i.normalize("NFD").replaceAll(C,"").normalize("NFC").toLowerCase():i.toLowerCase(),f=i=>new Set(v(i).split(" ")),j={de:f(R),en:f(A),es:f(F),fr:f(q),it:f(N),nl:f(_),none:new Set,pt:f(x)},z=3,U=256,w=new Map,k=i=>{const n=i!==void 0&&L(i)?i:"none",t=w.get(n);if(t)return t;const r=j[n],o=a=>{const d=v(a),$=d.match(b)??[],u=(g.test(d)?$.flatMap(l=>D(l)):$).filter(l=>l.length<=U);return r.size===0?u:u.filter(l=>!r.has(l))},s={document:o,profile:`${n}-v${String(z)}`,query:a=>{const d=o(a);return d.filter(($,u)=>d.lastIndexOf($)===u)}};return w.set(n,s),s},W=i=>`${k(i.language).profile}:${i.field}`,S=i=>{const n=i.slice(i.indexOf(":")+1),t=n.lastIndexOf("/");return t===-1?n:n.slice(0,t)},V=(i,n)=>i.profile!==n?{cursor:void 0,finished:!1,wipe:i.cursor!==void 0||i.done}:{cursor:i.cursor,finished:i.done,wipe:!1},I=(i,n)=>typeof i=="string"&&S(i)===S(n),c="__lunora_search_state",K=async(i,n)=>{const{integer:t,key:r}=n.companionTypes,o=async(s,a)=>{try{await p(i,n,e`ALTER TABLE ${e.identifier(c)} ADD COLUMN ${e.identifier(s)} ${e.raw(a)}`)}catch{}};await p(i,n,e`CREATE TABLE IF NOT EXISTS ${e.identifier(c)} (${e.identifier("companion")} ${e.raw(r)} PRIMARY KEY, ${e.identifier("cursor")} ${e.raw(r)}, ${e.identifier("done")} ${e.raw(t)} NOT NULL DEFAULT 0, ${e.identifier("profile")} ${e.raw(r)}, ${e.identifier("covered")} ${e.raw(t)} NOT NULL DEFAULT 0)`),await o("profile",r),await o("covered",`${t} NOT NULL DEFAULT 0`),await p(i,n,e`UPDATE ${e.identifier(c)} SET ${e.identifier("covered")} = 1 WHERE ${e.identifier("done")} = 1 AND ${e.identifier("covered")} = 0`)},T=i=>i===1||i===!0||i==="1",P=async(i,n,t)=>{const r=await m(i,n,e`SELECT ${e.identifier("covered")} FROM ${e.identifier(c)} WHERE ${e.identifier("companion")} = ${t}`);return T(r[0]?.covered)},Y=async(i,n,t)=>{await p(i,n,e`DELETE FROM ${e.identifier(c)} WHERE ${e.identifier("companion")} = ${t}`)},X=async(i,n,t)=>{const o=(await m(i,n,e`SELECT ${e.identifier("cursor")}, ${e.identifier("done")}, ${e.identifier("profile")} FROM ${e.identifier(c)} WHERE ${e.identifier("companion")} = ${t}`))[0];if(!o)return{cursor:void 0,done:!1,profile:void 0};const{cursor:s,profile:a}=o;return{cursor:typeof s=="string"?s:void 0,done:T(o.done),profile:typeof a=="string"?a:void 0}},G=async(i,n,t,r,o,s)=>{const a=r??null,d=await m(i,n,e`SELECT ${e.identifier("profile")} FROM ${e.identifier(c)} WHERE ${e.identifier("companion")} = ${t}`),$=I(d[0]?.profile,s),u=o?1:0,l=o||!$?e`${e.identifier("covered")} = ${u}`:e`${e.identifier("covered")} = ${e.identifier("covered")}`,h=e`UPDATE ${e.identifier(c)} SET ${e.identifier("cursor")} = ${a}, ${e.identifier("done")} = ${u}, ${e.identifier("profile")} = ${s}, ${l} WHERE ${e.identifier("companion")} = ${t}`;if(d.length>0){await p(i,n,h);return}try{await p(i,n,e`INSERT INTO ${e.identifier(c)} (${e.identifier("companion")}, ${e.identifier("cursor")}, ${e.identifier("done")}, ${e.identifier("profile")}, ${e.identifier("covered")}) VALUES (${t}, ${a}, ${o?1:0}, ${s}, ${o?1:0})`)}catch(E){if(!n.isUniqueViolation(E))throw E;await p(i,n,h)}};export{k as D,c as S,Y as a,P as b,W as c,V as l,K as m,X as r,G as w};
@@ -1 +0,0 @@
1
- import{B as l,O as o,b as n,c as r,z as t,f as d,h as i,g as u,v as f,l as R,i as q,u as c,n as C,m,o as p,p as x,x as I,d as S,q as h,e as w,a as E,k as O,r as y,j as z,s as B,w as L,t as N}from"./sql-exec-DBWZFC7S.mjs";import"./value-codec-CiS1h_97.mjs";export{l as BACKFILL_BATCH_SIZE,o as OCC_VERSION_COLUMN,n as columnRefSql,r as createIndexIfNotExists,t as decodeGlobalRow,d as decodeRow,i as decodeRows,u as dropIndexIfExists,f as fieldRefSql,R as forEachRowPaged,q as indexState,c as nextRowVersion,C as nullSafeEqualsSql,m as pathContainsNeedle,p as pathInList,x as pathTextReference,I as pathTypeGuardSql,S as qualifiedColumnRefSql,h as queryAll,w as queryBatch,E as queryRun,O as readRowsPage,y as runInOrder,z as serializeColumnValue,B as serializeDocumentColumn,L as serializeFieldValue,N as tableColumns};
@@ -1 +0,0 @@
1
- import{sql as a}from"drizzle-orm";import{provisionGlobalTablesSequentially as m,foldIdentifier as c,globalTableColumnsDdl as A,globalTableIndexSpecs as L,legacyRewrites as O,indexLedgerDdl as R,wantedGlobalColumns as k,undeclaredFrameworkIndexes as y,indexShapeChanged as $,INDEX_LEDGER_TABLE as T,MIGRATION_STATE_TABLE as E,recordIndexStatement as M,legacyRowPredicate as C}from"./runSqlAggregateMigrations-CTaYuZh9.mjs";import{r as q,q as g}from"./sql-exec-DBWZFC7S.mjs";const v=50,h=new Map([["'","'"],["[","]"],["`","`"],['"','"']]),N=/^[\w$]+/u,b=(e,r)=>{const n=h.get(e[r]);let t=r+1;for(;t<e.length;)if(e[t]!==n)t+=1;else if(n!=="]"&&e[t+1]===n)t+=2;else return t+1;return t},_=e=>{const r=e.trim(),n=h.get(r[0]??"");if(n===void 0)return N.exec(r)?.[0];const t=b(r,0),s=r.slice(1,r[t-1]===n?t-1:t);return n==="]"?s:s.replaceAll(`${n}${n}`,n)},B=e=>{const r=new Set,n=i=>{const d=_(i);d!==void 0&&r.add(d)};let t=0,s=0,o=0;for(;o<e.length;){const i=e[o];if(h.has(i)){o=b(e,o);continue}if(i==="(")t+=1,s=t===1?o+1:s;else if(i===")"){if(t-=1,t===0)return n(e.slice(s,o)),r}else i===","&&t===1&&(n(e.slice(s,o)),s=o+1);o+=1}return r},F=async(e,r,n)=>{const t=new Set,s=new Map,o=n.has(c(T)),i=[];if(n.has(c(E))&&i.push(a`SELECT 'marker' AS kind, name, NULL AS owner FROM ${a.identifier(E)}`),o&&i.push(a`SELECT 'index' AS kind, "l"."name" AS name, "l"."table_name" AS owner FROM ${a.identifier(T)} AS "l"`),i.length===0)return{hasLedger:o,markers:t,owned:s};for(const d of await g(e,r,a.join(i,a` UNION ALL `)))if(d.kind==="marker")t.add(String(d.name));else{const f=c(String(d.owner));s.set(f,[...s.get(f)??[],String(d.name)])}return{hasLedger:o,markers:t,owned:s}},D=async(e,r)=>{try{const n=await g(e,r,a`SELECT type, name, tbl_name, sql FROM sqlite_master WHERE type IN ('table', 'index')`),t=new Set,s=new Map,o=new Map;for(const l of n){const u=String(l.name);if(u.startsWith("sqlite_"))continue;const S=typeof l.sql=="string"?l.sql:void 0;l.type==="table"?(t.add(c(u)),s.set(c(u),new Set([...S===void 0?[]:B(S)].map(I=>c(I))))):o.set(c(u),S)}const{hasLedger:i,markers:d,owned:f}=await F(e,r,t);return{columns:s,hasLedger:i,indexes:o,markers:d,owned:f,tables:t}}catch{return}},w=e=>e.kind==="default-order"?[]:[M(e.name,e.table)],p=e=>{const r=e.unique?a`UNIQUE `:a``;return a`CREATE ${r}INDEX IF NOT EXISTS ${a.identifier(e.name)} ON ${a.identifier(e.table)} (${e.columns})`},x=(e,r,n)=>n.length===0?[]:[a`CREATE TABLE IF NOT EXISTS ${a.identifier(E)} (${a.identifier("name")} ${a.raw(e.companionTypes.key)} PRIMARY KEY)`,...n.map(t=>a`INSERT OR IGNORE INTO ${a.identifier(E)} (${a.identifier("name")}) SELECT ${t.marker} WHERE NOT EXISTS (SELECT 1 FROM ${a.identifier(r)} WHERE ${C(t)})`)],G=(e,r,n,t)=>{const s=A(e,r,n),o=L(e,r,n),i=O(e,r);if(!t.tables.has(c(e)))return[...t.hasLedger?[]:[R()],a`CREATE TABLE IF NOT EXISTS ${a.identifier(e)} (${s})`,...o.flatMap(l=>[p(l),...w(l)]),...x(n,e,i)];const d=t.columns.get(c(e))??new Set;if(k(r,n).some(([l])=>!d.has(c(l)))||i.some(l=>!t.markers.has(l.marker))||y(n,o,t.owned.get(c(e))??[]).length>0)return;const f=[];for(const l of o){if(!t.indexes.has(c(l.name))){f.push(p(l),...w(l));continue}const u=t.indexes.get(c(l.name));if(l.kind==="declared"&&typeof u=="string"&&$(n,u,l))return}return f},X=e=>{const r=[];let n=[],t=0;for(const s of e)n.length>0&&t+s.statements.length>v&&(r.push(n),n=[],t=0),n.push(s),t+=s.statements.length;return n.length>0&&r.push(n),r},U=(e,r)=>!r.hasLedger&&Object.entries(e.tables).some(([n,t])=>t.shardMode?.kind==="global"&&r.tables.has(c(n))),Q=async(e,r,n)=>{if(!e.batch||n.name!=="sqlite"){await m(e,r,n);return}const t=await D(e,n);if(t===void 0){await m(e,r,n);return}if(U(r,t)){await m(e,r,n);return}const s=[],o=new Set;for(const[i,d]of Object.entries(r.tables)){if(d.shardMode?.kind!=="global")continue;const f=G(i,d,n,t);f===void 0?o.add(i):f.length>0&&s.push({statements:f,table:i})}for(const i of X(s))try{await q(e,n,i.flatMap(d=>d.statements))}catch{for(const d of i)o.add(d.table)}await m(e,r,n,o)};export{B as columnNamesOfCreateTable,Q as runSqlGlobalTableMigrations};