Skip to content

FacetDeclaration

The description of a facet that a plugin passes to ctx.facets.define: its name, the kind of thing it is attached to, how its values are merged, which values it accepts, and whether it is shared with other devices.

const sessions = ctx.facets.define<number>({
key: 'com.example.pomodoro/sessions',
on: 'row',
merge: 'counter',
schema: { type: 'integer', minimum: 0 },
});
readonly alias?: string;

A short name that searches can use for the facet, for example pomodoro in the search pomodoro>3.


readonly key: string;

The name of the facet, written <plugin id>/<name>.


readonly merge: "text" | "set" | "lww" | "counter";

What happens when two devices change the value at the same time: lww keeps the later change, text merges the two texts, set keeps what both devices added, and counter adds up what each device added.


readonly on: "outline" | "library" | "row";

The kind of thing that the facet is attached to: a row, an outline or the library.


readonly paths?: readonly string[];

The parts of the value that searches can look at quickly. The path . designates the whole value.


readonly schema: Schema;

The description of the values that the facet accepts. The app checks every value against it when the value is written.


readonly sync?: boolean;

When false, the value stays on the device where it was written. By default it is shared with the other devices of the person.


readonly validate?: (value) => ValueVerdict;

A check that the plugin applies after the check against the schema.

Parameter Type Description
value unknown the value to check, which already conforms to the schema

ValueVerdict

valid(), coerced(value) or invalid(issue)