@h3ravel/url 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,298 @@
1
+ /// <reference path="./app.globals.d.ts" />
2
+ import { ExtractControllerMethods } from "@h3ravel/shared";
3
+ import { Application, ServiceProvider } from "@h3ravel/core";
4
+
5
+ //#region src/RequestAwareHelpers.d.ts
6
+
7
+ /**
8
+ * Request-aware URL helper class
9
+ */
10
+ declare class RequestAwareHelpers {
11
+ private app;
12
+ private readonly baseUrl;
13
+ constructor(app: Application);
14
+ /**
15
+ * Get the current request instance
16
+ */
17
+ private getCurrentRequest;
18
+ /**
19
+ * Get the current request URL (path only, no query string)
20
+ */
21
+ current(): string;
22
+ /**
23
+ * Get the full current URL with query string
24
+ */
25
+ full(): string;
26
+ /**
27
+ * Get the previous request URL from session or referrer
28
+ */
29
+ previous(): string;
30
+ /**
31
+ * Get the previous request path (without query string)
32
+ */
33
+ previousPath(): string;
34
+ /**
35
+ * Get the current query parameters
36
+ */
37
+ query(): RouteParams;
38
+ }
39
+ /**
40
+ * Global helper function factory
41
+ */
42
+ declare function createUrlHelper(app: Application): () => RequestAwareHelpers;
43
+ //#endregion
44
+ //#region src/Url.d.ts
45
+ /**
46
+ * URL builder class with fluent API and request-aware helpers
47
+ */
48
+ declare class Url {
49
+ private readonly _scheme?;
50
+ private readonly _host?;
51
+ private readonly _port?;
52
+ private readonly _path;
53
+ private readonly _query;
54
+ private readonly _fragment?;
55
+ private readonly app?;
56
+ private constructor();
57
+ /**
58
+ * Create a URL from a full URL string
59
+ */
60
+ static of(url: string, app?: Application): Url;
61
+ /**
62
+ * Create a URL from a path relative to the app URL
63
+ */
64
+ static to(path: string, app?: Application): Url;
65
+ /**
66
+ * Create a URL from a named route
67
+ */
68
+ static route<TName extends string = string, TParams extends RouteParams = RouteParams>(name: TName, params?: TParams, app?: Application): Url;
69
+ /**
70
+ * Create a signed URL from a named route
71
+ */
72
+ static signedRoute<TName extends string = string, TParams extends RouteParams = RouteParams>(name: TName, params?: TParams, app?: Application): Url;
73
+ /**
74
+ * Create a temporary signed URL from a named route
75
+ */
76
+ static temporarySignedRoute<TName extends string = string, TParams extends RouteParams = RouteParams>(name: TName, params: TParams | undefined, expiration: number, app?: Application): Url;
77
+ /**
78
+ * Create a URL from a controller action
79
+ */
80
+ static action<C extends new (...args: any) => any>(controller: string | [C, methodName: ExtractControllerMethods<InstanceType<C>>], params?: Record<string, any>, app?: Application): Url;
81
+ /**
82
+ * Set the scheme (protocol) of the URL
83
+ */
84
+ withScheme(scheme: string): Url;
85
+ /**
86
+ * Set the host of the URL
87
+ */
88
+ withHost(host: string): Url;
89
+ /**
90
+ * Set the port of the URL
91
+ */
92
+ withPort(port: number): Url;
93
+ /**
94
+ * Set the path of the URL
95
+ */
96
+ withPath(path: string): Url;
97
+ /**
98
+ * Set the query parameters of the URL
99
+ */
100
+ withQuery(query: Record<string, unknown>): Url;
101
+ /**
102
+ * Merge additional query parameters
103
+ */
104
+ withQueryParams(params: Record<string, unknown>): Url;
105
+ /**
106
+ * Set the fragment (hash) of the URL
107
+ */
108
+ withFragment(fragment: string): Url;
109
+ /**
110
+ * Add a signature to the URL for security
111
+ */
112
+ withSignature(app?: Application, expiration?: number): Url;
113
+ /**
114
+ * Verify if a URL signature is valid
115
+ */
116
+ hasValidSignature(app?: Application): boolean;
117
+ /**
118
+ * Convert the URL to its string representation
119
+ */
120
+ toString(): string;
121
+ /**
122
+ * Get the scheme
123
+ */
124
+ getScheme(): string | undefined;
125
+ /**
126
+ * Get the host
127
+ */
128
+ getHost(): string | undefined;
129
+ /**
130
+ * Get the port
131
+ */
132
+ getPort(): number | undefined;
133
+ /**
134
+ * Get the path
135
+ */
136
+ getPath(): string;
137
+ /**
138
+ * Get the query parameters
139
+ */
140
+ getQuery(): Record<string, unknown>;
141
+ /**
142
+ * Get the fragment
143
+ */
144
+ getFragment(): string | undefined;
145
+ }
146
+ //#endregion
147
+ //#region src/Contracts/UrlContract.d.ts
148
+ type RouteParams<N = any> = Record<string, N>;
149
+ /**
150
+ * Contract for URL manipulation and generation
151
+ */
152
+ interface UrlContract {
153
+ /**
154
+ * Set the scheme (protocol) of the URL
155
+ */
156
+ withScheme(scheme: string): this;
157
+ /**
158
+ * Set the host of the URL
159
+ */
160
+ withHost(host: string): this;
161
+ /**
162
+ * Set the port of the URL
163
+ */
164
+ withPort(port: number): this;
165
+ /**
166
+ * Set the path of the URL
167
+ */
168
+ withPath(path: string): this;
169
+ /**
170
+ * Set the query parameters of the URL
171
+ */
172
+ withQuery(query: Record<string, any>): this;
173
+ /**
174
+ * Set the fragment (hash) of the URL
175
+ */
176
+ withFragment(fragment: string): this;
177
+ /**
178
+ * Convert the URL to its string representation
179
+ */
180
+ toString(): string;
181
+ }
182
+ /**
183
+ * Contract for request-aware URL helpers
184
+ */
185
+ interface RequestAwareUrlContract {
186
+ /**
187
+ * Get the current request URL
188
+ */
189
+ current(): string;
190
+ /**
191
+ * Get the full current URL with query string
192
+ */
193
+ full(): string;
194
+ /**
195
+ * Get the previous request URL
196
+ */
197
+ previous(): string;
198
+ /**
199
+ * Get the previous request path (without query string)
200
+ */
201
+ previousPath(): string;
202
+ /**
203
+ * Get the current query parameters
204
+ */
205
+ query(): Record<string, any>;
206
+ }
207
+ /**
208
+ * The Url Helper Contract
209
+ */
210
+ interface HelpersContract {
211
+ /**
212
+ * Create a URL from a path relative to the app URL
213
+ */
214
+ to: (path: string) => Url;
215
+ /**
216
+ * Create a URL from a named route
217
+ */
218
+ route: (name: string, params?: Record<string, any>) => string;
219
+ /**
220
+ * Create a signed URL from a named route
221
+ *
222
+ * @param name
223
+ * @param params
224
+ * @returns
225
+ */
226
+ signedRoute: (name: string, params?: Record<string, any>) => Url;
227
+ /**
228
+ * Create a temporary signed URL from a named route
229
+ *
230
+ * @param name
231
+ * @param params
232
+ * @param expiration
233
+ * @returns
234
+ */
235
+ temporarySignedRoute: (name: string, params: Record<string, any> | undefined, expiration: number) => Url;
236
+ /**
237
+ * Create a URL from a controller action
238
+ */
239
+ action: <C extends new (...args: any) => any>(controller: string | [C, methodName: ExtractControllerMethods<InstanceType<C>>], params?: Record<string, any>) => string;
240
+ /**
241
+ * Get request-aware URL helpers
242
+ */
243
+ url: {
244
+ (): RequestAwareHelpers;
245
+ (path: string): string;
246
+ };
247
+ }
248
+ //#endregion
249
+ //#region src/Helpers.d.ts
250
+ /**
251
+ * Global helper functions for URL manipulation
252
+ */
253
+ /**
254
+ * Create a URL from a path relative to the app URL
255
+ */
256
+ declare function to(path: string, app?: Application): Url;
257
+ /**
258
+ * Create a URL from a named route
259
+ */
260
+ declare function route<TName extends string, TParams extends Record<string, string> = Record<string, string>>(name: TName, params?: TParams, app?: Application): Url;
261
+ /**
262
+ * Create a signed URL from a named route
263
+ */
264
+ declare function signedRoute<TName extends string, TParams extends Record<string, string> = Record<string, string>>(name: TName, params?: TParams, app?: Application): Url;
265
+ /**
266
+ * Create a temporary signed URL from a named route
267
+ */
268
+ declare function temporarySignedRoute(name: string, params: Record<string, string> | undefined, expiration: number, app?: Application): Url;
269
+ /**
270
+ * Create a URL from a controller action
271
+ */
272
+ declare function action(controller: string, app?: Application): Url;
273
+ /**
274
+ * Get request-aware URL helpers
275
+ */
276
+ declare function url(app?: Application): RequestAwareHelpers;
277
+ /**
278
+ * Create URL helpers that are bound to an application instance
279
+ */
280
+ declare function createUrlHelpers(app: Application): HelpersContract;
281
+ //#endregion
282
+ //#region src/Providers/UrlServiceProvider.d.ts
283
+ /**
284
+ * Service provider for URL utilities
285
+ */
286
+ declare class UrlServiceProvider extends ServiceProvider {
287
+ /**
288
+ * Register URL services in the container
289
+ */
290
+ register(): void;
291
+ /**
292
+ * Boot URL services
293
+ */
294
+ boot(): void;
295
+ }
296
+ //#endregion
297
+ export { HelpersContract, RequestAwareHelpers, RequestAwareUrlContract, RouteParams, Url, UrlContract, UrlServiceProvider, action, createUrlHelper, createUrlHelpers, route, signedRoute, temporarySignedRoute, to, url };
298
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1,298 @@
1
+ /// <reference path="./app.globals.d.ts" />
2
+ import { Application, ServiceProvider } from "@h3ravel/core";
3
+ import { ExtractControllerMethods } from "@h3ravel/shared";
4
+
5
+ //#region src/RequestAwareHelpers.d.ts
6
+
7
+ /**
8
+ * Request-aware URL helper class
9
+ */
10
+ declare class RequestAwareHelpers {
11
+ private app;
12
+ private readonly baseUrl;
13
+ constructor(app: Application);
14
+ /**
15
+ * Get the current request instance
16
+ */
17
+ private getCurrentRequest;
18
+ /**
19
+ * Get the current request URL (path only, no query string)
20
+ */
21
+ current(): string;
22
+ /**
23
+ * Get the full current URL with query string
24
+ */
25
+ full(): string;
26
+ /**
27
+ * Get the previous request URL from session or referrer
28
+ */
29
+ previous(): string;
30
+ /**
31
+ * Get the previous request path (without query string)
32
+ */
33
+ previousPath(): string;
34
+ /**
35
+ * Get the current query parameters
36
+ */
37
+ query(): RouteParams;
38
+ }
39
+ /**
40
+ * Global helper function factory
41
+ */
42
+ declare function createUrlHelper(app: Application): () => RequestAwareHelpers;
43
+ //#endregion
44
+ //#region src/Url.d.ts
45
+ /**
46
+ * URL builder class with fluent API and request-aware helpers
47
+ */
48
+ declare class Url {
49
+ private readonly _scheme?;
50
+ private readonly _host?;
51
+ private readonly _port?;
52
+ private readonly _path;
53
+ private readonly _query;
54
+ private readonly _fragment?;
55
+ private readonly app?;
56
+ private constructor();
57
+ /**
58
+ * Create a URL from a full URL string
59
+ */
60
+ static of(url: string, app?: Application): Url;
61
+ /**
62
+ * Create a URL from a path relative to the app URL
63
+ */
64
+ static to(path: string, app?: Application): Url;
65
+ /**
66
+ * Create a URL from a named route
67
+ */
68
+ static route<TName extends string = string, TParams extends RouteParams = RouteParams>(name: TName, params?: TParams, app?: Application): Url;
69
+ /**
70
+ * Create a signed URL from a named route
71
+ */
72
+ static signedRoute<TName extends string = string, TParams extends RouteParams = RouteParams>(name: TName, params?: TParams, app?: Application): Url;
73
+ /**
74
+ * Create a temporary signed URL from a named route
75
+ */
76
+ static temporarySignedRoute<TName extends string = string, TParams extends RouteParams = RouteParams>(name: TName, params: TParams | undefined, expiration: number, app?: Application): Url;
77
+ /**
78
+ * Create a URL from a controller action
79
+ */
80
+ static action<C extends new (...args: any) => any>(controller: string | [C, methodName: ExtractControllerMethods<InstanceType<C>>], params?: Record<string, any>, app?: Application): Url;
81
+ /**
82
+ * Set the scheme (protocol) of the URL
83
+ */
84
+ withScheme(scheme: string): Url;
85
+ /**
86
+ * Set the host of the URL
87
+ */
88
+ withHost(host: string): Url;
89
+ /**
90
+ * Set the port of the URL
91
+ */
92
+ withPort(port: number): Url;
93
+ /**
94
+ * Set the path of the URL
95
+ */
96
+ withPath(path: string): Url;
97
+ /**
98
+ * Set the query parameters of the URL
99
+ */
100
+ withQuery(query: Record<string, unknown>): Url;
101
+ /**
102
+ * Merge additional query parameters
103
+ */
104
+ withQueryParams(params: Record<string, unknown>): Url;
105
+ /**
106
+ * Set the fragment (hash) of the URL
107
+ */
108
+ withFragment(fragment: string): Url;
109
+ /**
110
+ * Add a signature to the URL for security
111
+ */
112
+ withSignature(app?: Application, expiration?: number): Url;
113
+ /**
114
+ * Verify if a URL signature is valid
115
+ */
116
+ hasValidSignature(app?: Application): boolean;
117
+ /**
118
+ * Convert the URL to its string representation
119
+ */
120
+ toString(): string;
121
+ /**
122
+ * Get the scheme
123
+ */
124
+ getScheme(): string | undefined;
125
+ /**
126
+ * Get the host
127
+ */
128
+ getHost(): string | undefined;
129
+ /**
130
+ * Get the port
131
+ */
132
+ getPort(): number | undefined;
133
+ /**
134
+ * Get the path
135
+ */
136
+ getPath(): string;
137
+ /**
138
+ * Get the query parameters
139
+ */
140
+ getQuery(): Record<string, unknown>;
141
+ /**
142
+ * Get the fragment
143
+ */
144
+ getFragment(): string | undefined;
145
+ }
146
+ //#endregion
147
+ //#region src/Contracts/UrlContract.d.ts
148
+ type RouteParams<N = any> = Record<string, N>;
149
+ /**
150
+ * Contract for URL manipulation and generation
151
+ */
152
+ interface UrlContract {
153
+ /**
154
+ * Set the scheme (protocol) of the URL
155
+ */
156
+ withScheme(scheme: string): this;
157
+ /**
158
+ * Set the host of the URL
159
+ */
160
+ withHost(host: string): this;
161
+ /**
162
+ * Set the port of the URL
163
+ */
164
+ withPort(port: number): this;
165
+ /**
166
+ * Set the path of the URL
167
+ */
168
+ withPath(path: string): this;
169
+ /**
170
+ * Set the query parameters of the URL
171
+ */
172
+ withQuery(query: Record<string, any>): this;
173
+ /**
174
+ * Set the fragment (hash) of the URL
175
+ */
176
+ withFragment(fragment: string): this;
177
+ /**
178
+ * Convert the URL to its string representation
179
+ */
180
+ toString(): string;
181
+ }
182
+ /**
183
+ * Contract for request-aware URL helpers
184
+ */
185
+ interface RequestAwareUrlContract {
186
+ /**
187
+ * Get the current request URL
188
+ */
189
+ current(): string;
190
+ /**
191
+ * Get the full current URL with query string
192
+ */
193
+ full(): string;
194
+ /**
195
+ * Get the previous request URL
196
+ */
197
+ previous(): string;
198
+ /**
199
+ * Get the previous request path (without query string)
200
+ */
201
+ previousPath(): string;
202
+ /**
203
+ * Get the current query parameters
204
+ */
205
+ query(): Record<string, any>;
206
+ }
207
+ /**
208
+ * The Url Helper Contract
209
+ */
210
+ interface HelpersContract {
211
+ /**
212
+ * Create a URL from a path relative to the app URL
213
+ */
214
+ to: (path: string) => Url;
215
+ /**
216
+ * Create a URL from a named route
217
+ */
218
+ route: (name: string, params?: Record<string, any>) => string;
219
+ /**
220
+ * Create a signed URL from a named route
221
+ *
222
+ * @param name
223
+ * @param params
224
+ * @returns
225
+ */
226
+ signedRoute: (name: string, params?: Record<string, any>) => Url;
227
+ /**
228
+ * Create a temporary signed URL from a named route
229
+ *
230
+ * @param name
231
+ * @param params
232
+ * @param expiration
233
+ * @returns
234
+ */
235
+ temporarySignedRoute: (name: string, params: Record<string, any> | undefined, expiration: number) => Url;
236
+ /**
237
+ * Create a URL from a controller action
238
+ */
239
+ action: <C extends new (...args: any) => any>(controller: string | [C, methodName: ExtractControllerMethods<InstanceType<C>>], params?: Record<string, any>) => string;
240
+ /**
241
+ * Get request-aware URL helpers
242
+ */
243
+ url: {
244
+ (): RequestAwareHelpers;
245
+ (path: string): string;
246
+ };
247
+ }
248
+ //#endregion
249
+ //#region src/Helpers.d.ts
250
+ /**
251
+ * Global helper functions for URL manipulation
252
+ */
253
+ /**
254
+ * Create a URL from a path relative to the app URL
255
+ */
256
+ declare function to(path: string, app?: Application): Url;
257
+ /**
258
+ * Create a URL from a named route
259
+ */
260
+ declare function route<TName extends string, TParams extends Record<string, string> = Record<string, string>>(name: TName, params?: TParams, app?: Application): Url;
261
+ /**
262
+ * Create a signed URL from a named route
263
+ */
264
+ declare function signedRoute<TName extends string, TParams extends Record<string, string> = Record<string, string>>(name: TName, params?: TParams, app?: Application): Url;
265
+ /**
266
+ * Create a temporary signed URL from a named route
267
+ */
268
+ declare function temporarySignedRoute(name: string, params: Record<string, string> | undefined, expiration: number, app?: Application): Url;
269
+ /**
270
+ * Create a URL from a controller action
271
+ */
272
+ declare function action(controller: string, app?: Application): Url;
273
+ /**
274
+ * Get request-aware URL helpers
275
+ */
276
+ declare function url(app?: Application): RequestAwareHelpers;
277
+ /**
278
+ * Create URL helpers that are bound to an application instance
279
+ */
280
+ declare function createUrlHelpers(app: Application): HelpersContract;
281
+ //#endregion
282
+ //#region src/Providers/UrlServiceProvider.d.ts
283
+ /**
284
+ * Service provider for URL utilities
285
+ */
286
+ declare class UrlServiceProvider extends ServiceProvider {
287
+ /**
288
+ * Register URL services in the container
289
+ */
290
+ register(): void;
291
+ /**
292
+ * Boot URL services
293
+ */
294
+ boot(): void;
295
+ }
296
+ //#endregion
297
+ export { HelpersContract, RequestAwareHelpers, RequestAwareUrlContract, RouteParams, Url, UrlContract, UrlServiceProvider, action, createUrlHelper, createUrlHelpers, route, signedRoute, temporarySignedRoute, to, url };
298
+ //# sourceMappingURL=index.d.ts.map