@stacksjs/stx 0.2.563 → 0.2.565
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/app-shell.d.ts +3 -0
- package/dist/app-shell.js +27 -3
- package/dist/{chunk-2tm3vzm7.js → chunk-01s01ten.js} +5 -5
- package/dist/chunk-04qvjcsr.js +2 -0
- package/dist/chunk-125rc958.js +3 -0
- package/dist/chunk-15g5sc0p.js +3 -0
- package/dist/{chunk-171xv81z.js → chunk-18270qgd.js} +2 -2
- package/dist/{chunk-g6cwhsb4.js → chunk-1hrj0t0j.js} +11 -11
- package/dist/chunk-1zfg1kd5.js +2 -0
- package/dist/chunk-203rr1c8.js +3 -0
- package/dist/{chunk-xb739v4r.js → chunk-2ernwctg.js} +6 -6
- package/dist/chunk-2xbrrc5a.js +2 -0
- package/dist/chunk-2yypassp.js +2 -0
- package/dist/{chunk-fgmv8f14.js → chunk-325p135t.js} +12 -12
- package/dist/{chunk-v1m9nrn9.js → chunk-36aj0yzt.js} +1 -1
- package/dist/chunk-375skn32.js +2 -0
- package/dist/{chunk-qmza4327.js → chunk-39tkfkp7.js} +3 -3
- package/dist/{chunk-jjwg83xv.js → chunk-3hkv4e7t.js} +1 -1
- package/dist/chunk-3wyxe996.js +2 -0
- package/dist/chunk-4mmdpb46.js +2 -0
- package/dist/chunk-4q5d5r7s.js +2 -0
- package/dist/{chunk-mtdx75j5.js → chunk-4zb2ga7p.js} +2 -2
- package/dist/{chunk-vb1w9wy4.js → chunk-55hfvmvv.js} +13 -13
- package/dist/{chunk-7t05bpf7.js → chunk-5grx48s2.js} +2 -2
- package/dist/{chunk-7wfh2hqy.js → chunk-5s555c1r.js} +4 -4
- package/dist/chunk-5ytg0wbc.js +2 -0
- package/dist/{chunk-8227vfw0.js → chunk-68b64sj4.js} +1 -1
- package/dist/chunk-6qyters0.js +2 -0
- package/dist/{chunk-6bxy1b9q.js → chunk-6sf4v894.js} +5 -5
- package/dist/{chunk-yp00nht2.js → chunk-6vnnx536.js} +2 -2
- package/dist/chunk-6yn90mq9.js +2 -0
- package/dist/chunk-7d2vyre0.js +2 -0
- package/dist/{chunk-r4199q6x.js → chunk-7m0r2qs2.js} +2 -2
- package/dist/chunk-7pewegtw.js +2 -0
- package/dist/chunk-7w0qa3n0.js +2 -0
- package/dist/{chunk-5fx8m234.js → chunk-7wyyjdks.js} +2 -2
- package/dist/{chunk-nd8v4xgb.js → chunk-7ze47qgv.js} +5 -5
- package/dist/{chunk-x8rx0s3h.js → chunk-8afnq4qx.js} +3 -3
- package/dist/{chunk-gxtk4fbm.js → chunk-8cpqy9ea.js} +1726 -1726
- package/dist/{chunk-97vj2cqz.js → chunk-8cs45k3f.js} +3 -3
- package/dist/chunk-8d788kvt.js +2 -0
- package/dist/{chunk-s040j1bv.js → chunk-8nr1kras.js} +6 -6
- package/dist/{chunk-912cj8pq.js → chunk-8txqk9nq.js} +2 -2
- package/dist/chunk-90qywh24.js +31 -0
- package/dist/{chunk-nda4xq79.js → chunk-9tcvkbb5.js} +2 -2
- package/dist/{chunk-vpmb8gcc.js → chunk-9ya4tdpz.js} +4 -4
- package/dist/{chunk-n1cqg89v.js → chunk-b76jbdtk.js} +2 -2
- package/dist/chunk-bdhtq3vs.js +2 -0
- package/dist/chunk-brnapchc.js +2 -0
- package/dist/chunk-c765y72x.js +18 -0
- package/dist/chunk-c78327kx.js +2 -0
- package/dist/chunk-cbyh8fhn.js +4 -0
- package/dist/chunk-d19w3e4x.js +2 -0
- package/dist/{chunk-jen9yg68.js → chunk-d1mqedk0.js} +7 -7
- package/dist/{chunk-6v1gwdbv.js → chunk-d4ybwtqt.js} +2 -2
- package/dist/chunk-da649d3k.js +2 -0
- package/dist/chunk-da9avgd9.js +2 -0
- package/dist/chunk-dkyjw3hc.js +3 -0
- package/dist/{chunk-ff61d2wr.js → chunk-dmf1jmge.js} +3 -3
- package/dist/chunk-e3njkecx.js +2 -0
- package/dist/chunk-efzc1nw8.js +2 -0
- package/dist/{chunk-h23bjqn1.js → chunk-ev3qnr9q.js} +31 -31
- package/dist/{chunk-y0pbnxjg.js → chunk-f46a7pvn.js} +2 -2
- package/dist/{chunk-azb58ven.js → chunk-ffxwsa94.js} +2 -2
- package/dist/chunk-fm4w1r9e.js +2 -0
- package/dist/{chunk-8jc86h7n.js → chunk-fpa1nq88.js} +2 -2
- package/dist/{chunk-tc2z8t2q.js → chunk-g1epk002.js} +5 -5
- package/dist/{chunk-8a4g0mex.js → chunk-g8tx0yf8.js} +7 -7
- package/dist/chunk-gan95hj0.js +2 -0
- package/dist/{chunk-e124cgb6.js → chunk-ghnkphy4.js} +2 -2
- package/dist/{chunk-m5fw8jq1.js → chunk-gjx5256r.js} +5 -5
- package/dist/chunk-hg7amzgz.js +2 -0
- package/dist/chunk-hmk7z0z6.js +2 -0
- package/dist/chunk-hn105xy3.js +2 -0
- package/dist/{chunk-8nwzd6eg.js → chunk-jbmhdyzz.js} +3 -3
- package/dist/chunk-jq079mrx.js +2 -0
- package/dist/chunk-jr149mmp.js +2 -0
- package/dist/{chunk-v79qs0qh.js → chunk-jra9r8fq.js} +1 -1
- package/dist/{chunk-zmq9hwta.js → chunk-k2dgwy05.js} +2 -2
- package/dist/chunk-k50k9zbw.js +2 -0
- package/dist/{chunk-xab6b4mt.js → chunk-kch9a9v1.js} +2 -2
- package/dist/chunk-kwxy0e3r.js +2 -0
- package/dist/chunk-kza3nxr0.js +2 -0
- package/dist/{chunk-g12j8ahm.js → chunk-m6m19hwd.js} +4 -4
- package/dist/{chunk-a5kaw8sc.js → chunk-m8qgr307.js} +8 -8
- package/dist/chunk-m9cmc6np.js +2 -0
- package/dist/chunk-m9r4x7e6.js +2 -0
- package/dist/chunk-mahv855w.js +2 -0
- package/dist/{chunk-27t55gtk.js → chunk-mb59b499.js} +6 -6
- package/dist/chunk-mbwdn96z.js +2 -0
- package/dist/chunk-mdxg95mq.js +2 -0
- package/dist/{chunk-2m91qmby.js → chunk-mm1vvk49.js} +5 -5
- package/dist/chunk-mqje968d.js +2 -0
- package/dist/{chunk-pp9jgyb6.js → chunk-mt8sew7a.js} +10 -10
- package/dist/{chunk-7gdvp6py.js → chunk-n1xcmhjw.js} +3 -3
- package/dist/chunk-n2g9mj2h.js +2 -0
- package/dist/chunk-n2nha538.js +2 -0
- package/dist/{chunk-f92hq39b.js → chunk-n6va14bt.js} +2 -2
- package/dist/chunk-nebw444s.js +2 -0
- package/dist/{chunk-gbx3gx8a.js → chunk-nm0y4qjg.js} +4 -4
- package/dist/chunk-nmt7kw0e.js +2 -0
- package/dist/chunk-pq8mz4ma.js +2 -0
- package/dist/chunk-pxcmv1xz.js +2 -0
- package/dist/chunk-pxes1ft6.js +2 -0
- package/dist/{chunk-v09hk0j6.js → chunk-pzasxhwz.js} +1 -1
- package/dist/{chunk-v2b8pa86.js → chunk-q94wdmdp.js} +3 -3
- package/dist/chunk-qajc13zq.js +2 -0
- package/dist/{chunk-1c4t7ncb.js → chunk-qj4j547f.js} +2 -2
- package/dist/chunk-qtnqmw1n.js +2 -0
- package/dist/chunk-r3zdgeah.js +2 -0
- package/dist/{chunk-4r7s3862.js → chunk-r47cs92n.js} +2 -2
- package/dist/chunk-r5htacg5.js +2 -0
- package/dist/chunk-rf2rwddd.js +2 -0
- package/dist/{chunk-1xgs9gd5.js → chunk-rgage0vm.js} +2 -2
- package/dist/{chunk-1zeqghsw.js → chunk-s1xxkzc9.js} +9 -9
- package/dist/chunk-s833fbvf.js +2 -0
- package/dist/{chunk-tqnh98j7.js → chunk-saf7kypg.js} +3 -3
- package/dist/chunk-sgvszh9s.js +2 -0
- package/dist/{chunk-emta09j6.js → chunk-ss78553t.js} +1 -1
- package/dist/chunk-t5r3s1wj.js +2 -0
- package/dist/{chunk-bqdsc6rm.js → chunk-tc01jkfc.js} +1 -1
- package/dist/{chunk-p2mxsjv1.js → chunk-tfeenp4h.js} +10 -10
- package/dist/chunk-tjprg6kq.js +2 -0
- package/dist/{chunk-hj67a88k.js → chunk-tsmbstj6.js} +7 -7
- package/dist/chunk-v0dzrwg8.js +2 -0
- package/dist/chunk-vtz9empe.js +2 -0
- package/dist/chunk-wa6nzq5b.js +2 -0
- package/dist/{chunk-3nc2fr4q.js → chunk-wm11csdm.js} +2 -2
- package/dist/{chunk-xj45mw7v.js → chunk-wsdn5fxe.js} +3 -3
- package/dist/{chunk-ah7h9q0x.js → chunk-wwn9dh6p.js} +2 -2
- package/dist/{chunk-yn3kp3qy.js → chunk-wy4hfmjs.js} +5 -5
- package/dist/{chunk-qfc912e5.js → chunk-xfpfs9zq.js} +2 -2
- package/dist/chunk-xw8kzm6b.js +2834 -0
- package/dist/chunk-xyhg70x9.js +63 -0
- package/dist/{chunk-w8q1xp9e.js → chunk-ymdy7b8z.js} +2 -2
- package/dist/chunk-ytdzgctp.js +2 -0
- package/dist/{chunk-wk85dz07.js → chunk-z06npyzn.js} +3 -3
- package/dist/chunk-z2n1rtj5.js +2 -0
- package/dist/cli.js +22 -22
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/database.js +2 -2
- package/dist/native/components/primitives.d.ts +20 -4
- package/dist/native/index.d.ts +3 -0
- package/dist/native/primitives/Map.stx +2 -1
- package/dist/native/prop-names.js +3 -0
- package/dist/native/runtime/craft-bridge.js +24 -11
- package/dist/native/runtime/craft.d.ts +6 -5
- package/dist/pwa.js +3 -3
- package/dist/ssg.js +11 -11
- package/dist/stx.d.ts +1 -1028
- package/dist/variable-extractor.js +2 -2
- package/package.json +5 -5
- package/stx.d.ts +2 -0
- package/dist/chunk-00dp53cx.js +0 -2
- package/dist/chunk-0pvn63x7.js +0 -2
- package/dist/chunk-0vpmdhfm.js +0 -2
- package/dist/chunk-10jwyvm0.js +0 -2
- package/dist/chunk-1ena03xn.js +0 -2
- package/dist/chunk-2bpj2dsh.js +0 -2
- package/dist/chunk-31ez1sq0.js +0 -2
- package/dist/chunk-3m2h76cz.js +0 -2
- package/dist/chunk-3n26hf93.js +0 -2
- package/dist/chunk-3nk8cnrm.js +0 -3
- package/dist/chunk-3tccqahy.js +0 -2
- package/dist/chunk-40fqmb3q.js +0 -2
- package/dist/chunk-45tq56qf.js +0 -2
- package/dist/chunk-46wykvrs.js +0 -2
- package/dist/chunk-4cmqjmqr.js +0 -3
- package/dist/chunk-56mkcxvb.js +0 -2
- package/dist/chunk-56wcmck6.js +0 -2
- package/dist/chunk-5eyf2zeg.js +0 -2
- package/dist/chunk-68ph8r20.js +0 -2
- package/dist/chunk-6bcvd3pg.js +0 -2
- package/dist/chunk-6n8jzdnm.js +0 -18
- package/dist/chunk-6va8wt88.js +0 -2
- package/dist/chunk-7acxdp9r.js +0 -2
- package/dist/chunk-7h324n17.js +0 -2
- package/dist/chunk-8fpz04kx.js +0 -2
- package/dist/chunk-8fwczr4s.js +0 -63
- package/dist/chunk-9skdekv5.js +0 -2
- package/dist/chunk-c3v5zmnq.js +0 -2
- package/dist/chunk-ce7zwt4v.js +0 -2
- package/dist/chunk-cp4dr9ch.js +0 -2
- package/dist/chunk-d7mfkc61.js +0 -2
- package/dist/chunk-d8fhthyf.js +0 -2
- package/dist/chunk-dekpf1ry.js +0 -2
- package/dist/chunk-dyavx9a1.js +0 -2
- package/dist/chunk-dz7v901d.js +0 -2
- package/dist/chunk-e099d50m.js +0 -2
- package/dist/chunk-e473tm1d.js +0 -2
- package/dist/chunk-eeadhr78.js +0 -2
- package/dist/chunk-evwj0k99.js +0 -2834
- package/dist/chunk-f11sx09b.js +0 -3
- package/dist/chunk-fdkyvr7y.js +0 -2
- package/dist/chunk-fqge0zn8.js +0 -2
- package/dist/chunk-fz7dxc1q.js +0 -2
- package/dist/chunk-hp8g2q2n.js +0 -2
- package/dist/chunk-hpeg9erh.js +0 -3
- package/dist/chunk-hv2kxb94.js +0 -2
- package/dist/chunk-j9c0yam7.js +0 -2
- package/dist/chunk-k9nd7z8j.js +0 -2
- package/dist/chunk-m7jmpech.js +0 -2
- package/dist/chunk-m7ktr4xn.js +0 -2
- package/dist/chunk-mjdyyekx.js +0 -4
- package/dist/chunk-njrakvz7.js +0 -2
- package/dist/chunk-nr5jf1hp.js +0 -2
- package/dist/chunk-qd7bqhm3.js +0 -2
- package/dist/chunk-qprkb5qe.js +0 -2
- package/dist/chunk-schxd5k5.js +0 -2
- package/dist/chunk-sn5c0x7q.js +0 -2
- package/dist/chunk-sx4wmprc.js +0 -2
- package/dist/chunk-t94z65ry.js +0 -2
- package/dist/chunk-vakryadj.js +0 -2
- package/dist/chunk-vgge9rf4.js +0 -2
- package/dist/chunk-w36w5jgs.js +0 -30
- package/dist/chunk-wzymzex7.js +0 -2
- package/dist/chunk-x07x8hzs.js +0 -2
- package/dist/chunk-z9q5p39g.js +0 -2
- package/dist/chunk-zfypzka2.js +0 -2
- package/dist/chunk-zh0jbzvk.js +0 -2
- package/dist/chunk-zpf9he2x.js +0 -2
- package/dist/chunk-zpftj8s8.js +0 -2
package/dist/database.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var u={default:"sqlite",connections:{},logging:!1,cacheTTL:0,maxCacheSize:1000},k={},C={},f=new Map,P=[];function z(t){u={...u,...t}}function V(){return{...u}}function G(){u={default:"sqlite",connections:{},logging:!1,cacheTTL:0,maxCacheSize:1000};for(let t of Object.keys(k))delete k[t];f.clear(),P.length=0}function X(t,e){k[t]=e}function g(t){let e=t||u.default;if(k[e])return k[e];let r=u.connections[e];if(!r)throw Error(`Database connection "${e}" not configured`);let s=N(r);return k[e]=s,s}function N(t){switch(t.driver){case"sqlite":return D(t);case"postgres":return S(t);case"mysql":return L(t);default:throw Error(`Unsupported database driver: ${t.driver}`)}}function D(t){let e=null,r=!1;return{async connect(){if(r)return;let{Database:s}=await import("bun:sqlite");e=new s(t.database,{create:!0,readwrite:!0}),r=!0},async disconnect(){if(e)e.close(),e=null,r=!1},async query(s,n=[]){if(!r)await this.connect();let i=performance.now();try{let o=e.prepare(s).all(...n);if(u.logging)y(s,n,performance.now()-i);return o}catch(a){throw new m(`Query failed: ${a}`,s,n)}},async insert(s,n=[]){if(!r)await this.connect();let i=performance.now();try{let o=e.prepare(s).run(...n);if(u.logging)y(s,n,performance.now()-i);return o.lastInsertRowid}catch(a){throw new m(`Insert failed: ${a}`,s,n)}},async execute(s,n=[]){if(!r)await this.connect();let i=performance.now();try{let o=e.prepare(s).run(...n);if(u.logging)y(s,n,performance.now()-i);return o.changes}catch(a){throw new m(`Execute failed: ${a}`,s,n)}},async beginTransaction(){if(!r)await this.connect();e.run("BEGIN TRANSACTION")},async commit(){e.run("COMMIT")},async rollback(){e.run("ROLLBACK")},isConnected(){return r}}}function S(t){let e=!1,r=null;return{async connect(){if(e)return;try{let{Client:s}=await import("pg");r=new s({host:t.host||"localhost",port:t.port||5432,database:t.database,user:t.username,password:t.password,ssl:t.ssl}),await r.connect(),e=!0}catch(s){throw Error(`PostgreSQL connection failed. Install 'pg' package: ${s}`)}},async disconnect(){if(r)await r.end(),r=null,e=!1},async query(s,n=[]){if(!e)await this.connect();let i=performance.now();try{let a=await r.query(s,n);if(u.logging)y(s,n,performance.now()-i);return a.rows}catch(a){throw new m(`Query failed: ${a}`,s,n)}},async insert(s,n=[]){if(!e)await this.connect();let i=performance.now();try{let a=await r.query(`${s} RETURNING id`,n);if(u.logging)y(s,n,performance.now()-i);return a.rows[0]?.id}catch(a){throw new m(`Insert failed: ${a}`,s,n)}},async execute(s,n=[]){if(!e)await this.connect();let i=performance.now();try{let a=await r.query(s,n);if(u.logging)y(s,n,performance.now()-i);return a.rowCount||0}catch(a){throw new m(`Execute failed: ${a}`,s,n)}},async beginTransaction(){if(!e)await this.connect();await r.query("BEGIN")},async commit(){await r.query("COMMIT")},async rollback(){await r.query("ROLLBACK")},isConnected(){return e}}}function L(t){let e=!1,r=null;return{async connect(){if(e)return;try{let s=await import("mysql2/promise");r=s.createPool({host:t.host||"localhost",port:t.port||3306,database:t.database,user:t.username,password:t.password,waitForConnections:!0,connectionLimit:t.poolSize||10,queueLimit:0}),e=!0}catch(s){throw Error(`MySQL connection failed. Install 'mysql2' package: ${s}`)}},async disconnect(){if(r)await r.end(),r=null,e=!1},async query(s,n=[]){if(!e)await this.connect();let i=performance.now();try{let[a]=await r.execute(s,n);if(u.logging)y(s,n,performance.now()-i);return a}catch(a){throw new m(`Query failed: ${a}`,s,n)}},async insert(s,n=[]){if(!e)await this.connect();let i=performance.now();try{let[a]=await r.execute(s,n);if(u.logging)y(s,n,performance.now()-i);return a.insertId}catch(a){throw new m(`Insert failed: ${a}`,s,n)}},async execute(s,n=[]){if(!e)await this.connect();let i=performance.now();try{let[a]=await r.execute(s,n);if(u.logging)y(s,n,performance.now()-i);return a.affectedRows||0}catch(a){throw new m(`Execute failed: ${a}`,s,n)}},async beginTransaction(){if(!e)await this.connect();let s=await r.getConnection();return await s.beginTransaction(),s},async commit(){await r.execute("COMMIT")},async rollback(){await r.execute("ROLLBACK")},isConnected(){return e}}}class x{_table="";_columns=["*"];_wheres=[];_orders=[];_joins=[];_groupBy=[];_having=[];_limit;_offset;_distinct=!1;_connection;_bindings=[];_modelDefinition;constructor(t){if(t)this._table=t}table(t){return this._table=t,this}from(t){return this.table(t)}connection(t){return this._connection=t,this}select(...t){return this._columns=t.length>0?t:["*"],this}addSelect(...t){if(this._columns[0]==="*")this._columns=t;else this._columns.push(...t);return this}distinct(){return this._distinct=!0,this}where(t,e,r){let s="=",n=e;if(r!==void 0)s=e,n=r;return this._wheres.push({column:t,operator:s,value:n,boolean:"and"}),this}orWhere(t,e,r){let s="=",n=e;if(r!==void 0)s=e,n=r;return this._wheres.push({column:t,operator:s,value:n,boolean:"or"}),this}whereIn(t,e){return this._wheres.push({column:t,operator:"in",value:e,boolean:"and"}),this}whereNotIn(t,e){return this._wheres.push({column:t,operator:"not in",value:e,boolean:"and"}),this}whereNull(t){return this._wheres.push({column:t,operator:"is null",value:null,boolean:"and"}),this}whereNotNull(t){return this._wheres.push({column:t,operator:"is not null",value:null,boolean:"and"}),this}whereBetween(t,e,r){return this._wheres.push({column:t,operator:"between",value:[e,r],boolean:"and"}),this}whereLike(t,e){return this._wheres.push({column:t,operator:"like",value:e,boolean:"and"}),this}join(t,e,r,s){return this._joins.push({type:"inner",table:t,first:e,operator:r,second:s}),this}leftJoin(t,e,r,s){return this._joins.push({type:"left",table:t,first:e,operator:r,second:s}),this}rightJoin(t,e,r,s){return this._joins.push({type:"right",table:t,first:e,operator:r,second:s}),this}orderBy(t,e="asc"){return this._orders.push({column:t,direction:e}),this}orderByDesc(t){return this.orderBy(t,"desc")}groupBy(...t){return this._groupBy.push(...t),this}having(t,e,r){return this._having.push({column:t,operator:e,value:r,boolean:"and"}),this}limit(t){return this._limit=t,this}take(t){return this.limit(t)}offset(t){return this._offset=t,this}skip(t){return this.offset(t)}forPage(t,e=15){return this.offset((t-1)*e).limit(e)}async get(){let{sql:t,bindings:e}=this.toSql();if(u.cacheTTL&&u.cacheTTL>0){let n=this.getCacheKey(t,e),i=Q(n);if(i!==void 0)return i}let s=await g(this._connection).query(t,e);if(u.cacheTTL&&u.cacheTTL>0){let n=this.getCacheKey(t,e);B(n,s,u.cacheTTL)}return s}async first(){return(await this.limit(1).get())[0]||null}async firstOrFail(){let t=await this.first();if(!t)throw Error("No results found");return t}async find(t,e="id"){return this.where(e,t).first()}async value(t){let e=await this.select(t).first();return e?e[t]:null}async pluck(t){return(await this.select(t).get()).map((r)=>r[t])}async exists(){return(await this.select(_("1")).limit(1).get()).length>0}async doesntExist(){return!await this.exists()}async count(t="*"){let e=await this.select(_(`COUNT(${t}) as count`)).first();return Number(e?.count||0)}async max(t){return(await this.select(_(`MAX(${t}) as max`)).first())?.max}async min(t){return(await this.select(_(`MIN(${t}) as min`)).first())?.min}async sum(t){let e=await this.select(_(`SUM(${t}) as sum`)).first();return Number(e?.sum||0)}async avg(t){return(await this.select(_(`AVG(${t}) as avg`)).first())?.avg}async insert(t){let e=Object.keys(t),r=e.map(()=>"?").join(", "),s=Object.values(t),n=`INSERT INTO ${this._table} (${e.join(", ")}) VALUES (${r})`,i=g(this._connection);return T(this._table),i.insert(n,s)}async insertAll(t){if(t.length===0)return;let e=Object.keys(t[0]),r=t.map(()=>`(${e.map(()=>"?").join(", ")})`).join(", "),s=t.flatMap((a)=>Object.values(a)),n=`INSERT INTO ${this._table} (${e.join(", ")}) VALUES ${r}`,i=g(this._connection);T(this._table),await i.execute(n,s)}async update(t){this._bindings=[];let e=this.buildWhereClause(),r=[...this._bindings],s=Object.keys(t).map((o)=>`${o} = ?`).join(", "),n=[...Object.values(t),...r],i=`UPDATE ${this._table} SET ${s}${e}`,a=g(this._connection);return T(this._table),a.execute(i,n)}async increment(t,e=1){this._bindings=[];let r=this.buildWhereClause(),s=`UPDATE ${this._table} SET ${t} = ${t} + ?${r}`,n=g(this._connection);return T(this._table),n.execute(s,[e,...this._bindings])}async decrement(t,e=1){return this.increment(t,-e)}async delete(){this._bindings=[];let t=this.buildWhereClause(),e=`DELETE FROM ${this._table}${t}`,r=g(this._connection);return T(this._table),r.execute(e,this._bindings)}async truncate(){let t=g(this._connection);T(this._table),await t.execute(`DELETE FROM ${this._table}`)}toSql(){this._bindings=[];let t="SELECT ";if(this._distinct)t+="DISTINCT ";t+=this._columns.map((e)=>{if(typeof e==="object"&&e.__raw)return e.sql;return e}).join(", "),t+=` FROM ${this._table}`;for(let e of this._joins)t+=` ${e.type.toUpperCase()} JOIN ${e.table} ON ${e.first} ${e.operator} ${e.second}`;if(t+=this.buildWhereClause(),this._groupBy.length>0)t+=` GROUP BY ${this._groupBy.join(", ")}`;if(this._having.length>0){let e=this._having.map((r,s)=>{let n=s===0?"":` ${r.boolean.toUpperCase()} `;return this._bindings.push(r.value),`${n}${r.column} ${r.operator} ?`});t+=` HAVING ${e.join("")}`}if(this._orders.length>0)t+=` ORDER BY ${this._orders.map((e)=>`${e.column} ${e.direction.toUpperCase()}`).join(", ")}`;if(this._limit!==void 0)t+=` LIMIT ${this._limit}`;if(this._offset!==void 0)t+=` OFFSET ${this._offset}`;return{sql:t,bindings:this._bindings}}buildWhereClause(){if(this._wheres.length===0)return"";return this._wheres.map((e,r)=>{let s=r===0?" WHERE ":` ${e.boolean.toUpperCase()} `;switch(e.operator){case"in":{let n=e.value,i=n.map(()=>"?").join(", ");return this._bindings.push(...n),`${s}${e.column} IN (${i})`}case"not in":{let n=e.value,i=n.map(()=>"?").join(", ");return this._bindings.push(...n),`${s}${e.column} NOT IN (${i})`}case"between":{let[n,i]=e.value;return this._bindings.push(n,i),`${s}${e.column} BETWEEN ? AND ?`}case"is null":return`${s}${e.column} IS NULL`;case"is not null":return`${s}${e.column} IS NOT NULL`;default:return this._bindings.push(e.value),`${s}${e.column} ${e.operator} ?`}}).join("")}getCacheKey(t,e){return`${this._table}:${t}:${JSON.stringify(e)}`}clone(){let t=new x(this._table);return t._columns=[...this._columns],t._wheres=[...this._wheres],t._orders=[...this._orders],t._joins=[...this._joins],t._groupBy=[...this._groupBy],t._having=[...this._having],t._limit=this._limit,t._offset=this._offset,t._distinct=this._distinct,t._connection=this._connection,t}}function l(t){return new x(t)}function Y(t){return l(t)}function _(t,e=[]){return{__raw:!0,sql:t,bindings:e}}function H(t,e){let r=e.primaryKey||"id",s={name:t,definition:e,async find(n){let i=await l(e.table).where(r,n).first();return i?b(s,i):null},async findOrFail(n){let i=await this.find(n);if(!i)throw Error(`${t} not found with ${r} = ${n}`);return i},async all(){return(await l(e.table).get()).map((i)=>b(s,i))},async create(n){let i={...e.defaults,...n},a=e.fillable?Object.fromEntries(Object.entries(i).filter(([c])=>e.fillable.includes(c))):i;if(e.timestamps!==!1){let c=new Date().toISOString(),h=typeof e.timestamps==="object"?e.timestamps.createdAt||"created_at":"created_at",p=typeof e.timestamps==="object"?e.timestamps.updatedAt||"updated_at":"updated_at";a[h]=c,a[p]=c}let o=await l(e.table).insert(a);return this.findOrFail(o)},async update(n){return l(e.table).update(n)},async destroy(n){let i=Array.isArray(n)?n:[n];return l(e.table).whereIn(r,i).delete()},query(){return l(e.table)},where(n,i,a){return this.query().where(n,i,a)},async first(){let n=await this.query().first();return n?b(s,n):null},async get(){return(await this.query().get()).map((i)=>b(s,i))},async count(){return this.query().count()}};return C[t]=s,s}function v(t){let e=C[t];if(!e)throw Error(`Model "${t}" not defined. Use defineModel() first.`);return e}function Z(t){return t in C}function b(t,e){let{definition:r}=t,s=r.primaryKey||"id",n={...e},i={...e};if(r.casts){for(let[o,c]of Object.entries(r.casts))if(o in i)i[o]=q(i[o],c)}let a={exists:!0,original:n,attributes:i,get(o){return i[o]},set(o,c){i[o]=c},toJSON(){let o={...i};if(r.hidden)for(let c of r.hidden)delete o[c];return o},async save(){let o={};for(let c of Object.keys(i))if(i[c]!==n[c])o[c]=i[c];if(Object.keys(o).length>0){if(r.timestamps!==!1){let c=typeof r.timestamps==="object"?r.timestamps.updatedAt||"updated_at":"updated_at";o[c]=new Date().toISOString()}await l(r.table).where(s,n[s]).update(o),Object.assign(n,o)}},async delete(){if(r.softDeletes){let o=typeof r.softDeletes==="string"?r.softDeletes:"deleted_at";await l(r.table).where(s,n[s]).update({[o]:new Date().toISOString()})}else await l(r.table).where(s,n[s]).delete();a.exists=!1},async refresh(){let o=await l(r.table).where(s,n[s]).first();if(o)Object.assign(n,o),Object.assign(i,o)},isDirty(o){if(o)return i[o]!==n[o];return Object.keys(i).some((c)=>i[c]!==n[c])}};if(r.relationships)for(let[o,c]of Object.entries(r.relationships))Object.defineProperty(a,o,{value:async()=>j(a,c,t),enumerable:!1});return new Proxy(a,{get(o,c){if(c in o)return o[c];return i[c]},set(o,c,h){if(c in o)o[c]=h;else i[c]=h;return!0}})}async function j(t,e,r){let s=v(e.model),n=r.definition.primaryKey||"id";switch(e.type){case"hasOne":{let i=e.foreignKey||`${r.name.toLowerCase()}_id`,a=await l(s.definition.table).where(i,t.get(n)).first();return a?b(s,a):null}case"hasMany":{let i=e.foreignKey||`${r.name.toLowerCase()}_id`;return(await l(s.definition.table).where(i,t.get(n)).get()).map((o)=>b(s,o))}case"belongsTo":{let i=e.foreignKey||`${e.model.toLowerCase()}_id`,a=e.localKey||"id",o=await l(s.definition.table).where(a,t.get(i)).first();return o?b(s,o):null}case"belongsToMany":{let i=e.pivotTable||[r.name,e.model].sort().join("_").toLowerCase(),a=e.pivotForeignKey||`${r.name.toLowerCase()}_id`,o=e.pivotRelatedKey||`${e.model.toLowerCase()}_id`,c=s.definition.primaryKey||"id";return(await l(s.definition.table).join(i,`${s.definition.table}.${c}`,"=",`${i}.${o}`).where(`${i}.${a}`,t.get(n)).get()).map((p)=>b(s,p))}default:return null}}function q(t,e){if(t===null||t===void 0)return t;switch(e){case"string":return String(t);case"number":return Number(t);case"boolean":return Boolean(t);case"date":return new Date(t);case"json":case"array":return typeof t==="string"?JSON.parse(t):t;default:return t}}async function tt(t,e){let r=g(e);await r.beginTransaction();try{let s=await t();return await r.commit(),s}catch(s){throw await r.rollback(),s}}function Q(t){let e=f.get(t);if(!e)return;if(Date.now()-e.timestamp>e.ttl*1000){f.delete(t);return}return e.result}function B(t,e,r){if(f.size>=(u.maxCacheSize||1000)){let s=f.keys().next().value;if(s)f.delete(s)}f.set(t,{result:e,timestamp:Date.now(),ttl:r})}function T(t){for(let e of f.keys())if(e.startsWith(`${t}:`))f.delete(e)}function et(){f.clear()}function nt(){return{size:f.size,keys:[...f.keys()]}}function y(t,e,r){if(P.push({sql:t,bindings:e,duration:r,timestamp:new Date}),P.length>1000)P.shift()}function rt(){return[...P]}function st(){P.length=0}function it(t=!0){u.logging=t}class m extends Error{sql;bindings;constructor(t,e,r){super(t);this.sql=e;this.bindings=r;this.name="DatabaseError"}}async function K(t,e,r,s){let n=/@db\(\s*['"]([^'"]+)['"]\s*\)((?:->\w+\([^)]*\))*)/g,i=t,a=[...t.matchAll(n)];for(let o of a){let[c,h,p]=o;try{let d=await W(h,p),w=`$${h}`;e[w]=d,i=i.replace(c,"")}catch(d){i=i.replace(c,`<!-- DB Error: ${d instanceof Error?d.message:String(d)} -->`)}}return i}async function U(t,e,r,s){let n=/@model\(\s*['"]([^'"]+)['"]\s*\)((?:->\w+\([^)]*\))*)/g,i=t,a=[...t.matchAll(n)];for(let o of a){let[c,h,p]=o;try{let d=v(h),w=await J(d,p),E=`$${h.toLowerCase()}`;e[E]=w,i=i.replace(c,"")}catch(d){i=i.replace(c,`<!-- Model Error: ${d instanceof Error?d.message:String(d)} -->`)}}return i}async function F(t,e,r,s){let n=/@query\(\s*['"]([^'"]+)['"]\s*(?:,\s*(\[[^\]]*\]))?\s*\)\s*as\s+\$(\w+)/g,i=t,a=[...t.matchAll(n)];for(let o of a){let[c,h,p,d]=o;try{let w=p?JSON.parse(p):[],A=await g().query(h,w);e[`$${d}`]=A,i=i.replace(c,"")}catch(w){i=i.replace(c,`<!-- Query Error: ${w instanceof Error?w.message:String(w)} -->`)}}return i}async function W(t,e){let r=l(t),s=/->(\w+)\(([^)]*)\)/g,n=[...e.matchAll(s)],i=r;for(let[,a,o]of n){let c=O(o);if(typeof i[a]==="function"){if(i=i[a](...c),i instanceof Promise){i=await i;break}}}if(i instanceof x)i=await i.get();return i}async function J(t,e){let r=/->(\w+)\(([^)]*)\)/g,s=[...e.matchAll(r)],n=t;for(let[,i,a]of s){let o=O(a);if(typeof n[i]==="function"){if(n=n[i](...o),n instanceof Promise)n=await n}else if(n instanceof x){if(typeof n[i]==="function"){if(n=n[i](...o),n instanceof Promise)n=await n}}}if(n instanceof x)n=await n.get();return n}function O(t){if(!t.trim())return[];let e=[],r="",s=0,n=!1,i="";for(let a=0;a<t.length;a++){let o=t[a];if(!n&&(o==='"'||o==="'"))n=!0,i=o,r+=o;else if(n&&o===i)n=!1,r+=o;else if(!n&&(o==="["||o==="{"||o==="("))s++,r+=o;else if(!n&&(o==="]"||o==="}"||o===")"))s--,r+=o;else if(!n&&s===0&&o===",")e.push(R(r.trim())),r="";else r+=o}if(r.trim())e.push(R(r.trim()));return e}function R(t){if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t==="true")return!0;if(t==="false")return!1;if(t==="null")return null;let e=Number(t);if(!Number.isNaN(e))return e;try{return JSON.parse(t)}catch{return t}}async function ot(t,e,r,s){let n=t;return n=await F(n,e,r,s),n=await U(n,e,r,s),n=await K(n,e,r,s),n}class I{_connection;connection(t){return this._connection=t,this}async create(t,e){let r=new M(t);e(r);let s=r.toCreateSQL();await g(this._connection).execute(s)}async drop(t){await g(this._connection).execute(`DROP TABLE IF EXISTS ${t}`)}async rename(t,e){await g(this._connection).execute(`ALTER TABLE ${t} RENAME TO ${e}`)}async hasTable(t){let e=g(this._connection);try{return await e.query(`SELECT 1 FROM ${t} LIMIT 1`),!0}catch{return!1}}}class M{table;columns=[];indices=[];constructor(t){this.table=t}id(t="id"){return this.columns.push(`${t} INTEGER PRIMARY KEY AUTOINCREMENT`),this}string(t,e=255){return this.columns.push(`${t} VARCHAR(${e})`),this}text(t){return this.columns.push(`${t} TEXT`),this}integer(t){return this.columns.push(`${t} INTEGER`),this}boolean(t){return this.columns.push(`${t} BOOLEAN DEFAULT 0`),this}datetime(t){return this.columns.push(`${t} DATETIME`),this}timestamps(){return this.columns.push("created_at DATETIME DEFAULT CURRENT_TIMESTAMP"),this.columns.push("updated_at DATETIME DEFAULT CURRENT_TIMESTAMP"),this}softDeletes(){return this.columns.push("deleted_at DATETIME"),this}json(t){return this.columns.push(`${t} TEXT`),this}foreignId(t){return this.columns.push(`${t} INTEGER`),this}index(t){let e=Array.isArray(t)?t:[t],r=`idx_${this.table}_${e.join("_")}`;return this.indices.push(`CREATE INDEX ${r} ON ${this.table} (${e.join(", ")})`),this}unique(t){let e=Array.isArray(t)?t:[t],r=`uniq_${this.table}_${e.join("_")}`;return this.indices.push(`CREATE UNIQUE INDEX ${r} ON ${this.table} (${e.join(", ")})`),this}toCreateSQL(){return`CREATE TABLE IF NOT EXISTS ${this.table} (
|
|
2
|
+
var u={default:"sqlite",connections:{},logging:!1,cacheTTL:0,maxCacheSize:1000},k={},C={},f=new Map,P=[];function z(t){u={...u,...t}}function V(){return{...u}}function G(){u={default:"sqlite",connections:{},logging:!1,cacheTTL:0,maxCacheSize:1000};for(let t of Object.keys(k))delete k[t];f.clear(),P.length=0}function X(t,e){k[t]=e}function g(t){let e=t||u.default;if(k[e])return k[e];let r=u.connections[e];if(!r)throw Error(`Database connection "${e}" not configured`);let s=N(r);return k[e]=s,s}function N(t){switch(t.driver){case"sqlite":return D(t);case"postgres":return S(t);case"mysql":return L(t);default:throw Error(`Unsupported database driver: ${t.driver}`)}}function D(t){let e=null,r=!1;return{async connect(){if(r)return;let{Database:s}=await import("bun:sqlite");e=new s(t.database,{create:!0,readwrite:!0}),r=!0},async disconnect(){if(e)e.close(),e=null,r=!1},async query(s,n=[]){if(!r)await this.connect();let i=performance.now();try{let o=e.prepare(s).all(...n);if(u.logging)y(s,n,performance.now()-i);return o}catch(a){throw new p(`Query failed: ${a}`,s,n)}},async insert(s,n=[]){if(!r)await this.connect();let i=performance.now();try{let o=e.prepare(s).run(...n);if(u.logging)y(s,n,performance.now()-i);return o.lastInsertRowid}catch(a){throw new p(`Insert failed: ${a}`,s,n)}},async execute(s,n=[]){if(!r)await this.connect();let i=performance.now();try{let o=e.prepare(s).run(...n);if(u.logging)y(s,n,performance.now()-i);return o.changes}catch(a){throw new p(`Execute failed: ${a}`,s,n)}},async beginTransaction(){if(!r)await this.connect();e.run("BEGIN TRANSACTION")},async commit(){e.run("COMMIT")},async rollback(){e.run("ROLLBACK")},isConnected(){return r}}}function S(t){let e=!1,r=null;return{async connect(){if(e)return;try{let{Client:s}=await import("pg");r=new s({host:t.host||"localhost",port:t.port||5432,database:t.database,user:t.username,password:t.password,ssl:t.ssl}),await r.connect(),e=!0}catch(s){throw Error(`PostgreSQL connection failed. Install 'pg' package: ${s}`)}},async disconnect(){if(r)await r.end(),r=null,e=!1},async query(s,n=[]){if(!e)await this.connect();let i=performance.now();try{let a=await r.query(s,n);if(u.logging)y(s,n,performance.now()-i);return a.rows}catch(a){throw new p(`Query failed: ${a}`,s,n)}},async insert(s,n=[]){if(!e)await this.connect();let i=performance.now();try{let a=await r.query(`${s} RETURNING id`,n);if(u.logging)y(s,n,performance.now()-i);return a.rows[0]?.id}catch(a){throw new p(`Insert failed: ${a}`,s,n)}},async execute(s,n=[]){if(!e)await this.connect();let i=performance.now();try{let a=await r.query(s,n);if(u.logging)y(s,n,performance.now()-i);return a.rowCount||0}catch(a){throw new p(`Execute failed: ${a}`,s,n)}},async beginTransaction(){if(!e)await this.connect();await r.query("BEGIN")},async commit(){await r.query("COMMIT")},async rollback(){await r.query("ROLLBACK")},isConnected(){return e}}}function L(t){let e=!1,r=null;return{async connect(){if(e)return;try{let s=await import("mysql2/promise");r=s.createPool({host:t.host||"localhost",port:t.port||3306,database:t.database,user:t.username,password:t.password,waitForConnections:!0,connectionLimit:t.poolSize||10,queueLimit:0}),e=!0}catch(s){throw Error(`MySQL connection failed. Install 'mysql2' package: ${s}`)}},async disconnect(){if(r)await r.end(),r=null,e=!1},async query(s,n=[]){if(!e)await this.connect();let i=performance.now();try{let[a]=await r.execute(s,n);if(u.logging)y(s,n,performance.now()-i);return a}catch(a){throw new p(`Query failed: ${a}`,s,n)}},async insert(s,n=[]){if(!e)await this.connect();let i=performance.now();try{let[a]=await r.execute(s,n);if(u.logging)y(s,n,performance.now()-i);return a.insertId}catch(a){throw new p(`Insert failed: ${a}`,s,n)}},async execute(s,n=[]){if(!e)await this.connect();let i=performance.now();try{let[a]=await r.execute(s,n);if(u.logging)y(s,n,performance.now()-i);return a.affectedRows||0}catch(a){throw new p(`Execute failed: ${a}`,s,n)}},async beginTransaction(){if(!e)await this.connect();let s=await r.getConnection();return await s.beginTransaction(),s},async commit(){await r.execute("COMMIT")},async rollback(){await r.execute("ROLLBACK")},isConnected(){return e}}}class x{_table="";_columns=["*"];_wheres=[];_orders=[];_joins=[];_groupBy=[];_having=[];_limit;_offset;_distinct=!1;_connection;_bindings=[];_modelDefinition;constructor(t){if(t)this._table=t}table(t){return this._table=t,this}from(t){return this.table(t)}connection(t){return this._connection=t,this}select(...t){return this._columns=t.length>0?t:["*"],this}addSelect(...t){if(this._columns[0]==="*")this._columns=t;else this._columns.push(...t);return this}distinct(){return this._distinct=!0,this}where(t,e,r){let s="=",n=e;if(r!==void 0)s=e,n=r;return this._wheres.push({column:t,operator:s,value:n,boolean:"and"}),this}orWhere(t,e,r){let s="=",n=e;if(r!==void 0)s=e,n=r;return this._wheres.push({column:t,operator:s,value:n,boolean:"or"}),this}whereIn(t,e){return this._wheres.push({column:t,operator:"in",value:e,boolean:"and"}),this}whereNotIn(t,e){return this._wheres.push({column:t,operator:"not in",value:e,boolean:"and"}),this}whereNull(t){return this._wheres.push({column:t,operator:"is null",value:null,boolean:"and"}),this}whereNotNull(t){return this._wheres.push({column:t,operator:"is not null",value:null,boolean:"and"}),this}whereBetween(t,e,r){return this._wheres.push({column:t,operator:"between",value:[e,r],boolean:"and"}),this}whereLike(t,e){return this._wheres.push({column:t,operator:"like",value:e,boolean:"and"}),this}join(t,e,r,s){return this._joins.push({type:"inner",table:t,first:e,operator:r,second:s}),this}leftJoin(t,e,r,s){return this._joins.push({type:"left",table:t,first:e,operator:r,second:s}),this}rightJoin(t,e,r,s){return this._joins.push({type:"right",table:t,first:e,operator:r,second:s}),this}orderBy(t,e="asc"){return this._orders.push({column:t,direction:e}),this}orderByDesc(t){return this.orderBy(t,"desc")}groupBy(...t){return this._groupBy.push(...t),this}having(t,e,r){return this._having.push({column:t,operator:e,value:r,boolean:"and"}),this}limit(t){return this._limit=t,this}take(t){return this.limit(t)}offset(t){return this._offset=t,this}skip(t){return this.offset(t)}forPage(t,e=15){return this.offset((t-1)*e).limit(e)}async get(){let{sql:t,bindings:e}=this.toSql();if(u.cacheTTL&&u.cacheTTL>0){let n=this.getCacheKey(t,e),i=Q(n);if(i!==void 0)return i}let s=await g(this._connection).query(t,e);if(u.cacheTTL&&u.cacheTTL>0){let n=this.getCacheKey(t,e);B(n,s,u.cacheTTL)}return s}async first(){return(await this.limit(1).get())[0]||null}async firstOrFail(){let t=await this.first();if(!t)throw Error("No results found");return t}async find(t,e="id"){return this.where(e,t).first()}async value(t){let e=await this.select(t).first();return e?e[t]:null}async pluck(t){return(await this.select(t).get()).map((r)=>r[t])}async exists(){return(await this.select(_("1")).limit(1).get()).length>0}async doesntExist(){return!await this.exists()}async count(t="*"){let e=await this.select(_(`COUNT(${t}) as count`)).first();return Number(e?.count||0)}async max(t){return(await this.select(_(`MAX(${t}) as max`)).first())?.max}async min(t){return(await this.select(_(`MIN(${t}) as min`)).first())?.min}async sum(t){let e=await this.select(_(`SUM(${t}) as sum`)).first();return Number(e?.sum||0)}async avg(t){return(await this.select(_(`AVG(${t}) as avg`)).first())?.avg}async insert(t){let e=Object.keys(t),r=e.map(()=>"?").join(", "),s=Object.values(t),n=`INSERT INTO ${this._table} (${e.join(", ")}) VALUES (${r})`,i=g(this._connection);return T(this._table),i.insert(n,s)}async insertAll(t){if(t.length===0)return;let e=Object.keys(t[0]),r=t.map(()=>`(${e.map(()=>"?").join(", ")})`).join(", "),s=t.flatMap((a)=>Object.values(a)),n=`INSERT INTO ${this._table} (${e.join(", ")}) VALUES ${r}`,i=g(this._connection);T(this._table),await i.execute(n,s)}async update(t){this._bindings=[];let e=this.buildWhereClause(),r=[...this._bindings],s=Object.keys(t).map((o)=>`${o} = ?`).join(", "),n=[...Object.values(t),...r],i=`UPDATE ${this._table} SET ${s}${e}`,a=g(this._connection);return T(this._table),a.execute(i,n)}async increment(t,e=1){this._bindings=[];let r=this.buildWhereClause(),s=`UPDATE ${this._table} SET ${t} = ${t} + ?${r}`,n=g(this._connection);return T(this._table),n.execute(s,[e,...this._bindings])}async decrement(t,e=1){return this.increment(t,-e)}async delete(){this._bindings=[];let t=this.buildWhereClause(),e=`DELETE FROM ${this._table}${t}`,r=g(this._connection);return T(this._table),r.execute(e,this._bindings)}async truncate(){let t=g(this._connection);T(this._table),await t.execute(`DELETE FROM ${this._table}`)}toSql(){this._bindings=[];let t="SELECT ";if(this._distinct)t+="DISTINCT ";t+=this._columns.map((e)=>{if(typeof e==="object"&&e.__raw)return e.sql;return e}).join(", "),t+=` FROM ${this._table}`;for(let e of this._joins)t+=` ${e.type.toUpperCase()} JOIN ${e.table} ON ${e.first} ${e.operator} ${e.second}`;if(t+=this.buildWhereClause(),this._groupBy.length>0)t+=` GROUP BY ${this._groupBy.join(", ")}`;if(this._having.length>0){let e=this._having.map((r,s)=>{let n=s===0?"":` ${r.boolean.toUpperCase()} `;return this._bindings.push(r.value),`${n}${r.column} ${r.operator} ?`});t+=` HAVING ${e.join("")}`}if(this._orders.length>0)t+=` ORDER BY ${this._orders.map((e)=>`${e.column} ${e.direction.toUpperCase()}`).join(", ")}`;if(this._limit!==void 0)t+=` LIMIT ${this._limit}`;if(this._offset!==void 0)t+=` OFFSET ${this._offset}`;return{sql:t,bindings:this._bindings}}buildWhereClause(){if(this._wheres.length===0)return"";return this._wheres.map((e,r)=>{let s=r===0?" WHERE ":` ${e.boolean.toUpperCase()} `;switch(e.operator){case"in":{let n=e.value,i=n.map(()=>"?").join(", ");return this._bindings.push(...n),`${s}${e.column} IN (${i})`}case"not in":{let n=e.value,i=n.map(()=>"?").join(", ");return this._bindings.push(...n),`${s}${e.column} NOT IN (${i})`}case"between":{let[n,i]=e.value;return this._bindings.push(n,i),`${s}${e.column} BETWEEN ? AND ?`}case"is null":return`${s}${e.column} IS NULL`;case"is not null":return`${s}${e.column} IS NOT NULL`;default:return this._bindings.push(e.value),`${s}${e.column} ${e.operator} ?`}}).join("")}getCacheKey(t,e){return`${this._table}:${t}:${JSON.stringify(e)}`}clone(){let t=new x(this._table);return t._columns=[...this._columns],t._wheres=[...this._wheres],t._orders=[...this._orders],t._joins=[...this._joins],t._groupBy=[...this._groupBy],t._having=[...this._having],t._limit=this._limit,t._offset=this._offset,t._distinct=this._distinct,t._connection=this._connection,t}}function l(t){return new x(t)}function Y(t){return l(t)}function _(t,e=[]){return{__raw:!0,sql:t,bindings:e}}function H(t,e){let r=e.primaryKey||"id",s={name:t,definition:e,async find(n){let i=await l(e.table).where(r,n).first();return i?b(s,i):null},async findOrFail(n){let i=await this.find(n);if(!i)throw Error(`${t} not found with ${r} = ${n}`);return i},async all(){return(await l(e.table).get()).map((i)=>b(s,i))},async create(n){let i={...e.defaults,...n},a=e.fillable?Object.fromEntries(Object.entries(i).filter(([c])=>e.fillable.includes(c))):i;if(e.timestamps!==!1){let c=new Date().toISOString(),h=typeof e.timestamps==="object"?e.timestamps.createdAt||"created_at":"created_at",m=typeof e.timestamps==="object"?e.timestamps.updatedAt||"updated_at":"updated_at";a[h]=c,a[m]=c}let o=await l(e.table).insert(a);return this.findOrFail(o)},async update(n){return l(e.table).update(n)},async destroy(n){let i=Array.isArray(n)?n:[n];return l(e.table).whereIn(r,i).delete()},query(){return l(e.table)},where(n,i,a){return this.query().where(n,i,a)},async first(){let n=await this.query().first();return n?b(s,n):null},async get(){return(await this.query().get()).map((i)=>b(s,i))},async count(){return this.query().count()}};return C[t]=s,s}function v(t){let e=C[t];if(!e)throw Error(`Model "${t}" not defined. Use defineModel() first.`);return e}function Z(t){return t in C}function b(t,e){let{definition:r}=t,s=r.primaryKey||"id",n={...e},i={...e};if(r.casts){for(let[o,c]of Object.entries(r.casts))if(o in i)i[o]=q(i[o],c)}let a={exists:!0,original:n,attributes:i,get(o){return i[o]},set(o,c){i[o]=c},toJSON(){let o={...i};if(r.hidden)for(let c of r.hidden)delete o[c];return o},async save(){let o={};for(let c of Object.keys(i))if(i[c]!==n[c])o[c]=i[c];if(Object.keys(o).length>0){if(r.timestamps!==!1){let c=typeof r.timestamps==="object"?r.timestamps.updatedAt||"updated_at":"updated_at";o[c]=new Date().toISOString()}await l(r.table).where(s,n[s]).update(o),Object.assign(n,o)}},async delete(){if(r.softDeletes){let o=typeof r.softDeletes==="string"?r.softDeletes:"deleted_at";await l(r.table).where(s,n[s]).update({[o]:new Date().toISOString()})}else await l(r.table).where(s,n[s]).delete();a.exists=!1},async refresh(){let o=await l(r.table).where(s,n[s]).first();if(o)Object.assign(n,o),Object.assign(i,o)},isDirty(o){if(o)return i[o]!==n[o];return Object.keys(i).some((c)=>i[c]!==n[c])}};if(r.relationships)for(let[o,c]of Object.entries(r.relationships))Object.defineProperty(a,o,{value:async()=>j(a,c,t),enumerable:!1});return new Proxy(a,{get(o,c){if(c in o)return o[c];return i[c]},set(o,c,h){if(c in o)o[c]=h;else i[c]=h;return!0}})}async function j(t,e,r){let s=v(e.model),n=r.definition.primaryKey||"id";switch(e.type){case"hasOne":{let i=e.foreignKey||`${r.name.toLowerCase()}_id`,a=await l(s.definition.table).where(i,t.get(n)).first();return a?b(s,a):null}case"hasMany":{let i=e.foreignKey||`${r.name.toLowerCase()}_id`;return(await l(s.definition.table).where(i,t.get(n)).get()).map((o)=>b(s,o))}case"belongsTo":{let i=e.foreignKey||`${e.model.toLowerCase()}_id`,a=e.localKey||"id",o=await l(s.definition.table).where(a,t.get(i)).first();return o?b(s,o):null}case"belongsToMany":{let i=e.pivotTable||[r.name,e.model].sort().join("_").toLowerCase(),a=e.pivotForeignKey||`${r.name.toLowerCase()}_id`,o=e.pivotRelatedKey||`${e.model.toLowerCase()}_id`,c=s.definition.primaryKey||"id";return(await l(s.definition.table).join(i,`${s.definition.table}.${c}`,"=",`${i}.${o}`).where(`${i}.${a}`,t.get(n)).get()).map((m)=>b(s,m))}default:return null}}function q(t,e){if(t===null||t===void 0)return t;switch(e){case"string":return String(t);case"number":return Number(t);case"boolean":return Boolean(t);case"date":return new Date(t);case"json":case"array":return typeof t==="string"?JSON.parse(t):t;default:return t}}async function tt(t,e){let r=g(e);await r.beginTransaction();try{let s=await t();return await r.commit(),s}catch(s){throw await r.rollback(),s}}function Q(t){let e=f.get(t);if(!e)return;if(Date.now()-e.timestamp>e.ttl*1000){f.delete(t);return}return e.result}function B(t,e,r){if(f.size>=(u.maxCacheSize||1000)){let s=f.keys().next().value;if(s)f.delete(s)}f.set(t,{result:e,timestamp:Date.now(),ttl:r})}function T(t){for(let e of f.keys())if(e.startsWith(`${t}:`))f.delete(e)}function et(){f.clear()}function nt(){return{size:f.size,keys:[...f.keys()]}}function y(t,e,r){if(P.push({sql:t,bindings:e,duration:r,timestamp:new Date}),P.length>1000)P.shift()}function rt(){return[...P]}function st(){P.length=0}function it(t=!0){u.logging=t}class p extends Error{sql;bindings;constructor(t,e,r){super(t);this.sql=e;this.bindings=r;this.name="DatabaseError"}}async function K(t,e,r,s){let n=/@db\(\s*['"]([^'"]+)['"]\s*\)((?:->\w+\([^)]*\))*)/g,i=t,a=[...t.matchAll(n)];for(let o of a){let[c,h,m]=o;try{let d=await W(h,m),w=`$${h}`;e[w]=d,i=i.replace(c,"")}catch(d){i=i.replace(c,`<!-- DB Error: ${d instanceof Error?d.message:String(d)} -->`)}}return i}async function U(t,e,r,s){let n=/@model\(\s*['"]([^'"]+)['"]\s*\)((?:->\w+\([^)]*\))*)/g,i=t,a=[...t.matchAll(n)];for(let o of a){let[c,h,m]=o;try{let d=v(h),w=await J(d,m),E=`$${h.toLowerCase()}`;e[E]=w,i=i.replace(c,"")}catch(d){i=i.replace(c,`<!-- Model Error: ${d instanceof Error?d.message:String(d)} -->`)}}return i}async function F(t,e,r,s){let n=/@query\(\s*['"]([^'"]+)['"]\s*(?:,\s*(\[[^\]]*\]))?\s*\)\s*as\s+\$(\w+)/g,i=t,a=[...t.matchAll(n)];for(let o of a){let[c,h,m,d]=o;try{let w=m?JSON.parse(m):[],A=await g().query(h,w);e[`$${d}`]=A,i=i.replace(c,"")}catch(w){i=i.replace(c,`<!-- Query Error: ${w instanceof Error?w.message:String(w)} -->`)}}return i}async function W(t,e){let r=l(t),s=/->(\w+)\(([^)]*)\)/g,n=[...e.matchAll(s)],i=r;for(let[,a,o]of n){let c=O(o);if(typeof i[a]==="function"){if(i=i[a](...c),i instanceof Promise){i=await i;break}}}if(i instanceof x)i=await i.get();return i}async function J(t,e){let r=/->(\w+)\(([^)]*)\)/g,s=[...e.matchAll(r)],n=t;for(let[,i,a]of s){let o=O(a);if(typeof n[i]==="function"){if(n=n[i](...o),n instanceof Promise)n=await n}else if(n instanceof x){if(typeof n[i]==="function"){if(n=n[i](...o),n instanceof Promise)n=await n}}}if(n instanceof x)n=await n.get();return n}function O(t){if(!t.trim())return[];let e=[],r="",s=0,n=!1,i="";for(let a=0;a<t.length;a++){let o=t[a];if(!n&&(o==='"'||o==="'"))n=!0,i=o,r+=o;else if(n&&o===i)n=!1,r+=o;else if(!n&&(o==="["||o==="{"||o==="("))s++,r+=o;else if(!n&&(o==="]"||o==="}"||o===")"))s--,r+=o;else if(!n&&s===0&&o===",")e.push(R(r.trim())),r="";else r+=o}if(r.trim())e.push(R(r.trim()));return e}function R(t){if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t==="true")return!0;if(t==="false")return!1;if(t==="null")return null;let e=Number(t);if(!Number.isNaN(e))return e;try{return JSON.parse(t)}catch{return t}}async function ot(t,e,r,s){let n=t;return n=await F(n,e,r,s),n=await U(n,e,r,s),n=await K(n,e,r,s),n}class I{_connection;connection(t){return this._connection=t,this}async create(t,e){let r=new M(t);e(r);let s=r.toCreateSQL();await g(this._connection).execute(s)}async drop(t){await g(this._connection).execute(`DROP TABLE IF EXISTS ${t}`)}async rename(t,e){await g(this._connection).execute(`ALTER TABLE ${t} RENAME TO ${e}`)}async hasTable(t){let e=g(this._connection);try{return await e.query(`SELECT 1 FROM ${t} LIMIT 1`),!0}catch{return!1}}}class M{table;columns=[];indices=[];constructor(t){this.table=t}id(t="id"){return this.columns.push(`${t} INTEGER PRIMARY KEY AUTOINCREMENT`),this}string(t,e=255){return this.columns.push(`${t} VARCHAR(${e})`),this}text(t){return this.columns.push(`${t} TEXT`),this}integer(t){return this.columns.push(`${t} INTEGER`),this}boolean(t){return this.columns.push(`${t} BOOLEAN DEFAULT 0`),this}datetime(t){return this.columns.push(`${t} DATETIME`),this}timestamps(){return this.columns.push("created_at DATETIME DEFAULT CURRENT_TIMESTAMP"),this.columns.push("updated_at DATETIME DEFAULT CURRENT_TIMESTAMP"),this}softDeletes(){return this.columns.push("deleted_at DATETIME"),this}json(t){return this.columns.push(`${t} TEXT`),this}foreignId(t){return this.columns.push(`${t} INTEGER`),this}index(t){let e=Array.isArray(t)?t:[t],r=`idx_${this.table}_${e.join("_")}`;return this.indices.push(`CREATE INDEX ${r} ON ${this.table} (${e.join(", ")})`),this}unique(t){let e=Array.isArray(t)?t:[t],r=`uniq_${this.table}_${e.join("_")}`;return this.indices.push(`CREATE UNIQUE INDEX ${r} ON ${this.table} (${e.join(", ")})`),this}toCreateSQL(){return`CREATE TABLE IF NOT EXISTS ${this.table} (
|
|
3
3
|
${this.columns.join(`,
|
|
4
4
|
`)}
|
|
5
|
-
)`}getIndexSQL(){return this.indices}}function at(){return new I}export{M as Blueprint,
|
|
5
|
+
)`}getIndexSQL(){return this.indices}}function at(){return new I}export{M as Blueprint,p as DatabaseError,x as QueryBuilder,I as SchemaBuilder,et as clearQueryCache,st as clearQueryLog,z as configureDatabase,H as defineModel,it as enableQueryLogging,g as getAdapter,V as getDatabaseConfig,v as getModel,nt as getQueryCacheStats,rt as getQueryLog,Z as hasModel,ot as processDatabaseDirectives,K as processDbDirective,U as processModelDirective,F as processQueryDirective,l as query,_ as raw,X as registerAdapter,G as resetDatabaseConfig,at as schema,Y as table,tt as transaction};
|
|
@@ -239,26 +239,41 @@ export declare interface ImageBackgroundProps extends ImageProps {
|
|
|
239
239
|
// ============================================================================
|
|
240
240
|
// Map Components
|
|
241
241
|
// ============================================================================
|
|
242
|
+
export declare interface MapCoordinate {
|
|
243
|
+
latitude: number
|
|
244
|
+
longitude: number
|
|
245
|
+
}
|
|
246
|
+
export declare interface MapTileOverlay {
|
|
247
|
+
urlTemplate: string
|
|
248
|
+
attribution: string
|
|
249
|
+
}
|
|
250
|
+
export declare interface MapEdgePadding {
|
|
251
|
+
top?: number
|
|
252
|
+
right?: number
|
|
253
|
+
bottom?: number
|
|
254
|
+
left?: number
|
|
255
|
+
}
|
|
242
256
|
export declare interface MapRegion {
|
|
243
|
-
center:
|
|
257
|
+
center: MapCoordinate
|
|
244
258
|
span: { latitudeDelta: number; longitudeDelta: number }
|
|
245
259
|
}
|
|
246
260
|
export declare interface MapProps extends BaseProps {
|
|
247
261
|
region?: MapRegion
|
|
248
262
|
initialRegion?: MapRegion
|
|
249
|
-
tileOverlay?:
|
|
250
|
-
edgePadding?:
|
|
263
|
+
tileOverlay?: MapTileOverlay
|
|
264
|
+
edgePadding?: MapEdgePadding
|
|
251
265
|
fitToBounds?: boolean
|
|
252
266
|
showsUserLocation?: boolean
|
|
253
267
|
scrollEnabled?: boolean
|
|
254
268
|
zoomEnabled?: boolean
|
|
255
269
|
rotateEnabled?: boolean
|
|
270
|
+
pitchEnabled?: boolean
|
|
256
271
|
mapType?: 'standard' | 'satellite' | 'hybrid' | 'terrain'
|
|
257
272
|
showsCompass?: boolean
|
|
258
273
|
showsScale?: boolean
|
|
259
274
|
cameraPitch?: number
|
|
260
275
|
cameraHeading?: number
|
|
261
|
-
onPress?: (event: { nativeEvent:
|
|
276
|
+
onPress?: (event: { nativeEvent: MapCoordinate }) => void
|
|
262
277
|
onRegionChangeComplete?: (event: { nativeEvent: MapRegion & { heading: number, pitch: number } }) => void
|
|
263
278
|
onMarkerPress?: (event: { nativeEvent: { id: string } }) => void
|
|
264
279
|
}
|
|
@@ -271,6 +286,7 @@ export declare interface MapMarkerProps extends BaseProps {
|
|
|
271
286
|
geometry: number[]
|
|
272
287
|
id: string
|
|
273
288
|
title?: string
|
|
289
|
+
pinColor?: string
|
|
274
290
|
bearing?: number
|
|
275
291
|
onPress?: (event: { nativeEvent: { id: string } }) => void
|
|
276
292
|
onMarkerPress?: (event: { nativeEvent: { id: string } }) => void
|
package/dist/native/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
{{-- Map:
|
|
1
|
+
{{-- Map: native MapKit on iOS or the configured Craft native Android provider.
|
|
2
|
+
The compiler preserves typed geometry, camera props and overlay children. --}}
|
|
2
3
|
<script server>
|
|
3
4
|
const classes = $props.class ?? $props.className ?? ''
|
|
4
5
|
</script>
|
|
@@ -77,8 +77,10 @@ const NATIVE_PROP_NAMES = [
|
|
|
77
77
|
"showsUserLocation",
|
|
78
78
|
"zoomEnabled",
|
|
79
79
|
"rotateEnabled",
|
|
80
|
+
"pitchEnabled",
|
|
80
81
|
"mapType",
|
|
81
82
|
"strokeColor",
|
|
83
|
+
"pinColor",
|
|
82
84
|
"showsCompass",
|
|
83
85
|
"showsScale",
|
|
84
86
|
"cameraPitch",
|
|
@@ -117,6 +119,7 @@ export const NATIVE_BOOLEAN_PROPS = new Set([
|
|
|
117
119
|
"showsUserLocation",
|
|
118
120
|
"zoomEnabled",
|
|
119
121
|
"rotateEnabled",
|
|
122
|
+
"pitchEnabled",
|
|
120
123
|
"showsCompass",
|
|
121
124
|
"showsScale",
|
|
122
125
|
"pictureInPicture"
|
|
@@ -17,8 +17,10 @@ function capabilityFlags(capabilities) {
|
|
|
17
17
|
localDatabase: capabilities.has("database"),
|
|
18
18
|
lifecycle: capabilities.has("lifecycle"),
|
|
19
19
|
geolocation: capabilities.has("geolocation"),
|
|
20
|
+
locationRecordingOwnership: capabilities.has("locationRecordingOwnership"),
|
|
20
21
|
music: capabilities.has("music"),
|
|
21
22
|
heartRate: capabilities.has("heartRate"),
|
|
23
|
+
heartRateRecordingOwnership: capabilities.has("heartRateRecordingOwnership"),
|
|
22
24
|
bluetooth: capabilities.has("bluetooth"),
|
|
23
25
|
scheduledWorkouts: capabilities.has("scheduledWorkouts"),
|
|
24
26
|
liveActivities: capabilities.has("liveActivities"),
|
|
@@ -59,7 +61,16 @@ function platformUserAgent(platform) {
|
|
|
59
61
|
return "Craft";
|
|
60
62
|
}
|
|
61
63
|
export function installCraftBridge(protocol, nativeBridge, target = globalThis, options = {}) {
|
|
62
|
-
const craft = target.craft = target.craft || {}, capabilities = new Set(nativeBridge.capabilities || []), request = (module, method, args) => protocol.callNativeAPI(module, method, ...args), ask = (module, method, args) => protocol.callPersonFacingAPI(module, method, ...args)
|
|
64
|
+
const craft = target.craft = target.craft || {}, capabilities = new Set(nativeBridge.capabilities || []), request = (module, method, args) => protocol.callNativeAPI(module, method, ...args), ask = (module, method, args) => protocol.callPersonFacingAPI(module, method, ...args), recordingRequest = (module, method, options) => {
|
|
65
|
+
if (options && Object.prototype.hasOwnProperty.call(options, "expectedId")) {
|
|
66
|
+
if (typeof options.expectedId !== "string" || !options.expectedId.trim())
|
|
67
|
+
return Promise.reject(Object.assign(Error("expectedId must be a nonempty recording ID"), { code: "INVALID_ARGUMENT" }));
|
|
68
|
+
const flag = module === "Location" ? "locationRecordingOwnership" : "heartRateRecordingOwnership";
|
|
69
|
+
if (!capabilities.has(flag))
|
|
70
|
+
return Promise.reject(Object.assign(Error("This app build cannot enforce recording ownership"), { code: "RECORDING_OWNERSHIP_UNSUPPORTED" }));
|
|
71
|
+
}
|
|
72
|
+
return request(module, method, options === void 0 ? [] : [options]);
|
|
73
|
+
};
|
|
63
74
|
let appState = nativeBridge.initialAppState || "active", initialDeepLinkClaimed = !1;
|
|
64
75
|
const appStateHandlers = new Set, deepLinkHandlers = new Set, navButtonHandlers = new Set, navButtonPresses = {
|
|
65
76
|
leftButtons: new Map,
|
|
@@ -300,11 +311,12 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
|
|
|
300
311
|
unwatched();
|
|
301
312
|
},
|
|
302
313
|
startRecording: (options = {}) => ask("Location", "startRecording", [options]),
|
|
303
|
-
pauseRecording: () =>
|
|
304
|
-
resumeRecording: () =>
|
|
305
|
-
stopRecording: () =>
|
|
306
|
-
getRecordingState: () =>
|
|
307
|
-
|
|
314
|
+
pauseRecording: (options) => recordingRequest("Location", "pauseRecording", options),
|
|
315
|
+
resumeRecording: (options) => recordingRequest("Location", "resumeRecording", options),
|
|
316
|
+
stopRecording: (options) => recordingRequest("Location", "stopRecording", options),
|
|
317
|
+
getRecordingState: (options) => recordingRequest("Location", "getRecordingState", options),
|
|
318
|
+
acknowledgeRecording: (options) => recordingRequest("Location", "acknowledgeRecording", options),
|
|
319
|
+
readRecording: (options) => recordingRequest("Location", "readRecording", options)
|
|
308
320
|
};
|
|
309
321
|
target.addEventListener?.("craftLocationUpdate", (event) => {
|
|
310
322
|
watchers.forEach((callback) => callback(event?.detail));
|
|
@@ -353,11 +365,12 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
|
|
|
353
365
|
reconnect: () => strap("reconnect"),
|
|
354
366
|
disconnect: (options = {}) => strap("disconnect", { forget: !!options.forget }),
|
|
355
367
|
startRecording: () => strap("startRecording"),
|
|
356
|
-
pauseRecording: () =>
|
|
357
|
-
resumeRecording: () =>
|
|
358
|
-
stopRecording: () =>
|
|
359
|
-
getRecordingState: () =>
|
|
360
|
-
|
|
368
|
+
pauseRecording: (options) => recordingRequest("HeartRate", "pauseRecording", options),
|
|
369
|
+
resumeRecording: (options) => recordingRequest("HeartRate", "resumeRecording", options),
|
|
370
|
+
stopRecording: (options) => recordingRequest("HeartRate", "stopRecording", options),
|
|
371
|
+
getRecordingState: (options) => recordingRequest("HeartRate", "getRecordingState", options),
|
|
372
|
+
acknowledgeRecording: (options) => recordingRequest("HeartRate", "acknowledgeRecording", options),
|
|
373
|
+
readRecording: (options = {}) => recordingRequest("HeartRate", "readRecording", options)
|
|
361
374
|
};
|
|
362
375
|
}
|
|
363
376
|
if (capabilities.has("scheduledWorkouts")) {
|
|
@@ -204,11 +204,12 @@ export declare interface NativeCraft {
|
|
|
204
204
|
watchPosition: (callback: (location: NativeLocation) => unknown, options?: Record<string, unknown>) => number
|
|
205
205
|
clearWatch: (id?: number) => void
|
|
206
206
|
startRecording: (options?: Record<string, unknown>) => Promise<NativeLocationRecordingState>
|
|
207
|
-
pauseRecording: () => Promise<NativeLocationRecordingState>
|
|
208
|
-
resumeRecording: () => Promise<NativeLocationRecordingState>
|
|
209
|
-
stopRecording: () => Promise<NativeLocationRecordingState & { locations: NativeLocation[] }>
|
|
210
|
-
|
|
211
|
-
|
|
207
|
+
pauseRecording: (options?: { expectedId: string }) => Promise<NativeLocationRecordingState>
|
|
208
|
+
resumeRecording: (options?: { expectedId: string }) => Promise<NativeLocationRecordingState>
|
|
209
|
+
stopRecording: (options?: { expectedId: string }) => Promise<NativeLocationRecordingState & { locations: NativeLocation[] }>
|
|
210
|
+
acknowledgeRecording: (options: { expectedId: string }) => Promise<boolean>
|
|
211
|
+
getRecordingState: (options?: { expectedId: string }) => Promise<NativeLocationRecordingState & { sampleCount: number }>
|
|
212
|
+
readRecording: (options?: { expectedId: string }) => Promise<NativeLocation[]>
|
|
212
213
|
}
|
|
213
214
|
setKeepAwake?: (enabled: boolean) => Promise<boolean>
|
|
214
215
|
getBrightness?: () => Promise<number>
|
package/dist/pwa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
3
|
-
Icon generation requires the sharp package for image processing.`),e.success=!1,e}let g=await c.default(o).metadata();if(g.width&&g.width<512)e.warnings.push(`Source icon is ${g.width}x${g.height}. Recommend using at least 512x512 for best quality.`);for(let i of s){let d=u.join(a,`icon-${i}x${i}.png`);if(await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d),l){let x=u.join(a,`icon-${i}x${i}.webp`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(x),e.generatedFiles.push(x)}}if(p){for(let d of S){let x=u.join(a,`apple-touch-icon-${d}x${d}.png`);await c.default(o).resize(d,d,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(x),e.generatedFiles.push(x)}let i=u.join(a,"apple-touch-icon.png");await c.default(o).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(i),e.generatedFiles.push(i)}for(let i of P){let d=u.join(a,`favicon-${i}x${i}.png`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d)}let f=512,y=u.join(a,`icon-maskable-${f}x${f}.png`),m=Math.floor(f*0.1),k=f-m*2;await c.default(o).resize(k,k,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:m,bottom:m,left:m,right:m,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(y),e.generatedFiles.push(y)}catch(c){let h=c instanceof Error?c.message:String(c);e.errors.push(`Icon generation failed: ${h}`),e.success=!1}return e}function N(n){let t=n.sizes||v,e=n.outputDir?`/${n.outputDir}`:"/pwa-icons",r=n.generateWebP??!0,o=n.generateAppleIcons??!0,a=[];for(let s of t)if(a.push(`${e}/icon-${s}x${s}.png`),r)a.push(`${e}/icon-${s}x${s}.webp`);if(o){a.push(`${e}/apple-touch-icon.png`);for(let s of S)a.push(`${e}/apple-touch-icon-${s}x${s}.png`)}for(let s of P)a.push(`${e}/favicon-${s}x${s}.png`);return a.push(`${e}/icon-maskable-512x512.png`),a}async function I(){try{return await import("sharp"),!0}catch{return!1}}function A(n,t,e,r){let o=[],a=r.join(" ");for(let s of n)if(o.push({src:`${t}/icon-${s}x${s}.png`,sizes:`${s}x${s}`,type:"image/png",purpose:a}),e)o.push({src:`${t}/icon-${s}x${s}.webp`,sizes:`${s}x${s}`,type:"image/webp",purpose:a});return o}function C(n){return n.map((t)=>({name:t.name,short_name:t.shortName,description:t.description,url:t.url,icons:t.icons?.map((e)=>({src:e.src,sizes:e.sizes,type:e.type}))}))}function T(n){let t=n.pwa?.shareTarget;if(!t?.enabled)return;let e={action:t.action||"/share",method:t.method||"POST",enctype:t.enctype||"multipart/form-data",params:{title:t.params?.title||"title",text:t.params?.text||"text",url:t.params?.url||"url"}};if(t.acceptFiles&&t.acceptFiles.length>0)e.params.files=t.acceptFiles.map((r)=>({name:r.name,accept:r.accept}));return e}function H(n){let t=n.pwa?.fileHandlers;if(!t?.enabled||!t.accept)return;let e=[{action:t.action||"/",accept:t.accept,launch_type:t.launchType||"single-client"}];if(t.icons)e[0].icons=t.icons.map((r)=>({src:r.src,sizes:r.sizes,type:r.type}));return e}function W(n){let t=n.pwa?.protocolHandlers;if(!t||t.length===0)return;return t.map((e)=>({protocol:e.protocol,url:e.url}))}function j(n){let t=n.pwa;if(!t?.enabled||!t.manifest)return null;let{manifest:e,icons:r}=t,o=r?.sizes||[72,96,128,144,152,192,384,512],a=r?.outputDir?`/${r.outputDir}`:"/pwa-icons",s=r?.generateWebP??!0,l=r?.purpose||["any","maskable"],p={name:e.name,short_name:e.shortName||e.name,description:e.description,start_url:e.startUrl||"/",display:e.display||"standalone",display_override:e.displayOverride,orientation:e.orientation,theme_color:e.themeColor,background_color:e.backgroundColor,scope:e.scope||"/",lang:e.lang,dir:e.dir,id:e.id,categories:e.categories,icons:A(o,a,s,l)};if(e.shortcuts&&e.shortcuts.length>0)p.shortcuts=C(e.shortcuts);if(e.screenshots&&e.screenshots.length>0)p.screenshots=e.screenshots.map((f)=>({src:f.src,sizes:f.sizes,type:f.type,label:f.label,form_factor:f.platform}));let c=T(n);if(c)p.share_target=c;let h=H(n);if(h)p.file_handlers=h;let g=W(n);if(g)p.protocol_handlers=g;if(e.launchHandler)p.launch_handler={client_mode:e.launchHandler};if(e.handleLinks)p.handle_links=e.handleLinks;if(e.edgeSidePanel?.enabled)p.edge_side_panel={preferred_width:e.edgeSidePanel.preferredWidth};return p}function _(n){let t=j(n);if(!t)return"";let e=JSON.parse(JSON.stringify(t));return JSON.stringify(e,null,2)}function q(n,t){return{...t,...n,shortcuts:n.shortcuts||t.shortcuts,screenshots:n.screenshots||t.screenshots,categories:n.categories||t.categories}}function D(n){let t=[],e=n.pwa;if(!e?.enabled)return t;let r=e.manifest;if(!r)return t.push("PWA manifest configuration is missing"),t;if(!r.name)t.push("Manifest name is required");let o=["fullscreen","standalone","minimal-ui","browser"];if(r.display&&!o.includes(r.display))t.push(`Invalid display mode: ${r.display}. Must be one of: ${o.join(", ")}`);let a=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(r.orientation&&!a.includes(r.orientation))t.push(`Invalid orientation: ${r.orientation}`);let s=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(r.themeColor&&!s.test(r.themeColor))t.push(`Invalid theme color: ${r.themeColor}. Must be a valid hex color.`);if(r.backgroundColor&&!s.test(r.backgroundColor))t.push(`Invalid background color: ${r.backgroundColor}. Must be a valid hex color.`);if(e.shareTarget?.enabled){if(!e.shareTarget.action)t.push("Share target action URL is required")}if(e.fileHandlers?.enabled){if(!e.fileHandlers.accept||Object.keys(e.fileHandlers.accept).length===0)t.push("File handlers must specify accepted MIME types")}if(e.protocolHandlers)for(let l of e.protocolHandlers){if(!l.protocol)t.push("Protocol handler missing protocol");if(!l.url||!l.url.includes("%s"))t.push(`Protocol handler URL must contain %s placeholder: ${l.protocol}`)}return t}import z from"path";async function F(n){let t=n.pwa?.offline;if(!t?.enabled)return"";if(t.page){let e=z.isAbsolute(t.page)?t.page:z.resolve(process.cwd(),t.page);if(await Bun.file(e).exists())try{let{processDirectives:r}=await import("./chunk-
|
|
2
|
+
import{Fn,Le,Uo,Ya}from"./chunk-9ya4tdpz.js";import{Bn,Gr,Ka,Xa,Ja}from"./chunk-g8tx0yf8.js";import{Fo,zo,Ho,qa,Ga}from"./chunk-7wyyjdks.js";import{ae,yt,Kr}from"./chunk-8cs45k3f.js";import{Qc,el,tl,nl,yr,xu}from"./chunk-9tcvkbb5.js";import B from"fs";import w from"path";import O from"fs";import u from"path";var v=[72,96,128,144,152,192,384,512],S=[120,152,167,180],P=[16,32];async function M(n,t){let e={success:!0,generatedFiles:[],errors:[],warnings:[]},r=n.pwa?.icons;if(!r?.src)return e.errors.push("No source icon specified in pwa.icons.src"),e.success=!1,e;let o=u.isAbsolute(r.src)?r.src:u.resolve(process.cwd(),r.src);if(!await Bun.file(o).exists())return e.errors.push(`Source icon not found: ${o}`),e.success=!1,e;let a=u.resolve(t,r.outputDir||"pwa-icons");try{O.mkdirSync(a,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${a}`),e.success=!1,e}let s=r.sizes||v,l=r.generateWebP??!0,p=r.generateAppleIcons??!0;try{let c;try{c=await import("sharp")}catch{return e.errors.push(`sharp is not installed. Install it with: bun add sharp
|
|
3
|
+
Icon generation requires the sharp package for image processing.`),e.success=!1,e}let g=await c.default(o).metadata();if(g.width&&g.width<512)e.warnings.push(`Source icon is ${g.width}x${g.height}. Recommend using at least 512x512 for best quality.`);for(let i of s){let d=u.join(a,`icon-${i}x${i}.png`);if(await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d),l){let x=u.join(a,`icon-${i}x${i}.webp`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(x),e.generatedFiles.push(x)}}if(p){for(let d of S){let x=u.join(a,`apple-touch-icon-${d}x${d}.png`);await c.default(o).resize(d,d,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(x),e.generatedFiles.push(x)}let i=u.join(a,"apple-touch-icon.png");await c.default(o).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(i),e.generatedFiles.push(i)}for(let i of P){let d=u.join(a,`favicon-${i}x${i}.png`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d)}let f=512,y=u.join(a,`icon-maskable-${f}x${f}.png`),m=Math.floor(f*0.1),k=f-m*2;await c.default(o).resize(k,k,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:m,bottom:m,left:m,right:m,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(y),e.generatedFiles.push(y)}catch(c){let h=c instanceof Error?c.message:String(c);e.errors.push(`Icon generation failed: ${h}`),e.success=!1}return e}function N(n){let t=n.sizes||v,e=n.outputDir?`/${n.outputDir}`:"/pwa-icons",r=n.generateWebP??!0,o=n.generateAppleIcons??!0,a=[];for(let s of t)if(a.push(`${e}/icon-${s}x${s}.png`),r)a.push(`${e}/icon-${s}x${s}.webp`);if(o){a.push(`${e}/apple-touch-icon.png`);for(let s of S)a.push(`${e}/apple-touch-icon-${s}x${s}.png`)}for(let s of P)a.push(`${e}/favicon-${s}x${s}.png`);return a.push(`${e}/icon-maskable-512x512.png`),a}async function I(){try{return await import("sharp"),!0}catch{return!1}}function A(n,t,e,r){let o=[],a=r.join(" ");for(let s of n)if(o.push({src:`${t}/icon-${s}x${s}.png`,sizes:`${s}x${s}`,type:"image/png",purpose:a}),e)o.push({src:`${t}/icon-${s}x${s}.webp`,sizes:`${s}x${s}`,type:"image/webp",purpose:a});return o}function C(n){return n.map((t)=>({name:t.name,short_name:t.shortName,description:t.description,url:t.url,icons:t.icons?.map((e)=>({src:e.src,sizes:e.sizes,type:e.type}))}))}function T(n){let t=n.pwa?.shareTarget;if(!t?.enabled)return;let e={action:t.action||"/share",method:t.method||"POST",enctype:t.enctype||"multipart/form-data",params:{title:t.params?.title||"title",text:t.params?.text||"text",url:t.params?.url||"url"}};if(t.acceptFiles&&t.acceptFiles.length>0)e.params.files=t.acceptFiles.map((r)=>({name:r.name,accept:r.accept}));return e}function H(n){let t=n.pwa?.fileHandlers;if(!t?.enabled||!t.accept)return;let e=[{action:t.action||"/",accept:t.accept,launch_type:t.launchType||"single-client"}];if(t.icons)e[0].icons=t.icons.map((r)=>({src:r.src,sizes:r.sizes,type:r.type}));return e}function W(n){let t=n.pwa?.protocolHandlers;if(!t||t.length===0)return;return t.map((e)=>({protocol:e.protocol,url:e.url}))}function j(n){let t=n.pwa;if(!t?.enabled||!t.manifest)return null;let{manifest:e,icons:r}=t,o=r?.sizes||[72,96,128,144,152,192,384,512],a=r?.outputDir?`/${r.outputDir}`:"/pwa-icons",s=r?.generateWebP??!0,l=r?.purpose||["any","maskable"],p={name:e.name,short_name:e.shortName||e.name,description:e.description,start_url:e.startUrl||"/",display:e.display||"standalone",display_override:e.displayOverride,orientation:e.orientation,theme_color:e.themeColor,background_color:e.backgroundColor,scope:e.scope||"/",lang:e.lang,dir:e.dir,id:e.id,categories:e.categories,icons:A(o,a,s,l)};if(e.shortcuts&&e.shortcuts.length>0)p.shortcuts=C(e.shortcuts);if(e.screenshots&&e.screenshots.length>0)p.screenshots=e.screenshots.map((f)=>({src:f.src,sizes:f.sizes,type:f.type,label:f.label,form_factor:f.platform}));let c=T(n);if(c)p.share_target=c;let h=H(n);if(h)p.file_handlers=h;let g=W(n);if(g)p.protocol_handlers=g;if(e.launchHandler)p.launch_handler={client_mode:e.launchHandler};if(e.handleLinks)p.handle_links=e.handleLinks;if(e.edgeSidePanel?.enabled)p.edge_side_panel={preferred_width:e.edgeSidePanel.preferredWidth};return p}function _(n){let t=j(n);if(!t)return"";let e=JSON.parse(JSON.stringify(t));return JSON.stringify(e,null,2)}function q(n,t){return{...t,...n,shortcuts:n.shortcuts||t.shortcuts,screenshots:n.screenshots||t.screenshots,categories:n.categories||t.categories}}function D(n){let t=[],e=n.pwa;if(!e?.enabled)return t;let r=e.manifest;if(!r)return t.push("PWA manifest configuration is missing"),t;if(!r.name)t.push("Manifest name is required");let o=["fullscreen","standalone","minimal-ui","browser"];if(r.display&&!o.includes(r.display))t.push(`Invalid display mode: ${r.display}. Must be one of: ${o.join(", ")}`);let a=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(r.orientation&&!a.includes(r.orientation))t.push(`Invalid orientation: ${r.orientation}`);let s=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(r.themeColor&&!s.test(r.themeColor))t.push(`Invalid theme color: ${r.themeColor}. Must be a valid hex color.`);if(r.backgroundColor&&!s.test(r.backgroundColor))t.push(`Invalid background color: ${r.backgroundColor}. Must be a valid hex color.`);if(e.shareTarget?.enabled){if(!e.shareTarget.action)t.push("Share target action URL is required")}if(e.fileHandlers?.enabled){if(!e.fileHandlers.accept||Object.keys(e.fileHandlers.accept).length===0)t.push("File handlers must specify accepted MIME types")}if(e.protocolHandlers)for(let l of e.protocolHandlers){if(!l.protocol)t.push("Protocol handler missing protocol");if(!l.url||!l.url.includes("%s"))t.push(`Protocol handler URL must contain %s placeholder: ${l.protocol}`)}return t}import z from"path";async function F(n){let t=n.pwa?.offline;if(!t?.enabled)return"";if(t.page){let e=z.isAbsolute(t.page)?t.page:z.resolve(process.cwd(),t.page);if(await Bun.file(e).exists())try{let{processDirectives:r}=await import("./chunk-7d2vyre0.js"),o=await Bun.file(e).text();return await r(o,{},e,n,new Set)}catch(r){console.warn(`[PWA] Failed to process custom offline page: ${r}`)}else console.warn(`[PWA] Custom offline page not found: ${e}`)}return E(n)}function E(n){let t=n.pwa?.offline,e=n.pwa?.manifest,r=t?.fallbackTitle||"You are offline",o=t?.fallbackMessage||"Please check your internet connection and try again.",a=e?.themeColor||"#4f46e5",s=e?.shortName||e?.name||"App";return`<!DOCTYPE html>
|
|
4
4
|
<html lang="en">
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="UTF-8">
|
|
@@ -233,4 +233,4 @@ Icon generation requires the sharp package for image processing.`),e.success=!1,
|
|
|
233
233
|
}, 5000);
|
|
234
234
|
</script>
|
|
235
235
|
</body>
|
|
236
|
-
</html>`}function b(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}async function re(n,t){let e={success:!0,files:{icons:[]},errors:[],warnings:[]},r=n.pwa;if(!r?.enabled)return e;try{B.mkdirSync(t,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${t}`),e.success=!1,e}try{let a=_(n);if(a){let s=w.join(t,"manifest.json");await Bun.write(s,a),e.files.manifest=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate manifest.json: ${s}`),e.success=!1}if(r.icons?.src)if(await I()){let s=await M(n,t);if(e.files.icons=s.generatedFiles,e.warnings.push(...s.warnings),!s.success)e.errors.push(...s.errors),e.success=!1}else e.warnings.push("sharp is not installed. Skipping icon generation. Install with: bun add sharp");if(r.offline?.enabled)try{let a=await F(n);if(a){let s=w.join(t,"offline.html");await Bun.write(s,a),e.files.offlinePage=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate offline page: ${s}`),e.success=!1}let o;if(r.precache?.enabled){let a=
|
|
236
|
+
</html>`}function b(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}async function re(n,t){let e={success:!0,files:{icons:[]},errors:[],warnings:[]},r=n.pwa;if(!r?.enabled)return e;try{B.mkdirSync(t,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${t}`),e.success=!1,e}try{let a=_(n);if(a){let s=w.join(t,"manifest.json");await Bun.write(s,a),e.files.manifest=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate manifest.json: ${s}`),e.success=!1}if(r.icons?.src)if(await I()){let s=await M(n,t);if(e.files.icons=s.generatedFiles,e.warnings.push(...s.warnings),!s.success)e.errors.push(...s.errors),e.success=!1}else e.warnings.push("sharp is not installed. Skipping icon generation. Install with: bun add sharp");if(r.offline?.enabled)try{let a=await F(n);if(a){let s=w.join(t,"offline.html");await Bun.write(s,a),e.files.offlinePage=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate offline page: ${s}`),e.success=!1}let o;if(r.precache?.enabled){let a=ae(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=Fn(n,t);if(a){let s=Le(n),l=w.join(t,s);await Bun.write(l,a),e.files.serviceWorker=l}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate service worker: ${s}`),e.success=!1}return e}function se(n,t){return Gr(n,t)}function oe(n){return n.pwa?.enabled===!0}export{S as APPLE_TOUCH_ICON_SIZES,v as DEFAULT_ICON_SIZES,P as FAVICON_SIZES,zo as auditBuildOutput,Fo as auditConfig,re as buildPwaAssets,Ho as calculateAuditResult,Ga as formatAuditResult,Kr as formatSize,j as generateManifest,_ as generateManifestJson,Xa as generateManifestLink,F as generateOfflinePage,ae as generatePrecacheManifest,yt as generatePrecacheManifestJs,M as generatePwaIcons,Bn as generatePwaTags,Fn as generateServiceWorker,Ya as generateServiceWorkerAuto,Ka as generateSwRegistrationScript,Ja as generateThemeColorMeta,N as getExpectedIconPaths,Le as getServiceWorkerFileName,Gr as injectPwaTags,oe as isPwaEnabled,I as isSharpAvailable,Uo as isWorkboxEnabled,q as mergeManifestConfig,se as processPwaHtml,yr as pwaDirectives,Qc as pwaInstallDirective,tl as pwaOfflineDirective,nl as pwaPushDirective,el as pwaUpdateDirective,xu as registerPwaDirectives,qa as runPwaAudit,D as validateManifest};
|
package/dist/ssg.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-
|
|
3
|
-
`)}class
|
|
2
|
+
import"./chunk-ffxwsa94.js";import"./chunk-m8qgr307.js";import"./chunk-4zb2ga7p.js";import{rt,st,ot,it,at,ct}from"./chunk-ev3qnr9q.js";import"./chunk-7m0r2qs2.js";import"./chunk-d4ybwtqt.js";import{f,He,N,X,n,o}from"./chunk-xw8kzm6b.js";import"./chunk-1hrj0t0j.js";import{or}from"./chunk-mt8sew7a.js";import"./chunk-ghnkphy4.js";import"./chunk-8txqk9nq.js";import"./chunk-rgage0vm.js";import"./chunk-dmf1jmge.js";import"./chunk-01s01ten.js";import{ce,bt,wt}from"./chunk-mm1vvk49.js";import{Lo,jo,Bo}from"./chunk-z06npyzn.js";import{ht,en,tn}from"./chunk-15g5sc0p.js";import"./chunk-8afnq4qx.js";import{a}from"./chunk-203rr1c8.js";import x from"fs";import g from"path";import{createHash as Dt}from"crypto";function Rt(t){try{return new Bun.Transpiler({loader:"js",minifyWhitespace:!0}).transformSync(t).replace(/\}(var |let |const |function )/g,"};$1").trim()}catch{return t}}var kt=/<script\s+type="stx\/island"\s+data-stx-island="([^"]+)"([^>]*)>([\s\S]*?)<\/script>/g;function Ct(t){return Bun.hash(t).toString(16)}function ut(t,i={}){if(!t.includes('type="stx/island"'))return{html:t,chunks:[]};let s=new Map,r=t.replace(kt,(e,l,w,y)=>{let h=y.trim();if(!h)return e;if(/\bdata-stx-src=/.test(w))return e;if(i.minify)h=Rt(h);let S=Ct(h);if(!s.has(S))s.set(S,h);let P=i.integrity?` data-stx-integrity="sha384-${Dt("sha384").update(h).digest("base64")}"`:"";return`<script type="stx/island" data-stx-island="${l}" data-stx-src="/_stx/islands/${S}.js"${P}${w}></script>`}),c=Array.from(s,([e,l])=>({hash:e,code:l}));return{html:r,chunks:c}}var Et=new Set(["visible","idle"]);function dt(t){if(!t.includes("data-stx-src="))return t;let i=new Map,s=/data-stx-scope="([^"]+)"[^>]*?stx-hydrate="([^"]+)"/g,r;while((r=s.exec(t))!==null)i.set(r[1],r[2]);let c=new Set,e=/data-stx-island="([^"]+)"[^>]*?data-stx-src="([^"]+)"/g,l;while((l=e.exec(t))!==null)if(Et.has(i.get(l[1])||""))c.add(l[2]);let w=t.lastIndexOf("</head>");if(c.size===0||w===-1)return t;let y=Array.from(c).filter((h)=>!t.includes(`rel="prefetch" href="${h}"`)).map((h)=>`<link rel="prefetch" href="${h}" as="script">`).join("");if(!y)return t;return t.slice(0,w)+y+t.slice(w)}var It=["STX_SITE_URL","SITE_URL","URL","VERCEL_URL","CF_PAGES_URL"];function q(t){let i=t.trim();if(!i)return null;let s=/^https?:\/\//i.test(i)?i:`https://${i}`;try{return new URL(s).origin+new URL(s).pathname.replace(/\/$/,"")}catch{return null}}function Bt(t){for(let i of It){let s=t[i];if(!s)continue;let r=q(s);if(r)return{url:r,source:"env",via:i}}return null}function gt(t){if(!t||typeof t!=="object")return null;let i=t,s=i.site?.url??i.url??i.app?.url;return typeof s==="string"?q(s):null}async function jt(t){let{existsSync:i}=await import("fs"),s=await import("path");for(let r of["site.config.ts","site.config.js",".config/site.config.ts"]){let c=s.resolve(t,r);if(!i(c))continue;try{let e=await import(c),l=gt(e.default??e);if(l)return l}catch{}}return null}async function pt(t={}){let i=t.cwd??process.cwd(),s=t.env??process.env;if(t.explicit){let l=q(t.explicit);if(l)return{url:l,source:"option"}}let r=gt(t.stxConfig);if(r)return{url:r,source:"stx.config",via:"site.url"};let c=await jt(i);if(c)return{url:c,source:"site.config",via:"url"};let e=Bt(s);if(e)return e;return{url:"http://localhost",source:"fallback"}}function ft(){return["No site URL configured \u2014 sitemap.xml and robots.txt will point at http://localhost."," Set one in stx.config.ts (site: { url: 'https://example.com' }), in site.config.ts,"," via --domain, or with SITE_URL in the build environment."].join(`
|
|
3
|
+
`)}class mt{cacheDir;cache=new Map;loaded=!1;salt;constructor(t,i=""){this.cacheDir=t,this.salt=i}async load(){if(this.loaded)return;let t=g.join(this.cacheDir,"build-cache.json");if(await Bun.file(t).exists())try{let i=JSON.parse(await Bun.file(t).text());for(let[s,r]of Object.entries(i))this.cache.set(s,r)}catch{}this.loaded=!0}async save(){await x.promises.mkdir(this.cacheDir,{recursive:!0});let t=g.join(this.cacheDir,"build-cache.json"),i={};for(let[s,r]of this.cache)i[s]=r;await Bun.write(t,JSON.stringify(i))}getHash(t,i){let s=x.statSync(t),r=`${this.salt}|${t}:${s.mtimeMs}`;for(let e of i)if(x.existsSync(e)){let l=x.statSync(e);r+=`:${e}:${l.mtimeMs}`}let c=0;for(let e=0;e<r.length;e++){let l=r.charCodeAt(e);c=(c<<5)-c+l,c=c&c}return Math.abs(c).toString(36)}get(t,i){let s=this.cache.get(t);if(!s)return null;let r=this.getHash(i,s.dependencies??[]);if(s.hash!==r)return this.cache.delete(t),null;return s.html}set(t,i,s,r){let c=this.getHash(i,s);this.cache.set(t,{hash:c,html:r,generatedAt:Date.now(),dependencies:s})}}class yt{cacheDir;constructor(t){this.cacheDir=t}getFilePath(t){let i=t.replace(/[^a-zA-Z0-9]/g,"_")+".json";return g.join(this.cacheDir,"isr",i)}async get(t){let i=this.getFilePath(t);if(!await Bun.file(i).exists())return null;try{return JSON.parse(await Bun.file(i).text())}catch{return null}}async set(t,i){let s=this.getFilePath(t);await x.promises.mkdir(g.dirname(s),{recursive:!0}),await Bun.write(s,JSON.stringify(i))}async invalidate(t){let i=this.getFilePath(t);if(await Bun.file(i).exists())await x.promises.unlink(i)}async invalidatePattern(t){let i=g.join(this.cacheDir,"isr");if(!x.existsSync(i))return;let s=await x.promises.readdir(i);for(let r of s){let c=r.replace(/_/g,"/").replace(".json","");if(t.test(c))await x.promises.unlink(g.join(i,r))}}async needsRevalidation(t){let i=await this.get(t);if(!i)return!0;return Date.now()>i.revalidateAfter}}async function Ft(t){try{let s=(await Bun.file(t).text()).match(/<script\s+server\b[^>]*>([\s\S]*?)<\/script>/i);if(!s)return null;let r=s[1];if(!r.includes("getStaticPaths"))return null;let c=r.match(/(?:export\s+)?(?:async\s+)?function\s+getStaticPaths\s*\([^)]*\)\s*\{([\s\S]*?)\n[\t ]*\}/);if(!c)return null;return await Function(`
|
|
4
4
|
return (async function getStaticPaths() {
|
|
5
5
|
${c[1]}
|
|
6
6
|
})()
|
|
@@ -9,9 +9,9 @@ import"./chunk-azb58ven.js";import"./chunk-a5kaw8sc.js";import"./chunk-mtdx75j5.
|
|
|
9
9
|
${e[1]}
|
|
10
10
|
})()
|
|
11
11
|
`)(i)}catch(e){return console.error(`Error executing getStaticProps in ${s}:`,e),null}}function Lt(t){return/(?:^|[^\w$.])(?:export\s+)?(?:async\s+)?function\s+action\s*\(/.test(t)||/(?:^|[^\w$.])(?:export\s+)?(?:const|let|var)\s+action\s*=/.test(t)}async function St(t,i,s={},r,c){let e=await Bun.file(t.filePath).text(),l=await Tt(t.filePath),w=await At(e,i,t.filePath),y={...l||{},...w||{},...s,params:i,$route:{path:t.pattern,params:i}},h=new Set,S=[],P=[],D={...c,...r.partialsDir?{partialsDir:r.partialsDir}:{},...r.componentsDir?{componentsDir:r.componentsDir}:{},debug:!1,cache:!1,autoShell:!0,onIncludeError:(b)=>{S.push(`${g.relative(process.cwd(),b.templatePath)}: ${b.message}
|
|
12
|
-
resolved against partialsDir: ${b.partialsDir}`)},onServerScriptError:(b)=>{P.push(`${g.relative(process.cwd(),b.sourcePath)} (${b.kind}): ${b.message}`)}};if(Lt(e))console.warn(`Warning: ${t.pattern} exports a page action, which cannot run in a static build. Its form will submit to a file. Serve this route with the production server, or point the form's action at a route handler.`);let p=await n(e,y,t.filePath,D,h);for(let b of[t.filePath,...h])for(let B of
|
|
12
|
+
resolved against partialsDir: ${b.partialsDir}`)},onServerScriptError:(b)=>{P.push(`${g.relative(process.cwd(),b.sourcePath)} (${b.kind}): ${b.message}`)}};if(Lt(e))console.warn(`Warning: ${t.pattern} exports a page action, which cannot run in a static build. Its form will submit to a file. Serve this route with the production server, or point the form's action at a route handler.`);let p=await n(e,y,t.filePath,D,h);for(let b of[t.filePath,...h])for(let B of ce(b))h.add(B);if(Object.keys(i).length>0){let b=`<script>if(window.stx)window.stx._rp=${JSON.stringify(i)};else window.__stx_rp=${JSON.stringify(i)};</script>`;if(p.includes("</head>"))p=p.replace("</head>",`${b}
|
|
13
13
|
</head>`);else p=`${b}
|
|
14
|
-
${p}`}if(p=await
|
|
14
|
+
${p}`}if(p=await X(p,{router:r.router}),p=await f(p),r.minify!==!1)return{html:Mt(p),dependencies:Array.from(h),includeFailures:S,serverScriptFailures:P};return{html:p,dependencies:Array.from(h),includeFailures:S,serverScriptFailures:P}}function Mt(t){let i=[],s=0,r=/(<script[^>]*>)([\s\S]*?)(<\/script>)/gi,c;while((c=r.exec(t))!==null){let l=t.slice(s,c.index);i.push(l.replace(/<!--(?!\[if)[\s\S]*?-->/g,"").replace(/\s+/g," ").replace(/>\s+</g,"><"));let w=c[1],y=c[2],h=c[3];y=y.replace(/([^:"\\'`])\/\/(?!\/)(?![*!])([^\n]*)/g,"$1"),i.push(w+y+h),s=c.index+c[0].length}let e=t.slice(s);return i.push(e.replace(/<!--(?!\[if)[\s\S]*?-->/g,"").replace(/\s+/g," ").replace(/>\s+</g,"><")),i.join("").trim()}function Ut(t){let i=0;for(let s=0;s<t.length;s++){let r=t.charCodeAt(s);i=(i<<5)-i+r,i=i&i}return`"${Math.abs(i).toString(36)}"`}function _t(t,i,s,r){if(s?.sitemap===!1)return!0;if(/<meta[^>]+name=["']robots["'][^>]+content=["'][^"']*noindex/i.test(i))return!0;return r.some((c)=>{if(c instanceof RegExp)return c.test(t);return c.endsWith("/")?t===c.slice(0,-1)||t.startsWith(c):t===c})}function Gt(t,i){return`<?xml version="1.0" encoding="UTF-8"?>
|
|
15
15
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
16
16
|
${t.map((r)=>{let c=new URL(r.loc,i).href,e=` <url>
|
|
17
17
|
<loc>${I(c)}</loc>`;if(r.lastmod)e+=`
|
|
@@ -41,16 +41,16 @@ ${t.map((r)=>{let c=new URL(r.loc,i).href,e=` <url>
|
|
|
41
41
|
${s.join(`
|
|
42
42
|
`)}
|
|
43
43
|
</channel>
|
|
44
|
-
</rss>`}async function zt(t={}){let i=Date.now();
|
|
44
|
+
</rss>`}async function zt(t={}){let i=Date.now();wt();let s=await o(process.cwd()),r=s.build||{},c=await pt({explicit:t.domain||r.domain,stxConfig:s});if(c.source==="fallback"&&(t.sitemap??r.sitemap??!0))console.warn(ft());let e={router:t.router??s?.router??{},pagesDir:t.pagesDir||r.pagesDir||"pages",outputDir:t.outputDir||r.outputDir||"dist",baseUrl:t.baseUrl||r.baseUrl||"/",domain:c.url,revalidate:t.revalidate??r.revalidate??!1,sitemap:t.sitemap??r.sitemap??!0,sitemapExclude:t.sitemapExclude||r.sitemapExclude||[],robots:t.robots??r.robots??!0,rss:t.rss??r.rss??!1,concurrency:t.concurrency||r.concurrency||10,cache:t.cache??r.cache??!0,cacheDir:t.cacheDir||r.cacheDir||a(process.cwd(),"ssg-cache"),contentLoaders:t.contentLoaders||[],hooks:t.hooks||{},minify:t.minify??r.minify??!0,generate404:t.generate404??r.generate404??!0,publicDir:t.publicDir||r.publicDir||"public",trailingSlash:t.trailingSlash??r.trailingSlash??!1,cleanOutput:t.cleanOutput??r.cleanOutput??!0,cacheSalt:t.cacheSalt??"",partialsDir:t.partialsDir||s?.partialsDir||"",componentsDir:t.componentsDir||s?.componentsDir||"",failOnIncludeError:t.failOnIncludeError??!0,failOnServerScriptError:t.failOnServerScriptError??!0,chunkIslands:t.chunkIslands===!0,prefetchIslands:t.prefetchIslands===!0,integrityIslands:t.integrityIslands===!0},l={totalPages:0,successCount:0,failedCount:0,cachedCount:0,buildTime:0,pages:[],errors:[]},w=new Set,y=0,h={},S={};await e.hooks.onBuildStart?.();try{if(e.cleanOutput&&x.existsSync(e.outputDir))await x.promises.rm(e.outputDir,{recursive:!0});await x.promises.mkdir(e.outputDir,{recursive:!0});let D=e.cacheSalt;if(!D){let{resolveUserCssConfig:u,fingerprintConfig:m}=await import("./chunk-t5r3s1wj.js");try{D=m(await u(process.cwd()))}catch{}}let{prepareImageDelivery:p}=await import("./chunk-da9avgd9.js"),b=await p(e.publicDir,e.outputDir);if(b.count>0)console.log(`Optimized ${b.count} image(s) for responsive delivery`),D=[D,b.fingerprint].filter(Boolean).join(":");let B=new mt(e.cacheDir,D);if(e.cache)await B.load();try{let{generateCss:u}=await import("./chunk-t5r3s1wj.js");await u('<div class="bg-black"></div>')}catch{}rt();let xt=s?.routeMiddleware?.dir||"middleware";await ot(process.cwd(),xt);let H=st();if(H.length>0)console.log(`Loaded ${H.length} middleware: ${H.join(", ")}`);let vt=s?.routeMiddleware?.global||[];Bo(s?.layoutsDir,a(process.cwd()));let V=N(".",{pagesDir:e.pagesDir,pagesDirs:s?._layerPageDirs});console.log(`Found ${V.length} routes`);let _=[];for(let u of V){let m=await Ot(u);for(let v of m)_.push({route:u,url:v.url,params:v.params,props:v.props,revalidate:v.revalidate??e.revalidate})}l.totalPages=_.length,console.log(`Generating ${l.totalPages} pages...`);let A=[],K=[];for(let u=0;u<_.length;u+=e.concurrency)K.push(_.slice(u,u+e.concurrency));for(let u of K)await Promise.all(u.map(async(m)=>{let{route:v,url:d,params:L,props:Pt,revalidate:Q}=m;try{await e.hooks.onPageStart?.(d);let j=await Bun.file(v.filePath).text(),F=Jt(j),$t=F?.middleware?Array.isArray(F.middleware)?F.middleware:[F.middleware]:[],tt=[...vt,...$t];if(tt.length>0){let C=it(d,L,F||{}),O=at(C,null,void 0,{isServer:!0}),E=await ct(tt,O);if(E.redirect){let R=typeof E.redirect==="string"?E.redirect:E.redirect.path||E.redirect,U=Vt(String(R),d),T=Kt(d,e);await x.promises.mkdir(g.dirname(T),{recursive:!0}),await Bun.write(T,U),l.successCount++,l.pages.push({route:d,outputPath:T,size:Buffer.byteLength(U),cached:!1}),A.push({loc:d,lastmod:new Date().toISOString()}),console.log(` \u21B3 ${d} \u2192 redirect to ${R}`);return}if(E.abort){let R=typeof E.abort==="string"?E.abort:E.abort?.error?.message||"aborted";console.warn(` \u21B3 ${d} \u2014 middleware aborted: ${R}`);return}}let et=j.match(/definePageMeta\s*\(\s*\{[\s\S]*?validate\s*:\s*((?:\([^)]*\)|[^,}])*(?:\{[\s\S]*?\})?)/m);if(et)try{if(!await Function("route",`
|
|
45
45
|
const validate = ${et[1]};
|
|
46
46
|
return validate(route);
|
|
47
|
-
`)({params:L})){console.warn(`Validation failed for ${d}, skipping...`);return}}catch{}let k=null,
|
|
47
|
+
`)({params:L})){console.warn(`Validation failed for ${d}, skipping...`);return}}catch{}let k=null,nt=!1;if(e.cache){if(k=B.get(d,v.filePath),k)nt=!0,l.cachedCount++}if(!k){let C=await St(v,L,Pt,e,s);if(k=C.html,e.failOnIncludeError&&C.includeFailures.length>0)throw Error(`${C.includeFailures.length} include(s) failed to resolve, so this page would have shipped with an error banner where the markup should be:
|
|
48
48
|
${C.includeFailures.join(`
|
|
49
49
|
`)}
|
|
50
50
|
Set ssg.failOnIncludeError to false to build anyway.`);if(e.failOnServerScriptError&&C.serverScriptFailures.length>0)throw Error(`${C.serverScriptFailures.length} <script server> block(s) failed, so this page would have shipped with the content they produce missing:
|
|
51
51
|
${C.serverScriptFailures.join(`
|
|
52
52
|
`)}
|
|
53
|
-
Set ssg.failOnServerScriptError to false to build anyway.`);if(e.cache)B.set(d,v.filePath,C.dependencies,k)}let M;if(e.trailingSlash)M=g.join(e.outputDir,d,"index.html");else M=d==="/"?g.join(e.outputDir,"index.html"):g.join(e.outputDir,`${d}.html`);if(e.chunkIslands){let{html:C,chunks:O}=ut(k,{integrity:e.integrityIslands,minify:e.minify});if(O.length>0){let E=g.join(e.outputDir,"_stx","islands");await x.promises.mkdir(E,{recursive:!0});for(let R of O){let U=g.join(E,`${R.hash}.js`);if(!await Bun.file(U).exists())await Bun.write(U,R.code);if(!w.has(R.hash)){w.add(R.hash);let T=Buffer.byteLength(R.code,"utf8");y+=T,h[R.hash]={bytes:T,file:`/_stx/islands/${R.hash}.js`}}}if(S[d]=O.map((R)=>R.hash),k=C,e.prefetchIslands)k=dt(k)}}if(await x.promises.mkdir(g.dirname(M),{recursive:!0}),await Bun.write(M,k),!_t(d,k,F,e.sitemapExclude))A.push({loc:d,lastmod:new Date().toISOString().split("T")[0],priority:d==="/"?1:0.8});let lt={route:d,outputPath:M,size:Buffer.byteLength(k,"utf8"),cached:
|
|
53
|
+
Set ssg.failOnServerScriptError to false to build anyway.`);if(e.cache)B.set(d,v.filePath,C.dependencies,k)}let M;if(e.trailingSlash)M=g.join(e.outputDir,d,"index.html");else M=d==="/"?g.join(e.outputDir,"index.html"):g.join(e.outputDir,`${d}.html`);if(e.chunkIslands){let{html:C,chunks:O}=ut(k,{integrity:e.integrityIslands,minify:e.minify});if(O.length>0){let E=g.join(e.outputDir,"_stx","islands");await x.promises.mkdir(E,{recursive:!0});for(let R of O){let U=g.join(E,`${R.hash}.js`);if(!await Bun.file(U).exists())await Bun.write(U,R.code);if(!w.has(R.hash)){w.add(R.hash);let T=Buffer.byteLength(R.code,"utf8");y+=T,h[R.hash]={bytes:T,file:`/_stx/islands/${R.hash}.js`}}}if(S[d]=O.map((R)=>R.hash),k=C,e.prefetchIslands)k=dt(k)}}if(await x.promises.mkdir(g.dirname(M),{recursive:!0}),await Bun.write(M,k),!_t(d,k,F,e.sitemapExclude))A.push({loc:d,lastmod:new Date().toISOString().split("T")[0],priority:d==="/"?1:0.8});let lt={route:d,outputPath:M,size:Buffer.byteLength(k,"utf8"),cached:nt};if(Q!==!1)lt.revalidateAt=Date.now()+Q*1000;l.pages.push(lt),l.successCount++,await e.hooks.onPageEnd?.(d,k)}catch(j){l.failedCount++,l.errors.push({route:d,error:j}),await e.hooks.onError?.(j,d),console.error(`Error generating ${d}:`,j)}}));let Y=bt();if(Y.length>0){let u=Y.map((m)=>`${m.filePath}: ${m.message}`).join(`
|
|
54
54
|
`);throw Error(`Client script bundling failed:
|
|
55
55
|
${u}`)}if(e.cache)await B.save();if(e.generate404){let u=g.join(e.pagesDir,"404.stx");if(await Bun.file(u).exists()){let m=new Set,v={...s,debug:!1,cache:!1},d=await n(await Bun.file(u).text(),{},u,v,m);await Bun.write(g.join(e.outputDir,"404.html"),d)}else await Bun.write(g.join(e.outputDir,"404.html"),`<!DOCTYPE html>
|
|
56
56
|
<html lang="en">
|
|
@@ -73,7 +73,7 @@ ${u}`)}if(e.cache)await B.save();if(e.generate404){let u=g.join(e.pagesDir,"404.
|
|
|
73
73
|
<a href="/">Go home</a>
|
|
74
74
|
</div>
|
|
75
75
|
</body>
|
|
76
|
-
</html>`)}for(let u of[500]){let m=g.join(e.pagesDir,`${u}.stx`);if(await Bun.file(m).exists()){let v=new Set,d={...s,debug:!1,cache:!1},L=await n(await Bun.file(m).text(),{},m,d,v);await Bun.write(g.join(e.outputDir,`${u}.html`),L)}}let W=g.join(e.pagesDir,"error.stx");if(await Bun.file(W).exists()){let u=new Set,m={...s,debug:!1,cache:!1},v=await n(await Bun.file(W).text(),{},W,m,u);await Bun.write(g.join(e.outputDir,"error.html"),v)}if(e.sitemap&&A.length>0){let u=Gt(A,e.domain),m=g.join(e.outputDir,"sitemap.xml");await Bun.write(m,u),l.sitemapPath=m,console.log(`Generated sitemap.xml with ${A.length} URLs`)}if(e.robots!==!1){let u=typeof e.robots==="object"?e.robots:{},m=[...e.sitemapExclude.filter((d)=>typeof d==="string"),...u.disallow||[]],v=
|
|
76
|
+
</html>`)}for(let u of[500]){let m=g.join(e.pagesDir,`${u}.stx`);if(await Bun.file(m).exists()){let v=new Set,d={...s,debug:!1,cache:!1},L=await n(await Bun.file(m).text(),{},m,d,v);await Bun.write(g.join(e.outputDir,`${u}.html`),L)}}let W=g.join(e.pagesDir,"error.stx");if(await Bun.file(W).exists()){let u=new Set,m={...s,debug:!1,cache:!1},v=await n(await Bun.file(W).text(),{},W,m,u);await Bun.write(g.join(e.outputDir,"error.html"),v)}if(e.sitemap&&A.length>0){let u=Gt(A,e.domain),m=g.join(e.outputDir,"sitemap.xml");await Bun.write(m,u),l.sitemapPath=m,console.log(`Generated sitemap.xml with ${A.length} URLs`)}if(e.robots!==!1){let u=typeof e.robots==="object"?e.robots:{},m=[...e.sitemapExclude.filter((d)=>typeof d==="string"),...u.disallow||[]],v=or({rules:[{userAgent:u.userAgent||"*",allow:u.allow||["/"],...m.length>0?{disallow:m}:{}}],...u.sitemap!==!1&&l.sitemapPath?{sitemap:new URL("/sitemap.xml",e.domain).href}:{}});await Bun.write(g.join(e.outputDir,"robots.txt"),v),console.log("Generated robots.txt")}if(e.rss){let u=typeof e.rss==="object"?e.rss:{title:"Site Feed",description:"Latest updates",link:e.domain},m=[];if(u.getItems)m=await u.getItems();let v=Nt(u,m),d=g.join(e.outputDir,"rss.xml");await Bun.write(d,v),l.rssPath=d,console.log(`Generated rss.xml with ${m.length} items`)}let G=Lo(e.outputDir);if(G.assets>0)console.log(`Externalized ${G.assets} asset(s) from ${G.pages} page(s) (${(G.bytesInlined/1024).toFixed(1)}KB removed from HTML)`);let z=jo(e.outputDir);if(z.assets>0)console.log(`Externalized ${z.assets} repeated asset(s) from ${z.pages} page(s) (${(z.bytesInlined/1024).toFixed(1)}KB removed from HTML)`);if(e.publicDir&&x.existsSync(e.publicDir))await J(e.publicDir,e.outputDir),console.log(`Copied public assets from ${e.publicDir}`);let Z=tn();if(Z)await J(Z,g.join(e.outputDir,en)),console.log(`Copied assets from ${ht}`)}catch(D){throw await e.hooks.onError?.(D),D}if(l.buildTime=Date.now()-i,w.size>0){l.islandChunks={count:w.size,totalBytes:y};let D={generatedChunks:w.size,totalBytes:y,chunks:h,pages:S};await Bun.write(g.join(e.outputDir,"_stx","islands-manifest.json"),JSON.stringify(D,null,2))}await e.hooks.onBuildEnd?.(l);let P=l.islandChunks?`
|
|
77
77
|
Island chunks: ${l.islandChunks.count} (${(l.islandChunks.totalBytes/1024).toFixed(1)} KB lifted out of inline HTML)`:"";return console.log(`
|
|
78
78
|
Build complete!
|
|
79
79
|
Total: ${l.totalPages} pages
|
|
@@ -81,8 +81,8 @@ Build complete!
|
|
|
81
81
|
Cached: ${l.cachedCount}
|
|
82
82
|
Failed: ${l.failedCount}
|
|
83
83
|
Time: ${l.buildTime}ms${P}
|
|
84
|
-
`),l}async function J(t,i){await x.promises.mkdir(i,{recursive:!0});let s=await x.promises.readdir(t,{withFileTypes:!0});for(let r of s){let c=g.join(t,r.name),e=g.join(i,r.name);if(r.isDirectory())await x.promises.mkdir(e,{recursive:!0}),await J(c,e);else await x.promises.copyFile(c,e)}}function Ht(t={}){let i=t.cacheDir||a(process.cwd(),"ssg-cache"),s=new
|
|
85
|
-
`)){let P=S.indexOf(":");if(P>0){let D=S.slice(0,P).trim(),p=S.slice(P+1).trim();if(p==="true")p=!0;else if(p==="false")p=!1;else if(/^\d+$/.test(p))p=parseInt(p,10);else if(/^\d+\.\d+$/.test(p))p=parseFloat(p);else if(p.startsWith("[")&&p.endsWith("]"))p=p.slice(1,-1).split(",").map((b)=>b.trim().replace(/^['"]|['"]$/g,""));r[D]=p}}}let e=c.replace(/^### (.*$)/gim,"<h3>$1</h3>").replace(/^## (.*$)/gim,"<h2>$1</h2>").replace(/^# (.*$)/gim,"<h1>$1</h1>").replace(/\*\*(.*)\*\*/gim,"<strong>$1</strong>").replace(/\*(.*)\*/gim,"<em>$1</em>").replace(/`([^`]+)`/gim,"<code>$1</code>").replace(/\[([^\]]+)\]\(([^)]+)\)/gim,'<a href="$2">$1</a>').replace(/\n/gim,"<br>"),l=[],w=/<h([1-6])>([^<]+)<\/h[1-6]>/gi,y;while((y=w.exec(e))!==null){let h=parseInt(y[1],10),S=y[2],P=S.toLowerCase().replace(/[^a-z0-9]+/g,"-");l.push({id:P,text:S,level:h})}return{content:e,data:r,toc:l}}}}function Jt(t){return
|
|
84
|
+
`),l}async function J(t,i){await x.promises.mkdir(i,{recursive:!0});let s=await x.promises.readdir(t,{withFileTypes:!0});for(let r of s){let c=g.join(t,r.name),e=g.join(i,r.name);if(r.isDirectory())await x.promises.mkdir(e,{recursive:!0}),await J(c,e);else await x.promises.copyFile(c,e)}}function Ht(t={}){let i=t.cacheDir||a(process.cwd(),"ssg-cache"),s=new yt(i),r=t.revalidate||3600;return{async get(c){let e=await s.get(c);if(!e)return null;if(Date.now()>e.revalidateAfter)this.revalidate(c).catch(console.error);return{html:e.html,headers:{"Cache-Control":`public, max-age=${r}, stale-while-revalidate=${r*2}`,ETag:e.etag,"X-ISR-Generated":new Date(e.generatedAt).toISOString(),...e.headers}}},async revalidate(c){let l=N(".",{pagesDir:t.pagesDir||"pages"}).find((P)=>c.match(P.regex)!==null);if(!l){console.warn(`Route not found for revalidation: ${c}`);return}let w=c.match(l.regex),y={};if(w)l.params.forEach((P,D)=>{y[P]=w[D+1]});let h=await o(),{html:S}=await St(l,y,{},t,h);await s.set(c,{html:S,generatedAt:Date.now(),revalidateAfter:Date.now()+r*1000,etag:Ut(S)}),console.log(`Revalidated: ${c}`)},async invalidate(c){if(typeof c==="string")await s.invalidate(c);else await s.invalidatePattern(c)}}}function Wt(t){return async()=>({paths:await t(),fallback:!1})}function qt(){return{name:"markdown",extensions:[".md",".mdx"],async load(t){let i=await Bun.file(t).text(),s=i.match(/^---\n([\s\S]*?)\n---/),r={},c=i;if(s){let h=s[1];c=i.slice(s[0].length).trim();for(let S of h.split(`
|
|
85
|
+
`)){let P=S.indexOf(":");if(P>0){let D=S.slice(0,P).trim(),p=S.slice(P+1).trim();if(p==="true")p=!0;else if(p==="false")p=!1;else if(/^\d+$/.test(p))p=parseInt(p,10);else if(/^\d+\.\d+$/.test(p))p=parseFloat(p);else if(p.startsWith("[")&&p.endsWith("]"))p=p.slice(1,-1).split(",").map((b)=>b.trim().replace(/^['"]|['"]$/g,""));r[D]=p}}}let e=c.replace(/^### (.*$)/gim,"<h3>$1</h3>").replace(/^## (.*$)/gim,"<h2>$1</h2>").replace(/^# (.*$)/gim,"<h1>$1</h1>").replace(/\*\*(.*)\*\*/gim,"<strong>$1</strong>").replace(/\*(.*)\*/gim,"<em>$1</em>").replace(/`([^`]+)`/gim,"<code>$1</code>").replace(/\[([^\]]+)\]\(([^)]+)\)/gim,'<a href="$2">$1</a>').replace(/\n/gim,"<br>"),l=[],w=/<h([1-6])>([^<]+)<\/h[1-6]>/gi,y;while((y=w.exec(e))!==null){let h=parseInt(y[1],10),S=y[2],P=S.toLowerCase().replace(/[^a-z0-9]+/g,"-");l.push({id:P,text:S,level:h})}return{content:e,data:r,toc:l}}}}function Jt(t){return He(t)}function Vt(t,i){return`<!DOCTYPE html>
|
|
86
86
|
<html>
|
|
87
87
|
<head>
|
|
88
88
|
<meta charset="utf-8">
|
|
@@ -94,4 +94,4 @@ Build complete!
|
|
|
94
94
|
<p>Redirecting to <a href="${t}">${t}</a>...</p>
|
|
95
95
|
<script>window.location.replace('${t}')</script>
|
|
96
96
|
</body>
|
|
97
|
-
</html>`}function Kt(t,i){if(t==="/"||t==="")return g.join(i.outputDir,"index.html");let s=t.replace(/^\/|\/$/g,"");if(i.trailingSlash)return g.join(i.outputDir,s,"index.html");return g.join(i.outputDir,`${s}.html`)}var
|
|
97
|
+
</html>`}function Kt(t,i){if(t==="/"||t==="")return g.join(i.outputDir,"index.html");let s=t.replace(/^\/|\/$/g,"");if(i.trailingSlash)return g.join(i.outputDir,s,"index.html");return g.join(i.outputDir,`${s}.html`)}var ye={generateStaticSite:zt,createISRHandler:Ht,defineStaticPaths:Wt,createMarkdownLoader:qt};export{Ht as createISRHandler,qt as createMarkdownLoader,Lt as declaresPageAction,ye as default,Wt as defineStaticPaths,zt as generateStaticSite,_t as isExcludedFromSitemap};
|