1 |
|
2 | "use strict";
|
3 | import type {
|
4 | JsonGraphAtomDefined,
|
5 | JsonGraphAtomUndefined,
|
6 | JsonGraphError,
|
7 | JsonGraphLeaf,
|
8 | JsonGraphMetadata,
|
9 | JsonGraphRef,
|
10 | JsonValue,
|
11 | Path,
|
12 | PathInvalidation,
|
13 | PathSet,
|
14 | PathValue
|
15 | } from ".";
|
16 |
|
17 | declare function atom<T: JsonValue>(
|
18 | value: T,
|
19 | props?: JsonGraphMetadata
|
20 | ): JsonGraphAtomDefined<T>;
|
21 |
|
22 | declare function atom(
|
23 | value?: void,
|
24 | props?: JsonGraphMetadata
|
25 | ): JsonGraphAtomUndefined;
|
26 |
|
27 | function atom(value, props) {
|
28 | const result =
|
29 | typeof value === "undefined"
|
30 | ? { $type: "atom" }
|
31 | : { $type: "atom", value: value };
|
32 | return props ? Object.assign({}, props, result) : result;
|
33 | }
|
34 |
|
35 | function undefinedAtom(): JsonGraphAtomUndefined {
|
36 | return { $type: "atom" };
|
37 | }
|
38 |
|
39 | module.exports = {
|
40 | ref: function ref(path: Path, props?: JsonGraphMetadata): JsonGraphRef {
|
41 | const result = { $type: "ref", value: path };
|
42 | return props ? Object.assign({}, props, result) : result;
|
43 | },
|
44 | atom: atom,
|
45 | undefinedAtom: undefinedAtom,
|
46 | error: function error(
|
47 | errorValue: string,
|
48 | props?: JsonGraphMetadata
|
49 | ): JsonGraphError {
|
50 | const result = { $type: "error", value: errorValue };
|
51 | return props ? Object.assign({}, props, result) : result;
|
52 | },
|
53 | pathValue: function pathValue(
|
54 | path: PathSet,
|
55 | value: JsonGraphLeaf
|
56 | ): PathValue {
|
57 | return { path: path, value: value };
|
58 | },
|
59 | pathInvalidation: function pathInvalidation(path: PathSet): PathInvalidation {
|
60 | return { path: path, invalidated: true };
|
61 | }
|
62 | };
|