@valbuild/core 0.25.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.
Files changed (94) hide show
  1. package/dist/declarations/src/selector/future/index.d.ts +1 -1
  2. package/dist/declarations/src/source/future/i18n.d.ts +1 -1
  3. package/package.json +12 -3
  4. package/CHANGELOG.md +0 -0
  5. package/ROADMAP.md +0 -106
  6. package/jest.config.js +0 -4
  7. package/src/Json.ts +0 -4
  8. package/src/ValApi.ts +0 -81
  9. package/src/expr/README.md +0 -193
  10. package/src/expr/eval.test.ts +0 -198
  11. package/src/expr/eval.ts +0 -251
  12. package/src/expr/expr.ts +0 -91
  13. package/src/expr/index.ts +0 -3
  14. package/src/expr/parser.test.ts +0 -158
  15. package/src/expr/parser.ts +0 -229
  16. package/src/expr/repl.ts +0 -88
  17. package/src/expr/tokenizer.test.ts +0 -539
  18. package/src/expr/tokenizer.ts +0 -117
  19. package/src/fp/array.ts +0 -30
  20. package/src/fp/index.ts +0 -3
  21. package/src/fp/result.ts +0 -214
  22. package/src/fp/util.ts +0 -52
  23. package/src/future/fetchVal.test.ts +0 -164
  24. package/src/future/fetchVal.ts +0 -206
  25. package/src/getSha256.ts +0 -8
  26. package/src/index.ts +0 -132
  27. package/src/initSchema.ts +0 -50
  28. package/src/initVal.ts +0 -73
  29. package/src/module.test.ts +0 -170
  30. package/src/module.ts +0 -397
  31. package/src/patch/deref.test.ts +0 -298
  32. package/src/patch/deref.ts +0 -136
  33. package/src/patch/index.ts +0 -12
  34. package/src/patch/json.test.ts +0 -582
  35. package/src/patch/json.ts +0 -304
  36. package/src/patch/operation.ts +0 -86
  37. package/src/patch/ops.ts +0 -83
  38. package/src/patch/parse.test.ts +0 -202
  39. package/src/patch/parse.ts +0 -202
  40. package/src/patch/patch.ts +0 -49
  41. package/src/patch/util.ts +0 -74
  42. package/src/schema/array.ts +0 -93
  43. package/src/schema/boolean.ts +0 -49
  44. package/src/schema/future/i18n.ts +0 -69
  45. package/src/schema/future/oneOf.ts +0 -63
  46. package/src/schema/image.ts +0 -137
  47. package/src/schema/index.ts +0 -70
  48. package/src/schema/keyOf.ts +0 -167
  49. package/src/schema/literal.ts +0 -63
  50. package/src/schema/number.ts +0 -56
  51. package/src/schema/object.ts +0 -110
  52. package/src/schema/record.ts +0 -103
  53. package/src/schema/richtext.ts +0 -44
  54. package/src/schema/string.ts +0 -95
  55. package/src/schema/union.ts +0 -63
  56. package/src/schema/validation/ValidationError.ts +0 -16
  57. package/src/schema/validation/ValidationFix.ts +0 -6
  58. package/src/schema/validation.test.ts +0 -291
  59. package/src/selector/SelectorProxy.ts +0 -238
  60. package/src/selector/array.ts +0 -13
  61. package/src/selector/boolean.ts +0 -4
  62. package/src/selector/file.ts +0 -6
  63. package/src/selector/future/ExprProxy.test.ts +0 -203
  64. package/src/selector/future/ExprProxy.ts +0 -216
  65. package/src/selector/future/SelectorProxy.test.ts +0 -172
  66. package/src/selector/future/SelectorProxy.ts +0 -238
  67. package/src/selector/future/array.ts +0 -37
  68. package/src/selector/future/boolean.ts +0 -4
  69. package/src/selector/future/file.ts +0 -14
  70. package/src/selector/future/i18n.ts +0 -13
  71. package/src/selector/future/index.ts +0 -169
  72. package/src/selector/future/number.ts +0 -4
  73. package/src/selector/future/object.ts +0 -22
  74. package/src/selector/future/primitive.ts +0 -17
  75. package/src/selector/future/remote.ts +0 -9
  76. package/src/selector/future/selector.test.ts +0 -429
  77. package/src/selector/future/selectorOf.ts +0 -7
  78. package/src/selector/future/string.ts +0 -4
  79. package/src/selector/index.ts +0 -121
  80. package/src/selector/number.ts +0 -4
  81. package/src/selector/object.ts +0 -5
  82. package/src/selector/primitive.ts +0 -4
  83. package/src/selector/string.ts +0 -4
  84. package/src/source/file.ts +0 -45
  85. package/src/source/future/i18n.ts +0 -60
  86. package/src/source/future/remote.ts +0 -54
  87. package/src/source/index.ts +0 -53
  88. package/src/source/link.ts +0 -14
  89. package/src/source/richtext.ts +0 -178
  90. package/src/val/array.ts +0 -10
  91. package/src/val/index.ts +0 -100
  92. package/src/val/object.ts +0 -13
  93. package/src/val/primitive.ts +0 -8
  94. package/tsconfig.json +0 -8
package/src/fp/result.ts DELETED
@@ -1,214 +0,0 @@
1
- import { isNonEmpty, NonEmptyArray } from "./array";
2
-
3
- export type Ok<T> = {
4
- readonly kind: "ok";
5
- readonly value: T;
6
- };
7
- export type Err<E> = {
8
- readonly kind: "err";
9
- readonly error: E;
10
- };
11
-
12
- export type Result<T, E> = Ok<T> | Err<E>;
13
-
14
- /**
15
- * Singleton instance of Ok<void>. Used to optimize results whose Ok values are
16
- * void.
17
- */
18
- export const voidOk: Ok<void> = Object.freeze({
19
- kind: "ok",
20
- value: undefined,
21
- });
22
-
23
- export function ok<T>(value: T): Ok<T> {
24
- if (value === undefined) return voidOk as Ok<T>;
25
- return {
26
- kind: "ok",
27
- value,
28
- };
29
- }
30
-
31
- export function err<E>(error: E): Err<E> {
32
- return {
33
- kind: "err",
34
- error,
35
- };
36
- }
37
-
38
- export function isOk<T, E>(result: Result<T, E>): result is Ok<T> {
39
- return result === voidOk || result.kind === "ok";
40
- }
41
-
42
- export function isErr<T, E>(result: Result<T, E>): result is Err<E> {
43
- return result !== voidOk && result.kind === "err";
44
- }
45
-
46
- export type OkType<R> = R extends Result<infer T, unknown> ? T : never;
47
- export type ErrType<R> = R extends Result<unknown, infer E> ? E : never;
48
-
49
- /**
50
- * If all results are Ok (or if results is empty), returns Ok with all the Ok
51
- * values concatenated into an array. If any result is Err, returns Err with all
52
- * Err values concatenated into an array.
53
- *
54
- * @see {@link all} for use with simple array types.
55
- */
56
- export function allT<T extends unknown[], E>(results: {
57
- readonly [P in keyof T]: Result<T[P], E>;
58
- }): Result<T, NonEmptyArray<E>> {
59
- const values: T[number][] = [];
60
- const errors: E[] = [];
61
- for (const result of results) {
62
- if (isOk(result)) {
63
- values.push(result.value);
64
- } else {
65
- errors.push(result.error);
66
- }
67
- }
68
- if (isNonEmpty(errors)) {
69
- return err(errors);
70
- } else {
71
- return ok(values as T);
72
- }
73
- }
74
-
75
- /**
76
- * If all results are Ok (or if results is empty), returns Ok with all the Ok
77
- * values concatenated into an array. If any result is Err, returns Err with all
78
- * Err values concatenated into an array.
79
- *
80
- * @see {@link allT} for use with tuple types.
81
- */
82
- export function all<T, E>(
83
- results: readonly Result<T, E>[]
84
- ): Result<T[], NonEmptyArray<E>> {
85
- return allT<T[], E>(results);
86
- }
87
-
88
- /**
89
- * If all results are Ok (or if results is empty), returns Ok. If any result is
90
- * Err, returns Err with all Err values concatenated into an array.
91
- */
92
- export function allV<E>(
93
- results: readonly Result<unknown, E>[]
94
- ): Result<void, NonEmptyArray<E>> {
95
- const errs: E[] = [];
96
- for (const result of results) {
97
- if (isErr(result)) {
98
- errs.push(result.error);
99
- }
100
- }
101
- if (isNonEmpty(errs)) {
102
- return err(errs);
103
- }
104
- return voidOk;
105
- }
106
-
107
- /**
108
- * Perform a reduction over an array with a Result-returning reducer. If the
109
- * reducer returns Ok, its value is used as the next value. If the reducer
110
- * returns Err, it is returned immediately.
111
- *
112
- * flatMapReduce is a short-circuiting equivalent to:
113
- * ```
114
- * arr.reduce(
115
- * (accRes, current, currentIndex) =>
116
- * flatMap((acc) => reducer(acc, current, currentIndex))(accRes),
117
- * ok(initVal)
118
- * )
119
- * ```
120
- */
121
- export function flatMapReduce<T, E, A>(
122
- reducer: (acc: T, current: A, currentIndex: number) => Result<T, E>,
123
- initVal: T
124
- ): (arr: readonly A[]) => Result<T, E> {
125
- return (arr) => {
126
- let val: Result<T, E> = ok(initVal);
127
- for (let i = 0; i < arr.length && isOk(val); ++i) {
128
- val = reducer(val.value, arr[i], i);
129
- }
130
- return val;
131
- };
132
- }
133
-
134
- export function map<T0, T1>(
135
- onOk: (value: T0) => T1
136
- ): <E>(result: Result<T0, E>) => Result<T1, E> {
137
- return (result) => {
138
- if (isOk(result)) {
139
- return ok(onOk(result.value));
140
- } else {
141
- return result;
142
- }
143
- };
144
- }
145
-
146
- export function flatMap<T0, T1, E1>(
147
- onOk: (value: T0) => Result<T1, E1>
148
- ): <E>(result: Result<T0, E>) => Result<T1, E | E1> {
149
- return (result) => {
150
- if (isOk(result)) {
151
- return onOk(result.value);
152
- } else {
153
- return result;
154
- }
155
- };
156
- }
157
-
158
- export function mapErr<E0, E1>(
159
- onErr: (error: E0) => E1
160
- ): <T>(result: Result<T, E0>) => Result<T, E1> {
161
- return (result) => {
162
- if (isErr(result)) {
163
- return err(onErr(result.error));
164
- } else {
165
- return result;
166
- }
167
- };
168
- }
169
-
170
- export function fromPredicate<T0, T1 extends T0, E>(
171
- refinement: (value: T0) => value is T1,
172
- onFalse: (value: T0) => E
173
- ): (value: T0) => Result<T1, E>;
174
- export function fromPredicate<T0, E>(
175
- refinement: (value: T0) => boolean,
176
- onFalse: (value: T0) => E
177
- ): <T1 extends T0>(value: T1) => Result<T1, E> {
178
- return (value) => {
179
- if (refinement(value)) {
180
- return ok(value);
181
- } else {
182
- return err(onFalse(value));
183
- }
184
- };
185
- }
186
-
187
- // NOTE: Function overload resolution seems to fail when declared as overloaded
188
- // function type, so a value with a callable type is used instead.
189
- export const filterOrElse: {
190
- <T0, T1 extends T0, E>(
191
- refinement: (value: T0) => value is T1,
192
- onFalse: (value: T0) => E
193
- ): (result: Result<T0, E>) => Result<T1, E>;
194
- <T0, E>(refinement: (value: T0) => boolean, onFalse: (value: T0) => E): <
195
- T1 extends T0
196
- >(
197
- result: Result<T1, E>
198
- ) => Result<T1, E>;
199
- } = <T0, E>(
200
- refinement: (value: T0) => boolean,
201
- onFalse: (value: T0) => E
202
- ): (<T1 extends T0>(result: Result<T1, E>) => Result<T1, E>) => {
203
- return (result) => {
204
- if (isOk(result)) {
205
- if (refinement(result.value)) {
206
- return result;
207
- } else {
208
- return err(onFalse(result.value));
209
- }
210
- } else {
211
- return result;
212
- }
213
- };
214
- };
package/src/fp/util.ts DELETED
@@ -1,52 +0,0 @@
1
- export function pipe<A>(a: A): A;
2
- export function pipe<A, B>(a: A, ab: (a: A) => B): B;
3
- export function pipe<A, B, C>(a: A, ab: (a: A) => B, bc: (b: B) => C): C;
4
- export function pipe<A, B, C, D>(
5
- a: A,
6
- ab: (a: A) => B,
7
- bc: (b: B) => C,
8
- cd: (c: C) => D
9
- ): D;
10
- export function pipe<A, B, C, D, E>(
11
- a: A,
12
- ab: (a: A) => B,
13
- bc: (b: B) => C,
14
- cd: (c: C) => D,
15
- de: (d: D) => E
16
- ): E;
17
- export function pipe<A, B, C, D, E, F>(
18
- a: A,
19
- ab: (a: A) => B,
20
- bc: (b: B) => C,
21
- cd: (c: C) => D,
22
- de: (d: D) => E,
23
- ef: (e: E) => F
24
- ): F;
25
- // "Ought to be enough for everybody" -- attributed to E. Åmdal
26
- export function pipe<A, B, C, D, E, F, G>(
27
- a: A,
28
- ab: (a: A) => B,
29
- bc: (b: B) => C,
30
- cd: (c: C) => D,
31
- de: (d: D) => E,
32
- ef: (e: E) => F,
33
- fg: (f: F) => G
34
- ): G;
35
- export function pipe(a: unknown, ...fns: ((u: unknown) => unknown)[]): unknown {
36
- let current = a;
37
- for (const fn of fns) {
38
- current = fn(current);
39
- }
40
- return current;
41
- }
42
-
43
- /**
44
- * Runs the callback with the supplied value, then returns the value. Useful for
45
- * debugging pipes.
46
- */
47
- export function tap<T>(callback: (value: T) => void): (value: T) => T {
48
- return (value) => {
49
- callback(value);
50
- return value;
51
- };
52
- }
@@ -1,164 +0,0 @@
1
- import { initSchema } from "../initSchema";
2
- import { content } from "../module";
3
- import { getValPath } from "../val";
4
- import { serializedValOfSelectorSource, fetchVal } from "./fetchVal";
5
-
6
- const s = initSchema();
7
- // const i18n = initI18n(["en_US", "no_NB"]);
8
-
9
- describe("serialization of val", () => {
10
- test("serialized val: string", () => {
11
- const schema = s.string();
12
-
13
- const testVal = content("/app", schema, "foo");
14
-
15
- expect(serializedValOfSelectorSource(testVal)).toStrictEqual({
16
- val: "foo",
17
- valPath: "/app",
18
- });
19
- });
20
-
21
- test("serialized val: array", () => {
22
- const schema = s.array(s.string());
23
-
24
- const testVal = content("/app", schema, ["foo", "bar"]);
25
-
26
- expect(serializedValOfSelectorSource(testVal)).toStrictEqual({
27
- val: [
28
- {
29
- val: "foo",
30
- valPath: "/app.0",
31
- },
32
- { val: "bar", valPath: "/app.1" },
33
- ],
34
- valPath: "/app",
35
- });
36
-
37
- // ^?
38
- });
39
-
40
- test("serialized val: object", () => {
41
- const schema = s.object({ foo: s.object({ bar: s.array(s.string()) }) });
42
-
43
- const testVal = content("/app", schema, { foo: { bar: ["foo", "bar"] } });
44
-
45
- expect(serializedValOfSelectorSource(testVal)).toStrictEqual({
46
- val: {
47
- foo: {
48
- val: {
49
- bar: {
50
- val: [
51
- {
52
- val: "foo",
53
- valPath: '/app."foo"."bar".0',
54
- },
55
- { val: "bar", valPath: '/app."foo"."bar".1' },
56
- ],
57
- valPath: '/app."foo"."bar"',
58
- },
59
- },
60
- valPath: '/app."foo"',
61
- },
62
- },
63
- valPath: "/app",
64
- });
65
- });
66
- });
67
-
68
- describe("fetchVal", () => {
69
- test("valuate: string", async () => {
70
- const schema = s.string();
71
-
72
- const testVal = content("/app", schema, "foo");
73
-
74
- const test = await fetchVal(testVal);
75
- // ^? should be Val<string>
76
- expect(test.val).toBe("foo");
77
- expect(getValPath(test)).toBe("/app");
78
- });
79
-
80
- test("valuate: array", async () => {
81
- const schema = s.array(s.string());
82
-
83
- const testVal = content("/app", schema, ["foo", "bar"]);
84
-
85
- const test = await fetchVal(testVal);
86
- // ^? should be Val<string[]>
87
- expect(test.val).toStrictEqual(["foo", "bar"]);
88
- expect(test[0].val).toStrictEqual("foo");
89
- expect(test[1].val).toStrictEqual("bar");
90
- expect(getValPath(test[0])).toStrictEqual("/app.0");
91
- expect(getValPath(test[1])).toStrictEqual("/app.1");
92
- });
93
-
94
- test("valuate: object", async () => {
95
- const schema = s.object({ foo: s.object({ bar: s.array(s.string()) }) });
96
-
97
- const testVal = content("/app", schema, { foo: { bar: ["foo", "bar"] } });
98
-
99
- const test = await fetchVal(testVal);
100
- // ^? should be Val<{ foo: { bar: string[] } }>
101
-
102
- expect(test.val).toStrictEqual({ foo: { bar: ["foo", "bar"] } });
103
- expect(test.foo.val).toStrictEqual({ bar: ["foo", "bar"] });
104
- expect(test.foo.bar.val).toStrictEqual(["foo", "bar"]);
105
- expect(test.foo.bar[0].val).toStrictEqual("foo");
106
- expect(test.foo.bar[1].val).toStrictEqual("bar");
107
- expect(getValPath(test.foo.bar[0])).toStrictEqual('/app."foo"."bar".0');
108
- expect(getValPath(test.foo.bar[1])).toStrictEqual('/app."foo"."bar".1');
109
- });
110
-
111
- // test("valuate: array with map", async () => {
112
- // const schema = s.array(s.string());
113
-
114
- // const testVal = content("/app", schema, ["foo", "bar"]);
115
-
116
- // const test = await fetchVal({
117
- // // ^? should be Val<{ title: string }[]>
118
- // foo: testVal.map((v) => ({ title: v })),
119
- // test: testVal,
120
- // });
121
- // expect(test.val).toStrictEqual({
122
- // foo: [{ title: "foo" }, { title: "bar" }],
123
- // test: ["foo", "bar"],
124
- // });
125
- // });
126
-
127
- // test("valuate: 2 modules with oneOf", async () => {
128
- // const testVal1 = content("/testVal1", s.array(s.string()), [
129
- // "test-val-1-0",
130
- // "test-val-1-1",
131
- // ]);
132
- // const testVal2 = content(
133
- // "/testVal2",
134
- // s.object({ test1: s.oneOf(testVal1), test2: s.string() }),
135
- // {
136
- // test2: "test2 value",
137
- // test1: testVal1[0],
138
- // }
139
- // );
140
-
141
- // const test = await fetchVal({
142
- // // ^?
143
- // testVal1: testVal1.map((v) => ({ title: v, otherModule: testVal2 })),
144
- // testVal2: testVal2,
145
- // });
146
- // expect(test.val).toStrictEqual({
147
- // testVal1: [
148
- // {
149
- // title: "test-val-1-0",
150
- // otherModule: { test2: "test2 value", test1: "test-val-1-0" },
151
- // },
152
- // {
153
- // title: "test-val-1-1",
154
- // otherModule: { test2: "test2 value", test1: "test-val-1-0" },
155
- // },
156
- // ],
157
- // testVal2: { test2: "test2 value", test1: "test-val-1-0" },
158
- // });
159
- // expect(getValPath(test.testVal1[0].otherModule.test1)).toStrictEqual(
160
- // "/testVal1.0"
161
- // );
162
- // expect(getValPath(test.testVal2.test2)).toStrictEqual('/testVal2."test2"');
163
- // });
164
- });
@@ -1,206 +0,0 @@
1
- import {
2
- GenericSelector,
3
- Path,
4
- SelectorOf,
5
- SelectorSource,
6
- GetSource,
7
- } from "../selector";
8
- import {
9
- isSerializedVal,
10
- JsonOfSource,
11
- SerializedVal,
12
- SourcePath,
13
- Val,
14
- } from "../val";
15
- import {
16
- createValPathOfItem,
17
- isSelector,
18
- newSelectorProxy,
19
- } from "../selector/SelectorProxy";
20
- import { Json } from "../Json";
21
-
22
- export function fetchVal<T extends SelectorSource>(
23
- selector: T
24
- ): SelectorOf<T> extends GenericSelector<infer S>
25
- ? Promise<Val<JsonOfSource<S>>>
26
- : never {
27
- return Promise.resolve(
28
- getVal(selector) as unknown
29
- ) as SelectorOf<T> extends GenericSelector<infer S>
30
- ? Promise<Val<JsonOfSource<S>>>
31
- : never;
32
- }
33
-
34
- export function getVal<T extends SelectorSource>(
35
- selector: T
36
- ): SelectorOf<T> extends GenericSelector<infer S>
37
- ? Val<JsonOfSource<S>>
38
- : never {
39
- return newValProxy(
40
- serializedValOfSelectorSource(selector)
41
- ) as SelectorOf<T> extends GenericSelector<infer S>
42
- ? Val<JsonOfSource<S>>
43
- : never;
44
- }
45
-
46
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
- function isArrayOrArraySelector(child: any) {
48
- if (isSelector(child)) {
49
- return (
50
- typeof child[GetSource] === "object" &&
51
- typeof child[GetSource] !== null &&
52
- Array.isArray(child[GetSource])
53
- );
54
- }
55
- return Array.isArray(child);
56
- }
57
-
58
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
- function isObjectOrObjectSelector(child: any) {
60
- if (isSelector(child)) {
61
- return (
62
- typeof child[GetSource] === "object" &&
63
- typeof child[GetSource] !== null &&
64
- !Array.isArray(child[GetSource])
65
- );
66
- }
67
- return typeof child === "object";
68
- }
69
-
70
- export function serializedValOfSelectorSource<T extends SelectorSource>(
71
- selector: T
72
- ) {
73
- const wrappedSelector = newSelectorProxy(selector); // NOTE: we do this if call-site uses a literal with selectors inside
74
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
75
- function rec(child: any): any {
76
- const isArray = isArrayOrArraySelector(child);
77
- const isObject = isObjectOrObjectSelector(child);
78
- if (isArray) {
79
- const array = (
80
- GetSource in child ? child[GetSource] : child
81
- ) as Array<unknown>;
82
- const valPath = Path in child ? (child[Path] as SourcePath) : undefined;
83
- return {
84
- val: array.map((item, i) =>
85
- rec(
86
- isSelector(item) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
87
- ? item
88
- : newSelectorProxy(item, createValPathOfItem(valPath, i))
89
- )
90
- ),
91
- valPath,
92
- };
93
- } else if (isObject) {
94
- const obj = (GetSource in child ? child[GetSource] : child) as object;
95
- const valPath = Path in child ? (child[Path] as SourcePath) : undefined;
96
- return {
97
- val:
98
- obj !== null &&
99
- Object.fromEntries(
100
- Object.entries(obj).map(([key, value]) => [
101
- key,
102
- rec(
103
- isSelector(value) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
104
- ? value
105
- : newSelectorProxy(value, createValPathOfItem(valPath, key))
106
- ),
107
- ])
108
- ),
109
- valPath,
110
- };
111
- } else if (isSelector(child)) {
112
- return {
113
- val: rec(child[GetSource]),
114
- valPath: child[Path],
115
- };
116
- } else {
117
- return child;
118
- }
119
- }
120
-
121
- return rec(wrappedSelector);
122
- }
123
-
124
- function strip(value: SerializedVal | Json): Json {
125
- const val = isSerializedVal(value) ? value.val : value;
126
- switch (typeof val) {
127
- case "function":
128
- case "symbol":
129
- throw Error(`Invalid val type: ${typeof val}`);
130
- case "object":
131
- if (val === null) {
132
- return null;
133
- } else if (Array.isArray(val)) {
134
- return val.map(strip);
135
- } else {
136
- return Object.fromEntries(
137
- Object.entries(val).map(([key, value]) => [
138
- key,
139
- value && strip(value),
140
- ])
141
- ) as Json;
142
- }
143
- // intentional fallthrough
144
- // eslint-disable-next-line no-fallthrough
145
- default:
146
- return val;
147
- }
148
- }
149
-
150
- function newValProxy<T extends Json>(val: SerializedVal): Val<T> {
151
- const source = val.val;
152
- switch (typeof source) {
153
- case "function":
154
- case "symbol":
155
- throw Error(`Invalid val type: ${typeof source}`);
156
- case "object":
157
- if (source !== null) {
158
- // Handles both objects and arrays!
159
- return new Proxy(source, {
160
- has(target, prop: string | symbol) {
161
- if (prop === "val") {
162
- return true;
163
- }
164
- if (prop === Path) {
165
- return true;
166
- }
167
- return hasOwn(target, prop);
168
- },
169
- get(target, prop: string | symbol) {
170
- if (prop === Path) {
171
- return val.valPath;
172
- }
173
- if (prop === "val") {
174
- return strip(val);
175
- }
176
- if (Array.isArray(target) && prop === "length") {
177
- return target.length;
178
- }
179
- if (hasOwn(source, prop)) {
180
- return newValProxy({
181
- val: Reflect.get(target, prop).val,
182
- valPath:
183
- Reflect.get(target, prop)?.valPath ??
184
- createValPathOfItem(
185
- val.valPath,
186
- Array.isArray(target) ? Number(prop) : prop
187
- ),
188
- } as SerializedVal);
189
- }
190
- return Reflect.get(target, prop);
191
- },
192
- }) as unknown as Val<T>;
193
- }
194
- // intentional fallthrough
195
- // eslint-disable-next-line no-fallthrough
196
- default:
197
- return {
198
- [Path]: val.valPath,
199
- val: val.val,
200
- } as Val<T>;
201
- }
202
- }
203
-
204
- function hasOwn<T extends PropertyKey>(obj: object, prop: T): boolean {
205
- return Object.prototype.hasOwnProperty.call(obj, prop);
206
- }
package/src/getSha256.ts DELETED
@@ -1,8 +0,0 @@
1
- export const getSHA256Hash = async (bits: Uint8Array) => {
2
- const hashBuffer = await crypto.subtle.digest("SHA-256", bits);
3
- const hashArray = Array.from(new Uint8Array(hashBuffer));
4
- const hash = hashArray
5
- .map((item) => item.toString(16).padStart(2, "0"))
6
- .join("");
7
- return hash;
8
- };