@holo-js/adapter-next 0.3.1 → 0.3.3
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/config.mjs
CHANGED
|
@@ -4,7 +4,6 @@ import { fileURLToPath } from "url";
|
|
|
4
4
|
import { join } from "path";
|
|
5
5
|
var HOLO_SERVER_EXTERNAL_PACKAGES = [
|
|
6
6
|
"@holo-js/core",
|
|
7
|
-
"@holo-js/adapter-next",
|
|
8
7
|
"@holo-js/db",
|
|
9
8
|
"@holo-js/config",
|
|
10
9
|
"esbuild"
|
|
@@ -39,10 +38,13 @@ var HOLO_OPTIONAL_SERVER_EXTERNAL_PACKAGES = [
|
|
|
39
38
|
"@holo-js/validation"
|
|
40
39
|
];
|
|
41
40
|
var HOLO_TRANSPILED_PACKAGES = [
|
|
41
|
+
"@holo-js/adapter-next",
|
|
42
42
|
"@holo-js/auth"
|
|
43
43
|
];
|
|
44
44
|
var HOLO_TRANSPILED_PACKAGE_SET = new Set(HOLO_TRANSPILED_PACKAGES);
|
|
45
45
|
var NEXT_AUTH_INTERRUPTS_ENV = "__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS";
|
|
46
|
+
var CORE_RUNTIME_CHUNK_PATH = /packages[\\/]core[\\/]dist[\\/].+\.mjs$/;
|
|
47
|
+
var OPTIONAL_RUNTIME_IMPORT_ISSUE = /Module not found: Can't resolve (?:'@holo-js\/storage-s3'|<dynamic>)/;
|
|
46
48
|
var PACKAGE_DEPENDENCY_FIELDS = [
|
|
47
49
|
"dependencies",
|
|
48
50
|
"devDependencies",
|
|
@@ -73,23 +75,30 @@ function readProjectPackageManifest() {
|
|
|
73
75
|
function isOptionalServerExternalPackageInstalled(packageName, manifest) {
|
|
74
76
|
return PACKAGE_DEPENDENCY_FIELDS.some((field) => Boolean(manifest?.[field]?.[packageName]));
|
|
75
77
|
}
|
|
76
|
-
function createRealtimeDefinitionWebpackRule(loaderPath) {
|
|
78
|
+
function createRealtimeDefinitionWebpackRule(loaderPath, preserveServerHandlers) {
|
|
77
79
|
return {
|
|
78
80
|
test: /(?:^|[\\/])server[\\/]realtime[\\/].+\.[cm]?[jt]sx?$/,
|
|
79
|
-
use: [
|
|
81
|
+
use: [{
|
|
82
|
+
loader: loaderPath,
|
|
83
|
+
options: { preserveServerHandlers }
|
|
84
|
+
}]
|
|
80
85
|
};
|
|
81
86
|
}
|
|
82
|
-
function createRealtimeDefinitionTurbopackRule(loaderPath) {
|
|
87
|
+
function createRealtimeDefinitionTurbopackRule(loaderPath, environment) {
|
|
88
|
+
const environmentCondition = environment === "browser" ? "browser" : { any: ["node", "edge-light"] };
|
|
83
89
|
return {
|
|
84
90
|
condition: {
|
|
85
91
|
all: [
|
|
86
|
-
|
|
92
|
+
environmentCondition,
|
|
87
93
|
{
|
|
88
94
|
path: /(?:^|[\\/])server[\\/]realtime[\\/]/
|
|
89
95
|
}
|
|
90
96
|
]
|
|
91
97
|
},
|
|
92
|
-
loaders: [
|
|
98
|
+
loaders: [{
|
|
99
|
+
loader: loaderPath,
|
|
100
|
+
options: { preserveServerHandlers: environment === "server" }
|
|
101
|
+
}],
|
|
93
102
|
as: "*.js"
|
|
94
103
|
};
|
|
95
104
|
}
|
|
@@ -120,12 +129,17 @@ function withHolo(nextConfig = {}) {
|
|
|
120
129
|
...existingTurbopack.rules ?? {},
|
|
121
130
|
...hasRealtime ? {
|
|
122
131
|
"*.{ts,tsx,js,jsx,mts,mjs,cts,cjs}": [
|
|
123
|
-
createRealtimeDefinitionTurbopackRule(realtimeDefinitionLoader)
|
|
132
|
+
createRealtimeDefinitionTurbopackRule(realtimeDefinitionLoader, "browser"),
|
|
133
|
+
createRealtimeDefinitionTurbopackRule(realtimeDefinitionLoader, "server")
|
|
124
134
|
]
|
|
125
135
|
} : {}
|
|
126
136
|
},
|
|
127
137
|
ignoreIssue: [
|
|
128
138
|
...existingIgnoreIssue,
|
|
139
|
+
{
|
|
140
|
+
path: CORE_RUNTIME_CHUNK_PATH,
|
|
141
|
+
title: OPTIONAL_RUNTIME_IMPORT_ISSUE
|
|
142
|
+
},
|
|
129
143
|
{
|
|
130
144
|
path: /next\.config\.(ts|mjs|js)$/,
|
|
131
145
|
title: /Encountered unexpected file in NFT list/
|
|
@@ -146,13 +160,13 @@ function withHolo(nextConfig = {}) {
|
|
|
146
160
|
turbopack: mergedTurbopack,
|
|
147
161
|
webpack(config, context) {
|
|
148
162
|
const nextWebpackConfig = userWebpack?.(config, context) ?? config;
|
|
149
|
-
if (!hasRealtime
|
|
163
|
+
if (!hasRealtime) {
|
|
150
164
|
return nextWebpackConfig;
|
|
151
165
|
}
|
|
152
166
|
nextWebpackConfig.module = nextWebpackConfig.module ?? {};
|
|
153
167
|
nextWebpackConfig.module.rules = [
|
|
154
168
|
...nextWebpackConfig.module.rules ?? [],
|
|
155
|
-
createRealtimeDefinitionWebpackRule(realtimeDefinitionLoader)
|
|
169
|
+
createRealtimeDefinitionWebpackRule(realtimeDefinitionLoader, context.isServer)
|
|
156
170
|
];
|
|
157
171
|
return nextWebpackConfig;
|
|
158
172
|
},
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
type LoaderContext = {
|
|
2
2
|
cacheable?: () => void;
|
|
3
3
|
callback?(error: null, code: string, map: object): void;
|
|
4
|
+
getOptions?(): {
|
|
5
|
+
readonly preserveServerHandlers?: boolean;
|
|
6
|
+
};
|
|
7
|
+
readonly resourceQuery?: string;
|
|
4
8
|
};
|
|
5
9
|
declare function realtimeDefinitionLoader(this: LoaderContext, source: string): string | undefined;
|
|
6
10
|
|
|
@@ -4,14 +4,17 @@ import {
|
|
|
4
4
|
createRealtimeClientDefinitionTransform as createSharedRealtimeClientDefinitionTransform,
|
|
5
5
|
stripRealtimeServerHandlers
|
|
6
6
|
} from "@holo-js/adapter-shared";
|
|
7
|
-
function createRealtimeClientDefinitionTransform(source) {
|
|
8
|
-
return createSharedRealtimeClientDefinitionTransform(source, "@holo-js/adapter-next/realtime");
|
|
7
|
+
function createRealtimeClientDefinitionTransform(source, options = {}) {
|
|
8
|
+
return createSharedRealtimeClientDefinitionTransform(source, "@holo-js/adapter-next/realtime", options);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
// src/realtime-definition-loader.ts
|
|
12
12
|
function realtimeDefinitionLoader(source) {
|
|
13
13
|
this.cacheable?.();
|
|
14
|
-
|
|
14
|
+
if (this.resourceQuery === "?holo-realtime-server") {
|
|
15
|
+
return source;
|
|
16
|
+
}
|
|
17
|
+
const result = createRealtimeClientDefinitionTransform(source, this.getOptions?.());
|
|
15
18
|
if (this.callback) {
|
|
16
19
|
this.callback(null, result.code, result.map);
|
|
17
20
|
return void 0;
|
package/dist/realtime.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import * as _holo_js_realtime from '@holo-js/realtime';
|
|
2
|
-
import { mutation as mutation$1 } from '@holo-js/realtime';
|
|
3
1
|
import { RealtimeClientTransport } from '@holo-js/realtime/client';
|
|
2
|
+
import { mutation as mutation$1, query as query$1 } from '@holo-js/realtime';
|
|
4
3
|
|
|
5
4
|
declare function subscribeRealtimeError(listener: () => void): () => void;
|
|
6
5
|
declare function emitRealtimeError(error: unknown): void;
|
|
7
6
|
declare function getRealtimeErrorSnapshot(): Error | undefined;
|
|
8
7
|
declare function consumeRealtimeError(): Error | undefined;
|
|
9
8
|
declare function createErrorHandlingRealtimeTransport(transport: RealtimeClientTransport): RealtimeClientTransport;
|
|
10
|
-
declare const query: typeof
|
|
9
|
+
declare const query: typeof query$1;
|
|
11
10
|
declare const mutation: typeof mutation$1;
|
|
12
11
|
declare const adapterNextRealtimeInternals: {
|
|
13
12
|
subscribeRealtimeError: typeof subscribeRealtimeError;
|
package/dist/realtime.mjs
CHANGED
|
@@ -6,12 +6,15 @@ import {
|
|
|
6
6
|
} from "./chunk-VBBQ4VXY.mjs";
|
|
7
7
|
|
|
8
8
|
// src/realtime.ts
|
|
9
|
-
import { useEffect, useSyncExternalStore } from "react";
|
|
9
|
+
import { cache, createElement, use, useEffect, useMemo, useSyncExternalStore } from "react";
|
|
10
|
+
import { useServerInsertedHTML } from "next/navigation";
|
|
10
11
|
import {
|
|
11
12
|
configureRealtimeClientRuntime,
|
|
12
13
|
configureRealtimeClientTransport,
|
|
13
14
|
createBroadcastRealtimeTransport,
|
|
14
|
-
getRealtimeQueryStore
|
|
15
|
+
getRealtimeQueryStore,
|
|
16
|
+
hydrateRealtimeQuery,
|
|
17
|
+
realtimeClientInternals
|
|
15
18
|
} from "@holo-js/realtime/client";
|
|
16
19
|
import {
|
|
17
20
|
mutation as createRealtimeMutation,
|
|
@@ -19,6 +22,33 @@ import {
|
|
|
19
22
|
} from "@holo-js/realtime";
|
|
20
23
|
var currentRealtimeError;
|
|
21
24
|
var realtimeErrorListeners = /* @__PURE__ */ new Set();
|
|
25
|
+
function isBrowserRuntime() {
|
|
26
|
+
return "window" in globalThis;
|
|
27
|
+
}
|
|
28
|
+
function createHydrationElementId(definitionName, serializedArgs) {
|
|
29
|
+
let hash = 2166136261;
|
|
30
|
+
const value = `${definitionName}:${serializedArgs}`;
|
|
31
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
32
|
+
hash ^= value.charCodeAt(index);
|
|
33
|
+
hash = Math.imul(hash, 16777619);
|
|
34
|
+
}
|
|
35
|
+
return `__holo_realtime_${(hash >>> 0).toString(36)}`;
|
|
36
|
+
}
|
|
37
|
+
function serializeHydrationData(value) {
|
|
38
|
+
return JSON.stringify({ data: value }).replace(/</g, "\\u003c");
|
|
39
|
+
}
|
|
40
|
+
function hydrateRealtimeQueryFromDocument(definition, args, elementId) {
|
|
41
|
+
const runtime = globalThis;
|
|
42
|
+
const element = runtime.document?.getElementById(elementId);
|
|
43
|
+
if (!element?.textContent) return;
|
|
44
|
+
const parsed = JSON.parse(element.textContent);
|
|
45
|
+
hydrateRealtimeQuery(definition, args, {
|
|
46
|
+
name: definition.name,
|
|
47
|
+
data: parsed.data,
|
|
48
|
+
dependencies: [],
|
|
49
|
+
version: 0
|
|
50
|
+
});
|
|
51
|
+
}
|
|
22
52
|
function subscribeRealtimeError(listener) {
|
|
23
53
|
realtimeErrorListeners.add(listener);
|
|
24
54
|
return () => {
|
|
@@ -70,7 +100,49 @@ function createErrorHandlingRealtimeTransport(transport) {
|
|
|
70
100
|
}
|
|
71
101
|
};
|
|
72
102
|
}
|
|
73
|
-
var
|
|
103
|
+
var resolveServerRealtimeQuery = cache(async (definition, serializedArgs) => {
|
|
104
|
+
const args = JSON.parse(serializedArgs);
|
|
105
|
+
return await Promise.resolve(Reflect.apply(definition, void 0, [args]));
|
|
106
|
+
});
|
|
107
|
+
var query = ((input) => {
|
|
108
|
+
const definition = createRealtimeQuery(input);
|
|
109
|
+
const wrappedDefinition = ((...args) => {
|
|
110
|
+
const normalizedArgs = args[0] ?? {};
|
|
111
|
+
const serializedArgs = realtimeClientInternals.stableStringify(normalizedArgs);
|
|
112
|
+
const hydrationElementId = createHydrationElementId(definition.name, serializedArgs);
|
|
113
|
+
const hydration = {
|
|
114
|
+
result: void 0,
|
|
115
|
+
hasResult: false,
|
|
116
|
+
inserted: false
|
|
117
|
+
};
|
|
118
|
+
useServerInsertedHTML(() => {
|
|
119
|
+
if (!hydration.hasResult || hydration.inserted) return null;
|
|
120
|
+
hydration.inserted = true;
|
|
121
|
+
return createElement("script", {
|
|
122
|
+
id: hydrationElementId,
|
|
123
|
+
type: "application/json",
|
|
124
|
+
dangerouslySetInnerHTML: { __html: serializeHydrationData(hydration.result) }
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
if (isBrowserRuntime()) {
|
|
128
|
+
hydrateRealtimeQueryFromDocument(
|
|
129
|
+
definition,
|
|
130
|
+
normalizedArgs,
|
|
131
|
+
hydrationElementId
|
|
132
|
+
);
|
|
133
|
+
return Reflect.apply(definition, void 0, args);
|
|
134
|
+
}
|
|
135
|
+
const result = use(resolveServerRealtimeQuery(
|
|
136
|
+
definition,
|
|
137
|
+
serializedArgs
|
|
138
|
+
));
|
|
139
|
+
hydration.result = result;
|
|
140
|
+
hydration.hasResult = true;
|
|
141
|
+
return result;
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperties(wrappedDefinition, Object.getOwnPropertyDescriptors(definition));
|
|
144
|
+
return wrappedDefinition;
|
|
145
|
+
});
|
|
74
146
|
var mutation = ((input) => {
|
|
75
147
|
const definition = createRealtimeMutation(input);
|
|
76
148
|
const wrappedDefinition = ((...args) => {
|
|
@@ -82,6 +154,16 @@ var mutation = ((input) => {
|
|
|
82
154
|
return wrappedDefinition;
|
|
83
155
|
});
|
|
84
156
|
function useReactiveRealtimeQuery(definition, args) {
|
|
157
|
+
const pendingRealtimeError = getRealtimeErrorSnapshot();
|
|
158
|
+
if (pendingRealtimeError) {
|
|
159
|
+
consumeRealtimeError();
|
|
160
|
+
throw pendingRealtimeError;
|
|
161
|
+
}
|
|
162
|
+
const serializedArgs = realtimeClientInternals.stableStringify(args);
|
|
163
|
+
const store = useMemo(
|
|
164
|
+
() => getRealtimeQueryStore(definition, args),
|
|
165
|
+
[definition, serializedArgs]
|
|
166
|
+
);
|
|
85
167
|
const realtimeError = useSyncExternalStore(
|
|
86
168
|
subscribeRealtimeError,
|
|
87
169
|
getRealtimeErrorSnapshot,
|
|
@@ -91,7 +173,6 @@ function useReactiveRealtimeQuery(definition, args) {
|
|
|
91
173
|
consumeRealtimeError();
|
|
92
174
|
throw realtimeError;
|
|
93
175
|
}
|
|
94
|
-
const store = getRealtimeQueryStore(definition, args);
|
|
95
176
|
useEffect(() => {
|
|
96
177
|
store.connect();
|
|
97
178
|
}, [store]);
|
|
@@ -103,11 +184,13 @@ function useReactiveRealtimeQuery(definition, args) {
|
|
|
103
184
|
);
|
|
104
185
|
return snapshot?.data;
|
|
105
186
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
187
|
+
if (isBrowserRuntime()) {
|
|
188
|
+
configureRealtimeClientRuntime({
|
|
189
|
+
handleError: emitRealtimeError,
|
|
190
|
+
useQuery: useReactiveRealtimeQuery
|
|
191
|
+
});
|
|
192
|
+
configureRealtimeClientTransport(createErrorHandlingRealtimeTransport(createBroadcastRealtimeTransport()));
|
|
193
|
+
}
|
|
111
194
|
var adapterNextRealtimeInternals = {
|
|
112
195
|
subscribeRealtimeError,
|
|
113
196
|
emitRealtimeError,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/adapter-next",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Holo-JS Framework - Next.js adapter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"test": "vitest --run"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@holo-js/adapter-shared": "^0.3.
|
|
47
|
-
"@holo-js/config": "^0.3.
|
|
48
|
-
"@holo-js/core": "^0.3.
|
|
46
|
+
"@holo-js/adapter-shared": "^0.3.3",
|
|
47
|
+
"@holo-js/config": "^0.3.3",
|
|
48
|
+
"@holo-js/core": "^0.3.3"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@holo-js/forms": "^0.3.
|
|
52
|
-
"@holo-js/realtime": "^0.3.
|
|
51
|
+
"@holo-js/forms": "^0.3.3",
|
|
52
|
+
"@holo-js/realtime": "^0.3.3",
|
|
53
53
|
"next": "^16.2.4",
|
|
54
54
|
"react": "^19.2.6"
|
|
55
55
|
},
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@holo-js/realtime": "^0.3.
|
|
65
|
+
"@holo-js/realtime": "^0.3.3",
|
|
66
66
|
"@types/node": "^22.10.2",
|
|
67
67
|
"next": "^16.2.4",
|
|
68
68
|
"tsup": "^8.3.5",
|