@stryke/json 0.9.44 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/code-frames-BUtrssZ5.d.cts +17 -0
- package/dist/code-frames-BUtrssZ5.d.cts.map +1 -0
- package/dist/code-frames-BmUvlJ0w.cjs +82 -0
- package/dist/code-frames-CrTAYYSE.d.mts +17 -0
- package/dist/code-frames-CrTAYYSE.d.mts.map +1 -0
- package/dist/code-frames-DuBfTMu4.mjs +77 -0
- package/dist/code-frames-DuBfTMu4.mjs.map +1 -0
- package/dist/find-reference-B8xshNXL.d.mts +52 -0
- package/dist/find-reference-B8xshNXL.d.mts.map +1 -0
- package/dist/find-reference-C-YleCds.d.cts +52 -0
- package/dist/find-reference-C-YleCds.d.cts.map +1 -0
- package/dist/find-reference-DMSYEaaI.mjs +64 -0
- package/dist/find-reference-DMSYEaaI.mjs.map +1 -0
- package/dist/find-reference-De5vBQV2.cjs +86 -0
- package/dist/index-B_e8BwCm.d.cts +1 -0
- package/dist/index-CCt0lwyI.d.mts +1 -0
- package/dist/index-CDAfh8Ew.d.cts +1 -0
- package/dist/index-DvuJXuAN.d.mts +1 -0
- package/dist/index.cjs +37 -14
- package/dist/index.d.cts +11 -8
- package/dist/index.d.mts +12 -9
- package/dist/index.mjs +13 -8
- package/dist/is-number-BIwzZzyi.mjs +31 -0
- package/dist/is-number-BIwzZzyi.mjs.map +1 -0
- package/dist/is-number-c5xguIbS.cjs +42 -0
- package/dist/{type-checks/src/is-plain-object.mjs → is-object-BpfmzHWa.mjs} +19 -3
- package/dist/is-object-BpfmzHWa.mjs.map +1 -0
- package/dist/{type-checks/src/is-plain-object.cjs → is-object-umGh91v1.cjs} +24 -3
- package/dist/is-set-object-BmHip9em.cjs +108 -0
- package/dist/is-set-object-C1Qnj1Q8.mjs +98 -0
- package/dist/is-set-object-C1Qnj1Q8.mjs.map +1 -0
- package/dist/{type-checks/src/is-string.mjs → is-string-C2RK4Gjs.cjs} +7 -2
- package/dist/{type-checks/src/is-string.cjs → is-string-CLiBUSKV.mjs} +2 -2
- package/dist/is-string-CLiBUSKV.mjs.map +1 -0
- package/dist/{type-checks/src/is-undefined.cjs → is-undefined-CmyJWYGD.mjs} +2 -2
- package/dist/is-undefined-CmyJWYGD.mjs.map +1 -0
- package/dist/{type-checks/src/is-undefined.mjs → is-undefined-CnI0qe-z.cjs} +7 -2
- package/dist/parse-BGlhbY16.d.cts +9 -0
- package/dist/parse-BGlhbY16.d.cts.map +1 -0
- package/dist/parse-Bp6kkcQ4.cjs +127 -0
- package/dist/parse-ByDxRup5.cjs +62 -0
- package/dist/parse-Cj-YfhrI.d.mts +51 -0
- package/dist/parse-Cj-YfhrI.d.mts.map +1 -0
- package/dist/parse-DZfi3d96.d.cts +51 -0
- package/dist/parse-DZfi3d96.d.cts.map +1 -0
- package/dist/parse-Dn43ZK9y.mjs +52 -0
- package/dist/parse-Dn43ZK9y.mjs.map +1 -0
- package/dist/parse-error-7K8s4vWf.d.cts +15 -0
- package/dist/parse-error-7K8s4vWf.d.cts.map +1 -0
- package/dist/parse-error-Af4zHUQ_.mjs +34 -0
- package/dist/parse-error-Af4zHUQ_.mjs.map +1 -0
- package/dist/parse-error-DpEv3vo_.d.mts +15 -0
- package/dist/parse-error-DpEv3vo_.d.mts.map +1 -0
- package/dist/parse-error-N7UE-HMh.cjs +39 -0
- package/dist/parse-fXy5pbmE.d.mts +9 -0
- package/dist/parse-fXy5pbmE.d.mts.map +1 -0
- package/dist/parse-vw_qRD3F.mjs +81 -0
- package/dist/parse-vw_qRD3F.mjs.map +1 -0
- package/dist/pointer/find-reference.cjs +5 -65
- package/dist/pointer/find-reference.d.cts +2 -52
- package/dist/pointer/find-reference.d.mts +2 -52
- package/dist/pointer/find-reference.mjs +2 -63
- package/dist/pointer/index.cjs +15 -14
- package/dist/pointer/index.d.cts +2 -2
- package/dist/pointer/index.d.mts +2 -2
- package/dist/pointer/index.mjs +3 -2
- package/dist/pointer/parse.cjs +9 -86
- package/dist/pointer/parse.d.cts +2 -44
- package/dist/pointer/parse.d.mts +2 -44
- package/dist/pointer/parse.mjs +2 -80
- package/dist/pointer-B3W_Sme3.cjs +0 -0
- package/dist/pointer-Dn__XOdY.mjs +0 -0
- package/dist/schema-BO1HCrxv.d.cts +55 -0
- package/dist/schema-BO1HCrxv.d.cts.map +1 -0
- package/dist/schema-CmH1V_uI.d.mts +55 -0
- package/dist/schema-CmH1V_uI.d.mts.map +1 -0
- package/dist/schema-DGmzxHja.mjs +72 -0
- package/dist/schema-DGmzxHja.mjs.map +1 -0
- package/dist/schema-Dl018Aq4.cjs +106 -0
- package/dist/schema.cjs +8 -0
- package/dist/schema.d.cts +2 -0
- package/dist/schema.d.mts +3 -0
- package/dist/schema.mjs +3 -0
- package/dist/storm-json-8F9CKpXu.d.mts +70 -0
- package/dist/storm-json-8F9CKpXu.d.mts.map +1 -0
- package/dist/storm-json-BD6WFbrI.cjs +154 -0
- package/dist/storm-json-DvIEWMEH.d.cts +70 -0
- package/dist/storm-json-DvIEWMEH.d.cts.map +1 -0
- package/dist/storm-json-nkhJgTz4.mjs +116 -0
- package/dist/storm-json-nkhJgTz4.mjs.map +1 -0
- package/dist/storm-json.cjs +3 -116
- package/dist/storm-json.d.cts +2 -70
- package/dist/storm-json.d.mts +3 -70
- package/dist/storm-json.mjs +3 -115
- package/dist/stringify-Bc8OkhIr.d.cts +13 -0
- package/dist/stringify-Bc8OkhIr.d.cts.map +1 -0
- package/dist/stringify-BehjrfhS.cjs +78 -0
- package/dist/stringify-CFT1K1LE.d.mts +13 -0
- package/dist/stringify-CFT1K1LE.d.mts.map +1 -0
- package/dist/stringify-CYHjAvWm.mjs +68 -0
- package/dist/stringify-CYHjAvWm.mjs.map +1 -0
- package/dist/strip-comments-BA8MS_Fs.d.mts +11 -0
- package/dist/strip-comments-BA8MS_Fs.d.mts.map +1 -0
- package/dist/strip-comments-CmEG_smS.cjs +94 -0
- package/dist/strip-comments-Cz_Wc25t.d.cts +11 -0
- package/dist/strip-comments-Cz_Wc25t.d.cts.map +1 -0
- package/dist/strip-comments-Dq00N_Sg.mjs +89 -0
- package/dist/strip-comments-Dq00N_Sg.mjs.map +1 -0
- package/dist/types-Bn8rC098.d.cts +222 -0
- package/dist/types-Bn8rC098.d.cts.map +1 -0
- package/dist/types-CPQlxauZ.d.mts +222 -0
- package/dist/types-CPQlxauZ.d.mts.map +1 -0
- package/dist/types.d.cts +2 -69
- package/dist/types.d.mts +2 -69
- package/dist/types.mjs +0 -1
- package/dist/utils/code-frames.cjs +2 -76
- package/dist/utils/code-frames.d.cts +2 -17
- package/dist/utils/code-frames.d.mts +2 -17
- package/dist/utils/code-frames.mjs +2 -76
- package/dist/utils/index.cjs +13 -12
- package/dist/utils/index.d.cts +5 -5
- package/dist/utils/index.d.mts +6 -5
- package/dist/utils/index.mjs +6 -5
- package/dist/utils/parse-error.cjs +2 -33
- package/dist/utils/parse-error.d.cts +2 -15
- package/dist/utils/parse-error.d.mts +2 -15
- package/dist/utils/parse-error.mjs +2 -33
- package/dist/utils/parse.cjs +3 -51
- package/dist/utils/parse.d.cts +2 -9
- package/dist/utils/parse.d.mts +2 -9
- package/dist/utils/parse.mjs +2 -51
- package/dist/utils/stringify.cjs +3 -67
- package/dist/utils/stringify.d.cts +2 -13
- package/dist/utils/stringify.d.mts +2 -13
- package/dist/utils/stringify.mjs +2 -67
- package/dist/utils/strip-comments.cjs +2 -85
- package/dist/utils/strip-comments.d.cts +2 -11
- package/dist/utils/strip-comments.d.mts +2 -11
- package/dist/utils/strip-comments.mjs +2 -86
- package/dist/utils-jN2UkvqB.cjs +0 -0
- package/dist/utils-mEkKIcgl.mjs +0 -0
- package/package.json +12 -3
- package/dist/_virtual/rolldown_runtime.cjs +0 -29
- package/dist/pointer/find-reference.d.cts.map +0 -1
- package/dist/pointer/find-reference.d.mts.map +0 -1
- package/dist/pointer/find-reference.mjs.map +0 -1
- package/dist/pointer/parse.d.cts.map +0 -1
- package/dist/pointer/parse.d.mts.map +0 -1
- package/dist/pointer/parse.mjs.map +0 -1
- package/dist/storm-json.d.cts.map +0 -1
- package/dist/storm-json.d.mts.map +0 -1
- package/dist/storm-json.mjs.map +0 -1
- package/dist/type-checks/src/get-object-tag.cjs +0 -15
- package/dist/type-checks/src/get-object-tag.mjs +0 -15
- package/dist/type-checks/src/get-object-tag.mjs.map +0 -1
- package/dist/type-checks/src/is-empty.cjs +0 -20
- package/dist/type-checks/src/is-empty.mjs +0 -21
- package/dist/type-checks/src/is-empty.mjs.map +0 -1
- package/dist/type-checks/src/is-non-null-object.cjs +0 -16
- package/dist/type-checks/src/is-non-null-object.mjs +0 -17
- package/dist/type-checks/src/is-non-null-object.mjs.map +0 -1
- package/dist/type-checks/src/is-null.cjs +0 -12
- package/dist/type-checks/src/is-null.mjs +0 -12
- package/dist/type-checks/src/is-null.mjs.map +0 -1
- package/dist/type-checks/src/is-number.cjs +0 -18
- package/dist/type-checks/src/is-number.mjs +0 -18
- package/dist/type-checks/src/is-number.mjs.map +0 -1
- package/dist/type-checks/src/is-object.cjs +0 -19
- package/dist/type-checks/src/is-object.mjs +0 -20
- package/dist/type-checks/src/is-object.mjs.map +0 -1
- package/dist/type-checks/src/is-plain-object.mjs.map +0 -1
- package/dist/type-checks/src/is-set-object.cjs +0 -19
- package/dist/type-checks/src/is-set-object.mjs +0 -20
- package/dist/type-checks/src/is-set-object.mjs.map +0 -1
- package/dist/type-checks/src/is-set.cjs +0 -19
- package/dist/type-checks/src/is-set.mjs +0 -20
- package/dist/type-checks/src/is-set.mjs.map +0 -1
- package/dist/type-checks/src/is-string.mjs.map +0 -1
- package/dist/type-checks/src/is-undefined.mjs.map +0 -1
- package/dist/types/src/base.cjs +0 -6
- package/dist/types/src/base.mjs +0 -6
- package/dist/types/src/base.mjs.map +0 -1
- package/dist/types/src/json.d.cts +0 -12
- package/dist/types/src/json.d.cts.map +0 -1
- package/dist/types/src/json.d.mts +0 -12
- package/dist/types/src/json.d.mts.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts.map +0 -1
- package/dist/utils/code-frames.d.cts.map +0 -1
- package/dist/utils/code-frames.d.mts.map +0 -1
- package/dist/utils/code-frames.mjs.map +0 -1
- package/dist/utils/parse-error.d.cts.map +0 -1
- package/dist/utils/parse-error.d.mts.map +0 -1
- package/dist/utils/parse-error.mjs.map +0 -1
- package/dist/utils/parse.d.cts.map +0 -1
- package/dist/utils/parse.d.mts.map +0 -1
- package/dist/utils/parse.mjs.map +0 -1
- package/dist/utils/stringify.d.cts.map +0 -1
- package/dist/utils/stringify.d.mts.map +0 -1
- package/dist/utils/stringify.mjs.map +0 -1
- package/dist/utils/strip-comments.d.cts.map +0 -1
- package/dist/utils/strip-comments.d.mts.map +0 -1
- package/dist/utils/strip-comments.mjs.map +0 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { n as isFunction, t as isSetObject } from "./is-set-object-C1Qnj1Q8.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/schema.ts
|
|
4
|
+
/**
|
|
5
|
+
* Type guard for {@link JsonSchema7AllOfType}
|
|
6
|
+
*
|
|
7
|
+
* @param schema - The schema to check
|
|
8
|
+
* @returns True if the schema is a {@link JsonSchema7AllOfType}, false otherwise
|
|
9
|
+
*/
|
|
10
|
+
function isJsonSchema7AllOfType(schema) {
|
|
11
|
+
if ("type" in schema && schema.type === "string") return false;
|
|
12
|
+
return "allOf" in schema;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Type guard for {@link JsonSchema7ObjectType}
|
|
16
|
+
*
|
|
17
|
+
* @param schema - The schema to check
|
|
18
|
+
* @returns True if the schema is a {@link JsonSchema7ObjectType}, false otherwise
|
|
19
|
+
*/
|
|
20
|
+
function isJsonSchema7ObjectType(schema) {
|
|
21
|
+
if ("type" in schema && schema.type === "object") return false;
|
|
22
|
+
return "properties" in schema;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Type guard for {@link JsonSchema7ArrayType}
|
|
26
|
+
*
|
|
27
|
+
* @param schema - The schema to check
|
|
28
|
+
* @returns True if the schema is a {@link JsonSchema7ArrayType}, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
function isJsonSchema7ArrayType(schema) {
|
|
31
|
+
return "type" in schema && schema.type === "array" && "items" in schema;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Type guard for {@link JsonSchema7PrimitiveLiteralType}
|
|
35
|
+
*
|
|
36
|
+
* @param schema - The schema to check
|
|
37
|
+
* @returns True if the schema is a {@link JsonSchema7PrimitiveLiteralType}, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
function isJsonSchema7PrimitiveLiteralType(schema) {
|
|
40
|
+
if (!("type" in schema)) return false;
|
|
41
|
+
const { type } = schema;
|
|
42
|
+
return (type === "string" || type === "number" || type === "integer" || type === "boolean") && "const" in schema;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Type guard for {@link JsonSchema7LiteralType}
|
|
46
|
+
*
|
|
47
|
+
* @param schema - The schema to check
|
|
48
|
+
* @returns True if the schema is a {@link JsonSchema7LiteralType}, false otherwise
|
|
49
|
+
*/
|
|
50
|
+
function isJsonSchema7LiteralType(schema) {
|
|
51
|
+
if (isJsonSchema7PrimitiveLiteralType(schema)) return true;
|
|
52
|
+
if (!("type" in schema)) return false;
|
|
53
|
+
return schema.type === "object" || schema.type === "array";
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Type guard to check if a value is a {@link StandardJSONSchemaV1 | Standard JSON Schema}.
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* This function checks if the value has the structure of a Standard JSON Schema, which includes a `~standard` property with a `jsonSchema` object that has `input` and `output` functions.
|
|
60
|
+
*
|
|
61
|
+
* @see https://standardschema.dev/json-schema
|
|
62
|
+
*
|
|
63
|
+
* @param value - The value to check.
|
|
64
|
+
* @returns True if the value is a {@link StandardJSONSchemaV1 | Standard JSON Schema}, false otherwise.
|
|
65
|
+
*/
|
|
66
|
+
function isStandardJsonSchema(value) {
|
|
67
|
+
return isSetObject(value) && "~standard" in value && isSetObject(value["~standard"]) && "jsonSchema" in value["~standard"] && isSetObject(value["~standard"].jsonSchema) && "input" in value["~standard"].jsonSchema && isFunction(value["~standard"].jsonSchema.input) && "output" in value["~standard"].jsonSchema && isFunction(value["~standard"].jsonSchema.output);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { isJsonSchema7PrimitiveLiteralType as a, isJsonSchema7ObjectType as i, isJsonSchema7ArrayType as n, isStandardJsonSchema as o, isJsonSchema7LiteralType as r, isJsonSchema7AllOfType as t };
|
|
72
|
+
//# sourceMappingURL=schema-DGmzxHja.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-DGmzxHja.mjs","names":[],"sources":["../src/schema.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport type {\n JsonSchema7AllOfType,\n JsonSchema7ArrayType,\n JsonSchema7LiteralType,\n JsonSchema7ObjectType,\n JsonSchema7PrimitiveLiteralType,\n JsonSchema7StringType,\n JsonSchema7Type\n} from \"./types\";\n\n/**\n * Type guard for {@link JsonSchema7AllOfType}\n *\n * @param schema - The schema to check\n * @returns True if the schema is a {@link JsonSchema7AllOfType}, false otherwise\n */\nexport function isJsonSchema7AllOfType(\n schema: JsonSchema7Type | JsonSchema7StringType\n): schema is JsonSchema7AllOfType {\n if (\"type\" in schema && schema.type === \"string\") {\n return false;\n }\n\n return \"allOf\" in schema;\n}\n\n/**\n * Type guard for {@link JsonSchema7ObjectType}\n *\n * @param schema - The schema to check\n * @returns True if the schema is a {@link JsonSchema7ObjectType}, false otherwise\n */\nexport function isJsonSchema7ObjectType(\n schema: JsonSchema7Type | JsonSchema7StringType\n): schema is JsonSchema7ObjectType {\n if (\"type\" in schema && schema.type === \"object\") {\n return false;\n }\n\n return \"properties\" in schema;\n}\n\n/**\n * Type guard for {@link JsonSchema7ArrayType}\n *\n * @param schema - The schema to check\n * @returns True if the schema is a {@link JsonSchema7ArrayType}, false otherwise\n */\nexport function isJsonSchema7ArrayType(\n schema: JsonSchema7Type\n): schema is JsonSchema7ArrayType {\n return \"type\" in schema && schema.type === \"array\" && \"items\" in schema;\n}\n\n/**\n * Type guard for {@link JsonSchema7PrimitiveLiteralType}\n *\n * @param schema - The schema to check\n * @returns True if the schema is a {@link JsonSchema7PrimitiveLiteralType}, false otherwise\n */\nexport function isJsonSchema7PrimitiveLiteralType(\n schema: JsonSchema7Type\n): schema is JsonSchema7PrimitiveLiteralType {\n if (!(\"type\" in schema)) {\n return false;\n }\n\n const { type } = schema;\n\n return (\n (type === \"string\" ||\n type === \"number\" ||\n type === \"integer\" ||\n type === \"boolean\") &&\n \"const\" in schema\n );\n}\n\n/**\n * Type guard for {@link JsonSchema7LiteralType}\n *\n * @param schema - The schema to check\n * @returns True if the schema is a {@link JsonSchema7LiteralType}, false otherwise\n */\nexport function isJsonSchema7LiteralType(\n schema: JsonSchema7Type\n): schema is JsonSchema7LiteralType {\n if (isJsonSchema7PrimitiveLiteralType(schema)) {\n return true;\n }\n\n if (!(\"type\" in schema)) {\n return false;\n }\n\n return schema.type === \"object\" || schema.type === \"array\";\n}\n\n/**\n * Type guard to check if a value is a {@link StandardJSONSchemaV1 | Standard JSON Schema}.\n *\n * @remarks\n * This function checks if the value has the structure of a Standard JSON Schema, which includes a `~standard` property with a `jsonSchema` object that has `input` and `output` functions.\n *\n * @see https://standardschema.dev/json-schema\n *\n * @param value - The value to check.\n * @returns True if the value is a {@link StandardJSONSchemaV1 | Standard JSON Schema}, false otherwise.\n */\nexport function isStandardJsonSchema<Input = unknown, Output = Input>(\n value: any\n): value is StandardJSONSchemaV1<Input, Output> {\n return (\n isSetObject(value) &&\n \"~standard\" in value &&\n isSetObject(value[\"~standard\"]) &&\n \"jsonSchema\" in value[\"~standard\"] &&\n isSetObject(value[\"~standard\"].jsonSchema) &&\n \"input\" in value[\"~standard\"].jsonSchema &&\n isFunction(value[\"~standard\"].jsonSchema.input) &&\n \"output\" in value[\"~standard\"].jsonSchema &&\n isFunction(value[\"~standard\"].jsonSchema.output)\n );\n}\n"],"mappings":";;;;;;;;;AAqCA,SAAgB,uBACd,QACgC;AAChC,KAAI,UAAU,UAAU,OAAO,SAAS,SACtC,QAAO;AAGT,QAAO,WAAW;;;;;;;;AASpB,SAAgB,wBACd,QACiC;AACjC,KAAI,UAAU,UAAU,OAAO,SAAS,SACtC,QAAO;AAGT,QAAO,gBAAgB;;;;;;;;AASzB,SAAgB,uBACd,QACgC;AAChC,QAAO,UAAU,UAAU,OAAO,SAAS,WAAW,WAAW;;;;;;;;AASnE,SAAgB,kCACd,QAC2C;AAC3C,KAAI,EAAE,UAAU,QACd,QAAO;CAGT,MAAM,EAAE,SAAS;AAEjB,SACG,SAAS,YACR,SAAS,YACT,SAAS,aACT,SAAS,cACX,WAAW;;;;;;;;AAUf,SAAgB,yBACd,QACkC;AAClC,KAAI,kCAAkC,OAAO,CAC3C,QAAO;AAGT,KAAI,EAAE,UAAU,QACd,QAAO;AAGT,QAAO,OAAO,SAAS,YAAY,OAAO,SAAS;;;;;;;;;;;;;AAcrD,SAAgB,qBACd,OAC8C;AAC9C,QACE,YAAY,MAAM,IAClB,eAAe,SACf,YAAY,MAAM,aAAa,IAC/B,gBAAgB,MAAM,gBACtB,YAAY,MAAM,aAAa,WAAW,IAC1C,WAAW,MAAM,aAAa,cAC9B,WAAW,MAAM,aAAa,WAAW,MAAM,IAC/C,YAAY,MAAM,aAAa,cAC/B,WAAW,MAAM,aAAa,WAAW,OAAO"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const require_is_set_object = require('./is-set-object-BmHip9em.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/schema.ts
|
|
4
|
+
/**
|
|
5
|
+
* Type guard for {@link JsonSchema7AllOfType}
|
|
6
|
+
*
|
|
7
|
+
* @param schema - The schema to check
|
|
8
|
+
* @returns True if the schema is a {@link JsonSchema7AllOfType}, false otherwise
|
|
9
|
+
*/
|
|
10
|
+
function isJsonSchema7AllOfType(schema) {
|
|
11
|
+
if ("type" in schema && schema.type === "string") return false;
|
|
12
|
+
return "allOf" in schema;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Type guard for {@link JsonSchema7ObjectType}
|
|
16
|
+
*
|
|
17
|
+
* @param schema - The schema to check
|
|
18
|
+
* @returns True if the schema is a {@link JsonSchema7ObjectType}, false otherwise
|
|
19
|
+
*/
|
|
20
|
+
function isJsonSchema7ObjectType(schema) {
|
|
21
|
+
if ("type" in schema && schema.type === "object") return false;
|
|
22
|
+
return "properties" in schema;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Type guard for {@link JsonSchema7ArrayType}
|
|
26
|
+
*
|
|
27
|
+
* @param schema - The schema to check
|
|
28
|
+
* @returns True if the schema is a {@link JsonSchema7ArrayType}, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
function isJsonSchema7ArrayType(schema) {
|
|
31
|
+
return "type" in schema && schema.type === "array" && "items" in schema;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Type guard for {@link JsonSchema7PrimitiveLiteralType}
|
|
35
|
+
*
|
|
36
|
+
* @param schema - The schema to check
|
|
37
|
+
* @returns True if the schema is a {@link JsonSchema7PrimitiveLiteralType}, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
function isJsonSchema7PrimitiveLiteralType(schema) {
|
|
40
|
+
if (!("type" in schema)) return false;
|
|
41
|
+
const { type } = schema;
|
|
42
|
+
return (type === "string" || type === "number" || type === "integer" || type === "boolean") && "const" in schema;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Type guard for {@link JsonSchema7LiteralType}
|
|
46
|
+
*
|
|
47
|
+
* @param schema - The schema to check
|
|
48
|
+
* @returns True if the schema is a {@link JsonSchema7LiteralType}, false otherwise
|
|
49
|
+
*/
|
|
50
|
+
function isJsonSchema7LiteralType(schema) {
|
|
51
|
+
if (isJsonSchema7PrimitiveLiteralType(schema)) return true;
|
|
52
|
+
if (!("type" in schema)) return false;
|
|
53
|
+
return schema.type === "object" || schema.type === "array";
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Type guard to check if a value is a {@link StandardJSONSchemaV1 | Standard JSON Schema}.
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* This function checks if the value has the structure of a Standard JSON Schema, which includes a `~standard` property with a `jsonSchema` object that has `input` and `output` functions.
|
|
60
|
+
*
|
|
61
|
+
* @see https://standardschema.dev/json-schema
|
|
62
|
+
*
|
|
63
|
+
* @param value - The value to check.
|
|
64
|
+
* @returns True if the value is a {@link StandardJSONSchemaV1 | Standard JSON Schema}, false otherwise.
|
|
65
|
+
*/
|
|
66
|
+
function isStandardJsonSchema(value) {
|
|
67
|
+
return require_is_set_object.isSetObject(value) && "~standard" in value && require_is_set_object.isSetObject(value["~standard"]) && "jsonSchema" in value["~standard"] && require_is_set_object.isSetObject(value["~standard"].jsonSchema) && "input" in value["~standard"].jsonSchema && require_is_set_object.isFunction(value["~standard"].jsonSchema.input) && "output" in value["~standard"].jsonSchema && require_is_set_object.isFunction(value["~standard"].jsonSchema.output);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
Object.defineProperty(exports, 'isJsonSchema7AllOfType', {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
get: function () {
|
|
74
|
+
return isJsonSchema7AllOfType;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(exports, 'isJsonSchema7ArrayType', {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function () {
|
|
80
|
+
return isJsonSchema7ArrayType;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(exports, 'isJsonSchema7LiteralType', {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function () {
|
|
86
|
+
return isJsonSchema7LiteralType;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(exports, 'isJsonSchema7ObjectType', {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function () {
|
|
92
|
+
return isJsonSchema7ObjectType;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(exports, 'isJsonSchema7PrimitiveLiteralType', {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function () {
|
|
98
|
+
return isJsonSchema7PrimitiveLiteralType;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(exports, 'isStandardJsonSchema', {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
get: function () {
|
|
104
|
+
return isStandardJsonSchema;
|
|
105
|
+
}
|
|
106
|
+
});
|
package/dist/schema.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const require_schema = require('./schema-Dl018Aq4.cjs');
|
|
2
|
+
|
|
3
|
+
exports.isJsonSchema7AllOfType = require_schema.isJsonSchema7AllOfType;
|
|
4
|
+
exports.isJsonSchema7ArrayType = require_schema.isJsonSchema7ArrayType;
|
|
5
|
+
exports.isJsonSchema7LiteralType = require_schema.isJsonSchema7LiteralType;
|
|
6
|
+
exports.isJsonSchema7ObjectType = require_schema.isJsonSchema7ObjectType;
|
|
7
|
+
exports.isJsonSchema7PrimitiveLiteralType = require_schema.isJsonSchema7PrimitiveLiteralType;
|
|
8
|
+
exports.isStandardJsonSchema = require_schema.isStandardJsonSchema;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as isJsonSchema7PrimitiveLiteralType, i as isJsonSchema7ObjectType, n as isJsonSchema7ArrayType, o as isStandardJsonSchema, r as isJsonSchema7LiteralType, t as isJsonSchema7AllOfType } from "./schema-BO1HCrxv.cjs";
|
|
2
|
+
export { isJsonSchema7AllOfType, isJsonSchema7ArrayType, isJsonSchema7LiteralType, isJsonSchema7ObjectType, isJsonSchema7PrimitiveLiteralType, isStandardJsonSchema };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import "./types-CPQlxauZ.mjs";
|
|
2
|
+
import { a as isJsonSchema7PrimitiveLiteralType, i as isJsonSchema7ObjectType, n as isJsonSchema7ArrayType, o as isStandardJsonSchema, r as isJsonSchema7LiteralType, t as isJsonSchema7AllOfType } from "./schema-CmH1V_uI.mjs";
|
|
3
|
+
export { isJsonSchema7AllOfType, isJsonSchema7ArrayType, isJsonSchema7LiteralType, isJsonSchema7ObjectType, isJsonSchema7PrimitiveLiteralType, isStandardJsonSchema };
|
package/dist/schema.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as isJsonSchema7PrimitiveLiteralType, i as isJsonSchema7ObjectType, n as isJsonSchema7ArrayType, o as isStandardJsonSchema, r as isJsonSchema7LiteralType, t as isJsonSchema7AllOfType } from "./schema-DGmzxHja.mjs";
|
|
2
|
+
|
|
3
|
+
export { isJsonSchema7AllOfType, isJsonSchema7ArrayType, isJsonSchema7LiteralType, isJsonSchema7ObjectType, isJsonSchema7PrimitiveLiteralType, isStandardJsonSchema };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { U as JsonSerializeOptions, W as JsonValue, d as JsonParserResult, l as JsonParseOptions, t as Class } from "./types-CPQlxauZ.mjs";
|
|
2
|
+
import SuperJSON from "superjson";
|
|
3
|
+
|
|
4
|
+
//#region src/storm-json.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A static JSON parser class used by Storm Software to serialize and deserialize JSON data
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This class uses the [SuperJSON](https://github.com/blitz-js/superjson) library under the hood.
|
|
11
|
+
*/
|
|
12
|
+
declare class StormJSON extends SuperJSON {
|
|
13
|
+
#private;
|
|
14
|
+
static get instance(): StormJSON;
|
|
15
|
+
/**
|
|
16
|
+
* Deserialize the given value with superjson using the given metadata
|
|
17
|
+
*/
|
|
18
|
+
static deserialize<TData = unknown>(payload: JsonParserResult): TData;
|
|
19
|
+
/**
|
|
20
|
+
* Serialize the given value with superjson
|
|
21
|
+
*/
|
|
22
|
+
static serialize(object: JsonValue): JsonParserResult;
|
|
23
|
+
/**
|
|
24
|
+
* Parse the given string value with superjson using the given metadata
|
|
25
|
+
*
|
|
26
|
+
* @param value - The string value to parse
|
|
27
|
+
* @returns The parsed data
|
|
28
|
+
*/
|
|
29
|
+
static parse<TData = unknown>(value: string): TData;
|
|
30
|
+
/**
|
|
31
|
+
* Serializes the given data to a JSON string.
|
|
32
|
+
* By default the JSON string is formatted with a 2 space indentation to be easy readable.
|
|
33
|
+
*
|
|
34
|
+
* @param value - Object which should be serialized to JSON
|
|
35
|
+
* @param options - JSON serialize options
|
|
36
|
+
* @returns the formatted JSON representation of the object
|
|
37
|
+
*/
|
|
38
|
+
static stringify<T>(value: T, options?: JsonSerializeOptions): string;
|
|
39
|
+
/**
|
|
40
|
+
* Parses the given JSON string and returns the object the JSON content represents.
|
|
41
|
+
* By default javascript-style comments and trailing commas are allowed.
|
|
42
|
+
*
|
|
43
|
+
* @param strData - JSON content as string
|
|
44
|
+
* @param options - JSON parse options
|
|
45
|
+
* @returns Object the JSON content represents
|
|
46
|
+
*/
|
|
47
|
+
static parseJson<TData = unknown>(strData: string, options?: JsonParseOptions): TData;
|
|
48
|
+
/**
|
|
49
|
+
* Register a custom schema with superjson
|
|
50
|
+
*
|
|
51
|
+
* @param name - The name of the schema
|
|
52
|
+
* @param serialize - The function to serialize the schema
|
|
53
|
+
* @param deserialize - The function to deserialize the schema
|
|
54
|
+
* @param isApplicable - The function to check if the schema is applicable
|
|
55
|
+
*/
|
|
56
|
+
static register<TData = any, TJsonObject extends JsonValue = JsonValue>(name: string, serialize: (data: TData) => TJsonObject, deserialize: (json: TJsonObject) => TData, isApplicable: (data: any) => data is TData): void;
|
|
57
|
+
/**
|
|
58
|
+
* Register a class with superjson
|
|
59
|
+
*
|
|
60
|
+
* @param classConstructor - The class constructor to register
|
|
61
|
+
*/
|
|
62
|
+
static registerClass(classConstructor: Class, options?: {
|
|
63
|
+
identifier?: string;
|
|
64
|
+
allowProps?: string[];
|
|
65
|
+
} | string): void;
|
|
66
|
+
private constructor();
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { StormJSON as t };
|
|
70
|
+
//# sourceMappingURL=storm-json-8F9CKpXu.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storm-json-8F9CKpXu.d.mts","names":[],"sources":["../src/storm-json.ts"],"sourcesContent":[],"mappings":";;;;;;;AA0CA;;;;AAuB2C,cAvB9B,SAAA,SAAkB,SAAA,CAuBY;EAAY,CAAA,OAAA;EAUS,WAAA,QAAA,CAAA,CAAA,EA9BhC,SA8BgC;EAarD;;;EAyBN,OAAA,WAAA,CAAA,QAAA,OAAA,CAAA,CAAA,OAAA,EAxDQ,gBAwDR,CAAA,EAvDA,KAuDA;EAiCmB;;;EAGQ,OAAA,SAAA,CAAA,MAAA,EApFW,SAoFX,CAAA,EApFuB,gBAoFvB;EACR;;;;;;gDA3EwC;;;;;;;;;6BAarD,aACG;;;;;;;;;+DAuBA,mBACT;;;;;;;;;mDAiCmB,YAAY,2CAGd,UAAU,iCACR,gBAAgB,4CACC;;;;;;yCAkBnB"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
const require_is_object = require('./is-object-umGh91v1.cjs');
|
|
29
|
+
const require_is_string = require('./is-string-C2RK4Gjs.cjs');
|
|
30
|
+
const require_parse = require('./parse-ByDxRup5.cjs');
|
|
31
|
+
const require_parse_error = require('./parse-error-N7UE-HMh.cjs');
|
|
32
|
+
const require_stringify = require('./stringify-BehjrfhS.cjs');
|
|
33
|
+
let jsonc_parser = require("jsonc-parser");
|
|
34
|
+
let node_buffer = require("node:buffer");
|
|
35
|
+
let superjson = require("superjson");
|
|
36
|
+
superjson = __toESM(superjson);
|
|
37
|
+
|
|
38
|
+
//#region src/storm-json.ts
|
|
39
|
+
/**
|
|
40
|
+
* A static JSON parser class used by Storm Software to serialize and deserialize JSON data
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* This class uses the [SuperJSON](https://github.com/blitz-js/superjson) library under the hood.
|
|
44
|
+
*/
|
|
45
|
+
var StormJSON = class StormJSON extends superjson.default {
|
|
46
|
+
static #instance;
|
|
47
|
+
static get instance() {
|
|
48
|
+
if (!StormJSON.#instance) StormJSON.#instance = new StormJSON();
|
|
49
|
+
return StormJSON.#instance;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Deserialize the given value with superjson using the given metadata
|
|
53
|
+
*/
|
|
54
|
+
static deserialize(payload) {
|
|
55
|
+
return StormJSON.instance.deserialize(payload);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Serialize the given value with superjson
|
|
59
|
+
*/
|
|
60
|
+
static serialize(object) {
|
|
61
|
+
return StormJSON.instance.serialize(object);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Parse the given string value with superjson using the given metadata
|
|
65
|
+
*
|
|
66
|
+
* @param value - The string value to parse
|
|
67
|
+
* @returns The parsed data
|
|
68
|
+
*/
|
|
69
|
+
static parse(value) {
|
|
70
|
+
return require_parse.parse(value);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Serializes the given data to a JSON string.
|
|
74
|
+
* By default the JSON string is formatted with a 2 space indentation to be easy readable.
|
|
75
|
+
*
|
|
76
|
+
* @param value - Object which should be serialized to JSON
|
|
77
|
+
* @param options - JSON serialize options
|
|
78
|
+
* @returns the formatted JSON representation of the object
|
|
79
|
+
*/
|
|
80
|
+
static stringify(value, options) {
|
|
81
|
+
const customTransformer = StormJSON.instance.customTransformerRegistry.findApplicable(value);
|
|
82
|
+
let result = value;
|
|
83
|
+
if (customTransformer && customTransformer.isApplicable(value)) result = customTransformer.serialize(result);
|
|
84
|
+
return require_stringify.stringify(result, options?.spaces ?? 2);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Parses the given JSON string and returns the object the JSON content represents.
|
|
88
|
+
* By default javascript-style comments and trailing commas are allowed.
|
|
89
|
+
*
|
|
90
|
+
* @param strData - JSON content as string
|
|
91
|
+
* @param options - JSON parse options
|
|
92
|
+
* @returns Object the JSON content represents
|
|
93
|
+
*/
|
|
94
|
+
static parseJson(strData, options) {
|
|
95
|
+
try {
|
|
96
|
+
if (options?.expectComments === false) return StormJSON.instance.parse(strData);
|
|
97
|
+
} catch {}
|
|
98
|
+
const errors = [];
|
|
99
|
+
const result = (0, jsonc_parser.parse)(strData, errors, {
|
|
100
|
+
allowTrailingComma: true,
|
|
101
|
+
...options
|
|
102
|
+
});
|
|
103
|
+
if (errors.length > 0 && errors[0]) throw new Error(require_parse_error.formatParseError(strData, errors[0]));
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Register a custom schema with superjson
|
|
108
|
+
*
|
|
109
|
+
* @param name - The name of the schema
|
|
110
|
+
* @param serialize - The function to serialize the schema
|
|
111
|
+
* @param deserialize - The function to deserialize the schema
|
|
112
|
+
* @param isApplicable - The function to check if the schema is applicable
|
|
113
|
+
*/
|
|
114
|
+
static register(name, serialize, deserialize, isApplicable) {
|
|
115
|
+
StormJSON.instance.registerCustom({
|
|
116
|
+
isApplicable,
|
|
117
|
+
serialize,
|
|
118
|
+
deserialize
|
|
119
|
+
}, name);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Register a class with superjson
|
|
123
|
+
*
|
|
124
|
+
* @param classConstructor - The class constructor to register
|
|
125
|
+
*/
|
|
126
|
+
static registerClass(classConstructor, options) {
|
|
127
|
+
StormJSON.instance.registerClass(classConstructor, {
|
|
128
|
+
identifier: require_is_string.isString(options) ? options : options?.identifier || classConstructor.name,
|
|
129
|
+
allowProps: options && require_is_object.isObject(options) && options?.allowProps && Array.isArray(options.allowProps) ? options.allowProps : ["__typename"]
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
constructor() {
|
|
133
|
+
super({ dedupe: true });
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
StormJSON.instance.registerCustom({
|
|
137
|
+
isApplicable: (v) => typeof node_buffer.Buffer.isBuffer === "function" && node_buffer.Buffer.isBuffer(v),
|
|
138
|
+
serialize: (v) => v.toString("base64"),
|
|
139
|
+
deserialize: (v) => node_buffer.Buffer.from(v, "base64")
|
|
140
|
+
}, "Bytes");
|
|
141
|
+
|
|
142
|
+
//#endregion
|
|
143
|
+
Object.defineProperty(exports, 'StormJSON', {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
get: function () {
|
|
146
|
+
return StormJSON;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
Object.defineProperty(exports, '__toESM', {
|
|
150
|
+
enumerable: true,
|
|
151
|
+
get: function () {
|
|
152
|
+
return __toESM;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { U as JsonSerializeOptions, W as JsonValue, d as JsonParserResult, l as JsonParseOptions, t as Class } from "./types-Bn8rC098.cjs";
|
|
2
|
+
import SuperJSON from "superjson";
|
|
3
|
+
|
|
4
|
+
//#region src/storm-json.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A static JSON parser class used by Storm Software to serialize and deserialize JSON data
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This class uses the [SuperJSON](https://github.com/blitz-js/superjson) library under the hood.
|
|
11
|
+
*/
|
|
12
|
+
declare class StormJSON extends SuperJSON {
|
|
13
|
+
#private;
|
|
14
|
+
static get instance(): StormJSON;
|
|
15
|
+
/**
|
|
16
|
+
* Deserialize the given value with superjson using the given metadata
|
|
17
|
+
*/
|
|
18
|
+
static deserialize<TData = unknown>(payload: JsonParserResult): TData;
|
|
19
|
+
/**
|
|
20
|
+
* Serialize the given value with superjson
|
|
21
|
+
*/
|
|
22
|
+
static serialize(object: JsonValue): JsonParserResult;
|
|
23
|
+
/**
|
|
24
|
+
* Parse the given string value with superjson using the given metadata
|
|
25
|
+
*
|
|
26
|
+
* @param value - The string value to parse
|
|
27
|
+
* @returns The parsed data
|
|
28
|
+
*/
|
|
29
|
+
static parse<TData = unknown>(value: string): TData;
|
|
30
|
+
/**
|
|
31
|
+
* Serializes the given data to a JSON string.
|
|
32
|
+
* By default the JSON string is formatted with a 2 space indentation to be easy readable.
|
|
33
|
+
*
|
|
34
|
+
* @param value - Object which should be serialized to JSON
|
|
35
|
+
* @param options - JSON serialize options
|
|
36
|
+
* @returns the formatted JSON representation of the object
|
|
37
|
+
*/
|
|
38
|
+
static stringify<T>(value: T, options?: JsonSerializeOptions): string;
|
|
39
|
+
/**
|
|
40
|
+
* Parses the given JSON string and returns the object the JSON content represents.
|
|
41
|
+
* By default javascript-style comments and trailing commas are allowed.
|
|
42
|
+
*
|
|
43
|
+
* @param strData - JSON content as string
|
|
44
|
+
* @param options - JSON parse options
|
|
45
|
+
* @returns Object the JSON content represents
|
|
46
|
+
*/
|
|
47
|
+
static parseJson<TData = unknown>(strData: string, options?: JsonParseOptions): TData;
|
|
48
|
+
/**
|
|
49
|
+
* Register a custom schema with superjson
|
|
50
|
+
*
|
|
51
|
+
* @param name - The name of the schema
|
|
52
|
+
* @param serialize - The function to serialize the schema
|
|
53
|
+
* @param deserialize - The function to deserialize the schema
|
|
54
|
+
* @param isApplicable - The function to check if the schema is applicable
|
|
55
|
+
*/
|
|
56
|
+
static register<TData = any, TJsonObject extends JsonValue = JsonValue>(name: string, serialize: (data: TData) => TJsonObject, deserialize: (json: TJsonObject) => TData, isApplicable: (data: any) => data is TData): void;
|
|
57
|
+
/**
|
|
58
|
+
* Register a class with superjson
|
|
59
|
+
*
|
|
60
|
+
* @param classConstructor - The class constructor to register
|
|
61
|
+
*/
|
|
62
|
+
static registerClass(classConstructor: Class, options?: {
|
|
63
|
+
identifier?: string;
|
|
64
|
+
allowProps?: string[];
|
|
65
|
+
} | string): void;
|
|
66
|
+
private constructor();
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { StormJSON as t };
|
|
70
|
+
//# sourceMappingURL=storm-json-DvIEWMEH.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storm-json-DvIEWMEH.d.cts","names":[],"sources":["../src/storm-json.ts"],"sourcesContent":[],"mappings":";;;;;;;AA0CA;;;;AAuB2C,cAvB9B,SAAA,SAAkB,SAAA,CAuBY;EAAY,CAAA,OAAA;EAUS,WAAA,QAAA,CAAA,CAAA,EA9BhC,SA8BgC;EAarD;;;EAyBN,OAAA,WAAA,CAAA,QAAA,OAAA,CAAA,CAAA,OAAA,EAxDQ,gBAwDR,CAAA,EAvDA,KAuDA;EAiCmB;;;EAGQ,OAAA,SAAA,CAAA,MAAA,EApFW,SAoFX,CAAA,EApFuB,gBAoFvB;EACR;;;;;;gDA3EwC;;;;;;;;;6BAarD,aACG;;;;;;;;;+DAuBA,mBACT;;;;;;;;;mDAiCmB,YAAY,2CAGd,UAAU,iCACR,gBAAgB,4CACC;;;;;;yCAkBnB"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { t as isObject } from "./is-object-BpfmzHWa.mjs";
|
|
2
|
+
import { t as isString } from "./is-string-CLiBUSKV.mjs";
|
|
3
|
+
import { t as parse$1 } from "./parse-Dn43ZK9y.mjs";
|
|
4
|
+
import { t as formatParseError } from "./parse-error-Af4zHUQ_.mjs";
|
|
5
|
+
import { n as stringify } from "./stringify-CYHjAvWm.mjs";
|
|
6
|
+
import { parse } from "jsonc-parser";
|
|
7
|
+
import { Buffer } from "node:buffer";
|
|
8
|
+
import SuperJSON from "superjson";
|
|
9
|
+
|
|
10
|
+
//#region src/storm-json.ts
|
|
11
|
+
/**
|
|
12
|
+
* A static JSON parser class used by Storm Software to serialize and deserialize JSON data
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* This class uses the [SuperJSON](https://github.com/blitz-js/superjson) library under the hood.
|
|
16
|
+
*/
|
|
17
|
+
var StormJSON = class StormJSON extends SuperJSON {
|
|
18
|
+
static #instance;
|
|
19
|
+
static get instance() {
|
|
20
|
+
if (!StormJSON.#instance) StormJSON.#instance = new StormJSON();
|
|
21
|
+
return StormJSON.#instance;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Deserialize the given value with superjson using the given metadata
|
|
25
|
+
*/
|
|
26
|
+
static deserialize(payload) {
|
|
27
|
+
return StormJSON.instance.deserialize(payload);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Serialize the given value with superjson
|
|
31
|
+
*/
|
|
32
|
+
static serialize(object) {
|
|
33
|
+
return StormJSON.instance.serialize(object);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Parse the given string value with superjson using the given metadata
|
|
37
|
+
*
|
|
38
|
+
* @param value - The string value to parse
|
|
39
|
+
* @returns The parsed data
|
|
40
|
+
*/
|
|
41
|
+
static parse(value) {
|
|
42
|
+
return parse$1(value);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Serializes the given data to a JSON string.
|
|
46
|
+
* By default the JSON string is formatted with a 2 space indentation to be easy readable.
|
|
47
|
+
*
|
|
48
|
+
* @param value - Object which should be serialized to JSON
|
|
49
|
+
* @param options - JSON serialize options
|
|
50
|
+
* @returns the formatted JSON representation of the object
|
|
51
|
+
*/
|
|
52
|
+
static stringify(value, options) {
|
|
53
|
+
const customTransformer = StormJSON.instance.customTransformerRegistry.findApplicable(value);
|
|
54
|
+
let result = value;
|
|
55
|
+
if (customTransformer && customTransformer.isApplicable(value)) result = customTransformer.serialize(result);
|
|
56
|
+
return stringify(result, options?.spaces ?? 2);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Parses the given JSON string and returns the object the JSON content represents.
|
|
60
|
+
* By default javascript-style comments and trailing commas are allowed.
|
|
61
|
+
*
|
|
62
|
+
* @param strData - JSON content as string
|
|
63
|
+
* @param options - JSON parse options
|
|
64
|
+
* @returns Object the JSON content represents
|
|
65
|
+
*/
|
|
66
|
+
static parseJson(strData, options) {
|
|
67
|
+
try {
|
|
68
|
+
if (options?.expectComments === false) return StormJSON.instance.parse(strData);
|
|
69
|
+
} catch {}
|
|
70
|
+
const errors = [];
|
|
71
|
+
const result = parse(strData, errors, {
|
|
72
|
+
allowTrailingComma: true,
|
|
73
|
+
...options
|
|
74
|
+
});
|
|
75
|
+
if (errors.length > 0 && errors[0]) throw new Error(formatParseError(strData, errors[0]));
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Register a custom schema with superjson
|
|
80
|
+
*
|
|
81
|
+
* @param name - The name of the schema
|
|
82
|
+
* @param serialize - The function to serialize the schema
|
|
83
|
+
* @param deserialize - The function to deserialize the schema
|
|
84
|
+
* @param isApplicable - The function to check if the schema is applicable
|
|
85
|
+
*/
|
|
86
|
+
static register(name, serialize, deserialize, isApplicable) {
|
|
87
|
+
StormJSON.instance.registerCustom({
|
|
88
|
+
isApplicable,
|
|
89
|
+
serialize,
|
|
90
|
+
deserialize
|
|
91
|
+
}, name);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Register a class with superjson
|
|
95
|
+
*
|
|
96
|
+
* @param classConstructor - The class constructor to register
|
|
97
|
+
*/
|
|
98
|
+
static registerClass(classConstructor, options) {
|
|
99
|
+
StormJSON.instance.registerClass(classConstructor, {
|
|
100
|
+
identifier: isString(options) ? options : options?.identifier || classConstructor.name,
|
|
101
|
+
allowProps: options && isObject(options) && options?.allowProps && Array.isArray(options.allowProps) ? options.allowProps : ["__typename"]
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
constructor() {
|
|
105
|
+
super({ dedupe: true });
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
StormJSON.instance.registerCustom({
|
|
109
|
+
isApplicable: (v) => typeof Buffer.isBuffer === "function" && Buffer.isBuffer(v),
|
|
110
|
+
serialize: (v) => v.toString("base64"),
|
|
111
|
+
deserialize: (v) => Buffer.from(v, "base64")
|
|
112
|
+
}, "Bytes");
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
export { StormJSON as t };
|
|
116
|
+
//# sourceMappingURL=storm-json-nkhJgTz4.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storm-json-nkhJgTz4.mjs","names":["#instance","parseValue","stringifyValue","errors: ParseError[]"],"sources":["../src/storm-json.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { ParseError } from \"jsonc-parser\";\nimport type {\n Class,\n JsonParseOptions,\n JsonParserResult,\n JsonSerializeOptions,\n JsonValue\n} from \"./types\";\n// import { Decimal } from \"decimal.js\";\nimport { isObject } from \"@stryke/type-checks/is-object\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { parse } from \"jsonc-parser\";\nimport { Buffer } from \"node:buffer\";\nimport SuperJSON from \"superjson\";\nimport { parse as parseValue } from \"./utils/parse\";\nimport { formatParseError } from \"./utils/parse-error\";\nimport { stringify as stringifyValue } from \"./utils/stringify\";\n\n/**\n * A static JSON parser class used by Storm Software to serialize and deserialize JSON data\n *\n * @remarks\n * This class uses the [SuperJSON](https://github.com/blitz-js/superjson) library under the hood.\n */\nexport class StormJSON extends SuperJSON {\n static #instance: StormJSON;\n\n public static get instance(): StormJSON {\n if (!StormJSON.#instance) {\n StormJSON.#instance = new StormJSON();\n }\n\n return StormJSON.#instance;\n }\n\n /**\n * Deserialize the given value with superjson using the given metadata\n */\n public static override deserialize<TData = unknown>(\n payload: JsonParserResult\n ): TData {\n return StormJSON.instance.deserialize(payload);\n }\n\n /**\n * Serialize the given value with superjson\n */\n public static override serialize(object: JsonValue): JsonParserResult {\n return StormJSON.instance.serialize(object);\n }\n\n /**\n * Parse the given string value with superjson using the given metadata\n *\n * @param value - The string value to parse\n * @returns The parsed data\n */\n public static override parse<TData = unknown>(value: string): TData {\n return parseValue(value);\n }\n\n /**\n * Serializes the given data to a JSON string.\n * By default the JSON string is formatted with a 2 space indentation to be easy readable.\n *\n * @param value - Object which should be serialized to JSON\n * @param options - JSON serialize options\n * @returns the formatted JSON representation of the object\n */\n public static override stringify<T>(\n value: T,\n options?: JsonSerializeOptions\n ): string {\n const customTransformer =\n StormJSON.instance.customTransformerRegistry.findApplicable(value);\n\n let result = value;\n if (customTransformer && customTransformer.isApplicable(value)) {\n result = customTransformer.serialize(result) as T;\n }\n\n return stringifyValue(result, options?.spaces ?? 2);\n }\n\n /**\n * Parses the given JSON string and returns the object the JSON content represents.\n * By default javascript-style comments and trailing commas are allowed.\n *\n * @param strData - JSON content as string\n * @param options - JSON parse options\n * @returns Object the JSON content represents\n */\n public static parseJson<TData = unknown>(\n strData: string,\n options?: JsonParseOptions\n ): TData {\n try {\n if (options?.expectComments === false) {\n return StormJSON.instance.parse(strData);\n }\n } catch {\n // Do nothing\n }\n\n const errors: ParseError[] = [];\n const opts = {\n allowTrailingComma: true,\n ...options\n };\n const result = parse(strData, errors, opts) as TData;\n\n if (errors.length > 0 && errors[0]) {\n throw new Error(formatParseError(strData, errors[0]));\n }\n\n return result;\n }\n\n /**\n * Register a custom schema with superjson\n *\n * @param name - The name of the schema\n * @param serialize - The function to serialize the schema\n * @param deserialize - The function to deserialize the schema\n * @param isApplicable - The function to check if the schema is applicable\n */\n public static register<\n TData = any,\n TJsonObject extends JsonValue = JsonValue\n >(\n name: string,\n serialize: (data: TData) => TJsonObject,\n deserialize: (json: TJsonObject) => TData,\n isApplicable: (data: any) => data is TData\n ) {\n StormJSON.instance.registerCustom<TData, TJsonObject>(\n {\n isApplicable,\n serialize,\n deserialize\n },\n name\n );\n }\n\n /**\n * Register a class with superjson\n *\n * @param classConstructor - The class constructor to register\n */\n public static override registerClass(\n classConstructor: Class,\n options?: { identifier?: string; allowProps?: string[] } | string\n ) {\n StormJSON.instance.registerClass(classConstructor, {\n identifier: isString(options)\n ? options\n : options?.identifier || classConstructor.name,\n allowProps:\n options &&\n isObject(options) &&\n options?.allowProps &&\n Array.isArray(options.allowProps)\n ? options.allowProps\n : [\"__typename\"]\n });\n }\n\n private constructor() {\n super({ dedupe: true });\n }\n}\n\nStormJSON.instance.registerCustom<Buffer, string>(\n {\n isApplicable: (v): v is Buffer =>\n typeof Buffer.isBuffer === \"function\" && Buffer.isBuffer(v),\n serialize: v => v.toString(\"base64\"),\n deserialize: v => Buffer.from(v, \"base64\")\n },\n \"Bytes\"\n);\n"],"mappings":";;;;;;;;;;;;;;;;AA0CA,IAAa,YAAb,MAAa,kBAAkB,UAAU;CACvC,QAAOA;CAEP,WAAkB,WAAsB;AACtC,MAAI,CAAC,WAAUA,SACb,YAAUA,WAAY,IAAI,WAAW;AAGvC,SAAO,WAAUA;;;;;CAMnB,OAAuB,YACrB,SACO;AACP,SAAO,UAAU,SAAS,YAAY,QAAQ;;;;;CAMhD,OAAuB,UAAU,QAAqC;AACpE,SAAO,UAAU,SAAS,UAAU,OAAO;;;;;;;;CAS7C,OAAuB,MAAuB,OAAsB;AAClE,SAAOC,QAAW,MAAM;;;;;;;;;;CAW1B,OAAuB,UACrB,OACA,SACQ;EACR,MAAM,oBACJ,UAAU,SAAS,0BAA0B,eAAe,MAAM;EAEpE,IAAI,SAAS;AACb,MAAI,qBAAqB,kBAAkB,aAAa,MAAM,CAC5D,UAAS,kBAAkB,UAAU,OAAO;AAG9C,SAAOC,UAAe,QAAQ,SAAS,UAAU,EAAE;;;;;;;;;;CAWrD,OAAc,UACZ,SACA,SACO;AACP,MAAI;AACF,OAAI,SAAS,mBAAmB,MAC9B,QAAO,UAAU,SAAS,MAAM,QAAQ;UAEpC;EAIR,MAAMC,SAAuB,EAAE;EAK/B,MAAM,SAAS,MAAM,SAAS,QAJjB;GACX,oBAAoB;GACpB,GAAG;GACJ,CAC0C;AAE3C,MAAI,OAAO,SAAS,KAAK,OAAO,GAC9B,OAAM,IAAI,MAAM,iBAAiB,SAAS,OAAO,GAAG,CAAC;AAGvD,SAAO;;;;;;;;;;CAWT,OAAc,SAIZ,MACA,WACA,aACA,cACA;AACA,YAAU,SAAS,eACjB;GACE;GACA;GACA;GACD,EACD,KACD;;;;;;;CAQH,OAAuB,cACrB,kBACA,SACA;AACA,YAAU,SAAS,cAAc,kBAAkB;GACjD,YAAY,SAAS,QAAQ,GACzB,UACA,SAAS,cAAc,iBAAiB;GAC5C,YACE,WACA,SAAS,QAAQ,IACjB,SAAS,cACT,MAAM,QAAQ,QAAQ,WAAW,GAC7B,QAAQ,aACR,CAAC,aAAa;GACrB,CAAC;;CAGJ,AAAQ,cAAc;AACpB,QAAM,EAAE,QAAQ,MAAM,CAAC;;;AAI3B,UAAU,SAAS,eACjB;CACE,eAAe,MACb,OAAO,OAAO,aAAa,cAAc,OAAO,SAAS,EAAE;CAC7D,YAAW,MAAK,EAAE,SAAS,SAAS;CACpC,cAAa,MAAK,OAAO,KAAK,GAAG,SAAS;CAC3C,EACD,QACD"}
|