@xemahq/object-projection-nest 0.6.3 → 0.8.0

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 +45 -89
  2. package/package.json +13 -9
package/README.md CHANGED
@@ -1,105 +1,61 @@
1
1
  # @xemahq/object-projection-nest
2
2
 
3
- This package belongs to Layer 1 — it is a kernel-side NestJS SDK with zero
4
- domain knowledge and no dependency on any Xema service.
3
+ > Shared NestJS building blocks for publishing a service's object projection.
5
4
 
6
- It ships the shared implementation of the **XSI plane-1 object projection**
7
- surface that every XemaObject-owning service exposes so
8
- `object-registry-api` can build the platform-wide object index:
5
+ ## Overview
9
6
 
10
- | piece | export |
11
- | --- | --- |
12
- | `GET /describe-objects` wire DTOs | `DescribeObjectsResponseDto`, `XemaObjectResponseDto`, `XemaSpaceRefDto`, `XemaSubjectRefDto` |
13
- | CloudEvent descriptor factory | `defineObjectProjectionEvents(serviceName)` |
14
- | change-driven publisher with reconcile-on-boot | `ObjectProjectionPublisherService` |
15
- | the slice content digest it compares | `projectionEnvelopeDigest(envelope)` |
16
-
17
- ## Freshness model: reconcile on boot, publish on change
18
-
19
- The publisher pushes the COMPLETE slice **unconditionally at boot** and
20
- thereafter **only when the slice has actually changed**.
21
-
22
- - **boot** — always publishes. A fresh process knows nothing about what the
23
- registry currently holds for its source, so this is what repairs a slice
24
- whose publish was dropped or failed before the last restart.
25
- - **every `PROJECTION_REFRESH_INTERVAL_MS`** — builds the envelope, digests it
26
- locally, and publishes *only* if the digest differs from the last
27
- successfully published one. In a quiet hour this puts **nothing** on the bus.
28
- - **`scheduleRepublish()`** — an optional per-write hook that collapses
29
- detection latency from one interval to `PROJECTION_DEBOUNCE_MS`. It passes
30
- the same digest gate, so a write that projects to identical content still
31
- publishes nothing. Wiring one can only ever make a producer more responsive,
32
- never noisier.
33
- - **`publishProjection(Manual)`** — forced, like boot. "Force a resync" that
34
- silently did nothing would be worse than the republish it saves.
35
-
36
- The interval is a POLL, not a heartbeat, and it is deliberately still here:
37
- most producers in the fleet wire no per-write hook, so for them it *is* the
38
- change signal. Deleting it would leave them publishing at boot and never again
39
- — the registry's cache would go stale on every write with nothing anywhere
40
- reporting a failure.
41
-
42
- The baseline is per PROCESS and in memory. Two replicas each publish once per
43
- real change instead of once a minute each; the consumer applies an idempotent
44
- REPLACE, so the duplicate costs nothing.
45
-
46
- ## Producer shape
47
-
48
- A producing service adds one `describe-objects/` folder:
7
+ Every service that owns Xema objects exposes the same projection surface so the platform-wide object index can be built: a `GET /describe-objects` response and a CloudEvent that carries the complete slice. This package ships the response DTOs, the event descriptor factory and a publisher base class that publishes at boot and then only when the slice changes.
8
+
9
+ ## When to use it
10
+
11
+ - Use it in a NestJS service that owns objects and must project them into the object registry.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pnpm add @xemahq/object-projection-nest
17
+ ```
18
+
19
+ ## Usage
49
20
 
50
21
  ```ts
51
- // projection-events.registry.ts
52
- export const { descriptor: ObjectRegistryProjectionPublishedEvent, descriptors } =
53
- defineObjectProjectionEvents('knowledge-base-api');
22
+ import {
23
+ defineObjectProjectionEvents,
24
+ ObjectProjectionPublisherService,
25
+ } from '@xemahq/object-projection-nest';
54
26
 
55
- // describe-objects.service.ts — builds the COMPLETE current slice
56
- @Injectable()
57
- export class DescribeObjectsService {
58
- async buildEnvelope(): Promise<DescribeObjectsResponseDto> { /* … */ }
59
- }
27
+ export const { descriptor: ProjectionPublishedEvent } =
28
+ defineObjectProjectionEvents('my-service-api');
60
29
 
61
- // projection-publisher.service.ts — PUSH path (optional; PULL alone is valid)
62
30
  @Injectable()
63
31
  export class ProjectionPublisherService extends ObjectProjectionPublisherService {
64
- constructor(
65
- publisher: DescriptorEventPublisherService,
66
- describeObjects: DescribeObjectsService,
67
- ) {
32
+ constructor(publisher: DescriptorEventPublisherService, describeObjects: DescribeObjectsService) {
68
33
  super(publisher, {
69
- source: KNOWLEDGE_BASE_PROJECTION_SOURCE,
70
- descriptor: ObjectRegistryProjectionPublishedEvent,
71
- buildEnvelope: () => describeObjects.buildEnvelope(),
34
+ source: MY_PROJECTION_SOURCE,
35
+ descriptor: ProjectionPublishedEvent,
36
+ buildEnvelope: () => describeObjects.buildEnvelope(), // the COMPLETE current slice
72
37
  });
73
38
  }
74
39
  }
75
40
  ```
76
41
 
77
- ## Layout note
78
-
79
- Sources live under `src/projection/` (not `src/lib/`) and the package declares a
80
- `./*` subpath export. This is load-bearing, not cosmetic: the `@nestjs/swagger`
81
- CLI plugin emits a `require()` of a DTO's *physical declaration path*, which
82
- `tooling/codegen/scrub-swagger-plugin-paths.mjs` rewrites to
83
- `@xemahq/<pkg>/<first-dir-under-dist>`. If that directory is not a resolvable
84
- subpath export, every consuming pod crashes at boot with
85
- `ERR_PACKAGE_PATH_NOT_EXPORTED`. Same convention as
86
- `@xemahq/kernel-contracts`. Consumers import from the package root.
87
-
88
- ## Invariants
89
-
90
- - A projection is always the **COMPLETE** slice. The registry REPLACES its
91
- cache slice keyed by `source` atomically; there is no delta primitive.
92
- - `payload` is opaque on the wire. The per-kind payload schema is owned by the
93
- producing service's domain contract; plane 1 carries it through and plane 3
94
- (Capability) is the validation point.
95
- - A row that cannot be projected (missing scope qualifier, missing version)
96
- MUST throw a typed error carrying the row id. Never skip it silently.
97
- - The publisher logs and does not rethrow on transport failure — a
98
- cache-refresh push must not crash its host. The next tick retries **because
99
- the baseline advances only after `publish` resolves**, and the consumer can
100
- always recover the same slice over the pull path.
101
- - An ABSENT key and an EMPTY collection are different slices. The digest uses
102
- the kernel's `canonicalJsonStringify`, which drops an `undefined` property
103
- and keeps `[]`, so a producer that starts emitting an empty collection where
104
- it previously omitted the key republishes once. That is correct, and it costs
105
- nothing across a deploy because the boot publish re-seeds the baseline anyway.
42
+ A projection is always the complete slice; the registry replaces its slice for the `source`. Call the protected `scheduleRepublish()` from a write hook to publish sooner than the poll interval.
43
+
44
+ ## Behaviour
45
+
46
+ | Trigger | Publishes |
47
+ | --- | --- |
48
+ | Boot | Always |
49
+ | Every `PROJECTION_REFRESH_INTERVAL_MS` (60 000 ms) | Only if the slice digest changed |
50
+ | `scheduleRepublish()`, debounced by `PROJECTION_DEBOUNCE_MS` (1 000 ms) | Only if the slice digest changed |
51
+ | `publishProjection(...)` | Always (forced) |
52
+
53
+ ## Peer requirements
54
+
55
+ - `@nestjs/common`, `@nestjs/swagger` >= 11
56
+ - `@xemahq/events`, `@xemahq/contracts`
57
+ - `zod` ^4
58
+
59
+ ## License
60
+
61
+ LicenseRef-Xema-BSL-1.1 &copy; Xema — [xema.dev](https://xema.dev)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xemahq/object-projection-nest",
3
- "version": "0.6.3",
3
+ "version": "0.8.0",
4
4
  "description": "Shared NestJS building blocks for the XSI plane-1 object projection surface (`GET /describe-objects` + the `xema.object-registry.projection.published.v1` CloudEvent) that every XemaObject-owning service implements.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -12,10 +12,10 @@
12
12
  "dist"
13
13
  ],
14
14
  "peerDependencies": {
15
- "@nestjs/common": ">=11.0.0",
16
- "@nestjs/swagger": ">=11.0.0",
17
- "@xemahq/events": ">=0.11.0",
18
- "@xemahq/contracts": ">=0.4.0",
15
+ "@nestjs/common": "^11.1.18",
16
+ "@nestjs/swagger": "^11.2.6",
17
+ "@xemahq/events": "^0.14.0",
18
+ "@xemahq/contracts": "^0.80.0",
19
19
  "zod": "^4.3.6"
20
20
  },
21
21
  "devDependencies": {
@@ -23,9 +23,10 @@
23
23
  "@nestjs/swagger": "11.2.6",
24
24
  "@types/jest": "^30.0.0",
25
25
  "@types/node": "25.2.3",
26
- "@xemahq/eslint-config": "^0.5.0",
27
- "@xemahq/events": ">=0.11.0",
28
- "@xemahq/contracts": "^0.18.0",
26
+ "@xemahq/eslint-config": "^0.14.0",
27
+ "@xemahq/event-hub-client": "^9.0.0",
28
+ "@xemahq/events": "^0.14.0",
29
+ "@xemahq/contracts": "^0.80.0",
29
30
  "eslint": "^9.39.4",
30
31
  "jest": "^30.3.0",
31
32
  "ts-jest": "^29.4.9",
@@ -59,5 +60,8 @@
59
60
  "lint": "eslint .",
60
61
  "test": "jest --config jest.config.ts",
61
62
  "typecheck": "tsc -p tsconfig.json --noEmit"
63
+ },
64
+ "xemaRelease": {
65
+ "sourceDigest": "sha256:b8939054c7dfb899933d4f30d333faeb60fd0f80a66f16dbe63159f82b5649cb"
62
66
  }
63
- }
67
+ }