@hop-top/kit 0.5.0-alpha.11 → 0.5.0-alpha.12
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 +18 -0
- package/dist/chunk-P3Y46PYF.js +138 -0
- package/dist/{chunk-4GPCWBBA.js → chunk-X4E5QGEB.js} +48 -20
- package/dist/id/index.d.ts +1 -1
- package/dist/id/index.js +4 -2
- package/dist/{index-VLDcI5NF.d.ts → index-D9zpUrpE.d.ts} +18 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/{upgrade-C3RWGwRi.d.ts → upgrade-BJ2z6Oqf.d.ts} +35 -4
- package/dist/upgrade.d.ts +1 -1
- package/dist/upgrade.js +4 -2
- package/package.json +9 -9
- 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/upgrade.test.ts +102 -1
- package/src/upgrade.ts +76 -27
- package/dist/chunk-L23O2FFE.js +0 -51
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,24 @@ All notable changes to `@hop-top/kit` are documented in this file.
|
|
|
4
4
|
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/);
|
|
5
5
|
versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.5.0-alpha.12](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.11...kit-ts/v0.5.0-alpha.12) (2026-11-15)
|
|
8
|
+
|
|
9
|
+
The hop-top team is happy to announce Kit's TS SDK 0.5.0-alpha.12. This release includes new features and bug fixes.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* **py/upgrade:** result-returning check() ([b212133](https://github.com/hop-top/poly-kit/commit/b212133e1e072b95efe93404e979052abdef2bb8))
|
|
15
|
+
* **ts/upgrade:** result-returning check() ([855da06](https://github.com/hop-top/poly-kit/commit/855da064273c089f49207156f42fdc58a272bd71))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **deps:** hono 4.13.16 in sdk/ts ([7c20fb7](https://github.com/hop-top/poly-kit/commit/7c20fb7b5d9dda0ff949b05bac2460cf33991fe9))
|
|
21
|
+
* **ts:** ship a self-contained TypeID, drop the typeid-js runtime dep ([c5aa133](https://github.com/hop-top/poly-kit/commit/c5aa133e826330d47b29e2b46e51c9e07ad4fa7a))
|
|
22
|
+
|
|
23
|
+
Full diff: [kit-ts/v0.5.0-alpha.11...kit-ts/v0.5.0-alpha.12](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.11...kit-ts/v0.5.0-alpha.12)
|
|
24
|
+
|
|
7
25
|
## [0.5.0-alpha.11](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.10...kit-ts/v0.5.0-alpha.11) (2026-11-04)
|
|
8
26
|
|
|
9
27
|
The hop-top team is happy to announce Kit's TS SDK 0.5.0-alpha.11. This release includes new features and bug fixes.
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|
|
4
|
+
|
|
5
|
+
// src/id/index.ts
|
|
6
|
+
var id_exports = {};
|
|
7
|
+
_chunkR5U7XKVJjs.__export.call(void 0, id_exports, {
|
|
8
|
+
fromUUID: () => fromUUID,
|
|
9
|
+
newId: () => newId,
|
|
10
|
+
newTyped: () => newTyped,
|
|
11
|
+
parse: () => parse,
|
|
12
|
+
parseTyped: () => parseTyped,
|
|
13
|
+
typeIdSchema: () => typeIdSchema
|
|
14
|
+
});
|
|
15
|
+
var _zod = require('zod');
|
|
16
|
+
var ALPHABET = "0123456789abcdefghjkmnpqrstvwxyz";
|
|
17
|
+
var DECODE = Object.fromEntries(
|
|
18
|
+
[...ALPHABET].map((c, i) => [c, i])
|
|
19
|
+
);
|
|
20
|
+
var PREFIX_RE = /^(?:[a-z](?:[a-z_]{0,61}[a-z])?)?$/;
|
|
21
|
+
function checkPrefix(prefix) {
|
|
22
|
+
if (!PREFIX_RE.test(prefix)) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`invalid typeid prefix '${prefix}': want up to 63 chars of [a-z_], starting and ending with a letter`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function encode(bytes) {
|
|
29
|
+
let n = 0n;
|
|
30
|
+
for (const b of bytes) n = n << 8n | BigInt(b);
|
|
31
|
+
let out = "";
|
|
32
|
+
for (let i = 0; i < 26; i++) {
|
|
33
|
+
out = ALPHABET[Number(n & 31n)] + out;
|
|
34
|
+
n >>= 5n;
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
function decode(suffix) {
|
|
39
|
+
if (suffix.length !== 26) {
|
|
40
|
+
throw new Error(`invalid typeid suffix '${suffix}': want 26 chars`);
|
|
41
|
+
}
|
|
42
|
+
if (suffix[0] > "7") {
|
|
43
|
+
throw new Error(`invalid typeid suffix '${suffix}': first char must be 0-7`);
|
|
44
|
+
}
|
|
45
|
+
let n = 0n;
|
|
46
|
+
for (const c of suffix) {
|
|
47
|
+
const v = DECODE[c];
|
|
48
|
+
if (v === void 0) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`invalid typeid suffix '${suffix}': '${c}' is not lowercase Crockford base32`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
n = n << 5n | BigInt(v);
|
|
54
|
+
}
|
|
55
|
+
const bytes = new Uint8Array(16);
|
|
56
|
+
for (let i = 15; i >= 0; i--) {
|
|
57
|
+
bytes[i] = Number(n & 0xffn);
|
|
58
|
+
n >>= 8n;
|
|
59
|
+
}
|
|
60
|
+
return bytes;
|
|
61
|
+
}
|
|
62
|
+
function uuidString(bytes) {
|
|
63
|
+
const hex = [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
64
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
65
|
+
}
|
|
66
|
+
function uuidBytes(uuid) {
|
|
67
|
+
const hex = uuid.replace(/-/g, "");
|
|
68
|
+
if (!/^[0-9a-fA-F]{32}$/.test(hex)) {
|
|
69
|
+
throw new Error(`invalid uuid '${uuid}'`);
|
|
70
|
+
}
|
|
71
|
+
const bytes = new Uint8Array(16);
|
|
72
|
+
for (let i = 0; i < 16; i++) bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
73
|
+
return bytes;
|
|
74
|
+
}
|
|
75
|
+
function uuidv7() {
|
|
76
|
+
const bytes = new Uint8Array(16);
|
|
77
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
78
|
+
let ms = BigInt(Date.now());
|
|
79
|
+
for (let i = 5; i >= 0; i--) {
|
|
80
|
+
bytes[i] = Number(ms & 0xffn);
|
|
81
|
+
ms >>= 8n;
|
|
82
|
+
}
|
|
83
|
+
bytes[6] = bytes[6] & 15 | 112;
|
|
84
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
85
|
+
return bytes;
|
|
86
|
+
}
|
|
87
|
+
function format(prefix, bytes) {
|
|
88
|
+
const suffix = encode(bytes);
|
|
89
|
+
return prefix === "" ? suffix : `${prefix}_${suffix}`;
|
|
90
|
+
}
|
|
91
|
+
function fromUUID(prefix, uuid) {
|
|
92
|
+
checkPrefix(prefix);
|
|
93
|
+
return format(prefix, uuidBytes(uuid));
|
|
94
|
+
}
|
|
95
|
+
function newId(prefix) {
|
|
96
|
+
checkPrefix(prefix);
|
|
97
|
+
return format(prefix, uuidv7());
|
|
98
|
+
}
|
|
99
|
+
function parse(s) {
|
|
100
|
+
const sep = s.lastIndexOf("_");
|
|
101
|
+
const prefix = sep === -1 ? "" : s.slice(0, sep);
|
|
102
|
+
const suffix = sep === -1 ? s : s.slice(sep + 1);
|
|
103
|
+
if (sep !== -1 && prefix === "") {
|
|
104
|
+
throw new Error(`invalid typeid '${s}': empty prefix with a separator`);
|
|
105
|
+
}
|
|
106
|
+
checkPrefix(prefix);
|
|
107
|
+
return { prefix, uuid: uuidString(decode(suffix)) };
|
|
108
|
+
}
|
|
109
|
+
function newTyped(prefix) {
|
|
110
|
+
return newId(prefix);
|
|
111
|
+
}
|
|
112
|
+
function parseTyped(prefix, s) {
|
|
113
|
+
const parsed = parse(s);
|
|
114
|
+
if (parsed.prefix !== prefix) {
|
|
115
|
+
throw new Error(`typeid '${s}' has prefix '${parsed.prefix}', want '${prefix}'`);
|
|
116
|
+
}
|
|
117
|
+
return s;
|
|
118
|
+
}
|
|
119
|
+
var SUFFIX_RE = /^[0-7][0-9a-hjkmnp-tv-z]{25}$/;
|
|
120
|
+
function typeIdSchema(prefix) {
|
|
121
|
+
const pattern = new RegExp(
|
|
122
|
+
`^${escapeRegExp(prefix)}_${SUFFIX_RE.source.slice(1, -1)}$`
|
|
123
|
+
);
|
|
124
|
+
return _zod.z.string().regex(pattern, `invalid typeid for prefix '${prefix}'`);
|
|
125
|
+
}
|
|
126
|
+
function escapeRegExp(s) {
|
|
127
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
exports.fromUUID = fromUUID; exports.newId = newId; exports.parse = parse; exports.newTyped = newTyped; exports.parseTyped = parseTyped; exports.typeIdSchema = typeIdSchema; exports.id_exports = id_exports;
|
|
@@ -5,12 +5,19 @@ var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|
|
|
5
5
|
// src/upgrade.ts
|
|
6
6
|
var upgrade_exports = {};
|
|
7
7
|
_chunkR5U7XKVJjs.__export.call(void 0, upgrade_exports, {
|
|
8
|
+
UpgradeCheckError: () => UpgradeCheckError,
|
|
8
9
|
createChecker: () => createChecker
|
|
9
10
|
});
|
|
10
11
|
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
11
12
|
var _os = require('os'); var os = _interopRequireWildcard(_os);
|
|
12
13
|
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
13
14
|
var _semver = require('semver'); var _semver2 = _interopRequireDefault(_semver);
|
|
15
|
+
var UpgradeCheckError = class extends Error {
|
|
16
|
+
constructor(message, options) {
|
|
17
|
+
super(message, options);
|
|
18
|
+
this.name = "UpgradeCheckError";
|
|
19
|
+
}
|
|
20
|
+
};
|
|
14
21
|
var PAGE_SIZE = 100;
|
|
15
22
|
var MAX_PAGES = 3;
|
|
16
23
|
function createChecker(opts) {
|
|
@@ -70,10 +77,10 @@ function createChecker(opts) {
|
|
|
70
77
|
signal: controller.signal,
|
|
71
78
|
headers: { Accept: "application/vnd.github+json" }
|
|
72
79
|
});
|
|
73
|
-
if (!res.ok)
|
|
80
|
+
if (!res.ok) throw new UpgradeCheckError(`release lookup failed: HTTP ${res.status}`);
|
|
74
81
|
const body = await res.json();
|
|
75
82
|
const tag = body.tag_name;
|
|
76
|
-
if (typeof tag !== "string")
|
|
83
|
+
if (typeof tag !== "string") throw new UpgradeCheckError("release lookup failed: no tag_name");
|
|
77
84
|
return { version: tag.replace(/^v/, "") };
|
|
78
85
|
} finally {
|
|
79
86
|
clearTimeout(timer);
|
|
@@ -87,11 +94,14 @@ function createChecker(opts) {
|
|
|
87
94
|
headers: { Accept: "application/vnd.github+json" }
|
|
88
95
|
});
|
|
89
96
|
if (!res.ok) {
|
|
90
|
-
if (page === 1)
|
|
97
|
+
if (page === 1) throw new UpgradeCheckError(`release lookup failed: HTTP ${res.status}`);
|
|
91
98
|
break;
|
|
92
99
|
}
|
|
93
100
|
const body = await res.json();
|
|
94
|
-
if (!Array.isArray(body))
|
|
101
|
+
if (!Array.isArray(body)) {
|
|
102
|
+
if (page === 1) throw new UpgradeCheckError("release lookup failed: unexpected response");
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
95
105
|
for (const rel of body) {
|
|
96
106
|
if (rel === null || typeof rel !== "object") continue;
|
|
97
107
|
if (rel.draft === true || typeof rel.tag_name !== "string") continue;
|
|
@@ -106,11 +116,12 @@ function createChecker(opts) {
|
|
|
106
116
|
}
|
|
107
117
|
if (body.length < PAGE_SIZE) break;
|
|
108
118
|
}
|
|
119
|
+
if (best === null) throw new UpgradeCheckError("no matching release found");
|
|
109
120
|
return best;
|
|
110
121
|
}
|
|
111
|
-
async function
|
|
122
|
+
async function check() {
|
|
112
123
|
try {
|
|
113
|
-
let latestVersion
|
|
124
|
+
let latestVersion;
|
|
114
125
|
let latestTag;
|
|
115
126
|
const cached = readCache();
|
|
116
127
|
if (cached !== null && Date.now() - cached.checkedAt < cacheTTL) {
|
|
@@ -118,26 +129,43 @@ function createChecker(opts) {
|
|
|
118
129
|
latestTag = cached.tag;
|
|
119
130
|
} else {
|
|
120
131
|
const latest = await fetchLatestVersion();
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
writeCache(latest.version, latest.tag);
|
|
125
|
-
}
|
|
132
|
+
latestVersion = latest.version;
|
|
133
|
+
latestTag = latest.tag;
|
|
134
|
+
writeCache(latest.version, latest.tag);
|
|
126
135
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
136
|
+
return {
|
|
137
|
+
current: currentVersion,
|
|
138
|
+
latest: latestVersion,
|
|
139
|
+
// Only strictly greater counts as an update.
|
|
140
|
+
updateAvailable: _semver2.default.gt(latestVersion, currentVersion),
|
|
141
|
+
url: noticeURL(latestTag)
|
|
142
|
+
};
|
|
143
|
+
} catch (err) {
|
|
144
|
+
if (err instanceof UpgradeCheckError) throw err;
|
|
145
|
+
throw new UpgradeCheckError(
|
|
146
|
+
`upgrade check failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
147
|
+
{ cause: err }
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function notifyIfAvailable(out) {
|
|
152
|
+
try {
|
|
153
|
+
const r = await check();
|
|
154
|
+
if (!r.updateAvailable) return;
|
|
155
|
+
out.write(
|
|
156
|
+
`
|
|
157
|
+
A new release of ${name} is available: v${r.current} \u2192 v${r.latest}
|
|
158
|
+
${r.url}
|
|
159
|
+
`
|
|
160
|
+
);
|
|
134
161
|
} catch (e3) {
|
|
135
162
|
}
|
|
136
163
|
}
|
|
137
|
-
return { notifyIfAvailable };
|
|
164
|
+
return { check, notifyIfAvailable };
|
|
138
165
|
}
|
|
139
166
|
|
|
140
167
|
|
|
141
168
|
|
|
142
169
|
|
|
143
|
-
|
|
170
|
+
|
|
171
|
+
exports.UpgradeCheckError = UpgradeCheckError; exports.createChecker = createChecker; exports.upgrade_exports = upgrade_exports;
|
package/dist/id/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import 'zod';
|
|
2
|
-
export { P as Parsed, T as Typed, n as newId, a as newTyped, p as parse, b as parseTyped, t as typeIdSchema } from '../index-
|
|
2
|
+
export { P as Parsed, T as Typed, f as fromUUID, n as newId, a as newTyped, p as parse, b as parseTyped, t as typeIdSchema } from '../index-D9zpUrpE.js';
|
package/dist/id/index.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
var _chunkP3Y46PYFjs = require('../chunk-P3Y46PYF.js');
|
|
8
9
|
require('../chunk-R5U7XKVJ.js');
|
|
9
10
|
|
|
10
11
|
|
|
@@ -12,4 +13,5 @@ require('../chunk-R5U7XKVJ.js');
|
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
|
|
17
|
+
exports.fromUUID = _chunkP3Y46PYFjs.fromUUID; exports.newId = _chunkP3Y46PYFjs.newId; exports.newTyped = _chunkP3Y46PYFjs.newTyped; exports.parse = _chunkP3Y46PYFjs.parse; exports.parseTyped = _chunkP3Y46PYFjs.parseTyped; exports.typeIdSchema = _chunkP3Y46PYFjs.typeIdSchema;
|
|
@@ -4,14 +4,18 @@ import { z } from 'zod';
|
|
|
4
4
|
* @module id
|
|
5
5
|
* @package @hop-top/kit
|
|
6
6
|
*
|
|
7
|
-
* TypeID primitive
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* TypeID primitive implementing the cross-language kit API SHAPE per
|
|
8
|
+
* docs/announcements/2026-05-typeid-primitive.md, on the jetify TypeID
|
|
9
|
+
* spec v0.3. Self-contained: no runtime dependency, so no transitive
|
|
10
|
+
* uuid release reaches adopters (typeid-js 1.2.0 pins uuid ^10, under
|
|
11
|
+
* an open advisory). contracts/typeid-v1/fixtures.json and a
|
|
12
|
+
* differential test against typeid-js (dev only) keep it on the wire
|
|
13
|
+
* format.
|
|
10
14
|
*
|
|
11
15
|
* Canonical wire form: `<prefix>_<26-char-base32>` where the suffix is
|
|
12
16
|
* a Crockford-base32-encoded UUIDv7. The TS surface adds a
|
|
13
17
|
* template-literal `Typed<P>` for compile-time prefix safety on top of
|
|
14
|
-
* the runtime
|
|
18
|
+
* the runtime checks in {@link parse}.
|
|
15
19
|
*
|
|
16
20
|
* URI composition (e.g. `tlc://task/task_…`) is NOT in this module —
|
|
17
21
|
* callers should use the `@hop-top/cite` package directly. This
|
|
@@ -19,6 +23,13 @@ import { z } from 'zod';
|
|
|
19
23
|
* registry.
|
|
20
24
|
*/
|
|
21
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Canonical TypeID string for `prefix` and an existing UUID (any
|
|
28
|
+
* version, hyphenated or not).
|
|
29
|
+
*
|
|
30
|
+
* @throws {Error} on an invalid prefix or UUID.
|
|
31
|
+
*/
|
|
32
|
+
declare function fromUUID(prefix: string, uuid: string): string;
|
|
22
33
|
/**
|
|
23
34
|
* Compile-time-typed canonical TypeID string for prefix `P`.
|
|
24
35
|
*
|
|
@@ -83,13 +94,14 @@ declare function typeIdSchema(prefix: string): z.ZodString;
|
|
|
83
94
|
|
|
84
95
|
type index_Parsed = Parsed;
|
|
85
96
|
type index_Typed<P extends string> = Typed<P>;
|
|
97
|
+
declare const index_fromUUID: typeof fromUUID;
|
|
86
98
|
declare const index_newId: typeof newId;
|
|
87
99
|
declare const index_newTyped: typeof newTyped;
|
|
88
100
|
declare const index_parse: typeof parse;
|
|
89
101
|
declare const index_parseTyped: typeof parseTyped;
|
|
90
102
|
declare const index_typeIdSchema: typeof typeIdSchema;
|
|
91
103
|
declare namespace index {
|
|
92
|
-
export { type index_Parsed as Parsed, type index_Typed as Typed, index_newId as newId, index_newTyped as newTyped, index_parse as parse, index_parseTyped as parseTyped, index_typeIdSchema as typeIdSchema };
|
|
104
|
+
export { type index_Parsed as Parsed, type index_Typed as Typed, index_fromUUID as fromUUID, index_newId as newId, index_newTyped as newTyped, index_parse as parse, index_parseTyped as parseTyped, index_typeIdSchema as typeIdSchema };
|
|
93
105
|
}
|
|
94
106
|
|
|
95
|
-
export { type Parsed as P, type Typed as T, newTyped as a, parseTyped as b, index as i, newId as n, parse as p, typeIdSchema as t };
|
|
107
|
+
export { type Parsed as P, type Typed as T, newTyped as a, parseTyped as b, fromUUID as f, index as i, newId as n, parse as p, typeIdSchema as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { c as completionValues } from './completion-values-By-mnjNt.js';
|
|
|
9
9
|
export { c as compliance } from './compliance-AxFf-uMy.js';
|
|
10
10
|
export { c as config } from './config-CaK60ByQ.js';
|
|
11
11
|
export { e as errcorrect } from './errcorrect-BcX1Ft0K.js';
|
|
12
|
-
export { i as id } from './index-
|
|
12
|
+
export { i as id } from './index-D9zpUrpE.js';
|
|
13
13
|
export { l as llm } from './llm-DYuR7_uX.js';
|
|
14
14
|
export { l as log } from './log-CkaxMX3U.js';
|
|
15
15
|
export { i as mcp } from './index-BKJZClJx.js';
|
|
@@ -27,7 +27,7 @@ export { s as stream } from './stream-CrjeCp0M.js';
|
|
|
27
27
|
export { i as telemetry } from './index-C3Zw4wDJ.js';
|
|
28
28
|
export { t as toolspec } from './toolspec-DcPwwoAZ.js';
|
|
29
29
|
export { i as tui } from './index-CGE5yLBj.js';
|
|
30
|
-
export { u as upgrade } from './upgrade-
|
|
30
|
+
export { u as upgrade } from './upgrade-BJ2z6Oqf.js';
|
|
31
31
|
export { x as xdg } from './xdg-DB7Shoib.js';
|
|
32
32
|
import 'commander';
|
|
33
33
|
import './parity-CvMuYcVI.js';
|
package/dist/index.js
CHANGED
|
@@ -9,10 +9,10 @@ var _chunkBRNEKPWXjs = require('./chunk-BRNEKPWX.js');
|
|
|
9
9
|
var _chunkEE4M2UOFjs = require('./chunk-EE4M2UOF.js');
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkX4E5QGEBjs = require('./chunk-X4E5QGEB.js');
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkP3Y46PYFjs = require('./chunk-P3Y46PYF.js');
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
var _chunkIVQHLI56js = require('./chunk-IVQHLI56.js');
|
|
@@ -129,4 +129,4 @@ require('./chunk-R5U7XKVJ.js');
|
|
|
129
129
|
|
|
130
130
|
|
|
131
131
|
|
|
132
|
-
exports.aim = _chunkQJVSKKRQjs.aim_exports; exports.alias = _chunkML7D5DWYjs.alias_exports; exports.anthropic = _chunk4FMALWYBjs.llm_anthropic_exports; exports.api = _chunkCSJWB6D3js.api_exports; exports.auth = _chunkUKZIAQA7js.auth_exports; exports.cli = _chunkMFVUENZRjs.cli_exports; exports.completion = _chunk65VPWMPVjs.completion_exports; exports.completionValues = _chunkJKMQSAJPjs.completion_values_exports; exports.compliance = _chunkXJTRY453js.compliance_exports; exports.config = _chunkQQQYCWSCjs.config_exports; exports.errcorrect = _chunk3FIKGFKIjs.errcorrect_exports; exports.id =
|
|
132
|
+
exports.aim = _chunkQJVSKKRQjs.aim_exports; exports.alias = _chunkML7D5DWYjs.alias_exports; exports.anthropic = _chunk4FMALWYBjs.llm_anthropic_exports; exports.api = _chunkCSJWB6D3js.api_exports; exports.auth = _chunkUKZIAQA7js.auth_exports; exports.cli = _chunkMFVUENZRjs.cli_exports; exports.completion = _chunk65VPWMPVjs.completion_exports; exports.completionValues = _chunkJKMQSAJPjs.completion_values_exports; exports.compliance = _chunkXJTRY453js.compliance_exports; exports.config = _chunkQQQYCWSCjs.config_exports; exports.errcorrect = _chunk3FIKGFKIjs.errcorrect_exports; exports.id = _chunkP3Y46PYFjs.id_exports; exports.llm = _chunkK7E34Q3Ajs.llm_exports; exports.log = _chunkIZ6Q4SE3js.log_exports; exports.mcp = _chunkIVQHLI56js.mcp_exports; exports.netpolicy = _chunkKVG7YCTSjs.netpolicy_exports; exports.openai = _chunkVWGP4NVJjs.llm_openai_exports; exports.output = _chunkGFRAYYRDjs.output_exports; exports.progress = _chunkBDNNPRX6js.progress_exports; exports.provenance = _chunk6SVOHNICjs.provenance_exports; exports.routellm = _chunkVGOA5Y7Sjs.routellm_exports; exports.rpc = _chunkWUOAQVOAjs.rpc_exports; exports.safety = _chunk6HFAEZ52js.safety_exports; exports.scope = _chunkWBVO43HUjs.scope_exports; exports.serve = _chunkMQXYDYRDjs.serve_exports; exports.stream = _chunkBRNEKPWXjs.stream_exports; exports.telemetry = _chunkYOBAUCVNjs.telemetry_exports; exports.toolspec = _chunkEE4M2UOFjs.toolspec_exports; exports.tui = _chunkRYKLVOVKjs.tui_exports; exports.upgrade = _chunkX4E5QGEBjs.upgrade_exports; exports.xdg = _chunk4UE5TCMQjs.xdg_exports;
|
|
@@ -17,8 +17,10 @@
|
|
|
17
17
|
* ### Error handling philosophy
|
|
18
18
|
* Version checking is a best-effort, non-critical operation. Any failure —
|
|
19
19
|
* network error, bad JSON, HTTP error, filesystem error, invalid semver — is
|
|
20
|
-
* silently discarded
|
|
21
|
-
*
|
|
20
|
+
* silently discarded by `notifyIfAvailable`, which always resolves without
|
|
21
|
+
* throwing. `check()` is the strict variant: it rejects with an
|
|
22
|
+
* {@link UpgradeCheckError} so callers (e.g. `upgrade --check`) can tell a
|
|
23
|
+
* failed lookup from "up to date".
|
|
22
24
|
*
|
|
23
25
|
* ### Notice format
|
|
24
26
|
* ```
|
|
@@ -91,11 +93,37 @@ interface CheckerOptions {
|
|
|
91
93
|
*/
|
|
92
94
|
includePrereleases?: boolean;
|
|
93
95
|
}
|
|
96
|
+
/** Outcome of {@link Checker.check}. */
|
|
97
|
+
interface UpgradeCheckResult {
|
|
98
|
+
/** Running version, as configured. */
|
|
99
|
+
current: string;
|
|
100
|
+
/** Latest release version (no leading `v` / tag prefix). */
|
|
101
|
+
latest: string;
|
|
102
|
+
/** True when `latest` is strictly greater than `current`. */
|
|
103
|
+
updateAvailable: boolean;
|
|
104
|
+
/** Release page to link to. */
|
|
105
|
+
url: string;
|
|
106
|
+
}
|
|
107
|
+
/** Rejection of {@link Checker.check}; the underlying error is in `cause`. */
|
|
108
|
+
declare class UpgradeCheckError extends Error {
|
|
109
|
+
constructor(message: string, options?: {
|
|
110
|
+
cause?: unknown;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
94
113
|
/**
|
|
95
114
|
* Returned by {@link createChecker}. Call {@link Checker.notifyIfAvailable}
|
|
96
115
|
* at the end of a CLI command to surface upgrade notices non-intrusively.
|
|
97
116
|
*/
|
|
98
117
|
interface Checker {
|
|
118
|
+
/**
|
|
119
|
+
* Looks up the latest release and resolves with the outcome. Unlike
|
|
120
|
+
* {@link Checker.notifyIfAvailable} it never swallows failures: network,
|
|
121
|
+
* HTTP, parse and "no matching release" errors reject with an
|
|
122
|
+
* {@link UpgradeCheckError}, so callers can tell a failed lookup from
|
|
123
|
+
* "up to date". Honours `tagPrefix`, `includePrereleases` and the cache;
|
|
124
|
+
* pass `cacheTTL: 0` to bypass the cache.
|
|
125
|
+
*/
|
|
126
|
+
check(): Promise<UpgradeCheckResult>;
|
|
99
127
|
/**
|
|
100
128
|
* Checks for a newer GitHub release and writes a one-line notice to `out`
|
|
101
129
|
* if one is available. Silently swallows all errors.
|
|
@@ -117,9 +145,12 @@ declare function createChecker(opts: CheckerOptions): Checker;
|
|
|
117
145
|
|
|
118
146
|
type upgrade_Checker = Checker;
|
|
119
147
|
type upgrade_CheckerOptions = CheckerOptions;
|
|
148
|
+
type upgrade_UpgradeCheckError = UpgradeCheckError;
|
|
149
|
+
declare const upgrade_UpgradeCheckError: typeof UpgradeCheckError;
|
|
150
|
+
type upgrade_UpgradeCheckResult = UpgradeCheckResult;
|
|
120
151
|
declare const upgrade_createChecker: typeof createChecker;
|
|
121
152
|
declare namespace upgrade {
|
|
122
|
-
export { type upgrade_Checker as Checker, type upgrade_CheckerOptions as CheckerOptions, upgrade_createChecker as createChecker };
|
|
153
|
+
export { type upgrade_Checker as Checker, type upgrade_CheckerOptions as CheckerOptions, upgrade_UpgradeCheckError as UpgradeCheckError, type upgrade_UpgradeCheckResult as UpgradeCheckResult, upgrade_createChecker as createChecker };
|
|
123
154
|
}
|
|
124
155
|
|
|
125
|
-
export { type Checker as C, type CheckerOptions as a, createChecker as c, upgrade as u };
|
|
156
|
+
export { type Checker as C, UpgradeCheckError as U, type CheckerOptions as a, type UpgradeCheckResult as b, createChecker as c, upgrade as u };
|
package/dist/upgrade.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { C as Checker, a as CheckerOptions, c as createChecker } from './upgrade-
|
|
1
|
+
export { C as Checker, a as CheckerOptions, U as UpgradeCheckError, b as UpgradeCheckResult, c as createChecker } from './upgrade-BJ2z6Oqf.js';
|
package/dist/upgrade.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
var _chunkX4E5QGEBjs = require('./chunk-X4E5QGEB.js');
|
|
4
5
|
require('./chunk-R5U7XKVJ.js');
|
|
5
6
|
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
exports.UpgradeCheckError = _chunkX4E5QGEBjs.UpgradeCheckError; exports.createChecker = _chunkX4E5QGEBjs.createChecker;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hop-top/kit",
|
|
3
|
-
"version": "0.5.0-alpha.
|
|
3
|
+
"version": "0.5.0-alpha.12",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/hop-top/poly-kit.git",
|
|
@@ -291,18 +291,17 @@
|
|
|
291
291
|
"@connectrpc/connect": "^2.2.0",
|
|
292
292
|
"@connectrpc/connect-web": "^2.2.0",
|
|
293
293
|
"@hop-top/cite": "^0.1.2",
|
|
294
|
-
"@modelcontextprotocol/core": "2.
|
|
295
|
-
"@modelcontextprotocol/server": "2.
|
|
294
|
+
"@modelcontextprotocol/core": "2.4.0",
|
|
295
|
+
"@modelcontextprotocol/server": "2.4.0",
|
|
296
296
|
"better-sqlite3": "^12.11.1",
|
|
297
297
|
"commander": "15.0.0",
|
|
298
298
|
"csv-stringify": "^6.9.0",
|
|
299
299
|
"eta": "^4.6.0",
|
|
300
|
-
"hono": "^4.13.
|
|
300
|
+
"hono": "^4.13.16",
|
|
301
301
|
"js-yaml": "^4.3.2",
|
|
302
302
|
"picomatch": "^4.0.7",
|
|
303
303
|
"pino": "^10.4.0",
|
|
304
304
|
"semver": "^7.8.5",
|
|
305
|
-
"typeid-js": "^1.2.0",
|
|
306
305
|
"zod": "^4.6.7"
|
|
307
306
|
},
|
|
308
307
|
"devDependencies": {
|
|
@@ -312,12 +311,13 @@
|
|
|
312
311
|
"@types/picomatch": "^4.0.3",
|
|
313
312
|
"@types/semver": "^7.8.0",
|
|
314
313
|
"esbuild": "^0.28.2",
|
|
315
|
-
"eslint": "^10.
|
|
314
|
+
"eslint": "^10.13.0",
|
|
316
315
|
"tsup": "^8",
|
|
316
|
+
"typeid-js": "^1.2.0",
|
|
317
317
|
"typescript": "^5",
|
|
318
|
-
"typescript-eslint": "^8.
|
|
319
|
-
"vite": "^8.3.
|
|
320
|
-
"vitest": "^5.0.
|
|
318
|
+
"typescript-eslint": "^8.72.1",
|
|
319
|
+
"vite": "^8.3.5",
|
|
320
|
+
"vitest": "^5.0.5"
|
|
321
321
|
},
|
|
322
322
|
"engines": {
|
|
323
323
|
"node": ">=22.12"
|
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/upgrade.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
|
2
2
|
import * as os from 'os';
|
|
3
3
|
import * as fs from 'fs';
|
|
4
4
|
import * as path from 'path';
|
|
5
|
-
import { createChecker } from './upgrade';
|
|
5
|
+
import { createChecker, UpgradeCheckError } from './upgrade';
|
|
6
6
|
|
|
7
7
|
// ─── helpers ─────────────────────────────────────────────────────────────────
|
|
8
8
|
|
|
@@ -587,3 +587,104 @@ describe('createChecker: tagPrefix and includePrereleases', () => {
|
|
|
587
587
|
expect(out.value()).toContain('https://github.com/acme/mono/releases/tag/xray/v2.0.0');
|
|
588
588
|
});
|
|
589
589
|
});
|
|
590
|
+
|
|
591
|
+
describe('createChecker: check()', () => {
|
|
592
|
+
let tmpDir: string;
|
|
593
|
+
|
|
594
|
+
beforeEach(() => {
|
|
595
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'upgrade-check-'));
|
|
596
|
+
vi.restoreAllMocks();
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
afterEach(() => {
|
|
600
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
601
|
+
vi.restoreAllMocks();
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
const mk = (extra: Record<string, unknown> = {}) =>
|
|
605
|
+
createChecker({
|
|
606
|
+
name: 'my-tool',
|
|
607
|
+
currentVersion: '1.0.0',
|
|
608
|
+
owner: 'acme',
|
|
609
|
+
repo: 'my-tool',
|
|
610
|
+
stateDir: tmpDir,
|
|
611
|
+
...extra,
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
it('resolves update info when newer', async () => {
|
|
615
|
+
vi.spyOn(globalThis, 'fetch').mockResolvedValue(jsonResponse({ tag_name: 'v2.0.0' }));
|
|
616
|
+
expect(await mk().check()).toEqual({
|
|
617
|
+
current: '1.0.0',
|
|
618
|
+
latest: '2.0.0',
|
|
619
|
+
updateAvailable: true,
|
|
620
|
+
url: 'https://github.com/acme/my-tool/releases/latest',
|
|
621
|
+
});
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
it('resolves updateAvailable false when up to date', async () => {
|
|
625
|
+
vi.spyOn(globalThis, 'fetch').mockResolvedValue(jsonResponse({ tag_name: 'v1.0.0' }));
|
|
626
|
+
const r = await mk().check();
|
|
627
|
+
expect(r.updateAvailable).toBe(false);
|
|
628
|
+
expect(r.latest).toBe('1.0.0');
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
it('rejects with UpgradeCheckError on network failure', async () => {
|
|
632
|
+
const boom = new Error('offline');
|
|
633
|
+
vi.spyOn(globalThis, 'fetch').mockRejectedValue(boom);
|
|
634
|
+
const err = await mk().check().catch((e) => e);
|
|
635
|
+
expect(err).toBeInstanceOf(UpgradeCheckError);
|
|
636
|
+
expect(err.cause).toBe(boom);
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
it('rejects on HTTP error status', async () => {
|
|
640
|
+
vi.spyOn(globalThis, 'fetch').mockResolvedValue(jsonResponse({}, 500));
|
|
641
|
+
await expect(mk().check()).rejects.toBeInstanceOf(UpgradeCheckError);
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
it('rejects on malformed body', async () => {
|
|
645
|
+
vi.spyOn(globalThis, 'fetch').mockResolvedValue(
|
|
646
|
+
new Response('not json', { status: 200 }),
|
|
647
|
+
);
|
|
648
|
+
await expect(mk().check()).rejects.toBeInstanceOf(UpgradeCheckError);
|
|
649
|
+
vi.spyOn(globalThis, 'fetch').mockResolvedValue(jsonResponse({ tag_name: 5 }));
|
|
650
|
+
await expect(mk().check()).rejects.toBeInstanceOf(UpgradeCheckError);
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
it('rejects when no release matches tagPrefix', async () => {
|
|
654
|
+
vi.spyOn(globalThis, 'fetch').mockResolvedValue(
|
|
655
|
+
jsonResponse([{ tag_name: 'other/v9.0.0' }]),
|
|
656
|
+
);
|
|
657
|
+
await expect(mk({ tagPrefix: 'xray/v' }).check()).rejects.toBeInstanceOf(
|
|
658
|
+
UpgradeCheckError,
|
|
659
|
+
);
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
it('honours tagPrefix and links the exact release', async () => {
|
|
663
|
+
vi.spyOn(globalThis, 'fetch').mockResolvedValue(
|
|
664
|
+
jsonResponse([{ tag_name: 'xray/v1.5.0' }, { tag_name: 'other/v9.0.0' }]),
|
|
665
|
+
);
|
|
666
|
+
const r = await mk({ tagPrefix: 'xray/v' }).check();
|
|
667
|
+
expect(r.latest).toBe('1.5.0');
|
|
668
|
+
expect(r.url).toBe('https://github.com/acme/my-tool/releases/tag/xray/v1.5.0');
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
it('serves from cache within TTL; cacheTTL 0 bypasses it', async () => {
|
|
672
|
+
const spy = vi
|
|
673
|
+
.spyOn(globalThis, 'fetch')
|
|
674
|
+
.mockImplementation(async () => jsonResponse({ tag_name: 'v2.0.0' }));
|
|
675
|
+
await mk().check();
|
|
676
|
+
await mk().check();
|
|
677
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
678
|
+
await mk({ cacheTTL: 0 }).check();
|
|
679
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
it('notifyIfAvailable still swallows what check() rejects', async () => {
|
|
683
|
+
vi.spyOn(globalThis, 'fetch').mockRejectedValue(new Error('offline'));
|
|
684
|
+
const out = new StringStream();
|
|
685
|
+
await expect(
|
|
686
|
+
mk().notifyIfAvailable(out as unknown as NodeJS.WritableStream),
|
|
687
|
+
).resolves.toBeUndefined();
|
|
688
|
+
expect(out.value()).toBe('');
|
|
689
|
+
});
|
|
690
|
+
});
|
package/src/upgrade.ts
CHANGED
|
@@ -17,8 +17,10 @@
|
|
|
17
17
|
* ### Error handling philosophy
|
|
18
18
|
* Version checking is a best-effort, non-critical operation. Any failure —
|
|
19
19
|
* network error, bad JSON, HTTP error, filesystem error, invalid semver — is
|
|
20
|
-
* silently discarded
|
|
21
|
-
*
|
|
20
|
+
* silently discarded by `notifyIfAvailable`, which always resolves without
|
|
21
|
+
* throwing. `check()` is the strict variant: it rejects with an
|
|
22
|
+
* {@link UpgradeCheckError} so callers (e.g. `upgrade --check`) can tell a
|
|
23
|
+
* failed lookup from "up to date".
|
|
22
24
|
*
|
|
23
25
|
* ### Notice format
|
|
24
26
|
* ```
|
|
@@ -100,11 +102,41 @@ export interface CheckerOptions {
|
|
|
100
102
|
includePrereleases?: boolean;
|
|
101
103
|
}
|
|
102
104
|
|
|
105
|
+
/** Outcome of {@link Checker.check}. */
|
|
106
|
+
export interface UpgradeCheckResult {
|
|
107
|
+
/** Running version, as configured. */
|
|
108
|
+
current: string;
|
|
109
|
+
/** Latest release version (no leading `v` / tag prefix). */
|
|
110
|
+
latest: string;
|
|
111
|
+
/** True when `latest` is strictly greater than `current`. */
|
|
112
|
+
updateAvailable: boolean;
|
|
113
|
+
/** Release page to link to. */
|
|
114
|
+
url: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Rejection of {@link Checker.check}; the underlying error is in `cause`. */
|
|
118
|
+
export class UpgradeCheckError extends Error {
|
|
119
|
+
constructor(message: string, options?: { cause?: unknown }) {
|
|
120
|
+
super(message, options);
|
|
121
|
+
this.name = 'UpgradeCheckError';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
103
125
|
/**
|
|
104
126
|
* Returned by {@link createChecker}. Call {@link Checker.notifyIfAvailable}
|
|
105
127
|
* at the end of a CLI command to surface upgrade notices non-intrusively.
|
|
106
128
|
*/
|
|
107
129
|
export interface Checker {
|
|
130
|
+
/**
|
|
131
|
+
* Looks up the latest release and resolves with the outcome. Unlike
|
|
132
|
+
* {@link Checker.notifyIfAvailable} it never swallows failures: network,
|
|
133
|
+
* HTTP, parse and "no matching release" errors reject with an
|
|
134
|
+
* {@link UpgradeCheckError}, so callers can tell a failed lookup from
|
|
135
|
+
* "up to date". Honours `tagPrefix`, `includePrereleases` and the cache;
|
|
136
|
+
* pass `cacheTTL: 0` to bypass the cache.
|
|
137
|
+
*/
|
|
138
|
+
check(): Promise<UpgradeCheckResult>;
|
|
139
|
+
|
|
108
140
|
/**
|
|
109
141
|
* Checks for a newer GitHub release and writes a one-line notice to `out`
|
|
110
142
|
* if one is available. Silently swallows all errors.
|
|
@@ -218,7 +250,7 @@ export function createChecker(opts: CheckerOptions): Checker {
|
|
|
218
250
|
tag?: string;
|
|
219
251
|
}
|
|
220
252
|
|
|
221
|
-
async function fetchLatestVersion(): Promise<Latest
|
|
253
|
+
async function fetchLatestVersion(): Promise<Latest> {
|
|
222
254
|
const controller = new AbortController();
|
|
223
255
|
const timer = setTimeout(() => controller.abort(), timeout);
|
|
224
256
|
try {
|
|
@@ -227,10 +259,10 @@ export function createChecker(opts: CheckerOptions): Checker {
|
|
|
227
259
|
signal: controller.signal,
|
|
228
260
|
headers: { Accept: 'application/vnd.github+json' },
|
|
229
261
|
});
|
|
230
|
-
if (!res.ok)
|
|
262
|
+
if (!res.ok) throw new UpgradeCheckError(`release lookup failed: HTTP ${res.status}`);
|
|
231
263
|
const body = (await res.json()) as { tag_name?: string };
|
|
232
264
|
const tag = body.tag_name;
|
|
233
|
-
if (typeof tag !== 'string')
|
|
265
|
+
if (typeof tag !== 'string') throw new UpgradeCheckError('release lookup failed: no tag_name');
|
|
234
266
|
// Strip leading 'v' so semver.gt works with or without prefix.
|
|
235
267
|
return { version: tag.replace(/^v/, '') };
|
|
236
268
|
} finally {
|
|
@@ -243,7 +275,7 @@ export function createChecker(opts: CheckerOptions): Checker {
|
|
|
243
275
|
* among non-draft releases whose tag starts with `tagPrefix`; prereleases
|
|
244
276
|
* only when `includePrereleases` is set.
|
|
245
277
|
*/
|
|
246
|
-
async function fetchHighestRelease(signal: AbortSignal): Promise<Latest
|
|
278
|
+
async function fetchHighestRelease(signal: AbortSignal): Promise<Latest> {
|
|
247
279
|
let best: Latest | null = null;
|
|
248
280
|
for (let page = 1; page <= MAX_PAGES; page++) {
|
|
249
281
|
const res = await fetch(`${listURL}?per_page=${PAGE_SIZE}&page=${page}`, {
|
|
@@ -252,11 +284,14 @@ export function createChecker(opts: CheckerOptions): Checker {
|
|
|
252
284
|
});
|
|
253
285
|
if (!res.ok) {
|
|
254
286
|
// Page 1 failing is a failed check; a later page keeps what we have.
|
|
255
|
-
if (page === 1)
|
|
287
|
+
if (page === 1) throw new UpgradeCheckError(`release lookup failed: HTTP ${res.status}`);
|
|
256
288
|
break;
|
|
257
289
|
}
|
|
258
290
|
const body = (await res.json()) as unknown;
|
|
259
|
-
if (!Array.isArray(body))
|
|
291
|
+
if (!Array.isArray(body)) {
|
|
292
|
+
if (page === 1) throw new UpgradeCheckError('release lookup failed: unexpected response');
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
260
295
|
for (const rel of body as GitHubRelease[]) {
|
|
261
296
|
if (rel === null || typeof rel !== 'object') continue;
|
|
262
297
|
if (rel.draft === true || typeof rel.tag_name !== 'string') continue;
|
|
@@ -271,44 +306,58 @@ export function createChecker(opts: CheckerOptions): Checker {
|
|
|
271
306
|
}
|
|
272
307
|
if (body.length < PAGE_SIZE) break;
|
|
273
308
|
}
|
|
309
|
+
if (best === null) throw new UpgradeCheckError('no matching release found');
|
|
274
310
|
return best;
|
|
275
311
|
}
|
|
276
312
|
|
|
277
|
-
// ──
|
|
313
|
+
// ── check ──────────────────────────────────────────────────────────────────
|
|
278
314
|
|
|
279
|
-
async function
|
|
315
|
+
async function check(): Promise<UpgradeCheckResult> {
|
|
280
316
|
try {
|
|
281
|
-
let latestVersion: string
|
|
317
|
+
let latestVersion: string;
|
|
282
318
|
let latestTag: string | undefined;
|
|
283
319
|
|
|
284
|
-
// Check cache first.
|
|
285
320
|
const cached = readCache();
|
|
286
321
|
if (cached !== null && Date.now() - cached.checkedAt < cacheTTL) {
|
|
287
322
|
latestVersion = cached.version;
|
|
288
323
|
latestTag = cached.tag;
|
|
289
324
|
} else {
|
|
290
325
|
const latest = await fetchLatestVersion();
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
writeCache(latest.version, latest.tag);
|
|
295
|
-
}
|
|
326
|
+
latestVersion = latest.version;
|
|
327
|
+
latestTag = latest.tag;
|
|
328
|
+
writeCache(latest.version, latest.tag);
|
|
296
329
|
}
|
|
297
330
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
331
|
+
return {
|
|
332
|
+
current: currentVersion,
|
|
333
|
+
latest: latestVersion,
|
|
334
|
+
// Only strictly greater counts as an update.
|
|
335
|
+
updateAvailable: semver.gt(latestVersion, currentVersion),
|
|
336
|
+
url: noticeURL(latestTag),
|
|
337
|
+
};
|
|
338
|
+
} catch (err) {
|
|
339
|
+
if (err instanceof UpgradeCheckError) throw err;
|
|
340
|
+
throw new UpgradeCheckError(
|
|
341
|
+
`upgrade check failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
342
|
+
{ cause: err },
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
302
346
|
|
|
303
|
-
|
|
304
|
-
`\nA new release of ${name} is available: v${currentVersion} → v${latestVersion}\n` +
|
|
305
|
-
`${noticeURL(latestTag)}\n`;
|
|
347
|
+
// ── notifyIfAvailable ──────────────────────────────────────────────────────
|
|
306
348
|
|
|
307
|
-
|
|
349
|
+
async function notifyIfAvailable(out: NodeJS.WritableStream): Promise<void> {
|
|
350
|
+
try {
|
|
351
|
+
const r = await check();
|
|
352
|
+
if (!r.updateAvailable) return;
|
|
353
|
+
out.write(
|
|
354
|
+
`\nA new release of ${name} is available: v${r.current} → v${r.latest}\n` +
|
|
355
|
+
`${r.url}\n`,
|
|
356
|
+
);
|
|
308
357
|
} catch {
|
|
309
|
-
//
|
|
358
|
+
// Best-effort: any failure is silently swallowed.
|
|
310
359
|
}
|
|
311
360
|
}
|
|
312
361
|
|
|
313
|
-
return { notifyIfAvailable };
|
|
362
|
+
return { check, notifyIfAvailable };
|
|
314
363
|
}
|
package/dist/chunk-L23O2FFE.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|
|
4
|
-
|
|
5
|
-
// src/id/index.ts
|
|
6
|
-
var id_exports = {};
|
|
7
|
-
_chunkR5U7XKVJjs.__export.call(void 0, id_exports, {
|
|
8
|
-
newId: () => newId,
|
|
9
|
-
newTyped: () => newTyped,
|
|
10
|
-
parse: () => parse,
|
|
11
|
-
parseTyped: () => parseTyped,
|
|
12
|
-
typeIdSchema: () => typeIdSchema
|
|
13
|
-
});
|
|
14
|
-
var _typeidjs = require('typeid-js');
|
|
15
|
-
var _zod = require('zod');
|
|
16
|
-
function newId(prefix) {
|
|
17
|
-
return _typeidjs.typeid.call(void 0, prefix).toString();
|
|
18
|
-
}
|
|
19
|
-
function parse(s) {
|
|
20
|
-
const tid = _typeidjs.TypeID.fromString(s);
|
|
21
|
-
return {
|
|
22
|
-
prefix: tid.getType(),
|
|
23
|
-
uuid: tid.toUUID()
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function newTyped(prefix) {
|
|
27
|
-
return _typeidjs.typeid.call(void 0, prefix).toString();
|
|
28
|
-
}
|
|
29
|
-
function parseTyped(prefix, s) {
|
|
30
|
-
const tid = _typeidjs.TypeID.fromString(s, prefix);
|
|
31
|
-
return tid.toString();
|
|
32
|
-
}
|
|
33
|
-
var SUFFIX_RE = /^[0-7][0-9a-hjkmnp-tv-z]{25}$/;
|
|
34
|
-
function typeIdSchema(prefix) {
|
|
35
|
-
const pattern = new RegExp(
|
|
36
|
-
`^${escapeRegExp(prefix)}_${SUFFIX_RE.source.slice(1, -1)}$`
|
|
37
|
-
);
|
|
38
|
-
return _zod.z.string().regex(pattern, `invalid typeid for prefix '${prefix}'`);
|
|
39
|
-
}
|
|
40
|
-
function escapeRegExp(s) {
|
|
41
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
exports.newId = newId; exports.parse = parse; exports.newTyped = newTyped; exports.parseTyped = parseTyped; exports.typeIdSchema = typeIdSchema; exports.id_exports = id_exports;
|