@orchestr-sh/orchestr 1.0.1

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 (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +344 -0
  3. package/dist/Container/Container.d.ts +90 -0
  4. package/dist/Container/Container.d.ts.map +1 -0
  5. package/dist/Container/Container.js +193 -0
  6. package/dist/Container/Container.js.map +1 -0
  7. package/dist/Facades/Route.d.ts +20 -0
  8. package/dist/Facades/Route.d.ts.map +1 -0
  9. package/dist/Facades/Route.js +50 -0
  10. package/dist/Facades/Route.js.map +1 -0
  11. package/dist/Foundation/Application.d.ts +97 -0
  12. package/dist/Foundation/Application.d.ts.map +1 -0
  13. package/dist/Foundation/Application.js +184 -0
  14. package/dist/Foundation/Application.js.map +1 -0
  15. package/dist/Foundation/Http/Kernel.d.ts +50 -0
  16. package/dist/Foundation/Http/Kernel.d.ts.map +1 -0
  17. package/dist/Foundation/Http/Kernel.js +122 -0
  18. package/dist/Foundation/Http/Kernel.js.map +1 -0
  19. package/dist/Foundation/ServiceProvider.d.ts +24 -0
  20. package/dist/Foundation/ServiceProvider.d.ts.map +1 -0
  21. package/dist/Foundation/ServiceProvider.js +15 -0
  22. package/dist/Foundation/ServiceProvider.js.map +1 -0
  23. package/dist/Providers/RouteServiceProvider.d.ts +9 -0
  24. package/dist/Providers/RouteServiceProvider.d.ts.map +1 -0
  25. package/dist/Providers/RouteServiceProvider.js +22 -0
  26. package/dist/Providers/RouteServiceProvider.js.map +1 -0
  27. package/dist/Routing/Controller.d.ts +17 -0
  28. package/dist/Routing/Controller.d.ts.map +1 -0
  29. package/dist/Routing/Controller.js +26 -0
  30. package/dist/Routing/Controller.js.map +1 -0
  31. package/dist/Routing/Request.d.ts +109 -0
  32. package/dist/Routing/Request.d.ts.map +1 -0
  33. package/dist/Routing/Request.js +212 -0
  34. package/dist/Routing/Request.js.map +1 -0
  35. package/dist/Routing/Response.d.ts +78 -0
  36. package/dist/Routing/Response.d.ts.map +1 -0
  37. package/dist/Routing/Response.js +174 -0
  38. package/dist/Routing/Response.js.map +1 -0
  39. package/dist/Routing/Route.d.ts +51 -0
  40. package/dist/Routing/Route.d.ts.map +1 -0
  41. package/dist/Routing/Route.js +94 -0
  42. package/dist/Routing/Route.js.map +1 -0
  43. package/dist/Routing/Router.d.ts +114 -0
  44. package/dist/Routing/Router.d.ts.map +1 -0
  45. package/dist/Routing/Router.js +216 -0
  46. package/dist/Routing/Router.js.map +1 -0
  47. package/dist/Support/Facade.d.ts +44 -0
  48. package/dist/Support/Facade.d.ts.map +1 -0
  49. package/dist/Support/Facade.js +101 -0
  50. package/dist/Support/Facade.js.map +1 -0
  51. package/dist/index.d.ts +20 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +37 -0
  54. package/dist/index.js.map +1 -0
  55. package/package.json +57 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sam Street
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,344 @@
1
+ # Laravel-Next
2
+
3
+ A 1:1 Laravel replica built in TypeScript. Brings Laravel's elegant syntax and architecture to the TypeScript/Node.js ecosystem.
4
+
5
+ ## Features
6
+
7
+ Built from the ground up with Laravel's core components:
8
+
9
+ - **Service Container** - Full IoC container with dependency injection and reflection
10
+ - **Service Providers** - Bootstrap and register services
11
+ - **HTTP Router** - Laravel-style routing with parameter binding
12
+ - **Request/Response** - Elegant HTTP abstractions
13
+ - **Middleware** - Global and route-level middleware pipeline
14
+ - **Controllers** - MVC architecture support
15
+ - **Facades** - Static proxy access to services
16
+ - **Application Lifecycle** - Complete Laravel bootstrap process
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install orchestr reflect-metadata
22
+ ```
23
+
24
+ **Note**: `reflect-metadata` is required for dependency injection to work.
25
+
26
+ ## Quick Start
27
+
28
+ ```typescript
29
+ import 'reflect-metadata'; // Must be first!
30
+ import { Application, Kernel, RouteServiceProvider, Route } from 'orchestr';
31
+
32
+ // Create application
33
+ const app = new Application(__dirname);
34
+
35
+ // Register providers
36
+ app.register(RouteServiceProvider);
37
+ app.boot();
38
+
39
+ // Create HTTP kernel
40
+ const kernel = new Kernel(app);
41
+
42
+ // Define routes
43
+ Route.get('/', async (req, res) => {
44
+ return res.json({ message: 'Hello from Laravel-Next!' });
45
+ });
46
+
47
+ Route.get('/users/:id', async (req, res) => {
48
+ const id = req.routeParam('id');
49
+ return res.json({ user: { id, name: 'John Doe' } });
50
+ });
51
+
52
+ Route.post('/users', async (req, res) => {
53
+ const data = req.only(['name', 'email']);
54
+ return res.status(201).json({ user: data });
55
+ });
56
+
57
+ // Start server
58
+ kernel.listen(3000);
59
+ ```
60
+
61
+ ## Core Concepts
62
+
63
+ ### Service Container
64
+
65
+ Laravel's IoC container provides powerful dependency injection:
66
+
67
+ ```typescript
68
+ // Bind a service
69
+ app.bind('UserService', () => new UserService());
70
+
71
+ // Bind a singleton
72
+ app.singleton('Database', () => new Database());
73
+
74
+ // Resolve from container
75
+ const userService = app.make('UserService');
76
+ ```
77
+
78
+ ### Service Providers
79
+
80
+ Organize service registration and bootstrapping:
81
+
82
+ ```typescript
83
+ class AppServiceProvider extends ServiceProvider {
84
+ register(): void {
85
+ this.app.singleton('config', () => ({ /* config */ }));
86
+ }
87
+
88
+ boot(): void {
89
+ // Bootstrap code
90
+ }
91
+ }
92
+
93
+ app.register(AppServiceProvider);
94
+ ```
95
+
96
+ ### Routing
97
+
98
+ Laravel-style routing with full parameter support:
99
+
100
+ ```typescript
101
+ // Simple routes
102
+ Route.get('/users', handler);
103
+ Route.post('/users', handler);
104
+ Route.put('/users/:id', handler);
105
+ Route.delete('/users/:id', handler);
106
+
107
+ // Route parameters
108
+ Route.get('/users/:id/posts/:postId', async (req, res) => {
109
+ const userId = req.routeParam('id');
110
+ const postId = req.routeParam('postId');
111
+ });
112
+
113
+ // Route groups
114
+ Route.group({ prefix: 'api/v1', middleware: authMiddleware }, () => {
115
+ Route.get('/profile', handler);
116
+ Route.post('/posts', handler);
117
+ });
118
+
119
+ // Named routes
120
+ const route = Route.get('/users', handler);
121
+ route.setName('users.index');
122
+ ```
123
+
124
+ ### Middleware
125
+
126
+ Global and route-level middleware:
127
+
128
+ ```typescript
129
+ // Global middleware
130
+ kernel.use(async (req, res, next) => {
131
+ console.log(`${req.method} ${req.path}`);
132
+ await next();
133
+ });
134
+
135
+ // Route middleware
136
+ const authMiddleware = async (req, res, next) => {
137
+ if (!req.header('authorization')) {
138
+ return res.status(401).json({ message: 'Unauthorized' });
139
+ }
140
+ await next();
141
+ };
142
+
143
+ Route.get('/profile', handler).addMiddleware(authMiddleware);
144
+ ```
145
+
146
+ ### Controllers
147
+
148
+ MVC pattern with base controller:
149
+
150
+ ```typescript
151
+ class UserController extends Controller {
152
+ async index(req: Request, res: Response) {
153
+ return res.json({ users: [] });
154
+ }
155
+
156
+ async show(req: Request, res: Response) {
157
+ const id = req.routeParam('id');
158
+ return res.json({ user: { id } });
159
+ }
160
+
161
+ async store(req: Request, res: Response) {
162
+ const validated = await this.validate(req, {
163
+ name: 'required',
164
+ email: 'required|email',
165
+ });
166
+ return res.status(201).json({ user: validated });
167
+ }
168
+ }
169
+ ```
170
+
171
+ ### Request
172
+
173
+ Powerful request helper methods:
174
+
175
+ ```typescript
176
+ // Get input
177
+ req.input('name');
178
+ req.get('email', 'default@example.com');
179
+
180
+ // Get all inputs
181
+ req.all();
182
+
183
+ // Get specific inputs
184
+ req.only(['name', 'email']);
185
+ req.except(['password']);
186
+
187
+ // Check input existence
188
+ req.has('name');
189
+ req.filled('email');
190
+
191
+ // Route parameters
192
+ req.routeParam('id');
193
+
194
+ // Headers
195
+ req.header('content-type');
196
+ req.expectsJson();
197
+ req.ajax();
198
+
199
+ // Request info
200
+ req.method;
201
+ req.path;
202
+ req.ip();
203
+ ```
204
+
205
+ ### Response
206
+
207
+ Fluent response building:
208
+
209
+ ```typescript
210
+ // JSON responses
211
+ res.json({ data: [] });
212
+ res.status(201).json({ created: true });
213
+
214
+ // Headers
215
+ res.header('X-Custom', 'value');
216
+ res.headers({ 'X-A': 'a', 'X-B': 'b' });
217
+
218
+ // Cookies
219
+ res.cookie('token', 'value', { httpOnly: true, maxAge: 3600 });
220
+
221
+ // Redirects
222
+ res.redirect('/home');
223
+ res.redirect('/login', 301);
224
+
225
+ // Downloads
226
+ res.download(buffer, 'file.pdf');
227
+
228
+ // Views (simplified)
229
+ res.view('welcome', { name: 'John' });
230
+ ```
231
+
232
+ ### Facades
233
+
234
+ Static access to services:
235
+
236
+ ```typescript
237
+ import { Route } from 'orchestr';
238
+
239
+ // Route facade provides static access to Router
240
+ Route.get('/path', handler);
241
+ Route.post('/path', handler);
242
+ Route.group({ prefix: 'api' }, () => {
243
+ // ...
244
+ });
245
+ ```
246
+
247
+ ## Example Application
248
+
249
+ Run the example application:
250
+
251
+ ```bash
252
+ npm run dev
253
+ ```
254
+
255
+ Visit `http://localhost:3000` to see it in action.
256
+
257
+ Available routes in the example:
258
+ - `GET /` - Welcome message
259
+ - `GET /users/:id` - Get user by ID
260
+ - `GET /search?q=query` - Search with query params
261
+ - `POST /users` - Create user
262
+ - `GET /api/v1/profile` - Protected route (requires auth header)
263
+ - `POST /api/v1/posts` - Create post (protected)
264
+ - `GET /posts/:postId/comments/:commentId` - Nested parameters
265
+
266
+ ## Architecture
267
+
268
+ Laravel-Next follows Laravel's architecture exactly:
269
+
270
+ ```
271
+ src/
272
+ ├── Container/
273
+ │ └── Container.ts # IoC Container with DI
274
+ ├── Foundation/
275
+ │ ├── Application.ts # Core application class
276
+ │ ├── ServiceProvider.ts # Service provider base
277
+ │ └── Http/
278
+ │ └── Kernel.ts # HTTP kernel
279
+ ├── Routing/
280
+ │ ├── Router.ts # Route registration and dispatch
281
+ │ ├── Route.ts # Individual route
282
+ │ ├── Request.ts # HTTP request wrapper
283
+ │ ├── Response.ts # HTTP response wrapper
284
+ │ └── Controller.ts # Base controller
285
+ ├── Support/
286
+ │ └── Facade.ts # Facade base class
287
+ ├── Facades/
288
+ │ └── Route.ts # Route facade
289
+ └── Providers/
290
+ └── RouteServiceProvider.ts
291
+ ```
292
+
293
+ ## TypeScript Benefits
294
+
295
+ While maintaining Laravel's API, you get:
296
+
297
+ - **Type Safety** - Full TypeScript type checking
298
+ - **Better IDE Support** - Autocomplete and IntelliSense
299
+ - **Reflection** - Automatic dependency injection
300
+ - **Modern Async** - Native async/await support
301
+ - **Performance** - Compiled JavaScript performance
302
+
303
+ ## Roadmap
304
+
305
+ This is the core foundation. Next components to build:
306
+
307
+ - [ ] Database Query Builder
308
+ - [ ] Eloquent ORM
309
+ - [ ] Validation System
310
+ - [ ] Authentication & Authorization
311
+ - [ ] Queue System
312
+ - [ ] Events & Listeners
313
+ - [ ] File Storage
314
+ - [ ] Cache System
315
+ - [ ] Template Engine (Blade equivalent)
316
+ - [ ] CLI/Artisan equivalent
317
+ - [ ] Testing utilities
318
+
319
+ ## Comparison to Laravel
320
+
321
+ | Feature | Laravel | Orchestr |
322
+ |---------|---------|----------|
323
+ | Service Container | ✅ | ✅ |
324
+ | Service Providers | ✅ | ✅ |
325
+ | Routing | ✅ | ✅ |
326
+ | Middleware | ✅ | ✅ |
327
+ | Controllers | ✅ | ✅ |
328
+ | Request/Response | ✅ | ✅ |
329
+ | Facades | ✅ | ✅ |
330
+ | Eloquent ORM | ✅ | 🚧 |
331
+ | Query Builder | ✅ | 🚧 |
332
+ | Validation | ✅ | 🚧 |
333
+ | Authentication | ✅ | 🚧 |
334
+ | Authorization | ✅ | 🚧 |
335
+ | Events | ✅ | 🚧 |
336
+ | Queues | ✅ | 🚧 |
337
+ | Cache | ✅ | 🚧 |
338
+ | File Storage | ✅ | 🚧 |
339
+ | Mail | ✅ | 🚧 |
340
+ | Notifications | ✅ | 🚧 |
341
+
342
+ ## License
343
+
344
+ MIT
@@ -0,0 +1,90 @@
1
+ import 'reflect-metadata';
2
+ export type Abstract = string | symbol | Function;
3
+ export type Concrete<T = any> = ((container: Container) => T) | (new (...args: any[]) => T);
4
+ export type Binding = {
5
+ concrete: Concrete;
6
+ shared: boolean;
7
+ };
8
+ /**
9
+ * Service Container - Laravel's IoC Container
10
+ * Handles dependency injection and service resolution
11
+ */
12
+ export declare class Container {
13
+ private bindings;
14
+ private instances;
15
+ private aliases;
16
+ private resolvedTypes;
17
+ /**
18
+ * Register a binding with the container
19
+ * Laravel: $app->bind(abstract, concrete)
20
+ */
21
+ bind<T>(abstract: Abstract, concrete?: Concrete<T> | null, shared?: boolean): void;
22
+ /**
23
+ * Register a shared binding (singleton) in the container
24
+ * Laravel: $app->singleton(abstract, concrete)
25
+ */
26
+ singleton<T>(abstract: Abstract, concrete?: Concrete<T> | null): void;
27
+ /**
28
+ * Register an existing instance as shared in the container
29
+ * Laravel: $app->instance(abstract, instance)
30
+ */
31
+ instance<T>(abstract: Abstract, instance: T): T;
32
+ /**
33
+ * Alias a type to a different name
34
+ * Laravel: $app->alias(abstract, alias)
35
+ */
36
+ alias(abstract: Abstract, alias: Abstract): void;
37
+ /**
38
+ * Resolve the given type from the container
39
+ * Laravel: $app->make(abstract)
40
+ */
41
+ make<T>(abstract: Abstract, parameters?: any[]): T;
42
+ /**
43
+ * Resolve the given type from the container
44
+ */
45
+ private resolve;
46
+ /**
47
+ * Get the concrete type for a given abstract
48
+ */
49
+ private getConcrete;
50
+ /**
51
+ * Get the alias for an abstract if available
52
+ */
53
+ private getAlias;
54
+ /**
55
+ * Determine if the given concrete is buildable
56
+ */
57
+ private isBuildable;
58
+ /**
59
+ * Determine if a given type is shared
60
+ */
61
+ private isShared;
62
+ /**
63
+ * Instantiate a concrete instance of the given type
64
+ * Uses reflection to resolve constructor dependencies
65
+ */
66
+ private build;
67
+ /**
68
+ * Resolve all dependencies for a class constructor
69
+ * Uses TypeScript's reflect-metadata to get parameter types
70
+ */
71
+ private resolveDependencies;
72
+ /**
73
+ * Determine if the given abstract type has been bound
74
+ */
75
+ bound(abstract: Abstract): boolean;
76
+ /**
77
+ * Determine if the given abstract type has been resolved
78
+ */
79
+ resolved(abstract: Abstract): boolean;
80
+ /**
81
+ * Flush the container of all bindings and resolved instances
82
+ */
83
+ flush(): void;
84
+ /**
85
+ * Call the given Closure / class@method and inject its dependencies
86
+ * Laravel: $app->call(callable)
87
+ */
88
+ call(callback: Function, parameters?: any[]): any;
89
+ }
90
+ //# sourceMappingURL=Container.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Container.d.ts","sourceRoot":"","sources":["../../src/Container/Container.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAClD,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,SAAS,EAAE,SAAS,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,IAA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IAIlC;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO;IAKrC;;OAEG;IACH,KAAK,IAAI,IAAI;IAOb;;;OAGG;IACH,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,GAAE,GAAG,EAAO,GAAG,GAAG;CAWtD"}
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Container = void 0;
4
+ require("reflect-metadata");
5
+ /**
6
+ * Service Container - Laravel's IoC Container
7
+ * Handles dependency injection and service resolution
8
+ */
9
+ class Container {
10
+ bindings = new Map();
11
+ instances = new Map();
12
+ aliases = new Map();
13
+ resolvedTypes = new Map();
14
+ /**
15
+ * Register a binding with the container
16
+ * Laravel: $app->bind(abstract, concrete)
17
+ */
18
+ bind(abstract, concrete = null, shared = false) {
19
+ if (concrete === null) {
20
+ concrete = abstract;
21
+ }
22
+ this.bindings.set(abstract, { concrete, shared });
23
+ // If already resolved and not shared, clear the instance
24
+ if (this.resolvedTypes.has(abstract) && !shared) {
25
+ this.instances.delete(abstract);
26
+ this.resolvedTypes.delete(abstract);
27
+ }
28
+ }
29
+ /**
30
+ * Register a shared binding (singleton) in the container
31
+ * Laravel: $app->singleton(abstract, concrete)
32
+ */
33
+ singleton(abstract, concrete = null) {
34
+ this.bind(abstract, concrete, true);
35
+ }
36
+ /**
37
+ * Register an existing instance as shared in the container
38
+ * Laravel: $app->instance(abstract, instance)
39
+ */
40
+ instance(abstract, instance) {
41
+ this.instances.set(abstract, instance);
42
+ this.bindings.set(abstract, {
43
+ concrete: () => instance,
44
+ shared: true,
45
+ });
46
+ return instance;
47
+ }
48
+ /**
49
+ * Alias a type to a different name
50
+ * Laravel: $app->alias(abstract, alias)
51
+ */
52
+ alias(abstract, alias) {
53
+ this.aliases.set(alias, abstract);
54
+ }
55
+ /**
56
+ * Resolve the given type from the container
57
+ * Laravel: $app->make(abstract)
58
+ */
59
+ make(abstract, parameters = []) {
60
+ return this.resolve(abstract, parameters);
61
+ }
62
+ /**
63
+ * Resolve the given type from the container
64
+ */
65
+ resolve(abstract, parameters = []) {
66
+ // Get the real abstract if this is an alias
67
+ abstract = this.getAlias(abstract);
68
+ // If we have a shared instance, return it
69
+ if (this.instances.has(abstract)) {
70
+ return this.instances.get(abstract);
71
+ }
72
+ // Get the concrete implementation
73
+ const concrete = this.getConcrete(abstract);
74
+ // Build the concrete type
75
+ let object;
76
+ if (this.isBuildable(concrete, abstract)) {
77
+ object = this.build(concrete, parameters);
78
+ }
79
+ else {
80
+ object = this.make(concrete, parameters);
81
+ }
82
+ // If the binding is shared, store the instance
83
+ if (this.isShared(abstract)) {
84
+ this.instances.set(abstract, object);
85
+ }
86
+ this.resolvedTypes.set(abstract, true);
87
+ return object;
88
+ }
89
+ /**
90
+ * Get the concrete type for a given abstract
91
+ */
92
+ getConcrete(abstract) {
93
+ const binding = this.bindings.get(abstract);
94
+ if (binding) {
95
+ return binding.concrete;
96
+ }
97
+ // If no binding exists, assume the abstract is the concrete
98
+ return abstract;
99
+ }
100
+ /**
101
+ * Get the alias for an abstract if available
102
+ */
103
+ getAlias(abstract) {
104
+ return this.aliases.has(abstract) ? this.getAlias(this.aliases.get(abstract)) : abstract;
105
+ }
106
+ /**
107
+ * Determine if the given concrete is buildable
108
+ */
109
+ isBuildable(concrete, abstract) {
110
+ return concrete === abstract || typeof concrete === 'function';
111
+ }
112
+ /**
113
+ * Determine if a given type is shared
114
+ */
115
+ isShared(abstract) {
116
+ const binding = this.bindings.get(abstract);
117
+ return binding ? binding.shared : false;
118
+ }
119
+ /**
120
+ * Instantiate a concrete instance of the given type
121
+ * Uses reflection to resolve constructor dependencies
122
+ */
123
+ build(concrete, parameters = []) {
124
+ // If concrete is a function (factory), call it
125
+ if (typeof concrete === 'function' && concrete.prototype === undefined) {
126
+ return concrete(this);
127
+ }
128
+ // If concrete is a class, use reflection to get dependencies
129
+ if (typeof concrete === 'function') {
130
+ const dependencies = this.resolveDependencies(concrete, parameters);
131
+ return new concrete(...dependencies);
132
+ }
133
+ throw new Error(`Target [${String(concrete)}] is not instantiable.`);
134
+ }
135
+ /**
136
+ * Resolve all dependencies for a class constructor
137
+ * Uses TypeScript's reflect-metadata to get parameter types
138
+ */
139
+ resolveDependencies(concrete, parameters = []) {
140
+ const paramTypes = Reflect.getMetadata('design:paramtypes', concrete) || [];
141
+ return paramTypes.map((paramType, index) => {
142
+ // If parameter was provided explicitly, use it
143
+ if (parameters[index] !== undefined) {
144
+ return parameters[index];
145
+ }
146
+ // If no type information, throw error
147
+ if (!paramType || paramType === Object) {
148
+ throw new Error(`Cannot resolve dependency at position ${index} for ${concrete.name}. ` +
149
+ `Make sure TypeScript decorators are enabled and the class has proper type hints.`);
150
+ }
151
+ // Resolve the dependency from the container
152
+ return this.make(paramType);
153
+ });
154
+ }
155
+ /**
156
+ * Determine if the given abstract type has been bound
157
+ */
158
+ bound(abstract) {
159
+ return this.bindings.has(abstract) || this.instances.has(abstract) || this.aliases.has(abstract);
160
+ }
161
+ /**
162
+ * Determine if the given abstract type has been resolved
163
+ */
164
+ resolved(abstract) {
165
+ abstract = this.getAlias(abstract);
166
+ return this.resolvedTypes.has(abstract) || this.instances.has(abstract);
167
+ }
168
+ /**
169
+ * Flush the container of all bindings and resolved instances
170
+ */
171
+ flush() {
172
+ this.bindings.clear();
173
+ this.instances.clear();
174
+ this.aliases.clear();
175
+ this.resolvedTypes.clear();
176
+ }
177
+ /**
178
+ * Call the given Closure / class@method and inject its dependencies
179
+ * Laravel: $app->call(callable)
180
+ */
181
+ call(callback, parameters = []) {
182
+ const paramTypes = Reflect.getMetadata('design:paramtypes', callback) || [];
183
+ const dependencies = paramTypes.map((paramType, index) => {
184
+ if (parameters[index] !== undefined) {
185
+ return parameters[index];
186
+ }
187
+ return this.make(paramType);
188
+ });
189
+ return callback(...dependencies);
190
+ }
191
+ }
192
+ exports.Container = Container;
193
+ //# sourceMappingURL=Container.js.map
@@ -0,0 +1 @@
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AAG,CAAC,QAAQ,CAAC,CAAC;IAC1E,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,IAAI,CAAC,QAAkB,EAAE,aAAoB,EAAE;QAC7C,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,mBAAmB,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC5E,MAAM,YAAY,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,SAAc,EAAE,KAAa,EAAE,EAAE;YACpE,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,SAAS,EAAE,CAAC;gBACpC,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;YACD,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC,GAAG,YAAY,CAAC,CAAC;IACnC,CAAC;CACF;AAxND,8BAwNC"}
@@ -0,0 +1,20 @@
1
+ import { Facade } from '../Support/Facade';
2
+ import { Router } from '../Routing/Router';
3
+ /**
4
+ * Route Facade - Static access to the Router
5
+ * Usage: Route.get('/path', handler)
6
+ */
7
+ declare class RouteFacade extends Facade {
8
+ protected static getFacadeAccessor(): string;
9
+ static get: Router['get'];
10
+ static post: Router['post'];
11
+ static put: Router['put'];
12
+ static patch: Router['patch'];
13
+ static delete: Router['delete'];
14
+ static any: Router['any'];
15
+ static match: Router['match'];
16
+ static group: Router['group'];
17
+ }
18
+ export declare const Route: typeof RouteFacade & Router;
19
+ export {};
20
+ //# sourceMappingURL=Route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Route.d.ts","sourceRoot":"","sources":["../../src/Facades/Route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;;GAGG;AACH,cAAM,WAAY,SAAQ,MAAM;IAC9B,SAAS,CAAC,MAAM,CAAC,iBAAiB,IAAI,MAAM;IAI5C,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5B,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAC9B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAC9B,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;CAC/B;AAGD,eAAO,MAAM,KAAK,EA2BD,OAAO,WAAW,GAAG,MAAM,CAAC"}