drizzle-cube 0.1.34 → 0.1.36

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.
@@ -1,6 +1,6 @@
1
1
  import p, { Router as w } from "express";
2
2
  import S from "cors";
3
- import { S as E, c as s, f as g, a as R, b as q, h as v } from "../compiler-Ce33cdy6.js";
3
+ import { S as E, c as s, f as g, a as R, b as q, h as v } from "../compiler-ixtRH_TD.js";
4
4
  function $(l) {
5
5
  const {
6
6
  cubes: c,
@@ -1,4 +1,4 @@
1
- import { S as j, c as i, f as q, a as $, b as h, h as v } from "../compiler-Ce33cdy6.js";
1
+ import { S as j, c as i, f as q, a as $, b as h, h as v } from "../compiler-ixtRH_TD.js";
2
2
  const Q = function(a, C, p) {
3
3
  const {
4
4
  cubes: g,
@@ -1,5 +1,5 @@
1
1
  import { Hono as w } from "hono";
2
- import { S as x, f as j, a as Q, b as g, h as p } from "../compiler-Ce33cdy6.js";
2
+ import { S as x, f as g, a as Q, b as j, h as p } from "../compiler-ixtRH_TD.js";
3
3
  var v = (d) => {
4
4
  const u = {
5
5
  ...{
@@ -11,30 +11,26 @@ var v = (d) => {
11
11
  ...d
12
12
  }, h = /* @__PURE__ */ ((a) => typeof a == "string" ? a === "*" ? () => a : (o) => a === o ? o : null : typeof a == "function" ? a : (o) => a.includes(o) ? o : null)(u.origin), f = ((a) => typeof a == "function" ? a : Array.isArray(a) ? () => a : () => [])(u.allowMethods);
13
13
  return async function(o, c) {
14
- function s(r, e) {
14
+ function n(r, e) {
15
15
  o.res.headers.set(r, e);
16
16
  }
17
- const n = await h(o.req.header("origin") || "", o);
18
- if (n && s("Access-Control-Allow-Origin", n), u.origin !== "*") {
19
- const r = o.req.header("Vary");
20
- r ? s("Vary", r) : s("Vary", "Origin");
21
- }
22
- if (u.credentials && s("Access-Control-Allow-Credentials", "true"), u.exposeHeaders?.length && s("Access-Control-Expose-Headers", u.exposeHeaders.join(",")), o.req.method === "OPTIONS") {
23
- u.maxAge != null && s("Access-Control-Max-Age", u.maxAge.toString());
17
+ const s = await h(o.req.header("origin") || "", o);
18
+ if (s && n("Access-Control-Allow-Origin", s), u.credentials && n("Access-Control-Allow-Credentials", "true"), u.exposeHeaders?.length && n("Access-Control-Expose-Headers", u.exposeHeaders.join(",")), o.req.method === "OPTIONS") {
19
+ u.origin !== "*" && n("Vary", "Origin"), u.maxAge != null && n("Access-Control-Max-Age", u.maxAge.toString());
24
20
  const r = await f(o.req.header("origin") || "", o);
25
- r.length && s("Access-Control-Allow-Methods", r.join(","));
21
+ r.length && n("Access-Control-Allow-Methods", r.join(","));
26
22
  let e = u.allowHeaders;
27
23
  if (!e?.length) {
28
24
  const t = o.req.header("Access-Control-Request-Headers");
29
25
  t && (e = t.split(/\s*,\s*/));
30
26
  }
31
- return e?.length && (s("Access-Control-Allow-Headers", e.join(",")), o.res.headers.append("Vary", "Access-Control-Request-Headers")), o.res.headers.delete("Content-Length"), o.res.headers.delete("Content-Type"), new Response(null, {
27
+ return e?.length && (n("Access-Control-Allow-Headers", e.join(",")), o.res.headers.append("Vary", "Access-Control-Request-Headers")), o.res.headers.delete("Content-Length"), o.res.headers.delete("Content-Type"), new Response(null, {
32
28
  headers: o.res.headers,
33
29
  status: 204,
34
30
  statusText: "No Content"
35
31
  });
36
32
  }
37
- await c();
33
+ await c(), u.origin !== "*" && o.header("Vary", "Origin", { append: !0 });
38
34
  };
39
35
  };
40
36
  function A(d) {
@@ -49,30 +45,30 @@ function A(d) {
49
45
  } = d;
50
46
  if (!y || y.length === 0)
51
47
  throw new Error("At least one cube must be provided in the cubes array");
52
- const s = new w();
53
- o && s.use("/*", v(o));
54
- const n = new x({
48
+ const n = new w();
49
+ o && n.use("/*", v(o));
50
+ const s = new x({
55
51
  drizzle: u,
56
52
  schema: h,
57
53
  engineType: a
58
54
  });
59
55
  return y.forEach((r) => {
60
- n.registerCube(r);
61
- }), s.post(`${c}/load`, async (r) => {
56
+ s.registerCube(r);
57
+ }), n.post(`${c}/load`, async (r) => {
62
58
  try {
63
- const e = await r.req.json(), t = e.query || e, l = await f(r), i = n.validateQuery(t);
59
+ const e = await r.req.json(), t = e.query || e, l = await f(r), i = s.validateQuery(t);
64
60
  if (!i.isValid)
65
61
  return r.json({
66
62
  error: `Query validation failed: ${i.errors.join(", ")}`
67
63
  }, 400);
68
- const m = await n.executeMultiCubeQuery(t, l);
69
- return r.json(j(t, m, n));
64
+ const m = await s.executeMultiCubeQuery(t, l);
65
+ return r.json(g(t, m, s));
70
66
  } catch (e) {
71
67
  return console.error("Query execution error:", e), r.json({
72
68
  error: e instanceof Error ? e.message : "Query execution failed"
73
69
  }, 500);
74
70
  }
75
- }), s.get(`${c}/load`, async (r) => {
71
+ }), n.get(`${c}/load`, async (r) => {
76
72
  try {
77
73
  const e = r.req.query("query");
78
74
  if (!e)
@@ -87,30 +83,30 @@ function A(d) {
87
83
  error: "Invalid JSON in query parameter"
88
84
  }, 400);
89
85
  }
90
- const l = await f(r), i = n.validateQuery(t);
86
+ const l = await f(r), i = s.validateQuery(t);
91
87
  if (!i.isValid)
92
88
  return r.json({
93
89
  error: `Query validation failed: ${i.errors.join(", ")}`
94
90
  }, 400);
95
- const m = await n.executeMultiCubeQuery(t, l);
96
- return r.json(j(t, m, n));
91
+ const m = await s.executeMultiCubeQuery(t, l);
92
+ return r.json(g(t, m, s));
97
93
  } catch (e) {
98
94
  return console.error("Query execution error:", e), r.json({
99
95
  error: e instanceof Error ? e.message : "Query execution failed"
100
96
  }, 500);
101
97
  }
102
- }), s.get(`${c}/meta`, (r) => {
98
+ }), n.get(`${c}/meta`, (r) => {
103
99
  try {
104
- const e = n.getMetadata();
100
+ const e = s.getMetadata();
105
101
  return r.json(Q(e));
106
102
  } catch (e) {
107
103
  return console.error("Metadata error:", e), r.json({
108
104
  error: e instanceof Error ? e.message : "Failed to fetch metadata"
109
105
  }, 500);
110
106
  }
111
- }), s.post(`${c}/sql`, async (r) => {
107
+ }), n.post(`${c}/sql`, async (r) => {
112
108
  try {
113
- const e = await r.req.json(), t = await f(r), l = n.validateQuery(e);
109
+ const e = await r.req.json(), t = await f(r), l = s.validateQuery(e);
114
110
  if (!l.isValid)
115
111
  return r.json({
116
112
  error: `Query validation failed: ${l.errors.join(", ")}`
@@ -120,21 +116,21 @@ function A(d) {
120
116
  return r.json({
121
117
  error: "No measures or dimensions specified"
122
118
  }, 400);
123
- const m = i.split(".")[0], q = await n.generateSQL(m, e, t);
124
- return r.json(g(e, q));
119
+ const m = i.split(".")[0], q = await s.generateSQL(m, e, t);
120
+ return r.json(j(e, q));
125
121
  } catch (e) {
126
122
  return console.error("SQL generation error:", e), r.json({
127
123
  error: e instanceof Error ? e.message : "SQL generation failed"
128
124
  }, 500);
129
125
  }
130
- }), s.get(`${c}/sql`, async (r) => {
126
+ }), n.get(`${c}/sql`, async (r) => {
131
127
  try {
132
128
  const e = r.req.query("query");
133
129
  if (!e)
134
130
  return r.json({
135
131
  error: "Query parameter is required"
136
132
  }, 400);
137
- const t = JSON.parse(e), l = await f(r), i = n.validateQuery(t);
133
+ const t = JSON.parse(e), l = await f(r), i = s.validateQuery(t);
138
134
  if (!i.isValid)
139
135
  return r.json({
140
136
  error: `Query validation failed: ${i.errors.join(", ")}`
@@ -144,16 +140,16 @@ function A(d) {
144
140
  return r.json({
145
141
  error: "No measures or dimensions specified"
146
142
  }, 400);
147
- const q = m.split(".")[0], C = await n.generateSQL(q, t, l);
148
- return r.json(g(t, C));
143
+ const q = m.split(".")[0], C = await s.generateSQL(q, t, l);
144
+ return r.json(j(t, C));
149
145
  } catch (e) {
150
146
  return console.error("SQL generation error:", e), r.json({
151
147
  error: e instanceof Error ? e.message : "SQL generation failed"
152
148
  }, 500);
153
149
  }
154
- }), s.post(`${c}/dry-run`, async (r) => {
150
+ }), n.post(`${c}/dry-run`, async (r) => {
155
151
  try {
156
- const e = await r.req.json(), t = e.query || e, l = await f(r), i = await p(t, l, n);
152
+ const e = await r.req.json(), t = e.query || e, l = await f(r), i = await p(t, l, s);
157
153
  return r.json(i);
158
154
  } catch (e) {
159
155
  return console.error("Dry-run error:", e), r.json({
@@ -161,7 +157,7 @@ function A(d) {
161
157
  valid: !1
162
158
  }, 400);
163
159
  }
164
- }), s.get(`${c}/dry-run`, async (r) => {
160
+ }), n.get(`${c}/dry-run`, async (r) => {
165
161
  try {
166
162
  const e = r.req.query("query");
167
163
  if (!e)
@@ -169,7 +165,7 @@ function A(d) {
169
165
  error: "Query parameter is required",
170
166
  valid: !1
171
167
  }, 400);
172
- const t = JSON.parse(e), l = await f(r), i = await p(t, l, n);
168
+ const t = JSON.parse(e), l = await f(r), i = await p(t, l, s);
173
169
  return r.json(i);
174
170
  } catch (e) {
175
171
  return console.error("Dry-run error:", e), r.json({
@@ -177,7 +173,7 @@ function A(d) {
177
173
  valid: !1
178
174
  }, 400);
179
175
  }
180
- }), s;
176
+ }), n;
181
177
  }
182
178
  function b(d, y) {
183
179
  const u = A(y);
@@ -1,5 +1,5 @@
1
1
  import { NextResponse as o } from "next/server";
2
- import { c, f as x, a as E, b as N, h as S, S as p } from "../compiler-Ce33cdy6.js";
2
+ import { c, f as x, a as E, b as N, h as S, S as p } from "../compiler-ixtRH_TD.js";
3
3
  function g(n) {
4
4
  const { cubes: r, drizzle: a, schema: s, engineType: f } = n;
5
5
  if (!r || r.length === 0)