@lunora/bindings 1.0.0-alpha.8 → 1.0.0-alpha.81

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.
Files changed (58) hide show
  1. package/dist/analytics/index.d.mts +81 -85
  2. package/dist/analytics/index.d.ts +81 -85
  3. package/dist/analytics/index.mjs +1 -2
  4. package/dist/images/index.d.mts +159 -174
  5. package/dist/images/index.d.ts +159 -174
  6. package/dist/images/index.mjs +1 -3
  7. package/dist/kv/index.d.mts +74 -151
  8. package/dist/kv/index.d.ts +74 -151
  9. package/dist/kv/index.mjs +1 -2
  10. package/dist/packem_shared/AnalyticsSqlError-CeQ3A5Eb.mjs +1 -0
  11. package/dist/packem_shared/R2SqlError-ZHgOWClB.mjs +1 -0
  12. package/dist/packem_shared/SelectBuilder-DJXNSdqC.mjs +1 -0
  13. package/dist/packem_shared/SetOperation-kiI5Wnlm.mjs +1 -0
  14. package/dist/packem_shared/Sql-BfnxRway.mjs +1 -0
  15. package/dist/packem_shared/WindowExpression-VX7EEV3h.mjs +1 -0
  16. package/dist/packem_shared/WindowFunction-CL4jYy2l.mjs +1 -0
  17. package/dist/packem_shared/asc-DP_WFiAE.mjs +1 -0
  18. package/dist/packem_shared/buildImageDeliveryUrl-Brqs-dcZ.mjs +1 -0
  19. package/dist/packem_shared/buildSignedImageUrl-BV-iSJKA.mjs +4 -0
  20. package/dist/packem_shared/cap-error-body-YBKO32BF.mjs +1 -0
  21. package/dist/packem_shared/concurrent-vRmSvRpF.mjs +1 -0
  22. package/dist/packem_shared/createAnalytics-BXTNc57d.mjs +1 -0
  23. package/dist/packem_shared/createContextVectors-DiyO3pZU.mjs +6 -0
  24. package/dist/packem_shared/createImages-D7JExfqF.mjs +1 -0
  25. package/dist/packem_shared/createKv-mAHanD5g.mjs +1 -0
  26. package/dist/packem_shared/createKvIntrospector-BpRiFRFQ.mjs +1 -0
  27. package/dist/packem_shared/createPipelines-CIvqrc7E.mjs +1 -0
  28. package/dist/packem_shared/createVectorAdminIntrospector-Ct8v6PxJ.mjs +1 -0
  29. package/dist/packem_shared/createVectors-Dzv0ilKE.mjs +1 -0
  30. package/dist/pipelines/index.d.mts +24 -24
  31. package/dist/pipelines/index.d.ts +24 -24
  32. package/dist/pipelines/index.mjs +1 -1
  33. package/dist/r2sql/index.d.mts +169 -125
  34. package/dist/r2sql/index.d.ts +169 -125
  35. package/dist/r2sql/index.mjs +1 -7
  36. package/dist/vectors/index.d.mts +299 -134
  37. package/dist/vectors/index.d.ts +299 -134
  38. package/dist/vectors/index.mjs +1 -3
  39. package/package.json +3 -2
  40. package/dist/packem_shared/AnalyticsSqlError-C2nz3jpH.mjs +0 -41
  41. package/dist/packem_shared/R2SqlError-drPKSCZ3.mjs +0 -65
  42. package/dist/packem_shared/SelectBuilder-BOqJQHEv.mjs +0 -168
  43. package/dist/packem_shared/SetOperation-DmPgUL8W.mjs +0 -81
  44. package/dist/packem_shared/Sql-B3zq2YGx.mjs +0 -74
  45. package/dist/packem_shared/WindowExpression-BT_uA6g1.mjs +0 -44
  46. package/dist/packem_shared/WindowFunction-DrnuZUF6.mjs +0 -82
  47. package/dist/packem_shared/asc-DZbQCxh1.mjs +0 -16
  48. package/dist/packem_shared/buildImageDeliveryUrl-qZ7XbqTL.mjs +0 -35
  49. package/dist/packem_shared/buildSignedImageUrl-DNUFfyGP.mjs +0 -130
  50. package/dist/packem_shared/concurrent-CkCEVwqP.mjs +0 -39
  51. package/dist/packem_shared/createAnalytics-CEEI69o9.mjs +0 -57
  52. package/dist/packem_shared/createContextVectors-DwZtnPeC.mjs +0 -140
  53. package/dist/packem_shared/createImages-BzRnsz3H.mjs +0 -85
  54. package/dist/packem_shared/createKv-C8Iyu5hD.mjs +0 -145
  55. package/dist/packem_shared/createKvIntrospector-Byk4GfsY.mjs +0 -77
  56. package/dist/packem_shared/createPipelines-CfyJ6VGu.mjs +0 -10
  57. package/dist/packem_shared/createVectorAdminIntrospector-DuSvcBa5.mjs +0 -53
  58. package/dist/packem_shared/createVectors-CTSrctiK.mjs +0 -95
@@ -1,65 +0,0 @@
1
- import { LunoraError } from '@lunora/errors';
2
- import SelectBuilder from './SelectBuilder-BOqJQHEv.mjs';
3
- import { ident, toText } from './Sql-B3zq2YGx.mjs';
4
-
5
- const API_BASE = "https://api.sql.cloudflarestorage.com/api/v1/accounts";
6
- const inferColumns = (rows) => {
7
- if (rows[0] === void 0) {
8
- return [];
9
- }
10
- return Object.keys(rows[0]).map((name) => {
11
- return { name };
12
- });
13
- };
14
- class R2SqlError extends LunoraError {
15
- constructor(status, body) {
16
- super("R2_SQL_ERROR", `R2 SQL query failed (${String(status)}): ${body}`, { name: "R2SqlError", status });
17
- }
18
- }
19
- const createR2Sql = (config) => {
20
- const fetchImpl = config.fetch ?? globalThis.fetch;
21
- const base = config.endpoint ?? API_BASE;
22
- const endpoint = `${base}/${encodeURIComponent(config.accountId)}/r2-sql/query/${encodeURIComponent(config.bucket)}`;
23
- const warehouse = `${config.accountId}_${config.bucket}`;
24
- const exec = async (statement) => {
25
- const response = await fetchImpl(endpoint, {
26
- body: JSON.stringify({ query: statement, warehouse }),
27
- headers: {
28
- Authorization: `Bearer ${config.apiToken}`,
29
- "Content-Type": "application/json"
30
- },
31
- method: "POST"
32
- });
33
- if (!response.ok) {
34
- throw new R2SqlError(response.status, await response.text());
35
- }
36
- let raw;
37
- try {
38
- raw = await response.json();
39
- } catch {
40
- throw new R2SqlError(response.status, "R2 SQL returned a non-JSON body.");
41
- }
42
- const body = raw;
43
- if (body.success === false || body.errors !== void 0 && body.errors.length > 0) {
44
- throw new R2SqlError(response.status, JSON.stringify(body.errors ?? body));
45
- }
46
- const rows = body.result?.rows ?? [];
47
- return {
48
- columns: body.result?.schema ?? inferColumns(rows),
49
- rowCount: rows.length,
50
- rows
51
- };
52
- };
53
- return {
54
- describe: async (table) => exec(`DESCRIBE ${ident(table)}`),
55
- explain: async (statement, options) => exec(`EXPLAIN ${options?.format === "json" ? "FORMAT JSON " : ""}${toText(statement)}`),
56
- // `SelectBuilder`'s constructor validates the table reference (allowing an
57
- // optional `[AS] alias`), so no pre-validation here.
58
- from: (table) => new SelectBuilder(exec, table),
59
- query: async (statement) => exec(toText(statement)),
60
- showDatabases: async () => exec("SHOW DATABASES"),
61
- showTables: async (namespace) => exec(`SHOW TABLES IN ${ident(namespace)}`)
62
- };
63
- };
64
-
65
- export { R2SqlError, createR2Sql };
@@ -1,168 +0,0 @@
1
- import { renderOrderTerm } from './asc-DZbQCxh1.mjs';
2
- import SetOperation from './SetOperation-DmPgUL8W.mjs';
3
- import { tableRef, toText, assertLimit, lit } from './Sql-B3zq2YGx.mjs';
4
-
5
- const JOIN_KEYWORDS = {
6
- cross: "CROSS JOIN",
7
- full: "FULL OUTER JOIN",
8
- inner: "INNER JOIN",
9
- left: "LEFT JOIN",
10
- right: "RIGHT JOIN"
11
- };
12
- class SelectBuilder {
13
- exec;
14
- table;
15
- selectItems = [];
16
- distinctFlag = false;
17
- distinctOnItems = [];
18
- joins = [];
19
- whereConditions = [];
20
- groupByItems = [];
21
- havingConditions = [];
22
- qualifyCondition;
23
- orderByItems = [];
24
- limitValue;
25
- constructor(exec, table) {
26
- this.exec = exec;
27
- this.table = tableRef(table);
28
- }
29
- /** The `SELECT` list. Omit/empty for `SELECT *`. Items are columns, expressions, or aliased window fragments (`fn.rowNumber().over(...).as("rk")`). */
30
- select(...items) {
31
- this.selectItems.push(...items.map((item) => toText(item)));
32
- return this;
33
- }
34
- /** `SELECT DISTINCT` — unique rows. */
35
- distinct() {
36
- this.distinctFlag = true;
37
- return this;
38
- }
39
- /** `DISTINCT ON (cols)` — the first row per distinct combination, ordered by {@link orderBy}. */
40
- distinctOn(...columns) {
41
- this.distinctOnItems.push(...columns.map((column) => toText(column)));
42
- return this;
43
- }
44
- /** `INNER JOIN table ON condition`. */
45
- innerJoin(table, on) {
46
- return this.addJoin("inner", table, on);
47
- }
48
- /** `LEFT JOIN table ON condition`. */
49
- leftJoin(table, on) {
50
- return this.addJoin("left", table, on);
51
- }
52
- /** `RIGHT JOIN table ON condition`. */
53
- rightJoin(table, on) {
54
- return this.addJoin("right", table, on);
55
- }
56
- /** `FULL OUTER JOIN table ON condition`. */
57
- fullJoin(table, on) {
58
- return this.addJoin("full", table, on);
59
- }
60
- /** `CROSS JOIN table` (no `ON`). */
61
- crossJoin(table) {
62
- return this.addJoin("cross", table);
63
- }
64
- /** Add `WHERE` condition(s). Multiple calls (and multiple args) are `AND`-ed. Bind values with the `sql` tag. */
65
- where(...conditions) {
66
- this.whereConditions.push(...conditions.map((condition) => toText(condition)));
67
- return this;
68
- }
69
- /** `GROUP BY` column(s)/expression(s). */
70
- groupBy(...columns) {
71
- this.groupByItems.push(...columns.map((column) => toText(column)));
72
- return this;
73
- }
74
- /** Add `HAVING` condition(s) over aggregates; multiple are `AND`-ed. */
75
- having(...conditions) {
76
- this.havingConditions.push(...conditions.map((condition) => toText(condition)));
77
- return this;
78
- }
79
- /**
80
- * `QUALIFY` — filter on a window function without a subquery, e.g.
81
- * `.qualify(fn.rowNumber().over({ partitionBy: "region", orderBy: desc("total") }).lte(3))`.
82
- */
83
- qualify(condition) {
84
- this.qualifyCondition = toText(condition);
85
- return this;
86
- }
87
- /** `ORDER BY` term(s) — bare strings (ASC) or {@link import("./order").asc | asc}/{@link import("./order").desc | desc} tags. */
88
- orderBy(...terms) {
89
- this.orderByItems.push(...terms.map((term) => renderOrderTerm(term)));
90
- return this;
91
- }
92
- /** `LIMIT n` (R2 SQL: 1–10,000, default 500). */
93
- limit(n) {
94
- assertLimit(n);
95
- this.limitValue = n;
96
- return this;
97
- }
98
- /** Re-type the result rows without changing the query (the builder carries no schema of its own). */
99
- returns() {
100
- return this;
101
- }
102
- /** `this UNION other` — all rows from both, duplicates removed. */
103
- union(other) {
104
- return this.setOperation("UNION", other);
105
- }
106
- /** `this UNION ALL other` — all rows from both, duplicates kept. */
107
- unionAll(other) {
108
- return this.setOperation("UNION ALL", other);
109
- }
110
- /** `this INTERSECT other` — rows present in both. */
111
- intersect(other) {
112
- return this.setOperation("INTERSECT", other);
113
- }
114
- /** `this EXCEPT other` — rows in `this` but not `other`. */
115
- except(other) {
116
- return this.setOperation("EXCEPT", other);
117
- }
118
- /** True when this query carries its own `ORDER BY`/`LIMIT` — so a set operation must parenthesise it. */
119
- get needsWrapForSetOperation() {
120
- return this.orderByItems.length > 0 || this.limitValue !== void 0;
121
- }
122
- /** Render the `SELECT` statement (no trailing semicolon). */
123
- toSQL() {
124
- const parts = [`${this.renderHead()} ${this.selectItems.length > 0 ? this.selectItems.join(", ") : "*"}`, `FROM ${this.table}`];
125
- for (const join of this.joins) {
126
- parts.push(join.on === void 0 ? `${JOIN_KEYWORDS[join.kind]} ${join.table}` : `${JOIN_KEYWORDS[join.kind]} ${join.table} ON ${toText(join.on)}`);
127
- }
128
- if (this.whereConditions.length > 0) {
129
- parts.push(`WHERE ${this.whereConditions.join(" AND ")}`);
130
- }
131
- if (this.groupByItems.length > 0) {
132
- parts.push(`GROUP BY ${this.groupByItems.join(", ")}`);
133
- }
134
- if (this.havingConditions.length > 0) {
135
- parts.push(`HAVING ${this.havingConditions.join(" AND ")}`);
136
- }
137
- if (this.qualifyCondition !== void 0) {
138
- parts.push(`QUALIFY ${this.qualifyCondition}`);
139
- }
140
- if (this.orderByItems.length > 0) {
141
- parts.push(`ORDER BY ${this.orderByItems.join(", ")}`);
142
- }
143
- if (this.limitValue !== void 0) {
144
- parts.push(`LIMIT ${lit(this.limitValue)}`);
145
- }
146
- return parts.join(" ");
147
- }
148
- /** Execute the query and return the typed result. */
149
- async run() {
150
- return this.exec(this.toSQL());
151
- }
152
- /** The `SELECT [DISTINCT [ON (...)]]` head. */
153
- renderHead() {
154
- if (this.distinctOnItems.length > 0) {
155
- return `SELECT DISTINCT ON (${this.distinctOnItems.join(", ")})`;
156
- }
157
- return this.distinctFlag ? "SELECT DISTINCT" : "SELECT";
158
- }
159
- addJoin(kind, table, on) {
160
- this.joins.push({ kind, on, table: tableRef(table) });
161
- return this;
162
- }
163
- setOperation(operator, other) {
164
- return new SetOperation(this.exec, [{ query: this }, { operator, query: other }]);
165
- }
166
- }
167
-
168
- export { SelectBuilder as default };
@@ -1,81 +0,0 @@
1
- import { renderOrderTerm } from './asc-DZbQCxh1.mjs';
2
- import { assertLimit, lit } from './Sql-B3zq2YGx.mjs';
3
-
4
- const renderMember = (query) => {
5
- const text = query.toSQL();
6
- return query.needsWrapForSetOperation === true ? `(${text})` : text;
7
- };
8
- class SetOperation {
9
- /**
10
- * Always `true`: a nested set operation must be parenthesised when it is a
11
- * member of another set operation, or mixed operators mis-associate — e.g.
12
- * `a.union(b.except(c))` must render `a UNION (b EXCEPT c)`, not the flat
13
- * `a UNION b EXCEPT c`.
14
- */
15
- needsWrapForSetOperation = true;
16
- exec;
17
- members;
18
- orderByItems = [];
19
- limitValue;
20
- constructor(exec, members) {
21
- this.exec = exec;
22
- this.members = members;
23
- }
24
- /** Append `UNION other`. */
25
- union(other) {
26
- return this.add("UNION", other);
27
- }
28
- /** Append `UNION ALL other`. */
29
- unionAll(other) {
30
- return this.add("UNION ALL", other);
31
- }
32
- /** Append `INTERSECT other`. */
33
- intersect(other) {
34
- return this.add("INTERSECT", other);
35
- }
36
- /** Append `EXCEPT other`. */
37
- except(other) {
38
- return this.add("EXCEPT", other);
39
- }
40
- /** `ORDER BY` applied to the combined result. */
41
- orderBy(...terms) {
42
- this.orderByItems.push(...terms.map((term) => renderOrderTerm(term)));
43
- return this;
44
- }
45
- /** `LIMIT` applied to the combined result. */
46
- limit(n) {
47
- assertLimit(n);
48
- this.limitValue = n;
49
- return this;
50
- }
51
- /** Re-type the combined result rows. */
52
- returns() {
53
- return this;
54
- }
55
- /** Render the combined statement. */
56
- toSQL() {
57
- const parts = this.members.map((member) => {
58
- const text = renderMember(member.query);
59
- return member.operator === void 0 ? text : `${member.operator} ${text}`;
60
- });
61
- const combined = parts.join(" ");
62
- const tail = [];
63
- if (this.orderByItems.length > 0) {
64
- tail.push(`ORDER BY ${this.orderByItems.join(", ")}`);
65
- }
66
- if (this.limitValue !== void 0) {
67
- tail.push(`LIMIT ${lit(this.limitValue)}`);
68
- }
69
- return tail.length > 0 ? `${combined} ${tail.join(" ")}` : combined;
70
- }
71
- /** Execute the combined query and return the typed result. */
72
- async run() {
73
- return this.exec(this.toSQL());
74
- }
75
- add(operator, other) {
76
- this.members.push({ operator, query: other });
77
- return this;
78
- }
79
- }
80
-
81
- export { SetOperation as default };
@@ -1,74 +0,0 @@
1
- const quoteString = (value) => `'${value.replaceAll("'", "''")}'`;
2
- const IDENTIFIER_RE = /^\w+(?:\.\w+)*$/;
3
- const TABLE_REF_RE = /^\w+(?:\.\w+)*(?:\s+(?:as\s+)?\w+)?$/i;
4
- const MAX_LIMIT = 1e4;
5
- class Sql {
6
- text;
7
- constructor(text) {
8
- this.text = text;
9
- }
10
- toString() {
11
- return this.text;
12
- }
13
- }
14
- const isSql = (value) => value instanceof Sql;
15
- const raw = (text) => new Sql(text);
16
- const toText = (value) => isSql(value) ? value.text : value;
17
- const ident = (name) => {
18
- if (typeof name !== "string" || !IDENTIFIER_RE.test(name)) {
19
- throw new TypeError(`r2sql: invalid identifier ${JSON.stringify(name)} — expected dotted [A-Za-z0-9_] segments (e.g. "namespace.table").`);
20
- }
21
- return name;
22
- };
23
- const tableRef = (ref) => {
24
- if (typeof ref !== "string" || !TABLE_REF_RE.test(ref)) {
25
- throw new TypeError(`r2sql: invalid table reference ${JSON.stringify(ref)} — expected "namespace.table" with an optional "[AS] alias".`);
26
- }
27
- return ref;
28
- };
29
- const lit = (value) => {
30
- if (value === null || value === void 0) {
31
- return "NULL";
32
- }
33
- if (typeof value === "boolean") {
34
- return value ? "true" : "false";
35
- }
36
- if (typeof value === "bigint") {
37
- return value.toString();
38
- }
39
- if (typeof value === "number") {
40
- if (!Number.isFinite(value)) {
41
- throw new TypeError(`r2sql: cannot inline a non-finite number (${String(value)}) as a SQL literal.`);
42
- }
43
- return String(value);
44
- }
45
- if (typeof value === "string") {
46
- return quoteString(value);
47
- }
48
- if (value instanceof Date) {
49
- return quoteString(value.toISOString());
50
- }
51
- if (Array.isArray(value)) {
52
- if (value.length === 0) {
53
- throw new TypeError("r2sql: cannot inline an empty array — `IN ()` is not valid SQL. Guard the empty case before building the query.");
54
- }
55
- return `(${value.map((element) => lit(element)).join(", ")})`;
56
- }
57
- throw new TypeError(`r2sql: cannot inline a value of type ${typeof value} as a SQL literal. Wrap trusted SQL with raw(), or pass a primitive/Date/array.`);
58
- };
59
- const sql = (strings, ...values) => {
60
- let out = strings[0] ?? "";
61
- for (const [index, value] of values.entries()) {
62
- out += isSql(value) ? value.text : lit(value);
63
- out += strings[index + 1] ?? "";
64
- }
65
- return new Sql(out);
66
- };
67
- const joinSql = (parts, separator) => new Sql(parts.map((part) => toText(part)).join(separator));
68
- const assertLimit = (n) => {
69
- if (!Number.isInteger(n) || n < 1 || n > MAX_LIMIT) {
70
- throw new RangeError(`r2sql: limit must be an integer between 1 and ${String(MAX_LIMIT)} (got ${String(n)}).`);
71
- }
72
- };
73
-
74
- export { Sql, assertLimit, ident, isSql, joinSql, lit, raw, sql, tableRef, toText };
@@ -1,44 +0,0 @@
1
- import { Sql, lit } from './Sql-B3zq2YGx.mjs';
2
-
3
- const IDENTIFIER = /^[A-Z_][\w$]*$/i;
4
- const assertIdent = (name) => {
5
- if (!IDENTIFIER.test(name)) {
6
- throw new TypeError(`r2sql: invalid identifier ${JSON.stringify(name)} — expected a simple SQL name (letters, digits, underscore).`);
7
- }
8
- return name;
9
- };
10
- class WindowExpression extends Sql {
11
- /** Alias the expression — `... AS alias` — for use in a `SELECT` list. */
12
- as(alias) {
13
- return new Sql(`${this.text} AS ${assertIdent(alias)}`);
14
- }
15
- /** `expr BETWEEN low AND high`. */
16
- between(low, high) {
17
- return new Sql(`${this.text} BETWEEN ${lit(low)} AND ${lit(high)}`);
18
- }
19
- /** `expr = value`. */
20
- eq(value) {
21
- return this.compare("=", value);
22
- }
23
- /** `expr > value`. */
24
- gt(value) {
25
- return this.compare(">", value);
26
- }
27
- /** `expr >= value`. */
28
- gte(value) {
29
- return this.compare(">=", value);
30
- }
31
- /** `expr &lt; value`. */
32
- lt(value) {
33
- return this.compare("<", value);
34
- }
35
- /** `expr &lt;= value`. */
36
- lte(value) {
37
- return this.compare("<=", value);
38
- }
39
- compare(operator, value) {
40
- return new Sql(`${this.text} ${operator} ${lit(value)}`);
41
- }
42
- }
43
-
44
- export { WindowExpression as default };
@@ -1,82 +0,0 @@
1
- import { renderOrderTerm } from './asc-DZbQCxh1.mjs';
2
- import { lit, toText } from './Sql-B3zq2YGx.mjs';
3
- import WindowExpression from './WindowExpression-BT_uA6g1.mjs';
4
-
5
- const toArray = (value) => {
6
- if (value === void 0) {
7
- return [];
8
- }
9
- return Array.isArray(value) ? value : [value];
10
- };
11
- const renderOver = (spec) => {
12
- const clauses = [];
13
- const partitions = toArray(spec.partitionBy).map((part) => toText(part));
14
- if (partitions.length > 0) {
15
- clauses.push(`PARTITION BY ${partitions.join(", ")}`);
16
- }
17
- const orders = toArray(spec.orderBy).map((order) => renderOrderTerm(order));
18
- if (orders.length > 0) {
19
- clauses.push(`ORDER BY ${orders.join(", ")}`);
20
- }
21
- if (spec.frame !== void 0 && spec.frame.length > 0) {
22
- clauses.push(spec.frame);
23
- }
24
- return `OVER (${clauses.join(" ")})`;
25
- };
26
- const offsetArguments = (column, offset, fallback) => {
27
- const parts = [toText(column)];
28
- if (offset !== void 0) {
29
- parts.push(lit(offset));
30
- }
31
- if (fallback !== void 0) {
32
- parts.push(lit(fallback));
33
- }
34
- return parts.join(", ");
35
- };
36
- class WindowFunction {
37
- callText;
38
- constructor(callText) {
39
- this.callText = callText;
40
- }
41
- /** Attach the window frame, yielding a {@link WindowExpression}. */
42
- over(spec = {}) {
43
- return new WindowExpression(`${this.callText} ${renderOver(spec)}`);
44
- }
45
- }
46
- const windowFunction = (callText) => new WindowFunction(callText);
47
- const fn = {
48
- /** `AVG(column) OVER (...)`. */
49
- avg: (column) => windowFunction(`AVG(${toText(column)})`),
50
- /** `COUNT(column) OVER (...)` — omit the column for `COUNT(*)`. */
51
- count: (column) => windowFunction(`COUNT(${column === void 0 ? "*" : toText(column)})`),
52
- /** `CUME_DIST() OVER (...)`. */
53
- cumeDist: () => windowFunction("CUME_DIST()"),
54
- /** `DENSE_RANK() OVER (...)`. */
55
- denseRank: () => windowFunction("DENSE_RANK()"),
56
- /** `FIRST_VALUE(column) OVER (...)`. */
57
- firstValue: (column) => windowFunction(`FIRST_VALUE(${toText(column)})`),
58
- /** `LAG(column[, offset[, default]]) OVER (...)`. */
59
- lag: (column, offset, fallback) => windowFunction(`LAG(${offsetArguments(column, offset, fallback)})`),
60
- /** `LAST_VALUE(column) OVER (...)`. */
61
- lastValue: (column) => windowFunction(`LAST_VALUE(${toText(column)})`),
62
- /** `LEAD(column[, offset[, default]]) OVER (...)`. */
63
- lead: (column, offset, fallback) => windowFunction(`LEAD(${offsetArguments(column, offset, fallback)})`),
64
- /** `MAX(column) OVER (...)`. */
65
- max: (column) => windowFunction(`MAX(${toText(column)})`),
66
- /** `MIN(column) OVER (...)`. */
67
- min: (column) => windowFunction(`MIN(${toText(column)})`),
68
- /** `NTH_VALUE(column, n) OVER (...)`. */
69
- nthValue: (column, n) => windowFunction(`NTH_VALUE(${toText(column)}, ${lit(n)})`),
70
- /** `NTILE(buckets) OVER (...)`. */
71
- ntile: (buckets) => windowFunction(`NTILE(${lit(buckets)})`),
72
- /** `PERCENT_RANK() OVER (...)`. */
73
- percentRank: () => windowFunction("PERCENT_RANK()"),
74
- /** `RANK() OVER (...)`. */
75
- rank: () => windowFunction("RANK()"),
76
- /** `ROW_NUMBER() OVER (...)`. */
77
- rowNumber: () => windowFunction("ROW_NUMBER()"),
78
- /** `SUM(column) OVER (...)`. */
79
- sum: (column) => windowFunction(`SUM(${toText(column)})`)
80
- };
81
-
82
- export { WindowFunction, fn };
@@ -1,16 +0,0 @@
1
- import { Sql, toText } from './Sql-B3zq2YGx.mjs';
2
-
3
- const asc = (expr) => {
4
- return { dir: "ASC", expr };
5
- };
6
- const desc = (expr) => {
7
- return { dir: "DESC", expr };
8
- };
9
- const renderOrderTerm = (term) => {
10
- if (typeof term === "string" || term instanceof Sql) {
11
- return toText(term);
12
- }
13
- return `${toText(term.expr)} ${term.dir}`;
14
- };
15
-
16
- export { asc, desc, renderOrderTerm };
@@ -1,35 +0,0 @@
1
- import { LunoraError } from '@lunora/errors';
2
-
3
- const ABSOLUTE_URL_RE = /^[a-z][a-z\d+\-.]*:\/\//i;
4
- const FORBIDDEN_VALUE_CHARS = [",", "=", "#", "?", "/"];
5
- const stripTrailingSlash = (value) => value.endsWith("/") ? value.slice(0, -1) : value;
6
- const stripLeadingSlash = (value) => value.startsWith("/") ? value.slice(1) : value;
7
- const serializeTransform = (transform) => Object.entries(transform).filter(([, value]) => value !== void 0 && (typeof value === "string" || typeof value === "number")).map(([key, value]) => {
8
- const serialized = String(value);
9
- const offendingChar = FORBIDDEN_VALUE_CHARS.find((char) => serialized.includes(char));
10
- if (offendingChar !== void 0) {
11
- throw new LunoraError(
12
- "INTERNAL",
13
- `@lunora/bindings/images: transform option \`${key}\` value \`${serialized}\` contains a \`${offendingChar}\`, which the /cdn-cgi/image/ option path cannot represent (\`,\`/\`=\` are the option/key-value separators; \`#\`/\`?\`/\`/\` are URL-structural). Percent-encode the value — for colors use \`%23RRGGBB\`, not \`#RRGGBB\` or \`rgb(r,g,b)\`.`
14
- );
15
- }
16
- return `${key}=${serialized}`;
17
- }).join(",");
18
- const encodeKey = (key) => key.split("/").map((segment) => encodeURIComponent(segment)).join("/");
19
- const buildImageDeliveryUrl = (options) => {
20
- const base = stripTrailingSlash(options.baseUrl);
21
- if (options.imageId !== void 0) {
22
- const variant = options.variant ?? "public";
23
- return `${base}/${encodeURIComponent(options.imageId)}/${encodeURIComponent(variant)}`;
24
- }
25
- if (options.key === void 0) {
26
- throw new LunoraError("INTERNAL", "@lunora/bindings/images: buildImageDeliveryUrl requires either `imageId` or `key`");
27
- }
28
- const optionString = options.transform === void 0 ? "" : serializeTransform(options.transform);
29
- const isAbsolute = ABSOLUTE_URL_RE.test(options.key);
30
- const source = isAbsolute ? options.key : `/${encodeKey(stripLeadingSlash(options.key))}`;
31
- const prefix = optionString === "" ? "/cdn-cgi/image" : `/cdn-cgi/image/${optionString}`;
32
- return `${base}${prefix}${source.startsWith("/") ? source : `/${source}`}`;
33
- };
34
-
35
- export { buildImageDeliveryUrl };