MCPcopy Create free account
hub / github.com/tiann/hapi / applyVersionedAck

Function applyVersionedAck

cli/src/api/versionedUpdate.ts:23–65  ·  view source on GitHub ↗
(
    ack: unknown,
    options: VersionedAckOptions<TValue, ValueKey>
)

Source from the content-addressed store, hash-verified

21}
22
23export const applyVersionedAck = <TValue, ValueKey extends string>(
24 ack: unknown,
25 options: VersionedAckOptions<TValue, ValueKey>
26): void => {
27 if (!isRecord(ack)) {
28 throw new Error(options.invalidResponseMessage)
29 }
30
31 const result = ack.result
32 if (result === 'success' || result === 'version-mismatch') {
33 const version = ack.version
34 if (typeof version !== 'number') {
35 throw new Error(options.invalidResponseMessage)
36 }
37
38 const rawValue = ack[options.valueKey]
39 if (rawValue == null) {
40 options.applyValue(null)
41 } else {
42 const parsed = options.parseValue(rawValue)
43 if (parsed === null) {
44 options.logInvalidValue(result, version)
45 } else {
46 options.applyValue(parsed)
47 }
48 }
49
50 options.applyVersion(version)
51
52 if (result === 'version-mismatch') {
53 throw new Error(options.versionMismatchMessage)
54 }
55
56 return
57 }
58
59 if (result === 'error') {
60 const reason = typeof ack.reason === 'string' ? ack.reason : 'unknown'
61 throw new Error(`${options.errorMessage} (${reason})`)
62 }
63
64 throw new Error(options.invalidResponseMessage)
65}

Callers 5

updateMachineMetadataMethod · 0.90
updateRunnerStateMethod · 0.90
updateMetadataMethod · 0.90
updateAgentStateMethod · 0.90

Calls 1

isRecordFunction · 0.85

Tested by

no test coverage detected