瀏覽代碼

Update structure

Organize exports.
refactor/new-arch
TheoryOfNekomata 6 月之前
父節點
當前提交
615eb4ce5b
共有 7 個檔案被更改,包括 15 行新增15 行删除
  1. +1
    -2
      packages/core/src/backend/common.ts
  2. +1
    -1
      packages/core/src/backend/server.ts
  3. +1
    -1
      packages/core/src/common/endpoint.ts
  4. +1
    -1
      packages/core/src/common/index.ts
  5. +1
    -1
      packages/core/src/common/recipe.ts
  6. +8
    -8
      packages/core/src/extenders/http/backend/core.ts
  7. +2
    -1
      packages/core/test/index.test.ts

+ 1
- 2
packages/core/src/backend/common.ts 查看文件

@@ -1,5 +1,4 @@
import {App as BaseApp, AppOperations, BaseAppState, Endpoint} from '../common';
import {Response} from '../common/response';
import {App as BaseApp, AppOperations, BaseAppState, Endpoint, Response} from '../common';

interface BackendParams<App extends BaseApp> {
app: App;


+ 1
- 1
packages/core/src/backend/server.ts 查看文件

@@ -1,5 +1,5 @@
import {Backend as BaseBackend} from './common';
import {ServiceParams} from '../common';
import {Backend as BaseBackend} from './common';

export interface ServerRequest {}



+ 1
- 1
packages/core/src/common/endpoint.ts 查看文件

@@ -1,5 +1,5 @@
import * as v from 'valibot';
import {DataSource} from './data-source';
import {validation as v} from '.';

export type EndpointQueue = [Endpoint, Record<string, unknown> | undefined][];



+ 1
- 1
packages/core/src/common/index.ts 查看文件

@@ -7,5 +7,5 @@ export * from './media-type';
export * from './operation';
export * from './response';
export * from './service';
export * from './status-codes';
export * as statusCodes from './status-codes';
export * as validation from 'valibot';

+ 1
- 1
packages/core/src/common/recipe.ts 查看文件

@@ -1,6 +1,6 @@
import {Backend} from '../backend';
import {Operation} from './operation';
import {App} from './app';
import {Backend} from '../backend';
import {Endpoint} from './endpoint';

export interface RecipeState<A extends App = App> {


+ 8
- 8
packages/core/src/extenders/http/backend/core.ts 查看文件

@@ -7,7 +7,7 @@ import {
ServerParams,
} from '../../../backend';
import http from 'http';
import { constants } from 'http2';
import { statusCodes } from '../../../common';

declare module '../../../backend' {
interface ServerRequest extends http.IncomingMessage {}
@@ -26,12 +26,12 @@ class ServerInstance<Backend extends BaseBackend> implements Server<Backend> {
private readonly requestListener = async (req: ServerRequest, res: ServerResponse) => {
// const endpoints = this.backend.app.endpoints;
if (typeof req.method === 'undefined') {
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, {});
res.writeHead(statusCodes.HTTP_STATUS_BAD_REQUEST, {});
res.end();
return;
}
if (typeof req.url === 'undefined') {
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, {});
res.writeHead(statusCodes.HTTP_STATUS_BAD_REQUEST, {});
res.end();
return;
}
@@ -44,7 +44,7 @@ class ServerInstance<Backend extends BaseBackend> implements Server<Backend> {
.find((op) => op.method === req.method?.toUpperCase());

if (typeof foundAppOperation === 'undefined') {
res.writeHead(constants.HTTP_STATUS_METHOD_NOT_ALLOWED, {
res.writeHead(statusCodes.HTTP_STATUS_METHOD_NOT_ALLOWED, {
'Allow': appOperations.map((op) => op.method).join(',')
});
res.end();
@@ -53,7 +53,7 @@ class ServerInstance<Backend extends BaseBackend> implements Server<Backend> {

const endpointOperations = Array.from(endpoint?.operations ?? []);
if (!endpointOperations.includes(foundAppOperation.name)) {
res.writeHead(constants.HTTP_STATUS_METHOD_NOT_ALLOWED, {
res.writeHead(statusCodes.HTTP_STATUS_METHOD_NOT_ALLOWED, {
'Allow': endpointOperations
.map((a) => appOperations.find((aa) => aa.name === a)?.method)
.join(',')
@@ -64,13 +64,13 @@ class ServerInstance<Backend extends BaseBackend> implements Server<Backend> {

const implementation = this.backend.implementations.get(foundAppOperation.name);
if (typeof implementation === 'undefined') {
res.writeHead(constants.HTTP_STATUS_NOT_IMPLEMENTED);
res.writeHead(statusCodes.HTTP_STATUS_NOT_IMPLEMENTED);
res.end();
return;
}

if (typeof endpoint === 'undefined') {
res.writeHead(constants.HTTP_STATUS_NOT_IMPLEMENTED);
res.writeHead(statusCodes.HTTP_STATUS_NOT_IMPLEMENTED);
res.end();
return;
}
@@ -88,7 +88,7 @@ class ServerInstance<Backend extends BaseBackend> implements Server<Backend> {
});

if (typeof responseSpec === 'undefined') {
res.writeHead(constants.HTTP_STATUS_UNPROCESSABLE_ENTITY, {});
res.writeHead(statusCodes.HTTP_STATUS_UNPROCESSABLE_ENTITY, {});
res.end();
return;
}


+ 2
- 1
packages/core/test/index.test.ts 查看文件

@@ -7,6 +7,7 @@ import {
endpoint,
Operation,
operation,
statusCodes,
validation as v,
} from '../src/common';
import {Backend, backend, Server} from '../src/backend';
@@ -99,7 +100,7 @@ describe('app', () => {
.at(theEndpoint, { resourceId: 3 })
.makeRequest(theOperation);

expect(response).toHaveProperty('status', 422);
expect(response).toHaveProperty('status', statusCodes.HTTP_STATUS_UNPROCESSABLE_ENTITY);
});
});



Loading…
取消
儲存