@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
|
@@ -12,7 +12,7 @@ var path = require('path');
|
|
|
12
12
|
var fs = require('fs');
|
|
13
13
|
var vm = require('node:vm');
|
|
14
14
|
var node_module = require('node:module');
|
|
15
|
-
var ValRouterCore = require('./ValRouterCore-
|
|
15
|
+
var ValRouterCore = require('./ValRouterCore-4b42da9b.cjs.dev.js');
|
|
16
16
|
var server = require('@valbuild/ui/server');
|
|
17
17
|
var z = require('zod');
|
|
18
18
|
var zodValidationError = require('zod-validation-error');
|
|
@@ -2469,6 +2469,88 @@ async function withPatchLock(lockFilePath, options, fn) {
|
|
|
2469
2469
|
}
|
|
2470
2470
|
}
|
|
2471
2471
|
|
|
2472
|
+
/**
|
|
2473
|
+
* Sketchpads in `fs` mode: one JSON file each, in `.val/sketchpads/` beside
|
|
2474
|
+
* the patch store (and nothing to do with it -- a sketchpad is not an edit
|
|
2475
|
+
* and is never published).
|
|
2476
|
+
*
|
|
2477
|
+
* A file is replaced by writing a temporary one and renaming it over, so a
|
|
2478
|
+
* reader never sees half of one. Changes to one sketchpad are queued in this
|
|
2479
|
+
* process, so its version check and its write are one step. Two dev servers
|
|
2480
|
+
* writing the same sketchpad at the same instant could still race; that is
|
|
2481
|
+
* a cost local development can carry, and the content service, which hosts
|
|
2482
|
+
* every real project's, does the check in one database statement.
|
|
2483
|
+
*/
|
|
2484
|
+
function createFsSketchpadStore(rootDir, now = () => new Date()) {
|
|
2485
|
+
const dir = path__default["default"].join(rootDir, ".val", "sketchpads");
|
|
2486
|
+
const fileOf = id => path__default["default"].join(dir, `${id}.json`);
|
|
2487
|
+
const queues = new Map();
|
|
2488
|
+
const read = async id => {
|
|
2489
|
+
if (!ValRouterCore.isSketchpadId(id)) {
|
|
2490
|
+
return null;
|
|
2491
|
+
}
|
|
2492
|
+
let raw;
|
|
2493
|
+
try {
|
|
2494
|
+
raw = await fs__default["default"].promises.readFile(fileOf(id), "utf8");
|
|
2495
|
+
} catch {
|
|
2496
|
+
return null;
|
|
2497
|
+
}
|
|
2498
|
+
try {
|
|
2499
|
+
const parsed = internal.Sketchpad.safeParse(JSON.parse(raw));
|
|
2500
|
+
if (parsed.success) {
|
|
2501
|
+
return parsed.data;
|
|
2502
|
+
}
|
|
2503
|
+
} catch {
|
|
2504
|
+
// Reported below, as for a file that parsed and was not a sketchpad.
|
|
2505
|
+
}
|
|
2506
|
+
core.Internal.log.warn(`${fileOf(id)} is not a sketchpad, so it is left out. Move it away to stop this message.`);
|
|
2507
|
+
return null;
|
|
2508
|
+
};
|
|
2509
|
+
const write = async sketchpad => {
|
|
2510
|
+
await fs__default["default"].promises.mkdir(dir, {
|
|
2511
|
+
recursive: true
|
|
2512
|
+
});
|
|
2513
|
+
const temporary = `${fileOf(sketchpad.id)}.${process.pid}.tmp`;
|
|
2514
|
+
await fs__default["default"].promises.writeFile(temporary, JSON.stringify(sketchpad, null, 2));
|
|
2515
|
+
await fs__default["default"].promises.rename(temporary, fileOf(sketchpad.id));
|
|
2516
|
+
};
|
|
2517
|
+
|
|
2518
|
+
/** Runs `task` after every earlier change to `id` has finished. */
|
|
2519
|
+
const queued = (id, task) => {
|
|
2520
|
+
const previous = queues.get(id) ?? Promise.resolve();
|
|
2521
|
+
const next = previous.then(task, task);
|
|
2522
|
+
queues.set(id, next.catch(() => undefined));
|
|
2523
|
+
return next;
|
|
2524
|
+
};
|
|
2525
|
+
return {
|
|
2526
|
+
async list(filter) {
|
|
2527
|
+
let names;
|
|
2528
|
+
try {
|
|
2529
|
+
names = await fs__default["default"].promises.readdir(dir);
|
|
2530
|
+
} catch {
|
|
2531
|
+
return [];
|
|
2532
|
+
}
|
|
2533
|
+
const all = await Promise.all(names.filter(name => name.endsWith(".json")).map(name => read(name.slice(0, -".json".length))));
|
|
2534
|
+
return all.filter(sketchpad => sketchpad !== null).map(ValRouterCore.summaryOf).filter(sketchpad => ValRouterCore.matchesFilter(sketchpad, filter)).sort(ValRouterCore.byUpdatedAt);
|
|
2535
|
+
},
|
|
2536
|
+
get: read,
|
|
2537
|
+
async create(input) {
|
|
2538
|
+
const sketchpad = ValRouterCore.newSketchpad(input, now());
|
|
2539
|
+
await write(sketchpad);
|
|
2540
|
+
return sketchpad;
|
|
2541
|
+
},
|
|
2542
|
+
update(id, change) {
|
|
2543
|
+
return queued(id, async () => {
|
|
2544
|
+
const result = ValRouterCore.applySketchpadChange(await read(id), change, now());
|
|
2545
|
+
if (result.status === "updated") {
|
|
2546
|
+
await write(result.sketchpad);
|
|
2547
|
+
}
|
|
2548
|
+
return result;
|
|
2549
|
+
});
|
|
2550
|
+
}
|
|
2551
|
+
};
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2472
2554
|
/** Serializes a schema, or gives up quietly — serialization errors are reported elsewhere. */
|
|
2473
2555
|
function serializeSchemaSafely(schema) {
|
|
2474
2556
|
try {
|
|
@@ -2494,8 +2576,12 @@ class ValOpsFS extends ValRouterCore.ValOps {
|
|
|
2494
2576
|
this.rootDir = rootDir;
|
|
2495
2577
|
this.host = new FSOpsHost();
|
|
2496
2578
|
this.jsonEntryFilesFingerprint = new JsonEntryFilesFingerprint(rootDir);
|
|
2579
|
+
this.sketchpads = createFsSketchpadStore(rootDir);
|
|
2497
2580
|
}
|
|
2498
2581
|
|
|
2582
|
+
/** In `.val/sketchpads`. See `sketchpads/fsSketchpadStore.ts`. */
|
|
2583
|
+
sketchpads;
|
|
2584
|
+
|
|
2499
2585
|
/**
|
|
2500
2586
|
* Change detection for `.jsonValues()` entry files, which no sha can see (their
|
|
2501
2587
|
* content lives behind a thunk that `JSON.stringify` drops).
|
|
@@ -5117,6 +5203,124 @@ function movesAtMerge(inputs, schemas) {
|
|
|
5117
5203
|
};
|
|
5118
5204
|
}
|
|
5119
5205
|
|
|
5206
|
+
/**
|
|
5207
|
+
* Sketchpads in `http` mode: the content service keeps them, per project, at
|
|
5208
|
+
* `/v1/{project}/sketchpads` (valbuild/home). This only carries requests
|
|
5209
|
+
* there and reads the answers; the version check is the service's, done in
|
|
5210
|
+
* one statement.
|
|
5211
|
+
*/
|
|
5212
|
+
function createHttpSketchpadStore(options) {
|
|
5213
|
+
const request = async (path, init) => fetch(`${options.url}${path}`, {
|
|
5214
|
+
method: init.method,
|
|
5215
|
+
headers: {
|
|
5216
|
+
...options.headers,
|
|
5217
|
+
// WHO, as for a proposal or a commit: the key names the project.
|
|
5218
|
+
...(init.by ? {
|
|
5219
|
+
"x-val-profile-id": init.by
|
|
5220
|
+
} : {}),
|
|
5221
|
+
...(init.body !== undefined ? {
|
|
5222
|
+
"Content-Type": "application/json"
|
|
5223
|
+
} : {})
|
|
5224
|
+
},
|
|
5225
|
+
...(init.body !== undefined ? {
|
|
5226
|
+
body: JSON.stringify(init.body)
|
|
5227
|
+
} : {})
|
|
5228
|
+
});
|
|
5229
|
+
const failed = async (res, doing) => new Error(`Val Build could not ${doing} (HTTP ${res.status}): ${await res.text().catch(() => "")}`);
|
|
5230
|
+
return {
|
|
5231
|
+
async list(filter) {
|
|
5232
|
+
const query = new URLSearchParams({
|
|
5233
|
+
archived: filter.archived
|
|
5234
|
+
});
|
|
5235
|
+
if (filter.page !== undefined) {
|
|
5236
|
+
query.set("page", filter.page);
|
|
5237
|
+
}
|
|
5238
|
+
const res = await request(`?${query}`, {
|
|
5239
|
+
method: "GET"
|
|
5240
|
+
});
|
|
5241
|
+
if (!res.ok) {
|
|
5242
|
+
throw await failed(res, "list the sketchpads");
|
|
5243
|
+
}
|
|
5244
|
+
return z.z.object({
|
|
5245
|
+
sketchpads: z.z.array(internal.SketchpadSummary)
|
|
5246
|
+
}).parse(await res.json()).sketchpads;
|
|
5247
|
+
},
|
|
5248
|
+
async get(id) {
|
|
5249
|
+
if (!ValRouterCore.isSketchpadId(id)) {
|
|
5250
|
+
return null;
|
|
5251
|
+
}
|
|
5252
|
+
const res = await request(`/${encodeURIComponent(id)}`, {
|
|
5253
|
+
method: "GET"
|
|
5254
|
+
});
|
|
5255
|
+
if (res.status === 404) {
|
|
5256
|
+
return null;
|
|
5257
|
+
}
|
|
5258
|
+
if (!res.ok) {
|
|
5259
|
+
throw await failed(res, "read the sketchpad");
|
|
5260
|
+
}
|
|
5261
|
+
return z.z.object({
|
|
5262
|
+
sketchpad: internal.Sketchpad
|
|
5263
|
+
}).parse(await res.json()).sketchpad;
|
|
5264
|
+
},
|
|
5265
|
+
async create(input) {
|
|
5266
|
+
const res = await request("", {
|
|
5267
|
+
method: "POST",
|
|
5268
|
+
body: {
|
|
5269
|
+
text: input.text,
|
|
5270
|
+
title: input.title,
|
|
5271
|
+
page: input.page
|
|
5272
|
+
},
|
|
5273
|
+
by: input.by
|
|
5274
|
+
});
|
|
5275
|
+
if (!res.ok) {
|
|
5276
|
+
throw await failed(res, "make the sketchpad");
|
|
5277
|
+
}
|
|
5278
|
+
return z.z.object({
|
|
5279
|
+
sketchpad: internal.Sketchpad
|
|
5280
|
+
}).parse(await res.json()).sketchpad;
|
|
5281
|
+
},
|
|
5282
|
+
async update(id, change) {
|
|
5283
|
+
if (!ValRouterCore.isSketchpadId(id)) {
|
|
5284
|
+
return {
|
|
5285
|
+
status: "not-found"
|
|
5286
|
+
};
|
|
5287
|
+
}
|
|
5288
|
+
const {
|
|
5289
|
+
by,
|
|
5290
|
+
...body
|
|
5291
|
+
} = change;
|
|
5292
|
+
const res = await request(`/${encodeURIComponent(id)}`, {
|
|
5293
|
+
method: "PATCH",
|
|
5294
|
+
body,
|
|
5295
|
+
by
|
|
5296
|
+
});
|
|
5297
|
+
if (res.status === 404) {
|
|
5298
|
+
return {
|
|
5299
|
+
status: "not-found"
|
|
5300
|
+
};
|
|
5301
|
+
}
|
|
5302
|
+
if (res.status === 409) {
|
|
5303
|
+
const current = z.z.object({
|
|
5304
|
+
sketchpad: internal.Sketchpad
|
|
5305
|
+
}).parse(await res.json()).sketchpad;
|
|
5306
|
+
return {
|
|
5307
|
+
status: "conflict",
|
|
5308
|
+
sketchpad: current
|
|
5309
|
+
};
|
|
5310
|
+
}
|
|
5311
|
+
if (!res.ok) {
|
|
5312
|
+
throw await failed(res, "save the sketchpad");
|
|
5313
|
+
}
|
|
5314
|
+
return {
|
|
5315
|
+
status: "updated",
|
|
5316
|
+
sketchpad: z.z.object({
|
|
5317
|
+
sketchpad: internal.Sketchpad
|
|
5318
|
+
}).parse(await res.json()).sketchpad
|
|
5319
|
+
};
|
|
5320
|
+
}
|
|
5321
|
+
};
|
|
5322
|
+
}
|
|
5323
|
+
|
|
5120
5324
|
const textEncoder$2 = new TextEncoder();
|
|
5121
5325
|
|
|
5122
5326
|
/** The body of the content API's 403 for a write the project's plan refuses. */
|
|
@@ -5418,6 +5622,8 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
5418
5622
|
/** Val's content service owns the store. See {@link ValOps.patchesAreLocal}. */
|
|
5419
5623
|
patchesAreLocal = false;
|
|
5420
5624
|
kind = "http";
|
|
5625
|
+
/** The content service's. See `sketchpads/httpSketchpadStore.ts`. */
|
|
5626
|
+
sketchpads;
|
|
5421
5627
|
/** See {@link ValOps.requiresAuth}. */
|
|
5422
5628
|
requiresAuth = true;
|
|
5423
5629
|
/**
|
|
@@ -5545,6 +5751,10 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
5545
5751
|
Authorization: `Bearer ${auth.apiKey}`
|
|
5546
5752
|
};
|
|
5547
5753
|
this.root = (options === null || options === void 0 ? void 0 : options.root) ?? "";
|
|
5754
|
+
this.sketchpads = createHttpSketchpadStore({
|
|
5755
|
+
url: `${contentUrl}/v1/${project}/sketchpads`,
|
|
5756
|
+
headers: this.authHeaders
|
|
5757
|
+
});
|
|
5548
5758
|
this.proposal = (options === null || options === void 0 ? void 0 : options.proposal) ?? null;
|
|
5549
5759
|
this.contentVersion = this.proposal === null ? (options === null || options === void 0 ? void 0 : options.contentVersion) ?? null : null;
|
|
5550
5760
|
/*
|
|
@@ -12,7 +12,7 @@ var path = require('path');
|
|
|
12
12
|
var fs = require('fs');
|
|
13
13
|
var vm = require('node:vm');
|
|
14
14
|
var node_module = require('node:module');
|
|
15
|
-
var ValRouterCore = require('./ValRouterCore-
|
|
15
|
+
var ValRouterCore = require('./ValRouterCore-4ea2110e.cjs.prod.js');
|
|
16
16
|
var server = require('@valbuild/ui/server');
|
|
17
17
|
var z = require('zod');
|
|
18
18
|
var zodValidationError = require('zod-validation-error');
|
|
@@ -2469,6 +2469,88 @@ async function withPatchLock(lockFilePath, options, fn) {
|
|
|
2469
2469
|
}
|
|
2470
2470
|
}
|
|
2471
2471
|
|
|
2472
|
+
/**
|
|
2473
|
+
* Sketchpads in `fs` mode: one JSON file each, in `.val/sketchpads/` beside
|
|
2474
|
+
* the patch store (and nothing to do with it -- a sketchpad is not an edit
|
|
2475
|
+
* and is never published).
|
|
2476
|
+
*
|
|
2477
|
+
* A file is replaced by writing a temporary one and renaming it over, so a
|
|
2478
|
+
* reader never sees half of one. Changes to one sketchpad are queued in this
|
|
2479
|
+
* process, so its version check and its write are one step. Two dev servers
|
|
2480
|
+
* writing the same sketchpad at the same instant could still race; that is
|
|
2481
|
+
* a cost local development can carry, and the content service, which hosts
|
|
2482
|
+
* every real project's, does the check in one database statement.
|
|
2483
|
+
*/
|
|
2484
|
+
function createFsSketchpadStore(rootDir, now = () => new Date()) {
|
|
2485
|
+
const dir = path__default["default"].join(rootDir, ".val", "sketchpads");
|
|
2486
|
+
const fileOf = id => path__default["default"].join(dir, `${id}.json`);
|
|
2487
|
+
const queues = new Map();
|
|
2488
|
+
const read = async id => {
|
|
2489
|
+
if (!ValRouterCore.isSketchpadId(id)) {
|
|
2490
|
+
return null;
|
|
2491
|
+
}
|
|
2492
|
+
let raw;
|
|
2493
|
+
try {
|
|
2494
|
+
raw = await fs__default["default"].promises.readFile(fileOf(id), "utf8");
|
|
2495
|
+
} catch {
|
|
2496
|
+
return null;
|
|
2497
|
+
}
|
|
2498
|
+
try {
|
|
2499
|
+
const parsed = internal.Sketchpad.safeParse(JSON.parse(raw));
|
|
2500
|
+
if (parsed.success) {
|
|
2501
|
+
return parsed.data;
|
|
2502
|
+
}
|
|
2503
|
+
} catch {
|
|
2504
|
+
// Reported below, as for a file that parsed and was not a sketchpad.
|
|
2505
|
+
}
|
|
2506
|
+
core.Internal.log.warn(`${fileOf(id)} is not a sketchpad, so it is left out. Move it away to stop this message.`);
|
|
2507
|
+
return null;
|
|
2508
|
+
};
|
|
2509
|
+
const write = async sketchpad => {
|
|
2510
|
+
await fs__default["default"].promises.mkdir(dir, {
|
|
2511
|
+
recursive: true
|
|
2512
|
+
});
|
|
2513
|
+
const temporary = `${fileOf(sketchpad.id)}.${process.pid}.tmp`;
|
|
2514
|
+
await fs__default["default"].promises.writeFile(temporary, JSON.stringify(sketchpad, null, 2));
|
|
2515
|
+
await fs__default["default"].promises.rename(temporary, fileOf(sketchpad.id));
|
|
2516
|
+
};
|
|
2517
|
+
|
|
2518
|
+
/** Runs `task` after every earlier change to `id` has finished. */
|
|
2519
|
+
const queued = (id, task) => {
|
|
2520
|
+
const previous = queues.get(id) ?? Promise.resolve();
|
|
2521
|
+
const next = previous.then(task, task);
|
|
2522
|
+
queues.set(id, next.catch(() => undefined));
|
|
2523
|
+
return next;
|
|
2524
|
+
};
|
|
2525
|
+
return {
|
|
2526
|
+
async list(filter) {
|
|
2527
|
+
let names;
|
|
2528
|
+
try {
|
|
2529
|
+
names = await fs__default["default"].promises.readdir(dir);
|
|
2530
|
+
} catch {
|
|
2531
|
+
return [];
|
|
2532
|
+
}
|
|
2533
|
+
const all = await Promise.all(names.filter(name => name.endsWith(".json")).map(name => read(name.slice(0, -".json".length))));
|
|
2534
|
+
return all.filter(sketchpad => sketchpad !== null).map(ValRouterCore.summaryOf).filter(sketchpad => ValRouterCore.matchesFilter(sketchpad, filter)).sort(ValRouterCore.byUpdatedAt);
|
|
2535
|
+
},
|
|
2536
|
+
get: read,
|
|
2537
|
+
async create(input) {
|
|
2538
|
+
const sketchpad = ValRouterCore.newSketchpad(input, now());
|
|
2539
|
+
await write(sketchpad);
|
|
2540
|
+
return sketchpad;
|
|
2541
|
+
},
|
|
2542
|
+
update(id, change) {
|
|
2543
|
+
return queued(id, async () => {
|
|
2544
|
+
const result = ValRouterCore.applySketchpadChange(await read(id), change, now());
|
|
2545
|
+
if (result.status === "updated") {
|
|
2546
|
+
await write(result.sketchpad);
|
|
2547
|
+
}
|
|
2548
|
+
return result;
|
|
2549
|
+
});
|
|
2550
|
+
}
|
|
2551
|
+
};
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2472
2554
|
/** Serializes a schema, or gives up quietly — serialization errors are reported elsewhere. */
|
|
2473
2555
|
function serializeSchemaSafely(schema) {
|
|
2474
2556
|
try {
|
|
@@ -2494,8 +2576,12 @@ class ValOpsFS extends ValRouterCore.ValOps {
|
|
|
2494
2576
|
this.rootDir = rootDir;
|
|
2495
2577
|
this.host = new FSOpsHost();
|
|
2496
2578
|
this.jsonEntryFilesFingerprint = new JsonEntryFilesFingerprint(rootDir);
|
|
2579
|
+
this.sketchpads = createFsSketchpadStore(rootDir);
|
|
2497
2580
|
}
|
|
2498
2581
|
|
|
2582
|
+
/** In `.val/sketchpads`. See `sketchpads/fsSketchpadStore.ts`. */
|
|
2583
|
+
sketchpads;
|
|
2584
|
+
|
|
2499
2585
|
/**
|
|
2500
2586
|
* Change detection for `.jsonValues()` entry files, which no sha can see (their
|
|
2501
2587
|
* content lives behind a thunk that `JSON.stringify` drops).
|
|
@@ -5117,6 +5203,124 @@ function movesAtMerge(inputs, schemas) {
|
|
|
5117
5203
|
};
|
|
5118
5204
|
}
|
|
5119
5205
|
|
|
5206
|
+
/**
|
|
5207
|
+
* Sketchpads in `http` mode: the content service keeps them, per project, at
|
|
5208
|
+
* `/v1/{project}/sketchpads` (valbuild/home). This only carries requests
|
|
5209
|
+
* there and reads the answers; the version check is the service's, done in
|
|
5210
|
+
* one statement.
|
|
5211
|
+
*/
|
|
5212
|
+
function createHttpSketchpadStore(options) {
|
|
5213
|
+
const request = async (path, init) => fetch(`${options.url}${path}`, {
|
|
5214
|
+
method: init.method,
|
|
5215
|
+
headers: {
|
|
5216
|
+
...options.headers,
|
|
5217
|
+
// WHO, as for a proposal or a commit: the key names the project.
|
|
5218
|
+
...(init.by ? {
|
|
5219
|
+
"x-val-profile-id": init.by
|
|
5220
|
+
} : {}),
|
|
5221
|
+
...(init.body !== undefined ? {
|
|
5222
|
+
"Content-Type": "application/json"
|
|
5223
|
+
} : {})
|
|
5224
|
+
},
|
|
5225
|
+
...(init.body !== undefined ? {
|
|
5226
|
+
body: JSON.stringify(init.body)
|
|
5227
|
+
} : {})
|
|
5228
|
+
});
|
|
5229
|
+
const failed = async (res, doing) => new Error(`Val Build could not ${doing} (HTTP ${res.status}): ${await res.text().catch(() => "")}`);
|
|
5230
|
+
return {
|
|
5231
|
+
async list(filter) {
|
|
5232
|
+
const query = new URLSearchParams({
|
|
5233
|
+
archived: filter.archived
|
|
5234
|
+
});
|
|
5235
|
+
if (filter.page !== undefined) {
|
|
5236
|
+
query.set("page", filter.page);
|
|
5237
|
+
}
|
|
5238
|
+
const res = await request(`?${query}`, {
|
|
5239
|
+
method: "GET"
|
|
5240
|
+
});
|
|
5241
|
+
if (!res.ok) {
|
|
5242
|
+
throw await failed(res, "list the sketchpads");
|
|
5243
|
+
}
|
|
5244
|
+
return z.z.object({
|
|
5245
|
+
sketchpads: z.z.array(internal.SketchpadSummary)
|
|
5246
|
+
}).parse(await res.json()).sketchpads;
|
|
5247
|
+
},
|
|
5248
|
+
async get(id) {
|
|
5249
|
+
if (!ValRouterCore.isSketchpadId(id)) {
|
|
5250
|
+
return null;
|
|
5251
|
+
}
|
|
5252
|
+
const res = await request(`/${encodeURIComponent(id)}`, {
|
|
5253
|
+
method: "GET"
|
|
5254
|
+
});
|
|
5255
|
+
if (res.status === 404) {
|
|
5256
|
+
return null;
|
|
5257
|
+
}
|
|
5258
|
+
if (!res.ok) {
|
|
5259
|
+
throw await failed(res, "read the sketchpad");
|
|
5260
|
+
}
|
|
5261
|
+
return z.z.object({
|
|
5262
|
+
sketchpad: internal.Sketchpad
|
|
5263
|
+
}).parse(await res.json()).sketchpad;
|
|
5264
|
+
},
|
|
5265
|
+
async create(input) {
|
|
5266
|
+
const res = await request("", {
|
|
5267
|
+
method: "POST",
|
|
5268
|
+
body: {
|
|
5269
|
+
text: input.text,
|
|
5270
|
+
title: input.title,
|
|
5271
|
+
page: input.page
|
|
5272
|
+
},
|
|
5273
|
+
by: input.by
|
|
5274
|
+
});
|
|
5275
|
+
if (!res.ok) {
|
|
5276
|
+
throw await failed(res, "make the sketchpad");
|
|
5277
|
+
}
|
|
5278
|
+
return z.z.object({
|
|
5279
|
+
sketchpad: internal.Sketchpad
|
|
5280
|
+
}).parse(await res.json()).sketchpad;
|
|
5281
|
+
},
|
|
5282
|
+
async update(id, change) {
|
|
5283
|
+
if (!ValRouterCore.isSketchpadId(id)) {
|
|
5284
|
+
return {
|
|
5285
|
+
status: "not-found"
|
|
5286
|
+
};
|
|
5287
|
+
}
|
|
5288
|
+
const {
|
|
5289
|
+
by,
|
|
5290
|
+
...body
|
|
5291
|
+
} = change;
|
|
5292
|
+
const res = await request(`/${encodeURIComponent(id)}`, {
|
|
5293
|
+
method: "PATCH",
|
|
5294
|
+
body,
|
|
5295
|
+
by
|
|
5296
|
+
});
|
|
5297
|
+
if (res.status === 404) {
|
|
5298
|
+
return {
|
|
5299
|
+
status: "not-found"
|
|
5300
|
+
};
|
|
5301
|
+
}
|
|
5302
|
+
if (res.status === 409) {
|
|
5303
|
+
const current = z.z.object({
|
|
5304
|
+
sketchpad: internal.Sketchpad
|
|
5305
|
+
}).parse(await res.json()).sketchpad;
|
|
5306
|
+
return {
|
|
5307
|
+
status: "conflict",
|
|
5308
|
+
sketchpad: current
|
|
5309
|
+
};
|
|
5310
|
+
}
|
|
5311
|
+
if (!res.ok) {
|
|
5312
|
+
throw await failed(res, "save the sketchpad");
|
|
5313
|
+
}
|
|
5314
|
+
return {
|
|
5315
|
+
status: "updated",
|
|
5316
|
+
sketchpad: z.z.object({
|
|
5317
|
+
sketchpad: internal.Sketchpad
|
|
5318
|
+
}).parse(await res.json()).sketchpad
|
|
5319
|
+
};
|
|
5320
|
+
}
|
|
5321
|
+
};
|
|
5322
|
+
}
|
|
5323
|
+
|
|
5120
5324
|
const textEncoder$2 = new TextEncoder();
|
|
5121
5325
|
|
|
5122
5326
|
/** The body of the content API's 403 for a write the project's plan refuses. */
|
|
@@ -5418,6 +5622,8 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
5418
5622
|
/** Val's content service owns the store. See {@link ValOps.patchesAreLocal}. */
|
|
5419
5623
|
patchesAreLocal = false;
|
|
5420
5624
|
kind = "http";
|
|
5625
|
+
/** The content service's. See `sketchpads/httpSketchpadStore.ts`. */
|
|
5626
|
+
sketchpads;
|
|
5421
5627
|
/** See {@link ValOps.requiresAuth}. */
|
|
5422
5628
|
requiresAuth = true;
|
|
5423
5629
|
/**
|
|
@@ -5545,6 +5751,10 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
5545
5751
|
Authorization: `Bearer ${auth.apiKey}`
|
|
5546
5752
|
};
|
|
5547
5753
|
this.root = (options === null || options === void 0 ? void 0 : options.root) ?? "";
|
|
5754
|
+
this.sketchpads = createHttpSketchpadStore({
|
|
5755
|
+
url: `${contentUrl}/v1/${project}/sketchpads`,
|
|
5756
|
+
headers: this.authHeaders
|
|
5757
|
+
});
|
|
5548
5758
|
this.proposal = (options === null || options === void 0 ? void 0 : options.proposal) ?? null;
|
|
5549
5759
|
this.contentVersion = this.proposal === null ? (options === null || options === void 0 ? void 0 : options.contentVersion) ?? null : null;
|
|
5550
5760
|
/*
|