@jskit-ai/database-runtime 0.1.146 → 0.1.147

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.
@@ -1,7 +1,7 @@
1
1
  export default Object.freeze({
2
2
  packageVersion: 1,
3
3
  packageId: "@jskit-ai/database-runtime",
4
- version: "0.1.146",
4
+ version: "0.1.147",
5
5
  kind: "runtime",
6
6
  dependsOn: [
7
7
  "@jskit-ai/kernel"
@@ -70,7 +70,7 @@ export default Object.freeze({
70
70
  mutations: {
71
71
  dependencies: {
72
72
  runtime: {
73
- "@jskit-ai/kernel": "0.1.146",
73
+ "@jskit-ai/kernel": "0.1.147",
74
74
  "dotenv": "^16.4.5",
75
75
  "knex": "^3.1.0"
76
76
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/database-runtime",
3
- "version": "0.1.146",
3
+ "version": "0.1.147",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test"
@@ -25,6 +25,6 @@
25
25
  "./shared/transactions": "./src/shared/transactions.js"
26
26
  },
27
27
  "dependencies": {
28
- "@jskit-ai/kernel": "0.1.146"
28
+ "@jskit-ai/kernel": "0.1.147"
29
29
  }
30
30
  }
@@ -1,9 +1,30 @@
1
+ const DATABASE_UTC_DATE_TIME_PATTERN = /^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}(?:\.\d+)?)$/u;
2
+ const RFC_3339_DATE_TIME_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/u;
3
+
1
4
  function normalizeDateInput(value) {
2
5
  if (!value) {
3
6
  return null;
4
7
  }
5
8
 
6
- const date = value instanceof Date ? value : new Date(value);
9
+ let date;
10
+ if (value instanceof Date) {
11
+ date = value;
12
+ } else if (typeof value === "string") {
13
+ const normalized = value.trim();
14
+ const databaseMatch = DATABASE_UTC_DATE_TIME_PATTERN.exec(normalized);
15
+ const dateTime = databaseMatch
16
+ ? `${databaseMatch[1]}T${databaseMatch[2]}Z`
17
+ : RFC_3339_DATE_TIME_PATTERN.test(normalized)
18
+ ? normalized
19
+ : "";
20
+ if (!dateTime) {
21
+ return null;
22
+ }
23
+ date = new Date(dateTime);
24
+ } else {
25
+ return null;
26
+ }
27
+
7
28
  if (Number.isNaN(date.getTime())) {
8
29
  return null;
9
30
  }
@@ -12,8 +33,8 @@ function normalizeDateInput(value) {
12
33
  }
13
34
 
14
35
  function toDateOrThrow(value) {
15
- const date = value instanceof Date ? value : new Date(value);
16
- if (Number.isNaN(date.getTime())) {
36
+ const date = normalizeDateInput(value);
37
+ if (!date) {
17
38
  throw new TypeError("Invalid date value.");
18
39
  }
19
40
 
@@ -4,6 +4,7 @@ import { toIsoString, toDatabaseDateTimeUtc } from "../src/shared/dateUtils.js";
4
4
 
5
5
  test("toIsoString normalizes valid date input", () => {
6
6
  assert.equal(toIsoString("2024-01-01T00:00:00.000Z"), "2024-01-01T00:00:00.000Z");
7
+ assert.equal(toIsoString("2024-01-01 01:02:03.045"), "2024-01-01T01:02:03.045Z");
7
8
  });
8
9
 
9
10
  test("toDatabaseDateTimeUtc formats DATETIME(3) UTC string", () => {
@@ -20,5 +21,7 @@ test("toDatabaseDateTimeUtc preserves nullable empty values", () => {
20
21
 
21
22
  test("date utils throw on invalid date", () => {
22
23
  assert.throws(() => toIsoString("not-a-date"), /Invalid date value\./);
24
+ assert.throws(() => toIsoString("January 1, 2024"), /Invalid date value\./);
25
+ assert.throws(() => toIsoString("2024-01-01T00:00:00"), /Invalid date value\./);
23
26
  assert.throws(() => toDatabaseDateTimeUtc("not-a-date"), /Invalid date value\./);
24
27
  });