@valbuild/server 0.154.0 → 0.154.2

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/browser/dist/valbuild-server-browser.cjs.dev.js +6 -3
  3. package/browser/dist/valbuild-server-browser.cjs.prod.js +6 -3
  4. package/browser/dist/valbuild-server-browser.esm.js +6 -3
  5. package/dist/{ValRouterCore-fe985e4c.esm.js → ValOpsMemory-611f33d2.esm.js} +44 -1988
  6. package/dist/{ValRouterCore-4be8eaf1.cjs.prod.js → ValOpsMemory-6ebbb3ba.cjs.prod.js} +53 -2009
  7. package/dist/{ValRouterCore-0c088c9e.cjs.dev.js → ValOpsMemory-d8bf9f5d.cjs.dev.js} +53 -2009
  8. package/dist/ValPatchStore-2f92eced.cjs.prod.js +1128 -0
  9. package/dist/ValPatchStore-df8cdbe7.cjs.dev.js +1128 -0
  10. package/dist/ValPatchStore-e23070df.esm.js +1119 -0
  11. package/dist/ValRouterCore-5b747abb.cjs.prod.js +612 -0
  12. package/dist/ValRouterCore-73eb843d.esm.js +608 -0
  13. package/dist/ValRouterCore-86757d56.cjs.dev.js +612 -0
  14. package/dist/createPrettierFormatter-05ad7480.cjs.prod.js +692 -0
  15. package/dist/createPrettierFormatter-1edca494.esm.js +673 -0
  16. package/dist/createPrettierFormatter-851fcf99.cjs.dev.js +692 -0
  17. package/dist/createValRuntime-2dc83070.cjs.prod.js +47 -0
  18. package/dist/createValRuntime-62836dbe.esm.js +45 -0
  19. package/dist/createValRuntime-fd9b673d.cjs.dev.js +47 -0
  20. package/dist/declarations/src/ValOpsMemory.d.ts +3 -73
  21. package/dist/declarations/src/ValPatchStore.d.ts +92 -0
  22. package/dist/declarations/src/ValRouter.d.ts +1 -11
  23. package/dist/declarations/src/createPrettierFormatter.d.ts +18 -3
  24. package/dist/declarations/src/createValRuntime.d.ts +12 -0
  25. package/dist/declarations/src/draftReads.d.ts +11 -3
  26. package/dist/declarations/src/index.d.ts +4 -2
  27. package/dist/declarations/src/internal/index.d.ts +28 -6
  28. package/dist/declarations/src/proposal.d.ts +13 -25
  29. package/dist/declarations/src/proposalJsonEntries.d.ts +30 -0
  30. package/dist/declarations/src/serverMode.d.ts +31 -0
  31. package/dist/{draftReads-0dcddf72.cjs.prod.js → draftReads-3f7dcda5.cjs.prod.js} +10 -2
  32. package/dist/{draftReads-df44e629.cjs.dev.js → draftReads-a300a02f.cjs.dev.js} +10 -2
  33. package/dist/{draftReads-1f29aedd.esm.js → draftReads-bca0d49c.esm.js} +10 -2
  34. package/dist/{inTabFetch-f6694ad2.cjs.prod.js → inTabFetch-0124da2e.cjs.prod.js} +5 -4
  35. package/dist/{inTabFetch-c8966e73.cjs.dev.js → inTabFetch-d0c9c58a.cjs.dev.js} +5 -4
  36. package/dist/{inTabFetch-877e7d11.esm.js → inTabFetch-e48a801e.esm.js} +2 -1
  37. package/dist/jsonValuesPatch-13acc674.esm.js +276 -0
  38. package/dist/jsonValuesPatch-88bc661d.cjs.dev.js +281 -0
  39. package/dist/jsonValuesPatch-92798812.cjs.prod.js +281 -0
  40. package/dist/proposalJsonEntries-0669f027.esm.js +480 -0
  41. package/dist/proposalJsonEntries-26f397bd.cjs.dev.js +500 -0
  42. package/dist/proposalJsonEntries-9e537244.cjs.prod.js +500 -0
  43. package/dist/{publishKit-cfe1273d.cjs.dev.js → publishKit-96522d5a.cjs.prod.js} +20 -22
  44. package/dist/{publishKit-e7f7db7c.cjs.prod.js → publishKit-b06031dc.cjs.dev.js} +20 -22
  45. package/dist/{publishKit-0709423c.esm.js → publishKit-b8929fe8.esm.js} +8 -9
  46. package/dist/{ValRouter-1f427c38.cjs.dev.js → valRuntime-ba8ff718.cjs.prod.js} +158 -6038
  47. package/dist/{ValRouter-cd6e854a.cjs.prod.js → valRuntime-c8c82b24.cjs.dev.js} +158 -6038
  48. package/dist/{ValRouter-558dc66d.esm.js → valRuntime-ccbbbfad.esm.js} +107 -5937
  49. package/dist/valbuild-server.cjs.dev.js +5146 -352
  50. package/dist/valbuild-server.cjs.prod.js +5146 -352
  51. package/dist/valbuild-server.esm.js +4902 -132
  52. package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +7 -4
  53. package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +7 -4
  54. package/internal/browser/dist/valbuild-server-internal-browser.esm.js +7 -4
  55. package/internal/dist/valbuild-server-internal.cjs.dev.js +47 -31
  56. package/internal/dist/valbuild-server-internal.cjs.prod.js +47 -31
  57. package/internal/dist/valbuild-server-internal.esm.js +38 -22
  58. package/package.json +4 -4
@@ -18,6 +18,14 @@ var internal = require('@valbuild/shared/internal');
18
18
  * nothing is read for it at all.
19
19
  */
20
20
 
21
+ /**
22
+ * The runtime a reader reads the draft through, asked for when a read first
23
+ * needs it (`createValRuntime`). A function rather than a promise, so that
24
+ * building the readers does not build the runtime: the runtime is the data
25
+ * layer, and a visitor -- draft mode off -- never needs it. A caller that
26
+ * already has one passes `() => runtime`; it is asked at most once a read.
27
+ */
28
+
21
29
  /** One module {@link readDraftChanges} read: what a reader's `reads` record. */
22
30
 
23
31
  const SERVER_DRAFT = "server-draft";
@@ -52,7 +60,7 @@ async function readDraftChanges(opts) {
52
60
  // Possibly absent: a local `fs` server answers without one. The runtime
53
61
  // decides, as the API does.
54
62
  const session = (_await$opts$getCookie = (await opts.getCookies()).get(internal.VAL_SESSION_COOKIE)) === null || _await$opts$getCookie === void 0 ? void 0 : _await$opts$getCookie.value;
55
- const runtime = await opts.runtime;
63
+ const runtime = await opts.runtime();
56
64
  if (!runtime.authorize(session)) {
57
65
  return null;
58
66
  }
@@ -133,7 +141,7 @@ function serverDraftSource(opts) {
133
141
  */
134
142
  let allowed = null;
135
143
  const runtime = () => {
136
- allowed ??= opts.runtime.then(async runtime => {
144
+ allowed ??= opts.runtime().then(async runtime => {
137
145
  if (!runtime.authorize(opts.session)) return null;
138
146
  const synced = await runtime.ops.head.sync();
139
147
  if ("error" in synced) {
@@ -18,6 +18,14 @@ var internal = require('@valbuild/shared/internal');
18
18
  * nothing is read for it at all.
19
19
  */
20
20
 
21
+ /**
22
+ * The runtime a reader reads the draft through, asked for when a read first
23
+ * needs it (`createValRuntime`). A function rather than a promise, so that
24
+ * building the readers does not build the runtime: the runtime is the data
25
+ * layer, and a visitor -- draft mode off -- never needs it. A caller that
26
+ * already has one passes `() => runtime`; it is asked at most once a read.
27
+ */
28
+
21
29
  /** One module {@link readDraftChanges} read: what a reader's `reads` record. */
22
30
 
23
31
  const SERVER_DRAFT = "server-draft";
@@ -52,7 +60,7 @@ async function readDraftChanges(opts) {
52
60
  // Possibly absent: a local `fs` server answers without one. The runtime
53
61
  // decides, as the API does.
54
62
  const session = (_await$opts$getCookie = (await opts.getCookies()).get(internal.VAL_SESSION_COOKIE)) === null || _await$opts$getCookie === void 0 ? void 0 : _await$opts$getCookie.value;
55
- const runtime = await opts.runtime;
63
+ const runtime = await opts.runtime();
56
64
  if (!runtime.authorize(session)) {
57
65
  return null;
58
66
  }
@@ -133,7 +141,7 @@ function serverDraftSource(opts) {
133
141
  */
134
142
  let allowed = null;
135
143
  const runtime = () => {
136
- allowed ??= opts.runtime.then(async runtime => {
144
+ allowed ??= opts.runtime().then(async runtime => {
137
145
  if (!runtime.authorize(opts.session)) return null;
138
146
  const synced = await runtime.ops.head.sync();
139
147
  if ("error" in synced) {
@@ -16,6 +16,14 @@ import { VAL_SESSION_COOKIE } from '@valbuild/shared/internal';
16
16
  * nothing is read for it at all.
17
17
  */
18
18
 
19
+ /**
20
+ * The runtime a reader reads the draft through, asked for when a read first
21
+ * needs it (`createValRuntime`). A function rather than a promise, so that
22
+ * building the readers does not build the runtime: the runtime is the data
23
+ * layer, and a visitor -- draft mode off -- never needs it. A caller that
24
+ * already has one passes `() => runtime`; it is asked at most once a read.
25
+ */
26
+
19
27
  /** One module {@link readDraftChanges} read: what a reader's `reads` record. */
20
28
 
21
29
  const SERVER_DRAFT = "server-draft";
@@ -50,7 +58,7 @@ async function readDraftChanges(opts) {
50
58
  // Possibly absent: a local `fs` server answers without one. The runtime
51
59
  // decides, as the API does.
52
60
  const session = (_await$opts$getCookie = (await opts.getCookies()).get(VAL_SESSION_COOKIE)) === null || _await$opts$getCookie === void 0 ? void 0 : _await$opts$getCookie.value;
53
- const runtime = await opts.runtime;
61
+ const runtime = await opts.runtime();
54
62
  if (!runtime.authorize(session)) {
55
63
  return null;
56
64
  }
@@ -131,7 +139,7 @@ function serverDraftSource(opts) {
131
139
  */
132
140
  let allowed = null;
133
141
  const runtime = () => {
134
- allowed ??= opts.runtime.then(async runtime => {
142
+ allowed ??= opts.runtime().then(async runtime => {
135
143
  if (!runtime.authorize(opts.session)) return null;
136
144
  const synced = await runtime.ops.head.sync();
137
145
  if ("error" in synced) {
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var core = require('@valbuild/core');
4
- var ValRouterCore = require('./ValRouterCore-4be8eaf1.cjs.prod.js');
4
+ var ValOpsMemory = require('./ValOpsMemory-6ebbb3ba.cjs.prod.js');
5
+ var ValRouterCore = require('./ValRouterCore-5b747abb.cjs.prod.js');
5
6
 
6
7
  const NO_SESSIONS = "Val: sessions are not available here -- this server runs in the browser, " + "has no secret to sign them with, and serves without authenticating.";
7
8
 
@@ -20,7 +21,7 @@ const browserPlatform = {
20
21
  if (options.mode !== "memory") {
21
22
  throw new Error(`Val: a server in the browser runs in memory mode, not '${options.mode}'.`);
22
23
  }
23
- return new ValRouterCore.ValOpsMemory(valModules, {
24
+ return new ValOpsMemory.ValOpsMemory(valModules, {
24
25
  formatter: options.formatter,
25
26
  config: options.config,
26
27
  sourceFiles: options.sourceFiles,
@@ -51,7 +52,7 @@ const browserPlatform = {
51
52
  },
52
53
  getExpire: () => Math.floor(Date.now() / 1000) + 60 * 60
53
54
  },
54
- bytesToBase64: ValRouterCore.bytesToBase64,
55
+ bytesToBase64: ValOpsMemory.bytesToBase64,
55
56
  readValLoginToken: async () => null,
56
57
  resolveRemoteFileAuth: async () => ({
57
58
  status: "error",
@@ -116,7 +117,7 @@ function createInTabVal(valModules, options) {
116
117
  return ops;
117
118
  }
118
119
  };
119
- const server = ValRouterCore.ValServer(valModules, serverConfig, {
120
+ const server = ValOpsMemory.ValServer(valModules, serverConfig, {
120
121
  // Draft content is the only content a demo has.
121
122
  isEnabled: async () => true,
122
123
  onEnable: async () => {},
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var core = require('@valbuild/core');
4
- var ValRouterCore = require('./ValRouterCore-0c088c9e.cjs.dev.js');
4
+ var ValOpsMemory = require('./ValOpsMemory-d8bf9f5d.cjs.dev.js');
5
+ var ValRouterCore = require('./ValRouterCore-86757d56.cjs.dev.js');
5
6
 
6
7
  const NO_SESSIONS = "Val: sessions are not available here -- this server runs in the browser, " + "has no secret to sign them with, and serves without authenticating.";
7
8
 
@@ -20,7 +21,7 @@ const browserPlatform = {
20
21
  if (options.mode !== "memory") {
21
22
  throw new Error(`Val: a server in the browser runs in memory mode, not '${options.mode}'.`);
22
23
  }
23
- return new ValRouterCore.ValOpsMemory(valModules, {
24
+ return new ValOpsMemory.ValOpsMemory(valModules, {
24
25
  formatter: options.formatter,
25
26
  config: options.config,
26
27
  sourceFiles: options.sourceFiles,
@@ -51,7 +52,7 @@ const browserPlatform = {
51
52
  },
52
53
  getExpire: () => Math.floor(Date.now() / 1000) + 60 * 60
53
54
  },
54
- bytesToBase64: ValRouterCore.bytesToBase64,
55
+ bytesToBase64: ValOpsMemory.bytesToBase64,
55
56
  readValLoginToken: async () => null,
56
57
  resolveRemoteFileAuth: async () => ({
57
58
  status: "error",
@@ -116,7 +117,7 @@ function createInTabVal(valModules, options) {
116
117
  return ops;
117
118
  }
118
119
  };
119
- const server = ValRouterCore.ValServer(valModules, serverConfig, {
120
+ const server = ValOpsMemory.ValServer(valModules, serverConfig, {
120
121
  // Draft content is the only content a demo has.
121
122
  isEnabled: async () => true,
122
123
  onEnable: async () => {},
@@ -1,5 +1,6 @@
1
1
  import { DEFAULT_CONTENT_HOST } from '@valbuild/core';
2
- import { e as ValOpsMemory, S as bytesToBase64, O as ValServer, R as createValRequestHandler } from './ValRouterCore-fe985e4c.esm.js';
2
+ import { o as ValOpsMemory, K as bytesToBase64, V as ValServer } from './ValOpsMemory-611f33d2.esm.js';
3
+ import { c as createValRequestHandler } from './ValRouterCore-73eb843d.esm.js';
3
4
 
4
5
  const NO_SESSIONS = "Val: sessions are not available here -- this server runs in the browser, " + "has no secret to sign them with, and serves without authenticating.";
5
6
 
@@ -0,0 +1,276 @@
1
+ import { result } from '@valbuild/core/fp';
2
+ import '@valbuild/shared/internal';
3
+
4
+ /**
5
+ * `path.posix`, for the four functions the request handlers use.
6
+ *
7
+ * Node's `path` cannot be bundled for a browser, and the request handlers run
8
+ * in one for the demo (`@valbuild/server/browser`). These are Node's own posix
9
+ * algorithms, and `posixPath.test.ts` checks them against `path.posix` itself,
10
+ * so the two cannot differ quietly. Module paths are always posix -- `/app/
11
+ * page.val.ts` on Windows too -- so nothing here needs the platform's `path`.
12
+ */
13
+
14
+ /** Resolves `.` and `..` segments, as Node's `normalizeString` does. */
15
+ function normalizeSegments(path, allowAboveRoot) {
16
+ let res = "";
17
+ let lastSegmentLength = 0;
18
+ let lastSlash = -1;
19
+ let dots = 0;
20
+ let code = 0;
21
+ for (let i = 0; i <= path.length; ++i) {
22
+ if (i < path.length) {
23
+ code = path.charCodeAt(i);
24
+ } else if (code === 47 /* / */) {
25
+ break;
26
+ } else {
27
+ code = 47;
28
+ }
29
+ if (code === 47) {
30
+ if (lastSlash === i - 1 || dots === 1) ; else if (dots === 2) {
31
+ if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /* . */ || res.charCodeAt(res.length - 2) !== 46) {
32
+ if (res.length > 2) {
33
+ const lastSlashIndex = res.lastIndexOf("/");
34
+ if (lastSlashIndex === -1) {
35
+ res = "";
36
+ lastSegmentLength = 0;
37
+ } else {
38
+ res = res.slice(0, lastSlashIndex);
39
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
40
+ }
41
+ lastSlash = i;
42
+ dots = 0;
43
+ continue;
44
+ } else if (res.length !== 0) {
45
+ res = "";
46
+ lastSegmentLength = 0;
47
+ lastSlash = i;
48
+ dots = 0;
49
+ continue;
50
+ }
51
+ }
52
+ if (allowAboveRoot) {
53
+ res += res.length > 0 ? "/.." : "..";
54
+ lastSegmentLength = 2;
55
+ }
56
+ } else {
57
+ if (res.length > 0) {
58
+ res += "/" + path.slice(lastSlash + 1, i);
59
+ } else {
60
+ res = path.slice(lastSlash + 1, i);
61
+ }
62
+ lastSegmentLength = i - lastSlash - 1;
63
+ }
64
+ lastSlash = i;
65
+ dots = 0;
66
+ } else if (code === 46 && dots !== -1) {
67
+ ++dots;
68
+ } else {
69
+ dots = -1;
70
+ }
71
+ }
72
+ return res;
73
+ }
74
+ function normalize(path) {
75
+ if (path.length === 0) return ".";
76
+ const isAbsolute = path.charCodeAt(0) === 47;
77
+ const trailingSeparator = path.charCodeAt(path.length - 1) === 47;
78
+ let normalized = normalizeSegments(path, !isAbsolute);
79
+ if (normalized.length === 0) {
80
+ if (isAbsolute) return "/";
81
+ return trailingSeparator ? "./" : ".";
82
+ }
83
+ if (trailingSeparator) normalized += "/";
84
+ return isAbsolute ? `/${normalized}` : normalized;
85
+ }
86
+ function join(...paths) {
87
+ const joined = paths.filter(path => path.length > 0).join("/");
88
+ return joined.length === 0 ? "." : normalize(joined);
89
+ }
90
+ function dirname(path) {
91
+ if (path.length === 0) return ".";
92
+ const hasRoot = path.charCodeAt(0) === 47;
93
+ let end = -1;
94
+ let matchedSlash = true;
95
+ for (let i = path.length - 1; i >= 1; --i) {
96
+ if (path.charCodeAt(i) === 47) {
97
+ if (!matchedSlash) {
98
+ end = i;
99
+ break;
100
+ }
101
+ } else {
102
+ matchedSlash = false;
103
+ }
104
+ }
105
+ if (end === -1) return hasRoot ? "/" : ".";
106
+ if (hasRoot && end === 1) return "//";
107
+ return path.slice(0, end);
108
+ }
109
+
110
+ /**
111
+ * Node resolves both sides against `process.cwd()` first. When both are
112
+ * relative the cwd is a common prefix and drops out of the answer, so a root
113
+ * stands in for it; when only one is, the answer depends on a directory a
114
+ * browser does not have, and it is refused rather than guessed.
115
+ */
116
+ function resolveBoth(from, to) {
117
+ const fromAbsolute = from.charCodeAt(0) === 47;
118
+ const toAbsolute = to.charCodeAt(0) === 47;
119
+ if (fromAbsolute !== toAbsolute) {
120
+ throw new Error(`posixPath.relative needs two absolute or two relative paths, got '${from}' and '${to}'.`);
121
+ }
122
+ const root = path => `/${normalizeSegments(fromAbsolute ? path : `/${path}`, false)}`;
123
+ return [root(from), root(to)];
124
+ }
125
+ function relative(from, to) {
126
+ if (from === to) return "";
127
+ [from, to] = resolveBoth(from, to);
128
+ if (from === to) return "";
129
+ const fromStart = 1;
130
+ const fromEnd = from.length;
131
+ const fromLen = fromEnd - fromStart;
132
+ const toStart = 1;
133
+ const toLen = to.length - toStart;
134
+ const length = fromLen < toLen ? fromLen : toLen;
135
+ let lastCommonSep = -1;
136
+ let i = 0;
137
+ for (; i < length; i++) {
138
+ const fromCode = from.charCodeAt(fromStart + i);
139
+ if (fromCode !== to.charCodeAt(toStart + i)) break;else if (fromCode === 47) lastCommonSep = i;
140
+ }
141
+ if (i === length) {
142
+ if (toLen > length) {
143
+ if (to.charCodeAt(toStart + i) === 47) {
144
+ return to.slice(toStart + i + 1);
145
+ }
146
+ if (i === 0) {
147
+ return to.slice(toStart + i);
148
+ }
149
+ } else if (fromLen > length) {
150
+ if (from.charCodeAt(fromStart + i) === 47) {
151
+ lastCommonSep = i;
152
+ } else if (i === 0) {
153
+ lastCommonSep = 0;
154
+ }
155
+ }
156
+ }
157
+ let out = "";
158
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
159
+ if (i === fromEnd || from.charCodeAt(i) === 47) {
160
+ out += out.length === 0 ? ".." : "/..";
161
+ }
162
+ }
163
+ return `${out}${to.slice(toStart + lastCommonSep)}`;
164
+ }
165
+ const posixPath = {
166
+ normalize,
167
+ join,
168
+ dirname,
169
+ relative
170
+ };
171
+
172
+ /**
173
+ * Finds every `.jsonValues()` record in a module's schema that is NOT the
174
+ * module's root, returning the path to each within the module source.
175
+ *
176
+ * `.jsonValues()` is only supported on a module's ROOT record/router: the
177
+ * `/json` endpoint keys entries by a single string, the Studio substitutes
178
+ * loaded content at the top level of the module source, and
179
+ * `validateJsonValuesEntries` only visits a root record. A nested one would
180
+ * silently skip content validation and hang the Studio on a 404, so we reject
181
+ * it up front instead (see {@link ValOps.initSources}).
182
+ */
183
+ function findNestedJsonValuesRecords(schema, path = []) {
184
+ const found = [];
185
+ const rec = (current, currentPath) => {
186
+ if (current.type === "record" && current.jsonValues && currentPath.length > 0) {
187
+ found.push(currentPath);
188
+ // Do not descend: everything below lives in the entry's `*.val.json`.
189
+ return;
190
+ }
191
+ switch (current.type) {
192
+ case "object":
193
+ for (const key of Object.keys(current.items)) {
194
+ rec(current.items[key], currentPath.concat(key));
195
+ }
196
+ return;
197
+ case "record":
198
+ rec(current.item, currentPath.concat("*"));
199
+ return;
200
+ case "array":
201
+ rec(current.item, currentPath.concat("*"));
202
+ return;
203
+ case "discriminated-union":
204
+ for (let i = 0; i < current.items.length; i++) {
205
+ rec(current.items[i], currentPath.concat(`union[${i}]`));
206
+ }
207
+ return;
208
+ default:
209
+ return;
210
+ }
211
+ };
212
+ rec(schema, path);
213
+ return found;
214
+ }
215
+
216
+ /**
217
+ * The `.val.ts` suffix a module file path ends with. Stripping it yields the
218
+ * folder that a new entry's `*.val.json` files are nested under.
219
+ */
220
+ const VAL_TS_SUFFIX = ".val.ts";
221
+
222
+ /**
223
+ * Computes the `*.val.json` file path (relative to rootDir) and the `import(...)`
224
+ * path (relative to the module's directory) for a NEW `.jsonValues()` entry,
225
+ * following the locked filename convention: the file mirrors the entry key under
226
+ * a folder named after the `.val.ts` (its `.val.ts` suffix becomes the folder).
227
+ *
228
+ * For module `/app/support/[slug]/page.val.ts` and key `/support/faq`:
229
+ * - jsonPath: `/app/support/[slug]/page/support/faq.val.json`
230
+ * - importPath: `./page/support/faq.val.json`
231
+ */
232
+ function getNewJsonEntryPaths(moduleFilePath, entryKey) {
233
+ const base = moduleFilePath.endsWith(VAL_TS_SUFFIX) ? moduleFilePath.slice(0, -VAL_TS_SUFFIX.length) : moduleFilePath;
234
+ const keyRel = entryKey.replace(/^\//, "");
235
+ const invalid = reason => result.err({
236
+ message: `Invalid .jsonValues() entry key '${entryKey}' in ${moduleFilePath}: ${reason}`,
237
+ filePath: moduleFilePath
238
+ });
239
+ // An entry key is CLIENT-SUPPLIED — it arrives as a record key in a patch op —
240
+ // and this path is what the commit writes to disk. Left unchecked, a key with
241
+ // `..` segments (or a backslash, which is a separator once the path is handed
242
+ // to node's `path.join` on Windows) puts that write anywhere in the project or
243
+ // outside it entirely, and a `move` additionally deletes the source path.
244
+ if (keyRel === "") {
245
+ return invalid("it is empty");
246
+ }
247
+ if (keyRel.includes("\\") || keyRel.includes("\0")) {
248
+ return invalid("it contains a backslash or a NUL byte");
249
+ }
250
+ const jsonPath = posixPath.normalize(`${base}/${keyRel}.val.json`);
251
+ if (!jsonPath.startsWith(`${base}/`)) {
252
+ return invalid(`it resolves outside '${base}/'`);
253
+ }
254
+ const moduleDir = posixPath.dirname(moduleFilePath);
255
+ let importPath = posixPath.relative(moduleDir, jsonPath);
256
+ if (!importPath.startsWith(".")) {
257
+ importPath = `./${importPath}`;
258
+ }
259
+ return result.ok({
260
+ jsonPath,
261
+ importPath
262
+ });
263
+ }
264
+
265
+ /**
266
+ * Resolves an EXISTING entry's `*.val.json` path (relative to rootDir) from the
267
+ * `import(...)` path recorded in the `.val.ts` thunk (from
268
+ * {@link analyzeJsonValuesEntries}). Existing files may have been hand-placed,
269
+ * so the import path is authoritative (hybrid authoring).
270
+ */
271
+ function resolveExistingJsonPath(moduleFilePath, importPath) {
272
+ const moduleDir = posixPath.dirname(moduleFilePath);
273
+ return posixPath.join(moduleDir, importPath);
274
+ }
275
+
276
+ export { findNestedJsonValuesRecords as f, getNewJsonEntryPaths as g, posixPath as p, resolveExistingJsonPath as r };