@geonosis/files
v0.1.1
Published
Where a file lives and where its bytes live: one shape for a folder and a name that can never climb out, an object key with the tenant in it, a size a person can read, an icon per content type as the consumer's table.
Maintainers
Readme
@geonosis/files
Where a file lives and where its bytes live: one shape for a folder and a name that can never climb out, an object key with the tenant in it, a size a person can read, and an icon per content type from the consumer's table. Engine-free, with no floor below it and no other domain named.
pnpm add @geonosis/filesWhere a file lives
normalizeFolder(folder)— exactly one shape for a folder, so two people who typed the same place two ways are in the same place:rootFolder(/) when nothing was typed, otherwise a leading slash and trimmed segments with nothing repeated. A backslash is a separator too. A segment that climbs —.or..— is refused by name withNotAFilePath.normalizeFileName(name)— a name is a name, never a path: trimmed; nothing, a separator, a dot name and a control character are each refused by name.joinPath({ folder, name })— both halves normalised, joined into one path.
Where its bytes live
objectKey({ tenant, fileId, prefix? })—<prefix>/<tenant>/<fileId>,fileKeyPrefix(files) when the consumer names no prefix. The tenant is IN the key, not merely checked before the key is used, and a tenant or id that could land the key under another tenant is refused.ownsKey({ tenant, key, prefix? })— whether a key a caller hands in is this tenant's: under this tenant's prefix, with nothing dotted after it. A key a caller hands us is not a key we trust.
What a person reads
formatFileSize(bytes)— binary units up toEB, one decimal at most, none when whole; an exact power of the unit lands in that unit. A size that is not one — negative, fractional, not finite — is refused by name withNotAFileSize.mimeIcon(contentType, { icons?, fallback? })— the icon for a content type, read off the header as sent (parameters dropped, case folded).defaultMimeIconsis a starting table; the consumer'siconsreplaces it, andfallback(file) answers for a type the table does not know.
What stays the consumer's
Which entity a file is linked to, and what that link is called; the upload and share routes of its
worker; which content types are worth handing to a model — @geonosis/extraction owns that list as
readableContentTypes, and this domain does not repeat it.
License
Apache-2.0
