@holo-js/adapter-next 0.3.1 → 0.3.2
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,6 +38,7 @@ 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);
|
|
@@ -73,23 +73,30 @@ function readProjectPackageManifest() {
|
|
|
73
73
|
function isOptionalServerExternalPackageInstalled(packageName, manifest) {
|
|
74
74
|
return PACKAGE_DEPENDENCY_FIELDS.some((field) => Boolean(manifest?.[field]?.[packageName]));
|
|
75
75
|
}
|
|
76
|
-
function createRealtimeDefinitionWebpackRule(loaderPath) {
|
|
76
|
+
function createRealtimeDefinitionWebpackRule(loaderPath, preserveServerHandlers) {
|
|
77
77
|
return {
|
|
78
78
|
test: /(?:^|[\\/])server[\\/]realtime[\\/].+\.[cm]?[jt]sx?$/,
|
|
79
|
-
use: [
|
|
79
|
+
use: [{
|
|
80
|
+
loader: loaderPath,
|
|
81
|
+
options: { preserveServerHandlers }
|
|
82
|
+
}]
|
|
80
83
|
};
|
|
81
84
|
}
|
|
82
|
-
function createRealtimeDefinitionTurbopackRule(loaderPath) {
|
|
85
|
+
function createRealtimeDefinitionTurbopackRule(loaderPath, environment) {
|
|
86
|
+
const environmentCondition = environment === "browser" ? "browser" : { any: ["node", "edge-light"] };
|
|
83
87
|
return {
|
|
84
88
|
condition: {
|
|
85
89
|
all: [
|
|
86
|
-
|
|
90
|
+
environmentCondition,
|
|
87
91
|
{
|
|
88
92
|
path: /(?:^|[\\/])server[\\/]realtime[\\/]/
|
|
89
93
|
}
|
|
90
94
|
]
|
|
91
95
|
},
|
|
92
|
-
loaders: [
|
|
96
|
+
loaders: [{
|
|
97
|
+
loader: loaderPath,
|
|
98
|
+
options: { preserveServerHandlers: environment === "server" }
|
|
99
|
+
}],
|
|
93
100
|
as: "*.js"
|
|
94
101
|
};
|
|
95
102
|
}
|
|
@@ -120,7 +127,8 @@ function withHolo(nextConfig = {}) {
|
|
|
120
127
|
...existingTurbopack.rules ?? {},
|
|
121
128
|
...hasRealtime ? {
|
|
122
129
|
"*.{ts,tsx,js,jsx,mts,mjs,cts,cjs}": [
|
|
123
|
-
createRealtimeDefinitionTurbopackRule(realtimeDefinitionLoader)
|
|
130
|
+
createRealtimeDefinitionTurbopackRule(realtimeDefinitionLoader, "browser"),
|
|
131
|
+
createRealtimeDefinitionTurbopackRule(realtimeDefinitionLoader, "server")
|
|
124
132
|
]
|
|
125
133
|
} : {}
|
|
126
134
|
},
|
|
@@ -146,13 +154,13 @@ function withHolo(nextConfig = {}) {
|
|
|
146
154
|
turbopack: mergedTurbopack,
|
|
147
155
|
webpack(config, context) {
|
|
148
156
|
const nextWebpackConfig = userWebpack?.(config, context) ?? config;
|
|
149
|
-
if (!hasRealtime
|
|
157
|
+
if (!hasRealtime) {
|
|
150
158
|
return nextWebpackConfig;
|
|
151
159
|
}
|
|
152
160
|
nextWebpackConfig.module = nextWebpackConfig.module ?? {};
|
|
153
161
|
nextWebpackConfig.module.rules = [
|
|
154
162
|
...nextWebpackConfig.module.rules ?? [],
|
|
155
|
-
createRealtimeDefinitionWebpackRule(realtimeDefinitionLoader)
|
|
163
|
+
createRealtimeDefinitionWebpackRule(realtimeDefinitionLoader, context.isServer)
|
|
156
164
|
];
|
|
157
165
|
return nextWebpackConfig;
|
|
158
166
|
},
|
|
@@ -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.2",
|
|
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.2",
|
|
47
|
+
"@holo-js/config": "^0.3.2",
|
|
48
|
+
"@holo-js/core": "^0.3.2"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@holo-js/forms": "^0.3.
|
|
52
|
-
"@holo-js/realtime": "^0.3.
|
|
51
|
+
"@holo-js/forms": "^0.3.2",
|
|
52
|
+
"@holo-js/realtime": "^0.3.2",
|
|
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.2",
|
|
66
66
|
"@types/node": "^22.10.2",
|
|
67
67
|
"next": "^16.2.4",
|
|
68
68
|
"tsup": "^8.3.5",
|