@hop-top/kit 0.5.0-alpha.11 → 0.5.0-alpha.13
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 +47 -0
- package/README.md +5 -5
- package/dist/bus-D2bAOPYz.d.ts +55 -0
- package/dist/bus.d.ts +1 -0
- package/dist/bus.js +13 -0
- package/dist/chunk-74E6RNOI.js +82 -0
- package/dist/chunk-B7XTFDBB.js +17 -0
- package/dist/chunk-CAONBSPO.js +497 -0
- package/dist/chunk-F7RSL4N4.js +88 -0
- package/dist/chunk-I6XDPSXQ.js +75 -0
- package/dist/chunk-IDM6YZXN.js +204 -0
- package/dist/chunk-P3Y46PYF.js +138 -0
- package/dist/chunk-VKQCOVKI.js +880 -0
- package/dist/cli.js +3 -3
- package/dist/id/index.d.ts +1 -1
- package/dist/id/index.js +4 -2
- package/dist/index-BqZ7WGQf.d.ts +731 -0
- package/dist/{index-VLDcI5NF.d.ts → index-D9zpUrpE.d.ts} +18 -6
- package/dist/index.d.ts +5 -2
- package/dist/index.js +27 -13
- package/dist/upgrade/drivers/configfile.d.ts +45 -0
- package/dist/upgrade/drivers/configfile.js +78 -0
- package/dist/upgrade/drivers/fsdir.d.ts +61 -0
- package/dist/upgrade/drivers/fsdir.js +170 -0
- package/dist/upgrade/drivers/postgres.d.ts +121 -0
- package/dist/upgrade/drivers/postgres.js +195 -0
- package/dist/upgrade/drivers/sqlite.d.ts +101 -0
- package/dist/upgrade/drivers/sqlite.js +241 -0
- package/dist/upgrade/index.d.ts +2 -0
- package/dist/upgrade/index.js +73 -0
- package/dist/uri-IJ_AoY3d.d.ts +144 -0
- package/dist/uri.d.ts +1 -0
- package/dist/uri.js +37 -0
- package/dist/version-DEJ3pbiO.d.ts +10 -0
- package/dist/wizard-Bf_qHc31.d.ts +159 -0
- package/dist/wizard.d.ts +1 -0
- package/dist/wizard.js +39 -0
- package/package.json +78 -19
- package/skills/hop-top-kit-ts/.claude-plugin/plugin.json +19 -0
- package/skills/hop-top-kit-ts/SKILL.md +117 -0
- package/skills/hop-top-kit-ts/assets/snippets/mcp/mcp.expected +2 -0
- package/skills/hop-top-kit-ts/assets/snippets/mcp/mcp.ts +20 -0
- package/skills/hop-top-kit-ts/assets/snippets/quickstart/quickstart.expected +13 -0
- package/skills/hop-top-kit-ts/assets/snippets/quickstart/quickstart.ts +26 -0
- package/skills/hop-top-kit-ts/gym.json +5 -0
- package/skills/hop-top-kit-ts/references/ai-and-agents.md +45 -0
- package/skills/hop-top-kit-ts/references/cli-and-console.md +63 -0
- package/skills/hop-top-kit-ts/references/coverage.md +56 -0
- package/skills/hop-top-kit-ts/references/guardrails-and-trust.md +60 -0
- package/skills/hop-top-kit-ts/references/other-ports.md +31 -0
- package/skills/hop-top-kit-ts/references/serving-and-transports.md +49 -0
- package/skills/hop-top-kit-ts/scripts/detect-port.sh +168 -0
- package/src/id/README.md +2 -2
- package/src/id/contract.test.ts +11 -8
- package/src/id/differential.test.ts +54 -0
- package/src/id/index.ts +123 -17
- package/src/index.test.ts +48 -2
- package/src/index.ts +6 -1
- package/src/published-types.test.ts +8 -0
- package/src/serve.stopped-order.test.ts +156 -0
- package/src/upgrade/README.md +42 -0
- package/src/upgrade/backup.ts +174 -0
- package/src/upgrade/conformance.test.ts +310 -0
- package/src/upgrade/document.ts +229 -0
- package/src/upgrade/driver.ts +66 -0
- package/src/upgrade/drivers/README.md +47 -0
- package/src/upgrade/drivers/configfile.test.ts +112 -0
- package/src/upgrade/drivers/configfile.ts +107 -0
- package/src/upgrade/drivers/fsdir.test.ts +188 -0
- package/src/upgrade/drivers/fsdir.ts +216 -0
- package/src/upgrade/drivers/isolation.test.ts +18 -0
- package/src/upgrade/drivers/postgres.integration.test.ts +395 -0
- package/src/upgrade/drivers/postgres.test.ts +272 -0
- package/src/upgrade/drivers/postgres.ts +284 -0
- package/src/upgrade/drivers/sqlite.integration.test.ts +492 -0
- package/src/upgrade/drivers/sqlite.ts +300 -0
- package/src/upgrade/drivers/version.ts +21 -0
- package/src/upgrade/errors.ts +117 -0
- package/src/upgrade/events.ts +117 -0
- package/src/{upgrade.test.ts → upgrade/index.test.ts} +102 -1
- package/src/{upgrade.ts → upgrade/index.ts} +96 -27
- package/src/upgrade/migration.ts +89 -0
- package/src/upgrade/migrator.test.ts +391 -0
- package/src/upgrade/migrator.ts +527 -0
- package/src/upgrade/options.ts +59 -0
- package/src/upgrade/semver.ts +90 -0
- package/test/skill-snippets.test.ts +60 -0
- package/test/upgrade/conformance-migrator.ts +439 -0
- package/test/upgrade/conformance-support.ts +44 -0
- package/test/upgrade/driver-support.ts +44 -0
- package/test/upgrade/pg-container.ts +64 -0
- package/test/upgrade/pg-race-worker.ts +48 -0
- package/test/upgrade/race-helper.ts +36 -0
- package/test/upgrade/sqlite-support.ts +41 -0
- package/test/upgrade/testdata/go-fsdir-mydata.tar.gz +0 -0
- package/vitest.config.ts +26 -0
- package/dist/chunk-4GPCWBBA.js +0 -143
- package/dist/chunk-L23O2FFE.js +0 -51
- package/dist/upgrade-C3RWGwRi.d.ts +0 -125
- package/dist/upgrade.d.ts +0 -1
- package/dist/upgrade.js +0 -7
- package/dist/{chunk-MFVUENZR.js → chunk-KV7FYEAF.js} +2 -2
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# detect-port.sh - report which kit port(s) a project directory already uses.
|
|
3
|
+
#
|
|
4
|
+
# Usage: detect-port.sh [dir] dir defaults to the current directory.
|
|
5
|
+
#
|
|
6
|
+
# Reads manifest files directly inside dir (no recursion). Writes nothing,
|
|
7
|
+
# touches no network, runs no package manager.
|
|
8
|
+
#
|
|
9
|
+
# Manifests, in the order they are reported:
|
|
10
|
+
# go.mod module hop.top/kit
|
|
11
|
+
# package.json @hop-top/kit
|
|
12
|
+
# pyproject.toml hop-top-kit
|
|
13
|
+
# requirements*.txt hop-top-kit
|
|
14
|
+
# uv.lock hop-top-kit
|
|
15
|
+
# Cargo.toml hop-top-kit
|
|
16
|
+
# composer.json hop-top/kit
|
|
17
|
+
#
|
|
18
|
+
# Output: one line per manifest found, fields separated by single spaces,
|
|
19
|
+
# key=value, no value contains a space:
|
|
20
|
+
# port=<go|ts|py|rs|php> manifest=<file> kit=<spec> skill=<name> url=<url>
|
|
21
|
+
# kit=<spec> is the version or range as the manifest writes it (spaces
|
|
22
|
+
# removed), "unpinned" when kit is listed without one, "absent" when the
|
|
23
|
+
# manifest does not list kit, "unreadable" when the file cannot be read.
|
|
24
|
+
# url is the port skill's SKILL.md. A directory with no manifest prints
|
|
25
|
+
# nothing on stdout and one note on stderr.
|
|
26
|
+
#
|
|
27
|
+
# Exit codes:
|
|
28
|
+
# 0 dir is readable (whether or not any manifest was found)
|
|
29
|
+
# 2 usage error, or dir is not a readable directory
|
|
30
|
+
|
|
31
|
+
LC_ALL=C
|
|
32
|
+
export LC_ALL
|
|
33
|
+
|
|
34
|
+
usage() {
|
|
35
|
+
echo "usage: detect-port.sh [dir]" >&2
|
|
36
|
+
exit 2
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
case ${1-} in
|
|
40
|
+
-h | --help)
|
|
41
|
+
echo "usage: detect-port.sh [dir]"
|
|
42
|
+
exit 0
|
|
43
|
+
;;
|
|
44
|
+
-*) usage ;;
|
|
45
|
+
esac
|
|
46
|
+
[ $# -le 1 ] || usage
|
|
47
|
+
dir=${1:-.}
|
|
48
|
+
if [ ! -d "$dir" ] || [ ! -r "$dir" ] || [ ! -x "$dir" ]; then
|
|
49
|
+
echo "detect-port: not a readable directory: $dir" >&2
|
|
50
|
+
exit 2
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
found=0
|
|
54
|
+
|
|
55
|
+
# report <port> <file> <spec>
|
|
56
|
+
report() {
|
|
57
|
+
case $1 in
|
|
58
|
+
go) skill=hop-top-kit-go mirror=kit ;;
|
|
59
|
+
ts) skill=hop-top-kit-ts mirror=kit-ts ;;
|
|
60
|
+
py) skill=hop-top-kit-py mirror=kit-py ;;
|
|
61
|
+
rs) skill=hop-top-kit-rs mirror=kit-rs ;;
|
|
62
|
+
php) skill=hop-top-kit-php mirror=kit-php ;;
|
|
63
|
+
esac
|
|
64
|
+
printf 'port=%s manifest=%s kit=%s skill=%s url=https://github.com/hop-top/%s/blob/main/skills/%s/SKILL.md\n' \
|
|
65
|
+
"$1" "$2" "$3" "$skill" "$mirror" "$skill"
|
|
66
|
+
found=1
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
# check <port> <name> <extractor> [path]: report when the manifest exists.
|
|
70
|
+
check() {
|
|
71
|
+
path=${4:-$dir/$2}
|
|
72
|
+
[ -f "$path" ] || return 0
|
|
73
|
+
if [ -r "$path" ]; then
|
|
74
|
+
spec=$(extract "$3" "$path" | tr -d ' \t')
|
|
75
|
+
else
|
|
76
|
+
spec=unreadable
|
|
77
|
+
fi
|
|
78
|
+
report "$1" "$2" "${spec:-unpinned}"
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# Extractors print the spec, "absent", or nothing for an unpinned entry.
|
|
82
|
+
|
|
83
|
+
extract() {
|
|
84
|
+
case $1 in
|
|
85
|
+
gomod) ex_gomod "$2" ;;
|
|
86
|
+
package) ex_package "$2" ;;
|
|
87
|
+
python) ex_python "$2" ;;
|
|
88
|
+
uvlock) ex_uvlock "$2" ;;
|
|
89
|
+
cargo) ex_cargo "$2" ;;
|
|
90
|
+
composer) ex_composer "$2" ;;
|
|
91
|
+
esac
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
# json_dep <key> <file>: the value of "<key>": "<value>".
|
|
95
|
+
json_dep() {
|
|
96
|
+
v=$(sed -n 's|.*"'"$1"'"[[:space:]]*:[[:space:]]*"\([^"]*\)".*|\1|p' "$2" | head -n 1)
|
|
97
|
+
[ -n "$v" ] && echo "$v" || echo absent
|
|
98
|
+
}
|
|
99
|
+
ex_package() { json_dep '@hop-top/kit' "$1"; }
|
|
100
|
+
ex_composer() { json_dep 'hop-top/kit' "$1"; }
|
|
101
|
+
|
|
102
|
+
ex_gomod() {
|
|
103
|
+
awk '
|
|
104
|
+
$1 == "require" && $2 == "hop.top/kit" && $3 ~ /^v[0-9]/ { print $3; f = 1; exit }
|
|
105
|
+
$1 == "hop.top/kit" && $2 ~ /^v[0-9]/ { print $2; f = 1; exit }
|
|
106
|
+
END { if (!f) print "absent" }' "$1"
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
# Python: requirement lines and TOML dependency entries, name normalised.
|
|
110
|
+
ex_python() {
|
|
111
|
+
awk '
|
|
112
|
+
/^[ \t]*#/ || /^[ \t]*name[ \t]*=/ { next }
|
|
113
|
+
{
|
|
114
|
+
low = tolower($0); gsub(/[_.]/, "-", low)
|
|
115
|
+
for (off = 0; (i = index(substr(low, off + 1), "hop-top-kit")) > 0; off += i) {
|
|
116
|
+
p = off + i
|
|
117
|
+
if (p > 1 && substr(low, p - 1, 1) ~ /[a-z0-9-]/) continue
|
|
118
|
+
if (substr(low, p + 11, 1) ~ /[a-z0-9-]/) continue
|
|
119
|
+
f = 1; rest = substr($0, p + 11)
|
|
120
|
+
sub(/^\[[^]]*\]/, "", rest)
|
|
121
|
+
if (match(rest, /^[ \t]*=[ \t]*["'"'"'][^"'"'"']*["'"'"']/)) {
|
|
122
|
+
v = substr(rest, RSTART, RLENGTH); sub(/^[ \t]*=[ \t]*["'"'"']/, "", v); sub(/["'"'"']$/, "", v)
|
|
123
|
+
} else if (match(rest, /^[ \t]*[<>=!~]+[ \t]*[^"'"'"';# \t,]*([ \t]*,[ \t]*[<>=!~]+[ \t]*[^"'"'"';# \t,]*)*/)) {
|
|
124
|
+
v = substr(rest, RSTART, RLENGTH); sub(/^[ \t]+/, "", v)
|
|
125
|
+
}
|
|
126
|
+
print v; exit
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
END { if (!f) print "absent" }' "$1"
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
ex_uvlock() {
|
|
133
|
+
awk '
|
|
134
|
+
tolower($0) ~ /^name[ \t]*=[ \t]*"hop[-_.]top[-_.]kit"/ { hit = 1; next }
|
|
135
|
+
hit && /^version[ \t]*=/ { v = $0; sub(/^[^"]*"/, "", v); sub(/".*/, "", v); print v; f = 1; exit }
|
|
136
|
+
/^\[\[package\]\]/ { hit = 0 }
|
|
137
|
+
END { if (!f) print (hit ? "" : "absent") }' "$1"
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
ex_cargo() {
|
|
141
|
+
awk '
|
|
142
|
+
/^[ \t]*#/ { next }
|
|
143
|
+
/^\[/ { tbl = ($0 ~ /dependencies\.hop-top-kit[ \t]*\]/); if (tbl) f = 1; next }
|
|
144
|
+
tbl && /^version[ \t]*=/ { v = $0; sub(/^[^"]*"/, "", v); sub(/".*/, "", v); print v; exit }
|
|
145
|
+
/^hop-top-kit[ \t]*=/ {
|
|
146
|
+
f = 1; v = $0; sub(/^[^=]*=[ \t]*/, "", v)
|
|
147
|
+
if (v ~ /^"/) { sub(/^"/, "", v); sub(/".*/, "", v) }
|
|
148
|
+
else if (match(v, /version[ \t]*=[ \t]*"[^"]*"/)) {
|
|
149
|
+
v = substr(v, RSTART, RLENGTH); sub(/^[^"]*"/, "", v); sub(/"$/, "", v)
|
|
150
|
+
} else v = ""
|
|
151
|
+
print v; exit
|
|
152
|
+
}
|
|
153
|
+
END { if (!f) print "absent" }' "$1"
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
check go go.mod gomod
|
|
157
|
+
check ts package.json package
|
|
158
|
+
check py pyproject.toml python
|
|
159
|
+
for req in "$dir"/requirements*.txt; do
|
|
160
|
+
[ -f "$req" ] || continue
|
|
161
|
+
check py "${req##*/}" python "$req"
|
|
162
|
+
done
|
|
163
|
+
check py uv.lock uvlock
|
|
164
|
+
check rs Cargo.toml cargo
|
|
165
|
+
check php composer.json composer
|
|
166
|
+
|
|
167
|
+
[ "$found" -eq 1 ] || echo "detect-port: no kit-relevant manifest in $dir" >&2
|
|
168
|
+
exit 0
|
package/src/id/README.md
CHANGED
|
@@ -21,10 +21,10 @@ console.log(id, parse(id).uuid);
|
|
|
21
21
|
|
|
22
22
|
## Contract
|
|
23
23
|
|
|
24
|
-
-
|
|
24
|
+
- Self-contained TypeID (spec v0.3, UUIDv7), no runtime dependency; the string returned by `newId` is the JSON wire form and round-trips losslessly through `parse`. `fromUUID` encodes an existing UUID.
|
|
25
25
|
- Prefix grammar and length limit follow the typeid spec pinned in the fixture; a divergence is a wire-format break.
|
|
26
26
|
- No transitive dependency on the URI registry, by design.
|
|
27
|
-
- Parity: [`contracts/typeid-v1/fixtures.json`](../../../../contracts/typeid-v1/fixtures.json), replayed by [`contract.test.ts`](contract.test.ts).
|
|
27
|
+
- Parity: [`contracts/typeid-v1/fixtures.json`](../../../../contracts/typeid-v1/fixtures.json), replayed by [`contract.test.ts`](contract.test.ts); [`differential.test.ts`](differential.test.ts) checks against `typeid-js`, the reference implementation, as a dev dependency.
|
|
28
28
|
|
|
29
29
|
## Neighbours
|
|
30
30
|
|
package/src/id/contract.test.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Cross-language parity contract test.
|
|
2
2
|
//
|
|
3
3
|
// Loads contracts/typeid-v1/fixtures.json from the repo root and
|
|
4
|
-
// asserts that this TS SDK's encode (
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
4
|
+
// asserts that this TS SDK's encode (fromUUID) and decode (parse)
|
|
5
|
+
// agree with the canonical wire form shared by go/rs/py/php, and that
|
|
6
|
+
// typeid-js, the reference implementation, still agrees too. A
|
|
7
|
+
// divergence means the SDK drifted, typeid-js drifted, or the contract
|
|
8
|
+
// was edited without updating all five SDKs.
|
|
8
9
|
|
|
9
10
|
import { existsSync, readFileSync } from 'node:fs';
|
|
10
11
|
import { dirname, resolve } from 'node:path';
|
|
@@ -13,7 +14,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
13
14
|
import { describe, it, expect } from 'vitest';
|
|
14
15
|
import { TypeID } from 'typeid-js';
|
|
15
16
|
|
|
16
|
-
import { parse } from './index';
|
|
17
|
+
import { fromUUID, parse } from './index';
|
|
17
18
|
|
|
18
19
|
interface ContractVector {
|
|
19
20
|
readonly name: string;
|
|
@@ -65,9 +66,11 @@ describe('typeid-v1 contract generation (TS)', () => {
|
|
|
65
66
|
for (const v of CONTRACT.vectors) {
|
|
66
67
|
const skipped = v.skip_in?.includes('ts') ?? false;
|
|
67
68
|
const fn = skipped ? it.skip : it;
|
|
68
|
-
fn(`vector ${v.name}:
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
fn(`vector ${v.name}: fromUUID produces the pinned canonical`, () => {
|
|
70
|
+
expect(fromUUID(v.prefix, v.uuid)).toBe(v.typeid);
|
|
71
|
+
});
|
|
72
|
+
fn(`vector ${v.name}: typeid-js (reference) agrees`, () => {
|
|
73
|
+
expect(TypeID.fromUUID(v.prefix, v.uuid).toString()).toBe(v.typeid);
|
|
71
74
|
});
|
|
72
75
|
}
|
|
73
76
|
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Differential test: the SDK's self-contained TypeID against typeid-js,
|
|
2
|
+
// the reference implementation (a dev dependency only). Random UUIDs
|
|
3
|
+
// and prefixes for the happy path; a fixed list of malformed inputs
|
|
4
|
+
// both must reject.
|
|
5
|
+
|
|
6
|
+
import { randomUUID } from 'node:crypto';
|
|
7
|
+
|
|
8
|
+
import { describe, expect, it } from 'vitest';
|
|
9
|
+
import { TypeID } from 'typeid-js';
|
|
10
|
+
|
|
11
|
+
import { fromUUID, newId, parse } from './index';
|
|
12
|
+
|
|
13
|
+
const PREFIXES = ['', 'a', 'task', 'my_app', 'a__b', 'a_b_c', 'z'.repeat(63)];
|
|
14
|
+
|
|
15
|
+
describe('differential vs typeid-js', () => {
|
|
16
|
+
it('encodes and decodes like typeid-js for random UUIDs', () => {
|
|
17
|
+
for (let i = 0; i < 500; i++) {
|
|
18
|
+
const uuid = randomUUID();
|
|
19
|
+
const prefix = PREFIXES[i % PREFIXES.length]!;
|
|
20
|
+
const ours = fromUUID(prefix, uuid);
|
|
21
|
+
expect(ours).toBe(TypeID.fromUUID(prefix, uuid).toString());
|
|
22
|
+
const ref = TypeID.fromString(ours);
|
|
23
|
+
expect(parse(ours)).toEqual({ prefix: ref.getType(), uuid: ref.toUUID() });
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('mints UUIDv7 ids typeid-js accepts', () => {
|
|
28
|
+
for (const prefix of PREFIXES) {
|
|
29
|
+
const id = newId(prefix);
|
|
30
|
+
const { uuid } = parse(id);
|
|
31
|
+
expect(uuid[14]).toBe('7');
|
|
32
|
+
expect('89ab').toContain(uuid[19]);
|
|
33
|
+
expect(TypeID.fromString(id).toString()).toBe(id);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it.each([
|
|
38
|
+
'not-a-typeid',
|
|
39
|
+
'task_too_short',
|
|
40
|
+
'_01jg000000e008000000000000',
|
|
41
|
+
'Task_01jg000000e008000000000000',
|
|
42
|
+
'task__01jg000000e008000000000000',
|
|
43
|
+
'_task_01jg000000e008000000000000',
|
|
44
|
+
'task_81jg000000e008000000000000',
|
|
45
|
+
'task_01JG000000E008000000000000',
|
|
46
|
+
'task_01jg000000e00800000000000u',
|
|
47
|
+
'task_01jg000000e0080000000000000',
|
|
48
|
+
`${'a'.repeat(64)}_01jg000000e008000000000000`,
|
|
49
|
+
'task1_01jg000000e008000000000000',
|
|
50
|
+
])('rejects %s like typeid-js', (s) => {
|
|
51
|
+
expect(() => TypeID.fromString(s)).toThrow();
|
|
52
|
+
expect(() => parse(s)).toThrow();
|
|
53
|
+
});
|
|
54
|
+
});
|
package/src/id/index.ts
CHANGED
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
* @module id
|
|
3
3
|
* @package @hop-top/kit
|
|
4
4
|
*
|
|
5
|
-
* TypeID primitive
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* TypeID primitive implementing the cross-language kit API SHAPE per
|
|
6
|
+
* docs/announcements/2026-05-typeid-primitive.md, on the jetify TypeID
|
|
7
|
+
* spec v0.3. Self-contained: no runtime dependency, so no transitive
|
|
8
|
+
* uuid release reaches adopters (typeid-js 1.2.0 pins uuid ^10, under
|
|
9
|
+
* an open advisory). contracts/typeid-v1/fixtures.json and a
|
|
10
|
+
* differential test against typeid-js (dev only) keep it on the wire
|
|
11
|
+
* format.
|
|
8
12
|
*
|
|
9
13
|
* Canonical wire form: `<prefix>_<26-char-base32>` where the suffix is
|
|
10
14
|
* a Crockford-base32-encoded UUIDv7. The TS surface adds a
|
|
11
15
|
* template-literal `Typed<P>` for compile-time prefix safety on top of
|
|
12
|
-
* the runtime
|
|
16
|
+
* the runtime checks in {@link parse}.
|
|
13
17
|
*
|
|
14
18
|
* URI composition (e.g. `tlc://task/task_…`) is NOT in this module —
|
|
15
19
|
* callers should use the `@hop-top/cite` package directly. This
|
|
@@ -17,9 +21,107 @@
|
|
|
17
21
|
* registry.
|
|
18
22
|
*/
|
|
19
23
|
|
|
20
|
-
import { typeid, TypeID } from 'typeid-js';
|
|
21
24
|
import { z } from 'zod';
|
|
22
25
|
|
|
26
|
+
// Crockford base32, lowercase, as the TypeID spec defines it.
|
|
27
|
+
const ALPHABET = '0123456789abcdefghjkmnpqrstvwxyz';
|
|
28
|
+
const DECODE: Record<string, number> = Object.fromEntries(
|
|
29
|
+
[...ALPHABET].map((c, i) => [c, i]),
|
|
30
|
+
);
|
|
31
|
+
// Spec v0.3: up to 63 chars of [a-z_], starting and ending with [a-z].
|
|
32
|
+
const PREFIX_RE = /^(?:[a-z](?:[a-z_]{0,61}[a-z])?)?$/;
|
|
33
|
+
|
|
34
|
+
function checkPrefix(prefix: string): void {
|
|
35
|
+
if (!PREFIX_RE.test(prefix)) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`invalid typeid prefix '${prefix}': want up to 63 chars of [a-z_], starting and ending with a letter`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 16 bytes -> 26 chars: 130 bits, the top two always zero.
|
|
43
|
+
function encode(bytes: Uint8Array): string {
|
|
44
|
+
let n = 0n;
|
|
45
|
+
for (const b of bytes) n = (n << 8n) | BigInt(b);
|
|
46
|
+
let out = '';
|
|
47
|
+
for (let i = 0; i < 26; i++) {
|
|
48
|
+
out = ALPHABET[Number(n & 31n)] + out;
|
|
49
|
+
n >>= 5n;
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function decode(suffix: string): Uint8Array {
|
|
55
|
+
if (suffix.length !== 26) {
|
|
56
|
+
throw new Error(`invalid typeid suffix '${suffix}': want 26 chars`);
|
|
57
|
+
}
|
|
58
|
+
if (suffix[0]! > '7') {
|
|
59
|
+
throw new Error(`invalid typeid suffix '${suffix}': first char must be 0-7`);
|
|
60
|
+
}
|
|
61
|
+
let n = 0n;
|
|
62
|
+
for (const c of suffix) {
|
|
63
|
+
const v = DECODE[c];
|
|
64
|
+
if (v === undefined) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`invalid typeid suffix '${suffix}': '${c}' is not lowercase Crockford base32`,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
n = (n << 5n) | BigInt(v);
|
|
70
|
+
}
|
|
71
|
+
const bytes = new Uint8Array(16);
|
|
72
|
+
for (let i = 15; i >= 0; i--) {
|
|
73
|
+
bytes[i] = Number(n & 0xffn);
|
|
74
|
+
n >>= 8n;
|
|
75
|
+
}
|
|
76
|
+
return bytes;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function uuidString(bytes: Uint8Array): string {
|
|
80
|
+
const hex = [...bytes].map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
81
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function uuidBytes(uuid: string): Uint8Array {
|
|
85
|
+
const hex = uuid.replace(/-/g, '');
|
|
86
|
+
if (!/^[0-9a-fA-F]{32}$/.test(hex)) {
|
|
87
|
+
throw new Error(`invalid uuid '${uuid}'`);
|
|
88
|
+
}
|
|
89
|
+
const bytes = new Uint8Array(16);
|
|
90
|
+
for (let i = 0; i < 16; i++) bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
91
|
+
return bytes;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// UUIDv7 (RFC 9562): 48-bit Unix-ms timestamp, version 7, variant 10,
|
|
95
|
+
// the remaining 74 bits random.
|
|
96
|
+
function uuidv7(): Uint8Array {
|
|
97
|
+
const bytes = new Uint8Array(16);
|
|
98
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
99
|
+
let ms = BigInt(Date.now());
|
|
100
|
+
for (let i = 5; i >= 0; i--) {
|
|
101
|
+
bytes[i] = Number(ms & 0xffn);
|
|
102
|
+
ms >>= 8n;
|
|
103
|
+
}
|
|
104
|
+
bytes[6] = (bytes[6]! & 0x0f) | 0x70;
|
|
105
|
+
bytes[8] = (bytes[8]! & 0x3f) | 0x80;
|
|
106
|
+
return bytes;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function format(prefix: string, bytes: Uint8Array): string {
|
|
110
|
+
const suffix = encode(bytes);
|
|
111
|
+
return prefix === '' ? suffix : `${prefix}_${suffix}`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Canonical TypeID string for `prefix` and an existing UUID (any
|
|
116
|
+
* version, hyphenated or not).
|
|
117
|
+
*
|
|
118
|
+
* @throws {Error} on an invalid prefix or UUID.
|
|
119
|
+
*/
|
|
120
|
+
export function fromUUID(prefix: string, uuid: string): string {
|
|
121
|
+
checkPrefix(prefix);
|
|
122
|
+
return format(prefix, uuidBytes(uuid));
|
|
123
|
+
}
|
|
124
|
+
|
|
23
125
|
/**
|
|
24
126
|
* Compile-time-typed canonical TypeID string for prefix `P`.
|
|
25
127
|
*
|
|
@@ -47,7 +149,8 @@ export interface Parsed {
|
|
|
47
149
|
* newId('task') // => 'task_01h2e8kqv8000000000000000'
|
|
48
150
|
*/
|
|
49
151
|
export function newId(prefix: string): string {
|
|
50
|
-
|
|
152
|
+
checkPrefix(prefix);
|
|
153
|
+
return format(prefix, uuidv7());
|
|
51
154
|
}
|
|
52
155
|
|
|
53
156
|
/**
|
|
@@ -57,11 +160,14 @@ export function newId(prefix: string): string {
|
|
|
57
160
|
* (e.g. malformed suffix, illegal prefix characters).
|
|
58
161
|
*/
|
|
59
162
|
export function parse(s: string): Parsed {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
163
|
+
const sep = s.lastIndexOf('_');
|
|
164
|
+
const prefix = sep === -1 ? '' : s.slice(0, sep);
|
|
165
|
+
const suffix = sep === -1 ? s : s.slice(sep + 1);
|
|
166
|
+
if (sep !== -1 && prefix === '') {
|
|
167
|
+
throw new Error(`invalid typeid '${s}': empty prefix with a separator`);
|
|
168
|
+
}
|
|
169
|
+
checkPrefix(prefix);
|
|
170
|
+
return { prefix, uuid: uuidString(decode(suffix)) };
|
|
65
171
|
}
|
|
66
172
|
|
|
67
173
|
/**
|
|
@@ -70,7 +176,7 @@ export function parse(s: string): Parsed {
|
|
|
70
176
|
* between e.g. `TaskId` and `InvoiceId`.
|
|
71
177
|
*/
|
|
72
178
|
export function newTyped<P extends string>(prefix: P): Typed<P> {
|
|
73
|
-
return
|
|
179
|
+
return newId(prefix) as Typed<P>;
|
|
74
180
|
}
|
|
75
181
|
|
|
76
182
|
/**
|
|
@@ -82,11 +188,11 @@ export function newTyped<P extends string>(prefix: P): Typed<P> {
|
|
|
82
188
|
* when the input is not a syntactically valid TypeID.
|
|
83
189
|
*/
|
|
84
190
|
export function parseTyped<P extends string>(prefix: P, s: string): Typed<P> {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return
|
|
191
|
+
const parsed = parse(s);
|
|
192
|
+
if (parsed.prefix !== prefix) {
|
|
193
|
+
throw new Error(`typeid '${s}' has prefix '${parsed.prefix}', want '${prefix}'`);
|
|
194
|
+
}
|
|
195
|
+
return s as Typed<P>;
|
|
90
196
|
}
|
|
91
197
|
|
|
92
198
|
// Crockford base32 alphabet used by the TypeID spec (lowercase),
|
package/src/index.test.ts
CHANGED
|
@@ -53,11 +53,51 @@ describe('exports map contract', () => {
|
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
+
describe('documented subpaths', () => {
|
|
57
|
+
const docs = ['README.md', '../../docs/adopters/reference/ts-api-reference.md'];
|
|
58
|
+
|
|
59
|
+
it.each(docs)('%s names only subpaths the exports map declares', (doc) => {
|
|
60
|
+
const text = readFileSync(join(pkgDir, doc), 'utf8');
|
|
61
|
+
const named = new Set(
|
|
62
|
+
[...text.matchAll(/@hop-top\/kit\/([a-z][a-z0-9/-]*[a-z0-9])/g)]
|
|
63
|
+
// `upgrade/drivers/{a,b}` is brace shorthand, not a subpath.
|
|
64
|
+
.filter((m) => !text.startsWith('/{', m.index + m[0].length))
|
|
65
|
+
.map((m) => `./${m[1]}`),
|
|
66
|
+
);
|
|
67
|
+
expect(named.size).toBeGreaterThan(0);
|
|
68
|
+
for (const sub of named) {
|
|
69
|
+
expect(pkg.exports, `${doc}: ${sub}`).toHaveProperty([sub]);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Adopter-facing modules (README, API reference, capability parity page).
|
|
74
|
+
it.each(['uri', 'wizard', 'bus'])('%s is importable as a subpath', (name) => {
|
|
75
|
+
expect(pkg.exports).toHaveProperty([`./${name}`]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Documented as internal: router would load hono from the root import; triton is only router's transport.
|
|
79
|
+
it.each(['router', 'triton'])('%s is intentionally not exported', (name) => {
|
|
80
|
+
expect(pkg.exports).not.toHaveProperty([`./${name}`]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it.each(docs)('%s never presents router or triton as importable', (doc) => {
|
|
84
|
+
const text = readFileSync(join(pkgDir, doc), 'utf8');
|
|
85
|
+
expect(text).not.toMatch(/@hop-top\/kit\/(router|triton)\b/);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Plumbing behind the cli factory: its public names are re-exported from `./cli`.
|
|
89
|
+
it.each(['delegation', 'sideeffect', 'policy'])('%s stays internal (reached through ./cli)', (name) => {
|
|
90
|
+
expect(pkg.exports).not.toHaveProperty([`./${name}`]);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
56
94
|
describe('root barrel', () => {
|
|
57
|
-
it('re-exports every public subpath except sqlstore as a namespace', () => {
|
|
95
|
+
it('re-exports every public subpath except sqlstore and the upgrade drivers as a namespace', () => {
|
|
58
96
|
// Kebab-case subpaths become camelCase namespaces (completion-values -> completionValues).
|
|
59
97
|
const expected = Object.keys(pkg.exports)
|
|
60
|
-
|
|
98
|
+
// Driver subpaths (`upgrade/drivers/<name>`) are opt-in entries (a caller-provided
|
|
99
|
+
// client, or a native or heavy module); they are nested, so they have no namespace.
|
|
100
|
+
.filter((p) => p !== '.' && p !== './sqlstore' && !p.startsWith('./upgrade/drivers/'))
|
|
61
101
|
.map((p) => p.replace(/^\.\//, '').replace(/-([a-z])/g, (_, c: string) => c.toUpperCase()));
|
|
62
102
|
for (const name of expected) {
|
|
63
103
|
expect(kit, name).toHaveProperty(name);
|
|
@@ -68,4 +108,10 @@ describe('root barrel', () => {
|
|
|
68
108
|
it('does not eagerly expose sqlstore (native deps stay behind the subpath)', () => {
|
|
69
109
|
expect(kit).not.toHaveProperty('sqlstore');
|
|
70
110
|
});
|
|
111
|
+
|
|
112
|
+
it('does not expose the upgrade drivers (better-sqlite3 and tar stay behind their subpaths)', () => {
|
|
113
|
+
expect(kit.upgrade).not.toHaveProperty('SqliteDriver');
|
|
114
|
+
expect(kit.upgrade).not.toHaveProperty('FsDirDriver');
|
|
115
|
+
expect(kit.upgrade).not.toHaveProperty('ConfigFileDriver');
|
|
116
|
+
});
|
|
71
117
|
});
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* `sqlstore` is intentionally NOT re-exported here: an eager re-export
|
|
12
12
|
* would load better-sqlite3 native bindings on every bare import of the
|
|
13
13
|
* package. Use the dedicated subpath instead: `@hop-top/kit/sqlstore`.
|
|
14
|
+
* The upgrade drivers (`@hop-top/kit/upgrade/drivers/{configfile,fsdir,sqlite}`)
|
|
15
|
+
* stay out for the same reason: `sqlite` loads better-sqlite3, `fsdir` loads `tar`.
|
|
14
16
|
*/
|
|
15
17
|
|
|
16
18
|
export * as aim from './aim.js';
|
|
@@ -18,6 +20,7 @@ export * as alias from './alias.js';
|
|
|
18
20
|
export * as anthropic from './llm-anthropic.js';
|
|
19
21
|
export * as api from './api.js';
|
|
20
22
|
export * as auth from './auth.js';
|
|
23
|
+
export * as bus from './bus.js';
|
|
21
24
|
export * as cli from './cli.js';
|
|
22
25
|
export * as completion from './completion.js';
|
|
23
26
|
export * as completionValues from './completion-values.js';
|
|
@@ -42,5 +45,7 @@ export * as stream from './stream.js';
|
|
|
42
45
|
export * as telemetry from './telemetry/index.js';
|
|
43
46
|
export * as toolspec from './toolspec.js';
|
|
44
47
|
export * as tui from './tui/index.js';
|
|
45
|
-
export * as upgrade from './upgrade.js';
|
|
48
|
+
export * as upgrade from './upgrade/index.js';
|
|
49
|
+
export * as uri from './uri.js';
|
|
50
|
+
export * as wizard from './wizard.js';
|
|
46
51
|
export * as xdg from './xdg.js';
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
17
17
|
import { execFileSync } from 'node:child_process';
|
|
18
|
+
import { createRequire } from 'node:module';
|
|
18
19
|
import { copyFileSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
19
20
|
import * as path from 'node:path';
|
|
20
21
|
import * as ts from 'typescript';
|
|
@@ -109,6 +110,13 @@ describe('published declarations', () => {
|
|
|
109
110
|
|
|
110
111
|
afterAll(() => { rmSync(stageDir, { recursive: true, force: true }); });
|
|
111
112
|
|
|
113
|
+
// Runtime resolution through the package `exports` map, outside any test alias.
|
|
114
|
+
it.each(Object.keys(pkg.exports))('%s resolves and loads from the built package', (key) => {
|
|
115
|
+
const req = createRequire(files[1]);
|
|
116
|
+
const spec = key === '.' ? pkg.name : `${pkg.name}/${key.slice(2)}`;
|
|
117
|
+
expect(typeof req(spec)).toBe('object');
|
|
118
|
+
});
|
|
119
|
+
|
|
112
120
|
it.each(Object.entries(modes).map(([name, m]) => [name, m.skipLibCheck] as const))(
|
|
113
121
|
'type-check clean (moduleResolution %s, skipLibCheck %s)', (mode) => {
|
|
114
122
|
const program = ts.createProgram(files, {
|