@valbuild/server 0.63.1 → 0.63.5
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.
@@ -6,7 +6,7 @@ export type ValServerOptions = {
|
|
6
6
|
route: string;
|
7
7
|
valEnableRedirectUrl?: string;
|
8
8
|
valDisableRedirectUrl?: string;
|
9
|
-
formatter?: (code: string, filePath: string) => string
|
9
|
+
formatter?: (code: string, filePath: string) => string | Promise<string>;
|
10
10
|
valBuildUrl?: string;
|
11
11
|
valSecret?: string;
|
12
12
|
apiKey?: string;
|
@@ -15,7 +15,6 @@ export type ValServerOptions = {
|
|
15
15
|
export type ValServerConfig = ValServerOptions & ({
|
16
16
|
mode: "fs";
|
17
17
|
cwd: string;
|
18
|
-
formatter?: (code: string, filePath: string) => string;
|
19
18
|
} | {
|
20
19
|
mode: "http";
|
21
20
|
valContentUrl: string;
|
@@ -60,6 +59,8 @@ export declare class ValServer {
|
|
60
59
|
logout(): Promise<ValServerResult<VAL_SESSION_COOKIE | VAL_STATE_COOKIE>>;
|
61
60
|
getPatches(query: {
|
62
61
|
authors?: string[];
|
62
|
+
patchIds?: string[];
|
63
|
+
omitPatch?: string;
|
63
64
|
}, cookies: Partial<Record<"val_session", string>>): Promise<ValServerJsonResult<ApiGetPatchResponse>>;
|
64
65
|
deletePatches(query: {
|
65
66
|
id?: string[];
|
@@ -113,7 +113,7 @@ type ValServerOverrides = Partial<{
|
|
113
113
|
*/
|
114
114
|
disableCache?: boolean;
|
115
115
|
}>;
|
116
|
-
export declare function createValServer(valModules: ValModules, route: string, opts: ValApiOptions, callbacks: ValServerCallbacks, formatter?: (code: string, filePath: string) => string): Promise<ValServer>;
|
116
|
+
export declare function createValServer(valModules: ValModules, route: string, opts: ValApiOptions, callbacks: ValServerCallbacks, formatter?: (code: string, filePath: string) => string | Promise<string>): Promise<ValServer>;
|
117
117
|
export declare function safeReadGit(cwd: string): Promise<{
|
118
118
|
commit?: string;
|
119
119
|
branch?: string;
|
@@ -1537,10 +1537,10 @@ class ValOps {
|
|
1537
1537
|
} else {
|
1538
1538
|
const patchData = analysis.patches[patchId];
|
1539
1539
|
if (!patchData) {
|
1540
|
-
errors[path]
|
1540
|
+
errors[path] = [{
|
1541
1541
|
patchId: patchId,
|
1542
1542
|
error: new patch.PatchError(`Patch not found`)
|
1543
|
-
}
|
1543
|
+
}];
|
1544
1544
|
continue;
|
1545
1545
|
}
|
1546
1546
|
const applicableOps = [];
|
@@ -1837,7 +1837,7 @@ class ValOps {
|
|
1837
1837
|
let sourceFileText = unescape(tsSourceFile.getText(tsSourceFile).replace(/\\u/g, "%u"));
|
1838
1838
|
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.formatter) {
|
1839
1839
|
try {
|
1840
|
-
sourceFileText = this.options.formatter(sourceFileText, path);
|
1840
|
+
sourceFileText = await this.options.formatter(sourceFileText, path);
|
1841
1841
|
} catch (err) {
|
1842
1842
|
errors.push({
|
1843
1843
|
message: "Could not format source file: " + (err instanceof Error ? err.message : "Unknown error")
|
@@ -2267,7 +2267,7 @@ class ValOpsFS extends ValOps {
|
|
2267
2267
|
throw new Error("Could not parse patch id from file name. Files found: " + patchJsonFiles.join(", "));
|
2268
2268
|
}
|
2269
2269
|
const patchId = patchIdNum.toString();
|
2270
|
-
if (includes && !includes.includes(patchId)) {
|
2270
|
+
if (includes && includes.length > 0 && !includes.includes(patchId)) {
|
2271
2271
|
continue;
|
2272
2272
|
}
|
2273
2273
|
const parsedFSPatchRes = this.parseJsonFile(this.getPatchFilePath(patchId), FSPatch);
|
@@ -2296,22 +2296,23 @@ class ValOpsFS extends ValOps {
|
|
2296
2296
|
patches
|
2297
2297
|
};
|
2298
2298
|
}
|
2299
|
-
async
|
2300
|
-
return this.readPatches(patchIds);
|
2301
|
-
}
|
2302
|
-
async findPatches(filters) {
|
2299
|
+
async fetchPatches(filters) {
|
2303
2300
|
const patches = {};
|
2304
2301
|
const errors = {};
|
2305
2302
|
const {
|
2306
2303
|
errors: allErrors,
|
2307
2304
|
patches: allPatches
|
2308
|
-
} = await this.readPatches();
|
2305
|
+
} = await this.readPatches(filters.patchIds);
|
2309
2306
|
for (const [patchIdS, patch] of Object.entries(allPatches)) {
|
2310
2307
|
const patchId = patchIdS;
|
2311
2308
|
if (filters.authors && !(patch.authorId === null || filters.authors.includes(patch.authorId))) {
|
2312
2309
|
continue;
|
2313
2310
|
}
|
2311
|
+
if (filters.moduleFilePaths && !filters.moduleFilePaths.includes(patch.path)) {
|
2312
|
+
continue;
|
2313
|
+
}
|
2314
2314
|
patches[patchId] = {
|
2315
|
+
patch: filters.omitPatch ? undefined : patch.patch,
|
2315
2316
|
path: patch.path,
|
2316
2317
|
createdAt: patch.createdAt,
|
2317
2318
|
authorId: patch.authorId,
|
@@ -2774,9 +2775,6 @@ const GetPatches = z.z.object({
|
|
2774
2775
|
message: z.z.string()
|
2775
2776
|
})).optional()
|
2776
2777
|
});
|
2777
|
-
const SearchPatches = z.z.object({
|
2778
|
-
patches: z.z.array(BasePatchResponse)
|
2779
|
-
});
|
2780
2778
|
const FilesResponse = z.z.object({
|
2781
2779
|
files: z.z.array(z.z.union([z.z.object({
|
2782
2780
|
filePath: z.z.string(),
|
@@ -2835,13 +2833,29 @@ class ValOpsHttp extends ValOps {
|
|
2835
2833
|
async onInit() {
|
2836
2834
|
// TODO: unused for now. Implement or remove
|
2837
2835
|
}
|
2838
|
-
async
|
2839
|
-
const params =
|
2840
|
-
params.
|
2841
|
-
if (patchIds
|
2842
|
-
|
2836
|
+
async fetchPatches(filters) {
|
2837
|
+
const params = [];
|
2838
|
+
params.push(["branch", this.branch]);
|
2839
|
+
if (filters.patchIds) {
|
2840
|
+
for (const patchId of filters.patchIds) {
|
2841
|
+
params.push(["patch_id", patchId]);
|
2842
|
+
}
|
2843
2843
|
}
|
2844
|
-
|
2844
|
+
if (filters.authors) {
|
2845
|
+
for (const author of filters.authors) {
|
2846
|
+
params.push(["author_id", author]);
|
2847
|
+
}
|
2848
|
+
}
|
2849
|
+
if (filters.omitPatch) {
|
2850
|
+
params.push(["omit_patch", "true"]);
|
2851
|
+
}
|
2852
|
+
if (filters.moduleFilePaths) {
|
2853
|
+
for (const moduleFilePath of filters.moduleFilePaths) {
|
2854
|
+
params.push(["module_file_path", moduleFilePath]);
|
2855
|
+
}
|
2856
|
+
}
|
2857
|
+
const searchParams = new URLSearchParams(params);
|
2858
|
+
return fetch(`${this.hostUrl}/v1/${this.project}/patches${searchParams.size > 0 ? `?${searchParams.toString()}` : ""}`, {
|
2845
2859
|
headers: {
|
2846
2860
|
...this.authHeaders,
|
2847
2861
|
"Content-Type": "application/json"
|
@@ -2889,55 +2903,6 @@ class ValOpsHttp extends ValOps {
|
|
2889
2903
|
};
|
2890
2904
|
});
|
2891
2905
|
}
|
2892
|
-
async findPatches(filters) {
|
2893
|
-
const params = new URLSearchParams();
|
2894
|
-
params.set("branch", this.branch);
|
2895
|
-
if (filters.authors && filters.authors.length > 0) {
|
2896
|
-
params.set("author_ids", encodeURIComponent(filters.authors.join(",")));
|
2897
|
-
}
|
2898
|
-
return fetch(`${this.hostUrl}/v1/${this.project}/search/patches${params.size > 0 ? "?" + params : ""}`, {
|
2899
|
-
headers: {
|
2900
|
-
...this.authHeaders,
|
2901
|
-
"Content-Type": "application/json"
|
2902
|
-
}
|
2903
|
-
}).then(async res => {
|
2904
|
-
const patches = {};
|
2905
|
-
if (res.ok) {
|
2906
|
-
const parsed = SearchPatches.safeParse(await res.json());
|
2907
|
-
if (parsed.success) {
|
2908
|
-
for (const patchesRes of parsed.data.patches) {
|
2909
|
-
patches[patchesRes.patchId] = {
|
2910
|
-
path: patchesRes.path,
|
2911
|
-
authorId: patchesRes.authorId,
|
2912
|
-
createdAt: patchesRes.createdAt,
|
2913
|
-
appliedAt: patchesRes.applied && {
|
2914
|
-
baseSha: patchesRes.applied.baseSha,
|
2915
|
-
timestamp: patchesRes.applied.appliedAt,
|
2916
|
-
git: {
|
2917
|
-
commitSha: patchesRes.applied.commitSha
|
2918
|
-
}
|
2919
|
-
}
|
2920
|
-
};
|
2921
|
-
}
|
2922
|
-
return {
|
2923
|
-
patches
|
2924
|
-
};
|
2925
|
-
}
|
2926
|
-
return {
|
2927
|
-
patches,
|
2928
|
-
error: {
|
2929
|
-
message: `Could not parse search patches response. Error: ${zodValidationError.fromError(parsed.error)}`
|
2930
|
-
}
|
2931
|
-
};
|
2932
|
-
}
|
2933
|
-
return {
|
2934
|
-
patches,
|
2935
|
-
error: {
|
2936
|
-
message: "Could not find patches. HTTP error: " + res.status + " " + res.statusText
|
2937
|
-
}
|
2938
|
-
};
|
2939
|
-
});
|
2940
|
-
}
|
2941
2906
|
async saveSourceFilePatch(path, patch, authorId) {
|
2942
2907
|
return fetch(`${this.hostUrl}/v1/${this.project}/patches`, {
|
2943
2908
|
method: "POST",
|
@@ -3652,8 +3617,10 @@ class ValServer {
|
|
3652
3617
|
};
|
3653
3618
|
}
|
3654
3619
|
const authors = query.authors;
|
3655
|
-
const patches = await this.serverOps.
|
3656
|
-
authors
|
3620
|
+
const patches = await this.serverOps.fetchPatches({
|
3621
|
+
authors,
|
3622
|
+
patchIds: query.patchIds,
|
3623
|
+
omitPatch: query.omitPatch === "true"
|
3657
3624
|
});
|
3658
3625
|
if (patches.errors && Object.keys(patches.errors).length > 0) {
|
3659
3626
|
console.error("Val: Failed to get patches", patches.errors);
|
@@ -3665,23 +3632,9 @@ class ValServer {
|
|
3665
3632
|
}
|
3666
3633
|
};
|
3667
3634
|
}
|
3668
|
-
const res = {};
|
3669
|
-
for (const [patchIdS, patchData] of Object.entries(patches.patches)) {
|
3670
|
-
var _patchData$appliedAt;
|
3671
|
-
const patchId = patchIdS;
|
3672
|
-
if (!res[patchData.path]) {
|
3673
|
-
res[patchData.path] = [];
|
3674
|
-
}
|
3675
|
-
res[patchData.path].push({
|
3676
|
-
patch_id: patchId,
|
3677
|
-
created_at: patchData.createdAt,
|
3678
|
-
applied_at_base_sha: ((_patchData$appliedAt = patchData.appliedAt) === null || _patchData$appliedAt === void 0 ? void 0 : _patchData$appliedAt.baseSha) || null,
|
3679
|
-
author: patchData.authorId ?? undefined
|
3680
|
-
});
|
3681
|
-
}
|
3682
3635
|
return {
|
3683
3636
|
status: 200,
|
3684
|
-
json:
|
3637
|
+
json: patches
|
3685
3638
|
};
|
3686
3639
|
}
|
3687
3640
|
async deletePatches(query, cookies) {
|
@@ -3817,11 +3770,15 @@ class ValServer {
|
|
3817
3770
|
}
|
3818
3771
|
let tree;
|
3819
3772
|
let patchAnalysis = null;
|
3773
|
+
let newPatchId = undefined;
|
3820
3774
|
if ((_bodyRes$data = bodyRes.data) !== null && _bodyRes$data !== void 0 && _bodyRes$data.patchIds && ((_bodyRes$data2 = bodyRes.data) === null || _bodyRes$data2 === void 0 || (_bodyRes$data2 = _bodyRes$data2.patchIds) === null || _bodyRes$data2 === void 0 ? void 0 : _bodyRes$data2.length) > 0 || (_bodyRes$data3 = bodyRes.data) !== null && _bodyRes$data3 !== void 0 && _bodyRes$data3.addPatch) {
|
3821
3775
|
var _bodyRes$data4, _bodyRes$data5;
|
3822
3776
|
// TODO: validate patches_sha
|
3823
3777
|
const patchIds = (_bodyRes$data4 = bodyRes.data) === null || _bodyRes$data4 === void 0 ? void 0 : _bodyRes$data4.patchIds;
|
3824
|
-
const patchOps = patchIds && patchIds.length > 0 ? await this.serverOps.
|
3778
|
+
const patchOps = patchIds && patchIds.length > 0 ? await this.serverOps.fetchPatches({
|
3779
|
+
patchIds,
|
3780
|
+
omitPatch: false
|
3781
|
+
}) : {
|
3825
3782
|
patches: {}
|
3826
3783
|
};
|
3827
3784
|
let patchErrors = undefined;
|
@@ -3862,6 +3819,7 @@ class ValServer {
|
|
3862
3819
|
// };
|
3863
3820
|
// }
|
3864
3821
|
// }
|
3822
|
+
newPatchId = createPatchRes.patchId;
|
3865
3823
|
patchOps.patches[createPatchRes.patchId] = {
|
3866
3824
|
path: newPatchModuleFilePath,
|
3867
3825
|
patch: newPatchOps,
|
@@ -3923,7 +3881,8 @@ class ValServer {
|
|
3923
3881
|
status: 200,
|
3924
3882
|
json: {
|
3925
3883
|
schemaSha,
|
3926
|
-
modules
|
3884
|
+
modules,
|
3885
|
+
newPatchId
|
3927
3886
|
}
|
3928
3887
|
};
|
3929
3888
|
}
|
@@ -3954,7 +3913,10 @@ class ValServer {
|
|
3954
3913
|
const {
|
3955
3914
|
patchIds
|
3956
3915
|
} = bodyRes.data;
|
3957
|
-
const patches = await this.serverOps.
|
3916
|
+
const patches = await this.serverOps.fetchPatches({
|
3917
|
+
patchIds,
|
3918
|
+
omitPatch: false
|
3919
|
+
});
|
3958
3920
|
const analysis = this.serverOps.analyzePatches(patches.patches);
|
3959
3921
|
const preparedCommit = await this.serverOps.prepare({
|
3960
3922
|
...analysis,
|
@@ -4550,7 +4512,9 @@ function createValApiRouter(route, valServerPromise, convert) {
|
|
4550
4512
|
}, getCookies(req, [VAL_SESSION_COOKIE]))));
|
4551
4513
|
} else if (method === "GET" && path.startsWith(PATCHES_PATH_PREFIX)) {
|
4552
4514
|
return withTreePath(path, PATCHES_PATH_PREFIX)(async () => convert(await valServer.getPatches({
|
4553
|
-
authors: url.searchParams.getAll("author")
|
4515
|
+
authors: url.searchParams.getAll("author"),
|
4516
|
+
patchIds: url.searchParams.getAll("patch_id"),
|
4517
|
+
omitPatch: url.searchParams.get("omit_patch") || undefined
|
4554
4518
|
}, getCookies(req, [VAL_SESSION_COOKIE]))));
|
4555
4519
|
} else if (method === "DELETE" && path.startsWith(PATCHES_PATH_PREFIX)) {
|
4556
4520
|
return withTreePath(path, PATCHES_PATH_PREFIX)(async () => convert(await valServer.deletePatches({
|
@@ -1537,10 +1537,10 @@ class ValOps {
|
|
1537
1537
|
} else {
|
1538
1538
|
const patchData = analysis.patches[patchId];
|
1539
1539
|
if (!patchData) {
|
1540
|
-
errors[path]
|
1540
|
+
errors[path] = [{
|
1541
1541
|
patchId: patchId,
|
1542
1542
|
error: new patch.PatchError(`Patch not found`)
|
1543
|
-
}
|
1543
|
+
}];
|
1544
1544
|
continue;
|
1545
1545
|
}
|
1546
1546
|
const applicableOps = [];
|
@@ -1837,7 +1837,7 @@ class ValOps {
|
|
1837
1837
|
let sourceFileText = unescape(tsSourceFile.getText(tsSourceFile).replace(/\\u/g, "%u"));
|
1838
1838
|
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.formatter) {
|
1839
1839
|
try {
|
1840
|
-
sourceFileText = this.options.formatter(sourceFileText, path);
|
1840
|
+
sourceFileText = await this.options.formatter(sourceFileText, path);
|
1841
1841
|
} catch (err) {
|
1842
1842
|
errors.push({
|
1843
1843
|
message: "Could not format source file: " + (err instanceof Error ? err.message : "Unknown error")
|
@@ -2267,7 +2267,7 @@ class ValOpsFS extends ValOps {
|
|
2267
2267
|
throw new Error("Could not parse patch id from file name. Files found: " + patchJsonFiles.join(", "));
|
2268
2268
|
}
|
2269
2269
|
const patchId = patchIdNum.toString();
|
2270
|
-
if (includes && !includes.includes(patchId)) {
|
2270
|
+
if (includes && includes.length > 0 && !includes.includes(patchId)) {
|
2271
2271
|
continue;
|
2272
2272
|
}
|
2273
2273
|
const parsedFSPatchRes = this.parseJsonFile(this.getPatchFilePath(patchId), FSPatch);
|
@@ -2296,22 +2296,23 @@ class ValOpsFS extends ValOps {
|
|
2296
2296
|
patches
|
2297
2297
|
};
|
2298
2298
|
}
|
2299
|
-
async
|
2300
|
-
return this.readPatches(patchIds);
|
2301
|
-
}
|
2302
|
-
async findPatches(filters) {
|
2299
|
+
async fetchPatches(filters) {
|
2303
2300
|
const patches = {};
|
2304
2301
|
const errors = {};
|
2305
2302
|
const {
|
2306
2303
|
errors: allErrors,
|
2307
2304
|
patches: allPatches
|
2308
|
-
} = await this.readPatches();
|
2305
|
+
} = await this.readPatches(filters.patchIds);
|
2309
2306
|
for (const [patchIdS, patch] of Object.entries(allPatches)) {
|
2310
2307
|
const patchId = patchIdS;
|
2311
2308
|
if (filters.authors && !(patch.authorId === null || filters.authors.includes(patch.authorId))) {
|
2312
2309
|
continue;
|
2313
2310
|
}
|
2311
|
+
if (filters.moduleFilePaths && !filters.moduleFilePaths.includes(patch.path)) {
|
2312
|
+
continue;
|
2313
|
+
}
|
2314
2314
|
patches[patchId] = {
|
2315
|
+
patch: filters.omitPatch ? undefined : patch.patch,
|
2315
2316
|
path: patch.path,
|
2316
2317
|
createdAt: patch.createdAt,
|
2317
2318
|
authorId: patch.authorId,
|
@@ -2774,9 +2775,6 @@ const GetPatches = z.z.object({
|
|
2774
2775
|
message: z.z.string()
|
2775
2776
|
})).optional()
|
2776
2777
|
});
|
2777
|
-
const SearchPatches = z.z.object({
|
2778
|
-
patches: z.z.array(BasePatchResponse)
|
2779
|
-
});
|
2780
2778
|
const FilesResponse = z.z.object({
|
2781
2779
|
files: z.z.array(z.z.union([z.z.object({
|
2782
2780
|
filePath: z.z.string(),
|
@@ -2835,13 +2833,29 @@ class ValOpsHttp extends ValOps {
|
|
2835
2833
|
async onInit() {
|
2836
2834
|
// TODO: unused for now. Implement or remove
|
2837
2835
|
}
|
2838
|
-
async
|
2839
|
-
const params =
|
2840
|
-
params.
|
2841
|
-
if (patchIds
|
2842
|
-
|
2836
|
+
async fetchPatches(filters) {
|
2837
|
+
const params = [];
|
2838
|
+
params.push(["branch", this.branch]);
|
2839
|
+
if (filters.patchIds) {
|
2840
|
+
for (const patchId of filters.patchIds) {
|
2841
|
+
params.push(["patch_id", patchId]);
|
2842
|
+
}
|
2843
2843
|
}
|
2844
|
-
|
2844
|
+
if (filters.authors) {
|
2845
|
+
for (const author of filters.authors) {
|
2846
|
+
params.push(["author_id", author]);
|
2847
|
+
}
|
2848
|
+
}
|
2849
|
+
if (filters.omitPatch) {
|
2850
|
+
params.push(["omit_patch", "true"]);
|
2851
|
+
}
|
2852
|
+
if (filters.moduleFilePaths) {
|
2853
|
+
for (const moduleFilePath of filters.moduleFilePaths) {
|
2854
|
+
params.push(["module_file_path", moduleFilePath]);
|
2855
|
+
}
|
2856
|
+
}
|
2857
|
+
const searchParams = new URLSearchParams(params);
|
2858
|
+
return fetch(`${this.hostUrl}/v1/${this.project}/patches${searchParams.size > 0 ? `?${searchParams.toString()}` : ""}`, {
|
2845
2859
|
headers: {
|
2846
2860
|
...this.authHeaders,
|
2847
2861
|
"Content-Type": "application/json"
|
@@ -2889,55 +2903,6 @@ class ValOpsHttp extends ValOps {
|
|
2889
2903
|
};
|
2890
2904
|
});
|
2891
2905
|
}
|
2892
|
-
async findPatches(filters) {
|
2893
|
-
const params = new URLSearchParams();
|
2894
|
-
params.set("branch", this.branch);
|
2895
|
-
if (filters.authors && filters.authors.length > 0) {
|
2896
|
-
params.set("author_ids", encodeURIComponent(filters.authors.join(",")));
|
2897
|
-
}
|
2898
|
-
return fetch(`${this.hostUrl}/v1/${this.project}/search/patches${params.size > 0 ? "?" + params : ""}`, {
|
2899
|
-
headers: {
|
2900
|
-
...this.authHeaders,
|
2901
|
-
"Content-Type": "application/json"
|
2902
|
-
}
|
2903
|
-
}).then(async res => {
|
2904
|
-
const patches = {};
|
2905
|
-
if (res.ok) {
|
2906
|
-
const parsed = SearchPatches.safeParse(await res.json());
|
2907
|
-
if (parsed.success) {
|
2908
|
-
for (const patchesRes of parsed.data.patches) {
|
2909
|
-
patches[patchesRes.patchId] = {
|
2910
|
-
path: patchesRes.path,
|
2911
|
-
authorId: patchesRes.authorId,
|
2912
|
-
createdAt: patchesRes.createdAt,
|
2913
|
-
appliedAt: patchesRes.applied && {
|
2914
|
-
baseSha: patchesRes.applied.baseSha,
|
2915
|
-
timestamp: patchesRes.applied.appliedAt,
|
2916
|
-
git: {
|
2917
|
-
commitSha: patchesRes.applied.commitSha
|
2918
|
-
}
|
2919
|
-
}
|
2920
|
-
};
|
2921
|
-
}
|
2922
|
-
return {
|
2923
|
-
patches
|
2924
|
-
};
|
2925
|
-
}
|
2926
|
-
return {
|
2927
|
-
patches,
|
2928
|
-
error: {
|
2929
|
-
message: `Could not parse search patches response. Error: ${zodValidationError.fromError(parsed.error)}`
|
2930
|
-
}
|
2931
|
-
};
|
2932
|
-
}
|
2933
|
-
return {
|
2934
|
-
patches,
|
2935
|
-
error: {
|
2936
|
-
message: "Could not find patches. HTTP error: " + res.status + " " + res.statusText
|
2937
|
-
}
|
2938
|
-
};
|
2939
|
-
});
|
2940
|
-
}
|
2941
2906
|
async saveSourceFilePatch(path, patch, authorId) {
|
2942
2907
|
return fetch(`${this.hostUrl}/v1/${this.project}/patches`, {
|
2943
2908
|
method: "POST",
|
@@ -3652,8 +3617,10 @@ class ValServer {
|
|
3652
3617
|
};
|
3653
3618
|
}
|
3654
3619
|
const authors = query.authors;
|
3655
|
-
const patches = await this.serverOps.
|
3656
|
-
authors
|
3620
|
+
const patches = await this.serverOps.fetchPatches({
|
3621
|
+
authors,
|
3622
|
+
patchIds: query.patchIds,
|
3623
|
+
omitPatch: query.omitPatch === "true"
|
3657
3624
|
});
|
3658
3625
|
if (patches.errors && Object.keys(patches.errors).length > 0) {
|
3659
3626
|
console.error("Val: Failed to get patches", patches.errors);
|
@@ -3665,23 +3632,9 @@ class ValServer {
|
|
3665
3632
|
}
|
3666
3633
|
};
|
3667
3634
|
}
|
3668
|
-
const res = {};
|
3669
|
-
for (const [patchIdS, patchData] of Object.entries(patches.patches)) {
|
3670
|
-
var _patchData$appliedAt;
|
3671
|
-
const patchId = patchIdS;
|
3672
|
-
if (!res[patchData.path]) {
|
3673
|
-
res[patchData.path] = [];
|
3674
|
-
}
|
3675
|
-
res[patchData.path].push({
|
3676
|
-
patch_id: patchId,
|
3677
|
-
created_at: patchData.createdAt,
|
3678
|
-
applied_at_base_sha: ((_patchData$appliedAt = patchData.appliedAt) === null || _patchData$appliedAt === void 0 ? void 0 : _patchData$appliedAt.baseSha) || null,
|
3679
|
-
author: patchData.authorId ?? undefined
|
3680
|
-
});
|
3681
|
-
}
|
3682
3635
|
return {
|
3683
3636
|
status: 200,
|
3684
|
-
json:
|
3637
|
+
json: patches
|
3685
3638
|
};
|
3686
3639
|
}
|
3687
3640
|
async deletePatches(query, cookies) {
|
@@ -3817,11 +3770,15 @@ class ValServer {
|
|
3817
3770
|
}
|
3818
3771
|
let tree;
|
3819
3772
|
let patchAnalysis = null;
|
3773
|
+
let newPatchId = undefined;
|
3820
3774
|
if ((_bodyRes$data = bodyRes.data) !== null && _bodyRes$data !== void 0 && _bodyRes$data.patchIds && ((_bodyRes$data2 = bodyRes.data) === null || _bodyRes$data2 === void 0 || (_bodyRes$data2 = _bodyRes$data2.patchIds) === null || _bodyRes$data2 === void 0 ? void 0 : _bodyRes$data2.length) > 0 || (_bodyRes$data3 = bodyRes.data) !== null && _bodyRes$data3 !== void 0 && _bodyRes$data3.addPatch) {
|
3821
3775
|
var _bodyRes$data4, _bodyRes$data5;
|
3822
3776
|
// TODO: validate patches_sha
|
3823
3777
|
const patchIds = (_bodyRes$data4 = bodyRes.data) === null || _bodyRes$data4 === void 0 ? void 0 : _bodyRes$data4.patchIds;
|
3824
|
-
const patchOps = patchIds && patchIds.length > 0 ? await this.serverOps.
|
3778
|
+
const patchOps = patchIds && patchIds.length > 0 ? await this.serverOps.fetchPatches({
|
3779
|
+
patchIds,
|
3780
|
+
omitPatch: false
|
3781
|
+
}) : {
|
3825
3782
|
patches: {}
|
3826
3783
|
};
|
3827
3784
|
let patchErrors = undefined;
|
@@ -3862,6 +3819,7 @@ class ValServer {
|
|
3862
3819
|
// };
|
3863
3820
|
// }
|
3864
3821
|
// }
|
3822
|
+
newPatchId = createPatchRes.patchId;
|
3865
3823
|
patchOps.patches[createPatchRes.patchId] = {
|
3866
3824
|
path: newPatchModuleFilePath,
|
3867
3825
|
patch: newPatchOps,
|
@@ -3923,7 +3881,8 @@ class ValServer {
|
|
3923
3881
|
status: 200,
|
3924
3882
|
json: {
|
3925
3883
|
schemaSha,
|
3926
|
-
modules
|
3884
|
+
modules,
|
3885
|
+
newPatchId
|
3927
3886
|
}
|
3928
3887
|
};
|
3929
3888
|
}
|
@@ -3954,7 +3913,10 @@ class ValServer {
|
|
3954
3913
|
const {
|
3955
3914
|
patchIds
|
3956
3915
|
} = bodyRes.data;
|
3957
|
-
const patches = await this.serverOps.
|
3916
|
+
const patches = await this.serverOps.fetchPatches({
|
3917
|
+
patchIds,
|
3918
|
+
omitPatch: false
|
3919
|
+
});
|
3958
3920
|
const analysis = this.serverOps.analyzePatches(patches.patches);
|
3959
3921
|
const preparedCommit = await this.serverOps.prepare({
|
3960
3922
|
...analysis,
|
@@ -4550,7 +4512,9 @@ function createValApiRouter(route, valServerPromise, convert) {
|
|
4550
4512
|
}, getCookies(req, [VAL_SESSION_COOKIE]))));
|
4551
4513
|
} else if (method === "GET" && path.startsWith(PATCHES_PATH_PREFIX)) {
|
4552
4514
|
return withTreePath(path, PATCHES_PATH_PREFIX)(async () => convert(await valServer.getPatches({
|
4553
|
-
authors: url.searchParams.getAll("author")
|
4515
|
+
authors: url.searchParams.getAll("author"),
|
4516
|
+
patchIds: url.searchParams.getAll("patch_id"),
|
4517
|
+
omitPatch: url.searchParams.get("omit_patch") || undefined
|
4554
4518
|
}, getCookies(req, [VAL_SESSION_COOKIE]))));
|
4555
4519
|
} else if (method === "DELETE" && path.startsWith(PATCHES_PATH_PREFIX)) {
|
4556
4520
|
return withTreePath(path, PATCHES_PATH_PREFIX)(async () => convert(await valServer.deletePatches({
|
@@ -1507,10 +1507,10 @@ class ValOps {
|
|
1507
1507
|
} else {
|
1508
1508
|
const patchData = analysis.patches[patchId];
|
1509
1509
|
if (!patchData) {
|
1510
|
-
errors[path]
|
1510
|
+
errors[path] = [{
|
1511
1511
|
patchId: patchId,
|
1512
1512
|
error: new PatchError(`Patch not found`)
|
1513
|
-
}
|
1513
|
+
}];
|
1514
1514
|
continue;
|
1515
1515
|
}
|
1516
1516
|
const applicableOps = [];
|
@@ -1807,7 +1807,7 @@ class ValOps {
|
|
1807
1807
|
let sourceFileText = unescape(tsSourceFile.getText(tsSourceFile).replace(/\\u/g, "%u"));
|
1808
1808
|
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.formatter) {
|
1809
1809
|
try {
|
1810
|
-
sourceFileText = this.options.formatter(sourceFileText, path);
|
1810
|
+
sourceFileText = await this.options.formatter(sourceFileText, path);
|
1811
1811
|
} catch (err) {
|
1812
1812
|
errors.push({
|
1813
1813
|
message: "Could not format source file: " + (err instanceof Error ? err.message : "Unknown error")
|
@@ -2237,7 +2237,7 @@ class ValOpsFS extends ValOps {
|
|
2237
2237
|
throw new Error("Could not parse patch id from file name. Files found: " + patchJsonFiles.join(", "));
|
2238
2238
|
}
|
2239
2239
|
const patchId = patchIdNum.toString();
|
2240
|
-
if (includes && !includes.includes(patchId)) {
|
2240
|
+
if (includes && includes.length > 0 && !includes.includes(patchId)) {
|
2241
2241
|
continue;
|
2242
2242
|
}
|
2243
2243
|
const parsedFSPatchRes = this.parseJsonFile(this.getPatchFilePath(patchId), FSPatch);
|
@@ -2266,22 +2266,23 @@ class ValOpsFS extends ValOps {
|
|
2266
2266
|
patches
|
2267
2267
|
};
|
2268
2268
|
}
|
2269
|
-
async
|
2270
|
-
return this.readPatches(patchIds);
|
2271
|
-
}
|
2272
|
-
async findPatches(filters) {
|
2269
|
+
async fetchPatches(filters) {
|
2273
2270
|
const patches = {};
|
2274
2271
|
const errors = {};
|
2275
2272
|
const {
|
2276
2273
|
errors: allErrors,
|
2277
2274
|
patches: allPatches
|
2278
|
-
} = await this.readPatches();
|
2275
|
+
} = await this.readPatches(filters.patchIds);
|
2279
2276
|
for (const [patchIdS, patch] of Object.entries(allPatches)) {
|
2280
2277
|
const patchId = patchIdS;
|
2281
2278
|
if (filters.authors && !(patch.authorId === null || filters.authors.includes(patch.authorId))) {
|
2282
2279
|
continue;
|
2283
2280
|
}
|
2281
|
+
if (filters.moduleFilePaths && !filters.moduleFilePaths.includes(patch.path)) {
|
2282
|
+
continue;
|
2283
|
+
}
|
2284
2284
|
patches[patchId] = {
|
2285
|
+
patch: filters.omitPatch ? undefined : patch.patch,
|
2285
2286
|
path: patch.path,
|
2286
2287
|
createdAt: patch.createdAt,
|
2287
2288
|
authorId: patch.authorId,
|
@@ -2744,9 +2745,6 @@ const GetPatches = z.object({
|
|
2744
2745
|
message: z.string()
|
2745
2746
|
})).optional()
|
2746
2747
|
});
|
2747
|
-
const SearchPatches = z.object({
|
2748
|
-
patches: z.array(BasePatchResponse)
|
2749
|
-
});
|
2750
2748
|
const FilesResponse = z.object({
|
2751
2749
|
files: z.array(z.union([z.object({
|
2752
2750
|
filePath: z.string(),
|
@@ -2805,13 +2803,29 @@ class ValOpsHttp extends ValOps {
|
|
2805
2803
|
async onInit() {
|
2806
2804
|
// TODO: unused for now. Implement or remove
|
2807
2805
|
}
|
2808
|
-
async
|
2809
|
-
const params =
|
2810
|
-
params.
|
2811
|
-
if (patchIds
|
2812
|
-
|
2806
|
+
async fetchPatches(filters) {
|
2807
|
+
const params = [];
|
2808
|
+
params.push(["branch", this.branch]);
|
2809
|
+
if (filters.patchIds) {
|
2810
|
+
for (const patchId of filters.patchIds) {
|
2811
|
+
params.push(["patch_id", patchId]);
|
2812
|
+
}
|
2813
2813
|
}
|
2814
|
-
|
2814
|
+
if (filters.authors) {
|
2815
|
+
for (const author of filters.authors) {
|
2816
|
+
params.push(["author_id", author]);
|
2817
|
+
}
|
2818
|
+
}
|
2819
|
+
if (filters.omitPatch) {
|
2820
|
+
params.push(["omit_patch", "true"]);
|
2821
|
+
}
|
2822
|
+
if (filters.moduleFilePaths) {
|
2823
|
+
for (const moduleFilePath of filters.moduleFilePaths) {
|
2824
|
+
params.push(["module_file_path", moduleFilePath]);
|
2825
|
+
}
|
2826
|
+
}
|
2827
|
+
const searchParams = new URLSearchParams(params);
|
2828
|
+
return fetch(`${this.hostUrl}/v1/${this.project}/patches${searchParams.size > 0 ? `?${searchParams.toString()}` : ""}`, {
|
2815
2829
|
headers: {
|
2816
2830
|
...this.authHeaders,
|
2817
2831
|
"Content-Type": "application/json"
|
@@ -2859,55 +2873,6 @@ class ValOpsHttp extends ValOps {
|
|
2859
2873
|
};
|
2860
2874
|
});
|
2861
2875
|
}
|
2862
|
-
async findPatches(filters) {
|
2863
|
-
const params = new URLSearchParams();
|
2864
|
-
params.set("branch", this.branch);
|
2865
|
-
if (filters.authors && filters.authors.length > 0) {
|
2866
|
-
params.set("author_ids", encodeURIComponent(filters.authors.join(",")));
|
2867
|
-
}
|
2868
|
-
return fetch(`${this.hostUrl}/v1/${this.project}/search/patches${params.size > 0 ? "?" + params : ""}`, {
|
2869
|
-
headers: {
|
2870
|
-
...this.authHeaders,
|
2871
|
-
"Content-Type": "application/json"
|
2872
|
-
}
|
2873
|
-
}).then(async res => {
|
2874
|
-
const patches = {};
|
2875
|
-
if (res.ok) {
|
2876
|
-
const parsed = SearchPatches.safeParse(await res.json());
|
2877
|
-
if (parsed.success) {
|
2878
|
-
for (const patchesRes of parsed.data.patches) {
|
2879
|
-
patches[patchesRes.patchId] = {
|
2880
|
-
path: patchesRes.path,
|
2881
|
-
authorId: patchesRes.authorId,
|
2882
|
-
createdAt: patchesRes.createdAt,
|
2883
|
-
appliedAt: patchesRes.applied && {
|
2884
|
-
baseSha: patchesRes.applied.baseSha,
|
2885
|
-
timestamp: patchesRes.applied.appliedAt,
|
2886
|
-
git: {
|
2887
|
-
commitSha: patchesRes.applied.commitSha
|
2888
|
-
}
|
2889
|
-
}
|
2890
|
-
};
|
2891
|
-
}
|
2892
|
-
return {
|
2893
|
-
patches
|
2894
|
-
};
|
2895
|
-
}
|
2896
|
-
return {
|
2897
|
-
patches,
|
2898
|
-
error: {
|
2899
|
-
message: `Could not parse search patches response. Error: ${fromError(parsed.error)}`
|
2900
|
-
}
|
2901
|
-
};
|
2902
|
-
}
|
2903
|
-
return {
|
2904
|
-
patches,
|
2905
|
-
error: {
|
2906
|
-
message: "Could not find patches. HTTP error: " + res.status + " " + res.statusText
|
2907
|
-
}
|
2908
|
-
};
|
2909
|
-
});
|
2910
|
-
}
|
2911
2876
|
async saveSourceFilePatch(path, patch, authorId) {
|
2912
2877
|
return fetch(`${this.hostUrl}/v1/${this.project}/patches`, {
|
2913
2878
|
method: "POST",
|
@@ -3622,8 +3587,10 @@ class ValServer {
|
|
3622
3587
|
};
|
3623
3588
|
}
|
3624
3589
|
const authors = query.authors;
|
3625
|
-
const patches = await this.serverOps.
|
3626
|
-
authors
|
3590
|
+
const patches = await this.serverOps.fetchPatches({
|
3591
|
+
authors,
|
3592
|
+
patchIds: query.patchIds,
|
3593
|
+
omitPatch: query.omitPatch === "true"
|
3627
3594
|
});
|
3628
3595
|
if (patches.errors && Object.keys(patches.errors).length > 0) {
|
3629
3596
|
console.error("Val: Failed to get patches", patches.errors);
|
@@ -3635,23 +3602,9 @@ class ValServer {
|
|
3635
3602
|
}
|
3636
3603
|
};
|
3637
3604
|
}
|
3638
|
-
const res = {};
|
3639
|
-
for (const [patchIdS, patchData] of Object.entries(patches.patches)) {
|
3640
|
-
var _patchData$appliedAt;
|
3641
|
-
const patchId = patchIdS;
|
3642
|
-
if (!res[patchData.path]) {
|
3643
|
-
res[patchData.path] = [];
|
3644
|
-
}
|
3645
|
-
res[patchData.path].push({
|
3646
|
-
patch_id: patchId,
|
3647
|
-
created_at: patchData.createdAt,
|
3648
|
-
applied_at_base_sha: ((_patchData$appliedAt = patchData.appliedAt) === null || _patchData$appliedAt === void 0 ? void 0 : _patchData$appliedAt.baseSha) || null,
|
3649
|
-
author: patchData.authorId ?? undefined
|
3650
|
-
});
|
3651
|
-
}
|
3652
3605
|
return {
|
3653
3606
|
status: 200,
|
3654
|
-
json:
|
3607
|
+
json: patches
|
3655
3608
|
};
|
3656
3609
|
}
|
3657
3610
|
async deletePatches(query, cookies) {
|
@@ -3787,11 +3740,15 @@ class ValServer {
|
|
3787
3740
|
}
|
3788
3741
|
let tree;
|
3789
3742
|
let patchAnalysis = null;
|
3743
|
+
let newPatchId = undefined;
|
3790
3744
|
if ((_bodyRes$data = bodyRes.data) !== null && _bodyRes$data !== void 0 && _bodyRes$data.patchIds && ((_bodyRes$data2 = bodyRes.data) === null || _bodyRes$data2 === void 0 || (_bodyRes$data2 = _bodyRes$data2.patchIds) === null || _bodyRes$data2 === void 0 ? void 0 : _bodyRes$data2.length) > 0 || (_bodyRes$data3 = bodyRes.data) !== null && _bodyRes$data3 !== void 0 && _bodyRes$data3.addPatch) {
|
3791
3745
|
var _bodyRes$data4, _bodyRes$data5;
|
3792
3746
|
// TODO: validate patches_sha
|
3793
3747
|
const patchIds = (_bodyRes$data4 = bodyRes.data) === null || _bodyRes$data4 === void 0 ? void 0 : _bodyRes$data4.patchIds;
|
3794
|
-
const patchOps = patchIds && patchIds.length > 0 ? await this.serverOps.
|
3748
|
+
const patchOps = patchIds && patchIds.length > 0 ? await this.serverOps.fetchPatches({
|
3749
|
+
patchIds,
|
3750
|
+
omitPatch: false
|
3751
|
+
}) : {
|
3795
3752
|
patches: {}
|
3796
3753
|
};
|
3797
3754
|
let patchErrors = undefined;
|
@@ -3832,6 +3789,7 @@ class ValServer {
|
|
3832
3789
|
// };
|
3833
3790
|
// }
|
3834
3791
|
// }
|
3792
|
+
newPatchId = createPatchRes.patchId;
|
3835
3793
|
patchOps.patches[createPatchRes.patchId] = {
|
3836
3794
|
path: newPatchModuleFilePath,
|
3837
3795
|
patch: newPatchOps,
|
@@ -3893,7 +3851,8 @@ class ValServer {
|
|
3893
3851
|
status: 200,
|
3894
3852
|
json: {
|
3895
3853
|
schemaSha,
|
3896
|
-
modules
|
3854
|
+
modules,
|
3855
|
+
newPatchId
|
3897
3856
|
}
|
3898
3857
|
};
|
3899
3858
|
}
|
@@ -3924,7 +3883,10 @@ class ValServer {
|
|
3924
3883
|
const {
|
3925
3884
|
patchIds
|
3926
3885
|
} = bodyRes.data;
|
3927
|
-
const patches = await this.serverOps.
|
3886
|
+
const patches = await this.serverOps.fetchPatches({
|
3887
|
+
patchIds,
|
3888
|
+
omitPatch: false
|
3889
|
+
});
|
3928
3890
|
const analysis = this.serverOps.analyzePatches(patches.patches);
|
3929
3891
|
const preparedCommit = await this.serverOps.prepare({
|
3930
3892
|
...analysis,
|
@@ -4520,7 +4482,9 @@ function createValApiRouter(route, valServerPromise, convert) {
|
|
4520
4482
|
}, getCookies(req, [VAL_SESSION_COOKIE]))));
|
4521
4483
|
} else if (method === "GET" && path.startsWith(PATCHES_PATH_PREFIX)) {
|
4522
4484
|
return withTreePath(path, PATCHES_PATH_PREFIX)(async () => convert(await valServer.getPatches({
|
4523
|
-
authors: url.searchParams.getAll("author")
|
4485
|
+
authors: url.searchParams.getAll("author"),
|
4486
|
+
patchIds: url.searchParams.getAll("patch_id"),
|
4487
|
+
omitPatch: url.searchParams.get("omit_patch") || undefined
|
4524
4488
|
}, getCookies(req, [VAL_SESSION_COOKIE]))));
|
4525
4489
|
} else if (method === "DELETE" && path.startsWith(PATCHES_PATH_PREFIX)) {
|
4526
4490
|
return withTreePath(path, PATCHES_PATH_PREFIX)(async () => convert(await valServer.deletePatches({
|
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.63.
|
15
|
+
"version": "0.63.5",
|
16
16
|
"scripts": {
|
17
17
|
"typecheck": "tsc --noEmit",
|
18
18
|
"test": "jest",
|
@@ -22,9 +22,9 @@
|
|
22
22
|
"@types/jest": "^29.2.5"
|
23
23
|
},
|
24
24
|
"dependencies": {
|
25
|
-
"@valbuild/core": "~0.63.
|
26
|
-
"@valbuild/shared": "~0.63.
|
27
|
-
"@valbuild/ui": "~0.63.
|
25
|
+
"@valbuild/core": "~0.63.5",
|
26
|
+
"@valbuild/shared": "~0.63.5",
|
27
|
+
"@valbuild/ui": "~0.63.5",
|
28
28
|
"image-size": "^1.0.2",
|
29
29
|
"minimatch": "^3.0.4",
|
30
30
|
"quickjs-emscripten": "^0.21.1",
|