@hyperjump/json-schema 1.6.0 → 1.6.2

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 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<OutputUnit>
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<(instance: any, outputFormat: OutputFormat = FLAG) => OutputUnit>
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<SchemaObject>
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<A>
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<number> | false
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<SchemaDocument>
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<SchemaDocument>
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<SchemaDocument>
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<SchemaDocument>
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<[string, SchemaDocument]>
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<SchemaDocument>
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<string>
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<InstanceDocument>
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<[string, InstanceDocument]>
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<InstanceDocument>
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<string>
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<AnnotatedInstance>
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**: (schema: SchemaDocument) => Promise<CompiledSchema>
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.
@@ -5,16 +5,17 @@ const id = "https://json-schema.org/keyword/draft-2019-09/recursiveRef";
5
5
 
6
6
  const compile = (schema) => schema.id;
7
7
 
8
- const interpret = (id, instance, ast, dynamicAnchors, quiet) => {
8
+ const evaluate = (strategy) => (id, instance, ast, dynamicAnchors, quiet) => {
9
9
  if ("" in ast.metaData[id].dynamicAnchors) {
10
10
  dynamicAnchors = { ...ast.metaData[id].dynamicAnchors, ...dynamicAnchors };
11
- return Validation.interpret(dynamicAnchors[""], instance, ast, dynamicAnchors, quiet);
11
+ return strategy(dynamicAnchors[""], instance, ast, dynamicAnchors, quiet);
12
12
  } else {
13
- return Validation.interpret(`${id}#`, instance, ast, dynamicAnchors, quiet);
13
+ return strategy(`${id}#`, instance, ast, dynamicAnchors, quiet);
14
14
  }
15
15
  };
16
16
 
17
- const collectEvaluatedProperties = Validation.collectEvaluatedProperties;
18
- const collectEvaluatedItems = Validation.collectEvaluatedItems;
17
+ const interpret = evaluate(Validation.interpret);
18
+ const collectEvaluatedProperties = evaluate(Validation.collectEvaluatedProperties);
19
+ const collectEvaluatedItems = evaluate(Validation.collectEvaluatedItems);
19
20
 
20
21
  export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
@@ -12,16 +12,17 @@ const compile = async (dynamicRef, ast) => {
12
12
  return [referencedSchema.id, fragment, Schema.uri(referencedSchema)];
13
13
  };
14
14
 
15
- const interpret = ([id, fragment, ref], instance, ast, dynamicAnchors, quiet) => {
15
+ const evaluate = (strategy) => ([id, fragment, ref], instance, ast, dynamicAnchors, quiet) => {
16
16
  if (fragment in ast.metaData[id].dynamicAnchors) {
17
17
  dynamicAnchors = { ...ast.metaData[id].dynamicAnchors, ...dynamicAnchors };
18
- return Validation.interpret(dynamicAnchors[fragment], instance, ast, dynamicAnchors, quiet);
18
+ return strategy(dynamicAnchors[fragment], instance, ast, dynamicAnchors, quiet);
19
19
  } else {
20
- return Validation.interpret(ref, instance, ast, dynamicAnchors, quiet);
20
+ return strategy(ref, instance, ast, dynamicAnchors, quiet);
21
21
  }
22
22
  };
23
23
 
24
- const collectEvaluatedProperties = Validation.collectEvaluatedProperties;
25
- const collectEvaluatedItems = Validation.collectEvaluatedItems;
24
+ const interpret = evaluate(Validation.interpret);
25
+ const collectEvaluatedProperties = evaluate(Validation.collectEvaluatedProperties);
26
+ const collectEvaluatedItems = evaluate(Validation.collectEvaluatedItems);
26
27
 
27
28
  export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
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
- return { ...instance, pointer: url.substr(1) };
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)}`;
@@ -7,14 +7,15 @@ const experimental = true;
7
7
 
8
8
  const compile = Schema.value;
9
9
 
10
- const interpret = (fragment, instance, ast, dynamicAnchors, quiet) => {
10
+ const evaluate = (strategy) => (fragment, instance, ast, dynamicAnchors, quiet) => {
11
11
  if (!(fragment in dynamicAnchors)) {
12
12
  throw Error(`No dynamic anchor found for "${fragment}"`);
13
13
  }
14
- return Validation.interpret(dynamicAnchors[fragment], instance, ast, dynamicAnchors, quiet);
14
+ return strategy(dynamicAnchors[fragment], instance, ast, dynamicAnchors, quiet);
15
15
  };
16
16
 
17
- const collectEvaluatedProperties = Validation.collectEvaluatedProperties;
18
- const collectEvaluatedItems = Validation.collectEvaluatedItems;
17
+ const interpret = evaluate(Validation.interpret);
18
+ const collectEvaluatedProperties = evaluate(Validation.collectEvaluatedProperties);
19
+ const collectEvaluatedItems = evaluate(Validation.collectEvaluatedItems);
19
20
 
20
21
  export default { id, experimental, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperjump/json-schema",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
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",
@@ -53,7 +53,7 @@
53
53
  "devDependencies": {
54
54
  "@types/chai": "*",
55
55
  "@types/mocha": "*",
56
- "@types/node": "^20.6.2",
56
+ "@types/node": "*",
57
57
  "@typescript-eslint/eslint-plugin": "*",
58
58
  "@typescript-eslint/parser": "*",
59
59
  "chai": "*",