Kaynağa Gözat

Update structure

Organize exports.
refactor/new-arch
TheoryOfNekomata 5 ay önce
ebeveyn
işleme
615eb4ce5b
7 değiştirilmiş dosya ile 15 ekleme ve 15 silme
  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 Dosyayı Görüntüle

@@ -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 Dosyayı Görüntüle

@@ -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 Dosyayı Görüntüle

@@ -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 Dosyayı Görüntüle

@@ -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 Dosyayı Görüntüle

@@ -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 Dosyayı Görüntüle

@@ -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 Dosyayı Görüntüle

@@ -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);
});
});



Yükleniyor…
İptal
Kaydet