@neko-makura/railid 4.3.3 → 4.4.0

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/index.d.ts CHANGED
@@ -1,200 +1,224 @@
1
- export type Backend = "tpm" | "os-only";
2
-
3
- /**
4
- * Stable `error.code` values set by the bindings. Native N-API failures are
5
- * mapped to these codes at the JavaScript boundary; `TpmUnavailable` is the
6
- * fail-closed signal from the TPM hybrid profile.
7
- */
8
- export type RailIdErrorCode =
9
- | "TpmUnavailable"
10
- | "TpmRandomFailure"
11
- | "OsRandomFailure"
12
- | "TimestampOutOfRange"
13
- | "InvalidInput"
14
- | "CapacityOverflow"
15
- | "WorkerFailure";
16
-
17
- /**
18
- * Errors thrown by the bindings carry one of the {@link RailIdErrorCode}
19
- * values in `code`.
20
- */
21
- export interface RailIdError extends Error {
22
- code: RailIdErrorCode;
23
- }
24
-
25
- export interface DecodedRailId {
26
- /** Unix timestamp in milliseconds. */
27
- timestampMs: number;
28
- /** 150-bit random field as 38 lowercase hex characters. */
29
- randomHex: string;
30
- /** Canonical 32-character Base64URL encoding. */
31
- encoded: string;
32
- }
33
-
34
- /** Generate one RailID with the standard TPM hybrid profile. */
35
- export declare function generate(): string;
36
-
37
- /** Generate one RailID with the explicitly degraded OS-only profile. */
38
- export declare function generateOsOnly(): string;
39
-
40
- /** Generate one TPM-profile RailID as 32 ASCII bytes, without a JS string. */
41
- export declare function generateBuffer(): Buffer;
42
-
43
- /** Generate one OS-only RailID as 32 ASCII bytes, without a JS string. */
44
- export declare function generateOsOnlyBuffer(): Buffer;
45
-
46
- /**
47
- * Generate one 126-bit v4 RailID as a 21-character string with the TPM hybrid
48
- * profile. Throws `TpmUnavailable` rather than falling back to OS-only.
49
- */
50
- export declare function generateV4(): string;
51
-
52
- /** Generate one 126-bit v4 RailID as a 21-character string with the OS-only profile. */
53
- export declare function generateV4OsOnly(): string;
54
-
55
- /** Generate one 126-bit v4 RailID as 21 ASCII bytes with the TPM hybrid profile. */
56
- export declare function generateV4Buffer(): Buffer;
57
-
58
- /** Generate one 126-bit v4 RailID as 21 ASCII bytes with the OS-only profile. */
59
- export declare function generateV4BufferOsOnly(): Buffer;
60
-
61
- /**
62
- * Generate `count` v4 IDs as one contiguous `count * 21` Buffer with the TPM
63
- * hybrid profile. Capped at 1,024 IDs and fails closed without a TPM.
64
- * Counts are validated before allocation; invalid counts throw `InvalidInput`.
65
- *
66
- * The returned Buffer's external allocation is reported to V8 so repeated
67
- * batches raise GC pressure instead of growing RSS silently. For sustained
68
- * throughput, prefer `generateV4ManyEncodedInto` to avoid the `count * 21`
69
- * allocation entirely.
70
- */
71
- export declare function generateV4ManyEncoded(count: number): Buffer;
72
-
73
- /**
74
- * Generate `count` v4 IDs as one contiguous `count * 21` Buffer with the
75
- * explicitly degraded OS-only profile. Capped at 1,000,000 IDs. Invalid
76
- * counts throw `InvalidInput`.
77
- */
78
- export declare function generateV4ManyEncodedOsOnly(count: number): Buffer;
79
-
80
- /**
81
- * Generate `count` v4 IDs asynchronously with the TPM hybrid profile. The
82
- * batch runs on a libuv worker thread and resolves to a `count * 21` Buffer.
83
- * Capped at 1,024 IDs. Fails closed with `TpmUnavailable` when no TPM is
84
- * usable; invalid counts throw `InvalidInput` synchronously.
85
- */
86
- export declare function generateV4ManyEncodedAsync(count: number): Promise<Buffer>;
87
-
88
- /**
89
- * Generate `count` v4 IDs asynchronously with the OS-only profile. The batch
90
- * runs on a libuv worker thread and resolves to a `count * 21` Buffer. Capped
91
- * at 1,000,000 IDs. Invalid counts throw `InvalidInput` synchronously.
92
- */
93
- export declare function generateV4ManyEncodedOsOnlyAsync(
94
- count: number,
95
- ): Promise<Buffer>;
96
-
97
- /**
98
- * Generate v4 IDs with the TPM hybrid profile into a caller-provided Buffer.
99
- * The buffer length must be an exact multiple of 21 and determines the count;
100
- * it is capped at 1,024 IDs. Nothing is returned. Invalid lengths throw
101
- * `InvalidInput` before any bytes are written. Fails closed with
102
- * `TpmUnavailable` without a TPM.
103
- *
104
- * This is the recommended high-throughput path: it avoids allocating and
105
- * handing a `count * 21` external Buffer to V8 on every call.
106
- */
107
- export declare function generateV4ManyEncodedInto(buffer: Buffer): void;
108
-
109
- /**
110
- * Generate v4 IDs with the OS-only profile into a caller-provided Buffer.
111
- * The buffer length must be an exact multiple of 21 and determines the count;
112
- * it is capped at 1,000,000 IDs. Nothing is returned. Invalid lengths throw
113
- * `InvalidInput` before any bytes are written.
114
- */
115
- export declare function generateV4ManyEncodedOsOnlyInto(buffer: Buffer): void;
116
-
117
- /** Generate `count` IDs synchronously as strings. OS-only strings cap at 100,000. */
118
- export declare function generateMany(count: number, osOnly?: boolean): string[];
119
-
120
- /** Generate `count` IDs synchronously as one contiguous `count * 32` Buffer. */
121
- export declare function generateManyEncoded(count: number, osOnly?: boolean): Buffer;
122
-
123
- /** Generate `count` IDs asynchronously as strings. */
124
- export declare function generateManyAsync(count: number, osOnly?: boolean): Promise<string[]>;
125
-
126
- /** Generate `count` IDs asynchronously as one contiguous `count * 32` Buffer. */
127
- export declare function generateManyEncodedAsync(
128
- count: number,
129
- osOnly?: boolean,
130
- ): Promise<Buffer>;
131
-
132
- /** Decode and validate a RailID. */
133
- export declare function decode(input: string): DecodedRailId;
134
-
135
- /** RailID crate version. */
136
- export declare function version(): string;
137
-
138
- /** Native backend compiled into the loaded addon. */
139
- export declare function backend(): Backend;
140
-
141
- export type V2Tick = "1d" | "1h" | "1s" | "100ms" | "10ms" | "1ms" | "0.1ms";
142
-
143
- /** A timestamp tick and field width. */
144
- export interface V2TimeSpec {
145
- tick: V2Tick;
146
- bits: number;
147
- }
148
-
149
- /** A v2 format description. `time` omitted means the default for `bits`. */
150
- export interface V2Format {
151
- bits: number;
152
- time?: V2Tick | V2TimeSpec | null;
153
- force?: boolean;
154
- }
155
-
156
- /** A non-fatal v2 format warning. */
157
- export interface V2Warning {
158
- code: string;
159
- reason: string;
160
- }
161
-
162
- /** A normalized v2 format. */
163
- export interface V2FormatInfo {
164
- totalBits: number;
165
- timestampBits: number;
166
- randomBits: number;
167
- tick: V2Tick | null;
168
- encodedLen: number;
169
- warnings: V2Warning[];
170
- }
171
-
172
- /** Decoded v2 fields. Timestamps are decimal strings for full precision. */
173
- export interface V2Decoded {
174
- encoded: string;
175
- bits: number;
176
- timestampBits: number;
177
- randomBits: number;
178
- ticks: string | null;
179
- timestampMs: string | null;
180
- timestampUs: string | null;
181
- randomHex: string;
182
- }
183
-
184
- /** Generate one v2 value. */
185
- export declare function generateV2(format: V2Format): string;
186
-
187
- /** Generate one v2 value as 3-171 ASCII bytes. */
188
- export declare function generateV2Buffer(format: V2Format): Buffer;
189
-
190
- /** Generate `count` v2 values as a string array. Capped at 1,024 (TPM) or 1,000,000 (OS-only). */
191
- export declare function generateV2Many(format: V2Format, count: number): string[];
192
-
193
- /** Generate `count` v2 values as one contiguous `count * encodedLen` Buffer. */
194
- export declare function generateV2ManyEncoded(format: V2Format, count: number): Buffer;
195
-
196
- /** Decode a v2 value with the expected format. */
197
- export declare function decodeV2(input: string, format: V2Format): V2Decoded;
198
-
199
- /** Normalize and validate a v2 format. */
200
- export declare function formatV2(format: V2Format): V2FormatInfo;
1
+ export type Backend = "tpm" | "os-only";
2
+
3
+ /**
4
+ * Stable `error.code` values set by the bindings. Native N-API failures are
5
+ * mapped to these codes at the JavaScript boundary; `TpmUnavailable` is the
6
+ * fail-closed signal from the TPM hybrid profile.
7
+ */
8
+ export type RailIdErrorCode =
9
+ | "TpmUnavailable"
10
+ | "TpmRandomFailure"
11
+ | "OsRandomFailure"
12
+ | "TimestampOutOfRange"
13
+ | "InvalidInput"
14
+ | "CapacityOverflow"
15
+ | "WorkerFailure";
16
+
17
+ /**
18
+ * Errors thrown by the bindings carry one of the {@link RailIdErrorCode}
19
+ * values in `code`.
20
+ */
21
+ export interface RailIdError extends Error {
22
+ code: RailIdErrorCode;
23
+ }
24
+
25
+ export interface DecodedRailId {
26
+ /** Unix timestamp in milliseconds. */
27
+ timestampMs: number;
28
+ /** 150-bit random field as 38 lowercase hex characters. */
29
+ randomHex: string;
30
+ /** Canonical 32-character Base64URL encoding. */
31
+ encoded: string;
32
+ }
33
+
34
+ /** Generate one RailID with the standard TPM hybrid profile. */
35
+ export declare function generate(): string;
36
+
37
+ /** Generate one RailID with the explicitly degraded OS-only profile. */
38
+ export declare function generateOsOnly(): string;
39
+
40
+ /** Generate one TPM-profile RailID as 32 ASCII bytes, without a JS string. */
41
+ export declare function generateBuffer(): Buffer;
42
+
43
+ /** Generate one OS-only RailID as 32 ASCII bytes, without a JS string. */
44
+ export declare function generateOsOnlyBuffer(): Buffer;
45
+
46
+ /**
47
+ * Generate one 126-bit v4 RailID as a 21-character string with the TPM hybrid
48
+ * profile. Throws `TpmUnavailable` rather than falling back to OS-only.
49
+ */
50
+ export declare function generateV4(): string;
51
+
52
+ /** Generate one 126-bit v4 RailID as a 21-character string with the OS-only profile. */
53
+ export declare function generateV4OsOnly(): string;
54
+
55
+ /** Generate one 126-bit v4 RailID as 21 ASCII bytes with the TPM hybrid profile. */
56
+ export declare function generateV4Buffer(): Buffer;
57
+
58
+ /** Generate one 126-bit v4 RailID as 21 ASCII bytes with the OS-only profile. */
59
+ export declare function generateV4BufferOsOnly(): Buffer;
60
+
61
+ /**
62
+ * Generate `count` v4 IDs as one contiguous `count * 21` Buffer with the TPM
63
+ * hybrid profile. Capped at 1,024 IDs and fails closed without a TPM.
64
+ * Counts are validated before allocation; invalid counts throw `InvalidInput`.
65
+ *
66
+ * The returned Buffer's external allocation is reported to V8 so repeated
67
+ * batches raise GC pressure instead of growing RSS silently. For sustained
68
+ * throughput, prefer `generateV4ManyEncodedInto` to avoid the `count * 21`
69
+ * allocation entirely.
70
+ */
71
+ export declare function generateV4ManyEncoded(count: number): Buffer;
72
+
73
+ /**
74
+ * Generate `count` v4 IDs as one contiguous `count * 21` Buffer with the
75
+ * explicitly degraded OS-only profile. Capped at 1,000,000 IDs. Invalid
76
+ * counts throw `InvalidInput`.
77
+ */
78
+ export declare function generateV4ManyEncodedOsOnly(count: number): Buffer;
79
+
80
+ /**
81
+ * Generate `count` v4 IDs asynchronously with the TPM hybrid profile. The
82
+ * batch runs on a libuv worker thread and resolves to a `count * 21` Buffer.
83
+ * Capped at 1,024 IDs. Fails closed with `TpmUnavailable` when no TPM is
84
+ * usable; invalid counts throw `InvalidInput` synchronously.
85
+ */
86
+ export declare function generateV4ManyEncodedAsync(count: number): Promise<Buffer>;
87
+
88
+ /**
89
+ * Generate `count` v4 IDs asynchronously with the OS-only profile. The batch
90
+ * runs on a libuv worker thread and resolves to a `count * 21` Buffer. Capped
91
+ * at 1,000,000 IDs. Invalid counts throw `InvalidInput` synchronously.
92
+ */
93
+ export declare function generateV4ManyEncodedOsOnlyAsync(
94
+ count: number,
95
+ ): Promise<Buffer>;
96
+
97
+ /**
98
+ * Generate v4 IDs with the TPM hybrid profile into a caller-provided Buffer.
99
+ * The buffer length must be an exact multiple of 21 and determines the count;
100
+ * it is capped at 1,024 IDs. Nothing is returned. Invalid lengths throw
101
+ * `InvalidInput` before any bytes are written. Fails closed with
102
+ * `TpmUnavailable` without a TPM.
103
+ *
104
+ * This is the recommended high-throughput path: it avoids allocating and
105
+ * handing a `count * 21` external Buffer to V8 on every call.
106
+ */
107
+ export declare function generateV4ManyEncodedInto(buffer: Buffer): void;
108
+
109
+ /**
110
+ * Generate v4 IDs with the OS-only profile into a caller-provided Buffer.
111
+ * The buffer length must be an exact multiple of 21 and determines the count;
112
+ * it is capped at 1,000,000 IDs. Nothing is returned. Invalid lengths throw
113
+ * `InvalidInput` before any bytes are written.
114
+ */
115
+ export declare function generateV4ManyEncodedOsOnlyInto(buffer: Buffer): void;
116
+
117
+ /** Generate `count` IDs synchronously as strings. OS-only strings cap at 100,000. */
118
+ export declare function generateMany(count: number, osOnly?: boolean): string[];
119
+
120
+ /** Generate `count` IDs synchronously as one contiguous `count * 32` Buffer. */
121
+ export declare function generateManyEncoded(count: number, osOnly?: boolean): Buffer;
122
+
123
+ /** Generate `count` IDs asynchronously as strings. */
124
+ export declare function generateManyAsync(count: number, osOnly?: boolean): Promise<string[]>;
125
+
126
+ /** Generate `count` IDs asynchronously as one contiguous `count * 32` Buffer. */
127
+ export declare function generateManyEncodedAsync(
128
+ count: number,
129
+ osOnly?: boolean,
130
+ ): Promise<Buffer>;
131
+
132
+ /** Decode and validate a RailID. */
133
+ export declare function decode(input: string): DecodedRailId;
134
+
135
+ /** RailID crate version. */
136
+ export declare function version(): string;
137
+
138
+ /** Native backend compiled into the loaded addon. */
139
+ export declare function backend(): Backend;
140
+
141
+ export type V2Tick = "1d" | "1h" | "1s" | "100ms" | "10ms" | "1ms" | "0.1ms";
142
+
143
+ /** A timestamp tick and field width. */
144
+ export interface V2TimeSpec {
145
+ tick: V2Tick;
146
+ bits: number;
147
+ }
148
+
149
+ /** A v2 format description. `time` omitted means the default for `bits`. */
150
+ export interface V2Format {
151
+ bits: number;
152
+ time?: V2Tick | V2TimeSpec | null;
153
+ force?: boolean;
154
+ }
155
+
156
+ /** A non-fatal v2 format warning. */
157
+ export interface V2Warning {
158
+ code: string;
159
+ reason: string;
160
+ }
161
+
162
+ /** A normalized v2 format. */
163
+ export interface V2FormatInfo {
164
+ totalBits: number;
165
+ timestampBits: number;
166
+ randomBits: number;
167
+ tick: V2Tick | null;
168
+ encodedLen: number;
169
+ warnings: V2Warning[];
170
+ }
171
+
172
+ /** Decoded v2 fields. Timestamps are decimal strings for full precision. */
173
+ export interface V2Decoded {
174
+ encoded: string;
175
+ bits: number;
176
+ timestampBits: number;
177
+ randomBits: number;
178
+ ticks: string | null;
179
+ timestampMs: string | null;
180
+ timestampUs: string | null;
181
+ randomHex: string;
182
+ }
183
+
184
+ /** Generate one v2 value. */
185
+ export declare function generateV2(format: V2Format): string;
186
+
187
+ /** Generate one v2 value as 3-171 ASCII bytes. */
188
+ export declare function generateV2Buffer(format: V2Format): Buffer;
189
+
190
+ /** Generate `count` v2 values as a string array. Capped at 1,024 (TPM) or 1,000,000 (OS-only). */
191
+ export declare function generateV2Many(format: V2Format, count: number): string[];
192
+
193
+ /** Generate `count` v2 values as one contiguous `count * encodedLen` Buffer. */
194
+ export declare function generateV2ManyEncoded(format: V2Format, count: number): Buffer;
195
+
196
+ /**
197
+ * Generate `count` v2 values asynchronously as a string array with the TPM
198
+ * hybrid profile. The batch runs on a libuv worker thread. Capped at 1,024
199
+ * IDs; fails closed with `TpmUnavailable` when no TPM is usable. Invalid
200
+ * formats and counts throw `InvalidInput` synchronously, before any work is
201
+ * scheduled.
202
+ */
203
+ export declare function generateV2ManyAsync(
204
+ format: V2Format,
205
+ count: number,
206
+ ): Promise<string[]>;
207
+
208
+ /**
209
+ * Generate `count` v2 values asynchronously as one contiguous
210
+ * `count * encodedLen` Buffer with the TPM hybrid profile. The batch runs on a
211
+ * libuv worker thread. Capped at 1,024 IDs; fails closed with
212
+ * `TpmUnavailable` when no TPM is usable. Invalid formats and counts throw
213
+ * `InvalidInput` synchronously, before any work is scheduled.
214
+ */
215
+ export declare function generateV2ManyEncodedAsync(
216
+ format: V2Format,
217
+ count: number,
218
+ ): Promise<Buffer>;
219
+
220
+ /** Decode a v2 value with the expected format. */
221
+ export declare function decodeV2(input: string, format: V2Format): V2Decoded;
222
+
223
+ /** Normalize and validate a v2 format. */
224
+ export declare function formatV2(format: V2Format): V2FormatInfo;