cultcache-ts: codecFormatter moves into the private document-formatter module; pack smoke refuses it from the root and ./document
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ce52d9aa60
commit
71d8ff3080
3 changed files with 21 additions and 11 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import type { CultCacheDocumentFormatter, CultCacheSchemaCatalogMember } from "./types";
|
||||
import { readWire, WireFloat, writeWire } from "./wire";
|
||||
import type { CultCacheSchemaCatalogMember } from "./types";
|
||||
import { WireFloat } from "./wire";
|
||||
|
||||
// A codec turns a value into the shape the reference runtimes write and back. Slot records are positional arrays with
|
||||
// nil gaps; a union value is { kind: armName, ...armFields }, written [armKey, [armSlots...]]. Refusals name the union
|
||||
|
|
@ -368,11 +368,3 @@ export function union<TValue extends { kind: string }>(
|
|||
},
|
||||
};
|
||||
}
|
||||
|
||||
// The formatter a document gets from a slot codec: the codec's value as one MessagePack payload.
|
||||
export function codecFormatter<TValue extends object>(codec: SlotsCodec<TValue>): CultCacheDocumentFormatter<TValue> {
|
||||
return {
|
||||
encode: (value) => writeWire(codec.encode(value)),
|
||||
decode: (payload) => codec.decode(readWire(payload)),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { decode, encode } from "@msgpack/msgpack";
|
||||
|
||||
import { codecFormatter } from "./codec";
|
||||
import type { SlotsCodec } from "./codec";
|
||||
import type { AnyCultCacheDocumentDefinition, CultCacheDocumentFormatter } from "./types";
|
||||
import { readWire, writeWire } from "./wire";
|
||||
|
||||
// The one place that decides how a document is encoded: its own formatter, or its codec's, or a plain map. A codec and a
|
||||
// formatter are two answers to one question, so a definition that carries both is refused wherever it enters (the
|
||||
|
|
@ -18,3 +19,12 @@ const plainDocumentFormatter: CultCacheDocumentFormatter<unknown> = {
|
|||
encode: (value: unknown) => encode(value),
|
||||
decode: (payload: Uint8Array) => decode(payload),
|
||||
};
|
||||
|
||||
// The formatter a document gets from a slot codec: the codec's value as one MessagePack payload. Private to this module
|
||||
// for the same reason as the resolver: exported, it would read a payload without the schema.
|
||||
function codecFormatter<TValue extends object>(codec: SlotsCodec<TValue>): CultCacheDocumentFormatter<TValue> {
|
||||
return {
|
||||
encode: (value) => writeWire(codec.encode(value)),
|
||||
decode: (payload) => codec.decode(readWire(payload)),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,8 @@ assert.equal(typeof cache.defineDocumentType, "function");
|
|||
assert.equal(documentEntry.decodeDocumentPayload, cache.decodeDocumentPayload);
|
||||
assert.equal("resolveDocumentFormatter" in cache, false);
|
||||
assert.equal("resolveDocumentFormatter" in documentEntry, false);
|
||||
assert.equal("codecFormatter" in cache.codecs, false);
|
||||
assert.equal("codecFormatter" in documentEntry, false);
|
||||
assert.equal(typeof net.CultNetPeer, "function");
|
||||
assert.equal(typeof mesh.CultMesh, "function");
|
||||
assert.equal(typeof mesh.CultMeshProviderSession, "function");
|
||||
|
|
@ -190,6 +192,12 @@ void decodeOwner;
|
|||
// @ts-expect-error resolveDocumentFormatter is not exported from the document entry
|
||||
import { resolveDocumentFormatter } from "@gamecult/cultcache-ts/document";
|
||||
void resolveDocumentFormatter;
|
||||
import { codecs } from "@gamecult/cultcache-ts";
|
||||
// @ts-expect-error codecFormatter is not exported from the document entry
|
||||
import { codecFormatter } from "@gamecult/cultcache-ts/document";
|
||||
void codecFormatter;
|
||||
// @ts-expect-error codecFormatter is not a member of the root's codecs namespace
|
||||
void codecs.codecFormatter;
|
||||
`);
|
||||
execFileSync(process.execPath, [
|
||||
tsc,
|
||||
|
|
|
|||
Loading…
Reference in a new issue