@blac/core 2.0.0-rc-14 → 2.0.0-rc.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 (162) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/Blac.d.ts +246 -0
  3. package/dist/Blac.d.ts.map +1 -0
  4. package/dist/Blac.js +625 -0
  5. package/dist/Blac.js.map +1 -0
  6. package/dist/Bloc.d.ts +41 -0
  7. package/dist/Bloc.d.ts.map +1 -0
  8. package/dist/Bloc.js +140 -0
  9. package/dist/Bloc.js.map +1 -0
  10. package/dist/BlocBase.d.ts +110 -0
  11. package/dist/BlocBase.d.ts.map +1 -0
  12. package/dist/BlocBase.js +287 -0
  13. package/dist/BlocBase.js.map +1 -0
  14. package/dist/Cubit.d.ts +25 -0
  15. package/dist/Cubit.d.ts.map +1 -0
  16. package/dist/Cubit.js +64 -0
  17. package/dist/Cubit.js.map +1 -0
  18. package/dist/adapter/BlacAdapter.d.ts +71 -0
  19. package/dist/adapter/BlacAdapter.d.ts.map +1 -0
  20. package/dist/adapter/BlacAdapter.js +373 -0
  21. package/dist/adapter/BlacAdapter.js.map +1 -0
  22. package/dist/adapter/ProxyFactory.d.ts +50 -0
  23. package/dist/adapter/ProxyFactory.d.ts.map +1 -0
  24. package/dist/adapter/ProxyFactory.js +150 -0
  25. package/dist/adapter/ProxyFactory.js.map +1 -0
  26. package/{src/adapter/index.ts → dist/adapter/index.d.ts} +1 -0
  27. package/dist/adapter/index.d.ts.map +1 -0
  28. package/dist/adapter/index.js +19 -0
  29. package/dist/adapter/index.js.map +1 -0
  30. package/dist/errors/BlacError.d.ts +38 -0
  31. package/dist/errors/BlacError.d.ts.map +1 -0
  32. package/dist/errors/BlacError.js +55 -0
  33. package/dist/errors/BlacError.js.map +1 -0
  34. package/dist/errors/ErrorManager.d.ts +39 -0
  35. package/dist/errors/ErrorManager.d.ts.map +1 -0
  36. package/dist/errors/ErrorManager.js +91 -0
  37. package/dist/errors/ErrorManager.js.map +1 -0
  38. package/dist/errors/handleError.d.ts +24 -0
  39. package/dist/errors/handleError.d.ts.map +1 -0
  40. package/dist/errors/handleError.js +62 -0
  41. package/dist/errors/handleError.js.map +1 -0
  42. package/dist/errors/index.d.ts +5 -0
  43. package/dist/errors/index.d.ts.map +1 -0
  44. package/dist/errors/index.js +13 -0
  45. package/dist/errors/index.js.map +1 -0
  46. package/{src/events.ts → dist/events.d.ts} +4 -2
  47. package/dist/events.d.ts.map +1 -0
  48. package/dist/events.js +17 -0
  49. package/dist/events.js.map +1 -0
  50. package/dist/index.cjs +38 -0
  51. package/dist/index.d.ts +17 -1303
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +38 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/lifecycle/BlocLifecycle.d.ts +51 -0
  56. package/dist/lifecycle/BlocLifecycle.d.ts.map +1 -0
  57. package/dist/lifecycle/BlocLifecycle.js +123 -0
  58. package/dist/lifecycle/BlocLifecycle.js.map +1 -0
  59. package/dist/lifecycle/index.d.ts +2 -0
  60. package/dist/lifecycle/index.d.ts.map +1 -0
  61. package/dist/lifecycle/index.js +18 -0
  62. package/dist/lifecycle/index.js.map +1 -0
  63. package/dist/plugins/BlocPluginRegistry.d.ts +58 -0
  64. package/dist/plugins/BlocPluginRegistry.d.ts.map +1 -0
  65. package/dist/plugins/BlocPluginRegistry.js +201 -0
  66. package/dist/plugins/BlocPluginRegistry.js.map +1 -0
  67. package/dist/plugins/SystemPluginRegistry.d.ts +79 -0
  68. package/dist/plugins/SystemPluginRegistry.d.ts.map +1 -0
  69. package/dist/plugins/SystemPluginRegistry.js +184 -0
  70. package/dist/plugins/SystemPluginRegistry.js.map +1 -0
  71. package/{src/plugins/index.ts → dist/plugins/index.d.ts} +1 -5
  72. package/dist/plugins/index.d.ts.map +1 -0
  73. package/dist/plugins/index.js +26 -0
  74. package/dist/plugins/index.js.map +1 -0
  75. package/dist/plugins/types.d.ts +103 -0
  76. package/dist/plugins/types.d.ts.map +1 -0
  77. package/dist/plugins/types.js +3 -0
  78. package/dist/plugins/types.js.map +1 -0
  79. package/dist/subscription/SubscriptionManager.d.ts +67 -0
  80. package/dist/subscription/SubscriptionManager.d.ts.map +1 -0
  81. package/dist/subscription/SubscriptionManager.js +317 -0
  82. package/dist/subscription/SubscriptionManager.js.map +1 -0
  83. package/{src/subscription/index.ts → dist/subscription/index.d.ts} +1 -0
  84. package/dist/subscription/index.d.ts.map +1 -0
  85. package/dist/subscription/index.js +19 -0
  86. package/dist/subscription/index.js.map +1 -0
  87. package/dist/subscription/types.d.ts +65 -0
  88. package/dist/subscription/types.d.ts.map +1 -0
  89. package/dist/subscription/types.js +3 -0
  90. package/dist/subscription/types.js.map +1 -0
  91. package/dist/testing.d.ts +85 -0
  92. package/dist/testing.d.ts.map +1 -0
  93. package/dist/testing.js +186 -0
  94. package/dist/testing.js.map +1 -0
  95. package/{src/types.ts → dist/types.d.ts} +11 -28
  96. package/dist/types.d.ts.map +1 -0
  97. package/dist/types.js +3 -0
  98. package/dist/types.js.map +1 -0
  99. package/dist/utils/BatchingManager.d.ts +28 -0
  100. package/dist/utils/BatchingManager.d.ts.map +1 -0
  101. package/dist/utils/BatchingManager.js +48 -0
  102. package/dist/utils/BatchingManager.js.map +1 -0
  103. package/dist/utils/RerenderLogger.d.ts +60 -0
  104. package/dist/utils/RerenderLogger.d.ts.map +1 -0
  105. package/dist/utils/RerenderLogger.js +205 -0
  106. package/dist/utils/RerenderLogger.js.map +1 -0
  107. package/dist/utils/generateInstanceId.d.ts +11 -0
  108. package/dist/utils/generateInstanceId.d.ts.map +1 -0
  109. package/dist/utils/generateInstanceId.js +50 -0
  110. package/dist/utils/generateInstanceId.js.map +1 -0
  111. package/dist/utils/shallowEqual.d.ts +9 -0
  112. package/dist/utils/shallowEqual.d.ts.map +1 -0
  113. package/dist/utils/shallowEqual.js +35 -0
  114. package/dist/utils/shallowEqual.js.map +1 -0
  115. package/dist/utils/uuid.d.ts +10 -0
  116. package/dist/utils/uuid.d.ts.map +1 -0
  117. package/dist/utils/uuid.js +24 -0
  118. package/dist/utils/uuid.js.map +1 -0
  119. package/package.json +17 -10
  120. package/dist/index.cjs.js +0 -11
  121. package/dist/index.cjs.js.map +0 -1
  122. package/dist/index.es.js +0 -2275
  123. package/dist/index.es.js.map +0 -1
  124. package/src/Blac.ts +0 -802
  125. package/src/Bloc.ts +0 -180
  126. package/src/BlocBase.ts +0 -398
  127. package/src/Cubit.ts +0 -68
  128. package/src/__tests__/Blac.config.test.ts +0 -79
  129. package/src/__tests__/Bloc.event.test.ts +0 -394
  130. package/src/__tests__/BlocBase.subscription.test.ts +0 -349
  131. package/src/__tests__/Cubit.test.ts +0 -462
  132. package/src/__tests__/memory-leaks.test.ts +0 -383
  133. package/src/__tests__/plugins.test.ts +0 -464
  134. package/src/adapter/BlacAdapter.ts +0 -467
  135. package/src/adapter/ProxyFactory.ts +0 -249
  136. package/src/adapter/__tests__/BlacAdapter.test.ts +0 -555
  137. package/src/adapter/__tests__/ProxyFactory.test.ts +0 -655
  138. package/src/errors/BlacError.ts +0 -69
  139. package/src/errors/ErrorManager.ts +0 -101
  140. package/src/errors/handleError.ts +0 -114
  141. package/src/errors/index.ts +0 -13
  142. package/src/index.ts +0 -26
  143. package/src/lifecycle/BlocLifecycle.ts +0 -156
  144. package/src/lifecycle/index.ts +0 -1
  145. package/src/plugins/BlocPluginRegistry.ts +0 -240
  146. package/src/plugins/SystemPluginRegistry.ts +0 -242
  147. package/src/plugins/__tests__/BlocPluginRegistry.test.ts +0 -450
  148. package/src/plugins/__tests__/SystemPluginRegistry.test.ts +0 -404
  149. package/src/plugins/types.ts +0 -129
  150. package/src/subscription/README.md +0 -132
  151. package/src/subscription/SubscriptionManager.ts +0 -395
  152. package/src/subscription/__tests__/SubscriptionManager.test.ts +0 -355
  153. package/src/subscription/types.ts +0 -90
  154. package/src/testing.ts +0 -246
  155. package/src/utils/BatchingManager.ts +0 -59
  156. package/src/utils/RerenderLogger.ts +0 -265
  157. package/src/utils/__tests__/generateInstanceId.test.ts +0 -104
  158. package/src/utils/__tests__/shallowEqual.test.ts +0 -171
  159. package/src/utils/__tests__/uuid.test.ts +0 -144
  160. package/src/utils/generateInstanceId.ts +0 -54
  161. package/src/utils/shallowEqual.ts +0 -40
  162. package/src/utils/uuid.ts +0 -22
@@ -1,144 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
- import { generateUUID } from '../uuid';
3
-
4
- describe('generateUUID', () => {
5
- const UUID_REGEX =
6
- /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
7
-
8
- describe('crypto.randomUUID available', () => {
9
- it('should use crypto.randomUUID when available', () => {
10
- const mockRandomUUID = vi.fn(
11
- () => '550e8400-e29b-41d4-a716-446655440000',
12
- );
13
-
14
- // Mock the crypto object
15
- vi.stubGlobal('crypto', {
16
- randomUUID: mockRandomUUID,
17
- });
18
-
19
- const uuid = generateUUID();
20
-
21
- expect(mockRandomUUID).toHaveBeenCalled();
22
- expect(uuid).toBe('550e8400-e29b-41d4-a716-446655440000');
23
-
24
- vi.unstubAllGlobals();
25
- });
26
-
27
- it('should return valid UUID v4 format from native crypto.randomUUID', () => {
28
- // Test with real crypto.randomUUID if available
29
- if (typeof crypto !== 'undefined' && crypto.randomUUID !== undefined) {
30
- const uuid = generateUUID();
31
- expect(uuid).toMatch(UUID_REGEX);
32
- } else {
33
- // Skip test if crypto.randomUUID is not available in test environment
34
- expect(true).toBe(true);
35
- }
36
- });
37
- });
38
-
39
- describe('Fallback implementation', () => {
40
- beforeEach(() => {
41
- // Remove crypto to force fallback
42
- vi.stubGlobal('crypto', undefined);
43
- });
44
-
45
- afterEach(() => {
46
- vi.unstubAllGlobals();
47
- });
48
-
49
- it('should generate valid UUID v4 format using fallback', () => {
50
- const uuid = generateUUID();
51
- expect(uuid).toMatch(UUID_REGEX);
52
- });
53
-
54
- it('should generate unique UUIDs', () => {
55
- const uuids = new Set();
56
- const count = 1000;
57
-
58
- for (let i = 0; i < count; i++) {
59
- uuids.add(generateUUID());
60
- }
61
-
62
- // All generated UUIDs should be unique
63
- expect(uuids.size).toBe(count);
64
- });
65
-
66
- it('should have correct version and variant bits', () => {
67
- for (let i = 0; i < 100; i++) {
68
- const uuid = generateUUID();
69
- const parts = uuid.split('-');
70
-
71
- // Version 4 UUID should have '4' in the third group
72
- expect(parts[2][0]).toBe('4');
73
-
74
- // Variant bits should be correct (8, 9, a, or b)
75
- const variantChar = parts[3][0].toLowerCase();
76
- expect(['8', '9', 'a', 'b']).toContain(variantChar);
77
- }
78
- });
79
-
80
- it('should have correct length and format', () => {
81
- const uuid = generateUUID();
82
-
83
- expect(uuid.length).toBe(36);
84
- expect(uuid.split('-').length).toBe(5);
85
-
86
- const parts = uuid.split('-');
87
- expect(parts[0].length).toBe(8);
88
- expect(parts[1].length).toBe(4);
89
- expect(parts[2].length).toBe(4);
90
- expect(parts[3].length).toBe(4);
91
- expect(parts[4].length).toBe(12);
92
- });
93
- });
94
-
95
- describe('Environment compatibility', () => {
96
- it('should work when crypto is defined but randomUUID is not', () => {
97
- // Mock crypto without randomUUID
98
- vi.stubGlobal('crypto', {});
99
-
100
- const uuid = generateUUID();
101
- expect(uuid).toMatch(UUID_REGEX);
102
-
103
- vi.unstubAllGlobals();
104
- });
105
-
106
- it('should work with different Math.random implementations', () => {
107
- // First remove crypto to ensure fallback
108
- vi.stubGlobal('crypto', undefined);
109
-
110
- const originalMathRandom = Math.random;
111
- let callCount = 0;
112
-
113
- // Mock Math.random to return predictable values
114
- Math.random = vi.fn(() => {
115
- callCount++;
116
- return (callCount % 16) / 16;
117
- });
118
-
119
- const uuid = generateUUID();
120
- expect(uuid).toMatch(UUID_REGEX);
121
- expect(Math.random).toHaveBeenCalled();
122
-
123
- Math.random = originalMathRandom;
124
- vi.unstubAllGlobals();
125
- });
126
- });
127
-
128
- describe('Performance', () => {
129
- it('should generate UUIDs efficiently', () => {
130
- const startTime = performance.now();
131
- const iterations = 10000;
132
-
133
- for (let i = 0; i < iterations; i++) {
134
- generateUUID();
135
- }
136
-
137
- const endTime = performance.now();
138
- const totalTime = endTime - startTime;
139
-
140
- // Should generate 10,000 UUIDs in less than 100ms
141
- expect(totalTime).toBeLessThan(100);
142
- });
143
- });
144
- });
@@ -1,54 +0,0 @@
1
- /**
2
- * Generates a deterministic instance ID from static props by extracting primitive values
3
- *
4
- * Rules:
5
- * 1. Only considers primitive types: string, number, boolean, null, undefined
6
- * 2. Ignores complex types: objects, arrays, functions, symbols
7
- * 3. Sorts keys alphabetically for deterministic output
8
- * 4. Returns undefined if no primitives found (caller should use default ID)
9
- */
10
- export function generateInstanceIdFromProps(
11
- props: unknown,
12
- ): string | undefined {
13
- if (!props || typeof props !== 'object') {
14
- return undefined;
15
- }
16
-
17
- const primitives: Array<[string, unknown]> = [];
18
-
19
- // Extract primitive values
20
- for (const [key, value] of Object.entries(props)) {
21
- const type = typeof value;
22
- if (
23
- type === 'string' ||
24
- type === 'number' ||
25
- type === 'boolean' ||
26
- value === null ||
27
- value === undefined
28
- ) {
29
- primitives.push([key, value]);
30
- }
31
- }
32
-
33
- // No primitives found
34
- if (primitives.length === 0) {
35
- return undefined;
36
- }
37
-
38
- // Sort by key for deterministic output
39
- primitives.sort(([a], [b]) => a.localeCompare(b));
40
-
41
- // Create instance ID
42
- const parts: string[] = [];
43
- for (const [key, value] of primitives) {
44
- if (value === null) {
45
- parts.push(`${key}:null`);
46
- } else if (value === undefined) {
47
- parts.push(`${key}:undefined`);
48
- } else {
49
- parts.push(`${key}:${String(value)}`);
50
- }
51
- }
52
-
53
- return parts.join('|');
54
- }
@@ -1,40 +0,0 @@
1
- /**
2
- * Performs a shallow equality comparison between two values.
3
- * For objects, it checks if all top-level properties are equal using Object.is.
4
- * @param a First value to compare
5
- * @param b Second value to compare
6
- * @returns true if values are shallowly equal, false otherwise
7
- */
8
- export function shallowEqual(a: any, b: any): boolean {
9
- if (Object.is(a, b)) {
10
- return true;
11
- }
12
-
13
- if (
14
- typeof a !== 'object' ||
15
- a === null ||
16
- typeof b !== 'object' ||
17
- b === null
18
- ) {
19
- return false;
20
- }
21
-
22
- const keysA = Object.keys(a);
23
- const keysB = Object.keys(b);
24
-
25
- if (keysA.length !== keysB.length) {
26
- return false;
27
- }
28
-
29
- for (let i = 0; i < keysA.length; i++) {
30
- const key = keysA[i];
31
- if (
32
- !Object.prototype.hasOwnProperty.call(b, key) ||
33
- !Object.is(a[key], b[key])
34
- ) {
35
- return false;
36
- }
37
- }
38
-
39
- return true;
40
- }
package/src/utils/uuid.ts DELETED
@@ -1,22 +0,0 @@
1
- /**
2
- * Cross-platform UUID v4 generator that works in all environments including React Native/Hermes
3
- * Falls back to crypto.randomUUID() when available, otherwise uses Math.random()
4
- */
5
-
6
- /**
7
- * Generates a UUID v4 string compatible with all JavaScript environments
8
- * @returns A UUID v4 string in the format xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
9
- */
10
- export function generateUUID(): string {
11
- // Try to use crypto.randomUUID() if available (Node.js 16+, modern browsers)
12
- if (typeof crypto !== 'undefined' && crypto.randomUUID) {
13
- return crypto.randomUUID();
14
- }
15
-
16
- // Fallback implementation for React Native/Hermes and older environments
17
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
18
- const r = (Math.random() * 16) | 0;
19
- const v = c === 'x' ? r : (r & 0x3) | 0x8;
20
- return v.toString(16);
21
- });
22
- }