@mlagie/sql-connector 2.1.0 → 2.1.2

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/index.d.ts CHANGED
@@ -40,9 +40,7 @@ export interface SchemaDict {
40
40
  }
41
41
 
42
42
  type NormalizeSqlType<T> =
43
- T extends { name: infer Name }
44
- ? NormalizeSqlType<Name>
45
- : T extends StringConstructor
43
+ T extends StringConstructor
46
44
  ? "String"
47
45
  : T extends NumberConstructor
48
46
  ? "Number"
@@ -56,7 +54,9 @@ type NormalizeSqlType<T> =
56
54
  ? "Array"
57
55
  : T extends SqlType
58
56
  ? T
59
- : never;
57
+ : T extends { name: SqlType }
58
+ ? T["name"]
59
+ : never;
60
60
 
61
61
  type InferSqlType<T> =
62
62
  NormalizeSqlType<T> extends "String" | "Text"
@@ -85,6 +85,8 @@ type InferFieldNullable<TField> =
85
85
  ? false
86
86
  : TField extends { auto_increment: true }
87
87
  ? false
88
+ : TField extends { default: null }
89
+ ? true
88
90
  : HasKey<TField, "default"> extends true
89
91
  ? false
90
92
  : true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlagie/sql-connector",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "The sql-connector module allows you to manage connections to a MySQL database, define table schemas, and interact with data in a simple and efficient way.",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -26,7 +26,7 @@ function isSqlTemporalDefault(defaultValue) {
26
26
  if (typeof defaultValue !== "string") return false;
27
27
 
28
28
  const normalizedValue = defaultValue.trim().toUpperCase();
29
- return ["CURRENT_TIMESTAMP", "CURRENT_TIMESTAMP()", "NOW()"].includes(normalizedValue);
29
+ return ["CURRENT_TIMESTAMP", "CURRENT_TIMESTAMP()", "NOW", "NOW()"].includes(normalizedValue);
30
30
  }
31
31
 
32
32
  function formatDefaultSql(defaultValue, fieldType) {
@@ -144,13 +144,17 @@ class Model {
144
144
 
145
145
  const sorted = [];
146
146
  const visited = {};
147
- function visit(table) {
147
+ function visit(table, stack = []) {
148
148
  if (getSafe(visited, table) === true) return;
149
- if (getSafe(visited, table) === 'temp') throw new Error('Cyclic foreign key dependency detected');
149
+ const cycleStartIndex = stack.indexOf(table);
150
+ if (cycleStartIndex !== -1) {
151
+ const cyclePath = [...stack.slice(cycleStartIndex), table];
152
+ throw new Error(`Cyclic foreign key dependency detected: ${cyclePath.join(' -> ')}`);
153
+ }
150
154
  setSafe(visited, table, 'temp');
151
155
  const deps = getSafe(dependencies, table)
152
156
  for (const dep of deps) {
153
- if (getSafe(modelMap, dep)) visit(dep);
157
+ if (getSafe(modelMap, dep)) visit(dep, [...stack, table]);
154
158
  }
155
159
  setSafe(visited, table, true);
156
160
  sorted.push(table);