Type Alias: LixPlugin

LixPlugin = { applyChanges?: ({ file, changes, }: { changes: Change[]; file: Omit<LixFile, "data"> & { data?: Uint8Array; }; }) => { fileData: Uint8Array; }; detectChanges?: ({ before, after, querySync, }: { after: Omit<LixFile, "data"> & { data: Uint8Array; }; before?: Omit<LixFile, "data"> & { data?: Uint8Array; }; querySync: QuerySync; }) => DetectedChange[]; detectChangesGlob?: string; key: string; renderDiff?: (args: RenderDiffArgs) => Promise<string>; }

Properties

applyChanges()?

optional applyChanges: ({ file, changes, }: { changes: Change[]; file: Omit<LixFile, "data"> & { data?: Uint8Array; }; }) => { fileData: Uint8Array; }

Parameters

ParameterTypeDescription
{ file, changes, }{ changes: Change[]; file: Omit<LixFile, "data"> & { data?: Uint8Array; }; }-
{ file, changes, }.changesChange[]-
{ file, changes, }.fileOmit<LixFile, "data"> & { data?: Uint8Array; }The file to which the changes should be applied. The file.data might be undefined if the file does not exist at the time of applying the changes. This can happen when merging a version that created a new file that did not exist in the target version. Or, a file has been deleted and should be restored at a later point.

Returns

{ fileData: Uint8Array; }

fileData

fileData: Uint8Array


detectChanges()?

optional detectChanges: ({ before, after, querySync, }: { after: Omit<LixFile, "data"> & { data: Uint8Array; }; before?: Omit<LixFile, "data"> & { data?: Uint8Array; }; querySync: QuerySync; }) => DetectedChange[]

Detects changes between the before and after file update(s).

Before is undefined if the file did not exist before ( the file was created).

After is always defined. Either the file was updated, or deleted. If the file is deleted, lix own change control will handle the deletion. Hence, after is always be defined.

Parameters

ParameterTypeDescription
{ before, after, querySync, }{ after: Omit<LixFile, "data"> & { data: Uint8Array; }; before?: Omit<LixFile, "data"> & { data?: Uint8Array; }; querySync: QuerySync; }-
{ before, after, querySync, }.afterOmit<LixFile, "data"> & { data: Uint8Array; }-
{ before, after, querySync, }.before?Omit<LixFile, "data"> & { data?: Uint8Array; }-
{ before, after, querySync, }.querySyncQuerySyncBuild synchronous SQL queries. Detecting changes can require reading current state to preserve stable entity ids, compare snapshots, or infer ordering without reparsing files. Why is a sync possible and allowed? The engine can run in a separate thread/process. SQLite executes queries synchronously and the engine cannot await async calls to the host thread during detectChanges(). querySync provides a Kysely builder whose .execute() runs synchronously inside the engine. Example detectChanges: ({ after, querySync }) => { const rows = querySync('state') .where('file_id', '=', after.id) .where('plugin_key', '=', 'plugin_md') .select(['entity_id', 'schema_key', 'snapshot_content']) .execute() const latestById = new Map(rows.map(r => [r.entity_id, r])) // ...use latestById to assign/reuse ids in emitted changes... return [] }

Returns

DetectedChange[]


detectChangesGlob?

optional detectChangesGlob: string

The glob pattern that should invoke detectChanges().

Example

`**/*.json` for all JSON files
  `**/*.inlang` for all inlang files

key

key: string


renderDiff()?

optional renderDiff: (args: RenderDiffArgs) => Promise<string>

Render the diff for this plugin as HTML.

Hosts can insert the returned markup directly or scope it inside a ShadowRoot. The HTML should rely on CSS custom properties (e.g. --lix-diff-*) instead of hardcoded colors so environments can theme it.

Example

const html = await plugin.renderDiff?.({ diffs })
container.innerHTML = html ?? ""

Parameters

ParameterType
argsRenderDiffArgs

Returns

Promise<string>