ccusage 16.2.5 → 17.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/README.md +20 -25
- package/config-schema.json +0 -33
- package/dist/_types-CV6z8-9_.js +583 -0
- package/dist/{calculate-cost-BDqO4yWA.js → calculate-cost-CX9KwEZt.js} +1 -1
- package/dist/calculate-cost.d.ts +1 -4
- package/dist/calculate-cost.js +2 -3
- package/dist/data-loader-DQtk3Va0.js +3733 -0
- package/dist/data-loader-D_hlygEz.d.ts +2307 -0
- package/dist/data-loader.d.ts +1 -2
- package/dist/data-loader.js +3 -5
- package/dist/debug-Bn_uiKiR.js +148 -0
- package/dist/debug.d.ts +8 -0
- package/dist/debug.js +4 -6
- package/dist/index.d.ts +0 -0
- package/dist/index.js +2838 -2065
- package/dist/{logger-wHijzbnK.js → logger-1M8m84B7.js} +179 -74
- package/dist/logger.d.ts +11 -7
- package/dist/logger.js +1 -1
- package/dist/{prompt-DsUFNEY7.js → prompt-BeRmYuGP.js} +49 -28
- package/package.json +4 -4
- package/dist/_token-utils-WjkbrjKv.js +0 -5
- package/dist/_types-DIdtMJ6V.js +0 -3076
- package/dist/data-loader-D1FVB4Lp.d.ts +0 -785
- package/dist/data-loader-abvRdQYo.js +0 -2681
- package/dist/debug-CkCfHFil.js +0 -109
- package/dist/mcp-Dz21qUWi.js +0 -6832
- package/dist/mcp.d.ts +0 -35
- package/dist/mcp.js +0 -8
- package/dist/pricing-fetcher-BtUY4dRM.js +0 -402
- package/dist/pricing-fetcher-DK8lcI1w.d.ts +0 -219
- package/dist/pricing-fetcher.d.ts +0 -2
- package/dist/pricing-fetcher.js +0 -4
|
@@ -0,0 +1,2307 @@
|
|
|
1
|
+
//#region src/_consts.d.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Days of the week for weekly aggregation
|
|
5
|
+
*/
|
|
6
|
+
declare const WEEK_DAYS: readonly ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
7
|
+
/**
|
|
8
|
+
* Week day names type
|
|
9
|
+
*/
|
|
10
|
+
type WeekDay = typeof WEEK_DAYS[number];
|
|
11
|
+
/**
|
|
12
|
+
* Day of week as number (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
|
|
13
|
+
*/
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/_session-blocks.d.ts
|
|
16
|
+
/**
|
|
17
|
+
* Represents a single usage data entry loaded from JSONL files
|
|
18
|
+
*/
|
|
19
|
+
type LoadedUsageEntry = {
|
|
20
|
+
timestamp: Date;
|
|
21
|
+
usage: {
|
|
22
|
+
inputTokens: number;
|
|
23
|
+
outputTokens: number;
|
|
24
|
+
cacheCreationInputTokens: number;
|
|
25
|
+
cacheReadInputTokens: number;
|
|
26
|
+
};
|
|
27
|
+
costUSD: number | null;
|
|
28
|
+
model: string;
|
|
29
|
+
version?: string;
|
|
30
|
+
usageLimitResetTime?: Date;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Aggregated token counts for different token types
|
|
34
|
+
*/
|
|
35
|
+
type TokenCounts = {
|
|
36
|
+
inputTokens: number;
|
|
37
|
+
outputTokens: number;
|
|
38
|
+
cacheCreationInputTokens: number;
|
|
39
|
+
cacheReadInputTokens: number;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Represents a session block (typically 5-hour billing period) with usage data
|
|
43
|
+
*/
|
|
44
|
+
type SessionBlock = {
|
|
45
|
+
id: string;
|
|
46
|
+
startTime: Date;
|
|
47
|
+
endTime: Date;
|
|
48
|
+
actualEndTime?: Date;
|
|
49
|
+
isActive: boolean;
|
|
50
|
+
isGap?: boolean;
|
|
51
|
+
entries: LoadedUsageEntry[];
|
|
52
|
+
tokenCounts: TokenCounts;
|
|
53
|
+
costUSD: number;
|
|
54
|
+
models: string[];
|
|
55
|
+
usageLimitResetTime?: Date;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Represents usage burn rate calculations
|
|
59
|
+
*/
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/observable-like.d.ts
|
|
62
|
+
declare global {
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
64
|
+
interface SymbolConstructor {
|
|
65
|
+
readonly observable: symbol;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
@remarks
|
|
71
|
+
The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021.
|
|
72
|
+
As well, some guidance on making an `Observable` to not include `closed` property.
|
|
73
|
+
@see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130
|
|
74
|
+
@see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85
|
|
75
|
+
@see https://github.com/benlesh/symbol-observable#making-an-object-observable
|
|
76
|
+
|
|
77
|
+
@category Observable
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/tuple-to-union.d.ts
|
|
82
|
+
/**
|
|
83
|
+
Convert a tuple/array into a union type of its elements.
|
|
84
|
+
|
|
85
|
+
This can be useful when you have a fixed set of allowed values and want a type defining only the allowed values, but do not want to repeat yourself.
|
|
86
|
+
|
|
87
|
+
@example
|
|
88
|
+
```
|
|
89
|
+
import type {TupleToUnion} from 'type-fest';
|
|
90
|
+
|
|
91
|
+
const destinations = ['a', 'b', 'c'] as const;
|
|
92
|
+
|
|
93
|
+
type Destination = TupleToUnion<typeof destinations>;
|
|
94
|
+
//=> 'a' | 'b' | 'c'
|
|
95
|
+
|
|
96
|
+
function verifyDestination(destination: unknown): destination is Destination {
|
|
97
|
+
return destinations.includes(destination as any);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
type RequestBody = {
|
|
101
|
+
deliverTo: Destination;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
function verifyRequestBody(body: unknown): body is RequestBody {
|
|
105
|
+
const deliverTo = (body as any).deliverTo;
|
|
106
|
+
return typeof body === 'object' && body !== null && verifyDestination(deliverTo);
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Alternatively, you may use `typeof destinations[number]`. If `destinations` is a tuple, there is no difference. However if `destinations` is a string, the resulting type will the union of the characters in the string. Other types of `destinations` may result in a compile error. In comparison, TupleToUnion will return `never` if a tuple is not provided.
|
|
111
|
+
|
|
112
|
+
@example
|
|
113
|
+
```
|
|
114
|
+
const destinations = ['a', 'b', 'c'] as const;
|
|
115
|
+
|
|
116
|
+
type Destination = typeof destinations[number];
|
|
117
|
+
//=> 'a' | 'b' | 'c'
|
|
118
|
+
|
|
119
|
+
const erroringType = new Set(['a', 'b', 'c']);
|
|
120
|
+
|
|
121
|
+
type ErroringType = typeof erroringType[number];
|
|
122
|
+
//=> Type 'Set<string>' has no matching index signature for type 'number'. ts(2537)
|
|
123
|
+
|
|
124
|
+
const numberBool: { [n: number]: boolean } = { 1: true };
|
|
125
|
+
|
|
126
|
+
type NumberBool = typeof numberBool[number];
|
|
127
|
+
//=> boolean
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
@category Array
|
|
131
|
+
*/
|
|
132
|
+
type TupleToUnion<ArrayType> = ArrayType extends readonly unknown[] ? ArrayType[number] : never;
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region ../../node_modules/.pnpm/valibot@1.1.0_typescript@5.9.2/node_modules/valibot/dist/index.d.ts
|
|
135
|
+
/**
|
|
136
|
+
* Fallback type.
|
|
137
|
+
*/
|
|
138
|
+
type Fallback<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>> = MaybeReadonly<InferOutput<TSchema>> | ((dataset?: OutputDataset<InferOutput<TSchema>, InferIssue<TSchema>>, config?: Config<InferIssue<TSchema>>) => MaybeReadonly<InferOutput<TSchema>>);
|
|
139
|
+
/**
|
|
140
|
+
* Schema with fallback type.
|
|
141
|
+
*/
|
|
142
|
+
type SchemaWithFallback<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TFallback extends Fallback<TSchema>> = TSchema & {
|
|
143
|
+
/**
|
|
144
|
+
* The fallback value.
|
|
145
|
+
*/
|
|
146
|
+
readonly fallback: TFallback;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Returns a fallback value as output if the input does not match the schema.
|
|
150
|
+
*
|
|
151
|
+
* @param schema The schema to catch.
|
|
152
|
+
* @param fallback The fallback value.
|
|
153
|
+
*
|
|
154
|
+
* @returns The passed schema.
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Fallback async type.
|
|
159
|
+
*/
|
|
160
|
+
type FallbackAsync<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>> = MaybeReadonly<InferOutput<TSchema>> | ((dataset?: OutputDataset<InferOutput<TSchema>, InferIssue<TSchema>>, config?: Config<InferIssue<TSchema>>) => MaybePromise<MaybeReadonly<InferOutput<TSchema>>>);
|
|
161
|
+
/**
|
|
162
|
+
* Schema with fallback async type.
|
|
163
|
+
*/
|
|
164
|
+
type SchemaWithFallbackAsync<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TFallback extends FallbackAsync<TSchema>> = Omit<TSchema, 'async' | '~standard' | '~run'> & {
|
|
165
|
+
/**
|
|
166
|
+
* The fallback value.
|
|
167
|
+
*/
|
|
168
|
+
readonly fallback: TFallback;
|
|
169
|
+
/**
|
|
170
|
+
* Whether it's async.
|
|
171
|
+
*/
|
|
172
|
+
readonly async: true;
|
|
173
|
+
/**
|
|
174
|
+
* The Standard Schema properties.
|
|
175
|
+
*
|
|
176
|
+
* @internal
|
|
177
|
+
*/
|
|
178
|
+
readonly '~standard': StandardProps<InferInput<TSchema>, InferOutput<TSchema>>;
|
|
179
|
+
/**
|
|
180
|
+
* Parses unknown input values.
|
|
181
|
+
*
|
|
182
|
+
* @param dataset The input dataset.
|
|
183
|
+
* @param config The configuration.
|
|
184
|
+
*
|
|
185
|
+
* @returns The output dataset.
|
|
186
|
+
*
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
readonly '~run': (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<InferOutput<TSchema>, InferIssue<TSchema>>>;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Returns a fallback value as output if the input does not match the schema.
|
|
193
|
+
*
|
|
194
|
+
* @param schema The schema to catch.
|
|
195
|
+
* @param fallback The fallback value.
|
|
196
|
+
*
|
|
197
|
+
* @returns The passed schema.
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Schema with pipe type.
|
|
202
|
+
*/
|
|
203
|
+
type SchemaWithPipe<TPipe extends readonly [BaseSchema<unknown, unknown, BaseIssue<unknown>>, ...PipeItem<any, unknown, BaseIssue<unknown>>[]]> = Omit<FirstTupleItem<TPipe>, 'pipe' | '~standard' | '~run' | '~types'> & {
|
|
204
|
+
/**
|
|
205
|
+
* The pipe items.
|
|
206
|
+
*/
|
|
207
|
+
readonly pipe: TPipe;
|
|
208
|
+
/**
|
|
209
|
+
* The Standard Schema properties.
|
|
210
|
+
*
|
|
211
|
+
* @internal
|
|
212
|
+
*/
|
|
213
|
+
readonly '~standard': StandardProps<InferInput<FirstTupleItem<TPipe>>, InferOutput<LastTupleItem<TPipe>>>;
|
|
214
|
+
/**
|
|
215
|
+
* Parses unknown input values.
|
|
216
|
+
*
|
|
217
|
+
* @param dataset The input dataset.
|
|
218
|
+
* @param config The configuration.
|
|
219
|
+
*
|
|
220
|
+
* @returns The output dataset.
|
|
221
|
+
*
|
|
222
|
+
* @internal
|
|
223
|
+
*/
|
|
224
|
+
readonly '~run': (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => OutputDataset<InferOutput<LastTupleItem<TPipe>>, InferIssue<TPipe[number]>>;
|
|
225
|
+
/**
|
|
226
|
+
* The input, output and issue type.
|
|
227
|
+
*
|
|
228
|
+
* @internal
|
|
229
|
+
*/
|
|
230
|
+
readonly '~types'?: {
|
|
231
|
+
readonly input: InferInput<FirstTupleItem<TPipe>>;
|
|
232
|
+
readonly output: InferOutput<LastTupleItem<TPipe>>;
|
|
233
|
+
readonly issue: InferIssue<TPipe[number]>;
|
|
234
|
+
} | undefined;
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Adds a pipeline to a schema, that can validate and transform its input.
|
|
238
|
+
*
|
|
239
|
+
* @param schema The root schema.
|
|
240
|
+
* @param item1 The first pipe item.
|
|
241
|
+
*
|
|
242
|
+
* @returns A schema with a pipeline.
|
|
243
|
+
*/
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Schema with pipe async type.
|
|
247
|
+
*/
|
|
248
|
+
type SchemaWithPipeAsync<TPipe extends readonly [(BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>), ...(PipeItem<any, unknown, BaseIssue<unknown>> | PipeItemAsync<any, unknown, BaseIssue<unknown>>)[]]> = Omit<FirstTupleItem<TPipe>, 'async' | 'pipe' | '~standard' | '~run' | '~types'> & {
|
|
249
|
+
/**
|
|
250
|
+
* The pipe items.
|
|
251
|
+
*/
|
|
252
|
+
readonly pipe: TPipe;
|
|
253
|
+
/**
|
|
254
|
+
* Whether it's async.
|
|
255
|
+
*/
|
|
256
|
+
readonly async: true;
|
|
257
|
+
/**
|
|
258
|
+
* The Standard Schema properties.
|
|
259
|
+
*
|
|
260
|
+
* @internal
|
|
261
|
+
*/
|
|
262
|
+
readonly '~standard': StandardProps<InferInput<FirstTupleItem<TPipe>>, InferOutput<LastTupleItem<TPipe>>>;
|
|
263
|
+
/**
|
|
264
|
+
* Parses unknown input values.
|
|
265
|
+
*
|
|
266
|
+
* @param dataset The input dataset.
|
|
267
|
+
* @param config The configuration.
|
|
268
|
+
*
|
|
269
|
+
* @returns The output dataset.
|
|
270
|
+
*
|
|
271
|
+
* @internal
|
|
272
|
+
*/
|
|
273
|
+
readonly '~run': (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<InferOutput<LastTupleItem<TPipe>>, InferIssue<TPipe[number]>>>;
|
|
274
|
+
/**
|
|
275
|
+
* The input, output and issue type.
|
|
276
|
+
*
|
|
277
|
+
* @internal
|
|
278
|
+
*/
|
|
279
|
+
readonly '~types'?: {
|
|
280
|
+
readonly input: InferInput<FirstTupleItem<TPipe>>;
|
|
281
|
+
readonly output: InferOutput<LastTupleItem<TPipe>>;
|
|
282
|
+
readonly issue: InferIssue<TPipe[number]>;
|
|
283
|
+
} | undefined;
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Adds a pipeline to a schema, that can validate and transform its input.
|
|
287
|
+
*
|
|
288
|
+
* @param schema The root schema.
|
|
289
|
+
* @param item1 The first pipe item.
|
|
290
|
+
*
|
|
291
|
+
* @returns A schema with a pipeline.
|
|
292
|
+
*/
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Base metadata interface.
|
|
296
|
+
*/
|
|
297
|
+
interface BaseMetadata<TInput> {
|
|
298
|
+
/**
|
|
299
|
+
* The object kind.
|
|
300
|
+
*/
|
|
301
|
+
readonly kind: 'metadata';
|
|
302
|
+
/**
|
|
303
|
+
* The metadata type.
|
|
304
|
+
*/
|
|
305
|
+
readonly type: string;
|
|
306
|
+
/**
|
|
307
|
+
* The metadata reference.
|
|
308
|
+
*/
|
|
309
|
+
readonly reference: (...args: any[]) => BaseMetadata<any>;
|
|
310
|
+
/**
|
|
311
|
+
* The input, output and issue type.
|
|
312
|
+
*
|
|
313
|
+
* @internal
|
|
314
|
+
*/
|
|
315
|
+
readonly '~types'?: {
|
|
316
|
+
readonly input: TInput;
|
|
317
|
+
readonly output: TInput;
|
|
318
|
+
readonly issue: never;
|
|
319
|
+
} | undefined;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Generic metadata type.
|
|
323
|
+
*/
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Unknown dataset interface.
|
|
327
|
+
*/
|
|
328
|
+
interface UnknownDataset {
|
|
329
|
+
/**
|
|
330
|
+
* Whether is's typed.
|
|
331
|
+
*/
|
|
332
|
+
typed?: false;
|
|
333
|
+
/**
|
|
334
|
+
* The dataset value.
|
|
335
|
+
*/
|
|
336
|
+
value: unknown;
|
|
337
|
+
/**
|
|
338
|
+
* The dataset issues.
|
|
339
|
+
*/
|
|
340
|
+
issues?: undefined;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Success dataset interface.
|
|
344
|
+
*/
|
|
345
|
+
interface SuccessDataset<TValue> {
|
|
346
|
+
/**
|
|
347
|
+
* Whether is's typed.
|
|
348
|
+
*/
|
|
349
|
+
typed: true;
|
|
350
|
+
/**
|
|
351
|
+
* The dataset value.
|
|
352
|
+
*/
|
|
353
|
+
value: TValue;
|
|
354
|
+
/**
|
|
355
|
+
* The dataset issues.
|
|
356
|
+
*/
|
|
357
|
+
issues?: undefined;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Partial dataset interface.
|
|
361
|
+
*/
|
|
362
|
+
interface PartialDataset<TValue, TIssue extends BaseIssue<unknown>> {
|
|
363
|
+
/**
|
|
364
|
+
* Whether is's typed.
|
|
365
|
+
*/
|
|
366
|
+
typed: true;
|
|
367
|
+
/**
|
|
368
|
+
* The dataset value.
|
|
369
|
+
*/
|
|
370
|
+
value: TValue;
|
|
371
|
+
/**
|
|
372
|
+
* The dataset issues.
|
|
373
|
+
*/
|
|
374
|
+
issues: [TIssue, ...TIssue[]];
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Failure dataset interface.
|
|
378
|
+
*/
|
|
379
|
+
interface FailureDataset<TIssue extends BaseIssue<unknown>> {
|
|
380
|
+
/**
|
|
381
|
+
* Whether is's typed.
|
|
382
|
+
*/
|
|
383
|
+
typed: false;
|
|
384
|
+
/**
|
|
385
|
+
* The dataset value.
|
|
386
|
+
*/
|
|
387
|
+
value: unknown;
|
|
388
|
+
/**
|
|
389
|
+
* The dataset issues.
|
|
390
|
+
*/
|
|
391
|
+
issues: [TIssue, ...TIssue[]];
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Output dataset type.
|
|
395
|
+
*/
|
|
396
|
+
type OutputDataset<TValue, TIssue extends BaseIssue<unknown>> = SuccessDataset<TValue> | PartialDataset<TValue, TIssue> | FailureDataset<TIssue>;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* The Standard Schema properties interface.
|
|
400
|
+
*/
|
|
401
|
+
interface StandardProps<TInput, TOutput> {
|
|
402
|
+
/**
|
|
403
|
+
* The version number of the standard.
|
|
404
|
+
*/
|
|
405
|
+
readonly version: 1;
|
|
406
|
+
/**
|
|
407
|
+
* The vendor name of the schema library.
|
|
408
|
+
*/
|
|
409
|
+
readonly vendor: 'valibot';
|
|
410
|
+
/**
|
|
411
|
+
* Validates unknown input values.
|
|
412
|
+
*/
|
|
413
|
+
readonly validate: (value: unknown) => StandardResult<TOutput> | Promise<StandardResult<TOutput>>;
|
|
414
|
+
/**
|
|
415
|
+
* Inferred types associated with the schema.
|
|
416
|
+
*/
|
|
417
|
+
readonly types?: StandardTypes<TInput, TOutput> | undefined;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* The result interface of the validate function.
|
|
421
|
+
*/
|
|
422
|
+
type StandardResult<TOutput> = StandardSuccessResult<TOutput> | StandardFailureResult;
|
|
423
|
+
/**
|
|
424
|
+
* The result interface if validation succeeds.
|
|
425
|
+
*/
|
|
426
|
+
interface StandardSuccessResult<TOutput> {
|
|
427
|
+
/**
|
|
428
|
+
* The typed output value.
|
|
429
|
+
*/
|
|
430
|
+
readonly value: TOutput;
|
|
431
|
+
/**
|
|
432
|
+
* The non-existent issues.
|
|
433
|
+
*/
|
|
434
|
+
readonly issues?: undefined;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* The result interface if validation fails.
|
|
438
|
+
*/
|
|
439
|
+
interface StandardFailureResult {
|
|
440
|
+
/**
|
|
441
|
+
* The issues of failed validation.
|
|
442
|
+
*/
|
|
443
|
+
readonly issues: readonly StandardIssue[];
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* The issue interface of the failure output.
|
|
447
|
+
*/
|
|
448
|
+
interface StandardIssue {
|
|
449
|
+
/**
|
|
450
|
+
* The error message of the issue.
|
|
451
|
+
*/
|
|
452
|
+
readonly message: string;
|
|
453
|
+
/**
|
|
454
|
+
* The path of the issue, if any.
|
|
455
|
+
*/
|
|
456
|
+
readonly path?: readonly (PropertyKey | StandardPathItem)[] | undefined;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* The path item interface of the issue.
|
|
460
|
+
*/
|
|
461
|
+
interface StandardPathItem {
|
|
462
|
+
/**
|
|
463
|
+
* The key of the path item.
|
|
464
|
+
*/
|
|
465
|
+
readonly key: PropertyKey;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* The Standard Schema types interface.
|
|
469
|
+
*/
|
|
470
|
+
interface StandardTypes<TInput, TOutput> {
|
|
471
|
+
/**
|
|
472
|
+
* The input type of the schema.
|
|
473
|
+
*/
|
|
474
|
+
readonly input: TInput;
|
|
475
|
+
/**
|
|
476
|
+
* The output type of the schema.
|
|
477
|
+
*/
|
|
478
|
+
readonly output: TOutput;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Base schema interface.
|
|
483
|
+
*/
|
|
484
|
+
interface BaseSchema<TInput, TOutput, TIssue extends BaseIssue<unknown>> {
|
|
485
|
+
/**
|
|
486
|
+
* The object kind.
|
|
487
|
+
*/
|
|
488
|
+
readonly kind: 'schema';
|
|
489
|
+
/**
|
|
490
|
+
* The schema type.
|
|
491
|
+
*/
|
|
492
|
+
readonly type: string;
|
|
493
|
+
/**
|
|
494
|
+
* The schema reference.
|
|
495
|
+
*/
|
|
496
|
+
readonly reference: (...args: any[]) => BaseSchema<unknown, unknown, BaseIssue<unknown>>;
|
|
497
|
+
/**
|
|
498
|
+
* The expected property.
|
|
499
|
+
*/
|
|
500
|
+
readonly expects: string;
|
|
501
|
+
/**
|
|
502
|
+
* Whether it's async.
|
|
503
|
+
*/
|
|
504
|
+
readonly async: false;
|
|
505
|
+
/**
|
|
506
|
+
* The Standard Schema properties.
|
|
507
|
+
*
|
|
508
|
+
* @internal
|
|
509
|
+
*/
|
|
510
|
+
readonly '~standard': StandardProps<TInput, TOutput>;
|
|
511
|
+
/**
|
|
512
|
+
* Parses unknown input values.
|
|
513
|
+
*
|
|
514
|
+
* @param dataset The input dataset.
|
|
515
|
+
* @param config The configuration.
|
|
516
|
+
*
|
|
517
|
+
* @returns The output dataset.
|
|
518
|
+
*
|
|
519
|
+
* @internal
|
|
520
|
+
*/
|
|
521
|
+
readonly '~run': (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => OutputDataset<TOutput, TIssue>;
|
|
522
|
+
/**
|
|
523
|
+
* The input, output and issue type.
|
|
524
|
+
*
|
|
525
|
+
* @internal
|
|
526
|
+
*/
|
|
527
|
+
readonly '~types'?: {
|
|
528
|
+
readonly input: TInput;
|
|
529
|
+
readonly output: TOutput;
|
|
530
|
+
readonly issue: TIssue;
|
|
531
|
+
} | undefined;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Base schema async interface.
|
|
535
|
+
*/
|
|
536
|
+
interface BaseSchemaAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> extends Omit<BaseSchema<TInput, TOutput, TIssue>, 'reference' | 'async' | '~run'> {
|
|
537
|
+
/**
|
|
538
|
+
* The schema reference.
|
|
539
|
+
*/
|
|
540
|
+
readonly reference: (...args: any[]) => BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>;
|
|
541
|
+
/**
|
|
542
|
+
* Whether it's async.
|
|
543
|
+
*/
|
|
544
|
+
readonly async: true;
|
|
545
|
+
/**
|
|
546
|
+
* Parses unknown input values.
|
|
547
|
+
*
|
|
548
|
+
* @param dataset The input dataset.
|
|
549
|
+
* @param config The configuration.
|
|
550
|
+
*
|
|
551
|
+
* @returns The output dataset.
|
|
552
|
+
*
|
|
553
|
+
* @internal
|
|
554
|
+
*/
|
|
555
|
+
readonly '~run': (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<TOutput, TIssue>>;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Generic schema type.
|
|
559
|
+
*/
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Base transformation interface.
|
|
563
|
+
*/
|
|
564
|
+
interface BaseTransformation<TInput, TOutput, TIssue extends BaseIssue<unknown>> {
|
|
565
|
+
/**
|
|
566
|
+
* The object kind.
|
|
567
|
+
*/
|
|
568
|
+
readonly kind: 'transformation';
|
|
569
|
+
/**
|
|
570
|
+
* The transformation type.
|
|
571
|
+
*/
|
|
572
|
+
readonly type: string;
|
|
573
|
+
/**
|
|
574
|
+
* The transformation reference.
|
|
575
|
+
*/
|
|
576
|
+
readonly reference: (...args: any[]) => BaseTransformation<any, any, BaseIssue<unknown>>;
|
|
577
|
+
/**
|
|
578
|
+
* Whether it's async.
|
|
579
|
+
*/
|
|
580
|
+
readonly async: false;
|
|
581
|
+
/**
|
|
582
|
+
* Transforms known input values.
|
|
583
|
+
*
|
|
584
|
+
* @param dataset The input dataset.
|
|
585
|
+
* @param config The configuration.
|
|
586
|
+
*
|
|
587
|
+
* @returns The output dataset.
|
|
588
|
+
*
|
|
589
|
+
* @internal
|
|
590
|
+
*/
|
|
591
|
+
readonly '~run': (dataset: SuccessDataset<TInput>, config: Config<BaseIssue<unknown>>) => OutputDataset<TOutput, BaseIssue<unknown> | TIssue>;
|
|
592
|
+
/**
|
|
593
|
+
* The input, output and issue type.
|
|
594
|
+
*
|
|
595
|
+
* @internal
|
|
596
|
+
*/
|
|
597
|
+
readonly '~types'?: {
|
|
598
|
+
readonly input: TInput;
|
|
599
|
+
readonly output: TOutput;
|
|
600
|
+
readonly issue: TIssue;
|
|
601
|
+
} | undefined;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Base transformation async interface.
|
|
605
|
+
*/
|
|
606
|
+
interface BaseTransformationAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> extends Omit<BaseTransformation<TInput, TOutput, TIssue>, 'reference' | 'async' | '~run'> {
|
|
607
|
+
/**
|
|
608
|
+
* The transformation reference.
|
|
609
|
+
*/
|
|
610
|
+
readonly reference: (...args: any[]) => BaseTransformation<any, any, BaseIssue<unknown>> | BaseTransformationAsync<any, any, BaseIssue<unknown>>;
|
|
611
|
+
/**
|
|
612
|
+
* Whether it's async.
|
|
613
|
+
*/
|
|
614
|
+
readonly async: true;
|
|
615
|
+
/**
|
|
616
|
+
* Transforms known input values.
|
|
617
|
+
*
|
|
618
|
+
* @param dataset The input dataset.
|
|
619
|
+
* @param config The configuration.
|
|
620
|
+
*
|
|
621
|
+
* @returns The output dataset.
|
|
622
|
+
*
|
|
623
|
+
* @internal
|
|
624
|
+
*/
|
|
625
|
+
readonly '~run': (dataset: SuccessDataset<TInput>, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<TOutput, BaseIssue<unknown> | TIssue>>;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Generic transformation type.
|
|
629
|
+
*/
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Base validation interface.
|
|
633
|
+
*/
|
|
634
|
+
interface BaseValidation<TInput, TOutput, TIssue extends BaseIssue<unknown>> {
|
|
635
|
+
/**
|
|
636
|
+
* The object kind.
|
|
637
|
+
*/
|
|
638
|
+
readonly kind: 'validation';
|
|
639
|
+
/**
|
|
640
|
+
* The validation type.
|
|
641
|
+
*/
|
|
642
|
+
readonly type: string;
|
|
643
|
+
/**
|
|
644
|
+
* The validation reference.
|
|
645
|
+
*/
|
|
646
|
+
readonly reference: (...args: any[]) => BaseValidation<any, any, BaseIssue<unknown>>;
|
|
647
|
+
/**
|
|
648
|
+
* The expected property.
|
|
649
|
+
*/
|
|
650
|
+
readonly expects: string | null;
|
|
651
|
+
/**
|
|
652
|
+
* Whether it's async.
|
|
653
|
+
*/
|
|
654
|
+
readonly async: false;
|
|
655
|
+
/**
|
|
656
|
+
* Validates known input values.
|
|
657
|
+
*
|
|
658
|
+
* @param dataset The input dataset.
|
|
659
|
+
* @param config The configuration.
|
|
660
|
+
*
|
|
661
|
+
* @returns The output dataset.
|
|
662
|
+
*
|
|
663
|
+
* @internal
|
|
664
|
+
*/
|
|
665
|
+
readonly '~run': (dataset: OutputDataset<TInput, BaseIssue<unknown>>, config: Config<BaseIssue<unknown>>) => OutputDataset<TOutput, BaseIssue<unknown> | TIssue>;
|
|
666
|
+
/**
|
|
667
|
+
* The input, output and issue type.
|
|
668
|
+
*
|
|
669
|
+
* @internal
|
|
670
|
+
*/
|
|
671
|
+
readonly '~types'?: {
|
|
672
|
+
readonly input: TInput;
|
|
673
|
+
readonly output: TOutput;
|
|
674
|
+
readonly issue: TIssue;
|
|
675
|
+
} | undefined;
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Base validation async interface.
|
|
679
|
+
*/
|
|
680
|
+
interface BaseValidationAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> extends Omit<BaseValidation<TInput, TOutput, TIssue>, 'reference' | 'async' | '~run'> {
|
|
681
|
+
/**
|
|
682
|
+
* The validation reference.
|
|
683
|
+
*/
|
|
684
|
+
readonly reference: (...args: any[]) => BaseValidation<any, any, BaseIssue<unknown>> | BaseValidationAsync<any, any, BaseIssue<unknown>>;
|
|
685
|
+
/**
|
|
686
|
+
* Whether it's async.
|
|
687
|
+
*/
|
|
688
|
+
readonly async: true;
|
|
689
|
+
/**
|
|
690
|
+
* Validates known input values.
|
|
691
|
+
*
|
|
692
|
+
* @param dataset The input dataset.
|
|
693
|
+
* @param config The configuration.
|
|
694
|
+
*
|
|
695
|
+
* @returns The output dataset.
|
|
696
|
+
*
|
|
697
|
+
* @internal
|
|
698
|
+
*/
|
|
699
|
+
readonly '~run': (dataset: OutputDataset<TInput, BaseIssue<unknown>>, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<TOutput, BaseIssue<unknown> | TIssue>>;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Generic validation type.
|
|
703
|
+
*/
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Infer input type.
|
|
707
|
+
*/
|
|
708
|
+
type InferInput<TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>> | BaseValidation<any, unknown, BaseIssue<unknown>> | BaseValidationAsync<any, unknown, BaseIssue<unknown>> | BaseTransformation<any, unknown, BaseIssue<unknown>> | BaseTransformationAsync<any, unknown, BaseIssue<unknown>> | BaseMetadata<any>> = NonNullable<TItem['~types']>['input'];
|
|
709
|
+
/**
|
|
710
|
+
* Infer output type.
|
|
711
|
+
*/
|
|
712
|
+
type InferOutput<TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>> | BaseValidation<any, unknown, BaseIssue<unknown>> | BaseValidationAsync<any, unknown, BaseIssue<unknown>> | BaseTransformation<any, unknown, BaseIssue<unknown>> | BaseTransformationAsync<any, unknown, BaseIssue<unknown>> | BaseMetadata<any>> = NonNullable<TItem['~types']>['output'];
|
|
713
|
+
/**
|
|
714
|
+
* Infer issue type.
|
|
715
|
+
*/
|
|
716
|
+
type InferIssue<TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>> | BaseValidation<any, unknown, BaseIssue<unknown>> | BaseValidationAsync<any, unknown, BaseIssue<unknown>> | BaseTransformation<any, unknown, BaseIssue<unknown>> | BaseTransformationAsync<any, unknown, BaseIssue<unknown>> | BaseMetadata<any>> = NonNullable<TItem['~types']>['issue'];
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Checks if a type is `any`.
|
|
720
|
+
*/
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Constructs a type that is maybe readonly.
|
|
724
|
+
*/
|
|
725
|
+
type MaybeReadonly<TValue> = TValue | Readonly<TValue>;
|
|
726
|
+
/**
|
|
727
|
+
* Constructs a type that is maybe a promise.
|
|
728
|
+
*/
|
|
729
|
+
type MaybePromise<TValue> = TValue | Promise<TValue>;
|
|
730
|
+
/**
|
|
731
|
+
* Prettifies a type for better readability.
|
|
732
|
+
*
|
|
733
|
+
* Hint: This type has no effect and is only used so that TypeScript displays
|
|
734
|
+
* the final type in the preview instead of the utility types used.
|
|
735
|
+
*/
|
|
736
|
+
type Prettify<TObject> = { [TKey in keyof TObject]: TObject[TKey] } & {};
|
|
737
|
+
/**
|
|
738
|
+
* Marks specific keys as optional.
|
|
739
|
+
*/
|
|
740
|
+
type MarkOptional<TObject, TKeys extends keyof TObject> = { [TKey in keyof TObject]?: unknown } & Omit<TObject, TKeys> & Partial<Pick<TObject, TKeys>>;
|
|
741
|
+
/**
|
|
742
|
+
* Merges two objects. Overlapping entries from the second object overwrite
|
|
743
|
+
* properties from the first object.
|
|
744
|
+
*/
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Extracts first tuple item.
|
|
748
|
+
*/
|
|
749
|
+
type FirstTupleItem<TTuple extends readonly [unknown, ...unknown[]]> = TTuple[0];
|
|
750
|
+
/**
|
|
751
|
+
* Extracts last tuple item.
|
|
752
|
+
*/
|
|
753
|
+
type LastTupleItem<TTuple extends readonly [unknown, ...unknown[]]> = TTuple[TTuple extends readonly [unknown, ...infer TRest] ? TRest['length'] : never];
|
|
754
|
+
/**
|
|
755
|
+
* Converts union to intersection type.
|
|
756
|
+
*/
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* Error message type.
|
|
760
|
+
*/
|
|
761
|
+
type ErrorMessage<TIssue extends BaseIssue<unknown>> = ((issue: TIssue) => string) | string;
|
|
762
|
+
/**
|
|
763
|
+
* Default type.
|
|
764
|
+
*/
|
|
765
|
+
type Default<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TInput extends null | undefined> = MaybeReadonly<InferInput<TWrapped> | TInput> | ((dataset?: UnknownDataset, config?: Config<InferIssue<TWrapped>>) => MaybeReadonly<InferInput<TWrapped> | TInput>) | undefined;
|
|
766
|
+
/**
|
|
767
|
+
* Default async type.
|
|
768
|
+
*/
|
|
769
|
+
type DefaultAsync<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TInput extends null | undefined> = MaybeReadonly<InferInput<TWrapped> | TInput> | ((dataset?: UnknownDataset, config?: Config<InferIssue<TWrapped>>) => MaybePromise<MaybeReadonly<InferInput<TWrapped> | TInput>>) | undefined;
|
|
770
|
+
/**
|
|
771
|
+
* Default value type.
|
|
772
|
+
*/
|
|
773
|
+
type DefaultValue<TDefault extends Default<BaseSchema<unknown, unknown, BaseIssue<unknown>>, null | undefined> | DefaultAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, null | undefined>> = TDefault extends DefaultAsync<infer TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, infer TInput> ? TDefault extends ((dataset?: UnknownDataset, config?: Config<InferIssue<TWrapped>>) => MaybePromise<InferInput<TWrapped> | TInput>) ? Awaited<ReturnType<TDefault>> : TDefault : never;
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Optional entry schema type.
|
|
777
|
+
*/
|
|
778
|
+
type OptionalEntrySchema = ExactOptionalSchema<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | NullishSchema<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalSchema<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown>;
|
|
779
|
+
/**
|
|
780
|
+
* Optional entry schema async type.
|
|
781
|
+
*/
|
|
782
|
+
type OptionalEntrySchemaAsync = ExactOptionalSchemaAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown> | NullishSchemaAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalSchemaAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown>;
|
|
783
|
+
/**
|
|
784
|
+
* Object entries interface.
|
|
785
|
+
*/
|
|
786
|
+
interface ObjectEntries {
|
|
787
|
+
[key: string]: BaseSchema<unknown, unknown, BaseIssue<unknown>> | SchemaWithFallback<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalEntrySchema;
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Object entries async interface.
|
|
791
|
+
*/
|
|
792
|
+
interface ObjectEntriesAsync {
|
|
793
|
+
[key: string]: BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>> | SchemaWithFallback<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | SchemaWithFallbackAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalEntrySchema | OptionalEntrySchemaAsync;
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Object keys type.
|
|
797
|
+
*/
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* Infer entries input type.
|
|
801
|
+
*/
|
|
802
|
+
type InferEntriesInput<TEntries extends ObjectEntries | ObjectEntriesAsync> = { -readonly [TKey in keyof TEntries]: InferInput<TEntries[TKey]> };
|
|
803
|
+
/**
|
|
804
|
+
* Infer entries output type.
|
|
805
|
+
*/
|
|
806
|
+
type InferEntriesOutput<TEntries extends ObjectEntries | ObjectEntriesAsync> = { -readonly [TKey in keyof TEntries]: InferOutput<TEntries[TKey]> };
|
|
807
|
+
/**
|
|
808
|
+
* Optional input keys type.
|
|
809
|
+
*/
|
|
810
|
+
type OptionalInputKeys<TEntries extends ObjectEntries | ObjectEntriesAsync> = { [TKey in keyof TEntries]: TEntries[TKey] extends OptionalEntrySchema | OptionalEntrySchemaAsync ? TKey : never }[keyof TEntries];
|
|
811
|
+
/**
|
|
812
|
+
* Optional output keys type.
|
|
813
|
+
*/
|
|
814
|
+
type OptionalOutputKeys<TEntries extends ObjectEntries | ObjectEntriesAsync> = { [TKey in keyof TEntries]: TEntries[TKey] extends OptionalEntrySchema | OptionalEntrySchemaAsync ? undefined extends TEntries[TKey]['default'] ? TKey : never : never }[keyof TEntries];
|
|
815
|
+
/**
|
|
816
|
+
* Input with question marks type.
|
|
817
|
+
*/
|
|
818
|
+
type InputWithQuestionMarks<TEntries extends ObjectEntries | ObjectEntriesAsync, TObject extends InferEntriesInput<TEntries>> = MarkOptional<TObject, OptionalInputKeys<TEntries>>;
|
|
819
|
+
/**
|
|
820
|
+
* Output with question marks type.
|
|
821
|
+
*/
|
|
822
|
+
type OutputWithQuestionMarks<TEntries extends ObjectEntries | ObjectEntriesAsync, TObject extends InferEntriesOutput<TEntries>> = MarkOptional<TObject, OptionalOutputKeys<TEntries>>;
|
|
823
|
+
/**
|
|
824
|
+
* Readonly output keys type.
|
|
825
|
+
*/
|
|
826
|
+
type ReadonlyOutputKeys<TEntries extends ObjectEntries | ObjectEntriesAsync> = { [TKey in keyof TEntries]: TEntries[TKey] extends SchemaWithPipe<infer TPipe> | SchemaWithPipeAsync<infer TPipe> ? ReadonlyAction<any> extends TPipe[number] ? TKey : never : never }[keyof TEntries];
|
|
827
|
+
/**
|
|
828
|
+
* Output with readonly type.
|
|
829
|
+
*/
|
|
830
|
+
type OutputWithReadonly<TEntries extends ObjectEntries | ObjectEntriesAsync, TObject extends OutputWithQuestionMarks<TEntries, InferEntriesOutput<TEntries>>> = Readonly<TObject> & Pick<TObject, Exclude<keyof TObject, ReadonlyOutputKeys<TEntries>>>;
|
|
831
|
+
/**
|
|
832
|
+
* Infer object input type.
|
|
833
|
+
*/
|
|
834
|
+
type InferObjectInput<TEntries extends ObjectEntries | ObjectEntriesAsync> = Prettify<InputWithQuestionMarks<TEntries, InferEntriesInput<TEntries>>>;
|
|
835
|
+
/**
|
|
836
|
+
* Infer object output type.
|
|
837
|
+
*/
|
|
838
|
+
type InferObjectOutput<TEntries extends ObjectEntries | ObjectEntriesAsync> = Prettify<OutputWithReadonly<TEntries, OutputWithQuestionMarks<TEntries, InferEntriesOutput<TEntries>>>>;
|
|
839
|
+
/**
|
|
840
|
+
* Infer object issue type.
|
|
841
|
+
*/
|
|
842
|
+
type InferObjectIssue<TEntries extends ObjectEntries | ObjectEntriesAsync> = InferIssue<TEntries[keyof TEntries]>;
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* Tuple items type.
|
|
846
|
+
*/
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* Array path item interface.
|
|
850
|
+
*/
|
|
851
|
+
interface ArrayPathItem {
|
|
852
|
+
/**
|
|
853
|
+
* The path item type.
|
|
854
|
+
*/
|
|
855
|
+
readonly type: 'array';
|
|
856
|
+
/**
|
|
857
|
+
* The path item origin.
|
|
858
|
+
*/
|
|
859
|
+
readonly origin: 'value';
|
|
860
|
+
/**
|
|
861
|
+
* The path item input.
|
|
862
|
+
*/
|
|
863
|
+
readonly input: MaybeReadonly<unknown[]>;
|
|
864
|
+
/**
|
|
865
|
+
* The path item key.
|
|
866
|
+
*/
|
|
867
|
+
readonly key: number;
|
|
868
|
+
/**
|
|
869
|
+
* The path item value.
|
|
870
|
+
*/
|
|
871
|
+
readonly value: unknown;
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* Map path item interface.
|
|
875
|
+
*/
|
|
876
|
+
interface MapPathItem {
|
|
877
|
+
/**
|
|
878
|
+
* The path item type.
|
|
879
|
+
*/
|
|
880
|
+
readonly type: 'map';
|
|
881
|
+
/**
|
|
882
|
+
* The path item origin.
|
|
883
|
+
*/
|
|
884
|
+
readonly origin: 'key' | 'value';
|
|
885
|
+
/**
|
|
886
|
+
* The path item input.
|
|
887
|
+
*/
|
|
888
|
+
readonly input: Map<unknown, unknown>;
|
|
889
|
+
/**
|
|
890
|
+
* The path item key.
|
|
891
|
+
*/
|
|
892
|
+
readonly key: unknown;
|
|
893
|
+
/**
|
|
894
|
+
* The path item value.
|
|
895
|
+
*/
|
|
896
|
+
readonly value: unknown;
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Object path item interface.
|
|
900
|
+
*/
|
|
901
|
+
interface ObjectPathItem {
|
|
902
|
+
/**
|
|
903
|
+
* The path item type.
|
|
904
|
+
*/
|
|
905
|
+
readonly type: 'object';
|
|
906
|
+
/**
|
|
907
|
+
* The path item origin.
|
|
908
|
+
*/
|
|
909
|
+
readonly origin: 'key' | 'value';
|
|
910
|
+
/**
|
|
911
|
+
* The path item input.
|
|
912
|
+
*/
|
|
913
|
+
readonly input: Record<string, unknown>;
|
|
914
|
+
/**
|
|
915
|
+
* The path item key.
|
|
916
|
+
*/
|
|
917
|
+
readonly key: string;
|
|
918
|
+
/**
|
|
919
|
+
* The path item value.
|
|
920
|
+
*/
|
|
921
|
+
readonly value: unknown;
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Set path item interface.
|
|
925
|
+
*/
|
|
926
|
+
interface SetPathItem {
|
|
927
|
+
/**
|
|
928
|
+
* The path item type.
|
|
929
|
+
*/
|
|
930
|
+
readonly type: 'set';
|
|
931
|
+
/**
|
|
932
|
+
* The path item origin.
|
|
933
|
+
*/
|
|
934
|
+
readonly origin: 'value';
|
|
935
|
+
/**
|
|
936
|
+
* The path item input.
|
|
937
|
+
*/
|
|
938
|
+
readonly input: Set<unknown>;
|
|
939
|
+
/**
|
|
940
|
+
* The path item key.
|
|
941
|
+
*/
|
|
942
|
+
readonly key: null;
|
|
943
|
+
/**
|
|
944
|
+
* The path item key.
|
|
945
|
+
*/
|
|
946
|
+
readonly value: unknown;
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Unknown path item interface.
|
|
950
|
+
*/
|
|
951
|
+
interface UnknownPathItem {
|
|
952
|
+
/**
|
|
953
|
+
* The path item type.
|
|
954
|
+
*/
|
|
955
|
+
readonly type: 'unknown';
|
|
956
|
+
/**
|
|
957
|
+
* The path item origin.
|
|
958
|
+
*/
|
|
959
|
+
readonly origin: 'key' | 'value';
|
|
960
|
+
/**
|
|
961
|
+
* The path item input.
|
|
962
|
+
*/
|
|
963
|
+
readonly input: unknown;
|
|
964
|
+
/**
|
|
965
|
+
* The path item key.
|
|
966
|
+
*/
|
|
967
|
+
readonly key: unknown;
|
|
968
|
+
/**
|
|
969
|
+
* The path item value.
|
|
970
|
+
*/
|
|
971
|
+
readonly value: unknown;
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* Issue path item type.
|
|
975
|
+
*/
|
|
976
|
+
type IssuePathItem = ArrayPathItem | MapPathItem | ObjectPathItem | SetPathItem | UnknownPathItem;
|
|
977
|
+
/**
|
|
978
|
+
* Base issue interface.
|
|
979
|
+
*/
|
|
980
|
+
interface BaseIssue<TInput> extends Config<BaseIssue<TInput>> {
|
|
981
|
+
/**
|
|
982
|
+
* The issue kind.
|
|
983
|
+
*/
|
|
984
|
+
readonly kind: 'schema' | 'validation' | 'transformation';
|
|
985
|
+
/**
|
|
986
|
+
* The issue type.
|
|
987
|
+
*/
|
|
988
|
+
readonly type: string;
|
|
989
|
+
/**
|
|
990
|
+
* The raw input data.
|
|
991
|
+
*/
|
|
992
|
+
readonly input: TInput;
|
|
993
|
+
/**
|
|
994
|
+
* The expected property.
|
|
995
|
+
*/
|
|
996
|
+
readonly expected: string | null;
|
|
997
|
+
/**
|
|
998
|
+
* The received property.
|
|
999
|
+
*/
|
|
1000
|
+
readonly received: string;
|
|
1001
|
+
/**
|
|
1002
|
+
* The error message.
|
|
1003
|
+
*/
|
|
1004
|
+
readonly message: string;
|
|
1005
|
+
/**
|
|
1006
|
+
* The input requirement.
|
|
1007
|
+
*/
|
|
1008
|
+
readonly requirement?: unknown | undefined;
|
|
1009
|
+
/**
|
|
1010
|
+
* The issue path.
|
|
1011
|
+
*/
|
|
1012
|
+
readonly path?: [IssuePathItem, ...IssuePathItem[]] | undefined;
|
|
1013
|
+
/**
|
|
1014
|
+
* The sub issues.
|
|
1015
|
+
*/
|
|
1016
|
+
readonly issues?: [BaseIssue<TInput>, ...BaseIssue<TInput>[]] | undefined;
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Generic issue type.
|
|
1020
|
+
*/
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
* Config interface.
|
|
1024
|
+
*/
|
|
1025
|
+
interface Config<TIssue extends BaseIssue<unknown>> {
|
|
1026
|
+
/**
|
|
1027
|
+
* The selected language.
|
|
1028
|
+
*/
|
|
1029
|
+
readonly lang?: string | undefined;
|
|
1030
|
+
/**
|
|
1031
|
+
* The error message.
|
|
1032
|
+
*/
|
|
1033
|
+
readonly message?: ErrorMessage<TIssue> | undefined;
|
|
1034
|
+
/**
|
|
1035
|
+
* Whether it should be aborted early.
|
|
1036
|
+
*/
|
|
1037
|
+
readonly abortEarly?: boolean | undefined;
|
|
1038
|
+
/**
|
|
1039
|
+
* Whether a pipe should be aborted early.
|
|
1040
|
+
*/
|
|
1041
|
+
readonly abortPipeEarly?: boolean | undefined;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* Pipe action type.
|
|
1046
|
+
*/
|
|
1047
|
+
type PipeAction<TInput, TOutput, TIssue extends BaseIssue<unknown>> = BaseValidation<TInput, TOutput, TIssue> | BaseTransformation<TInput, TOutput, TIssue> | BaseMetadata<TInput>;
|
|
1048
|
+
/**
|
|
1049
|
+
* Pipe action async type.
|
|
1050
|
+
*/
|
|
1051
|
+
type PipeActionAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> = BaseValidationAsync<TInput, TOutput, TIssue> | BaseTransformationAsync<TInput, TOutput, TIssue>;
|
|
1052
|
+
/**
|
|
1053
|
+
* Pipe item type.
|
|
1054
|
+
*/
|
|
1055
|
+
type PipeItem<TInput, TOutput, TIssue extends BaseIssue<unknown>> = BaseSchema<TInput, TOutput, TIssue> | PipeAction<TInput, TOutput, TIssue>;
|
|
1056
|
+
/**
|
|
1057
|
+
* Pipe item async type.
|
|
1058
|
+
*/
|
|
1059
|
+
type PipeItemAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> = BaseSchemaAsync<TInput, TOutput, TIssue> | PipeActionAsync<TInput, TOutput, TIssue>;
|
|
1060
|
+
/**
|
|
1061
|
+
* Schema without pipe type.
|
|
1062
|
+
*/
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* Array issue interface.
|
|
1066
|
+
*/
|
|
1067
|
+
interface ArrayIssue extends BaseIssue<unknown> {
|
|
1068
|
+
/**
|
|
1069
|
+
* The issue kind.
|
|
1070
|
+
*/
|
|
1071
|
+
readonly kind: 'schema';
|
|
1072
|
+
/**
|
|
1073
|
+
* The issue type.
|
|
1074
|
+
*/
|
|
1075
|
+
readonly type: 'array';
|
|
1076
|
+
/**
|
|
1077
|
+
* The expected property.
|
|
1078
|
+
*/
|
|
1079
|
+
readonly expected: 'Array';
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
/**
|
|
1083
|
+
* Array schema interface.
|
|
1084
|
+
*/
|
|
1085
|
+
interface ArraySchema<TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TMessage extends ErrorMessage<ArrayIssue> | undefined> extends BaseSchema<InferInput<TItem>[], InferOutput<TItem>[], ArrayIssue | InferIssue<TItem>> {
|
|
1086
|
+
/**
|
|
1087
|
+
* The schema type.
|
|
1088
|
+
*/
|
|
1089
|
+
readonly type: 'array';
|
|
1090
|
+
/**
|
|
1091
|
+
* The schema reference.
|
|
1092
|
+
*/
|
|
1093
|
+
readonly reference: typeof array;
|
|
1094
|
+
/**
|
|
1095
|
+
* The expected property.
|
|
1096
|
+
*/
|
|
1097
|
+
readonly expects: 'Array';
|
|
1098
|
+
/**
|
|
1099
|
+
* The array item schema.
|
|
1100
|
+
*/
|
|
1101
|
+
readonly item: TItem;
|
|
1102
|
+
/**
|
|
1103
|
+
* The error message.
|
|
1104
|
+
*/
|
|
1105
|
+
readonly message: TMessage;
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Creates an array schema.
|
|
1109
|
+
*
|
|
1110
|
+
* @param item The item schema.
|
|
1111
|
+
*
|
|
1112
|
+
* @returns An array schema.
|
|
1113
|
+
*/
|
|
1114
|
+
declare function array<const TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(item: TItem): ArraySchema<TItem, undefined>;
|
|
1115
|
+
/**
|
|
1116
|
+
* Creates an array schema.
|
|
1117
|
+
*
|
|
1118
|
+
* @param item The item schema.
|
|
1119
|
+
* @param message The error message.
|
|
1120
|
+
*
|
|
1121
|
+
* @returns An array schema.
|
|
1122
|
+
*/
|
|
1123
|
+
declare function array<const TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, const TMessage extends ErrorMessage<ArrayIssue> | undefined>(item: TItem, message: TMessage): ArraySchema<TItem, TMessage>;
|
|
1124
|
+
|
|
1125
|
+
/**
|
|
1126
|
+
* Array schema interface.
|
|
1127
|
+
*/
|
|
1128
|
+
|
|
1129
|
+
/**
|
|
1130
|
+
* Boolean issue interface.
|
|
1131
|
+
*/
|
|
1132
|
+
interface BooleanIssue extends BaseIssue<unknown> {
|
|
1133
|
+
/**
|
|
1134
|
+
* The issue kind.
|
|
1135
|
+
*/
|
|
1136
|
+
readonly kind: 'schema';
|
|
1137
|
+
/**
|
|
1138
|
+
* The issue type.
|
|
1139
|
+
*/
|
|
1140
|
+
readonly type: 'boolean';
|
|
1141
|
+
/**
|
|
1142
|
+
* The expected property.
|
|
1143
|
+
*/
|
|
1144
|
+
readonly expected: 'boolean';
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Boolean schema interface.
|
|
1148
|
+
*/
|
|
1149
|
+
interface BooleanSchema<TMessage extends ErrorMessage<BooleanIssue> | undefined> extends BaseSchema<boolean, boolean, BooleanIssue> {
|
|
1150
|
+
/**
|
|
1151
|
+
* The schema type.
|
|
1152
|
+
*/
|
|
1153
|
+
readonly type: 'boolean';
|
|
1154
|
+
/**
|
|
1155
|
+
* The schema reference.
|
|
1156
|
+
*/
|
|
1157
|
+
readonly reference: typeof boolean;
|
|
1158
|
+
/**
|
|
1159
|
+
* The expected property.
|
|
1160
|
+
*/
|
|
1161
|
+
readonly expects: 'boolean';
|
|
1162
|
+
/**
|
|
1163
|
+
* The error message.
|
|
1164
|
+
*/
|
|
1165
|
+
readonly message: TMessage;
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Creates a boolean schema.
|
|
1169
|
+
*
|
|
1170
|
+
* @returns A boolean schema.
|
|
1171
|
+
*/
|
|
1172
|
+
declare function boolean(): BooleanSchema<undefined>;
|
|
1173
|
+
/**
|
|
1174
|
+
* Creates a boolean schema.
|
|
1175
|
+
*
|
|
1176
|
+
* @param message The error message.
|
|
1177
|
+
*
|
|
1178
|
+
* @returns A boolean schema.
|
|
1179
|
+
*/
|
|
1180
|
+
declare function boolean<const TMessage extends ErrorMessage<BooleanIssue> | undefined>(message: TMessage): BooleanSchema<TMessage>;
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* Custom issue interface.
|
|
1184
|
+
*/
|
|
1185
|
+
|
|
1186
|
+
/**
|
|
1187
|
+
* Exact optional schema interface.
|
|
1188
|
+
*/
|
|
1189
|
+
interface ExactOptionalSchema<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TDefault extends Default<TWrapped, never>> extends BaseSchema<InferInput<TWrapped>, InferOutput<TWrapped>, InferIssue<TWrapped>> {
|
|
1190
|
+
/**
|
|
1191
|
+
* The schema type.
|
|
1192
|
+
*/
|
|
1193
|
+
readonly type: 'exact_optional';
|
|
1194
|
+
/**
|
|
1195
|
+
* The schema reference.
|
|
1196
|
+
*/
|
|
1197
|
+
readonly reference: typeof exactOptional;
|
|
1198
|
+
/**
|
|
1199
|
+
* The expected property.
|
|
1200
|
+
*/
|
|
1201
|
+
readonly expects: TWrapped['expects'];
|
|
1202
|
+
/**
|
|
1203
|
+
* The wrapped schema.
|
|
1204
|
+
*/
|
|
1205
|
+
readonly wrapped: TWrapped;
|
|
1206
|
+
/**
|
|
1207
|
+
* The default value.
|
|
1208
|
+
*/
|
|
1209
|
+
readonly default: TDefault;
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Creates an exact optional schema.
|
|
1213
|
+
*
|
|
1214
|
+
* @param wrapped The wrapped schema.
|
|
1215
|
+
*
|
|
1216
|
+
* @returns An exact optional schema.
|
|
1217
|
+
*/
|
|
1218
|
+
declare function exactOptional<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(wrapped: TWrapped): ExactOptionalSchema<TWrapped, undefined>;
|
|
1219
|
+
/**
|
|
1220
|
+
* Creates an exact optional schema.
|
|
1221
|
+
*
|
|
1222
|
+
* @param wrapped The wrapped schema.
|
|
1223
|
+
* @param default_ The default value.
|
|
1224
|
+
*
|
|
1225
|
+
* @returns An exact optional schema.
|
|
1226
|
+
*/
|
|
1227
|
+
declare function exactOptional<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, const TDefault extends Default<TWrapped, never>>(wrapped: TWrapped, default_: TDefault): ExactOptionalSchema<TWrapped, TDefault>;
|
|
1228
|
+
|
|
1229
|
+
/**
|
|
1230
|
+
* Exact optional schema async interface.
|
|
1231
|
+
*/
|
|
1232
|
+
interface ExactOptionalSchemaAsync<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TDefault extends DefaultAsync<TWrapped, never>> extends BaseSchemaAsync<InferInput<TWrapped>, InferOutput<TWrapped>, InferIssue<TWrapped>> {
|
|
1233
|
+
/**
|
|
1234
|
+
* The schema type.
|
|
1235
|
+
*/
|
|
1236
|
+
readonly type: 'exact_optional';
|
|
1237
|
+
/**
|
|
1238
|
+
* The schema reference.
|
|
1239
|
+
*/
|
|
1240
|
+
readonly reference: typeof exactOptional | typeof exactOptionalAsync;
|
|
1241
|
+
/**
|
|
1242
|
+
* The expected property.
|
|
1243
|
+
*/
|
|
1244
|
+
readonly expects: TWrapped['expects'];
|
|
1245
|
+
/**
|
|
1246
|
+
* The wrapped schema.
|
|
1247
|
+
*/
|
|
1248
|
+
readonly wrapped: TWrapped;
|
|
1249
|
+
/**
|
|
1250
|
+
* The default value.
|
|
1251
|
+
*/
|
|
1252
|
+
readonly default: TDefault;
|
|
1253
|
+
}
|
|
1254
|
+
/**
|
|
1255
|
+
* Creates an exact optional schema.
|
|
1256
|
+
*
|
|
1257
|
+
* @param wrapped The wrapped schema.
|
|
1258
|
+
*
|
|
1259
|
+
* @returns An exact optional schema.
|
|
1260
|
+
*/
|
|
1261
|
+
declare function exactOptionalAsync<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>>(wrapped: TWrapped): ExactOptionalSchemaAsync<TWrapped, undefined>;
|
|
1262
|
+
/**
|
|
1263
|
+
* Creates an exact optional schema.
|
|
1264
|
+
*
|
|
1265
|
+
* @param wrapped The wrapped schema.
|
|
1266
|
+
* @param default_ The default value.
|
|
1267
|
+
*
|
|
1268
|
+
* @returns An exact optional schema.
|
|
1269
|
+
*/
|
|
1270
|
+
declare function exactOptionalAsync<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, const TDefault extends DefaultAsync<TWrapped, never>>(wrapped: TWrapped, default_: TDefault): ExactOptionalSchemaAsync<TWrapped, TDefault>;
|
|
1271
|
+
|
|
1272
|
+
/**
|
|
1273
|
+
* File issue interface.
|
|
1274
|
+
*/
|
|
1275
|
+
|
|
1276
|
+
/**
|
|
1277
|
+
* Union issue interface.
|
|
1278
|
+
*/
|
|
1279
|
+
interface UnionIssue<TSubIssue extends BaseIssue<unknown>> extends BaseIssue<unknown> {
|
|
1280
|
+
/**
|
|
1281
|
+
* The issue kind.
|
|
1282
|
+
*/
|
|
1283
|
+
readonly kind: 'schema';
|
|
1284
|
+
/**
|
|
1285
|
+
* The issue type.
|
|
1286
|
+
*/
|
|
1287
|
+
readonly type: 'union';
|
|
1288
|
+
/**
|
|
1289
|
+
* The expected property.
|
|
1290
|
+
*/
|
|
1291
|
+
readonly expected: string;
|
|
1292
|
+
/**
|
|
1293
|
+
* The sub issues.
|
|
1294
|
+
*/
|
|
1295
|
+
readonly issues?: [TSubIssue, ...TSubIssue[]];
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
/**
|
|
1299
|
+
* Union options type.
|
|
1300
|
+
*/
|
|
1301
|
+
type UnionOptions = MaybeReadonly<BaseSchema<unknown, unknown, BaseIssue<unknown>>[]>;
|
|
1302
|
+
/**
|
|
1303
|
+
* Union schema interface.
|
|
1304
|
+
*/
|
|
1305
|
+
interface UnionSchema<TOptions extends UnionOptions, TMessage extends ErrorMessage<UnionIssue<InferIssue<TOptions[number]>>> | undefined> extends BaseSchema<InferInput<TOptions[number]>, InferOutput<TOptions[number]>, UnionIssue<InferIssue<TOptions[number]>> | InferIssue<TOptions[number]>> {
|
|
1306
|
+
/**
|
|
1307
|
+
* The schema type.
|
|
1308
|
+
*/
|
|
1309
|
+
readonly type: 'union';
|
|
1310
|
+
/**
|
|
1311
|
+
* The schema reference.
|
|
1312
|
+
*/
|
|
1313
|
+
readonly reference: typeof union;
|
|
1314
|
+
/**
|
|
1315
|
+
* The union options.
|
|
1316
|
+
*/
|
|
1317
|
+
readonly options: TOptions;
|
|
1318
|
+
/**
|
|
1319
|
+
* The error message.
|
|
1320
|
+
*/
|
|
1321
|
+
readonly message: TMessage;
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Creates an union schema.
|
|
1325
|
+
*
|
|
1326
|
+
* @param options The union options.
|
|
1327
|
+
*
|
|
1328
|
+
* @returns An union schema.
|
|
1329
|
+
*/
|
|
1330
|
+
declare function union<const TOptions extends UnionOptions>(options: TOptions): UnionSchema<TOptions, undefined>;
|
|
1331
|
+
/**
|
|
1332
|
+
* Creates an union schema.
|
|
1333
|
+
*
|
|
1334
|
+
* @param options The union options.
|
|
1335
|
+
* @param message The error message.
|
|
1336
|
+
*
|
|
1337
|
+
* @returns An union schema.
|
|
1338
|
+
*/
|
|
1339
|
+
declare function union<const TOptions extends UnionOptions, const TMessage extends ErrorMessage<UnionIssue<InferIssue<TOptions[number]>>> | undefined>(options: TOptions, message: TMessage): UnionSchema<TOptions, TMessage>;
|
|
1340
|
+
|
|
1341
|
+
/**
|
|
1342
|
+
* Union options async type.
|
|
1343
|
+
*/
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* Infer nullish output type.
|
|
1347
|
+
*/
|
|
1348
|
+
type InferNullishOutput<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TDefault extends DefaultAsync<TWrapped, null | undefined>> = undefined extends TDefault ? InferOutput<TWrapped> | null | undefined : InferOutput<TWrapped> | Extract<DefaultValue<TDefault>, null | undefined>;
|
|
1349
|
+
|
|
1350
|
+
/**
|
|
1351
|
+
* Nullish schema interface.
|
|
1352
|
+
*/
|
|
1353
|
+
interface NullishSchema<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TDefault extends Default<TWrapped, null | undefined>> extends BaseSchema<InferInput<TWrapped> | null | undefined, InferNullishOutput<TWrapped, TDefault>, InferIssue<TWrapped>> {
|
|
1354
|
+
/**
|
|
1355
|
+
* The schema type.
|
|
1356
|
+
*/
|
|
1357
|
+
readonly type: 'nullish';
|
|
1358
|
+
/**
|
|
1359
|
+
* The schema reference.
|
|
1360
|
+
*/
|
|
1361
|
+
readonly reference: typeof nullish;
|
|
1362
|
+
/**
|
|
1363
|
+
* The expected property.
|
|
1364
|
+
*/
|
|
1365
|
+
readonly expects: `(${TWrapped['expects']} | null | undefined)`;
|
|
1366
|
+
/**
|
|
1367
|
+
* The wrapped schema.
|
|
1368
|
+
*/
|
|
1369
|
+
readonly wrapped: TWrapped;
|
|
1370
|
+
/**
|
|
1371
|
+
* The default value.
|
|
1372
|
+
*/
|
|
1373
|
+
readonly default: TDefault;
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* Creates a nullish schema.
|
|
1377
|
+
*
|
|
1378
|
+
* @param wrapped The wrapped schema.
|
|
1379
|
+
*
|
|
1380
|
+
* @returns A nullish schema.
|
|
1381
|
+
*/
|
|
1382
|
+
declare function nullish<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(wrapped: TWrapped): NullishSchema<TWrapped, undefined>;
|
|
1383
|
+
/**
|
|
1384
|
+
* Creates a nullish schema.
|
|
1385
|
+
*
|
|
1386
|
+
* @param wrapped The wrapped schema.
|
|
1387
|
+
* @param default_ The default value.
|
|
1388
|
+
*
|
|
1389
|
+
* @returns A nullish schema.
|
|
1390
|
+
*/
|
|
1391
|
+
declare function nullish<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, const TDefault extends Default<TWrapped, null | undefined>>(wrapped: TWrapped, default_: TDefault): NullishSchema<TWrapped, TDefault>;
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* Nullish schema async interface.
|
|
1395
|
+
*/
|
|
1396
|
+
interface NullishSchemaAsync<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TDefault extends DefaultAsync<TWrapped, null | undefined>> extends BaseSchemaAsync<InferInput<TWrapped> | null | undefined, InferNullishOutput<TWrapped, TDefault>, InferIssue<TWrapped>> {
|
|
1397
|
+
/**
|
|
1398
|
+
* The schema type.
|
|
1399
|
+
*/
|
|
1400
|
+
readonly type: 'nullish';
|
|
1401
|
+
/**
|
|
1402
|
+
* The schema reference.
|
|
1403
|
+
*/
|
|
1404
|
+
readonly reference: typeof nullish | typeof nullishAsync;
|
|
1405
|
+
/**
|
|
1406
|
+
* The expected property.
|
|
1407
|
+
*/
|
|
1408
|
+
readonly expects: `(${TWrapped['expects']} | null | undefined)`;
|
|
1409
|
+
/**
|
|
1410
|
+
* The wrapped schema.
|
|
1411
|
+
*/
|
|
1412
|
+
readonly wrapped: TWrapped;
|
|
1413
|
+
/**
|
|
1414
|
+
* The default value.
|
|
1415
|
+
*/
|
|
1416
|
+
readonly default: TDefault;
|
|
1417
|
+
}
|
|
1418
|
+
/**
|
|
1419
|
+
* Creates a nullish schema.
|
|
1420
|
+
*
|
|
1421
|
+
* @param wrapped The wrapped schema.
|
|
1422
|
+
*
|
|
1423
|
+
* @returns A nullish schema.
|
|
1424
|
+
*/
|
|
1425
|
+
declare function nullishAsync<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>>(wrapped: TWrapped): NullishSchemaAsync<TWrapped, undefined>;
|
|
1426
|
+
/**
|
|
1427
|
+
* Creates a nullish schema.
|
|
1428
|
+
*
|
|
1429
|
+
* @param wrapped The wrapped schema.
|
|
1430
|
+
* @param default_ The default value.
|
|
1431
|
+
*
|
|
1432
|
+
* @returns A nullish schema.
|
|
1433
|
+
*/
|
|
1434
|
+
declare function nullishAsync<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, const TDefault extends DefaultAsync<TWrapped, null | undefined>>(wrapped: TWrapped, default_: TDefault): NullishSchemaAsync<TWrapped, TDefault>;
|
|
1435
|
+
|
|
1436
|
+
/**
|
|
1437
|
+
* Number issue interface.
|
|
1438
|
+
*/
|
|
1439
|
+
interface NumberIssue extends BaseIssue<unknown> {
|
|
1440
|
+
/**
|
|
1441
|
+
* The issue kind.
|
|
1442
|
+
*/
|
|
1443
|
+
readonly kind: 'schema';
|
|
1444
|
+
/**
|
|
1445
|
+
* The issue type.
|
|
1446
|
+
*/
|
|
1447
|
+
readonly type: 'number';
|
|
1448
|
+
/**
|
|
1449
|
+
* The expected property.
|
|
1450
|
+
*/
|
|
1451
|
+
readonly expected: 'number';
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Number schema interface.
|
|
1455
|
+
*/
|
|
1456
|
+
interface NumberSchema<TMessage extends ErrorMessage<NumberIssue> | undefined> extends BaseSchema<number, number, NumberIssue> {
|
|
1457
|
+
/**
|
|
1458
|
+
* The schema type.
|
|
1459
|
+
*/
|
|
1460
|
+
readonly type: 'number';
|
|
1461
|
+
/**
|
|
1462
|
+
* The schema reference.
|
|
1463
|
+
*/
|
|
1464
|
+
readonly reference: typeof number;
|
|
1465
|
+
/**
|
|
1466
|
+
* The expected property.
|
|
1467
|
+
*/
|
|
1468
|
+
readonly expects: 'number';
|
|
1469
|
+
/**
|
|
1470
|
+
* The error message.
|
|
1471
|
+
*/
|
|
1472
|
+
readonly message: TMessage;
|
|
1473
|
+
}
|
|
1474
|
+
/**
|
|
1475
|
+
* Creates a number schema.
|
|
1476
|
+
*
|
|
1477
|
+
* @returns A number schema.
|
|
1478
|
+
*/
|
|
1479
|
+
declare function number(): NumberSchema<undefined>;
|
|
1480
|
+
/**
|
|
1481
|
+
* Creates a number schema.
|
|
1482
|
+
*
|
|
1483
|
+
* @param message The error message.
|
|
1484
|
+
*
|
|
1485
|
+
* @returns A number schema.
|
|
1486
|
+
*/
|
|
1487
|
+
declare function number<const TMessage extends ErrorMessage<NumberIssue> | undefined>(message: TMessage): NumberSchema<TMessage>;
|
|
1488
|
+
|
|
1489
|
+
/**
|
|
1490
|
+
* Object issue interface.
|
|
1491
|
+
*/
|
|
1492
|
+
interface ObjectIssue extends BaseIssue<unknown> {
|
|
1493
|
+
/**
|
|
1494
|
+
* The issue kind.
|
|
1495
|
+
*/
|
|
1496
|
+
readonly kind: 'schema';
|
|
1497
|
+
/**
|
|
1498
|
+
* The issue type.
|
|
1499
|
+
*/
|
|
1500
|
+
readonly type: 'object';
|
|
1501
|
+
/**
|
|
1502
|
+
* The expected property.
|
|
1503
|
+
*/
|
|
1504
|
+
readonly expected: 'Object' | `"${string}"`;
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
/**
|
|
1508
|
+
* Object schema interface.
|
|
1509
|
+
*/
|
|
1510
|
+
interface ObjectSchema<TEntries extends ObjectEntries, TMessage extends ErrorMessage<ObjectIssue> | undefined> extends BaseSchema<InferObjectInput<TEntries>, InferObjectOutput<TEntries>, ObjectIssue | InferObjectIssue<TEntries>> {
|
|
1511
|
+
/**
|
|
1512
|
+
* The schema type.
|
|
1513
|
+
*/
|
|
1514
|
+
readonly type: 'object';
|
|
1515
|
+
/**
|
|
1516
|
+
* The schema reference.
|
|
1517
|
+
*/
|
|
1518
|
+
readonly reference: typeof object;
|
|
1519
|
+
/**
|
|
1520
|
+
* The expected property.
|
|
1521
|
+
*/
|
|
1522
|
+
readonly expects: 'Object';
|
|
1523
|
+
/**
|
|
1524
|
+
* The entries schema.
|
|
1525
|
+
*/
|
|
1526
|
+
readonly entries: TEntries;
|
|
1527
|
+
/**
|
|
1528
|
+
* The error message.
|
|
1529
|
+
*/
|
|
1530
|
+
readonly message: TMessage;
|
|
1531
|
+
}
|
|
1532
|
+
/**
|
|
1533
|
+
* Creates an object schema.
|
|
1534
|
+
*
|
|
1535
|
+
* Hint: This schema removes unknown entries. The output will only include the
|
|
1536
|
+
* entries you specify. To include unknown entries, use `looseObject`. To
|
|
1537
|
+
* return an issue for unknown entries, use `strictObject`. To include and
|
|
1538
|
+
* validate unknown entries, use `objectWithRest`.
|
|
1539
|
+
*
|
|
1540
|
+
* @param entries The entries schema.
|
|
1541
|
+
*
|
|
1542
|
+
* @returns An object schema.
|
|
1543
|
+
*/
|
|
1544
|
+
declare function object<const TEntries extends ObjectEntries>(entries: TEntries): ObjectSchema<TEntries, undefined>;
|
|
1545
|
+
/**
|
|
1546
|
+
* Creates an object schema.
|
|
1547
|
+
*
|
|
1548
|
+
* Hint: This schema removes unknown entries. The output will only include the
|
|
1549
|
+
* entries you specify. To include unknown entries, use `looseObject`. To
|
|
1550
|
+
* return an issue for unknown entries, use `strictObject`. To include and
|
|
1551
|
+
* validate unknown entries, use `objectWithRest`.
|
|
1552
|
+
*
|
|
1553
|
+
* @param entries The entries schema.
|
|
1554
|
+
* @param message The error message.
|
|
1555
|
+
*
|
|
1556
|
+
* @returns An object schema.
|
|
1557
|
+
*/
|
|
1558
|
+
declare function object<const TEntries extends ObjectEntries, const TMessage extends ErrorMessage<ObjectIssue> | undefined>(entries: TEntries, message: TMessage): ObjectSchema<TEntries, TMessage>;
|
|
1559
|
+
|
|
1560
|
+
/**
|
|
1561
|
+
* Object schema async interface.
|
|
1562
|
+
*/
|
|
1563
|
+
|
|
1564
|
+
/**
|
|
1565
|
+
* Infer optional output type.
|
|
1566
|
+
*/
|
|
1567
|
+
type InferOptionalOutput<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TDefault extends DefaultAsync<TWrapped, undefined>> = undefined extends TDefault ? InferOutput<TWrapped> | undefined : InferOutput<TWrapped> | Extract<DefaultValue<TDefault>, undefined>;
|
|
1568
|
+
|
|
1569
|
+
/**
|
|
1570
|
+
* Optional schema interface.
|
|
1571
|
+
*/
|
|
1572
|
+
interface OptionalSchema<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TDefault extends Default<TWrapped, undefined>> extends BaseSchema<InferInput<TWrapped> | undefined, InferOptionalOutput<TWrapped, TDefault>, InferIssue<TWrapped>> {
|
|
1573
|
+
/**
|
|
1574
|
+
* The schema type.
|
|
1575
|
+
*/
|
|
1576
|
+
readonly type: 'optional';
|
|
1577
|
+
/**
|
|
1578
|
+
* The schema reference.
|
|
1579
|
+
*/
|
|
1580
|
+
readonly reference: typeof optional;
|
|
1581
|
+
/**
|
|
1582
|
+
* The expected property.
|
|
1583
|
+
*/
|
|
1584
|
+
readonly expects: `(${TWrapped['expects']} | undefined)`;
|
|
1585
|
+
/**
|
|
1586
|
+
* The wrapped schema.
|
|
1587
|
+
*/
|
|
1588
|
+
readonly wrapped: TWrapped;
|
|
1589
|
+
/**
|
|
1590
|
+
* The default value.
|
|
1591
|
+
*/
|
|
1592
|
+
readonly default: TDefault;
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Creates an optional schema.
|
|
1596
|
+
*
|
|
1597
|
+
* @param wrapped The wrapped schema.
|
|
1598
|
+
*
|
|
1599
|
+
* @returns An optional schema.
|
|
1600
|
+
*/
|
|
1601
|
+
declare function optional<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(wrapped: TWrapped): OptionalSchema<TWrapped, undefined>;
|
|
1602
|
+
/**
|
|
1603
|
+
* Creates an optional schema.
|
|
1604
|
+
*
|
|
1605
|
+
* @param wrapped The wrapped schema.
|
|
1606
|
+
* @param default_ The default value.
|
|
1607
|
+
*
|
|
1608
|
+
* @returns An optional schema.
|
|
1609
|
+
*/
|
|
1610
|
+
declare function optional<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, const TDefault extends Default<TWrapped, undefined>>(wrapped: TWrapped, default_: TDefault): OptionalSchema<TWrapped, TDefault>;
|
|
1611
|
+
|
|
1612
|
+
/**
|
|
1613
|
+
* Optional schema async interface.
|
|
1614
|
+
*/
|
|
1615
|
+
interface OptionalSchemaAsync<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TDefault extends DefaultAsync<TWrapped, undefined>> extends BaseSchemaAsync<InferInput<TWrapped> | undefined, InferOptionalOutput<TWrapped, TDefault>, InferIssue<TWrapped>> {
|
|
1616
|
+
/**
|
|
1617
|
+
* The schema type.
|
|
1618
|
+
*/
|
|
1619
|
+
readonly type: 'optional';
|
|
1620
|
+
/**
|
|
1621
|
+
* The schema reference.
|
|
1622
|
+
*/
|
|
1623
|
+
readonly reference: typeof optional | typeof optionalAsync;
|
|
1624
|
+
/**
|
|
1625
|
+
* The expected property.
|
|
1626
|
+
*/
|
|
1627
|
+
readonly expects: `(${TWrapped['expects']} | undefined)`;
|
|
1628
|
+
/**
|
|
1629
|
+
* The wrapped schema.
|
|
1630
|
+
*/
|
|
1631
|
+
readonly wrapped: TWrapped;
|
|
1632
|
+
/**
|
|
1633
|
+
* The default value.
|
|
1634
|
+
*/
|
|
1635
|
+
readonly default: TDefault;
|
|
1636
|
+
}
|
|
1637
|
+
/**
|
|
1638
|
+
* Creates an optional schema.
|
|
1639
|
+
*
|
|
1640
|
+
* @param wrapped The wrapped schema.
|
|
1641
|
+
*
|
|
1642
|
+
* @returns An optional schema.
|
|
1643
|
+
*/
|
|
1644
|
+
declare function optionalAsync<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>>(wrapped: TWrapped): OptionalSchemaAsync<TWrapped, undefined>;
|
|
1645
|
+
/**
|
|
1646
|
+
* Creates an optional schema.
|
|
1647
|
+
*
|
|
1648
|
+
* @param wrapped The wrapped schema.
|
|
1649
|
+
* @param default_ The default value.
|
|
1650
|
+
*
|
|
1651
|
+
* @returns An optional schema.
|
|
1652
|
+
*/
|
|
1653
|
+
declare function optionalAsync<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, const TDefault extends DefaultAsync<TWrapped, undefined>>(wrapped: TWrapped, default_: TDefault): OptionalSchemaAsync<TWrapped, TDefault>;
|
|
1654
|
+
|
|
1655
|
+
/**
|
|
1656
|
+
* Picklist options type.
|
|
1657
|
+
*/
|
|
1658
|
+
|
|
1659
|
+
/**
|
|
1660
|
+
* String issue interface.
|
|
1661
|
+
*/
|
|
1662
|
+
interface StringIssue extends BaseIssue<unknown> {
|
|
1663
|
+
/**
|
|
1664
|
+
* The issue kind.
|
|
1665
|
+
*/
|
|
1666
|
+
readonly kind: 'schema';
|
|
1667
|
+
/**
|
|
1668
|
+
* The issue type.
|
|
1669
|
+
*/
|
|
1670
|
+
readonly type: 'string';
|
|
1671
|
+
/**
|
|
1672
|
+
* The expected property.
|
|
1673
|
+
*/
|
|
1674
|
+
readonly expected: 'string';
|
|
1675
|
+
}
|
|
1676
|
+
/**
|
|
1677
|
+
* String schema interface.
|
|
1678
|
+
*/
|
|
1679
|
+
interface StringSchema<TMessage extends ErrorMessage<StringIssue> | undefined> extends BaseSchema<string, string, StringIssue> {
|
|
1680
|
+
/**
|
|
1681
|
+
* The schema type.
|
|
1682
|
+
*/
|
|
1683
|
+
readonly type: 'string';
|
|
1684
|
+
/**
|
|
1685
|
+
* The schema reference.
|
|
1686
|
+
*/
|
|
1687
|
+
readonly reference: typeof string;
|
|
1688
|
+
/**
|
|
1689
|
+
* The expected property.
|
|
1690
|
+
*/
|
|
1691
|
+
readonly expects: 'string';
|
|
1692
|
+
/**
|
|
1693
|
+
* The error message.
|
|
1694
|
+
*/
|
|
1695
|
+
readonly message: TMessage;
|
|
1696
|
+
}
|
|
1697
|
+
/**
|
|
1698
|
+
* Creates a string schema.
|
|
1699
|
+
*
|
|
1700
|
+
* @returns A string schema.
|
|
1701
|
+
*/
|
|
1702
|
+
declare function string(): StringSchema<undefined>;
|
|
1703
|
+
/**
|
|
1704
|
+
* Creates a string schema.
|
|
1705
|
+
*
|
|
1706
|
+
* @param message The error message.
|
|
1707
|
+
*
|
|
1708
|
+
* @returns A string schema.
|
|
1709
|
+
*/
|
|
1710
|
+
declare function string<const TMessage extends ErrorMessage<StringIssue> | undefined>(message: TMessage): StringSchema<TMessage>;
|
|
1711
|
+
|
|
1712
|
+
/**
|
|
1713
|
+
* Symbol issue interface.
|
|
1714
|
+
*/
|
|
1715
|
+
|
|
1716
|
+
/**
|
|
1717
|
+
* Brand symbol.
|
|
1718
|
+
*/
|
|
1719
|
+
declare const BrandSymbol: unique symbol;
|
|
1720
|
+
/**
|
|
1721
|
+
* Brand name type.
|
|
1722
|
+
*/
|
|
1723
|
+
type BrandName = string | number | symbol;
|
|
1724
|
+
/**
|
|
1725
|
+
* Brand interface.
|
|
1726
|
+
*/
|
|
1727
|
+
interface Brand<TName extends BrandName> {
|
|
1728
|
+
[BrandSymbol]: { [TValue in TName]: TValue };
|
|
1729
|
+
}
|
|
1730
|
+
/**
|
|
1731
|
+
* Brand action interface.
|
|
1732
|
+
*/
|
|
1733
|
+
interface BrandAction<TInput, TName extends BrandName> extends BaseTransformation<TInput, TInput & Brand<TName>, never> {
|
|
1734
|
+
/**
|
|
1735
|
+
* The action type.
|
|
1736
|
+
*/
|
|
1737
|
+
readonly type: 'brand';
|
|
1738
|
+
/**
|
|
1739
|
+
* The action reference.
|
|
1740
|
+
*/
|
|
1741
|
+
readonly reference: typeof brand;
|
|
1742
|
+
/**
|
|
1743
|
+
* The brand name.
|
|
1744
|
+
*/
|
|
1745
|
+
readonly name: TName;
|
|
1746
|
+
}
|
|
1747
|
+
/**
|
|
1748
|
+
* Creates a brand transformation action.
|
|
1749
|
+
*
|
|
1750
|
+
* @param name The brand name.
|
|
1751
|
+
*
|
|
1752
|
+
* @returns A brand action.
|
|
1753
|
+
*/
|
|
1754
|
+
declare function brand<TInput, TName extends BrandName>(name: TName): BrandAction<TInput, TName>;
|
|
1755
|
+
|
|
1756
|
+
/**
|
|
1757
|
+
* Bytes issue interface.
|
|
1758
|
+
*/
|
|
1759
|
+
|
|
1760
|
+
/**
|
|
1761
|
+
* Length input type.
|
|
1762
|
+
*/
|
|
1763
|
+
type LengthInput = string | ArrayLike<unknown>;
|
|
1764
|
+
/**
|
|
1765
|
+
* Size input type.
|
|
1766
|
+
*/
|
|
1767
|
+
|
|
1768
|
+
/**
|
|
1769
|
+
* Min length issue interface.
|
|
1770
|
+
*/
|
|
1771
|
+
interface MinLengthIssue<TInput extends LengthInput, TRequirement extends number> extends BaseIssue<TInput> {
|
|
1772
|
+
/**
|
|
1773
|
+
* The issue kind.
|
|
1774
|
+
*/
|
|
1775
|
+
readonly kind: 'validation';
|
|
1776
|
+
/**
|
|
1777
|
+
* The issue type.
|
|
1778
|
+
*/
|
|
1779
|
+
readonly type: 'min_length';
|
|
1780
|
+
/**
|
|
1781
|
+
* The expected property.
|
|
1782
|
+
*/
|
|
1783
|
+
readonly expected: `>=${TRequirement}`;
|
|
1784
|
+
/**
|
|
1785
|
+
* The received property.
|
|
1786
|
+
*/
|
|
1787
|
+
readonly received: `${number}`;
|
|
1788
|
+
/**
|
|
1789
|
+
* The minimum length.
|
|
1790
|
+
*/
|
|
1791
|
+
readonly requirement: TRequirement;
|
|
1792
|
+
}
|
|
1793
|
+
/**
|
|
1794
|
+
* Min length action interface.
|
|
1795
|
+
*/
|
|
1796
|
+
interface MinLengthAction<TInput extends LengthInput, TRequirement extends number, TMessage extends ErrorMessage<MinLengthIssue<TInput, TRequirement>> | undefined> extends BaseValidation<TInput, TInput, MinLengthIssue<TInput, TRequirement>> {
|
|
1797
|
+
/**
|
|
1798
|
+
* The action type.
|
|
1799
|
+
*/
|
|
1800
|
+
readonly type: 'min_length';
|
|
1801
|
+
/**
|
|
1802
|
+
* The action reference.
|
|
1803
|
+
*/
|
|
1804
|
+
readonly reference: typeof minLength;
|
|
1805
|
+
/**
|
|
1806
|
+
* The expected property.
|
|
1807
|
+
*/
|
|
1808
|
+
readonly expects: `>=${TRequirement}`;
|
|
1809
|
+
/**
|
|
1810
|
+
* The minimum length.
|
|
1811
|
+
*/
|
|
1812
|
+
readonly requirement: TRequirement;
|
|
1813
|
+
/**
|
|
1814
|
+
* The error message.
|
|
1815
|
+
*/
|
|
1816
|
+
readonly message: TMessage;
|
|
1817
|
+
}
|
|
1818
|
+
/**
|
|
1819
|
+
* Creates a min length validation action.
|
|
1820
|
+
*
|
|
1821
|
+
* @param requirement The minimum length.
|
|
1822
|
+
*
|
|
1823
|
+
* @returns A min length action.
|
|
1824
|
+
*/
|
|
1825
|
+
declare function minLength<TInput extends LengthInput, const TRequirement extends number>(requirement: TRequirement): MinLengthAction<TInput, TRequirement, undefined>;
|
|
1826
|
+
/**
|
|
1827
|
+
* Creates a min length validation action.
|
|
1828
|
+
*
|
|
1829
|
+
* @param requirement The minimum length.
|
|
1830
|
+
* @param message The error message.
|
|
1831
|
+
*
|
|
1832
|
+
* @returns A min length action.
|
|
1833
|
+
*/
|
|
1834
|
+
declare function minLength<TInput extends LengthInput, const TRequirement extends number, const TMessage extends ErrorMessage<MinLengthIssue<TInput, TRequirement>> | undefined>(requirement: TRequirement, message: TMessage): MinLengthAction<TInput, TRequirement, TMessage>;
|
|
1835
|
+
|
|
1836
|
+
/**
|
|
1837
|
+
* Min size issue interface.
|
|
1838
|
+
*/
|
|
1839
|
+
|
|
1840
|
+
/**
|
|
1841
|
+
* Readonly output type.
|
|
1842
|
+
*/
|
|
1843
|
+
type ReadonlyOutput<TInput> = TInput extends Map<infer TKey, infer TValue> ? ReadonlyMap<TKey, TValue> : TInput extends Set<infer TValue> ? ReadonlySet<TValue> : Readonly<TInput>;
|
|
1844
|
+
/**
|
|
1845
|
+
* Readonly action interface.
|
|
1846
|
+
*/
|
|
1847
|
+
interface ReadonlyAction<TInput> extends BaseTransformation<TInput, ReadonlyOutput<TInput>, never> {
|
|
1848
|
+
/**
|
|
1849
|
+
* The action type.
|
|
1850
|
+
*/
|
|
1851
|
+
readonly type: 'readonly';
|
|
1852
|
+
/**
|
|
1853
|
+
* The action reference.
|
|
1854
|
+
*/
|
|
1855
|
+
readonly reference: typeof readonly;
|
|
1856
|
+
}
|
|
1857
|
+
/**
|
|
1858
|
+
* Creates a readonly transformation action.
|
|
1859
|
+
*
|
|
1860
|
+
* @returns A readonly action.
|
|
1861
|
+
*/
|
|
1862
|
+
declare function readonly<TInput>(): ReadonlyAction<TInput>;
|
|
1863
|
+
|
|
1864
|
+
/**
|
|
1865
|
+
* Array action type.
|
|
1866
|
+
*/
|
|
1867
|
+
|
|
1868
|
+
/**
|
|
1869
|
+
* Regex issue interface.
|
|
1870
|
+
*/
|
|
1871
|
+
interface RegexIssue<TInput extends string> extends BaseIssue<TInput> {
|
|
1872
|
+
/**
|
|
1873
|
+
* The issue kind.
|
|
1874
|
+
*/
|
|
1875
|
+
readonly kind: 'validation';
|
|
1876
|
+
/**
|
|
1877
|
+
* The issue type.
|
|
1878
|
+
*/
|
|
1879
|
+
readonly type: 'regex';
|
|
1880
|
+
/**
|
|
1881
|
+
* The expected input.
|
|
1882
|
+
*/
|
|
1883
|
+
readonly expected: string;
|
|
1884
|
+
/**
|
|
1885
|
+
* The received input.
|
|
1886
|
+
*/
|
|
1887
|
+
readonly received: `"${string}"`;
|
|
1888
|
+
/**
|
|
1889
|
+
* The regex pattern.
|
|
1890
|
+
*/
|
|
1891
|
+
readonly requirement: RegExp;
|
|
1892
|
+
}
|
|
1893
|
+
/**
|
|
1894
|
+
* Regex action interface.
|
|
1895
|
+
*/
|
|
1896
|
+
interface RegexAction<TInput extends string, TMessage extends ErrorMessage<RegexIssue<TInput>> | undefined> extends BaseValidation<TInput, TInput, RegexIssue<TInput>> {
|
|
1897
|
+
/**
|
|
1898
|
+
* The action type.
|
|
1899
|
+
*/
|
|
1900
|
+
readonly type: 'regex';
|
|
1901
|
+
/**
|
|
1902
|
+
* The action reference.
|
|
1903
|
+
*/
|
|
1904
|
+
readonly reference: typeof regex;
|
|
1905
|
+
/**
|
|
1906
|
+
* The expected property.
|
|
1907
|
+
*/
|
|
1908
|
+
readonly expects: string;
|
|
1909
|
+
/**
|
|
1910
|
+
* The regex pattern.
|
|
1911
|
+
*/
|
|
1912
|
+
readonly requirement: RegExp;
|
|
1913
|
+
/**
|
|
1914
|
+
* The error message.
|
|
1915
|
+
*/
|
|
1916
|
+
readonly message: TMessage;
|
|
1917
|
+
}
|
|
1918
|
+
/**
|
|
1919
|
+
* Creates a [regex](https://en.wikipedia.org/wiki/Regular_expression) validation action.
|
|
1920
|
+
*
|
|
1921
|
+
* Hint: Be careful with the global flag `g` in your regex pattern, as it can lead to unexpected results. See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test#using_test_on_a_regex_with_the_global_flag) for more information.
|
|
1922
|
+
*
|
|
1923
|
+
* @param requirement The regex pattern.
|
|
1924
|
+
*
|
|
1925
|
+
* @returns A regex action.
|
|
1926
|
+
*/
|
|
1927
|
+
declare function regex<TInput extends string>(requirement: RegExp): RegexAction<TInput, undefined>;
|
|
1928
|
+
/**
|
|
1929
|
+
* Creates a [regex](https://en.wikipedia.org/wiki/Regular_expression) validation action.
|
|
1930
|
+
*
|
|
1931
|
+
* Hint: Be careful with the global flag `g` in your regex pattern, as it can lead to unexpected results. See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test#using_test_on_a_regex_with_the_global_flag) for more information.
|
|
1932
|
+
*
|
|
1933
|
+
* @param requirement The regex pattern.
|
|
1934
|
+
* @param message The error message.
|
|
1935
|
+
*
|
|
1936
|
+
* @returns A regex action.
|
|
1937
|
+
*/
|
|
1938
|
+
declare function regex<TInput extends string, const TMessage extends ErrorMessage<RegexIssue<TInput>> | undefined>(requirement: RegExp, message: TMessage): RegexAction<TInput, TMessage>;
|
|
1939
|
+
|
|
1940
|
+
/**
|
|
1941
|
+
* Returns action type.
|
|
1942
|
+
*/
|
|
1943
|
+
//#endregion
|
|
1944
|
+
//#region src/_types.d.ts
|
|
1945
|
+
declare const monthlyDateSchema: SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, "Date must be in YYYY-MM format">, BrandAction<string, "MonthlyDate">]>;
|
|
1946
|
+
declare const weeklyDateSchema: SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, "Date must be in YYYY-MM-DD format">, BrandAction<string, "WeeklyDate">]>;
|
|
1947
|
+
type MonthlyDate = InferOutput<typeof monthlyDateSchema>;
|
|
1948
|
+
type WeeklyDate = InferOutput<typeof weeklyDateSchema>;
|
|
1949
|
+
type Bucket = MonthlyDate | WeeklyDate;
|
|
1950
|
+
/**
|
|
1951
|
+
* Available cost calculation modes
|
|
1952
|
+
* - auto: Use pre-calculated costs when available, otherwise calculate from tokens
|
|
1953
|
+
* - calculate: Always calculate costs from token counts using model pricing
|
|
1954
|
+
* - display: Always use pre-calculated costs, show 0 for missing costs
|
|
1955
|
+
*/
|
|
1956
|
+
declare const CostModes: readonly ["auto", "calculate", "display"];
|
|
1957
|
+
/**
|
|
1958
|
+
* Union type for cost calculation modes
|
|
1959
|
+
*/
|
|
1960
|
+
type CostMode = TupleToUnion<typeof CostModes>;
|
|
1961
|
+
/**
|
|
1962
|
+
* Available sort orders for data presentation
|
|
1963
|
+
*/
|
|
1964
|
+
declare const SortOrders: readonly ["desc", "asc"];
|
|
1965
|
+
/**
|
|
1966
|
+
* Union type for sort order options
|
|
1967
|
+
*/
|
|
1968
|
+
type SortOrder = TupleToUnion<typeof SortOrders>;
|
|
1969
|
+
/**
|
|
1970
|
+
* Valibot schema for Claude Code statusline hook JSON data
|
|
1971
|
+
*/
|
|
1972
|
+
//#endregion
|
|
1973
|
+
//#region src/_pricing-fetcher.d.ts
|
|
1974
|
+
declare class PricingFetcher extends LiteLLMPricingFetcher {
|
|
1975
|
+
constructor(offline?: boolean);
|
|
1976
|
+
}
|
|
1977
|
+
//#endregion
|
|
1978
|
+
//#region src/data-loader.d.ts
|
|
1979
|
+
/**
|
|
1980
|
+
* Get Claude data directories to search for usage data
|
|
1981
|
+
* When CLAUDE_CONFIG_DIR is set: uses only those paths
|
|
1982
|
+
* When not set: uses default paths (~/.config/claude and ~/.claude)
|
|
1983
|
+
* @returns Array of valid Claude data directory paths
|
|
1984
|
+
*/
|
|
1985
|
+
declare function getClaudePaths(): string[];
|
|
1986
|
+
/**
|
|
1987
|
+
* Extract project name from Claude JSONL file path
|
|
1988
|
+
* @param jsonlPath - Absolute path to JSONL file
|
|
1989
|
+
* @returns Project name extracted from path, or "unknown" if malformed
|
|
1990
|
+
*/
|
|
1991
|
+
declare function extractProjectFromPath(jsonlPath: string): string;
|
|
1992
|
+
/**
|
|
1993
|
+
* Valibot schema for validating Claude usage data from JSONL files
|
|
1994
|
+
*/
|
|
1995
|
+
declare const usageDataSchema: ObjectSchema<{
|
|
1996
|
+
readonly cwd: OptionalSchema<StringSchema<undefined>, undefined>;
|
|
1997
|
+
readonly sessionId: OptionalSchema<SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Session ID cannot be empty">, BrandAction<string, "SessionId">]>, undefined>;
|
|
1998
|
+
readonly timestamp: SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, "Invalid ISO timestamp">, BrandAction<string, "ISOTimestamp">]>;
|
|
1999
|
+
readonly version: OptionalSchema<SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, "Invalid version format">, BrandAction<string, "Version">]>, undefined>;
|
|
2000
|
+
readonly message: ObjectSchema<{
|
|
2001
|
+
readonly usage: ObjectSchema<{
|
|
2002
|
+
readonly input_tokens: NumberSchema<undefined>;
|
|
2003
|
+
readonly output_tokens: NumberSchema<undefined>;
|
|
2004
|
+
readonly cache_creation_input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
|
|
2005
|
+
readonly cache_read_input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
|
|
2006
|
+
}, undefined>;
|
|
2007
|
+
readonly model: OptionalSchema<SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Model name cannot be empty">, BrandAction<string, "ModelName">]>, undefined>;
|
|
2008
|
+
readonly id: OptionalSchema<SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Message ID cannot be empty">, BrandAction<string, "MessageId">]>, undefined>;
|
|
2009
|
+
readonly content: OptionalSchema<ArraySchema<ObjectSchema<{
|
|
2010
|
+
readonly text: OptionalSchema<StringSchema<undefined>, undefined>;
|
|
2011
|
+
}, undefined>, undefined>, undefined>;
|
|
2012
|
+
}, undefined>;
|
|
2013
|
+
readonly costUSD: OptionalSchema<NumberSchema<undefined>, undefined>;
|
|
2014
|
+
readonly requestId: OptionalSchema<SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Request ID cannot be empty">, BrandAction<string, "RequestId">]>, undefined>;
|
|
2015
|
+
readonly isApiErrorMessage: OptionalSchema<BooleanSchema<undefined>, undefined>;
|
|
2016
|
+
}, undefined>;
|
|
2017
|
+
/**
|
|
2018
|
+
* Valibot schema for transcript usage data from Claude messages
|
|
2019
|
+
*/
|
|
2020
|
+
declare const transcriptUsageSchema: ObjectSchema<{
|
|
2021
|
+
readonly input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
|
|
2022
|
+
readonly cache_creation_input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
|
|
2023
|
+
readonly cache_read_input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
|
|
2024
|
+
readonly output_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
|
|
2025
|
+
}, undefined>;
|
|
2026
|
+
/**
|
|
2027
|
+
* Valibot schema for transcript message data
|
|
2028
|
+
*/
|
|
2029
|
+
declare const transcriptMessageSchema: ObjectSchema<{
|
|
2030
|
+
readonly type: OptionalSchema<StringSchema<undefined>, undefined>;
|
|
2031
|
+
readonly message: OptionalSchema<ObjectSchema<{
|
|
2032
|
+
readonly usage: OptionalSchema<ObjectSchema<{
|
|
2033
|
+
readonly input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
|
|
2034
|
+
readonly cache_creation_input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
|
|
2035
|
+
readonly cache_read_input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
|
|
2036
|
+
readonly output_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
|
|
2037
|
+
}, undefined>, undefined>;
|
|
2038
|
+
}, undefined>, undefined>;
|
|
2039
|
+
}, undefined>;
|
|
2040
|
+
/**
|
|
2041
|
+
* Type definition for Claude usage data entries from JSONL files
|
|
2042
|
+
*/
|
|
2043
|
+
type UsageData = InferOutput<typeof usageDataSchema>;
|
|
2044
|
+
/**
|
|
2045
|
+
* Valibot schema for model-specific usage breakdown data
|
|
2046
|
+
*/
|
|
2047
|
+
declare const modelBreakdownSchema: ObjectSchema<{
|
|
2048
|
+
readonly modelName: SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Model name cannot be empty">, BrandAction<string, "ModelName">]>;
|
|
2049
|
+
readonly inputTokens: NumberSchema<undefined>;
|
|
2050
|
+
readonly outputTokens: NumberSchema<undefined>;
|
|
2051
|
+
readonly cacheCreationTokens: NumberSchema<undefined>;
|
|
2052
|
+
readonly cacheReadTokens: NumberSchema<undefined>;
|
|
2053
|
+
readonly cost: NumberSchema<undefined>;
|
|
2054
|
+
}, undefined>;
|
|
2055
|
+
/**
|
|
2056
|
+
* Type definition for model-specific usage breakdown
|
|
2057
|
+
*/
|
|
2058
|
+
type ModelBreakdown = InferOutput<typeof modelBreakdownSchema>;
|
|
2059
|
+
/**
|
|
2060
|
+
* Valibot schema for daily usage aggregation data
|
|
2061
|
+
*/
|
|
2062
|
+
declare const dailyUsageSchema: ObjectSchema<{
|
|
2063
|
+
readonly date: SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, "Date must be in YYYY-MM-DD format">, BrandAction<string, "DailyDate">]>;
|
|
2064
|
+
readonly inputTokens: NumberSchema<undefined>;
|
|
2065
|
+
readonly outputTokens: NumberSchema<undefined>;
|
|
2066
|
+
readonly cacheCreationTokens: NumberSchema<undefined>;
|
|
2067
|
+
readonly cacheReadTokens: NumberSchema<undefined>;
|
|
2068
|
+
readonly totalCost: NumberSchema<undefined>;
|
|
2069
|
+
readonly modelsUsed: ArraySchema<SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Model name cannot be empty">, BrandAction<string, "ModelName">]>, undefined>;
|
|
2070
|
+
readonly modelBreakdowns: ArraySchema<ObjectSchema<{
|
|
2071
|
+
readonly modelName: SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Model name cannot be empty">, BrandAction<string, "ModelName">]>;
|
|
2072
|
+
readonly inputTokens: NumberSchema<undefined>;
|
|
2073
|
+
readonly outputTokens: NumberSchema<undefined>;
|
|
2074
|
+
readonly cacheCreationTokens: NumberSchema<undefined>;
|
|
2075
|
+
readonly cacheReadTokens: NumberSchema<undefined>;
|
|
2076
|
+
readonly cost: NumberSchema<undefined>;
|
|
2077
|
+
}, undefined>, undefined>;
|
|
2078
|
+
readonly project: OptionalSchema<StringSchema<undefined>, undefined>;
|
|
2079
|
+
}, undefined>;
|
|
2080
|
+
/**
|
|
2081
|
+
* Type definition for daily usage aggregation
|
|
2082
|
+
*/
|
|
2083
|
+
type DailyUsage = InferOutput<typeof dailyUsageSchema>;
|
|
2084
|
+
/**
|
|
2085
|
+
* Valibot schema for session-based usage aggregation data
|
|
2086
|
+
*/
|
|
2087
|
+
declare const sessionUsageSchema: ObjectSchema<{
|
|
2088
|
+
readonly sessionId: SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Session ID cannot be empty">, BrandAction<string, "SessionId">]>;
|
|
2089
|
+
readonly projectPath: SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Project path cannot be empty">, BrandAction<string, "ProjectPath">]>;
|
|
2090
|
+
readonly inputTokens: NumberSchema<undefined>;
|
|
2091
|
+
readonly outputTokens: NumberSchema<undefined>;
|
|
2092
|
+
readonly cacheCreationTokens: NumberSchema<undefined>;
|
|
2093
|
+
readonly cacheReadTokens: NumberSchema<undefined>;
|
|
2094
|
+
readonly totalCost: NumberSchema<undefined>;
|
|
2095
|
+
readonly lastActivity: SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, "Date must be in YYYY-MM-DD format">, BrandAction<string, "ActivityDate">]>;
|
|
2096
|
+
readonly versions: ArraySchema<SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, "Invalid version format">, BrandAction<string, "Version">]>, undefined>;
|
|
2097
|
+
readonly modelsUsed: ArraySchema<SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Model name cannot be empty">, BrandAction<string, "ModelName">]>, undefined>;
|
|
2098
|
+
readonly modelBreakdowns: ArraySchema<ObjectSchema<{
|
|
2099
|
+
readonly modelName: SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Model name cannot be empty">, BrandAction<string, "ModelName">]>;
|
|
2100
|
+
readonly inputTokens: NumberSchema<undefined>;
|
|
2101
|
+
readonly outputTokens: NumberSchema<undefined>;
|
|
2102
|
+
readonly cacheCreationTokens: NumberSchema<undefined>;
|
|
2103
|
+
readonly cacheReadTokens: NumberSchema<undefined>;
|
|
2104
|
+
readonly cost: NumberSchema<undefined>;
|
|
2105
|
+
}, undefined>, undefined>;
|
|
2106
|
+
}, undefined>;
|
|
2107
|
+
/**
|
|
2108
|
+
* Type definition for session-based usage aggregation
|
|
2109
|
+
*/
|
|
2110
|
+
type SessionUsage = InferOutput<typeof sessionUsageSchema>;
|
|
2111
|
+
/**
|
|
2112
|
+
* Valibot schema for monthly usage aggregation data
|
|
2113
|
+
*/
|
|
2114
|
+
declare const monthlyUsageSchema: ObjectSchema<{
|
|
2115
|
+
readonly month: SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, "Date must be in YYYY-MM format">, BrandAction<string, "MonthlyDate">]>;
|
|
2116
|
+
readonly inputTokens: NumberSchema<undefined>;
|
|
2117
|
+
readonly outputTokens: NumberSchema<undefined>;
|
|
2118
|
+
readonly cacheCreationTokens: NumberSchema<undefined>;
|
|
2119
|
+
readonly cacheReadTokens: NumberSchema<undefined>;
|
|
2120
|
+
readonly totalCost: NumberSchema<undefined>;
|
|
2121
|
+
readonly modelsUsed: ArraySchema<SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Model name cannot be empty">, BrandAction<string, "ModelName">]>, undefined>;
|
|
2122
|
+
readonly modelBreakdowns: ArraySchema<ObjectSchema<{
|
|
2123
|
+
readonly modelName: SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Model name cannot be empty">, BrandAction<string, "ModelName">]>;
|
|
2124
|
+
readonly inputTokens: NumberSchema<undefined>;
|
|
2125
|
+
readonly outputTokens: NumberSchema<undefined>;
|
|
2126
|
+
readonly cacheCreationTokens: NumberSchema<undefined>;
|
|
2127
|
+
readonly cacheReadTokens: NumberSchema<undefined>;
|
|
2128
|
+
readonly cost: NumberSchema<undefined>;
|
|
2129
|
+
}, undefined>, undefined>;
|
|
2130
|
+
readonly project: OptionalSchema<StringSchema<undefined>, undefined>;
|
|
2131
|
+
}, undefined>;
|
|
2132
|
+
/**
|
|
2133
|
+
* Type definition for monthly usage aggregation
|
|
2134
|
+
*/
|
|
2135
|
+
type MonthlyUsage = InferOutput<typeof monthlyUsageSchema>;
|
|
2136
|
+
/**
|
|
2137
|
+
* Valibot schema for weekly usage aggregation data
|
|
2138
|
+
*/
|
|
2139
|
+
declare const weeklyUsageSchema: ObjectSchema<{
|
|
2140
|
+
readonly week: SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, "Date must be in YYYY-MM-DD format">, BrandAction<string, "WeeklyDate">]>;
|
|
2141
|
+
readonly inputTokens: NumberSchema<undefined>;
|
|
2142
|
+
readonly outputTokens: NumberSchema<undefined>;
|
|
2143
|
+
readonly cacheCreationTokens: NumberSchema<undefined>;
|
|
2144
|
+
readonly cacheReadTokens: NumberSchema<undefined>;
|
|
2145
|
+
readonly totalCost: NumberSchema<undefined>;
|
|
2146
|
+
readonly modelsUsed: ArraySchema<SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Model name cannot be empty">, BrandAction<string, "ModelName">]>, undefined>;
|
|
2147
|
+
readonly modelBreakdowns: ArraySchema<ObjectSchema<{
|
|
2148
|
+
readonly modelName: SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Model name cannot be empty">, BrandAction<string, "ModelName">]>;
|
|
2149
|
+
readonly inputTokens: NumberSchema<undefined>;
|
|
2150
|
+
readonly outputTokens: NumberSchema<undefined>;
|
|
2151
|
+
readonly cacheCreationTokens: NumberSchema<undefined>;
|
|
2152
|
+
readonly cacheReadTokens: NumberSchema<undefined>;
|
|
2153
|
+
readonly cost: NumberSchema<undefined>;
|
|
2154
|
+
}, undefined>, undefined>;
|
|
2155
|
+
readonly project: OptionalSchema<StringSchema<undefined>, undefined>;
|
|
2156
|
+
}, undefined>;
|
|
2157
|
+
/**
|
|
2158
|
+
* Type definition for weekly usage aggregation
|
|
2159
|
+
*/
|
|
2160
|
+
type WeeklyUsage = InferOutput<typeof weeklyUsageSchema>;
|
|
2161
|
+
/**
|
|
2162
|
+
* Valibot schema for bucket usage aggregation data
|
|
2163
|
+
*/
|
|
2164
|
+
declare const bucketUsageSchema: ObjectSchema<{
|
|
2165
|
+
readonly bucket: UnionSchema<[SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, "Date must be in YYYY-MM-DD format">, BrandAction<string, "WeeklyDate">]>, SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, "Date must be in YYYY-MM format">, BrandAction<string, "MonthlyDate">]>], undefined>;
|
|
2166
|
+
readonly inputTokens: NumberSchema<undefined>;
|
|
2167
|
+
readonly outputTokens: NumberSchema<undefined>;
|
|
2168
|
+
readonly cacheCreationTokens: NumberSchema<undefined>;
|
|
2169
|
+
readonly cacheReadTokens: NumberSchema<undefined>;
|
|
2170
|
+
readonly totalCost: NumberSchema<undefined>;
|
|
2171
|
+
readonly modelsUsed: ArraySchema<SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Model name cannot be empty">, BrandAction<string, "ModelName">]>, undefined>;
|
|
2172
|
+
readonly modelBreakdowns: ArraySchema<ObjectSchema<{
|
|
2173
|
+
readonly modelName: SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Model name cannot be empty">, BrandAction<string, "ModelName">]>;
|
|
2174
|
+
readonly inputTokens: NumberSchema<undefined>;
|
|
2175
|
+
readonly outputTokens: NumberSchema<undefined>;
|
|
2176
|
+
readonly cacheCreationTokens: NumberSchema<undefined>;
|
|
2177
|
+
readonly cacheReadTokens: NumberSchema<undefined>;
|
|
2178
|
+
readonly cost: NumberSchema<undefined>;
|
|
2179
|
+
}, undefined>, undefined>;
|
|
2180
|
+
readonly project: OptionalSchema<StringSchema<undefined>, undefined>;
|
|
2181
|
+
}, undefined>;
|
|
2182
|
+
/**
|
|
2183
|
+
* Type definition for bucket usage aggregation
|
|
2184
|
+
*/
|
|
2185
|
+
type BucketUsage = InferOutput<typeof bucketUsageSchema>;
|
|
2186
|
+
/**
|
|
2187
|
+
* Create a unique identifier for deduplication using message ID and request ID
|
|
2188
|
+
*/
|
|
2189
|
+
declare function createUniqueHash(data: UsageData): string | null;
|
|
2190
|
+
/**
|
|
2191
|
+
* Extract the earliest timestamp from a JSONL file
|
|
2192
|
+
* Scans through the file until it finds a valid timestamp
|
|
2193
|
+
*/
|
|
2194
|
+
declare function getEarliestTimestamp(filePath: string): Promise<Date | null>;
|
|
2195
|
+
/**
|
|
2196
|
+
* Sort files by their earliest timestamp
|
|
2197
|
+
* Files without valid timestamps are placed at the end
|
|
2198
|
+
*/
|
|
2199
|
+
declare function sortFilesByTimestamp(files: string[]): Promise<string[]>;
|
|
2200
|
+
/**
|
|
2201
|
+
* Calculates cost for a single usage data entry based on the specified cost calculation mode
|
|
2202
|
+
* @param data - Usage data entry
|
|
2203
|
+
* @param mode - Cost calculation mode (auto, calculate, or display)
|
|
2204
|
+
* @param fetcher - Pricing fetcher instance for calculating costs from tokens
|
|
2205
|
+
* @returns Calculated cost in USD
|
|
2206
|
+
*/
|
|
2207
|
+
declare function calculateCostForEntry(data: UsageData, mode: CostMode, fetcher: PricingFetcher): Promise<number>;
|
|
2208
|
+
/**
|
|
2209
|
+
* Get Claude Code usage limit expiration date
|
|
2210
|
+
* @param data - Usage data entry
|
|
2211
|
+
* @returns Usage limit expiration date
|
|
2212
|
+
*/
|
|
2213
|
+
declare function getUsageLimitResetTime(data: UsageData): Date | null;
|
|
2214
|
+
/**
|
|
2215
|
+
* Result of glob operation with base directory information
|
|
2216
|
+
*/
|
|
2217
|
+
type GlobResult = {
|
|
2218
|
+
file: string;
|
|
2219
|
+
baseDir: string;
|
|
2220
|
+
};
|
|
2221
|
+
/**
|
|
2222
|
+
* Glob files from multiple Claude paths in parallel
|
|
2223
|
+
* @param claudePaths - Array of Claude base paths
|
|
2224
|
+
* @returns Array of file paths with their base directories
|
|
2225
|
+
*/
|
|
2226
|
+
declare function globUsageFiles(claudePaths: string[]): Promise<GlobResult[]>;
|
|
2227
|
+
/**
|
|
2228
|
+
* Date range filter for limiting usage data by date
|
|
2229
|
+
*/
|
|
2230
|
+
type DateFilter = {
|
|
2231
|
+
since?: string;
|
|
2232
|
+
until?: string;
|
|
2233
|
+
};
|
|
2234
|
+
/**
|
|
2235
|
+
* Configuration options for loading usage data
|
|
2236
|
+
*/
|
|
2237
|
+
type LoadOptions = {
|
|
2238
|
+
claudePath?: string;
|
|
2239
|
+
mode?: CostMode;
|
|
2240
|
+
order?: SortOrder;
|
|
2241
|
+
offline?: boolean;
|
|
2242
|
+
sessionDurationHours?: number;
|
|
2243
|
+
groupByProject?: boolean;
|
|
2244
|
+
project?: string;
|
|
2245
|
+
startOfWeek?: WeekDay;
|
|
2246
|
+
timezone?: string;
|
|
2247
|
+
locale?: string;
|
|
2248
|
+
} & DateFilter;
|
|
2249
|
+
/**
|
|
2250
|
+
* Loads and aggregates Claude usage data by day
|
|
2251
|
+
* Processes all JSONL files in the Claude projects directory and groups usage by date
|
|
2252
|
+
* @param options - Optional configuration for loading and filtering data
|
|
2253
|
+
* @returns Array of daily usage summaries sorted by date
|
|
2254
|
+
*/
|
|
2255
|
+
declare function loadDailyUsageData(options?: LoadOptions): Promise<DailyUsage[]>;
|
|
2256
|
+
/**
|
|
2257
|
+
* Loads and aggregates Claude usage data by session
|
|
2258
|
+
* Groups usage data by project path and session ID based on file structure
|
|
2259
|
+
* @param options - Optional configuration for loading and filtering data
|
|
2260
|
+
* @returns Array of session usage summaries sorted by last activity
|
|
2261
|
+
*/
|
|
2262
|
+
declare function loadSessionData(options?: LoadOptions): Promise<SessionUsage[]>;
|
|
2263
|
+
/**
|
|
2264
|
+
* Loads and aggregates Claude usage data by month
|
|
2265
|
+
* Uses daily usage data as the source and groups by month
|
|
2266
|
+
* @param options - Optional configuration for loading and filtering data
|
|
2267
|
+
* @returns Array of monthly usage summaries sorted by month
|
|
2268
|
+
*/
|
|
2269
|
+
declare function loadMonthlyUsageData(options?: LoadOptions): Promise<MonthlyUsage[]>;
|
|
2270
|
+
declare function loadWeeklyUsageData(options?: LoadOptions): Promise<WeeklyUsage[]>;
|
|
2271
|
+
/**
|
|
2272
|
+
* Load usage data for a specific session by sessionId
|
|
2273
|
+
* Searches for a JSONL file named {sessionId}.jsonl in all Claude project directories
|
|
2274
|
+
* @param sessionId - The session ID to load data for (matches the JSONL filename)
|
|
2275
|
+
* @param options - Options for loading data
|
|
2276
|
+
* @param options.mode - Cost calculation mode (auto, calculate, display)
|
|
2277
|
+
* @param options.offline - Whether to use offline pricing data
|
|
2278
|
+
* @returns Usage data for the specific session or null if not found
|
|
2279
|
+
*/
|
|
2280
|
+
declare function loadSessionUsageById(sessionId: string, options?: {
|
|
2281
|
+
mode?: CostMode;
|
|
2282
|
+
offline?: boolean;
|
|
2283
|
+
}): Promise<{
|
|
2284
|
+
totalCost: number;
|
|
2285
|
+
entries: UsageData[];
|
|
2286
|
+
} | null>;
|
|
2287
|
+
declare function loadBucketUsageData(groupingFn: (data: DailyUsage) => Bucket, options?: LoadOptions): Promise<BucketUsage[]>;
|
|
2288
|
+
/**
|
|
2289
|
+
* Calculate context tokens from transcript file using improved JSONL parsing
|
|
2290
|
+
* Based on the Python reference implementation for better accuracy
|
|
2291
|
+
* @param transcriptPath - Path to the transcript JSONL file
|
|
2292
|
+
* @returns Object with context tokens info or null if unavailable
|
|
2293
|
+
*/
|
|
2294
|
+
declare function calculateContextTokens(transcriptPath: string, modelId?: string, offline?: boolean): Promise<{
|
|
2295
|
+
inputTokens: number;
|
|
2296
|
+
percentage: number;
|
|
2297
|
+
contextLimit: number;
|
|
2298
|
+
} | null>;
|
|
2299
|
+
/**
|
|
2300
|
+
* Loads usage data and organizes it into session blocks (typically 5-hour billing periods)
|
|
2301
|
+
* Processes all usage data and groups it into time-based blocks for billing analysis
|
|
2302
|
+
* @param options - Optional configuration including session duration and filtering
|
|
2303
|
+
* @returns Array of session blocks with usage and cost information
|
|
2304
|
+
*/
|
|
2305
|
+
declare function loadSessionBlockData(options?: LoadOptions): Promise<SessionBlock[]>;
|
|
2306
|
+
//#endregion
|
|
2307
|
+
export { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema };
|