ソースを参照

Update interface augmentations

Use correct paths when referring to extended interfaces.
master
TheoryOfNekomata 6ヶ月前
コミット
a10c4baff8
20個のファイルの変更37行の追加28行の削除
  1. +2
    -0
      TODO.md
  2. +1
    -1
      packages/core/src/backend/common.ts
  3. +1
    -1
      packages/core/src/backend/core.ts
  4. +3
    -0
      packages/core/src/backend/index.ts
  5. +1
    -1
      packages/core/src/common/resource.ts
  6. +4
    -2
      packages/core/src/servers/http/core.ts
  7. +2
    -2
      packages/core/src/servers/http/decorators/backend/content-negotiation.ts
  8. +2
    -2
      packages/core/src/servers/http/decorators/backend/index.ts
  9. +2
    -2
      packages/core/src/servers/http/decorators/backend/resource.ts
  10. +1
    -1
      packages/core/src/servers/http/decorators/method/index.ts
  11. +2
    -2
      packages/core/src/servers/http/decorators/url/base-path.ts
  12. +2
    -2
      packages/core/src/servers/http/decorators/url/host.ts
  13. +2
    -2
      packages/core/src/servers/http/decorators/url/index.ts
  14. +2
    -2
      packages/core/src/servers/http/decorators/url/scheme.ts
  15. +1
    -1
      packages/core/src/servers/http/handlers/default.ts
  16. +1
    -1
      packages/core/src/servers/http/handlers/resource.ts
  17. +1
    -1
      packages/core/src/servers/http/response.ts
  18. +1
    -1
      packages/core/test/features/decorators.test.ts
  19. +5
    -4
      packages/examples/cms-web-api/src/index.ts
  20. +1
    -0
      packages/examples/cms-web-api/src/languages/tl.ts

+ 2
- 0
TODO.md ファイルの表示

@@ -37,3 +37,5 @@
- [ ] Plugin support
- [ ] Add option to reject content negotiation params with `406 Not Acceptable`
- [ ] Add `fast-check` for property-based checking
- [X] Split HTTP server from backend core
- [ ] Add HTTP entrypoint (package?)

+ 1
- 1
packages/core/src/backend/common.ts ファイルの表示

@@ -77,7 +77,7 @@ export interface Backend<T extends DataSource = DataSource> {
checksSerializersOnDelete(b?: boolean): this;
throwsErrorOnDeletingNotFound(b?: boolean): this;
use<BackendExtended extends this>(extender: (state: BackendState, t: this) => BackendExtended): BackendExtended;
createServer<T extends Server>(type: string, options?: {}): T;
createServer<T extends Server = Server>(type: string, options?: {}): T;
dataSource?: (resource: Resource) => T;
}



+ 1
- 1
packages/core/src/backend/core.ts ファイルの表示

@@ -43,7 +43,7 @@ export const createBackend = (params: CreateBackendParams) => {
backendState.checksSerializersOnDelete = b;
return this;
},
createServer(): Server {
createServer(_type: string, _options = {}): Server {
return {
requestDecorator() {
return this;


+ 3
- 0
packages/core/src/backend/index.ts ファイルの表示

@@ -1,3 +1,6 @@
export * from './core';
export * from './common';
export * from './data-source';

// where to put these? we should be publishing them as a separate entry point
export * as http from '../servers/http';

+ 1
- 1
packages/core/src/common/resource.ts ファイルの表示

@@ -1,6 +1,6 @@
import * as v from 'valibot';
import {PatchContentType} from './media-type';
import {DataSource, ResourceIdConfig} from '../backend';
import {DataSource, ResourceIdConfig} from '../backend/data-source';

export const CAN_PATCH_VALID_VALUES = ['merge', 'delta'] as const;



+ 4
- 2
packages/core/src/servers/http/core.ts ファイルの表示

@@ -12,8 +12,10 @@ import {
RequestDecorator,
Response,
Server,
DataSource,
} from '../../backend';
} from '../../backend/common';
import {
DataSource
} from '../../backend/data-source';
import {
BaseResourceType,
CanPatchSpec,


+ 2
- 2
packages/core/src/servers/http/decorators/backend/content-negotiation.ts ファイルの表示

@@ -1,8 +1,8 @@
import {ContentNegotiation} from '../../../../common';
import {RequestDecorator} from '../../../../backend';
import {RequestDecorator} from '../../../../backend/common';
import Negotiator from 'negotiator';

declare module '../../../../backend' {
declare module '../../../../backend/common' {
interface RequestContext {
cn: Partial<ContentNegotiation>;
}


+ 2
- 2
packages/core/src/servers/http/decorators/backend/index.ts ファイルの表示

@@ -1,8 +1,8 @@
import {BackendState, ParamRequestDecorator} from '../../../../backend';
import {BackendState, ParamRequestDecorator} from '../../../../backend/common';
import {decorateRequestWithContentNegotiation} from './content-negotiation';
import {decorateRequestWithResource} from './resource';

declare module '../../../../backend' {
declare module '../../../../backend/common' {
interface RequestContext {
backend: BackendState;
}


+ 2
- 2
packages/core/src/servers/http/decorators/backend/resource.ts ファイルの表示

@@ -1,7 +1,7 @@
import {Resource} from '../../../../common';
import {RequestDecorator} from '../../../../backend';
import {RequestDecorator} from '../../../../backend/common';

declare module '../../../../backend' {
declare module '../../../../backend/common' {
interface RequestContext {
resource?: Resource;
resourceId?: string;


+ 1
- 1
packages/core/src/servers/http/decorators/method/index.ts ファイルの表示

@@ -1,4 +1,4 @@
import {RequestDecorator} from '../../../../backend';
import {RequestDecorator} from '../../../../backend/common';

const METHOD_SPOOF_HEADER_NAME = 'x-original-method' as const;
const METHOD_SPOOF_ORIGINAL_METHOD = 'POST' as const;


+ 2
- 2
packages/core/src/servers/http/decorators/url/base-path.ts ファイルの表示

@@ -1,6 +1,6 @@
import {ParamRequestDecorator} from '../../../../backend';
import {ParamRequestDecorator} from '../../../../backend/common';

declare module '../../../../backend' {
declare module '../../../../backend/common' {
interface RequestContext {
basePath: string;
}


+ 2
- 2
packages/core/src/servers/http/decorators/url/host.ts ファイルの表示

@@ -1,6 +1,6 @@
import {ParamRequestDecorator} from '../../../../backend';
import {ParamRequestDecorator} from '../../../../backend/common';

declare module '../../../../backend' {
declare module '../../../../backend/common' {
interface RequestContext {
host: string;
}


+ 2
- 2
packages/core/src/servers/http/decorators/url/index.ts ファイルの表示

@@ -1,10 +1,10 @@
import {ParamRequestDecorator} from '../../../../backend';
import {ParamRequestDecorator} from '../../../../backend/common';
import {CreateServerParams} from '../../core';
import {decorateRequestWithScheme} from './scheme';
import {decorateRequestWithHost} from './host';
import {decorateRequestWithBasePath} from './base-path';

declare module '../../../../backend' {
declare module '../../../../backend/common' {
interface RequestContext {
rawUrl?: string;
query: URLSearchParams;


+ 2
- 2
packages/core/src/servers/http/decorators/url/scheme.ts ファイルの表示

@@ -1,6 +1,6 @@
import {ParamRequestDecorator} from '../../../../backend';
import {ParamRequestDecorator} from '../../../../backend/common';

declare module '../../../../backend' {
declare module '../../../../backend/common' {
interface RequestContext {
scheme: string;
}


+ 1
- 1
packages/core/src/servers/http/handlers/default.ts ファイルの表示

@@ -1,5 +1,5 @@
import {constants} from 'http2';
import {AllowedMiddlewareSpecification, getAllowString, Middleware} from '../../../backend';
import {AllowedMiddlewareSpecification, getAllowString, Middleware} from '../../../backend/common';
import {LinkMap} from '../utils';
import {PlainResponse, ErrorPlainResponse} from '../response';
import {getAcceptPatchString, getAcceptPostString} from '../../../common';


+ 1
- 1
packages/core/src/servers/http/handlers/resource.ts ファイルの表示

@@ -1,7 +1,7 @@
import { constants } from 'http2';
import * as v from 'valibot';
import assert from 'assert';
import {Middleware} from '../../../backend';
import {Middleware} from '../../../backend/common';
import {
applyDelta, Query,
Delta,


+ 1
- 1
packages/core/src/servers/http/response.ts ファイルの表示

@@ -1,5 +1,5 @@
import {Language, LanguageStatusMessageMap} from '../../common';
import {MiddlewareResponseError, Response} from '../../backend';
import {MiddlewareResponseError, Response} from '../../backend/common';

interface PlainResponseParams<T = unknown, U extends NodeJS.EventEmitter = NodeJS.EventEmitter> extends Response {
body?: T;


+ 1
- 1
packages/core/test/features/decorators.test.ts ファイルの表示

@@ -1,6 +1,6 @@
import {describe, afterAll, beforeAll, it} from 'vitest';
import {Application, application, resource, Resource, validation as v} from '../../src/common';
import {Backend, DataSource, RequestContext, Server} from '../../src/backend';
import {Backend, DataSource, RequestContext} from '../../src/backend';
import {createTestClient, DummyDataSource, dummyGenerationStrategy, TEST_LANGUAGE, TestClient} from '../utils';
import {httpExtender, HttpServer} from '../../src/servers/http';



+ 5
- 4
packages/examples/cms-web-api/src/index.ts ファイルの表示

@@ -1,7 +1,7 @@
import { application, resource, validation as v } from '@modal-sh/yasumi';
import { http } from '@modal-sh/yasumi/backend';
import { randomUUID } from 'crypto';
import {JsonLinesDataSource} from '@modal-sh/yasumi-data-source-file-jsonl';
import { JsonLinesDataSource } from '@modal-sh/yasumi-data-source-file-jsonl';
import { constants } from 'http2';
import TAGALOG from './languages/tl';

@@ -17,8 +17,8 @@ const User = resource(
v.object({
email: v.string([v.email()]),
password: v.string(),
createdAt: v.datelike(),
updatedAt: v.datelike(),
createdAt: v.date(),
updatedAt: v.date(),
})
)
.name('User')
@@ -59,9 +59,10 @@ const app = application({
const backend = app.createBackend({
dataSource: new JsonLinesDataSource(),
})
.use(http.httpExtender)
.throwsErrorOnDeletingNotFound();

const server = backend.createHttpServer({
const server = backend.createServer('http', {
basePath: '/api',
})
.defaultErrorHandler((_req, res) => () => {


+ 1
- 0
packages/examples/cms-web-api/src/languages/tl.ts ファイルの表示

@@ -20,6 +20,7 @@ export default {
badRequest: 'Maling Paghiling',
ok: 'OK',
provideOptions: 'Magbigay ng mga Pagpipilian',
resourceCollectionQueried: 'Hinanapan ang $RESOURCE Collection',
resourceCollectionFetched: 'Nakuha ang $RESOURCE Collection',
resourceFetched: 'Nakuha ang $RESOURCE',
resourceNotFound: 'Hindi Nahanap ang $RESOURCE',


読み込み中…
キャンセル
保存