@octoii-works/octoii-std 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +86 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -4,4 +4,8 @@ The notable changes of `@octoii-works/octoii-std`, newest first.
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.0.2] - 2026-10-31
|
|
8
|
+
|
|
9
|
+
## [0.0.1] - 2026-10-31
|
|
10
|
+
|
|
7
11
|
- First release: The general-purpose base library of Octoii: JSON, deltas, encodings, ids, schemas, async helpers, bounded text, SQLite, SSE and JSON-RPC.
|
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @octoii-works/octoii-std
|
|
2
|
+
|
|
3
|
+
The base every Octoii package stands on: JSON values and their changes, text encodings, hashes, ids, TypeBox
|
|
4
|
+
validation, time and cancellation, a portable SQLite connection, Server-Sent Events, JSON-RPC 2.0, addresses and text
|
|
5
|
+
diffs. It knows no agent, model or tool, and the same code runs on Bun, Node, browsers, workerd and the Hermes of
|
|
6
|
+
React Native.
|
|
7
|
+
|
|
8
|
+
Contents: [Where it sits](#where-it-sits) · [The subpaths](#the-subpaths) · [Everything from the caller](#everything-from-the-caller) ·
|
|
9
|
+
[SQLite](#sqlite) · [Constants](#constants) · [Testing](#testing).
|
|
10
|
+
|
|
11
|
+
## Where it sits
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
bun add @octoii-works/octoii-std
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- **At the bottom.** std depends on TypeBox alone, and every other Octoii package depends on it.
|
|
18
|
+
- **No root entry.** Every import names its subpath, so a program loads only what it uses:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { parseJson, type JsonValue } from "@octoii-works/octoii-std/json";
|
|
22
|
+
import { matches } from "@octoii-works/octoii-std/schema";
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## The subpaths
|
|
26
|
+
|
|
27
|
+
| Subpath | What it gives |
|
|
28
|
+
| --- | --- |
|
|
29
|
+
| `/json` | The JSON value model every package shares, `JsonValue` and `JsonObject`, with checks, `jsonEqual`, `copyJson` and a `parseJson` whose keys are own data only |
|
|
30
|
+
| `/delta` | How a JSON value changed, as operations: `diffJson` and `applyOps` |
|
|
31
|
+
| `/encoding` | UTF-8, base64, base64url and hex, strict when asked, so a value read back is the value written |
|
|
32
|
+
| `/hash` | SHA-256 in plain JavaScript, synchronous on every platform, and HMAC, PKCE and the check of an RSA signature on it |
|
|
33
|
+
| `/id` | UUIDs of versions 4 and 7, from the randomness and the time the caller passes |
|
|
34
|
+
| `/schema` | TypeBox validators compiled once per schema, `matches`, `parsed` and `validationProblems`, with the same results where code cannot be generated |
|
|
35
|
+
| `/async` | Clocks, `sleep`, timeouts (`withinLimit`), cancellation (`abortable`, `linkedSignal`) and backoff |
|
|
36
|
+
| `/errors` | `errorMessage` for an unknown error, and `unreachable` |
|
|
37
|
+
| `/sqlite` | A synchronous SQLite connection, `SqlDriver`, and consecutive schema migrations; its adapters are `/sqlite/bun`, `/sqlite/node` and `/sqlite/worker` |
|
|
38
|
+
| `/sse` | An incremental Server-Sent Events decoder that does no I/O |
|
|
39
|
+
| `/json-rpc` | JSON-RPC 2.0 messages, their checks, and the error codes as `JSON_RPC_ERRORS` |
|
|
40
|
+
| `/url` | Absolute addresses parsed and normalized without a platform URL parser, and their queries |
|
|
41
|
+
| `/text` | Text as editing tools read it: sizes and line counts, line endings, line diffs and the unified diff, and an edit's tiers |
|
|
42
|
+
| `/testing` | `portabilityProblems`, the scan of platform-neutral sources against what Hermes lacks |
|
|
43
|
+
|
|
44
|
+
## Everything from the caller
|
|
45
|
+
|
|
46
|
+
std reads no clock, timer, randomness or environment of its own: a function that needs one takes it.
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { systemClock, withinLimit } from "@octoii-works/octoii-std/async";
|
|
50
|
+
import { uuidv7 } from "@octoii-works/octoii-std/id";
|
|
51
|
+
|
|
52
|
+
const random = (length: number) => crypto.getRandomValues(new Uint8Array(length));
|
|
53
|
+
const id = uuidv7(systemClock.now(), random);
|
|
54
|
+
const answer = await withinLimit(fetch("https://example.com"), 5_000, systemClock);
|
|
55
|
+
if ("timedOut" in answer) console.log("gave up after 5 s");
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
So a test passes a fake clock and fixed bytes, and gets the same results every run.
|
|
59
|
+
|
|
60
|
+
## SQLite
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { bunSqlite } from "@octoii-works/octoii-std/sqlite/bun";
|
|
64
|
+
import { migrate } from "@octoii-works/octoii-std/sqlite";
|
|
65
|
+
|
|
66
|
+
const db = bunSqlite("app.db", { durability: "full" });
|
|
67
|
+
migrate(db, [
|
|
68
|
+
"CREATE TABLE notes (id TEXT PRIMARY KEY, text TEXT NOT NULL)",
|
|
69
|
+
"ALTER TABLE notes ADD COLUMN at INTEGER",
|
|
70
|
+
]);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
- **One interface, three platforms.** `bunSqlite` on Bun, `nodeSqlite` on Node, `durableObjectSql` in a Durable Object;
|
|
74
|
+
code written against `SqlDriver` runs on all three.
|
|
75
|
+
- **Synchronous.** Every statement returns its rows, so a transaction never waits in the middle.
|
|
76
|
+
- **Migrations count on.** `migrate` runs the statements past the schema's version, each once, in order.
|
|
77
|
+
|
|
78
|
+
## Constants
|
|
79
|
+
|
|
80
|
+
std's codes and limits are in one module, and each subpath gives those of its own, such as `JSON_RPC_ERRORS` from
|
|
81
|
+
`/json-rpc`, `DIFF_CONTEXT_LINES` from `/text` and `PKCE_VERIFIER_BYTES` from `/hash`.
|
|
82
|
+
|
|
83
|
+
## Testing
|
|
84
|
+
|
|
85
|
+
Each module's tests run on Bun and on Node. `portabilityProblems` from `/testing` is what every Octoii package's tests
|
|
86
|
+
use to keep platform-neutral code within what Hermes runs.
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@octoii-works/octoii-std",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"description": "The general-purpose base library of Octoii: JSON, deltas, encodings, ids, schemas, async helpers, bounded text, SQLite, SSE and JSON-RPC",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "Elian Yang (https://elianyang.com)",
|
|
9
|
-
"homepage": "https://github.com/octoii-works/octoii/tree/main/packages/std#readme",
|
|
9
|
+
"homepage": "https://github.com/octoii-works/octoii-siphon/tree/main/packages/std#readme",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/octoii-works/octoii.git",
|
|
12
|
+
"url": "git+https://github.com/octoii-works/octoii-siphon.git",
|
|
13
13
|
"directory": "packages/std"
|
|
14
14
|
},
|
|
15
15
|
"publishConfig": {
|