@procedures/json 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +104 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/diff.d.ts +18 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +66 -0
- package/dist/diff.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/merge.d.ts +14 -0
- package/dist/merge.d.ts.map +1 -0
- package/dist/merge.js +34 -0
- package/dist/merge.js.map +1 -0
- package/dist/module.d.ts +21 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +192 -0
- package/dist/module.js.map +1 -0
- package/dist/patch.d.ts +23 -0
- package/dist/patch.d.ts.map +1 -0
- package/dist/patch.js +137 -0
- package/dist/patch.js.map +1 -0
- package/dist/path.d.ts +38 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +157 -0
- package/dist/path.js.map +1 -0
- package/dist/pointer.d.ts +22 -0
- package/dist/pointer.d.ts.map +1 -0
- package/dist/pointer.js +70 -0
- package/dist/pointer.js.map +1 -0
- package/dist/procedures/json/diff.d.ts +12 -0
- package/dist/procedures/json/diff.d.ts.map +1 -0
- package/dist/procedures/json/diff.js +17 -0
- package/dist/procedures/json/diff.js.map +1 -0
- package/dist/procedures/json/index.d.ts +6 -0
- package/dist/procedures/json/index.d.ts.map +1 -0
- package/dist/procedures/json/index.js +6 -0
- package/dist/procedures/json/index.js.map +1 -0
- package/dist/procedures/json/merge.d.ts +12 -0
- package/dist/procedures/json/merge.d.ts.map +1 -0
- package/dist/procedures/json/merge.js +17 -0
- package/dist/procedures/json/merge.js.map +1 -0
- package/dist/procedures/json/patch.d.ts +12 -0
- package/dist/procedures/json/patch.d.ts.map +1 -0
- package/dist/procedures/json/patch.js +20 -0
- package/dist/procedures/json/patch.js.map +1 -0
- package/dist/procedures/json/query.d.ts +12 -0
- package/dist/procedures/json/query.d.ts.map +1 -0
- package/dist/procedures/json/query.js +28 -0
- package/dist/procedures/json/query.js.map +1 -0
- package/dist/procedures/json/validate.d.ts +12 -0
- package/dist/procedures/json/validate.d.ts.map +1 -0
- package/dist/procedures/json/validate.js +18 -0
- package/dist/procedures/json/validate.js.map +1 -0
- package/dist/procedures/yaml/index.d.ts +3 -0
- package/dist/procedures/yaml/index.d.ts.map +1 -0
- package/dist/procedures/yaml/index.js +3 -0
- package/dist/procedures/yaml/index.js.map +1 -0
- package/dist/procedures/yaml/parse.d.ts +12 -0
- package/dist/procedures/yaml/parse.d.ts.map +1 -0
- package/dist/procedures/yaml/parse.js +14 -0
- package/dist/procedures/yaml/parse.js.map +1 -0
- package/dist/procedures/yaml/stringify.d.ts +11 -0
- package/dist/procedures/yaml/stringify.d.ts.map +1 -0
- package/dist/procedures/yaml/stringify.js +15 -0
- package/dist/procedures/yaml/stringify.js.map +1 -0
- package/dist/register.d.ts +6 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +8 -0
- package/dist/register.js.map +1 -0
- package/dist/schema.d.ts +38 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +92 -0
- package/dist/schema.js.map +1 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/value.d.ts +61 -0
- package/dist/value.d.ts.map +1 -0
- package/dist/value.js +124 -0
- package/dist/value.js.map +1 -0
- package/dist/yaml.d.ts +35 -0
- package/dist/yaml.d.ts.map +1 -0
- package/dist/yaml.js +111 -0
- package/dist/yaml.js.map +1 -0
- package/package.json +81 -3
- package/src/diff.ts +58 -0
- package/src/index.ts +14 -0
- package/src/merge.ts +34 -0
- package/src/module.ts +236 -0
- package/src/patch.ts +132 -0
- package/src/path.ts +155 -0
- package/src/pointer.ts +70 -0
- package/src/procedures/json/diff.ts +19 -0
- package/src/procedures/json/index.ts +5 -0
- package/src/procedures/json/merge.ts +19 -0
- package/src/procedures/json/patch.ts +21 -0
- package/src/procedures/json/query.ts +29 -0
- package/src/procedures/json/validate.ts +20 -0
- package/src/procedures/yaml/index.ts +2 -0
- package/src/procedures/yaml/parse.ts +16 -0
- package/src/procedures/yaml/stringify.ts +17 -0
- package/src/register.ts +10 -0
- package/src/schema.ts +104 -0
- package/src/types.ts +127 -0
- package/src/value.ts +143 -0
- package/src/yaml.ts +128 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* yaml.stringify procedure
|
|
3
|
+
*
|
|
4
|
+
* Write a JSON value as YAML text. `yaml.parse` of the text gives a value equal to the input.
|
|
5
|
+
*/
|
|
6
|
+
import { assertJson } from "../../value.js";
|
|
7
|
+
import { stringifyYaml } from "../../yaml.js";
|
|
8
|
+
/**
|
|
9
|
+
* Write a JSON value as YAML text
|
|
10
|
+
*/
|
|
11
|
+
export async function yamlStringify(input) {
|
|
12
|
+
assertJson(input.value, "yaml.stringify: value");
|
|
13
|
+
return { text: stringifyYaml(input.value, { indent: input.indent, lineWidth: input.lineWidth, sortKeys: input.sortKeys }) };
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=stringify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringify.js","sourceRoot":"","sources":["../../../src/procedures/yaml/stringify.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG9C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,KAAyB;IAC3D,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,uBAAuB,CAAC,CAAC;IACjD,OAAO,EAAE,IAAI,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;AAC9H,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,cAAc,aAAa,CAAC"}
|
package/dist/register.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing this file registers the procedures of @procedures/json in the global registry:
|
|
3
|
+
* `import "@procedures/json/register"`. The package root registers nothing.
|
|
4
|
+
*/
|
|
5
|
+
import { registerJsonProcedures } from "./module.js";
|
|
6
|
+
export * from "./module.js";
|
|
7
|
+
registerJsonProcedures();
|
|
8
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,cAAc,aAAa,CAAC;AAE5B,sBAAsB,EAAE,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The check of a JSON value against a JSON Schema (`json.validate`).
|
|
3
|
+
*
|
|
4
|
+
* The check uses the validator of `@procedures/compiler` (`checkShape`), the validator that
|
|
5
|
+
* `program.check` uses for the inputs of a program. It is a subset of JSON Schema:
|
|
6
|
+
*
|
|
7
|
+
* - Examined: `type`, `enum`, `const`, `$ref` to the same schema (`#/...`), `allOf`, `anyOf`,
|
|
8
|
+
* `oneOf` (as `anyOf`), `properties`, `required`, `additionalProperties`, `patternProperties`,
|
|
9
|
+
* `items`, `prefixItems`, `additionalItems`, `minItems`, `maxItems`, `minLength`, `maxLength`,
|
|
10
|
+
* `pattern`, `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum` and `multipleOf`.
|
|
11
|
+
* - Annotations without a check, as the standard tells: `format`, `title`, `description`,
|
|
12
|
+
* `default`, `examples` and the other annotations.
|
|
13
|
+
* - Not examined: `not`, `if`, `then`, `else`, `uniqueItems`, `contains`, `minProperties`,
|
|
14
|
+
* `maxProperties`, `propertyNames`, `dependentRequired`, `dependentSchemas`, `unevaluated*`, a
|
|
15
|
+
* `$ref` to another document, and the others of `NOT_EXAMINED`. The output lists them in
|
|
16
|
+
* `unchecked`, so a caller knows that the verdict is not complete.
|
|
17
|
+
*
|
|
18
|
+
* `minLength` and `maxLength` count UTF-16 code units, not code points.
|
|
19
|
+
*/
|
|
20
|
+
import { type JsonValue } from "./value.js";
|
|
21
|
+
/** One problem of a value. */
|
|
22
|
+
export interface ValidationIssue {
|
|
23
|
+
/** The JSON Pointer of the part of the value. */
|
|
24
|
+
readonly pointer: string;
|
|
25
|
+
readonly message: string;
|
|
26
|
+
}
|
|
27
|
+
/** The verdict of a check. */
|
|
28
|
+
export interface ValidationResult {
|
|
29
|
+
readonly valid: boolean;
|
|
30
|
+
readonly errors: readonly ValidationIssue[];
|
|
31
|
+
/** The keywords of the schema that the check does not examine, or examines only in part. */
|
|
32
|
+
readonly unchecked: readonly string[];
|
|
33
|
+
}
|
|
34
|
+
/** The assertion keywords of JSON Schema that the subset does not examine. */
|
|
35
|
+
export declare const NOT_EXAMINED: readonly string[];
|
|
36
|
+
/** This function examines a JSON value against a JSON Schema. A schema that is not an object or a boolean throws. */
|
|
37
|
+
export declare function validateJson(value: JsonValue, schema: unknown): ValidationResult;
|
|
38
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAA4B,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAEtE,8BAA8B;AAC9B,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,8BAA8B;AAC9B,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;IAC5C,4FAA4F;IAC5F,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC;AAED,8EAA8E;AAC9E,eAAO,MAAM,YAAY,EAAE,SAAS,MAAM,EAoBzC,CAAC;AAoCF,qHAAqH;AACrH,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAOhF"}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The check of a JSON value against a JSON Schema (`json.validate`).
|
|
3
|
+
*
|
|
4
|
+
* The check uses the validator of `@procedures/compiler` (`checkShape`), the validator that
|
|
5
|
+
* `program.check` uses for the inputs of a program. It is a subset of JSON Schema:
|
|
6
|
+
*
|
|
7
|
+
* - Examined: `type`, `enum`, `const`, `$ref` to the same schema (`#/...`), `allOf`, `anyOf`,
|
|
8
|
+
* `oneOf` (as `anyOf`), `properties`, `required`, `additionalProperties`, `patternProperties`,
|
|
9
|
+
* `items`, `prefixItems`, `additionalItems`, `minItems`, `maxItems`, `minLength`, `maxLength`,
|
|
10
|
+
* `pattern`, `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum` and `multipleOf`.
|
|
11
|
+
* - Annotations without a check, as the standard tells: `format`, `title`, `description`,
|
|
12
|
+
* `default`, `examples` and the other annotations.
|
|
13
|
+
* - Not examined: `not`, `if`, `then`, `else`, `uniqueItems`, `contains`, `minProperties`,
|
|
14
|
+
* `maxProperties`, `propertyNames`, `dependentRequired`, `dependentSchemas`, `unevaluated*`, a
|
|
15
|
+
* `$ref` to another document, and the others of `NOT_EXAMINED`. The output lists them in
|
|
16
|
+
* `unchecked`, so a caller knows that the verdict is not complete.
|
|
17
|
+
*
|
|
18
|
+
* `minLength` and `maxLength` count UTF-16 code units, not code points.
|
|
19
|
+
*/
|
|
20
|
+
import { checkShape } from "@procedures/compiler";
|
|
21
|
+
import { isPlainObject, JsonError } from "./value.js";
|
|
22
|
+
/** The assertion keywords of JSON Schema that the subset does not examine. */
|
|
23
|
+
export const NOT_EXAMINED = [
|
|
24
|
+
"not",
|
|
25
|
+
"if",
|
|
26
|
+
"then",
|
|
27
|
+
"else",
|
|
28
|
+
"uniqueItems",
|
|
29
|
+
"contains",
|
|
30
|
+
"minContains",
|
|
31
|
+
"maxContains",
|
|
32
|
+
"minProperties",
|
|
33
|
+
"maxProperties",
|
|
34
|
+
"propertyNames",
|
|
35
|
+
"dependentRequired",
|
|
36
|
+
"dependentSchemas",
|
|
37
|
+
"dependencies",
|
|
38
|
+
"unevaluatedItems",
|
|
39
|
+
"unevaluatedProperties",
|
|
40
|
+
"$dynamicRef",
|
|
41
|
+
"$recursiveRef",
|
|
42
|
+
"nullable",
|
|
43
|
+
];
|
|
44
|
+
/** The keywords whose value is one schema. */
|
|
45
|
+
const ONE_SCHEMA = ["additionalProperties", "additionalItems", "items", "not", "if", "then", "else", "contains", "propertyNames", "unevaluatedItems", "unevaluatedProperties"];
|
|
46
|
+
/** The keywords whose value is a list of schemas. */
|
|
47
|
+
const SCHEMA_LIST = ["allOf", "anyOf", "oneOf", "prefixItems", "items"];
|
|
48
|
+
/** The keywords whose value is a map of schemas. */
|
|
49
|
+
const SCHEMA_MAP = ["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"];
|
|
50
|
+
/** The keywords of a schema and its subschemas that the check does not examine fully. */
|
|
51
|
+
function uncheckedKeywords(schema) {
|
|
52
|
+
const found = new Set();
|
|
53
|
+
const seen = new Set();
|
|
54
|
+
const visit = (node) => {
|
|
55
|
+
if (!isPlainObject(node) || seen.has(node))
|
|
56
|
+
return;
|
|
57
|
+
seen.add(node);
|
|
58
|
+
for (const keyword of Object.keys(node)) {
|
|
59
|
+
if (NOT_EXAMINED.includes(keyword))
|
|
60
|
+
found.add(keyword);
|
|
61
|
+
}
|
|
62
|
+
if (node["oneOf"] !== undefined)
|
|
63
|
+
found.add("oneOf (examined as anyOf)");
|
|
64
|
+
const ref = node["$ref"];
|
|
65
|
+
if (typeof ref === "string" && !(ref === "#" || ref.startsWith("#/")))
|
|
66
|
+
found.add(`$ref ${ref}`);
|
|
67
|
+
for (const keyword of ONE_SCHEMA)
|
|
68
|
+
visit(node[keyword]);
|
|
69
|
+
for (const keyword of SCHEMA_LIST) {
|
|
70
|
+
const list = node[keyword];
|
|
71
|
+
if (Array.isArray(list))
|
|
72
|
+
list.forEach(visit);
|
|
73
|
+
}
|
|
74
|
+
for (const keyword of SCHEMA_MAP) {
|
|
75
|
+
const map = node[keyword];
|
|
76
|
+
if (isPlainObject(map))
|
|
77
|
+
Object.values(map).forEach(visit);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
visit(schema);
|
|
81
|
+
return [...found].sort();
|
|
82
|
+
}
|
|
83
|
+
/** This function examines a JSON value against a JSON Schema. A schema that is not an object or a boolean throws. */
|
|
84
|
+
export function validateJson(value, schema) {
|
|
85
|
+
if (typeof schema !== "boolean" && !isPlainObject(schema)) {
|
|
86
|
+
throw new JsonError("INVALID_SCHEMA", "json.validate: the schema is not an object or a boolean");
|
|
87
|
+
}
|
|
88
|
+
const issues = checkShape({ kind: "known", value, pointer: "" }, schema);
|
|
89
|
+
const errors = issues.map((issue) => ({ pointer: issue.pointer, message: issue.message }));
|
|
90
|
+
return { valid: errors.length === 0, errors, unchecked: uncheckedKeywords(schema) };
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","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AgB,EAAE,MAAe;IAC5D,IAAI,OAAO,MAAM,KAAK,SAAS,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1D,MAAM,IAAI,SAAS,CAAC,gBAAgB,EAAE,yDAAyD,CAAC,CAAC;IACnG,CAAC;IACD,MAAM,MAAM,GAAG,UAAU,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;IACzE,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAC3F,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC;AACtF,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions of the procedures of this package
|
|
3
|
+
*
|
|
4
|
+
* mark procedure new adds the types of each new procedure here. The zod schemas are in
|
|
5
|
+
* `module.ts`: an exported schema needs a written type (isolatedDeclarations).
|
|
6
|
+
*/
|
|
7
|
+
import type { PatchOperation } from "./patch.js";
|
|
8
|
+
export type { JsonValue } from "./value.js";
|
|
9
|
+
export type { PatchOperation } from "./patch.js";
|
|
10
|
+
export interface JsonQueryInput {
|
|
11
|
+
/** The JSON value to search. */
|
|
12
|
+
value: unknown;
|
|
13
|
+
/** A JSON Pointer (RFC 6901): `/items/0/name`. Give `pointer` or `path`. */
|
|
14
|
+
pointer?: string | undefined;
|
|
15
|
+
/** A path query: `items[*].name`, `$..id`. Give `pointer` or `path`. */
|
|
16
|
+
path?: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
export interface JsonQueryOutput {
|
|
19
|
+
/** True when one or more values match. */
|
|
20
|
+
found: boolean;
|
|
21
|
+
/** The value of the first match. */
|
|
22
|
+
value?: unknown;
|
|
23
|
+
/** Each match, in document order: its JSON Pointer and its value. */
|
|
24
|
+
matches: Array<{
|
|
25
|
+
pointer: string;
|
|
26
|
+
value?: unknown;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
export interface JsonPatchInput {
|
|
30
|
+
value: unknown;
|
|
31
|
+
/** The operations, in order. */
|
|
32
|
+
patch: PatchOperation[];
|
|
33
|
+
}
|
|
34
|
+
export interface JsonPatchOutput {
|
|
35
|
+
/** The value after the patch. */
|
|
36
|
+
value?: unknown;
|
|
37
|
+
}
|
|
38
|
+
export interface JsonDiffInput {
|
|
39
|
+
from: unknown;
|
|
40
|
+
to: unknown;
|
|
41
|
+
}
|
|
42
|
+
export interface JsonDiffOutput {
|
|
43
|
+
/** The operations that change `from` into `to`. Equal values give an empty list. */
|
|
44
|
+
patch: PatchOperation[];
|
|
45
|
+
}
|
|
46
|
+
export interface JsonMergeInput {
|
|
47
|
+
/** The value to change. */
|
|
48
|
+
target: unknown;
|
|
49
|
+
/** The merge patch: an object of changes, where null removes a key. */
|
|
50
|
+
patch: unknown;
|
|
51
|
+
}
|
|
52
|
+
export interface JsonMergeOutput {
|
|
53
|
+
value?: unknown;
|
|
54
|
+
}
|
|
55
|
+
export interface JsonValidateInput {
|
|
56
|
+
value: unknown;
|
|
57
|
+
/** The JSON Schema: an object or a boolean. */
|
|
58
|
+
schema: unknown;
|
|
59
|
+
}
|
|
60
|
+
export interface JsonValidateOutput {
|
|
61
|
+
valid: boolean;
|
|
62
|
+
/** Each problem: the JSON Pointer of the part of the value, and a message. */
|
|
63
|
+
errors: Array<{
|
|
64
|
+
pointer: string;
|
|
65
|
+
message: string;
|
|
66
|
+
}>;
|
|
67
|
+
/** The keywords of the schema that the check does not examine. Empty: the verdict is complete. */
|
|
68
|
+
unchecked: string[];
|
|
69
|
+
}
|
|
70
|
+
export interface YamlParseInput {
|
|
71
|
+
text: string;
|
|
72
|
+
/** True: the text can have more than one document, and `value` is the list of documents. */
|
|
73
|
+
all?: boolean | undefined;
|
|
74
|
+
}
|
|
75
|
+
export interface YamlParseOutput {
|
|
76
|
+
value?: unknown;
|
|
77
|
+
}
|
|
78
|
+
export interface YamlStringifyInput {
|
|
79
|
+
value: unknown;
|
|
80
|
+
/** The spaces of one level of indentation: 1 to 8. The default is 2. */
|
|
81
|
+
indent?: number | undefined;
|
|
82
|
+
/** The longest line before a fold. 0: no fold. The default is 80. */
|
|
83
|
+
lineWidth?: number | undefined;
|
|
84
|
+
/** True: the keys of each map in alphabetical order. */
|
|
85
|
+
sortKeys?: boolean | undefined;
|
|
86
|
+
}
|
|
87
|
+
export interface YamlStringifyOutput {
|
|
88
|
+
text: string;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAMjD,MAAM,WAAW,cAAc;IAC7B,gCAAgC;IAChC,KAAK,EAAE,OAAO,CAAC;IACf,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,wEAAwE;IACxE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,0CAA0C;IAC1C,KAAK,EAAE,OAAO,CAAC;IACf,oCAAoC;IACpC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,qEAAqE;IACrE,OAAO,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KA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,GAAG,SAAS,CAAC;IAC5B,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,wDAAwD;IACxD,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;CACd"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions of the procedures of this package
|
|
3
|
+
*
|
|
4
|
+
* mark procedure new adds the types of each new procedure here. The zod schemas are in
|
|
5
|
+
* `module.ts`: an exported schema needs a written type (isolatedDeclarations).
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
package/dist/value.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON values: the check, the copy and the comparison. The procedures of this package take and
|
|
3
|
+
* give only JSON values: null, booleans, finite numbers, strings, arrays and plain objects.
|
|
4
|
+
*
|
|
5
|
+
* Each object that this package makes has own data properties only, so a key `__proto__` of the
|
|
6
|
+
* data stays data: it does not change the prototype of the object (roadmap R6).
|
|
7
|
+
*/
|
|
8
|
+
/** A JSON value. */
|
|
9
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
10
|
+
[key: string]: JsonValue;
|
|
11
|
+
};
|
|
12
|
+
/** The keys that reach a prototype. A pointer, a path or a patch of this package refuses them. */
|
|
13
|
+
export declare const PROTOTYPE_KEYS: ReadonlySet<string>;
|
|
14
|
+
/** The kinds of `JsonError`. */
|
|
15
|
+
export type JsonErrorCode =
|
|
16
|
+
/** A value is not JSON: `undefined`, `NaN`, a function, a date or a class instance. */
|
|
17
|
+
"NOT_JSON"
|
|
18
|
+
/** A JSON Pointer or a path query is not valid. */
|
|
19
|
+
| "INVALID_POINTER"
|
|
20
|
+
/** A pointer, a path or a patch names `__proto__`, `constructor` or `prototype`. */
|
|
21
|
+
| "PROTOTYPE_KEY"
|
|
22
|
+
/** An operation of a patch is not valid, or its location does not exist. */
|
|
23
|
+
| "INVALID_PATCH"
|
|
24
|
+
/** A `test` operation of a patch found another value. */
|
|
25
|
+
| "TEST_FAILED"
|
|
26
|
+
/** The YAML text is not valid, or it has a value that JSON does not have. */
|
|
27
|
+
| "INVALID_YAML"
|
|
28
|
+
/** The JSON Schema is not a schema. */
|
|
29
|
+
| "INVALID_SCHEMA";
|
|
30
|
+
/** An error of a procedure of this package. A server sends it with the code `HANDLER_ERROR`. */
|
|
31
|
+
export declare class JsonError extends Error {
|
|
32
|
+
readonly code: JsonErrorCode;
|
|
33
|
+
readonly name = "JsonError";
|
|
34
|
+
constructor(code: JsonErrorCode, message: string);
|
|
35
|
+
}
|
|
36
|
+
/** True for an object whose prototype is `Object.prototype` or null. */
|
|
37
|
+
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
38
|
+
/** This function sets an own data property: a key `__proto__` stays data. */
|
|
39
|
+
export declare function put(target: Record<string, unknown>, key: string, value: unknown): void;
|
|
40
|
+
/** True when the object has an own property with this key. */
|
|
41
|
+
export declare function hasOwn(target: object, key: string): boolean;
|
|
42
|
+
/** The text of one reference token of a JSON Pointer (RFC 6901): `~` and `/` are escaped. */
|
|
43
|
+
export declare function escapeToken(token: string | number): string;
|
|
44
|
+
/** The JSON Pointer of a list of tokens. */
|
|
45
|
+
export declare function formatPointer(tokens: readonly (string | number)[]): string;
|
|
46
|
+
/**
|
|
47
|
+
* This function throws `NOT_JSON` when a part of the value is not JSON. The message has the JSON
|
|
48
|
+
* Pointer of the part. `label` starts the message: the procedure and the field.
|
|
49
|
+
*/
|
|
50
|
+
export declare function assertJson(value: unknown, label: string): asserts value is JsonValue;
|
|
51
|
+
/** A deep copy of a JSON value. Each object of the copy has own data properties only. */
|
|
52
|
+
export declare function cloneJson<T extends JsonValue>(value: T): T;
|
|
53
|
+
/**
|
|
54
|
+
* True when two JSON values are equal: the same type and value, arrays with equal items in the
|
|
55
|
+
* same order, and objects with the same keys and equal values in any order. The number 0 and -0
|
|
56
|
+
* are equal, as in JSON.
|
|
57
|
+
*/
|
|
58
|
+
export declare function jsonEqual(a: JsonValue, b: JsonValue): boolean;
|
|
59
|
+
/** The JSON type of a value, for a message. */
|
|
60
|
+
export declare function typeName(value: JsonValue | undefined): string;
|
|
61
|
+
//# sourceMappingURL=value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../src/value.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,oBAAoB;AACpB,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEtG,kGAAkG;AAClG,eAAO,MAAM,cAAc,EAAE,WAAW,CAAC,MAAM,CAAsD,CAAC;AAEtG,gCAAgC;AAChC,MAAM,MAAM,aAAa;AACvB,uFAAuF;AACrF,UAAU;AACZ,mDAAmD;GACjD,iBAAiB;AACnB,oFAAoF;GAClF,eAAe;AACjB,4EAA4E;GAC1E,eAAe;AACjB,yDAAyD;GACvD,aAAa;AACf,6EAA6E;GAC3E,cAAc;AAChB,uCAAuC;GACrC,gBAAgB,CAAC;AAErB,gGAAgG;AAChG,qBAAa,SAAU,SAAQ,KAAK;IAIhC,QAAQ,CAAC,IAAI,EAAE,aAAa;IAH9B,SAAkB,IAAI,eAAe;IAErC,YACW,IAAI,EAAE,aAAa,EAC5B,OAAO,EAAE,MAAM,EAGhB;CACF;AAED,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAI9E;AAED,6EAA6E;AAC7E,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAEtF;AAED,8DAA8D;AAC9D,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED,6FAA6F;AAC7F,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAE1D;AAED,4CAA4C;AAC5C,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,MAAM,CAE1E;AAkBD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,IAAI,SAAS,CAkBpF;AAED,yFAAyF;AACzF,wBAAgB,SAAS,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;AAS5D;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,OAAO,CAS7D;AAED,+CAA+C;AAC/C,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,CAK7D"}
|
package/dist/value.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON values: the check, the copy and the comparison. The procedures of this package take and
|
|
3
|
+
* give only JSON values: null, booleans, finite numbers, strings, arrays and plain objects.
|
|
4
|
+
*
|
|
5
|
+
* Each object that this package makes has own data properties only, so a key `__proto__` of the
|
|
6
|
+
* data stays data: it does not change the prototype of the object (roadmap R6).
|
|
7
|
+
*/
|
|
8
|
+
/** The keys that reach a prototype. A pointer, a path or a patch of this package refuses them. */
|
|
9
|
+
export const PROTOTYPE_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
10
|
+
/** An error of a procedure of this package. A server sends it with the code `HANDLER_ERROR`. */
|
|
11
|
+
export class JsonError extends Error {
|
|
12
|
+
code;
|
|
13
|
+
name = "JsonError";
|
|
14
|
+
constructor(code, message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.code = code;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** True for an object whose prototype is `Object.prototype` or null. */
|
|
20
|
+
export function isPlainObject(value) {
|
|
21
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
22
|
+
return false;
|
|
23
|
+
const prototype = Object.getPrototypeOf(value);
|
|
24
|
+
return prototype === Object.prototype || prototype === null;
|
|
25
|
+
}
|
|
26
|
+
/** This function sets an own data property: a key `__proto__` stays data. */
|
|
27
|
+
export function put(target, key, value) {
|
|
28
|
+
Object.defineProperty(target, key, { value, writable: true, enumerable: true, configurable: true });
|
|
29
|
+
}
|
|
30
|
+
/** True when the object has an own property with this key. */
|
|
31
|
+
export function hasOwn(target, key) {
|
|
32
|
+
return Object.prototype.hasOwnProperty.call(target, key);
|
|
33
|
+
}
|
|
34
|
+
/** The text of one reference token of a JSON Pointer (RFC 6901): `~` and `/` are escaped. */
|
|
35
|
+
export function escapeToken(token) {
|
|
36
|
+
return String(token).replace(/~/g, "~0").replace(/\//g, "~1");
|
|
37
|
+
}
|
|
38
|
+
/** The JSON Pointer of a list of tokens. */
|
|
39
|
+
export function formatPointer(tokens) {
|
|
40
|
+
return tokens.map((token) => `/${escapeToken(token)}`).join("");
|
|
41
|
+
}
|
|
42
|
+
/** The description of a value that is not JSON, or undefined for a JSON value. */
|
|
43
|
+
function notJson(value) {
|
|
44
|
+
switch (typeof value) {
|
|
45
|
+
case "string":
|
|
46
|
+
case "boolean":
|
|
47
|
+
return undefined;
|
|
48
|
+
case "number":
|
|
49
|
+
return Number.isFinite(value) ? undefined : `the number ${String(value)}`;
|
|
50
|
+
case "object":
|
|
51
|
+
if (value === null || Array.isArray(value) || isPlainObject(value))
|
|
52
|
+
return undefined;
|
|
53
|
+
return `an object of the class ${value.constructor?.name ?? "unknown"}`;
|
|
54
|
+
default:
|
|
55
|
+
return `a value of the type ${typeof value}`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* This function throws `NOT_JSON` when a part of the value is not JSON. The message has the JSON
|
|
60
|
+
* Pointer of the part. `label` starts the message: the procedure and the field.
|
|
61
|
+
*/
|
|
62
|
+
export function assertJson(value, label) {
|
|
63
|
+
const stack = [{ value, tokens: [] }];
|
|
64
|
+
const seen = new Set();
|
|
65
|
+
while (stack.length > 0) {
|
|
66
|
+
const { value: current, tokens } = stack.pop();
|
|
67
|
+
const problem = notJson(current);
|
|
68
|
+
if (problem !== undefined) {
|
|
69
|
+
throw new JsonError("NOT_JSON", `${label}: the value at "${formatPointer(tokens)}" is ${problem}, which JSON does not have`);
|
|
70
|
+
}
|
|
71
|
+
if (current === null || typeof current !== "object")
|
|
72
|
+
continue;
|
|
73
|
+
if (seen.has(current))
|
|
74
|
+
throw new JsonError("NOT_JSON", `${label}: the value at "${formatPointer(tokens)}" refers to itself`);
|
|
75
|
+
seen.add(current);
|
|
76
|
+
if (Array.isArray(current)) {
|
|
77
|
+
for (let index = current.length - 1; index >= 0; index--)
|
|
78
|
+
stack.push({ value: current[index], tokens: [...tokens, index] });
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
for (const key of Object.keys(current))
|
|
82
|
+
stack.push({ value: current[key], tokens: [...tokens, key] });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export function cloneJson(value) {
|
|
87
|
+
if (value === null || typeof value !== "object")
|
|
88
|
+
return value;
|
|
89
|
+
if (Array.isArray(value))
|
|
90
|
+
return value.map((item) => cloneJson(item));
|
|
91
|
+
const copy = {};
|
|
92
|
+
for (const key of Object.keys(value))
|
|
93
|
+
put(copy, key, cloneJson(value[key]));
|
|
94
|
+
return copy;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* True when two JSON values are equal: the same type and value, arrays with equal items in the
|
|
98
|
+
* same order, and objects with the same keys and equal values in any order. The number 0 and -0
|
|
99
|
+
* are equal, as in JSON.
|
|
100
|
+
*/
|
|
101
|
+
export function jsonEqual(a, b) {
|
|
102
|
+
if (a === b)
|
|
103
|
+
return true;
|
|
104
|
+
if (a === null || b === null || typeof a !== "object" || typeof b !== "object")
|
|
105
|
+
return false;
|
|
106
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
107
|
+
return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((item, index) => jsonEqual(item, b[index]));
|
|
108
|
+
}
|
|
109
|
+
const keysA = Object.keys(a);
|
|
110
|
+
if (keysA.length !== Object.keys(b).length)
|
|
111
|
+
return false;
|
|
112
|
+
return keysA.every((key) => hasOwn(b, key) && jsonEqual(a[key], b[key]));
|
|
113
|
+
}
|
|
114
|
+
/** The JSON type of a value, for a message. */
|
|
115
|
+
export function typeName(value) {
|
|
116
|
+
if (value === undefined)
|
|
117
|
+
return "nothing";
|
|
118
|
+
if (value === null)
|
|
119
|
+
return "null";
|
|
120
|
+
if (Array.isArray(value))
|
|
121
|
+
return "an array";
|
|
122
|
+
return typeof value === "object" ? "an object" : `a ${typeof value}`;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value.js","sourceRoot":"","sources":["../src/value.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,kGAAkG;AAClG,MAAM,CAAC,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,CAAC;AAmBtG,gGAAgG;AAChG,MAAM,OAAO,SAAU,SAAQ,KAAK;IAIvB,IAAI;IAHG,IAAI,GAAG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,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,UAAU,CAAC;IAC5C,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,OAAO,KAAK,EAAE,CAAC;AACvE,CAAC"}
|
package/dist/yaml.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML to JSON and back, with the `yaml` package (YAML 1.2, the core schema).
|
|
3
|
+
*
|
|
4
|
+
* - The parse gives only JSON values. A value that JSON does not have (`.inf`, `.nan`) is an
|
|
5
|
+
* error. The explicit YAML 1.1 tags (`!!binary`, `!!timestamp`, `!!set`) give their text.
|
|
6
|
+
* - A key of a map that is a number, a boolean or null becomes its text. A key that is a map or a
|
|
7
|
+
* list is an error.
|
|
8
|
+
* - The parse refuses more than 100 aliases (a resource attack) and a duplicate key.
|
|
9
|
+
* - Each object of the result has own data properties only, so a key `__proto__` stays data.
|
|
10
|
+
* - The text of a value is YAML 1.2 that a YAML 1.1 reader reads as the same value.
|
|
11
|
+
*/
|
|
12
|
+
import { type JsonValue } from "./value.js";
|
|
13
|
+
/** The options of the parse. */
|
|
14
|
+
export interface YamlParseOptions {
|
|
15
|
+
/** True: the text can have more than one document, and the result is the list of documents. */
|
|
16
|
+
readonly all?: boolean | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** The options of the text. */
|
|
19
|
+
export interface YamlStringifyOptions {
|
|
20
|
+
/** The spaces of one level of indentation: 1 to 8. The default is 2. */
|
|
21
|
+
readonly indent?: number | undefined;
|
|
22
|
+
/** The longest line before a fold. 0: no fold. The default is 80. */
|
|
23
|
+
readonly lineWidth?: number | undefined;
|
|
24
|
+
/** True: the keys of each map in alphabetical order. The default keeps the order of the value. */
|
|
25
|
+
readonly sortKeys?: boolean | undefined;
|
|
26
|
+
}
|
|
27
|
+
/** This function parses YAML text into a JSON value. Bad YAML throws `INVALID_YAML`. */
|
|
28
|
+
export declare function parseYaml(text: string, options?: YamlParseOptions): JsonValue;
|
|
29
|
+
/**
|
|
30
|
+
* This function writes a JSON value as YAML text. The text is YAML 1.2, and a YAML 1.1 reader
|
|
31
|
+
* reads the same value: a string that YAML 1.1 takes as another type (`yes`, `no`, `on`, a
|
|
32
|
+
* date, `0777`, `1_000`) is in double quotes.
|
|
33
|
+
*/
|
|
34
|
+
export declare function stringifyYaml(value: JsonValue, options?: YamlStringifyOptions): string;
|
|
35
|
+
//# sourceMappingURL=yaml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../src/yaml.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAiC,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAE3E,gCAAgC;AAChC,MAAM,WAAW,gBAAgB;IAC/B,+FAA+F;IAC/F,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACpC;AAED,+BAA+B;AAC/B,MAAM,WAAW,oBAAoB;IACnC,wEAAwE;IACxE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,qEAAqE;IACrE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,kGAAkG;IAClG,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACzC;AA8CD,wFAAwF;AACxF,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,SAAS,CAMjF;AAoBD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,GAAE,oBAAyB,GAAG,MAAM,CAoB1F"}
|