better-supabase 0.3.0 → 0.5.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 (211) hide show
  1. package/README.md +9 -6
  2. package/bin/better-supabase.js +4 -0
  3. package/dist/{base64-CQeB1eSf.js → base64-D2gsioCY.js} +2 -2
  4. package/dist/channel-FQW-CnGR.d.ts +70 -0
  5. package/dist/claims-BAf6c7is.js +48 -0
  6. package/dist/cli/_format-Cax5EsM9.js +101 -0
  7. package/dist/cli/bin.d.ts +1 -0
  8. package/dist/cli/bin.js +48 -0
  9. package/dist/cli/codemod-DqV7612m.js +388 -0
  10. package/dist/cli/command-CK14fP91.js +502 -0
  11. package/dist/cli/compare-BmIWVEui.js +9 -0
  12. package/dist/cli/config-CPVpXP5I.js +1965 -0
  13. package/dist/cli/config-dtoekM0v.js +2 -0
  14. package/dist/cli/db-DOBPt660.js +52 -0
  15. package/dist/cli/diff-SjkO5rNr.js +752 -0
  16. package/dist/cli/dist-DBPdlPYK.js +1112 -0
  17. package/dist/cli/dist-DreZ24Sz.js +129 -0
  18. package/dist/cli/dist-xn4wlboc.js +732 -0
  19. package/dist/cli/doctor-L7Z8mYTx.js +2863 -0
  20. package/dist/cli/env-DmKv_G4A.js +108 -0
  21. package/dist/cli/env-jIFUADLY.js +511 -0
  22. package/dist/cli/errors-4v4DTtda.js +56 -0
  23. package/dist/cli/fastest-levenshtein-CFN-lNDv.js +120 -0
  24. package/dist/cli/gen-BJc9vdyu.js +2 -0
  25. package/dist/cli/gen-C2osRcr5.js +2204 -0
  26. package/dist/cli/index.d.ts +493 -0
  27. package/dist/cli/index.js +184 -0
  28. package/dist/cli/init-Saf5-R9T.js +550 -0
  29. package/dist/cli/introspect--H7oGmcd.js +81 -0
  30. package/dist/cli/io-k41_z-jT.js +24 -0
  31. package/dist/cli/json5-ChRycquj.js +787 -0
  32. package/dist/cli/jsonc-BUniUpOk.js +2 -0
  33. package/dist/cli/jsonc-D5Fu67jw.js +45 -0
  34. package/dist/cli/keys-ByKHnvP9.js +83 -0
  35. package/dist/cli/ohash-D7bG_EOb.js +277 -0
  36. package/dist/cli/openapi-Cp5Fyta-.js +66 -0
  37. package/dist/cli/project-B_GeXyHh.js +70 -0
  38. package/dist/cli/prompts-BNcNfAve.js +1142 -0
  39. package/dist/cli/prompts-BTYQGunc.js +2 -0
  40. package/dist/cli/read-sets-BfMQcKy8.js +289 -0
  41. package/dist/cli/rolldown-runtime-BPOCksWG.js +24 -0
  42. package/dist/cli/run-BKR2W_79.js +351 -0
  43. package/dist/cli/seed-CUlqWh-8.js +98 -0
  44. package/dist/cli/skills-LJJIhLFR.js +137 -0
  45. package/dist/cli/sql-DzPbfngx.js +348 -0
  46. package/dist/cli/style-C0NFdJRL.js +29 -0
  47. package/dist/cli/toml-DB-MNnFs.js +424 -0
  48. package/dist/cli/version-BDJuO0UR.js +4 -0
  49. package/dist/cli/yaml-CYCbJ6et.js +2252 -0
  50. package/dist/client/index.d.ts +2 -2
  51. package/dist/client/index.js +15 -22
  52. package/dist/clone-BfgmLU90.js +21 -0
  53. package/dist/{compiler-2zqGzxVZ.d.ts → compiler-BXH_aZ7N.d.ts} +2 -2
  54. package/dist/config/index.d.ts +4 -4
  55. package/dist/config/index.js +5 -5
  56. package/dist/{config-DOsGYSiT.js → config-DreERlKo.js} +1 -1
  57. package/dist/{config-C1CYcm6o.d.ts → config-T_ejwyd3.d.ts} +176 -11
  58. package/dist/{define-DUbydmJa.d.ts → define-Bp_BZa5h.d.ts} +37 -29
  59. package/dist/{define-DF341GDj.js → define-cNKzqwL_.js} +356 -89
  60. package/dist/edge/index.d.ts +20 -13
  61. package/dist/edge/index.js +55 -26
  62. package/dist/{entitlements-DvJXoI02.d.ts → entitlements-DUxU4oHe.d.ts} +2 -2
  63. package/dist/env/index.d.ts +2 -2
  64. package/dist/env/index.js +34 -1
  65. package/dist/{errors-Bl3rkOzo.js → errors-DtwXa6b8.js} +2 -1
  66. package/dist/events/index.d.ts +3 -2
  67. package/dist/events/index.js +69 -16
  68. package/dist/events-aIO7vsIk.d.ts +230 -0
  69. package/dist/executor-BunPOO-k.d.ts +402 -0
  70. package/dist/{executor-B26lgbHD.d.ts → executor-Cghdstwu.d.ts} +1 -2
  71. package/dist/{executor-C57jx2pn.js → executor-XycESQPH.js} +3 -3
  72. package/dist/hono/index.d.ts +27 -23
  73. package/dist/hono/index.js +46 -11
  74. package/dist/impersonation-VfaGc4Q_.js +41 -0
  75. package/dist/{index-BNsABq7P.d.ts → index-BGdgBPdf.d.ts} +66 -25
  76. package/dist/{index-qriRM9cZ.d.ts → index-C7f8cOBM.d.ts} +4 -4
  77. package/dist/{index-Dy6kuF0P.d.ts → index-CLg87OBW.d.ts} +6 -1
  78. package/dist/{index-GV77NpRP.d.ts → index-DOESKG27.d.ts} +34 -9
  79. package/dist/{index-CriFFJ_p.d.ts → index-DgILJRXj.d.ts} +43 -17
  80. package/dist/{index-UJ-LUxtI.d.ts → index-DmXSxbLi.d.ts} +14 -14
  81. package/dist/{index-Cf-D2jk1.d.ts → index-Dxn2a5cw.d.ts} +2 -2
  82. package/dist/{index-CTTMS6_1.d.ts → index-SaTsEfGP.d.ts} +86 -9
  83. package/dist/{index-CADlNHK-.d.ts → index-fag8VJZ2.d.ts} +5 -6
  84. package/dist/index.d.ts +34 -17
  85. package/dist/index.js +15 -14
  86. package/dist/jobs/index.d.ts +147 -95
  87. package/dist/jobs/index.js +773 -250
  88. package/dist/{json-schema--aOXAGfU.js → json-schema-m1fiwKgN.js} +23 -2
  89. package/dist/kit-events-CTFDfSwb.js +60 -0
  90. package/dist/kit-transport-B82k1djG.d.ts +33 -0
  91. package/dist/kit-transport-DJlHQUBU.js +55 -0
  92. package/dist/{config-Be4GwsqI.js → kits-CGLLrNPd.js} +38 -10
  93. package/dist/list/index.d.ts +1 -1
  94. package/dist/list/index.js +3 -3
  95. package/dist/{live-D8rV1Ldw.js → live-CdJBOc4f.js} +13 -9
  96. package/dist/{live-QE3UPbGm.d.ts → live-D9W2M5aO.d.ts} +16 -15
  97. package/dist/lookup-BaP5bI27.js +18 -0
  98. package/dist/mcp/index.d.ts +39 -22
  99. package/dist/mcp/index.js +39 -25
  100. package/dist/{mfa-x3V3vGh-.d.ts → mfa-CusDgPaD.d.ts} +5 -1
  101. package/dist/next/image/index.js +6 -3
  102. package/dist/next/index.d.ts +60 -36
  103. package/dist/next/index.js +167 -50
  104. package/dist/notifications/index.d.ts +162 -0
  105. package/dist/notifications/index.js +264 -0
  106. package/dist/openapi/index.d.ts +1 -1
  107. package/dist/openapi/index.js +6 -6
  108. package/dist/orgs/index.d.ts +132 -0
  109. package/dist/orgs/index.js +245 -0
  110. package/dist/orpc/index.d.ts +37 -20
  111. package/dist/orpc/index.js +24 -11
  112. package/dist/otel/index.d.ts +24 -5
  113. package/dist/otel/index.js +124 -64
  114. package/dist/permdock-sql-C2Inc6Xc.d.ts +29 -0
  115. package/dist/permdock-sql-DgOfeixi.js +51 -0
  116. package/dist/plugin-DwARMuQp.js +59 -0
  117. package/dist/{plugin-DVRB8qNE.d.ts → plugin-o144f322.d.ts} +17 -5
  118. package/dist/plugins/actor/index.d.ts +5 -2
  119. package/dist/plugins/actor/index.js +22 -8
  120. package/dist/plugins/rules/index.d.ts +2 -2
  121. package/dist/plugins/rules/index.js +52 -17
  122. package/dist/plugins/soft-delete/index.d.ts +3 -3
  123. package/dist/plugins/soft-delete/index.js +14 -5
  124. package/dist/plugins/tenant/index.d.ts +3 -3
  125. package/dist/plugins/tenant/index.js +45 -21
  126. package/dist/plugins/timestamps/index.d.ts +1 -1
  127. package/dist/plugins/timestamps/index.js +4 -3
  128. package/dist/plugins/validation/index.d.ts +2 -2
  129. package/dist/plugins/validation/index.js +26 -6
  130. package/dist/{pool-B9qsLyFR.d.ts → pool-C9voM4Kw.d.ts} +24 -6
  131. package/dist/postgres/index.d.ts +5 -5
  132. package/dist/postgres/index.js +20 -10
  133. package/dist/{postgrest-DmBlevh-.d.ts → postgrest-CruYKAvV.d.ts} +1 -1
  134. package/dist/{problem-CGt1ADix.js → problem-BW1KhzSG.js} +2 -1
  135. package/dist/{problem-Z2RTQjZD.d.ts → problem-Blxe8S31.d.ts} +1 -1
  136. package/dist/query/index.d.ts +2 -2
  137. package/dist/query/index.js +3 -3
  138. package/dist/{query-BdKLTPlj.js → query-CCbo44lG.js} +18 -18
  139. package/dist/queue-BYUCjr59.d.ts +252 -0
  140. package/dist/react/index.d.ts +8 -7
  141. package/dist/react/index.js +4 -3
  142. package/dist/react/server.d.ts +16 -5
  143. package/dist/react/server.js +12 -4
  144. package/dist/react/session.d.ts +10 -4
  145. package/dist/react/session.js +11 -3
  146. package/dist/{react-DNBYNazu.js → react-C_s7kiNz.js} +138 -46
  147. package/dist/{read-set-D0qBcboM.js → read-set-DQFt1N_Y.js} +71 -15
  148. package/dist/realtime/index.d.ts +3 -3
  149. package/dist/realtime/index.js +14 -12
  150. package/dist/{index-kpgopLNv.d.ts → refresh-BTrQ_ZTp.d.ts} +6 -3
  151. package/dist/{resolve-BRciX2jK.d.ts → resolve-C15TJq77.d.ts} +22 -11
  152. package/dist/{resource-D30rp0GN.js → resource-CRxxwkQq.js} +24 -9
  153. package/dist/{resource-CwVgiI5q.d.ts → resource-D8iqWMr-.d.ts} +6 -6
  154. package/dist/respond-D2OQl62-.d.ts +371 -0
  155. package/dist/{result-DWXatkd6.js → result-BKiliPY7.js} +2 -2
  156. package/dist/server/index.d.ts +17 -15
  157. package/dist/server/index.js +16 -22
  158. package/dist/server-Csx2sRjg.js +655 -0
  159. package/dist/{shared-_6-uPL7E.js → shared-D1dRUrAg.js} +19 -4
  160. package/dist/signers-Cc6r98SW.d.ts +162 -0
  161. package/dist/{simplify-LakqK1vH.js → simplify-_0oUKqCd.js} +27 -95
  162. package/dist/sql/index.d.ts +247 -10
  163. package/dist/sql/index.js +8591 -780
  164. package/dist/{sql-BIgk12ew.js → sql-Coh6n4cC.js} +11 -3
  165. package/dist/ssr/index.d.ts +4 -4
  166. package/dist/ssr/index.js +1 -2
  167. package/dist/{standard-FUi3Z3-7.js → standard-D7r6dMUu.js} +6 -3
  168. package/dist/{standard-eudBiRk1.d.ts → standard-J4YgMOLm.d.ts} +1 -1
  169. package/dist/{stats-D78UQ8Yu.js → stats-Bqob3WqT.js} +34 -9
  170. package/dist/storage/index.d.ts +4 -4
  171. package/dist/storage/index.js +174 -27
  172. package/dist/support-DT-OhSxD.d.ts +88 -0
  173. package/dist/support-Dk6vdmEw.js +291 -0
  174. package/dist/support-view-Da5peKFg.d.ts +17 -0
  175. package/dist/support-view-g4YLBeqX.js +18 -0
  176. package/dist/{tables-Dhha3BXM.js → tables-Cb-3_VWc.js} +14 -0
  177. package/dist/{permdock-sql-Bta_G0v-.js → template-TxrGI5jR.js} +2 -31
  178. package/dist/{temporal-BwshQk0W.js → temporal-CVlIV2DZ.js} +17 -4
  179. package/dist/{temporal-required-CMxeSVPo.js → temporal-required-CAt4Dc9Z.js} +2 -2
  180. package/dist/testing/index.d.ts +113 -24
  181. package/dist/testing/index.js +375 -47
  182. package/dist/{types-DONv9SHN.d.ts → types-Dnf_wRDz.d.ts} +26 -3
  183. package/dist/user-change-CHFEUro1.js +49 -0
  184. package/dist/{webhooks-CAIFQSTM.js → verify-Ce49ETPz.js} +38 -19
  185. package/dist/{version-BfpG2gks.js → version-DM_Roffb.js} +1 -1
  186. package/dist/{view-3Po_PVlr.d.ts → view-BEf0diC5.d.ts} +10 -5
  187. package/dist/{mfa-BxoR1RkN.js → view-Bq64ki8-.js} +210 -64
  188. package/dist/webhooks/index.d.ts +136 -5
  189. package/dist/webhooks/index.js +588 -2
  190. package/dist/wire-D2dT86vi.js +35 -0
  191. package/package.json +50 -10
  192. package/schemas/config-v1.json +131 -1
  193. package/schemas/doctor-report-v1.json +10 -0
  194. package/skills/better-supabase/SKILL.md +60 -10
  195. package/skills/better-supabase/references/plugins.md +13 -14
  196. package/skills/better-supabase/references/troubleshooting.md +25 -4
  197. package/skills/better-supabase-api/SKILL.md +74 -19
  198. package/skills/better-supabase-api/references/adapters.md +48 -27
  199. package/skills/better-supabase-auth/SKILL.md +149 -0
  200. package/skills/better-supabase-auth/references/permdock.md +100 -0
  201. package/skills/better-supabase-testing/SKILL.md +58 -4
  202. package/dist/claims-CoTobNC-.js +0 -25
  203. package/dist/events-Do8jXh4D.d.ts +0 -84
  204. package/dist/executor-DynmIWhq.d.ts +0 -195
  205. package/dist/invalidate-DbxuL2jL.js +0 -18
  206. package/dist/permdock-sql-DImJULY-.d.ts +0 -17
  207. package/dist/plugin-BqR6wKMB.js +0 -23
  208. package/dist/respond-C44EZAJo.js +0 -399
  209. package/dist/respond-DAkPIdTH.d.ts +0 -175
  210. package/dist/result-c2OYgCV2.d.ts +0 -203
  211. package/dist/view-wZ-9qIUz.js +0 -45
@@ -0,0 +1,752 @@
1
+ import { i as plain } from "./style-C0NFdJRL.js";
2
+ //#region ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/base.js
3
+ var Diff = class {
4
+ diff(oldStr, newStr, options = {}) {
5
+ let callback;
6
+ if (typeof options === "function") {
7
+ callback = options;
8
+ options = {};
9
+ } else if ("callback" in options) callback = options.callback;
10
+ const oldString = this.castInput(oldStr, options);
11
+ const newString = this.castInput(newStr, options);
12
+ const oldTokens = this.removeEmpty(this.tokenize(oldString, options));
13
+ const newTokens = this.removeEmpty(this.tokenize(newString, options));
14
+ return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
15
+ }
16
+ diffWithOptionsObj(oldTokens, newTokens, options, callback) {
17
+ var _a;
18
+ const done = (value) => {
19
+ value = this.postProcess(value, options);
20
+ if (callback) {
21
+ setTimeout(function() {
22
+ callback(value);
23
+ }, 0);
24
+ return;
25
+ } else return value;
26
+ };
27
+ const newLen = newTokens.length, oldLen = oldTokens.length;
28
+ let editLength = 1;
29
+ let maxEditLength = newLen + oldLen;
30
+ if (options.maxEditLength != null) maxEditLength = Math.min(maxEditLength, options.maxEditLength);
31
+ const maxExecutionTime = (_a = options.timeout) !== null && _a !== void 0 ? _a : Infinity;
32
+ const abortAfterTimestamp = Date.now() + maxExecutionTime;
33
+ const bestPath = [{
34
+ oldPos: -1,
35
+ lastComponent: void 0
36
+ }];
37
+ let newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
38
+ if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
39
+ let minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
40
+ const execEditLength = () => {
41
+ for (let diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
42
+ let basePath;
43
+ const removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
44
+ if (removePath) bestPath[diagonalPath - 1] = void 0;
45
+ let canAdd = false;
46
+ if (addPath) {
47
+ const addPathNewPos = addPath.oldPos - diagonalPath;
48
+ canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
49
+ }
50
+ const canRemove = removePath && removePath.oldPos + 1 < oldLen;
51
+ if (!canAdd && !canRemove) {
52
+ bestPath[diagonalPath] = void 0;
53
+ continue;
54
+ }
55
+ if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) basePath = this.addToPath(addPath, true, false, 0, options);
56
+ else basePath = this.addToPath(removePath, false, true, 1, options);
57
+ newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
58
+ if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
59
+ else {
60
+ bestPath[diagonalPath] = basePath;
61
+ if (basePath.oldPos + 1 >= oldLen) maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
62
+ if (newPos + 1 >= newLen) minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
63
+ }
64
+ }
65
+ editLength++;
66
+ };
67
+ if (callback) (function exec() {
68
+ setTimeout(function() {
69
+ if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) return callback(void 0);
70
+ if (!execEditLength()) exec();
71
+ }, 0);
72
+ })();
73
+ else while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
74
+ const ret = execEditLength();
75
+ if (ret) return ret;
76
+ }
77
+ }
78
+ addToPath(path, added, removed, oldPosInc, options) {
79
+ const last = path.lastComponent;
80
+ if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) return {
81
+ oldPos: path.oldPos + oldPosInc,
82
+ lastComponent: {
83
+ count: last.count + 1,
84
+ added,
85
+ removed,
86
+ previousComponent: last.previousComponent
87
+ }
88
+ };
89
+ else return {
90
+ oldPos: path.oldPos + oldPosInc,
91
+ lastComponent: {
92
+ count: 1,
93
+ added,
94
+ removed,
95
+ previousComponent: last
96
+ }
97
+ };
98
+ }
99
+ extractCommon(basePath, newTokens, oldTokens, diagonalPath, options) {
100
+ const newLen = newTokens.length, oldLen = oldTokens.length;
101
+ let oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
102
+ while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
103
+ newPos++;
104
+ oldPos++;
105
+ commonCount++;
106
+ if (options.oneChangePerToken) basePath.lastComponent = {
107
+ count: 1,
108
+ previousComponent: basePath.lastComponent,
109
+ added: false,
110
+ removed: false
111
+ };
112
+ }
113
+ if (commonCount && !options.oneChangePerToken) basePath.lastComponent = {
114
+ count: commonCount,
115
+ previousComponent: basePath.lastComponent,
116
+ added: false,
117
+ removed: false
118
+ };
119
+ basePath.oldPos = oldPos;
120
+ return newPos;
121
+ }
122
+ equals(left, right, options) {
123
+ if (options.comparator) return options.comparator(left, right);
124
+ else return left === right || !!options.ignoreCase && left.toLowerCase() === right.toLowerCase();
125
+ }
126
+ removeEmpty(array) {
127
+ const ret = [];
128
+ for (let i = 0; i < array.length; i++) if (array[i]) ret.push(array[i]);
129
+ return ret;
130
+ }
131
+ castInput(value, options) {
132
+ return value;
133
+ }
134
+ tokenize(value, options) {
135
+ return Array.from(value);
136
+ }
137
+ join(chars) {
138
+ return chars.join("");
139
+ }
140
+ postProcess(changeObjects, options) {
141
+ return changeObjects;
142
+ }
143
+ get useLongestToken() {
144
+ return false;
145
+ }
146
+ buildValues(lastComponent, newTokens, oldTokens) {
147
+ const components = [];
148
+ let nextComponent;
149
+ while (lastComponent) {
150
+ components.push(lastComponent);
151
+ nextComponent = lastComponent.previousComponent;
152
+ delete lastComponent.previousComponent;
153
+ lastComponent = nextComponent;
154
+ }
155
+ components.reverse();
156
+ const componentLen = components.length;
157
+ let componentPos = 0, newPos = 0, oldPos = 0;
158
+ for (; componentPos < componentLen; componentPos++) {
159
+ const component = components[componentPos];
160
+ if (!component.removed) {
161
+ if (!component.added && this.useLongestToken) {
162
+ let value = newTokens.slice(newPos, newPos + component.count);
163
+ value = value.map(function(value, i) {
164
+ const oldValue = oldTokens[oldPos + i];
165
+ return oldValue.length > value.length ? oldValue : value;
166
+ });
167
+ component.value = this.join(value);
168
+ } else component.value = this.join(newTokens.slice(newPos, newPos + component.count));
169
+ newPos += component.count;
170
+ if (!component.added) oldPos += component.count;
171
+ } else {
172
+ component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
173
+ oldPos += component.count;
174
+ }
175
+ }
176
+ return components;
177
+ }
178
+ };
179
+ //#endregion
180
+ //#region ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/character.js
181
+ var CharacterDiff = class extends Diff {};
182
+ new CharacterDiff();
183
+ //#endregion
184
+ //#region ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/util/string.js
185
+ function longestCommonPrefix(str1, str2) {
186
+ let i = 0;
187
+ for (; i < str1.length && i < str2.length; i++) if (str1[i] != str2[i]) return str1.slice(0, i);
188
+ return str1.slice(0, i);
189
+ }
190
+ function longestCommonSuffix(str1, str2) {
191
+ let i;
192
+ if (!str1 || !str2 || str1[str1.length - 1] != str2[str2.length - 1]) return "";
193
+ for (i = 0; i < str1.length && i < str2.length; i++) if (str1[str1.length - (i + 1)] != str2[str2.length - (i + 1)]) return str1.slice(-i);
194
+ return str1.slice(-i);
195
+ }
196
+ function replacePrefix(string, oldPrefix, newPrefix) {
197
+ if (string.slice(0, oldPrefix.length) != oldPrefix) throw Error(`string ${JSON.stringify(string)} doesn't start with prefix ${JSON.stringify(oldPrefix)}; this is a bug`);
198
+ return newPrefix + string.slice(oldPrefix.length);
199
+ }
200
+ function replaceSuffix(string, oldSuffix, newSuffix) {
201
+ if (!oldSuffix) return string + newSuffix;
202
+ if (string.slice(-oldSuffix.length) != oldSuffix) throw Error(`string ${JSON.stringify(string)} doesn't end with suffix ${JSON.stringify(oldSuffix)}; this is a bug`);
203
+ return string.slice(0, -oldSuffix.length) + newSuffix;
204
+ }
205
+ function removePrefix(string, oldPrefix) {
206
+ return replacePrefix(string, oldPrefix, "");
207
+ }
208
+ function removeSuffix(string, oldSuffix) {
209
+ return replaceSuffix(string, oldSuffix, "");
210
+ }
211
+ function maximumOverlap(string1, string2) {
212
+ return string2.slice(0, overlapCount(string1, string2));
213
+ }
214
+ function overlapCount(a, b) {
215
+ let startA = 0;
216
+ if (a.length > b.length) startA = a.length - b.length;
217
+ let endB = b.length;
218
+ if (a.length < b.length) endB = a.length;
219
+ const map = Array(endB);
220
+ let k = 0;
221
+ map[0] = 0;
222
+ for (let j = 1; j < endB; j++) {
223
+ if (b[j] == b[k]) map[j] = map[k];
224
+ else map[j] = k;
225
+ while (k > 0 && b[j] != b[k]) k = map[k];
226
+ if (b[j] == b[k]) k++;
227
+ }
228
+ k = 0;
229
+ for (let i = startA; i < a.length; i++) {
230
+ while (k > 0 && a[i] != b[k]) k = map[k];
231
+ if (a[i] == b[k]) k++;
232
+ }
233
+ return k;
234
+ }
235
+ /**
236
+ * Split a string into segments using a word segmenter, merging consecutive
237
+ * segments if they are both whitespace segments. Whitespace segments can
238
+ * appear adjacent to one another for two reasons:
239
+ * - newlines always get their own segment
240
+ * - where a diacritic is attached to a whitespace character in the text, the
241
+ * segment ends after the diacritic, so e.g. " \u0300 " becomes two segments.
242
+ * This function therefore runs the segmenter's .segment() method and then
243
+ * merges consecutive segments of whitespace into a single part.
244
+ */
245
+ function segment(string, segmenter) {
246
+ const parts = [];
247
+ for (const segmentObj of Array.from(segmenter.segment(string))) {
248
+ const segment = segmentObj.segment;
249
+ if (parts.length && /\s/.test(parts[parts.length - 1]) && /\s/.test(segment)) parts[parts.length - 1] += segment;
250
+ else parts.push(segment);
251
+ }
252
+ return parts;
253
+ }
254
+ function trailingWs(string, segmenter) {
255
+ if (segmenter) return leadingAndTrailingWs(string, segmenter)[1];
256
+ let i;
257
+ for (i = string.length - 1; i >= 0; i--) if (!string[i].match(/\s/)) break;
258
+ return string.substring(i + 1);
259
+ }
260
+ function leadingWs(string, segmenter) {
261
+ if (segmenter) return leadingAndTrailingWs(string, segmenter)[0];
262
+ const match = string.match(/^\s*/);
263
+ return match ? match[0] : "";
264
+ }
265
+ function leadingAndTrailingWs(string, segmenter) {
266
+ if (!segmenter) return [leadingWs(string), trailingWs(string)];
267
+ if (segmenter.resolvedOptions().granularity != "word") throw new Error("The segmenter passed must have a granularity of \"word\"");
268
+ const segments = segment(string, segmenter);
269
+ const firstSeg = segments[0];
270
+ const lastSeg = segments[segments.length - 1];
271
+ return [/\s/.test(firstSeg) ? firstSeg : "", /\s/.test(lastSeg) ? lastSeg : ""];
272
+ }
273
+ //#endregion
274
+ //#region ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/word.js
275
+ const extendedWordChars = "a-zA-Z0-9_\\u{AD}\\u{C0}-\\u{D6}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}";
276
+ const tokenizeIncludingWhitespace = new RegExp(`[${extendedWordChars}]+|\\s+|[^${extendedWordChars}]`, "ug");
277
+ var WordDiff = class extends Diff {
278
+ equals(left, right, options) {
279
+ if (options.ignoreCase) {
280
+ left = left.toLowerCase();
281
+ right = right.toLowerCase();
282
+ }
283
+ return left.trim() === right.trim();
284
+ }
285
+ tokenize(value, options = {}) {
286
+ let parts;
287
+ if (options.intlSegmenter) {
288
+ const segmenter = options.intlSegmenter;
289
+ if (segmenter.resolvedOptions().granularity != "word") throw new Error("The segmenter passed must have a granularity of \"word\"");
290
+ parts = segment(value, segmenter);
291
+ } else parts = value.match(tokenizeIncludingWhitespace) || [];
292
+ const tokens = [];
293
+ let prevPart = null;
294
+ parts.forEach((part) => {
295
+ if (/\s/.test(part)) {
296
+ if (prevPart == null) tokens.push(part);
297
+ else tokens.push(tokens.pop() + part);
298
+ } else if (prevPart != null && /\s/.test(prevPart)) {
299
+ if (tokens[tokens.length - 1] == prevPart) tokens.push(tokens.pop() + part);
300
+ else tokens.push(prevPart + part);
301
+ } else tokens.push(part);
302
+ prevPart = part;
303
+ });
304
+ return tokens;
305
+ }
306
+ join(tokens) {
307
+ return tokens.map((token, i) => {
308
+ if (i == 0) return token;
309
+ else return token.replace(/^\s+/, "");
310
+ }).join("");
311
+ }
312
+ postProcess(changes, options) {
313
+ if (!changes || options.oneChangePerToken) return changes;
314
+ let lastKeep = null;
315
+ let insertion = null;
316
+ let deletion = null;
317
+ changes.forEach((change) => {
318
+ if (change.added) insertion = change;
319
+ else if (change.removed) deletion = change;
320
+ else {
321
+ if (insertion || deletion) dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, change, options.intlSegmenter);
322
+ lastKeep = change;
323
+ insertion = null;
324
+ deletion = null;
325
+ }
326
+ });
327
+ if (insertion || deletion) dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, null, options.intlSegmenter);
328
+ return changes;
329
+ }
330
+ };
331
+ new WordDiff();
332
+ function dedupeWhitespaceInChangeObjects(startKeep, deletion, insertion, endKeep, segmenter) {
333
+ if (deletion && insertion) {
334
+ const [oldWsPrefix, oldWsSuffix] = leadingAndTrailingWs(deletion.value, segmenter);
335
+ const [newWsPrefix, newWsSuffix] = leadingAndTrailingWs(insertion.value, segmenter);
336
+ if (startKeep) {
337
+ const commonWsPrefix = longestCommonPrefix(oldWsPrefix, newWsPrefix);
338
+ startKeep.value = replaceSuffix(startKeep.value, newWsPrefix, commonWsPrefix);
339
+ deletion.value = removePrefix(deletion.value, commonWsPrefix);
340
+ insertion.value = removePrefix(insertion.value, commonWsPrefix);
341
+ }
342
+ if (endKeep) {
343
+ const commonWsSuffix = longestCommonSuffix(oldWsSuffix, newWsSuffix);
344
+ endKeep.value = replacePrefix(endKeep.value, newWsSuffix, commonWsSuffix);
345
+ deletion.value = removeSuffix(deletion.value, commonWsSuffix);
346
+ insertion.value = removeSuffix(insertion.value, commonWsSuffix);
347
+ }
348
+ } else if (insertion) {
349
+ if (startKeep) {
350
+ const ws = leadingWs(insertion.value, segmenter);
351
+ insertion.value = insertion.value.substring(ws.length);
352
+ }
353
+ if (endKeep) {
354
+ const ws = leadingWs(endKeep.value, segmenter);
355
+ endKeep.value = endKeep.value.substring(ws.length);
356
+ }
357
+ } else if (startKeep && endKeep) {
358
+ const newWsFull = leadingWs(endKeep.value, segmenter), [delWsStart, delWsEnd] = leadingAndTrailingWs(deletion.value, segmenter);
359
+ const newWsStart = longestCommonPrefix(newWsFull, delWsStart);
360
+ deletion.value = removePrefix(deletion.value, newWsStart);
361
+ const newWsEnd = longestCommonSuffix(removePrefix(newWsFull, newWsStart), delWsEnd);
362
+ deletion.value = removeSuffix(deletion.value, newWsEnd);
363
+ endKeep.value = replacePrefix(endKeep.value, newWsFull, newWsEnd);
364
+ startKeep.value = replaceSuffix(startKeep.value, newWsFull, newWsFull.slice(0, newWsFull.length - newWsEnd.length));
365
+ } else if (endKeep) {
366
+ const endKeepWsPrefix = leadingWs(endKeep.value, segmenter);
367
+ const overlap = maximumOverlap(trailingWs(deletion.value, segmenter), endKeepWsPrefix);
368
+ deletion.value = removeSuffix(deletion.value, overlap);
369
+ } else if (startKeep) {
370
+ const overlap = maximumOverlap(trailingWs(startKeep.value, segmenter), leadingWs(deletion.value, segmenter));
371
+ deletion.value = removePrefix(deletion.value, overlap);
372
+ }
373
+ }
374
+ var WordsWithSpaceDiff = class extends Diff {
375
+ tokenize(value) {
376
+ const regex = new RegExp(`(\\r?\\n)|[${extendedWordChars}]+|[^\\S\\n\\r]+|[^${extendedWordChars}]`, "ug");
377
+ return value.match(regex) || [];
378
+ }
379
+ };
380
+ new WordsWithSpaceDiff();
381
+ //#endregion
382
+ //#region ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/line.js
383
+ var LineDiff = class extends Diff {
384
+ constructor() {
385
+ super(...arguments);
386
+ this.tokenize = tokenize;
387
+ }
388
+ equals(left, right, options) {
389
+ if (options.ignoreWhitespace) {
390
+ if (!options.newlineIsToken || !left.includes("\n")) left = left.trim();
391
+ if (!options.newlineIsToken || !right.includes("\n")) right = right.trim();
392
+ } else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
393
+ if (left.endsWith("\n")) left = left.slice(0, -1);
394
+ if (right.endsWith("\n")) right = right.slice(0, -1);
395
+ }
396
+ return super.equals(left, right, options);
397
+ }
398
+ };
399
+ const lineDiff = new LineDiff();
400
+ function diffLines(oldStr, newStr, options) {
401
+ return lineDiff.diff(oldStr, newStr, options);
402
+ }
403
+ function tokenize(value, options) {
404
+ if (options.stripTrailingCr) value = value.replace(/\r\n/g, "\n");
405
+ const retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
406
+ if (!linesAndNewlines[linesAndNewlines.length - 1]) linesAndNewlines.pop();
407
+ for (let i = 0; i < linesAndNewlines.length; i++) {
408
+ const line = linesAndNewlines[i];
409
+ if (i % 2 && !options.newlineIsToken) retLines[retLines.length - 1] += line;
410
+ else retLines.push(line);
411
+ }
412
+ return retLines;
413
+ }
414
+ //#endregion
415
+ //#region ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/sentence.js
416
+ function isSentenceEndPunct(char) {
417
+ return char == "." || char == "!" || char == "?";
418
+ }
419
+ var SentenceDiff = class extends Diff {
420
+ tokenize(value) {
421
+ var _a;
422
+ const result = [];
423
+ let tokenStartI = 0;
424
+ for (let i = 0; i < value.length; i++) {
425
+ if (i == value.length - 1) {
426
+ result.push(value.slice(tokenStartI));
427
+ break;
428
+ }
429
+ if (isSentenceEndPunct(value[i]) && value[i + 1].match(/\s/)) {
430
+ result.push(value.slice(tokenStartI, i + 1));
431
+ i = tokenStartI = i + 1;
432
+ while ((_a = value[i + 1]) === null || _a === void 0 ? void 0 : _a.match(/\s/)) i++;
433
+ result.push(value.slice(tokenStartI, i + 1));
434
+ tokenStartI = i + 1;
435
+ }
436
+ }
437
+ return result;
438
+ }
439
+ };
440
+ new SentenceDiff();
441
+ //#endregion
442
+ //#region ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/css.js
443
+ var CssDiff = class extends Diff {
444
+ tokenize(value) {
445
+ return value.split(/([{}:;,]|\s+)/);
446
+ }
447
+ };
448
+ new CssDiff();
449
+ //#endregion
450
+ //#region ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/json.js
451
+ var JsonDiff = class extends Diff {
452
+ constructor() {
453
+ super(...arguments);
454
+ this.tokenize = tokenize;
455
+ }
456
+ get useLongestToken() {
457
+ return true;
458
+ }
459
+ castInput(value, options) {
460
+ const { undefinedReplacement, stringifyReplacer = (k, v) => typeof v === "undefined" ? undefinedReplacement : v } = options;
461
+ return typeof value === "string" ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), null, " ");
462
+ }
463
+ equals(left, right, options) {
464
+ return super.equals(left.replace(/,([\r\n])/g, "$1"), right.replace(/,([\r\n])/g, "$1"), options);
465
+ }
466
+ };
467
+ new JsonDiff();
468
+ function canonicalize(obj, stack, replacementStack, replacer, key) {
469
+ stack = stack || [];
470
+ replacementStack = replacementStack || [];
471
+ if (replacer) obj = replacer(key === void 0 ? "" : key, obj);
472
+ let i = 0;
473
+ for (; i < stack.length; i += 1) if (stack[i] === obj) return replacementStack[i];
474
+ let canonicalizedObj;
475
+ if ("[object Array]" === Object.prototype.toString.call(obj)) {
476
+ stack.push(obj);
477
+ canonicalizedObj = new Array(obj.length);
478
+ replacementStack.push(canonicalizedObj);
479
+ for (i = 0; i < obj.length; i += 1) canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, String(i));
480
+ stack.pop();
481
+ replacementStack.pop();
482
+ return canonicalizedObj;
483
+ }
484
+ if (obj && obj.toJSON) obj = obj.toJSON();
485
+ if (typeof obj === "object" && obj !== null) {
486
+ stack.push(obj);
487
+ canonicalizedObj = {};
488
+ replacementStack.push(canonicalizedObj);
489
+ const sortedKeys = [];
490
+ let key;
491
+ for (key in obj)
492
+ /* istanbul ignore else */
493
+ if (Object.prototype.hasOwnProperty.call(obj, key)) sortedKeys.push(key);
494
+ sortedKeys.sort();
495
+ for (i = 0; i < sortedKeys.length; i += 1) {
496
+ key = sortedKeys[i];
497
+ canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack, replacer, key);
498
+ }
499
+ stack.pop();
500
+ replacementStack.pop();
501
+ } else canonicalizedObj = obj;
502
+ return canonicalizedObj;
503
+ }
504
+ //#endregion
505
+ //#region ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/array.js
506
+ var ArrayDiff = class extends Diff {
507
+ tokenize(value) {
508
+ return value.slice();
509
+ }
510
+ join(value) {
511
+ return value;
512
+ }
513
+ removeEmpty(value) {
514
+ return value;
515
+ }
516
+ };
517
+ new ArrayDiff();
518
+ //#endregion
519
+ //#region ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/patch/create.js
520
+ /**
521
+ * Returns true if the filename contains characters that require C-style
522
+ * quoting (as used by Git and GNU diffutils in diff output).
523
+ */
524
+ function needsQuoting(s) {
525
+ for (let i = 0; i < s.length; i++) if (s[i] < " " || s[i] > "~" || s[i] === "\"" || s[i] === "\\") return true;
526
+ return false;
527
+ }
528
+ /**
529
+ * C-style quotes a filename, encoding special characters as escape sequences
530
+ * and non-ASCII bytes as octal escapes. This is the inverse of
531
+ * `parseQuotedFileName` in parse.ts.
532
+ *
533
+ * Non-ASCII bytes are encoded as UTF-8 before being emitted as octal escapes.
534
+ * This matches the behaviour of both Git and GNU diffutils, which always emit
535
+ * UTF-8 octal escapes regardless of the underlying filesystem encoding (e.g.
536
+ * Git for Windows converts from NTFS's UTF-16 to UTF-8 internally).
537
+ *
538
+ * If the filename doesn't need quoting, returns it as-is.
539
+ */
540
+ function quoteFileNameIfNeeded(s) {
541
+ if (!needsQuoting(s)) return s;
542
+ let result = "\"";
543
+ const bytes = new TextEncoder().encode(s);
544
+ let i = 0;
545
+ while (i < bytes.length) {
546
+ const b = bytes[i];
547
+ if (b === 7) result += "\\a";
548
+ else if (b === 8) result += "\\b";
549
+ else if (b === 9) result += "\\t";
550
+ else if (b === 10) result += "\\n";
551
+ else if (b === 11) result += "\\v";
552
+ else if (b === 12) result += "\\f";
553
+ else if (b === 13) result += "\\r";
554
+ else if (b === 34) result += "\\\"";
555
+ else if (b === 92) result += "\\\\";
556
+ else if (b >= 32 && b <= 126) result += String.fromCharCode(b);
557
+ else result += "\\" + b.toString(8).padStart(3, "0");
558
+ i++;
559
+ }
560
+ result += "\"";
561
+ return result;
562
+ }
563
+ const INCLUDE_HEADERS = {
564
+ includeIndex: true,
565
+ includeUnderline: true,
566
+ includeFileHeaders: true
567
+ };
568
+ function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
569
+ let optionsObj;
570
+ if (!options) optionsObj = {};
571
+ else if (typeof options === "function") optionsObj = { callback: options };
572
+ else optionsObj = options;
573
+ if (typeof optionsObj.context === "undefined") optionsObj.context = 4;
574
+ const context = optionsObj.context;
575
+ if (optionsObj.newlineIsToken) throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");
576
+ if (!optionsObj.callback) return diffLinesResultToPatch(diffLines(oldStr, newStr, optionsObj));
577
+ else {
578
+ const { callback } = optionsObj;
579
+ diffLines(oldStr, newStr, Object.assign(Object.assign({}, optionsObj), { callback: (diff) => {
580
+ const patch = diffLinesResultToPatch(diff);
581
+ callback(patch);
582
+ } }));
583
+ }
584
+ function diffLinesResultToPatch(diff) {
585
+ if (!diff) return;
586
+ diff.push({
587
+ value: "",
588
+ lines: []
589
+ });
590
+ function contextLines(lines) {
591
+ return lines.map(function(entry) {
592
+ return " " + entry;
593
+ });
594
+ }
595
+ const hunks = [];
596
+ let oldRangeStart = 0, newRangeStart = 0, curRange = [], oldLine = 1, newLine = 1;
597
+ for (let i = 0; i < diff.length; i++) {
598
+ const current = diff[i], lines = current.lines || splitLines(current.value);
599
+ current.lines = lines;
600
+ if (current.added || current.removed) {
601
+ if (!oldRangeStart) {
602
+ const prev = diff[i - 1];
603
+ oldRangeStart = oldLine;
604
+ newRangeStart = newLine;
605
+ if (prev) {
606
+ curRange = context > 0 ? contextLines(prev.lines.slice(-context)) : [];
607
+ oldRangeStart -= curRange.length;
608
+ newRangeStart -= curRange.length;
609
+ }
610
+ }
611
+ for (const line of lines) curRange.push((current.added ? "+" : "-") + line);
612
+ if (current.added) newLine += lines.length;
613
+ else oldLine += lines.length;
614
+ } else {
615
+ if (oldRangeStart) {
616
+ if (lines.length <= context * 2 && i < diff.length - 2) for (const line of contextLines(lines)) curRange.push(line);
617
+ else {
618
+ const contextSize = Math.min(lines.length, context);
619
+ for (const line of contextLines(lines.slice(0, contextSize))) curRange.push(line);
620
+ const hunk = {
621
+ oldStart: oldRangeStart,
622
+ oldLines: oldLine - oldRangeStart + contextSize,
623
+ newStart: newRangeStart,
624
+ newLines: newLine - newRangeStart + contextSize,
625
+ lines: curRange
626
+ };
627
+ hunks.push(hunk);
628
+ oldRangeStart = 0;
629
+ newRangeStart = 0;
630
+ curRange = [];
631
+ }
632
+ }
633
+ oldLine += lines.length;
634
+ newLine += lines.length;
635
+ }
636
+ }
637
+ for (const hunk of hunks) for (let i = 0; i < hunk.lines.length; i++) if (hunk.lines[i].endsWith("\n")) hunk.lines[i] = hunk.lines[i].slice(0, -1);
638
+ else {
639
+ hunk.lines.splice(i + 1, 0, "\");
640
+ i++;
641
+ }
642
+ return {
643
+ oldFileName,
644
+ newFileName,
645
+ oldHeader,
646
+ newHeader,
647
+ hunks
648
+ };
649
+ }
650
+ }
651
+ /**
652
+ * creates a unified diff patch.
653
+ *
654
+ * @param patch either a single structured patch object (as returned by `structuredPatch`) or an
655
+ * array of them (as returned by `parsePatch`).
656
+ * @param headerOptions behaves the same as the `headerOptions` option of `createTwoFilesPatch`.
657
+ * Ignored for patches where `isGit` is `true`.
658
+ *
659
+ * When a patch has `isGit: true`, `formatPatch` output is changed to more closely match Git's
660
+ * output: it emits a `diff --git` header, emits Git extended headers as appropriate based on
661
+ * properties like `isRename`, `isCreate`, `newMode`, etc, and will omit `---`/`+++` file
662
+ * headers for patches with no hunks (e.g. renames without content changes).
663
+ */
664
+ function formatPatch(patch, headerOptions) {
665
+ var _a, _b, _c, _d, _e, _f;
666
+ if (!headerOptions) headerOptions = INCLUDE_HEADERS;
667
+ if (Array.isArray(patch)) {
668
+ if (patch.length > 1 && !headerOptions.includeFileHeaders && !patch.every((p) => p.isGit)) throw new Error("Cannot omit file headers on a multi-file patch. (The result would be unparseable; how would a tool trying to apply the patch know which changes are to which file?)");
669
+ return patch.map((p) => formatPatch(p, headerOptions)).join("\n");
670
+ }
671
+ const ret = [];
672
+ if (patch.isGit) {
673
+ headerOptions = INCLUDE_HEADERS;
674
+ if (!patch.oldFileName) throw new Error("oldFileName must be specified for Git patches");
675
+ if (!patch.newFileName) throw new Error("newFileName must be specified for Git patches");
676
+ let gitOldName = patch.oldFileName;
677
+ let gitNewName = patch.newFileName;
678
+ if (patch.isCreate && gitOldName === "/dev/null") gitOldName = gitNewName.replace(/^b\//, "a/");
679
+ else if (patch.isDelete && gitNewName === "/dev/null") gitNewName = gitOldName.replace(/^a\//, "b/");
680
+ ret.push("diff --git " + quoteFileNameIfNeeded(gitOldName) + " " + quoteFileNameIfNeeded(gitNewName));
681
+ if (patch.isDelete) ret.push("deleted file mode " + ((_a = patch.oldMode) !== null && _a !== void 0 ? _a : "100644"));
682
+ if (patch.isCreate) ret.push("new file mode " + ((_b = patch.newMode) !== null && _b !== void 0 ? _b : "100644"));
683
+ if (patch.oldMode && patch.newMode && !patch.isDelete && !patch.isCreate) {
684
+ ret.push("old mode " + patch.oldMode);
685
+ ret.push("new mode " + patch.newMode);
686
+ }
687
+ if (patch.isRename) {
688
+ ret.push("rename from " + quoteFileNameIfNeeded(((_c = patch.oldFileName) !== null && _c !== void 0 ? _c : "").replace(/^a\//, "")));
689
+ ret.push("rename to " + quoteFileNameIfNeeded(((_d = patch.newFileName) !== null && _d !== void 0 ? _d : "").replace(/^b\//, "")));
690
+ }
691
+ if (patch.isCopy) {
692
+ ret.push("copy from " + quoteFileNameIfNeeded(((_e = patch.oldFileName) !== null && _e !== void 0 ? _e : "").replace(/^a\//, "")));
693
+ ret.push("copy to " + quoteFileNameIfNeeded(((_f = patch.newFileName) !== null && _f !== void 0 ? _f : "").replace(/^b\//, "")));
694
+ }
695
+ } else {
696
+ if (headerOptions.includeIndex && patch.oldFileName == patch.newFileName && patch.oldFileName !== void 0) ret.push("Index: " + patch.oldFileName);
697
+ if (headerOptions.includeUnderline) ret.push("===================================================================");
698
+ }
699
+ const hasHunks = patch.hunks.length > 0;
700
+ if (headerOptions.includeFileHeaders && patch.oldFileName !== void 0 && patch.newFileName !== void 0 && (!patch.isGit || hasHunks)) {
701
+ ret.push("--- " + quoteFileNameIfNeeded(patch.oldFileName) + (patch.oldHeader ? " " + patch.oldHeader : ""));
702
+ ret.push("+++ " + quoteFileNameIfNeeded(patch.newFileName) + (patch.newHeader ? " " + patch.newHeader : ""));
703
+ }
704
+ for (let i = 0; i < patch.hunks.length; i++) {
705
+ const hunk = patch.hunks[i];
706
+ const oldStart = hunk.oldLines === 0 ? hunk.oldStart - 1 : hunk.oldStart;
707
+ const newStart = hunk.newLines === 0 ? hunk.newStart - 1 : hunk.newStart;
708
+ ret.push("@@ -" + oldStart + "," + hunk.oldLines + " +" + newStart + "," + hunk.newLines + " @@");
709
+ for (const line of hunk.lines) ret.push(line);
710
+ }
711
+ return ret.join("\n") + "\n";
712
+ }
713
+ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
714
+ if (typeof options === "function") options = { callback: options };
715
+ if (!(options === null || options === void 0 ? void 0 : options.callback)) {
716
+ const patchObj = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
717
+ if (!patchObj) return;
718
+ return formatPatch(patchObj, options === null || options === void 0 ? void 0 : options.headerOptions);
719
+ } else {
720
+ const { callback } = options;
721
+ structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, Object.assign(Object.assign({}, options), { callback: (patchObj) => {
722
+ if (!patchObj) callback(void 0);
723
+ else callback(formatPatch(patchObj, options.headerOptions));
724
+ } }));
725
+ }
726
+ }
727
+ /**
728
+ * Split `text` into an array of lines, including the trailing newline character (where present)
729
+ */
730
+ function splitLines(text) {
731
+ const hasTrailingNl = text.endsWith("\n");
732
+ const result = text.split("\n").map((line) => line + "\n");
733
+ if (hasTrailingNl) result.pop();
734
+ else result.push(result.pop().slice(0, -1));
735
+ return result;
736
+ }
737
+ function paintLine(line, paint) {
738
+ if (line.startsWith("---") || line.startsWith("+++")) return paint("bold", line);
739
+ if (line.startsWith("@@")) return paint("cyan", line);
740
+ if (line.startsWith("+")) return paint("green", line);
741
+ if (line.startsWith("-")) return paint("red", line);
742
+ return line;
743
+ }
744
+ /** A unified diff from the file on disk (`current`, missing when `undefined`) to `next`, capped at `DIFF_LINES`. */
745
+ function fileDiff(path, current, next, paint = plain) {
746
+ const lines = createTwoFilesPatch(path, path, current ?? "", next, current === void 0 ? "missing" : "on disk", "generated", { context: 2 }).split("\n").filter((line) => line !== "" && !line.startsWith("=====") && !line.startsWith("Index:"));
747
+ const shown = lines.slice(0, 40).map((line) => paintLine(line, paint));
748
+ const hidden = lines.length - shown.length;
749
+ return [...shown, ...hidden > 0 ? [paint("dim", `... ${hidden} more diff lines`)] : []].join("\n");
750
+ }
751
+ //#endregion
752
+ export { fileDiff as t };