@h3ravel/url 1.1.0-alpha.9 → 1.29.0-alpha.11

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/index.cjs CHANGED
@@ -1,40 +1,36 @@
1
- //#region rolldown:runtime
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __getProtoOf = Object.getPrototypeOf;
7
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to$1, from, except, desc) => {
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
- }
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
19
16
  }
20
- return to$1;
17
+ return to;
21
18
  };
22
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
20
  value: mod,
24
21
  enumerable: true
25
22
  }) : target, mod));
26
-
27
23
  //#endregion
28
- let __h3ravel_foundation = require("@h3ravel/foundation");
29
- let __h3ravel_support = require("@h3ravel/support");
24
+ let _h3ravel_foundation = require("@h3ravel/foundation");
25
+ let _h3ravel_support = require("@h3ravel/support");
30
26
  let node_path = require("node:path");
31
- node_path = __toESM(node_path);
32
-
27
+ node_path = __toESM(node_path, 1);
33
28
  //#region src/RequestAwareHelpers.ts
34
29
  /**
35
30
  * Request-aware URL helper class
36
31
  */
37
32
  var RequestAwareHelpers = class {
33
+ app;
38
34
  baseUrl = "";
39
35
  constructor(app) {
40
36
  this.app = app;
@@ -99,7 +95,6 @@ var RequestAwareHelpers = class {
99
95
  function createUrlHelper(app) {
100
96
  return () => new RequestAwareHelpers(app);
101
97
  }
102
-
103
98
  //#endregion
104
99
  //#region src/Url.ts
105
100
  /**
@@ -113,39 +108,39 @@ var Url = class Url {
113
108
  _query;
114
109
  _fragment;
115
110
  app;
116
- constructor(app, scheme, host, port, path$1 = "/", query = {}, fragment) {
111
+ constructor(app, scheme, host, port, path = "/", query = {}, fragment) {
117
112
  this.app = app;
118
113
  this._scheme = scheme;
119
114
  this._host = host;
120
115
  this._port = port;
121
- this._path = path$1.startsWith("/") ? path$1 : `/${path$1}`;
116
+ this._path = path.startsWith("/") ? path : `/${path}`;
122
117
  this._query = { ...query };
123
118
  this._fragment = fragment;
124
119
  }
125
120
  /**
126
121
  * Create a URL from a full URL string
127
122
  */
128
- static of(url$1, app) {
123
+ static of(url, app) {
129
124
  try {
130
- const parsed = new URL(url$1);
125
+ const parsed = new URL(url);
131
126
  const query = {};
132
127
  parsed.searchParams.forEach((value, key) => {
133
128
  query[key] = value;
134
129
  });
135
130
  return new Url(app, parsed.protocol.replace(":", ""), parsed.hostname, parsed.port ? parseInt(parsed.port) : void 0, parsed.pathname || "/", query, parsed.hash ? parsed.hash.substring(1) : void 0);
136
131
  } catch {
137
- throw new Error(`Invalid URL: ${url$1}`);
132
+ throw new Error(`Invalid URL: ${url}`);
138
133
  }
139
134
  }
140
135
  /**
141
136
  * Create a URL from a path relative to the app URL
142
137
  */
143
- static to(path$1, app) {
138
+ static to(path, app) {
144
139
  let baseUrl = "";
145
140
  try {
146
141
  baseUrl = config("app.url", "http://localhost:3000");
147
142
  } catch {}
148
- const fullUrl = new URL(path$1, baseUrl).toString();
143
+ const fullUrl = new URL(path, baseUrl).toString();
149
144
  return Url.of(fullUrl, app);
150
145
  }
151
146
  /**
@@ -176,11 +171,24 @@ var Url = class Url {
176
171
  if (!app) throw new Error("Application instance required for action URL generation");
177
172
  const [controllerName, methodName = "index"] = typeof controller === "string" ? controller.split("@") : controller;
178
173
  const cname = typeof controllerName === "string" ? controllerName : controllerName.name;
179
- const routes = app.make("app.routes");
180
- if (!Array.isArray(routes)) throw new Error("Action URL generation requires router integration - not yet implemented");
174
+ let routes;
175
+ try {
176
+ const legacyRoutes = app.make("app.routes");
177
+ routes = Array.isArray(legacyRoutes) ? legacyRoutes : [];
178
+ } catch {
179
+ routes = app.make("router").getRoutes().getRoutes().map((route) => {
180
+ const action = route.getAction();
181
+ const controller = action.controller;
182
+ const signature = typeof controller === "function" ? [controller.name, action.uses?.[1] ?? "index"] : typeof controller === "string" ? controller.replace(/^\\/, "").split("@") : void 0;
183
+ return {
184
+ path: route.uri(),
185
+ signature
186
+ };
187
+ });
188
+ }
181
189
  if (routes.length < 1) throw new Error(`No routes available to resolve action: ${controller}`);
182
- const found = routes.find((route$1) => {
183
- return route$1.signature?.[0] === cname && (route$1.signature?.[1] || "index") === methodName;
190
+ const found = routes.find((route) => {
191
+ return route.signature?.[0] === cname && (route.signature?.[1] || "index") === methodName;
184
192
  });
185
193
  if (!found) throw new Error(`No route found for ${cname}`);
186
194
  const _params = Object.values(params ?? {}).join("/");
@@ -208,8 +216,8 @@ var Url = class Url {
208
216
  /**
209
217
  * Set the path of the URL
210
218
  */
211
- withPath(path$1) {
212
- return new Url(this.app, this._scheme, this._host, this._port, path$1, this._query, this._fragment);
219
+ withPath(path) {
220
+ return new Url(this.app, this._scheme, this._host, this._port, path, this._query, this._fragment);
213
221
  }
214
222
  /**
215
223
  * Set the query parameters of the URL
@@ -241,11 +249,11 @@ var Url = class Url {
241
249
  try {
242
250
  key = config("app.key");
243
251
  } catch {}
244
- if (!key) throw new __h3ravel_foundation.ConfigException("APP_KEY and app.key", "any", this);
245
- const url$1 = this.toString();
252
+ if (!key) throw new _h3ravel_foundation.ConfigException("APP_KEY and app.key", "any", this);
253
+ const url = this.toString();
246
254
  const queryParams = { ...this._query };
247
255
  if (expiration) queryParams.expires = Math.floor(expiration / 1e3);
248
- queryParams.signature = (0, __h3ravel_support.hmac)(expiration ? `${url$1}?expires=${queryParams.expires}` : url$1, key);
256
+ queryParams.signature = (0, _h3ravel_support.hmac)(expiration ? `${url}?expires=${queryParams.expires}` : url, key);
249
257
  return this.withQuery(queryParams);
250
258
  }
251
259
  /**
@@ -268,20 +276,20 @@ var Url = class Url {
268
276
  try {
269
277
  key = config("app.key", "default-key");
270
278
  } catch {}
271
- return signature === (0, __h3ravel_support.hmac)(payload, key);
279
+ return signature === (0, _h3ravel_support.hmac)(payload, key);
272
280
  }
273
281
  /**
274
282
  * Convert the URL to its string representation
275
283
  */
276
284
  toString() {
277
- let url$1 = "";
285
+ let url = "";
278
286
  if (this._scheme && this._host) {
279
- url$1 += `${this._scheme}://${this._host}`;
280
- if (this._port && !(this._scheme === "http" && this._port === 80 || this._scheme === "https" && this._port === 443)) url$1 += `:${this._port}`;
287
+ url += `${this._scheme}://${this._host}`;
288
+ if (this._port && !(this._scheme === "http" && this._port === 80 || this._scheme === "https" && this._port === 443)) url += `:${this._port}`;
281
289
  }
282
290
  if (this._path) {
283
- if (!this._path.startsWith("/")) url$1 += "/";
284
- url$1 += this._path;
291
+ if (!this._path.startsWith("/")) url += "/";
292
+ url += this._path;
285
293
  }
286
294
  const queryEntries = Object.entries(this._query);
287
295
  if (queryEntries.length > 0) {
@@ -289,10 +297,10 @@ var Url = class Url {
289
297
  if (Array.isArray(value)) return value.map((v) => `${encodeURIComponent(key)}%5B%5D=${encodeURIComponent(v)}`).join("&");
290
298
  return `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`;
291
299
  }).join("&");
292
- url$1 += `?${queryString}`;
300
+ url += `?${queryString}`;
293
301
  }
294
- if (this._fragment) url$1 += `#${this._fragment}`;
295
- return url$1;
302
+ if (this._fragment) url += `#${this._fragment}`;
303
+ return url;
296
304
  }
297
305
  /**
298
306
  * Get the scheme
@@ -331,7 +339,6 @@ var Url = class Url {
331
339
  return this._fragment;
332
340
  }
333
341
  };
334
-
335
342
  //#endregion
336
343
  //#region src/Helpers.ts
337
344
  /**
@@ -340,8 +347,8 @@ var Url = class Url {
340
347
  /**
341
348
  * Create a URL from a path relative to the app URL
342
349
  */
343
- function to(path$1, app) {
344
- return Url.to(path$1, app);
350
+ function to(path, app) {
351
+ return Url.to(path, app);
345
352
  }
346
353
  /**
347
354
  * Create a URL from a named route
@@ -379,24 +386,41 @@ function url(app) {
379
386
  */
380
387
  function createUrlHelpers(app) {
381
388
  return {
382
- to: (path$1) => Url.to(path$1, app),
389
+ /**
390
+ * Create a URL from a path relative to the app URL
391
+ */
392
+ to: (path) => Url.to(path, app),
393
+ /**
394
+ * Create a URL from a named route
395
+ */
383
396
  route: (name, params = {}) => Url.route(name, params, app).toString(),
397
+ /**
398
+ * Create a signed URL from a named route
399
+ */
384
400
  signedRoute: (name, params = {}) => Url.signedRoute(name, params, app),
401
+ /**
402
+ * Create a temporary signed URL from a named route
403
+ */
385
404
  temporarySignedRoute: (name, params = {}, expiration) => Url.temporarySignedRoute(name, params, expiration, app),
405
+ /**
406
+ * Create a URL from a controller action
407
+ */
386
408
  action: (controller, params) => Url.action(controller, params, app).toString(),
387
- url: (path$1) => {
388
- if (path$1) return Url.to(path$1).toString();
409
+ /**
410
+ * Get request-aware URL helpers
411
+ */
412
+ url: (path) => {
413
+ if (path) return Url.to(path).toString();
389
414
  return new RequestAwareHelpers(app);
390
415
  }
391
416
  };
392
417
  }
393
-
394
418
  //#endregion
395
419
  //#region src/Providers/UrlServiceProvider.ts
396
420
  /**
397
421
  * Service provider for URL utilities
398
422
  */
399
- var UrlServiceProvider = class extends __h3ravel_support.ServiceProvider {
423
+ var UrlServiceProvider = class extends _h3ravel_support.ServiceProvider {
400
424
  static priority = 897;
401
425
  /**
402
426
  * Register URL services in the container
@@ -421,7 +445,6 @@ var UrlServiceProvider = class extends __h3ravel_support.ServiceProvider {
421
445
  }
422
446
  }
423
447
  };
424
-
425
448
  //#endregion
426
449
  exports.RequestAwareHelpers = RequestAwareHelpers;
427
450
  exports.Url = Url;
@@ -433,4 +456,4 @@ exports.route = route;
433
456
  exports.signedRoute = signedRoute;
434
457
  exports.temporarySignedRoute = temporarySignedRoute;
435
458
  exports.to = to;
436
- exports.url = url;
459
+ exports.url = url;
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { ConfigException } from "@h3ravel/foundation";
2
2
  import { ServiceProvider, hmac } from "@h3ravel/support";
3
3
  import path from "node:path";
4
-
5
4
  //#region src/RequestAwareHelpers.ts
6
5
  /**
7
6
  * Request-aware URL helper class
8
7
  */
9
8
  var RequestAwareHelpers = class {
9
+ app;
10
10
  baseUrl = "";
11
11
  constructor(app) {
12
12
  this.app = app;
@@ -71,7 +71,6 @@ var RequestAwareHelpers = class {
71
71
  function createUrlHelper(app) {
72
72
  return () => new RequestAwareHelpers(app);
73
73
  }
74
-
75
74
  //#endregion
76
75
  //#region src/Url.ts
77
76
  /**
@@ -85,39 +84,39 @@ var Url = class Url {
85
84
  _query;
86
85
  _fragment;
87
86
  app;
88
- constructor(app, scheme, host, port, path$1 = "/", query = {}, fragment) {
87
+ constructor(app, scheme, host, port, path = "/", query = {}, fragment) {
89
88
  this.app = app;
90
89
  this._scheme = scheme;
91
90
  this._host = host;
92
91
  this._port = port;
93
- this._path = path$1.startsWith("/") ? path$1 : `/${path$1}`;
92
+ this._path = path.startsWith("/") ? path : `/${path}`;
94
93
  this._query = { ...query };
95
94
  this._fragment = fragment;
96
95
  }
97
96
  /**
98
97
  * Create a URL from a full URL string
99
98
  */
100
- static of(url$1, app) {
99
+ static of(url, app) {
101
100
  try {
102
- const parsed = new URL(url$1);
101
+ const parsed = new URL(url);
103
102
  const query = {};
104
103
  parsed.searchParams.forEach((value, key) => {
105
104
  query[key] = value;
106
105
  });
107
106
  return new Url(app, parsed.protocol.replace(":", ""), parsed.hostname, parsed.port ? parseInt(parsed.port) : void 0, parsed.pathname || "/", query, parsed.hash ? parsed.hash.substring(1) : void 0);
108
107
  } catch {
109
- throw new Error(`Invalid URL: ${url$1}`);
108
+ throw new Error(`Invalid URL: ${url}`);
110
109
  }
111
110
  }
112
111
  /**
113
112
  * Create a URL from a path relative to the app URL
114
113
  */
115
- static to(path$1, app) {
114
+ static to(path, app) {
116
115
  let baseUrl = "";
117
116
  try {
118
117
  baseUrl = config("app.url", "http://localhost:3000");
119
118
  } catch {}
120
- const fullUrl = new URL(path$1, baseUrl).toString();
119
+ const fullUrl = new URL(path, baseUrl).toString();
121
120
  return Url.of(fullUrl, app);
122
121
  }
123
122
  /**
@@ -148,11 +147,24 @@ var Url = class Url {
148
147
  if (!app) throw new Error("Application instance required for action URL generation");
149
148
  const [controllerName, methodName = "index"] = typeof controller === "string" ? controller.split("@") : controller;
150
149
  const cname = typeof controllerName === "string" ? controllerName : controllerName.name;
151
- const routes = app.make("app.routes");
152
- if (!Array.isArray(routes)) throw new Error("Action URL generation requires router integration - not yet implemented");
150
+ let routes;
151
+ try {
152
+ const legacyRoutes = app.make("app.routes");
153
+ routes = Array.isArray(legacyRoutes) ? legacyRoutes : [];
154
+ } catch {
155
+ routes = app.make("router").getRoutes().getRoutes().map((route) => {
156
+ const action = route.getAction();
157
+ const controller = action.controller;
158
+ const signature = typeof controller === "function" ? [controller.name, action.uses?.[1] ?? "index"] : typeof controller === "string" ? controller.replace(/^\\/, "").split("@") : void 0;
159
+ return {
160
+ path: route.uri(),
161
+ signature
162
+ };
163
+ });
164
+ }
153
165
  if (routes.length < 1) throw new Error(`No routes available to resolve action: ${controller}`);
154
- const found = routes.find((route$1) => {
155
- return route$1.signature?.[0] === cname && (route$1.signature?.[1] || "index") === methodName;
166
+ const found = routes.find((route) => {
167
+ return route.signature?.[0] === cname && (route.signature?.[1] || "index") === methodName;
156
168
  });
157
169
  if (!found) throw new Error(`No route found for ${cname}`);
158
170
  const _params = Object.values(params ?? {}).join("/");
@@ -180,8 +192,8 @@ var Url = class Url {
180
192
  /**
181
193
  * Set the path of the URL
182
194
  */
183
- withPath(path$1) {
184
- return new Url(this.app, this._scheme, this._host, this._port, path$1, this._query, this._fragment);
195
+ withPath(path) {
196
+ return new Url(this.app, this._scheme, this._host, this._port, path, this._query, this._fragment);
185
197
  }
186
198
  /**
187
199
  * Set the query parameters of the URL
@@ -214,10 +226,10 @@ var Url = class Url {
214
226
  key = config("app.key");
215
227
  } catch {}
216
228
  if (!key) throw new ConfigException("APP_KEY and app.key", "any", this);
217
- const url$1 = this.toString();
229
+ const url = this.toString();
218
230
  const queryParams = { ...this._query };
219
231
  if (expiration) queryParams.expires = Math.floor(expiration / 1e3);
220
- queryParams.signature = hmac(expiration ? `${url$1}?expires=${queryParams.expires}` : url$1, key);
232
+ queryParams.signature = hmac(expiration ? `${url}?expires=${queryParams.expires}` : url, key);
221
233
  return this.withQuery(queryParams);
222
234
  }
223
235
  /**
@@ -246,14 +258,14 @@ var Url = class Url {
246
258
  * Convert the URL to its string representation
247
259
  */
248
260
  toString() {
249
- let url$1 = "";
261
+ let url = "";
250
262
  if (this._scheme && this._host) {
251
- url$1 += `${this._scheme}://${this._host}`;
252
- if (this._port && !(this._scheme === "http" && this._port === 80 || this._scheme === "https" && this._port === 443)) url$1 += `:${this._port}`;
263
+ url += `${this._scheme}://${this._host}`;
264
+ if (this._port && !(this._scheme === "http" && this._port === 80 || this._scheme === "https" && this._port === 443)) url += `:${this._port}`;
253
265
  }
254
266
  if (this._path) {
255
- if (!this._path.startsWith("/")) url$1 += "/";
256
- url$1 += this._path;
267
+ if (!this._path.startsWith("/")) url += "/";
268
+ url += this._path;
257
269
  }
258
270
  const queryEntries = Object.entries(this._query);
259
271
  if (queryEntries.length > 0) {
@@ -261,10 +273,10 @@ var Url = class Url {
261
273
  if (Array.isArray(value)) return value.map((v) => `${encodeURIComponent(key)}%5B%5D=${encodeURIComponent(v)}`).join("&");
262
274
  return `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`;
263
275
  }).join("&");
264
- url$1 += `?${queryString}`;
276
+ url += `?${queryString}`;
265
277
  }
266
- if (this._fragment) url$1 += `#${this._fragment}`;
267
- return url$1;
278
+ if (this._fragment) url += `#${this._fragment}`;
279
+ return url;
268
280
  }
269
281
  /**
270
282
  * Get the scheme
@@ -303,7 +315,6 @@ var Url = class Url {
303
315
  return this._fragment;
304
316
  }
305
317
  };
306
-
307
318
  //#endregion
308
319
  //#region src/Helpers.ts
309
320
  /**
@@ -312,8 +323,8 @@ var Url = class Url {
312
323
  /**
313
324
  * Create a URL from a path relative to the app URL
314
325
  */
315
- function to(path$1, app) {
316
- return Url.to(path$1, app);
326
+ function to(path, app) {
327
+ return Url.to(path, app);
317
328
  }
318
329
  /**
319
330
  * Create a URL from a named route
@@ -351,18 +362,35 @@ function url(app) {
351
362
  */
352
363
  function createUrlHelpers(app) {
353
364
  return {
354
- to: (path$1) => Url.to(path$1, app),
365
+ /**
366
+ * Create a URL from a path relative to the app URL
367
+ */
368
+ to: (path) => Url.to(path, app),
369
+ /**
370
+ * Create a URL from a named route
371
+ */
355
372
  route: (name, params = {}) => Url.route(name, params, app).toString(),
373
+ /**
374
+ * Create a signed URL from a named route
375
+ */
356
376
  signedRoute: (name, params = {}) => Url.signedRoute(name, params, app),
377
+ /**
378
+ * Create a temporary signed URL from a named route
379
+ */
357
380
  temporarySignedRoute: (name, params = {}, expiration) => Url.temporarySignedRoute(name, params, expiration, app),
381
+ /**
382
+ * Create a URL from a controller action
383
+ */
358
384
  action: (controller, params) => Url.action(controller, params, app).toString(),
359
- url: (path$1) => {
360
- if (path$1) return Url.to(path$1).toString();
385
+ /**
386
+ * Get request-aware URL helpers
387
+ */
388
+ url: (path) => {
389
+ if (path) return Url.to(path).toString();
361
390
  return new RequestAwareHelpers(app);
362
391
  }
363
392
  };
364
393
  }
365
-
366
394
  //#endregion
367
395
  //#region src/Providers/UrlServiceProvider.ts
368
396
  /**
@@ -393,6 +421,5 @@ var UrlServiceProvider = class extends ServiceProvider {
393
421
  }
394
422
  }
395
423
  };
396
-
397
424
  //#endregion
398
- export { RequestAwareHelpers, Url, UrlServiceProvider, action, createUrlHelper, createUrlHelpers, route, signedRoute, temporarySignedRoute, to, url };
425
+ export { RequestAwareHelpers, Url, UrlServiceProvider, action, createUrlHelper, createUrlHelpers, route, signedRoute, temporarySignedRoute, to, url };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/url",
3
- "version": "1.1.0-alpha.9",
3
+ "version": "1.29.0-alpha.11",
4
4
  "description": "Request-aware URI builder and URL manipulation utilities for H3ravel.",
5
5
  "h3ravel": {
6
6
  "providers": [
@@ -44,16 +44,16 @@
44
44
  "builder"
45
45
  ],
46
46
  "dependencies": {
47
- "@h3ravel/support": "^0.17.0-alpha.9",
48
- "@h3ravel/contracts": "^0.29.0-alpha.9",
49
- "@h3ravel/foundation": "^0.1.0-alpha.9",
50
- "@h3ravel/shared": "^0.29.0-alpha.9"
47
+ "@h3ravel/support": "^1.29.0-alpha.11",
48
+ "@h3ravel/contracts": "^1.29.0-alpha.11",
49
+ "@h3ravel/foundation": "^1.29.0-alpha.11",
50
+ "@h3ravel/shared": "^1.29.0-alpha.11"
51
51
  },
52
52
  "devDependencies": {
53
- "typescript": "^5.4.0"
53
+ "typescript": "^6.0.0"
54
54
  },
55
55
  "scripts": {
56
- "build": "tsdown --config-loader unconfig",
56
+ "build": "tsdown --config-loader unrun",
57
57
  "dev": "tsx watch src/index.ts",
58
58
  "start": "node dist/index.js",
59
59
  "lint": "eslint . --ext .ts",