@valbuild/core 0.15.0 → 0.17.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 (133) hide show
  1. package/ROADMAP.md +106 -0
  2. package/dist/declarations/src/ValApi.d.ts +26 -0
  3. package/dist/declarations/src/expr/eval.d.ts +1 -1
  4. package/dist/declarations/src/future/fetchVal.d.ts +5 -0
  5. package/dist/declarations/src/index.d.ts +38 -9
  6. package/dist/declarations/src/initSchema.d.ts +2 -10
  7. package/dist/declarations/src/initVal.d.ts +3 -21
  8. package/dist/declarations/src/module.d.ts +2 -14
  9. package/dist/declarations/src/patch/index.d.ts +1 -1
  10. package/dist/declarations/src/patch/util.d.ts +2 -0
  11. package/dist/declarations/src/schema/array.d.ts +3 -2
  12. package/dist/declarations/src/schema/boolean.d.ts +3 -2
  13. package/dist/declarations/src/schema/image.d.ts +4 -3
  14. package/dist/declarations/src/schema/index.d.ts +8 -7
  15. package/dist/declarations/src/schema/keyOf.d.ts +23 -0
  16. package/dist/declarations/src/schema/literal.d.ts +3 -2
  17. package/dist/declarations/src/schema/number.d.ts +3 -2
  18. package/dist/declarations/src/schema/object.d.ts +3 -2
  19. package/dist/declarations/src/schema/record.d.ts +19 -0
  20. package/dist/declarations/src/schema/richtext.d.ts +3 -2
  21. package/dist/declarations/src/schema/string.d.ts +3 -2
  22. package/dist/declarations/src/schema/union.d.ts +4 -2
  23. package/dist/declarations/src/schema/validation/ValidationError.d.ts +14 -0
  24. package/dist/declarations/src/schema/validation/ValidationFix.d.ts +2 -0
  25. package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
  26. package/dist/declarations/src/selector/array.d.ts +2 -13
  27. package/dist/declarations/src/selector/file.d.ts +1 -4
  28. package/dist/declarations/src/selector/future/array.d.ts +17 -0
  29. package/dist/declarations/src/selector/future/boolean.d.ts +2 -0
  30. package/dist/declarations/src/selector/future/file.d.ts +9 -0
  31. package/dist/declarations/src/selector/{i18n.d.ts → future/i18n.d.ts} +2 -2
  32. package/dist/declarations/src/selector/future/index.d.ts +81 -0
  33. package/dist/declarations/src/selector/future/number.d.ts +2 -0
  34. package/dist/declarations/src/selector/future/object.d.ts +10 -0
  35. package/dist/declarations/src/selector/future/primitive.d.ts +9 -0
  36. package/dist/declarations/src/selector/{remote.d.ts → future/remote.d.ts} +1 -1
  37. package/dist/declarations/src/selector/future/string.d.ts +2 -0
  38. package/dist/declarations/src/selector/index.d.ts +5 -32
  39. package/dist/declarations/src/selector/object.d.ts +2 -9
  40. package/dist/declarations/src/selector/primitive.d.ts +3 -9
  41. package/dist/declarations/src/source/{i18n.d.ts → future/i18n.d.ts} +2 -2
  42. package/dist/declarations/src/source/{remote.d.ts → future/remote.d.ts} +3 -3
  43. package/dist/declarations/src/source/index.d.ts +4 -3
  44. package/dist/declarations/src/val/index.d.ts +2 -2
  45. package/dist/index-369caccf.esm.js +550 -0
  46. package/dist/{index-06df0a5b.esm.js → index-3e3e839e.esm.js} +190 -555
  47. package/dist/{index-9663f28a.cjs.dev.js → index-486c7fbf.cjs.dev.js} +224 -617
  48. package/dist/{index-b2270f8f.cjs.prod.js → index-601a7d73.cjs.prod.js} +224 -617
  49. package/dist/index-8706c87e.cjs.prod.js +582 -0
  50. package/dist/index-a6e642dd.cjs.dev.js +582 -0
  51. package/dist/ops-0d09f8ee.cjs.prod.js +684 -0
  52. package/dist/ops-23a5abb2.esm.js +671 -0
  53. package/dist/ops-f3015423.cjs.dev.js +684 -0
  54. package/dist/valbuild-core.cjs.dev.js +640 -633
  55. package/dist/valbuild-core.cjs.prod.js +640 -633
  56. package/dist/valbuild-core.esm.js +578 -572
  57. package/expr/dist/valbuild-core-expr.cjs.dev.js +8 -8
  58. package/expr/dist/valbuild-core-expr.cjs.prod.js +8 -8
  59. package/expr/dist/valbuild-core-expr.esm.js +2 -2
  60. package/package.json +2 -2
  61. package/patch/dist/valbuild-core-patch.cjs.dev.js +32 -23
  62. package/patch/dist/valbuild-core-patch.cjs.prod.js +32 -23
  63. package/patch/dist/valbuild-core-patch.esm.js +12 -4
  64. package/src/ValApi.ts +85 -0
  65. package/src/expr/eval.test.ts +2 -2
  66. package/src/expr/eval.ts +2 -2
  67. package/src/expr/repl.ts +2 -2
  68. package/src/{fetchVal.test.ts → future/fetchVal.test.ts} +57 -57
  69. package/src/{fetchVal.ts → future/fetchVal.ts} +17 -22
  70. package/src/index.ts +51 -14
  71. package/src/initSchema.ts +11 -12
  72. package/src/initVal.ts +42 -52
  73. package/src/module.test.ts +40 -40
  74. package/src/module.ts +53 -43
  75. package/src/patch/deref.test.ts +1 -1
  76. package/src/patch/deref.ts +1 -1
  77. package/src/patch/index.ts +1 -0
  78. package/src/patch/json.test.ts +0 -1
  79. package/src/patch/util.ts +7 -0
  80. package/src/schema/array.ts +45 -4
  81. package/src/schema/boolean.ts +14 -3
  82. package/src/schema/{i18n.ts → future/i18n.ts} +15 -11
  83. package/src/schema/{oneOf.ts → future/oneOf.ts} +21 -18
  84. package/src/schema/image.ts +66 -6
  85. package/src/schema/index.ts +37 -13
  86. package/src/schema/keyOf.ts +167 -0
  87. package/src/schema/literal.ts +24 -3
  88. package/src/schema/number.ts +14 -3
  89. package/src/schema/object.ts +50 -7
  90. package/src/schema/record.ts +103 -0
  91. package/src/schema/richtext.ts +63 -3
  92. package/src/schema/string.ts +14 -3
  93. package/src/schema/union.ts +4 -3
  94. package/src/schema/validation/ValidationError.ts +16 -0
  95. package/src/schema/validation/ValidationFix.ts +6 -0
  96. package/src/schema/validation.test.ts +291 -0
  97. package/src/selector/SelectorProxy.ts +16 -16
  98. package/src/selector/array.ts +2 -26
  99. package/src/selector/file.ts +1 -9
  100. package/src/selector/{ExprProxy.test.ts → future/ExprProxy.test.ts} +2 -2
  101. package/src/selector/{ExprProxy.ts → future/ExprProxy.ts} +9 -2
  102. package/src/selector/{SelectorProxy.test.ts → future/SelectorProxy.test.ts} +4 -4
  103. package/src/selector/future/SelectorProxy.ts +238 -0
  104. package/src/selector/future/array.ts +37 -0
  105. package/src/selector/future/boolean.ts +4 -0
  106. package/src/selector/future/file.ts +14 -0
  107. package/src/selector/{i18n.ts → future/i18n.ts} +2 -2
  108. package/src/selector/future/index.ts +165 -0
  109. package/src/selector/future/number.ts +4 -0
  110. package/src/selector/future/object.ts +22 -0
  111. package/src/selector/future/primitive.ts +17 -0
  112. package/src/selector/{remote.ts → future/remote.ts} +1 -1
  113. package/src/selector/{selector.test.ts → future/selector.test.ts} +8 -28
  114. package/src/selector/{selectorOf.ts → future/selectorOf.ts} +1 -1
  115. package/src/selector/future/string.ts +4 -0
  116. package/src/selector/index.ts +4 -46
  117. package/src/selector/object.ts +2 -19
  118. package/src/selector/primitive.ts +3 -16
  119. package/src/source/{i18n.ts → future/i18n.ts} +2 -2
  120. package/src/source/{remote.ts → future/remote.ts} +3 -3
  121. package/src/source/index.ts +3 -2
  122. package/src/val/array.ts +1 -1
  123. package/src/val/index.ts +2 -2
  124. package/src/val/object.ts +1 -1
  125. package/dist/createClass-012eebbf.esm.js +0 -109
  126. package/dist/createClass-a436dbfe.cjs.dev.js +0 -116
  127. package/dist/createClass-de7426aa.cjs.prod.js +0 -116
  128. package/dist/declarations/src/fetchVal.d.ts +0 -5
  129. package/dist/declarations/src/schema/i18n.d.ts +0 -21
  130. package/dist/declarations/src/schema/oneOf.d.ts +0 -22
  131. package/dist/ops-6fae92a1.esm.js +0 -12
  132. package/dist/ops-87cdbafc.cjs.dev.js +0 -14
  133. package/dist/ops-ae4d1bc2.cjs.prod.js +0 -14
@@ -0,0 +1,291 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ import { createValPathOfItem } from "../selector/future/SelectorProxy";
4
+ import { SourcePath } from "../val";
5
+ import { array } from "./array";
6
+ import { boolean } from "./boolean";
7
+ import { literal } from "./literal";
8
+ import { number } from "./number";
9
+ import { object } from "./object";
10
+ import { string } from "./string";
11
+ import { file as fileVal } from "../source/file";
12
+ import { richtext as richtextVal } from "../source/richtext";
13
+ import { image } from "./image";
14
+ import { ValidationFix } from "./validation/ValidationFix";
15
+ import {
16
+ ValidationError,
17
+ ValidationErrors,
18
+ } from "./validation/ValidationError";
19
+ import { richtext } from "./richtext";
20
+ import { record } from "./record";
21
+ import { keyOf } from "./keyOf";
22
+ import { content } from "../module";
23
+
24
+ const testPath = "/test" as SourcePath;
25
+ const pathOf = (p: string | symbol | number) => {
26
+ return createValPathOfItem(testPath, p);
27
+ };
28
+ const ValidationTestCases: {
29
+ description: string;
30
+ input: any;
31
+ schema: any;
32
+ expected: [SourcePath | undefined] | false;
33
+ fixes?: {
34
+ [path: string]: ValidationFix[];
35
+ };
36
+ }[] = [
37
+ // boolean
38
+ {
39
+ description: "basic boolean (true)",
40
+ input: true,
41
+ schema: boolean(),
42
+ expected: false,
43
+ },
44
+ {
45
+ description: "basic boolean (false)",
46
+ input: false,
47
+ schema: boolean(),
48
+ expected: false,
49
+ },
50
+ {
51
+ description: "failing boolean (null)",
52
+ input: null,
53
+ schema: boolean(),
54
+ expected: [testPath],
55
+ },
56
+ {
57
+ description: "optional boolean (null)",
58
+ input: null,
59
+ schema: boolean().optional(),
60
+ expected: false,
61
+ },
62
+ {
63
+ description: "failing boolean",
64
+ input: "false",
65
+ schema: boolean(),
66
+ expected: [testPath],
67
+ },
68
+ // number
69
+ {
70
+ description: "basic number (0)",
71
+ input: 0,
72
+ schema: number(),
73
+ expected: false,
74
+ },
75
+ {
76
+ description: "basic number (-1)",
77
+ input: -1,
78
+ schema: number(),
79
+ expected: false,
80
+ },
81
+ {
82
+ description: "basic number (1)",
83
+ input: 1,
84
+ schema: number(),
85
+ expected: false,
86
+ },
87
+ {
88
+ description: "basic number (1)",
89
+ input: 1,
90
+ schema: number(),
91
+ expected: false,
92
+ },
93
+ // string
94
+ {
95
+ description: "basic string",
96
+ input: "two",
97
+ schema: string(),
98
+ expected: false,
99
+ },
100
+ {
101
+ description: "failing string",
102
+ input: 1,
103
+ schema: string(),
104
+ expected: [testPath],
105
+ },
106
+ // literal
107
+ {
108
+ description: "basic literal",
109
+ input: "one",
110
+ schema: literal("one"),
111
+ expected: false,
112
+ },
113
+ {
114
+ description: "failing literal",
115
+ input: "two",
116
+ schema: literal("one"),
117
+ expected: [testPath],
118
+ },
119
+ // array
120
+ {
121
+ description: "basic array(string)",
122
+ input: ["one", "two"],
123
+ schema: array(string()),
124
+ expected: false,
125
+ },
126
+ {
127
+ description: "failing array(string)",
128
+ input: [true, "false"],
129
+ schema: array(string()),
130
+ expected: [pathOf(0)],
131
+ },
132
+ // object
133
+ {
134
+ description: "basic object(string)",
135
+ input: { one: "one val", two: 2 },
136
+ schema: object({
137
+ one: string(),
138
+ two: number(),
139
+ }),
140
+ expected: false,
141
+ },
142
+ {
143
+ description: "failing object(string)",
144
+ input: { one: "one val", two: 1 },
145
+ schema: object({
146
+ one: string(),
147
+ two: string(),
148
+ }),
149
+ expected: [pathOf("two")],
150
+ },
151
+ // record
152
+ {
153
+ description: "basic record(string)",
154
+ input: { one: "one val", two: "two val" },
155
+ schema: record(string()),
156
+ expected: false,
157
+ },
158
+ {
159
+ description: "failing record(string)",
160
+ input: { one: "one val", two: 1 },
161
+ schema: object({
162
+ one: string(),
163
+ two: string(),
164
+ }),
165
+ expected: [pathOf("two")],
166
+ },
167
+ // keyof
168
+ {
169
+ description: "basic keyOf(array)",
170
+ input: 1,
171
+ schema: keyOf(content("/keyof-module", array(string()), [])),
172
+ expected: false,
173
+ },
174
+ {
175
+ description: "failing keyOf(record)",
176
+ input: "1",
177
+ schema: keyOf(content("/keyof-module", array(string()), [])),
178
+ expected: [testPath],
179
+ },
180
+ {
181
+ description: "basic keyOf(record)",
182
+ input: "one",
183
+ schema: keyOf(content("/keyof-module", record(string()), {})),
184
+ expected: false,
185
+ },
186
+ {
187
+ description: "failing keyOf(record)",
188
+ input: 1,
189
+ schema: keyOf(content("/keyof-module", record(string()), {})),
190
+ expected: [testPath],
191
+ },
192
+ {
193
+ description: "basic keyOf(object)",
194
+ input: "test1",
195
+ schema: keyOf(
196
+ content("/keyof-module", object({ test1: string(), test2: string() }), {
197
+ test1: "",
198
+ test2: "",
199
+ })
200
+ ),
201
+ expected: false,
202
+ },
203
+ {
204
+ description: "failing keyOf(object)",
205
+ input: "test",
206
+ schema: keyOf(
207
+ content("/keyof-module", object({ test1: string(), test2: string() }), {
208
+ test1: "",
209
+ test2: "",
210
+ })
211
+ ),
212
+ expected: [testPath],
213
+ },
214
+ // image / file
215
+ {
216
+ description: "optional image",
217
+ input: null,
218
+ schema: image().optional(),
219
+ expected: false,
220
+ },
221
+ {
222
+ description: "failure image:: null",
223
+ input: null,
224
+ schema: image(),
225
+ expected: [testPath],
226
+ },
227
+ {
228
+ description: "failure image: replace metadata",
229
+ input: fileVal("test", {
230
+ width: 100,
231
+ height: 100,
232
+ sha256: "test",
233
+ }),
234
+ schema: image(),
235
+ expected: [testPath],
236
+ fixes: {
237
+ [testPath]: ["image:replace-metadata"],
238
+ },
239
+ },
240
+ {
241
+ description: "failure image: check metadata",
242
+ input: fileVal("test", {
243
+ width: 100,
244
+ height: 100,
245
+ sha256:
246
+ "9e420dc93157ab98338542ba6f1d34fcf829d646aa729a86720fa3f4cb2d0076",
247
+ }),
248
+ schema: image(),
249
+ expected: [testPath],
250
+ fixes: {
251
+ [testPath]: ["image:replace-metadata"],
252
+ },
253
+ },
254
+ // richtext
255
+ {
256
+ description: "basic richtext",
257
+ input: richtextVal("test"),
258
+ expected: false,
259
+ schema: richtext(),
260
+ },
261
+ // TODO: more richtext cases
262
+ // TODO: union
263
+ // TODO: oneOf
264
+ // TODO: i18n
265
+ ];
266
+
267
+ describe("validation", () => {
268
+ test.each(ValidationTestCases)(
269
+ 'validate ($description): "$expected"',
270
+ ({ input, schema, expected, fixes }) => {
271
+ const result = schema.validate(testPath, input);
272
+ if (result) {
273
+ expect(Object.keys(result)).toStrictEqual(expected);
274
+ if (fixes) {
275
+ expect(
276
+ Object.fromEntries(
277
+ Object.entries(result as ValidationErrors).map(
278
+ ([path, errors]) => [
279
+ path,
280
+ errors.flatMap((error: ValidationError) => error.fixes),
281
+ ]
282
+ )
283
+ )
284
+ ).toStrictEqual(fixes);
285
+ }
286
+ } else {
287
+ expect(result).toStrictEqual(expected);
288
+ }
289
+ }
290
+ );
291
+ });
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { Path, GenericSelector, SourceOrExpr, GetSchema } from ".";
2
+ import { Path, GenericSelector, GetSource, GetSchema } from "./index";
3
3
  import { Expr } from "../expr/expr";
4
4
  import { Schema } from "../schema";
5
- import { convertImageSource } from "../schema/image";
5
+ import { convertFileSource } from "../schema/image";
6
6
  import { Source, SourcePrimitive, VAL_EXTENSION } from "../source";
7
7
  import { FILE_REF_PROP } from "../source/file";
8
8
  import { isSerializedVal, SourcePath } from "../val";
@@ -22,7 +22,7 @@ export function isSelector(source: any): source is GenericSelector<Source> {
22
22
  return (
23
23
  typeof source === "object" &&
24
24
  source !== null &&
25
- (SourceOrExpr in source || Path in source)
25
+ (GetSource in source || Path in source)
26
26
  );
27
27
  }
28
28
 
@@ -44,7 +44,7 @@ export function newSelectorProxy(
44
44
  if (typeof fileRef !== "string") {
45
45
  throw Error("Invalid file ref: " + fileRef);
46
46
  }
47
- return newSelectorProxy(convertImageSource(source), path, moduleSchema);
47
+ return newSelectorProxy(convertFileSource(source), path, moduleSchema);
48
48
  }
49
49
 
50
50
  switch (typeof source) {
@@ -57,7 +57,7 @@ export function newSelectorProxy(
57
57
  return new Proxy(source, {
58
58
  // TODO: see proxy docs if we want more traps
59
59
  has(target, prop: string | symbol) {
60
- if (prop === SourceOrExpr) {
60
+ if (prop === GetSource) {
61
61
  return true;
62
62
  }
63
63
  if (prop === Path) {
@@ -72,7 +72,7 @@ export function newSelectorProxy(
72
72
  return prop in target;
73
73
  },
74
74
  get(target, prop: string | symbol) {
75
- if (prop === SourceOrExpr) {
75
+ if (prop === GetSource) {
76
76
  return source;
77
77
  }
78
78
  if (prop === Path) {
@@ -97,7 +97,7 @@ export function newSelectorProxy(
97
97
  )
98
98
  .filter((a) => {
99
99
  if (f && f instanceof Schema) {
100
- return f.match(unValify(a));
100
+ return f.assert(unValify(a));
101
101
  } else {
102
102
  return unValify(f(a));
103
103
  }
@@ -154,7 +154,7 @@ export function newSelectorProxy(
154
154
  eq: (other: SourcePrimitive | GenericSelector<Source>) => {
155
155
  let otherValue: any = other;
156
156
  if (isSelector(other)) {
157
- otherValue = other[SourceOrExpr];
157
+ otherValue = other[GetSource];
158
158
  if (otherValue instanceof Expr) {
159
159
  throw Error("TODO: Cannot evaluate equality with an Expr");
160
160
  }
@@ -164,7 +164,7 @@ export function newSelectorProxy(
164
164
  andThen: (f: any) => {
165
165
  return andThen(f, source === undefined ? null : source, path);
166
166
  },
167
- [SourceOrExpr]: source === undefined ? null : source,
167
+ [GetSource]: source === undefined ? null : source,
168
168
  [Path]: path,
169
169
  [GetSchema]: moduleSchema,
170
170
  };
@@ -178,7 +178,7 @@ function selectorAsVal(sel: any): any {
178
178
  } else if (
179
179
  typeof sel === "object" &&
180
180
  sel &&
181
- !(SourceOrExpr in sel) &&
181
+ !(GetSource in sel) &&
182
182
  !Array.isArray(sel)
183
183
  ) {
184
184
  // is object
@@ -188,7 +188,7 @@ function selectorAsVal(sel: any): any {
188
188
  } else if (
189
189
  typeof sel === "object" &&
190
190
  sel &&
191
- !(SourceOrExpr in sel) &&
191
+ !(GetSource in sel) &&
192
192
  Array.isArray(sel)
193
193
  ) {
194
194
  // is array
@@ -196,9 +196,9 @@ function selectorAsVal(sel: any): any {
196
196
  } else if (
197
197
  typeof sel === "object" &&
198
198
  sel &&
199
- (SourceOrExpr in sel || Path in sel)
199
+ (GetSource in sel || Path in sel)
200
200
  ) {
201
- return selectorAsVal(sel?.[SourceOrExpr]);
201
+ return selectorAsVal(sel?.[GetSource]);
202
202
  } else if (sel === undefined) {
203
203
  return null;
204
204
  }
@@ -218,7 +218,7 @@ export function createValPathOfItem(
218
218
  }
219
219
 
220
220
  export function selectorToVal(s: any): any {
221
- const v = selectorAsVal(s?.[SourceOrExpr]);
221
+ const v = selectorAsVal(s?.[GetSource]);
222
222
  return {
223
223
  val: v,
224
224
  [Path]: s?.[Path],
@@ -229,9 +229,9 @@ export function selectorToVal(s: any): any {
229
229
  function unValify(valueOrSelector: any) {
230
230
  if (
231
231
  typeof valueOrSelector === "object" &&
232
- (SourceOrExpr in valueOrSelector || Path in valueOrSelector)
232
+ (GetSource in valueOrSelector || Path in valueOrSelector)
233
233
  ) {
234
- const selectorValue = valueOrSelector[SourceOrExpr];
234
+ const selectorValue = valueOrSelector[GetSource];
235
235
  return selectorValue;
236
236
  }
237
237
  return valueOrSelector;
@@ -1,13 +1,5 @@
1
- import {
2
- Selector as UnknownSelector,
3
- GenericSelector,
4
- SelectorOf,
5
- SelectorSource,
6
- } from ".";
7
- import { Schema } from "../schema";
1
+ import { GenericSelector } from ".";
8
2
  import { Source, SourceArray } from "../source";
9
- import { Selector as BooleanSelector } from "./boolean";
10
- import { Selector as NumberSelector } from "./number";
11
3
 
12
4
  export type UndistributedSourceArray<T extends SourceArray> = [T] extends [
13
5
  infer U // infer here to avoid Type instantiation is excessively deep and possibly infinite. See: https://github.com/microsoft/TypeScript/issues/30188#issuecomment-478938437. Avoiding infer extends to keep us below TS 4.9 compat
@@ -18,20 +10,4 @@ export type UndistributedSourceArray<T extends SourceArray> = [T] extends [
18
10
  : never;
19
11
 
20
12
  // TODO: docs
21
- export type Selector<T extends SourceArray> = GenericSelector<T> & {
22
- readonly [key: number]: UnknownSelector<T[number]>;
23
- } & {
24
- length: NumberSelector<number>;
25
- filter(
26
- predicate: (
27
- v: UnknownSelector<T[number]>
28
- ) => BooleanSelector<boolean> | boolean
29
- ): Selector<T>;
30
- filter<U extends Source>(schema: Schema<U>): Selector<U[]>;
31
- map<U extends SelectorSource>(
32
- f: (v: UnknownSelector<T[number]>, i: UnknownSelector<number>) => U
33
- ): SelectorOf<U[]>; // TODO: this should be SelectorOf<ArraySelectorSourceBranded<U[]>>;
34
- andThen<U extends SelectorSource>(
35
- f: (v: UnknownSelector<NonNullable<T>>) => U
36
- ): SelectorOf<U | T>;
37
- };
13
+ export type Selector<T extends SourceArray> = GenericSelector<T>;
@@ -1,14 +1,6 @@
1
- import {
2
- Selector as UnknownSelector,
3
- GenericSelector,
4
- SelectorOf,
5
- SelectorSource,
6
- } from ".";
1
+ import { Selector as UnknownSelector, GenericSelector } from "./index";
7
2
 
8
3
  // TODO: docs
9
4
  export type FileSelector = GenericSelector<{ url: string }> & {
10
5
  readonly url: UnknownSelector<string>;
11
- andThen<U extends SelectorSource>(
12
- f: (v: UnknownSelector<NonNullable<{ url: string }>>) => U
13
- ): SelectorOf<U> | UnknownSelector<boolean>;
14
6
  };
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import { convertLiteralProxy, newExprSelectorProxy } from "./ExprProxy";
3
- import * as expr from "../expr/expr";
3
+ import * as expr from "../../expr/expr";
4
4
  import { GenericSelector, SelectorSource, SourceOrExpr } from ".";
5
- import { Source } from "../source";
5
+ import { Source } from "../../source";
6
6
 
7
7
  const ExprSelectorTestCases: any[] = [
8
8
  {
@@ -1,6 +1,6 @@
1
1
  import { Selector, SelectorSource, SourceOrExpr } from ".";
2
- import * as expr from "../expr/expr";
3
- import { Source, SourcePrimitive } from "../source";
2
+ import * as expr from "../../expr/expr";
3
+ import { Source, SourcePrimitive } from "../../source";
4
4
 
5
5
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
6
  type AnyFun = (...args: any[]) => any;
@@ -25,6 +25,13 @@ export function newExprSelectorProxy<T extends Source>(
25
25
  }) as unknown as Selector<T>;
26
26
  }
27
27
 
28
+ export function root(sourcePath: string) {
29
+ return new expr.Call(
30
+ [new expr.Sym("val"), new expr.StringLiteral(sourcePath)],
31
+ false
32
+ );
33
+ }
34
+
28
35
  class GenericExprSelector {
29
36
  [SourceOrExpr]: expr.Expr;
30
37
  constructor(private readonly root: expr.Expr, private readonly depth = 0) {
@@ -1,9 +1,9 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import { Selector, GenericSelector, Path } from ".";
3
- import { number } from "../schema/number";
4
- import { string } from "../schema/string";
5
- import { Source } from "../source";
6
- import { SourcePath } from "../val";
3
+ import { number } from "../../schema/number";
4
+ import { string } from "../../schema/string";
5
+ import { Source } from "../../source";
6
+ import { SourcePath } from "../../val";
7
7
  import { newSelectorProxy, selectorToVal } from "./SelectorProxy";
8
8
 
9
9
  describe("SelectorProxy", () => {