@monstermann/delta 0.0.0
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/LICENSE +21 -0
- package/README.md +695 -0
- package/dist/Delta/batch.d.mts +57 -0
- package/dist/Delta/batch.mjs +61 -0
- package/dist/Delta/chop.d.mts +56 -0
- package/dist/Delta/chop.mjs +60 -0
- package/dist/Delta/clean.d.mts +57 -0
- package/dist/Delta/clean.mjs +61 -0
- package/dist/Delta/compose.d.mts +58 -0
- package/dist/Delta/compose.mjs +100 -0
- package/dist/Delta/concat.d.mts +50 -0
- package/dist/Delta/concat.mjs +51 -0
- package/dist/Delta/diff.d.mts +73 -0
- package/dist/Delta/diff.mjs +124 -0
- package/dist/Delta/equals.d.mts +43 -0
- package/dist/Delta/equals.mjs +50 -0
- package/dist/Delta/index.d.mts +26 -0
- package/dist/Delta/index.mjs +37 -0
- package/dist/Delta/insert.d.mts +52 -0
- package/dist/Delta/insert.mjs +57 -0
- package/dist/Delta/invert.d.mts +54 -0
- package/dist/Delta/invert.mjs +77 -0
- package/dist/Delta/length.d.mts +51 -0
- package/dist/Delta/length.mjs +51 -0
- package/dist/Delta/push.d.mts +51 -0
- package/dist/Delta/push.mjs +87 -0
- package/dist/Delta/remove.d.mts +41 -0
- package/dist/Delta/remove.mjs +46 -0
- package/dist/Delta/retain.d.mts +70 -0
- package/dist/Delta/retain.mjs +76 -0
- package/dist/Delta/slice.d.mts +64 -0
- package/dist/Delta/slice.mjs +77 -0
- package/dist/Delta/transform.d.mts +63 -0
- package/dist/Delta/transform.mjs +91 -0
- package/dist/Op/index.d.mts +21 -0
- package/dist/OpAttributes/compose.d.mts +6 -0
- package/dist/OpAttributes/compose.mjs +25 -0
- package/dist/OpAttributes/diff.d.mts +6 -0
- package/dist/OpAttributes/diff.mjs +14 -0
- package/dist/OpAttributes/index.d.mts +15 -0
- package/dist/OpAttributes/invert.d.mts +6 -0
- package/dist/OpAttributes/invert.mjs +16 -0
- package/dist/OpAttributes/isEqual.d.mts +6 -0
- package/dist/OpAttributes/isEqual.mjs +16 -0
- package/dist/OpAttributes/transform.d.mts +6 -0
- package/dist/OpAttributes/transform.mjs +13 -0
- package/dist/OpIterator/create.mjs +11 -0
- package/dist/OpIterator/hasNext.mjs +9 -0
- package/dist/OpIterator/next.mjs +36 -0
- package/dist/OpIterator/peek.mjs +7 -0
- package/dist/OpIterator/peekLength.mjs +9 -0
- package/dist/OpIterator/peekType.mjs +7 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3 -0
- package/dist/internals/hasKeys.mjs +8 -0
- package/package.json +42 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { compose } from "./compose.mjs";
|
|
2
|
+
import { diff } from "./diff.mjs";
|
|
3
|
+
import { invert } from "./invert.mjs";
|
|
4
|
+
import { isEqual } from "./isEqual.mjs";
|
|
5
|
+
import { transform } from "./transform.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/OpAttributes/index.d.ts
|
|
8
|
+
|
|
9
|
+
type OpAttributes = Record<string, unknown>;
|
|
10
|
+
type NullableOpAttributes<T> = { [K in keyof T]?: T[K] | null };
|
|
11
|
+
declare namespace OpAttributes {
|
|
12
|
+
export { compose, diff, invert, isEqual, transform };
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { NullableOpAttributes, OpAttributes };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NullableOpAttributes, OpAttributes } from "./index.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/OpAttributes/invert.d.ts
|
|
4
|
+
declare function invert<T extends OpAttributes>(a: NullableOpAttributes<T> | undefined, b: NullableOpAttributes<NoInfer<T>> | undefined): NullableOpAttributes<T>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { invert };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/OpAttributes/invert.ts
|
|
2
|
+
function invert(a, b) {
|
|
3
|
+
if (!a) a = {};
|
|
4
|
+
if (!b) b = {};
|
|
5
|
+
const result = {};
|
|
6
|
+
const keys = new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
7
|
+
for (const key of keys) {
|
|
8
|
+
if (a[key] === b[key]) continue;
|
|
9
|
+
if (key in b && key in a) result[key] = b[key];
|
|
10
|
+
else if (!(key in b)) result[key] = null;
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { invert };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/OpAttributes/isEqual.ts
|
|
2
|
+
function isEqual(a, b) {
|
|
3
|
+
if (a === b) return true;
|
|
4
|
+
if (!a || !b) return false;
|
|
5
|
+
const keysA = Object.keys(a);
|
|
6
|
+
const keysB = Object.keys(b);
|
|
7
|
+
if (keysA.length !== keysB.length) return false;
|
|
8
|
+
for (const key of keysA) {
|
|
9
|
+
if (!Object.hasOwn(b, key)) return false;
|
|
10
|
+
if (!Object.is(a[key], b[key])) return false;
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { isEqual };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NullableOpAttributes, OpAttributes } from "./index.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/OpAttributes/transform.d.ts
|
|
4
|
+
declare function transform<T extends OpAttributes>(a: NullableOpAttributes<T> | undefined, b: NullableOpAttributes<NoInfer<T>> | undefined, priority?: boolean): NullableOpAttributes<T> | undefined;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { transform };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/OpAttributes/transform.ts
|
|
2
|
+
function transform(a, b, priority = false) {
|
|
3
|
+
if (!a || !b || !priority) return b;
|
|
4
|
+
const result = {};
|
|
5
|
+
for (const key of Object.keys(b)) {
|
|
6
|
+
if (key in a) continue;
|
|
7
|
+
result[key] = b[key];
|
|
8
|
+
}
|
|
9
|
+
return Object.keys(result).length ? result : void 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { transform };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/OpIterator/next.ts
|
|
2
|
+
function next(opIt, length = Infinity) {
|
|
3
|
+
const nextOp = opIt.ops[opIt.index];
|
|
4
|
+
if (nextOp) {
|
|
5
|
+
const offset = opIt.offset;
|
|
6
|
+
const opLength = nextOp.type === "insert" ? nextOp.value.length : nextOp.value;
|
|
7
|
+
if (length >= opLength - offset) {
|
|
8
|
+
length = opLength - offset;
|
|
9
|
+
opIt.index += 1;
|
|
10
|
+
opIt.offset = 0;
|
|
11
|
+
} else opIt.offset += length;
|
|
12
|
+
if (nextOp.type === "remove") return {
|
|
13
|
+
attributes: void 0,
|
|
14
|
+
type: "remove",
|
|
15
|
+
value: length
|
|
16
|
+
};
|
|
17
|
+
if (nextOp.type === "retain") return {
|
|
18
|
+
attributes: nextOp.attributes,
|
|
19
|
+
type: "retain",
|
|
20
|
+
value: length
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
attributes: nextOp.attributes,
|
|
24
|
+
type: "insert",
|
|
25
|
+
value: nextOp.value.slice(offset, offset + length)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
attributes: void 0,
|
|
30
|
+
type: "retain",
|
|
31
|
+
value: Infinity
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { next };
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@monstermann/delta",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"description": "Functional operational-transform.",
|
|
6
|
+
"author": "Michael Ostermann <michaelostermann@me.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://MichaelOstermann.github.io/delta",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/MichaelOstermann/delta.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/MichaelOstermann/delta/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.mts",
|
|
21
|
+
"import": "./dist/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./*": "./dist/*"
|
|
24
|
+
},
|
|
25
|
+
"main": "./dist/index.mjs",
|
|
26
|
+
"module": "./dist/index.mjs",
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"bundle": "tsdown"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@monstermann/dfdl": "^0.1.0",
|
|
36
|
+
"@monstermann/remmi": "^0.2.0",
|
|
37
|
+
"fast-diff": "^1.3.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@monstermann/unplugin-tree-shake-import-namespaces": "^0.3.0"
|
|
41
|
+
}
|
|
42
|
+
}
|