velocious 1.0.470 → 1.0.472
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/README.md +5 -3
- package/build/configuration-types.js +1 -0
- package/build/configuration.js +27 -1
- package/build/controller.js +13 -1
- package/build/database/datetime-storage.js +49 -5
- package/build/database/record/index.js +14 -4
- package/build/environment-handlers/base.js +46 -0
- package/build/environment-handlers/node/cli/commands/generate/base-models.js +4 -1
- package/build/environment-handlers/node/cli/commands/generate/frontend-models.js +368 -43
- package/build/environment-handlers/node/cli/commands/generate/generated-file-banner.js +15 -0
- package/build/environment-handlers/node.js +84 -8
- package/build/frontend-model-controller.js +7 -7
- package/build/frontend-models/base.js +75 -9
- package/build/frontend-models/transport-serialization.js +41 -8
- package/build/frontend-models/websocket-channel.js +18 -1
- package/build/frontend-models/websocket-publishers.js +12 -1
- package/build/http-server/client/request-runner.js +13 -1
- package/build/src/configuration-types.d.ts +5 -0
- package/build/src/configuration-types.d.ts.map +1 -1
- package/build/src/configuration-types.js +2 -1
- package/build/src/configuration.d.ts +14 -1
- package/build/src/configuration.d.ts.map +1 -1
- package/build/src/configuration.js +25 -2
- package/build/src/controller.d.ts +5 -0
- package/build/src/controller.d.ts.map +1 -1
- package/build/src/controller.js +12 -2
- package/build/src/database/datetime-storage.d.ts +12 -4
- package/build/src/database/datetime-storage.d.ts.map +1 -1
- package/build/src/database/datetime-storage.js +48 -6
- package/build/src/database/record/index.d.ts +5 -0
- package/build/src/database/record/index.d.ts.map +1 -1
- package/build/src/database/record/index.js +13 -5
- package/build/src/environment-handlers/base.d.ts +19 -0
- package/build/src/environment-handlers/base.d.ts.map +1 -1
- package/build/src/environment-handlers/base.js +41 -1
- package/build/src/environment-handlers/node/cli/commands/generate/base-models.d.ts.map +1 -1
- package/build/src/environment-handlers/node/cli/commands/generate/base-models.js +4 -2
- package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.d.ts +219 -40
- package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.d.ts.map +1 -1
- package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.js +317 -43
- package/build/src/environment-handlers/node/cli/commands/generate/generated-file-banner.d.ts +9 -0
- package/build/src/environment-handlers/node/cli/commands/generate/generated-file-banner.d.ts.map +1 -0
- package/build/src/environment-handlers/node/cli/commands/generate/generated-file-banner.js +13 -0
- package/build/src/environment-handlers/node.d.ts +1 -0
- package/build/src/environment-handlers/node.d.ts.map +1 -1
- package/build/src/environment-handlers/node.js +76 -9
- package/build/src/frontend-model-controller.js +8 -8
- package/build/src/frontend-models/base.d.ts +4 -0
- package/build/src/frontend-models/base.d.ts.map +1 -1
- package/build/src/frontend-models/base.js +64 -9
- package/build/src/frontend-models/transport-serialization.d.ts +30 -1
- package/build/src/frontend-models/transport-serialization.d.ts.map +1 -1
- package/build/src/frontend-models/transport-serialization.js +34 -9
- package/build/src/frontend-models/websocket-channel.d.ts.map +1 -1
- package/build/src/frontend-models/websocket-channel.js +16 -2
- package/build/src/frontend-models/websocket-publishers.d.ts.map +1 -1
- package/build/src/frontend-models/websocket-publishers.js +12 -2
- package/build/src/http-server/client/request-runner.d.ts.map +1 -1
- package/build/src/http-server/client/request-runner.js +13 -2
- package/build/src/time-zone.d.ts +16 -0
- package/build/src/time-zone.d.ts.map +1 -0
- package/build/src/time-zone.js +56 -0
- package/build/time-zone.js +65 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/scripts/test-browser.js +1 -0
- package/src/configuration-types.js +1 -0
- package/src/configuration.js +27 -1
- package/src/controller.js +13 -1
- package/src/database/datetime-storage.js +49 -5
- package/src/database/record/index.js +14 -4
- package/src/environment-handlers/base.js +46 -0
- package/src/environment-handlers/node/cli/commands/generate/base-models.js +4 -1
- package/src/environment-handlers/node/cli/commands/generate/frontend-models.js +368 -43
- package/src/environment-handlers/node/cli/commands/generate/generated-file-banner.js +15 -0
- package/src/environment-handlers/node.js +84 -8
- package/src/frontend-model-controller.js +7 -7
- package/src/frontend-models/base.js +75 -9
- package/src/frontend-models/transport-serialization.js +41 -8
- package/src/frontend-models/websocket-channel.js +18 -1
- package/src/frontend-models/websocket-publishers.js +12 -1
- package/src/http-server/client/request-runner.js +13 -1
- package/src/time-zone.js +65 -0
package/src/time-zone.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {Temporal} from "@js-temporal/polyfill"
|
|
4
|
+
|
|
5
|
+
export const REQUEST_TIME_ZONE_HEADER = "X-Velocious-Time-Zone"
|
|
6
|
+
|
|
7
|
+
const timezoneOffsetPattern = /^[+-]\d{2}:\d{2}$/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Validates a configured or client-provided IANA timezone.
|
|
11
|
+
* @param {string} timeZone - Timezone identifier.
|
|
12
|
+
* @param {string} label - Error label.
|
|
13
|
+
* @returns {string} - Normalized timezone identifier.
|
|
14
|
+
*/
|
|
15
|
+
export function validateTimeZone(timeZone, label = "timeZone") {
|
|
16
|
+
if (typeof timeZone !== "string") {
|
|
17
|
+
throw new Error(`Expected ${label} to be a timezone string`)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const normalizedTimeZone = timeZone.trim()
|
|
21
|
+
|
|
22
|
+
if (!normalizedTimeZone) {
|
|
23
|
+
throw new Error(`Expected ${label} to be a timezone string`)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (timezoneOffsetPattern.test(normalizedTimeZone)) {
|
|
27
|
+
throw new Error(`Expected ${label} to be an IANA timezone string, not offset "${normalizedTimeZone}"`)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
Temporal.ZonedDateTime.from({
|
|
32
|
+
day: 1,
|
|
33
|
+
hour: 0,
|
|
34
|
+
microsecond: 0,
|
|
35
|
+
millisecond: 0,
|
|
36
|
+
minute: 0,
|
|
37
|
+
month: 1,
|
|
38
|
+
nanosecond: 0,
|
|
39
|
+
second: 0,
|
|
40
|
+
timeZone: normalizedTimeZone,
|
|
41
|
+
year: 2000
|
|
42
|
+
})
|
|
43
|
+
} catch (error) {
|
|
44
|
+
throw new Error(`Invalid timezone "${normalizedTimeZone}" for ${label}`, {cause: error})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return normalizedTimeZone
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Formats a Date as an ISO timestamp in the given timezone.
|
|
52
|
+
* @param {Date} value - Date instant.
|
|
53
|
+
* @param {string} timeZone - IANA timezone identifier.
|
|
54
|
+
* @returns {string} - ISO timestamp carrying the timezone's offset for the instant.
|
|
55
|
+
*/
|
|
56
|
+
export function formatDateInTimeZone(value, timeZone) {
|
|
57
|
+
const normalizedTimeZone = validateTimeZone(timeZone, "timeZone")
|
|
58
|
+
const instant = Temporal.Instant.fromEpochMilliseconds(value.getTime())
|
|
59
|
+
const zonedDateTime = instant.toZonedDateTimeISO(normalizedTimeZone)
|
|
60
|
+
|
|
61
|
+
return zonedDateTime.toString({
|
|
62
|
+
fractionalSecondDigits: 3,
|
|
63
|
+
timeZoneName: "never"
|
|
64
|
+
})
|
|
65
|
+
}
|