@magemetrics/core 0.9.0 → 0.10.0-rc1

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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { sha256 } from '@noble/hashes/sha2.js';
2
- import z5, { z } from 'zod';
2
+ import z6, { z } from 'zod';
3
3
  import { GoTrueClient } from '@supabase/auth-js';
4
4
  import createApiClient2 from 'openapi-fetch';
5
5
  import dayjs from 'dayjs';
@@ -57,7 +57,7 @@ var addApiKeyHeader = (apiKey) => {
57
57
 
58
58
  // package.json
59
59
  var package_default = {
60
- version: "0.9.0"};
60
+ version: "0.10.0-rc1"};
61
61
 
62
62
  // src/core/MageMetricsEventEmitter.ts
63
63
  var MageMetricsEventEmitter = class {
@@ -990,15 +990,26 @@ var ReportColumnsSchema = z.object({
990
990
  name: z.string(),
991
991
  data_type: z.string()
992
992
  }).array();
993
+ var CanonicalDataTypeSchema = z.enum([
994
+ "numeric",
995
+ "boolean",
996
+ "datetime",
997
+ "text",
998
+ "array",
999
+ "json",
1000
+ "other"
1001
+ ]);
993
1002
  z.object({
994
1003
  render_type: z.string().nullish(),
995
- unit: z.string().nullish()
1004
+ unit: z.string().nullish(),
1005
+ canonical_data_type: CanonicalDataTypeSchema.nullish()
996
1006
  });
997
1007
  var FrontendReportColumnsSchema = z.object({
998
1008
  ...ReportColumnsSchema.element.shape,
999
1009
  dataType: z.string(),
1000
1010
  renderType: z.string().optional(),
1001
- unit: z.string().optional()
1011
+ unit: z.string().optional(),
1012
+ canonicalDataType: CanonicalDataTypeSchema.optional()
1002
1013
  }).array().openapi("ReportColumns");
1003
1014
  z.object({
1004
1015
  goal: z.string(),
@@ -1025,6 +1036,84 @@ var FrontendReportExplainabilitySchema = ReportExplainabilitySchema.omit({
1025
1036
  output_dataset: z.string().optional(),
1026
1037
  sql: z.string().optional()
1027
1038
  });
1039
+ var FilterOperatorSchema = z.enum([
1040
+ // Text operators
1041
+ "eq",
1042
+ "neq",
1043
+ "contains",
1044
+ "startsWith",
1045
+ "endsWith",
1046
+ "regex",
1047
+ // Numeric operators
1048
+ "gt",
1049
+ "lt",
1050
+ "gte",
1051
+ "lte",
1052
+ "between"
1053
+ ]);
1054
+ z.object({
1055
+ operator: FilterOperatorSchema,
1056
+ value: z.union([
1057
+ z.string(),
1058
+ z.number(),
1059
+ z.boolean(),
1060
+ z.tuple([z.number(), z.number()])
1061
+ // for "between" operator
1062
+ ])
1063
+ });
1064
+ var DataTableSchema = z.object({
1065
+ id: z.number(),
1066
+ dataset: z.string(),
1067
+ table_name: z.string(),
1068
+ description: z.string().nullable(),
1069
+ primary_key_names: z.string().array(),
1070
+ row_count: z.number().nullable(),
1071
+ created_at: z.string(),
1072
+ updated_at: z.string(),
1073
+ source_id: z.number(),
1074
+ parent_table_id: z.number().nullable()
1075
+ });
1076
+ var DataTableColumnSchema = z.object({
1077
+ id: z.number(),
1078
+ name: z.string(),
1079
+ data_type: z.string().nullable(),
1080
+ description: z.string().nullable(),
1081
+ null_percentage: z.number().nullable(),
1082
+ unique_values: z.number().nullable(),
1083
+ sample_values: z.array(z.unknown()).nullable()
1084
+ });
1085
+ DataTableSchema.extend({
1086
+ columns: z.array(DataTableColumnSchema)
1087
+ });
1088
+ var toSearchParams = ({ cursor, filters, sorting, limit }) => {
1089
+ const params = {};
1090
+ if (limit !== void 0) {
1091
+ params.limit = limit;
1092
+ }
1093
+ if (cursor !== void 0) {
1094
+ params.cursor = cursor;
1095
+ }
1096
+ const sortingParams = sorting?.map((c) => `${c.id}:${c.desc ? "DESC" : "ASC"}`).join(",");
1097
+ if (sortingParams) {
1098
+ params.order = sortingParams;
1099
+ }
1100
+ if (filters) {
1101
+ const filterParams = Object.entries(filters).flatMap(([column, filter]) => {
1102
+ const { operator, value } = filter;
1103
+ if (operator === "between" && Array.isArray(value)) {
1104
+ return `${column}:${operator}:${encodeURIComponent(`${value[0]},${value[1]}`)}`;
1105
+ }
1106
+ if (typeof value === "string" || typeof value === "boolean" || typeof value === "number") {
1107
+ return `${column}:${operator}:${encodeURIComponent(value)}`;
1108
+ }
1109
+ return [];
1110
+ }).join(",");
1111
+ if (filterParams.length > 0) {
1112
+ params.filter = filterParams;
1113
+ }
1114
+ }
1115
+ return params;
1116
+ };
1028
1117
 
1029
1118
  // ../shared/dist/src/endpoints/utils.js
1030
1119
  var limitQueryParams = z.string().pipe(z.coerce.number()).optional().openapi({
@@ -1063,16 +1152,25 @@ var filterQueryParams = z.string().transform((str) => {
1063
1152
  if (!str)
1064
1153
  return [];
1065
1154
  return str.split(",").map((part) => {
1066
- const [column, value = ""] = part.split(":").map(decodeURIComponent);
1067
- return { column, value };
1155
+ const parts = part.split(":");
1156
+ const column = decodeURIComponent(parts[0] ?? "");
1157
+ const operatorRaw = parts[1] ?? "";
1158
+ const isNewFormat = parts.length >= 3 && FilterOperatorSchema.safeParse(operatorRaw).success;
1159
+ if (isNewFormat) {
1160
+ const value2 = decodeURIComponent(parts.slice(2).join(":"));
1161
+ return { column, operator: operatorRaw, value: value2 };
1162
+ }
1163
+ const value = decodeURIComponent(parts.slice(1).join(":"));
1164
+ return { column, operator: "eq", value };
1068
1165
  });
1069
1166
  }).pipe(z.array(z.object({
1070
1167
  column: z.string(),
1168
+ operator: FilterOperatorSchema,
1071
1169
  value: z.string()
1072
1170
  }))).optional().openapi({
1073
1171
  param: {
1074
1172
  required: false,
1075
- example: "status:active,name:John%20Doe"
1173
+ example: "status:eq:active,name:contains:John%20Doe"
1076
1174
  },
1077
1175
  type: "string"
1078
1176
  });
@@ -1822,20 +1920,20 @@ var CreateSpeechToken = createRoute({
1822
1920
  }
1823
1921
  }
1824
1922
  });
1825
- z5.discriminatedUnion("status", [
1826
- z5.object({
1827
- status: z5.literal("error"),
1828
- error: z5.string()
1923
+ z6.discriminatedUnion("status", [
1924
+ z6.object({
1925
+ status: z6.literal("error"),
1926
+ error: z6.string()
1829
1927
  }),
1830
- z5.object({
1831
- status: z5.literal("success"),
1832
- flowId: z5.string()
1928
+ z6.object({
1929
+ status: z6.literal("success"),
1930
+ flowId: z6.string()
1833
1931
  })
1834
1932
  ]);
1835
- var TriggerFlowBody = z5.object({
1836
- triggerId: z5.string(),
1837
- variables: z5.record(z5.string(), z5.string()),
1838
- applicationName: z5.string().optional()
1933
+ var TriggerFlowBody = z6.object({
1934
+ triggerId: z6.string(),
1935
+ variables: z6.record(z6.string(), z6.string()),
1936
+ applicationName: z6.string().optional()
1839
1937
  });
1840
1938
  var TriggerFlow = createRoute({
1841
1939
  method: "post",
@@ -1858,9 +1956,9 @@ var TriggerFlow = createRoute({
1858
1956
  description: "Flow id",
1859
1957
  content: {
1860
1958
  "application/json": {
1861
- schema: z5.object({
1862
- status: z5.literal("success"),
1863
- flowId: z5.string()
1959
+ schema: z6.object({
1960
+ status: z6.literal("success"),
1961
+ flowId: z6.string()
1864
1962
  })
1865
1963
  }
1866
1964
  }
@@ -1868,8 +1966,8 @@ var TriggerFlow = createRoute({
1868
1966
  400: {
1869
1967
  content: {
1870
1968
  "application/json": {
1871
- schema: z5.object({
1872
- error: z5.string()
1969
+ schema: z6.object({
1970
+ error: z6.string()
1873
1971
  })
1874
1972
  }
1875
1973
  },
@@ -1878,7 +1976,7 @@ var TriggerFlow = createRoute({
1878
1976
  404: {
1879
1977
  content: {
1880
1978
  "application/json": {
1881
- schema: z5.object({ error: z5.string() })
1979
+ schema: z6.object({ error: z6.string() })
1882
1980
  }
1883
1981
  },
1884
1982
  description: "Unable to retrieve trigger with this id"
@@ -1887,8 +1985,8 @@ var TriggerFlow = createRoute({
1887
1985
  description: "Something wrong happened",
1888
1986
  content: {
1889
1987
  "application/json": {
1890
- schema: z5.object({
1891
- error: z5.string()
1988
+ schema: z6.object({
1989
+ error: z6.string()
1892
1990
  })
1893
1991
  }
1894
1992
  }
@@ -1918,9 +2016,9 @@ createRoute({
1918
2016
  description: "Flow id",
1919
2017
  content: {
1920
2018
  "application/json": {
1921
- schema: z5.object({
1922
- status: z5.literal("success"),
1923
- flowId: z5.string()
2019
+ schema: z6.object({
2020
+ status: z6.literal("success"),
2021
+ flowId: z6.string()
1924
2022
  })
1925
2023
  }
1926
2024
  }
@@ -1928,8 +2026,8 @@ createRoute({
1928
2026
  400: {
1929
2027
  content: {
1930
2028
  "application/json": {
1931
- schema: z5.object({
1932
- error: z5.string()
2029
+ schema: z6.object({
2030
+ error: z6.string()
1933
2031
  })
1934
2032
  }
1935
2033
  },
@@ -1938,7 +2036,7 @@ createRoute({
1938
2036
  404: {
1939
2037
  content: {
1940
2038
  "application/json": {
1941
- schema: z5.object({ error: z5.string() })
2039
+ schema: z6.object({ error: z6.string() })
1942
2040
  }
1943
2041
  },
1944
2042
  description: "Unable to retrieve trigger with this id"
@@ -1947,8 +2045,8 @@ createRoute({
1947
2045
  description: "Something wrong happened",
1948
2046
  content: {
1949
2047
  "application/json": {
1950
- schema: z5.object({
1951
- error: z5.string()
2048
+ schema: z6.object({
2049
+ error: z6.string()
1952
2050
  })
1953
2051
  }
1954
2052
  }
@@ -2316,7 +2414,7 @@ var GetCanvasForFlow = createRoute({
2316
2414
  request: {
2317
2415
  headers: SupabaseHeaderSchema,
2318
2416
  params: z.object({
2319
- flow_id: z.string().uuid()
2417
+ flow_id: z.uuid()
2320
2418
  })
2321
2419
  },
2322
2420
  responses: {
@@ -2811,54 +2909,6 @@ var ListVisualizationsForFlow = createRoute({
2811
2909
  }
2812
2910
  }
2813
2911
  });
2814
- var DataTableSchema = z.object({
2815
- id: z.number(),
2816
- dataset: z.string(),
2817
- table_name: z.string(),
2818
- description: z.string().nullable(),
2819
- primary_key_names: z.string().array(),
2820
- row_count: z.number().nullable(),
2821
- created_at: z.string(),
2822
- updated_at: z.string(),
2823
- source_id: z.number(),
2824
- parent_table_id: z.number().nullable()
2825
- });
2826
- var DataTableColumnSchema = z.object({
2827
- id: z.number(),
2828
- name: z.string(),
2829
- data_type: z.string().nullable(),
2830
- description: z.string().nullable(),
2831
- null_percentage: z.number().nullable(),
2832
- unique_values: z.number().nullable(),
2833
- sample_values: z.array(z.unknown()).nullable()
2834
- });
2835
- DataTableSchema.extend({
2836
- columns: z.array(DataTableColumnSchema)
2837
- });
2838
- var toSearchParams = ({ cursor, filters, sorting, limit }) => {
2839
- const params = {};
2840
- if (limit !== void 0) {
2841
- params.limit = limit;
2842
- }
2843
- if (cursor !== void 0) {
2844
- params.cursor = cursor;
2845
- }
2846
- const sortingParams = sorting?.map((c) => `${c.id}:${c.desc ? "DESC" : "ASC"}`).join(",");
2847
- if (sortingParams) {
2848
- params.order = sortingParams;
2849
- }
2850
- if (filters) {
2851
- const filterParams = Object.entries(filters).flatMap(([key, value]) => {
2852
- if (!(typeof value === "string" || typeof value === "boolean" || typeof value === "number"))
2853
- return [];
2854
- return `${key}:${encodeURIComponent(value)}`;
2855
- }).join(",");
2856
- if (filterParams.length > 0) {
2857
- params.filter = filterParams;
2858
- }
2859
- }
2860
- return params;
2861
- };
2862
2912
  var isToolResultMessage = (message) => {
2863
2913
  if (message.role !== "assistant") {
2864
2914
  return false;