Use correct paths when referring to extended interfaces.master
@@ -37,3 +37,5 @@ | |||||
- [ ] Plugin support | - [ ] Plugin support | ||||
- [ ] Add option to reject content negotiation params with `406 Not Acceptable` | - [ ] Add option to reject content negotiation params with `406 Not Acceptable` | ||||
- [ ] Add `fast-check` for property-based checking | - [ ] Add `fast-check` for property-based checking | ||||
- [X] Split HTTP server from backend core | |||||
- [ ] Add HTTP entrypoint (package?) |
@@ -77,7 +77,7 @@ export interface Backend<T extends DataSource = DataSource> { | |||||
checksSerializersOnDelete(b?: boolean): this; | checksSerializersOnDelete(b?: boolean): this; | ||||
throwsErrorOnDeletingNotFound(b?: boolean): this; | throwsErrorOnDeletingNotFound(b?: boolean): this; | ||||
use<BackendExtended extends this>(extender: (state: BackendState, t: this) => BackendExtended): BackendExtended; | 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; | dataSource?: (resource: Resource) => T; | ||||
} | } | ||||
@@ -43,7 +43,7 @@ export const createBackend = (params: CreateBackendParams) => { | |||||
backendState.checksSerializersOnDelete = b; | backendState.checksSerializersOnDelete = b; | ||||
return this; | return this; | ||||
}, | }, | ||||
createServer(): Server { | |||||
createServer(_type: string, _options = {}): Server { | |||||
return { | return { | ||||
requestDecorator() { | requestDecorator() { | ||||
return this; | return this; | ||||
@@ -1,3 +1,6 @@ | |||||
export * from './core'; | export * from './core'; | ||||
export * from './common'; | export * from './common'; | ||||
export * from './data-source'; | 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,6 +1,6 @@ | |||||
import * as v from 'valibot'; | import * as v from 'valibot'; | ||||
import {PatchContentType} from './media-type'; | 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; | export const CAN_PATCH_VALID_VALUES = ['merge', 'delta'] as const; | ||||
@@ -12,8 +12,10 @@ import { | |||||
RequestDecorator, | RequestDecorator, | ||||
Response, | Response, | ||||
Server, | Server, | ||||
DataSource, | |||||
} from '../../backend'; | |||||
} from '../../backend/common'; | |||||
import { | |||||
DataSource | |||||
} from '../../backend/data-source'; | |||||
import { | import { | ||||
BaseResourceType, | BaseResourceType, | ||||
CanPatchSpec, | CanPatchSpec, | ||||
@@ -1,8 +1,8 @@ | |||||
import {ContentNegotiation} from '../../../../common'; | import {ContentNegotiation} from '../../../../common'; | ||||
import {RequestDecorator} from '../../../../backend'; | |||||
import {RequestDecorator} from '../../../../backend/common'; | |||||
import Negotiator from 'negotiator'; | import Negotiator from 'negotiator'; | ||||
declare module '../../../../backend' { | |||||
declare module '../../../../backend/common' { | |||||
interface RequestContext { | interface RequestContext { | ||||
cn: Partial<ContentNegotiation>; | cn: Partial<ContentNegotiation>; | ||||
} | } | ||||
@@ -1,8 +1,8 @@ | |||||
import {BackendState, ParamRequestDecorator} from '../../../../backend'; | |||||
import {BackendState, ParamRequestDecorator} from '../../../../backend/common'; | |||||
import {decorateRequestWithContentNegotiation} from './content-negotiation'; | import {decorateRequestWithContentNegotiation} from './content-negotiation'; | ||||
import {decorateRequestWithResource} from './resource'; | import {decorateRequestWithResource} from './resource'; | ||||
declare module '../../../../backend' { | |||||
declare module '../../../../backend/common' { | |||||
interface RequestContext { | interface RequestContext { | ||||
backend: BackendState; | backend: BackendState; | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
import {Resource} from '../../../../common'; | import {Resource} from '../../../../common'; | ||||
import {RequestDecorator} from '../../../../backend'; | |||||
import {RequestDecorator} from '../../../../backend/common'; | |||||
declare module '../../../../backend' { | |||||
declare module '../../../../backend/common' { | |||||
interface RequestContext { | interface RequestContext { | ||||
resource?: Resource; | resource?: Resource; | ||||
resourceId?: string; | resourceId?: string; | ||||
@@ -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_HEADER_NAME = 'x-original-method' as const; | ||||
const METHOD_SPOOF_ORIGINAL_METHOD = 'POST' as const; | const METHOD_SPOOF_ORIGINAL_METHOD = 'POST' as const; | ||||
@@ -1,6 +1,6 @@ | |||||
import {ParamRequestDecorator} from '../../../../backend'; | |||||
import {ParamRequestDecorator} from '../../../../backend/common'; | |||||
declare module '../../../../backend' { | |||||
declare module '../../../../backend/common' { | |||||
interface RequestContext { | interface RequestContext { | ||||
basePath: string; | basePath: string; | ||||
} | } | ||||
@@ -1,6 +1,6 @@ | |||||
import {ParamRequestDecorator} from '../../../../backend'; | |||||
import {ParamRequestDecorator} from '../../../../backend/common'; | |||||
declare module '../../../../backend' { | |||||
declare module '../../../../backend/common' { | |||||
interface RequestContext { | interface RequestContext { | ||||
host: string; | host: string; | ||||
} | } | ||||
@@ -1,10 +1,10 @@ | |||||
import {ParamRequestDecorator} from '../../../../backend'; | |||||
import {ParamRequestDecorator} from '../../../../backend/common'; | |||||
import {CreateServerParams} from '../../core'; | import {CreateServerParams} from '../../core'; | ||||
import {decorateRequestWithScheme} from './scheme'; | import {decorateRequestWithScheme} from './scheme'; | ||||
import {decorateRequestWithHost} from './host'; | import {decorateRequestWithHost} from './host'; | ||||
import {decorateRequestWithBasePath} from './base-path'; | import {decorateRequestWithBasePath} from './base-path'; | ||||
declare module '../../../../backend' { | |||||
declare module '../../../../backend/common' { | |||||
interface RequestContext { | interface RequestContext { | ||||
rawUrl?: string; | rawUrl?: string; | ||||
query: URLSearchParams; | query: URLSearchParams; | ||||
@@ -1,6 +1,6 @@ | |||||
import {ParamRequestDecorator} from '../../../../backend'; | |||||
import {ParamRequestDecorator} from '../../../../backend/common'; | |||||
declare module '../../../../backend' { | |||||
declare module '../../../../backend/common' { | |||||
interface RequestContext { | interface RequestContext { | ||||
scheme: string; | scheme: string; | ||||
} | } | ||||
@@ -1,5 +1,5 @@ | |||||
import {constants} from 'http2'; | import {constants} from 'http2'; | ||||
import {AllowedMiddlewareSpecification, getAllowString, Middleware} from '../../../backend'; | |||||
import {AllowedMiddlewareSpecification, getAllowString, Middleware} from '../../../backend/common'; | |||||
import {LinkMap} from '../utils'; | import {LinkMap} from '../utils'; | ||||
import {PlainResponse, ErrorPlainResponse} from '../response'; | import {PlainResponse, ErrorPlainResponse} from '../response'; | ||||
import {getAcceptPatchString, getAcceptPostString} from '../../../common'; | import {getAcceptPatchString, getAcceptPostString} from '../../../common'; | ||||
@@ -1,7 +1,7 @@ | |||||
import { constants } from 'http2'; | import { constants } from 'http2'; | ||||
import * as v from 'valibot'; | import * as v from 'valibot'; | ||||
import assert from 'assert'; | import assert from 'assert'; | ||||
import {Middleware} from '../../../backend'; | |||||
import {Middleware} from '../../../backend/common'; | |||||
import { | import { | ||||
applyDelta, Query, | applyDelta, Query, | ||||
Delta, | Delta, | ||||
@@ -1,5 +1,5 @@ | |||||
import {Language, LanguageStatusMessageMap} from '../../common'; | 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 { | interface PlainResponseParams<T = unknown, U extends NodeJS.EventEmitter = NodeJS.EventEmitter> extends Response { | ||||
body?: T; | body?: T; | ||||
@@ -1,6 +1,6 @@ | |||||
import {describe, afterAll, beforeAll, it} from 'vitest'; | import {describe, afterAll, beforeAll, it} from 'vitest'; | ||||
import {Application, application, resource, Resource, validation as v} from '../../src/common'; | 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 {createTestClient, DummyDataSource, dummyGenerationStrategy, TEST_LANGUAGE, TestClient} from '../utils'; | ||||
import {httpExtender, HttpServer} from '../../src/servers/http'; | import {httpExtender, HttpServer} from '../../src/servers/http'; | ||||
@@ -1,7 +1,7 @@ | |||||
import { application, resource, validation as v } from '@modal-sh/yasumi'; | import { application, resource, validation as v } from '@modal-sh/yasumi'; | ||||
import { http } from '@modal-sh/yasumi/backend'; | import { http } from '@modal-sh/yasumi/backend'; | ||||
import { randomUUID } from 'crypto'; | 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 { constants } from 'http2'; | ||||
import TAGALOG from './languages/tl'; | import TAGALOG from './languages/tl'; | ||||
@@ -17,8 +17,8 @@ const User = resource( | |||||
v.object({ | v.object({ | ||||
email: v.string([v.email()]), | email: v.string([v.email()]), | ||||
password: v.string(), | password: v.string(), | ||||
createdAt: v.datelike(), | |||||
updatedAt: v.datelike(), | |||||
createdAt: v.date(), | |||||
updatedAt: v.date(), | |||||
}) | }) | ||||
) | ) | ||||
.name('User') | .name('User') | ||||
@@ -59,9 +59,10 @@ const app = application({ | |||||
const backend = app.createBackend({ | const backend = app.createBackend({ | ||||
dataSource: new JsonLinesDataSource(), | dataSource: new JsonLinesDataSource(), | ||||
}) | }) | ||||
.use(http.httpExtender) | |||||
.throwsErrorOnDeletingNotFound(); | .throwsErrorOnDeletingNotFound(); | ||||
const server = backend.createHttpServer({ | |||||
const server = backend.createServer('http', { | |||||
basePath: '/api', | basePath: '/api', | ||||
}) | }) | ||||
.defaultErrorHandler((_req, res) => () => { | .defaultErrorHandler((_req, res) => () => { | ||||
@@ -20,6 +20,7 @@ export default { | |||||
badRequest: 'Maling Paghiling', | badRequest: 'Maling Paghiling', | ||||
ok: 'OK', | ok: 'OK', | ||||
provideOptions: 'Magbigay ng mga Pagpipilian', | provideOptions: 'Magbigay ng mga Pagpipilian', | ||||
resourceCollectionQueried: 'Hinanapan ang $RESOURCE Collection', | |||||
resourceCollectionFetched: 'Nakuha ang $RESOURCE Collection', | resourceCollectionFetched: 'Nakuha ang $RESOURCE Collection', | ||||
resourceFetched: 'Nakuha ang $RESOURCE', | resourceFetched: 'Nakuha ang $RESOURCE', | ||||
resourceNotFound: 'Hindi Nahanap ang $RESOURCE', | resourceNotFound: 'Hindi Nahanap ang $RESOURCE', | ||||