feat: 초기 프로젝트 설정 및 룰.md 파일 추가
This commit is contained in:
22
api.hyungi.net/node_modules/fast-json-patch/LICENSE.txt
generated
vendored
Normal file
22
api.hyungi.net/node_modules/fast-json-patch/LICENSE.txt
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2013, 2014, 2020 Joachim Wester
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
428
api.hyungi.net/node_modules/fast-json-patch/README.md
generated
vendored
Normal file
428
api.hyungi.net/node_modules/fast-json-patch/README.md
generated
vendored
Normal file
@@ -0,0 +1,428 @@
|
||||
JSON-Patch
|
||||
===============
|
||||
|
||||
> A leaner and meaner implementation of JSON-Patch. Small footprint. High performance.
|
||||
|
||||
[](https://travis-ci.org/Starcounter-Jack/JSON-Patch)
|
||||
|
||||
With JSON-Patch, you can:
|
||||
- **apply** patches (arrays) and single operations on JS object
|
||||
- **validate** a sequence of patches
|
||||
- **observe** for changes and **generate** patches when a change is detected
|
||||
- **compare** two objects to obtain the difference
|
||||
|
||||
Tested in Firefox, Chrome, Edge, Safari, IE11, Deno and Node.js
|
||||
|
||||
|
||||
## Why you should use JSON-Patch
|
||||
|
||||
JSON-Patch [(RFC6902)](http://tools.ietf.org/html/rfc6902) is a standard format that
|
||||
allows you to update a JSON document by sending the changes rather than the whole document.
|
||||
JSON Patch plays well with the HTTP PATCH verb (method) and REST style programming.
|
||||
|
||||
Mark Nottingham has a [nice blog]( http://www.mnot.net/blog/2012/09/05/patch) about it.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
[Download as ZIP](https://github.com/Starcounter-Jack/JSON-Patch/archive/master.zip) or install the current version using a package manager (and save it as a dependency):
|
||||
|
||||
```sh
|
||||
# NPM
|
||||
npm install fast-json-patch --save
|
||||
```
|
||||
|
||||
|
||||
## Adding to your project
|
||||
|
||||
### In a web browser
|
||||
|
||||
Load the bundled distribution script:
|
||||
|
||||
```html
|
||||
<script src="dist/fast-json-patch.min.js"></script>
|
||||
```
|
||||
|
||||
In [browsers that support ECMAScript modules](https://caniuse.com/#feat=es6-module), the below code uses this library as a module:
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import * as jsonpatch from 'fast-json-patch/index.mjs';
|
||||
import { applyOperation } from 'fast-json-patch/index.mjs';
|
||||
</script>
|
||||
```
|
||||
|
||||
### In Node.js
|
||||
|
||||
In Node 12+ with `--experimental-modules` flag, the below code uses this library as an ECMAScript module:
|
||||
|
||||
```js
|
||||
import * as jsonpatch from 'fast-json-patch/index.mjs';
|
||||
import { applyOperation } from 'fast-json-patch/index.mjs';
|
||||
```
|
||||
|
||||
In Webpack (and most surely other bundlers based on Babel), the below code uses this library as an ECMAScript module:
|
||||
|
||||
```js
|
||||
import * as jsonpatch from 'fast-json-patch';
|
||||
import { applyOperation } from 'fast-json-patch';
|
||||
```
|
||||
|
||||
In standard Node, the below code uses this library as a CommonJS module:
|
||||
|
||||
```js
|
||||
const { applyOperation } = require('fast-json-patch');
|
||||
const applyOperation = require('fast-json-patch').applyOperation;
|
||||
```
|
||||
|
||||
## Directories
|
||||
|
||||
Directories used in this package:
|
||||
|
||||
- `dist/` - contains ES5 files for a Web browser
|
||||
- `commonjs/` - contains CommonJS module and typings
|
||||
- `module/` - contains ECMAScript module and typings
|
||||
- `src/` - contains TypeScript source files
|
||||
|
||||
## API
|
||||
|
||||
#### `function applyPatch<T>(document: T, patch: Operation[], validateOperation?: boolean | Validator<T>, mutateDocument: boolean = true, banPrototypeModifications: boolean = true): PatchResult<T>`
|
||||
|
||||
Applies `patch` array on `obj`.
|
||||
|
||||
- `document` The document to patch
|
||||
- `patch` a JSON-Patch array of operations to apply
|
||||
- `validateOperation` Boolean for whether to validate each operation with our default validator, or to pass a validator callback
|
||||
- `mutateDocument` Whether to mutate the original document or clone it before applying
|
||||
- `banPrototypeModifications` Whether to ban modifications to `__proto__`, defaults to `true`.
|
||||
|
||||
An invalid patch results in throwing an error (see `jsonpatch.validate` for more information about the error object).
|
||||
|
||||
It modifies the `document` object and `patch` - it gets the values by reference.
|
||||
If you would like to avoid touching your `patch` array values, clone them: `jsonpatch.applyPatch(document, jsonpatch.deepClone(patch))`.
|
||||
|
||||
Returns an array of [`OperationResult`](#operationresult-type) objects - one item for each item in `patches`, each item is an object `{newDocument: any, test?: boolean, removed?: any}`.
|
||||
|
||||
* `test` - boolean result of the test
|
||||
* `remove`, `replace` and `move` - original object that has been removed
|
||||
* `add` (only when adding to an array) - index at which item has been inserted (useful when using `-` alias)
|
||||
|
||||
- ** Note: It throws `TEST_OPERATION_FAILED` error if `test` operation fails. **
|
||||
- ** Note II: the returned array has `newDocument` property that you can use as the final state of the patched document **.
|
||||
- ** Note III: By default, when `banPrototypeModifications` is `true`, this method throws a `TypeError` when you attempt to modify an object's prototype.
|
||||
|
||||
- See [Validation notes](#validation-notes).
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var document = { firstName: "Albert", contactDetails: { phoneNumbers: [] } };
|
||||
var patch = [
|
||||
{ op: "replace", path: "/firstName", value: "Joachim" },
|
||||
{ op: "add", path: "/lastName", value: "Wester" },
|
||||
{ op: "add", path: "/contactDetails/phoneNumbers/0", value: { number: "555-123" } }
|
||||
];
|
||||
document = jsonpatch.applyPatch(document, patch).newDocument;
|
||||
// document == { firstName: "Joachim", lastName: "Wester", contactDetails: { phoneNumbers: [{number:"555-123"}] } };
|
||||
```
|
||||
|
||||
#### `function applyOperation<T>(document: T, operation: Operation, validateOperation: boolean | Validator<T> = false, mutateDocument: boolean = true, banPrototypeModifications: boolean = true, index: number = 0): OperationResult<T>`
|
||||
|
||||
Applies single operation object `operation` on `document`.
|
||||
|
||||
- `document` The document to patch
|
||||
- `operation` The operation to apply
|
||||
- `validateOperation` Whether to validate the operation, or to pass a validator callback
|
||||
- `mutateDocument` Whether to mutate the original document or clone it before applying
|
||||
- `banPrototypeModifications` Whether to ban modifications to `__proto__`, defaults to `true`.
|
||||
- `index` The index of the operation in your patch array. Useful for better error reporting when that operation fails to apply.
|
||||
|
||||
It modifies the `document` object and `operation` - it gets the values by reference.
|
||||
If you would like to avoid touching your values, clone them: `jsonpatch.applyOperation(document, jsonpatch.deepClone(operation))`.
|
||||
|
||||
Returns an [`OperationResult`](#operationresult-type) object `{newDocument: any, test?: boolean, removed?: any}`.
|
||||
|
||||
- ** Note: It throws `TEST_OPERATION_FAILED` error if `test` operation fails. **
|
||||
- ** Note II: By default, when `banPrototypeModifications` is `true`, this method throws a `TypeError` when you attempt to modify an object's prototype.
|
||||
|
||||
- See [Validation notes](#validation-notes).
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var document = { firstName: "Albert", contactDetails: { phoneNumbers: [] } };
|
||||
var operation = { op: "replace", path: "/firstName", value: "Joachim" };
|
||||
document = jsonpatch.applyOperation(document, operation).newDocument;
|
||||
// document == { firstName: "Joachim", contactDetails: { phoneNumbers: [] }}
|
||||
```
|
||||
|
||||
#### `jsonpatch.applyReducer<T>(document: T, operation: Operation, index: number): T`
|
||||
|
||||
**Ideal for `patch.reduce(jsonpatch.applyReducer, document)`**.
|
||||
|
||||
Applies single operation object `operation` on `document`.
|
||||
|
||||
Returns the a modified document.
|
||||
|
||||
Note: It throws `TEST_OPERATION_FAILED` error if `test` operation fails.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var document = { firstName: "Albert", contactDetails: { phoneNumbers: [ ] } };
|
||||
var patch = [
|
||||
{ op:"replace", path: "/firstName", value: "Joachim" },
|
||||
{ op:"add", path: "/lastName", value: "Wester" },
|
||||
{ op:"add", path: "/contactDetails/phoneNumbers/0", value: { number: "555-123" } }
|
||||
];
|
||||
var updatedDocument = patch.reduce(applyReducer, document);
|
||||
// updatedDocument == { firstName:"Joachim", lastName:"Wester", contactDetails:{ phoneNumbers[ {number:"555-123"} ] } };
|
||||
```
|
||||
|
||||
#### `jsonpatch.deepClone(value: any): any`
|
||||
|
||||
Returns deeply cloned value.
|
||||
|
||||
#### `jsonpatch.escapePathComponent(path: string): string`
|
||||
|
||||
Returns the escaped path.
|
||||
|
||||
#### `jsonpatch.unescapePathComponent(path: string): string`
|
||||
|
||||
Returns the unescaped path.
|
||||
|
||||
#### `jsonpatch.getValueByPointer(document: object, pointer: string)`
|
||||
|
||||
Retrieves a value from a JSON document by a JSON pointer.
|
||||
|
||||
Returns the value.
|
||||
|
||||
#### `jsonpatch.observe(document: any, callback?: Function): Observer`
|
||||
|
||||
Sets up an deep observer on `document` that listens for changes in object tree. When changes are detected, the optional
|
||||
callback is called with the generated patches array as the parameter.
|
||||
|
||||
Returns `observer`.
|
||||
|
||||
#### `jsonpatch.generate(document: any, observer: Observer, invertible = false): Operation[]`
|
||||
|
||||
If there are pending changes in `obj`, returns them synchronously. If a `callback` was defined in `observe`
|
||||
method, it will be triggered synchronously as well. If `invertible` is true, then each change will be preceded by a test operation of the value before the change.
|
||||
|
||||
If there are no pending changes in `obj`, returns an empty array (length 0).
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var document = { firstName: "Joachim", lastName: "Wester", contactDetails: { phoneNumbers: [ { number:"555-123" }] } };
|
||||
var observer = jsonpatch.observe(document);
|
||||
document.firstName = "Albert";
|
||||
document.contactDetails.phoneNumbers[0].number = "123";
|
||||
document.contactDetails.phoneNumbers.push({ number:"456" });
|
||||
var patch = jsonpatch.generate(observer);
|
||||
// patch == [
|
||||
// { op: "replace", path: "/firstName", value: "Albert"},
|
||||
// { op: "replace", path: "/contactDetails/phoneNumbers/0/number", value: "123" },
|
||||
// { op: "add", path: "/contactDetails/phoneNumbers/1", value: {number:"456"}}
|
||||
// ];
|
||||
```
|
||||
|
||||
Example of generating patches with test operations for values in the first object:
|
||||
|
||||
```js
|
||||
var document = { firstName: "Joachim", lastName: "Wester", contactDetails: { phoneNumbers: [ { number:"555-123" }] } };
|
||||
var observer = jsonpatch.observe(document);
|
||||
document.firstName = "Albert";
|
||||
document.contactDetails.phoneNumbers[0].number = "123";
|
||||
document.contactDetails.phoneNumbers.push({ number:"456" });
|
||||
var patch = jsonpatch.generate(observer, true);
|
||||
// patch == [
|
||||
// { op: "test", path: "/firstName", value: "Joachim"},
|
||||
// { op: "replace", path: "/firstName", value: "Albert"},
|
||||
// { op: "test", path: "/contactDetails/phoneNumbers/0/number", value: "555-123" },
|
||||
// { op: "replace", path: "/contactDetails/phoneNumbers/0/number", value: "123" },
|
||||
// { op: "add", path: "/contactDetails/phoneNumbers/1", value: {number:"456"}}
|
||||
// ];
|
||||
```
|
||||
|
||||
#### `jsonpatch.unobserve(document, observer)`
|
||||
```typescript
|
||||
jsonpatch.unobserve(document: any, observer: Observer): void
|
||||
|
||||
type JsonableObj = { [key:string]: Jsonable };
|
||||
type JsonableArr = Jsonable[];
|
||||
type Jsonable = JsonableArr | JsonableObj | string | number | boolean | null;
|
||||
```
|
||||
|
||||
Destroys the observer set up on `document`.
|
||||
|
||||
Any remaining changes are delivered synchronously (as in `jsonpatch.generate`). Note: this is different that ES6/7 `Object.unobserve`, which delivers remaining changes asynchronously.
|
||||
|
||||
#### `jsonpatch.compare(document1, document2, invertible)`
|
||||
|
||||
```typescript
|
||||
jsonpatch.compare(document1: Jsonable, document2: Jsonable, invertible = false): Operation[]
|
||||
|
||||
type JsonableObj = { [key:string]: Jsonable };
|
||||
type JsonableArr = Jsonable[];
|
||||
type Jsonable = JsonableArr | JsonableObj | string | number | boolean | null;
|
||||
```
|
||||
|
||||
Compares object trees `document1` and `document2` and returns the difference relative to `document1` as a patches array. If `invertible` is true, then each change will be preceded by a test operation of the value in `document1`.
|
||||
|
||||
If there are no differences, returns an empty array (length 0).
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var documentA = {user: {firstName: "Albert", lastName: "Einstein"}};
|
||||
var documentB = {user: {firstName: "Albert", lastName: "Collins"}};
|
||||
var diff = jsonpatch.compare(documentA, documentB);
|
||||
//diff == [{op: "replace", path: "/user/lastName", value: "Collins"}]
|
||||
```
|
||||
|
||||
Example of comparing two object trees with test operations for values in the first object:
|
||||
|
||||
```js
|
||||
var documentA = {user: {firstName: "Albert", lastName: "Einstein"}};
|
||||
var documentB = {user: {firstName: "Albert", lastName: "Collins"}};
|
||||
var diff = jsonpatch.compare(documentA, documentB, true);
|
||||
//diff == [
|
||||
// {op: "test", path: "/user/lastName", value: "Einstein"},
|
||||
// {op: "replace", path: "/user/lastName", value: "Collins"}
|
||||
// ];
|
||||
```
|
||||
|
||||
#### `jsonpatch.validate(patch: Operation[], document?: any, validator?: Function): JsonPatchError`
|
||||
|
||||
See [Validation notes](#validation-notes)
|
||||
|
||||
Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object tree.
|
||||
|
||||
If there are no errors, returns undefined. If there is an errors, returns a JsonPatchError object with the following properties:
|
||||
|
||||
- `name` String - short error code
|
||||
- `message` String - long human readable error message
|
||||
- `index` Number - index of the operation in the sequence
|
||||
- `operation` Object - reference to the operation
|
||||
- `tree` Object - reference to the tree
|
||||
|
||||
Possible errors:
|
||||
|
||||
Error name | Error message
|
||||
------------------------------|------------
|
||||
SEQUENCE_NOT_AN_ARRAY | Patch sequence must be an array
|
||||
OPERATION_NOT_AN_OBJECT | Operation is not an object
|
||||
OPERATION_OP_INVALID | Operation `op` property is not one of operations defined in RFC-6902
|
||||
OPERATION_PATH_INVALID | Operation `path` property is not a valid string
|
||||
OPERATION_FROM_REQUIRED | Operation `from` property is not present (applicable in `move` and `copy` operations)
|
||||
OPERATION_VALUE_REQUIRED | Operation `value` property is not present, or `undefined` (applicable in `add`, `replace` and `test` operations)
|
||||
OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED | Operation `value` property object has at least one `undefined` value (applicable in `add`, `replace` and `test` operations)
|
||||
OPERATION_PATH_CANNOT_ADD | Cannot perform an `add` operation at the desired path
|
||||
OPERATION_PATH_UNRESOLVABLE | Cannot perform the operation at a path that does not exist
|
||||
OPERATION_FROM_UNRESOLVABLE | Cannot perform the operation from a path that does not exist
|
||||
OPERATION_PATH_ILLEGAL_ARRAY_INDEX | Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index
|
||||
OPERATION_VALUE_OUT_OF_BOUNDS | The specified index MUST NOT be greater than the number of elements in the array
|
||||
TEST_OPERATION_FAILED | When operation is `test` and the test fails, applies to `applyReducer`.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var obj = {user: {firstName: "Albert"}};
|
||||
var patches = [{op: "replace", path: "/user/firstName", value: "Albert"}, {op: "replace", path: "/user/lastName", value: "Einstein"}];
|
||||
var errors = jsonpatch.validate(patches, obj);
|
||||
if (errors.length == 0) {
|
||||
//there are no errors!
|
||||
}
|
||||
else {
|
||||
for (var i=0; i < errors.length; i++) {
|
||||
if (!errors[i]) {
|
||||
console.log("Valid patch at index", i, patches[i]);
|
||||
}
|
||||
else {
|
||||
console.error("Invalid patch at index", i, errors[i], patches[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## `OperationResult` Type
|
||||
|
||||
Functions `applyPatch` and `applyOperation` both return `OperationResult` object. This object is:
|
||||
|
||||
```ts
|
||||
{newDocument: any, test?: boolean, removed?: any}
|
||||
```
|
||||
|
||||
Where:
|
||||
|
||||
- `newDocument`: the new state of the document after the patch/operation is applied.
|
||||
- `test`: if the operation was a `test` operation. This will be its result.
|
||||
- `removed`: contains the removed, moved, or replaced values from the document after a `remove`, `move` or `replace` operation.
|
||||
|
||||
|
||||
## Validation Notes
|
||||
|
||||
Functions `applyPatch`, `applyOperation`, and `validate` accept a `validate`/ `validator` parameter:
|
||||
|
||||
- If the `validateOperation` parameter is set to `false`, validation will not occur.
|
||||
- If set to `true`, the patch is extensively validated before applying using jsonpatch's default validation.
|
||||
- If set to a `function` callback, the patch is validated using that function.
|
||||
|
||||
If you pass a validator, it will be called with four parameters for each operation, `function(operation, index, tree, existingPath)` and it is expected to throw `JsonPatchError` when your conditions are not met.
|
||||
|
||||
- `operation` The operation it self.
|
||||
- `index` `operation`'s index in the patch array (if application).
|
||||
- `tree` The object that is supposed to be patched.
|
||||
- `existingPath` the path `operation` points to.
|
||||
|
||||
## Overwriting and `move` Operation
|
||||
|
||||
When the target of the move operation already exists, it is cached, deep cloned and returned as `removed` in `OperationResult`.
|
||||
|
||||
## `undefined`s (JS to JSON projection)
|
||||
|
||||
As `undefined` type does not exist in JSON, it's also not a valid value of JSON Patch operation. Therefore `jsonpatch` will not generate JSON Patches that sets anything to `undefined`.
|
||||
|
||||
Whenever a value is set to `undefined` in JS, JSON-Patch methods `generate` and `compare` will treat it similarly to how JavaScript method [`JSON.stringify` (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) treats them:
|
||||
|
||||
> If `undefined` (...) is encountered during conversion it is either omitted (when it is found in an object) or censored to `null` (when it is found in an array).
|
||||
|
||||
See the [ECMAScript spec](http://www.ecma-international.org/ecma-262/6.0/index.html#sec-json.stringify) for details.
|
||||
|
||||
## Specs/tests
|
||||
|
||||
- [Run in browser](http://starcounter-jack.github.io/JSON-Patch/test/)
|
||||
|
||||
## [Contributing](CONTRIBUTING.md)
|
||||
|
||||
## Changelog
|
||||
|
||||
To see the list of recent changes, see [Releases](https://github.com/Starcounter-Jack/JSON-Patch/releases).
|
||||
|
||||
## Footprint
|
||||
4 KB minified and gzipped (12 KB minified)
|
||||
|
||||
## Performance
|
||||
|
||||
##### [`add` benchmark](https://run.perf.zone/view/JSON-Patch-Add-Operation-1535541298893)
|
||||
|
||||

|
||||
|
||||
##### [`replace` benchmark](https://run.perf.zone/view/JSON-Patch-Replace-Operation-1535540952263)
|
||||
|
||||

|
||||
|
||||
Tested on 29.08.2018. Compared libraries:
|
||||
|
||||
- [Starcounter-Jack/JSON-Patch](https://www.npmjs.com/package/fast-json-patch) 2.0.6
|
||||
- [bruth/jsonpatch-js](https://www.npmjs.com/package/json-patch) 0.7.0
|
||||
- [dharmafly/jsonpatch.js](https://www.npmjs.com/package/jsonpatch) 3.0.1
|
||||
- [jiff](https://www.npmjs.com/package/jiff) 0.7.3
|
||||
- [RFC6902](https://www.npmjs.com/package/rfc6902) 2.4.0
|
||||
|
||||
We aim the tests to be fair. Our library puts performance as the #1 priority, while other libraries can have different priorities. If you'd like to update the benchmarks or add a library, please fork the [perf.zone](https://perf.zone) benchmarks linked above and open an issue to include new results.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
111
api.hyungi.net/node_modules/fast-json-patch/commonjs/core.d.ts
generated
vendored
Normal file
111
api.hyungi.net/node_modules/fast-json-patch/commonjs/core.d.ts
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
import { PatchError, _deepClone } from './helpers.js';
|
||||
export declare const JsonPatchError: typeof PatchError;
|
||||
export declare const deepClone: typeof _deepClone;
|
||||
export declare type Operation = AddOperation<any> | RemoveOperation | ReplaceOperation<any> | MoveOperation | CopyOperation | TestOperation<any> | GetOperation<any>;
|
||||
export interface Validator<T> {
|
||||
(operation: Operation, index: number, document: T, existingPathFragment: string): void;
|
||||
}
|
||||
export interface OperationResult<T> {
|
||||
removed?: any;
|
||||
test?: boolean;
|
||||
newDocument: T;
|
||||
}
|
||||
export interface BaseOperation {
|
||||
path: string;
|
||||
}
|
||||
export interface AddOperation<T> extends BaseOperation {
|
||||
op: 'add';
|
||||
value: T;
|
||||
}
|
||||
export interface RemoveOperation extends BaseOperation {
|
||||
op: 'remove';
|
||||
}
|
||||
export interface ReplaceOperation<T> extends BaseOperation {
|
||||
op: 'replace';
|
||||
value: T;
|
||||
}
|
||||
export interface MoveOperation extends BaseOperation {
|
||||
op: 'move';
|
||||
from: string;
|
||||
}
|
||||
export interface CopyOperation extends BaseOperation {
|
||||
op: 'copy';
|
||||
from: string;
|
||||
}
|
||||
export interface TestOperation<T> extends BaseOperation {
|
||||
op: 'test';
|
||||
value: T;
|
||||
}
|
||||
export interface GetOperation<T> extends BaseOperation {
|
||||
op: '_get';
|
||||
value: T;
|
||||
}
|
||||
export interface PatchResult<T> extends Array<OperationResult<T>> {
|
||||
newDocument: T;
|
||||
}
|
||||
/**
|
||||
* Retrieves a value from a JSON document by a JSON pointer.
|
||||
* Returns the value.
|
||||
*
|
||||
* @param document The document to get the value from
|
||||
* @param pointer an escaped JSON pointer
|
||||
* @return The retrieved value
|
||||
*/
|
||||
export declare function getValueByPointer(document: any, pointer: string): any;
|
||||
/**
|
||||
* Apply a single JSON Patch Operation on a JSON document.
|
||||
* Returns the {newDocument, result} of the operation.
|
||||
* It modifies the `document` and `operation` objects - it gets the values by reference.
|
||||
* If you would like to avoid touching your values, clone them:
|
||||
* `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.
|
||||
*
|
||||
* @param document The document to patch
|
||||
* @param operation The operation to apply
|
||||
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
||||
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
||||
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
||||
* @return `{newDocument, result}` after the operation
|
||||
*/
|
||||
export declare function applyOperation<T>(document: T, operation: Operation, validateOperation?: boolean | Validator<T>, mutateDocument?: boolean, banPrototypeModifications?: boolean, index?: number): OperationResult<T>;
|
||||
/**
|
||||
* Apply a full JSON Patch array on a JSON document.
|
||||
* Returns the {newDocument, result} of the patch.
|
||||
* It modifies the `document` object and `patch` - it gets the values by reference.
|
||||
* If you would like to avoid touching your values, clone them:
|
||||
* `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.
|
||||
*
|
||||
* @param document The document to patch
|
||||
* @param patch The patch to apply
|
||||
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
||||
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
||||
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
||||
* @return An array of `{newDocument, result}` after the patch
|
||||
*/
|
||||
export declare function applyPatch<T>(document: T, patch: ReadonlyArray<Operation>, validateOperation?: boolean | Validator<T>, mutateDocument?: boolean, banPrototypeModifications?: boolean): PatchResult<T>;
|
||||
/**
|
||||
* Apply a single JSON Patch Operation on a JSON document.
|
||||
* Returns the updated document.
|
||||
* Suitable as a reducer.
|
||||
*
|
||||
* @param document The document to patch
|
||||
* @param operation The operation to apply
|
||||
* @return The updated document
|
||||
*/
|
||||
export declare function applyReducer<T>(document: T, operation: Operation, index: number): T;
|
||||
/**
|
||||
* Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.
|
||||
* @param {object} operation - operation object (patch)
|
||||
* @param {number} index - index of operation in the sequence
|
||||
* @param {object} [document] - object where the operation is supposed to be applied
|
||||
* @param {string} [existingPathFragment] - comes along with `document`
|
||||
*/
|
||||
export declare function validator(operation: Operation, index: number, document?: any, existingPathFragment?: string): void;
|
||||
/**
|
||||
* Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.
|
||||
* If error is encountered, returns a JsonPatchError object
|
||||
* @param sequence
|
||||
* @param document
|
||||
* @returns {JsonPatchError|undefined}
|
||||
*/
|
||||
export declare function validate<T>(sequence: ReadonlyArray<Operation>, document?: T, externalValidator?: Validator<T>): PatchError;
|
||||
export declare function _areEquals(a: any, b: any): boolean;
|
||||
441
api.hyungi.net/node_modules/fast-json-patch/commonjs/core.js
generated
vendored
Normal file
441
api.hyungi.net/node_modules/fast-json-patch/commonjs/core.js
generated
vendored
Normal file
@@ -0,0 +1,441 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var helpers_js_1 = require("./helpers.js");
|
||||
exports.JsonPatchError = helpers_js_1.PatchError;
|
||||
exports.deepClone = helpers_js_1._deepClone;
|
||||
/* We use a Javascript hash to store each
|
||||
function. Each hash entry (property) uses
|
||||
the operation identifiers specified in rfc6902.
|
||||
In this way, we can map each patch operation
|
||||
to its dedicated function in efficient way.
|
||||
*/
|
||||
/* The operations applicable to an object */
|
||||
var objOps = {
|
||||
add: function (obj, key, document) {
|
||||
obj[key] = this.value;
|
||||
return { newDocument: document };
|
||||
},
|
||||
remove: function (obj, key, document) {
|
||||
var removed = obj[key];
|
||||
delete obj[key];
|
||||
return { newDocument: document, removed: removed };
|
||||
},
|
||||
replace: function (obj, key, document) {
|
||||
var removed = obj[key];
|
||||
obj[key] = this.value;
|
||||
return { newDocument: document, removed: removed };
|
||||
},
|
||||
move: function (obj, key, document) {
|
||||
/* in case move target overwrites an existing value,
|
||||
return the removed value, this can be taxing performance-wise,
|
||||
and is potentially unneeded */
|
||||
var removed = getValueByPointer(document, this.path);
|
||||
if (removed) {
|
||||
removed = helpers_js_1._deepClone(removed);
|
||||
}
|
||||
var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed;
|
||||
applyOperation(document, { op: "add", path: this.path, value: originalValue });
|
||||
return { newDocument: document, removed: removed };
|
||||
},
|
||||
copy: function (obj, key, document) {
|
||||
var valueToCopy = getValueByPointer(document, this.from);
|
||||
// enforce copy by value so further operations don't affect source (see issue #177)
|
||||
applyOperation(document, { op: "add", path: this.path, value: helpers_js_1._deepClone(valueToCopy) });
|
||||
return { newDocument: document };
|
||||
},
|
||||
test: function (obj, key, document) {
|
||||
return { newDocument: document, test: _areEquals(obj[key], this.value) };
|
||||
},
|
||||
_get: function (obj, key, document) {
|
||||
this.value = obj[key];
|
||||
return { newDocument: document };
|
||||
}
|
||||
};
|
||||
/* The operations applicable to an array. Many are the same as for the object */
|
||||
var arrOps = {
|
||||
add: function (arr, i, document) {
|
||||
if (helpers_js_1.isInteger(i)) {
|
||||
arr.splice(i, 0, this.value);
|
||||
}
|
||||
else { // array props
|
||||
arr[i] = this.value;
|
||||
}
|
||||
// this may be needed when using '-' in an array
|
||||
return { newDocument: document, index: i };
|
||||
},
|
||||
remove: function (arr, i, document) {
|
||||
var removedList = arr.splice(i, 1);
|
||||
return { newDocument: document, removed: removedList[0] };
|
||||
},
|
||||
replace: function (arr, i, document) {
|
||||
var removed = arr[i];
|
||||
arr[i] = this.value;
|
||||
return { newDocument: document, removed: removed };
|
||||
},
|
||||
move: objOps.move,
|
||||
copy: objOps.copy,
|
||||
test: objOps.test,
|
||||
_get: objOps._get
|
||||
};
|
||||
/**
|
||||
* Retrieves a value from a JSON document by a JSON pointer.
|
||||
* Returns the value.
|
||||
*
|
||||
* @param document The document to get the value from
|
||||
* @param pointer an escaped JSON pointer
|
||||
* @return The retrieved value
|
||||
*/
|
||||
function getValueByPointer(document, pointer) {
|
||||
if (pointer == '') {
|
||||
return document;
|
||||
}
|
||||
var getOriginalDestination = { op: "_get", path: pointer };
|
||||
applyOperation(document, getOriginalDestination);
|
||||
return getOriginalDestination.value;
|
||||
}
|
||||
exports.getValueByPointer = getValueByPointer;
|
||||
/**
|
||||
* Apply a single JSON Patch Operation on a JSON document.
|
||||
* Returns the {newDocument, result} of the operation.
|
||||
* It modifies the `document` and `operation` objects - it gets the values by reference.
|
||||
* If you would like to avoid touching your values, clone them:
|
||||
* `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.
|
||||
*
|
||||
* @param document The document to patch
|
||||
* @param operation The operation to apply
|
||||
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
||||
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
||||
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
||||
* @return `{newDocument, result}` after the operation
|
||||
*/
|
||||
function applyOperation(document, operation, validateOperation, mutateDocument, banPrototypeModifications, index) {
|
||||
if (validateOperation === void 0) { validateOperation = false; }
|
||||
if (mutateDocument === void 0) { mutateDocument = true; }
|
||||
if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
|
||||
if (index === void 0) { index = 0; }
|
||||
if (validateOperation) {
|
||||
if (typeof validateOperation == 'function') {
|
||||
validateOperation(operation, 0, document, operation.path);
|
||||
}
|
||||
else {
|
||||
validator(operation, 0);
|
||||
}
|
||||
}
|
||||
/* ROOT OPERATIONS */
|
||||
if (operation.path === "") {
|
||||
var returnValue = { newDocument: document };
|
||||
if (operation.op === 'add') {
|
||||
returnValue.newDocument = operation.value;
|
||||
return returnValue;
|
||||
}
|
||||
else if (operation.op === 'replace') {
|
||||
returnValue.newDocument = operation.value;
|
||||
returnValue.removed = document; //document we removed
|
||||
return returnValue;
|
||||
}
|
||||
else if (operation.op === 'move' || operation.op === 'copy') { // it's a move or copy to root
|
||||
returnValue.newDocument = getValueByPointer(document, operation.from); // get the value by json-pointer in `from` field
|
||||
if (operation.op === 'move') { // report removed item
|
||||
returnValue.removed = document;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
else if (operation.op === 'test') {
|
||||
returnValue.test = _areEquals(document, operation.value);
|
||||
if (returnValue.test === false) {
|
||||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
||||
}
|
||||
returnValue.newDocument = document;
|
||||
return returnValue;
|
||||
}
|
||||
else if (operation.op === 'remove') { // a remove on root
|
||||
returnValue.removed = document;
|
||||
returnValue.newDocument = null;
|
||||
return returnValue;
|
||||
}
|
||||
else if (operation.op === '_get') {
|
||||
operation.value = document;
|
||||
return returnValue;
|
||||
}
|
||||
else { /* bad operation */
|
||||
if (validateOperation) {
|
||||
throw new exports.JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);
|
||||
}
|
||||
else {
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
} /* END ROOT OPERATIONS */
|
||||
else {
|
||||
if (!mutateDocument) {
|
||||
document = helpers_js_1._deepClone(document);
|
||||
}
|
||||
var path = operation.path || "";
|
||||
var keys = path.split('/');
|
||||
var obj = document;
|
||||
var t = 1; //skip empty element - http://jsperf.com/to-shift-or-not-to-shift
|
||||
var len = keys.length;
|
||||
var existingPathFragment = undefined;
|
||||
var key = void 0;
|
||||
var validateFunction = void 0;
|
||||
if (typeof validateOperation == 'function') {
|
||||
validateFunction = validateOperation;
|
||||
}
|
||||
else {
|
||||
validateFunction = validator;
|
||||
}
|
||||
while (true) {
|
||||
key = keys[t];
|
||||
if (key && key.indexOf('~') != -1) {
|
||||
key = helpers_js_1.unescapePathComponent(key);
|
||||
}
|
||||
if (banPrototypeModifications &&
|
||||
(key == '__proto__' ||
|
||||
(key == 'prototype' && t > 0 && keys[t - 1] == 'constructor'))) {
|
||||
throw new TypeError('JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README');
|
||||
}
|
||||
if (validateOperation) {
|
||||
if (existingPathFragment === undefined) {
|
||||
if (obj[key] === undefined) {
|
||||
existingPathFragment = keys.slice(0, t).join('/');
|
||||
}
|
||||
else if (t == len - 1) {
|
||||
existingPathFragment = operation.path;
|
||||
}
|
||||
if (existingPathFragment !== undefined) {
|
||||
validateFunction(operation, 0, document, existingPathFragment);
|
||||
}
|
||||
}
|
||||
}
|
||||
t++;
|
||||
if (Array.isArray(obj)) {
|
||||
if (key === '-') {
|
||||
key = obj.length;
|
||||
}
|
||||
else {
|
||||
if (validateOperation && !helpers_js_1.isInteger(key)) {
|
||||
throw new exports.JsonPatchError("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", index, operation, document);
|
||||
} // only parse key when it's an integer for `arr.prop` to work
|
||||
else if (helpers_js_1.isInteger(key)) {
|
||||
key = ~~key;
|
||||
}
|
||||
}
|
||||
if (t >= len) {
|
||||
if (validateOperation && operation.op === "add" && key > obj.length) {
|
||||
throw new exports.JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", index, operation, document);
|
||||
}
|
||||
var returnValue = arrOps[operation.op].call(operation, obj, key, document); // Apply patch
|
||||
if (returnValue.test === false) {
|
||||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (t >= len) {
|
||||
var returnValue = objOps[operation.op].call(operation, obj, key, document); // Apply patch
|
||||
if (returnValue.test === false) {
|
||||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
obj = obj[key];
|
||||
// If we have more keys in the path, but the next value isn't a non-null object,
|
||||
// throw an OPERATION_PATH_UNRESOLVABLE error instead of iterating again.
|
||||
if (validateOperation && t < len && (!obj || typeof obj !== "object")) {
|
||||
throw new exports.JsonPatchError('Cannot perform operation at the desired path', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.applyOperation = applyOperation;
|
||||
/**
|
||||
* Apply a full JSON Patch array on a JSON document.
|
||||
* Returns the {newDocument, result} of the patch.
|
||||
* It modifies the `document` object and `patch` - it gets the values by reference.
|
||||
* If you would like to avoid touching your values, clone them:
|
||||
* `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.
|
||||
*
|
||||
* @param document The document to patch
|
||||
* @param patch The patch to apply
|
||||
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
||||
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
||||
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
||||
* @return An array of `{newDocument, result}` after the patch
|
||||
*/
|
||||
function applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) {
|
||||
if (mutateDocument === void 0) { mutateDocument = true; }
|
||||
if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
|
||||
if (validateOperation) {
|
||||
if (!Array.isArray(patch)) {
|
||||
throw new exports.JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
|
||||
}
|
||||
}
|
||||
if (!mutateDocument) {
|
||||
document = helpers_js_1._deepClone(document);
|
||||
}
|
||||
var results = new Array(patch.length);
|
||||
for (var i = 0, length_1 = patch.length; i < length_1; i++) {
|
||||
// we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`
|
||||
results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);
|
||||
document = results[i].newDocument; // in case root was replaced
|
||||
}
|
||||
results.newDocument = document;
|
||||
return results;
|
||||
}
|
||||
exports.applyPatch = applyPatch;
|
||||
/**
|
||||
* Apply a single JSON Patch Operation on a JSON document.
|
||||
* Returns the updated document.
|
||||
* Suitable as a reducer.
|
||||
*
|
||||
* @param document The document to patch
|
||||
* @param operation The operation to apply
|
||||
* @return The updated document
|
||||
*/
|
||||
function applyReducer(document, operation, index) {
|
||||
var operationResult = applyOperation(document, operation);
|
||||
if (operationResult.test === false) { // failed test
|
||||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
||||
}
|
||||
return operationResult.newDocument;
|
||||
}
|
||||
exports.applyReducer = applyReducer;
|
||||
/**
|
||||
* Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.
|
||||
* @param {object} operation - operation object (patch)
|
||||
* @param {number} index - index of operation in the sequence
|
||||
* @param {object} [document] - object where the operation is supposed to be applied
|
||||
* @param {string} [existingPathFragment] - comes along with `document`
|
||||
*/
|
||||
function validator(operation, index, document, existingPathFragment) {
|
||||
if (typeof operation !== 'object' || operation === null || Array.isArray(operation)) {
|
||||
throw new exports.JsonPatchError('Operation is not an object', 'OPERATION_NOT_AN_OBJECT', index, operation, document);
|
||||
}
|
||||
else if (!objOps[operation.op]) {
|
||||
throw new exports.JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);
|
||||
}
|
||||
else if (typeof operation.path !== 'string') {
|
||||
throw new exports.JsonPatchError('Operation `path` property is not a string', 'OPERATION_PATH_INVALID', index, operation, document);
|
||||
}
|
||||
else if (operation.path.indexOf('/') !== 0 && operation.path.length > 0) {
|
||||
// paths that aren't empty string should start with "/"
|
||||
throw new exports.JsonPatchError('Operation `path` property must start with "/"', 'OPERATION_PATH_INVALID', index, operation, document);
|
||||
}
|
||||
else if ((operation.op === 'move' || operation.op === 'copy') && typeof operation.from !== 'string') {
|
||||
throw new exports.JsonPatchError('Operation `from` property is not present (applicable in `move` and `copy` operations)', 'OPERATION_FROM_REQUIRED', index, operation, document);
|
||||
}
|
||||
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && operation.value === undefined) {
|
||||
throw new exports.JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document);
|
||||
}
|
||||
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && helpers_js_1.hasUndefined(operation.value)) {
|
||||
throw new exports.JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, document);
|
||||
}
|
||||
else if (document) {
|
||||
if (operation.op == "add") {
|
||||
var pathLen = operation.path.split("/").length;
|
||||
var existingPathLen = existingPathFragment.split("/").length;
|
||||
if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {
|
||||
throw new exports.JsonPatchError('Cannot perform an `add` operation at the desired path', 'OPERATION_PATH_CANNOT_ADD', index, operation, document);
|
||||
}
|
||||
}
|
||||
else if (operation.op === 'replace' || operation.op === 'remove' || operation.op === '_get') {
|
||||
if (operation.path !== existingPathFragment) {
|
||||
throw new exports.JsonPatchError('Cannot perform the operation at a path that does not exist', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);
|
||||
}
|
||||
}
|
||||
else if (operation.op === 'move' || operation.op === 'copy') {
|
||||
var existingValue = { op: "_get", path: operation.from, value: undefined };
|
||||
var error = validate([existingValue], document);
|
||||
if (error && error.name === 'OPERATION_PATH_UNRESOLVABLE') {
|
||||
throw new exports.JsonPatchError('Cannot perform the operation from a path that does not exist', 'OPERATION_FROM_UNRESOLVABLE', index, operation, document);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.validator = validator;
|
||||
/**
|
||||
* Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.
|
||||
* If error is encountered, returns a JsonPatchError object
|
||||
* @param sequence
|
||||
* @param document
|
||||
* @returns {JsonPatchError|undefined}
|
||||
*/
|
||||
function validate(sequence, document, externalValidator) {
|
||||
try {
|
||||
if (!Array.isArray(sequence)) {
|
||||
throw new exports.JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
|
||||
}
|
||||
if (document) {
|
||||
//clone document and sequence so that we can safely try applying operations
|
||||
applyPatch(helpers_js_1._deepClone(document), helpers_js_1._deepClone(sequence), externalValidator || true);
|
||||
}
|
||||
else {
|
||||
externalValidator = externalValidator || validator;
|
||||
for (var i = 0; i < sequence.length; i++) {
|
||||
externalValidator(sequence[i], i, document, undefined);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
if (e instanceof exports.JsonPatchError) {
|
||||
return e;
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.validate = validate;
|
||||
// based on https://github.com/epoberezkin/fast-deep-equal
|
||||
// MIT License
|
||||
// Copyright (c) 2017 Evgeny Poberezkin
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
function _areEquals(a, b) {
|
||||
if (a === b)
|
||||
return true;
|
||||
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
||||
var arrA = Array.isArray(a), arrB = Array.isArray(b), i, length, key;
|
||||
if (arrA && arrB) {
|
||||
length = a.length;
|
||||
if (length != b.length)
|
||||
return false;
|
||||
for (i = length; i-- !== 0;)
|
||||
if (!_areEquals(a[i], b[i]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
if (arrA != arrB)
|
||||
return false;
|
||||
var keys = Object.keys(a);
|
||||
length = keys.length;
|
||||
if (length !== Object.keys(b).length)
|
||||
return false;
|
||||
for (i = length; i-- !== 0;)
|
||||
if (!b.hasOwnProperty(keys[i]))
|
||||
return false;
|
||||
for (i = length; i-- !== 0;) {
|
||||
key = keys[i];
|
||||
if (!_areEquals(a[key], b[key]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return a !== a && b !== b;
|
||||
}
|
||||
exports._areEquals = _areEquals;
|
||||
;
|
||||
23
api.hyungi.net/node_modules/fast-json-patch/commonjs/duplex.d.ts
generated
vendored
Normal file
23
api.hyungi.net/node_modules/fast-json-patch/commonjs/duplex.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Operation } from './core.js';
|
||||
export interface Observer<T> {
|
||||
object: T;
|
||||
patches: Operation[];
|
||||
unobserve: () => void;
|
||||
callback: (patches: Operation[]) => void;
|
||||
}
|
||||
/**
|
||||
* Detach an observer from an object
|
||||
*/
|
||||
export declare function unobserve<T>(root: T, observer: Observer<T>): void;
|
||||
/**
|
||||
* Observes changes made to an object, which can then be retrieved using generate
|
||||
*/
|
||||
export declare function observe<T>(obj: Object | Array<T>, callback?: (patches: Operation[]) => void): Observer<T>;
|
||||
/**
|
||||
* Generate an array of patches from an observer
|
||||
*/
|
||||
export declare function generate<T>(observer: Observer<Object>, invertible?: boolean): Operation[];
|
||||
/**
|
||||
* Create an array of patches from the differences in two objects
|
||||
*/
|
||||
export declare function compare(tree1: Object | Array<any>, tree2: Object | Array<any>, invertible?: boolean): Operation[];
|
||||
181
api.hyungi.net/node_modules/fast-json-patch/commonjs/duplex.js
generated
vendored
Normal file
181
api.hyungi.net/node_modules/fast-json-patch/commonjs/duplex.js
generated
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/*!
|
||||
* https://github.com/Starcounter-Jack/JSON-Patch
|
||||
* (c) 2017-2021 Joachim Wester
|
||||
* MIT license
|
||||
*/
|
||||
var helpers_js_1 = require("./helpers.js");
|
||||
var core_js_1 = require("./core.js");
|
||||
var beforeDict = new WeakMap();
|
||||
var Mirror = /** @class */ (function () {
|
||||
function Mirror(obj) {
|
||||
this.observers = new Map();
|
||||
this.obj = obj;
|
||||
}
|
||||
return Mirror;
|
||||
}());
|
||||
var ObserverInfo = /** @class */ (function () {
|
||||
function ObserverInfo(callback, observer) {
|
||||
this.callback = callback;
|
||||
this.observer = observer;
|
||||
}
|
||||
return ObserverInfo;
|
||||
}());
|
||||
function getMirror(obj) {
|
||||
return beforeDict.get(obj);
|
||||
}
|
||||
function getObserverFromMirror(mirror, callback) {
|
||||
return mirror.observers.get(callback);
|
||||
}
|
||||
function removeObserverFromMirror(mirror, observer) {
|
||||
mirror.observers.delete(observer.callback);
|
||||
}
|
||||
/**
|
||||
* Detach an observer from an object
|
||||
*/
|
||||
function unobserve(root, observer) {
|
||||
observer.unobserve();
|
||||
}
|
||||
exports.unobserve = unobserve;
|
||||
/**
|
||||
* Observes changes made to an object, which can then be retrieved using generate
|
||||
*/
|
||||
function observe(obj, callback) {
|
||||
var patches = [];
|
||||
var observer;
|
||||
var mirror = getMirror(obj);
|
||||
if (!mirror) {
|
||||
mirror = new Mirror(obj);
|
||||
beforeDict.set(obj, mirror);
|
||||
}
|
||||
else {
|
||||
var observerInfo = getObserverFromMirror(mirror, callback);
|
||||
observer = observerInfo && observerInfo.observer;
|
||||
}
|
||||
if (observer) {
|
||||
return observer;
|
||||
}
|
||||
observer = {};
|
||||
mirror.value = helpers_js_1._deepClone(obj);
|
||||
if (callback) {
|
||||
observer.callback = callback;
|
||||
observer.next = null;
|
||||
var dirtyCheck = function () {
|
||||
generate(observer);
|
||||
};
|
||||
var fastCheck = function () {
|
||||
clearTimeout(observer.next);
|
||||
observer.next = setTimeout(dirtyCheck);
|
||||
};
|
||||
if (typeof window !== 'undefined') { //not Node
|
||||
window.addEventListener('mouseup', fastCheck);
|
||||
window.addEventListener('keyup', fastCheck);
|
||||
window.addEventListener('mousedown', fastCheck);
|
||||
window.addEventListener('keydown', fastCheck);
|
||||
window.addEventListener('change', fastCheck);
|
||||
}
|
||||
}
|
||||
observer.patches = patches;
|
||||
observer.object = obj;
|
||||
observer.unobserve = function () {
|
||||
generate(observer);
|
||||
clearTimeout(observer.next);
|
||||
removeObserverFromMirror(mirror, observer);
|
||||
if (typeof window !== 'undefined') {
|
||||
window.removeEventListener('mouseup', fastCheck);
|
||||
window.removeEventListener('keyup', fastCheck);
|
||||
window.removeEventListener('mousedown', fastCheck);
|
||||
window.removeEventListener('keydown', fastCheck);
|
||||
window.removeEventListener('change', fastCheck);
|
||||
}
|
||||
};
|
||||
mirror.observers.set(callback, new ObserverInfo(callback, observer));
|
||||
return observer;
|
||||
}
|
||||
exports.observe = observe;
|
||||
/**
|
||||
* Generate an array of patches from an observer
|
||||
*/
|
||||
function generate(observer, invertible) {
|
||||
if (invertible === void 0) { invertible = false; }
|
||||
var mirror = beforeDict.get(observer.object);
|
||||
_generate(mirror.value, observer.object, observer.patches, "", invertible);
|
||||
if (observer.patches.length) {
|
||||
core_js_1.applyPatch(mirror.value, observer.patches);
|
||||
}
|
||||
var temp = observer.patches;
|
||||
if (temp.length > 0) {
|
||||
observer.patches = [];
|
||||
if (observer.callback) {
|
||||
observer.callback(temp);
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
exports.generate = generate;
|
||||
// Dirty check if obj is different from mirror, generate patches and update mirror
|
||||
function _generate(mirror, obj, patches, path, invertible) {
|
||||
if (obj === mirror) {
|
||||
return;
|
||||
}
|
||||
if (typeof obj.toJSON === "function") {
|
||||
obj = obj.toJSON();
|
||||
}
|
||||
var newKeys = helpers_js_1._objectKeys(obj);
|
||||
var oldKeys = helpers_js_1._objectKeys(mirror);
|
||||
var changed = false;
|
||||
var deleted = false;
|
||||
//if ever "move" operation is implemented here, make sure this test runs OK: "should not generate the same patch twice (move)"
|
||||
for (var t = oldKeys.length - 1; t >= 0; t--) {
|
||||
var key = oldKeys[t];
|
||||
var oldVal = mirror[key];
|
||||
if (helpers_js_1.hasOwnProperty(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
|
||||
var newVal = obj[key];
|
||||
if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null && Array.isArray(oldVal) === Array.isArray(newVal)) {
|
||||
_generate(oldVal, newVal, patches, path + "/" + helpers_js_1.escapePathComponent(key), invertible);
|
||||
}
|
||||
else {
|
||||
if (oldVal !== newVal) {
|
||||
changed = true;
|
||||
if (invertible) {
|
||||
patches.push({ op: "test", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(oldVal) });
|
||||
}
|
||||
patches.push({ op: "replace", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(newVal) });
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Array.isArray(mirror) === Array.isArray(obj)) {
|
||||
if (invertible) {
|
||||
patches.push({ op: "test", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(oldVal) });
|
||||
}
|
||||
patches.push({ op: "remove", path: path + "/" + helpers_js_1.escapePathComponent(key) });
|
||||
deleted = true; // property has been deleted
|
||||
}
|
||||
else {
|
||||
if (invertible) {
|
||||
patches.push({ op: "test", path: path, value: mirror });
|
||||
}
|
||||
patches.push({ op: "replace", path: path, value: obj });
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (!deleted && newKeys.length == oldKeys.length) {
|
||||
return;
|
||||
}
|
||||
for (var t = 0; t < newKeys.length; t++) {
|
||||
var key = newKeys[t];
|
||||
if (!helpers_js_1.hasOwnProperty(mirror, key) && obj[key] !== undefined) {
|
||||
patches.push({ op: "add", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(obj[key]) });
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create an array of patches from the differences in two objects
|
||||
*/
|
||||
function compare(tree1, tree2, invertible) {
|
||||
if (invertible === void 0) { invertible = false; }
|
||||
var patches = [];
|
||||
_generate(tree1, tree2, patches, '', invertible);
|
||||
return patches;
|
||||
}
|
||||
exports.compare = compare;
|
||||
41
api.hyungi.net/node_modules/fast-json-patch/commonjs/helpers.d.ts
generated
vendored
Normal file
41
api.hyungi.net/node_modules/fast-json-patch/commonjs/helpers.d.ts
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
/*!
|
||||
* https://github.com/Starcounter-Jack/JSON-Patch
|
||||
* (c) 2017-2022 Joachim Wester
|
||||
* MIT licensed
|
||||
*/
|
||||
export declare function hasOwnProperty(obj: any, key: any): any;
|
||||
export declare function _objectKeys(obj: any): any[];
|
||||
/**
|
||||
* Deeply clone the object.
|
||||
* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
|
||||
* @param {any} obj value to clone
|
||||
* @return {any} cloned obj
|
||||
*/
|
||||
export declare function _deepClone(obj: any): any;
|
||||
export declare function isInteger(str: string): boolean;
|
||||
/**
|
||||
* Escapes a json pointer path
|
||||
* @param path The raw pointer
|
||||
* @return the Escaped path
|
||||
*/
|
||||
export declare function escapePathComponent(path: string): string;
|
||||
/**
|
||||
* Unescapes a json pointer path
|
||||
* @param path The escaped pointer
|
||||
* @return The unescaped path
|
||||
*/
|
||||
export declare function unescapePathComponent(path: string): string;
|
||||
export declare function _getPathRecursive(root: Object, obj: Object): string;
|
||||
export declare function getPath(root: Object, obj: Object): string;
|
||||
/**
|
||||
* Recursively checks whether an object has any undefined values inside.
|
||||
*/
|
||||
export declare function hasUndefined(obj: any): boolean;
|
||||
export declare type JsonPatchErrorName = 'SEQUENCE_NOT_AN_ARRAY' | 'OPERATION_NOT_AN_OBJECT' | 'OPERATION_OP_INVALID' | 'OPERATION_PATH_INVALID' | 'OPERATION_FROM_REQUIRED' | 'OPERATION_VALUE_REQUIRED' | 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED' | 'OPERATION_PATH_CANNOT_ADD' | 'OPERATION_PATH_UNRESOLVABLE' | 'OPERATION_FROM_UNRESOLVABLE' | 'OPERATION_PATH_ILLEGAL_ARRAY_INDEX' | 'OPERATION_VALUE_OUT_OF_BOUNDS' | 'TEST_OPERATION_FAILED';
|
||||
export declare class PatchError extends Error {
|
||||
name: JsonPatchErrorName;
|
||||
index?: number;
|
||||
operation?: any;
|
||||
tree?: any;
|
||||
constructor(message: string, name: JsonPatchErrorName, index?: number, operation?: any, tree?: any);
|
||||
}
|
||||
181
api.hyungi.net/node_modules/fast-json-patch/commonjs/helpers.js
generated
vendored
Normal file
181
api.hyungi.net/node_modules/fast-json-patch/commonjs/helpers.js
generated
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
/*!
|
||||
* https://github.com/Starcounter-Jack/JSON-Patch
|
||||
* (c) 2017-2022 Joachim Wester
|
||||
* MIT licensed
|
||||
*/
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
function hasOwnProperty(obj, key) {
|
||||
return _hasOwnProperty.call(obj, key);
|
||||
}
|
||||
exports.hasOwnProperty = hasOwnProperty;
|
||||
function _objectKeys(obj) {
|
||||
if (Array.isArray(obj)) {
|
||||
var keys_1 = new Array(obj.length);
|
||||
for (var k = 0; k < keys_1.length; k++) {
|
||||
keys_1[k] = "" + k;
|
||||
}
|
||||
return keys_1;
|
||||
}
|
||||
if (Object.keys) {
|
||||
return Object.keys(obj);
|
||||
}
|
||||
var keys = [];
|
||||
for (var i in obj) {
|
||||
if (hasOwnProperty(obj, i)) {
|
||||
keys.push(i);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
exports._objectKeys = _objectKeys;
|
||||
;
|
||||
/**
|
||||
* Deeply clone the object.
|
||||
* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
|
||||
* @param {any} obj value to clone
|
||||
* @return {any} cloned obj
|
||||
*/
|
||||
function _deepClone(obj) {
|
||||
switch (typeof obj) {
|
||||
case "object":
|
||||
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
|
||||
case "undefined":
|
||||
return null; //this is how JSON.stringify behaves for array items
|
||||
default:
|
||||
return obj; //no need to clone primitives
|
||||
}
|
||||
}
|
||||
exports._deepClone = _deepClone;
|
||||
//3x faster than cached /^\d+$/.test(str)
|
||||
function isInteger(str) {
|
||||
var i = 0;
|
||||
var len = str.length;
|
||||
var charCode;
|
||||
while (i < len) {
|
||||
charCode = str.charCodeAt(i);
|
||||
if (charCode >= 48 && charCode <= 57) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
exports.isInteger = isInteger;
|
||||
/**
|
||||
* Escapes a json pointer path
|
||||
* @param path The raw pointer
|
||||
* @return the Escaped path
|
||||
*/
|
||||
function escapePathComponent(path) {
|
||||
if (path.indexOf('/') === -1 && path.indexOf('~') === -1)
|
||||
return path;
|
||||
return path.replace(/~/g, '~0').replace(/\//g, '~1');
|
||||
}
|
||||
exports.escapePathComponent = escapePathComponent;
|
||||
/**
|
||||
* Unescapes a json pointer path
|
||||
* @param path The escaped pointer
|
||||
* @return The unescaped path
|
||||
*/
|
||||
function unescapePathComponent(path) {
|
||||
return path.replace(/~1/g, '/').replace(/~0/g, '~');
|
||||
}
|
||||
exports.unescapePathComponent = unescapePathComponent;
|
||||
function _getPathRecursive(root, obj) {
|
||||
var found;
|
||||
for (var key in root) {
|
||||
if (hasOwnProperty(root, key)) {
|
||||
if (root[key] === obj) {
|
||||
return escapePathComponent(key) + '/';
|
||||
}
|
||||
else if (typeof root[key] === 'object') {
|
||||
found = _getPathRecursive(root[key], obj);
|
||||
if (found != '') {
|
||||
return escapePathComponent(key) + '/' + found;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
exports._getPathRecursive = _getPathRecursive;
|
||||
function getPath(root, obj) {
|
||||
if (root === obj) {
|
||||
return '/';
|
||||
}
|
||||
var path = _getPathRecursive(root, obj);
|
||||
if (path === '') {
|
||||
throw new Error("Object not found in root");
|
||||
}
|
||||
return "/" + path;
|
||||
}
|
||||
exports.getPath = getPath;
|
||||
/**
|
||||
* Recursively checks whether an object has any undefined values inside.
|
||||
*/
|
||||
function hasUndefined(obj) {
|
||||
if (obj === undefined) {
|
||||
return true;
|
||||
}
|
||||
if (obj) {
|
||||
if (Array.isArray(obj)) {
|
||||
for (var i_1 = 0, len = obj.length; i_1 < len; i_1++) {
|
||||
if (hasUndefined(obj[i_1])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof obj === "object") {
|
||||
var objKeys = _objectKeys(obj);
|
||||
var objKeysLength = objKeys.length;
|
||||
for (var i = 0; i < objKeysLength; i++) {
|
||||
if (hasUndefined(obj[objKeys[i]])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.hasUndefined = hasUndefined;
|
||||
function patchErrorMessageFormatter(message, args) {
|
||||
var messageParts = [message];
|
||||
for (var key in args) {
|
||||
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
|
||||
if (typeof value !== 'undefined') {
|
||||
messageParts.push(key + ": " + value);
|
||||
}
|
||||
}
|
||||
return messageParts.join('\n');
|
||||
}
|
||||
var PatchError = /** @class */ (function (_super) {
|
||||
__extends(PatchError, _super);
|
||||
function PatchError(message, name, index, operation, tree) {
|
||||
var _newTarget = this.constructor;
|
||||
var _this = _super.call(this, patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree })) || this;
|
||||
_this.name = name;
|
||||
_this.index = index;
|
||||
_this.operation = operation;
|
||||
_this.tree = tree;
|
||||
Object.setPrototypeOf(_this, _newTarget.prototype); // restore prototype chain, see https://stackoverflow.com/a/48342359
|
||||
_this.message = patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree });
|
||||
return _this;
|
||||
}
|
||||
return PatchError;
|
||||
}(Error));
|
||||
exports.PatchError = PatchError;
|
||||
928
api.hyungi.net/node_modules/fast-json-patch/dist/fast-json-patch.js
generated
vendored
Normal file
928
api.hyungi.net/node_modules/fast-json-patch/dist/fast-json-patch.js
generated
vendored
Normal file
@@ -0,0 +1,928 @@
|
||||
/*! fast-json-patch, version: 3.1.1 */
|
||||
var jsonpatch =
|
||||
/******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if(installedModules[moduleId]) {
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ i: moduleId,
|
||||
/******/ l: false,
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.l = true;
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
/******/
|
||||
/******/
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
/******/
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
/******/
|
||||
/******/ // define getter function for harmony exports
|
||||
/******/ __webpack_require__.d = function(exports, name, getter) {
|
||||
/******/ if(!__webpack_require__.o(exports, name)) {
|
||||
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
||||
/******/ }
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // define __esModule on exports
|
||||
/******/ __webpack_require__.r = function(exports) {
|
||||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
||||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||
/******/ }
|
||||
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // create a fake namespace object
|
||||
/******/ // mode & 1: value is a module id, require it
|
||||
/******/ // mode & 2: merge all properties of value into the ns
|
||||
/******/ // mode & 4: return value when already ns object
|
||||
/******/ // mode & 8|1: behave like require
|
||||
/******/ __webpack_require__.t = function(value, mode) {
|
||||
/******/ if(mode & 1) value = __webpack_require__(value);
|
||||
/******/ if(mode & 8) return value;
|
||||
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
||||
/******/ var ns = Object.create(null);
|
||||
/******/ __webpack_require__.r(ns);
|
||||
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
||||
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
||||
/******/ return ns;
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||
/******/ __webpack_require__.n = function(module) {
|
||||
/******/ var getter = module && module.__esModule ?
|
||||
/******/ function getDefault() { return module['default']; } :
|
||||
/******/ function getModuleExports() { return module; };
|
||||
/******/ __webpack_require__.d(getter, 'a', getter);
|
||||
/******/ return getter;
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Object.prototype.hasOwnProperty.call
|
||||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
||||
/******/
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "";
|
||||
/******/
|
||||
/******/
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(__webpack_require__.s = 2);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ([
|
||||
/* 0 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
/*!
|
||||
* https://github.com/Starcounter-Jack/JSON-Patch
|
||||
* (c) 2017-2022 Joachim Wester
|
||||
* MIT licensed
|
||||
*/
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
function hasOwnProperty(obj, key) {
|
||||
return _hasOwnProperty.call(obj, key);
|
||||
}
|
||||
exports.hasOwnProperty = hasOwnProperty;
|
||||
function _objectKeys(obj) {
|
||||
if (Array.isArray(obj)) {
|
||||
var keys_1 = new Array(obj.length);
|
||||
for (var k = 0; k < keys_1.length; k++) {
|
||||
keys_1[k] = "" + k;
|
||||
}
|
||||
return keys_1;
|
||||
}
|
||||
if (Object.keys) {
|
||||
return Object.keys(obj);
|
||||
}
|
||||
var keys = [];
|
||||
for (var i in obj) {
|
||||
if (hasOwnProperty(obj, i)) {
|
||||
keys.push(i);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
exports._objectKeys = _objectKeys;
|
||||
;
|
||||
/**
|
||||
* Deeply clone the object.
|
||||
* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
|
||||
* @param {any} obj value to clone
|
||||
* @return {any} cloned obj
|
||||
*/
|
||||
function _deepClone(obj) {
|
||||
switch (typeof obj) {
|
||||
case "object":
|
||||
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
|
||||
case "undefined":
|
||||
return null; //this is how JSON.stringify behaves for array items
|
||||
default:
|
||||
return obj; //no need to clone primitives
|
||||
}
|
||||
}
|
||||
exports._deepClone = _deepClone;
|
||||
//3x faster than cached /^\d+$/.test(str)
|
||||
function isInteger(str) {
|
||||
var i = 0;
|
||||
var len = str.length;
|
||||
var charCode;
|
||||
while (i < len) {
|
||||
charCode = str.charCodeAt(i);
|
||||
if (charCode >= 48 && charCode <= 57) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
exports.isInteger = isInteger;
|
||||
/**
|
||||
* Escapes a json pointer path
|
||||
* @param path The raw pointer
|
||||
* @return the Escaped path
|
||||
*/
|
||||
function escapePathComponent(path) {
|
||||
if (path.indexOf('/') === -1 && path.indexOf('~') === -1)
|
||||
return path;
|
||||
return path.replace(/~/g, '~0').replace(/\//g, '~1');
|
||||
}
|
||||
exports.escapePathComponent = escapePathComponent;
|
||||
/**
|
||||
* Unescapes a json pointer path
|
||||
* @param path The escaped pointer
|
||||
* @return The unescaped path
|
||||
*/
|
||||
function unescapePathComponent(path) {
|
||||
return path.replace(/~1/g, '/').replace(/~0/g, '~');
|
||||
}
|
||||
exports.unescapePathComponent = unescapePathComponent;
|
||||
function _getPathRecursive(root, obj) {
|
||||
var found;
|
||||
for (var key in root) {
|
||||
if (hasOwnProperty(root, key)) {
|
||||
if (root[key] === obj) {
|
||||
return escapePathComponent(key) + '/';
|
||||
}
|
||||
else if (typeof root[key] === 'object') {
|
||||
found = _getPathRecursive(root[key], obj);
|
||||
if (found != '') {
|
||||
return escapePathComponent(key) + '/' + found;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
exports._getPathRecursive = _getPathRecursive;
|
||||
function getPath(root, obj) {
|
||||
if (root === obj) {
|
||||
return '/';
|
||||
}
|
||||
var path = _getPathRecursive(root, obj);
|
||||
if (path === '') {
|
||||
throw new Error("Object not found in root");
|
||||
}
|
||||
return "/" + path;
|
||||
}
|
||||
exports.getPath = getPath;
|
||||
/**
|
||||
* Recursively checks whether an object has any undefined values inside.
|
||||
*/
|
||||
function hasUndefined(obj) {
|
||||
if (obj === undefined) {
|
||||
return true;
|
||||
}
|
||||
if (obj) {
|
||||
if (Array.isArray(obj)) {
|
||||
for (var i_1 = 0, len = obj.length; i_1 < len; i_1++) {
|
||||
if (hasUndefined(obj[i_1])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof obj === "object") {
|
||||
var objKeys = _objectKeys(obj);
|
||||
var objKeysLength = objKeys.length;
|
||||
for (var i = 0; i < objKeysLength; i++) {
|
||||
if (hasUndefined(obj[objKeys[i]])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.hasUndefined = hasUndefined;
|
||||
function patchErrorMessageFormatter(message, args) {
|
||||
var messageParts = [message];
|
||||
for (var key in args) {
|
||||
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
|
||||
if (typeof value !== 'undefined') {
|
||||
messageParts.push(key + ": " + value);
|
||||
}
|
||||
}
|
||||
return messageParts.join('\n');
|
||||
}
|
||||
var PatchError = /** @class */ (function (_super) {
|
||||
__extends(PatchError, _super);
|
||||
function PatchError(message, name, index, operation, tree) {
|
||||
var _newTarget = this.constructor;
|
||||
var _this = _super.call(this, patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree })) || this;
|
||||
_this.name = name;
|
||||
_this.index = index;
|
||||
_this.operation = operation;
|
||||
_this.tree = tree;
|
||||
Object.setPrototypeOf(_this, _newTarget.prototype); // restore prototype chain, see https://stackoverflow.com/a/48342359
|
||||
_this.message = patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree });
|
||||
return _this;
|
||||
}
|
||||
return PatchError;
|
||||
}(Error));
|
||||
exports.PatchError = PatchError;
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 1 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var helpers_js_1 = __webpack_require__(0);
|
||||
exports.JsonPatchError = helpers_js_1.PatchError;
|
||||
exports.deepClone = helpers_js_1._deepClone;
|
||||
/* We use a Javascript hash to store each
|
||||
function. Each hash entry (property) uses
|
||||
the operation identifiers specified in rfc6902.
|
||||
In this way, we can map each patch operation
|
||||
to its dedicated function in efficient way.
|
||||
*/
|
||||
/* The operations applicable to an object */
|
||||
var objOps = {
|
||||
add: function (obj, key, document) {
|
||||
obj[key] = this.value;
|
||||
return { newDocument: document };
|
||||
},
|
||||
remove: function (obj, key, document) {
|
||||
var removed = obj[key];
|
||||
delete obj[key];
|
||||
return { newDocument: document, removed: removed };
|
||||
},
|
||||
replace: function (obj, key, document) {
|
||||
var removed = obj[key];
|
||||
obj[key] = this.value;
|
||||
return { newDocument: document, removed: removed };
|
||||
},
|
||||
move: function (obj, key, document) {
|
||||
/* in case move target overwrites an existing value,
|
||||
return the removed value, this can be taxing performance-wise,
|
||||
and is potentially unneeded */
|
||||
var removed = getValueByPointer(document, this.path);
|
||||
if (removed) {
|
||||
removed = helpers_js_1._deepClone(removed);
|
||||
}
|
||||
var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed;
|
||||
applyOperation(document, { op: "add", path: this.path, value: originalValue });
|
||||
return { newDocument: document, removed: removed };
|
||||
},
|
||||
copy: function (obj, key, document) {
|
||||
var valueToCopy = getValueByPointer(document, this.from);
|
||||
// enforce copy by value so further operations don't affect source (see issue #177)
|
||||
applyOperation(document, { op: "add", path: this.path, value: helpers_js_1._deepClone(valueToCopy) });
|
||||
return { newDocument: document };
|
||||
},
|
||||
test: function (obj, key, document) {
|
||||
return { newDocument: document, test: _areEquals(obj[key], this.value) };
|
||||
},
|
||||
_get: function (obj, key, document) {
|
||||
this.value = obj[key];
|
||||
return { newDocument: document };
|
||||
}
|
||||
};
|
||||
/* The operations applicable to an array. Many are the same as for the object */
|
||||
var arrOps = {
|
||||
add: function (arr, i, document) {
|
||||
if (helpers_js_1.isInteger(i)) {
|
||||
arr.splice(i, 0, this.value);
|
||||
}
|
||||
else { // array props
|
||||
arr[i] = this.value;
|
||||
}
|
||||
// this may be needed when using '-' in an array
|
||||
return { newDocument: document, index: i };
|
||||
},
|
||||
remove: function (arr, i, document) {
|
||||
var removedList = arr.splice(i, 1);
|
||||
return { newDocument: document, removed: removedList[0] };
|
||||
},
|
||||
replace: function (arr, i, document) {
|
||||
var removed = arr[i];
|
||||
arr[i] = this.value;
|
||||
return { newDocument: document, removed: removed };
|
||||
},
|
||||
move: objOps.move,
|
||||
copy: objOps.copy,
|
||||
test: objOps.test,
|
||||
_get: objOps._get
|
||||
};
|
||||
/**
|
||||
* Retrieves a value from a JSON document by a JSON pointer.
|
||||
* Returns the value.
|
||||
*
|
||||
* @param document The document to get the value from
|
||||
* @param pointer an escaped JSON pointer
|
||||
* @return The retrieved value
|
||||
*/
|
||||
function getValueByPointer(document, pointer) {
|
||||
if (pointer == '') {
|
||||
return document;
|
||||
}
|
||||
var getOriginalDestination = { op: "_get", path: pointer };
|
||||
applyOperation(document, getOriginalDestination);
|
||||
return getOriginalDestination.value;
|
||||
}
|
||||
exports.getValueByPointer = getValueByPointer;
|
||||
/**
|
||||
* Apply a single JSON Patch Operation on a JSON document.
|
||||
* Returns the {newDocument, result} of the operation.
|
||||
* It modifies the `document` and `operation` objects - it gets the values by reference.
|
||||
* If you would like to avoid touching your values, clone them:
|
||||
* `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.
|
||||
*
|
||||
* @param document The document to patch
|
||||
* @param operation The operation to apply
|
||||
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
||||
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
||||
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
||||
* @return `{newDocument, result}` after the operation
|
||||
*/
|
||||
function applyOperation(document, operation, validateOperation, mutateDocument, banPrototypeModifications, index) {
|
||||
if (validateOperation === void 0) { validateOperation = false; }
|
||||
if (mutateDocument === void 0) { mutateDocument = true; }
|
||||
if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
|
||||
if (index === void 0) { index = 0; }
|
||||
if (validateOperation) {
|
||||
if (typeof validateOperation == 'function') {
|
||||
validateOperation(operation, 0, document, operation.path);
|
||||
}
|
||||
else {
|
||||
validator(operation, 0);
|
||||
}
|
||||
}
|
||||
/* ROOT OPERATIONS */
|
||||
if (operation.path === "") {
|
||||
var returnValue = { newDocument: document };
|
||||
if (operation.op === 'add') {
|
||||
returnValue.newDocument = operation.value;
|
||||
return returnValue;
|
||||
}
|
||||
else if (operation.op === 'replace') {
|
||||
returnValue.newDocument = operation.value;
|
||||
returnValue.removed = document; //document we removed
|
||||
return returnValue;
|
||||
}
|
||||
else if (operation.op === 'move' || operation.op === 'copy') { // it's a move or copy to root
|
||||
returnValue.newDocument = getValueByPointer(document, operation.from); // get the value by json-pointer in `from` field
|
||||
if (operation.op === 'move') { // report removed item
|
||||
returnValue.removed = document;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
else if (operation.op === 'test') {
|
||||
returnValue.test = _areEquals(document, operation.value);
|
||||
if (returnValue.test === false) {
|
||||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
||||
}
|
||||
returnValue.newDocument = document;
|
||||
return returnValue;
|
||||
}
|
||||
else if (operation.op === 'remove') { // a remove on root
|
||||
returnValue.removed = document;
|
||||
returnValue.newDocument = null;
|
||||
return returnValue;
|
||||
}
|
||||
else if (operation.op === '_get') {
|
||||
operation.value = document;
|
||||
return returnValue;
|
||||
}
|
||||
else { /* bad operation */
|
||||
if (validateOperation) {
|
||||
throw new exports.JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);
|
||||
}
|
||||
else {
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
} /* END ROOT OPERATIONS */
|
||||
else {
|
||||
if (!mutateDocument) {
|
||||
document = helpers_js_1._deepClone(document);
|
||||
}
|
||||
var path = operation.path || "";
|
||||
var keys = path.split('/');
|
||||
var obj = document;
|
||||
var t = 1; //skip empty element - http://jsperf.com/to-shift-or-not-to-shift
|
||||
var len = keys.length;
|
||||
var existingPathFragment = undefined;
|
||||
var key = void 0;
|
||||
var validateFunction = void 0;
|
||||
if (typeof validateOperation == 'function') {
|
||||
validateFunction = validateOperation;
|
||||
}
|
||||
else {
|
||||
validateFunction = validator;
|
||||
}
|
||||
while (true) {
|
||||
key = keys[t];
|
||||
if (key && key.indexOf('~') != -1) {
|
||||
key = helpers_js_1.unescapePathComponent(key);
|
||||
}
|
||||
if (banPrototypeModifications &&
|
||||
(key == '__proto__' ||
|
||||
(key == 'prototype' && t > 0 && keys[t - 1] == 'constructor'))) {
|
||||
throw new TypeError('JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README');
|
||||
}
|
||||
if (validateOperation) {
|
||||
if (existingPathFragment === undefined) {
|
||||
if (obj[key] === undefined) {
|
||||
existingPathFragment = keys.slice(0, t).join('/');
|
||||
}
|
||||
else if (t == len - 1) {
|
||||
existingPathFragment = operation.path;
|
||||
}
|
||||
if (existingPathFragment !== undefined) {
|
||||
validateFunction(operation, 0, document, existingPathFragment);
|
||||
}
|
||||
}
|
||||
}
|
||||
t++;
|
||||
if (Array.isArray(obj)) {
|
||||
if (key === '-') {
|
||||
key = obj.length;
|
||||
}
|
||||
else {
|
||||
if (validateOperation && !helpers_js_1.isInteger(key)) {
|
||||
throw new exports.JsonPatchError("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", index, operation, document);
|
||||
} // only parse key when it's an integer for `arr.prop` to work
|
||||
else if (helpers_js_1.isInteger(key)) {
|
||||
key = ~~key;
|
||||
}
|
||||
}
|
||||
if (t >= len) {
|
||||
if (validateOperation && operation.op === "add" && key > obj.length) {
|
||||
throw new exports.JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", index, operation, document);
|
||||
}
|
||||
var returnValue = arrOps[operation.op].call(operation, obj, key, document); // Apply patch
|
||||
if (returnValue.test === false) {
|
||||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (t >= len) {
|
||||
var returnValue = objOps[operation.op].call(operation, obj, key, document); // Apply patch
|
||||
if (returnValue.test === false) {
|
||||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
obj = obj[key];
|
||||
// If we have more keys in the path, but the next value isn't a non-null object,
|
||||
// throw an OPERATION_PATH_UNRESOLVABLE error instead of iterating again.
|
||||
if (validateOperation && t < len && (!obj || typeof obj !== "object")) {
|
||||
throw new exports.JsonPatchError('Cannot perform operation at the desired path', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.applyOperation = applyOperation;
|
||||
/**
|
||||
* Apply a full JSON Patch array on a JSON document.
|
||||
* Returns the {newDocument, result} of the patch.
|
||||
* It modifies the `document` object and `patch` - it gets the values by reference.
|
||||
* If you would like to avoid touching your values, clone them:
|
||||
* `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.
|
||||
*
|
||||
* @param document The document to patch
|
||||
* @param patch The patch to apply
|
||||
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
||||
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
||||
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
||||
* @return An array of `{newDocument, result}` after the patch
|
||||
*/
|
||||
function applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) {
|
||||
if (mutateDocument === void 0) { mutateDocument = true; }
|
||||
if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
|
||||
if (validateOperation) {
|
||||
if (!Array.isArray(patch)) {
|
||||
throw new exports.JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
|
||||
}
|
||||
}
|
||||
if (!mutateDocument) {
|
||||
document = helpers_js_1._deepClone(document);
|
||||
}
|
||||
var results = new Array(patch.length);
|
||||
for (var i = 0, length_1 = patch.length; i < length_1; i++) {
|
||||
// we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`
|
||||
results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);
|
||||
document = results[i].newDocument; // in case root was replaced
|
||||
}
|
||||
results.newDocument = document;
|
||||
return results;
|
||||
}
|
||||
exports.applyPatch = applyPatch;
|
||||
/**
|
||||
* Apply a single JSON Patch Operation on a JSON document.
|
||||
* Returns the updated document.
|
||||
* Suitable as a reducer.
|
||||
*
|
||||
* @param document The document to patch
|
||||
* @param operation The operation to apply
|
||||
* @return The updated document
|
||||
*/
|
||||
function applyReducer(document, operation, index) {
|
||||
var operationResult = applyOperation(document, operation);
|
||||
if (operationResult.test === false) { // failed test
|
||||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
||||
}
|
||||
return operationResult.newDocument;
|
||||
}
|
||||
exports.applyReducer = applyReducer;
|
||||
/**
|
||||
* Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.
|
||||
* @param {object} operation - operation object (patch)
|
||||
* @param {number} index - index of operation in the sequence
|
||||
* @param {object} [document] - object where the operation is supposed to be applied
|
||||
* @param {string} [existingPathFragment] - comes along with `document`
|
||||
*/
|
||||
function validator(operation, index, document, existingPathFragment) {
|
||||
if (typeof operation !== 'object' || operation === null || Array.isArray(operation)) {
|
||||
throw new exports.JsonPatchError('Operation is not an object', 'OPERATION_NOT_AN_OBJECT', index, operation, document);
|
||||
}
|
||||
else if (!objOps[operation.op]) {
|
||||
throw new exports.JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);
|
||||
}
|
||||
else if (typeof operation.path !== 'string') {
|
||||
throw new exports.JsonPatchError('Operation `path` property is not a string', 'OPERATION_PATH_INVALID', index, operation, document);
|
||||
}
|
||||
else if (operation.path.indexOf('/') !== 0 && operation.path.length > 0) {
|
||||
// paths that aren't empty string should start with "/"
|
||||
throw new exports.JsonPatchError('Operation `path` property must start with "/"', 'OPERATION_PATH_INVALID', index, operation, document);
|
||||
}
|
||||
else if ((operation.op === 'move' || operation.op === 'copy') && typeof operation.from !== 'string') {
|
||||
throw new exports.JsonPatchError('Operation `from` property is not present (applicable in `move` and `copy` operations)', 'OPERATION_FROM_REQUIRED', index, operation, document);
|
||||
}
|
||||
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && operation.value === undefined) {
|
||||
throw new exports.JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document);
|
||||
}
|
||||
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && helpers_js_1.hasUndefined(operation.value)) {
|
||||
throw new exports.JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, document);
|
||||
}
|
||||
else if (document) {
|
||||
if (operation.op == "add") {
|
||||
var pathLen = operation.path.split("/").length;
|
||||
var existingPathLen = existingPathFragment.split("/").length;
|
||||
if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {
|
||||
throw new exports.JsonPatchError('Cannot perform an `add` operation at the desired path', 'OPERATION_PATH_CANNOT_ADD', index, operation, document);
|
||||
}
|
||||
}
|
||||
else if (operation.op === 'replace' || operation.op === 'remove' || operation.op === '_get') {
|
||||
if (operation.path !== existingPathFragment) {
|
||||
throw new exports.JsonPatchError('Cannot perform the operation at a path that does not exist', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);
|
||||
}
|
||||
}
|
||||
else if (operation.op === 'move' || operation.op === 'copy') {
|
||||
var existingValue = { op: "_get", path: operation.from, value: undefined };
|
||||
var error = validate([existingValue], document);
|
||||
if (error && error.name === 'OPERATION_PATH_UNRESOLVABLE') {
|
||||
throw new exports.JsonPatchError('Cannot perform the operation from a path that does not exist', 'OPERATION_FROM_UNRESOLVABLE', index, operation, document);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.validator = validator;
|
||||
/**
|
||||
* Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.
|
||||
* If error is encountered, returns a JsonPatchError object
|
||||
* @param sequence
|
||||
* @param document
|
||||
* @returns {JsonPatchError|undefined}
|
||||
*/
|
||||
function validate(sequence, document, externalValidator) {
|
||||
try {
|
||||
if (!Array.isArray(sequence)) {
|
||||
throw new exports.JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
|
||||
}
|
||||
if (document) {
|
||||
//clone document and sequence so that we can safely try applying operations
|
||||
applyPatch(helpers_js_1._deepClone(document), helpers_js_1._deepClone(sequence), externalValidator || true);
|
||||
}
|
||||
else {
|
||||
externalValidator = externalValidator || validator;
|
||||
for (var i = 0; i < sequence.length; i++) {
|
||||
externalValidator(sequence[i], i, document, undefined);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
if (e instanceof exports.JsonPatchError) {
|
||||
return e;
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.validate = validate;
|
||||
// based on https://github.com/epoberezkin/fast-deep-equal
|
||||
// MIT License
|
||||
// Copyright (c) 2017 Evgeny Poberezkin
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
function _areEquals(a, b) {
|
||||
if (a === b)
|
||||
return true;
|
||||
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
||||
var arrA = Array.isArray(a), arrB = Array.isArray(b), i, length, key;
|
||||
if (arrA && arrB) {
|
||||
length = a.length;
|
||||
if (length != b.length)
|
||||
return false;
|
||||
for (i = length; i-- !== 0;)
|
||||
if (!_areEquals(a[i], b[i]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
if (arrA != arrB)
|
||||
return false;
|
||||
var keys = Object.keys(a);
|
||||
length = keys.length;
|
||||
if (length !== Object.keys(b).length)
|
||||
return false;
|
||||
for (i = length; i-- !== 0;)
|
||||
if (!b.hasOwnProperty(keys[i]))
|
||||
return false;
|
||||
for (i = length; i-- !== 0;) {
|
||||
key = keys[i];
|
||||
if (!_areEquals(a[key], b[key]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return a !== a && b !== b;
|
||||
}
|
||||
exports._areEquals = _areEquals;
|
||||
;
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 2 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
var core = __webpack_require__(1);
|
||||
Object.assign(exports, core);
|
||||
|
||||
var duplex = __webpack_require__(3);
|
||||
Object.assign(exports, duplex);
|
||||
|
||||
var helpers = __webpack_require__(0);
|
||||
exports.JsonPatchError = helpers.PatchError;
|
||||
exports.deepClone = helpers._deepClone;
|
||||
exports.escapePathComponent = helpers.escapePathComponent;
|
||||
exports.unescapePathComponent = helpers.unescapePathComponent;
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 3 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/*!
|
||||
* https://github.com/Starcounter-Jack/JSON-Patch
|
||||
* (c) 2017-2021 Joachim Wester
|
||||
* MIT license
|
||||
*/
|
||||
var helpers_js_1 = __webpack_require__(0);
|
||||
var core_js_1 = __webpack_require__(1);
|
||||
var beforeDict = new WeakMap();
|
||||
var Mirror = /** @class */ (function () {
|
||||
function Mirror(obj) {
|
||||
this.observers = new Map();
|
||||
this.obj = obj;
|
||||
}
|
||||
return Mirror;
|
||||
}());
|
||||
var ObserverInfo = /** @class */ (function () {
|
||||
function ObserverInfo(callback, observer) {
|
||||
this.callback = callback;
|
||||
this.observer = observer;
|
||||
}
|
||||
return ObserverInfo;
|
||||
}());
|
||||
function getMirror(obj) {
|
||||
return beforeDict.get(obj);
|
||||
}
|
||||
function getObserverFromMirror(mirror, callback) {
|
||||
return mirror.observers.get(callback);
|
||||
}
|
||||
function removeObserverFromMirror(mirror, observer) {
|
||||
mirror.observers.delete(observer.callback);
|
||||
}
|
||||
/**
|
||||
* Detach an observer from an object
|
||||
*/
|
||||
function unobserve(root, observer) {
|
||||
observer.unobserve();
|
||||
}
|
||||
exports.unobserve = unobserve;
|
||||
/**
|
||||
* Observes changes made to an object, which can then be retrieved using generate
|
||||
*/
|
||||
function observe(obj, callback) {
|
||||
var patches = [];
|
||||
var observer;
|
||||
var mirror = getMirror(obj);
|
||||
if (!mirror) {
|
||||
mirror = new Mirror(obj);
|
||||
beforeDict.set(obj, mirror);
|
||||
}
|
||||
else {
|
||||
var observerInfo = getObserverFromMirror(mirror, callback);
|
||||
observer = observerInfo && observerInfo.observer;
|
||||
}
|
||||
if (observer) {
|
||||
return observer;
|
||||
}
|
||||
observer = {};
|
||||
mirror.value = helpers_js_1._deepClone(obj);
|
||||
if (callback) {
|
||||
observer.callback = callback;
|
||||
observer.next = null;
|
||||
var dirtyCheck = function () {
|
||||
generate(observer);
|
||||
};
|
||||
var fastCheck = function () {
|
||||
clearTimeout(observer.next);
|
||||
observer.next = setTimeout(dirtyCheck);
|
||||
};
|
||||
if (typeof window !== 'undefined') { //not Node
|
||||
window.addEventListener('mouseup', fastCheck);
|
||||
window.addEventListener('keyup', fastCheck);
|
||||
window.addEventListener('mousedown', fastCheck);
|
||||
window.addEventListener('keydown', fastCheck);
|
||||
window.addEventListener('change', fastCheck);
|
||||
}
|
||||
}
|
||||
observer.patches = patches;
|
||||
observer.object = obj;
|
||||
observer.unobserve = function () {
|
||||
generate(observer);
|
||||
clearTimeout(observer.next);
|
||||
removeObserverFromMirror(mirror, observer);
|
||||
if (typeof window !== 'undefined') {
|
||||
window.removeEventListener('mouseup', fastCheck);
|
||||
window.removeEventListener('keyup', fastCheck);
|
||||
window.removeEventListener('mousedown', fastCheck);
|
||||
window.removeEventListener('keydown', fastCheck);
|
||||
window.removeEventListener('change', fastCheck);
|
||||
}
|
||||
};
|
||||
mirror.observers.set(callback, new ObserverInfo(callback, observer));
|
||||
return observer;
|
||||
}
|
||||
exports.observe = observe;
|
||||
/**
|
||||
* Generate an array of patches from an observer
|
||||
*/
|
||||
function generate(observer, invertible) {
|
||||
if (invertible === void 0) { invertible = false; }
|
||||
var mirror = beforeDict.get(observer.object);
|
||||
_generate(mirror.value, observer.object, observer.patches, "", invertible);
|
||||
if (observer.patches.length) {
|
||||
core_js_1.applyPatch(mirror.value, observer.patches);
|
||||
}
|
||||
var temp = observer.patches;
|
||||
if (temp.length > 0) {
|
||||
observer.patches = [];
|
||||
if (observer.callback) {
|
||||
observer.callback(temp);
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
exports.generate = generate;
|
||||
// Dirty check if obj is different from mirror, generate patches and update mirror
|
||||
function _generate(mirror, obj, patches, path, invertible) {
|
||||
if (obj === mirror) {
|
||||
return;
|
||||
}
|
||||
if (typeof obj.toJSON === "function") {
|
||||
obj = obj.toJSON();
|
||||
}
|
||||
var newKeys = helpers_js_1._objectKeys(obj);
|
||||
var oldKeys = helpers_js_1._objectKeys(mirror);
|
||||
var changed = false;
|
||||
var deleted = false;
|
||||
//if ever "move" operation is implemented here, make sure this test runs OK: "should not generate the same patch twice (move)"
|
||||
for (var t = oldKeys.length - 1; t >= 0; t--) {
|
||||
var key = oldKeys[t];
|
||||
var oldVal = mirror[key];
|
||||
if (helpers_js_1.hasOwnProperty(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
|
||||
var newVal = obj[key];
|
||||
if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null && Array.isArray(oldVal) === Array.isArray(newVal)) {
|
||||
_generate(oldVal, newVal, patches, path + "/" + helpers_js_1.escapePathComponent(key), invertible);
|
||||
}
|
||||
else {
|
||||
if (oldVal !== newVal) {
|
||||
changed = true;
|
||||
if (invertible) {
|
||||
patches.push({ op: "test", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(oldVal) });
|
||||
}
|
||||
patches.push({ op: "replace", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(newVal) });
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Array.isArray(mirror) === Array.isArray(obj)) {
|
||||
if (invertible) {
|
||||
patches.push({ op: "test", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(oldVal) });
|
||||
}
|
||||
patches.push({ op: "remove", path: path + "/" + helpers_js_1.escapePathComponent(key) });
|
||||
deleted = true; // property has been deleted
|
||||
}
|
||||
else {
|
||||
if (invertible) {
|
||||
patches.push({ op: "test", path: path, value: mirror });
|
||||
}
|
||||
patches.push({ op: "replace", path: path, value: obj });
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (!deleted && newKeys.length == oldKeys.length) {
|
||||
return;
|
||||
}
|
||||
for (var t = 0; t < newKeys.length; t++) {
|
||||
var key = newKeys[t];
|
||||
if (!helpers_js_1.hasOwnProperty(mirror, key) && obj[key] !== undefined) {
|
||||
patches.push({ op: "add", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(obj[key]) });
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create an array of patches from the differences in two objects
|
||||
*/
|
||||
function compare(tree1, tree2, invertible) {
|
||||
if (invertible === void 0) { invertible = false; }
|
||||
var patches = [];
|
||||
_generate(tree1, tree2, patches, '', invertible);
|
||||
return patches;
|
||||
}
|
||||
exports.compare = compare;
|
||||
|
||||
|
||||
/***/ })
|
||||
/******/ ]);
|
||||
14
api.hyungi.net/node_modules/fast-json-patch/dist/fast-json-patch.min.js
generated
vendored
Normal file
14
api.hyungi.net/node_modules/fast-json-patch/dist/fast-json-patch.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
34
api.hyungi.net/node_modules/fast-json-patch/index.d.ts
generated
vendored
Normal file
34
api.hyungi.net/node_modules/fast-json-patch/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
export * from './module/core';
|
||||
export * from './module/duplex';
|
||||
export {
|
||||
PatchError as JsonPatchError,
|
||||
_deepClone as deepClone,
|
||||
escapePathComponent,
|
||||
unescapePathComponent
|
||||
} from './module/helpers';
|
||||
|
||||
|
||||
/**
|
||||
* Default export for backwards compat
|
||||
*/
|
||||
import * as core from './module/core';
|
||||
import * as duplex from './module/duplex';
|
||||
import { PatchError as JsonPatchError, _deepClone as deepClone, escapePathComponent, unescapePathComponent } from './module/helpers';
|
||||
declare const _default: {
|
||||
JsonPatchError: typeof JsonPatchError;
|
||||
deepClone: typeof deepClone;
|
||||
escapePathComponent: typeof escapePathComponent;
|
||||
unescapePathComponent: typeof unescapePathComponent;
|
||||
unobserve<T>(root: T, observer: duplex.Observer<T>): void;
|
||||
observe<T>(obj: Object | T[], callback?: (patches: core.Operation[]) => void): duplex.Observer<T>;
|
||||
generate<T>(observer: duplex.Observer<Object>, invertible?: boolean): core.Operation[];
|
||||
compare(tree1: Object | any[], tree2: Object | any[], invertible?: boolean): core.Operation[];
|
||||
getValueByPointer(document: any, pointer: string): any;
|
||||
applyOperation<T>(document: T, operation: core.Operation, validateOperation?: boolean | core.Validator<T>, mutateDocument?: boolean, banPrototypeModifications?: boolean, index?: number): core.OperationResult<T>;
|
||||
applyPatch<T>(document: T, patch: core.Operation[], validateOperation?: boolean | core.Validator<T>, mutateDocument?: boolean, banPrototypeModifications?: boolean): core.PatchResult<T>;
|
||||
applyReducer<T>(document: T, operation: core.Operation, index: number): T;
|
||||
validator(operation: core.Operation, index: number, document?: any, existingPathFragment?: string): void;
|
||||
validate<T>(sequence: core.Operation[], document?: T, externalValidator?: core.Validator<T>): JsonPatchError;
|
||||
_areEquals(a: any, b: any): boolean;
|
||||
};
|
||||
export default _default;
|
||||
11
api.hyungi.net/node_modules/fast-json-patch/index.js
generated
vendored
Normal file
11
api.hyungi.net/node_modules/fast-json-patch/index.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
var core = require("./commonjs/core.js");
|
||||
Object.assign(exports, core);
|
||||
|
||||
var duplex = require("./commonjs/duplex.js");
|
||||
Object.assign(exports, duplex);
|
||||
|
||||
var helpers = require("./commonjs/helpers.js");
|
||||
exports.JsonPatchError = helpers.PatchError;
|
||||
exports.deepClone = helpers._deepClone;
|
||||
exports.escapePathComponent = helpers.escapePathComponent;
|
||||
exports.unescapePathComponent = helpers.unescapePathComponent;
|
||||
29
api.hyungi.net/node_modules/fast-json-patch/index.mjs
generated
vendored
Normal file
29
api.hyungi.net/node_modules/fast-json-patch/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
export * from './module/core.mjs';
|
||||
export * from './module/duplex.mjs';
|
||||
export {
|
||||
PatchError as JsonPatchError,
|
||||
_deepClone as deepClone,
|
||||
escapePathComponent,
|
||||
unescapePathComponent
|
||||
} from './module/helpers.mjs';
|
||||
|
||||
|
||||
/**
|
||||
* Default export for backwards compat
|
||||
*/
|
||||
|
||||
import * as core from './module/core.mjs';
|
||||
import * as duplex from './module/duplex.mjs';
|
||||
import {
|
||||
PatchError as JsonPatchError,
|
||||
_deepClone as deepClone,
|
||||
escapePathComponent,
|
||||
unescapePathComponent
|
||||
} from './module/helpers.mjs';
|
||||
|
||||
export default Object.assign({}, core, duplex, {
|
||||
JsonPatchError,
|
||||
deepClone,
|
||||
escapePathComponent,
|
||||
unescapePathComponent
|
||||
});
|
||||
31
api.hyungi.net/node_modules/fast-json-patch/index.ts
generated
vendored
Normal file
31
api.hyungi.net/node_modules/fast-json-patch/index.ts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
export * from './src/core';
|
||||
export * from './src/duplex';
|
||||
export {
|
||||
PatchError as JsonPatchError,
|
||||
_deepClone as deepClone,
|
||||
escapePathComponent,
|
||||
unescapePathComponent
|
||||
} from './src/helpers';
|
||||
|
||||
|
||||
/**
|
||||
* Default export for backwards compat
|
||||
*/
|
||||
|
||||
import * as core from './src/core';
|
||||
import * as duplex from './src/duplex';
|
||||
import {
|
||||
PatchError as JsonPatchError,
|
||||
_deepClone as deepClone,
|
||||
escapePathComponent,
|
||||
unescapePathComponent
|
||||
} from './src/helpers';
|
||||
|
||||
export default {
|
||||
...core,
|
||||
...duplex,
|
||||
JsonPatchError,
|
||||
deepClone,
|
||||
escapePathComponent,
|
||||
unescapePathComponent
|
||||
}
|
||||
23
api.hyungi.net/node_modules/fast-json-patch/jasmine-run.mjs
generated
vendored
Normal file
23
api.hyungi.net/node_modules/fast-json-patch/jasmine-run.mjs
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import glob from 'glob';
|
||||
import Jasmine from 'jasmine';
|
||||
|
||||
const jasmine = new Jasmine();
|
||||
jasmine.loadConfigFile('test/jasmine.json');
|
||||
|
||||
const pattern = process.argv[2] || 'test/spec/*.js';
|
||||
|
||||
// Load your specs
|
||||
glob(pattern, function (er, files) {
|
||||
Promise.all(
|
||||
files
|
||||
// Use relative paths
|
||||
.map(f => f.replace(/^([^\/])/, './$1'))
|
||||
.map(f => import(f)
|
||||
.catch(e => {
|
||||
console.error('** Error loading ' + f + ': ');
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
}))
|
||||
)
|
||||
.then(() => jasmine.execute());
|
||||
});
|
||||
111
api.hyungi.net/node_modules/fast-json-patch/module/core.d.ts
generated
vendored
Normal file
111
api.hyungi.net/node_modules/fast-json-patch/module/core.d.ts
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
import { PatchError, _deepClone } from './helpers.js';
|
||||
export declare const JsonPatchError: typeof PatchError;
|
||||
export declare const deepClone: typeof _deepClone;
|
||||
export declare type Operation = AddOperation<any> | RemoveOperation | ReplaceOperation<any> | MoveOperation | CopyOperation | TestOperation<any> | GetOperation<any>;
|
||||
export interface Validator<T> {
|
||||
(operation: Operation, index: number, document: T, existingPathFragment: string): void;
|
||||
}
|
||||
export interface OperationResult<T> {
|
||||
removed?: any;
|
||||
test?: boolean;
|
||||
newDocument: T;
|
||||
}
|
||||
export interface BaseOperation {
|
||||
path: string;
|
||||
}
|
||||
export interface AddOperation<T> extends BaseOperation {
|
||||
op: 'add';
|
||||
value: T;
|
||||
}
|
||||
export interface RemoveOperation extends BaseOperation {
|
||||
op: 'remove';
|
||||
}
|
||||
export interface ReplaceOperation<T> extends BaseOperation {
|
||||
op: 'replace';
|
||||
value: T;
|
||||
}
|
||||
export interface MoveOperation extends BaseOperation {
|
||||
op: 'move';
|
||||
from: string;
|
||||
}
|
||||
export interface CopyOperation extends BaseOperation {
|
||||
op: 'copy';
|
||||
from: string;
|
||||
}
|
||||
export interface TestOperation<T> extends BaseOperation {
|
||||
op: 'test';
|
||||
value: T;
|
||||
}
|
||||
export interface GetOperation<T> extends BaseOperation {
|
||||
op: '_get';
|
||||
value: T;
|
||||
}
|
||||
export interface PatchResult<T> extends Array<OperationResult<T>> {
|
||||
newDocument: T;
|
||||
}
|
||||
/**
|
||||
* Retrieves a value from a JSON document by a JSON pointer.
|
||||
* Returns the value.
|
||||
*
|
||||
* @param document The document to get the value from
|
||||
* @param pointer an escaped JSON pointer
|
||||
* @return The retrieved value
|
||||
*/
|
||||
export declare function getValueByPointer(document: any, pointer: string): any;
|
||||
/**
|
||||
* Apply a single JSON Patch Operation on a JSON document.
|
||||
* Returns the {newDocument, result} of the operation.
|
||||
* It modifies the `document` and `operation` objects - it gets the values by reference.
|
||||
* If you would like to avoid touching your values, clone them:
|
||||
* `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.
|
||||
*
|
||||
* @param document The document to patch
|
||||
* @param operation The operation to apply
|
||||
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
||||
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
||||
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
||||
* @return `{newDocument, result}` after the operation
|
||||
*/
|
||||
export declare function applyOperation<T>(document: T, operation: Operation, validateOperation?: boolean | Validator<T>, mutateDocument?: boolean, banPrototypeModifications?: boolean, index?: number): OperationResult<T>;
|
||||
/**
|
||||
* Apply a full JSON Patch array on a JSON document.
|
||||
* Returns the {newDocument, result} of the patch.
|
||||
* It modifies the `document` object and `patch` - it gets the values by reference.
|
||||
* If you would like to avoid touching your values, clone them:
|
||||
* `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.
|
||||
*
|
||||
* @param document The document to patch
|
||||
* @param patch The patch to apply
|
||||
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
||||
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
||||
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
||||
* @return An array of `{newDocument, result}` after the patch
|
||||
*/
|
||||
export declare function applyPatch<T>(document: T, patch: ReadonlyArray<Operation>, validateOperation?: boolean | Validator<T>, mutateDocument?: boolean, banPrototypeModifications?: boolean): PatchResult<T>;
|
||||
/**
|
||||
* Apply a single JSON Patch Operation on a JSON document.
|
||||
* Returns the updated document.
|
||||
* Suitable as a reducer.
|
||||
*
|
||||
* @param document The document to patch
|
||||
* @param operation The operation to apply
|
||||
* @return The updated document
|
||||
*/
|
||||
export declare function applyReducer<T>(document: T, operation: Operation, index: number): T;
|
||||
/**
|
||||
* Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.
|
||||
* @param {object} operation - operation object (patch)
|
||||
* @param {number} index - index of operation in the sequence
|
||||
* @param {object} [document] - object where the operation is supposed to be applied
|
||||
* @param {string} [existingPathFragment] - comes along with `document`
|
||||
*/
|
||||
export declare function validator(operation: Operation, index: number, document?: any, existingPathFragment?: string): void;
|
||||
/**
|
||||
* Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.
|
||||
* If error is encountered, returns a JsonPatchError object
|
||||
* @param sequence
|
||||
* @param document
|
||||
* @returns {JsonPatchError|undefined}
|
||||
*/
|
||||
export declare function validate<T>(sequence: ReadonlyArray<Operation>, document?: T, externalValidator?: Validator<T>): PatchError;
|
||||
export declare function _areEquals(a: any, b: any): boolean;
|
||||
433
api.hyungi.net/node_modules/fast-json-patch/module/core.mjs
generated
vendored
Normal file
433
api.hyungi.net/node_modules/fast-json-patch/module/core.mjs
generated
vendored
Normal file
@@ -0,0 +1,433 @@
|
||||
import { PatchError, _deepClone, isInteger, unescapePathComponent, hasUndefined } from './helpers.mjs';
|
||||
export var JsonPatchError = PatchError;
|
||||
export var deepClone = _deepClone;
|
||||
/* We use a Javascript hash to store each
|
||||
function. Each hash entry (property) uses
|
||||
the operation identifiers specified in rfc6902.
|
||||
In this way, we can map each patch operation
|
||||
to its dedicated function in efficient way.
|
||||
*/
|
||||
/* The operations applicable to an object */
|
||||
var objOps = {
|
||||
add: function (obj, key, document) {
|
||||
obj[key] = this.value;
|
||||
return { newDocument: document };
|
||||
},
|
||||
remove: function (obj, key, document) {
|
||||
var removed = obj[key];
|
||||
delete obj[key];
|
||||
return { newDocument: document, removed: removed };
|
||||
},
|
||||
replace: function (obj, key, document) {
|
||||
var removed = obj[key];
|
||||
obj[key] = this.value;
|
||||
return { newDocument: document, removed: removed };
|
||||
},
|
||||
move: function (obj, key, document) {
|
||||
/* in case move target overwrites an existing value,
|
||||
return the removed value, this can be taxing performance-wise,
|
||||
and is potentially unneeded */
|
||||
var removed = getValueByPointer(document, this.path);
|
||||
if (removed) {
|
||||
removed = _deepClone(removed);
|
||||
}
|
||||
var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed;
|
||||
applyOperation(document, { op: "add", path: this.path, value: originalValue });
|
||||
return { newDocument: document, removed: removed };
|
||||
},
|
||||
copy: function (obj, key, document) {
|
||||
var valueToCopy = getValueByPointer(document, this.from);
|
||||
// enforce copy by value so further operations don't affect source (see issue #177)
|
||||
applyOperation(document, { op: "add", path: this.path, value: _deepClone(valueToCopy) });
|
||||
return { newDocument: document };
|
||||
},
|
||||
test: function (obj, key, document) {
|
||||
return { newDocument: document, test: _areEquals(obj[key], this.value) };
|
||||
},
|
||||
_get: function (obj, key, document) {
|
||||
this.value = obj[key];
|
||||
return { newDocument: document };
|
||||
}
|
||||
};
|
||||
/* The operations applicable to an array. Many are the same as for the object */
|
||||
var arrOps = {
|
||||
add: function (arr, i, document) {
|
||||
if (isInteger(i)) {
|
||||
arr.splice(i, 0, this.value);
|
||||
}
|
||||
else { // array props
|
||||
arr[i] = this.value;
|
||||
}
|
||||
// this may be needed when using '-' in an array
|
||||
return { newDocument: document, index: i };
|
||||
},
|
||||
remove: function (arr, i, document) {
|
||||
var removedList = arr.splice(i, 1);
|
||||
return { newDocument: document, removed: removedList[0] };
|
||||
},
|
||||
replace: function (arr, i, document) {
|
||||
var removed = arr[i];
|
||||
arr[i] = this.value;
|
||||
return { newDocument: document, removed: removed };
|
||||
},
|
||||
move: objOps.move,
|
||||
copy: objOps.copy,
|
||||
test: objOps.test,
|
||||
_get: objOps._get
|
||||
};
|
||||
/**
|
||||
* Retrieves a value from a JSON document by a JSON pointer.
|
||||
* Returns the value.
|
||||
*
|
||||
* @param document The document to get the value from
|
||||
* @param pointer an escaped JSON pointer
|
||||
* @return The retrieved value
|
||||
*/
|
||||
export function getValueByPointer(document, pointer) {
|
||||
if (pointer == '') {
|
||||
return document;
|
||||
}
|
||||
var getOriginalDestination = { op: "_get", path: pointer };
|
||||
applyOperation(document, getOriginalDestination);
|
||||
return getOriginalDestination.value;
|
||||
}
|
||||
/**
|
||||
* Apply a single JSON Patch Operation on a JSON document.
|
||||
* Returns the {newDocument, result} of the operation.
|
||||
* It modifies the `document` and `operation` objects - it gets the values by reference.
|
||||
* If you would like to avoid touching your values, clone them:
|
||||
* `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.
|
||||
*
|
||||
* @param document The document to patch
|
||||
* @param operation The operation to apply
|
||||
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
||||
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
||||
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
||||
* @return `{newDocument, result}` after the operation
|
||||
*/
|
||||
export function applyOperation(document, operation, validateOperation, mutateDocument, banPrototypeModifications, index) {
|
||||
if (validateOperation === void 0) { validateOperation = false; }
|
||||
if (mutateDocument === void 0) { mutateDocument = true; }
|
||||
if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
|
||||
if (index === void 0) { index = 0; }
|
||||
if (validateOperation) {
|
||||
if (typeof validateOperation == 'function') {
|
||||
validateOperation(operation, 0, document, operation.path);
|
||||
}
|
||||
else {
|
||||
validator(operation, 0);
|
||||
}
|
||||
}
|
||||
/* ROOT OPERATIONS */
|
||||
if (operation.path === "") {
|
||||
var returnValue = { newDocument: document };
|
||||
if (operation.op === 'add') {
|
||||
returnValue.newDocument = operation.value;
|
||||
return returnValue;
|
||||
}
|
||||
else if (operation.op === 'replace') {
|
||||
returnValue.newDocument = operation.value;
|
||||
returnValue.removed = document; //document we removed
|
||||
return returnValue;
|
||||
}
|
||||
else if (operation.op === 'move' || operation.op === 'copy') { // it's a move or copy to root
|
||||
returnValue.newDocument = getValueByPointer(document, operation.from); // get the value by json-pointer in `from` field
|
||||
if (operation.op === 'move') { // report removed item
|
||||
returnValue.removed = document;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
else if (operation.op === 'test') {
|
||||
returnValue.test = _areEquals(document, operation.value);
|
||||
if (returnValue.test === false) {
|
||||
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
||||
}
|
||||
returnValue.newDocument = document;
|
||||
return returnValue;
|
||||
}
|
||||
else if (operation.op === 'remove') { // a remove on root
|
||||
returnValue.removed = document;
|
||||
returnValue.newDocument = null;
|
||||
return returnValue;
|
||||
}
|
||||
else if (operation.op === '_get') {
|
||||
operation.value = document;
|
||||
return returnValue;
|
||||
}
|
||||
else { /* bad operation */
|
||||
if (validateOperation) {
|
||||
throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);
|
||||
}
|
||||
else {
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
} /* END ROOT OPERATIONS */
|
||||
else {
|
||||
if (!mutateDocument) {
|
||||
document = _deepClone(document);
|
||||
}
|
||||
var path = operation.path || "";
|
||||
var keys = path.split('/');
|
||||
var obj = document;
|
||||
var t = 1; //skip empty element - http://jsperf.com/to-shift-or-not-to-shift
|
||||
var len = keys.length;
|
||||
var existingPathFragment = undefined;
|
||||
var key = void 0;
|
||||
var validateFunction = void 0;
|
||||
if (typeof validateOperation == 'function') {
|
||||
validateFunction = validateOperation;
|
||||
}
|
||||
else {
|
||||
validateFunction = validator;
|
||||
}
|
||||
while (true) {
|
||||
key = keys[t];
|
||||
if (key && key.indexOf('~') != -1) {
|
||||
key = unescapePathComponent(key);
|
||||
}
|
||||
if (banPrototypeModifications &&
|
||||
(key == '__proto__' ||
|
||||
(key == 'prototype' && t > 0 && keys[t - 1] == 'constructor'))) {
|
||||
throw new TypeError('JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README');
|
||||
}
|
||||
if (validateOperation) {
|
||||
if (existingPathFragment === undefined) {
|
||||
if (obj[key] === undefined) {
|
||||
existingPathFragment = keys.slice(0, t).join('/');
|
||||
}
|
||||
else if (t == len - 1) {
|
||||
existingPathFragment = operation.path;
|
||||
}
|
||||
if (existingPathFragment !== undefined) {
|
||||
validateFunction(operation, 0, document, existingPathFragment);
|
||||
}
|
||||
}
|
||||
}
|
||||
t++;
|
||||
if (Array.isArray(obj)) {
|
||||
if (key === '-') {
|
||||
key = obj.length;
|
||||
}
|
||||
else {
|
||||
if (validateOperation && !isInteger(key)) {
|
||||
throw new JsonPatchError("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", index, operation, document);
|
||||
} // only parse key when it's an integer for `arr.prop` to work
|
||||
else if (isInteger(key)) {
|
||||
key = ~~key;
|
||||
}
|
||||
}
|
||||
if (t >= len) {
|
||||
if (validateOperation && operation.op === "add" && key > obj.length) {
|
||||
throw new JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", index, operation, document);
|
||||
}
|
||||
var returnValue = arrOps[operation.op].call(operation, obj, key, document); // Apply patch
|
||||
if (returnValue.test === false) {
|
||||
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (t >= len) {
|
||||
var returnValue = objOps[operation.op].call(operation, obj, key, document); // Apply patch
|
||||
if (returnValue.test === false) {
|
||||
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
obj = obj[key];
|
||||
// If we have more keys in the path, but the next value isn't a non-null object,
|
||||
// throw an OPERATION_PATH_UNRESOLVABLE error instead of iterating again.
|
||||
if (validateOperation && t < len && (!obj || typeof obj !== "object")) {
|
||||
throw new JsonPatchError('Cannot perform operation at the desired path', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Apply a full JSON Patch array on a JSON document.
|
||||
* Returns the {newDocument, result} of the patch.
|
||||
* It modifies the `document` object and `patch` - it gets the values by reference.
|
||||
* If you would like to avoid touching your values, clone them:
|
||||
* `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.
|
||||
*
|
||||
* @param document The document to patch
|
||||
* @param patch The patch to apply
|
||||
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
||||
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
||||
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
||||
* @return An array of `{newDocument, result}` after the patch
|
||||
*/
|
||||
export function applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) {
|
||||
if (mutateDocument === void 0) { mutateDocument = true; }
|
||||
if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
|
||||
if (validateOperation) {
|
||||
if (!Array.isArray(patch)) {
|
||||
throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
|
||||
}
|
||||
}
|
||||
if (!mutateDocument) {
|
||||
document = _deepClone(document);
|
||||
}
|
||||
var results = new Array(patch.length);
|
||||
for (var i = 0, length_1 = patch.length; i < length_1; i++) {
|
||||
// we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`
|
||||
results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);
|
||||
document = results[i].newDocument; // in case root was replaced
|
||||
}
|
||||
results.newDocument = document;
|
||||
return results;
|
||||
}
|
||||
/**
|
||||
* Apply a single JSON Patch Operation on a JSON document.
|
||||
* Returns the updated document.
|
||||
* Suitable as a reducer.
|
||||
*
|
||||
* @param document The document to patch
|
||||
* @param operation The operation to apply
|
||||
* @return The updated document
|
||||
*/
|
||||
export function applyReducer(document, operation, index) {
|
||||
var operationResult = applyOperation(document, operation);
|
||||
if (operationResult.test === false) { // failed test
|
||||
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
||||
}
|
||||
return operationResult.newDocument;
|
||||
}
|
||||
/**
|
||||
* Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.
|
||||
* @param {object} operation - operation object (patch)
|
||||
* @param {number} index - index of operation in the sequence
|
||||
* @param {object} [document] - object where the operation is supposed to be applied
|
||||
* @param {string} [existingPathFragment] - comes along with `document`
|
||||
*/
|
||||
export function validator(operation, index, document, existingPathFragment) {
|
||||
if (typeof operation !== 'object' || operation === null || Array.isArray(operation)) {
|
||||
throw new JsonPatchError('Operation is not an object', 'OPERATION_NOT_AN_OBJECT', index, operation, document);
|
||||
}
|
||||
else if (!objOps[operation.op]) {
|
||||
throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);
|
||||
}
|
||||
else if (typeof operation.path !== 'string') {
|
||||
throw new JsonPatchError('Operation `path` property is not a string', 'OPERATION_PATH_INVALID', index, operation, document);
|
||||
}
|
||||
else if (operation.path.indexOf('/') !== 0 && operation.path.length > 0) {
|
||||
// paths that aren't empty string should start with "/"
|
||||
throw new JsonPatchError('Operation `path` property must start with "/"', 'OPERATION_PATH_INVALID', index, operation, document);
|
||||
}
|
||||
else if ((operation.op === 'move' || operation.op === 'copy') && typeof operation.from !== 'string') {
|
||||
throw new JsonPatchError('Operation `from` property is not present (applicable in `move` and `copy` operations)', 'OPERATION_FROM_REQUIRED', index, operation, document);
|
||||
}
|
||||
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && operation.value === undefined) {
|
||||
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document);
|
||||
}
|
||||
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && hasUndefined(operation.value)) {
|
||||
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, document);
|
||||
}
|
||||
else if (document) {
|
||||
if (operation.op == "add") {
|
||||
var pathLen = operation.path.split("/").length;
|
||||
var existingPathLen = existingPathFragment.split("/").length;
|
||||
if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {
|
||||
throw new JsonPatchError('Cannot perform an `add` operation at the desired path', 'OPERATION_PATH_CANNOT_ADD', index, operation, document);
|
||||
}
|
||||
}
|
||||
else if (operation.op === 'replace' || operation.op === 'remove' || operation.op === '_get') {
|
||||
if (operation.path !== existingPathFragment) {
|
||||
throw new JsonPatchError('Cannot perform the operation at a path that does not exist', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);
|
||||
}
|
||||
}
|
||||
else if (operation.op === 'move' || operation.op === 'copy') {
|
||||
var existingValue = { op: "_get", path: operation.from, value: undefined };
|
||||
var error = validate([existingValue], document);
|
||||
if (error && error.name === 'OPERATION_PATH_UNRESOLVABLE') {
|
||||
throw new JsonPatchError('Cannot perform the operation from a path that does not exist', 'OPERATION_FROM_UNRESOLVABLE', index, operation, document);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.
|
||||
* If error is encountered, returns a JsonPatchError object
|
||||
* @param sequence
|
||||
* @param document
|
||||
* @returns {JsonPatchError|undefined}
|
||||
*/
|
||||
export function validate(sequence, document, externalValidator) {
|
||||
try {
|
||||
if (!Array.isArray(sequence)) {
|
||||
throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
|
||||
}
|
||||
if (document) {
|
||||
//clone document and sequence so that we can safely try applying operations
|
||||
applyPatch(_deepClone(document), _deepClone(sequence), externalValidator || true);
|
||||
}
|
||||
else {
|
||||
externalValidator = externalValidator || validator;
|
||||
for (var i = 0; i < sequence.length; i++) {
|
||||
externalValidator(sequence[i], i, document, undefined);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
if (e instanceof JsonPatchError) {
|
||||
return e;
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
// based on https://github.com/epoberezkin/fast-deep-equal
|
||||
// MIT License
|
||||
// Copyright (c) 2017 Evgeny Poberezkin
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
export function _areEquals(a, b) {
|
||||
if (a === b)
|
||||
return true;
|
||||
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
||||
var arrA = Array.isArray(a), arrB = Array.isArray(b), i, length, key;
|
||||
if (arrA && arrB) {
|
||||
length = a.length;
|
||||
if (length != b.length)
|
||||
return false;
|
||||
for (i = length; i-- !== 0;)
|
||||
if (!_areEquals(a[i], b[i]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
if (arrA != arrB)
|
||||
return false;
|
||||
var keys = Object.keys(a);
|
||||
length = keys.length;
|
||||
if (length !== Object.keys(b).length)
|
||||
return false;
|
||||
for (i = length; i-- !== 0;)
|
||||
if (!b.hasOwnProperty(keys[i]))
|
||||
return false;
|
||||
for (i = length; i-- !== 0;) {
|
||||
key = keys[i];
|
||||
if (!_areEquals(a[key], b[key]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return a !== a && b !== b;
|
||||
}
|
||||
;
|
||||
23
api.hyungi.net/node_modules/fast-json-patch/module/duplex.d.ts
generated
vendored
Normal file
23
api.hyungi.net/node_modules/fast-json-patch/module/duplex.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Operation } from './core.js';
|
||||
export interface Observer<T> {
|
||||
object: T;
|
||||
patches: Operation[];
|
||||
unobserve: () => void;
|
||||
callback: (patches: Operation[]) => void;
|
||||
}
|
||||
/**
|
||||
* Detach an observer from an object
|
||||
*/
|
||||
export declare function unobserve<T>(root: T, observer: Observer<T>): void;
|
||||
/**
|
||||
* Observes changes made to an object, which can then be retrieved using generate
|
||||
*/
|
||||
export declare function observe<T>(obj: Object | Array<T>, callback?: (patches: Operation[]) => void): Observer<T>;
|
||||
/**
|
||||
* Generate an array of patches from an observer
|
||||
*/
|
||||
export declare function generate<T>(observer: Observer<Object>, invertible?: boolean): Operation[];
|
||||
/**
|
||||
* Create an array of patches from the differences in two objects
|
||||
*/
|
||||
export declare function compare(tree1: Object | Array<any>, tree2: Object | Array<any>, invertible?: boolean): Operation[];
|
||||
176
api.hyungi.net/node_modules/fast-json-patch/module/duplex.mjs
generated
vendored
Normal file
176
api.hyungi.net/node_modules/fast-json-patch/module/duplex.mjs
generated
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
/*!
|
||||
* https://github.com/Starcounter-Jack/JSON-Patch
|
||||
* (c) 2017-2021 Joachim Wester
|
||||
* MIT license
|
||||
*/
|
||||
import { _deepClone, _objectKeys, escapePathComponent, hasOwnProperty } from './helpers.mjs';
|
||||
import { applyPatch } from './core.mjs';
|
||||
var beforeDict = new WeakMap();
|
||||
var Mirror = /** @class */ (function () {
|
||||
function Mirror(obj) {
|
||||
this.observers = new Map();
|
||||
this.obj = obj;
|
||||
}
|
||||
return Mirror;
|
||||
}());
|
||||
var ObserverInfo = /** @class */ (function () {
|
||||
function ObserverInfo(callback, observer) {
|
||||
this.callback = callback;
|
||||
this.observer = observer;
|
||||
}
|
||||
return ObserverInfo;
|
||||
}());
|
||||
function getMirror(obj) {
|
||||
return beforeDict.get(obj);
|
||||
}
|
||||
function getObserverFromMirror(mirror, callback) {
|
||||
return mirror.observers.get(callback);
|
||||
}
|
||||
function removeObserverFromMirror(mirror, observer) {
|
||||
mirror.observers.delete(observer.callback);
|
||||
}
|
||||
/**
|
||||
* Detach an observer from an object
|
||||
*/
|
||||
export function unobserve(root, observer) {
|
||||
observer.unobserve();
|
||||
}
|
||||
/**
|
||||
* Observes changes made to an object, which can then be retrieved using generate
|
||||
*/
|
||||
export function observe(obj, callback) {
|
||||
var patches = [];
|
||||
var observer;
|
||||
var mirror = getMirror(obj);
|
||||
if (!mirror) {
|
||||
mirror = new Mirror(obj);
|
||||
beforeDict.set(obj, mirror);
|
||||
}
|
||||
else {
|
||||
var observerInfo = getObserverFromMirror(mirror, callback);
|
||||
observer = observerInfo && observerInfo.observer;
|
||||
}
|
||||
if (observer) {
|
||||
return observer;
|
||||
}
|
||||
observer = {};
|
||||
mirror.value = _deepClone(obj);
|
||||
if (callback) {
|
||||
observer.callback = callback;
|
||||
observer.next = null;
|
||||
var dirtyCheck = function () {
|
||||
generate(observer);
|
||||
};
|
||||
var fastCheck = function () {
|
||||
clearTimeout(observer.next);
|
||||
observer.next = setTimeout(dirtyCheck);
|
||||
};
|
||||
if (typeof window !== 'undefined') { //not Node
|
||||
window.addEventListener('mouseup', fastCheck);
|
||||
window.addEventListener('keyup', fastCheck);
|
||||
window.addEventListener('mousedown', fastCheck);
|
||||
window.addEventListener('keydown', fastCheck);
|
||||
window.addEventListener('change', fastCheck);
|
||||
}
|
||||
}
|
||||
observer.patches = patches;
|
||||
observer.object = obj;
|
||||
observer.unobserve = function () {
|
||||
generate(observer);
|
||||
clearTimeout(observer.next);
|
||||
removeObserverFromMirror(mirror, observer);
|
||||
if (typeof window !== 'undefined') {
|
||||
window.removeEventListener('mouseup', fastCheck);
|
||||
window.removeEventListener('keyup', fastCheck);
|
||||
window.removeEventListener('mousedown', fastCheck);
|
||||
window.removeEventListener('keydown', fastCheck);
|
||||
window.removeEventListener('change', fastCheck);
|
||||
}
|
||||
};
|
||||
mirror.observers.set(callback, new ObserverInfo(callback, observer));
|
||||
return observer;
|
||||
}
|
||||
/**
|
||||
* Generate an array of patches from an observer
|
||||
*/
|
||||
export function generate(observer, invertible) {
|
||||
if (invertible === void 0) { invertible = false; }
|
||||
var mirror = beforeDict.get(observer.object);
|
||||
_generate(mirror.value, observer.object, observer.patches, "", invertible);
|
||||
if (observer.patches.length) {
|
||||
applyPatch(mirror.value, observer.patches);
|
||||
}
|
||||
var temp = observer.patches;
|
||||
if (temp.length > 0) {
|
||||
observer.patches = [];
|
||||
if (observer.callback) {
|
||||
observer.callback(temp);
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
// Dirty check if obj is different from mirror, generate patches and update mirror
|
||||
function _generate(mirror, obj, patches, path, invertible) {
|
||||
if (obj === mirror) {
|
||||
return;
|
||||
}
|
||||
if (typeof obj.toJSON === "function") {
|
||||
obj = obj.toJSON();
|
||||
}
|
||||
var newKeys = _objectKeys(obj);
|
||||
var oldKeys = _objectKeys(mirror);
|
||||
var changed = false;
|
||||
var deleted = false;
|
||||
//if ever "move" operation is implemented here, make sure this test runs OK: "should not generate the same patch twice (move)"
|
||||
for (var t = oldKeys.length - 1; t >= 0; t--) {
|
||||
var key = oldKeys[t];
|
||||
var oldVal = mirror[key];
|
||||
if (hasOwnProperty(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
|
||||
var newVal = obj[key];
|
||||
if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null && Array.isArray(oldVal) === Array.isArray(newVal)) {
|
||||
_generate(oldVal, newVal, patches, path + "/" + escapePathComponent(key), invertible);
|
||||
}
|
||||
else {
|
||||
if (oldVal !== newVal) {
|
||||
changed = true;
|
||||
if (invertible) {
|
||||
patches.push({ op: "test", path: path + "/" + escapePathComponent(key), value: _deepClone(oldVal) });
|
||||
}
|
||||
patches.push({ op: "replace", path: path + "/" + escapePathComponent(key), value: _deepClone(newVal) });
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Array.isArray(mirror) === Array.isArray(obj)) {
|
||||
if (invertible) {
|
||||
patches.push({ op: "test", path: path + "/" + escapePathComponent(key), value: _deepClone(oldVal) });
|
||||
}
|
||||
patches.push({ op: "remove", path: path + "/" + escapePathComponent(key) });
|
||||
deleted = true; // property has been deleted
|
||||
}
|
||||
else {
|
||||
if (invertible) {
|
||||
patches.push({ op: "test", path: path, value: mirror });
|
||||
}
|
||||
patches.push({ op: "replace", path: path, value: obj });
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (!deleted && newKeys.length == oldKeys.length) {
|
||||
return;
|
||||
}
|
||||
for (var t = 0; t < newKeys.length; t++) {
|
||||
var key = newKeys[t];
|
||||
if (!hasOwnProperty(mirror, key) && obj[key] !== undefined) {
|
||||
patches.push({ op: "add", path: path + "/" + escapePathComponent(key), value: _deepClone(obj[key]) });
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create an array of patches from the differences in two objects
|
||||
*/
|
||||
export function compare(tree1, tree2, invertible) {
|
||||
if (invertible === void 0) { invertible = false; }
|
||||
var patches = [];
|
||||
_generate(tree1, tree2, patches, '', invertible);
|
||||
return patches;
|
||||
}
|
||||
41
api.hyungi.net/node_modules/fast-json-patch/module/helpers.d.ts
generated
vendored
Normal file
41
api.hyungi.net/node_modules/fast-json-patch/module/helpers.d.ts
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
/*!
|
||||
* https://github.com/Starcounter-Jack/JSON-Patch
|
||||
* (c) 2017-2022 Joachim Wester
|
||||
* MIT licensed
|
||||
*/
|
||||
export declare function hasOwnProperty(obj: any, key: any): any;
|
||||
export declare function _objectKeys(obj: any): any[];
|
||||
/**
|
||||
* Deeply clone the object.
|
||||
* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
|
||||
* @param {any} obj value to clone
|
||||
* @return {any} cloned obj
|
||||
*/
|
||||
export declare function _deepClone(obj: any): any;
|
||||
export declare function isInteger(str: string): boolean;
|
||||
/**
|
||||
* Escapes a json pointer path
|
||||
* @param path The raw pointer
|
||||
* @return the Escaped path
|
||||
*/
|
||||
export declare function escapePathComponent(path: string): string;
|
||||
/**
|
||||
* Unescapes a json pointer path
|
||||
* @param path The escaped pointer
|
||||
* @return The unescaped path
|
||||
*/
|
||||
export declare function unescapePathComponent(path: string): string;
|
||||
export declare function _getPathRecursive(root: Object, obj: Object): string;
|
||||
export declare function getPath(root: Object, obj: Object): string;
|
||||
/**
|
||||
* Recursively checks whether an object has any undefined values inside.
|
||||
*/
|
||||
export declare function hasUndefined(obj: any): boolean;
|
||||
export declare type JsonPatchErrorName = 'SEQUENCE_NOT_AN_ARRAY' | 'OPERATION_NOT_AN_OBJECT' | 'OPERATION_OP_INVALID' | 'OPERATION_PATH_INVALID' | 'OPERATION_FROM_REQUIRED' | 'OPERATION_VALUE_REQUIRED' | 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED' | 'OPERATION_PATH_CANNOT_ADD' | 'OPERATION_PATH_UNRESOLVABLE' | 'OPERATION_FROM_UNRESOLVABLE' | 'OPERATION_PATH_ILLEGAL_ARRAY_INDEX' | 'OPERATION_VALUE_OUT_OF_BOUNDS' | 'TEST_OPERATION_FAILED';
|
||||
export declare class PatchError extends Error {
|
||||
name: JsonPatchErrorName;
|
||||
index?: number;
|
||||
operation?: any;
|
||||
tree?: any;
|
||||
constructor(message: string, name: JsonPatchErrorName, index?: number, operation?: any, tree?: any);
|
||||
}
|
||||
171
api.hyungi.net/node_modules/fast-json-patch/module/helpers.mjs
generated
vendored
Normal file
171
api.hyungi.net/node_modules/fast-json-patch/module/helpers.mjs
generated
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
/*!
|
||||
* https://github.com/Starcounter-Jack/JSON-Patch
|
||||
* (c) 2017-2022 Joachim Wester
|
||||
* MIT licensed
|
||||
*/
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
export function hasOwnProperty(obj, key) {
|
||||
return _hasOwnProperty.call(obj, key);
|
||||
}
|
||||
export function _objectKeys(obj) {
|
||||
if (Array.isArray(obj)) {
|
||||
var keys_1 = new Array(obj.length);
|
||||
for (var k = 0; k < keys_1.length; k++) {
|
||||
keys_1[k] = "" + k;
|
||||
}
|
||||
return keys_1;
|
||||
}
|
||||
if (Object.keys) {
|
||||
return Object.keys(obj);
|
||||
}
|
||||
var keys = [];
|
||||
for (var i in obj) {
|
||||
if (hasOwnProperty(obj, i)) {
|
||||
keys.push(i);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* Deeply clone the object.
|
||||
* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
|
||||
* @param {any} obj value to clone
|
||||
* @return {any} cloned obj
|
||||
*/
|
||||
export function _deepClone(obj) {
|
||||
switch (typeof obj) {
|
||||
case "object":
|
||||
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
|
||||
case "undefined":
|
||||
return null; //this is how JSON.stringify behaves for array items
|
||||
default:
|
||||
return obj; //no need to clone primitives
|
||||
}
|
||||
}
|
||||
//3x faster than cached /^\d+$/.test(str)
|
||||
export function isInteger(str) {
|
||||
var i = 0;
|
||||
var len = str.length;
|
||||
var charCode;
|
||||
while (i < len) {
|
||||
charCode = str.charCodeAt(i);
|
||||
if (charCode >= 48 && charCode <= 57) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Escapes a json pointer path
|
||||
* @param path The raw pointer
|
||||
* @return the Escaped path
|
||||
*/
|
||||
export function escapePathComponent(path) {
|
||||
if (path.indexOf('/') === -1 && path.indexOf('~') === -1)
|
||||
return path;
|
||||
return path.replace(/~/g, '~0').replace(/\//g, '~1');
|
||||
}
|
||||
/**
|
||||
* Unescapes a json pointer path
|
||||
* @param path The escaped pointer
|
||||
* @return The unescaped path
|
||||
*/
|
||||
export function unescapePathComponent(path) {
|
||||
return path.replace(/~1/g, '/').replace(/~0/g, '~');
|
||||
}
|
||||
export function _getPathRecursive(root, obj) {
|
||||
var found;
|
||||
for (var key in root) {
|
||||
if (hasOwnProperty(root, key)) {
|
||||
if (root[key] === obj) {
|
||||
return escapePathComponent(key) + '/';
|
||||
}
|
||||
else if (typeof root[key] === 'object') {
|
||||
found = _getPathRecursive(root[key], obj);
|
||||
if (found != '') {
|
||||
return escapePathComponent(key) + '/' + found;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
export function getPath(root, obj) {
|
||||
if (root === obj) {
|
||||
return '/';
|
||||
}
|
||||
var path = _getPathRecursive(root, obj);
|
||||
if (path === '') {
|
||||
throw new Error("Object not found in root");
|
||||
}
|
||||
return "/" + path;
|
||||
}
|
||||
/**
|
||||
* Recursively checks whether an object has any undefined values inside.
|
||||
*/
|
||||
export function hasUndefined(obj) {
|
||||
if (obj === undefined) {
|
||||
return true;
|
||||
}
|
||||
if (obj) {
|
||||
if (Array.isArray(obj)) {
|
||||
for (var i_1 = 0, len = obj.length; i_1 < len; i_1++) {
|
||||
if (hasUndefined(obj[i_1])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof obj === "object") {
|
||||
var objKeys = _objectKeys(obj);
|
||||
var objKeysLength = objKeys.length;
|
||||
for (var i = 0; i < objKeysLength; i++) {
|
||||
if (hasUndefined(obj[objKeys[i]])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function patchErrorMessageFormatter(message, args) {
|
||||
var messageParts = [message];
|
||||
for (var key in args) {
|
||||
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
|
||||
if (typeof value !== 'undefined') {
|
||||
messageParts.push(key + ": " + value);
|
||||
}
|
||||
}
|
||||
return messageParts.join('\n');
|
||||
}
|
||||
var PatchError = /** @class */ (function (_super) {
|
||||
__extends(PatchError, _super);
|
||||
function PatchError(message, name, index, operation, tree) {
|
||||
var _newTarget = this.constructor;
|
||||
var _this = _super.call(this, patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree })) || this;
|
||||
_this.name = name;
|
||||
_this.index = index;
|
||||
_this.operation = operation;
|
||||
_this.tree = tree;
|
||||
Object.setPrototypeOf(_this, _newTarget.prototype); // restore prototype chain, see https://stackoverflow.com/a/48342359
|
||||
_this.message = patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree });
|
||||
return _this;
|
||||
}
|
||||
return PatchError;
|
||||
}(Error));
|
||||
export { PatchError };
|
||||
65
api.hyungi.net/node_modules/fast-json-patch/package.json
generated
vendored
Normal file
65
api.hyungi.net/node_modules/fast-json-patch/package.json
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"name": "fast-json-patch",
|
||||
"version": "3.1.1",
|
||||
"description": "Fast implementation of JSON-Patch (RFC-6902) with duplex (observe changes) capabilities",
|
||||
"homepage": "https://github.com/Starcounter-Jack/JSON-Patch",
|
||||
"keywords": [
|
||||
"json",
|
||||
"patch",
|
||||
"http",
|
||||
"rest"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/Starcounter-Jack/JSON-Patch.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Starcounter-Jack/JSON-Patch/issues"
|
||||
},
|
||||
"author": {
|
||||
"name": "Joachim Wester",
|
||||
"email": "joachimwester@me.com",
|
||||
"url": "http://www.starcounter.com/"
|
||||
},
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"module": "index.mjs",
|
||||
"typings": "index.d.ts",
|
||||
"devDependencies": {
|
||||
"benchmark": "^2.1.4",
|
||||
"bluebird": "^3.5.5",
|
||||
"bluebird-retry": "^0.11.0",
|
||||
"chalk": "^2.4.2",
|
||||
"event-target-shim": "^5.0.1",
|
||||
"fast-deep-equal": "^2.0.1",
|
||||
"http-server": "^0.12.3",
|
||||
"jasmine": "^3.4.0",
|
||||
"request": "^2.88.0",
|
||||
"sauce-connect-launcher": "^1.2.7",
|
||||
"saucelabs": "^2.1.9",
|
||||
"selenium-webdriver": "^4.0.0-alpha.4",
|
||||
"typescript": "~3.5.2",
|
||||
"webpack": "^4.35.0",
|
||||
"webpack-cli": "^3.3.5"
|
||||
},
|
||||
"scripts": {
|
||||
"tsc": "npm run tsc-common && npm run tsc-module",
|
||||
"tsc-common": "tsc",
|
||||
"tsc-module": "tsc --module esnext --moduleResolution node --outDir \"module/\" && npm run tsc-to-mjs",
|
||||
"tsc-to-mjs": "bash tsc-to-mjs.sh",
|
||||
"version": "npm run tsc && webpack && git add -A",
|
||||
"build": "npm run tsc && webpack",
|
||||
"serve": "http-server -p 5000 --silent",
|
||||
"tsc-watch": "tsc -w",
|
||||
"test": "npm run tsc && npm run test-core && npm run test-duplex && npm run test-commonjs && npm run test-webpack-import && npm run test-typings",
|
||||
"test-sauce": "npm run build && node test/Sauce/Runner.js",
|
||||
"test-commonjs": "jasmine test/spec/commonjs/requireSpec.js",
|
||||
"test-webpack-import": "webpack --env.NODE_ENV=test && jasmine test/spec/webpack/importSpec.build.js",
|
||||
"test-typings": "tsc test/spec/typings/typingsSpec.ts",
|
||||
"test-duplex": "node --experimental-modules jasmine-run.mjs test/**/*[sS]pec.mjs",
|
||||
"test-core": "node --experimental-modules jasmine-run.mjs 'test/spec/{jsonPatchTestsSpec,coreSpec,validateSpec}.mjs'",
|
||||
"bench": "npm run bench-core && npm run bench-duplex",
|
||||
"bench-core": "node test/spec/coreBenchmark.js",
|
||||
"bench-duplex": "node test/spec/coreBenchmark.js && node test/spec/duplexBenchmark.js"
|
||||
}
|
||||
}
|
||||
10
api.hyungi.net/node_modules/fast-json-patch/tsc-to-mjs.sh
generated
vendored
Normal file
10
api.hyungi.net/node_modules/fast-json-patch/tsc-to-mjs.sh
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
cd module
|
||||
mv core.js core.mjs && mv duplex.js duplex.mjs && mv helpers.js helpers.mjs
|
||||
# Unlike Ubuntu, OS X requires the extension to be explicitly specified
|
||||
# https://myshittycode.com/2014/07/24/os-x-sed-extra-characters-at-the-end-of-l-command-error/
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
sed -i '' 's/\.js/\.mjs/g' duplex.mjs core.mjs
|
||||
else
|
||||
sed -i 's/\.js/\.mjs/g' duplex.mjs core.mjs
|
||||
fi
|
||||
63
api.hyungi.net/node_modules/fast-json-patch/webpack.config.js
generated
vendored
Normal file
63
api.hyungi.net/node_modules/fast-json-patch/webpack.config.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
var webpack = require('webpack');
|
||||
const package = require('./package.json');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = env => {
|
||||
if(env && env.NODE_ENV === "test") {
|
||||
return [
|
||||
{
|
||||
entry: './test/spec/webpack/importSpec.src.js',
|
||||
mode: 'production',
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'test/spec/webpack'),
|
||||
filename: 'importSpec.build.js'
|
||||
},
|
||||
target: 'node',
|
||||
resolve: {
|
||||
extensions: ['.js']
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
else {
|
||||
return [
|
||||
{
|
||||
entry: './index.js',
|
||||
mode: 'production',
|
||||
optimization: {
|
||||
minimize: false
|
||||
},
|
||||
output: {
|
||||
filename: 'fast-json-patch.js',
|
||||
library: 'jsonpatch',
|
||||
libraryTarget: 'var'
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.js']
|
||||
},
|
||||
plugins: [
|
||||
new webpack.BannerPlugin('fast-json-patch, version: ' + package['version'])
|
||||
]
|
||||
},
|
||||
{
|
||||
entry: './index.js',
|
||||
mode: 'production',
|
||||
output: {
|
||||
filename: 'fast-json-patch.min.js',
|
||||
library: 'jsonpatch',
|
||||
libraryTarget: 'var'
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.js']
|
||||
},
|
||||
plugins: [
|
||||
new webpack.BannerPlugin('fast-json-patch, version: ' + package['version'])
|
||||
]
|
||||
}
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user