zuzu-js 0.1.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/LICENSE +5 -0
- package/README.md +113 -0
- package/bin/zuzu +17 -0
- package/bin/zuzu-build-browser-bundle +57 -0
- package/bin/zuzu-generate-browser-stdlib +584 -0
- package/bin/zuzu-js +23 -0
- package/bin/zuzu-js-compile +152 -0
- package/bin/zuzu-js-electron +19 -0
- package/dist/zuzu-browser-worker.js +45574 -0
- package/dist/zuzu-browser.js +45362 -0
- package/lib/browser-bundle-entry.js +160 -0
- package/lib/browser-gui-renderer.js +387 -0
- package/lib/browser-runtime.js +167 -0
- package/lib/browser-worker-entry.js +413 -0
- package/lib/browser-ztests/runner.html +103 -0
- package/lib/browser-ztests/runner.js +369 -0
- package/lib/cli.js +350 -0
- package/lib/collections.js +367 -0
- package/lib/compiler.js +303 -0
- package/lib/electron/launcher.js +70 -0
- package/lib/electron/main.js +956 -0
- package/lib/electron/preload.js +80 -0
- package/lib/electron/renderer.html +122 -0
- package/lib/electron/renderer.js +24 -0
- package/lib/execution-metadata.js +18 -0
- package/lib/gui/dom-renderer.js +778 -0
- package/lib/host/browser-host.js +278 -0
- package/lib/host/capabilities.js +47 -0
- package/lib/host/electron-host.js +15 -0
- package/lib/host/node-host.js +74 -0
- package/lib/paths.js +150 -0
- package/lib/runtime-entrypoints.js +60 -0
- package/lib/runtime-helpers.js +886 -0
- package/lib/runtime.js +3529 -0
- package/lib/tap.js +37 -0
- package/lib/transpiler-new/ast.js +23 -0
- package/lib/transpiler-new/codegen.js +2455 -0
- package/lib/transpiler-new/errors.js +28 -0
- package/lib/transpiler-new/index.js +26 -0
- package/lib/transpiler-new/lexer.js +834 -0
- package/lib/transpiler-new/parser.js +2332 -0
- package/lib/transpiler-new/validate-bindings.js +326 -0
- package/lib/transpiler-utils.js +95 -0
- package/lib/transpiler.js +33 -0
- package/lib/zuzu.js +53 -0
- package/modules/javascript.js +193 -0
- package/modules/std/archive.js +603 -0
- package/modules/std/clib.js +338 -0
- package/modules/std/data/csv.js +1331 -0
- package/modules/std/data/json.js +531 -0
- package/modules/std/data/xml.js +441 -0
- package/modules/std/data/yaml.js +256 -0
- package/modules/std/db-worker.js +250 -0
- package/modules/std/db.js +664 -0
- package/modules/std/digest/_hash.js +443 -0
- package/modules/std/digest/md5.js +26 -0
- package/modules/std/digest/sha.js +72 -0
- package/modules/std/eval.js +10 -0
- package/modules/std/gui/objects.js +1519 -0
- package/modules/std/internals.js +571 -0
- package/modules/std/io/socks-worker.js +318 -0
- package/modules/std/io/socks.js +186 -0
- package/modules/std/io.js +475 -0
- package/modules/std/marshal/cbor.js +463 -0
- package/modules/std/marshal/graph.js +1624 -0
- package/modules/std/marshal.js +87 -0
- package/modules/std/math/bignum.js +91 -0
- package/modules/std/math.js +79 -0
- package/modules/std/net/dns.js +306 -0
- package/modules/std/net/http.js +820 -0
- package/modules/std/net/smtp.js +943 -0
- package/modules/std/net/url.js +109 -0
- package/modules/std/proc.js +602 -0
- package/modules/std/secure.js +3724 -0
- package/modules/std/string/base64.js +138 -0
- package/modules/std/string.js +299 -0
- package/modules/std/task.js +914 -0
- package/modules/std/time.js +579 -0
- package/modules/std/tui.js +188 -0
- package/modules/std/worker-thread.js +246 -0
- package/modules/std/worker.js +790 -0
- package/package.json +67 -0
- package/stdlib/modules/javascript.zzm +99 -0
- package/stdlib/modules/perl.zzm +105 -0
- package/stdlib/modules/std/archive.zzm +132 -0
- package/stdlib/modules/std/cache/lru.zzm +174 -0
- package/stdlib/modules/std/clib.zzm +112 -0
- package/stdlib/modules/std/colour.zzm +220 -0
- package/stdlib/modules/std/config.zzm +818 -0
- package/stdlib/modules/std/data/cbor.zzm +497 -0
- package/stdlib/modules/std/data/csv.zzm +285 -0
- package/stdlib/modules/std/data/ini.zzm +472 -0
- package/stdlib/modules/std/data/json/schema/core.zzm +573 -0
- package/stdlib/modules/std/data/json/schema/format.zzm +581 -0
- package/stdlib/modules/std/data/json/schema/model.zzm +255 -0
- package/stdlib/modules/std/data/json/schema/output.zzm +272 -0
- package/stdlib/modules/std/data/json/schema/relative_pointer.zzm +299 -0
- package/stdlib/modules/std/data/json/schema/validation.zzm +1503 -0
- package/stdlib/modules/std/data/json/schema.zzm +306 -0
- package/stdlib/modules/std/data/json.zzm +102 -0
- package/stdlib/modules/std/data/kdl/json.zzm +460 -0
- package/stdlib/modules/std/data/kdl/xml.zzm +387 -0
- package/stdlib/modules/std/data/kdl.zzm +1631 -0
- package/stdlib/modules/std/data/toml.zzm +756 -0
- package/stdlib/modules/std/data/toon.zzm +1017 -0
- package/stdlib/modules/std/data/xml/escape.zzm +156 -0
- package/stdlib/modules/std/data/xml.zzm +276 -0
- package/stdlib/modules/std/data/yaml.zzm +94 -0
- package/stdlib/modules/std/db.zzm +173 -0
- package/stdlib/modules/std/defer.zzm +75 -0
- package/stdlib/modules/std/digest/crc32.zzm +196 -0
- package/stdlib/modules/std/digest/md5.zzm +54 -0
- package/stdlib/modules/std/digest/sha.zzm +83 -0
- package/stdlib/modules/std/dump.zzm +317 -0
- package/stdlib/modules/std/eval.zzm +63 -0
- package/stdlib/modules/std/getopt.zzm +432 -0
- package/stdlib/modules/std/gui/dialogue.zzm +592 -0
- package/stdlib/modules/std/gui/objects.zzm +123 -0
- package/stdlib/modules/std/gui.zzm +1914 -0
- package/stdlib/modules/std/internals.zzm +139 -0
- package/stdlib/modules/std/io/socks.zzm +139 -0
- package/stdlib/modules/std/io.zzm +157 -0
- package/stdlib/modules/std/lingua/en.zzm +347 -0
- package/stdlib/modules/std/log.zzm +169 -0
- package/stdlib/modules/std/mail.zzm +2726 -0
- package/stdlib/modules/std/marshal.zzm +138 -0
- package/stdlib/modules/std/math/bignum.zzm +98 -0
- package/stdlib/modules/std/math/range.zzm +116 -0
- package/stdlib/modules/std/math/roman.zzm +156 -0
- package/stdlib/modules/std/math.zzm +141 -0
- package/stdlib/modules/std/net/dns.zzm +93 -0
- package/stdlib/modules/std/net/http.zzm +278 -0
- package/stdlib/modules/std/net/smtp.zzm +257 -0
- package/stdlib/modules/std/net/url.zzm +69 -0
- package/stdlib/modules/std/path/jsonpointer.zzm +526 -0
- package/stdlib/modules/std/path/kdl.zzm +1003 -0
- package/stdlib/modules/std/path/simple.zzm +520 -0
- package/stdlib/modules/std/path/z/context.zzm +147 -0
- package/stdlib/modules/std/path/z/evaluate.zzm +549 -0
- package/stdlib/modules/std/path/z/functions.zzm +874 -0
- package/stdlib/modules/std/path/z/lexer.zzm +490 -0
- package/stdlib/modules/std/path/z/node.zzm +1455 -0
- package/stdlib/modules/std/path/z/operators.zzm +445 -0
- package/stdlib/modules/std/path/z/parser.zzm +359 -0
- package/stdlib/modules/std/path/z.zzm +403 -0
- package/stdlib/modules/std/path/zz/functions.zzm +828 -0
- package/stdlib/modules/std/path/zz/operators.zzm +1036 -0
- package/stdlib/modules/std/path/zz.zzm +100 -0
- package/stdlib/modules/std/proc.zzm +155 -0
- package/stdlib/modules/std/result.zzm +149 -0
- package/stdlib/modules/std/secure.zzm +606 -0
- package/stdlib/modules/std/string/base64.zzm +66 -0
- package/stdlib/modules/std/string/quoted_printable.zzm +485 -0
- package/stdlib/modules/std/string.zzm +179 -0
- package/stdlib/modules/std/task.zzm +221 -0
- package/stdlib/modules/std/template/z.zzm +531 -0
- package/stdlib/modules/std/template/zz.zzm +62 -0
- package/stdlib/modules/std/time.zzm +188 -0
- package/stdlib/modules/std/tui.zzm +89 -0
- package/stdlib/modules/std/uuid.zzm +223 -0
- package/stdlib/modules/std/web/session.zzm +388 -0
- package/stdlib/modules/std/web/static.zzm +329 -0
- package/stdlib/modules/std/web.zzm +1942 -0
- package/stdlib/modules/std/worker.zzm +202 -0
- package/stdlib/modules/std/zuzuzoo.zzm +3960 -0
- package/stdlib/modules/test/more.zzm +528 -0
- package/stdlib/modules/test/parser.zzm +209 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
=encoding utf8
|
|
2
|
+
|
|
3
|
+
=head1 NAME
|
|
4
|
+
|
|
5
|
+
std/data/json/schema - JSON Schema 2020-12 validation.
|
|
6
|
+
|
|
7
|
+
=head1 SYNOPSIS
|
|
8
|
+
|
|
9
|
+
from std/data/json/schema import
|
|
10
|
+
JSONSchema,
|
|
11
|
+
RequiredPropertyError,
|
|
12
|
+
TypeMismatchError,
|
|
13
|
+
validate,
|
|
14
|
+
valid;
|
|
15
|
+
|
|
16
|
+
let person_schema := {
|
|
17
|
+
type: "object",
|
|
18
|
+
required: [ "name" ],
|
|
19
|
+
properties: {
|
|
20
|
+
name: { type: "string" },
|
|
21
|
+
age: { type: "integer", minimum: 0 },
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
say( valid( person_schema, { name: "Ada", age: 37 } ) );
|
|
26
|
+
|
|
27
|
+
let result := validate( person_schema, { age: -1 } );
|
|
28
|
+
for ( let error in result.errors() ) {
|
|
29
|
+
if ( error instanceof RequiredPropertyError ) {
|
|
30
|
+
say( error.instanceLocation() _ ": " _ error.error() );
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
=head1 IMPLEMENTATION SUPPORT
|
|
35
|
+
|
|
36
|
+
This Pure Zuzu module is supported by all implementations of ZuzuScript.
|
|
37
|
+
Network reference loading needs C<std/net/http>, so it is available only in
|
|
38
|
+
runtimes that provide that module.
|
|
39
|
+
|
|
40
|
+
=head1 DESCRIPTION
|
|
41
|
+
|
|
42
|
+
I<std/data/json/schema> validates native Zuzu values against JSON Schema
|
|
43
|
+
2020-12 schemas. It is intended for already-decoded JSON data: schemas and
|
|
44
|
+
instances are normally C<Dict>, C<Array>, strings, numbers, booleans, and
|
|
45
|
+
C<null>.
|
|
46
|
+
|
|
47
|
+
The validator also accepts some native collection types where the JSON model
|
|
48
|
+
has a clear equivalent. C<PairList> is treated as an object and preserves
|
|
49
|
+
duplicate keys for keywords that need to inspect them. C<Set> and C<Bag> are
|
|
50
|
+
treated as array-like values when order is not important, though ordered
|
|
51
|
+
tuple validation is meaningful only for C<Array>.
|
|
52
|
+
|
|
53
|
+
Validation can be requested in two forms. Boolean validation short-circuits
|
|
54
|
+
after the first failure and returns C<true> or C<false>. Full validation
|
|
55
|
+
collects errors and returns a C<ValidationResult> whose errors are proper
|
|
56
|
+
Zuzu objects with methods such as C<keywordLocation()>,
|
|
57
|
+
C<instanceLocation()>, and C<error()>.
|
|
58
|
+
|
|
59
|
+
=head1 EXPORTS
|
|
60
|
+
|
|
61
|
+
=head2 Functions
|
|
62
|
+
|
|
63
|
+
=over
|
|
64
|
+
|
|
65
|
+
=item C<< valid( schema, instance, options := {} ) >>
|
|
66
|
+
|
|
67
|
+
Returns C<true> when C<instance> satisfies C<schema>, otherwise C<false>.
|
|
68
|
+
This mode is the cheapest validation mode and stops as soon as a failure is
|
|
69
|
+
known.
|
|
70
|
+
|
|
71
|
+
=item C<< validate( schema, instance, options := {} ) >>
|
|
72
|
+
|
|
73
|
+
Returns a C<ValidationResult>. This mode attempts to collect every
|
|
74
|
+
independent validation error it can find.
|
|
75
|
+
|
|
76
|
+
=back
|
|
77
|
+
|
|
78
|
+
=head2 Classes
|
|
79
|
+
|
|
80
|
+
=over
|
|
81
|
+
|
|
82
|
+
=item C<JSONSchema>
|
|
83
|
+
|
|
84
|
+
Compiled schema wrapper. Construct with C<< new JSONSchema( schema: ... ) >>
|
|
85
|
+
or pass C<options> as a named field.
|
|
86
|
+
|
|
87
|
+
Common methods:
|
|
88
|
+
|
|
89
|
+
=over
|
|
90
|
+
|
|
91
|
+
=item C<< is_valid( instance ) >>
|
|
92
|
+
|
|
93
|
+
Boolean validation with short-circuiting.
|
|
94
|
+
|
|
95
|
+
=item C<< validate( instance ) >>
|
|
96
|
+
|
|
97
|
+
Full validation returning a C<ValidationResult>.
|
|
98
|
+
|
|
99
|
+
=back
|
|
100
|
+
|
|
101
|
+
=item C<ValidationResult>
|
|
102
|
+
|
|
103
|
+
The structured result returned by C<validate>. C<valid()> returns the boolean
|
|
104
|
+
status. C<errors()> returns an array of C<ValidationError> objects.
|
|
105
|
+
C<to_Dict()> converts to a Basic-style output shape.
|
|
106
|
+
|
|
107
|
+
=item C<ValidationError>
|
|
108
|
+
|
|
109
|
+
Base class for validation errors. The canonical methods are
|
|
110
|
+
C<keywordLocation()>, C<absoluteKeywordLocation()>, C<instanceLocation()>,
|
|
111
|
+
C<error()>, C<keyword()>, C<details()>, and C<to_Dict()>.
|
|
112
|
+
|
|
113
|
+
Errors are grouped under C<MissingValueError>, C<UnexpectedValueError>, and
|
|
114
|
+
C<WrongValueError>. The module exports specific subclasses for individual
|
|
115
|
+
keywords such as C<RequiredPropertyError>, C<TypeMismatchError>,
|
|
116
|
+
C<MaximumError>, C<PatternError>, C<AdditionalPropertiesError>,
|
|
117
|
+
C<OneOfError>, and C<ReferenceResolutionError>.
|
|
118
|
+
|
|
119
|
+
=item C<SubschemaError>
|
|
120
|
+
|
|
121
|
+
Error class used for the message C<A subschema had errors.>. Its
|
|
122
|
+
C<suberrors()> method returns weak links to the errors produced inside the
|
|
123
|
+
subschema.
|
|
124
|
+
|
|
125
|
+
=item C<SchemaRegistry>
|
|
126
|
+
|
|
127
|
+
Registry for schema resources, anchors, and references. It is usually
|
|
128
|
+
managed by C<JSONSchema>, but may be supplied in C<options> when several
|
|
129
|
+
schemas share references.
|
|
130
|
+
|
|
131
|
+
=item C<HTTPResourceLoader>
|
|
132
|
+
|
|
133
|
+
Reference loader for HTTP and HTTPS resources. It is used only when supplied
|
|
134
|
+
directly or when C<allow_network> is true.
|
|
135
|
+
|
|
136
|
+
=item C<FormatRegistry>
|
|
137
|
+
|
|
138
|
+
Registry of C<format> validators. A custom registry may be passed with the
|
|
139
|
+
C<formats> or C<format_registry> option.
|
|
140
|
+
|
|
141
|
+
=item C<RelativeJSONPointer>
|
|
142
|
+
|
|
143
|
+
Parser and evaluator for Relative JSON Pointers. This class is exported
|
|
144
|
+
because JSON Schema uses the syntax for the C<relative-json-pointer> format
|
|
145
|
+
and because it is useful with schema-adjacent data tools.
|
|
146
|
+
|
|
147
|
+
=back
|
|
148
|
+
|
|
149
|
+
=head1 OPTIONS
|
|
150
|
+
|
|
151
|
+
The C<options> value may be a C<Dict> or C<PairList>.
|
|
152
|
+
|
|
153
|
+
=over
|
|
154
|
+
|
|
155
|
+
=item C<base_uri>
|
|
156
|
+
|
|
157
|
+
Base URI used when registering the root schema and resolving relative
|
|
158
|
+
references.
|
|
159
|
+
|
|
160
|
+
=item C<registry>
|
|
161
|
+
|
|
162
|
+
A C<SchemaRegistry> to use for C<$ref> and C<$dynamicRef>.
|
|
163
|
+
|
|
164
|
+
=item C<loader>
|
|
165
|
+
|
|
166
|
+
A callable or object with a C<load(uri)> method used to fetch missing schema
|
|
167
|
+
resources.
|
|
168
|
+
|
|
169
|
+
=item C<allow_network>
|
|
170
|
+
|
|
171
|
+
When true and no loader is supplied, C<JSONSchema> creates an
|
|
172
|
+
C<HTTPResourceLoader>.
|
|
173
|
+
|
|
174
|
+
=item C<formats> or C<format_registry>
|
|
175
|
+
|
|
176
|
+
A C<FormatRegistry> used for C<format> checks.
|
|
177
|
+
|
|
178
|
+
=item C<format_assert>
|
|
179
|
+
|
|
180
|
+
When false, C<format> is treated as an annotation and does not make
|
|
181
|
+
validation fail.
|
|
182
|
+
|
|
183
|
+
=item C<unknown_format>
|
|
184
|
+
|
|
185
|
+
Controls unknown formats. The default is C<fail>; C<ignore> treats unknown
|
|
186
|
+
formats as annotations.
|
|
187
|
+
|
|
188
|
+
=back
|
|
189
|
+
|
|
190
|
+
=head1 KNOWN OPTIONAL FIXTURE GAPS
|
|
191
|
+
|
|
192
|
+
The validator covers all required JSON Schema draft 2020-12 fixture files
|
|
193
|
+
and many optional fixture files. The following optional fixture files are not
|
|
194
|
+
yet promoted to the expected-passing set.
|
|
195
|
+
|
|
196
|
+
=over
|
|
197
|
+
|
|
198
|
+
=item F<optional/cross-draft.json>
|
|
199
|
+
|
|
200
|
+
References into older schema drafts are resolved, but draft-specific
|
|
201
|
+
validation semantics for referenced historic drafts are not yet applied.
|
|
202
|
+
|
|
203
|
+
=item F<optional/float-overflow.json>
|
|
204
|
+
|
|
205
|
+
Very large numeric values still use the host numeric model, so overflow and
|
|
206
|
+
precision edge cases for C<multipleOf> are not fully handled.
|
|
207
|
+
|
|
208
|
+
=item F<optional/ecmascript-regex.json>
|
|
209
|
+
|
|
210
|
+
The JavaScript runtime passes this fixture, but the Perl and Rust runtimes do
|
|
211
|
+
not yet emulate enough ECMAScript regular-expression semantics.
|
|
212
|
+
|
|
213
|
+
=item F<optional/format/duration.json>
|
|
214
|
+
|
|
215
|
+
The C<duration> format checker accepts basic duration shapes, but does not
|
|
216
|
+
yet implement the full RFC 3339 duration grammar.
|
|
217
|
+
|
|
218
|
+
=item F<optional/format/hostname.json>
|
|
219
|
+
|
|
220
|
+
Hostname validation is intentionally conservative and does not yet fully
|
|
221
|
+
validate A-label, Punycode, and IDNA edge cases.
|
|
222
|
+
|
|
223
|
+
=item F<optional/format/idn-hostname.json>
|
|
224
|
+
|
|
225
|
+
Internationalized hostname validation does not yet implement the full IDNA
|
|
226
|
+
Unicode category, normalization, and bidirectional-text rules.
|
|
227
|
+
|
|
228
|
+
=item F<optional/format/ipv6.json>
|
|
229
|
+
|
|
230
|
+
IPv6 validation is still simplified and misses some invalid compression and
|
|
231
|
+
group-length edge cases.
|
|
232
|
+
|
|
233
|
+
=item F<optional/format/time.json>
|
|
234
|
+
|
|
235
|
+
Time validation handles common RFC 3339 forms, but still has some leap-second
|
|
236
|
+
and timezone-offset edge cases.
|
|
237
|
+
|
|
238
|
+
=item F<optional/format/uri.json>
|
|
239
|
+
|
|
240
|
+
URI validation is stricter than a plain string check, but still accepts some
|
|
241
|
+
invalid authority, userinfo, character, and port cases.
|
|
242
|
+
|
|
243
|
+
=back
|
|
244
|
+
|
|
245
|
+
=head1 PORTABILITY
|
|
246
|
+
|
|
247
|
+
The module is pure ZuzuScript. Behaviour that depends on regular expression
|
|
248
|
+
details or HTTP support may vary with the host runtime.
|
|
249
|
+
|
|
250
|
+
=head1 COPYRIGHT AND LICENCE
|
|
251
|
+
|
|
252
|
+
B<< std/data/json/schema >> is copyright Toby Inkster.
|
|
253
|
+
|
|
254
|
+
It is free software; you may redistribute it and/or modify it under
|
|
255
|
+
the terms of either the Artistic License 1.0 or the GNU General Public
|
|
256
|
+
License version 2.
|
|
257
|
+
|
|
258
|
+
=cut
|
|
259
|
+
|
|
260
|
+
from std/data/json/schema/core import HTTPResourceLoader, SchemaRegistry;
|
|
261
|
+
from std/data/json/schema/format import FormatRegistry;
|
|
262
|
+
from std/data/json/schema/output import
|
|
263
|
+
AdditionalItemsError,
|
|
264
|
+
AdditionalPropertiesError,
|
|
265
|
+
AllOfError,
|
|
266
|
+
AnyOfError,
|
|
267
|
+
ConstMismatchError,
|
|
268
|
+
ContentEncodingError,
|
|
269
|
+
ContentMediaTypeError,
|
|
270
|
+
DependentRequiredPropertyError,
|
|
271
|
+
EnumMismatchError,
|
|
272
|
+
ExclusiveMaximumError,
|
|
273
|
+
ExclusiveMinimumError,
|
|
274
|
+
FalseSchemaError,
|
|
275
|
+
FormatError,
|
|
276
|
+
IfThenElseError,
|
|
277
|
+
MaxContainsError,
|
|
278
|
+
MaximumError,
|
|
279
|
+
MaxItemsError,
|
|
280
|
+
MaxLengthError,
|
|
281
|
+
MaxPropertiesError,
|
|
282
|
+
MinContainsError,
|
|
283
|
+
MinimumError,
|
|
284
|
+
MinItemsError,
|
|
285
|
+
MinLengthError,
|
|
286
|
+
MinPropertiesError,
|
|
287
|
+
MissingValueError,
|
|
288
|
+
MultipleOfError,
|
|
289
|
+
NotMatchedError,
|
|
290
|
+
OneOfError,
|
|
291
|
+
PatternError,
|
|
292
|
+
PropertyNamesError,
|
|
293
|
+
ReferenceResolutionError,
|
|
294
|
+
RequiredPropertyError,
|
|
295
|
+
SubschemaError,
|
|
296
|
+
TypeMismatchError,
|
|
297
|
+
UnevaluatedItemsError,
|
|
298
|
+
UnevaluatedPropertiesError,
|
|
299
|
+
UnexpectedValueError,
|
|
300
|
+
UniqueItemsError,
|
|
301
|
+
UnknownFormatError,
|
|
302
|
+
ValidationError,
|
|
303
|
+
ValidationResult,
|
|
304
|
+
WrongValueError;
|
|
305
|
+
from std/data/json/schema/relative_pointer import RelativeJSONPointer;
|
|
306
|
+
from std/data/json/schema/validation import JSONSchema, validate, valid;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
=encoding utf8
|
|
2
|
+
|
|
3
|
+
=head1 NAME
|
|
4
|
+
|
|
5
|
+
std/data/json - JSON encoding and decoding for ZuzuScript.
|
|
6
|
+
|
|
7
|
+
=head1 SYNOPSIS
|
|
8
|
+
|
|
9
|
+
from std/data/json import JSON;
|
|
10
|
+
|
|
11
|
+
let codec := new JSON( pretty: true );
|
|
12
|
+
let text := codec.encode({ answer: 42 });
|
|
13
|
+
let data := codec.decode(text);
|
|
14
|
+
|
|
15
|
+
=head1 IMPLEMENTATION SUPPORT
|
|
16
|
+
|
|
17
|
+
This module is supported by zuzu.pl, zuzu-rust, and zuzu-js on Node and
|
|
18
|
+
Electron. It is partially supported by zuzu-js in the browser: in-memory
|
|
19
|
+
JSON encode/decode coverage passes, but file-backed load/dump coverage is
|
|
20
|
+
unsupported because browser filesystem capability is unavailable.
|
|
21
|
+
|
|
22
|
+
=head1 DESCRIPTION
|
|
23
|
+
|
|
24
|
+
This module provides a C<JSON> class for turning ZuzuScript values
|
|
25
|
+
into JSON text and parsing JSON text back into ZuzuScript values.
|
|
26
|
+
|
|
27
|
+
=head1 EXPORTS
|
|
28
|
+
|
|
29
|
+
=head2 Classes
|
|
30
|
+
|
|
31
|
+
=over
|
|
32
|
+
|
|
33
|
+
=item C<< JSON({ utf8?: Bool, pretty?: Bool, canonical?: Bool }) >>
|
|
34
|
+
|
|
35
|
+
Constructs a JSON codec. Returns: C<JSON>.
|
|
36
|
+
|
|
37
|
+
The constructor accepts named options:
|
|
38
|
+
|
|
39
|
+
=over
|
|
40
|
+
|
|
41
|
+
=item * C<utf8>
|
|
42
|
+
|
|
43
|
+
Accepted for compatibility with older runtime implementations. Use
|
|
44
|
+
C<encode_binarystring> when UTF-8 bytes are required.
|
|
45
|
+
|
|
46
|
+
=item * C<pretty> (default false)
|
|
47
|
+
|
|
48
|
+
Pretty-print the JSON output.
|
|
49
|
+
|
|
50
|
+
=item * C<canonical> (default false)
|
|
51
|
+
|
|
52
|
+
Sort keys in objects while encoding.
|
|
53
|
+
|
|
54
|
+
=item * C<pairlists> (default false)
|
|
55
|
+
|
|
56
|
+
Decode JSON objects as PairLists instead of Dicts.
|
|
57
|
+
|
|
58
|
+
(PairLists will always be encoded into JSON properly; this only affects
|
|
59
|
+
decoding.)
|
|
60
|
+
|
|
61
|
+
=back
|
|
62
|
+
|
|
63
|
+
=item C<< codec.encode(value) >>
|
|
64
|
+
|
|
65
|
+
Parameters: C<value> is any JSON-encodable ZuzuScript value. Returns:
|
|
66
|
+
C<String>. Encodes C<value> as JSON text.
|
|
67
|
+
|
|
68
|
+
=item C<< codec.encode_binarystring(value) >>
|
|
69
|
+
|
|
70
|
+
Parameters: C<value> is any JSON-encodable ZuzuScript value. Returns:
|
|
71
|
+
C<BinaryString>. Encodes C<value> as UTF-8 JSON bytes.
|
|
72
|
+
|
|
73
|
+
=item C<< codec.decode(String json) >>
|
|
74
|
+
|
|
75
|
+
Parameters: C<json> is JSON text. Returns: value. Decodes JSON into the
|
|
76
|
+
equivalent ZuzuScript value.
|
|
77
|
+
|
|
78
|
+
=item C<< codec.decode_binarystring(BinaryString json) >>
|
|
79
|
+
|
|
80
|
+
Parameters: C<json> is UTF-8 JSON bytes. Returns: value. Decodes JSON
|
|
81
|
+
into the equivalent ZuzuScript value.
|
|
82
|
+
|
|
83
|
+
=item C<< codec.load(Path path) >>
|
|
84
|
+
|
|
85
|
+
Parameters: C<path> is a C<std/io> C<Path>. Returns: value. Reads JSON
|
|
86
|
+
text from C<path> and decodes it.
|
|
87
|
+
|
|
88
|
+
=item C<< codec.dump(Path path, value) >>
|
|
89
|
+
|
|
90
|
+
Parameters: C<path> is a C<std/io> C<Path> and C<value> is any
|
|
91
|
+
JSON-encodable value. Returns: C<null>. Encodes C<value> and writes JSON
|
|
92
|
+
text to C<path>.
|
|
93
|
+
|
|
94
|
+
=back
|
|
95
|
+
|
|
96
|
+
=head1 COPYRIGHT AND LICENCE
|
|
97
|
+
|
|
98
|
+
B<< std/data/json >> is copyright Toby Inkster.
|
|
99
|
+
|
|
100
|
+
It is free software; you may redistribute it and/or modify it under
|
|
101
|
+
the terms of either the Artistic License 1.0 or the GNU General Public
|
|
102
|
+
License version 2.
|