@nubase/core 0.1.0 → 0.1.3

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/dist/index.d.mts CHANGED
@@ -1,8 +1,44 @@
1
+ import { z } from 'zod';
2
+
3
+ interface HttpResponse<T = any> {
4
+ status: number;
5
+ data: T;
6
+ }
7
+ interface HttpRequestConfig {
8
+ headers?: Record<string, string>;
9
+ timeout?: number;
10
+ params?: Record<string, any>;
11
+ }
12
+ declare class HttpClient {
13
+ private baseUrl;
14
+ constructor({ baseUrl }: {
15
+ baseUrl?: string;
16
+ });
17
+ private request;
18
+ get<T>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
19
+ post<T>(url: string, data?: any, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
20
+ put<T>(url: string, data?: any, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
21
+ patch<T>(url: string, data?: any, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
22
+ delete<T>(url: string, data?: any, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
23
+ }
24
+
1
25
  interface SchemaMetadata<Output = any> {
2
26
  label?: string;
3
27
  description?: string;
4
28
  defaultValue?: Output;
29
+ /**
30
+ * Custom renderer identifier to override the default type-based rendering.
31
+ * Examples: "multiline", "email", "password", "url"
32
+ */
33
+ renderer?: string;
34
+ validateOnSubmit?: (value: any) => string | undefined;
35
+ validateOnSubmitAsync?: (value: any) => Promise<string | undefined>;
36
+ validateOnBlur?: (value: any) => string | undefined;
37
+ validateOnBlurAsync?: (value: any) => Promise<string | undefined>;
5
38
  }
39
+ type ComputedSchemaMetadata<Output = any, Input = any> = {
40
+ [K in keyof SchemaMetadata<Output>]: (input: Input) => Promise<SchemaMetadata<Output>[K]>;
41
+ };
6
42
  declare abstract class BaseSchema<Output = any> {
7
43
  /**
8
44
  * Phantom property used for TypeScript type inference.
@@ -10,30 +46,61 @@ declare abstract class BaseSchema<Output = any> {
10
46
  * @internal
11
47
  */
12
48
  readonly _outputType: Output;
49
+ /**
50
+ * The type identifier for this schema.
51
+ * Used for type-based form field rendering.
52
+ */
53
+ abstract readonly type: string;
13
54
  _meta: SchemaMetadata<Output>;
14
55
  /**
15
56
  * Replace the schema metadata with a new object.
16
57
  * @param meta The new metadata object.
17
58
  * @returns The schema instance for chaining.
18
59
  */
19
- meta(meta: SchemaMetadata<Output>): this;
60
+ withMeta(meta: SchemaMetadata<Output>): this;
20
61
  /**
21
- * Parses and validates the input data against the schema.
22
- * Should throw an error if validation fails.
23
- * @param data The data to parse.
24
- * @returns The parsed data (potentially transformed).
62
+ * Add metadata with validation functions to the schema.
63
+ * @param meta The metadata object with validation functions.
64
+ * @returns The schema instance for chaining.
25
65
  */
26
- abstract parse(data: any): Output;
66
+ withMetadata(meta: SchemaMetadata<Output>): this;
67
+ /**
68
+ * Makes this schema optional, allowing undefined values.
69
+ * @returns An OptionalSchema wrapping this schema.
70
+ */
71
+ optional(): OptionalSchema<this>;
72
+ /**
73
+ * Converts this nubase schema to a Zod schema.
74
+ * @returns The equivalent Zod schema.
75
+ */
76
+ abstract toZod(): z.ZodSchema<Output>;
27
77
  }
28
-
29
78
  declare class BooleanSchema extends BaseSchema<boolean> {
30
- parse(data: any): boolean;
79
+ readonly type: "boolean";
80
+ toZod(): z.ZodBoolean;
31
81
  }
32
82
  declare class StringSchema extends BaseSchema<string> {
33
- parse(data: any): string;
83
+ readonly type: "string";
84
+ toZod(): z.ZodString;
34
85
  }
35
86
  declare class NumberSchema extends BaseSchema<number> {
36
- parse(data: any): number;
87
+ readonly type: "number";
88
+ toZod(): z.ZodNumber;
89
+ }
90
+ /**
91
+ * A wrapper schema that makes the wrapped schema optional.
92
+ * Allows undefined values in addition to the wrapped schema's type.
93
+ */
94
+ declare class OptionalSchema<TWrapped extends BaseSchema<any>> extends BaseSchema<TWrapped["_outputType"] | undefined> {
95
+ readonly type: "optional";
96
+ _wrapped: TWrapped;
97
+ constructor(wrapped: TWrapped);
98
+ /**
99
+ * Get the underlying wrapped schema.
100
+ * @returns The wrapped schema.
101
+ */
102
+ unwrap(): TWrapped;
103
+ toZod(): z.ZodOptional<z.ZodNullable<z.ZodSchema<TWrapped["_outputType"]>>>;
37
104
  }
38
105
  /**
39
106
  * Type representing the shape of an object schema (key to schema mapping).
@@ -44,25 +111,356 @@ type ObjectShape = {
44
111
  /**
45
112
  * Infers the TypeScript output type from an ObjectShape.
46
113
  * Use mapped types to get the output type of each property schema.
114
+ * Required keys are those that are not OptionalSchema instances.
115
+ * Optional keys are those that are OptionalSchema instances.
47
116
  */
48
117
  type ObjectOutput<TShape extends ObjectShape> = {
49
- [K in keyof TShape]: TShape[K]['_outputType'];
118
+ [K in keyof TShape as TShape[K] extends OptionalSchema<any> ? never : K]: TShape[K]["_outputType"];
119
+ } & {
120
+ [K in keyof TShape as TShape[K] extends OptionalSchema<any> ? K : never]?: TShape[K]["_outputType"];
121
+ };
122
+ /**
123
+ * Type representing computed metadata for object properties.
124
+ */
125
+ type ObjectComputedMetadata<TShape extends ObjectShape> = {
126
+ [K in keyof TShape]?: Partial<ComputedSchemaMetadata<TShape[K]["_outputType"], ObjectOutput<TShape>>>;
127
+ };
128
+ /**
129
+ * Represents a field within a layout group.
130
+ */
131
+ interface FormLayoutField<TShape extends ObjectShape> {
132
+ /** The name of the field - must be a valid property key from the object shape */
133
+ name: keyof TShape;
134
+ /** Width of the field in grid units (1-12) - number of 1/12 spaces it occupies */
135
+ fieldWidth?: number;
136
+ /** Additional CSS classes for styling */
137
+ className?: string;
138
+ /** Whether the field should be hidden */
139
+ hidden?: boolean;
140
+ }
141
+ /**
142
+ * Represents a group of fields within a layout.
143
+ */
144
+ interface LayoutGroup<TShape extends ObjectShape> {
145
+ /** Label for the group */
146
+ label?: string;
147
+ /** Description for the group */
148
+ description?: string;
149
+ /** Array of fields in this group */
150
+ fields: FormLayoutField<TShape>[];
151
+ /** Additional CSS classes for the group */
152
+ className?: string;
153
+ /** Whether the group should be collapsible */
154
+ collapsible?: boolean;
155
+ /** Whether the group is initially collapsed (if collapsible) */
156
+ defaultCollapsed?: boolean;
157
+ }
158
+ /**
159
+ * Represents a complete layout configuration.
160
+ */
161
+ interface Layout<TShape extends ObjectShape> {
162
+ /** Type of layout */
163
+ type: "form" | "grid" | "tabs" | "accordion" | "custom" | "table";
164
+ /** Groups of fields within the layout */
165
+ groups: LayoutGroup<TShape>[];
166
+ /** Additional CSS classes for the layout */
167
+ className?: string;
168
+ /** Layout-specific configuration */
169
+ config?: {
170
+ /** Number of columns for grid layouts */
171
+ columns?: number;
172
+ /** Gap between elements */
173
+ gap?: string | number;
174
+ /** Other layout-specific options */
175
+ [key: string]: any;
176
+ };
177
+ /** Layout metadata - can contain any metadata, specific layouts may have specific metadata */
178
+ metadata?: Record<string, any>;
179
+ }
180
+ /**
181
+ * Form layout specific interface
182
+ */
183
+ interface FormLayout<TShape extends ObjectShape> extends Layout<TShape> {
184
+ type: "form";
185
+ groups: LayoutGroup<TShape>[];
186
+ }
187
+ /**
188
+ * Table layout specific field
189
+ */
190
+ interface TableLayoutField<TShape extends ObjectShape> {
191
+ /** The name of the field - must be a valid property key from the object shape */
192
+ name: keyof TShape;
193
+ /** Additional CSS classes for styling */
194
+ className?: string;
195
+ /** Whether the field should be hidden */
196
+ hidden?: boolean;
197
+ /** Column width in pixels - unlike fieldWidth, this is in pixels */
198
+ columnWidthPx?: number;
199
+ /** Whether the column should be pinned/frozen to the left */
200
+ pinned?: boolean;
201
+ }
202
+ /**
203
+ * Table layout specific interface
204
+ */
205
+ interface TableLayout<TShape extends ObjectShape> extends Layout<TShape> {
206
+ type: "table";
207
+ /** For tables, we only have one group internally but expose fields directly */
208
+ groups: LayoutGroup<TShape>[];
209
+ /** Table-specific metadata */
210
+ metadata?: {
211
+ /** Fields that should be clickable links to view the entity */
212
+ linkFields?: (keyof TShape)[];
213
+ /** Other metadata */
214
+ [key: string]: any;
215
+ };
216
+ }
217
+ /**
218
+ * Type representing multiple layouts for an object schema.
219
+ */
220
+ type ObjectLayouts<TShape extends ObjectShape> = {
221
+ [layoutName: string]: Layout<TShape>;
50
222
  };
51
- declare class ObjectSchema<TShape extends ObjectShape> extends BaseSchema<ObjectOutput<TShape>> {
223
+ /**
224
+ * Type representing multiple form layouts
225
+ */
226
+ type FormLayouts<TShape extends ObjectShape> = {
227
+ [layoutName: string]: FormLayout<TShape>;
228
+ };
229
+ /**
230
+ * Type representing multiple table layouts
231
+ */
232
+ type TableLayouts<TShape extends ObjectShape> = {
233
+ [layoutName: string]: TableLayout<TShape>;
234
+ };
235
+ /**
236
+ * ObjectSchema with optional catchall.
237
+ *
238
+ * Note on typing: When using .catchall(), the output type remains ObjectOutput<TShape>.
239
+ * TypeScript cannot express "extra keys have type X" without conflicting with defined keys.
240
+ * The catchall provides runtime validation and passthrough behavior, but dynamic keys
241
+ * should be accessed via type assertion: `(data as any).dynamicKey` or `data["dynamicKey"]`.
242
+ */
243
+ declare class ObjectSchema<TShape extends ObjectShape = any, TCatchall extends BaseSchema<any> | null = null> extends BaseSchema<ObjectOutput<TShape>> {
244
+ readonly type: "object";
52
245
  _shape: TShape;
53
- constructor(shape: TShape);
54
- parse(data: any): ObjectOutput<TShape>;
246
+ _computedMeta: ObjectComputedMetadata<TShape>;
247
+ _layouts: ObjectLayouts<TShape>;
248
+ _idField: keyof ObjectOutput<TShape>;
249
+ _catchall: TCatchall;
250
+ constructor(shape: TShape, catchall?: TCatchall);
251
+ /**
252
+ * Allow additional properties beyond the defined shape, validated against the provided schema.
253
+ * Similar to Zod's .catchall() method.
254
+ *
255
+ * @example
256
+ * const chartDataSchema = nu.object({ category: nu.string() }).catchall(nu.number());
257
+ * // Validates: { category: "Jan", desktop: 186, mobile: 80 }
258
+ *
259
+ * @param schema The schema to validate additional properties against.
260
+ * @returns A new ObjectSchema that allows additional properties.
261
+ */
262
+ catchall<TCatchallSchema extends BaseSchema<any>>(schema: TCatchallSchema): ObjectSchema<TShape, TCatchallSchema>;
263
+ /**
264
+ * Add computed metadata to the object schema.
265
+ * @param computedMeta Object mapping property keys to computed metadata functions.
266
+ * @returns The schema instance for chaining.
267
+ */
268
+ withComputed(computedMeta: ObjectComputedMetadata<TShape>): this;
269
+ /**
270
+ * Add layouts to the object schema.
271
+ * @param layouts Object mapping layout names to layout configurations.
272
+ * @returns The schema instance for chaining.
273
+ * @deprecated Use withFormLayouts or withTableLayouts instead
274
+ */
275
+ withLayouts(layouts: ObjectLayouts<TShape>): this;
276
+ /**
277
+ * Add form layouts to the object schema.
278
+ * @param layouts Object mapping layout names to form layout configurations.
279
+ * @returns The schema instance for chaining.
280
+ */
281
+ withFormLayouts(layouts: FormLayouts<TShape>): this;
282
+ /**
283
+ * Add table layouts to the object schema.
284
+ * @param layouts Object mapping layout names to table layout configurations with fields and optional linkFields.
285
+ * @returns The schema instance for chaining.
286
+ */
287
+ withTableLayouts(layouts: {
288
+ [layoutName: string]: {
289
+ fields: TableLayoutField<TShape>[];
290
+ className?: string;
291
+ config?: Layout<TShape>["config"];
292
+ metadata?: {
293
+ linkFields?: (keyof TShape)[];
294
+ [key: string]: any;
295
+ };
296
+ };
297
+ }): this;
298
+ /**
299
+ * Specify which field serves as the unique identifier for this object schema.
300
+ * This is used by resource operations to determine how to identify specific records.
301
+ * @param idField The field name or a selector function that returns the ID field.
302
+ * @returns The schema instance for chaining.
303
+ */
304
+ withId<K extends keyof ObjectOutput<TShape>>(idField: K | ((schema: ObjectOutput<TShape>) => ObjectOutput<TShape>[K])): this;
305
+ /**
306
+ * Get the ID field name for this object schema.
307
+ * @returns The field name that serves as the unique identifier.
308
+ */
309
+ getIdField(): keyof ObjectOutput<TShape>;
310
+ /**
311
+ * Get a specific layout by name.
312
+ * @param layoutName The name of the layout to retrieve.
313
+ * @returns The layout configuration or undefined if not found.
314
+ */
315
+ getLayout(layoutName: string): Layout<TShape> | undefined;
316
+ /**
317
+ * Get all available layout names.
318
+ * @returns Array of layout names.
319
+ */
320
+ getLayoutNames(): string[];
321
+ /**
322
+ * Check if a layout exists.
323
+ * @param layoutName The name of the layout to check.
324
+ * @returns True if the layout exists, false otherwise.
325
+ */
326
+ hasLayout(layoutName: string): boolean;
327
+ /**
328
+ * Get the computed metadata for a specific property.
329
+ * @param key The property key.
330
+ * @param data The parsed object data to pass to computed functions.
331
+ * @returns Promise resolving to the computed metadata.
332
+ */
333
+ getComputedMeta(key: keyof TShape, data: ObjectOutput<TShape>): Promise<Partial<SchemaMetadata<TShape[typeof key]["_outputType"]>>>;
334
+ /**
335
+ * Get all computed metadata for all properties.
336
+ * @param data The parsed object data to pass to computed functions.
337
+ * @returns Promise resolving to a map of property keys to computed metadata.
338
+ */
339
+ getAllComputedMeta(data: ObjectOutput<TShape>): Promise<Record<keyof TShape, Partial<SchemaMetadata<any>>>>;
340
+ /**
341
+ * Get merged metadata (static + computed) for all properties.
342
+ * @param data The current form data to pass to computed functions.
343
+ * @returns Promise resolving to a map of property keys to merged metadata.
344
+ */
345
+ getAllMergedMeta(data: Partial<ObjectOutput<TShape>>): Promise<Record<keyof TShape, SchemaMetadata<any>>>;
346
+ /**
347
+ * Create a new ObjectSchema with certain properties omitted.
348
+ * @param keys The property keys to omit from the schema.
349
+ * @returns A new ObjectSchema without the specified properties.
350
+ */
351
+ omit<K extends keyof TShape>(...keys: K[]): ObjectSchema<Omit<TShape, K>>;
352
+ /**
353
+ * Create a new ObjectSchema with additional or modified properties.
354
+ * @param shape The new properties to add or existing properties to modify.
355
+ * @returns A new ObjectSchema with the extended shape.
356
+ */
357
+ extend<TExtend extends ObjectShape>(shape: TExtend): ObjectSchema<TShape & TExtend>;
358
+ /**
359
+ * Create a new ObjectSchema where all top-level properties become optional.
360
+ * This wraps each field in an OptionalSchema, similar to how Zod handles partial.
361
+ * @returns A new ObjectSchema where all properties are optional.
362
+ */
363
+ partial(): ObjectSchema<{
364
+ [K in keyof TShape]: OptionalSchema<TShape[K]>;
365
+ }>;
366
+ toZod(): z.ZodSchema<ObjectOutput<TShape>>;
367
+ /**
368
+ * Returns a Zod schema with URL coercion enabled.
369
+ * This automatically converts string values from URL parameters to the expected types:
370
+ * - "37" → 37 (number)
371
+ * - "true" → true (boolean)
372
+ * - "hello" → "hello" (string, unchanged)
373
+ *
374
+ * Use this when parsing URL search params that arrive as strings but need to be typed.
375
+ *
376
+ * @returns A Zod schema with coercion for URL parameter parsing
377
+ */
378
+ toZodWithCoercion(): z.ZodSchema<ObjectOutput<TShape>>;
55
379
  }
56
380
  /**
57
381
  * Infers the TypeScript output type from an element schema for an array.
58
382
  */
59
- type ArrayOutput<TElementSchema extends BaseSchema<any>> = Array<TElementSchema['_outputType']>;
383
+ type ArrayOutput<TElementSchema extends BaseSchema<any>> = Array<TElementSchema["_outputType"]>;
60
384
  declare class ArraySchema<TElementSchema extends BaseSchema<any>> extends BaseSchema<ArrayOutput<TElementSchema>> {
385
+ readonly type: "array";
61
386
  _element: TElementSchema;
62
387
  constructor(elementSchema: TElementSchema);
63
- parse(data: any): ArrayOutput<TElementSchema>;
388
+ toZod(): z.ZodArray<z.ZodSchema<TElementSchema["_outputType"]>>;
389
+ }
390
+ /**
391
+ * RecordSchema represents a dictionary/map type with string keys and values of a specific type.
392
+ * Similar to TypeScript's Record<string, T> or Zod's z.record().
393
+ *
394
+ * @example
395
+ * const scoresSchema = nu.record(nu.number());
396
+ * // Represents: { [key: string]: number }
397
+ */
398
+ declare class RecordSchema<TValueSchema extends BaseSchema<any>> extends BaseSchema<Record<string, TValueSchema["_outputType"]>> {
399
+ readonly type: "record";
400
+ _valueSchema: TValueSchema;
401
+ constructor(valueSchema: TValueSchema);
402
+ toZod(): z.ZodRecord<z.ZodString, z.ZodSchema<TValueSchema["_outputType"]>>;
403
+ }
404
+ /**
405
+ * Infers the TypeScript type from a schema.
406
+ * @example
407
+ * const userSchema = nu.object({ name: nu.string() });
408
+ * type User = Infer&lt;typeof userSchema&gt;; // { name: string }
409
+ */
410
+ type Infer<T extends BaseSchema<any>> = T["_outputType"];
411
+ type NuSchema = BooleanSchema | StringSchema | NumberSchema | OptionalSchema<any> | ObjectSchema<any> | ArraySchema<any> | RecordSchema<any>;
412
+
413
+ declare const emptySchema: ObjectSchema<{}, null>;
414
+ declare const idNumberSchema: ObjectSchema<{
415
+ id: NumberSchema;
416
+ }, null>;
417
+ declare const idStringSchema: ObjectSchema<{
418
+ id: StringSchema;
419
+ }, null>;
420
+ declare const successSchema: ObjectSchema<{
421
+ success: BooleanSchema;
422
+ }, null>;
423
+ declare const successMessageSchema: ObjectSchema<{
424
+ success: BooleanSchema;
425
+ message: OptionalSchema<StringSchema>;
426
+ }, null>;
427
+ declare const successErrorSchema: ObjectSchema<{
428
+ success: BooleanSchema;
429
+ message: OptionalSchema<StringSchema>;
430
+ errors: OptionalSchema<ArraySchema<ObjectSchema<{
431
+ field: OptionalSchema<StringSchema>;
432
+ message: StringSchema;
433
+ }, null>>>;
434
+ }, null>;
435
+
436
+ declare const errorSchema: ObjectSchema<{
437
+ errorCode: StringSchema;
438
+ errorMessage: StringSchema;
439
+ }, null>;
440
+
441
+ /**
442
+ * Represents a validation error in Nubase schema validation
443
+ */
444
+ interface NubaseValidationError {
445
+ path: string;
446
+ message: string;
447
+ value?: unknown;
448
+ }
449
+ /**
450
+ * Error thrown when Nubase schema validation fails
451
+ */
452
+ declare class NubaseSchemaError extends Error {
453
+ readonly errors: NubaseValidationError[];
454
+ constructor(errors: NubaseValidationError[]);
455
+ /**
456
+ * Creates a NubaseSchemaError from a list of error messages
457
+ */
458
+ static fromMessages(errorMessages: string[]): NubaseSchemaError;
459
+ /**
460
+ * Type guard to check if an error is a NubaseSchemaError
461
+ */
462
+ static isNubaseSchemaError(error: unknown): error is NubaseSchemaError;
64
463
  }
65
- type NuSchema = BooleanSchema | StringSchema | NumberSchema | ObjectSchema<any> | ArraySchema<any>;
66
464
 
67
465
  /**
68
466
  * The main nubase schema instance.
@@ -82,12 +480,253 @@ declare const nu: {
82
480
  * Creates an object schema with a defined shape.
83
481
  * @param shape An object mapping keys to schemas.
84
482
  */
85
- object: <TShape extends ObjectShape>(shape: TShape) => ObjectSchema<TShape>;
483
+ object: <TShape extends ObjectShape>(shape: TShape) => ObjectSchema<TShape, null>;
86
484
  /**
87
485
  * Creates an array schema with a defined element schema.
88
486
  * @param elementSchema The schema for elements within the array.
89
487
  */
90
488
  array: <TElementSchema extends BaseSchema<any>>(elementSchema: TElementSchema) => ArraySchema<TElementSchema>;
489
+ /**
490
+ * Creates a record schema (dictionary) with string keys and values of a specific type.
491
+ * Similar to TypeScript's Record<string, T>.
492
+ *
493
+ * @example
494
+ * const scoresSchema = nu.record(nu.number());
495
+ * // Represents: { [key: string]: number }
496
+ *
497
+ * @param valueSchema The schema for values in the record.
498
+ */
499
+ record: <TValueSchema extends BaseSchema<any>>(valueSchema: TValueSchema) => RecordSchema<TValueSchema>;
91
500
  };
92
501
 
93
- export { type ArrayOutput, ArraySchema, BaseSchema, BooleanSchema, type NuSchema, NumberSchema, type ObjectOutput, ObjectSchema, type ObjectShape, type SchemaMetadata, StringSchema, nu };
502
+ type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
503
+ interface RequestSchema {
504
+ method: HttpMethod;
505
+ path: string;
506
+ requestParams: ObjectSchema;
507
+ requestBody?: ObjectSchema;
508
+ responseBody: ObjectSchema | any;
509
+ }
510
+ type InferRequestParams<T extends RequestSchema> = Infer<T["requestParams"]>;
511
+ type InferRequestBody<T extends RequestSchema> = T["requestBody"] extends ObjectSchema ? Infer<T["requestBody"]> : undefined;
512
+ type InferResponseBody<T extends RequestSchema> = Infer<T["responseBody"]>;
513
+
514
+ /**
515
+ * Configuration for series charts.
516
+ * Defines which data keys represent the series and their display properties.
517
+ */
518
+ declare const seriesConfigSchema: ObjectSchema<{
519
+ /** The data key field names that represent numeric series (e.g., ["desktop", "mobile"]) */
520
+ keys: ArraySchema<StringSchema>;
521
+ /** Optional labels for each key (e.g., { desktop: "Desktop Users" }) */
522
+ labels: OptionalSchema<ObjectSchema<{}, null>>;
523
+ /** Optional colors for each key (e.g., { desktop: "var(--chart1)" }) */
524
+ colors: OptionalSchema<ObjectSchema<{}, null>>;
525
+ }, null>;
526
+ /**
527
+ * A single data point in a series chart.
528
+ * The 'category' is the x-axis label (e.g., "January", "Q1", "2024-01").
529
+ * Additional numeric fields are the data series values (e.g., desktop: 186, mobile: 80).
530
+ *
531
+ * Uses .catchall(nu.number()) to allow dynamic numeric fields beyond 'category'.
532
+ */
533
+ declare const seriesDataPointSchema: ObjectSchema<{
534
+ category: StringSchema;
535
+ }, NumberSchema>;
536
+ /**
537
+ * Complete series data response from an endpoint.
538
+ * Used for Line, Bar, and Area charts.
539
+ */
540
+ declare const seriesDataSchema: ObjectSchema<{
541
+ type: StringSchema;
542
+ config: ObjectSchema<{
543
+ /** The data key field names that represent numeric series (e.g., ["desktop", "mobile"]) */
544
+ keys: ArraySchema<StringSchema>;
545
+ /** Optional labels for each key (e.g., { desktop: "Desktop Users" }) */
546
+ labels: OptionalSchema<ObjectSchema<{}, null>>;
547
+ /** Optional colors for each key (e.g., { desktop: "var(--chart1)" }) */
548
+ colors: OptionalSchema<ObjectSchema<{}, null>>;
549
+ }, null>;
550
+ data: ArraySchema<ObjectSchema<{
551
+ category: StringSchema;
552
+ }, NumberSchema>>;
553
+ }, null>;
554
+ type SeriesConfig = Infer<typeof seriesConfigSchema>;
555
+ type SeriesDataPoint = Infer<typeof seriesDataPointSchema> & Record<string, number>;
556
+ type SeriesData = {
557
+ type: "series";
558
+ config: SeriesConfig;
559
+ data: SeriesDataPoint[];
560
+ };
561
+ /**
562
+ * A single segment in a proportional chart.
563
+ * Note: Colors are automatically assigned by the frontend based on index.
564
+ */
565
+ declare const proportionalDataItemSchema: ObjectSchema<{
566
+ label: StringSchema;
567
+ value: NumberSchema;
568
+ }, null>;
569
+ /**
570
+ * Complete proportional data response from an endpoint.
571
+ * Used for Pie and Donut charts.
572
+ */
573
+ declare const proportionalDataSchema: ObjectSchema<{
574
+ type: StringSchema;
575
+ data: ArraySchema<ObjectSchema<{
576
+ label: StringSchema;
577
+ value: NumberSchema;
578
+ }, null>>;
579
+ }, null>;
580
+ type ProportionalDataItem = Infer<typeof proportionalDataItemSchema>;
581
+ type ProportionalData = {
582
+ type: "proportional";
583
+ data: Array<ProportionalDataItem & {
584
+ fill?: string;
585
+ }>;
586
+ };
587
+ /**
588
+ * KPI/stat widget data for displaying a single metric.
589
+ */
590
+ declare const kpiDataSchema: ObjectSchema<{
591
+ type: StringSchema;
592
+ value: StringSchema;
593
+ label: OptionalSchema<StringSchema>;
594
+ trend: OptionalSchema<StringSchema>;
595
+ trendDirection: OptionalSchema<StringSchema>;
596
+ }, null>;
597
+ type KpiData = {
598
+ type: "kpi";
599
+ value: string;
600
+ label?: string;
601
+ trend?: string;
602
+ trendDirection?: "up" | "down" | "neutral";
603
+ };
604
+ /**
605
+ * Column definition for table widgets.
606
+ */
607
+ declare const tableColumnSchema: ObjectSchema<{
608
+ key: StringSchema;
609
+ label: StringSchema;
610
+ width: OptionalSchema<StringSchema>;
611
+ }, null>;
612
+ /**
613
+ * Complete table data response from an endpoint.
614
+ */
615
+ declare const tableDataSchema: ObjectSchema<{
616
+ type: StringSchema;
617
+ columns: ArraySchema<ObjectSchema<{
618
+ key: StringSchema;
619
+ label: StringSchema;
620
+ width: OptionalSchema<StringSchema>;
621
+ }, null>>;
622
+ rows: ArraySchema<ObjectSchema<{}, null>>;
623
+ }, null>;
624
+ type TableColumn = Infer<typeof tableColumnSchema>;
625
+ type TableData = {
626
+ type: "table";
627
+ columns: TableColumn[];
628
+ rows: Record<string, unknown>[];
629
+ };
630
+ /**
631
+ * Union of all possible widget data types.
632
+ */
633
+ type WidgetData = SeriesData | ProportionalData | KpiData | TableData;
634
+ /**
635
+ * Widget data type discriminator.
636
+ */
637
+ type WidgetDataType = "series" | "proportional" | "kpi" | "table";
638
+
639
+ /**
640
+ * Type for a series widget endpoint that preserves the responseBody type.
641
+ */
642
+ type SeriesWidgetRequestSchema = {
643
+ method: "GET";
644
+ path: string;
645
+ requestParams: ObjectSchema<any>;
646
+ responseBody: typeof seriesDataSchema;
647
+ };
648
+ /**
649
+ * Type for a proportional widget endpoint that preserves the responseBody type.
650
+ */
651
+ type ProportionalWidgetRequestSchema = {
652
+ method: "GET";
653
+ path: string;
654
+ requestParams: ObjectSchema<any>;
655
+ responseBody: typeof proportionalDataSchema;
656
+ };
657
+ /**
658
+ * Type for a KPI widget endpoint that preserves the responseBody type.
659
+ */
660
+ type KpiWidgetRequestSchema = {
661
+ method: "GET";
662
+ path: string;
663
+ requestParams: ObjectSchema<any>;
664
+ responseBody: typeof kpiDataSchema;
665
+ };
666
+ /**
667
+ * Type for a table widget endpoint that preserves the responseBody type.
668
+ */
669
+ type TableWidgetRequestSchema = {
670
+ method: "GET";
671
+ path: string;
672
+ requestParams: ObjectSchema<any>;
673
+ responseBody: typeof tableDataSchema;
674
+ };
675
+ /**
676
+ * Creates a RequestSchema for a Series widget endpoint.
677
+ * The response conforms to SeriesData shape.
678
+ *
679
+ * @param path The API endpoint path (e.g., "/dashboard/revenue")
680
+ * @param requestParams Optional request parameters schema
681
+ * @returns A RequestSchema configured for series data
682
+ *
683
+ * @example
684
+ * ```typescript
685
+ * export const getRevenueChartSchema = createSeriesWidgetEndpoint("/dashboard/revenue");
686
+ * ```
687
+ */
688
+ declare function createSeriesWidgetEndpoint(path: string, requestParams?: ObjectSchema<any>): SeriesWidgetRequestSchema;
689
+ /**
690
+ * Creates a RequestSchema for a Proportional widget endpoint.
691
+ * The response conforms to ProportionalData shape.
692
+ *
693
+ * @param path The API endpoint path (e.g., "/dashboard/browser-stats")
694
+ * @param requestParams Optional request parameters schema
695
+ * @returns A RequestSchema configured for proportional data
696
+ *
697
+ * @example
698
+ * ```typescript
699
+ * export const getBrowserStatsSchema = createProportionalWidgetEndpoint("/dashboard/browsers");
700
+ * ```
701
+ */
702
+ declare function createProportionalWidgetEndpoint(path: string, requestParams?: ObjectSchema<any>): ProportionalWidgetRequestSchema;
703
+ /**
704
+ * Creates a RequestSchema for a KPI widget endpoint.
705
+ * The response conforms to KpiData shape.
706
+ *
707
+ * @param path The API endpoint path (e.g., "/dashboard/total-revenue")
708
+ * @param requestParams Optional request parameters schema
709
+ * @returns A RequestSchema configured for KPI data
710
+ *
711
+ * @example
712
+ * ```typescript
713
+ * export const getTotalRevenueSchema = createKpiWidgetEndpoint("/dashboard/total-revenue");
714
+ * ```
715
+ */
716
+ declare function createKpiWidgetEndpoint(path: string, requestParams?: ObjectSchema<any>): KpiWidgetRequestSchema;
717
+ /**
718
+ * Creates a RequestSchema for a Table widget endpoint.
719
+ * The response conforms to TableData shape.
720
+ *
721
+ * @param path The API endpoint path (e.g., "/dashboard/recent-orders")
722
+ * @param requestParams Optional request parameters schema
723
+ * @returns A RequestSchema configured for table data
724
+ *
725
+ * @example
726
+ * ```typescript
727
+ * export const getRecentOrdersSchema = createTableWidgetEndpoint("/dashboard/orders");
728
+ * ```
729
+ */
730
+ declare function createTableWidgetEndpoint(path: string, requestParams?: ObjectSchema<any>): TableWidgetRequestSchema;
731
+
732
+ export { type ArrayOutput, ArraySchema, BaseSchema, BooleanSchema, type ComputedSchemaMetadata, type FormLayout, type FormLayoutField, type FormLayouts, HttpClient, type HttpMethod, type HttpRequestConfig, type HttpResponse, type Infer, type InferRequestBody, type InferRequestParams, type InferResponseBody, type KpiData, type KpiWidgetRequestSchema, type Layout, type LayoutGroup, type NuSchema, NubaseSchemaError, type NubaseValidationError, NumberSchema, type ObjectComputedMetadata, type ObjectLayouts, type ObjectOutput, ObjectSchema, type ObjectShape, OptionalSchema, type ProportionalData, type ProportionalDataItem, type ProportionalWidgetRequestSchema, RecordSchema, type RequestSchema, type SchemaMetadata, type SeriesConfig, type SeriesData, type SeriesDataPoint, type SeriesWidgetRequestSchema, StringSchema, type TableColumn, type TableData, type TableLayout, type TableLayoutField, type TableLayouts, type TableWidgetRequestSchema, type WidgetData, type WidgetDataType, createKpiWidgetEndpoint, createProportionalWidgetEndpoint, createSeriesWidgetEndpoint, createTableWidgetEndpoint, emptySchema, errorSchema, idNumberSchema, idStringSchema, kpiDataSchema, nu, proportionalDataItemSchema, proportionalDataSchema, seriesConfigSchema, seriesDataPointSchema, seriesDataSchema, successErrorSchema, successMessageSchema, successSchema, tableColumnSchema, tableDataSchema };