@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Internal, VAL_EXTENSION, extractValModules, computeValModuleShas, ImageSchema, DEFAULT_CONTENT_HOST, hasRemoteFileSchema } from '@valbuild/core';
|
|
2
|
-
import { isSchemaSourceFixError, resolveSchemaSourceFixForError, SerializedSchema, AnalyticsBeacon, VAL_ENABLE_COOKIE_NAME, VAL_STATE_COOKIE, VAL_SESSION_COOKIE, newestCommitSha, parseJob, VAL_STUDIO_HEADER, AIToolCallSummaries, getErrorMessageFromUnknownJson, QUICK_PREVIEW_SERVICE_WORKER_PATH, QUICK_PREVIEW_SERVICE_WORKER_SOURCE, Api } from '@valbuild/shared/internal';
|
|
2
|
+
import { isSchemaSourceFixError, resolveSchemaSourceFixForError, SerializedSchema, sketchTitle, parseSketch, SKETCHPAD_MAX_TEXT_LENGTH, checkSketch, AnalyticsBeacon, VAL_ENABLE_COOKIE_NAME, VAL_STATE_COOKIE, VAL_SESSION_COOKIE, newestCommitSha, parseJob, VAL_STUDIO_HEADER, AIToolCallSummaries, getErrorMessageFromUnknownJson, QUICK_PREVIEW_SERVICE_WORKER_PATH, QUICK_PREVIEW_SERVICE_WORKER_SOURCE, Api } from '@valbuild/shared/internal';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { fromError } from 'zod-validation-error';
|
|
5
5
|
import { result, array } from '@valbuild/core/fp';
|
|
@@ -4558,6 +4558,11 @@ class ValOps {
|
|
|
4558
4558
|
* narrow on it with type-only imports.
|
|
4559
4559
|
*/
|
|
4560
4560
|
|
|
4561
|
+
/**
|
|
4562
|
+
* The project's sketchpads, kept wherever this mode keeps things: see
|
|
4563
|
+
* `sketchpads/SketchpadStore.ts`. Not patches, and never published.
|
|
4564
|
+
*/
|
|
4565
|
+
|
|
4561
4566
|
/**
|
|
4562
4567
|
* Save a patch's binary file from a `data:...;base64,...` URL.
|
|
4563
4568
|
*
|
|
@@ -5498,7 +5503,7 @@ var packageJson = {
|
|
|
5498
5503
|
],
|
|
5499
5504
|
exports: true
|
|
5500
5505
|
},
|
|
5501
|
-
version: "0.150.
|
|
5506
|
+
version: "0.150.16",
|
|
5502
5507
|
scripts: {
|
|
5503
5508
|
typecheck: "tsc --noEmit",
|
|
5504
5509
|
test: "jest",
|
|
@@ -5541,6 +5546,239 @@ var packageJson = {
|
|
|
5541
5546
|
*/
|
|
5542
5547
|
const VERSION = packageJson.version;
|
|
5543
5548
|
|
|
5549
|
+
/**
|
|
5550
|
+
* `/sketchpads` and `/sketchpad`. Here rather than inline in `ValServer` so
|
|
5551
|
+
* the rules every mode shares are in one place: a text is a sketch in the
|
|
5552
|
+
* one spelling or it is refused, line by line; an archived sketchpad is
|
|
5553
|
+
* reopened before it is changed; a change names the version it was made on.
|
|
5554
|
+
*/
|
|
5555
|
+
function createSketchpadRoutes(options) {
|
|
5556
|
+
const {
|
|
5557
|
+
store,
|
|
5558
|
+
getAuth,
|
|
5559
|
+
profileOf
|
|
5560
|
+
} = options;
|
|
5561
|
+
return {
|
|
5562
|
+
"/sketchpads": {
|
|
5563
|
+
GET: async req => {
|
|
5564
|
+
const auth = getAuth(req.cookies);
|
|
5565
|
+
if (auth.error) {
|
|
5566
|
+
return {
|
|
5567
|
+
status: 401,
|
|
5568
|
+
json: {
|
|
5569
|
+
message: auth.error
|
|
5570
|
+
}
|
|
5571
|
+
};
|
|
5572
|
+
}
|
|
5573
|
+
const archived = req.query.archived ?? "exclude";
|
|
5574
|
+
if (!isArchivedFilter(archived)) {
|
|
5575
|
+
return {
|
|
5576
|
+
status: 400,
|
|
5577
|
+
json: {
|
|
5578
|
+
message: `"archived" is exclude, include or only, not "${archived}".`
|
|
5579
|
+
}
|
|
5580
|
+
};
|
|
5581
|
+
}
|
|
5582
|
+
try {
|
|
5583
|
+
const sketchpads = await store().list({
|
|
5584
|
+
archived,
|
|
5585
|
+
...(req.query.page !== undefined ? {
|
|
5586
|
+
page: req.query.page
|
|
5587
|
+
} : {})
|
|
5588
|
+
});
|
|
5589
|
+
return {
|
|
5590
|
+
status: 200,
|
|
5591
|
+
json: {
|
|
5592
|
+
sketchpads
|
|
5593
|
+
}
|
|
5594
|
+
};
|
|
5595
|
+
} catch (error) {
|
|
5596
|
+
return failed(error);
|
|
5597
|
+
}
|
|
5598
|
+
},
|
|
5599
|
+
POST: async req => {
|
|
5600
|
+
const auth = getAuth(req.cookies);
|
|
5601
|
+
if (auth.error) {
|
|
5602
|
+
return {
|
|
5603
|
+
status: 401,
|
|
5604
|
+
json: {
|
|
5605
|
+
message: auth.error
|
|
5606
|
+
}
|
|
5607
|
+
};
|
|
5608
|
+
}
|
|
5609
|
+
const refused = refuseText(req.body.text);
|
|
5610
|
+
if (refused) {
|
|
5611
|
+
return refused;
|
|
5612
|
+
}
|
|
5613
|
+
try {
|
|
5614
|
+
const sketchpad = await store().create({
|
|
5615
|
+
text: req.body.text,
|
|
5616
|
+
title: titleOf(req.body.text),
|
|
5617
|
+
page: req.body.page,
|
|
5618
|
+
by: profileOf(auth)
|
|
5619
|
+
});
|
|
5620
|
+
return {
|
|
5621
|
+
status: 201,
|
|
5622
|
+
json: {
|
|
5623
|
+
sketchpad
|
|
5624
|
+
}
|
|
5625
|
+
};
|
|
5626
|
+
} catch (error) {
|
|
5627
|
+
return failed(error);
|
|
5628
|
+
}
|
|
5629
|
+
}
|
|
5630
|
+
},
|
|
5631
|
+
"/sketchpad": {
|
|
5632
|
+
GET: async req => {
|
|
5633
|
+
const auth = getAuth(req.cookies);
|
|
5634
|
+
if (auth.error) {
|
|
5635
|
+
return {
|
|
5636
|
+
status: 401,
|
|
5637
|
+
json: {
|
|
5638
|
+
message: auth.error
|
|
5639
|
+
}
|
|
5640
|
+
};
|
|
5641
|
+
}
|
|
5642
|
+
try {
|
|
5643
|
+
const sketchpad = await store().get(req.query.id);
|
|
5644
|
+
if (sketchpad === null) {
|
|
5645
|
+
return notFound(req.query.id);
|
|
5646
|
+
}
|
|
5647
|
+
return {
|
|
5648
|
+
status: 200,
|
|
5649
|
+
json: {
|
|
5650
|
+
sketchpad
|
|
5651
|
+
}
|
|
5652
|
+
};
|
|
5653
|
+
} catch (error) {
|
|
5654
|
+
return failed(error);
|
|
5655
|
+
}
|
|
5656
|
+
},
|
|
5657
|
+
PATCH: async req => {
|
|
5658
|
+
const auth = getAuth(req.cookies);
|
|
5659
|
+
if (auth.error) {
|
|
5660
|
+
return {
|
|
5661
|
+
status: 401,
|
|
5662
|
+
json: {
|
|
5663
|
+
message: auth.error
|
|
5664
|
+
}
|
|
5665
|
+
};
|
|
5666
|
+
}
|
|
5667
|
+
const {
|
|
5668
|
+
id,
|
|
5669
|
+
baseVersion,
|
|
5670
|
+
text,
|
|
5671
|
+
page,
|
|
5672
|
+
archived
|
|
5673
|
+
} = req.body;
|
|
5674
|
+
if (text !== undefined) {
|
|
5675
|
+
const refused = refuseText(text);
|
|
5676
|
+
if (refused) {
|
|
5677
|
+
return refused;
|
|
5678
|
+
}
|
|
5679
|
+
}
|
|
5680
|
+
try {
|
|
5681
|
+
const current = await store().get(id);
|
|
5682
|
+
if (current === null) {
|
|
5683
|
+
return notFound(id);
|
|
5684
|
+
}
|
|
5685
|
+
// Reopening is the one change an archived sketchpad takes, and it
|
|
5686
|
+
// can come with others: "reopen and put this in it".
|
|
5687
|
+
if (current.archived && archived !== false && (text !== undefined || page !== undefined)) {
|
|
5688
|
+
return {
|
|
5689
|
+
status: 400,
|
|
5690
|
+
json: {
|
|
5691
|
+
message: "This sketchpad is archived, so it is not changed. Reopen it first (archived: false), or ask the person to."
|
|
5692
|
+
}
|
|
5693
|
+
};
|
|
5694
|
+
}
|
|
5695
|
+
const result = await store().update(id, {
|
|
5696
|
+
baseVersion,
|
|
5697
|
+
...(text !== undefined ? {
|
|
5698
|
+
text,
|
|
5699
|
+
title: titleOf(text)
|
|
5700
|
+
} : {}),
|
|
5701
|
+
...(page !== undefined ? {
|
|
5702
|
+
page
|
|
5703
|
+
} : {}),
|
|
5704
|
+
...(archived !== undefined ? {
|
|
5705
|
+
archived
|
|
5706
|
+
} : {}),
|
|
5707
|
+
by: profileOf(auth)
|
|
5708
|
+
});
|
|
5709
|
+
if (result.status === "not-found") {
|
|
5710
|
+
return notFound(id);
|
|
5711
|
+
}
|
|
5712
|
+
if (result.status === "conflict") {
|
|
5713
|
+
return {
|
|
5714
|
+
status: 409,
|
|
5715
|
+
json: {
|
|
5716
|
+
message: `The sketchpad changed since version ${baseVersion}: it is at version ${result.sketchpad.version} now. Here it is; make the change again on top of it.`,
|
|
5717
|
+
sketchpad: result.sketchpad
|
|
5718
|
+
}
|
|
5719
|
+
};
|
|
5720
|
+
}
|
|
5721
|
+
return {
|
|
5722
|
+
status: 200,
|
|
5723
|
+
json: {
|
|
5724
|
+
sketchpad: result.sketchpad
|
|
5725
|
+
}
|
|
5726
|
+
};
|
|
5727
|
+
} catch (error) {
|
|
5728
|
+
return failed(error);
|
|
5729
|
+
}
|
|
5730
|
+
}
|
|
5731
|
+
}
|
|
5732
|
+
};
|
|
5733
|
+
}
|
|
5734
|
+
function isArchivedFilter(value) {
|
|
5735
|
+
return value === "exclude" || value === "include" || value === "only";
|
|
5736
|
+
}
|
|
5737
|
+
function titleOf(text) {
|
|
5738
|
+
return sketchTitle(parseSketch(text).blocks);
|
|
5739
|
+
}
|
|
5740
|
+
/** A 400 for a text the server will not keep, saying which lines and why. */
|
|
5741
|
+
function refuseText(text) {
|
|
5742
|
+
// Bytes, not characters, as the content service counts them: a page in
|
|
5743
|
+
// Norwegian is longer in UTF-8 than it looks.
|
|
5744
|
+
const bytes = new TextEncoder().encode(text).length;
|
|
5745
|
+
if (bytes > SKETCHPAD_MAX_TEXT_LENGTH) {
|
|
5746
|
+
return {
|
|
5747
|
+
status: 400,
|
|
5748
|
+
json: {
|
|
5749
|
+
message: `A sketchpad holds at most ${SKETCHPAD_MAX_TEXT_LENGTH / 1024} KiB of text; this is ${Math.ceil(bytes / 1024)} KiB.`
|
|
5750
|
+
}
|
|
5751
|
+
};
|
|
5752
|
+
}
|
|
5753
|
+
const errors = checkSketch(text);
|
|
5754
|
+
if (errors.length === 0) {
|
|
5755
|
+
return null;
|
|
5756
|
+
}
|
|
5757
|
+
return {
|
|
5758
|
+
status: 400,
|
|
5759
|
+
json: {
|
|
5760
|
+
message: `That is not a sketch the Sketchpad can show: ${errors.map(error => `line ${error.line}: ${error.message}`).join(" ")}`,
|
|
5761
|
+
errors
|
|
5762
|
+
}
|
|
5763
|
+
};
|
|
5764
|
+
}
|
|
5765
|
+
function notFound(id) {
|
|
5766
|
+
return {
|
|
5767
|
+
status: 404,
|
|
5768
|
+
json: {
|
|
5769
|
+
message: `There is no sketchpad "${id}" in this project.`
|
|
5770
|
+
}
|
|
5771
|
+
};
|
|
5772
|
+
}
|
|
5773
|
+
function failed(error) {
|
|
5774
|
+
return {
|
|
5775
|
+
status: 500,
|
|
5776
|
+
json: {
|
|
5777
|
+
message: error instanceof Error ? error.message : "The sketchpads could not be reached."
|
|
5778
|
+
}
|
|
5779
|
+
};
|
|
5780
|
+
}
|
|
5781
|
+
|
|
5544
5782
|
/** What {@link ValServerOptions.publishOverride} is given. */
|
|
5545
5783
|
|
|
5546
5784
|
/** What a publish reports back, in either shape. */
|
|
@@ -6043,6 +6281,11 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
6043
6281
|
};
|
|
6044
6282
|
};
|
|
6045
6283
|
return {
|
|
6284
|
+
...createSketchpadRoutes({
|
|
6285
|
+
store: () => serverOps.sketchpads,
|
|
6286
|
+
getAuth,
|
|
6287
|
+
profileOf
|
|
6288
|
+
}),
|
|
6046
6289
|
"/draft/enable": {
|
|
6047
6290
|
GET: async req => {
|
|
6048
6291
|
const cookies = req.cookies;
|
|
@@ -9236,7 +9479,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
9236
9479
|
// TypeScript compiler. See `patch/ts/publishKit.ts`.
|
|
9237
9480
|
const {
|
|
9238
9481
|
getJsonEntryAtCommit
|
|
9239
|
-
} = await import('./getJsonEntryAtCommit-
|
|
9482
|
+
} = await import('./getJsonEntryAtCommit-5d340344.esm.js');
|
|
9240
9483
|
const res = await getJsonEntryAtCommit(serverOps, req.query.commit_sha, req.query.path, req.query.key);
|
|
9241
9484
|
if (result.isErr(res)) {
|
|
9242
9485
|
return historyErrorResponse(res.error);
|
|
@@ -9966,6 +10209,138 @@ async function uploadRemoteFile(contentHost, project, bucket, fileHash, fileExt,
|
|
|
9966
10209
|
};
|
|
9967
10210
|
}
|
|
9968
10211
|
|
|
10212
|
+
/**
|
|
10213
|
+
* Where a project's sketchpads are kept, in each of the server's modes:
|
|
10214
|
+
* `.val/sketchpads` in `fs` mode, the content service in `http` mode, the
|
|
10215
|
+
* tab's memory in the demo. See `Sketchpad` in `ApiRoutes.ts` for what one
|
|
10216
|
+
* is.
|
|
10217
|
+
*
|
|
10218
|
+
* The store keeps what it is given. Whether a text is a sketch at all is
|
|
10219
|
+
* decided before it gets here (`checkSketch`, in `ValServer`), once for every
|
|
10220
|
+
* mode, so no store has its own idea of the format.
|
|
10221
|
+
*/
|
|
10222
|
+
|
|
10223
|
+
/**
|
|
10224
|
+
* Whether `id` is in the shape a sketchpad's id has. Every store checks it
|
|
10225
|
+
* before the id goes anywhere it could mean something else: a file name in
|
|
10226
|
+
* fs mode, a URL path in http mode, where `..` is not an id but a way out.
|
|
10227
|
+
*/
|
|
10228
|
+
function isSketchpadId(id) {
|
|
10229
|
+
return /^[0-9a-f-]{36}$/.test(id);
|
|
10230
|
+
}
|
|
10231
|
+
|
|
10232
|
+
/**
|
|
10233
|
+
* A random id in the shape of a UUID. `getRandomValues` rather than
|
|
10234
|
+
* `randomUUID`, which a browser only has in a secure context -- and the demo
|
|
10235
|
+
* runs this server in the visitor's tab.
|
|
10236
|
+
*/
|
|
10237
|
+
function newSketchpadId() {
|
|
10238
|
+
const bytes = new Uint8Array(16);
|
|
10239
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
10240
|
+
bytes[6] = bytes[6] & 0x0f | 0x40;
|
|
10241
|
+
bytes[8] = bytes[8] & 0x3f | 0x80;
|
|
10242
|
+
const hex = Array.from(bytes, b => b.toString(16).padStart(2, "0"));
|
|
10243
|
+
return [hex.slice(0, 4).join(""), hex.slice(4, 6).join(""), hex.slice(6, 8).join(""), hex.slice(8, 10).join(""), hex.slice(10, 16).join("")].join("-");
|
|
10244
|
+
}
|
|
10245
|
+
function summaryOf(sketchpad) {
|
|
10246
|
+
const {
|
|
10247
|
+
text,
|
|
10248
|
+
...summary
|
|
10249
|
+
} = sketchpad;
|
|
10250
|
+
return summary;
|
|
10251
|
+
}
|
|
10252
|
+
function matchesFilter(sketchpad, filter) {
|
|
10253
|
+
if (filter.page !== undefined && sketchpad.page !== filter.page) {
|
|
10254
|
+
return false;
|
|
10255
|
+
}
|
|
10256
|
+
return filter.archived === "include" ? true : filter.archived === "only" ? sketchpad.archived : !sketchpad.archived;
|
|
10257
|
+
}
|
|
10258
|
+
|
|
10259
|
+
/** Newest change first, as every list of them is read. */
|
|
10260
|
+
function byUpdatedAt(a, b) {
|
|
10261
|
+
return b.updatedAt.localeCompare(a.updatedAt);
|
|
10262
|
+
}
|
|
10263
|
+
function newSketchpad(input, now) {
|
|
10264
|
+
const at = now.toISOString();
|
|
10265
|
+
return {
|
|
10266
|
+
id: newSketchpadId(),
|
|
10267
|
+
page: input.page,
|
|
10268
|
+
title: input.title,
|
|
10269
|
+
text: input.text,
|
|
10270
|
+
version: 1,
|
|
10271
|
+
archived: false,
|
|
10272
|
+
createdAt: at,
|
|
10273
|
+
updatedAt: at,
|
|
10274
|
+
createdBy: input.by,
|
|
10275
|
+
updatedBy: input.by
|
|
10276
|
+
};
|
|
10277
|
+
}
|
|
10278
|
+
|
|
10279
|
+
/** `current` with `change` applied, or why not. Pure: storing is the caller's. */
|
|
10280
|
+
function applySketchpadChange(current, change, now) {
|
|
10281
|
+
if (current === null) {
|
|
10282
|
+
return {
|
|
10283
|
+
status: "not-found"
|
|
10284
|
+
};
|
|
10285
|
+
}
|
|
10286
|
+
if (current.version !== change.baseVersion) {
|
|
10287
|
+
return {
|
|
10288
|
+
status: "conflict",
|
|
10289
|
+
sketchpad: current
|
|
10290
|
+
};
|
|
10291
|
+
}
|
|
10292
|
+
return {
|
|
10293
|
+
status: "updated",
|
|
10294
|
+
sketchpad: {
|
|
10295
|
+
...current,
|
|
10296
|
+
...(change.text !== undefined ? {
|
|
10297
|
+
text: change.text
|
|
10298
|
+
} : {}),
|
|
10299
|
+
...(change.title !== undefined ? {
|
|
10300
|
+
title: change.title
|
|
10301
|
+
} : {}),
|
|
10302
|
+
...(change.page !== undefined ? {
|
|
10303
|
+
page: change.page
|
|
10304
|
+
} : {}),
|
|
10305
|
+
...(change.archived !== undefined ? {
|
|
10306
|
+
archived: change.archived
|
|
10307
|
+
} : {}),
|
|
10308
|
+
version: current.version + 1,
|
|
10309
|
+
updatedAt: now.toISOString(),
|
|
10310
|
+
updatedBy: change.by
|
|
10311
|
+
}
|
|
10312
|
+
};
|
|
10313
|
+
}
|
|
10314
|
+
|
|
10315
|
+
/**
|
|
10316
|
+
* Sketchpads kept in memory, for as long as the server runs: the demo's
|
|
10317
|
+
* store, where a reload starts over anyway, and the tests'.
|
|
10318
|
+
*/
|
|
10319
|
+
function createMemorySketchpadStore(now = () => new Date()) {
|
|
10320
|
+
const sketchpads = new Map();
|
|
10321
|
+
return {
|
|
10322
|
+
async list(filter) {
|
|
10323
|
+
return Array.from(sketchpads.values()).map(summaryOf).filter(sketchpad => matchesFilter(sketchpad, filter)).sort(byUpdatedAt);
|
|
10324
|
+
},
|
|
10325
|
+
async get(id) {
|
|
10326
|
+
return sketchpads.get(id) ?? null;
|
|
10327
|
+
},
|
|
10328
|
+
async create(input) {
|
|
10329
|
+
const sketchpad = newSketchpad(input, now());
|
|
10330
|
+
sketchpads.set(sketchpad.id, sketchpad);
|
|
10331
|
+
return sketchpad;
|
|
10332
|
+
},
|
|
10333
|
+
async update(id, change) {
|
|
10334
|
+
// Synchronous from the read to the write, so nothing interleaves.
|
|
10335
|
+
const result = applySketchpadChange(sketchpads.get(id) ?? null, change, now());
|
|
10336
|
+
if (result.status === "updated") {
|
|
10337
|
+
sketchpads.set(id, result.sketchpad);
|
|
10338
|
+
}
|
|
10339
|
+
return result;
|
|
10340
|
+
}
|
|
10341
|
+
};
|
|
10342
|
+
}
|
|
10343
|
+
|
|
9969
10344
|
/**
|
|
9970
10345
|
* One stored patch. Everything the ordered chain needs and nothing else.
|
|
9971
10346
|
*/
|
|
@@ -10098,6 +10473,8 @@ class ValOpsMemory extends ValOps {
|
|
|
10098
10473
|
*/
|
|
10099
10474
|
patchesAreLocal = true;
|
|
10100
10475
|
kind = "memory";
|
|
10476
|
+
/** For as long as the tab is open, like everything else in the demo. */
|
|
10477
|
+
sketchpads = createMemorySketchpadStore();
|
|
10101
10478
|
/**
|
|
10102
10479
|
* Required, unless the host explicitly takes the boundary itself.
|
|
10103
10480
|
*
|
|
@@ -10988,4 +11365,4 @@ function getCookies(req, cookiesDef) {
|
|
|
10988
11365
|
return z.object(cookiesDef).safeParse(input);
|
|
10989
11366
|
}
|
|
10990
11367
|
|
|
10991
|
-
export {
|
|
11368
|
+
export { needsHostCheck as A, rewriteRefHost as B, fallbackRemoteHost as C, checkRemoteFiles as D, ValServer as E, createValRequestHandler as F, getNewJsonEntryPaths as G, formatPatchSourceError as H, askOncePerHost as I, getSettings as J, InMemoryPatchStore as K, bytesToBase64 as L, bytesToUtf8 as M, posixPath as N, ValOps as V, rebaseContentOp as a, byUpdatedAt as b, classifyJsonValuesOp as c, isSketchpadId as d, applySketchpadChange as e, findNestedJsonValuesRecords as f, bufferFromDataUrl as g, getFieldsForType as h, isJsonValuesRootOp as i, getFileExt as j, guessMimeTypeFromPath as k, createMetadataFromBuffer as l, matchesFilter as m, newSketchpad as n, ValOpsMemory as o, isHlsMasterPlaylist as p, sumHlsSegmentDurations as q, resolveExistingJsonPath as r, summaryOf as s, parseHlsMasterVariants as t, uploadRemoteFile as u, validateJsonValuesEntries as v, largestHlsVariant as w, fallbackRefOf as x, mapHlsUris as y, movedRemoteHost as z };
|
|
@@ -9,6 +9,7 @@ import type { ValSyntaxError, ValSyntaxErrorTree } from "./patch/ts/syntax.js";
|
|
|
9
9
|
import { ParentPatchId } from "@valbuild/core";
|
|
10
10
|
import type { ReifiedPreview } from "@valbuild/core";
|
|
11
11
|
import { ValCommit, ValDeployment } from "@valbuild/shared/internal";
|
|
12
|
+
import type { SketchpadStore } from "./sketchpads/SketchpadStore.js";
|
|
12
13
|
export type BaseSha = string & {
|
|
13
14
|
readonly _tag: unique symbol;
|
|
14
15
|
};
|
|
@@ -640,6 +641,11 @@ export declare abstract class ValOps {
|
|
|
640
641
|
* narrow on it with type-only imports.
|
|
641
642
|
*/
|
|
642
643
|
abstract readonly kind: "fs" | "http" | "memory";
|
|
644
|
+
/**
|
|
645
|
+
* The project's sketchpads, kept wherever this mode keeps things: see
|
|
646
|
+
* `sketchpads/SketchpadStore.ts`. Not patches, and never published.
|
|
647
|
+
*/
|
|
648
|
+
abstract readonly sketchpads: SketchpadStore;
|
|
643
649
|
abstract onInit(baseSha: BaseSha, schemaSha: SchemaSha): Promise<void>;
|
|
644
650
|
abstract fetchPatches<ExcludePatchOps extends boolean>(filters: {
|
|
645
651
|
patchIds?: PatchId[];
|
|
@@ -5,6 +5,7 @@ import type { HistoryError } from "./history/HistoryError.js";
|
|
|
5
5
|
import type { AffectedFile, StoredModuleVersion, CommitPage, CommitPatch, HistoricalCommit } from "./history/types.js";
|
|
6
6
|
import { result } from "@valbuild/core/fp";
|
|
7
7
|
import { Buffer } from "buffer";
|
|
8
|
+
import type { SketchpadStore } from "./sketchpads/SketchpadStore.js";
|
|
8
9
|
export declare class ValOpsFS extends ValOps {
|
|
9
10
|
private readonly contentUrl;
|
|
10
11
|
private readonly rootDir;
|
|
@@ -19,6 +20,8 @@ export declare class ValOpsFS extends ValOps {
|
|
|
19
20
|
*/
|
|
20
21
|
readonly requiresAuth = false;
|
|
21
22
|
constructor(contentUrl: string, rootDir: string, valModules: ValModules, options?: ValOpsOptions);
|
|
23
|
+
/** In `.val/sketchpads`. See `sketchpads/fsSketchpadStore.ts`. */
|
|
24
|
+
readonly sketchpads: SketchpadStore;
|
|
22
25
|
/**
|
|
23
26
|
* Change detection for `.jsonValues()` entry files, which no sha can see (their
|
|
24
27
|
* content lives behind a thunk that `JSON.stringify` drops).
|
|
@@ -7,6 +7,7 @@ import type { HistoryError } from "./history/HistoryError.js";
|
|
|
7
7
|
import type { AffectedFile, StoredModuleVersion, CommitPage, CommitPatch, HistoricalCommit } from "./history/types.js";
|
|
8
8
|
import { ParentRef, ValCommit, ValDeployment } from "@valbuild/shared/internal";
|
|
9
9
|
import { result } from "@valbuild/core/fp";
|
|
10
|
+
import type { SketchpadStore } from "./sketchpads/SketchpadStore.js";
|
|
10
11
|
declare const PatchId: z.ZodString & z.ZodType<PatchId, string, z.core.$ZodTypeInternals<PatchId, string>>;
|
|
11
12
|
declare const CommitSha: z.ZodString & z.ZodType<CommitSha, string, z.core.$ZodTypeInternals<CommitSha, string>>;
|
|
12
13
|
declare const BaseSha: z.ZodString & z.ZodType<BaseSha, string, z.core.$ZodTypeInternals<BaseSha, string>>;
|
|
@@ -44,6 +45,8 @@ export declare class ValOpsHttp extends ValOps {
|
|
|
44
45
|
/** Val's content service owns the store. See {@link ValOps.patchesAreLocal}. */
|
|
45
46
|
readonly patchesAreLocal = false;
|
|
46
47
|
readonly kind = "http";
|
|
48
|
+
/** The content service's. See `sketchpads/httpSketchpadStore.ts`. */
|
|
49
|
+
readonly sketchpads: SketchpadStore;
|
|
47
50
|
/** See {@link ValOps.requiresAuth}. */
|
|
48
51
|
readonly requiresAuth = true;
|
|
49
52
|
/**
|
|
@@ -4,6 +4,7 @@ import { ValOps, type AuthorId, type BaseSha, type GenericErrorMessage, type Met
|
|
|
4
4
|
import type { HistoryError } from "./history/HistoryError.js";
|
|
5
5
|
import type { AffectedFile, CommitPage, CommitPatch, HistoricalCommit, StoredModuleVersion } from "./history/types.js";
|
|
6
6
|
import { result } from "@valbuild/core/fp";
|
|
7
|
+
import { type SketchpadStore } from "./sketchpads/SketchpadStore.js";
|
|
7
8
|
/**
|
|
8
9
|
* One stored patch. Everything the ordered chain needs and nothing else.
|
|
9
10
|
*/
|
|
@@ -177,6 +178,8 @@ export declare class ValOpsMemory extends ValOps {
|
|
|
177
178
|
*/
|
|
178
179
|
readonly patchesAreLocal = true;
|
|
179
180
|
readonly kind = "memory";
|
|
181
|
+
/** For as long as the tab is open, like everything else in the demo. */
|
|
182
|
+
readonly sketchpads: SketchpadStore;
|
|
180
183
|
/**
|
|
181
184
|
* Required, unless the host explicitly takes the boundary itself.
|
|
182
185
|
*
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { SketchpadSummaryT, SketchpadT } from "@valbuild/shared/internal";
|
|
2
|
+
/**
|
|
3
|
+
* Where a project's sketchpads are kept, in each of the server's modes:
|
|
4
|
+
* `.val/sketchpads` in `fs` mode, the content service in `http` mode, the
|
|
5
|
+
* tab's memory in the demo. See `Sketchpad` in `ApiRoutes.ts` for what one
|
|
6
|
+
* is.
|
|
7
|
+
*
|
|
8
|
+
* The store keeps what it is given. Whether a text is a sketch at all is
|
|
9
|
+
* decided before it gets here (`checkSketch`, in `ValServer`), once for every
|
|
10
|
+
* mode, so no store has its own idea of the format.
|
|
11
|
+
*/
|
|
12
|
+
export interface SketchpadStore {
|
|
13
|
+
list(filter: SketchpadFilter): Promise<SketchpadSummaryT[]>;
|
|
14
|
+
get(id: string): Promise<SketchpadT | null>;
|
|
15
|
+
create(input: SketchpadInput): Promise<SketchpadT>;
|
|
16
|
+
/**
|
|
17
|
+
* Applies `change` if the sketchpad is still at `change.baseVersion`, in
|
|
18
|
+
* one step: a store that checked and then wrote would let two writers in
|
|
19
|
+
* between.
|
|
20
|
+
*/
|
|
21
|
+
update(id: string, change: SketchpadChange): Promise<SketchpadUpdate>;
|
|
22
|
+
}
|
|
23
|
+
export type SketchpadFilter = {
|
|
24
|
+
archived: "exclude" | "include" | "only";
|
|
25
|
+
page?: string;
|
|
26
|
+
};
|
|
27
|
+
export type SketchpadInput = {
|
|
28
|
+
text: string;
|
|
29
|
+
title: string | null;
|
|
30
|
+
page: string | null;
|
|
31
|
+
/** Profile id of whoever made it, when somebody is signed in. */
|
|
32
|
+
by: string | null;
|
|
33
|
+
};
|
|
34
|
+
export type SketchpadChange = {
|
|
35
|
+
baseVersion: number;
|
|
36
|
+
text?: string;
|
|
37
|
+
title?: string | null;
|
|
38
|
+
page?: string | null;
|
|
39
|
+
archived?: boolean;
|
|
40
|
+
by: string | null;
|
|
41
|
+
};
|
|
42
|
+
export type SketchpadUpdate = {
|
|
43
|
+
status: "updated";
|
|
44
|
+
sketchpad: SketchpadT;
|
|
45
|
+
} | {
|
|
46
|
+
status: "not-found";
|
|
47
|
+
}
|
|
48
|
+
/** Changed since `baseVersion`; `sketchpad` is how it is now. */
|
|
49
|
+
| {
|
|
50
|
+
status: "conflict";
|
|
51
|
+
sketchpad: SketchpadT;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Whether `id` is in the shape a sketchpad's id has. Every store checks it
|
|
55
|
+
* before the id goes anywhere it could mean something else: a file name in
|
|
56
|
+
* fs mode, a URL path in http mode, where `..` is not an id but a way out.
|
|
57
|
+
*/
|
|
58
|
+
export declare function isSketchpadId(id: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* A random id in the shape of a UUID. `getRandomValues` rather than
|
|
61
|
+
* `randomUUID`, which a browser only has in a secure context -- and the demo
|
|
62
|
+
* runs this server in the visitor's tab.
|
|
63
|
+
*/
|
|
64
|
+
export declare function newSketchpadId(): string;
|
|
65
|
+
export declare function summaryOf(sketchpad: SketchpadT): SketchpadSummaryT;
|
|
66
|
+
export declare function matchesFilter(sketchpad: SketchpadSummaryT, filter: SketchpadFilter): boolean;
|
|
67
|
+
/** Newest change first, as every list of them is read. */
|
|
68
|
+
export declare function byUpdatedAt(a: SketchpadSummaryT, b: SketchpadSummaryT): number;
|
|
69
|
+
export declare function newSketchpad(input: SketchpadInput, now: Date): SketchpadT;
|
|
70
|
+
/** `current` with `change` applied, or why not. Pure: storing is the caller's. */
|
|
71
|
+
export declare function applySketchpadChange(current: SketchpadT | null, change: SketchpadChange, now: Date): SketchpadUpdate;
|
|
72
|
+
/**
|
|
73
|
+
* Sketchpads kept in memory, for as long as the server runs: the demo's
|
|
74
|
+
* store, where a reload starts over anyway, and the tests'.
|
|
75
|
+
*/
|
|
76
|
+
export declare function createMemorySketchpadStore(now?: () => Date): SketchpadStore;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import {
|
|
2
|
+
import { M as bytesToUtf8, N as posixPath } from './ValRouterCore-c250061f.esm.js';
|
|
3
3
|
import { result } from '@valbuild/core/fp';
|
|
4
4
|
import { a as analyzeValModule, c as analyzeJsonValuesEntries } from './jsonValuesModule-427d68c8.esm.js';
|
|
5
5
|
import '@valbuild/core';
|
package/dist/{getJsonEntryAtCommit-e1946be3.cjs.dev.js → getJsonEntryAtCommit-971b7bbe.cjs.dev.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ts = require('typescript');
|
|
4
|
-
var ValRouterCore = require('./ValRouterCore-
|
|
4
|
+
var ValRouterCore = require('./ValRouterCore-4b42da9b.cjs.dev.js');
|
|
5
5
|
var fp = require('@valbuild/core/fp');
|
|
6
6
|
var jsonValuesModule = require('./jsonValuesModule-8ae503a8.cjs.dev.js');
|
|
7
7
|
require('@valbuild/core');
|
package/dist/{getJsonEntryAtCommit-fbd7665f.cjs.prod.js → getJsonEntryAtCommit-ece4f965.cjs.prod.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ts = require('typescript');
|
|
4
|
-
var ValRouterCore = require('./ValRouterCore-
|
|
4
|
+
var ValRouterCore = require('./ValRouterCore-4ea2110e.cjs.prod.js');
|
|
5
5
|
var fp = require('@valbuild/core/fp');
|
|
6
6
|
var jsonValuesModule = require('./jsonValuesModule-d1bb8d8f.cjs.prod.js');
|
|
7
7
|
require('@valbuild/core');
|