@pracht/core 0.2.6 → 0.3.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.mts +54 -36
- package/dist/index.mjs +1143 -686
- package/package.json +1 -1
- package/dist/app-CUL3q2ZA.mjs +0 -259
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ metadata for the failure phase and matched framework files when available.
|
|
|
37
37
|
- `startApp()` — client-side hydration and runtime
|
|
38
38
|
- `useLocation()` — access the current pathname and search string separately
|
|
39
39
|
- `useRouteData()` — access loader data inside a route component
|
|
40
|
-
- `
|
|
40
|
+
- `useRevalidate()` — trigger a revalidation of the current route's data
|
|
41
41
|
- `<Form>` — progressive enhancement form component
|
|
42
42
|
|
|
43
43
|
### Types
|
package/dist/index.d.mts
CHANGED
|
@@ -35,7 +35,9 @@ interface TimeRevalidatePolicy {
|
|
|
35
35
|
}
|
|
36
36
|
type RouteRevalidate = TimeRevalidatePolicy;
|
|
37
37
|
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
|
|
38
|
-
type ApiRouteArgs<TContext = RegisteredContext> = BaseRouteArgs<TContext
|
|
38
|
+
type ApiRouteArgs<TContext = RegisteredContext> = Omit<BaseRouteArgs<TContext>, "route"> & {
|
|
39
|
+
route: ResolvedApiRoute;
|
|
40
|
+
};
|
|
39
41
|
type ApiRouteHandler<TContext = RegisteredContext> = (args: ApiRouteArgs<TContext>) => MaybePromise<Response>;
|
|
40
42
|
interface ApiRouteModule<TContext = any> {
|
|
41
43
|
default?: ApiRouteHandler<TContext>;
|
|
@@ -74,6 +76,14 @@ interface GroupMeta {
|
|
|
74
76
|
}
|
|
75
77
|
interface ApiConfig {
|
|
76
78
|
middleware?: string[];
|
|
79
|
+
/**
|
|
80
|
+
* When `true` (the default), state-changing API requests
|
|
81
|
+
* (POST/PUT/PATCH/DELETE) are rejected unless the browser signals a
|
|
82
|
+
* same-origin/same-site fetch (Sec-Fetch-Site) or the request Origin
|
|
83
|
+
* matches the request URL's origin. Set to `false` to opt out if you
|
|
84
|
+
* build your own CSRF protection into middleware.
|
|
85
|
+
*/
|
|
86
|
+
requireSameOrigin?: boolean;
|
|
77
87
|
}
|
|
78
88
|
interface RouteConfig extends RouteMeta {
|
|
79
89
|
component: ModuleRef;
|
|
@@ -179,6 +189,7 @@ interface RouteModule<TContext = any, TLoader extends LoaderLike = undefined> {
|
|
|
179
189
|
default?: FunctionComponent<RouteComponentProps<TLoader>>;
|
|
180
190
|
ErrorBoundary?: FunctionComponent<ErrorBoundaryProps>;
|
|
181
191
|
getStaticPaths?: () => MaybePromise<RouteParams[]>;
|
|
192
|
+
markdown?: string;
|
|
182
193
|
}
|
|
183
194
|
interface ShellModule<TContext = any> {
|
|
184
195
|
Shell: FunctionComponent<ShellProps>;
|
|
@@ -188,6 +199,7 @@ interface ShellModule<TContext = any> {
|
|
|
188
199
|
}
|
|
189
200
|
type MiddlewareResult<TContext = any> = void | Response | {
|
|
190
201
|
redirect: string;
|
|
202
|
+
status?: number;
|
|
191
203
|
} | {
|
|
192
204
|
context: Partial<TContext>;
|
|
193
205
|
};
|
|
@@ -250,7 +262,10 @@ declare function forwardRef<P = {}>(fn: ((props: P, ref: any) => any) & {
|
|
|
250
262
|
*/
|
|
251
263
|
declare function useIsHydrated(): boolean;
|
|
252
264
|
//#endregion
|
|
253
|
-
//#region src/runtime.d.ts
|
|
265
|
+
//#region src/runtime-headers.d.ts
|
|
266
|
+
declare function applyDefaultSecurityHeaders(headers: Headers): Headers;
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region src/runtime-errors.d.ts
|
|
254
269
|
type PrachtRuntimeDiagnosticPhase = "match" | "middleware" | "loader" | "action" | "render" | "api";
|
|
255
270
|
interface PrachtRuntimeDiagnostics {
|
|
256
271
|
phase: PrachtRuntimeDiagnosticPhase;
|
|
@@ -262,6 +277,14 @@ interface PrachtRuntimeDiagnostics {
|
|
|
262
277
|
middlewareFiles?: string[];
|
|
263
278
|
status: number;
|
|
264
279
|
}
|
|
280
|
+
interface SerializedRouteError {
|
|
281
|
+
message: string;
|
|
282
|
+
name: string;
|
|
283
|
+
status: number;
|
|
284
|
+
diagnostics?: PrachtRuntimeDiagnostics;
|
|
285
|
+
}
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region src/runtime-hooks.d.ts
|
|
265
288
|
interface PrachtHydrationState<TData = unknown> {
|
|
266
289
|
url: string;
|
|
267
290
|
routeId: string;
|
|
@@ -269,35 +292,17 @@ interface PrachtHydrationState<TData = unknown> {
|
|
|
269
292
|
error?: SerializedRouteError | null;
|
|
270
293
|
pending?: boolean;
|
|
271
294
|
}
|
|
272
|
-
interface SerializedRouteError {
|
|
273
|
-
message: string;
|
|
274
|
-
name: string;
|
|
275
|
-
status: number;
|
|
276
|
-
diagnostics?: PrachtRuntimeDiagnostics;
|
|
277
|
-
}
|
|
278
295
|
interface StartAppOptions<TData = unknown> {
|
|
279
296
|
initialData?: TData;
|
|
280
297
|
}
|
|
281
|
-
interface HandlePrachtRequestOptions<TContext = unknown> {
|
|
282
|
-
app: PrachtApp;
|
|
283
|
-
request: Request;
|
|
284
|
-
context?: TContext;
|
|
285
|
-
registry?: ModuleRegistry;
|
|
286
|
-
/** Expose raw server error details in rendered HTML and route-state JSON. */
|
|
287
|
-
debugErrors?: boolean;
|
|
288
|
-
clientEntryUrl?: string;
|
|
289
|
-
/** Per-source-file CSS map produced by the vite plugin (preferred over cssUrls). */
|
|
290
|
-
cssManifest?: Record<string, string[]>;
|
|
291
|
-
/** @deprecated Pass cssManifest instead for per-page CSS resolution. */
|
|
292
|
-
cssUrls?: string[];
|
|
293
|
-
/** Per-source-file JS chunk map produced by the vite plugin for modulepreload hints. */
|
|
294
|
-
jsManifest?: Record<string, string[]>;
|
|
295
|
-
apiRoutes?: ResolvedApiRoute[];
|
|
296
|
-
}
|
|
297
298
|
interface FormProps extends Omit<JSX.HTMLAttributes<HTMLFormElement>, "action" | "method"> {
|
|
298
299
|
action?: string;
|
|
299
300
|
method?: string;
|
|
300
301
|
}
|
|
302
|
+
interface Location {
|
|
303
|
+
pathname: string;
|
|
304
|
+
search: string;
|
|
305
|
+
}
|
|
301
306
|
declare global {
|
|
302
307
|
interface Window {
|
|
303
308
|
__PRACHT_STATE__?: PrachtHydrationState;
|
|
@@ -318,12 +323,14 @@ declare function PrachtRuntimeProvider<TData>({
|
|
|
318
323
|
data,
|
|
319
324
|
params,
|
|
320
325
|
routeId,
|
|
326
|
+
stateVersion,
|
|
321
327
|
url
|
|
322
328
|
}: {
|
|
323
329
|
children: ComponentChildren;
|
|
324
330
|
data: TData;
|
|
325
331
|
params?: RouteParams;
|
|
326
332
|
routeId: string;
|
|
333
|
+
stateVersion?: number;
|
|
327
334
|
url: string;
|
|
328
335
|
}): _$preact.VNode<_$preact.Attributes & {
|
|
329
336
|
value: PrachtRuntimeValue | undefined;
|
|
@@ -332,16 +339,12 @@ declare function PrachtRuntimeProvider<TData>({
|
|
|
332
339
|
declare function startApp<TData = unknown>(options?: StartAppOptions<TData>): TData | undefined;
|
|
333
340
|
declare function readHydrationState<TData = unknown>(): PrachtHydrationState<TData> | undefined;
|
|
334
341
|
declare function useRouteData<TData = unknown>(): TData;
|
|
335
|
-
interface Location {
|
|
336
|
-
pathname: string;
|
|
337
|
-
search: string;
|
|
338
|
-
}
|
|
339
342
|
declare function useLocation(): Location;
|
|
340
343
|
declare function useParams(): RouteParams;
|
|
341
344
|
declare function useRevalidate(): () => Promise<unknown>;
|
|
342
|
-
/** @deprecated Use useRevalidate instead. */
|
|
343
|
-
declare const useRevalidateRoute: typeof useRevalidate;
|
|
344
345
|
declare function Form(props: FormProps): _$preact.VNode<_$preact.ClassAttributes<HTMLFormElement> & h.JSX.HTMLAttributes<HTMLFormElement>>;
|
|
346
|
+
//#endregion
|
|
347
|
+
//#region src/runtime-client-fetch.d.ts
|
|
345
348
|
type RouteStateResult = {
|
|
346
349
|
type: "data";
|
|
347
350
|
data: unknown;
|
|
@@ -352,8 +355,25 @@ type RouteStateResult = {
|
|
|
352
355
|
type: "error";
|
|
353
356
|
error: SerializedRouteError;
|
|
354
357
|
};
|
|
358
|
+
//#endregion
|
|
359
|
+
//#region src/runtime.d.ts
|
|
360
|
+
interface HandlePrachtRequestOptions<TContext = unknown> {
|
|
361
|
+
app: PrachtApp;
|
|
362
|
+
request: Request;
|
|
363
|
+
context?: TContext;
|
|
364
|
+
registry?: ModuleRegistry;
|
|
365
|
+
/** Expose raw server error details in rendered HTML and route-state JSON. */
|
|
366
|
+
debugErrors?: boolean;
|
|
367
|
+
clientEntryUrl?: string;
|
|
368
|
+
/** Per-source-file CSS map produced by the vite plugin. */
|
|
369
|
+
cssManifest?: Record<string, string[]>;
|
|
370
|
+
/** Per-source-file JS chunk map produced by the vite plugin for modulepreload hints. */
|
|
371
|
+
jsManifest?: Record<string, string[]>;
|
|
372
|
+
apiRoutes?: ResolvedApiRoute[];
|
|
373
|
+
}
|
|
355
374
|
declare function handlePrachtRequest<TContext>(options: HandlePrachtRequestOptions<TContext>): Promise<Response>;
|
|
356
|
-
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/prerender.d.ts
|
|
357
377
|
interface PrerenderResult {
|
|
358
378
|
path: string;
|
|
359
379
|
html: string;
|
|
@@ -370,12 +390,10 @@ interface PrerenderAppOptions {
|
|
|
370
390
|
app: PrachtApp;
|
|
371
391
|
registry?: ModuleRegistry;
|
|
372
392
|
clientEntryUrl?: string;
|
|
373
|
-
/** Per-source-file CSS map produced by the vite plugin
|
|
393
|
+
/** Per-source-file CSS map produced by the vite plugin. */
|
|
374
394
|
cssManifest?: Record<string, string[]>;
|
|
375
395
|
/** Per-source-file JS map produced by the vite plugin for modulepreload hints. */
|
|
376
396
|
jsManifest?: Record<string, string[]>;
|
|
377
|
-
/** @deprecated Pass cssManifest instead for per-page CSS resolution. */
|
|
378
|
-
cssUrls?: string[];
|
|
379
397
|
}
|
|
380
398
|
declare function prerenderApp(options: PrerenderAppOptions): Promise<PrerenderResult[]>;
|
|
381
399
|
declare function prerenderApp(options: PrerenderAppOptions & {
|
|
@@ -389,7 +407,7 @@ declare global {
|
|
|
389
407
|
__PRACHT_ROUTER_READY__?: boolean;
|
|
390
408
|
}
|
|
391
409
|
}
|
|
392
|
-
type ModuleMap = Record<string, () => Promise<
|
|
410
|
+
type ModuleMap = Record<string, () => Promise<unknown>>;
|
|
393
411
|
type NavigateFn = (to: string, options?: {
|
|
394
412
|
replace?: boolean;
|
|
395
413
|
}) => Promise<void>;
|
|
@@ -404,4 +422,4 @@ interface InitClientRouterOptions {
|
|
|
404
422
|
}
|
|
405
423
|
declare function initClientRouter(options: InitClientRouterOptions): Promise<void>;
|
|
406
424
|
//#endregion
|
|
407
|
-
export { type ApiConfig, type ApiRouteArgs, type ApiRouteHandler, type ApiRouteMatch, type ApiRouteModule, type BaseRouteArgs, type DataModule, type ErrorBoundaryProps, Form, type FormProps, type GroupDefinition, type GroupMeta, type HandlePrachtRequestOptions, type HeadArgs, type HeadMetadata, type HeadersArgs, type HttpMethod, type ISGManifestEntry, type InitClientRouterOptions, type LoaderArgs, type LoaderData, type LoaderFn, type Location, type MiddlewareArgs, type MiddlewareFn, type MiddlewareModule, type MiddlewareResult, type ModuleImporter, type ModuleRef, type ModuleRegistry, type NavigateFn, type PrachtApp, type PrachtAppConfig, PrachtHttpError, type PrachtHydrationState, type PrachtRuntimeDiagnosticPhase, type PrachtRuntimeDiagnostics, PrachtRuntimeProvider, type PrefetchStrategy, type PrerenderAppOptions, type PrerenderAppResult, type PrerenderResult, type Register, type RenderMode, type ResolvedApiRoute, type ResolvedPrachtApp, type ResolvedRoute, type RouteComponentProps, type RouteConfig, type RouteDefinition, type RouteMatch, type RouteMeta, type RouteModule, type RouteParams, type RouteRevalidate, type RouteStateResult, type RouteTreeNode, type SerializedRouteError, type ShellModule, type ShellProps, type StartAppOptions, Suspense, type TimeRevalidatePolicy, applyDefaultSecurityHeaders, buildPathFromSegments, defineApp, forwardRef, group, handlePrachtRequest, initClientRouter, lazy, matchApiRoute, matchAppRoute, prerenderApp, readHydrationState, resolveApiRoutes, resolveApp, route, startApp, timeRevalidate, useIsHydrated, useLocation, useNavigate, useParams, useRevalidate,
|
|
425
|
+
export { type ApiConfig, type ApiRouteArgs, type ApiRouteHandler, type ApiRouteMatch, type ApiRouteModule, type BaseRouteArgs, type DataModule, type ErrorBoundaryProps, Form, type FormProps, type GroupDefinition, type GroupMeta, type HandlePrachtRequestOptions, type HeadArgs, type HeadMetadata, type HeadersArgs, type HttpMethod, type ISGManifestEntry, type InitClientRouterOptions, type LoaderArgs, type LoaderData, type LoaderFn, type Location, type MiddlewareArgs, type MiddlewareFn, type MiddlewareModule, type MiddlewareResult, type ModuleImporter, type ModuleRef, type ModuleRegistry, type NavigateFn, type PrachtApp, type PrachtAppConfig, PrachtHttpError, type PrachtHydrationState, type PrachtRuntimeDiagnosticPhase, type PrachtRuntimeDiagnostics, PrachtRuntimeProvider, type PrefetchStrategy, type PrerenderAppOptions, type PrerenderAppResult, type PrerenderResult, type Register, type RenderMode, type ResolvedApiRoute, type ResolvedPrachtApp, type ResolvedRoute, type RouteComponentProps, type RouteConfig, type RouteDefinition, type RouteMatch, type RouteMeta, type RouteModule, type RouteParams, type RouteRevalidate, type RouteStateResult, type RouteTreeNode, type SerializedRouteError, type ShellModule, type ShellProps, type StartAppOptions, Suspense, type TimeRevalidatePolicy, applyDefaultSecurityHeaders, buildPathFromSegments, defineApp, forwardRef, group, handlePrachtRequest, initClientRouter, lazy, matchApiRoute, matchAppRoute, prerenderApp, readHydrationState, resolveApiRoutes, resolveApp, route, startApp, timeRevalidate, useIsHydrated, useLocation, useNavigate, useParams, useRevalidate, useRouteData };
|