Skip to content

Commit

Permalink
Merge pull request #29 from jg-rp/update-typedoc
Browse files Browse the repository at this point in the history
docs: update typedoc
  • Loading branch information
jg-rp authored Dec 11, 2024
2 parents 2a11ebc + 99c43ba commit 36fde9a
Show file tree
Hide file tree
Showing 11 changed files with 360 additions and 352 deletions.
8 changes: 4 additions & 4 deletions docs/docs/README_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Welcome to the API documentation for JSON P3. Also see the [quick start guide](/

## API Quick Links

- [JSONPathEnvironment](/api/classes/jsonpath.JSONPathEnvironment)
- [JSONPathEnvironment Options](/api/namespaces/jsonpath#jsonpathenvironmentoptions)
- [JSONPathNodeList](/api/classes/jsonpath.JSONPathNodeList)
- [JSONPathNode](/api/classes/jsonpath.JSONPathNode)
- [JSONPathEnvironment](/api/namespaces/jsonpath/classes/JSONPathEnvironment)
- [JSONPathEnvironment Options](/api/namespaces/jsonpath/type-aliases/JSONPathEnvironmentOptions)
- [JSONPathNodeList](/api/namespaces/jsonpath/classes/JSONPathNodeList)
- [JSONPathNode](/api/namespaces/jsonpath/classes/JSONPathNode)
18 changes: 9 additions & 9 deletions docs/docs/guides/json-patch.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

JSON Patch ([RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902)) is a standard for describing update operations to perform on JSON-like data. Each operation includes, at least, an `op` string and a `path`, which is a [JSON Pointer](./json-pointer.md).

Use [`jsonpatch.apply(ops, data)`](../api/namespaces/jsonpatch.md#apply) to apply _ops_ to _data_, where _ops_ should be an array of [`OpObject`s](../api/namespaces/jsonpatch.md#opobject), as per RFC 6902. Patch operation are applied sequentially and, unless the target JSON document's root value is replaced, **data is modified in place**.
Use [`jsonpatch.apply(ops, data)`](../api/namespaces/jsonpatch/functions/apply.md) to apply _ops_ to _data_, where _ops_ should be an array of [`OpObject`s](../api/namespaces/jsonpatch/type-aliases/OpObject.md), as per RFC 6902. Patch operation are applied sequentially and, unless the target JSON document's root value is replaced, **data is modified in place**.

```javascript
import { jsonpatch } from "json-p3";
Expand All @@ -20,7 +20,7 @@ console.log(data);
// { some: { other: 'thing', foo: { bar: [Array], else: 'thing' } } }
```

Use the [`JSONPatch`](../api/classes/jsonpatch.JSONPatch.md) constructor to create a patch for repeated application.
Use the [`JSONPatch`](../api/namespaces/jsonpatch/classes/JSONPatch.md) constructor to create a patch for repeated application.

```javascript
import { JSONPatch } from "json-p3";
Expand All @@ -40,11 +40,11 @@ console.log(data);

## Builder API

[`JSONPatch`](../api/classes/jsonpatch.JSONPatch.md) implements a builder interface for constructing JSON Patch documents. Each of the following methods appends an operation to the patch and returns the patch instance, so method calls can be chained.
[`JSONPatch`](../api/namespaces/jsonpatch/classes/JSONPatch.md) implements a builder interface for constructing JSON Patch documents. Each of the following methods appends an operation to the patch and returns the patch instance, so method calls can be chained.

### `add()`

[`JSONPatch.add(pointer, value)`](../api/classes/jsonpatch.JSONPatch.md#add) appends an [_add_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.1) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/classes/jsonpointer.JSONPointer.md).
[`JSONPatch.add(pointer, value)`](../api/namespaces/jsonpatch/classes/JSONPatch.md#add) appends an [_add_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.1) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/namespaces/jsonpointer/classes/JSONPointer.md).

```javascript
import { JSONPatch } from "json-p3";
Expand All @@ -67,7 +67,7 @@ console.log(JSON.stringify(patch.toArray(), undefined, " "));

### `remove()`

[`JSONPatch.remove(pointer)`](../api/classes/jsonpatch.JSONPatch.md#add) appends an [_remove_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.2) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/classes/jsonpointer.JSONPointer.md).
[`JSONPatch.remove(pointer)`](../api/namespaces/jsonpatch/classes/JSONPatch.md#remove) appends a [_remove_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.2) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/namespaces/jsonpointer/classes/JSONPointer.md).

```javascript
import { JSONPatch } from "json-p3";
Expand All @@ -87,7 +87,7 @@ console.log(JSON.stringify(patch.toArray(), undefined, " "));

### `replace()`

[`JSONPatch.replace(pointer, value)`](../api/classes/jsonpatch.JSONPatch.md#add) appends an [_replace_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.3) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/classes/jsonpointer.JSONPointer.md).
[`JSONPatch.replace(pointer, value)`](../api/namespaces/jsonpatch/classes/JSONPatch.md#replace) appends a [_replace_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.3) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/namespaces/jsonpointer/classes/JSONPointer.md).

```javascript
import { JSONPatch } from "json-p3";
Expand All @@ -108,7 +108,7 @@ console.log(JSON.stringify(patch.toArray(), undefined, " "));

### `move()`

[`JSONPatch.move(fromPointer, toPointer)`](../api/classes/jsonpatch.JSONPatch.md#add) appends an [_move_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.4) operation to the patch. _fromPointer_ and _toPointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/classes/jsonpointer.JSONPointer.md).
[`JSONPatch.move(fromPointer, toPointer)`](../api/namespaces/jsonpatch/classes/JSONPatch.md#move) appends a [_move_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.4) operation to the patch. _fromPointer_ and _toPointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/namespaces/jsonpointer/classes/JSONPointer.md).

```javascript
import { JSONPatch } from "json-p3";
Expand All @@ -129,7 +129,7 @@ console.log(JSON.stringify(patch.toArray(), undefined, " "));

### `copy()`

[`JSONPatch.copy(fromPointer, toPointer)`](../api/classes/jsonpatch.JSONPatch.md#add) appends an [_copy_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.5) operation to the patch. _fromPointer_ and _toPointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/classes/jsonpointer.JSONPointer.md).
[`JSONPatch.copy(fromPointer, toPointer)`](../api/namespaces/jsonpatch/classes/JSONPatch.md#copy) appends a [_copy_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.5) operation to the patch. _fromPointer_ and _toPointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/namespaces/jsonpointer/classes/JSONPointer.md).

```javascript
import { JSONPatch } from "json-p3";
Expand All @@ -150,7 +150,7 @@ console.log(JSON.stringify(patch.toArray(), undefined, " "));

### `test()`

[`JSONPatch.copy(pointer, value)`](../api/classes/jsonpatch.JSONPatch.md#add) appends an [_test_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.6) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/classes/jsonpointer.JSONPointer.md).
[`JSONPatch.copy(pointer, value)`](../api/namespaces/jsonpatch/classes/JSONPatch.md#test) appends a [_test_](https://datatracker.ietf.org/doc/html/rfc6902#section-4.6) operation to the patch. _pointer_ can be a string following RFC 6901 or an instance of [`JSONPointer`](../api/namespaces/jsonpointer/classes/JSONPointer.md).

```javascript
import { JSONPatch } from "json-p3";
Expand Down
22 changes: 11 additions & 11 deletions docs/docs/guides/json-pointer.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ We have extended RFC 6901 to handle index/property pointers from [Relative JSON

## Pointer resolution

Resolve a JSON Pointer against some data using [`jsonpointer.resolve(pointer, data)`](../api/namespaces/jsonpointer.md#resolve).
Resolve a JSON Pointer against some data using [`jsonpointer.resolve(pointer, data)`](../api/namespaces/jsonpointer/classes/JSONPointer#resolve).

```javascript
import { jsonpointer } from "json-p3";
Expand All @@ -28,7 +28,7 @@ const rv = jsonpointer.resolve("/users/1", data);
console.log(rv); // { name: 'John', score: 86 }
```

`resolve()` is a convenience function equivalent to `new JSONPointer(pointer).resolve(data)`. Use the [`JSONPointer`](../api/classes/jsonpointer.JSONPointer.md) constructor when you need to resolve the same pointer repeatedly against different data.
`resolve()` is a convenience function equivalent to `new JSONPointer(pointer).resolve(data)`. Use the [`JSONPointer`](../api/namespaces/jsonpointer/classes/JSONPointer.md) constructor when you need to resolve the same pointer repeatedly against different data.

```javascript
import { JSONPointer } from "json-p3";
Expand All @@ -52,7 +52,7 @@ console.log(pointer.resolve(otherData)); // { name: 'Roy' }

### Errors and fallbacks

If the pointer can't be resolved against the argument JSON value, one of [`JSONPointerIndexError`](../api/classes/jsonpointer.JSONPointerIndexError.md), [`JSONPointerKeyError`](../api/classes/jsonpointer.JSONPointerKeyError.md) or [`JSONPointerTypeError`](../api/classes/jsonpointer.JSONPointerTypeError.md) is thrown. All three exceptions inherit from [`JSONPointerResolutionError`](../api/classes/jsonpointer.JSONPointerResolutionError.md).
If the pointer can't be resolved against the argument JSON value, one of [`JSONPointerIndexError`](../api/namespaces/jsonpointer/classes/JSONPointerIndexError.md), [`JSONPointerKeyError`](../api/namespaces/jsonpointer/classes/JSONPointerKeyError.md) or [`JSONPointerTypeError`](../api/namespaces/jsonpointer/classes/JSONPointerTypeError.md) is thrown. All three exceptions inherit from [`JSONPointerResolutionError`](../api/namespaces/jsonpointer/classes/JSONPointerResolutionError.md).

```javascript
// .. continued from above
Expand All @@ -70,7 +70,7 @@ console.log(rv); // -1

### With parent

[`resolveWithParent()`](../api/classes/jsonpointer.JSONPointer.md#resolvewithparent) is similar to `resolve()`, but returns the target's parent value and the target value as a two-element array.
[`resolveWithParent()`](../api/namespaces/jsonpointer/classes/JSONPointer.md#resolvewithparent) is similar to `resolve()`, but returns the target's parent value and the target value as a two-element array.

```javascript
import { JSONPointer } from "json-p3";
Expand All @@ -87,15 +87,15 @@ const pointer = new JSONPointer("/users/1");
const [parent, target] = pointer.resolveWithParent(data);
```

If the target value does not exist but the parent does, you'll get the parent object and the special [`UNDEFINED`](../api/namespaces/jsonpointer.md#undefined) symbol. Similarly, if the pointer is pointing to the JSON document root, you'll get `UNDEFINED` and the target document in its entirety.
If the target value does not exist but the parent does, you'll get the parent object and the special [`UNDEFINED`](../api/namespaces/jsonpointer/variables/UNDEFINED.md) symbol. Similarly, if the pointer is pointing to the JSON document root, you'll get `UNDEFINED` and the target document in its entirety.

Otherwise, if the pointer's parent does not exist, a [`JSONPointerResolutionError`](../api/classes/jsonpointer.JSONPointerResolutionError.md) is thrown.
Otherwise, if the pointer's parent does not exist, a [`JSONPointerResolutionError`](../api/namespaces/jsonpointer/classes/JSONPointerResolutionError.md) is thrown.

## Utility methods

### `exists()`

Test for existence with [`JSONPointer.exists(data)`](../api/classes/jsonpointer.JSONPointer.md#exists). It returns `true` if the target exists in _data_, even if the target is falsy, and `false` otherwise.
Test for existence with [`JSONPointer.exists(data)`](../api/namespaces/jsonpointer/classes/JSONPointer.md#exists). It returns `true` if the target exists in _data_, even if the target is falsy, and `false` otherwise.

```javascript
import { JSONPointer } from "json-p3";
Expand All @@ -114,7 +114,7 @@ console.log(pointer.exists(data)); // true

### `join()`

Build child pointers using [`JSONPointer.join(...tokens)`](../api/classes/jsonpointer.JSONPointer.md#join). It takes any number of JSON Pointer tokens and returns a new `JSONPointer`. Similar to joining a file system path, if a token has a leading slash, the previous pointer is ignored and a new `JSONPointer` is created, before processing of remaining tokens continues.
Build child pointers using [`JSONPointer.join(...tokens)`](../api/namespaces/jsonpointer/classes/JSONPointer.md#join). It takes any number of JSON Pointer tokens and returns a new `JSONPointer`. Similar to joining a file system path, if a token has a leading slash, the previous pointer is ignored and a new `JSONPointer` is created, before processing of remaining tokens continues.

```javascript
import { JSONPointer } from "json-p3";
Expand All @@ -129,7 +129,7 @@ console.log(pointer.join("baz/qux", "0").toString()); // /foo/bar/baz/qux/0

### `parent()`

Get a pointer to the parent of an existing JSON Pointer using [`JSONPointer.parent()`](../api/classes/jsonpointer.JSONPointer.md#parent). If the pointer is pointing to the document root, `this` is returned.
Get a pointer to the parent of an existing JSON Pointer using [`JSONPointer.parent()`](../api/namespaces/jsonpointer/classes/JSONPointer.md#parent). If the pointer is pointing to the document root, `this` is returned.

```javascript
import { JSONPointer } from "json-p3";
Expand All @@ -142,7 +142,7 @@ console.log(pointer.parent().toString()); // /foo

### `isRelativeTo()`

Test if a pointer is a child of another using [`JSONPointer.isRelativeTo()`](../api/classes/jsonpointer.JSONPointer.md#isrelativeto).
Test if a pointer is a child of another using [`JSONPointer.isRelativeTo()`](../api/namespaces/jsonpointer/classes/JSONPointer.md#isrelativeto).

```javascript
import { JSONPointer } from "json-p3";
Expand All @@ -158,7 +158,7 @@ console.log(anotherPointer.isRelativeTo(pointer)); // false

## Relative JSON Pointer

Use [Relative JSON Pointer](https://datatracker.ietf.org/doc/html/draft-hha-relative-json-pointer) syntax with [`JSONPointer.to(rel)`](../api/classes/jsonpointer.JSONPointer.md#to) to create a new pointer relative to an existing one.
Use [Relative JSON Pointer](https://datatracker.ietf.org/doc/html/draft-hha-relative-json-pointer) syntax with [`JSONPointer.to(rel)`](../api/namespaces/jsonpointer/classes/JSONPointer.md#to) to create a new pointer relative to an existing one.

```javascript
import { JSONPointer } from "json-p3";
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guides/jsonpath-extra.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**_New in version 1.3.0_**

JSON P3 includes some extra, non-standard JSONPath syntax that is disabled by default. Setting the [`strict`](../api/namespaces/jsonpath.md#jsonpathenvironmentoptions) option to `false` when instantiating a [`JSONPathEnvironment`](../api/classes/jsonpath.JSONPathEnvironment.md) will enable all non-standard syntax.
JSON P3 includes some extra, non-standard JSONPath syntax that is disabled by default. Setting the [`strict`](../api/namespaces/jsonpath/type-aliases/JSONPathEnvironmentOptions) option to `false` when instantiating a [`JSONPathEnvironment`](../api/namespaces/jsonpath/classes/JSONPathEnvironment.md) will enable all non-standard syntax.

```javascript
import { JSONPathEnvironment } from "json-p3";
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/guides/jsonpath-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ $.users[?search(@.name, '[Aa]')]
value(nodes: JSONPathNodeList): JSONValue | undefined
```

Return the value associated with the first node in _nodes_, if _nodes_ has exactly one [`JSONPathNode`](../api/classes/jsonpath.JSONPathNode.md). Usually, `value()` will be called with a [filter query](./jsonpath-syntax.md#filter-queries) as its argument.
Return the value associated with the first node in _nodes_, if _nodes_ has exactly one [`JSONPathNode`](../api/namespaces/jsonpath/classes/JSONPathNode.md). Usually, `value()` will be called with a [filter query](./jsonpath-syntax.md#filter-queries) as its argument.

:::info
[Filter queries](./jsonpath-syntax.md#filter-queries) that can result in at most one node are known as "singular queries", and all singular queries will be implicitly replaced with their value as required, without the use of `value()`. `value()` is useful when you need the value from a query that can, theoretically, return multiple nodes.
:::

## Well-typedness

The JSONPath specification defines a [type system for function expressions](https://datatracker.ietf.org/doc/html/rfc9535#name-type-system-for-function-ex), and rules for how those types can be used within an expression. JSON P3 will throw a [JSONPathTypeError](../api/classes/jsonpath.JSONPathTypeError.md) at query compile time if it contains expressions that are not deemed to be well-typed.
The JSONPath specification defines a [type system for function expressions](https://datatracker.ietf.org/doc/html/rfc9535#name-type-system-for-function-ex), and rules for how those types can be used within an expression. JSON P3 will throw a [JSONPathTypeError](../api/namespaces/jsonpath/classes/JSONPathTypeError.md) at query compile time if it contains expressions that are not deemed to be well-typed.

Please see [Section 2.4.3](https://datatracker.ietf.org/doc/html/rfc9535#name-well-typedness-of-function-) _Well-Typedness of Function Expressions_.

## Function extensions

Add, remove or replace [filter functions](./jsonpath-syntax.md#filter-functions) by updating the [function register](../api/classes/jsonpath.JSONPathEnvironment.md#functionregister) on a [`JSONPathEnvironment`](../api/classes/jsonpath.JSONPathEnvironment.md). It is a regular [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map), mapping function names to objects implementing the [`FilterFunction`](../api/interfaces/jsonpath.functions.FilterFunction.md) interface.
Add, remove or replace [filter functions](./jsonpath-syntax.md#filter-functions) by updating the [function register](../api/namespaces/jsonpath/classes/JSONPathEnvironment.md#functionregister) on a [`JSONPathEnvironment`](../api/namespaces/jsonpath/classes/JSONPathEnvironment.md). It is a regular [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map), mapping function names to objects implementing the [`FilterFunction`](../api/namespaces/jsonpath/namespaces/functions/interfaces/FilterFunction.md) interface.

:::info
You can update the function register on the _default environment_ (`import { DEFAULT_ENVIRONMENT } from "json-p3"`), and use convenience functions like [`query()`](../quick-start.md#jsonpath) and [`compile()`](../quick-start.md#compilation). Here we'll create a new `JSONPathEnvironment`, then use its methods directly.
:::

Every filter function must define the types of its parameters and the type of its return value, according to the JSONPath specification's [type system](https://datatracker.ietf.org/doc/html/rfc9535#name-type-system-for-function-ex). This example implements a `typeof()` function, which accepts a parameter of [`ValueType`](../api/enums/jsonpath.functions.FunctionExpressionType.md) and returns a `ValueType`.
Every filter function must define the types of its parameters and the type of its return value, according to the JSONPath specification's [type system](https://datatracker.ietf.org/doc/html/rfc9535#name-type-system-for-function-ex). This example implements a `typeof()` function, which accepts a parameter of [`ValueType`](../api/namespaces/jsonpath/namespaces/functions/enumerations/FunctionExpressionType.md) and returns a `ValueType`.

```typescript
import {
Expand Down
Loading

0 comments on commit 36fde9a

Please sign in to comment.