@kontourai/survey 0.4.20 → 0.4.21
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
CHANGED
|
@@ -113,7 +113,8 @@ For browser-backed queues, server code can import
|
|
|
113
113
|
`createServerReviewSessionRecord`, `hashReviewSessionSnapshot`,
|
|
114
114
|
`assertServerReviewSessionFreshness`, and `assertServerReviewSessionEvents` to
|
|
115
115
|
keep the review snapshot server-owned while accepting browser-submitted
|
|
116
|
-
`ReviewSessionEvent` resources.
|
|
116
|
+
`ReviewSessionEvent` resources. `deriveServerReviewSessionApplyResult` composes
|
|
117
|
+
those checks with Survey's apply-result derivation for server-side write paths.
|
|
117
118
|
For generic, test-covered consumer examples, see
|
|
118
119
|
[`examples/review-workbench/facility-credential-consumer.ts`](examples/review-workbench/facility-credential-consumer.ts)
|
|
119
120
|
for presentation and event persistence, and
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type DeriveReviewSessionApplyResultForSnapshotResult, type ReviewSessionApplyResolutionRequirement } from "./review-workbench.js";
|
|
1
2
|
import { type ReviewSessionReplayIssue } from "./review-session-replay.js";
|
|
2
3
|
import type { ReviewSessionEvent } from "../review-resource.js";
|
|
3
4
|
import type { ReviewQueueSessionState } from "./review-queue-session.js";
|
|
@@ -48,9 +49,17 @@ export interface CreateServerReviewSessionRecordOptions {
|
|
|
48
49
|
readonly eventCount?: number;
|
|
49
50
|
readonly updatedAt?: string | Date;
|
|
50
51
|
}
|
|
52
|
+
export interface DeriveServerReviewSessionApplyResultOptions {
|
|
53
|
+
readonly record: ServerReviewSessionRecord;
|
|
54
|
+
readonly events: readonly ReviewSessionEvent[];
|
|
55
|
+
readonly currentSnapshot?: ReviewQueueSessionState;
|
|
56
|
+
readonly currentEventCount?: number;
|
|
57
|
+
readonly requiredResolvedItems?: ReviewSessionApplyResolutionRequirement;
|
|
58
|
+
}
|
|
51
59
|
export declare function createServerReviewSessionRecord(options: CreateServerReviewSessionRecordOptions): ServerReviewSessionRecord;
|
|
52
60
|
export declare function hashReviewSessionSnapshot(snapshot: ReviewQueueSessionState): string;
|
|
53
61
|
export declare function compareServerReviewSessionFreshness(record: ServerReviewSessionRecord, snapshot: ReviewQueueSessionState, eventCount?: number): ServerReviewSessionFreshnessComparison;
|
|
54
62
|
export declare function assertServerReviewSessionFreshness(record: ServerReviewSessionRecord, snapshot: ReviewQueueSessionState, eventCount?: number): void;
|
|
55
63
|
export declare function validateServerReviewSessionEvents(record: ServerReviewSessionRecord, events: readonly ReviewSessionEvent[]): ServerReviewSessionEventValidationIssue[];
|
|
56
64
|
export declare function assertServerReviewSessionEvents(record: ServerReviewSessionRecord, events: readonly ReviewSessionEvent[]): void;
|
|
65
|
+
export declare function deriveServerReviewSessionApplyResult(options: DeriveServerReviewSessionApplyResultOptions): DeriveReviewSessionApplyResultForSnapshotResult;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
+
import { deriveReviewSessionApplyResultForSnapshot, } from "./review-workbench.js";
|
|
2
3
|
import { validateReviewSessionEventsForSnapshot, } from "./review-session-replay.js";
|
|
3
4
|
export class StaleServerReviewSessionError extends Error {
|
|
4
5
|
name = "StaleServerReviewSessionError";
|
|
@@ -72,6 +73,18 @@ export function assertServerReviewSessionEvents(record, events) {
|
|
|
72
73
|
throw new ServerReviewSessionEventValidationError(issues);
|
|
73
74
|
}
|
|
74
75
|
}
|
|
76
|
+
export function deriveServerReviewSessionApplyResult(options) {
|
|
77
|
+
assertServerReviewSessionFreshness(options.record, options.record.snapshot);
|
|
78
|
+
if (options.currentSnapshot) {
|
|
79
|
+
assertServerReviewSessionFreshness(options.record, options.currentSnapshot, options.currentEventCount);
|
|
80
|
+
}
|
|
81
|
+
assertServerReviewSessionEvents(options.record, options.events);
|
|
82
|
+
return deriveReviewSessionApplyResultForSnapshot({
|
|
83
|
+
snapshot: options.record.snapshot,
|
|
84
|
+
events: options.events,
|
|
85
|
+
requiredResolvedItems: options.requiredResolvedItems,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
75
88
|
function staleIssuesForComparison(comparison) {
|
|
76
89
|
const issues = [];
|
|
77
90
|
if (comparison.expectedSnapshotHash !== comparison.actualSnapshotHash) {
|
package/package.json
CHANGED