@signaltree/core 3.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/package.json +59 -12
  2. package/src/enhancers/batching/index.d.ts +1 -0
  3. package/src/enhancers/batching/index.js +1 -0
  4. package/src/enhancers/batching/jest.config.d.ts +15 -0
  5. package/src/enhancers/batching/jest.config.js +21 -0
  6. package/src/enhancers/batching/lib/batching.d.ts +16 -0
  7. package/src/enhancers/batching/lib/batching.js +155 -0
  8. package/src/enhancers/batching/test-setup.d.ts +1 -0
  9. package/src/enhancers/batching/test-setup.js +5 -0
  10. package/src/enhancers/computed/index.d.ts +1 -0
  11. package/src/enhancers/computed/index.js +1 -0
  12. package/src/enhancers/computed/jest.config.d.ts +15 -0
  13. package/src/enhancers/computed/jest.config.js +21 -0
  14. package/src/enhancers/computed/lib/computed.d.ts +12 -0
  15. package/src/enhancers/computed/lib/computed.js +18 -0
  16. package/src/enhancers/devtools/index.d.ts +1 -0
  17. package/src/enhancers/devtools/index.js +1 -0
  18. package/src/enhancers/devtools/jest.config.d.ts +15 -0
  19. package/src/enhancers/devtools/jest.config.js +21 -0
  20. package/src/enhancers/devtools/lib/devtools.d.ts +77 -0
  21. package/src/enhancers/devtools/lib/devtools.js +278 -0
  22. package/src/enhancers/devtools/test-setup.d.ts +1 -0
  23. package/src/enhancers/devtools/test-setup.js +5 -0
  24. package/src/enhancers/entities/index.d.ts +1 -0
  25. package/src/enhancers/entities/index.js +1 -0
  26. package/src/enhancers/entities/jest.config.d.ts +15 -0
  27. package/src/enhancers/entities/jest.config.js +21 -0
  28. package/src/enhancers/entities/lib/entities.d.ts +22 -0
  29. package/src/enhancers/entities/lib/entities.js +110 -0
  30. package/src/enhancers/entities/test-setup.d.ts +1 -0
  31. package/src/enhancers/entities/test-setup.js +5 -0
  32. package/src/enhancers/index.d.ts +3 -0
  33. package/src/enhancers/index.js +84 -0
  34. package/src/enhancers/memoization/index.d.ts +1 -0
  35. package/src/enhancers/memoization/index.js +1 -0
  36. package/src/enhancers/memoization/jest.config.d.ts +15 -0
  37. package/src/enhancers/memoization/jest.config.js +21 -0
  38. package/src/enhancers/memoization/lib/memoization.d.ts +65 -0
  39. package/src/enhancers/memoization/lib/memoization.js +391 -0
  40. package/src/enhancers/memoization/test-setup.d.ts +1 -0
  41. package/src/enhancers/memoization/test-setup.js +5 -0
  42. package/src/enhancers/middleware/index.d.ts +2 -0
  43. package/src/enhancers/middleware/index.js +2 -0
  44. package/src/enhancers/middleware/jest.config.d.ts +15 -0
  45. package/src/enhancers/middleware/jest.config.js +21 -0
  46. package/src/enhancers/middleware/lib/async-helpers.d.ts +8 -0
  47. package/src/enhancers/middleware/lib/async-helpers.js +85 -0
  48. package/src/enhancers/middleware/lib/middleware.d.ts +11 -0
  49. package/src/enhancers/middleware/lib/middleware.js +179 -0
  50. package/src/enhancers/middleware/test-setup.d.ts +1 -0
  51. package/src/enhancers/middleware/test-setup.js +5 -0
  52. package/src/enhancers/presets/index.d.ts +1 -0
  53. package/src/enhancers/presets/index.js +1 -0
  54. package/src/enhancers/presets/jest.config.d.ts +15 -0
  55. package/src/enhancers/presets/jest.config.js +21 -0
  56. package/src/enhancers/presets/lib/presets.d.ts +11 -0
  57. package/src/enhancers/presets/lib/presets.js +102 -0
  58. package/src/enhancers/presets/test-setup.d.ts +1 -0
  59. package/src/enhancers/presets/test-setup.js +5 -0
  60. package/src/enhancers/serialization/constants.d.ts +14 -0
  61. package/src/enhancers/serialization/constants.js +14 -0
  62. package/src/enhancers/serialization/index.d.ts +2 -0
  63. package/src/enhancers/serialization/index.js +2 -0
  64. package/src/enhancers/serialization/jest.config.d.ts +15 -0
  65. package/src/enhancers/serialization/jest.config.js +21 -0
  66. package/src/enhancers/serialization/lib/serialization.d.ts +59 -0
  67. package/src/enhancers/serialization/lib/serialization.js +668 -0
  68. package/src/enhancers/serialization/test-setup.d.ts +1 -0
  69. package/src/enhancers/serialization/test-setup.js +5 -0
  70. package/src/enhancers/time-travel/index.d.ts +1 -0
  71. package/src/enhancers/time-travel/index.js +1 -0
  72. package/src/enhancers/time-travel/jest.config.d.ts +15 -0
  73. package/src/enhancers/time-travel/jest.config.js +21 -0
  74. package/src/enhancers/time-travel/lib/time-travel.d.ts +36 -0
  75. package/src/enhancers/time-travel/lib/time-travel.js +192 -0
  76. package/src/enhancers/time-travel/lib/utils.d.ts +1 -0
  77. package/src/enhancers/time-travel/lib/utils.js +1 -0
  78. package/src/enhancers/time-travel/test-setup.d.ts +1 -0
  79. package/src/enhancers/time-travel/test-setup.js +5 -0
  80. package/src/enhancers/types.d.ts +105 -0
  81. package/src/enhancers/types.js +0 -0
  82. package/src/index.d.ts +16 -0
  83. package/src/index.js +15 -0
  84. package/src/lib/constants.d.ts +42 -0
  85. package/src/lib/constants.js +61 -0
  86. package/src/lib/memory/memory-manager.d.ts +30 -0
  87. package/src/lib/memory/memory-manager.js +166 -0
  88. package/src/lib/performance/diff-engine.d.ts +33 -0
  89. package/src/lib/performance/diff-engine.js +156 -0
  90. package/src/lib/performance/path-index.d.ts +25 -0
  91. package/src/lib/performance/path-index.js +154 -0
  92. package/src/lib/performance/update-engine.d.ts +32 -0
  93. package/src/lib/performance/update-engine.js +193 -0
  94. package/src/lib/security/security-validator.d.ts +33 -0
  95. package/src/lib/security/security-validator.js +139 -0
  96. package/src/lib/signal-tree.d.ts +8 -0
  97. package/{fesm2022/signaltree-core.mjs → src/lib/signal-tree.js} +100 -573
  98. package/src/lib/types.d.ts +164 -0
  99. package/src/lib/types.js +9 -0
  100. package/src/lib/utils.d.ts +27 -0
  101. package/src/lib/utils.js +286 -0
  102. package/README.md +0 -1455
  103. package/fesm2022/signaltree-core.mjs.map +0 -1
  104. package/index.d.ts +0 -216
@@ -0,0 +1,278 @@
1
+ import { signal } from '@angular/core';
2
+ function createActivityTracker() {
3
+ const modules = new Map();
4
+ return {
5
+ trackMethodCall: (module, method, duration) => {
6
+ const existing = modules.get(module);
7
+ if (existing) {
8
+ existing.lastActivity = new Date();
9
+ existing.operationCount++;
10
+ existing.averageExecutionTime =
11
+ (existing.averageExecutionTime * (existing.operationCount - 1) +
12
+ duration) /
13
+ existing.operationCount;
14
+ }
15
+ else {
16
+ modules.set(module, {
17
+ name: module,
18
+ methods: [method],
19
+ addedAt: new Date(),
20
+ lastActivity: new Date(),
21
+ operationCount: 1,
22
+ averageExecutionTime: duration,
23
+ errorCount: 0,
24
+ });
25
+ }
26
+ },
27
+ trackError: (module, error, context) => {
28
+ const existing = modules.get(module);
29
+ if (existing) {
30
+ existing.errorCount++;
31
+ }
32
+ console.error(`❌ [${module}] Error${context ? ` in ${context}` : ''}:`, error);
33
+ },
34
+ getModuleActivity: (module) => modules.get(module),
35
+ getAllModules: () => Array.from(modules.values()),
36
+ };
37
+ }
38
+ function createCompositionLogger() {
39
+ const logs = [];
40
+ const addLog = (module, type, data) => {
41
+ logs.push({ timestamp: new Date(), module, type, data });
42
+ if (logs.length > 1000) {
43
+ logs.splice(0, logs.length - 1000);
44
+ }
45
+ };
46
+ return {
47
+ logComposition: (modules, action) => {
48
+ addLog('core', 'composition', { modules, action });
49
+ console.log(`🔗 Composition ${action}:`, modules.join(' → '));
50
+ },
51
+ logMethodExecution: (module, method, args, result) => {
52
+ addLog(module, 'method', { method, args, result });
53
+ console.debug(`🔧 [${module}] ${method}`, { args, result });
54
+ },
55
+ logStateChange: (module, path, oldValue, newValue) => {
56
+ addLog(module, 'state', { path, oldValue, newValue });
57
+ console.debug(`📝 [${module}] State change at ${path}:`, {
58
+ from: oldValue,
59
+ to: newValue,
60
+ });
61
+ },
62
+ logPerformanceWarning: (module, operation, duration, threshold) => {
63
+ addLog(module, 'performance', { operation, duration, threshold });
64
+ console.warn(`⚠️ [${module}] Slow ${operation}: ${duration.toFixed(2)}ms (threshold: ${threshold}ms)`);
65
+ },
66
+ exportLogs: () => [...logs],
67
+ };
68
+ }
69
+ function createModularMetrics() {
70
+ const metricsSignal = signal({
71
+ totalUpdates: 0,
72
+ moduleUpdates: {},
73
+ modulePerformance: {},
74
+ compositionChain: [],
75
+ signalGrowth: {},
76
+ memoryDelta: {},
77
+ moduleCacheStats: {},
78
+ });
79
+ return {
80
+ signal: metricsSignal.asReadonly(),
81
+ updateMetrics: (updates) => {
82
+ metricsSignal.update((current) => ({ ...current, ...updates }));
83
+ },
84
+ trackModuleUpdate: (module, duration) => {
85
+ metricsSignal.update((current) => ({
86
+ ...current,
87
+ totalUpdates: current.totalUpdates + 1,
88
+ moduleUpdates: {
89
+ ...current.moduleUpdates,
90
+ [module]: (current.moduleUpdates[module] || 0) + 1,
91
+ },
92
+ modulePerformance: {
93
+ ...current.modulePerformance,
94
+ [module]: duration,
95
+ },
96
+ }));
97
+ },
98
+ };
99
+ }
100
+ export function withDevTools(config = {}) {
101
+ const { enabled = true, treeName = 'ModularSignalTree', enableBrowserDevTools = true, enableLogging = true, performanceThreshold = 16, } = config;
102
+ return (tree) => {
103
+ if (!enabled) {
104
+ const createNoopInterface = () => ({
105
+ activityTracker: {
106
+ trackMethodCall: () => undefined,
107
+ trackError: () => undefined,
108
+ getModuleActivity: () => undefined,
109
+ getAllModules: () => [],
110
+ },
111
+ logger: {
112
+ logComposition: () => undefined,
113
+ logMethodExecution: () => undefined,
114
+ logStateChange: () => undefined,
115
+ logPerformanceWarning: () => undefined,
116
+ exportLogs: () => [],
117
+ },
118
+ metrics: signal({
119
+ totalUpdates: 0,
120
+ moduleUpdates: {},
121
+ modulePerformance: {},
122
+ compositionChain: [],
123
+ signalGrowth: {},
124
+ memoryDelta: {},
125
+ moduleCacheStats: {},
126
+ }).asReadonly(),
127
+ trackComposition: () => undefined,
128
+ startModuleProfiling: () => '',
129
+ endModuleProfiling: () => undefined,
130
+ connectDevTools: () => undefined,
131
+ exportDebugSession: () => ({
132
+ metrics: {
133
+ totalUpdates: 0,
134
+ moduleUpdates: {},
135
+ modulePerformance: {},
136
+ compositionChain: [],
137
+ signalGrowth: {},
138
+ memoryDelta: {},
139
+ moduleCacheStats: {},
140
+ },
141
+ modules: [],
142
+ logs: [],
143
+ compositionHistory: [],
144
+ }),
145
+ });
146
+ return Object.assign(tree, { __devTools: createNoopInterface() });
147
+ }
148
+ const activityTracker = createActivityTracker();
149
+ const logger = enableLogging
150
+ ? createCompositionLogger()
151
+ : {
152
+ logComposition: () => undefined,
153
+ logMethodExecution: () => undefined,
154
+ logStateChange: () => undefined,
155
+ logPerformanceWarning: () => undefined,
156
+ exportLogs: () => [],
157
+ };
158
+ const metrics = createModularMetrics();
159
+ const compositionHistory = [];
160
+ const activeProfiles = new Map();
161
+ let browserDevTools = null;
162
+ if (enableBrowserDevTools &&
163
+ typeof window !== 'undefined' &&
164
+ '__REDUX_DEVTOOLS_EXTENSION__' in window) {
165
+ const devToolsExt = window['__REDUX_DEVTOOLS_EXTENSION__'];
166
+ const connection = devToolsExt.connect({
167
+ name: treeName,
168
+ features: { dispatch: true, jump: true, skip: true },
169
+ });
170
+ browserDevTools = { send: connection.send };
171
+ }
172
+ const originalTreeCall = tree.bind(tree);
173
+ const enhancedTree = function (...args) {
174
+ if (args.length === 0) {
175
+ return originalTreeCall();
176
+ }
177
+ else {
178
+ const startTime = performance.now();
179
+ let result;
180
+ if (args.length === 1) {
181
+ const arg = args[0];
182
+ if (typeof arg === 'function') {
183
+ result = originalTreeCall(arg);
184
+ }
185
+ else {
186
+ result = originalTreeCall(arg);
187
+ }
188
+ }
189
+ const duration = performance.now() - startTime;
190
+ const newState = originalTreeCall();
191
+ metrics.trackModuleUpdate('core', duration);
192
+ if (duration > performanceThreshold) {
193
+ logger.logPerformanceWarning('core', 'update', duration, performanceThreshold);
194
+ }
195
+ if (browserDevTools) {
196
+ browserDevTools.send('UPDATE', newState);
197
+ }
198
+ return result;
199
+ }
200
+ };
201
+ Object.setPrototypeOf(enhancedTree, Object.getPrototypeOf(tree));
202
+ Object.assign(enhancedTree, tree);
203
+ if ('state' in tree) {
204
+ Object.defineProperty(enhancedTree, 'state', {
205
+ value: tree.state,
206
+ enumerable: false,
207
+ configurable: true,
208
+ });
209
+ }
210
+ if ('$' in tree) {
211
+ Object.defineProperty(enhancedTree, '$', {
212
+ value: tree['$'],
213
+ enumerable: false,
214
+ configurable: true,
215
+ });
216
+ }
217
+ const devToolsInterface = {
218
+ activityTracker,
219
+ logger,
220
+ metrics: metrics.signal,
221
+ trackComposition: (modules) => {
222
+ compositionHistory.push({ timestamp: new Date(), chain: [...modules] });
223
+ metrics.updateMetrics({ compositionChain: modules });
224
+ logger.logComposition(modules, 'with');
225
+ },
226
+ startModuleProfiling: (module) => {
227
+ const profileId = `${module}_${Date.now()}`;
228
+ activeProfiles.set(profileId, {
229
+ module,
230
+ operation: 'profile',
231
+ startTime: performance.now(),
232
+ });
233
+ return profileId;
234
+ },
235
+ endModuleProfiling: (profileId) => {
236
+ const profile = activeProfiles.get(profileId);
237
+ if (profile) {
238
+ const duration = performance.now() - profile.startTime;
239
+ activityTracker.trackMethodCall(profile.module, profile.operation, duration);
240
+ activeProfiles.delete(profileId);
241
+ }
242
+ },
243
+ connectDevTools: (name) => {
244
+ if (browserDevTools) {
245
+ browserDevTools.send('@@INIT', originalTreeCall());
246
+ console.log(`🔗 Connected to Redux DevTools as "${name}"`);
247
+ }
248
+ },
249
+ exportDebugSession: () => ({
250
+ metrics: metrics.signal(),
251
+ modules: activityTracker.getAllModules(),
252
+ logs: logger.exportLogs(),
253
+ compositionHistory: [...compositionHistory],
254
+ }),
255
+ };
256
+ return Object.assign(enhancedTree, { __devTools: devToolsInterface });
257
+ };
258
+ }
259
+ export function enableDevTools(treeName = 'SignalTree') {
260
+ return withDevTools({ treeName, enabled: true });
261
+ }
262
+ export function withFullDevTools(treeName = 'SignalTree') {
263
+ return withDevTools({
264
+ treeName,
265
+ enabled: true,
266
+ enableBrowserDevTools: true,
267
+ enableLogging: true,
268
+ performanceThreshold: 10,
269
+ });
270
+ }
271
+ export function withProductionDevTools() {
272
+ return withDevTools({
273
+ enabled: true,
274
+ enableBrowserDevTools: false,
275
+ enableLogging: false,
276
+ performanceThreshold: 50,
277
+ });
278
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';
2
+ setupZoneTestEnv({
3
+ errorOnUnknownElements: true,
4
+ errorOnUnknownProperties: true,
5
+ });
@@ -0,0 +1 @@
1
+ export * from './lib/entities';
@@ -0,0 +1 @@
1
+ export * from './lib/entities';
@@ -0,0 +1,15 @@
1
+ declare const _default: {
2
+ displayName: string;
3
+ preset: string;
4
+ setupFilesAfterEnv: string[];
5
+ coverageDirectory: string;
6
+ transform: {
7
+ '^.+\\.(ts|mjs|js|html)$': (string | {
8
+ tsconfig: string;
9
+ stringifyContentPathRegex: string;
10
+ })[];
11
+ };
12
+ transformIgnorePatterns: string[];
13
+ snapshotSerializers: string[];
14
+ };
15
+ export default _default;
@@ -0,0 +1,21 @@
1
+ export default {
2
+ displayName: 'entities',
3
+ preset: '../../../jest.preset.js',
4
+ setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
5
+ coverageDirectory: '../../../coverage/packages/core/enhancers/entities',
6
+ transform: {
7
+ '^.+\\.(ts|mjs|js|html)$': [
8
+ 'jest-preset-angular',
9
+ {
10
+ tsconfig: '<rootDir>/tsconfig.spec.json',
11
+ stringifyContentPathRegex: '\\.(html|svg)$',
12
+ },
13
+ ],
14
+ },
15
+ transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
16
+ snapshotSerializers: [
17
+ 'jest-preset-angular/build/serializers/no-ng-attributes',
18
+ 'jest-preset-angular/build/serializers/ng-snapshot',
19
+ 'jest-preset-angular/build/serializers/html-comment',
20
+ ],
21
+ };
@@ -0,0 +1,22 @@
1
+ import type { SignalTree, EntityHelpers } from '../../../lib/types';
2
+ interface EntityConfig {
3
+ enabled?: boolean;
4
+ trackChanges?: boolean;
5
+ validateIds?: boolean;
6
+ }
7
+ export declare function withEntities(config?: EntityConfig): <T>(tree: SignalTree<T>) => SignalTree<T> & {
8
+ entities<E extends {
9
+ id: string | number;
10
+ }>(entityKey: keyof T): EntityHelpers<E>;
11
+ };
12
+ export declare function enableEntities(): <T>(tree: SignalTree<T>) => SignalTree<T> & {
13
+ entities<E extends {
14
+ id: string | number;
15
+ }>(entityKey: keyof T): EntityHelpers<E>;
16
+ };
17
+ export declare function withHighPerformanceEntities(): <T>(tree: SignalTree<T>) => SignalTree<T> & {
18
+ entities<E extends {
19
+ id: string | number;
20
+ }>(entityKey: keyof T): EntityHelpers<E>;
21
+ };
22
+ export {};
@@ -0,0 +1,110 @@
1
+ import { computed } from '@angular/core';
2
+ import { isAnySignal, isNodeAccessor } from '../../../lib/utils';
3
+ function createEntityHelpers(tree, entityKey) {
4
+ const getEntitySignal = () => {
5
+ const stateProperty = tree.state[entityKey];
6
+ if (!stateProperty) {
7
+ throw new Error(`Entity key '${String(entityKey)}' does not exist in the state`);
8
+ }
9
+ if (!isAnySignal(stateProperty)) {
10
+ throw new Error(`Entity key '${String(entityKey)}' is not a signal. This should not happen with SignalTree.`);
11
+ }
12
+ const signal = stateProperty;
13
+ const value = signal();
14
+ if (!Array.isArray(value)) {
15
+ throw new Error(`Entity key '${String(entityKey)}' does not contain an array. Current type: ${typeof value}`);
16
+ }
17
+ return signal;
18
+ };
19
+ const setSignalValue = (signal, value) => {
20
+ if (isNodeAccessor(signal)) {
21
+ signal(value);
22
+ }
23
+ else {
24
+ signal.set(value);
25
+ }
26
+ };
27
+ return {
28
+ add: (entity) => {
29
+ const entitySignal = getEntitySignal();
30
+ const currentEntities = entitySignal();
31
+ if (currentEntities.some((e) => e.id === entity.id)) {
32
+ throw new Error(`Entity with id '${entity.id}' already exists`);
33
+ }
34
+ setSignalValue(entitySignal, [...currentEntities, entity]);
35
+ },
36
+ update: (id, updates) => {
37
+ const entitySignal = getEntitySignal();
38
+ const currentEntities = entitySignal();
39
+ const updatedEntities = currentEntities.map((entity) => entity.id === id ? { ...entity, ...updates } : entity);
40
+ setSignalValue(entitySignal, updatedEntities);
41
+ },
42
+ remove: (id) => {
43
+ const entitySignal = getEntitySignal();
44
+ const currentEntities = entitySignal();
45
+ const filteredEntities = currentEntities.filter((entity) => entity.id !== id);
46
+ setSignalValue(entitySignal, filteredEntities);
47
+ },
48
+ upsert: (entity) => {
49
+ const entitySignal = getEntitySignal();
50
+ const currentEntities = entitySignal();
51
+ const index = currentEntities.findIndex((e) => e.id === entity.id);
52
+ if (index >= 0) {
53
+ const updatedEntities = [...currentEntities];
54
+ updatedEntities[index] = entity;
55
+ setSignalValue(entitySignal, updatedEntities);
56
+ }
57
+ else {
58
+ setSignalValue(entitySignal, [...currentEntities, entity]);
59
+ }
60
+ },
61
+ selectById: (id) => {
62
+ const entitySignal = getEntitySignal();
63
+ return computed(() => entitySignal().find((entity) => entity.id === id));
64
+ },
65
+ selectBy: (predicate) => {
66
+ const entitySignal = getEntitySignal();
67
+ return computed(() => entitySignal().filter(predicate));
68
+ },
69
+ selectIds: () => {
70
+ const entitySignal = getEntitySignal();
71
+ return computed(() => entitySignal().map((entity) => entity.id));
72
+ },
73
+ selectAll: () => {
74
+ const entitySignal = getEntitySignal();
75
+ return entitySignal;
76
+ },
77
+ selectTotal: () => {
78
+ const entitySignal = getEntitySignal();
79
+ return computed(() => entitySignal().length);
80
+ },
81
+ clear: () => {
82
+ const entitySignal = getEntitySignal();
83
+ setSignalValue(entitySignal, []);
84
+ },
85
+ };
86
+ }
87
+ export function withEntities(config = {}) {
88
+ const { enabled = true } = config;
89
+ return function enhanceWithEntities(tree) {
90
+ if (!enabled) {
91
+ return tree;
92
+ }
93
+ const enhancedTree = Object.assign(tree, {
94
+ entities(entityKey) {
95
+ return createEntityHelpers(tree, entityKey);
96
+ },
97
+ });
98
+ return enhancedTree;
99
+ };
100
+ }
101
+ export function enableEntities() {
102
+ return withEntities({ enabled: true });
103
+ }
104
+ export function withHighPerformanceEntities() {
105
+ return withEntities({
106
+ enabled: true,
107
+ trackChanges: true,
108
+ validateIds: true,
109
+ });
110
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';
2
+ setupZoneTestEnv({
3
+ errorOnUnknownElements: true,
4
+ errorOnUnknownProperties: true,
5
+ });
@@ -0,0 +1,3 @@
1
+ import type { EnhancerMeta, EnhancerWithMeta } from '../lib/types';
2
+ export declare function createEnhancer<I = unknown, O = unknown>(meta: EnhancerMeta, enhancerFn: (input: I) => O): EnhancerWithMeta<I, O>;
3
+ export declare function resolveEnhancerOrder(enhancers: EnhancerWithMeta<unknown, unknown>[], availableCapabilities?: Set<string>, debugMode?: boolean): EnhancerWithMeta<unknown, unknown>[];
@@ -0,0 +1,84 @@
1
+ import { SIGNAL_TREE_MESSAGES } from '../lib/constants';
2
+ import { ENHANCER_META } from '../lib/types';
3
+ export function createEnhancer(meta, enhancerFn) {
4
+ const fn = enhancerFn;
5
+ try {
6
+ fn.metadata = meta;
7
+ try {
8
+ fn[ENHANCER_META] = meta;
9
+ }
10
+ catch {
11
+ }
12
+ }
13
+ catch {
14
+ }
15
+ return fn;
16
+ }
17
+ export function resolveEnhancerOrder(enhancers, availableCapabilities = new Set(), debugMode = false) {
18
+ const nodes = enhancers.map((e, idx) => ({
19
+ fn: e,
20
+ name: e.metadata && e.metadata.name
21
+ ? String(e.metadata.name)
22
+ : `enhancer#${idx}`,
23
+ requires: new Set(e.metadata?.requires ?? []),
24
+ provides: new Set(e.metadata?.provides ?? []),
25
+ }));
26
+ const adj = new Map();
27
+ const nameToNode = new Map();
28
+ for (const n of nodes) {
29
+ nameToNode.set(n.name, n);
30
+ adj.set(n.name, new Set());
31
+ }
32
+ for (const a of nodes) {
33
+ for (const b of nodes) {
34
+ if (a === b)
35
+ continue;
36
+ for (const req of b.requires) {
37
+ if (availableCapabilities.has(req))
38
+ continue;
39
+ if (a.provides.has(req)) {
40
+ const set = adj.get(a.name);
41
+ if (set)
42
+ set.add(b.name);
43
+ }
44
+ }
45
+ }
46
+ }
47
+ const inDegree = new Map();
48
+ for (const entry of adj.keys())
49
+ inDegree.set(entry, 0);
50
+ for (const [, outs] of adj) {
51
+ for (const to of outs)
52
+ inDegree.set(to, (inDegree.get(to) || 0) + 1);
53
+ }
54
+ const queue = [];
55
+ for (const [name, deg] of inDegree.entries()) {
56
+ if (deg === 0)
57
+ queue.push(name);
58
+ }
59
+ const ordered = [];
60
+ while (queue.length > 0) {
61
+ const n = queue.shift();
62
+ if (!n)
63
+ break;
64
+ ordered.push(n);
65
+ const outs = adj.get(n);
66
+ if (!outs)
67
+ continue;
68
+ for (const m of outs) {
69
+ inDegree.set(m, (inDegree.get(m) || 0) - 1);
70
+ if (inDegree.get(m) === 0)
71
+ queue.push(m);
72
+ }
73
+ }
74
+ if (ordered.length !== nodes.length) {
75
+ if (debugMode) {
76
+ console.warn(SIGNAL_TREE_MESSAGES.ENHANCER_CYCLE_DETECTED);
77
+ }
78
+ return enhancers;
79
+ }
80
+ return ordered.map((name) => {
81
+ const n = nameToNode.get(name);
82
+ return (n ? n.fn : enhancers[0]);
83
+ });
84
+ }
@@ -0,0 +1 @@
1
+ export * from './lib/memoization';
@@ -0,0 +1 @@
1
+ export * from './lib/memoization';
@@ -0,0 +1,15 @@
1
+ declare const _default: {
2
+ displayName: string;
3
+ preset: string;
4
+ setupFilesAfterEnv: string[];
5
+ coverageDirectory: string;
6
+ transform: {
7
+ '^.+\\.(ts|mjs|js|html)$': (string | {
8
+ tsconfig: string;
9
+ stringifyContentPathRegex: string;
10
+ })[];
11
+ };
12
+ transformIgnorePatterns: string[];
13
+ snapshotSerializers: string[];
14
+ };
15
+ export default _default;
@@ -0,0 +1,21 @@
1
+ export default {
2
+ displayName: 'memoization',
3
+ preset: '../../../jest.preset.js',
4
+ setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
5
+ coverageDirectory: '../../../coverage/packages/core/enhancers/memoization',
6
+ transform: {
7
+ '^.+\\.(ts|mjs|js|html)$': [
8
+ 'jest-preset-angular',
9
+ {
10
+ tsconfig: '<rootDir>/tsconfig.spec.json',
11
+ stringifyContentPathRegex: '\\.(html|svg)$',
12
+ },
13
+ ],
14
+ },
15
+ transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
16
+ snapshotSerializers: [
17
+ 'jest-preset-angular/build/serializers/no-ng-attributes',
18
+ 'jest-preset-angular/build/serializers/ng-snapshot',
19
+ 'jest-preset-angular/build/serializers/html-comment',
20
+ ],
21
+ };
@@ -0,0 +1,65 @@
1
+ import type { SignalTree } from '../../../lib/types';
2
+ export interface MemoizedSignalTree<T> extends SignalTree<T> {
3
+ memoizedUpdate: (updater: (current: T) => Partial<T>, cacheKey?: string) => void;
4
+ clearMemoCache: (key?: string) => void;
5
+ getCacheStats: () => {
6
+ size: number;
7
+ hitRate: number;
8
+ totalHits: number;
9
+ totalMisses: number;
10
+ keys: string[];
11
+ };
12
+ }
13
+ export declare function cleanupMemoizationCache(): void;
14
+ export interface MemoizationConfig {
15
+ enabled?: boolean;
16
+ maxCacheSize?: number;
17
+ ttl?: number;
18
+ equality?: 'deep' | 'shallow' | 'reference';
19
+ enableLRU?: boolean;
20
+ }
21
+ export declare function memoize<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn, keyFn?: (...args: TArgs) => string, config?: MemoizationConfig): (...args: TArgs) => TReturn;
22
+ export declare function memoizeShallow<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn, keyFn?: (...args: TArgs) => string): (...args: TArgs) => TReturn;
23
+ export declare function memoizeReference<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn, keyFn?: (...args: TArgs) => string): (...args: TArgs) => TReturn;
24
+ export declare const MEMOIZATION_PRESETS: {
25
+ readonly selector: {
26
+ readonly equality: "reference";
27
+ readonly maxCacheSize: 10;
28
+ readonly enableLRU: false;
29
+ readonly ttl: undefined;
30
+ };
31
+ readonly computed: {
32
+ readonly equality: "shallow";
33
+ readonly maxCacheSize: 100;
34
+ readonly enableLRU: false;
35
+ readonly ttl: undefined;
36
+ };
37
+ readonly deepState: {
38
+ readonly equality: "deep";
39
+ readonly maxCacheSize: 1000;
40
+ readonly enableLRU: true;
41
+ readonly ttl: number;
42
+ };
43
+ readonly highFrequency: {
44
+ readonly equality: "reference";
45
+ readonly maxCacheSize: 5;
46
+ readonly enableLRU: false;
47
+ readonly ttl: undefined;
48
+ };
49
+ };
50
+ export declare function withSelectorMemoization<T>(): (tree: SignalTree<T>) => MemoizedSignalTree<T>;
51
+ export declare function withComputedMemoization<T>(): (tree: SignalTree<T>) => MemoizedSignalTree<T>;
52
+ export declare function withDeepStateMemoization<T>(): (tree: SignalTree<T>) => MemoizedSignalTree<T>;
53
+ export declare function withHighFrequencyMemoization<T>(): (tree: SignalTree<T>) => MemoizedSignalTree<T>;
54
+ export declare function withMemoization<T>(config?: MemoizationConfig): (tree: SignalTree<T>) => MemoizedSignalTree<T>;
55
+ export declare function enableMemoization<T>(): (tree: SignalTree<T>) => MemoizedSignalTree<T>;
56
+ export declare function withHighPerformanceMemoization<T>(): (tree: SignalTree<T>) => MemoizedSignalTree<T>;
57
+ export declare function withLightweightMemoization<T>(): (tree: SignalTree<T>) => MemoizedSignalTree<T>;
58
+ export declare function withShallowMemoization<T>(): (tree: SignalTree<T>) => MemoizedSignalTree<T>;
59
+ export declare function clearAllCaches(): void;
60
+ export declare function getGlobalCacheStats(): {
61
+ treeCount: number;
62
+ totalSize: number;
63
+ totalHits: number;
64
+ averageCacheSize: number;
65
+ };