@arronqzy/blueprint-dsl 1.0.14 → 1.0.16

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.js CHANGED
@@ -158,18 +158,668 @@ function registerDefaultBehaviors(registry) {
158
158
  });
159
159
  }
160
160
 
161
+ // vendor/dayjs/esm/constant.js
162
+ var SECONDS_A_MINUTE = 60;
163
+ var SECONDS_A_HOUR = SECONDS_A_MINUTE * 60;
164
+ var SECONDS_A_DAY = SECONDS_A_HOUR * 24;
165
+ var SECONDS_A_WEEK = SECONDS_A_DAY * 7;
166
+ var MILLISECONDS_A_SECOND = 1e3;
167
+ var MILLISECONDS_A_MINUTE = SECONDS_A_MINUTE * MILLISECONDS_A_SECOND;
168
+ var MILLISECONDS_A_HOUR = SECONDS_A_HOUR * MILLISECONDS_A_SECOND;
169
+ var MILLISECONDS_A_DAY = SECONDS_A_DAY * MILLISECONDS_A_SECOND;
170
+ var MILLISECONDS_A_WEEK = SECONDS_A_WEEK * MILLISECONDS_A_SECOND;
171
+ var MS = "millisecond";
172
+ var S = "second";
173
+ var MIN = "minute";
174
+ var H = "hour";
175
+ var D = "day";
176
+ var W = "week";
177
+ var M = "month";
178
+ var Q = "quarter";
179
+ var Y = "year";
180
+ var DATE = "date";
181
+ var FORMAT_DEFAULT = "YYYY-MM-DDTHH:mm:ssZ";
182
+ var INVALID_DATE_STRING = "Invalid Date";
183
+ var REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/;
184
+ var REGEX_FORMAT = /\[([^\]]+)]|YYYY|YY|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g;
185
+
186
+ // vendor/dayjs/esm/locale/en.js
187
+ var en_default = {
188
+ name: "en",
189
+ weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
190
+ months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
191
+ ordinal: function ordinal(n) {
192
+ var s = ["th", "st", "nd", "rd"];
193
+ var v = n % 100;
194
+ return "[" + n + (s[(v - 20) % 10] || s[v] || s[0]) + "]";
195
+ }
196
+ };
197
+
198
+ // vendor/dayjs/esm/utils.js
199
+ var padStart = function padStart2(string, length, pad) {
200
+ var s = String(string);
201
+ if (!s || s.length >= length) return string;
202
+ return "" + Array(length + 1 - s.length).join(pad) + string;
203
+ };
204
+ var padZoneStr = function padZoneStr2(instance) {
205
+ var negMinutes = -instance.utcOffset();
206
+ var minutes = Math.abs(negMinutes);
207
+ var hourOffset = Math.floor(minutes / 60);
208
+ var minuteOffset = minutes % 60;
209
+ return (negMinutes <= 0 ? "+" : "-") + padStart(hourOffset, 2, "0") + ":" + padStart(minuteOffset, 2, "0");
210
+ };
211
+ var monthDiff = function monthDiff2(a, b) {
212
+ if (a.date() < b.date()) return -monthDiff2(b, a);
213
+ var wholeMonthDiff = (b.year() - a.year()) * 12 + (b.month() - a.month());
214
+ var anchor = a.clone().add(wholeMonthDiff, M);
215
+ var c = b - anchor < 0;
216
+ var anchor2 = a.clone().add(wholeMonthDiff + (c ? -1 : 1), M);
217
+ return +(-(wholeMonthDiff + (b - anchor) / (c ? anchor - anchor2 : anchor2 - anchor)) || 0);
218
+ };
219
+ var absFloor = function absFloor2(n) {
220
+ return n < 0 ? Math.ceil(n) || 0 : Math.floor(n);
221
+ };
222
+ var prettyUnit = function prettyUnit2(u) {
223
+ var special = {
224
+ M,
225
+ y: Y,
226
+ w: W,
227
+ d: D,
228
+ D: DATE,
229
+ h: H,
230
+ m: MIN,
231
+ s: S,
232
+ ms: MS,
233
+ Q
234
+ };
235
+ return special[u] || String(u || "").toLowerCase().replace(/s$/, "");
236
+ };
237
+ var isUndefined = function isUndefined2(s) {
238
+ return s === void 0;
239
+ };
240
+ var utils_default = {
241
+ s: padStart,
242
+ z: padZoneStr,
243
+ m: monthDiff,
244
+ a: absFloor,
245
+ p: prettyUnit,
246
+ u: isUndefined
247
+ };
248
+
249
+ // vendor/dayjs/esm/index.js
250
+ var L = "en";
251
+ var Ls = {};
252
+ Ls[L] = en_default;
253
+ var IS_DAYJS = "$isDayjsObject";
254
+ var isDayjs = function isDayjs2(d) {
255
+ return d instanceof Dayjs || !!(d && d[IS_DAYJS]);
256
+ };
257
+ var parseLocale = function parseLocale2(preset, object, isLocal) {
258
+ var l;
259
+ if (!preset) return L;
260
+ if (typeof preset === "string") {
261
+ var presetLower = preset.toLowerCase();
262
+ if (Ls[presetLower]) {
263
+ l = presetLower;
264
+ }
265
+ if (object) {
266
+ Ls[presetLower] = object;
267
+ l = presetLower;
268
+ }
269
+ var presetSplit = preset.split("-");
270
+ if (!l && presetSplit.length > 1) {
271
+ return parseLocale2(presetSplit[0]);
272
+ }
273
+ } else {
274
+ var name = preset.name;
275
+ Ls[name] = preset;
276
+ l = name;
277
+ }
278
+ if (!isLocal && l) L = l;
279
+ return l || !isLocal && L;
280
+ };
281
+ var dayjs = function dayjs2(date, c) {
282
+ if (isDayjs(date)) {
283
+ return date.clone();
284
+ }
285
+ var cfg = typeof c === "object" ? c : {};
286
+ cfg.date = date;
287
+ cfg.args = arguments;
288
+ return new Dayjs(cfg);
289
+ };
290
+ var wrapper = function wrapper2(date, instance) {
291
+ return dayjs(date, {
292
+ locale: instance.$L,
293
+ utc: instance.$u,
294
+ x: instance.$x,
295
+ $offset: instance.$offset
296
+ // todo: refactor; do not use this.$offset in you code
297
+ });
298
+ };
299
+ var Utils = utils_default;
300
+ Utils.l = parseLocale;
301
+ Utils.i = isDayjs;
302
+ Utils.w = wrapper;
303
+ var parseDate = function parseDate2(cfg) {
304
+ var date = cfg.date, utc = cfg.utc;
305
+ if (date === null) return /* @__PURE__ */ new Date(NaN);
306
+ if (Utils.u(date)) return /* @__PURE__ */ new Date();
307
+ if (date instanceof Date) return new Date(date);
308
+ if (typeof date === "string" && !/Z$/i.test(date)) {
309
+ var d = date.match(REGEX_PARSE);
310
+ if (d) {
311
+ var m = d[2] - 1 || 0;
312
+ var ms = (d[7] || "0").substring(0, 3);
313
+ if (utc) {
314
+ return new Date(Date.UTC(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms));
315
+ }
316
+ return new Date(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms);
317
+ }
318
+ }
319
+ return new Date(date);
320
+ };
321
+ var Dayjs = /* @__PURE__ */ (function() {
322
+ function Dayjs2(cfg) {
323
+ this.$L = parseLocale(cfg.locale, null, true);
324
+ this.parse(cfg);
325
+ this.$x = this.$x || cfg.x || {};
326
+ this[IS_DAYJS] = true;
327
+ }
328
+ var _proto = Dayjs2.prototype;
329
+ _proto.parse = function parse(cfg) {
330
+ this.$d = parseDate(cfg);
331
+ this.init();
332
+ };
333
+ _proto.init = function init() {
334
+ var $d = this.$d;
335
+ this.$y = $d.getFullYear();
336
+ this.$M = $d.getMonth();
337
+ this.$D = $d.getDate();
338
+ this.$W = $d.getDay();
339
+ this.$H = $d.getHours();
340
+ this.$m = $d.getMinutes();
341
+ this.$s = $d.getSeconds();
342
+ this.$ms = $d.getMilliseconds();
343
+ };
344
+ _proto.$utils = function $utils() {
345
+ return Utils;
346
+ };
347
+ _proto.isValid = function isValid() {
348
+ return !(this.$d.toString() === INVALID_DATE_STRING);
349
+ };
350
+ _proto.isSame = function isSame(that, units) {
351
+ var other = dayjs(that);
352
+ return this.startOf(units) <= other && other <= this.endOf(units);
353
+ };
354
+ _proto.isAfter = function isAfter(that, units) {
355
+ return dayjs(that) < this.startOf(units);
356
+ };
357
+ _proto.isBefore = function isBefore(that, units) {
358
+ return this.endOf(units) < dayjs(that);
359
+ };
360
+ _proto.$g = function $g(input, get, set) {
361
+ if (Utils.u(input)) return this[get];
362
+ return this.set(set, input);
363
+ };
364
+ _proto.unix = function unix() {
365
+ return Math.floor(this.valueOf() / 1e3);
366
+ };
367
+ _proto.valueOf = function valueOf() {
368
+ return this.$d.getTime();
369
+ };
370
+ _proto.startOf = function startOf(units, _startOf) {
371
+ var _this = this;
372
+ var isStartOf = !Utils.u(_startOf) ? _startOf : true;
373
+ var unit = Utils.p(units);
374
+ var instanceFactory = function instanceFactory2(d, m) {
375
+ var ins = Utils.w(_this.$u ? Date.UTC(_this.$y, m, d) : new Date(_this.$y, m, d), _this);
376
+ return isStartOf ? ins : ins.endOf(D);
377
+ };
378
+ var instanceFactorySet = function instanceFactorySet2(method, slice) {
379
+ var argumentStart = [0, 0, 0, 0];
380
+ var argumentEnd = [23, 59, 59, 999];
381
+ return Utils.w(_this.toDate()[method].apply(
382
+ // eslint-disable-line prefer-spread
383
+ _this.toDate("s"),
384
+ (isStartOf ? argumentStart : argumentEnd).slice(slice)
385
+ ), _this);
386
+ };
387
+ var $W = this.$W, $M = this.$M, $D = this.$D;
388
+ var utcPad = "set" + (this.$u ? "UTC" : "");
389
+ switch (unit) {
390
+ case Y:
391
+ return isStartOf ? instanceFactory(1, 0) : instanceFactory(31, 11);
392
+ case M:
393
+ return isStartOf ? instanceFactory(1, $M) : instanceFactory(0, $M + 1);
394
+ case W: {
395
+ var weekStart = this.$locale().weekStart || 0;
396
+ var gap = ($W < weekStart ? $W + 7 : $W) - weekStart;
397
+ return instanceFactory(isStartOf ? $D - gap : $D + (6 - gap), $M);
398
+ }
399
+ case D:
400
+ case DATE:
401
+ return instanceFactorySet(utcPad + "Hours", 0);
402
+ case H:
403
+ return instanceFactorySet(utcPad + "Minutes", 1);
404
+ case MIN:
405
+ return instanceFactorySet(utcPad + "Seconds", 2);
406
+ case S:
407
+ return instanceFactorySet(utcPad + "Milliseconds", 3);
408
+ default:
409
+ return this.clone();
410
+ }
411
+ };
412
+ _proto.endOf = function endOf(arg) {
413
+ return this.startOf(arg, false);
414
+ };
415
+ _proto.$set = function $set(units, _int) {
416
+ var _C$D$C$DATE$C$M$C$Y$C;
417
+ var unit = Utils.p(units);
418
+ var utcPad = "set" + (this.$u ? "UTC" : "");
419
+ var name = (_C$D$C$DATE$C$M$C$Y$C = {}, _C$D$C$DATE$C$M$C$Y$C[D] = utcPad + "Date", _C$D$C$DATE$C$M$C$Y$C[DATE] = utcPad + "Date", _C$D$C$DATE$C$M$C$Y$C[M] = utcPad + "Month", _C$D$C$DATE$C$M$C$Y$C[Y] = utcPad + "FullYear", _C$D$C$DATE$C$M$C$Y$C[H] = utcPad + "Hours", _C$D$C$DATE$C$M$C$Y$C[MIN] = utcPad + "Minutes", _C$D$C$DATE$C$M$C$Y$C[S] = utcPad + "Seconds", _C$D$C$DATE$C$M$C$Y$C[MS] = utcPad + "Milliseconds", _C$D$C$DATE$C$M$C$Y$C)[unit];
420
+ var arg = unit === D ? this.$D + (_int - this.$W) : _int;
421
+ if (unit === M || unit === Y) {
422
+ var date = this.clone().set(DATE, 1);
423
+ date.$d[name](arg);
424
+ date.init();
425
+ this.$d = date.set(DATE, Math.min(this.$D, date.daysInMonth())).$d;
426
+ } else if (name) this.$d[name](arg);
427
+ this.init();
428
+ return this;
429
+ };
430
+ _proto.set = function set(string, _int2) {
431
+ return this.clone().$set(string, _int2);
432
+ };
433
+ _proto.get = function get(unit) {
434
+ return this[Utils.p(unit)]();
435
+ };
436
+ _proto.add = function add(number, units) {
437
+ var _this2 = this, _C$MIN$C$H$C$S$unit;
438
+ number = Number(number);
439
+ var unit = Utils.p(units);
440
+ var instanceFactorySet = function instanceFactorySet2(n) {
441
+ var d = dayjs(_this2);
442
+ return Utils.w(d.date(d.date() + Math.round(n * number)), _this2);
443
+ };
444
+ if (unit === M) {
445
+ return this.set(M, this.$M + number);
446
+ }
447
+ if (unit === Y) {
448
+ return this.set(Y, this.$y + number);
449
+ }
450
+ if (unit === D) {
451
+ return instanceFactorySet(1);
452
+ }
453
+ if (unit === W) {
454
+ return instanceFactorySet(7);
455
+ }
456
+ var step = (_C$MIN$C$H$C$S$unit = {}, _C$MIN$C$H$C$S$unit[MIN] = MILLISECONDS_A_MINUTE, _C$MIN$C$H$C$S$unit[H] = MILLISECONDS_A_HOUR, _C$MIN$C$H$C$S$unit[S] = MILLISECONDS_A_SECOND, _C$MIN$C$H$C$S$unit)[unit] || 1;
457
+ var nextTimeStamp = this.$d.getTime() + number * step;
458
+ return Utils.w(nextTimeStamp, this);
459
+ };
460
+ _proto.subtract = function subtract(number, string) {
461
+ return this.add(number * -1, string);
462
+ };
463
+ _proto.format = function format(formatStr) {
464
+ var _this3 = this;
465
+ var locale = this.$locale();
466
+ if (!this.isValid()) return locale.invalidDate || INVALID_DATE_STRING;
467
+ var str = formatStr || FORMAT_DEFAULT;
468
+ var zoneStr = Utils.z(this);
469
+ var $H = this.$H, $m = this.$m, $M = this.$M;
470
+ var weekdays = locale.weekdays, months = locale.months, meridiem = locale.meridiem;
471
+ var getShort = function getShort2(arr, index, full, length) {
472
+ return arr && (arr[index] || arr(_this3, str)) || full[index].slice(0, length);
473
+ };
474
+ var get$H = function get$H2(num) {
475
+ return Utils.s($H % 12 || 12, num, "0");
476
+ };
477
+ var meridiemFunc = meridiem || function(hour, minute, isLowercase) {
478
+ var m = hour < 12 ? "AM" : "PM";
479
+ return isLowercase ? m.toLowerCase() : m;
480
+ };
481
+ var matches = function matches2(match) {
482
+ switch (match) {
483
+ case "YY":
484
+ return String(_this3.$y).slice(-2);
485
+ case "YYYY":
486
+ return Utils.s(_this3.$y, 4, "0");
487
+ case "M":
488
+ return $M + 1;
489
+ case "MM":
490
+ return Utils.s($M + 1, 2, "0");
491
+ case "MMM":
492
+ return getShort(locale.monthsShort, $M, months, 3);
493
+ case "MMMM":
494
+ return getShort(months, $M);
495
+ case "D":
496
+ return _this3.$D;
497
+ case "DD":
498
+ return Utils.s(_this3.$D, 2, "0");
499
+ case "d":
500
+ return String(_this3.$W);
501
+ case "dd":
502
+ return getShort(locale.weekdaysMin, _this3.$W, weekdays, 2);
503
+ case "ddd":
504
+ return getShort(locale.weekdaysShort, _this3.$W, weekdays, 3);
505
+ case "dddd":
506
+ return weekdays[_this3.$W];
507
+ case "H":
508
+ return String($H);
509
+ case "HH":
510
+ return Utils.s($H, 2, "0");
511
+ case "h":
512
+ return get$H(1);
513
+ case "hh":
514
+ return get$H(2);
515
+ case "a":
516
+ return meridiemFunc($H, $m, true);
517
+ case "A":
518
+ return meridiemFunc($H, $m, false);
519
+ case "m":
520
+ return String($m);
521
+ case "mm":
522
+ return Utils.s($m, 2, "0");
523
+ case "s":
524
+ return String(_this3.$s);
525
+ case "ss":
526
+ return Utils.s(_this3.$s, 2, "0");
527
+ case "SSS":
528
+ return Utils.s(_this3.$ms, 3, "0");
529
+ case "Z":
530
+ return zoneStr;
531
+ }
532
+ return null;
533
+ };
534
+ return str.replace(REGEX_FORMAT, function(match, $1) {
535
+ return $1 || matches(match) || zoneStr.replace(":", "");
536
+ });
537
+ };
538
+ _proto.utcOffset = function utcOffset() {
539
+ return -Math.round(this.$d.getTimezoneOffset() / 15) * 15;
540
+ };
541
+ _proto.diff = function diff(input, units, _float) {
542
+ var _this4 = this;
543
+ var unit = Utils.p(units);
544
+ var that = dayjs(input);
545
+ var zoneDelta = (that.utcOffset() - this.utcOffset()) * MILLISECONDS_A_MINUTE;
546
+ var diff2 = this - that;
547
+ var getMonth = function getMonth2() {
548
+ return Utils.m(_this4, that);
549
+ };
550
+ var result;
551
+ switch (unit) {
552
+ case Y:
553
+ result = getMonth() / 12;
554
+ break;
555
+ case M:
556
+ result = getMonth();
557
+ break;
558
+ case Q:
559
+ result = getMonth() / 3;
560
+ break;
561
+ case W:
562
+ result = (diff2 - zoneDelta) / MILLISECONDS_A_WEEK;
563
+ break;
564
+ case D:
565
+ result = (diff2 - zoneDelta) / MILLISECONDS_A_DAY;
566
+ break;
567
+ case H:
568
+ result = diff2 / MILLISECONDS_A_HOUR;
569
+ break;
570
+ case MIN:
571
+ result = diff2 / MILLISECONDS_A_MINUTE;
572
+ break;
573
+ case S:
574
+ result = diff2 / MILLISECONDS_A_SECOND;
575
+ break;
576
+ default:
577
+ result = diff2;
578
+ break;
579
+ }
580
+ return _float ? result : Utils.a(result);
581
+ };
582
+ _proto.daysInMonth = function daysInMonth() {
583
+ return this.endOf(M).$D;
584
+ };
585
+ _proto.$locale = function $locale() {
586
+ return Ls[this.$L];
587
+ };
588
+ _proto.locale = function locale(preset, object) {
589
+ if (!preset) return this.$L;
590
+ var that = this.clone();
591
+ var nextLocaleName = parseLocale(preset, object, true);
592
+ if (nextLocaleName) that.$L = nextLocaleName;
593
+ return that;
594
+ };
595
+ _proto.clone = function clone() {
596
+ return Utils.w(this.$d, this);
597
+ };
598
+ _proto.toDate = function toDate() {
599
+ return new Date(this.valueOf());
600
+ };
601
+ _proto.toJSON = function toJSON() {
602
+ return this.isValid() ? this.toISOString() : null;
603
+ };
604
+ _proto.toISOString = function toISOString() {
605
+ return this.$d.toISOString();
606
+ };
607
+ _proto.toString = function toString() {
608
+ return this.$d.toUTCString();
609
+ };
610
+ return Dayjs2;
611
+ })();
612
+ var proto = Dayjs.prototype;
613
+ dayjs.prototype = proto;
614
+ [["$ms", MS], ["$s", S], ["$m", MIN], ["$H", H], ["$W", D], ["$M", M], ["$y", Y], ["$D", DATE]].forEach(function(g) {
615
+ proto[g[1]] = function(input) {
616
+ return this.$g(input, g[0], g[1]);
617
+ };
618
+ });
619
+ dayjs.extend = function(plugin, option) {
620
+ if (!plugin.$i) {
621
+ plugin(option, Dayjs, dayjs);
622
+ plugin.$i = true;
623
+ }
624
+ return dayjs;
625
+ };
626
+ dayjs.locale = parseLocale;
627
+ dayjs.isDayjs = isDayjs;
628
+ dayjs.unix = function(timestamp) {
629
+ return dayjs(timestamp * 1e3);
630
+ };
631
+ dayjs.en = Ls[L];
632
+ dayjs.Ls = Ls;
633
+ dayjs.p = {};
634
+ var esm_default = dayjs;
635
+
636
+ // src/system-root.ts
637
+ var TEMPLATE_ROOT_NAMES = ["scope", "system"];
638
+ var SYSTEM_TIME_METHOD_NAMES = [
639
+ "add",
640
+ "subtract",
641
+ "set",
642
+ "get",
643
+ "millisecond",
644
+ "second",
645
+ "minute",
646
+ "hour",
647
+ "date",
648
+ "day",
649
+ "weekday",
650
+ "isoWeekday",
651
+ "dayOfYear",
652
+ "week",
653
+ "isoWeek",
654
+ "month",
655
+ "quarter",
656
+ "year",
657
+ "weekYear",
658
+ "isoWeekYear",
659
+ "startOf",
660
+ "endOf",
661
+ "format",
662
+ "fromNow",
663
+ "toNow",
664
+ "from",
665
+ "to",
666
+ "calendar",
667
+ "diff",
668
+ "valueOf",
669
+ "unix",
670
+ "daysInMonth",
671
+ "toDate",
672
+ "toArray",
673
+ "toJSON",
674
+ "toISOString",
675
+ "toObject",
676
+ "toString",
677
+ "isBefore",
678
+ "isSame",
679
+ "isAfter",
680
+ "isSameOrBefore",
681
+ "isSameOrAfter",
682
+ "isBetween",
683
+ "isLeapYear",
684
+ "isValid",
685
+ "clone",
686
+ "locale",
687
+ "utcOffset",
688
+ "local",
689
+ "utc",
690
+ "isUTC"
691
+ ];
692
+ var SYSTEM_MATH_KEYS = [
693
+ "E",
694
+ "LN10",
695
+ "LN2",
696
+ "LOG10E",
697
+ "LOG2E",
698
+ "PI",
699
+ "SQRT1_2",
700
+ "SQRT2",
701
+ "abs",
702
+ "acos",
703
+ "acosh",
704
+ "asin",
705
+ "asinh",
706
+ "atan",
707
+ "atan2",
708
+ "atanh",
709
+ "cbrt",
710
+ "ceil",
711
+ "clz32",
712
+ "cos",
713
+ "cosh",
714
+ "exp",
715
+ "expm1",
716
+ "floor",
717
+ "fround",
718
+ "hypot",
719
+ "imul",
720
+ "log",
721
+ "log10",
722
+ "log1p",
723
+ "log2",
724
+ "max",
725
+ "min",
726
+ "pow",
727
+ "random",
728
+ "round",
729
+ "sign",
730
+ "sin",
731
+ "sinh",
732
+ "sqrt",
733
+ "tan",
734
+ "tanh",
735
+ "trunc"
736
+ ];
737
+ var SYSTEM_LOCATION_KEYS = [
738
+ "href",
739
+ "protocol",
740
+ "host",
741
+ "hostname",
742
+ "port",
743
+ "pathname",
744
+ "search",
745
+ "hash",
746
+ "origin",
747
+ "ancestorOrigins",
748
+ "assign",
749
+ "reload",
750
+ "replace",
751
+ "toString"
752
+ ];
753
+ function createLocationStub() {
754
+ return {
755
+ href: "",
756
+ protocol: "",
757
+ host: "",
758
+ hostname: "",
759
+ port: "",
760
+ pathname: "",
761
+ search: "",
762
+ hash: "",
763
+ origin: "",
764
+ assign() {
765
+ },
766
+ reload() {
767
+ },
768
+ replace() {
769
+ },
770
+ toString() {
771
+ return "";
772
+ }
773
+ };
774
+ }
775
+ function createSystemRoot() {
776
+ const locationValue = typeof globalThis !== "undefined" && "location" in globalThis && globalThis.location ? globalThis.location : createLocationStub();
777
+ return {
778
+ time: esm_default(),
779
+ math: Math,
780
+ location: locationValue
781
+ };
782
+ }
783
+ function getSystemAutocompleteTree() {
784
+ const timeMethods = {};
785
+ for (const name of SYSTEM_TIME_METHOD_NAMES) {
786
+ timeMethods[name] = /* @__PURE__ */ Object.create(null);
787
+ }
788
+ const mathKeys = {};
789
+ for (const name of SYSTEM_MATH_KEYS) {
790
+ mathKeys[name] = /* @__PURE__ */ Object.create(null);
791
+ }
792
+ const locationKeys = {};
793
+ for (const name of SYSTEM_LOCATION_KEYS) {
794
+ locationKeys[name] = /* @__PURE__ */ Object.create(null);
795
+ }
796
+ return {
797
+ time: timeMethods,
798
+ math: mathKeys,
799
+ location: locationKeys
800
+ };
801
+ }
802
+ function isDayjsValue(value) {
803
+ return esm_default.isDayjs(value);
804
+ }
805
+
161
806
  // src/scope-template.ts
162
- var SCOPE_TOKEN_RE = /\{(scope[^}]*)\}/g;
807
+ var TEMPLATE_TOKEN_RE = /\{((?:scope|system)[^}]*)\}/g;
163
808
  function hasScopeTemplate(value) {
164
- SCOPE_TOKEN_RE.lastIndex = 0;
165
- return SCOPE_TOKEN_RE.test(value);
809
+ TEMPLATE_TOKEN_RE.lastIndex = 0;
810
+ return TEMPLATE_TOKEN_RE.test(value);
166
811
  }
167
- function evaluateScopeExpression(expression, scope) {
812
+ var hasTemplateExpression = hasScopeTemplate;
813
+ function evaluateScopeExpression(expression, scope, system = createSystemRoot()) {
168
814
  const trimmed = expression.trim();
169
815
  if (!trimmed) return void 0;
170
816
  try {
171
- const fn = new Function("scope", `"use strict"; return (${trimmed});`);
172
- return fn(scope);
817
+ const fn = new Function(
818
+ "scope",
819
+ "system",
820
+ `"use strict"; return (${trimmed});`
821
+ );
822
+ return fn(scope, system);
173
823
  } catch {
174
824
  return void 0;
175
825
  }
@@ -180,6 +830,9 @@ function stringifyScopeValue(value) {
180
830
  if (typeof value === "number" || typeof value === "boolean") {
181
831
  return String(value);
182
832
  }
833
+ if (isDayjsValue(value)) {
834
+ return value.toISOString();
835
+ }
183
836
  try {
184
837
  return JSON.stringify(value);
185
838
  } catch {
@@ -206,24 +859,30 @@ function isInsideJsonString(before) {
206
859
  }
207
860
  return inString;
208
861
  }
209
- function replaceScopeTokens(template, scope, replacer) {
210
- SCOPE_TOKEN_RE.lastIndex = 0;
862
+ function replaceTemplateTokens(template, scope, system, replacer) {
863
+ TEMPLATE_TOKEN_RE.lastIndex = 0;
211
864
  return template.replace(
212
- SCOPE_TOKEN_RE,
213
- (_match, rawExpr, offset) => replacer(evaluateScopeExpression(rawExpr, scope), offset)
865
+ TEMPLATE_TOKEN_RE,
866
+ (_match, rawExpr, offset) => replacer(evaluateScopeExpression(rawExpr, scope, system), offset)
214
867
  );
215
868
  }
216
- function evaluateScopeTemplate(template, scope) {
869
+ function evaluateScopeTemplate(template, scope, system = createSystemRoot()) {
217
870
  if (!hasScopeTemplate(template)) return template;
218
- return replaceScopeTokens(template, scope, (value) => stringifyScopeValue(value));
871
+ return replaceTemplateTokens(
872
+ template,
873
+ scope,
874
+ system,
875
+ (value) => stringifyScopeValue(value)
876
+ );
219
877
  }
220
- function evaluateScopeTemplateInJson(template, scope) {
878
+ function evaluateScopeTemplateInJson(template, scope, system = createSystemRoot()) {
221
879
  if (!hasScopeTemplate(template)) return template;
222
- return replaceScopeTokens(template, scope, (value, offset) => {
880
+ return replaceTemplateTokens(template, scope, system, (value, offset) => {
223
881
  if (isInsideJsonString(template.slice(0, offset))) {
224
882
  return JSON.stringify(stringifyScopeValue(value)).slice(1, -1);
225
883
  }
226
884
  if (value === void 0) return "null";
885
+ if (isDayjsValue(value)) return JSON.stringify(value.toISOString());
227
886
  return JSON.stringify(value);
228
887
  });
229
888
  }
@@ -231,6 +890,9 @@ function looksLikeJsonText(text) {
231
890
  const trimmed = text.trim();
232
891
  return trimmed.startsWith("{") || trimmed.startsWith("[");
233
892
  }
893
+ function preserveTemplateTokensInEncode(value) {
894
+ return hasScopeTemplate(value);
895
+ }
234
896
 
235
897
  // src/fetch-config.ts
236
898
  var FETCH_HTTP_METHODS = [
@@ -275,7 +937,8 @@ function normalizeFetchRequestConfig(config) {
275
937
  ...config?.headers
276
938
  },
277
939
  headersJson: config?.headersJson,
278
- swaggerEndpoints: config?.swaggerEndpoints
940
+ swaggerEndpoints: config?.swaggerEndpoints,
941
+ apiCollectionSyncNotice: config?.apiCollectionSyncNotice
279
942
  };
280
943
  }
281
944
  function joinFetchUrl(base, path) {
@@ -423,8 +1086,8 @@ async function executeFetch(config, options) {
423
1086
  }
424
1087
 
425
1088
  // src/scope-autocomplete.ts
426
- function getValueAtPath(scope, path) {
427
- let current = scope;
1089
+ function getValueAtPath(root, path) {
1090
+ let current = root;
428
1091
  for (const part of path) {
429
1092
  if (current === null || typeof current !== "object") return void 0;
430
1093
  current = current[part];
@@ -437,63 +1100,193 @@ function listObjectKeys(value) {
437
1100
  }
438
1101
  return Object.keys(value);
439
1102
  }
1103
+ function matchRootPrefix(inner) {
1104
+ if (!inner) return "partial";
1105
+ for (const name of TEMPLATE_ROOT_NAMES) {
1106
+ if (inner === name) return name;
1107
+ if (name.startsWith(inner) && !inner.includes("?") && !inner.includes(".")) {
1108
+ return "partial";
1109
+ }
1110
+ }
1111
+ return null;
1112
+ }
1113
+ function splitPathBody(body) {
1114
+ let depth = 0;
1115
+ let current = "";
1116
+ const segments = [];
1117
+ let i = 0;
1118
+ while (i < body.length) {
1119
+ const ch = body[i];
1120
+ if (ch === "(" || ch === "[" || ch === "{") {
1121
+ depth += 1;
1122
+ current += ch;
1123
+ i += 1;
1124
+ continue;
1125
+ }
1126
+ if (ch === ")" || ch === "]" || ch === "}") {
1127
+ depth = Math.max(0, depth - 1);
1128
+ current += ch;
1129
+ i += 1;
1130
+ continue;
1131
+ }
1132
+ if (depth > 0) {
1133
+ current += ch;
1134
+ i += 1;
1135
+ continue;
1136
+ }
1137
+ if (body.startsWith("?.", i)) {
1138
+ segments.push(current);
1139
+ current = "";
1140
+ i += 2;
1141
+ continue;
1142
+ }
1143
+ if (ch === ".") {
1144
+ segments.push(current);
1145
+ current = "";
1146
+ i += 1;
1147
+ continue;
1148
+ }
1149
+ current += ch;
1150
+ i += 1;
1151
+ }
1152
+ if (depth > 0) return null;
1153
+ const endsWithSeparator = body.endsWith("?.") || body.endsWith(".") && !body.endsWith("?.") && !body.endsWith("..");
1154
+ if (endsWithSeparator) {
1155
+ const path = segments.map((s) => stripCallSuffix(s)).filter((s) => s.length > 0);
1156
+ return { segments: path, endsWithSeparator: true, partialOrComplete: "" };
1157
+ }
1158
+ const cleaned = segments.map((s) => stripCallSuffix(s)).filter((s) => s.length > 0);
1159
+ const lastRaw = current;
1160
+ const lastClean = stripCallSuffix(lastRaw);
1161
+ if (lastRaw.includes("(") && lastRaw.endsWith(")")) {
1162
+ return {
1163
+ segments: [...cleaned, lastClean].filter(Boolean),
1164
+ endsWithSeparator: false,
1165
+ partialOrComplete: lastClean
1166
+ };
1167
+ }
1168
+ return {
1169
+ segments: cleaned,
1170
+ endsWithSeparator: false,
1171
+ partialOrComplete: lastClean
1172
+ };
1173
+ }
1174
+ function stripCallSuffix(segment) {
1175
+ const idx = segment.indexOf("(");
1176
+ if (idx < 0) return segment.trim();
1177
+ return segment.slice(0, idx).trim();
1178
+ }
440
1179
  function parseScopeAutocomplete(text, cursor, scope) {
441
1180
  const before = text.slice(0, cursor);
442
1181
  const templateStart = before.lastIndexOf("{");
443
1182
  if (templateStart < 0) return null;
444
1183
  const inner = before.slice(templateStart + 1);
445
1184
  if (inner.includes("}")) return null;
446
- if (!inner.startsWith("scope")) return null;
447
- let body = inner.slice("scope".length);
448
- if (body === "" || body === "?") {
449
- return { templateStart, cursor, path: [], partialKey: "" };
1185
+ const rootMatch = matchRootPrefix(inner);
1186
+ if (rootMatch === "partial" || rootMatch && !inner.includes("?") && !inner.includes(".")) {
1187
+ if (!inner.includes("?") && !inner.includes(".") && !inner.includes("(")) {
1188
+ return {
1189
+ templateStart,
1190
+ cursor,
1191
+ suggestingRoot: true,
1192
+ root: typeof rootMatch === "string" && rootMatch !== "partial" ? rootMatch : null,
1193
+ path: [],
1194
+ partialKey: inner
1195
+ };
1196
+ }
450
1197
  }
451
- if (!body.startsWith("?.")) return null;
452
- body = body.slice(2);
453
- if (body === "") {
454
- return { templateStart, cursor, path: [], partialKey: "" };
1198
+ let root = null;
1199
+ let body = "";
1200
+ if (inner.startsWith("scope")) {
1201
+ root = "scope";
1202
+ body = inner.slice("scope".length);
1203
+ } else if (inner.startsWith("system")) {
1204
+ root = "system";
1205
+ body = inner.slice("system".length);
1206
+ } else {
1207
+ return null;
455
1208
  }
456
- const segments = body.split("?.");
457
- const endsWithSeparator = inner.endsWith("?.");
458
- if (endsWithSeparator) {
459
- const path = segments.filter((segment) => segment.length > 0);
460
- return { templateStart, cursor, path, partialKey: "" };
1209
+ if (body === "" || body === "?") {
1210
+ return {
1211
+ templateStart,
1212
+ cursor,
1213
+ suggestingRoot: false,
1214
+ root,
1215
+ path: [],
1216
+ partialKey: ""
1217
+ };
461
1218
  }
462
- const lastSegment = segments[segments.length - 1] ?? "";
463
- const prefixSegments = segments.slice(0, -1).filter((segment) => segment.length > 0);
464
- const parent = getValueAtPath(scope, prefixSegments);
465
- const keys = listObjectKeys(parent);
466
- if (lastSegment.length === 0) {
467
- return { templateStart, cursor, path: prefixSegments, partialKey: "" };
1219
+ if (body.startsWith("?.")) {
1220
+ body = body.slice(2);
1221
+ } else if (body.startsWith(".")) {
1222
+ body = body.slice(1);
1223
+ } else {
1224
+ return null;
1225
+ }
1226
+ if (body === "") {
1227
+ return {
1228
+ templateStart,
1229
+ cursor,
1230
+ suggestingRoot: false,
1231
+ root,
1232
+ path: [],
1233
+ partialKey: ""
1234
+ };
468
1235
  }
469
- if (keys.includes(lastSegment)) {
1236
+ const split = splitPathBody(body);
1237
+ if (!split) return null;
1238
+ if (split.endsWithSeparator) {
470
1239
  return {
471
1240
  templateStart,
472
1241
  cursor,
473
- path: [...prefixSegments, lastSegment],
1242
+ suggestingRoot: false,
1243
+ root,
1244
+ path: split.segments,
474
1245
  partialKey: ""
475
1246
  };
476
1247
  }
1248
+ const lastSegment = split.partialOrComplete;
1249
+ const prefixSegments = split.segments;
477
1250
  return {
478
1251
  templateStart,
479
1252
  cursor,
1253
+ suggestingRoot: false,
1254
+ root,
480
1255
  path: prefixSegments,
481
1256
  partialKey: lastSegment
482
1257
  };
483
1258
  }
1259
+ function resolveAutocompleteRoot(state, scope) {
1260
+ if (state.root === "system") return getSystemAutocompleteTree();
1261
+ return scope;
1262
+ }
484
1263
  function getScopeAutocompleteSuggestions(scope, state) {
485
- const parent = state.partialKey.length > 0 ? getValueAtPath(scope, state.path) : state.path.length > 0 ? getValueAtPath(scope, state.path) : scope;
486
- const keys = listObjectKeys(parent);
1264
+ if (state.suggestingRoot) {
1265
+ return TEMPLATE_ROOT_NAMES.filter(
1266
+ (name) => name.startsWith(state.partialKey)
1267
+ );
1268
+ }
1269
+ const dataRoot = resolveAutocompleteRoot(state, scope);
1270
+ if (dataRoot === void 0 || dataRoot === null) return [];
1271
+ const parent = state.path.length > 0 ? getValueAtPath(dataRoot, state.path) : dataRoot;
1272
+ let keys = listObjectKeys(parent);
487
1273
  if (state.partialKey.length === 0) return keys;
488
- return keys.filter((key) => key.startsWith(state.partialKey));
1274
+ keys = keys.filter((key) => key.startsWith(state.partialKey));
1275
+ return keys;
489
1276
  }
490
- function buildScopeExpression(path, selectedKey) {
491
- return `scope?.${[...path, selectedKey].join("?.")}`;
1277
+ function buildScopeExpression(path, selectedKey, root = "scope") {
1278
+ return `${root}?.${[...path, selectedKey].join("?.")}`;
492
1279
  }
493
1280
  function applyScopeAutocompleteSelection(text, state, selectedKey) {
494
- const expr = buildScopeExpression(state.path, selectedKey);
495
1281
  const before = text.slice(0, state.templateStart + 1);
496
1282
  const after = text.slice(state.cursor);
1283
+ let expr;
1284
+ if (state.suggestingRoot) {
1285
+ expr = `${selectedKey}?.`;
1286
+ } else {
1287
+ const root = state.root ?? "scope";
1288
+ expr = buildScopeExpression(state.path, selectedKey, root);
1289
+ }
497
1290
  const value = `${before}${expr}${after}`;
498
1291
  const cursor = before.length + expr.length;
499
1292
  return { value, cursor };
@@ -654,13 +1447,13 @@ function resolveFetchBody(body, scope) {
654
1447
  if (body === void 0) return void 0;
655
1448
  const trimmed = body.trim();
656
1449
  if (!trimmed) return body;
657
- if (scope !== void 0 && isWholeScopeExpression(trimmed)) {
1450
+ if (isWholeScopeExpression(trimmed)) {
658
1451
  const value = evaluateScopeExpression(trimmed.slice(1, -1), scope);
659
1452
  if (value === void 0) return "";
660
1453
  if (typeof value === "string") return value;
661
1454
  return stringifyScopeValue(value);
662
1455
  }
663
- if (scope === void 0 || !hasScopeTemplate(body)) return body;
1456
+ if (!hasScopeTemplate(body)) return body;
664
1457
  if (looksLikeJsonText(trimmed)) {
665
1458
  return evaluateScopeTemplateInJson(body, scope);
666
1459
  }
@@ -694,7 +1487,8 @@ function getFetchHeadersValidationError(config, scope) {
694
1487
  function isWholeScopeExpression(text) {
695
1488
  const trimmed = text.trim();
696
1489
  if (!trimmed.startsWith("{") || !trimmed.endsWith("}")) return false;
697
- return trimmed.slice(1, -1).trim().startsWith("scope");
1490
+ const inner = trimmed.slice(1, -1).trim();
1491
+ return inner.startsWith("scope") || inner.startsWith("system");
698
1492
  }
699
1493
  function asHeaderRecord(value) {
700
1494
  if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
@@ -706,7 +1500,6 @@ function asHeaderRecord(value) {
706
1500
  return headers;
707
1501
  }
708
1502
  function applyScopeToHeaderRecord(headers, scope) {
709
- if (scope === void 0) return headers;
710
1503
  return Object.fromEntries(
711
1504
  Object.entries(headers).map(([key, value]) => [
712
1505
  evaluateScopeTemplate(String(key), scope),
@@ -718,12 +1511,11 @@ function parseFetchHeadersJson(text, scope) {
718
1511
  const trimmed = text.trim();
719
1512
  if (!trimmed) return {};
720
1513
  if (isWholeScopeExpression(trimmed)) {
721
- if (scope === void 0) return void 0;
722
1514
  const inner = trimmed.slice(1, -1);
723
1515
  return asHeaderRecord(evaluateScopeExpression(inner, scope));
724
1516
  }
725
1517
  let jsonText = trimmed;
726
- if (scope !== void 0 && hasScopeTemplate(trimmed) && looksLikeJsonText(trimmed)) {
1518
+ if (hasScopeTemplate(trimmed) && looksLikeJsonText(trimmed)) {
727
1519
  jsonText = evaluateScopeTemplateInJson(trimmed, scope);
728
1520
  }
729
1521
  try {
@@ -757,14 +1549,15 @@ function resolveFetchHeaders(config, scope) {
757
1549
  function applyFetchConfigScope(config, scope) {
758
1550
  const headers = resolveFetchHeaders(config, scope);
759
1551
  const body = resolveFetchBody(config.body, scope);
760
- if (scope === void 0) {
761
- if (headers === config.headers && body === config.body) return config;
762
- return { ...config, headers, body };
1552
+ const url = resolveTemplateString(config.url, scope) ?? "";
1553
+ const apiBaseUrl = resolveTemplateString(config.apiBaseUrl, scope);
1554
+ if (url === (config.url ?? "") && apiBaseUrl === config.apiBaseUrl && headers === config.headers && body === config.body) {
1555
+ return config;
763
1556
  }
764
1557
  return {
765
1558
  ...config,
766
- url: resolveTemplateString(config.url, scope) ?? "",
767
- apiBaseUrl: resolveTemplateString(config.apiBaseUrl, scope),
1559
+ url,
1560
+ apiBaseUrl,
768
1561
  body,
769
1562
  headers
770
1563
  };
@@ -780,30 +1573,322 @@ function fetchConfigHasScopeTemplate(config) {
780
1573
  );
781
1574
  }
782
1575
 
783
- // src/json-config.ts
784
- var DEFAULT_JSON_NODE_CONFIG = {
785
- jsonString: "{}"
786
- };
787
- function validateJsonString(jsonString) {
788
- const raw = jsonString?.trim();
789
- if (!raw) {
790
- return { ok: false, error: "JSON \u4E0D\u80FD\u4E3A\u7A7A" };
1576
+ // src/json-lint.ts
1577
+ var SUSPECT_CHAR_RE = /[\u201C\u201D\u2018\u2019\u300C\u300D\u300E\u300F\uFF0C\uFF1A\uFF1B\u3010\u3011\uFF08\uFF09\uFF01\uFF1F\u3001\u3002]/gu;
1578
+ function lineColToOffset(text, line, column) {
1579
+ const lines = text.split("\n");
1580
+ let offset = 0;
1581
+ const targetLine = Math.max(1, line) - 1;
1582
+ for (let i = 0; i < targetLine && i < lines.length; i += 1) {
1583
+ offset += lines[i].length + 1;
1584
+ }
1585
+ const col = Math.max(1, column) - 1;
1586
+ const lineText = lines[targetLine] ?? "";
1587
+ return offset + Math.min(col, lineText.length);
1588
+ }
1589
+ function extractJsonErrorPosition(message, text) {
1590
+ let match = /position\s+(\d+)/i.exec(message);
1591
+ if (match) {
1592
+ const pos = Number(match[1]);
1593
+ if (Number.isFinite(pos) && pos >= 0) {
1594
+ return Math.min(pos, Math.max(0, text.length - 1));
1595
+ }
1596
+ }
1597
+ match = /line\s+(\d+)\s+column\s+(\d+)/i.exec(message);
1598
+ if (match) {
1599
+ const pos = lineColToOffset(text, Number(match[1]), Number(match[2]));
1600
+ return Math.min(pos, Math.max(0, text.length - 1));
791
1601
  }
1602
+ match = /\bat\s+(\d+):(\d+)\b/.exec(message);
1603
+ if (match) {
1604
+ const pos = lineColToOffset(text, Number(match[1]), Number(match[2]));
1605
+ return Math.min(pos, Math.max(0, text.length - 1));
1606
+ }
1607
+ return null;
1608
+ }
1609
+ function findJsonSyntaxErrorOffset(text) {
1610
+ const src = text;
1611
+ const len = src.length;
1612
+ let i = 0;
1613
+ const peek = () => i < len ? src[i] : "";
1614
+ const fail = () => i < len ? i : Math.max(0, len - 1);
1615
+ const skipWs = () => {
1616
+ while (i < len && /[ \t\r\n]/.test(src[i])) i += 1;
1617
+ };
1618
+ const parseString = () => {
1619
+ if (peek() !== '"') return false;
1620
+ i += 1;
1621
+ while (i < len) {
1622
+ const c = src[i];
1623
+ if (c === '"') {
1624
+ i += 1;
1625
+ return true;
1626
+ }
1627
+ if (c === "\\") {
1628
+ i += 1;
1629
+ if (i >= len) return false;
1630
+ i += 1;
1631
+ continue;
1632
+ }
1633
+ i += 1;
1634
+ }
1635
+ return false;
1636
+ };
1637
+ const parseNumber = () => {
1638
+ const start = i;
1639
+ if (peek() === "-") i += 1;
1640
+ if (peek() === "0") {
1641
+ i += 1;
1642
+ } else if (/[1-9]/.test(peek())) {
1643
+ while (/[0-9]/.test(peek())) i += 1;
1644
+ } else {
1645
+ i = start;
1646
+ return false;
1647
+ }
1648
+ if (peek() === ".") {
1649
+ i += 1;
1650
+ if (!/[0-9]/.test(peek())) {
1651
+ return false;
1652
+ }
1653
+ while (/[0-9]/.test(peek())) i += 1;
1654
+ }
1655
+ if (peek() === "e" || peek() === "E") {
1656
+ i += 1;
1657
+ if (peek() === "+" || peek() === "-") i += 1;
1658
+ if (!/[0-9]/.test(peek())) return false;
1659
+ while (/[0-9]/.test(peek())) i += 1;
1660
+ }
1661
+ return i > start;
1662
+ };
1663
+ const parseLiteral = (word) => {
1664
+ if (src.startsWith(word, i)) {
1665
+ i += word.length;
1666
+ return true;
1667
+ }
1668
+ return false;
1669
+ };
1670
+ const parseValue = () => {
1671
+ skipWs();
1672
+ if (i >= len) return false;
1673
+ const c = peek();
1674
+ if (c === "{") return parseObject();
1675
+ if (c === "[") return parseArray();
1676
+ if (c === '"') return parseString();
1677
+ if (c === "-" || /[0-9]/.test(c)) return parseNumber();
1678
+ if (parseLiteral("true") || parseLiteral("false") || parseLiteral("null")) {
1679
+ return true;
1680
+ }
1681
+ return false;
1682
+ };
1683
+ const parseObject = () => {
1684
+ if (peek() !== "{") return false;
1685
+ i += 1;
1686
+ skipWs();
1687
+ if (peek() === "}") {
1688
+ i += 1;
1689
+ return true;
1690
+ }
1691
+ while (i < len) {
1692
+ skipWs();
1693
+ if (peek() !== '"') return false;
1694
+ if (!parseString()) return false;
1695
+ skipWs();
1696
+ if (peek() !== ":") return false;
1697
+ i += 1;
1698
+ if (!parseValue()) return false;
1699
+ skipWs();
1700
+ if (peek() === ",") {
1701
+ i += 1;
1702
+ skipWs();
1703
+ if (peek() === "}" || i >= len) return false;
1704
+ continue;
1705
+ }
1706
+ if (peek() === "}") {
1707
+ i += 1;
1708
+ return true;
1709
+ }
1710
+ return false;
1711
+ }
1712
+ return false;
1713
+ };
1714
+ const parseArray = () => {
1715
+ if (peek() !== "[") return false;
1716
+ i += 1;
1717
+ skipWs();
1718
+ if (peek() === "]") {
1719
+ i += 1;
1720
+ return true;
1721
+ }
1722
+ while (i < len) {
1723
+ if (!parseValue()) return false;
1724
+ skipWs();
1725
+ if (peek() === ",") {
1726
+ i += 1;
1727
+ skipWs();
1728
+ if (peek() === "]" || i >= len) return false;
1729
+ continue;
1730
+ }
1731
+ if (peek() === "]") {
1732
+ i += 1;
1733
+ return true;
1734
+ }
1735
+ return false;
1736
+ }
1737
+ return false;
1738
+ };
1739
+ skipWs();
1740
+ if (i >= len) return 0;
1741
+ if (!parseValue()) return fail();
1742
+ skipWs();
1743
+ if (i < len) return i;
1744
+ return null;
1745
+ }
1746
+ function expandAround(text, pos) {
1747
+ const len = text.length;
1748
+ if (len === 0) return { start: 0, end: 0, kind: "parse" };
1749
+ const clamped = Math.max(0, Math.min(pos, len - 1));
1750
+ const ch = text[clamped];
1751
+ SUSPECT_CHAR_RE.lastIndex = 0;
1752
+ if (SUSPECT_CHAR_RE.test(ch)) {
1753
+ let start = clamped;
1754
+ let end = clamped + 1;
1755
+ while (start > 0) {
1756
+ SUSPECT_CHAR_RE.lastIndex = 0;
1757
+ if (!SUSPECT_CHAR_RE.test(text[start - 1])) break;
1758
+ start -= 1;
1759
+ }
1760
+ while (end < len) {
1761
+ SUSPECT_CHAR_RE.lastIndex = 0;
1762
+ if (!SUSPECT_CHAR_RE.test(text[end])) break;
1763
+ end += 1;
1764
+ }
1765
+ return { start, end, kind: "parse" };
1766
+ }
1767
+ const isTokenChar = (c) => /[A-Za-z0-9_$.+\-]/.test(c);
1768
+ if (isTokenChar(ch)) {
1769
+ let start = clamped;
1770
+ let end = clamped + 1;
1771
+ while (start > 0 && isTokenChar(text[start - 1])) start -= 1;
1772
+ while (end < len && isTokenChar(text[end])) end += 1;
1773
+ return { start, end, kind: "parse" };
1774
+ }
1775
+ return { start: clamped, end: clamped + 1, kind: "parse" };
1776
+ }
1777
+ function findSuspectCharRanges(text) {
1778
+ const ranges = [];
1779
+ SUSPECT_CHAR_RE.lastIndex = 0;
1780
+ let match;
1781
+ while ((match = SUSPECT_CHAR_RE.exec(text)) !== null) {
1782
+ ranges.push({
1783
+ start: match.index,
1784
+ end: match.index + match[0].length,
1785
+ kind: "suspect"
1786
+ });
1787
+ }
1788
+ return ranges;
1789
+ }
1790
+ function mergeRanges(ranges) {
1791
+ if (ranges.length === 0) return [];
1792
+ const sorted = [...ranges].sort((a, b) => a.start - b.start || a.end - b.end);
1793
+ const out = [];
1794
+ for (const range of sorted) {
1795
+ const last = out[out.length - 1];
1796
+ if (!last || range.start > last.end) {
1797
+ out.push({ ...range });
1798
+ continue;
1799
+ }
1800
+ last.end = Math.max(last.end, range.end);
1801
+ if (last.kind === "parse" || range.kind === "parse") last.kind = "parse";
1802
+ }
1803
+ return out;
1804
+ }
1805
+ function lintJsonString(jsonString) {
1806
+ const raw = jsonString ?? "";
1807
+ const trimmed = raw.trim();
1808
+ if (!trimmed) {
1809
+ return { ok: false, error: "JSON \u4E0D\u80FD\u4E3A\u7A7A", ranges: [] };
1810
+ }
1811
+ const suspectRanges = findSuspectCharRanges(raw);
1812
+ const trimStart = raw.indexOf(trimmed);
1813
+ const offset = trimStart >= 0 ? trimStart : 0;
792
1814
  try {
793
- const value = JSON.parse(raw);
1815
+ const value = JSON.parse(trimmed);
794
1816
  if (value === null || typeof value !== "object") {
795
- return { ok: false, error: "JSON \u6839\u8282\u70B9\u5FC5\u987B\u662F object \u6216 array" };
1817
+ return {
1818
+ ok: false,
1819
+ error: "JSON \u6839\u8282\u70B9\u5FC5\u987B\u662F object \u6216 array",
1820
+ ranges: mergeRanges(suspectRanges)
1821
+ };
796
1822
  }
797
1823
  return { ok: true, value };
798
1824
  } catch (error) {
1825
+ const message = error instanceof Error ? error.message : "JSON \u683C\u5F0F\u65E0\u6548";
1826
+ const ranges = [...suspectRanges];
1827
+ const fromEngine = extractJsonErrorPosition(message, trimmed);
1828
+ const fromScan = findJsonSyntaxErrorOffset(trimmed);
1829
+ const pos = fromScan ?? fromEngine;
1830
+ if (pos != null) {
1831
+ ranges.push(expandAround(raw, offset + pos));
1832
+ } else if (ranges.length === 0 && raw.length > 0) {
1833
+ const first = raw.search(/\S/);
1834
+ ranges.push(expandAround(raw, first >= 0 ? first : 0));
1835
+ }
799
1836
  return {
800
1837
  ok: false,
801
- error: error instanceof Error ? error.message : "JSON \u683C\u5F0F\u65E0\u6548"
1838
+ error: message,
1839
+ ranges: mergeRanges(ranges)
802
1840
  };
803
1841
  }
804
1842
  }
805
- function parseJsonConfig(config) {
806
- const result = validateJsonString(config.jsonString ?? "");
1843
+ function renderJsonWithErrorHighlights(text, ranges, markClass = "json-lint-error") {
1844
+ const escape = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1845
+ const source = text ?? "";
1846
+ const merged = mergeRanges(
1847
+ ranges.filter((r) => r.end > r.start && r.start < source.length)
1848
+ );
1849
+ if (merged.length === 0) return escape(source) || "\n";
1850
+ let html = "";
1851
+ let cursor = 0;
1852
+ for (const range of merged) {
1853
+ const start = Math.max(0, range.start);
1854
+ const end = Math.min(source.length, range.end);
1855
+ if (start > cursor) html += escape(source.slice(cursor, start));
1856
+ if (end > start) {
1857
+ html += `<mark class="${markClass}">${escape(source.slice(start, end))}</mark>`;
1858
+ }
1859
+ cursor = Math.max(cursor, end);
1860
+ }
1861
+ if (cursor < source.length) html += escape(source.slice(cursor));
1862
+ return html;
1863
+ }
1864
+
1865
+ // src/json-config.ts
1866
+ var DEFAULT_JSON_NODE_CONFIG = {
1867
+ jsonString: "{}"
1868
+ };
1869
+ function validateJsonString(jsonString) {
1870
+ const result = lintJsonString(jsonString);
1871
+ if (!result.ok) {
1872
+ return { ok: false, error: result.error, ranges: result.ranges };
1873
+ }
1874
+ return { ok: true, value: result.value };
1875
+ }
1876
+ function validateJsonStringAllowingScope(jsonString) {
1877
+ const lint = lintJsonString(jsonString ?? "");
1878
+ if (!lint.ok) {
1879
+ return { ok: false, error: lint.error, ranges: lint.ranges };
1880
+ }
1881
+ if (hasScopeTemplate(jsonString ?? "")) {
1882
+ return { ok: true, deferred: true };
1883
+ }
1884
+ return { ok: true, value: lint.value };
1885
+ }
1886
+ function parseJsonConfig(config, scope) {
1887
+ let raw = config.jsonString ?? "";
1888
+ if (hasScopeTemplate(raw)) {
1889
+ raw = evaluateScopeTemplateInJson(raw, scope);
1890
+ }
1891
+ const result = validateJsonString(raw);
807
1892
  if (!result.ok) {
808
1893
  throw new Error(result.error);
809
1894
  }
@@ -860,6 +1945,20 @@ function resolveStorageWriteValue(template, scope) {
860
1945
  }
861
1946
  return raw;
862
1947
  }
1948
+ function resolveStorageKey(key, scope) {
1949
+ const raw = key ?? "";
1950
+ const trimmed = raw.trim();
1951
+ if (!trimmed) return "";
1952
+ if (isWholeScopeExpression(trimmed)) {
1953
+ return stringifyScopeValue(
1954
+ evaluateScopeExpression(trimmed.slice(1, -1), scope)
1955
+ );
1956
+ }
1957
+ if (hasScopeTemplate(raw)) {
1958
+ return evaluateScopeTemplate(raw, scope).trim();
1959
+ }
1960
+ return trimmed;
1961
+ }
863
1962
  function serializeStorageValue(value) {
864
1963
  if (value === void 0 || value === null) return "";
865
1964
  if (typeof value === "string") return value;
@@ -891,6 +1990,35 @@ function getDefaultStorageAccessors() {
891
1990
  return null;
892
1991
  }
893
1992
  }
1993
+ function readBrowserStorageBucket(kind) {
1994
+ if (typeof window === "undefined") return null;
1995
+ try {
1996
+ return kind === "session" ? window.sessionStorage : window.localStorage;
1997
+ } catch {
1998
+ return null;
1999
+ }
2000
+ }
2001
+ function listBrowserStorageKeys(kind) {
2002
+ const kinds = uniqueStorageKinds(Array.isArray(kind) ? kind : [kind]);
2003
+ const keys = /* @__PURE__ */ new Set();
2004
+ for (const next of kinds) {
2005
+ const storage = readBrowserStorageBucket(next);
2006
+ if (!storage) continue;
2007
+ try {
2008
+ for (let i = 0; i < storage.length; i += 1) {
2009
+ const key = storage.key(i);
2010
+ if (typeof key === "string" && key) keys.add(key);
2011
+ }
2012
+ } catch {
2013
+ }
2014
+ }
2015
+ return [...keys].sort((a, b) => a.localeCompare(b));
2016
+ }
2017
+ function filterStorageKeySuggestions(keys, query) {
2018
+ const q = query.trim().toLowerCase();
2019
+ if (!q) return [...keys];
2020
+ return keys.filter((key) => key.toLowerCase().includes(q));
2021
+ }
894
2022
  function requireStorage(accessors, kind) {
895
2023
  const target = kind === "session" ? accessors?.session : accessors?.local;
896
2024
  if (!target) {
@@ -906,7 +2034,10 @@ function executeStorageConfig(config, incomingScope, accessors) {
906
2034
  if (isStorageSetConfigured(normalized)) {
907
2035
  const value = resolveStorageWriteValue(normalized.set.value, incomingScope);
908
2036
  const serialized = serializeStorageValue(value);
909
- const key = normalized.set.key.trim();
2037
+ const key = resolveStorageKey(normalized.set.key, incomingScope);
2038
+ if (!key) {
2039
+ throw new Error("\u5B58\u50A8\u5199\u5165 key \u89E3\u6790\u4E3A\u7A7A");
2040
+ }
910
2041
  for (const kind of normalized.set.storages) {
911
2042
  requireStorage(store, kind).setItem(key, serialized);
912
2043
  }
@@ -914,10 +2045,12 @@ function executeStorageConfig(config, incomingScope, accessors) {
914
2045
  if (!isStorageReadConfigured(normalized)) {
915
2046
  return null;
916
2047
  }
2048
+ const readKey = resolveStorageKey(normalized.read.key, incomingScope);
2049
+ if (!readKey) {
2050
+ return null;
2051
+ }
917
2052
  return deserializeStorageValue(
918
- requireStorage(store, normalized.read.storage).getItem(
919
- normalized.read.key.trim()
920
- )
2053
+ requireStorage(store, normalized.read.storage).getItem(readKey)
921
2054
  );
922
2055
  }
923
2056
 
@@ -1290,16 +2423,16 @@ function parseSwaggerDocument(spec, docsUrl) {
1290
2423
  if (!spec || typeof spec !== "object") {
1291
2424
  throw new Error("Swagger \u6587\u6863\u683C\u5F0F\u65E0\u6548");
1292
2425
  }
1293
- const document = spec;
1294
- if (typeof document.openapi === "string") {
1295
- const parsed = parseOpenApiV3(document, docsUrl);
2426
+ const document2 = spec;
2427
+ if (typeof document2.openapi === "string") {
2428
+ const parsed = parseOpenApiV3(document2, docsUrl);
1296
2429
  if (parsed.endpoints.length === 0) {
1297
2430
  throw new Error("\u672A\u5728 OpenAPI \u6587\u6863\u4E2D\u627E\u5230\u63A5\u53E3");
1298
2431
  }
1299
2432
  return parsed;
1300
2433
  }
1301
- if (document.swagger === "2.0" || document.swagger === 2) {
1302
- const parsed = parseSwaggerV2(document, docsUrl);
2434
+ if (document2.swagger === "2.0" || document2.swagger === 2) {
2435
+ const parsed = parseSwaggerV2(document2, docsUrl);
1303
2436
  if (parsed.endpoints.length === 0) {
1304
2437
  throw new Error("\u672A\u5728 Swagger 2.0 \u6587\u6863\u4E2D\u627E\u5230\u63A5\u53E3");
1305
2438
  }
@@ -1334,6 +2467,329 @@ function filterEndpointSuggestions(suggestions, query) {
1334
2467
  );
1335
2468
  }
1336
2469
 
2470
+ // src/api-collection.ts
2471
+ var API_COLLECTION_DOCUMENT_VERSION = 1;
2472
+ var HTTP_METHOD_SET = new Set(FETCH_HTTP_METHODS);
2473
+ function isPlainStringRecord(value) {
2474
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
2475
+ return Object.values(value).every(
2476
+ (item) => typeof item === "string"
2477
+ );
2478
+ }
2479
+ function normalizeEndpoint(raw, index) {
2480
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
2481
+ return `apis[${index}] \u5FC5\u987B\u662F\u5BF9\u8C61`;
2482
+ }
2483
+ const item = raw;
2484
+ const name = typeof item.name === "string" ? item.name.trim() : "";
2485
+ if (!name) return `apis[${index}].name \u5FC5\u586B\u4E14\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32`;
2486
+ const url = typeof item.url === "string" ? item.url.trim() : "";
2487
+ if (!url) return `apis[${index}].url \u5FC5\u586B\u4E14\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32`;
2488
+ const methodRaw = typeof item.method === "string" ? item.method.trim().toUpperCase() : "";
2489
+ if (!HTTP_METHOD_SET.has(methodRaw)) {
2490
+ return `apis[${index}].method \u5FC5\u987B\u662F ${FETCH_HTTP_METHODS.join(" / ")} \u4E4B\u4E00`;
2491
+ }
2492
+ if (item.params !== void 0 && !isPlainStringRecord(item.params)) {
2493
+ return `apis[${index}].params \u5FC5\u987B\u662F string \u5B57\u5178`;
2494
+ }
2495
+ if (item.headers !== void 0 && !isPlainStringRecord(item.headers)) {
2496
+ return `apis[${index}].headers \u5FC5\u987B\u662F string \u5B57\u5178`;
2497
+ }
2498
+ if (item.body !== void 0 && typeof item.body !== "string") {
2499
+ return `apis[${index}].body \u5FC5\u987B\u662F\u5B57\u7B26\u4E32`;
2500
+ }
2501
+ if (item.description !== void 0 && typeof item.description !== "string") {
2502
+ return `apis[${index}].description \u5FC5\u987B\u662F\u5B57\u7B26\u4E32`;
2503
+ }
2504
+ return {
2505
+ name,
2506
+ url,
2507
+ method: methodRaw,
2508
+ ...item.params ? { params: item.params } : {},
2509
+ ...item.headers ? { headers: item.headers } : {},
2510
+ ...typeof item.body === "string" ? { body: item.body } : {},
2511
+ ...typeof item.description === "string" ? { description: item.description } : {}
2512
+ };
2513
+ }
2514
+ function validateApiCollectionDocument(input) {
2515
+ if (!input || typeof input !== "object" || Array.isArray(input)) {
2516
+ return { ok: false, error: "\u6839\u8282\u70B9\u5FC5\u987B\u662F\u5BF9\u8C61" };
2517
+ }
2518
+ const root = input;
2519
+ const version = root.version;
2520
+ if (version !== API_COLLECTION_DOCUMENT_VERSION && version !== "1") {
2521
+ return {
2522
+ ok: false,
2523
+ error: `version \u5FC5\u987B\u4E3A ${API_COLLECTION_DOCUMENT_VERSION}`
2524
+ };
2525
+ }
2526
+ const name = typeof root.name === "string" ? root.name.trim() : "";
2527
+ if (!name) return { ok: false, error: "name \u5FC5\u586B\u4E14\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32" };
2528
+ if (root.baseUrl !== void 0 && typeof root.baseUrl !== "string") {
2529
+ return { ok: false, error: "baseUrl \u5FC5\u987B\u662F\u5B57\u7B26\u4E32" };
2530
+ }
2531
+ if (!Array.isArray(root.apis)) {
2532
+ return { ok: false, error: "apis \u5FC5\u987B\u662F\u6570\u7EC4" };
2533
+ }
2534
+ if (root.apis.length === 0) {
2535
+ return { ok: false, error: "apis \u81F3\u5C11\u5305\u542B\u4E00\u6761\u63A5\u53E3" };
2536
+ }
2537
+ const apis = [];
2538
+ const nameSet = /* @__PURE__ */ new Set();
2539
+ for (let i = 0; i < root.apis.length; i += 1) {
2540
+ const normalized = normalizeEndpoint(root.apis[i], i);
2541
+ if (typeof normalized === "string") {
2542
+ return { ok: false, error: normalized };
2543
+ }
2544
+ if (nameSet.has(normalized.name)) {
2545
+ return { ok: false, error: `\u63A5\u53E3\u540D\u79F0\u91CD\u590D\uFF1A${normalized.name}` };
2546
+ }
2547
+ nameSet.add(normalized.name);
2548
+ apis.push(normalized);
2549
+ }
2550
+ return {
2551
+ ok: true,
2552
+ document: {
2553
+ version: API_COLLECTION_DOCUMENT_VERSION,
2554
+ name,
2555
+ ...typeof root.baseUrl === "string" && root.baseUrl.trim() ? { baseUrl: root.baseUrl.trim() } : {},
2556
+ apis
2557
+ }
2558
+ };
2559
+ }
2560
+ function parseApiCollectionJson(text) {
2561
+ const trimmed = text.trim();
2562
+ if (!trimmed) return { ok: false, error: "\u5185\u5BB9\u4E3A\u7A7A" };
2563
+ let parsed;
2564
+ try {
2565
+ parsed = JSON.parse(trimmed);
2566
+ } catch (error) {
2567
+ return {
2568
+ ok: false,
2569
+ error: `\u4E0D\u662F\u6709\u6548 JSON\uFF1A${error instanceof Error ? error.message : "\u683C\u5F0F\u65E0\u6548"}`
2570
+ };
2571
+ }
2572
+ const validated = validateApiCollectionDocument(parsed);
2573
+ if (!validated.ok) return validated;
2574
+ return {
2575
+ ok: true,
2576
+ document: validated.document,
2577
+ rawJson: JSON.stringify(validated.document, null, 2)
2578
+ };
2579
+ }
2580
+ function createApiCollectionId() {
2581
+ return `api_col_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`;
2582
+ }
2583
+ function apiCollectionToListItem(record) {
2584
+ return {
2585
+ id: record.id,
2586
+ name: record.name,
2587
+ persistLocal: record.persistLocal,
2588
+ apiCount: record.document.apis.length,
2589
+ updatedAt: record.updatedAt
2590
+ };
2591
+ }
2592
+ function getApiCollectionTemplateDocument() {
2593
+ return {
2594
+ version: API_COLLECTION_DOCUMENT_VERSION,
2595
+ name: "\u793A\u4F8B\u63A5\u53E3\u96C6\u5408",
2596
+ baseUrl: "https://api.example.com",
2597
+ apis: [
2598
+ {
2599
+ name: "\u83B7\u53D6\u7528\u6237\u5217\u8868",
2600
+ method: "GET",
2601
+ url: "/users",
2602
+ params: {
2603
+ page: "{scope?.value?.page}",
2604
+ pageSize: "20",
2605
+ tenant: "{scope?.value?.tenant}"
2606
+ },
2607
+ headers: {
2608
+ Accept: "application/json",
2609
+ Authorization: "Bearer {scope?.value?.token}"
2610
+ },
2611
+ description: "\u5206\u9875\u67E5\u8BE2\u7528\u6237\uFF1Bpage / tenant / token \u53EF\u7528 Scope \u6A21\u7248"
2612
+ },
2613
+ {
2614
+ name: "\u521B\u5EFA\u7528\u6237",
2615
+ method: "POST",
2616
+ url: "/tenants/{scope?.value?.tenant}/users",
2617
+ headers: { "Content-Type": "application/json" },
2618
+ body: '{\n "name": "{scope?.value?.name}",\n "role": "member"\n}',
2619
+ description: "\u521B\u5EFA\u7528\u6237\uFF1BURL \u4E0E body \u5747\u652F\u6301 Scope \u6A21\u7248"
2620
+ },
2621
+ {
2622
+ name: "\u83B7\u53D6\u7528\u6237\u8BE6\u60C5",
2623
+ method: "GET",
2624
+ url: "/users/{scope?.value?.id}",
2625
+ headers: { Accept: "application/json" },
2626
+ description: "\u6309 id \u67E5\u8BE2\uFF1B\u8DEF\u5F84\u91CC\u53EF\u76F4\u63A5\u5199 Scope \u6A21\u7248"
2627
+ }
2628
+ ]
2629
+ };
2630
+ }
2631
+ function getApiCollectionTemplateJson() {
2632
+ return `${JSON.stringify(getApiCollectionTemplateDocument(), null, 2)}
2633
+ `;
2634
+ }
2635
+ function downloadApiCollectionTemplate(filename = "abuilder-api-collection-template.json") {
2636
+ if (typeof document === "undefined") return;
2637
+ const blob = new Blob([getApiCollectionTemplateJson()], {
2638
+ type: "application/json;charset=utf-8"
2639
+ });
2640
+ const url = URL.createObjectURL(blob);
2641
+ const anchor = document.createElement("a");
2642
+ anchor.href = url;
2643
+ anchor.download = filename;
2644
+ anchor.click();
2645
+ URL.revokeObjectURL(url);
2646
+ }
2647
+ function encodeQueryValuePreservingScope(value) {
2648
+ if (!hasScopeTemplate(value)) return encodeURIComponent(value);
2649
+ const re = /\{((?:scope|system)[^}]*)\}/g;
2650
+ let result = "";
2651
+ let lastIndex = 0;
2652
+ let match;
2653
+ while ((match = re.exec(value)) !== null) {
2654
+ result += encodeURIComponent(value.slice(lastIndex, match.index));
2655
+ result += match[0];
2656
+ lastIndex = match.index + match[0].length;
2657
+ }
2658
+ result += encodeURIComponent(value.slice(lastIndex));
2659
+ return result;
2660
+ }
2661
+ function buildApiCollectionEndpointUrl(endpoint) {
2662
+ const base = endpoint.url.trim();
2663
+ const params = endpoint.params;
2664
+ if (!params || Object.keys(params).length === 0) return base;
2665
+ const search = Object.entries(params).filter(([, value]) => value !== void 0 && value !== null && String(value).length > 0).map(
2666
+ ([key, value]) => `${encodeURIComponent(key)}=${encodeQueryValuePreservingScope(String(value))}`
2667
+ ).join("&");
2668
+ if (!search) return base;
2669
+ return base.includes("?") ? `${base}&${search}` : `${base}?${search}`;
2670
+ }
2671
+ function normalizeApiCollectionUrlKey(url) {
2672
+ const trimmed = url.trim();
2673
+ if (!trimmed) return "";
2674
+ const withoutHash = trimmed.split("#")[0] ?? trimmed;
2675
+ const queryIndex = withoutHash.indexOf("?");
2676
+ const pathOnly = queryIndex === -1 ? withoutHash : withoutHash.slice(0, queryIndex);
2677
+ const normalized = pathOnly.replace(/\/+$/, "");
2678
+ return normalized || "/";
2679
+ }
2680
+ function stableHeadersText(headers) {
2681
+ if (!headers || Object.keys(headers).length === 0) return "";
2682
+ const sorted = Object.keys(headers).sort().reduce((acc, key) => {
2683
+ acc[key] = headers[key] ?? "";
2684
+ return acc;
2685
+ }, {});
2686
+ return JSON.stringify(sorted);
2687
+ }
2688
+ function diffFetchConfigChanges(prev, next) {
2689
+ const changed = [];
2690
+ const prevUrl = prev?.url?.trim() ?? "";
2691
+ const nextUrl = next.url?.trim() ?? "";
2692
+ if (prevUrl !== nextUrl) changed.push("url");
2693
+ const prevMethod = (prev?.method ?? "GET").toUpperCase();
2694
+ const nextMethod = (next.method ?? "GET").toUpperCase();
2695
+ if (prevMethod !== nextMethod) changed.push("method");
2696
+ if (stableHeadersText(prev?.headers) !== stableHeadersText(next.headers)) {
2697
+ changed.push("headers");
2698
+ }
2699
+ if ((prev?.body ?? "").trim() !== (next.body ?? "").trim()) {
2700
+ changed.push("body");
2701
+ }
2702
+ if ((prev?.apiBaseUrl?.trim() ?? "") !== (next.apiBaseUrl?.trim() ?? "")) {
2703
+ changed.push("apiBaseUrl");
2704
+ }
2705
+ return changed;
2706
+ }
2707
+ function pickEndpointForNode(node, collectionId, candidates) {
2708
+ if (candidates.length === 0) return null;
2709
+ if (candidates.length === 1) return candidates[0] ?? null;
2710
+ const config = node.fetchConfig;
2711
+ if (config?.apiCollectionId === collectionId && config.apiCollectionEndpointName) {
2712
+ const byName = candidates.find(
2713
+ (item) => item.name === config.apiCollectionEndpointName
2714
+ );
2715
+ if (byName) return byName;
2716
+ }
2717
+ const method = config?.method?.toUpperCase();
2718
+ if (method) {
2719
+ const byMethod = candidates.filter((item) => item.method === method);
2720
+ if (byMethod.length === 1) return byMethod[0] ?? null;
2721
+ if (byMethod.length > 1) return byMethod[0] ?? null;
2722
+ }
2723
+ return candidates[0] ?? null;
2724
+ }
2725
+ function buildApiCollectionSyncPatches(options) {
2726
+ const { collectionId, document: document2, nodes } = options;
2727
+ const byUrl = /* @__PURE__ */ new Map();
2728
+ for (const endpoint of document2.apis) {
2729
+ const key = normalizeApiCollectionUrlKey(endpoint.url);
2730
+ if (!key) continue;
2731
+ const list = byUrl.get(key) ?? [];
2732
+ list.push(endpoint);
2733
+ byUrl.set(key, list);
2734
+ }
2735
+ const patches = [];
2736
+ const syncedAt = Date.now();
2737
+ for (const node of nodes) {
2738
+ const nodeUrl = node.fetchConfig?.url;
2739
+ if (!nodeUrl?.trim()) continue;
2740
+ const key = normalizeApiCollectionUrlKey(nodeUrl);
2741
+ if (!key) continue;
2742
+ const candidates = byUrl.get(key) ?? [];
2743
+ const endpoint = pickEndpointForNode(node, collectionId, candidates);
2744
+ if (!endpoint) continue;
2745
+ const fetchConfigPatch = applyApiCollectionEndpointToFetchConfig({
2746
+ collectionId,
2747
+ document: document2,
2748
+ endpoint
2749
+ });
2750
+ const changedFields = diffFetchConfigChanges(node.fetchConfig, fetchConfigPatch);
2751
+ fetchConfigPatch.apiCollectionSyncNotice = {
2752
+ source: "api-collection-sync",
2753
+ collectionName: document2.name,
2754
+ endpointName: endpoint.name,
2755
+ changedFields,
2756
+ updatedAt: syncedAt
2757
+ };
2758
+ patches.push({
2759
+ nodeId: node.id,
2760
+ nodeLabel: (node.label ?? "").trim() || node.id,
2761
+ changedFields,
2762
+ fetchConfigPatch
2763
+ });
2764
+ }
2765
+ return patches;
2766
+ }
2767
+ function toApiCollectionSyncResult(patches) {
2768
+ return {
2769
+ updatedCount: patches.length,
2770
+ nodes: patches.map((patch) => ({
2771
+ id: patch.nodeId,
2772
+ label: patch.nodeLabel,
2773
+ changedFields: patch.changedFields
2774
+ }))
2775
+ };
2776
+ }
2777
+ function applyApiCollectionEndpointToFetchConfig(options) {
2778
+ const { collectionId, document: document2, endpoint } = options;
2779
+ const headers = endpoint.headers ?? {};
2780
+ return {
2781
+ url: buildApiCollectionEndpointUrl(endpoint),
2782
+ method: endpoint.method,
2783
+ headers,
2784
+ headersJson: Object.keys(headers).length > 0 ? JSON.stringify(headers, null, 2) : "",
2785
+ body: endpoint.body ?? "",
2786
+ apiBaseUrl: document2.baseUrl?.trim() || void 0,
2787
+ urlInputMode: "collection",
2788
+ apiCollectionId: collectionId,
2789
+ apiCollectionEndpointName: endpoint.name
2790
+ };
2791
+ }
2792
+
1337
2793
  // src/runtime/execution-trace.ts
1338
2794
  function serializeTraceValue(value) {
1339
2795
  if (value === void 0) return void 0;
@@ -2442,7 +3898,12 @@ var BlueprintGraphRunner = class _BlueprintGraphRunner {
2442
3898
  ...DEFAULT_JSON_NODE_CONFIG,
2443
3899
  ...node.jsonConfig
2444
3900
  };
2445
- const value = parseJsonConfig(config);
3901
+ const incomingScope = runner.buildFetchIncomingScope(
3902
+ token.nodeId,
3903
+ "in",
3904
+ input
3905
+ );
3906
+ const value = parseJsonConfig(config, incomingScope);
2446
3907
  io.setOutput("out", createTrueSignal(value));
2447
3908
  } catch (error) {
2448
3909
  io.setOutput(
@@ -2752,6 +4213,6 @@ var BlueprintGraphRunner = class _BlueprintGraphRunner {
2752
4213
  }
2753
4214
  };
2754
4215
 
2755
- export { AND_NODE_TYPE, BLUEPRINT_ACTIVATION_INPUT_KEY, BLUEPRINT_CALL_STACK_KEY, BLUEPRINT_NODE_TYPE, BehaviorRegistry, BlueprintCycleError, BlueprintGraphRunner, CLOCK_NODE_TYPE, DEFAULT_CLOCK_NODE_CONFIG, DEFAULT_FETCH_REQUEST_CONFIG, DEFAULT_JSON_NODE_CONFIG, DEFAULT_LOGIC_NODE_CONFIG, DEFAULT_LOGIC_NODE_TYPE, DEFAULT_STORAGE_NODE_CONFIG, DEFAULT_VIEW_EVENT_NODE_CONFIG, EVENT_NODE_TYPE, Executor, FETCH_CACHES, FETCH_CREDENTIALS, FETCH_HTTP_METHODS, FETCH_MODES, FETCH_NODE_TYPE, FETCH_REDIRECTS, FETCH_RESPONSE_TYPES, FETCH_SCOPE_AUTOCOMPLETE_FALLBACK, JSON_NODE_TYPE, LIFECYCLE_NODE_TYPE, LIFECYCLE_SIGNAL_KEY, PAGE_LIFECYCLE_LABELS, PAGE_LIFECYCLE_PHASES, STORAGE_KINDS, STORAGE_NODE_TYPE, UI_EVENT_PAYLOAD_KEY, VIEW_EVENT_SIGNAL_KEY, VIEW_EVENT_TYPES, VIEW_NODE_TYPE, abortClockNode, abortClockSession, andLogicNodeDefinition, appStorageKey, applyFetchConfigScope, applyScopeAutocompleteSelection, assertNoBlueprintReferenceCycle, blueprintNodeDefinition, buildClockSessionKey, buildClockSignalValue, buildEndpointFullUrl, buildEndpointSuggestions, buildIncomingNodeScope, buildScopeExpression, clearClockSessionAbort, clockNodeDefinition, collectArmedViewEventBindings, collectArmedViewEventNodeIds, collectBlueprintLibraryRefs, collectIncomingNodeScopeEntries, collectViewEventBindings, combinePortSignalsOr, createClockOutputValue, createFalseSignal, createIncomingNodeScopeEntry, createLifecycleSignal, createTraceEntryId, createTrueSignal, createViewEventSignal, defaultLogicNodeDefinition, deserializeStorageValue, detectBlueprintReferenceCycle, detectRuntimeBlueprintCycle, draftFetchHeadersText, evaluateScopeExpression, evaluateScopeTemplate, evaluateScopeTemplateInJson, executeFetch, executeLogicConfig, executeStorageConfig, fetchConfigHasScopeTemplate, fetchNodeDefinition, filterEndpointSuggestions, formatBlueprintCycleMessage, formatClockTime, getActiveClockNodeIds, getClockTickDelayOffsetMs, getClockTickWaitMs, getFetchBodyValidationError, getFetchHeadersValidationError, getNodeDefinition, getScopeAutocompleteSuggestions, hasScopeTemplate, isClockNodeActive, isClockScheduleActive, isClockSessionAborted, isFalseSignal, isStorageReadConfigured, isStorageSetConfigured, isTrueSignal, isViewEventType, isWholeScopeExpression, jsonNodeDefinition, latestTraceOutputsByNode, lifecycleNodeDefinition, looksLikeJsonText, nodeDefinitionRegistry, normalizeAppNameSpace, normalizeClockConfig, normalizeFetchRequestConfig, normalizeStorageConfig, normalizeViewEventConfig, parseFetchHeadersJson, parseJsonConfig, parseJsonText, parseScopeAutocomplete, parseSwaggerDocument, registerDefaultBehaviors, resolveBlueprintCallStack, resolveFetchBody, resolveFetchHeaders, resolveFetchIncomingScope, resolveFetchRequestUrl, resolveFetchScopeAutocompleteRoot, resolveStorageWriteValue, scheduleClockOutputs, serializeStorageValue, serializeTraceValue, snapshotDomEvent, snapshotViewEventNode, startClockSchedule, stopAllClockSchedules, stopClockSchedule, storageNodeDefinition, stringifyScopeValue, subscribeActiveClockNodes, uniqueStorageKinds, validateClockScheduleConfig, validateFetchJsonText, validateJsonString, validateLogicSourceCode, viewBindNodeDefinition, viewEventNodeDefinition };
4216
+ export { AND_NODE_TYPE, API_COLLECTION_DOCUMENT_VERSION, BLUEPRINT_ACTIVATION_INPUT_KEY, BLUEPRINT_CALL_STACK_KEY, BLUEPRINT_NODE_TYPE, BehaviorRegistry, BlueprintCycleError, BlueprintGraphRunner, CLOCK_NODE_TYPE, DEFAULT_CLOCK_NODE_CONFIG, DEFAULT_FETCH_REQUEST_CONFIG, DEFAULT_JSON_NODE_CONFIG, DEFAULT_LOGIC_NODE_CONFIG, DEFAULT_LOGIC_NODE_TYPE, DEFAULT_STORAGE_NODE_CONFIG, DEFAULT_VIEW_EVENT_NODE_CONFIG, EVENT_NODE_TYPE, Executor, FETCH_CACHES, FETCH_CREDENTIALS, FETCH_HTTP_METHODS, FETCH_MODES, FETCH_NODE_TYPE, FETCH_REDIRECTS, FETCH_RESPONSE_TYPES, FETCH_SCOPE_AUTOCOMPLETE_FALLBACK, JSON_NODE_TYPE, LIFECYCLE_NODE_TYPE, LIFECYCLE_SIGNAL_KEY, PAGE_LIFECYCLE_LABELS, PAGE_LIFECYCLE_PHASES, STORAGE_KINDS, STORAGE_NODE_TYPE, SYSTEM_LOCATION_KEYS, SYSTEM_MATH_KEYS, SYSTEM_TIME_METHOD_NAMES, TEMPLATE_ROOT_NAMES, UI_EVENT_PAYLOAD_KEY, VIEW_EVENT_SIGNAL_KEY, VIEW_EVENT_TYPES, VIEW_NODE_TYPE, abortClockNode, abortClockSession, andLogicNodeDefinition, apiCollectionToListItem, appStorageKey, applyApiCollectionEndpointToFetchConfig, applyFetchConfigScope, applyScopeAutocompleteSelection, assertNoBlueprintReferenceCycle, blueprintNodeDefinition, buildApiCollectionEndpointUrl, buildApiCollectionSyncPatches, buildClockSessionKey, buildClockSignalValue, buildEndpointFullUrl, buildEndpointSuggestions, buildIncomingNodeScope, buildScopeExpression, clearClockSessionAbort, clockNodeDefinition, collectArmedViewEventBindings, collectArmedViewEventNodeIds, collectBlueprintLibraryRefs, collectIncomingNodeScopeEntries, collectViewEventBindings, combinePortSignalsOr, createApiCollectionId, createClockOutputValue, createFalseSignal, createIncomingNodeScopeEntry, createLifecycleSignal, createSystemRoot, createTraceEntryId, createTrueSignal, createViewEventSignal, defaultLogicNodeDefinition, deserializeStorageValue, detectBlueprintReferenceCycle, detectRuntimeBlueprintCycle, downloadApiCollectionTemplate, draftFetchHeadersText, evaluateScopeExpression, evaluateScopeTemplate, evaluateScopeTemplateInJson, executeFetch, executeLogicConfig, executeStorageConfig, extractJsonErrorPosition, fetchConfigHasScopeTemplate, fetchNodeDefinition, filterEndpointSuggestions, filterStorageKeySuggestions, findJsonSyntaxErrorOffset, findSuspectCharRanges, formatBlueprintCycleMessage, formatClockTime, getActiveClockNodeIds, getApiCollectionTemplateDocument, getApiCollectionTemplateJson, getClockTickDelayOffsetMs, getClockTickWaitMs, getFetchBodyValidationError, getFetchHeadersValidationError, getNodeDefinition, getScopeAutocompleteSuggestions, getSystemAutocompleteTree, hasScopeTemplate, hasTemplateExpression, isClockNodeActive, isClockScheduleActive, isClockSessionAborted, isDayjsValue, isFalseSignal, isStorageReadConfigured, isStorageSetConfigured, isTrueSignal, isViewEventType, isWholeScopeExpression, jsonNodeDefinition, latestTraceOutputsByNode, lifecycleNodeDefinition, lintJsonString, listBrowserStorageKeys, looksLikeJsonText, nodeDefinitionRegistry, normalizeApiCollectionUrlKey, normalizeAppNameSpace, normalizeClockConfig, normalizeFetchRequestConfig, normalizeStorageConfig, normalizeViewEventConfig, parseApiCollectionJson, parseFetchHeadersJson, parseJsonConfig, parseJsonText, parseScopeAutocomplete, parseSwaggerDocument, preserveTemplateTokensInEncode, registerDefaultBehaviors, renderJsonWithErrorHighlights, resolveBlueprintCallStack, resolveFetchBody, resolveFetchHeaders, resolveFetchIncomingScope, resolveFetchRequestUrl, resolveFetchScopeAutocompleteRoot, resolveStorageKey, resolveStorageWriteValue, scheduleClockOutputs, serializeStorageValue, serializeTraceValue, snapshotDomEvent, snapshotViewEventNode, startClockSchedule, stopAllClockSchedules, stopClockSchedule, storageNodeDefinition, stringifyScopeValue, subscribeActiveClockNodes, toApiCollectionSyncResult, uniqueStorageKinds, validateApiCollectionDocument, validateClockScheduleConfig, validateFetchJsonText, validateJsonString, validateJsonStringAllowingScope, validateLogicSourceCode, viewBindNodeDefinition, viewEventNodeDefinition };
2756
4217
  //# sourceMappingURL=index.js.map
2757
4218
  //# sourceMappingURL=index.js.map