@tussle/core
Advanced tools
Comparing version 0.2.2 to 0.2.3
import type { TussleIncomingRequest } from '@tussle/spec/interface/request'; | ||
import type { Tussle } from '../core'; | ||
import { Observable } from 'rxjs'; | ||
export default function handleCreate<R>(core: Tussle, ctx: Readonly<TussleIncomingRequest<R>>): Observable<TussleIncomingRequest<R>>; | ||
export default function handleCreate<R>(_core: Tussle, ctx: Readonly<TussleIncomingRequest<R>>): Observable<TussleIncomingRequest<R>>; | ||
export interface TussleCreationParams { | ||
@@ -6,0 +6,0 @@ id: string; |
@@ -6,27 +6,10 @@ "use strict"; | ||
const operators_1 = require("rxjs/operators"); | ||
function defaultPath(path, filename) { | ||
return [ | ||
path, | ||
Math.floor(Math.random() * 1e16).toString(16), | ||
encodeURIComponent(filename), | ||
].join('/'); | ||
} | ||
// If the before-create hook didn't set the location, for the file being | ||
// created, then generate a default based on the request path and metadata | ||
// filename. | ||
const ensureFilePath = (originalPath) => (0, operators_1.map)(params => { | ||
if (params.path === originalPath) { | ||
params.path = defaultPath(params.path, params.uploadMetadata.filename); | ||
} | ||
return params; | ||
}); | ||
function handleCreate(core, ctx) { | ||
function handleCreate(_core, ctx) { | ||
const params = extractCreationHeaders(ctx); | ||
const originalPath = params.path; | ||
const store = ctx.cfg.storage; | ||
if (!store) { | ||
return (0, rxjs_1.throwError)('no storage service selected'); | ||
return (0, rxjs_1.throwError)(() => new Error('no storage service selected')); | ||
} | ||
else { | ||
const params$ = ctx.source.hook('before-create', ctx, params).pipe(ensureFilePath(originalPath)); | ||
const params$ = ctx.source.hook('before-create', ctx, params); | ||
return params$.pipe((0, operators_1.switchMap)((params) => store.createFile(params)), (0, operators_1.switchMap)((createdFile) => ctx.source.hook('after-create', ctx, createdFile)), (0, operators_1.map)((createdFile) => toResponse(ctx, createdFile))); | ||
@@ -33,0 +16,0 @@ } |
import { Observable } from "rxjs"; | ||
import type { TussleIncomingRequest } from '@tussle/spec/interface/request'; | ||
import type { Tussle } from '../core'; | ||
export default function handleHead<Req>(core: Tussle, ctx: TussleIncomingRequest<Req>): Observable<TussleIncomingRequest<Req>>; | ||
export default function handleHead<Req>(_core: Tussle, ctx: TussleIncomingRequest<Req>): Observable<TussleIncomingRequest<Req>>; | ||
declare const extractParamsFromHeaders: <T>(ctx: TussleIncomingRequest<T>) => { | ||
@@ -6,0 +6,0 @@ location: string; |
@@ -5,7 +5,7 @@ "use strict"; | ||
const operators_1 = require("rxjs/operators"); | ||
function handleHead(core, ctx) { | ||
function handleHead(_core, ctx) { | ||
const params = extractParamsFromHeaders(ctx); | ||
const store = ctx.cfg.storage; | ||
if (!store) { | ||
return (0, rxjs_1.throwError)('no storage service selected'); | ||
return (0, rxjs_1.throwError)(() => new Error('no storage service selected')); | ||
} | ||
@@ -12,0 +12,0 @@ else { |
@@ -5,3 +5,3 @@ /// <reference types="node" /> | ||
import type { TussleIncomingRequest } from '@tussle/spec/interface/request'; | ||
export default function handlePatch<T>(core: Tussle, ctx: TussleIncomingRequest<T>): Observable<TussleIncomingRequest<T>>; | ||
export default function handlePatch<T>(_core: Tussle, ctx: TussleIncomingRequest<T>): Observable<TussleIncomingRequest<T>>; | ||
declare const extractPatchHeaders: <Req>(ctx: TussleIncomingRequest<Req>) => { | ||
@@ -8,0 +8,0 @@ contentType: string; |
@@ -6,7 +6,7 @@ "use strict"; | ||
const operators_1 = require("rxjs/operators"); | ||
function handlePatch(core, ctx) { | ||
function handlePatch(_core, ctx) { | ||
const params = extractPatchHeaders(ctx); | ||
const store = ctx.cfg.storage; | ||
if (!store) { | ||
return (0, rxjs_1.throwError)('no storage service selected'); | ||
return (0, rxjs_1.throwError)(() => new Error('no storage service selected')); | ||
} | ||
@@ -13,0 +13,0 @@ // PATCH requests MUST use Content-Type: application/offset+octet-stream |
{ | ||
"name": "@tussle/core", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Tussle tus daemon core module", | ||
@@ -35,3 +35,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "2328201ed539a02b092d6743ca90e65354aa913f" | ||
"gitHead": "ec8013768f04e3060ee20df06caf99cfa86f222e" | ||
} |
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
27532
631