| 7245 | return out |
| 7246 | } |
| 7247 | const checkWire: CacheInternals["checkWire"] = (input) => { |
| 7248 | const parsed = parseRaw(input) |
| 7249 | if (parsed === undefined) return ["the ~query state isn't the tuple shape"] |
| 7250 | const out: Array<string> = [] |
| 7251 | for (const [name, byKey] of parsed) { |
| 7252 | const def = queries.get(name) |
| 7253 | if (def === undefined) { |
| 7254 | out.push( |
| 7255 | "the query " + quote(name) + |
| 7256 | " shipped entries, and this cache doesn't know it" |
| 7257 | ) |
| 7258 | continue |
| 7259 | } |
| 7260 | const codec = def.codec() |
| 7261 | for (const [wireKey, tuple] of byKey) { |
| 7262 | let args: unknown |
| 7263 | let logKey: string |
| 7264 | try { |
| 7265 | args = codec.decodeArgs(wireKey) |
| 7266 | const argsKey = def.argsKey(args) |
| 7267 | logKey = def.logKey(args, argsKey) |
| 7268 | if (argsKey !== wireKey) { |
| 7269 | out.push( |
| 7270 | "an entry of " + quote(name) + " at " + logKey + |
| 7271 | " has args that key differently once decoded" |
| 7272 | ) |
| 7273 | continue |
| 7274 | } |
| 7275 | } catch { |
| 7276 | out.push( |
| 7277 | "the args of an entry of " + quote(name) + " failed to decode" |
| 7278 | ) |
| 7279 | continue |
| 7280 | } |
| 7281 | try { |
| 7282 | const again = tuple[1] === 0 |
| 7283 | ? codec.encodeSuccess(codec.decodeSuccess(tuple[2])) |
| 7284 | : tuple[2].map((error) => codec.encodeError(codec.decodeError(error))) |
| 7285 | if (JSON.stringify(again) !== JSON.stringify(tuple[2])) { |
| 7286 | out.push( |
| 7287 | "the entry of " + quote(name) + " at " + logKey + |
| 7288 | " encodes differently once decoded" |
| 7289 | ) |
| 7290 | } |
| 7291 | } catch { |
| 7292 | out.push( |
| 7293 | "the entry of " + quote(name) + " at " + logKey + |
| 7294 | " failed to decode or encode again" |
| 7295 | ) |
| 7296 | } |
| 7297 | } |
| 7298 | } |
| 7299 | return out |
| 7300 | } |
| 7301 | const seed: CacheInternals["seed"] = (snapshot) => { |
| 7302 | const data = snapshotData(snapshot) |
| 7303 | // A per-request cache never refetches a settled entry, so a seed there would be final. |