@obversa/memory defines one storage-neutral memory port. The port has a
scope and one execute method.
/memories. The port accepts these commands:
A result has
ok: true and a typed value, or ok: false and a typed error.
Adapters use the same limits and error codes. A conformance kit checks this
contract without a network service.
Command examples
UseviewRange: [start, end] to read selected lines. Line numbers in a view
start at 1. Use -1 as the end to read the rest of the file.
create makes a file. It replaces the file if the path exists.
str_replace changes one text match. It fails if it finds zero matches or
more than one non-overlapping match.
insertLine is a zero-based slot. Use 0 to insert before the first line.
Use 1 to insert after the first line.
An insert rewrites the file with \n line endings. A full view and a text
replacement preserve the stored line endings.
delete removes one file or a directory and all files below it.
rename moves a file or a complete directory. It does not replace an existing
destination.
Storage limits
The two initial adapters use these default limits:- One file can contain 65,536 bytes.
- One scope can contain 1,048,576 bytes.
- One scope can contain 256 files.
.txt, .md, .json, .py, .yaml, and .yml files.
When a write exceeds a scope limit, the adapter removes the file with the
earliest write time. A read does not change the write time. The adapter does
not remove the target of the new write.
Path rules
A path can contain letters, numbers, periods, underscores, and hyphens. Each path segment can contain 128 characters. A complete path can contain 1,024 bytes. A scope and all written text must contain complete Unicode characters. The adapters reject malformed Unicode instead of replacing incomplete characters. The memory root cannot be a file. A caller cannot delete or rename the memory root. Directory deletion is recursive. A rename does not replace an existing path.Errors
An unsuccessful result contains the command, the error code, and a message.
Some errors also contain the applicable path and structured details.