@valbuild/core 0.58.0 → 0.60.0

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.
@@ -1,7 +1,7 @@
1
- import { ApiCommitResponse, ApiGetPatchResponse, ApiPostPatchResponse, ApiTreeResponse } from "./index.js";
1
+ import { ApiCommitResponse, ApiGetPatchResponse, ApiPostValidationErrorResponse, ApiPostPatchResponse, ApiPostValidationResponse, ApiTreeResponse, Json } from "./index.js";
2
2
  import { result } from "./fp/index.js";
3
- import { PatchJSON } from "./patch/index.js";
4
- import { ModuleId } from "./val/index.js";
3
+ import { Patch } from "./patch/index.js";
4
+ import { ModuleId, PatchId } from "./val/index.js";
5
5
  type FetchError = {
6
6
  message: string;
7
7
  statusCode?: number;
@@ -16,8 +16,9 @@ export declare class ValApi {
16
16
  patchIds?: string[];
17
17
  headers?: Record<string, string> | undefined;
18
18
  }): Promise<result.Result<ApiGetPatchResponse, FetchError>>;
19
+ deletePatches(ids: string[], headers?: Record<string, string>): Promise<result.Result<Json, FetchError>>;
19
20
  getEditUrl(): string;
20
- postPatches(moduleId: ModuleId, patches: PatchJSON, headers?: Record<string, string> | undefined): Promise<result.Result<ApiPostPatchResponse, FetchError>>;
21
+ postPatches(moduleId: ModuleId, patches: Patch, headers?: Record<string, string> | undefined): Promise<result.Result<ApiPostPatchResponse, FetchError>>;
21
22
  getSession(): Promise<result.Result<{
22
23
  mode: "proxy" | "local";
23
24
  member_role: "owner" | "developer" | "editor";
@@ -33,8 +34,12 @@ export declare class ValApi {
33
34
  headers?: Record<string, string> | undefined;
34
35
  }): Promise<result.Result<ApiTreeResponse, FetchError>>;
35
36
  postCommit({ patches, headers, }: {
36
- patches?: Record<ModuleId, string[]>;
37
+ patches?: Record<ModuleId, PatchId[]>;
37
38
  headers?: Record<string, string> | undefined;
38
- }): Promise<result.Result<ApiCommitResponse, FetchError>>;
39
+ }): Promise<result.Result<ApiCommitResponse, FetchError | ApiPostValidationErrorResponse>>;
40
+ postValidate({ patches, headers, }: {
41
+ patches?: Record<ModuleId, PatchId[]>;
42
+ headers?: Record<string, string> | undefined;
43
+ }): Promise<result.Result<ApiPostValidationResponse | ApiPostValidationErrorResponse, FetchError>>;
39
44
  }
40
45
  export {};
@@ -11,7 +11,7 @@ export type { RawString } from "./schema/string.js";
11
11
  export type { ImageSource } from "./source/image.js";
12
12
  export { RT_IMAGE_TAG } from "./source/richtext.js";
13
13
  export type { AnyRichTextOptions, Bold, Classes, HeadingNode, ImageNode, Italic, LineThrough, ListItemNode, LinkNode, OrderedListNode, ParagraphNode, BrNode, RichText, RichTextNode, RichTextOptions, RichTextSource, RootNode, SpanNode, UnorderedListNode, } from "./source/richtext.js";
14
- export { type Val, type SerializedVal, type ModuleId, type ModulePath, type SourcePath, type JsonOfSource, } from "./val/index.js";
14
+ export { type Val, type SerializedVal, type ModuleId, type PatchId, type ModulePath, type SourcePath, type JsonOfSource, } from "./val/index.js";
15
15
  export type { Json, JsonPrimitive, JsonArray, JsonObject } from "./Json.js";
16
16
  export type { ValidationError, ValidationErrors, } from "./schema/validation/ValidationError.js";
17
17
  import type { ValidationErrors } from "./schema/validation/ValidationError.js";
@@ -23,15 +23,14 @@ export { derefPatch } from "./patch/deref.js";
23
23
  export { type SelectorSource, type SelectorOf, GenericSelector, } from "./selector/index.js";
24
24
  import { getSource, resolvePath, splitModuleIdAndModulePath } from "./module.js";
25
25
  import { getSchema } from "./selector/index.js";
26
- import { ModuleId, ModulePath, getValPath, isVal } from "./val/index.js";
26
+ import { ModuleId, ModulePath, PatchId, getValPath, isVal } from "./val/index.js";
27
27
  import { convertFileSource } from "./schema/file.js";
28
28
  import { createValPathOfItem } from "./selector/SelectorProxy.js";
29
29
  import { getVal } from "./future/fetchVal.js";
30
30
  import type { Json } from "./Json.js";
31
31
  import { SerializedSchema } from "./schema/index.js";
32
- import { PatchJSON } from "./patch/index.js";
32
+ import { Operation, Patch } from "./patch/index.js";
33
33
  import { initSchema } from "./initSchema.js";
34
- export { ValApi } from "./ValApi.js";
35
34
  export { type SerializedArraySchema, ArraySchema } from "./schema/array.js";
36
35
  export { type SerializedObjectSchema, ObjectSchema } from "./schema/object.js";
37
36
  export { type SerializedRecordSchema, RecordSchema } from "./schema/record.js";
@@ -43,10 +42,13 @@ export { type SerializedFileSchema, FileSchema } from "./schema/file.js";
43
42
  export { type SerializedRichTextSchema, RichTextSchema, } from "./schema/richtext.js";
44
43
  export { type SerializedUnionSchema, UnionSchema } from "./schema/union.js";
45
44
  export { type SerializedLiteralSchema, LiteralSchema } from "./schema/literal.js";
45
+ export { deserializeSchema } from "./schema/deserialize.js";
46
+ export { ValApi } from "./ValApi.js";
46
47
  export type ApiCommitResponse = {
48
+ validationErrors: false;
47
49
  modules: Record<ModuleId, {
48
50
  patches: {
49
- applied: string[];
51
+ applied: PatchId[];
50
52
  };
51
53
  }>;
52
54
  git: {
@@ -62,8 +64,8 @@ export type ApiTreeResponse = {
62
64
  modules: Record<ModuleId, {
63
65
  schema?: SerializedSchema;
64
66
  patches?: {
65
- applied: string[];
66
- failed?: string[];
67
+ applied: PatchId[];
68
+ failed?: PatchId[];
67
69
  };
68
70
  source?: Json;
69
71
  errors?: false | {
@@ -78,13 +80,46 @@ export type ApiTreeResponse = {
78
80
  }>;
79
81
  };
80
82
  export type ApiGetPatchResponse = Record<ModuleId, {
81
- patch: PatchJSON;
82
- patch_id: string;
83
- commit_sha: string;
84
- author: string;
83
+ patch: Patch;
84
+ patch_id: PatchId;
85
85
  created_at: string;
86
+ commit_sha?: string;
87
+ author?: string;
86
88
  }[]>;
87
- export type ApiPostPatchResponse = Record<ModuleId, string[]>;
89
+ export type ApiDeletePatchResponse = PatchId[];
90
+ export type ApiPostPatchResponse = Record<ModuleId, {
91
+ patch_id: PatchId;
92
+ }>;
93
+ export type ApiPostValidationResponse = {
94
+ validationErrors: false;
95
+ modules: Record<ModuleId, {
96
+ patches: {
97
+ applied: PatchId[];
98
+ };
99
+ }>;
100
+ };
101
+ export declare const FATAL_ERROR_TYPES: readonly ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
102
+ export type FatalErrorType = (typeof FATAL_ERROR_TYPES)[number];
103
+ export type ApiPostValidationErrorResponse = {
104
+ modules: Record<ModuleId, {
105
+ patches: {
106
+ applied: PatchId[];
107
+ failed?: PatchId[];
108
+ };
109
+ }>;
110
+ validationErrors: Record<ModuleId, {
111
+ source?: Json;
112
+ errors: {
113
+ invalidModuleId?: ModuleId;
114
+ validation?: ValidationErrors;
115
+ fatal?: {
116
+ message: string;
117
+ stack?: string;
118
+ type?: FatalErrorType;
119
+ }[];
120
+ };
121
+ }>;
122
+ };
88
123
  declare const Internal: {
89
124
  convertFileSource: typeof convertFileSource;
90
125
  getSchema: typeof getSchema;
@@ -97,7 +132,16 @@ declare const Internal: {
97
132
  createValPathOfItem: typeof createValPathOfItem;
98
133
  getSHA256Hash: (bits: Uint8Array) => string;
99
134
  initSchema: typeof initSchema;
135
+ notFileOp: (op: Operation) => boolean;
136
+ isFileOp: (op: Operation) => op is {
137
+ op: "file";
138
+ path: string[];
139
+ filePath: string;
140
+ value: string;
141
+ };
100
142
  createPatchJSONPath: (modulePath: ModulePath) => string;
143
+ createPatchPath: (modulePath: ModulePath) => string[];
144
+ patchPathToModulePath: (patchPath: string[]) => ModulePath;
101
145
  VAL_ENABLE_COOKIE_NAME: "val_enable";
102
146
  VAL_STATE_COOKIE: "val_state";
103
147
  VAL_SESSION_COOKIE: "val_session";
@@ -17,10 +17,10 @@ export type ValConstructor = {
17
17
  unstable_getPath: typeof getPath;
18
18
  };
19
19
  export type ValConfig = {
20
- valCloud?: string;
20
+ remote?: string;
21
+ root?: string;
21
22
  gitCommit?: string;
22
23
  gitBranch?: string;
23
- valConfigPath?: string;
24
24
  };
25
25
  export type InitVal = {
26
26
  c: ContentConstructor;
@@ -28,4 +28,4 @@ export type InitVal = {
28
28
  s: InitSchema;
29
29
  config: ValConfig;
30
30
  };
31
- export declare const initVal: () => InitVal;
31
+ export declare const initVal: (config?: ValConfig) => InitVal;
@@ -0,0 +1,3 @@
1
+ import { SerializedSchema, Schema } from "./index.js";
2
+ import { SelectorSource } from "../selector/index.js";
3
+ export declare function deserializeSchema(serialized: SerializedSchema): Schema<SelectorSource>;
@@ -6,15 +6,17 @@ import { SourcePath } from "../val/index.js";
6
6
  import { ValidationErrors } from "./validation/ValidationError.js";
7
7
  export type SerializedKeyOfSchema = {
8
8
  type: "keyOf";
9
- selector: SourcePath;
9
+ path: SourcePath;
10
+ schema: SerializedSchema;
10
11
  opt: boolean;
11
12
  values: "string" | "number" | string[];
12
13
  };
13
14
  type KeyOfSelector<Sel extends GenericSelector<SourceArray | SourceObject>> = Sel extends GenericSelector<infer S> ? S extends readonly any[] ? number : S extends SourceObject ? keyof S : S extends Record<string, any> ? string : never : never;
14
15
  export declare class KeyOfSchema<Sel extends GenericSelector<SourceArray | SourceObject>> extends Schema<KeyOfSelector<Sel>> {
15
- readonly selector: Sel;
16
+ readonly schema?: SerializedSchema | undefined;
17
+ readonly sourcePath?: SourcePath | undefined;
16
18
  readonly opt: boolean;
17
- constructor(selector: Sel, opt?: boolean);
19
+ constructor(schema?: SerializedSchema | undefined, sourcePath?: SourcePath | undefined, opt?: boolean);
18
20
  validate(path: SourcePath, src: KeyOfSelector<Sel>): ValidationErrors;
19
21
  assert(src: KeyOfSelector<Sel>): boolean;
20
22
  optional(): Schema<KeyOfSelector<Sel> | null>;
@@ -5,7 +5,7 @@ import { SourcePath } from "../val/index.js";
5
5
  import { ValidationErrors } from "./validation/ValidationError.js";
6
6
  export type SerializedUnionSchema = {
7
7
  type: "union";
8
- key?: string;
8
+ key: string | SerializedSchema;
9
9
  items: SerializedSchema[];
10
10
  opt: boolean;
11
11
  };
@@ -17,7 +17,7 @@ export type SourceObject = {
17
17
  export type SourceArray = readonly Source[];
18
18
  export type SourcePrimitive = string | number | boolean | null;
19
19
  export declare const VAL_EXTENSION: "_type";
20
- export declare function getValExtension(source: Source): false | "" | 0 | "remote" | "file" | "richtext" | "i18n" | null | undefined;
20
+ export declare function getValExtension(source: Source): false | "" | 0 | "file" | "remote" | "richtext" | "i18n" | null | undefined;
21
21
  /**
22
22
  * A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
23
23
  *
@@ -50,5 +50,8 @@ export type ModulePath = string & {
50
50
  export type ModuleId = string & {
51
51
  [brand]: "ModuleId";
52
52
  };
53
+ export type PatchId = string & {
54
+ [brand]: "PatchId";
55
+ };
53
56
  export declare function getValPath(valOrSelector: Val<Json> | Selector<Source>): SourcePath | undefined;
54
57
  export {};
@@ -1,4 +1,4 @@
1
- import { s as _objectSpread2, j as _slicedToArray, c as _createClass, a as _classCallCheck, t as Sym, C as Call, u as StringLiteral, v as StringTemplate, e as _typeof, m as isSerializedVal, F as FILE_REF_PROP, V as VAL_EXTENSION, n as convertFileSource, d as _defineProperty, E as Expr, S as Schema, w as _toConsumableArray, N as NilSym } from './index-b88673ad.esm.js';
1
+ import { o as _objectSpread2, j as _slicedToArray, c as _createClass, a as _classCallCheck, t as Sym, C as Call, u as StringLiteral, v as StringTemplate, e as _typeof, m as isSerializedVal, F as FILE_REF_PROP, V as VAL_EXTENSION, p as convertFileSource, d as _defineProperty, E as Expr, S as Schema, w as _toConsumableArray, N as NilSym } from './index-c6d9700a.esm.js';
2
2
  import { i as isErr, e as err, o as ok, a as isOk } from './result-b96df128.esm.js';
3
3
 
4
4
  var WHITE_SPACE = ["\n", "\r", "\t", " "];
@@ -536,4 +536,4 @@ function getValPath(valOrSelector) {
536
536
  return valOrSelector[Path];
537
537
  }
538
538
 
539
- export { Call as C, Expr as E, FILE_REF_PROP as F, GetSchema as G, NilSym as N, Path as P, Schema as S, VAL_EXTENSION as V, _inherits as _, _classCallCheck as a, _callSuper as b, _createClass as c, _defineProperty as d, _typeof as e, file as f, getValPath as g, FILE_REF_SUBTYPE_TAG as h, file$1 as i, _slicedToArray as j, isFile as k, GetSource as l, isSerializedVal as m, convertFileSource as n, getSchema as o, isVal as p, GenericSelector as q, FileSchema as r, _objectSpread2 as s, Sym as t, StringLiteral as u, StringTemplate as v, _toConsumableArray as w };
539
+ export { Call as C, Expr as E, FILE_REF_PROP as F, GetSchema as G, NilSym as N, Path as P, Schema as S, VAL_EXTENSION as V, _inherits as _, _classCallCheck as a, _callSuper as b, _createClass as c, _defineProperty as d, _typeof as e, file as f, getValPath as g, FILE_REF_SUBTYPE_TAG as h, file$1 as i, _slicedToArray as j, isFile as k, GetSource as l, isSerializedVal as m, FileSchema as n, _objectSpread2 as o, convertFileSource as p, getSchema as q, isVal as r, GenericSelector as s, Sym as t, StringLiteral as u, StringTemplate as v, _toConsumableArray as w };
@@ -1,4 +1,4 @@
1
- import { e as _typeof, m as isSerializedVal, F as FILE_REF_PROP, V as VAL_EXTENSION, n as convertFileSource, d as _defineProperty, G as GetSchema, l as GetSource, E as Expr, P as Path, S as Schema, _ as _inherits, a as _classCallCheck, b as _callSuper, c as _createClass, j as _slicedToArray, s as _objectSpread2, w as _toConsumableArray } from './index-b88673ad.esm.js';
1
+ import { e as _typeof, m as isSerializedVal, F as FILE_REF_PROP, V as VAL_EXTENSION, p as convertFileSource, d as _defineProperty, G as GetSchema, l as GetSource, E as Expr, P as Path, S as Schema, _ as _inherits, a as _classCallCheck, b as _callSuper, c as _createClass, j as _slicedToArray, o as _objectSpread2, w as _toConsumableArray } from './index-c6d9700a.esm.js';
2
2
  import { _ as _createForOfIteratorHelper } from './result-b96df128.esm.js';
3
3
 
4
4
  function hasOwn(obj, prop) {
@@ -132,7 +132,7 @@ function createValPathOfItem(arrayPath, prop) {
132
132
  if (_typeof(prop) === "symbol") {
133
133
  throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
134
134
  }
135
- return arrayPath && "".concat(arrayPath, ".").concat(JSON.stringify(prop));
135
+ return arrayPath !== undefined ? "".concat(arrayPath, ".").concat(JSON.stringify(prop)) : undefined;
136
136
  }
137
137
 
138
138
  // TODO: could we do .val on the objects instead?
@@ -564,6 +564,7 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
564
564
  }
565
565
  return {
566
566
  type: "union",
567
+ key: this.key.serialize(),
567
568
  items: this.items.map(function (o) {
568
569
  return o.serialize();
569
570
  }),
@@ -927,7 +928,7 @@ function resolvePath(path, valModule, schema) {
927
928
  };
928
929
  } else if (isUnionSchema(resolvedSchema)) {
929
930
  var _key = resolvedSchema.key;
930
- if (!_key) {
931
+ if (typeof _key !== "string") {
931
932
  return {
932
933
  v: {
933
934
  path: origParts.map(function (p) {
@@ -1040,4 +1041,4 @@ var PatchError = /*#__PURE__*/_createClass(function PatchError(message) {
1040
1041
  * NOTE: MAY mutate the input document.
1041
1042
  */
1042
1043
 
1043
- export { ArraySchema as A, ImageSchema as I, LiteralSchema as L, ObjectSchema as O, PatchError as P, RecordSchema as R, UnionSchema as U, array as a, record as b, createValPathOfItem as c, define as d, isSelector as e, resolvePath as f, getSource as g, RichTextSchema as h, image as i, literal as l, newSelectorProxy as n, object as o, richtext as r, splitModuleIdAndModulePath as s, union as u };
1044
+ export { ArraySchema as A, ImageSchema as I, LiteralSchema as L, ObjectSchema as O, PatchError as P, RecordSchema as R, UnionSchema as U, array as a, record as b, createValPathOfItem as c, define as d, isSelector as e, RichTextSchema as f, getSource as g, resolvePath as h, image as i, literal as l, newSelectorProxy as n, object as o, parsePath as p, richtext as r, splitModuleIdAndModulePath as s, union as u };
@@ -134,7 +134,7 @@ function createValPathOfItem(arrayPath, prop) {
134
134
  if (index._typeof(prop) === "symbol") {
135
135
  throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
136
136
  }
137
- return arrayPath && "".concat(arrayPath, ".").concat(JSON.stringify(prop));
137
+ return arrayPath !== undefined ? "".concat(arrayPath, ".").concat(JSON.stringify(prop)) : undefined;
138
138
  }
139
139
 
140
140
  // TODO: could we do .val on the objects instead?
@@ -566,6 +566,7 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
566
566
  }
567
567
  return {
568
568
  type: "union",
569
+ key: this.key.serialize(),
569
570
  items: this.items.map(function (o) {
570
571
  return o.serialize();
571
572
  }),
@@ -929,7 +930,7 @@ function resolvePath(path, valModule, schema) {
929
930
  };
930
931
  } else if (isUnionSchema(resolvedSchema)) {
931
932
  var _key = resolvedSchema.key;
932
- if (!_key) {
933
+ if (typeof _key !== "string") {
933
934
  return {
934
935
  v: {
935
936
  path: origParts.map(function (p) {
@@ -1059,6 +1060,7 @@ exports.isSelector = isSelector;
1059
1060
  exports.literal = literal;
1060
1061
  exports.newSelectorProxy = newSelectorProxy;
1061
1062
  exports.object = object;
1063
+ exports.parsePath = parsePath;
1062
1064
  exports.record = record;
1063
1065
  exports.resolvePath = resolvePath;
1064
1066
  exports.richtext = richtext;
@@ -134,7 +134,7 @@ function createValPathOfItem(arrayPath, prop) {
134
134
  if (index._typeof(prop) === "symbol") {
135
135
  throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
136
136
  }
137
- return arrayPath && "".concat(arrayPath, ".").concat(JSON.stringify(prop));
137
+ return arrayPath !== undefined ? "".concat(arrayPath, ".").concat(JSON.stringify(prop)) : undefined;
138
138
  }
139
139
 
140
140
  // TODO: could we do .val on the objects instead?
@@ -566,6 +566,7 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
566
566
  }
567
567
  return {
568
568
  type: "union",
569
+ key: this.key.serialize(),
569
570
  items: this.items.map(function (o) {
570
571
  return o.serialize();
571
572
  }),
@@ -929,7 +930,7 @@ function resolvePath(path, valModule, schema) {
929
930
  };
930
931
  } else if (isUnionSchema(resolvedSchema)) {
931
932
  var _key = resolvedSchema.key;
932
- if (!_key) {
933
+ if (typeof _key !== "string") {
933
934
  return {
934
935
  v: {
935
936
  path: origParts.map(function (p) {
@@ -1059,6 +1060,7 @@ exports.isSelector = isSelector;
1059
1060
  exports.literal = literal;
1060
1061
  exports.newSelectorProxy = newSelectorProxy;
1061
1062
  exports.object = object;
1063
+ exports.parsePath = parsePath;
1062
1064
  exports.record = record;
1063
1065
  exports.resolvePath = resolvePath;
1064
1066
  exports.richtext = richtext;