mutts 1.0.9 → 1.0.10

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 (204) hide show
  1. package/README.md +58 -33
  2. package/dist/browser.cjs +1371 -1206
  3. package/dist/browser.cjs.map +1 -1
  4. package/dist/browser.d.ts +2 -1392
  5. package/dist/browser.dev.cjs +110 -0
  6. package/dist/browser.dev.cjs.map +1 -0
  7. package/dist/browser.dev.d.ts +2 -0
  8. package/dist/browser.dev.esm.js +5 -0
  9. package/dist/browser.dev.esm.js.map +1 -0
  10. package/dist/browser.esm.js +6 -87
  11. package/dist/browser.esm.js.map +1 -1
  12. package/dist/chunks/{async-browser-lvzLOCgk.cjs → async-browser-BU_IfxYD.cjs} +4 -85
  13. package/dist/chunks/async-browser-BU_IfxYD.cjs.map +1 -0
  14. package/dist/chunks/{async-node-C3DeIb0y.cjs → async-node-3PrbVAbB.cjs} +3 -1
  15. package/dist/chunks/async-node-3PrbVAbB.cjs.map +1 -0
  16. package/dist/chunks/{index-2vea86wD.esm.js → index-CaaQQlPJ.esm.js} +1116 -953
  17. package/dist/chunks/index-CaaQQlPJ.esm.js.map +1 -0
  18. package/dist/chunks/node-nKJBk8iJ.esm.js +96 -0
  19. package/dist/chunks/node-nKJBk8iJ.esm.js.map +1 -0
  20. package/dist/chunks/{index-VTO-b2vR.cjs → proxy-Dtg-bJ3T.cjs} +2285 -2983
  21. package/dist/chunks/proxy-Dtg-bJ3T.cjs.map +1 -0
  22. package/dist/chunks/{index-CtA2AWl3.esm.js → proxy-r7lARftl.esm.js} +2273 -2948
  23. package/dist/chunks/proxy-r7lARftl.esm.js.map +1 -0
  24. package/dist/debug.cjs +973 -28
  25. package/dist/debug.cjs.map +1 -1
  26. package/dist/debug.d.ts +36 -37
  27. package/dist/debug.esm.js +949 -1
  28. package/dist/debug.esm.js.map +1 -1
  29. package/dist/devtools/manifest.json +1 -1
  30. package/dist/devtools/panel.html +1 -1
  31. package/dist/devtools/panel.js +107 -94
  32. package/dist/devtools/panel.js.map +1 -1
  33. package/dist/index.d.ts +1447 -1
  34. package/dist/mutts.umd.js +7167 -1
  35. package/dist/mutts.umd.js.map +1 -1
  36. package/dist/mutts.umd.min.js +1 -1
  37. package/dist/mutts.umd.min.js.map +1 -1
  38. package/dist/node.cjs +62 -60
  39. package/dist/node.cjs.map +1 -1
  40. package/dist/node.d.ts +2 -2
  41. package/dist/node.dev.cjs +110 -0
  42. package/dist/node.dev.cjs.map +1 -0
  43. package/dist/node.dev.d.ts +2 -0
  44. package/dist/node.dev.esm.js +6 -0
  45. package/dist/node.dev.esm.js.map +1 -0
  46. package/dist/node.esm.js +4 -97
  47. package/dist/node.esm.js.map +1 -1
  48. package/dist/{types-DaHFfhlN.d.ts → types-W5vD6m2n.d.ts} +99 -44
  49. package/docs/ai/api-reference.md +11 -18
  50. package/docs/ai/manual.md +308 -230
  51. package/docs/reactive/advanced.md +312 -2
  52. package/docs/reactive/attend.md +1 -2
  53. package/docs/reactive/collections.md +21 -39
  54. package/docs/reactive/core.md +7 -37
  55. package/docs/reactive/debugging.md +117 -10
  56. package/docs/reactive/error-handling.md +10 -10
  57. package/docs/reactive/resource.md +125 -0
  58. package/docs/reactive/scan.md +32 -1
  59. package/docs/reactive.md +3 -2
  60. package/docs/utils.md +70 -0
  61. package/package.json +59 -30
  62. package/dist/chunks/async-browser-lvzLOCgk.cjs.map +0 -1
  63. package/dist/chunks/async-node-C3DeIb0y.cjs.map +0 -1
  64. package/dist/chunks/index-2vea86wD.esm.js.map +0 -1
  65. package/dist/chunks/index-CtA2AWl3.esm.js.map +0 -1
  66. package/dist/chunks/index-VTO-b2vR.cjs.map +0 -1
  67. package/dist/debug/debug.d.ts +0 -122
  68. package/dist/debug/debug.d.ts.map +0 -1
  69. package/dist/debug/index.d.ts +0 -4
  70. package/dist/debug/index.d.ts.map +0 -1
  71. package/dist/debug/lineage-panel.d.ts +0 -5
  72. package/dist/debug/lineage-panel.d.ts.map +0 -1
  73. package/dist/debug/lineage.d.ts +0 -79
  74. package/dist/debug/lineage.d.ts.map +0 -1
  75. package/dist/src/async/browser.d.ts +0 -2
  76. package/dist/src/async/browser.d.ts.map +0 -1
  77. package/dist/src/async/index.d.ts +0 -19
  78. package/dist/src/async/index.d.ts.map +0 -1
  79. package/dist/src/async/node.d.ts +0 -2
  80. package/dist/src/async/node.d.ts.map +0 -1
  81. package/dist/src/decorator.d.ts +0 -106
  82. package/dist/src/decorator.d.ts.map +0 -1
  83. package/dist/src/destroyable.d.ts +0 -87
  84. package/dist/src/destroyable.d.ts.map +0 -1
  85. package/dist/src/entry-browser.d.ts +0 -3
  86. package/dist/src/entry-browser.d.ts.map +0 -1
  87. package/dist/src/entry-node.d.ts +0 -3
  88. package/dist/src/entry-node.d.ts.map +0 -1
  89. package/dist/src/eventful.d.ts +0 -20
  90. package/dist/src/eventful.d.ts.map +0 -1
  91. package/dist/src/flavored.d.ts +0 -33
  92. package/dist/src/flavored.d.ts.map +0 -1
  93. package/dist/src/index.d.ts +0 -14
  94. package/dist/src/index.d.ts.map +0 -1
  95. package/dist/src/indexable.d.ts +0 -243
  96. package/dist/src/indexable.d.ts.map +0 -1
  97. package/dist/src/introspection.d.ts +0 -27
  98. package/dist/src/introspection.d.ts.map +0 -1
  99. package/dist/src/iterableWeak.d.ts +0 -53
  100. package/dist/src/iterableWeak.d.ts.map +0 -1
  101. package/dist/src/mixins.d.ts +0 -25
  102. package/dist/src/mixins.d.ts.map +0 -1
  103. package/dist/src/promiseChain.d.ts +0 -20
  104. package/dist/src/promiseChain.d.ts.map +0 -1
  105. package/dist/src/reactive/array.d.ts +0 -48
  106. package/dist/src/reactive/array.d.ts.map +0 -1
  107. package/dist/src/reactive/buffer.d.ts +0 -120
  108. package/dist/src/reactive/buffer.d.ts.map +0 -1
  109. package/dist/src/reactive/change.d.ts +0 -29
  110. package/dist/src/reactive/change.d.ts.map +0 -1
  111. package/dist/src/reactive/deep-touch.d.ts +0 -28
  112. package/dist/src/reactive/deep-touch.d.ts.map +0 -1
  113. package/dist/src/reactive/deep-watch-state.d.ts +0 -25
  114. package/dist/src/reactive/deep-watch-state.d.ts.map +0 -1
  115. package/dist/src/reactive/deep-watch.d.ts +0 -20
  116. package/dist/src/reactive/deep-watch.d.ts.map +0 -1
  117. package/dist/src/reactive/describe.d.ts +0 -12
  118. package/dist/src/reactive/describe.d.ts.map +0 -1
  119. package/dist/src/reactive/effect-context.d.ts +0 -34
  120. package/dist/src/reactive/effect-context.d.ts.map +0 -1
  121. package/dist/src/reactive/effects.d.ts +0 -164
  122. package/dist/src/reactive/effects.d.ts.map +0 -1
  123. package/dist/src/reactive/index.d.ts +0 -19
  124. package/dist/src/reactive/index.d.ts.map +0 -1
  125. package/dist/src/reactive/map.d.ts +0 -28
  126. package/dist/src/reactive/map.d.ts.map +0 -1
  127. package/dist/src/reactive/memoize.d.ts +0 -28
  128. package/dist/src/reactive/memoize.d.ts.map +0 -1
  129. package/dist/src/reactive/non-reactive-state.d.ts +0 -9
  130. package/dist/src/reactive/non-reactive-state.d.ts.map +0 -1
  131. package/dist/src/reactive/non-reactive.d.ts +0 -11
  132. package/dist/src/reactive/non-reactive.d.ts.map +0 -1
  133. package/dist/src/reactive/project.d.ts +0 -40
  134. package/dist/src/reactive/project.d.ts.map +0 -1
  135. package/dist/src/reactive/proxy-state.d.ts +0 -8
  136. package/dist/src/reactive/proxy-state.d.ts.map +0 -1
  137. package/dist/src/reactive/proxy.d.ts +0 -23
  138. package/dist/src/reactive/proxy.d.ts.map +0 -1
  139. package/dist/src/reactive/record.d.ts +0 -115
  140. package/dist/src/reactive/record.d.ts.map +0 -1
  141. package/dist/src/reactive/register.d.ts +0 -125
  142. package/dist/src/reactive/register.d.ts.map +0 -1
  143. package/dist/src/reactive/registry.d.ts +0 -21
  144. package/dist/src/reactive/registry.d.ts.map +0 -1
  145. package/dist/src/reactive/set.d.ts +0 -26
  146. package/dist/src/reactive/set.d.ts.map +0 -1
  147. package/dist/src/reactive/tracking.d.ts +0 -7
  148. package/dist/src/reactive/tracking.d.ts.map +0 -1
  149. package/dist/src/reactive/types.d.ts +0 -424
  150. package/dist/src/reactive/types.d.ts.map +0 -1
  151. package/dist/src/reactive/watch.d.ts +0 -48
  152. package/dist/src/reactive/watch.d.ts.map +0 -1
  153. package/dist/src/std-decorators.d.ts +0 -45
  154. package/dist/src/std-decorators.d.ts.map +0 -1
  155. package/dist/src/utils.d.ts +0 -49
  156. package/dist/src/utils.d.ts.map +0 -1
  157. package/dist/src/zone.d.ts +0 -40
  158. package/dist/src/zone.d.ts.map +0 -1
  159. package/docs/reactive/describe.md +0 -85
  160. package/docs/reactive/project.md +0 -93
  161. package/src/async/browser.ts +0 -323
  162. package/src/async/index.ts +0 -27
  163. package/src/async/node.ts +0 -92
  164. package/src/decorator.ts +0 -272
  165. package/src/destroyable.ts +0 -199
  166. package/src/entry-browser.ts +0 -5
  167. package/src/entry-node.ts +0 -5
  168. package/src/eventful.ts +0 -110
  169. package/src/flavored.ts +0 -106
  170. package/src/index.d.ts +0 -12
  171. package/src/index.ts +0 -64
  172. package/src/indexable.ts +0 -526
  173. package/src/introspection.ts +0 -59
  174. package/src/iterableWeak.ts +0 -233
  175. package/src/mixins.ts +0 -123
  176. package/src/promiseChain.ts +0 -110
  177. package/src/reactive/array.ts +0 -500
  178. package/src/reactive/buffer.ts +0 -328
  179. package/src/reactive/change.ts +0 -131
  180. package/src/reactive/deep-touch.ts +0 -273
  181. package/src/reactive/deep-watch-state.ts +0 -82
  182. package/src/reactive/deep-watch.ts +0 -171
  183. package/src/reactive/describe.ts +0 -39
  184. package/src/reactive/effect-context.ts +0 -83
  185. package/src/reactive/effects.ts +0 -1434
  186. package/src/reactive/index.ts +0 -72
  187. package/src/reactive/map.ts +0 -142
  188. package/src/reactive/memoize.ts +0 -186
  189. package/src/reactive/non-reactive-state.ts +0 -49
  190. package/src/reactive/non-reactive.ts +0 -43
  191. package/src/reactive/project.md +0 -107
  192. package/src/reactive/project.ts +0 -430
  193. package/src/reactive/proxy-state.ts +0 -27
  194. package/src/reactive/proxy.ts +0 -282
  195. package/src/reactive/record.ts +0 -181
  196. package/src/reactive/register.ts +0 -538
  197. package/src/reactive/registry.ts +0 -72
  198. package/src/reactive/set.ts +0 -117
  199. package/src/reactive/tracking.ts +0 -41
  200. package/src/reactive/types.ts +0 -520
  201. package/src/reactive/watch.ts +0 -180
  202. package/src/std-decorators.ts +0 -256
  203. package/src/utils.ts +0 -300
  204. package/src/zone.ts +0 -142
package/src/index.d.ts DELETED
@@ -1,12 +0,0 @@
1
- export * from './decorator'
2
- export * from './destroyable'
3
- export * from './eventful'
4
- export * from './indexable'
5
- export * from './iterableWeak'
6
- export * from './mixins'
7
- export * from './promiseChain'
8
- export * from './reactive'
9
- export * from './std-decorators'
10
- export * from './utils'
11
- export * from './zone'
12
- export * from './async'
package/src/index.ts DELETED
@@ -1,64 +0,0 @@
1
- export * from './async'
2
- export * from './decorator'
3
- export * from './destroyable'
4
- export * from './eventful'
5
- export * from './flavored'
6
- export * from './indexable'
7
- export * from './iterableWeak'
8
- export * from './mixins'
9
- export * from './promiseChain'
10
- export * from './reactive'
11
- export * from './std-decorators'
12
- export * from './utils'
13
- export * from './zone'
14
-
15
- import pkg from '../package.json'
16
-
17
- const { version } = pkg
18
-
19
- // Singleton verification
20
- const GLOBAL_MUTTS_KEY = '__MUTTS_INSTANCE__'
21
- const globalScope = (
22
- typeof globalThis !== 'undefined'
23
- ? globalThis
24
- : typeof window !== 'undefined'
25
- ? window
26
- : typeof global !== 'undefined'
27
- ? global
28
- : false
29
- ) as any
30
- if (globalScope) {
31
- // Detect the source of this instance safely across different environments
32
- let source = 'mutts/index'
33
- const viteEval = eval
34
- try {
35
- if (typeof __filename !== 'undefined') source = __filename
36
- else {
37
- // Using eval to avoid SyntaxError in CJS environments where import.meta is not allowed
38
- const meta = viteEval('import.meta')
39
- if (meta && meta.url) source = meta.url
40
- }
41
- } catch (e) {
42
- // Fallback for environments where neither is available or accessible
43
- }
44
-
45
- const currentSourceInfo = {
46
- version,
47
- source,
48
- timestamp: Date.now(),
49
- }
50
-
51
- if (globalScope[GLOBAL_MUTTS_KEY]) {
52
- const existing = globalScope[GLOBAL_MUTTS_KEY]
53
- throw new Error(
54
- `[Mutts] Multiple instances detected!\n` +
55
- `Existing instance: ${JSON.stringify(existing, null, 2)}\n` +
56
- `New instance: ${JSON.stringify(currentSourceInfo, null, 2)}\n` +
57
- `This usually happens when 'mutts' is both installed as a dependency and bundled, ` +
58
- `or when different versions are loaded. ` +
59
- `Please check your build configuration (aliases, externals) to ensure a single source of truth.`
60
- )
61
- }
62
-
63
- globalScope[GLOBAL_MUTTS_KEY] = currentSourceInfo
64
- }
package/src/indexable.ts DELETED
@@ -1,526 +0,0 @@
1
- /**
2
- * Symbol for defining custom getter logic for numeric index access
3
- */
4
- export const getAt = Symbol('getAt')
5
- /**
6
- * Symbol for defining custom setter logic for numeric index access
7
- */
8
- export const setAt = Symbol('setAt')
9
-
10
- interface IndexingAt<Items = any> {
11
- [getAt](index: number): Items
12
- }
13
-
14
- interface Accessor<T, Items> {
15
- get(this: T, index: number): Items
16
- set?(this: T, index: number, value: Items): void
17
- getLength?(this: T): number
18
- setLength?(this: T, value: number): void
19
- }
20
-
21
- abstract class AbstractGetAt<Items = any> {
22
- abstract [getAt](index: number): Items
23
- }
24
-
25
- /**
26
- * Creates an indexable class with a base class and accessor object
27
- * @param base - The base class to extend
28
- * @param accessor - Object containing get/set methods for numeric index access
29
- * @returns A class that supports numeric index access
30
- */
31
- export function Indexable<Items, Base extends abstract new (...args: any[]) => any>(
32
- base: Base,
33
- accessor: Accessor<InstanceType<Base>, Items>
34
- ): new (
35
- ...args: ConstructorParameters<Base>
36
- ) => InstanceType<Base> & { [x: number]: Items }
37
-
38
- /**
39
- * Creates an indexable class with only an accessor object (no base class)
40
- * @param accessor - Object containing get/set methods for numeric index access
41
- * @returns A class that supports numeric index access
42
- */
43
- export function Indexable<Items>(accessor: Accessor<any, Items>): new () => { [x: number]: Items }
44
-
45
- /**
46
- * Creates an indexable class with a base class that has [getAt] method
47
- * @param base - The base class that implements [getAt] method
48
- * @returns A class that supports numeric index access using the base class's [getAt] method
49
- */
50
- export function Indexable<Base extends new (...args: any[]) => IndexingAt>(
51
- base: Base
52
- ): new (
53
- ...args: ConstructorParameters<Base>
54
- ) => InstanceType<Base> & { [x: number]: AtReturnType<InstanceType<Base>> }
55
-
56
- /**
57
- * Creates an abstract indexable base class
58
- * @returns An abstract class that supports numeric index access
59
- */
60
- export function Indexable<Items>(): abstract new (
61
- ...args: any[]
62
- ) => AbstractGetAt & { [x: number]: Items }
63
-
64
- export function Indexable<Items, Base extends abstract new (...args: any[]) => any>(
65
- base?: Base | Accessor<Base, Items>,
66
- accessor?: Accessor<Base, Items>
67
- ) {
68
- if (base && typeof base !== 'function') {
69
- accessor = base as Accessor<Base, Items>
70
- base = undefined
71
- }
72
- if (!base) {
73
- //@ts-expect-error
74
- base = class {} as Base
75
- }
76
- if (!accessor) {
77
- accessor = {
78
- get(this: any, index: number) {
79
- if (typeof this[getAt] !== 'function') {
80
- throw new Error('Indexable class must have an [getAt] method')
81
- }
82
- return this[getAt](index)
83
- },
84
- set(this: any, index: number, value: Items) {
85
- if (typeof this[setAt] !== 'function') {
86
- throw new Error('Indexable class has read-only numeric index access')
87
- }
88
- this[setAt](index, value)
89
- },
90
- }
91
- }
92
-
93
- abstract class Indexable extends (base as Base) {
94
- [x: number]: Items
95
- }
96
-
97
- Object.setPrototypeOf(
98
- Indexable.prototype,
99
- new Proxy((base as Base).prototype, {
100
- //@ts-expect-error
101
- [Symbol.toStringTag]: 'MutTs Indexable',
102
- get(target, prop, receiver) {
103
- if (prop in target) {
104
- const getter = Object.getOwnPropertyDescriptor(target, prop)?.get
105
- return getter ? getter.call(receiver) : target[prop]
106
- }
107
- if (typeof prop === 'string') {
108
- if (prop === 'length' && accessor.getLength) return accessor.getLength.call(receiver)
109
- const numProp = Number(prop)
110
- if (!Number.isNaN(numProp)) {
111
- return accessor.get!.call(receiver, numProp) as Items
112
- }
113
- }
114
- return undefined
115
- },
116
- set(target, prop, value, receiver) {
117
- if (prop in target) {
118
- const setter = Object.getOwnPropertyDescriptor(target, prop)?.set
119
- if (setter) setter.call(receiver, value)
120
- else target[prop] = value
121
- return true
122
- }
123
- if (typeof prop === 'string') {
124
- if (prop === 'length' && accessor.setLength) {
125
- accessor.setLength.call(receiver, value)
126
- return true
127
- }
128
- const numProp = Number(prop)
129
- if (!Number.isNaN(numProp)) {
130
- if (!accessor.set) throw new Error('Indexable class has read-only numeric index access')
131
- accessor.set!.call(receiver, numProp, value)
132
- return true
133
- }
134
- }
135
- Object.defineProperty(receiver, prop, {
136
- value,
137
- writable: true,
138
- enumerable: true,
139
- configurable: true,
140
- })
141
- return true
142
- },
143
- has(target, prop) {
144
- if (prop in target) return true
145
- if (typeof prop === 'string') {
146
- if (prop === 'length' && accessor.getLength) return true
147
- const numProp = Number(prop)
148
- if (!Number.isNaN(numProp)) return true
149
- }
150
- return false
151
- },
152
- ownKeys(target) {
153
- const keys = Reflect.ownKeys(target)
154
- if (accessor.getLength) {
155
- keys.push('length')
156
- const len = accessor.getLength.call(this as any)
157
- for (let i = 0; i < len; i++) keys.push(String(i))
158
- }
159
- return keys
160
- },
161
- getOwnPropertyDescriptor(target, prop) {
162
- if (prop in target) return Object.getOwnPropertyDescriptor(target, prop)
163
- if (typeof prop === 'string') {
164
- if (prop === 'length' && accessor.getLength) {
165
- return {
166
- enumerable: false,
167
- configurable: true,
168
- get: () => accessor.getLength!.call(this as any),
169
- }
170
- }
171
- const numProp = Number(prop)
172
- if (!Number.isNaN(numProp)) {
173
- return {
174
- enumerable: true,
175
- configurable: true,
176
- get: () => accessor.get!.call(this as any, numProp),
177
- set: accessor.set
178
- ? (v: any) => accessor.set!.call(this as any, numProp, v)
179
- : undefined,
180
- }
181
- }
182
- }
183
- return undefined
184
- },
185
- })
186
- )
187
- return Indexable
188
- }
189
-
190
- type AtReturnType<T> = T extends { [getAt](index: number): infer R } ? R : never
191
-
192
- /**
193
- * Symbol for accessing the forwarded array in ArrayReadForward
194
- */
195
- export const forwardArray = Symbol('forwardArray')
196
-
197
- /**
198
- * A read-only array forwarder that implements all reading/iterating methods of Array
199
- * but does not implement modification methods.
200
- *
201
- * The constructor takes a callback that returns an array, and all methods forward
202
- * their behavior to the result of that callback.
203
- */
204
- export class ArrayReadForward<T> {
205
- protected get [forwardArray](): readonly T[] {
206
- throw new Error('ArrayReadForward is not implemented')
207
- }
208
-
209
- /**
210
- * Get the length of the array
211
- */
212
- get length(): number {
213
- return this[forwardArray].length
214
- }
215
-
216
- /**
217
- * Get an element at a specific index
218
- */
219
- [index: number]: T | undefined
220
-
221
- /**
222
- * Iterator protocol support
223
- */
224
- [Symbol.iterator](): Iterator<T> {
225
- return this[forwardArray][Symbol.iterator]()
226
- }
227
-
228
- // Reading/Iterating methods
229
-
230
- /**
231
- * Creates a new array with the results of calling a provided function on every element
232
- */
233
- map<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U, thisArg?: any): U[] {
234
- return this[forwardArray].map(callbackfn, thisArg)
235
- }
236
-
237
- /**
238
- * Creates a new array with all elements that pass the test implemented by the provided function
239
- */
240
- filter<S extends T>(
241
- predicate: (value: T, index: number, array: readonly T[]) => value is S,
242
- thisArg?: any
243
- ): S[]
244
- filter(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T[]
245
- filter(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T[] {
246
- return this[forwardArray].filter(predicate, thisArg)
247
- }
248
-
249
- /**
250
- * Executes a reducer function on each element of the array, resulting in a single output value
251
- */
252
- reduce(
253
- callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T
254
- ): T
255
- reduce(
256
- callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T,
257
- initialValue: T
258
- ): T
259
- reduce<U>(
260
- callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U,
261
- initialValue: U
262
- ): U
263
- reduce(
264
- callbackfn: (
265
- previousValue: any,
266
- currentValue: T,
267
- currentIndex: number,
268
- array: readonly T[]
269
- ) => any,
270
- initialValue?: any
271
- ): any {
272
- return initialValue !== undefined
273
- ? this[forwardArray].reduce(callbackfn, initialValue)
274
- : this[forwardArray].reduce(callbackfn)
275
- }
276
-
277
- /**
278
- * Executes a reducer function on each element of the array (right-to-left), resulting in a single output value
279
- */
280
- reduceRight(
281
- callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T
282
- ): T
283
- reduceRight(
284
- callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T,
285
- initialValue: T
286
- ): T
287
- reduceRight<U>(
288
- callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U,
289
- initialValue: U
290
- ): U
291
- reduceRight(
292
- callbackfn: (
293
- previousValue: any,
294
- currentValue: T,
295
- currentIndex: number,
296
- array: readonly T[]
297
- ) => any,
298
- initialValue?: any
299
- ): any {
300
- return initialValue !== undefined
301
- ? this[forwardArray].reduceRight(callbackfn, initialValue)
302
- : this[forwardArray].reduceRight(callbackfn)
303
- }
304
-
305
- /**
306
- * Executes a provided function once for each array element
307
- */
308
- forEach(callbackfn: (value: T, index: number, array: readonly T[]) => void, thisArg?: any): void {
309
- this[forwardArray].forEach(callbackfn, thisArg)
310
- }
311
-
312
- /**
313
- * Returns the value of the first element in the array that satisfies the provided testing function
314
- */
315
- find<S extends T>(
316
- predicate: (value: T, index: number, array: readonly T[]) => value is S,
317
- thisArg?: any
318
- ): S | undefined
319
- find(
320
- predicate: (value: T, index: number, array: readonly T[]) => unknown,
321
- thisArg?: any
322
- ): T | undefined
323
- find(
324
- predicate: (value: T, index: number, array: readonly T[]) => unknown,
325
- thisArg?: any
326
- ): T | undefined {
327
- return this[forwardArray].find(predicate, thisArg)
328
- }
329
-
330
- /**
331
- * Returns the index of the first element in the array that satisfies the provided testing function
332
- */
333
- findIndex(
334
- predicate: (value: T, index: number, array: readonly T[]) => unknown,
335
- thisArg?: any
336
- ): number {
337
- return this[forwardArray].findIndex(predicate, thisArg)
338
- }
339
-
340
- /**
341
- * Returns the value of the last element in the array that satisfies the provided testing function
342
- */
343
- findLast<S extends T>(
344
- predicate: (value: T, index: number, array: readonly T[]) => value is S,
345
- thisArg?: any
346
- ): S | undefined
347
- findLast(
348
- predicate: (value: T, index: number, array: readonly T[]) => unknown,
349
- thisArg?: any
350
- ): T | undefined
351
- findLast(
352
- predicate: (value: T, index: number, array: readonly T[]) => unknown,
353
- thisArg?: any
354
- ): T | undefined {
355
- return this[forwardArray].findLast(predicate, thisArg)
356
- }
357
-
358
- /**
359
- * Returns the index of the last element in the array that satisfies the provided testing function
360
- */
361
- findLastIndex(
362
- predicate: (value: T, index: number, array: readonly T[]) => unknown,
363
- thisArg?: any
364
- ): number {
365
- return this[forwardArray].findLastIndex(predicate, thisArg)
366
- }
367
-
368
- /**
369
- * Determines whether an array includes a certain value among its entries
370
- */
371
- includes(searchElement: T, fromIndex?: number): boolean {
372
- return this[forwardArray].includes(searchElement, fromIndex)
373
- }
374
-
375
- /**
376
- * Returns the first index at which a given element can be found in the array
377
- */
378
- indexOf(searchElement: T, fromIndex?: number): number {
379
- return this[forwardArray].indexOf(searchElement, fromIndex)
380
- }
381
-
382
- /**
383
- * Returns the last index at which a given element can be found in the array
384
- */
385
- lastIndexOf(searchElement: T, fromIndex?: number): number {
386
- return this[forwardArray].lastIndexOf(searchElement, fromIndex)
387
- }
388
-
389
- /**
390
- * Returns a shallow copy of a portion of an array into a new array object
391
- */
392
- slice(start?: number, end?: number): T[] {
393
- return this[forwardArray].slice(start, end)
394
- }
395
-
396
- /**
397
- * Returns a new array comprised of this array joined with other array(s) and/or value(s)
398
- */
399
- concat(...items: ConcatArray<T>[]): T[]
400
- concat(...items: (T | ConcatArray<T>)[]): T[]
401
- concat(...items: (T | ConcatArray<T>)[]): T[] {
402
- return this[forwardArray].concat(...items)
403
- }
404
-
405
- /**
406
- * Tests whether all elements in the array pass the test implemented by the provided function
407
- */
408
- every(
409
- predicate: (value: T, index: number, array: readonly T[]) => unknown,
410
- thisArg?: any
411
- ): boolean {
412
- return this[forwardArray].every(predicate, thisArg)
413
- }
414
-
415
- /**
416
- * Tests whether at least one element in the array passes the test implemented by the provided function
417
- */
418
- some(
419
- predicate: (value: T, index: number, array: readonly T[]) => unknown,
420
- thisArg?: any
421
- ): boolean {
422
- return this[forwardArray].some(predicate, thisArg)
423
- }
424
-
425
- /**
426
- * Joins all elements of an array into a string
427
- */
428
- join(separator?: string): string {
429
- return this[forwardArray].join(separator)
430
- }
431
-
432
- /**
433
- * Returns a new array iterator that contains the keys for each index in the array
434
- */
435
- keys(): IterableIterator<number> {
436
- return this[forwardArray].keys()
437
- }
438
-
439
- /**
440
- * Returns a new array iterator that contains the values for each index in the array
441
- */
442
- values(): IterableIterator<T> {
443
- return this[forwardArray].values()
444
- }
445
-
446
- /**
447
- * Returns a new array iterator that contains the key/value pairs for each index in the array
448
- */
449
- entries(): IterableIterator<[number, T]> {
450
- return this[forwardArray].entries()
451
- }
452
-
453
- /**
454
- * Returns a string representation of the array
455
- */
456
- toString(): string {
457
- return this[forwardArray].toString()
458
- }
459
-
460
- /**
461
- * Returns a localized string representing the array
462
- */
463
- toLocaleString(
464
- locales?: string | string[],
465
- options?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions
466
- ): string {
467
- return this[forwardArray].toLocaleString(locales as string | string[], options)
468
- }
469
-
470
- /**
471
- * Returns the element at the specified index, or undefined if the index is out of bounds
472
- */
473
- at(index: number): T | undefined {
474
- return this[forwardArray].at(index)
475
- }
476
-
477
- /**
478
- * Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth
479
- */
480
- flat(depth?: number): T[] {
481
- return this[forwardArray].flat(depth) as T[]
482
- }
483
-
484
- /**
485
- * Returns a new array formed by applying a given callback function to each element of the array,
486
- * and then flattening the result by one level
487
- */
488
- flatMap<U, This = undefined>(
489
- callback: (this: This, value: T, index: number, array: readonly T[]) => U | ReadonlyArray<U>,
490
- thisArg?: This
491
- ): U[] {
492
- return this[forwardArray].flatMap(callback as any, thisArg)
493
- }
494
-
495
- /**
496
- * Returns a new array with elements in reversed order (ES2023)
497
- */
498
- toReversed(): T[] {
499
- return this[forwardArray].toReversed?.() ?? [...this[forwardArray]].reverse()
500
- }
501
-
502
- /**
503
- * Returns a new array with elements sorted (ES2023)
504
- */
505
- toSorted(compareFn?: ((a: T, b: T) => number) | undefined): T[] {
506
- return this[forwardArray].toSorted?.(compareFn) ?? [...this[forwardArray]].sort(compareFn)
507
- }
508
-
509
- /**
510
- * Returns a new array with some elements removed and/or replaced at a given index (ES2023)
511
- */
512
- toSpliced(start: number, deleteCount?: number, ...items: T[]): T[] {
513
- if (deleteCount === undefined) return this[forwardArray].toSpliced(start)
514
- return this[forwardArray].toSpliced(start, deleteCount, ...items)
515
- }
516
-
517
- /**
518
- * Returns a new array with the element at the given index replaced with the given value (ES2023)
519
- */
520
- with(index: number, value: T): T[] {
521
- return this[forwardArray].with(index, value)
522
- }
523
- get [Symbol.unscopables]() {
524
- return this[forwardArray][Symbol.unscopables]
525
- }
526
- }
@@ -1,59 +0,0 @@
1
- /**
2
- * Introspection API for Mutts
3
- * Designed for AI agents and advanced debugging tools to programmatically analyze the reactive system.
4
- */
5
-
6
- import {
7
- type EffectNode,
8
- forceEnableGraphTracking,
9
- type GraphEdge,
10
- getDependencies,
11
- getDependencyGraph,
12
- getDependents,
13
- getMutationHistory,
14
- type MutationRecord,
15
- type ObjectNode,
16
- type ReactivityGraph,
17
- } from '../debug/debug'
18
- import { options, type ReactiveDebugInfo, ReactiveErrorCode } from './reactive/types'
19
-
20
- export {
21
- getDependencyGraph,
22
- getDependents,
23
- getDependencies,
24
- getMutationHistory,
25
- options,
26
- ReactiveErrorCode,
27
- }
28
-
29
- export type {
30
- MutationRecord,
31
- ReactivityGraph,
32
- EffectNode,
33
- ObjectNode,
34
- GraphEdge,
35
- ReactiveDebugInfo,
36
- }
37
-
38
- /**
39
- * Enable introspection features (history recording, etc.)
40
- * @param config Configuration options
41
- */
42
- export function enableIntrospection(config: { historySize?: number } = {}) {
43
- options.introspection.enableHistory = true
44
- forceEnableGraphTracking()
45
- if (config.historySize) {
46
- options.introspection.historySize = config.historySize
47
- }
48
- }
49
-
50
- /**
51
- * Capture a complete snapshot of the current reactive state
52
- */
53
- export function snapshot() {
54
- return {
55
- graph: getDependencyGraph(),
56
- history: getMutationHistory(),
57
- timestamp: Date.now(),
58
- }
59
- }