@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.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +695 -0
  3. package/dist/Delta/batch.d.mts +57 -0
  4. package/dist/Delta/batch.mjs +61 -0
  5. package/dist/Delta/chop.d.mts +56 -0
  6. package/dist/Delta/chop.mjs +60 -0
  7. package/dist/Delta/clean.d.mts +57 -0
  8. package/dist/Delta/clean.mjs +61 -0
  9. package/dist/Delta/compose.d.mts +58 -0
  10. package/dist/Delta/compose.mjs +100 -0
  11. package/dist/Delta/concat.d.mts +50 -0
  12. package/dist/Delta/concat.mjs +51 -0
  13. package/dist/Delta/diff.d.mts +73 -0
  14. package/dist/Delta/diff.mjs +124 -0
  15. package/dist/Delta/equals.d.mts +43 -0
  16. package/dist/Delta/equals.mjs +50 -0
  17. package/dist/Delta/index.d.mts +26 -0
  18. package/dist/Delta/index.mjs +37 -0
  19. package/dist/Delta/insert.d.mts +52 -0
  20. package/dist/Delta/insert.mjs +57 -0
  21. package/dist/Delta/invert.d.mts +54 -0
  22. package/dist/Delta/invert.mjs +77 -0
  23. package/dist/Delta/length.d.mts +51 -0
  24. package/dist/Delta/length.mjs +51 -0
  25. package/dist/Delta/push.d.mts +51 -0
  26. package/dist/Delta/push.mjs +87 -0
  27. package/dist/Delta/remove.d.mts +41 -0
  28. package/dist/Delta/remove.mjs +46 -0
  29. package/dist/Delta/retain.d.mts +70 -0
  30. package/dist/Delta/retain.mjs +76 -0
  31. package/dist/Delta/slice.d.mts +64 -0
  32. package/dist/Delta/slice.mjs +77 -0
  33. package/dist/Delta/transform.d.mts +63 -0
  34. package/dist/Delta/transform.mjs +91 -0
  35. package/dist/Op/index.d.mts +21 -0
  36. package/dist/OpAttributes/compose.d.mts +6 -0
  37. package/dist/OpAttributes/compose.mjs +25 -0
  38. package/dist/OpAttributes/diff.d.mts +6 -0
  39. package/dist/OpAttributes/diff.mjs +14 -0
  40. package/dist/OpAttributes/index.d.mts +15 -0
  41. package/dist/OpAttributes/invert.d.mts +6 -0
  42. package/dist/OpAttributes/invert.mjs +16 -0
  43. package/dist/OpAttributes/isEqual.d.mts +6 -0
  44. package/dist/OpAttributes/isEqual.mjs +16 -0
  45. package/dist/OpAttributes/transform.d.mts +6 -0
  46. package/dist/OpAttributes/transform.mjs +13 -0
  47. package/dist/OpIterator/create.mjs +11 -0
  48. package/dist/OpIterator/hasNext.mjs +9 -0
  49. package/dist/OpIterator/next.mjs +36 -0
  50. package/dist/OpIterator/peek.mjs +7 -0
  51. package/dist/OpIterator/peekLength.mjs +9 -0
  52. package/dist/OpIterator/peekType.mjs +7 -0
  53. package/dist/index.d.mts +2 -0
  54. package/dist/index.mjs +3 -0
  55. package/dist/internals/hasKeys.mjs +8 -0
  56. 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,6 @@
1
+ import { OpAttributes } from "./index.mjs";
2
+
3
+ //#region src/OpAttributes/isEqual.d.ts
4
+ declare function isEqual<T extends OpAttributes>(a: T | undefined, b: NoInfer<T> | undefined): boolean;
5
+ //#endregion
6
+ export { isEqual };
@@ -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,11 @@
1
+ //#region src/OpIterator/create.ts
2
+ function create(ops) {
3
+ return {
4
+ index: 0,
5
+ offset: 0,
6
+ ops
7
+ };
8
+ }
9
+
10
+ //#endregion
11
+ export { create };
@@ -0,0 +1,9 @@
1
+ import { peekLength } from "./peekLength.mjs";
2
+
3
+ //#region src/OpIterator/hasNext.ts
4
+ function hasNext(opIt) {
5
+ return peekLength(opIt) < Infinity;
6
+ }
7
+
8
+ //#endregion
9
+ export { hasNext };
@@ -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 };
@@ -0,0 +1,7 @@
1
+ //#region src/OpIterator/peek.ts
2
+ function peek(opIt) {
3
+ return opIt.ops[opIt.index];
4
+ }
5
+
6
+ //#endregion
7
+ export { peek };
@@ -0,0 +1,9 @@
1
+ //#region src/OpIterator/peekLength.ts
2
+ function peekLength(opIt) {
3
+ const op = opIt.ops[opIt.index];
4
+ if (!op) return Infinity;
5
+ return (op.type === "insert" ? op.value.length : op.value) - opIt.offset;
6
+ }
7
+
8
+ //#endregion
9
+ export { peekLength };
@@ -0,0 +1,7 @@
1
+ //#region src/OpIterator/peekType.ts
2
+ function peekType(opIt) {
3
+ return opIt.ops[opIt.index]?.type ?? "retain";
4
+ }
5
+
6
+ //#endregion
7
+ export { peekType };
@@ -0,0 +1,2 @@
1
+ import { Delta } from "./Delta/index.mjs";
2
+ export { Delta };
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { Delta } from "./Delta/index.mjs";
2
+
3
+ export { Delta };
@@ -0,0 +1,8 @@
1
+ //#region src/internals/hasKeys.ts
2
+ function hasKeys(value) {
3
+ for (const key in value) if (Object.hasOwn(value, key)) return true;
4
+ return false;
5
+ }
6
+
7
+ //#endregion
8
+ export { hasKeys };
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
+ }