palgres 0.53.0 → 0.55.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.
Files changed (37) hide show
  1. package/dist/chunks/5EMZSH7B.js +5 -0
  2. package/dist/chunks/DLP3GKUJ.js +309 -0
  3. package/dist/chunks/EBHTHWOS.js +2 -0
  4. package/dist/dsl.js +2 -2
  5. package/dist/index.js +156 -125
  6. package/dist/testing.js +2 -2
  7. package/package.json +1 -1
  8. package/types/access/src/apply.d.ts +98 -0
  9. package/types/access/src/base.d.ts +49 -0
  10. package/types/access/src/catalog.d.ts +53 -0
  11. package/types/access/src/compile.d.ts +120 -0
  12. package/types/access/src/errors.d.ts +7 -0
  13. package/types/access/src/index.d.ts +10 -0
  14. package/types/access/src/model.d.ts +87 -0
  15. package/types/access/src/reference.d.ts +12 -0
  16. package/types/access/src/text.d.ts +104 -0
  17. package/types/access/src/validation.d.ts +22 -0
  18. package/types/access/src/world.d.ts +43 -0
  19. package/types/palgres/src/access.d.ts +63 -0
  20. package/types/palgres/src/connect.d.ts +10 -1
  21. package/types/palgres/src/dsl/policy.d.ts +24 -0
  22. package/types/palgres/src/dsl/to-model.d.ts +11 -1
  23. package/types/palgres/src/forget.d.ts +6 -6
  24. package/types/palgres/src/index.d.ts +1 -1
  25. package/types/palgres/src/model.d.ts +8 -0
  26. package/types/palgres/src/plan.d.ts +5 -1
  27. package/types/palgres/src/query/access.d.ts +169 -0
  28. package/types/palgres/src/query/env-gen.d.ts +2 -0
  29. package/types/palgres/src/query/index.d.ts +9 -7
  30. package/types/palgres/src/query/surface.d.ts +7 -1
  31. package/types/palgres/src/query/typed.d.ts +13 -5
  32. package/types/palgres/src/testing/access.d.ts +17 -0
  33. package/types/palgres/src/testing/fake.d.ts +13 -1
  34. package/types/palgres/src/testing/index.d.ts +2 -1
  35. package/dist/chunks/ULLX3GNS.js +0 -2
  36. package/dist/chunks/X2B6AJ7P.js +0 -5
  37. package/dist/chunks/XPFGITD6.js +0 -2
@@ -0,0 +1,2 @@
1
+ /*! palgres 0.55.0 — Palbase SDK License (see LICENSE) */
2
+ import{A as x,C as A,S as w,a as g,b as D,f as K,g as _,k as N,n as P,o as k,r as S}from"./DLP3GKUJ.js";var q={uuid:"uuid",text:"text",integer:"integer",bigint:"bigint",numeric:"numeric",boolean:"boolean",timestamp:"timestamp with time zone",date:"date",jsonb:"jsonb"};function ne(e,n={}){let t=Array.isArray(e)?e:[e],i={tables:[],enums:[],extensions:[],raw:[]},a=new Map;for(let o of t){for(let l of Object.values(o.tables))i.tables.push(V(o.name,l,a));i.extensions.push(...o.extensions);for(let l of o.raw??[])i.raw.push({name:l.name,schema:o.name,sql:l.up,...l.drop!==void 0?{drop:l.drop}:{},...l.before===!0?{before:!0}:{}})}i.enums=[...a.values()];for(let o of t)for(let l of Object.values(o.tables))for(let r of l.raw??[])i.raw.push({name:r.name,table:`${o.name}.${l.name}`,sql:r.up});return n.access!==void 0&&(O(i,n.access),i.access={text:n.access,compiled:A(N(i),n.access,n.roles??{authenticated:"authenticated",service:"service_role"})}),i}function O(e,n){let t;try{t=S(k(n))}catch(i){if(i instanceof P)return;throw i}for(let i of t.types.values()){let a=i.table;if(!a)continue;let o=e.tables.find(r=>r.schema===a.schema&&r.name===a.name);if(!o||o.ignored)continue;let l=$.get(o);if(o.policies.some(r=>!l?.unindexedPolicies.has(r.name)&&(x(r.using)||x(r.withCheck))))for(let r of i.relations.values())r.kind==="column"&&U(o,r.column,l?.rawNames??new Set)}}var $=new WeakMap;function U(e,n,t){let i=new Set,a=r=>r[0]!==void 0&&i.add(r[0]);a(e.primaryKey);for(let r of e.uniques)a(r.columns);for(let r of e.indexes){let d=r.keys[0];d&&"column"in d&&r.where===void 0&&i.add(d.column)}let o=e.columns.find(r=>r.name===n);if(i.has(n)||!o||o.ignored)return;let l=`${e.name}_${n}_idx`;Buffer.byteLength(l)>63||e.indexes.some(r=>r.name===l)||t.has(l)||e.indexes.push({name:l,keys:[{column:n}],unique:!1})}function B(e,n){return!n&&D(e.onDelete,e.onUpdate)?{...e,deferrable:!0}:e}function Q(e){return e._def}function V(e,n,t){let i=[],a=s=>{let h=n.columns[s];return h!==void 0&&Q(h).encrypted?.lookup?g(s):s},o=(n.unique??[]).map(s=>({name:s.name,columns:s.columns.map(a)})),l=[],r=[],d=new Set,m=[];for(let[s,h]of Object.entries(n.columns)){let u=Q(h),c={name:s,type:j(e,s,n.name,u,t),nullable:u.nullable},E=F(u);E!==void 0&&(c.default=E),u.renamedFrom!==void 0&&(c.renamedFrom=u.renamedFrom),u.ignored&&(c.ignored=!0),u.fill!==void 0&&(c.fill=u.fill),u.identity!==void 0&&(c.identity=u.identity==="always"?"always":"by default"),u.generated!==void 0&&(c.generated={...u.generated}),u.user!==void 0&&(c.user={...u.user}),u.primaryKey&&r.push(s);let y=u.encrypted?.lookup?g(s):void 0;if(u.encrypted!==void 0&&(c.encrypted=y?{lookup:y}:{}),u.unique&&o.push(y?{name:`${n.name}_${y}_key`,columns:[y]}:{name:`${n.name}_${s}_key`,columns:[s]}),u.references!==void 0){let[b,R]=W(u.references.table);l.push(B({name:`${z(e,n.name)}_${s}_fkey`,columns:[s],refSchema:b,refTable:R,refColumns:[u.references.column],onDelete:u.onDeleteAction??"no action",onUpdate:u.onUpdateAction??"no action"},u.deferrable===!1)),u.index===!1&&d.add(s)}if(i.push(c),y){let b={name:y,type:"text",nullable:!0,lookupOf:s};u.renamedFrom!==void 0&&(b.renamedFrom=g(u.renamedFrom)),u.ignored&&(b.ignored=!0),i.push(b),u.unique||m.push({name:`${n.name}_${y}_idx`,keys:[{column:y}],unique:!1})}}for(let s of n.foreignKeys??[]){s.index===!1&&s.columns.length===1&&d.add(s.columns[0]);let[h,u]=W(s.refTable);l.push(B({name:s.name,columns:[...s.columns],refSchema:h,refTable:u,refColumns:[...s.refColumns],onDelete:s.onDelete??"no action",onUpdate:s.onUpdate??"no action",...s.match==="full"?{match:"full"}:{}},s.deferrable===!1))}let p={schema:e,name:n.name,columns:i,primaryKey:n.primaryKey!==void 0?[...n.primaryKey]:r,uniques:o,indexes:[...(n.indexes??[]).map(I),...m],checks:(n.checks??[]).map(s=>({name:s.name,expr:s.expr})),foreignKeys:l,rls:n.rls,policies:n.policies.map(L)};n.ignored&&(p.ignored=!0),n.search!==void 0&&(p.search={...n.search,from:[...n.search.from]}),p.uniques=H(p.uniques);let C=new Set((n.raw??[]).map(s=>s.name)),T=new Set(n.policies.filter(s=>s.indexes===!1).map(s=>s.name));return M(p,d,C,T),$.set(p,{rawNames:C,unindexedPolicies:T}),p}function j(e,n,t,i,a){let o=i.type;if(o==="enum"||o==="enum[]"){let l=i.enumName,r=`${e}.${l}`,d=i.enumValues??[],m=a.get(r);if(m&&m.values.join()!==d.join())throw new Error(`enum ${r} is declared with different values by ${t}.${n}: (${m.values.join(", ")}) and (${d.join(", ")}) \u2014 one type has one list`);return a.set(r,{schema:e,name:l,values:[...d]}),o==="enum[]"?`${_(e,l)}[]`:_(e,l)}return o==="sql"?K(i.sqlType):o==="numeric"&&i.precision!==void 0?`numeric(${i.precision},${i.scale??0})`:o.endsWith("[]")?`${q[o.slice(0,-2)]??o.slice(0,-2)}[]`:q[o]??o}function F(e){if(e.defaultSql!==void 0)return e.defaultSql;if(e.defaultRandom)return"gen_random_uuid()";if(e.defaultNow)return e.type==="date"?"CURRENT_DATE":"now()";let n=e.defaultValue;if(n!==void 0){if(Array.isArray(n)&&n.length===0&&e.type.endsWith("[]"))return"'{}'";if(typeof n=="string")return`'${n.replace(/'/g,"''")}'`;if(typeof n=="boolean")return n?"true":"false";if(typeof n=="number"){if(!Number.isFinite(n))throw new Error(`default ${n} is not a number Postgres can store`);return String(n)}return n===null?"NULL":`'${JSON.stringify(n).replace(/'/g,"''")}'::jsonb`}}function I(e){let n=e.expression!==void 0?[{expr:e.expression}]:(e.columns??[]).map(a=>({column:a}));for(let a of n)e.sort==="desc"&&(a.desc=!0),e.nulls!==void 0&&(a.nulls=e.nulls);let t={name:e.name,keys:n,unique:e.unique===!0},i=e.where===void 0?void 0:w(e.where);return i!==void 0&&(t.where=i),e.include?.length&&(t.include=[...e.include]),t}function L(e){let n={name:e.name,for:e.command,to:e.roles.length===0?["public"]:[...e.roles]},t=w(e.using),i=w(e.withCheck);return t!==void 0&&(n.using=t),i!==void 0&&(n.withCheck=i),e.permissive||(n.restrictive=!0),n}function M(e,n,t,i){let a=new Set,o=r=>r[0]!==void 0&&a.add(r[0]);o(e.primaryKey);for(let r of e.uniques)o(r.columns);for(let r of e.indexes){let d=r.keys[0];d&&"column"in d&&r.where===void 0&&a.add(d.column)}let l=r=>{if(a.has(r)||e.columns.find(m=>m.name===r)?.ignored)return;let d=`${e.name}_${r}_idx`;Buffer.byteLength(d)>63||e.indexes.some(m=>m.name===d)||t.has(d)||(e.indexes.push({name:d,keys:[{column:r}],unique:!1}),a.add(r))};for(let r of e.foreignKeys)r.columns.length===1&&!n.has(r.columns[0])&&l(r.columns[0]);for(let r of e.policies)if(!i.has(r.name))for(let d of Y(e,r))l(d)}function Y(e,n){let t=[];for(let i of[n.using,n.withCheck])if(i!==void 0)for(let a of i.matchAll(/(?<![.\w"])"((?:[^"]|"")+)"(?!\s*\.)/g)){let o=a[1].replace(/""/g,'"');e.columns.some(l=>l.name===o)&&!t.includes(o)&&t.push(o)}return t}function W(e){let n=e.indexOf(".");return n<0?["public",e]:[e.slice(0,n),e.slice(n+1)]}function z(e,n){return e==="public"?n:`${e}_${n}`}function H(e){let n=new Map;return e.filter(t=>{let i=n.get(t.name);if(i===void 0)return n.set(t.name,t),!0;if(i.columns.join()!==t.columns.join())throw new Error(`palgres: unique ${t.name} is declared over (${i.columns.join(", ")}) and over (${t.columns.join(", ")}): give one of them another name`);return!1})}var v=new Set(["uuid","text","integer","bigint","numeric","boolean","timestamp","date","enum"]),re={number:{fromDb:e=>e==null?e:Number(e),toDb:e=>{if(e==null||typeof e!="number")return e==null?e:String(e);if(!Number.isFinite(e))throw new Error(`asNumber() cannot write ${e}: it is not a finite number, and the column holds one.`);if(Number.isInteger(e)&&!Number.isSafeInteger(e))throw new Error(`asNumber() cannot write ${e}: it is outside the safe integer range and would be stored as a different number. Declare .asDecimal() and hand this column a string.`);return String(e)},tsType:"number"},decimal:{fromDb:e=>e==null?e:String(e),toDb:e=>e==null?e:String(e),tsType:"string"}},f=class e{_def;constructor(n,t){this._def=t??{type:n,nullable:!1,primaryKey:!1}}primaryKey(){return this._def.primaryKey=!0,new e(this._def.type,this._def)}notNull(){return this._def.nullable=!1,new e(this._def.type,this._def)}nullable(){if(this._def.identity!==void 0)throw new Error(".nullable() on an identity column: an identity is always NOT NULL");return this._def.nullable=!0,new e(this._def.type,this._def)}default(n){return this._def.defaultValue=n,new e(this._def.type,this._def)}defaultRandom(){return this._def.defaultRandom=!0,new e(this._def.type,this._def)}defaultNow(){return this._def.defaultNow=!0,new e(this._def.type,this._def)}defaultSql(n){if(typeof n!="string"||n.trim()==="")throw new Error("defaultSql() takes the SQL of the default");return this._def.defaultSql=n,new e(this._def.type,this._def)}dbAssigned(){return this._def.dbAssigned=!0,new e(this._def.type,this._def)}array(){let n=this._def.type;if(!v.has(n))throw new Error(`${n} column: .array() is available on uuid(), text(), integer(), bigint(), numeric(), boolean(), timestamp(), date() and enumType()`);if(this._def.defaultValue!==void 0||this._def.defaultNow||this._def.defaultRandom||this._def.defaultSql!==void 0)throw new Error(`.array() comes before the default \u2014 write ${n}().array().default([])`);if(this._def.codec!==void 0||this._def.transform!==void 0)throw new Error(".array() cannot follow a codec or a transform \u2014 they convert one value, not a list of them");let t=`${n}[]`;return new e(t,{...this._def,type:t})}identity(n){if(this._def.type!=="integer"&&this._def.type!=="bigint"&&!(this._def.type==="sql"&&this._def.sqlType==="smallint"))throw new Error(`${this._def.type} column: .identity() is for integer(), bigint() and sqlType('smallint') columns`);if(this._def.defaultValue!==void 0||this._def.defaultNow||this._def.defaultRandom||this._def.defaultSql!==void 0||this._def.fill!==void 0)throw new Error(".identity() is the column's value \u2014 it cannot also have a default or a fill");let t=n?.always===!1?"byDefault":"always";return new e(this._def.type,{...this._def,nullable:!1,identity:t})}generated(n,t={}){if(typeof n!="string"||n.trim()==="")throw new Error(".generated() takes the SQL expression the column is");if(this._def.defaultValue!==void 0||this._def.defaultNow||this._def.defaultRandom||this._def.defaultSql!==void 0||this._def.fill!==void 0||this._def.identity!==void 0)throw new Error(".generated() is the column's value \u2014 it cannot also have a default, a fill or an identity");return new e(this._def.type,{...this._def,generated:{expr:n,stored:t.stored===!0}})}fillWith(n){return new e(this._def.type,{...this._def,fill:n})}renamedFrom(n){return this._def.renamedFrom=n,this}ignored(){return new e(this._def.type,{...this._def,ignored:!0})}encrypted(n={}){if(this._def.type!=="text")throw new Error(`.encrypted() is for a text() column \u2014 a ${this._def.type} column's value is not text to seal; keep it in a text() column (JSON.stringify it)`);return new e("text",{...this._def,encrypted:{lookup:n.lookup===!0}})}references(n,t){if(typeof n!="function")throw new Error('references(...) takes a callback: write references(() => otherTable.column). The two-string form references("table", "column") is gone \u2014 a string cannot be type-checked and cannot point at a table that does not exist yet.');return this._def.referencesThunk=n,t?.as!==void 0&&(this._def.refAs=t.as),t?.reverseAs!==void 0&&(this._def.reverseAs=t.reverseAs),t?.onDelete!==void 0&&(this._def.onDeleteAction=t.onDelete),t?.onUpdate!==void 0&&(this._def.onUpdateAction=t.onUpdate),t?.index===!1&&(this._def.index=!1),t?.deferrable===!1&&(this._def.deferrable=!1),new e(this._def.type,this._def)}selfReferences(n,t){return this._def.selfRefColumn=n,t?.as!==void 0&&(this._def.refAs=t.as),t?.onDelete!==void 0&&(this._def.onDeleteAction=t.onDelete),new e(this._def.type,this._def)}onDelete(n){return this._def.onDeleteAction=n,new e(this._def.type,this._def)}unique(){return this._def.unique=!0,new e(this._def.type,this._def)}asNumber(){return this.withCodec("number","asNumber")}asDecimal(){return this.withCodec("decimal","asDecimal")}withCodec(n,t){if(this._def.type!=="bigint"&&this._def.type!=="numeric")throw new Error(`${this._def.type} column: .${t}() is only available on bigint()/numeric() \u2014 those are the exact-precision types that surface as string.`);if(this._def.transform!==void 0)throw new Error(`.${t}() and .transform() are two ways to say the same thing on one column \u2014 keep .${t}().`);if(this._def.codec!==void 0)throw new Error(`column already declares .as${this._def.codec==="number"?"Number":"Decimal"}(); a column has ONE codec.`);return new e(this._def.type,{...this._def,codec:n})}transform(n){if(this._def.codec!==void 0)throw new Error("column already declares a named codec; .transform() and .as*() are two ways to say the same thing \u2014 keep the codec.");return new e(this._def.type,{...this._def,transform:n})}};function ie(){return new f("uuid")}function oe(){return new f("text")}function se(){return new f("integer")}function le(){return new f("bigint")}function ue(e){if(e===void 0)return new f("numeric");let{precision:n,scale:t=0}=e;if(!Number.isInteger(n)||n<1||n>1e3)throw new Error(`numeric({ precision: ${n} }): precision is a whole number from 1 to 1000`);if(!Number.isInteger(t)||t<0||t>n)throw new Error(`numeric({ precision: ${n}, scale: ${t} }): scale is a whole number from 0 to the precision`);return new f("numeric",{type:"numeric",nullable:!1,primaryKey:!1,precision:n,scale:t})}function ae(){return new f("date")}var J={uuid:"uuid()",text:"text()",integer:"integer()",int:"integer()",int4:"integer()",bigint:"bigint()",int8:"bigint()",numeric:"numeric()",decimal:"numeric()",boolean:"boolean()",bool:"boolean()",timestamptz:"timestamp()","timestamp with time zone":"timestamp()",date:"date()",jsonb:"jsonb()"};function de(e){let n=typeof e=="string"?e.trim():"";if(n==="")throw new Error('sqlType() takes the Postgres type, e.g. sqlType("inet")');let t=n.toLowerCase().replace(/\[\]$/,""),i=J[t];if(i!==void 0&&!(n.endsWith("[]")&&!v.has(i.slice(0,-2))))throw new Error(`sqlType(${JSON.stringify(n)}): the DSL has this type \u2014 declare it as ${i}${n.endsWith("[]")?".array()":""}`);return new f("sql",{type:"sql",nullable:!1,primaryKey:!1,sqlType:n})}var fe=new Set(["smallint","real","double precision"]),me=new Set(["json"]);function ce(){return new f("boolean")}function ye(){return new f("timestamp")}function pe(){return new f("jsonb")}function he(e,n){let t=new f("enum");return t._def.enumName=e,t._def.enumValues=[...n],t}function be(){let e=new f("text");return e._def.nullable=!1,e._def.user={onDelete:"cascade",owns:!0},e}function ge(e){let n=new f("text");return n._def.user={onDelete:e.onDelete,owns:!1},e.as!==void 0&&(n._def.refAs=e.as),n}export{ne as a,Y as b,re as c,f as d,ie as e,oe as f,se as g,le as h,ue as i,ae as j,de as k,fe as l,me as m,ce as n,ye as o,pe as p,he as q,be as r,ge as s};
package/dist/dsl.js CHANGED
@@ -1,2 +1,2 @@
1
- /*! palgres 0.53.0 — Palbase SDK License (see LICENSE) */
2
- import{a as b,d as g,e as C,f as w,g as R,h as T,i as P,j as h,k as A,n as U,o as B,p as E,q as K,r as k,s as I}from"./chunks/XPFGITD6.js";import{A as D,n,o as i,p as f,q as a,r as l,s as p,t as u,u as m,v as s,w as y,x as c,y as d,z as x}from"./chunks/X2B6AJ7P.js";function M(o,t,e){if(e===void 0)return{name:o,up:t};let r={name:o,up:t};return e.drop!==void 0&&(r.drop=e.drop),e.before===!0&&(r.before=!0),r}export{g as ColumnBuilder,n as ForeignKeyBuilder,a as IndexBuilder,c as PolicyBuilder,s as PolicyExprRef,p as TABLE_META,T as bigint,U as boolean,x as check,h as date,m as defineSchema,u as defineTable,K as enumType,y as exprCtx,i as foreignKey,l as index,R as integer,E as jsonb,P as numeric,k as ownedByUser,d as policy,D as policySQL,f as qualifiedTableKey,M as raw,A as sqlType,w as text,B as timestamp,b as toModel,I as userRef,C as uuid};
1
+ /*! palgres 0.55.0 — Palbase SDK License (see LICENSE) */
2
+ import{a as b,d as g,e as C,f as w,g as R,h as T,i as P,j as h,k as A,n as U,o as B,p as E,q as K,r as k,s as I}from"./chunks/EBHTHWOS.js";import{F as n,G as i,H as f,I as a,J as l,K as p,L as u,M as m,N as s,O as y,P as c,Q as d,R as x,S as D}from"./chunks/DLP3GKUJ.js";function M(o,t,e){if(e===void 0)return{name:o,up:t};let r={name:o,up:t};return e.drop!==void 0&&(r.drop=e.drop),e.before===!0&&(r.before=!0),r}export{g as ColumnBuilder,n as ForeignKeyBuilder,a as IndexBuilder,c as PolicyBuilder,s as PolicyExprRef,p as TABLE_META,T as bigint,U as boolean,x as check,h as date,m as defineSchema,u as defineTable,K as enumType,y as exprCtx,i as foreignKey,l as index,R as integer,E as jsonb,P as numeric,k as ownedByUser,d as policy,D as policySQL,f as qualifiedTableKey,M as raw,A as sqlType,w as text,B as timestamp,b as toModel,I as userRef,C as uuid};