@holo-js/adapter-next 0.3.27 → 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/LICENSE +21 -0
- package/dist/.holo-build-fingerprint +1 -0
- package/dist/config.d.ts +3 -0
- package/dist/config.mjs +67 -9
- package/dist/index.d.ts +2 -1
- package/dist/realtime-definition-loader.d.ts +2 -0
- package/dist/realtime-definition-loader.mjs +8 -3
- package/dist/realtime.mjs +14 -4
- package/dist/runtime.d.ts +10 -14
- package/dist/runtime.mjs +122 -5
- package/package.json +23 -16
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Holo-JS contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
05c6b0e549d6f013da98a82b7f834bf3e1a4a4bed08149fe912bc67039dfdb04
|
package/dist/config.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ interface TurbopackIgnoreIssueRule {
|
|
|
3
3
|
readonly title?: string | RegExp;
|
|
4
4
|
}
|
|
5
5
|
interface TurbopackConfig {
|
|
6
|
+
readonly root?: string;
|
|
6
7
|
readonly ignoreIssue?: readonly TurbopackIgnoreIssueRule[];
|
|
7
8
|
readonly rules?: Record<string, unknown>;
|
|
8
9
|
readonly [key: string]: unknown;
|
|
@@ -11,6 +12,7 @@ interface NextConfig {
|
|
|
11
12
|
readonly serverExternalPackages?: string[];
|
|
12
13
|
readonly transpilePackages?: string[];
|
|
13
14
|
readonly outputFileTracingExcludes?: Record<string, string[]>;
|
|
15
|
+
readonly outputFileTracingRoot?: string;
|
|
14
16
|
readonly experimental?: Record<string, unknown>;
|
|
15
17
|
readonly turbopack?: TurbopackConfig;
|
|
16
18
|
readonly rewrites?: () => Promise<unknown>;
|
|
@@ -22,6 +24,7 @@ type WebpackConfig = {
|
|
|
22
24
|
rules?: unknown[];
|
|
23
25
|
[key: string]: unknown;
|
|
24
26
|
};
|
|
27
|
+
plugins?: unknown[];
|
|
25
28
|
[key: string]: unknown;
|
|
26
29
|
};
|
|
27
30
|
type WebpackConfigContext = {
|
package/dist/config.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// src/config.ts
|
|
2
|
-
import {
|
|
2
|
+
import { assertRealtimeDefinitionTree, resolveRealtimeDefinitionDirectories } from "@holo-js/adapter-shared/realtime-directories";
|
|
3
|
+
import { existsSync, readFileSync, realpathSync } from "fs";
|
|
4
|
+
import { createRequire } from "module";
|
|
3
5
|
import { fileURLToPath } from "url";
|
|
4
|
-
import { join } from "path";
|
|
6
|
+
import { isAbsolute, join, relative, resolve } from "path";
|
|
5
7
|
var HOLO_SERVER_EXTERNAL_PACKAGES = [
|
|
6
8
|
"@holo-js/core",
|
|
7
9
|
"@holo-js/db",
|
|
@@ -82,6 +84,15 @@ function holoPanelsRewrites() {
|
|
|
82
84
|
}
|
|
83
85
|
return Object.freeze([...rewrites.values()]);
|
|
84
86
|
}
|
|
87
|
+
function createRealtimeDefinitionTreePlugin(rootDir) {
|
|
88
|
+
return {
|
|
89
|
+
apply(compiler) {
|
|
90
|
+
const assertTree = () => assertRealtimeDefinitionTree(rootDir);
|
|
91
|
+
compiler.hooks.beforeRun.tap("HoloRealtimeDefinitionTree", assertTree);
|
|
92
|
+
compiler.hooks.watchRun.tap("HoloRealtimeDefinitionTree", assertTree);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
85
96
|
function isPackageDependencyMap(value) {
|
|
86
97
|
return value !== null && typeof value === "object" && Object.values(value).every((dependency) => typeof dependency === "string");
|
|
87
98
|
}
|
|
@@ -106,23 +117,65 @@ function readProjectPackageManifest() {
|
|
|
106
117
|
function isOptionalServerExternalPackageInstalled(packageName, manifest) {
|
|
107
118
|
return PACKAGE_DEPENDENCY_FIELDS.some((field) => Boolean(manifest?.[field]?.[packageName]));
|
|
108
119
|
}
|
|
109
|
-
|
|
120
|
+
var pathSeparatorPattern = "[\\\\/]";
|
|
121
|
+
function escapePathSegments(segments) {
|
|
122
|
+
return segments.map((segment) => segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join(pathSeparatorPattern);
|
|
123
|
+
}
|
|
124
|
+
function loadNextFindRoot(projectRoot) {
|
|
125
|
+
const projectRequire = createRequire(join(projectRoot, "package.json"));
|
|
126
|
+
try {
|
|
127
|
+
return projectRequire("next/dist/lib/find-root");
|
|
128
|
+
} catch {
|
|
129
|
+
return createRequire(import.meta.url)("next/dist/lib/find-root");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function resolveTurbopackRoot(nextConfig, projectRoot) {
|
|
133
|
+
const configured = nextConfig.outputFileTracingRoot || nextConfig.turbopack?.root || process.env.NEXT_PRIVATE_OUTPUT_TRACE_ROOT;
|
|
134
|
+
let root = configured ? resolve(projectRoot, configured) : void 0;
|
|
135
|
+
if (!root) {
|
|
136
|
+
try {
|
|
137
|
+
root = loadNextFindRoot(projectRoot).findRootDirAndLockFiles(projectRoot).rootDir;
|
|
138
|
+
} catch (error) {
|
|
139
|
+
throw new Error("Holo could not determine the Turbopack root for a symlinked server/realtime folder. Set turbopack.root in next.config.", { cause: error });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (!root) {
|
|
143
|
+
throw new Error("Holo could not determine the Turbopack root for a symlinked server/realtime folder. Set turbopack.root in next.config.");
|
|
144
|
+
}
|
|
145
|
+
return existsSync(root) ? realpathSync.native(root) : root;
|
|
146
|
+
}
|
|
147
|
+
function resolveRealtimeDefinitionPatterns(nextConfig, projectRoot) {
|
|
148
|
+
const directories = resolveRealtimeDefinitionDirectories(projectRoot);
|
|
149
|
+
const linkedDirectories = directories.filter((directory) => !directory.endsWith("/server/realtime"));
|
|
150
|
+
const turbopackRoot = linkedDirectories.length > 0 ? resolveTurbopackRoot(nextConfig, projectRoot) : void 0;
|
|
110
151
|
return {
|
|
111
|
-
|
|
152
|
+
absolute: directories.map((directory) => new RegExp(`^${escapePathSegments(directory.split("/"))}${pathSeparatorPattern}`)),
|
|
153
|
+
turbopackRelative: linkedDirectories.map((directory) => {
|
|
154
|
+
const relativeDirectory = relative(turbopackRoot, directory);
|
|
155
|
+
if (relativeDirectory === "" || relativeDirectory.startsWith("..") || isAbsolute(relativeDirectory)) {
|
|
156
|
+
throw new Error(`server/realtime resolves to ${directory}, outside the Turbopack root ${turbopackRoot}. Move the folder inside the root or set turbopack.root in next.config.`);
|
|
157
|
+
}
|
|
158
|
+
return new RegExp(`^(?:\\.${pathSeparatorPattern})?${escapePathSegments(relativeDirectory.replaceAll("\\", "/").split("/"))}${pathSeparatorPattern}`);
|
|
159
|
+
})
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function createRealtimeDefinitionWebpackRule(loaderPath, preserveServerHandlers, directoryPatterns) {
|
|
163
|
+
return {
|
|
164
|
+
test: [/(?:^|[\\/])server[\\/]realtime[\\/].+\.[cm]?[jt]sx?$/, ...directoryPatterns.map((pattern) => new RegExp(`${pattern.source}.+\\.[cm]?[jt]sx?$`))],
|
|
112
165
|
use: [{
|
|
113
166
|
loader: loaderPath,
|
|
114
167
|
options: { preserveServerHandlers }
|
|
115
168
|
}]
|
|
116
169
|
};
|
|
117
170
|
}
|
|
118
|
-
function createRealtimeDefinitionTurbopackRule(loaderPath, environment) {
|
|
171
|
+
function createRealtimeDefinitionTurbopackRule(loaderPath, environment, directoryPatterns) {
|
|
119
172
|
const environmentCondition = environment === "browser" ? "browser" : { any: ["node", "edge-light"] };
|
|
120
173
|
return {
|
|
121
174
|
condition: {
|
|
122
175
|
all: [
|
|
123
176
|
environmentCondition,
|
|
124
177
|
{
|
|
125
|
-
path: /(?:^|[\\/])server[\\/]realtime[\\/]/
|
|
178
|
+
any: [{ path: /(?:^|[\\/])server[\\/]realtime[\\/]/ }, ...directoryPatterns.map((path) => ({ path }))]
|
|
126
179
|
}
|
|
127
180
|
]
|
|
128
181
|
},
|
|
@@ -156,6 +209,7 @@ function withHolo(nextConfig = {}) {
|
|
|
156
209
|
const validationLoader = fileURLToPath(new URL("./validation-loader.mjs", import.meta.url));
|
|
157
210
|
const routeLoader = fileURLToPath(new URL("./route-loader.mjs", import.meta.url));
|
|
158
211
|
const realtimeDefinitionLoader = fileURLToPath(new URL("./realtime-definition-loader.mjs", import.meta.url));
|
|
212
|
+
const realtimeDirectoryPatterns = hasRealtime ? resolveRealtimeDefinitionPatterns(nextConfig, process.cwd()) : { absolute: [], turbopackRelative: [] };
|
|
159
213
|
const mergedTurbopack = {
|
|
160
214
|
...existingTurbopack,
|
|
161
215
|
rules: {
|
|
@@ -167,8 +221,8 @@ function withHolo(nextConfig = {}) {
|
|
|
167
221
|
],
|
|
168
222
|
...hasRealtime ? {
|
|
169
223
|
"*.{ts,tsx,js,jsx,mts,mjs,cts,cjs}": [
|
|
170
|
-
createRealtimeDefinitionTurbopackRule(realtimeDefinitionLoader, "browser"),
|
|
171
|
-
createRealtimeDefinitionTurbopackRule(realtimeDefinitionLoader, "server")
|
|
224
|
+
createRealtimeDefinitionTurbopackRule(realtimeDefinitionLoader, "browser", [...realtimeDirectoryPatterns.absolute, ...realtimeDirectoryPatterns.turbopackRelative]),
|
|
225
|
+
createRealtimeDefinitionTurbopackRule(realtimeDefinitionLoader, "server", [...realtimeDirectoryPatterns.absolute, ...realtimeDirectoryPatterns.turbopackRelative])
|
|
172
226
|
]
|
|
173
227
|
} : {}
|
|
174
228
|
},
|
|
@@ -202,10 +256,14 @@ function withHolo(nextConfig = {}) {
|
|
|
202
256
|
turbopack: mergedTurbopack,
|
|
203
257
|
webpack(config, context) {
|
|
204
258
|
const nextWebpackConfig = userWebpack?.(config, context) ?? config;
|
|
259
|
+
if (hasRealtime) {
|
|
260
|
+
assertRealtimeDefinitionTree(process.cwd());
|
|
261
|
+
nextWebpackConfig.plugins = [...nextWebpackConfig.plugins ?? [], createRealtimeDefinitionTreePlugin(process.cwd())];
|
|
262
|
+
}
|
|
205
263
|
nextWebpackConfig.module = nextWebpackConfig.module ?? {};
|
|
206
264
|
nextWebpackConfig.module.rules = [
|
|
207
265
|
...nextWebpackConfig.module.rules ?? [],
|
|
208
|
-
...hasRealtime ? [createRealtimeDefinitionWebpackRule(realtimeDefinitionLoader, context.isServer)] : [],
|
|
266
|
+
...hasRealtime ? [createRealtimeDefinitionWebpackRule(realtimeDefinitionLoader, context.isServer, realtimeDirectoryPatterns.absolute)] : [],
|
|
209
267
|
...!context.isServer ? [{ test: /\.[cm]?[jt]sx?$/, exclude: /node_modules/, use: [{ loader: validationLoader }] }] : [],
|
|
210
268
|
...context.isServer ? [{ test: /[\\/]app[\\/].*[\\/]route\.[cm]?[jt]s$/, exclude: /node_modules/, use: [{ loader: routeLoader }] }] : []
|
|
211
269
|
];
|
package/dist/index.d.ts
CHANGED
|
@@ -14,4 +14,5 @@ declare const adapterNextInternals: {
|
|
|
14
14
|
resolveOptions: (projectOptions?: HoloFrameworkOptions) => _holo_js_core.ResolvedHoloFrameworkOptions;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
export {
|
|
17
|
+
export { adapterNextInternals, createNextHoloHelpers, createNextHoloProject, initializeNextHoloProject, nextHoloCapabilities, resetNextHoloProject };
|
|
18
|
+
export type { NextHoloOptions, NextHoloProject };
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
// src/realtime-definition-loader.ts
|
|
2
|
+
import { assertRealtimeDefinitionTree } from "@holo-js/adapter-shared/realtime-directories";
|
|
3
|
+
|
|
1
4
|
// src/realtime-definition-transform.ts
|
|
2
5
|
import {
|
|
3
6
|
createRealtimeClientDefinitionModule as createSharedRealtimeClientDefinitionModule,
|
|
4
7
|
createRealtimeClientDefinitionTransform as createSharedRealtimeClientDefinitionTransform,
|
|
5
8
|
stripRealtimeServerHandlers
|
|
6
9
|
} from "@holo-js/adapter-shared/build";
|
|
7
|
-
function createRealtimeClientDefinitionTransform(source, options = {}) {
|
|
8
|
-
return createSharedRealtimeClientDefinitionTransform(source, "@holo-js/adapter-next/realtime",
|
|
10
|
+
function createRealtimeClientDefinitionTransform(source, filePath, options = {}) {
|
|
11
|
+
return createSharedRealtimeClientDefinitionTransform({ ...options, source, importTarget: "@holo-js/adapter-next/realtime", filePath });
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
// src/realtime-definition-loader.ts
|
|
@@ -14,7 +17,9 @@ function realtimeDefinitionLoader(source) {
|
|
|
14
17
|
if (this.resourceQuery === "?holo-realtime-server") {
|
|
15
18
|
return source;
|
|
16
19
|
}
|
|
17
|
-
const
|
|
20
|
+
const options = this.getOptions?.();
|
|
21
|
+
if (!options?.preserveServerHandlers) assertRealtimeDefinitionTree(this.rootContext ?? process.cwd());
|
|
22
|
+
const result = createRealtimeClientDefinitionTransform(source, this.resourcePath ?? "<realtime module>", options);
|
|
18
23
|
if (this.callback) {
|
|
19
24
|
this.callback(null, result.code, result.map);
|
|
20
25
|
return void 0;
|
package/dist/realtime.mjs
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
query as createRealtimeQuery
|
|
22
22
|
} from "@holo-js/realtime";
|
|
23
23
|
var currentRealtimeError;
|
|
24
|
+
var hydratedSnapshotLoads = /* @__PURE__ */ new WeakMap();
|
|
24
25
|
var realtimeErrorListeners = /* @__PURE__ */ new Set();
|
|
25
26
|
function isBrowserRuntime() {
|
|
26
27
|
return "window" in globalThis;
|
|
@@ -153,6 +154,17 @@ var mutation = ((input) => {
|
|
|
153
154
|
Object.defineProperties(wrappedDefinition, Object.getOwnPropertyDescriptors(definition));
|
|
154
155
|
return wrappedDefinition;
|
|
155
156
|
});
|
|
157
|
+
function fulfilledReactThenable(value) {
|
|
158
|
+
return Object.assign(Promise.resolve(value), { status: "fulfilled", value });
|
|
159
|
+
}
|
|
160
|
+
function loadRealtimeSnapshot(store) {
|
|
161
|
+
if (!store.snapshot) {
|
|
162
|
+
return store.load();
|
|
163
|
+
}
|
|
164
|
+
const hydratedLoad = hydratedSnapshotLoads.get(store) ?? fulfilledReactThenable(store.snapshot);
|
|
165
|
+
hydratedSnapshotLoads.set(store, hydratedLoad);
|
|
166
|
+
return hydratedLoad;
|
|
167
|
+
}
|
|
156
168
|
function useReactiveRealtimeQuery(definition, args) {
|
|
157
169
|
const pendingRealtimeError = getRealtimeErrorSnapshot();
|
|
158
170
|
if (pendingRealtimeError) {
|
|
@@ -182,10 +194,8 @@ function useReactiveRealtimeQuery(definition, args) {
|
|
|
182
194
|
getSnapshot,
|
|
183
195
|
getSnapshot
|
|
184
196
|
);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
return snapshot.data;
|
|
197
|
+
const loadedSnapshot = use(loadRealtimeSnapshot(store));
|
|
198
|
+
return (snapshot ?? loadedSnapshot).data;
|
|
189
199
|
}
|
|
190
200
|
if (isBrowserRuntime()) {
|
|
191
201
|
configureRealtimeClientRuntime({
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NormalizedHoloRedisClusterNodeConfig } from '@holo-js/kernel';
|
|
1
2
|
import * as _holo_js_core_runtime from '@holo-js/core/runtime';
|
|
2
3
|
import { CreateHoloOptions } from '@holo-js/core/runtime';
|
|
3
4
|
import * as _holo_js_config from '@holo-js/config';
|
|
@@ -5,13 +6,6 @@ import { HoloConfigMap, DotPath, HoloConfigValues, ValueAtPath } from '@holo-js/
|
|
|
5
6
|
import { NextRequestLike } from '@holo-js/adapter-shared/next/request-context';
|
|
6
7
|
export { NextRequestLike } from '@holo-js/adapter-shared/next/request-context';
|
|
7
8
|
|
|
8
|
-
interface NormalizedHoloRedisClusterNodeConfig {
|
|
9
|
-
readonly url?: string;
|
|
10
|
-
readonly socketPath?: string;
|
|
11
|
-
readonly host: string;
|
|
12
|
-
readonly port: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
9
|
type SessionCookieSameSite = 'lax' | 'strict' | 'none';
|
|
16
10
|
declare module '@holo-js/config' {
|
|
17
11
|
interface HoloConfigRegistry {
|
|
@@ -81,9 +75,6 @@ interface RotateSessionOptions {
|
|
|
81
75
|
readonly data?: SessionRecord['data'];
|
|
82
76
|
readonly renewLifetime?: boolean;
|
|
83
77
|
}
|
|
84
|
-
interface RememberTokenOptions {
|
|
85
|
-
readonly store?: string;
|
|
86
|
-
}
|
|
87
78
|
interface SessionRecord {
|
|
88
79
|
readonly id: string;
|
|
89
80
|
readonly store: string;
|
|
@@ -91,7 +82,10 @@ interface SessionRecord {
|
|
|
91
82
|
readonly createdAt: Date;
|
|
92
83
|
readonly lastActivityAt: Date;
|
|
93
84
|
readonly expiresAt: Date;
|
|
94
|
-
|
|
85
|
+
}
|
|
86
|
+
interface SessionStoreSetDataResult {
|
|
87
|
+
readonly found: boolean;
|
|
88
|
+
readonly value?: unknown;
|
|
95
89
|
}
|
|
96
90
|
interface CookieSerializeOptions {
|
|
97
91
|
readonly path?: string;
|
|
@@ -104,19 +98,20 @@ interface CookieSerializeOptions {
|
|
|
104
98
|
readonly expires?: Date;
|
|
105
99
|
}
|
|
106
100
|
interface SessionRuntimeFacade {
|
|
101
|
+
rememberMeLifetimeMinutes(): number;
|
|
107
102
|
create(input?: CreateSessionInput): Promise<SessionRecord>;
|
|
108
103
|
write(record: SessionRecord): Promise<SessionRecord>;
|
|
109
104
|
read(sessionId: string, options?: ReadSessionOptions): Promise<SessionRecord | null>;
|
|
110
105
|
rotate(sessionId: string, options?: RotateSessionOptions): Promise<SessionRecord>;
|
|
111
106
|
invalidate(sessionId: string, options?: ReadSessionOptions): Promise<void>;
|
|
112
107
|
touch(sessionId: string, options?: TouchSessionOptions): Promise<SessionRecord | null>;
|
|
113
|
-
issueRememberMeToken(sessionId: string, options?: RememberTokenOptions): Promise<string>;
|
|
114
|
-
consumeRememberMeToken(token: string, options?: RememberTokenOptions): Promise<SessionRecord | null>;
|
|
115
108
|
flash(sessionId: string, key: string, value: unknown, options?: ReadSessionOptions): Promise<void>;
|
|
116
109
|
take<TValue = unknown>(sessionId: string, key: string, options?: ReadSessionOptions): Promise<TValue | undefined>;
|
|
110
|
+
setDataIfAbsent(sessionId: string, key: string, value: unknown, options?: ReadSessionOptions): Promise<SessionStoreSetDataResult>;
|
|
117
111
|
cookie(name: string, value: string, options?: CookieSerializeOptions): string;
|
|
118
112
|
sessionCookie(value: string, options?: CookieSerializeOptions): string;
|
|
119
113
|
rememberMeCookie(value: string, options?: CookieSerializeOptions): string;
|
|
114
|
+
decryptCookie(name: string, value: string): string | undefined;
|
|
120
115
|
}
|
|
121
116
|
|
|
122
117
|
declare function runWithNextRequest<TValue>(request: NextRequestLike, callback: () => TValue): TValue;
|
|
@@ -175,4 +170,5 @@ declare const adapterNextRuntimeInternals: {
|
|
|
175
170
|
createNextHttpAccessFallbackError: typeof createNextHttpAccessFallbackError;
|
|
176
171
|
};
|
|
177
172
|
|
|
178
|
-
export {
|
|
173
|
+
export { adapterNextRuntimeInternals, createNextHoloHelpers, createNextRequestContext, runWithNextRequest };
|
|
174
|
+
export type { NextHoloRuntimeOptions };
|
package/dist/runtime.mjs
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { createRequire } from "module";
|
|
3
3
|
import { resolve } from "path";
|
|
4
4
|
import { initializeHolo } from "@holo-js/core/runtime";
|
|
5
|
-
import {
|
|
5
|
+
import { createCookieWriteUnavailableError } from "@holo-js/kernel";
|
|
6
|
+
import { captureErrorReporter } from "@holo-js/kernel/error-reporting";
|
|
7
|
+
import { serializeValidationException } from "@holo-js/validation";
|
|
6
8
|
import { serializeRateLimitError } from "@holo-js/adapter-shared/server-errors";
|
|
7
9
|
|
|
8
10
|
// src/request-context.ts
|
|
@@ -18,6 +20,82 @@ function setNextAuthRequestRunner(runner) {
|
|
|
18
20
|
globalThis.__holoNextAuthRequestRunner = runner;
|
|
19
21
|
}
|
|
20
22
|
|
|
23
|
+
// src/shutdown.ts
|
|
24
|
+
import { constants } from "os";
|
|
25
|
+
var SHUTDOWN_DEADLINE_MS = 3e4;
|
|
26
|
+
var TERMINATION_SIGNALS = ["SIGINT", "SIGTERM"];
|
|
27
|
+
function shutdownState() {
|
|
28
|
+
const globalState = globalThis;
|
|
29
|
+
globalState.__holoNextShutdown__ ??= { installed: false };
|
|
30
|
+
return globalState.__holoNextShutdown__;
|
|
31
|
+
}
|
|
32
|
+
function closeCurrent() {
|
|
33
|
+
const state = shutdownState();
|
|
34
|
+
state.closing ??= closeUntilStable().finally(() => {
|
|
35
|
+
state.closing = void 0;
|
|
36
|
+
});
|
|
37
|
+
return state.closing;
|
|
38
|
+
}
|
|
39
|
+
async function closeUntilStable() {
|
|
40
|
+
const state = shutdownState();
|
|
41
|
+
while (state.options && state.options !== state.closed) {
|
|
42
|
+
const current = state.options;
|
|
43
|
+
state.closed = current;
|
|
44
|
+
try {
|
|
45
|
+
await current.close();
|
|
46
|
+
} catch (error) {
|
|
47
|
+
current.report(error, { capability: "next", operation: "shutdown" });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function installNextShutdown(options) {
|
|
52
|
+
const state = shutdownState();
|
|
53
|
+
state.options = options;
|
|
54
|
+
if (state.signal) void closeCurrent();
|
|
55
|
+
if (state.installed) return state.uninstall ?? (() => {
|
|
56
|
+
});
|
|
57
|
+
state.installed = true;
|
|
58
|
+
const exit = process.exit;
|
|
59
|
+
const removedDuringEmit = /* @__PURE__ */ new Map();
|
|
60
|
+
const onRemoveListener = (event) => {
|
|
61
|
+
const signal = TERMINATION_SIGNALS.find((candidate) => candidate === event);
|
|
62
|
+
if (!signal) return;
|
|
63
|
+
if (removedDuringEmit.size === 0) queueMicrotask(() => removedDuringEmit.clear());
|
|
64
|
+
removedDuringEmit.set(signal, (removedDuringEmit.get(signal) ?? 0) + 1);
|
|
65
|
+
};
|
|
66
|
+
const onSignal = (signal) => {
|
|
67
|
+
if (state.signal) return;
|
|
68
|
+
state.signal = signal;
|
|
69
|
+
const code = 128 + constants.signals[signal];
|
|
70
|
+
process.exitCode = code;
|
|
71
|
+
const deadline = setTimeout(() => exit.call(process, code), SHUTDOWN_DEADLINE_MS);
|
|
72
|
+
deadline.unref();
|
|
73
|
+
const ownsTermination = process.listenerCount(signal) + (removedDuringEmit.get(signal) ?? 0) === 1;
|
|
74
|
+
setImmediate(() => void closeCurrent().then(() => {
|
|
75
|
+
if (ownsTermination) exit.call(process, code);
|
|
76
|
+
}));
|
|
77
|
+
};
|
|
78
|
+
const listeners = TERMINATION_SIGNALS.map((signal) => [signal, () => onSignal(signal)]);
|
|
79
|
+
const patchedExit = ((code) => {
|
|
80
|
+
if (!state.signal) return exit.call(process, code);
|
|
81
|
+
void closeCurrent().then(() => exit.call(process, code));
|
|
82
|
+
});
|
|
83
|
+
process.exit = patchedExit;
|
|
84
|
+
process.on("removeListener", onRemoveListener);
|
|
85
|
+
for (const [signal, listener] of listeners) process.prependListener(signal, listener);
|
|
86
|
+
function uninstall() {
|
|
87
|
+
if (process.exit === patchedExit) process.exit = exit;
|
|
88
|
+
process.removeListener("removeListener", onRemoveListener);
|
|
89
|
+
for (const [signal, listener] of listeners) process.removeListener(signal, listener);
|
|
90
|
+
state.installed = false;
|
|
91
|
+
state.signal = void 0;
|
|
92
|
+
state.closing = void 0;
|
|
93
|
+
state.closed = void 0;
|
|
94
|
+
}
|
|
95
|
+
state.uninstall = uninstall;
|
|
96
|
+
return uninstall;
|
|
97
|
+
}
|
|
98
|
+
|
|
21
99
|
// src/runtime.ts
|
|
22
100
|
function createNextHttpAccessFallbackError(status, message) {
|
|
23
101
|
const error = new Error(message);
|
|
@@ -107,10 +185,22 @@ function parseRequestCookies(header) {
|
|
|
107
185
|
function isMissingNextRequestScope(error) {
|
|
108
186
|
return error instanceof Error && error.message.includes("outside a request scope");
|
|
109
187
|
}
|
|
188
|
+
function nextCookiesMutableInCurrentPhase(requireNext) {
|
|
189
|
+
try {
|
|
190
|
+
const { workUnitAsyncStorage } = requireNext("next/dist/server/app-render/work-unit-async-storage.external.js");
|
|
191
|
+
return workUnitAsyncStorage.getStore()?.phase === "action";
|
|
192
|
+
} catch {
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function isReadonlyNextCookieStore(error) {
|
|
197
|
+
return error instanceof Error && error.message.startsWith("Cookies can only be modified in a Server Action or Route Handler");
|
|
198
|
+
}
|
|
110
199
|
function createNextRequestContext(request) {
|
|
111
200
|
const nextRequest = request;
|
|
112
201
|
const parsedCookies = nextRequest.cookies ? void 0 : parseRequestCookies(request.headers.get("cookie"));
|
|
113
202
|
return {
|
|
203
|
+
url: request.url,
|
|
114
204
|
headers: request.headers,
|
|
115
205
|
cookies: {
|
|
116
206
|
get(name) {
|
|
@@ -155,17 +245,33 @@ function resolveNextAuthRequestAccessors(projectRoot = process.cwd()) {
|
|
|
155
245
|
throw error;
|
|
156
246
|
}
|
|
157
247
|
},
|
|
248
|
+
async canAppendResponseCookie() {
|
|
249
|
+
try {
|
|
250
|
+
const { cookies } = requireNext("next/headers.js");
|
|
251
|
+
await cookies();
|
|
252
|
+
} catch (error) {
|
|
253
|
+
if (isMissingNextRequestScope(error)) return false;
|
|
254
|
+
throw error;
|
|
255
|
+
}
|
|
256
|
+
return nextCookiesMutableInCurrentPhase(requireNext);
|
|
257
|
+
},
|
|
158
258
|
async appendResponseCookie(cookie) {
|
|
159
259
|
const parsed = parseResponseCookie(cookie);
|
|
160
260
|
if (!parsed) {
|
|
161
|
-
|
|
261
|
+
throw new Error("[@holo-js/adapter-next] An authentication cookie could not be parsed.");
|
|
162
262
|
}
|
|
163
263
|
try {
|
|
164
264
|
const { cookies } = requireNext("next/headers.js");
|
|
165
265
|
const store = await cookies();
|
|
166
266
|
store.set(parsed.name, parsed.value, parsed.options);
|
|
167
267
|
} catch (error) {
|
|
168
|
-
if (
|
|
268
|
+
if (isMissingNextRequestScope(error) || isReadonlyNextCookieStore(error)) {
|
|
269
|
+
throw createCookieWriteUnavailableError(
|
|
270
|
+
"Cookies can only be set in a Server Action or Route Handler, not while rendering a Server Component.",
|
|
271
|
+
error
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
throw error;
|
|
169
275
|
}
|
|
170
276
|
},
|
|
171
277
|
async redirectResponse(url) {
|
|
@@ -177,7 +283,7 @@ function resolveNextAuthRequestAccessors(projectRoot = process.cwd()) {
|
|
|
177
283
|
function createNextHoloHelpers(options) {
|
|
178
284
|
const authRequest = options.authRequest ?? resolveNextAuthRequestAccessors(options.projectRoot);
|
|
179
285
|
const resolveRuntime = async () => {
|
|
180
|
-
const
|
|
286
|
+
const pendingRuntime = initializeHolo(options.projectRoot, {
|
|
181
287
|
...options,
|
|
182
288
|
authRequest,
|
|
183
289
|
authorizationError: options.authorizationError ?? {
|
|
@@ -189,6 +295,17 @@ function createNextHoloHelpers(options) {
|
|
|
189
295
|
}
|
|
190
296
|
}
|
|
191
297
|
});
|
|
298
|
+
let report;
|
|
299
|
+
installNextShutdown({
|
|
300
|
+
close: async () => {
|
|
301
|
+
const runtime2 = await pendingRuntime.catch(() => void 0);
|
|
302
|
+
if (!runtime2) return;
|
|
303
|
+
report = captureErrorReporter();
|
|
304
|
+
await runtime2.shutdown();
|
|
305
|
+
},
|
|
306
|
+
report: (error, context) => (report ?? captureErrorReporter())(error, context)
|
|
307
|
+
});
|
|
308
|
+
const runtime = await pendingRuntime;
|
|
192
309
|
setNextAuthRequestRunner((callback) => runtime.runWithAuthRequestAccessors(authRequest, callback));
|
|
193
310
|
return runtime;
|
|
194
311
|
};
|
|
@@ -229,7 +346,7 @@ function routeHandler(handler) {
|
|
|
229
346
|
try {
|
|
230
347
|
return await handler(...args);
|
|
231
348
|
} catch (error) {
|
|
232
|
-
const payload =
|
|
349
|
+
const payload = serializeValidationException(error) ?? serializeRateLimitError(error);
|
|
233
350
|
if (!payload) throw error;
|
|
234
351
|
return Response.json(payload, {
|
|
235
352
|
status: payload.status,
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/adapter-next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Holo-JS Framework - Next.js adapter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/cobraprojects/holo-js.git",
|
|
10
|
+
"directory": "packages/adapter-next"
|
|
11
|
+
},
|
|
7
12
|
"exports": {
|
|
8
13
|
".": {
|
|
9
14
|
"types": "./dist/index.d.ts",
|
|
@@ -34,7 +39,8 @@
|
|
|
34
39
|
"main": "./dist/index.mjs",
|
|
35
40
|
"types": "./dist/index.d.ts",
|
|
36
41
|
"files": [
|
|
37
|
-
"dist"
|
|
42
|
+
"dist",
|
|
43
|
+
"LICENSE"
|
|
38
44
|
],
|
|
39
45
|
"scripts": {
|
|
40
46
|
"build": "tsup",
|
|
@@ -43,15 +49,16 @@
|
|
|
43
49
|
"test": "vitest --run"
|
|
44
50
|
},
|
|
45
51
|
"dependencies": {
|
|
46
|
-
"@holo-js/adapter-shared": "^0.
|
|
47
|
-
"@holo-js/config": "^0.
|
|
48
|
-
"@holo-js/core": "^0.
|
|
49
|
-
"@holo-js/
|
|
52
|
+
"@holo-js/adapter-shared": "^0.4.0",
|
|
53
|
+
"@holo-js/config": "^0.4.0",
|
|
54
|
+
"@holo-js/core": "^0.4.0",
|
|
55
|
+
"@holo-js/kernel": "^0.4.0",
|
|
56
|
+
"@holo-js/validation": "^0.4.0"
|
|
50
57
|
},
|
|
51
58
|
"peerDependencies": {
|
|
52
|
-
"@holo-js/forms": "^0.
|
|
53
|
-
"@holo-js/realtime": "^0.
|
|
54
|
-
"next": "^16.3
|
|
59
|
+
"@holo-js/forms": "^0.4.0",
|
|
60
|
+
"@holo-js/realtime": "^0.4.0",
|
|
61
|
+
"next": "^16.4.3",
|
|
55
62
|
"react": "^19.2.6"
|
|
56
63
|
},
|
|
57
64
|
"peerDependenciesMeta": {
|
|
@@ -63,14 +70,14 @@
|
|
|
63
70
|
}
|
|
64
71
|
},
|
|
65
72
|
"devDependencies": {
|
|
66
|
-
"@holo-js/realtime": "^0.
|
|
67
|
-
"@types/node": "^22.
|
|
68
|
-
"next": "^16.3
|
|
69
|
-
"tsup": "^
|
|
70
|
-
"typescript": "^
|
|
71
|
-
"vitest": "^
|
|
73
|
+
"@holo-js/realtime": "^0.4.0",
|
|
74
|
+
"@types/node": "^22.20.5",
|
|
75
|
+
"next": "^16.4.3",
|
|
76
|
+
"tsup": "^9.0.0",
|
|
77
|
+
"typescript": "^6.0.3",
|
|
78
|
+
"vitest": "^5.0.5"
|
|
72
79
|
},
|
|
73
80
|
"engines": {
|
|
74
|
-
"node": "^22.
|
|
81
|
+
"node": "^22.18.0 || ^24.0.0 || ^26.0.0"
|
|
75
82
|
}
|
|
76
83
|
}
|