@holo-js/db 0.1.5 → 0.1.7

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.
Files changed (2) hide show
  1. package/dist/index.mjs +51 -5
  2. package/package.json +7 -7
package/dist/index.mjs CHANGED
@@ -1901,8 +1901,42 @@ function parseDateLike(value) {
1901
1901
  }
1902
1902
  return new Date(String(value));
1903
1903
  }
1904
- function stringifyDateLike(value) {
1905
- return value instanceof Date ? value.toISOString() : value;
1904
+ function padDatePart(value, length = 2) {
1905
+ return String(value).padStart(length, "0");
1906
+ }
1907
+ function formatUtcDate(value) {
1908
+ return [
1909
+ value.getUTCFullYear(),
1910
+ padDatePart(value.getUTCMonth() + 1),
1911
+ padDatePart(value.getUTCDate())
1912
+ ].join("-");
1913
+ }
1914
+ function formatUtcDateTime(value) {
1915
+ return [
1916
+ formatUtcDate(value),
1917
+ [
1918
+ padDatePart(value.getUTCHours()),
1919
+ padDatePart(value.getUTCMinutes()),
1920
+ padDatePart(value.getUTCSeconds())
1921
+ ].join(":")
1922
+ ].join(" ");
1923
+ }
1924
+ function parseIsoTemporalString(value) {
1925
+ if (!/^\d{4}-\d{2}-\d{2}T/.test(value)) {
1926
+ return void 0;
1927
+ }
1928
+ const parsed = new Date(value);
1929
+ return Number.isNaN(parsed.getTime()) ? void 0 : parsed;
1930
+ }
1931
+ function stringifyDateLike(dialect, column2, value) {
1932
+ if (dialect !== "mysql") {
1933
+ return value instanceof Date ? value.toISOString() : value;
1934
+ }
1935
+ const date = value instanceof Date ? value : typeof value === "string" ? parseIsoTemporalString(value) : void 0;
1936
+ if (!date) {
1937
+ return value;
1938
+ }
1939
+ return column2.kind === "date" ? formatUtcDate(date) : formatUtcDateTime(date);
1906
1940
  }
1907
1941
  function parseVectorString(value) {
1908
1942
  const trimmed = value.trim();
@@ -1979,7 +2013,7 @@ function normalizeDialectWriteValue(dialect, column2, value) {
1979
2013
  case "date":
1980
2014
  case "datetime":
1981
2015
  case "timestamp":
1982
- return stringifyDateLike(value);
2016
+ return stringifyDateLike(dialect, column2, value);
1983
2017
  case "vector":
1984
2018
  if (!DIALECT_VECTOR_SUPPORT[dialect]) {
1985
2019
  throw new CapabilityError(`${DIALECT_DISPLAY_NAME[dialect]} does not support logical vector columns.`);
@@ -6212,7 +6246,7 @@ var MigrationService = class {
6212
6246
  await new TableQueryBuilder(migrationsTable, tx).insert({
6213
6247
  name: migration.name,
6214
6248
  batch: nextBatch,
6215
- migrated_at: (/* @__PURE__ */ new Date()).toISOString()
6249
+ migrated_at: /* @__PURE__ */ new Date()
6216
6250
  });
6217
6251
  });
6218
6252
  });
@@ -6421,6 +6455,16 @@ function tryGetDefinitionTableName(definition) {
6421
6455
  throw error;
6422
6456
  }
6423
6457
  }
6458
+ function tryGetDefinitionPrimaryKey(definition) {
6459
+ try {
6460
+ return definition.primaryKey;
6461
+ } catch (error) {
6462
+ if (isMissingGeneratedSchemaModelError(error)) {
6463
+ return void 0;
6464
+ }
6465
+ throw error;
6466
+ }
6467
+ }
6424
6468
  function definitionsReferToSameModel(left, right) {
6425
6469
  if (left === right) {
6426
6470
  return true;
@@ -6428,7 +6472,9 @@ function definitionsReferToSameModel(left, right) {
6428
6472
  const leftTableName = tryGetDefinitionTableName(left);
6429
6473
  const rightTableName = tryGetDefinitionTableName(right);
6430
6474
  if (!leftTableName || !rightTableName) {
6431
- return left.name === right.name && left.primaryKey === right.primaryKey && left.morphClass === right.morphClass;
6475
+ const leftPrimaryKey = tryGetDefinitionPrimaryKey(left);
6476
+ const rightPrimaryKey = tryGetDefinitionPrimaryKey(right);
6477
+ return left.name === right.name && (leftPrimaryKey === void 0 || rightPrimaryKey === void 0 || leftPrimaryKey === rightPrimaryKey) && left.morphClass === right.morphClass;
6432
6478
  }
6433
6479
  return leftTableName === rightTableName && left.primaryKey === right.primaryKey && left.morphClass === right.morphClass;
6434
6480
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holo-js/db",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Holo-JS Framework - portable database, ORM, migrations, factories, and seeders",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -28,9 +28,9 @@
28
28
  "uuid": "^12.0.0"
29
29
  },
30
30
  "peerDependencies": {
31
- "@holo-js/db-mysql": "^0.1.5",
32
- "@holo-js/db-postgres": "^0.1.5",
33
- "@holo-js/db-sqlite": "^0.1.5"
31
+ "@holo-js/db-mysql": "^0.1.7",
32
+ "@holo-js/db-postgres": "^0.1.7",
33
+ "@holo-js/db-sqlite": "^0.1.7"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@holo-js/db-mysql": {
@@ -44,9 +44,9 @@
44
44
  }
45
45
  },
46
46
  "devDependencies": {
47
- "@holo-js/db-mysql": "^0.1.5",
48
- "@holo-js/db-postgres": "^0.1.5",
49
- "@holo-js/db-sqlite": "^0.1.5",
47
+ "@holo-js/db-mysql": "^0.1.7",
48
+ "@holo-js/db-postgres": "^0.1.7",
49
+ "@holo-js/db-sqlite": "^0.1.7",
50
50
  "tsup": "^8.3.5",
51
51
  "typescript": "^5.7.2"
52
52
  }