@aglyn/shared-util-timestamp 1.0.0-beta.143 → 1.0.0-beta.144

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/README.md +27 -31
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,7 +1,14 @@
1
1
  # @aglyn/shared-util-timestamp
2
2
 
3
- Two entry points. **Which one you import decides whether the Firestore client
4
- ends up in your bundle**, so pick deliberately.
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 extends` the Firestore SDK's own `Timestamp`. That `extends` is a
15
- **hard runtime dependency** — not type-only, not tree-shakeable — and it is
16
- load-bearing: Firestore's serialiser recognises timestamps by `instanceof`
17
- against its own class. An object that fails that check is not written as a
18
- timestamp, so ordering queries and `.toDate()` on read stop working.
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
- Use this anywhere the value is **written into a Firestore document**. That is
21
- the console and the plugin console cards, which already ship the SDK.
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 serialised shape
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 serialise** — a log line, an emitted
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 the split exists (AGL-1151)
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
- ## Running unit tests
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
- `npx jest --config libs/shared/util/timestamp/jest.config.ts`
70
+ ## License
75
71
 
76
- (`nx test` leaks the root `.env`; run bare jest.)
72
+ Apache-2.0. Source: https://github.com/aglyn/aglyn/tree/main/libs/shared/util/timestamp
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/shared-util-timestamp",
3
- "version": "1.0.0-beta.143",
3
+ "version": "1.0.0-beta.144",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {