@primate/core 0.8.7 → 0.8.8

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.
@@ -32,8 +32,8 @@ function plugin_server_virtual_routes(app) {
32
32
  ${route_files.map((file, i) => {
33
33
  const path = app.basename(file, app.path.routes);
34
34
  return is_hook_file(path)
35
- ? `router.addHook("${path}", route${i});
36
- routes.push(["${path}", route${i}]);
35
+ ? `router.setHook("${path}", route${i});
36
+ routes.push(["${path}", route${i}]);
37
37
  `
38
38
  : `for (const [method, { handler, options }] of Object.entries(route${i})) {
39
39
  router.add("${path}", method, handler, options);
@@ -5,7 +5,7 @@ import type { Method } from "@rcompat/http";
5
5
  declare class Router {
6
6
  #private;
7
7
  add(path: string, method: Method, handler: RouteHandler, options?: RouteOptions): void;
8
- addHook(path: string, fn: RequestHook): void;
8
+ setHook(path: string, fn: RequestHook): void;
9
9
  getHooks(path: string): RequestHook[];
10
10
  verifyHook(path: string): void;
11
11
  get(path: string): {
@@ -27,12 +27,12 @@ class Router {
27
27
  this.#routes[path] = {};
28
28
  this.#routes[path][method] = { handler, options: options ?? {} };
29
29
  }
30
- addHook(path, fn) {
30
+ setHook(path, fn) {
31
31
  assert.string(path);
32
32
  assert.function(fn);
33
33
  if (!is_hook_file(path))
34
34
  throw E.hook_not_allowed(path);
35
- (this.#hooks[path] ??= []).push(fn);
35
+ this.#hooks[path] = [fn];
36
36
  }
37
37
  getHooks(path) {
38
38
  return [...(this.#hooks[path] ?? [])];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/core",
3
- "version": "0.8.7",
3
+ "version": "0.8.8",
4
4
  "description": "The universal web framework",
5
5
  "homepage": "https://primate.run",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",