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.
Example
Section titled “Example”const sessions = ctx.facets.define<number>({ key: 'com.example.pomodoro/sessions', on: 'row', merge: 'counter', schema: { type: 'integer', minimum: 0 },});Properties
Section titled “Properties”alias?
Section titled “alias?”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.
paths?
Section titled “paths?”readonly paths?: readonly string[];The parts of the value that searches can look at quickly. The path . designates the whole value.
schema
Section titled “schema”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.
validate?
Section titled “validate?”readonly validate?: (value) => ValueVerdict;A check that the plugin applies after the check against the schema.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
unknown |
the value to check, which already conforms to the schema |
Returns
Section titled “Returns”valid(), coerced(value) or invalid(issue)
