@velarscript/compiler 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +70 -0
  3. package/dist/analyzer.d.ts +1175 -0
  4. package/dist/analyzer.d.ts.map +1 -0
  5. package/dist/analyzer.js +12130 -0
  6. package/dist/analyzer.js.map +1 -0
  7. package/dist/application-package-host.d.ts +28 -0
  8. package/dist/application-package-host.d.ts.map +1 -0
  9. package/dist/application-package-host.js +2 -0
  10. package/dist/application-package-host.js.map +1 -0
  11. package/dist/ast.d.ts +853 -0
  12. package/dist/ast.d.ts.map +1 -0
  13. package/dist/ast.js +245 -0
  14. package/dist/ast.js.map +1 -0
  15. package/dist/class-runtime.d.ts +6 -0
  16. package/dist/class-runtime.d.ts.map +1 -0
  17. package/dist/class-runtime.js +45 -0
  18. package/dist/class-runtime.js.map +1 -0
  19. package/dist/collection-lowering-runtime.d.ts +7 -0
  20. package/dist/collection-lowering-runtime.d.ts.map +1 -0
  21. package/dist/collection-lowering-runtime.js +952 -0
  22. package/dist/collection-lowering-runtime.js.map +1 -0
  23. package/dist/collection-runtime.d.ts +16 -0
  24. package/dist/collection-runtime.d.ts.map +1 -0
  25. package/dist/collection-runtime.js +231 -0
  26. package/dist/collection-runtime.js.map +1 -0
  27. package/dist/core-vocabulary.d.ts +141 -0
  28. package/dist/core-vocabulary.d.ts.map +1 -0
  29. package/dist/core-vocabulary.js +88 -0
  30. package/dist/core-vocabulary.js.map +1 -0
  31. package/dist/diagnostic.d.ts +42 -0
  32. package/dist/diagnostic.d.ts.map +1 -0
  33. package/dist/diagnostic.js +66 -0
  34. package/dist/diagnostic.js.map +1 -0
  35. package/dist/embedded-javascript.d.ts +74 -0
  36. package/dist/embedded-javascript.d.ts.map +1 -0
  37. package/dist/embedded-javascript.js +341 -0
  38. package/dist/embedded-javascript.js.map +1 -0
  39. package/dist/embedded-module.d.ts +11 -0
  40. package/dist/embedded-module.d.ts.map +1 -0
  41. package/dist/embedded-module.js +67 -0
  42. package/dist/embedded-module.js.map +1 -0
  43. package/dist/embedded-source.d.ts +19 -0
  44. package/dist/embedded-source.d.ts.map +1 -0
  45. package/dist/embedded-source.js +61 -0
  46. package/dist/embedded-source.js.map +1 -0
  47. package/dist/emitter.d.ts +188 -0
  48. package/dist/emitter.d.ts.map +1 -0
  49. package/dist/emitter.js +3254 -0
  50. package/dist/emitter.js.map +1 -0
  51. package/dist/error-runtime.d.ts +17 -0
  52. package/dist/error-runtime.d.ts.map +1 -0
  53. package/dist/error-runtime.js +109 -0
  54. package/dist/error-runtime.js.map +1 -0
  55. package/dist/extension.d.ts +373 -0
  56. package/dist/extension.d.ts.map +1 -0
  57. package/dist/extension.js +25 -0
  58. package/dist/extension.js.map +1 -0
  59. package/dist/formatter.d.ts +13 -0
  60. package/dist/formatter.d.ts.map +1 -0
  61. package/dist/formatter.js +1440 -0
  62. package/dist/formatter.js.map +1 -0
  63. package/dist/framework-host.d.ts +87 -0
  64. package/dist/framework-host.d.ts.map +1 -0
  65. package/dist/framework-host.js +2 -0
  66. package/dist/framework-host.js.map +1 -0
  67. package/dist/index.d.ts +75 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +932 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/interpolated-string.d.ts +47 -0
  72. package/dist/interpolated-string.d.ts.map +1 -0
  73. package/dist/interpolated-string.js +344 -0
  74. package/dist/interpolated-string.js.map +1 -0
  75. package/dist/json-runtime.d.ts +2 -0
  76. package/dist/json-runtime.d.ts.map +1 -0
  77. package/dist/json-runtime.js +193 -0
  78. package/dist/json-runtime.js.map +1 -0
  79. package/dist/language-guidance.d.ts +31 -0
  80. package/dist/language-guidance.d.ts.map +1 -0
  81. package/dist/language-guidance.js +187 -0
  82. package/dist/language-guidance.js.map +1 -0
  83. package/dist/lexer.d.ts +85 -0
  84. package/dist/lexer.d.ts.map +1 -0
  85. package/dist/lexer.js +1004 -0
  86. package/dist/lexer.js.map +1 -0
  87. package/dist/limits.d.ts +2 -0
  88. package/dist/limits.d.ts.map +1 -0
  89. package/dist/limits.js +2 -0
  90. package/dist/limits.js.map +1 -0
  91. package/dist/mechanical-fix.d.ts +26 -0
  92. package/dist/mechanical-fix.d.ts.map +1 -0
  93. package/dist/mechanical-fix.js +61 -0
  94. package/dist/mechanical-fix.js.map +1 -0
  95. package/dist/narrowing-runtime.d.ts +5 -0
  96. package/dist/narrowing-runtime.d.ts.map +1 -0
  97. package/dist/narrowing-runtime.js +27 -0
  98. package/dist/narrowing-runtime.js.map +1 -0
  99. package/dist/number-runtime.d.ts +3 -0
  100. package/dist/number-runtime.d.ts.map +1 -0
  101. package/dist/number-runtime.js +37 -0
  102. package/dist/number-runtime.js.map +1 -0
  103. package/dist/parser.d.ts +245 -0
  104. package/dist/parser.d.ts.map +1 -0
  105. package/dist/parser.js +3582 -0
  106. package/dist/parser.js.map +1 -0
  107. package/dist/primitive-runtime.d.ts +4 -0
  108. package/dist/primitive-runtime.d.ts.map +1 -0
  109. package/dist/primitive-runtime.js +39 -0
  110. package/dist/primitive-runtime.js.map +1 -0
  111. package/dist/promise-runtime.d.ts +6 -0
  112. package/dist/promise-runtime.d.ts.map +1 -0
  113. package/dist/promise-runtime.js +86 -0
  114. package/dist/promise-runtime.js.map +1 -0
  115. package/dist/reactive-bridge-runtime.d.ts +7 -0
  116. package/dist/reactive-bridge-runtime.d.ts.map +1 -0
  117. package/dist/reactive-bridge-runtime.js +112 -0
  118. package/dist/reactive-bridge-runtime.js.map +1 -0
  119. package/dist/runtime-abi.d.ts +24 -0
  120. package/dist/runtime-abi.d.ts.map +1 -0
  121. package/dist/runtime-abi.js +24 -0
  122. package/dist/runtime-abi.js.map +1 -0
  123. package/dist/semantic.d.ts +142 -0
  124. package/dist/semantic.d.ts.map +1 -0
  125. package/dist/semantic.js +845 -0
  126. package/dist/semantic.js.map +1 -0
  127. package/dist/source-names.d.ts +32 -0
  128. package/dist/source-names.d.ts.map +1 -0
  129. package/dist/source-names.js +101 -0
  130. package/dist/source-names.js.map +1 -0
  131. package/dist/source.d.ts +19 -0
  132. package/dist/source.d.ts.map +1 -0
  133. package/dist/source.js +64 -0
  134. package/dist/source.js.map +1 -0
  135. package/dist/text-runtime.d.ts +2 -0
  136. package/dist/text-runtime.d.ts.map +1 -0
  137. package/dist/text-runtime.js +285 -0
  138. package/dist/text-runtime.js.map +1 -0
  139. package/dist/token.d.ts +19 -0
  140. package/dist/token.d.ts.map +1 -0
  141. package/dist/token.js +51 -0
  142. package/dist/token.js.map +1 -0
  143. package/dist/type-registry-runtime.d.ts +7 -0
  144. package/dist/type-registry-runtime.d.ts.map +1 -0
  145. package/dist/type-registry-runtime.js +51 -0
  146. package/dist/type-registry-runtime.js.map +1 -0
  147. package/dist/type-validation-runtime.d.ts +17 -0
  148. package/dist/type-validation-runtime.d.ts.map +1 -0
  149. package/dist/type-validation-runtime.js +150 -0
  150. package/dist/type-validation-runtime.js.map +1 -0
  151. package/dist/types.d.ts +356 -0
  152. package/dist/types.d.ts.map +1 -0
  153. package/dist/types.js +1170 -0
  154. package/dist/types.js.map +1 -0
  155. package/dist/utf8-runtime.d.ts +7 -0
  156. package/dist/utf8-runtime.d.ts.map +1 -0
  157. package/dist/utf8-runtime.js +43 -0
  158. package/dist/utf8-runtime.js.map +1 -0
  159. package/package.json +48 -0
@@ -0,0 +1,952 @@
1
+ import { VELAR_COLLECTION_HOST_EXPORTS, VELAR_COLLECTION_HOST_MODULE } from "./collection-runtime.js";
2
+ import { VELAR_REACTIVE_BRIDGE_MODULE } from "./reactive-bridge-runtime.js";
3
+ export const VELAR_COLLECTION_LOWERING_MODULE = "velar/compiler-runtime-collection-lowering-v1";
4
+ /** Stateless collection algorithms shared by project compilation. */
5
+ export const VELAR_COLLECTION_LOWERING_EXPORTS = [
6
+ "__velarMaxCollectionItems",
7
+ "__velarCollectionValue",
8
+ "__velarSameValueZero",
9
+ "__velarEquals",
10
+ "__velarValidateDenseList",
11
+ "__velarReactiveListIterator",
12
+ "__velarReactiveSetIterator",
13
+ "__velarReactiveMapKeyIterator",
14
+ "__velarReactiveRecordIterator",
15
+ "__velarCollectionIterator",
16
+ "__velarCollectionPairIterator",
17
+ "__velarCopyList",
18
+ "__velarOrderedListValue",
19
+ "__velarCreateList",
20
+ "__velarCreateListAsync",
21
+ "__velarCreateSet",
22
+ "__velarCreateMap",
23
+ "__velarCollectionSize",
24
+ "__velarCollectionGet",
25
+ "__velarCollectionSlice",
26
+ // COL-U5: `IndexError` is a nameable source type, so a project build must be
27
+ // able to import the one runtime class every List position raises. The
28
+ // standalone path inlines this runtime whole, so an unexported class stayed
29
+ // reachable there while every CLI entry (sharedRuntimeModules) emitted an
30
+ // unbound reference.
31
+ "__VelarIndexError",
32
+ "__velarIndex",
33
+ "__velarOptionalIndex",
34
+ "__velarSetIndex",
35
+ "__velarListAppend",
36
+ "__velarListExtend",
37
+ "__velarListInsert",
38
+ "__velarListRemove",
39
+ "__velarListPop",
40
+ "__velarListCopy",
41
+ "__velarListCount",
42
+ "__velarListIndex",
43
+ "__velarListFind",
44
+ "__velarListMap",
45
+ "__velarListFilter",
46
+ "__velarListReduce",
47
+ "__velarListEvery",
48
+ "__velarListSome",
49
+ "__velarListSum",
50
+ "__velarListExtremum",
51
+ "__velarListMin",
52
+ "__velarListMax",
53
+ "__velarListJoin",
54
+ "__velarListSorted",
55
+ "__velarListReversed",
56
+ "__velarListFlatMap",
57
+ "__velarSetAdd",
58
+ "__velarSetUpdate",
59
+ "__velarSetCopy",
60
+ "__velarSetUnion",
61
+ "__velarSetIntersection",
62
+ "__velarSetDifference",
63
+ "__velarMapSet",
64
+ "__velarMapUpdate",
65
+ "__velarMapCopy",
66
+ "__velarRecordFields",
67
+ "__velarRecordSet",
68
+ "__velarRecordCopy",
69
+ "__velarCollectionHas",
70
+ "__velarContains",
71
+ "__velarCollectionRemove",
72
+ "__velarCollectionClear",
73
+ "__velarCollectionKeys",
74
+ "__velarCollectionValues",
75
+ "__velarCollectionEntries",
76
+ "__velarOptionalCollection",
77
+ ];
78
+ export const VELAR_COLLECTION_LOWERING_DEPENDENCIES = [
79
+ VELAR_COLLECTION_HOST_MODULE,
80
+ VELAR_REACTIVE_BRIDGE_MODULE,
81
+ ];
82
+ export const VELAR_COLLECTION_LOWERING_RUNTIME = String.raw `
83
+ const __velarMaxCollectionItems = 1000000;
84
+ const __velarCollectionValue = value => value === undefined ? null : value;
85
+ const __velarSameValueZero = (left, right) => { left = __velarCollectionValue(left); right = __velarCollectionValue(right); return left === right || (left !== left && right !== right); };
86
+ const __velarListNativeWeakMap = globalThis.WeakMap;
87
+ const __velarListWeakMapPrototype = __velarCollectionListGetOwnPropertyDescriptor(__velarListNativeWeakMap, "prototype")?.value;
88
+ const __velarListWeakMapGetOperation = __velarCollectionListGetOwnPropertyDescriptor(__velarListWeakMapPrototype, "get")?.value;
89
+ const __velarListWeakMapSetOperation = __velarCollectionListGetOwnPropertyDescriptor(__velarListWeakMapPrototype, "set")?.value;
90
+ // Ownership is the memo of a completed dense validation: the registry records
91
+ // the element count the List had when it was proved dense. Any foreign length
92
+ // change -- an unsafe push, a length assignment, a truncation -- breaks the
93
+ // match and sends the List back through full validation, so a List that
94
+ // crossed an unsafe boundary is never trusted on the strength of an older
95
+ // check. Without the memo every index read on a List the compiler did not
96
+ // build (a literal, anything velar/collections returns) revalidated every
97
+ // element, making 'for i in range(n): values[i]' quadratic.
98
+ const __velarOwnedLists = new __velarListNativeWeakMap();
99
+ const __velarListIsFrozenOperation = __velarCollectionListGetOwnPropertyDescriptor(__velarCollectionNativeObject, "isFrozen")?.value;
100
+ // COL-U4: a frozen host array fails every mutability probe below; without
101
+ // this check the author sees "requires ordinary mutable List data elements"
102
+ // with no way out. Freezing is a whole-value verdict, so it is answered once
103
+ // with the copy-on-the-JavaScript-side workflow.
104
+ function __velarListRejectFrozen(value, name) {
105
+ if (__velarCollectionHostCall(__velarListIsFrozenOperation, __velarCollectionNativeObject, [value])) {
106
+ throw new __velarCollectionNativeTypeError(name + " received a frozen JavaScript array; copy it on the JavaScript side — [...values] — before passing it to VelarScript");
107
+ }
108
+ }
109
+ function __velarListOwnedLength(value) { return __velarCollectionHostCall(__velarListWeakMapGetOperation, __velarOwnedLists, [value]); }
110
+ function __velarMarkOwnedList(value) { __velarCollectionHostCall(__velarListWeakMapSetOperation, __velarOwnedLists, [value, value.length]); return value; }
111
+ function __velarValidateDenseList(value, name) {
112
+ value = __velarReactiveRaw(value);
113
+ if (!__velarCollectionListIsArray(value) || value.length > __velarMaxCollectionItems || __velarCollectionListOwnSymbols(value).length > 0 || __velarCollectionListOwnNames(value).length !== value.length + 1) {
114
+ throw new __velarCollectionNativeTypeError(name + " requires a dense VelarScript List");
115
+ }
116
+ __velarListRejectFrozen(value, name);
117
+ const lengthDescriptor = __velarCollectionListGetOwnPropertyDescriptor(value, "length");
118
+ if (!lengthDescriptor || !lengthDescriptor.writable || lengthDescriptor.enumerable || lengthDescriptor.configurable || !("value" in lengthDescriptor)) throw new __velarCollectionNativeTypeError(name + " requires an ordinary mutable List length");
119
+ for (let index = 0; index < value.length; index += 1) {
120
+ const descriptor = __velarCollectionListGetOwnPropertyDescriptor(value, index);
121
+ if (!descriptor?.enumerable || !descriptor.configurable || !descriptor.writable || !("value" in descriptor)) throw new __velarCollectionNativeTypeError(name + " requires ordinary mutable List data elements");
122
+ }
123
+ return __velarMarkOwnedList(value);
124
+ }
125
+ function __velarValidateOwnedList(value, name) {
126
+ value = __velarReactiveRaw(value);
127
+ if (!__velarCollectionListIsArray(value) || value.length > __velarMaxCollectionItems) throw new __velarCollectionNativeTypeError(name + " requires a dense VelarScript List");
128
+ if (__velarListOwnedLength(value) !== value.length) return __velarValidateDenseList(value, name);
129
+ const lengthDescriptor = __velarCollectionListGetOwnPropertyDescriptor(value, "length");
130
+ if (!lengthDescriptor || !lengthDescriptor.writable || lengthDescriptor.enumerable || lengthDescriptor.configurable || !("value" in lengthDescriptor)) throw new __velarCollectionNativeTypeError(name + " requires an ordinary mutable List length");
131
+ return value;
132
+ }
133
+ function __velarOwnedListElement(value, index, name) {
134
+ const descriptor = __velarCollectionListGetOwnPropertyDescriptor(value, index);
135
+ if (!descriptor?.enumerable || !descriptor.configurable || !descriptor.writable || !("value" in descriptor)) throw new __velarCollectionNativeTypeError(name + " requires ordinary mutable List data elements");
136
+ return descriptor.value;
137
+ }
138
+ function* __velarReactiveListIterator(value) { __velarReactiveCollectionTrack(value); value = __velarValidateOwnedList(value, "List iteration"); for (let index = 0; index < value.length; index += 1) yield __velarReactiveCollectionRead(value, __velarReactiveIterateKey, __velarOwnedListElement(value, index, "List iteration")); }
139
+ function* __velarReactiveSetIterator(value) { const size = __velarCollectionSetMapSetSize(value); if (size > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A Set cannot exceed 1000000 items"); __velarReactiveCollectionTrack(value); const iterator = __velarCollectionSetMapSetValues(value); while (true) { const step = __velarCollectionSetMapSetNext(iterator); if (step.done) return; yield __velarReactiveCollectionRead(value, __velarReactiveIterateKey, step.value); } }
140
+ function* __velarReactiveMapKeyIterator(value) { const size = __velarCollectionSetMapMapSize(value); if (size > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A Map cannot exceed 1000000 entries"); __velarReactiveCollectionTrack(value, __velarReactiveStructureKey); const iterator = __velarCollectionSetMapMapKeys(value); while (true) { const step = __velarCollectionSetMapMapNext(iterator); if (step.done) return; yield __velarReactiveCollectionRead(value, __velarReactiveStructureKey, step.value); } }
141
+ function* __velarReactiveRecordIterator(value) { const fields = __velarRecordFields(value, "Record iteration"); __velarReactiveCollectionTrack(value, __velarReactiveStructureKey); for (let index = 0; index < fields.length; index += 1) yield __velarReactiveCollectionRead(value, __velarReactiveStructureKey, fields[index]); }
142
+ function __velarCopyList(value, name) {
143
+ // Every callback operation snapshots through here, so the owned fast path is
144
+ // what keeps map from revalidating the whole List before the first call.
145
+ value = __velarValidateOwnedList(value, name);
146
+ const output = [];
147
+ for (let index = 0; index < value.length; index += 1) output[index] = __velarCollectionValue(__velarOwnedListElement(value, index, name));
148
+ return __velarMarkOwnedList(output);
149
+ }
150
+ // TXT-D1: ordered string comparison is code-point order (= UTF-8 binary
151
+ // order) everywhere. UTF-16 code-unit order agrees exactly when neither
152
+ // operand contains a surrogate, so the one native regex probe keeps the
153
+ // decoded walk on surrogate-bearing strings only.
154
+ const __velarListNativeString = globalThis.String;
155
+ const __velarListStringPrototype = __velarCollectionListGetOwnPropertyDescriptor(__velarListNativeString, "prototype")?.value;
156
+ const __velarListStringCharCodeAt = __velarCollectionListGetOwnPropertyDescriptor(__velarListStringPrototype, "charCodeAt")?.value;
157
+ const __velarListSurrogatePattern = /[\uD800-\uDFFF]/;
158
+ const __velarListRegExpPrototype = __velarCollectionHostCall(__velarCollectionGetPrototypeOf, __velarCollectionNativeObject, [__velarListSurrogatePattern]);
159
+ const __velarListSurrogateExecOperation = __velarCollectionListGetOwnPropertyDescriptor(__velarListRegExpPrototype, "exec")?.value;
160
+ function __velarListCharCode(value, index) { return __velarCollectionHostCall(__velarListStringCharCodeAt, value, [index]); }
161
+ function __velarListHasSurrogate(value) { return __velarCollectionHostCall(__velarListSurrogateExecOperation, __velarListSurrogatePattern, [value]) !== null; }
162
+ function __velarCodePointCompare(left, right) {
163
+ if (left === right) return 0;
164
+ if (!__velarListHasSurrogate(left) && !__velarListHasSurrogate(right)) return left < right ? -1 : 1;
165
+ let leftOffset = 0;
166
+ let rightOffset = 0;
167
+ while (leftOffset < left.length && rightOffset < right.length) {
168
+ let first = __velarListCharCode(left, leftOffset);
169
+ let firstUnits = 1;
170
+ if (first >= 0xD800 && first <= 0xDBFF && leftOffset + 1 < left.length) {
171
+ const trail = __velarListCharCode(left, leftOffset + 1);
172
+ if (trail >= 0xDC00 && trail <= 0xDFFF) { first = (first - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000; firstUnits = 2; }
173
+ }
174
+ let second = __velarListCharCode(right, rightOffset);
175
+ let secondUnits = 1;
176
+ if (second >= 0xD800 && second <= 0xDBFF && rightOffset + 1 < right.length) {
177
+ const trail = __velarListCharCode(right, rightOffset + 1);
178
+ if (trail >= 0xDC00 && trail <= 0xDFFF) { second = (second - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000; secondUnits = 2; }
179
+ }
180
+ if (first !== second) return first < second ? -1 : 1;
181
+ leftOffset += firstUnits;
182
+ rightOffset += secondUnits;
183
+ }
184
+ return leftOffset < left.length ? 1 : rightOffset < right.length ? -1 : 0;
185
+ }
186
+ function __velarOrderedCompare(kind, left, right) {
187
+ if (kind === "string") return __velarCodePointCompare(left, right);
188
+ return left < right ? -1 : left > right ? 1 : 0;
189
+ }
190
+ function __velarRecordFields(value, name) {
191
+ value = __velarReactiveRaw(value);
192
+ if (!__velarIsRecord(value) || __velarCollectionRecordOwnSymbols(value).length > 0) throw new __velarCollectionNativeTypeError(name + " requires a plain Record");
193
+ const fields = __velarCollectionRecordOwnNames(value);
194
+ if (fields.length > __velarMaxCollectionItems) throw new __velarCollectionRecordNativeRangeError("A Record cannot exceed 1000000 fields");
195
+ for (let index = 0; index < fields.length; index += 1) {
196
+ const descriptor = __velarCollectionRecordGetOwnPropertyDescriptor(value, fields[index]);
197
+ if (!descriptor?.enumerable || !descriptor.configurable || !descriptor.writable || !("value" in descriptor)) throw new __velarCollectionNativeTypeError(name + " requires ordinary mutable enumerable data fields");
198
+ }
199
+ return fields;
200
+ }
201
+
202
+ function __velarCollectionIterator(value) {
203
+ if (typeof value === "string") return String.prototype[Symbol.iterator].call(value);
204
+ value = __velarReactiveRaw(value);
205
+ if (__velarCollectionListIsArray(value)) return __velarReactiveListIterator(value);
206
+ if (__velarIsMap(value)) return __velarReactiveMapKeyIterator(value);
207
+ if (__velarIsSet(value)) return __velarReactiveSetIterator(value);
208
+ if (__velarIsRecord(value)) return __velarReactiveRecordIterator(value);
209
+ throw new __velarCollectionNativeTypeError("VelarScript iteration requires a List, Set, Map, or Record");
210
+ }
211
+ function* __velarCollectionPairIterator(value) {
212
+ const raw = __velarReactiveRaw(value);
213
+ if (__velarIsMap(raw)) {
214
+ if (__velarCollectionSetMapMapSize(raw) > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A Map cannot exceed 1000000 entries");
215
+ __velarReactiveCollectionTrack(raw);
216
+ const iterator = __velarCollectionSetMapMapEntries(raw);
217
+ while (true) { const step = __velarCollectionSetMapMapNext(iterator); if (step.done) return; const entry = step.value; yield [__velarReactiveCollectionRead(raw, __velarReactiveIterateKey, entry[0]), __velarReactiveCollectionRead(raw, entry[0], entry[1])]; }
218
+ }
219
+ if (__velarIsRecord(raw)) {
220
+ const fields = __velarRecordFields(raw, "Record iteration");
221
+ __velarReactiveCollectionTrack(raw);
222
+ for (let index = 0; index < fields.length; index += 1) {
223
+ const field = fields[index];
224
+ const descriptor = __velarCollectionRecordGetOwnPropertyDescriptor(raw, field);
225
+ // COL-D1: the key snapshot can outlive the field — a body that removes
226
+ // a later key must see that key skipped (Map iteration parity), not a
227
+ // raw TypeError from reading a missing descriptor.
228
+ if (descriptor === undefined) continue;
229
+ yield [__velarReactiveCollectionRead(raw, __velarReactiveIterateKey, field), __velarReactiveCollectionRead(raw, field, descriptor.value)];
230
+ }
231
+ return;
232
+ }
233
+ let index = 0;
234
+ for (const item of __velarCollectionIterator(value)) yield [item, index++];
235
+ }
236
+
237
+ function __velarCollectionSize(value) {
238
+ value = __velarReactiveRaw(value);
239
+ __velarReactiveCollectionTrack(value, __velarReactiveStructureKey);
240
+ if (__velarCollectionListIsArray(value)) return __velarValidateOwnedList(value, "List size").length;
241
+ if (__velarIsRecord(value)) return __velarRecordFields(value, "Record size").length;
242
+ const size = __velarIsMap(value) ? __velarCollectionSetMapMapSize(value) : __velarIsSet(value) ? __velarCollectionSetMapSetSize(value) : null;
243
+ if (size === null) throw new __velarCollectionNativeTypeError("VelarScript size requires a List, Set, Map, or Record");
244
+ if (size > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A collection cannot exceed 1000000 items");
245
+ return size;
246
+ }
247
+
248
+ function __velarCreateList(parts) {
249
+ const output = [];
250
+ __velarValidateDenseList(parts, "List construction parts");
251
+ for (let partIndex = 0; partIndex < parts.length; partIndex += 1) {
252
+ const part = __velarValidateDenseList(__velarCollectionListGetOwnPropertyDescriptor(parts, partIndex).value, "List construction part");
253
+ const spread = part[0];
254
+ const read = part[1];
255
+ if (!spread) {
256
+ if (output.length >= __velarMaxCollectionItems) throw new __velarCollectionListNativeRangeError("A List cannot exceed 1000000 items");
257
+ output[output.length] = __velarCollectionValue(read());
258
+ continue;
259
+ }
260
+ const values = __velarValidateOwnedList(read(), "List spread");
261
+ if (output.length + values.length > __velarMaxCollectionItems) throw new __velarCollectionListNativeRangeError("A List cannot exceed 1000000 items");
262
+ for (let index = 0; index < values.length; index += 1) output[output.length] = __velarCollectionValue(__velarOwnedListElement(values, index, "List spread"));
263
+ }
264
+ return __velarMarkOwnedList(output);
265
+ }
266
+ async function __velarCreateListAsync(parts) {
267
+ const output = [];
268
+ __velarValidateDenseList(parts, "List construction parts");
269
+ for (let partIndex = 0; partIndex < parts.length; partIndex += 1) {
270
+ const part = __velarValidateDenseList(__velarCollectionListGetOwnPropertyDescriptor(parts, partIndex).value, "List construction part");
271
+ const spread = part[0];
272
+ const asynchronous = part[1];
273
+ const read = part[2];
274
+ if (!spread) {
275
+ if (output.length >= __velarMaxCollectionItems) throw new __velarCollectionListNativeRangeError("A List cannot exceed 1000000 items");
276
+ output[output.length] = __velarCollectionValue(asynchronous ? await read() : read());
277
+ continue;
278
+ }
279
+ const values = __velarValidateOwnedList(asynchronous ? await read() : read(), "List spread");
280
+ if (output.length + values.length > __velarMaxCollectionItems) throw new __velarCollectionListNativeRangeError("A List cannot exceed 1000000 items");
281
+ for (let index = 0; index < values.length; index += 1) output[output.length] = __velarCollectionValue(__velarOwnedListElement(values, index, "List spread"));
282
+ }
283
+ return __velarMarkOwnedList(output);
284
+ }
285
+
286
+ // Members and keys are stored raw. Every membership and key lookup unwraps
287
+ // its argument (docs/web-api.md: "Map keys and Set members are unwrapped
288
+ // before lookup"), so a construction that stored a reactive proxy would split
289
+ // member identity and make every later lookup miss.
290
+ function __velarCreateSet(value) {
291
+ const output = new __velarCollectionNativeSet();
292
+ if (value === undefined) return output;
293
+ value = __velarReactiveRaw(value);
294
+ if (__velarCollectionListIsArray(value)) { const values = __velarValidateOwnedList(value, "Set construction"); for (let index = 0; index < values.length; index += 1) __velarCollectionSetMapSetAdd(output, __velarCollectionValue(__velarReactiveRaw(__velarOwnedListElement(values, index, "Set construction")))); return output; }
295
+ if (!__velarIsSet(value)) throw new __velarCollectionNativeTypeError("Set construction requires a List or Set");
296
+ if (__velarCollectionSetMapSetSize(value) > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A Set cannot exceed 1000000 items");
297
+ const iterator = __velarCollectionSetMapSetValues(value); while (true) { const step = __velarCollectionSetMapSetNext(iterator); if (step.done) return output; __velarCollectionSetMapSetAdd(output, __velarCollectionValue(__velarReactiveRaw(step.value))); }
298
+ }
299
+
300
+ function __velarCreateMap(value) {
301
+ const output = new __velarCollectionNativeMap();
302
+ if (value === undefined) return output;
303
+ value = __velarReactiveRaw(value);
304
+ if (__velarIsMap(value)) {
305
+ if (__velarCollectionSetMapMapSize(value) > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A Map cannot exceed 1000000 entries");
306
+ const iterator = __velarCollectionSetMapMapEntries(value); while (true) { const step = __velarCollectionSetMapMapNext(iterator); if (step.done) return output; const entry = step.value; __velarCollectionSetMapMapSet(output, __velarCollectionValue(__velarReactiveRaw(entry[0])), __velarCollectionValue(__velarReactiveRaw(entry[1]))); }
307
+ }
308
+ if (__velarCollectionListIsArray(value)) {
309
+ const entries = __velarValidateOwnedList(value, "Map construction");
310
+ for (let index = 0; index < entries.length; index += 1) {
311
+ const entry = __velarValidateOwnedList(__velarOwnedListElement(entries, index, "Map construction"), "Map entry construction");
312
+ if (entry.length !== 2) throw new __velarCollectionNativeTypeError("Map entry construction requires exactly [key, value]");
313
+ __velarCollectionSetMapMapSet(output, __velarCollectionValue(__velarReactiveRaw(__velarOwnedListElement(entry, 0, "Map entry construction"))), __velarCollectionValue(__velarReactiveRaw(__velarOwnedListElement(entry, 1, "Map entry construction"))));
314
+ }
315
+ return output;
316
+ }
317
+ if (value && typeof value === "object") {
318
+ const prototype = __velarCollectionHostCall(__velarCollectionGetPrototypeOf, __velarCollectionNativeObject, [value]);
319
+ const names = __velarCollectionRecordOwnNames(value);
320
+ if ((prototype !== __velarCollectionObjectPrototype && prototype !== null) || __velarCollectionRecordOwnSymbols(value).length > 0 || names.length > __velarMaxCollectionItems) throw new __velarCollectionNativeTypeError("Map record construction requires an ordinary record");
321
+ for (let index = 0; index < names.length; index += 1) {
322
+ const name = names[index];
323
+ const descriptor = __velarCollectionRecordGetOwnPropertyDescriptor(value, name);
324
+ if (!descriptor?.enumerable || !("value" in descriptor)) throw new __velarCollectionNativeTypeError("Map record construction requires own enumerable data fields");
325
+ __velarCollectionSetMapMapSet(output, name, __velarCollectionValue(__velarReactiveRaw(descriptor.value)));
326
+ }
327
+ return output;
328
+ }
329
+ throw new __velarCollectionNativeTypeError("Map construction requires a Map, a List of [key, value] Lists, or a record");
330
+ }
331
+
332
+ function __velarCollectionGet(value, key) {
333
+ value = __velarReactiveRaw(value);
334
+ if (__velarCollectionListIsArray(value)) {
335
+ __velarValidateOwnedList(value, "List.get");
336
+ if (!__velarCollectionListIsInteger(key)) throw new __VelarIndexError("List.get index must be an integer");
337
+ const index = key < 0 ? value.length + key : key;
338
+ if (index >= 0 && index < value.length) return __velarReactiveCollectionRead(value, index, __velarOwnedListElement(value, index, "List.get"));
339
+ __velarReactiveCollectionTrack(value, key < 0 ? __velarReactiveIterateKey : index);
340
+ __velarReactiveCollectionTrack(value);
341
+ return null;
342
+ }
343
+ if (__velarIsRecord(value)) {
344
+ if (typeof key !== "string") throw new __velarCollectionNativeTypeError("Record.get requires a string key");
345
+ __velarRecordFields(value, "Record.get");
346
+ __velarReactiveCollectionTrack(value, key);
347
+ const descriptor = __velarCollectionRecordGetOwnPropertyDescriptor(value, key);
348
+ return descriptor === undefined ? null : __velarReactiveCollectionRead(value, key, descriptor.value);
349
+ }
350
+ if (!__velarIsMap(value)) throw new __velarCollectionNativeTypeError("Map.get requires a Map");
351
+ const size = __velarCollectionSetMapMapSize(value);
352
+ if (size > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A Map cannot exceed 1000000 entries");
353
+ key = __velarReactiveRaw(key);
354
+ __velarReactiveCollectionTrack(value, key);
355
+ const item = __velarCollectionSetMapMapGet(value, key);
356
+ return item === undefined ? null : __velarReactiveCollectionRead(value, key, item);
357
+ }
358
+
359
+ function __velarCollectionSlice(value, start = 0, end = null) {
360
+ value = __velarValidateOwnedList(value, "List.slice");
361
+ __velarReactiveCollectionTrack(value);
362
+ if (end === null) end = value.length;
363
+ // COL-I2: every List position error is an IndexError.
364
+ if (!__velarCollectionListIsInteger(start) || !__velarCollectionListIsInteger(end)) {
365
+ throw new __VelarIndexError("List.slice positions must be integers");
366
+ }
367
+ const length = value.length;
368
+ const first = start < 0 ? __velarCollectionListMaximum(length + start, 0) : __velarCollectionListMinimum(start, length);
369
+ const last = end < 0 ? __velarCollectionListMaximum(length + end, 0) : __velarCollectionListMinimum(end, length);
370
+ const output = [];
371
+ for (let index = first; index < __velarCollectionListMaximum(first, last); index += 1) output[output.length] = __velarReactiveCollectionRead(value, index, __velarOwnedListElement(value, index, "List.slice"));
372
+ return __velarMarkOwnedList(output);
373
+ }
374
+
375
+ class __VelarIndexError extends __velarCollectionListNativeRangeError {
376
+ constructor(message) {
377
+ super(message);
378
+ this.name = "IndexError";
379
+ }
380
+ }
381
+ // D51 rule 107: 'code' answers with the class a value was constructed from, so
382
+ // the compiler-owned class carries the source-level name it reports.
383
+ __velarCollectionListDefineProperty(__VelarIndexError, "name", { value: "IndexError", writable: false, enumerable: false, configurable: true });
384
+ function __velarStrictListIndex(value, requested) {
385
+ if (!__velarCollectionListIsInteger(requested)) throw new __VelarIndexError("List index must be an in-range integer");
386
+ const index = requested < 0 ? value.length + requested : requested;
387
+ if (index < 0 || index >= value.length) throw new __VelarIndexError("List index must be an in-range integer");
388
+ return index;
389
+ }
390
+ function __velarIndex(value, index) {
391
+ value = __velarReactiveRaw(value);
392
+ if (__velarCollectionListIsArray(value)) {
393
+ __velarValidateOwnedList(value, "List index");
394
+ index = __velarStrictListIndex(value, index);
395
+ return __velarReactiveCollectionRead(value, index, __velarOwnedListElement(value, index, "List index"));
396
+ }
397
+ if (!__velarIsRecord(value) || typeof index !== "string") throw new __velarCollectionNativeTypeError("Record index requires a plain record and a string key");
398
+ __velarRecordFields(value, "Record index");
399
+ const descriptor = __velarCollectionRecordGetOwnPropertyDescriptor(value, index);
400
+ return __velarReactiveCollectionRead(value, index, descriptor?.value);
401
+ }
402
+ function __velarOptionalIndex(value, index) {
403
+ return value == null ? null : __velarIndex(value, index());
404
+ }
405
+ function __velarSetIndex(value, index, next) {
406
+ value = __velarReactiveRaw(value);
407
+ if (__velarCollectionListIsArray(value)) {
408
+ __velarValidateOwnedList(value, "List index assignment");
409
+ index = __velarStrictListIndex(value, index);
410
+ const previous = __velarOwnedListElement(value, index, "List index assignment");
411
+ next = __velarReactiveRaw(next);
412
+ if (__velarCollectionListObjectIs(__velarReactiveRaw(previous), next)) return next;
413
+ value[index] = next;
414
+ __velarReactiveCollectionUnlink(value, previous);
415
+ __velarReactiveCollectionLink(value, next);
416
+ __velarReactiveCollectionTrigger(value, index, true, false);
417
+ __velarMarkOwnedList(value);
418
+ return next;
419
+ }
420
+ if (!__velarIsRecord(value) || typeof index !== "string") throw new __velarCollectionNativeTypeError("Record index assignment requires a plain record and a string key");
421
+ const fields = __velarRecordFields(value, "Record index assignment");
422
+ const descriptor = __velarCollectionRecordGetOwnPropertyDescriptor(value, index);
423
+ if (descriptor === undefined && fields.length >= 1000000) throw new __velarCollectionRecordNativeRangeError("A Record cannot exceed 1000000 fields");
424
+ const previous = descriptor?.value;
425
+ next = __velarReactiveRaw(next);
426
+ if (descriptor !== undefined && __velarCollectionRecordObjectIs(__velarReactiveRaw(previous), next)) return next;
427
+ __velarCollectionRecordDefineProperty(value, index, { value: next, writable: true, enumerable: true, configurable: true });
428
+ __velarReactiveCollectionUnlink(value, previous);
429
+ __velarReactiveCollectionLink(value, next);
430
+ __velarReactiveCollectionTrigger(value, index, true, descriptor === undefined);
431
+ return next;
432
+ }
433
+
434
+ function __velarListAppend(value, item) {
435
+ value = __velarValidateOwnedList(value, "List.append");
436
+ if (value.length >= __velarMaxCollectionItems) throw new __velarCollectionListNativeRangeError("A List cannot exceed 1000000 items");
437
+ item = __velarReactiveRaw(item);
438
+ const index = value.length;
439
+ __velarCollectionListDefineProperty(value, index, { value: item, writable: true, enumerable: true, configurable: true });
440
+ __velarReactiveCollectionLink(value, item);
441
+ __velarReactiveCollectionTrigger(value, index, true, true, index);
442
+ __velarMarkOwnedList(value);
443
+ return null;
444
+ }
445
+
446
+ function __velarListExtend(value, items) {
447
+ value = __velarValidateOwnedList(value, "List.extend");
448
+ items = __velarValidateOwnedList(items, "List.extend");
449
+ if (value.length + items.length > __velarMaxCollectionItems) throw new __velarCollectionListNativeRangeError("A List cannot exceed 1000000 items");
450
+ const start = value.length;
451
+ const count = items.length;
452
+ for (let index = 0; index < count; index += 1) { const item = __velarReactiveRaw(__velarOwnedListElement(items, index, "List.extend")); __velarCollectionListDefineProperty(value, value.length, { value: item, writable: true, enumerable: true, configurable: true }); __velarReactiveCollectionLink(value, item); }
453
+ if (count > 0) __velarReactiveCollectionTrigger(value, start, true, true, start);
454
+ __velarMarkOwnedList(value);
455
+ return null;
456
+ }
457
+
458
+ function __velarListInsert(value, index, item) {
459
+ value = __velarValidateOwnedList(value, "List.insert");
460
+ // COL-I2: every List position error is an IndexError, and the accepted
461
+ // range 0..size (inclusive) is the charter's insert contract.
462
+ if (!__velarCollectionListIsInteger(index) || index < 0 || index > value.length) throw new __VelarIndexError("List.insert index must be an integer from 0 through size");
463
+ if (value.length >= __velarMaxCollectionItems) throw new __velarCollectionListNativeRangeError("A List cannot exceed 1000000 items");
464
+ item = __velarReactiveRaw(item);
465
+ __velarCollectionListDefineProperty(value, value.length, { value: item, writable: true, enumerable: true, configurable: true });
466
+ for (let cursor = value.length - 1; cursor > index; cursor -= 1) value[cursor] = __velarOwnedListElement(value, cursor - 1, "List.insert");
467
+ value[index] = item;
468
+ __velarMarkOwnedList(value);
469
+ __velarReactiveCollectionLink(value, item);
470
+ __velarReactiveCollectionTrigger(value, index, true, true, index);
471
+ return null;
472
+ }
473
+
474
+ function __velarListPop(value, requested = -1) {
475
+ value = __velarValidateOwnedList(value, "List.pop");
476
+ if (!__velarCollectionListIsInteger(requested)) throw new __VelarIndexError("List.pop index must be an integer");
477
+ const index = requested < 0 ? value.length + requested : requested;
478
+ if (value.length === 0) throw new __VelarIndexError("List.pop requires a non-empty List");
479
+ if (index < 0 || index >= value.length) throw new __VelarIndexError("List.pop index must be an in-range integer");
480
+ const item = __velarOwnedListElement(value, index, "List.pop");
481
+ for (let cursor = index; cursor < value.length - 1; cursor += 1) value[cursor] = __velarOwnedListElement(value, cursor + 1, "List.pop");
482
+ value.length -= 1;
483
+ __velarMarkOwnedList(value);
484
+ __velarReactiveCollectionUnlink(value, item);
485
+ __velarReactiveCollectionTrigger(value, index, true, true, index);
486
+ return item;
487
+ }
488
+ function __velarListRemove(value, item) { value = __velarValidateOwnedList(value, "List.remove"); item = __velarReactiveRaw(item); for (let index = 0; index < value.length; index += 1) if (__velarSameValueZero(__velarReactiveRaw(__velarOwnedListElement(value, index, "List.remove")), item)) { __velarListPop(value, index); return true; } return false; }
489
+ function __velarListCopy(value) { __velarReactiveCollectionTrack(value); return __velarCopyList(value, "List.copy"); }
490
+ function __velarListCount(value, item) { value = __velarValidateOwnedList(value, "List.count"); item = __velarReactiveRaw(item); __velarReactiveCollectionTrack(value); let count = 0; for (let index = 0; index < value.length; index += 1) if (__velarSameValueZero(__velarReactiveRaw(__velarOwnedListElement(value, index, "List.count")), item)) count += 1; return count; }
491
+ function __velarListFind(value, predicate) { const items = __velarCopyList(value, "List.find"); __velarReactiveCollectionTrack(value); for (let index = 0; index < items.length; index += 1) { const item = __velarReactiveCollectionRead(value, index, items[index]); const accepted = predicate(item); if (typeof accepted !== "boolean") throw new __velarCollectionNativeTypeError("List.find predicate must return bool"); if (accepted) return item; } return null; }
492
+ function __velarListIndex(value, item) { value = __velarValidateOwnedList(value, "List.index"); item = __velarReactiveRaw(item); __velarReactiveCollectionTrack(value); for (let index = 0; index < value.length; index += 1) if (__velarSameValueZero(__velarReactiveRaw(__velarOwnedListElement(value, index, "List.index")), item)) return index; return null; }
493
+ function __velarListSome(value, predicate) { const items = __velarCopyList(value, "List.some"); __velarReactiveCollectionTrack(value); for (let index = 0; index < items.length; index += 1) { const accepted = predicate(__velarReactiveCollectionRead(value, index, items[index])); if (typeof accepted !== "boolean") throw new __velarCollectionNativeTypeError("List.some predicate must return bool"); if (accepted) return true; } return false; }
494
+ function __velarListEvery(value, predicate) { const items = __velarCopyList(value, "List.every"); __velarReactiveCollectionTrack(value); for (let index = 0; index < items.length; index += 1) { const accepted = predicate(__velarReactiveCollectionRead(value, index, items[index])); if (typeof accepted !== "boolean") throw new __velarCollectionNativeTypeError("List.every predicate must return bool"); if (!accepted) return false; } return true; }
495
+ function __velarListMap(value, transform) { const items = __velarCopyList(value, "List.map"); __velarReactiveCollectionTrack(value); const output = new __velarCollectionNativeArray(items.length); for (let index = 0; index < items.length; index += 1) { const item = transform(__velarReactiveCollectionRead(value, index, items[index])); output[index] = item === undefined ? null : __velarReactiveRaw(item); } return __velarMarkOwnedList(output); }
496
+ function __velarListFilter(value, predicate) { const items = __velarCopyList(value, "List.filter"); __velarReactiveCollectionTrack(value); const output = []; for (let index = 0; index < items.length; index += 1) { const item = __velarReactiveCollectionRead(value, index, items[index]); const accepted = predicate(item); if (typeof accepted !== "boolean") throw new __velarCollectionNativeTypeError("List.filter predicate must return bool"); if (accepted) output[output.length] = __velarReactiveRaw(item); } return __velarMarkOwnedList(output); }
497
+ function __velarListReduce(value, combine, initial) { const items = __velarCopyList(value, "List.reduce"); __velarReactiveCollectionTrack(value); let result = initial; for (let index = 0; index < items.length; index += 1) { const next = combine(result, __velarReactiveCollectionRead(value, index, items[index])); result = next === undefined ? null : next; } return result; }
498
+ function __velarListJoin(value, separator = "") { value = __velarValidateOwnedList(value, "List.join"); __velarReactiveCollectionTrack(value); if (typeof separator !== "string") throw new __velarCollectionNativeTypeError("List.join separator must be string"); for (let index = 0; index < value.length; index += 1) if (typeof __velarOwnedListElement(value, index, "List.join") !== "string") throw new __velarCollectionNativeTypeError("List.join requires string values"); return __velarCollectionListHostJoin(value, separator); }
499
+ function __velarOrderedListValue(value, name, kind = null) { const current = typeof value; if (current === "number" && __velarCollectionListIsNaN(value)) throw new __velarCollectionNativeTypeError(name + " found NaN, which has no ordering; drop it with filter(x => not x.isNaN()) or fix the upstream computation"); if ((current !== "string" && current !== "number") || (kind !== null && current !== kind)) throw new __velarCollectionNativeTypeError(name + " requires uniform numbers or strings"); return current; }
500
+ function __velarListSorted(value, compare = null, by = null) {
501
+ if (compare !== null && by !== null) throw new __velarCollectionNativeTypeError("List.sorted accepts either a comparator or by, not both");
502
+ if (compare !== null && typeof compare !== "function") throw new __velarCollectionNativeTypeError("List.sorted comparator must be a function");
503
+ if (by !== null && typeof by !== "function") throw new __velarCollectionNativeTypeError("List.sorted by must be a function");
504
+ __velarReactiveCollectionTrack(value);
505
+ const output = __velarCopyList(value, "List.sorted");
506
+ if (by !== null) {
507
+ let kind = null;
508
+ const decorated = new __velarCollectionNativeArray(output.length);
509
+ for (let index = 0; index < output.length; index += 1) { const item = output[index]; const key = by(__velarReactiveCollectionRead(value, index, item)); kind = __velarOrderedListValue(key, "List.sorted by", kind); decorated[index] = { item, key }; }
510
+ __velarCollectionListHostSort(decorated, (left, right) => __velarOrderedCompare(kind, left.key, right.key));
511
+ const selected = new __velarCollectionNativeArray(decorated.length);
512
+ for (let index = 0; index < decorated.length; index += 1) selected[index] = decorated[index].item;
513
+ return __velarMarkOwnedList(selected);
514
+ }
515
+ let kind = null;
516
+ if (compare === null) { for (let index = 0; index < output.length; index += 1) kind = __velarOrderedListValue(output[index], "List.sorted()", kind); }
517
+ const compareValues = compare ?? ((left, right) => { kind = __velarOrderedListValue(left, "List.sorted()", kind); __velarOrderedListValue(right, "List.sorted()", kind); return __velarOrderedCompare(kind, left, right); });
518
+ __velarCollectionListHostSort(output, (left, right) => { const order = compareValues(left, right); if (typeof order !== "number" || !__velarCollectionListIsFinite(order)) throw new __velarCollectionNativeTypeError("List.sorted comparator must return a finite number"); return order; });
519
+ return output;
520
+ }
521
+ function __velarListSum(value) { const items = __velarCopyList(value, "List.sum"); __velarReactiveCollectionTrack(value); let total = 0; for (let index = 0; index < items.length; index += 1) { const item = __velarReactiveCollectionRead(value, index, items[index]); if (typeof item !== "number") throw new __velarCollectionNativeTypeError("List.sum requires numbers"); if (__velarCollectionListIsNaN(item)) throw new __velarCollectionNativeTypeError("List.sum found NaN, which poisons the total; drop it with filter(x => not x.isNaN()) or fix the upstream computation"); total += item; } return total; }
522
+ function __velarListExtremum(value, maximum) { const items = __velarCopyList(value, maximum ? "List.max" : "List.min"); __velarReactiveCollectionTrack(value); if (items.length === 0) return null; let result = __velarReactiveCollectionRead(value, 0, items[0]); let kind = __velarOrderedListValue(result, maximum ? "List.max" : "List.min"); for (let index = 1; index < items.length; index += 1) { const item = __velarReactiveCollectionRead(value, index, items[index]); __velarOrderedListValue(item, maximum ? "List.max" : "List.min", kind); const order = __velarOrderedCompare(kind, item, result); if (maximum ? order > 0 : order < 0) result = item; } return result; }
523
+ function __velarListMin(value) { return __velarListExtremum(value, false); }
524
+ function __velarListMax(value) { return __velarListExtremum(value, true); }
525
+ function __velarListReversed(value) { __velarReactiveCollectionTrack(value); const output = __velarCopyList(value, "List.reversed"); __velarCollectionListHostReverse(output); return output; }
526
+ // COL-U1: map-then-flatten-one-level. The transform must return a List for
527
+ // every element; its items append in order, under the one 1,000,000 budget.
528
+ function __velarListFlatMap(value, transform) {
529
+ const items = __velarCopyList(value, "List.flatMap");
530
+ __velarReactiveCollectionTrack(value);
531
+ const output = [];
532
+ for (let index = 0; index < items.length; index += 1) {
533
+ const part = transform(__velarReactiveCollectionRead(value, index, items[index]));
534
+ const values = __velarValidateOwnedList(part, "List.flatMap transform result");
535
+ if (output.length + values.length > __velarMaxCollectionItems) throw new __velarCollectionListNativeRangeError("A List cannot exceed 1000000 items");
536
+ for (let cursor = 0; cursor < values.length; cursor += 1) output[output.length] = __velarCollectionValue(__velarReactiveRaw(__velarOwnedListElement(values, cursor, "List.flatMap")));
537
+ }
538
+ return __velarMarkOwnedList(output);
539
+ }
540
+
541
+ function __velarSetAdd(value, item) {
542
+ value = __velarReactiveRaw(value);
543
+ item = __velarReactiveRaw(item);
544
+ const size = __velarCollectionSetMapSetSize(value);
545
+ if (size >= __velarMaxCollectionItems && !__velarCollectionSetMapSetHas(value, item)) throw new __velarCollectionSetMapNativeRangeError("A Set cannot exceed 1000000 items");
546
+ if (__velarCollectionSetMapSetHas(value, item)) return null;
547
+ __velarCollectionSetMapSetAdd(value, item);
548
+ __velarReactiveCollectionLink(value, item);
549
+ __velarReactiveCollectionTrigger(value, item, true, true);
550
+ return null;
551
+ }
552
+
553
+ function __velarSetUpdate(value, items) {
554
+ value = __velarReactiveRaw(value);
555
+ items = __velarReactiveRaw(items);
556
+ if (!__velarCollectionListIsArray(items) && !__velarIsSet(items)) throw new __velarCollectionNativeTypeError("Set.update requires a List or Set");
557
+ let entries;
558
+ if (__velarCollectionListIsArray(items)) entries = __velarCopyList(items, "Set.update");
559
+ else { const sourceSize = __velarCollectionSetMapSetSize(items); if (sourceSize > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A Set cannot exceed 1000000 items"); entries = new __velarCollectionNativeArray(sourceSize); const iterator = __velarCollectionSetMapSetValues(items); let index = 0; while (true) { const step = __velarCollectionSetMapSetNext(iterator); if (step.done) break; entries[index++] = step.value; } }
560
+ const additions = new __velarCollectionNativeSet();
561
+ for (let index = 0; index < entries.length; index += 1) { const item = __velarReactiveRaw(entries[index]); if (!__velarCollectionSetMapSetHas(value, item)) __velarCollectionSetMapSetAdd(additions, item); }
562
+ const size = __velarCollectionSetMapSetSize(value);
563
+ const added = __velarCollectionSetMapSetSize(additions);
564
+ if (size + added > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A Set cannot exceed 1000000 items");
565
+ const iterator = __velarCollectionSetMapSetValues(additions); while (true) { const step = __velarCollectionSetMapSetNext(iterator); if (step.done) break; const item = step.value; __velarCollectionSetMapSetAdd(value, item); __velarReactiveCollectionLink(value, item); }
566
+ // Every member added publishes its own key exactly as Set.add does: a
567
+ // membership observer (x in tags) tracks the member key, not the iterate
568
+ // key, so triggering only iteration would leave it stale.
569
+ const published = __velarCollectionSetMapSetValues(additions); while (true) { const step = __velarCollectionSetMapSetNext(published); if (step.done) break; __velarReactiveCollectionTrigger(value, step.value, true, true); }
570
+ if (added > 0) __velarReactiveCollectionTrigger(value, __velarReactiveIterateKey, true, true);
571
+ return null;
572
+ }
573
+ function __velarSetCopy(value) { value = __velarReactiveRaw(value); __velarReactiveCollectionTrack(value); const size = __velarCollectionSetMapSetSize(value); if (size > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A Set cannot exceed 1000000 items"); const output = new __velarCollectionNativeSet(); const iterator = __velarCollectionSetMapSetValues(value); while (true) { const step = __velarCollectionSetMapSetNext(iterator); if (step.done) return output; __velarCollectionSetMapSetAdd(output, step.value); } }
574
+ // COL-U2: Set algebra. Each method reads both operands, copies (never
575
+ // mutates, exactly like sorted), and answers by SameValueZero membership.
576
+ function __velarSetAlgebraOperands(value, other, name) {
577
+ value = __velarReactiveRaw(value);
578
+ other = __velarReactiveRaw(other);
579
+ if (!__velarIsSet(other)) throw new __velarCollectionNativeTypeError(name + " requires a Set");
580
+ if (__velarCollectionSetMapSetSize(value) > __velarMaxCollectionItems || __velarCollectionSetMapSetSize(other) > __velarMaxCollectionItems) {
581
+ throw new __velarCollectionSetMapNativeRangeError("A Set cannot exceed 1000000 items");
582
+ }
583
+ __velarReactiveCollectionTrack(value);
584
+ __velarReactiveCollectionTrack(other);
585
+ return [value, other];
586
+ }
587
+ function __velarSetUnion(value, other) {
588
+ const operands = __velarSetAlgebraOperands(value, other, "Set.union");
589
+ const output = new __velarCollectionNativeSet();
590
+ const first = __velarCollectionSetMapSetValues(operands[0]);
591
+ while (true) { const step = __velarCollectionSetMapSetNext(first); if (step.done) break; __velarCollectionSetMapSetAdd(output, step.value); }
592
+ const second = __velarCollectionSetMapSetValues(operands[1]);
593
+ while (true) {
594
+ const step = __velarCollectionSetMapSetNext(second);
595
+ if (step.done) break;
596
+ const member = __velarCollectionValue(__velarReactiveRaw(step.value));
597
+ if (!__velarCollectionSetMapSetHas(output, member) && __velarCollectionSetMapSetSize(output) >= __velarMaxCollectionItems) {
598
+ throw new __velarCollectionSetMapNativeRangeError("A Set cannot exceed 1000000 items");
599
+ }
600
+ __velarCollectionSetMapSetAdd(output, member);
601
+ }
602
+ return output;
603
+ }
604
+ function __velarSetIntersection(value, other) {
605
+ const operands = __velarSetAlgebraOperands(value, other, "Set.intersection");
606
+ const output = new __velarCollectionNativeSet();
607
+ const iterator = __velarCollectionSetMapSetValues(operands[0]);
608
+ while (true) { const step = __velarCollectionSetMapSetNext(iterator); if (step.done) return output; if (__velarCollectionSetMapSetHas(operands[1], step.value)) __velarCollectionSetMapSetAdd(output, step.value); }
609
+ }
610
+ function __velarSetDifference(value, other) {
611
+ const operands = __velarSetAlgebraOperands(value, other, "Set.difference");
612
+ const output = new __velarCollectionNativeSet();
613
+ const iterator = __velarCollectionSetMapSetValues(operands[0]);
614
+ while (true) { const step = __velarCollectionSetMapSetNext(iterator); if (step.done) return output; if (!__velarCollectionSetMapSetHas(operands[1], step.value)) __velarCollectionSetMapSetAdd(output, step.value); }
615
+ }
616
+
617
+ function __velarMapSet(value, key, item) {
618
+ value = __velarReactiveRaw(value);
619
+ key = __velarReactiveRaw(key);
620
+ item = __velarReactiveRaw(item);
621
+ const size = __velarCollectionSetMapMapSize(value);
622
+ if (size >= __velarMaxCollectionItems && !__velarCollectionSetMapMapHas(value, key)) throw new __velarCollectionSetMapNativeRangeError("A Map cannot exceed 1000000 entries");
623
+ const present = __velarCollectionSetMapMapHas(value, key);
624
+ const previous = present ? __velarCollectionSetMapMapGet(value, key) : undefined;
625
+ if (present && __velarCollectionListObjectIs(__velarReactiveRaw(previous), item)) return null;
626
+ __velarCollectionSetMapMapSet(value, key, item);
627
+ __velarReactiveCollectionUnlink(value, previous);
628
+ __velarReactiveCollectionLink(value, key);
629
+ __velarReactiveCollectionLink(value, item);
630
+ __velarReactiveCollectionTrigger(value, key, true, !present);
631
+ return null;
632
+ }
633
+
634
+ function __velarMapUpdate(value, items) {
635
+ value = __velarReactiveRaw(value);
636
+ items = __velarReactiveRaw(items);
637
+ if (!__velarIsMap(items)) throw new __velarCollectionNativeTypeError("Map.update requires a Map");
638
+ const sourceSize = __velarCollectionSetMapMapSize(items);
639
+ if (sourceSize > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A Map cannot exceed 1000000 entries");
640
+ const size = __velarCollectionSetMapMapSize(value);
641
+ let additions = 0;
642
+ const keys = __velarCollectionSetMapMapKeys(items); while (true) { const step = __velarCollectionSetMapMapNext(keys); if (step.done) break; if (!__velarCollectionSetMapMapHas(value, step.value)) additions += 1; }
643
+ if (size + additions > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A Map cannot exceed 1000000 entries");
644
+ const entries = __velarCollectionSetMapMapEntries(items); while (true) { const step = __velarCollectionSetMapMapNext(entries); if (step.done) break; const entry = step.value; __velarMapSet(value, entry[0], entry[1]); }
645
+ return null;
646
+ }
647
+ function __velarMapCopy(value) { value = __velarReactiveRaw(value); __velarReactiveCollectionTrack(value); const size = __velarCollectionSetMapMapSize(value); if (size > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A Map cannot exceed 1000000 entries"); const output = new __velarCollectionNativeMap(); const iterator = __velarCollectionSetMapMapEntries(value); while (true) { const step = __velarCollectionSetMapMapNext(iterator); if (step.done) return output; const entry = step.value; __velarCollectionSetMapMapSet(output, entry[0], entry[1]); } }
648
+
649
+ function __velarRecordSet(value, key, item) {
650
+ value = __velarReactiveRaw(value);
651
+ if (typeof key !== "string") throw new __velarCollectionNativeTypeError("Record.set requires a string key");
652
+ const fields = __velarRecordFields(value, "Record.set");
653
+ const descriptor = __velarCollectionRecordGetOwnPropertyDescriptor(value, key);
654
+ if (descriptor !== undefined && !descriptor.writable) throw new __velarCollectionNativeTypeError("Record.set requires a writable data field");
655
+ if (descriptor === undefined && fields.length >= __velarMaxCollectionItems) throw new __velarCollectionRecordNativeRangeError("A Record cannot exceed 1000000 fields");
656
+ const previous = descriptor?.value;
657
+ item = __velarReactiveRaw(item);
658
+ if (descriptor !== undefined && __velarCollectionRecordObjectIs(__velarReactiveRaw(previous), item)) return null;
659
+ __velarCollectionRecordDefineProperty(value, key, { value: item, writable: true, enumerable: true, configurable: true });
660
+ __velarReactiveCollectionUnlink(value, previous);
661
+ __velarReactiveCollectionLink(value, item);
662
+ __velarReactiveCollectionTrigger(value, key, true, descriptor === undefined);
663
+ return null;
664
+ }
665
+ function __velarRecordCopy(value) {
666
+ value = __velarReactiveRaw(value);
667
+ const output = {};
668
+ __velarReactiveCollectionTrack(value);
669
+ const fields = __velarRecordFields(value, "Record.copy");
670
+ for (let index = 0; index < fields.length; index += 1) {
671
+ const field = fields[index];
672
+ const descriptor = __velarCollectionRecordGetOwnPropertyDescriptor(value, field);
673
+ __velarCollectionRecordDefineProperty(output, field, { value: __velarReactiveCollectionRead(value, field, descriptor.value), writable: true, enumerable: true, configurable: true });
674
+ }
675
+ return output;
676
+ }
677
+
678
+ function __velarCollectionHas(value, item) {
679
+ value = __velarReactiveRaw(value); item = __velarReactiveRaw(item);
680
+ if (__velarCollectionListIsArray(value)) { value = __velarValidateOwnedList(value, "List.has"); __velarReactiveCollectionTrack(value); for (let index = 0; index < value.length; index += 1) if (__velarSameValueZero(__velarReactiveRaw(__velarOwnedListElement(value, index, "List.has")), item)) return true; return false; }
681
+ if (__velarIsRecord(value)) { if (typeof item !== "string") throw new __velarCollectionNativeTypeError("Record.has requires a string key"); __velarRecordFields(value, "Record.has"); __velarReactiveCollectionTrack(value, item); return __velarCollectionRecordGetOwnPropertyDescriptor(value, item) !== undefined; }
682
+ const map = __velarIsMap(value); const set = !map && __velarIsSet(value);
683
+ if (!map && !set) throw new __velarCollectionNativeTypeError("VelarScript membership requires a List, Set, Map, or Record");
684
+ const size = map ? __velarCollectionSetMapMapSize(value) : __velarCollectionSetMapSetSize(value);
685
+ if (size > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A collection cannot exceed 1000000 items");
686
+ __velarReactiveCollectionTrack(value, item);
687
+ return map ? __velarCollectionSetMapMapHas(value, item) : __velarCollectionSetMapSetHas(value, item);
688
+ }
689
+ function __velarContains(item, value) {
690
+ if (typeof value === "string") { if (typeof item !== "string") throw new __velarCollectionNativeTypeError("String membership requires a string"); return value.includes(item); }
691
+ value = __velarReactiveRaw(value);
692
+ if (__velarIsRecord(value)) {
693
+ if (typeof item !== "string") throw new __velarCollectionNativeTypeError("Record membership requires a string key");
694
+ const descriptor = __velarCollectionRecordGetOwnPropertyDescriptor(value, item);
695
+ if (descriptor !== undefined && (!descriptor.enumerable || !("value" in descriptor))) throw new __velarCollectionNativeTypeError("Record fields must be enumerable data values");
696
+ __velarReactiveCollectionTrack(value, item);
697
+ return descriptor !== undefined;
698
+ }
699
+ return __velarCollectionHas(value, item);
700
+ }
701
+
702
+ // D47 rule 81: equals(a, b) — deep structural comparison. Lists compare
703
+ // ordered element-wise, Sets as the same member set, Maps as the same
704
+ // key-value pairs, records as the same field set; leaves compare by
705
+ // SameValueZero so NaN agrees with '=='. Cyclic structures throw (the same
706
+ // stance stringify takes), and so does data nested past the validator depth
707
+ // budget, so a pathological input never becomes a silent stack overflow.
708
+ function __velarEquals(left, right) {
709
+ return __velarEqualsVisit(left, right, [], 0);
710
+ }
711
+ function __velarEqualsVisit(left, right, active, depth) {
712
+ left = __velarCollectionValue(__velarReactiveRaw(left));
713
+ right = __velarCollectionValue(__velarReactiveRaw(right));
714
+ if (left === right || (left !== left && right !== right)) return true;
715
+ if (left === null || right === null || typeof left !== "object" || typeof right !== "object") return false;
716
+ if (depth >= 1000) throw new __velarCollectionNativeTypeError("equals cannot compare data nested more than 1000 collections deep");
717
+ for (let index = 0; index < active.length; index += 1) {
718
+ if (active[index] === left || active[index] === right) throw new __velarCollectionNativeTypeError("equals cannot compare cyclic data");
719
+ }
720
+ active[active.length] = left;
721
+ active[active.length] = right;
722
+ try {
723
+ if (__velarCollectionListIsArray(left)) {
724
+ if (!__velarCollectionListIsArray(right)) return false;
725
+ const leftList = __velarValidateOwnedList(left, "equals");
726
+ const rightList = __velarValidateOwnedList(right, "equals");
727
+ __velarReactiveCollectionTrack(leftList);
728
+ __velarReactiveCollectionTrack(rightList);
729
+ if (leftList.length !== rightList.length) return false;
730
+ for (let index = 0; index < leftList.length; index += 1) {
731
+ if (!__velarEqualsVisit(__velarOwnedListElement(leftList, index, "equals"), __velarOwnedListElement(rightList, index, "equals"), active, depth + 1)) return false;
732
+ }
733
+ return true;
734
+ }
735
+ if (__velarIsSet(left)) {
736
+ if (!__velarIsSet(right)) return false;
737
+ const size = __velarCollectionSetMapSetSize(left);
738
+ if (size > __velarMaxCollectionItems || __velarCollectionSetMapSetSize(right) > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A collection cannot exceed 1000000 items");
739
+ __velarReactiveCollectionTrack(left);
740
+ __velarReactiveCollectionTrack(right);
741
+ if (size !== __velarCollectionSetMapSetSize(right)) return false;
742
+ // The native lookup already answers SameValueZero membership; only
743
+ // structured members without an identical partner fall back to the
744
+ // injective structural matching below. Structural equality is an
745
+ // equivalence relation, so greedy matching is exact.
746
+ const pending = [];
747
+ const leftIterator = __velarCollectionSetMapSetValues(left);
748
+ while (true) {
749
+ const step = __velarCollectionSetMapSetNext(leftIterator);
750
+ if (step.done) break;
751
+ const member = __velarCollectionValue(__velarReactiveRaw(step.value));
752
+ if (__velarCollectionSetMapSetHas(right, member)) continue;
753
+ if (member === null || typeof member !== "object") return false;
754
+ pending[pending.length] = member;
755
+ }
756
+ if (pending.length === 0) return true;
757
+ const candidates = [];
758
+ const rightIterator = __velarCollectionSetMapSetValues(right);
759
+ while (true) {
760
+ const step = __velarCollectionSetMapSetNext(rightIterator);
761
+ if (step.done) break;
762
+ const member = __velarCollectionValue(__velarReactiveRaw(step.value));
763
+ if (__velarCollectionSetMapSetHas(left, member)) continue;
764
+ if (member === null || typeof member !== "object") return false;
765
+ candidates[candidates.length] = member;
766
+ }
767
+ if (candidates.length !== pending.length) return false;
768
+ const used = new __velarCollectionNativeArray(candidates.length);
769
+ for (let leftIndex = 0; leftIndex < pending.length; leftIndex += 1) {
770
+ let matched = false;
771
+ for (let rightIndex = 0; rightIndex < candidates.length; rightIndex += 1) {
772
+ if (used[rightIndex]) continue;
773
+ if (__velarEqualsVisit(pending[leftIndex], candidates[rightIndex], active, depth + 1)) {
774
+ used[rightIndex] = true;
775
+ matched = true;
776
+ break;
777
+ }
778
+ }
779
+ if (!matched) return false;
780
+ }
781
+ return true;
782
+ }
783
+ if (__velarIsMap(left)) {
784
+ if (!__velarIsMap(right)) return false;
785
+ const size = __velarCollectionSetMapMapSize(left);
786
+ if (size > __velarMaxCollectionItems || __velarCollectionSetMapMapSize(right) > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A collection cannot exceed 1000000 items");
787
+ __velarReactiveCollectionTrack(left);
788
+ __velarReactiveCollectionTrack(right);
789
+ if (size !== __velarCollectionSetMapMapSize(right)) return false;
790
+ const pendingKeys = [];
791
+ const pendingValues = [];
792
+ const leftIterator = __velarCollectionSetMapMapEntries(left);
793
+ while (true) {
794
+ const step = __velarCollectionSetMapMapNext(leftIterator);
795
+ if (step.done) break;
796
+ const key = __velarCollectionValue(__velarReactiveRaw(step.value[0]));
797
+ const value = step.value[1];
798
+ if (__velarCollectionSetMapMapHas(right, key)) {
799
+ if (!__velarEqualsVisit(value, __velarCollectionSetMapMapGet(right, key), active, depth + 1)) return false;
800
+ continue;
801
+ }
802
+ if (key === null || typeof key !== "object") return false;
803
+ pendingKeys[pendingKeys.length] = key;
804
+ pendingValues[pendingValues.length] = value;
805
+ }
806
+ if (pendingKeys.length === 0) return true;
807
+ const candidateKeys = [];
808
+ const candidateValues = [];
809
+ const rightIterator = __velarCollectionSetMapMapEntries(right);
810
+ while (true) {
811
+ const step = __velarCollectionSetMapMapNext(rightIterator);
812
+ if (step.done) break;
813
+ const key = __velarCollectionValue(__velarReactiveRaw(step.value[0]));
814
+ if (__velarCollectionSetMapMapHas(left, key)) continue;
815
+ if (key === null || typeof key !== "object") return false;
816
+ candidateKeys[candidateKeys.length] = key;
817
+ candidateValues[candidateValues.length] = step.value[1];
818
+ }
819
+ if (candidateKeys.length !== pendingKeys.length) return false;
820
+ const used = new __velarCollectionNativeArray(candidateKeys.length);
821
+ for (let leftIndex = 0; leftIndex < pendingKeys.length; leftIndex += 1) {
822
+ let matched = false;
823
+ for (let rightIndex = 0; rightIndex < candidateKeys.length; rightIndex += 1) {
824
+ if (used[rightIndex]) continue;
825
+ if (__velarEqualsVisit(pendingKeys[leftIndex], candidateKeys[rightIndex], active, depth + 1)
826
+ && __velarEqualsVisit(pendingValues[leftIndex], candidateValues[rightIndex], active, depth + 1)) {
827
+ used[rightIndex] = true;
828
+ matched = true;
829
+ break;
830
+ }
831
+ }
832
+ if (!matched) return false;
833
+ }
834
+ return true;
835
+ }
836
+ if (__velarIsRecord(left)) {
837
+ if (!__velarIsRecord(right)) return false;
838
+ const leftFields = __velarRecordFields(left, "equals");
839
+ const rightFields = __velarRecordFields(right, "equals");
840
+ __velarReactiveCollectionTrack(left);
841
+ __velarReactiveCollectionTrack(right);
842
+ if (leftFields.length !== rightFields.length) return false;
843
+ for (let index = 0; index < leftFields.length; index += 1) {
844
+ const field = leftFields[index];
845
+ const rightDescriptor = __velarCollectionRecordGetOwnPropertyDescriptor(right, field);
846
+ if (!rightDescriptor || !rightDescriptor.enumerable || !("value" in rightDescriptor)) return false;
847
+ if (!__velarEqualsVisit(__velarCollectionRecordGetOwnPropertyDescriptor(left, field).value, rightDescriptor.value, active, depth + 1)) return false;
848
+ }
849
+ return true;
850
+ }
851
+ // Anything else — class instances, host objects — has no structural
852
+ // content contract; the analyzer rejects those domains statically, so a
853
+ // value reaching here came through 'any' and fails closed.
854
+ return false;
855
+ } finally {
856
+ active.length -= 2;
857
+ }
858
+ }
859
+
860
+ function __velarCollectionRemove(value, item) {
861
+ value = __velarReactiveRaw(value); item = __velarReactiveRaw(item);
862
+ if (__velarIsRecord(value)) {
863
+ if (typeof item !== "string") throw new __velarCollectionNativeTypeError("Record.remove requires a string key");
864
+ __velarRecordFields(value, "Record.remove");
865
+ const descriptor = __velarCollectionRecordGetOwnPropertyDescriptor(value, item);
866
+ if (descriptor === undefined) return false;
867
+ if (!descriptor.configurable) throw new __velarCollectionNativeTypeError("Record.remove requires a configurable data field");
868
+ if (!__velarCollectionRecordDeleteProperty(value, item)) throw new __velarCollectionNativeTypeError("Record.remove could not delete the field");
869
+ __velarReactiveCollectionUnlink(value, descriptor.value);
870
+ __velarReactiveCollectionTrigger(value, item, true, true);
871
+ return true;
872
+ }
873
+ const map = __velarIsMap(value);
874
+ const previous = map ? __velarCollectionSetMapMapGet(value, item) : undefined;
875
+ const removed = map ? __velarCollectionSetMapMapDelete(value, item) : __velarCollectionSetMapSetDelete(value, item);
876
+ // A Set member is its own entry: unlinking it twice repeats an O(children)
877
+ // scan for nothing. Only a Map has a separate value to unlink.
878
+ if (removed) { __velarReactiveCollectionUnlink(value, item); if (map) __velarReactiveCollectionUnlink(value, previous); __velarReactiveCollectionTrigger(value, item, true, true); }
879
+ return removed;
880
+ }
881
+
882
+ function __velarCollectionClear(value) {
883
+ value = __velarReactiveRaw(value);
884
+ if (__velarCollectionListIsArray(value)) {
885
+ const previous = __velarCopyList(value, "List.clear");
886
+ if (previous.length === 0) return null;
887
+ value.length = 0;
888
+ __velarMarkOwnedList(value);
889
+ for (let index = 0; index < previous.length; index += 1) __velarReactiveCollectionUnlink(value, previous[index]);
890
+ __velarReactiveCollectionTrigger(value, __velarReactiveIterateKey, true, true, 0);
891
+ return null;
892
+ }
893
+ if (__velarIsRecord(value)) {
894
+ const fields = __velarRecordFields(value, "Record.clear");
895
+ if (fields.length === 0) return null;
896
+ const previous = new __velarCollectionNativeArray(fields.length);
897
+ for (let index = 0; index < fields.length; index += 1) { const descriptor = __velarCollectionRecordGetOwnPropertyDescriptor(value, fields[index]); if (!descriptor.configurable) throw new __velarCollectionNativeTypeError("Record.clear requires configurable data fields"); previous[index] = descriptor.value; }
898
+ for (let index = 0; index < fields.length; index += 1) if (!__velarCollectionRecordDeleteProperty(value, fields[index])) throw new __velarCollectionNativeTypeError("Record.clear could not delete a field");
899
+ for (let index = 0; index < previous.length; index += 1) __velarReactiveCollectionUnlink(value, previous[index]);
900
+ __velarReactiveCollectionTrigger(value, __velarReactiveIterateKey, true, true, null, true);
901
+ return null;
902
+ }
903
+ const map = __velarIsMap(value);
904
+ const previous = [];
905
+ if (map) { const iterator = __velarCollectionSetMapMapEntries(value); while (true) { const step = __velarCollectionSetMapMapNext(iterator); if (step.done) break; const entry = step.value; previous[previous.length] = entry[0]; previous[previous.length] = entry[1]; } }
906
+ else { const iterator = __velarCollectionSetMapSetValues(value); while (true) { const step = __velarCollectionSetMapSetNext(iterator); if (step.done) break; previous[previous.length] = step.value; } }
907
+ if (previous.length === 0) return null;
908
+ if (map) __velarCollectionSetMapMapClear(value); else __velarCollectionSetMapSetClear(value);
909
+ for (let index = 0; index < previous.length; index += 1) __velarReactiveCollectionUnlink(value, previous[index]);
910
+ __velarReactiveCollectionTrigger(value, __velarReactiveIterateKey, true, true, null, true);
911
+ return null;
912
+ }
913
+
914
+ function __velarCollectionKeys(value) {
915
+ value = __velarReactiveRaw(value); __velarReactiveCollectionTrack(value, __velarReactiveStructureKey);
916
+ if (__velarIsRecord(value)) { const fields = __velarRecordFields(value, "Record.keys"); const output = new __velarCollectionNativeArray(fields.length); for (let index = 0; index < fields.length; index += 1) output[index] = __velarReactiveCollectionRead(value, __velarReactiveStructureKey, fields[index]); return __velarMarkOwnedList(output); }
917
+ const size = __velarCollectionSetMapMapSize(value); if (size > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A Map cannot exceed 1000000 entries");
918
+ const output = new __velarCollectionNativeArray(size); const iterator = __velarCollectionSetMapMapKeys(value); let index = 0; while (true) { const step = __velarCollectionSetMapMapNext(iterator); if (step.done) return __velarMarkOwnedList(output); output[index++] = __velarReactiveCollectionRead(value, __velarReactiveStructureKey, step.value); }
919
+ }
920
+ function __velarCollectionValues(value) {
921
+ value = __velarReactiveRaw(value); __velarReactiveCollectionTrack(value);
922
+ if (__velarIsRecord(value)) { const fields = __velarRecordFields(value, "Record.values"); const output = new __velarCollectionNativeArray(fields.length); for (let index = 0; index < fields.length; index += 1) { const field = fields[index]; output[index] = __velarReactiveCollectionRead(value, field, __velarCollectionRecordGetOwnPropertyDescriptor(value, field).value); } return __velarMarkOwnedList(output); }
923
+ const map = __velarIsMap(value); const size = map ? __velarCollectionSetMapMapSize(value) : __velarCollectionSetMapSetSize(value); if (size > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A collection cannot exceed 1000000 items");
924
+ const output = new __velarCollectionNativeArray(size); const iterator = map ? __velarCollectionSetMapMapValues(value) : __velarCollectionSetMapSetValues(value); let index = 0; while (true) { const step = map ? __velarCollectionSetMapMapNext(iterator) : __velarCollectionSetMapSetNext(iterator); if (step.done) return __velarMarkOwnedList(output); output[index++] = __velarReactiveCollectionRead(value, __velarReactiveIterateKey, step.value); }
925
+ }
926
+ function __velarCollectionEntries(value) {
927
+ value = __velarReactiveRaw(value); __velarReactiveCollectionTrack(value);
928
+ if (__velarIsRecord(value)) { const fields = __velarRecordFields(value, "Record.entries"); const output = new __velarCollectionNativeArray(fields.length); for (let index = 0; index < fields.length; index += 1) { const field = fields[index]; output[index] = __velarCollectionRecordFreeze({ key: __velarReactiveCollectionRead(value, __velarReactiveIterateKey, field), value: __velarReactiveCollectionRead(value, field, __velarCollectionRecordGetOwnPropertyDescriptor(value, field).value) }); } return __velarMarkOwnedList(output); }
929
+ const size = __velarCollectionSetMapMapSize(value); if (size > __velarMaxCollectionItems) throw new __velarCollectionSetMapNativeRangeError("A Map cannot exceed 1000000 entries");
930
+ const output = new __velarCollectionNativeArray(size); const iterator = __velarCollectionSetMapMapEntries(value); let index = 0; while (true) { const step = __velarCollectionSetMapMapNext(iterator); if (step.done) return __velarMarkOwnedList(output); const entry = step.value; output[index++] = __velarCollectionSetMapFreeze({ key: __velarReactiveCollectionRead(value, __velarReactiveIterateKey, entry[0]), value: __velarReactiveCollectionRead(value, entry[0], entry[1]) }); }
931
+ }
932
+ function __velarOptionalCollection(value, operation) { return value == null ? null : operation(value); }`;
933
+ export const VELAR_COLLECTION_LOWERING_MODULE_SOURCE = String.raw `
934
+ import {
935
+ ${VELAR_COLLECTION_HOST_EXPORTS.map((name) => ` ${name},`).join("\n")}
936
+ } from ${JSON.stringify(VELAR_COLLECTION_HOST_MODULE)};
937
+ import {
938
+ reactiveIterateKey as __velarReactiveIterateKey,
939
+ reactiveStructureKey as __velarReactiveStructureKey,
940
+ reactiveRaw as __velarReactiveRaw,
941
+ reactiveCollectionRead as __velarReactiveCollectionRead,
942
+ reactiveCollectionTrack as __velarReactiveCollectionTrack,
943
+ reactiveCollectionLink as __velarReactiveCollectionLink,
944
+ reactiveCollectionTrigger as __velarReactiveCollectionTrigger,
945
+ reactiveCollectionUnlink as __velarReactiveCollectionUnlink,
946
+ } from ${JSON.stringify(VELAR_REACTIVE_BRIDGE_MODULE)};
947
+ ${VELAR_COLLECTION_LOWERING_RUNTIME}
948
+ export {
949
+ ${VELAR_COLLECTION_LOWERING_EXPORTS.map((name) => ` ${name},`).join("\n")}
950
+ };
951
+ `.trimStart();
952
+ //# sourceMappingURL=collection-lowering-runtime.js.map