@@ -218,19 +218,21 @@ export async function newLixFile(args?: {
218218 ) ?. entity_id ;
219219
220220 // Set active version using updateUntrackedState for proper inheritance handling
221- updateUntrackedState ( {
222- lix : { sqlite, db } ,
223- change : {
224- entity_id : "active" ,
225- schema_key : "lix_active_version" ,
226- file_id : "lix" ,
227- plugin_key : "lix_own_entity" ,
228- snapshot_content : JSON . stringify ( { version_id : initialVersionId } ) ,
229- schema_version : "1.0" ,
230- created_at : created_at ,
231- } ,
232- version_id : "global" ,
233- } ) ;
221+ updateUntrackedState ( {
222+ lix : { sqlite, db } ,
223+ changes : [
224+ {
225+ entity_id : "active" ,
226+ schema_key : "lix_active_version" ,
227+ file_id : "lix" ,
228+ plugin_key : "lix_own_entity" ,
229+ snapshot_content : JSON . stringify ( { version_id : initialVersionId } ) ,
230+ schema_version : "1.0" ,
231+ created_at : created_at ,
232+ lixcol_version_id : "global" ,
233+ } ,
234+ ] ,
235+ } ) ;
234236
235237 // Create anonymous account as untracked for deterministic behavior
236238 const activeAccountId = generateNanoid ( ) ;
@@ -240,64 +242,70 @@ export async function newLixFile(args?: {
240242 const anonymousAccountName = `Anonymous ${ humanName } ` ;
241243
242244 // Create the anonymous account as untracked
243- updateUntrackedState ( {
244- lix : { sqlite, db } ,
245- change : {
246- entity_id : activeAccountId ,
247- schema_key : LixAccountSchema [ "x-lix-key" ] ,
248- file_id : "lix" ,
249- plugin_key : "lix_own_entity" ,
250- snapshot_content : JSON . stringify ( {
251- id : activeAccountId ,
252- name : anonymousAccountName ,
253- } satisfies LixAccount ) ,
254- schema_version : LixAccountSchema [ "x-lix-version" ] ,
255- created_at : created_at ,
256- } ,
257- version_id : "global" ,
258- } ) ;
245+ updateUntrackedState ( {
246+ lix : { sqlite, db } ,
247+ changes : [
248+ {
249+ entity_id : activeAccountId ,
250+ schema_key : LixAccountSchema [ "x-lix-key" ] ,
251+ file_id : "lix" ,
252+ plugin_key : "lix_own_entity" ,
253+ snapshot_content : JSON . stringify ( {
254+ id : activeAccountId ,
255+ name : anonymousAccountName ,
256+ } satisfies LixAccount ) ,
257+ schema_version : LixAccountSchema [ "x-lix-version" ] ,
258+ created_at : created_at ,
259+ lixcol_version_id : "global" ,
260+ } ,
261+ ] ,
262+ } ) ;
259263
260264 // Set it as the active account
261- updateUntrackedState ( {
262- lix : { sqlite, db } ,
263- change : {
264- entity_id : `active_${ activeAccountId } ` ,
265- schema_key : LixActiveAccountSchema [ "x-lix-key" ] ,
266- file_id : "lix" ,
267- plugin_key : "lix_own_entity" ,
268- snapshot_content : JSON . stringify ( {
269- account_id : activeAccountId ,
270- } satisfies LixActiveAccount ) ,
271- schema_version : LixActiveAccountSchema [ "x-lix-version" ] ,
272- created_at : created_at ,
273- } ,
274- version_id : "global" ,
275- } ) ;
265+ updateUntrackedState ( {
266+ lix : { sqlite, db } ,
267+ changes : [
268+ {
269+ entity_id : `active_${ activeAccountId } ` ,
270+ schema_key : LixActiveAccountSchema [ "x-lix-key" ] ,
271+ file_id : "lix" ,
272+ plugin_key : "lix_own_entity" ,
273+ snapshot_content : JSON . stringify ( {
274+ account_id : activeAccountId ,
275+ } satisfies LixActiveAccount ) ,
276+ schema_version : LixActiveAccountSchema [ "x-lix-version" ] ,
277+ created_at : created_at ,
278+ lixcol_version_id : "global" ,
279+ } ,
280+ ] ,
281+ } ) ;
276282
277283 // Handle other untracked key values
278284 const untrackedKeyValues = args ?. keyValues ?. filter (
279285 ( kv ) => kv . lixcol_untracked === true
280286 ) ;
281287 if ( untrackedKeyValues ) {
282- for ( const kv of untrackedKeyValues ) {
283- const versionId = kv . lixcol_version_id ?? "global" ;
284- updateUntrackedState ( {
285- lix : { sqlite, db } ,
286- change : {
287- entity_id : kv . key ,
288- schema_key : "lix_key_value" ,
289- file_id : "lix" ,
290- plugin_key : "lix_own_entity" ,
291- snapshot_content : JSON . stringify ( {
292- key : kv . key ,
293- value : kv . value ,
294- } ) ,
295- schema_version : LixKeyValueSchema [ "x-lix-version" ] ,
296- created_at : created_at ,
297- } ,
298- version_id : versionId ,
299- } ) ;
300- }
288+ for ( const kv of untrackedKeyValues ) {
289+ const versionId = kv . lixcol_version_id ?? "global" ;
290+ updateUntrackedState ( {
291+ lix : { sqlite, db } ,
292+ changes : [
293+ {
294+ entity_id : kv . key ,
295+ schema_key : "lix_key_value" ,
296+ file_id : "lix" ,
297+ plugin_key : "lix_own_entity" ,
298+ snapshot_content : JSON . stringify ( {
299+ key : kv . key ,
300+ value : kv . value ,
301+ } ) ,
302+ schema_version : LixKeyValueSchema [ "x-lix-version" ] ,
303+ created_at : created_at ,
304+ lixcol_version_id : versionId ,
305+ } ,
306+ ] ,
307+ } ) ;
308+ }
301309 }
302310
303311 try {
0 commit comments