@koala-ts/framework 2.14.0 → 2.14.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 (114) hide show
  1. package/dist/Http/Scope/index.d.ts +1 -0
  2. package/dist/Http/Scope/index.d.ts.map +1 -1
  3. package/dist/Http/Scope/index.js +1 -0
  4. package/dist/Http/Scope/index.js.map +1 -1
  5. package/dist/Http/Scope/initialize-scope.d.ts +8 -0
  6. package/dist/Http/Scope/initialize-scope.d.ts.map +1 -0
  7. package/dist/Http/Scope/initialize-scope.js +26 -0
  8. package/dist/Http/Scope/initialize-scope.js.map +1 -0
  9. package/dist/Http/Scope/initialize-scope.test.d.ts +2 -0
  10. package/dist/Http/Scope/initialize-scope.test.d.ts.map +1 -0
  11. package/dist/Http/Scope/initialize-scope.test.js +63 -0
  12. package/dist/Http/Scope/initialize-scope.test.js.map +1 -0
  13. package/dist/Http/Scope/request-scope-storage.d.ts +13 -0
  14. package/dist/Http/Scope/request-scope-storage.d.ts.map +1 -0
  15. package/dist/Http/Scope/request-scope-storage.js +15 -0
  16. package/dist/Http/Scope/request-scope-storage.js.map +1 -0
  17. package/dist/Http/Scope/request-scope-storage.test.d.ts +2 -0
  18. package/dist/Http/Scope/request-scope-storage.test.d.ts.map +1 -0
  19. package/dist/{Kernel/HttpKernel.test.js → Http/Scope/request-scope-storage.test.js} +4 -4
  20. package/dist/Http/Scope/request-scope-storage.test.js.map +1 -0
  21. package/dist/Http/middleware/apply-configured-global-middleware.d.ts +3 -0
  22. package/dist/Http/middleware/apply-configured-global-middleware.d.ts.map +1 -0
  23. package/dist/Http/middleware/apply-configured-global-middleware.js +9 -0
  24. package/dist/Http/middleware/apply-configured-global-middleware.js.map +1 -0
  25. package/dist/Http/middleware/apply-configured-global-middleware.test.d.ts +2 -0
  26. package/dist/Http/middleware/apply-configured-global-middleware.test.d.ts.map +1 -0
  27. package/dist/Http/middleware/apply-configured-global-middleware.test.js +53 -0
  28. package/dist/Http/middleware/apply-configured-global-middleware.test.js.map +1 -0
  29. package/dist/Kernel/index.d.ts +2 -1
  30. package/dist/Kernel/index.d.ts.map +1 -1
  31. package/dist/Kernel/index.js +2 -1
  32. package/dist/Kernel/index.js.map +1 -1
  33. package/dist/Kernel/register-event-subscribers.d.ts +4 -0
  34. package/dist/Kernel/register-event-subscribers.d.ts.map +1 -0
  35. package/dist/Kernel/register-event-subscribers.js +22 -0
  36. package/dist/Kernel/register-event-subscribers.js.map +1 -0
  37. package/dist/Kernel/register-event-subscribers.test.d.ts +2 -0
  38. package/dist/Kernel/register-event-subscribers.test.d.ts.map +1 -0
  39. package/dist/Kernel/register-event-subscribers.test.js +19 -0
  40. package/dist/Kernel/register-event-subscribers.test.js.map +1 -0
  41. package/dist/Testing/TestAgentFactory.d.ts +1 -1
  42. package/dist/Testing/TestAgentFactory.d.ts.map +1 -1
  43. package/dist/Testing/TestAgentFactory.js +1 -1
  44. package/dist/Testing/TestAgentFactory.js.map +1 -1
  45. package/dist/{Application/types.d.ts → application/application.d.ts} +1 -1
  46. package/dist/application/application.d.ts.map +1 -0
  47. package/dist/application/application.js +1 -0
  48. package/dist/application/application.js.map +1 -0
  49. package/dist/{Application/ApplicationFactory.d.ts → application/create-application.d.ts} +2 -2
  50. package/dist/application/create-application.d.ts.map +1 -0
  51. package/dist/application/create-application.js +18 -0
  52. package/dist/application/create-application.js.map +1 -0
  53. package/dist/application/create-application.test.d.ts +2 -0
  54. package/dist/application/create-application.test.d.ts.map +1 -0
  55. package/dist/{Application/ApplicationFactory.test.js → application/create-application.test.js} +3 -3
  56. package/dist/application/create-application.test.js.map +1 -0
  57. package/dist/index.d.ts +3 -2
  58. package/dist/index.d.ts.map +1 -1
  59. package/dist/index.js +2 -2
  60. package/dist/index.js.map +1 -1
  61. package/dist/routing/index.d.ts +4 -0
  62. package/dist/routing/index.d.ts.map +1 -0
  63. package/dist/routing/index.js +3 -0
  64. package/dist/routing/index.js.map +1 -0
  65. package/dist/{Routing/Router.d.ts → routing/router.d.ts} +3 -1
  66. package/dist/routing/router.d.ts.map +1 -0
  67. package/dist/{Routing/Router.js → routing/router.js} +34 -1
  68. package/dist/routing/router.js.map +1 -0
  69. package/dist/routing/router.test.d.ts +2 -0
  70. package/dist/routing/router.test.d.ts.map +1 -0
  71. package/dist/{Routing/Router.test.js → routing/router.test.js} +46 -4
  72. package/dist/routing/router.test.js.map +1 -0
  73. package/dist/{Routing → routing}/types.d.ts.map +1 -1
  74. package/dist/{Routing → routing}/types.js.map +1 -1
  75. package/package.json +4 -7
  76. package/dist/Application/ApplicationFactory.d.ts.map +0 -1
  77. package/dist/Application/ApplicationFactory.js +0 -52
  78. package/dist/Application/ApplicationFactory.js.map +0 -1
  79. package/dist/Application/ApplicationFactory.test.d.ts +0 -2
  80. package/dist/Application/ApplicationFactory.test.d.ts.map +0 -1
  81. package/dist/Application/ApplicationFactory.test.js.map +0 -1
  82. package/dist/Application/Response.d.ts +0 -4
  83. package/dist/Application/Response.d.ts.map +0 -1
  84. package/dist/Application/Response.js +0 -14
  85. package/dist/Application/Response.js.map +0 -1
  86. package/dist/Application/Response.test.d.ts +0 -2
  87. package/dist/Application/Response.test.d.ts.map +0 -1
  88. package/dist/Application/Response.test.js +0 -40
  89. package/dist/Application/Response.test.js.map +0 -1
  90. package/dist/Application/index.d.ts +0 -3
  91. package/dist/Application/index.d.ts.map +0 -1
  92. package/dist/Application/index.js +0 -2
  93. package/dist/Application/index.js.map +0 -1
  94. package/dist/Application/types.d.ts.map +0 -1
  95. package/dist/Application/types.js.map +0 -1
  96. package/dist/Kernel/HttpKernel.d.ts +0 -7
  97. package/dist/Kernel/HttpKernel.d.ts.map +0 -1
  98. package/dist/Kernel/HttpKernel.js +0 -15
  99. package/dist/Kernel/HttpKernel.js.map +0 -1
  100. package/dist/Kernel/HttpKernel.test.d.ts +0 -2
  101. package/dist/Kernel/HttpKernel.test.d.ts.map +0 -1
  102. package/dist/Kernel/HttpKernel.test.js.map +0 -1
  103. package/dist/Routing/Router.d.ts.map +0 -1
  104. package/dist/Routing/Router.js.map +0 -1
  105. package/dist/Routing/Router.test.d.ts +0 -2
  106. package/dist/Routing/Router.test.d.ts.map +0 -1
  107. package/dist/Routing/Router.test.js.map +0 -1
  108. package/dist/Routing/index.d.ts +0 -4
  109. package/dist/Routing/index.d.ts.map +0 -1
  110. package/dist/Routing/index.js +0 -3
  111. package/dist/Routing/index.js.map +0 -1
  112. package/dist/Routing/types.js +0 -1
  113. /package/dist/{Routing → routing}/types.d.ts +0 -0
  114. /package/dist/{Application → routing}/types.js +0 -0
@@ -1,3 +1,4 @@
1
1
  export type * from './types.js';
2
+ export * from './initialize-scope.js';
2
3
  export * from './State/index.js';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Http/Scope/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,SAAS,CAAC;AAC7B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Http/Scope/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,SAAS,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC"}
@@ -1,2 +1,3 @@
1
+ export * from './initialize-scope.js';
1
2
  export * from './State/index.js';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Http/Scope/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Http/Scope/index.ts"],"names":[],"mappings":"AACA,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type Next } from 'koa';
2
+ import { type HttpScope } from './types.js';
3
+ export type ScopeAwareApp = {
4
+ context: HttpScope;
5
+ scope: HttpScope;
6
+ };
7
+ export declare function initializeScope(scope: HttpScope, next: Next): Promise<void>;
8
+ //# sourceMappingURL=initialize-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialize-scope.d.ts","sourceRoot":"","sources":["../../../src/Http/Scope/initialize-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,KAAK,CAAC;AAEhC,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,SAAS,CAAC;IACnB,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC;AAmBF,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAejF"}
@@ -0,0 +1,26 @@
1
+ function setHeader(name, value) {
2
+ const scope = this.ctx;
3
+ scope.set(name, value);
4
+ return this;
5
+ }
6
+ function withHeaders(headers) {
7
+ const scope = this.ctx;
8
+ for (const [name, value] of Object.entries(headers)) {
9
+ scope.set(name, value);
10
+ }
11
+ return this;
12
+ }
13
+ export async function initializeScope(scope, next) {
14
+ const app = scope.app;
15
+ if (app.scope !== app.context) {
16
+ app.scope = app.context;
17
+ }
18
+ if (scope.response.setHeader !== setHeader) {
19
+ scope.response.setHeader = setHeader;
20
+ }
21
+ if (scope.response.withHeaders !== withHeaders) {
22
+ scope.response.withHeaders = withHeaders;
23
+ }
24
+ await next();
25
+ }
26
+ //# sourceMappingURL=initialize-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialize-scope.js","sourceRoot":"","sources":["../../../src/Http/Scope/initialize-scope.ts"],"names":[],"mappings":"AASA,SAAS,SAAS,CAAqB,IAAY,EAAE,KAAwB;IAC3E,MAAM,KAAK,GAAG,IAAI,CAAC,GAAgB,CAAC;IACpC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAEvB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,WAAW,CAAqB,OAA0C;IACjF,MAAM,KAAK,GAAG,IAAI,CAAC,GAAgB,CAAC;IAEpC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACzB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,KAAgB,EAAE,IAAU;IAChE,MAAM,GAAG,GAAG,KAAK,CAAC,GAA+B,CAAC;IAClD,IAAI,GAAG,CAAC,KAAK,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC;QAC9B,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QAC3C,KAAK,CAAC,QAAQ,CAAC,SAAS,GAAG,SAAS,CAAC;IACvC,CAAC;IAED,IAAI,KAAK,CAAC,QAAQ,CAAC,WAAW,KAAK,WAAW,EAAE,CAAC;QAC/C,KAAK,CAAC,QAAQ,CAAC,WAAW,GAAG,WAAW,CAAC;IAC3C,CAAC;IAED,MAAM,IAAI,EAAE,CAAC;AACf,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=initialize-scope.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialize-scope.test.d.ts","sourceRoot":"","sources":["../../../src/Http/Scope/initialize-scope.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,63 @@
1
+ import { beforeEach, describe, expect, test, vi } from 'vitest';
2
+ import { initializeScope } from './initialize-scope.js';
3
+ describe('initializeScope', () => {
4
+ let scope;
5
+ let next;
6
+ beforeEach(() => {
7
+ scope = { app: { context: {} }, response: {}, set: vi.fn() };
8
+ scope.response.ctx = scope;
9
+ next = vi.fn();
10
+ });
11
+ test('sets the app scope alias from the application context', async () => {
12
+ await initializeScope(scope, next);
13
+ const app = scope.app;
14
+ expect(app.scope).toBe(app.context);
15
+ });
16
+ test('adds setHeader to the response', async () => {
17
+ await initializeScope(scope, next);
18
+ scope.response.setHeader('Content-Type', 'application/json');
19
+ expect(scope.set).toHaveBeenCalledWith('Content-Type', 'application/json');
20
+ });
21
+ test('returns the response from setHeader', async () => {
22
+ await initializeScope(scope, next);
23
+ const response = scope.response.setHeader('Content-Type', 'application/json');
24
+ expect(response).toBe(scope.response);
25
+ });
26
+ test('adds withHeaders to the response', async () => {
27
+ await initializeScope(scope, next);
28
+ scope.response.withHeaders({
29
+ 'Content-Type': 'application/json',
30
+ 'X-Custom-Header': 'value',
31
+ });
32
+ expect(scope.set).toHaveBeenCalledWith('Content-Type', 'application/json');
33
+ expect(scope.set).toHaveBeenCalledWith('X-Custom-Header', 'value');
34
+ });
35
+ test('returns the response from withHeaders', async () => {
36
+ await initializeScope(scope, next);
37
+ const response = scope.response.withHeaders({
38
+ 'Content-Type': 'application/json',
39
+ 'X-Custom-Header': 'value',
40
+ });
41
+ expect(response).toBe(scope.response);
42
+ });
43
+ test('does not replace response helpers when called twice', async () => {
44
+ await initializeScope(scope, next);
45
+ const setHeader = scope.response.setHeader;
46
+ const withHeaders = scope.response.withHeaders;
47
+ await initializeScope(scope, next);
48
+ expect(scope.response.setHeader).toBe(setHeader);
49
+ expect(scope.response.withHeaders).toBe(withHeaders);
50
+ });
51
+ test('does not replace the app scope alias when already initialized', async () => {
52
+ await initializeScope(scope, next);
53
+ const app = scope.app;
54
+ const currentScope = app.scope;
55
+ await initializeScope(scope, next);
56
+ expect(app.scope).toBe(currentScope);
57
+ });
58
+ test('calls next middleware', async () => {
59
+ await initializeScope(scope, next);
60
+ expect(next).toHaveBeenCalledTimes(1);
61
+ });
62
+ });
63
+ //# sourceMappingURL=initialize-scope.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init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AM,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC;QAE/C,MAAM,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAEnC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACjD,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,+DAA+D,EAAE,KAAK,IAAI,EAAE;QAC/E,MAAM,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAEnC,MAAM,GAAG,GAAG,KAAK,CAAC,GAA+B,CAAC;QAClD,MAAM,YAAY,GAAG,GAAG,CAAC,KAAK,CAAC;QAE/B,MAAM,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAEnC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,uBAAuB,EAAE,KAAK,IAAI,EAAE;QACvC,MAAM,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAEnC,MAAM,CAAC,IAAI,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { type HttpRequest, type HttpResponse, type HttpScope, type NextMiddleware, type ScopeStore } from '../../Http/index.js';
2
+ export interface ScopeEventEmitter {
3
+ emit(event: string, ...args: unknown[]): void;
4
+ }
5
+ export interface ScopeStorage {
6
+ eventEmitter: ScopeEventEmitter;
7
+ scope: HttpScope;
8
+ }
9
+ export declare function initializeRequestScopeStorage(scope: HttpScope, next: NextMiddleware, storage?: ScopeStore<ScopeStorage>): Promise<void>;
10
+ export declare function useEmit(storage?: ScopeStore<ScopeStorage>): ScopeEventEmitter;
11
+ export declare function useRequest(storage?: ScopeStore<ScopeStorage>): HttpRequest;
12
+ export declare function useResponse(storage?: ScopeStore<ScopeStorage>): HttpResponse;
13
+ //# sourceMappingURL=request-scope-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-scope-storage.d.ts","sourceRoot":"","sources":["../../../src/Http/Scope/request-scope-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,UAAU,EAChB,MAAM,QAAQ,CAAC;AAEhB,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CAC/C;AAED,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,iBAAiB,CAAC;IAChC,KAAK,EAAE,SAAS,CAAC;CAClB;AAID,wBAAsB,6BAA6B,CACjD,KAAK,EAAE,SAAS,EAChB,IAAI,EAAE,cAAc,EACpB,OAAO,GAAE,UAAU,CAAC,YAAY,CAAuB,GACtD,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,wBAAgB,OAAO,CAAC,OAAO,GAAE,UAAU,CAAC,YAAY,CAAuB,GAAG,iBAAiB,CAElG;AAED,wBAAgB,UAAU,CAAC,OAAO,GAAE,UAAU,CAAC,YAAY,CAAuB,GAAG,WAAW,CAE/F;AAED,wBAAgB,WAAW,CAAC,OAAO,GAAE,UAAU,CAAC,YAAY,CAAuB,GAAG,YAAY,CAEjG"}
@@ -0,0 +1,15 @@
1
+ import { createStore, } from '../../Http/index.js';
2
+ const requestScopeStorage = createStore();
3
+ export async function initializeRequestScopeStorage(scope, next, storage = requestScopeStorage) {
4
+ await storage.run({ eventEmitter: scope.app, scope }, next);
5
+ }
6
+ export function useEmit(storage = requestScopeStorage) {
7
+ return storage.get('eventEmitter');
8
+ }
9
+ export function useRequest(storage = requestScopeStorage) {
10
+ return storage.get('scope').request;
11
+ }
12
+ export function useResponse(storage = requestScopeStorage) {
13
+ return storage.get('scope').response;
14
+ }
15
+ //# sourceMappingURL=request-scope-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-scope-storage.js","sourceRoot":"","sources":["../../../src/Http/Scope/request-scope-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,GAMZ,MAAM,QAAQ,CAAC;AAWhB,MAAM,mBAAmB,GAAG,WAAW,EAAgB,CAAC;AAExD,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,KAAgB,EAChB,IAAoB,EACpB,UAAoC,mBAAmB;IAEvD,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,UAAoC,mBAAmB;IAC7E,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,UAAoC,mBAAmB;IAChF,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,UAAoC,mBAAmB;IACjF,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC;AACvC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=request-scope-storage.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-scope-storage.test.d.ts","sourceRoot":"","sources":["../../../src/Http/Scope/request-scope-storage.test.ts"],"names":[],"mappings":""}
@@ -1,11 +1,11 @@
1
1
  import { describe, expect, test, vi } from 'vitest';
2
- import { httpKernel, useEmit, useRequest, useResponse } from '../Kernel/HttpKernel.js';
3
- describe('Http Kernel', () => {
2
+ import { initializeRequestScopeStorage, useEmit, useRequest, useResponse, } from './request-scope-storage.js';
3
+ describe('request scope storage', () => {
4
4
  test('middleware should init storage', async () => {
5
5
  const scope = { app: vi.fn() };
6
6
  const next = vi.fn();
7
7
  const storage = { run: vi.fn() };
8
- await httpKernel(scope, next, storage);
8
+ await initializeRequestScopeStorage(scope, next, storage);
9
9
  expect(storage.run).toHaveBeenCalledWith({ eventEmitter: scope.app, scope }, next);
10
10
  });
11
11
  test('useEmit should return emitter from storage', () => {
@@ -29,4 +29,4 @@ describe('Http Kernel', () => {
29
29
  expect(res).toBe(response);
30
30
  });
31
31
  });
32
- //# sourceMappingURL=HttpKernel.test.js.map
32
+ //# sourceMappingURL=request-scope-storage.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-scope-storage.test.js","sourceRoot":"","sources":["../../../src/Http/Scope/request-scope-storage.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEpD,OAAO,EACL,6BAA6B,EAE7B,OAAO,EACP,UAAU,EACV,WAAW,GACZ,MAAM,yBAAyB,CAAC;AAEjC,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,IAAI,CAAC,gCAAgC,EAAE,KAAK,IAAI,EAAE;QAChD,MAAM,KAAK,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QACrB,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;QAEjC,MAAM,6BAA6B,CACjC,KAA6B,EAC7B,IAAI,EACJ,OAA8C,CAC/C,CAAC;QAEF,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,oBAAoB,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE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AAC,OAAO,CAAC,GAAG,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAClD,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type HttpMiddleware } from '../../Http/index.js';
2
+ export declare function applyConfiguredGlobalMiddleware(middleware?: HttpMiddleware[] | undefined): HttpMiddleware;
3
+ //# sourceMappingURL=apply-configured-global-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-configured-global-middleware.d.ts","sourceRoot":"","sources":["../../../src/Http/middleware/apply-configured-global-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,QAAQ,CAAC;AAE7C,wBAAgB,+BAA+B,CAAC,UAAU,GAAE,cAAc,EAAE,GAAG,SAAc,GAAG,cAAc,CAW7G"}
@@ -0,0 +1,9 @@
1
+ export function applyConfiguredGlobalMiddleware(middleware = []) {
2
+ return async (scope, next) => {
3
+ const pipeline = middleware.reduceRight((stack, current) => {
4
+ return async () => await current(scope, stack);
5
+ }, async () => await next());
6
+ await pipeline();
7
+ };
8
+ }
9
+ //# sourceMappingURL=apply-configured-global-middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-configured-global-middleware.js","sourceRoot":"","sources":["../../../src/Http/middleware/apply-configured-global-middleware.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,+BAA+B,CAAC,aAA2C,EAAE;IAC3F,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,CACrC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YACjB,OAAO,KAAK,IAAI,EAAE,CAAC,MAAM,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACjD,CAAC,EACD,KAAK,IAAI,EAAE,CAAC,MAAM,IAAI,EAAE,CACzB,CAAC;QAEF,MAAM,QAAQ,EAAE,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=apply-configured-global-middleware.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-configured-global-middleware.test.d.ts","sourceRoot":"","sources":["../../../src/Http/middleware/apply-configured-global-middleware.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,53 @@
1
+ import { describe, expect, test, vi } from 'vitest';
2
+ import { applyConfiguredGlobalMiddleware } from './apply-configured-global-middleware.js';
3
+ describe('applyConfiguredGlobalMiddleware', () => {
4
+ test('continues to next middleware when undefined', async () => {
5
+ const middleware = applyConfiguredGlobalMiddleware(undefined);
6
+ const scope = {};
7
+ const next = vi.fn();
8
+ await middleware(scope, next);
9
+ expect(next).toHaveBeenCalledTimes(1);
10
+ });
11
+ test('continues to next middleware when empty', async () => {
12
+ const middleware = applyConfiguredGlobalMiddleware([]);
13
+ const scope = {};
14
+ const next = vi.fn();
15
+ await middleware(scope, next);
16
+ expect(next).toHaveBeenCalledTimes(1);
17
+ });
18
+ test('runs a single middleware', async () => {
19
+ const calls = [];
20
+ const configuredMiddleware = async (_scope, next) => {
21
+ calls.push('configured');
22
+ await next();
23
+ };
24
+ const middleware = applyConfiguredGlobalMiddleware([configuredMiddleware]);
25
+ const scope = {};
26
+ const next = vi.fn(async () => {
27
+ calls.push('next');
28
+ });
29
+ await middleware(scope, next);
30
+ expect(calls).toEqual(['configured', 'next']);
31
+ });
32
+ test('runs configured middleware in order', async () => {
33
+ const calls = [];
34
+ const firstMiddleware = async (_scope, next) => {
35
+ calls.push('first-before');
36
+ await next();
37
+ calls.push('first-after');
38
+ };
39
+ const secondMiddleware = async (_scope, next) => {
40
+ calls.push('second-before');
41
+ await next();
42
+ calls.push('second-after');
43
+ };
44
+ const middleware = applyConfiguredGlobalMiddleware([firstMiddleware, secondMiddleware]);
45
+ const scope = {};
46
+ const next = vi.fn(async () => {
47
+ calls.push('next');
48
+ });
49
+ await middleware(scope, next);
50
+ expect(calls).toEqual(['first-before', 'second-before', 'next', 'second-after', 'first-after']);
51
+ });
52
+ });
53
+ //# sourceMappingURL=apply-configured-global-middleware.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-configured-global-middleware.test.js","sourceRoot":"","sources":["../../../src/Http/middleware/apply-configured-global-middleware.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACpD,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AAEvF,QAAQ,CAAC,iCAAiC,EAAE,GAAG,EAAE;IAC/C,IAAI,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;QAC7D,MAAM,UAAU,GAAG,+BAA+B,CAAC,SAAS,CAAC,CAAC;QAC9D,MAAM,KAAK,GAAG,EAAe,CAAC;QAC9B,MAAM,IAAI,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAErB,MAAM,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAE9B,MAAM,CAAC,IAAI,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;QACzD,MAAM,UAAU,GAAG,+BAA+B,CAAC,EAAE,CAAC,CAAC;QACvD,MAAM,KAAK,GAAG,EAAe,CAAC;QAC9B,MAAM,IAAI,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAErB,MAAM,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAE9B,MAAM,CAAC,IAAI,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,0BAA0B,EAAE,KAAK,IAAI,EA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,MAAM,KAAK,GAAG,EAAe,CAAC;QAC9B,MAAM,IAAI,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE;YAC5B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,MAAM,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAE9B,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,cAAc,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC,CAAC;IAClG,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export * from './types.js';
2
- export * from './HttpKernel.js';
2
+ export { registerEventSubscribers } from '../Kernel/register-event-subscribers.js';
3
+ export { initializeRequestScopeStorage, useEmit, useRequest, useResponse } from '../Http/Scope/request-scope-storage.js';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Kernel/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Kernel/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,6BAA6B,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export * from './types.js';
2
- export * from './HttpKernel.js';
2
+ export { registerEventSubscribers } from '../Kernel/register-event-subscribers.js';
3
+ export { initializeRequestScopeStorage, useEmit, useRequest, useResponse } from '../Http/Scope/request-scope-storage.js';
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Kernel/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Kernel/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,6BAA6B,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type Application } from '../application/application.js';
2
+ import { type EventSubscriber } from '../Kernel/types.js';
3
+ export declare function registerEventSubscribers(app: Application, map: Record<string, EventSubscriber | EventSubscriber[]> | undefined): void;
4
+ //# sourceMappingURL=register-event-subscribers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-event-subscribers.d.ts","sourceRoot":"","sources":["../../src/Kernel/register-event-subscribers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,EAAE,CAAC,GAAG,SAAS,GACnE,IAAI,CAQN"}
@@ -0,0 +1,22 @@
1
+ export function registerEventSubscribers(app, map) {
2
+ if (undefined === map) {
3
+ return;
4
+ }
5
+ for (const [event, subscriber] of normalizeEventSubscribers(map)) {
6
+ app.on(event, subscriber);
7
+ }
8
+ }
9
+ function normalizeEventSubscribers(map) {
10
+ const subscriptions = [];
11
+ for (const [event, subscribers] of Object.entries(map)) {
12
+ if (Array.isArray(subscribers)) {
13
+ for (const subscriber of subscribers) {
14
+ subscriptions.push([event, subscriber]);
15
+ }
16
+ continue;
17
+ }
18
+ subscriptions.push([event, subscribers]);
19
+ }
20
+ return subscriptions;
21
+ }
22
+ //# sourceMappingURL=register-event-subscribers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-event-subscribers.js","sourceRoot":"","sources":["../../src/Kernel/register-event-subscribers.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,wBAAwB,CACtC,GAAgB,EAChB,GAAoE;IAEpE,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;QACtB,OAAO;IACT,CAAC;IAED,KAAK,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,yBAAyB,CAAC,GAAG,CAAC,EAAE,CAAC;QACjE,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,UAAqD,CAAC,CAAC;IACvE,CAAC;AACH,CAAC;AAED,SAAS,yBAAyB,CAChC,GAAwD;IAExD,MAAM,aAAa,GAAqC,EAAE,CAAC;IAE3D,KAAK,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvD,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/B,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;gBACrC,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;YAC1C,CAAC;YAED,SAAS;QACX,CAAC;QAED,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=register-event-subscribers.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-event-subscribers.test.d.ts","sourceRoot":"","sources":["../../src/Kernel/register-event-subscribers.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ import { registerEventSubscribers } from '../Kernel/index.js';
2
+ import { expect, test, vi } from 'vitest';
3
+ test('register a single event subscriber', () => {
4
+ const on = vi.fn();
5
+ const app = { on };
6
+ const subscriber = vi.fn();
7
+ registerEventSubscribers(app, { requestCompleted: subscriber });
8
+ expect(on).toHaveBeenCalledWith('requestCompleted', subscriber);
9
+ });
10
+ test('register multiple event subscribers', () => {
11
+ const on = vi.fn();
12
+ const app = { on };
13
+ const firstSubscriber = vi.fn();
14
+ const secondSubscriber = vi.fn();
15
+ registerEventSubscribers(app, { requestCompleted: [firstSubscriber, secondSubscriber] });
16
+ expect(on).toHaveBeenNthCalledWith(1, 'requestCompleted', firstSubscriber);
17
+ expect(on).toHaveBeenNthCalledWith(2, 'requestCompleted', secondSubscriber);
18
+ });
19
+ //# sourceMappingURL=register-event-subscribers.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-event-subscribers.test.js","sourceRoot":"","sources":["../../src/Kernel/register-event-subscribers.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE1C,IAAI,CAAC,oCAAoC,EAAE,GAAG,EAAE;IAC9C,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;IACnB,MAAM,GAAG,GAAG,EAAE,EAAE,EAA4B,CAAC;IAC7C,MAAM,UAAU,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;IAE3B,wBAAwB,CAAC,GAAG,EAAE,EAAE,gBAAgB,EAAE,UAAU,EAAE,CAAC,CAAC;IAEhE,MAAM,CAAC,EAAE,CAAC,CAAC,oBAAoB,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC;AAClE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,qCAAqC,EAAE,GAAG,EAAE;IAC/C,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;IACnB,MAAM,GAAG,GAAG,EAAE,EAAE,EAA4B,CAAC;IAC7C,MAAM,eAAe,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;IAChC,MAAM,gBAAgB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;IAEjC,wBAAwB,CAAC,GAAG,EAAE,EAAE,gBAAgB,EAAE,CAAC,eAAe,EAAE,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAEzF,MAAM,CAAC,EAAE,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,kBAAkB,EAAE,eAAe,CAAC,CAAC;IAC3E,MAAM,CAAC,EAAE,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,kBAAkB,EAAE,gBAAgB,CAAC,CAAC;AAC9E,CAAC,CAAC,CAAC"}
@@ -1,6 +1,6 @@
1
- import { type TestAgent } from './types.js';
2
1
  import { type KoalaConfig } from '../Config/index.js';
3
2
  import { type User } from '../Security/types.js';
3
+ import { type TestAgent } from './types.js';
4
4
  export declare function createTestAgent(config: KoalaConfig, agentConfig?: {
5
5
  actAs?: User;
6
6
  }): TestAgent;
@@ -1 +1 @@
1
- {"version":3,"file":"TestAgentFactory.d.ts","sourceRoot":"","sources":["../../src/Testing/TestAgentFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,EAAE,WAAW,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,IAAI,CAAA;CAAE,GAAG,SAAS,CAW9F"}
1
+ {"version":3,"file":"TestAgentFactory.d.ts","sourceRoot":"","sources":["../../src/Testing/TestAgentFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,EAAE,WAAW,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,IAAI,CAAA;CAAE,GAAG,SAAS,CAW9F"}
@@ -1,5 +1,5 @@
1
+ import { create } from '../application/create-application.js';
1
2
  import supertest from 'supertest';
2
- import { create } from '../Application/index.js';
3
3
  export function createTestAgent(config, agentConfig) {
4
4
  const globalMiddleware = config.globalMiddleware ?? [];
5
5
  const testConfig = { ...config };
@@ -1 +1 @@
1
- {"version":3,"file":"TestAgentFactory.js","sourceRoot":"","sources":["../../src/Testing/TestAgentFactory.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAKvC,MAAM,UAAU,eAAe,CAAC,MAAmB,EAAE,WAA8B;IACjF,MAAM,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,IAAI,EAAE,CAAC;IACvD,MAAM,UAAU,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAEjC,MAAM,EAAE,KAAK,EAAE,GAAG,WAAW,IAAI,EAAE,CAAC;IAEpC,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;QACxB,UAAU,CAAC,gBAAgB,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,GAAG,gBAAgB,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,SAAS,CAAC,IAAU;IAC3B,OAAO,KAAK,UAAU,mBAAmB,CAAC,KAAgB,EAAE,IAAoB;QAC9E,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAClB,MAAM,IAAI,EAAE,CAAC;IACf,CAAC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"TestAgentFactory.js","sourceRoot":"","sources":["../../src/Testing/TestAgentFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAI1D,OAAO,SAAS,MAAM,WAAW,CAAC;AAGlC,MAAM,UAAU,eAAe,CAAC,MAAmB,EAAE,WAA8B;IACjF,MAAM,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,IAAI,EAAE,CAAC;IACvD,MAAM,UAAU,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAEjC,MAAM,EAAE,KAAK,EAAE,GAAG,WAAW,IAAI,EAAE,CAAC;IAEpC,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;QACxB,UAAU,CAAC,gBAAgB,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,GAAG,gBAAgB,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,SAAS,CAAC,IAAU;IAC3B,OAAO,KAAK,UAAU,mBAAmB,CAAC,KAAgB,EAAE,IAAoB;QAC9E,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAClB,MAAM,IAAI,EAAE,CAAC;IACf,CAAC,CAAC;AACJ,CAAC"}
@@ -3,4 +3,4 @@ import type { AppState, HttpScope } from '../Http/index.js';
3
3
  export type Application<StateT = AppState, ScopeT = HttpScope> = Koa<StateT, ScopeT> & {
4
4
  scope: HttpScope;
5
5
  };
6
- //# sourceMappingURL=types.d.ts.map
6
+ //# sourceMappingURL=application.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../src/application/application.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAElD,MAAM,MAAM,WAAW,CAAC,MAAM,GAAG,QAAQ,EAAE,MAAM,GAAG,SAAS,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG;IACrF,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=application.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application.js","sourceRoot":"","sources":["../../src/application/application.ts"],"names":[],"mappings":""}
@@ -1,4 +1,4 @@
1
- import { type Application } from './types.js';
2
1
  import { type KoalaConfig } from '../Config/index.js';
2
+ import { type Application } from './application.js';
3
3
  export declare function create(config: KoalaConfig): Application;
4
- //# sourceMappingURL=ApplicationFactory.d.ts.map
4
+ //# sourceMappingURL=create-application.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-application.d.ts","sourceRoot":"","sources":["../../src/application/create-application.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAQ5C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,wBAAgB,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAYvD"}
@@ -0,0 +1,18 @@
1
+ import { initializeScope } from '../Http/index.js';
2
+ import { serveStaticFiles } from '../Http/Files/index.js';
3
+ import { applyConfiguredGlobalMiddleware } from '../Http/middleware/apply-configured-global-middleware.js';
4
+ import { initializeRequestScopeStorage } from '../Http/Scope/request-scope-storage.js';
5
+ import { registerEventSubscribers } from '../Kernel/index.js';
6
+ import { registerRoutes } from '../routing/index.js';
7
+ import Koa from 'koa';
8
+ export function create(config) {
9
+ const app = new Koa();
10
+ app.use(initializeScope);
11
+ app.use(initializeRequestScopeStorage);
12
+ app.use(applyConfiguredGlobalMiddleware(config.globalMiddleware));
13
+ app.use(serveStaticFiles(config.staticFiles));
14
+ registerRoutes(app);
15
+ registerEventSubscribers(app, config.eventSubscribers);
16
+ return app;
17
+ }
18
+ //# sourceMappingURL=create-application.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-application.js","sourceRoot":"","sources":["../../src/application/create-application.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,+BAA+B,EAAE,MAAM,sDAAsD,CAAC;AACvG,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,GAAG,MAAM,KAAK,CAAC;AAGtB,MAAM,UAAU,MAAM,CAAC,MAAmB;IACxC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAiB,CAAC;IAErC,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACzB,GAAG,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;IACvC,GAAG,CAAC,GAAG,CAAC,+BAA+B,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAClE,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;IAE9C,cAAc,CAAC,GAAG,CAAC,CAAC;IACpB,wBAAwB,CAAC,GAAG,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAEvD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=create-application.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-application.test.d.ts","sourceRoot":"","sources":["../../src/application/create-application.test.ts"],"names":[],"mappings":""}
@@ -1,8 +1,8 @@
1
- import { expect, test } from 'vitest';
2
- import { create } from '../Application/ApplicationFactory.js';
1
+ import { create } from '../application/create-application.js';
3
2
  import { koalaDefaultConfig } from '../Config/index.js';
3
+ import { expect, test } from 'vitest';
4
4
  test('create app with default config', () => {
5
5
  const app = create(koalaDefaultConfig);
6
6
  expect(app).toBeDefined();
7
7
  });
8
- //# sourceMappingURL=ApplicationFactory.test.js.map
8
+ //# sourceMappingURL=create-application.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-application.test.js","sourceRoot":"","sources":["../../src/application/create-application.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,IAAI,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC1C,MAAM,GAAG,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAEvC,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;AAC5B,CAAC,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- export * from './Application/index.js';
1
+ export { create } from './application/create-application.js';
2
+ export type { Application } from './application/application.js';
2
3
  export * from './Config/index.js';
3
4
  export * from './Http/index.js';
4
5
  export * from './Kernel/index.js';
5
- export * from './Routing/index.js';
6
+ export * from './routing/index.js';
6
7
  export * from './Security/index.js';
7
8
  export * from './Testing/index.js';
8
9
  export * from './serializer/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC1D,YAAY,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- export * from './Application/index.js';
1
+ export { create } from './application/create-application.js';
2
2
  export * from './Config/index.js';
3
3
  export * from './Http/index.js';
4
4
  export * from './Kernel/index.js';
5
- export * from './Routing/index.js';
5
+ export * from './routing/index.js';
6
6
  export * from './Security/index.js';
7
7
  export * from './Testing/index.js';
8
8
  export * from './serializer/index.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAE1D,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,4 @@
1
+ export type * from '../routing/types.js';
2
+ export { getRoutes, registerRoutes } from '../routing/router.js';
3
+ export { Route } from '../routing/router.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routing/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,iBAAiB,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { getRoutes, registerRoutes } from '../routing/router.js';
2
+ export { Route } from '../routing/router.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/routing/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1,5 +1,7 @@
1
1
  import 'reflect-metadata';
2
+ import { type Application } from '../application/application.js';
2
3
  import type { Route, RouteMetadata } from './types.js';
3
4
  export declare function Route({ method, path, middleware, options }: Route): MethodDecorator;
4
5
  export declare function getRoutes(): RouteMetadata[];
5
- //# sourceMappingURL=Router.d.ts.map
6
+ export declare function registerRoutes(app: Application): Application;
7
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/routing/router.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAK7D,OAAO,KAAK,EAAc,KAAK,EAAE,aAAa,EAA8B,MAAM,SAAS,CAAC;AAK5F,wBAAgB,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,UAAe,EAAE,OAAY,EAAE,EAAE,KAAK,GAAG,eAAe,CAe7F;AAED,wBAAgB,SAAS,IAAI,aAAa,EAAE,CAE3C;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,WAAW,GAAG,WAAW,CAO5D"}