@fangorn-network/sdk 2026.9.22-dev → 2026.10.19-dev

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 (89) hide show
  1. package/README.md +177 -192
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +165 -194
  4. package/lib/config.d.ts +32 -27
  5. package/lib/config.js +17 -7
  6. package/lib/contracts/app-registry/abi.d.ts +1033 -277
  7. package/lib/contracts/app-registry/abi.js +1214 -335
  8. package/lib/contracts/app-registry/index.d.ts +105 -65
  9. package/lib/contracts/app-registry/index.js +182 -175
  10. package/lib/contracts/data-registry/abi.d.ts +166 -187
  11. package/lib/contracts/data-registry/abi.js +207 -237
  12. package/lib/contracts/data-registry/index.d.ts +4 -151
  13. package/lib/contracts/data-registry/index.js +5 -279
  14. package/lib/contracts/index.d.ts +6 -7
  15. package/lib/contracts/index.js +6 -8
  16. package/lib/contracts/logs.d.ts +4 -1
  17. package/lib/contracts/logs.js +9 -2
  18. package/lib/contracts/membership-registry/abi.d.ts +1145 -0
  19. package/lib/contracts/membership-registry/abi.js +1333 -0
  20. package/lib/contracts/membership-registry/index.d.ts +79 -0
  21. package/lib/contracts/membership-registry/index.js +104 -0
  22. package/lib/contracts/types.d.ts +3 -1
  23. package/lib/contracts/types.js +3 -1
  24. package/lib/contracts/write.d.ts +34 -2
  25. package/lib/contracts/write.js +48 -1
  26. package/lib/crypto/encryption.js +4 -4
  27. package/lib/engine/car.d.ts +2 -2
  28. package/lib/engine/car.js +10 -5
  29. package/lib/engine/index.d.ts +99 -143
  30. package/lib/engine/index.js +156 -295
  31. package/lib/engine/records.d.ts +110 -0
  32. package/lib/engine/records.js +165 -0
  33. package/lib/engine/test-helpers.d.ts +7 -14
  34. package/lib/engine/test-helpers.js +7 -18
  35. package/lib/fangorn.d.ts +129 -156
  36. package/lib/fangorn.js +250 -250
  37. package/lib/feed.d.ts +7 -4
  38. package/lib/feed.js +4 -1
  39. package/lib/index.d.ts +9 -9
  40. package/lib/index.js +8 -9
  41. package/lib/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.js +77 -0
  42. package/lib/node_modules/@vitest/expect/dist/index.js +1414 -0
  43. package/lib/node_modules/@vitest/pretty-format/dist/index.js +858 -0
  44. package/lib/node_modules/@vitest/runner/dist/chunk-tasks.js +51 -0
  45. package/lib/node_modules/@vitest/runner/dist/index.js +1199 -0
  46. package/lib/node_modules/@vitest/runner/dist/utils.js +3 -0
  47. package/lib/node_modules/@vitest/snapshot/dist/index.js +1075 -0
  48. package/lib/node_modules/@vitest/spy/dist/index.js +353 -0
  49. package/lib/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js +7 -0
  50. package/lib/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.js +81 -0
  51. package/lib/node_modules/@vitest/utils/dist/diff.js +1345 -0
  52. package/lib/node_modules/@vitest/utils/dist/display.js +534 -0
  53. package/lib/node_modules/@vitest/utils/dist/error.js +30 -0
  54. package/lib/node_modules/@vitest/utils/dist/helpers.js +118 -0
  55. package/lib/node_modules/@vitest/utils/dist/serialize.js +76 -0
  56. package/lib/node_modules/@vitest/utils/dist/source-map.js +93 -0
  57. package/lib/node_modules/@vitest/utils/dist/timers.js +36 -0
  58. package/lib/node_modules/chai/index.js +2874 -0
  59. package/lib/node_modules/magic-string/dist/magic-string.es.js +939 -0
  60. package/lib/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +81 -0
  61. package/lib/node_modules/tinyrainbow/dist/index.js +85 -0
  62. package/lib/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js +5 -0
  63. package/lib/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js +50 -0
  64. package/lib/node_modules/vitest/dist/chunks/utils.DvEY5TfP.js +44 -0
  65. package/lib/node_modules/vitest/dist/chunks/vi.2VT5v0um.js +2578 -0
  66. package/lib/providers/storage/signed-url.d.ts +16 -6
  67. package/lib/providers/storage/signed-url.js +20 -8
  68. package/lib/registry.d.ts +116 -0
  69. package/lib/registry.js +182 -0
  70. package/lib/test/mem-registry.d.ts +51 -0
  71. package/lib/test/mem-registry.js +107 -0
  72. package/lib/test/sdk-suite.d.ts +13 -0
  73. package/lib/test/sdk-suite.js +226 -0
  74. package/lib/test/testbed.d.ts +16411 -61
  75. package/lib/test/testbed.js +190 -84
  76. package/lib/types/index.d.ts +13 -11
  77. package/package.json +89 -73
  78. package/lib/contracts/data-registry/test.d.ts +0 -1
  79. package/lib/contracts/data-registry/test.js +0 -1
  80. package/lib/contracts/settlement-registry/abi.d.ts +0 -466
  81. package/lib/contracts/settlement-registry/abi.js +0 -535
  82. package/lib/contracts/settlement-registry/index.d.ts +0 -163
  83. package/lib/contracts/settlement-registry/index.js +0 -264
  84. package/lib/contracts/subscription-registry/abi.d.ts +0 -179
  85. package/lib/contracts/subscription-registry/abi.js +0 -195
  86. package/lib/contracts/subscription-registry/index.d.ts +0 -59
  87. package/lib/contracts/subscription-registry/index.js +0 -116
  88. package/lib/engine/graph.d.ts +0 -70
  89. package/lib/engine/graph.js +0 -73
@@ -0,0 +1,1075 @@
1
+ import { format, plugins } from "../../pretty-format/dist/index.js";
2
+ import { resolve } from "../../../pathe/dist/shared/pathe.M-eThtNZ.js";
3
+
4
+ //#region node_modules/@vitest/snapshot/dist/index.js
5
+ var comma = ",".charCodeAt(0);
6
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
7
+ var intToChar = new Uint8Array(64);
8
+ var charToInt = new Uint8Array(128);
9
+ for (let i = 0; i < chars.length; i++) {
10
+ const c = chars.charCodeAt(i);
11
+ intToChar[i] = c;
12
+ charToInt[c] = i;
13
+ }
14
+ function decodeInteger(reader, relative) {
15
+ let value = 0;
16
+ let shift = 0;
17
+ let integer = 0;
18
+ do {
19
+ integer = charToInt[reader.next()];
20
+ value |= (integer & 31) << shift;
21
+ shift += 5;
22
+ } while (integer & 32);
23
+ const shouldNegate = value & 1;
24
+ value >>>= 1;
25
+ if (shouldNegate) value = -2147483648 | -value;
26
+ return relative + value;
27
+ }
28
+ function hasMoreVlq(reader, max) {
29
+ if (reader.pos >= max) return false;
30
+ return reader.peek() !== comma;
31
+ }
32
+ var StringReader = class {
33
+ constructor(buffer) {
34
+ this.pos = 0;
35
+ this.buffer = buffer;
36
+ }
37
+ next() {
38
+ return this.buffer.charCodeAt(this.pos++);
39
+ }
40
+ peek() {
41
+ return this.buffer.charCodeAt(this.pos);
42
+ }
43
+ indexOf(char) {
44
+ const { buffer, pos } = this;
45
+ const idx = buffer.indexOf(char, pos);
46
+ return idx === -1 ? buffer.length : idx;
47
+ }
48
+ };
49
+ function decode(mappings) {
50
+ const { length } = mappings;
51
+ const reader = new StringReader(mappings);
52
+ const decoded = [];
53
+ let genColumn = 0;
54
+ let sourcesIndex = 0;
55
+ let sourceLine = 0;
56
+ let sourceColumn = 0;
57
+ let namesIndex = 0;
58
+ do {
59
+ const semi = reader.indexOf(";");
60
+ const line = [];
61
+ let sorted = true;
62
+ let lastCol = 0;
63
+ genColumn = 0;
64
+ while (reader.pos < semi) {
65
+ let seg;
66
+ genColumn = decodeInteger(reader, genColumn);
67
+ if (genColumn < lastCol) sorted = false;
68
+ lastCol = genColumn;
69
+ if (hasMoreVlq(reader, semi)) {
70
+ sourcesIndex = decodeInteger(reader, sourcesIndex);
71
+ sourceLine = decodeInteger(reader, sourceLine);
72
+ sourceColumn = decodeInteger(reader, sourceColumn);
73
+ if (hasMoreVlq(reader, semi)) {
74
+ namesIndex = decodeInteger(reader, namesIndex);
75
+ seg = [
76
+ genColumn,
77
+ sourcesIndex,
78
+ sourceLine,
79
+ sourceColumn,
80
+ namesIndex
81
+ ];
82
+ } else seg = [
83
+ genColumn,
84
+ sourcesIndex,
85
+ sourceLine,
86
+ sourceColumn
87
+ ];
88
+ } else seg = [genColumn];
89
+ line.push(seg);
90
+ reader.pos++;
91
+ }
92
+ if (!sorted) sort(line);
93
+ decoded.push(line);
94
+ reader.pos = semi + 1;
95
+ } while (reader.pos <= length);
96
+ return decoded;
97
+ }
98
+ function sort(line) {
99
+ line.sort(sortComparator);
100
+ }
101
+ function sortComparator(a, b) {
102
+ return a[0] - b[0];
103
+ }
104
+ var COLUMN = 0;
105
+ var SOURCES_INDEX = 1;
106
+ var SOURCE_LINE = 2;
107
+ var SOURCE_COLUMN = 3;
108
+ var NAMES_INDEX = 4;
109
+ var found = false;
110
+ function binarySearch(haystack, needle, low, high) {
111
+ while (low <= high) {
112
+ const mid = low + (high - low >> 1);
113
+ const cmp = haystack[mid][COLUMN] - needle;
114
+ if (cmp === 0) {
115
+ found = true;
116
+ return mid;
117
+ }
118
+ if (cmp < 0) low = mid + 1;
119
+ else high = mid - 1;
120
+ }
121
+ found = false;
122
+ return low - 1;
123
+ }
124
+ function upperBound(haystack, needle, index) {
125
+ for (let i = index + 1; i < haystack.length; index = i++) if (haystack[i][COLUMN] !== needle) break;
126
+ return index;
127
+ }
128
+ function lowerBound(haystack, needle, index) {
129
+ for (let i = index - 1; i >= 0; index = i--) if (haystack[i][COLUMN] !== needle) break;
130
+ return index;
131
+ }
132
+ function memoizedBinarySearch(haystack, needle, state, key) {
133
+ const { lastKey, lastNeedle, lastIndex } = state;
134
+ let low = 0;
135
+ let high = haystack.length - 1;
136
+ if (key === lastKey) {
137
+ if (needle === lastNeedle) {
138
+ found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
139
+ return lastIndex;
140
+ }
141
+ if (needle >= lastNeedle) low = lastIndex === -1 ? 0 : lastIndex;
142
+ else high = lastIndex;
143
+ }
144
+ state.lastKey = key;
145
+ state.lastNeedle = needle;
146
+ return state.lastIndex = binarySearch(haystack, needle, low, high);
147
+ }
148
+ var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
149
+ var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
150
+ var LEAST_UPPER_BOUND = -1;
151
+ var GREATEST_LOWER_BOUND = 1;
152
+ function cast(map) {
153
+ return map;
154
+ }
155
+ function decodedMappings(map) {
156
+ var _a;
157
+ return (_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded));
158
+ }
159
+ function originalPositionFor(map, needle) {
160
+ let { line, column, bias } = needle;
161
+ line--;
162
+ if (line < 0) throw new Error(LINE_GTR_ZERO);
163
+ if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
164
+ const decoded = decodedMappings(map);
165
+ if (line >= decoded.length) return OMapping(null, null, null, null);
166
+ const segments = decoded[line];
167
+ const index = traceSegmentInternal(segments, cast(map)._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
168
+ if (index === -1) return OMapping(null, null, null, null);
169
+ const segment = segments[index];
170
+ if (segment.length === 1) return OMapping(null, null, null, null);
171
+ const { names, resolvedSources } = map;
172
+ return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
173
+ }
174
+ function OMapping(source, line, column, name) {
175
+ return {
176
+ source,
177
+ line,
178
+ column,
179
+ name
180
+ };
181
+ }
182
+ function traceSegmentInternal(segments, memo, line, column, bias) {
183
+ let index = memoizedBinarySearch(segments, column, memo, line);
184
+ if (found) index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
185
+ else if (bias === LEAST_UPPER_BOUND) index++;
186
+ if (index === -1 || index === segments.length) return -1;
187
+ return index;
188
+ }
189
+ function notNullish(v) {
190
+ return v != null;
191
+ }
192
+ function isPrimitive(value) {
193
+ return value === null || typeof value !== "function" && typeof value !== "object";
194
+ }
195
+ function isObject(item) {
196
+ return item != null && typeof item === "object" && !Array.isArray(item);
197
+ }
198
+ /**
199
+ * If code starts with a function call, will return its last index, respecting arguments.
200
+ * This will return 25 - last ending character of toMatch ")"
201
+ * Also works with callbacks
202
+ * ```
203
+ * toMatch({ test: '123' });
204
+ * toBeAliased('123')
205
+ * ```
206
+ */
207
+ function getCallLastIndex(code) {
208
+ let charIndex = -1;
209
+ let inString = null;
210
+ let startedBracers = 0;
211
+ let endedBracers = 0;
212
+ let beforeChar = null;
213
+ while (charIndex <= code.length) {
214
+ beforeChar = code[charIndex];
215
+ charIndex++;
216
+ const char = code[charIndex];
217
+ if ((char === "\"" || char === "'" || char === "`") && beforeChar !== "\\") {
218
+ if (inString === char) inString = null;
219
+ else if (!inString) inString = char;
220
+ }
221
+ if (!inString) {
222
+ if (char === "(") startedBracers++;
223
+ if (char === ")") endedBracers++;
224
+ }
225
+ if (startedBracers && endedBracers && startedBracers === endedBracers) return charIndex;
226
+ }
227
+ return null;
228
+ }
229
+ const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
230
+ const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
231
+ const stackIgnorePatterns = [
232
+ "node:internal",
233
+ /\/packages\/\w+\/dist\//,
234
+ /\/@vitest\/\w+\/dist\//,
235
+ "/vitest/dist/",
236
+ "/vitest/src/",
237
+ "/node_modules/chai/",
238
+ "/node_modules/tinyspy/",
239
+ "/vite/dist/node/module-runner",
240
+ "/rolldown-vite/dist/node/module-runner",
241
+ "/deps/chunk-",
242
+ "/deps/@vitest",
243
+ "/deps/loupe",
244
+ "/deps/chai",
245
+ "/browser-playwright/dist/locators.js",
246
+ "/browser-webdriverio/dist/locators.js",
247
+ "/browser-preview/dist/locators.js",
248
+ /node:\w+/,
249
+ /__vitest_test__/,
250
+ /__vitest_browser__/,
251
+ /\/deps\/vitest_/
252
+ ];
253
+ function extractLocation(urlLike) {
254
+ if (!urlLike.includes(":")) return [urlLike];
255
+ const parts = /(.+?)(?::(\d+))?(?::(\d+))?$/.exec(urlLike.replace(/^\(|\)$/g, ""));
256
+ if (!parts) return [urlLike];
257
+ let url = parts[1];
258
+ if (url.startsWith("async ")) url = url.slice(6);
259
+ if (url.startsWith("http:") || url.startsWith("https:")) {
260
+ const urlObj = new URL(url);
261
+ urlObj.searchParams.delete("import");
262
+ urlObj.searchParams.delete("browserv");
263
+ url = urlObj.pathname + urlObj.hash + urlObj.search;
264
+ }
265
+ if (url.startsWith("/@fs/")) {
266
+ const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
267
+ url = url.slice(isWindows ? 5 : 4);
268
+ }
269
+ return [
270
+ url,
271
+ parts[2] || void 0,
272
+ parts[3] || void 0
273
+ ];
274
+ }
275
+ function parseSingleFFOrSafariStack(raw) {
276
+ let line = raw.trim();
277
+ if (SAFARI_NATIVE_CODE_REGEXP.test(line)) return null;
278
+ if (line.includes(" > eval")) line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1");
279
+ if (!line.includes("@")) return null;
280
+ let atIndex = -1;
281
+ let locationPart = "";
282
+ let functionName;
283
+ for (let i = 0; i < line.length; i++) if (line[i] === "@") {
284
+ const candidateLocation = line.slice(i + 1);
285
+ if (candidateLocation.includes(":") && candidateLocation.length >= 3) {
286
+ atIndex = i;
287
+ locationPart = candidateLocation;
288
+ functionName = i > 0 ? line.slice(0, i) : void 0;
289
+ break;
290
+ }
291
+ }
292
+ if (atIndex === -1 || !locationPart.includes(":") || locationPart.length < 3) return null;
293
+ const [url, lineNumber, columnNumber] = extractLocation(locationPart);
294
+ if (!url || !lineNumber || !columnNumber) return null;
295
+ return {
296
+ file: url,
297
+ method: functionName || "",
298
+ line: Number.parseInt(lineNumber),
299
+ column: Number.parseInt(columnNumber)
300
+ };
301
+ }
302
+ function parseSingleV8Stack(raw) {
303
+ let line = raw.trim();
304
+ if (!CHROME_IE_STACK_REGEXP.test(line)) return null;
305
+ if (line.includes("(eval ")) line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
306
+ let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
307
+ const location = sanitizedLine.match(/ (\(.+\)$)/);
308
+ sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
309
+ const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
310
+ let method = location && sanitizedLine || "";
311
+ let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
312
+ if (!file || !lineNumber || !columnNumber) return null;
313
+ if (method.startsWith("async ")) method = method.slice(6);
314
+ if (file.startsWith("file://")) file = file.slice(7);
315
+ file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve(file);
316
+ if (method) method = method.replace(/__vite_ssr_import_\d+__\./g, "").replace(/(Object\.)?__vite_ssr_export_default__\s?/g, "");
317
+ return {
318
+ method,
319
+ file,
320
+ line: Number.parseInt(lineNumber),
321
+ column: Number.parseInt(columnNumber)
322
+ };
323
+ }
324
+ function parseStacktrace(stack, options = {}) {
325
+ const { ignoreStackEntries = stackIgnorePatterns } = options;
326
+ return (!CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack)).map((stack$1) => {
327
+ var _options$getSourceMap;
328
+ if (options.getUrlId) stack$1.file = options.getUrlId(stack$1.file);
329
+ const map = (_options$getSourceMap = options.getSourceMap) === null || _options$getSourceMap === void 0 ? void 0 : _options$getSourceMap.call(options, stack$1.file);
330
+ if (!map || typeof map !== "object" || !map.version) return shouldFilter(ignoreStackEntries, stack$1.file) ? null : stack$1;
331
+ const position = getOriginalPosition(new DecodedMap(map, stack$1.file), stack$1);
332
+ if (!position) return stack$1;
333
+ const { line, column, source, name } = position;
334
+ let file = source || stack$1.file;
335
+ if (file.match(/\/\w:\//)) file = file.slice(1);
336
+ if (shouldFilter(ignoreStackEntries, file)) return null;
337
+ if (line != null && column != null) return {
338
+ line,
339
+ column,
340
+ file,
341
+ method: name || stack$1.method
342
+ };
343
+ return stack$1;
344
+ }).filter((s) => s != null);
345
+ }
346
+ function shouldFilter(ignoreStackEntries, file) {
347
+ return ignoreStackEntries.some((p) => file.match(p));
348
+ }
349
+ function parseFFOrSafariStackTrace(stack) {
350
+ return stack.split("\n").map((line) => parseSingleFFOrSafariStack(line)).filter(notNullish);
351
+ }
352
+ function parseV8Stacktrace(stack) {
353
+ return stack.split("\n").map((line) => parseSingleV8Stack(line)).filter(notNullish);
354
+ }
355
+ function parseErrorStacktrace(e, options = {}) {
356
+ if (!e || isPrimitive(e)) return [];
357
+ if ("stacks" in e && e.stacks) return e.stacks;
358
+ const stackStr = e.stack || "";
359
+ let stackFrames = typeof stackStr === "string" ? parseStacktrace(stackStr, options) : [];
360
+ if (!stackFrames.length) {
361
+ const e_ = e;
362
+ if (e_.fileName != null && e_.lineNumber != null && e_.columnNumber != null) stackFrames = parseStacktrace(`${e_.fileName}:${e_.lineNumber}:${e_.columnNumber}`, options);
363
+ if (e_.sourceURL != null && e_.line != null && e_._column != null) stackFrames = parseStacktrace(`${e_.sourceURL}:${e_.line}:${e_.column}`, options);
364
+ }
365
+ if (options.frameFilter) stackFrames = stackFrames.filter((f) => options.frameFilter(e, f) !== false);
366
+ e.stacks = stackFrames;
367
+ return stackFrames;
368
+ }
369
+ var DecodedMap = class {
370
+ _encoded;
371
+ _decoded;
372
+ _decodedMemo;
373
+ url;
374
+ version;
375
+ names = [];
376
+ resolvedSources;
377
+ constructor(map, from) {
378
+ this.map = map;
379
+ const { mappings, names, sources } = map;
380
+ this.version = map.version;
381
+ this.names = names || [];
382
+ this._encoded = mappings || "";
383
+ this._decodedMemo = memoizedState();
384
+ this.url = from;
385
+ this.resolvedSources = (sources || []).map((s) => resolve(s || "", from));
386
+ }
387
+ };
388
+ function memoizedState() {
389
+ return {
390
+ lastKey: -1,
391
+ lastNeedle: -1,
392
+ lastIndex: -1
393
+ };
394
+ }
395
+ function getOriginalPosition(map, needle) {
396
+ const result = originalPositionFor(map, needle);
397
+ if (result.column == null) return null;
398
+ return result;
399
+ }
400
+ const lineSplitRE = /\r?\n/;
401
+ function positionToOffset(source, lineNumber, columnNumber) {
402
+ const lines = source.split(lineSplitRE);
403
+ const nl = /\r\n/.test(source) ? 2 : 1;
404
+ let start = 0;
405
+ if (lineNumber > lines.length) return source.length;
406
+ for (let i = 0; i < lineNumber - 1; i++) start += lines[i].length + nl;
407
+ return start + columnNumber;
408
+ }
409
+ function offsetToLineNumber(source, offset) {
410
+ if (offset > source.length) throw new Error(`offset is longer than source length! offset ${offset} > length ${source.length}`);
411
+ const lines = source.split(lineSplitRE);
412
+ const nl = /\r\n/.test(source) ? 2 : 1;
413
+ let counted = 0;
414
+ let line = 0;
415
+ for (; line < lines.length; line++) {
416
+ const lineLength = lines[line].length + nl;
417
+ if (counted + lineLength >= offset) break;
418
+ counted += lineLength;
419
+ }
420
+ return line + 1;
421
+ }
422
+ async function saveInlineSnapshots(environment, snapshots) {
423
+ const MagicString = (await import("../../../magic-string/dist/magic-string.es.js")).default;
424
+ const files = new Set(snapshots.map((i) => i.file));
425
+ await Promise.all(Array.from(files).map(async (file) => {
426
+ const snaps = snapshots.filter((i) => i.file === file);
427
+ const code = await environment.readSnapshotFile(file);
428
+ const s = new MagicString(code);
429
+ for (const snap of snaps) replaceInlineSnap(code, s, positionToOffset(code, snap.line, snap.column), snap.snapshot);
430
+ const transformed = s.toString();
431
+ if (transformed !== code) await environment.saveSnapshotFile(file, transformed);
432
+ }));
433
+ }
434
+ const startObjectRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*\{/;
435
+ function replaceObjectSnap(code, s, index, newSnap) {
436
+ let _code = code.slice(index);
437
+ const startMatch = startObjectRegex.exec(_code);
438
+ if (!startMatch) return false;
439
+ _code = _code.slice(startMatch.index);
440
+ let callEnd = getCallLastIndex(_code);
441
+ if (callEnd === null) return false;
442
+ callEnd += index + startMatch.index;
443
+ const shapeEnd = getObjectShapeEndIndex(code, index + startMatch.index + startMatch[0].length);
444
+ const snap = `, ${prepareSnapString(newSnap, code, index)}`;
445
+ if (shapeEnd === callEnd) s.appendLeft(callEnd, snap);
446
+ else s.overwrite(shapeEnd, callEnd, snap);
447
+ return true;
448
+ }
449
+ function getObjectShapeEndIndex(code, index) {
450
+ let startBraces = 1;
451
+ let endBraces = 0;
452
+ while (startBraces !== endBraces && index < code.length) {
453
+ const s = code[index++];
454
+ if (s === "{") startBraces++;
455
+ else if (s === "}") endBraces++;
456
+ }
457
+ return index;
458
+ }
459
+ function prepareSnapString(snap, source, index) {
460
+ const lineNumber = offsetToLineNumber(source, index);
461
+ const indent = source.split(lineSplitRE)[lineNumber - 1].match(/^\s*/)[0] || "";
462
+ const indentNext = indent.includes(" ") ? `${indent}\t` : `${indent} `;
463
+ const lines = snap.trim().replace(/\\/g, "\\\\").split(/\n/g);
464
+ const isOneline = lines.length <= 1;
465
+ const quote = "`";
466
+ if (isOneline) return `${quote}${lines.join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}${quote}`;
467
+ return `${quote}\n${lines.map((i) => i ? indentNext + i : "").join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}\n${indent}${quote}`;
468
+ }
469
+ const toMatchInlineName = "toMatchInlineSnapshot";
470
+ const toThrowErrorMatchingInlineName = "toThrowErrorMatchingInlineSnapshot";
471
+ function getCodeStartingAtIndex(code, index) {
472
+ const indexInline = index - 21;
473
+ if (code.slice(indexInline, index) === toMatchInlineName) return {
474
+ code: code.slice(indexInline),
475
+ index: indexInline
476
+ };
477
+ const indexThrowInline = index - 34;
478
+ if (code.slice(index - indexThrowInline, index) === toThrowErrorMatchingInlineName) return {
479
+ code: code.slice(index - indexThrowInline),
480
+ index: index - indexThrowInline
481
+ };
482
+ return {
483
+ code: code.slice(index),
484
+ index
485
+ };
486
+ }
487
+ const startRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*[\w$]*(['"`)])/;
488
+ function replaceInlineSnap(code, s, currentIndex, newSnap) {
489
+ const { code: codeStartingAtIndex, index } = getCodeStartingAtIndex(code, currentIndex);
490
+ const startMatch = startRegex.exec(codeStartingAtIndex);
491
+ const firstKeywordMatch = /toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot/.exec(codeStartingAtIndex);
492
+ if (!startMatch || startMatch.index !== (firstKeywordMatch === null || firstKeywordMatch === void 0 ? void 0 : firstKeywordMatch.index)) return replaceObjectSnap(code, s, index, newSnap);
493
+ const quote = startMatch[1];
494
+ const startIndex = index + startMatch.index + startMatch[0].length;
495
+ const snapString = prepareSnapString(newSnap, code, index);
496
+ if (quote === ")") {
497
+ s.appendRight(startIndex - 1, snapString);
498
+ return true;
499
+ }
500
+ const endMatch = (/* @__PURE__ */ new RegExp(`(?:^|[^\\\\])${quote}`)).exec(code.slice(startIndex));
501
+ if (!endMatch) return false;
502
+ const endIndex = startIndex + endMatch.index + endMatch[0].length;
503
+ s.overwrite(startIndex - 1, endIndex, snapString);
504
+ return true;
505
+ }
506
+ const INDENTATION_REGEX = /^([^\S\n]*)\S/m;
507
+ function stripSnapshotIndentation(inlineSnapshot) {
508
+ var _lines$at;
509
+ const match = inlineSnapshot.match(INDENTATION_REGEX);
510
+ if (!match || !match[1]) return inlineSnapshot;
511
+ const indentation = match[1];
512
+ const lines = inlineSnapshot.split(/\n/g);
513
+ if (lines.length <= 2) return inlineSnapshot;
514
+ if (lines[0].trim() !== "" || ((_lines$at = lines.at(-1)) === null || _lines$at === void 0 ? void 0 : _lines$at.trim()) !== "") return inlineSnapshot;
515
+ for (let i = 1; i < lines.length - 1; i++) if (lines[i] !== "") {
516
+ if (lines[i].indexOf(indentation) !== 0) return inlineSnapshot;
517
+ lines[i] = lines[i].substring(indentation.length);
518
+ }
519
+ lines[lines.length - 1] = "";
520
+ inlineSnapshot = lines.join("\n");
521
+ return inlineSnapshot;
522
+ }
523
+ async function saveRawSnapshots(environment, snapshots) {
524
+ await Promise.all(snapshots.map(async (snap) => {
525
+ if (!snap.readonly) await environment.saveSnapshotFile(snap.file, snap.snapshot);
526
+ }));
527
+ }
528
+ function getDefaultExportFromCjs(x) {
529
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
530
+ }
531
+ var naturalCompare$1 = { exports: {} };
532
+ var hasRequiredNaturalCompare;
533
+ function requireNaturalCompare() {
534
+ if (hasRequiredNaturalCompare) return naturalCompare$1.exports;
535
+ hasRequiredNaturalCompare = 1;
536
+ /*
537
+ * @version 1.4.0
538
+ * @date 2015-10-26
539
+ * @stability 3 - Stable
540
+ * @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
541
+ * @license MIT License
542
+ */
543
+ var naturalCompare$2 = function(a, b) {
544
+ var i, codeA, codeB = 1, posA = 0, posB = 0, alphabet = String.alphabet;
545
+ function getCode(str, pos, code) {
546
+ if (code) {
547
+ for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
548
+ return +str.slice(pos - 1, i);
549
+ }
550
+ code = alphabet && alphabet.indexOf(str.charAt(pos));
551
+ return code > -1 ? code + 76 : (code = str.charCodeAt(pos) || 0, code < 45 || code > 127) ? code : code < 46 ? 65 : code < 48 ? code - 1 : code < 58 ? code + 18 : code < 65 ? code - 11 : code < 91 ? code + 11 : code < 97 ? code - 37 : code < 123 ? code + 5 : code - 63;
552
+ }
553
+ if ((a += "") != (b += "")) for (; codeB;) {
554
+ codeA = getCode(a, posA++);
555
+ codeB = getCode(b, posB++);
556
+ if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
557
+ codeA = getCode(a, posA, posA);
558
+ codeB = getCode(b, posB, posA = i);
559
+ posB = i;
560
+ }
561
+ if (codeA != codeB) return codeA < codeB ? -1 : 1;
562
+ }
563
+ return 0;
564
+ };
565
+ try {
566
+ naturalCompare$1.exports = naturalCompare$2;
567
+ } catch (e) {
568
+ String.naturalCompare = naturalCompare$2;
569
+ }
570
+ return naturalCompare$1.exports;
571
+ }
572
+ var naturalCompare = /* @__PURE__ */ getDefaultExportFromCjs(requireNaturalCompare());
573
+ const serialize$1 = (val, config, indentation, depth, refs, printer) => {
574
+ const name = val.getMockName();
575
+ const nameString = name === "vi.fn()" ? "" : ` ${name}`;
576
+ let callsString = "";
577
+ if (val.mock.calls.length !== 0) {
578
+ const indentationNext = indentation + config.indent;
579
+ callsString = ` {${config.spacingOuter}${indentationNext}"calls": ${printer(val.mock.calls, config, indentationNext, depth, refs)}${config.min ? ", " : ","}${config.spacingOuter}${indentationNext}"results": ${printer(val.mock.results, config, indentationNext, depth, refs)}${config.min ? "" : ","}${config.spacingOuter}${indentation}}`;
580
+ }
581
+ return `[MockFunction${nameString}]${callsString}`;
582
+ };
583
+ const test = (val) => val && !!val._isMockFunction;
584
+ const plugin = {
585
+ serialize: serialize$1,
586
+ test
587
+ };
588
+ const { DOMCollection, DOMElement, Immutable, ReactElement, ReactTestComponent, AsymmetricMatcher } = plugins;
589
+ let PLUGINS = [
590
+ ReactTestComponent,
591
+ ReactElement,
592
+ DOMElement,
593
+ DOMCollection,
594
+ Immutable,
595
+ AsymmetricMatcher,
596
+ plugin
597
+ ];
598
+ function addSerializer(plugin$1) {
599
+ PLUGINS = [plugin$1].concat(PLUGINS);
600
+ }
601
+ function getSerializers() {
602
+ return PLUGINS;
603
+ }
604
+ function testNameToKey(testName, count) {
605
+ return `${testName} ${count}`;
606
+ }
607
+ function keyToTestName(key) {
608
+ if (!/ \d+$/.test(key)) throw new Error("Snapshot keys must end with a number.");
609
+ return key.replace(/ \d+$/, "");
610
+ }
611
+ function getSnapshotData(content, options) {
612
+ const update = options.updateSnapshot;
613
+ const data = Object.create(null);
614
+ let snapshotContents = "";
615
+ let dirty = false;
616
+ if (content != null) try {
617
+ snapshotContents = content;
618
+ new Function("exports", snapshotContents)(data);
619
+ } catch {}
620
+ if ((update === "all" || update === "new") && snapshotContents) dirty = true;
621
+ return {
622
+ data,
623
+ dirty
624
+ };
625
+ }
626
+ function addExtraLineBreaks(string) {
627
+ return string.includes("\n") ? `\n${string}\n` : string;
628
+ }
629
+ function removeExtraLineBreaks(string) {
630
+ return string.length > 2 && string[0] === "\n" && string.endsWith("\n") ? string.slice(1, -1) : string;
631
+ }
632
+ const escapeRegex = true;
633
+ const printFunctionName = false;
634
+ function serialize(val, indent = 2, formatOverrides = {}) {
635
+ return normalizeNewlines(format(val, {
636
+ escapeRegex,
637
+ indent,
638
+ plugins: getSerializers(),
639
+ printFunctionName,
640
+ ...formatOverrides
641
+ }));
642
+ }
643
+ function escapeBacktickString(str) {
644
+ return str.replace(/`|\\|\$\{/g, "\\$&");
645
+ }
646
+ function printBacktickString(str) {
647
+ return `\`${escapeBacktickString(str)}\``;
648
+ }
649
+ function normalizeNewlines(string) {
650
+ return string.replace(/\r\n|\r/g, "\n");
651
+ }
652
+ async function saveSnapshotFile(environment, snapshotData, snapshotPath) {
653
+ const snapshots = Object.keys(snapshotData).sort(naturalCompare).map((key) => `exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`);
654
+ const content = `${environment.getHeader()}\n\n${snapshots.join("\n\n")}\n`;
655
+ const oldContent = await environment.readSnapshotFile(snapshotPath);
656
+ if (oldContent != null && oldContent === content) return;
657
+ await environment.saveSnapshotFile(snapshotPath, content);
658
+ }
659
+ function deepMergeArray(target = [], source = []) {
660
+ const mergedOutput = Array.from(target);
661
+ source.forEach((sourceElement, index) => {
662
+ const targetElement = mergedOutput[index];
663
+ if (Array.isArray(target[index])) mergedOutput[index] = deepMergeArray(target[index], sourceElement);
664
+ else if (isObject(targetElement)) mergedOutput[index] = deepMergeSnapshot(target[index], sourceElement);
665
+ else mergedOutput[index] = sourceElement;
666
+ });
667
+ return mergedOutput;
668
+ }
669
+ /**
670
+ * Deep merge, but considers asymmetric matchers. Unlike base util's deep merge,
671
+ * will merge any object-like instance.
672
+ * Compatible with Jest's snapshot matcher. Should not be used outside of snapshot.
673
+ *
674
+ * @example
675
+ * ```ts
676
+ * toMatchSnapshot({
677
+ * name: expect.stringContaining('text')
678
+ * })
679
+ * ```
680
+ */
681
+ function deepMergeSnapshot(target, source) {
682
+ if (isObject(target) && isObject(source)) {
683
+ const mergedOutput = { ...target };
684
+ Object.keys(source).forEach((key) => {
685
+ if (isObject(source[key]) && !source[key].$$typeof) if (!(key in target)) Object.assign(mergedOutput, { [key]: source[key] });
686
+ else mergedOutput[key] = deepMergeSnapshot(target[key], source[key]);
687
+ else if (Array.isArray(source[key])) mergedOutput[key] = deepMergeArray(target[key], source[key]);
688
+ else Object.assign(mergedOutput, { [key]: source[key] });
689
+ });
690
+ return mergedOutput;
691
+ } else if (Array.isArray(target) && Array.isArray(source)) return deepMergeArray(target, source);
692
+ return target;
693
+ }
694
+ var DefaultMap = class extends Map {
695
+ constructor(defaultFn, entries) {
696
+ super(entries);
697
+ this.defaultFn = defaultFn;
698
+ }
699
+ get(key) {
700
+ if (!this.has(key)) this.set(key, this.defaultFn(key));
701
+ return super.get(key);
702
+ }
703
+ };
704
+ var CounterMap = class extends DefaultMap {
705
+ constructor() {
706
+ super(() => 0);
707
+ }
708
+ _total;
709
+ valueOf() {
710
+ return this._total = this.total();
711
+ }
712
+ increment(key) {
713
+ if (typeof this._total !== "undefined") this._total++;
714
+ this.set(key, this.get(key) + 1);
715
+ }
716
+ total() {
717
+ if (typeof this._total !== "undefined") return this._total;
718
+ let total = 0;
719
+ for (const x of this.values()) total += x;
720
+ return total;
721
+ }
722
+ };
723
+ function isSameStackPosition(x, y) {
724
+ return x.file === y.file && x.column === y.column && x.line === y.line;
725
+ }
726
+ var SnapshotState = class SnapshotState {
727
+ _counters = new CounterMap();
728
+ _dirty;
729
+ _updateSnapshot;
730
+ _snapshotData;
731
+ _initialData;
732
+ _inlineSnapshots;
733
+ _inlineSnapshotStacks;
734
+ _testIdToKeys = new DefaultMap(() => []);
735
+ _rawSnapshots;
736
+ _uncheckedKeys;
737
+ _snapshotFormat;
738
+ _environment;
739
+ _fileExists;
740
+ expand;
741
+ _added = new CounterMap();
742
+ _matched = new CounterMap();
743
+ _unmatched = new CounterMap();
744
+ _updated = new CounterMap();
745
+ get added() {
746
+ return this._added;
747
+ }
748
+ set added(value) {
749
+ this._added._total = value;
750
+ }
751
+ get matched() {
752
+ return this._matched;
753
+ }
754
+ set matched(value) {
755
+ this._matched._total = value;
756
+ }
757
+ get unmatched() {
758
+ return this._unmatched;
759
+ }
760
+ set unmatched(value) {
761
+ this._unmatched._total = value;
762
+ }
763
+ get updated() {
764
+ return this._updated;
765
+ }
766
+ set updated(value) {
767
+ this._updated._total = value;
768
+ }
769
+ constructor(testFilePath, snapshotPath, snapshotContent, options) {
770
+ this.testFilePath = testFilePath;
771
+ this.snapshotPath = snapshotPath;
772
+ const { data, dirty } = getSnapshotData(snapshotContent, options);
773
+ this._fileExists = snapshotContent != null;
774
+ this._initialData = { ...data };
775
+ this._snapshotData = { ...data };
776
+ this._dirty = dirty;
777
+ this._inlineSnapshots = [];
778
+ this._inlineSnapshotStacks = [];
779
+ this._rawSnapshots = [];
780
+ this._uncheckedKeys = new Set(Object.keys(this._snapshotData));
781
+ this.expand = options.expand || false;
782
+ this._updateSnapshot = options.updateSnapshot;
783
+ this._snapshotFormat = {
784
+ printBasicPrototype: false,
785
+ escapeString: false,
786
+ ...options.snapshotFormat
787
+ };
788
+ this._environment = options.snapshotEnvironment;
789
+ }
790
+ static async create(testFilePath, options) {
791
+ const snapshotPath = await options.snapshotEnvironment.resolvePath(testFilePath);
792
+ return new SnapshotState(testFilePath, snapshotPath, await options.snapshotEnvironment.readSnapshotFile(snapshotPath), options);
793
+ }
794
+ get environment() {
795
+ return this._environment;
796
+ }
797
+ markSnapshotsAsCheckedForTest(testName) {
798
+ this._uncheckedKeys.forEach((uncheckedKey) => {
799
+ if (/ \d+$| > /.test(uncheckedKey.slice(testName.length))) this._uncheckedKeys.delete(uncheckedKey);
800
+ });
801
+ }
802
+ clearTest(testId) {
803
+ this._inlineSnapshots = this._inlineSnapshots.filter((s) => s.testId !== testId);
804
+ this._inlineSnapshotStacks = this._inlineSnapshotStacks.filter((s) => s.testId !== testId);
805
+ for (const key of this._testIdToKeys.get(testId)) {
806
+ const name = keyToTestName(key);
807
+ const count = this._counters.get(name);
808
+ if (count > 0) {
809
+ if (key in this._snapshotData || key in this._initialData) this._snapshotData[key] = this._initialData[key];
810
+ this._counters.set(name, count - 1);
811
+ }
812
+ }
813
+ this._testIdToKeys.delete(testId);
814
+ this.added.delete(testId);
815
+ this.updated.delete(testId);
816
+ this.matched.delete(testId);
817
+ this.unmatched.delete(testId);
818
+ }
819
+ _inferInlineSnapshotStack(stacks) {
820
+ const promiseIndex = stacks.findIndex((i) => i.method.match(/__VITEST_(RESOLVES|REJECTS)__/));
821
+ if (promiseIndex !== -1) return stacks[promiseIndex + 3];
822
+ const stackIndex = stacks.findIndex((i) => i.method.includes("__INLINE_SNAPSHOT__"));
823
+ return stackIndex !== -1 ? stacks[stackIndex + 2] : null;
824
+ }
825
+ _addSnapshot(key, receivedSerialized, options) {
826
+ this._dirty = true;
827
+ if (options.stack) this._inlineSnapshots.push({
828
+ snapshot: receivedSerialized,
829
+ testId: options.testId,
830
+ ...options.stack
831
+ });
832
+ else if (options.rawSnapshot) this._rawSnapshots.push({
833
+ ...options.rawSnapshot,
834
+ snapshot: receivedSerialized
835
+ });
836
+ else this._snapshotData[key] = receivedSerialized;
837
+ }
838
+ async save() {
839
+ const hasExternalSnapshots = Object.keys(this._snapshotData).length;
840
+ const hasInlineSnapshots = this._inlineSnapshots.length;
841
+ const hasRawSnapshots = this._rawSnapshots.length;
842
+ const isEmpty = !hasExternalSnapshots && !hasInlineSnapshots && !hasRawSnapshots;
843
+ const status = {
844
+ deleted: false,
845
+ saved: false
846
+ };
847
+ if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) {
848
+ if (hasExternalSnapshots) {
849
+ await saveSnapshotFile(this._environment, this._snapshotData, this.snapshotPath);
850
+ this._fileExists = true;
851
+ }
852
+ if (hasInlineSnapshots) await saveInlineSnapshots(this._environment, this._inlineSnapshots);
853
+ if (hasRawSnapshots) await saveRawSnapshots(this._environment, this._rawSnapshots);
854
+ status.saved = true;
855
+ } else if (!hasExternalSnapshots && this._fileExists) {
856
+ if (this._updateSnapshot === "all") {
857
+ await this._environment.removeSnapshotFile(this.snapshotPath);
858
+ this._fileExists = false;
859
+ }
860
+ status.deleted = true;
861
+ }
862
+ return status;
863
+ }
864
+ getUncheckedCount() {
865
+ return this._uncheckedKeys.size || 0;
866
+ }
867
+ getUncheckedKeys() {
868
+ return Array.from(this._uncheckedKeys);
869
+ }
870
+ removeUncheckedKeys() {
871
+ if (this._updateSnapshot === "all" && this._uncheckedKeys.size) {
872
+ this._dirty = true;
873
+ this._uncheckedKeys.forEach((key) => delete this._snapshotData[key]);
874
+ this._uncheckedKeys.clear();
875
+ }
876
+ }
877
+ match({ testId, testName, received, key, inlineSnapshot, isInline, error, rawSnapshot }) {
878
+ this._counters.increment(testName);
879
+ const count = this._counters.get(testName);
880
+ if (!key) key = testNameToKey(testName, count);
881
+ this._testIdToKeys.get(testId).push(key);
882
+ if (!(isInline && this._snapshotData[key] !== void 0)) this._uncheckedKeys.delete(key);
883
+ let receivedSerialized = rawSnapshot && typeof received === "string" ? received : serialize(received, void 0, this._snapshotFormat);
884
+ if (!rawSnapshot) receivedSerialized = addExtraLineBreaks(receivedSerialized);
885
+ if (rawSnapshot) {
886
+ if (rawSnapshot.content && rawSnapshot.content.match(/\r\n/) && !receivedSerialized.match(/\r\n/)) rawSnapshot.content = normalizeNewlines(rawSnapshot.content);
887
+ }
888
+ const expected = isInline ? inlineSnapshot : rawSnapshot ? rawSnapshot.content : this._snapshotData[key];
889
+ const expectedTrimmed = rawSnapshot ? expected : expected === null || expected === void 0 ? void 0 : expected.trim();
890
+ const pass = expectedTrimmed === (rawSnapshot ? receivedSerialized : receivedSerialized.trim());
891
+ const hasSnapshot = expected !== void 0;
892
+ const snapshotIsPersisted = isInline || this._fileExists || rawSnapshot && rawSnapshot.content != null;
893
+ if (pass && !isInline && !rawSnapshot) this._snapshotData[key] = receivedSerialized;
894
+ let stack;
895
+ if (isInline) {
896
+ var _this$environment$pro, _this$environment;
897
+ const stacks = parseErrorStacktrace(error || /* @__PURE__ */ new Error("snapshot"), { ignoreStackEntries: [] });
898
+ const _stack = this._inferInlineSnapshotStack(stacks);
899
+ if (!_stack) throw new Error(`@vitest/snapshot: Couldn't infer stack frame for inline snapshot.\n${JSON.stringify(stacks)}`);
900
+ stack = ((_this$environment$pro = (_this$environment = this.environment).processStackTrace) === null || _this$environment$pro === void 0 ? void 0 : _this$environment$pro.call(_this$environment, _stack)) || _stack;
901
+ stack.column--;
902
+ const snapshotsWithSameStack = this._inlineSnapshotStacks.filter((s) => isSameStackPosition(s, stack));
903
+ if (snapshotsWithSameStack.length > 0) {
904
+ this._inlineSnapshots = this._inlineSnapshots.filter((s) => !isSameStackPosition(s, stack));
905
+ const differentSnapshot = snapshotsWithSameStack.find((s) => s.snapshot !== receivedSerialized);
906
+ if (differentSnapshot) throw Object.assign(/* @__PURE__ */ new Error("toMatchInlineSnapshot with different snapshots cannot be called at the same location"), {
907
+ actual: receivedSerialized,
908
+ expected: differentSnapshot.snapshot
909
+ });
910
+ }
911
+ this._inlineSnapshotStacks.push({
912
+ ...stack,
913
+ testId,
914
+ snapshot: receivedSerialized
915
+ });
916
+ }
917
+ if (hasSnapshot && this._updateSnapshot === "all" || (!hasSnapshot || !snapshotIsPersisted) && (this._updateSnapshot === "new" || this._updateSnapshot === "all")) {
918
+ if (this._updateSnapshot === "all") if (!pass) {
919
+ if (hasSnapshot) this.updated.increment(testId);
920
+ else this.added.increment(testId);
921
+ this._addSnapshot(key, receivedSerialized, {
922
+ stack,
923
+ testId,
924
+ rawSnapshot
925
+ });
926
+ } else this.matched.increment(testId);
927
+ else {
928
+ this._addSnapshot(key, receivedSerialized, {
929
+ stack,
930
+ testId,
931
+ rawSnapshot
932
+ });
933
+ this.added.increment(testId);
934
+ }
935
+ return {
936
+ actual: "",
937
+ count,
938
+ expected: "",
939
+ key,
940
+ pass: true
941
+ };
942
+ } else if (!pass) {
943
+ this.unmatched.increment(testId);
944
+ return {
945
+ actual: rawSnapshot ? receivedSerialized : removeExtraLineBreaks(receivedSerialized),
946
+ count,
947
+ expected: expectedTrimmed !== void 0 ? rawSnapshot ? expectedTrimmed : removeExtraLineBreaks(expectedTrimmed) : void 0,
948
+ key,
949
+ pass: false
950
+ };
951
+ } else {
952
+ this.matched.increment(testId);
953
+ return {
954
+ actual: "",
955
+ count,
956
+ expected: "",
957
+ key,
958
+ pass: true
959
+ };
960
+ }
961
+ }
962
+ async pack() {
963
+ const snapshot = {
964
+ filepath: this.testFilePath,
965
+ added: 0,
966
+ fileDeleted: false,
967
+ matched: 0,
968
+ unchecked: 0,
969
+ uncheckedKeys: [],
970
+ unmatched: 0,
971
+ updated: 0
972
+ };
973
+ const uncheckedCount = this.getUncheckedCount();
974
+ const uncheckedKeys = this.getUncheckedKeys();
975
+ if (uncheckedCount) this.removeUncheckedKeys();
976
+ const status = await this.save();
977
+ snapshot.fileDeleted = status.deleted;
978
+ snapshot.added = this.added.total();
979
+ snapshot.matched = this.matched.total();
980
+ snapshot.unmatched = this.unmatched.total();
981
+ snapshot.updated = this.updated.total();
982
+ snapshot.unchecked = !status.deleted ? uncheckedCount : 0;
983
+ snapshot.uncheckedKeys = Array.from(uncheckedKeys);
984
+ return snapshot;
985
+ }
986
+ };
987
+ function createMismatchError(message, expand, actual, expected) {
988
+ const error = new Error(message);
989
+ Object.defineProperty(error, "actual", {
990
+ value: actual,
991
+ enumerable: true,
992
+ configurable: true,
993
+ writable: true
994
+ });
995
+ Object.defineProperty(error, "expected", {
996
+ value: expected,
997
+ enumerable: true,
998
+ configurable: true,
999
+ writable: true
1000
+ });
1001
+ Object.defineProperty(error, "diffOptions", { value: { expand } });
1002
+ return error;
1003
+ }
1004
+ var SnapshotClient = class {
1005
+ snapshotStateMap = /* @__PURE__ */ new Map();
1006
+ constructor(options = {}) {
1007
+ this.options = options;
1008
+ }
1009
+ async setup(filepath, options) {
1010
+ if (this.snapshotStateMap.has(filepath)) return;
1011
+ this.snapshotStateMap.set(filepath, await SnapshotState.create(filepath, options));
1012
+ }
1013
+ async finish(filepath) {
1014
+ const result = await this.getSnapshotState(filepath).pack();
1015
+ this.snapshotStateMap.delete(filepath);
1016
+ return result;
1017
+ }
1018
+ skipTest(filepath, testName) {
1019
+ this.getSnapshotState(filepath).markSnapshotsAsCheckedForTest(testName);
1020
+ }
1021
+ clearTest(filepath, testId) {
1022
+ this.getSnapshotState(filepath).clearTest(testId);
1023
+ }
1024
+ getSnapshotState(filepath) {
1025
+ const state = this.snapshotStateMap.get(filepath);
1026
+ if (!state) throw new Error(`The snapshot state for '${filepath}' is not found. Did you call 'SnapshotClient.setup()'?`);
1027
+ return state;
1028
+ }
1029
+ assert(options) {
1030
+ const { filepath, name, testId = name, message, isInline = false, properties, inlineSnapshot, error, errorMessage, rawSnapshot } = options;
1031
+ let { received } = options;
1032
+ if (!filepath) throw new Error("Snapshot cannot be used outside of test");
1033
+ const snapshotState = this.getSnapshotState(filepath);
1034
+ if (typeof properties === "object") {
1035
+ if (typeof received !== "object" || !received) throw new Error("Received value must be an object when the matcher has properties");
1036
+ try {
1037
+ var _this$options$isEqual, _this$options;
1038
+ if (!(((_this$options$isEqual = (_this$options = this.options).isEqual) === null || _this$options$isEqual === void 0 ? void 0 : _this$options$isEqual.call(_this$options, received, properties)) ?? false)) throw createMismatchError("Snapshot properties mismatched", snapshotState.expand, received, properties);
1039
+ else received = deepMergeSnapshot(received, properties);
1040
+ } catch (err) {
1041
+ err.message = errorMessage || "Snapshot mismatched";
1042
+ throw err;
1043
+ }
1044
+ }
1045
+ const testName = [name, ...message ? [message] : []].join(" > ");
1046
+ const { actual, expected, key, pass } = snapshotState.match({
1047
+ testId,
1048
+ testName,
1049
+ received,
1050
+ isInline,
1051
+ error,
1052
+ inlineSnapshot,
1053
+ rawSnapshot
1054
+ });
1055
+ if (!pass) throw createMismatchError(`Snapshot \`${key || "unknown"}\` mismatched`, snapshotState.expand, rawSnapshot ? actual : actual === null || actual === void 0 ? void 0 : actual.trim(), rawSnapshot ? expected : expected === null || expected === void 0 ? void 0 : expected.trim());
1056
+ }
1057
+ async assertRaw(options) {
1058
+ if (!options.rawSnapshot) throw new Error("Raw snapshot is required");
1059
+ const { filepath, rawSnapshot } = options;
1060
+ if (rawSnapshot.content == null) {
1061
+ if (!filepath) throw new Error("Snapshot cannot be used outside of test");
1062
+ const snapshotState = this.getSnapshotState(filepath);
1063
+ options.filepath || (options.filepath = filepath);
1064
+ rawSnapshot.file = await snapshotState.environment.resolveRawPath(filepath, rawSnapshot.file);
1065
+ rawSnapshot.content = await snapshotState.environment.readSnapshotFile(rawSnapshot.file) ?? void 0;
1066
+ }
1067
+ return this.assert(options);
1068
+ }
1069
+ clear() {
1070
+ this.snapshotStateMap.clear();
1071
+ }
1072
+ };
1073
+
1074
+ //#endregion
1075
+ export { SnapshotClient, addSerializer, stripSnapshotIndentation };