fondu 0.3.0 → 0.4.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.
- package/README.md +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/server/protocol.d.ts +31 -2
- package/dist/server/protocol.js +11 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ URLs, the document and error pages. Everything else is Hono's, Vite's and Inerti
|
|
|
15
15
|
## Quick start
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
bun create fondu my-app
|
|
18
|
+
bun create fondu@latest my-app # or: npm create fondu@latest my-app · pnpm create fondu@latest my-app
|
|
19
19
|
cd my-app
|
|
20
20
|
bun dev
|
|
21
21
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { defineHandler, defineMiddleware } from './server/handler.js';
|
|
2
|
-
export { render, share, type RenderOptions } from './server/protocol.js';
|
|
2
|
+
export { render, share, encryptHistory, type RenderOptions } from './server/protocol.js';
|
|
3
3
|
export { back, location, isInertia, wantsPage } from './server/http.js';
|
|
4
4
|
export { optional, always, defer, once, merge, prepend, deepMerge, scroll, type Prop, type Paginated, } from './server/props.js';
|
|
5
5
|
export { flash, clearHistory } from './server/flash.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { defineHandler, defineMiddleware } from './server/handler.js';
|
|
2
|
-
export { render, share } from './server/protocol.js';
|
|
2
|
+
export { render, share, encryptHistory } from './server/protocol.js';
|
|
3
3
|
export { back, location, isInertia, wantsPage } from './server/http.js';
|
|
4
4
|
export { optional, always, defer, once, merge, prepend, deepMerge, scroll, } from './server/props.js';
|
|
5
5
|
export { flash, clearHistory } from './server/flash.js';
|
|
@@ -28,18 +28,47 @@ type OwnProps<N> = Omit<ComponentProps<N>, FromShared<ComponentProps<N>> | Clash
|
|
|
28
28
|
type PropsInput<P> = {
|
|
29
29
|
[K in keyof P]: P[K] | (() => P[K] | Promise<P[K]>);
|
|
30
30
|
};
|
|
31
|
+
type Json = string | number | boolean | null;
|
|
32
|
+
/** types JSON doesn't deliver as they are: a Date arrives as a string, a Map or a Set as {}, a function not at all */
|
|
33
|
+
type NotJson = Date | Map<unknown, unknown> | Set<unknown> | WeakMap<object, unknown> | WeakSet<object> | RegExp | bigint | symbol | ((...args: never[]) => unknown);
|
|
34
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
35
|
+
/** each member of T arrives as itself (depth-limited, for recursive types) */
|
|
36
|
+
type JsonMember<T, D extends unknown[]> = T extends Json | undefined ? true : T extends NotJson ? false : D['length'] extends 6 ? true : T extends readonly (infer E)[] ? Arrives<E, [...D, 0]> : T extends object ? Arrives<T[keyof T], [...D, 0]> : true;
|
|
37
|
+
type Arrives<T, D extends unknown[] = []> = IsAny<T> extends true ? true : unknown extends T ? true : [JsonMember<T, D>] extends [true] ? true : false;
|
|
38
|
+
/** what a route may pass for a page prop of type T: T, or anything JSON turns into it (a Date for a string: toJSON) */
|
|
39
|
+
type JsonInput<T> = IsAny<T> extends true ? T : T extends Json | undefined ? T | {
|
|
40
|
+
toJSON(): T;
|
|
41
|
+
} : T extends readonly (infer E)[] ? readonly JsonInput<E>[] | {
|
|
42
|
+
toJSON(): T;
|
|
43
|
+
} : T extends object ? {
|
|
44
|
+
[K in keyof T]: JsonInput<T[K]>;
|
|
45
|
+
} | {
|
|
46
|
+
toJSON(): T;
|
|
47
|
+
} : T;
|
|
48
|
+
type NotJsonError = 'fondu: the page receives this prop as JSON (a Date as a string, a Map as {}): type it as such';
|
|
49
|
+
/** a page's props as `render` takes them: what becomes each as JSON, or an error for a type JSON can't deliver */
|
|
50
|
+
export type Delivered<P> = {
|
|
51
|
+
[K in keyof P]: Arrives<P[K]> extends true ? JsonInput<P[K]> : NotJsonError;
|
|
52
|
+
};
|
|
31
53
|
type RequiredKeys<T> = {
|
|
32
54
|
[K in keyof T]-?: object extends Pick<T, K> ? never : K;
|
|
33
55
|
}[keyof T];
|
|
56
|
+
/**
|
|
57
|
+
* The pages of these requests are encrypted in the browser's history (Laravel's `EncryptHistory` middleware), so Back
|
|
58
|
+
* after signing out can't show them: in `routes/account/_middleware.ts`, `export default encryptHistory()`. A route
|
|
59
|
+
* can still opt out: `render(c, page, props, { encryptHistory: false })`.
|
|
60
|
+
*/
|
|
61
|
+
export declare const encryptHistory: () => MiddlewareHandler;
|
|
34
62
|
export interface RenderOptions {
|
|
35
63
|
status?: number;
|
|
64
|
+
/** the page's state is encrypted in the browser's history; default: `encryptHistory()` above the route, or not */
|
|
36
65
|
encryptHistory?: boolean;
|
|
37
66
|
clearHistory?: boolean;
|
|
38
67
|
preserveFragment?: boolean;
|
|
39
68
|
}
|
|
40
69
|
type RenderArgs<N> = [RequiredKeys<OwnProps<N>>] extends [never] ? OptionalArgs<N> : string extends keyof OwnProps<N> ? OptionalArgs<N> : RequiredArgs<N>;
|
|
41
|
-
type OptionalArgs<N> = [props?: PropsInput<OwnProps<N
|
|
42
|
-
type RequiredArgs<N> = [props: PropsInput<OwnProps<N
|
|
70
|
+
type OptionalArgs<N> = [props?: PropsInput<Delivered<OwnProps<N>>>, options?: RenderOptions];
|
|
71
|
+
type RequiredArgs<N> = [props: PropsInput<Delivered<OwnProps<N>>>, options?: RenderOptions];
|
|
43
72
|
export declare const hasPage: (name: string) => boolean;
|
|
44
73
|
/**
|
|
45
74
|
* The page `component` (a file in `pages/`, without extension) with these props: JSON for Inertia's requests,
|
package/dist/server/protocol.js
CHANGED
|
@@ -9,6 +9,16 @@ const shared = new WeakMap();
|
|
|
9
9
|
export function share(c, props) {
|
|
10
10
|
shared.set(c, { ...shared.get(c), ...props });
|
|
11
11
|
}
|
|
12
|
+
const encrypted = new WeakSet();
|
|
13
|
+
/**
|
|
14
|
+
* The pages of these requests are encrypted in the browser's history (Laravel's `EncryptHistory` middleware), so Back
|
|
15
|
+
* after signing out can't show them: in `routes/account/_middleware.ts`, `export default encryptHistory()`. A route
|
|
16
|
+
* can still opt out: `render(c, page, props, { encryptHistory: false })`.
|
|
17
|
+
*/
|
|
18
|
+
export const encryptHistory = () => async (c, next) => {
|
|
19
|
+
encrypted.add(c);
|
|
20
|
+
await next();
|
|
21
|
+
};
|
|
12
22
|
// development: the files in app/pages/ (Vite keeps the list current); a build: the pages in the client manifest
|
|
13
23
|
const devPages = import.meta.env.DEV ? import.meta.glob('/app/pages/**/*.{tsx,jsx,mdx}') : {};
|
|
14
24
|
export const hasPage = (name) => pages
|
|
@@ -136,7 +146,7 @@ export async function render(c, component, ...[props = {}, options = {}]) {
|
|
|
136
146
|
const sharedKeys = Object.keys(sharedProps);
|
|
137
147
|
if (sharedKeys.length)
|
|
138
148
|
page.sharedProps = sharedKeys;
|
|
139
|
-
if (options.encryptHistory)
|
|
149
|
+
if (options.encryptHistory ?? encrypted.has(c))
|
|
140
150
|
page.encryptHistory = true;
|
|
141
151
|
if (options.clearHistory || carried.clearHistory)
|
|
142
152
|
page.clearHistory = true;
|