@humjs/core 0.0.0-stage → 0.0.2
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/README.md +5 -2
- package/dist/app.d.ts +40 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +230 -0
- package/dist/app.js.map +1 -0
- package/dist/build_cache.d.ts +56 -0
- package/dist/build_cache.d.ts.map +1 -0
- package/dist/build_cache.js +108 -0
- package/dist/build_cache.js.map +1 -0
- package/dist/config.d.ts +47 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +41 -0
- package/dist/config.js.map +1 -0
- package/dist/define.d.ts +44 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +15 -0
- package/dist/define.js.map +1 -0
- package/dist/discovery/fs_crawl.d.ts +19 -0
- package/dist/discovery/fs_crawl.d.ts.map +1 -0
- package/dist/discovery/fs_crawl.js +142 -0
- package/dist/discovery/fs_crawl.js.map +1 -0
- package/dist/discovery/mod.d.ts +2 -0
- package/dist/discovery/mod.d.ts.map +1 -0
- package/dist/discovery/mod.js +2 -0
- package/dist/discovery/mod.js.map +1 -0
- package/dist/error.d.ts +16 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +21 -0
- package/dist/error.js.map +1 -0
- package/dist/jsonify/constants.d.ts +13 -0
- package/dist/jsonify/constants.d.ts.map +1 -0
- package/dist/jsonify/constants.js +13 -0
- package/dist/jsonify/constants.js.map +1 -0
- package/dist/jsonify/parse.d.ts +8 -0
- package/dist/jsonify/parse.d.ts.map +1 -0
- package/dist/jsonify/parse.js +110 -0
- package/dist/jsonify/parse.js.map +1 -0
- package/dist/jsonify/stringify.d.ts +24 -0
- package/dist/jsonify/stringify.d.ts.map +1 -0
- package/dist/jsonify/stringify.js +167 -0
- package/dist/jsonify/stringify.js.map +1 -0
- package/dist/loader.d.ts +19 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +33 -0
- package/dist/loader.js.map +1 -0
- package/dist/mod.d.ts +19 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +16 -0
- package/dist/mod.js.map +1 -0
- package/dist/render.d.ts +31 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +162 -0
- package/dist/render.js.map +1 -0
- package/dist/request_context.d.ts +27 -0
- package/dist/request_context.d.ts.map +1 -0
- package/dist/request_context.js +39 -0
- package/dist/request_context.js.map +1 -0
- package/dist/resource.d.ts +25 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +78 -0
- package/dist/resource.js.map +1 -0
- package/dist/routing/fs_routes.d.ts +59 -0
- package/dist/routing/fs_routes.d.ts.map +1 -0
- package/dist/routing/fs_routes.js +146 -0
- package/dist/routing/fs_routes.js.map +1 -0
- package/dist/routing/mod.d.ts +3 -0
- package/dist/routing/mod.d.ts.map +1 -0
- package/dist/routing/mod.js +3 -0
- package/dist/routing/mod.js.map +1 -0
- package/dist/routing/path_to_pattern.d.ts +62 -0
- package/dist/routing/path_to_pattern.d.ts.map +1 -0
- package/dist/routing/path_to_pattern.js +283 -0
- package/dist/routing/path_to_pattern.js.map +1 -0
- package/dist/runtime/client/mod.d.ts +20 -0
- package/dist/runtime/client/mod.d.ts.map +1 -0
- package/dist/runtime/client/mod.js +18 -0
- package/dist/runtime/client/mod.js.map +1 -0
- package/dist/runtime/client/partials.d.ts +7 -0
- package/dist/runtime/client/partials.d.ts.map +1 -0
- package/dist/runtime/client/partials.js +337 -0
- package/dist/runtime/client/partials.js.map +1 -0
- package/dist/runtime/client/reviver.d.ts +104 -0
- package/dist/runtime/client/reviver.d.ts.map +1 -0
- package/dist/runtime/client/reviver.js +450 -0
- package/dist/runtime/client/reviver.js.map +1 -0
- package/dist/runtime/server/document.d.ts +50 -0
- package/dist/runtime/server/document.d.ts.map +1 -0
- package/dist/runtime/server/document.js +321 -0
- package/dist/runtime/server/document.js.map +1 -0
- package/dist/runtime/server/head.d.ts +31 -0
- package/dist/runtime/server/head.d.ts.map +1 -0
- package/dist/runtime/server/head.js +96 -0
- package/dist/runtime/server/head.js.map +1 -0
- package/dist/runtime/server/preact_hooks.d.ts +92 -0
- package/dist/runtime/server/preact_hooks.d.ts.map +1 -0
- package/dist/runtime/server/preact_hooks.js +341 -0
- package/dist/runtime/server/preact_hooks.js.map +1 -0
- package/dist/runtime/shared.d.ts +31 -0
- package/dist/runtime/shared.d.ts.map +1 -0
- package/dist/runtime/shared.js +31 -0
- package/dist/runtime/shared.js.map +1 -0
- package/dist/runtime/shared_internal.d.ts +91 -0
- package/dist/runtime/shared_internal.d.ts.map +1 -0
- package/dist/runtime/shared_internal.js +162 -0
- package/dist/runtime/shared_internal.js.map +1 -0
- package/dist/server/mod.d.ts +22 -0
- package/dist/server/mod.d.ts.map +1 -0
- package/dist/server/mod.js +28 -0
- package/dist/server/mod.js.map +1 -0
- package/dist/static.d.ts +12 -0
- package/dist/static.d.ts.map +1 -0
- package/dist/static.js +57 -0
- package/dist/static.js.map +1 -0
- package/dist/types.d.ts +159 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +46 -3
package/README.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @humjs/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Hum's core framework package for server-rendered Preact applications.
|
|
4
|
+
|
|
5
|
+
Documentation, source code, and issue tracking are available in the
|
|
6
|
+
[Hum repository](https://github.com/oaly2000/hum).
|
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Env, Hono, type Schema } from "hono";
|
|
2
|
+
import { BuildCache, type ProdManifest } from "./build_cache.js";
|
|
3
|
+
import { type HumConfig, type ResolvedConfig } from "./config.js";
|
|
4
|
+
import { ModuleLoader } from "./loader.js";
|
|
5
|
+
import { type ResolvedNotFound, type ResolvedRoute } from "./routing/fs_routes.js";
|
|
6
|
+
import type { HumManifest } from "./types.js";
|
|
7
|
+
export interface HumVariables {
|
|
8
|
+
/** The route Hum matched for this request. */
|
|
9
|
+
humRoute?: ResolvedRoute;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
export type HumApp = Hono<{
|
|
13
|
+
Variables: HumVariables;
|
|
14
|
+
}> & {
|
|
15
|
+
hum: HumInternals;
|
|
16
|
+
};
|
|
17
|
+
export type MountedHumApp<E extends Env, S extends Schema, P extends string> = Hono<E, S, P> & {
|
|
18
|
+
hum: HumInternals;
|
|
19
|
+
};
|
|
20
|
+
export interface HumInternals {
|
|
21
|
+
config: ResolvedConfig;
|
|
22
|
+
manifest: HumManifest;
|
|
23
|
+
prodManifest: ProdManifest | null;
|
|
24
|
+
buildCache: BuildCache;
|
|
25
|
+
loader: ModuleLoader;
|
|
26
|
+
routes: ResolvedRoute[];
|
|
27
|
+
notFound: ResolvedNotFound[];
|
|
28
|
+
/** Reloads island and route modules. No-op in production. */
|
|
29
|
+
refresh(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Mounts Hum's file routes, static assets, 404 handling, and runtime state onto
|
|
33
|
+
* an existing Hono application.
|
|
34
|
+
*
|
|
35
|
+
* Application middleware registered before this call also wraps Hum routes.
|
|
36
|
+
*/
|
|
37
|
+
export declare function mountHum<E extends Env, S extends Schema, P extends string>(app: Hono<E, S, P>, config: HumConfig): Promise<MountedHumApp<E, S, P>>;
|
|
38
|
+
/** Creates a standalone Hono app with Hum mounted on it. */
|
|
39
|
+
export declare function createApp(config: HumConfig): Promise<HumApp>;
|
|
40
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,GAAG,EAAE,IAAI,EAA0B,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC;AAG3E,OAAO,EACL,UAAU,EAEV,KAAK,YAAY,EAElB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E,CAAC,EAAE,CAAC,CAAC,EAClB,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAwGjC;AAED,4DAA4D;AAC5D,wBAAsB,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAGlE"}
|
package/dist/app.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { pathToFileURL } from "node:url";
|
|
2
|
+
import { Hono } from "hono";
|
|
3
|
+
import { BuildCache, manifestPath, readProdManifest, } from "./build_cache.js";
|
|
4
|
+
import { defaultLogger, resolveConfig, } from "./config.js";
|
|
5
|
+
import { crawlProject } from "./discovery/fs_crawl.js";
|
|
6
|
+
import { ModuleLoader } from "./loader.js";
|
|
7
|
+
import { runWithRequestContext, } from "./request_context.js";
|
|
8
|
+
import { findNotFound, renderError, renderNotFound, renderRoute, } from "./render.js";
|
|
9
|
+
import { dirOf, resolveRoutes, unmatchedRoute, } from "./routing/fs_routes.js";
|
|
10
|
+
import { staticAssetHandler } from "./static.js";
|
|
11
|
+
function htmlResponse(c, outcome) {
|
|
12
|
+
if (outcome.links.length > 0) {
|
|
13
|
+
c.header("Link", outcome.links.map((url) => `<${url}>; rel=modulepreload`).join(", "));
|
|
14
|
+
}
|
|
15
|
+
if (typeof outcome.body === "string") {
|
|
16
|
+
return c.html(outcome.body, outcome.status);
|
|
17
|
+
}
|
|
18
|
+
return c.body(outcome.body, outcome.status, { "Content-Type": "text/html; charset=UTF-8" });
|
|
19
|
+
}
|
|
20
|
+
function pickHandler(handlers, method) {
|
|
21
|
+
if (handlers === undefined)
|
|
22
|
+
return undefined;
|
|
23
|
+
if (method === "HEAD" && handlers.HEAD === undefined) {
|
|
24
|
+
return handlers.GET;
|
|
25
|
+
}
|
|
26
|
+
const byMethod = handlers;
|
|
27
|
+
return byMethod[method];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Runs the middleware a route module exports. Mirrors Hono's semantics:
|
|
31
|
+
* returning a `Response` short circuits, and a middleware that never calls
|
|
32
|
+
* `next()` continues the chain so that simple middlewares stay ergonomic.
|
|
33
|
+
*/
|
|
34
|
+
async function runRouteMiddleware(list, c, terminal) {
|
|
35
|
+
const dispatch = async (index) => {
|
|
36
|
+
if (index >= list.length)
|
|
37
|
+
return await terminal();
|
|
38
|
+
const fn = list[index];
|
|
39
|
+
let downstream;
|
|
40
|
+
let called = false;
|
|
41
|
+
const next = async () => {
|
|
42
|
+
if (called)
|
|
43
|
+
throw new Error("next() called multiple times");
|
|
44
|
+
called = true;
|
|
45
|
+
downstream = await dispatch(index + 1);
|
|
46
|
+
};
|
|
47
|
+
const result = await fn(c, next);
|
|
48
|
+
if (result instanceof Response) {
|
|
49
|
+
c.res = result;
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
if (called && downstream !== undefined)
|
|
53
|
+
return downstream;
|
|
54
|
+
return await dispatch(index + 1);
|
|
55
|
+
};
|
|
56
|
+
return await dispatch(0);
|
|
57
|
+
}
|
|
58
|
+
function middlewareArray(middleware) {
|
|
59
|
+
if (middleware === undefined)
|
|
60
|
+
return [];
|
|
61
|
+
return Array.isArray(middleware) ? middleware : [middleware];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Mounts Hum's file routes, static assets, 404 handling, and runtime state onto
|
|
65
|
+
* an existing Hono application.
|
|
66
|
+
*
|
|
67
|
+
* Application middleware registered before this call also wraps Hum routes.
|
|
68
|
+
*/
|
|
69
|
+
export async function mountHum(app, config) {
|
|
70
|
+
const manifest = config.manifest ??
|
|
71
|
+
await crawlToManifest(config);
|
|
72
|
+
const root = config.root ?? process.cwd();
|
|
73
|
+
const outDir = config.outDir ?? "_hum";
|
|
74
|
+
const prodManifest = await readProdManifest(manifestPath(root, outDir));
|
|
75
|
+
const dev = config.dev ?? prodManifest === null;
|
|
76
|
+
const resolved = resolveConfig({
|
|
77
|
+
...config,
|
|
78
|
+
dev,
|
|
79
|
+
// The manifest knows the URL the build is served from, which is what keeps
|
|
80
|
+
// the client asset URLs stable when the output directory is renamed.
|
|
81
|
+
assetsBase: config.assetsBase ?? prodManifest?.assetsBase,
|
|
82
|
+
}, manifest);
|
|
83
|
+
const buildCache = new BuildCache(dev);
|
|
84
|
+
await buildCache.load(manifest, prodManifest, resolved.logger);
|
|
85
|
+
const { routes, notFound } = resolveRoutes(manifest.routes, resolved.routesDir);
|
|
86
|
+
const loader = new ModuleLoader(dev);
|
|
87
|
+
if (!resolved.dev && prodManifest === null) {
|
|
88
|
+
resolved.logger.error(`hum: no build manifest found at ${manifestPath(root, outDir)}. ` +
|
|
89
|
+
`Client islands and styles cannot be served; run the production ` +
|
|
90
|
+
`build, or point \`outDir\` at the deployed output directory.`);
|
|
91
|
+
}
|
|
92
|
+
// Serve the production build output. In dev Vite handles these requests
|
|
93
|
+
// before the Hum handler, so this branch stays inert.
|
|
94
|
+
app.use(`${resolved.assetsBase}/*`, staticAssetHandler(resolved));
|
|
95
|
+
const internals = {
|
|
96
|
+
config: resolved,
|
|
97
|
+
manifest,
|
|
98
|
+
prodManifest,
|
|
99
|
+
buildCache,
|
|
100
|
+
loader,
|
|
101
|
+
routes,
|
|
102
|
+
notFound,
|
|
103
|
+
async refresh() {
|
|
104
|
+
if (!resolved.dev)
|
|
105
|
+
return;
|
|
106
|
+
await buildCache.load(manifest, prodManifest, resolved.logger);
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
// Hono's variadic `HandlerInterface` overloads cannot be satisfied by a
|
|
110
|
+
// dynamically built middleware chain, so registration goes through a
|
|
111
|
+
// narrow, explicitly typed funnel. The handlers themselves stay typed.
|
|
112
|
+
const register = app.all.bind(app);
|
|
113
|
+
for (const route of routes) {
|
|
114
|
+
const chain = routeHandler(route, internals, notFound);
|
|
115
|
+
for (const pattern of route.honoPatterns) {
|
|
116
|
+
register(pattern, chain);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
app.notFound(async (c) => {
|
|
120
|
+
const url = new URL(c.req.url);
|
|
121
|
+
const found = findNotFound(notFound, url.pathname);
|
|
122
|
+
const dir = found === undefined
|
|
123
|
+
? ""
|
|
124
|
+
: dirOf(found.file.file, resolved.routesDir);
|
|
125
|
+
const input = {
|
|
126
|
+
config: resolved,
|
|
127
|
+
buildCache,
|
|
128
|
+
loader,
|
|
129
|
+
route: unmatchedRoute(manifest.routes, resolved.routesDir, dir, url.pathname),
|
|
130
|
+
url,
|
|
131
|
+
params: {},
|
|
132
|
+
state: c.var,
|
|
133
|
+
notFound,
|
|
134
|
+
};
|
|
135
|
+
try {
|
|
136
|
+
await internals.refresh();
|
|
137
|
+
return htmlResponse(c, await renderNotFound(input, url.pathname));
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
return htmlResponse(c, await renderError(input, err));
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return Object.assign(app, { hum: internals });
|
|
144
|
+
}
|
|
145
|
+
/** Creates a standalone Hono app with Hum mounted on it. */
|
|
146
|
+
export async function createApp(config) {
|
|
147
|
+
const app = new Hono();
|
|
148
|
+
return await mountHum(app, config);
|
|
149
|
+
}
|
|
150
|
+
function routeHandler(route, internals, notFound) {
|
|
151
|
+
return async (c) => {
|
|
152
|
+
const url = new URL(c.req.url);
|
|
153
|
+
const method = c.req.method.toUpperCase();
|
|
154
|
+
const params = c.req.param();
|
|
155
|
+
const context = c;
|
|
156
|
+
context.set("humRoute", route);
|
|
157
|
+
const input = {
|
|
158
|
+
config: internals.config,
|
|
159
|
+
buildCache: internals.buildCache,
|
|
160
|
+
loader: internals.loader,
|
|
161
|
+
route,
|
|
162
|
+
url,
|
|
163
|
+
params,
|
|
164
|
+
state: c.var,
|
|
165
|
+
notFound,
|
|
166
|
+
};
|
|
167
|
+
try {
|
|
168
|
+
await internals.refresh();
|
|
169
|
+
const mod = (await internals.loader.load(route.file));
|
|
170
|
+
const routeMiddleware = [];
|
|
171
|
+
for (const spec of route.middlewares) {
|
|
172
|
+
const middlewareModule = await internals.loader.load(spec);
|
|
173
|
+
const middleware = (middlewareModule.default ??
|
|
174
|
+
middlewareModule.middleware);
|
|
175
|
+
if (typeof middleware !== "function") {
|
|
176
|
+
internals.config.logger.warn(`hum: ${spec.file} does not export a middleware as its default ` +
|
|
177
|
+
`export. Skipping it.`);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
routeMiddleware.push(middleware);
|
|
181
|
+
}
|
|
182
|
+
routeMiddleware.push(...middlewareArray(mod.middleware));
|
|
183
|
+
const terminal = async () => {
|
|
184
|
+
const handler = pickHandler(mod.handlers, method);
|
|
185
|
+
if (handler !== undefined) {
|
|
186
|
+
const requestContext = {
|
|
187
|
+
page: async (data, options) => htmlResponse(context, await renderRoute(input, data, options)),
|
|
188
|
+
};
|
|
189
|
+
const res = await runWithRequestContext(requestContext, () => handler(context));
|
|
190
|
+
if (res instanceof Response)
|
|
191
|
+
return res;
|
|
192
|
+
}
|
|
193
|
+
else if (mod.handlers !== undefined && method !== "GET" && method !== "HEAD") {
|
|
194
|
+
return context.text("Method Not Allowed", 405);
|
|
195
|
+
}
|
|
196
|
+
return htmlResponse(context, await renderRoute(input));
|
|
197
|
+
};
|
|
198
|
+
return await runRouteMiddleware(routeMiddleware, context, terminal);
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
if (route.error === undefined) {
|
|
202
|
+
internals.config.logger.error(`hum: unhandled error while handling ${context.req.method} ${url.pathname}`, err);
|
|
203
|
+
}
|
|
204
|
+
return htmlResponse(context, await renderError(input, err));
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/** Fallback discovery used when the bundler did not supply a manifest. */
|
|
209
|
+
async function crawlToManifest(config) {
|
|
210
|
+
const root = config.root ?? process.cwd();
|
|
211
|
+
const crawled = await crawlProject({
|
|
212
|
+
root,
|
|
213
|
+
routesDir: config.routesDir,
|
|
214
|
+
islandsDir: config.islandsDir,
|
|
215
|
+
logger: config.logger,
|
|
216
|
+
});
|
|
217
|
+
return {
|
|
218
|
+
routes: crawled.routes.map((spec) => ({
|
|
219
|
+
...spec,
|
|
220
|
+
// The path is only known at runtime; Vite must not try to resolve it.
|
|
221
|
+
load: () => import(/* @vite-ignore */ pathToFileURL(spec.absPath).href),
|
|
222
|
+
})),
|
|
223
|
+
islands: crawled.islands.map((spec) => ({
|
|
224
|
+
...spec,
|
|
225
|
+
// The path is only known at runtime; Vite must not try to resolve it.
|
|
226
|
+
load: () => import(/* @vite-ignore */ pathToFileURL(spec.absPath).href),
|
|
227
|
+
})),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=app.js.map
|
package/dist/app.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAY,IAAI,EAAuC,MAAM,MAAM,CAAC;AAG3E,OAAO,EACL,UAAU,EACV,YAAY,EAEZ,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,aAAa,EAEb,aAAa,GAEd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAEL,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,YAAY,EACZ,WAAW,EACX,cAAc,EAEd,WAAW,GAEZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,EAGL,aAAa,EACb,cAAc,GACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAgCjD,SAAS,YAAY,CACnB,CAAa,EACb,OAAsB;IAEtB,IAAI,OAAO,CAAC,KAAK,CA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IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAEzD;SACJ,CAAC,CAAC;QACH,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACtC,GAAG,IAAI;YACP,sEAAsE;YACtE,IAAI,EAAE,GAAG,EAAE,CACT,MAAM,CAAC,kBAAkB,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAEzD;SACJ,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { HumManifest, Island, Logger } from "./types.js";
|
|
2
|
+
/** URL the dev server serves the client runtime from. */
|
|
3
|
+
export declare const CLIENT_ENTRY_DEV = "/_hum/runtime.js";
|
|
4
|
+
/** Name of the manifest the production build writes into the out dir. */
|
|
5
|
+
export declare const MANIFEST_FILE = "manifest.json";
|
|
6
|
+
export interface ProdIslandEntry {
|
|
7
|
+
/** Island chunk path, relative to the output directory. */
|
|
8
|
+
file: string;
|
|
9
|
+
/** Island stylesheet paths, relative to the output directory. */
|
|
10
|
+
css?: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface ProdManifest {
|
|
13
|
+
buildId: string;
|
|
14
|
+
/**
|
|
15
|
+
* URL the output directory is served from, e.g. `/_hum`. The assets are
|
|
16
|
+
* addressed through it, while the directory itself is located next to the
|
|
17
|
+
* server bundle, so the built app keeps working when the output directory is
|
|
18
|
+
* renamed or moved on the deploy machine.
|
|
19
|
+
*/
|
|
20
|
+
assetsBase: string;
|
|
21
|
+
/** Client runtime chunk path, relative to the output directory. */
|
|
22
|
+
clientEntry: string;
|
|
23
|
+
islands: Record<string, ProdIslandEntry>;
|
|
24
|
+
/** Client entry stylesheet paths, relative to the output directory. */
|
|
25
|
+
entryAssets?: string[];
|
|
26
|
+
}
|
|
27
|
+
export declare function manifestPath(root: string, outDir: string): string;
|
|
28
|
+
/** Reads the production manifest, or `null` when the app runs in dev. */
|
|
29
|
+
export declare function readProdManifest(path: string): Promise<ProdManifest | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Maps island components to their client side module URLs, and keeps the
|
|
32
|
+
* bookkeeping the renderer needs (`islandRegistry`, entry assets, build id).
|
|
33
|
+
*
|
|
34
|
+
* Island modules are loaded through the bundler supplied thunks, so the same
|
|
35
|
+
* cache implementation works for the Vite dev module runner and for the
|
|
36
|
+
* bundled production output.
|
|
37
|
+
*/
|
|
38
|
+
export declare class BuildCache {
|
|
39
|
+
#private;
|
|
40
|
+
/** Islands by name. */
|
|
41
|
+
readonly islands: Map<string, Island>;
|
|
42
|
+
/** Islands by component reference, used to detect islands while rendering. */
|
|
43
|
+
readonly islandRegistry: Map<unknown, Island>;
|
|
44
|
+
/** URL of the client runtime entry, imported by the boot script. */
|
|
45
|
+
clientEntry: string;
|
|
46
|
+
/** Stylesheets that belong to the client entry itself. */
|
|
47
|
+
entryAssets: string[];
|
|
48
|
+
buildId: string;
|
|
49
|
+
readonly dev: boolean;
|
|
50
|
+
constructor(dev: boolean);
|
|
51
|
+
/** Loads every island module and (re)builds the registries. */
|
|
52
|
+
load(manifest: HumManifest, prod: ProdManifest | null, logger?: Logger): Promise<void>;
|
|
53
|
+
getIsland(name: string): Island | undefined;
|
|
54
|
+
get prodManifest(): ProdManifest | null;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=build_cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build_cache.d.ts","sourceRoot":"","sources":["../src/build_cache.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAE9D,yDAAyD;AACzD,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,yEAAyE;AACzE,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAE7C,MAAM,WAAW,eAAe;IAC9B,2DAA2D;IAC3D,IAAI,EAAE,M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
|
+
import { setBuildId } from "./runtime/shared_internal.js";
|
|
4
|
+
/** URL the dev server serves the client runtime from. */
|
|
5
|
+
export const CLIENT_ENTRY_DEV = "/_hum/runtime.js";
|
|
6
|
+
/** Name of the manifest the production build writes into the out dir. */
|
|
7
|
+
export const MANIFEST_FILE = "manifest.json";
|
|
8
|
+
export function manifestPath(root, outDir) {
|
|
9
|
+
return join(root, outDir, MANIFEST_FILE);
|
|
10
|
+
}
|
|
11
|
+
/** Reads the production manifest, or `null` when the app runs in dev. */
|
|
12
|
+
export async function readProdManifest(path) {
|
|
13
|
+
try {
|
|
14
|
+
const raw = await readFile(path, "utf8");
|
|
15
|
+
return JSON.parse(raw);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Maps island components to their client side module URLs, and keeps the
|
|
23
|
+
* bookkeeping the renderer needs (`islandRegistry`, entry assets, build id).
|
|
24
|
+
*
|
|
25
|
+
* Island modules are loaded through the bundler supplied thunks, so the same
|
|
26
|
+
* cache implementation works for the Vite dev module runner and for the
|
|
27
|
+
* bundled production output.
|
|
28
|
+
*/
|
|
29
|
+
export class BuildCache {
|
|
30
|
+
/** Islands by name. */
|
|
31
|
+
islands = new Map();
|
|
32
|
+
/** Islands by component reference, used to detect islands while rendering. */
|
|
33
|
+
islandRegistry = new Map();
|
|
34
|
+
/** URL of the client runtime entry, imported by the boot script. */
|
|
35
|
+
clientEntry;
|
|
36
|
+
/** Stylesheets that belong to the client entry itself. */
|
|
37
|
+
entryAssets = [];
|
|
38
|
+
buildId = "dev";
|
|
39
|
+
dev;
|
|
40
|
+
#prod = null;
|
|
41
|
+
/** URL prefix the production output directory is served from. */
|
|
42
|
+
#assetsBase = "";
|
|
43
|
+
constructor(dev) {
|
|
44
|
+
this.dev = dev;
|
|
45
|
+
this.clientEntry = dev ? CLIENT_ENTRY_DEV : "";
|
|
46
|
+
}
|
|
47
|
+
/** Loads every island module and (re)builds the registries. */
|
|
48
|
+
async load(manifest, prod, logger) {
|
|
49
|
+
this.#prod = prod;
|
|
50
|
+
this.islands.clear();
|
|
51
|
+
this.islandRegistry.clear();
|
|
52
|
+
this.#assetsBase = this.dev || prod === null
|
|
53
|
+
? ""
|
|
54
|
+
: (prod.assetsBase ?? "").replace(/\/+$/, "");
|
|
55
|
+
for (const spec of manifest.islands) {
|
|
56
|
+
let component;
|
|
57
|
+
try {
|
|
58
|
+
const mod = await spec.load();
|
|
59
|
+
component = mod[spec.exportName];
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
logger?.error(`hum: failed to load island "${spec.name}" from ${spec.file}:`, err);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (component === undefined) {
|
|
66
|
+
logger?.warn(`hum: island "${spec.name}" (${spec.file}) has no ` +
|
|
67
|
+
`"${spec.exportName}" export. Add a default export to make it ` +
|
|
68
|
+
`interactive.`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
// In dev the modules are served straight from Vite, so a leftover
|
|
72
|
+
// production manifest must never win over the dev URLs.
|
|
73
|
+
const prodInfo = this.dev ? undefined : prod?.islands[spec.name];
|
|
74
|
+
const island = {
|
|
75
|
+
name: spec.name,
|
|
76
|
+
exportName: spec.exportName,
|
|
77
|
+
file: spec.file,
|
|
78
|
+
clientUrl: prodInfo === undefined
|
|
79
|
+
? `/${spec.file}`
|
|
80
|
+
: this.#assetUrl(prodInfo.file),
|
|
81
|
+
css: (prodInfo?.css ?? []).map((css) => this.#assetUrl(css)),
|
|
82
|
+
};
|
|
83
|
+
this.islands.set(island.name, island);
|
|
84
|
+
this.islandRegistry.set(component, island);
|
|
85
|
+
}
|
|
86
|
+
if (!this.dev && prod !== null) {
|
|
87
|
+
this.clientEntry = this.#assetUrl(prod.clientEntry);
|
|
88
|
+
this.entryAssets = (prod.entryAssets ?? []).map((asset) => this.#assetUrl(asset));
|
|
89
|
+
this.buildId = prod.buildId;
|
|
90
|
+
setBuildId(prod.buildId);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Turns a path relative to the output directory into a public URL. */
|
|
94
|
+
#assetUrl(file) {
|
|
95
|
+
// Manifests written by an older plugin stored absolute URLs; keep those
|
|
96
|
+
// working instead of prefixing them a second time.
|
|
97
|
+
if (file.startsWith("/"))
|
|
98
|
+
return file;
|
|
99
|
+
return `${this.#assetsBase}/${file}`;
|
|
100
|
+
}
|
|
101
|
+
getIsland(name) {
|
|
102
|
+
return this.islands.get(name);
|
|
103
|
+
}
|
|
104
|
+
get prodManifest() {
|
|
105
|
+
return this.#prod;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=build_cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build_cache.js","sourceRoot":"","sources":["../src/build_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAG1D,yDAAyD;AACzD,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAEnD,yEAAyE;AACzE,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC;AAyB7C,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,MAAc;IACvD,OAAO,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;AAC3C,CAAC;AAED,yEAAyE;AACzE,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAAY;IAEZ,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAiB,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,OA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CAAC;YAC/B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACpD,IAAI,CAAC,WAAW,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACxD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CACtB,CAAC;YACF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;YAC5B,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,uEAAuE;IACvE,SAAS,CAAC,IAAY;QACpB,wEAAwE;QACxE,mDAAmD;QACnD,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QACtC,OAAO,GAAG,IAAI,CAAC,WAAW,IAAI,IAAI,EAAE,CAAC;IACvC,CAAC;IAED,SAAS,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { HumManifest, Logger } from "./types.js";
|
|
2
|
+
export interface HumConfig {
|
|
3
|
+
/**
|
|
4
|
+
* Project root. Defaults to `process.cwd()`.
|
|
5
|
+
*/
|
|
6
|
+
root?: string;
|
|
7
|
+
/** Routes directory, relative to the root. Defaults to `routes`. */
|
|
8
|
+
routesDir?: string;
|
|
9
|
+
/** Islands directory, relative to the root. Defaults to `islands`. */
|
|
10
|
+
islandsDir?: string;
|
|
11
|
+
/** Output directory of the production build. Defaults to `_hum`. */
|
|
12
|
+
outDir?: string;
|
|
13
|
+
/**
|
|
14
|
+
* URL the production build output is served from. The build manifest carries
|
|
15
|
+
* it, so it is normally read from there; the fallback is `/<outDir>`.
|
|
16
|
+
*/
|
|
17
|
+
assetsBase?: string;
|
|
18
|
+
/** Base path the app is served from. Defaults to `/`. */
|
|
19
|
+
basePath?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Run in development mode: modules are re-imported per request so edits show
|
|
22
|
+
* up without a restart, and islands are served straight from Vite.
|
|
23
|
+
* Defaults to `true` when no production manifest exists.
|
|
24
|
+
*/
|
|
25
|
+
dev?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Route and island modules generated by the bundler. The Vite plugin
|
|
28
|
+
* generates this; when omitted, Hum discovers the files on disk (useful for
|
|
29
|
+
* tests and programmatic use).
|
|
30
|
+
*/
|
|
31
|
+
manifest?: HumManifest;
|
|
32
|
+
logger?: Logger;
|
|
33
|
+
}
|
|
34
|
+
export interface ResolvedConfig {
|
|
35
|
+
root: string;
|
|
36
|
+
routesDir: string;
|
|
37
|
+
islandsDir: string;
|
|
38
|
+
outDir: string;
|
|
39
|
+
assetsBase: string;
|
|
40
|
+
basePath: string;
|
|
41
|
+
dev: boolean;
|
|
42
|
+
manifest: HumManifest;
|
|
43
|
+
logger: Logger;
|
|
44
|
+
}
|
|
45
|
+
export declare const defaultLogger: Logger;
|
|
46
|
+
export declare function resolveConfig(config: HumConfig, manifest: HumManifest): ResolvedConfig;
|
|
47
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEtD,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sEAAsE;IACtE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;;;OAIG;IACH,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,WAAW,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,aAAa,EAAE,MAO3B,CAAC;AAYF,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,GAAG,cAAc,CAqBtF"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
export const defaultLogger = {
|
|
3
|
+
info: (...args) => console.log("hum:", ...args),
|
|
4
|
+
warn: (...args) => console.warn("hum:", ...args),
|
|
5
|
+
error: (...args) => console.error("hum:", ...args),
|
|
6
|
+
debug: (...args) => {
|
|
7
|
+
if (process.env.HUM_DEBUG)
|
|
8
|
+
console.log("hum:", ...args);
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Normalizes an absolute URL prefix: it always starts with `/` and never ends
|
|
13
|
+
* with one, so callers can append `/<path>` unconditionally.
|
|
14
|
+
*/
|
|
15
|
+
function normalizeAssetsBase(value) {
|
|
16
|
+
const trimmed = value.trim().replace(/\\/g, "/");
|
|
17
|
+
const withLeadingSlash = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
18
|
+
return withLeadingSlash.replace(/\/+$/, "");
|
|
19
|
+
}
|
|
20
|
+
export function resolveConfig(config, manifest) {
|
|
21
|
+
const root = resolve(config.root ?? process.cwd());
|
|
22
|
+
let basePath = config.basePath ?? "/";
|
|
23
|
+
if (basePath !== "/" && basePath.endsWith("/")) {
|
|
24
|
+
basePath = basePath.slice(0, -1);
|
|
25
|
+
}
|
|
26
|
+
if (basePath === "/")
|
|
27
|
+
basePath = "";
|
|
28
|
+
const outDir = config.outDir ?? "_hum";
|
|
29
|
+
return {
|
|
30
|
+
root,
|
|
31
|
+
routesDir: config.routesDir ?? "routes",
|
|
32
|
+
islandsDir: config.islandsDir ?? "islands",
|
|
33
|
+
outDir,
|
|
34
|
+
assetsBase: normalizeAssetsBase(config.assetsBase ?? `/${outDir}`),
|
|
35
|
+
basePath,
|
|
36
|
+
dev: config.dev ?? true,
|
|
37
|
+
manifest,
|
|
38
|
+
logger: config.logger ?? defaultLogger,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAiDpC,MAAM,CAAC,MAAM,aAAa,GAAW;IACnC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAC/C,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAChD,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAClD,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,E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ACR,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI,IAAI;QACvB,QAAQ;QACR,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,aAAa;KACvC,CAAC;AACJ,CAAC"}
|
package/dist/define.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ComponentType } from "preact";
|
|
2
|
+
import type { AppModule, ErrorModule, Handlers, HeadExport, HumMiddleware, LayoutModule, PageViewProps, RouteConfig, RouteModule, RouteProps } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Type helpers for route modules. They add no runtime behaviour, they only
|
|
5
|
+
* make the exports of a route file type checked:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { define, page } from "@humjs/core";
|
|
9
|
+
*
|
|
10
|
+
* export const handlers = define.handlers({
|
|
11
|
+
* GET: async (c) => page({ post: await load(c.req.param("id")) }),
|
|
12
|
+
* POST: async (c) => c.redirect("/thanks"),
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* export default define.page<{ post: Post }>(({ data }) => (
|
|
16
|
+
* <h1>{data.post.title}</h1>
|
|
17
|
+
* ));
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* `define.page<Data>()` types a route's view. The handler passes business data
|
|
21
|
+
* with `page(data)`, and the view receives it under `data`.
|
|
22
|
+
*
|
|
23
|
+
* Use `define.head()` for static or route-aware head content, and
|
|
24
|
+
* `define.config()` for route rendering options:
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* export const head = define.head(({ params }) => <title>Post {params.id}</title>);
|
|
28
|
+
* export const config = define.config({ skipInheritedLayouts: true });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export interface Define<State = Record<string, unknown>> {
|
|
32
|
+
route(module: RouteModule<State>): RouteModule<State>;
|
|
33
|
+
head(head: HeadExport<State>): HeadExport<State>;
|
|
34
|
+
config(config: RouteConfig): RouteConfig;
|
|
35
|
+
page<Data>(component: ComponentType<RouteProps<State> & PageViewProps<Data>>): ComponentType<RouteProps<State> & PageViewProps<Data>>;
|
|
36
|
+
app(module: AppModule<State>): AppModule<State>;
|
|
37
|
+
layout(module: LayoutModule<State>): LayoutModule<State>;
|
|
38
|
+
error(module: ErrorModule<State>): ErrorModule<State>;
|
|
39
|
+
handlers(handlers: Handlers): Handlers;
|
|
40
|
+
middleware(middleware: HumMiddleware | HumMiddleware[]): HumMiddleware | HumMiddleware[];
|
|
41
|
+
}
|
|
42
|
+
export declare function createDefine<State = Record<string, unknown>>(): Define<State>;
|
|
43
|
+
export declare const define: Define<Record<string, unknown>>;
|
|
44
|
+
//# sourceMappingURL=define.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,QAAQ,EACR,UAAU,EACV,aAAa,EACb,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,WAAW,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACrD,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IACtD,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IACjD,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAAC;IACzC,IAAI,CAAC,IAAI,EACP,SAAS,EAAE,aAAa,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,GAChE,aAAa,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1D,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAChD,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACzD,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IACtD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAC;IACvC,UAAU,CACR,UAAU,EAAE,aAAa,GAAG,aAAa,EAAE,GAC1C,aAAa,GAAG,aAAa,EAAE,CAAC;CACpC;AAED,wBAAgB,YAAY,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,KAAK,CAAC,CAY7E;AAED,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAkB,CAAC"}
|
package/dist/define.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function createDefine() {
|
|
2
|
+
return {
|
|
3
|
+
route: (module) => module,
|
|
4
|
+
head: (head) => head,
|
|
5
|
+
config: (config) => config,
|
|
6
|
+
page: (component) => component,
|
|
7
|
+
app: (module) => module,
|
|
8
|
+
layout: (module) => module,
|
|
9
|
+
error: (module) => module,
|
|
10
|
+
handlers: (handlers) => handlers,
|
|
11
|
+
middleware: (middleware) => middleware,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export const define = createDefine();
|
|
15
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AA2DA,MAAM,UAAU,YAAY;IAC1B,OAAO;QACL,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;QACzB,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI;QACpB,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;QAC1B,IAAI,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS;QAC9B,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;QACvB,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;QAC1B,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;QACzB,QAAQ,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ;QAChC,UAAU,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU;KACvC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAoC,YAAY,EAAE,CAAC"}
|