-
Notifications
You must be signed in to change notification settings - Fork 1
/
data.ts
70 lines (62 loc) · 1.25 KB
/
data.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import type {
PSBoolean,
PSExternal,
PSFn,
PSFnCallContext,
PSList,
PSMap,
PSNumber,
PSRef,
PSString,
PSValue,
} from "./types.ts";
import type { Operation } from "./deps.ts";
export function number(value: number): PSNumber {
return { type: "number", value };
}
export function boolean(value: boolean): PSBoolean {
return { type: "boolean", value };
}
export function string(value: string): PSString {
return { type: "string", value };
}
export function ref(key: string, path: string[]): PSRef {
return {
type: "ref",
value: string(`$${[key].concat(path).join(".")}`),
key,
path,
};
}
export function list(value: PSValue[]): PSList {
return { type: "list", value };
}
export function map(value: Record<string, PSValue>): PSMap {
return {
type: "map",
value: new Map(
Object.entries(value).map(([k, v]) => {
return [string(k), v];
}),
),
};
}
export function external(
value: unknown,
view?: PSExternal["view"],
): PSExternal {
return { type: "external", value, view };
}
export function fn(
call: (cxt: PSFnCallContext) => Operation<PSValue>,
param: PSFn["param"],
): PSFn {
return {
type: "fn",
param,
value: {
type: "native",
call,
},
};
}