@holo-js/adapter-next 0.5.0 → 0.5.1
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/dist/.holo-build-fingerprint +1 -1
- package/dist/chunk-2JUQOM3L.mjs +17 -0
- package/dist/chunk-7LOU63WN.mjs +49 -0
- package/dist/chunk-RFEFJPTI.mjs +13 -0
- package/dist/chunk-ZPWXXNMV.mjs +13 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.mjs +3 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.mjs +12 -2
- package/dist/internal/validation-errors.d.ts +10 -0
- package/dist/internal/validation-errors.mjs +68 -0
- package/dist/internal/validation-layout.d.ts +8 -0
- package/dist/internal/validation-layout.mjs +21 -0
- package/dist/layout-loader.d.ts +17 -0
- package/dist/layout-loader.mjs +69 -0
- package/dist/module-transform-loader-B5slbWAk.d.ts +9 -0
- package/dist/route-loader.d.ts +4 -4
- package/dist/route-loader.mjs +7 -4
- package/dist/runtime.d.ts +2 -1
- package/dist/runtime.mjs +77 -20
- package/dist/server-action-loader.d.ts +4 -4
- package/dist/server-action-loader.mjs +7 -4
- package/package.json +18 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
91408e43a7af3f232c577938b298cf69b2340d4057f754907fd4d2058e258f7b
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/app-layout-files.ts
|
|
2
|
+
var DEFAULT_PAGE_EXTENSIONS = ["tsx", "ts", "jsx", "js"];
|
|
3
|
+
function extensionsPattern(pageExtensions) {
|
|
4
|
+
return pageExtensions.map((extension) => extension.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
|
|
5
|
+
}
|
|
6
|
+
function layoutFileNamePattern(pageExtensions) {
|
|
7
|
+
return new RegExp(`^layout\\.(?:${extensionsPattern(pageExtensions)})$`);
|
|
8
|
+
}
|
|
9
|
+
function appLayoutPathPattern(pageExtensions) {
|
|
10
|
+
return new RegExp(`(?:^|[\\\\/])app[\\\\/](?:.*[\\\\/])?layout\\.(?:${extensionsPattern(pageExtensions)})$`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
DEFAULT_PAGE_EXTENSIONS,
|
|
15
|
+
layoutFileNamePattern,
|
|
16
|
+
appLayoutPathPattern
|
|
17
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/validation-flash.ts
|
|
2
|
+
var VALIDATION_FLASH_COOKIE = "holo_form_failure";
|
|
3
|
+
var MAX_FLASH_COOKIE_BYTES = 3800;
|
|
4
|
+
function isMessages(value) {
|
|
5
|
+
return Array.isArray(value) && value.every((message) => typeof message === "string");
|
|
6
|
+
}
|
|
7
|
+
function isErrors(value) {
|
|
8
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.values(value).every(isMessages);
|
|
9
|
+
}
|
|
10
|
+
function parseValidationFlash(value) {
|
|
11
|
+
if (!value) return void 0;
|
|
12
|
+
try {
|
|
13
|
+
const flash = JSON.parse(value);
|
|
14
|
+
if (typeof flash !== "object" || flash === null) return void 0;
|
|
15
|
+
const { bag, page, errors } = flash;
|
|
16
|
+
return typeof bag === "string" && typeof page === "string" && isErrors(errors) ? { bag, page, errors } : void 0;
|
|
17
|
+
} catch {
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function validationFlashPage(pathname) {
|
|
22
|
+
let hash = 2166136261;
|
|
23
|
+
for (const character of pathname) {
|
|
24
|
+
hash = Math.imul(hash ^ (character.codePointAt(0) ?? 0), 16777619);
|
|
25
|
+
}
|
|
26
|
+
return (hash >>> 0).toString(36);
|
|
27
|
+
}
|
|
28
|
+
function fitsInCookie(flash) {
|
|
29
|
+
return encodeURIComponent(JSON.stringify(flash)).length <= MAX_FLASH_COOKIE_BYTES;
|
|
30
|
+
}
|
|
31
|
+
function firstMessages(errors) {
|
|
32
|
+
return Object.fromEntries(Object.entries(errors).map(([path, messages]) => [path, messages.slice(0, 1)]));
|
|
33
|
+
}
|
|
34
|
+
function serializeValidationFlash(flash) {
|
|
35
|
+
if (fitsInCookie(flash)) return JSON.stringify(flash);
|
|
36
|
+
if (!fitsInCookie({ ...flash, errors: {} })) return void 0;
|
|
37
|
+
const errors = {};
|
|
38
|
+
for (const [path, messages] of Object.entries(firstMessages(flash.errors))) {
|
|
39
|
+
if (fitsInCookie({ ...flash, errors: { ...errors, [path]: messages } })) errors[path] = messages;
|
|
40
|
+
}
|
|
41
|
+
return JSON.stringify({ ...flash, errors });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
VALIDATION_FLASH_COOKIE,
|
|
46
|
+
parseValidationFlash,
|
|
47
|
+
validationFlashPage,
|
|
48
|
+
serializeValidationFlash
|
|
49
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/module-transform-loader.ts
|
|
2
|
+
function runModuleTransform(context, transform, source, incomingMap) {
|
|
3
|
+
context.cacheable?.();
|
|
4
|
+
const inputMap = incomingMap ?? void 0;
|
|
5
|
+
const result = transform(source, context.resourcePath, inputMap);
|
|
6
|
+
if (!context.callback) return result?.code ?? source;
|
|
7
|
+
context.callback(null, result?.code ?? source, result?.map ?? inputMap);
|
|
8
|
+
return void 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
runModuleTransform
|
|
13
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/rendered-validation-flash.ts
|
|
2
|
+
var renderedValidationFlashes = globalThis.__holoNextRenderedValidationFlashes ??= /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function rememberRenderedValidationFlash(request, flash) {
|
|
4
|
+
renderedValidationFlashes.set(request, flash);
|
|
5
|
+
}
|
|
6
|
+
function renderedValidationFlash(request) {
|
|
7
|
+
return request ? renderedValidationFlashes.get(request) : void 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
rememberRenderedValidationFlash,
|
|
12
|
+
renderedValidationFlash
|
|
13
|
+
};
|
package/dist/client.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { InferFormData } from '@holo-js/forms';
|
|
|
2
2
|
import { ValidationSchema } from '@holo-js/validation';
|
|
3
3
|
import { UseFormOptions, ClientSubmitContext, ClientSubmitResult, UseFormResult, InferFormFieldTree } from '@holo-js/forms/internal/client';
|
|
4
4
|
export { ClientCsrfOptions, ClientSubmitContext, ClientSubmitResult, FormFieldState, FormFieldTree, FormRequestCredentials, UseFormOptions, UseFormResult, ValidateOnMode } from '@holo-js/forms/internal/client';
|
|
5
|
+
export { useValidationErrors } from '@holo-js/adapter-next/internal/validation-errors';
|
|
5
6
|
|
|
6
7
|
declare function isNextRedirectError(error: unknown): boolean;
|
|
7
8
|
declare function createSubmitterBridge<TData, TSuccess>(optionsRef: {
|
package/dist/client.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
createFormClient,
|
|
12
12
|
markClientSubmitControlFlowError
|
|
13
13
|
} from "@holo-js/forms/internal/client";
|
|
14
|
+
import { useValidationErrors } from "@holo-js/adapter-next/internal/validation-errors";
|
|
14
15
|
function isPlainObject(value) {
|
|
15
16
|
return !!value && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !(value instanceof Blob);
|
|
16
17
|
}
|
|
@@ -104,5 +105,6 @@ var adapterNextClientInternals = {
|
|
|
104
105
|
};
|
|
105
106
|
export {
|
|
106
107
|
adapterNextClientInternals,
|
|
107
|
-
useForm
|
|
108
|
+
useForm,
|
|
109
|
+
useValidationErrors
|
|
108
110
|
};
|
package/dist/config.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ interface NextConfig {
|
|
|
14
14
|
readonly outputFileTracingExcludes?: Record<string, string[]>;
|
|
15
15
|
readonly outputFileTracingRoot?: string;
|
|
16
16
|
readonly experimental?: Record<string, unknown>;
|
|
17
|
+
readonly pageExtensions?: readonly string[];
|
|
17
18
|
readonly turbopack?: TurbopackConfig;
|
|
18
19
|
readonly rewrites?: () => Promise<unknown>;
|
|
19
20
|
readonly webpack?: (config: WebpackConfig, context: WebpackConfigContext) => WebpackConfig;
|
package/dist/config.mjs
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_PAGE_EXTENSIONS,
|
|
3
|
+
appLayoutPathPattern
|
|
4
|
+
} from "./chunk-2JUQOM3L.mjs";
|
|
5
|
+
|
|
1
6
|
// src/config.ts
|
|
2
7
|
import { assertRealtimeDefinitionTree, resolveRealtimeDefinitionDirectories } from "@holo-js/adapter-shared/realtime-directories";
|
|
3
8
|
import { existsSync, readFileSync, realpathSync } from "fs";
|
|
@@ -210,6 +215,9 @@ function withHolo(nextConfig = {}) {
|
|
|
210
215
|
const validationLoader = fileURLToPath(new URL("./validation-loader.mjs", import.meta.url));
|
|
211
216
|
const routeLoader = fileURLToPath(new URL("./route-loader.mjs", import.meta.url));
|
|
212
217
|
const serverActionLoader = fileURLToPath(new URL("./server-action-loader.mjs", import.meta.url));
|
|
218
|
+
const pageExtensions = nextConfig.pageExtensions ?? DEFAULT_PAGE_EXTENSIONS;
|
|
219
|
+
const appLayoutFile = appLayoutPathPattern(pageExtensions);
|
|
220
|
+
const layoutLoader = fileURLToPath(new URL("./layout-loader.mjs", import.meta.url));
|
|
213
221
|
const realtimeDefinitionLoader = fileURLToPath(new URL("./realtime-definition-loader.mjs", import.meta.url));
|
|
214
222
|
const realtimeDirectoryPatterns = hasRealtime ? resolveRealtimeDefinitionPatterns(nextConfig, process.cwd()) : { absolute: [], turbopackRelative: [] };
|
|
215
223
|
const mergedTurbopack = {
|
|
@@ -220,7 +228,8 @@ function withHolo(nextConfig = {}) {
|
|
|
220
228
|
...existingTurbopack.rules?.["*"] ? [existingTurbopack.rules["*"]].flat() : [],
|
|
221
229
|
{ condition: { all: ["browser", { not: "foreign" }, { path: /\.[cm]?[jt]sx?$/ }] }, loaders: [validationLoader] },
|
|
222
230
|
{ condition: { all: [{ not: "browser" }, { not: "foreign" }, { path: /(?:^|[\\/])app[\\/].*[\\/]route\.[cm]?[jt]s$/ }] }, loaders: [routeLoader] },
|
|
223
|
-
{ condition: { all: [{ not: "browser" }, { not: "foreign" }, { path: /\.[cm]?[jt]sx?$/ }, { content: USE_SERVER_DIRECTIVE }] }, loaders: [serverActionLoader] }
|
|
231
|
+
{ condition: { all: [{ not: "browser" }, { not: "foreign" }, { path: /\.[cm]?[jt]sx?$/ }, { content: USE_SERVER_DIRECTIVE }] }, loaders: [serverActionLoader] },
|
|
232
|
+
{ condition: { all: [{ not: "browser" }, { not: "foreign" }, { path: appLayoutFile }] }, loaders: [{ loader: layoutLoader, options: { pageExtensions, bundler: "turbopack" } }] }
|
|
224
233
|
],
|
|
225
234
|
...hasRealtime ? {
|
|
226
235
|
"*.{ts,tsx,js,jsx,mts,mjs,cts,cjs}": [
|
|
@@ -269,7 +278,8 @@ function withHolo(nextConfig = {}) {
|
|
|
269
278
|
...hasRealtime ? [createRealtimeDefinitionWebpackRule(realtimeDefinitionLoader, context.isServer, realtimeDirectoryPatterns.absolute)] : [],
|
|
270
279
|
...!context.isServer ? [{ test: /\.[cm]?[jt]sx?$/, exclude: /node_modules/, use: [{ loader: validationLoader }] }] : [],
|
|
271
280
|
...context.isServer ? [{ test: /[\\/]app[\\/].*[\\/]route\.[cm]?[jt]s$/, exclude: /node_modules/, use: [{ loader: routeLoader }] }] : [],
|
|
272
|
-
...context.isServer ? [{ test: /\.[cm]?[jt]sx?$/, exclude: /node_modules/, use: [{ loader: serverActionLoader }] }] : []
|
|
281
|
+
...context.isServer ? [{ test: /\.[cm]?[jt]sx?$/, exclude: /node_modules/, use: [{ loader: serverActionLoader }] }] : [],
|
|
282
|
+
...context.isServer ? [{ test: appLayoutFile, issuerLayer: "rsc", exclude: /node_modules/, use: [{ loader: layoutLoader, options: { pageExtensions, bundler: "webpack" } }] }] : []
|
|
273
283
|
];
|
|
274
284
|
return nextWebpackConfig;
|
|
275
285
|
},
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { ValidationErrorBag } from '@holo-js/validation';
|
|
3
|
+
|
|
4
|
+
declare function HoloValidationErrorsProvider({ initial, children }: {
|
|
5
|
+
readonly initial?: string;
|
|
6
|
+
readonly children?: ReactNode;
|
|
7
|
+
}): ReactNode;
|
|
8
|
+
declare function useValidationErrors<TData = Record<string, unknown>>(bag?: string): ValidationErrorBag<TData>;
|
|
9
|
+
|
|
10
|
+
export { HoloValidationErrorsProvider, useValidationErrors };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
VALIDATION_FLASH_COOKIE,
|
|
4
|
+
parseValidationFlash,
|
|
5
|
+
validationFlashPage
|
|
6
|
+
} from "../chunk-7LOU63WN.mjs";
|
|
7
|
+
|
|
8
|
+
// src/validation-errors.ts
|
|
9
|
+
import { createContext, createElement, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
10
|
+
import { usePathname } from "next/navigation.js";
|
|
11
|
+
import { DEFAULT_VALIDATION_BAG, createErrorBag } from "@holo-js/validation";
|
|
12
|
+
var ValidationFlashContext = createContext(void 0);
|
|
13
|
+
function browserDocument() {
|
|
14
|
+
return globalThis.document;
|
|
15
|
+
}
|
|
16
|
+
function readFlashCookie() {
|
|
17
|
+
const prefix = `${VALIDATION_FLASH_COOKIE}=`;
|
|
18
|
+
const cookie = browserDocument()?.cookie.split(";").map((part) => part.trim()).find((part) => part.startsWith(prefix));
|
|
19
|
+
if (!cookie) return "";
|
|
20
|
+
try {
|
|
21
|
+
return decodeURIComponent(cookie.slice(prefix.length));
|
|
22
|
+
} catch {
|
|
23
|
+
return "";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function readableValidationFlash(value) {
|
|
27
|
+
const flash = parseValidationFlash(value);
|
|
28
|
+
if (!flash) return void 0;
|
|
29
|
+
try {
|
|
30
|
+
createErrorBag(flash.errors);
|
|
31
|
+
return flash;
|
|
32
|
+
} catch {
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function clearFlashCookie() {
|
|
37
|
+
const document = browserDocument();
|
|
38
|
+
if (document) document.cookie = `${VALIDATION_FLASH_COOKIE}=; Max-Age=0; Path=/; SameSite=Lax`;
|
|
39
|
+
}
|
|
40
|
+
function HoloValidationErrorsProvider({ initial = "", children }) {
|
|
41
|
+
const pathname = usePathname();
|
|
42
|
+
const [flash, setFlash] = useState(initial);
|
|
43
|
+
const mounted = useRef(false);
|
|
44
|
+
const shownPath = useRef(pathname);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!mounted.current) {
|
|
47
|
+
mounted.current = true;
|
|
48
|
+
if (!initial) clearFlashCookie();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (shownPath.current !== pathname) {
|
|
52
|
+
shownPath.current = pathname;
|
|
53
|
+
clearFlashCookie();
|
|
54
|
+
}
|
|
55
|
+
setFlash(readFlashCookie());
|
|
56
|
+
});
|
|
57
|
+
const value = useMemo(() => readableValidationFlash(flash), [flash]);
|
|
58
|
+
return createElement(ValidationFlashContext.Provider, { value }, children);
|
|
59
|
+
}
|
|
60
|
+
function useValidationErrors(bag = DEFAULT_VALIDATION_BAG) {
|
|
61
|
+
const flash = useContext(ValidationFlashContext);
|
|
62
|
+
const pathname = usePathname();
|
|
63
|
+
return createErrorBag(flash?.bag === bag && flash.page === validationFlashPage(pathname) ? flash.errors : {});
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
HoloValidationErrorsProvider,
|
|
67
|
+
useValidationErrors
|
|
68
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReactNode, ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
declare function validationErrorsLayout<TProps extends object>(layout: (props: TProps) => ReactNode | Promise<ReactNode>): (props: TProps) => ReactElement;
|
|
4
|
+
declare const adapterNextLayoutInternals: {
|
|
5
|
+
validationErrorsLayout: typeof validationErrorsLayout;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { adapterNextLayoutInternals };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
renderedValidationFlash
|
|
3
|
+
} from "../chunk-ZPWXXNMV.mjs";
|
|
4
|
+
|
|
5
|
+
// src/validation-layout.ts
|
|
6
|
+
import { createElement } from "react";
|
|
7
|
+
import { workUnitAsyncStorage } from "next/dist/server/app-render/work-unit-async-storage.external.js";
|
|
8
|
+
import { HoloValidationErrorsProvider } from "@holo-js/adapter-next/internal/validation-errors";
|
|
9
|
+
function validationErrorsLayout(layout) {
|
|
10
|
+
return (props) => createElement(
|
|
11
|
+
HoloValidationErrorsProvider,
|
|
12
|
+
{ initial: renderedValidationFlash(workUnitAsyncStorage.getStore()) },
|
|
13
|
+
createElement(layout, props)
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
var adapterNextLayoutInternals = {
|
|
17
|
+
validationErrorsLayout
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
adapterNextLayoutInternals
|
|
21
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { NextModuleInputSourceMap } from '@holo-js/adapter-shared/build';
|
|
2
|
+
import { M as ModuleTransformLoaderContext } from './module-transform-loader-B5slbWAk.js';
|
|
3
|
+
|
|
4
|
+
type NextBundler = 'turbopack' | 'webpack';
|
|
5
|
+
type LayoutLoaderContext = ModuleTransformLoaderContext & {
|
|
6
|
+
readonly resourceQuery?: string;
|
|
7
|
+
readonly rootContext?: string;
|
|
8
|
+
addDependency?(file: string): void;
|
|
9
|
+
addMissingDependency?(file: string): void;
|
|
10
|
+
getOptions?(): {
|
|
11
|
+
readonly pageExtensions?: readonly string[];
|
|
12
|
+
readonly bundler?: NextBundler;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
declare function layoutLoader(this: LayoutLoaderContext, source: string, inputMap?: NextModuleInputSourceMap | null): string | undefined;
|
|
16
|
+
|
|
17
|
+
export { layoutLoader as default };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_PAGE_EXTENSIONS,
|
|
3
|
+
layoutFileNamePattern
|
|
4
|
+
} from "./chunk-2JUQOM3L.mjs";
|
|
5
|
+
import {
|
|
6
|
+
runModuleTransform
|
|
7
|
+
} from "./chunk-RFEFJPTI.mjs";
|
|
8
|
+
|
|
9
|
+
// src/layout-loader.ts
|
|
10
|
+
import { createHash } from "crypto";
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
12
|
+
import { basename, dirname, join, relative, sep } from "path";
|
|
13
|
+
import { transformNextRootLayout } from "@holo-js/adapter-shared/build";
|
|
14
|
+
var CLIENT_LAYOUT_QUERY = "?holo-client-layout";
|
|
15
|
+
function appDirectory(projectRoot) {
|
|
16
|
+
const rootAppDirectory = join(projectRoot, "app");
|
|
17
|
+
return existsSync(rootAppDirectory) ? rootAppDirectory : join(projectRoot, "src", "app");
|
|
18
|
+
}
|
|
19
|
+
function isInside(directory, parent) {
|
|
20
|
+
const path = relative(parent, directory);
|
|
21
|
+
return path === "" || !path.startsWith("..") && !path.startsWith(sep);
|
|
22
|
+
}
|
|
23
|
+
function hasLayout(directory, pageExtensions, dependencies) {
|
|
24
|
+
let found = false;
|
|
25
|
+
for (const extension of pageExtensions) {
|
|
26
|
+
const candidate = join(directory, `layout.${extension}`);
|
|
27
|
+
if (existsSync(candidate)) {
|
|
28
|
+
dependencies.existing(candidate);
|
|
29
|
+
found = true;
|
|
30
|
+
} else {
|
|
31
|
+
dependencies.missing(candidate);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return found;
|
|
35
|
+
}
|
|
36
|
+
function isRootLayout(file, projectRoot, pageExtensions, dependencies) {
|
|
37
|
+
const app = appDirectory(projectRoot);
|
|
38
|
+
if (!layoutFileNamePattern(pageExtensions).test(basename(file)) || !isInside(dirname(file), app)) return false;
|
|
39
|
+
for (let directory = dirname(dirname(file)); isInside(directory, app); directory = dirname(directory)) {
|
|
40
|
+
if (hasLayout(directory, pageExtensions, dependencies)) return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
function writeClientLayoutEntry(layout, projectRoot) {
|
|
45
|
+
const name = createHash("sha256").update(relative(projectRoot, layout)).digest("hex").slice(0, 16);
|
|
46
|
+
const entry = join(projectRoot, ".holo-js", "generated", "next", "client-layouts", `${name}.tsx`);
|
|
47
|
+
const source = [`'use client'`, `export * from ${JSON.stringify(layout)}`, `export { default } from ${JSON.stringify(layout)}`, ""].join("\n");
|
|
48
|
+
if (!existsSync(entry) || readFileSync(entry, "utf8") !== source) {
|
|
49
|
+
mkdirSync(dirname(entry), { recursive: true });
|
|
50
|
+
writeFileSync(entry, source);
|
|
51
|
+
}
|
|
52
|
+
return entry;
|
|
53
|
+
}
|
|
54
|
+
function layoutLoader(source, inputMap) {
|
|
55
|
+
const options = this.getOptions?.();
|
|
56
|
+
const projectRoot = this.rootContext ?? process.cwd();
|
|
57
|
+
const dependencies = { existing: (file) => this.addDependency?.(file), missing: (file) => this.addMissingDependency?.(file) };
|
|
58
|
+
const wrapsLayout = this.resourceQuery !== CLIENT_LAYOUT_QUERY && isRootLayout(this.resourcePath, projectRoot, options?.pageExtensions ?? DEFAULT_PAGE_EXTENSIONS, dependencies);
|
|
59
|
+
const clientLayoutRequest = () => {
|
|
60
|
+
if (options?.bundler !== "webpack") return `./${basename(this.resourcePath)}${CLIENT_LAYOUT_QUERY}`;
|
|
61
|
+
const entry = writeClientLayoutEntry(this.resourcePath, projectRoot);
|
|
62
|
+
this.addDependency?.(entry);
|
|
63
|
+
return entry;
|
|
64
|
+
};
|
|
65
|
+
return runModuleTransform(this, (code, filename, map) => wrapsLayout ? transformNextRootLayout(code, filename, clientLayoutRequest, map) : void 0, source, inputMap);
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
layoutLoader as default
|
|
69
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NextModuleInputSourceMap } from '@holo-js/adapter-shared/build';
|
|
2
|
+
|
|
3
|
+
type ModuleTransformLoaderContext = {
|
|
4
|
+
cacheable?: () => void;
|
|
5
|
+
readonly resourcePath: string;
|
|
6
|
+
callback?(error: null, code: string, map?: NextModuleInputSourceMap): void;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type { ModuleTransformLoaderContext as M };
|
package/dist/route-loader.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { NextModuleInputSourceMap } from '@holo-js/adapter-shared/build';
|
|
2
|
+
import { M as ModuleTransformLoaderContext } from './module-transform-loader-B5slbWAk.js';
|
|
3
|
+
|
|
4
|
+
declare function routeLoader(this: ModuleTransformLoaderContext, source: string, inputMap?: NextModuleInputSourceMap | null): string | undefined;
|
|
5
5
|
|
|
6
6
|
export { routeLoader as default };
|
package/dist/route-loader.mjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
runModuleTransform
|
|
3
|
+
} from "./chunk-RFEFJPTI.mjs";
|
|
4
|
+
|
|
1
5
|
// src/route-loader.ts
|
|
2
|
-
import {
|
|
3
|
-
function routeLoader(source) {
|
|
4
|
-
this
|
|
5
|
-
return compileNextRoute(source, this.resourcePath);
|
|
6
|
+
import { transformNextRoute } from "@holo-js/adapter-shared/build";
|
|
7
|
+
function routeLoader(source, inputMap) {
|
|
8
|
+
return runModuleTransform(this, transformNextRoute, source, inputMap);
|
|
6
9
|
}
|
|
7
10
|
export {
|
|
8
11
|
routeLoader as default
|
package/dist/runtime.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as _holo_js_core_runtime from '@holo-js/core/runtime';
|
|
|
3
3
|
import { CreateHoloOptions } from '@holo-js/core/runtime';
|
|
4
4
|
import * as _holo_js_config from '@holo-js/config';
|
|
5
5
|
import { HoloConfigMap, DotPath, HoloConfigValues, ValueAtPath } from '@holo-js/config';
|
|
6
|
-
import {
|
|
6
|
+
import { SerializedValidationException } from '@holo-js/validation';
|
|
7
7
|
import { serializeRateLimitError } from '@holo-js/adapter-shared/server-errors';
|
|
8
8
|
import { NextRequestLike } from '@holo-js/adapter-shared/next/request-context';
|
|
9
9
|
export { NextRequestLike } from '@holo-js/adapter-shared/next/request-context';
|
|
@@ -161,6 +161,7 @@ declare function createNextHoloHelpers<TCustom extends HoloConfigMap = HoloConfi
|
|
|
161
161
|
useConfig: <TPath extends DotPath<HoloConfigValues<TCustom>>>(path: TPath) => Promise<ValueAtPath<HoloConfigValues<TCustom>, TPath>>;
|
|
162
162
|
config: <TPath extends DotPath<HoloConfigValues<TCustom>>>(path: TPath) => Promise<ValueAtPath<HoloConfigValues<TCustom>, TPath>>;
|
|
163
163
|
};
|
|
164
|
+
declare const serializeValidationException: (value: unknown) => SerializedValidationException | undefined;
|
|
164
165
|
type ExpectedFailure = NonNullable<ReturnType<typeof serializeValidationException> | ReturnType<typeof serializeRateLimitError>>;
|
|
165
166
|
declare function routeHandler<TArgs extends readonly unknown[]>(handler: (...args: TArgs) => Response | Promise<Response>): (...args: TArgs) => Promise<Response>;
|
|
166
167
|
declare function serverAction<TArgs extends readonly unknown[], TResult>(action: (...args: TArgs) => Promise<TResult>): (...args: TArgs) => Promise<TResult | ExpectedFailure>;
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VALIDATION_FLASH_COOKIE,
|
|
3
|
+
serializeValidationFlash,
|
|
4
|
+
validationFlashPage
|
|
5
|
+
} from "./chunk-7LOU63WN.mjs";
|
|
6
|
+
import {
|
|
7
|
+
rememberRenderedValidationFlash
|
|
8
|
+
} from "./chunk-ZPWXXNMV.mjs";
|
|
9
|
+
|
|
1
10
|
// src/runtime.ts
|
|
2
11
|
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
-
import { createRequire } from "module";
|
|
4
|
-
import { resolve } from "path";
|
|
12
|
+
import { createRequire as createRequire2 } from "module";
|
|
13
|
+
import { resolve as resolve2 } from "path";
|
|
5
14
|
import { initializeHolo } from "@holo-js/core/runtime";
|
|
6
|
-
import { createCookieWriteUnavailableError } from "@holo-js/kernel";
|
|
15
|
+
import { createCookieWriteUnavailableError, resolveRequestUrl } from "@holo-js/kernel";
|
|
7
16
|
import { captureErrorReporter } from "@holo-js/kernel/error-reporting";
|
|
8
|
-
import {
|
|
17
|
+
import { validationInternals } from "@holo-js/validation";
|
|
9
18
|
import { serializeRateLimitError } from "@holo-js/adapter-shared/server-errors";
|
|
10
19
|
|
|
11
20
|
// src/request-context.ts
|
|
@@ -21,6 +30,24 @@ function setNextAuthRequestRunner(runner) {
|
|
|
21
30
|
globalThis.__holoNextAuthRequestRunner = runner;
|
|
22
31
|
}
|
|
23
32
|
|
|
33
|
+
// src/next-async-storage.ts
|
|
34
|
+
import { createRequire } from "module";
|
|
35
|
+
import { resolve } from "path";
|
|
36
|
+
function requireNextFromProject() {
|
|
37
|
+
return createRequire(resolve(process.cwd(), "package.json"));
|
|
38
|
+
}
|
|
39
|
+
function loadNextAsyncStorage(requireNext, name) {
|
|
40
|
+
try {
|
|
41
|
+
const storage = requireNext(`next/dist/server/app-render/${name}-async-storage.external.js`);
|
|
42
|
+
return storage[name === "action" ? "actionAsyncStorage" : "workUnitAsyncStorage"];
|
|
43
|
+
} catch {
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function currentWorkUnitStore() {
|
|
48
|
+
return loadNextAsyncStorage(requireNextFromProject(), "work-unit")?.getStore();
|
|
49
|
+
}
|
|
50
|
+
|
|
24
51
|
// src/shutdown.ts
|
|
25
52
|
import { constants } from "os";
|
|
26
53
|
var SHUTDOWN_DEADLINE_MS = 3e4;
|
|
@@ -186,14 +213,6 @@ function parseRequestCookies(header) {
|
|
|
186
213
|
function isMissingNextRequestScope(error) {
|
|
187
214
|
return error instanceof Error && error.message.includes("outside a request scope");
|
|
188
215
|
}
|
|
189
|
-
function loadNextAsyncStorage(requireNext, name) {
|
|
190
|
-
try {
|
|
191
|
-
const storage = requireNext(`next/dist/server/app-render/${name}-async-storage.external.js`);
|
|
192
|
-
return storage[name === "action" ? "actionAsyncStorage" : "workUnitAsyncStorage"];
|
|
193
|
-
} catch {
|
|
194
|
-
return void 0;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
216
|
function nextCookiesMutableInCurrentPhase(requireNext) {
|
|
198
217
|
const workUnitAsyncStorage = loadNextAsyncStorage(requireNext, "work-unit");
|
|
199
218
|
return !workUnitAsyncStorage || workUnitAsyncStorage.getStore()?.phase === "action";
|
|
@@ -220,7 +239,7 @@ function createNextRequestContext(request) {
|
|
|
220
239
|
};
|
|
221
240
|
}
|
|
222
241
|
function resolveNextAuthRequestAccessors(projectRoot = process.cwd()) {
|
|
223
|
-
const requireNext =
|
|
242
|
+
const requireNext = createRequire2(resolve2(projectRoot, "package.json"));
|
|
224
243
|
return {
|
|
225
244
|
async getCookie(name) {
|
|
226
245
|
const request = getCurrentNextRequest();
|
|
@@ -346,6 +365,7 @@ function createNextHoloHelpers(options) {
|
|
|
346
365
|
config: useConfig
|
|
347
366
|
};
|
|
348
367
|
}
|
|
368
|
+
var { serializeValidationException } = validationInternals;
|
|
349
369
|
function serializeExpectedFailure(error) {
|
|
350
370
|
const payload = serializeValidationException(error) ?? serializeRateLimitError(error);
|
|
351
371
|
if (!payload) throw error;
|
|
@@ -365,20 +385,57 @@ function routeHandler(handler) {
|
|
|
365
385
|
};
|
|
366
386
|
}
|
|
367
387
|
var runningServerAction = new AsyncLocalStorage();
|
|
368
|
-
function
|
|
369
|
-
const
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
if (!actionStore?.isAction || actionStore.isAppRoute || store?.type !== "request" || store.phase !== "action") return false;
|
|
388
|
+
function invokedServerActionRequest(action) {
|
|
389
|
+
const actionStore = loadNextAsyncStorage(requireNextFromProject(), "action")?.getStore();
|
|
390
|
+
const store = currentWorkUnitStore();
|
|
391
|
+
if (!actionStore?.isAction || actionStore.isAppRoute || store?.type !== "request" || store.phase !== "action") return void 0;
|
|
373
392
|
const invoked = store.headers?.get("next-action");
|
|
374
|
-
return
|
|
393
|
+
return !invoked || invoked === Reflect.get(action, "$$id") ? store : void 0;
|
|
394
|
+
}
|
|
395
|
+
function isSubmittedWithJavaScript(store) {
|
|
396
|
+
return Boolean(store.headers?.get("next-action"));
|
|
397
|
+
}
|
|
398
|
+
async function actionCookies() {
|
|
399
|
+
const { cookies } = requireNextFromProject()("next/headers.js");
|
|
400
|
+
return await cookies();
|
|
401
|
+
}
|
|
402
|
+
function isSecureRequest(store) {
|
|
403
|
+
const protocol = store.headers?.get("x-forwarded-proto") === "https" ? "https" : "http";
|
|
404
|
+
try {
|
|
405
|
+
return resolveRequestUrl({ url: `${protocol}://localhost/`, headers: store.headers }).protocol === "https:";
|
|
406
|
+
} catch {
|
|
407
|
+
return protocol === "https";
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
async function flashValidationErrors(store, failure) {
|
|
411
|
+
const flash = serializeValidationFlash({ bag: failure.bag, page: validationFlashPage(store.url?.pathname ?? "/"), errors: failure.errors });
|
|
412
|
+
if (!flash) return;
|
|
413
|
+
rememberRenderedValidationFlash(store, flash);
|
|
414
|
+
const cookies = await actionCookies();
|
|
415
|
+
cookies.set(VALIDATION_FLASH_COOKIE, flash, {
|
|
416
|
+
path: "/",
|
|
417
|
+
sameSite: "lax",
|
|
418
|
+
secure: isSecureRequest(store)
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
async function forgetValidationErrors() {
|
|
422
|
+
const cookies = await actionCookies();
|
|
423
|
+
if (cookies.get(VALIDATION_FLASH_COOKIE)) cookies.delete(VALIDATION_FLASH_COOKIE);
|
|
375
424
|
}
|
|
376
425
|
function serverAction(action) {
|
|
377
426
|
const invoke = async (...args) => {
|
|
378
|
-
|
|
427
|
+
const request = runningServerAction.getStore() ? void 0 : invokedServerActionRequest(invoke);
|
|
428
|
+
if (!request) return await action(...args);
|
|
429
|
+
await forgetValidationErrors();
|
|
379
430
|
try {
|
|
380
431
|
return await runningServerAction.run(true, () => action(...args));
|
|
381
432
|
} catch (error) {
|
|
433
|
+
const failure = serializeValidationException(error);
|
|
434
|
+
if (failure) {
|
|
435
|
+
await flashValidationErrors(request, failure);
|
|
436
|
+
return failure;
|
|
437
|
+
}
|
|
438
|
+
if (!isSubmittedWithJavaScript(request)) throw error;
|
|
382
439
|
return serializeExpectedFailure(error);
|
|
383
440
|
}
|
|
384
441
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { NextModuleInputSourceMap } from '@holo-js/adapter-shared/build';
|
|
2
|
+
import { M as ModuleTransformLoaderContext } from './module-transform-loader-B5slbWAk.js';
|
|
3
|
+
|
|
4
|
+
declare function serverActionLoader(this: ModuleTransformLoaderContext, source: string, inputMap?: NextModuleInputSourceMap | null): string | undefined;
|
|
5
5
|
|
|
6
6
|
export { serverActionLoader as default };
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
runModuleTransform
|
|
3
|
+
} from "./chunk-RFEFJPTI.mjs";
|
|
4
|
+
|
|
1
5
|
// src/server-action-loader.ts
|
|
2
|
-
import {
|
|
3
|
-
function serverActionLoader(source) {
|
|
4
|
-
this
|
|
5
|
-
return compileNextServerActions(source, this.resourcePath);
|
|
6
|
+
import { transformNextServerActions } from "@holo-js/adapter-shared/build";
|
|
7
|
+
function serverActionLoader(source, inputMap) {
|
|
8
|
+
return runModuleTransform(this, transformNextServerActions, source, inputMap);
|
|
6
9
|
}
|
|
7
10
|
export {
|
|
8
11
|
serverActionLoader as default
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/adapter-next",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Holo-JS Framework - Next.js adapter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,6 +25,16 @@
|
|
|
25
25
|
"import": "./dist/client.mjs",
|
|
26
26
|
"default": "./dist/client.mjs"
|
|
27
27
|
},
|
|
28
|
+
"./internal/validation-errors": {
|
|
29
|
+
"types": "./dist/internal/validation-errors.d.ts",
|
|
30
|
+
"import": "./dist/internal/validation-errors.mjs",
|
|
31
|
+
"default": "./dist/internal/validation-errors.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./internal/validation-layout": {
|
|
34
|
+
"types": "./dist/internal/validation-layout.d.ts",
|
|
35
|
+
"import": "./dist/internal/validation-layout.mjs",
|
|
36
|
+
"default": "./dist/internal/validation-layout.mjs"
|
|
37
|
+
},
|
|
28
38
|
"./realtime": {
|
|
29
39
|
"types": "./dist/realtime.d.ts",
|
|
30
40
|
"import": "./dist/realtime.mjs",
|
|
@@ -49,11 +59,11 @@
|
|
|
49
59
|
"test": "vitest --run"
|
|
50
60
|
},
|
|
51
61
|
"dependencies": {
|
|
52
|
-
"@holo-js/adapter-shared": "^0.5.
|
|
53
|
-
"@holo-js/config": "^0.5.
|
|
54
|
-
"@holo-js/core": "^0.5.
|
|
55
|
-
"@holo-js/kernel": "^0.5.
|
|
56
|
-
"@holo-js/validation": "^0.5.
|
|
62
|
+
"@holo-js/adapter-shared": "^0.5.1",
|
|
63
|
+
"@holo-js/config": "^0.5.1",
|
|
64
|
+
"@holo-js/core": "^0.5.1",
|
|
65
|
+
"@holo-js/kernel": "^0.5.1",
|
|
66
|
+
"@holo-js/validation": "^0.5.1"
|
|
57
67
|
},
|
|
58
68
|
"peerDependencies": {
|
|
59
69
|
"@holo-js/forms": ">=0.4.0",
|
|
@@ -70,7 +80,8 @@
|
|
|
70
80
|
}
|
|
71
81
|
},
|
|
72
82
|
"devDependencies": {
|
|
73
|
-
"@holo-js/realtime": "^0.5.
|
|
83
|
+
"@holo-js/realtime": "^0.5.1",
|
|
84
|
+
"@jridgewell/trace-mapping": "^0.3.31",
|
|
74
85
|
"@types/node": "^22.20.5",
|
|
75
86
|
"next": "^16.4.3",
|
|
76
87
|
"tsup": "^9.0.0",
|