@procedures/json 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/LICENSE +21 -0
  3. package/README.md +104 -2
  4. package/dist/.tsbuildinfo +1 -0
  5. package/dist/diff.d.ts +18 -0
  6. package/dist/diff.d.ts.map +1 -0
  7. package/dist/diff.js +66 -0
  8. package/dist/diff.js.map +1 -0
  9. package/dist/index.d.ts +13 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +15 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/merge.d.ts +14 -0
  14. package/dist/merge.d.ts.map +1 -0
  15. package/dist/merge.js +34 -0
  16. package/dist/merge.js.map +1 -0
  17. package/dist/module.d.ts +21 -0
  18. package/dist/module.d.ts.map +1 -0
  19. package/dist/module.js +192 -0
  20. package/dist/module.js.map +1 -0
  21. package/dist/patch.d.ts +23 -0
  22. package/dist/patch.d.ts.map +1 -0
  23. package/dist/patch.js +137 -0
  24. package/dist/patch.js.map +1 -0
  25. package/dist/path.d.ts +38 -0
  26. package/dist/path.d.ts.map +1 -0
  27. package/dist/path.js +157 -0
  28. package/dist/path.js.map +1 -0
  29. package/dist/pointer.d.ts +22 -0
  30. package/dist/pointer.d.ts.map +1 -0
  31. package/dist/pointer.js +70 -0
  32. package/dist/pointer.js.map +1 -0
  33. package/dist/procedures/json/diff.d.ts +12 -0
  34. package/dist/procedures/json/diff.d.ts.map +1 -0
  35. package/dist/procedures/json/diff.js +17 -0
  36. package/dist/procedures/json/diff.js.map +1 -0
  37. package/dist/procedures/json/index.d.ts +6 -0
  38. package/dist/procedures/json/index.d.ts.map +1 -0
  39. package/dist/procedures/json/index.js +6 -0
  40. package/dist/procedures/json/index.js.map +1 -0
  41. package/dist/procedures/json/merge.d.ts +12 -0
  42. package/dist/procedures/json/merge.d.ts.map +1 -0
  43. package/dist/procedures/json/merge.js +17 -0
  44. package/dist/procedures/json/merge.js.map +1 -0
  45. package/dist/procedures/json/patch.d.ts +12 -0
  46. package/dist/procedures/json/patch.d.ts.map +1 -0
  47. package/dist/procedures/json/patch.js +20 -0
  48. package/dist/procedures/json/patch.js.map +1 -0
  49. package/dist/procedures/json/query.d.ts +12 -0
  50. package/dist/procedures/json/query.d.ts.map +1 -0
  51. package/dist/procedures/json/query.js +28 -0
  52. package/dist/procedures/json/query.js.map +1 -0
  53. package/dist/procedures/json/validate.d.ts +12 -0
  54. package/dist/procedures/json/validate.d.ts.map +1 -0
  55. package/dist/procedures/json/validate.js +18 -0
  56. package/dist/procedures/json/validate.js.map +1 -0
  57. package/dist/procedures/yaml/index.d.ts +3 -0
  58. package/dist/procedures/yaml/index.d.ts.map +1 -0
  59. package/dist/procedures/yaml/index.js +3 -0
  60. package/dist/procedures/yaml/index.js.map +1 -0
  61. package/dist/procedures/yaml/parse.d.ts +12 -0
  62. package/dist/procedures/yaml/parse.d.ts.map +1 -0
  63. package/dist/procedures/yaml/parse.js +14 -0
  64. package/dist/procedures/yaml/parse.js.map +1 -0
  65. package/dist/procedures/yaml/stringify.d.ts +11 -0
  66. package/dist/procedures/yaml/stringify.d.ts.map +1 -0
  67. package/dist/procedures/yaml/stringify.js +15 -0
  68. package/dist/procedures/yaml/stringify.js.map +1 -0
  69. package/dist/register.d.ts +6 -0
  70. package/dist/register.d.ts.map +1 -0
  71. package/dist/register.js +8 -0
  72. package/dist/register.js.map +1 -0
  73. package/dist/schema.d.ts +38 -0
  74. package/dist/schema.d.ts.map +1 -0
  75. package/dist/schema.js +92 -0
  76. package/dist/schema.js.map +1 -0
  77. package/dist/types.d.ts +90 -0
  78. package/dist/types.d.ts.map +1 -0
  79. package/dist/types.js +8 -0
  80. package/dist/types.js.map +1 -0
  81. package/dist/value.d.ts +61 -0
  82. package/dist/value.d.ts.map +1 -0
  83. package/dist/value.js +124 -0
  84. package/dist/value.js.map +1 -0
  85. package/dist/yaml.d.ts +35 -0
  86. package/dist/yaml.d.ts.map +1 -0
  87. package/dist/yaml.js +111 -0
  88. package/dist/yaml.js.map +1 -0
  89. package/package.json +81 -3
  90. package/src/diff.ts +58 -0
  91. package/src/index.ts +14 -0
  92. package/src/merge.ts +34 -0
  93. package/src/module.ts +236 -0
  94. package/src/patch.ts +132 -0
  95. package/src/path.ts +155 -0
  96. package/src/pointer.ts +70 -0
  97. package/src/procedures/json/diff.ts +19 -0
  98. package/src/procedures/json/index.ts +5 -0
  99. package/src/procedures/json/merge.ts +19 -0
  100. package/src/procedures/json/patch.ts +21 -0
  101. package/src/procedures/json/query.ts +29 -0
  102. package/src/procedures/json/validate.ts +20 -0
  103. package/src/procedures/yaml/index.ts +2 -0
  104. package/src/procedures/yaml/parse.ts +16 -0
  105. package/src/procedures/yaml/stringify.ts +17 -0
  106. package/src/register.ts +10 -0
  107. package/src/schema.ts +104 -0
  108. package/src/types.ts +127 -0
  109. package/src/value.ts +143 -0
  110. package/src/yaml.ts +128 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,48 @@
1
+ # @procedures/json
2
+
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - a6b01a9: The new package `@procedures/json` (roadmap R39) has seven pure procedures (`PURE_EFFECTS`): `json.query` (a JSON Pointer or a path query), `json.patch` (RFC 6902), `json.diff` (it gives an RFC 6902 patch), `json.merge` (RFC 7386), `json.validate` (a subset of JSON Schema, with the keywords that the check does not examine in `unchecked`), `yaml.parse` and `yaml.stringify`.
8
+
9
+ A pointer, a path, a patch and a merge patch cannot name `__proto__`, `constructor` or `prototype`. A key `__proto__` in the data stays data. The YAML text of `yaml.stringify` is YAML 1.2 that a YAML 1.1 reader reads as the same value. Property tests examine that a patch from `json.diff` gives the second value, and that `yaml.parse` of the text of `yaml.stringify` gives the value again.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [ddea529]
14
+ - Updated dependencies [b2a3e3a]
15
+ - Updated dependencies [a8c47f1]
16
+ - Updated dependencies [381ce3a]
17
+ - Updated dependencies [0c627f8]
18
+ - Updated dependencies [ae7f05f]
19
+ - Updated dependencies [7873940]
20
+ - Updated dependencies [29a7b29]
21
+ - Updated dependencies [9bc2ddb]
22
+ - Updated dependencies [a70d445]
23
+ - Updated dependencies [bc70357]
24
+ - Updated dependencies [07cc998]
25
+ - Updated dependencies [a6b01a9]
26
+ - Updated dependencies [c799cdd]
27
+ - Updated dependencies [540f8d9]
28
+ - Updated dependencies [b6daaec]
29
+ - Updated dependencies [5b9264e]
30
+ - Updated dependencies [956e88b]
31
+ - Updated dependencies [ff62281]
32
+ - Updated dependencies [d81d0ed]
33
+ - Updated dependencies [f5ed492]
34
+ - Updated dependencies [aa67cc7]
35
+ - Updated dependencies [061fa22]
36
+ - Updated dependencies [cfb9d69]
37
+ - Updated dependencies [43f7de5]
38
+ - Updated dependencies [b07bb50]
39
+ - Updated dependencies [4a3bfa1]
40
+ - Updated dependencies [bd0b626]
41
+ - Updated dependencies [a6be873]
42
+ - Updated dependencies [fb30718]
43
+ - Updated dependencies [c5528e4]
44
+ - Updated dependencies [fee5d9c]
45
+ - Updated dependencies [21f7743]
46
+ - Updated dependencies [31a0b46]
47
+ - @procedures/client@0.3.0
48
+ - @procedures/compiler@0.3.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Mark Russell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,105 @@
1
- # Temporary Holding Version
1
+ # @procedures/json
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/@procedures/json?color=2346c4&label=npm)](https://www.npmjs.com/package/@procedures/json)
4
+
5
+ ```sh
6
+ npm install @procedures/json
7
+ ```
8
+
9
+ Transforms of JSON values as procedures: a query, a patch, a diff, a merge, a schema check, and YAML to JSON and back. Each procedure is pure. Its output comes only from its input, and it changes nothing.
10
+
11
+ ## The procedures
12
+
13
+ | Procedure | What it does |
14
+ |---|---|
15
+ | `json.query` | It gives the values at a JSON Pointer (RFC 6901) or at a path query. |
16
+ | `json.patch` | It applies a JSON Patch (RFC 6902). |
17
+ | `json.diff` | It gives the JSON Patch that changes one value into another value. |
18
+ | `json.merge` | It applies a JSON merge patch (RFC 7386). |
19
+ | `json.validate` | It examines a value against a JSON Schema. |
20
+ | `yaml.parse` | It parses YAML text into a JSON value. |
21
+ | `yaml.stringify` | It writes a JSON value as YAML text. |
22
+
23
+ Each procedure declares `PURE_EFFECTS`, so a read-only host can start it.
24
+
25
+ ```ts
26
+ import "@procedures/json/register";
27
+
28
+ await client.call(["json", "query"], { value: config, path: "services[*].image" });
29
+ await client.call(["json", "patch"], { value: config, patch: [{ op: "replace", path: "/version", value: 2 }] });
30
+ await client.call(["yaml", "parse"], { text: "name: app\nports: [80, 443]" });
31
+ ```
32
+
33
+ ## Pointers and paths
34
+
35
+ `json.query` takes `pointer` or `path`. Each match has its JSON Pointer.
36
+
37
+ | Path | Meaning |
38
+ |---|---|
39
+ | `$` | The whole value. It is optional at the start. |
40
+ | `.name` or `name` | A member of an object. A name has letters, digits, `_`, `$` and `-`. |
41
+ | `["a.b"]` | A member with any key. A backslash escapes a quote or a backslash. |
42
+ | `[2]`, `[-1]` | An item of an array. `[-1]` is the last item. |
43
+ | `*` or `[*]` | Each member or each item. |
44
+ | `..name` | The same step at each depth. |
45
+
46
+ The path query has no filters and no scripts.
47
+
48
+ ## The prototype keys
49
+
50
+ A pointer, a path, a JSON Patch and a merge patch cannot name `__proto__`, `constructor` or `prototype`. The error has the code `PROTOTYPE_KEY`.
51
+
52
+ - A key `__proto__` in the data stays data. Each object that a procedure makes has own data properties only.
53
+ - The patch of `json.diff` does not name a prototype key. When a difference is under such a key, the patch replaces the object that holds the key.
54
+
55
+ ## Patches
56
+
57
+ - `json.patch` applies all operations or none. A failed `test` operation gives the code `TEST_FAILED`.
58
+ - `json.diff` keeps the shared start and end of an array, so an insert at the start is one `add`.
59
+ - `json.patch` of the output of `json.diff` on the first value gives the second value. A property test with random JSON values examines this rule.
60
+ - `json.merge` removes a key whose patch value is null. A patch that is not an object replaces the value.
61
+
62
+ ## The schema check
63
+
64
+ `json.validate` uses the validator of [`@procedures/compiler`](../compiler), the validator that `program.check` uses. It examines a subset of JSON Schema:
65
+
66
+ - `type`, `enum`, `const` and `$ref` to the same schema
67
+ - `allOf`, `anyOf` and `oneOf`. The check examines `oneOf` as `anyOf`, so a value that agrees with two branches passes.
68
+ - `properties`, `required`, `additionalProperties` and `patternProperties`
69
+ - `items`, `prefixItems`, `additionalItems`, `minItems` and `maxItems`
70
+ - `minLength`, `maxLength` and `pattern`. The lengths count UTF-16 code units.
71
+ - `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum` and `multipleOf`
72
+
73
+ The check ignores `format` and the other annotations, as the standard tells. The output field `unchecked` lists each keyword of the schema that the check does not examine. Examples are `not`, `if`, `uniqueItems`, `minProperties` and a `$ref` to another document. When `unchecked` is empty, the verdict is complete. A `oneOf` in the schema goes into `unchecked` too, because its check is not complete.
74
+
75
+ ## YAML
76
+
77
+ - The parse uses YAML 1.2 with the core schema of the [`yaml`](https://www.npmjs.com/package/yaml) package.
78
+ - The parse gives only JSON values. `.inf` and `.nan` are errors. A map or a list as a key is an error.
79
+ - A key that is a number, a boolean or null becomes its text.
80
+ - The explicit YAML 1.1 tags (`!!binary`, `!!timestamp`) give their text.
81
+ - The parse refuses more than 100 aliases, because many aliases can fill the memory. It also refuses a duplicate key.
82
+ - `all: true` reads more than one document and gives the list of documents.
83
+ - The text of `yaml.stringify` is YAML 1.2, and a YAML 1.1 reader reads the same value. A string that YAML 1.1 reads as another type is in double quotes, for example `yes`, `no`, `on`, a date or `0777`.
84
+ - `yaml.parse` of the text of `yaml.stringify` gives the value again. A property test with random JSON values examines this rule.
85
+ - A strict YAML 1.1 reader reads a number with an exponent and without a fraction as a string, for example `1e+21`.
86
+
87
+ ## Errors
88
+
89
+ Each error is a `JsonError`. A server sends it with the code `HANDLER_ERROR` and the message. The field `code` tells the kind:
90
+
91
+ | Code | Cause |
92
+ |---|---|
93
+ | `NOT_JSON` | A value is not JSON: `undefined`, `NaN`, a date or a value that refers to itself. The message has the pointer of the value. |
94
+ | `INVALID_POINTER` | A pointer or a path is not correct. |
95
+ | `PROTOTYPE_KEY` | A pointer, a path or a patch names a prototype key. |
96
+ | `INVALID_PATCH` | An operation is not correct, or its location does not exist. |
97
+ | `TEST_FAILED` | A `test` operation found another value. |
98
+ | `INVALID_YAML` | The YAML text is not correct, or it has a value that JSON does not have. |
99
+ | `INVALID_SCHEMA` | The schema is not an object or a boolean. |
100
+
101
+ ## Related packages
102
+
103
+ - [`@procedures/client`](../client): the core, with `PURE_EFFECTS`.
104
+ - [`@procedures/compiler`](../compiler): the validator of the schema check.
105
+ - [`@procedures/http`](../http): the HTTP procedures.