@useavalon/avalon 0.1.5 → 0.1.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 (39) hide show
  1. package/package.json +31 -58
  2. package/src/build/prop-extractors/index.ts +11 -11
  3. package/src/build/prop-extractors/lit.ts +1 -1
  4. package/src/build/prop-extractors/qwik.ts +2 -2
  5. package/src/build/prop-extractors/solid.ts +1 -1
  6. package/src/build/prop-extractors/svelte.ts +1 -1
  7. package/src/schemas/routing.ts +2 -2
  8. package/src/vite-plugin/nitro-integration.ts +1 -1
  9. package/src/vite-plugin/plugin.ts +20 -16
  10. package/src/build/README.md +0 -310
  11. package/src/client/tests/css-hmr-handler.test.ts +0 -360
  12. package/src/client/tests/framework-adapter.test.ts +0 -519
  13. package/src/client/tests/hmr-coordinator.test.ts +0 -176
  14. package/src/client/tests/hydration-option-parsing.test.ts +0 -107
  15. package/src/client/tests/lit-adapter.test.ts +0 -427
  16. package/src/client/tests/preact-adapter.test.ts +0 -353
  17. package/src/client/tests/qwik-adapter.test.ts +0 -343
  18. package/src/client/tests/react-adapter.test.ts +0 -317
  19. package/src/client/tests/solid-adapter.test.ts +0 -396
  20. package/src/client/tests/svelte-adapter.test.ts +0 -387
  21. package/src/client/tests/vue-adapter.test.ts +0 -407
  22. package/src/components/tests/component-analyzer.test.ts +0 -96
  23. package/src/components/tests/component-detection.test.ts +0 -347
  24. package/src/components/tests/persistent-islands.test.ts +0 -398
  25. package/src/core/components/tests/enhanced-framework-detector.test.ts +0 -577
  26. package/src/core/components/tests/framework-registry.test.ts +0 -465
  27. package/src/core/integrations/README.md +0 -282
  28. package/src/core/layout/tests/enhanced-layout-resolver.test.ts +0 -477
  29. package/src/core/layout/tests/layout-cache-optimization.test.ts +0 -149
  30. package/src/core/layout/tests/layout-composer.test.ts +0 -486
  31. package/src/core/layout/tests/layout-data-loader.test.ts +0 -443
  32. package/src/core/layout/tests/layout-discovery.test.ts +0 -253
  33. package/src/core/layout/tests/layout-matcher.test.ts +0 -480
  34. package/src/core/modules/tests/framework-module-resolver.test.ts +0 -263
  35. package/src/core/modules/tests/module-resolution-integration.test.ts +0 -117
  36. package/src/islands/discovery/tests/island-discovery.test.ts +0 -881
  37. package/src/middleware/__tests__/discovery.test.ts +0 -107
  38. package/src/types/tests/layout-types.test.ts +0 -197
  39. package/src/vite-plugin/tests/image-optimization.test.ts +0 -54
@@ -1,398 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest';
2
- import { IslandPersistence } from '../../core/islands/island-persistence.ts';
3
- import { IslandStateSerializer } from '../../core/islands/island-state-serializer.ts';
4
- import { createPersistentIslandContext } from '../../core/islands/persistent-island-context.tsx';
5
- import type { IslandState } from '../../schemas/layout.ts';
6
-
7
- // Mock Storage for testing
8
- class MockStorage implements Storage {
9
- private data: Map<string, string> = new Map();
10
-
11
- get length(): number {
12
- return this.data.size;
13
- }
14
-
15
- clear(): void {
16
- this.data.clear();
17
- }
18
-
19
- getItem(key: string): string | null {
20
- return this.data.get(key) || null;
21
- }
22
-
23
- key(index: number): string | null {
24
- const keys = Array.from(this.data.keys());
25
- return keys[index] || null;
26
- }
27
-
28
- removeItem(key: string): void {
29
- this.data.delete(key);
30
- }
31
-
32
- setItem(key: string, value: string): void {
33
- this.data.set(key, value);
34
- }
35
- }
36
-
37
- // Mock global window and storage for testing
38
- const mockStorage = new MockStorage();
39
- (globalThis as any).window = {
40
- sessionStorage: mockStorage,
41
- localStorage: mockStorage,
42
- };
43
- (globalThis as any).sessionStorage = mockStorage;
44
- (globalThis as any).localStorage = mockStorage;
45
-
46
- describe('IslandPersistence - Basic Operations', () => {
47
- beforeEach(() => { mockStorage.clear(); });
48
-
49
- it('should save and load state', () => {
50
- const persistence = new IslandPersistence();
51
- const testState: IslandState = { count: 42, name: 'test' };
52
-
53
- persistence.saveState('test-island', testState);
54
- const loadedState = persistence.loadState('test-island');
55
-
56
- expect(loadedState).toEqual(testState);
57
- });
58
-
59
- it('should return null for non-existent state', () => {
60
- const persistence = new IslandPersistence();
61
- const loadedState = persistence.loadState('non-existent');
62
-
63
- expect(loadedState).toEqual(null);
64
- });
65
-
66
- it('should clear state', () => {
67
- const persistence = new IslandPersistence();
68
- const testState: IslandState = { count: 42 };
69
-
70
- persistence.saveState('test-island', testState);
71
- expect(persistence.hasState('test-island')).toEqual(true);
72
-
73
- persistence.clearState('test-island');
74
- expect(persistence.hasState('test-island')).toEqual(false);
75
- expect(persistence.loadState('test-island')).toEqual(null);
76
- });
77
-
78
- it('should check if state exists', () => {
79
- const persistence = new IslandPersistence();
80
- const testState: IslandState = { count: 42 };
81
-
82
- expect(persistence.hasState('test-island')).toEqual(false);
83
-
84
- persistence.saveState('test-island', testState);
85
- expect(persistence.hasState('test-island')).toEqual(true);
86
-
87
- persistence.clearState('test-island');
88
- });
89
-
90
- it('should get stored IDs', () => {
91
- const persistence = new IslandPersistence();
92
-
93
- persistence.saveState('island-1', { count: 1 });
94
- persistence.saveState('island-2', { count: 2 });
95
-
96
- const storedIds = persistence.getStoredIds();
97
- expect(storedIds.sort()).toEqual(['island-1', 'island-2']);
98
- });
99
-
100
- it('should clear all states', () => {
101
- const persistence = new IslandPersistence();
102
-
103
- persistence.saveState('island-1', { count: 1 });
104
- persistence.saveState('island-2', { count: 2 });
105
-
106
- expect(persistence.getStoredIds().length).toEqual(2);
107
-
108
- persistence.clearAllStates();
109
- expect(persistence.getStoredIds().length).toEqual(0);
110
- });
111
- });
112
-
113
- describe('IslandPersistence - Configuration', () => {
114
- beforeEach(() => { mockStorage.clear(); });
115
-
116
- it('should use custom key prefix', () => {
117
- const persistence = new IslandPersistence({ keyPrefix: 'custom-prefix' });
118
- const testState: IslandState = { count: 42 };
119
-
120
- persistence.saveState('test-island', testState);
121
-
122
- const config = persistence.getConfig();
123
- expect(config.keyPrefix).toEqual('custom-prefix');
124
-
125
- const loadedState = persistence.loadState('test-island');
126
- expect(loadedState).toEqual(testState);
127
-
128
- persistence.clearState('test-island');
129
- });
130
-
131
- it('should provide storage stats', () => {
132
- const persistence = new IslandPersistence();
133
-
134
- persistence.saveState('island-1', { count: 1 });
135
- persistence.saveState('island-2', { count: 2, name: 'test' });
136
-
137
- const stats = persistence.getStorageStats();
138
- expect(stats.islandKeys).toEqual(2);
139
- expect(stats.estimatedSize > 0).toEqual(true);
140
- });
141
- });
142
-
143
- describe('IslandStateSerializer - Basic Serialization', () => {
144
- it('should serialize and deserialize basic types', () => {
145
- const state: IslandState = {
146
- string: 'hello',
147
- number: 42,
148
- boolean: true,
149
- null: null,
150
- array: [1, 2, 3],
151
- object: { nested: 'value' },
152
- };
153
-
154
- const serialized = IslandStateSerializer.serialize(state);
155
- const deserialized = IslandStateSerializer.deserialize(serialized);
156
-
157
- expect(deserialized).toEqual(state);
158
- });
159
-
160
- it('should handle Date objects', () => {
161
- const date = new Date('2023-01-01T00:00:00.000Z');
162
- const state: IslandState = { timestamp: date };
163
-
164
- const serialized = IslandStateSerializer.serialize(state);
165
- const deserialized = IslandStateSerializer.deserialize(serialized);
166
-
167
- expect(deserialized.timestamp instanceof Date).toEqual(true);
168
- expect((deserialized.timestamp as Date).getTime()).toEqual(date.getTime());
169
- });
170
-
171
- it('should handle RegExp objects', () => {
172
- const regex = /test/gi;
173
- const state: IslandState = { pattern: regex };
174
-
175
- const serialized = IslandStateSerializer.serialize(state);
176
- const deserialized = IslandStateSerializer.deserialize(serialized);
177
-
178
- expect(deserialized.pattern instanceof RegExp).toEqual(true);
179
- expect((deserialized.pattern as RegExp).source).toEqual(regex.source);
180
- expect((deserialized.pattern as RegExp).flags).toEqual(regex.flags);
181
- });
182
-
183
- it('should handle Map objects', () => {
184
- const map = new Map([
185
- ['key1', 'value1'],
186
- ['key2', 'value2'],
187
- ]);
188
- const state: IslandState = { map };
189
-
190
- const serialized = IslandStateSerializer.serialize(state);
191
- const deserialized = IslandStateSerializer.deserialize(serialized);
192
-
193
- expect(deserialized.map instanceof Map).toEqual(true);
194
- expect((deserialized.map as Map<string, string>).get('key1')).toEqual('value1');
195
- expect((deserialized.map as Map<string, string>).get('key2')).toEqual('value2');
196
- });
197
-
198
- it('should handle Set objects', () => {
199
- const set = new Set(['value1', 'value2']);
200
- const state: IslandState = { set };
201
-
202
- const serialized = IslandStateSerializer.serialize(state);
203
- const deserialized = IslandStateSerializer.deserialize(serialized);
204
-
205
- expect(deserialized.set instanceof Set).toEqual(true);
206
- expect((deserialized.set as Set<string>).has('value1')).toEqual(true);
207
- expect((deserialized.set as Set<string>).has('value2')).toEqual(true);
208
- });
209
-
210
- it('should convert functions to null', () => {
211
- const state: IslandState = {
212
- func: () => 'test',
213
- value: 42,
214
- };
215
-
216
- const serialized = IslandStateSerializer.serialize(state);
217
- const deserialized = IslandStateSerializer.deserialize(serialized);
218
-
219
- expect(deserialized.func).toEqual(null);
220
- expect(deserialized.value).toEqual(42);
221
- });
222
-
223
- it('should convert undefined to null', () => {
224
- const state: IslandState = {
225
- undef: undefined,
226
- value: 42,
227
- };
228
-
229
- const serialized = IslandStateSerializer.serialize(state);
230
- const deserialized = IslandStateSerializer.deserialize(serialized);
231
-
232
- expect(deserialized.undef).toEqual(null);
233
- expect(deserialized.value).toEqual(42);
234
- });
235
- });
236
-
237
- describe('IslandStateSerializer - Validation and Utilities', () => {
238
- it('should validate serializable state', () => {
239
- const validState: IslandState = { count: 42, name: 'test' };
240
- const validation = IslandStateSerializer.validate(validState);
241
-
242
- expect(validation.valid).toEqual(true);
243
- expect(validation.errors.length).toEqual(0);
244
- });
245
-
246
- it('should calculate state size', () => {
247
- const state: IslandState = { count: 42, name: 'test' };
248
- const size = IslandStateSerializer.getSize(state);
249
-
250
- expect(size.bytes > 0).toEqual(true);
251
- expect(size.kilobytes > 0).toEqual(true);
252
- expect(typeof size.readable).toEqual('string');
253
- });
254
-
255
- it('should clone state', () => {
256
- const original: IslandState = {
257
- count: 42,
258
- nested: { value: 'test' },
259
- date: new Date('2023-01-01'),
260
- };
261
-
262
- const cloned = IslandStateSerializer.clone(original);
263
-
264
- expect(IslandStateSerializer.equals(original, cloned)).toEqual(true);
265
- expect(original === cloned).toEqual(false);
266
- expect(original.nested === cloned.nested).toEqual(false);
267
- });
268
-
269
- it('should compare states for equality', () => {
270
- const state1: IslandState = { count: 42, name: 'test' };
271
- const state2: IslandState = { count: 42, name: 'test' };
272
- const state3: IslandState = { count: 43, name: 'test' };
273
-
274
- expect(IslandStateSerializer.equals(state1, state2)).toEqual(true);
275
- expect(IslandStateSerializer.equals(state1, state3)).toEqual(false);
276
- });
277
-
278
- it('should sanitize state', () => {
279
- const state: IslandState = {
280
- count: 42,
281
- func: () => 'test',
282
- undef: undefined,
283
- date: new Date('2023-01-01'),
284
- };
285
-
286
- const sanitized = IslandStateSerializer.sanitize(state);
287
-
288
- expect(sanitized.count).toEqual(42);
289
- expect(sanitized.func).toEqual(null);
290
- expect(sanitized.undef).toEqual(null);
291
- expect(sanitized.date instanceof Date).toEqual(true);
292
- });
293
- });
294
-
295
- describe('PersistentIslandContext - Context Creation', () => {
296
- beforeEach(() => { mockStorage.clear(); });
297
-
298
- it('should create context with save/load/clear functions', () => {
299
- const context = createPersistentIslandContext('test-island');
300
-
301
- expect(context.saveState).toBeDefined();
302
- expect(context.loadState).toBeDefined();
303
- expect(context.clearState).toBeDefined();
304
-
305
- expect(typeof context.saveState).toEqual('function');
306
- expect(typeof context.loadState).toEqual('function');
307
- expect(typeof context.clearState).toEqual('function');
308
- });
309
-
310
- it('should save and load state through context', () => {
311
- const persistence = new IslandPersistence();
312
- const context = createPersistentIslandContext('test-island', persistence);
313
- const testState: IslandState = { count: 42 };
314
-
315
- context.saveState(testState);
316
- const loadedState = context.loadState();
317
-
318
- expect(loadedState).toEqual(testState);
319
- });
320
-
321
- it('should clear state through context', () => {
322
- const persistence = new IslandPersistence();
323
- const context = createPersistentIslandContext('test-island', persistence);
324
- const testState: IslandState = { count: 42 };
325
-
326
- context.saveState(testState);
327
- expect(context.loadState()).toEqual(testState);
328
-
329
- context.clearState();
330
- expect(context.loadState()).toEqual(null);
331
- });
332
- });
333
-
334
- describe('Integration - Complete Persistent Islands Flow', () => {
335
- beforeEach(() => { mockStorage.clear(); });
336
-
337
- it('should handle complete save/load/clear cycle', () => {
338
- const persistence = new IslandPersistence();
339
- const context = createPersistentIslandContext('integration-test', persistence);
340
-
341
- const complexState: IslandState = {
342
- counter: 42,
343
- user: {
344
- name: 'John Doe',
345
- preferences: {
346
- theme: 'dark',
347
- notifications: true,
348
- },
349
- },
350
- timestamps: [new Date('2023-01-01'), new Date('2023-01-02')],
351
- patterns: [/test/gi, /another/i],
352
- cache: new Map([
353
- ['key1', { value: 'cached1', expires: new Date('2023-12-31') }],
354
- ['key2', { value: 'cached2', expires: new Date('2023-12-31') }],
355
- ]),
356
- tags: new Set(['tag1', 'tag2', 'tag3']),
357
- };
358
-
359
- context.saveState(complexState);
360
-
361
- expect(persistence.hasState('integration-test')).toEqual(true);
362
-
363
- const loadedState = context.loadState();
364
- expect(loadedState).toBeDefined();
365
-
366
- expect(loadedState!.counter).toEqual(42);
367
- expect(loadedState!.user.name).toEqual('John Doe');
368
- expect(loadedState!.timestamps[0] instanceof Date).toEqual(true);
369
- expect(loadedState!.patterns[0] instanceof RegExp).toEqual(true);
370
- expect(loadedState!.cache instanceof Map).toEqual(true);
371
- expect(loadedState!.tags instanceof Set).toEqual(true);
372
-
373
- const loadedMap = loadedState!.cache as Map<string, any>;
374
- expect(loadedMap.get('key1').value).toEqual('cached1');
375
- expect(loadedMap.get('key1').expires instanceof Date).toEqual(true);
376
-
377
- const loadedSet = loadedState!.tags as Set<string>;
378
- expect(loadedSet.has('tag1')).toEqual(true);
379
- expect(loadedSet.has('tag2')).toEqual(true);
380
- expect(loadedSet.has('tag3')).toEqual(true);
381
-
382
- context.clearState();
383
- expect(context.loadState()).toEqual(null);
384
- expect(persistence.hasState('integration-test')).toEqual(false);
385
- });
386
-
387
- it('should handle serialization errors gracefully', () => {
388
- const persistence = new IslandPersistence();
389
-
390
- const circularState: any = { count: 42 };
391
- circularState.self = circularState;
392
-
393
- persistence.saveState('circular-test', circularState);
394
-
395
- const loadedState = persistence.loadState('circular-test');
396
- expect(loadedState).toEqual(null);
397
- });
398
- });