Framework-neutral tus 1.0 resumable upload protocol state machine for MoonBit
let engine = @tus.TusEngine::new().unwrap()
let response = engine.handle(@tus.options_request())
assert_eq!(response.status, 204)pub(all) struct AppendPlan {
identifier : String
expected_revision : Int64
old_offset : Int64
new_offset : Int64
resolved_length : UploadLength
body : Bytes
completes_upload : Bool
} derive(Eq, Debug)pub(all) struct ConformanceExpectation {
status : Int
error_code : String?
response_offset : Int64?
store : StoreExpectation
} derive(Eq, Debug)pub(all) struct ConformanceReport {
results : Array[ConformanceResult]
passed : Int
failed : Int
} derive(Eq, Debug)pub(all) struct ConformanceResult {
name : String
passed : Bool
response : TusResponse
findings : Array[String]
} derive(Eq, Debug)pub(all) struct ConformanceVector {
name : String
initial_records : Array[UploadRecord]
request : TusRequest
expected : ConformanceExpectation
} derive(Eq, Debug)pub(all) struct CreationPlan {
length : UploadLength
metadata : Array[MetadataEntry]
} derive(Eq, Debug)fn Headers::required_singleton(self : Headers, name : String, missing_kind : TusErrorKind) -> Result[String, TusError]pub struct MemoryStore {
// private fields
}fn MemoryStore::commit_append(self : MemoryStore, plan : AppendPlan, limits : TusLimits) -> Result[UploadRecord, TusError]fn MemoryStore::create(self : MemoryStore, plan : CreationPlan, limits : TusLimits) -> Result[UploadRecord, TusError]fn MemoryStore::import_record(self : MemoryStore, record : UploadRecord, limits : TusLimits) -> Result[Unit, TusError]pub(all) enum ScenarioAction {
Discover
CreateKnown(String, Int64, Array[MetadataEntry])
CreateDeferred(String, Array[MetadataEntry])
Inspect(String)
Append(String, Int64, Bytes, Int64?)
} derive(Eq, Debug)pub(all) struct ScenarioReport {
events : Array[ScenarioEvent]
uploads : Array[UploadRecord]
succeeded : Bool
} derive(Eq, Debug)pub(all) enum StoreExpectation {
IgnoreStore
ResourceMissing(String)
ResourceState(String, Int64, UploadLength, UploadLifecycle, Bytes)
} derive(Eq, Debug)pub(all) struct TusError {
kind : TusErrorKind
code : String
message : String
status : Int
header_name : String?
expected : String?
actual : String?
} derive(Eq, Debug)pub(all) enum TusErrorKind {
InvalidMethod
InvalidPath
InvalidHeaderName
UnsafeHeaderValue
MissingTusResumable
UnsupportedVersion
DuplicateSingletonHeader
InvalidUnsignedInteger
IntegerOverflow
MissingUploadOffset
OffsetMismatch
MissingContentType
InvalidContentType
MissingContentLength
BodyLengthMismatch
MissingUploadLength
ConflictingUploadLength
InvalidDeferredLength
UploadTooLarge
UploadNotFound
UploadAlreadyComplete
UploadTerminated
InvalidMetadata
DuplicateMetadataKey
MetadataTooLarge
TooManyMetadataEntries
InvalidBase64
HeaderCountExceeded
HeaderBytesExceeded
BodyTooLarge
IdentifierExhausted
StorageConflict
StorageFailure
UnsupportedExtension
InvalidScenario
UnsupportedScenario
InternalInvariant
} derive(Eq, Debug)pub(all) struct TusRequest {
http_method : HttpMethod
path : String
headers : Headers
body : Bytes
} derive(Eq, Debug)pub(all) struct UploadRecord {
identifier : String
offset : Int64
length : UploadLength
metadata : Array[MetadataEntry]
revision : Int64
lifecycle : UploadLifecycle
data : Bytes
} derive(Eq, Debug)let TUS_VERSION : Stringfn encode_base64(input : Bytes) -> Stringfn parse_upload_metadata(value : String, limits : TusLimits) -> Result[Array[MetadataEntry], TusError]fn plan_append(request : TusRequest, record : UploadRecord, config : TusConfig) -> Result[AppendPlan, TusError]fn run_conformance_suite(vectors : Array[ConformanceVector], config? : TusConfig) -> Result[ConformanceReport, TusError]fn run_conformance_vector(vector : ConformanceVector, config? : TusConfig) -> Result[ConformanceResult, TusError]fn run_scenario(actions : Array[ScenarioAction], config? : TusConfig) -> Result[ScenarioReport, TusError]fn tus_error(kind : TusErrorKind, code : String, message : String, status? : Int, header_name? : String?, expected? : String?, actual? : String?) -> TusErrorfn upload_record(identifier : String, length : UploadLength, metadata? : Array[MetadataEntry]) -> UploadRecordfn validate_append_plan(current : UploadRecord, plan : AppendPlan, limits : TusLimits) -> Result[Unit, TusError]Install
Download zipFramework-neutral tus 1.0 resumable upload protocol state machine for MoonBit