@holo-js/adapter-next 0.4.3 → 0.5.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
ddacd99d82382b602d55ea256cfd25d3487962ce04af00b19af7f4d6df16f8c8
|
package/dist/config.mjs
CHANGED
|
@@ -48,6 +48,7 @@ var NEXT_AUTH_INTERRUPTS_ENV = "__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS";
|
|
|
48
48
|
var CORE_RUNTIME_CHUNK_PATH = /packages[\\/]core[\\/]dist[\\/].+\.mjs$/;
|
|
49
49
|
var OPTIONAL_RUNTIME_IMPORT_ISSUE = /Module not found: Can't resolve (?:'@holo-js\/storage-s3'|<dynamic>)/;
|
|
50
50
|
var HOLO_RUNTIME_FILESYSTEM_PATH = /(?:packages|node_modules[\\/]@holo-js)[\\/](?:core|kernel|media)[\\/]dist[\\/].+\.mjs$/;
|
|
51
|
+
var USE_SERVER_DIRECTIVE = /['"]use server['"]/;
|
|
51
52
|
var DYNAMIC_FILESYSTEM_ACCESS_ISSUE = /Dynamic filesystem access causes tracing of the whole project/;
|
|
52
53
|
var PACKAGE_DEPENDENCY_FIELDS = [
|
|
53
54
|
"dependencies",
|
|
@@ -208,6 +209,7 @@ function withHolo(nextConfig = {}) {
|
|
|
208
209
|
const hasRealtime = isOptionalServerExternalPackageInstalled("@holo-js/realtime", packageManifest);
|
|
209
210
|
const validationLoader = fileURLToPath(new URL("./validation-loader.mjs", import.meta.url));
|
|
210
211
|
const routeLoader = fileURLToPath(new URL("./route-loader.mjs", import.meta.url));
|
|
212
|
+
const serverActionLoader = fileURLToPath(new URL("./server-action-loader.mjs", import.meta.url));
|
|
211
213
|
const realtimeDefinitionLoader = fileURLToPath(new URL("./realtime-definition-loader.mjs", import.meta.url));
|
|
212
214
|
const realtimeDirectoryPatterns = hasRealtime ? resolveRealtimeDefinitionPatterns(nextConfig, process.cwd()) : { absolute: [], turbopackRelative: [] };
|
|
213
215
|
const mergedTurbopack = {
|
|
@@ -217,7 +219,8 @@ function withHolo(nextConfig = {}) {
|
|
|
217
219
|
"*": [
|
|
218
220
|
...existingTurbopack.rules?.["*"] ? [existingTurbopack.rules["*"]].flat() : [],
|
|
219
221
|
{ condition: { all: ["browser", { not: "foreign" }, { path: /\.[cm]?[jt]sx?$/ }] }, loaders: [validationLoader] },
|
|
220
|
-
{ condition: { all: [{ not: "browser" }, { not: "foreign" }, { path: /(?:^|[\\/])app[\\/].*[\\/]route\.[cm]?[jt]s$/ }] }, loaders: [routeLoader] }
|
|
222
|
+
{ 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] }
|
|
221
224
|
],
|
|
222
225
|
...hasRealtime ? {
|
|
223
226
|
"*.{ts,tsx,js,jsx,mts,mjs,cts,cjs}": [
|
|
@@ -265,7 +268,8 @@ function withHolo(nextConfig = {}) {
|
|
|
265
268
|
...nextWebpackConfig.module.rules ?? [],
|
|
266
269
|
...hasRealtime ? [createRealtimeDefinitionWebpackRule(realtimeDefinitionLoader, context.isServer, realtimeDirectoryPatterns.absolute)] : [],
|
|
267
270
|
...!context.isServer ? [{ test: /\.[cm]?[jt]sx?$/, exclude: /node_modules/, use: [{ loader: validationLoader }] }] : [],
|
|
268
|
-
...context.isServer ? [{ test: /[\\/]app[\\/].*[\\/]route\.[cm]?[jt]s$/, exclude: /node_modules/, use: [{ loader: routeLoader }] }] : []
|
|
271
|
+
...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 }] }] : []
|
|
269
273
|
];
|
|
270
274
|
return nextWebpackConfig;
|
|
271
275
|
},
|
package/dist/runtime.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ 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 { serializeValidationException } from '@holo-js/validation';
|
|
7
|
+
import { serializeRateLimitError } from '@holo-js/adapter-shared/server-errors';
|
|
6
8
|
import { NextRequestLike } from '@holo-js/adapter-shared/next/request-context';
|
|
7
9
|
export { NextRequestLike } from '@holo-js/adapter-shared/next/request-context';
|
|
8
10
|
|
|
@@ -159,9 +161,12 @@ declare function createNextHoloHelpers<TCustom extends HoloConfigMap = HoloConfi
|
|
|
159
161
|
useConfig: <TPath extends DotPath<HoloConfigValues<TCustom>>>(path: TPath) => Promise<ValueAtPath<HoloConfigValues<TCustom>, TPath>>;
|
|
160
162
|
config: <TPath extends DotPath<HoloConfigValues<TCustom>>>(path: TPath) => Promise<ValueAtPath<HoloConfigValues<TCustom>, TPath>>;
|
|
161
163
|
};
|
|
164
|
+
type ExpectedFailure = NonNullable<ReturnType<typeof serializeValidationException> | ReturnType<typeof serializeRateLimitError>>;
|
|
162
165
|
declare function routeHandler<TArgs extends readonly unknown[]>(handler: (...args: TArgs) => Response | Promise<Response>): (...args: TArgs) => Promise<Response>;
|
|
166
|
+
declare function serverAction<TArgs extends readonly unknown[], TResult>(action: (...args: TArgs) => Promise<TResult>): (...args: TArgs) => Promise<TResult | ExpectedFailure>;
|
|
163
167
|
declare const adapterNextRuntimeInternals: {
|
|
164
168
|
routeHandler: typeof routeHandler;
|
|
169
|
+
serverAction: typeof serverAction;
|
|
165
170
|
safeDecodeCookieSegment: typeof safeDecodeCookieSegment;
|
|
166
171
|
parseResponseCookie: typeof parseResponseCookie;
|
|
167
172
|
parseRequestCookies: typeof parseRequestCookies;
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/runtime.ts
|
|
2
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
2
3
|
import { createRequire } from "module";
|
|
3
4
|
import { resolve } from "path";
|
|
4
5
|
import { initializeHolo } from "@holo-js/core/runtime";
|
|
@@ -185,14 +186,18 @@ function parseRequestCookies(header) {
|
|
|
185
186
|
function isMissingNextRequestScope(error) {
|
|
186
187
|
return error instanceof Error && error.message.includes("outside a request scope");
|
|
187
188
|
}
|
|
188
|
-
function
|
|
189
|
+
function loadNextAsyncStorage(requireNext, name) {
|
|
189
190
|
try {
|
|
190
|
-
const
|
|
191
|
-
return
|
|
191
|
+
const storage = requireNext(`next/dist/server/app-render/${name}-async-storage.external.js`);
|
|
192
|
+
return storage[name === "action" ? "actionAsyncStorage" : "workUnitAsyncStorage"];
|
|
192
193
|
} catch {
|
|
193
|
-
return
|
|
194
|
+
return void 0;
|
|
194
195
|
}
|
|
195
196
|
}
|
|
197
|
+
function nextCookiesMutableInCurrentPhase(requireNext) {
|
|
198
|
+
const workUnitAsyncStorage = loadNextAsyncStorage(requireNext, "work-unit");
|
|
199
|
+
return !workUnitAsyncStorage || workUnitAsyncStorage.getStore()?.phase === "action";
|
|
200
|
+
}
|
|
196
201
|
function isReadonlyNextCookieStore(error) {
|
|
197
202
|
return error instanceof Error && error.message.startsWith("Cookies can only be modified in a Server Action or Route Handler");
|
|
198
203
|
}
|
|
@@ -341,13 +346,17 @@ function createNextHoloHelpers(options) {
|
|
|
341
346
|
config: useConfig
|
|
342
347
|
};
|
|
343
348
|
}
|
|
349
|
+
function serializeExpectedFailure(error) {
|
|
350
|
+
const payload = serializeValidationException(error) ?? serializeRateLimitError(error);
|
|
351
|
+
if (!payload) throw error;
|
|
352
|
+
return payload;
|
|
353
|
+
}
|
|
344
354
|
function routeHandler(handler) {
|
|
345
355
|
return async (...args) => {
|
|
346
356
|
try {
|
|
347
357
|
return await handler(...args);
|
|
348
358
|
} catch (error) {
|
|
349
|
-
const payload =
|
|
350
|
-
if (!payload) throw error;
|
|
359
|
+
const payload = serializeExpectedFailure(error);
|
|
351
360
|
return Response.json(payload, {
|
|
352
361
|
status: payload.status,
|
|
353
362
|
...payload.retryAfterSeconds === void 0 ? {} : { headers: { "Retry-After": String(payload.retryAfterSeconds) } }
|
|
@@ -355,8 +364,29 @@ function routeHandler(handler) {
|
|
|
355
364
|
}
|
|
356
365
|
};
|
|
357
366
|
}
|
|
367
|
+
var runningServerAction = new AsyncLocalStorage();
|
|
368
|
+
function isInvokedServerAction(action) {
|
|
369
|
+
const requireNext = createRequire(resolve(process.cwd(), "package.json"));
|
|
370
|
+
const actionStore = loadNextAsyncStorage(requireNext, "action")?.getStore();
|
|
371
|
+
const store = loadNextAsyncStorage(requireNext, "work-unit")?.getStore();
|
|
372
|
+
if (!actionStore?.isAction || actionStore.isAppRoute || store?.type !== "request" || store.phase !== "action") return false;
|
|
373
|
+
const invoked = store.headers?.get("next-action");
|
|
374
|
+
return Boolean(invoked) && invoked === Reflect.get(action, "$$id");
|
|
375
|
+
}
|
|
376
|
+
function serverAction(action) {
|
|
377
|
+
const invoke = async (...args) => {
|
|
378
|
+
if (runningServerAction.getStore() || !isInvokedServerAction(invoke)) return await action(...args);
|
|
379
|
+
try {
|
|
380
|
+
return await runningServerAction.run(true, () => action(...args));
|
|
381
|
+
} catch (error) {
|
|
382
|
+
return serializeExpectedFailure(error);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
return invoke;
|
|
386
|
+
}
|
|
358
387
|
var adapterNextRuntimeInternals = {
|
|
359
388
|
routeHandler,
|
|
389
|
+
serverAction,
|
|
360
390
|
safeDecodeCookieSegment,
|
|
361
391
|
parseResponseCookie,
|
|
362
392
|
parseRequestCookies,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// src/server-action-loader.ts
|
|
2
|
+
import { compileNextServerActions } from "@holo-js/adapter-shared/build";
|
|
3
|
+
function serverActionLoader(source) {
|
|
4
|
+
this.cacheable?.();
|
|
5
|
+
return compileNextServerActions(source, this.resourcePath);
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
serverActionLoader as default
|
|
9
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/adapter-next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Holo-JS Framework - Next.js adapter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
"test": "vitest --run"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@holo-js/adapter-shared": "^0.
|
|
53
|
-
"@holo-js/config": "^0.
|
|
54
|
-
"@holo-js/core": "^0.
|
|
55
|
-
"@holo-js/kernel": "^0.
|
|
56
|
-
"@holo-js/validation": "^0.
|
|
52
|
+
"@holo-js/adapter-shared": "^0.5.0",
|
|
53
|
+
"@holo-js/config": "^0.5.0",
|
|
54
|
+
"@holo-js/core": "^0.5.0",
|
|
55
|
+
"@holo-js/kernel": "^0.5.0",
|
|
56
|
+
"@holo-js/validation": "^0.5.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@holo-js/forms": "
|
|
60
|
-
"@holo-js/realtime": "
|
|
59
|
+
"@holo-js/forms": ">=0.4.0",
|
|
60
|
+
"@holo-js/realtime": ">=0.4.0",
|
|
61
61
|
"next": "^16.4.3",
|
|
62
62
|
"react": "^19.2.6"
|
|
63
63
|
},
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@holo-js/realtime": "^0.
|
|
73
|
+
"@holo-js/realtime": "^0.5.0",
|
|
74
74
|
"@types/node": "^22.20.5",
|
|
75
75
|
"next": "^16.4.3",
|
|
76
76
|
"tsup": "^9.0.0",
|