@valbuild/server 0.108.3 → 0.108.5

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.
@@ -14,10 +14,24 @@ export declare class Service {
14
14
  * The module file paths that are registered in the project's val.modules.
15
15
  */
16
16
  getModuleFilePaths(): ModuleFilePath[];
17
+ private serializedSchemaOf;
17
18
  get(moduleFilePath: ModuleFilePath, modulePath: ModulePath, options?: {
18
19
  validate: boolean;
19
20
  }): Promise<SerializedModuleContent>;
21
+ /**
22
+ * Applies a patch to a module's files.
23
+ *
24
+ * A `.jsonValues()` entry's content is not in the `.val.ts` — that file holds
25
+ * only `c.json(() => import("./x.val.json"))` — so an op whose path descends
26
+ * into an entry has to be replayed against the backing `*.val.json` instead.
27
+ * That routing is the same one the Studio's commit flow does in
28
+ * `ValOps.prepare`; both classify with {@link classifyJsonValuesOp} and rebase
29
+ * with {@link rebaseContentOp}, so a CLI fix and a Studio publish write the
30
+ * same file the same way.
31
+ */
20
32
  patch(moduleFilePath: ModuleFilePath, patch: Patch): Promise<void>;
33
+ /** Replays content ops against one `.jsonValues()` entry's `*.val.json`. */
34
+ private patchJsonValuesEntry;
21
35
  dispose(): void;
22
36
  }
23
37
  export {};
@@ -5,4 +5,4 @@ import { ValidationError } from "@valbuild/core";
5
5
  * There is no schema in hand here — a `ValidationError` carries only the value
6
6
  * it flagged — so the shape is all there is to go on.
7
7
  */
8
- export declare function getValidationErrorFileRef(validationError: ValidationError): string | null;
8
+ export declare function getValidationErrorFileRef(validationError: ValidationError): any;
@@ -29,6 +29,8 @@ export { startValLogin, awaitValLoginConfirmation, persistPersonalAccessToken, V
29
29
  export type { ValLoginErrorCode, ValLoginResult, ValLoginSession, } from "./login.js";
30
30
  export { createModulePathMap, createJsonEntryPathMap, getModulePathRange, } from "./modulePathMap.js";
31
31
  export { findJsonEntryFilePath } from "./jsonEntryLocation.js";
32
+ export { classifyJsonValuesOp, rebaseContentOp } from "./patch/jsonValuesPatch.js";
33
+ export type { JsonValuesOpClass } from "./patch/jsonValuesPatch.js";
32
34
  export { extractJsonValuesEntry } from "./extractJsonValuesEntry.js";
33
35
  export type { ModulePathMap } from "./modulePathMap.js";
34
36
  export { ValOpsFS } from "./ValOpsFS.js";
@@ -0,0 +1,107 @@
1
+ import type { PatchId, SerializedSchema } from "@valbuild/core";
2
+ import type { PatchSourceError } from "../ValOps.js";
3
+ import { result } from "@valbuild/core/fp";
4
+ import { JSONValue, Operation, Patch, PatchError } from "@valbuild/core/patch";
5
+ /**
6
+ * Classification of a single patch op against a module's serialized schema,
7
+ * used by the commit flow to route ops for `.jsonValues()` records:
8
+ *
9
+ * - `normal`: the op does not descend into a `.jsonValues()` entry; apply it to
10
+ * the `.val.ts` as usual.
11
+ * - `entry`: the op targets a `.jsonValues()` entry. `recordPath` is the path to
12
+ * the record within the module source (empty for a root record/router),
13
+ * `entryKey` is the entry key, and `subPath` is the remaining path inside the
14
+ * entry (empty when the op targets the entry value itself, e.g. add/remove of
15
+ * the whole entry).
16
+ */
17
+ export type JsonValuesOpClass = {
18
+ kind: "normal";
19
+ } | {
20
+ kind: "entry";
21
+ recordPath: string[];
22
+ entryKey: string;
23
+ subPath: string[];
24
+ };
25
+ /**
26
+ * Walks the serialized schema following the op path. When a `.jsonValues()`
27
+ * record is encountered, the next path segment is the entry key and everything
28
+ * after it lives inside the entry's `*.val.json` (so it does not touch the
29
+ * `.val.ts`). Returns `{ kind: "normal" }` when the op never enters a
30
+ * `.jsonValues()` record.
31
+ */
32
+ export declare function classifyJsonValuesOp(schema: SerializedSchema, opPath: string[]): JsonValuesOpClass;
33
+ /**
34
+ * Finds every `.jsonValues()` record in a module's schema that is NOT the
35
+ * module's root, returning the path to each within the module source.
36
+ *
37
+ * `.jsonValues()` is only supported on a module's ROOT record/router: the
38
+ * `/json` endpoint keys entries by a single string, the Studio substitutes
39
+ * loaded content at the top level of the module source, and
40
+ * `validateJsonValuesEntries` only visits a root record. A nested one would
41
+ * silently skip content validation and hang the Studio on a 404, so we reject
42
+ * it up front instead (see {@link ValOps.initSources}).
43
+ */
44
+ export declare function findNestedJsonValuesRecords(schema: SerializedSchema, path?: string[]): string[][];
45
+ /**
46
+ * Computes the `*.val.json` file path (relative to rootDir) and the `import(...)`
47
+ * path (relative to the module's directory) for a NEW `.jsonValues()` entry,
48
+ * following the locked filename convention: the file mirrors the entry key under
49
+ * a folder named after the `.val.ts` (its `.val.ts` suffix becomes the folder).
50
+ *
51
+ * For module `/app/support/[slug]/page.val.ts` and key `/support/faq`:
52
+ * - jsonPath: `/app/support/[slug]/page/support/faq.val.json`
53
+ * - importPath: `./page/support/faq.val.json`
54
+ */
55
+ export declare function getNewJsonEntryPaths(moduleFilePath: string, entryKey: string): result.Result<{
56
+ jsonPath: string;
57
+ importPath: string;
58
+ }, PatchSourceError>;
59
+ /**
60
+ * Rebases a patch op that targets a `.jsonValues()` entry's content so its paths
61
+ * are relative to the entry's `*.val.json` root (drops the record + entry-key
62
+ * prefix). Used to replay the op against the backing JSON file.
63
+ */
64
+ export declare function rebaseContentOp(op: Operation, prefixLen: number): result.Result<Operation, PatchError>;
65
+ /** The outcome of replaying pending patches onto one `.jsonValues()` entry. */
66
+ export type JsonEntryResolution = {
67
+ kind: "content";
68
+ content: JSONValue | null;
69
+ appliedPatchIds: PatchId[];
70
+ } | {
71
+ kind: "deleted";
72
+ appliedPatchIds: PatchId[];
73
+ } | {
74
+ kind: "error";
75
+ message: string;
76
+ patchId?: PatchId;
77
+ };
78
+ /**
79
+ * Replays the ops of `patches` that target ONE `.jsonValues()` entry onto its
80
+ * committed content, yielding the entry's draft content.
81
+ *
82
+ * This is the read-side counterpart to the commit flow in `ValOps.prepare`:
83
+ * both route ops with {@link classifyJsonValuesOp} and replay content sub-ops
84
+ * with {@link rebaseContentOp}, but this one produces a value instead of files
85
+ * and never touches the `.val.ts`.
86
+ *
87
+ * Root-only, like the rest of the `.jsonValues()` machinery: ops targeting a
88
+ * nested record are ignored (nested `.jsonValues()` is rejected at startup).
89
+ */
90
+ export declare function applyJsonValuesEntryPatches(args: {
91
+ serializedSchema: SerializedSchema | undefined;
92
+ entryKey: string;
93
+ /** `undefined` when the entry does not exist in the committed source. */
94
+ baseContent: JSONValue | undefined;
95
+ /** Ordered, already filtered to the entry's module. */
96
+ patches: {
97
+ patchId: PatchId;
98
+ patch: Patch;
99
+ }[];
100
+ }): JsonEntryResolution;
101
+ /**
102
+ * Resolves an EXISTING entry's `*.val.json` path (relative to rootDir) from the
103
+ * `import(...)` path recorded in the `.val.ts` thunk (from
104
+ * {@link analyzeJsonValuesEntries}). Existing files may have been hand-placed,
105
+ * so the import path is authoritative (hybrid authoring).
106
+ */
107
+ export declare function resolveExistingJsonPath(moduleFilePath: string, importPath: string): string;
@@ -1,4 +1,4 @@
1
- import { ModuleFilePath, PatchId } from "@valbuild/core";
1
+ import { PatchId } from "@valbuild/core";
2
2
  import { z } from "zod";
3
3
  import type { AuthorId, BaseSha } from "./ValOps.js";
4
4
  import { PatchLogEntry, PatchLogProblem } from "./patchLog.js";