@tussle/core
Advanced tools
Comparing version 0.5.4 to 0.6.0
@@ -104,1 +104,2 @@ "use strict"; | ||
} | ||
//# sourceMappingURL=core.js.map |
@@ -7,22 +7,36 @@ "use strict"; | ||
function handleCreate(_core, ctx) { | ||
const params = extractCreationHeaders(ctx); | ||
const store = ctx.cfg.storage; | ||
return (0, rxjs_1.of)({ ctx }).pipe(withParametersFromContext, withConfiguredStorage, withParamsUpdatedByBeforeCreateHook, filterValidStoragePath, (0, operators_1.switchMap)(({ ctx, params, store }) => store.createFile(params).pipe((0, operators_1.map)((created) => ({ ctx, created })), postCreateHooks, (0, operators_1.map)((created) => toResponse(ctx, created)))), (0, operators_1.defaultIfEmpty)(Object.assign(Object.assign({}, ctx), { response: { | ||
status: 403, // Forbidden | ||
} }))); | ||
} | ||
exports.default = handleCreate; | ||
const filterValidStoragePath = (0, operators_1.filter)((item) => !!item.params.path); | ||
const withParametersFromContext = (0, rxjs_1.pipe)((0, operators_1.switchMap)((item) => { | ||
const params = extractCreationHeaders(item.ctx); | ||
if (isNaN(params.uploadLength)) { | ||
throw new Error('Failed to get upload length from header.'); | ||
} | ||
return (0, rxjs_1.of)(Object.assign(Object.assign({}, item), { params })); | ||
})); | ||
const withConfiguredStorage = (0, rxjs_1.pipe)((0, operators_1.map)((item) => { | ||
const store = item.ctx.cfg.storage; | ||
if (!store) { | ||
return (0, rxjs_1.throwError)(() => new Error('no storage service selected')); | ||
throw new Error('No storage service selected'); | ||
} | ||
else { | ||
const params$ = (0, rxjs_1.from)(ctx.source.hook('before-create', ctx, params)); | ||
return params$.pipe((0, operators_1.switchMap)((params) => store.createFile(params)), (0, operators_1.switchMap)((createdFile) => callOptionalHooks(ctx, createdFile)), (0, operators_1.switchMap)((createdFile) => ctx.source.hook('after-create', ctx, createdFile)), (0, operators_1.map)((createdFile) => toResponse(ctx, createdFile))); | ||
} | ||
} | ||
exports.default = handleCreate; | ||
const callOptionalHooks = (ctx, createdFile) => { | ||
return Object.assign(Object.assign({}, item), { store }); | ||
})); | ||
const withParamsUpdatedByBeforeCreateHook = (0, rxjs_1.pipe)((0, operators_1.switchMap)((item) => { | ||
return (0, rxjs_1.from)(item.ctx.source.hook('before-create', item.ctx, item.params)).pipe((0, operators_1.map)((params) => (Object.assign(Object.assign({}, item), { params })))); | ||
})); | ||
const postCreateHooks = (0, rxjs_1.pipe)((0, operators_1.switchMap)((item) => callOptionalHooks(item)), (0, operators_1.switchMap)(({ ctx, created }) => (0, rxjs_1.from)(ctx.source.hook('after-create', ctx, created)))); | ||
const callOptionalHooks = (item) => { | ||
var _a; | ||
if (((_a = createdFile.uploadConcat) === null || _a === void 0 ? void 0 : _a.action) === 'final') { | ||
const patchedFile = Object.assign(Object.assign({}, createdFile), { offset: createdFile.offset, complete: true, details: { | ||
tussleUploadMetadata: createdFile.metadata || {}, | ||
const { created, ctx } = item; | ||
if (((_a = created.uploadConcat) === null || _a === void 0 ? void 0 : _a.action) === 'final') { | ||
const patchedFile = Object.assign(Object.assign({}, created), { offset: created.offset, complete: true, details: { | ||
tussleUploadMetadata: created.metadata || {}, | ||
} }); | ||
return (0, rxjs_1.from)(ctx.source.hook('after-complete', ctx, patchedFile)); | ||
return (0, rxjs_1.from)(ctx.source.hook('after-complete', ctx, patchedFile)).pipe((0, operators_1.map)(() => item)); | ||
} | ||
return (0, rxjs_1.of)(createdFile); | ||
return (0, rxjs_1.of)(item); | ||
}; | ||
@@ -45,3 +59,3 @@ const extractCreationHeaders = (ctx) => { | ||
}, {}); | ||
// used by 'concatenation' extension | ||
// Used by 'concatenation' extension | ||
const uploadConcat = parseUploadConcat(header('upload-concat') || null); | ||
@@ -91,1 +105,2 @@ return { | ||
} | ||
//# sourceMappingURL=create.js.map |
@@ -44,1 +44,2 @@ "use strict"; | ||
}; | ||
//# sourceMappingURL=head.js.map |
@@ -17,1 +17,2 @@ "use strict"; | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -19,1 +19,2 @@ "use strict"; | ||
exports.default = handleOptions; | ||
//# sourceMappingURL=options.js.map |
/// <reference types="node" /> | ||
import type { TussleIncomingRequest } from '@tussle/spec/interface/request'; | ||
import { Observable } from 'rxjs'; | ||
import type { Tussle } from '../core'; | ||
import type { TussleIncomingRequest } from '@tussle/spec/interface/request'; | ||
export default function handlePatch<T, P>(_core: Tussle, ctx: TussleIncomingRequest<T, P>): Observable<TussleIncomingRequest<T, P>>; | ||
@@ -6,0 +6,0 @@ declare const extractPatchHeaders: <Req, P>(ctx: TussleIncomingRequest<Req, P>) => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const rxjs_1 = require("rxjs"); | ||
const rxjs_2 = require("rxjs"); | ||
const operators_1 = require("rxjs/operators"); | ||
@@ -18,5 +17,5 @@ function handlePatch(_core, ctx) { | ||
}; | ||
return (0, rxjs_2.of)(ctx); | ||
return (0, rxjs_1.of)(ctx); | ||
} | ||
const params$ = (0, rxjs_2.from)(ctx.source.hook('before-patch', ctx, params)); | ||
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))); | ||
@@ -31,5 +30,5 @@ } | ||
if (isComplete(patchedFile)) { | ||
return (0, rxjs_2.from)(ctx.source.hook('after-complete', ctx, patchedFile)); | ||
return (0, rxjs_1.from)(ctx.source.hook('after-complete', ctx, patchedFile)).pipe((0, operators_1.map)((hookResponse) => hookResponse || patchedFile)); | ||
} | ||
return (0, rxjs_2.of)(patchedFile); | ||
return (0, rxjs_1.of)(patchedFile); | ||
}; | ||
@@ -69,1 +68,2 @@ const extractPatchHeaders = (ctx) => { | ||
}; | ||
//# sourceMappingURL=patch.js.map |
@@ -12,1 +12,2 @@ "use strict"; | ||
Object.defineProperty(exports, "TussleBaseMiddleware", { enumerable: true, get: function () { return middleware_1.TussleBaseMiddleware; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -18,1 +18,2 @@ "use strict"; | ||
exports.TussleBaseMiddleware = TussleBaseMiddleware; | ||
//# sourceMappingURL=middleware.js.map |
@@ -31,1 +31,2 @@ "use strict"; | ||
exports.TussleStateNamespace = TussleStateNamespace; | ||
//# sourceMappingURL=state.js.map |
export declare type TTLCacheType<T> = T extends TTLCache<infer U> ? U : never; | ||
interface TTLCacheItem<T> { | ||
atime: number; | ||
data: T; | ||
} | ||
export declare class TTLCache<T> { | ||
@@ -12,3 +8,6 @@ private readonly ttl; | ||
private lastGarbageCollection; | ||
constructor(ttl?: number, garbageCollectionInterval?: number, cache?: Record<string, TTLCacheItem<T>>, now?: () => number); | ||
constructor(ttl?: number, garbageCollectionInterval?: number, cache?: Record<string, { | ||
atime: number; | ||
data: T; | ||
}>, now?: () => number); | ||
onRelease(_key: string, _data: T): void; | ||
@@ -25,2 +24,1 @@ getOrCreate(key: string, create: () => Promise<T>): Promise<T>; | ||
} | ||
export {}; |
@@ -101,1 +101,2 @@ "use strict"; | ||
exports.TTLCache = TTLCache; | ||
//# sourceMappingURL=ttlcache.js.map |
{ | ||
"name": "@tussle/core", | ||
"version": "0.5.4", | ||
"version": "0.6.0", | ||
"description": "Tussle tus daemon core module", | ||
@@ -23,7 +23,7 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@tussle/spec": "^0.5.4", | ||
"jest": "^29.1.2", | ||
"@tussle/spec": "^0.6.0", | ||
"jest": "^29.2.2", | ||
"npm-run-all": "^4.1.5", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^4.8.2" | ||
"typescript": "^4.8.4" | ||
}, | ||
@@ -37,3 +37,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "51cc6b91a2e8ff71681692e7ba33e4b2570b54af" | ||
"gitHead": "9706c7c8091970421e81515b56422e85ae771277" | ||
} |
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
48327
36
689