metal-orm 1.0.66 → 1.0.67

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metal-orm",
3
- "version": "1.0.66",
3
+ "version": "1.0.67",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "engines": {
@@ -74,44 +74,44 @@ export const createTableNode = (table: TableRef): TableNode => ({
74
74
  /**
75
75
  * Creates a FunctionTable node for expressions like `function_name(args...)` used in FROM
76
76
  */
77
- export const fnTable = (
78
- name: string,
79
- args: OperandNode[] = [],
80
- alias?: string,
81
- opts?: { lateral?: boolean; withOrdinality?: boolean; columnAliases?: string[]; schema?: string }
82
- ): FunctionTableNode => ({
83
- type: 'FunctionTable',
84
- name,
85
- args,
86
- alias,
87
- lateral: opts?.lateral,
88
- withOrdinality: opts?.withOrdinality,
89
- columnAliases: opts?.columnAliases,
90
- schema: opts?.schema
91
- });
92
-
93
- // Dialect-aware table function (portable intent key, not a real SQL function name).
94
- export const tvf = (
95
- key: string,
96
- args: OperandNode[] = [],
97
- alias?: string,
98
- opts?: { lateral?: boolean; withOrdinality?: boolean; columnAliases?: string[]; schema?: string }
99
- ): FunctionTableNode => ({
100
- type: 'FunctionTable',
101
- key,
102
- name: key,
103
- args,
104
- alias,
105
- lateral: opts?.lateral,
106
- withOrdinality: opts?.withOrdinality,
107
- columnAliases: opts?.columnAliases,
108
- schema: opts?.schema
109
- });
110
-
111
- /**
112
- * Creates a derived table node wrapping a subquery.
113
- */
114
- export const derivedTable = (
77
+ export const fnTable = (
78
+ name: string,
79
+ args: OperandNode[] = [],
80
+ alias?: string,
81
+ opts?: { lateral?: boolean; withOrdinality?: boolean; columnAliases?: string[]; schema?: string }
82
+ ): FunctionTableNode => ({
83
+ type: 'FunctionTable',
84
+ name,
85
+ args,
86
+ alias,
87
+ lateral: opts?.lateral,
88
+ withOrdinality: opts?.withOrdinality,
89
+ columnAliases: opts?.columnAliases,
90
+ schema: opts?.schema
91
+ });
92
+
93
+ // Dialect-aware table function (portable intent key, not a real SQL function name).
94
+ export const tvf = (
95
+ key: string,
96
+ args: OperandNode[] = [],
97
+ alias?: string,
98
+ opts?: { lateral?: boolean; withOrdinality?: boolean; columnAliases?: string[]; schema?: string }
99
+ ): FunctionTableNode => ({
100
+ type: 'FunctionTable',
101
+ key,
102
+ name: key,
103
+ args,
104
+ alias,
105
+ lateral: opts?.lateral,
106
+ withOrdinality: opts?.withOrdinality,
107
+ columnAliases: opts?.columnAliases,
108
+ schema: opts?.schema
109
+ });
110
+
111
+ /**
112
+ * Creates a derived table node wrapping a subquery.
113
+ */
114
+ export const derivedTable = (
115
115
  query: import('./query.js').SelectQueryNode,
116
116
  alias: string,
117
117
  columnAliases?: string[]
@@ -32,17 +32,21 @@ export type TypedLike<T> = { tsType?: T } | { __tsType: T };
32
32
  /**
33
33
  * Type guard to check if a value is a literal value
34
34
  */
35
- const isLiteralValue = (value: unknown): value is LiteralValue =>
36
- value === null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean';
35
+ const isLiteralValue = (value: unknown): value is LiteralValue =>
36
+ value === null ||
37
+ typeof value === 'string' ||
38
+ typeof value === 'number' ||
39
+ typeof value === 'boolean' ||
40
+ value instanceof Date;
37
41
 
38
42
 
39
43
  /**
40
44
  * Converts a primitive value to a LiteralNode
41
45
  */
42
- const toLiteralNode = (value: string | number | boolean | null): LiteralNode => ({
43
- type: 'Literal',
44
- value
45
- });
46
+ const toLiteralNode = (value: LiteralValue): LiteralNode => ({
47
+ type: 'Literal',
48
+ value: value instanceof Date ? value.toISOString() : value
49
+ });
46
50
 
47
51
  /**
48
52
  * Converts a ColumnRef to a ColumnNode
@@ -5,11 +5,11 @@ import { ColumnRef } from './types.js';
5
5
  /**
6
6
  * AST node representing a literal value
7
7
  */
8
- export interface LiteralNode {
9
- type: 'Literal';
10
- /** The literal value (string, number, boolean, or null) */
11
- value: string | number | boolean | null;
12
- }
8
+ export interface LiteralNode {
9
+ type: 'Literal';
10
+ /** The literal value (string, number, boolean, Date, or null) */
11
+ value: string | number | boolean | Date | null;
12
+ }
13
13
 
14
14
  /**
15
15
  * AST node representing a reference to a SELECT alias (for ORDER BY / GROUP BY).
@@ -1,18 +1,18 @@
1
- import { TableSourceNode } from './query.js';
2
- import { ExpressionNode } from './expression.js';
3
- import { JoinKind } from '../sql/sql.js';
4
-
5
- /**
6
- * AST node representing a JOIN clause
1
+ import { TableSourceNode } from './query.js';
2
+ import { ExpressionNode } from './expression.js';
3
+ import { JoinKind } from '../sql/sql.js';
4
+
5
+ /**
6
+ * AST node representing a JOIN clause
7
7
  */
8
8
  export interface JoinNode {
9
- type: 'Join';
10
- /** Type of join (INNER, LEFT, RIGHT, etc.) */
11
- kind: JoinKind;
12
- /** Table to join */
13
- table: TableSourceNode;
14
- /** Join condition expression */
15
- condition: ExpressionNode;
16
- /** Optional metadata for non-SQL concerns (e.g., relation name) */
17
- meta?: Record<string, unknown>;
18
- }
9
+ type: 'Join';
10
+ /** Type of join (INNER, LEFT, RIGHT, etc.) */
11
+ kind: JoinKind;
12
+ /** Table to join */
13
+ table: TableSourceNode;
14
+ /** Join condition expression */
15
+ condition: ExpressionNode;
16
+ /** Optional metadata for non-SQL concerns (e.g., relation name) */
17
+ meta?: Record<string, unknown>;
18
+ }
@@ -1,219 +1,219 @@
1
- import {
2
- AliasRefNode,
3
- CaseExpressionNode,
4
- CastExpressionNode,
5
- ColumnNode,
6
- ExpressionNode,
7
- FunctionNode,
8
- OperandNode,
9
- ScalarSubqueryNode,
10
- WindowFunctionNode
11
- } from './expression.js';
12
- import { JoinNode } from './join.js';
13
- import { OrderDirection } from '../sql/sql.js';
14
-
15
- /**
16
- * AST node representing a table reference in a query
17
- */
18
- export interface TableNode {
19
- type: 'Table';
20
- /** Table name */
21
- name: string;
22
- /** Optional schema name */
23
- schema?: string;
24
- /** Optional table alias */
25
- alias?: string;
26
- }
27
-
28
- /**
29
- * AST node representing a function used as a table source (table-valued function)
30
- */
31
- export interface FunctionTableNode {
32
- type: 'FunctionTable';
33
- // Canonical "intent" for dialect-aware table functions (tvf).
34
- // If set, compiler resolves via TableFunctionStrategy and can fail fast.
35
- key?: string;
36
- /** Function name */
37
- name: string;
38
- /** Optional schema for the function (some dialects) */
39
- schema?: string;
40
- /** Function arguments as operand nodes */
41
- args?: OperandNode[];
42
- /** Optional alias for the function table */
43
- alias?: string;
44
- /** LATERAL flag */
45
- lateral?: boolean;
46
- /** WITH ORDINALITY flag */
47
- withOrdinality?: boolean;
48
- /** Optional column aliases */
49
- columnAliases?: string[];
50
- }
51
-
52
- /**
53
- * AST node representing a derived table (subquery with an alias)
54
- */
55
- export interface DerivedTableNode {
56
- type: 'DerivedTable';
57
- /** Subquery providing the rows */
58
- query: SelectQueryNode;
59
- /** Required alias for the derived table */
60
- alias: string;
61
- /** Optional column aliases */
62
- columnAliases?: string[];
63
- }
64
-
65
- export type TableSourceNode = TableNode | FunctionTableNode | DerivedTableNode;
66
-
67
- /**
68
- * Any expression that can appear in ORDER BY / GROUP BY terms.
69
- */
70
- export type OrderingTerm = OperandNode | ExpressionNode | AliasRefNode;
71
-
72
- /**
73
- * AST node representing an ORDER BY clause
74
- */
75
- export interface OrderByNode {
76
- type: 'OrderBy';
77
- /** Expression/operand/alias to order by */
78
- term: OrderingTerm;
79
- /** Order direction (ASC or DESC) */
80
- direction: OrderDirection;
81
- /** Optional nulls ordering (NULLS FIRST/LAST) */
82
- nulls?: 'FIRST' | 'LAST';
83
- /** Optional collation */
84
- collation?: string;
85
- }
86
-
87
- /**
88
- * AST node representing a Common Table Expression (CTE)
89
- */
90
- export interface CommonTableExpressionNode {
91
- type: 'CommonTableExpression';
92
- /** CTE name */
93
- name: string;
94
- /** Optional column names */
95
- columns?: string[];
96
- /** CTE query */
97
- query: SelectQueryNode;
98
- /** Whether the CTE is recursive */
99
- recursive: boolean;
100
- }
101
-
102
- /**
103
- * Supported set operation kinds for compound SELECT queries
104
- */
105
- export type SetOperationKind = 'UNION' | 'UNION ALL' | 'INTERSECT' | 'EXCEPT';
106
-
107
- /**
108
- * AST node representing a set operation (UNION, INTERSECT, etc.)
109
- */
110
- export interface SetOperationNode {
111
- type: 'SetOperation';
112
- /** Operator to combine queries */
113
- operator: SetOperationKind;
114
- /** Right-hand query in the compound expression */
115
- query: SelectQueryNode;
116
- }
117
-
118
- /**
119
- * AST node representing a complete SELECT query
120
- */
121
- export interface SelectQueryNode {
122
- type: 'SelectQuery';
123
- /** Optional CTEs (WITH clauses) */
124
- ctes?: CommonTableExpressionNode[];
125
- /** FROM clause table (either a Table or a FunctionTable) */
126
- from: TableSourceNode;
127
- /** SELECT clause columns */
128
- columns: (
129
- ColumnNode |
130
- FunctionNode |
131
- ScalarSubqueryNode |
132
- CaseExpressionNode |
133
- CastExpressionNode |
134
- WindowFunctionNode
135
- )[];
136
- /** JOIN clauses */
137
- joins: JoinNode[];
138
- /** Optional WHERE clause */
139
- where?: ExpressionNode;
140
- /** Optional GROUP BY clause */
141
- groupBy?: OrderingTerm[];
142
- /** Optional HAVING clause */
143
- having?: ExpressionNode;
144
- /** Optional ORDER BY clause */
145
- orderBy?: OrderByNode[];
146
- /** Optional LIMIT clause */
147
- limit?: number;
148
- /** Optional OFFSET clause */
149
- offset?: number;
150
- /** Optional query metadata */
151
- meta?: Record<string, unknown>;
152
- /** Optional DISTINCT clause */
153
- distinct?: ColumnNode[];
154
- /** Optional set operations chaining this query with others */
155
- setOps?: SetOperationNode[];
156
- }
157
-
158
- export interface InsertValuesSourceNode {
159
- type: 'InsertValues';
160
- /** Rows of values for INSERT rows */
161
- rows: OperandNode[][];
162
- }
163
-
164
- export interface InsertSelectSourceNode {
165
- type: 'InsertSelect';
166
- /** SELECT query providing rows */
167
- query: SelectQueryNode;
168
- }
169
-
170
- export type InsertSourceNode = InsertValuesSourceNode | InsertSelectSourceNode;
171
-
172
- export interface InsertQueryNode {
173
- type: 'InsertQuery';
174
- /** Target table */
175
- into: TableNode;
176
- /** Column order for inserted values */
177
- columns: ColumnNode[];
178
- /** Source of inserted rows (either literal values or a SELECT query) */
179
- source: InsertSourceNode;
180
- /** Optional RETURNING clause */
181
- returning?: ColumnNode[];
182
- }
183
-
184
- export interface UpdateAssignmentNode {
185
- /** Column to update */
186
- column: ColumnNode;
187
- /** Value to set */
188
- value: OperandNode;
189
- }
190
-
191
- export interface UpdateQueryNode {
192
- type: 'UpdateQuery';
193
- /** Table being updated */
194
- table: TableNode;
195
- /** Optional FROM clause for multi-table updates */
196
- from?: TableSourceNode;
197
- /** Optional joins applied to the FROM/USING tables */
198
- joins?: JoinNode[];
199
- /** Assignments for SET clause */
200
- set: UpdateAssignmentNode[];
201
- /** Optional WHERE clause */
202
- where?: ExpressionNode;
203
- /** Optional RETURNING clause */
204
- returning?: ColumnNode[];
205
- }
206
-
207
- export interface DeleteQueryNode {
208
- type: 'DeleteQuery';
209
- /** Table to delete from */
210
- from: TableNode;
211
- /** Optional USING clause for multi-table deletes */
212
- using?: TableSourceNode;
213
- /** Optional joins applied to the USING clause */
214
- joins?: JoinNode[];
215
- /** Optional WHERE clause */
216
- where?: ExpressionNode;
217
- /** Optional RETURNING clause */
218
- returning?: ColumnNode[];
219
- }
1
+ import {
2
+ AliasRefNode,
3
+ CaseExpressionNode,
4
+ CastExpressionNode,
5
+ ColumnNode,
6
+ ExpressionNode,
7
+ FunctionNode,
8
+ OperandNode,
9
+ ScalarSubqueryNode,
10
+ WindowFunctionNode
11
+ } from './expression.js';
12
+ import { JoinNode } from './join.js';
13
+ import { OrderDirection } from '../sql/sql.js';
14
+
15
+ /**
16
+ * AST node representing a table reference in a query
17
+ */
18
+ export interface TableNode {
19
+ type: 'Table';
20
+ /** Table name */
21
+ name: string;
22
+ /** Optional schema name */
23
+ schema?: string;
24
+ /** Optional table alias */
25
+ alias?: string;
26
+ }
27
+
28
+ /**
29
+ * AST node representing a function used as a table source (table-valued function)
30
+ */
31
+ export interface FunctionTableNode {
32
+ type: 'FunctionTable';
33
+ // Canonical "intent" for dialect-aware table functions (tvf).
34
+ // If set, compiler resolves via TableFunctionStrategy and can fail fast.
35
+ key?: string;
36
+ /** Function name */
37
+ name: string;
38
+ /** Optional schema for the function (some dialects) */
39
+ schema?: string;
40
+ /** Function arguments as operand nodes */
41
+ args?: OperandNode[];
42
+ /** Optional alias for the function table */
43
+ alias?: string;
44
+ /** LATERAL flag */
45
+ lateral?: boolean;
46
+ /** WITH ORDINALITY flag */
47
+ withOrdinality?: boolean;
48
+ /** Optional column aliases */
49
+ columnAliases?: string[];
50
+ }
51
+
52
+ /**
53
+ * AST node representing a derived table (subquery with an alias)
54
+ */
55
+ export interface DerivedTableNode {
56
+ type: 'DerivedTable';
57
+ /** Subquery providing the rows */
58
+ query: SelectQueryNode;
59
+ /** Required alias for the derived table */
60
+ alias: string;
61
+ /** Optional column aliases */
62
+ columnAliases?: string[];
63
+ }
64
+
65
+ export type TableSourceNode = TableNode | FunctionTableNode | DerivedTableNode;
66
+
67
+ /**
68
+ * Any expression that can appear in ORDER BY / GROUP BY terms.
69
+ */
70
+ export type OrderingTerm = OperandNode | ExpressionNode | AliasRefNode;
71
+
72
+ /**
73
+ * AST node representing an ORDER BY clause
74
+ */
75
+ export interface OrderByNode {
76
+ type: 'OrderBy';
77
+ /** Expression/operand/alias to order by */
78
+ term: OrderingTerm;
79
+ /** Order direction (ASC or DESC) */
80
+ direction: OrderDirection;
81
+ /** Optional nulls ordering (NULLS FIRST/LAST) */
82
+ nulls?: 'FIRST' | 'LAST';
83
+ /** Optional collation */
84
+ collation?: string;
85
+ }
86
+
87
+ /**
88
+ * AST node representing a Common Table Expression (CTE)
89
+ */
90
+ export interface CommonTableExpressionNode {
91
+ type: 'CommonTableExpression';
92
+ /** CTE name */
93
+ name: string;
94
+ /** Optional column names */
95
+ columns?: string[];
96
+ /** CTE query */
97
+ query: SelectQueryNode;
98
+ /** Whether the CTE is recursive */
99
+ recursive: boolean;
100
+ }
101
+
102
+ /**
103
+ * Supported set operation kinds for compound SELECT queries
104
+ */
105
+ export type SetOperationKind = 'UNION' | 'UNION ALL' | 'INTERSECT' | 'EXCEPT';
106
+
107
+ /**
108
+ * AST node representing a set operation (UNION, INTERSECT, etc.)
109
+ */
110
+ export interface SetOperationNode {
111
+ type: 'SetOperation';
112
+ /** Operator to combine queries */
113
+ operator: SetOperationKind;
114
+ /** Right-hand query in the compound expression */
115
+ query: SelectQueryNode;
116
+ }
117
+
118
+ /**
119
+ * AST node representing a complete SELECT query
120
+ */
121
+ export interface SelectQueryNode {
122
+ type: 'SelectQuery';
123
+ /** Optional CTEs (WITH clauses) */
124
+ ctes?: CommonTableExpressionNode[];
125
+ /** FROM clause table (either a Table or a FunctionTable) */
126
+ from: TableSourceNode;
127
+ /** SELECT clause columns */
128
+ columns: (
129
+ ColumnNode |
130
+ FunctionNode |
131
+ ScalarSubqueryNode |
132
+ CaseExpressionNode |
133
+ CastExpressionNode |
134
+ WindowFunctionNode
135
+ )[];
136
+ /** JOIN clauses */
137
+ joins: JoinNode[];
138
+ /** Optional WHERE clause */
139
+ where?: ExpressionNode;
140
+ /** Optional GROUP BY clause */
141
+ groupBy?: OrderingTerm[];
142
+ /** Optional HAVING clause */
143
+ having?: ExpressionNode;
144
+ /** Optional ORDER BY clause */
145
+ orderBy?: OrderByNode[];
146
+ /** Optional LIMIT clause */
147
+ limit?: number;
148
+ /** Optional OFFSET clause */
149
+ offset?: number;
150
+ /** Optional query metadata */
151
+ meta?: Record<string, unknown>;
152
+ /** Optional DISTINCT clause */
153
+ distinct?: ColumnNode[];
154
+ /** Optional set operations chaining this query with others */
155
+ setOps?: SetOperationNode[];
156
+ }
157
+
158
+ export interface InsertValuesSourceNode {
159
+ type: 'InsertValues';
160
+ /** Rows of values for INSERT rows */
161
+ rows: OperandNode[][];
162
+ }
163
+
164
+ export interface InsertSelectSourceNode {
165
+ type: 'InsertSelect';
166
+ /** SELECT query providing rows */
167
+ query: SelectQueryNode;
168
+ }
169
+
170
+ export type InsertSourceNode = InsertValuesSourceNode | InsertSelectSourceNode;
171
+
172
+ export interface InsertQueryNode {
173
+ type: 'InsertQuery';
174
+ /** Target table */
175
+ into: TableNode;
176
+ /** Column order for inserted values */
177
+ columns: ColumnNode[];
178
+ /** Source of inserted rows (either literal values or a SELECT query) */
179
+ source: InsertSourceNode;
180
+ /** Optional RETURNING clause */
181
+ returning?: ColumnNode[];
182
+ }
183
+
184
+ export interface UpdateAssignmentNode {
185
+ /** Column to update */
186
+ column: ColumnNode;
187
+ /** Value to set */
188
+ value: OperandNode;
189
+ }
190
+
191
+ export interface UpdateQueryNode {
192
+ type: 'UpdateQuery';
193
+ /** Table being updated */
194
+ table: TableNode;
195
+ /** Optional FROM clause for multi-table updates */
196
+ from?: TableSourceNode;
197
+ /** Optional joins applied to the FROM/USING tables */
198
+ joins?: JoinNode[];
199
+ /** Assignments for SET clause */
200
+ set: UpdateAssignmentNode[];
201
+ /** Optional WHERE clause */
202
+ where?: ExpressionNode;
203
+ /** Optional RETURNING clause */
204
+ returning?: ColumnNode[];
205
+ }
206
+
207
+ export interface DeleteQueryNode {
208
+ type: 'DeleteQuery';
209
+ /** Table to delete from */
210
+ from: TableNode;
211
+ /** Optional USING clause for multi-table deletes */
212
+ using?: TableSourceNode;
213
+ /** Optional joins applied to the USING clause */
214
+ joins?: JoinNode[];
215
+ /** Optional WHERE clause */
216
+ where?: ExpressionNode;
217
+ /** Optional RETURNING clause */
218
+ returning?: ColumnNode[];
219
+ }