@soundscript/soundscript 0.1.1 → 0.1.3
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/README.md +1 -1
- package/async.d.ts +3 -3
- package/async.js +2 -2
- package/async.js.map +1 -1
- package/codec.d.ts +3 -2
- package/codec.js +2 -2
- package/codec.js.map +1 -1
- package/compare.js +5 -10
- package/compare.js.map +1 -1
- package/decode.d.ts +6 -4
- package/decode.js +5 -5
- package/decode.js.map +1 -1
- package/derive.d.ts +6 -0
- package/derive.js +8 -0
- package/derive.js.map +1 -0
- package/encode.d.ts +11 -9
- package/encode.js +5 -5
- package/encode.js.map +1 -1
- package/experimental/thunk.js.map +1 -0
- package/fetch.d.ts +67 -0
- package/fetch.js +6 -0
- package/fetch.js.map +1 -0
- package/hash.js +9 -14
- package/hash.js.map +1 -1
- package/json.d.ts +29 -2
- package/json.js +124 -1
- package/json.js.map +1 -1
- package/numerics.d.ts +523 -0
- package/numerics.js +1357 -0
- package/numerics.js.map +1 -0
- package/package.json +122 -35
- package/random.d.ts +19 -0
- package/random.js +4 -0
- package/random.js.map +1 -0
- package/result.d.ts +21 -5
- package/result.js +55 -19
- package/result.js.map +1 -1
- package/soundscript/async.sts +7 -7
- package/soundscript/codec.sts +8 -7
- package/soundscript/compare.sts +5 -13
- package/soundscript/decode.sts +15 -13
- package/soundscript/derive.sts +7 -0
- package/soundscript/encode.sts +18 -16
- package/soundscript/fetch.sts +11 -0
- package/soundscript/hash.sts +9 -17
- package/soundscript/json.sts +209 -3
- package/soundscript/numerics.sts +1937 -0
- package/soundscript/random.sts +5 -0
- package/soundscript/result.sts +93 -24
- package/soundscript/text.sts +4 -0
- package/soundscript/typeclasses.sts +22 -16
- package/soundscript/url.sts +4 -0
- package/soundscript/value.sts +133 -0
- package/text.d.ts +24 -0
- package/text.js +4 -0
- package/text.js.map +1 -0
- package/typeclasses.d.ts +2 -2
- package/typeclasses.js +10 -9
- package/typeclasses.js.map +1 -1
- package/url.d.ts +37 -0
- package/url.js +4 -0
- package/url.js.map +1 -0
- package/value.d.ts +9 -0
- package/value.js +105 -0
- package/value.js.map +1 -0
- package/experimental/component.d.ts +0 -40
- package/experimental/component.js +0 -46
- package/experimental/component.js.map +0 -1
- package/soundscript/experimental/component.sts +0 -69
- package/thunk.js.map +0 -1
- /package/{thunk.d.ts → experimental/thunk.d.ts} +0 -0
- /package/{thunk.js → experimental/thunk.js} +0 -0
- /package/soundscript/{thunk.sts → experimental/thunk.sts} +0 -0
package/fetch.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { URL, URLSearchParams } from '@soundscript/soundscript/url';
|
|
2
|
+
|
|
3
|
+
export interface AbortSignal {
|
|
4
|
+
readonly aborted: boolean;
|
|
5
|
+
readonly reason: unknown;
|
|
6
|
+
throwIfAborted(): void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type HeadersInit = Headers | Iterable<readonly [string, string]> | Record<string, string>;
|
|
10
|
+
export type BodyInit = ArrayBuffer | string | Uint8Array<ArrayBufferLike> | URLSearchParams;
|
|
11
|
+
export type RequestInfo = Request | string | URL;
|
|
12
|
+
|
|
13
|
+
export interface RequestInit {
|
|
14
|
+
readonly body?: BodyInit | null;
|
|
15
|
+
readonly headers?: HeadersInit;
|
|
16
|
+
readonly method?: string;
|
|
17
|
+
readonly signal?: AbortSignal | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ResponseInit {
|
|
21
|
+
readonly headers?: HeadersInit;
|
|
22
|
+
readonly status?: number;
|
|
23
|
+
readonly statusText?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export declare class Headers {
|
|
27
|
+
constructor(init?: HeadersInit);
|
|
28
|
+
append(name: string, value: string): void;
|
|
29
|
+
delete(name: string): void;
|
|
30
|
+
entries(): IterableIterator<[string, string]>;
|
|
31
|
+
get(name: string): string | null;
|
|
32
|
+
has(name: string): boolean;
|
|
33
|
+
keys(): IterableIterator<string>;
|
|
34
|
+
set(name: string, value: string): void;
|
|
35
|
+
values(): IterableIterator<string>;
|
|
36
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export declare class Request {
|
|
40
|
+
constructor(input: RequestInfo, init?: RequestInit);
|
|
41
|
+
readonly headers: Headers;
|
|
42
|
+
readonly method: string;
|
|
43
|
+
readonly signal: AbortSignal;
|
|
44
|
+
readonly url: string;
|
|
45
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
46
|
+
clone(): Request;
|
|
47
|
+
json(): Promise<unknown>;
|
|
48
|
+
text(): Promise<string>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export declare class Response {
|
|
52
|
+
constructor(body?: BodyInit | null, init?: ResponseInit);
|
|
53
|
+
readonly headers: Headers;
|
|
54
|
+
readonly ok: boolean;
|
|
55
|
+
readonly status: number;
|
|
56
|
+
readonly statusText: string;
|
|
57
|
+
readonly url: string;
|
|
58
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
59
|
+
clone(): Response;
|
|
60
|
+
json(): Promise<unknown>;
|
|
61
|
+
text(): Promise<string>;
|
|
62
|
+
static error(): Response;
|
|
63
|
+
static json(data: unknown, init?: ResponseInit): Response;
|
|
64
|
+
static redirect(url: string | URL, status?: number): Response;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
|
package/fetch.js
ADDED
package/fetch.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["./soundscript/fetch.sts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,KAAK,CAAC;AACtB,MAAM,WAAW,GAAG,OAAO,CAAC;AAC5B,MAAM,WAAW,GAAG,OAAO,CAAC;AAC5B,MAAM,YAAY,GAAG,QAAQ,CAAC;AAE9B,OAAO,EACL,OAAO,IAAI,KAAK,EAChB,WAAW,IAAI,OAAO,EACtB,WAAW,IAAI,OAAO,EACtB,YAAY,IAAI,QAAQ,GACzB,CAAC","sourcesContent":["const fetchFn = fetch;\nconst HeadersCtor = Headers;\nconst RequestCtor = Request;\nconst ResponseCtor = Response;\n\nexport {\n fetchFn as fetch,\n HeadersCtor as Headers,\n RequestCtor as Request,\n ResponseCtor as Response,\n};\n"]}
|
package/hash.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isErr, isNone, isOk, isSome } from '@soundscript/soundscript/result';
|
|
1
2
|
export function fromHashEq(hash, equals) {
|
|
2
3
|
return {
|
|
3
4
|
hash(value) {
|
|
@@ -51,29 +52,23 @@ export function tupleHash(...elements) {
|
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
54
|
export function optionHash(itemHash) {
|
|
54
|
-
return fromHashEq((value) => value
|
|
55
|
-
? combineHashes(stringHash.hash('
|
|
56
|
-
: stringHash.hash('
|
|
57
|
-
if (left
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
if (left.tag === 'ok' && right.tag === 'ok') {
|
|
55
|
+
return fromHashEq((value) => isSome(value)
|
|
56
|
+
? combineHashes(stringHash.hash('some'), itemHash.hash(value.value))
|
|
57
|
+
: stringHash.hash('none'), (left, right) => {
|
|
58
|
+
if (isSome(left) && isSome(right)) {
|
|
61
59
|
return itemHash.equals(left.value, right.value);
|
|
62
60
|
}
|
|
63
|
-
return
|
|
61
|
+
return isNone(left) && isNone(right);
|
|
64
62
|
});
|
|
65
63
|
}
|
|
66
64
|
export function resultHash(okHash, errHash) {
|
|
67
|
-
return fromHashEq((value) => value
|
|
65
|
+
return fromHashEq((value) => isOk(value)
|
|
68
66
|
? combineHashes(stringHash.hash('ok'), okHash.hash(value.value))
|
|
69
67
|
: combineHashes(stringHash.hash('err'), errHash.hash(value.error)), (left, right) => {
|
|
70
|
-
if (left
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
if (left.tag === 'ok' && right.tag === 'ok') {
|
|
68
|
+
if (isOk(left) && isOk(right)) {
|
|
74
69
|
return okHash.equals(left.value, right.value);
|
|
75
70
|
}
|
|
76
|
-
if (left
|
|
71
|
+
if (isErr(left) && isErr(right)) {
|
|
77
72
|
return errHash.equals(left.error, right.error);
|
|
78
73
|
}
|
|
79
74
|
return false;
|
package/hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","sourceRoot":"","sources":["./soundscript/hash.sts"],"names":[],"mappings":"AAaA,MAAM,UAAU,UAAU,CACxB,IAA4B,EAC5B,MAAsC;IAEtC,OAAO;QACL,IAAI,CAAC,KAAK;YACR,OAAO,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACxC,CAAC;QACD,MAAM;KACP,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,SAAS,CACvB,MAAiB,EACjB,OAAwB;IAExB,OAAO,UAAU,CACf,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EACtC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAC9D,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAI,SAA0B;IACtD,OAAO,UAAU,CACf,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAClC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CACjD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,SAAS,CAAI,QAAmB;IAC9C,OAAO,UAAU,CACf,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,KA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a;IAC/B,IAAI,IAAI,GAAG,UAAU,CAAC;IACtB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACrD,IAAI,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,IAAI,GAAG,CAAC,CAAC;AAClB,CAAC","sourcesContent":["import type { Eq } from '@soundscript/soundscript/compare';\nimport type { Option, Result } from '@soundscript/soundscript/result';\n\nexport type HashCode = number;\n\nexport interface Hash<T> {\n hash(value: T): HashCode;\n}\n\nexport interface HashEq<T> extends Hash<T>, Eq<T> {}\n\ntype HashEqValue<THashEq> = THashEq extends HashEq<infer TValue> ? TValue : never;\n\nexport function fromHashEq<T>(\n hash: (value: T) => HashCode,\n equals: (left: T, right: T) => boolean,\n): HashEq<T> {\n return {\n hash(value) {\n return normalizeHashCode(hash(value));\n },\n equals,\n };\n}\n\nexport function contramap<A, B>(\n hashEq: HashEq<A>,\n project: (value: B) => A,\n): HashEq<B> {\n return fromHashEq(\n (value) => hashEq.hash(project(value)),\n (left, right) => hashEq.equals(project(left), project(right)),\n );\n}\n\nexport function lazyHashEq<T>(getHashEq: () => HashEq<T>): HashEq<T> {\n return fromHashEq(\n (value) => getHashEq().hash(value),\n (left, right) => getHashEq().equals(left, right),\n );\n}\n\nexport function arrayHash<T>(itemHash: HashEq<T>): HashEq<readonly T[]> {\n return fromHashEq(\n (value) => combineHashes(...value.map((entry) => itemHash.hash(entry))),\n (left, right) => {\n if (left.length !== right.length) {\n return false;\n }\n\n for (let index = 0; index < left.length; index += 1) {\n if (!itemHash.equals(left[index]!, right[index]!)) {\n return false;\n }\n }\n\n return true;\n },\n );\n}\n\nexport function tupleHash<const THashEqs extends readonly HashEq<unknown>[]>(\n ...elements: THashEqs\n): HashEq<{ readonly [K in keyof THashEqs]: HashEqValue<THashEqs[K]> }> {\n return fromHashEq(\n (value) => {\n const values = value as readonly unknown[];\n if (values.length !== elements.length) {\n return 0;\n }\n return combineHashes(\n ...elements.map((elementHash, index) => elementHash.hash(values[index])),\n );\n },\n (left, right) => {\n const leftValues = left as readonly unknown[];\n const rightValues = right as readonly unknown[];\n if (leftValues.length !== elements.length || rightValues.length !== elements.length) {\n return false;\n }\n\n for (let index = 0; index < elements.length; index += 1) {\n const elementHash = elements[index];\n if (!elementHash) {\n continue;\n }\n if (!elementHash.equals(leftValues[index], rightValues[index])) {\n return false;\n }\n }\n\n return true;\n },\n );\n}\n\nexport function optionHash<T>(itemHash: HashEq<T>): HashEq<Option<T>> {\n return fromHashEq(\n (value) =>\n value.tag === 'ok'\n ? combineHashes(stringHash.hash('ok'), itemHash.hash(value.value))\n : stringHash.hash('err'),\n (left, right) => {\n if (left.tag !== right.tag) {\n return false;\n }\n\n if (left.tag === 'ok' && right.tag === 'ok') {\n return itemHash.equals(left.value, right.value);\n }\n\n return true;\n },\n );\n}\n\nexport function resultHash<T, E>(okHash: HashEq<T>, errHash: HashEq<E>): HashEq<Result<T, E>> {\n return fromHashEq(\n (value) =>\n value.tag === 'ok'\n ? combineHashes(stringHash.hash('ok'), okHash.hash(value.value))\n : combineHashes(stringHash.hash('err'), errHash.hash(value.error)),\n (left, right) => {\n if (left.tag !== right.tag) {\n return false;\n }\n\n if (left.tag === 'ok' && right.tag === 'ok') {\n return okHash.equals(left.value, right.value);\n }\n\n if (left.tag === 'err' && right.tag === 'err') {\n return errHash.equals(left.error, right.error);\n }\n\n return false;\n },\n );\n}\n\nexport const stringHash: HashEq<string> = fromHashEq(\n hashString,\n (left, right) => left === right,\n);\n\nexport const numberHash: HashEq<number> = fromHashEq(\n (value) => hashString(normalizeNumberKey(value)),\n (left, right) => left === right || (Number.isNaN(left) && Number.isNaN(right)),\n);\n\nexport const booleanHash: HashEq<boolean> = fromHashEq(\n (value) => value ? 1 : 0,\n (left, right) => left === right,\n);\n\nexport const bigintHash: HashEq<bigint> = fromHashEq(\n (value) => hashString(value.toString()),\n (left, right) => left === right,\n);\n\nexport function combineHashes(...hashes: readonly HashCode[]): HashCode {\n let hash = 0;\n for (const value of hashes) {\n hash = Math.imul(hash ^ normalizeHashCode(value), 0x01000193);\n }\n return normalizeHashCode(hash);\n}\n\nfunction normalizeHashCode(value: number): HashCode {\n if (!Number.isFinite(value)) {\n return 0;\n }\n\n return value | 0;\n}\n\nfunction normalizeNumberKey(value: number): string {\n if (Number.isNaN(value)) {\n return 'NaN';\n }\n\n if (value === 0) {\n return '0';\n }\n\n return String(value);\n}\n\nfunction hashString(value: string): HashCode {\n let hash = 0x811c9dc5;\n for (let index = 0; index < value.length; index += 1) {\n hash ^= value.charCodeAt(index);\n hash = Math.imul(hash, 0x01000193);\n }\n return hash | 0;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["./soundscript/hash.sts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAA4B,MAAM,iCAAiC,CAAC;AAYxG,MAAM,UAAU,UAAU,CACxB,IAA4B,EAC5B,MAAsC;IAEtC,OAAO;QACL,IAAI,CAAC,KAAK;YACR,OAAO,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACxC,CAAC;QACD,MAAM;KACP,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,SAAS,CACvB,MAAiB,EACjB,OAAwB;IAExB,OAAO,UAAU,CACf,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EACtC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAC9D,CAAC;AACJ,CAAC;AAED,MAA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OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QAChB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,IAAI,IAAI,GAAG,UAAU,CAAC;IACtB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACrD,IAAI,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,IAAI,GAAG,CAAC,CAAC;AAClB,CAAC","sourcesContent":["import type { Eq } from '@soundscript/soundscript/compare';\nimport { isErr, isNone, isOk, isSome, type Option, type Result } from '@soundscript/soundscript/result';\n\nexport type HashCode = number;\n\nexport interface Hash<T> {\n hash(value: T): HashCode;\n}\n\nexport interface HashEq<T> extends Hash<T>, Eq<T> {}\n\ntype HashEqValue<THashEq> = THashEq extends HashEq<infer TValue> ? TValue : never;\n\nexport function fromHashEq<T>(\n hash: (value: T) => HashCode,\n equals: (left: T, right: T) => boolean,\n): HashEq<T> {\n return {\n hash(value) {\n return normalizeHashCode(hash(value));\n },\n equals,\n };\n}\n\nexport function contramap<A, B>(\n hashEq: HashEq<A>,\n project: (value: B) => A,\n): HashEq<B> {\n return fromHashEq(\n (value) => hashEq.hash(project(value)),\n (left, right) => hashEq.equals(project(left), project(right)),\n );\n}\n\nexport function lazyHashEq<T>(getHashEq: () => HashEq<T>): HashEq<T> {\n return fromHashEq(\n (value) => getHashEq().hash(value),\n (left, right) => getHashEq().equals(left, right),\n );\n}\n\nexport function arrayHash<T>(itemHash: HashEq<T>): HashEq<readonly T[]> {\n return fromHashEq(\n (value) => combineHashes(...value.map((entry) => itemHash.hash(entry))),\n (left, right) => {\n if (left.length !== right.length) {\n return false;\n }\n\n for (let index = 0; index < left.length; index += 1) {\n if (!itemHash.equals(left[index]!, right[index]!)) {\n return false;\n }\n }\n\n return true;\n },\n );\n}\n\nexport function tupleHash<const THashEqs extends readonly HashEq<unknown>[]>(\n ...elements: THashEqs\n): HashEq<{ readonly [K in keyof THashEqs]: HashEqValue<THashEqs[K]> }> {\n return fromHashEq(\n (value) => {\n const values = value as readonly unknown[];\n if (values.length !== elements.length) {\n return 0;\n }\n return combineHashes(\n ...elements.map((elementHash, index) => elementHash.hash(values[index])),\n );\n },\n (left, right) => {\n const leftValues = left as readonly unknown[];\n const rightValues = right as readonly unknown[];\n if (leftValues.length !== elements.length || rightValues.length !== elements.length) {\n return false;\n }\n\n for (let index = 0; index < elements.length; index += 1) {\n const elementHash = elements[index];\n if (!elementHash) {\n continue;\n }\n if (!elementHash.equals(leftValues[index], rightValues[index])) {\n return false;\n }\n }\n\n return true;\n },\n );\n}\n\nexport function optionHash<T>(itemHash: HashEq<T>): HashEq<Option<T>> {\n return fromHashEq(\n (value) =>\n isSome(value)\n ? combineHashes(stringHash.hash('some'), itemHash.hash(value.value))\n : stringHash.hash('none'),\n (left, right) => {\n if (isSome(left) && isSome(right)) {\n return itemHash.equals(left.value, right.value);\n }\n\n return isNone(left) && isNone(right);\n },\n );\n}\n\nexport function resultHash<T, E>(okHash: HashEq<T>, errHash: HashEq<E>): HashEq<Result<T, E>> {\n return fromHashEq(\n (value) =>\n isOk(value)\n ? combineHashes(stringHash.hash('ok'), okHash.hash(value.value))\n : combineHashes(stringHash.hash('err'), errHash.hash(value.error)),\n (left, right) => {\n if (isOk(left) && isOk(right)) {\n return okHash.equals(left.value, right.value);\n }\n\n if (isErr(left) && isErr(right)) {\n return errHash.equals(left.error, right.error);\n }\n\n return false;\n },\n );\n}\n\nexport const stringHash: HashEq<string> = fromHashEq(\n hashString,\n (left, right) => left === right,\n);\n\nexport const numberHash: HashEq<number> = fromHashEq(\n (value) => hashString(normalizeNumberKey(value)),\n (left, right) => left === right || (Number.isNaN(left) && Number.isNaN(right)),\n);\n\nexport const booleanHash: HashEq<boolean> = fromHashEq(\n (value) => value ? 1 : 0,\n (left, right) => left === right,\n);\n\nexport const bigintHash: HashEq<bigint> = fromHashEq(\n (value) => hashString(value.toString()),\n (left, right) => left === right,\n);\n\nexport function combineHashes(...hashes: readonly HashCode[]): HashCode {\n let hash = 0;\n for (const value of hashes) {\n hash = Math.imul(hash ^ normalizeHashCode(value), 0x01000193);\n }\n return normalizeHashCode(hash);\n}\n\nfunction normalizeHashCode(value: number): HashCode {\n if (!Number.isFinite(value)) {\n return 0;\n }\n\n return value | 0;\n}\n\nfunction normalizeNumberKey(value: number): string {\n if (Number.isNaN(value)) {\n return 'NaN';\n }\n\n if (value === 0) {\n return '0';\n }\n\n return String(value);\n}\n\nfunction hashString(value: string): HashCode {\n let hash = 0x811c9dc5;\n for (let index = 0; index < value.length; index += 1) {\n hash ^= value.charCodeAt(index);\n hash = Math.imul(hash, 0x01000193);\n }\n return hash | 0;\n}\n"]}
|
package/json.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Failure } from '@soundscript/soundscript/failures';
|
|
|
2
2
|
import type { Decoder } from '@soundscript/soundscript/decode';
|
|
3
3
|
import type { Encoder } from '@soundscript/soundscript/encode';
|
|
4
4
|
import type { Result } from '@soundscript/soundscript/result';
|
|
5
|
+
import type { Numeric } from '@soundscript/soundscript/numerics';
|
|
5
6
|
|
|
6
7
|
export type JsonArray = JsonValue[];
|
|
7
8
|
export type JsonObject = {
|
|
@@ -35,15 +36,33 @@ export type JsonLikeValue =
|
|
|
35
36
|
| JsonLikeObject
|
|
36
37
|
| JsonLikeArray;
|
|
37
38
|
|
|
39
|
+
export type MachineJsonArray = MachineJsonLikeValue[];
|
|
40
|
+
export type MachineJsonObject = {
|
|
41
|
+
[key: string]: MachineJsonLikeValue;
|
|
42
|
+
};
|
|
43
|
+
export type MachineJsonLikeValue =
|
|
44
|
+
| string
|
|
45
|
+
| number
|
|
46
|
+
| boolean
|
|
47
|
+
| bigint
|
|
48
|
+
| null
|
|
49
|
+
| undefined
|
|
50
|
+
| Numeric
|
|
51
|
+
| MachineJsonObject
|
|
52
|
+
| MachineJsonArray;
|
|
53
|
+
|
|
38
54
|
export interface JsonParseOptions {
|
|
39
55
|
int64?: 'default' | 'lossless';
|
|
56
|
+
numerics?: 'tagged';
|
|
40
57
|
}
|
|
41
58
|
|
|
42
59
|
export type JsonStringifyBigintMode = 'number' | 'reject' | 'string';
|
|
60
|
+
export type MachineJsonNumericMode = 'tagged' | 'decimal-string' | 'json-number';
|
|
43
61
|
|
|
44
62
|
export interface JsonStringifyOptions {
|
|
45
63
|
int64?: 'default' | 'string' | 'lossless';
|
|
46
64
|
readonly bigint?: JsonStringifyBigintMode;
|
|
65
|
+
numerics?: MachineJsonNumericMode;
|
|
47
66
|
}
|
|
48
67
|
|
|
49
68
|
export class JsonParseFailure extends Failure {
|
|
@@ -59,17 +78,25 @@ export function parseJson(
|
|
|
59
78
|
text: string,
|
|
60
79
|
options: JsonParseOptions & { int64: 'lossless' },
|
|
61
80
|
): Result<LosslessJsonValue, JsonParseFailure>;
|
|
81
|
+
export function parseJson(
|
|
82
|
+
text: string,
|
|
83
|
+
options: JsonParseOptions & { numerics: 'tagged' },
|
|
84
|
+
): Result<MachineJsonLikeValue, JsonParseFailure>;
|
|
62
85
|
export function parseJson(
|
|
63
86
|
text: string,
|
|
64
87
|
options?: JsonParseOptions,
|
|
65
|
-
): Result<JsonValue | LosslessJsonValue, JsonParseFailure>;
|
|
88
|
+
): Result<JsonValue | LosslessJsonValue | MachineJsonLikeValue, JsonParseFailure>;
|
|
66
89
|
export function stringifyJson(value: JsonValue): Result<string, JsonStringifyFailure>;
|
|
67
90
|
export function stringifyJson(
|
|
68
91
|
value: LosslessJsonValue,
|
|
69
92
|
options: JsonStringifyOptions & { int64: 'string' | 'lossless' },
|
|
70
93
|
): Result<string, JsonStringifyFailure>;
|
|
71
94
|
export function stringifyJson(
|
|
72
|
-
value:
|
|
95
|
+
value: MachineJsonLikeValue,
|
|
96
|
+
options: JsonStringifyOptions & { numerics: MachineJsonNumericMode },
|
|
97
|
+
): Result<string, JsonStringifyFailure>;
|
|
98
|
+
export function stringifyJson(
|
|
99
|
+
value: JsonValue | LosslessJsonValue | MachineJsonLikeValue,
|
|
73
100
|
options?: JsonStringifyOptions,
|
|
74
101
|
): Result<string, JsonStringifyFailure>;
|
|
75
102
|
export function parseAndDecode<T, E>(
|
package/json.js
CHANGED
|
@@ -12,6 +12,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
12
12
|
var _JsonLikeParser_instances, _JsonLikeParser_index, _JsonLikeParser_text, _JsonLikeParser_consumeKeyword, _JsonLikeParser_parseArray, _JsonLikeParser_parseNumber, _JsonLikeParser_parseObject, _JsonLikeParser_parseString, _JsonLikeParser_consumeDigits, _JsonLikeParser_skipWhitespace, _JsonLikeParser_isDigit, _JsonLikeParser_error;
|
|
13
13
|
import { Failure } from '@soundscript/soundscript/failures';
|
|
14
14
|
import { isErr, resultOf } from '@soundscript/soundscript/result';
|
|
15
|
+
import { F32, F64, format as formatNumeric, I8, I16, I32, I64, isNumeric, toHostNumber, U8, U16, U32, U64, } from './numerics.js';
|
|
15
16
|
const MAX_SAFE_INTEGER_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
16
17
|
const MIN_SAFE_INTEGER_BIGINT = BigInt(Number.MIN_SAFE_INTEGER);
|
|
17
18
|
export class JsonParseFailure extends Failure {
|
|
@@ -25,10 +26,23 @@ export class JsonStringifyFailure extends Failure {
|
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
export function parseJson(text, options = {}) {
|
|
28
|
-
return resultOf(() =>
|
|
29
|
+
return resultOf(() => {
|
|
30
|
+
const parsed = options.int64 === 'lossless' ? parseLosslessJson(text) : JSON.parse(text);
|
|
31
|
+
return options.numerics === 'tagged'
|
|
32
|
+
? decodeTaggedMachineJsonValue(parsed)
|
|
33
|
+
: parsed;
|
|
34
|
+
}, (cause) => new JsonParseFailure(cause));
|
|
29
35
|
}
|
|
30
36
|
export function stringifyJson(value, options = {}) {
|
|
31
37
|
return resultOf(() => {
|
|
38
|
+
if (options.numerics) {
|
|
39
|
+
const normalized = normalizeMachineJsonLikeValue(value, new Set(), options.numerics, 'root');
|
|
40
|
+
const encoded = stringifyJsonLikeInternal(normalized, new Set(), options.bigint ?? 'reject', 'root');
|
|
41
|
+
if (encoded === undefined) {
|
|
42
|
+
throw new TypeError('JSON stringification produced no top-level value.');
|
|
43
|
+
}
|
|
44
|
+
return encoded;
|
|
45
|
+
}
|
|
32
46
|
if (options.int64 === 'string') {
|
|
33
47
|
return stringifyJsonWithInt64Mode(value, 'string');
|
|
34
48
|
}
|
|
@@ -198,6 +212,115 @@ function isJsonLikeValueInternal(value, visited) {
|
|
|
198
212
|
return false;
|
|
199
213
|
}
|
|
200
214
|
}
|
|
215
|
+
function normalizeMachineJsonLikeValue(value, visited, numericMode, position) {
|
|
216
|
+
if (isNumeric(value)) {
|
|
217
|
+
return normalizeMachineNumericJsonValue(value, numericMode);
|
|
218
|
+
}
|
|
219
|
+
switch (typeof value) {
|
|
220
|
+
case 'string':
|
|
221
|
+
case 'number':
|
|
222
|
+
case 'boolean':
|
|
223
|
+
case 'bigint':
|
|
224
|
+
return value;
|
|
225
|
+
case 'undefined':
|
|
226
|
+
return position === 'array' ? null : undefined;
|
|
227
|
+
case 'object':
|
|
228
|
+
if (value === null) {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
if (visited.has(value)) {
|
|
232
|
+
throw new TypeError('Converting circular structure to machine JSON text.');
|
|
233
|
+
}
|
|
234
|
+
visited.add(value);
|
|
235
|
+
try {
|
|
236
|
+
if (Array.isArray(value)) {
|
|
237
|
+
return value.map((entry) => normalizeMachineJsonLikeValue(entry, visited, numericMode, 'array') ?? null);
|
|
238
|
+
}
|
|
239
|
+
const result = {};
|
|
240
|
+
for (const key of Object.keys(value)) {
|
|
241
|
+
const normalized = normalizeMachineJsonLikeValue(value[key], visited, numericMode, 'object');
|
|
242
|
+
if (normalized !== undefined) {
|
|
243
|
+
result[key] = normalized;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
finally {
|
|
249
|
+
visited.delete(value);
|
|
250
|
+
}
|
|
251
|
+
default:
|
|
252
|
+
throw new TypeError(`Unsupported machine JSON value kind: ${typeof value}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function normalizeMachineNumericJsonValue(value, numericMode) {
|
|
256
|
+
switch (numericMode) {
|
|
257
|
+
case 'tagged':
|
|
258
|
+
return value.toJSON();
|
|
259
|
+
case 'decimal-string':
|
|
260
|
+
return formatNumeric(value);
|
|
261
|
+
case 'json-number':
|
|
262
|
+
switch (value.__soundscript_numeric_kind) {
|
|
263
|
+
case 'i64':
|
|
264
|
+
case 'u64':
|
|
265
|
+
throw new TypeError('json-number machine JSON mode does not support bigint-backed machine numerics.');
|
|
266
|
+
default:
|
|
267
|
+
return toHostNumber(value);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function decodeTaggedMachineJsonValue(value) {
|
|
272
|
+
if (Array.isArray(value)) {
|
|
273
|
+
return value.map((entry) => decodeTaggedMachineJsonValue(entry));
|
|
274
|
+
}
|
|
275
|
+
if (value && typeof value === 'object') {
|
|
276
|
+
const taggedNumeric = decodeTaggedMachineNumeric(value);
|
|
277
|
+
if (taggedNumeric) {
|
|
278
|
+
return taggedNumeric;
|
|
279
|
+
}
|
|
280
|
+
const result = {};
|
|
281
|
+
for (const key of Object.keys(value)) {
|
|
282
|
+
result[key] = decodeTaggedMachineJsonValue(value[key]);
|
|
283
|
+
}
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
286
|
+
return value;
|
|
287
|
+
}
|
|
288
|
+
function decodeTaggedMachineNumeric(value) {
|
|
289
|
+
const numericKind = value.$numeric;
|
|
290
|
+
const numericValue = value.value;
|
|
291
|
+
const keys = Object.keys(value);
|
|
292
|
+
if (typeof numericKind !== 'string' ||
|
|
293
|
+
typeof numericValue !== 'string' ||
|
|
294
|
+
keys.length !== 2 ||
|
|
295
|
+
!keys.includes('$numeric') ||
|
|
296
|
+
!keys.includes('value')) {
|
|
297
|
+
return undefined;
|
|
298
|
+
}
|
|
299
|
+
switch (numericKind) {
|
|
300
|
+
case 'f64':
|
|
301
|
+
return F64.parse(numericValue);
|
|
302
|
+
case 'f32':
|
|
303
|
+
return F32.parse(numericValue);
|
|
304
|
+
case 'i8':
|
|
305
|
+
return I8.parse(numericValue);
|
|
306
|
+
case 'i16':
|
|
307
|
+
return I16.parse(numericValue);
|
|
308
|
+
case 'i32':
|
|
309
|
+
return I32.parse(numericValue);
|
|
310
|
+
case 'i64':
|
|
311
|
+
return I64.parse(numericValue);
|
|
312
|
+
case 'u8':
|
|
313
|
+
return U8.parse(numericValue);
|
|
314
|
+
case 'u16':
|
|
315
|
+
return U16.parse(numericValue);
|
|
316
|
+
case 'u32':
|
|
317
|
+
return U32.parse(numericValue);
|
|
318
|
+
case 'u64':
|
|
319
|
+
return U64.parse(numericValue);
|
|
320
|
+
default:
|
|
321
|
+
return undefined;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
201
324
|
function stringifyJsonLikeInternal(value, visited, bigintMode, position) {
|
|
202
325
|
switch (typeof value) {
|
|
203
326
|
case 'string':
|
package/json.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["./soundscript/json.sts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAe,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AA6C/E,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAA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AAW,CAAC,GAAG,OAAO,gBAAgB,uBAAA,IAAI,6BAAO,GAAG,CAAC,CAAC;AAClE,CAAC;AAGH,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC;AACpC,CAAC","sourcesContent":["import type { Decoder } from '@soundscript/soundscript/decode';\nimport type { Encoder } from '@soundscript/soundscript/encode';\nimport { Failure } from '@soundscript/soundscript/failures';\nimport { isErr, type Result, resultOf } from '@soundscript/soundscript/result';\n\nexport type JsonArray = JsonValue[];\nexport type JsonObject = {\n [key: string]: JsonValue;\n};\nexport type JsonValue = string | number | boolean | null | JsonObject | JsonArray;\ntype LosslessJsonArray = LosslessJsonValue[];\ntype LosslessJsonObject = {\n [key: string]: LosslessJsonValue;\n};\nexport type LosslessJsonValue =\n | string\n | number\n | bigint\n | boolean\n | null\n | LosslessJsonObject\n | LosslessJsonArray;\n\nexport type JsonLikeArray = JsonLikeValue[];\nexport type JsonLikeObject = {\n [key: string]: JsonLikeValue;\n};\nexport type JsonLikeValue =\n | string\n | number\n | boolean\n | bigint\n | null\n | undefined\n | JsonLikeObject\n | JsonLikeArray;\n\nexport interface JsonParseOptions {\n int64?: 'default' | 'lossless';\n}\n\nexport type JsonStringifyBigintMode = 'number' | 'reject' | 'string';\n\nexport interface JsonStringifyOptions {\n int64?: 'default' | 'string' | 'lossless';\n readonly bigint?: JsonStringifyBigintMode;\n}\n\nconst MAX_SAFE_INTEGER_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);\nconst MIN_SAFE_INTEGER_BIGINT = BigInt(Number.MIN_SAFE_INTEGER);\n\nexport class JsonParseFailure extends Failure {\n constructor(cause?: unknown) {\n super('Failed to parse JSON.', { cause });\n }\n}\n\nexport class JsonStringifyFailure extends Failure {\n constructor(cause?: unknown) {\n super('Failed to stringify JSON.', { cause });\n }\n}\n\nexport function parseJson(text: string): Result<JsonValue, JsonParseFailure>;\nexport function parseJson(\n text: string,\n options: JsonParseOptions & { int64: 'lossless' },\n): Result<LosslessJsonValue, JsonParseFailure>;\nexport function parseJson(\n text: string,\n options: JsonParseOptions = {},\n): Result<JsonValue | LosslessJsonValue, JsonParseFailure> {\n return resultOf(\n () => options.int64 === 'lossless' ? parseLosslessJson(text) : JSON.parse(text),\n (cause) => new JsonParseFailure(cause),\n );\n}\n\nexport function stringifyJson(value: JsonValue): Result<string, JsonStringifyFailure>;\nexport function stringifyJson(\n value: LosslessJsonValue,\n options: JsonStringifyOptions & { int64: 'string' | 'lossless' },\n): Result<string, JsonStringifyFailure>;\nexport function stringifyJson(\n value: JsonValue | LosslessJsonValue,\n options: JsonStringifyOptions = {},\n): Result<string, JsonStringifyFailure> {\n return resultOf(\n () => {\n if (options.int64 === 'string') {\n return stringifyJsonWithInt64Mode(value as LosslessJsonValue, 'string');\n }\n if (options.int64 === 'lossless') {\n return stringifyJsonWithInt64Mode(value as LosslessJsonValue, 'lossless');\n }\n\n const encoded = JSON.stringify(value);\n if (encoded === undefined) {\n throw new TypeError(\n 'JSON.stringify returned undefined for a JsonValue input.',\n );\n }\n return encoded;\n },\n (cause) => new JsonStringifyFailure(cause),\n );\n}\n\nexport function parseAndDecode<T, E>(\n text: string,\n decoder: Decoder<T, E>,\n): Result<T, JsonParseFailure | E> {\n const parsed = parseJson(text);\n return isErr(parsed) ? parsed : decoder.decode(parsed.value);\n}\n\nexport function encodeAndStringify<T, E>(\n value: T,\n encoder: Encoder<T, JsonValue, E>,\n): Result<string, E | JsonStringifyFailure> {\n const encoded = encoder.encode(value);\n return isErr(encoded) ? encoded : stringifyJson(encoded.value);\n}\n\nexport function isJsonValue(value: unknown): value is JsonValue {\n return isJsonValueInternal(value, new Set<object>());\n}\n\nexport function parseJsonLike(text: string): Result<JsonLikeValue, JsonParseFailure> {\n return resultOf(\n () => {\n const parser = new JsonLikeParser(text);\n const value = parser.parseValue();\n parser.finish();\n return value;\n },\n (cause) => new JsonParseFailure(cause),\n );\n}\n\nexport function stringifyJsonLike(\n value: JsonLikeValue,\n options: JsonStringifyOptions = {},\n): Result<string, JsonStringifyFailure> {\n return resultOf(\n () => {\n const encoded = stringifyJsonLikeInternal(\n value,\n new Set<object>(),\n options.bigint ?? 'reject',\n 'root',\n );\n if (encoded === undefined) {\n throw new TypeError('JSON-like stringification produced no top-level value.');\n }\n return encoded;\n },\n (cause) => new JsonStringifyFailure(cause),\n );\n}\n\nexport function decodeJson<T, E>(\n text: string,\n decoder: Decoder<T, E>,\n): Result<T, E | JsonParseFailure> {\n const parsed = parseJsonLike(text);\n return isErr(parsed) ? parsed : decoder.decode(parsed.value);\n}\n\nexport function encodeJson<T, E>(\n value: T,\n encoder: Encoder<T, JsonLikeValue, E>,\n options: JsonStringifyOptions = {},\n): Result<string, E | JsonStringifyFailure> {\n const encoded = encoder.encode(value);\n return isErr(encoded) ? encoded : stringifyJsonLike(encoded.value, options);\n}\n\nexport function isJsonLikeValue(value: unknown): value is JsonLikeValue {\n return isJsonLikeValueInternal(value, new Set<object>());\n}\n\nfunction stringifyJsonWithInt64Mode(\n value: LosslessJsonValue,\n int64Mode: 'string' | 'lossless',\n): string {\n return stringifyJsonWithInt64ModeInternal(value, int64Mode, new Set<object>());\n}\n\nfunction stringifyJsonWithInt64ModeInternal(\n value: LosslessJsonValue,\n int64Mode: 'string' | 'lossless',\n visited: Set<object>,\n): string {\n switch (typeof value) {\n case 'string':\n return JSON.stringify(value);\n case 'number': {\n const encoded = JSON.stringify(value);\n if (encoded === undefined) {\n throw new TypeError('JSON.stringify returned undefined for a numeric input.');\n }\n return encoded;\n }\n case 'bigint':\n return int64Mode === 'string'\n ? JSON.stringify(value.toString())\n : value.toString();\n case 'boolean':\n return value ? 'true' : 'false';\n case 'object':\n if (value === null) {\n return 'null';\n }\n\n if (visited.has(value)) {\n throw new TypeError('Could not stringify cyclic JSON value.');\n }\n\n visited.add(value);\n try {\n if (Array.isArray(value)) {\n return `[${value.map((entry) => stringifyJsonWithInt64ModeInternal(entry, int64Mode, visited)).join(',')}]`;\n }\n\n const fields = Object.keys(value).map((key) =>\n `${JSON.stringify(key)}:${stringifyJsonWithInt64ModeInternal(value[key]!, int64Mode, visited)}`\n );\n return `{${fields.join(',')}}`;\n } finally {\n visited.delete(value);\n }\n default:\n throw new TypeError(`Unsupported JSON value kind: ${typeof value}`);\n }\n}\n\nfunction parseLosslessJson(text: string): LosslessJsonValue {\n const parser = new LosslessJsonParser(text);\n const value = parser.parseValue();\n parser.skipWhitespace();\n if (!parser.isAtEnd()) {\n parser.fail('Unexpected trailing characters.');\n }\n return value;\n}\n\nfunction isJsonValueInternal(value: unknown, visited: Set<object>): value is JsonValue {\n switch (typeof value) {\n case 'string':\n case 'number':\n case 'boolean':\n return true;\n case 'object':\n if (value === null) {\n return true;\n }\n\n if (visited.has(value)) {\n return true;\n }\n\n visited.add(value);\n try {\n if (Array.isArray(value)) {\n return value.every((entry) => isJsonValueInternal(entry, visited));\n }\n\n for (const key of Object.keys(value)) {\n if (!isJsonValueInternal((value as Record<string, unknown>)[key], visited)) {\n return false;\n }\n }\n\n return true;\n } finally {\n visited.delete(value);\n }\n default:\n return false;\n }\n}\n\nfunction isJsonLikeValueInternal(\n value: unknown,\n visited: Set<object>,\n): value is JsonLikeValue {\n switch (typeof value) {\n case 'string':\n case 'number':\n case 'boolean':\n case 'bigint':\n case 'undefined':\n return true;\n case 'object':\n if (value === null) {\n return true;\n }\n\n if (visited.has(value)) {\n return true;\n }\n\n visited.add(value);\n try {\n if (Array.isArray(value)) {\n return value.every((entry) => isJsonLikeValueInternal(entry, visited));\n }\n\n for (const key of Object.keys(value)) {\n if (!isJsonLikeValueInternal((value as Record<string, unknown>)[key], visited)) {\n return false;\n }\n }\n\n return true;\n } finally {\n visited.delete(value);\n }\n default:\n return false;\n }\n}\n\nfunction stringifyJsonLikeInternal(\n value: JsonLikeValue,\n visited: Set<object>,\n bigintMode: JsonStringifyBigintMode,\n position: 'array' | 'object' | 'root',\n): string | undefined {\n switch (typeof value) {\n case 'string':\n return JSON.stringify(value);\n case 'number':\n return Number.isFinite(value) ? JSON.stringify(value) : 'null';\n case 'boolean':\n return value ? 'true' : 'false';\n case 'bigint':\n switch (bigintMode) {\n case 'string':\n return JSON.stringify(value.toString());\n case 'number':\n return value.toString();\n case 'reject':\n throw new TypeError('Encountered bigint while stringifying JSON-like data.');\n }\n case 'undefined':\n return position === 'array' ? 'null' : undefined;\n case 'object':\n if (value === null) {\n return 'null';\n }\n\n if (visited.has(value)) {\n throw new TypeError('Converting circular structure to JSON-like text.');\n }\n\n visited.add(value);\n try {\n if (Array.isArray(value)) {\n return `[${value.map((entry) =>\n stringifyJsonLikeInternal(entry, visited, bigintMode, 'array') ?? 'null'\n ).join(',')}]`;\n }\n\n const encodedProperties: string[] = [];\n for (const key of Object.keys(value)) {\n const encodedValue = stringifyJsonLikeInternal(\n (value as Record<string, JsonLikeValue>)[key],\n visited,\n bigintMode,\n 'object',\n );\n if (encodedValue === undefined) {\n continue;\n }\n encodedProperties.push(`${JSON.stringify(key)}:${encodedValue}`);\n }\n return `{${encodedProperties.join(',')}}`;\n } finally {\n visited.delete(value);\n }\n default:\n throw new TypeError('Encountered an unsupported JSON-like value.');\n }\n}\n\nclass LosslessJsonParser {\n private readonly text: string;\n private index = 0;\n\n constructor(text: string) {\n this.text = text;\n }\n\n fail(message: string): never {\n throw new SyntaxError(`${message} At character ${this.index}.`);\n }\n\n isAtEnd(): boolean {\n return this.index >= this.text.length;\n }\n\n skipWhitespace(): void {\n while (!this.isAtEnd() && /\\s/u.test(this.text[this.index]!)) {\n this.index += 1;\n }\n }\n\n parseValue(): LosslessJsonValue {\n this.skipWhitespace();\n if (this.isAtEnd()) {\n this.fail('Unexpected end of JSON input.');\n }\n\n const current = this.text[this.index]!;\n switch (current) {\n case '\"':\n return this.parseString();\n case '{':\n return this.parseObject();\n case '[':\n return this.parseArray();\n case 't':\n this.consumeKeyword('true');\n return true;\n case 'f':\n this.consumeKeyword('false');\n return false;\n case 'n':\n this.consumeKeyword('null');\n return null;\n default:\n if (current === '-' || isAsciiDigit(current)) {\n return this.parseNumber();\n }\n this.fail(`Unexpected token ${JSON.stringify(current)}.`);\n }\n }\n\n private consumeKeyword(keyword: string): void {\n if (!this.text.startsWith(keyword, this.index)) {\n this.fail(`Expected ${keyword}.`);\n }\n this.index += keyword.length;\n }\n\n private parseString(): string {\n let result = '';\n this.index += 1;\n\n while (!this.isAtEnd()) {\n const current = this.text[this.index]!;\n if (current === '\"') {\n this.index += 1;\n return result;\n }\n if (current === '\\\\') {\n this.index += 1;\n if (this.isAtEnd()) {\n this.fail('Unexpected end of escape sequence.');\n }\n result += this.parseEscapeSequence();\n continue;\n }\n result += current;\n this.index += 1;\n }\n\n this.fail('Unterminated string literal.');\n }\n\n private parseEscapeSequence(): string {\n const current = this.text[this.index]!;\n this.index += 1;\n switch (current) {\n case '\"':\n case '\\\\':\n case '/':\n return current;\n case 'b':\n return '\\b';\n case 'f':\n return '\\f';\n case 'n':\n return '\\n';\n case 'r':\n return '\\r';\n case 't':\n return '\\t';\n case 'u': {\n const hex = this.text.slice(this.index, this.index + 4);\n if (!/^[0-9A-Fa-f]{4}$/u.test(hex)) {\n this.fail('Invalid unicode escape.');\n }\n this.index += 4;\n return String.fromCharCode(Number.parseInt(hex, 16));\n }\n default:\n this.fail(`Invalid escape sequence \\\\${current}.`);\n }\n }\n\n private parseArray(): LosslessJsonArray {\n const result: LosslessJsonArray = [];\n this.index += 1;\n this.skipWhitespace();\n if (this.text[this.index] === ']') {\n this.index += 1;\n return result;\n }\n\n while (true) {\n result.push(this.parseValue());\n this.skipWhitespace();\n const current = this.text[this.index];\n if (current === ']') {\n this.index += 1;\n return result;\n }\n if (current !== ',') {\n this.fail('Expected , or ] in array literal.');\n }\n this.index += 1;\n }\n }\n\n private parseObject(): LosslessJsonObject {\n const result: LosslessJsonObject = {};\n this.index += 1;\n this.skipWhitespace();\n if (this.text[this.index] === '}') {\n this.index += 1;\n return result;\n }\n\n while (true) {\n this.skipWhitespace();\n if (this.text[this.index] !== '\"') {\n this.fail('Expected string key in object literal.');\n }\n const key = this.parseString();\n this.skipWhitespace();\n if (this.text[this.index] !== ':') {\n this.fail('Expected : after object key.');\n }\n this.index += 1;\n result[key] = this.parseValue();\n this.skipWhitespace();\n const current = this.text[this.index];\n if (current === '}') {\n this.index += 1;\n return result;\n }\n if (current !== ',') {\n this.fail('Expected , or } in object literal.');\n }\n this.index += 1;\n }\n }\n\n private parseNumber(): number | bigint {\n const start = this.index;\n if (this.text[this.index] === '-') {\n this.index += 1;\n }\n\n if (this.text[this.index] === '0') {\n this.index += 1;\n } else {\n this.consumeDigits();\n }\n\n let isInteger = true;\n if (this.text[this.index] === '.') {\n isInteger = false;\n this.index += 1;\n this.consumeDigits();\n }\n\n const exponentMarker = this.text[this.index];\n if (exponentMarker === 'e' || exponentMarker === 'E') {\n isInteger = false;\n this.index += 1;\n const sign = this.text[this.index];\n if (sign === '+' || sign === '-') {\n this.index += 1;\n }\n this.consumeDigits();\n }\n\n const token = this.text.slice(start, this.index);\n if (!isInteger) {\n return Number(token);\n }\n if (token === '-0') {\n return -0;\n }\n\n const bigintValue = BigInt(token);\n return bigintValue <= MAX_SAFE_INTEGER_BIGINT && bigintValue >= MIN_SAFE_INTEGER_BIGINT\n ? Number(token)\n : bigintValue;\n }\n\n private consumeDigits(): void {\n const start = this.index;\n while (!this.isAtEnd() && isAsciiDigit(this.text[this.index]!)) {\n this.index += 1;\n }\n if (start === this.index) {\n this.fail('Expected digits.');\n }\n }\n}\n\nclass JsonLikeParser {\n #index = 0;\n readonly #text: string;\n\n constructor(text: string) {\n this.#text = text;\n }\n\n finish(): void {\n this.#skipWhitespace();\n if (this.#index !== this.#text.length) {\n this.#error('Unexpected trailing JSON input');\n }\n }\n\n parseValue(): JsonLikeValue {\n this.#skipWhitespace();\n const current = this.#text[this.#index];\n switch (current) {\n case '{':\n return this.#parseObject();\n case '[':\n return this.#parseArray();\n case '\"':\n return this.#parseString();\n case 't':\n this.#consumeKeyword('true');\n return true;\n case 'f':\n this.#consumeKeyword('false');\n return false;\n case 'n':\n this.#consumeKeyword('null');\n return null;\n default:\n if (current === '-' || this.#isDigit(current)) {\n return this.#parseNumber();\n }\n this.#error('Unexpected token in JSON input');\n }\n }\n\n #consumeKeyword(keyword: string): void {\n if (this.#text.slice(this.#index, this.#index + keyword.length) !== keyword) {\n this.#error(`Expected ${keyword}`);\n }\n this.#index += keyword.length;\n }\n\n #parseArray(): JsonLikeArray {\n const values: JsonLikeValue[] = [];\n this.#index += 1;\n this.#skipWhitespace();\n if (this.#text[this.#index] === ']') {\n this.#index += 1;\n return values;\n }\n\n while (true) {\n values.push(this.parseValue());\n this.#skipWhitespace();\n const current = this.#text[this.#index];\n if (current === ']') {\n this.#index += 1;\n return values;\n }\n if (current !== ',') {\n this.#error('Expected , or ] in JSON array');\n }\n this.#index += 1;\n }\n }\n\n #parseNumber(): number | bigint {\n const start = this.#index;\n if (this.#text[this.#index] === '-') {\n this.#index += 1;\n }\n\n if (this.#text[this.#index] === '0') {\n this.#index += 1;\n } else {\n this.#consumeDigits();\n }\n\n let isInteger = true;\n if (this.#text[this.#index] === '.') {\n isInteger = false;\n this.#index += 1;\n this.#consumeDigits();\n }\n\n const exponent = this.#text[this.#index];\n if (exponent === 'e' || exponent === 'E') {\n isInteger = false;\n this.#index += 1;\n const sign = this.#text[this.#index];\n if (sign === '+' || sign === '-') {\n this.#index += 1;\n }\n this.#consumeDigits();\n }\n\n const token = this.#text.slice(start, this.#index);\n if (!isInteger) {\n return Number(token);\n }\n\n const bigintValue = BigInt(token);\n const numberValue = Number(token);\n return Number.isSafeInteger(numberValue) && BigInt(numberValue) === bigintValue\n ? numberValue\n : bigintValue;\n }\n\n #parseObject(): JsonLikeObject {\n const object: Record<string, JsonLikeValue> = {};\n this.#index += 1;\n this.#skipWhitespace();\n if (this.#text[this.#index] === '}') {\n this.#index += 1;\n return object;\n }\n\n while (true) {\n this.#skipWhitespace();\n if (this.#text[this.#index] !== '\"') {\n this.#error('Expected string key in JSON object');\n }\n const key = this.#parseString();\n this.#skipWhitespace();\n if (this.#text[this.#index] !== ':') {\n this.#error('Expected : in JSON object');\n }\n this.#index += 1;\n object[key] = this.parseValue();\n this.#skipWhitespace();\n const current = this.#text[this.#index];\n if (current === '}') {\n this.#index += 1;\n return object;\n }\n if (current !== ',') {\n this.#error('Expected , or } in JSON object');\n }\n this.#index += 1;\n }\n }\n\n #parseString(): string {\n const start = this.#index;\n this.#index += 1;\n while (this.#index < this.#text.length) {\n const current = this.#text[this.#index];\n if (current === '\"') {\n this.#index += 1;\n return JSON.parse(this.#text.slice(start, this.#index));\n }\n if (current === '\\\\') {\n this.#index += 1;\n const escaped = this.#text[this.#index];\n if (escaped === undefined) {\n this.#error('Unterminated string escape');\n }\n if (escaped === 'u') {\n for (let index = 0; index < 4; index += 1) {\n this.#index += 1;\n if (!/[0-9A-Fa-f]/u.test(this.#text[this.#index] ?? '')) {\n this.#error('Invalid unicode escape');\n }\n }\n }\n } else if (current <= '\\u001F') {\n this.#error('Invalid control character in string literal');\n }\n this.#index += 1;\n }\n this.#error('Unterminated string literal');\n }\n\n #consumeDigits(): void {\n const start = this.#index;\n while (this.#isDigit(this.#text[this.#index])) {\n this.#index += 1;\n }\n if (start === this.#index) {\n this.#error('Expected digit in JSON number');\n }\n }\n\n #skipWhitespace(): void {\n while (/\\s/u.test(this.#text[this.#index] ?? '')) {\n this.#index += 1;\n }\n }\n\n #isDigit(value: string | undefined): boolean {\n return value !== undefined && value >= '0' && value <= '9';\n }\n\n #error(message: string): never {\n throw new SyntaxError(`${message} at position ${this.#index}.`);\n }\n}\n\nfunction isAsciiDigit(text: string): boolean {\n return text >= '0' && text <= '9';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["./soundscript/json.sts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAe,QAAQ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":["import type { Decoder } from '@soundscript/soundscript/decode';\nimport type { Encoder } from '@soundscript/soundscript/encode';\nimport { Failure } from '@soundscript/soundscript/failures';\nimport { isErr, type Result, resultOf } from '@soundscript/soundscript/result';\nimport {\n F32,\n F64,\n format as formatNumeric,\n I8,\n I16,\n I32,\n I64,\n isNumeric,\n toHostNumber,\n type Numeric,\n U8,\n U16,\n U32,\n U64,\n} from './numerics.js';\n\nexport type JsonArray = JsonValue[];\nexport type JsonObject = {\n [key: string]: JsonValue;\n};\nexport type JsonValue = string | number | boolean | null | JsonObject | JsonArray;\ntype LosslessJsonArray = LosslessJsonValue[];\ntype LosslessJsonObject = {\n [key: string]: LosslessJsonValue;\n};\nexport type LosslessJsonValue =\n | string\n | number\n | bigint\n | boolean\n | null\n | LosslessJsonObject\n | LosslessJsonArray;\n\nexport type JsonLikeArray = JsonLikeValue[];\nexport type JsonLikeObject = {\n [key: string]: JsonLikeValue;\n};\nexport type JsonLikeValue =\n | string\n | number\n | boolean\n | bigint\n | null\n | undefined\n | JsonLikeObject\n | JsonLikeArray;\n\nexport type MachineJsonArray = MachineJsonLikeValue[];\nexport type MachineJsonObject = {\n [key: string]: MachineJsonLikeValue;\n};\nexport type MachineJsonLikeValue =\n | string\n | number\n | boolean\n | bigint\n | null\n | undefined\n | Numeric\n | MachineJsonObject\n | MachineJsonArray;\n\nexport type MachineJsonNumericMode = 'tagged' | 'decimal-string' | 'json-number';\n\nexport interface JsonParseOptions {\n int64?: 'default' | 'lossless';\n numerics?: 'tagged';\n}\n\nexport type JsonStringifyBigintMode = 'number' | 'reject' | 'string';\n\nexport interface JsonStringifyOptions {\n int64?: 'default' | 'string' | 'lossless';\n readonly bigint?: JsonStringifyBigintMode;\n numerics?: MachineJsonNumericMode;\n}\n\nconst MAX_SAFE_INTEGER_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);\nconst MIN_SAFE_INTEGER_BIGINT = BigInt(Number.MIN_SAFE_INTEGER);\n\nexport class JsonParseFailure extends Failure {\n constructor(cause?: unknown) {\n super('Failed to parse JSON.', { cause });\n }\n}\n\nexport class JsonStringifyFailure extends Failure {\n constructor(cause?: unknown) {\n super('Failed to stringify JSON.', { cause });\n }\n}\n\nexport function parseJson(text: string): Result<JsonValue, JsonParseFailure>;\nexport function parseJson(\n text: string,\n options: JsonParseOptions & { int64: 'lossless' },\n): Result<LosslessJsonValue, JsonParseFailure>;\nexport function parseJson(\n text: string,\n options: JsonParseOptions & { numerics: 'tagged' },\n): Result<MachineJsonLikeValue, JsonParseFailure>;\nexport function parseJson(\n text: string,\n options: JsonParseOptions = {},\n): Result<JsonValue | LosslessJsonValue | MachineJsonLikeValue, JsonParseFailure> {\n return resultOf(\n () => {\n const parsed = options.int64 === 'lossless' ? parseLosslessJson(text) : JSON.parse(text);\n return options.numerics === 'tagged'\n ? decodeTaggedMachineJsonValue(parsed as JsonValue | LosslessJsonValue)\n : parsed;\n },\n (cause) => new JsonParseFailure(cause),\n );\n}\n\nexport function stringifyJson(value: JsonValue): Result<string, JsonStringifyFailure>;\nexport function stringifyJson(\n value: LosslessJsonValue,\n options: JsonStringifyOptions & { int64: 'string' | 'lossless' },\n): Result<string, JsonStringifyFailure>;\nexport function stringifyJson(\n value: MachineJsonLikeValue,\n options: JsonStringifyOptions & { numerics: MachineJsonNumericMode },\n): Result<string, JsonStringifyFailure>;\nexport function stringifyJson(\n value: JsonValue | LosslessJsonValue | MachineJsonLikeValue,\n options: JsonStringifyOptions = {},\n): Result<string, JsonStringifyFailure> {\n return resultOf(\n () => {\n if (options.numerics) {\n const normalized = normalizeMachineJsonLikeValue(\n value as MachineJsonLikeValue,\n new Set<object>(),\n options.numerics,\n 'root',\n );\n const encoded = stringifyJsonLikeInternal(\n normalized,\n new Set<object>(),\n options.bigint ?? 'reject',\n 'root',\n );\n if (encoded === undefined) {\n throw new TypeError('JSON stringification produced no top-level value.');\n }\n return encoded;\n }\n\n if (options.int64 === 'string') {\n return stringifyJsonWithInt64Mode(value as LosslessJsonValue, 'string');\n }\n if (options.int64 === 'lossless') {\n return stringifyJsonWithInt64Mode(value as LosslessJsonValue, 'lossless');\n }\n\n const encoded = JSON.stringify(value);\n if (encoded === undefined) {\n throw new TypeError(\n 'JSON.stringify returned undefined for a JsonValue input.',\n );\n }\n return encoded;\n },\n (cause) => new JsonStringifyFailure(cause),\n );\n}\n\nexport function parseAndDecode<T, E>(\n text: string,\n decoder: Decoder<T, E>,\n): Result<T, JsonParseFailure | E> {\n const parsed = parseJson(text);\n return isErr(parsed) ? parsed : decoder.decode(parsed.value);\n}\n\nexport function encodeAndStringify<T, E>(\n value: T,\n encoder: Encoder<T, JsonValue, E>,\n): Result<string, E | JsonStringifyFailure> {\n const encoded = encoder.encode(value);\n return isErr(encoded) ? encoded : stringifyJson(encoded.value);\n}\n\nexport function isJsonValue(value: unknown): value is JsonValue {\n return isJsonValueInternal(value, new Set<object>());\n}\n\nexport function parseJsonLike(text: string): Result<JsonLikeValue, JsonParseFailure> {\n return resultOf(\n () => {\n const parser = new JsonLikeParser(text);\n const value = parser.parseValue();\n parser.finish();\n return value;\n },\n (cause) => new JsonParseFailure(cause),\n );\n}\n\nexport function stringifyJsonLike(\n value: JsonLikeValue,\n options: JsonStringifyOptions = {},\n): Result<string, JsonStringifyFailure> {\n return resultOf(\n () => {\n const encoded = stringifyJsonLikeInternal(\n value,\n new Set<object>(),\n options.bigint ?? 'reject',\n 'root',\n );\n if (encoded === undefined) {\n throw new TypeError('JSON-like stringification produced no top-level value.');\n }\n return encoded;\n },\n (cause) => new JsonStringifyFailure(cause),\n );\n}\n\nexport function decodeJson<T, E>(\n text: string,\n decoder: Decoder<T, E>,\n): Result<T, E | JsonParseFailure> {\n const parsed = parseJsonLike(text);\n return isErr(parsed) ? parsed : decoder.decode(parsed.value);\n}\n\nexport function encodeJson<T, E>(\n value: T,\n encoder: Encoder<T, JsonLikeValue, E>,\n options: JsonStringifyOptions = {},\n): Result<string, E | JsonStringifyFailure> {\n const encoded = encoder.encode(value);\n return isErr(encoded) ? encoded : stringifyJsonLike(encoded.value, options);\n}\n\nexport function isJsonLikeValue(value: unknown): value is JsonLikeValue {\n return isJsonLikeValueInternal(value, new Set<object>());\n}\n\nfunction stringifyJsonWithInt64Mode(\n value: LosslessJsonValue,\n int64Mode: 'string' | 'lossless',\n): string {\n return stringifyJsonWithInt64ModeInternal(value, int64Mode, new Set<object>());\n}\n\nfunction stringifyJsonWithInt64ModeInternal(\n value: LosslessJsonValue,\n int64Mode: 'string' | 'lossless',\n visited: Set<object>,\n): string {\n switch (typeof value) {\n case 'string':\n return JSON.stringify(value);\n case 'number': {\n const encoded = JSON.stringify(value);\n if (encoded === undefined) {\n throw new TypeError('JSON.stringify returned undefined for a numeric input.');\n }\n return encoded;\n }\n case 'bigint':\n return int64Mode === 'string'\n ? JSON.stringify(value.toString())\n : value.toString();\n case 'boolean':\n return value ? 'true' : 'false';\n case 'object':\n if (value === null) {\n return 'null';\n }\n\n if (visited.has(value)) {\n throw new TypeError('Could not stringify cyclic JSON value.');\n }\n\n visited.add(value);\n try {\n if (Array.isArray(value)) {\n return `[${value.map((entry) => stringifyJsonWithInt64ModeInternal(entry, int64Mode, visited)).join(',')}]`;\n }\n\n const fields = Object.keys(value).map((key) =>\n `${JSON.stringify(key)}:${stringifyJsonWithInt64ModeInternal(value[key]!, int64Mode, visited)}`\n );\n return `{${fields.join(',')}}`;\n } finally {\n visited.delete(value);\n }\n default:\n throw new TypeError(`Unsupported JSON value kind: ${typeof value}`);\n }\n}\n\nfunction parseLosslessJson(text: string): LosslessJsonValue {\n const parser = new LosslessJsonParser(text);\n const value = parser.parseValue();\n parser.skipWhitespace();\n if (!parser.isAtEnd()) {\n parser.fail('Unexpected trailing characters.');\n }\n return value;\n}\n\nfunction isJsonValueInternal(value: unknown, visited: Set<object>): value is JsonValue {\n switch (typeof value) {\n case 'string':\n case 'number':\n case 'boolean':\n return true;\n case 'object':\n if (value === null) {\n return true;\n }\n\n if (visited.has(value)) {\n return true;\n }\n\n visited.add(value);\n try {\n if (Array.isArray(value)) {\n return value.every((entry) => isJsonValueInternal(entry, visited));\n }\n\n for (const key of Object.keys(value)) {\n if (!isJsonValueInternal((value as Record<string, unknown>)[key], visited)) {\n return false;\n }\n }\n\n return true;\n } finally {\n visited.delete(value);\n }\n default:\n return false;\n }\n}\n\nfunction isJsonLikeValueInternal(\n value: unknown,\n visited: Set<object>,\n): value is JsonLikeValue {\n switch (typeof value) {\n case 'string':\n case 'number':\n case 'boolean':\n case 'bigint':\n case 'undefined':\n return true;\n case 'object':\n if (value === null) {\n return true;\n }\n\n if (visited.has(value)) {\n return true;\n }\n\n visited.add(value);\n try {\n if (Array.isArray(value)) {\n return value.every((entry) => isJsonLikeValueInternal(entry, visited));\n }\n\n for (const key of Object.keys(value)) {\n if (!isJsonLikeValueInternal((value as Record<string, unknown>)[key], visited)) {\n return false;\n }\n }\n\n return true;\n } finally {\n visited.delete(value);\n }\n default:\n return false;\n }\n}\n\nfunction normalizeMachineJsonLikeValue(\n value: MachineJsonLikeValue,\n visited: Set<object>,\n numericMode: MachineJsonNumericMode,\n position: 'array' | 'object' | 'root',\n): JsonLikeValue {\n if (isNumeric(value)) {\n return normalizeMachineNumericJsonValue(value, numericMode);\n }\n\n switch (typeof value) {\n case 'string':\n case 'number':\n case 'boolean':\n case 'bigint':\n return value;\n case 'undefined':\n return position === 'array' ? null : undefined;\n case 'object':\n if (value === null) {\n return null;\n }\n\n if (visited.has(value)) {\n throw new TypeError('Converting circular structure to machine JSON text.');\n }\n\n visited.add(value);\n try {\n if (Array.isArray(value)) {\n return value.map((entry) =>\n normalizeMachineJsonLikeValue(entry, visited, numericMode, 'array') ?? null\n );\n }\n\n const result: Record<string, JsonLikeValue> = {};\n for (const key of Object.keys(value)) {\n const normalized = normalizeMachineJsonLikeValue(\n (value as MachineJsonObject)[key]!,\n visited,\n numericMode,\n 'object',\n );\n if (normalized !== undefined) {\n result[key] = normalized;\n }\n }\n return result;\n } finally {\n visited.delete(value);\n }\n default:\n throw new TypeError(`Unsupported machine JSON value kind: ${typeof value}`);\n }\n}\n\nfunction normalizeMachineNumericJsonValue(\n value: Numeric,\n numericMode: MachineJsonNumericMode,\n): JsonLikeValue {\n switch (numericMode) {\n case 'tagged':\n return value.toJSON();\n case 'decimal-string':\n return formatNumeric(value);\n case 'json-number':\n switch (value.__soundscript_numeric_kind) {\n case 'i64':\n case 'u64':\n throw new TypeError('json-number machine JSON mode does not support bigint-backed machine numerics.');\n default:\n return toHostNumber(value);\n }\n }\n}\n\nfunction decodeTaggedMachineJsonValue(value: JsonValue | LosslessJsonValue): MachineJsonLikeValue {\n if (Array.isArray(value)) {\n return value.map((entry) => decodeTaggedMachineJsonValue(entry));\n }\n\n if (value && typeof value === 'object') {\n const taggedNumeric = decodeTaggedMachineNumeric(value);\n if (taggedNumeric) {\n return taggedNumeric;\n }\n\n const result: Record<string, MachineJsonLikeValue> = {};\n for (const key of Object.keys(value)) {\n result[key] = decodeTaggedMachineJsonValue(value[key]!);\n }\n return result;\n }\n\n return value;\n}\n\nfunction decodeTaggedMachineNumeric(\n value: Record<string, JsonValue | LosslessJsonValue>,\n): Numeric | undefined {\n const numericKind = value.$numeric;\n const numericValue = value.value;\n const keys = Object.keys(value);\n if (\n typeof numericKind !== 'string' ||\n typeof numericValue !== 'string' ||\n keys.length !== 2 ||\n !keys.includes('$numeric') ||\n !keys.includes('value')\n ) {\n return undefined;\n }\n\n switch (numericKind) {\n case 'f64':\n return F64.parse(numericValue);\n case 'f32':\n return F32.parse(numericValue);\n case 'i8':\n return I8.parse(numericValue);\n case 'i16':\n return I16.parse(numericValue);\n case 'i32':\n return I32.parse(numericValue);\n case 'i64':\n return I64.parse(numericValue);\n case 'u8':\n return U8.parse(numericValue);\n case 'u16':\n return U16.parse(numericValue);\n case 'u32':\n return U32.parse(numericValue);\n case 'u64':\n return U64.parse(numericValue);\n default:\n return undefined;\n }\n}\n\nfunction stringifyJsonLikeInternal(\n value: JsonLikeValue,\n visited: Set<object>,\n bigintMode: JsonStringifyBigintMode,\n position: 'array' | 'object' | 'root',\n): string | undefined {\n switch (typeof value) {\n case 'string':\n return JSON.stringify(value);\n case 'number':\n return Number.isFinite(value) ? JSON.stringify(value) : 'null';\n case 'boolean':\n return value ? 'true' : 'false';\n case 'bigint':\n switch (bigintMode) {\n case 'string':\n return JSON.stringify(value.toString());\n case 'number':\n return value.toString();\n case 'reject':\n throw new TypeError('Encountered bigint while stringifying JSON-like data.');\n }\n case 'undefined':\n return position === 'array' ? 'null' : undefined;\n case 'object':\n if (value === null) {\n return 'null';\n }\n\n if (visited.has(value)) {\n throw new TypeError('Converting circular structure to JSON-like text.');\n }\n\n visited.add(value);\n try {\n if (Array.isArray(value)) {\n return `[${value.map((entry) =>\n stringifyJsonLikeInternal(entry, visited, bigintMode, 'array') ?? 'null'\n ).join(',')}]`;\n }\n\n const encodedProperties: string[] = [];\n for (const key of Object.keys(value)) {\n const encodedValue = stringifyJsonLikeInternal(\n (value as Record<string, JsonLikeValue>)[key],\n visited,\n bigintMode,\n 'object',\n );\n if (encodedValue === undefined) {\n continue;\n }\n encodedProperties.push(`${JSON.stringify(key)}:${encodedValue}`);\n }\n return `{${encodedProperties.join(',')}}`;\n } finally {\n visited.delete(value);\n }\n default:\n throw new TypeError('Encountered an unsupported JSON-like value.');\n }\n}\n\nclass LosslessJsonParser {\n private readonly text: string;\n private index = 0;\n\n constructor(text: string) {\n this.text = text;\n }\n\n fail(message: string): never {\n throw new SyntaxError(`${message} At character ${this.index}.`);\n }\n\n isAtEnd(): boolean {\n return this.index >= this.text.length;\n }\n\n skipWhitespace(): void {\n while (!this.isAtEnd() && /\\s/u.test(this.text[this.index]!)) {\n this.index += 1;\n }\n }\n\n parseValue(): LosslessJsonValue {\n this.skipWhitespace();\n if (this.isAtEnd()) {\n this.fail('Unexpected end of JSON input.');\n }\n\n const current = this.text[this.index]!;\n switch (current) {\n case '\"':\n return this.parseString();\n case '{':\n return this.parseObject();\n case '[':\n return this.parseArray();\n case 't':\n this.consumeKeyword('true');\n return true;\n case 'f':\n this.consumeKeyword('false');\n return false;\n case 'n':\n this.consumeKeyword('null');\n return null;\n default:\n if (current === '-' || isAsciiDigit(current)) {\n return this.parseNumber();\n }\n this.fail(`Unexpected token ${JSON.stringify(current)}.`);\n }\n }\n\n private consumeKeyword(keyword: string): void {\n if (!this.text.startsWith(keyword, this.index)) {\n this.fail(`Expected ${keyword}.`);\n }\n this.index += keyword.length;\n }\n\n private parseString(): string {\n let result = '';\n this.index += 1;\n\n while (!this.isAtEnd()) {\n const current = this.text[this.index]!;\n if (current === '\"') {\n this.index += 1;\n return result;\n }\n if (current === '\\\\') {\n this.index += 1;\n if (this.isAtEnd()) {\n this.fail('Unexpected end of escape sequence.');\n }\n result += this.parseEscapeSequence();\n continue;\n }\n result += current;\n this.index += 1;\n }\n\n this.fail('Unterminated string literal.');\n }\n\n private parseEscapeSequence(): string {\n const current = this.text[this.index]!;\n this.index += 1;\n switch (current) {\n case '\"':\n case '\\\\':\n case '/':\n return current;\n case 'b':\n return '\\b';\n case 'f':\n return '\\f';\n case 'n':\n return '\\n';\n case 'r':\n return '\\r';\n case 't':\n return '\\t';\n case 'u': {\n const hex = this.text.slice(this.index, this.index + 4);\n if (!/^[0-9A-Fa-f]{4}$/u.test(hex)) {\n this.fail('Invalid unicode escape.');\n }\n this.index += 4;\n return String.fromCharCode(Number.parseInt(hex, 16));\n }\n default:\n this.fail(`Invalid escape sequence \\\\${current}.`);\n }\n }\n\n private parseArray(): LosslessJsonArray {\n const result: LosslessJsonArray = [];\n this.index += 1;\n this.skipWhitespace();\n if (this.text[this.index] === ']') {\n this.index += 1;\n return result;\n }\n\n while (true) {\n result.push(this.parseValue());\n this.skipWhitespace();\n const current = this.text[this.index];\n if (current === ']') {\n this.index += 1;\n return result;\n }\n if (current !== ',') {\n this.fail('Expected , or ] in array literal.');\n }\n this.index += 1;\n }\n }\n\n private parseObject(): LosslessJsonObject {\n const result: LosslessJsonObject = {};\n this.index += 1;\n this.skipWhitespace();\n if (this.text[this.index] === '}') {\n this.index += 1;\n return result;\n }\n\n while (true) {\n this.skipWhitespace();\n if (this.text[this.index] !== '\"') {\n this.fail('Expected string key in object literal.');\n }\n const key = this.parseString();\n this.skipWhitespace();\n if (this.text[this.index] !== ':') {\n this.fail('Expected : after object key.');\n }\n this.index += 1;\n result[key] = this.parseValue();\n this.skipWhitespace();\n const current = this.text[this.index];\n if (current === '}') {\n this.index += 1;\n return result;\n }\n if (current !== ',') {\n this.fail('Expected , or } in object literal.');\n }\n this.index += 1;\n }\n }\n\n private parseNumber(): number | bigint {\n const start = this.index;\n if (this.text[this.index] === '-') {\n this.index += 1;\n }\n\n if (this.text[this.index] === '0') {\n this.index += 1;\n } else {\n this.consumeDigits();\n }\n\n let isInteger = true;\n if (this.text[this.index] === '.') {\n isInteger = false;\n this.index += 1;\n this.consumeDigits();\n }\n\n const exponentMarker = this.text[this.index];\n if (exponentMarker === 'e' || exponentMarker === 'E') {\n isInteger = false;\n this.index += 1;\n const sign = this.text[this.index];\n if (sign === '+' || sign === '-') {\n this.index += 1;\n }\n this.consumeDigits();\n }\n\n const token = this.text.slice(start, this.index);\n if (!isInteger) {\n return Number(token);\n }\n if (token === '-0') {\n return -0;\n }\n\n const bigintValue = BigInt(token);\n return bigintValue <= MAX_SAFE_INTEGER_BIGINT && bigintValue >= MIN_SAFE_INTEGER_BIGINT\n ? Number(token)\n : bigintValue;\n }\n\n private consumeDigits(): void {\n const start = this.index;\n while (!this.isAtEnd() && isAsciiDigit(this.text[this.index]!)) {\n this.index += 1;\n }\n if (start === this.index) {\n this.fail('Expected digits.');\n }\n }\n}\n\nclass JsonLikeParser {\n #index = 0;\n readonly #text: string;\n\n constructor(text: string) {\n this.#text = text;\n }\n\n finish(): void {\n this.#skipWhitespace();\n if (this.#index !== this.#text.length) {\n this.#error('Unexpected trailing JSON input');\n }\n }\n\n parseValue(): JsonLikeValue {\n this.#skipWhitespace();\n const current = this.#text[this.#index];\n switch (current) {\n case '{':\n return this.#parseObject();\n case '[':\n return this.#parseArray();\n case '\"':\n return this.#parseString();\n case 't':\n this.#consumeKeyword('true');\n return true;\n case 'f':\n this.#consumeKeyword('false');\n return false;\n case 'n':\n this.#consumeKeyword('null');\n return null;\n default:\n if (current === '-' || this.#isDigit(current)) {\n return this.#parseNumber();\n }\n this.#error('Unexpected token in JSON input');\n }\n }\n\n #consumeKeyword(keyword: string): void {\n if (this.#text.slice(this.#index, this.#index + keyword.length) !== keyword) {\n this.#error(`Expected ${keyword}`);\n }\n this.#index += keyword.length;\n }\n\n #parseArray(): JsonLikeArray {\n const values: JsonLikeValue[] = [];\n this.#index += 1;\n this.#skipWhitespace();\n if (this.#text[this.#index] === ']') {\n this.#index += 1;\n return values;\n }\n\n while (true) {\n values.push(this.parseValue());\n this.#skipWhitespace();\n const current = this.#text[this.#index];\n if (current === ']') {\n this.#index += 1;\n return values;\n }\n if (current !== ',') {\n this.#error('Expected , or ] in JSON array');\n }\n this.#index += 1;\n }\n }\n\n #parseNumber(): number | bigint {\n const start = this.#index;\n if (this.#text[this.#index] === '-') {\n this.#index += 1;\n }\n\n if (this.#text[this.#index] === '0') {\n this.#index += 1;\n } else {\n this.#consumeDigits();\n }\n\n let isInteger = true;\n if (this.#text[this.#index] === '.') {\n isInteger = false;\n this.#index += 1;\n this.#consumeDigits();\n }\n\n const exponent = this.#text[this.#index];\n if (exponent === 'e' || exponent === 'E') {\n isInteger = false;\n this.#index += 1;\n const sign = this.#text[this.#index];\n if (sign === '+' || sign === '-') {\n this.#index += 1;\n }\n this.#consumeDigits();\n }\n\n const token = this.#text.slice(start, this.#index);\n if (!isInteger) {\n return Number(token);\n }\n\n const bigintValue = BigInt(token);\n const numberValue = Number(token);\n return Number.isSafeInteger(numberValue) && BigInt(numberValue) === bigintValue\n ? numberValue\n : bigintValue;\n }\n\n #parseObject(): JsonLikeObject {\n const object: Record<string, JsonLikeValue> = {};\n this.#index += 1;\n this.#skipWhitespace();\n if (this.#text[this.#index] === '}') {\n this.#index += 1;\n return object;\n }\n\n while (true) {\n this.#skipWhitespace();\n if (this.#text[this.#index] !== '\"') {\n this.#error('Expected string key in JSON object');\n }\n const key = this.#parseString();\n this.#skipWhitespace();\n if (this.#text[this.#index] !== ':') {\n this.#error('Expected : in JSON object');\n }\n this.#index += 1;\n object[key] = this.parseValue();\n this.#skipWhitespace();\n const current = this.#text[this.#index];\n if (current === '}') {\n this.#index += 1;\n return object;\n }\n if (current !== ',') {\n this.#error('Expected , or } in JSON object');\n }\n this.#index += 1;\n }\n }\n\n #parseString(): string {\n const start = this.#index;\n this.#index += 1;\n while (this.#index < this.#text.length) {\n const current = this.#text[this.#index];\n if (current === '\"') {\n this.#index += 1;\n return JSON.parse(this.#text.slice(start, this.#index));\n }\n if (current === '\\\\') {\n this.#index += 1;\n const escaped = this.#text[this.#index];\n if (escaped === undefined) {\n this.#error('Unterminated string escape');\n }\n if (escaped === 'u') {\n for (let index = 0; index < 4; index += 1) {\n this.#index += 1;\n if (!/[0-9A-Fa-f]/u.test(this.#text[this.#index] ?? '')) {\n this.#error('Invalid unicode escape');\n }\n }\n }\n } else if (current <= '\\u001F') {\n this.#error('Invalid control character in string literal');\n }\n this.#index += 1;\n }\n this.#error('Unterminated string literal');\n }\n\n #consumeDigits(): void {\n const start = this.#index;\n while (this.#isDigit(this.#text[this.#index])) {\n this.#index += 1;\n }\n if (start === this.#index) {\n this.#error('Expected digit in JSON number');\n }\n }\n\n #skipWhitespace(): void {\n while (/\\s/u.test(this.#text[this.#index] ?? '')) {\n this.#index += 1;\n }\n }\n\n #isDigit(value: string | undefined): boolean {\n return value !== undefined && value >= '0' && value <= '9';\n }\n\n #error(message: string): never {\n throw new SyntaxError(`${message} at position ${this.#index}.`);\n }\n}\n\nfunction isAsciiDigit(text: string): boolean {\n return text >= '0' && text <= '9';\n}\n"]}
|