@hyperjump/json-schema 1.6.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -18
- package/lib/instance.js +7 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -194,11 +194,11 @@ Schema, such as `@hyperjump/json-schema/draft-2020-12`.
|
|
|
194
194
|
|
|
195
195
|
Load a schema manually rather than fetching it from the filesystem or over
|
|
196
196
|
the network.
|
|
197
|
-
* **validate**: (schemaURI: string, instance: any, outputFormat: OutputFormat = FLAG) => Promise
|
|
197
|
+
* **validate**: (schemaURI: string, instance: any, outputFormat: OutputFormat = * FLAG) => Promise\<OutputUnit>
|
|
198
198
|
|
|
199
199
|
Validate an instance against a schema. This function is curried to allow
|
|
200
200
|
compiling the schema once and applying it to multiple instances.
|
|
201
|
-
* **validate**: (schemaURI: string) => Promise
|
|
201
|
+
* **validate**: (schemaURI: string) => Promise\<(instance: any, outputFormat: OutputFormat = FLAG) => OutputUnit>
|
|
202
202
|
|
|
203
203
|
Compiling a schema to a validation function.
|
|
204
204
|
* **FLAG**: "FLAG"
|
|
@@ -313,7 +313,7 @@ const bundledSchema = await bundle("https://example.com/main"); // {
|
|
|
313
313
|
### API
|
|
314
314
|
These are available from the `@hyperjump/json-schema/bundle` export.
|
|
315
315
|
|
|
316
|
-
* **bundle**: (uri: string, options: Options) => Promise
|
|
316
|
+
* **bundle**: (uri: string, options: Options) => Promise\<SchemaObject>
|
|
317
317
|
|
|
318
318
|
Create a bundled schema starting with the given schema. External schemas
|
|
319
319
|
will be fetched from the filesystem, the network, or internally as needed.
|
|
@@ -533,7 +533,7 @@ These are available from the `@hyperjump/json-schema/experimental` export.
|
|
|
533
533
|
|
|
534
534
|
A URI that uniquely identifies the keyword. It should use a domain you
|
|
535
535
|
own to avoid conflict with keywords defined by others.
|
|
536
|
-
* compile: (schema: SchemaDocument, ast: AST, parentSchema: SchemaDocument) => Promise
|
|
536
|
+
* compile: (schema: SchemaDocument, ast: AST, parentSchema: SchemaDocument) * => Promise\<A>
|
|
537
537
|
|
|
538
538
|
This function takes the keyword value, does whatever preprocessing it
|
|
539
539
|
can on it without an instance, and returns the result. The returned
|
|
@@ -551,7 +551,7 @@ These are available from the `@hyperjump/json-schema/experimental` export.
|
|
|
551
551
|
|
|
552
552
|
If the keyword is an applicator, it will need to implements this
|
|
553
553
|
function for `unevaluatedProperties` to work as expected.
|
|
554
|
-
* collectEvaluatedItems?: (compiledKeywordValue: A, instance: JsonDocument, ast: AST, dynamicAnchors: Anchors) => Set
|
|
554
|
+
* collectEvaluatedItems?: (compiledKeywordValue: A, instance: JsonDocument, * ast: AST, dynamicAnchors: Anchors) => Set\<number> | false
|
|
555
555
|
|
|
556
556
|
If the keyword is an applicator, it will need to implements this
|
|
557
557
|
function for `unevaluatedItems` to work as expected.
|
|
@@ -567,7 +567,7 @@ set of functions for working with SchemaDocuments.
|
|
|
567
567
|
* **Schema.add**: (schema: object, retrievalUri?: string, dialectId?: string) => string
|
|
568
568
|
|
|
569
569
|
Load a schema. Returns the identifier for the schema.
|
|
570
|
-
* **Schema.get**: (url: string, contextDoc?: SchemaDocument) => Promise
|
|
570
|
+
* **Schema.get**: (url: string, contextDoc?: SchemaDocument) => Promise\<SchemaDocument>
|
|
571
571
|
|
|
572
572
|
Fetch a schema. Schemas can come from an HTTP request, a file, or a schema
|
|
573
573
|
that was added with `Schema.add`.
|
|
@@ -580,22 +580,22 @@ set of functions for working with SchemaDocuments.
|
|
|
580
580
|
* **Schema.typeOf**: (doc: SchemaDocument, type: string) => boolean
|
|
581
581
|
|
|
582
582
|
Determines if the JSON type of the given doc matches the given type.
|
|
583
|
-
* **Schema.has**: (key: string, doc: SchemaDocument) => Promise
|
|
583
|
+
* **Schema.has**: (key: string, doc: SchemaDocument) => Promise\<SchemaDocument>
|
|
584
584
|
|
|
585
585
|
Similar to `key in schema`.
|
|
586
|
-
* **Schema.step**: (key: string, doc: SchemaDocument) => Promise
|
|
586
|
+
* **Schema.step**: (key: string, doc: SchemaDocument) => Promise\<SchemaDocument>
|
|
587
587
|
|
|
588
588
|
Similar to `schema[key]`, but returns an SchemaDocument.
|
|
589
|
-
* **Schema.iter**: (doc: SchemaDocument) => AsyncGenerator
|
|
589
|
+
* **Schema.iter**: (doc: SchemaDocument) => AsyncGenerator\<SchemaDocument>
|
|
590
590
|
|
|
591
591
|
Iterate over the items in the array that the SchemaDocument represents
|
|
592
|
-
* **Schema.entries**: (doc: SchemaDocument) => AsyncGenerator
|
|
592
|
+
* **Schema.entries**: (doc: SchemaDocument) => AsyncGenerator\<[string, SchemaDocument]>
|
|
593
593
|
|
|
594
594
|
Similar to `Object.entries`, but yields SchemaDocuments for values.
|
|
595
|
-
* **Schema.values**: (doc: SchemaDocument) => AsyncGenerator
|
|
595
|
+
* **Schema.values**: (doc: SchemaDocument) => AsyncGenerator\<SchemaDocument>
|
|
596
596
|
|
|
597
597
|
Similar to `Object.values`, but yields SchemaDocuments for values.
|
|
598
|
-
* **Schema.keys**: (doc: SchemaDocument) => Generator
|
|
598
|
+
* **Schema.keys**: (doc: SchemaDocument) => Generator\<string>
|
|
599
599
|
|
|
600
600
|
Similar to `Object.keys`.
|
|
601
601
|
* **Schema.length**: (doc: SchemaDocument) => number
|
|
@@ -647,16 +647,16 @@ set of functions for working with InstanceDocuments.
|
|
|
647
647
|
* **Instance.step**: (key: string, doc: InstanceDocument) => InstanceDocument
|
|
648
648
|
|
|
649
649
|
Similar to `schema[key]`, but returns a InstanceDocument.
|
|
650
|
-
* **Instance.iter**: (doc: InstanceDocument) => Generator
|
|
650
|
+
* **Instance.iter**: (doc: InstanceDocument) => Generator\<InstanceDocument>
|
|
651
651
|
|
|
652
652
|
Iterate over the items in the array that the SchemaDocument represents.
|
|
653
|
-
* **Instance.entries**: (doc: InstanceDocument) => Generator
|
|
653
|
+
* **Instance.entries**: (doc: InstanceDocument) => Generator\<[string, InstanceDocument]>
|
|
654
654
|
|
|
655
655
|
Similar to `Object.entries`, but yields InstanceDocuments for values.
|
|
656
|
-
* **Instance.values**: (doc: InstanceDocument) => Generator
|
|
656
|
+
* **Instance.values**: (doc: InstanceDocument) => Generator\<InstanceDocument>
|
|
657
657
|
|
|
658
658
|
Similar to `Object.values`, but yields InstanceDocuments for values.
|
|
659
|
-
* **Instance.keys**: (doc: InstanceDocument) => Generator
|
|
659
|
+
* **Instance.keys**: (doc: InstanceDocument) => Generator\<string>
|
|
660
660
|
|
|
661
661
|
Similar to `Object.keys`.
|
|
662
662
|
* **Instance.length**: (doc: InstanceDocument) => number
|
|
@@ -743,7 +743,7 @@ for (const deprecated of AnnotatedInstance.annotatedWith(instance, "deprecated",
|
|
|
743
743
|
These are available from the `@hyperjump/json-schema/annotations/experimental`
|
|
744
744
|
export.
|
|
745
745
|
|
|
746
|
-
* **annotate**: (schemaUri: string, instance: any, outputFormat: OutputFormat = FLAG) => Promise
|
|
746
|
+
* **annotate**: (schemaUri: string, instance: any, outputFormat: OutputFormat = * FLAG) => Promise\<AnnotatedInstance>
|
|
747
747
|
|
|
748
748
|
Annotate an instance using the given schema. The function is curried to
|
|
749
749
|
allow compiling the schema once and applying it to multiple instances. This
|
|
@@ -777,7 +777,7 @@ following functions are available in addition to the functions available in the
|
|
|
777
777
|
### API
|
|
778
778
|
These are available from the `@hyperjump/json-schema/experimental` export.
|
|
779
779
|
|
|
780
|
-
* **compile**: (
|
|
780
|
+
* **compile**: (schemaUri: string) => Promise\<CompiledSchema>
|
|
781
781
|
|
|
782
782
|
Return a compiled schema. This is useful if you're creating tooling for
|
|
783
783
|
something other than validation.
|
package/lib/instance.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { append as pointerAppend } from "@hyperjump/json-pointer";
|
|
1
|
+
import { append as pointerAppend, get as pointerGet } from "@hyperjump/json-pointer";
|
|
2
2
|
import { toAbsoluteIri } from "@hyperjump/uri";
|
|
3
3
|
import curry from "just-curry-it";
|
|
4
4
|
import { jsonTypeOf } from "./common.js";
|
|
@@ -18,7 +18,12 @@ export const get = (url, instance = nil) => {
|
|
|
18
18
|
throw Error(`No JSON document found at '${url.split("#")[0]}'`);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const pointer = url.substr(1);
|
|
22
|
+
return {
|
|
23
|
+
...instance,
|
|
24
|
+
pointer: pointer,
|
|
25
|
+
value: pointerGet(pointer, instance.instance)
|
|
26
|
+
};
|
|
22
27
|
};
|
|
23
28
|
|
|
24
29
|
export const uri = (doc) => `${doc.id || ""}#${encodeURI(doc.pointer)}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperjump/json-schema",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "A JSON Schema validator with support for custom keywords, vocabularies, and dialects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./stable/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"clean": "xargs -a .gitignore rm -rf",
|
|
29
|
-
"lint": "eslint lib stable draft-* openapi-*",
|
|
29
|
+
"lint": "eslint lib stable draft-* openapi-* bundle annotations",
|
|
30
30
|
"test": "mocha 'lib/**/*.spec.ts' 'stable/**/*.spec.ts' 'draft-*/**/*.spec.ts' 'openapi-*/**/*.spec.ts' 'bundle/**/*.spec.ts' 'annotations/**/*.spec.ts'"
|
|
31
31
|
},
|
|
32
32
|
"repository": "github:hyperjump-io/json-schema",
|