noofpi 1.1.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +20 -4
  2. package/dist/{build-GGRF4JTM.js → build-PFCGDPPJ.js} +5 -4
  3. package/dist/chunk-3PSMWWUB.js +68 -0
  4. package/dist/{chunk-NALDZ3PS.js → chunk-I6TFIGFO.js} +13 -5
  5. package/dist/{chunk-NX6BO7UB.js → chunk-IE3WF5XF.js} +82 -2
  6. package/dist/{chunk-M7TMNIVH.js → chunk-LL3NO5EI.js} +367 -133
  7. package/dist/{chunk-FIJJ3EGL.js → chunk-MN5PVHC5.js} +4 -0
  8. package/dist/chunk-OKNF6XDO.js +14 -0
  9. package/dist/chunk-PPUFFGCH.js +168 -0
  10. package/dist/{chunk-WX2V6EYH.js → chunk-RUNIVVFH.js} +34 -10
  11. package/dist/{chunk-2XCZWFIQ.js → chunk-X3DYEZLK.js} +1 -1
  12. package/dist/{chunk-4YOOGEOF.js → chunk-YJVMBHNL.js} +1 -1
  13. package/dist/cli.js +130 -34
  14. package/dist/{dev-Y5IW7464.js → dev-HTWUY27O.js} +47 -59
  15. package/dist/devtools-PLUN2DYV.js +958 -0
  16. package/dist/handler-C6NnwBfC.d.ts +17 -0
  17. package/dist/index.d.ts +21 -1
  18. package/dist/index.js +2 -2
  19. package/dist/{validation-ClXd_DAW.d.ts → payload-CL6tYBin.d.ts} +2 -40
  20. package/dist/prepare-KKQ2AEBW.js +24 -0
  21. package/dist/runtime/default-app.d.ts +6 -0
  22. package/dist/runtime/entry-client.d.ts +3 -0
  23. package/dist/runtime/entry-client.js +12 -4
  24. package/dist/runtime/entry-server.d.ts +8 -0
  25. package/dist/runtime/entry-server.js +2 -2
  26. package/dist/runtime/index.d.ts +55 -18
  27. package/dist/runtime/index.js +2 -2
  28. package/dist/runtime/routes.d.ts +13 -0
  29. package/dist/runtime/silent-diagnostics.d.ts +5 -0
  30. package/dist/server/bun.d.ts +15 -0
  31. package/dist/server/bun.js +14 -11
  32. package/dist/server/index.d.ts +9 -90
  33. package/dist/server/index.js +2 -2
  34. package/dist/server/node.d.ts +20 -0
  35. package/dist/server/node.js +2 -2
  36. package/dist/{start-IK3X6V3N.js → start-AJKNZRJQ.js} +11 -7
  37. package/dist/typecheck-QACZZ6FN.js +30 -0
  38. package/dist/types-B6rQOOxS.d.ts +76 -0
  39. package/dist/validation-Dwpex2JZ.d.ts +40 -0
  40. package/package.json +22 -6
  41. package/dist/chunk-KGZP2RCF.js +0 -51
  42. package/dist/devtools-KTDSD5PR.js +0 -564
@@ -0,0 +1,17 @@
1
+ import { e as ServerModule } from './types-B6rQOOxS.js';
2
+
3
+ interface HandlerOptions {
4
+ /** Returns the generated server module (`virtual:noofpi/server`, or the built bundle in production) */
5
+ load: () => Promise<ServerModule>;
6
+ /** Returns the HTML shell for a page URL */
7
+ getTemplate: (url: string) => Promise<string>;
8
+ onError?: (error: unknown) => void;
9
+ }
10
+ type Handler = (request: Request, env?: unknown) => Promise<Response>;
11
+ /**: one web-standard `fetch(Request) -> Response` handler.
12
+ * Order: proxy (pfetch) -> local doofpi API -> HTML (SSR render or SPA shell).
13
+ */
14
+ declare function createHandler(options: HandlerOptions): Handler;
15
+
16
+ export { createHandler as c };
17
+ export type { Handler as H, HandlerOptions as a };
package/dist/index.d.ts CHANGED
@@ -67,6 +67,17 @@ interface FontsConfig {
67
67
  families: FontFamily[];
68
68
  }
69
69
 
70
+ interface SeoConfig {
71
+ /** Public URL of the site (`https://example.com`, or with a path for project sites). Needed for the sitemap, whose URLs are absolute */
72
+ siteUrl?: string;
73
+ /** Generate `sitemap.xml` from the static pages (those without params) at build time. Default: `true` when `siteUrl` is set, otherwise off. `false` disables it */
74
+ sitemap?: boolean;
75
+ /** Generate `robots.txt` at build time (pointing to the sitemap, if any). Default: `true`. `false` disables it */
76
+ robots?: boolean;
77
+ /** Page patterns (`/admin/**`, `/users/*`, `/about`, like `routeRules`) left out of the sitemap and disallowed in `robots.txt` */
78
+ exclude?: string[];
79
+ }
80
+
70
81
  interface NoofpiConfig {
71
82
  /** Render pages on the server (`true`, default) or ship a client-only SPA (`false`) */
72
83
  ssr?: boolean;
@@ -88,6 +99,8 @@ interface NoofpiConfig {
88
99
  security?: SecurityConfig;
89
100
  /** Built-in i18n: `t()` with typed message keys from `app/locales/<locale>.ts`, locale detection (cookie, `Accept-Language`) and `<html lang dir>`. Off unless set */
90
101
  i18n?: I18nConfig;
102
+ /** `sitemap.xml` and `robots.txt` generated by `noofpi build`: `siteUrl` enables the sitemap, `sitemap: false` / `robots: false` disable either file, `exclude` hides pages. A file in `public/` always wins */
103
+ seo?: SeoConfig;
91
104
  doofpi?: {
92
105
  /** How the doofpi client reaches the API. Default: `lfetch`. `routeRules[...].fetch` overrides it per route */
93
106
  fetch?: FetchMode;
@@ -103,6 +116,13 @@ interface NoofpiConfig {
103
116
  build?: {
104
117
  /** Deploy target of `noofpi build`: `node` (default), `bun`, `docker`, `cloudflare-worker`, `cloudflare-pages` or `github-pages` (static SPA). `--preset` overrides it */
105
118
  preset?: BuildPreset;
119
+ /** Options of the generated `.output/Dockerfile` (`docker` preset) */
120
+ docker?: {
121
+ /** Base image of both build stages. Default: `node:22-alpine` (`oven/bun:1` when the project uses bun) */
122
+ image?: string;
123
+ /** Path the image `HEALTHCHECK` requests (any status below 500 is healthy), or `false` for no healthcheck. Default: `/` */
124
+ healthcheck?: string | false;
125
+ };
106
126
  };
107
127
  /** Mini devtools overlay in `noofpi dev` (current route, middleware chain, fetch mode, doofpi requests, CSP violations). Never included in production builds. Default: `true` */
108
128
  devtools?: boolean;
@@ -112,4 +132,4 @@ interface NoofpiConfig {
112
132
  declare function defineNoofpiConfig(config: NoofpiConfig): NoofpiConfig;
113
133
 
114
134
  export { BUILD_PRESETS, FONT_PROVIDERS, FetchMode, HeadConfig, I18nConfig, ImagesConfig, RouteRules, SecurityConfig, defineNoofpiConfig };
115
- export type { BuildPreset, FontDisplay, FontFamily, FontProviderName, FontStyle, FontWeight, FontsConfig, GoogleFontFamily, LocalFontFamily, LocalFontFile, NoofpiConfig };
135
+ export type { BuildPreset, FontDisplay, FontFamily, FontProviderName, FontStyle, FontWeight, FontsConfig, GoogleFontFamily, LocalFontFamily, LocalFontFile, NoofpiConfig, SeoConfig };
package/dist/index.js CHANGED
@@ -2,11 +2,11 @@ import {
2
2
  BUILD_PRESETS,
3
3
  FONT_PROVIDERS,
4
4
  defineNoofpiConfig
5
- } from "./chunk-NX6BO7UB.js";
5
+ } from "./chunk-IE3WF5XF.js";
6
6
  import "./chunk-ELXCFUA4.js";
7
7
  import {
8
8
  FETCH_MODES
9
- } from "./chunk-FIJJ3EGL.js";
9
+ } from "./chunk-MN5PVHC5.js";
10
10
  export {
11
11
  BUILD_PRESETS,
12
12
  FETCH_MODES,
@@ -117,43 +117,5 @@ interface AsyncDataError {
117
117
  status?: number;
118
118
  }
119
119
 
120
- /** The part of a Zod issue that noofpi reads; doofpi's `issues` and `schema.safeParse()` errors satisfy it */
121
- interface ValidationIssue {
122
- path: readonly PropertyKey[];
123
- message: string;
124
- }
125
- /** Messages by field path (`"user.email"`, `"tags.0"`). Issues about the whole value are under {@link FORM_ERROR_KEY} */
126
- type FormErrors = Record<string, string[]>;
127
- declare const FORM_ERROR_KEY = "";
128
- /** Any schema with a Zod-style `safeParse` (Zod 3 and 4) */
129
- interface FormSchema<T> {
130
- safeParse(value: unknown): {
131
- success: true;
132
- data: T;
133
- } | {
134
- success: false;
135
- error: {
136
- issues: readonly ValidationIssue[];
137
- };
138
- };
139
- }
140
- type InferSchema<S> = S extends FormSchema<infer T> ? T : never;
141
- type ValidationResult<T> = {
142
- ok: true;
143
- data: T;
144
- } | {
145
- ok: false;
146
- errors: FormErrors;
147
- };
148
- /** Groups issues by field path, the same shape on the server and in the browser */
149
- declare function issuesToErrors(issues: readonly ValidationIssue[] | undefined): FormErrors;
150
- /** Validates with the schema shared by the server endpoint and the form */
151
- declare function validate<T>(schema: FormSchema<T>, value: unknown): ValidationResult<T>;
152
- /**
153
- * The field errors of a doofpi input validation failure (a `DoofpiClientError` with status 400 and `issues`), or
154
- * `undefined` for any other failure
155
- */
156
- declare function errorsFromFailure(failure: unknown): FormErrors | undefined;
157
-
158
- export { NoofpiError as a, FORM_ERROR_KEY as g, booleanCodec as i, createError as j, defineCookie as k, enumCodec as l, errorsFromFailure as m, issuesToErrors as n, jsonCodec as o, numberCodec as p, stringCodec as s, validate as v };
159
- export type { AsyncDataError as A, CreateErrorInput as C, FormErrors as F, InferSchema as I, NoofpiErrorData as N, PayloadData as P, RequestEntry as R, ValidationIssue as V, CookieJar as b, CookieOptions as c, CookieCodec as d, CookieDefinition as e, FormSchema as f, ValidationResult as h };
120
+ export { NoofpiError as a, booleanCodec as f, createError as g, defineCookie as h, enumCodec as i, jsonCodec as j, numberCodec as n, stringCodec as s };
121
+ export type { AsyncDataError as A, CreateErrorInput as C, NoofpiErrorData as N, PayloadData as P, RequestEntry as R, CookieJar as b, CookieOptions as c, CookieCodec as d, CookieDefinition as e };
@@ -0,0 +1,24 @@
1
+ import {
2
+ createViteConfig
3
+ } from "./chunk-LL3NO5EI.js";
4
+ import "./chunk-IE3WF5XF.js";
5
+ import "./chunk-MTXQR32N.js";
6
+ import "./chunk-PPUFFGCH.js";
7
+ import "./chunk-ELXCFUA4.js";
8
+ import "./chunk-G35DW4NA.js";
9
+ import "./chunk-MN5PVHC5.js";
10
+ import "./chunk-Y3NBZ6DW.js";
11
+
12
+ // src/vite/prepare.ts
13
+ import { createServer } from "vite";
14
+ async function prepareApp(root, config) {
15
+ const inline = createViteConfig(root, config, "dev");
16
+ inline.logLevel = "warn";
17
+ inline.server = { middlewareMode: true, hmr: false, watch: null };
18
+ inline.optimizeDeps = { noDiscovery: true, include: [] };
19
+ const vite = await createServer(inline);
20
+ await vite.close();
21
+ }
22
+ export {
23
+ prepareApp
24
+ };
@@ -0,0 +1,6 @@
1
+ import * as vue from 'vue';
2
+
3
+ /** Root component used when the project has no `app/app.vue` */
4
+ declare const DefaultApp: vue.DefineComponent<{}, {}, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
5
+
6
+ export { DefaultApp as default };
@@ -0,0 +1,3 @@
1
+ declare function mount(): Promise<void>;
2
+
3
+ export { mount };
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  createNoofpiApp
3
- } from "../chunk-4YOOGEOF.js";
3
+ } from "../chunk-YJVMBHNL.js";
4
4
  import "../chunk-6OWKWAIW.js";
5
5
  import "../chunk-ELXCFUA4.js";
6
6
  import "../chunk-EZPJF4D4.js";
7
7
  import "../chunk-G35DW4NA.js";
8
- import "../chunk-FIJJ3EGL.js";
8
+ import "../chunk-MN5PVHC5.js";
9
9
 
10
10
  // src/runtime/entry-client.ts
11
11
  import { publicConfig } from "virtual:noofpi/config";
@@ -49,12 +49,20 @@ async function mount() {
49
49
  });
50
50
  await i18n?.ready;
51
51
  if (import.meta.env.DEV && publicConfig.devtools) {
52
- const { mountDevtools } = await import("../devtools-KTDSD5PR.js");
52
+ const { mountDevtools } = await import("../devtools-PLUN2DYV.js");
53
53
  mountDevtools({
54
54
  router,
55
55
  config: publicConfig,
56
56
  middlewareFiles: Object.keys(routeMiddleware),
57
- requests: log
57
+ requests: log,
58
+ app,
59
+ payload: {
60
+ data: payload.data,
61
+ errors: payload.errors,
62
+ state: payload.state,
63
+ locale: payload.locale,
64
+ error: payload.error
65
+ }
58
66
  });
59
67
  }
60
68
  await router.isReady().catch((failure) => {
@@ -0,0 +1,8 @@
1
+ import { RenderContext, RenderResult } from '../server/index.js';
2
+ import 'doofpi';
3
+ import '../route-rules-COilNsVT.js';
4
+ import '../payload-CL6tYBin.js';
5
+
6
+ declare function render(url: string, ctx: RenderContext): Promise<RenderResult>;
7
+
8
+ export { render };
@@ -4,7 +4,7 @@ import {
4
4
  notFoundError,
5
5
  setServerStateSource,
6
6
  snapshotEntries
7
- } from "../chunk-4YOOGEOF.js";
7
+ } from "../chunk-YJVMBHNL.js";
8
8
  import "../chunk-6OWKWAIW.js";
9
9
  import "../chunk-ELXCFUA4.js";
10
10
  import {
@@ -12,7 +12,7 @@ import {
12
12
  toErrorData
13
13
  } from "../chunk-EZPJF4D4.js";
14
14
  import "../chunk-G35DW4NA.js";
15
- import "../chunk-FIJJ3EGL.js";
15
+ import "../chunk-MN5PVHC5.js";
16
16
 
17
17
  // src/runtime/entry-server.ts
18
18
  import { AsyncLocalStorage } from "async_hooks";
@@ -1,16 +1,19 @@
1
1
  import * as vue from 'vue';
2
2
  import { Ref, ComputedRef, ShallowRef, MaybeRefOrGetter, App, PropType, VNode } from 'vue';
3
3
  import * as vue_router from 'vue-router';
4
- import { RouteLocationNormalized, RouteParams, LocationQuery, Router, NavigationGuardReturn, RouteRecordRaw, LocationQueryRaw, NavigationFailure, RouteLocationRaw } from 'vue-router';
5
- import { A as AsyncDataError, R as RequestEntry, N as NoofpiErrorData, C as CreateErrorInput, a as NoofpiError, b as CookieJar, c as CookieOptions, d as CookieCodec, e as CookieDefinition, F as FormErrors, f as FormSchema } from '../validation-ClXd_DAW.js';
4
+ import { RouteLocationNormalized, RouteParams, LocationQuery, Router, NavigationGuardReturn, LocationQueryRaw, NavigationFailure, RouteLocationRaw } from 'vue-router';
5
+ import { A as AsyncDataError, R as RequestEntry, N as NoofpiErrorData, C as CreateErrorInput, a as NoofpiError, b as CookieJar, c as CookieOptions, d as CookieCodec, e as CookieDefinition } from '../payload-CL6tYBin.js';
6
6
  import { PayloadData } from '../server/index.js';
7
- export { g as FORM_ERROR_KEY, I as InferSchema, V as ValidationIssue, h as ValidationResult, i as booleanCodec, j as createError, k as defineCookie, l as enumCodec, m as errorsFromFailure, n as issuesToErrors, o as jsonCodec, p as numberCodec, s as stringCodec, v as validate } from '../validation-ClXd_DAW.js';
7
+ export { f as booleanCodec, g as createError, h as defineCookie, i as enumCodec, j as jsonCodec, n as numberCodec, s as stringCodec } from '../payload-CL6tYBin.js';
8
8
  import Doofpi, { createClient, ClientFetch } from 'doofpi';
9
9
  import { e as HeadInput } from '../route-rules-COilNsVT.js';
10
10
  import { FetchMode } from '../index.js';
11
11
  import { ResolvedHead } from '../server/index.js';
12
12
  export { H as HeadConfig, f as HeadTag, g as RouteRule, R as RouteRules } from '../route-rules-COilNsVT.js';
13
13
  import { M as Messages, c as MessageParamValue, d as ImageSource } from '../images-BNwTAi50.js';
14
+ import { F as FormErrors, a as FormSchema } from '../validation-Dwpex2JZ.js';
15
+ export { b as FORM_ERROR_KEY, I as InferSchema, V as ValidationIssue, c as ValidationResult, e as errorsFromFailure, i as issuesToErrors, v as validate } from '../validation-Dwpex2JZ.js';
16
+ export { createRoutes, filePathToRoute } from './routes.js';
14
17
 
15
18
  interface NoofpiPayloadState extends PayloadData {
16
19
  server: boolean;
@@ -99,15 +102,46 @@ interface RequestLog {
99
102
  /** doofpi's `Routes` type is not exported, but it is the constraint of `routes()` */
100
103
  type Routes = Parameters<Doofpi["routes"]>[0];
101
104
  /**
102
- * Filled in by the `.noofpi/doofpi.d.ts` that noofpi generates from `server/doofpi.ts` (its `routes` export), so
103
- * clients are typed without a generic. Augment it yourself to register routes from elsewhere.
105
+ * Registers the routes types of the doofpi clients, so they are typed without a generic. Augment it yourself:
106
+ * - `remoteRoutes`: the routes of the remote API, used by `dfetch`, `pfetch` and `sfetch`
107
+ * - `localRoutes`: the routes of `server/doofpi.ts`, used by `lfetch`. Filled in by the `.noofpi/doofpi.d.ts` that
108
+ * noofpi generates (its `routes` export), so you rarely set it
109
+ * - `routes`: used by every mode that has no `localRoutes` / `remoteRoutes`
110
+ * - `defaultFetch`: the `doofpi.fetch` mode of the config (also filled in by `.noofpi/doofpi.d.ts`). A call without
111
+ * `{ mode }` is typed for it, so it cannot see `routeRules[...].fetch`: pass `{ mode }` where a page differs
104
112
  */
105
113
  interface Register {
106
114
  }
107
- /** The routes registered through {@link Register}, `any` when there are none */
115
+ /** The `routes` registered through {@link Register}, `any` when there are none */
108
116
  type RegisteredRoutes = Register extends {
109
117
  routes: infer R extends Routes;
110
118
  } ? R : any;
119
+ type LocalOnly = Register extends {
120
+ localRoutes: infer R extends Routes;
121
+ } ? R : never;
122
+ type RemoteOnly = Register extends {
123
+ remoteRoutes: infer R extends Routes;
124
+ } ? R : never;
125
+ type OrRoutes<R> = [R] extends [never] ? RegisteredRoutes : R;
126
+ /** The `localRoutes` registered through {@link Register}, else {@link RegisteredRoutes} */
127
+ type RegisteredLocalRoutes = OrRoutes<LocalOnly>;
128
+ /** The `remoteRoutes` registered through {@link Register}, else {@link RegisteredRoutes} */
129
+ type RegisteredRemoteRoutes = OrRoutes<RemoteOnly>;
130
+ type DefaultFetch = Register extends {
131
+ defaultFetch: infer F extends FetchMode;
132
+ } ? F : undefined;
133
+ type REMOTE_MODES = "dfetch" | "pfetch" | "sfetch";
134
+ /** Without a default mode: `routes`, else the remote routes, else the local ones, else `any` */
135
+ type UnmodedRoutes = Register extends {
136
+ routes: infer R extends Routes;
137
+ } ? R : [RemoteOnly] extends [never] ? [LocalOnly] extends [never] ? any : LocalOnly : RemoteOnly;
138
+ /**
139
+ * The routes of a fetch mode: `lfetch` -> local, the other modes -> remote. `undefined` (or a mode that is not a single
140
+ * literal) is the `defaultFetch` mode of the config.
141
+ */
142
+ type RoutesForMode<M extends FetchMode | undefined = undefined> = [
143
+ M
144
+ ] extends ["lfetch"] ? RegisteredLocalRoutes : [M] extends [REMOTE_MODES] ? RegisteredRemoteRoutes : [DefaultFetch] extends ["lfetch"] ? RegisteredLocalRoutes : [DefaultFetch] extends [REMOTE_MODES] ? RegisteredRemoteRoutes : UnmodedRoutes;
111
145
  type DoofpiClient<R extends Routes = RegisteredRoutes> = ReturnType<typeof createClient<R>>;
112
146
  interface UseDoofpiOptions {
113
147
  /** Use this fetch mode instead of the one of the current page */
@@ -117,10 +151,13 @@ interface UseDoofpiOptions {
117
151
  * The doofpi client for the `doofpi.fetch` mode that applies to the current page (`routeRules[...].fetch` or the global
118
152
  * one), or for an explicit `{ mode }` (e.g. `useDoofpi({ mode: "sfetch" })`, which must be enabled in the config).
119
153
  * Call it inside `setup()` (or `app.runWithContext`); layouts and `app.vue` are set up once, so they keep the
120
- * client of the first page. Typed by the `routes` export of `server/doofpi.ts`; pass a routes type to override it:
121
- * `useDoofpi<OtherRoutes>()`.
154
+ * client of the first page. Typed by the `Register` routes of the mode (`localRoutes` for `lfetch`, `remoteRoutes` for
155
+ * the others, see {@link Register}); pass a routes type to override it: `useDoofpi<OtherRoutes>()`.
122
156
  */
123
- declare function useDoofpi<R extends Routes = RegisteredRoutes>(options?: UseDoofpiOptions): DoofpiClient<R>;
157
+ declare function useDoofpi<M extends FetchMode | undefined = undefined>(options?: UseDoofpiOptions & {
158
+ mode?: M;
159
+ }): DoofpiClient<RoutesForMode<M>>;
160
+ declare function useDoofpi<R extends Routes>(options?: UseDoofpiOptions): DoofpiClient<R>;
124
161
  interface DoofpiClientConfig {
125
162
  fetch: FetchMode;
126
163
  url: string | undefined;
@@ -294,12 +331,16 @@ declare function useCookie<T>(cookie: CookieDefinition<T>, options?: UseCookieOp
294
331
 
295
332
  /**
296
333
  * `useAsyncData` with the doofpi client handed to the handler: fetched on the server, transferred to the browser,
297
- * not fetched again while hydrating. The client is typed by the `routes` export of `server/doofpi.ts`:
298
- * `useDoofpiFetch("hello", (client) => client.hello.read())`.
334
+ * not fetched again while hydrating. The client is typed by the `Register` routes of its mode (`localRoutes` for
335
+ * `lfetch`, `remoteRoutes` for the others): `useDoofpiFetch("hello", (client) => client.hello.read())`.
299
336
  * `key` must be unique per piece of data. `options.mode` picks the fetch mode like `useDoofpi({ mode })`.
337
+ * To type the client with other routes, annotate it: `(client: DoofpiClient<OtherRoutes>) => ...`.
300
338
  * Call inside `setup()`.
301
339
  */
302
- declare function useDoofpiFetch<T, R extends Routes = RegisteredRoutes>(key: string, handler: (client: DoofpiClient<R>) => Promise<T>, options?: UseAsyncDataOptions & {
340
+ declare function useDoofpiFetch<T, M extends FetchMode | undefined = undefined>(key: string, handler: (client: DoofpiClient<RoutesForMode<M>>) => Promise<T>, options?: UseAsyncDataOptions & {
341
+ mode?: M;
342
+ }): AsyncData<T>;
343
+ declare function useDoofpiFetch<T, R extends Routes>(key: string, handler: (client: DoofpiClient<R>) => Promise<T>, options?: UseAsyncDataOptions & {
303
344
  mode?: FetchMode;
304
345
  }): AsyncData<T>;
305
346
 
@@ -487,10 +528,6 @@ interface NoofpiPluginContext {
487
528
  type NoofpiPlugin = (context: NoofpiPluginContext) => void;
488
529
  declare function defineNoofpiPlugin(plugin: NoofpiPlugin): NoofpiPlugin;
489
530
 
490
- /** `/app/pages/users/[id].vue` -> `/users/:id` ; `index.vue` -> `/` ; `[...slug].vue` -> catch-all */
491
- declare function filePathToRoute(file: string): string;
492
- declare function createRoutes(pages: Record<string, () => Promise<unknown>>, layouts?: Record<string, string | false>, middleware?: Record<string, string[]>): RouteRecordRaw[];
493
-
494
531
  /**
495
532
  * The page routes registered through {@link Register}: path pattern -> params. Filled in by the `.noofpi/routes.d.ts`
496
533
  * that noofpi generates from `app/pages`. Empty without it.
@@ -519,5 +556,5 @@ declare function navigateTo<T extends RouteLocationRaw>(to: T extends keyof Regi
519
556
  params?: Record<string, RouteParamValue>;
520
557
  }): Promise<NavigationFailure | void | undefined>;
521
558
 
522
- export { AsyncDataError, ClientOnly, CookieCodec, CookieDefinition, CookieJar, CookieOptions, CreateErrorInput, FormErrors, FormSchema, HeadInput, ImageSource, MessageParamValue, Messages, NoofpiError, NoofpiErrorData, NoofpiImage, NoofpiLayout, NoofpiLink, NoofpiPage, RequestEntry, clearError, createDoofpiClient, createNoofpiApp, createRoutes, defineMessages, defineNoofpiPlugin, definePage, defineRouteMiddleware, filePathToRoute, navigateTo, showError, useAsyncData, useCookie, useCookies, useDoofpi, useDoofpiFetch, useDoofpiForm, useError, useHead, useI18n, useLayout, useLoaderData, useMiddleware, useState };
523
- export type { AsyncData, DoofpiClient, DoofpiClientConfig, DoofpiClientContext, DoofpiForm, I18n, LoaderContext, LoaderData, Locale, LocaleMessages, MessageArgs, MessageKey, NavigateToOptions, NoofpiPlugin, NoofpiPluginContext, PageDefinition, PageLoader, Register, RegisteredMessages, RegisteredPages, RegisteredRoutes, RouteMiddleware, RouteParamValue, SubmitResult, TranslateFunction, UseAsyncDataOptions, UseCookieCodecOptions, UseCookieOptions, UseDoofpiFormOptions, UseDoofpiOptions };
559
+ export { AsyncDataError, ClientOnly, CookieCodec, CookieDefinition, CookieJar, CookieOptions, CreateErrorInput, FormErrors, FormSchema, HeadInput, ImageSource, MessageParamValue, Messages, NoofpiError, NoofpiErrorData, NoofpiImage, NoofpiLayout, NoofpiLink, NoofpiPage, RequestEntry, clearError, createDoofpiClient, createNoofpiApp, defineMessages, defineNoofpiPlugin, definePage, defineRouteMiddleware, navigateTo, showError, useAsyncData, useCookie, useCookies, useDoofpi, useDoofpiFetch, useDoofpiForm, useError, useHead, useI18n, useLayout, useLoaderData, useMiddleware, useState };
560
+ export type { AsyncData, DoofpiClient, DoofpiClientConfig, DoofpiClientContext, DoofpiForm, I18n, LoaderContext, LoaderData, Locale, LocaleMessages, MessageArgs, MessageKey, NavigateToOptions, NoofpiPlugin, NoofpiPluginContext, PageDefinition, PageLoader, Register, RegisteredLocalRoutes, RegisteredMessages, RegisteredPages, RegisteredRemoteRoutes, RegisteredRoutes, RouteMiddleware, RouteParamValue, RoutesForMode, SubmitResult, TranslateFunction, UseAsyncDataOptions, UseCookieCodecOptions, UseCookieOptions, UseDoofpiFormOptions, UseDoofpiOptions };
@@ -16,7 +16,7 @@ import {
16
16
  useI18n,
17
17
  useLoaderData,
18
18
  useState
19
- } from "../chunk-4YOOGEOF.js";
19
+ } from "../chunk-YJVMBHNL.js";
20
20
  import {
21
21
  defineRouteMiddleware,
22
22
  useMiddleware
@@ -38,7 +38,7 @@ import {
38
38
  stringCodec
39
39
  } from "../chunk-EZPJF4D4.js";
40
40
  import "../chunk-G35DW4NA.js";
41
- import "../chunk-FIJJ3EGL.js";
41
+ import "../chunk-MN5PVHC5.js";
42
42
  import {
43
43
  NoofpiLayout,
44
44
  NoofpiLink,
@@ -0,0 +1,13 @@
1
+ import { Component } from 'vue';
2
+ import { RouteRecordRaw } from 'vue-router';
3
+
4
+ /** `/app/pages/users/[id].vue` -> `/users/:id` ; `index.vue` -> `/` ; `[...slug].vue` -> catch-all */
5
+ declare function filePathToRoute(file: string): string;
6
+ declare function createRoutes(pages: Record<string, () => Promise<unknown>>, layouts?: Record<string, string | false>, middleware?: Record<string, string[]>): RouteRecordRaw[];
7
+ /** `/app/layouts/AdminPanel.vue` -> `admin-panel` */
8
+ declare function filePathToLayoutName(file: string): string;
9
+ declare function createLayouts(modules: Record<string, Component>): Record<string, Component>;
10
+ /** A page's `layout` export: a layout name, `false` for no layout, anything else means "default" */
11
+ declare function normalizeLayout(value: unknown): string | false | undefined;
12
+
13
+ export { createLayouts, createRoutes, filePathToLayoutName, filePathToRoute, normalizeLayout };
@@ -0,0 +1,5 @@
1
+ declare const createConsoleReporter: () => () => void;
2
+ declare const defineDiagnostics: (_options?: unknown) => {};
3
+ declare const defineProdDiagnostics: (_options?: unknown) => {};
4
+
5
+ export { createConsoleReporter, defineDiagnostics, defineProdDiagnostics };
@@ -0,0 +1,15 @@
1
+ import { Handler } from './index.js';
2
+ import '../types-B6rQOOxS.js';
3
+ import 'doofpi';
4
+ import '../route-rules-COilNsVT.js';
5
+ import '../payload-CL6tYBin.js';
6
+
7
+ /** Serves a handler with `Bun.serve`: static files of `publicDir` first, then the handler. */
8
+ declare function serveBun(options: {
9
+ publicDir: string;
10
+ handler: Handler;
11
+ port: number;
12
+ host: string;
13
+ }): Promise<void>;
14
+
15
+ export { serveBun };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  resolveStaticFile
3
- } from "../chunk-KGZP2RCF.js";
3
+ } from "../chunk-PPUFFGCH.js";
4
4
 
5
5
  // src/server/bun.ts
6
6
  async function serveBun(options) {
@@ -16,18 +16,21 @@ async function serveBun(options) {
16
16
  const found = await resolveStaticFile(
17
17
  options.publicDir,
18
18
  request.method,
19
- url.pathname
19
+ url.pathname,
20
+ Object.fromEntries(request.headers)
20
21
  );
21
22
  if (found) {
22
- return new Response(
23
- request.method === "HEAD" ? null : bun.file(found.file),
24
- {
25
- headers: {
26
- ...found.headers,
27
- "Content-Length": String(found.size)
28
- }
29
- }
30
- );
23
+ let body = null;
24
+ if (request.method !== "HEAD" && found.body) {
25
+ const { file, start, end } = found.body;
26
+ body = bun.file(file);
27
+ if (start !== void 0 && end !== void 0)
28
+ body = body.slice(start, end + 1);
29
+ }
30
+ return new Response(body, {
31
+ status: found.status,
32
+ headers: found.headers
33
+ });
31
34
  }
32
35
  return await options.handler(request);
33
36
  } catch (error) {
@@ -1,91 +1,11 @@
1
- import { ClientFetch } from 'doofpi';
2
- import { i as ResolvedSecurity, h as ResolvedHead } from '../route-rules-COilNsVT.js';
3
- import { FetchMode, HeadConfig, RouteRules } from '../index.js';
4
- import { b as CookieJar, P as PayloadData } from '../validation-ClXd_DAW.js';
5
- export { d as CookieCodec, e as CookieDefinition, c as CookieOptions, g as FORM_ERROR_KEY, F as FormErrors, f as FormSchema, I as InferSchema, V as ValidationIssue, h as ValidationResult, i as booleanCodec, k as defineCookie, l as enumCodec, m as errorsFromFailure, n as issuesToErrors, o as jsonCodec, p as numberCodec, s as stringCodec, v as validate } from '../validation-ClXd_DAW.js';
6
-
7
- declare const PROXY_PREFIX = "/_noofpi/proxy";
8
- /** Server-side config (includes the remote `doofpi.url`, which is never sent to the browser for pfetch/sfetch) */
9
- interface ServerConfig {
10
- ssr: boolean;
11
- doofpi: {
12
- fetch: FetchMode;
13
- url: string | undefined;
14
- root: string;
15
- };
16
- head?: HeadConfig;
17
- routeRules?: RouteRules;
18
- security?: Partial<ResolvedSecurity>;
19
- }
20
- interface RenderContext {
21
- origin: string;
22
- cookie?: string;
23
- /** The request's cookies; changes made while rendering are sent with the response */
24
- cookies: CookieJar;
25
- /** The request's `Accept-Language` header, for the `i18n` locale detection */
26
- acceptLanguage?: string;
27
- /** In-process fetch into the noofpi server (used for `lfetch` / `pfetch` during SSR) */
28
- fetch: ClientFetch;
29
- }
30
- interface RenderResult {
31
- html: string;
32
- status: number;
33
- /** Set when a route middleware redirected: the handler answers with a 302 to this path instead of HTML */
34
- redirect?: string;
35
- /** An unexpected error that was rendered as `app/error.vue` (status 500); the handler reports it like any server error */
36
- error?: unknown;
37
- /** Data gathered by `useAsyncData` while rendering, embedded in the page for the browser */
38
- payload?: PayloadData;
39
- /** Title, meta tags and attributes gathered by `useHead` while rendering, written into the HTML shell */
40
- head?: ResolvedHead;
41
- }
42
- /**
43
- * Optional `server/proxy.ts` default export. Mutate `headers` to change what is sent to the doofpi API
44
- * (e.g. inject an `Authorization` token), or return a `Response` to short-circuit the request.
45
- */
46
- type ProxyHook = (ctx: {
47
- request: Request;
48
- headers: Headers;
49
- target: URL;
50
- }) => void | Response | Promise<void | Response>;
51
- interface DoofpiLike {
52
- fetch(request: Request, env?: any, extra?: any): Promise<Response>;
53
- }
54
- interface ServerMiddlewareContext {
55
- request: Request;
56
- url: URL;
57
- env?: unknown;
58
- /** Read the request's cookies and set / remove cookies on the response (also when you return your own `Response`) */
59
- cookies: CookieJar;
60
- }
61
- /**
62
- * A `server/middleware/*.ts` default export. Runs around every request the noofpi server handles (pages, the doofpi
63
- * API and the pfetch proxy). Call `next()` to continue and optionally change its response, or return your own
64
- * `Response` without calling it to short-circuit. Always returns a `Response`.
65
- */
66
- type ServerMiddleware = (ctx: ServerMiddlewareContext, next: () => Promise<Response>) => Response | Promise<Response>;
67
- /** Shape of the generated `virtual:noofpi/server` module */
68
- interface ServerModule {
69
- config: ServerConfig;
70
- doofpi?: DoofpiLike;
71
- proxyHook?: ProxyHook;
72
- /** `server/middleware/*` in file-name order, outermost first */
73
- middleware?: ServerMiddleware[];
74
- render?: (url: string, ctx: RenderContext) => Promise<RenderResult>;
75
- }
76
-
77
- interface HandlerOptions {
78
- /** Returns the generated server module (`virtual:noofpi/server`, or the built bundle in production) */
79
- load: () => Promise<ServerModule>;
80
- /** Returns the HTML shell for a page URL */
81
- getTemplate: (url: string) => Promise<string>;
82
- onError?: (error: unknown) => void;
83
- }
84
- type Handler = (request: Request, env?: unknown) => Promise<Response>;
85
- /**: one web-standard `fetch(Request) -> Response` handler.
86
- * Order: proxy (pfetch) -> local doofpi API -> HTML (SSR render or SPA shell).
87
- */
88
- declare function createHandler(options: HandlerOptions): Handler;
1
+ export { H as Handler, a as HandlerOptions, c as createHandler } from '../handler-C6NnwBfC.js';
2
+ import { P as ProxyHook, S as ServerMiddleware } from '../types-B6rQOOxS.js';
3
+ export { b as PROXY_PREFIX, R as RenderContext, a as RenderResult, c as ServerConfig, d as ServerMiddlewareContext, e as ServerModule } from '../types-B6rQOOxS.js';
4
+ import { b as CookieJar } from '../payload-CL6tYBin.js';
5
+ export { d as CookieCodec, e as CookieDefinition, c as CookieOptions, P as PayloadData, f as booleanCodec, h as defineCookie, i as enumCodec, j as jsonCodec, n as numberCodec, s as stringCodec } from '../payload-CL6tYBin.js';
6
+ export { b as FORM_ERROR_KEY, F as FormErrors, a as FormSchema, I as InferSchema, V as ValidationIssue, c as ValidationResult, e as errorsFromFailure, i as issuesToErrors, v as validate } from '../validation-Dwpex2JZ.js';
7
+ export { h as ResolvedHead, i as ResolvedSecurity } from '../route-rules-COilNsVT.js';
8
+ import 'doofpi';
89
9
 
90
10
  /** Resolves a proxied path to a URL on the remote API, or `null` when it is not allowed */
91
11
  declare function resolveProxyTarget(pathname: string, search: string, base: string, root: string): URL | null;
@@ -105,5 +25,4 @@ declare function getRequestCookies(request: Request): CookieJar;
105
25
  /** Typing helper for `server/middleware/*.ts` */
106
26
  declare function defineServerMiddleware(middleware: ServerMiddleware): ServerMiddleware;
107
27
 
108
- export { CookieJar, PROXY_PREFIX, PayloadData, ResolvedHead, ResolvedSecurity, createHandler, defineServerMiddleware, getRequestCookies, proxyRequest, resolveProxyTarget };
109
- export type { Handler, HandlerOptions, ProxyHook, RenderContext, RenderResult, ServerConfig, ServerMiddleware, ServerMiddlewareContext, ServerModule };
28
+ export { CookieJar, ProxyHook, ServerMiddleware, defineServerMiddleware, getRequestCookies, proxyRequest, resolveProxyTarget };
@@ -3,7 +3,7 @@ import {
3
3
  getRequestCookies,
4
4
  proxyRequest,
5
5
  resolveProxyTarget
6
- } from "../chunk-2XCZWFIQ.js";
6
+ } from "../chunk-X3DYEZLK.js";
7
7
  import {
8
8
  PROXY_PREFIX
9
9
  } from "../chunk-MTXQR32N.js";
@@ -22,7 +22,7 @@ import {
22
22
  stringCodec
23
23
  } from "../chunk-EZPJF4D4.js";
24
24
  import "../chunk-G35DW4NA.js";
25
- import "../chunk-FIJJ3EGL.js";
25
+ import "../chunk-MN5PVHC5.js";
26
26
 
27
27
  // src/server/index.ts
28
28
  function defineServerMiddleware(middleware) {
@@ -0,0 +1,20 @@
1
+ import { Server, ServerResponse, IncomingMessage } from 'node:http';
2
+ import { Handler } from './index.js';
3
+ import '../types-B6rQOOxS.js';
4
+ import 'doofpi';
5
+ import '../route-rules-COilNsVT.js';
6
+ import '../payload-CL6tYBin.js';
7
+
8
+ declare function toWebRequest(req: IncomingMessage): Request;
9
+ declare function sendWebResponse(res: ServerResponse, response: Response): Promise<void>;
10
+ /** Serves files from `dir`. Returns `false` when the request is not a static file. */
11
+ declare function serveStatic(dir: string, req: IncomingMessage, res: ServerResponse): Promise<boolean>;
12
+ /** A node http server for a handler: static files of `publicDir` first, then the handler. Not listening yet. */
13
+ declare function createNodeServer(options: {
14
+ publicDir: string;
15
+ handler: Handler;
16
+ }): Server;
17
+ /** Starts `createNodeServer` and logs the address. `host` `0.0.0.0` is shown as `localhost`. */
18
+ declare function listenNodeServer(server: Server, port: number, host: string): Promise<Server>;
19
+
20
+ export { createNodeServer, listenNodeServer, sendWebResponse, serveStatic, toWebRequest };
@@ -4,8 +4,8 @@ import {
4
4
  sendWebResponse,
5
5
  serveStatic,
6
6
  toWebRequest
7
- } from "../chunk-NALDZ3PS.js";
8
- import "../chunk-KGZP2RCF.js";
7
+ } from "../chunk-I6TFIGFO.js";
8
+ import "../chunk-PPUFFGCH.js";
9
9
  export {
10
10
  createNodeServer,
11
11
  listenNodeServer,