API reference@evolu/commonLookup › structuralLookup

function structuralLookup<K>(key: Structural<K>): StructuralLookupKey;

Defined in: packages/common/src/Lookup.ts:332

Returns the structural lookup key for key.

Structural lookup keys are derived from JSON-like values plus Uint8Array. Equal structures produce the same lookup key even when they are different JavaScript instances.

The derived key is memoized by non-null object identity in a module-scoped WeakMap shared by all callers, so keys must be immutable.

Use this as a Lookup when logical equality should be based on structural value instead of reference identity.

Example

const byFilter = createLookupMap<
  { readonly table: string; readonly where: readonly [string, string] },
  string,
  StructuralLookupKey
>({
  lookup: structuralLookup,
});

byFilter.set({ table: "todo", where: ["owner", "ada"] }, "cached");
byFilter.get({ table: "todo", where: ["owner", "ada"] }); // "cached"

See