@aglyn/shared-util-timestamp 1.0.0-beta.143 → 1.0.0-beta.145
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 +27 -31
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
# @aglyn/shared-util-timestamp
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
> Beta. Published from the Aglyn monorepo under the `beta` dist-tag; APIs can change between beta releases.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
npm install @aglyn/shared-util-timestamp@beta
|
|
8
|
+
|
|
9
|
+
A point in time at nanosecond resolution, the JSON shape it serializes to, and
|
|
10
|
+
calendar math in a named time zone. None of the three imports the Firestore
|
|
11
|
+
SDK, or anything else.
|
|
5
12
|
|
|
6
13
|
## `@aglyn/shared-util-timestamp` — the `Timestamp` class
|
|
7
14
|
|
|
@@ -11,16 +18,19 @@ import { Timestamp } from '@aglyn/shared-util-timestamp'
|
|
|
11
18
|
await setDoc(ref, { createdAt: Timestamp.now() })
|
|
12
19
|
```
|
|
13
20
|
|
|
14
|
-
`Timestamp
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
`Timestamp` has the members Firestore's own timestamp has — `seconds`,
|
|
22
|
+
`nanoseconds`, `toDate()`, `toMillis()`, `isEqual()` — and it extends the
|
|
23
|
+
built-in `Date`. That base is deliberate. Firestore's client accepts a field
|
|
24
|
+
value that is `instanceof Date` and writes it as a real timestamp, so a value
|
|
25
|
+
from this class can be written into a document as it is, while the package
|
|
26
|
+
itself depends on no SDK. A plain custom class would be refused by Firestore as
|
|
27
|
+
an unsupported field value.
|
|
19
28
|
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
Three members differ from `Date` on purpose: `valueOf()` returns a zero-padded
|
|
30
|
+
string that orders correctly, `toJSON()` returns `{ seconds, nanoseconds, type }`,
|
|
31
|
+
and `toString()` returns the `Timestamp(seconds=…, nanoseconds=…)` form.
|
|
22
32
|
|
|
23
|
-
## `@aglyn/shared-util-timestamp/timestamp-json` — the
|
|
33
|
+
## `@aglyn/shared-util-timestamp/timestamp-json` — the serialized shape
|
|
24
34
|
|
|
25
35
|
```ts
|
|
26
36
|
import { timestampNowJson } from '@aglyn/shared-util-timestamp/timestamp-json'
|
|
@@ -29,7 +39,7 @@ logger.debug(timestampNowJson(), event, payload)
|
|
|
29
39
|
```
|
|
30
40
|
|
|
31
41
|
Returns exactly what `Timestamp.now().toJSON()` returns, and imports nothing.
|
|
32
|
-
Use it when you only need to **stamp or
|
|
42
|
+
Use it when you only need to **stamp or serialize** — a log line, an emitted
|
|
33
43
|
event, a JSON payload — and the value never reaches Firestore.
|
|
34
44
|
|
|
35
45
|
## `@aglyn/shared-util-timestamp/zoned-time` — calendar math in a named zone
|
|
@@ -51,26 +61,12 @@ It is the one copy the booking slots, the CRM digest and the Sequences send
|
|
|
51
61
|
windows read. Imports nothing, like `timestamp-json`, and
|
|
52
62
|
`zoned-time.isolation.spec.ts` holds it to that.
|
|
53
63
|
|
|
54
|
-
## Why
|
|
55
|
-
|
|
56
|
-
Every tenant site was shipping the Firestore client in its eagerly-loaded page
|
|
57
|
-
chunk. The route was two calls to `Timestamp.now().toJSON()` in `libs/aglyn` —
|
|
58
|
-
both formatting log lines. Nothing on a published site writes to Firestore from
|
|
59
|
-
the browser; the SDK was pure weight.
|
|
60
|
-
|
|
61
|
-
`timestamp-json.isolation.spec.ts` guards this and is worth understanding before
|
|
62
|
-
editing either module: it asserts that requiring `timestamp-json` loads no
|
|
63
|
-
`firebase` module. Its first version sat beside the behavioural tests, which
|
|
64
|
-
import `./timestamp`, so `firebase` was already cached before the check ran and
|
|
65
|
-
it passed just as happily when the isolation was broken. If you touch that test,
|
|
66
|
-
break the isolation on purpose and confirm it fails — a green run proves nothing
|
|
67
|
-
on its own.
|
|
68
|
-
|
|
69
|
-
The type-only `ITimestamp` is safe to import from the root anywhere, since
|
|
70
|
-
`import type` is erased.
|
|
64
|
+
## Why `timestamp-json` is its own entry point
|
|
71
65
|
|
|
72
|
-
|
|
66
|
+
Code that only stamps a log line or an event has no use for the class, so the
|
|
67
|
+
serialized shape is available without it. `ITimestamp`, the structural type, is
|
|
68
|
+
safe to import from the root anywhere: a type import is erased.
|
|
73
69
|
|
|
74
|
-
|
|
70
|
+
## License
|
|
75
71
|
|
|
76
|
-
|
|
72
|
+
Apache-2.0. Source: https://github.com/aglyn/aglyn/tree/main/libs/shared/util/timestamp
|