@valbuild/server 0.26.0 → 0.28.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/dist/valbuild-server.cjs.dev.js +2 -2
- package/dist/valbuild-server.cjs.prod.js +2 -2
- package/dist/valbuild-server.esm.js +2 -2
- package/package.json +7 -4
- package/.babelrc.json +0 -5
- package/CHANGELOG.md +0 -0
- package/jest.config.js +0 -4
- package/src/LocalValServer.ts +0 -167
- package/src/ProxyValServer.ts +0 -542
- package/src/SerializedModuleContent.ts +0 -36
- package/src/Service.ts +0 -126
- package/src/ValFS.ts +0 -22
- package/src/ValFSHost.ts +0 -66
- package/src/ValModuleLoader.test.ts +0 -75
- package/src/ValModuleLoader.ts +0 -158
- package/src/ValQuickJSRuntime.ts +0 -85
- package/src/ValServer.ts +0 -24
- package/src/ValSourceFileHandler.ts +0 -57
- package/src/createFixPatch.ts +0 -170
- package/src/createRequestHandler.ts +0 -27
- package/src/expressHelpers.ts +0 -5
- package/src/getCompilerOptions.ts +0 -50
- package/src/hosting.ts +0 -290
- package/src/index.ts +0 -16
- package/src/jwt.ts +0 -93
- package/src/patch/ts/ops.test.ts +0 -937
- package/src/patch/ts/ops.ts +0 -897
- package/src/patch/ts/syntax.ts +0 -371
- package/src/patch/ts/valModule.test.ts +0 -26
- package/src/patch/ts/valModule.ts +0 -110
- package/src/patch/validation.ts +0 -81
- package/src/patchValFile.ts +0 -110
- package/src/readValFile.test.ts +0 -49
- package/src/readValFile.ts +0 -96
- package/test/example-projects/basic-next-javascript/jsconfig.json +0 -8
- package/test/example-projects/basic-next-javascript/package.json +0 -23
- package/test/example-projects/basic-next-javascript/pages/blogs.val.js +0 -20
- package/test/example-projects/basic-next-javascript/val.config.js +0 -4
- package/test/example-projects/basic-next-src-typescript/package.json +0 -23
- package/test/example-projects/basic-next-src-typescript/src/pages/blogs.val.ts +0 -20
- package/test/example-projects/basic-next-src-typescript/src/val.config.ts +0 -5
- package/test/example-projects/basic-next-src-typescript/tsconfig.json +0 -24
- package/test/example-projects/basic-next-typescript/package.json +0 -23
- package/test/example-projects/basic-next-typescript/pages/blogs.val.ts +0 -20
- package/test/example-projects/basic-next-typescript/tsconfig.json +0 -25
- package/test/example-projects/basic-next-typescript/val.config.ts +0 -5
- package/test/example-projects/typescript-description-files/README.md +0 -2
- package/test/example-projects/typescript-description-files/jsconfig.json +0 -8
- package/test/example-projects/typescript-description-files/package.json +0 -23
- package/test/example-projects/typescript-description-files/pages/blogs.val.d.ts +0 -7
- package/test/example-projects/typescript-description-files/pages/blogs.val.js +0 -19
- package/test/example-projects/typescript-description-files/val.config.d.ts +0 -3
- package/test/example-projects/typescript-description-files/val.config.js +0 -5
- package/tsconfig.json +0 -12
@@ -1442,7 +1442,7 @@ class ProxyValServer {
|
|
1442
1442
|
return url.toString();
|
1443
1443
|
}
|
1444
1444
|
getAppErrorUrl(error) {
|
1445
|
-
const url = new URL(
|
1445
|
+
const url = new URL(`/auth/${this.options.valName}/authorize`, this.options.valBuildUrl);
|
1446
1446
|
url.searchParams.set("error", encodeURIComponent(error));
|
1447
1447
|
return url.toString();
|
1448
1448
|
}
|
@@ -1745,7 +1745,7 @@ async function initHandlerOptions(route, opts) {
|
|
1745
1745
|
if (!maybeGitBranch) {
|
1746
1746
|
throw new Error("VAL_GIT_BRANCH env var must be set in proxy mode");
|
1747
1747
|
}
|
1748
|
-
const maybeValName = opts.
|
1748
|
+
const maybeValName = opts.valName || process.env.VAL_NAME;
|
1749
1749
|
if (!maybeValName) {
|
1750
1750
|
throw new Error("VAL_NAME env var must be set in proxy mode");
|
1751
1751
|
}
|
@@ -1442,7 +1442,7 @@ class ProxyValServer {
|
|
1442
1442
|
return url.toString();
|
1443
1443
|
}
|
1444
1444
|
getAppErrorUrl(error) {
|
1445
|
-
const url = new URL(
|
1445
|
+
const url = new URL(`/auth/${this.options.valName}/authorize`, this.options.valBuildUrl);
|
1446
1446
|
url.searchParams.set("error", encodeURIComponent(error));
|
1447
1447
|
return url.toString();
|
1448
1448
|
}
|
@@ -1745,7 +1745,7 @@ async function initHandlerOptions(route, opts) {
|
|
1745
1745
|
if (!maybeGitBranch) {
|
1746
1746
|
throw new Error("VAL_GIT_BRANCH env var must be set in proxy mode");
|
1747
1747
|
}
|
1748
|
-
const maybeValName = opts.
|
1748
|
+
const maybeValName = opts.valName || process.env.VAL_NAME;
|
1749
1749
|
if (!maybeValName) {
|
1750
1750
|
throw new Error("VAL_NAME env var must be set in proxy mode");
|
1751
1751
|
}
|
@@ -1411,7 +1411,7 @@ class ProxyValServer {
|
|
1411
1411
|
return url.toString();
|
1412
1412
|
}
|
1413
1413
|
getAppErrorUrl(error) {
|
1414
|
-
const url = new URL(
|
1414
|
+
const url = new URL(`/auth/${this.options.valName}/authorize`, this.options.valBuildUrl);
|
1415
1415
|
url.searchParams.set("error", encodeURIComponent(error));
|
1416
1416
|
return url.toString();
|
1417
1417
|
}
|
@@ -1714,7 +1714,7 @@ async function initHandlerOptions(route, opts) {
|
|
1714
1714
|
if (!maybeGitBranch) {
|
1715
1715
|
throw new Error("VAL_GIT_BRANCH env var must be set in proxy mode");
|
1716
1716
|
}
|
1717
|
-
const maybeValName = opts.
|
1717
|
+
const maybeValName = opts.valName || process.env.VAL_NAME;
|
1718
1718
|
if (!maybeValName) {
|
1719
1719
|
throw new Error("VAL_NAME env var must be set in proxy mode");
|
1720
1720
|
}
|
package/package.json
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
"./package.json": "./package.json"
|
13
13
|
},
|
14
14
|
"types": "dist/valbuild-server.cjs.d.ts",
|
15
|
-
"version": "0.
|
15
|
+
"version": "0.28.0",
|
16
16
|
"scripts": {
|
17
17
|
"typecheck": "tsc --noEmit",
|
18
18
|
"test": "jest",
|
@@ -25,8 +25,8 @@
|
|
25
25
|
"concurrently": "^7.6.0"
|
26
26
|
},
|
27
27
|
"dependencies": {
|
28
|
-
"@valbuild/core": "~0.
|
29
|
-
"@valbuild/ui": "~0.
|
28
|
+
"@valbuild/core": "~0.28.0",
|
29
|
+
"@valbuild/ui": "~0.28.0",
|
30
30
|
"express": "^4.18.2",
|
31
31
|
"image-size": "^1.0.2",
|
32
32
|
"quickjs-emscripten": "^0.21.1",
|
@@ -37,5 +37,8 @@
|
|
37
37
|
},
|
38
38
|
"engines": {
|
39
39
|
"node": ">=16.0.0"
|
40
|
-
}
|
40
|
+
},
|
41
|
+
"files": [
|
42
|
+
"dist"
|
43
|
+
]
|
41
44
|
}
|
package/CHANGELOG.md
DELETED
File without changes
|
package/jest.config.js
DELETED
package/src/LocalValServer.ts
DELETED
@@ -1,167 +0,0 @@
|
|
1
|
-
import express from "express";
|
2
|
-
import { Service } from "./Service";
|
3
|
-
import { result } from "@valbuild/core/fp";
|
4
|
-
import { parsePatch, PatchError } from "@valbuild/core/patch";
|
5
|
-
import { PatchJSON } from "./patch/validation";
|
6
|
-
import { ValServer } from "./ValServer";
|
7
|
-
import { ApiTreeResponse, ModuleId, ModulePath } from "@valbuild/core";
|
8
|
-
import { disable, enable } from "./ProxyValServer";
|
9
|
-
import { promises as fs } from "fs";
|
10
|
-
import path from "path";
|
11
|
-
import { z } from "zod";
|
12
|
-
|
13
|
-
export type LocalValServerOptions = {
|
14
|
-
service: Service;
|
15
|
-
git: {
|
16
|
-
commit?: string;
|
17
|
-
branch?: string;
|
18
|
-
};
|
19
|
-
};
|
20
|
-
|
21
|
-
export class LocalValServer implements ValServer {
|
22
|
-
constructor(readonly options: LocalValServerOptions) {}
|
23
|
-
|
24
|
-
async session(_req: express.Request, res: express.Response): Promise<void> {
|
25
|
-
res.json({
|
26
|
-
mode: "local",
|
27
|
-
});
|
28
|
-
}
|
29
|
-
|
30
|
-
async getTree(req: express.Request, res: express.Response): Promise<void> {
|
31
|
-
try {
|
32
|
-
// TODO: use the params: patch, schema, source
|
33
|
-
const treePath = req.params["0"].replace("~", "");
|
34
|
-
const rootDir = process.cwd();
|
35
|
-
const moduleIds: string[] = [];
|
36
|
-
// iterate over all .val files in the root directory
|
37
|
-
const walk = async (dir: string) => {
|
38
|
-
const files = await fs.readdir(dir);
|
39
|
-
for (const file of files) {
|
40
|
-
if ((await fs.stat(path.join(dir, file))).isDirectory()) {
|
41
|
-
if (file === "node_modules") continue;
|
42
|
-
await walk(path.join(dir, file));
|
43
|
-
} else {
|
44
|
-
const isValFile =
|
45
|
-
file.endsWith(".val.js") || file.endsWith(".val.ts");
|
46
|
-
if (!isValFile) {
|
47
|
-
continue;
|
48
|
-
}
|
49
|
-
if (
|
50
|
-
treePath &&
|
51
|
-
!path.join(dir, file).replace(rootDir, "").startsWith(treePath)
|
52
|
-
) {
|
53
|
-
continue;
|
54
|
-
}
|
55
|
-
moduleIds.push(
|
56
|
-
path
|
57
|
-
.join(dir, file)
|
58
|
-
.replace(rootDir, "")
|
59
|
-
.replace(".val.js", "")
|
60
|
-
.replace(".val.ts", "")
|
61
|
-
);
|
62
|
-
}
|
63
|
-
}
|
64
|
-
};
|
65
|
-
const serializedModuleContent = await walk(rootDir).then(async () => {
|
66
|
-
return Promise.all(
|
67
|
-
moduleIds.map(async (moduleId) => {
|
68
|
-
return await this.options.service.get(
|
69
|
-
moduleId as ModuleId,
|
70
|
-
"" as ModulePath
|
71
|
-
);
|
72
|
-
})
|
73
|
-
);
|
74
|
-
});
|
75
|
-
|
76
|
-
//
|
77
|
-
const modules = Object.fromEntries(
|
78
|
-
serializedModuleContent.map((serializedModuleContent) => {
|
79
|
-
const module: ApiTreeResponse["modules"][keyof ApiTreeResponse["modules"]] =
|
80
|
-
{
|
81
|
-
schema: serializedModuleContent.schema,
|
82
|
-
source: serializedModuleContent.source,
|
83
|
-
errors: serializedModuleContent.errors,
|
84
|
-
};
|
85
|
-
return [serializedModuleContent.path, module];
|
86
|
-
})
|
87
|
-
);
|
88
|
-
const apiTreeResponse: ApiTreeResponse = {
|
89
|
-
modules,
|
90
|
-
git: this.options.git,
|
91
|
-
};
|
92
|
-
res.send(JSON.stringify(apiTreeResponse));
|
93
|
-
} catch (err) {
|
94
|
-
console.error(err);
|
95
|
-
res.sendStatus(500);
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|
99
|
-
async enable(req: express.Request, res: express.Response): Promise<void> {
|
100
|
-
return enable(req, res);
|
101
|
-
}
|
102
|
-
|
103
|
-
async disable(req: express.Request, res: express.Response): Promise<void> {
|
104
|
-
return disable(req, res);
|
105
|
-
}
|
106
|
-
|
107
|
-
async postPatches(
|
108
|
-
req: express.Request<{ 0: string }>,
|
109
|
-
res: express.Response
|
110
|
-
): Promise<void> {
|
111
|
-
// First validate that the body has the right structure
|
112
|
-
const patchJSON = z.record(PatchJSON).safeParse(req.body);
|
113
|
-
if (!patchJSON.success) {
|
114
|
-
res.status(401).json(patchJSON.error.issues);
|
115
|
-
return;
|
116
|
-
}
|
117
|
-
|
118
|
-
try {
|
119
|
-
for (const moduleId in patchJSON.data) {
|
120
|
-
// Then parse/validate
|
121
|
-
// TODO: validate all and then fail instead:
|
122
|
-
const patch = parsePatch(patchJSON.data[moduleId]);
|
123
|
-
if (result.isErr(patch)) {
|
124
|
-
res.status(401).json(patch.error);
|
125
|
-
return;
|
126
|
-
}
|
127
|
-
await this.options.service.patch(moduleId, patch.value);
|
128
|
-
}
|
129
|
-
res.json({});
|
130
|
-
} catch (err) {
|
131
|
-
if (err instanceof PatchError) {
|
132
|
-
res.status(400).send({ message: err.message });
|
133
|
-
} else {
|
134
|
-
console.error(err);
|
135
|
-
res.status(500).send({
|
136
|
-
message: err instanceof Error ? err.message : "Unknown error",
|
137
|
-
});
|
138
|
-
}
|
139
|
-
}
|
140
|
-
}
|
141
|
-
private async badRequest(
|
142
|
-
req: express.Request,
|
143
|
-
res: express.Response
|
144
|
-
): Promise<void> {
|
145
|
-
console.debug("Local server does handle this request", req.url);
|
146
|
-
res.sendStatus(400);
|
147
|
-
}
|
148
|
-
|
149
|
-
commit(req: express.Request, res: express.Response): Promise<void> {
|
150
|
-
return this.badRequest(req, res);
|
151
|
-
}
|
152
|
-
|
153
|
-
authorize(req: express.Request, res: express.Response): Promise<void> {
|
154
|
-
return this.badRequest(req, res);
|
155
|
-
}
|
156
|
-
|
157
|
-
callback(req: express.Request, res: express.Response): Promise<void> {
|
158
|
-
return this.badRequest(req, res);
|
159
|
-
}
|
160
|
-
|
161
|
-
logout(req: express.Request, res: express.Response): Promise<void> {
|
162
|
-
return this.badRequest(req, res);
|
163
|
-
}
|
164
|
-
getFiles(req: express.Request, res: express.Response): Promise<void> {
|
165
|
-
return this.badRequest(req, res);
|
166
|
-
}
|
167
|
-
}
|