@stacksjs/stx 0.2.303 → 0.2.304
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/api-client.d.ts +26 -0
- package/dist/api-client.js +22 -0
- package/dist/api-handler.d.ts +6 -0
- package/dist/api-handler.js +3 -0
- package/dist/app-shell.js +11 -2
- package/dist/application-layers.d.ts +30 -0
- package/dist/application-layers.js +202 -0
- package/dist/build.js +9 -1
- package/dist/chunk-02hm88m5.js +2 -0
- package/dist/{chunk-7eea1cse.js → chunk-09zjty4k.js} +1 -1
- package/dist/{chunk-7nfn7nj9.js → chunk-0gz0rhvs.js} +1 -1
- package/dist/{chunk-jsfch50r.js → chunk-1c2j4eby.js} +1 -1
- package/dist/{chunk-m6wz1hf5.js → chunk-2h94c5hm.js} +2 -2
- package/dist/{chunk-mjpqz66q.js → chunk-2ver2s2y.js} +1 -1
- package/dist/{chunk-hp3rjwnb.js → chunk-30nbe9hr.js} +2 -2
- package/dist/chunk-39qzhpn6.js +18 -0
- package/dist/chunk-3z6bqqr7.js +2 -0
- package/dist/chunk-43p1qq7g.js +2 -0
- package/dist/{chunk-c6b5nqct.js → chunk-45y8bjrv.js} +287 -352
- package/dist/{chunk-2rp09y5j.js → chunk-4evbx7sz.js} +1 -1
- package/dist/chunk-4jgr954p.js +2 -0
- package/dist/chunk-51j2aqvb.js +2 -0
- package/dist/{chunk-whm6bybj.js → chunk-54f8bpp6.js} +3 -3
- package/dist/{chunk-yfwyvh02.js → chunk-5k1hznvq.js} +2 -2
- package/dist/chunk-5qfpcgcs.js +2 -0
- package/dist/{chunk-7eg7ep8f.js → chunk-5tefa8qb.js} +2 -2
- package/dist/chunk-5x2fc4vk.js +30 -0
- package/dist/{chunk-683tfkz4.js → chunk-64djh88a.js} +1 -1
- package/dist/{chunk-btrmvj2y.js → chunk-695fkras.js} +1 -1
- package/dist/chunk-6hcc4973.js +2 -0
- package/dist/{chunk-y7dcdjav.js → chunk-6vswphz4.js} +2 -2
- package/dist/chunk-7gqbr8nr.js +2 -0
- package/dist/{chunk-x4prtyjs.js → chunk-7kw3grq5.js} +1 -1
- package/dist/{chunk-7jebw3ea.js → chunk-7skk34dh.js} +2 -2
- package/dist/chunk-8215nhej.js +12 -0
- package/dist/chunk-8ee62a9q.js +2 -0
- package/dist/{chunk-jj6yp7gm.js → chunk-8jam44my.js} +1 -1
- package/dist/chunk-8z0n5mtg.js +2 -0
- package/dist/{chunk-3bc8bqw2.js → chunk-9368t9jm.js} +1 -1
- package/dist/chunk-9499k64n.js +6 -0
- package/dist/chunk-976g5qe5.js +2 -0
- package/dist/{chunk-3jwmcf4k.js → chunk-9c835qjn.js} +1 -1
- package/dist/chunk-9px4y692.js +2 -0
- package/dist/{chunk-zn6xcc0a.js → chunk-9vqnrcrw.js} +2 -2
- package/dist/chunk-9wrrr7g3.js +4 -0
- package/dist/{chunk-95t0k8cz.js → chunk-9xzszvn5.js} +1 -1
- package/dist/chunk-a07chbgj.js +2 -0
- package/dist/{chunk-rdg1n42s.js → chunk-ankp4reb.js} +2 -2
- package/dist/{chunk-5d9cy7a0.js → chunk-awj7yy37.js} +1 -1
- package/dist/chunk-b1hd8kvy.js +2 -0
- package/dist/chunk-b4xwbh8a.js +2 -0
- package/dist/{chunk-1evf3bdg.js → chunk-bd9wrcq1.js} +205 -19
- package/dist/{chunk-q25mr70f.js → chunk-c131k3mt.js} +1 -1
- package/dist/chunk-c3tmzx7q.js +2 -0
- package/dist/{chunk-6btbgxh1.js → chunk-c79nfdyj.js} +1 -1
- package/dist/{chunk-cfgpk6bh.js → chunk-cbgh359m.js} +1 -1
- package/dist/chunk-ckzhp09g.js +2 -0
- package/dist/{chunk-weqpt9nt.js → chunk-cr8v8k53.js} +1 -1
- package/dist/{chunk-p3wwm6k4.js → chunk-d19tvdvv.js} +1 -1
- package/dist/{chunk-nb1zdh1y.js → chunk-d3srvh3q.js} +1 -1
- package/dist/{chunk-rqrfq305.js → chunk-d57gb0v2.js} +1 -1
- package/dist/{chunk-1xyhk1wr.js → chunk-d5cqnwdd.js} +1 -1
- package/dist/chunk-dgpjxmhs.js +2 -0
- package/dist/chunk-dvvx1wny.js +3 -0
- package/dist/{chunk-ctz53mbz.js → chunk-ej8mv2k6.js} +1 -1
- package/dist/{chunk-dv3z80gt.js → chunk-env6knrs.js} +1 -1
- package/dist/{chunk-rf10fkrf.js → chunk-ess2pgt5.js} +1 -1
- package/dist/chunk-ez28vck6.js +2 -0
- package/dist/{chunk-0tbgvp70.js → chunk-fczfdsab.js} +21 -5
- package/dist/{chunk-xdq52pwj.js → chunk-fp7ms6e7.js} +1 -1
- package/dist/{chunk-qg6pg6ze.js → chunk-fqq5k9ve.js} +1 -1
- package/dist/chunk-fvtv1s5j.js +3 -0
- package/dist/{chunk-5t0w4h6z.js → chunk-g912mb7x.js} +1 -1
- package/dist/chunk-g97atepq.js +2 -0
- package/dist/{chunk-wj25qt72.js → chunk-gbwhbasw.js} +1 -1
- package/dist/{chunk-f62fh1fw.js → chunk-gfc3qye3.js} +2 -2
- package/dist/{chunk-cratkhhb.js → chunk-ghw5p1yk.js} +1 -1
- package/dist/{chunk-f0g2q51j.js → chunk-gssbag3e.js} +1 -1
- package/dist/{chunk-c9vhtjtr.js → chunk-gt8ja700.js} +2 -2
- package/dist/chunk-hay1rzb0.js +3754 -0
- package/dist/{chunk-ftvmk1nj.js → chunk-hg2afckn.js} +1 -1
- package/dist/chunk-hgjjnjas.js +7 -0
- package/dist/{chunk-hhnzd03k.js → chunk-hrcxfvh1.js} +1 -1
- package/dist/chunk-hzav4hyd.js +2 -0
- package/dist/{chunk-29gjwajm.js → chunk-jfzfrmzy.js} +1 -1
- package/dist/chunk-jjq9q9jr.js +2 -0
- package/dist/{chunk-ddqkj56r.js → chunk-jp2f8yzw.js} +1 -1
- package/dist/{chunk-ry3a2674.js → chunk-jsg1rthc.js} +1 -1
- package/dist/chunk-jxxv18a0.js +5 -0
- package/dist/chunk-kbw2qzqx.js +2 -0
- package/dist/chunk-kdxvraec.js +2 -0
- package/dist/chunk-krfjb7b8.js +2 -0
- package/dist/{chunk-6b4k8fay.js → chunk-kxavsh3m.js} +1 -1
- package/dist/{chunk-4tffxxpd.js → chunk-m31n9pkr.js} +1 -1
- package/dist/{chunk-fj6fbqgb.js → chunk-m3a20mmb.js} +1 -1
- package/dist/{chunk-j21csh4j.js → chunk-mbmqpaq1.js} +1 -1
- package/dist/{chunk-y9nyqcha.js → chunk-mwh3ymwc.js} +1 -1
- package/dist/{chunk-51g95yts.js → chunk-mygq61f5.js} +2 -2
- package/dist/chunk-nqq7y7m9.js +3 -0
- package/dist/chunk-nws8fbde.js +2 -0
- package/dist/{chunk-q6xfyasj.js → chunk-pcvayb2f.js} +1 -1
- package/dist/{chunk-nvxv2wxv.js → chunk-ppyz9623.js} +1 -1
- package/dist/chunk-pr14wjkn.js +2 -0
- package/dist/{chunk-jb2r696a.js → chunk-qev11kg8.js} +1 -1
- package/dist/{chunk-6njgsr6w.js → chunk-qeyw5za9.js} +1 -1
- package/dist/chunk-rpfcnq8n.js +2 -0
- package/dist/chunk-rrankpmj.js +3 -0
- package/dist/chunk-rst1rw09.js +2 -0
- package/dist/{chunk-3p0zgfgz.js → chunk-rzevgemj.js} +2 -2
- package/dist/{chunk-aa6kt84c.js → chunk-sart9ehj.js} +1 -1
- package/dist/chunk-sb7ana2z.js +19 -0
- package/dist/chunk-snt2773t.js +2 -0
- package/dist/{chunk-jptkc64r.js → chunk-t3qb9s6s.js} +2 -2
- package/dist/{chunk-w8yac9xp.js → chunk-t41aaehf.js} +1 -1
- package/dist/{chunk-qjkzpd68.js → chunk-t51mwjyq.js} +1 -1
- package/dist/chunk-tt4r8q4v.js +2 -0
- package/dist/chunk-vd3h9z7e.js +2 -0
- package/dist/{chunk-6rzwef28.js → chunk-vd5xvsnv.js} +1 -1
- package/dist/chunk-wbecqx03.js +2 -0
- package/dist/{chunk-dcxtrqfy.js → chunk-wfffa8zm.js} +1 -1
- package/dist/{chunk-22p0ezj6.js → chunk-wx13qmaw.js} +1 -1
- package/dist/chunk-xd5ahrtn.js +2 -0
- package/dist/{chunk-2m6x8tcx.js → chunk-xganfzgn.js} +2 -2
- package/dist/chunk-xq1swv2e.js +2 -0
- package/dist/chunk-xsfwcj6x.js +2 -0
- package/dist/{chunk-91007tan.js → chunk-xwxdwqn9.js} +1 -1
- package/dist/{chunk-634gaa9d.js → chunk-xz3evxqp.js} +1 -1
- package/dist/chunk-xzgvcrnz.js +2 -0
- package/dist/chunk-y2kmm6bt.js +43 -0
- package/dist/{chunk-v8474ah4.js → chunk-y4nzmkea.js} +1 -1
- package/dist/chunk-y7wsk78j.js +3 -0
- package/dist/{chunk-6w8fa3b8.js → chunk-ya5m5vbn.js} +1 -1
- package/dist/{chunk-ps20v1ah.js → chunk-ym3r8ktq.js} +1 -1
- package/dist/chunk-yyebm8q4.js +2 -0
- package/dist/chunk-yyyxt326.js +2 -0
- package/dist/chunk-yz16bgs3.js +28 -0
- package/dist/{chunk-ew6tr7b1.js → chunk-z9ezmjwd.js} +2 -2
- package/dist/chunk-zbtfhxhn.js +2 -0
- package/dist/chunk-zggm7kjd.js +17 -0
- package/dist/{chunk-mdf3jbe6.js → chunk-zhcs8m2a.js} +2 -2
- package/dist/{chunk-f9d27v49.js → chunk-zs5y7xnt.js} +1 -1
- package/dist/cli.js +14 -14
- package/dist/client-script-bundler.js +22 -11
- package/dist/component-contract-checks.d.ts +19 -0
- package/dist/component-contract-checks.js +147 -0
- package/dist/component-contract.d.ts +20 -0
- package/dist/component-contract.js +108 -0
- package/dist/component-model.d.ts +29 -0
- package/dist/component-model.js +59 -0
- package/dist/component-registry.js +7 -64
- package/dist/component-renderer.d.ts +1 -26
- package/dist/component-renderer.js +4 -239
- package/dist/component-resolution.d.ts +21 -0
- package/dist/component-resolution.js +118 -0
- package/dist/component-tags.d.ts +9 -0
- package/dist/component-tags.js +174 -0
- package/dist/composable-loader.d.ts +2 -13
- package/dist/composable-loader.js +15 -26
- package/dist/composables/index.d.ts +1 -0
- package/dist/composables/index.js +1 -0
- package/dist/composables/use-fetch.d.ts +117 -42
- package/dist/composables/use-fetch.js +47 -4
- package/dist/composition-api.d.ts +43 -19
- package/dist/config.d.ts +1 -1
- package/dist/config.js +46 -4
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/database.js +1 -1
- package/dist/dev-server/serve-app.js +57 -17
- package/dist/dev-server/serve-file.js +8 -1
- package/dist/expressions.js +1 -1
- package/dist/imported-signals.js +1 -1
- package/dist/includes.js +8 -2
- package/dist/index.d.ts +11 -0
- package/dist/index.js +7 -0
- package/dist/manifest.d.ts +6 -0
- package/dist/misc-directives.d.ts +2 -0
- package/dist/misc-directives.js +39 -1
- package/dist/process.js +18 -1
- package/dist/production-builder.d.ts +4 -0
- package/dist/production-builder.js +47 -8
- package/dist/production-server.d.ts +4 -1
- package/dist/production-server.js +119 -71
- package/dist/pwa.js +2 -2
- package/dist/render.js +9 -2
- package/dist/route-response-cache.d.ts +7 -0
- package/dist/route-response-cache.js +72 -0
- package/dist/route-rules.d.ts +17 -0
- package/dist/route-rules.js +40 -0
- package/dist/router.d.ts +1 -0
- package/dist/runtime-config-loader.d.ts +5 -0
- package/dist/runtime-config-loader.js +42 -0
- package/dist/runtime-config-server.d.ts +26 -0
- package/dist/runtime-config-server.js +77 -0
- package/dist/runtime-config-types.d.ts +2 -0
- package/dist/runtime-config-types.js +0 -0
- package/dist/runtime-config.d.ts +5 -0
- package/dist/runtime-config.js +9 -0
- package/dist/runtime-globals.js +3 -0
- package/dist/serve.js +32 -10
- package/dist/server-api.d.ts +27 -0
- package/dist/server-api.js +181 -0
- package/dist/server-data.d.ts +17 -0
- package/dist/server-data.js +40 -0
- package/dist/signal-processing.js +2 -2
- package/dist/signals.js +138 -15
- package/dist/ssg.js +2 -2
- package/dist/stx-virtual-ts.d.ts +6 -0
- package/dist/stx-virtual-ts.js +31 -7
- package/dist/stx.d.ts +28 -0
- package/dist/template-compiler.d.ts +1 -0
- package/dist/template-compiler.js +1 -1
- package/dist/template-hydrator.js +15 -4
- package/dist/typecheck.d.ts +1 -0
- package/dist/typecheck.js +4 -3
- package/dist/types/config-types.d.ts +17 -0
- package/dist/utils.js +15 -5
- package/dist/variable-extractor.d.ts +1 -1
- package/dist/variable-extractor.js +12 -1
- package/dist/visual-testing.js +1 -1
- package/dist/vue-template.js +19 -41
- package/package.json +5 -5
- package/stx.d.ts +28 -0
- package/dist/chunk-0p44z42s.js +0 -2
- package/dist/chunk-2jd9bxmf.js +0 -2
- package/dist/chunk-2yp8ang5.js +0 -2
- package/dist/chunk-35x7s4cr.js +0 -2
- package/dist/chunk-3bqz5zre.js +0 -2
- package/dist/chunk-48p0k8y7.js +0 -2
- package/dist/chunk-4b625drg.js +0 -2
- package/dist/chunk-593kby1d.js +0 -2
- package/dist/chunk-5nac67r4.js +0 -18
- package/dist/chunk-70cf5h11.js +0 -2
- package/dist/chunk-78akhaws.js +0 -2
- package/dist/chunk-9a4q74r6.js +0 -2
- package/dist/chunk-9f5329rv.js +0 -2
- package/dist/chunk-9rv7akqq.js +0 -30
- package/dist/chunk-apjy1a72.js +0 -12
- package/dist/chunk-b3p3bzax.js +0 -3
- package/dist/chunk-c5hk1fxt.js +0 -2
- package/dist/chunk-c9rs5g1s.js +0 -2
- package/dist/chunk-dkd0bg8g.js +0 -2
- package/dist/chunk-dxhtry04.js +0 -2
- package/dist/chunk-ehp6fez3.js +0 -2
- package/dist/chunk-em3jb1dn.js +0 -4
- package/dist/chunk-ev4djb0p.js +0 -2
- package/dist/chunk-frejnjh9.js +0 -2
- package/dist/chunk-fvcr26a0.js +0 -22
- package/dist/chunk-g6ttsdz1.js +0 -2
- package/dist/chunk-gd73rpks.js +0 -2
- package/dist/chunk-ggwnrdqz.js +0 -17
- package/dist/chunk-h3t6fjba.js +0 -2
- package/dist/chunk-jc57j887.js +0 -2
- package/dist/chunk-jw248h1d.js +0 -2
- package/dist/chunk-k5xtf38q.js +0 -3
- package/dist/chunk-m78y5qys.js +0 -19
- package/dist/chunk-mc4rtf5d.js +0 -2
- package/dist/chunk-mx2wcb15.js +0 -2
- package/dist/chunk-p4w3wjbv.js +0 -2
- package/dist/chunk-pm3k8dyk.js +0 -2
- package/dist/chunk-qr59yfq9.js +0 -2
- package/dist/chunk-qsmdvy1z.js +0 -2
- package/dist/chunk-rsxmjfxq.js +0 -3754
- package/dist/chunk-s4sp78fn.js +0 -2
- package/dist/chunk-v2fp9vkh.js +0 -2
- package/dist/chunk-vwnnbzsp.js +0 -2
- package/dist/chunk-w0g99tx9.js +0 -2
- package/dist/chunk-x2pk87q2.js +0 -3
- package/dist/chunk-xn0asg46.js +0 -2
- package/dist/chunk-xwmw1wtk.js +0 -2
- package/dist/chunk-zdx9s3z0.js +0 -28
|
@@ -1,3 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* STX Composition API
|
|
3
|
+
*
|
|
4
|
+
* Provides Vue-compatible Composition API features:
|
|
5
|
+
* - provide() / inject() for dependency injection across components
|
|
6
|
+
* - defineEmits() for typed event emission
|
|
7
|
+
* - defineExpose() for exposing component internals to template refs
|
|
8
|
+
* - nextTick() for waiting on DOM updates
|
|
9
|
+
* - getCurrentInstance() for accessing the current component instance
|
|
10
|
+
* - onErrorCaptured() for error boundary handling
|
|
11
|
+
*
|
|
12
|
+
* @module composition-api
|
|
13
|
+
*/
|
|
14
|
+
/** Represents a component instance in the stx component tree */
|
|
15
|
+
export interface StxComponentInstance {
|
|
16
|
+
/** Unique scope ID for this instance */
|
|
17
|
+
scopeId: string;
|
|
18
|
+
/** Parent component instance */
|
|
19
|
+
parent: StxComponentInstance | null;
|
|
20
|
+
/** Provided values from this instance */
|
|
21
|
+
provides: Map<string | symbol, unknown>;
|
|
22
|
+
/** Exposed public properties */
|
|
23
|
+
exposed: Record<string, unknown> | null;
|
|
24
|
+
/** Template refs */
|
|
25
|
+
refs: Record<string, Element | null>;
|
|
26
|
+
/** Component props */
|
|
27
|
+
props: Record<string, unknown>;
|
|
28
|
+
/** Component attrs (non-prop attributes) */
|
|
29
|
+
attrs: Record<string, unknown>;
|
|
30
|
+
/** Slot content */
|
|
31
|
+
slots: Record<string, any>;
|
|
32
|
+
/** Emit function */
|
|
33
|
+
emit: EmitFn;
|
|
34
|
+
/** Root element */
|
|
35
|
+
el: Element | null;
|
|
36
|
+
/** Error captured hooks */
|
|
37
|
+
errorCapturedHooks: Array<(error: Error, instance: StxComponentInstance | null, info: string) => boolean | void>;
|
|
38
|
+
/** Is mounted */
|
|
39
|
+
isMounted: boolean;
|
|
40
|
+
}
|
|
1
41
|
/**
|
|
2
42
|
* Generate a unique scope ID.
|
|
3
43
|
*/
|
|
@@ -58,6 +98,8 @@ export declare function inject<T>(key: string | symbol, defaultValue?: T): T | u
|
|
|
58
98
|
* @internal
|
|
59
99
|
*/
|
|
60
100
|
export declare function setGlobalProvide<T>(key: string | symbol, value: T): void;
|
|
101
|
+
/** Type-safe emit function */
|
|
102
|
+
export type EmitFn<T extends string = string> = (event: T, ...args: any[]) => void;
|
|
61
103
|
/**
|
|
62
104
|
* Define the events a component can emit.
|
|
63
105
|
* Returns a typed emit function.
|
|
@@ -155,7 +197,7 @@ export declare function useSlots(): Record<string, any>;
|
|
|
155
197
|
* if (slots.header) { ... }
|
|
156
198
|
* ```
|
|
157
199
|
*/
|
|
158
|
-
export declare function defineSlots<T extends Record<string, (...args: any[]) => any> = Record<string, (...args: any[]) => any
|
|
200
|
+
export declare function defineSlots<T extends Record<string, (...args: any[]) => any> = Record<string, (...args: any[]) => any>>(): T;
|
|
159
201
|
/**
|
|
160
202
|
* Get the current component's non-prop attributes.
|
|
161
203
|
*
|
|
@@ -177,21 +219,3 @@ export declare function createProvideContext(parentContext: Record<string, any>)
|
|
|
177
219
|
* @internal
|
|
178
220
|
*/
|
|
179
221
|
export declare function generateCompositionRuntime(): string;
|
|
180
|
-
/** Represents a component instance in the stx component tree */
|
|
181
|
-
export declare interface StxComponentInstance {
|
|
182
|
-
scopeId: string
|
|
183
|
-
parent: StxComponentInstance | null
|
|
184
|
-
provides: Map<string | symbol, unknown>
|
|
185
|
-
exposed: Record<string, unknown> | null
|
|
186
|
-
refs: Record<string, Element | null>
|
|
187
|
-
props: Record<string, unknown>
|
|
188
|
-
attrs: Record<string, unknown>
|
|
189
|
-
slots: Record<string, any>
|
|
190
|
-
emit: EmitFn
|
|
191
|
-
el: Element | null
|
|
192
|
-
errorCapturedHooks: Array<(error: Error, instance: StxComponentInstance | null, info: string) => boolean | void>
|
|
193
|
-
isMounted: boolean
|
|
194
|
-
}
|
|
195
|
-
/** Type-safe emit function */
|
|
196
|
-
// eslint-disable-next-line pickier/no-unused-vars
|
|
197
|
-
export type EmitFn<T extends string = string> = (event: T, ...args: any[]) => void;
|
package/dist/config.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare const config: StxConfig;
|
|
|
43
43
|
/**
|
|
44
44
|
* Helper function to define stx configuration
|
|
45
45
|
*/
|
|
46
|
-
export declare function defineStxConfig(config:
|
|
46
|
+
export declare function defineStxConfig<T extends StxOptions>(config: T): T;
|
|
47
47
|
/**
|
|
48
48
|
* Configuration validation error
|
|
49
49
|
*/
|
package/dist/config.js
CHANGED
|
@@ -13,6 +13,7 @@ import { pwaDirectives } from "./pwa/directives.js";
|
|
|
13
13
|
import { metaDirective, structuredDataDirective } from "./seo.js";
|
|
14
14
|
import { DEFAULT_STATE_DIR, rebaseOntoStateDir, setStateDir, stateDirName } from "./state-dir.js";
|
|
15
15
|
import { webComponentDirectiveHandler } from "./web-components.js";
|
|
16
|
+
import { layerConfigSignature, layerSignature, refreshLayerDiagnostics, resolveApplicationLayers } from "./application-layers.js";
|
|
16
17
|
export const defaultConfig = {
|
|
17
18
|
enabled: !0,
|
|
18
19
|
ssr: !1,
|
|
@@ -453,26 +454,63 @@ function applyStateDir(loaded) {
|
|
|
453
454
|
loaded.story.outDir = rebaseOntoStateDir(loaded.story.outDir);
|
|
454
455
|
}
|
|
455
456
|
let _config = null;
|
|
456
|
-
const _cwdConfigCache = new Map;
|
|
457
|
+
const _cwdConfigCache = new Map, _layerSnapshots = new Map;
|
|
457
458
|
let _configPromise = null;
|
|
458
459
|
export async function loadStxConfig(cwd) {
|
|
460
|
+
const effectiveCwd = cwd ? path.resolve(cwd) : process.cwd(), snapshot = _layerSnapshots.get(effectiveCwd);
|
|
461
|
+
if (snapshot && snapshot.signature !== layerSignature(snapshot.graph)) {
|
|
462
|
+
const previous = _cwdConfigCache.get(effectiveCwd);
|
|
463
|
+
_cwdConfigCache.delete(effectiveCwd);
|
|
464
|
+
_layerSnapshots.delete(effectiveCwd);
|
|
465
|
+
if (!cwd) {
|
|
466
|
+
_config = null;
|
|
467
|
+
_configPromise = null;
|
|
468
|
+
}
|
|
469
|
+
const { clearComponentCache } = await import("./utils.js"), { partialsCache } = await import("./includes.js");
|
|
470
|
+
clearComponentCache();
|
|
471
|
+
partialsCache.clear();
|
|
472
|
+
if (previous && snapshot.configSignature === layerConfigSignature(snapshot.graph)) {
|
|
473
|
+
const refreshed = previous.then(async (loaded) => {
|
|
474
|
+
const graph = { ...snapshot.graph };
|
|
475
|
+
await refreshLayerDiagnostics(graph, effectiveCwd);
|
|
476
|
+
_layerSnapshots.set(effectiveCwd, { graph, signature: layerSignature(graph), configSignature: layerConfigSignature(graph) });
|
|
477
|
+
const result = { ...loaded, _layerGraph: graph };
|
|
478
|
+
if (!cwd)
|
|
479
|
+
_config = result;
|
|
480
|
+
return result;
|
|
481
|
+
});
|
|
482
|
+
_cwdConfigCache.set(effectiveCwd, refreshed);
|
|
483
|
+
return refreshed;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
459
486
|
if (!cwd) {
|
|
460
487
|
if (_config)
|
|
461
488
|
return _config;
|
|
462
489
|
if (_configPromise)
|
|
463
490
|
return _configPromise;
|
|
464
491
|
}
|
|
465
|
-
const
|
|
492
|
+
const cached = _cwdConfigCache.get(effectiveCwd);
|
|
466
493
|
if (cached)
|
|
467
494
|
return cached;
|
|
468
495
|
const promise = (async () => {
|
|
469
|
-
|
|
496
|
+
let loaded = (await loadConfigWithResult({
|
|
470
497
|
name: "stx",
|
|
471
498
|
alias: "ui",
|
|
472
499
|
cwd: effectiveCwd,
|
|
473
500
|
defaultConfig,
|
|
474
501
|
verbose: !1
|
|
475
502
|
})).config;
|
|
503
|
+
if (loaded.extends !== void 0 || snapshot) {
|
|
504
|
+
const resolved = await resolveApplicationLayers(effectiveCwd, defaultConfig);
|
|
505
|
+
loaded = resolved.config;
|
|
506
|
+
_layerSnapshots.set(effectiveCwd, { graph: resolved.graph, signature: layerSignature(resolved.graph), configSignature: layerConfigSignature(resolved.graph) });
|
|
507
|
+
}
|
|
508
|
+
if (loaded.runtimeConfig) {
|
|
509
|
+
const { resolveRuntimeConfig } = await import("./runtime-config-server.js");
|
|
510
|
+
resolveRuntimeConfig(loaded.runtimeConfig, {});
|
|
511
|
+
const { generateRuntimeConfigTypes } = await import("./runtime-config-loader.js");
|
|
512
|
+
await generateRuntimeConfigTypes(effectiveCwd, loaded.runtimeConfig);
|
|
513
|
+
}
|
|
476
514
|
detachMutableContainers(loaded);
|
|
477
515
|
applyStateDir(loaded);
|
|
478
516
|
resolveStxDirectories(loaded, effectiveCwd);
|
|
@@ -487,7 +525,7 @@ export async function loadStxConfig(cwd) {
|
|
|
487
525
|
pluginModule = await import(pluginPath);
|
|
488
526
|
pluginDir = path.dirname(require.resolve(pluginPath));
|
|
489
527
|
} catch {
|
|
490
|
-
const resolvedPath = path.resolve(
|
|
528
|
+
const resolvedPath = path.resolve(effectiveCwd, pluginPath);
|
|
491
529
|
pluginModule = await import(resolvedPath);
|
|
492
530
|
pluginDir = path.dirname(resolvedPath);
|
|
493
531
|
}
|
|
@@ -533,6 +571,10 @@ export async function loadStxConfig(cwd) {
|
|
|
533
571
|
return loaded;
|
|
534
572
|
})();
|
|
535
573
|
_cwdConfigCache.set(effectiveCwd, promise);
|
|
574
|
+
promise.catch(() => {
|
|
575
|
+
if (_cwdConfigCache.get(effectiveCwd) === promise)
|
|
576
|
+
_cwdConfigCache.delete(effectiveCwd);
|
|
577
|
+
});
|
|
536
578
|
if (!cwd) {
|
|
537
579
|
_configPromise = promise;
|
|
538
580
|
promise.then((c) => {
|
package/dist/craft-entry.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{ek as Nj,fk as wj,gk as Aj}from"./chunk-pcvayb2f.js";import{ik as Uj,jk as Xj,kk as Yj,lk as Zj,mk as _j,nk as $j,ok as qj,pk as Fj,qk as Oj,rk as Vj,sk as Ij,tk as Qj,uk as Wj,vk as Kj}from"./chunk-gfc3qye3.js";import"./chunk-39qzhpn6.js";import"./chunk-hay1rzb0.js";import"./chunk-2h94c5hm.js";import"./chunk-8jam44my.js";import"./chunk-t51mwjyq.js";import"./chunk-wfffa8zm.js";import"./chunk-54f8bpp6.js";import"./chunk-4evbx7sz.js";import"./chunk-jxxv18a0.js";import"./chunk-c131k3mt.js";import"./chunk-hgjjnjas.js";import"./chunk-nqq7y7m9.js";import"./chunk-1c2j4eby.js";import"./chunk-kxavsh3m.js";import"./chunk-qev11kg8.js";import"./chunk-rrankpmj.js";import"./chunk-fczfdsab.js";import"./chunk-fp7ms6e7.js";import"./chunk-jp2f8yzw.js";var I=new Map,Q=new Map;function L(j,B){let G=B?.id||g(j),J=h(j),U=I.get(G);if(U&&U.hash===J)return U;let X=S(j),Z=y(j),Y=T(j),_=v(X),{staticParts:q,dynamicParts:$}=C(X),F=u(j),O={id:G,hash:J,tree:X,scripts:Z,styles:Y,staticParts:q,dynamicParts:$,dependencies:F,metadata:_};return I.set(G,O),O}async function r(j,B={},G={}){let J=performance.now();if(G.cache){let Y=`${j.id}:${JSON.stringify(B)}`,_=Q.get(Y);if(_&&Date.now()-_.timestamp<(G.cacheTTL||60000))return{html:_.html,styles:j.styles.join(`
|
|
3
3
|
`),scripts:j.scripts.join(`
|
|
4
4
|
`),metadata:{renderTime:0,cacheHit:!0,totalSize:_.html.length,componentCount:j.metadata.componentCount}}}let U;if(G.streaming)U=await H(j.tree,B);else U=W(j.tree,B);let X;if(G.hydrate){let Y=k(U,j,B);U=Y.html,X=Y.data}if(G.minify)U=x(U);if(G.cache){let Y=`${j.id}:${JSON.stringify(B)}`;Q.set(Y,{html:U,timestamp:Date.now()})}let Z=performance.now()-J;return{html:U,styles:j.styles.join(`
|
|
5
5
|
`),scripts:j.scripts.join(`
|
package/dist/craft.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{ek as Nj,fk as wj,gk as Aj}from"./chunk-pcvayb2f.js";import{ik as Uj,jk as Xj,kk as Yj,lk as Zj,mk as _j,nk as $j,ok as qj,pk as Fj,qk as Oj,rk as Vj,sk as Ij,tk as Qj,uk as Wj,vk as Kj}from"./chunk-gfc3qye3.js";import"./chunk-39qzhpn6.js";import"./chunk-hay1rzb0.js";import"./chunk-2h94c5hm.js";import"./chunk-8jam44my.js";import"./chunk-t51mwjyq.js";import"./chunk-wfffa8zm.js";import"./chunk-54f8bpp6.js";import"./chunk-4evbx7sz.js";import"./chunk-jxxv18a0.js";import"./chunk-c131k3mt.js";import"./chunk-hgjjnjas.js";import"./chunk-nqq7y7m9.js";import"./chunk-1c2j4eby.js";import"./chunk-kxavsh3m.js";import"./chunk-qev11kg8.js";import"./chunk-rrankpmj.js";import"./chunk-fczfdsab.js";import"./chunk-fp7ms6e7.js";import"./chunk-jp2f8yzw.js";var I=new Map,Q=new Map;function L(j,B){let G=B?.id||g(j),J=h(j),U=I.get(G);if(U&&U.hash===J)return U;let X=S(j),Z=y(j),Y=T(j),_=v(X),{staticParts:q,dynamicParts:$}=C(X),F=u(j),O={id:G,hash:J,tree:X,scripts:Z,styles:Y,staticParts:q,dynamicParts:$,dependencies:F,metadata:_};return I.set(G,O),O}async function r(j,B={},G={}){let J=performance.now();if(G.cache){let Y=`${j.id}:${JSON.stringify(B)}`,_=Q.get(Y);if(_&&Date.now()-_.timestamp<(G.cacheTTL||60000))return{html:_.html,styles:j.styles.join(`
|
|
3
3
|
`),scripts:j.scripts.join(`
|
|
4
4
|
`),metadata:{renderTime:0,cacheHit:!0,totalSize:_.html.length,componentCount:j.metadata.componentCount}}}let U;if(G.streaming)U=await H(j.tree,B);else U=W(j.tree,B);let X;if(G.hydrate){let Y=k(U,j,B);U=Y.html,X=Y.data}if(G.minify)U=x(U);if(G.cache){let Y=`${j.id}:${JSON.stringify(B)}`;Q.set(Y,{html:U,timestamp:Date.now()})}let Z=performance.now()-J;return{html:U,styles:j.styles.join(`
|
|
5
5
|
`),scripts:j.scripts.join(`
|
package/dist/database.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{wv as Q}from"./chunk-ddqkj56r.js";var $={default:"sqlite",connections:{},logging:!1,cacheTTL:0,maxCacheSize:1000},V={},A={},L=new Map,S=[];function i(z){$={...$,...z}}function o(){return{...$}}function r(){$={default:"sqlite",connections:{},logging:!1,cacheTTL:0,maxCacheSize:1000};for(let z of Object.keys(V))delete V[z];L.clear(),S.length=0}function a(z,H){V[z]=H}function F(z){let H=z||$.default;if(V[H])return V[H];let U=$.connections[H];if(!U)throw Error(`Database connection "${H}" not configured`);let W=h(U);return V[H]=W,W}function h(z){switch(z.driver){case"sqlite":return q(z);case"postgres":return y(z);case"mysql":return f(z);default:throw Error(`Unsupported database driver: ${z.driver}`)}}function q(z){let H=null,U=!1;return{async connect(){if(U)return;let{Database:W}=await import("bun:sqlite");H=new W(z.database,{create:!0,readwrite:!0}),U=!0},async disconnect(){if(H)H.close(),H=null,U=!1},async query(W,J=[]){if(!U)await this.connect();let X=performance.now();try{let Y=H.prepare(W).all(...J);if($.logging)B(W,J,performance.now()-X);return Y}catch(Z){throw new O(`Query failed: ${Z}`,W,J)}},async insert(W,J=[]){if(!U)await this.connect();let X=performance.now();try{let Y=H.prepare(W).run(...J);if($.logging)B(W,J,performance.now()-X);return Y.lastInsertRowid}catch(Z){throw new O(`Insert failed: ${Z}`,W,J)}},async execute(W,J=[]){if(!U)await this.connect();let X=performance.now();try{let Y=H.prepare(W).run(...J);if($.logging)B(W,J,performance.now()-X);return Y.changes}catch(Z){throw new O(`Execute failed: ${Z}`,W,J)}},async beginTransaction(){if(!U)await this.connect();H.run("BEGIN TRANSACTION")},async commit(){H.run("COMMIT")},async rollback(){H.run("ROLLBACK")},isConnected(){return U}}}function y(z){let H=!1,U=null;return{async connect(){if(H)return;try{let{Client:W}=await import("pg");U=new W({host:z.host||"localhost",port:z.port||5432,database:z.database,user:z.username,password:z.password,ssl:z.ssl}),await U.connect(),H=!0}catch(W){throw Error(`PostgreSQL connection failed. Install 'pg' package: ${W}`)}},async disconnect(){if(U)await U.end(),U=null,H=!1},async query(W,J=[]){if(!H)await this.connect();let X=performance.now();try{let Z=await U.query(W,J);if($.logging)B(W,J,performance.now()-X);return Z.rows}catch(Z){throw new O(`Query failed: ${Z}`,W,J)}},async insert(W,J=[]){if(!H)await this.connect();let X=performance.now();try{let Z=await U.query(`${W} RETURNING id`,J);if($.logging)B(W,J,performance.now()-X);return Z.rows[0]?.id}catch(Z){throw new O(`Insert failed: ${Z}`,W,J)}},async execute(W,J=[]){if(!H)await this.connect();let X=performance.now();try{let Z=await U.query(W,J);if($.logging)B(W,J,performance.now()-X);return Z.rowCount||0}catch(Z){throw new O(`Execute failed: ${Z}`,W,J)}},async beginTransaction(){if(!H)await this.connect();await U.query("BEGIN")},async commit(){await U.query("COMMIT")},async rollback(){await U.query("ROLLBACK")},isConnected(){return H}}}function f(z){let H=!1,U=null;return{async connect(){if(H)return;try{U=(await import("mysql2/promise")).createPool({host:z.host||"localhost",port:z.port||3306,database:z.database,user:z.username,password:z.password,waitForConnections:!0,connectionLimit:z.poolSize||10,queueLimit:0}),H=!0}catch(W){throw Error(`MySQL connection failed. Install 'mysql2' package: ${W}`)}},async disconnect(){if(U)await U.end(),U=null,H=!1},async query(W,J=[]){if(!H)await this.connect();let X=performance.now();try{let[Z]=await U.execute(W,J);if($.logging)B(W,J,performance.now()-X);return Z}catch(Z){throw new O(`Query failed: ${Z}`,W,J)}},async insert(W,J=[]){if(!H)await this.connect();let X=performance.now();try{let[Z]=await U.execute(W,J);if($.logging)B(W,J,performance.now()-X);return Z.insertId}catch(Z){throw new O(`Insert failed: ${Z}`,W,J)}},async execute(W,J=[]){if(!H)await this.connect();let X=performance.now();try{let[Z]=await U.execute(W,J);if($.logging)B(W,J,performance.now()-X);return Z.affectedRows||0}catch(Z){throw new O(`Execute failed: ${Z}`,W,J)}},async beginTransaction(){if(!H)await this.connect();let W=await U.getConnection();return await W.beginTransaction(),W},async commit(){await U.execute("COMMIT")},async rollback(){await U.execute("ROLLBACK")},isConnected(){return H}}}class D{_table="";_columns=["*"];_wheres=[];_orders=[];_joins=[];_groupBy=[];_having=[];_limit;_offset;_distinct=!1;_connection;_bindings=[];_modelDefinition;constructor(z){if(z)this._table=z}table(z){return this._table=z,this}from(z){return this.table(z)}connection(z){return this._connection=z,this}select(...z){return this._columns=z.length>0?z:["*"],this}addSelect(...z){if(this._columns[0]==="*")this._columns=z;else this._columns.push(...z);return this}distinct(){return this._distinct=!0,this}where(z,H,U){let W="=",J=H;if(U!==void 0)W=H,J=U;return this._wheres.push({column:z,operator:W,value:J,boolean:"and"}),this}orWhere(z,H,U){let W="=",J=H;if(U!==void 0)W=H,J=U;return this._wheres.push({column:z,operator:W,value:J,boolean:"or"}),this}whereIn(z,H){return this._wheres.push({column:z,operator:"in",value:H,boolean:"and"}),this}whereNotIn(z,H){return this._wheres.push({column:z,operator:"not in",value:H,boolean:"and"}),this}whereNull(z){return this._wheres.push({column:z,operator:"is null",value:null,boolean:"and"}),this}whereNotNull(z){return this._wheres.push({column:z,operator:"is not null",value:null,boolean:"and"}),this}whereBetween(z,H,U){return this._wheres.push({column:z,operator:"between",value:[H,U],boolean:"and"}),this}whereLike(z,H){return this._wheres.push({column:z,operator:"like",value:H,boolean:"and"}),this}join(z,H,U,W){return this._joins.push({type:"inner",table:z,first:H,operator:U,second:W}),this}leftJoin(z,H,U,W){return this._joins.push({type:"left",table:z,first:H,operator:U,second:W}),this}rightJoin(z,H,U,W){return this._joins.push({type:"right",table:z,first:H,operator:U,second:W}),this}orderBy(z,H="asc"){return this._orders.push({column:z,direction:H}),this}orderByDesc(z){return this.orderBy(z,"desc")}groupBy(...z){return this._groupBy.push(...z),this}having(z,H,U){return this._having.push({column:z,operator:H,value:U,boolean:"and"}),this}limit(z){return this._limit=z,this}take(z){return this.limit(z)}offset(z){return this._offset=z,this}skip(z){return this.offset(z)}forPage(z,H=15){return this.offset((z-1)*H).limit(H)}async get(){let{sql:z,bindings:H}=this.toSql();if($.cacheTTL&&$.cacheTTL>0){let J=this.getCacheKey(z,H),X=g(J);if(X!==void 0)return X}let W=await F(this._connection).query(z,H);if($.cacheTTL&&$.cacheTTL>0){let J=this.getCacheKey(z,H);m(J,W,$.cacheTTL)}return W}async first(){return(await this.limit(1).get())[0]||null}async firstOrFail(){let z=await this.first();if(!z)throw Error("No results found");return z}async find(z,H="id"){return this.where(H,z).first()}async value(z){let H=await this.select(z).first();return H?H[z]:null}async pluck(z){return(await this.select(z).get()).map((U)=>U[z])}async exists(){return(await this.select(E("1")).limit(1).get()).length>0}async doesntExist(){return!await this.exists()}async count(z="*"){let H=await this.select(E(`COUNT(${z}) as count`)).first();return Number(H?.count||0)}async max(z){return(await this.select(E(`MAX(${z}) as max`)).first())?.max}async min(z){return(await this.select(E(`MIN(${z}) as min`)).first())?.min}async sum(z){let H=await this.select(E(`SUM(${z}) as sum`)).first();return Number(H?.sum||0)}async avg(z){return(await this.select(E(`AVG(${z}) as avg`)).first())?.avg}async insert(z){let H=Object.keys(z),U=H.map(()=>"?").join(", "),W=Object.values(z),J=`INSERT INTO ${this._table} (${H.join(", ")}) VALUES (${U})`,X=F(this._connection);return P(this._table),X.insert(J,W)}async insertAll(z){if(z.length===0)return;let H=Object.keys(z[0]),U=z.map(()=>`(${H.map(()=>"?").join(", ")})`).join(", "),W=z.flatMap((Z)=>Object.values(Z)),J=`INSERT INTO ${this._table} (${H.join(", ")}) VALUES ${U}`,X=F(this._connection);P(this._table),await X.execute(J,W)}async update(z){this._bindings=[];let H=this.buildWhereClause(),U=[...this._bindings],W=Object.keys(z).map((Y)=>`${Y} = ?`).join(", "),J=[...Object.values(z),...U],X=`UPDATE ${this._table} SET ${W}${H}`,Z=F(this._connection);return P(this._table),Z.execute(X,J)}async increment(z,H=1){this._bindings=[];let U=this.buildWhereClause(),W=`UPDATE ${this._table} SET ${z} = ${z} + ?${U}`,J=F(this._connection);return P(this._table),J.execute(W,[H,...this._bindings])}async decrement(z,H=1){return this.increment(z,-H)}async delete(){this._bindings=[];let z=this.buildWhereClause(),H=`DELETE FROM ${this._table}${z}`,U=F(this._connection);return P(this._table),U.execute(H,this._bindings)}async truncate(){let z=F(this._connection);P(this._table),await z.execute(`DELETE FROM ${this._table}`)}toSql(){this._bindings=[];let z="SELECT ";if(this._distinct)z+="DISTINCT ";z+=this._columns.map((H)=>{if(typeof H==="object"&&H.__raw)return H.sql;return H}).join(", "),z+=` FROM ${this._table}`;for(let H of this._joins)z+=` ${H.type.toUpperCase()} JOIN ${H.table} ON ${H.first} ${H.operator} ${H.second}`;if(z+=this.buildWhereClause(),this._groupBy.length>0)z+=` GROUP BY ${this._groupBy.join(", ")}`;if(this._having.length>0){let H=this._having.map((U,W)=>{let J=W===0?"":` ${U.boolean.toUpperCase()} `;return this._bindings.push(U.value),`${J}${U.column} ${U.operator} ?`});z+=` HAVING ${H.join("")}`}if(this._orders.length>0)z+=` ORDER BY ${this._orders.map((H)=>`${H.column} ${H.direction.toUpperCase()}`).join(", ")}`;if(this._limit!==void 0)z+=` LIMIT ${this._limit}`;if(this._offset!==void 0)z+=` OFFSET ${this._offset}`;return{sql:z,bindings:this._bindings}}buildWhereClause(){if(this._wheres.length===0)return"";return this._wheres.map((H,U)=>{let W=U===0?" WHERE ":` ${H.boolean.toUpperCase()} `;switch(H.operator){case"in":{let J=H.value,X=J.map(()=>"?").join(", ");return this._bindings.push(...J),`${W}${H.column} IN (${X})`}case"not in":{let J=H.value,X=J.map(()=>"?").join(", ");return this._bindings.push(...J),`${W}${H.column} NOT IN (${X})`}case"between":{let[J,X]=H.value;return this._bindings.push(J,X),`${W}${H.column} BETWEEN ? AND ?`}case"is null":return`${W}${H.column} IS NULL`;case"is not null":return`${W}${H.column} IS NOT NULL`;default:return this._bindings.push(H.value),`${W}${H.column} ${H.operator} ?`}}).join("")}getCacheKey(z,H){return`${this._table}:${z}:${JSON.stringify(H)}`}clone(){let z=new D(this._table);return z._columns=[...this._columns],z._wheres=[...this._wheres],z._orders=[...this._orders],z._joins=[...this._joins],z._groupBy=[...this._groupBy],z._having=[...this._having],z._limit=this._limit,z._offset=this._offset,z._distinct=this._distinct,z._connection=this._connection,z}}function G(z){return new D(z)}function t(z){return G(z)}function E(z,H=[]){return{__raw:!0,sql:z,bindings:H}}function n(z,H){let U=H.primaryKey||"id",W={name:z,definition:H,async find(J){let X=await G(H.table).where(U,J).first();return X?N(W,X):null},async findOrFail(J){let X=await this.find(J);if(!X)throw Error(`${z} not found with ${U} = ${J}`);return X},async all(){return(await G(H.table).get()).map((X)=>N(W,X))},async create(J){let X={...H.defaults,...J},Z=H.fillable?Object.fromEntries(Object.entries(X).filter(([_])=>H.fillable.includes(_))):X;if(H.timestamps!==!1){let _=new Date().toISOString(),R=typeof H.timestamps==="object"?H.timestamps.createdAt||"created_at":"created_at",T=typeof H.timestamps==="object"?H.timestamps.updatedAt||"updated_at":"updated_at";Z[R]=_,Z[T]=_}let Y=await G(H.table).insert(Z);return this.findOrFail(Y)},async update(J){return G(H.table).update(J)},async destroy(J){let X=Array.isArray(J)?J:[J];return G(H.table).whereIn(U,X).delete()},query(){return G(H.table)},where(J,X,Z){return this.query().where(J,X,Z)},async first(){let J=await this.query().first();return J?N(W,J):null},async get(){return(await this.query().get()).map((X)=>N(W,X))},async count(){return this.query().count()}};return A[z]=W,W}function k(z){let H=A[z];if(!H)throw Error(`Model "${z}" not defined. Use defineModel() first.`);return H}function e(z){return z in A}function N(z,H){let{definition:U}=z,W=U.primaryKey||"id",J={...H},X={...H};if(U.casts){for(let[Y,_]of Object.entries(U.casts))if(Y in X)X[Y]=p(X[Y],_)}let Z={exists:!0,original:J,attributes:X,get(Y){return X[Y]},set(Y,_){X[Y]=_},toJSON(){let Y={...X};if(U.hidden)for(let _ of U.hidden)delete Y[_];return Y},async save(){let Y={};for(let _ of Object.keys(X))if(X[_]!==J[_])Y[_]=X[_];if(Object.keys(Y).length>0){if(U.timestamps!==!1){let _=typeof U.timestamps==="object"?U.timestamps.updatedAt||"updated_at":"updated_at";Y[_]=new Date().toISOString()}await G(U.table).where(W,J[W]).update(Y),Object.assign(J,Y)}},async delete(){if(U.softDeletes){let Y=typeof U.softDeletes==="string"?U.softDeletes:"deleted_at";await G(U.table).where(W,J[W]).update({[Y]:new Date().toISOString()})}else await G(U.table).where(W,J[W]).delete();Z.exists=!1},async refresh(){let Y=await G(U.table).where(W,J[W]).first();if(Y)Object.assign(J,Y),Object.assign(X,Y)},isDirty(Y){if(Y)return X[Y]!==J[Y];return Object.keys(X).some((_)=>X[_]!==J[_])}};if(U.relationships)for(let[Y,_]of Object.entries(U.relationships))Object.defineProperty(Z,Y,{value:async()=>{return b(Z,_,z)},enumerable:!1});return new Proxy(Z,{get(Y,_){if(_ in Y)return Y[_];return X[_]},set(Y,_,R){if(_ in Y)Y[_]=R;else X[_]=R;return!0}})}async function b(z,H,U){let W=k(H.model),J=U.definition.primaryKey||"id";switch(H.type){case"hasOne":{let X=H.foreignKey||`${U.name.toLowerCase()}_id`,Z=await G(W.definition.table).where(X,z.get(J)).first();return Z?N(W,Z):null}case"hasMany":{let X=H.foreignKey||`${U.name.toLowerCase()}_id`;return(await G(W.definition.table).where(X,z.get(J)).get()).map((Y)=>N(W,Y))}case"belongsTo":{let X=H.foreignKey||`${H.model.toLowerCase()}_id`,Z=H.localKey||"id",Y=await G(W.definition.table).where(Z,z.get(X)).first();return Y?N(W,Y):null}case"belongsToMany":{let X=H.pivotTable||[U.name,H.model].sort().join("_").toLowerCase(),Z=H.pivotForeignKey||`${U.name.toLowerCase()}_id`,Y=H.pivotRelatedKey||`${H.model.toLowerCase()}_id`,_=W.definition.primaryKey||"id";return(await G(W.definition.table).join(X,`${W.definition.table}.${_}`,"=",`${X}.${Y}`).where(`${X}.${Z}`,z.get(J)).get()).map((T)=>N(W,T))}default:return null}}function p(z,H){if(z===null||z===void 0)return z;switch(H){case"string":return String(z);case"number":return Number(z);case"boolean":return Boolean(z);case"date":return new Date(z);case"json":case"array":return typeof z==="string"?JSON.parse(z):z;default:return z}}async function zz(z,H){let U=F(H);await U.beginTransaction();try{let W=await z();return await U.commit(),W}catch(W){throw await U.rollback(),W}}function g(z){let H=L.get(z);if(!H)return;if(Date.now()-H.timestamp>H.ttl*1000){L.delete(z);return}return H.result}function m(z,H,U){if(L.size>=($.maxCacheSize||1000)){let W=L.keys().next().value;if(W)L.delete(W)}L.set(z,{result:H,timestamp:Date.now(),ttl:U})}function P(z){for(let H of L.keys())if(H.startsWith(`${z}:`))L.delete(H)}function Hz(){L.clear()}function Jz(){return{size:L.size,keys:[...L.keys()]}}function B(z,H,U){if(S.push({sql:z,bindings:H,duration:U,timestamp:new Date}),S.length>1000)S.shift()}function Uz(){return[...S]}function Wz(){S.length=0}function Xz(z=!0){$.logging=z}class O extends Error{sql;bindings;constructor(z,H,U){super(z);this.sql=H;this.bindings=U;this.name="DatabaseError"}}async function u(z,H,U,W){let J=/@db\(\s*['"]([^'"]+)['"]\s*\)((?:->\w+\([^)]*\))*)/g,X=z,Z=[...z.matchAll(J)];for(let Y of Z){let[_,R,T]=Y;try{let j=await s(R,T),I=`$${R}`;H[I]=j,X=X.replace(_,"")}catch(j){X=X.replace(_,`<!-- DB Error: ${j instanceof Error?j.message:String(j)} -->`)}}return X}async function d(z,H,U,W){let J=/@model\(\s*['"]([^'"]+)['"]\s*\)((?:->\w+\([^)]*\))*)/g,X=z,Z=[...z.matchAll(J)];for(let Y of Z){let[_,R,T]=Y;try{let j=k(R),I=await l(j,T),K=`$${R.toLowerCase()}`;H[K]=I,X=X.replace(_,"")}catch(j){X=X.replace(_,`<!-- Model Error: ${j instanceof Error?j.message:String(j)} -->`)}}return X}async function c(z,H,U,W){let J=/@query\(\s*['"]([^'"]+)['"]\s*(?:,\s*(\[[^\]]*\]))?\s*\)\s*as\s+\$(\w+)/g,X=z,Z=[...z.matchAll(J)];for(let Y of Z){let[_,R,T,j]=Y;try{let I=T?JSON.parse(T):[],v=await F().query(R,I);H[`$${j}`]=v,X=X.replace(_,"")}catch(I){X=X.replace(_,`<!-- Query Error: ${I instanceof Error?I.message:String(I)} -->`)}}return X}async function s(z,H){let U=G(z),W=/->(\w+)\(([^)]*)\)/g,J=[...H.matchAll(W)],X=U;for(let[,Z,Y]of J){let _=M(Y);if(typeof X[Z]==="function"){if(X=X[Z](..._),X instanceof Promise){X=await X;break}}}if(X instanceof D)X=await X.get();return X}async function l(z,H){let U=/->(\w+)\(([^)]*)\)/g,W=[...H.matchAll(U)],J=z;for(let[,X,Z]of W){let Y=M(Z);if(typeof J[X]==="function"){if(J=J[X](...Y),J instanceof Promise)J=await J}else if(J instanceof D){if(typeof J[X]==="function"){if(J=J[X](...Y),J instanceof Promise)J=await J}}}if(J instanceof D)J=await J.get();return J}function M(z){if(!z.trim())return[];let H=[],U="",W=0,J=!1,X="";for(let Z=0;Z<z.length;Z++){let Y=z[Z];if(!J&&(Y==='"'||Y==="'"))J=!0,X=Y,U+=Y;else if(J&&Y===X)J=!1,U+=Y;else if(!J&&(Y==="["||Y==="{"||Y==="("))W++,U+=Y;else if(!J&&(Y==="]"||Y==="}"||Y===")"))W--,U+=Y;else if(!J&&W===0&&Y===",")H.push(x(U.trim())),U="";else U+=Y}if(U.trim())H.push(x(U.trim()));return H}function x(z){if(z.startsWith('"')&&z.endsWith('"')||z.startsWith("'")&&z.endsWith("'"))return z.slice(1,-1);if(z==="true")return!0;if(z==="false")return!1;if(z==="null")return null;let H=Number(z);if(!Number.isNaN(H))return H;try{return JSON.parse(z)}catch{return z}}async function Yz(z,H,U,W){let J=z;return J=await c(J,H,U,W),J=await d(J,H,U,W),J=await u(J,H,U,W),J}class w{_connection;connection(z){return this._connection=z,this}async create(z,H){let U=new C(z);H(U);let W=U.toCreateSQL();await F(this._connection).execute(W)}async drop(z){await F(this._connection).execute(`DROP TABLE IF EXISTS ${z}`)}async rename(z,H){await F(this._connection).execute(`ALTER TABLE ${z} RENAME TO ${H}`)}async hasTable(z){let H=F(this._connection);try{return await H.query(`SELECT 1 FROM ${z} LIMIT 1`),!0}catch{return!1}}}class C{table;columns=[];indices=[];constructor(z){this.table=z}id(z="id"){return this.columns.push(`${z} INTEGER PRIMARY KEY AUTOINCREMENT`),this}string(z,H=255){return this.columns.push(`${z} VARCHAR(${H})`),this}text(z){return this.columns.push(`${z} TEXT`),this}integer(z){return this.columns.push(`${z} INTEGER`),this}boolean(z){return this.columns.push(`${z} BOOLEAN DEFAULT 0`),this}datetime(z){return this.columns.push(`${z} 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(z){return this.columns.push(`${z} TEXT`),this}foreignId(z){return this.columns.push(`${z} INTEGER`),this}index(z){let H=Array.isArray(z)?z:[z],U=`idx_${this.table}_${H.join("_")}`;return this.indices.push(`CREATE INDEX ${U} ON ${this.table} (${H.join(", ")})`),this}unique(z){let H=Array.isArray(z)?z:[z],U=`uniq_${this.table}_${H.join("_")}`;return this.indices.push(`CREATE UNIQUE INDEX ${U} ON ${this.table} (${H.join(", ")})`),this}toCreateSQL(){return`CREATE TABLE IF NOT EXISTS ${this.table} (
|
|
2
|
+
import{cw as Q}from"./chunk-jp2f8yzw.js";var $={default:"sqlite",connections:{},logging:!1,cacheTTL:0,maxCacheSize:1000},V={},A={},L=new Map,S=[];function i(z){$={...$,...z}}function o(){return{...$}}function r(){$={default:"sqlite",connections:{},logging:!1,cacheTTL:0,maxCacheSize:1000};for(let z of Object.keys(V))delete V[z];L.clear(),S.length=0}function a(z,H){V[z]=H}function F(z){let H=z||$.default;if(V[H])return V[H];let U=$.connections[H];if(!U)throw Error(`Database connection "${H}" not configured`);let W=h(U);return V[H]=W,W}function h(z){switch(z.driver){case"sqlite":return q(z);case"postgres":return y(z);case"mysql":return f(z);default:throw Error(`Unsupported database driver: ${z.driver}`)}}function q(z){let H=null,U=!1;return{async connect(){if(U)return;let{Database:W}=await import("bun:sqlite");H=new W(z.database,{create:!0,readwrite:!0}),U=!0},async disconnect(){if(H)H.close(),H=null,U=!1},async query(W,J=[]){if(!U)await this.connect();let X=performance.now();try{let Y=H.prepare(W).all(...J);if($.logging)B(W,J,performance.now()-X);return Y}catch(Z){throw new O(`Query failed: ${Z}`,W,J)}},async insert(W,J=[]){if(!U)await this.connect();let X=performance.now();try{let Y=H.prepare(W).run(...J);if($.logging)B(W,J,performance.now()-X);return Y.lastInsertRowid}catch(Z){throw new O(`Insert failed: ${Z}`,W,J)}},async execute(W,J=[]){if(!U)await this.connect();let X=performance.now();try{let Y=H.prepare(W).run(...J);if($.logging)B(W,J,performance.now()-X);return Y.changes}catch(Z){throw new O(`Execute failed: ${Z}`,W,J)}},async beginTransaction(){if(!U)await this.connect();H.run("BEGIN TRANSACTION")},async commit(){H.run("COMMIT")},async rollback(){H.run("ROLLBACK")},isConnected(){return U}}}function y(z){let H=!1,U=null;return{async connect(){if(H)return;try{let{Client:W}=await import("pg");U=new W({host:z.host||"localhost",port:z.port||5432,database:z.database,user:z.username,password:z.password,ssl:z.ssl}),await U.connect(),H=!0}catch(W){throw Error(`PostgreSQL connection failed. Install 'pg' package: ${W}`)}},async disconnect(){if(U)await U.end(),U=null,H=!1},async query(W,J=[]){if(!H)await this.connect();let X=performance.now();try{let Z=await U.query(W,J);if($.logging)B(W,J,performance.now()-X);return Z.rows}catch(Z){throw new O(`Query failed: ${Z}`,W,J)}},async insert(W,J=[]){if(!H)await this.connect();let X=performance.now();try{let Z=await U.query(`${W} RETURNING id`,J);if($.logging)B(W,J,performance.now()-X);return Z.rows[0]?.id}catch(Z){throw new O(`Insert failed: ${Z}`,W,J)}},async execute(W,J=[]){if(!H)await this.connect();let X=performance.now();try{let Z=await U.query(W,J);if($.logging)B(W,J,performance.now()-X);return Z.rowCount||0}catch(Z){throw new O(`Execute failed: ${Z}`,W,J)}},async beginTransaction(){if(!H)await this.connect();await U.query("BEGIN")},async commit(){await U.query("COMMIT")},async rollback(){await U.query("ROLLBACK")},isConnected(){return H}}}function f(z){let H=!1,U=null;return{async connect(){if(H)return;try{U=(await import("mysql2/promise")).createPool({host:z.host||"localhost",port:z.port||3306,database:z.database,user:z.username,password:z.password,waitForConnections:!0,connectionLimit:z.poolSize||10,queueLimit:0}),H=!0}catch(W){throw Error(`MySQL connection failed. Install 'mysql2' package: ${W}`)}},async disconnect(){if(U)await U.end(),U=null,H=!1},async query(W,J=[]){if(!H)await this.connect();let X=performance.now();try{let[Z]=await U.execute(W,J);if($.logging)B(W,J,performance.now()-X);return Z}catch(Z){throw new O(`Query failed: ${Z}`,W,J)}},async insert(W,J=[]){if(!H)await this.connect();let X=performance.now();try{let[Z]=await U.execute(W,J);if($.logging)B(W,J,performance.now()-X);return Z.insertId}catch(Z){throw new O(`Insert failed: ${Z}`,W,J)}},async execute(W,J=[]){if(!H)await this.connect();let X=performance.now();try{let[Z]=await U.execute(W,J);if($.logging)B(W,J,performance.now()-X);return Z.affectedRows||0}catch(Z){throw new O(`Execute failed: ${Z}`,W,J)}},async beginTransaction(){if(!H)await this.connect();let W=await U.getConnection();return await W.beginTransaction(),W},async commit(){await U.execute("COMMIT")},async rollback(){await U.execute("ROLLBACK")},isConnected(){return H}}}class D{_table="";_columns=["*"];_wheres=[];_orders=[];_joins=[];_groupBy=[];_having=[];_limit;_offset;_distinct=!1;_connection;_bindings=[];_modelDefinition;constructor(z){if(z)this._table=z}table(z){return this._table=z,this}from(z){return this.table(z)}connection(z){return this._connection=z,this}select(...z){return this._columns=z.length>0?z:["*"],this}addSelect(...z){if(this._columns[0]==="*")this._columns=z;else this._columns.push(...z);return this}distinct(){return this._distinct=!0,this}where(z,H,U){let W="=",J=H;if(U!==void 0)W=H,J=U;return this._wheres.push({column:z,operator:W,value:J,boolean:"and"}),this}orWhere(z,H,U){let W="=",J=H;if(U!==void 0)W=H,J=U;return this._wheres.push({column:z,operator:W,value:J,boolean:"or"}),this}whereIn(z,H){return this._wheres.push({column:z,operator:"in",value:H,boolean:"and"}),this}whereNotIn(z,H){return this._wheres.push({column:z,operator:"not in",value:H,boolean:"and"}),this}whereNull(z){return this._wheres.push({column:z,operator:"is null",value:null,boolean:"and"}),this}whereNotNull(z){return this._wheres.push({column:z,operator:"is not null",value:null,boolean:"and"}),this}whereBetween(z,H,U){return this._wheres.push({column:z,operator:"between",value:[H,U],boolean:"and"}),this}whereLike(z,H){return this._wheres.push({column:z,operator:"like",value:H,boolean:"and"}),this}join(z,H,U,W){return this._joins.push({type:"inner",table:z,first:H,operator:U,second:W}),this}leftJoin(z,H,U,W){return this._joins.push({type:"left",table:z,first:H,operator:U,second:W}),this}rightJoin(z,H,U,W){return this._joins.push({type:"right",table:z,first:H,operator:U,second:W}),this}orderBy(z,H="asc"){return this._orders.push({column:z,direction:H}),this}orderByDesc(z){return this.orderBy(z,"desc")}groupBy(...z){return this._groupBy.push(...z),this}having(z,H,U){return this._having.push({column:z,operator:H,value:U,boolean:"and"}),this}limit(z){return this._limit=z,this}take(z){return this.limit(z)}offset(z){return this._offset=z,this}skip(z){return this.offset(z)}forPage(z,H=15){return this.offset((z-1)*H).limit(H)}async get(){let{sql:z,bindings:H}=this.toSql();if($.cacheTTL&&$.cacheTTL>0){let J=this.getCacheKey(z,H),X=g(J);if(X!==void 0)return X}let W=await F(this._connection).query(z,H);if($.cacheTTL&&$.cacheTTL>0){let J=this.getCacheKey(z,H);m(J,W,$.cacheTTL)}return W}async first(){return(await this.limit(1).get())[0]||null}async firstOrFail(){let z=await this.first();if(!z)throw Error("No results found");return z}async find(z,H="id"){return this.where(H,z).first()}async value(z){let H=await this.select(z).first();return H?H[z]:null}async pluck(z){return(await this.select(z).get()).map((U)=>U[z])}async exists(){return(await this.select(E("1")).limit(1).get()).length>0}async doesntExist(){return!await this.exists()}async count(z="*"){let H=await this.select(E(`COUNT(${z}) as count`)).first();return Number(H?.count||0)}async max(z){return(await this.select(E(`MAX(${z}) as max`)).first())?.max}async min(z){return(await this.select(E(`MIN(${z}) as min`)).first())?.min}async sum(z){let H=await this.select(E(`SUM(${z}) as sum`)).first();return Number(H?.sum||0)}async avg(z){return(await this.select(E(`AVG(${z}) as avg`)).first())?.avg}async insert(z){let H=Object.keys(z),U=H.map(()=>"?").join(", "),W=Object.values(z),J=`INSERT INTO ${this._table} (${H.join(", ")}) VALUES (${U})`,X=F(this._connection);return P(this._table),X.insert(J,W)}async insertAll(z){if(z.length===0)return;let H=Object.keys(z[0]),U=z.map(()=>`(${H.map(()=>"?").join(", ")})`).join(", "),W=z.flatMap((Z)=>Object.values(Z)),J=`INSERT INTO ${this._table} (${H.join(", ")}) VALUES ${U}`,X=F(this._connection);P(this._table),await X.execute(J,W)}async update(z){this._bindings=[];let H=this.buildWhereClause(),U=[...this._bindings],W=Object.keys(z).map((Y)=>`${Y} = ?`).join(", "),J=[...Object.values(z),...U],X=`UPDATE ${this._table} SET ${W}${H}`,Z=F(this._connection);return P(this._table),Z.execute(X,J)}async increment(z,H=1){this._bindings=[];let U=this.buildWhereClause(),W=`UPDATE ${this._table} SET ${z} = ${z} + ?${U}`,J=F(this._connection);return P(this._table),J.execute(W,[H,...this._bindings])}async decrement(z,H=1){return this.increment(z,-H)}async delete(){this._bindings=[];let z=this.buildWhereClause(),H=`DELETE FROM ${this._table}${z}`,U=F(this._connection);return P(this._table),U.execute(H,this._bindings)}async truncate(){let z=F(this._connection);P(this._table),await z.execute(`DELETE FROM ${this._table}`)}toSql(){this._bindings=[];let z="SELECT ";if(this._distinct)z+="DISTINCT ";z+=this._columns.map((H)=>{if(typeof H==="object"&&H.__raw)return H.sql;return H}).join(", "),z+=` FROM ${this._table}`;for(let H of this._joins)z+=` ${H.type.toUpperCase()} JOIN ${H.table} ON ${H.first} ${H.operator} ${H.second}`;if(z+=this.buildWhereClause(),this._groupBy.length>0)z+=` GROUP BY ${this._groupBy.join(", ")}`;if(this._having.length>0){let H=this._having.map((U,W)=>{let J=W===0?"":` ${U.boolean.toUpperCase()} `;return this._bindings.push(U.value),`${J}${U.column} ${U.operator} ?`});z+=` HAVING ${H.join("")}`}if(this._orders.length>0)z+=` ORDER BY ${this._orders.map((H)=>`${H.column} ${H.direction.toUpperCase()}`).join(", ")}`;if(this._limit!==void 0)z+=` LIMIT ${this._limit}`;if(this._offset!==void 0)z+=` OFFSET ${this._offset}`;return{sql:z,bindings:this._bindings}}buildWhereClause(){if(this._wheres.length===0)return"";return this._wheres.map((H,U)=>{let W=U===0?" WHERE ":` ${H.boolean.toUpperCase()} `;switch(H.operator){case"in":{let J=H.value,X=J.map(()=>"?").join(", ");return this._bindings.push(...J),`${W}${H.column} IN (${X})`}case"not in":{let J=H.value,X=J.map(()=>"?").join(", ");return this._bindings.push(...J),`${W}${H.column} NOT IN (${X})`}case"between":{let[J,X]=H.value;return this._bindings.push(J,X),`${W}${H.column} BETWEEN ? AND ?`}case"is null":return`${W}${H.column} IS NULL`;case"is not null":return`${W}${H.column} IS NOT NULL`;default:return this._bindings.push(H.value),`${W}${H.column} ${H.operator} ?`}}).join("")}getCacheKey(z,H){return`${this._table}:${z}:${JSON.stringify(H)}`}clone(){let z=new D(this._table);return z._columns=[...this._columns],z._wheres=[...this._wheres],z._orders=[...this._orders],z._joins=[...this._joins],z._groupBy=[...this._groupBy],z._having=[...this._having],z._limit=this._limit,z._offset=this._offset,z._distinct=this._distinct,z._connection=this._connection,z}}function G(z){return new D(z)}function t(z){return G(z)}function E(z,H=[]){return{__raw:!0,sql:z,bindings:H}}function n(z,H){let U=H.primaryKey||"id",W={name:z,definition:H,async find(J){let X=await G(H.table).where(U,J).first();return X?N(W,X):null},async findOrFail(J){let X=await this.find(J);if(!X)throw Error(`${z} not found with ${U} = ${J}`);return X},async all(){return(await G(H.table).get()).map((X)=>N(W,X))},async create(J){let X={...H.defaults,...J},Z=H.fillable?Object.fromEntries(Object.entries(X).filter(([_])=>H.fillable.includes(_))):X;if(H.timestamps!==!1){let _=new Date().toISOString(),R=typeof H.timestamps==="object"?H.timestamps.createdAt||"created_at":"created_at",T=typeof H.timestamps==="object"?H.timestamps.updatedAt||"updated_at":"updated_at";Z[R]=_,Z[T]=_}let Y=await G(H.table).insert(Z);return this.findOrFail(Y)},async update(J){return G(H.table).update(J)},async destroy(J){let X=Array.isArray(J)?J:[J];return G(H.table).whereIn(U,X).delete()},query(){return G(H.table)},where(J,X,Z){return this.query().where(J,X,Z)},async first(){let J=await this.query().first();return J?N(W,J):null},async get(){return(await this.query().get()).map((X)=>N(W,X))},async count(){return this.query().count()}};return A[z]=W,W}function k(z){let H=A[z];if(!H)throw Error(`Model "${z}" not defined. Use defineModel() first.`);return H}function e(z){return z in A}function N(z,H){let{definition:U}=z,W=U.primaryKey||"id",J={...H},X={...H};if(U.casts){for(let[Y,_]of Object.entries(U.casts))if(Y in X)X[Y]=p(X[Y],_)}let Z={exists:!0,original:J,attributes:X,get(Y){return X[Y]},set(Y,_){X[Y]=_},toJSON(){let Y={...X};if(U.hidden)for(let _ of U.hidden)delete Y[_];return Y},async save(){let Y={};for(let _ of Object.keys(X))if(X[_]!==J[_])Y[_]=X[_];if(Object.keys(Y).length>0){if(U.timestamps!==!1){let _=typeof U.timestamps==="object"?U.timestamps.updatedAt||"updated_at":"updated_at";Y[_]=new Date().toISOString()}await G(U.table).where(W,J[W]).update(Y),Object.assign(J,Y)}},async delete(){if(U.softDeletes){let Y=typeof U.softDeletes==="string"?U.softDeletes:"deleted_at";await G(U.table).where(W,J[W]).update({[Y]:new Date().toISOString()})}else await G(U.table).where(W,J[W]).delete();Z.exists=!1},async refresh(){let Y=await G(U.table).where(W,J[W]).first();if(Y)Object.assign(J,Y),Object.assign(X,Y)},isDirty(Y){if(Y)return X[Y]!==J[Y];return Object.keys(X).some((_)=>X[_]!==J[_])}};if(U.relationships)for(let[Y,_]of Object.entries(U.relationships))Object.defineProperty(Z,Y,{value:async()=>{return b(Z,_,z)},enumerable:!1});return new Proxy(Z,{get(Y,_){if(_ in Y)return Y[_];return X[_]},set(Y,_,R){if(_ in Y)Y[_]=R;else X[_]=R;return!0}})}async function b(z,H,U){let W=k(H.model),J=U.definition.primaryKey||"id";switch(H.type){case"hasOne":{let X=H.foreignKey||`${U.name.toLowerCase()}_id`,Z=await G(W.definition.table).where(X,z.get(J)).first();return Z?N(W,Z):null}case"hasMany":{let X=H.foreignKey||`${U.name.toLowerCase()}_id`;return(await G(W.definition.table).where(X,z.get(J)).get()).map((Y)=>N(W,Y))}case"belongsTo":{let X=H.foreignKey||`${H.model.toLowerCase()}_id`,Z=H.localKey||"id",Y=await G(W.definition.table).where(Z,z.get(X)).first();return Y?N(W,Y):null}case"belongsToMany":{let X=H.pivotTable||[U.name,H.model].sort().join("_").toLowerCase(),Z=H.pivotForeignKey||`${U.name.toLowerCase()}_id`,Y=H.pivotRelatedKey||`${H.model.toLowerCase()}_id`,_=W.definition.primaryKey||"id";return(await G(W.definition.table).join(X,`${W.definition.table}.${_}`,"=",`${X}.${Y}`).where(`${X}.${Z}`,z.get(J)).get()).map((T)=>N(W,T))}default:return null}}function p(z,H){if(z===null||z===void 0)return z;switch(H){case"string":return String(z);case"number":return Number(z);case"boolean":return Boolean(z);case"date":return new Date(z);case"json":case"array":return typeof z==="string"?JSON.parse(z):z;default:return z}}async function zz(z,H){let U=F(H);await U.beginTransaction();try{let W=await z();return await U.commit(),W}catch(W){throw await U.rollback(),W}}function g(z){let H=L.get(z);if(!H)return;if(Date.now()-H.timestamp>H.ttl*1000){L.delete(z);return}return H.result}function m(z,H,U){if(L.size>=($.maxCacheSize||1000)){let W=L.keys().next().value;if(W)L.delete(W)}L.set(z,{result:H,timestamp:Date.now(),ttl:U})}function P(z){for(let H of L.keys())if(H.startsWith(`${z}:`))L.delete(H)}function Hz(){L.clear()}function Jz(){return{size:L.size,keys:[...L.keys()]}}function B(z,H,U){if(S.push({sql:z,bindings:H,duration:U,timestamp:new Date}),S.length>1000)S.shift()}function Uz(){return[...S]}function Wz(){S.length=0}function Xz(z=!0){$.logging=z}class O extends Error{sql;bindings;constructor(z,H,U){super(z);this.sql=H;this.bindings=U;this.name="DatabaseError"}}async function u(z,H,U,W){let J=/@db\(\s*['"]([^'"]+)['"]\s*\)((?:->\w+\([^)]*\))*)/g,X=z,Z=[...z.matchAll(J)];for(let Y of Z){let[_,R,T]=Y;try{let j=await s(R,T),I=`$${R}`;H[I]=j,X=X.replace(_,"")}catch(j){X=X.replace(_,`<!-- DB Error: ${j instanceof Error?j.message:String(j)} -->`)}}return X}async function d(z,H,U,W){let J=/@model\(\s*['"]([^'"]+)['"]\s*\)((?:->\w+\([^)]*\))*)/g,X=z,Z=[...z.matchAll(J)];for(let Y of Z){let[_,R,T]=Y;try{let j=k(R),I=await l(j,T),K=`$${R.toLowerCase()}`;H[K]=I,X=X.replace(_,"")}catch(j){X=X.replace(_,`<!-- Model Error: ${j instanceof Error?j.message:String(j)} -->`)}}return X}async function c(z,H,U,W){let J=/@query\(\s*['"]([^'"]+)['"]\s*(?:,\s*(\[[^\]]*\]))?\s*\)\s*as\s+\$(\w+)/g,X=z,Z=[...z.matchAll(J)];for(let Y of Z){let[_,R,T,j]=Y;try{let I=T?JSON.parse(T):[],v=await F().query(R,I);H[`$${j}`]=v,X=X.replace(_,"")}catch(I){X=X.replace(_,`<!-- Query Error: ${I instanceof Error?I.message:String(I)} -->`)}}return X}async function s(z,H){let U=G(z),W=/->(\w+)\(([^)]*)\)/g,J=[...H.matchAll(W)],X=U;for(let[,Z,Y]of J){let _=M(Y);if(typeof X[Z]==="function"){if(X=X[Z](..._),X instanceof Promise){X=await X;break}}}if(X instanceof D)X=await X.get();return X}async function l(z,H){let U=/->(\w+)\(([^)]*)\)/g,W=[...H.matchAll(U)],J=z;for(let[,X,Z]of W){let Y=M(Z);if(typeof J[X]==="function"){if(J=J[X](...Y),J instanceof Promise)J=await J}else if(J instanceof D){if(typeof J[X]==="function"){if(J=J[X](...Y),J instanceof Promise)J=await J}}}if(J instanceof D)J=await J.get();return J}function M(z){if(!z.trim())return[];let H=[],U="",W=0,J=!1,X="";for(let Z=0;Z<z.length;Z++){let Y=z[Z];if(!J&&(Y==='"'||Y==="'"))J=!0,X=Y,U+=Y;else if(J&&Y===X)J=!1,U+=Y;else if(!J&&(Y==="["||Y==="{"||Y==="("))W++,U+=Y;else if(!J&&(Y==="]"||Y==="}"||Y===")"))W--,U+=Y;else if(!J&&W===0&&Y===",")H.push(x(U.trim())),U="";else U+=Y}if(U.trim())H.push(x(U.trim()));return H}function x(z){if(z.startsWith('"')&&z.endsWith('"')||z.startsWith("'")&&z.endsWith("'"))return z.slice(1,-1);if(z==="true")return!0;if(z==="false")return!1;if(z==="null")return null;let H=Number(z);if(!Number.isNaN(H))return H;try{return JSON.parse(z)}catch{return z}}async function Yz(z,H,U,W){let J=z;return J=await c(J,H,U,W),J=await d(J,H,U,W),J=await u(J,H,U,W),J}class w{_connection;connection(z){return this._connection=z,this}async create(z,H){let U=new C(z);H(U);let W=U.toCreateSQL();await F(this._connection).execute(W)}async drop(z){await F(this._connection).execute(`DROP TABLE IF EXISTS ${z}`)}async rename(z,H){await F(this._connection).execute(`ALTER TABLE ${z} RENAME TO ${H}`)}async hasTable(z){let H=F(this._connection);try{return await H.query(`SELECT 1 FROM ${z} LIMIT 1`),!0}catch{return!1}}}class C{table;columns=[];indices=[];constructor(z){this.table=z}id(z="id"){return this.columns.push(`${z} INTEGER PRIMARY KEY AUTOINCREMENT`),this}string(z,H=255){return this.columns.push(`${z} VARCHAR(${H})`),this}text(z){return this.columns.push(`${z} TEXT`),this}integer(z){return this.columns.push(`${z} INTEGER`),this}boolean(z){return this.columns.push(`${z} BOOLEAN DEFAULT 0`),this}datetime(z){return this.columns.push(`${z} 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(z){return this.columns.push(`${z} TEXT`),this}foreignId(z){return this.columns.push(`${z} INTEGER`),this}index(z){let H=Array.isArray(z)?z:[z],U=`idx_${this.table}_${H.join("_")}`;return this.indices.push(`CREATE INDEX ${U} ON ${this.table} (${H.join(", ")})`),this}unique(z){let H=Array.isArray(z)?z:[z],U=`uniq_${this.table}_${H.join("_")}`;return this.indices.push(`CREATE UNIQUE INDEX ${U} ON ${this.table} (${H.join(", ")})`),this}toCreateSQL(){return`CREATE TABLE IF NOT EXISTS ${this.table} (
|
|
3
3
|
${this.columns.join(`,
|
|
4
4
|
`)}
|
|
5
5
|
)`}getIndexSQL(){return this.indices}}function Zz(){return new w}export{zz as transaction,t as table,Zz as schema,r as resetDatabaseConfig,a as registerAdapter,E as raw,G as query,c as processQueryDirective,d as processModelDirective,u as processDbDirective,Yz as processDatabaseDirectives,e as hasModel,Uz as getQueryLog,Jz as getQueryCacheStats,k as getModel,o as getDatabaseConfig,F as getAdapter,Xz as enableQueryLogging,n as defineModel,i as configureDatabase,Wz as clearQueryLog,Hz as clearQueryCache,w as SchemaBuilder,D as QueryBuilder,O as DatabaseError,C as Blueprint};
|
|
@@ -78,8 +78,8 @@ function serveStaticFile(filePath) {
|
|
|
78
78
|
export async function serveApp(appDir = ".", options = {}) {
|
|
79
79
|
const port = options.port || 3000, watch = options.watch !== !1, hotReload = options.hotReload !== !1 && watch;
|
|
80
80
|
let hmrServer = null, actualHmrPort = options.hmrPort || port + 1;
|
|
81
|
-
const absoluteAppDir = path.resolve(appDir), { loadStxConfig } = await import("../index.js"), projectConfig = await loadStxConfig(absoluteAppDir), stxRoot = projectConfig.root && projectConfig.root !== "." ? path.join(absoluteAppDir, projectConfig.root) : absoluteAppDir, pagesDirName = options.pagesDir || projectConfig.pagesDir || "pages", pagesDir = path.join(stxRoot, pagesDirName);
|
|
82
|
-
if (!fs.existsSync(pagesDir)) {
|
|
81
|
+
const absoluteAppDir = path.resolve(appDir), { loadStxConfig } = await import("../index.js"), projectConfig = await loadStxConfig(absoluteAppDir), { createServerApi, isServerApiSource } = await import("../server-api.js"), serverApi = options.stxOptions?.serverApi ?? projectConfig.serverApi, handleApi = await createServerApi(absoluteAppDir, serverApi), stxRoot = projectConfig.root && projectConfig.root !== "." ? path.join(absoluteAppDir, projectConfig.root) : absoluteAppDir, pagesDirName = options.pagesDir || projectConfig.pagesDir || "pages", pagesDir = path.join(stxRoot, pagesDirName);
|
|
82
|
+
if (!fs.existsSync(pagesDir) && !projectConfig._layerPageDirs?.some((dir) => fs.existsSync(dir))) {
|
|
83
83
|
console.error(`${colors.red}Error: No '${pagesDirName}' directory found${colors.reset}`);
|
|
84
84
|
console.log(`${colors.dim}Looked in: ${colors.bright}${pagesDir}${colors.reset}`);
|
|
85
85
|
console.log(`${colors.dim}Run stx dev from the app directory, pass it as an argument (stx dev <dir>),${colors.reset}`);
|
|
@@ -87,7 +87,7 @@ export async function serveApp(appDir = ".", options = {}) {
|
|
|
87
87
|
console.log(`${colors.dim}Starting fresh? Create ${pagesDirName}/index.stx for the homepage.${colors.reset}`);
|
|
88
88
|
return !1;
|
|
89
89
|
}
|
|
90
|
-
const routes = createRouter(stxRoot, { pagesDir: pagesDirName });
|
|
90
|
+
const routes = createRouter(stxRoot, { pagesDir: pagesDirName, pagesDirs: projectConfig._layerPageDirs ? [pagesDir, ...projectConfig._layerPageDirs.slice(1)] : void 0 });
|
|
91
91
|
if (routes.length === 0) {
|
|
92
92
|
console.error(`${colors.red}Error: No page files found in ${colors.bright}${pagesDir}${colors.reset}`);
|
|
93
93
|
return !1;
|
|
@@ -252,6 +252,7 @@ export async function serveApp(appDir = ".", options = {}) {
|
|
|
252
252
|
const context = {
|
|
253
253
|
__filename: route.filePath,
|
|
254
254
|
__dirname: path.dirname(route.filePath),
|
|
255
|
+
__stx_options: merged,
|
|
255
256
|
params: requestParams ?? {},
|
|
256
257
|
__stx_runtime_head: {}
|
|
257
258
|
};
|
|
@@ -365,16 +366,19 @@ export async function serveApp(appDir = ".", options = {}) {
|
|
|
365
366
|
const server = serve({
|
|
366
367
|
port: actualPort,
|
|
367
368
|
async fetch(request) {
|
|
368
|
-
const url = new URL(request.url), publicDirName = projectConfig?.publicDir || "public", publicPath = path.join(absoluteAppDir, publicDirName, url.pathname), distPath = path.join(absoluteAppDir, url.pathname), outputPath = path.join(outputDir, url.pathname)
|
|
369
|
+
const url = new URL(request.url), publicDirName = projectConfig?.publicDir || "public", publicPath = path.join(absoluteAppDir, publicDirName, url.pathname), distPath = path.join(absoluteAppDir, url.pathname), outputPath = path.join(outputDir, url.pathname);
|
|
370
|
+
if ([publicPath, distPath, outputPath].some((file) => isServerApiSource(file, absoluteAppDir, serverApi)))
|
|
371
|
+
return new Response("Not Found", { status: 404 });
|
|
372
|
+
const [publicStat, distStat, outputStat] = await Promise.all([
|
|
369
373
|
fs.promises.stat(publicPath).catch(() => null),
|
|
370
374
|
fs.promises.stat(distPath).catch(() => null),
|
|
371
375
|
fs.promises.stat(outputPath).catch(() => null)
|
|
372
376
|
]);
|
|
373
|
-
if (publicStat?.isFile())
|
|
377
|
+
if (publicStat?.isFile() && !isServerApiSource(publicPath, absoluteAppDir, serverApi))
|
|
374
378
|
return serveStaticFile(publicPath);
|
|
375
|
-
if (distStat?.isFile())
|
|
379
|
+
if (distStat?.isFile() && !isServerApiSource(distPath, absoluteAppDir, serverApi))
|
|
376
380
|
return serveStaticFile(distPath);
|
|
377
|
-
if (outputStat?.isFile())
|
|
381
|
+
if (outputStat?.isFile() && !isServerApiSource(outputPath, absoluteAppDir, serverApi))
|
|
378
382
|
return serveStaticFile(outputPath);
|
|
379
383
|
if (url.pathname.startsWith("/_stx/component/")) {
|
|
380
384
|
const componentName = decodeURIComponent(url.pathname.slice(16));
|
|
@@ -409,6 +413,9 @@ export async function serveApp(appDir = ".", options = {}) {
|
|
|
409
413
|
headers: { "Content-Type": "application/json" }
|
|
410
414
|
});
|
|
411
415
|
}
|
|
416
|
+
const apiResponse = await handleApi(request);
|
|
417
|
+
if (apiResponse)
|
|
418
|
+
return apiResponse;
|
|
412
419
|
const routeMatch = matchRoute(url.pathname, routes);
|
|
413
420
|
if (routeMatch) {
|
|
414
421
|
let builtPage = builtPages.get(routeMatch.route.pattern);
|
|
@@ -668,10 +675,41 @@ Press ${colors.cyan}h${colors.reset} + ${colors.cyan}Enter${colors.reset} to sho
|
|
|
668
675
|
}, isTemplateFile = (filename) => {
|
|
669
676
|
const ext = filename.toLowerCase();
|
|
670
677
|
return ext.endsWith(".stx") || ext.endsWith(".html") || ext.endsWith(".md");
|
|
671
|
-
},
|
|
678
|
+
}, watchers = new Map, syncWatchers = () => {
|
|
679
|
+
const roots = new Set([absoluteAppDir, ...projectConfig._layerGraph?.layers.map((layer) => layer.root) ?? [], ...projectConfig._layerGraph?.configDependencies.map((file) => path.dirname(file)) ?? []].filter((root) => fs.existsSync(root)).map((root) => fs.realpathSync(root)));
|
|
680
|
+
for (const layer of projectConfig._layerGraph?.layers ?? [])
|
|
681
|
+
for (const directory of Object.values(layer.resources)) {
|
|
682
|
+
if (!fs.existsSync(directory))
|
|
683
|
+
continue;
|
|
684
|
+
const root = fs.realpathSync(directory);
|
|
685
|
+
if (![...roots].some((parent) => root === parent || root.startsWith(`${parent}${path.sep}`)))
|
|
686
|
+
roots.add(root);
|
|
687
|
+
}
|
|
688
|
+
for (const [root, watcher] of watchers)
|
|
689
|
+
if (!roots.has(root)) {
|
|
690
|
+
watcher.close();
|
|
691
|
+
watchers.delete(root);
|
|
692
|
+
}
|
|
693
|
+
for (const root of roots)
|
|
694
|
+
if (!watchers.has(root) && fs.existsSync(root))
|
|
695
|
+
watchers.set(root, fs.watch(root, { recursive: !0 }, (event, file) => {
|
|
696
|
+
changed(root, event, file).catch((error) => console.error("[stx] Layer rebuild failed:", error));
|
|
697
|
+
}));
|
|
698
|
+
};
|
|
699
|
+
let rebuildQueue = Promise.resolve();
|
|
700
|
+
const changed = (watchRoot, eventType, filename) => {
|
|
701
|
+
rebuildQueue = rebuildQueue.catch(() => {}).then(() => onChange(watchRoot, eventType, filename));
|
|
702
|
+
return rebuildQueue;
|
|
703
|
+
}, onChange = async (watchRoot, eventType, filename) => {
|
|
672
704
|
if (!filename || shouldIgnoreFile(filename))
|
|
673
705
|
return;
|
|
674
|
-
if (shouldReloadOnChange(filename))
|
|
706
|
+
if (shouldReloadOnChange(filename)) {
|
|
707
|
+
if (projectConfig._layerGraph) {
|
|
708
|
+
const fresh = await loadStxConfig(absoluteAppDir);
|
|
709
|
+
Object.assign(projectConfig, fresh);
|
|
710
|
+
routes.splice(0, routes.length, ...createRouter(stxRoot, { pagesDir: pagesDirName, pagesDirs: fresh._layerPageDirs ? [pagesDir, ...fresh._layerPageDirs.slice(1)] : void 0 }));
|
|
711
|
+
syncWatchers();
|
|
712
|
+
}
|
|
675
713
|
if (isStaticAsset(filename)) {
|
|
676
714
|
console.log(`${colors.cyan}${filename} changed${colors.reset}`);
|
|
677
715
|
if (hotReload && hmrServer)
|
|
@@ -682,11 +720,11 @@ Press ${colors.cyan}h${colors.reset} + ${colors.cyan}Enter${colors.reset} to sho
|
|
|
682
720
|
clearComponentCache();
|
|
683
721
|
try {
|
|
684
722
|
const { invalidateFileCache, templateCache } = await import("../caching.js");
|
|
685
|
-
invalidateFileCache(path.resolve(
|
|
686
|
-
templateCache.delete(path.resolve(
|
|
723
|
+
invalidateFileCache(path.resolve(watchRoot, filename));
|
|
724
|
+
templateCache.delete(path.resolve(watchRoot, filename));
|
|
687
725
|
} catch {}
|
|
688
726
|
if (shellPath && filename) {
|
|
689
|
-
if (path.resolve(
|
|
727
|
+
if (path.resolve(watchRoot, filename) === shellPath || path.basename(shellPath) === filename) {
|
|
690
728
|
const newShell = await processShell(shellPath, options.stxOptions || {});
|
|
691
729
|
if (newShell)
|
|
692
730
|
shell = newShell;
|
|
@@ -702,21 +740,23 @@ Press ${colors.cyan}h${colors.reset} + ${colors.cyan}Enter${colors.reset} to sho
|
|
|
702
740
|
clearComponentCache();
|
|
703
741
|
try {
|
|
704
742
|
const { invalidateFileCache, templateCache } = await import("../caching.js");
|
|
705
|
-
invalidateFileCache(path.resolve(
|
|
706
|
-
templateCache.delete(path.resolve(
|
|
743
|
+
invalidateFileCache(path.resolve(watchRoot, filename));
|
|
744
|
+
templateCache.delete(path.resolve(watchRoot, filename));
|
|
707
745
|
} catch {}
|
|
708
746
|
await buildAllPages();
|
|
709
747
|
if (hotReload && hmrServer)
|
|
710
748
|
hmrServer.reload(filename);
|
|
711
749
|
}
|
|
712
|
-
else if (isCssOnlyChange(filename)) {
|
|
750
|
+
} else if (isCssOnlyChange(filename)) {
|
|
713
751
|
console.log(`${colors.cyan}CSS ${filename} changed${colors.reset}`);
|
|
714
752
|
if (hotReload && hmrServer)
|
|
715
753
|
hmrServer.updateCss(filename);
|
|
716
754
|
}
|
|
717
|
-
}
|
|
755
|
+
};
|
|
756
|
+
syncWatchers();
|
|
718
757
|
process.on("SIGINT", () => {
|
|
719
|
-
watcher.
|
|
758
|
+
for (const watcher of watchers.values())
|
|
759
|
+
watcher.close();
|
|
720
760
|
if (hmrServer)
|
|
721
761
|
stopHmrServer();
|
|
722
762
|
server.stop();
|
|
@@ -99,9 +99,10 @@ export async function serveStxFile(filePath, options = {}) {
|
|
|
99
99
|
hmrServer = getHmrServer({ wsPort: desiredHmrPort, verbose: !1 });
|
|
100
100
|
actualHmrPort = hmrServer.start(desiredHmrPort);
|
|
101
101
|
}
|
|
102
|
-
let apiRoutes = {}, customRouter = null;
|
|
102
|
+
let apiRoutes = {}, customRouter = null, serverApi;
|
|
103
103
|
try {
|
|
104
104
|
const { loadStxConfig } = await import("../index.js"), projectConfig = await loadStxConfig();
|
|
105
|
+
serverApi = options.stxOptions?.serverApi ?? projectConfig.serverApi;
|
|
105
106
|
if (projectConfig?.apiRouter) {
|
|
106
107
|
customRouter = projectConfig?.apiRouter;
|
|
107
108
|
console.log(`${colors.blue}Using custom router for API handling${colors.reset}`);
|
|
@@ -130,6 +131,7 @@ export async function serveStxFile(filePath, options = {}) {
|
|
|
130
131
|
console.warn(`${colors.yellow}Broadcasting failed to start: ${err.message}${colors.reset}`);
|
|
131
132
|
}
|
|
132
133
|
} catch {}
|
|
134
|
+
const { createServerApi, isServerApiSource } = await import("../server-api.js"), handleApi = await createServerApi(process.cwd(), serverApi);
|
|
133
135
|
console.log(`${colors.blue}Starting server on ${colors.cyan}http://localhost:${actualPort}/${colors.reset}...`);
|
|
134
136
|
if (hotReload)
|
|
135
137
|
console.log(`${colors.magenta}Hot reload enabled on ws://localhost:${actualHmrPort}${colors.reset}`);
|
|
@@ -138,6 +140,8 @@ export async function serveStxFile(filePath, options = {}) {
|
|
|
138
140
|
async fetch(request) {
|
|
139
141
|
return compressResponse(request, await (async () => {
|
|
140
142
|
const url = new URL(request.url);
|
|
143
|
+
if ([outputDir, path.dirname(absolutePath), path.join(process.cwd(), "public")].some((directory) => isServerApiSource(path.join(directory, url.pathname), process.cwd(), serverApi)))
|
|
144
|
+
return new Response("Not Found", { status: 404 });
|
|
141
145
|
if (customRouter)
|
|
142
146
|
try {
|
|
143
147
|
const routerResponse = await customRouter.handleRequest(request);
|
|
@@ -153,6 +157,9 @@ export async function serveStxFile(filePath, options = {}) {
|
|
|
153
157
|
headers: { "Content-Type": "application/json" }
|
|
154
158
|
});
|
|
155
159
|
}
|
|
160
|
+
const apiResponse = await handleApi(request);
|
|
161
|
+
if (apiResponse)
|
|
162
|
+
return apiResponse;
|
|
156
163
|
if (url.pathname === "/")
|
|
157
164
|
return (async () => {
|
|
158
165
|
let content = await injectCss(htmlContent || "");
|
package/dist/expressions.js
CHANGED
|
@@ -251,7 +251,7 @@ export function usesSignalsInScript(template, filePath) {
|
|
|
251
251
|
if (!match || /\bserver\b|\bsrc\s*=/.test(match[1]))
|
|
252
252
|
continue;
|
|
253
253
|
const content = match[2];
|
|
254
|
-
if (/\b(state|derived|effect|ref|reactive|computed|watch|watchEffect)\s*(?:<[^>]*>)?\s*\(/.test(content))
|
|
254
|
+
if (/\b(state|derived|effect|ref|reactive|computed|watch|watchEffect|useModel)\s*(?:<[^>]*>)?\s*\(/.test(content))
|
|
255
255
|
return !0;
|
|
256
256
|
if (importsSignalDeclarations(content, filePath))
|
|
257
257
|
return !0;
|
package/dist/imported-signals.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
const SIGNAL_API_CALL = /\b(?:state|derived|effect|ref|reactive|computed|watch|watchEffect)\s*(?:<[^<>()]*>)?\s*\(/, RELATIVE_IMPORT = /(?:^|\n)\s*(?:import|export)\s+(?:[^'"]*?\sfrom\s+)?['"](\.[^'"]*)['"]/g, EXTENSIONS = ["", ".ts", ".tsx", ".js", ".jsx", ".mts", ".mjs", "/index.ts", "/index.js"], MAX_DEPTH = 3;
|
|
3
|
+
const SIGNAL_API_CALL = /\b(?:state|derived|effect|ref|reactive|computed|watch|watchEffect|useModel)\s*(?:<[^<>()]*>)?\s*\(/, RELATIVE_IMPORT = /(?:^|\n)\s*(?:import|export)\s+(?:[^'"]*?\sfrom\s+)?['"](\.[^'"]*)['"]/g, EXTENSIONS = ["", ".ts", ".tsx", ".js", ".jsx", ".mts", ".mjs", "/index.ts", "/index.js"], MAX_DEPTH = 3;
|
|
4
4
|
function resolveImport(specifier, fromFile) {
|
|
5
5
|
const base = path.resolve(path.dirname(fromFile), specifier);
|
|
6
6
|
for (const extension of EXTENSIONS) {
|
package/dist/includes.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { findSfcTemplateBlock } from "./sfc-template.js";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
3
4
|
import { processConditionals } from "./conditionals.js";
|
|
4
5
|
import { isProduction, isTest } from "./env.js";
|
|
5
6
|
import { findBodyOpenTag, replaceBodyOpenTag } from "./find-body-tag.js";
|
|
@@ -514,9 +515,14 @@ export async function processIncludes(template, context, filePath, options, depe
|
|
|
514
515
|
includeFilePath = `${includePath}.stx`;
|
|
515
516
|
const normalizedPartialsDir = path.resolve(partialsDir), templateDir = path.resolve(path.dirname(filePath));
|
|
516
517
|
let resolvedPath;
|
|
517
|
-
if (!includeFilePath.startsWith("./") && !includeFilePath.startsWith("../"))
|
|
518
|
+
if (!includeFilePath.startsWith("./") && !includeFilePath.startsWith("../")) {
|
|
519
|
+
for (const directory of options._layerPartialDirs ?? []) {
|
|
520
|
+
const candidate = path.resolve(directory, includeFilePath);
|
|
521
|
+
if (candidate.startsWith(`${path.resolve(directory)}${path.sep}`) && existsSync(candidate))
|
|
522
|
+
return candidate;
|
|
523
|
+
}
|
|
518
524
|
resolvedPath = path.resolve(partialsDir, includeFilePath);
|
|
519
|
-
else
|
|
525
|
+
} else
|
|
520
526
|
resolvedPath = path.resolve(templateDir, includeFilePath);
|
|
521
527
|
const normalizedResolvedPath = path.normalize(resolvedPath), isWithinPartialsDir = normalizedResolvedPath.startsWith(normalizedPartialsDir + path.sep) || normalizedResolvedPath === normalizedPartialsDir, isWithinTemplateDir = normalizedResolvedPath.startsWith(templateDir + path.sep) || normalizedResolvedPath === templateDir;
|
|
522
528
|
let isWithinProjectScope = !1;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/// <reference path="./stx.d.ts" />
|
|
2
|
+
export type { RuntimeConfigDefaults, PublicRuntimeConfig } from './runtime-config-types';
|
|
3
|
+
export type { ServerApiOptions, ServerApiRoute } from './server-api';
|
|
4
|
+
export type { ApiHandlerContext } from './api-handler';
|
|
2
5
|
export type { Store, StoreOptions, PersistOptions, DefineStoreOptions } from './state-management';
|
|
3
6
|
export type { StxComponentInstance, EmitFn } from './composition-api';
|
|
7
|
+
export type { ModelSignal, ModelOptions, ModelModifiers } from './component-model';
|
|
4
8
|
export type { VNode } from './jsx-runtime';
|
|
5
9
|
export type { StxApp, StxApp as App, StxAppPlugin, StxPluginInput, StxAppConfig } from './app';
|
|
6
10
|
export type { StxPlugin, PluginContext, PluginSetupContext } from './plugin-system';
|
|
@@ -20,6 +24,9 @@ export type {
|
|
|
20
24
|
// ============================================================
|
|
21
25
|
// Explicit re-exports to resolve wildcard ambiguities
|
|
22
26
|
export { type BuildResult } from './build-optimizer';
|
|
27
|
+
export { useServerData } from './server-data';
|
|
28
|
+
export { useRuntimeConfig, useServerRuntimeConfig } from './runtime-config-server';
|
|
29
|
+
export { clearServerData } from './composables/use-fetch';
|
|
23
30
|
// Exported for servers as well as the static build: SSR inlines the runtime
|
|
24
31
|
// once per *request*, which is the same waste in a worse form.
|
|
25
32
|
export { EXTERNALIZED_ASSET_DIR, externalizeHtml, externalizeSharedAssets, type ExternalizedAsset, type ExternalizeHtmlResult, type ExternalizeResult } from './build-externalize';
|
|
@@ -190,6 +197,9 @@ export * from './process';
|
|
|
190
197
|
export * from './production-build';
|
|
191
198
|
export * from './production-builder';
|
|
192
199
|
export * from './production-server';
|
|
200
|
+
export * from './route-rules';
|
|
201
|
+
export { createServerApi, discoverServerApi, generateApiTypes } from './server-api';
|
|
202
|
+
export { defineApiHandler } from './api-handler';
|
|
193
203
|
export * from './release';
|
|
194
204
|
export * from './router';
|
|
195
205
|
export * from './scaffolding';
|
|
@@ -265,6 +275,7 @@ export * from './spa-shell';
|
|
|
265
275
|
export * from './vue-template';
|
|
266
276
|
export { processServerBindings } from './server-bindings';
|
|
267
277
|
export { provide, inject, setGlobalProvide, defineEmits, defineExpose, defineSlots, nextTick, onErrorCaptured, handleError, useSlots, useAttrs, createProvideContext, generateCompositionRuntime } from './composition-api';
|
|
278
|
+
export { useModel } from './component-model';
|
|
268
279
|
export { jsx, jsxs, jsxDEV, Fragment, renderToString, renderToStream, renderToDOM, Show, For, Portal, h } from './jsx-runtime';
|
|
269
280
|
export { createApp, createApp as createStxApp, defineCustomElement } from './app';
|
|
270
281
|
export * from './dynamic-components';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export { useServerData } from "./server-data.js";
|
|
2
|
+
export { useRuntimeConfig, useServerRuntimeConfig } from "./runtime-config-server.js";
|
|
3
|
+
export { clearServerData } from "./composables/use-fetch.js";
|
|
1
4
|
export { EXTERNALIZED_ASSET_DIR, externalizeHtml, externalizeSharedAssets } from "./build-externalize.js";
|
|
2
5
|
export { externalizeRepeatedAssets } from "./build-externalize-repeated.js";
|
|
3
6
|
export {
|
|
@@ -100,6 +103,9 @@ export * from "./process.js";
|
|
|
100
103
|
export * from "./production-build.js";
|
|
101
104
|
export * from "./production-builder.js";
|
|
102
105
|
export * from "./production-server.js";
|
|
106
|
+
export * from "./route-rules.js";
|
|
107
|
+
export { createServerApi, discoverServerApi, generateApiTypes } from "./server-api.js";
|
|
108
|
+
export { defineApiHandler } from "./api-handler.js";
|
|
103
109
|
export * from "./release.js";
|
|
104
110
|
export * from "./router.js";
|
|
105
111
|
export * from "./scaffolding.js";
|
|
@@ -151,6 +157,7 @@ export * from "./spa-shell.js";
|
|
|
151
157
|
export * from "./vue-template.js";
|
|
152
158
|
export { processServerBindings } from "./server-bindings.js";
|
|
153
159
|
export { provide, inject, setGlobalProvide, defineEmits, defineExpose, defineSlots, nextTick, onErrorCaptured, handleError, useSlots, useAttrs, createProvideContext, generateCompositionRuntime } from "./composition-api.js";
|
|
160
|
+
export { useModel } from "./component-model.js";
|
|
154
161
|
export { jsx, jsxs, jsxDEV, Fragment, renderToString, renderToStream, renderToDOM, Show, For, Portal, h } from "./jsx-runtime.js";
|
|
155
162
|
export { createApp, createApp as createStxApp, defineCustomElement } from "./app.js";
|
|
156
163
|
export * from "./dynamic-components.js";
|