mutts 1.0.5 → 1.0.7

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 (114) hide show
  1. package/README.md +2 -1
  2. package/dist/browser.d.ts +2 -0
  3. package/dist/browser.esm.js +70 -0
  4. package/dist/browser.esm.js.map +1 -0
  5. package/dist/browser.js +161 -0
  6. package/dist/browser.js.map +1 -0
  7. package/dist/chunks/{index-Cvxdw6Ax.js → index-BFYK02LG.js} +5377 -4059
  8. package/dist/chunks/index-BFYK02LG.js.map +1 -0
  9. package/dist/chunks/{index-qiWwozOc.esm.js → index-CNR6QRUl.esm.js} +5247 -3963
  10. package/dist/chunks/index-CNR6QRUl.esm.js.map +1 -0
  11. package/dist/mutts.umd.js +1 -1
  12. package/dist/mutts.umd.js.map +1 -1
  13. package/dist/mutts.umd.min.js +1 -1
  14. package/dist/mutts.umd.min.js.map +1 -1
  15. package/dist/node.d.ts +2 -0
  16. package/dist/node.esm.js +45 -0
  17. package/dist/node.esm.js.map +1 -0
  18. package/dist/node.js +136 -0
  19. package/dist/node.js.map +1 -0
  20. package/docs/ai/api-reference.md +0 -2
  21. package/docs/ai/manual.md +14 -95
  22. package/docs/reactive/advanced.md +7 -111
  23. package/docs/reactive/collections.md +0 -125
  24. package/docs/reactive/core.md +27 -24
  25. package/docs/reactive/debugging.md +168 -0
  26. package/docs/reactive/project.md +1 -1
  27. package/docs/reactive/scan.md +78 -0
  28. package/docs/reactive.md +8 -6
  29. package/docs/std-decorators.md +1 -0
  30. package/docs/zone.md +88 -0
  31. package/package.json +47 -65
  32. package/src/async/browser.ts +87 -0
  33. package/src/async/index.ts +8 -0
  34. package/src/async/node.ts +46 -0
  35. package/src/decorator.ts +15 -9
  36. package/src/destroyable.ts +4 -4
  37. package/src/index.ts +54 -0
  38. package/src/indexable.ts +42 -0
  39. package/src/mixins.ts +2 -2
  40. package/src/reactive/array.ts +149 -141
  41. package/src/reactive/buffer.ts +168 -0
  42. package/src/reactive/change.ts +3 -3
  43. package/src/reactive/debug.ts +1 -1
  44. package/src/reactive/deep-touch.ts +1 -1
  45. package/src/reactive/deep-watch.ts +1 -1
  46. package/src/reactive/effect-context.ts +15 -91
  47. package/src/reactive/effects.ts +138 -170
  48. package/src/reactive/index.ts +10 -13
  49. package/src/reactive/interface.ts +20 -33
  50. package/src/reactive/map.ts +48 -61
  51. package/src/reactive/memoize.ts +87 -31
  52. package/src/reactive/project.ts +43 -22
  53. package/src/reactive/proxy.ts +18 -43
  54. package/src/reactive/record.ts +3 -3
  55. package/src/reactive/register.ts +5 -7
  56. package/src/reactive/registry.ts +59 -0
  57. package/src/reactive/set.ts +42 -56
  58. package/src/reactive/tracking.ts +5 -62
  59. package/src/reactive/types.ts +79 -19
  60. package/src/std-decorators.ts +9 -9
  61. package/src/utils.ts +203 -19
  62. package/src/zone.ts +127 -0
  63. package/dist/chunks/_tslib-BgjropY9.js +0 -81
  64. package/dist/chunks/_tslib-BgjropY9.js.map +0 -1
  65. package/dist/chunks/_tslib-Mzh1rNsX.esm.js +0 -75
  66. package/dist/chunks/_tslib-Mzh1rNsX.esm.js.map +0 -1
  67. package/dist/chunks/decorator-DLvrD0UF.js +0 -265
  68. package/dist/chunks/decorator-DLvrD0UF.js.map +0 -1
  69. package/dist/chunks/decorator-DqiszP7i.esm.js +0 -253
  70. package/dist/chunks/decorator-DqiszP7i.esm.js.map +0 -1
  71. package/dist/chunks/index-Cvxdw6Ax.js.map +0 -1
  72. package/dist/chunks/index-qiWwozOc.esm.js.map +0 -1
  73. package/dist/decorator.d.ts +0 -107
  74. package/dist/decorator.esm.js +0 -2
  75. package/dist/decorator.esm.js.map +0 -1
  76. package/dist/decorator.js +0 -11
  77. package/dist/decorator.js.map +0 -1
  78. package/dist/destroyable.d.ts +0 -90
  79. package/dist/destroyable.esm.js +0 -109
  80. package/dist/destroyable.esm.js.map +0 -1
  81. package/dist/destroyable.js +0 -116
  82. package/dist/destroyable.js.map +0 -1
  83. package/dist/eventful.d.ts +0 -20
  84. package/dist/eventful.esm.js +0 -66
  85. package/dist/eventful.esm.js.map +0 -1
  86. package/dist/eventful.js +0 -68
  87. package/dist/eventful.js.map +0 -1
  88. package/dist/index.d.ts +0 -19
  89. package/dist/index.esm.js +0 -8
  90. package/dist/index.esm.js.map +0 -1
  91. package/dist/index.js +0 -95
  92. package/dist/index.js.map +0 -1
  93. package/dist/indexable.d.ts +0 -243
  94. package/dist/indexable.esm.js +0 -285
  95. package/dist/indexable.esm.js.map +0 -1
  96. package/dist/indexable.js +0 -291
  97. package/dist/indexable.js.map +0 -1
  98. package/dist/promiseChain.d.ts +0 -21
  99. package/dist/promiseChain.esm.js +0 -78
  100. package/dist/promiseChain.esm.js.map +0 -1
  101. package/dist/promiseChain.js +0 -80
  102. package/dist/promiseChain.js.map +0 -1
  103. package/dist/reactive.d.ts +0 -885
  104. package/dist/reactive.esm.js +0 -5
  105. package/dist/reactive.esm.js.map +0 -1
  106. package/dist/reactive.js +0 -59
  107. package/dist/reactive.js.map +0 -1
  108. package/dist/std-decorators.d.ts +0 -52
  109. package/dist/std-decorators.esm.js +0 -196
  110. package/dist/std-decorators.esm.js.map +0 -1
  111. package/dist/std-decorators.js +0 -204
  112. package/dist/std-decorators.js.map +0 -1
  113. package/src/reactive/mapped.ts +0 -129
  114. package/src/reactive/zone.ts +0 -208
@@ -1 +0,0 @@
1
- {"version":3,"file":"eventful.js","sources":["../src/eventful.ts"],"sourcesContent":["/**\n * Base type for event maps - all event handlers must be functions\n */\nexport type EventsBase = Record<string, (...args: any[]) => void>\n/**\n * A type-safe event system that provides a clean API for event handling\n * @template Events - The event map defining event names and their handler signatures\n */\nexport class Eventful<Events extends EventsBase> {\n\treadonly #events = new Map<keyof Events, ((...args: any[]) => void)[]>()\n\treadonly #hooks = [] as ((...args: any[]) => void)[]\n\n\tpublic hook(\n\t\tcb: <EventType extends keyof Events>(\n\t\t\tevent: EventType,\n\t\t\t...args: Parameters<Events[EventType]>\n\t\t) => void\n\t): () => void {\n\t\tif (!this.#hooks.includes(cb)) this.#hooks.push(cb)\n\t\treturn () => {\n\t\t\tthis.#hooks.splice(this.#hooks.indexOf(cb), 1)\n\t\t}\n\t}\n\n\tpublic on(events: Partial<Events>): void\n\tpublic on<EventType extends keyof Events>(event: EventType, cb: Events[EventType]): () => void\n\tpublic on<EventType extends keyof Events>(\n\t\teventOrEvents: EventType | Partial<Events>,\n\t\tcb?: Events[EventType]\n\t): () => void {\n\t\tif (typeof eventOrEvents === 'object') {\n\t\t\tfor (const e of Object.keys(eventOrEvents) as (keyof Events)[]) {\n\t\t\t\tthis.on(e, eventOrEvents[e]!)\n\t\t\t}\n\t\t} else if (cb !== undefined) {\n\t\t\tlet callbacks = this.#events.get(eventOrEvents)\n\t\t\tif (!callbacks) {\n\t\t\t\tcallbacks = []\n\t\t\t\tthis.#events.set(eventOrEvents, callbacks)\n\t\t\t}\n\t\t\tcallbacks.push(cb)\n\t\t}\n\t\t// @ts-expect-error Generic case leads to generic case\n\t\treturn () => this.off(eventOrEvents, cb)\n\t}\n\tpublic off(events: Partial<Events>): void\n\tpublic off<EventType extends keyof Events>(event: EventType, cb?: Events[EventType]): void\n\tpublic off<EventType extends keyof Events>(\n\t\teventOrEvents: EventType | Partial<Events>,\n\t\tcb?: Events[EventType]\n\t): void {\n\t\tif (typeof eventOrEvents === 'object') {\n\t\t\tfor (const e of Object.keys(eventOrEvents) as (keyof Events)[]) {\n\t\t\t\tthis.off(e, eventOrEvents[e])\n\t\t\t}\n\t\t} else if (cb !== null && cb !== undefined) {\n\t\t\tconst callbacks = this.#events.get(eventOrEvents)\n\t\t\tif (callbacks) {\n\t\t\t\tthis.#events.set(\n\t\t\t\t\teventOrEvents,\n\t\t\t\t\tcallbacks.filter((c) => c !== cb)\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\t// Remove all listeners for this event\n\t\t\tthis.#events.delete(eventOrEvents)\n\t\t}\n\t}\n\tpublic emit<EventType extends keyof Events>(\n\t\tevent: EventType,\n\t\t...args: Parameters<Events[EventType]>\n\t) {\n\t\tconst callbacks = this.#events.get(event)\n\t\tif (callbacks) for (const cb of callbacks) cb.apply(this, args)\n\t\tfor (const cb of this.#hooks) cb.call(this, event, ...args)\n\t}\n}\n"],"names":["__classPrivateFieldGet"],"mappings":";;;;;AAIA;;;AAGG;MACU,QAAQ,CAAA;AAArB,IAAA,WAAA,GAAA;QACU,gBAAA,CAAA,GAAA,CAAA,IAAA,EAAU,IAAI,GAAG,EAA8C,CAAA;AAC/D,QAAA,eAAA,CAAA,GAAA,CAAA,IAAA,EAAS,EAAkC,CAAA;IAkErD;AAhEQ,IAAA,IAAI,CACV,EAGS,EAAA;QAET,IAAI,CAACA,8BAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;AAAE,YAAAA,6BAAA,CAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO,CAAC,IAAI,CAAC,EAAE,CAAC;AACnD,QAAA,OAAO,MAAK;AACX,YAAAA,6BAAA,CAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO,CAAC,MAAM,CAACA,8BAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAC/C,QAAA,CAAC;IACF;IAIO,EAAE,CACR,aAA0C,EAC1C,EAAsB,EAAA;AAEtB,QAAA,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE;YACtC,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAqB,EAAE;gBAC/D,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAE,CAAC;YAC9B;QACD;AAAO,aAAA,IAAI,EAAE,KAAK,SAAS,EAAE;YAC5B,IAAI,SAAS,GAAGA,6BAAA,CAAA,IAAI,EAAA,gBAAA,EAAA,GAAA,CAAQ,CAAC,GAAG,CAAC,aAAa,CAAC;YAC/C,IAAI,CAAC,SAAS,EAAE;gBACf,SAAS,GAAG,EAAE;gBACdA,6BAAA,CAAA,IAAI,wBAAQ,CAAC,GAAG,CAAC,aAAa,EAAE,SAAS,CAAC;YAC3C;AACA,YAAA,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QACnB;;QAEA,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,EAAE,CAAC;IACzC;IAGO,GAAG,CACT,aAA0C,EAC1C,EAAsB,EAAA;AAEtB,QAAA,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE;YACtC,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAqB,EAAE;gBAC/D,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;YAC9B;QACD;aAAO,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,SAAS,EAAE;YAC3C,MAAM,SAAS,GAAGA,6BAAA,CAAA,IAAI,EAAA,gBAAA,EAAA,GAAA,CAAQ,CAAC,GAAG,CAAC,aAAa,CAAC;YACjD,IAAI,SAAS,EAAE;gBACdA,6BAAA,CAAA,IAAI,wBAAQ,CAAC,GAAG,CACf,aAAa,EACb,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CACjC;YACF;QACD;aAAO;;AAEN,YAAAA,6BAAA,CAAA,IAAI,EAAA,gBAAA,EAAA,GAAA,CAAQ,CAAC,MAAM,CAAC,aAAa,CAAC;QACnC;IACD;AACO,IAAA,IAAI,CACV,KAAgB,EAChB,GAAG,IAAmC,EAAA;QAEtC,MAAM,SAAS,GAAGA,6BAAA,CAAA,IAAI,EAAA,gBAAA,EAAA,GAAA,CAAQ,CAAC,GAAG,CAAC,KAAK,CAAC;AACzC,QAAA,IAAI,SAAS;YAAE,KAAK,MAAM,EAAE,IAAI,SAAS;AAAE,gBAAA,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;AAC/D,QAAA,KAAK,MAAM,EAAE,IAAIA,6BAAA,CAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO;YAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAC5D;AACA;;;;;"}
package/dist/index.d.ts DELETED
@@ -1,19 +0,0 @@
1
- export * from './decorator.js'
2
- export * from './destroyable.js'
3
- export * from './eventful.js'
4
- export * from './indexable.js'
5
- export * from './iterableWeak.js'
6
- export * from './mixins.js'
7
- export * from './reactive.js'
8
- export * from './std-decorators.js'
9
- export * from './utils.js'
10
-
11
- // Augment Array.isArray to properly handle readonly arrays in type narrowing
12
- interface ArrayConstructor {
13
- /**
14
- * Determines whether an object is an array.
15
- * @param arg Any value to test.
16
- * @returns True if the value is an array (mutable or readonly), false otherwise.
17
- */
18
- isArray(arg: any): arg is any[] | readonly any[]
19
- }
package/dist/index.esm.js DELETED
@@ -1,8 +0,0 @@
1
- export { D as DecoratorError, R as ReflectGet, b as ReflectSet, a as arrayEquals, d as decorator, i as isConstructor, c as isOwnAccessor, l as legacyDecorator, m as modernDecorator, r as renamed, z as zip } from './chunks/decorator-DqiszP7i.esm.js';
2
- export { Destroyable, DestructionError, allocated, allocatedValues, callOnGC, destructor } from './destroyable.esm.js';
3
- export { Eventful } from './eventful.esm.js';
4
- export { ArrayReadForward, Indexable, forwardArray, getAt, setAt } from './indexable.esm.js';
5
- export { I as IterableWeakMap, a as IterableWeakSet, O as ReactiveBase, X as ReactiveError, R as ReadOnlyError, U as Register, j as addBatchCleanup, k as atomic, l as batch, n as biDi, c as buildReactivityGraph, z as cleanedBy, A as cleanup, h as deepWatch, o as defer, B as derived, q as effect, e as enableDevTools, u as getActivationLog, v as getActiveEffect, L as getActiveProjection, g as getState, H as immutables, i as isDevtoolsEnabled, J as isNonReactive, N as isReactive, Y as isZoneEnabled, E as mapped, G as memoize, m as mixin, S as organize, T as organized, p as profileInfo, M as project, P as reactive, W as reactiveOptions, F as reduced, V as register, r as registerEffectForDebug, K as registerNativeReactivity, d as registerObjectForDebug, w as root, s as setEffectName, f as setObjectName, Z as setZoneEnabled, t as touched, b as touched1, x as trackEffect, C as unreactive, y as untracked, Q as unwrap, D as watch } from './chunks/index-qiWwozOc.esm.js';
6
- export { cache, cached, debounce, deprecated, describe, isCached, throttle } from './std-decorators.esm.js';
7
- import './chunks/_tslib-Mzh1rNsX.esm.js';
8
- //# sourceMappingURL=index.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
package/dist/index.js DELETED
@@ -1,95 +0,0 @@
1
- 'use strict';
2
-
3
- var decorator = require('./chunks/decorator-DLvrD0UF.js');
4
- var destroyable = require('./destroyable.js');
5
- var eventful = require('./eventful.js');
6
- var indexable = require('./indexable.js');
7
- var reactive = require('./chunks/index-Cvxdw6Ax.js');
8
- var stdDecorators = require('./std-decorators.js');
9
- require('./chunks/_tslib-BgjropY9.js');
10
-
11
-
12
-
13
- exports.DecoratorError = decorator.DecoratorError;
14
- exports.ReflectGet = decorator.ReflectGet;
15
- exports.ReflectSet = decorator.ReflectSet;
16
- exports.arrayEquals = decorator.arrayEquals;
17
- exports.decorator = decorator.decorator;
18
- exports.isConstructor = decorator.isConstructor;
19
- exports.isOwnAccessor = decorator.isOwnAccessor;
20
- exports.legacyDecorator = decorator.legacyDecorator;
21
- exports.modernDecorator = decorator.modernDecorator;
22
- exports.renamed = decorator.renamed;
23
- exports.zip = decorator.zip;
24
- exports.Destroyable = destroyable.Destroyable;
25
- exports.DestructionError = destroyable.DestructionError;
26
- exports.allocated = destroyable.allocated;
27
- exports.allocatedValues = destroyable.allocatedValues;
28
- exports.callOnGC = destroyable.callOnGC;
29
- exports.destructor = destroyable.destructor;
30
- exports.Eventful = eventful.Eventful;
31
- exports.ArrayReadForward = indexable.ArrayReadForward;
32
- exports.Indexable = indexable.Indexable;
33
- exports.forwardArray = indexable.forwardArray;
34
- exports.getAt = indexable.getAt;
35
- exports.setAt = indexable.setAt;
36
- exports.IterableWeakMap = reactive.IterableWeakMap;
37
- exports.IterableWeakSet = reactive.IterableWeakSet;
38
- exports.ReactiveBase = reactive.ReactiveBase;
39
- exports.ReactiveError = reactive.ReactiveError;
40
- exports.ReadOnlyError = reactive.ReadOnlyError;
41
- exports.Register = reactive.Register;
42
- exports.addBatchCleanup = reactive.addBatchCleanup;
43
- exports.atomic = reactive.atomic;
44
- exports.batch = reactive.batch;
45
- exports.biDi = reactive.biDi;
46
- exports.buildReactivityGraph = reactive.buildReactivityGraph;
47
- exports.cleanedBy = reactive.cleanedBy;
48
- exports.cleanup = reactive.cleanup;
49
- exports.deepWatch = reactive.deepWatch;
50
- exports.defer = reactive.defer;
51
- exports.derived = reactive.derived;
52
- exports.effect = reactive.effect;
53
- exports.enableDevTools = reactive.enableDevTools;
54
- exports.getActivationLog = reactive.getActivationLog;
55
- exports.getActiveEffect = reactive.getActiveEffect;
56
- exports.getActiveProjection = reactive.getActiveProjection;
57
- exports.getState = reactive.getState;
58
- exports.immutables = reactive.immutables;
59
- exports.isDevtoolsEnabled = reactive.isDevtoolsEnabled;
60
- exports.isNonReactive = reactive.isNonReactive;
61
- exports.isReactive = reactive.isReactive;
62
- exports.isZoneEnabled = reactive.isZoneEnabled;
63
- exports.mapped = reactive.mapped;
64
- exports.memoize = reactive.memoize;
65
- exports.mixin = reactive.mixin;
66
- exports.organize = reactive.organize;
67
- exports.organized = reactive.organized;
68
- exports.profileInfo = reactive.profileInfo;
69
- exports.project = reactive.project;
70
- exports.reactive = reactive.reactive;
71
- exports.reactiveOptions = reactive.options;
72
- exports.reduced = reactive.reduced;
73
- exports.register = reactive.register;
74
- exports.registerEffectForDebug = reactive.registerEffectForDebug;
75
- exports.registerNativeReactivity = reactive.registerNativeReactivity;
76
- exports.registerObjectForDebug = reactive.registerObjectForDebug;
77
- exports.root = reactive.root;
78
- exports.setEffectName = reactive.setEffectName;
79
- exports.setObjectName = reactive.setObjectName;
80
- exports.setZoneEnabled = reactive.setZoneEnabled;
81
- exports.touched = reactive.touched;
82
- exports.touched1 = reactive.touched1;
83
- exports.trackEffect = reactive.trackEffect;
84
- exports.unreactive = reactive.unreactive;
85
- exports.untracked = reactive.untracked;
86
- exports.unwrap = reactive.unwrap;
87
- exports.watch = reactive.watch;
88
- exports.cache = stdDecorators.cache;
89
- exports.cached = stdDecorators.cached;
90
- exports.debounce = stdDecorators.debounce;
91
- exports.deprecated = stdDecorators.deprecated;
92
- exports.describe = stdDecorators.describe;
93
- exports.isCached = stdDecorators.isCached;
94
- exports.throttle = stdDecorators.throttle;
95
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,243 +0,0 @@
1
- /**
2
- * Symbol for defining custom getter logic for numeric index access
3
- */
4
- declare const getAt: unique symbol;
5
- /**
6
- * Symbol for defining custom setter logic for numeric index access
7
- */
8
- declare const setAt: unique symbol;
9
- interface IndexingAt<Items = any> {
10
- [getAt](index: number): Items;
11
- }
12
- interface Accessor<T, Items> {
13
- get(this: T, index: number): Items;
14
- set?(this: T, index: number, value: Items): void;
15
- getLength?(this: T): number;
16
- setLength?(this: T, value: number): void;
17
- }
18
- declare abstract class AbstractGetAt<Items = any> {
19
- abstract [getAt](index: number): Items;
20
- }
21
- /**
22
- * Creates an indexable class with a base class and accessor object
23
- * @param base - The base class to extend
24
- * @param accessor - Object containing get/set methods for numeric index access
25
- * @returns A class that supports numeric index access
26
- */
27
- declare function Indexable<Items, Base extends abstract new (...args: any[]) => any>(base: Base, accessor: Accessor<InstanceType<Base>, Items>): new (...args: ConstructorParameters<Base>) => InstanceType<Base> & {
28
- [x: number]: Items;
29
- };
30
- /**
31
- * Creates an indexable class with only an accessor object (no base class)
32
- * @param accessor - Object containing get/set methods for numeric index access
33
- * @returns A class that supports numeric index access
34
- */
35
- declare function Indexable<Items>(accessor: Accessor<any, Items>): new () => {
36
- [x: number]: Items;
37
- };
38
- /**
39
- * Creates an indexable class with a base class that has [getAt] method
40
- * @param base - The base class that implements [getAt] method
41
- * @returns A class that supports numeric index access using the base class's [getAt] method
42
- */
43
- declare function Indexable<Base extends new (...args: any[]) => IndexingAt>(base: Base): new (...args: ConstructorParameters<Base>) => InstanceType<Base> & {
44
- [x: number]: AtReturnType<InstanceType<Base>>;
45
- };
46
- /**
47
- * Creates an abstract indexable base class
48
- * @returns An abstract class that supports numeric index access
49
- */
50
- declare function Indexable<Items>(): abstract new (...args: any[]) => AbstractGetAt & {
51
- [x: number]: Items;
52
- };
53
- type AtReturnType<T> = T extends {
54
- [getAt](index: number): infer R;
55
- } ? R : never;
56
- /**
57
- * Symbol for accessing the forwarded array in ArrayReadForward
58
- */
59
- declare const forwardArray: unique symbol;
60
- /**
61
- * A read-only array forwarder that implements all reading/iterating methods of Array
62
- * but does not implement modification methods.
63
- *
64
- * The constructor takes a callback that returns an array, and all methods forward
65
- * their behavior to the result of that callback.
66
- */
67
- declare class ArrayReadForward<T> {
68
- protected get [forwardArray](): readonly T[];
69
- /**
70
- * Get the length of the array
71
- */
72
- get length(): number;
73
- /**
74
- * Get an element at a specific index
75
- */
76
- [index: number]: T | undefined;
77
- /**
78
- * Iterator protocol support
79
- */
80
- [Symbol.iterator](): Iterator<T>;
81
- /**
82
- * Creates a new array with the results of calling a provided function on every element
83
- */
84
- map<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U, thisArg?: any): U[];
85
- /**
86
- * Creates a new array with all elements that pass the test implemented by the provided function
87
- */
88
- filter<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S, thisArg?: any): S[];
89
- filter(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T[];
90
- /**
91
- * Executes a reducer function on each element of the array, resulting in a single output value
92
- */
93
- reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T): T;
94
- reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T, initialValue: T): T;
95
- reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
96
- /**
97
- * Executes a reducer function on each element of the array (right-to-left), resulting in a single output value
98
- */
99
- reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T): T;
100
- reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T, initialValue: T): T;
101
- reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
102
- /**
103
- * Executes a provided function once for each array element
104
- */
105
- forEach(callbackfn: (value: T, index: number, array: readonly T[]) => void, thisArg?: any): void;
106
- /**
107
- * Returns the value of the first element in the array that satisfies the provided testing function
108
- */
109
- find<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S, thisArg?: any): S | undefined;
110
- find(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T | undefined;
111
- /**
112
- * Returns the index of the first element in the array that satisfies the provided testing function
113
- */
114
- findIndex(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): number;
115
- /**
116
- * Returns the value of the last element in the array that satisfies the provided testing function
117
- */
118
- findLast<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S, thisArg?: any): S | undefined;
119
- findLast(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T | undefined;
120
- /**
121
- * Returns the index of the last element in the array that satisfies the provided testing function
122
- */
123
- findLastIndex(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): number;
124
- /**
125
- * Determines whether an array includes a certain value among its entries
126
- */
127
- includes(searchElement: T, fromIndex?: number): boolean;
128
- /**
129
- * Returns the first index at which a given element can be found in the array
130
- */
131
- indexOf(searchElement: T, fromIndex?: number): number;
132
- /**
133
- * Returns the last index at which a given element can be found in the array
134
- */
135
- lastIndexOf(searchElement: T, fromIndex?: number): number;
136
- /**
137
- * Returns a shallow copy of a portion of an array into a new array object
138
- */
139
- slice(start?: number, end?: number): T[];
140
- /**
141
- * Returns a new array comprised of this array joined with other array(s) and/or value(s)
142
- */
143
- concat(...items: ConcatArray<T>[]): T[];
144
- concat(...items: (T | ConcatArray<T>)[]): T[];
145
- /**
146
- * Tests whether all elements in the array pass the test implemented by the provided function
147
- */
148
- every(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): boolean;
149
- /**
150
- * Tests whether at least one element in the array passes the test implemented by the provided function
151
- */
152
- some(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): boolean;
153
- /**
154
- * Joins all elements of an array into a string
155
- */
156
- join(separator?: string): string;
157
- /**
158
- * Returns a new array iterator that contains the keys for each index in the array
159
- */
160
- keys(): IterableIterator<number>;
161
- /**
162
- * Returns a new array iterator that contains the values for each index in the array
163
- */
164
- values(): IterableIterator<T>;
165
- /**
166
- * Returns a new array iterator that contains the key/value pairs for each index in the array
167
- */
168
- entries(): IterableIterator<[number, T]>;
169
- /**
170
- * Returns a string representation of the array
171
- */
172
- toString(): string;
173
- /**
174
- * Returns a localized string representing the array
175
- */
176
- toLocaleString(locales?: string | string[], options?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions): string;
177
- /**
178
- * Returns the element at the specified index, or undefined if the index is out of bounds
179
- */
180
- at(index: number): T | undefined;
181
- /**
182
- * Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth
183
- */
184
- flat(depth?: number): T[];
185
- /**
186
- * Returns a new array formed by applying a given callback function to each element of the array,
187
- * and then flattening the result by one level
188
- */
189
- flatMap<U, This = undefined>(callback: (this: This, value: T, index: number, array: readonly T[]) => U | ReadonlyArray<U>, thisArg?: This): U[];
190
- /**
191
- * Returns a new array with elements in reversed order (ES2023)
192
- */
193
- toReversed(): T[];
194
- /**
195
- * Returns a new array with elements sorted (ES2023)
196
- */
197
- toSorted(compareFn?: ((a: T, b: T) => number) | undefined): T[];
198
- /**
199
- * Returns a new array with some elements removed and/or replaced at a given index (ES2023)
200
- */
201
- toSpliced(start: number, deleteCount?: number, ...items: T[]): T[];
202
- /**
203
- * Returns a new array with the element at the given index replaced with the given value (ES2023)
204
- */
205
- with(index: number, value: T): T[];
206
- get [Symbol.unscopables](): {
207
- readonly [x: number]: boolean;
208
- readonly length?: boolean;
209
- toString?: boolean;
210
- toLocaleString?: boolean;
211
- concat?: boolean;
212
- join?: boolean;
213
- slice?: boolean;
214
- indexOf?: boolean;
215
- lastIndexOf?: boolean;
216
- every?: boolean;
217
- some?: boolean;
218
- forEach?: boolean;
219
- map?: boolean;
220
- filter?: boolean;
221
- reduce?: boolean;
222
- reduceRight?: boolean;
223
- find?: boolean;
224
- findIndex?: boolean;
225
- entries?: boolean;
226
- keys?: boolean;
227
- values?: boolean;
228
- includes?: boolean;
229
- flatMap?: boolean;
230
- flat?: boolean;
231
- at?: boolean;
232
- findLast?: boolean;
233
- findLastIndex?: boolean;
234
- toReversed?: boolean;
235
- toSorted?: boolean;
236
- toSpliced?: boolean;
237
- with?: boolean;
238
- [Symbol.iterator]?: boolean;
239
- readonly [Symbol.unscopables]?: boolean;
240
- };
241
- }
242
-
243
- export { ArrayReadForward, Indexable, forwardArray, getAt, setAt };
@@ -1,285 +0,0 @@
1
- /**
2
- * Symbol for defining custom getter logic for numeric index access
3
- */
4
- const getAt = Symbol('getAt');
5
- /**
6
- * Symbol for defining custom setter logic for numeric index access
7
- */
8
- const setAt = Symbol('setAt');
9
- function Indexable(base, accessor) {
10
- if (base && typeof base !== 'function') {
11
- accessor = base;
12
- base = undefined;
13
- }
14
- if (!base) {
15
- //@ts-expect-error
16
- base = class {
17
- };
18
- }
19
- if (!accessor) {
20
- accessor = {
21
- get(index) {
22
- if (typeof this[getAt] !== 'function') {
23
- throw new Error('Indexable class must have an [getAt] method');
24
- }
25
- return this[getAt](index);
26
- },
27
- set(index, value) {
28
- if (typeof this[setAt] !== 'function') {
29
- throw new Error('Indexable class has read-only numeric index access');
30
- }
31
- this[setAt](index, value);
32
- },
33
- };
34
- }
35
- class Indexable extends base {
36
- }
37
- Object.setPrototypeOf(Indexable.prototype, new Proxy(base.prototype, {
38
- //@ts-expect-error
39
- [Symbol.toStringTag]: 'MutTs Indexable',
40
- get(target, prop, receiver) {
41
- if (prop in target) {
42
- const getter = Object.getOwnPropertyDescriptor(target, prop)?.get;
43
- return getter ? getter.call(receiver) : target[prop];
44
- }
45
- if (typeof prop === 'string') {
46
- if (prop === 'length' && accessor.getLength)
47
- return accessor.getLength.call(receiver);
48
- const numProp = Number(prop);
49
- if (!Number.isNaN(numProp)) {
50
- return accessor.get.call(receiver, numProp);
51
- }
52
- }
53
- return undefined;
54
- },
55
- set(target, prop, value, receiver) {
56
- if (prop in target) {
57
- const setter = Object.getOwnPropertyDescriptor(target, prop)?.set;
58
- if (setter)
59
- setter.call(receiver, value);
60
- else
61
- target[prop] = value;
62
- return true;
63
- }
64
- if (typeof prop === 'string') {
65
- if (prop === 'length' && accessor.setLength) {
66
- accessor.setLength.call(receiver, value);
67
- return true;
68
- }
69
- const numProp = Number(prop);
70
- if (!Number.isNaN(numProp)) {
71
- if (!accessor.set)
72
- throw new Error('Indexable class has read-only numeric index access');
73
- accessor.set.call(receiver, numProp, value);
74
- return true;
75
- }
76
- }
77
- Object.defineProperty(receiver, prop, {
78
- value,
79
- writable: true,
80
- enumerable: true,
81
- configurable: true,
82
- });
83
- return true;
84
- },
85
- }));
86
- return Indexable;
87
- }
88
- /**
89
- * Symbol for accessing the forwarded array in ArrayReadForward
90
- */
91
- const forwardArray = Symbol('forwardArray');
92
- /**
93
- * A read-only array forwarder that implements all reading/iterating methods of Array
94
- * but does not implement modification methods.
95
- *
96
- * The constructor takes a callback that returns an array, and all methods forward
97
- * their behavior to the result of that callback.
98
- */
99
- class ArrayReadForward {
100
- get [forwardArray]() {
101
- throw new Error('ArrayReadForward is not implemented');
102
- }
103
- /**
104
- * Get the length of the array
105
- */
106
- get length() {
107
- return this[forwardArray].length;
108
- }
109
- /**
110
- * Iterator protocol support
111
- */
112
- [Symbol.iterator]() {
113
- return this[forwardArray][Symbol.iterator]();
114
- }
115
- // Reading/Iterating methods
116
- /**
117
- * Creates a new array with the results of calling a provided function on every element
118
- */
119
- map(callbackfn, thisArg) {
120
- return this[forwardArray].map(callbackfn, thisArg);
121
- }
122
- filter(predicate, thisArg) {
123
- return this[forwardArray].filter(predicate, thisArg);
124
- }
125
- reduce(callbackfn, initialValue) {
126
- return initialValue !== undefined
127
- ? this[forwardArray].reduce(callbackfn, initialValue)
128
- : this[forwardArray].reduce(callbackfn);
129
- }
130
- reduceRight(callbackfn, initialValue) {
131
- return initialValue !== undefined
132
- ? this[forwardArray].reduceRight(callbackfn, initialValue)
133
- : this[forwardArray].reduceRight(callbackfn);
134
- }
135
- /**
136
- * Executes a provided function once for each array element
137
- */
138
- forEach(callbackfn, thisArg) {
139
- this[forwardArray].forEach(callbackfn, thisArg);
140
- }
141
- find(predicate, thisArg) {
142
- return this[forwardArray].find(predicate, thisArg);
143
- }
144
- /**
145
- * Returns the index of the first element in the array that satisfies the provided testing function
146
- */
147
- findIndex(predicate, thisArg) {
148
- return this[forwardArray].findIndex(predicate, thisArg);
149
- }
150
- findLast(predicate, thisArg) {
151
- return this[forwardArray].findLast(predicate, thisArg);
152
- }
153
- /**
154
- * Returns the index of the last element in the array that satisfies the provided testing function
155
- */
156
- findLastIndex(predicate, thisArg) {
157
- return this[forwardArray].findLastIndex(predicate, thisArg);
158
- }
159
- /**
160
- * Determines whether an array includes a certain value among its entries
161
- */
162
- includes(searchElement, fromIndex) {
163
- return this[forwardArray].includes(searchElement, fromIndex);
164
- }
165
- /**
166
- * Returns the first index at which a given element can be found in the array
167
- */
168
- indexOf(searchElement, fromIndex) {
169
- return this[forwardArray].indexOf(searchElement, fromIndex);
170
- }
171
- /**
172
- * Returns the last index at which a given element can be found in the array
173
- */
174
- lastIndexOf(searchElement, fromIndex) {
175
- return this[forwardArray].lastIndexOf(searchElement, fromIndex);
176
- }
177
- /**
178
- * Returns a shallow copy of a portion of an array into a new array object
179
- */
180
- slice(start, end) {
181
- return this[forwardArray].slice(start, end);
182
- }
183
- concat(...items) {
184
- return this[forwardArray].concat(...items);
185
- }
186
- /**
187
- * Tests whether all elements in the array pass the test implemented by the provided function
188
- */
189
- every(predicate, thisArg) {
190
- return this[forwardArray].every(predicate, thisArg);
191
- }
192
- /**
193
- * Tests whether at least one element in the array passes the test implemented by the provided function
194
- */
195
- some(predicate, thisArg) {
196
- return this[forwardArray].some(predicate, thisArg);
197
- }
198
- /**
199
- * Joins all elements of an array into a string
200
- */
201
- join(separator) {
202
- return this[forwardArray].join(separator);
203
- }
204
- /**
205
- * Returns a new array iterator that contains the keys for each index in the array
206
- */
207
- keys() {
208
- return this[forwardArray].keys();
209
- }
210
- /**
211
- * Returns a new array iterator that contains the values for each index in the array
212
- */
213
- values() {
214
- return this[forwardArray].values();
215
- }
216
- /**
217
- * Returns a new array iterator that contains the key/value pairs for each index in the array
218
- */
219
- entries() {
220
- return this[forwardArray].entries();
221
- }
222
- /**
223
- * Returns a string representation of the array
224
- */
225
- toString() {
226
- return this[forwardArray].toString();
227
- }
228
- /**
229
- * Returns a localized string representing the array
230
- */
231
- toLocaleString(locales, options) {
232
- return this[forwardArray].toLocaleString(locales, options);
233
- }
234
- /**
235
- * Returns the element at the specified index, or undefined if the index is out of bounds
236
- */
237
- at(index) {
238
- return this[forwardArray].at(index);
239
- }
240
- /**
241
- * Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth
242
- */
243
- flat(depth) {
244
- return this[forwardArray].flat(depth);
245
- }
246
- /**
247
- * Returns a new array formed by applying a given callback function to each element of the array,
248
- * and then flattening the result by one level
249
- */
250
- flatMap(callback, thisArg) {
251
- return this[forwardArray].flatMap(callback, thisArg);
252
- }
253
- /**
254
- * Returns a new array with elements in reversed order (ES2023)
255
- */
256
- toReversed() {
257
- return this[forwardArray].toReversed?.() ?? [...this[forwardArray]].reverse();
258
- }
259
- /**
260
- * Returns a new array with elements sorted (ES2023)
261
- */
262
- toSorted(compareFn) {
263
- return this[forwardArray].toSorted?.(compareFn) ?? [...this[forwardArray]].sort(compareFn);
264
- }
265
- /**
266
- * Returns a new array with some elements removed and/or replaced at a given index (ES2023)
267
- */
268
- toSpliced(start, deleteCount, ...items) {
269
- if (deleteCount === undefined)
270
- return this[forwardArray].toSpliced(start);
271
- return this[forwardArray].toSpliced(start, deleteCount, ...items);
272
- }
273
- /**
274
- * Returns a new array with the element at the given index replaced with the given value (ES2023)
275
- */
276
- with(index, value) {
277
- return this[forwardArray].with(index, value);
278
- }
279
- get [Symbol.unscopables]() {
280
- return this[forwardArray][Symbol.unscopables];
281
- }
282
- }
283
-
284
- export { ArrayReadForward, Indexable, forwardArray, getAt, setAt };
285
- //# sourceMappingURL=indexable.esm.js.map