@dabble/patches 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/json-patch/JSONPatch.d.ts +1 -5
- package/dist/json-patch/JSONPatch.js +1 -15
- package/dist/json-patch/createJSONPatch.js +1 -1
- package/dist/server/PatchesServer.d.ts +1 -1
- package/dist/types.d.ts +7 -3
- package/dist/types.js +1 -1
- package/package.json +1 -1
- /package/dist/json-patch/{patchProxy.d.ts → pathProxy.d.ts} +0 -0
- /package/dist/json-patch/{patchProxy.js → pathProxy.js} +0 -0
|
@@ -75,11 +75,7 @@ export declare class JSONPatch {
|
|
|
75
75
|
*/
|
|
76
76
|
addUpdates(updates: {
|
|
77
77
|
[key: string]: any;
|
|
78
|
-
}, path?:
|
|
79
|
-
/**
|
|
80
|
-
* This will ensure an "add empty object" operation is created for each property along the path that does not exist.
|
|
81
|
-
*/
|
|
82
|
-
addObjectsInPath(obj: any, path: PathLike): this;
|
|
78
|
+
}, path?: PathLike): this;
|
|
83
79
|
/**
|
|
84
80
|
* Apply this patch to an object, returning a new object with the applied changes (or the same object if nothing
|
|
85
81
|
* changed in the patch). Optionally apply the page at the given path prefix.
|
|
@@ -122,6 +122,7 @@ export class JSONPatch {
|
|
|
122
122
|
* Creates a patch from an object partial, updating each field. Set a field to undefined to delete it.
|
|
123
123
|
*/
|
|
124
124
|
addUpdates(updates, path = '/') {
|
|
125
|
+
path = checkPath(path);
|
|
125
126
|
if (path[path.length - 1] !== '/')
|
|
126
127
|
path += '/';
|
|
127
128
|
Object.keys(updates).forEach(key => {
|
|
@@ -135,21 +136,6 @@ export class JSONPatch {
|
|
|
135
136
|
});
|
|
136
137
|
return this;
|
|
137
138
|
}
|
|
138
|
-
/**
|
|
139
|
-
* This will ensure an "add empty object" operation is created for each property along the path that does not exist.
|
|
140
|
-
*/
|
|
141
|
-
addObjectsInPath(obj, path) {
|
|
142
|
-
path = checkPath(path);
|
|
143
|
-
const parts = path.split('/');
|
|
144
|
-
for (let i = 1; i < parts.length - 1; i++) {
|
|
145
|
-
const prop = parts[i];
|
|
146
|
-
if (!obj || !obj[prop]) {
|
|
147
|
-
this.add(parts.slice(0, i + 1).join('/'), {});
|
|
148
|
-
}
|
|
149
|
-
obj = obj && obj[prop];
|
|
150
|
-
}
|
|
151
|
-
return this;
|
|
152
|
-
}
|
|
153
139
|
/**
|
|
154
140
|
* Apply this patch to an object, returning a new object with the applied changes (or the same object if nothing
|
|
155
141
|
* changed in the patch). Optionally apply the page at the given path prefix.
|
|
@@ -61,7 +61,7 @@ export declare class PatchesServer {
|
|
|
61
61
|
* @param mutator
|
|
62
62
|
* @returns
|
|
63
63
|
*/
|
|
64
|
-
change<T = Record<string, any>>(docId: string, mutator: (patch: JSONPatch,
|
|
64
|
+
change<T = Record<string, any>>(docId: string, mutator: (patch: JSONPatch, root: PathProxy<T>) => void, metadata?: Record<string, any>): Promise<Change | null>;
|
|
65
65
|
/**
|
|
66
66
|
* Deletes a document.
|
|
67
67
|
* @param docId The document ID.
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { JSONPatch } from './json-patch/JSONPatch.js';
|
|
1
2
|
import type { JSONPatchOp } from './json-patch/types.js';
|
|
2
|
-
import type { JSONPatch } from './json-patch/JSONPatch.js';
|
|
3
3
|
export interface Change {
|
|
4
4
|
/** Unique identifier for the change, generated client-side. */
|
|
5
5
|
id: string;
|
|
@@ -131,12 +131,16 @@ export interface ListVersionsOptions {
|
|
|
131
131
|
* without null checks, but should only be used for path generation, not value access.
|
|
132
132
|
*/
|
|
133
133
|
export type PathProxy<T> = {
|
|
134
|
-
[P in keyof T]-?: T[P] extends object ? PathProxy<T[P]
|
|
134
|
+
[P in keyof T]-?: NonNullable<T[P]> extends object ? PathProxy<NonNullable<T[P]>> : {
|
|
135
|
+
toString: () => string;
|
|
136
|
+
};
|
|
137
|
+
} & {
|
|
138
|
+
toString: () => string;
|
|
135
139
|
};
|
|
136
140
|
/**
|
|
137
141
|
* Type signature for change mutator functions that use path-only proxies.
|
|
138
142
|
* The mutator receives a JSONPatch instance and a PathProxy for type-safe path creation.
|
|
139
143
|
* All modifications must be done through explicit patch operations.
|
|
140
144
|
*/
|
|
141
|
-
export type ChangeMutator<T> = (patch: JSONPatch,
|
|
145
|
+
export type ChangeMutator<T> = (patch: JSONPatch, root: PathProxy<T>) => void;
|
|
142
146
|
export {};
|
package/dist/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import { JSONPatch } from './json-patch/JSONPatch.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dabble/patches",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Immutable JSON Patch implementation based on RFC 6902 supporting operational transformation and last-writer-wins",
|
|
5
5
|
"author": "Jacob Wright <jacwright@gmail.com>",
|
|
6
6
|
"bugs": {
|
|
File without changes
|
|
File without changes
|