@honua/react 0.1.2-beta.0 → 0.1.7-beta.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.
- package/contract/discovery.d.ts +34 -0
- package/contract/discovery.d.ts.map +1 -1
- package/contract/index.d.ts +7 -5
- package/contract/index.d.ts.map +1 -1
- package/contract/index.js +3 -2
- package/contract/pmtiles.d.ts +10 -1
- package/contract/pmtiles.d.ts.map +1 -1
- package/contract/pmtiles.js +10 -2
- package/contract/protocol-module.d.ts +84 -9
- package/contract/protocol-module.d.ts.map +1 -1
- package/contract/query-filter-fes.d.ts +18 -0
- package/contract/query-filter-fes.d.ts.map +1 -0
- package/contract/query-filter-fes.js +122 -0
- package/contract/query-filter.d.ts +300 -0
- package/contract/query-filter.d.ts.map +1 -0
- package/contract/query-filter.js +883 -0
- package/contract/schema.d.ts +12 -0
- package/contract/schema.d.ts.map +1 -1
- package/contract/schema.js +34 -0
- package/contract/source-capability-support.d.ts.map +1 -1
- package/contract/source-capability-support.js +15 -3
- package/contract/source.d.ts +45 -25
- package/contract/source.d.ts.map +1 -1
- package/contract/source.js +719 -479
- package/contract/types.d.ts +88 -19
- package/contract/types.d.ts.map +1 -1
- package/contract/types.js +4 -0
- package/contract/widget-source.d.ts.map +1 -1
- package/core/client.d.ts +51 -21
- package/core/client.d.ts.map +1 -1
- package/core/client.js +234 -54
- package/core/error-classifications.d.ts +23 -0
- package/core/error-classifications.d.ts.map +1 -1
- package/core/error-classifications.js +23 -0
- package/core/error-code-registry.d.ts +24 -1
- package/core/error-code-registry.d.ts.map +1 -1
- package/core/error-code-registry.js +23 -0
- package/core/error-envelope.js +2 -0
- package/core/errors.d.ts +2 -2
- package/core/errors.d.ts.map +1 -1
- package/core/errors.js +1 -1
- package/core/geoparquet-sql.d.ts +69 -5
- package/core/geoparquet-sql.d.ts.map +1 -1
- package/core/geoparquet-sql.js +327 -10
- package/core/odata-write-codec.d.ts.map +1 -1
- package/core/odata-write-codec.js +0 -1
- package/core/odata.d.ts +6 -0
- package/core/odata.d.ts.map +1 -1
- package/core/odata.js +6 -1
- package/core/ogc-processes.d.ts +182 -25
- package/core/ogc-processes.d.ts.map +1 -1
- package/core/ogc-processes.js +602 -30
- package/core/process-runner.d.ts +8 -1
- package/core/process-runner.d.ts.map +1 -1
- package/core/process-runner.js +1 -0
- package/core/protocol-transport.d.ts +2 -0
- package/core/protocol-transport.d.ts.map +1 -1
- package/core/stac.d.ts +32 -0
- package/core/stac.d.ts.map +1 -1
- package/core/stac.js +158 -23
- package/core/surfaces.d.ts.map +1 -1
- package/core/surfaces.js +273 -68
- package/core/types.d.ts +138 -11
- package/core/types.d.ts.map +1 -1
- package/core/wfs-axis-order.d.ts +18 -0
- package/core/wfs-axis-order.d.ts.map +1 -0
- package/core/wfs-axis-order.js +108 -0
- package/core/wfs-capabilities.d.ts +65 -24
- package/core/wfs-capabilities.d.ts.map +1 -1
- package/core/wfs-capabilities.js +237 -27
- package/core/wfs-filter.d.ts +26 -3
- package/core/wfs-filter.d.ts.map +1 -1
- package/core/wfs-filter.js +48 -53
- package/core/wfs-protocol-error.d.ts +12 -0
- package/core/wfs-protocol-error.d.ts.map +1 -0
- package/core/wfs-protocol-error.js +13 -0
- package/core/wfs.d.ts +53 -1
- package/core/wfs.d.ts.map +1 -1
- package/core/wfs.js +251 -29
- package/core/wms-feature-info.d.ts +92 -0
- package/core/wms-feature-info.d.ts.map +1 -0
- package/core/wms-feature-info.js +285 -0
- package/core/wms.d.ts +9 -0
- package/core/wms.d.ts.map +1 -1
- package/core/wms.js +17 -5
- package/esri-compat/event-bus.d.ts +20 -0
- package/esri-compat/event-bus.d.ts.map +1 -1
- package/esri-compat/feature-filter.d.ts +46 -1
- package/esri-compat/feature-filter.d.ts.map +1 -1
- package/esri-compat/feature-filter.js +49 -0
- package/esri-compat/geojson-layer.d.ts +4 -2
- package/esri-compat/geojson-layer.d.ts.map +1 -1
- package/esri-compat/geojson-layer.js +4 -2
- package/esri-compat/identity-manager.js +2 -2
- package/esri-compat/imagery-layer.d.ts +2 -1
- package/esri-compat/imagery-layer.d.ts.map +1 -1
- package/esri-compat/imagery-layer.js +2 -1
- package/esri-compat/layer-list.d.ts +8 -1
- package/esri-compat/layer-list.d.ts.map +1 -1
- package/esri-compat/layer-list.js +11 -4
- package/esri-compat/legend.d.ts.map +1 -1
- package/esri-compat/legend.js +1 -1
- package/esri-compat/locator.d.ts +297 -0
- package/esri-compat/locator.d.ts.map +1 -0
- package/esri-compat/locator.js +579 -0
- package/esri-compat/map-image-layer.d.ts.map +1 -1
- package/esri-compat/map-view.d.ts.map +1 -1
- package/esri-compat/map-view.js +1 -1
- package/esri-compat/scene-view.d.ts.map +1 -1
- package/esri-compat/time-slider.d.ts +29 -0
- package/esri-compat/time-slider.d.ts.map +1 -1
- package/esri-compat/time-slider.js +117 -0
- package/esri-compat/wfs-layer.d.ts +2 -1
- package/esri-compat/wfs-layer.d.ts.map +1 -1
- package/esri-compat/wfs-layer.js +2 -1
- package/esri-compat/widget-host.d.ts +42 -6
- package/esri-compat/widget-host.d.ts.map +1 -1
- package/esri-compat/widget-host.js +99 -10
- package/generated-app/projection.d.ts.map +1 -1
- package/generated-app/runtime.d.ts.map +1 -1
- package/interactions/declarative-contract.d.ts +149 -0
- package/interactions/declarative-contract.d.ts.map +1 -0
- package/interactions/declarative-contract.js +293 -0
- package/interactions/declarative.d.ts +198 -0
- package/interactions/declarative.d.ts.map +1 -0
- package/interactions/declarative.js +470 -0
- package/interactions/feature-state.d.ts +7 -0
- package/interactions/feature-state.d.ts.map +1 -1
- package/interactions/feature-state.js +10 -2
- package/map/data-to-map-bridge.d.ts +1 -1
- package/map/data-to-map-bridge.d.ts.map +1 -1
- package/map/data-to-map-bridge.js +1 -2
- package/map/honua-map.d.ts.map +1 -1
- package/map/honua-map.js +1 -1
- package/map/index.d.ts +2 -0
- package/map/index.d.ts.map +1 -1
- package/map/index.js +2 -0
- package/map/maplibre-target.js +1 -1
- package/map/realtime-reconciliation-adapter.d.ts +98 -0
- package/map/realtime-reconciliation-adapter.d.ts.map +1 -0
- package/map/realtime-reconciliation-adapter.js +84 -0
- package/map/temporal-playback.d.ts +25 -0
- package/map/temporal-playback.d.ts.map +1 -1
- package/map/temporal-playback.js +29 -1
- package/package.json +4 -3
- package/query-planner/canonical-filter.d.ts +30 -0
- package/query-planner/canonical-filter.d.ts.map +1 -0
- package/query-planner/canonical-filter.js +30 -0
- package/query-planner/columnar-plan.d.ts +63 -0
- package/query-planner/columnar-plan.d.ts.map +1 -0
- package/query-planner/columnar-plan.js +94 -0
- package/query-planner/diagnostics.d.ts +3 -3
- package/query-planner/diagnostics.d.ts.map +1 -1
- package/query-planner/diagnostics.js +17 -4
- package/query-planner/duckdb.d.ts.map +1 -1
- package/query-planner/duckdb.js +16 -2
- package/query-planner/execution-context.d.ts.map +1 -1
- package/query-planner/execution-context.js +3 -1
- package/query-planner/executor.d.ts.map +1 -1
- package/query-planner/executor.js +7 -1
- package/query-planner/geoservices.d.ts.map +1 -1
- package/query-planner/geoservices.js +24 -5
- package/query-planner/grpc.d.ts.map +1 -1
- package/query-planner/grpc.js +29 -5
- package/query-planner/index.d.ts +20 -5
- package/query-planner/index.d.ts.map +1 -1
- package/query-planner/index.js +16 -3
- package/query-planner/ir.d.ts +6 -1
- package/query-planner/ir.d.ts.map +1 -1
- package/query-planner/ir.js +63 -1
- package/query-planner/odata-protocol-module.d.ts +54 -0
- package/query-planner/odata-protocol-module.d.ts.map +1 -0
- package/query-planner/odata-protocol-module.js +199 -0
- package/query-planner/odata-v1.d.ts +23 -0
- package/query-planner/odata-v1.d.ts.map +1 -0
- package/query-planner/odata-v1.js +202 -0
- package/query-planner/odata.d.ts +0 -3
- package/query-planner/odata.d.ts.map +1 -1
- package/query-planner/odata.js +0 -143
- package/query-planner/ogc-features.d.ts.map +1 -1
- package/query-planner/ogc-features.js +23 -1
- package/query-planner/planner.d.ts +2 -2
- package/query-planner/planner.d.ts.map +1 -1
- package/query-planner/planner.js +146 -27
- package/query-planner/representation.d.ts +59 -0
- package/query-planner/representation.d.ts.map +1 -0
- package/query-planner/representation.js +140 -0
- package/query-planner/types.d.ts +153 -3
- package/query-planner/types.d.ts.map +1 -1
- package/query-planner/wfs-protocol-module.d.ts +57 -0
- package/query-planner/wfs-protocol-module.d.ts.map +1 -0
- package/query-planner/wfs-protocol-module.js +731 -0
- package/query-planner/wfs-v1.d.ts +41 -0
- package/query-planner/wfs-v1.d.ts.map +1 -0
- package/query-planner/wfs-v1.js +366 -0
- package/query-planner/wfs.d.ts +1 -3
- package/query-planner/wfs.d.ts.map +1 -1
- package/query-planner/wfs.js +1 -70
- package/react/honua-map.d.ts +3 -1
- package/react/honua-map.d.ts.map +1 -1
- package/react/honua-map.js +11 -1
- package/react/hooks.d.ts +1 -1
- package/react/hooks.js +1 -1
- package/react/selection.d.ts.map +1 -1
- package/react/selection.js +0 -0
- package/react/use-mounted-source.d.ts +1 -1
- package/react/use-mounted-source.js +1 -1
- package/realtime/checkpoint-store.d.ts +206 -0
- package/realtime/checkpoint-store.d.ts.map +1 -0
- package/realtime/checkpoint-store.js +504 -0
- package/realtime/contract.d.ts +142 -0
- package/realtime/contract.d.ts.map +1 -0
- package/realtime/contract.js +154 -0
- package/realtime/exploration.d.ts +16 -0
- package/realtime/exploration.d.ts.map +1 -0
- package/realtime/exploration.js +32 -0
- package/realtime/honua-server.d.ts +131 -0
- package/realtime/honua-server.d.ts.map +1 -0
- package/realtime/honua-server.js +302 -0
- package/realtime/index.d.ts +39 -0
- package/realtime/index.d.ts.map +1 -0
- package/realtime/index.js +26 -0
- package/realtime/odata-delta.d.ts +114 -0
- package/realtime/odata-delta.d.ts.map +1 -0
- package/realtime/odata-delta.js +483 -0
- package/realtime/projections.d.ts +30 -0
- package/realtime/projections.d.ts.map +1 -0
- package/realtime/projections.js +51 -0
- package/realtime/reconciliation.d.ts +245 -0
- package/realtime/reconciliation.d.ts.map +1 -0
- package/realtime/reconciliation.js +377 -0
- package/realtime/reducer.d.ts +14 -0
- package/realtime/reducer.d.ts.map +1 -0
- package/realtime/reducer.js +351 -0
- package/realtime/resumable-transport.d.ts +111 -0
- package/realtime/resumable-transport.d.ts.map +1 -0
- package/realtime/resumable-transport.js +406 -0
- package/realtime/resumable.d.ts +104 -0
- package/realtime/resumable.d.ts.map +1 -0
- package/realtime/resumable.js +632 -0
- package/realtime/sse.d.ts +23 -0
- package/realtime/sse.d.ts.map +1 -0
- package/realtime/sse.js +153 -0
- package/realtime/store.d.ts +18 -0
- package/realtime/store.d.ts.map +1 -0
- package/realtime/store.js +63 -0
- package/realtime/types.d.ts +190 -0
- package/realtime/types.d.ts.map +1 -0
- package/realtime/types.js +10 -0
- package/realtime/websocket.d.ts +60 -0
- package/realtime/websocket.d.ts.map +1 -0
- package/realtime/websocket.js +157 -0
- package/realtime/wire.d.ts +28 -0
- package/realtime/wire.d.ts.map +1 -0
- package/realtime/wire.js +73 -0
- package/runtime/index.d.ts +6 -2
- package/runtime/index.d.ts.map +1 -1
- package/runtime/index.js +3 -1
- package/runtime/load-package.d.ts +24 -0
- package/runtime/load-package.d.ts.map +1 -1
- package/runtime/load-package.js +45 -1
- package/runtime/maplibre-renderer.d.ts +11 -0
- package/runtime/maplibre-renderer.d.ts.map +1 -1
- package/runtime/maplibre-renderer.js +32 -7
- package/runtime/offline-region-protocol.d.ts +73 -0
- package/runtime/offline-region-protocol.d.ts.map +1 -0
- package/runtime/offline-region-protocol.js +63 -0
- package/runtime/offline-region-style.d.ts +78 -0
- package/runtime/offline-region-style.d.ts.map +1 -0
- package/runtime/offline-region-style.js +147 -0
- package/runtime/pmtiles-protocol.d.ts +7 -8
- package/runtime/pmtiles-protocol.d.ts.map +1 -1
- package/runtime/pmtiles-protocol.js +19 -66
- package/runtime/protocol-registry.d.ts +55 -0
- package/runtime/protocol-registry.d.ts.map +1 -0
- package/runtime/protocol-registry.js +103 -0
- package/runtime/runtime.d.ts +2 -0
- package/runtime/runtime.d.ts.map +1 -1
- package/runtime/runtime.js +6 -1
- package/runtime/style-compose.d.ts.map +1 -1
- package/runtime/style-compose.js +78 -9
- package/studio/index.d.ts +24 -7
- package/studio/index.d.ts.map +1 -1
- package/studio/index.js +21 -7
- package/studio/lifecycle-client.d.ts +164 -0
- package/studio/lifecycle-client.d.ts.map +1 -0
- package/studio/lifecycle-client.js +299 -0
- package/studio/lifecycle-errors.d.ts +91 -0
- package/studio/lifecycle-errors.d.ts.map +1 -0
- package/studio/lifecycle-errors.js +77 -0
- package/studio/lifecycle-types.d.ts +321 -0
- package/studio/lifecycle-types.d.ts.map +1 -0
- package/studio/lifecycle-types.js +22 -0
- package/webmap/convert-label.js +0 -1
- package/webmap/convert-symbol.d.ts.map +1 -1
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renderer-neutral reconciliation of accepted realtime deltas (issue #559).
|
|
3
|
+
*
|
|
4
|
+
* `reducer.ts` already folds `snapshot`/`upsert`/`delete`/`delta` events into
|
|
5
|
+
* one authoritative `RealtimeFeatureState` (`records`/`tombstones`, keyed by
|
|
6
|
+
* {@link realtimeFeatureKey}) — that state is the accepted realtime store this
|
|
7
|
+
* module builds on. This module adds the piece #556/#557 deliberately left
|
|
8
|
+
* open: turning a `(previous, next, trigger)` state transition into an
|
|
9
|
+
* explicit, identity-stable **patch** (create/update/delete) or **rebuild**
|
|
10
|
+
* (replacement snapshot, schema change, or policy-driven queue overflow)
|
|
11
|
+
* decision, plus the derived-state reconciliation that keeps caches,
|
|
12
|
+
* selection, filters, and viewport deterministic across it:
|
|
13
|
+
*
|
|
14
|
+
* - {@link diffRealtimeFeatureState} — pure REQ-001 identity/patch-rebuild
|
|
15
|
+
* classification for one event or explicit reset trigger.
|
|
16
|
+
* - {@link createRealtimeReconciler} — stateful REQ-004 policy: bounds the
|
|
17
|
+
* pending-patch queue and switches `mode` to `"rebuild"` once a single
|
|
18
|
+
* event or the accumulated queue crosses an explicit threshold, so a
|
|
19
|
+
* renderer never has to apply an unbounded patch backlog.
|
|
20
|
+
* - {@link realtimeReconciliationVersion} — the resume-position fields a
|
|
21
|
+
* derived cache should record so it can state exactly which cursor/sequence
|
|
22
|
+
* it reflects (the accepted store in `store.ts`/`reducer.ts` remains the
|
|
23
|
+
* sole authority; nothing here re-derives truth from a cache).
|
|
24
|
+
* - {@link createRealtimeReconciledCache} — a REQ-002 generic, renderer-neutral
|
|
25
|
+
* feature cache driven by reconciliation results; adapt its snapshot into a
|
|
26
|
+
* `Result<T>`-shaped or `HonuaQueryCache`-backed cache as needed.
|
|
27
|
+
* - {@link reconcileRealtimeKeyedState} / {@link reconcileRealtimeViewport} —
|
|
28
|
+
* REQ-003 deterministic preservation of any identity-keyed UI state
|
|
29
|
+
* (selection, an active client-side filter's matched-feature set) and of an
|
|
30
|
+
* opaque viewport value, both with a structured invalidation reason instead
|
|
31
|
+
* of a silent reset.
|
|
32
|
+
*
|
|
33
|
+
* `@honua/sdk-js/map`'s `realtime-reconciliation-adapter.ts` is the only
|
|
34
|
+
* place a `RealtimeReconciliationResult` is projected onto MapLibre
|
|
35
|
+
* (`setFeatureState` for `"patch"`, a caller-supplied rebuild callback for
|
|
36
|
+
* `"rebuild"`) — this module never imports `maplibre-gl` and has no
|
|
37
|
+
* renderer-specific dependency (REQ-005). deck.gl/Cesium adapters and the
|
|
38
|
+
* transport implementations that feed `previous`/`next` state are out of
|
|
39
|
+
* scope for #559.
|
|
40
|
+
*
|
|
41
|
+
* @module
|
|
42
|
+
*/
|
|
43
|
+
import type { FeatureId, SourceId } from "../contract/types.js";
|
|
44
|
+
import { type HonuaErrorOptions, HonuaSdkError } from "../core/error-envelope.js";
|
|
45
|
+
import type { RealtimeFeatureEvent, RealtimeFeatureRecord, RealtimeFeatureState, RealtimeFeatureTombstone } from "./types.js";
|
|
46
|
+
/** Error codes raised by the reconciliation core (and, by reuse, its MapLibre adapter). @experimental */
|
|
47
|
+
export type RealtimeReconciliationErrorCode = "disposed" | "invalid-option";
|
|
48
|
+
/** A stable, machine-readable reconciliation failure. @experimental */
|
|
49
|
+
export declare class HonuaRealtimeReconciliationError extends HonuaSdkError {
|
|
50
|
+
readonly code: RealtimeReconciliationErrorCode;
|
|
51
|
+
readonly detail?: Readonly<Record<string, unknown>> | undefined;
|
|
52
|
+
constructor(code: RealtimeReconciliationErrorCode, message: string, detail?: Readonly<Record<string, unknown>> | undefined, options?: HonuaErrorOptions);
|
|
53
|
+
}
|
|
54
|
+
/** Identity-level change classification. @experimental */
|
|
55
|
+
export type RealtimeReconciliationChangeKind = "create" | "update" | "delete";
|
|
56
|
+
/** One identity-stable change, keyed exactly like the accepted store ({@link realtimeFeatureKey}). @experimental */
|
|
57
|
+
export interface RealtimeReconciliationChange<TFeature = unknown> {
|
|
58
|
+
readonly kind: RealtimeReconciliationChangeKind;
|
|
59
|
+
readonly key: string;
|
|
60
|
+
readonly id: FeatureId;
|
|
61
|
+
readonly sourceId?: SourceId;
|
|
62
|
+
/** Present for `"create"`/`"update"`; the accepted store's record (carries `cursor`/`sequence`/`receivedAt`). */
|
|
63
|
+
readonly record?: RealtimeFeatureRecord<TFeature>;
|
|
64
|
+
/** Present for `"delete"`; the accepted store's tombstone, when the reducer still retains it. */
|
|
65
|
+
readonly tombstone?: RealtimeFeatureTombstone;
|
|
66
|
+
}
|
|
67
|
+
/** Why a reconciliation declared a full reset instead of an incremental patch. @experimental */
|
|
68
|
+
export type RealtimeReconciliationResetReasonCode = "replacement-snapshot" | "schema-changed" | "source-changed" | "authorization-scope-changed" | "manual";
|
|
69
|
+
/**
|
|
70
|
+
* What drove one `(previous, next)` transition: an accepted `RealtimeFeatureEvent`
|
|
71
|
+
* (the common case — `snapshot`/`upsert`/`delete`/`delta`/`heartbeat`/`status`/`error`),
|
|
72
|
+
* or an explicit reset the caller derived from outside the event stream (a
|
|
73
|
+
* `schema-version-changed` / `source-version-changed` / `authorization-scope-changed`
|
|
74
|
+
* checkpoint incompatibility from `resumable.ts`'s `evaluateRealtimeCheckpoint`, or a
|
|
75
|
+
* caller-initiated manual reset). @experimental
|
|
76
|
+
*/
|
|
77
|
+
export type RealtimeReconciliationTrigger<TFeature = unknown> = {
|
|
78
|
+
readonly kind: "event";
|
|
79
|
+
readonly event: RealtimeFeatureEvent<TFeature>;
|
|
80
|
+
} | {
|
|
81
|
+
readonly kind: "reset";
|
|
82
|
+
readonly reason: RealtimeReconciliationResetReasonCode;
|
|
83
|
+
readonly detail?: string;
|
|
84
|
+
};
|
|
85
|
+
/** Pure REQ-001 output: the identity changes for one transition, and whether it was a reset. @experimental */
|
|
86
|
+
export interface RealtimeReconciliationDiff<TFeature = unknown> {
|
|
87
|
+
readonly changes: readonly RealtimeReconciliationChange<TFeature>[];
|
|
88
|
+
readonly reset: boolean;
|
|
89
|
+
readonly resetReason?: RealtimeReconciliationResetReasonCode;
|
|
90
|
+
readonly resetDetail?: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Classify one `(previous, next)` accepted-store transition into identity-stable
|
|
94
|
+
* create/update/delete changes, or an explicit reset (replacement snapshot,
|
|
95
|
+
* schema change, source-version change, authorization-scope change, or a
|
|
96
|
+
* caller-initiated manual reset). Pure and side-effect free — `next` must
|
|
97
|
+
* already be the reducer's output for `trigger` (`reduceRealtimeFeatureState`
|
|
98
|
+
* when `trigger.kind === "event"`); this function never re-derives store state.
|
|
99
|
+
*
|
|
100
|
+
* @experimental
|
|
101
|
+
*/
|
|
102
|
+
export declare function diffRealtimeFeatureState<TFeature>(previous: RealtimeFeatureState<TFeature>, next: RealtimeFeatureState<TFeature>, trigger: RealtimeReconciliationTrigger<TFeature>): RealtimeReconciliationDiff<TFeature>;
|
|
103
|
+
/** The resume-position fields a derived cache should record alongside its data. @experimental */
|
|
104
|
+
export interface RealtimeReconciliationVersion {
|
|
105
|
+
readonly cursor?: string;
|
|
106
|
+
readonly watermark?: string;
|
|
107
|
+
readonly timestamp?: string;
|
|
108
|
+
readonly sequence?: number;
|
|
109
|
+
readonly deltaToken?: string;
|
|
110
|
+
}
|
|
111
|
+
/** Project the accepted store's current resume position — what a derived cache built from `state` reflects. @experimental */
|
|
112
|
+
export declare function realtimeReconciliationVersion<TFeature>(state: RealtimeFeatureState<TFeature>): RealtimeReconciliationVersion;
|
|
113
|
+
/** `"patch"` applies `changes` incrementally; `"rebuild"` requires a full re-materialization. @experimental */
|
|
114
|
+
export type RealtimeReconciliationMode = "patch" | "rebuild";
|
|
115
|
+
/** Why {@link RealtimeReconciliationResult.mode} is `"rebuild"` even when `reset` is `false`. @experimental */
|
|
116
|
+
export type RealtimeReconciliationRebuildReason = "reset" | "event-exceeds-patch-bound" | "queue-threshold-exceeded";
|
|
117
|
+
/** Result of one {@link RealtimeReconciler.reconcile} call. @experimental */
|
|
118
|
+
export interface RealtimeReconciliationResult<TFeature = unknown> {
|
|
119
|
+
readonly mode: RealtimeReconciliationMode;
|
|
120
|
+
readonly rebuildReason?: RealtimeReconciliationRebuildReason;
|
|
121
|
+
/**
|
|
122
|
+
* For `"patch"`, the transition's incremental changes. For `"rebuild"`,
|
|
123
|
+
* always the full accepted store as `"create"` changes (plus the triggering
|
|
124
|
+
* event's `"delete"` changes on a non-reset rebuild), so a derived cache can
|
|
125
|
+
* re-materialize wholesale from the result alone without dropping live
|
|
126
|
+
* features that were not part of the triggering event.
|
|
127
|
+
*/
|
|
128
|
+
readonly changes: readonly RealtimeReconciliationChange<TFeature>[];
|
|
129
|
+
readonly version: RealtimeReconciliationVersion;
|
|
130
|
+
readonly reset: boolean;
|
|
131
|
+
readonly resetReason?: RealtimeReconciliationResetReasonCode;
|
|
132
|
+
/** Patches accumulated since the last rebuild, including this result. Always `0` immediately after a rebuild. @experimental */
|
|
133
|
+
readonly pendingPatchCount: number;
|
|
134
|
+
}
|
|
135
|
+
/** Options for {@link createRealtimeReconciler}. @experimental */
|
|
136
|
+
export interface RealtimeReconcilerOptions {
|
|
137
|
+
/** A single event/trigger producing more identity changes than this forces an immediate rebuild. @default 500 */
|
|
138
|
+
readonly maxChangesPerEvent?: number;
|
|
139
|
+
/** Cumulative pending patches (since the last rebuild) that force the next reconciliation to rebuild. @default 2000 */
|
|
140
|
+
readonly rebuildThreshold?: number;
|
|
141
|
+
}
|
|
142
|
+
/** Stateful REQ-004 policy wrapper around {@link diffRealtimeFeatureState}. @experimental */
|
|
143
|
+
export interface RealtimeReconciler<TFeature = unknown> {
|
|
144
|
+
readonly disposed: boolean;
|
|
145
|
+
/** Patches accumulated since the last rebuild. */
|
|
146
|
+
readonly pendingPatchCount: number;
|
|
147
|
+
/**
|
|
148
|
+
* Reconcile one accepted transition. Throws {@link HonuaRealtimeReconciliationError}
|
|
149
|
+
* (`"disposed"`) once {@link RealtimeReconciler.dispose} has been called —
|
|
150
|
+
* a disposed reconciler must never hand a caller another patch.
|
|
151
|
+
*/
|
|
152
|
+
reconcile(previous: RealtimeFeatureState<TFeature>, next: RealtimeFeatureState<TFeature>, trigger: RealtimeReconciliationTrigger<TFeature>): RealtimeReconciliationResult<TFeature>;
|
|
153
|
+
/** Stop accepting reconciliations. Idempotent. */
|
|
154
|
+
dispose(): void;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Create a bounded, renderer-neutral reconciliation policy: identity changes
|
|
158
|
+
* classify through {@link diffRealtimeFeatureState}; a single oversized event,
|
|
159
|
+
* or an accumulated pending-patch count over `rebuildThreshold`, switches
|
|
160
|
+
* `mode` to `"rebuild"` by explicit policy rather than growing an unbounded
|
|
161
|
+
* patch queue.
|
|
162
|
+
*
|
|
163
|
+
* @experimental
|
|
164
|
+
*/
|
|
165
|
+
export declare function createRealtimeReconciler<TFeature = unknown>(options?: RealtimeReconcilerOptions): RealtimeReconciler<TFeature>;
|
|
166
|
+
/** Snapshot returned by {@link RealtimeReconciledCache.snapshot} / `.apply`. @experimental */
|
|
167
|
+
export interface RealtimeReconciledCacheSnapshot<TFeature = unknown> {
|
|
168
|
+
/** Insertion-ordered (creation order; unaffected by updates) live features. */
|
|
169
|
+
readonly features: readonly TFeature[];
|
|
170
|
+
/** The cursor/sequence this snapshot reflects — see {@link realtimeReconciliationVersion}. */
|
|
171
|
+
readonly version: RealtimeReconciliationVersion;
|
|
172
|
+
}
|
|
173
|
+
/** A renderer-neutral, identity-keyed feature cache kept in sync by reconciliation results. @experimental */
|
|
174
|
+
export interface RealtimeReconciledCache<TFeature = unknown> {
|
|
175
|
+
readonly disposed: boolean;
|
|
176
|
+
snapshot(): RealtimeReconciledCacheSnapshot<TFeature>;
|
|
177
|
+
/**
|
|
178
|
+
* Apply one {@link RealtimeReconciliationResult}: `"rebuild"` replaces the
|
|
179
|
+
* cache wholesale (creates only — the caller's rebuild path already
|
|
180
|
+
* re-materializes from the authoritative store); `"patch"` applies each
|
|
181
|
+
* change in place. Throws {@link HonuaRealtimeReconciliationError}
|
|
182
|
+
* (`"disposed"`) once disposed.
|
|
183
|
+
*/
|
|
184
|
+
apply(result: RealtimeReconciliationResult<TFeature>): RealtimeReconciledCacheSnapshot<TFeature>;
|
|
185
|
+
/** Discard cached data. Idempotent. */
|
|
186
|
+
dispose(): void;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Create a generic, renderer-neutral cache of live features keyed exactly
|
|
190
|
+
* like the accepted realtime store. Adapt {@link RealtimeReconciledCache.snapshot}
|
|
191
|
+
* into a `Result<T>`-shaped or `HonuaQueryCache`-backed cache entry as needed —
|
|
192
|
+
* this module intentionally does not import either.
|
|
193
|
+
*
|
|
194
|
+
* @experimental
|
|
195
|
+
*/
|
|
196
|
+
export declare function createRealtimeReconciledCache<TFeature = unknown>(): RealtimeReconciledCache<TFeature>;
|
|
197
|
+
/** Why an identity-keyed entry (selection, active filter membership) was invalidated instead of preserved. @experimental */
|
|
198
|
+
export type RealtimeReconciliationInvalidationReason = "feature-deleted" | "reset" | "schema-changed";
|
|
199
|
+
/** One structured invalidation of a previously identity-keyed entry. @experimental */
|
|
200
|
+
export interface RealtimeReconciliationInvalidation {
|
|
201
|
+
readonly key: string;
|
|
202
|
+
readonly reason: RealtimeReconciliationInvalidationReason;
|
|
203
|
+
}
|
|
204
|
+
/** Result of {@link reconcileRealtimeKeyedState}. @experimental */
|
|
205
|
+
export interface RealtimeKeyedStateReconciliation {
|
|
206
|
+
readonly next: ReadonlySet<string>;
|
|
207
|
+
readonly invalidations: readonly RealtimeReconciliationInvalidation[];
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Deterministically preserve or invalidate an identity-keyed set of feature
|
|
211
|
+
* keys (a selection, or the matched-key set of an active client-side filter)
|
|
212
|
+
* across one reconciliation result:
|
|
213
|
+
*
|
|
214
|
+
* - `result.reset` (replacement snapshot, schema/source/scope change, or
|
|
215
|
+
* manual reset): every key is invalidated with reason `"reset"` (or
|
|
216
|
+
* `"schema-changed"` when that was the reset reason) and `next` is empty —
|
|
217
|
+
* a rebuild replaces identity wholesale, so no prior key is safe to assume
|
|
218
|
+
* still exists.
|
|
219
|
+
* - Otherwise: a key backed by a feature the delta deleted is invalidated
|
|
220
|
+
* with reason `"feature-deleted"`; every other key is preserved unchanged.
|
|
221
|
+
*
|
|
222
|
+
* Reused for both selection and filter membership — both are "a set of
|
|
223
|
+
* feature keys that must stay valid or be explicitly dropped."
|
|
224
|
+
*
|
|
225
|
+
* @experimental
|
|
226
|
+
*/
|
|
227
|
+
export declare function reconcileRealtimeKeyedState(keys: ReadonlySet<string>, result: Pick<RealtimeReconciliationResult<unknown>, "changes" | "reset" | "resetReason">): RealtimeKeyedStateReconciliation;
|
|
228
|
+
/** Result of {@link reconcileRealtimeViewport}. @experimental */
|
|
229
|
+
export interface RealtimeViewportReconciliation<TViewport> {
|
|
230
|
+
/** Always the input `viewport`; this module never mutates or resets camera state itself. */
|
|
231
|
+
readonly viewport: TViewport;
|
|
232
|
+
readonly invalidated: boolean;
|
|
233
|
+
readonly reason?: RealtimeReconciliationInvalidationReason;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Preserve an opaque viewport value across a reconciliation result. The
|
|
237
|
+
* viewport itself is always passed through unchanged (this module never
|
|
238
|
+
* moves a camera); `invalidated` is `true` only on `result.reset`, so a
|
|
239
|
+
* caller can decide whether to refit bounds — deterministic, and never a
|
|
240
|
+
* silent no-op on a schema/replacement-snapshot reset.
|
|
241
|
+
*
|
|
242
|
+
* @experimental
|
|
243
|
+
*/
|
|
244
|
+
export declare function reconcileRealtimeViewport<TViewport>(viewport: TViewport, result: Pick<RealtimeReconciliationResult<unknown>, "reset" | "resetReason">): RealtimeViewportReconciliation<TViewport>;
|
|
245
|
+
//# sourceMappingURL=reconciliation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconciliation.d.ts","sourceRoot":"","sources":["../../../src/realtime/reconciliation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,KAAK,iBAAiB,EAAE,aAAa,EAA0B,MAAM,2BAA2B,CAAC;AAE1G,OAAO,KAAK,EAEV,oBAAoB,EAEpB,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,YAAY,CAAC;AAIpB,yGAAyG;AACzG,MAAM,MAAM,+BAA+B,GAAG,UAAU,GAAG,gBAAgB,CAAC;AAE5E,uEAAuE;AACvE,qBAAa,gCAAiC,SAAQ,aAAa;aAE/C,IAAI,EAAE,+BAA+B;aAErC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAF1C,IAAI,EAAE,+BAA+B,EACrD,OAAO,EAAE,MAAM,EACC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,YAAA,EAC1D,OAAO,GAAE,iBAAsB;CAQlC;AASD,0DAA0D;AAC1D,MAAM,MAAM,gCAAgC,GAAG,QAAQ,GA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 -0,0 +1,377 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renderer-neutral reconciliation of accepted realtime deltas (issue #559).
|
|
3
|
+
*
|
|
4
|
+
* `reducer.ts` already folds `snapshot`/`upsert`/`delete`/`delta` events into
|
|
5
|
+
* one authoritative `RealtimeFeatureState` (`records`/`tombstones`, keyed by
|
|
6
|
+
* {@link realtimeFeatureKey}) — that state is the accepted realtime store this
|
|
7
|
+
* module builds on. This module adds the piece #556/#557 deliberately left
|
|
8
|
+
* open: turning a `(previous, next, trigger)` state transition into an
|
|
9
|
+
* explicit, identity-stable **patch** (create/update/delete) or **rebuild**
|
|
10
|
+
* (replacement snapshot, schema change, or policy-driven queue overflow)
|
|
11
|
+
* decision, plus the derived-state reconciliation that keeps caches,
|
|
12
|
+
* selection, filters, and viewport deterministic across it:
|
|
13
|
+
*
|
|
14
|
+
* - {@link diffRealtimeFeatureState} — pure REQ-001 identity/patch-rebuild
|
|
15
|
+
* classification for one event or explicit reset trigger.
|
|
16
|
+
* - {@link createRealtimeReconciler} — stateful REQ-004 policy: bounds the
|
|
17
|
+
* pending-patch queue and switches `mode` to `"rebuild"` once a single
|
|
18
|
+
* event or the accumulated queue crosses an explicit threshold, so a
|
|
19
|
+
* renderer never has to apply an unbounded patch backlog.
|
|
20
|
+
* - {@link realtimeReconciliationVersion} — the resume-position fields a
|
|
21
|
+
* derived cache should record so it can state exactly which cursor/sequence
|
|
22
|
+
* it reflects (the accepted store in `store.ts`/`reducer.ts` remains the
|
|
23
|
+
* sole authority; nothing here re-derives truth from a cache).
|
|
24
|
+
* - {@link createRealtimeReconciledCache} — a REQ-002 generic, renderer-neutral
|
|
25
|
+
* feature cache driven by reconciliation results; adapt its snapshot into a
|
|
26
|
+
* `Result<T>`-shaped or `HonuaQueryCache`-backed cache as needed.
|
|
27
|
+
* - {@link reconcileRealtimeKeyedState} / {@link reconcileRealtimeViewport} —
|
|
28
|
+
* REQ-003 deterministic preservation of any identity-keyed UI state
|
|
29
|
+
* (selection, an active client-side filter's matched-feature set) and of an
|
|
30
|
+
* opaque viewport value, both with a structured invalidation reason instead
|
|
31
|
+
* of a silent reset.
|
|
32
|
+
*
|
|
33
|
+
* `@honua/sdk-js/map`'s `realtime-reconciliation-adapter.ts` is the only
|
|
34
|
+
* place a `RealtimeReconciliationResult` is projected onto MapLibre
|
|
35
|
+
* (`setFeatureState` for `"patch"`, a caller-supplied rebuild callback for
|
|
36
|
+
* `"rebuild"`) — this module never imports `maplibre-gl` and has no
|
|
37
|
+
* renderer-specific dependency (REQ-005). deck.gl/Cesium adapters and the
|
|
38
|
+
* transport implementations that feed `previous`/`next` state are out of
|
|
39
|
+
* scope for #559.
|
|
40
|
+
*
|
|
41
|
+
* @module
|
|
42
|
+
*/
|
|
43
|
+
import { HonuaSdkError, mergeHonuaErrorContext } from "../core/error-envelope.js";
|
|
44
|
+
import { realtimeFeatureKey } from "./reducer.js";
|
|
45
|
+
/** A stable, machine-readable reconciliation failure. @experimental */
|
|
46
|
+
export class HonuaRealtimeReconciliationError extends HonuaSdkError {
|
|
47
|
+
code;
|
|
48
|
+
detail;
|
|
49
|
+
constructor(code, message, detail, options = {}) {
|
|
50
|
+
super(REALTIME_RECONCILIATION_ERROR_CODES[code], message, {
|
|
51
|
+
...options,
|
|
52
|
+
context: mergeHonuaErrorContext(detail, options.context),
|
|
53
|
+
});
|
|
54
|
+
this.code = code;
|
|
55
|
+
this.detail = detail;
|
|
56
|
+
this.name = "HonuaRealtimeReconciliationError";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const REALTIME_RECONCILIATION_ERROR_CODES = {
|
|
60
|
+
disposed: "realtime.reconciliation.disposed",
|
|
61
|
+
"invalid-option": "realtime.reconciliation.invalid-option",
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Classify one `(previous, next)` accepted-store transition into identity-stable
|
|
65
|
+
* create/update/delete changes, or an explicit reset (replacement snapshot,
|
|
66
|
+
* schema change, source-version change, authorization-scope change, or a
|
|
67
|
+
* caller-initiated manual reset). Pure and side-effect free — `next` must
|
|
68
|
+
* already be the reducer's output for `trigger` (`reduceRealtimeFeatureState`
|
|
69
|
+
* when `trigger.kind === "event"`); this function never re-derives store state.
|
|
70
|
+
*
|
|
71
|
+
* @experimental
|
|
72
|
+
*/
|
|
73
|
+
export function diffRealtimeFeatureState(previous, next, trigger) {
|
|
74
|
+
if (trigger.kind === "reset") {
|
|
75
|
+
return Object.freeze({
|
|
76
|
+
changes: recordsAsCreateChanges(next),
|
|
77
|
+
reset: true,
|
|
78
|
+
resetReason: trigger.reason,
|
|
79
|
+
...(trigger.detail !== undefined ? { resetDetail: trigger.detail } : {}),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const event = trigger.event;
|
|
83
|
+
switch (event.type) {
|
|
84
|
+
case "snapshot": {
|
|
85
|
+
if (event.replace ?? true) {
|
|
86
|
+
return Object.freeze({
|
|
87
|
+
changes: recordsAsCreateChanges(next),
|
|
88
|
+
reset: true,
|
|
89
|
+
resetReason: "replacement-snapshot",
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return Object.freeze({
|
|
93
|
+
changes: event.features.map((feature) => classifyUpsert(previous, next, feature)),
|
|
94
|
+
reset: false,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
case "upsert":
|
|
98
|
+
return Object.freeze({ changes: [classifyUpsert(previous, next, event.feature)], reset: false });
|
|
99
|
+
case "delete":
|
|
100
|
+
return Object.freeze({ changes: [classifyDelete(next, event)], reset: false });
|
|
101
|
+
case "delta":
|
|
102
|
+
return Object.freeze({
|
|
103
|
+
changes: [
|
|
104
|
+
...(event.upserts ?? []).map((feature) => classifyUpsert(previous, next, feature)),
|
|
105
|
+
...(event.deletes ?? []).map((tombstone) => classifyDelete(next, tombstone)),
|
|
106
|
+
],
|
|
107
|
+
reset: false,
|
|
108
|
+
});
|
|
109
|
+
case "heartbeat":
|
|
110
|
+
case "status":
|
|
111
|
+
case "error":
|
|
112
|
+
return Object.freeze({ changes: [], reset: false });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function classifyUpsert(previous, next, patch) {
|
|
116
|
+
const key = realtimeFeatureKey(patch.sourceId, patch.id);
|
|
117
|
+
const existed = Boolean(previous.records[key]);
|
|
118
|
+
const record = next.records[key];
|
|
119
|
+
return Object.freeze({
|
|
120
|
+
kind: existed ? "update" : "create",
|
|
121
|
+
key,
|
|
122
|
+
id: patch.id,
|
|
123
|
+
...(patch.sourceId !== undefined ? { sourceId: patch.sourceId } : {}),
|
|
124
|
+
...(record ? { record } : {}),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function classifyDelete(next, input) {
|
|
128
|
+
const key = realtimeFeatureKey(input.sourceId, input.id);
|
|
129
|
+
const tombstone = next.tombstones[key];
|
|
130
|
+
return Object.freeze({
|
|
131
|
+
kind: "delete",
|
|
132
|
+
key,
|
|
133
|
+
id: input.id,
|
|
134
|
+
...(input.sourceId !== undefined ? { sourceId: input.sourceId } : {}),
|
|
135
|
+
...(tombstone ? { tombstone } : {}),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function recordsAsCreateChanges(next) {
|
|
139
|
+
return Object.freeze(Object.values(next.records).map((record) => Object.freeze({
|
|
140
|
+
kind: "create",
|
|
141
|
+
key: record.key,
|
|
142
|
+
id: record.id,
|
|
143
|
+
...(record.sourceId !== undefined ? { sourceId: record.sourceId } : {}),
|
|
144
|
+
record,
|
|
145
|
+
})));
|
|
146
|
+
}
|
|
147
|
+
/** Project the accepted store's current resume position — what a derived cache built from `state` reflects. @experimental */
|
|
148
|
+
export function realtimeReconciliationVersion(state) {
|
|
149
|
+
return Object.freeze({
|
|
150
|
+
...(state.cursor !== undefined ? { cursor: state.cursor } : {}),
|
|
151
|
+
...(state.watermark !== undefined ? { watermark: state.watermark } : {}),
|
|
152
|
+
...(state.timestamp !== undefined ? { timestamp: state.timestamp } : {}),
|
|
153
|
+
...(state.lastSequence !== undefined ? { sequence: state.lastSequence } : {}),
|
|
154
|
+
...(state.deltaToken !== undefined ? { deltaToken: state.deltaToken } : {}),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Create a bounded, renderer-neutral reconciliation policy: identity changes
|
|
159
|
+
* classify through {@link diffRealtimeFeatureState}; a single oversized event,
|
|
160
|
+
* or an accumulated pending-patch count over `rebuildThreshold`, switches
|
|
161
|
+
* `mode` to `"rebuild"` by explicit policy rather than growing an unbounded
|
|
162
|
+
* patch queue.
|
|
163
|
+
*
|
|
164
|
+
* @experimental
|
|
165
|
+
*/
|
|
166
|
+
export function createRealtimeReconciler(options = {}) {
|
|
167
|
+
const maxChangesPerEvent = positiveInteger(options.maxChangesPerEvent, 500, "maxChangesPerEvent");
|
|
168
|
+
const rebuildThreshold = positiveInteger(options.rebuildThreshold, 2000, "rebuildThreshold");
|
|
169
|
+
let pending = 0;
|
|
170
|
+
let disposed = false;
|
|
171
|
+
return {
|
|
172
|
+
get disposed() {
|
|
173
|
+
return disposed;
|
|
174
|
+
},
|
|
175
|
+
get pendingPatchCount() {
|
|
176
|
+
return pending;
|
|
177
|
+
},
|
|
178
|
+
reconcile(previous, next, trigger) {
|
|
179
|
+
if (disposed) {
|
|
180
|
+
throw new HonuaRealtimeReconciliationError("disposed", "Cannot reconcile with a disposed realtime reconciler.");
|
|
181
|
+
}
|
|
182
|
+
const diff = diffRealtimeFeatureState(previous, next, trigger);
|
|
183
|
+
const version = realtimeReconciliationVersion(next);
|
|
184
|
+
if (diff.reset) {
|
|
185
|
+
pending = 0;
|
|
186
|
+
return freezeResult({
|
|
187
|
+
mode: "rebuild",
|
|
188
|
+
rebuildReason: "reset",
|
|
189
|
+
changes: diff.changes,
|
|
190
|
+
version,
|
|
191
|
+
reset: true,
|
|
192
|
+
...(diff.resetReason !== undefined ? { resetReason: diff.resetReason } : {}),
|
|
193
|
+
pendingPatchCount: 0,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
if (diff.changes.length > maxChangesPerEvent) {
|
|
197
|
+
pending = 0;
|
|
198
|
+
return freezeResult({
|
|
199
|
+
mode: "rebuild",
|
|
200
|
+
rebuildReason: "event-exceeds-patch-bound",
|
|
201
|
+
changes: nonResetRebuildChanges(next, diff.changes),
|
|
202
|
+
version,
|
|
203
|
+
reset: false,
|
|
204
|
+
pendingPatchCount: 0,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
pending += diff.changes.length;
|
|
208
|
+
if (pending > rebuildThreshold) {
|
|
209
|
+
pending = 0;
|
|
210
|
+
return freezeResult({
|
|
211
|
+
mode: "rebuild",
|
|
212
|
+
rebuildReason: "queue-threshold-exceeded",
|
|
213
|
+
changes: nonResetRebuildChanges(next, diff.changes),
|
|
214
|
+
version,
|
|
215
|
+
reset: false,
|
|
216
|
+
pendingPatchCount: 0,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
return freezeResult({
|
|
220
|
+
mode: "patch",
|
|
221
|
+
changes: diff.changes,
|
|
222
|
+
version,
|
|
223
|
+
reset: false,
|
|
224
|
+
pendingPatchCount: pending,
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
dispose() {
|
|
228
|
+
disposed = true;
|
|
229
|
+
pending = 0;
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
// A rebuild consumer (createRealtimeReconciledCache.apply, a mounted source's
|
|
234
|
+
// re-materialization path) treats `changes` as the complete replacement state,
|
|
235
|
+
// so a non-reset rebuild must carry the full accepted store — the triggering
|
|
236
|
+
// event's diff alone would drop every live feature outside that one event. The
|
|
237
|
+
// event's deletes ride along so identity-keyed state (selection, filter
|
|
238
|
+
// membership) can still invalidate exactly what this transition removed.
|
|
239
|
+
function nonResetRebuildChanges(next, eventChanges) {
|
|
240
|
+
return Object.freeze([...recordsAsCreateChanges(next), ...eventChanges.filter((change) => change.kind === "delete")]);
|
|
241
|
+
}
|
|
242
|
+
function freezeResult(result) {
|
|
243
|
+
return Object.freeze({ ...result, changes: Object.freeze([...result.changes]) });
|
|
244
|
+
}
|
|
245
|
+
function positiveInteger(value, fallback, name) {
|
|
246
|
+
if (value === undefined)
|
|
247
|
+
return fallback;
|
|
248
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
249
|
+
throw new HonuaRealtimeReconciliationError("invalid-option", `${name} must be a positive safe integer.`, {
|
|
250
|
+
[name]: value,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
return value;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Create a generic, renderer-neutral cache of live features keyed exactly
|
|
257
|
+
* like the accepted realtime store. Adapt {@link RealtimeReconciledCache.snapshot}
|
|
258
|
+
* into a `Result<T>`-shaped or `HonuaQueryCache`-backed cache entry as needed —
|
|
259
|
+
* this module intentionally does not import either.
|
|
260
|
+
*
|
|
261
|
+
* @experimental
|
|
262
|
+
*/
|
|
263
|
+
export function createRealtimeReconciledCache() {
|
|
264
|
+
let order = [];
|
|
265
|
+
let byKey = new Map();
|
|
266
|
+
let version = Object.freeze({});
|
|
267
|
+
let disposed = false;
|
|
268
|
+
const snapshotOf = () => Object.freeze({
|
|
269
|
+
features: Object.freeze(order.map((key) => byKey.get(key))),
|
|
270
|
+
version,
|
|
271
|
+
});
|
|
272
|
+
return {
|
|
273
|
+
get disposed() {
|
|
274
|
+
return disposed;
|
|
275
|
+
},
|
|
276
|
+
snapshot: snapshotOf,
|
|
277
|
+
apply(result) {
|
|
278
|
+
if (disposed) {
|
|
279
|
+
throw new HonuaRealtimeReconciliationError("disposed", "Cannot apply to a disposed realtime reconciled cache.");
|
|
280
|
+
}
|
|
281
|
+
if (result.mode === "rebuild") {
|
|
282
|
+
const nextOrder = [];
|
|
283
|
+
const nextByKey = new Map();
|
|
284
|
+
for (const change of result.changes) {
|
|
285
|
+
if (change.kind === "delete" || !change.record)
|
|
286
|
+
continue;
|
|
287
|
+
nextOrder.push(change.key);
|
|
288
|
+
nextByKey.set(change.key, change.record.feature);
|
|
289
|
+
}
|
|
290
|
+
order = nextOrder;
|
|
291
|
+
byKey = nextByKey;
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
for (const change of result.changes) {
|
|
295
|
+
if (change.kind === "delete") {
|
|
296
|
+
if (byKey.delete(change.key))
|
|
297
|
+
order = order.filter((key) => key !== change.key);
|
|
298
|
+
}
|
|
299
|
+
else if (change.record) {
|
|
300
|
+
if (!byKey.has(change.key))
|
|
301
|
+
order.push(change.key);
|
|
302
|
+
byKey.set(change.key, change.record.feature);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
version = result.version;
|
|
307
|
+
return snapshotOf();
|
|
308
|
+
},
|
|
309
|
+
dispose() {
|
|
310
|
+
disposed = true;
|
|
311
|
+
order = [];
|
|
312
|
+
byKey = new Map();
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Deterministically preserve or invalidate an identity-keyed set of feature
|
|
318
|
+
* keys (a selection, or the matched-key set of an active client-side filter)
|
|
319
|
+
* across one reconciliation result:
|
|
320
|
+
*
|
|
321
|
+
* - `result.reset` (replacement snapshot, schema/source/scope change, or
|
|
322
|
+
* manual reset): every key is invalidated with reason `"reset"` (or
|
|
323
|
+
* `"schema-changed"` when that was the reset reason) and `next` is empty —
|
|
324
|
+
* a rebuild replaces identity wholesale, so no prior key is safe to assume
|
|
325
|
+
* still exists.
|
|
326
|
+
* - Otherwise: a key backed by a feature the delta deleted is invalidated
|
|
327
|
+
* with reason `"feature-deleted"`; every other key is preserved unchanged.
|
|
328
|
+
*
|
|
329
|
+
* Reused for both selection and filter membership — both are "a set of
|
|
330
|
+
* feature keys that must stay valid or be explicitly dropped."
|
|
331
|
+
*
|
|
332
|
+
* @experimental
|
|
333
|
+
*/
|
|
334
|
+
export function reconcileRealtimeKeyedState(keys, result) {
|
|
335
|
+
if (result.reset) {
|
|
336
|
+
const reason = result.resetReason === "schema-changed" ? "schema-changed" : "reset";
|
|
337
|
+
return Object.freeze({
|
|
338
|
+
next: Object.freeze(new Set()),
|
|
339
|
+
invalidations: Object.freeze([...keys].map((key) => Object.freeze({ key, reason }))),
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
const deletedKeys = new Set();
|
|
343
|
+
for (const change of result.changes) {
|
|
344
|
+
if (change.kind === "delete")
|
|
345
|
+
deletedKeys.add(change.key);
|
|
346
|
+
}
|
|
347
|
+
if (deletedKeys.size === 0) {
|
|
348
|
+
return Object.freeze({ next: keys, invalidations: Object.freeze([]) });
|
|
349
|
+
}
|
|
350
|
+
const next = new Set();
|
|
351
|
+
const invalidations = [];
|
|
352
|
+
for (const key of keys) {
|
|
353
|
+
if (deletedKeys.has(key))
|
|
354
|
+
invalidations.push(Object.freeze({ key, reason: "feature-deleted" }));
|
|
355
|
+
else
|
|
356
|
+
next.add(key);
|
|
357
|
+
}
|
|
358
|
+
return Object.freeze({ next: Object.freeze(next), invalidations: Object.freeze(invalidations) });
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Preserve an opaque viewport value across a reconciliation result. The
|
|
362
|
+
* viewport itself is always passed through unchanged (this module never
|
|
363
|
+
* moves a camera); `invalidated` is `true` only on `result.reset`, so a
|
|
364
|
+
* caller can decide whether to refit bounds — deterministic, and never a
|
|
365
|
+
* silent no-op on a schema/replacement-snapshot reset.
|
|
366
|
+
*
|
|
367
|
+
* @experimental
|
|
368
|
+
*/
|
|
369
|
+
export function reconcileRealtimeViewport(viewport, result) {
|
|
370
|
+
if (!result.reset)
|
|
371
|
+
return Object.freeze({ viewport, invalidated: false });
|
|
372
|
+
return Object.freeze({
|
|
373
|
+
viewport,
|
|
374
|
+
invalidated: true,
|
|
375
|
+
reason: result.resetReason === "schema-changed" ? "schema-changed" : "reset",
|
|
376
|
+
});
|
|
377
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure reducer helpers for realtime feature state.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { FeatureId, SourceId } from "../contract/types.js";
|
|
7
|
+
import type { RealtimeFeatureEvent, RealtimeFeatureState, RealtimeReducerOptions, RealtimeResumeCheckpoint, RealtimeStalenessOptions, RealtimeSubscriptionIdentity } from "./types.js";
|
|
8
|
+
export declare function emptyRealtimeFeatureState<TFeature = unknown>(): RealtimeFeatureState<TFeature>;
|
|
9
|
+
export declare function realtimeFeatureKey(sourceId: SourceId | undefined, id: FeatureId): string;
|
|
10
|
+
export declare function realtimeSubscriptionKey(request: RealtimeSubscriptionIdentity): string;
|
|
11
|
+
export declare function realtimeResumeCheckpoint<TFeature>(state: RealtimeFeatureState<TFeature>): RealtimeResumeCheckpoint | undefined;
|
|
12
|
+
export declare function reduceRealtimeFeatureState<TFeature>(state: RealtimeFeatureState<TFeature>, event: RealtimeFeatureEvent<TFeature>, options?: RealtimeReducerOptions): RealtimeFeatureState<TFeature>;
|
|
13
|
+
export declare function reconcileRealtimeStaleness<TFeature>(state: RealtimeFeatureState<TFeature>, options: RealtimeStalenessOptions): RealtimeFeatureState<TFeature>;
|
|
14
|
+
//# sourceMappingURL=reducer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../../src/realtime/reducer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,KAAK,EAEV,oBAAoB,EAGpB,oBAAoB,EAEpB,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,4BAA4B,EAC7B,MAAM,YAAY,CAAC;AAKpB,wBAAgB,yBAAyB,CAAC,QAAQ,GAAG,OAAO,KAAK,oBAAoB,CAAC,QAAQ,CAAC,CAQ9F;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAAE,EAAE,EAAE,SAAS,GAAG,MAAM,CAExF;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,4BAA4B,GAAG,MAAM,CASrF;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAC/C,KAAK,EAAE,oBAAoB,CAAC,QAAQ,CAAC,GACpC,wBAAwB,GAAG,SAAS,CAGtC;AAED,wBAAgB,0BAA0B,CAAC,QAAQ,EACjD,KAAK,EAAE,oBAAoB,CAAC,QAAQ,CAAC,EACrC,KAAK,EAAE,oBAAoB,CAAC,QAAQ,CAAC,EACrC,OAAO,GAAE,sBAA2B,GACnC,oBAAoB,CAAC,QAAQ,CAAC,CAuEhC;AAED,wBAAgB,0BAA0B,CAAC,QAAQ,EACjD,KAAK,EAAE,oBAAoB,CAAC,QAAQ,CAAC,EACrC,OAAO,EAAE,wBAAwB,GAChC,oBAAoB,CAAC,QAAQ,CAAC,CAUhC"}
|