@kubun/mutation 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/create.d.ts.map +1 -1
- package/lib/create.js +1 -1
- package/package.json +4 -3
- package/lib/json-patch.d.ts +0 -8
- package/lib/json-patch.d.ts.map +0 -1
- package/lib/json-patch.js +0 -70
package/lib/create.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAIhG,MAAM,MAAM,uBAAuB,CAAC,IAAI,SAAS,YAAY,GAAG,YAAY,IAAI;IAC9E,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,eAAe,GAAG,MAAM,CAAA;IACjC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,UAAU,CAAA;CACnB,CAAA;AAED,wBAAsB,iBAAiB,CAAC,IAAI,SAAS,YAAY,GAAG,YAAY,EAC9E,MAAM,EAAE,uBAAuB,CAAC,IAAI,CAAC,GACpC,OAAO,CAAC,mBAAmB,CAAC,CAe9B;AAED,MAAM,MAAM,0BAA0B,CAAC,IAAI,SAAS,YAAY,GAAG,YAAY,IAAI;IACjF,KAAK,EAAE,UAAU,GAAG,MAAM,CAAA;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAA;IACrD,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;CAC7B,CAAA;AAED,wBAAsB,oBAAoB,CAAC,IAAI,SAAS,YAAY,GAAG,YAAY,EACjF,MAAM,EAAE,0BAA0B,CAAC,IAAI,CAAC,GACvC,OAAO,CAAC,sBAAsB,CAAC,CAkBjC;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,0BAA0B,GAAG,sBAAsB,CAQ/F"}
|
package/lib/create.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as A from '@automerge/automerge/slim';
|
|
2
2
|
import { toB64 } from '@enkaku/codec';
|
|
3
|
+
import { applyPatches } from '@enkaku/patch';
|
|
3
4
|
import { DocumentID } from '@kubun/id';
|
|
4
5
|
import { automergeReady } from './automerge.js';
|
|
5
|
-
import { applyPatches } from './json-patch.js';
|
|
6
6
|
export async function createSetMutation(params) {
|
|
7
7
|
const issuer = params.issuer;
|
|
8
8
|
const owner = params.owner ?? issuer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/mutation",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"license": "see LICENSE.md",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"type": "module",
|
|
@@ -15,15 +15,16 @@
|
|
|
15
15
|
],
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@automerge/automerge": "^2.2.
|
|
18
|
+
"@automerge/automerge": "^2.2.9",
|
|
19
19
|
"@enkaku/async": "^0.12.0",
|
|
20
20
|
"@enkaku/codec": "^0.12.0",
|
|
21
|
+
"@enkaku/patch": "^0.12.0",
|
|
21
22
|
"@enkaku/schema": "^0.12.0",
|
|
22
23
|
"@kubun/id": "^0.3.0"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
26
|
+
"@kubun/graphql": "^0.3.8",
|
|
25
27
|
"@kubun/db": "^0.3.3",
|
|
26
|
-
"@kubun/graphql": "^0.3.6",
|
|
27
28
|
"@kubun/protocol": "^0.3.4"
|
|
28
29
|
},
|
|
29
30
|
"scripts": {
|
package/lib/json-patch.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { PatchOperation } from '@kubun/graphql';
|
|
2
|
-
import type { DocumentData } from '@kubun/protocol';
|
|
3
|
-
export declare function parsePath(path: string): Array<string | number>;
|
|
4
|
-
export declare function getPath(obj: unknown, path: string): unknown;
|
|
5
|
-
export declare function setPath(obj: Record<string, unknown> | Array<unknown>, path: string, value: unknown): void;
|
|
6
|
-
export declare function deletePath(obj: Record<string, unknown> | Array<unknown>, path: string): void;
|
|
7
|
-
export declare function applyPatches(data: DocumentData, patches: Array<PatchOperation>): void;
|
|
8
|
-
//# sourceMappingURL=json-patch.d.ts.map
|
package/lib/json-patch.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json-patch.d.ts","sourceRoot":"","sources":["../src/json-patch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAEnD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAS9D;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAI3D;AAED,wBAAgB,OAAO,CACrB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,EAC7C,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,GACb,IAAI,CAYN;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAY5F;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,CAAC,cAAc,CAAC,GAAG,IAAI,CA0BrF"}
|
package/lib/json-patch.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
export function parsePath(path) {
|
|
2
|
-
return path.slice(1).split('/').map((key)=>{
|
|
3
|
-
// Convert array indices to numbers
|
|
4
|
-
const index = Number(key);
|
|
5
|
-
return Number.isNaN(index) ? key : index;
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
export function getPath(obj, path) {
|
|
9
|
-
const keys = parsePath(path);
|
|
10
|
-
// @ts-ignore index signature
|
|
11
|
-
return keys.reduce((acc, key)=>acc?.[key], obj);
|
|
12
|
-
}
|
|
13
|
-
export function setPath(obj, path, value) {
|
|
14
|
-
const keys = parsePath(path);
|
|
15
|
-
const lastKey = keys.pop();
|
|
16
|
-
if (lastKey !== undefined) {
|
|
17
|
-
// @ts-ignore unknown object
|
|
18
|
-
const target = keys.reduce((acc, key)=>acc[key], obj);
|
|
19
|
-
if (Array.isArray(target) && typeof lastKey === 'number' && lastKey === target.length) {
|
|
20
|
-
target.push(value) // Append to array if index is equal to array length
|
|
21
|
-
;
|
|
22
|
-
} else {
|
|
23
|
-
;
|
|
24
|
-
target[lastKey] = value;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export function deletePath(obj, path) {
|
|
29
|
-
const keys = parsePath(path);
|
|
30
|
-
const lastKey = keys.pop();
|
|
31
|
-
if (lastKey !== undefined) {
|
|
32
|
-
// @ts-ignore unknown object
|
|
33
|
-
const target = keys.reduce((acc, key)=>acc[key], obj);
|
|
34
|
-
if (Array.isArray(target) && typeof lastKey === 'number') {
|
|
35
|
-
target.splice(lastKey, 1) // Remove from array if lastKey is an index
|
|
36
|
-
;
|
|
37
|
-
} else {
|
|
38
|
-
delete target[lastKey];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
export function applyPatches(data, patches) {
|
|
43
|
-
for (const patch of patches){
|
|
44
|
-
switch(patch.op){
|
|
45
|
-
case 'add':
|
|
46
|
-
case 'replace':
|
|
47
|
-
setPath(data, patch.path, patch.value);
|
|
48
|
-
break;
|
|
49
|
-
case 'remove':
|
|
50
|
-
deletePath(data, patch.path);
|
|
51
|
-
break;
|
|
52
|
-
case 'copy':
|
|
53
|
-
{
|
|
54
|
-
const value = getPath(data, patch.from);
|
|
55
|
-
setPath(data, patch.path, value);
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
case 'move':
|
|
59
|
-
{
|
|
60
|
-
const value = getPath(data, patch.from);
|
|
61
|
-
deletePath(data, patch.from);
|
|
62
|
-
setPath(data, patch.path, value);
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
default:
|
|
66
|
-
// @ts-ignore never type
|
|
67
|
-
throw new Error(`Unknown operation: ${patch.op}`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|