owebjs 1.1.1 → 1.1.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/index.d.ts CHANGED
@@ -3,6 +3,8 @@ import { FastifyReply as FastifyReply$1 } from 'fastify/types/reply';
3
3
  export { FastifyReply } from 'fastify/types/reply';
4
4
  import { FastifyRequest as FastifyRequest$1 } from 'fastify/types/request';
5
5
  export { FastifyRequest, RequestGenericInterface } from 'fastify/types/request';
6
+ import { RouteShorthandOptions } from 'fastify/types/route';
7
+ export { RouteGenericInterface, RouteHandler, RouteHandlerMethod, RouteOptions, RouteShorthandMethod, RouteShorthandOptions, RouteShorthandOptionsWithHandler } from 'fastify/types/route';
6
8
  export { AddContentTypeParser, ConstructorAction, FastifyBodyParser, FastifyContentTypeParser, ProtoAction, getDefaultJsonParser, hasContentTypeParser } from 'fastify/types/content-type-parser';
7
9
  export { FastifyContext, FastifyContextConfig } from 'fastify/types/context';
8
10
  export { FastifyErrorCodes } from 'fastify/types/errors';
@@ -11,7 +13,6 @@ export { FastifyInstance, FastifyListenOptions, PrintRoutesOptions } from 'fasti
11
13
  export { Bindings, ChildLoggerOptions, FastifyBaseLogger, FastifyLogFn, FastifyLoggerInstance, FastifyLoggerOptions, LogLevel, PinoLoggerOptions } from 'fastify/types/logger';
12
14
  export { FastifyPlugin, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions } from 'fastify/types/plugin';
13
15
  export { FastifyRegister, FastifyRegisterOptions, RegisterOptions } from 'fastify/types/register';
14
- export { RouteGenericInterface, RouteHandler, RouteHandlerMethod, RouteOptions, RouteShorthandMethod, RouteShorthandOptions, RouteShorthandOptionsWithHandler } from 'fastify/types/route';
15
16
  export { FastifySchema, FastifySchemaCompiler, FastifySchemaValidationError, SchemaErrorDataVar, SchemaErrorFormatter } from 'fastify/types/schema';
16
17
  export { FastifyServerFactory, FastifyServerFactoryHandler } from 'fastify/types/serverFactory';
17
18
  export { FastifyTypeProvider, FastifyTypeProviderDefault } from 'fastify/types/type-provider';
@@ -46,6 +47,8 @@ declare interface Route {
46
47
  handleError?(req: FastifyRequest$1, res: FastifyReply$1, err: Error): Awaitable<any>;
47
48
  }
48
49
  declare abstract class Route {
50
+ _options: RouteShorthandOptions;
51
+ constructor(options?: RouteShorthandOptions);
49
52
  }
50
53
 
51
54
  declare interface Hook {
@@ -5,6 +5,10 @@ class Route {
5
5
  static {
6
6
  __name(this, "Route");
7
7
  }
8
+ _options = {};
9
+ constructor(options) {
10
+ this._options = options ?? {};
11
+ }
8
12
  handle() {
9
13
  throw new Error("Route#handle must be implemented");
10
14
  }
@@ -30,8 +30,8 @@ const assignRoutes = /* @__PURE__ */ __name(async (directory, oweb) => {
30
30
  const files = await walk(directory);
31
31
  const routes = await generateRoutes(files);
32
32
  for (const route of routes) {
33
- oweb[route.method](route.url, function(req, res) {
34
- const routeFunc = new route.fn(...arguments);
33
+ const routeFunc = new route.fn();
34
+ oweb[route.method](route.url, routeFunc._options, function(req, res) {
35
35
  const handle = /* @__PURE__ */ __name(() => {
36
36
  if (routeFunc.handle.constructor.name == "AsyncFunction") {
37
37
  routeFunc.handle(...arguments).catch((error) => {
@@ -18,8 +18,15 @@ const buildRoutePath = /* @__PURE__ */ __name((parsedFile) => {
18
18
  return directory + name;
19
19
  }, "buildRoutePath");
20
20
  const buildRouteURL = /* @__PURE__ */ __name((path) => {
21
+ const paths = path.split("/");
22
+ const normalizedPath = paths.map((x) => {
23
+ if (x.startsWith("(") && x.endsWith(")")) {
24
+ x = x.slice(1, -1);
25
+ }
26
+ return x;
27
+ }).join("/");
21
28
  let method = "get";
22
- const paramURL = convertParamSyntax(path);
29
+ const paramURL = convertParamSyntax(normalizedPath);
23
30
  let url = convertCatchallSyntax(paramURL);
24
31
  for (const m of [
25
32
  ".DELETE",
@@ -45,9 +45,25 @@ const walk = /* @__PURE__ */ __name(async (directory, tree = []) => {
45
45
  ...hookPaths
46
46
  ];
47
47
  const hooks = spread.filter((hookPath) => {
48
- return isParentOrGrandparent(hookPath, directoryResolve);
48
+ const ren = isParentOrGrandparent(hookPath, directoryResolve);
49
+ return ren;
49
50
  });
50
- const hooksImport = hooks.map((hookPath) => new URL(hookPath, `file://${__dirname}`).pathname.replaceAll("\\", "/") + "/_hooks.js");
51
+ const copyHooks = [
52
+ hooks
53
+ ].flat();
54
+ let scopingSort = copyHooks.sort((a, b) => b.length - a.length);
55
+ const scopeIndex = scopingSort.findIndex((path2) => {
56
+ const lastdir = path2.split("\\").at(-1);
57
+ return lastdir.startsWith("(") && lastdir.endsWith(")");
58
+ });
59
+ let useHook = [];
60
+ if (scopeIndex > -1) {
61
+ scopingSort.length = scopeIndex + 1;
62
+ useHook = scopingSort;
63
+ } else {
64
+ useHook = hooks;
65
+ }
66
+ const hooksImport = useHook.map((hookPath) => new URL(hookPath, `file://${__dirname}`).pathname.replaceAll("\\", "/") + "/_hooks.js");
51
67
  const hookFunctions = [];
52
68
  for (const importPath of hooksImport) {
53
69
  const imp = await import(importPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owebjs",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Flexible handler that built on top of Fastify",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,6 +11,11 @@
11
11
  "test": "tsup && node scripts/copyBinaries && node test/index.js",
12
12
  "format": "prettier --write . --ignore-path .gitignore"
13
13
  },
14
+ "homepage": "https://github.com/owebjs/oweb",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/owebjs/oweb"
18
+ },
14
19
  "keywords": [],
15
20
  "author": "owebjs",
16
21
  "license": "MIT",