bun-query-builder 0.1.54 → 0.1.56

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/dist/bin/cli.js CHANGED
@@ -17932,6 +17932,8 @@ class MySQLDriver {
17932
17932
  return "date";
17933
17933
  case "datetime":
17934
17934
  return "datetime";
17935
+ case "timestamptz":
17936
+ return "datetime";
17935
17937
  case "json":
17936
17938
  return "json";
17937
17939
  case "enum":
@@ -18117,6 +18119,8 @@ class PostgresDriver {
18117
18119
  return "date";
18118
18120
  case "datetime":
18119
18121
  return "timestamp";
18122
+ case "timestamptz":
18123
+ return "timestamptz";
18120
18124
  case "json":
18121
18125
  return "jsonb";
18122
18126
  case "enum":
@@ -18346,6 +18350,8 @@ class SQLiteDriver {
18346
18350
  return "TEXT";
18347
18351
  case "datetime":
18348
18352
  return "TEXT";
18353
+ case "timestamptz":
18354
+ return "TEXT";
18349
18355
  case "json":
18350
18356
  return "TEXT";
18351
18357
  case "enum":
@@ -18578,13 +18584,23 @@ function loadPlanSnapshot(workspaceRoot, dialect) {
18578
18584
  function savePlanSnapshot(workspaceRoot, dialect, plan) {
18579
18585
  const snapshotPath = getSnapshotPath(workspaceRoot, dialect);
18580
18586
  const snapshotDir = join9(workspaceRoot, ".qb");
18587
+ const hash = hashMigrationPlan(plan);
18588
+ if (existsSync16(snapshotPath)) {
18589
+ try {
18590
+ const current = JSON.parse(readFileSync3(snapshotPath, "utf8"));
18591
+ if (current?.hash === hash && current?.dialect === dialect && current?.plan) {
18592
+ info("-- Model snapshot unchanged");
18593
+ return;
18594
+ }
18595
+ } catch {}
18596
+ }
18581
18597
  if (!existsSync16(snapshotDir)) {
18582
18598
  mkdirSync8(snapshotDir, { recursive: true });
18583
18599
  info(`-- Created snapshot directory: ${snapshotDir}`);
18584
18600
  }
18585
18601
  const snapshot = {
18586
18602
  plan,
18587
- hash: hashMigrationPlan(plan),
18603
+ hash,
18588
18604
  dialect,
18589
18605
  updatedAt: new Date().toISOString()
18590
18606
  };
@@ -27982,6 +27998,9 @@ function detectTypeFromValidationRule(rule) {
27982
27998
  case "datetime":
27983
27999
  case "timestamp":
27984
28000
  return "datetime";
28001
+ case "timestamptz":
28002
+ case "timestamp_tz":
28003
+ return "timestamptz";
27985
28004
  case "json":
27986
28005
  return "json";
27987
28006
  case "enum":
@@ -28006,11 +28025,57 @@ function detectTypeFromValidationRule(rule) {
28006
28025
  return "date";
28007
28026
  if (type === "datetime")
28008
28027
  return "datetime";
28028
+ if (type === "timestamptz" || type === "timestamp_tz")
28029
+ return "timestamptz";
28009
28030
  if (type === "json")
28010
28031
  return "json";
28011
28032
  }
28012
28033
  return;
28013
28034
  }
28035
+ function normalizeAttributeType(value) {
28036
+ if (typeof value !== "string")
28037
+ return;
28038
+ const type = value.trim().toLowerCase().replace(/[\s-]+/g, "_");
28039
+ switch (type) {
28040
+ case "varchar":
28041
+ case "string":
28042
+ return "string";
28043
+ case "text":
28044
+ return "text";
28045
+ case "bool":
28046
+ case "boolean":
28047
+ return "boolean";
28048
+ case "int":
28049
+ case "integer":
28050
+ return "integer";
28051
+ case "bigint":
28052
+ return "bigint";
28053
+ case "float":
28054
+ return "float";
28055
+ case "double":
28056
+ return "double";
28057
+ case "number":
28058
+ case "numeric":
28059
+ case "decimal":
28060
+ return "decimal";
28061
+ case "date":
28062
+ return "date";
28063
+ case "datetime":
28064
+ case "timestamp":
28065
+ return "datetime";
28066
+ case "timestamp_tz":
28067
+ case "timestamptz":
28068
+ case "timestamp_with_time_zone":
28069
+ return "timestamptz";
28070
+ case "json":
28071
+ case "jsonb":
28072
+ return "json";
28073
+ case "enum":
28074
+ return "enum";
28075
+ default:
28076
+ return;
28077
+ }
28078
+ }
28014
28079
  function buildMigrationPlan2(models, options) {
28015
28080
  const meta = buildSchemaMeta(models);
28016
28081
  const tables = [];
@@ -28040,7 +28105,7 @@ function buildMigrationPlan2(models, options) {
28040
28105
  let inferred;
28041
28106
  let enumValues;
28042
28107
  const isPk = attrName === primaryKey;
28043
- inferred = detectTypeFromValidationRule(attr.validation?.rule);
28108
+ inferred = normalizeAttributeType(attr.type) ?? detectTypeFromValidationRule(attr.validation?.rule);
28044
28109
  if (!inferred || inferred === "enum") {
28045
28110
  const enumVals = detectEnumFromValidationRule(attr.validation?.rule);
28046
28111
  if (enumVals && enumVals.length > 0) {
@@ -28463,6 +28528,7 @@ function canonicalStorageType(col, dialect) {
28463
28528
  case "text":
28464
28529
  case "date":
28465
28530
  case "datetime":
28531
+ case "timestamptz":
28466
28532
  case "json":
28467
28533
  case "enum":
28468
28534
  return "TEXT";
@@ -30956,7 +31022,7 @@ function getPrefix() {
30956
31022
  }
30957
31023
  var prefix = getPrefix();
30958
31024
  // package.json
30959
- var version2 = "0.1.54";
31025
+ var version2 = "0.1.56";
30960
31026
 
30961
31027
  // bin/cli.ts
30962
31028
  init_actions();
@@ -133,6 +133,7 @@ export type NormalizedColumnType = | 'string'
133
133
  | 'decimal'
134
134
  | 'date'
135
135
  | 'datetime'
136
+ | 'timestamptz'
136
137
  | 'json'
137
138
  | 'enum';
138
139
  /** The kind of schema change a single migration operation represents. */
package/dist/schema.d.ts CHANGED
@@ -54,6 +54,7 @@ export declare interface ForeignKeyConfig {
54
54
  export declare interface Attribute {
55
55
  required?: boolean
56
56
  nullable?: boolean
57
+ type?: string
57
58
  default?: string | number | boolean | Date
58
59
  unique?: boolean
59
60
  order?: number
package/dist/src/index.js CHANGED
@@ -17931,6 +17931,8 @@ class MySQLDriver {
17931
17931
  return "date";
17932
17932
  case "datetime":
17933
17933
  return "datetime";
17934
+ case "timestamptz":
17935
+ return "datetime";
17934
17936
  case "json":
17935
17937
  return "json";
17936
17938
  case "enum":
@@ -18116,6 +18118,8 @@ class PostgresDriver {
18116
18118
  return "date";
18117
18119
  case "datetime":
18118
18120
  return "timestamp";
18121
+ case "timestamptz":
18122
+ return "timestamptz";
18119
18123
  case "json":
18120
18124
  return "jsonb";
18121
18125
  case "enum":
@@ -18345,6 +18349,8 @@ class SQLiteDriver {
18345
18349
  return "TEXT";
18346
18350
  case "datetime":
18347
18351
  return "TEXT";
18352
+ case "timestamptz":
18353
+ return "TEXT";
18348
18354
  case "json":
18349
18355
  return "TEXT";
18350
18356
  case "enum":
@@ -18577,13 +18583,23 @@ function loadPlanSnapshot(workspaceRoot, dialect) {
18577
18583
  function savePlanSnapshot(workspaceRoot, dialect, plan) {
18578
18584
  const snapshotPath = getSnapshotPath(workspaceRoot, dialect);
18579
18585
  const snapshotDir = join9(workspaceRoot, ".qb");
18586
+ const hash = hashMigrationPlan(plan);
18587
+ if (existsSync16(snapshotPath)) {
18588
+ try {
18589
+ const current = JSON.parse(readFileSync3(snapshotPath, "utf8"));
18590
+ if (current?.hash === hash && current?.dialect === dialect && current?.plan) {
18591
+ info("-- Model snapshot unchanged");
18592
+ return;
18593
+ }
18594
+ } catch {}
18595
+ }
18580
18596
  if (!existsSync16(snapshotDir)) {
18581
18597
  mkdirSync8(snapshotDir, { recursive: true });
18582
18598
  info(`-- Created snapshot directory: ${snapshotDir}`);
18583
18599
  }
18584
18600
  const snapshot = {
18585
18601
  plan,
18586
- hash: hashMigrationPlan(plan),
18602
+ hash,
18587
18603
  dialect,
18588
18604
  updatedAt: new Date().toISOString()
18589
18605
  };
@@ -27981,6 +27997,9 @@ function detectTypeFromValidationRule(rule) {
27981
27997
  case "datetime":
27982
27998
  case "timestamp":
27983
27999
  return "datetime";
28000
+ case "timestamptz":
28001
+ case "timestamp_tz":
28002
+ return "timestamptz";
27984
28003
  case "json":
27985
28004
  return "json";
27986
28005
  case "enum":
@@ -28005,11 +28024,57 @@ function detectTypeFromValidationRule(rule) {
28005
28024
  return "date";
28006
28025
  if (type === "datetime")
28007
28026
  return "datetime";
28027
+ if (type === "timestamptz" || type === "timestamp_tz")
28028
+ return "timestamptz";
28008
28029
  if (type === "json")
28009
28030
  return "json";
28010
28031
  }
28011
28032
  return;
28012
28033
  }
28034
+ function normalizeAttributeType(value) {
28035
+ if (typeof value !== "string")
28036
+ return;
28037
+ const type = value.trim().toLowerCase().replace(/[\s-]+/g, "_");
28038
+ switch (type) {
28039
+ case "varchar":
28040
+ case "string":
28041
+ return "string";
28042
+ case "text":
28043
+ return "text";
28044
+ case "bool":
28045
+ case "boolean":
28046
+ return "boolean";
28047
+ case "int":
28048
+ case "integer":
28049
+ return "integer";
28050
+ case "bigint":
28051
+ return "bigint";
28052
+ case "float":
28053
+ return "float";
28054
+ case "double":
28055
+ return "double";
28056
+ case "number":
28057
+ case "numeric":
28058
+ case "decimal":
28059
+ return "decimal";
28060
+ case "date":
28061
+ return "date";
28062
+ case "datetime":
28063
+ case "timestamp":
28064
+ return "datetime";
28065
+ case "timestamp_tz":
28066
+ case "timestamptz":
28067
+ case "timestamp_with_time_zone":
28068
+ return "timestamptz";
28069
+ case "json":
28070
+ case "jsonb":
28071
+ return "json";
28072
+ case "enum":
28073
+ return "enum";
28074
+ default:
28075
+ return;
28076
+ }
28077
+ }
28013
28078
  function buildMigrationPlan2(models, options) {
28014
28079
  const meta = buildSchemaMeta(models);
28015
28080
  const tables = [];
@@ -28039,7 +28104,7 @@ function buildMigrationPlan2(models, options) {
28039
28104
  let inferred;
28040
28105
  let enumValues;
28041
28106
  const isPk = attrName === primaryKey;
28042
- inferred = detectTypeFromValidationRule(attr.validation?.rule);
28107
+ inferred = normalizeAttributeType(attr.type) ?? detectTypeFromValidationRule(attr.validation?.rule);
28043
28108
  if (!inferred || inferred === "enum") {
28044
28109
  const enumVals = detectEnumFromValidationRule(attr.validation?.rule);
28045
28110
  if (enumVals && enumVals.length > 0) {
@@ -28462,6 +28527,7 @@ function canonicalStorageType(col, dialect) {
28462
28527
  case "text":
28463
28528
  case "date":
28464
28529
  case "datetime":
28530
+ case "timestamptz":
28465
28531
  case "json":
28466
28532
  case "enum":
28467
28533
  return "TEXT";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-query-builder",
3
3
  "type": "module",
4
- "version": "0.1.54",
4
+ "version": "0.1.56",
5
5
  "description": "A simple yet performant query builder for TypeScript. Built with Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",