Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
},
moduleNameMapper: {
'^callsites$': '<rootDir>/src/__tests__/__mocks__/callsites.cjs',
'^(\\.{1,2}/.*)\\.js$': '$1',
},
collectCoverageFrom: ['<rootDir>/src/**/*.ts'],
coveragePathIgnorePatterns: ['<rootDir>/src/examples'],
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/context/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { context, enableContext, newContext } from '../../context/index';
import { context, enableContext, newContext } from '../../context/index.js';

test("Do not create execution if it's not enabled", () => {
newContext('newContext');
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/logger/serializers.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getStatusLevel, parseError, serializeHttp, serializeLog } from '../../logger/serializers';
import { getStatusLevel, parseError, serializeHttp, serializeLog } from '../../logger/serializers.js';

describe('logger - loglevel', () => {
test('Correctly gets http log level from the returning http status <300', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/request.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BareRequest } from '../request';
import { BareRequest } from '../request.js';

import { IncomingMessage, ServerResponse } from 'http';
import { Socket } from 'net';
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/server.integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';

import { context } from '../context';
import { BareHttp } from '../server';
import { context } from '../context/index.js';
import { BareHttp } from '../server.js';

test('Enables context in the settings', async () => {
const app = new BareHttp({ context: true, setRandomPort: true });
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/server.middlewares.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';

import { BareHttp } from '../server';
import { BareHttp } from '../server.js';

jest.spyOn(console, 'log');

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/server.routes.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';

import { BareHttp } from '../server';
import { BareHttp } from '../server.js';

// test('Registers a route with a handler', () => {
// const app = new BareHttp({ setRandomPort: true });
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/server.websockets.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BareHttp } from '../server';
import { BareHttp } from '../server.js';

test('Starts and shut downs the server with ws', async () => {
const app = new BareHttp({ setRandomPort: true });
Expand Down
2 changes: 1 addition & 1 deletion src/bench/baretest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BareHttp } from '../index';
import { BareHttp } from '../index.js';

const brt = new BareHttp({ logging: false });

Expand Down
2 changes: 1 addition & 1 deletion src/context/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Execution } from './execution';
import { Execution } from './execution.js';

import asyncHooks from 'async_hooks';

Expand Down
2 changes: 1 addition & 1 deletion src/examples/bare-http.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BareHttp } from '../index';
import { BareHttp } from '../index.js';

const app = new BareHttp({
logging: false,
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { BareHttp } from './server';
export type { BareHttpType } from './server';
export type { BareRequest } from './request';
export { context } from './context';
export { logMe } from './logger';
export { BareHttp } from './server.js';
export type { BareHttpType } from './server.js';
export type { BareRequest } from './request.js';
export { context } from './context/index.js';
export { logMe } from './logger/index.js';
4 changes: 2 additions & 2 deletions src/logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pino, { destination } from 'pino';

import { serializeLog, serializeHttp } from './serializers';
import { serializeLog, serializeHttp } from './serializers.js';

import { envs } from '../env';
import { envs } from '../env.js';

const asyncDest = envs.isProd ? [destination({ sync: false })] : [];

Expand Down
2 changes: 1 addition & 1 deletion src/logger/serializers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import callsites from 'callsites';

import { context } from '../context';
import { context } from '../context/index.js';

import util from 'util';
import type { IncomingMessage, ServerResponse } from 'http';
Expand Down
6 changes: 3 additions & 3 deletions src/middlewares/cookies/cookie-manager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { serialize, type ParseOptions, type SerializeOptions } from 'cookie';

import { secretsOperator } from './signer';
import { secretsOperator } from './signer.js';

import { logMe } from '../../logger';
import type { BareRequest } from '../../request';
import { logMe } from '../../logger/index.js';
import type { BareRequest } from '../../request.js';

export type CookiesManagerOptions = Omit<SerializeOptions, 'expires'> & {
expires?: Date | number;
Expand Down
4 changes: 2 additions & 2 deletions src/middlewares/cors/cors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import type { HttpMethodsUnionUppercase } from '../../utils';
import type { BareRequest } from '../../request';
import type { HttpMethodsUnionUppercase } from '../../utils/index.js';
import type { BareRequest } from '../../request.js';

import type { IncomingMessage } from 'http';

Expand Down
14 changes: 8 additions & 6 deletions src/request.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import hyperid from 'hyperid';

import { StatusCodes, StatusCodesUnion, StatusPhrases } from './utils/';
import { JSONParse, JSONStringify } from './utils/safe-json';
import { logHttp, logMe } from './logger';
import { ContentType } from './utils/content-type';
import { CookiesManager, CookiesManagerOptions } from './middlewares/cookies/cookie-manager';
import { StatusCodes, StatusCodesUnion, StatusPhrases } from './utils/index.js';
import { JSONParse, JSONStringify } from './utils/safe-json.js';
import { logHttp, logMe } from './logger/index.js';
import { ContentType } from './utils/content-type.js';
import { CookiesManager, CookiesManagerOptions } from './middlewares/cookies/cookie-manager.js';

import { types } from 'util';
import { Writable } from 'stream';
Expand Down Expand Up @@ -36,7 +36,9 @@ export type CacheOpts = {
revalidation?: Revalidation;
};

const statusTuples = Object.entries(StatusCodes).reduce((acc, [name, status]) => {
const statusTuples = (Object.entries(StatusCodes) as Array<
[keyof typeof StatusCodes, StatusCodesUnion]
>).reduce((acc, [name, status]) => {
acc[status] = StatusPhrases[name];
return acc;
}, {} as Codes);
Expand Down
4 changes: 2 additions & 2 deletions src/schemas/custom-schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import find from 'lodash/find';
import find from 'lodash/find.js';
import { ts, Type } from 'ts-morph';

import {
Expand All @@ -7,7 +7,7 @@ import {
helpers,
isFinalType,
isNullType,
} from './helpers';
} from './helpers.js';
// (type: X, is: K): type is T

// export const customTypeIs = <
Expand Down
4 changes: 2 additions & 2 deletions src/schemas/dirty-tsm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ClassMemberTypes, Node, Project, SyntaxList, ts, Type } from 'ts-morph';

import { generateCustomSchema } from './custom-schema';
import { isFinalType, logInternals } from './helpers';
import { generateCustomSchema } from './custom-schema.js';
import { isFinalType, logInternals } from './helpers.js';

const project = new Project({ tsConfigFilePath: 'tsconfig.json' });
project.enableLogging();
Expand Down
6 changes: 3 additions & 3 deletions src/schemas/generator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ClassMemberTypes, Node, Project, ReferenceEntry, SyntaxList, ts, Type } from 'ts-morph';

import { generateCustomSchema } from './custom-schema';
import { isFinalType, isHandler, isRoute } from './helpers';
import { convertToJsonSchema } from './json-schema';
import { generateCustomSchema } from './custom-schema.js';
import { isFinalType, isHandler, isRoute } from './helpers.js';
import { convertToJsonSchema } from './json-schema.js';

import path from 'path';
import { existsSync } from 'fs';
Expand Down
9 changes: 6 additions & 3 deletions src/schemas/json-schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArraySchemaType, CustomSchema, ObjectSchemaType, UnionSchemaType } from './custom-schema';
import { ArraySchemaType, CustomSchema, ObjectSchemaType, UnionSchemaType } from './custom-schema.js';

export const convertToJsonSchema = (schema: CustomSchema) => {
if (schema.type === 'string') {
Expand Down Expand Up @@ -32,12 +32,15 @@ export const convertToJsonSchema = (schema: CustomSchema) => {
return acc;
}, {} as any);

const required = Object.entries(reSchema.properties).reduce((acc, [key, value]) => {
const required = (Object.entries(reSchema.properties) as Array<[string, CustomSchema]>).reduce(
(acc, [key, value]) => {
if (!value.nullable) {
acc.push(key);
}
return acc;
}, [] as string[]);
},
[] as string[],
);

return {
required,
Expand Down
9 changes: 6 additions & 3 deletions src/schemas/openami-schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArraySchemaType, CustomSchema, ObjectSchemaType, UnionSchemaType } from './custom-schema';
import { ArraySchemaType, CustomSchema, ObjectSchemaType, UnionSchemaType } from './custom-schema.js';

const createRouteSchema = (route: string, method: string, openApiSchema: any) => ({
[route]: {
Expand Down Expand Up @@ -43,12 +43,15 @@ export const convertToOpenApiSchema = (schema: CustomSchema, route?: string, met
return acc;
}, {} as any);

const required = Object.entries(reSchema.properties).reduce((acc, [key, value]) => {
const required = (Object.entries(reSchema.properties) as Array<[string, CustomSchema]>).reduce(
(acc, [key, value]) => {
if (!value.nullable) {
acc.push(key);
}
return acc;
}, [] as string[]);
},
[] as string[],
);

return {
required,
Expand Down
18 changes: 9 additions & 9 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import Router from 'find-my-way';
import { ServerOptions } from 'ws';
import Ajv, { ValidateFunction } from 'ajv';
import { Ajv, ValidateFunction } from 'ajv';

import { BareRequest, CacheOpts } from './request';
import { logMe } from './logger';
import { context, enableContext, newContext } from './context';
import { CookiesManagerOptions } from './middlewares/cookies/cookie-manager';
import { BareRequest, CacheOpts } from './request.js';
import { logMe } from './logger/index.js';
import { context, enableContext, newContext } from './context/index.js';
import { CookiesManagerOptions } from './middlewares/cookies/cookie-manager.js';
import {
HttpMethods,
HttpMethodsUnion,
HttpMethodsUnionUppercase,
StatusCodes,
StatusCodesUnion,
} from './utils';
import { Cors, CorsOptions } from './middlewares/cors/cors';
import { WebSocketServer } from './websocket';
import { generateRouteSchema } from './schemas/generator';
} from './utils/index.js';
import { Cors, CorsOptions } from './middlewares/cors/cors.js';
import { WebSocketServer } from './websocket.js';
import { generateRouteSchema } from './schemas/generator.js';

import dns from 'dns';
import { createServer, IncomingMessage, ServerResponse, Server } from 'http';
Expand Down
8 changes: 4 additions & 4 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { StatusPhrases } from './status-phrases';
export { StatusCodes, StatusCodesUnion } from './status-codes';
export { HttpMethods, HttpMethodsUnion, HttpMethodsUnionUppercase } from './http-methods';
export { JSONStringify, JSONParse } from './safe-json';
export { StatusPhrases } from './status-phrases.js';
export { StatusCodes, StatusCodesUnion } from './status-codes.js';
export { HttpMethods, HttpMethodsUnion, HttpMethodsUnionUppercase } from './http-methods.js';
export { JSONStringify, JSONParse } from './safe-json.js';
4 changes: 2 additions & 2 deletions src/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import WebSocket, { WebSocketServer as WServer, type MessageEvent, type ServerOp
import callsites from 'callsites';
import hyperid from 'hyperid';

import { logMe } from './logger';
import { JSONParse, JSONStringify } from './utils';
import { logMe } from './logger/index.js';
import { JSONParse, JSONStringify } from './utils/index.js';

import { IncomingMessage, Server } from 'http';
import { Duplex } from 'stream';
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"compilerOptions": {
"declaration": true,
"downlevelIteration": true,
"module": "esnext",
"moduleResolution": "Node",
"module": "nodenext",
"moduleResolution": "nodenext",
"outDir": "./lib",
"target": "ESNext",
"lib": ["ES2015", "ES2016", "ES2017", "ES2018", "ES2019", "ES2020", "ESNext"],
Expand Down