@ibyar/platform 3.1.1 → 5.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020-2024 @ibyar/platform
3
+ Copyright (c) 2020-2026 @ibyar/platform
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibyar/platform",
3
- "version": "3.1.1",
3
+ "version": "5.0.0",
4
4
  "description": "Ibyar Platform, A utility package for Aurora",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/ibyar/aurora/tree/dev/packages/platform",
@@ -16,7 +16,8 @@
16
16
  "contributors": [
17
17
  {
18
18
  "name": "Muhammad Salem",
19
- "email": "salem.ebo@gmail.com"
19
+ "email": "salem.ebo@gmail.com",
20
+ "url": "https://github.com/muhammad-salem"
20
21
  }
21
22
  ],
22
23
  "main": "./index.js",
@@ -33,10 +34,10 @@
33
34
  "access": "public"
34
35
  },
35
36
  "dependencies": {
36
- "tslib": "^2.8.1"
37
+ "tslib": "^2.9.1"
37
38
  },
38
39
  "devDependencies": {
39
- "typescript": "^5.7.3"
40
+ "typescript": "^7.0.2"
40
41
  },
41
42
  "scripts": {
42
43
  "build": "tsc --build --verbose",
@@ -48,5 +49,5 @@
48
49
  "platform",
49
50
  "front-end"
50
51
  ],
51
- "gitHead": "9532d01b23f038ee839911245e7ccf1f24add1d6"
52
+ "gitHead": "c0e54a3bb5807191ee8d18c55835f4dee535d78d"
52
53
  }
package/patch/diff.d.ts CHANGED
@@ -2,12 +2,13 @@ export type TrackBy<T, R = T> = (index: number, item: T) => R;
2
2
  export type DiffOptions<T, R = T> = {
3
3
  trackBy?: TrackBy<T, R>;
4
4
  };
5
+ /**
6
+ * in memory patch operations
7
+ */
5
8
  export declare enum PatchOperation {
6
9
  ADD = "add",
7
10
  REMOVE = "remove",
8
- REPLACE = "replace",
9
- MOVE = "move",
10
- KEEP = "keep"
11
+ MOVE = "move"
11
12
  }
12
13
  export type PatchArray<T> = {
13
14
  currentIndex: number;
@@ -19,19 +20,15 @@ export type PatchObject = {
19
20
  key: string;
20
21
  op: PatchOperation;
21
22
  };
22
- export declare const PatchRoot: {
23
- op: PatchOperation;
24
- root: boolean;
25
- };
26
23
  export type DiffPatch<T> = PatchArray<T> | PatchObject;
27
24
  export declare class JSONPatch {
28
- protected diffArray<T, R = T>(input: T[], output: T[], options?: DiffOptions<T, R>): PatchArray<T>[] | [typeof PatchRoot];
29
- protected diffObject<T = any>(input: T, output: T): PatchObject[] | [typeof PatchRoot];
30
- diff<T = any>(input: T, output: T): PatchObject[] | [typeof PatchRoot];
31
- diff<T>(input: T[], output: T[]): PatchArray<T>[] | [typeof PatchRoot];
32
- diff<T, R>(input: T[], output: T[], options?: DiffOptions<T, R>): PatchArray<T>[] | [typeof PatchRoot];
25
+ protected diffArray<T, R = T>(input: T[], output: T[], options?: DiffOptions<T, R>): PatchArray<T>[];
26
+ protected diffObject<T = any>(input: T, output: T): PatchObject[];
27
+ diff<T = any>(input: T, output: T): PatchObject[];
28
+ diff<T>(input: T[], output: T[]): PatchArray<T>[];
29
+ diff<T, R>(input: T[], output: T[], options?: DiffOptions<T, R>): PatchArray<T>[];
33
30
  }
34
- export declare function diff<T = any>(input: T, output: T): PatchObject[] | [typeof PatchRoot];
35
- export declare function diff<T>(input: T[], output: T[]): PatchArray<T>[] | [typeof PatchRoot];
36
- export declare function diff<T, R>(input: T[], output: T[], options?: DiffOptions<T, R>): PatchArray<T>[] | [typeof PatchRoot];
31
+ export declare function diff<T = any>(input: T, output: T): PatchObject[];
32
+ export declare function diff<T>(input: T[], output: T[]): PatchArray<T>[];
33
+ export declare function diff<T, R>(input: T[], output: T[], options?: DiffOptions<T, R>): PatchArray<T>[];
37
34
  //# sourceMappingURL=diff.d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EAAE,CAAC,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE;IACjD,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE;CASjF;AAID,wBAAgB,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC;AAClE,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;AAClE,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC"}
package/patch/diff.js CHANGED
@@ -1,78 +1,51 @@
1
+ /**
2
+ * in memory patch operations
3
+ */
1
4
  export var PatchOperation;
2
5
  (function (PatchOperation) {
3
6
  PatchOperation["ADD"] = "add";
4
7
  PatchOperation["REMOVE"] = "remove";
5
- PatchOperation["REPLACE"] = "replace";
6
8
  PatchOperation["MOVE"] = "move";
7
- PatchOperation["KEEP"] = "keep";
8
9
  })(PatchOperation || (PatchOperation = {}));
9
10
  ;
10
- export const PatchRoot = { op: PatchOperation.REPLACE, root: true };
11
11
  export class JSONPatch {
12
12
  diffArray(input, output, options) {
13
13
  const trackBy = options?.trackBy;
14
- const identityInput = (trackBy && input.map((item, index) => trackBy(index, item))) ?? input;
15
- const identityOutput = (trackBy && output.map((item, index) => trackBy(index, item))) ?? output;
16
- const diffArray = [];
17
- identityInput.forEach((item, index) => {
14
+ const identityInput = (trackBy && input.map((item, index) => trackBy(index, item))) ?? input.slice();
15
+ const identityOutput = (trackBy && output.map((item, index) => trackBy(index, item))) ?? output.slice();
16
+ const diff = [];
17
+ for (let currentIndex = identityInput.length - 1; currentIndex >= 0; currentIndex--) {
18
+ const item = identityInput[currentIndex];
18
19
  const nextIndex = identityOutput.indexOf(item);
19
- const op = nextIndex == -1
20
- ? PatchOperation.REMOVE
21
- : index == nextIndex
22
- ? PatchOperation.KEEP
23
- : PatchOperation.MOVE;
24
- diffArray.push({
25
- currentIndex: index,
26
- nextIndex: nextIndex,
27
- op: op,
28
- item: output[nextIndex]
29
- });
30
- });
31
- identityOutput.forEach((item, index) => {
32
- const oldIndex = identityInput.indexOf(item);
33
- if (oldIndex == -1) {
34
- diffArray.push({
35
- currentIndex: -1,
36
- nextIndex: index,
37
- op: PatchOperation.ADD,
38
- item: output[index]
39
- });
20
+ if (nextIndex !== -1) {
21
+ continue;
40
22
  }
41
- });
42
- const patchArray = new Array(output.length);
43
- let i = 0;
44
- diffArray.forEach(item => {
45
- if (item.ignore) {
23
+ diff.push({
24
+ nextIndex,
25
+ currentIndex,
26
+ op: PatchOperation.REMOVE,
27
+ item: input[currentIndex]
28
+ });
29
+ identityInput.splice(currentIndex, 1);
30
+ }
31
+ identityOutput.forEach((item, nextIndex) => {
32
+ const currentIndex = identityInput.indexOf(item);
33
+ if (currentIndex === nextIndex) {
46
34
  return;
47
35
  }
48
- let patch = item;
49
- if (PatchOperation.REMOVE == item.op) {
50
- const replacedItem = diffArray.find(r => !r.ignore && r.nextIndex == item.currentIndex);
51
- if (replacedItem) {
52
- if (PatchOperation.MOVE == replacedItem.op) {
53
- item.ignore = replacedItem.ignore = true;
54
- return;
55
- }
56
- else {
57
- replacedItem.ignore = true;
58
- patch = {
59
- currentIndex: item.currentIndex,
60
- nextIndex: replacedItem.nextIndex,
61
- op: PatchOperation.REPLACE,
62
- item: replacedItem.item
63
- };
64
- }
65
- }
36
+ const op = currentIndex === -1 ? PatchOperation.ADD : PatchOperation.MOVE;
37
+ diff.push({
38
+ op,
39
+ nextIndex,
40
+ currentIndex,
41
+ item: output[nextIndex]
42
+ });
43
+ if (op === PatchOperation.MOVE) {
44
+ identityInput.splice(currentIndex, 1);
66
45
  }
67
- patchArray[i++] = patch;
46
+ identityInput.splice(nextIndex, 0, item);
68
47
  });
69
- const removed = patchArray
70
- .filter(item => !item.ignore && PatchOperation.REMOVE == item.op)
71
- .sort((a, b) => b.currentIndex - a.currentIndex);
72
- const apply = patchArray
73
- .filter(item => !item.ignore && PatchOperation.REMOVE != item.op)
74
- .sort((a, b) => a.nextIndex - b.nextIndex);
75
- return removed.concat(apply);
48
+ return diff;
76
49
  }
77
50
  diffObject(input, output) {
78
51
  return [];
@@ -84,7 +57,7 @@ export class JSONPatch {
84
57
  else if (typeof input == 'object' && typeof output == 'object') {
85
58
  return this.diffObject(input, output);
86
59
  }
87
- return [PatchRoot];
60
+ throw new Error('Not supported operation');
88
61
  }
89
62
  }
90
63
  const jsonPatch = new JSONPatch();
package/patch/diff.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"diff.js","sourceRoot":"","sources":["../../../src/platform/patch/diff.ts"],"names":[],"mappings":"AAGA,MAAM,CAAN,IAAY,cAMX;AAND,WAAY,cAAc;IACzB,6BAAW,CAAA;IACX,mCAAiB,CAAA;IACjB,qCAAmB,CAAA;IACnB,+BAAa,CAAA;IACb,+BAAa,CAAA;AACd,CAAC,EANW,cAAc,KAAd,cAAc,QAMzB;AAAA,CAAC;AAIF,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,EAAE,EAAE,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAGpE,MAAM,OAAO,SAAS;IAEX,SAAS,CAAW,KAAU,EAAE,MAAW,EAAE,OAA2B;QAEjF,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,CAAC;QACjC,MAAM,aAAa,GAAG,CAAC,OAAO,IAAI,K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rackBy<T, R> };\n\nexport enum PatchOperation {\n\tADD = 'add',\n\tREMOVE = 'remove',\n\tREPLACE = 'replace',\n\tMOVE = 'move',\n\tKEEP = 'keep'\n};\n\nexport type PatchArray<T> = { currentIndex: number, nextIndex: number, op: PatchOperation, item: T };\nexport type PatchObject = { key: string, op: PatchOperation };\nexport const PatchRoot = { op: PatchOperation.REPLACE, root: true };\nexport type DiffPatch<T> = PatchArray<T> | PatchObject;\n\nexport class JSONPatch {\n\n\tprotected diffArray<T, R = T>(input: T[], output: T[], options?: DiffOptions<T, R>): PatchArray<T>[] | [typeof PatchRoot] {\n\t\ttype DiffArray = PatchArray<T> & { ignore?: boolean };\n\t\tconst trackBy = options?.trackBy;\n\t\tconst identityInput = (trackBy && input.map((item, index) => trackBy(index, item))) ?? input;\n\t\tconst identityOutput = (trackBy && output.map((item, index) => trackBy(index, item))) ?? output;\n\t\tconst diffArray: DiffArray[] = [];\n\t\tidentityInput.forEach((item, index) => {\n\t\t\tconst nextIndex = identityOutput.indexOf(item as T & R);\n\t\t\tconst op: PatchOperation = nextIndex == -1\n\t\t\t\t? PatchOperation.REMOVE\n\t\t\t\t: index == nextIndex\n\t\t\t\t\t? PatchOperation.KEEP\n\t\t\t\t\t: PatchOperation.MOVE;\n\t\t\tdiffArray.push({\n\t\t\t\tcurrentIndex: index,\n\t\t\t\tnextIndex: nextIndex,\n\t\t\t\top: op,\n\t\t\t\titem: output[nextIndex]\n\t\t\t});\n\t\t});\n\t\tidentityOutput.forEach((item, index) => {\n\t\t\tconst oldIndex = identityInput.indexOf(item as T & R);\n\t\t\tif (oldIndex == -1) {\n\t\t\t\tdiffArray.push({\n\t\t\t\t\tcurrentIndex: -1,\n\t\t\t\t\tnextIndex: index,\n\t\t\t\t\top: PatchOperation.ADD,\n\t\t\t\t\titem: output[index]\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t\tconst patchArray: DiffArray[] = new Array<DiffArray>(output.length);\n\t\tlet i = 0;\n\t\tdiffArray.forEach(item => {\n\t\t\tif (item.ignore) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet patch = item;\n\t\t\tif (PatchOperation.REMOVE == item.op) {\n\t\t\t\tconst replacedItem = diffArray.find(r => !r.ignore && r.nextIndex == item.currentIndex);\n\t\t\t\tif (replacedItem) {\n\t\t\t\t\tif (PatchOperation.MOVE == replacedItem.op) {\n\t\t\t\t\t\titem.ignore = replacedItem.ignore = true;\n\t\t\t\t\t\treturn;\n\t\t\t\t\t} else {\n\t\t\t\t\t\treplacedItem.ignore = true;\n\t\t\t\t\t\tpatch = {\n\t\t\t\t\t\t\tcurrentIndex: item.currentIndex,\n\t\t\t\t\t\t\tnextIndex: replacedItem.nextIndex,\n\t\t\t\t\t\t\top: PatchOperation.REPLACE,\n\t\t\t\t\t\t\titem: replacedItem.item\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tpatchArray[i++] = patch;\n\t\t});\n\t\tconst removed = patchArray\n\t\t\t.filter(item => !item.ignore && PatchOperation.REMOVE == item.op)\n\t\t\t.sort((a, b) => b.currentIndex - a.currentIndex);\n\t\tconst apply = patchArray\n\t\t\t.filter(item => !item.ignore && PatchOperation.REMOVE != item.op)\n\t\t\t.sort((a, b) => a.nextIndex - b.nextIndex);\n\t\treturn removed.concat(apply) as PatchArray<T>[];\n\t}\n\n\tprotected diffObject<T = any>(input: T, output: T): PatchObject[] | [typeof PatchRoot] {\n\t\treturn [];\n\t}\n\n\tdiff<T = any>(input: T, output: T): PatchObject[] | [typeof PatchRoot];\n\tdiff<T>(input: T[], output: T[]): PatchArray<T>[] | [typeof PatchRoot];\n\tdiff<T, R>(input: T[], output: T[], options?: DiffOptions<T, R>): PatchArray<T>[] | [typeof PatchRoot];\n\tdiff(input: any, output: any, options?: DiffOptions<any, any>): DiffPatch<any>[] | [typeof PatchRoot] {\n\t\tif (Array.isArray(input) && Array.isArray(output)) {\n\t\t\treturn this.diffArray(input, output, options);\n\t\t} else if (typeof input == 'object' && typeof output == 'object') {\n\t\t\treturn this.diffObject(input, output);\n\t\t}\n\t\treturn [PatchRoot];\n\t}\n}\n\nconst jsonPatch = new JSONPatch();\n\nexport function diff<T = any>(input: T, output: T): PatchObject[] | [typeof PatchRoot];\nexport function diff<T>(input: T[], output: T[]): PatchArray<T>[] | [typeof PatchRoot];\nexport function diff<T, R>(input: T[], output: T[], options?: DiffOptions<T, R>): PatchArray<T>[] | [typeof PatchRoot];\nexport function diff(input: any, output: any, options?: DiffOptions<any, any>): DiffPatch<any>[] | [typeof PatchRoot] {\n\treturn jsonPatch.diff(input, output, options);\n}\n"]}
1
+ {"version":3,"file":"diff.js","sourceRoot":"","sources":["../../../src/platform/patch/diff.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,CAAN,IAAY,cAIX;AAJD,WAAY,cAAc;IACzB,6BAAW,CAAA;IACX,mCAAiB,CAAA;IACjB,+BAAa,CAAA;AACd,CAAC,EAJW,cAAc,KAAd,cAAc,QAIzB;AAAA,CAAC;AAMF,MAAM,OAAO,SAAS;IAEX,SAAS,CAAW,KAAU,EAAE,MAAW,EAAE,OAA2B;QACjF,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,CAAC;QACjC,MAAM,aAAa,GAAG,CAAC,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,EAAoB,CAAC;QACvH,MAAM,cAAc,GAAG,CAAC,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,KAAK,EAAoB,CAAC;QAC1H,MAAM,IAAI,GAAoB,EAAE,CAAC;QACjC,KAAK,IAAI,YAAY,GAAG,aAAa,CAAC,MAA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ChD,OAAO,EAAE,CAAC;IACX,CAAC;IAKD,IAAI,CAAC,KAAU,EAAE,MAAW,EAAE,OAA+B;QAC5D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACnD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC;aAAM,IAAI,OAAO,KAAK,IAAI,QAAQ,IAAI,OAAO,MAAM,IAAI,QAAQ,EAAE,CAAC;YAClE,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACvC,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;CACD;AAED,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;AAKlC,MAAM,UAAU,IAAI,CAAC,KAAU,EAAE,MAAW,EAAE,OAA+B;IAC5E,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["export type TrackBy<T, R = T> = (index: number, item: T) => R;\nexport type DiffOptions<T, R = T> = { trackBy?: TrackBy<T, R> };\n\n\n/**\n * in memory patch operations\n */\nexport enum PatchOperation {\n\tADD = 'add',\n\tREMOVE = 'remove',\n\tMOVE = 'move',\n};\n\nexport type PatchArray<T> = { currentIndex: number, nextIndex: number, op: PatchOperation, item: T };\nexport type PatchObject = { key: string, op: PatchOperation };\nexport type DiffPatch<T> = PatchArray<T> | PatchObject;\n\nexport class JSONPatch {\n\n\tprotected diffArray<T, R = T>(input: T[], output: T[], options?: DiffOptions<T, R>): PatchArray<T>[] {\n\t\tconst trackBy = options?.trackBy;\n\t\tconst identityInput = (trackBy && input.map((item, index) => trackBy(index, item))) ?? input.slice() as unknown as R[];\n\t\tconst identityOutput = (trackBy && output.map((item, index) => trackBy(index, item))) ?? output.slice() as unknown as R[];\n\t\tconst diff: PatchArray<T>[] = [];\n\t\tfor (let currentIndex = identityInput.length - 1; currentIndex >= 0; currentIndex--) {\n\t\t\tconst item = identityInput[currentIndex];\n\t\t\tconst nextIndex = identityOutput.indexOf(item);\n\t\t\tif (nextIndex !== -1) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tdiff.push({\n\t\t\t\tnextIndex,\n\t\t\t\tcurrentIndex,\n\t\t\t\top: PatchOperation.REMOVE,\n\t\t\t\titem: input[currentIndex]\n\t\t\t});\n\t\t\tidentityInput.splice(currentIndex, 1);\n\t\t}\n\t\tidentityOutput.forEach((item, nextIndex) => {\n\t\t\tconst currentIndex = identityInput.indexOf(item);\n\t\t\tif (currentIndex === nextIndex) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst op = currentIndex === -1 ? PatchOperation.ADD : PatchOperation.MOVE;\n\t\t\tdiff.push({\n\t\t\t\top,\n\t\t\t\tnextIndex,\n\t\t\t\tcurrentIndex,\n\t\t\t\titem: output[nextIndex]\n\t\t\t});\n\t\t\tif (op === PatchOperation.MOVE) {\n\t\t\t\tidentityInput.splice(currentIndex, 1);\n\t\t\t}\n\t\t\tidentityInput.splice(nextIndex, 0, item);\n\t\t});\n\t\treturn diff;\n\t}\n\n\tprotected diffObject<T = any>(input: T, output: T): PatchObject[] {\n\t\treturn [];\n\t}\n\n\tdiff<T = any>(input: T, output: T): PatchObject[];\n\tdiff<T>(input: T[], output: T[]): PatchArray<T>[];\n\tdiff<T, R>(input: T[], output: T[], options?: DiffOptions<T, R>): PatchArray<T>[];\n\tdiff(input: any, output: any, options?: DiffOptions<any, any>): DiffPatch<any>[] {\n\t\tif (Array.isArray(input) && Array.isArray(output)) {\n\t\t\treturn this.diffArray(input, output, options);\n\t\t} else if (typeof input == 'object' && typeof output == 'object') {\n\t\t\treturn this.diffObject(input, output);\n\t\t}\n\t\tthrow new Error('Not supported operation');\n\t}\n}\n\nconst jsonPatch = new JSONPatch();\n\nexport function diff<T = any>(input: T, output: T): PatchObject[];\nexport function diff<T>(input: T[], output: T[]): PatchArray<T>[];\nexport function diff<T, R>(input: T[], output: T[], options?: DiffOptions<T, R>): PatchArray<T>[];\nexport function diff(input: any, output: any, options?: DiffOptions<any, any>): DiffPatch<any>[] {\n\treturn jsonPatch.diff(input, output, options);\n}\n"]}