owebjs 1.1.0 → 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
@@ -1,19 +1,21 @@
1
1
  import { FastifyServerOptions, FastifyRequest, FastifyReply, FastifyListenOptions, FastifyInstance } from 'fastify';
2
- export * from 'fastify/types/instance';
3
- export * from 'fastify/types/hooks';
4
- export * from 'fastify/types/logger';
5
- export * from 'fastify/types/request';
6
- export * from 'fastify/types/reply';
7
- export * from 'fastify/types/errors';
8
- export * from 'fastify/types/register';
9
- export * from 'fastify/types/plugin';
10
- export * from 'fastify/types/route';
11
- export * from 'fastify/types/schema';
12
- export * from 'fastify/types/context';
13
- export * from 'fastify/types/utils';
14
- export * from 'fastify/types/serverFactory';
15
- export * from 'fastify/types/type-provider';
16
- export * from 'fastify/types/content-type-parser';
2
+ import { FastifyReply as FastifyReply$1 } from 'fastify/types/reply';
3
+ export { FastifyReply } from 'fastify/types/reply';
4
+ import { FastifyRequest as FastifyRequest$1 } from 'fastify/types/request';
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';
8
+ export { AddContentTypeParser, ConstructorAction, FastifyBodyParser, FastifyContentTypeParser, ProtoAction, getDefaultJsonParser, hasContentTypeParser } from 'fastify/types/content-type-parser';
9
+ export { FastifyContext, FastifyContextConfig } from 'fastify/types/context';
10
+ export { FastifyErrorCodes } from 'fastify/types/errors';
11
+ export { DoneFuncWithErrOrRes, HookHandlerDoneFunction, RequestPayload, onCloseAsyncHookHandler, onCloseHookHandler, onErrorAsyncHookHandler, onErrorHookHandler, onListenAsyncHookHandler, onListenHookHandler, onReadyAsyncHookHandler, onReadyHookHandler, onRegisterHookHandler, onRequestAbortAsyncHookHandler, onRequestAbortHookHandler, onRequestAsyncHookHandler, onRequestHookHandler, onResponseAsyncHookHandler, onResponseHookHandler, onRouteHookHandler, onSendAsyncHookHandler, onSendHookHandler, onTimeoutAsyncHookHandler, onTimeoutHookHandler, preHandlerAsyncHookHandler, preHandlerHookHandler, preParsingAsyncHookHandler, preParsingHookHandler, preSerializationAsyncHookHandler, preSerializationHookHandler, preValidationAsyncHookHandler, preValidationHookHandler } from 'fastify/types/hooks';
12
+ export { FastifyInstance, FastifyListenOptions, PrintRoutesOptions } from 'fastify/types/instance';
13
+ export { Bindings, ChildLoggerOptions, FastifyBaseLogger, FastifyLogFn, FastifyLoggerInstance, FastifyLoggerOptions, LogLevel, PinoLoggerOptions } from 'fastify/types/logger';
14
+ export { FastifyPlugin, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions } from 'fastify/types/plugin';
15
+ export { FastifyRegister, FastifyRegisterOptions, RegisterOptions } from 'fastify/types/register';
16
+ export { FastifySchema, FastifySchemaCompiler, FastifySchemaValidationError, SchemaErrorDataVar, SchemaErrorFormatter } from 'fastify/types/schema';
17
+ export { FastifyServerFactory, FastifyServerFactoryHandler } from 'fastify/types/serverFactory';
18
+ export { FastifyTypeProvider, FastifyTypeProviderDefault } from 'fastify/types/type-provider';
17
19
 
18
20
  interface OwebOptions extends FastifyServerOptions {
19
21
  uWebSocketsEnabled?: boolean;
@@ -41,14 +43,16 @@ declare class Oweb extends _FastifyInstance {
41
43
  type Awaitable<T> = T | Promise<T>;
42
44
 
43
45
  declare interface Route {
44
- handle(req: FastifyRequest, res: FastifyReply): Awaitable<any>;
45
- handleError?(req: FastifyRequest, res: FastifyReply, err: Error): Awaitable<any>;
46
+ handle(req: FastifyRequest$1, res: FastifyReply$1): Awaitable<any>;
47
+ handleError?(req: FastifyRequest$1, res: FastifyReply$1, err: Error): Awaitable<any>;
46
48
  }
47
49
  declare abstract class Route {
50
+ _options: RouteShorthandOptions;
51
+ constructor(options?: RouteShorthandOptions);
48
52
  }
49
53
 
50
54
  declare interface Hook {
51
- handle(req: FastifyRequest, res: FastifyReply, done: () => void): Awaitable<any>;
55
+ handle(req: FastifyRequest$1, res: FastifyReply$1, done: () => void): Awaitable<any>;
52
56
  }
53
57
  declare abstract class Hook {
54
58
  }
@@ -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.0",
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",