alepha 0.12.1 → 0.13.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 (198) hide show
  1. package/dist/api-notifications/index.d.ts +111 -111
  2. package/dist/api-users/index.d.ts +1240 -1240
  3. package/dist/api-verifications/index.d.ts +94 -94
  4. package/dist/cli/{dist-Sz2EXvQX.cjs → dist-Dl9Vl7Ur.js} +17 -13
  5. package/dist/cli/{dist-BBPjuQ56.js.map → dist-Dl9Vl7Ur.js.map} +1 -1
  6. package/dist/cli/index.d.ts +3 -11
  7. package/dist/cli/index.js +106 -74
  8. package/dist/cli/index.js.map +1 -1
  9. package/dist/email/index.js +71 -73
  10. package/dist/email/index.js.map +1 -1
  11. package/dist/orm/index.d.ts +1 -1
  12. package/dist/orm/index.js.map +1 -1
  13. package/dist/queue/index.d.ts +4 -4
  14. package/dist/redis/index.d.ts +10 -10
  15. package/dist/retry/index.d.ts +1 -1
  16. package/dist/retry/index.js +2 -2
  17. package/dist/retry/index.js.map +1 -1
  18. package/dist/scheduler/index.d.ts +6 -6
  19. package/dist/server/index.js +1 -1
  20. package/dist/server/index.js.map +1 -1
  21. package/dist/server-auth/index.d.ts +193 -193
  22. package/dist/server-health/index.d.ts +17 -17
  23. package/dist/server-links/index.d.ts +34 -34
  24. package/dist/server-metrics/index.js +170 -174
  25. package/dist/server-metrics/index.js.map +1 -1
  26. package/dist/server-security/index.d.ts +9 -9
  27. package/dist/vite/index.js +4 -5
  28. package/dist/vite/index.js.map +1 -1
  29. package/dist/websocket/index.d.ts +7 -7
  30. package/package.json +52 -103
  31. package/src/cli/apps/AlephaPackageBuilderCli.ts +7 -2
  32. package/src/cli/assets/appRouterTs.ts +9 -0
  33. package/src/cli/assets/indexHtml.ts +2 -1
  34. package/src/cli/assets/mainBrowserTs.ts +10 -0
  35. package/src/cli/commands/CoreCommands.ts +6 -5
  36. package/src/cli/commands/DrizzleCommands.ts +65 -57
  37. package/src/cli/commands/VerifyCommands.ts +1 -1
  38. package/src/cli/services/ProjectUtils.ts +44 -38
  39. package/src/orm/providers/DrizzleKitProvider.ts +1 -1
  40. package/src/retry/descriptors/$retry.ts +5 -3
  41. package/src/server/providers/NodeHttpServerProvider.ts +1 -1
  42. package/src/vite/helpers/boot.ts +3 -3
  43. package/dist/api-files/index.cjs +0 -1293
  44. package/dist/api-files/index.cjs.map +0 -1
  45. package/dist/api-files/index.d.cts +0 -829
  46. package/dist/api-jobs/index.cjs +0 -274
  47. package/dist/api-jobs/index.cjs.map +0 -1
  48. package/dist/api-jobs/index.d.cts +0 -654
  49. package/dist/api-notifications/index.cjs +0 -380
  50. package/dist/api-notifications/index.cjs.map +0 -1
  51. package/dist/api-notifications/index.d.cts +0 -289
  52. package/dist/api-parameters/index.cjs +0 -66
  53. package/dist/api-parameters/index.cjs.map +0 -1
  54. package/dist/api-parameters/index.d.cts +0 -84
  55. package/dist/api-users/index.cjs +0 -6009
  56. package/dist/api-users/index.cjs.map +0 -1
  57. package/dist/api-users/index.d.cts +0 -4740
  58. package/dist/api-verifications/index.cjs +0 -407
  59. package/dist/api-verifications/index.cjs.map +0 -1
  60. package/dist/api-verifications/index.d.cts +0 -207
  61. package/dist/batch/index.cjs +0 -408
  62. package/dist/batch/index.cjs.map +0 -1
  63. package/dist/batch/index.d.cts +0 -330
  64. package/dist/bin/index.cjs +0 -17
  65. package/dist/bin/index.cjs.map +0 -1
  66. package/dist/bin/index.d.cts +0 -1
  67. package/dist/bucket/index.cjs +0 -303
  68. package/dist/bucket/index.cjs.map +0 -1
  69. package/dist/bucket/index.d.cts +0 -355
  70. package/dist/cache/index.cjs +0 -241
  71. package/dist/cache/index.cjs.map +0 -1
  72. package/dist/cache/index.d.cts +0 -202
  73. package/dist/cache-redis/index.cjs +0 -84
  74. package/dist/cache-redis/index.cjs.map +0 -1
  75. package/dist/cache-redis/index.d.cts +0 -40
  76. package/dist/cli/chunk-DSlc6foC.cjs +0 -43
  77. package/dist/cli/dist-BBPjuQ56.js +0 -2778
  78. package/dist/cli/dist-Sz2EXvQX.cjs.map +0 -1
  79. package/dist/cli/index.cjs +0 -1241
  80. package/dist/cli/index.cjs.map +0 -1
  81. package/dist/cli/index.d.cts +0 -422
  82. package/dist/command/index.cjs +0 -693
  83. package/dist/command/index.cjs.map +0 -1
  84. package/dist/command/index.d.cts +0 -340
  85. package/dist/core/index.cjs +0 -2264
  86. package/dist/core/index.cjs.map +0 -1
  87. package/dist/core/index.d.cts +0 -1927
  88. package/dist/datetime/index.cjs +0 -318
  89. package/dist/datetime/index.cjs.map +0 -1
  90. package/dist/datetime/index.d.cts +0 -145
  91. package/dist/email/index.cjs +0 -10874
  92. package/dist/email/index.cjs.map +0 -1
  93. package/dist/email/index.d.cts +0 -186
  94. package/dist/fake/index.cjs +0 -34641
  95. package/dist/fake/index.cjs.map +0 -1
  96. package/dist/fake/index.d.cts +0 -74
  97. package/dist/file/index.cjs +0 -1212
  98. package/dist/file/index.cjs.map +0 -1
  99. package/dist/file/index.d.cts +0 -698
  100. package/dist/lock/index.cjs +0 -226
  101. package/dist/lock/index.cjs.map +0 -1
  102. package/dist/lock/index.d.cts +0 -361
  103. package/dist/lock-redis/index.cjs +0 -113
  104. package/dist/lock-redis/index.cjs.map +0 -1
  105. package/dist/lock-redis/index.d.cts +0 -24
  106. package/dist/logger/index.cjs +0 -521
  107. package/dist/logger/index.cjs.map +0 -1
  108. package/dist/logger/index.d.cts +0 -281
  109. package/dist/orm/index.cjs +0 -2986
  110. package/dist/orm/index.cjs.map +0 -1
  111. package/dist/orm/index.d.cts +0 -2213
  112. package/dist/queue/index.cjs +0 -1044
  113. package/dist/queue/index.cjs.map +0 -1
  114. package/dist/queue/index.d.cts +0 -1265
  115. package/dist/queue-redis/index.cjs +0 -873
  116. package/dist/queue-redis/index.cjs.map +0 -1
  117. package/dist/queue-redis/index.d.cts +0 -82
  118. package/dist/redis/index.cjs +0 -153
  119. package/dist/redis/index.cjs.map +0 -1
  120. package/dist/redis/index.d.cts +0 -82
  121. package/dist/retry/index.cjs +0 -146
  122. package/dist/retry/index.cjs.map +0 -1
  123. package/dist/retry/index.d.cts +0 -172
  124. package/dist/router/index.cjs +0 -111
  125. package/dist/router/index.cjs.map +0 -1
  126. package/dist/router/index.d.cts +0 -46
  127. package/dist/scheduler/index.cjs +0 -576
  128. package/dist/scheduler/index.cjs.map +0 -1
  129. package/dist/scheduler/index.d.cts +0 -145
  130. package/dist/security/index.cjs +0 -2402
  131. package/dist/security/index.cjs.map +0 -1
  132. package/dist/security/index.d.cts +0 -598
  133. package/dist/server/index.cjs +0 -1680
  134. package/dist/server/index.cjs.map +0 -1
  135. package/dist/server/index.d.cts +0 -810
  136. package/dist/server-auth/index.cjs +0 -3146
  137. package/dist/server-auth/index.cjs.map +0 -1
  138. package/dist/server-auth/index.d.cts +0 -1164
  139. package/dist/server-cache/index.cjs +0 -252
  140. package/dist/server-cache/index.cjs.map +0 -1
  141. package/dist/server-cache/index.d.cts +0 -164
  142. package/dist/server-compress/index.cjs +0 -141
  143. package/dist/server-compress/index.cjs.map +0 -1
  144. package/dist/server-compress/index.d.cts +0 -38
  145. package/dist/server-cookies/index.cjs +0 -234
  146. package/dist/server-cookies/index.cjs.map +0 -1
  147. package/dist/server-cookies/index.d.cts +0 -144
  148. package/dist/server-cors/index.cjs +0 -201
  149. package/dist/server-cors/index.cjs.map +0 -1
  150. package/dist/server-cors/index.d.cts +0 -140
  151. package/dist/server-health/index.cjs +0 -62
  152. package/dist/server-health/index.cjs.map +0 -1
  153. package/dist/server-health/index.d.cts +0 -58
  154. package/dist/server-helmet/index.cjs +0 -131
  155. package/dist/server-helmet/index.cjs.map +0 -1
  156. package/dist/server-helmet/index.d.cts +0 -97
  157. package/dist/server-links/index.cjs +0 -992
  158. package/dist/server-links/index.cjs.map +0 -1
  159. package/dist/server-links/index.d.cts +0 -513
  160. package/dist/server-metrics/index.cjs +0 -4535
  161. package/dist/server-metrics/index.cjs.map +0 -1
  162. package/dist/server-metrics/index.d.cts +0 -35
  163. package/dist/server-multipart/index.cjs +0 -237
  164. package/dist/server-multipart/index.cjs.map +0 -1
  165. package/dist/server-multipart/index.d.cts +0 -50
  166. package/dist/server-proxy/index.cjs +0 -186
  167. package/dist/server-proxy/index.cjs.map +0 -1
  168. package/dist/server-proxy/index.d.cts +0 -234
  169. package/dist/server-rate-limit/index.cjs +0 -241
  170. package/dist/server-rate-limit/index.cjs.map +0 -1
  171. package/dist/server-rate-limit/index.d.cts +0 -183
  172. package/dist/server-security/index.cjs +0 -316
  173. package/dist/server-security/index.cjs.map +0 -1
  174. package/dist/server-security/index.d.cts +0 -173
  175. package/dist/server-static/index.cjs +0 -170
  176. package/dist/server-static/index.cjs.map +0 -1
  177. package/dist/server-static/index.d.cts +0 -121
  178. package/dist/server-swagger/index.cjs +0 -1021
  179. package/dist/server-swagger/index.cjs.map +0 -1
  180. package/dist/server-swagger/index.d.cts +0 -382
  181. package/dist/sms/index.cjs +0 -221
  182. package/dist/sms/index.cjs.map +0 -1
  183. package/dist/sms/index.d.cts +0 -130
  184. package/dist/thread/index.cjs +0 -350
  185. package/dist/thread/index.cjs.map +0 -1
  186. package/dist/thread/index.d.cts +0 -260
  187. package/dist/topic/index.cjs +0 -282
  188. package/dist/topic/index.cjs.map +0 -1
  189. package/dist/topic/index.d.cts +0 -523
  190. package/dist/topic-redis/index.cjs +0 -71
  191. package/dist/topic-redis/index.cjs.map +0 -1
  192. package/dist/topic-redis/index.d.cts +0 -42
  193. package/dist/vite/index.cjs +0 -1077
  194. package/dist/vite/index.cjs.map +0 -1
  195. package/dist/vite/index.d.cts +0 -542
  196. package/dist/websocket/index.cjs +0 -1117
  197. package/dist/websocket/index.cjs.map +0 -1
  198. package/dist/websocket/index.d.cts +0 -861
@@ -1,172 +0,0 @@
1
- import * as alepha0 from "alepha";
2
- import { AlephaError, Descriptor, DescriptorArgs, KIND } from "alepha";
3
- import { DateTimeProvider, DurationLike } from "alepha/datetime";
4
- import * as alepha_logger0 from "alepha/logger";
5
-
6
- //#region src/retry/providers/RetryProvider.d.ts
7
- interface RetryOptions<T extends (...args: any[]) => any> {
8
- /**
9
- * The function to retry.
10
- */
11
- handler: T;
12
- /**
13
- * The maximum number of attempts.
14
- *
15
- * @default 3
16
- */
17
- max?: number;
18
- /**
19
- * The backoff strategy for delays between retries.
20
- * Can be a fixed number (in ms) or a configuration object for exponential backoff.
21
- *
22
- * @default { initial: 200, factor: 2, jitter: true }
23
- */
24
- backoff?: number | RetryBackoffOptions;
25
- /**
26
- * An overall time limit for all retry attempts combined.
27
- *
28
- * e.g., `[5, 'seconds']`
29
- */
30
- maxDuration?: DurationLike;
31
- /**
32
- * A function that determines if a retry should be attempted based on the error.
33
- *
34
- * @default (error) => true (retries on any error)
35
- */
36
- when?: (error: Error) => boolean;
37
- /**
38
- * A custom callback for when a retry attempt fails.
39
- * This is called before the delay.
40
- */
41
- onError?: (error: Error, attempt: number, ...args: Parameters<T>) => void;
42
- /**
43
- * An AbortSignal to allow for external cancellation of the retry loop.
44
- */
45
- signal?: AbortSignal;
46
- /**
47
- * An additional AbortSignal to combine with the provided signal.
48
- * Used internally by $retry to handle app lifecycle.
49
- */
50
- additionalSignal?: AbortSignal;
51
- }
52
- interface RetryBackoffOptions {
53
- /**
54
- * Initial delay in milliseconds.
55
- *
56
- * @default 200
57
- */
58
- initial?: number;
59
- /**
60
- * Multiplier for each subsequent delay.
61
- *
62
- * @default 2
63
- */
64
- factor?: number;
65
- /**
66
- * Maximum delay in milliseconds.
67
- */
68
- max?: number;
69
- /**
70
- * If true, adds a random jitter to the delay to prevent thundering herd.
71
- *
72
- * @default true
73
- */
74
- jitter?: boolean;
75
- }
76
- /**
77
- * Service for executing functions with automatic retry logic.
78
- * Supports exponential backoff, max duration, conditional retries, and cancellation.
79
- */
80
- declare class RetryProvider {
81
- protected readonly log: alepha_logger0.Logger;
82
- protected readonly dateTime: DateTimeProvider;
83
- /**
84
- * Execute a function with automatic retry logic.
85
- */
86
- retry<T extends (...args: any[]) => any>(options: RetryOptions<T>, ...args: Parameters<T>): Promise<ReturnType<T>>;
87
- /**
88
- * Calculate the backoff delay for a given attempt.
89
- */
90
- protected calculateBackoff(attempt: number, options?: number | RetryBackoffOptions): number;
91
- }
92
- //#endregion
93
- //#region src/retry/descriptors/$retry.d.ts
94
- /**
95
- * Creates a function that automatically retries a handler upon failure,
96
- * with support for exponential backoff, max duration, and cancellation.
97
- */
98
- declare const $retry: {
99
- <T extends (...args: any[]) => any>(options: RetryDescriptorOptions<T>): RetryDescriptorFn<T>;
100
- [KIND]: typeof RetryDescriptor;
101
- };
102
- interface RetryDescriptorOptions<T extends (...args: any[]) => any> {
103
- /**
104
- * The function to retry.
105
- */
106
- handler: T;
107
- /**
108
- * The maximum number of attempts.
109
- *
110
- * @default 3
111
- */
112
- max?: number;
113
- /**
114
- * The backoff strategy for delays between retries.
115
- * Can be a fixed number (in ms) or a configuration object for exponential backoff.
116
- *
117
- * @default { initial: 200, factor: 2, jitter: true }
118
- */
119
- backoff?: number | RetryBackoffOptions;
120
- /**
121
- * An overall time limit for all retry attempts combined.
122
- *
123
- * e.g., `[5, 'seconds']`
124
- */
125
- maxDuration?: DurationLike;
126
- /**
127
- * A function that determines if a retry should be attempted based on the error.
128
- *
129
- * @default (error) => true (retries on any error)
130
- */
131
- when?: (error: Error) => boolean;
132
- /**
133
- * A custom callback for when a retry attempt fails.
134
- * This is called before the delay.
135
- */
136
- onError?: (error: Error, attempt: number, ...args: Parameters<T>) => void;
137
- /**
138
- * An AbortSignal to allow for external cancellation of the retry loop.
139
- */
140
- signal?: AbortSignal;
141
- }
142
- declare class RetryDescriptor<T extends (...args: any[]) => any> extends Descriptor<RetryDescriptorOptions<T>> {
143
- protected readonly retryProvider: RetryProvider;
144
- protected appAbortController: AbortController;
145
- constructor(args: DescriptorArgs<RetryDescriptorOptions<T>>);
146
- run(...args: Parameters<T>): Promise<ReturnType<T>>;
147
- }
148
- interface RetryDescriptorFn<T extends (...args: any[]) => any> extends RetryDescriptor<T> {
149
- (...args: Parameters<T>): Promise<ReturnType<T>>;
150
- }
151
- //#endregion
152
- //#region src/retry/errors/RetryCancelError.d.ts
153
- declare class RetryCancelError extends AlephaError {
154
- constructor();
155
- }
156
- //#endregion
157
- //#region src/retry/errors/RetryTimeoutError.d.ts
158
- declare class RetryTimeoutError extends AlephaError {
159
- constructor(duration: number);
160
- }
161
- //#endregion
162
- //#region src/retry/index.d.ts
163
- /**
164
- * Retry mechanism provider for Alepha applications.
165
- *
166
- * @see {@link RetryProvider}
167
- * @module alepha.retry
168
- */
169
- declare const AlephaRetry: alepha0.Service<alepha0.Module>;
170
- //#endregion
171
- export { $retry, AlephaRetry, RetryBackoffOptions, RetryCancelError, RetryDescriptor, RetryDescriptorFn, RetryDescriptorOptions, RetryOptions, RetryProvider, RetryTimeoutError };
172
- //# sourceMappingURL=index.d.cts.map
@@ -1,111 +0,0 @@
1
- let alepha = require("alepha");
2
-
3
- //#region src/router/providers/RouterProvider.ts
4
- var RouterProvider = class {
5
- routePathRegex = /^\/[A-Za-z0-9._~!$&%'()*+,;=:@{}?/-]*$/;
6
- tree = { children: {} };
7
- cache = /* @__PURE__ */ new Map();
8
- match(path) {
9
- if (this.cache.has(path)) return this.cache.get(path);
10
- const result = this.mapParams(this.createRouteMatch(path));
11
- this.cache.set(path, result);
12
- return result;
13
- }
14
- test(path) {
15
- if (!this.routePathRegex.test(path)) throw new alepha.AlephaError(`Route '${path}' is not valid`);
16
- }
17
- push(route) {
18
- const path = route.path.replaceAll("//", "/");
19
- this.test(path);
20
- const parts = this.createParts(path);
21
- let cursor = this.tree;
22
- for (let i = 0; i < parts.length; i++) {
23
- const isLast = i === parts.length - 1;
24
- let part = parts[i].toLowerCase();
25
- if (part === "*" && isLast) {
26
- cursor.wildcard = { route };
27
- break;
28
- }
29
- if (part.includes("*")) throw new alepha.AlephaError(`Route '${path}' has an invalid wildcard syntax`);
30
- if (part.includes("{") || part.includes("}")) if (part.startsWith("{") && part.endsWith("}")) part = `:${part.slice(1, -1)}`;
31
- else throw new alepha.AlephaError(`Route '${path}' has an invalid param syntax`);
32
- if (part.startsWith(":")) {
33
- const name = parts[i].slice(1).replaceAll("}", "");
34
- if (!name) throw new alepha.AlephaError(`Route '${path}' has an empty param name`);
35
- if (!cursor.param) cursor.param = {
36
- name,
37
- children: {}
38
- };
39
- else if (cursor.param.name !== name) {
40
- route.mapParams ??= {};
41
- route.mapParams[cursor.param.name] = name;
42
- }
43
- if (isLast) cursor.param.route = route;
44
- cursor = cursor.param;
45
- continue;
46
- }
47
- if (!cursor.children[part]) cursor.children[part] = { children: {} };
48
- if (isLast) cursor.children[part].route = route;
49
- cursor = cursor.children[part];
50
- }
51
- }
52
- createRouteMatch(path) {
53
- if (path[0] !== "/") throw new alepha.AlephaError(`Path '${path}' must start with "/"`);
54
- const parts = this.createParts(path);
55
- let cursor = this.tree;
56
- let wildcard;
57
- const params = {};
58
- for (let i = 0; i < parts.length; i++) {
59
- const part = parts[i].toLowerCase();
60
- if (cursor.children[part]) {
61
- if (cursor.wildcard) wildcard = cursor.wildcard;
62
- cursor = cursor.children[part];
63
- } else if (cursor.param) {
64
- if (cursor.wildcard) wildcard = cursor.wildcard;
65
- params[cursor.param.name] = parts[i];
66
- cursor = cursor.param;
67
- } else if (cursor.wildcard) {
68
- params["*"] = parts.slice(i).join("/");
69
- return {
70
- route: cursor.wildcard.route,
71
- params
72
- };
73
- } else return {
74
- route: wildcard?.route,
75
- params
76
- };
77
- }
78
- if (!cursor?.route) {
79
- if (cursor.wildcard) return {
80
- route: cursor.wildcard.route,
81
- params
82
- };
83
- return {
84
- route: wildcard?.route,
85
- params
86
- };
87
- }
88
- return {
89
- route: cursor.route,
90
- params
91
- };
92
- }
93
- mapParams(match) {
94
- if (match.route?.mapParams && match.params) {
95
- for (const [key, value] of Object.entries(match.route.mapParams)) if (match.params[key]) {
96
- match.params[value] = match.params[key];
97
- delete match.params[key];
98
- }
99
- }
100
- return match;
101
- }
102
- createParts(path) {
103
- let pathname = path.split("?")[0].replaceAll("//", "/");
104
- if (pathname.endsWith("/") && pathname.length > 1) pathname = pathname.slice(0, -1);
105
- return pathname.split("/").slice(1);
106
- }
107
- };
108
-
109
- //#endregion
110
- exports.RouterProvider = RouterProvider;
111
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","names":["AlephaError","wildcard: { route: T } | undefined","params: Record<string, string>"],"sources":["../../src/router/providers/RouterProvider.ts"],"sourcesContent":["import { AlephaError } from \"alepha\";\n\nexport abstract class RouterProvider<T extends Route = Route> {\n protected routePathRegex: RegExp = /^\\/[A-Za-z0-9._~!$&%'()*+,;=:@{}?/-]*$/;\n\n protected tree: Tree<T> = { children: {} };\n protected cache = new Map<string, RouteMatch<T>>();\n\n public match(path: string): RouteMatch<T> {\n if (this.cache.has(path)) {\n return this.cache.get(path)!;\n }\n const result = this.mapParams(this.createRouteMatch(path));\n this.cache.set(path, result);\n return result;\n }\n\n protected test(path: string): void {\n if (!this.routePathRegex.test(path)) {\n throw new AlephaError(`Route '${path}' is not valid`);\n }\n }\n\n protected push(route: T): void {\n const path = route.path.replaceAll(\"//\", \"/\");\n\n this.test(path);\n\n const parts = this.createParts(path);\n\n let cursor = this.tree;\n for (let i = 0; i < parts.length; i++) {\n const isLast = i === parts.length - 1;\n let part = parts[i].toLowerCase(); // url is case-insensitive\n if (part === \"*\" && isLast) {\n cursor.wildcard = { route };\n break;\n }\n\n if (part.includes(\"*\")) {\n throw new AlephaError(`Route '${path}' has an invalid wildcard syntax`);\n }\n\n if (part.includes(\"{\") || part.includes(\"}\")) {\n if (part.startsWith(\"{\") && part.endsWith(\"}\")) {\n part = `:${part.slice(1, -1)}`; // convert {param} to :param\n } else {\n throw new AlephaError(`Route '${path}' has an invalid param syntax`);\n }\n }\n\n if (part.startsWith(\":\")) {\n const name = parts[i].slice(1).replaceAll(\"}\", \"\");\n if (!name) {\n throw new AlephaError(`Route '${path}' has an empty param name`);\n }\n if (!cursor.param) {\n cursor.param = { name, children: {} };\n } else if (cursor.param.name !== name) {\n // damn, 2 url params with different names\n // got this case with /customers/:id and /customers/:userId/payments\n route.mapParams ??= {};\n route.mapParams[cursor.param.name] = name;\n }\n\n if (isLast) {\n cursor.param.route = route;\n }\n\n cursor = cursor.param;\n continue;\n }\n\n if (!cursor.children[part]) {\n cursor.children[part] = { children: {} };\n }\n\n if (isLast) {\n cursor.children[part].route = route;\n }\n\n cursor = cursor.children[part];\n }\n }\n\n protected createRouteMatch(path: string): RouteMatch<T> {\n if (path[0] !== \"/\") {\n throw new AlephaError(`Path '${path}' must start with \"/\"`);\n }\n\n const parts = this.createParts(path);\n\n let cursor = this.tree;\n let wildcard: { route: T } | undefined;\n const params: Record<string, string> = {};\n\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i].toLowerCase(); // url is case-insensitive\n if (cursor.children[part]) {\n if (cursor.wildcard) {\n wildcard = cursor.wildcard;\n }\n cursor = cursor.children[part];\n } else if (cursor.param) {\n if (cursor.wildcard) {\n wildcard = cursor.wildcard;\n }\n params[cursor.param.name] = parts[i];\n cursor = cursor.param;\n } else if (cursor.wildcard) {\n params[\"*\"] = parts.slice(i).join(\"/\");\n return { route: cursor.wildcard.route, params };\n } else {\n return { route: wildcard?.route, params };\n }\n }\n\n if (!cursor?.route) {\n // when \"/a/*\" - trigger if \"/a\"\n if (cursor.wildcard) {\n return { route: cursor.wildcard.route, params };\n }\n // return deep wildcard or nothing\n return { route: wildcard?.route, params };\n }\n\n return { route: cursor.route, params };\n }\n\n protected mapParams(match: RouteMatch<T>): RouteMatch<T> {\n if (match.route?.mapParams && match.params) {\n for (const [key, value] of Object.entries(match.route.mapParams)) {\n if (match.params[key]) {\n match.params[value] = match.params[key];\n delete match.params[key];\n }\n }\n }\n\n return match;\n }\n\n protected createParts(path: string): string[] {\n let pathname = path.split(\"?\")[0].replaceAll(\"//\", \"/\");\n\n // remove trailing slash\n if (pathname.endsWith(\"/\") && pathname.length > 1) {\n pathname = pathname.slice(0, -1);\n }\n\n return pathname.split(\"/\").slice(1);\n }\n}\n\nexport interface RouteMatch<T extends Route> {\n route?: T;\n params?: Record<string, string>;\n}\n\nexport interface Route {\n path: string;\n\n /**\n * Rename a param in the route.\n * This is automatically filled when you have scenarios like:\n * `/customers/:id` and `/customers/:userId/payments`\n *\n * In this case, `:id` will be renamed to `:userId` in the second route.\n */\n mapParams?: Record<string, string>;\n}\n\nexport interface Tree<T extends Route> {\n route?: T;\n children: {\n [key: string]: Tree<T>;\n };\n param?: {\n route?: T;\n name: string;\n children: {\n [key: string]: Tree<T>;\n };\n };\n wildcard?: {\n route: T;\n };\n}\n"],"mappings":"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"}
@@ -1,46 +0,0 @@
1
- //#region src/router/providers/RouterProvider.d.ts
2
- declare abstract class RouterProvider<T extends Route = Route> {
3
- protected routePathRegex: RegExp;
4
- protected tree: Tree<T>;
5
- protected cache: Map<string, RouteMatch<T>>;
6
- match(path: string): RouteMatch<T>;
7
- protected test(path: string): void;
8
- protected push(route: T): void;
9
- protected createRouteMatch(path: string): RouteMatch<T>;
10
- protected mapParams(match: RouteMatch<T>): RouteMatch<T>;
11
- protected createParts(path: string): string[];
12
- }
13
- interface RouteMatch<T extends Route> {
14
- route?: T;
15
- params?: Record<string, string>;
16
- }
17
- interface Route {
18
- path: string;
19
- /**
20
- * Rename a param in the route.
21
- * This is automatically filled when you have scenarios like:
22
- * `/customers/:id` and `/customers/:userId/payments`
23
- *
24
- * In this case, `:id` will be renamed to `:userId` in the second route.
25
- */
26
- mapParams?: Record<string, string>;
27
- }
28
- interface Tree<T extends Route> {
29
- route?: T;
30
- children: {
31
- [key: string]: Tree<T>;
32
- };
33
- param?: {
34
- route?: T;
35
- name: string;
36
- children: {
37
- [key: string]: Tree<T>;
38
- };
39
- };
40
- wildcard?: {
41
- route: T;
42
- };
43
- }
44
- //#endregion
45
- export { Route, RouteMatch, RouterProvider, Tree };
46
- //# sourceMappingURL=index.d.cts.map