@valbuild/server 0.150.13 → 0.150.16
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/CHANGELOG.md +24 -0
- package/browser/dist/valbuild-server-browser.cjs.dev.js +1 -1
- package/browser/dist/valbuild-server-browser.cjs.prod.js +1 -1
- package/browser/dist/valbuild-server-browser.esm.js +1 -1
- package/dist/{ValRouterCore-f5d6d448.cjs.dev.js → ValRouterCore-4b42da9b.cjs.dev.js} +385 -2
- package/dist/{ValRouterCore-e5a916eb.cjs.prod.js → ValRouterCore-4ea2110e.cjs.prod.js} +385 -2
- package/dist/{ValRouterCore-f328843e.esm.js → ValRouterCore-c250061f.esm.js} +381 -4
- package/dist/declarations/src/ValOps.d.ts +6 -0
- package/dist/declarations/src/ValOpsFS.d.ts +3 -0
- package/dist/declarations/src/ValOpsHttp.d.ts +3 -0
- package/dist/declarations/src/ValOpsMemory.d.ts +3 -0
- package/dist/declarations/src/sketchpads/SketchpadStore.d.ts +76 -0
- package/dist/{getJsonEntryAtCommit-08387cef.esm.js → getJsonEntryAtCommit-5d340344.esm.js} +1 -1
- package/dist/{getJsonEntryAtCommit-e1946be3.cjs.dev.js → getJsonEntryAtCommit-971b7bbe.cjs.dev.js} +1 -1
- package/dist/{getJsonEntryAtCommit-fbd7665f.cjs.prod.js → getJsonEntryAtCommit-ece4f965.cjs.prod.js} +1 -1
- package/dist/valbuild-server.cjs.dev.js +211 -1
- package/dist/valbuild-server.cjs.prod.js +211 -1
- package/dist/valbuild-server.esm.js +213 -3
- package/package.json +3 -3
|
@@ -10,12 +10,12 @@ import path from 'path';
|
|
|
10
10
|
import fs from 'fs';
|
|
11
11
|
import vm from 'node:vm';
|
|
12
12
|
import { Module } from 'node:module';
|
|
13
|
-
import { r as resolveExistingJsonPath, f as findNestedJsonValuesRecords, v as validateJsonValuesEntries, i as isJsonValuesRootOp, a as rebaseContentOp, c as classifyJsonValuesOp, V as ValOps,
|
|
14
|
-
export {
|
|
13
|
+
import { r as resolveExistingJsonPath, f as findNestedJsonValuesRecords, v as validateJsonValuesEntries, i as isJsonValuesRootOp, a as rebaseContentOp, c as classifyJsonValuesOp, s as summaryOf, m as matchesFilter, b as byUpdatedAt, n as newSketchpad, d as isSketchpadId, e as applySketchpadChange, V as ValOps, g as bufferFromDataUrl, h as getFieldsForType, u as uploadRemoteFile, j as getFileExt, k as guessMimeTypeFromPath, l as createMetadataFromBuffer, o as ValOpsMemory, p as isHlsMasterPlaylist, q as sumHlsSegmentDurations, t as parseHlsMasterVariants, w as largestHlsVariant, x as fallbackRefOf, y as mapHlsUris, z as movedRemoteHost, A as needsHostCheck, B as rewriteRefHost, C as fallbackRemoteHost, D as checkRemoteFiles, E as ValServer, F as createValRequestHandler, G as getNewJsonEntryPaths, H as formatPatchSourceError } from './ValRouterCore-c250061f.esm.js';
|
|
14
|
+
export { K as InMemoryPatchStore, o as ValOpsMemory, I as askOncePerHost, c as classifyJsonValuesOp, H as formatPatchSourceError, j as getFileExt, J as getSettings, a as rebaseContentOp, u as uploadRemoteFile } from './ValRouterCore-c250061f.esm.js';
|
|
15
15
|
import { createUIRequestHandler } from '@valbuild/ui/server';
|
|
16
16
|
import z$1, { z } from 'zod';
|
|
17
17
|
import { fromError } from 'zod-validation-error';
|
|
18
|
-
import { Patch, schemaErrorsOf, PatchSets, joinSharedChanges, schemaTypesOfPath, sideFiles, sideSource, JSONValue, PlanRefusalError, PatchId as PatchId$1, SerializedSchema, getErrorMessageFromUnknownJson, newestCommitSha, LOCAL_FILE_IN_REMOTE_PROJECT_WARNING, LOCAL_FILE_IN_REMOTE_PROJECT_HINT, traverseSchemaSource, richTextImageSchema, forEachRichTextImage, isStudioFix } from '@valbuild/shared/internal';
|
|
18
|
+
import { Patch, Sketchpad, schemaErrorsOf, PatchSets, joinSharedChanges, schemaTypesOfPath, sideFiles, sideSource, JSONValue, SketchpadSummary, PlanRefusalError, PatchId as PatchId$1, SerializedSchema, getErrorMessageFromUnknownJson, newestCommitSha, LOCAL_FILE_IN_REMOTE_PROJECT_WARNING, LOCAL_FILE_IN_REMOTE_PROJECT_HINT, traverseSchemaSource, richTextImageSchema, forEachRichTextImage, isStudioFix } from '@valbuild/shared/internal';
|
|
19
19
|
import os from 'os';
|
|
20
20
|
import crypto$1, { createHash } from 'crypto';
|
|
21
21
|
import { Buffer as Buffer$1 } from 'buffer';
|
|
@@ -2433,6 +2433,88 @@ async function withPatchLock(lockFilePath, options, fn) {
|
|
|
2433
2433
|
}
|
|
2434
2434
|
}
|
|
2435
2435
|
|
|
2436
|
+
/**
|
|
2437
|
+
* Sketchpads in `fs` mode: one JSON file each, in `.val/sketchpads/` beside
|
|
2438
|
+
* the patch store (and nothing to do with it -- a sketchpad is not an edit
|
|
2439
|
+
* and is never published).
|
|
2440
|
+
*
|
|
2441
|
+
* A file is replaced by writing a temporary one and renaming it over, so a
|
|
2442
|
+
* reader never sees half of one. Changes to one sketchpad are queued in this
|
|
2443
|
+
* process, so its version check and its write are one step. Two dev servers
|
|
2444
|
+
* writing the same sketchpad at the same instant could still race; that is
|
|
2445
|
+
* a cost local development can carry, and the content service, which hosts
|
|
2446
|
+
* every real project's, does the check in one database statement.
|
|
2447
|
+
*/
|
|
2448
|
+
function createFsSketchpadStore(rootDir, now = () => new Date()) {
|
|
2449
|
+
const dir = path.join(rootDir, ".val", "sketchpads");
|
|
2450
|
+
const fileOf = id => path.join(dir, `${id}.json`);
|
|
2451
|
+
const queues = new Map();
|
|
2452
|
+
const read = async id => {
|
|
2453
|
+
if (!isSketchpadId(id)) {
|
|
2454
|
+
return null;
|
|
2455
|
+
}
|
|
2456
|
+
let raw;
|
|
2457
|
+
try {
|
|
2458
|
+
raw = await fs.promises.readFile(fileOf(id), "utf8");
|
|
2459
|
+
} catch {
|
|
2460
|
+
return null;
|
|
2461
|
+
}
|
|
2462
|
+
try {
|
|
2463
|
+
const parsed = Sketchpad.safeParse(JSON.parse(raw));
|
|
2464
|
+
if (parsed.success) {
|
|
2465
|
+
return parsed.data;
|
|
2466
|
+
}
|
|
2467
|
+
} catch {
|
|
2468
|
+
// Reported below, as for a file that parsed and was not a sketchpad.
|
|
2469
|
+
}
|
|
2470
|
+
Internal.log.warn(`${fileOf(id)} is not a sketchpad, so it is left out. Move it away to stop this message.`);
|
|
2471
|
+
return null;
|
|
2472
|
+
};
|
|
2473
|
+
const write = async sketchpad => {
|
|
2474
|
+
await fs.promises.mkdir(dir, {
|
|
2475
|
+
recursive: true
|
|
2476
|
+
});
|
|
2477
|
+
const temporary = `${fileOf(sketchpad.id)}.${process.pid}.tmp`;
|
|
2478
|
+
await fs.promises.writeFile(temporary, JSON.stringify(sketchpad, null, 2));
|
|
2479
|
+
await fs.promises.rename(temporary, fileOf(sketchpad.id));
|
|
2480
|
+
};
|
|
2481
|
+
|
|
2482
|
+
/** Runs `task` after every earlier change to `id` has finished. */
|
|
2483
|
+
const queued = (id, task) => {
|
|
2484
|
+
const previous = queues.get(id) ?? Promise.resolve();
|
|
2485
|
+
const next = previous.then(task, task);
|
|
2486
|
+
queues.set(id, next.catch(() => undefined));
|
|
2487
|
+
return next;
|
|
2488
|
+
};
|
|
2489
|
+
return {
|
|
2490
|
+
async list(filter) {
|
|
2491
|
+
let names;
|
|
2492
|
+
try {
|
|
2493
|
+
names = await fs.promises.readdir(dir);
|
|
2494
|
+
} catch {
|
|
2495
|
+
return [];
|
|
2496
|
+
}
|
|
2497
|
+
const all = await Promise.all(names.filter(name => name.endsWith(".json")).map(name => read(name.slice(0, -".json".length))));
|
|
2498
|
+
return all.filter(sketchpad => sketchpad !== null).map(summaryOf).filter(sketchpad => matchesFilter(sketchpad, filter)).sort(byUpdatedAt);
|
|
2499
|
+
},
|
|
2500
|
+
get: read,
|
|
2501
|
+
async create(input) {
|
|
2502
|
+
const sketchpad = newSketchpad(input, now());
|
|
2503
|
+
await write(sketchpad);
|
|
2504
|
+
return sketchpad;
|
|
2505
|
+
},
|
|
2506
|
+
update(id, change) {
|
|
2507
|
+
return queued(id, async () => {
|
|
2508
|
+
const result = applySketchpadChange(await read(id), change, now());
|
|
2509
|
+
if (result.status === "updated") {
|
|
2510
|
+
await write(result.sketchpad);
|
|
2511
|
+
}
|
|
2512
|
+
return result;
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
};
|
|
2516
|
+
}
|
|
2517
|
+
|
|
2436
2518
|
/** Serializes a schema, or gives up quietly — serialization errors are reported elsewhere. */
|
|
2437
2519
|
function serializeSchemaSafely(schema) {
|
|
2438
2520
|
try {
|
|
@@ -2458,8 +2540,12 @@ class ValOpsFS extends ValOps {
|
|
|
2458
2540
|
this.rootDir = rootDir;
|
|
2459
2541
|
this.host = new FSOpsHost();
|
|
2460
2542
|
this.jsonEntryFilesFingerprint = new JsonEntryFilesFingerprint(rootDir);
|
|
2543
|
+
this.sketchpads = createFsSketchpadStore(rootDir);
|
|
2461
2544
|
}
|
|
2462
2545
|
|
|
2546
|
+
/** In `.val/sketchpads`. See `sketchpads/fsSketchpadStore.ts`. */
|
|
2547
|
+
sketchpads;
|
|
2548
|
+
|
|
2463
2549
|
/**
|
|
2464
2550
|
* Change detection for `.jsonValues()` entry files, which no sha can see (their
|
|
2465
2551
|
* content lives behind a thunk that `JSON.stringify` drops).
|
|
@@ -5081,6 +5167,124 @@ function movesAtMerge(inputs, schemas) {
|
|
|
5081
5167
|
};
|
|
5082
5168
|
}
|
|
5083
5169
|
|
|
5170
|
+
/**
|
|
5171
|
+
* Sketchpads in `http` mode: the content service keeps them, per project, at
|
|
5172
|
+
* `/v1/{project}/sketchpads` (valbuild/home). This only carries requests
|
|
5173
|
+
* there and reads the answers; the version check is the service's, done in
|
|
5174
|
+
* one statement.
|
|
5175
|
+
*/
|
|
5176
|
+
function createHttpSketchpadStore(options) {
|
|
5177
|
+
const request = async (path, init) => fetch(`${options.url}${path}`, {
|
|
5178
|
+
method: init.method,
|
|
5179
|
+
headers: {
|
|
5180
|
+
...options.headers,
|
|
5181
|
+
// WHO, as for a proposal or a commit: the key names the project.
|
|
5182
|
+
...(init.by ? {
|
|
5183
|
+
"x-val-profile-id": init.by
|
|
5184
|
+
} : {}),
|
|
5185
|
+
...(init.body !== undefined ? {
|
|
5186
|
+
"Content-Type": "application/json"
|
|
5187
|
+
} : {})
|
|
5188
|
+
},
|
|
5189
|
+
...(init.body !== undefined ? {
|
|
5190
|
+
body: JSON.stringify(init.body)
|
|
5191
|
+
} : {})
|
|
5192
|
+
});
|
|
5193
|
+
const failed = async (res, doing) => new Error(`Val Build could not ${doing} (HTTP ${res.status}): ${await res.text().catch(() => "")}`);
|
|
5194
|
+
return {
|
|
5195
|
+
async list(filter) {
|
|
5196
|
+
const query = new URLSearchParams({
|
|
5197
|
+
archived: filter.archived
|
|
5198
|
+
});
|
|
5199
|
+
if (filter.page !== undefined) {
|
|
5200
|
+
query.set("page", filter.page);
|
|
5201
|
+
}
|
|
5202
|
+
const res = await request(`?${query}`, {
|
|
5203
|
+
method: "GET"
|
|
5204
|
+
});
|
|
5205
|
+
if (!res.ok) {
|
|
5206
|
+
throw await failed(res, "list the sketchpads");
|
|
5207
|
+
}
|
|
5208
|
+
return z.object({
|
|
5209
|
+
sketchpads: z.array(SketchpadSummary)
|
|
5210
|
+
}).parse(await res.json()).sketchpads;
|
|
5211
|
+
},
|
|
5212
|
+
async get(id) {
|
|
5213
|
+
if (!isSketchpadId(id)) {
|
|
5214
|
+
return null;
|
|
5215
|
+
}
|
|
5216
|
+
const res = await request(`/${encodeURIComponent(id)}`, {
|
|
5217
|
+
method: "GET"
|
|
5218
|
+
});
|
|
5219
|
+
if (res.status === 404) {
|
|
5220
|
+
return null;
|
|
5221
|
+
}
|
|
5222
|
+
if (!res.ok) {
|
|
5223
|
+
throw await failed(res, "read the sketchpad");
|
|
5224
|
+
}
|
|
5225
|
+
return z.object({
|
|
5226
|
+
sketchpad: Sketchpad
|
|
5227
|
+
}).parse(await res.json()).sketchpad;
|
|
5228
|
+
},
|
|
5229
|
+
async create(input) {
|
|
5230
|
+
const res = await request("", {
|
|
5231
|
+
method: "POST",
|
|
5232
|
+
body: {
|
|
5233
|
+
text: input.text,
|
|
5234
|
+
title: input.title,
|
|
5235
|
+
page: input.page
|
|
5236
|
+
},
|
|
5237
|
+
by: input.by
|
|
5238
|
+
});
|
|
5239
|
+
if (!res.ok) {
|
|
5240
|
+
throw await failed(res, "make the sketchpad");
|
|
5241
|
+
}
|
|
5242
|
+
return z.object({
|
|
5243
|
+
sketchpad: Sketchpad
|
|
5244
|
+
}).parse(await res.json()).sketchpad;
|
|
5245
|
+
},
|
|
5246
|
+
async update(id, change) {
|
|
5247
|
+
if (!isSketchpadId(id)) {
|
|
5248
|
+
return {
|
|
5249
|
+
status: "not-found"
|
|
5250
|
+
};
|
|
5251
|
+
}
|
|
5252
|
+
const {
|
|
5253
|
+
by,
|
|
5254
|
+
...body
|
|
5255
|
+
} = change;
|
|
5256
|
+
const res = await request(`/${encodeURIComponent(id)}`, {
|
|
5257
|
+
method: "PATCH",
|
|
5258
|
+
body,
|
|
5259
|
+
by
|
|
5260
|
+
});
|
|
5261
|
+
if (res.status === 404) {
|
|
5262
|
+
return {
|
|
5263
|
+
status: "not-found"
|
|
5264
|
+
};
|
|
5265
|
+
}
|
|
5266
|
+
if (res.status === 409) {
|
|
5267
|
+
const current = z.object({
|
|
5268
|
+
sketchpad: Sketchpad
|
|
5269
|
+
}).parse(await res.json()).sketchpad;
|
|
5270
|
+
return {
|
|
5271
|
+
status: "conflict",
|
|
5272
|
+
sketchpad: current
|
|
5273
|
+
};
|
|
5274
|
+
}
|
|
5275
|
+
if (!res.ok) {
|
|
5276
|
+
throw await failed(res, "save the sketchpad");
|
|
5277
|
+
}
|
|
5278
|
+
return {
|
|
5279
|
+
status: "updated",
|
|
5280
|
+
sketchpad: z.object({
|
|
5281
|
+
sketchpad: Sketchpad
|
|
5282
|
+
}).parse(await res.json()).sketchpad
|
|
5283
|
+
};
|
|
5284
|
+
}
|
|
5285
|
+
};
|
|
5286
|
+
}
|
|
5287
|
+
|
|
5084
5288
|
const textEncoder$2 = new TextEncoder();
|
|
5085
5289
|
|
|
5086
5290
|
/** The body of the content API's 403 for a write the project's plan refuses. */
|
|
@@ -5382,6 +5586,8 @@ class ValOpsHttp extends ValOps {
|
|
|
5382
5586
|
/** Val's content service owns the store. See {@link ValOps.patchesAreLocal}. */
|
|
5383
5587
|
patchesAreLocal = false;
|
|
5384
5588
|
kind = "http";
|
|
5589
|
+
/** The content service's. See `sketchpads/httpSketchpadStore.ts`. */
|
|
5590
|
+
sketchpads;
|
|
5385
5591
|
/** See {@link ValOps.requiresAuth}. */
|
|
5386
5592
|
requiresAuth = true;
|
|
5387
5593
|
/**
|
|
@@ -5509,6 +5715,10 @@ class ValOpsHttp extends ValOps {
|
|
|
5509
5715
|
Authorization: `Bearer ${auth.apiKey}`
|
|
5510
5716
|
};
|
|
5511
5717
|
this.root = (options === null || options === void 0 ? void 0 : options.root) ?? "";
|
|
5718
|
+
this.sketchpads = createHttpSketchpadStore({
|
|
5719
|
+
url: `${contentUrl}/v1/${project}/sketchpads`,
|
|
5720
|
+
headers: this.authHeaders
|
|
5721
|
+
});
|
|
5512
5722
|
this.proposal = (options === null || options === void 0 ? void 0 : options.proposal) ?? null;
|
|
5513
5723
|
this.contentVersion = this.proposal === null ? (options === null || options === void 0 ? void 0 : options.contentVersion) ?? null : null;
|
|
5514
5724
|
/*
|
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"exports": true
|
|
29
29
|
},
|
|
30
|
-
"version": "0.150.
|
|
30
|
+
"version": "0.150.16",
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@prettier/sync": "^0.6.1",
|
|
33
33
|
"@types/jest": "^30.0.0",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"zod": "^4.4.3",
|
|
43
43
|
"zod-validation-error": "^5.0.0",
|
|
44
44
|
"@valbuild/core": "0.150.3",
|
|
45
|
-
"@valbuild/
|
|
46
|
-
"@valbuild/
|
|
45
|
+
"@valbuild/ui": "0.150.16",
|
|
46
|
+
"@valbuild/shared": "0.150.16"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
49
|
"node": "^20.19.0 || >=22"
|