@514labs/moose-lib 0.6.437 → 0.6.439

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
@@ -677,6 +677,7 @@ interface DimensionDef<TModel = any, TKey extends keyof TModel = keyof TModel> {
677
677
  column?: TKey;
678
678
  expression?: Sql;
679
679
  as?: string;
680
+ description?: string;
680
681
  }
681
682
  /**
682
683
  * Metric definition — an aggregate or computed value.
@@ -691,6 +692,7 @@ interface DimensionDef<TModel = any, TKey extends keyof TModel = keyof TModel> {
691
692
  interface MetricDef {
692
693
  agg: Sql;
693
694
  as?: string;
695
+ description?: string;
694
696
  }
695
697
  /**
696
698
  * Column definition for detail (non-aggregated) queries.
@@ -752,6 +754,7 @@ interface ModelFilterDef<TModel, TKey extends keyof TModel = keyof TModel> {
752
754
  inputType?: FilterInputTypeHint;
753
755
  /** When true, this filter's `eq` param is required in MCP tool schemas */
754
756
  required?: true;
757
+ description?: string;
755
758
  }
756
759
  /** Extract string keys from a record type */
757
760
  type Names<T> = Extract<keyof T, string>;
@@ -935,8 +938,6 @@ interface QueryModel<TTable, TMetrics extends Record<string, MetricDef>, TDimens
935
938
  readonly dimensions?: TDimensions;
936
939
  readonly metrics?: TMetrics;
937
940
  readonly columns?: TColumns;
938
- readonly dimensionNames: readonly string[];
939
- readonly metricNames: readonly string[];
940
941
  readonly columnNames: readonly string[];
941
942
  /** Type inference helpers (similar to Drizzle's $inferSelect pattern). */
942
943
  readonly $inferDimensions: Names<TDimensions>;
@@ -1117,6 +1118,7 @@ interface QueryModelFilter {
1117
1118
  operators: readonly string[];
1118
1119
  inputType?: FilterInputTypeHint;
1119
1120
  required?: true;
1121
+ description?: string;
1120
1122
  }
1121
1123
  /**
1122
1124
  * Minimal model interface consumed by createModelTool / registerModelTools.
@@ -1139,8 +1141,12 @@ interface QueryModelBase {
1139
1141
  };
1140
1142
  readonly filters: Record<string, QueryModelFilter>;
1141
1143
  readonly sortable: readonly string[];
1142
- readonly dimensionNames: readonly string[];
1143
- readonly metricNames: readonly string[];
1144
+ readonly dimensions?: Record<string, {
1145
+ description?: string;
1146
+ }>;
1147
+ readonly metrics?: Record<string, {
1148
+ description?: string;
1149
+ }>;
1144
1150
  readonly columnNames: readonly string[];
1145
1151
  toSql(request: Record<string, unknown>): Sql;
1146
1152
  }
package/dist/index.d.ts CHANGED
@@ -677,6 +677,7 @@ interface DimensionDef<TModel = any, TKey extends keyof TModel = keyof TModel> {
677
677
  column?: TKey;
678
678
  expression?: Sql;
679
679
  as?: string;
680
+ description?: string;
680
681
  }
681
682
  /**
682
683
  * Metric definition — an aggregate or computed value.
@@ -691,6 +692,7 @@ interface DimensionDef<TModel = any, TKey extends keyof TModel = keyof TModel> {
691
692
  interface MetricDef {
692
693
  agg: Sql;
693
694
  as?: string;
695
+ description?: string;
694
696
  }
695
697
  /**
696
698
  * Column definition for detail (non-aggregated) queries.
@@ -752,6 +754,7 @@ interface ModelFilterDef<TModel, TKey extends keyof TModel = keyof TModel> {
752
754
  inputType?: FilterInputTypeHint;
753
755
  /** When true, this filter's `eq` param is required in MCP tool schemas */
754
756
  required?: true;
757
+ description?: string;
755
758
  }
756
759
  /** Extract string keys from a record type */
757
760
  type Names<T> = Extract<keyof T, string>;
@@ -935,8 +938,6 @@ interface QueryModel<TTable, TMetrics extends Record<string, MetricDef>, TDimens
935
938
  readonly dimensions?: TDimensions;
936
939
  readonly metrics?: TMetrics;
937
940
  readonly columns?: TColumns;
938
- readonly dimensionNames: readonly string[];
939
- readonly metricNames: readonly string[];
940
941
  readonly columnNames: readonly string[];
941
942
  /** Type inference helpers (similar to Drizzle's $inferSelect pattern). */
942
943
  readonly $inferDimensions: Names<TDimensions>;
@@ -1117,6 +1118,7 @@ interface QueryModelFilter {
1117
1118
  operators: readonly string[];
1118
1119
  inputType?: FilterInputTypeHint;
1119
1120
  required?: true;
1121
+ description?: string;
1120
1122
  }
1121
1123
  /**
1122
1124
  * Minimal model interface consumed by createModelTool / registerModelTools.
@@ -1139,8 +1141,12 @@ interface QueryModelBase {
1139
1141
  };
1140
1142
  readonly filters: Record<string, QueryModelFilter>;
1141
1143
  readonly sortable: readonly string[];
1142
- readonly dimensionNames: readonly string[];
1143
- readonly metricNames: readonly string[];
1144
+ readonly dimensions?: Record<string, {
1145
+ description?: string;
1146
+ }>;
1147
+ readonly metrics?: Record<string, {
1148
+ description?: string;
1149
+ }>;
1144
1150
  readonly columnNames: readonly string[];
1145
1151
  toSql(request: Record<string, unknown>): Sql;
1146
1152
  }
package/dist/index.js CHANGED
@@ -4579,8 +4579,6 @@ function defineQueryModel(config) {
4579
4579
  dimensions,
4580
4580
  metrics,
4581
4581
  columns: columnDefs,
4582
- dimensionNames,
4583
- metricNames,
4584
4582
  columnNames,
4585
4583
  query: async (request, client) => {
4586
4584
  const result = await client.execute(toSql(request));
@@ -4668,6 +4666,14 @@ function camelToSnake(s) {
4668
4666
  function titleFromName(name) {
4669
4667
  return name.replace(/^query_/, "Query ").replace(/^list_/, "List ").replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
4670
4668
  }
4669
+ function buildEnumDescription(metadata) {
4670
+ const entries = Object.entries(metadata);
4671
+ if (entries.length === 0) return void 0;
4672
+ const lines = entries.map(([name, def]) => {
4673
+ return def.description ? `- ${name}: ${def.description}` : `- ${name}`;
4674
+ });
4675
+ return lines.join("\n");
4676
+ }
4671
4677
  function zodBaseType(inputType) {
4672
4678
  if (inputType === "number") return import_zod.z.number();
4673
4679
  return import_zod.z.string();
@@ -4705,13 +4711,19 @@ function createModelTool(model, options = {}) {
4705
4711
  const requiredSet = new Set(requiredFilters);
4706
4712
  const schema = {};
4707
4713
  const filterParamMap = {};
4708
- if (model.dimensionNames.length > 0) {
4709
- const names = model.dimensionNames;
4710
- schema.dimensions = import_zod.z.array(import_zod.z.enum(names)).optional();
4711
- }
4712
- if (model.metricNames.length > 0) {
4713
- const names = model.metricNames;
4714
- schema.metrics = import_zod.z.array(import_zod.z.enum(names)).optional();
4714
+ const dimensionNames = Object.keys(model.dimensions ?? {});
4715
+ if (dimensionNames.length > 0) {
4716
+ const names = dimensionNames;
4717
+ const desc = buildEnumDescription(model.dimensions);
4718
+ const dimSchema = import_zod.z.array(import_zod.z.enum(names)).optional();
4719
+ schema.dimensions = desc ? dimSchema.describe(desc) : dimSchema;
4720
+ }
4721
+ const metricNames = Object.keys(model.metrics ?? {});
4722
+ if (metricNames.length > 0) {
4723
+ const names = metricNames;
4724
+ const desc = buildEnumDescription(model.metrics);
4725
+ const metSchema = import_zod.z.array(import_zod.z.enum(names)).optional();
4726
+ schema.metrics = desc ? metSchema.describe(desc) : metSchema;
4715
4727
  }
4716
4728
  if (model.columnNames.length > 0) {
4717
4729
  const names = model.columnNames;
@@ -4735,9 +4747,10 @@ function createModelTool(model, options = {}) {
4735
4747
  paramType = baseType;
4736
4748
  }
4737
4749
  if (requiredSet.has(filterName) && op === "eq") {
4738
- schema[paramName] = paramType;
4750
+ schema[paramName] = filterDef.description ? paramType.describe(filterDef.description) : paramType;
4739
4751
  } else {
4740
- schema[paramName] = paramType.optional();
4752
+ const opt = paramType.optional();
4753
+ schema[paramName] = filterDef.description ? opt.describe(filterDef.description) : opt;
4741
4754
  }
4742
4755
  filterParamMap[paramName] = { filterName, op };
4743
4756
  }
@@ -4745,10 +4758,10 @@ function createModelTool(model, options = {}) {
4745
4758
  schema.limit = import_zod.z.number().min(1).max(maxLimit).default(defaultLimit).optional();
4746
4759
  function buildRequest(params) {
4747
4760
  const request = {};
4748
- if (model.dimensionNames.length > 0) {
4761
+ if (dimensionNames.length > 0) {
4749
4762
  request.dimensions = params.dimensions ?? mergedDefaults.dimensions;
4750
4763
  }
4751
- if (model.metricNames.length > 0) {
4764
+ if (metricNames.length > 0) {
4752
4765
  request.metrics = params.metrics ?? mergedDefaults.metrics;
4753
4766
  }
4754
4767
  if (model.columnNames.length > 0) {