@valbuild/next 0.63.3 → 0.64.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/README.md +6 -6
- package/dist/declarations/src/external_exempt_from_val_quickjs.d.ts +7 -0
- package/dist/declarations/src/rsc/initValRsc.d.ts +4 -4
- package/dist/declarations/src/server/initValServer.d.ts +2 -2
- package/package.json +6 -5
- package/rsc/dist/valbuild-next-rsc.cjs.dev.js +128 -45
- package/rsc/dist/valbuild-next-rsc.cjs.prod.js +128 -45
- package/rsc/dist/valbuild-next-rsc.esm.js +129 -46
package/README.md
CHANGED
|
@@ -200,7 +200,7 @@ export const schema = s.object({
|
|
|
200
200
|
bold: true, // <- Enables bold in richtext
|
|
201
201
|
},
|
|
202
202
|
}),
|
|
203
|
-
})
|
|
203
|
+
}),
|
|
204
204
|
),
|
|
205
205
|
});
|
|
206
206
|
|
|
@@ -223,7 +223,7 @@ export default c.define(
|
|
|
223
223
|
],
|
|
224
224
|
},
|
|
225
225
|
],
|
|
226
|
-
}
|
|
226
|
+
},
|
|
227
227
|
);
|
|
228
228
|
```
|
|
229
229
|
|
|
@@ -524,7 +524,7 @@ export function ValRichText({
|
|
|
524
524
|
}) {
|
|
525
525
|
function build(
|
|
526
526
|
node: RichTextNode<MyRichTextOptions>,
|
|
527
|
-
key?: number
|
|
527
|
+
key?: number,
|
|
528
528
|
): JSX.Element | string {
|
|
529
529
|
if (typeof node === "string") {
|
|
530
530
|
return node;
|
|
@@ -543,7 +543,7 @@ export function ValRichText({
|
|
|
543
543
|
key,
|
|
544
544
|
className,
|
|
545
545
|
},
|
|
546
|
-
"children" in node ? node.children.map(build) : null
|
|
546
|
+
"children" in node ? node.children.map(build) : null,
|
|
547
547
|
);
|
|
548
548
|
}
|
|
549
549
|
return <div {...val.attrs(root)}>{root.children.map(build)}</div>;
|
|
@@ -622,7 +622,7 @@ s.union(
|
|
|
622
622
|
type: s.literal("productPage"),
|
|
623
623
|
sku: s.number(),
|
|
624
624
|
// ...
|
|
625
|
-
})
|
|
625
|
+
}),
|
|
626
626
|
); // <- Schema<{ type: "blogPage", author: string } | { type: "productPage", sku: number }>
|
|
627
627
|
```
|
|
628
628
|
|
|
@@ -633,7 +633,7 @@ You can also use a union to create a union of string literals. This is useful if
|
|
|
633
633
|
```ts
|
|
634
634
|
s.union(
|
|
635
635
|
s.literal("one"),
|
|
636
|
-
s.literal("two")
|
|
636
|
+
s.literal("two"),
|
|
637
637
|
//...
|
|
638
638
|
); // <- Schema<"one" | "two">
|
|
639
639
|
```
|
|
@@ -35,6 +35,13 @@ export declare const Internal: {
|
|
|
35
35
|
createValPathOfItem: typeof import("@valbuild/core/dist/declarations/src/selector/SelectorProxy").createValPathOfItem;
|
|
36
36
|
getSHA256Hash: (bits: Uint8Array) => string;
|
|
37
37
|
initSchema: typeof import("@valbuild/core/dist/declarations/src/initSchema").initSchema;
|
|
38
|
+
getMimeType: typeof import("@valbuild/core/dist/declarations/src/mimeType").getMimeType;
|
|
39
|
+
mimeTypeToFileExt: typeof import("@valbuild/core/dist/declarations/src/mimeType").mimeTypeToFileExt;
|
|
40
|
+
filenameToMimeType: typeof import("@valbuild/core/dist/declarations/src/mimeType").filenameToMimeType;
|
|
41
|
+
EXT_TO_MIME_TYPES: Record<string, string>;
|
|
42
|
+
MIME_TYPES_TO_EXT: {
|
|
43
|
+
[k: string]: string;
|
|
44
|
+
};
|
|
38
45
|
ModuleFilePathSep: string;
|
|
39
46
|
notFileOp: (op: import("@valbuild/core/patch").Operation) => boolean;
|
|
40
47
|
isFileOp: (op: import("@valbuild/core/patch").Operation) => op is {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type StegaOfSource } from "@valbuild/react/stega";
|
|
2
|
-
import { SelectorSource, SelectorOf, GenericSelector } from "@valbuild/core";
|
|
3
|
-
import { ValConfig } from "@valbuild/core";
|
|
2
|
+
import { SelectorSource, SelectorOf, GenericSelector, ValConfig, ValModules } from "@valbuild/core";
|
|
4
3
|
import { cookies, draftMode, headers } from "next/headers";
|
|
5
|
-
|
|
4
|
+
import { ValServer } from "@valbuild/server";
|
|
5
|
+
declare const initFetchValStega: (config: ValConfig, valApiEndpoints: string, valServerPromise: Promise<ValServer>, isEnabled: () => boolean, getHeaders: () => Headers, getCookies: () => {
|
|
6
6
|
get(name: string): {
|
|
7
7
|
name: string;
|
|
8
8
|
value: string;
|
|
@@ -13,7 +13,7 @@ type ValNextRscConfig = {
|
|
|
13
13
|
headers: typeof headers;
|
|
14
14
|
cookies: typeof cookies;
|
|
15
15
|
};
|
|
16
|
-
export declare function initValRsc(config: ValConfig, rscNextConfig: ValNextRscConfig): {
|
|
16
|
+
export declare function initValRsc(config: ValConfig, valModules: ValModules, rscNextConfig: ValNextRscConfig): {
|
|
17
17
|
fetchValStega: ReturnType<typeof initFetchValStega>;
|
|
18
18
|
};
|
|
19
19
|
export {};
|
|
@@ -2,11 +2,11 @@ import { ValConfig, ValModules } from "@valbuild/core";
|
|
|
2
2
|
import type { draftMode } from "next/headers";
|
|
3
3
|
import { NextResponse } from "next/server";
|
|
4
4
|
declare const initValNextAppRouter: (valModules: ValModules, config: ValConfig, nextConfig: ValServerNextConfig & {
|
|
5
|
-
formatter?: ((code: string, filePath: string) => string) | undefined;
|
|
5
|
+
formatter?: ((code: string, filePath: string) => Promise<string> | string) | undefined;
|
|
6
6
|
}) => (req: Request) => Promise<NextResponse<unknown>>;
|
|
7
7
|
type ValServerNextConfig = {
|
|
8
8
|
draftMode: typeof draftMode;
|
|
9
|
-
formatter?: (code: string, filePath: string) => string;
|
|
9
|
+
formatter?: (code: string, filePath: string) => Promise<string> | string;
|
|
10
10
|
};
|
|
11
11
|
export declare function initValServer(valModules: ValModules, config: ValConfig & {
|
|
12
12
|
disableCache?: boolean;
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"next",
|
|
9
9
|
"react"
|
|
10
10
|
],
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.64.0",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"typecheck": "tsc --noEmit",
|
|
14
14
|
"test": "jest"
|
|
@@ -45,10 +45,11 @@
|
|
|
45
45
|
"exports": true
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@valbuild/core": "~0.
|
|
49
|
-
"@valbuild/react": "~0.
|
|
50
|
-
"@valbuild/server": "~0.
|
|
51
|
-
"@valbuild/
|
|
48
|
+
"@valbuild/core": "~0.64.0",
|
|
49
|
+
"@valbuild/react": "~0.64.0",
|
|
50
|
+
"@valbuild/server": "~0.64.0",
|
|
51
|
+
"@valbuild/shared": "~0.64.0",
|
|
52
|
+
"@valbuild/ui": "~0.64.0",
|
|
52
53
|
"client-only": "^0.0.1",
|
|
53
54
|
"server-only": "^0.0.1"
|
|
54
55
|
},
|
|
@@ -3,12 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
require('server-only');
|
|
6
|
+
var objectSpread2 = require('../../dist/objectSpread2-bb9509e8.cjs.dev.js');
|
|
6
7
|
var asyncToGenerator = require('../../dist/asyncToGenerator-ba66657c.cjs.dev.js');
|
|
7
8
|
var stega = require('@valbuild/react/stega');
|
|
8
9
|
var core = require('@valbuild/core');
|
|
9
|
-
var
|
|
10
|
+
var internal = require('@valbuild/shared/internal');
|
|
11
|
+
var server = require('@valbuild/server');
|
|
12
|
+
var version = require('../../dist/version-82faa1d0.cjs.dev.js');
|
|
10
13
|
|
|
11
|
-
var initFetchValStega = function initFetchValStega(config, valApiEndpoints, isEnabled, getHeaders, getCookies) {
|
|
14
|
+
var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies) {
|
|
12
15
|
return function (selector) {
|
|
13
16
|
var enabled = false;
|
|
14
17
|
try {
|
|
@@ -28,58 +31,84 @@ var initFetchValStega = function initFetchValStega(config, valApiEndpoints, isEn
|
|
|
28
31
|
console.error("Val: could not read headers! fetchVal can only be used server-side. Use useVal on clients.", err);
|
|
29
32
|
headers = null;
|
|
30
33
|
}
|
|
31
|
-
var cookies
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
var cookies = function () {
|
|
35
|
+
try {
|
|
36
|
+
return getCookies();
|
|
37
|
+
} catch (err) {
|
|
38
|
+
console.error("Val: could not read cookies! fetchVal can only be used server-side. Use useVal on clients.", err);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}();
|
|
38
42
|
var host = headers && getHost(headers);
|
|
39
43
|
if (host && cookies) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var allPatches;
|
|
44
|
+
return valServerPromise.then( /*#__PURE__*/function () {
|
|
45
|
+
var _ref = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator._regeneratorRuntime().mark(function _callee(valServer) {
|
|
46
|
+
var _cookies$get, _cookies$get2;
|
|
47
|
+
var patchesRes, allPatches, treeRes, modules;
|
|
44
48
|
return asyncToGenerator._regeneratorRuntime().wrap(function _callee$(_context) {
|
|
45
49
|
while (1) switch (_context.prev = _context.next) {
|
|
46
50
|
case 0:
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
_context.next = 2;
|
|
52
|
+
return valServer["/patches/~"]["GET"]({
|
|
53
|
+
query: {
|
|
54
|
+
omit_patch: true,
|
|
55
|
+
author: undefined,
|
|
56
|
+
patch_id: undefined,
|
|
57
|
+
module_file_path: undefined
|
|
58
|
+
},
|
|
59
|
+
cookies: objectSpread2._defineProperty({}, internal.VAL_SESSION_COOKIE, (_cookies$get = cookies.get(internal.VAL_SESSION_COOKIE)) === null || _cookies$get === void 0 ? void 0 : _cookies$get.value)
|
|
60
|
+
});
|
|
61
|
+
case 2:
|
|
62
|
+
patchesRes = _context.sent;
|
|
63
|
+
if (!(patchesRes.status !== 200)) {
|
|
64
|
+
_context.next = 6;
|
|
49
65
|
break;
|
|
50
66
|
}
|
|
51
|
-
console.error("Val: could not fetch patches", patchesRes.
|
|
52
|
-
throw Error(JSON.stringify(patchesRes.
|
|
53
|
-
case
|
|
54
|
-
allPatches = Object.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
67
|
+
console.error("Val: could not fetch patches", patchesRes.json);
|
|
68
|
+
throw Error(JSON.stringify(patchesRes.json, null, 2));
|
|
69
|
+
case 6:
|
|
70
|
+
allPatches = Object.keys(patchesRes.json.patches);
|
|
71
|
+
_context.next = 9;
|
|
72
|
+
return valServer["/tree/~"]["PUT"]({
|
|
73
|
+
path: "/",
|
|
74
|
+
query: {
|
|
75
|
+
validate_sources: true,
|
|
76
|
+
validate_all: false,
|
|
77
|
+
validate_binary_files: false
|
|
78
|
+
},
|
|
79
|
+
body: {
|
|
80
|
+
patchIds: allPatches
|
|
81
|
+
},
|
|
82
|
+
cookies: objectSpread2._defineProperty({}, internal.VAL_SESSION_COOKIE, (_cookies$get2 = cookies.get(internal.VAL_SESSION_COOKIE)) === null || _cookies$get2 === void 0 ? void 0 : _cookies$get2.value)
|
|
58
83
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
} else {
|
|
74
|
-
if (res.error.statusCode === 401) {
|
|
75
|
-
console.warn("Val: authentication error: ", res.error.message);
|
|
76
|
-
} else {
|
|
77
|
-
console.error("Val: could not fetch modules", res.error);
|
|
78
|
-
throw Error(JSON.stringify(res.error, null, 2));
|
|
84
|
+
case 9:
|
|
85
|
+
treeRes = _context.sent;
|
|
86
|
+
if (!(treeRes.status === 200)) {
|
|
87
|
+
_context.next = 15;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
modules = treeRes.json.modules;
|
|
91
|
+
return _context.abrupt("return", stega.stegaEncode(selector, {
|
|
92
|
+
disabled: !enabled,
|
|
93
|
+
getModule: function getModule(path) {
|
|
94
|
+
var module = modules[path];
|
|
95
|
+
if (module) {
|
|
96
|
+
return module.source;
|
|
79
97
|
}
|
|
80
98
|
}
|
|
81
99
|
}));
|
|
82
|
-
case
|
|
100
|
+
case 15:
|
|
101
|
+
if (!(treeRes.status === 401)) {
|
|
102
|
+
_context.next = 19;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
console.warn("Val: authentication error: ", treeRes.json.message);
|
|
106
|
+
_context.next = 21;
|
|
107
|
+
break;
|
|
108
|
+
case 19:
|
|
109
|
+
console.error("Val: could not fetch modules", treeRes.json);
|
|
110
|
+
throw Error(JSON.stringify(treeRes.json, null, 2));
|
|
111
|
+
case 21:
|
|
83
112
|
case "end":
|
|
84
113
|
return _context.stop();
|
|
85
114
|
}
|
|
@@ -145,11 +174,65 @@ function getHost(headers) {
|
|
|
145
174
|
|
|
146
175
|
var valApiEndpoints = "/api/val";
|
|
147
176
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
148
|
-
function initValRsc(config, rscNextConfig) {
|
|
177
|
+
function initValRsc(config, valModules, rscNextConfig) {
|
|
178
|
+
var coreVersion = core.Internal.VERSION.core;
|
|
179
|
+
if (!coreVersion) {
|
|
180
|
+
throw new Error("Could not get @valbuild/core package version");
|
|
181
|
+
}
|
|
182
|
+
var nextVersion = version.VERSION;
|
|
183
|
+
if (!nextVersion) {
|
|
184
|
+
throw new Error("Could not get @valbuild/next package version");
|
|
185
|
+
}
|
|
186
|
+
var valServerPromise = server.createValServer(valModules, "/api/val", objectSpread2._objectSpread2({
|
|
187
|
+
versions: {
|
|
188
|
+
next: nextVersion,
|
|
189
|
+
core: coreVersion
|
|
190
|
+
}
|
|
191
|
+
}, config), {
|
|
192
|
+
isEnabled: function isEnabled() {
|
|
193
|
+
return asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator._regeneratorRuntime().mark(function _callee2() {
|
|
194
|
+
return asyncToGenerator._regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
195
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
196
|
+
case 0:
|
|
197
|
+
return _context2.abrupt("return", rscNextConfig.draftMode().isEnabled);
|
|
198
|
+
case 1:
|
|
199
|
+
case "end":
|
|
200
|
+
return _context2.stop();
|
|
201
|
+
}
|
|
202
|
+
}, _callee2);
|
|
203
|
+
}))();
|
|
204
|
+
},
|
|
205
|
+
onEnable: function onEnable() {
|
|
206
|
+
return asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator._regeneratorRuntime().mark(function _callee3() {
|
|
207
|
+
return asyncToGenerator._regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
208
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
209
|
+
case 0:
|
|
210
|
+
rscNextConfig.draftMode().enable();
|
|
211
|
+
case 1:
|
|
212
|
+
case "end":
|
|
213
|
+
return _context3.stop();
|
|
214
|
+
}
|
|
215
|
+
}, _callee3);
|
|
216
|
+
}))();
|
|
217
|
+
},
|
|
218
|
+
onDisable: function onDisable() {
|
|
219
|
+
return asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator._regeneratorRuntime().mark(function _callee4() {
|
|
220
|
+
return asyncToGenerator._regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
221
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
222
|
+
case 0:
|
|
223
|
+
rscNextConfig.draftMode().disable();
|
|
224
|
+
case 1:
|
|
225
|
+
case "end":
|
|
226
|
+
return _context4.stop();
|
|
227
|
+
}
|
|
228
|
+
}, _callee4);
|
|
229
|
+
}))();
|
|
230
|
+
}
|
|
231
|
+
});
|
|
149
232
|
return {
|
|
150
233
|
fetchValStega: initFetchValStega(config, valApiEndpoints,
|
|
151
234
|
// TODO: get from config
|
|
152
|
-
function () {
|
|
235
|
+
valServerPromise, function () {
|
|
153
236
|
return rscNextConfig.draftMode().isEnabled;
|
|
154
237
|
}, function () {
|
|
155
238
|
return rscNextConfig.headers();
|
|
@@ -3,12 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
require('server-only');
|
|
6
|
+
var objectSpread2 = require('../../dist/objectSpread2-24e737a6.cjs.prod.js');
|
|
6
7
|
var asyncToGenerator = require('../../dist/asyncToGenerator-3551d940.cjs.prod.js');
|
|
7
8
|
var stega = require('@valbuild/react/stega');
|
|
8
9
|
var core = require('@valbuild/core');
|
|
9
|
-
var
|
|
10
|
+
var internal = require('@valbuild/shared/internal');
|
|
11
|
+
var server = require('@valbuild/server');
|
|
12
|
+
var version = require('../../dist/version-a9a6a619.cjs.prod.js');
|
|
10
13
|
|
|
11
|
-
var initFetchValStega = function initFetchValStega(config, valApiEndpoints, isEnabled, getHeaders, getCookies) {
|
|
14
|
+
var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies) {
|
|
12
15
|
return function (selector) {
|
|
13
16
|
var enabled = false;
|
|
14
17
|
try {
|
|
@@ -28,58 +31,84 @@ var initFetchValStega = function initFetchValStega(config, valApiEndpoints, isEn
|
|
|
28
31
|
console.error("Val: could not read headers! fetchVal can only be used server-side. Use useVal on clients.", err);
|
|
29
32
|
headers = null;
|
|
30
33
|
}
|
|
31
|
-
var cookies
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
var cookies = function () {
|
|
35
|
+
try {
|
|
36
|
+
return getCookies();
|
|
37
|
+
} catch (err) {
|
|
38
|
+
console.error("Val: could not read cookies! fetchVal can only be used server-side. Use useVal on clients.", err);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}();
|
|
38
42
|
var host = headers && getHost(headers);
|
|
39
43
|
if (host && cookies) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var allPatches;
|
|
44
|
+
return valServerPromise.then( /*#__PURE__*/function () {
|
|
45
|
+
var _ref = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator._regeneratorRuntime().mark(function _callee(valServer) {
|
|
46
|
+
var _cookies$get, _cookies$get2;
|
|
47
|
+
var patchesRes, allPatches, treeRes, modules;
|
|
44
48
|
return asyncToGenerator._regeneratorRuntime().wrap(function _callee$(_context) {
|
|
45
49
|
while (1) switch (_context.prev = _context.next) {
|
|
46
50
|
case 0:
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
_context.next = 2;
|
|
52
|
+
return valServer["/patches/~"]["GET"]({
|
|
53
|
+
query: {
|
|
54
|
+
omit_patch: true,
|
|
55
|
+
author: undefined,
|
|
56
|
+
patch_id: undefined,
|
|
57
|
+
module_file_path: undefined
|
|
58
|
+
},
|
|
59
|
+
cookies: objectSpread2._defineProperty({}, internal.VAL_SESSION_COOKIE, (_cookies$get = cookies.get(internal.VAL_SESSION_COOKIE)) === null || _cookies$get === void 0 ? void 0 : _cookies$get.value)
|
|
60
|
+
});
|
|
61
|
+
case 2:
|
|
62
|
+
patchesRes = _context.sent;
|
|
63
|
+
if (!(patchesRes.status !== 200)) {
|
|
64
|
+
_context.next = 6;
|
|
49
65
|
break;
|
|
50
66
|
}
|
|
51
|
-
console.error("Val: could not fetch patches", patchesRes.
|
|
52
|
-
throw Error(JSON.stringify(patchesRes.
|
|
53
|
-
case
|
|
54
|
-
allPatches = Object.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
67
|
+
console.error("Val: could not fetch patches", patchesRes.json);
|
|
68
|
+
throw Error(JSON.stringify(patchesRes.json, null, 2));
|
|
69
|
+
case 6:
|
|
70
|
+
allPatches = Object.keys(patchesRes.json.patches);
|
|
71
|
+
_context.next = 9;
|
|
72
|
+
return valServer["/tree/~"]["PUT"]({
|
|
73
|
+
path: "/",
|
|
74
|
+
query: {
|
|
75
|
+
validate_sources: true,
|
|
76
|
+
validate_all: false,
|
|
77
|
+
validate_binary_files: false
|
|
78
|
+
},
|
|
79
|
+
body: {
|
|
80
|
+
patchIds: allPatches
|
|
81
|
+
},
|
|
82
|
+
cookies: objectSpread2._defineProperty({}, internal.VAL_SESSION_COOKIE, (_cookies$get2 = cookies.get(internal.VAL_SESSION_COOKIE)) === null || _cookies$get2 === void 0 ? void 0 : _cookies$get2.value)
|
|
58
83
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
} else {
|
|
74
|
-
if (res.error.statusCode === 401) {
|
|
75
|
-
console.warn("Val: authentication error: ", res.error.message);
|
|
76
|
-
} else {
|
|
77
|
-
console.error("Val: could not fetch modules", res.error);
|
|
78
|
-
throw Error(JSON.stringify(res.error, null, 2));
|
|
84
|
+
case 9:
|
|
85
|
+
treeRes = _context.sent;
|
|
86
|
+
if (!(treeRes.status === 200)) {
|
|
87
|
+
_context.next = 15;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
modules = treeRes.json.modules;
|
|
91
|
+
return _context.abrupt("return", stega.stegaEncode(selector, {
|
|
92
|
+
disabled: !enabled,
|
|
93
|
+
getModule: function getModule(path) {
|
|
94
|
+
var module = modules[path];
|
|
95
|
+
if (module) {
|
|
96
|
+
return module.source;
|
|
79
97
|
}
|
|
80
98
|
}
|
|
81
99
|
}));
|
|
82
|
-
case
|
|
100
|
+
case 15:
|
|
101
|
+
if (!(treeRes.status === 401)) {
|
|
102
|
+
_context.next = 19;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
console.warn("Val: authentication error: ", treeRes.json.message);
|
|
106
|
+
_context.next = 21;
|
|
107
|
+
break;
|
|
108
|
+
case 19:
|
|
109
|
+
console.error("Val: could not fetch modules", treeRes.json);
|
|
110
|
+
throw Error(JSON.stringify(treeRes.json, null, 2));
|
|
111
|
+
case 21:
|
|
83
112
|
case "end":
|
|
84
113
|
return _context.stop();
|
|
85
114
|
}
|
|
@@ -142,11 +171,65 @@ function getHost(headers) {
|
|
|
142
171
|
|
|
143
172
|
var valApiEndpoints = "/api/val";
|
|
144
173
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
145
|
-
function initValRsc(config, rscNextConfig) {
|
|
174
|
+
function initValRsc(config, valModules, rscNextConfig) {
|
|
175
|
+
var coreVersion = core.Internal.VERSION.core;
|
|
176
|
+
if (!coreVersion) {
|
|
177
|
+
throw new Error("Could not get @valbuild/core package version");
|
|
178
|
+
}
|
|
179
|
+
var nextVersion = version.VERSION;
|
|
180
|
+
if (!nextVersion) {
|
|
181
|
+
throw new Error("Could not get @valbuild/next package version");
|
|
182
|
+
}
|
|
183
|
+
var valServerPromise = server.createValServer(valModules, "/api/val", objectSpread2._objectSpread2({
|
|
184
|
+
versions: {
|
|
185
|
+
next: nextVersion,
|
|
186
|
+
core: coreVersion
|
|
187
|
+
}
|
|
188
|
+
}, config), {
|
|
189
|
+
isEnabled: function isEnabled() {
|
|
190
|
+
return asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator._regeneratorRuntime().mark(function _callee2() {
|
|
191
|
+
return asyncToGenerator._regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
192
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
193
|
+
case 0:
|
|
194
|
+
return _context2.abrupt("return", rscNextConfig.draftMode().isEnabled);
|
|
195
|
+
case 1:
|
|
196
|
+
case "end":
|
|
197
|
+
return _context2.stop();
|
|
198
|
+
}
|
|
199
|
+
}, _callee2);
|
|
200
|
+
}))();
|
|
201
|
+
},
|
|
202
|
+
onEnable: function onEnable() {
|
|
203
|
+
return asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator._regeneratorRuntime().mark(function _callee3() {
|
|
204
|
+
return asyncToGenerator._regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
205
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
206
|
+
case 0:
|
|
207
|
+
rscNextConfig.draftMode().enable();
|
|
208
|
+
case 1:
|
|
209
|
+
case "end":
|
|
210
|
+
return _context3.stop();
|
|
211
|
+
}
|
|
212
|
+
}, _callee3);
|
|
213
|
+
}))();
|
|
214
|
+
},
|
|
215
|
+
onDisable: function onDisable() {
|
|
216
|
+
return asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator._regeneratorRuntime().mark(function _callee4() {
|
|
217
|
+
return asyncToGenerator._regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
218
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
219
|
+
case 0:
|
|
220
|
+
rscNextConfig.draftMode().disable();
|
|
221
|
+
case 1:
|
|
222
|
+
case "end":
|
|
223
|
+
return _context4.stop();
|
|
224
|
+
}
|
|
225
|
+
}, _callee4);
|
|
226
|
+
}))();
|
|
227
|
+
}
|
|
228
|
+
});
|
|
146
229
|
return {
|
|
147
230
|
fetchValStega: initFetchValStega(config, valApiEndpoints,
|
|
148
231
|
// TODO: get from config
|
|
149
|
-
function () {
|
|
232
|
+
valServerPromise, function () {
|
|
150
233
|
return rscNextConfig.draftMode().isEnabled;
|
|
151
234
|
}, function () {
|
|
152
235
|
return rscNextConfig.headers();
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import 'server-only';
|
|
2
|
+
import { _ as _objectSpread2, a as _defineProperty } from '../../dist/objectSpread2-439bdcdd.esm.js';
|
|
2
3
|
import { _ as _asyncToGenerator, a as _regeneratorRuntime } from '../../dist/asyncToGenerator-0859ab5c.esm.js';
|
|
3
4
|
import { SET_AUTO_TAG_JSX_ENABLED, stegaEncode } from '@valbuild/react/stega';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { Internal } from '@valbuild/core';
|
|
6
|
+
import { VAL_SESSION_COOKIE } from '@valbuild/shared/internal';
|
|
7
|
+
import { createValServer } from '@valbuild/server';
|
|
8
|
+
import { V as VERSION } from '../../dist/version-98ec5c7a.esm.js';
|
|
6
9
|
|
|
7
|
-
var initFetchValStega = function initFetchValStega(config, valApiEndpoints, isEnabled, getHeaders, getCookies) {
|
|
10
|
+
var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies) {
|
|
8
11
|
return function (selector) {
|
|
9
12
|
var enabled = false;
|
|
10
13
|
try {
|
|
@@ -24,58 +27,84 @@ var initFetchValStega = function initFetchValStega(config, valApiEndpoints, isEn
|
|
|
24
27
|
console.error("Val: could not read headers! fetchVal can only be used server-side. Use useVal on clients.", err);
|
|
25
28
|
headers = null;
|
|
26
29
|
}
|
|
27
|
-
var cookies
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
var cookies = function () {
|
|
31
|
+
try {
|
|
32
|
+
return getCookies();
|
|
33
|
+
} catch (err) {
|
|
34
|
+
console.error("Val: could not read cookies! fetchVal can only be used server-side. Use useVal on clients.", err);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}();
|
|
34
38
|
var host = headers && getHost(headers);
|
|
35
39
|
if (host && cookies) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var allPatches;
|
|
40
|
+
return valServerPromise.then( /*#__PURE__*/function () {
|
|
41
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(valServer) {
|
|
42
|
+
var _cookies$get, _cookies$get2;
|
|
43
|
+
var patchesRes, allPatches, treeRes, modules;
|
|
40
44
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
41
45
|
while (1) switch (_context.prev = _context.next) {
|
|
42
46
|
case 0:
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
_context.next = 2;
|
|
48
|
+
return valServer["/patches/~"]["GET"]({
|
|
49
|
+
query: {
|
|
50
|
+
omit_patch: true,
|
|
51
|
+
author: undefined,
|
|
52
|
+
patch_id: undefined,
|
|
53
|
+
module_file_path: undefined
|
|
54
|
+
},
|
|
55
|
+
cookies: _defineProperty({}, VAL_SESSION_COOKIE, (_cookies$get = cookies.get(VAL_SESSION_COOKIE)) === null || _cookies$get === void 0 ? void 0 : _cookies$get.value)
|
|
56
|
+
});
|
|
57
|
+
case 2:
|
|
58
|
+
patchesRes = _context.sent;
|
|
59
|
+
if (!(patchesRes.status !== 200)) {
|
|
60
|
+
_context.next = 6;
|
|
45
61
|
break;
|
|
46
62
|
}
|
|
47
|
-
console.error("Val: could not fetch patches", patchesRes.
|
|
48
|
-
throw Error(JSON.stringify(patchesRes.
|
|
49
|
-
case
|
|
50
|
-
allPatches = Object.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
console.error("Val: could not fetch patches", patchesRes.json);
|
|
64
|
+
throw Error(JSON.stringify(patchesRes.json, null, 2));
|
|
65
|
+
case 6:
|
|
66
|
+
allPatches = Object.keys(patchesRes.json.patches);
|
|
67
|
+
_context.next = 9;
|
|
68
|
+
return valServer["/tree/~"]["PUT"]({
|
|
69
|
+
path: "/",
|
|
70
|
+
query: {
|
|
71
|
+
validate_sources: true,
|
|
72
|
+
validate_all: false,
|
|
73
|
+
validate_binary_files: false
|
|
74
|
+
},
|
|
75
|
+
body: {
|
|
76
|
+
patchIds: allPatches
|
|
77
|
+
},
|
|
78
|
+
cookies: _defineProperty({}, VAL_SESSION_COOKIE, (_cookies$get2 = cookies.get(VAL_SESSION_COOKIE)) === null || _cookies$get2 === void 0 ? void 0 : _cookies$get2.value)
|
|
54
79
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
} else {
|
|
70
|
-
if (res.error.statusCode === 401) {
|
|
71
|
-
console.warn("Val: authentication error: ", res.error.message);
|
|
72
|
-
} else {
|
|
73
|
-
console.error("Val: could not fetch modules", res.error);
|
|
74
|
-
throw Error(JSON.stringify(res.error, null, 2));
|
|
80
|
+
case 9:
|
|
81
|
+
treeRes = _context.sent;
|
|
82
|
+
if (!(treeRes.status === 200)) {
|
|
83
|
+
_context.next = 15;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
modules = treeRes.json.modules;
|
|
87
|
+
return _context.abrupt("return", stegaEncode(selector, {
|
|
88
|
+
disabled: !enabled,
|
|
89
|
+
getModule: function getModule(path) {
|
|
90
|
+
var module = modules[path];
|
|
91
|
+
if (module) {
|
|
92
|
+
return module.source;
|
|
75
93
|
}
|
|
76
94
|
}
|
|
77
95
|
}));
|
|
78
|
-
case
|
|
96
|
+
case 15:
|
|
97
|
+
if (!(treeRes.status === 401)) {
|
|
98
|
+
_context.next = 19;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
console.warn("Val: authentication error: ", treeRes.json.message);
|
|
102
|
+
_context.next = 21;
|
|
103
|
+
break;
|
|
104
|
+
case 19:
|
|
105
|
+
console.error("Val: could not fetch modules", treeRes.json);
|
|
106
|
+
throw Error(JSON.stringify(treeRes.json, null, 2));
|
|
107
|
+
case 21:
|
|
79
108
|
case "end":
|
|
80
109
|
return _context.stop();
|
|
81
110
|
}
|
|
@@ -141,11 +170,65 @@ function getHost(headers) {
|
|
|
141
170
|
|
|
142
171
|
var valApiEndpoints = "/api/val";
|
|
143
172
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
144
|
-
function initValRsc(config, rscNextConfig) {
|
|
173
|
+
function initValRsc(config, valModules, rscNextConfig) {
|
|
174
|
+
var coreVersion = Internal.VERSION.core;
|
|
175
|
+
if (!coreVersion) {
|
|
176
|
+
throw new Error("Could not get @valbuild/core package version");
|
|
177
|
+
}
|
|
178
|
+
var nextVersion = VERSION;
|
|
179
|
+
if (!nextVersion) {
|
|
180
|
+
throw new Error("Could not get @valbuild/next package version");
|
|
181
|
+
}
|
|
182
|
+
var valServerPromise = createValServer(valModules, "/api/val", _objectSpread2({
|
|
183
|
+
versions: {
|
|
184
|
+
next: nextVersion,
|
|
185
|
+
core: coreVersion
|
|
186
|
+
}
|
|
187
|
+
}, config), {
|
|
188
|
+
isEnabled: function isEnabled() {
|
|
189
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
190
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
191
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
192
|
+
case 0:
|
|
193
|
+
return _context2.abrupt("return", rscNextConfig.draftMode().isEnabled);
|
|
194
|
+
case 1:
|
|
195
|
+
case "end":
|
|
196
|
+
return _context2.stop();
|
|
197
|
+
}
|
|
198
|
+
}, _callee2);
|
|
199
|
+
}))();
|
|
200
|
+
},
|
|
201
|
+
onEnable: function onEnable() {
|
|
202
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
203
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
204
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
205
|
+
case 0:
|
|
206
|
+
rscNextConfig.draftMode().enable();
|
|
207
|
+
case 1:
|
|
208
|
+
case "end":
|
|
209
|
+
return _context3.stop();
|
|
210
|
+
}
|
|
211
|
+
}, _callee3);
|
|
212
|
+
}))();
|
|
213
|
+
},
|
|
214
|
+
onDisable: function onDisable() {
|
|
215
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
216
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
217
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
218
|
+
case 0:
|
|
219
|
+
rscNextConfig.draftMode().disable();
|
|
220
|
+
case 1:
|
|
221
|
+
case "end":
|
|
222
|
+
return _context4.stop();
|
|
223
|
+
}
|
|
224
|
+
}, _callee4);
|
|
225
|
+
}))();
|
|
226
|
+
}
|
|
227
|
+
});
|
|
145
228
|
return {
|
|
146
229
|
fetchValStega: initFetchValStega(config, valApiEndpoints,
|
|
147
230
|
// TODO: get from config
|
|
148
|
-
function () {
|
|
231
|
+
valServerPromise, function () {
|
|
149
232
|
return rscNextConfig.draftMode().isEnabled;
|
|
150
233
|
}, function () {
|
|
151
234
|
return rscNextConfig.headers();
|