@soda-gql/swc-transformer 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,913 @@
1
+ import { realpathSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+
4
+ //#region node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
5
+ var comma = ",".charCodeAt(0);
6
+ var semicolon = ";".charCodeAt(0);
7
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
8
+ var intToChar = new Uint8Array(64);
9
+ var charToInt = new Uint8Array(128);
10
+ for (let i = 0; i < chars.length; i++) {
11
+ const c = chars.charCodeAt(i);
12
+ intToChar[i] = c;
13
+ charToInt[c] = i;
14
+ }
15
+ function decodeInteger(reader, relative) {
16
+ let value = 0;
17
+ let shift = 0;
18
+ let integer = 0;
19
+ do {
20
+ integer = charToInt[reader.next()];
21
+ value |= (integer & 31) << shift;
22
+ shift += 5;
23
+ } while (integer & 32);
24
+ const shouldNegate = value & 1;
25
+ value >>>= 1;
26
+ if (shouldNegate) value = -2147483648 | -value;
27
+ return relative + value;
28
+ }
29
+ function encodeInteger(builder, num, relative) {
30
+ let delta = num - relative;
31
+ delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
32
+ do {
33
+ let clamped = delta & 31;
34
+ delta >>>= 5;
35
+ if (delta > 0) clamped |= 32;
36
+ builder.write(intToChar[clamped]);
37
+ } while (delta > 0);
38
+ return num;
39
+ }
40
+ function hasMoreVlq(reader, max) {
41
+ if (reader.pos >= max) return false;
42
+ return reader.peek() !== comma;
43
+ }
44
+ var bufLength = 1024 * 16;
45
+ var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? { decode(buf) {
46
+ return Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength).toString();
47
+ } } : { decode(buf) {
48
+ let out = "";
49
+ for (let i = 0; i < buf.length; i++) out += String.fromCharCode(buf[i]);
50
+ return out;
51
+ } };
52
+ var StringWriter = class {
53
+ constructor() {
54
+ this.pos = 0;
55
+ this.out = "";
56
+ this.buffer = new Uint8Array(bufLength);
57
+ }
58
+ write(v) {
59
+ const { buffer } = this;
60
+ buffer[this.pos++] = v;
61
+ if (this.pos === bufLength) {
62
+ this.out += td.decode(buffer);
63
+ this.pos = 0;
64
+ }
65
+ }
66
+ flush() {
67
+ const { buffer, out, pos } = this;
68
+ return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
69
+ }
70
+ };
71
+ var StringReader = class {
72
+ constructor(buffer) {
73
+ this.pos = 0;
74
+ this.buffer = buffer;
75
+ }
76
+ next() {
77
+ return this.buffer.charCodeAt(this.pos++);
78
+ }
79
+ peek() {
80
+ return this.buffer.charCodeAt(this.pos);
81
+ }
82
+ indexOf(char) {
83
+ const { buffer, pos } = this;
84
+ const idx = buffer.indexOf(char, pos);
85
+ return idx === -1 ? buffer.length : idx;
86
+ }
87
+ };
88
+ function decode(mappings) {
89
+ const { length } = mappings;
90
+ const reader = new StringReader(mappings);
91
+ const decoded = [];
92
+ let genColumn = 0;
93
+ let sourcesIndex = 0;
94
+ let sourceLine = 0;
95
+ let sourceColumn = 0;
96
+ let namesIndex = 0;
97
+ do {
98
+ const semi = reader.indexOf(";");
99
+ const line = [];
100
+ let sorted = true;
101
+ let lastCol = 0;
102
+ genColumn = 0;
103
+ while (reader.pos < semi) {
104
+ let seg;
105
+ genColumn = decodeInteger(reader, genColumn);
106
+ if (genColumn < lastCol) sorted = false;
107
+ lastCol = genColumn;
108
+ if (hasMoreVlq(reader, semi)) {
109
+ sourcesIndex = decodeInteger(reader, sourcesIndex);
110
+ sourceLine = decodeInteger(reader, sourceLine);
111
+ sourceColumn = decodeInteger(reader, sourceColumn);
112
+ if (hasMoreVlq(reader, semi)) {
113
+ namesIndex = decodeInteger(reader, namesIndex);
114
+ seg = [
115
+ genColumn,
116
+ sourcesIndex,
117
+ sourceLine,
118
+ sourceColumn,
119
+ namesIndex
120
+ ];
121
+ } else seg = [
122
+ genColumn,
123
+ sourcesIndex,
124
+ sourceLine,
125
+ sourceColumn
126
+ ];
127
+ } else seg = [genColumn];
128
+ line.push(seg);
129
+ reader.pos++;
130
+ }
131
+ if (!sorted) sort(line);
132
+ decoded.push(line);
133
+ reader.pos = semi + 1;
134
+ } while (reader.pos <= length);
135
+ return decoded;
136
+ }
137
+ function sort(line) {
138
+ line.sort(sortComparator$1);
139
+ }
140
+ function sortComparator$1(a, b) {
141
+ return a[0] - b[0];
142
+ }
143
+ function encode(decoded) {
144
+ const writer = new StringWriter();
145
+ let sourcesIndex = 0;
146
+ let sourceLine = 0;
147
+ let sourceColumn = 0;
148
+ let namesIndex = 0;
149
+ for (let i = 0; i < decoded.length; i++) {
150
+ const line = decoded[i];
151
+ if (i > 0) writer.write(semicolon);
152
+ if (line.length === 0) continue;
153
+ let genColumn = 0;
154
+ for (let j = 0; j < line.length; j++) {
155
+ const segment = line[j];
156
+ if (j > 0) writer.write(comma);
157
+ genColumn = encodeInteger(writer, segment[0], genColumn);
158
+ if (segment.length === 1) continue;
159
+ sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
160
+ sourceLine = encodeInteger(writer, segment[2], sourceLine);
161
+ sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
162
+ if (segment.length === 4) continue;
163
+ namesIndex = encodeInteger(writer, segment[4], namesIndex);
164
+ }
165
+ }
166
+ return writer.flush();
167
+ }
168
+
169
+ //#endregion
170
+ //#region node_modules/@jridgewell/resolve-uri/dist/resolve-uri.mjs
171
+ const schemeRegex = /^[\w+.-]+:\/\//;
172
+ /**
173
+ * Matches the parts of a URL:
174
+ * 1. Scheme, including ":", guaranteed.
175
+ * 2. User/password, including "@", optional.
176
+ * 3. Host, guaranteed.
177
+ * 4. Port, including ":", optional.
178
+ * 5. Path, including "/", optional.
179
+ * 6. Query, including "?", optional.
180
+ * 7. Hash, including "#", optional.
181
+ */
182
+ const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
183
+ /**
184
+ * File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
185
+ * with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
186
+ *
187
+ * 1. Host, optional.
188
+ * 2. Path, which may include "/", guaranteed.
189
+ * 3. Query, including "?", optional.
190
+ * 4. Hash, including "#", optional.
191
+ */
192
+ const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
193
+ function isAbsoluteUrl(input) {
194
+ return schemeRegex.test(input);
195
+ }
196
+ function isSchemeRelativeUrl(input) {
197
+ return input.startsWith("//");
198
+ }
199
+ function isAbsolutePath(input) {
200
+ return input.startsWith("/");
201
+ }
202
+ function isFileUrl(input) {
203
+ return input.startsWith("file:");
204
+ }
205
+ function isRelative(input) {
206
+ return /^[.?#]/.test(input);
207
+ }
208
+ function parseAbsoluteUrl(input) {
209
+ const match = urlRegex.exec(input);
210
+ return makeUrl(match[1], match[2] || "", match[3], match[4] || "", match[5] || "/", match[6] || "", match[7] || "");
211
+ }
212
+ function parseFileUrl(input) {
213
+ const match = fileRegex.exec(input);
214
+ const path = match[2];
215
+ return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(path) ? path : "/" + path, match[3] || "", match[4] || "");
216
+ }
217
+ function makeUrl(scheme, user, host, port, path, query, hash) {
218
+ return {
219
+ scheme,
220
+ user,
221
+ host,
222
+ port,
223
+ path,
224
+ query,
225
+ hash,
226
+ type: 7
227
+ };
228
+ }
229
+ function parseUrl(input) {
230
+ if (isSchemeRelativeUrl(input)) {
231
+ const url$1 = parseAbsoluteUrl("http:" + input);
232
+ url$1.scheme = "";
233
+ url$1.type = 6;
234
+ return url$1;
235
+ }
236
+ if (isAbsolutePath(input)) {
237
+ const url$1 = parseAbsoluteUrl("http://foo.com" + input);
238
+ url$1.scheme = "";
239
+ url$1.host = "";
240
+ url$1.type = 5;
241
+ return url$1;
242
+ }
243
+ if (isFileUrl(input)) return parseFileUrl(input);
244
+ if (isAbsoluteUrl(input)) return parseAbsoluteUrl(input);
245
+ const url = parseAbsoluteUrl("http://foo.com/" + input);
246
+ url.scheme = "";
247
+ url.host = "";
248
+ url.type = input ? input.startsWith("?") ? 3 : input.startsWith("#") ? 2 : 4 : 1;
249
+ return url;
250
+ }
251
+ function stripPathFilename(path) {
252
+ if (path.endsWith("/..")) return path;
253
+ const index = path.lastIndexOf("/");
254
+ return path.slice(0, index + 1);
255
+ }
256
+ function mergePaths(url, base) {
257
+ normalizePath$1(base, base.type);
258
+ if (url.path === "/") url.path = base.path;
259
+ else url.path = stripPathFilename(base.path) + url.path;
260
+ }
261
+ /**
262
+ * The path can have empty directories "//", unneeded parents "foo/..", or current directory
263
+ * "foo/.". We need to normalize to a standard representation.
264
+ */
265
+ function normalizePath$1(url, type) {
266
+ const rel = type <= 4;
267
+ const pieces = url.path.split("/");
268
+ let pointer = 1;
269
+ let positive = 0;
270
+ let addTrailingSlash = false;
271
+ for (let i = 1; i < pieces.length; i++) {
272
+ const piece = pieces[i];
273
+ if (!piece) {
274
+ addTrailingSlash = true;
275
+ continue;
276
+ }
277
+ addTrailingSlash = false;
278
+ if (piece === ".") continue;
279
+ if (piece === "..") {
280
+ if (positive) {
281
+ addTrailingSlash = true;
282
+ positive--;
283
+ pointer--;
284
+ } else if (rel) pieces[pointer++] = piece;
285
+ continue;
286
+ }
287
+ pieces[pointer++] = piece;
288
+ positive++;
289
+ }
290
+ let path = "";
291
+ for (let i = 1; i < pointer; i++) path += "/" + pieces[i];
292
+ if (!path || addTrailingSlash && !path.endsWith("/..")) path += "/";
293
+ url.path = path;
294
+ }
295
+ /**
296
+ * Attempts to resolve `input` URL/path relative to `base`.
297
+ */
298
+ function resolve$1(input, base) {
299
+ if (!input && !base) return "";
300
+ const url = parseUrl(input);
301
+ let inputType = url.type;
302
+ if (base && inputType !== 7) {
303
+ const baseUrl = parseUrl(base);
304
+ const baseType = baseUrl.type;
305
+ switch (inputType) {
306
+ case 1: url.hash = baseUrl.hash;
307
+ case 2: url.query = baseUrl.query;
308
+ case 3:
309
+ case 4: mergePaths(url, baseUrl);
310
+ case 5:
311
+ url.user = baseUrl.user;
312
+ url.host = baseUrl.host;
313
+ url.port = baseUrl.port;
314
+ case 6: url.scheme = baseUrl.scheme;
315
+ }
316
+ if (baseType > inputType) inputType = baseType;
317
+ }
318
+ normalizePath$1(url, inputType);
319
+ const queryHash = url.query + url.hash;
320
+ switch (inputType) {
321
+ case 2:
322
+ case 3: return queryHash;
323
+ case 4: {
324
+ const path = url.path.slice(1);
325
+ if (!path) return queryHash || ".";
326
+ if (isRelative(base || input) && !isRelative(path)) return "./" + path + queryHash;
327
+ return path + queryHash;
328
+ }
329
+ case 5: return url.path + queryHash;
330
+ default: return url.scheme + "//" + url.user + url.host + url.port + url.path + queryHash;
331
+ }
332
+ }
333
+
334
+ //#endregion
335
+ //#region node_modules/@jridgewell/trace-mapping/dist/trace-mapping.mjs
336
+ function stripFilename(path) {
337
+ if (!path) return "";
338
+ const index = path.lastIndexOf("/");
339
+ return path.slice(0, index + 1);
340
+ }
341
+ function resolver(mapUrl, sourceRoot) {
342
+ const from = stripFilename(mapUrl);
343
+ const prefix = sourceRoot ? sourceRoot + "/" : "";
344
+ return (source) => resolve$1(prefix + (source || ""), from);
345
+ }
346
+ var COLUMN$1 = 0;
347
+ function maybeSort(mappings, owned) {
348
+ const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
349
+ if (unsortedIndex === mappings.length) return mappings;
350
+ if (!owned) mappings = mappings.slice();
351
+ for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) mappings[i] = sortSegments(mappings[i], owned);
352
+ return mappings;
353
+ }
354
+ function nextUnsortedSegmentLine(mappings, start) {
355
+ for (let i = start; i < mappings.length; i++) if (!isSorted(mappings[i])) return i;
356
+ return mappings.length;
357
+ }
358
+ function isSorted(line) {
359
+ for (let j = 1; j < line.length; j++) if (line[j][COLUMN$1] < line[j - 1][COLUMN$1]) return false;
360
+ return true;
361
+ }
362
+ function sortSegments(line, owned) {
363
+ if (!owned) line = line.slice();
364
+ return line.sort(sortComparator);
365
+ }
366
+ function sortComparator(a, b) {
367
+ return a[COLUMN$1] - b[COLUMN$1];
368
+ }
369
+ var found = false;
370
+ function binarySearch(haystack, needle, low, high) {
371
+ while (low <= high) {
372
+ const mid = low + (high - low >> 1);
373
+ const cmp = haystack[mid][COLUMN$1] - needle;
374
+ if (cmp === 0) {
375
+ found = true;
376
+ return mid;
377
+ }
378
+ if (cmp < 0) low = mid + 1;
379
+ else high = mid - 1;
380
+ }
381
+ found = false;
382
+ return low - 1;
383
+ }
384
+ function upperBound(haystack, needle, index) {
385
+ for (let i = index + 1; i < haystack.length; index = i++) if (haystack[i][COLUMN$1] !== needle) break;
386
+ return index;
387
+ }
388
+ function lowerBound(haystack, needle, index) {
389
+ for (let i = index - 1; i >= 0; index = i--) if (haystack[i][COLUMN$1] !== needle) break;
390
+ return index;
391
+ }
392
+ function memoizedState() {
393
+ return {
394
+ lastKey: -1,
395
+ lastNeedle: -1,
396
+ lastIndex: -1
397
+ };
398
+ }
399
+ function memoizedBinarySearch(haystack, needle, state, key) {
400
+ const { lastKey, lastNeedle, lastIndex } = state;
401
+ let low = 0;
402
+ let high = haystack.length - 1;
403
+ if (key === lastKey) {
404
+ if (needle === lastNeedle) {
405
+ found = lastIndex !== -1 && haystack[lastIndex][COLUMN$1] === needle;
406
+ return lastIndex;
407
+ }
408
+ if (needle >= lastNeedle) low = lastIndex === -1 ? 0 : lastIndex;
409
+ else high = lastIndex;
410
+ }
411
+ state.lastKey = key;
412
+ state.lastNeedle = needle;
413
+ return state.lastIndex = binarySearch(haystack, needle, low, high);
414
+ }
415
+ function parse(map) {
416
+ return typeof map === "string" ? JSON.parse(map) : map;
417
+ }
418
+ var LEAST_UPPER_BOUND = -1;
419
+ var GREATEST_LOWER_BOUND = 1;
420
+ var TraceMap = class {
421
+ constructor(map, mapUrl) {
422
+ const isString = typeof map === "string";
423
+ if (!isString && map._decodedMemo) return map;
424
+ const parsed = parse(map);
425
+ const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
426
+ this.version = version;
427
+ this.file = file;
428
+ this.names = names || [];
429
+ this.sourceRoot = sourceRoot;
430
+ this.sources = sources;
431
+ this.sourcesContent = sourcesContent;
432
+ this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
433
+ const resolve$2 = resolver(mapUrl, sourceRoot);
434
+ this.resolvedSources = sources.map(resolve$2);
435
+ const { mappings } = parsed;
436
+ if (typeof mappings === "string") {
437
+ this._encoded = mappings;
438
+ this._decoded = void 0;
439
+ } else if (Array.isArray(mappings)) {
440
+ this._encoded = void 0;
441
+ this._decoded = maybeSort(mappings, isString);
442
+ } else if (parsed.sections) throw new Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);
443
+ else throw new Error(`invalid source map: ${JSON.stringify(parsed)}`);
444
+ this._decodedMemo = memoizedState();
445
+ this._bySources = void 0;
446
+ this._bySourceMemos = void 0;
447
+ }
448
+ };
449
+ function cast$1(map) {
450
+ return map;
451
+ }
452
+ function decodedMappings(map) {
453
+ var _a;
454
+ return (_a = cast$1(map))._decoded || (_a._decoded = decode(cast$1(map)._encoded));
455
+ }
456
+ function traceSegment(map, line, column) {
457
+ const decoded = decodedMappings(map);
458
+ if (line >= decoded.length) return null;
459
+ const segments = decoded[line];
460
+ const index = traceSegmentInternal(segments, cast$1(map)._decodedMemo, line, column, GREATEST_LOWER_BOUND);
461
+ return index === -1 ? null : segments[index];
462
+ }
463
+ function traceSegmentInternal(segments, memo, line, column, bias) {
464
+ let index = memoizedBinarySearch(segments, column, memo, line);
465
+ if (found) index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
466
+ else if (bias === LEAST_UPPER_BOUND) index++;
467
+ if (index === -1 || index === segments.length) return -1;
468
+ return index;
469
+ }
470
+
471
+ //#endregion
472
+ //#region node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
473
+ var SetArray = class {
474
+ constructor() {
475
+ this._indexes = { __proto__: null };
476
+ this.array = [];
477
+ }
478
+ };
479
+ function cast(set) {
480
+ return set;
481
+ }
482
+ function get(setarr, key) {
483
+ return cast(setarr)._indexes[key];
484
+ }
485
+ function put(setarr, key) {
486
+ const index = get(setarr, key);
487
+ if (index !== void 0) return index;
488
+ const { array, _indexes: indexes } = cast(setarr);
489
+ return indexes[key] = array.push(key) - 1;
490
+ }
491
+ function remove(setarr, key) {
492
+ const index = get(setarr, key);
493
+ if (index === void 0) return;
494
+ const { array, _indexes: indexes } = cast(setarr);
495
+ for (let i = index + 1; i < array.length; i++) {
496
+ const k = array[i];
497
+ array[i - 1] = k;
498
+ indexes[k]--;
499
+ }
500
+ indexes[key] = void 0;
501
+ array.pop();
502
+ }
503
+ var COLUMN = 0;
504
+ var SOURCES_INDEX = 1;
505
+ var SOURCE_LINE = 2;
506
+ var SOURCE_COLUMN = 3;
507
+ var NAMES_INDEX = 4;
508
+ var NO_NAME = -1;
509
+ var GenMapping = class {
510
+ constructor({ file, sourceRoot } = {}) {
511
+ this._names = new SetArray();
512
+ this._sources = new SetArray();
513
+ this._sourcesContent = [];
514
+ this._mappings = [];
515
+ this.file = file;
516
+ this.sourceRoot = sourceRoot;
517
+ this._ignoreList = new SetArray();
518
+ }
519
+ };
520
+ function cast2(map) {
521
+ return map;
522
+ }
523
+ var maybeAddSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
524
+ return addSegmentInternal(true, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content);
525
+ };
526
+ function setSourceContent(map, source, content) {
527
+ const { _sources: sources, _sourcesContent: sourcesContent } = cast2(map);
528
+ const index = put(sources, source);
529
+ sourcesContent[index] = content;
530
+ }
531
+ function setIgnore(map, source, ignore = true) {
532
+ const { _sources: sources, _sourcesContent: sourcesContent, _ignoreList: ignoreList } = cast2(map);
533
+ const index = put(sources, source);
534
+ if (index === sourcesContent.length) sourcesContent[index] = null;
535
+ if (ignore) put(ignoreList, index);
536
+ else remove(ignoreList, index);
537
+ }
538
+ function toDecodedMap(map) {
539
+ const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, _ignoreList: ignoreList } = cast2(map);
540
+ removeEmptyFinalLines(mappings);
541
+ return {
542
+ version: 3,
543
+ file: map.file || void 0,
544
+ names: names.array,
545
+ sourceRoot: map.sourceRoot || void 0,
546
+ sources: sources.array,
547
+ sourcesContent,
548
+ mappings,
549
+ ignoreList: ignoreList.array
550
+ };
551
+ }
552
+ function toEncodedMap(map) {
553
+ const decoded = toDecodedMap(map);
554
+ return Object.assign({}, decoded, { mappings: encode(decoded.mappings) });
555
+ }
556
+ function addSegmentInternal(skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
557
+ const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names } = cast2(map);
558
+ const line = getIndex(mappings, genLine);
559
+ const index = getColumnIndex(line, genColumn);
560
+ if (!source) {
561
+ if (skipable && skipSourceless(line, index)) return;
562
+ return insert(line, index, [genColumn]);
563
+ }
564
+ assert(sourceLine);
565
+ assert(sourceColumn);
566
+ const sourcesIndex = put(sources, source);
567
+ const namesIndex = name ? put(names, name) : NO_NAME;
568
+ if (sourcesIndex === sourcesContent.length) sourcesContent[sourcesIndex] = content != null ? content : null;
569
+ if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) return;
570
+ return insert(line, index, name ? [
571
+ genColumn,
572
+ sourcesIndex,
573
+ sourceLine,
574
+ sourceColumn,
575
+ namesIndex
576
+ ] : [
577
+ genColumn,
578
+ sourcesIndex,
579
+ sourceLine,
580
+ sourceColumn
581
+ ]);
582
+ }
583
+ function assert(_val) {}
584
+ function getIndex(arr, index) {
585
+ for (let i = arr.length; i <= index; i++) arr[i] = [];
586
+ return arr[index];
587
+ }
588
+ function getColumnIndex(line, genColumn) {
589
+ let index = line.length;
590
+ for (let i = index - 1; i >= 0; index = i--) if (genColumn >= line[i][COLUMN]) break;
591
+ return index;
592
+ }
593
+ function insert(array, index, value) {
594
+ for (let i = array.length; i > index; i--) array[i] = array[i - 1];
595
+ array[index] = value;
596
+ }
597
+ function removeEmptyFinalLines(mappings) {
598
+ const { length } = mappings;
599
+ let len = length;
600
+ for (let i = len - 1; i >= 0; len = i, i--) if (mappings[i].length > 0) break;
601
+ if (len < length) mappings.length = len;
602
+ }
603
+ function skipSourceless(line, index) {
604
+ if (index === 0) return true;
605
+ return line[index - 1].length === 1;
606
+ }
607
+ function skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex) {
608
+ if (index === 0) return false;
609
+ const prev = line[index - 1];
610
+ if (prev.length === 1) return false;
611
+ return sourcesIndex === prev[SOURCES_INDEX] && sourceLine === prev[SOURCE_LINE] && sourceColumn === prev[SOURCE_COLUMN] && namesIndex === (prev.length === 5 ? prev[NAMES_INDEX] : NO_NAME);
612
+ }
613
+
614
+ //#endregion
615
+ //#region node_modules/@ampproject/remapping/dist/remapping.mjs
616
+ const SOURCELESS_MAPPING = /* @__PURE__ */ SegmentObject("", -1, -1, "", null, false);
617
+ const EMPTY_SOURCES = [];
618
+ function SegmentObject(source, line, column, name, content, ignore) {
619
+ return {
620
+ source,
621
+ line,
622
+ column,
623
+ name,
624
+ content,
625
+ ignore
626
+ };
627
+ }
628
+ function Source(map, sources, source, content, ignore) {
629
+ return {
630
+ map,
631
+ sources,
632
+ source,
633
+ content,
634
+ ignore
635
+ };
636
+ }
637
+ /**
638
+ * MapSource represents a single sourcemap, with the ability to trace mappings into its child nodes
639
+ * (which may themselves be SourceMapTrees).
640
+ */
641
+ function MapSource(map, sources) {
642
+ return Source(map, sources, "", null, false);
643
+ }
644
+ /**
645
+ * A "leaf" node in the sourcemap tree, representing an original, unmodified source file. Recursive
646
+ * segment tracing ends at the `OriginalSource`.
647
+ */
648
+ function OriginalSource(source, content, ignore) {
649
+ return Source(null, EMPTY_SOURCES, source, content, ignore);
650
+ }
651
+ /**
652
+ * traceMappings is only called on the root level SourceMapTree, and begins the process of
653
+ * resolving each mapping in terms of the original source files.
654
+ */
655
+ function traceMappings(tree) {
656
+ const gen = new GenMapping({ file: tree.map.file });
657
+ const { sources: rootSources, map } = tree;
658
+ const rootNames = map.names;
659
+ const rootMappings = decodedMappings(map);
660
+ for (let i = 0; i < rootMappings.length; i++) {
661
+ const segments = rootMappings[i];
662
+ for (let j = 0; j < segments.length; j++) {
663
+ const segment = segments[j];
664
+ const genCol = segment[0];
665
+ let traced = SOURCELESS_MAPPING;
666
+ if (segment.length !== 1) {
667
+ const source$1 = rootSources[segment[1]];
668
+ traced = originalPositionFor(source$1, segment[2], segment[3], segment.length === 5 ? rootNames[segment[4]] : "");
669
+ if (traced == null) continue;
670
+ }
671
+ const { column, line, name, content, source, ignore } = traced;
672
+ maybeAddSegment(gen, i, genCol, source, line, column, name);
673
+ if (source && content != null) setSourceContent(gen, source, content);
674
+ if (ignore) setIgnore(gen, source, true);
675
+ }
676
+ }
677
+ return gen;
678
+ }
679
+ /**
680
+ * originalPositionFor is only called on children SourceMapTrees. It recurses down into its own
681
+ * child SourceMapTrees, until we find the original source map.
682
+ */
683
+ function originalPositionFor(source, line, column, name) {
684
+ if (!source.map) return SegmentObject(source.source, line, column, name, source.content, source.ignore);
685
+ const segment = traceSegment(source.map, line, column);
686
+ if (segment == null) return null;
687
+ if (segment.length === 1) return SOURCELESS_MAPPING;
688
+ return originalPositionFor(source.sources[segment[1]], segment[2], segment[3], segment.length === 5 ? source.map.names[segment[4]] : name);
689
+ }
690
+ function asArray(value) {
691
+ if (Array.isArray(value)) return value;
692
+ return [value];
693
+ }
694
+ /**
695
+ * Recursively builds a tree structure out of sourcemap files, with each node
696
+ * being either an `OriginalSource` "leaf" or a `SourceMapTree` composed of
697
+ * `OriginalSource`s and `SourceMapTree`s.
698
+ *
699
+ * Every sourcemap is composed of a collection of source files and mappings
700
+ * into locations of those source files. When we generate a `SourceMapTree` for
701
+ * the sourcemap, we attempt to load each source file's own sourcemap. If it
702
+ * does not have an associated sourcemap, it is considered an original,
703
+ * unmodified source file.
704
+ */
705
+ function buildSourceMapTree(input, loader) {
706
+ const maps = asArray(input).map((m) => new TraceMap(m, ""));
707
+ const map = maps.pop();
708
+ for (let i = 0; i < maps.length; i++) if (maps[i].sources.length > 1) throw new Error(`Transformation map ${i} must have exactly one source file.\nDid you specify these with the most recent transformation maps first?`);
709
+ let tree = build(map, loader, "", 0);
710
+ for (let i = maps.length - 1; i >= 0; i--) tree = MapSource(maps[i], [tree]);
711
+ return tree;
712
+ }
713
+ function build(map, loader, importer, importerDepth) {
714
+ const { resolvedSources, sourcesContent, ignoreList } = map;
715
+ const depth = importerDepth + 1;
716
+ return MapSource(map, resolvedSources.map((sourceFile, i) => {
717
+ const ctx = {
718
+ importer,
719
+ depth,
720
+ source: sourceFile || "",
721
+ content: void 0,
722
+ ignore: void 0
723
+ };
724
+ const sourceMap = loader(ctx.source, ctx);
725
+ const { source, content, ignore } = ctx;
726
+ if (sourceMap) return build(new TraceMap(sourceMap, source), loader, source, depth);
727
+ return OriginalSource(source, content !== void 0 ? content : sourcesContent ? sourcesContent[i] : null, ignore !== void 0 ? ignore : ignoreList ? ignoreList.includes(i) : false);
728
+ }));
729
+ }
730
+ /**
731
+ * A SourceMap v3 compatible sourcemap, which only includes fields that were
732
+ * provided to it.
733
+ */
734
+ var SourceMap = class {
735
+ constructor(map, options) {
736
+ const out = options.decodedMappings ? toDecodedMap(map) : toEncodedMap(map);
737
+ this.version = out.version;
738
+ this.file = out.file;
739
+ this.mappings = out.mappings;
740
+ this.names = out.names;
741
+ this.ignoreList = out.ignoreList;
742
+ this.sourceRoot = out.sourceRoot;
743
+ this.sources = out.sources;
744
+ if (!options.excludeContent) this.sourcesContent = out.sourcesContent;
745
+ }
746
+ toString() {
747
+ return JSON.stringify(this);
748
+ }
749
+ };
750
+ /**
751
+ * Traces through all the mappings in the root sourcemap, through the sources
752
+ * (and their sourcemaps), all the way back to the original source location.
753
+ *
754
+ * `loader` will be called every time we encounter a source file. If it returns
755
+ * a sourcemap, we will recurse into that sourcemap to continue the trace. If
756
+ * it returns a falsey value, that source file is treated as an original,
757
+ * unmodified source file.
758
+ *
759
+ * Pass `excludeContent` to exclude any self-containing source file content
760
+ * from the output sourcemap.
761
+ *
762
+ * Pass `decodedMappings` to receive a SourceMap with decoded (instead of
763
+ * VLQ encoded) mappings.
764
+ */
765
+ function remapping(input, loader, options) {
766
+ const opts = typeof options === "object" ? options : {
767
+ excludeContent: !!options,
768
+ decodedMappings: false
769
+ };
770
+ return new SourceMap(traceMappings(buildSourceMapTree(input, loader)), opts);
771
+ }
772
+
773
+ //#endregion
774
+ //#region packages/swc-transformer/src/index.ts
775
+ /**
776
+ * SWC-based transformer for soda-gql GraphQL code generation.
777
+ *
778
+ * This module provides a TypeScript wrapper around the native Rust transformer.
779
+ */
780
+ let nativeModule = null;
781
+ /**
782
+ * Load the native module.
783
+ * Uses the napi-rs generated loader which handles platform detection.
784
+ */
785
+ const loadNativeModule = async () => {
786
+ if (nativeModule) return nativeModule;
787
+ try {
788
+ const { createRequire } = await import("node:module");
789
+ nativeModule = createRequire(import.meta.url)("./native/index.js");
790
+ return nativeModule;
791
+ } catch (error) {
792
+ throw new Error(`Failed to load @soda-gql/swc-transformer native module. Make sure the native module is built for your platform. Run 'bun run build' in the packages/swc-transformer directory. (${error})`);
793
+ }
794
+ };
795
+ /**
796
+ * Normalize path separators to forward slashes (cross-platform).
797
+ * This matches the behavior of @soda-gql/common normalizePath.
798
+ */
799
+ const normalizePath = (value) => value.replace(/\\/g, "/");
800
+ /**
801
+ * Filter artifact to only include elements for the given source file.
802
+ * This significantly reduces JSON serialization overhead for large codebases.
803
+ *
804
+ * Canonical IDs have the format: "filepath::astPath"
805
+ * We filter by matching the filepath prefix.
806
+ */
807
+ const filterArtifactForFile = (artifact, sourcePath) => {
808
+ const prefix = `${sourcePath}::`;
809
+ const filteredElements = {};
810
+ for (const [id, element] of Object.entries(artifact.elements)) if (id.startsWith(prefix)) filteredElements[id] = element;
811
+ return {
812
+ elements: filteredElements,
813
+ report: {
814
+ stats: {
815
+ hits: 0,
816
+ misses: 0,
817
+ skips: 0
818
+ },
819
+ durationMs: 0,
820
+ warnings: []
821
+ }
822
+ };
823
+ };
824
+ /**
825
+ * Resolve the canonical path to the graphql-system file.
826
+ * Uses realpath to resolve symlinks for accurate comparison.
827
+ */
828
+ const resolveGraphqlSystemPath = (config) => {
829
+ const graphqlSystemPath = resolve(config.outdir, "index.ts");
830
+ try {
831
+ return normalizePath(realpathSync(graphqlSystemPath));
832
+ } catch {
833
+ return normalizePath(resolve(graphqlSystemPath));
834
+ }
835
+ };
836
+ /**
837
+ * Create a transformer instance.
838
+ *
839
+ * @param options - Transform options including config and artifact
840
+ * @returns A transformer that can transform source files
841
+ */
842
+ const createTransformer = async (options) => {
843
+ const native = await loadNativeModule();
844
+ const isCJS = options.compilerOptions?.module === "CommonJS";
845
+ const graphqlSystemPath = resolveGraphqlSystemPath(options.config);
846
+ const configJson = JSON.stringify({
847
+ graphqlSystemAliases: options.config.graphqlSystemAliases,
848
+ isCjs: isCJS,
849
+ graphqlSystemPath,
850
+ sourceMap: options.sourceMap ?? false
851
+ });
852
+ const fullArtifact = options.artifact;
853
+ return { transform: ({ sourceCode, sourcePath, inputSourceMap }) => {
854
+ const normalizedPath = normalizePath(resolve(sourcePath));
855
+ const filteredArtifact = filterArtifactForFile(fullArtifact, normalizedPath);
856
+ const filteredArtifactJson = JSON.stringify(filteredArtifact);
857
+ const resultJson = new native.SwcTransformer(filteredArtifactJson, configJson).transform(sourceCode, normalizedPath);
858
+ const result = JSON.parse(resultJson);
859
+ let finalSourceMap;
860
+ if (result.sourceMap) if (inputSourceMap) {
861
+ const merged = remapping([JSON.parse(result.sourceMap), JSON.parse(inputSourceMap)], () => null);
862
+ finalSourceMap = JSON.stringify(merged);
863
+ } else finalSourceMap = result.sourceMap;
864
+ return {
865
+ transformed: result.transformed,
866
+ sourceCode: result.outputCode,
867
+ sourceMap: finalSourceMap,
868
+ errors: result.errors ?? []
869
+ };
870
+ } };
871
+ };
872
+ /**
873
+ * Transform a single source file (one-shot).
874
+ *
875
+ * For transforming multiple files, use createTransformer() to reuse the artifact.
876
+ *
877
+ * @param input - Transform input including source, path, artifact, and config
878
+ * @returns Transform output
879
+ */
880
+ const transform = async (input) => {
881
+ const native = await loadNativeModule();
882
+ const normalizedPath = normalizePath(resolve(input.sourcePath));
883
+ const filteredArtifact = filterArtifactForFile(input.artifact, normalizedPath);
884
+ const graphqlSystemPath = resolveGraphqlSystemPath(input.config);
885
+ const inputJson = JSON.stringify({
886
+ sourceCode: input.sourceCode,
887
+ sourcePath: normalizedPath,
888
+ artifactJson: JSON.stringify(filteredArtifact),
889
+ config: {
890
+ graphqlSystemAliases: input.config.graphqlSystemAliases,
891
+ isCjs: input.isCjs ?? false,
892
+ graphqlSystemPath,
893
+ sourceMap: input.sourceMap ?? false
894
+ }
895
+ });
896
+ const resultJson = native.transform(inputJson);
897
+ const result = JSON.parse(resultJson);
898
+ let finalSourceMap;
899
+ if (result.sourceMap) if (input.inputSourceMap) {
900
+ const merged = remapping([JSON.parse(result.sourceMap), JSON.parse(input.inputSourceMap)], () => null);
901
+ finalSourceMap = JSON.stringify(merged);
902
+ } else finalSourceMap = result.sourceMap;
903
+ return {
904
+ transformed: result.transformed,
905
+ sourceCode: result.outputCode,
906
+ sourceMap: finalSourceMap,
907
+ errors: result.errors ?? []
908
+ };
909
+ };
910
+
911
+ //#endregion
912
+ export { createTransformer, transform };
913
+ //# sourceMappingURL=index.mjs.map