@umbra-privacy/sdk 1.0.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/LICENSE +21 -0
- package/README.md +122 -0
- package/dist/addresses-Brzgurv_.d.ts +145 -0
- package/dist/addresses-D_0YAS6B.d.cts +145 -0
- package/dist/chunk-2Q75CQQJ.js +12 -0
- package/dist/chunk-2Q75CQQJ.js.map +1 -0
- package/dist/chunk-7QVYU63E.js +6 -0
- package/dist/chunk-7QVYU63E.js.map +1 -0
- package/dist/chunk-BM7N6N7E.js +1883 -0
- package/dist/chunk-BM7N6N7E.js.map +1 -0
- package/dist/chunk-GXKSUB2U.cjs +4416 -0
- package/dist/chunk-GXKSUB2U.cjs.map +1 -0
- package/dist/chunk-HOEXDXRC.cjs +792 -0
- package/dist/chunk-HOEXDXRC.cjs.map +1 -0
- package/dist/chunk-MDFSBU5W.cjs +2033 -0
- package/dist/chunk-MDFSBU5W.cjs.map +1 -0
- package/dist/chunk-MQY7HDIA.js +600 -0
- package/dist/chunk-MQY7HDIA.js.map +1 -0
- package/dist/chunk-MVKTV3FT.cjs +20 -0
- package/dist/chunk-MVKTV3FT.cjs.map +1 -0
- package/dist/chunk-PG2J6V6Y.js +4094 -0
- package/dist/chunk-PG2J6V6Y.js.map +1 -0
- package/dist/chunk-PK6SKIKE.cjs +8 -0
- package/dist/chunk-PK6SKIKE.cjs.map +1 -0
- package/dist/chunk-VEGLTTYQ.cjs +621 -0
- package/dist/chunk-VEGLTTYQ.cjs.map +1 -0
- package/dist/chunk-WVHQ46DD.js +758 -0
- package/dist/chunk-WVHQ46DD.js.map +1 -0
- package/dist/constants/index.cjs +316 -0
- package/dist/constants/index.cjs.map +1 -0
- package/dist/constants/index.d.cts +739 -0
- package/dist/constants/index.d.ts +739 -0
- package/dist/constants/index.js +193 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/cryptography-BTGC72u-.d.cts +4809 -0
- package/dist/cryptography-BTGC72u-.d.ts +4809 -0
- package/dist/errors/index.cjs +141 -0
- package/dist/errors/index.cjs.map +1 -0
- package/dist/errors/index.d.cts +1415 -0
- package/dist/errors/index.d.ts +1415 -0
- package/dist/errors/index.js +4 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index-B9pDY73x.d.ts +12933 -0
- package/dist/index-CLj_zWSD.d.ts +235 -0
- package/dist/index-CX6_pIRS.d.cts +235 -0
- package/dist/index-D33yo0qB.d.cts +12933 -0
- package/dist/index.cjs +22464 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +11694 -0
- package/dist/index.d.ts +11694 -0
- package/dist/index.js +22314 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.cjs +4 -0
- package/dist/interfaces/index.cjs.map +1 -0
- package/dist/interfaces/index.d.cts +8 -0
- package/dist/interfaces/index.d.ts +8 -0
- package/dist/interfaces/index.js +3 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/networks-C-orpSFW.d.ts +65 -0
- package/dist/networks-FxYERGD1.d.cts +65 -0
- package/dist/types/index.cjs +605 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +1853 -0
- package/dist/types/index.d.ts +1853 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types-BBuELtY8.d.cts +495 -0
- package/dist/types-n-sHFcgr.d.ts +495 -0
- package/dist/utils/index.cjs +1295 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +9559 -0
- package/dist/utils/index.d.ts +9559 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/versions-D9PqsEvj.d.cts +173 -0
- package/dist/versions-D9PqsEvj.d.ts +173 -0
- package/package.json +151 -0
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
import { S as SubBrandedType, B as BrandedType } from './cryptography-BTGC72u-.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Temporal Types
|
|
5
|
+
*
|
|
6
|
+
* This module defines branded types for timestamp components used in
|
|
7
|
+
* time-scoped viewing key derivation. These types provide compile-time
|
|
8
|
+
* safety for temporal values with runtime validation.
|
|
9
|
+
*
|
|
10
|
+
* ## Overview
|
|
11
|
+
*
|
|
12
|
+
* The module provides a hierarchical type system:
|
|
13
|
+
* - `TimestampComponent` - Base branded type for all timestamp values
|
|
14
|
+
* - `Year`, `Month`, `Day`, `Hour`, `Minute`, `Second` - Subbranded types
|
|
15
|
+
*
|
|
16
|
+
* ## Validation Ranges
|
|
17
|
+
*
|
|
18
|
+
* - Year: 0 to 9999 (reasonable range for most applications)
|
|
19
|
+
* - Month: 1 to 12
|
|
20
|
+
* - Day: 1 to 31
|
|
21
|
+
* - Hour: 0 to 23
|
|
22
|
+
* - Minute: 0 to 59
|
|
23
|
+
* - Second: 0 to 59
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* All temporal component types are encoded as `bigint` to integrate directly with the BN254
|
|
27
|
+
* field arithmetic used in viewing key derivation. The branded type system prevents accidentally
|
|
28
|
+
* passing a `Month` where a `Year` is expected, catching a class of derivation-key bugs at
|
|
29
|
+
* compile time.
|
|
30
|
+
*
|
|
31
|
+
* @packageDocumentation
|
|
32
|
+
* @module common/temporal/types
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Minimum valid year value (inclusive).
|
|
37
|
+
*
|
|
38
|
+
* @remarks Year 0 corresponds to 1 BCE in the proleptic Gregorian calendar.
|
|
39
|
+
* @see {@link YEAR_MAX}
|
|
40
|
+
* @see {@link assertYear}
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
declare const YEAR_MIN = 0n;
|
|
44
|
+
/**
|
|
45
|
+
* Maximum valid year value (inclusive).
|
|
46
|
+
*
|
|
47
|
+
* @remarks Upper bound chosen to comfortably cover all practical use cases.
|
|
48
|
+
* @see {@link YEAR_MIN}
|
|
49
|
+
* @see {@link assertYear}
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
declare const YEAR_MAX = 9999n;
|
|
53
|
+
/**
|
|
54
|
+
* Minimum valid month value (inclusive).
|
|
55
|
+
*
|
|
56
|
+
* @remarks January is represented as 1, following the ISO 8601 convention.
|
|
57
|
+
* @see {@link MONTH_MAX}
|
|
58
|
+
* @see {@link assertMonth}
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
declare const MONTH_MIN = 1n;
|
|
62
|
+
/**
|
|
63
|
+
* Maximum valid month value (inclusive).
|
|
64
|
+
*
|
|
65
|
+
* @remarks December is represented as 12.
|
|
66
|
+
* @see {@link MONTH_MIN}
|
|
67
|
+
* @see {@link assertMonth}
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
declare const MONTH_MAX = 12n;
|
|
71
|
+
/**
|
|
72
|
+
* Minimum valid day value (inclusive).
|
|
73
|
+
*
|
|
74
|
+
* @remarks The first day of any month.
|
|
75
|
+
* @see {@link DAY_MAX}
|
|
76
|
+
* @see {@link assertDay}
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
declare const DAY_MIN = 1n;
|
|
80
|
+
/**
|
|
81
|
+
* Maximum valid day value (inclusive).
|
|
82
|
+
*
|
|
83
|
+
* @remarks
|
|
84
|
+
* Set to 31 to accommodate all months. Month-specific validation (e.g., February having at most
|
|
85
|
+
* 28 or 29 days) is not enforced here and must be handled at the application level if needed.
|
|
86
|
+
*
|
|
87
|
+
* @see {@link DAY_MIN}
|
|
88
|
+
* @see {@link assertDay}
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
declare const DAY_MAX = 31n;
|
|
92
|
+
/**
|
|
93
|
+
* Minimum valid hour value (inclusive), in 24-hour format.
|
|
94
|
+
*
|
|
95
|
+
* @see {@link HOUR_MAX}
|
|
96
|
+
* @see {@link assertHour}
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
declare const HOUR_MIN = 0n;
|
|
100
|
+
/**
|
|
101
|
+
* Maximum valid hour value (inclusive), in 24-hour format.
|
|
102
|
+
*
|
|
103
|
+
* @see {@link HOUR_MIN}
|
|
104
|
+
* @see {@link assertHour}
|
|
105
|
+
* @public
|
|
106
|
+
*/
|
|
107
|
+
declare const HOUR_MAX = 23n;
|
|
108
|
+
/**
|
|
109
|
+
* Minimum valid minute value (inclusive).
|
|
110
|
+
*
|
|
111
|
+
* @see {@link MINUTE_MAX}
|
|
112
|
+
* @see {@link assertMinute}
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
115
|
+
declare const MINUTE_MIN = 0n;
|
|
116
|
+
/**
|
|
117
|
+
* Maximum valid minute value (inclusive).
|
|
118
|
+
*
|
|
119
|
+
* @see {@link MINUTE_MIN}
|
|
120
|
+
* @see {@link assertMinute}
|
|
121
|
+
* @public
|
|
122
|
+
*/
|
|
123
|
+
declare const MINUTE_MAX = 59n;
|
|
124
|
+
/**
|
|
125
|
+
* Minimum valid second value (inclusive).
|
|
126
|
+
*
|
|
127
|
+
* @see {@link SECOND_MAX}
|
|
128
|
+
* @see {@link assertSecond}
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
131
|
+
declare const SECOND_MIN = 0n;
|
|
132
|
+
/**
|
|
133
|
+
* Maximum valid second value (inclusive).
|
|
134
|
+
*
|
|
135
|
+
* @remarks Leap seconds (value 60) are not supported.
|
|
136
|
+
* @see {@link SECOND_MIN}
|
|
137
|
+
* @see {@link assertSecond}
|
|
138
|
+
* @public
|
|
139
|
+
*/
|
|
140
|
+
declare const SECOND_MAX = 59n;
|
|
141
|
+
/**
|
|
142
|
+
* Error thrown when a temporal type assertion fails.
|
|
143
|
+
*
|
|
144
|
+
* This error provides detailed information about why an assertion failed,
|
|
145
|
+
* including the actual value, the expected type, and the constraint that
|
|
146
|
+
* was violated.
|
|
147
|
+
*
|
|
148
|
+
* @remarks
|
|
149
|
+
* Every `assertXxx` function in this module throws `TemporalAssertionError` on failure.
|
|
150
|
+
* Catch this specific type to distinguish temporal validation failures from other errors.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* import { assertMonth, TemporalAssertionError } from "./temporal";
|
|
155
|
+
*
|
|
156
|
+
* try {
|
|
157
|
+
* assertMonth(13n); // Will throw - month must be 1-12
|
|
158
|
+
* } catch (error) {
|
|
159
|
+
* if (error instanceof TemporalAssertionError) {
|
|
160
|
+
* console.error(`Assertion failed for ${error.expectedType}`);
|
|
161
|
+
* console.error(`Value: ${error.value}`);
|
|
162
|
+
* console.error(`Constraint: ${error.constraint}`);
|
|
163
|
+
* }
|
|
164
|
+
* }
|
|
165
|
+
* ```
|
|
166
|
+
*
|
|
167
|
+
* @sealed
|
|
168
|
+
* @public
|
|
169
|
+
*/
|
|
170
|
+
declare class TemporalAssertionError extends Error {
|
|
171
|
+
/**
|
|
172
|
+
* The actual value that failed the assertion.
|
|
173
|
+
* @readonly
|
|
174
|
+
*/
|
|
175
|
+
readonly value: unknown;
|
|
176
|
+
/**
|
|
177
|
+
* The type that was expected (e.g., `"Month"`, `"Hour"`).
|
|
178
|
+
* @readonly
|
|
179
|
+
*/
|
|
180
|
+
readonly expectedType: string;
|
|
181
|
+
/**
|
|
182
|
+
* Description of the constraint that was violated.
|
|
183
|
+
*
|
|
184
|
+
* @remarks
|
|
185
|
+
* `undefined` when the failure was a type mismatch (e.g., received a number instead of a
|
|
186
|
+
* bigint). Contains a human-readable range string (e.g., `"1 <= value <= 12"`) when the
|
|
187
|
+
* value was the correct type but out of the valid range.
|
|
188
|
+
* @readonly
|
|
189
|
+
*/
|
|
190
|
+
readonly constraint: string | undefined;
|
|
191
|
+
/**
|
|
192
|
+
* Creates a new TemporalAssertionError.
|
|
193
|
+
*
|
|
194
|
+
* @param message - Human-readable description of what went wrong
|
|
195
|
+
* @param details - Structured error details for programmatic inspection
|
|
196
|
+
* @param details.value - The value that failed the assertion
|
|
197
|
+
* @param details.expectedType - Name of the branded type that was expected
|
|
198
|
+
* @param details.constraint - Optional human-readable constraint that was violated
|
|
199
|
+
*/
|
|
200
|
+
constructor(message: string, details: {
|
|
201
|
+
value: unknown;
|
|
202
|
+
expectedType: string;
|
|
203
|
+
constraint?: string;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Base branded type for all timestamp components.
|
|
208
|
+
*
|
|
209
|
+
* `TimestampComponent` is a branded bigint that serves as the parent type for all
|
|
210
|
+
* calendar-component types: `Year`, `Month`, `Day`, `Hour`, `Minute`, and `Second`.
|
|
211
|
+
*
|
|
212
|
+
* @remarks
|
|
213
|
+
* All timestamp component types are subbrands of `TimestampComponent`. Code that accepts
|
|
214
|
+
* any calendar component without caring which one (e.g., a generic key-derivation utility)
|
|
215
|
+
* can accept `TimestampComponent` as its parameter type.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* import { TimestampComponent, assertTimestampComponent } from "./temporal";
|
|
220
|
+
*
|
|
221
|
+
* const value: bigint = 2024n;
|
|
222
|
+
* assertTimestampComponent(value);
|
|
223
|
+
* // Now value is typed as TimestampComponent
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @see {@link Year}
|
|
227
|
+
* @see {@link Month}
|
|
228
|
+
* @see {@link Day}
|
|
229
|
+
* @see {@link Hour}
|
|
230
|
+
* @see {@link Minute}
|
|
231
|
+
* @see {@link Second}
|
|
232
|
+
* @public
|
|
233
|
+
*/
|
|
234
|
+
type TimestampComponent = BrandedType<bigint, "TimestampComponent">;
|
|
235
|
+
/**
|
|
236
|
+
* Asserts that a value is a valid TimestampComponent (non-negative bigint).
|
|
237
|
+
*
|
|
238
|
+
* @param value - The bigint to validate (must be `>= 0`)
|
|
239
|
+
* @throws {TemporalAssertionError} If value is not a bigint or is negative
|
|
240
|
+
* @returns `void` — narrows the type of `value` to `TimestampComponent` on success
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const value = 100n;
|
|
245
|
+
* assertTimestampComponent(value);
|
|
246
|
+
* // value is now typed as TimestampComponent
|
|
247
|
+
* ```
|
|
248
|
+
*
|
|
249
|
+
* @public
|
|
250
|
+
*/
|
|
251
|
+
declare function assertTimestampComponent(value: bigint): asserts value is TimestampComponent;
|
|
252
|
+
/**
|
|
253
|
+
* Branded type for year values in the Gregorian calendar.
|
|
254
|
+
*
|
|
255
|
+
* `Year` is a subbrand of `TimestampComponent` used to represent the year component of a
|
|
256
|
+
* UTC timestamp in time-scoped viewing key derivation. Valid range: `YEAR_MIN` (0) to
|
|
257
|
+
* `YEAR_MAX` (9999).
|
|
258
|
+
*
|
|
259
|
+
* @remarks
|
|
260
|
+
* The type distinction between `Year`, `Month`, `Day`, etc. is intentional: passing
|
|
261
|
+
* a `Month` value where a `Year` is expected is a compile-time error, preventing
|
|
262
|
+
* subtle key-derivation bugs.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* import { Year, assertYear } from "./temporal";
|
|
267
|
+
*
|
|
268
|
+
* const year: bigint = 2024n;
|
|
269
|
+
* assertYear(year);
|
|
270
|
+
* // year is now typed as Year
|
|
271
|
+
*
|
|
272
|
+
* const generator = getYearlyViewingKeyGenerator({ masterViewingKey });
|
|
273
|
+
* const key = await generator(mint, year);
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
* @see {@link assertYear}
|
|
277
|
+
* @see {@link YEAR_MIN}
|
|
278
|
+
* @see {@link YEAR_MAX}
|
|
279
|
+
* @public
|
|
280
|
+
*/
|
|
281
|
+
type Year = SubBrandedType<TimestampComponent, "Year">;
|
|
282
|
+
/**
|
|
283
|
+
* Asserts that a value is a valid `Year` in the range `[YEAR_MIN, YEAR_MAX]` (0–9999).
|
|
284
|
+
*
|
|
285
|
+
* @param value - The bigint to validate
|
|
286
|
+
* @throws {TemporalAssertionError} If `value` is not a bigint or is outside `[YEAR_MIN, YEAR_MAX]`
|
|
287
|
+
* @returns `void` — narrows the type of `value` to `Year` on success
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```typescript
|
|
291
|
+
* const year = 2024n;
|
|
292
|
+
* assertYear(year);
|
|
293
|
+
* // year is now typed as Year
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* @public
|
|
297
|
+
*/
|
|
298
|
+
declare function assertYear(value: bigint): asserts value is Year;
|
|
299
|
+
/**
|
|
300
|
+
* Branded type for month values in the Gregorian calendar (1 = January, 12 = December).
|
|
301
|
+
*
|
|
302
|
+
* `Month` is a subbrand of `TimestampComponent`. Valid range: `MONTH_MIN` (1) to
|
|
303
|
+
* `MONTH_MAX` (12).
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* ```typescript
|
|
307
|
+
* import { Month, assertMonth } from "./temporal";
|
|
308
|
+
*
|
|
309
|
+
* const month: bigint = 6n; // June
|
|
310
|
+
* assertMonth(month);
|
|
311
|
+
* // month is now typed as Month
|
|
312
|
+
* ```
|
|
313
|
+
*
|
|
314
|
+
* @see {@link assertMonth}
|
|
315
|
+
* @see {@link MONTH_MIN}
|
|
316
|
+
* @see {@link MONTH_MAX}
|
|
317
|
+
* @public
|
|
318
|
+
*/
|
|
319
|
+
type Month = SubBrandedType<TimestampComponent, "Month">;
|
|
320
|
+
/**
|
|
321
|
+
* Asserts that a value is a valid `Month` in the range `[MONTH_MIN, MONTH_MAX]` (1–12).
|
|
322
|
+
*
|
|
323
|
+
* @param value - The bigint to validate
|
|
324
|
+
* @throws {TemporalAssertionError} If `value` is not a bigint or is outside `[MONTH_MIN, MONTH_MAX]`
|
|
325
|
+
* @returns `void` — narrows the type of `value` to `Month` on success
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```typescript
|
|
329
|
+
* const month = 6n;
|
|
330
|
+
* assertMonth(month);
|
|
331
|
+
* // month is now typed as Month
|
|
332
|
+
* ```
|
|
333
|
+
*
|
|
334
|
+
* @public
|
|
335
|
+
*/
|
|
336
|
+
declare function assertMonth(value: bigint): asserts value is Month;
|
|
337
|
+
/**
|
|
338
|
+
* Branded type for day-of-month values in the Gregorian calendar.
|
|
339
|
+
*
|
|
340
|
+
* `Day` is a subbrand of `TimestampComponent`. Valid range: `DAY_MIN` (1) to `DAY_MAX` (31).
|
|
341
|
+
*
|
|
342
|
+
* @remarks
|
|
343
|
+
* This type does not enforce month-specific day limits (e.g., February has 28 or 29 days).
|
|
344
|
+
* Additional calendar validation must be performed by the application if required.
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* ```typescript
|
|
348
|
+
* import { Day, assertDay } from "./temporal";
|
|
349
|
+
*
|
|
350
|
+
* const day: bigint = 15n;
|
|
351
|
+
* assertDay(day);
|
|
352
|
+
* // day is now typed as Day
|
|
353
|
+
* ```
|
|
354
|
+
*
|
|
355
|
+
* @see {@link assertDay}
|
|
356
|
+
* @see {@link DAY_MIN}
|
|
357
|
+
* @see {@link DAY_MAX}
|
|
358
|
+
* @public
|
|
359
|
+
*/
|
|
360
|
+
type Day = SubBrandedType<TimestampComponent, "Day">;
|
|
361
|
+
/**
|
|
362
|
+
* Asserts that a value is a valid `Day` in the range `[DAY_MIN, DAY_MAX]` (1–31).
|
|
363
|
+
*
|
|
364
|
+
* @param value - The bigint to validate
|
|
365
|
+
* @throws {TemporalAssertionError} If `value` is not a bigint or is outside `[DAY_MIN, DAY_MAX]`
|
|
366
|
+
* @returns `void` — narrows the type of `value` to `Day` on success
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```typescript
|
|
370
|
+
* const day = 15n;
|
|
371
|
+
* assertDay(day);
|
|
372
|
+
* // day is now typed as Day
|
|
373
|
+
* ```
|
|
374
|
+
*
|
|
375
|
+
* @public
|
|
376
|
+
*/
|
|
377
|
+
declare function assertDay(value: bigint): asserts value is Day;
|
|
378
|
+
/**
|
|
379
|
+
* Branded type for hour-of-day values in 24-hour format.
|
|
380
|
+
*
|
|
381
|
+
* `Hour` is a subbrand of `TimestampComponent`. Valid range: `HOUR_MIN` (0) to `HOUR_MAX` (23).
|
|
382
|
+
*
|
|
383
|
+
* @remarks
|
|
384
|
+
* Uses 24-hour clock convention: midnight is 0, noon is 12, and 11 PM is 23.
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* ```typescript
|
|
388
|
+
* import { Hour, assertHour } from "./temporal";
|
|
389
|
+
*
|
|
390
|
+
* const hour: bigint = 14n; // 2 PM
|
|
391
|
+
* assertHour(hour);
|
|
392
|
+
* // hour is now typed as Hour
|
|
393
|
+
* ```
|
|
394
|
+
*
|
|
395
|
+
* @see {@link assertHour}
|
|
396
|
+
* @see {@link HOUR_MIN}
|
|
397
|
+
* @see {@link HOUR_MAX}
|
|
398
|
+
* @public
|
|
399
|
+
*/
|
|
400
|
+
type Hour = SubBrandedType<TimestampComponent, "Hour">;
|
|
401
|
+
/**
|
|
402
|
+
* Asserts that a value is a valid `Hour` in the range `[HOUR_MIN, HOUR_MAX]` (0–23).
|
|
403
|
+
*
|
|
404
|
+
* @param value - The bigint to validate
|
|
405
|
+
* @throws {TemporalAssertionError} If `value` is not a bigint or is outside `[HOUR_MIN, HOUR_MAX]`
|
|
406
|
+
* @returns `void` — narrows the type of `value` to `Hour` on success
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```typescript
|
|
410
|
+
* const hour = 14n;
|
|
411
|
+
* assertHour(hour);
|
|
412
|
+
* // hour is now typed as Hour
|
|
413
|
+
* ```
|
|
414
|
+
*
|
|
415
|
+
* @public
|
|
416
|
+
*/
|
|
417
|
+
declare function assertHour(value: bigint): asserts value is Hour;
|
|
418
|
+
/**
|
|
419
|
+
* Branded type for minute-of-hour values.
|
|
420
|
+
*
|
|
421
|
+
* `Minute` is a subbrand of `TimestampComponent`. Valid range: `MINUTE_MIN` (0) to
|
|
422
|
+
* `MINUTE_MAX` (59).
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```typescript
|
|
426
|
+
* import { Minute, assertMinute } from "./temporal";
|
|
427
|
+
*
|
|
428
|
+
* const minute: bigint = 30n;
|
|
429
|
+
* assertMinute(minute);
|
|
430
|
+
* // minute is now typed as Minute
|
|
431
|
+
* ```
|
|
432
|
+
*
|
|
433
|
+
* @see {@link assertMinute}
|
|
434
|
+
* @see {@link MINUTE_MIN}
|
|
435
|
+
* @see {@link MINUTE_MAX}
|
|
436
|
+
* @public
|
|
437
|
+
*/
|
|
438
|
+
type Minute = SubBrandedType<TimestampComponent, "Minute">;
|
|
439
|
+
/**
|
|
440
|
+
* Asserts that a value is a valid `Minute` in the range `[MINUTE_MIN, MINUTE_MAX]` (0–59).
|
|
441
|
+
*
|
|
442
|
+
* @param value - The bigint to validate
|
|
443
|
+
* @throws {TemporalAssertionError} If `value` is not a bigint or is outside `[MINUTE_MIN, MINUTE_MAX]`
|
|
444
|
+
* @returns `void` — narrows the type of `value` to `Minute` on success
|
|
445
|
+
*
|
|
446
|
+
* @example
|
|
447
|
+
* ```typescript
|
|
448
|
+
* const minute = 30n;
|
|
449
|
+
* assertMinute(minute);
|
|
450
|
+
* // minute is now typed as Minute
|
|
451
|
+
* ```
|
|
452
|
+
*
|
|
453
|
+
* @public
|
|
454
|
+
*/
|
|
455
|
+
declare function assertMinute(value: bigint): asserts value is Minute;
|
|
456
|
+
/**
|
|
457
|
+
* Branded type for second-of-minute values.
|
|
458
|
+
*
|
|
459
|
+
* `Second` is a subbrand of `TimestampComponent`. Valid range: `SECOND_MIN` (0) to
|
|
460
|
+
* `SECOND_MAX` (59). Leap seconds (value 60) are not supported.
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* ```typescript
|
|
464
|
+
* import { Second, assertSecond } from "./temporal";
|
|
465
|
+
*
|
|
466
|
+
* const second: bigint = 45n;
|
|
467
|
+
* assertSecond(second);
|
|
468
|
+
* // second is now typed as Second
|
|
469
|
+
* ```
|
|
470
|
+
*
|
|
471
|
+
* @see {@link assertSecond}
|
|
472
|
+
* @see {@link SECOND_MIN}
|
|
473
|
+
* @see {@link SECOND_MAX}
|
|
474
|
+
* @public
|
|
475
|
+
*/
|
|
476
|
+
type Second = SubBrandedType<TimestampComponent, "Second">;
|
|
477
|
+
/**
|
|
478
|
+
* Asserts that a value is a valid `Second` in the range `[SECOND_MIN, SECOND_MAX]` (0–59).
|
|
479
|
+
*
|
|
480
|
+
* @param value - The bigint to validate
|
|
481
|
+
* @throws {TemporalAssertionError} If `value` is not a bigint or is outside `[SECOND_MIN, SECOND_MAX]`
|
|
482
|
+
* @returns `void` — narrows the type of `value` to `Second` on success
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```typescript
|
|
486
|
+
* const second = 45n;
|
|
487
|
+
* assertSecond(second);
|
|
488
|
+
* // second is now typed as Second
|
|
489
|
+
* ```
|
|
490
|
+
*
|
|
491
|
+
* @public
|
|
492
|
+
*/
|
|
493
|
+
declare function assertSecond(value: bigint): asserts value is Second;
|
|
494
|
+
|
|
495
|
+
export { type Day as D, type Hour as H, type Month as M, type Second as S, TemporalAssertionError as T, type Year as Y, type Minute as a, DAY_MAX as b, DAY_MIN as c, HOUR_MAX as d, HOUR_MIN as e, MINUTE_MAX as f, MINUTE_MIN as g, MONTH_MAX as h, MONTH_MIN as i, SECOND_MAX as j, SECOND_MIN as k, type TimestampComponent as l, YEAR_MAX as m, YEAR_MIN as n, assertDay as o, assertHour as p, assertMinute as q, assertMonth as r, assertSecond as s, assertTimestampComponent as t, assertYear as u };
|