@jk2908/solas 0.5.4 → 0.7.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 (75) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +34 -94
  3. package/dist/config.d.ts +24 -0
  4. package/dist/config.js +143 -0
  5. package/dist/events.d.ts +4 -0
  6. package/dist/events.js +5 -0
  7. package/dist/index.d.ts +1 -2
  8. package/dist/index.js +59 -41
  9. package/dist/internal/boundary-error.d.ts +4 -0
  10. package/dist/internal/boundary-error.js +8 -0
  11. package/dist/internal/browser-router/history.d.ts +1 -1
  12. package/dist/internal/browser-router/link.d.ts +1 -1
  13. package/dist/internal/browser-router/link.js +1 -1
  14. package/dist/internal/browser-router/router.d.ts +2 -2
  15. package/dist/internal/browser-router/router.js +5 -5
  16. package/dist/internal/browser-router/shared.d.ts +182 -184
  17. package/dist/internal/browser-router/shared.js +49 -56
  18. package/dist/internal/browser-router/use-router.d.ts +1 -1
  19. package/dist/internal/browser-router/use-search-params.js +3 -3
  20. package/dist/internal/build.d.ts +108 -110
  21. package/dist/internal/build.js +569 -581
  22. package/dist/internal/codegen/config.js +4 -5
  23. package/dist/internal/codegen/environments.d.ts +1 -1
  24. package/dist/internal/codegen/environments.js +6 -9
  25. package/dist/internal/codegen/format.d.ts +6 -0
  26. package/dist/internal/codegen/format.js +24 -0
  27. package/dist/internal/codegen/manifest.js +2 -2
  28. package/dist/internal/codegen/maps.d.ts +1 -1
  29. package/dist/internal/codegen/maps.js +2 -2
  30. package/dist/internal/codegen/types.js +4 -4
  31. package/dist/internal/codegen/utils.js +2 -2
  32. package/dist/internal/env/request-context.js +1 -1
  33. package/dist/internal/env/rsc.d.ts +3 -3
  34. package/dist/internal/env/rsc.js +26 -26
  35. package/dist/internal/env/ssr.js +4 -4
  36. package/dist/internal/http-router/router.js +8 -8
  37. package/dist/internal/metadata.d.ts +1 -1
  38. package/dist/internal/metadata.js +1 -1
  39. package/dist/internal/navigation/http-exception-boundary.d.ts +1 -1
  40. package/dist/internal/navigation/redirect-boundary.d.ts +1 -1
  41. package/dist/internal/navigation/redirect.js +6 -6
  42. package/dist/internal/postbuild.js +18 -17
  43. package/dist/internal/prerender.d.ts +130 -138
  44. package/dist/internal/prerender.js +326 -354
  45. package/dist/internal/public-files.js +2 -4
  46. package/dist/internal/render/head.js +2 -2
  47. package/dist/internal/resolver.js +1 -1
  48. package/dist/internal/runtimes/runtime.d.ts +7 -21
  49. package/dist/internal/runtimes/runtime.js +24 -19
  50. package/dist/internal/server/actions.js +2 -2
  51. package/dist/internal/ui/error-boundary.d.ts +1 -1
  52. package/dist/manifest.d.ts +7 -0
  53. package/dist/manifest.js +85 -0
  54. package/dist/prerender.d.ts +1 -1
  55. package/dist/prerender.js +1 -1
  56. package/dist/solas.d.ts +2 -46
  57. package/dist/solas.js +6 -266
  58. package/dist/types.d.ts +14 -25
  59. package/dist/types.js +1 -1
  60. package/dist/utils/base-path.d.ts +12 -14
  61. package/dist/utils/base-path.js +75 -82
  62. package/dist/utils/compress.d.ts +9 -11
  63. package/dist/utils/compress.js +59 -64
  64. package/dist/utils/context.d.ts +4 -6
  65. package/dist/utils/context.js +17 -22
  66. package/dist/utils/logger.js +2 -2
  67. package/dist/utils/time.d.ts +2 -4
  68. package/dist/utils/time.js +23 -29
  69. package/package.json +18 -8
  70. package/dist/internal/runtimes/bun.d.ts +0 -9
  71. package/dist/internal/runtimes/bun.js +0 -33
  72. package/dist/internal/runtimes/create.d.ts +0 -4
  73. package/dist/internal/runtimes/create.js +0 -9
  74. package/dist/internal/runtimes/node.d.ts +0 -9
  75. package/dist/internal/runtimes/node.js +0 -31
@@ -1,140 +1,132 @@
1
1
  import type { BuildContext } from '../types.js';
2
- export declare namespace Prerender {
3
- namespace Artifact {
4
- type Mode = 'full' | 'ppr';
5
- type File = 'html' | 'prelude' | 'postponed' | 'metadata';
6
- type Value = {
7
- schema: string;
8
- route: string;
9
- createdAt: number;
10
- mode: Mode;
11
- html: string;
12
- postponed?: unknown;
13
- };
14
- type Metadata = Pick<Value, 'schema' | 'route' | 'createdAt' | 'mode'>;
15
- type ManifestEntry = {
16
- mode: Mode;
17
- files?: readonly File[];
18
- };
19
- type Manifest = Record<string, ManifestEntry>;
20
- /**
21
- * Get the root directory path where prerender artifacts are stored,
22
- * based on the output directory specified in the configuration
23
- */
24
- function getRootPath(outDir: string): string;
25
- /**
26
- * Get the file system path for storing prerender artifacts for a given route
27
- */
28
- function getPath(outDir: string, pathname: string): string;
29
- /**
30
- * Get the file system path for a single prerender artifact file under a route directory
31
- */
32
- function getFilePath(outDir: string, pathname: string, fileName: string): string;
33
- /**
34
- * File name used for saved full-prerender html inside each route artifact directory
35
- */
36
- const FULL_PRERENDER_FILENAME = "prerendered.html";
37
- /**
38
- * Load the postponed state for a given route from the file system, if it exists
39
- */
40
- function loadPostponedState(outDir: string, pathname: string): Promise<any>;
41
- /**
42
- * Load the prelude HTML for a given route from the file system, if it exists
43
- */
44
- function loadPrelude(outDir: string, pathname: string): Promise<string | null>;
45
- /**
46
- * Load the prerender artifact metadata for a given route from the file system, if it exists and is valid
47
- */
48
- function loadMetadata(outDir: string, pathname: string): Promise<{
49
- schema: string;
50
- route: string;
51
- createdAt: number;
52
- mode: "full" | "ppr";
53
- } | null>;
54
- /**
55
- * Check if a prerender artifact is compatible with the current application version and route,
56
- * based on its metadata
57
- */
58
- function isCompatible(artifactMetadata: Metadata, pathname: string, mode: Mode): boolean;
59
- /**
60
- * Compose the prelude HTML and the resume stream into a single HTML stream, by injecting the resume stream
61
- * into the prelude at the appropriate location (before </body> or </html>)
62
- */
63
- function composePreludeAndResume(prelude: string, resumeStream: ReadableStream<Uint8Array>): ReadableStream<Uint8Array<ArrayBufferLike>>;
64
- }
65
- type Result = {
66
- route: string;
67
- artifact: Artifact.Value;
68
- } | {
69
- route: string;
70
- status: number;
71
- } | {
72
- route: string;
73
- error: unknown;
74
- };
75
- namespace Runtime {
76
- /**
77
- * Custom error class to indicate that prerendering has been postponed to request-time
78
- */
79
- class Postponed extends Error {
80
- constructor(message?: string);
81
- }
82
- /**
83
- * Type guard to check if an error is a Postponed error, including wrapped errors like
84
- * AbortError or TimeoutError
85
- */
86
- function isPostponed(error: unknown): boolean;
87
- }
88
- namespace Build {
89
- /**
90
- * Get the prerender concurrency value from the environment variable, or return the default
91
- * if it's not set or invalid
92
- */
93
- function getConcurrency(): number;
94
- /**
95
- * Extract the prerendering mode ('full', 'ppr', or false) from the source code of a route module, by
96
- * looking for an exported `prerender` binding and validating its value
97
- */
98
- function getStaticFlag(filePath: string, buildContext: BuildContext): Promise<"full" | "ppr" | false | undefined>;
99
- /**
100
- * Get the list of static parameters for a dynamic route, by looking for an exported `params` function
101
- * in the route module and calling it to get the list of parameter objects
102
- */
103
- function getStaticParams(filePath: string, buildContext: BuildContext): Promise<Record<string, string | number | (string | number)[]>[]>;
104
- /**
105
- * Generate the list of prerenderable routes for a dynamic route, by combining the static parameters obtained from
106
- * the route module with the route pattern, and filtering out any routes that still contain dynamic segments
107
- */
108
- function getDynamicRouteList(route: string, paramNames: string[], staticParams: Record<string, string | number | (string | number)[]>[]): string[];
109
- /**
110
- * Function to prerender a single route by making a request to the route with special headers, and returning the
111
- * result which includes either the prerender artifact or an error/status code if the prerendering failed or was
112
- * postponed to request-time
113
- */
114
- function get(app: {
115
- fetch: (req: Request) => Promise<Response>;
116
- }, route: string, opts: {
117
- origin?: string;
118
- base?: string;
119
- }): Promise<{
120
- route: string;
121
- status: number;
122
- artifact?: undefined;
123
- } | {
124
- status?: undefined;
125
- route: string;
126
- artifact: any;
127
- }>;
128
- /**
129
- * Run the prerendering process for a list of routes with a specified concurrency limit,
130
- * by calling the 'get' function for each route and yielding the results as they become available
131
- */
132
- function run(app: {
133
- fetch: (req: Request) => Promise<Response>;
134
- }, routes: string[], opts: {
135
- concurrency?: number;
136
- origin?: string;
137
- base?: string;
138
- }): AsyncGenerator<Result, void, unknown>;
139
- }
2
+ export type Mode = 'full' | 'ppr';
3
+ export type File = 'html' | 'prelude' | 'postponed' | 'metadata';
4
+ export type Value = {
5
+ schema: string;
6
+ route: string;
7
+ createdAt: number;
8
+ mode: Mode;
9
+ html: string;
10
+ postponed?: unknown;
11
+ };
12
+ export type Metadata = Pick<Value, 'schema' | 'route' | 'createdAt' | 'mode'>;
13
+ export type Artifact = {
14
+ mode: Mode;
15
+ files?: readonly File[];
16
+ };
17
+ export type ArtifactManifest = Record<string, Artifact>;
18
+ /**
19
+ * Get the root directory path where prerender artifacts are stored,
20
+ * based on the output directory specified in the configuration
21
+ */
22
+ export declare function getArtifactRootPath(outDir: string): string;
23
+ /**
24
+ * Get the file system path for storing prerender artifacts for a given route
25
+ */
26
+ export declare function getArtifactPath(outDir: string, pathname: string): string;
27
+ /**
28
+ * Get the file system path for a single prerender artifact file under a route directory
29
+ */
30
+ export declare function getArtifactFilePath(outDir: string, pathname: string, fileName: string): string;
31
+ /**
32
+ * File name used for saved full-prerender html inside each route artifact directory
33
+ */
34
+ export declare const FULL_PRERENDER_FILENAME = "prerendered.html";
35
+ /**
36
+ * Load the postponed state for a given route from the file system, if it exists
37
+ */
38
+ export declare function loadPostponedState(outDir: string, pathname: string): Promise<any>;
39
+ /**
40
+ * Load the prelude HTML for a given route from the file system, if it exists
41
+ */
42
+ export declare function loadPrelude(outDir: string, pathname: string): Promise<string | null>;
43
+ /**
44
+ * Load the prerender artifact metadata for a given route from the file system, if it exists and is valid
45
+ */
46
+ export declare function loadMetadata(outDir: string, pathname: string): Promise<{
47
+ schema: string;
48
+ route: string;
49
+ createdAt: number;
50
+ mode: "full" | "ppr";
51
+ } | null>;
52
+ /**
53
+ * Check if a prerender artifact is compatible with the current application version and route,
54
+ * based on its metadata
55
+ */
56
+ export declare function isCompatible(artifactMetadata: Metadata, pathname: string, mode: Mode): boolean;
57
+ /**
58
+ * Compose the prelude HTML and the resume stream into a single HTML stream, by injecting the resume stream
59
+ * into the prelude at the appropriate location (before </body> or </html>)
60
+ */
61
+ export declare function composePreludeAndResume(prelude: string, resumeStream: ReadableStream<Uint8Array>): ReadableStream<Uint8Array<ArrayBufferLike>>;
62
+ export type Result = {
63
+ route: string;
64
+ artifact: Value;
65
+ } | {
66
+ route: string;
67
+ status: number;
68
+ } | {
69
+ route: string;
70
+ error: unknown;
71
+ };
72
+ /**
73
+ * Custom error class to indicate that prerendering has been postponed to request-time
74
+ */
75
+ export declare class Postponed extends Error {
76
+ constructor(message?: string);
140
77
  }
78
+ /**
79
+ * Type guard to check if an error is a Postponed error, including wrapped errors like
80
+ * AbortError or TimeoutError
81
+ */
82
+ export declare function isPostponed(error: unknown): boolean;
83
+ /**
84
+ * Get the prerender concurrency value from the environment variable, or return the default
85
+ * if it's not set or invalid
86
+ */
87
+ export declare function getConcurrency(): number;
88
+ /**
89
+ * Extract the prerendering mode ('full', 'ppr', or false) from the source code of a route module, by
90
+ * looking for an exported `prerender` binding and validating its value
91
+ */
92
+ export declare function getStaticFlag(filePath: string, buildContext: BuildContext): Promise<"full" | "ppr" | false | undefined>;
93
+ /**
94
+ * Get the list of static parameters for a dynamic route, by looking for an exported `params` function
95
+ * in the route module and calling it to get the list of parameter objects
96
+ */
97
+ export declare function getStaticParams(filePath: string, buildContext: BuildContext): Promise<Record<string, string | number | (string | number)[]>[]>;
98
+ /**
99
+ * Generate the list of prerenderable routes for a dynamic route, by combining the static parameters obtained from
100
+ * the route module with the route pattern, and filtering out any routes that still contain dynamic segments
101
+ */
102
+ export declare function getDynamicRouteList(route: string, paramNames: string[], staticParams: Record<string, string | number | (string | number)[]>[]): string[];
103
+ /**
104
+ * Function to prerender a single route by making a request to the route with special headers, and returning the
105
+ * result which includes either the prerender artifact or an error/status code if the prerendering failed or was
106
+ * postponed to request-time
107
+ */
108
+ export declare function get(app: {
109
+ fetch: (req: Request) => Promise<Response>;
110
+ }, route: string, opts: {
111
+ origin?: string;
112
+ base?: string;
113
+ }): Promise<{
114
+ route: string;
115
+ status: number;
116
+ artifact?: undefined;
117
+ } | {
118
+ status?: undefined;
119
+ route: string;
120
+ artifact: any;
121
+ }>;
122
+ /**
123
+ * Run the prerendering process for a list of routes with a specified concurrency limit,
124
+ * by calling the 'get' function for each route and yielding the results as they become available
125
+ */
126
+ export declare function run(app: {
127
+ fetch: (req: Request) => Promise<Response>;
128
+ }, routes: string[], opts: {
129
+ concurrency?: number;
130
+ origin?: string;
131
+ base?: string;
132
+ }): AsyncGenerator<Result, void, unknown>;