metal-orm 1.0.95 → 1.0.97

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.95",
3
+ "version": "1.0.97",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "engines": {
@@ -45,9 +45,17 @@ export const hydrateRows = (rows: Record<string, unknown>[], plan?: HydrationPla
45
45
  return seen;
46
46
  };
47
47
 
48
+ const hasRelations = plan.relations.length > 0;
49
+
48
50
  for (const row of rows) {
49
51
  const rootId = row[plan.rootPrimaryKey];
50
- if (rootId === undefined) continue;
52
+
53
+ if (rootId === undefined || rootId === null) {
54
+ if (!hasRelations) {
55
+ rootMap.set(Symbol(), createBaseRow(row, plan));
56
+ }
57
+ continue;
58
+ }
51
59
 
52
60
  const parent = getOrCreateParent(row);
53
61
  if (!parent) continue;
@@ -14,10 +14,16 @@ import {
14
14
  import { JoinNode } from '../core/ast/join.js';
15
15
  import { createTableNode } from '../core/ast/builders.js';
16
16
 
17
+ /**
18
+ * Allowed literal type names - single source of truth for both type and error messages
19
+ */
20
+ const LITERAL_VALUE_TYPES = ['string', 'number', 'boolean', 'Date', 'null'] as const;
21
+
17
22
  /**
18
23
  * Literal values that can be used in UPDATE statements
24
+ * Derived from LITERAL_VALUE_TYPES to maintain single source of truth
19
25
  */
20
- type LiteralValue = string | number | boolean | null;
26
+ type LiteralValue = typeof LITERAL_VALUE_TYPES[number] | null;
21
27
 
22
28
  /**
23
29
  * Values allowed in UPDATE SET clauses
@@ -31,6 +37,7 @@ type UpdateValue = OperandNode | LiteralValue;
31
37
  */
32
38
  const isUpdateValue = (value: unknown): value is UpdateValue => {
33
39
  if (value === null) return true;
40
+ if (value instanceof Date) return true;
34
41
  switch (typeof value) {
35
42
  case 'string':
36
43
  case 'number':
@@ -80,8 +87,9 @@ export class UpdateQueryState {
80
87
  withSet(values: Record<string, unknown>): UpdateQueryState {
81
88
  const assignments: UpdateAssignmentNode[] = Object.entries(values).map(([column, rawValue]) => {
82
89
  if (!isUpdateValue(rawValue)) {
90
+ const allowedTypes = [...LITERAL_VALUE_TYPES, 'OperandNode'];
83
91
  throw new Error(
84
- `Invalid update value for column "${column}": only primitives, null, or OperandNodes are allowed`
92
+ `Invalid update value for column "${column}": only ${allowedTypes.join(', ')} are allowed`
85
93
  );
86
94
  }
87
95