@h3ravel/url 1.0.15 → 1.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.globals.d.ts +2 -14
- package/dist/index.cjs +18 -15
- package/dist/index.d.ts +20 -123
- package/dist/index.js +7 -8
- package/package.json +5 -13
package/dist/app.globals.d.ts
CHANGED
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { RequestAwareHelpers, Url } from '.'
|
|
1
|
+
import { ExtractClassMethods } from '@h3ravel/shared'
|
|
3
2
|
|
|
4
3
|
export { }
|
|
5
4
|
|
|
6
5
|
declare global {
|
|
7
|
-
/**
|
|
8
|
-
* Create a URL from a named route
|
|
9
|
-
*/
|
|
10
|
-
function route (name: string, params?: Record<string, any>): string;
|
|
11
|
-
|
|
12
6
|
/**
|
|
13
7
|
* Create a URL from a controller action
|
|
14
8
|
*/
|
|
15
9
|
function action<C extends new (...args: any) => any> (
|
|
16
|
-
controller: string | [C, methodName:
|
|
10
|
+
controller: string | [C, methodName: ExtractClassMethods<InstanceType<C>>],
|
|
17
11
|
params?: Record<string, any>
|
|
18
12
|
): string;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Get request-aware URL helpers
|
|
22
|
-
*/
|
|
23
|
-
function url (): RequestAwareHelpers;
|
|
24
|
-
function url (path: string): string;
|
|
25
13
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -6,12 +6,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __copyProps = (to$1, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to$1, key) && key !== except) {
|
|
13
|
+
__defProp(to$1, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
return to$1;
|
|
17
21
|
};
|
|
@@ -21,7 +25,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
25
|
}) : target, mod));
|
|
22
26
|
|
|
23
27
|
//#endregion
|
|
24
|
-
let
|
|
28
|
+
let __h3ravel_foundation = require("@h3ravel/foundation");
|
|
25
29
|
let __h3ravel_support = require("@h3ravel/support");
|
|
26
30
|
let node_path = require("node:path");
|
|
27
31
|
node_path = __toESM(node_path);
|
|
@@ -86,7 +90,7 @@ var RequestAwareHelpers = class {
|
|
|
86
90
|
* Get the current query parameters
|
|
87
91
|
*/
|
|
88
92
|
query() {
|
|
89
|
-
return this.getCurrentRequest().
|
|
93
|
+
return this.getCurrentRequest()._query || {};
|
|
90
94
|
}
|
|
91
95
|
};
|
|
92
96
|
/**
|
|
@@ -149,10 +153,7 @@ var Url = class Url {
|
|
|
149
153
|
*/
|
|
150
154
|
static route(name, params = {}, app) {
|
|
151
155
|
if (!app) throw new Error("Application instance required for route generation");
|
|
152
|
-
const
|
|
153
|
-
if (!router || typeof router.route !== "function") throw new Error("Router not available or does not support route generation");
|
|
154
|
-
if (typeof router.route !== "function") throw new Error("Router does not support route generation");
|
|
155
|
-
const routeUrl = router.route(name, params);
|
|
156
|
+
const routeUrl = app.make("url").route(name, params);
|
|
156
157
|
if (!routeUrl) throw new Error(`Route "${name}" not found`);
|
|
157
158
|
return Url.to(routeUrl, app);
|
|
158
159
|
}
|
|
@@ -240,7 +241,7 @@ var Url = class Url {
|
|
|
240
241
|
try {
|
|
241
242
|
key = config("app.key");
|
|
242
243
|
} catch {}
|
|
243
|
-
if (!key) throw new
|
|
244
|
+
if (!key) throw new __h3ravel_foundation.ConfigException("APP_KEY and app.key", "any", this);
|
|
244
245
|
const url$1 = this.toString();
|
|
245
246
|
const queryParams = { ...this._query };
|
|
246
247
|
if (expiration) queryParams.expires = Math.floor(expiration / 1e3);
|
|
@@ -395,12 +396,14 @@ function createUrlHelpers(app) {
|
|
|
395
396
|
/**
|
|
396
397
|
* Service provider for URL utilities
|
|
397
398
|
*/
|
|
398
|
-
var UrlServiceProvider = class extends
|
|
399
|
+
var UrlServiceProvider = class extends __h3ravel_support.ServiceProvider {
|
|
399
400
|
static priority = 897;
|
|
400
401
|
/**
|
|
401
402
|
* Register URL services in the container
|
|
402
403
|
*/
|
|
403
|
-
register() {
|
|
404
|
+
register() {
|
|
405
|
+
this.app.setUriResolver(() => Url);
|
|
406
|
+
}
|
|
404
407
|
/**
|
|
405
408
|
* Boot URL services
|
|
406
409
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
/// <reference path="./app.globals.d.ts" />
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ExtractClassMethods, IApplication, IUrlHelpers, RouteParams } from "@h3ravel/contracts";
|
|
3
|
+
import { ServiceProvider } from "@h3ravel/support";
|
|
4
4
|
|
|
5
5
|
//#region src/RequestAwareHelpers.d.ts
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* Request-aware URL helper class
|
|
9
8
|
*/
|
|
10
9
|
declare class RequestAwareHelpers {
|
|
11
10
|
private app;
|
|
12
11
|
private readonly baseUrl;
|
|
13
|
-
constructor(app:
|
|
12
|
+
constructor(app: IApplication);
|
|
14
13
|
/**
|
|
15
14
|
* Get the current request instance
|
|
16
15
|
*/
|
|
@@ -39,7 +38,7 @@ declare class RequestAwareHelpers {
|
|
|
39
38
|
/**
|
|
40
39
|
* Global helper function factory
|
|
41
40
|
*/
|
|
42
|
-
declare function createUrlHelper(app:
|
|
41
|
+
declare function createUrlHelper(app: IApplication): () => RequestAwareHelpers;
|
|
43
42
|
//#endregion
|
|
44
43
|
//#region src/Url.d.ts
|
|
45
44
|
/**
|
|
@@ -57,27 +56,27 @@ declare class Url {
|
|
|
57
56
|
/**
|
|
58
57
|
* Create a URL from a full URL string
|
|
59
58
|
*/
|
|
60
|
-
static of(url: string, app?:
|
|
59
|
+
static of(url: string, app?: IApplication): Url;
|
|
61
60
|
/**
|
|
62
61
|
* Create a URL from a path relative to the app URL
|
|
63
62
|
*/
|
|
64
|
-
static to(path: string, app?:
|
|
63
|
+
static to(path: string, app?: IApplication): Url;
|
|
65
64
|
/**
|
|
66
65
|
* Create a URL from a named route
|
|
67
66
|
*/
|
|
68
|
-
static route<TName extends string = string, TParams extends RouteParams = RouteParams>(name: TName, params?: TParams, app?:
|
|
67
|
+
static route<TName extends string = string, TParams extends RouteParams = RouteParams>(name: TName, params?: TParams, app?: IApplication): Url;
|
|
69
68
|
/**
|
|
70
69
|
* Create a signed URL from a named route
|
|
71
70
|
*/
|
|
72
|
-
static signedRoute<TName extends string = string, TParams extends RouteParams = RouteParams>(name: TName, params?: TParams, app?:
|
|
71
|
+
static signedRoute<TName extends string = string, TParams extends RouteParams = RouteParams>(name: TName, params?: TParams, app?: IApplication): Url;
|
|
73
72
|
/**
|
|
74
73
|
* Create a temporary signed URL from a named route
|
|
75
74
|
*/
|
|
76
|
-
static temporarySignedRoute<TName extends string = string, TParams extends RouteParams = RouteParams>(name: TName, params: TParams | undefined, expiration: number, app?:
|
|
75
|
+
static temporarySignedRoute<TName extends string = string, TParams extends RouteParams = RouteParams>(name: TName, params: TParams | undefined, expiration: number, app?: IApplication): Url;
|
|
77
76
|
/**
|
|
78
77
|
* Create a URL from a controller action
|
|
79
78
|
*/
|
|
80
|
-
static action<C extends new (...args: any) => any>(controller: string | [C, methodName:
|
|
79
|
+
static action<C extends new (...args: any) => any>(controller: string | [C, methodName: ExtractClassMethods<InstanceType<C>>], params?: Record<string, any>, app?: IApplication): Url;
|
|
81
80
|
/**
|
|
82
81
|
* Set the scheme (protocol) of the URL
|
|
83
82
|
*/
|
|
@@ -109,11 +108,11 @@ declare class Url {
|
|
|
109
108
|
/**
|
|
110
109
|
* Add a signature to the URL for security
|
|
111
110
|
*/
|
|
112
|
-
withSignature(app?:
|
|
111
|
+
withSignature(app?: IApplication, expiration?: number): Url;
|
|
113
112
|
/**
|
|
114
113
|
* Verify if a URL signature is valid
|
|
115
114
|
*/
|
|
116
|
-
hasValidSignature(app?:
|
|
115
|
+
hasValidSignature(app?: IApplication): boolean;
|
|
117
116
|
/**
|
|
118
117
|
* Convert the URL to its string representation
|
|
119
118
|
*/
|
|
@@ -144,108 +143,6 @@ declare class Url {
|
|
|
144
143
|
getFragment(): string | undefined;
|
|
145
144
|
}
|
|
146
145
|
//#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
146
|
//#region src/Helpers.d.ts
|
|
250
147
|
/**
|
|
251
148
|
* Global helper functions for URL manipulation
|
|
@@ -253,31 +150,31 @@ interface HelpersContract {
|
|
|
253
150
|
/**
|
|
254
151
|
* Create a URL from a path relative to the app URL
|
|
255
152
|
*/
|
|
256
|
-
declare function to(path: string, app?:
|
|
153
|
+
declare function to(path: string, app?: IApplication): Url;
|
|
257
154
|
/**
|
|
258
155
|
* Create a URL from a named route
|
|
259
156
|
*/
|
|
260
|
-
declare function route<TName extends string, TParams extends Record<string, string> = Record<string, string>>(name: TName, params?: TParams, app?:
|
|
157
|
+
declare function route<TName extends string, TParams extends Record<string, string> = Record<string, string>>(name: TName, params?: TParams, app?: IApplication): Url;
|
|
261
158
|
/**
|
|
262
159
|
* Create a signed URL from a named route
|
|
263
160
|
*/
|
|
264
|
-
declare function signedRoute<TName extends string, TParams extends Record<string, string> = Record<string, string>>(name: TName, params?: TParams, app?:
|
|
161
|
+
declare function signedRoute<TName extends string, TParams extends Record<string, string> = Record<string, string>>(name: TName, params?: TParams, app?: IApplication): Url;
|
|
265
162
|
/**
|
|
266
163
|
* Create a temporary signed URL from a named route
|
|
267
164
|
*/
|
|
268
|
-
declare function temporarySignedRoute(name: string, params: Record<string, string> | undefined, expiration: number, app?:
|
|
165
|
+
declare function temporarySignedRoute(name: string, params: Record<string, string> | undefined, expiration: number, app?: IApplication): Url;
|
|
269
166
|
/**
|
|
270
167
|
* Create a URL from a controller action
|
|
271
168
|
*/
|
|
272
|
-
declare function action(controller: string, app?:
|
|
169
|
+
declare function action(controller: string, app?: IApplication): Url;
|
|
273
170
|
/**
|
|
274
171
|
* Get request-aware URL helpers
|
|
275
172
|
*/
|
|
276
|
-
declare function url(app?:
|
|
173
|
+
declare function url(app?: IApplication): RequestAwareHelpers;
|
|
277
174
|
/**
|
|
278
175
|
* Create URL helpers that are bound to an application instance
|
|
279
176
|
*/
|
|
280
|
-
declare function createUrlHelpers(app:
|
|
177
|
+
declare function createUrlHelpers(app: IApplication): IUrlHelpers;
|
|
281
178
|
//#endregion
|
|
282
179
|
//#region src/Providers/UrlServiceProvider.d.ts
|
|
283
180
|
/**
|
|
@@ -295,4 +192,4 @@ declare class UrlServiceProvider extends ServiceProvider {
|
|
|
295
192
|
boot(): void;
|
|
296
193
|
}
|
|
297
194
|
//#endregion
|
|
298
|
-
export {
|
|
195
|
+
export { RequestAwareHelpers, Url, UrlServiceProvider, action, createUrlHelper, createUrlHelpers, route, signedRoute, temporarySignedRoute, to, url };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ConfigException
|
|
2
|
-
import { hmac } from "@h3ravel/support";
|
|
1
|
+
import { ConfigException } from "@h3ravel/foundation";
|
|
2
|
+
import { ServiceProvider, hmac } from "@h3ravel/support";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
5
5
|
//#region src/RequestAwareHelpers.ts
|
|
@@ -62,7 +62,7 @@ var RequestAwareHelpers = class {
|
|
|
62
62
|
* Get the current query parameters
|
|
63
63
|
*/
|
|
64
64
|
query() {
|
|
65
|
-
return this.getCurrentRequest().
|
|
65
|
+
return this.getCurrentRequest()._query || {};
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
68
|
/**
|
|
@@ -125,10 +125,7 @@ var Url = class Url {
|
|
|
125
125
|
*/
|
|
126
126
|
static route(name, params = {}, app) {
|
|
127
127
|
if (!app) throw new Error("Application instance required for route generation");
|
|
128
|
-
const
|
|
129
|
-
if (!router || typeof router.route !== "function") throw new Error("Router not available or does not support route generation");
|
|
130
|
-
if (typeof router.route !== "function") throw new Error("Router does not support route generation");
|
|
131
|
-
const routeUrl = router.route(name, params);
|
|
128
|
+
const routeUrl = app.make("url").route(name, params);
|
|
132
129
|
if (!routeUrl) throw new Error(`Route "${name}" not found`);
|
|
133
130
|
return Url.to(routeUrl, app);
|
|
134
131
|
}
|
|
@@ -376,7 +373,9 @@ var UrlServiceProvider = class extends ServiceProvider {
|
|
|
376
373
|
/**
|
|
377
374
|
* Register URL services in the container
|
|
378
375
|
*/
|
|
379
|
-
register() {
|
|
376
|
+
register() {
|
|
377
|
+
this.app.setUriResolver(() => Url);
|
|
378
|
+
}
|
|
380
379
|
/**
|
|
381
380
|
* Boot URL services
|
|
382
381
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h3ravel/url",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-alpha.2",
|
|
4
4
|
"description": "Request-aware URI builder and URL manipulation utilities for H3ravel.",
|
|
5
5
|
"h3ravel": {
|
|
6
6
|
"providers": [
|
|
@@ -44,23 +44,15 @@
|
|
|
44
44
|
"builder"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@h3ravel/support": "^0.
|
|
48
|
-
"@h3ravel/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"@h3ravel/core": "^1.21.6",
|
|
52
|
-
"@h3ravel/config": "^1.4.18"
|
|
47
|
+
"@h3ravel/support": "^0.1.0-alpha.2",
|
|
48
|
+
"@h3ravel/contracts": "^0.1.0-alpha.2",
|
|
49
|
+
"@h3ravel/foundation": "^0.1.0-alpha.2",
|
|
50
|
+
"@h3ravel/shared": "^0.1.0-alpha.2"
|
|
53
51
|
},
|
|
54
52
|
"devDependencies": {
|
|
55
53
|
"typescript": "^5.4.0"
|
|
56
54
|
},
|
|
57
|
-
"peerDependenciesMeta": {
|
|
58
|
-
"@h3ravel/config": {
|
|
59
|
-
"optional": true
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
55
|
"scripts": {
|
|
63
|
-
"barrel": "barrelsby --directory src --delete --singleQuotes",
|
|
64
56
|
"build": "tsdown --config-loader unconfig",
|
|
65
57
|
"dev": "tsx watch src/index.ts",
|
|
66
58
|
"start": "node dist/index.js",
|