@nubase/core 0.1.14 → 0.1.16

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
@@ -28,9 +28,14 @@ interface SchemaMetadata<Output = any> {
28
28
  defaultValue?: Output;
29
29
  /**
30
30
  * Custom renderer identifier to override the default type-based rendering.
31
- * Examples: "multiline", "email", "password", "url"
31
+ * Examples: "multiline", "email", "password", "url", "lookup"
32
32
  */
33
33
  renderer?: string;
34
+ /**
35
+ * When renderer is "lookup", this specifies which resource to use for the lookup.
36
+ * The resource must have a lookup endpoint configured.
37
+ */
38
+ lookupResource?: string;
34
39
  validateOnSubmit?: (value: any) => string | undefined;
35
40
  validateOnSubmitAsync?: (value: any) => Promise<string | undefined>;
36
41
  validateOnBlur?: (value: any) => string | undefined;
@@ -51,6 +56,18 @@ declare abstract class BaseSchema<Output = any> {
51
56
  * Used for type-based form field rendering.
52
57
  */
53
58
  abstract readonly type: string;
59
+ /**
60
+ * The base type of this schema, unwrapping any wrapper schemas (like OptionalSchema).
61
+ * For most schemas, this is the same as `type`. For wrapper schemas like OptionalSchema,
62
+ * this returns the type of the innermost wrapped schema.
63
+ */
64
+ get baseType(): string;
65
+ /**
66
+ * The default value for this schema type.
67
+ * Returns the user-configured default from metadata, or a sensible type-specific default.
68
+ * Subclasses override this to provide appropriate defaults (e.g., false for boolean, 0 for number).
69
+ */
70
+ get defaultValue(): Output | undefined;
54
71
  _meta: SchemaMetadata<Output>;
55
72
  /**
56
73
  * Replace the schema metadata with a new object.
@@ -77,14 +94,17 @@ declare abstract class BaseSchema<Output = any> {
77
94
  }
78
95
  declare class BooleanSchema extends BaseSchema<boolean> {
79
96
  readonly type: "boolean";
97
+ get defaultValue(): boolean;
80
98
  toZod(): z.ZodBoolean;
81
99
  }
82
100
  declare class StringSchema extends BaseSchema<string> {
83
101
  readonly type: "string";
102
+ get defaultValue(): string;
84
103
  toZod(): z.ZodString;
85
104
  }
86
105
  declare class NumberSchema extends BaseSchema<number> {
87
106
  readonly type: "number";
107
+ get defaultValue(): number;
88
108
  toZod(): z.ZodNumber;
89
109
  }
90
110
  /**
@@ -100,6 +120,15 @@ declare class OptionalSchema<TWrapped extends BaseSchema<any>> extends BaseSchem
100
120
  * @returns The wrapped schema.
101
121
  */
102
122
  unwrap(): TWrapped;
123
+ /**
124
+ * Returns the base type of the wrapped schema.
125
+ * This allows getting the underlying type (e.g., "number") even when wrapped in OptionalSchema.
126
+ */
127
+ get baseType(): string;
128
+ /**
129
+ * Optional fields default to undefined (which becomes null during validation).
130
+ */
131
+ get defaultValue(): TWrapped["_outputType"] | undefined;
103
132
  toZod(): z.ZodOptional<z.ZodNullable<z.ZodSchema<TWrapped["_outputType"]>>>;
104
133
  }
105
134
  /**
@@ -474,6 +503,79 @@ declare class NubaseSchemaError extends Error {
474
503
  static isNubaseSchemaError(error: unknown): error is NubaseSchemaError;
475
504
  }
476
505
 
506
+ type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
507
+ interface RequestSchema {
508
+ method: HttpMethod;
509
+ path: string;
510
+ requestParams: ObjectSchema;
511
+ requestBody?: ObjectSchema;
512
+ responseBody: ObjectSchema | any;
513
+ }
514
+ type InferRequestParams<T extends RequestSchema> = Infer<T["requestParams"]>;
515
+ type InferRequestBody<T extends RequestSchema> = T["requestBody"] extends ObjectSchema ? Infer<T["requestBody"]> : undefined;
516
+ type InferResponseBody<T extends RequestSchema> = Infer<T["responseBody"]>;
517
+
518
+ /**
519
+ * Schema type that can be used for lookup IDs.
520
+ * Supports both string IDs (UUIDs) and numeric IDs (auto-increment).
521
+ */
522
+ type LookupIdSchema = StringSchema | NumberSchema;
523
+ /**
524
+ * Creates a lookup schema with the specified ID type.
525
+ * This is the standardized format that all lookup endpoints must return.
526
+ *
527
+ * @param idSchema The schema for the ID field (nu.string() or nu.number())
528
+ */
529
+ declare function createLookupSchema<TIdSchema extends LookupIdSchema>(idSchema: TIdSchema): ObjectSchema<{
530
+ /** Unique identifier for the entity */
531
+ id: TIdSchema;
532
+ /** Primary display text (e.g., user's display name) */
533
+ title: StringSchema;
534
+ /** Optional secondary text (e.g., email address) */
535
+ subtitle: OptionalSchema<StringSchema>;
536
+ /** Optional image URL or data URL for avatar display */
537
+ image: OptionalSchema<StringSchema>;
538
+ }, null>;
539
+ /**
540
+ * The default Lookup schema with string IDs.
541
+ * For numeric IDs, use createLookupSchema(nu.number()) instead.
542
+ */
543
+ declare const lookupSchema: ObjectSchema<{
544
+ /** Unique identifier for the entity */
545
+ id: StringSchema;
546
+ /** Primary display text (e.g., user's display name) */
547
+ title: StringSchema;
548
+ /** Optional secondary text (e.g., email address) */
549
+ subtitle: OptionalSchema<StringSchema>;
550
+ /** Optional image URL or data URL for avatar display */
551
+ image: OptionalSchema<StringSchema>;
552
+ }, null>;
553
+ /**
554
+ * The Lookup type with string IDs - the display representation of an entity in lookup/select components.
555
+ * For numeric IDs, use Infer<ReturnType<typeof createLookupSchema<NumberSchema>>>.
556
+ */
557
+ type Lookup = Infer<typeof lookupSchema>;
558
+ /**
559
+ * Creates a lookup endpoint schema for a resource.
560
+ * Lookup endpoints accept a query string and return an array of Lookup objects.
561
+ *
562
+ * @example
563
+ * ```typescript
564
+ * // For string IDs (UUIDs):
565
+ * export const lookupUsersSchema = createLookupEndpoint("users", nu.string());
566
+ *
567
+ * // For numeric IDs (auto-increment):
568
+ * export const lookupUsersSchema = createLookupEndpoint("users", nu.number());
569
+ *
570
+ * // Creates: GET /lookup/users?q=<query> → Lookup[]
571
+ * ```
572
+ *
573
+ * @param resourceName The name of the resource (used in the path: /lookup/{resourceName})
574
+ * @param idSchema The schema for the ID field - use nu.string() for UUIDs or nu.number() for auto-increment IDs
575
+ * @returns A RequestSchema for the lookup endpoint
576
+ */
577
+ declare function createLookupEndpoint<TIdSchema extends LookupIdSchema>(resourceName: string, idSchema: TIdSchema): RequestSchema;
578
+
477
579
  /**
478
580
  * The main nubase schema instance.
479
581
  * Provides factory methods to create different schema types.
@@ -511,18 +613,6 @@ declare const nu: {
511
613
  record: <TValueSchema extends BaseSchema<any>>(valueSchema: TValueSchema) => RecordSchema<TValueSchema>;
512
614
  };
513
615
 
514
- type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
515
- interface RequestSchema {
516
- method: HttpMethod;
517
- path: string;
518
- requestParams: ObjectSchema;
519
- requestBody?: ObjectSchema;
520
- responseBody: ObjectSchema | any;
521
- }
522
- type InferRequestParams<T extends RequestSchema> = Infer<T["requestParams"]>;
523
- type InferRequestBody<T extends RequestSchema> = T["requestBody"] extends ObjectSchema ? Infer<T["requestBody"]> : undefined;
524
- type InferResponseBody<T extends RequestSchema> = Infer<T["responseBody"]>;
525
-
526
616
  /**
527
617
  * Configuration for series charts.
528
618
  * Defines which data keys represent the series and their display properties.
@@ -742,4 +832,4 @@ declare function createKpiWidgetEndpoint(path: string, requestParams?: ObjectSch
742
832
  */
743
833
  declare function createTableWidgetEndpoint(path: string, requestParams?: ObjectSchema<any>): TableWidgetRequestSchema;
744
834
 
745
- 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 };
835
+ 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 Lookup, type LookupIdSchema, 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, createLookupEndpoint, createLookupSchema, createProportionalWidgetEndpoint, createSeriesWidgetEndpoint, createTableWidgetEndpoint, emptySchema, errorSchema, idNumberSchema, idStringSchema, kpiDataSchema, lookupSchema, nu, proportionalDataItemSchema, proportionalDataSchema, seriesConfigSchema, seriesDataPointSchema, seriesDataSchema, successErrorSchema, successMessageSchema, successSchema, tableColumnSchema, tableDataSchema };
package/dist/index.d.ts CHANGED
@@ -28,9 +28,14 @@ interface SchemaMetadata<Output = any> {
28
28
  defaultValue?: Output;
29
29
  /**
30
30
  * Custom renderer identifier to override the default type-based rendering.
31
- * Examples: "multiline", "email", "password", "url"
31
+ * Examples: "multiline", "email", "password", "url", "lookup"
32
32
  */
33
33
  renderer?: string;
34
+ /**
35
+ * When renderer is "lookup", this specifies which resource to use for the lookup.
36
+ * The resource must have a lookup endpoint configured.
37
+ */
38
+ lookupResource?: string;
34
39
  validateOnSubmit?: (value: any) => string | undefined;
35
40
  validateOnSubmitAsync?: (value: any) => Promise<string | undefined>;
36
41
  validateOnBlur?: (value: any) => string | undefined;
@@ -51,6 +56,18 @@ declare abstract class BaseSchema<Output = any> {
51
56
  * Used for type-based form field rendering.
52
57
  */
53
58
  abstract readonly type: string;
59
+ /**
60
+ * The base type of this schema, unwrapping any wrapper schemas (like OptionalSchema).
61
+ * For most schemas, this is the same as `type`. For wrapper schemas like OptionalSchema,
62
+ * this returns the type of the innermost wrapped schema.
63
+ */
64
+ get baseType(): string;
65
+ /**
66
+ * The default value for this schema type.
67
+ * Returns the user-configured default from metadata, or a sensible type-specific default.
68
+ * Subclasses override this to provide appropriate defaults (e.g., false for boolean, 0 for number).
69
+ */
70
+ get defaultValue(): Output | undefined;
54
71
  _meta: SchemaMetadata<Output>;
55
72
  /**
56
73
  * Replace the schema metadata with a new object.
@@ -77,14 +94,17 @@ declare abstract class BaseSchema<Output = any> {
77
94
  }
78
95
  declare class BooleanSchema extends BaseSchema<boolean> {
79
96
  readonly type: "boolean";
97
+ get defaultValue(): boolean;
80
98
  toZod(): z.ZodBoolean;
81
99
  }
82
100
  declare class StringSchema extends BaseSchema<string> {
83
101
  readonly type: "string";
102
+ get defaultValue(): string;
84
103
  toZod(): z.ZodString;
85
104
  }
86
105
  declare class NumberSchema extends BaseSchema<number> {
87
106
  readonly type: "number";
107
+ get defaultValue(): number;
88
108
  toZod(): z.ZodNumber;
89
109
  }
90
110
  /**
@@ -100,6 +120,15 @@ declare class OptionalSchema<TWrapped extends BaseSchema<any>> extends BaseSchem
100
120
  * @returns The wrapped schema.
101
121
  */
102
122
  unwrap(): TWrapped;
123
+ /**
124
+ * Returns the base type of the wrapped schema.
125
+ * This allows getting the underlying type (e.g., "number") even when wrapped in OptionalSchema.
126
+ */
127
+ get baseType(): string;
128
+ /**
129
+ * Optional fields default to undefined (which becomes null during validation).
130
+ */
131
+ get defaultValue(): TWrapped["_outputType"] | undefined;
103
132
  toZod(): z.ZodOptional<z.ZodNullable<z.ZodSchema<TWrapped["_outputType"]>>>;
104
133
  }
105
134
  /**
@@ -474,6 +503,79 @@ declare class NubaseSchemaError extends Error {
474
503
  static isNubaseSchemaError(error: unknown): error is NubaseSchemaError;
475
504
  }
476
505
 
506
+ type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
507
+ interface RequestSchema {
508
+ method: HttpMethod;
509
+ path: string;
510
+ requestParams: ObjectSchema;
511
+ requestBody?: ObjectSchema;
512
+ responseBody: ObjectSchema | any;
513
+ }
514
+ type InferRequestParams<T extends RequestSchema> = Infer<T["requestParams"]>;
515
+ type InferRequestBody<T extends RequestSchema> = T["requestBody"] extends ObjectSchema ? Infer<T["requestBody"]> : undefined;
516
+ type InferResponseBody<T extends RequestSchema> = Infer<T["responseBody"]>;
517
+
518
+ /**
519
+ * Schema type that can be used for lookup IDs.
520
+ * Supports both string IDs (UUIDs) and numeric IDs (auto-increment).
521
+ */
522
+ type LookupIdSchema = StringSchema | NumberSchema;
523
+ /**
524
+ * Creates a lookup schema with the specified ID type.
525
+ * This is the standardized format that all lookup endpoints must return.
526
+ *
527
+ * @param idSchema The schema for the ID field (nu.string() or nu.number())
528
+ */
529
+ declare function createLookupSchema<TIdSchema extends LookupIdSchema>(idSchema: TIdSchema): ObjectSchema<{
530
+ /** Unique identifier for the entity */
531
+ id: TIdSchema;
532
+ /** Primary display text (e.g., user's display name) */
533
+ title: StringSchema;
534
+ /** Optional secondary text (e.g., email address) */
535
+ subtitle: OptionalSchema<StringSchema>;
536
+ /** Optional image URL or data URL for avatar display */
537
+ image: OptionalSchema<StringSchema>;
538
+ }, null>;
539
+ /**
540
+ * The default Lookup schema with string IDs.
541
+ * For numeric IDs, use createLookupSchema(nu.number()) instead.
542
+ */
543
+ declare const lookupSchema: ObjectSchema<{
544
+ /** Unique identifier for the entity */
545
+ id: StringSchema;
546
+ /** Primary display text (e.g., user's display name) */
547
+ title: StringSchema;
548
+ /** Optional secondary text (e.g., email address) */
549
+ subtitle: OptionalSchema<StringSchema>;
550
+ /** Optional image URL or data URL for avatar display */
551
+ image: OptionalSchema<StringSchema>;
552
+ }, null>;
553
+ /**
554
+ * The Lookup type with string IDs - the display representation of an entity in lookup/select components.
555
+ * For numeric IDs, use Infer<ReturnType<typeof createLookupSchema<NumberSchema>>>.
556
+ */
557
+ type Lookup = Infer<typeof lookupSchema>;
558
+ /**
559
+ * Creates a lookup endpoint schema for a resource.
560
+ * Lookup endpoints accept a query string and return an array of Lookup objects.
561
+ *
562
+ * @example
563
+ * ```typescript
564
+ * // For string IDs (UUIDs):
565
+ * export const lookupUsersSchema = createLookupEndpoint("users", nu.string());
566
+ *
567
+ * // For numeric IDs (auto-increment):
568
+ * export const lookupUsersSchema = createLookupEndpoint("users", nu.number());
569
+ *
570
+ * // Creates: GET /lookup/users?q=<query> → Lookup[]
571
+ * ```
572
+ *
573
+ * @param resourceName The name of the resource (used in the path: /lookup/{resourceName})
574
+ * @param idSchema The schema for the ID field - use nu.string() for UUIDs or nu.number() for auto-increment IDs
575
+ * @returns A RequestSchema for the lookup endpoint
576
+ */
577
+ declare function createLookupEndpoint<TIdSchema extends LookupIdSchema>(resourceName: string, idSchema: TIdSchema): RequestSchema;
578
+
477
579
  /**
478
580
  * The main nubase schema instance.
479
581
  * Provides factory methods to create different schema types.
@@ -511,18 +613,6 @@ declare const nu: {
511
613
  record: <TValueSchema extends BaseSchema<any>>(valueSchema: TValueSchema) => RecordSchema<TValueSchema>;
512
614
  };
513
615
 
514
- type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
515
- interface RequestSchema {
516
- method: HttpMethod;
517
- path: string;
518
- requestParams: ObjectSchema;
519
- requestBody?: ObjectSchema;
520
- responseBody: ObjectSchema | any;
521
- }
522
- type InferRequestParams<T extends RequestSchema> = Infer<T["requestParams"]>;
523
- type InferRequestBody<T extends RequestSchema> = T["requestBody"] extends ObjectSchema ? Infer<T["requestBody"]> : undefined;
524
- type InferResponseBody<T extends RequestSchema> = Infer<T["responseBody"]>;
525
-
526
616
  /**
527
617
  * Configuration for series charts.
528
618
  * Defines which data keys represent the series and their display properties.
@@ -742,4 +832,4 @@ declare function createKpiWidgetEndpoint(path: string, requestParams?: ObjectSch
742
832
  */
743
833
  declare function createTableWidgetEndpoint(path: string, requestParams?: ObjectSchema<any>): TableWidgetRequestSchema;
744
834
 
745
- 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 };
835
+ 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 Lookup, type LookupIdSchema, 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, createLookupEndpoint, createLookupSchema, createProportionalWidgetEndpoint, createSeriesWidgetEndpoint, createTableWidgetEndpoint, emptySchema, errorSchema, idNumberSchema, idStringSchema, kpiDataSchema, lookupSchema, nu, proportionalDataItemSchema, proportionalDataSchema, seriesConfigSchema, seriesDataPointSchema, seriesDataSchema, successErrorSchema, successMessageSchema, successSchema, tableColumnSchema, tableDataSchema };
package/dist/index.js CHANGED
@@ -41,6 +41,8 @@ __export(index_exports, {
41
41
  RecordSchema: () => RecordSchema,
42
42
  StringSchema: () => StringSchema,
43
43
  createKpiWidgetEndpoint: () => createKpiWidgetEndpoint,
44
+ createLookupEndpoint: () => createLookupEndpoint,
45
+ createLookupSchema: () => createLookupSchema,
44
46
  createProportionalWidgetEndpoint: () => createProportionalWidgetEndpoint,
45
47
  createSeriesWidgetEndpoint: () => createSeriesWidgetEndpoint,
46
48
  createTableWidgetEndpoint: () => createTableWidgetEndpoint,
@@ -49,6 +51,7 @@ __export(index_exports, {
49
51
  idNumberSchema: () => idNumberSchema,
50
52
  idStringSchema: () => idStringSchema,
51
53
  kpiDataSchema: () => kpiDataSchema,
54
+ lookupSchema: () => lookupSchema,
52
55
  nu: () => nu,
53
56
  proportionalDataItemSchema: () => proportionalDataItemSchema,
54
57
  proportionalDataSchema: () => proportionalDataSchema,
@@ -336,6 +339,22 @@ var BaseSchema = class {
336
339
  * @internal
337
340
  */
338
341
  _outputType;
342
+ /**
343
+ * The base type of this schema, unwrapping any wrapper schemas (like OptionalSchema).
344
+ * For most schemas, this is the same as `type`. For wrapper schemas like OptionalSchema,
345
+ * this returns the type of the innermost wrapped schema.
346
+ */
347
+ get baseType() {
348
+ return this.type;
349
+ }
350
+ /**
351
+ * The default value for this schema type.
352
+ * Returns the user-configured default from metadata, or a sensible type-specific default.
353
+ * Subclasses override this to provide appropriate defaults (e.g., false for boolean, 0 for number).
354
+ */
355
+ get defaultValue() {
356
+ return this._meta?.defaultValue;
357
+ }
339
358
  _meta = {};
340
359
  /**
341
360
  * Replace the schema metadata with a new object.
@@ -365,20 +384,27 @@ var BaseSchema = class {
365
384
  };
366
385
  var BooleanSchema = class extends BaseSchema {
367
386
  type = "boolean";
387
+ get defaultValue() {
388
+ return this._meta?.defaultValue ?? false;
389
+ }
368
390
  toZod() {
369
391
  return import_zod.z.boolean();
370
392
  }
371
393
  };
372
394
  var StringSchema = class extends BaseSchema {
373
395
  type = "string";
374
- // Add string-specific validation methods here (e.g., minLength, pattern)
396
+ get defaultValue() {
397
+ return this._meta?.defaultValue ?? "";
398
+ }
375
399
  toZod() {
376
400
  return import_zod.z.string();
377
401
  }
378
402
  };
379
403
  var NumberSchema = class extends BaseSchema {
380
404
  type = "number";
381
- // Add number-specific validation methods here (e.g., min, max)
405
+ get defaultValue() {
406
+ return this._meta?.defaultValue ?? 0;
407
+ }
382
408
  toZod() {
383
409
  return import_zod.z.number();
384
410
  }
@@ -397,6 +423,19 @@ var OptionalSchema = class extends BaseSchema {
397
423
  unwrap() {
398
424
  return this._wrapped;
399
425
  }
426
+ /**
427
+ * Returns the base type of the wrapped schema.
428
+ * This allows getting the underlying type (e.g., "number") even when wrapped in OptionalSchema.
429
+ */
430
+ get baseType() {
431
+ return this._wrapped.baseType;
432
+ }
433
+ /**
434
+ * Optional fields default to undefined (which becomes null during validation).
435
+ */
436
+ get defaultValue() {
437
+ return this._meta?.defaultValue ?? void 0;
438
+ }
400
439
  toZod() {
401
440
  return this._wrapped.toZod().nullable().optional();
402
441
  }
@@ -927,6 +966,32 @@ ${errors.map((e) => ` - ${e.path}: ${e.message}`).join("\n")}`;
927
966
  }
928
967
  };
929
968
 
969
+ // src/schema/lookup.ts
970
+ function createLookupSchema(idSchema) {
971
+ return nu.object({
972
+ /** Unique identifier for the entity */
973
+ id: idSchema,
974
+ /** Primary display text (e.g., user's display name) */
975
+ title: nu.string(),
976
+ /** Optional secondary text (e.g., email address) */
977
+ subtitle: nu.string().optional(),
978
+ /** Optional image URL or data URL for avatar display */
979
+ image: nu.string().optional()
980
+ });
981
+ }
982
+ var lookupSchema = createLookupSchema(nu.string());
983
+ function createLookupEndpoint(resourceName, idSchema) {
984
+ return {
985
+ method: "GET",
986
+ path: `/lookup/${resourceName}`,
987
+ requestParams: nu.object({
988
+ /** The search query string */
989
+ q: nu.string()
990
+ }),
991
+ responseBody: nu.array(createLookupSchema(idSchema))
992
+ };
993
+ }
994
+
930
995
  // src/schema/widget-data-schema.ts
931
996
  var seriesConfigSchema = nu.object({
932
997
  /** The data key field names that represent numeric series (e.g., ["desktop", "mobile"]) */
@@ -1022,6 +1087,8 @@ function createTableWidgetEndpoint(path, requestParams) {
1022
1087
  RecordSchema,
1023
1088
  StringSchema,
1024
1089
  createKpiWidgetEndpoint,
1090
+ createLookupEndpoint,
1091
+ createLookupSchema,
1025
1092
  createProportionalWidgetEndpoint,
1026
1093
  createSeriesWidgetEndpoint,
1027
1094
  createTableWidgetEndpoint,
@@ -1030,6 +1097,7 @@ function createTableWidgetEndpoint(path, requestParams) {
1030
1097
  idNumberSchema,
1031
1098
  idStringSchema,
1032
1099
  kpiDataSchema,
1100
+ lookupSchema,
1033
1101
  nu,
1034
1102
  proportionalDataItemSchema,
1035
1103
  proportionalDataSchema,