Browse Source

refactor: moves ROOT_PATH constant to separated file

e22m4u 3 weeks ago
parent
commit
037898fea7

+ 3 - 1
dist/cjs/index.cjs

@@ -71,6 +71,9 @@ __export(index_exports, {
 });
 module.exports = __toCommonJS(index_exports);
 
+// src/constants.js
+var ROOT_PATH = "/";
+
 // src/route/route.js
 var import_js_debug = require("@e22m4u/js-debug");
 
@@ -994,7 +997,6 @@ var HttpMethod = {
   PATCH: "PATCH",
   DELETE: "DELETE"
 };
-var ROOT_PATH = "/";
 var _Route = class _Route extends import_js_debug.Debuggable {
   /**
    * Method.

+ 4 - 0
src/constants.d.ts

@@ -0,0 +1,4 @@
+/**
+ * Root path.
+ */
+export declare const ROOT_PATH: '/';

+ 6 - 0
src/constants.js

@@ -0,0 +1,6 @@
+/**
+ * Root path.
+ *
+ * @type {string}
+ */
+export const ROOT_PATH = '/';

+ 2 - 1
src/hooks/hook-invoker.spec.js

@@ -1,8 +1,9 @@
 import {expect} from 'chai';
 import {format} from '@e22m4u/js-format';
+import {ROOT_PATH} from '../constants.js';
 import {HookInvoker} from './hook-invoker.js';
+import {Route, HttpMethod} from '../route/index.js';
 import {createResponseMock} from '../utils/index.js';
-import {Route, HttpMethod, ROOT_PATH} from '../route/index.js';
 import {HookRegistry, RouterHookType} from './hook-registry.js';
 
 describe('HookInvoker', function () {

+ 1 - 0
src/index.d.ts

@@ -1,3 +1,4 @@
+export * from './constants.js';
 export * from './route/index.js';
 export * from './utils/index.js';
 export * from './hooks/index.js';

+ 1 - 0
src/index.js

@@ -1,3 +1,4 @@
+export * from './constants.js';
 export * from './route/index.js';
 export * from './utils/index.js';
 export * from './hooks/index.js';

+ 2 - 1
src/route-registry.js

@@ -1,5 +1,6 @@
+import {Route} from './route/index.js';
+import {ROOT_PATH} from './constants.js';
 import {PathTrie} from '@e22m4u/js-path-trie';
-import {ROOT_PATH, Route} from './route/index.js';
 import {getRequestPathname} from './utils/index.js';
 import {ServiceContainer} from '@e22m4u/js-service';
 import {InvalidArgumentError} from '@e22m4u/js-format';

+ 0 - 5
src/route/route.d.ts

@@ -55,11 +55,6 @@ export type RouteDefinition = {
   meta?: RouteMeta;
 };
 
-/**
- * Root path.
- */
-export declare const ROOT_PATH: '/';
-
 /**
  * Route.
  */

+ 0 - 7
src/route/route.js

@@ -38,13 +38,6 @@ export const HttpMethod = {
   DELETE: 'DELETE',
 };
 
-/**
- * Root path.
- *
- * @type {string}
- */
-export const ROOT_PATH = '/';
-
 /**
  * Route.
  */

+ 2 - 1
src/route/route.spec.js

@@ -1,9 +1,10 @@
 import {expect} from 'chai';
 import {format} from '@e22m4u/js-format';
+import {ROOT_PATH} from '../constants.js';
+import {Route, HttpMethod} from './route.js';
 import {RouterHookType} from '../hooks/index.js';
 import {ServiceContainer} from '@e22m4u/js-service';
 import {RequestContext} from '../request-context.js';
-import {Route, HttpMethod, ROOT_PATH} from './route.js';
 import {createRequestMock, createResponseMock} from '../utils/index.js';
 
 describe('Route', function () {

+ 2 - 1
src/route/validate-route-definition.spec.js

@@ -1,6 +1,7 @@
 import {expect} from 'chai';
+import {HttpMethod} from './route.js';
 import {format} from '@e22m4u/js-format';
-import {HttpMethod, ROOT_PATH} from './route.js';
+import {ROOT_PATH} from '../constants.js';
 import {validateRouteDefinition} from './validate-route-definition.js';
 
 describe('validateRouteDefinition', function () {

+ 2 - 1
src/trie-router.spec.js

@@ -1,10 +1,11 @@
 import {expect} from 'chai';
+import {ROOT_PATH} from './constants.js';
 import {TrieRouter} from './trie-router.js';
+import {Route, HttpMethod} from './route/index.js';
 import {RequestContext} from './request-context.js';
 import {ServerResponse, IncomingMessage} from 'http';
 import {DataSender, ErrorSender} from './senders/index.js';
 import {HookRegistry, RouterHookType} from './hooks/index.js';
-import {Route, HttpMethod, ROOT_PATH} from './route/index.js';
 import {createRequestMock, createResponseMock} from './utils/index.js';
 
 describe('TrieRouter', function () {

+ 1 - 1
src/utils/create-request-mock.js

@@ -2,7 +2,7 @@ import {Socket} from 'net';
 import {TLSSocket} from 'tls';
 import {IncomingMessage} from 'http';
 import queryString from 'querystring';
-import {ROOT_PATH} from '../route/index.js';
+import {ROOT_PATH} from '../constants.js';
 import {InvalidArgumentError} from '@e22m4u/js-format';
 import {isReadableStream} from './is-readable-stream.js';
 import {createCookieString} from './create-cookie-string.js';

+ 1 - 1
src/utils/create-request-mock.spec.js

@@ -3,7 +3,7 @@ import {Stream} from 'stream';
 import {TLSSocket} from 'tls';
 import {expect} from 'chai';
 import {format} from '@e22m4u/js-format';
-import {ROOT_PATH} from '../route/index.js';
+import {ROOT_PATH} from '../constants.js';
 import {createRequestMock} from './create-request-mock.js';
 import {CHARACTER_ENCODING_LIST} from './fetch-request-body.js';
 

+ 2 - 1
src/utils/create-route-mock.js

@@ -1,4 +1,5 @@
-import {Route, HttpMethod, ROOT_PATH} from '../route/index.js';
+import {ROOT_PATH} from '../constants.js';
+import {Route, HttpMethod} from '../route/index.js';
 
 /**
  * @typedef {object} RouteMockOptions

+ 2 - 1
src/utils/create-route-mock.spec.js

@@ -1,6 +1,7 @@
 import {expect} from 'chai';
+import {ROOT_PATH} from '../constants.js';
+import {HttpMethod, Route} from '../route/index.js';
 import {createRouteMock} from './create-route-mock.js';
-import {HttpMethod, ROOT_PATH, Route} from '../route/index.js';
 
 describe('createRouteMock', function () {
   it('returns an instance of Route with default options', function () {

+ 1 - 1
src/utils/get-request-pathname.js

@@ -1,4 +1,4 @@
-import {ROOT_PATH} from '../route/index.js';
+import {ROOT_PATH} from '../constants.js';
 import {InvalidArgumentError} from '@e22m4u/js-format';
 
 /**