@valbuild/core 0.16.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.
- package/ROADMAP.md +106 -0
- package/dist/declarations/src/ValApi.d.ts +26 -0
- package/dist/declarations/src/expr/eval.d.ts +1 -1
- package/dist/declarations/src/future/fetchVal.d.ts +5 -0
- package/dist/declarations/src/index.d.ts +36 -9
- package/dist/declarations/src/initSchema.d.ts +2 -10
- package/dist/declarations/src/initVal.d.ts +3 -21
- package/dist/declarations/src/module.d.ts +2 -14
- package/dist/declarations/src/schema/image.d.ts +1 -1
- package/dist/declarations/src/schema/index.d.ts +3 -5
- package/dist/declarations/src/schema/keyOf.d.ts +23 -0
- package/dist/declarations/src/schema/record.d.ts +19 -0
- package/dist/declarations/src/schema/union.d.ts +1 -0
- package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
- package/dist/declarations/src/selector/array.d.ts +2 -13
- package/dist/declarations/src/selector/file.d.ts +1 -4
- package/dist/declarations/src/selector/future/array.d.ts +17 -0
- package/dist/declarations/src/selector/future/boolean.d.ts +2 -0
- package/dist/declarations/src/selector/future/file.d.ts +9 -0
- package/dist/declarations/src/selector/{i18n.d.ts → future/i18n.d.ts} +2 -2
- package/dist/declarations/src/selector/future/index.d.ts +81 -0
- package/dist/declarations/src/selector/future/number.d.ts +2 -0
- package/dist/declarations/src/selector/future/object.d.ts +10 -0
- package/dist/declarations/src/selector/future/primitive.d.ts +9 -0
- package/dist/declarations/src/selector/{remote.d.ts → future/remote.d.ts} +1 -1
- package/dist/declarations/src/selector/future/string.d.ts +2 -0
- package/dist/declarations/src/selector/index.d.ts +5 -32
- package/dist/declarations/src/selector/object.d.ts +2 -9
- package/dist/declarations/src/selector/primitive.d.ts +3 -9
- package/dist/declarations/src/source/{i18n.d.ts → future/i18n.d.ts} +2 -2
- package/dist/declarations/src/source/{remote.d.ts → future/remote.d.ts} +3 -3
- package/dist/declarations/src/source/index.d.ts +4 -3
- package/dist/declarations/src/val/index.d.ts +2 -2
- package/dist/{SelectorProxy-63c2d0e2.esm.js → index-369caccf.esm.js} +23 -195
- package/dist/{index-af761363.esm.js → index-3e3e839e.esm.js} +189 -1
- package/dist/{index-2fff5ca8.cjs.dev.js → index-486c7fbf.cjs.dev.js} +242 -54
- package/dist/{index-cac9ecbd.cjs.prod.js → index-601a7d73.cjs.prod.js} +242 -54
- package/dist/{SelectorProxy-2af1b2b8.cjs.prod.js → index-8706c87e.cjs.prod.js} +25 -199
- package/dist/{SelectorProxy-873782a5.cjs.dev.js → index-a6e642dd.cjs.dev.js} +25 -199
- package/dist/{ops-1b6e0e35.cjs.prod.js → ops-0d09f8ee.cjs.prod.js} +258 -126
- package/dist/{ops-74661336.esm.js → ops-23a5abb2.esm.js} +195 -65
- package/dist/{ops-ea4827fc.cjs.dev.js → ops-f3015423.cjs.dev.js} +258 -126
- package/dist/valbuild-core.cjs.dev.js +585 -198
- package/dist/valbuild-core.cjs.prod.js +585 -198
- package/dist/valbuild-core.esm.js +520 -134
- package/expr/dist/valbuild-core-expr.cjs.dev.js +8 -8
- package/expr/dist/valbuild-core-expr.cjs.prod.js +8 -8
- package/expr/dist/valbuild-core-expr.esm.js +2 -2
- package/package.json +2 -3
- package/patch/dist/valbuild-core-patch.cjs.dev.js +24 -24
- package/patch/dist/valbuild-core-patch.cjs.prod.js +24 -24
- package/patch/dist/valbuild-core-patch.esm.js +3 -3
- package/src/ValApi.ts +85 -0
- package/src/expr/eval.test.ts +2 -2
- package/src/expr/eval.ts +2 -2
- package/src/{fetchVal.test.ts → future/fetchVal.test.ts} +57 -57
- package/src/{fetchVal.ts → future/fetchVal.ts} +17 -22
- package/src/index.ts +46 -14
- package/src/initSchema.ts +11 -12
- package/src/initVal.ts +42 -52
- package/src/module.test.ts +40 -40
- package/src/module.ts +53 -43
- package/src/patch/deref.test.ts +1 -1
- package/src/patch/deref.ts +1 -1
- package/src/patch/json.test.ts +0 -1
- package/src/schema/{i18n.ts → future/i18n.ts} +12 -10
- package/src/schema/{oneOf.ts → future/oneOf.ts} +19 -17
- package/src/schema/image.ts +1 -1
- package/src/schema/index.ts +16 -13
- package/src/schema/keyOf.ts +167 -0
- package/src/schema/record.ts +103 -0
- package/src/schema/union.ts +1 -1
- package/src/schema/validation.test.ts +195 -130
- package/src/selector/SelectorProxy.ts +15 -15
- package/src/selector/array.ts +2 -26
- package/src/selector/file.ts +1 -9
- package/src/selector/{ExprProxy.test.ts → future/ExprProxy.test.ts} +2 -2
- package/src/selector/{ExprProxy.ts → future/ExprProxy.ts} +9 -2
- package/src/selector/{SelectorProxy.test.ts → future/SelectorProxy.test.ts} +4 -4
- package/src/selector/future/SelectorProxy.ts +238 -0
- package/src/selector/future/array.ts +37 -0
- package/src/selector/future/boolean.ts +4 -0
- package/src/selector/future/file.ts +14 -0
- package/src/selector/{i18n.ts → future/i18n.ts} +2 -2
- package/src/selector/future/index.ts +165 -0
- package/src/selector/future/number.ts +4 -0
- package/src/selector/future/object.ts +22 -0
- package/src/selector/future/primitive.ts +17 -0
- package/src/selector/{remote.ts → future/remote.ts} +1 -1
- package/src/selector/{selector.test.ts → future/selector.test.ts} +8 -28
- package/src/selector/{selectorOf.ts → future/selectorOf.ts} +1 -1
- package/src/selector/future/string.ts +4 -0
- package/src/selector/index.ts +4 -46
- package/src/selector/object.ts +2 -19
- package/src/selector/primitive.ts +3 -16
- package/src/source/{i18n.ts → future/i18n.ts} +2 -2
- package/src/source/{remote.ts → future/remote.ts} +3 -3
- package/src/source/index.ts +3 -2
- package/src/val/array.ts +1 -1
- package/src/val/index.ts +2 -2
- package/src/val/object.ts +1 -1
- package/dist/declarations/src/fetchVal.d.ts +0 -5
- package/dist/declarations/src/schema/i18n.d.ts +0 -22
- package/dist/declarations/src/schema/oneOf.d.ts +0 -23
@@ -1,6 +1,6 @@
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2
2
|
|
3
|
-
import { createValPathOfItem } from "../selector/SelectorProxy";
|
3
|
+
import { createValPathOfItem } from "../selector/future/SelectorProxy";
|
4
4
|
import { SourcePath } from "../val";
|
5
5
|
import { array } from "./array";
|
6
6
|
import { boolean } from "./boolean";
|
@@ -17,6 +17,9 @@ import {
|
|
17
17
|
ValidationErrors,
|
18
18
|
} from "./validation/ValidationError";
|
19
19
|
import { richtext } from "./richtext";
|
20
|
+
import { record } from "./record";
|
21
|
+
import { keyOf } from "./keyOf";
|
22
|
+
import { content } from "../module";
|
20
23
|
|
21
24
|
const testPath = "/test" as SourcePath;
|
22
25
|
const pathOf = (p: string | symbol | number) => {
|
@@ -56,135 +59,198 @@ const ValidationTestCases: {
|
|
56
59
|
schema: boolean().optional(),
|
57
60
|
expected: false,
|
58
61
|
},
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
//
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
//
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
//
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
//
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
//
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
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
|
+
},
|
148
214
|
// image / file
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
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
|
+
},
|
188
254
|
// richtext
|
189
255
|
{
|
190
256
|
description: "basic richtext",
|
@@ -203,7 +269,6 @@ describe("validation", () => {
|
|
203
269
|
'validate ($description): "$expected"',
|
204
270
|
({ input, schema, expected, fixes }) => {
|
205
271
|
const result = schema.validate(testPath, input);
|
206
|
-
console.log(JSON.stringify({ result, expected }, null, 2));
|
207
272
|
if (result) {
|
208
273
|
expect(Object.keys(result)).toStrictEqual(expected);
|
209
274
|
if (fixes) {
|
@@ -1,8 +1,8 @@
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2
|
-
import { Path, GenericSelector,
|
2
|
+
import { Path, GenericSelector, GetSource, GetSchema } from "./index";
|
3
3
|
import { Expr } from "../expr/expr";
|
4
4
|
import { Schema } from "../schema";
|
5
|
-
import {
|
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
|
-
(
|
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(
|
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 ===
|
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 ===
|
75
|
+
if (prop === GetSource) {
|
76
76
|
return source;
|
77
77
|
}
|
78
78
|
if (prop === Path) {
|
@@ -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[
|
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
|
-
[
|
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
|
-
!(
|
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
|
-
!(
|
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
|
-
(
|
199
|
+
(GetSource in sel || Path in sel)
|
200
200
|
) {
|
201
|
-
return selectorAsVal(sel?.[
|
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?.[
|
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
|
-
(
|
232
|
+
(GetSource in valueOrSelector || Path in valueOrSelector)
|
233
233
|
) {
|
234
|
-
const selectorValue = valueOrSelector[
|
234
|
+
const selectorValue = valueOrSelector[GetSource];
|
235
235
|
return selectorValue;
|
236
236
|
}
|
237
237
|
return valueOrSelector;
|
package/src/selector/array.ts
CHANGED
@@ -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>;
|
package/src/selector/file.ts
CHANGED
@@ -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 "
|
3
|
+
import * as expr from "../../expr/expr";
|
4
4
|
import { GenericSelector, SelectorSource, SourceOrExpr } from ".";
|
5
|
-
import { Source } from "
|
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 "
|
3
|
-
import { Source, SourcePrimitive } from "
|
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 "
|
4
|
-
import { string } from "
|
5
|
-
import { Source } from "
|
6
|
-
import { SourcePath } from "
|
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", () => {
|