@guren/server 2.1.0 → 2.2.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.
- package/dist/{McpServiceProvider-7BB5FPF3.js → McpServiceProvider-GRDYNEQG.js} +1 -1
- package/dist/auth/AuthManager.d.ts +30 -0
- package/dist/auth/AuthenticatableModel.d.ts +25 -0
- package/dist/auth/RequestAuthContext.d.ts +24 -0
- package/dist/auth/SessionGuard.d.ts +31 -0
- package/dist/auth/api-token.d.ts +299 -0
- package/dist/auth/email-verification.d.ts +203 -0
- package/dist/auth/index.d.ts +18 -110
- package/dist/auth/index.js +3 -1
- package/dist/auth/oauth/index.d.ts +239 -0
- package/dist/auth/password/DefaultHasher.d.ts +13 -0
- package/dist/auth/password/NodeHasher.d.ts +22 -0
- package/dist/auth/password/PasswordHasher.d.ts +5 -0
- package/dist/auth/password/ScryptHasher.d.ts +26 -0
- package/dist/auth/password-reset.d.ts +91 -0
- package/dist/auth/providers/ModelUserProvider.d.ts +36 -0
- package/dist/auth/providers/UserProvider.d.ts +9 -0
- package/dist/auth/types.d.ts +102 -0
- package/dist/auth/utils.d.ts +39 -0
- package/dist/{Gate-CynjZCtS.d.ts → authorization/Gate.d.ts} +30 -111
- package/dist/authorization/Policy.d.ts +77 -0
- package/dist/authorization/index.d.ts +5 -129
- package/dist/authorization/index.js +3 -1
- package/dist/authorization/middleware.d.ts +49 -0
- package/dist/authorization/types.d.ts +108 -0
- package/dist/broadcasting/BroadcastManager.d.ts +205 -0
- package/dist/broadcasting/channels/Channel.d.ts +28 -0
- package/dist/broadcasting/channels/PresenceChannel.d.ts +72 -0
- package/dist/broadcasting/channels/PrivateChannel.d.ts +32 -0
- package/dist/broadcasting/channels/index.d.ts +3 -0
- package/dist/broadcasting/drivers/MemoryDriver.d.ts +93 -0
- package/dist/broadcasting/drivers/RedisDriver.d.ts +112 -0
- package/dist/broadcasting/drivers/index.d.ts +2 -0
- package/dist/broadcasting/index.d.ts +6 -233
- package/dist/broadcasting/index.js +1 -1
- package/dist/broadcasting/typed.d.ts +23 -0
- package/dist/broadcasting/types.d.ts +155 -0
- package/dist/cache/CacheManager.d.ts +87 -0
- package/dist/cache/TaggedCache.d.ts +62 -0
- package/dist/cache/index.d.ts +6 -233
- package/dist/cache/index.js +1 -1
- package/dist/cache/stores/FileStore.d.ts +64 -0
- package/dist/cache/stores/MemoryStore.d.ts +52 -0
- package/dist/cache/stores/RedisStore.d.ts +53 -0
- package/dist/{CacheManager-BmDzUKrF.d.ts → cache/types.d.ts} +26 -99
- package/dist/{chunk-TVY72CLV.js → chunk-4VE3LYOM.js} +3 -2
- package/dist/{chunk-FZD2AKJI.js → chunk-7OB2YXRE.js} +56 -28
- package/dist/{chunk-HONCNQXZ.js → chunk-BUQXOZCT.js} +97 -10
- package/dist/{chunk-DSDX3ASM.js → chunk-CDZUNKI6.js} +65 -83
- package/dist/{chunk-CWI4AJ47.js → chunk-HPET6XY5.js} +13 -9
- package/dist/{chunk-A3ISJVEV.js → chunk-HR2KZ3WL.js} +23 -5
- package/dist/{chunk-EARA7JM4.js → chunk-PZKUDFMW.js} +11 -8
- package/dist/console/Command.d.ts +179 -0
- package/dist/{ConsoleKernel-CJg975mp.d.ts → console/ConsoleKernel.d.ts} +4 -6
- package/dist/console/Input.d.ts +140 -0
- package/dist/console/Output.d.ts +161 -0
- package/dist/console/index.d.ts +5 -0
- package/dist/console/types.d.ts +106 -0
- package/dist/container/Container.d.ts +148 -0
- package/dist/container/ServiceProvider.d.ts +103 -0
- package/dist/container/bindings.d.ts +55 -0
- package/dist/container/defineModule.d.ts +88 -0
- package/dist/container/definePlugin.d.ts +62 -0
- package/dist/container/index.d.ts +8 -0
- package/dist/container/types.d.ts +73 -0
- package/dist/database/Factory.d.ts +82 -0
- package/dist/database/Seeder.d.ts +35 -0
- package/dist/database/SeederRunner.d.ts +41 -0
- package/dist/database/index.d.ts +4 -0
- package/dist/database/types.d.ts +49 -0
- package/dist/discovery/AutoDiscovery.d.ts +113 -0
- package/dist/discovery/index.d.ts +2 -0
- package/dist/docs-viewer/DocsViewerServiceProvider.d.ts +12 -0
- package/dist/docs-viewer/endpoint.d.ts +19 -0
- package/dist/encryption/Encrypter.d.ts +96 -0
- package/dist/encryption/Hash.d.ts +69 -0
- package/dist/encryption/MessageSigner.d.ts +21 -0
- package/dist/encryption/Random.d.ts +119 -0
- package/dist/encryption/app-key.d.ts +12 -0
- package/dist/encryption/index.d.ts +10 -222
- package/dist/encryption/signed-url.d.ts +9 -0
- package/dist/encryption/types.d.ts +103 -0
- package/dist/errors/ExceptionHandler.d.ts +118 -0
- package/dist/errors/HttpException.d.ts +106 -0
- package/dist/errors/debug-page.d.ts +22 -0
- package/dist/errors/error-page.d.ts +1 -0
- package/dist/errors/exceptions/AuthenticationException.d.ts +32 -0
- package/dist/errors/exceptions/AuthorizationException.d.ts +32 -0
- package/dist/errors/exceptions/MethodNotAllowedException.d.ts +31 -0
- package/dist/errors/exceptions/NotFoundHttpException.d.ts +36 -0
- package/dist/errors/exceptions/ValidationException.d.ts +60 -0
- package/dist/errors/exceptions/index.d.ts +5 -0
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/types.d.ts +43 -0
- package/dist/events/Event.d.ts +33 -0
- package/dist/{EventManager-CmIoLt7r.d.ts → events/EventManager.d.ts} +4 -86
- package/dist/events/Listener.d.ts +79 -0
- package/dist/events/builtin.d.ts +73 -0
- package/dist/events/index.d.ts +6 -155
- package/dist/events/types.d.ts +48 -0
- package/dist/facades/index.d.ts +31 -0
- package/dist/health/HealthCheck.d.ts +34 -0
- package/dist/health/HealthManager.d.ts +53 -0
- package/dist/health/checks/CacheCheck.d.ts +35 -0
- package/dist/health/checks/CustomCheck.d.ts +23 -0
- package/dist/health/checks/DatabaseCheck.d.ts +33 -0
- package/dist/health/checks/MemoryCheck.d.ts +32 -0
- package/dist/health/checks/RedisCheck.d.ts +27 -0
- package/dist/health/checks/StorageCheck.d.ts +35 -0
- package/dist/health/checks/index.d.ts +12 -0
- package/dist/health/index.d.ts +5 -185
- package/dist/health/types.d.ts +52 -0
- package/dist/hot-reload/hot-disposables.d.ts +96 -0
- package/dist/hot-reload/testing.d.ts +14 -0
- package/dist/http/Application.d.ts +187 -0
- package/dist/http/FormRequest.d.ts +73 -0
- package/dist/http/dev-assets.d.ts +51 -0
- package/dist/http/dev-banner.d.ts +7 -0
- package/dist/http/inertia-assets.d.ts +22 -0
- package/dist/http/middleware/auth.d.ts +13 -0
- package/dist/http/middleware/capabilities.d.ts +22 -0
- package/dist/http/middleware/cors.d.ts +40 -0
- package/dist/http/middleware/csp.d.ts +59 -0
- package/dist/http/middleware/csrf.d.ts +121 -0
- package/dist/http/middleware/detect-locale.d.ts +65 -0
- package/dist/http/middleware/force-https.d.ts +34 -0
- package/dist/http/middleware/host-authorization.d.ts +24 -0
- package/dist/http/middleware/index.d.ts +19 -0
- package/dist/http/middleware/loopback-guard.d.ts +38 -0
- package/dist/{rate-limit-D9J2b4S1.d.ts → http/middleware/rate-limit.d.ts} +22 -50
- package/dist/http/middleware/redirect-safety.d.ts +29 -0
- package/dist/http/middleware/request-id.d.ts +19 -0
- package/dist/http/middleware/request-logging.d.ts +16 -0
- package/dist/http/middleware/security-headers.d.ts +49 -0
- package/dist/http/middleware/session.d.ts +93 -0
- package/dist/http/middleware/validation.d.ts +94 -0
- package/dist/http/public-assets.d.ts +15 -0
- package/dist/http/request.d.ts +24 -0
- package/dist/http/resources/CursorPaginator.d.ts +106 -0
- package/dist/http/resources/Paginator.d.ts +130 -0
- package/dist/http/resources/Resource.d.ts +67 -0
- package/dist/http/resources/ResourceCollection.d.ts +60 -0
- package/dist/http/resources/index.d.ts +6 -0
- package/dist/http/resources/types.d.ts +91 -0
- package/dist/http/validation/Validator.d.ts +128 -0
- package/dist/http/validation/index.d.ts +3 -0
- package/dist/http/validation/rules.d.ts +196 -0
- package/dist/http/validation/types.d.ts +96 -0
- package/dist/http/vite-dev-server.d.ts +27 -0
- package/dist/i18n/I18nManager.d.ts +114 -0
- package/dist/i18n/Translator.d.ts +80 -0
- package/dist/i18n/index.d.ts +6 -101
- package/dist/i18n/index.js +5 -3
- package/dist/i18n/loaders/JsonLoader.d.ts +47 -0
- package/dist/i18n/loaders/MemoryLoader.d.ts +37 -0
- package/dist/i18n/pluralization.d.ts +19 -0
- package/dist/i18n/types.d.ts +106 -0
- package/dist/index.d.ts +69 -2605
- package/dist/index.js +332 -152
- package/dist/lambda/index.d.ts +17 -37
- package/dist/logging/LogManager.d.ts +83 -0
- package/dist/logging/Logger.d.ts +76 -0
- package/dist/logging/channels/ConsoleChannel.d.ts +11 -0
- package/dist/logging/channels/DailyFileChannel.d.ts +20 -0
- package/dist/logging/channels/FileChannel.d.ts +15 -0
- package/dist/logging/index.d.ts +8 -50
- package/dist/logging/types.d.ts +96 -0
- package/dist/mail/Mail.d.ts +138 -0
- package/dist/mail/MailManager.d.ts +79 -0
- package/dist/mail/address.d.ts +8 -0
- package/dist/mail/index.d.ts +7 -316
- package/dist/mail/transports/LogTransport.d.ts +19 -0
- package/dist/mail/transports/MemoryTransport.d.ts +84 -0
- package/dist/mail/transports/ResendTransport.d.ts +32 -0
- package/dist/mail/transports/SmtpTransport.d.ts +40 -0
- package/dist/{MailManager-DpMvYiP9.d.ts → mail/types.d.ts} +11 -92
- package/dist/mcp/McpServiceProvider.d.ts +17 -0
- package/dist/mcp/create-mcp-server.d.ts +144 -0
- package/dist/mcp/endpoint.d.ts +29 -0
- package/dist/mcp/index.d.ts +3 -185
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Controller.d.ts +326 -0
- package/dist/mvc/Router.d.ts +239 -0
- package/dist/mvc/ViewEngine.d.ts +11 -0
- package/dist/mvc/inertia/InertiaEngine.d.ts +114 -0
- package/dist/mvc/inertia/shared.d.ts +90 -0
- package/dist/mvc/mount-route.d.ts +10 -0
- package/dist/notifications/Notification.d.ts +99 -0
- package/dist/notifications/NotificationManager.d.ts +150 -0
- package/dist/notifications/channels/DatabaseChannel.d.ts +55 -0
- package/dist/notifications/channels/MailChannel.d.ts +45 -0
- package/dist/notifications/channels/MemoryChannel.d.ts +85 -0
- package/dist/notifications/channels/SlackChannel.d.ts +73 -0
- package/dist/notifications/channels/index.d.ts +4 -0
- package/dist/notifications/index.d.ts +6 -322
- package/dist/notifications/notifiable-type.d.ts +10 -0
- package/dist/notifications/registry.d.ts +39 -0
- package/dist/notifications/types.d.ts +162 -0
- package/dist/providers/AuthServiceProvider.d.ts +7 -0
- package/dist/providers/AuthorizationServiceProvider.d.ts +9 -0
- package/dist/providers/BroadcastServiceProvider.d.ts +7 -0
- package/dist/providers/CacheServiceProvider.d.ts +7 -0
- package/dist/providers/EncryptionServiceProvider.d.ts +7 -0
- package/dist/providers/ErrorServiceProvider.d.ts +9 -0
- package/dist/providers/EventServiceProvider.d.ts +7 -0
- package/dist/providers/HealthServiceProvider.d.ts +7 -0
- package/dist/providers/I18nServiceProvider.d.ts +27 -0
- package/dist/providers/InertiaServiceProvider.d.ts +20 -0
- package/dist/providers/LogServiceProvider.d.ts +7 -0
- package/dist/providers/MailServiceProvider.d.ts +7 -0
- package/dist/providers/NotificationServiceProvider.d.ts +8 -0
- package/dist/providers/OAuthServiceProvider.d.ts +7 -0
- package/dist/providers/QueueServiceProvider.d.ts +7 -0
- package/dist/providers/SchedulingServiceProvider.d.ts +7 -0
- package/dist/providers/StorageServiceProvider.d.ts +7 -0
- package/dist/providers/index.d.ts +17 -0
- package/dist/queue/FailedJobReporter.d.ts +40 -0
- package/dist/queue/Job.d.ts +140 -0
- package/dist/queue/QueueManager.d.ts +79 -0
- package/dist/queue/Worker.d.ts +99 -0
- package/dist/queue/drivers/MemoryDriver.d.ts +60 -0
- package/dist/queue/drivers/RedisDriver.d.ts +96 -0
- package/dist/queue/drivers/SqsDriver.d.ts +108 -0
- package/dist/queue/drivers/SyncDriver.d.ts +28 -0
- package/dist/queue/index.d.ts +9 -453
- package/dist/queue/types.d.ts +171 -0
- package/dist/redis/RedisApiTokenStore.d.ts +78 -0
- package/dist/redis/RedisEmailVerificationStore.d.ts +54 -0
- package/dist/redis/RedisOAuthStateStore.d.ts +26 -0
- package/dist/redis/RedisPasswordResetStore.d.ts +57 -0
- package/dist/redis/RedisRateLimitStore.d.ts +77 -0
- package/dist/redis/RedisSessionStore.d.ts +61 -0
- package/dist/redis/client.d.ts +41 -0
- package/dist/redis/index.d.ts +14 -356
- package/dist/redis/index.js +5 -2
- package/dist/redis/scan-keys.d.ts +6 -0
- package/dist/runtime/index.d.ts +8 -95
- package/dist/runtime/index.js +1 -1
- package/dist/scheduling/CronParser.d.ts +37 -0
- package/dist/scheduling/Schedule.d.ts +229 -0
- package/dist/scheduling/ScheduledTask.d.ts +47 -0
- package/dist/scheduling/Scheduler.d.ts +99 -0
- package/dist/scheduling/index.d.ts +5 -41
- package/dist/scheduling/types.d.ts +97 -0
- package/dist/storage/StorageManager.d.ts +65 -0
- package/dist/storage/drivers/LocalDriver.d.ts +55 -0
- package/dist/storage/drivers/MemoryDriver.d.ts +66 -0
- package/dist/storage/drivers/S3Driver.d.ts +72 -0
- package/dist/storage/index.d.ts +5 -197
- package/dist/{StorageManager-oZTHqaza.d.ts → storage/types.d.ts} +10 -77
- package/dist/support/error-polyfill.d.ts +9 -0
- package/dist/support/import-map.d.ts +13 -0
- package/dist/support/redirect-target.d.ts +11 -0
- package/dist/support/stack-frames.d.ts +56 -0
- package/dist/support/trim-slashes.d.ts +11 -0
- package/dist/vite/index.d.ts +2 -35
- package/dist/vite/index.js +0 -3
- package/dist/vite/plugin.d.ts +34 -0
- package/package.json +3 -3
- package/dist/AuthManager-DBP4KYsx.d.ts +0 -79
- package/dist/BroadcastManager-D8KoJxiV.d.ts +0 -492
- package/dist/HealthManager-DUyMIzsZ.d.ts +0 -141
- package/dist/I18nManager-BiSoczfV.d.ts +0 -275
- package/dist/LogManager-7mxnkaPM.d.ts +0 -256
- package/dist/Scheduler-pZiT8i57.d.ts +0 -471
- package/dist/api-token-D24VPr_E.d.ts +0 -663
- package/dist/app-key-CsBfRC_Q.d.ts +0 -214
- package/dist/email-verification-D60YF2ZO.d.ts +0 -329
- package/dist/index-9_Jzj5jo.d.ts +0 -7
- package/dist/validation-yAL53e1S.d.ts +0 -2610
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { ServiceFactory, ServiceBinding, ContextualBindingBuilder, ContextualBinding } from './types.js';
|
|
2
|
+
import type { ServiceBindings } from './bindings.js';
|
|
3
|
+
/**
|
|
4
|
+
* Dependency injection container with type-safe service resolution.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const container = new Container()
|
|
9
|
+
*
|
|
10
|
+
* // Register services
|
|
11
|
+
* container.singleton('events', (c) => new EventManager())
|
|
12
|
+
* container.instance('config', loadConfig())
|
|
13
|
+
*
|
|
14
|
+
* // Type-safe resolution (known bindings)
|
|
15
|
+
* const events = container.make('events') // EventManager
|
|
16
|
+
*
|
|
17
|
+
* // Generic resolution (custom bindings)
|
|
18
|
+
* const db = container.make<Database>('db')
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class Container {
|
|
22
|
+
protected bindings: Map<string, ServiceBinding>;
|
|
23
|
+
protected aliases: Map<string, string>;
|
|
24
|
+
protected tags: Map<string, Set<string>>;
|
|
25
|
+
protected contextualBindings: ContextualBinding[];
|
|
26
|
+
protected resolvingStack: string[];
|
|
27
|
+
protected scopedInstances: Map<string, unknown>[];
|
|
28
|
+
protected fakes: Map<string, unknown>;
|
|
29
|
+
/** @internal Used by ProviderManager to resolve deferred providers on demand */
|
|
30
|
+
deferredProviderLoader: ((service: string) => Promise<void>) | null;
|
|
31
|
+
/**
|
|
32
|
+
* Bind a service to the container.
|
|
33
|
+
* Each resolution creates a new instance.
|
|
34
|
+
*/
|
|
35
|
+
bind<T>(key: string, factory: ServiceFactory<T>): this;
|
|
36
|
+
/**
|
|
37
|
+
* Bind a singleton service to the container.
|
|
38
|
+
* Only one instance is created and reused.
|
|
39
|
+
*/
|
|
40
|
+
singleton<T>(key: string, factory: ServiceFactory<T>): this;
|
|
41
|
+
/**
|
|
42
|
+
* Bind an existing instance to the container.
|
|
43
|
+
*/
|
|
44
|
+
instance<T>(key: string, value: T): this;
|
|
45
|
+
/**
|
|
46
|
+
* Resolve a service from the container.
|
|
47
|
+
*
|
|
48
|
+
* Known service keys (from ServiceBindings) are automatically typed:
|
|
49
|
+
* ```typescript
|
|
50
|
+
* container.make('events') // EventManager
|
|
51
|
+
* container.make('cache') // CacheManager
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* Custom keys require an explicit type parameter:
|
|
55
|
+
* ```typescript
|
|
56
|
+
* container.make<MyService>('myService')
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
make<K extends keyof ServiceBindings>(key: K): ServiceBindings[K];
|
|
60
|
+
make<T>(key: string): T;
|
|
61
|
+
/**
|
|
62
|
+
* Resolve a service with additional parameters.
|
|
63
|
+
*/
|
|
64
|
+
makeWith<T>(key: string, params: Record<string, unknown>): T;
|
|
65
|
+
/**
|
|
66
|
+
* Check if a service is bound in the container.
|
|
67
|
+
*/
|
|
68
|
+
has(key: string): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Create an alias for a service.
|
|
71
|
+
*/
|
|
72
|
+
alias(alias: string, key: string): this;
|
|
73
|
+
/**
|
|
74
|
+
* Tag multiple services with a tag name.
|
|
75
|
+
*/
|
|
76
|
+
tag(keys: string[], tagName: string): this;
|
|
77
|
+
/**
|
|
78
|
+
* Resolve all services with a given tag.
|
|
79
|
+
*/
|
|
80
|
+
tagged<T = unknown>(tagName: string): T[];
|
|
81
|
+
/**
|
|
82
|
+
* Define a contextual binding.
|
|
83
|
+
*/
|
|
84
|
+
when(concrete: string): ContextualBindingBuilder;
|
|
85
|
+
/**
|
|
86
|
+
* Run a callback within a scoped context.
|
|
87
|
+
* Services resolved within the scope are cached and released when the scope ends.
|
|
88
|
+
*/
|
|
89
|
+
scoped<T>(callback: () => T): T;
|
|
90
|
+
/**
|
|
91
|
+
* Run an async callback within a scoped context.
|
|
92
|
+
*/
|
|
93
|
+
scopedAsync<T>(callback: () => Promise<T>): Promise<T>;
|
|
94
|
+
/**
|
|
95
|
+
* Replace a service binding with a fake instance for testing.
|
|
96
|
+
* Returns a disposable that restores the original binding when disposed.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* // Using 'using' declaration (auto-cleanup)
|
|
101
|
+
* using _ = container.fake('events', fakeEventManager)
|
|
102
|
+
*
|
|
103
|
+
* // Manual cleanup
|
|
104
|
+
* const restore = container.fake('mail', fakeMailManager)
|
|
105
|
+
* // ... run tests ...
|
|
106
|
+
* restore[Symbol.dispose]()
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
fake<K extends keyof ServiceBindings>(key: K, instance: ServiceBindings[K]): Disposable;
|
|
110
|
+
fake(key: string, instance: unknown): Disposable;
|
|
111
|
+
/**
|
|
112
|
+
* Check if a service is currently faked.
|
|
113
|
+
*/
|
|
114
|
+
isFaked(key: string): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Remove all fakes.
|
|
117
|
+
*/
|
|
118
|
+
clearFakes(): void;
|
|
119
|
+
/**
|
|
120
|
+
* Flush all resolved singleton instances.
|
|
121
|
+
*/
|
|
122
|
+
flush(): void;
|
|
123
|
+
/**
|
|
124
|
+
* Remove a binding from the container.
|
|
125
|
+
*/
|
|
126
|
+
forget(key: string): this;
|
|
127
|
+
/**
|
|
128
|
+
* Get all bound service keys.
|
|
129
|
+
*/
|
|
130
|
+
getBindings(): string[];
|
|
131
|
+
/**
|
|
132
|
+
* Get all aliases.
|
|
133
|
+
*/
|
|
134
|
+
getAliases(): Record<string, string>;
|
|
135
|
+
/**
|
|
136
|
+
* Get all tags.
|
|
137
|
+
*/
|
|
138
|
+
getTags(): Record<string, string[]>;
|
|
139
|
+
protected resolveAlias(key: string): string;
|
|
140
|
+
protected findContextualBinding(needs: string): ServiceFactory<unknown> | null;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Create a new container instance.
|
|
144
|
+
*/
|
|
145
|
+
export declare function createContainer(): Container;
|
|
146
|
+
export declare function setContainer(container: Container): void;
|
|
147
|
+
export declare function getContainer(): Container;
|
|
148
|
+
export declare function resolve<T = unknown>(key: string): T;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { Container } from './Container.js';
|
|
2
|
+
import type { Provider } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Constructor shape accepted wherever a provider class can be registered.
|
|
5
|
+
*/
|
|
6
|
+
export type ServiceProviderConstructor = new (container: Container) => ServiceProvider;
|
|
7
|
+
/**
|
|
8
|
+
* Base service provider class.
|
|
9
|
+
*
|
|
10
|
+
* Service providers are the central place of all application bootstrapping.
|
|
11
|
+
* Your own application, as well as all core services, are bootstrapped via providers.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* export class AppServiceProvider extends ServiceProvider {
|
|
16
|
+
* register(): void {
|
|
17
|
+
* // Register bindings
|
|
18
|
+
* this.container.singleton('db', (c) => new Database(c.make('config')))
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* boot(): void {
|
|
22
|
+
* // Bootstrap after all providers registered
|
|
23
|
+
* const db = this.container.make<Database>('db')
|
|
24
|
+
* db.connect()
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare abstract class ServiceProvider implements Provider {
|
|
30
|
+
protected container: Container;
|
|
31
|
+
/**
|
|
32
|
+
* Whether this provider should be deferred.
|
|
33
|
+
* Deferred providers are only loaded when one of their provided services is requested.
|
|
34
|
+
*/
|
|
35
|
+
static deferred: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The services provided by this provider (for deferred loading).
|
|
38
|
+
*/
|
|
39
|
+
static provides: string[];
|
|
40
|
+
constructor(container: Container);
|
|
41
|
+
/**
|
|
42
|
+
* Register any application services.
|
|
43
|
+
* This is called before any other providers have booted.
|
|
44
|
+
*/
|
|
45
|
+
abstract register(): void | Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Bootstrap any application services.
|
|
48
|
+
* This is called after all providers have registered.
|
|
49
|
+
*/
|
|
50
|
+
boot?(): void | Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Get the services provided by the provider.
|
|
53
|
+
*/
|
|
54
|
+
provides(): string[];
|
|
55
|
+
/**
|
|
56
|
+
* Check if this provider is deferred.
|
|
57
|
+
*/
|
|
58
|
+
isDeferred(): boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Provider manager for registering and booting providers.
|
|
62
|
+
*/
|
|
63
|
+
export declare class ProviderManager {
|
|
64
|
+
protected container: Container;
|
|
65
|
+
protected providers: ServiceProvider[];
|
|
66
|
+
protected registered: Set<ServiceProvider>;
|
|
67
|
+
protected booted: Set<ServiceProvider>;
|
|
68
|
+
protected deferredProviders: Map<string, ServiceProvider>;
|
|
69
|
+
private allBooted;
|
|
70
|
+
constructor(container: Container);
|
|
71
|
+
/**
|
|
72
|
+
* Register a provider.
|
|
73
|
+
*/
|
|
74
|
+
register(providerOrClass: ServiceProvider | ServiceProviderConstructor): this;
|
|
75
|
+
/**
|
|
76
|
+
* Register multiple providers.
|
|
77
|
+
*/
|
|
78
|
+
registerMany(providers: Array<ServiceProvider | ServiceProviderConstructor>): this;
|
|
79
|
+
/**
|
|
80
|
+
* Register all non-deferred providers.
|
|
81
|
+
*/
|
|
82
|
+
registerAll(): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Boot all registered providers.
|
|
85
|
+
*/
|
|
86
|
+
bootAll(): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Load a deferred provider for a service.
|
|
89
|
+
*/
|
|
90
|
+
loadDeferredProvider(service: string): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Check if a service is provided by a deferred provider.
|
|
93
|
+
*/
|
|
94
|
+
isDeferredService(service: string): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Get all registered providers.
|
|
97
|
+
*/
|
|
98
|
+
getProviders(): ServiceProvider[];
|
|
99
|
+
/**
|
|
100
|
+
* Get all deferred services.
|
|
101
|
+
*/
|
|
102
|
+
getDeferredServices(): string[];
|
|
103
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Hono } from 'hono';
|
|
2
|
+
import type { Application } from '../http/Application.js';
|
|
3
|
+
import type { EventManager } from '../events/index.js';
|
|
4
|
+
import type { CacheManager } from '../cache/index.js';
|
|
5
|
+
import type { QueueManager } from '../queue/index.js';
|
|
6
|
+
import type { MailManager } from '../mail/index.js';
|
|
7
|
+
import type { LogManager } from '../logging/index.js';
|
|
8
|
+
import type { I18nManager } from '../i18n/index.js';
|
|
9
|
+
import type { NotificationManager } from '../notifications/index.js';
|
|
10
|
+
import type { BroadcastManager } from '../broadcasting/index.js';
|
|
11
|
+
import type { Encrypter } from '../encryption/index.js';
|
|
12
|
+
import type { AppKeyring } from '../encryption/app-key.js';
|
|
13
|
+
import type { AuthManager } from '../auth/AuthManager.js';
|
|
14
|
+
import type { OAuthManager } from '../auth/oauth/index.js';
|
|
15
|
+
import type { StorageManager } from '../storage/index.js';
|
|
16
|
+
import type { HealthManager } from '../health/index.js';
|
|
17
|
+
import type { Scheduler } from '../scheduling/index.js';
|
|
18
|
+
import type { Gate } from '../authorization/Gate.js';
|
|
19
|
+
import type { ExceptionHandler } from '../errors/index.js';
|
|
20
|
+
import type { SharedInertiaPropsRegistry } from '../mvc/inertia/shared.js';
|
|
21
|
+
/**
|
|
22
|
+
* Type-safe service binding map.
|
|
23
|
+
*
|
|
24
|
+
* Maps service keys to their concrete types for type-safe resolution
|
|
25
|
+
* via `container.make('key')`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const events = container.make('events') // EventManager
|
|
30
|
+
* const cache = container.make('cache') // CacheManager
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export interface ServiceBindings {
|
|
34
|
+
app: Application;
|
|
35
|
+
hono: Hono;
|
|
36
|
+
events: EventManager;
|
|
37
|
+
cache: CacheManager;
|
|
38
|
+
queue: QueueManager;
|
|
39
|
+
mail: MailManager;
|
|
40
|
+
log: LogManager;
|
|
41
|
+
i18n: I18nManager;
|
|
42
|
+
notifications: NotificationManager;
|
|
43
|
+
broadcast: BroadcastManager;
|
|
44
|
+
encrypter: Encrypter;
|
|
45
|
+
'app.keyring': AppKeyring;
|
|
46
|
+
auth: AuthManager;
|
|
47
|
+
oauth: OAuthManager;
|
|
48
|
+
storage: StorageManager;
|
|
49
|
+
health: HealthManager;
|
|
50
|
+
scheduler: Scheduler;
|
|
51
|
+
gate: Gate;
|
|
52
|
+
/** Bound lazily on the first `shareInertiaProps(fn, container)` call. */
|
|
53
|
+
'inertia.sharedProps': SharedInertiaPropsRegistry;
|
|
54
|
+
'exception.handler': ExceptionHandler;
|
|
55
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { CommandClass } from '../console/types.js';
|
|
2
|
+
import type { Router } from '../mvc/Router.js';
|
|
3
|
+
import type { ServiceProviderConstructor } from './ServiceProvider.js';
|
|
4
|
+
/**
|
|
5
|
+
* Declarative definition of an application module — a self-contained
|
|
6
|
+
* `modules/<name>/` directory that can register routes and providers, per
|
|
7
|
+
* RFC 0002. Unlike `definePlugin()`, a module has no config stage and no
|
|
8
|
+
* register/boot lifecycle of its own: it's a plain descriptor bundling
|
|
9
|
+
* providers and a route registrar that `Application` folds into its own
|
|
10
|
+
* provider list and route mounting.
|
|
11
|
+
*/
|
|
12
|
+
export interface ModuleDefinition {
|
|
13
|
+
/** Diagnostic name; also the expected directory name under `modules/`. */
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* URL prefix applied to all module routes via `router.group(prefix, ...)`.
|
|
17
|
+
* Declarative on purpose — tooling can read a module's URL surface
|
|
18
|
+
* statically without executing the registrar.
|
|
19
|
+
*/
|
|
20
|
+
prefix?: string;
|
|
21
|
+
/** Route registrar, invoked after `options.routes` during boot. */
|
|
22
|
+
routes?: (router: Router) => void | Promise<void>;
|
|
23
|
+
/** Providers appended to the application's provider list. */
|
|
24
|
+
providers?: ServiceProviderConstructor[];
|
|
25
|
+
/**
|
|
26
|
+
* Console commands the module owns, exposed so the project's console
|
|
27
|
+
* entrypoint can register them without importing module internals:
|
|
28
|
+
* `kernel.registerMany(billingModule.commands)`. Nothing registers them
|
|
29
|
+
* automatically — `Application` never builds a `ConsoleKernel`, and
|
|
30
|
+
* command registration stays explicit so a bundled deployment resolves
|
|
31
|
+
* the same commands as a local checkout.
|
|
32
|
+
*/
|
|
33
|
+
commands?: CommandClass[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A module as `Application` consumes it — `providers` and `commands`
|
|
37
|
+
* normalized to always be arrays so callers don't repeat the `?? []`
|
|
38
|
+
* fallback. `commands` in particular is read by hand-written console
|
|
39
|
+
* entrypoints (`kernel.registerMany(billingModule.commands)`), where an
|
|
40
|
+
* `undefined` would be a runtime error rather than a no-op.
|
|
41
|
+
*/
|
|
42
|
+
export interface GurenModule {
|
|
43
|
+
name: string;
|
|
44
|
+
prefix?: string;
|
|
45
|
+
routes?: (router: Router) => void | Promise<void>;
|
|
46
|
+
providers: ServiceProviderConstructor[];
|
|
47
|
+
commands: CommandClass[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Define a Guren application module without boilerplate.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* // modules/billing/index.ts
|
|
55
|
+
* export const billingModule = defineModule({
|
|
56
|
+
* name: 'billing',
|
|
57
|
+
* prefix: '/billing',
|
|
58
|
+
* routes: registerBillingRoutes,
|
|
59
|
+
* providers: [BillingServiceProvider],
|
|
60
|
+
* commands: [InvoiceCommand],
|
|
61
|
+
* })
|
|
62
|
+
*
|
|
63
|
+
* // src/app.ts
|
|
64
|
+
* createApp({ routes, providers, modules: [billingModule] })
|
|
65
|
+
*
|
|
66
|
+
* // src/console.ts
|
|
67
|
+
* kernel.registerMany(billingModule.commands)
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function defineModule(definition: ModuleDefinition): GurenModule;
|
|
71
|
+
/**
|
|
72
|
+
* Runs a module's route registrar against `router`, applying its `prefix`
|
|
73
|
+
* via `router.group()` when set. Shared by `Application.mountRoutes()` (at
|
|
74
|
+
* boot) and the CLI's route loader (for `guren codegen`/`audit`/`routes`/
|
|
75
|
+
* `openapi:generate`, which need the same route set without booting a real
|
|
76
|
+
* app) so both stay in sync — a bugfix to one path fixes the other.
|
|
77
|
+
*
|
|
78
|
+
* `router.group(prefix, callback)`'s callback is synchronous — it pushes
|
|
79
|
+
* the prefix, invokes the callback, then pops it, with no support for
|
|
80
|
+
* awaiting inside. Capturing the registrar's return value and awaiting it
|
|
81
|
+
* after `group()` returns preserves prefixing for the common case (a
|
|
82
|
+
* synchronous registrar, or an async one that calls `router.get`/`post`/
|
|
83
|
+
* etc. before its first `await`); route calls after an `await` inside an
|
|
84
|
+
* async, prefixed module registrar would run with the prefix already
|
|
85
|
+
* popped. Registrars with no prefix don't go through group() and have no
|
|
86
|
+
* such limitation.
|
|
87
|
+
*/
|
|
88
|
+
export declare function mountModuleRoutes(router: Router, gurenModule: GurenModule): Promise<void>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Container } from './Container.js';
|
|
2
|
+
import { type ServiceProviderConstructor } from './ServiceProvider.js';
|
|
3
|
+
/**
|
|
4
|
+
* Declarative definition of a plugin's lifecycle hooks.
|
|
5
|
+
*
|
|
6
|
+
* `register` and `boot` mirror the ServiceProvider hooks and receive the
|
|
7
|
+
* container plus the configuration captured by the plugin factory.
|
|
8
|
+
*/
|
|
9
|
+
export interface PluginDefinition<TConfig = void> {
|
|
10
|
+
/**
|
|
11
|
+
* Diagnostic name for the plugin (e.g. 'analytics').
|
|
12
|
+
* Used to derive the generated provider class name.
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* Register services into the container.
|
|
17
|
+
* Called before any provider has booted.
|
|
18
|
+
*/
|
|
19
|
+
register(container: Container, config: TConfig): void | Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Bootstrap after all providers have registered.
|
|
22
|
+
*/
|
|
23
|
+
boot?(container: Container, config: TConfig): void | Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Defer instantiation until one of the `provides` services is resolved.
|
|
26
|
+
* Maps to `ServiceProvider.deferred`.
|
|
27
|
+
*/
|
|
28
|
+
deferred?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Services bound by this plugin (required when `deferred` is true).
|
|
31
|
+
* Maps to `ServiceProvider.provides`.
|
|
32
|
+
*/
|
|
33
|
+
provides?: string[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A factory returned by `definePlugin()`. Each call produces an independent
|
|
37
|
+
* ServiceProvider subclass with the given configuration captured in a closure.
|
|
38
|
+
*/
|
|
39
|
+
export type PluginFactory<TConfig = void> = (config: TConfig) => ServiceProviderConstructor;
|
|
40
|
+
/**
|
|
41
|
+
* Define a configurable Guren plugin without ServiceProvider boilerplate.
|
|
42
|
+
*
|
|
43
|
+
* Unlike storing configuration on a static class property, each factory call
|
|
44
|
+
* returns a fresh provider class, so the same plugin can be registered twice
|
|
45
|
+
* with different configurations.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* export const analyticsPlugin = definePlugin<AnalyticsConfig>({
|
|
50
|
+
* name: 'analytics',
|
|
51
|
+
* register(container, config) {
|
|
52
|
+
* container.singleton('analytics', () => new AnalyticsClient(config))
|
|
53
|
+
* },
|
|
54
|
+
* })
|
|
55
|
+
*
|
|
56
|
+
* // In the application:
|
|
57
|
+
* createApp({
|
|
58
|
+
* providers: [analyticsPlugin({ apiKey: process.env.ANALYTICS_API_KEY! })],
|
|
59
|
+
* })
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function definePlugin<TConfig = void>(definition: PluginDefinition<TConfig>): PluginFactory<TConfig>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { ServiceFactory, ServiceClass, ServiceBinding, ContextualBindingBuilder, ContextualNeedsBuilder, ContextualBinding, ServiceProviderOptions, Provider, ServiceProviderClass, } from './types.js';
|
|
2
|
+
export type { ServiceBindings } from './bindings.js';
|
|
3
|
+
export { Container, createContainer, setContainer, getContainer, resolve, } from './Container.js';
|
|
4
|
+
export { ServiceProvider, ProviderManager } from './ServiceProvider.js';
|
|
5
|
+
export { definePlugin } from './definePlugin.js';
|
|
6
|
+
export type { PluginDefinition, PluginFactory } from './definePlugin.js';
|
|
7
|
+
export { defineModule, mountModuleRoutes } from './defineModule.js';
|
|
8
|
+
export type { ModuleDefinition, GurenModule } from './defineModule.js';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Container } from './Container.js';
|
|
2
|
+
/**
|
|
3
|
+
* Structural type for DI containers, avoiding a hard dependency on Container
|
|
4
|
+
* where only resolution is needed (controllers, Inertia shared props).
|
|
5
|
+
*/
|
|
6
|
+
export interface ContainerLike {
|
|
7
|
+
make(key: string): unknown;
|
|
8
|
+
has?(key: string): boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Service factory function.
|
|
12
|
+
*/
|
|
13
|
+
export type ServiceFactory<T> = (container: Container) => T;
|
|
14
|
+
/**
|
|
15
|
+
* Service class constructor.
|
|
16
|
+
*/
|
|
17
|
+
export type ServiceClass<T> = new (...args: unknown[]) => T;
|
|
18
|
+
/**
|
|
19
|
+
* Service binding configuration.
|
|
20
|
+
*/
|
|
21
|
+
export interface ServiceBinding {
|
|
22
|
+
factory: ServiceFactory<unknown>;
|
|
23
|
+
singleton: boolean;
|
|
24
|
+
instance?: unknown;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Contextual binding builder interface.
|
|
28
|
+
*/
|
|
29
|
+
export interface ContextualBindingBuilder {
|
|
30
|
+
needs(abstract: string): ContextualNeedsBuilder;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Contextual needs builder interface.
|
|
34
|
+
*/
|
|
35
|
+
export interface ContextualNeedsBuilder {
|
|
36
|
+
give<T>(factory: ServiceFactory<T> | T): void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Contextual binding configuration.
|
|
40
|
+
*/
|
|
41
|
+
export interface ContextualBinding {
|
|
42
|
+
concrete: string;
|
|
43
|
+
needs: string;
|
|
44
|
+
factory: ServiceFactory<unknown>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Service provider options.
|
|
48
|
+
*/
|
|
49
|
+
export interface ServiceProviderOptions {
|
|
50
|
+
/**
|
|
51
|
+
* Whether this provider should be deferred.
|
|
52
|
+
*/
|
|
53
|
+
deferred?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Services this provider provides (for deferred loading).
|
|
56
|
+
*/
|
|
57
|
+
provides?: string[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Provider interface for container-based service providers.
|
|
61
|
+
*/
|
|
62
|
+
export interface Provider {
|
|
63
|
+
register?(context: unknown): void | Promise<void>;
|
|
64
|
+
boot?(context: unknown): void | Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Service provider class type.
|
|
68
|
+
*/
|
|
69
|
+
export interface ServiceProviderClass {
|
|
70
|
+
new (container: Container): Provider;
|
|
71
|
+
deferred?: boolean;
|
|
72
|
+
provides?: string[];
|
|
73
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State definition for factories.
|
|
3
|
+
*/
|
|
4
|
+
type StateDefinition<T> = Partial<T> | ((attributes: Partial<T>) => Partial<T>);
|
|
5
|
+
/**
|
|
6
|
+
* Abstract base class for model factories.
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class BaseFactory<T> {
|
|
9
|
+
private _sequence;
|
|
10
|
+
private _states;
|
|
11
|
+
private _activeStates;
|
|
12
|
+
private _afterCreatingCallbacks;
|
|
13
|
+
private _afterMakingCallbacks;
|
|
14
|
+
/**
|
|
15
|
+
* Get the current sequence number.
|
|
16
|
+
*/
|
|
17
|
+
protected get sequence(): number;
|
|
18
|
+
/**
|
|
19
|
+
* Define the default attributes for the model.
|
|
20
|
+
*/
|
|
21
|
+
abstract definition(): Partial<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Create a model instance (to be overridden for persistence).
|
|
24
|
+
*/
|
|
25
|
+
protected persist(attributes: Partial<T>): Promise<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Define a state.
|
|
28
|
+
*/
|
|
29
|
+
state(name: string, state: StateDefinition<T>): this;
|
|
30
|
+
/**
|
|
31
|
+
* Apply a state to the factory.
|
|
32
|
+
*/
|
|
33
|
+
withState(name: string): this;
|
|
34
|
+
/**
|
|
35
|
+
* Apply multiple states.
|
|
36
|
+
*/
|
|
37
|
+
withStates(...names: string[]): this;
|
|
38
|
+
/**
|
|
39
|
+
* Register a callback to run after creating.
|
|
40
|
+
*/
|
|
41
|
+
afterCreating(callback: (model: T) => void | Promise<void>): this;
|
|
42
|
+
/**
|
|
43
|
+
* Register a callback to run after making.
|
|
44
|
+
*/
|
|
45
|
+
afterMaking(callback: (model: T) => void | Promise<void>): this;
|
|
46
|
+
/**
|
|
47
|
+
* Make a model instance without persisting.
|
|
48
|
+
*/
|
|
49
|
+
make(overrides?: Partial<T>): T;
|
|
50
|
+
/**
|
|
51
|
+
* Make multiple model instances without persisting.
|
|
52
|
+
*/
|
|
53
|
+
makeMany(count: number, overrides?: Partial<T>): T[];
|
|
54
|
+
/**
|
|
55
|
+
* Create and persist a model instance.
|
|
56
|
+
*/
|
|
57
|
+
create(overrides?: Partial<T>): Promise<T>;
|
|
58
|
+
/**
|
|
59
|
+
* Create and persist multiple model instances.
|
|
60
|
+
*/
|
|
61
|
+
createMany(count: number, overrides?: Partial<T>): Promise<T[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Reset the sequence counter.
|
|
64
|
+
*/
|
|
65
|
+
resetSequence(): this;
|
|
66
|
+
/**
|
|
67
|
+
* Clear active states.
|
|
68
|
+
*/
|
|
69
|
+
clearStates(): this;
|
|
70
|
+
/**
|
|
71
|
+
* Create a new factory instance with fresh state.
|
|
72
|
+
*/
|
|
73
|
+
fresh(): this;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Alias for BaseFactory.
|
|
77
|
+
*/
|
|
78
|
+
export { BaseFactory as Factory };
|
|
79
|
+
/**
|
|
80
|
+
* Helper to create a simple factory with a definition function.
|
|
81
|
+
*/
|
|
82
|
+
export declare function defineFactory<T>(definition: (sequence: number) => Partial<T>, persist?: (attributes: Partial<T>) => Promise<T>): BaseFactory<T>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SeederClass } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reset called seeders tracking (for testing).
|
|
4
|
+
*/
|
|
5
|
+
export declare function resetCalledSeeders(): void;
|
|
6
|
+
/**
|
|
7
|
+
* Abstract base class for database seeders.
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class BaseSeeder {
|
|
10
|
+
/**
|
|
11
|
+
* Run the seeder.
|
|
12
|
+
*/
|
|
13
|
+
abstract run(): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Call another seeder.
|
|
16
|
+
*/
|
|
17
|
+
protected call(SeederClass: SeederClass): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Call another seeder only once.
|
|
20
|
+
* Useful for avoiding duplicate data when seeders have dependencies.
|
|
21
|
+
*/
|
|
22
|
+
protected callOnce(SeederClass: SeederClass): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Call multiple seeders in sequence.
|
|
25
|
+
*/
|
|
26
|
+
protected callMany(seeders: SeederClass[]): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Call multiple seeders in parallel.
|
|
29
|
+
*/
|
|
30
|
+
protected callParallel(seeders: SeederClass[]): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Alias for BaseSeeder.
|
|
34
|
+
*/
|
|
35
|
+
export { BaseSeeder as Seeder };
|