@valbuild/server 0.150.14 → 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 +17 -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-c4b07665.cjs.dev.js → ValRouterCore-4b42da9b.cjs.dev.js} +385 -2
- package/dist/{ValRouterCore-83973a50.cjs.prod.js → ValRouterCore-4ea2110e.cjs.prod.js} +385 -2
- package/dist/{ValRouterCore-26bf9ed9.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-28be5ffd.esm.js → getJsonEntryAtCommit-5d340344.esm.js} +1 -1
- package/dist/{getJsonEntryAtCommit-7d550e7f.cjs.dev.js → getJsonEntryAtCommit-971b7bbe.cjs.dev.js} +1 -1
- package/dist/{getJsonEntryAtCommit-64632fba.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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @valbuild/server
|
|
2
2
|
|
|
3
|
+
## 0.150.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#969](https://github.com/valbuild/val/pull/969) [`7db39ef`](https://github.com/valbuild/val/commit/7db39ef722b4f743e6974effd5fedfadc76e6544) Thanks [@freekh](https://github.com/freekh)! - **Sketchpad**: work out a page's content and rough layout with the assistant before anyone builds it.
|
|
8
|
+
|
|
9
|
+
A sketchpad is a document of headings, text, boxes and columns, where you edit the text in place. A box can show an image or a video from a link: paste one, or drag an image in from a web page. The assistant sees the same sketch as text in one strict format, so what it reads is what is on screen. It has tools to list, create, read and write sketchpads, and **Send to AI** asks it to read the one you are on.
|
|
10
|
+
|
|
11
|
+
- Sketchpads live on the server, apart from any chat or page. They outlast the chat they started in, and the page a sketchpad is about can be changed. A sketchpad can be archived and reopened.
|
|
12
|
+
- Open one from a page's menu (**Sketch changes**), from the top bar, or when the assistant offers one.
|
|
13
|
+
- On a desktop the page, the sketchpad and the chat sit side by side, the chat docked beside them. On a phone a sketchpad can go full screen, with the page one tap away and the buttons at the bottom.
|
|
14
|
+
- In local development sketchpads are stored in `.val/sketchpads/`. A hosted project needs the content host's sketchpad API; without it the Studio does not offer sketchpads.
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`c0abcde`](https://github.com/valbuild/val/commit/c0abcde887fa61edb2dd542b9cfd707237a74daf), [`3ac24d4`](https://github.com/valbuild/val/commit/3ac24d46691c646dd5d2789cf2e1d6e2734195d3), [`7db39ef`](https://github.com/valbuild/val/commit/7db39ef722b4f743e6974effd5fedfadc76e6544)]:
|
|
17
|
+
- @valbuild/ui@0.150.16
|
|
18
|
+
- @valbuild/shared@0.150.16
|
|
19
|
+
|
|
3
20
|
## 0.150.14
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var core = require('@valbuild/core');
|
|
6
|
-
var ValRouterCore = require('../../dist/ValRouterCore-
|
|
6
|
+
var ValRouterCore = require('../../dist/ValRouterCore-4b42da9b.cjs.dev.js');
|
|
7
7
|
require('@valbuild/shared/internal');
|
|
8
8
|
require('zod');
|
|
9
9
|
require('zod-validation-error');
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var core = require('@valbuild/core');
|
|
6
|
-
var ValRouterCore = require('../../dist/ValRouterCore-
|
|
6
|
+
var ValRouterCore = require('../../dist/ValRouterCore-4ea2110e.cjs.prod.js');
|
|
7
7
|
require('@valbuild/shared/internal');
|
|
8
8
|
require('zod');
|
|
9
9
|
require('zod-validation-error');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_CONTENT_HOST } from '@valbuild/core';
|
|
2
|
-
import {
|
|
2
|
+
import { o as ValOpsMemory, L as bytesToBase64, E as ValServer, F as createValRequestHandler } from '../../dist/ValRouterCore-c250061f.esm.js';
|
|
3
3
|
import '@valbuild/shared/internal';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import 'zod-validation-error';
|
|
@@ -4564,6 +4564,11 @@ class ValOps {
|
|
|
4564
4564
|
* narrow on it with type-only imports.
|
|
4565
4565
|
*/
|
|
4566
4566
|
|
|
4567
|
+
/**
|
|
4568
|
+
* The project's sketchpads, kept wherever this mode keeps things: see
|
|
4569
|
+
* `sketchpads/SketchpadStore.ts`. Not patches, and never published.
|
|
4570
|
+
*/
|
|
4571
|
+
|
|
4567
4572
|
/**
|
|
4568
4573
|
* Save a patch's binary file from a `data:...;base64,...` URL.
|
|
4569
4574
|
*
|
|
@@ -5504,7 +5509,7 @@ var packageJson = {
|
|
|
5504
5509
|
],
|
|
5505
5510
|
exports: true
|
|
5506
5511
|
},
|
|
5507
|
-
version: "0.150.
|
|
5512
|
+
version: "0.150.16",
|
|
5508
5513
|
scripts: {
|
|
5509
5514
|
typecheck: "tsc --noEmit",
|
|
5510
5515
|
test: "jest",
|
|
@@ -5547,6 +5552,239 @@ var packageJson = {
|
|
|
5547
5552
|
*/
|
|
5548
5553
|
const VERSION = packageJson.version;
|
|
5549
5554
|
|
|
5555
|
+
/**
|
|
5556
|
+
* `/sketchpads` and `/sketchpad`. Here rather than inline in `ValServer` so
|
|
5557
|
+
* the rules every mode shares are in one place: a text is a sketch in the
|
|
5558
|
+
* one spelling or it is refused, line by line; an archived sketchpad is
|
|
5559
|
+
* reopened before it is changed; a change names the version it was made on.
|
|
5560
|
+
*/
|
|
5561
|
+
function createSketchpadRoutes(options) {
|
|
5562
|
+
const {
|
|
5563
|
+
store,
|
|
5564
|
+
getAuth,
|
|
5565
|
+
profileOf
|
|
5566
|
+
} = options;
|
|
5567
|
+
return {
|
|
5568
|
+
"/sketchpads": {
|
|
5569
|
+
GET: async req => {
|
|
5570
|
+
const auth = getAuth(req.cookies);
|
|
5571
|
+
if (auth.error) {
|
|
5572
|
+
return {
|
|
5573
|
+
status: 401,
|
|
5574
|
+
json: {
|
|
5575
|
+
message: auth.error
|
|
5576
|
+
}
|
|
5577
|
+
};
|
|
5578
|
+
}
|
|
5579
|
+
const archived = req.query.archived ?? "exclude";
|
|
5580
|
+
if (!isArchivedFilter(archived)) {
|
|
5581
|
+
return {
|
|
5582
|
+
status: 400,
|
|
5583
|
+
json: {
|
|
5584
|
+
message: `"archived" is exclude, include or only, not "${archived}".`
|
|
5585
|
+
}
|
|
5586
|
+
};
|
|
5587
|
+
}
|
|
5588
|
+
try {
|
|
5589
|
+
const sketchpads = await store().list({
|
|
5590
|
+
archived,
|
|
5591
|
+
...(req.query.page !== undefined ? {
|
|
5592
|
+
page: req.query.page
|
|
5593
|
+
} : {})
|
|
5594
|
+
});
|
|
5595
|
+
return {
|
|
5596
|
+
status: 200,
|
|
5597
|
+
json: {
|
|
5598
|
+
sketchpads
|
|
5599
|
+
}
|
|
5600
|
+
};
|
|
5601
|
+
} catch (error) {
|
|
5602
|
+
return failed(error);
|
|
5603
|
+
}
|
|
5604
|
+
},
|
|
5605
|
+
POST: async req => {
|
|
5606
|
+
const auth = getAuth(req.cookies);
|
|
5607
|
+
if (auth.error) {
|
|
5608
|
+
return {
|
|
5609
|
+
status: 401,
|
|
5610
|
+
json: {
|
|
5611
|
+
message: auth.error
|
|
5612
|
+
}
|
|
5613
|
+
};
|
|
5614
|
+
}
|
|
5615
|
+
const refused = refuseText(req.body.text);
|
|
5616
|
+
if (refused) {
|
|
5617
|
+
return refused;
|
|
5618
|
+
}
|
|
5619
|
+
try {
|
|
5620
|
+
const sketchpad = await store().create({
|
|
5621
|
+
text: req.body.text,
|
|
5622
|
+
title: titleOf(req.body.text),
|
|
5623
|
+
page: req.body.page,
|
|
5624
|
+
by: profileOf(auth)
|
|
5625
|
+
});
|
|
5626
|
+
return {
|
|
5627
|
+
status: 201,
|
|
5628
|
+
json: {
|
|
5629
|
+
sketchpad
|
|
5630
|
+
}
|
|
5631
|
+
};
|
|
5632
|
+
} catch (error) {
|
|
5633
|
+
return failed(error);
|
|
5634
|
+
}
|
|
5635
|
+
}
|
|
5636
|
+
},
|
|
5637
|
+
"/sketchpad": {
|
|
5638
|
+
GET: async req => {
|
|
5639
|
+
const auth = getAuth(req.cookies);
|
|
5640
|
+
if (auth.error) {
|
|
5641
|
+
return {
|
|
5642
|
+
status: 401,
|
|
5643
|
+
json: {
|
|
5644
|
+
message: auth.error
|
|
5645
|
+
}
|
|
5646
|
+
};
|
|
5647
|
+
}
|
|
5648
|
+
try {
|
|
5649
|
+
const sketchpad = await store().get(req.query.id);
|
|
5650
|
+
if (sketchpad === null) {
|
|
5651
|
+
return notFound(req.query.id);
|
|
5652
|
+
}
|
|
5653
|
+
return {
|
|
5654
|
+
status: 200,
|
|
5655
|
+
json: {
|
|
5656
|
+
sketchpad
|
|
5657
|
+
}
|
|
5658
|
+
};
|
|
5659
|
+
} catch (error) {
|
|
5660
|
+
return failed(error);
|
|
5661
|
+
}
|
|
5662
|
+
},
|
|
5663
|
+
PATCH: async req => {
|
|
5664
|
+
const auth = getAuth(req.cookies);
|
|
5665
|
+
if (auth.error) {
|
|
5666
|
+
return {
|
|
5667
|
+
status: 401,
|
|
5668
|
+
json: {
|
|
5669
|
+
message: auth.error
|
|
5670
|
+
}
|
|
5671
|
+
};
|
|
5672
|
+
}
|
|
5673
|
+
const {
|
|
5674
|
+
id,
|
|
5675
|
+
baseVersion,
|
|
5676
|
+
text,
|
|
5677
|
+
page,
|
|
5678
|
+
archived
|
|
5679
|
+
} = req.body;
|
|
5680
|
+
if (text !== undefined) {
|
|
5681
|
+
const refused = refuseText(text);
|
|
5682
|
+
if (refused) {
|
|
5683
|
+
return refused;
|
|
5684
|
+
}
|
|
5685
|
+
}
|
|
5686
|
+
try {
|
|
5687
|
+
const current = await store().get(id);
|
|
5688
|
+
if (current === null) {
|
|
5689
|
+
return notFound(id);
|
|
5690
|
+
}
|
|
5691
|
+
// Reopening is the one change an archived sketchpad takes, and it
|
|
5692
|
+
// can come with others: "reopen and put this in it".
|
|
5693
|
+
if (current.archived && archived !== false && (text !== undefined || page !== undefined)) {
|
|
5694
|
+
return {
|
|
5695
|
+
status: 400,
|
|
5696
|
+
json: {
|
|
5697
|
+
message: "This sketchpad is archived, so it is not changed. Reopen it first (archived: false), or ask the person to."
|
|
5698
|
+
}
|
|
5699
|
+
};
|
|
5700
|
+
}
|
|
5701
|
+
const result = await store().update(id, {
|
|
5702
|
+
baseVersion,
|
|
5703
|
+
...(text !== undefined ? {
|
|
5704
|
+
text,
|
|
5705
|
+
title: titleOf(text)
|
|
5706
|
+
} : {}),
|
|
5707
|
+
...(page !== undefined ? {
|
|
5708
|
+
page
|
|
5709
|
+
} : {}),
|
|
5710
|
+
...(archived !== undefined ? {
|
|
5711
|
+
archived
|
|
5712
|
+
} : {}),
|
|
5713
|
+
by: profileOf(auth)
|
|
5714
|
+
});
|
|
5715
|
+
if (result.status === "not-found") {
|
|
5716
|
+
return notFound(id);
|
|
5717
|
+
}
|
|
5718
|
+
if (result.status === "conflict") {
|
|
5719
|
+
return {
|
|
5720
|
+
status: 409,
|
|
5721
|
+
json: {
|
|
5722
|
+
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.`,
|
|
5723
|
+
sketchpad: result.sketchpad
|
|
5724
|
+
}
|
|
5725
|
+
};
|
|
5726
|
+
}
|
|
5727
|
+
return {
|
|
5728
|
+
status: 200,
|
|
5729
|
+
json: {
|
|
5730
|
+
sketchpad: result.sketchpad
|
|
5731
|
+
}
|
|
5732
|
+
};
|
|
5733
|
+
} catch (error) {
|
|
5734
|
+
return failed(error);
|
|
5735
|
+
}
|
|
5736
|
+
}
|
|
5737
|
+
}
|
|
5738
|
+
};
|
|
5739
|
+
}
|
|
5740
|
+
function isArchivedFilter(value) {
|
|
5741
|
+
return value === "exclude" || value === "include" || value === "only";
|
|
5742
|
+
}
|
|
5743
|
+
function titleOf(text) {
|
|
5744
|
+
return internal.sketchTitle(internal.parseSketch(text).blocks);
|
|
5745
|
+
}
|
|
5746
|
+
/** A 400 for a text the server will not keep, saying which lines and why. */
|
|
5747
|
+
function refuseText(text) {
|
|
5748
|
+
// Bytes, not characters, as the content service counts them: a page in
|
|
5749
|
+
// Norwegian is longer in UTF-8 than it looks.
|
|
5750
|
+
const bytes = new TextEncoder().encode(text).length;
|
|
5751
|
+
if (bytes > internal.SKETCHPAD_MAX_TEXT_LENGTH) {
|
|
5752
|
+
return {
|
|
5753
|
+
status: 400,
|
|
5754
|
+
json: {
|
|
5755
|
+
message: `A sketchpad holds at most ${internal.SKETCHPAD_MAX_TEXT_LENGTH / 1024} KiB of text; this is ${Math.ceil(bytes / 1024)} KiB.`
|
|
5756
|
+
}
|
|
5757
|
+
};
|
|
5758
|
+
}
|
|
5759
|
+
const errors = internal.checkSketch(text);
|
|
5760
|
+
if (errors.length === 0) {
|
|
5761
|
+
return null;
|
|
5762
|
+
}
|
|
5763
|
+
return {
|
|
5764
|
+
status: 400,
|
|
5765
|
+
json: {
|
|
5766
|
+
message: `That is not a sketch the Sketchpad can show: ${errors.map(error => `line ${error.line}: ${error.message}`).join(" ")}`,
|
|
5767
|
+
errors
|
|
5768
|
+
}
|
|
5769
|
+
};
|
|
5770
|
+
}
|
|
5771
|
+
function notFound(id) {
|
|
5772
|
+
return {
|
|
5773
|
+
status: 404,
|
|
5774
|
+
json: {
|
|
5775
|
+
message: `There is no sketchpad "${id}" in this project.`
|
|
5776
|
+
}
|
|
5777
|
+
};
|
|
5778
|
+
}
|
|
5779
|
+
function failed(error) {
|
|
5780
|
+
return {
|
|
5781
|
+
status: 500,
|
|
5782
|
+
json: {
|
|
5783
|
+
message: error instanceof Error ? error.message : "The sketchpads could not be reached."
|
|
5784
|
+
}
|
|
5785
|
+
};
|
|
5786
|
+
}
|
|
5787
|
+
|
|
5550
5788
|
/** What {@link ValServerOptions.publishOverride} is given. */
|
|
5551
5789
|
|
|
5552
5790
|
/** What a publish reports back, in either shape. */
|
|
@@ -6049,6 +6287,11 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
6049
6287
|
};
|
|
6050
6288
|
};
|
|
6051
6289
|
return {
|
|
6290
|
+
...createSketchpadRoutes({
|
|
6291
|
+
store: () => serverOps.sketchpads,
|
|
6292
|
+
getAuth,
|
|
6293
|
+
profileOf
|
|
6294
|
+
}),
|
|
6052
6295
|
"/draft/enable": {
|
|
6053
6296
|
GET: async req => {
|
|
6054
6297
|
const cookies = req.cookies;
|
|
@@ -9242,7 +9485,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
9242
9485
|
// TypeScript compiler. See `patch/ts/publishKit.ts`.
|
|
9243
9486
|
const {
|
|
9244
9487
|
getJsonEntryAtCommit
|
|
9245
|
-
} = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-
|
|
9488
|
+
} = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-971b7bbe.cjs.dev.js'); });
|
|
9246
9489
|
const res = await getJsonEntryAtCommit(serverOps, req.query.commit_sha, req.query.path, req.query.key);
|
|
9247
9490
|
if (fp.result.isErr(res)) {
|
|
9248
9491
|
return historyErrorResponse(res.error);
|
|
@@ -9972,6 +10215,138 @@ async function uploadRemoteFile(contentHost, project, bucket, fileHash, fileExt,
|
|
|
9972
10215
|
};
|
|
9973
10216
|
}
|
|
9974
10217
|
|
|
10218
|
+
/**
|
|
10219
|
+
* Where a project's sketchpads are kept, in each of the server's modes:
|
|
10220
|
+
* `.val/sketchpads` in `fs` mode, the content service in `http` mode, the
|
|
10221
|
+
* tab's memory in the demo. See `Sketchpad` in `ApiRoutes.ts` for what one
|
|
10222
|
+
* is.
|
|
10223
|
+
*
|
|
10224
|
+
* The store keeps what it is given. Whether a text is a sketch at all is
|
|
10225
|
+
* decided before it gets here (`checkSketch`, in `ValServer`), once for every
|
|
10226
|
+
* mode, so no store has its own idea of the format.
|
|
10227
|
+
*/
|
|
10228
|
+
|
|
10229
|
+
/**
|
|
10230
|
+
* Whether `id` is in the shape a sketchpad's id has. Every store checks it
|
|
10231
|
+
* before the id goes anywhere it could mean something else: a file name in
|
|
10232
|
+
* fs mode, a URL path in http mode, where `..` is not an id but a way out.
|
|
10233
|
+
*/
|
|
10234
|
+
function isSketchpadId(id) {
|
|
10235
|
+
return /^[0-9a-f-]{36}$/.test(id);
|
|
10236
|
+
}
|
|
10237
|
+
|
|
10238
|
+
/**
|
|
10239
|
+
* A random id in the shape of a UUID. `getRandomValues` rather than
|
|
10240
|
+
* `randomUUID`, which a browser only has in a secure context -- and the demo
|
|
10241
|
+
* runs this server in the visitor's tab.
|
|
10242
|
+
*/
|
|
10243
|
+
function newSketchpadId() {
|
|
10244
|
+
const bytes = new Uint8Array(16);
|
|
10245
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
10246
|
+
bytes[6] = bytes[6] & 0x0f | 0x40;
|
|
10247
|
+
bytes[8] = bytes[8] & 0x3f | 0x80;
|
|
10248
|
+
const hex = Array.from(bytes, b => b.toString(16).padStart(2, "0"));
|
|
10249
|
+
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("-");
|
|
10250
|
+
}
|
|
10251
|
+
function summaryOf(sketchpad) {
|
|
10252
|
+
const {
|
|
10253
|
+
text,
|
|
10254
|
+
...summary
|
|
10255
|
+
} = sketchpad;
|
|
10256
|
+
return summary;
|
|
10257
|
+
}
|
|
10258
|
+
function matchesFilter(sketchpad, filter) {
|
|
10259
|
+
if (filter.page !== undefined && sketchpad.page !== filter.page) {
|
|
10260
|
+
return false;
|
|
10261
|
+
}
|
|
10262
|
+
return filter.archived === "include" ? true : filter.archived === "only" ? sketchpad.archived : !sketchpad.archived;
|
|
10263
|
+
}
|
|
10264
|
+
|
|
10265
|
+
/** Newest change first, as every list of them is read. */
|
|
10266
|
+
function byUpdatedAt(a, b) {
|
|
10267
|
+
return b.updatedAt.localeCompare(a.updatedAt);
|
|
10268
|
+
}
|
|
10269
|
+
function newSketchpad(input, now) {
|
|
10270
|
+
const at = now.toISOString();
|
|
10271
|
+
return {
|
|
10272
|
+
id: newSketchpadId(),
|
|
10273
|
+
page: input.page,
|
|
10274
|
+
title: input.title,
|
|
10275
|
+
text: input.text,
|
|
10276
|
+
version: 1,
|
|
10277
|
+
archived: false,
|
|
10278
|
+
createdAt: at,
|
|
10279
|
+
updatedAt: at,
|
|
10280
|
+
createdBy: input.by,
|
|
10281
|
+
updatedBy: input.by
|
|
10282
|
+
};
|
|
10283
|
+
}
|
|
10284
|
+
|
|
10285
|
+
/** `current` with `change` applied, or why not. Pure: storing is the caller's. */
|
|
10286
|
+
function applySketchpadChange(current, change, now) {
|
|
10287
|
+
if (current === null) {
|
|
10288
|
+
return {
|
|
10289
|
+
status: "not-found"
|
|
10290
|
+
};
|
|
10291
|
+
}
|
|
10292
|
+
if (current.version !== change.baseVersion) {
|
|
10293
|
+
return {
|
|
10294
|
+
status: "conflict",
|
|
10295
|
+
sketchpad: current
|
|
10296
|
+
};
|
|
10297
|
+
}
|
|
10298
|
+
return {
|
|
10299
|
+
status: "updated",
|
|
10300
|
+
sketchpad: {
|
|
10301
|
+
...current,
|
|
10302
|
+
...(change.text !== undefined ? {
|
|
10303
|
+
text: change.text
|
|
10304
|
+
} : {}),
|
|
10305
|
+
...(change.title !== undefined ? {
|
|
10306
|
+
title: change.title
|
|
10307
|
+
} : {}),
|
|
10308
|
+
...(change.page !== undefined ? {
|
|
10309
|
+
page: change.page
|
|
10310
|
+
} : {}),
|
|
10311
|
+
...(change.archived !== undefined ? {
|
|
10312
|
+
archived: change.archived
|
|
10313
|
+
} : {}),
|
|
10314
|
+
version: current.version + 1,
|
|
10315
|
+
updatedAt: now.toISOString(),
|
|
10316
|
+
updatedBy: change.by
|
|
10317
|
+
}
|
|
10318
|
+
};
|
|
10319
|
+
}
|
|
10320
|
+
|
|
10321
|
+
/**
|
|
10322
|
+
* Sketchpads kept in memory, for as long as the server runs: the demo's
|
|
10323
|
+
* store, where a reload starts over anyway, and the tests'.
|
|
10324
|
+
*/
|
|
10325
|
+
function createMemorySketchpadStore(now = () => new Date()) {
|
|
10326
|
+
const sketchpads = new Map();
|
|
10327
|
+
return {
|
|
10328
|
+
async list(filter) {
|
|
10329
|
+
return Array.from(sketchpads.values()).map(summaryOf).filter(sketchpad => matchesFilter(sketchpad, filter)).sort(byUpdatedAt);
|
|
10330
|
+
},
|
|
10331
|
+
async get(id) {
|
|
10332
|
+
return sketchpads.get(id) ?? null;
|
|
10333
|
+
},
|
|
10334
|
+
async create(input) {
|
|
10335
|
+
const sketchpad = newSketchpad(input, now());
|
|
10336
|
+
sketchpads.set(sketchpad.id, sketchpad);
|
|
10337
|
+
return sketchpad;
|
|
10338
|
+
},
|
|
10339
|
+
async update(id, change) {
|
|
10340
|
+
// Synchronous from the read to the write, so nothing interleaves.
|
|
10341
|
+
const result = applySketchpadChange(sketchpads.get(id) ?? null, change, now());
|
|
10342
|
+
if (result.status === "updated") {
|
|
10343
|
+
sketchpads.set(id, result.sketchpad);
|
|
10344
|
+
}
|
|
10345
|
+
return result;
|
|
10346
|
+
}
|
|
10347
|
+
};
|
|
10348
|
+
}
|
|
10349
|
+
|
|
9975
10350
|
/**
|
|
9976
10351
|
* One stored patch. Everything the ordered chain needs and nothing else.
|
|
9977
10352
|
*/
|
|
@@ -10104,6 +10479,8 @@ class ValOpsMemory extends ValOps {
|
|
|
10104
10479
|
*/
|
|
10105
10480
|
patchesAreLocal = true;
|
|
10106
10481
|
kind = "memory";
|
|
10482
|
+
/** For as long as the tab is open, like everything else in the demo. */
|
|
10483
|
+
sketchpads = createMemorySketchpadStore();
|
|
10107
10484
|
/**
|
|
10108
10485
|
* Required, unless the host explicitly takes the boundary itself.
|
|
10109
10486
|
*
|
|
@@ -10998,8 +11375,10 @@ exports.InMemoryPatchStore = InMemoryPatchStore;
|
|
|
10998
11375
|
exports.ValOps = ValOps;
|
|
10999
11376
|
exports.ValOpsMemory = ValOpsMemory;
|
|
11000
11377
|
exports.ValServer = ValServer;
|
|
11378
|
+
exports.applySketchpadChange = applySketchpadChange;
|
|
11001
11379
|
exports.askOncePerHost = askOncePerHost;
|
|
11002
11380
|
exports.bufferFromDataUrl = bufferFromDataUrl;
|
|
11381
|
+
exports.byUpdatedAt = byUpdatedAt;
|
|
11003
11382
|
exports.bytesToBase64 = bytesToBase64;
|
|
11004
11383
|
exports.bytesToUtf8 = bytesToUtf8;
|
|
11005
11384
|
exports.checkRemoteFiles = checkRemoteFiles;
|
|
@@ -11017,15 +11396,19 @@ exports.getSettings = getSettings;
|
|
|
11017
11396
|
exports.guessMimeTypeFromPath = guessMimeTypeFromPath;
|
|
11018
11397
|
exports.isHlsMasterPlaylist = isHlsMasterPlaylist;
|
|
11019
11398
|
exports.isJsonValuesRootOp = isJsonValuesRootOp;
|
|
11399
|
+
exports.isSketchpadId = isSketchpadId;
|
|
11020
11400
|
exports.largestHlsVariant = largestHlsVariant;
|
|
11021
11401
|
exports.mapHlsUris = mapHlsUris;
|
|
11402
|
+
exports.matchesFilter = matchesFilter;
|
|
11022
11403
|
exports.movedRemoteHost = movedRemoteHost;
|
|
11023
11404
|
exports.needsHostCheck = needsHostCheck;
|
|
11405
|
+
exports.newSketchpad = newSketchpad;
|
|
11024
11406
|
exports.parseHlsMasterVariants = parseHlsMasterVariants;
|
|
11025
11407
|
exports.posixPath = posixPath;
|
|
11026
11408
|
exports.rebaseContentOp = rebaseContentOp;
|
|
11027
11409
|
exports.resolveExistingJsonPath = resolveExistingJsonPath;
|
|
11028
11410
|
exports.rewriteRefHost = rewriteRefHost;
|
|
11029
11411
|
exports.sumHlsSegmentDurations = sumHlsSegmentDurations;
|
|
11412
|
+
exports.summaryOf = summaryOf;
|
|
11030
11413
|
exports.uploadRemoteFile = uploadRemoteFile;
|
|
11031
11414
|
exports.validateJsonValuesEntries = validateJsonValuesEntries;
|