@kosmojs/dev 0.2.7 → 0.2.10
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/package.json +19 -18
- package/pkg/chassis.js +58 -77
- package/pkg/chassis.js.map +1 -1
- package/pkg/index.js +680 -228
- package/pkg/index.js.map +1 -1
package/pkg/index.js
CHANGED
|
@@ -1,4 +1,116 @@
|
|
|
1
|
-
import{join as e,resolve as t}from"node:path";import{styleText as n}from"node:util";import{DEFAULT_APIBASE as r,RequestBodyTargets as i,RequestValidationTargets as a,createRouteResolver as o,createTemplateResolver as s,defaults as c}from"@kosmojs/core";import{createHonoPattern as l,createPathPattern as u,defineGenerator as d,defineGeneratorFactory as f,mergeConfigs as p,nestedRoutesFactory as m,pathResolver as h,pathTokensFactory as g,renderFactory as _,renderToFile as ee,sortRoutes as v,spinnerFactory as te,vitePlugins as y}from"@kosmojs/lib";import{routeRenderHelpers as b}from"@kosmojs/core/generators";import x from"crc/crc32";import ne from"@mdx-js/rollup";import{build as S,createFilter as C}from"vite";import re from"yaml";import{parse as ie}from"path-to-regexp";import ae from"typebox";import oe from"@vitejs/plugin-react";import w from"vite-plugin-solid";import{access as se,constants as ce,cp as T,mkdir as le,rm as E,writeFile as ue}from"node:fs/promises";import{svelte as de}from"@sveltejs/vite-plugin-svelte";import
|
|
1
|
+
import{join as e,resolve as t}from"node:path";import{styleText as n}from"node:util";import{DEFAULT_APIBASE as r,RequestBodyTargets as i,RequestValidationTargets as a,createRouteResolver as o,createTemplateResolver as s,defaults as c}from"@kosmojs/core";import{createHonoPattern as l,createPathPattern as u,defineGenerator as d,defineGeneratorFactory as f,mergeConfigs as p,nestedRoutesFactory as m,pathResolver as h,pathTokensFactory as g,renderFactory as _,renderToFile as ee,sortRoutes as v,spinnerFactory as te,vitePlugins as y}from"@kosmojs/lib";import{routeRenderHelpers as b}from"@kosmojs/core/generators";import x from"crc/crc32";import ne from"@mdx-js/rollup";import{build as S,createFilter as C}from"vite";import re from"yaml";import{parse as ie}from"path-to-regexp";import ae from"typebox";import oe from"@vitejs/plugin-react";import w from"vite-plugin-solid";import{access as se,constants as ce,cp as T,mkdir as le,rm as E,writeFile as ue}from"node:fs/promises";import{svelte as de}from"@sveltejs/vite-plugin-svelte";import fe from"@vitejs/plugin-vue";var D={type:`module`,private:!0,name:`@kosmojs/fetch-generator`,version:`0.2.10`,author:`Slee Woo`,license:`MIT`,files:[`pkg/*`],exports:{".":{types:`./pkg/index.d.ts`,default:`./pkg/index.js`}},scripts:{build:`wsbuild src/index.ts`,test:`vitest --root ../.. --project generators/fetch-generator`},dependencies:{"@kosmojs/core":`workspace:^`,"@kosmojs/lib":`workspace:^`},devDependencies:{"path-to-regexp":`^8.4.2`}},O=`import { compile } from "path-to-regexp";
|
|
2
|
+
|
|
3
|
+
import type { ApiRouteSerialized, ValidationTarget } from "@kosmojs/core";
|
|
4
|
+
import type { HTTPMethod } from "@kosmojs/core/api";
|
|
5
|
+
import { createHost, type HostOpt, join, stringify } from "@kosmojs/core/fetch";
|
|
6
|
+
|
|
7
|
+
export * from "./transport";
|
|
8
|
+
|
|
9
|
+
export const fetchHelpers = <ParamsT extends readonly unknown[]>(
|
|
10
|
+
basePath: string,
|
|
11
|
+
route: ApiRouteSerialized,
|
|
12
|
+
) => {
|
|
13
|
+
const toPath = compile(route.pathPattern);
|
|
14
|
+
|
|
15
|
+
const maybeNumber = (val: unknown) => {
|
|
16
|
+
if (val === undefined || val === null) {
|
|
17
|
+
return val;
|
|
18
|
+
}
|
|
19
|
+
const n = Number(val);
|
|
20
|
+
return Number.isFinite(n) ? n : val;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const paramsMapper = (params: ParamsT, opt?: { coerceNumbers?: boolean }) => {
|
|
24
|
+
return route.params.reduce<Record<string, unknown>>((map, name, i) => {
|
|
25
|
+
const coerceNumbers = opt?.coerceNumbers
|
|
26
|
+
? route.numericProperties.params.includes(name)
|
|
27
|
+
: false;
|
|
28
|
+
if (Array.isArray(params[i])) {
|
|
29
|
+
map[name] = coerceNumbers
|
|
30
|
+
? params[i].map((v) => maybeNumber(v))
|
|
31
|
+
: params[i].map(String);
|
|
32
|
+
} else if (params[i] !== undefined) {
|
|
33
|
+
map[name] = coerceNumbers ? maybeNumber(params[i]) : String(params[i]);
|
|
34
|
+
}
|
|
35
|
+
return map;
|
|
36
|
+
}, {});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const parametrize = (params: ParamsT) => {
|
|
40
|
+
try {
|
|
41
|
+
return toPath(paramsMapper(params) as never);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error(\`❗ERROR: Failed building path for \${route.name}\`);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const base = (params: ParamsT, query?: Record<string, unknown>) => {
|
|
49
|
+
const path = join("/", parametrize(params));
|
|
50
|
+
return query ? [path, stringify(query)].join("?") : path;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const path = (params: ParamsT, query?: Record<string, unknown>) => {
|
|
54
|
+
return join(basePath, base(params, query));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const href = (
|
|
58
|
+
host: HostOpt,
|
|
59
|
+
params: ParamsT,
|
|
60
|
+
query?: Record<string, unknown>,
|
|
61
|
+
) => {
|
|
62
|
+
return createHost(host) + path(params, query);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const payloadResolver = <T>(
|
|
66
|
+
payload: Record<ValidationTarget, T> | undefined,
|
|
67
|
+
target: ValidationTarget,
|
|
68
|
+
method: HTTPMethod,
|
|
69
|
+
) => {
|
|
70
|
+
const data = payload?.[target];
|
|
71
|
+
|
|
72
|
+
if (target === "query") {
|
|
73
|
+
return Object.fromEntries(
|
|
74
|
+
Object.entries({ ...data }).map(([k, v]) => {
|
|
75
|
+
return [
|
|
76
|
+
k,
|
|
77
|
+
route.numericProperties.query[method]?.includes(k)
|
|
78
|
+
? Array.isArray(v)
|
|
79
|
+
? v.map((v) => maybeNumber(v))
|
|
80
|
+
: maybeNumber(v)
|
|
81
|
+
: v,
|
|
82
|
+
];
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (data instanceof FormData) {
|
|
88
|
+
return [...data].reduce<
|
|
89
|
+
Record<string, FormDataEntryValue | Array<FormDataEntryValue>>
|
|
90
|
+
>((map, [key, val]) => {
|
|
91
|
+
if (key in map) {
|
|
92
|
+
map[key] = [map[key]].flat().concat(val);
|
|
93
|
+
} else {
|
|
94
|
+
map[key] = val;
|
|
95
|
+
}
|
|
96
|
+
return map;
|
|
97
|
+
}, {}) as T;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return data;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
paramsMapper,
|
|
105
|
+
parametrize,
|
|
106
|
+
base,
|
|
107
|
+
path,
|
|
108
|
+
href,
|
|
109
|
+
payloadResolver,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
`,k=`export const transport = undefined;
|
|
113
|
+
`,A=`{{#each routes}}
|
|
2
114
|
import {{id}} from "{{ createImport 'libApi' name 'fetch' }}";
|
|
3
115
|
{{/each}}
|
|
4
116
|
|
|
@@ -16,13 +128,10 @@ export default {
|
|
|
16
128
|
{{/each}}
|
|
17
129
|
{{/each}}
|
|
18
130
|
}
|
|
19
|
-
`,
|
|
20
|
-
join,
|
|
21
|
-
stringify,
|
|
22
|
-
payloadResolver,
|
|
23
|
-
} from "@kosmojs/core/fetch";
|
|
131
|
+
`,j=`import fetchFactory, { join, stringify } from "@kosmojs/core/fetch";
|
|
24
132
|
|
|
25
133
|
import { base, apiBase, apiRouteMap } from "{{ createImport 'libCore' }}";
|
|
134
|
+
import { transport, fetchHelpers } from "{{ createImport 'lib' '@fetch' }}";
|
|
26
135
|
|
|
27
136
|
import {
|
|
28
137
|
type MaybeWrapped,
|
|
@@ -59,18 +168,17 @@ export type ResponseT = {
|
|
|
59
168
|
const {
|
|
60
169
|
paramsMapper,
|
|
61
170
|
parametrize,
|
|
171
|
+
payloadResolver,
|
|
62
172
|
path,
|
|
63
173
|
href,
|
|
64
|
-
} =
|
|
174
|
+
} = fetchHelpers<[{{serializeParamsTupleElements route}}]>(
|
|
175
|
+
apiBase,
|
|
176
|
+
apiRouteMap["{{route.name}}"],
|
|
177
|
+
);
|
|
65
178
|
|
|
66
179
|
const fetchApi = fetchFactory(
|
|
67
180
|
join(base, apiBase),
|
|
68
|
-
{
|
|
69
|
-
stringify,
|
|
70
|
-
...KOSMO_SERVERSIDE_FETCH
|
|
71
|
-
? { transport: await import("{{ createImport 'lib' '@ssr/fetch' }}").then((e) => e.transport) }
|
|
72
|
-
: {},
|
|
73
|
-
},
|
|
181
|
+
{ transport, stringify },
|
|
74
182
|
);
|
|
75
183
|
|
|
76
184
|
{{#each routeMethods}}
|
|
@@ -101,14 +209,16 @@ export const {{method}} = (
|
|
|
101
209
|
return typeof opt?.unwrap === "function" ? opt.unwrap(data) : unwrap(data);
|
|
102
210
|
})
|
|
103
211
|
// validate only on client, skip double validation in SSR mode
|
|
104
|
-
if (!
|
|
212
|
+
if (!import.meta.env.SSR) {
|
|
105
213
|
if (validationSchemas.params) {
|
|
106
|
-
validationSchemas.params.validate(
|
|
214
|
+
validationSchemas.params.validate(
|
|
215
|
+
paramsMapper(params as never, { coerceNumbers: true }),
|
|
216
|
+
);
|
|
107
217
|
}
|
|
108
218
|
{{#each ../payloadTypes}}
|
|
109
219
|
if (validationSchemas.{{target}}?.{{../method}}) {
|
|
110
220
|
validationSchemas.{{target}}.{{../method}}.validate(
|
|
111
|
-
payloadResolver(payload, "{{target}}")
|
|
221
|
+
payloadResolver(payload, "{{target}}", "{{../method}}"),
|
|
112
222
|
);
|
|
113
223
|
}
|
|
114
224
|
{{/each}}
|
|
@@ -125,9 +235,9 @@ export default {
|
|
|
125
235
|
href,
|
|
126
236
|
validationSchemas,
|
|
127
237
|
};
|
|
128
|
-
`,
|
|
238
|
+
`,M=`export type MaybeWrapped<T> = T;
|
|
129
239
|
export const unwrap = <T>(data: T) => data;
|
|
130
|
-
`,
|
|
240
|
+
`,N=f(e=>{let{createPath:t,createImportHelpers:n}=h(e),{renderToFile:r}=_({helpers:{...n({origin:`lib`}),...b()}}),i=async(e,n)=>{let i=e.flatMap(({kind:e,entry:t})=>e===`apiRoute`?[t]:[]).sort(v);await r(t.lib(`fetch.ts`),A,{routes:i});for(let{kind:e,entry:i}of n)if(e===`apiRoute`){let e=[];for(let t of i.validationDefinitions)if(t.target===`response`)for(let{id:n,body:r,resolvedType:i}of t.variants)r&&e.push({id:n,target:t.target,method:t.method,resolvedType:i});else{let{id:n,resolvedType:r}=t.schema;e.push({id:n,target:t.target,method:t.method,resolvedType:r})}let n=i.methods.map(t=>({method:t,responseType:e.find(e=>e.target===`response`&&e.method===t)})),o=Object.entries(e.reduce((e,{id:t,target:n,method:r,resolvedType:i})=>{if([`headers`,`cookies`,`response`].includes(n))return e;let a=`${n.replace(/^./,e=>e.toUpperCase())}T`;return e[a]||(e[a]=[]),e[a].push({id:t,target:n,method:r,resolvedType:i}),e},{})).map(([e,t])=>({name:e,types:t,target:t[0].target})),s=Object.keys(a).map(e=>({target:e,payloadType:o.find(t=>t.target===e)})),c=Object.values(e.reduce((e,{id:t,target:n,method:r,resolvedType:i})=>(n===`response`&&(e[r]||(e[r]={method:r,types:[]}),e[r].types.push({id:t,target:n,method:r,resolvedType:i})),e),{}));await r(t.libApi(i.name,`fetch.ts`),j,{route:i,validationTypes:e,routeMethods:n,payloadTypes:o,payloadTargets:s,responseTypes:c})}};return{async start(){for(let[e,n]of[[`unwrap.ts`,M],[`@fetch/transport.ts`,k],[`@fetch/index.ts`,O]])await r(t.lib(e),n,{})},async watch(e,t){await i(e,t?e.filter(({kind:e,entry:n})=>t.kind===`update`&&e===`apiRoute`&&n.fileFullpath===t.file):e)},async build(e){await i(e,e)},async ssrBuild(){for(let[e,n]of[[`@fetch/transport.ts`,`export { transport } from "${c.libPrefix}/@ssr/fetch";`]])await r(t.lib(e),n,{})}}}),P=d({meta:{name:`Fetch`,slot:`fetch`},dependencies:{"path-to-regexp":D.devDependencies[`path-to-regexp`]},factory:N}),F={type:`module`,private:!0,name:`@kosmojs/hono-generator`,version:`0.2.10`,author:`Slee Woo`,license:`MIT`,files:[`pkg/*`],exports:{".":{types:`./pkg/index.d.ts`,default:`./pkg/index.js`}},scripts:{build:`wsbuild src/index.ts`,test:`vitest --root ../.. --project generators/hono-generator`},dependencies:{"@kosmojs/core":`workspace:^`,"@kosmojs/lib":`workspace:^`,crc:`^4.3.2`},devDependencies:{"@hono/node-server":`^2.1.0`,hono:`^4.13.1`,"path-to-regexp":`^8.4.2`,vite:`^8.2.1`}},I=`import { Hono } from "hono";
|
|
131
241
|
|
|
132
242
|
import type { AppFactory } from "@kosmojs/core/api";
|
|
133
243
|
|
|
@@ -148,10 +258,10 @@ export const appFactory: AppFactory<App, AppOptions> = (factory) => {
|
|
|
148
258
|
};
|
|
149
259
|
return factory({ createApp });
|
|
150
260
|
};
|
|
151
|
-
`,
|
|
261
|
+
`,L=`import type { DevSetup } from "@kosmojs/core/api";
|
|
152
262
|
|
|
153
263
|
export const devSetup = (setup: DevSetup) => setup;
|
|
154
|
-
`,
|
|
264
|
+
`,R=`import type { Context } from "hono";
|
|
155
265
|
|
|
156
266
|
import type { AppEnv } from "./app";
|
|
157
267
|
|
|
@@ -165,7 +275,7 @@ export type ErrorHandlerFactory = (handler: ErrorHandler) => ErrorHandler;
|
|
|
165
275
|
export const errorHandlerFactory: ErrorHandlerFactory = (handler) => {
|
|
166
276
|
return handler;
|
|
167
277
|
};
|
|
168
|
-
`,
|
|
278
|
+
`,z=`import type { Context } from "hono";
|
|
169
279
|
|
|
170
280
|
import type { RequestBodyTarget, RequestMetadataTarget } from "@kosmojs/core";
|
|
171
281
|
import { parseCookies, parseQuerystring } from "@kosmojs/core/api";
|
|
@@ -210,7 +320,7 @@ export const bodyparsers: {
|
|
|
210
320
|
return ctx.req[as]();
|
|
211
321
|
},
|
|
212
322
|
};
|
|
213
|
-
`,
|
|
323
|
+
`,B=`import type { MiddlewareHandler } from "hono";
|
|
214
324
|
import type { Router } from "hono/router";
|
|
215
325
|
import { RegExpRouter } from "hono/router/reg-exp-router";
|
|
216
326
|
import { SmartRouter } from "hono/router/smart-router";
|
|
@@ -243,6 +353,7 @@ import { type BodyparserOptions, bodyparsers, metaparsers } from "./parsers";
|
|
|
243
353
|
import { routeSources } from "./routes";
|
|
244
354
|
|
|
245
355
|
import globalMiddleware from "{{ createImport 'api' 'use' }}";
|
|
356
|
+
import { apiRouteMap } from "{{ createImport 'libCore' }}";
|
|
246
357
|
|
|
247
358
|
/**
|
|
248
359
|
* Create route-level middleware stack that handles:
|
|
@@ -259,7 +370,15 @@ import globalMiddleware from "{{ createImport 'api' 'use' }}";
|
|
|
259
370
|
* */
|
|
260
371
|
export const createRouteMiddleware: CreateRouteMiddleware<
|
|
261
372
|
ParameterizedMiddleware
|
|
262
|
-
> = ({ name, pathPattern,
|
|
373
|
+
> = ({ name, pathPattern, validationSchemas }) => {
|
|
374
|
+
const route = apiRouteMap[name];
|
|
375
|
+
|
|
376
|
+
if (!route) {
|
|
377
|
+
throw new Error(\`createRouteMiddleware: \${name} route does not exists\`);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const { params, numericProperties } = route;
|
|
381
|
+
|
|
263
382
|
const pathMatcher = match(pathPattern);
|
|
264
383
|
|
|
265
384
|
const matchPath = (path: string) => {
|
|
@@ -270,6 +389,14 @@ export const createRouteMiddleware: CreateRouteMiddleware<
|
|
|
270
389
|
}
|
|
271
390
|
};
|
|
272
391
|
|
|
392
|
+
const maybeNumber = (val: unknown) => {
|
|
393
|
+
if (val === undefined || val === null) {
|
|
394
|
+
return val;
|
|
395
|
+
}
|
|
396
|
+
const n = Number(val);
|
|
397
|
+
return Number.isFinite(n) ? n : val;
|
|
398
|
+
};
|
|
399
|
+
|
|
273
400
|
const validationMiddleware = [
|
|
274
401
|
/**
|
|
275
402
|
* Extends Hono context with:
|
|
@@ -307,7 +434,21 @@ export const createRouteMiddleware: CreateRouteMiddleware<
|
|
|
307
434
|
];
|
|
308
435
|
map[target] = () => {
|
|
309
436
|
if (!ctx[StateKey].has(target)) {
|
|
310
|
-
ctx[StateKey].set(
|
|
437
|
+
ctx[StateKey].set(
|
|
438
|
+
target,
|
|
439
|
+
target === "query"
|
|
440
|
+
? Object.fromEntries(
|
|
441
|
+
Object.entries(parser(ctx)).map(([k, v]) => [
|
|
442
|
+
k,
|
|
443
|
+
numericProperties.query[ctx.req.method]?.includes(k)
|
|
444
|
+
? Array.isArray(v)
|
|
445
|
+
? v.map((e) => maybeNumber(e))
|
|
446
|
+
: maybeNumber(v)
|
|
447
|
+
: v,
|
|
448
|
+
]),
|
|
449
|
+
)
|
|
450
|
+
: parser(ctx),
|
|
451
|
+
);
|
|
311
452
|
}
|
|
312
453
|
return ctx[StateKey].get(target);
|
|
313
454
|
};
|
|
@@ -362,12 +503,12 @@ export const createRouteMiddleware: CreateRouteMiddleware<
|
|
|
362
503
|
(map: Record<string, unknown>, name) => {
|
|
363
504
|
const value = matched ? matched.params[name] : undefined;
|
|
364
505
|
if (Array.isArray(value)) {
|
|
365
|
-
map[name] =
|
|
366
|
-
? value.map(
|
|
506
|
+
map[name] = numericProperties.params.includes(name)
|
|
507
|
+
? value.map((e) => maybeNumber(e))
|
|
367
508
|
: value;
|
|
368
509
|
} else if (value) {
|
|
369
|
-
map[name] =
|
|
370
|
-
?
|
|
510
|
+
map[name] = numericProperties.params.includes(name)
|
|
511
|
+
? maybeNumber(value)
|
|
371
512
|
: value;
|
|
372
513
|
}
|
|
373
514
|
return map;
|
|
@@ -610,7 +751,7 @@ export const routerFactory: RouterFactory<Router<never>, never> = (factory) => {
|
|
|
610
751
|
};
|
|
611
752
|
return factory({ createRouter });
|
|
612
753
|
};
|
|
613
|
-
`,
|
|
754
|
+
`,V=`import { join } from "node:path";
|
|
614
755
|
|
|
615
756
|
import type { RouteSource } from "@kosmojs/core/api";
|
|
616
757
|
|
|
@@ -651,13 +792,11 @@ export const routeSources: Array<RouteSource<never>> = [
|
|
|
651
792
|
file: "{{file}}",
|
|
652
793
|
cascadingMiddleware: [ {{#each cascadingMiddleware}}{{id}}, {{/each}}].flat() as Array<never>,
|
|
653
794
|
definitionItems: {{id}} as never,
|
|
654
|
-
params: [ {{#each params.schema}}"{{name}}", {{/each}}],
|
|
655
|
-
numericParams: [ {{#each numericParams}}"{{.}}", {{/each}}],
|
|
656
795
|
validationSchemas: {{id}}_schemas,
|
|
657
796
|
},
|
|
658
797
|
{{/each}}
|
|
659
798
|
];
|
|
660
|
-
`,
|
|
799
|
+
`,pe=`import { chmod, unlink } from "node:fs/promises";
|
|
661
800
|
import { parseArgs, styleText } from "node:util";
|
|
662
801
|
|
|
663
802
|
import { createAdaptorServer } from "@hono/node-server";
|
|
@@ -757,7 +896,7 @@ process.on("unhandledRejection", (reason) => {
|
|
|
757
896
|
process.exit(1);
|
|
758
897
|
}
|
|
759
898
|
});
|
|
760
|
-
`,
|
|
899
|
+
`,me=`import type { Context, Next } from "hono";
|
|
761
900
|
|
|
762
901
|
import type { ValidationDefmap, ValidationOptmap } from "@kosmojs/core";
|
|
763
902
|
import {
|
|
@@ -940,13 +1079,13 @@ export const defineRoute: <
|
|
|
940
1079
|
use: use as never,
|
|
941
1080
|
});
|
|
942
1081
|
};
|
|
943
|
-
`,
|
|
1082
|
+
`,he=`export * from "./@api/app";
|
|
944
1083
|
export * from "./@api/dev";
|
|
945
1084
|
export * from "./@api/errors";
|
|
946
1085
|
export * from "./@api/router";
|
|
947
1086
|
export * from "./@api/routes";
|
|
948
1087
|
export * from "./@api/server";
|
|
949
|
-
`,
|
|
1088
|
+
`,ge=`import defaultErrorHandler from "./errors";
|
|
950
1089
|
import router from "./router";
|
|
951
1090
|
|
|
952
1091
|
import { appFactory, routes } from "{{ createImport 'lib' 'api:factory' }}";
|
|
@@ -962,7 +1101,7 @@ export default appFactory(({ createApp }) => {
|
|
|
962
1101
|
|
|
963
1102
|
return app;
|
|
964
1103
|
});
|
|
965
|
-
`,
|
|
1104
|
+
`,_e=`import { getRequestListener } from "@hono/node-server";
|
|
966
1105
|
|
|
967
1106
|
import app from "./app";
|
|
968
1107
|
|
|
@@ -976,11 +1115,11 @@ export default devSetup({
|
|
|
976
1115
|
// close db connections, server sockets etc.
|
|
977
1116
|
},
|
|
978
1117
|
});
|
|
979
|
-
`,
|
|
1118
|
+
`,ve=`export declare module "{{ createImport 'libApi' }}" {
|
|
980
1119
|
interface DefaultVariables {}
|
|
981
1120
|
interface DefaultBindings {}
|
|
982
1121
|
}
|
|
983
|
-
`,
|
|
1122
|
+
`,ye=`import { accepts } from "hono/accepts";
|
|
984
1123
|
import { HTTPException } from "hono/http-exception";
|
|
985
1124
|
|
|
986
1125
|
import { ValidationError, HTTPError } from "@kosmojs/core/errors";
|
|
@@ -1014,7 +1153,7 @@ export default errorHandlerFactory(
|
|
|
1014
1153
|
: ctx.text(message, status);
|
|
1015
1154
|
},
|
|
1016
1155
|
);
|
|
1017
|
-
`,
|
|
1156
|
+
`,be=`import { defineRoute } from "{{ createImport 'libApi' }}";
|
|
1018
1157
|
|
|
1019
1158
|
export default defineRoute<"{{route.name}}">(({ GET }) => [
|
|
1020
1159
|
GET(async (ctx) => {
|
|
@@ -1023,7 +1162,7 @@ export default defineRoute<"{{route.name}}">(({ GET }) => [
|
|
|
1023
1162
|
return ctx.text("Automatically generated route");
|
|
1024
1163
|
}),
|
|
1025
1164
|
]);
|
|
1026
|
-
`,
|
|
1165
|
+
`,xe=`import { use } from "{{ createImport 'libApi' }}";
|
|
1027
1166
|
|
|
1028
1167
|
export type UseT = {};
|
|
1029
1168
|
|
|
@@ -1034,20 +1173,20 @@ export default [
|
|
|
1034
1173
|
return next();
|
|
1035
1174
|
}),
|
|
1036
1175
|
];
|
|
1037
|
-
`,
|
|
1176
|
+
`,Se=`import { routerFactory } from "{{ createImport 'lib' 'api:factory' }}";
|
|
1038
1177
|
|
|
1039
1178
|
export default routerFactory(({ createRouter }) => {
|
|
1040
1179
|
const router = createRouter();
|
|
1041
1180
|
return router;
|
|
1042
1181
|
});
|
|
1043
|
-
`,
|
|
1182
|
+
`,Ce=`import app from "./app";
|
|
1044
1183
|
|
|
1045
1184
|
import { serverFactory } from "{{ createImport 'lib' 'api:factory' }}";
|
|
1046
1185
|
|
|
1047
1186
|
serverFactory(async ({ createServer }) => {
|
|
1048
1187
|
await createServer(app);
|
|
1049
1188
|
});
|
|
1050
|
-
`,
|
|
1189
|
+
`,we=`import { use } from "{{ createImport 'libApi' }}";
|
|
1051
1190
|
|
|
1052
1191
|
/**
|
|
1053
1192
|
* Define global middleware applied to all routes.
|
|
@@ -1058,7 +1197,7 @@ export default [
|
|
|
1058
1197
|
return next();
|
|
1059
1198
|
}),
|
|
1060
1199
|
];
|
|
1061
|
-
`,
|
|
1200
|
+
`,Te=f((t,n)=>{let{createPath:r,createImportHelpers:i}=h(t),a=e=>e.length===0?`{}`:e.length===1?e[0]:`Override<${e[0]}, ${a(e.slice(1))}>`,{renderToFile:o}=_({helpers:{...i({origin:`lib`}),...b(),paramsDefaults({params:e}){return`[${e.schema.map(()=>`unknown?`).join(`, `)}]`},paramsMappings({params:e}){return`[${e.schema.map(({name:e,kind:t})=>`["${e}", unknown, ${t===`required`?`true`:`false`}]`).join(`, `)}]`},cascadingState({cascadingMiddleware:e}){return a(e.map(({id:e})=>`UseT${e}`))}}}),{renderToFile:c}=_({helpers:i({origin:`src`})}),u=e=>e?.trim().length===0,d=s(n?.templates,be),f=async e=>{for(let{kind:t,entry:n}of e)t===`apiRoute`?await c(r.api(n.file),d(n.name,n),{route:n},{overwrite:u}):t===`apiUse`&&await c(r.api(n.file),xe,{},{overwrite:u})},p=async t=>{let i=t.flatMap(({kind:e,entry:t})=>e===`apiUse`?[t]:[]),a=t.flatMap(({kind:t,entry:r})=>{if(t!==`apiRoute`)return[];let a=r.name.split(`/`).reduce((t,n)=>{let r=t[t.length-1];return t.push(r?e(r,n):n),t},[]),o={...r,path:r.honoPattern,cascadingMiddleware:i.flatMap(e=>a.some(t=>e.name===t)?[e]:[])};return[o,...Object.entries({...n?.alias}).flatMap(([e,t])=>{let n=g(e);return t===r.name?[{...o,name:e,id:`${o.id}_${x(e)}`,fullpath:l(n),pathTokens:n}]:[]})]}).sort(v);for(let[e,t]of[[`@api/routes.ts`,V]])await o(r.lib(e),t,{routes:a,cascadingMiddleware:i})};return{config({command:e}){return{define:{KOSMO_PRODUCTION_BUILD:e===`build`?`true`:`false`}}},async start(){for(let[e,t]of[[`api.ts`,me],[`api:factory.ts`,he],[`@api/app.ts`,I],[`@api/parsers.ts`,z],[`@api/dev.ts`,L],[`@api/errors.ts`,R],[`@api/router.ts`,B],[`@api/server.ts`,pe]])await o(r.lib(e),t,{});for(let[e,t]of[[`app.ts`,ge],[`dev.ts`,_e],[`errors.ts`,ye],[`router.ts`,Se],[`server.ts`,Ce],[`use.ts`,we]])await c(r.api(e),t,{},{overwrite:u});await o(r.api(`env.d.ts`),ve,{},{overwrite:u})},async watch(e,t){(!t||t.kind===`create`)&&await f(e),await p(e)},async build(e){await f(e),await p(e)}}}),Ee=d({meta:{name:`Hono`,slot:`backend`},dependencies:{hono:F.devDependencies.hono,"@hono/node-server":F.devDependencies[`@hono/node-server`],"path-to-regexp":F.devDependencies[`path-to-regexp`]},factory:Te}),H={type:`module`,private:!0,name:`@kosmojs/koa-generator`,version:`0.2.10`,author:`Slee Woo`,license:`MIT`,files:[`pkg/*`],exports:{".":{types:`./pkg/index.d.ts`,default:`./pkg/index.js`},"./lib":{types:`./pkg/lib.d.ts`,default:`./pkg/lib.js`}},scripts:{build:`wsbuild src/index.ts src/lib.ts`,test:`vitest --root ../.. --project generators/koa-generator`},dependencies:{"@kosmojs/core":`workspace:^`,"@kosmojs/lib":`workspace:^`,crc:`^4.3.2`},devDependencies:{"@koa/router":`^15.7.0`,"@types/formidable":`^3.5.1`,"@types/koa":`^3.0.3`,"@types/koa-compose":`^3.2.9`,formidable:`^3.5.4`,koa:`^3.2.1`,"koa-compose":`^4.1.0`,"light-my-request":`^6.6.0`,"path-to-regexp":`^8.4.2`,"raw-body":`^4.0.0`,vite:`^8.2.1`}},De=`import Koa from "koa";
|
|
1062
1201
|
|
|
1063
1202
|
import type { AppFactory } from "@kosmojs/core/api";
|
|
1064
1203
|
|
|
@@ -1076,10 +1215,10 @@ export const appFactory: AppFactory<App, AppOptions> = (factory) => {
|
|
|
1076
1215
|
};
|
|
1077
1216
|
return factory({ createApp });
|
|
1078
1217
|
};
|
|
1079
|
-
`,
|
|
1218
|
+
`,Oe=`import type { DevSetup } from "@kosmojs/core/api";
|
|
1080
1219
|
|
|
1081
1220
|
export const devSetup = (setup: DevSetup) => setup;
|
|
1082
|
-
`,
|
|
1221
|
+
`,ke=`import type { ParameterizedMiddleware } from "../api";
|
|
1083
1222
|
|
|
1084
1223
|
export type ErrorHandlerFactory = (
|
|
1085
1224
|
h: ParameterizedMiddleware,
|
|
@@ -1088,7 +1227,7 @@ export type ErrorHandlerFactory = (
|
|
|
1088
1227
|
export const errorHandlerFactory: ErrorHandlerFactory = (handler) => {
|
|
1089
1228
|
return handler;
|
|
1090
1229
|
};
|
|
1091
|
-
`,
|
|
1230
|
+
`,Ae=`import zlib from "node:zlib";
|
|
1092
1231
|
|
|
1093
1232
|
import type { RouterContext } from "@koa/router";
|
|
1094
1233
|
import Formidable, { type Options as FormidableOptions } from "formidable";
|
|
@@ -1297,7 +1436,7 @@ export const bodyparsers: {
|
|
|
1297
1436
|
return rawParser(stream, rawParserOptions);
|
|
1298
1437
|
},
|
|
1299
1438
|
};
|
|
1300
|
-
`,
|
|
1439
|
+
`,je=`import KoaRouter, { type RouterMiddleware } from "@koa/router";
|
|
1301
1440
|
import { match } from "path-to-regexp";
|
|
1302
1441
|
|
|
1303
1442
|
import type {
|
|
@@ -1326,6 +1465,7 @@ import { type BodyparserOptions, bodyparsers, metaparsers } from "./parsers";
|
|
|
1326
1465
|
import { routeSources } from "./routes";
|
|
1327
1466
|
|
|
1328
1467
|
import globalMiddleware from "{{ createImport 'api' 'use' }}";
|
|
1468
|
+
import { apiRouteMap } from "{{ createImport 'libCore' }}";
|
|
1329
1469
|
|
|
1330
1470
|
export type Router = import("@koa/router").Router<DefaultState, DefaultContext>;
|
|
1331
1471
|
export type RouterOptions = import("@koa/router").RouterOptions;
|
|
@@ -1345,7 +1485,15 @@ export type RouterOptions = import("@koa/router").RouterOptions;
|
|
|
1345
1485
|
* */
|
|
1346
1486
|
export const createRouteMiddleware: CreateRouteMiddleware<
|
|
1347
1487
|
ParameterizedMiddleware
|
|
1348
|
-
> = ({ name, pathPattern,
|
|
1488
|
+
> = ({ name, pathPattern, validationSchemas }) => {
|
|
1489
|
+
const route = apiRouteMap[name];
|
|
1490
|
+
|
|
1491
|
+
if (!route) {
|
|
1492
|
+
throw new Error(\`createRouteMiddleware: \${name} route does not exists\`);
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
const { params, numericProperties } = route;
|
|
1496
|
+
|
|
1349
1497
|
const pathMatcher = match(pathPattern);
|
|
1350
1498
|
|
|
1351
1499
|
const matchPath = (path: string) => {
|
|
@@ -1355,6 +1503,15 @@ export const createRouteMiddleware: CreateRouteMiddleware<
|
|
|
1355
1503
|
return undefined;
|
|
1356
1504
|
}
|
|
1357
1505
|
};
|
|
1506
|
+
|
|
1507
|
+
const maybeNumber = (val: unknown) => {
|
|
1508
|
+
if (val === undefined || val === null) {
|
|
1509
|
+
return val;
|
|
1510
|
+
}
|
|
1511
|
+
const n = Number(val);
|
|
1512
|
+
return Number.isFinite(n) ? n : val;
|
|
1513
|
+
};
|
|
1514
|
+
|
|
1358
1515
|
const validationMiddleware = [
|
|
1359
1516
|
/**
|
|
1360
1517
|
* Extends Koa context with:
|
|
@@ -1392,7 +1549,21 @@ export const createRouteMiddleware: CreateRouteMiddleware<
|
|
|
1392
1549
|
];
|
|
1393
1550
|
map[target] = () => {
|
|
1394
1551
|
if (!ctx[StateKey].has(target)) {
|
|
1395
|
-
ctx[StateKey].set(
|
|
1552
|
+
ctx[StateKey].set(
|
|
1553
|
+
target,
|
|
1554
|
+
target === "query"
|
|
1555
|
+
? Object.fromEntries(
|
|
1556
|
+
Object.entries(parser(ctx)).map(([k, v]) => [
|
|
1557
|
+
k,
|
|
1558
|
+
numericProperties.query[ctx.method]?.includes(k)
|
|
1559
|
+
? Array.isArray(v)
|
|
1560
|
+
? v.map((e) => maybeNumber(e))
|
|
1561
|
+
: maybeNumber(v)
|
|
1562
|
+
: v,
|
|
1563
|
+
]),
|
|
1564
|
+
)
|
|
1565
|
+
: parser(ctx),
|
|
1566
|
+
);
|
|
1396
1567
|
}
|
|
1397
1568
|
return ctx[StateKey].get(target);
|
|
1398
1569
|
};
|
|
@@ -1447,12 +1618,12 @@ export const createRouteMiddleware: CreateRouteMiddleware<
|
|
|
1447
1618
|
(map: Record<string, unknown>, name) => {
|
|
1448
1619
|
const value = matched ? matched.params[name] : undefined;
|
|
1449
1620
|
if (Array.isArray(value)) {
|
|
1450
|
-
map[name] =
|
|
1451
|
-
? value.map(
|
|
1621
|
+
map[name] = numericProperties.params.includes(name)
|
|
1622
|
+
? value.map((e) => maybeNumber(e))
|
|
1452
1623
|
: value;
|
|
1453
1624
|
} else if (value) {
|
|
1454
|
-
map[name] =
|
|
1455
|
-
?
|
|
1625
|
+
map[name] = numericProperties.params.includes(name)
|
|
1626
|
+
? maybeNumber(value)
|
|
1456
1627
|
: value;
|
|
1457
1628
|
}
|
|
1458
1629
|
return map;
|
|
@@ -1696,7 +1867,7 @@ export const routerFactory: RouterFactory<Router, RouterOptions> = (
|
|
|
1696
1867
|
};
|
|
1697
1868
|
return factory({ createRouter });
|
|
1698
1869
|
};
|
|
1699
|
-
`,
|
|
1870
|
+
`,Me=`import { join } from "node:path";
|
|
1700
1871
|
|
|
1701
1872
|
import type { RouteSource } from "@kosmojs/core/api";
|
|
1702
1873
|
|
|
@@ -1737,13 +1908,11 @@ export const routeSources: Array<RouteSource<never>> = [
|
|
|
1737
1908
|
file: "{{file}}",
|
|
1738
1909
|
cascadingMiddleware: [ {{#each cascadingMiddleware}}{{id}}, {{/each}}].flat() as Array<never>,
|
|
1739
1910
|
definitionItems: {{id}} as never,
|
|
1740
|
-
params: [ {{#each params.schema}}"{{name}}", {{/each}}],
|
|
1741
|
-
numericParams: [ {{#each numericParams}}"{{.}}", {{/each}}],
|
|
1742
1911
|
validationSchemas: {{id}}_schemas,
|
|
1743
1912
|
},
|
|
1744
1913
|
{{/each}}
|
|
1745
1914
|
] as const;
|
|
1746
|
-
`,
|
|
1915
|
+
`,Ne=`import { chmod, unlink } from "node:fs/promises";
|
|
1747
1916
|
import { parseArgs, styleText } from "node:util";
|
|
1748
1917
|
|
|
1749
1918
|
import type { ServerFactory } from "@kosmojs/core/api";
|
|
@@ -1821,7 +1990,7 @@ process.on("unhandledRejection", (reason) => {
|
|
|
1821
1990
|
process.exit(1);
|
|
1822
1991
|
}
|
|
1823
1992
|
});
|
|
1824
|
-
`,
|
|
1993
|
+
`,Pe=`import type { RouterContext } from "@koa/router";
|
|
1825
1994
|
import type { Next } from "koa";
|
|
1826
1995
|
|
|
1827
1996
|
import type { ValidationDefmap, ValidationOptmap } from "@kosmojs/core";
|
|
@@ -1983,13 +2152,13 @@ export const defineRoute: <
|
|
|
1983
2152
|
use: use as never,
|
|
1984
2153
|
});
|
|
1985
2154
|
};
|
|
1986
|
-
`,
|
|
2155
|
+
`,Fe=`export * from "./@api/app";
|
|
1987
2156
|
export * from "./@api/dev";
|
|
1988
2157
|
export * from "./@api/errors";
|
|
1989
2158
|
export * from "./@api/router";
|
|
1990
2159
|
export * from "./@api/routes";
|
|
1991
2160
|
export * from "./@api/server";
|
|
1992
|
-
`,
|
|
2161
|
+
`,Ie=`import router from "./router";
|
|
1993
2162
|
|
|
1994
2163
|
import { appFactory } from "{{ createImport 'lib' 'api:factory' }}";
|
|
1995
2164
|
|
|
@@ -2001,7 +2170,7 @@ export default appFactory(({ createApp }) => {
|
|
|
2001
2170
|
|
|
2002
2171
|
return app;
|
|
2003
2172
|
});
|
|
2004
|
-
`,
|
|
2173
|
+
`,Le=`import app from "./app";
|
|
2005
2174
|
|
|
2006
2175
|
import { devSetup } from "{{ createImport 'lib' 'api:factory' }}";
|
|
2007
2176
|
|
|
@@ -2013,11 +2182,11 @@ export default devSetup({
|
|
|
2013
2182
|
// close db connections, server sockets etc.
|
|
2014
2183
|
},
|
|
2015
2184
|
});
|
|
2016
|
-
`,
|
|
2185
|
+
`,Re=`export declare module "{{ createImport 'libApi' }}" {
|
|
2017
2186
|
interface DefaultState {}
|
|
2018
2187
|
interface DefaultContext {}
|
|
2019
2188
|
}
|
|
2020
|
-
`,
|
|
2189
|
+
`,ze=`import { HTTPError, ValidationError } from "@kosmojs/core/errors";
|
|
2021
2190
|
|
|
2022
2191
|
import { errorHandlerFactory } from "{{ createImport 'lib' 'api:factory' }}";
|
|
2023
2192
|
|
|
@@ -2044,14 +2213,14 @@ export default errorHandlerFactory(
|
|
|
2044
2213
|
}
|
|
2045
2214
|
},
|
|
2046
2215
|
);
|
|
2047
|
-
`,
|
|
2216
|
+
`,Be=`import { defineRoute } from "{{ createImport 'libApi' }}";
|
|
2048
2217
|
|
|
2049
2218
|
export default defineRoute<"{{route.name}}">(({ GET }) => [
|
|
2050
2219
|
GET(async (ctx) => {
|
|
2051
2220
|
ctx.body = "Automatically generated route";
|
|
2052
2221
|
}),
|
|
2053
2222
|
]);
|
|
2054
|
-
`,
|
|
2223
|
+
`,Ve=`import { use } from "{{ createImport 'libApi' }}";
|
|
2055
2224
|
|
|
2056
2225
|
export type UseT = {};
|
|
2057
2226
|
|
|
@@ -2062,7 +2231,7 @@ export default [
|
|
|
2062
2231
|
return next();
|
|
2063
2232
|
}),
|
|
2064
2233
|
];
|
|
2065
|
-
`,
|
|
2234
|
+
`,He=`import { routerFactory, routes } from "{{ createImport 'lib' 'api:factory' }}";
|
|
2066
2235
|
|
|
2067
2236
|
export default routerFactory(({ createRouter }) => {
|
|
2068
2237
|
const router = createRouter();
|
|
@@ -2073,14 +2242,14 @@ export default routerFactory(({ createRouter }) => {
|
|
|
2073
2242
|
|
|
2074
2243
|
return router;
|
|
2075
2244
|
});
|
|
2076
|
-
`,
|
|
2245
|
+
`,Ue=`import app from "./app";
|
|
2077
2246
|
|
|
2078
2247
|
import { serverFactory } from "{{ createImport 'lib' 'api:factory' }}";
|
|
2079
2248
|
|
|
2080
2249
|
serverFactory(async ({ createServer }) => {
|
|
2081
2250
|
await createServer(app);
|
|
2082
2251
|
});
|
|
2083
|
-
`,
|
|
2252
|
+
`,We=`import defaultErrorHandler from "./errors";
|
|
2084
2253
|
|
|
2085
2254
|
import { use } from "{{ createImport 'libApi' }}";
|
|
2086
2255
|
|
|
@@ -2091,12 +2260,17 @@ export default [
|
|
|
2091
2260
|
* */
|
|
2092
2261
|
use(defaultErrorHandler, { slot: "errorHandler" }),
|
|
2093
2262
|
];
|
|
2094
|
-
`,
|
|
2263
|
+
`,Ge=f((t,n)=>{let{createPath:r,createImportHelpers:i}=h(t),a=e=>e.length===0?`{}`:e.length===1?e[0]:`Override<${e[0]}, ${a(e.slice(1))}>`,{renderToFile:o}=_({helpers:{...i({origin:`lib`}),...b(),paramsDefaults({params:e}){return`[${e.schema.map(()=>`unknown?`).join(`, `)}]`},paramsMappings({params:e}){return`[${e.schema.map(({name:e,kind:t})=>`["${e}", unknown, ${t===`required`?`true`:`false`}]`).join(`, `)}]`},cascadingState({cascadingMiddleware:e}){return a(e.map(({id:e})=>`UseT${e}`))}}}),{renderToFile:c}=_({helpers:i({origin:`src`})}),l=e=>e?.trim().length===0,d=s(n?.templates,Be),f=async e=>{for(let{kind:t,entry:n}of e)t===`apiRoute`?await c(r.api(n.file),d(n.name,n),{route:n},{overwrite:l}):t===`apiUse`&&await c(r.api(n.file),Ve,{},{overwrite:l})},p=async t=>{let i=t.flatMap(({kind:e,entry:t})=>e===`apiUse`?[t]:[]),a=t.flatMap(({kind:t,entry:r})=>{if(t!==`apiRoute`)return[];let a=r.name.split(`/`).reduce((t,n)=>{let r=t[t.length-1];return t.push(r?e(r,n):n),t},[]),o={...r,path:r.pathPattern,cascadingMiddleware:i.flatMap(e=>a.some(t=>e.name===t)?[e]:[])};return[o,...Object.entries({...n?.alias}).flatMap(([e,t])=>{let n=g(e);return t===r.name?[{...o,name:e,id:`${o.id}_${x(e)}`,fullpath:u(n),pathTokens:n}]:[]})]}).sort(v);for(let[e,t]of[[`@api/routes.ts`,Me]])await o(r.lib(e),t,{routes:a,cascadingMiddleware:i})};return{config({command:e}){return{define:{KOSMO_PRODUCTION_BUILD:e===`build`?`true`:`false`}}},async start(){for(let[e,t]of[[`api.ts`,Pe],[`api:factory.ts`,Fe],[`@api/app.ts`,De],[`@api/dev.ts`,Oe],[`@api/errors.ts`,ke],[`@api/parsers.ts`,Ae],[`@api/router.ts`,je],[`@api/server.ts`,Ne]])await o(r.lib(e),t,{});for(let[e,t]of[[`app.ts`,Ie],[`dev.ts`,Le],[`errors.ts`,ze],[`router.ts`,He],[`server.ts`,Ue],[`use.ts`,We]])await c(r.api(e),t,{},{overwrite:l});await o(r.api(`env.d.ts`),Re,{},{overwrite:l})},async watch(e,t){(!t||t.kind===`create`)&&await f(e),await p(e)},async build(e){await f(e),await p(e)}}}),Ke=d({meta:{name:`Koa`,slot:`backend`,types:[`@types/koa`]},dependencies:{koa:H.devDependencies.koa,"@koa/router":H.devDependencies[`@koa/router`],"path-to-regexp":H.devDependencies[`path-to-regexp`],formidable:H.devDependencies.formidable,"raw-body":H.devDependencies[`raw-body`]},devDependencies:{"@types/koa":H.devDependencies[`@types/koa`],"@types/formidable":H.devDependencies[`@types/formidable`]},factory:Ge}),U={type:`module`,private:!0,name:`@kosmojs/mdx-generator`,version:`0.2.10`,author:`Slee Woo`,license:`MIT`,files:[`pkg/*`],exports:{".":{types:`./pkg/index.d.ts`,default:`./pkg/index.js`}},scripts:{build:`wsbuild src/index.ts`},dependencies:{"@kosmojs/core":`workspace:^`,"@kosmojs/lib":`workspace:^`,"@mdx-js/rollup":`^3.1.1`,vite:`^8.2.1`},devDependencies:{"@mdx-js/mdx":`^3.1.1`,"@mdx-js/preact":`^3.1.1`,"path-to-regexp":`^8.4.2`,preact:`^10.29.8`,"preact-render-to-string":`^6.7.0`,"remark-frontmatter":`^5.0.0`,"remark-mdx-frontmatter":`^5.2.0`}},qe=()=>{let e=[`🎉 Well done! You just created a new MDX page.`,`🚀 Success! A fresh MDX page is ready to roll.`,`🌟 Nice work! Another MDX page added to your site.`,`🧩 All set! A new MDX page has been scaffolded.`,`🔧 Scaffold complete! Your new MDX page is in place.`,`✅ Built! Your MDX page is scaffolded and ready.`,`✨ Fantastic! Your new MDX page is good to go.`,`🎯 Nailed it! A brand new MDX page just landed.`,`💫 Awesome! Another MDX page joins the party.`,`⚡ Lightning fast! A new MDX page created successfully.`];return e[Math.floor(Math.random()*e.length)]},Je=(e,t,n)=>{let{remarkPlugins:r=[],rehypePlugins:i=[]}={...n},a=()=>{let t=[`${c.srcDir}/${e.name}/${c.entryDir}/client.ts`].map(e=>C(e)),n=e=>t.some(t=>t(e));return{name:`kosmo:mdx[hmr]`,enforce:`post`,transform(e,t){if(!(!n(t)||e.includes(`import.meta.hot.accept`)))return{code:[e,`
|
|
2095
2264
|
if (import.meta.hot) {
|
|
2096
2265
|
import.meta.hot.accept(() => {});
|
|
2097
2266
|
}
|
|
2098
2267
|
`].join(`
|
|
2099
|
-
`)}}}},o=[ne({jsxImportSource:`preact`,providerImportSource:`@mdx-js/preact`,remarkPlugins:r,rehypePlugins:i})];return t===`serve`&&o.push(a()),o},
|
|
2268
|
+
`)}}}},o=[ne({jsxImportSource:`preact`,providerImportSource:`@mdx-js/preact`,remarkPlugins:r,rehypePlugins:i})];return t===`serve`&&o.push(a()),o},Ye=`import type { FunctionComponent } from "preact";
|
|
2269
|
+
|
|
2270
|
+
export const AppProvider: FunctionComponent = (props) => {
|
|
2271
|
+
return props.children;
|
|
2272
|
+
};
|
|
2273
|
+
`,Xe=`import { render, hydrate as hydrateOrig } from "preact";
|
|
2100
2274
|
import type { RouterFactoryReturn } from "@kosmojs/core";
|
|
2101
2275
|
import { clientRenderFactory } from "@kosmojs/core/generators";
|
|
2102
2276
|
|
|
@@ -2137,7 +2311,7 @@ export const mount = async (
|
|
|
2137
2311
|
}
|
|
2138
2312
|
|
|
2139
2313
|
export default clientRenderFactory();
|
|
2140
|
-
`,
|
|
2314
|
+
`,Ze=`import { renderToString as renderToStringOrig } from "preact-render-to-string";
|
|
2141
2315
|
|
|
2142
2316
|
import type {
|
|
2143
2317
|
RenderToStringWrapper,
|
|
@@ -2211,7 +2385,7 @@ export const renderToString: RenderToStringWrapper<
|
|
|
2211
2385
|
}
|
|
2212
2386
|
|
|
2213
2387
|
export default serverRenderFactory<false>();
|
|
2214
|
-
`,
|
|
2388
|
+
`,Qe=`declare module "*.mdx" {
|
|
2215
2389
|
import type { ComponentType } from "preact";
|
|
2216
2390
|
export const frontmatter: Record<string, unknown>;
|
|
2217
2391
|
const component: ComponentType;
|
|
@@ -2224,7 +2398,7 @@ declare module "*.md" {
|
|
|
2224
2398
|
const component: ComponentType;
|
|
2225
2399
|
export default component;
|
|
2226
2400
|
}
|
|
2227
|
-
|
|
2401
|
+
`,$e=`import { MDXProvider } from "@mdx-js/preact";
|
|
2228
2402
|
import { match, pathToRegexp } from "path-to-regexp";
|
|
2229
2403
|
import { type ComponentType, createContext, h, type VNode } from "preact";
|
|
2230
2404
|
|
|
@@ -2414,7 +2588,7 @@ export const createRoute = (
|
|
|
2414
2588
|
layouts,
|
|
2415
2589
|
};
|
|
2416
2590
|
};
|
|
2417
|
-
`,
|
|
2591
|
+
`,et=`/* @jsxImportSource preact */
|
|
2418
2592
|
|
|
2419
2593
|
import styles from "./styles.module.css";
|
|
2420
2594
|
|
|
@@ -2455,7 +2629,7 @@ export default function PageSample(props: {
|
|
|
2455
2629
|
</div>
|
|
2456
2630
|
);
|
|
2457
2631
|
}
|
|
2458
|
-
`,
|
|
2632
|
+
`,tt=`/* @jsxImportSource preact */
|
|
2459
2633
|
|
|
2460
2634
|
import styles from "./styles.module.css";
|
|
2461
2635
|
|
|
@@ -2507,7 +2681,7 @@ export default function PageSample(props: {
|
|
|
2507
2681
|
</div>
|
|
2508
2682
|
);
|
|
2509
2683
|
}
|
|
2510
|
-
`,
|
|
2684
|
+
`,nt=`* {
|
|
2511
2685
|
margin: 0;
|
|
2512
2686
|
padding: 0;
|
|
2513
2687
|
box-sizing: border-box;
|
|
@@ -2642,7 +2816,7 @@ export default function PageSample(props: {
|
|
|
2642
2816
|
align-items: center;
|
|
2643
2817
|
gap: 0.25rem;
|
|
2644
2818
|
}
|
|
2645
|
-
|
|
2819
|
+
`,rt=`/* @jsxImportSource preact */
|
|
2646
2820
|
|
|
2647
2821
|
import styles from "./styles.module.css";
|
|
2648
2822
|
|
|
@@ -2708,7 +2882,7 @@ export default function WelcomePage() {
|
|
|
2708
2882
|
</div>
|
|
2709
2883
|
);
|
|
2710
2884
|
}
|
|
2711
|
-
`,
|
|
2885
|
+
`,it=`export type ParamsMap = {
|
|
2712
2886
|
{{#each pageRoutes}}"{{name}}": {{serializeParamsLiteral .}};
|
|
2713
2887
|
{{/each}}
|
|
2714
2888
|
};
|
|
@@ -2717,7 +2891,7 @@ export const paramNames = {
|
|
|
2717
2891
|
{{#each pageRoutes}}"{{name}}": [ {{#each params.schema}}"{{name}}", {{/each}}],
|
|
2718
2892
|
{{/each}}
|
|
2719
2893
|
} as const;
|
|
2720
|
-
`,
|
|
2894
|
+
`,at=`import type { ComponentType } from "preact";
|
|
2721
2895
|
|
|
2722
2896
|
import type { RouterFactoryReturn } from "@kosmojs/core";
|
|
2723
2897
|
import { createRouterFactory } from "@kosmojs/core/generators";
|
|
@@ -2761,7 +2935,7 @@ export default createRouterFactory<
|
|
|
2761
2935
|
Promise<RouteComponent>,
|
|
2762
2936
|
{ server: { route: Route } }
|
|
2763
2937
|
>();
|
|
2764
|
-
`,
|
|
2938
|
+
`,ot=`import { join } from "node:path";
|
|
2765
2939
|
|
|
2766
2940
|
import { compile } from "path-to-regexp";
|
|
2767
2941
|
|
|
@@ -2807,7 +2981,7 @@ export default Object.entries(routes)
|
|
|
2807
2981
|
return [];
|
|
2808
2982
|
})
|
|
2809
2983
|
.map((path) => join(base, path));
|
|
2810
|
-
`,
|
|
2984
|
+
`,st=`import type { PageRoute } from "@kosmojs/core";
|
|
2811
2985
|
|
|
2812
2986
|
{{#each pageRoutes}}
|
|
2813
2987
|
import * as {{id}} from "{{ createImport 'pages' file }}";
|
|
@@ -2831,7 +3005,7 @@ const routeMap: Record<
|
|
|
2831
3005
|
}
|
|
2832
3006
|
|
|
2833
3007
|
export default routeMap;
|
|
2834
|
-
`,
|
|
3008
|
+
`,ct=`import { useContext } from "preact/hooks";
|
|
2835
3009
|
|
|
2836
3010
|
import { RouterContext } from "./mdx";
|
|
2837
3011
|
|
|
@@ -2873,8 +3047,10 @@ export const useFrontmatter = <
|
|
|
2873
3047
|
>(): T => {
|
|
2874
3048
|
return useContext(RouterContext).frontmatter as T;
|
|
2875
3049
|
};
|
|
2876
|
-
`,
|
|
2877
|
-
|
|
3050
|
+
`,lt=`import { AppProvider } from "{{ createImport 'lib' 'app' }}";
|
|
3051
|
+
|
|
3052
|
+
<AppProvider>{props.children}</AppProvider>
|
|
3053
|
+
`,ut=`import { h, type JSX } from "preact";
|
|
2878
3054
|
|
|
2879
3055
|
import { pageRouteMap, type LinkProps } from "{{ createImport 'libCore' }}";
|
|
2880
3056
|
|
|
@@ -2891,7 +3067,7 @@ export default function Link(
|
|
|
2891
3067
|
|
|
2892
3068
|
return h("a", { ...restProps, href }, children);
|
|
2893
3069
|
}
|
|
2894
|
-
`,
|
|
3070
|
+
`,dt=`/**
|
|
2895
3071
|
* MDX component overrides.
|
|
2896
3072
|
*
|
|
2897
3073
|
* Every standard markdown element (headings, links, code blocks, etc.)
|
|
@@ -2914,7 +3090,7 @@ export const components = {
|
|
|
2914
3090
|
declare global {
|
|
2915
3091
|
type MDXProvidedComponents = typeof components;
|
|
2916
3092
|
}
|
|
2917
|
-
`,
|
|
3093
|
+
`,ft=`import renderFactory, {
|
|
2918
3094
|
createRoutes,
|
|
2919
3095
|
hydrate,
|
|
2920
3096
|
mount,
|
|
@@ -2941,7 +3117,7 @@ if (root) {
|
|
|
2941
3117
|
} else {
|
|
2942
3118
|
console.error("❌ Root element not found!");
|
|
2943
3119
|
}
|
|
2944
|
-
`,
|
|
3120
|
+
`,pt=`import renderFactory, {
|
|
2945
3121
|
createRoutes,
|
|
2946
3122
|
renderToString,
|
|
2947
3123
|
// no renderToStream on MDX folders
|
|
@@ -2962,7 +3138,7 @@ export default renderFactory(() => {
|
|
|
2962
3138
|
},
|
|
2963
3139
|
};
|
|
2964
3140
|
});
|
|
2965
|
-
`,
|
|
3141
|
+
`,mt=`<!doctype html>
|
|
2966
3142
|
<html lang="en">
|
|
2967
3143
|
<head>
|
|
2968
3144
|
<meta charset="UTF-8" />
|
|
@@ -2974,13 +3150,13 @@ export default renderFactory(() => {
|
|
|
2974
3150
|
<script type="module" src="/{{ entryDir }}/client.ts"><\/script>
|
|
2975
3151
|
</body>
|
|
2976
3152
|
</html>
|
|
2977
|
-
`,
|
|
3153
|
+
`,ht=`import PageSample from "{{ createImport 'lib' 'pageSamples/404.tsx' }}";
|
|
2978
3154
|
|
|
2979
3155
|
export default function Page() {
|
|
2980
3156
|
return <PageSample />;
|
|
2981
3157
|
}
|
|
2982
|
-
`,
|
|
2983
|
-
`,
|
|
3158
|
+
`,gt=`{props.children}
|
|
3159
|
+
`,_t=`---
|
|
2984
3160
|
title: "{{title}}"
|
|
2985
3161
|
---
|
|
2986
3162
|
|
|
@@ -2997,7 +3173,7 @@ export const pathMap = {
|
|
|
2997
3173
|
routeName="{{route.name}}"
|
|
2998
3174
|
pathMap={pathMap}
|
|
2999
3175
|
/>
|
|
3000
|
-
`,
|
|
3176
|
+
`,vt=`---
|
|
3001
3177
|
title: Welcome to KosmoJS
|
|
3002
3178
|
description: Content-first development with MDX and Vite
|
|
3003
3179
|
---
|
|
@@ -3005,9 +3181,9 @@ description: Content-first development with MDX and Vite
|
|
|
3005
3181
|
import WelcomePage from "{{ createImport 'lib' 'pageSamples/welcome.tsx' }}"
|
|
3006
3182
|
|
|
3007
3183
|
<WelcomePage />
|
|
3008
|
-
`,
|
|
3184
|
+
`,yt=`import routerFactory, { createRouters } from "{{ createImport 'lib' 'router' }}";
|
|
3009
3185
|
|
|
3010
|
-
import app from "./
|
|
3186
|
+
import app from "./app.mdx";
|
|
3011
3187
|
import { components } from "./components/mdx"
|
|
3012
3188
|
|
|
3013
3189
|
export default routerFactory((routes) => {
|
|
@@ -3021,7 +3197,31 @@ export default routerFactory((routes) => {
|
|
|
3021
3197
|
},
|
|
3022
3198
|
};
|
|
3023
3199
|
});
|
|
3024
|
-
`,
|
|
3200
|
+
`,bt=f((e,t)=>{let{createPath:n,createImportHelpers:r}=h(e),{renderToFile:i}=_({helpers:{...r({origin:`lib`}),...b(),serializeParams(e){return JSON.stringify(e.params)}}}),{renderToFile:a}=_({helpers:r({origin:`src`})}),o=e=>!e?.trim().length,l=s(t?.templates,_t),u=async e=>{for(let{kind:t,entry:r}of e)t===`pageRoute`?await a(n.pages(r.file),r.name===`index`?vt:l(r.name,r),{route:r,title:r.name.replace(/\{([^}]+)\}/g,`$1`),message:qe()},{overwrite:o}):t===`pageLayout`&&await a(n.pages(r.file),gt,{route:r},{overwrite:o})},d=async e=>{let t=e.flatMap(({kind:e,entry:t})=>e===`pageLayout`?[t]:[]),r=e.flatMap(({kind:e,entry:n})=>{if(e===`pageRoute`){let{name:e,file:r}=n;return[{...n,layouts:t.flatMap(t=>t.name===e||r.startsWith(`${t.name}/`)?[t]:[]).sort(v)}]}return[]}).sort(v);for(let[e,a]of[[`client.ts`,Xe],[`server.ts`,Ze]])await i(n.libEntry(e),a,{pageRoutes:r,layouts:t});for(let[e,t]of[[`params.ts`,it],[`router.ts`,at],[`ssg:routes.ts`,st]])await i(n.lib(e),t,{pageRoutes:r})};return{config({command:n}){return{oxc:{jsx:{importSource:`preact`}},plugins:Je(e,n,t)}},async start(){for(let[e,t]of[[`env.d.ts`,Qe],[`app.ts`,Ye],[`mdx.ts`,$e],[`use.ts`,ct],[`ssg.ts`,ot],[`pageSamples/styles.module.css`,nt],[`pageSamples/welcome.tsx`,rt],[`pageSamples/page.tsx`,tt],[`pageSamples/404.tsx`,et]])await i(n.lib(e),t,{});for(let[e,t]of[[`pages/404.mdx`,ht],[`components/Link.tsx`,ut],[`components/mdx.ts`,dt],[`app.mdx`,lt],[`router.ts`,yt]])await a(n.src(e),t,{entryDir:c.entryDir},{overwrite:o});await a(n.src(`index.html`),mt,{entryDir:c.entryDir},{overwrite:e=>!e?.trim().length||!e.replace(/<!--[\s\S]*?-->/g,``).trim().length});for(let[e,t]of[[`client.ts`,ft],[`server.ts`,pt]])await a(n.entry(e),t,{},{overwrite:o})},async watch(e,t){(!t||t.kind===`create`)&&await u(e),await d(e)},async build(e){await u(e),await d(e)}}}),xt=d({meta:{name:`MDX`,jsxImportSource:`preact`},dependencies:{"path-to-regexp":U.devDependencies[`path-to-regexp`]},devDependencies:{preact:U.devDependencies.preact,"preact-render-to-string":U.devDependencies[`preact-render-to-string`],"@mdx-js/preact":U.devDependencies[`@mdx-js/preact`],"remark-frontmatter":U.devDependencies[`remark-frontmatter`],"remark-mdx-frontmatter":U.devDependencies[`remark-mdx-frontmatter`]},factory:bt}),St={json:`application/json`,form:[`application/x-www-form-urlencoded`,`multipart/form-data`],raw:void 0},Ct=()=>{let t=e=>[`Buffer`,`ArrayBuffer`,`Blob`].includes(e)?{type:`string`,format:`binary`}:ae.Script(e),n=(e,t,n)=>{let r=n?`${t}_${n.replace(/[^\w.-]/g,`_`)}${x(n)}`:t;return`${e.id}_${r}`},r=(e,t,r,i)=>[`#`,`components`,e,n(t,r,i)].join(`/`),a=e=>e.split(`/`).reduce((e,t)=>e+ +!t.includes(`{`),0),o=t=>{if(t.name===`index`)return[`/`];let{tokens:n}=ie(t.pathPattern),r=e=>e.flatMap(e=>{switch(e.type){case`param`:return[e.name];case`wildcard`:return[e.name];case`group`:return r(e.tokens);default:return[]}}),i=(e,t)=>{if(!e.length)return[t];let[n,...a]=e;switch(n.type){case`text`:return i(a,{path:`${t.path}${n.value}`,params:t.params});case`param`:return i(a,{path:`${t.path}{${n.name}}`,params:[...t.params,n.name]});case`wildcard`:return i(a,{path:`${t.path}{${n.name}*}`,params:[...t.params,n.name]});case`group`:{let e=i(a,t),o=i([...n.tokens,...a],t),s=r(n.tokens),c=o.filter(e=>s.some(t=>e.params.includes(t)));return[...e,...c]}}},o=i(n,{path:``,params:[]}),s=t.params.schema.reduce((e,{name:t},n)=>(e[n]=t,e),{});return o.reduce((t,n)=>{let r=e(`/`,n.path);return t.includes(r)||n.params.every((e,t)=>e===s[t])&&t.push(r),t},[]).sort((e,t)=>a(t)-a(e))},s=(e,t)=>{let n=e.params.resolvedType?.properties?.flatMap(n=>RegExp(`\\{${n.name}\\*?\\}`).test(t)?[{$ref:r(`parameters`,e,e.params.id,n.name)}]:[]);return n?.length?n:void 0},c=(e,t)=>{let n=e.validationDefinitions.find(e=>e.method===t&&e.target===`response`);return Array.isArray(n?.variants)?n.variants.reduce((t,{id:n,status:i,contentType:a,body:o})=>(t[i]=wt(i,a)||{description:`Success`,content:{[a||`application/json`]:{schema:o?{$ref:r(`schemas`,e,n)}:{type:`object`}}}},t),{}):{200:{description:`Success - TODO: Add response schema`,content:{"text/plain":{schema:{type:`string`}}}}}},l=e=>{let{parameters:r,schemas:i}={parameters:{},schemas:{}};for(let r of e.validationDefinitions)if(r.target===`response`)for(let{id:a,resolvedType:o}of r.variants)o?.typeboxSchema&&(i[n(e,a)]=t(o.typeboxSchema));else if(r.target===`query`){let{id:a,resolvedType:o}=r.schema;for(let r of o?.properties||[])if(r?.typeboxSchema){let o=n(e,a,r.name);i[o]=t(r.typeboxSchema)}}else{let{id:a,resolvedType:o}=r.schema;o?.typeboxSchema&&(i[n(e,a)]=t(o.typeboxSchema))}if(e.params.resolvedType)for(let i of e.params.resolvedType.properties||[])i?.typeboxSchema&&(r[n(e,e.params.id,i.name)]={name:i.name,in:`path`,required:!0,schema:t(i.typeboxSchema)});return{parameters:r,schemas:i}},u=e=>{let t={},n=e.validationDefinitions.flatMap(e=>e.target===`response`?[]:e.schema.resolvedType?[e]:[]);for(let a of o(e))for(let o of e.methods){let l={responses:c(e,o)},u=s(e,a);u&&(l.parameters=u);let d=n.find(e=>e.method===o&&e.target===`query`);if(d?.schema)for(let t of d.schema.resolvedType?.properties||[])l.parameters||=[],l.parameters.push({name:t.name,in:`query`,required:!t.optional,schema:{$ref:r(`schemas`,e,d.schema.id,t.name)}});let f=n.filter(e=>e.method===o&&Object.keys(i).includes(e.target));f.length&&(l.requestBody={required:!0,content:f.reduce((t,n)=>{let{contentType:i=St[n.target]}=n;if(i){let a={$ref:r(`schemas`,e,n.schema.id)};for(let e of[i].flat())t[e]={schema:a}}return t},{})}),t[a]||(t[a]={}),t[a][o.toLowerCase()]=l}return t};return{generateComponentId:n,generateComponentPath:r,generatePathVariations:o,generateOpenAPISchema:e=>{let{components:t,paths:n}=e.sort(v).flatMap(t=>e.some(e=>e.name!==t.name&&e.name.startsWith(t.name))?[]:[t]).reduce((e,t)=>{let n=u(t),{parameters:r,schemas:i}=l(t);return{paths:{...e.paths,...n},components:{parameters:{...e.components.parameters,...r},schemas:{...e.components.schemas,...i}}}},{paths:{},components:{parameters:{},schemas:{}}});return{paths:n,components:t}}}},wt=(e,t)=>{let n={type:`string`,format:`uri`,...t?{enum:[t]}:{}};return{301:{description:`Moved Permanently`,headers:{Location:{description:`New permanent location`,schema:n}}},302:{description:`Found`,headers:{Location:{description:`Temporary location`,schema:n}}},303:{description:`See Other`,headers:{Location:{description:`Location to GET after POST/PUT/DELETE`,schema:n}}},307:{description:`Temporary Redirect`,headers:{Location:{description:`Temporary location (preserves request method)`,schema:n}}},308:{description:`Permanent Redirect`,headers:{Location:{description:`New permanent location (preserves request method)`,schema:n}}}}[e]},Tt=f((e,t)=>{let{outfile:n=``,...r}={...t},{createPath:i}=h(e),{generateOpenAPISchema:a}=Ct(),o=async e=>{let t=e.flatMap(({kind:e,entry:t})=>e===`apiRoute`?[t]:[]),{paths:o,components:s}=a(t),c={...JSON.parse(JSON.stringify(r)),paths:o,components:s},l=/ya?ml/.test(n)?re.stringify(c):JSON.stringify(c,null,2);await ee(i.src(n),l,{})};return{async watch(e){await o(e)},async build(e){await o(e)}}}),Et=d({meta:{name:`OpenAPI`,resolveTypes:!0},factory:Tt}),W={type:`module`,private:!0,name:`@kosmojs/react-generator`,version:`0.2.10`,author:`Slee Woo`,license:`MIT`,files:[`pkg/*`],exports:{".":{types:`./pkg/index.d.ts`,default:`./pkg/index.js`}},scripts:{build:`wsbuild src/index.ts`,test:`vitest --root ../.. --project generators/react-generator`},dependencies:{"@kosmojs/core":`workspace:^`,"@kosmojs/lib":`workspace:^`,"@vitejs/plugin-react":`^6.0.5`},devDependencies:{"@tanstack/react-query":`^5.101.4`,"@types/react":`^19.2.18`,"@types/react-dom":`^19.2.4`,"path-to-regexp":`^8.4.2`,react:`^19.2.8`,"react-dom":`^19.2.8`,"react-router":`^8.3.0`}},Dt=e=>{let t=e.map(e=>e.orig).join(`/`),r=e=>e.kind===`splat`?`*`:e.kind===`optional`?`:${e.name}?`:`:${e.name}`;return e.flatMap(e=>e.kind===`static`?[e.parts[0].value]:e.kind===`param`?[r(e.parts[0])]:(/\.\w+$/.test(e.orig)||(console.warn(`❗${n([`red`,`bold`],`WARN`)}: React Router v7 only supports dot-suffix mixed segments (e.g. :param.html).`),console.warn(` ${n([`magenta`],e.orig)} in ${n([`blue`],t)} route won't match as expected.`),console.warn()),[e.parts.map(e=>e.type===`static`?e.value:r(e)).join(``)])).join(`/`)},Ot=()=>{let e=e=>e?.kind===`param`&&e.parts[0]?.kind===`splat`,t=n=>n.flatMap(({index:n,layout:r,children:i})=>{let{name:a,pathTokens:o}={...n,...r};if(!o)return[];let s=`${a}:layout`,c=Dt(o),l=o.at(-1);return e(l)?n&&r?[{name:s,path:c,component:r.id,children:[{name:a,path:`*`,component:n.id}]}]:n?[{path:c,children:[{name:a,path:`*`,component:n.id},...t(i)]}]:r?[{name:s,path:c,component:r.id,children:t(i)}]:[]:n&&r?[{name:s,path:c,component:r.id,children:[{name:a,index:!0,component:n.id},...t(i)]}]:n?[{path:c,children:[{name:a,index:!0,component:n.id},...t(i)]}]:r?[{name:s,path:c,component:r.id,children:t(i)}]:[]});return t},kt=()=>{let e=[`🎉 Well done! You just created a new React route.`,`🚀 Success! A fresh React route is ready to roll.`,`🌟 Nice work! Another React route added to your app.`,`⚡ Quick and easy! Your new React route is good to go.`,`🥳 Congrats! Your app just leveled up with a new React route.`,`🧩 All set! A new React route has been scaffolded.`,`🔧 Scaffold complete! Your new React route is in place.`,`✨ Fantastic! Your new React route is ready.`,`🎯 Nailed it! A brand new React route just landed.`,`💫 Awesome! Another React route joins the lineup.`];return e[Math.floor(Math.random()*e.length)]},At=`import type { ReactNode } from "react";
|
|
3201
|
+
|
|
3202
|
+
export const AppProvider = ({ children }: { children: ReactNode }) => {
|
|
3203
|
+
return children;
|
|
3204
|
+
}
|
|
3205
|
+
`,jt=`import { type QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
3206
|
+
import type { ReactNode } from "react";
|
|
3207
|
+
|
|
3208
|
+
import { getQueryClient } from "./query";
|
|
3209
|
+
|
|
3210
|
+
export const AppProvider = ({
|
|
3211
|
+
client,
|
|
3212
|
+
children,
|
|
3213
|
+
}: {
|
|
3214
|
+
client?: QueryClient;
|
|
3215
|
+
children: ReactNode;
|
|
3216
|
+
}) => {
|
|
3217
|
+
const queryClient = client ?? getQueryClient();
|
|
3218
|
+
return (
|
|
3219
|
+
<QueryClientProvider client={queryClient}>
|
|
3220
|
+
{children}
|
|
3221
|
+
</QueryClientProvider>
|
|
3222
|
+
);
|
|
3223
|
+
}
|
|
3224
|
+
`,Mt=`import { lazy, type JSX } from "react";
|
|
3025
3225
|
|
|
3026
3226
|
import {
|
|
3027
3227
|
createRoot,
|
|
@@ -3075,7 +3275,7 @@ export const mount = async (
|
|
|
3075
3275
|
}
|
|
3076
3276
|
|
|
3077
3277
|
export default clientRenderFactory();
|
|
3078
|
-
`,
|
|
3278
|
+
`,Nt=`{
|
|
3079
3279
|
{{#if name}}
|
|
3080
3280
|
id: "{{name}}",
|
|
3081
3281
|
{{/if}}
|
|
@@ -3093,7 +3293,7 @@ export default clientRenderFactory();
|
|
|
3093
3293
|
children: [ {{#each children}}{{> routePartial}}, {{/each}}],
|
|
3094
3294
|
{{/if}}
|
|
3095
3295
|
}
|
|
3096
|
-
`,
|
|
3296
|
+
`,Pt=`import type { JSX } from "react";
|
|
3097
3297
|
|
|
3098
3298
|
import {
|
|
3099
3299
|
renderToString as renderToStringOrig,
|
|
@@ -3159,7 +3359,7 @@ export const renderToStream: RenderToStreamWrapper<
|
|
|
3159
3359
|
};
|
|
3160
3360
|
|
|
3161
3361
|
export default serverRenderFactory();
|
|
3162
|
-
`,
|
|
3362
|
+
`,Ft=`/* @jsxImportSource react */
|
|
3163
3363
|
|
|
3164
3364
|
import styles from "./styles.module.css";
|
|
3165
3365
|
|
|
@@ -3200,7 +3400,7 @@ export default function PageSample(props: {
|
|
|
3200
3400
|
</div>
|
|
3201
3401
|
);
|
|
3202
3402
|
}
|
|
3203
|
-
`,
|
|
3403
|
+
`,It=`/* @jsxImportSource react */
|
|
3204
3404
|
|
|
3205
3405
|
import styles from "./styles.module.css";
|
|
3206
3406
|
|
|
@@ -3252,7 +3452,7 @@ export default function PageSample(props: {
|
|
|
3252
3452
|
</div>
|
|
3253
3453
|
);
|
|
3254
3454
|
}
|
|
3255
|
-
`,
|
|
3455
|
+
`,Lt=`* {
|
|
3256
3456
|
margin: 0;
|
|
3257
3457
|
padding: 0;
|
|
3258
3458
|
box-sizing: border-box;
|
|
@@ -3387,7 +3587,7 @@ export default function PageSample(props: {
|
|
|
3387
3587
|
align-items: center;
|
|
3388
3588
|
gap: 0.25rem;
|
|
3389
3589
|
}
|
|
3390
|
-
`,
|
|
3590
|
+
`,Rt=`/* @jsxImportSource react */
|
|
3391
3591
|
|
|
3392
3592
|
import styles from "./styles.module.css";
|
|
3393
3593
|
|
|
@@ -3453,7 +3653,45 @@ export default function WelcomePage() {
|
|
|
3453
3653
|
</div>
|
|
3454
3654
|
);
|
|
3455
3655
|
}
|
|
3456
|
-
`,
|
|
3656
|
+
`,zt=`import { QueryClient, type QueryClientConfig } from "@tanstack/react-query";
|
|
3657
|
+
|
|
3658
|
+
let client: QueryClient | undefined;
|
|
3659
|
+
|
|
3660
|
+
export const createQueryClient = (options?: QueryClientConfig): QueryClient => {
|
|
3661
|
+
client = new QueryClient(options);
|
|
3662
|
+
return client;
|
|
3663
|
+
};
|
|
3664
|
+
|
|
3665
|
+
export const getQueryClient = (): QueryClient => {
|
|
3666
|
+
if (!client) {
|
|
3667
|
+
client = new QueryClient();
|
|
3668
|
+
}
|
|
3669
|
+
return client;
|
|
3670
|
+
};
|
|
3671
|
+
`,Bt=`import { QueryClient, type QueryClientConfig } from "@tanstack/react-query";
|
|
3672
|
+
|
|
3673
|
+
import { store } from "{{ createImport 'lib' '@ssr/base' }}";
|
|
3674
|
+
|
|
3675
|
+
export const createQueryClient = (options?: QueryClientConfig): QueryClient => {
|
|
3676
|
+
const client = new QueryClient(options);
|
|
3677
|
+
const ctx = store?.getStore();
|
|
3678
|
+
if (ctx) {
|
|
3679
|
+
ctx.tsqClient = client;
|
|
3680
|
+
}
|
|
3681
|
+
return client;
|
|
3682
|
+
};
|
|
3683
|
+
|
|
3684
|
+
export const getQueryClient = (): QueryClient => {
|
|
3685
|
+
const ctx = store?.getStore();
|
|
3686
|
+
if (!ctx) {
|
|
3687
|
+
throw new Error("getQueryClient(): called outside an SSR request scope");
|
|
3688
|
+
}
|
|
3689
|
+
if (!ctx.tsqClient) {
|
|
3690
|
+
ctx.tsqClient = new QueryClient();
|
|
3691
|
+
}
|
|
3692
|
+
return ctx.tsqClient as QueryClient;
|
|
3693
|
+
};
|
|
3694
|
+
`,Vt=`export type ComponentLoader = () => Promise<{
|
|
3457
3695
|
loader?: (arg: unknown) => Promise<unknown>;
|
|
3458
3696
|
}>;
|
|
3459
3697
|
|
|
@@ -3486,7 +3724,7 @@ export const loaderFactory = (opt?: { withPreload?: boolean }) => {
|
|
|
3486
3724
|
return opt?.withPreload ? { loader } : {};
|
|
3487
3725
|
};
|
|
3488
3726
|
};
|
|
3489
|
-
`,
|
|
3727
|
+
`,Ht=`import type { JSX, ComponentType } from "react";
|
|
3490
3728
|
|
|
3491
3729
|
import {
|
|
3492
3730
|
type RouteObject,
|
|
@@ -3544,12 +3782,17 @@ export const createRouters = (
|
|
|
3544
3782
|
}
|
|
3545
3783
|
|
|
3546
3784
|
export default createRouterFactory<RouteObject, Promise<JSX.Element>>();
|
|
3547
|
-
`,
|
|
3785
|
+
`,Ut=`import { Outlet } from "react-router";
|
|
3786
|
+
import { AppProvider } from "{{ createImport 'lib' 'app' }}";
|
|
3548
3787
|
|
|
3549
3788
|
export default function App() {
|
|
3550
|
-
return
|
|
3789
|
+
return (
|
|
3790
|
+
<AppProvider>
|
|
3791
|
+
<Outlet />
|
|
3792
|
+
</AppProvider>
|
|
3793
|
+
);
|
|
3551
3794
|
}
|
|
3552
|
-
`,
|
|
3795
|
+
`,Wt=`import {
|
|
3553
3796
|
type LinkProps as RouterLinkProps,
|
|
3554
3797
|
Link as RouterLink,
|
|
3555
3798
|
} from "react-router";
|
|
@@ -3577,7 +3820,7 @@ export default function Link(
|
|
|
3577
3820
|
</RouterLink>
|
|
3578
3821
|
);
|
|
3579
3822
|
}
|
|
3580
|
-
`,
|
|
3823
|
+
`,Gt=`import renderFactory, {
|
|
3581
3824
|
createRoutes,
|
|
3582
3825
|
hydrate,
|
|
3583
3826
|
mount,
|
|
@@ -3604,7 +3847,7 @@ if (root) {
|
|
|
3604
3847
|
} else {
|
|
3605
3848
|
console.error("❌ Root element not found!");
|
|
3606
3849
|
}
|
|
3607
|
-
`,
|
|
3850
|
+
`,Kt=`import renderFactory, {
|
|
3608
3851
|
createRoutes,
|
|
3609
3852
|
renderToStream,
|
|
3610
3853
|
renderToString,
|
|
@@ -3631,7 +3874,7 @@ export default renderFactory(() => {
|
|
|
3631
3874
|
},
|
|
3632
3875
|
};
|
|
3633
3876
|
});
|
|
3634
|
-
`,
|
|
3877
|
+
`,qt=`<!doctype html>
|
|
3635
3878
|
<html lang="en">
|
|
3636
3879
|
<head>
|
|
3637
3880
|
<meta charset="UTF-8" />
|
|
@@ -3643,17 +3886,17 @@ export default renderFactory(() => {
|
|
|
3643
3886
|
<script type="module" src="/{{ entryDir }}/client.ts"><\/script>
|
|
3644
3887
|
</body>
|
|
3645
3888
|
</html>
|
|
3646
|
-
`,
|
|
3889
|
+
`,Jt=`import PageSample from "{{ createImport 'lib' 'pageSamples/404.tsx' }}";
|
|
3647
3890
|
|
|
3648
3891
|
export default function Page() {
|
|
3649
3892
|
return <PageSample />;
|
|
3650
3893
|
}
|
|
3651
|
-
`,
|
|
3894
|
+
`,Yt=`import { Outlet } from "react-router";
|
|
3652
3895
|
|
|
3653
3896
|
export default function Layout() {
|
|
3654
3897
|
return <Outlet />;
|
|
3655
3898
|
}
|
|
3656
|
-
`,
|
|
3899
|
+
`,Xt=`import PageSample from "{{ createImport 'lib' 'pageSamples/page.tsx' }}";
|
|
3657
3900
|
|
|
3658
3901
|
export default function Page() {
|
|
3659
3902
|
return PageSample({
|
|
@@ -3666,10 +3909,10 @@ export default function Page() {
|
|
|
3666
3909
|
},
|
|
3667
3910
|
});
|
|
3668
3911
|
}
|
|
3669
|
-
`,
|
|
3670
|
-
`,
|
|
3912
|
+
`,Zt=`export { default } from "{{ createImport 'lib' 'pageSamples/welcome.tsx' }}";
|
|
3913
|
+
`,Qt=`import routerFactory, { createRouters } from "{{ createImport 'lib' 'router' }}";
|
|
3671
3914
|
|
|
3672
|
-
import app from "./
|
|
3915
|
+
import app from "./app";
|
|
3673
3916
|
|
|
3674
3917
|
export default routerFactory((routes) => {
|
|
3675
3918
|
const { clientRouter, serverRouter } = createRouters(routes, { app });
|
|
@@ -3682,7 +3925,24 @@ export default routerFactory((routes) => {
|
|
|
3682
3925
|
},
|
|
3683
3926
|
};
|
|
3684
3927
|
});
|
|
3685
|
-
|
|
3928
|
+
`,$t=f((e,t)=>{let{createPath:n,createImportHelpers:r}=h(e),{renderToFile:i}=_({helpers:{...r({origin:`lib`}),...b()},partials:{routePartial:Nt}}),{renderToFile:a}=_({helpers:r({origin:`src`})}),o=Ot(),l=e=>!e?.trim().length,u=s(t?.templates,Xt),d=async e=>{for(let{kind:t,entry:r}of e)t===`pageRoute`?await a(n.pages(r.file),r.name===`index`?Zt:u(r.name,r),{route:r,message:kt()},{overwrite:l}):t===`pageLayout`&&await a(n.pages(r.file),Yt,{route:r},{overwrite:l})},f=async e=>{let t=e.flatMap(({kind:e,entry:t})=>e===`pageRoute`?[t]:[]).sort(v),r=e.flatMap(({kind:e,entry:t})=>e===`pageRoute`||e===`pageLayout`?[t]:[]),a=o(m(r));for(let[e,t]of[[`client.ts`,Mt],[`server.ts`,Pt]])await i(n.libEntry(e),t,{pageEntries:r,nestedRoutes:a});await i(n.lib(`router.tsx`),Ht,{entries:e,indexRoutes:t})};return{config(){let{templates:e,...n}={...t};return{plugins:[oe(n)]}},async start(){for(let[e,r]of[[`env.d.ts`,``],[`react.ts`,Vt],[`pageSamples/styles.module.css`,Lt],[`pageSamples/welcome.tsx`,Rt],[`pageSamples/page.tsx`,It],[`pageSamples/404.tsx`,Ft],...t?.tanstack?.query?[[`app.tsx`,jt],[`query.ts`,zt]]:[[`app.tsx`,At],[`query.ts`,`/** tanstack query disabled */`]]])await i(n.lib(e),r,{});for(let[e,t]of[[`pages/404.tsx`,Jt],[`components/Link.tsx`,Wt],[`app.tsx`,Ut],[`router.ts`,Qt]])await a(n.src(e),t,{entryDir:c.entryDir},{overwrite:l});await a(n.src(`index.html`),qt,{entryDir:c.entryDir},{overwrite:e=>!e?.trim().length||!e.replace(/<!--[\s\S]*?-->/g,``).trim().length});for(let[e,t]of[[`client.ts`,Gt],[`server.ts`,Kt]])await a(n.entry(e),t,{},{overwrite:l})},async watch(e,t){(!t||t.kind===`create`)&&await d(e),await f(e)},async build(e){await d(e),await f(e)},async ssrBuild(){await i(n.lib(`query.ts`),t?.tanstack?.query?Bt:`/** tanstack query disabled */`,{ssrBundle:!0})}}}),en=d({meta:{name:`React`,jsx:`preserve`,jsxImportSource:`react`},dependencies(e){return{react:W.devDependencies.react,"react-router":W.devDependencies[`react-router`],"path-to-regexp":W.devDependencies[`path-to-regexp`],...e?.tanstack?.query?{"@tanstack/react-query":W.devDependencies[`@tanstack/react-query`]}:{}}},devDependencies:{"@types/react":W.devDependencies[`@types/react`],"@types/react-dom":W.devDependencies[`@types/react-dom`],"react-dom":W.devDependencies[`react-dom`]},factory:$t}),G={type:`module`,private:!0,name:`@kosmojs/solid-generator`,version:`0.2.10`,author:`Slee Woo`,license:`MIT`,files:[`pkg/*`],exports:{".":{types:`./pkg/index.d.ts`,default:`./pkg/index.js`}},scripts:{build:`wsbuild src/index.ts`,test:`vitest --root ../.. --project generators/solid-generator`},dependencies:{"@kosmojs/core":`workspace:^`,"@kosmojs/lib":`workspace:^`,"vite-plugin-solid":`^2.11.14`},devDependencies:{"@solidjs/router":`^1.0.0`,"@tanstack/solid-query":`^5.101.4`,"path-to-regexp":`^8.4.2`,"solid-js":`^1.9.14`}},tn=()=>{let e=e=>e?.kind===`param`&&e.parts[0]?.kind===`splat`,t=t=>t?.kind===`param`?t.parts[0]?.kind===`optional`||e(t):!1,n=r=>r.flatMap(({index:r,layout:i,children:a})=>{let{pathTokens:o}={...r,...i},s=K(o.map((e,n)=>e.kind===`param`&&(t(o[n+1])||a.some(e=>e.index?.pathTokens.some(t)))?{...e,parts:[{...e.parts[0],kind:`required`}]}:e)),c=o.at(-1);if(e(c)){let e=K([c]);return r&&i?[{path:s,component:i.id,children:[{path:e,component:r.id}]}]:r?[{path:s,children:[{path:e,component:r.id},...n(a)]}]:i?[{path:s,component:i.id,children:n(a)}]:[]}return r&&i?[{path:s,component:i.id,children:[{path:`/`,component:r.id},...n(a)]}]:r?[{path:s,children:[{path:`/`,component:r.id},...n(a)]}]:i?[{path:s,component:i.id,children:n(a)}]:[]});return n},K=e=>{let t=e.map(e=>e.orig).join(`/`),r=e=>e.kind===`splat`?`*${e.name}`:e.kind===`optional`?`:${e.name}?`:`:${e.name}`;return e.flatMap(e=>e.kind===`static`?[e.parts[0].value]:e.kind===`param`?[r(e.parts[0])]:(e.parts.length&&(console.warn(`❗${n([`red`,`bold`],`WARN`)}: At the moment Solid Router does not support mixed path segments.`),console.warn(` ${n([`magenta`],e.orig)} segment in ${n([`blue`],t)} route won't match as expected.`),console.warn()),[e.parts.map(e=>e.type===`static`?e.value:r(e)).join(``)])).join(`/`)},nn=()=>{let e=[`🎉 Well done! You just created a new Solid route.`,`🚀 Success! A fresh Solid route is ready to roll.`,`🌟 Nice work! Another Solid route added to your app.`,`🧩 All set! A new Solid route has been scaffolded.`,`🔧 Scaffold complete! Your new Solid route is in place.`,`✅ Built! Your Solid route is scaffolded and ready.`,`✨ Fantastic! Your new Solid route is good to go.`,`🎯 Nailed it! A brand new Solid route just landed.`,`💫 Awesome! Another Solid route joins the party.`,`⚡ Lightning fast! A new Solid route created successfully.`];return e[Math.floor(Math.random()*e.length)]},rn=`import type { ParentComponent } from "solid-js";
|
|
3929
|
+
|
|
3930
|
+
export const AppProvider: ParentComponent = (props) => {
|
|
3931
|
+
return props.children;
|
|
3932
|
+
};
|
|
3933
|
+
`,an=`import type { ParentComponent } from "solid-js";
|
|
3934
|
+
import { type QueryClient, QueryClientProvider } from "@tanstack/solid-query";
|
|
3935
|
+
|
|
3936
|
+
import { getQueryClient } from "./query";
|
|
3937
|
+
|
|
3938
|
+
export const AppProvider: ParentComponent<{ client?: QueryClient }> = (props) => {
|
|
3939
|
+
return (
|
|
3940
|
+
<QueryClientProvider client={props.client ?? getQueryClient()}>
|
|
3941
|
+
{props.children}
|
|
3942
|
+
</QueryClientProvider>
|
|
3943
|
+
);
|
|
3944
|
+
};
|
|
3945
|
+
`,on=`import { lazy, type JSX } from "solid-js";
|
|
3686
3946
|
import { hydrate as hydrateOrig, render } from "solid-js/web";
|
|
3687
3947
|
import type { RouterFactoryReturn } from "@kosmojs/core";
|
|
3688
3948
|
import { clientRenderFactory } from "@kosmojs/core/generators";
|
|
@@ -3727,7 +3987,7 @@ export const mount = async (
|
|
|
3727
3987
|
}
|
|
3728
3988
|
|
|
3729
3989
|
export default clientRenderFactory();
|
|
3730
|
-
`,
|
|
3990
|
+
`,sn=`{
|
|
3731
3991
|
path: "{{path}}",
|
|
3732
3992
|
{{#if component}}
|
|
3733
3993
|
component: {{component}}_component,
|
|
@@ -3737,7 +3997,7 @@ export default clientRenderFactory();
|
|
|
3737
3997
|
children: [ {{#each children}}{{> routePartial}}, {{/each}}],
|
|
3738
3998
|
{{/if}}
|
|
3739
3999
|
}
|
|
3740
|
-
`,
|
|
4000
|
+
`,cn=`import type { JSX } from "solid-js";
|
|
3741
4001
|
|
|
3742
4002
|
import {
|
|
3743
4003
|
generateHydrationScript,
|
|
@@ -3813,7 +4073,7 @@ export const renderToStream: RenderToStreamWrapper<
|
|
|
3813
4073
|
};
|
|
3814
4074
|
|
|
3815
4075
|
export default serverRenderFactory<true>();
|
|
3816
|
-
`,
|
|
4076
|
+
`,ln=`/* @jsxImportSource solid-js */
|
|
3817
4077
|
|
|
3818
4078
|
import styles from "./styles.module.css";
|
|
3819
4079
|
|
|
@@ -3854,7 +4114,7 @@ export default function PageSample(props: {
|
|
|
3854
4114
|
</div>
|
|
3855
4115
|
);
|
|
3856
4116
|
}
|
|
3857
|
-
|
|
4117
|
+
`,un=`/* @jsxImportSource solid-js */
|
|
3858
4118
|
|
|
3859
4119
|
import styles from "./styles.module.css";
|
|
3860
4120
|
|
|
@@ -3906,7 +4166,7 @@ export default function PageSample(props: {
|
|
|
3906
4166
|
</div>
|
|
3907
4167
|
);
|
|
3908
4168
|
}
|
|
3909
|
-
`,
|
|
4169
|
+
`,dn=`* {
|
|
3910
4170
|
margin: 0;
|
|
3911
4171
|
padding: 0;
|
|
3912
4172
|
box-sizing: border-box;
|
|
@@ -4041,7 +4301,7 @@ export default function PageSample(props: {
|
|
|
4041
4301
|
align-items: center;
|
|
4042
4302
|
gap: 0.25rem;
|
|
4043
4303
|
}
|
|
4044
|
-
`,
|
|
4304
|
+
`,fn=`/* @jsxImportSource solid-js */
|
|
4045
4305
|
|
|
4046
4306
|
import styles from "./styles.module.css";
|
|
4047
4307
|
|
|
@@ -4107,7 +4367,45 @@ export default function WelcomePage() {
|
|
|
4107
4367
|
</div>
|
|
4108
4368
|
);
|
|
4109
4369
|
}
|
|
4110
|
-
`,
|
|
4370
|
+
`,pn=`import { QueryClient, type QueryClientConfig } from "@tanstack/solid-query";
|
|
4371
|
+
|
|
4372
|
+
let client: QueryClient | undefined;
|
|
4373
|
+
|
|
4374
|
+
export const createQueryClient = (options?: QueryClientConfig): QueryClient => {
|
|
4375
|
+
client = new QueryClient(options);
|
|
4376
|
+
return client;
|
|
4377
|
+
};
|
|
4378
|
+
|
|
4379
|
+
export const getQueryClient = (): QueryClient => {
|
|
4380
|
+
if (!client) {
|
|
4381
|
+
client = new QueryClient();
|
|
4382
|
+
}
|
|
4383
|
+
return client;
|
|
4384
|
+
};
|
|
4385
|
+
`,mn=`import { QueryClient, type QueryClientConfig } from "@tanstack/solid-query";
|
|
4386
|
+
|
|
4387
|
+
import { store } from "{{ createImport 'lib' '@ssr/base' }}";
|
|
4388
|
+
|
|
4389
|
+
export const createQueryClient = (options?: QueryClientConfig): QueryClient => {
|
|
4390
|
+
const client = new QueryClient(options);
|
|
4391
|
+
const ctx = store?.getStore();
|
|
4392
|
+
if (ctx) {
|
|
4393
|
+
ctx.tsqClient = client;
|
|
4394
|
+
}
|
|
4395
|
+
return client;
|
|
4396
|
+
};
|
|
4397
|
+
|
|
4398
|
+
export const getQueryClient = (): QueryClient => {
|
|
4399
|
+
const ctx = store?.getStore();
|
|
4400
|
+
if (!ctx) {
|
|
4401
|
+
throw new Error("getQueryClient(): called outside an SSR request scope");
|
|
4402
|
+
}
|
|
4403
|
+
if (!ctx.tsqClient) {
|
|
4404
|
+
ctx.tsqClient = new QueryClient();
|
|
4405
|
+
}
|
|
4406
|
+
return ctx.tsqClient as QueryClient;
|
|
4407
|
+
};
|
|
4408
|
+
`,hn=`import type { JSX, ParentComponent } from "solid-js";
|
|
4111
4409
|
import { Router, type RouteDefinition } from "@solidjs/router";
|
|
4112
4410
|
import type { RouterFactoryReturn } from "@kosmojs/core";
|
|
4113
4411
|
import { createRouterFactory } from "@kosmojs/core/generators";
|
|
@@ -4143,7 +4441,7 @@ export const createRouters = (
|
|
|
4143
4441
|
}
|
|
4144
4442
|
|
|
4145
4443
|
export default createRouterFactory<RouteDefinition, JSX.Element>();
|
|
4146
|
-
`,
|
|
4444
|
+
`,gn=`export type ComponentLoader = () => Promise<{
|
|
4147
4445
|
preload?: () => Promise<unknown>;
|
|
4148
4446
|
}>;
|
|
4149
4447
|
|
|
@@ -4163,17 +4461,18 @@ export const loaderFactory = (opt?: { withPreload?: boolean }) => {
|
|
|
4163
4461
|
return opt?.withPreload ? { preload } : {};
|
|
4164
4462
|
};
|
|
4165
4463
|
};
|
|
4166
|
-
`,
|
|
4464
|
+
`,_n=`export type MaybeWrapped<T> = import("solid-js/store").Store<T> | T;
|
|
4167
4465
|
|
|
4168
4466
|
export { unwrap } from "solid-js/store";
|
|
4169
|
-
`,
|
|
4467
|
+
`,vn=`import type { ParentComponent } from "solid-js";
|
|
4468
|
+
import { AppProvider } from "{{ createImport 'lib' 'app' }}";
|
|
4170
4469
|
|
|
4171
4470
|
const App: ParentComponent = (props) => {
|
|
4172
|
-
return props.children
|
|
4471
|
+
return <AppProvider>{props.children}</AppProvider>;
|
|
4173
4472
|
};
|
|
4174
4473
|
|
|
4175
4474
|
export default App;
|
|
4176
|
-
`,
|
|
4475
|
+
`,yn=`import { A, type AnchorProps } from "@solidjs/router";
|
|
4177
4476
|
import { type JSXElement, splitProps } from "solid-js";
|
|
4178
4477
|
|
|
4179
4478
|
import { pageRouteMap, type LinkProps } from "{{ createImport 'libCore' }}";
|
|
@@ -4198,7 +4497,7 @@ export default function Link(
|
|
|
4198
4497
|
|
|
4199
4498
|
return <A {...{ ...restProps, href: href() }}>{knownProps.children}</A>;
|
|
4200
4499
|
}
|
|
4201
|
-
`,
|
|
4500
|
+
`,bn=`import renderFactory, {
|
|
4202
4501
|
createRoutes,
|
|
4203
4502
|
hydrate,
|
|
4204
4503
|
mount,
|
|
@@ -4225,7 +4524,7 @@ if (root) {
|
|
|
4225
4524
|
} else {
|
|
4226
4525
|
console.error("❌ Root element not found!");
|
|
4227
4526
|
}
|
|
4228
|
-
`,
|
|
4527
|
+
`,xn=`import renderFactory, {
|
|
4229
4528
|
createRoutes,
|
|
4230
4529
|
renderToStream,
|
|
4231
4530
|
renderToString,
|
|
@@ -4252,7 +4551,7 @@ export default renderFactory(() => {
|
|
|
4252
4551
|
},
|
|
4253
4552
|
};
|
|
4254
4553
|
});
|
|
4255
|
-
`,
|
|
4554
|
+
`,Sn=`<!doctype html>
|
|
4256
4555
|
<html lang="en">
|
|
4257
4556
|
<head>
|
|
4258
4557
|
<meta charset="UTF-8" />
|
|
@@ -4264,19 +4563,19 @@ export default renderFactory(() => {
|
|
|
4264
4563
|
<script type="module" src="/{{ entryDir }}/client.ts"><\/script>
|
|
4265
4564
|
</body>
|
|
4266
4565
|
</html>
|
|
4267
|
-
`,
|
|
4566
|
+
`,Cn=`import PageSample from "{{ createImport 'lib' 'pageSamples/404.tsx' }}";
|
|
4268
4567
|
|
|
4269
4568
|
export default function Page() {
|
|
4270
4569
|
return <PageSample />;
|
|
4271
4570
|
}
|
|
4272
|
-
`,
|
|
4571
|
+
`,wn=`import type { ParentComponent } from "solid-js";
|
|
4273
4572
|
|
|
4274
4573
|
const Layout: ParentComponent = (props) => {
|
|
4275
4574
|
return props.children;
|
|
4276
4575
|
};
|
|
4277
4576
|
|
|
4278
4577
|
export default Layout;
|
|
4279
|
-
`,
|
|
4578
|
+
`,Tn=`import PageSample from "{{ createImport 'lib' 'pageSamples/page.tsx' }}";
|
|
4280
4579
|
|
|
4281
4580
|
export default function Page() {
|
|
4282
4581
|
return PageSample({
|
|
@@ -4289,10 +4588,10 @@ export default function Page() {
|
|
|
4289
4588
|
},
|
|
4290
4589
|
});
|
|
4291
4590
|
}
|
|
4292
|
-
`,
|
|
4293
|
-
`,
|
|
4591
|
+
`,En=`export { default } from "{{ createImport 'lib' 'pageSamples/welcome.tsx' }}";
|
|
4592
|
+
`,Dn=`import routerFactory, { createRouters } from "{{ createImport 'lib' 'router' }}";
|
|
4294
4593
|
|
|
4295
|
-
import app from "./
|
|
4594
|
+
import app from "./app";
|
|
4296
4595
|
|
|
4297
4596
|
export default routerFactory((routes) => {
|
|
4298
4597
|
const { clientRouter, serverRouter } = createRouters(routes, { app });
|
|
@@ -4305,33 +4604,16 @@ export default routerFactory((routes) => {
|
|
|
4305
4604
|
},
|
|
4306
4605
|
};
|
|
4307
4606
|
});
|
|
4308
|
-
`,
|
|
4607
|
+
`,On=f((e,t)=>{let{generators:n=[]}=e.config,{createPath:r,createImportHelpers:i}=h(e),{renderToFile:a}=_({helpers:{...i({origin:`lib`}),...b()},partials:{routePartial:sn}}),{renderToFile:o}=_({helpers:i({origin:`src`})}),l=tn(),u=e=>!e?.trim().length,d=s(t?.templates,Tn),f=async e=>{for(let{kind:t,entry:n}of e)t===`pageRoute`?await o(r.pages(n.file),n.name===`index`?En:d(n.name,n),{route:n,message:nn()},{overwrite:u}):t===`pageLayout`&&await o(r.pages(n.file),wn,{route:n},{overwrite:u})},p=async e=>{let t=e.flatMap(({kind:e,entry:t})=>e===`pageRoute`?[t]:[]).sort(v),n=e.flatMap(({kind:e,entry:t})=>e===`pageRoute`||e===`pageLayout`?[t]:[]),i=l(m(n));for(let[e,t]of[[`client.ts`,on],[`server.ts`,cn]])await a(r.libEntry(e),t,{pageEntries:n,nestedRoutes:i});await a(r.lib(`router.tsx`),hn,{entries:e,indexRoutes:t})};return{config({command:e}){let{templates:r,...i}={...t};return{oxc:{jsx:{importSource:`solid-js`}},plugins:e===`build`?[w({...i,...n.some(e=>e.meta.slot===`ssr`)?{ssr:!0,solid:{...i?.solid,hydratable:!0}}:{}})]:[w({...i,dev:!0,hot:!0})]}},async start(){for(let[e,n]of[[`env.d.ts`,``],[`solid.ts`,gn],[`unwrap.ts`,_n],[`pageSamples/styles.module.css`,dn],[`pageSamples/welcome.tsx`,fn],[`pageSamples/page.tsx`,un],[`pageSamples/404.tsx`,ln],...t?.tanstack?.query?[[`app.tsx`,an],[`query.ts`,pn]]:[[`app.tsx`,rn],[`query.ts`,`/** tanstack query disabled */`]]])await a(r.lib(e),n,{});for(let[e,t]of[[`pages/404.tsx`,Cn],[`components/Link.tsx`,yn],[`app.tsx`,vn],[`router.ts`,Dn]])await o(r.src(e),t,{entryDir:c.entryDir},{overwrite:u});await o(r.src(`index.html`),Sn,{entryDir:c.entryDir},{overwrite:e=>!e?.trim().length||!e.replace(/<!--[\s\S]*?-->/g,``).trim().length});for(let[e,t]of[[`client.ts`,bn],[`server.ts`,xn]])await o(r.entry(e),t,{},{overwrite:u})},async watch(e,t){(!t||t.kind===`create`)&&await f(e),await p(e)},async build(e){await f(e),await p(e)},async ssrBuild(){await a(r.lib(`query.ts`),t?.tanstack?.query?mn:`/** tanstack query disabled */`,{ssrBundle:!0})}}}),kn=d({meta:{name:`SolidJS`,jsx:`preserve`,jsxImportSource:`solid-js`},dependencies(e){return{"solid-js":G.devDependencies[`solid-js`],"@solidjs/router":G.devDependencies[`@solidjs/router`],"path-to-regexp":G.devDependencies[`path-to-regexp`],...e?.tanstack?.query?{"@tanstack/solid-query":G.devDependencies[`@tanstack/solid-query`]}:{}}},factory:On}),An=f(r=>{let{generators:i=[],refineTypeName:a,...o}={...r.config},{createPath:s}=h(r);return{async postBuild(){let a=s.distDir(`ssg`),c=t(a,`../ssr/server.js`);if(!await se(c,ce.F_OK).then(()=>!0,()=>!1)){console.error(),console.error(n(`red`,`❗Please enable ssrGenerator in ${r.name}/kosmo.config.ts`)),console.error(` SSG generator can not run without SSR server`),console.error();return}let l=te(`${r.name}: SSG`);l.append(`preparing...`);let{createDisposableServer:u}=await import(c);await T(t(a,`../client/assets`),e(a,`assets`),{recursive:!0}),l.append(`bundling routes...`),await S(p(o,...i.map(({factory:e})=>e(r).config?.({kind:`client`,command:`build`})),{root:s.lib(),appType:`custom`,plugins:[y.tsconfigPaths(r),y.nodePrefix()],resolve:{conditions:[`node`]},build:{ssr:s.lib(`ssg.ts`),target:`esnext`,sourcemap:!1,emptyOutDir:!0,rolldownOptions:{output:{dir:a,entryFileNames:`routes.js`,format:`esm`}}}}));try{let t=await import(e(a,`routes.js`)).then(e=>e.default);u(async n=>{for(let[r,i]of t.entries()){l.append(`[ ${r+1} of ${t.length} ] ${i}`);let o=await jn(n,i);o!==void 0&&(await le(e(a,i),{recursive:!0}),await ue(e(a,e(i,`index.html`)),o,`utf8`))}l.succeed(`done ✨`)})}finally{await E(`${a}/routes.js`)}}}}),jn=async(e,t)=>{try{let n=`http://localhost:${e}${t}`;return await(await fetch(n)).text()}catch(e){console.error(n(`red`,`✗ SSG: Failed generating ${t} route: ${e.message}`));return}},Mn=d({meta:{name:`SSG`,slot:`ssg`},factory:An}),q={type:`module`,private:!0,name:`@kosmojs/ssr-generator`,version:`0.2.10`,author:`Slee Woo`,license:`MIT`,files:[`pkg/*`],exports:{".":{types:`./pkg/index.d.ts`,default:`./pkg/index.js`}},scripts:{build:`wsbuild src/index.ts`},dependencies:{"@kosmojs/core":`workspace:^`,"@kosmojs/lib":`workspace:^`,vite:`^8.2.1`},devDependencies:{"@hono/node-server":`^2.1.0`,hono:`^4.13.1`,"light-my-request":`^6.6.0`,tinyglobby:`^0.2.17`}},Nn=`{{#if apiGenerator}}
|
|
4309
4608
|
export { default as apiApp } from "{{ createImport 'api' 'app' }}";
|
|
4310
4609
|
{{else}}
|
|
4311
4610
|
export const apiApp = undefined;
|
|
4312
4611
|
{{/if}}
|
|
4313
|
-
`,
|
|
4314
|
-
|
|
4315
|
-
import { renderWrapper } from "{{ createImport 'libEntry' 'server' }}";
|
|
4316
|
-
|
|
4317
|
-
export { default as ssrApp } from "{{ createImport 'entry' 'server' }}";
|
|
4318
|
-
export { apiApp } from "{{ createImport 'lib' '@ssr/api' }}";
|
|
4319
|
-
|
|
4320
|
-
/**
|
|
4321
|
-
* Wraps a render call, making the given context visible to every
|
|
4322
|
-
* fetch dispatch that happens during it - across await points,
|
|
4323
|
-
* stream chunks and parallel component data loads.
|
|
4324
|
-
* */
|
|
4325
|
-
export const withSsrContext = <T>(
|
|
4326
|
-
context: RequestContext,
|
|
4327
|
-
render: () => T,
|
|
4328
|
-
): T => {
|
|
4329
|
-
return store.run(context, () => renderWrapper(context, render));
|
|
4330
|
-
};
|
|
4331
|
-
`,Cn=`import { AsyncLocalStorage } from "node:async_hooks";
|
|
4612
|
+
`,Pn=`import { AsyncLocalStorage } from "node:async_hooks";
|
|
4332
4613
|
|
|
4333
4614
|
export type RequestContext = {
|
|
4334
4615
|
headers?: HeadersInit;
|
|
4616
|
+
tsqClient?: unknown;
|
|
4335
4617
|
};
|
|
4336
4618
|
|
|
4337
4619
|
export const redirectCodes = [
|
|
@@ -4364,7 +4646,25 @@ export const maxRedirects = 5;
|
|
|
4364
4646
|
* Server-only module - never reaches browser bundles.
|
|
4365
4647
|
* */
|
|
4366
4648
|
export const store = new AsyncLocalStorage<RequestContext>();
|
|
4367
|
-
`,
|
|
4649
|
+
`,Fn=`import { type RequestContext, store } from "./base";
|
|
4650
|
+
|
|
4651
|
+
import { renderWrapper } from "{{ createImport 'libEntry' 'server' }}";
|
|
4652
|
+
|
|
4653
|
+
export { default as ssrApp } from "{{ createImport 'entry' 'server' }}";
|
|
4654
|
+
export { apiApp } from "{{ createImport 'lib' '@ssr/api' }}";
|
|
4655
|
+
|
|
4656
|
+
/**
|
|
4657
|
+
* Wraps a render call, making the given context visible to every
|
|
4658
|
+
* fetch dispatch that happens during it - across await points,
|
|
4659
|
+
* stream chunks and parallel component data loads.
|
|
4660
|
+
* */
|
|
4661
|
+
export const withSsrContext = <T>(
|
|
4662
|
+
context: RequestContext,
|
|
4663
|
+
render: () => T,
|
|
4664
|
+
): T => {
|
|
4665
|
+
return store.run(context, () => renderWrapper(context, render));
|
|
4666
|
+
};
|
|
4667
|
+
`,In=`import { inject } from "light-my-request";
|
|
4368
4668
|
|
|
4369
4669
|
import { type FetchApp, isFetchApp, type NodeApp } from "@kosmojs/core";
|
|
4370
4670
|
import type { Transport } from "@kosmojs/core/fetch";
|
|
@@ -4503,12 +4803,12 @@ const createNodeDispatch = (app: NodeApp) => {
|
|
|
4503
4803
|
};
|
|
4504
4804
|
|
|
4505
4805
|
export const transport = apiApp ? createTransport(apiApp) : globalThis.fetch;
|
|
4506
|
-
`,
|
|
4806
|
+
`,Ln=`export const routeMap = [
|
|
4507
4807
|
{{#each pageRoutes}}
|
|
4508
4808
|
{ pathPattern: "{{honoPattern}}", renderMode: "{{renderMode}}" },
|
|
4509
4809
|
{{/each}}
|
|
4510
4810
|
];
|
|
4511
|
-
`,
|
|
4811
|
+
`,Rn=`import { access, chmod, constants, readFile, unlink } from "node:fs/promises";
|
|
4512
4812
|
import {
|
|
4513
4813
|
createServer,
|
|
4514
4814
|
type IncomingMessage,
|
|
@@ -4578,16 +4878,13 @@ export const createApp = async () => {
|
|
|
4578
4878
|
const ssrOptions = () => {
|
|
4579
4879
|
const cssAssets = [...assets.entries()].flatMap(
|
|
4580
4880
|
([path, { file, buffer, size }]) => {
|
|
4581
|
-
// Vite is naming assets by entry name
|
|
4582
|
-
if (!/^
|
|
4881
|
+
// Vite is naming assets by entry name
|
|
4882
|
+
if (!/^__kosmo_ssr_bundle-.+\\.css$/i.test(file)) {
|
|
4583
4883
|
return [];
|
|
4584
4884
|
}
|
|
4585
4885
|
|
|
4586
|
-
if
|
|
4587
|
-
|
|
4588
|
-
// Vite use same hash for client and server assets:
|
|
4589
|
-
// client asset: index-D-m1j8Sq.css
|
|
4590
|
-
// server asset: ssr_base-D-m1j8Sq.css
|
|
4886
|
+
// skip if template contains a file with same hash
|
|
4887
|
+
if (template.includes(file.replace(/^__kosmo_ssr_bundle\\b/, ""))) {
|
|
4591
4888
|
return [];
|
|
4592
4889
|
}
|
|
4593
4890
|
|
|
@@ -4655,7 +4952,7 @@ export const createApp = async () => {
|
|
|
4655
4952
|
headers: Object.fromEntries(ctx.req.raw.headers),
|
|
4656
4953
|
url: ctx.req.url,
|
|
4657
4954
|
},
|
|
4658
|
-
() => renderToStream(url, ssrOptions(), stream),
|
|
4955
|
+
() => renderToStream(url, ssrOptions(), stream as never),
|
|
4659
4956
|
);
|
|
4660
4957
|
await stream.write(htmlStart.replace("<!--app-head-->", head));
|
|
4661
4958
|
await stream.pipe(html);
|
|
@@ -4896,7 +5193,31 @@ if (isMain) {
|
|
|
4896
5193
|
process.exit(1);
|
|
4897
5194
|
}
|
|
4898
5195
|
}
|
|
4899
|
-
`,
|
|
5196
|
+
`,zn=`string`,Bn=f((n,r)=>{let{generators:i=[],refineTypeName:a,...s}=n.config,{createPath:c,createImportHelpers:l}=h(n),{renderToFile:u}=_({helpers:{...l({origin:`lib`})}});return{async build(e){let t=r?.renderMode?typeof r.renderMode==`string`?()=>r.renderMode:o(r?.renderMode,`string`):()=>zn,n={renderMode:JSON.stringify(r?.renderMode||null),pageRoutes:e.flatMap(e=>e.kind===`pageRoute`?[{...e.entry,renderMode:t(e.entry.name)}]:[]).sort(v),apiGenerator:i.some(e=>e.meta.slot===`backend`)};for(let[e,t]of[[`ssr.ts`,Rn],[`@ssr/api.ts`,Nn],[`@ssr/__kosmo_ssr_bundle.ts`,Fn],[`@ssr/base.ts`,Pn],[`@ssr/fetch.ts`,In],[`@ssr/routes.ts`,Ln]])await u(c.lib(e),t,n)},async postBuild(){let r=c.distDir(`ssr`),a=[y.tsconfigPaths(n),y.nodePrefix()];for(let e of i)await e.factory(n).ssrBuild?.();await S(p(s,...i.map(({factory:e})=>e(n).config?.({kind:`client`,command:`build`})),{root:c.src(),plugins:a,define:{KOSMO_PRODUCTION_BUILD:`true`},build:{ssr:c.lib(`@ssr/__kosmo_ssr_bundle`),ssrEmitAssets:!0,sourcemap:!0,emptyOutDir:!0,minify:!1,rolldownOptions:{output:{dir:r,entryFileNames:`app.js`,format:`esm`}}}})),await S({root:c.lib(),configFile:!1,appType:`custom`,plugins:a,resolve:{conditions:[`node`]},build:{ssr:c.lib(`ssr.ts`),target:`esnext`,sourcemap:!0,emptyOutDir:!0,rolldownOptions:{output:{dir:e(r,`server`),entryFileNames:`server.js`,format:`esm`}}}}),await T(t(r,`../client`),r,{recursive:!0});for(let e of[`server.js`,`server.js.map`])await T(`${r}/server/${e}`,`${r}/${e}`);await E(`${r}/server`,{recursive:!0,force:!0})}}}),Vn=d({meta:{name:`SSR`,slot:`ssr`},dependencies:{tinyglobby:q.devDependencies.tinyglobby,hono:q.devDependencies.hono,"@hono/node-server":q.devDependencies[`@hono/node-server`],"light-my-request":q.devDependencies[`light-my-request`]},factory:Bn}),J={type:`module`,private:!0,name:`@kosmojs/svelte-generator`,version:`0.2.10`,author:`Slee Woo`,license:`MIT`,files:[`pkg/*`],exports:{".":{types:`./pkg/index.d.ts`,default:`./pkg/index.js`}},scripts:{build:`wsbuild src/index.ts`},dependencies:{"@kosmojs/core":`workspace:^`,"@kosmojs/lib":`workspace:^`,"@sveltejs/vite-plugin-svelte":`^7.2.0`,vite:`^8.2.1`},devDependencies:{"@tanstack/svelte-query":`^6.1.38`,"path-to-regexp":`^8.4.2`,svelte:`^5.56.8`}},Hn=()=>{let e=[`🎉 Well done! You just created a new Svelte page.`,`🚀 Success! A fresh Svelte page is ready to roll.`,`🌟 Nice work! Another Svelte page added to your app.`,`🧩 All set! A new Svelte page has been scaffolded.`,`🔧 Scaffold complete! Your new Svelte page is in place.`,`✅ Built! Your Svelte page is scaffolded and ready.`,`✨ Fantastic! Your new Svelte page is good to go.`,`🎯 Nailed it! A brand new Svelte page just landed.`,`💫 Awesome! Another Svelte page joins the party.`,`⚡ Lightning fast! A new Svelte page created successfully.`];return e[Math.floor(Math.random()*e.length)]},Y=`<script lang="ts">
|
|
5197
|
+
import type { Snippet } from "svelte";
|
|
5198
|
+
|
|
5199
|
+
let { children }: { children: Snippet } = $props();
|
|
5200
|
+
<\/script>
|
|
5201
|
+
|
|
5202
|
+
{@render children()}
|
|
5203
|
+
`,Un=`<script lang="ts">
|
|
5204
|
+
import { type QueryClient, QueryClientProvider } from "@tanstack/svelte-query";
|
|
5205
|
+
import type { Snippet } from "svelte";
|
|
5206
|
+
|
|
5207
|
+
import { getQueryClient } from "../query";
|
|
5208
|
+
|
|
5209
|
+
let { client, children }: {
|
|
5210
|
+
client?: QueryClient;
|
|
5211
|
+
children: Snippet;
|
|
5212
|
+
} = $props();
|
|
5213
|
+
|
|
5214
|
+
const queryClient = $derived(client ?? getQueryClient());
|
|
5215
|
+
<\/script>
|
|
5216
|
+
|
|
5217
|
+
<QueryClientProvider client={queryClient}>
|
|
5218
|
+
{@render children()}
|
|
5219
|
+
</QueryClientProvider>
|
|
5220
|
+
`,Wn=`import { hydrate as hydrateOrig, mount as mountOrig } from "svelte";
|
|
4900
5221
|
import type { RouterFactoryReturn } from "@kosmojs/core";
|
|
4901
5222
|
import { clientRenderFactory } from "@kosmojs/core/generators";
|
|
4902
5223
|
|
|
@@ -4937,7 +5258,7 @@ export const mount = async (
|
|
|
4937
5258
|
}
|
|
4938
5259
|
|
|
4939
5260
|
export default clientRenderFactory();
|
|
4940
|
-
`,
|
|
5261
|
+
`,Gn=`import { render as renderOrig } from "svelte/server";
|
|
4941
5262
|
|
|
4942
5263
|
import type {
|
|
4943
5264
|
RenderToStringWrapper,
|
|
@@ -5003,12 +5324,12 @@ export const renderToString: RenderToStringWrapper<
|
|
|
5003
5324
|
// svelte/server exposes only render() - no web-stream renderer -
|
|
5004
5325
|
// so this folder is string-only SSR.
|
|
5005
5326
|
export default serverRenderFactory<false>();
|
|
5006
|
-
`,
|
|
5327
|
+
`,Kn=`declare module "*.svelte" {
|
|
5007
5328
|
import type { Component } from "svelte";
|
|
5008
5329
|
const component: Component;
|
|
5009
5330
|
export default component;
|
|
5010
5331
|
}
|
|
5011
|
-
`,
|
|
5332
|
+
`,qn=`<script lang="ts">
|
|
5012
5333
|
/**
|
|
5013
5334
|
* Folds [app, ...layouts] around the page component.
|
|
5014
5335
|
*
|
|
@@ -5026,7 +5347,7 @@ export default serverRenderFactory<false>();
|
|
|
5026
5347
|
|
|
5027
5348
|
setRouteContext(() => route);
|
|
5028
5349
|
|
|
5029
|
-
const chain = $derived([...layouts
|
|
5350
|
+
const chain = $derived([app, ...layouts.toReversed()]);
|
|
5030
5351
|
<\/script>
|
|
5031
5352
|
|
|
5032
5353
|
{#snippet layer(index: number)}
|
|
@@ -5042,7 +5363,7 @@ export default serverRenderFactory<false>();
|
|
|
5042
5363
|
{/snippet}
|
|
5043
5364
|
|
|
5044
5365
|
{@render layer(0)}
|
|
5045
|
-
`,
|
|
5366
|
+
`,Jn=`<script lang="ts">
|
|
5046
5367
|
import styles from "./styles.module.css";
|
|
5047
5368
|
|
|
5048
5369
|
let { headline }: { headline?: string } = $props();
|
|
@@ -5074,7 +5395,7 @@ export default serverRenderFactory<false>();
|
|
|
5074
5395
|
</div>
|
|
5075
5396
|
</div>
|
|
5076
5397
|
</div>
|
|
5077
|
-
`,
|
|
5398
|
+
`,Yn=`<script lang="ts">
|
|
5078
5399
|
import styles from "./styles.module.css";
|
|
5079
5400
|
|
|
5080
5401
|
let {
|
|
@@ -5119,7 +5440,7 @@ export default serverRenderFactory<false>();
|
|
|
5119
5440
|
</div>
|
|
5120
5441
|
</div>
|
|
5121
5442
|
</div>
|
|
5122
|
-
`,
|
|
5443
|
+
`,Xn=`* {
|
|
5123
5444
|
margin: 0;
|
|
5124
5445
|
padding: 0;
|
|
5125
5446
|
box-sizing: border-box;
|
|
@@ -5254,7 +5575,7 @@ export default serverRenderFactory<false>();
|
|
|
5254
5575
|
align-items: center;
|
|
5255
5576
|
gap: 0.25rem;
|
|
5256
5577
|
}
|
|
5257
|
-
`,
|
|
5578
|
+
`,Zn=`<script lang="ts">
|
|
5258
5579
|
import styles from "./styles.module.css";
|
|
5259
5580
|
<\/script>
|
|
5260
5581
|
|
|
@@ -5312,7 +5633,7 @@ export default serverRenderFactory<false>();
|
|
|
5312
5633
|
</div>
|
|
5313
5634
|
</div>
|
|
5314
5635
|
</div>
|
|
5315
|
-
`,
|
|
5636
|
+
`,Qn=`export type ParamsMap = {
|
|
5316
5637
|
{{#each pageRoutes}}"{{name}}": {{serializeParamsLiteral .}};
|
|
5317
5638
|
{{/each}}
|
|
5318
5639
|
};
|
|
@@ -5321,7 +5642,45 @@ export const paramNames = {
|
|
|
5321
5642
|
{{#each pageRoutes}}"{{name}}": [ {{#each params.schema}}"{{name}}", {{/each}}],
|
|
5322
5643
|
{{/each}}
|
|
5323
5644
|
} as const;
|
|
5324
|
-
|
|
5645
|
+
`,$n=`import { QueryClient, type QueryClientConfig } from "@tanstack/svelte-query";
|
|
5646
|
+
|
|
5647
|
+
let client: QueryClient | undefined;
|
|
5648
|
+
|
|
5649
|
+
export const createQueryClient = (options?: QueryClientConfig): QueryClient => {
|
|
5650
|
+
client = new QueryClient(options);
|
|
5651
|
+
return client;
|
|
5652
|
+
};
|
|
5653
|
+
|
|
5654
|
+
export const getQueryClient = (): QueryClient => {
|
|
5655
|
+
if (!client) {
|
|
5656
|
+
client = new QueryClient();
|
|
5657
|
+
}
|
|
5658
|
+
return client;
|
|
5659
|
+
};
|
|
5660
|
+
`,er=`import { QueryClient, type QueryClientConfig } from "@tanstack/svelte-query";
|
|
5661
|
+
|
|
5662
|
+
import { store } from "{{ createImport 'lib' '@ssr/base' }}";
|
|
5663
|
+
|
|
5664
|
+
export const createQueryClient = (options?: QueryClientConfig): QueryClient => {
|
|
5665
|
+
const client = new QueryClient(options);
|
|
5666
|
+
const ctx = store?.getStore();
|
|
5667
|
+
if (ctx) {
|
|
5668
|
+
ctx.tsqClient = client;
|
|
5669
|
+
}
|
|
5670
|
+
return client;
|
|
5671
|
+
};
|
|
5672
|
+
|
|
5673
|
+
export const getQueryClient = (): QueryClient => {
|
|
5674
|
+
const ctx = store?.getStore();
|
|
5675
|
+
if (!ctx) {
|
|
5676
|
+
throw new Error("getQueryClient(): called outside an SSR request scope");
|
|
5677
|
+
}
|
|
5678
|
+
if (!ctx.tsqClient) {
|
|
5679
|
+
ctx.tsqClient = new QueryClient();
|
|
5680
|
+
}
|
|
5681
|
+
return ctx.tsqClient as QueryClient;
|
|
5682
|
+
};
|
|
5683
|
+
`,tr=`import type { RouterFactoryReturn } from "@kosmojs/core";
|
|
5325
5684
|
import { createRouterFactory } from "@kosmojs/core/generators";
|
|
5326
5685
|
|
|
5327
5686
|
import Layouts from "./Layouts.svelte";
|
|
@@ -5361,7 +5720,7 @@ export default createRouterFactory<
|
|
|
5361
5720
|
Promise<RouteComponent>,
|
|
5362
5721
|
{ server: { route: Route } }
|
|
5363
5722
|
>();
|
|
5364
|
-
`,
|
|
5723
|
+
`,nr=`import { match, pathToRegexp } from "path-to-regexp";
|
|
5365
5724
|
import { type Component, createContext } from "svelte";
|
|
5366
5725
|
|
|
5367
5726
|
import { paramNames } from "{{ createImport 'lib' 'params' }}";
|
|
@@ -5572,7 +5931,7 @@ export const createRoute = (
|
|
|
5572
5931
|
layouts,
|
|
5573
5932
|
};
|
|
5574
5933
|
};
|
|
5575
|
-
`,
|
|
5934
|
+
`,rr=`import { getRouteContext } from "./svelte";
|
|
5576
5935
|
|
|
5577
5936
|
import type { ParamsMap, paramNames } from "{{ createImport 'lib' 'params' }}";
|
|
5578
5937
|
|
|
@@ -5608,18 +5967,17 @@ export const useLoaderData = <T>(key?: string): T | undefined => {
|
|
|
5608
5967
|
const route = useRoute();
|
|
5609
5968
|
return route.loaderData?.[key || route.name] as T;
|
|
5610
5969
|
};
|
|
5611
|
-
`,
|
|
5612
|
-
|
|
5613
|
-
* Root wrapper rendered around every page - the App layer of
|
|
5614
|
-
* [App, ...layouts]. Receives the rest of the chain as \`children\`.
|
|
5615
|
-
* */
|
|
5970
|
+
`,ir=`<script lang="ts">
|
|
5971
|
+
import { AppProvider } from "{{ createImport 'lib' 'app' }}";
|
|
5616
5972
|
import type { Snippet } from "svelte";
|
|
5617
5973
|
|
|
5618
5974
|
let { children }: { children: Snippet } = $props();
|
|
5619
5975
|
<\/script>
|
|
5620
5976
|
|
|
5621
|
-
|
|
5622
|
-
|
|
5977
|
+
<AppProvider>
|
|
5978
|
+
{@render children()}
|
|
5979
|
+
</AppProvider>
|
|
5980
|
+
`,ar=`<script lang="ts">
|
|
5623
5981
|
import type { Snippet } from "svelte";
|
|
5624
5982
|
import type { HTMLAnchorAttributes } from "svelte/elements";
|
|
5625
5983
|
|
|
@@ -5643,7 +6001,7 @@ export const useLoaderData = <T>(key?: string): T | undefined => {
|
|
|
5643
6001
|
<\/script>
|
|
5644
6002
|
|
|
5645
6003
|
<a {href} {...rest}>{@render children?.()}</a>
|
|
5646
|
-
`,
|
|
6004
|
+
`,or=`import renderFactory, {
|
|
5647
6005
|
createRoutes,
|
|
5648
6006
|
hydrate,
|
|
5649
6007
|
mount,
|
|
@@ -5670,7 +6028,7 @@ if (root) {
|
|
|
5670
6028
|
} else {
|
|
5671
6029
|
console.error("❌ Root element not found!");
|
|
5672
6030
|
}
|
|
5673
|
-
`,
|
|
6031
|
+
`,sr=`import renderFactory, {
|
|
5674
6032
|
createRoutes,
|
|
5675
6033
|
renderToString,
|
|
5676
6034
|
// no renderToStream on Svelte folders
|
|
@@ -5691,7 +6049,7 @@ export default renderFactory(() => {
|
|
|
5691
6049
|
},
|
|
5692
6050
|
};
|
|
5693
6051
|
});
|
|
5694
|
-
`,
|
|
6052
|
+
`,cr=`<!doctype html>
|
|
5695
6053
|
<html lang="en">
|
|
5696
6054
|
<head>
|
|
5697
6055
|
<meta charset="UTF-8" />
|
|
@@ -5703,19 +6061,19 @@ export default renderFactory(() => {
|
|
|
5703
6061
|
<script type="module" src="/{{ entryDir }}/client.ts"><\/script>
|
|
5704
6062
|
</body>
|
|
5705
6063
|
</html>
|
|
5706
|
-
`,
|
|
6064
|
+
`,lr=`<script lang="ts">
|
|
5707
6065
|
import PageSample from "{{ createImport 'lib' 'pageSamples/404.svelte' }}";
|
|
5708
6066
|
<\/script>
|
|
5709
6067
|
|
|
5710
6068
|
<PageSample />
|
|
5711
|
-
`,
|
|
6069
|
+
`,ur=`<script lang="ts">
|
|
5712
6070
|
import type { Snippet } from "svelte";
|
|
5713
6071
|
|
|
5714
6072
|
let { children }: { children: Snippet } = $props();
|
|
5715
6073
|
<\/script>
|
|
5716
6074
|
|
|
5717
6075
|
{@render children()}
|
|
5718
|
-
`,
|
|
6076
|
+
`,dr=`<script lang="ts">
|
|
5719
6077
|
import PageSample from "{{ createImport 'lib' 'pageSamples/page.svelte' }}";
|
|
5720
6078
|
|
|
5721
6079
|
const pathMap = {
|
|
@@ -5734,7 +6092,7 @@ export default renderFactory(() => {
|
|
|
5734
6092
|
routeName={"{{route.name}}"}
|
|
5735
6093
|
{pathMap}
|
|
5736
6094
|
/>
|
|
5737
|
-
`,
|
|
6095
|
+
`,fr=`<script lang="ts">
|
|
5738
6096
|
import WelcomePage from "{{ createImport 'lib' 'pageSamples/welcome.svelte' }}";
|
|
5739
6097
|
<\/script>
|
|
5740
6098
|
|
|
@@ -5747,9 +6105,9 @@ export default renderFactory(() => {
|
|
|
5747
6105
|
</svelte:head>
|
|
5748
6106
|
|
|
5749
6107
|
<WelcomePage />
|
|
5750
|
-
`,
|
|
6108
|
+
`,pr=`import routerFactory, { createRouters } from "{{ createImport 'lib' 'router' }}";
|
|
5751
6109
|
|
|
5752
|
-
import app from "./
|
|
6110
|
+
import app from "./app.svelte";
|
|
5753
6111
|
|
|
5754
6112
|
export default routerFactory((routes) => {
|
|
5755
6113
|
const { clientRouter, serverRouter } = createRouters(routes, { app });
|
|
@@ -5762,7 +6120,7 @@ export default routerFactory((routes) => {
|
|
|
5762
6120
|
},
|
|
5763
6121
|
};
|
|
5764
6122
|
});
|
|
5765
|
-
|
|
6123
|
+
`,mr=f((e,t)=>{let{createPath:n,createImportHelpers:r}=h(e),{renderToFile:i}=_({helpers:{...r({origin:`lib`}),...b()}}),{renderToFile:a}=_({helpers:r({origin:`src`})}),o=e=>!e?.trim().length,l=s(t?.templates,dr),u=async e=>{for(let{kind:t,entry:r}of e)t===`pageRoute`?await a(n.pages(r.file),r.name===`index`?fr:l(r.name,r),{route:r,title:r.name.replace(/\{([^}]+)\}/g,`$1`),message:Hn()},{overwrite:o}):t===`pageLayout`&&await a(n.pages(r.file),ur,{route:r},{overwrite:o})},d=async e=>{let t=e.flatMap(({kind:e,entry:t})=>e===`pageLayout`?[t]:[]),r=e.flatMap(({kind:e,entry:n})=>{if(e===`pageRoute`){let{name:e,file:r}=n;return[{...n,layouts:t.flatMap(t=>t.name===e||r.startsWith(`${t.name}/`)?[t]:[]).sort(v)}]}return[]}).sort(v);for(let[e,a]of[[`client.ts`,Wn],[`server.ts`,Gn]])await i(n.libEntry(e),a,{pageRoutes:r,layouts:t});for(let[e,t]of[[`params.ts`,Qn],[`router.ts`,tr]])await i(n.lib(e),t,{pageRoutes:r})};return{config(){let{templates:e,...n}={...t};return{plugins:de(n)}},async start(){for(let[e,r]of[[`env.d.ts`,Kn],[`svelte.ts`,nr],[`Layouts.svelte`,qn],[`use.ts`,rr],[`pageSamples/styles.module.css`,Xn],[`pageSamples/welcome.svelte`,Zn],[`pageSamples/page.svelte`,Yn],[`pageSamples/404.svelte`,Jn],...t?.tanstack?.query?[[`app/app.svelte`,Y],[`app/app-tsq.svelte`,Un],[`app/index.ts`,`export { default as AppProvider } from "./app-tsq.svelte";`],[`query.ts`,$n]]:[[`app/app.svelte`,Y],[`app/app-tsq.svelte`,`/** tanstack query disabled */`],[`app/index.ts`,`export { default as AppProvider } from "./app.svelte";`],[`query.ts`,`/** tanstack query disabled */`]]])await i(n.lib(e),r,{});for(let[e,t]of[[`pages/404.svelte`,lr],[`components/Link.svelte`,ar],[`app.svelte`,ir],[`router.ts`,pr]])await a(n.src(e),t,{entryDir:c.entryDir},{overwrite:o});await a(n.src(`index.html`),cr,{entryDir:c.entryDir},{overwrite:e=>!e?.trim().length||!e.replace(/<!--[\s\S]*?-->/g,``).trim().length});for(let[e,t]of[[`client.ts`,or],[`server.ts`,sr]])await a(n.entry(e),t,{},{overwrite:o})},async watch(e,t){(!t||t.kind===`create`)&&await u(e),await d(e)},async build(e){await u(e),await d(e)},async ssrBuild(){await i(n.lib(`query.ts`),t?.tanstack?.query?er:`/** tanstack query disabled */`,{ssrBundle:!0})}}}),hr=d({meta:{name:`Svelte`},dependencies(e){return{svelte:J.devDependencies.svelte,"path-to-regexp":J.devDependencies[`path-to-regexp`],...e?.tanstack?.query?{"@tanstack/svelte-query":J.devDependencies[`@tanstack/svelte-query`]}:{}}},factory:mr}),gr={type:`module`,private:!0,name:`@kosmojs/typebox-generator`,version:`0.2.10`,cacheVersion:`1`,author:`Slee Woo`,license:`MIT`,files:[`pkg/*`],exports:{".":{types:`./pkg/index.d.ts`,default:`./pkg/index.js`}},scripts:{build:`wsbuild src/index.ts`,test:`vitest --root ../.. --project generators/typebox-generator`},dependencies:{"@kosmojs/core":`workspace:^`,"@kosmojs/lib":`workspace:^`,crc:`^4.3.2`,semver:`^7.8.5`},devDependencies:{"@kosmojs/core-generator":`workspace:^`,"@kosmojs/koa-generator":`workspace:^`,typebox:`^1.3.11`}},_r=`import Type from "typebox";
|
|
5766
6124
|
|
|
5767
6125
|
/**
|
|
5768
6126
|
* Custom types for JavaScript constructs that have no JSON Schema
|
|
@@ -5834,7 +6192,7 @@ export default {
|
|
|
5834
6192
|
Buffer: TBuffer(),
|
|
5835
6193
|
ArrayBuffer: TArrayBuffer(),
|
|
5836
6194
|
};
|
|
5837
|
-
`,
|
|
6195
|
+
`,vr=`import type { TValidationError } from "typebox/error";
|
|
5838
6196
|
|
|
5839
6197
|
import type { ValidationErrorEntry } from "@kosmojs/core";
|
|
5840
6198
|
|
|
@@ -7018,7 +7376,7 @@ const format = (fmt: string, ...args: unknown[]): string => {
|
|
|
7018
7376
|
|
|
7019
7377
|
return str;
|
|
7020
7378
|
};
|
|
7021
|
-
`,
|
|
7379
|
+
`,yr=`import Type from "typebox";
|
|
7022
7380
|
import { Compile } from "typebox/compile";
|
|
7023
7381
|
import Value from "typebox/value";
|
|
7024
7382
|
|
|
@@ -7070,14 +7428,14 @@ export const validationSchemaFactory = (
|
|
|
7070
7428
|
},
|
|
7071
7429
|
};
|
|
7072
7430
|
};
|
|
7073
|
-
`,
|
|
7431
|
+
`,br=`import { Settings } from "typebox/system";
|
|
7074
7432
|
|
|
7075
7433
|
Settings.Set({{settings}});
|
|
7076
7434
|
|
|
7077
7435
|
export { default as customTypes } from "{{customTypesImport}}";
|
|
7078
7436
|
|
|
7079
7437
|
export const validationMessages = {{validationMessages}};
|
|
7080
|
-
`,
|
|
7438
|
+
`,xr=`import type { ValidationSchemas } from "@kosmojs/core";
|
|
7081
7439
|
|
|
7082
7440
|
import { validationSchemaFactory } from "{{ createImport 'lib' '@typebox' }}";
|
|
7083
7441
|
|
|
@@ -7138,7 +7496,29 @@ export const validationSchemas: ValidationSchemas = {
|
|
|
7138
7496
|
{{/each}}
|
|
7139
7497
|
},
|
|
7140
7498
|
};
|
|
7141
|
-
`,
|
|
7499
|
+
`,Sr={exactOptionalPropertyTypes:!0},Cr=f((e,t)=>{let{createPath:n,createImport:r,createImportHelpers:i}=h(e),{renderToFile:o}=_({helpers:{...i({origin:`lib`})}}),{validationMessages:s={},customTypesImport:c=r.lib([`@typebox/custom-types`],{origin:`lib`}),settings:l}={...t},u=async e=>{for(let{kind:t,entry:r}of e){if(t!==`apiRoute`)continue;let e=[r.params,...r.validationDefinitions.flatMap(e=>e.target===`response`?e.variants:[e.schema])].flatMap(({resolvedType:e})=>e?[e]:[]),i=[...new Set(r.validationDefinitions.flatMap(({target:e})=>Object.keys(a).includes(e)?[e]:[]))].map(e=>({target:e,methods:r.methods.flatMap(t=>{let n=r.validationDefinitions.find(n=>n.method===t&&n.target===e);return n?[{route:r.name,method:t,target:e,schema:n.schema,...n.runtimeValidation===void 0?{}:{runtimeValidation:JSON.stringify(n.runtimeValidation)},...n.customErrors===void 0?{}:{customErrors:JSON.stringify(n.customErrors)}}]:[]})})),s=r.methods.flatMap(e=>{let t=r.validationDefinitions.find(t=>t.method===e&&t.target===`response`);return t?[{method:e,variants:t.variants.map(e=>({route:r.name,target:`response`,...e,...t.runtimeValidation===void 0?{}:{runtimeValidation:JSON.stringify(t.runtimeValidation)},...t.customErrors===void 0?{}:{customErrors:JSON.stringify(t.customErrors)}}))}]:[]});await o(n.libApi(r.name,`schemas.ts`),xr,{route:r,resolvedTypes:e,requestSchemas:i,responseSchemas:s})}};return{async start(){for(let[e,t]of[[`custom-types.ts`,_r],[`error-handler.ts`,vr],[`index.ts`,yr],[`setup.ts`,br]])await o(n.lib(`@typebox`,e),t,{validationMessages:JSON.stringify(s),customTypesImport:c,settings:JSON.stringify({...Sr,...l})})},async watch(e,t){await u(t?e.filter(({kind:e,entry:n})=>t.kind===`update`&&e===`apiRoute`&&n.fileFullpath===t.file):e)},async build(e){await u(e)}}}),X={PROPERTY:`PROPERTY`,PROPERTIES:`PROPERTIES`,ALLOWED_VALUES:`ALLOWED_VALUES`,FOUND_N_DUPLICATES:`FOUND_N_DUPLICATES`,VALIDATION_PASSED:`VALIDATION_PASSED`,VALIDATION_FAILED_PREFIX:`VALIDATION_FAILED_PREFIX`,ERROR_SUMMARY:`ERROR_SUMMARY`,PLURAL_SUFFIX:`PLURAL_SUFFIX`,FIRST:`FIRST`,SECOND:`SECOND`,THIRD:`THIRD`,FOURTH:`FOURTH`,FIFTH:`FIFTH`,TYPE_INVALID:`TYPE_INVALID`,STRING_MIN_LENGTH:`STRING_MIN_LENGTH`,STRING_MAX_LENGTH:`STRING_MAX_LENGTH`,STRING_PATTERN:`STRING_PATTERN`,STRING_FORMAT:`STRING_FORMAT`,STRING_FORMAT_EMAIL:`STRING_FORMAT_EMAIL`,STRING_FORMAT_DATE:`STRING_FORMAT_DATE`,STRING_FORMAT_DATETIME:`STRING_FORMAT_DATETIME`,STRING_FORMAT_TIME:`STRING_FORMAT_TIME`,STRING_FORMAT_URI:`STRING_FORMAT_URI`,STRING_FORMAT_URL:`STRING_FORMAT_URL`,STRING_FORMAT_UUID:`STRING_FORMAT_UUID`,STRING_FORMAT_IPV4:`STRING_FORMAT_IPV4`,STRING_FORMAT_IPV6:`STRING_FORMAT_IPV6`,STRING_FORMAT_HOSTNAME:`STRING_FORMAT_HOSTNAME`,STRING_FORMAT_JSON_POINTER:`STRING_FORMAT_JSON_POINTER`,STRING_FORMAT_REGEX:`STRING_FORMAT_REGEX`,NUMBER_MINIMUM:`NUMBER_MINIMUM`,NUMBER_MAXIMUM:`NUMBER_MAXIMUM`,NUMBER_EXCLUSIVE_MINIMUM:`NUMBER_EXCLUSIVE_MINIMUM`,NUMBER_EXCLUSIVE_MAXIMUM:`NUMBER_EXCLUSIVE_MAXIMUM`,NUMBER_MULTIPLE_OF:`NUMBER_MULTIPLE_OF`,ARRAY_MIN_ITEMS:`ARRAY_MIN_ITEMS`,ARRAY_MAX_ITEMS:`ARRAY_MAX_ITEMS`,ARRAY_UNIQUE_ITEMS:`ARRAY_UNIQUE_ITEMS`,ARRAY_CONTAINS:`ARRAY_CONTAINS`,ARRAY_MIN_CONTAINS:`ARRAY_MIN_CONTAINS`,ARRAY_MAX_CONTAINS:`ARRAY_MAX_CONTAINS`,ARRAY_PREFIX_ITEMS:`ARRAY_PREFIX_ITEMS`,ARRAY_ITEMS:`ARRAY_ITEMS`,ARRAY_UNEVALUATED_ITEMS:`ARRAY_UNEVALUATED_ITEMS`,TUPLE_MIN_ITEMS:`TUPLE_MIN_ITEMS`,TUPLE_MAX_ITEMS:`TUPLE_MAX_ITEMS`,OBJECT_REQUIRED:`OBJECT_REQUIRED`,OBJECT_ADDITIONAL_PROPERTIES:`OBJECT_ADDITIONAL_PROPERTIES`,OBJECT_MIN_PROPERTIES:`OBJECT_MIN_PROPERTIES`,OBJECT_MAX_PROPERTIES:`OBJECT_MAX_PROPERTIES`,OBJECT_PROPERTY_NAMES:`OBJECT_PROPERTY_NAMES`,OBJECT_DEPENDENCIES:`OBJECT_DEPENDENCIES`,OBJECT_UNEVALUATED_PROPERTIES:`OBJECT_UNEVALUATED_PROPERTIES`,ENUM_MISMATCH:`ENUM_MISMATCH`,CONST_MISMATCH:`CONST_MISMATCH`,CONDITIONAL_IF:`CONDITIONAL_IF`,CONDITIONAL_THEN:`CONDITIONAL_THEN`,CONDITIONAL_ELSE:`CONDITIONAL_ELSE`,COMPOSITION_ONE_OF:`COMPOSITION_ONE_OF`,COMPOSITION_ANY_OF:`COMPOSITION_ANY_OF`,COMPOSITION_ALL_OF:`COMPOSITION_ALL_OF`,COMPOSITION_NOT:`COMPOSITION_NOT`,CONTENT_DISCRIMINATOR:`CONTENT_DISCRIMINATOR`,CONTENT_ENCODING:`CONTENT_ENCODING`,CONTENT_MEDIA_TYPE:`CONTENT_MEDIA_TYPE`,CUSTOM_RANGE:`CUSTOM_RANGE`,CUSTOM_EXCLUSIVE_RANGE:`CUSTOM_EXCLUSIVE_RANGE`,CUSTOM_REGEXP:`CUSTOM_REGEXP`,CUSTOM_DYNAMIC_DEFAULTS:`CUSTOM_DYNAMIC_DEFAULTS`,CUSTOM_SELECT:`CUSTOM_SELECT`,CUSTOM_TRANSFORM:`CUSTOM_TRANSFORM`,CUSTOM_UNIQUE_ITEM_PROPERTIES:`CUSTOM_UNIQUE_ITEM_PROPERTIES`,UNKNOWN:`UNKNOWN`};X.PROPERTY,X.PROPERTIES,X.ALLOWED_VALUES,X.FOUND_N_DUPLICATES,X.VALIDATION_PASSED,X.VALIDATION_FAILED_PREFIX,X.ERROR_SUMMARY,X.PLURAL_SUFFIX,X.FIRST,X.SECOND,X.THIRD,X.FOURTH,X.FIFTH,X.TYPE_INVALID,X.STRING_MIN_LENGTH,X.STRING_MAX_LENGTH,X.STRING_PATTERN,X.STRING_FORMAT,X.STRING_FORMAT_EMAIL,X.STRING_FORMAT_DATE,X.STRING_FORMAT_DATETIME,X.STRING_FORMAT_TIME,X.STRING_FORMAT_URI,X.STRING_FORMAT_URL,X.STRING_FORMAT_UUID,X.STRING_FORMAT_IPV4,X.STRING_FORMAT_IPV6,X.STRING_FORMAT_HOSTNAME,X.STRING_FORMAT_JSON_POINTER,X.STRING_FORMAT_REGEX,X.NUMBER_MINIMUM,X.NUMBER_MAXIMUM,X.NUMBER_EXCLUSIVE_MINIMUM,X.NUMBER_EXCLUSIVE_MAXIMUM,X.NUMBER_MULTIPLE_OF,X.ARRAY_MIN_ITEMS,X.ARRAY_MAX_ITEMS,X.ARRAY_UNIQUE_ITEMS,X.ARRAY_CONTAINS,X.ARRAY_MIN_CONTAINS,X.ARRAY_MAX_CONTAINS,X.ARRAY_PREFIX_ITEMS,X.ARRAY_ITEMS,X.ARRAY_UNEVALUATED_ITEMS,X.TUPLE_MIN_ITEMS,X.TUPLE_MAX_ITEMS,X.OBJECT_REQUIRED,X.OBJECT_ADDITIONAL_PROPERTIES,X.OBJECT_MIN_PROPERTIES,X.OBJECT_MAX_PROPERTIES,X.OBJECT_PROPERTY_NAMES,X.OBJECT_DEPENDENCIES,X.OBJECT_UNEVALUATED_PROPERTIES,X.ENUM_MISMATCH,X.CONST_MISMATCH,X.CONDITIONAL_IF,X.CONDITIONAL_THEN,X.CONDITIONAL_ELSE,X.COMPOSITION_ONE_OF,X.COMPOSITION_ANY_OF,X.COMPOSITION_ALL_OF,X.COMPOSITION_NOT,X.CONTENT_DISCRIMINATOR,X.CONTENT_ENCODING,X.CONTENT_MEDIA_TYPE,X.CUSTOM_RANGE,X.CUSTOM_EXCLUSIVE_RANGE,X.CUSTOM_REGEXP,X.CUSTOM_DYNAMIC_DEFAULTS,X.CUSTOM_SELECT,X.CUSTOM_TRANSFORM,X.CUSTOM_UNIQUE_ITEM_PROPERTIES,X.UNKNOWN;var wr=d({meta:{name:`TypeBox`,resolveTypes:!0},dependencies:{typebox:gr.devDependencies.typebox},factory:Cr}),Z={type:`module`,private:!0,name:`@kosmojs/vue-generator`,version:`0.2.10`,author:`Slee Woo`,license:`MIT`,files:[`pkg/*`],exports:{".":{types:`./pkg/index.d.ts`,default:`./pkg/index.js`}},scripts:{build:`wsbuild src/index.ts`,test:`vitest --root ../.. --project generators/vue-generator`},dependencies:{"@kosmojs/core":`workspace:^`,"@kosmojs/lib":`workspace:^`,"@vitejs/plugin-vue":`^6.0.8`},devDependencies:{"@tanstack/vue-query":`^5.101.4`,"path-to-regexp":`^8.4.2`,vue:`^3.5.41`,"vue-router":`^5.2.0`}},Q=e=>{let t=e=>e.kind===`splat`?`:${e.name}(.*)?`:e.kind===`optional`?`:${e.name}?`:`:${e.name}`;return e.flatMap(e=>e.kind===`static`?[e.parts[0].value]:e.kind===`param`?[t(e.parts[0])]:[e.parts.map(e=>e.type===`static`?e.value:t(e)).join(``)]).join(`/`)},Tr=()=>{let t=e=>e?.kind===`param`&&e.parts[0]?.kind===`splat`,n=(r,i)=>r.flatMap(({index:r,layout:a,children:o})=>{let{name:s,pathTokens:c}={...r,...a};if(!c)return[];let l=`${s}/layout`,u=i?Q(c):e(`/`,Q(c)),d=c.at(-1);return t(d)?r&&a?[{name:l,path:u,component:a.id,children:[{name:s,path:``,component:r.id}]}]:r?[{path:u,children:[{name:s,path:``,component:r.id},...n(o,s)]}]:a?[{name:l,path:u,component:a.id,children:n(o,s)}]:[]:r&&a?[{name:l,path:u,component:a.id,children:[{name:s,path:``,component:r.id},...n(o,s)]}]:r?[{path:u,children:[{name:s,path:``,component:r.id},...n(o,s)]}]:a?[{name:l,path:u,component:a.id,children:n(o,s)}]:[]});return n},Er=()=>{let e=[`🎉 Well done! You just created a new Vue route.`,`🚀 Success! A fresh Vue route is ready to roll.`,`🌟 Nice work! Another Vue route added to your app.`,`🧩 All set! A new Vue route has been scaffolded.`,`🔧 Scaffold complete! Your new Vue route is in place.`,`✅ Built! Your Vue route is scaffolded and ready.`,`✨ Fantastic! Your new Vue route is good to go.`,`🎯 Nailed it! A brand new Vue route just landed.`,`💫 Awesome! Another Vue route joins the party.`,`⚡ Lightning fast! A new Vue route created successfully.`];return e[Math.floor(Math.random()*e.length)]},Dr=`import type { Plugin } from "vue";
|
|
7500
|
+
|
|
7501
|
+
export { default as AppProvider } from "./provider.vue";
|
|
7502
|
+
|
|
7503
|
+
export const appProvider: Plugin = {
|
|
7504
|
+
install() {},
|
|
7505
|
+
};
|
|
7506
|
+
`,Or=`import { VueQueryPlugin } from "@tanstack/vue-query";
|
|
7507
|
+
import type { Plugin } from "vue";
|
|
7508
|
+
|
|
7509
|
+
import { getQueryClient } from "../query";
|
|
7510
|
+
|
|
7511
|
+
export { default as AppProvider } from "./provider.vue";
|
|
7512
|
+
|
|
7513
|
+
export const appProvider: Plugin = {
|
|
7514
|
+
install(app) {
|
|
7515
|
+
app.use(VueQueryPlugin, { queryClient: getQueryClient() });
|
|
7516
|
+
},
|
|
7517
|
+
};
|
|
7518
|
+
`,kr=`<template>
|
|
7519
|
+
<slot />
|
|
7520
|
+
</template>
|
|
7521
|
+
`,Ar=`import type { App } from "vue";
|
|
7142
7522
|
import type { RouterFactoryReturn } from "@kosmojs/core";
|
|
7143
7523
|
import { clientRenderFactory } from "@kosmojs/core/generators";
|
|
7144
7524
|
|
|
@@ -7178,7 +7558,7 @@ export const mount = async (
|
|
|
7178
7558
|
}
|
|
7179
7559
|
|
|
7180
7560
|
export default clientRenderFactory();
|
|
7181
|
-
`,
|
|
7561
|
+
`,jr=`{
|
|
7182
7562
|
path: "{{path}}",
|
|
7183
7563
|
{{#if name}}
|
|
7184
7564
|
name: "{{name}}",
|
|
@@ -7196,7 +7576,7 @@ export default clientRenderFactory();
|
|
|
7196
7576
|
children: [ {{#each children}}{{> routePartial}}, {{/each}}],
|
|
7197
7577
|
{{/if}}
|
|
7198
7578
|
}
|
|
7199
|
-
`,
|
|
7579
|
+
`,Mr=`import type { App } from "vue";
|
|
7200
7580
|
|
|
7201
7581
|
import {
|
|
7202
7582
|
renderToString as renderToStringOrig,
|
|
@@ -7296,7 +7676,7 @@ export default serverRenderFactory();
|
|
|
7296
7676
|
const component: DefineComponent<{}, {}, any>;
|
|
7297
7677
|
export default component;
|
|
7298
7678
|
}
|
|
7299
|
-
`,
|
|
7679
|
+
`,Nr=`<script setup lang="ts">
|
|
7300
7680
|
import styles from "./styles.module.css";
|
|
7301
7681
|
defineProps<{
|
|
7302
7682
|
headline?: string;
|
|
@@ -7335,7 +7715,7 @@ defineProps<{
|
|
|
7335
7715
|
</div>
|
|
7336
7716
|
</div>
|
|
7337
7717
|
</template>
|
|
7338
|
-
`,
|
|
7718
|
+
`,Pr=`<script setup lang="ts">
|
|
7339
7719
|
import styles from "./styles.module.css";
|
|
7340
7720
|
defineProps<{
|
|
7341
7721
|
message: string;
|
|
@@ -7384,7 +7764,7 @@ defineProps<{
|
|
|
7384
7764
|
</div>
|
|
7385
7765
|
</div>
|
|
7386
7766
|
</template>
|
|
7387
|
-
`,
|
|
7767
|
+
`,Fr=`* {
|
|
7388
7768
|
margin: 0;
|
|
7389
7769
|
padding: 0;
|
|
7390
7770
|
box-sizing: border-box;
|
|
@@ -7517,7 +7897,7 @@ defineProps<{
|
|
|
7517
7897
|
align-items: center;
|
|
7518
7898
|
gap: 0.25rem;
|
|
7519
7899
|
}
|
|
7520
|
-
`,
|
|
7900
|
+
`,Ir=`<script setup lang="ts">
|
|
7521
7901
|
import styles from "./styles.module.css";
|
|
7522
7902
|
<\/script>
|
|
7523
7903
|
|
|
@@ -7581,7 +7961,51 @@ import styles from "./styles.module.css";
|
|
|
7581
7961
|
</div>
|
|
7582
7962
|
</div>
|
|
7583
7963
|
</template>
|
|
7584
|
-
`,
|
|
7964
|
+
`,Lr=`import { QueryClient, type QueryClientConfig } from "@tanstack/vue-query";
|
|
7965
|
+
|
|
7966
|
+
let client: QueryClient | undefined;
|
|
7967
|
+
|
|
7968
|
+
export const createQueryClient = (options?: QueryClientConfig): QueryClient => {
|
|
7969
|
+
client = new QueryClient(options);
|
|
7970
|
+
return client;
|
|
7971
|
+
};
|
|
7972
|
+
|
|
7973
|
+
export const getQueryClient = (): QueryClient => {
|
|
7974
|
+
if (!client) {
|
|
7975
|
+
client = new QueryClient();
|
|
7976
|
+
}
|
|
7977
|
+
return client;
|
|
7978
|
+
};
|
|
7979
|
+
`,Rr=`import { QueryClient, type QueryClientConfig } from "@tanstack/vue-query";
|
|
7980
|
+
|
|
7981
|
+
import { store } from "{{ createImport 'lib' '@ssr/base' }}";
|
|
7982
|
+
|
|
7983
|
+
export const createQueryClient = (options?: QueryClientConfig): QueryClient => {
|
|
7984
|
+
const client = new QueryClient(options);
|
|
7985
|
+
const ctx = store?.getStore();
|
|
7986
|
+
if (ctx) {
|
|
7987
|
+
ctx.tsqClient = client;
|
|
7988
|
+
}
|
|
7989
|
+
return client;
|
|
7990
|
+
};
|
|
7991
|
+
|
|
7992
|
+
export const getQueryClient = (): QueryClient => {
|
|
7993
|
+
const ctx = store?.getStore();
|
|
7994
|
+
if (!ctx) {
|
|
7995
|
+
throw new Error("getQueryClient(): called outside an SSR request scope");
|
|
7996
|
+
}
|
|
7997
|
+
if (!ctx.tsqClient) {
|
|
7998
|
+
ctx.tsqClient = new QueryClient();
|
|
7999
|
+
}
|
|
8000
|
+
return ctx.tsqClient as QueryClient;
|
|
8001
|
+
};
|
|
8002
|
+
`,zr=`import {
|
|
8003
|
+
type App,
|
|
8004
|
+
type Component,
|
|
8005
|
+
createApp,
|
|
8006
|
+
createSSRApp,
|
|
8007
|
+
type Plugin,
|
|
8008
|
+
} from "vue";
|
|
7585
8009
|
import {
|
|
7586
8010
|
createMemoryHistory,
|
|
7587
8011
|
createRouter,
|
|
@@ -7652,7 +8076,13 @@ const installLoaderGuard = (router: RouterWithLoaderData) => {
|
|
|
7652
8076
|
|
|
7653
8077
|
export const createRouters = (
|
|
7654
8078
|
routes: Array<RouteRecordRaw>,
|
|
7655
|
-
{
|
|
8079
|
+
{
|
|
8080
|
+
app,
|
|
8081
|
+
use,
|
|
8082
|
+
}: {
|
|
8083
|
+
app: Component;
|
|
8084
|
+
use?: Array<[plugin: Plugin, options: object | undefined]>;
|
|
8085
|
+
},
|
|
7656
8086
|
): {
|
|
7657
8087
|
clientRouter: () => RouterFactoryReturn<Promise<App>>;
|
|
7658
8088
|
serverRouter: (
|
|
@@ -7676,6 +8106,12 @@ export const createRouters = (
|
|
|
7676
8106
|
|
|
7677
8107
|
component.use(router);
|
|
7678
8108
|
|
|
8109
|
+
if (Array.isArray(use)) {
|
|
8110
|
+
for (const [plugin, options] of use) {
|
|
8111
|
+
component.use(plugin, options);
|
|
8112
|
+
}
|
|
8113
|
+
}
|
|
8114
|
+
|
|
7679
8115
|
return { component };
|
|
7680
8116
|
},
|
|
7681
8117
|
|
|
@@ -7698,6 +8134,12 @@ export const createRouters = (
|
|
|
7698
8134
|
|
|
7699
8135
|
component.use(router);
|
|
7700
8136
|
|
|
8137
|
+
if (Array.isArray(use)) {
|
|
8138
|
+
for (const [plugin, options] of use) {
|
|
8139
|
+
component.use(plugin, options);
|
|
8140
|
+
}
|
|
8141
|
+
}
|
|
8142
|
+
|
|
7701
8143
|
return { component, loaderData: router.__loaderData };
|
|
7702
8144
|
},
|
|
7703
8145
|
};
|
|
@@ -7708,14 +8150,14 @@ export default createRouterFactory<
|
|
|
7708
8150
|
Promise<App>,
|
|
7709
8151
|
{ server: { loaderData: Record<string, unknown> } }
|
|
7710
8152
|
>();
|
|
7711
|
-
`,
|
|
8153
|
+
`,Br=`import { type Ref, unref } from "vue";
|
|
7712
8154
|
|
|
7713
8155
|
export type MaybeWrapped<T> = Ref<T> | T;
|
|
7714
8156
|
|
|
7715
8157
|
export function unwrap<T>(value: MaybeWrapped<T>): T {
|
|
7716
8158
|
return unref(value);
|
|
7717
8159
|
}
|
|
7718
|
-
`,
|
|
8160
|
+
`,Vr=`import { useRoute, useRouter } from "vue-router";
|
|
7719
8161
|
|
|
7720
8162
|
import type { RouterWithLoaderData } from "./router";
|
|
7721
8163
|
|
|
@@ -7730,10 +8172,16 @@ export const useLoaderData = <T>(key?: string): T | undefined => {
|
|
|
7730
8172
|
const route = useRoute();
|
|
7731
8173
|
return router.__loaderData?.[key || (route.name as string)] as T;
|
|
7732
8174
|
};
|
|
7733
|
-
`,
|
|
7734
|
-
|
|
8175
|
+
`,Hr=`<script setup lang="ts">
|
|
8176
|
+
import { AppProvider } from "_/app";
|
|
8177
|
+
<\/script>
|
|
8178
|
+
|
|
8179
|
+
<template>
|
|
8180
|
+
<AppProvider>
|
|
8181
|
+
<RouterView />
|
|
8182
|
+
</AppProvider>
|
|
7735
8183
|
</template>
|
|
7736
|
-
`,
|
|
8184
|
+
`,Ur=`<script setup lang="ts" generic="T extends LinkProps">
|
|
7737
8185
|
import { computed } from "vue";
|
|
7738
8186
|
import { RouterLink } from "vue-router";
|
|
7739
8187
|
|
|
@@ -7765,7 +8213,7 @@ const href = computed(() => {
|
|
|
7765
8213
|
<slot />
|
|
7766
8214
|
</RouterLink>
|
|
7767
8215
|
</template>
|
|
7768
|
-
`,
|
|
8216
|
+
`,Wr=`import renderFactory, {
|
|
7769
8217
|
createRoutes,
|
|
7770
8218
|
hydrate,
|
|
7771
8219
|
mount,
|
|
@@ -7792,7 +8240,7 @@ if (root) {
|
|
|
7792
8240
|
} else {
|
|
7793
8241
|
console.error("❌ Root element not found!");
|
|
7794
8242
|
}
|
|
7795
|
-
`,
|
|
8243
|
+
`,Gr=`import renderFactory, {
|
|
7796
8244
|
createRoutes,
|
|
7797
8245
|
renderToStream,
|
|
7798
8246
|
renderToString,
|
|
@@ -7819,7 +8267,7 @@ export default renderFactory(() => {
|
|
|
7819
8267
|
},
|
|
7820
8268
|
};
|
|
7821
8269
|
});
|
|
7822
|
-
`,
|
|
8270
|
+
`,Kr=`<!doctype html>
|
|
7823
8271
|
<html lang="en">
|
|
7824
8272
|
<head>
|
|
7825
8273
|
<meta charset="UTF-8" />
|
|
@@ -7831,17 +8279,17 @@ export default renderFactory(() => {
|
|
|
7831
8279
|
<script type="module" src="/{{ entryDir }}/client.ts"><\/script>
|
|
7832
8280
|
</body>
|
|
7833
8281
|
</html>
|
|
7834
|
-
`,
|
|
8282
|
+
`,qr=`<script setup lang="ts">
|
|
7835
8283
|
import PageSample from "{{ createImport 'lib' 'pageSamples/404.vue' }}";
|
|
7836
8284
|
<\/script>
|
|
7837
8285
|
|
|
7838
8286
|
<template>
|
|
7839
8287
|
<PageSample />
|
|
7840
8288
|
</template>
|
|
7841
|
-
`,
|
|
8289
|
+
`,Jr=`<template>
|
|
7842
8290
|
<router-view />
|
|
7843
8291
|
</template>
|
|
7844
|
-
`,
|
|
8292
|
+
`,Yr=`<script setup lang="ts">
|
|
7845
8293
|
import PageSample from "{{ createImport 'lib' 'pageSamples/page.vue' }}";
|
|
7846
8294
|
<\/script>
|
|
7847
8295
|
|
|
@@ -7856,19 +8304,23 @@ import PageSample from "{{ createImport 'lib' 'pageSamples/page.vue' }}";
|
|
|
7856
8304
|
}"
|
|
7857
8305
|
/>
|
|
7858
8306
|
</template>
|
|
7859
|
-
`,
|
|
8307
|
+
`,Xr=`<script setup lang="ts">
|
|
7860
8308
|
import WelcomePage from "{{ createImport 'lib' 'pageSamples/welcome.vue' }}";
|
|
7861
8309
|
<\/script>
|
|
7862
8310
|
|
|
7863
8311
|
<template>
|
|
7864
8312
|
<WelcomePage />
|
|
7865
8313
|
</template>
|
|
7866
|
-
`,
|
|
8314
|
+
`,Zr=`import routerFactory, { createRouters } from "{{ createImport 'lib' 'router' }}";
|
|
8315
|
+
import { appProvider } from "{{ createImport 'lib' 'app' }}";
|
|
7867
8316
|
|
|
7868
|
-
import app from "./
|
|
8317
|
+
import app from "./app.vue";
|
|
7869
8318
|
|
|
7870
8319
|
export default routerFactory((routes) => {
|
|
7871
|
-
const { clientRouter, serverRouter } = createRouters(routes, {
|
|
8320
|
+
const { clientRouter, serverRouter } = createRouters(routes, {
|
|
8321
|
+
app,
|
|
8322
|
+
use: [[appProvider, undefined]],
|
|
8323
|
+
});
|
|
7872
8324
|
return {
|
|
7873
8325
|
clientRouter() {
|
|
7874
8326
|
return clientRouter()
|
|
@@ -7878,5 +8330,5 @@ export default routerFactory((routes) => {
|
|
|
7878
8330
|
},
|
|
7879
8331
|
};
|
|
7880
8332
|
});
|
|
7881
|
-
`,
|
|
8333
|
+
`,Qr=f((e,t)=>{let{createPath:n,createImportHelpers:r}=h(e),{renderToFile:i}=_({helpers:{...r({origin:`lib`}),...b()},partials:{routePartial:jr}}),{renderToFile:a}=_({helpers:r({origin:`src`})}),o=Tr(),l=e=>!e?.trim().length,u=s(t?.templates,Yr),d=async e=>{for(let{kind:t,entry:r}of e)t===`pageRoute`?await a(n.pages(r.file),r.name===`index`?Xr:u(r.name,r),{route:r,message:Er()},{overwrite:l}):t===`pageLayout`&&await a(n.pages(r.file),Jr,{route:r},{overwrite:l})},f=async e=>{let t=e.flatMap(({kind:e,entry:t})=>e===`pageRoute`?[t]:[]).sort(v),r=e.flatMap(({kind:e,entry:t})=>e===`pageRoute`||e===`pageLayout`?[t]:[]),a=o(m(r));for(let[e,t]of[[`client.ts`,Ar],[`server.ts`,Mr]])await i(n.libEntry(e),t,{pageEntries:r,nestedRoutes:a,lazyLoad:e===`client.ts`});await i(n.lib(`router.ts`),zr,{entries:e,indexRoutes:t})};return{config(){let{templates:e,...n}={...t};return{plugins:[fe(n)]}},async start(){for(let[e,r]of[[`env.d.ts`,$],[`unwrap.ts`,Br],[`use.ts`,Vr],[`pageSamples/styles.module.css`,Fr],[`pageSamples/welcome.vue`,Ir],[`pageSamples/page.vue`,Pr],[`pageSamples/404.vue`,Nr],[`app/provider.vue`,kr],...t?.tanstack?.query?[[`app/index.ts`,Or],[`query.ts`,Lr]]:[[`app/index.ts`,Dr],[`query.ts`,`/** tanstack query disabled */`]]])await i(n.lib(e),r,{});for(let[e,t]of[[`pages/404.vue`,qr],[`components/Link.vue`,Ur],[`app.vue`,Hr],[`router.ts`,Zr]])await a(n.src(e),t,{entryDir:c.entryDir},{overwrite:l});await a(n.src(`index.html`),Kr,{entryDir:c.entryDir},{overwrite:e=>!e?.trim().length||!e.replace(/<!--[\s\S]*?-->/g,``).trim().length});for(let[e,t]of[[`client.ts`,Wr],[`server.ts`,Gr]])await a(n.entry(e),t,{},{overwrite:l})},async watch(e,t){(!t||t.kind===`create`)&&await d(e),await f(e)},async build(e){await d(e),await f(e)},async ssrBuild(){await i(n.lib(`query.ts`),t?.tanstack?.query?Rr:`/** tanstack query disabled */`,{ssrBundle:!0})}}}),$r=d({meta:{name:`Vue`,jsxImportSource:`vue`},dependencies(e){return{vue:Z.devDependencies.vue,"vue-router":Z.devDependencies[`vue-router`],"path-to-regexp":Z.devDependencies[`path-to-regexp`],...e?.tanstack?.query?{"@tanstack/vue-query":Z.devDependencies[`@tanstack/vue-query`]}:{}}},factory:Qr}),ei=t=>{let i=process.env.NODE_ENV||`development`,a=typeof t.base==`string`?t.base:t.base[i];if(!a?.trim())throw Error(n([`red`],`ERROR: Invalid Config - no base provided`));return{...t,base:e(`/`,a),apiBase:e(`/`,t.apiBase||r)}};export{ei as defineConfig,P as fetchGenerator,Ee as honoGenerator,Ke as koaGenerator,xt as mdxGenerator,Et as openapiGenerator,en as reactGenerator,kn as solidGenerator,Mn as ssgGenerator,Vn as ssrGenerator,hr as svelteGenerator,wr as typeboxGenerator,$r as vueGenerator};
|
|
7882
8334
|
//# sourceMappingURL=index.js.map
|