@engjts/nexus 0.1.8 → 0.1.9

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 (205) hide show
  1. package/package.json +1 -1
  2. package/BENCHMARK_REPORT.md +0 -343
  3. package/documentation/01-getting-started.md +0 -240
  4. package/documentation/02-context.md +0 -335
  5. package/documentation/03-routing.md +0 -397
  6. package/documentation/04-middleware.md +0 -483
  7. package/documentation/05-validation.md +0 -514
  8. package/documentation/06-error-handling.md +0 -465
  9. package/documentation/07-performance.md +0 -364
  10. package/documentation/08-adapters.md +0 -470
  11. package/documentation/09-api-reference.md +0 -548
  12. package/documentation/10-examples.md +0 -582
  13. package/documentation/11-deployment.md +0 -477
  14. package/documentation/12-sentry.md +0 -620
  15. package/documentation/13-sentry-data-storage.md +0 -996
  16. package/documentation/14-sentry-data-reference.md +0 -457
  17. package/documentation/15-sentry-summary.md +0 -409
  18. package/documentation/16-alerts-system.md +0 -745
  19. package/documentation/17-alert-adapters.md +0 -696
  20. package/documentation/18-alerts-implementation-summary.md +0 -385
  21. package/documentation/19-class-based-routing.md +0 -840
  22. package/documentation/20-websocket-realtime.md +0 -813
  23. package/documentation/21-cache-system.md +0 -510
  24. package/documentation/22-job-queue.md +0 -772
  25. package/documentation/23-sentry-plugin.md +0 -551
  26. package/documentation/24-testing-utilities.md +0 -1287
  27. package/documentation/25-api-versioning.md +0 -533
  28. package/documentation/26-context-store.md +0 -607
  29. package/documentation/27-dependency-injection.md +0 -329
  30. package/documentation/28-lifecycle-hooks.md +0 -521
  31. package/documentation/29-package-structure.md +0 -196
  32. package/documentation/30-plugin-system.md +0 -414
  33. package/documentation/31-jwt-authentication.md +0 -597
  34. package/documentation/32-cli.md +0 -268
  35. package/documentation/ALERTS-COMPLETE-SUMMARY.md +0 -429
  36. package/documentation/ALERTS-INDEX.md +0 -330
  37. package/documentation/ALERTS-QUICK-REFERENCE.md +0 -286
  38. package/documentation/README.md +0 -178
  39. package/documentation/index.html +0 -34
  40. package/modern_framework_paper.md +0 -1870
  41. package/public/css/style.css +0 -87
  42. package/public/index.html +0 -34
  43. package/public/js/app.js +0 -27
  44. package/src/advanced/cache/InMemoryCacheStore.ts +0 -68
  45. package/src/advanced/cache/MultiTierCache.ts +0 -194
  46. package/src/advanced/cache/RedisCacheStore.ts +0 -341
  47. package/src/advanced/cache/index.ts +0 -5
  48. package/src/advanced/cache/types.ts +0 -40
  49. package/src/advanced/graphql/SimpleDataLoader.ts +0 -42
  50. package/src/advanced/graphql/index.ts +0 -22
  51. package/src/advanced/graphql/server.ts +0 -252
  52. package/src/advanced/graphql/types.ts +0 -42
  53. package/src/advanced/jobs/InMemoryQueueStore.ts +0 -68
  54. package/src/advanced/jobs/JobQueue.ts +0 -556
  55. package/src/advanced/jobs/RedisQueueStore.ts +0 -367
  56. package/src/advanced/jobs/index.ts +0 -5
  57. package/src/advanced/jobs/types.ts +0 -70
  58. package/src/advanced/observability/APMManager.ts +0 -163
  59. package/src/advanced/observability/AlertManager.ts +0 -109
  60. package/src/advanced/observability/MetricRegistry.ts +0 -151
  61. package/src/advanced/observability/ObservabilityCenter.ts +0 -304
  62. package/src/advanced/observability/StructuredLogger.ts +0 -154
  63. package/src/advanced/observability/TracingManager.ts +0 -117
  64. package/src/advanced/observability/adapters.ts +0 -304
  65. package/src/advanced/observability/createObservabilityMiddleware.ts +0 -63
  66. package/src/advanced/observability/index.ts +0 -11
  67. package/src/advanced/observability/types.ts +0 -174
  68. package/src/advanced/playground/extractPathParams.ts +0 -6
  69. package/src/advanced/playground/generateFieldExample.ts +0 -31
  70. package/src/advanced/playground/generatePlaygroundHTML.ts +0 -1956
  71. package/src/advanced/playground/generateSummary.ts +0 -19
  72. package/src/advanced/playground/getTagFromPath.ts +0 -9
  73. package/src/advanced/playground/index.ts +0 -8
  74. package/src/advanced/playground/playground.ts +0 -250
  75. package/src/advanced/playground/types.ts +0 -49
  76. package/src/advanced/playground/zodToExample.ts +0 -16
  77. package/src/advanced/playground/zodToParams.ts +0 -15
  78. package/src/advanced/postman/buildAuth.ts +0 -31
  79. package/src/advanced/postman/buildBody.ts +0 -15
  80. package/src/advanced/postman/buildQueryParams.ts +0 -27
  81. package/src/advanced/postman/buildRequestItem.ts +0 -36
  82. package/src/advanced/postman/buildResponses.ts +0 -11
  83. package/src/advanced/postman/buildUrl.ts +0 -33
  84. package/src/advanced/postman/capitalize.ts +0 -4
  85. package/src/advanced/postman/generateCollection.ts +0 -59
  86. package/src/advanced/postman/generateEnvironment.ts +0 -34
  87. package/src/advanced/postman/generateExampleFromZod.ts +0 -21
  88. package/src/advanced/postman/generateFieldExample.ts +0 -45
  89. package/src/advanced/postman/generateName.ts +0 -20
  90. package/src/advanced/postman/generateUUID.ts +0 -11
  91. package/src/advanced/postman/getTagFromPath.ts +0 -10
  92. package/src/advanced/postman/index.ts +0 -28
  93. package/src/advanced/postman/postman.ts +0 -156
  94. package/src/advanced/postman/slugify.ts +0 -7
  95. package/src/advanced/postman/types.ts +0 -140
  96. package/src/advanced/realtime/index.ts +0 -18
  97. package/src/advanced/realtime/websocket.ts +0 -231
  98. package/src/advanced/sentry/index.ts +0 -1236
  99. package/src/advanced/sentry/types.ts +0 -355
  100. package/src/advanced/static/generateDirectoryListing.ts +0 -47
  101. package/src/advanced/static/generateETag.ts +0 -7
  102. package/src/advanced/static/getMimeType.ts +0 -9
  103. package/src/advanced/static/index.ts +0 -32
  104. package/src/advanced/static/isSafePath.ts +0 -13
  105. package/src/advanced/static/publicDir.ts +0 -21
  106. package/src/advanced/static/serveStatic.ts +0 -225
  107. package/src/advanced/static/spa.ts +0 -24
  108. package/src/advanced/static/types.ts +0 -159
  109. package/src/advanced/swagger/SwaggerGenerator.ts +0 -66
  110. package/src/advanced/swagger/buildOperation.ts +0 -61
  111. package/src/advanced/swagger/buildParameters.ts +0 -61
  112. package/src/advanced/swagger/buildRequestBody.ts +0 -21
  113. package/src/advanced/swagger/buildResponses.ts +0 -54
  114. package/src/advanced/swagger/capitalize.ts +0 -5
  115. package/src/advanced/swagger/convertPath.ts +0 -9
  116. package/src/advanced/swagger/createSwagger.ts +0 -12
  117. package/src/advanced/swagger/generateOperationId.ts +0 -21
  118. package/src/advanced/swagger/generateSpec.ts +0 -105
  119. package/src/advanced/swagger/generateSummary.ts +0 -24
  120. package/src/advanced/swagger/generateSwaggerUI.ts +0 -70
  121. package/src/advanced/swagger/generateThemeCss.ts +0 -53
  122. package/src/advanced/swagger/index.ts +0 -25
  123. package/src/advanced/swagger/swagger.ts +0 -237
  124. package/src/advanced/swagger/types.ts +0 -206
  125. package/src/advanced/swagger/zodFieldToOpenAPI.ts +0 -94
  126. package/src/advanced/swagger/zodSchemaToOpenAPI.ts +0 -50
  127. package/src/advanced/swagger/zodToOpenAPI.ts +0 -22
  128. package/src/advanced/testing/factory.ts +0 -509
  129. package/src/advanced/testing/harness.ts +0 -612
  130. package/src/advanced/testing/index.ts +0 -430
  131. package/src/advanced/testing/load-test.ts +0 -618
  132. package/src/advanced/testing/mock-server.ts +0 -498
  133. package/src/advanced/testing/mock.ts +0 -670
  134. package/src/cli/bin.ts +0 -9
  135. package/src/cli/cli.ts +0 -158
  136. package/src/cli/commands/add.ts +0 -178
  137. package/src/cli/commands/build.ts +0 -73
  138. package/src/cli/commands/create.ts +0 -166
  139. package/src/cli/commands/dev.ts +0 -85
  140. package/src/cli/commands/generate.ts +0 -99
  141. package/src/cli/commands/help.ts +0 -95
  142. package/src/cli/commands/init.ts +0 -91
  143. package/src/cli/commands/version.ts +0 -38
  144. package/src/cli/index.ts +0 -6
  145. package/src/cli/templates/generators.ts +0 -359
  146. package/src/cli/templates/index.ts +0 -680
  147. package/src/cli/utils/exec.ts +0 -52
  148. package/src/cli/utils/file-system.ts +0 -78
  149. package/src/cli/utils/logger.ts +0 -111
  150. package/src/core/adapter.ts +0 -88
  151. package/src/core/application.ts +0 -1453
  152. package/src/core/context-pool.ts +0 -79
  153. package/src/core/context.ts +0 -856
  154. package/src/core/index.ts +0 -94
  155. package/src/core/middleware.ts +0 -272
  156. package/src/core/performance/buffer-pool.ts +0 -108
  157. package/src/core/performance/middleware-optimizer.ts +0 -162
  158. package/src/core/plugin/PluginManager.ts +0 -435
  159. package/src/core/plugin/builder.ts +0 -358
  160. package/src/core/plugin/index.ts +0 -50
  161. package/src/core/plugin/types.ts +0 -214
  162. package/src/core/router/file-router.ts +0 -623
  163. package/src/core/router/index.ts +0 -260
  164. package/src/core/router/radix-tree.ts +0 -242
  165. package/src/core/serializer.ts +0 -397
  166. package/src/core/store/index.ts +0 -30
  167. package/src/core/store/registry.ts +0 -178
  168. package/src/core/store/request-store.ts +0 -240
  169. package/src/core/store/types.ts +0 -233
  170. package/src/core/types.ts +0 -616
  171. package/src/database/adapter.ts +0 -35
  172. package/src/database/adapters/index.ts +0 -1
  173. package/src/database/adapters/mysql.ts +0 -669
  174. package/src/database/database.ts +0 -70
  175. package/src/database/dialect.ts +0 -388
  176. package/src/database/index.ts +0 -12
  177. package/src/database/migrations.ts +0 -86
  178. package/src/database/optimizer.ts +0 -125
  179. package/src/database/query-builder.ts +0 -404
  180. package/src/database/realtime.ts +0 -53
  181. package/src/database/schema.ts +0 -71
  182. package/src/database/transactions.ts +0 -56
  183. package/src/database/types.ts +0 -87
  184. package/src/deployment/cluster.ts +0 -471
  185. package/src/deployment/config.ts +0 -454
  186. package/src/deployment/docker.ts +0 -599
  187. package/src/deployment/graceful-shutdown.ts +0 -373
  188. package/src/deployment/index.ts +0 -56
  189. package/src/index.ts +0 -281
  190. package/src/security/adapter.ts +0 -318
  191. package/src/security/auth/JWTPlugin.ts +0 -234
  192. package/src/security/auth/JWTProvider.ts +0 -316
  193. package/src/security/auth/adapter.ts +0 -12
  194. package/src/security/auth/jwt.ts +0 -234
  195. package/src/security/auth/middleware.ts +0 -188
  196. package/src/security/csrf.ts +0 -220
  197. package/src/security/headers.ts +0 -108
  198. package/src/security/index.ts +0 -60
  199. package/src/security/rate-limit/adapter.ts +0 -7
  200. package/src/security/rate-limit/memory.ts +0 -108
  201. package/src/security/rate-limit/middleware.ts +0 -181
  202. package/src/security/sanitization.ts +0 -75
  203. package/src/security/types.ts +0 -240
  204. package/src/security/utils.ts +0 -52
  205. package/tsconfig.json +0 -39
@@ -1,397 +0,0 @@
1
- /**
2
- * Fast JSON Serializer Module
3
- * Uses fast-json-stringify for 2-3x faster JSON serialization
4
- *
5
- * @example
6
- * ```typescript
7
- * // Define response schema
8
- * const userSchema = {
9
- * type: 'object',
10
- * properties: {
11
- * id: { type: 'number' },
12
- * name: { type: 'string' },
13
- * email: { type: 'string' }
14
- * }
15
- * };
16
- *
17
- * // Create serializer
18
- * const serialize = createSerializer(userSchema);
19
- *
20
- * // Use in handler (2-3x faster than JSON.stringify)
21
- * app.get('/user', {
22
- * responseSchema: userSchema,
23
- * handler: async (ctx) => ({ id: 1, name: 'John', email: 'john@example.com' })
24
- * });
25
- * ```
26
- */
27
-
28
- import fastJson from 'fast-json-stringify';
29
-
30
- /**
31
- * JSON Schema type definition for fast-json-stringify
32
- */
33
- export interface JSONSchema {
34
- type?: string;
35
- properties?: Record<string, JSONSchema>;
36
- items?: JSONSchema | JSONSchema[];
37
- additionalProperties?: boolean | JSONSchema;
38
- required?: string[];
39
- nullable?: boolean;
40
- default?: any;
41
- enum?: any[];
42
- const?: any;
43
- format?: string;
44
- minimum?: number;
45
- maximum?: number;
46
- minLength?: number;
47
- maxLength?: number;
48
- pattern?: string;
49
- $ref?: string;
50
- $id?: string;
51
- definitions?: Record<string, JSONSchema>;
52
- allOf?: JSONSchema[];
53
- anyOf?: JSONSchema[];
54
- oneOf?: JSONSchema[];
55
- if?: JSONSchema;
56
- then?: JSONSchema;
57
- else?: JSONSchema;
58
- // Array specific
59
- minItems?: number;
60
- maxItems?: number;
61
- uniqueItems?: boolean;
62
- // Object specific
63
- minProperties?: number;
64
- maxProperties?: number;
65
- patternProperties?: Record<string, JSONSchema>;
66
- }
67
-
68
- /**
69
- * Response schema configuration for routes
70
- */
71
- export interface ResponseSchemaConfig {
72
- /** Schema for 2xx responses */
73
- '2xx'?: JSONSchema;
74
- /** Schema for specific status codes */
75
- 200?: JSONSchema;
76
- 201?: JSONSchema;
77
- 204?: JSONSchema;
78
- /** Schema for error responses */
79
- '4xx'?: JSONSchema;
80
- 400?: JSONSchema;
81
- 401?: JSONSchema;
82
- 403?: JSONSchema;
83
- 404?: JSONSchema;
84
- '5xx'?: JSONSchema;
85
- 500?: JSONSchema;
86
- /** Default schema for any status code */
87
- default?: JSONSchema;
88
- }
89
-
90
- /**
91
- * Serializer function type
92
- */
93
- export type SerializerFunction = (data: any) => string;
94
-
95
- /**
96
- * Serializer options for fast-json-stringify
97
- */
98
- export interface SerializerOptions {
99
- /** Use strict mode for schema validation */
100
- mode?: 'debug' | 'standalone';
101
- /** Rounding mode for numbers */
102
- rounding?: 'ceil' | 'floor' | 'round' | 'trunc';
103
- /** Large array mode optimization */
104
- largeArrayMechanism?: 'default' | 'json-stringify';
105
- /** Large array size threshold */
106
- largeArraySize?: number;
107
- }
108
-
109
- /**
110
- * Compiled serializers cache
111
- * Maps route path + method to serializer functions
112
- */
113
- class SerializerRegistry {
114
- private serializers: Map<string, Map<number | string, SerializerFunction>> = new Map();
115
- private schemaCache: WeakMap<JSONSchema, SerializerFunction> = new WeakMap();
116
- private options: SerializerOptions;
117
-
118
- constructor(options: SerializerOptions = {}) {
119
- this.options = {
120
- mode: 'standalone',
121
- rounding: 'trunc',
122
- largeArrayMechanism: 'default',
123
- largeArraySize: 20000,
124
- ...options
125
- };
126
- }
127
-
128
- /**
129
- * Compile a schema into a serializer function
130
- */
131
- compile(schema: JSONSchema): SerializerFunction {
132
- // Check cache first
133
- const cached = this.schemaCache.get(schema);
134
- if (cached) return cached;
135
-
136
- // Compile new serializer
137
- const serializer = fastJson(schema as any, {
138
- mode: this.options.mode,
139
- rounding: this.options.rounding,
140
- largeArrayMechanism: this.options.largeArrayMechanism,
141
- largeArraySize: this.options.largeArraySize
142
- });
143
-
144
- // Cache it
145
- this.schemaCache.set(schema, serializer);
146
- return serializer;
147
- }
148
-
149
- /**
150
- * Register serializers for a route
151
- */
152
- register(routeKey: string, schemas: ResponseSchemaConfig): void {
153
- const routeSerializers = new Map<number | string, SerializerFunction>();
154
-
155
- for (const [statusKey, schema] of Object.entries(schemas)) {
156
- if (schema) {
157
- const serializer = this.compile(schema);
158
- routeSerializers.set(statusKey, serializer);
159
- }
160
- }
161
-
162
- this.serializers.set(routeKey, routeSerializers);
163
- }
164
-
165
- /**
166
- * Get serializer for a route and status code
167
- */
168
- get(routeKey: string, statusCode: number): SerializerFunction | null {
169
- const routeSerializers = this.serializers.get(routeKey);
170
- if (!routeSerializers) return null;
171
-
172
- // Try exact match first
173
- const exactMatch = routeSerializers.get(statusCode);
174
- if (exactMatch) return exactMatch;
175
-
176
- // Try status code ranges (2xx, 4xx, 5xx)
177
- const range = `${Math.floor(statusCode / 100)}xx`;
178
- const rangeMatch = routeSerializers.get(range);
179
- if (rangeMatch) return rangeMatch;
180
-
181
- // Try default
182
- return routeSerializers.get('default') || null;
183
- }
184
-
185
- /**
186
- * Check if route has registered serializers
187
- */
188
- has(routeKey: string): boolean {
189
- return this.serializers.has(routeKey);
190
- }
191
-
192
- /**
193
- * Clear all serializers
194
- */
195
- clear(): void {
196
- this.serializers.clear();
197
- }
198
-
199
- /**
200
- * Get route key from method and path
201
- */
202
- static getRouteKey(method: string, path: string): string {
203
- return `${method}:${path}`;
204
- }
205
- }
206
-
207
- /**
208
- * Global serializer registry instance
209
- */
210
- export const serializerRegistry = new SerializerRegistry();
211
-
212
- /**
213
- * Create a standalone serializer from schema
214
- * Use this for manual serialization outside of routes
215
- *
216
- * @example
217
- * ```typescript
218
- * const userSerializer = createSerializer({
219
- * type: 'object',
220
- * properties: {
221
- * id: { type: 'number' },
222
- * name: { type: 'string' }
223
- * }
224
- * });
225
- *
226
- * const json = userSerializer({ id: 1, name: 'John' });
227
- * // Much faster than JSON.stringify!
228
- * ```
229
- */
230
- export function createSerializer(schema: JSONSchema, options?: SerializerOptions): SerializerFunction {
231
- return fastJson(schema as any, {
232
- mode: options?.mode || 'standalone',
233
- rounding: options?.rounding || 'trunc',
234
- largeArrayMechanism: options?.largeArrayMechanism || 'default',
235
- largeArraySize: options?.largeArraySize || 20000
236
- });
237
- }
238
-
239
- /**
240
- * Create an array serializer optimized for large arrays
241
- *
242
- * @example
243
- * ```typescript
244
- * const usersSerializer = createArraySerializer({
245
- * type: 'object',
246
- * properties: {
247
- * id: { type: 'number' },
248
- * name: { type: 'string' }
249
- * }
250
- * });
251
- *
252
- * // Optimized for arrays with 100+ items
253
- * const json = usersSerializer(users);
254
- * ```
255
- */
256
- export function createArraySerializer(itemSchema: JSONSchema, options?: SerializerOptions): SerializerFunction {
257
- const arraySchema: JSONSchema = {
258
- type: 'array',
259
- items: itemSchema
260
- };
261
-
262
- return fastJson(arraySchema as any, {
263
- mode: options?.mode || 'standalone',
264
- rounding: options?.rounding || 'trunc',
265
- // For large arrays, use optimized mechanism
266
- largeArrayMechanism: options?.largeArrayMechanism || 'default',
267
- largeArraySize: options?.largeArraySize || 20000
268
- });
269
- }
270
-
271
- /**
272
- * Common schemas for quick use
273
- */
274
- export const CommonSchemas = {
275
- /** String type */
276
- string: { type: 'string' } as JSONSchema,
277
-
278
- /** Number type */
279
- number: { type: 'number' } as JSONSchema,
280
-
281
- /** Integer type */
282
- integer: { type: 'integer' } as JSONSchema,
283
-
284
- /** Boolean type */
285
- boolean: { type: 'boolean' } as JSONSchema,
286
-
287
- /** Null type */
288
- null: { type: 'null' } as JSONSchema,
289
-
290
- /** Any type (no validation, uses JSON.stringify internally) */
291
- any: {} as JSONSchema,
292
-
293
- /** UUID string format */
294
- uuid: { type: 'string', format: 'uuid' } as JSONSchema,
295
-
296
- /** Email string format */
297
- email: { type: 'string', format: 'email' } as JSONSchema,
298
-
299
- /** Date-time string format */
300
- datetime: { type: 'string', format: 'date-time' } as JSONSchema,
301
-
302
- /** Date string format */
303
- date: { type: 'string', format: 'date' } as JSONSchema,
304
-
305
- /** URI string format */
306
- uri: { type: 'string', format: 'uri' } as JSONSchema,
307
-
308
- /**
309
- * Create object schema helper
310
- * @example
311
- * ```typescript
312
- * const userSchema = CommonSchemas.object({
313
- * id: CommonSchemas.number,
314
- * name: CommonSchemas.string,
315
- * email: CommonSchemas.email
316
- * });
317
- * ```
318
- */
319
- object: (properties: Record<string, JSONSchema>, required?: string[]): JSONSchema => ({
320
- type: 'object',
321
- properties,
322
- required,
323
- additionalProperties: false
324
- }),
325
-
326
- /**
327
- * Create array schema helper
328
- * @example
329
- * ```typescript
330
- * const usersSchema = CommonSchemas.array(userSchema);
331
- * ```
332
- */
333
- array: (items: JSONSchema): JSONSchema => ({
334
- type: 'array',
335
- items
336
- }),
337
-
338
- /**
339
- * Create nullable schema helper
340
- * @example
341
- * ```typescript
342
- * const nullableString = CommonSchemas.nullable(CommonSchemas.string);
343
- * ```
344
- */
345
- nullable: (schema: JSONSchema): JSONSchema => ({
346
- ...schema,
347
- nullable: true
348
- }),
349
-
350
- /**
351
- * Standard error response schema
352
- */
353
- error: {
354
- type: 'object',
355
- properties: {
356
- error: { type: 'string' },
357
- message: { type: 'string' },
358
- statusCode: { type: 'number' }
359
- }
360
- } as JSONSchema,
361
-
362
- /**
363
- * Standard pagination response schema helper
364
- * @example
365
- * ```typescript
366
- * const paginatedUsers = CommonSchemas.paginated(userSchema);
367
- * ```
368
- */
369
- paginated: (itemSchema: JSONSchema): JSONSchema => ({
370
- type: 'object',
371
- properties: {
372
- data: { type: 'array', items: itemSchema },
373
- total: { type: 'number' },
374
- page: { type: 'number' },
375
- limit: { type: 'number' },
376
- totalPages: { type: 'number' }
377
- }
378
- })
379
- };
380
-
381
- /**
382
- * Serialize data with fast-json-stringify
383
- * Falls back to JSON.stringify if no schema is provided
384
- */
385
- export function serialize(data: any, schema?: JSONSchema): string {
386
- if (!schema) {
387
- return JSON.stringify(data);
388
- }
389
-
390
- const serializer = serializerRegistry.compile(schema);
391
- return serializer(data);
392
- }
393
-
394
- /**
395
- * Export SerializerRegistry class for advanced usage
396
- */
397
- export { SerializerRegistry };
@@ -1,30 +0,0 @@
1
- /**
2
- * ContextStore System
3
- * State management inspired by Flutter's Provider pattern
4
- *
5
- * Two types of stores:
6
- * - ContextStore: Global singleton, persists across all requests
7
- * - RequestStore: Per-request scoped, disposed after response
8
- */
9
-
10
- // Core store classes
11
- export { ContextStore } from './types';
12
- export { RequestStore } from './request-store';
13
-
14
- // Types
15
- export type {
16
- StoreListener,
17
- DisposeCallback,
18
- StoreConstructor,
19
- StateOf,
20
- StoreOptions
21
- } from './types';
22
-
23
- export type {
24
- RequestStoreConstructor,
25
- RequestStateOf
26
- } from './request-store';
27
-
28
- // Registries
29
- export { StoreRegistry, createStoreRegistry } from './registry';
30
- export { RequestStoreRegistry } from './request-store';
@@ -1,178 +0,0 @@
1
- /**
2
- * StoreRegistry - Global store container
3
- * Manages all ContextStore instances at application level
4
- */
5
-
6
- import { ContextStore, StoreConstructor, StoreRegistryOptions } from './types';
7
-
8
- /**
9
- * StoreRegistry manages all stores in the application
10
- * Ensures singleton instances and handles lifecycle
11
- */
12
- export class StoreRegistry {
13
- private stores: Map<StoreConstructor<any>, ContextStore<any>> = new Map();
14
- private options: StoreRegistryOptions;
15
-
16
- constructor(options: StoreRegistryOptions = {}) {
17
- this.options = options;
18
- }
19
-
20
- /**
21
- * Register a store class
22
- * Creates instance immediately
23
- *
24
- * @param StoreClass - Store constructor class
25
- * @returns The created store instance
26
- */
27
- register<T extends ContextStore<any>>(StoreClass: StoreConstructor<T>): T {
28
- if (this.stores.has(StoreClass)) {
29
- if (this.options.debug) {
30
- console.log(`[StoreRegistry] Store ${StoreClass.name} already registered`);
31
- }
32
- return this.stores.get(StoreClass) as T;
33
- }
34
-
35
- const instance = new StoreClass({ debug: this.options.debug });
36
- this.stores.set(StoreClass, instance);
37
-
38
- if (this.options.debug) {
39
- console.log(`[StoreRegistry] Registered store: ${StoreClass.name}`);
40
- }
41
-
42
- // Call onInit if defined
43
- const initResult = instance.onInit();
44
- if (initResult instanceof Promise) {
45
- initResult.catch(err => {
46
- console.error(`[StoreRegistry] Error in ${StoreClass.name}.onInit():`, err);
47
- });
48
- }
49
-
50
- return instance;
51
- }
52
-
53
- /**
54
- * Register multiple stores at once
55
- *
56
- * @param storeClasses - Array of store constructor classes
57
- */
58
- registerAll(storeClasses: StoreConstructor<any>[]): void {
59
- storeClasses.forEach(StoreClass => this.register(StoreClass));
60
- }
61
-
62
- /**
63
- * Get a store instance by its class
64
- * Throws if store is not registered
65
- *
66
- * @param StoreClass - Store constructor class
67
- * @returns Store instance
68
- */
69
- get<T extends ContextStore<any>>(StoreClass: StoreConstructor<T>): T {
70
- const store = this.stores.get(StoreClass);
71
-
72
- if (!store) {
73
- throw new Error(
74
- `[StoreRegistry] Store ${StoreClass.name} is not registered. ` +
75
- `Make sure to call app.stores([${StoreClass.name}]) before accessing it.`
76
- );
77
- }
78
-
79
- return store as T;
80
- }
81
-
82
- /**
83
- * Check if a store is registered
84
- *
85
- * @param StoreClass - Store constructor class
86
- */
87
- has<T extends ContextStore<any>>(StoreClass: StoreConstructor<T>): boolean {
88
- return this.stores.has(StoreClass);
89
- }
90
-
91
- /**
92
- * Get a store instance, or register it if not exists
93
- * Useful for lazy initialization
94
- *
95
- * @param StoreClass - Store constructor class
96
- * @returns Store instance
97
- */
98
- getOrRegister<T extends ContextStore<any>>(StoreClass: StoreConstructor<T>): T {
99
- if (!this.stores.has(StoreClass)) {
100
- return this.register(StoreClass);
101
- }
102
- return this.stores.get(StoreClass) as T;
103
- }
104
-
105
- /**
106
- * Remove a store from registry and dispose it
107
- *
108
- * @param StoreClass - Store constructor class
109
- */
110
- unregister<T extends ContextStore<any>>(StoreClass: StoreConstructor<T>): void {
111
- const store = this.stores.get(StoreClass);
112
-
113
- if (store) {
114
- store.dispose();
115
- this.stores.delete(StoreClass);
116
-
117
- if (this.options.debug) {
118
- console.log(`[StoreRegistry] Unregistered store: ${StoreClass.name}`);
119
- }
120
- }
121
- }
122
-
123
- /**
124
- * Get all registered store classes
125
- */
126
- getRegisteredStores(): StoreConstructor<any>[] {
127
- return Array.from(this.stores.keys());
128
- }
129
-
130
- /**
131
- * Get store count
132
- */
133
- get size(): number {
134
- return this.stores.size;
135
- }
136
-
137
- /**
138
- * Dispose all stores and clear registry
139
- */
140
- dispose(): void {
141
- if (this.options.debug) {
142
- console.log(`[StoreRegistry] Disposing all stores (${this.stores.size})`);
143
- }
144
-
145
- this.stores.forEach((store, StoreClass) => {
146
- try {
147
- store.dispose();
148
- } catch (error) {
149
- console.error(`[StoreRegistry] Error disposing ${StoreClass.name}:`, error);
150
- }
151
- });
152
-
153
- this.stores.clear();
154
- }
155
-
156
- /**
157
- * Get debug info about all stores
158
- */
159
- getDebugInfo(): Record<string, { listenerCount: number; isInitialized: boolean }> {
160
- const info: Record<string, { listenerCount: number; isInitialized: boolean }> = {};
161
-
162
- this.stores.forEach((store, StoreClass) => {
163
- info[StoreClass.name] = {
164
- listenerCount: store.listenerCount,
165
- isInitialized: store.isInitialized
166
- };
167
- });
168
-
169
- return info;
170
- }
171
- }
172
-
173
- /**
174
- * Create a new store registry
175
- */
176
- export function createStoreRegistry(options?: StoreRegistryOptions): StoreRegistry {
177
- return new StoreRegistry(options);
178
- }