@tussle/core
Advanced tools
Comparing version 0.6.12 to 0.7.0
@@ -9,5 +9,5 @@ import type { TussleIncomingRequest } from '@tussle/spec/interface/request'; | ||
} | ||
declare type IncomingRequestMethod = TussleIncomingRequest<unknown, unknown>['request']['method']; | ||
declare type IncomingRequestHandler = <T, P>(core: Tussle, ctx: TussleIncomingRequest<T, P>) => Observable<TussleIncomingRequest<T, P>>; | ||
declare type RequestHandler = Record<IncomingRequestMethod, IncomingRequestHandler>; | ||
type IncomingRequestMethod = TussleIncomingRequest<unknown, unknown>['request']['method']; | ||
type IncomingRequestHandler = <T, P>(ctx: TussleIncomingRequest<T, P>) => Observable<TussleIncomingRequest<T, P>>; | ||
type RequestHandler = Record<IncomingRequestMethod, IncomingRequestHandler>; | ||
export declare class Tussle { | ||
@@ -14,0 +14,0 @@ private readonly cfg; |
@@ -35,3 +35,3 @@ "use strict"; | ||
if (handler) { | ||
return handler(this, ctx); | ||
return handler(ctx); | ||
} | ||
@@ -38,0 +38,0 @@ } |
import { Observable } from "rxjs"; | ||
import type { TussleIncomingRequest } from '@tussle/spec/interface/request'; | ||
import type { Tussle } from '../core'; | ||
export default function handleHead<Req, P>(_core: Tussle, ctx: TussleIncomingRequest<Req, P>): Observable<TussleIncomingRequest<Req, P>>; | ||
export default function handleHead<Req, P>(ctx: TussleIncomingRequest<Req, P>): Observable<TussleIncomingRequest<Req, P>>; | ||
declare const extractParamsFromHeaders: <T, P>(ctx: TussleIncomingRequest<T, P>) => { | ||
location: string; | ||
}; | ||
export declare type ExtractedHeadHeaders = ReturnType<typeof extractParamsFromHeaders>; | ||
export type ExtractedHeadHeaders = ReturnType<typeof extractParamsFromHeaders>; | ||
export {}; | ||
//# sourceMappingURL=head.d.ts.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
const operators_1 = require("rxjs/operators"); | ||
function handleHead(_core, ctx) { | ||
function handleHead(ctx) { | ||
const params = extractParamsFromHeaders(ctx); | ||
@@ -8,0 +8,0 @@ const store = ctx.cfg.storage; |
@@ -1,2 +0,2 @@ | ||
import handleCreate from './create'; | ||
import handlePost from './post'; | ||
import handlePatch from './patch'; | ||
@@ -6,3 +6,3 @@ import handleHead from './head'; | ||
export declare const defaultHandlers: { | ||
POST: typeof handleCreate; | ||
POST: typeof handlePost; | ||
PATCH: typeof handlePatch; | ||
@@ -9,0 +9,0 @@ HEAD: typeof handleHead; |
@@ -7,3 +7,3 @@ "use strict"; | ||
exports.defaultHandlers = void 0; | ||
const create_1 = __importDefault(require("./create")); | ||
const post_1 = __importDefault(require("./post")); | ||
const patch_1 = __importDefault(require("./patch")); | ||
@@ -13,3 +13,3 @@ const head_1 = __importDefault(require("./head")); | ||
exports.defaultHandlers = { | ||
'POST': create_1.default, | ||
'POST': post_1.default, | ||
'PATCH': patch_1.default, | ||
@@ -16,0 +16,0 @@ 'HEAD': head_1.default, |
import type { TussleIncomingRequest } from '@tussle/spec/interface/request'; | ||
import type { Observable } from 'rxjs'; | ||
import type { Tussle } from '../core'; | ||
declare const defaultResponse: { | ||
@@ -11,5 +10,5 @@ status: number; | ||
}; | ||
export default function handleOptions<Req, P>(_core: Tussle, ctx: TussleIncomingRequest<Req, P>): Observable<TussleIncomingRequest<Req, P>>; | ||
export declare type OptionsDefaultResponse = typeof defaultResponse; | ||
export default function handleOptions<Req, P>(ctx: TussleIncomingRequest<Req, P>): Observable<TussleIncomingRequest<Req, P>>; | ||
export type OptionsDefaultResponse = typeof defaultResponse; | ||
export {}; | ||
//# sourceMappingURL=options.d.ts.map |
@@ -14,3 +14,3 @@ "use strict"; | ||
}; | ||
function handleOptions(_core, ctx) { | ||
function handleOptions(ctx) { | ||
const response$ = (0, rxjs_1.from)(ctx.source.hook('before-options', ctx, Object.assign({}, defaultResponse))).pipe((0, operators_1.map)((response) => (Object.assign(Object.assign({}, ctx), { response })))); | ||
@@ -17,0 +17,0 @@ return response$; |
@@ -1,9 +0,12 @@ | ||
/// <reference types="node" /> | ||
import type { TussleIncomingRequest } from '@tussle/spec/interface/request'; | ||
import type { TussleStoragePatchFileResponse } from '@tussle/spec/interface/storage'; | ||
import { Observable } from 'rxjs'; | ||
import type { Tussle } from '../core'; | ||
export default function handlePatch<T, P>(_core: Tussle, ctx: TussleIncomingRequest<T, P>): Observable<TussleIncomingRequest<T, P>>; | ||
export default function handlePatch<T, P>(ctx: TussleIncomingRequest<T, P>): Observable<TussleIncomingRequest<T, P>>; | ||
export declare function processUploadBodyAndCallHooks<T, P>(ctx: TussleIncomingRequest<T, P>): Observable<{ | ||
ctx: TussleIncomingRequest<T, P>; | ||
patchedFile: TussleStoragePatchFileResponse | null; | ||
}>; | ||
declare const extractPatchHeaders: <Req, P>(ctx: TussleIncomingRequest<Req, P>) => { | ||
contentType: string; | ||
getReadable: () => import("stream").Readable | Uint8Array | ReadableStream<Uint8Array> | undefined; | ||
getReadable: () => Uint8Array | ReadableStream<Uint8Array> | undefined; | ||
length: number; | ||
@@ -14,4 +17,4 @@ location: string; | ||
}; | ||
export declare type ExtractedPatchHeaders = ReturnType<typeof extractPatchHeaders>; | ||
export type ExtractedPatchHeaders = ReturnType<typeof extractPatchHeaders>; | ||
export {}; | ||
//# sourceMappingURL=patch.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.processUploadBodyAndCallHooks = void 0; | ||
const rxjs_1 = require("rxjs"); | ||
const operators_1 = require("rxjs/operators"); | ||
function handlePatch(_core, ctx) { | ||
function handlePatch(ctx) { | ||
return processUploadBodyAndCallHooks(ctx).pipe((0, operators_1.map)(({ ctx, patchedFile }) => { | ||
if (!patchedFile) { | ||
return ctx; | ||
} | ||
return toResponse(ctx, patchedFile); | ||
})); | ||
} | ||
exports.default = handlePatch; | ||
function processUploadBodyAndCallHooks(ctx) { | ||
const store = ctx.cfg.storage; | ||
const params = extractPatchHeaders(ctx); | ||
const store = ctx.cfg.storage; | ||
if (!store) { | ||
return (0, rxjs_1.throwError)(() => new Error('no storage service selected')); | ||
return (0, rxjs_1.throwError)(() => new Error('no storage service sleected')); | ||
} | ||
// PATCH requests MUST use Content-Type: application/offset+octet-stream | ||
// Upload requests MUST use Content-Type: application/offset+octet-stream | ||
if (params.contentType !== 'application/offset+octet-stream') { | ||
@@ -17,8 +27,7 @@ ctx.response = { | ||
}; | ||
return (0, rxjs_1.of)(ctx); | ||
return (0, rxjs_1.of)({ ctx, patchedFile: null }); | ||
} | ||
const params$ = (0, rxjs_1.from)(ctx.source.hook('before-patch', ctx, params)); | ||
return params$.pipe((0, operators_1.switchMap)((params) => store.patchFile(params)), (0, operators_1.switchMap)((patchedFile) => callOptionalHooks(ctx, patchedFile)), (0, operators_1.switchMap)((patchedFile) => ctx.source.hook('after-patch', ctx, patchedFile)), (0, operators_1.map)((patchedFile) => toResponse(ctx, patchedFile))); | ||
return (0, rxjs_1.of)(params).pipe((0, operators_1.switchMap)(params => store.patchFile(params)), (0, operators_1.switchMap)((patchedFile) => callOptionalHooks(ctx, patchedFile)), (0, operators_1.switchMap)((patchedFile) => ctx.source.hook('after-patch', ctx, patchedFile)), (0, operators_1.map)((patchedFile) => ({ ctx, patchedFile }))); | ||
} | ||
exports.default = handlePatch; | ||
exports.processUploadBodyAndCallHooks = processUploadBodyAndCallHooks; | ||
function isComplete(response) { | ||
@@ -41,3 +50,3 @@ return response.complete; | ||
const length = intHeader('content-length'); | ||
const offset = intHeader('upload-offset'); | ||
const offset = intHeader('upload-offset') || 0; | ||
const getReadable = () => ctx.request.getReadable(); | ||
@@ -44,0 +53,0 @@ return { |
@@ -1,2 +0,2 @@ | ||
export declare type TTLCacheType<T> = T extends TTLCache<infer U> ? U : never; | ||
export type TTLCacheType<T> = T extends TTLCache<infer U> ? U : never; | ||
export declare class TTLCache<T> { | ||
@@ -3,0 +3,0 @@ private readonly ttl; |
{ | ||
"name": "@tussle/core", | ||
"version": "0.6.12", | ||
"version": "0.7.0", | ||
"description": "Tussle tus daemon core module", | ||
@@ -23,7 +23,7 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@tussle/spec": "^0.6.12", | ||
"@tussle/spec": "^0.7.0", | ||
"jest": "^29.2.2", | ||
"npm-run-all": "^4.1.5", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^4.8.4" | ||
"typescript": "^4.9.3" | ||
}, | ||
@@ -37,3 +37,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "085ef255d8191123f54d506296b2b4773a5696f7" | ||
"gitHead": "5a1db14dc48c3082895197bd1e711339c0839e7f" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52391
624