bun-query-builder 0.1.53 → 0.1.55

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.
@@ -11,7 +11,7 @@ export { inspectTable, tableInfo } from './inspect';
11
11
  export { introspect } from './introspect';
12
12
  export { generateModelSource, introspectDatabase, modelNameForTable, sqlTypeToAttr } from './introspect-db';
13
13
  export { makeModel } from './make-model';
14
- export { executeMigration, generateMigration, resetDatabase } from './migrate';
14
+ export { executeMigration, generateMigration, resetDatabase, saveMigrationSnapshot } from './migrate';
15
15
  export { migrateGenerate } from './migrate-generate';
16
16
  export { migrateRollback } from './migrate-rollback';
17
17
  export { migrateList, migrateStatus } from './migrate-status';
@@ -1,4 +1,12 @@
1
- import type { GenerateMigrationResult, MigrateOptions } from '@/types';
1
+ import type { GenerateMigrationResult, MigrateOptions, SupportedDialect } from '@/types';
2
+ import type { MigrationPlan } from '@/migrations';
3
+ /**
4
+ * Persist a plan returned by a dry-run migration after an embedding framework
5
+ * has successfully written the SQL itself. This keeps preview semantics pure
6
+ * while allowing a custom migration writer to advance the source-of-truth
7
+ * snapshot only after its own persistence step succeeds.
8
+ */
9
+ export declare function saveMigrationSnapshot(plan: MigrationPlan, options?: { dialect?: SupportedDialect, workspaceRoot?: string }): void;
2
10
  /**
3
11
  * Generate migration files by comparing the stored model snapshot with current models.
4
12
  *
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":
@@ -18534,6 +18540,7 @@ var init_drivers = __esm(() => {
18534
18540
  // src/actions/migrate.ts
18535
18541
  var exports_migrate = {};
18536
18542
  __export(exports_migrate, {
18543
+ saveMigrationSnapshot: () => saveMigrationSnapshot,
18537
18544
  resetDatabase: () => resetDatabase,
18538
18545
  generateMigration: () => generateMigration,
18539
18546
  executeMigration: () => executeMigration,
@@ -18590,6 +18597,10 @@ function savePlanSnapshot(workspaceRoot, dialect, plan) {
18590
18597
  writeFileSync11(snapshotPath, JSON.stringify(snapshot, null, 2));
18591
18598
  info(`-- Model snapshot saved to ${snapshotPath}`);
18592
18599
  }
18600
+ function saveMigrationSnapshot(plan, options = {}) {
18601
+ const dialect = options.dialect ?? plan.dialect;
18602
+ savePlanSnapshot(options.workspaceRoot ?? getWorkspaceRoot(), dialect, plan);
18603
+ }
18593
18604
  function getWorkspaceRoot() {
18594
18605
  return process25.cwd();
18595
18606
  }
@@ -27977,6 +27988,9 @@ function detectTypeFromValidationRule(rule) {
27977
27988
  case "datetime":
27978
27989
  case "timestamp":
27979
27990
  return "datetime";
27991
+ case "timestamptz":
27992
+ case "timestamp_tz":
27993
+ return "timestamptz";
27980
27994
  case "json":
27981
27995
  return "json";
27982
27996
  case "enum":
@@ -28001,11 +28015,57 @@ function detectTypeFromValidationRule(rule) {
28001
28015
  return "date";
28002
28016
  if (type === "datetime")
28003
28017
  return "datetime";
28018
+ if (type === "timestamptz" || type === "timestamp_tz")
28019
+ return "timestamptz";
28004
28020
  if (type === "json")
28005
28021
  return "json";
28006
28022
  }
28007
28023
  return;
28008
28024
  }
28025
+ function normalizeAttributeType(value) {
28026
+ if (typeof value !== "string")
28027
+ return;
28028
+ const type = value.trim().toLowerCase().replace(/[\s-]+/g, "_");
28029
+ switch (type) {
28030
+ case "varchar":
28031
+ case "string":
28032
+ return "string";
28033
+ case "text":
28034
+ return "text";
28035
+ case "bool":
28036
+ case "boolean":
28037
+ return "boolean";
28038
+ case "int":
28039
+ case "integer":
28040
+ return "integer";
28041
+ case "bigint":
28042
+ return "bigint";
28043
+ case "float":
28044
+ return "float";
28045
+ case "double":
28046
+ return "double";
28047
+ case "number":
28048
+ case "numeric":
28049
+ case "decimal":
28050
+ return "decimal";
28051
+ case "date":
28052
+ return "date";
28053
+ case "datetime":
28054
+ case "timestamp":
28055
+ return "datetime";
28056
+ case "timestamp_tz":
28057
+ case "timestamptz":
28058
+ case "timestamp_with_time_zone":
28059
+ return "timestamptz";
28060
+ case "json":
28061
+ case "jsonb":
28062
+ return "json";
28063
+ case "enum":
28064
+ return "enum";
28065
+ default:
28066
+ return;
28067
+ }
28068
+ }
28009
28069
  function buildMigrationPlan2(models, options) {
28010
28070
  const meta = buildSchemaMeta(models);
28011
28071
  const tables = [];
@@ -28035,7 +28095,7 @@ function buildMigrationPlan2(models, options) {
28035
28095
  let inferred;
28036
28096
  let enumValues;
28037
28097
  const isPk = attrName === primaryKey;
28038
- inferred = detectTypeFromValidationRule(attr.validation?.rule);
28098
+ inferred = normalizeAttributeType(attr.type) ?? detectTypeFromValidationRule(attr.validation?.rule);
28039
28099
  if (!inferred || inferred === "enum") {
28040
28100
  const enumVals = detectEnumFromValidationRule(attr.validation?.rule);
28041
28101
  if (enumVals && enumVals.length > 0) {
@@ -28458,6 +28518,7 @@ function canonicalStorageType(col, dialect) {
28458
28518
  case "text":
28459
28519
  case "date":
28460
28520
  case "datetime":
28521
+ case "timestamptz":
28461
28522
  case "json":
28462
28523
  case "enum":
28463
28524
  return "TEXT";
@@ -30951,7 +31012,7 @@ function getPrefix() {
30951
31012
  }
30952
31013
  var prefix = getPrefix();
30953
31014
  // package.json
30954
- var version2 = "0.1.53";
31015
+ var version2 = "0.1.55";
30955
31016
 
30956
31017
  // bin/cli.ts
30957
31018
  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":
@@ -18533,6 +18539,7 @@ var init_drivers = __esm(() => {
18533
18539
  // src/actions/migrate.ts
18534
18540
  var exports_migrate = {};
18535
18541
  __export(exports_migrate, {
18542
+ saveMigrationSnapshot: () => saveMigrationSnapshot,
18536
18543
  resetDatabase: () => resetDatabase,
18537
18544
  generateMigration: () => generateMigration,
18538
18545
  executeMigration: () => executeMigration,
@@ -18589,6 +18596,10 @@ function savePlanSnapshot(workspaceRoot, dialect, plan) {
18589
18596
  writeFileSync11(snapshotPath, JSON.stringify(snapshot, null, 2));
18590
18597
  info(`-- Model snapshot saved to ${snapshotPath}`);
18591
18598
  }
18599
+ function saveMigrationSnapshot(plan, options = {}) {
18600
+ const dialect = options.dialect ?? plan.dialect;
18601
+ savePlanSnapshot(options.workspaceRoot ?? getWorkspaceRoot(), dialect, plan);
18602
+ }
18592
18603
  function getWorkspaceRoot() {
18593
18604
  return process25.cwd();
18594
18605
  }
@@ -27976,6 +27987,9 @@ function detectTypeFromValidationRule(rule) {
27976
27987
  case "datetime":
27977
27988
  case "timestamp":
27978
27989
  return "datetime";
27990
+ case "timestamptz":
27991
+ case "timestamp_tz":
27992
+ return "timestamptz";
27979
27993
  case "json":
27980
27994
  return "json";
27981
27995
  case "enum":
@@ -28000,11 +28014,57 @@ function detectTypeFromValidationRule(rule) {
28000
28014
  return "date";
28001
28015
  if (type === "datetime")
28002
28016
  return "datetime";
28017
+ if (type === "timestamptz" || type === "timestamp_tz")
28018
+ return "timestamptz";
28003
28019
  if (type === "json")
28004
28020
  return "json";
28005
28021
  }
28006
28022
  return;
28007
28023
  }
28024
+ function normalizeAttributeType(value) {
28025
+ if (typeof value !== "string")
28026
+ return;
28027
+ const type = value.trim().toLowerCase().replace(/[\s-]+/g, "_");
28028
+ switch (type) {
28029
+ case "varchar":
28030
+ case "string":
28031
+ return "string";
28032
+ case "text":
28033
+ return "text";
28034
+ case "bool":
28035
+ case "boolean":
28036
+ return "boolean";
28037
+ case "int":
28038
+ case "integer":
28039
+ return "integer";
28040
+ case "bigint":
28041
+ return "bigint";
28042
+ case "float":
28043
+ return "float";
28044
+ case "double":
28045
+ return "double";
28046
+ case "number":
28047
+ case "numeric":
28048
+ case "decimal":
28049
+ return "decimal";
28050
+ case "date":
28051
+ return "date";
28052
+ case "datetime":
28053
+ case "timestamp":
28054
+ return "datetime";
28055
+ case "timestamp_tz":
28056
+ case "timestamptz":
28057
+ case "timestamp_with_time_zone":
28058
+ return "timestamptz";
28059
+ case "json":
28060
+ case "jsonb":
28061
+ return "json";
28062
+ case "enum":
28063
+ return "enum";
28064
+ default:
28065
+ return;
28066
+ }
28067
+ }
28008
28068
  function buildMigrationPlan2(models, options) {
28009
28069
  const meta = buildSchemaMeta(models);
28010
28070
  const tables = [];
@@ -28034,7 +28094,7 @@ function buildMigrationPlan2(models, options) {
28034
28094
  let inferred;
28035
28095
  let enumValues;
28036
28096
  const isPk = attrName === primaryKey;
28037
- inferred = detectTypeFromValidationRule(attr.validation?.rule);
28097
+ inferred = normalizeAttributeType(attr.type) ?? detectTypeFromValidationRule(attr.validation?.rule);
28038
28098
  if (!inferred || inferred === "enum") {
28039
28099
  const enumVals = detectEnumFromValidationRule(attr.validation?.rule);
28040
28100
  if (enumVals && enumVals.length > 0) {
@@ -28457,6 +28517,7 @@ function canonicalStorageType(col, dialect) {
28457
28517
  case "text":
28458
28518
  case "date":
28459
28519
  case "datetime":
28520
+ case "timestamptz":
28460
28521
  case "json":
28461
28522
  case "enum":
28462
28523
  return "TEXT";
@@ -28930,6 +28991,7 @@ export {
28930
28991
  setQueryCacheMaxSize,
28931
28992
  setConfig,
28932
28993
  seedModel,
28994
+ saveMigrationSnapshot,
28933
28995
  runSeeders,
28934
28996
  runSeeder,
28935
28997
  runBenchmark,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-query-builder",
3
3
  "type": "module",
4
- "version": "0.1.53",
4
+ "version": "0.1.55",
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",