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>; }
optionalapplyChanges: ({ file, changes, }: {changes:Change[];file:Omit<LixFile,"data"> & {data?:Uint8Array; }; }) => {fileData:Uint8Array; }
| Parameter | Type | Description |
|---|---|---|
{ file, changes, } | { changes: Change[]; file: Omit<LixFile, "data"> & { data?: Uint8Array; }; } | - |
{ file, changes, }.changes | Change[] | - |
{ file, changes, }.file | Omit<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. |
{ fileData: Uint8Array; }
fileData:
Uint8Array
optionaldetectChanges: ({ 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.
| Parameter | Type | Description |
|---|---|---|
{ before, after, querySync, } | { after: Omit<LixFile, "data"> & { data: Uint8Array; }; before?: Omit<LixFile, "data"> & { data?: Uint8Array; }; querySync: QuerySync; } | - |
{ before, after, querySync, }.after | Omit<LixFile, "data"> & { data: Uint8Array; } | - |
{ before, after, querySync, }.before? | Omit<LixFile, "data"> & { data?: Uint8Array; } | - |
{ before, after, querySync, }.querySync | QuerySync | Build 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 [] } |
optionaldetectChangesGlob:string
The glob pattern that should invoke detectChanges().
`**/*.json` for all JSON files
`**/*.inlang` for all inlang fileskey:
string
optionalrenderDiff: (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.
const html = await plugin.renderDiff?.({ diffs })
container.innerHTML = html ?? ""| Parameter | Type |
|---|---|
args | RenderDiffArgs |
Promise<string>