ccusage 0.4.0 → 0.4.2

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.
@@ -0,0 +1,462 @@
1
+ //#region node_modules/valibot/dist/index.js
2
+ var store;
3
+ /* @__NO_SIDE_EFFECTS__ */
4
+ function getGlobalConfig(config2) {
5
+ return {
6
+ lang: config2?.lang ?? store?.lang,
7
+ message: config2?.message,
8
+ abortEarly: config2?.abortEarly ?? store?.abortEarly,
9
+ abortPipeEarly: config2?.abortPipeEarly ?? store?.abortPipeEarly
10
+ };
11
+ }
12
+ var store2;
13
+ /* @__NO_SIDE_EFFECTS__ */
14
+ function getGlobalMessage(lang) {
15
+ return store2?.get(lang);
16
+ }
17
+ var store3;
18
+ /* @__NO_SIDE_EFFECTS__ */
19
+ function getSchemaMessage(lang) {
20
+ return store3?.get(lang);
21
+ }
22
+ var store4;
23
+ /* @__NO_SIDE_EFFECTS__ */
24
+ function getSpecificMessage(reference, lang) {
25
+ return store4?.get(reference)?.get(lang);
26
+ }
27
+ /* @__NO_SIDE_EFFECTS__ */
28
+ function _stringify(input) {
29
+ const type = typeof input;
30
+ if (type === "string") return `"${input}"`;
31
+ if (type === "number" || type === "bigint" || type === "boolean") return `${input}`;
32
+ if (type === "object" || type === "function") return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null";
33
+ return type;
34
+ }
35
+ function _addIssue(context, label, dataset, config2, other) {
36
+ const input = other && "input" in other ? other.input : dataset.value;
37
+ const expected = other?.expected ?? context.expects ?? null;
38
+ const received = other?.received ?? /* @__PURE__ */ _stringify(input);
39
+ const issue = {
40
+ kind: context.kind,
41
+ type: context.type,
42
+ input,
43
+ expected,
44
+ received,
45
+ message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
46
+ requirement: context.requirement,
47
+ path: other?.path,
48
+ issues: other?.issues,
49
+ lang: config2.lang,
50
+ abortEarly: config2.abortEarly,
51
+ abortPipeEarly: config2.abortPipeEarly
52
+ };
53
+ const isSchema = context.kind === "schema";
54
+ const message2 = other?.message ?? context.message ?? /* @__PURE__ */ getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? /* @__PURE__ */ getSchemaMessage(issue.lang) : null) ?? config2.message ?? /* @__PURE__ */ getGlobalMessage(issue.lang);
55
+ if (message2 !== void 0) issue.message = typeof message2 === "function" ? message2(issue) : message2;
56
+ if (isSchema) dataset.typed = false;
57
+ if (dataset.issues) dataset.issues.push(issue);
58
+ else dataset.issues = [issue];
59
+ }
60
+ /* @__NO_SIDE_EFFECTS__ */
61
+ function _getStandardProps(context) {
62
+ return {
63
+ version: 1,
64
+ vendor: "valibot",
65
+ validate(value2) {
66
+ return context["~run"]({ value: value2 }, /* @__PURE__ */ getGlobalConfig());
67
+ }
68
+ };
69
+ }
70
+ /* @__NO_SIDE_EFFECTS__ */
71
+ function _isValidObjectKey(object2, key) {
72
+ return Object.hasOwn(object2, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
73
+ }
74
+ /* @__NO_SIDE_EFFECTS__ */
75
+ function _joinExpects(values2, separator) {
76
+ const list = [...new Set(values2)];
77
+ if (list.length > 1) return `(${list.join(` ${separator} `)})`;
78
+ return list[0] ?? "never";
79
+ }
80
+ var ValiError = class extends Error {
81
+ /**
82
+ * Creates a Valibot error with useful information.
83
+ *
84
+ * @param issues The error issues.
85
+ */
86
+ constructor(issues) {
87
+ super(issues[0].message);
88
+ this.name = "ValiError";
89
+ this.issues = issues;
90
+ }
91
+ };
92
+ /* @__NO_SIDE_EFFECTS__ */
93
+ function regex(requirement, message2) {
94
+ return {
95
+ kind: "validation",
96
+ type: "regex",
97
+ reference: regex,
98
+ async: false,
99
+ expects: `${requirement}`,
100
+ requirement,
101
+ message: message2,
102
+ "~run"(dataset, config2) {
103
+ if (dataset.typed && !this.requirement.test(dataset.value)) _addIssue(this, "format", dataset, config2);
104
+ return dataset;
105
+ }
106
+ };
107
+ }
108
+ /* @__NO_SIDE_EFFECTS__ */
109
+ function getFallback(schema, dataset, config2) {
110
+ return typeof schema.fallback === "function" ? schema.fallback(dataset, config2) : schema.fallback;
111
+ }
112
+ /* @__NO_SIDE_EFFECTS__ */
113
+ function getDefault(schema, dataset, config2) {
114
+ return typeof schema.default === "function" ? schema.default(dataset, config2) : schema.default;
115
+ }
116
+ /* @__NO_SIDE_EFFECTS__ */
117
+ function array(item, message2) {
118
+ return {
119
+ kind: "schema",
120
+ type: "array",
121
+ reference: array,
122
+ expects: "Array",
123
+ async: false,
124
+ item,
125
+ message: message2,
126
+ get "~standard"() {
127
+ return /* @__PURE__ */ _getStandardProps(this);
128
+ },
129
+ "~run"(dataset, config2) {
130
+ const input = dataset.value;
131
+ if (Array.isArray(input)) {
132
+ dataset.typed = true;
133
+ dataset.value = [];
134
+ for (let key = 0; key < input.length; key++) {
135
+ const value2 = input[key];
136
+ const itemDataset = this.item["~run"]({ value: value2 }, config2);
137
+ if (itemDataset.issues) {
138
+ const pathItem = {
139
+ type: "array",
140
+ origin: "value",
141
+ input,
142
+ key,
143
+ value: value2
144
+ };
145
+ for (const issue of itemDataset.issues) {
146
+ if (issue.path) issue.path.unshift(pathItem);
147
+ else issue.path = [pathItem];
148
+ dataset.issues?.push(issue);
149
+ }
150
+ if (!dataset.issues) dataset.issues = itemDataset.issues;
151
+ if (config2.abortEarly) {
152
+ dataset.typed = false;
153
+ break;
154
+ }
155
+ }
156
+ if (!itemDataset.typed) dataset.typed = false;
157
+ dataset.value.push(itemDataset.value);
158
+ }
159
+ } else _addIssue(this, "type", dataset, config2);
160
+ return dataset;
161
+ }
162
+ };
163
+ }
164
+ /* @__NO_SIDE_EFFECTS__ */
165
+ function boolean(message2) {
166
+ return {
167
+ kind: "schema",
168
+ type: "boolean",
169
+ reference: boolean,
170
+ expects: "boolean",
171
+ async: false,
172
+ message: message2,
173
+ get "~standard"() {
174
+ return /* @__PURE__ */ _getStandardProps(this);
175
+ },
176
+ "~run"(dataset, config2) {
177
+ if (typeof dataset.value === "boolean") dataset.typed = true;
178
+ else _addIssue(this, "type", dataset, config2);
179
+ return dataset;
180
+ }
181
+ };
182
+ }
183
+ /* @__NO_SIDE_EFFECTS__ */
184
+ function number(message2) {
185
+ return {
186
+ kind: "schema",
187
+ type: "number",
188
+ reference: number,
189
+ expects: "number",
190
+ async: false,
191
+ message: message2,
192
+ get "~standard"() {
193
+ return /* @__PURE__ */ _getStandardProps(this);
194
+ },
195
+ "~run"(dataset, config2) {
196
+ if (typeof dataset.value === "number" && !isNaN(dataset.value)) dataset.typed = true;
197
+ else _addIssue(this, "type", dataset, config2);
198
+ return dataset;
199
+ }
200
+ };
201
+ }
202
+ /* @__NO_SIDE_EFFECTS__ */
203
+ function object(entries2, message2) {
204
+ return {
205
+ kind: "schema",
206
+ type: "object",
207
+ reference: object,
208
+ expects: "Object",
209
+ async: false,
210
+ entries: entries2,
211
+ message: message2,
212
+ get "~standard"() {
213
+ return /* @__PURE__ */ _getStandardProps(this);
214
+ },
215
+ "~run"(dataset, config2) {
216
+ const input = dataset.value;
217
+ if (input && typeof input === "object") {
218
+ dataset.typed = true;
219
+ dataset.value = {};
220
+ for (const key in this.entries) {
221
+ const valueSchema = this.entries[key];
222
+ if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
223
+ const value2 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
224
+ const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
225
+ if (valueDataset.issues) {
226
+ const pathItem = {
227
+ type: "object",
228
+ origin: "value",
229
+ input,
230
+ key,
231
+ value: value2
232
+ };
233
+ for (const issue of valueDataset.issues) {
234
+ if (issue.path) issue.path.unshift(pathItem);
235
+ else issue.path = [pathItem];
236
+ dataset.issues?.push(issue);
237
+ }
238
+ if (!dataset.issues) dataset.issues = valueDataset.issues;
239
+ if (config2.abortEarly) {
240
+ dataset.typed = false;
241
+ break;
242
+ }
243
+ }
244
+ if (!valueDataset.typed) dataset.typed = false;
245
+ dataset.value[key] = valueDataset.value;
246
+ } else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
247
+ else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
248
+ _addIssue(this, "key", dataset, config2, {
249
+ input: void 0,
250
+ expected: `"${key}"`,
251
+ path: [{
252
+ type: "object",
253
+ origin: "key",
254
+ input,
255
+ key,
256
+ value: input[key]
257
+ }]
258
+ });
259
+ if (config2.abortEarly) break;
260
+ }
261
+ }
262
+ } else _addIssue(this, "type", dataset, config2);
263
+ return dataset;
264
+ }
265
+ };
266
+ }
267
+ /* @__NO_SIDE_EFFECTS__ */
268
+ function optional(wrapped, default_) {
269
+ return {
270
+ kind: "schema",
271
+ type: "optional",
272
+ reference: optional,
273
+ expects: `(${wrapped.expects} | undefined)`,
274
+ async: false,
275
+ wrapped,
276
+ default: default_,
277
+ get "~standard"() {
278
+ return /* @__PURE__ */ _getStandardProps(this);
279
+ },
280
+ "~run"(dataset, config2) {
281
+ if (dataset.value === void 0) {
282
+ if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2);
283
+ if (dataset.value === void 0) {
284
+ dataset.typed = true;
285
+ return dataset;
286
+ }
287
+ }
288
+ return this.wrapped["~run"](dataset, config2);
289
+ }
290
+ };
291
+ }
292
+ /* @__NO_SIDE_EFFECTS__ */
293
+ function record(key, value2, message2) {
294
+ return {
295
+ kind: "schema",
296
+ type: "record",
297
+ reference: record,
298
+ expects: "Object",
299
+ async: false,
300
+ key,
301
+ value: value2,
302
+ message: message2,
303
+ get "~standard"() {
304
+ return /* @__PURE__ */ _getStandardProps(this);
305
+ },
306
+ "~run"(dataset, config2) {
307
+ const input = dataset.value;
308
+ if (input && typeof input === "object") {
309
+ dataset.typed = true;
310
+ dataset.value = {};
311
+ for (const entryKey in input) if (/* @__PURE__ */ _isValidObjectKey(input, entryKey)) {
312
+ const entryValue = input[entryKey];
313
+ const keyDataset = this.key["~run"]({ value: entryKey }, config2);
314
+ if (keyDataset.issues) {
315
+ const pathItem = {
316
+ type: "object",
317
+ origin: "key",
318
+ input,
319
+ key: entryKey,
320
+ value: entryValue
321
+ };
322
+ for (const issue of keyDataset.issues) {
323
+ issue.path = [pathItem];
324
+ dataset.issues?.push(issue);
325
+ }
326
+ if (!dataset.issues) dataset.issues = keyDataset.issues;
327
+ if (config2.abortEarly) {
328
+ dataset.typed = false;
329
+ break;
330
+ }
331
+ }
332
+ const valueDataset = this.value["~run"]({ value: entryValue }, config2);
333
+ if (valueDataset.issues) {
334
+ const pathItem = {
335
+ type: "object",
336
+ origin: "value",
337
+ input,
338
+ key: entryKey,
339
+ value: entryValue
340
+ };
341
+ for (const issue of valueDataset.issues) {
342
+ if (issue.path) issue.path.unshift(pathItem);
343
+ else issue.path = [pathItem];
344
+ dataset.issues?.push(issue);
345
+ }
346
+ if (!dataset.issues) dataset.issues = valueDataset.issues;
347
+ if (config2.abortEarly) {
348
+ dataset.typed = false;
349
+ break;
350
+ }
351
+ }
352
+ if (!keyDataset.typed || !valueDataset.typed) dataset.typed = false;
353
+ if (keyDataset.typed) dataset.value[keyDataset.value] = valueDataset.value;
354
+ }
355
+ } else _addIssue(this, "type", dataset, config2);
356
+ return dataset;
357
+ }
358
+ };
359
+ }
360
+ /* @__NO_SIDE_EFFECTS__ */
361
+ function string(message2) {
362
+ return {
363
+ kind: "schema",
364
+ type: "string",
365
+ reference: string,
366
+ expects: "string",
367
+ async: false,
368
+ message: message2,
369
+ get "~standard"() {
370
+ return /* @__PURE__ */ _getStandardProps(this);
371
+ },
372
+ "~run"(dataset, config2) {
373
+ if (typeof dataset.value === "string") dataset.typed = true;
374
+ else _addIssue(this, "type", dataset, config2);
375
+ return dataset;
376
+ }
377
+ };
378
+ }
379
+ /* @__NO_SIDE_EFFECTS__ */
380
+ function _subIssues(datasets) {
381
+ let issues;
382
+ if (datasets) for (const dataset of datasets) if (issues) issues.push(...dataset.issues);
383
+ else issues = dataset.issues;
384
+ return issues;
385
+ }
386
+ /* @__NO_SIDE_EFFECTS__ */
387
+ function union(options, message2) {
388
+ return {
389
+ kind: "schema",
390
+ type: "union",
391
+ reference: union,
392
+ expects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), "|"),
393
+ async: false,
394
+ options,
395
+ message: message2,
396
+ get "~standard"() {
397
+ return /* @__PURE__ */ _getStandardProps(this);
398
+ },
399
+ "~run"(dataset, config2) {
400
+ let validDataset;
401
+ let typedDatasets;
402
+ let untypedDatasets;
403
+ for (const schema of this.options) {
404
+ const optionDataset = schema["~run"]({ value: dataset.value }, config2);
405
+ if (optionDataset.typed) if (optionDataset.issues) if (typedDatasets) typedDatasets.push(optionDataset);
406
+ else typedDatasets = [optionDataset];
407
+ else {
408
+ validDataset = optionDataset;
409
+ break;
410
+ }
411
+ else if (untypedDatasets) untypedDatasets.push(optionDataset);
412
+ else untypedDatasets = [optionDataset];
413
+ }
414
+ if (validDataset) return validDataset;
415
+ if (typedDatasets) {
416
+ if (typedDatasets.length === 1) return typedDatasets[0];
417
+ _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(typedDatasets) });
418
+ dataset.typed = true;
419
+ } else if (untypedDatasets?.length === 1) return untypedDatasets[0];
420
+ else _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(untypedDatasets) });
421
+ return dataset;
422
+ }
423
+ };
424
+ }
425
+ function parse(schema, input, config2) {
426
+ const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config2));
427
+ if (dataset.issues) throw new ValiError(dataset.issues);
428
+ return dataset.value;
429
+ }
430
+ /* @__NO_SIDE_EFFECTS__ */
431
+ function pipe(...pipe2) {
432
+ return {
433
+ ...pipe2[0],
434
+ pipe: pipe2,
435
+ get "~standard"() {
436
+ return /* @__PURE__ */ _getStandardProps(this);
437
+ },
438
+ "~run"(dataset, config2) {
439
+ for (const item of pipe2) if (item.kind !== "metadata") {
440
+ if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
441
+ dataset.typed = false;
442
+ break;
443
+ }
444
+ if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) dataset = item["~run"](dataset, config2);
445
+ }
446
+ return dataset;
447
+ }
448
+ };
449
+ }
450
+ /* @__NO_SIDE_EFFECTS__ */
451
+ function safeParse(schema, input, config2) {
452
+ const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config2));
453
+ return {
454
+ typed: dataset.typed,
455
+ success: !dataset.issues,
456
+ output: dataset.value,
457
+ issues: dataset.issues
458
+ };
459
+ }
460
+
461
+ //#endregion
462
+ export { array, boolean, number, object, optional, parse, pipe, record, regex, safeParse, string, union };