@valbuild/core 0.21.1 → 0.22.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.
Files changed (34) hide show
  1. package/dist/declarations/src/ValApi.d.ts +2 -1
  2. package/dist/declarations/src/index.d.ts +21 -3
  3. package/dist/declarations/src/module.d.ts +11 -5
  4. package/dist/declarations/src/patch/deref.d.ts +0 -3
  5. package/dist/declarations/src/patch/operation.d.ts +2 -0
  6. package/dist/declarations/src/schema/string.d.ts +5 -1
  7. package/dist/{index-75b79c89.cjs.prod.js → index-30eee5ec.cjs.prod.js} +47 -43
  8. package/dist/{index-067cff4a.cjs.prod.js → index-425d164d.cjs.prod.js} +1 -1
  9. package/dist/{index-31991dd7.cjs.dev.js → index-43369070.cjs.dev.js} +47 -43
  10. package/dist/{index-4bb14a92.esm.js → index-499b9e87.esm.js} +47 -43
  11. package/dist/{index-d17f9503.cjs.dev.js → index-a0f36fe3.cjs.dev.js} +1 -1
  12. package/dist/{index-870205b5.esm.js → index-f0475164.esm.js} +1 -1
  13. package/dist/{ops-9b396073.esm.js → ops-1225f750.esm.js} +5 -2
  14. package/dist/{ops-0f7617a0.cjs.dev.js → ops-558f07b7.cjs.dev.js} +5 -2
  15. package/dist/{ops-451ffb3f.cjs.prod.js → ops-b263963e.cjs.prod.js} +5 -2
  16. package/dist/valbuild-core.cjs.dev.js +251 -240
  17. package/dist/valbuild-core.cjs.prod.js +251 -240
  18. package/dist/valbuild-core.esm.js +252 -241
  19. package/expr/dist/valbuild-core-expr.cjs.dev.js +2 -2
  20. package/expr/dist/valbuild-core-expr.cjs.prod.js +2 -2
  21. package/expr/dist/valbuild-core-expr.esm.js +2 -2
  22. package/package.json +1 -1
  23. package/patch/dist/valbuild-core-patch.cjs.dev.js +13 -3
  24. package/patch/dist/valbuild-core-patch.cjs.prod.js +13 -3
  25. package/patch/dist/valbuild-core-patch.esm.js +14 -4
  26. package/src/ValApi.ts +9 -13
  27. package/src/index.ts +23 -3
  28. package/src/module.ts +40 -14
  29. package/src/patch/deref.test.ts +130 -132
  30. package/src/patch/deref.ts +12 -17
  31. package/src/patch/operation.ts +2 -0
  32. package/src/patch/parse.ts +15 -1
  33. package/src/schema/image.ts +5 -3
  34. package/src/schema/string.ts +27 -2
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('../../dist/index-d17f9503.cjs.dev.js');
6
- var index = require('../../dist/index-31991dd7.cjs.dev.js');
5
+ var expr_dist_valbuildCoreExpr = require('../../dist/index-a0f36fe3.cjs.dev.js');
6
+ var index = require('../../dist/index-43369070.cjs.dev.js');
7
7
  require('../../dist/result-48320acd.cjs.dev.js');
8
8
 
9
9
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('../../dist/index-067cff4a.cjs.prod.js');
6
- var index = require('../../dist/index-75b79c89.cjs.prod.js');
5
+ var expr_dist_valbuildCoreExpr = require('../../dist/index-425d164d.cjs.prod.js');
6
+ var index = require('../../dist/index-30eee5ec.cjs.prod.js');
7
7
  require('../../dist/result-26f67b40.cjs.prod.js');
8
8
 
9
9
 
@@ -1,3 +1,3 @@
1
- export { e as evaluate, p as parse } from '../../dist/index-870205b5.esm.js';
2
- export { C as Call, E as Expr, N as NilSym, s as StringLiteral, t as StringTemplate, r as Sym } from '../../dist/index-4bb14a92.esm.js';
1
+ export { e as evaluate, p as parse } from '../../dist/index-f0475164.esm.js';
2
+ export { C as Call, E as Expr, N as NilSym, s as StringLiteral, t as StringTemplate, r as Sym } from '../../dist/index-499b9e87.esm.js';
3
3
  import '../../dist/result-b96df128.esm.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/core",
3
- "version": "0.21.1",
3
+ "version": "0.22.0",
4
4
  "private": false,
5
5
  "description": "Val - supercharged hard-coded content",
6
6
  "scripts": {
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-31991dd7.cjs.dev.js');
5
+ var index = require('../../dist/index-43369070.cjs.dev.js');
6
6
  var result = require('../../dist/result-48320acd.cjs.dev.js');
7
7
  var util = require('../../dist/util-b213092b.cjs.dev.js');
8
- var ops = require('../../dist/ops-0f7617a0.cjs.dev.js');
8
+ var ops = require('../../dist/ops-558f07b7.cjs.dev.js');
9
9
 
10
10
  function isNotRoot(path) {
11
11
  return result.isNonEmpty(path);
@@ -350,7 +350,6 @@ function isProperPathPrefix(prefix, path) {
350
350
  function parseOperation(operation) {
351
351
  var path = parseJSONPointer(operation.path);
352
352
  switch (operation.op) {
353
- case "file":
354
353
  case "add":
355
354
  case "replace":
356
355
  case "test":
@@ -363,6 +362,17 @@ function parseOperation(operation) {
363
362
  value: operation.value
364
363
  };
365
364
  }));
365
+ case "file":
366
+ return util.pipe(path, result.mapErr(function (error) {
367
+ return [createIssueAtPath(["path"])(error)];
368
+ }), result.map(function (path) {
369
+ return {
370
+ op: operation.op,
371
+ path: path,
372
+ filePath: operation.filePath,
373
+ value: operation.value
374
+ };
375
+ }));
366
376
  case "remove":
367
377
  return util.pipe(path, result.filterOrElse(result.isNonEmpty, function () {
368
378
  return "Cannot remove root";
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-75b79c89.cjs.prod.js');
5
+ var index = require('../../dist/index-30eee5ec.cjs.prod.js');
6
6
  var result = require('../../dist/result-26f67b40.cjs.prod.js');
7
7
  var util = require('../../dist/util-030d8a1f.cjs.prod.js');
8
- var ops = require('../../dist/ops-451ffb3f.cjs.prod.js');
8
+ var ops = require('../../dist/ops-b263963e.cjs.prod.js');
9
9
 
10
10
  function isNotRoot(path) {
11
11
  return result.isNonEmpty(path);
@@ -350,7 +350,6 @@ function isProperPathPrefix(prefix, path) {
350
350
  function parseOperation(operation) {
351
351
  var path = parseJSONPointer(operation.path);
352
352
  switch (operation.op) {
353
- case "file":
354
353
  case "add":
355
354
  case "replace":
356
355
  case "test":
@@ -363,6 +362,17 @@ function parseOperation(operation) {
363
362
  value: operation.value
364
363
  };
365
364
  }));
365
+ case "file":
366
+ return util.pipe(path, result.mapErr(function (error) {
367
+ return [createIssueAtPath(["path"])(error)];
368
+ }), result.map(function (path) {
369
+ return {
370
+ op: operation.op,
371
+ path: path,
372
+ filePath: operation.filePath,
373
+ value: operation.value
374
+ };
375
+ }));
366
376
  case "remove":
367
377
  return util.pipe(path, result.filterOrElse(result.isNonEmpty, function () {
368
378
  return "Cannot remove root";
@@ -1,8 +1,8 @@
1
- import { e as _typeof, j as _slicedToArray, c as _createClass, b as _classCallCheck, u as _toConsumableArray } from '../../dist/index-4bb14a92.esm.js';
1
+ import { e as _typeof, j as _slicedToArray, c as _createClass, b as _classCallCheck, u as _toConsumableArray } from '../../dist/index-499b9e87.esm.js';
2
2
  import { f as isNonEmpty, e as err, o as ok, m as map, g as flatMap, i as isErr, h as flatMapReduce, j as filterOrElse, k as mapErr, l as map$1, n as all, p as flatten, q as allT } from '../../dist/result-b96df128.esm.js';
3
3
  import { p as pipe } from '../../dist/util-18613e99.esm.js';
4
- import { P as PatchError, s as splitModuleIdAndModulePath } from '../../dist/ops-9b396073.esm.js';
5
- export { P as PatchError } from '../../dist/ops-9b396073.esm.js';
4
+ import { P as PatchError, s as splitModuleIdAndModulePath } from '../../dist/ops-1225f750.esm.js';
5
+ export { P as PatchError } from '../../dist/ops-1225f750.esm.js';
6
6
 
7
7
  function isNotRoot(path) {
8
8
  return isNonEmpty(path);
@@ -347,7 +347,6 @@ function isProperPathPrefix(prefix, path) {
347
347
  function parseOperation(operation) {
348
348
  var path = parseJSONPointer(operation.path);
349
349
  switch (operation.op) {
350
- case "file":
351
350
  case "add":
352
351
  case "replace":
353
352
  case "test":
@@ -360,6 +359,17 @@ function parseOperation(operation) {
360
359
  value: operation.value
361
360
  };
362
361
  }));
362
+ case "file":
363
+ return pipe(path, mapErr(function (error) {
364
+ return [createIssueAtPath(["path"])(error)];
365
+ }), map(function (path) {
366
+ return {
367
+ op: operation.op,
368
+ path: path,
369
+ filePath: operation.filePath,
370
+ value: operation.value
371
+ };
372
+ }));
363
373
  case "remove":
364
374
  return pipe(path, filterOrElse(isNonEmpty, function () {
365
375
  return "Cannot remove root";
package/src/ValApi.ts CHANGED
@@ -12,34 +12,30 @@ export class ValApi {
12
12
  getDisableUrl() {
13
13
  return `${this.host}/disable`;
14
14
  }
15
+ getEditUrl() {
16
+ return `${this.host}/static/edit`;
17
+ }
15
18
 
16
19
  postPatches(
17
20
  moduleId: ModuleId,
18
21
  patches: PatchJSON,
19
- commit?: string,
20
22
  headers?: Record<string, string> | undefined
21
23
  ) {
22
- let params = "";
23
- if (commit) {
24
- const p = new URLSearchParams();
25
- p.set("commit", commit);
26
- params = `?${p.toString()}`;
27
- }
28
- return fetch(`${this.host}/patches/~${moduleId}${params}`, {
24
+ return fetch(`${this.host}/patches/~`, {
29
25
  headers: headers || {
30
26
  "Content-Type": "application/json",
31
27
  },
32
28
  method: "POST",
33
- body: JSON.stringify(patches),
34
- }).then(parse<ApiPatchResponse>);
29
+ body: JSON.stringify({ [moduleId]: patches }),
30
+ }).then((res) => parse<ApiPatchResponse>(res));
35
31
  }
36
32
 
37
33
  getSession() {
38
- return fetch(`${this.host}/session`).then(
34
+ return fetch(`${this.host}/session`).then((res) =>
39
35
  parse<{
40
36
  mode: "proxy" | "local";
41
37
  member_role: "owner" | "developer" | "editor";
42
- }>
38
+ }>(res)
43
39
  );
44
40
  }
45
41
 
@@ -62,7 +58,7 @@ export class ValApi {
62
58
  params.set("source", includeSource.toString());
63
59
  return fetch(`${this.host}/tree/~${treePath}?${params.toString()}`, {
64
60
  headers,
65
- }).then(parse<ApiTreeResponse>);
61
+ }).then((res) => parse<ApiTreeResponse>(res));
66
62
  }
67
63
  }
68
64
 
package/src/index.ts CHANGED
@@ -35,11 +35,12 @@ export {
35
35
  type SourcePath,
36
36
  type JsonOfSource,
37
37
  } from "./val";
38
- export type { Json, JsonPrimitive } from "./Json";
38
+ export type { Json, JsonPrimitive, JsonArray, JsonObject } from "./Json";
39
39
  export type {
40
- ValidationErrors,
41
40
  ValidationError,
41
+ ValidationErrors,
42
42
  } from "./schema/validation/ValidationError";
43
+ import type { ValidationErrors } from "./schema/validation/ValidationError";
43
44
  export type { ValidationFix } from "./schema/validation/ValidationFix";
44
45
  export * as expr from "./expr/";
45
46
  export { FILE_REF_PROP } from "./source/file";
@@ -56,10 +57,18 @@ import { ModuleId, ModulePath, getValPath, isVal } from "./val";
56
57
  import { convertFileSource } from "./schema/image";
57
58
  import { createValPathOfItem } from "./selector/SelectorProxy";
58
59
  import { getVal } from "./future/fetchVal";
59
- import { Json } from "./Json";
60
+ import type { Json } from "./Json";
60
61
  import { SerializedSchema } from "./schema";
61
62
  import { getSHA256Hash } from "./getSha256";
62
63
  export { ValApi } from "./ValApi";
64
+ export type { SerializedArraySchema } from "./schema/array";
65
+ export type { SerializedObjectSchema } from "./schema/object";
66
+ export type { SerializedRecordSchema } from "./schema/record";
67
+ export type { SerializedStringSchema } from "./schema/string";
68
+ export type { SerializedNumberSchema } from "./schema/number";
69
+ export type { SerializedBooleanSchema } from "./schema/boolean";
70
+ export type { SerializedImageSchema } from "./schema/image";
71
+ export type { SerializedRichTextSchema } from "./schema/richtext";
63
72
 
64
73
  export type ApiTreeResponse = {
65
74
  git: {
@@ -75,6 +84,17 @@ export type ApiTreeResponse = {
75
84
  failed?: string[];
76
85
  };
77
86
  source?: Json;
87
+ errors?:
88
+ | false
89
+ | {
90
+ invalidModuleId?: ModuleId;
91
+ validation?: ValidationErrors;
92
+ fatal?: {
93
+ message: string;
94
+ stack?: string;
95
+ type?: string;
96
+ }[];
97
+ };
78
98
  }
79
99
  >;
80
100
  };
package/src/module.ts CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  import { FileSource } from "./source/file";
24
24
  import { AnyRichTextOptions, RichText } from "./source/richtext";
25
25
  import { RecordSchema, SerializedRecordSchema } from "./schema/record";
26
+ import { RawString } from "./schema/string";
26
27
 
27
28
  const brand = Symbol("ValModule");
28
29
  export type ValModule<T extends SelectorSource> = SelectorOf<T> &
@@ -35,13 +36,26 @@ export type ValModuleBrand = {
35
36
  export type TypeOfValModule<T extends ValModule<SelectorSource>> =
36
37
  T extends GenericSelector<infer S> ? S : never;
37
38
 
39
+ type ReplaceRawStringWithString<T extends SelectorSource> =
40
+ SelectorSource extends T
41
+ ? T
42
+ : T extends RawString
43
+ ? string
44
+ : T extends { [key in string]: SelectorSource }
45
+ ? {
46
+ [key in keyof T]: ReplaceRawStringWithString<T[key]>;
47
+ }
48
+ : T extends SelectorSource[]
49
+ ? ReplaceRawStringWithString<T[number]>[]
50
+ : T;
51
+
38
52
  export function content<T extends Schema<SelectorSource>>(
39
53
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
40
54
  id: string,
41
55
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
42
56
  schema: T,
43
57
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
44
- source: SchemaTypeOf<T>
58
+ source: ReplaceRawStringWithString<SchemaTypeOf<T>>
45
59
  ): ValModule<SchemaTypeOf<T>> {
46
60
  return {
47
61
  [GetSource]: source,
@@ -62,6 +76,9 @@ export function getSource(valModule: ValModule<SelectorSource>): Source {
62
76
  export function splitModuleIdAndModulePath(
63
77
  path: SourcePath
64
78
  ): [moduleId: ModuleId, path: ModulePath] {
79
+ if (path.indexOf(".") === -1) {
80
+ return [path as unknown as ModuleId, "" as ModulePath];
81
+ }
65
82
  return [
66
83
  path.slice(0, path.indexOf(".")) as ModuleId,
67
84
  path.slice(path.indexOf(".") + 1) as ModulePath,
@@ -166,14 +183,21 @@ function isImageSchema(
166
183
  // );
167
184
  // }
168
185
 
169
- export function resolvePath(
186
+ export function resolvePath<
187
+ Src extends ValModule<SelectorSource> | Source,
188
+ Sch extends Schema<SelectorSource> | SerializedSchema
189
+ >(
170
190
  path: ModulePath,
171
- valModule: ValModule<SelectorSource> | Source,
172
- schema: Schema<SelectorSource> | SerializedSchema
173
- ) {
191
+ valModule: Src,
192
+ schema: Sch
193
+ ): {
194
+ path: SourcePath;
195
+ schema: Sch;
196
+ source: Src;
197
+ } {
174
198
  const parts = parsePath(path);
175
199
  const origParts = [...parts];
176
- let resolvedSchema = schema;
200
+ let resolvedSchema: Schema<SelectorSource> | SerializedSchema = schema;
177
201
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
178
202
  let resolvedSource: any /* TODO: any */ = valModule;
179
203
  while (parts.length > 0) {
@@ -184,7 +208,9 @@ export function resolvePath(
184
208
  if (isArraySchema(resolvedSchema)) {
185
209
  if (Number.isNaN(Number(part))) {
186
210
  throw Error(
187
- `Invalid path: array schema ${resolvedSchema} must have ${part} a number as path`
211
+ `Invalid path: array schema ${JSON.stringify(
212
+ resolvedSchema
213
+ )} must have a number as path, but got ${part}. Path: ${path}`
188
214
  );
189
215
  }
190
216
  if (
@@ -259,8 +285,8 @@ export function resolvePath(
259
285
  path: origParts
260
286
  .slice(0, origParts.length - parts.length - 1)
261
287
  .map((p) => JSON.stringify(p))
262
- .join("."), // TODO: create a function generate path from parts (not sure if this always works)
263
- schema: resolvedSchema,
288
+ .join(".") as SourcePath, // TODO: create a function generate path from parts (not sure if this always works)
289
+ schema: resolvedSchema as Sch,
264
290
  source: resolvedSource,
265
291
  };
266
292
  } else if (isUnionSchema(resolvedSchema)) {
@@ -287,8 +313,8 @@ export function resolvePath(
287
313
  path: origParts
288
314
  .slice(0, origParts.length - parts.length - 1)
289
315
  .map((p) => JSON.stringify(p))
290
- .join("."), // TODO: create a function generate path from parts (not sure if this always works)
291
- schema: resolvedSchema,
316
+ .join(".") as SourcePath, // TODO: create a function generate path from parts (not sure if this always works)
317
+ schema: resolvedSchema as Sch,
292
318
  source: resolvedSource,
293
319
  };
294
320
  } else {
@@ -311,9 +337,9 @@ export function resolvePath(
311
337
  return JSON.stringify(p);
312
338
  }
313
339
  })
314
- .join("."), // TODO: create a function generate path from parts (not sure if this always works)
315
- schema: resolvedSchema,
316
- source: resolvedSource,
340
+ .join(".") as SourcePath, // TODO: create a function generate path from parts (not sure if this always works)
341
+ schema: resolvedSchema as Sch,
342
+ source: resolvedSource as Src,
317
343
  };
318
344
  }
319
345
 
@@ -57,7 +57,6 @@ describe("deref", () => {
57
57
  "/public/val/File\\ Name.jpg": "aWtrZSB25nJzdD8=",
58
58
  "/public/val/Some\\ Other\\ image.jpg": "ZnVua2VyIGRldHRlPw==",
59
59
  },
60
- remotePatches: {},
61
60
  };
62
61
  expect(actual).toStrictEqual(result.ok(expected));
63
62
  });
@@ -136,141 +135,140 @@ describe("deref", () => {
136
135
  fileUpdates: {
137
136
  "/public/val/File\\ Name.jpg": "ZnVua2VyIGRldHRlPw==",
138
137
  },
139
- remotePatches: {},
140
138
  };
141
139
  expect(actual).toStrictEqual(result.ok(expected));
142
140
  });
143
141
 
144
- test("replace remote", () => {
145
- const actual = derefPatch(
146
- [
147
- {
148
- op: "replace",
149
- path: ["foo", "baz"],
150
- value: 2,
151
- },
152
- {
153
- op: "replace",
154
- path: ["foo", "$re1", "test1"],
155
- value: "next test1 update",
156
- },
157
- {
158
- op: "replace",
159
- path: ["foo", "baz"],
160
- value: 3,
161
- },
162
- {
163
- op: "replace",
164
- path: ["foo", "$re2", "test2", "sub-segment"],
165
- value: "next test2 update",
166
- },
167
- ],
168
- {
169
- foo: {
170
- baz: 1,
171
- re1: remote("41f86df3"),
172
- re2: remote("96536d44"),
173
- },
174
- },
175
- ops
176
- );
177
- const expected: DerefPatchResult = {
178
- dereferencedPatch: [
179
- {
180
- op: "replace",
181
- path: ["foo", "baz"],
182
- value: 2,
183
- },
184
- {
185
- op: "replace",
186
- path: ["foo", "baz"],
187
- value: 3,
188
- },
189
- ],
190
- fileUpdates: {},
191
- remotePatches: {
192
- "41f86df3": [
193
- {
194
- op: "replace",
195
- path: ["test1"],
196
- value: "next test1 update",
197
- },
198
- ],
199
- "96536d44": [
200
- {
201
- op: "replace",
202
- path: ["test2", "sub-segment"],
203
- value: "next test2 update",
204
- },
205
- ],
206
- },
207
- };
208
- expect(actual).toStrictEqual(result.ok(expected));
209
- });
210
- test("replace remote with 2 replaces on same ref", () => {
211
- const actual = derefPatch(
212
- [
213
- {
214
- op: "replace",
215
- path: ["foo", "baz"],
216
- value: 2,
217
- },
218
- {
219
- op: "replace",
220
- path: ["foo", "$re1", "test1"],
221
- value: "next test1 update",
222
- },
223
- {
224
- op: "replace",
225
- path: ["foo", "baz"],
226
- value: 3,
227
- },
228
- {
229
- op: "replace",
230
- path: ["foo", "$re1", "test1"],
231
- value: "next test2 update",
232
- },
233
- ],
234
- {
235
- foo: {
236
- baz: 1,
237
- re1: remote("41f86df3"),
238
- re2: remote("96536d44"),
239
- },
240
- },
241
- ops
242
- );
243
- const expected: DerefPatchResult = {
244
- dereferencedPatch: [
245
- {
246
- op: "replace",
247
- path: ["foo", "baz"],
248
- value: 2,
249
- },
250
- {
251
- op: "replace",
252
- path: ["foo", "baz"],
253
- value: 3,
254
- },
255
- ],
256
- fileUpdates: {},
257
- remotePatches: {
258
- "41f86df3": [
259
- {
260
- op: "replace",
261
- path: ["test1"],
262
- value: "next test1 update",
263
- },
264
- {
265
- op: "replace",
266
- path: ["test1"],
267
- value: "next test2 update",
268
- },
269
- ],
270
- },
271
- };
272
- expect(actual).toStrictEqual(result.ok(expected));
273
- });
142
+ // test("replace remote", () => {
143
+ // const actual = derefPatch(
144
+ // [
145
+ // {
146
+ // op: "replace",
147
+ // path: ["foo", "baz"],
148
+ // value: 2,
149
+ // },
150
+ // {
151
+ // op: "replace",
152
+ // path: ["foo", "$re1", "test1"],
153
+ // value: "next test1 update",
154
+ // },
155
+ // {
156
+ // op: "replace",
157
+ // path: ["foo", "baz"],
158
+ // value: 3,
159
+ // },
160
+ // {
161
+ // op: "replace",
162
+ // path: ["foo", "$re2", "test2", "sub-segment"],
163
+ // value: "next test2 update",
164
+ // },
165
+ // ],
166
+ // {
167
+ // foo: {
168
+ // baz: 1,
169
+ // re1: remote("41f86df3"),
170
+ // re2: remote("96536d44"),
171
+ // },
172
+ // },
173
+ // ops
174
+ // );
175
+ // const expected: DerefPatchResult = {
176
+ // dereferencedPatch: [
177
+ // {
178
+ // op: "replace",
179
+ // path: ["foo", "baz"],
180
+ // value: 2,
181
+ // },
182
+ // {
183
+ // op: "replace",
184
+ // path: ["foo", "baz"],
185
+ // value: 3,
186
+ // },
187
+ // ],
188
+ // fileUpdates: {},
189
+ // remotePatches: {
190
+ // "41f86df3": [
191
+ // {
192
+ // op: "replace",
193
+ // path: ["test1"],
194
+ // value: "next test1 update",
195
+ // },
196
+ // ],
197
+ // "96536d44": [
198
+ // {
199
+ // op: "replace",
200
+ // path: ["test2", "sub-segment"],
201
+ // value: "next test2 update",
202
+ // },
203
+ // ],
204
+ // },
205
+ // };
206
+ // expect(actual).toStrictEqual(result.ok(expected));
207
+ // });
208
+ // test("replace remote with 2 replaces on same ref", () => {
209
+ // const actual = derefPatch(
210
+ // [
211
+ // {
212
+ // op: "replace",
213
+ // path: ["foo", "baz"],
214
+ // value: 2,
215
+ // },
216
+ // {
217
+ // op: "replace",
218
+ // path: ["foo", "$re1", "test1"],
219
+ // value: "next test1 update",
220
+ // },
221
+ // {
222
+ // op: "replace",
223
+ // path: ["foo", "baz"],
224
+ // value: 3,
225
+ // },
226
+ // {
227
+ // op: "replace",
228
+ // path: ["foo", "$re1", "test1"],
229
+ // value: "next test2 update",
230
+ // },
231
+ // ],
232
+ // {
233
+ // foo: {
234
+ // baz: 1,
235
+ // re1: remote("41f86df3"),
236
+ // re2: remote("96536d44"),
237
+ // },
238
+ // },
239
+ // ops
240
+ // );
241
+ // const expected: DerefPatchResult = {
242
+ // dereferencedPatch: [
243
+ // {
244
+ // op: "replace",
245
+ // path: ["foo", "baz"],
246
+ // value: 2,
247
+ // },
248
+ // {
249
+ // op: "replace",
250
+ // path: ["foo", "baz"],
251
+ // value: 3,
252
+ // },
253
+ // ],
254
+ // fileUpdates: {},
255
+ // remotePatches: {
256
+ // "41f86df3": [
257
+ // {
258
+ // op: "replace",
259
+ // path: ["test1"],
260
+ // value: "next test1 update",
261
+ // },
262
+ // {
263
+ // op: "replace",
264
+ // path: ["test1"],
265
+ // value: "next test2 update",
266
+ // },
267
+ // ],
268
+ // },
269
+ // };
270
+ // expect(actual).toStrictEqual(result.ok(expected));
271
+ // });
274
272
 
275
273
  test("replace chained references fails", () => {
276
274
  const actual = derefPatch(