@valbuild/core 0.26.0 → 0.27.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/package.json +12 -3
- package/CHANGELOG.md +0 -0
- package/ROADMAP.md +0 -106
- package/jest.config.js +0 -4
- package/src/Json.ts +0 -4
- package/src/ValApi.ts +0 -81
- package/src/expr/README.md +0 -193
- package/src/expr/eval.test.ts +0 -198
- package/src/expr/eval.ts +0 -251
- package/src/expr/expr.ts +0 -91
- package/src/expr/index.ts +0 -3
- package/src/expr/parser.test.ts +0 -158
- package/src/expr/parser.ts +0 -229
- package/src/expr/repl.ts +0 -88
- package/src/expr/tokenizer.test.ts +0 -539
- package/src/expr/tokenizer.ts +0 -117
- package/src/fp/array.ts +0 -30
- package/src/fp/index.ts +0 -3
- package/src/fp/result.ts +0 -214
- package/src/fp/util.ts +0 -52
- package/src/future/fetchVal.test.ts +0 -164
- package/src/future/fetchVal.ts +0 -206
- package/src/getSha256.ts +0 -8
- package/src/index.ts +0 -132
- package/src/initSchema.ts +0 -50
- package/src/initVal.ts +0 -73
- package/src/module.test.ts +0 -170
- package/src/module.ts +0 -397
- package/src/patch/deref.test.ts +0 -298
- package/src/patch/deref.ts +0 -136
- package/src/patch/index.ts +0 -12
- package/src/patch/json.test.ts +0 -582
- package/src/patch/json.ts +0 -304
- package/src/patch/operation.ts +0 -86
- package/src/patch/ops.ts +0 -83
- package/src/patch/parse.test.ts +0 -202
- package/src/patch/parse.ts +0 -202
- package/src/patch/patch.ts +0 -49
- package/src/patch/util.ts +0 -74
- package/src/schema/array.ts +0 -93
- package/src/schema/boolean.ts +0 -49
- package/src/schema/future/i18n.ts +0 -69
- package/src/schema/future/oneOf.ts +0 -63
- package/src/schema/image.ts +0 -137
- package/src/schema/index.ts +0 -70
- package/src/schema/keyOf.ts +0 -167
- package/src/schema/literal.ts +0 -63
- package/src/schema/number.ts +0 -56
- package/src/schema/object.ts +0 -110
- package/src/schema/record.ts +0 -103
- package/src/schema/richtext.ts +0 -44
- package/src/schema/string.ts +0 -95
- package/src/schema/union.ts +0 -63
- package/src/schema/validation/ValidationError.ts +0 -16
- package/src/schema/validation/ValidationFix.ts +0 -6
- package/src/schema/validation.test.ts +0 -291
- package/src/selector/SelectorProxy.ts +0 -238
- package/src/selector/array.ts +0 -13
- package/src/selector/boolean.ts +0 -4
- package/src/selector/file.ts +0 -6
- package/src/selector/future/ExprProxy.test.ts +0 -203
- package/src/selector/future/ExprProxy.ts +0 -216
- package/src/selector/future/SelectorProxy.test.ts +0 -172
- package/src/selector/future/SelectorProxy.ts +0 -238
- package/src/selector/future/array.ts +0 -37
- package/src/selector/future/boolean.ts +0 -4
- package/src/selector/future/file.ts +0 -14
- package/src/selector/future/i18n.ts +0 -13
- package/src/selector/future/index.ts +0 -169
- package/src/selector/future/number.ts +0 -4
- package/src/selector/future/object.ts +0 -22
- package/src/selector/future/primitive.ts +0 -17
- package/src/selector/future/remote.ts +0 -9
- package/src/selector/future/selector.test.ts +0 -429
- package/src/selector/future/selectorOf.ts +0 -7
- package/src/selector/future/string.ts +0 -4
- package/src/selector/index.ts +0 -121
- package/src/selector/number.ts +0 -4
- package/src/selector/object.ts +0 -5
- package/src/selector/primitive.ts +0 -4
- package/src/selector/string.ts +0 -4
- package/src/source/file.ts +0 -45
- package/src/source/future/i18n.ts +0 -60
- package/src/source/future/remote.ts +0 -54
- package/src/source/index.ts +0 -53
- package/src/source/link.ts +0 -14
- package/src/source/richtext.ts +0 -178
- package/src/val/array.ts +0 -10
- package/src/val/index.ts +0 -100
- package/src/val/object.ts +0 -13
- package/src/val/primitive.ts +0 -8
- package/tsconfig.json +0 -8
package/src/expr/parser.ts
DELETED
@@ -1,229 +0,0 @@
|
|
1
|
-
import { result } from "../fp";
|
2
|
-
import { Call, Expr, StringLiteral, StringTemplate, Sym } from "./expr";
|
3
|
-
import { Token, tokenize } from "./tokenizer";
|
4
|
-
|
5
|
-
export class ParserError {
|
6
|
-
constructor(
|
7
|
-
public readonly message: string,
|
8
|
-
public readonly span?: [number, number?]
|
9
|
-
) {}
|
10
|
-
}
|
11
|
-
|
12
|
-
function parseTokens(inputTokens: Token[]): result.Result<Expr, ParserError> {
|
13
|
-
const tokens = inputTokens.slice();
|
14
|
-
|
15
|
-
function slurpCall(
|
16
|
-
first: Token,
|
17
|
-
isAnon: boolean
|
18
|
-
): result.Result<Call | Sym, ParserError> {
|
19
|
-
// peek
|
20
|
-
if (
|
21
|
-
(tokens[0]?.type === "ws" && tokens[1]?.type === ")") ||
|
22
|
-
tokens[0]?.type === ")"
|
23
|
-
) {
|
24
|
-
slurpWs();
|
25
|
-
tokens.shift();
|
26
|
-
return result.ok(new Sym("()", [first.span[0], first.span[1] + 1]));
|
27
|
-
}
|
28
|
-
const args: Expr[] = [];
|
29
|
-
let completed = false;
|
30
|
-
while (!completed) {
|
31
|
-
const res = slurp();
|
32
|
-
if (result.isOk(res)) {
|
33
|
-
args.push(res.value);
|
34
|
-
completed =
|
35
|
-
tokens[0]?.type !== "ws" ||
|
36
|
-
(tokens[0]?.type === "ws" && tokens[1]?.type === ")");
|
37
|
-
} else {
|
38
|
-
return res;
|
39
|
-
}
|
40
|
-
}
|
41
|
-
if (tokens[0]?.type === "ws" && tokens[1]?.type === ")") {
|
42
|
-
tokens.shift();
|
43
|
-
}
|
44
|
-
const last = tokens.shift();
|
45
|
-
if (last?.type !== ")") {
|
46
|
-
return result.err(
|
47
|
-
new ParserError("unbalanced parens: missing a ')'", [
|
48
|
-
first.span[0],
|
49
|
-
first.span[1] + 1,
|
50
|
-
])
|
51
|
-
);
|
52
|
-
}
|
53
|
-
return result.ok(
|
54
|
-
new Call(args, isAnon, [first.span[0], args.slice(-1)[0].span?.[1] || -1])
|
55
|
-
);
|
56
|
-
}
|
57
|
-
|
58
|
-
function slurpWs() {
|
59
|
-
while (tokens[0]?.type === "ws") {
|
60
|
-
tokens.shift();
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
function slurpTemplate(
|
65
|
-
first: Token
|
66
|
-
): result.Result<StringLiteral | StringTemplate, ParserError> {
|
67
|
-
const children: Expr[] = [];
|
68
|
-
while (tokens.length > 0) {
|
69
|
-
if ((tokens[0]?.type as string) === "'") {
|
70
|
-
break;
|
71
|
-
}
|
72
|
-
const nextToken = tokens.shift();
|
73
|
-
if (nextToken?.type === "${") {
|
74
|
-
const res = slurp();
|
75
|
-
if (result.isOk(res)) {
|
76
|
-
children.push(res.value);
|
77
|
-
const last = tokens.shift();
|
78
|
-
if (!last) {
|
79
|
-
return result.err(
|
80
|
-
new ParserError("unbalanced string template: missing a '}'", [
|
81
|
-
first.span[0],
|
82
|
-
children.slice(-1)[0].span?.[1],
|
83
|
-
])
|
84
|
-
);
|
85
|
-
} else if (last.type !== "}") {
|
86
|
-
return result.err(
|
87
|
-
new ParserError(
|
88
|
-
"unbalanced string template: expected '}'",
|
89
|
-
last.span
|
90
|
-
)
|
91
|
-
);
|
92
|
-
}
|
93
|
-
} else {
|
94
|
-
return res;
|
95
|
-
}
|
96
|
-
} else if (nextToken?.type === "string") {
|
97
|
-
children.push(
|
98
|
-
new StringLiteral(
|
99
|
-
nextToken.unescapedValue || nextToken.value || "",
|
100
|
-
nextToken.span
|
101
|
-
)
|
102
|
-
);
|
103
|
-
}
|
104
|
-
}
|
105
|
-
|
106
|
-
const last = tokens.shift();
|
107
|
-
if (!last) {
|
108
|
-
return result.err(
|
109
|
-
new ParserError("unbalanced string template: missing a '''", [
|
110
|
-
first.span[0],
|
111
|
-
children.slice(-1)[0].span?.[1],
|
112
|
-
])
|
113
|
-
);
|
114
|
-
} else if (last.type !== "'") {
|
115
|
-
return result.err(
|
116
|
-
new ParserError("unbalanced string template: expected '''", last.span)
|
117
|
-
);
|
118
|
-
}
|
119
|
-
|
120
|
-
return result.ok(
|
121
|
-
new StringTemplate(children, [first.span[0], last.span[1]])
|
122
|
-
);
|
123
|
-
}
|
124
|
-
|
125
|
-
function slurpString(
|
126
|
-
first: Token
|
127
|
-
): result.Result<StringLiteral | StringTemplate, ParserError> {
|
128
|
-
if (tokens[0]?.type === "string" && tokens[1]?.type === "'") {
|
129
|
-
const stringToken = tokens.shift();
|
130
|
-
const last = tokens.shift();
|
131
|
-
if (!last || !stringToken) {
|
132
|
-
throw Error("Unexpected error: stringToken or last is undefined");
|
133
|
-
}
|
134
|
-
return result.ok(
|
135
|
-
new StringLiteral(
|
136
|
-
stringToken.unescapedValue || stringToken.value || "",
|
137
|
-
[first.span[0], last.span[1]]
|
138
|
-
)
|
139
|
-
);
|
140
|
-
} else if (tokens[0]?.type === "'") {
|
141
|
-
const last = tokens.shift();
|
142
|
-
if (!last) {
|
143
|
-
throw Error("Unexpected error: last is undefined");
|
144
|
-
}
|
145
|
-
return result.ok(new StringLiteral("", [first.span[0], last.span[1]]));
|
146
|
-
} else {
|
147
|
-
return slurpTemplate(first);
|
148
|
-
}
|
149
|
-
}
|
150
|
-
|
151
|
-
function slurp(): result.Result<Expr, ParserError> {
|
152
|
-
slurpWs();
|
153
|
-
const first = tokens.shift();
|
154
|
-
if (!first) {
|
155
|
-
return result.err(
|
156
|
-
new ParserError("expected '(', '!(', string or literal", [0, 0])
|
157
|
-
);
|
158
|
-
}
|
159
|
-
if (first.type === "(" || first.type === "!(") {
|
160
|
-
return slurpCall(first, first.type === "!(");
|
161
|
-
} else if (first.type === "'") {
|
162
|
-
return slurpString(first);
|
163
|
-
} else if (first.type === "token") {
|
164
|
-
if (first.value?.includes("(") || first.value?.includes(")")) {
|
165
|
-
return result.err(
|
166
|
-
new ParserError(
|
167
|
-
"unexpected token: '(' and ')' are not allowed in tokens",
|
168
|
-
first.span
|
169
|
-
)
|
170
|
-
);
|
171
|
-
}
|
172
|
-
if (first.value?.includes("'")) {
|
173
|
-
return result.err(
|
174
|
-
new ParserError(
|
175
|
-
'unexpected token: "\'" is not allowed in tokens',
|
176
|
-
first.span
|
177
|
-
)
|
178
|
-
);
|
179
|
-
}
|
180
|
-
if (first.value?.includes(".")) {
|
181
|
-
return result.err(
|
182
|
-
new ParserError(
|
183
|
-
'unexpected token: "." is not allowed in tokens',
|
184
|
-
first.span
|
185
|
-
)
|
186
|
-
);
|
187
|
-
}
|
188
|
-
if (first.value?.includes("{") || first.value?.includes("}")) {
|
189
|
-
return result.err(
|
190
|
-
new ParserError(
|
191
|
-
"unexpected token: '{' and '}' are not allowed in tokens",
|
192
|
-
first.span
|
193
|
-
)
|
194
|
-
);
|
195
|
-
}
|
196
|
-
return result.ok(new Sym(first.value || "", first.span));
|
197
|
-
} else {
|
198
|
-
return result.err(
|
199
|
-
new ParserError(
|
200
|
-
`expected '(', '!(' or literal or token${
|
201
|
-
first.value || first.type
|
202
|
-
? `, got: '${first.value || first.type}'`
|
203
|
-
: ""
|
204
|
-
}`,
|
205
|
-
first.span
|
206
|
-
)
|
207
|
-
);
|
208
|
-
}
|
209
|
-
}
|
210
|
-
const res = slurp();
|
211
|
-
slurpWs();
|
212
|
-
if (result.isErr(res)) {
|
213
|
-
return res;
|
214
|
-
}
|
215
|
-
if (tokens.length > 0) {
|
216
|
-
return result.err(
|
217
|
-
new ParserError("expected end of input, superfluous tokens", [
|
218
|
-
tokens[0].span[0],
|
219
|
-
tokens.slice(-1)[0].span[1],
|
220
|
-
])
|
221
|
-
);
|
222
|
-
}
|
223
|
-
return res;
|
224
|
-
}
|
225
|
-
export function parse(input: string): result.Result<Expr, ParserError> {
|
226
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
227
|
-
const [tokens, cursor] = tokenize(input); // TODO: we can use cursor to improve error messages / spans
|
228
|
-
return parseTokens(tokens);
|
229
|
-
}
|
package/src/expr/repl.ts
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
import * as repl from "repl";
|
2
|
-
import { result, pipe } from "../../fp";
|
3
|
-
import { selectorToVal } from "../selector/SelectorProxy";
|
4
|
-
import { evaluate } from "./eval";
|
5
|
-
import { parse } from "./parser";
|
6
|
-
|
7
|
-
const sources = {
|
8
|
-
"/app/text": "text1",
|
9
|
-
"/numbers": [1, 2, 3],
|
10
|
-
"/blogs": [
|
11
|
-
{ title: "title1", text: "text1" },
|
12
|
-
{ title: "title2", text: "text2" },
|
13
|
-
],
|
14
|
-
};
|
15
|
-
|
16
|
-
repl
|
17
|
-
.start({
|
18
|
-
prompt: "β > ",
|
19
|
-
eval: (
|
20
|
-
cmd,
|
21
|
-
_context,
|
22
|
-
_filename,
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
24
|
-
callback: (arg0: any, arg1: any) => void
|
25
|
-
) => {
|
26
|
-
const res = parse(cmd);
|
27
|
-
if (result.isErr(res)) {
|
28
|
-
let lines = "\n\x1b[31m";
|
29
|
-
lines +=
|
30
|
-
res.error.message[0]?.toUpperCase() +
|
31
|
-
res.error.message.slice(1) +
|
32
|
-
` (${res.error.span?.[0]}:${res.error.span?.[1]})` +
|
33
|
-
":\x1b[0m\n\n";
|
34
|
-
lines += cmd + "\n";
|
35
|
-
let underline = "\x1b[31m";
|
36
|
-
for (let i = 0; i < cmd.length; i++) {
|
37
|
-
if (
|
38
|
-
res.error.span &&
|
39
|
-
i >= res.error.span[0] &&
|
40
|
-
i <= (res.error.span?.[1] === undefined ? -1 : res.error.span?.[1])
|
41
|
-
) {
|
42
|
-
underline += "^";
|
43
|
-
} else {
|
44
|
-
if (cmd[i] === "\n") {
|
45
|
-
if (!underline.includes("^")) {
|
46
|
-
underline = "";
|
47
|
-
}
|
48
|
-
} else {
|
49
|
-
underline += " ";
|
50
|
-
}
|
51
|
-
}
|
52
|
-
}
|
53
|
-
lines += underline + "\x1b[0m\n";
|
54
|
-
callback(null, lines);
|
55
|
-
} else {
|
56
|
-
pipe(
|
57
|
-
evaluate(
|
58
|
-
res.value,
|
59
|
-
(path) => sources[path as keyof typeof sources],
|
60
|
-
|
61
|
-
[]
|
62
|
-
),
|
63
|
-
result.map((v) => {
|
64
|
-
try {
|
65
|
-
console.log(selectorToVal(v).val);
|
66
|
-
callback(null, undefined);
|
67
|
-
} catch (e) {
|
68
|
-
callback(
|
69
|
-
null,
|
70
|
-
`\x1b[31mInvalid function! Expected selector, but got:\x1b[0m:\n${JSON.stringify(
|
71
|
-
v
|
72
|
-
)}\n\nDetails: ${
|
73
|
-
e instanceof Error ? e.message : JSON.stringify(e)
|
74
|
-
}`
|
75
|
-
);
|
76
|
-
}
|
77
|
-
})
|
78
|
-
);
|
79
|
-
}
|
80
|
-
},
|
81
|
-
ignoreUndefined: true,
|
82
|
-
writer: (output) => {
|
83
|
-
return output;
|
84
|
-
},
|
85
|
-
})
|
86
|
-
.setupHistory(".repl_history", () => {
|
87
|
-
//
|
88
|
-
});
|