Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/lix-sdk/src/change/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ test("changes in transaction can be accessed via change view", async () => {
})
.execute();

// This should create a change in internal_transaction_state
// The change view should include changes from both internal_change and internal_transaction_state
// This should create a change in internal_transaction_state
// The change view should include changes from both internal_change and internal_transaction_state

// Try to find the change within the transaction via the change view
const changesInTransaction = await trx
Expand All @@ -309,7 +309,7 @@ test("changes in transaction can be accessed via change view", async () => {
.selectAll()
.execute();

// This should find the change that was created in internal_transaction_state
// This should find the change that was created in internal_transaction_state
expect(changesInTransaction).toHaveLength(1);
expect(changesInTransaction[0]).toMatchObject({
entity_id: "test_key_in_transaction",
Expand Down
30 changes: 15 additions & 15 deletions packages/lix-sdk/src/deterministic/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,19 +248,19 @@ export function commitDeterministicRngState(args: {
} satisfies LixKeyValue);

const now = args.timestamp ?? timestamp({ lix: args.lix });
updateUntrackedState({
lix: args.lix,
changes: [
{
entity_id: "lix_deterministic_rng_state",
schema_key: LixKeyValueSchema["x-lix-key"],
file_id: "lix",
plugin_key: "lix_own_entity",
snapshot_content: newValue,
schema_version: LixKeyValueSchema["x-lix-version"],
created_at: now,
lixcol_version_id: "global",
},
],
});
updateUntrackedState({
lix: args.lix,
changes: [
{
entity_id: "lix_deterministic_rng_state",
schema_key: LixKeyValueSchema["x-lix-key"],
file_id: "lix",
plugin_key: "lix_own_entity",
snapshot_content: newValue,
schema_version: LixKeyValueSchema["x-lix-version"],
created_at: now,
lixcol_version_id: "global",
},
],
});
}
30 changes: 15 additions & 15 deletions packages/lix-sdk/src/deterministic/sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,19 @@ export function commitDeterministicSequenceNumber(args: {
} satisfies LixKeyValue);

const now = args.timestamp ?? timestamp({ lix: args.lix });
updateUntrackedState({
lix: args.lix,
changes: [
{
entity_id: "lix_deterministic_sequence_number",
schema_key: LixKeyValueSchema["x-lix-key"],
file_id: "lix",
plugin_key: "lix_own_entity",
snapshot_content: newValue,
schema_version: LixKeyValueSchema["x-lix-version"],
created_at: now,
lixcol_version_id: "global",
},
],
});
updateUntrackedState({
lix: args.lix,
changes: [
{
entity_id: "lix_deterministic_sequence_number",
schema_key: LixKeyValueSchema["x-lix-key"],
file_id: "lix",
plugin_key: "lix_own_entity",
snapshot_content: newValue,
schema_version: LixKeyValueSchema["x-lix-version"],
created_at: now,
lixcol_version_id: "global",
},
],
});
}
142 changes: 71 additions & 71 deletions packages/lix-sdk/src/lix/new-lix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,21 +218,21 @@ export async function newLixFile(args?: {
)?.entity_id;

// Set active version using updateUntrackedState for proper inheritance handling
updateUntrackedState({
lix: { sqlite, db },
changes: [
{
entity_id: "active",
schema_key: "lix_active_version",
file_id: "lix",
plugin_key: "lix_own_entity",
snapshot_content: JSON.stringify({ version_id: initialVersionId }),
schema_version: "1.0",
created_at: created_at,
lixcol_version_id: "global",
},
],
});
updateUntrackedState({
lix: { sqlite, db },
changes: [
{
entity_id: "active",
schema_key: "lix_active_version",
file_id: "lix",
plugin_key: "lix_own_entity",
snapshot_content: JSON.stringify({ version_id: initialVersionId }),
schema_version: "1.0",
created_at: created_at,
lixcol_version_id: "global",
},
],
});

// Create anonymous account as untracked for deterministic behavior
const activeAccountId = generateNanoid();
Expand All @@ -242,70 +242,70 @@ export async function newLixFile(args?: {
const anonymousAccountName = `Anonymous ${humanName}`;

// Create the anonymous account as untracked
updateUntrackedState({
lix: { sqlite, db },
changes: [
{
entity_id: activeAccountId,
schema_key: LixAccountSchema["x-lix-key"],
file_id: "lix",
plugin_key: "lix_own_entity",
snapshot_content: JSON.stringify({
id: activeAccountId,
name: anonymousAccountName,
} satisfies LixAccount),
schema_version: LixAccountSchema["x-lix-version"],
created_at: created_at,
lixcol_version_id: "global",
},
],
});
updateUntrackedState({
lix: { sqlite, db },
changes: [
{
entity_id: activeAccountId,
schema_key: LixAccountSchema["x-lix-key"],
file_id: "lix",
plugin_key: "lix_own_entity",
snapshot_content: JSON.stringify({
id: activeAccountId,
name: anonymousAccountName,
} satisfies LixAccount),
schema_version: LixAccountSchema["x-lix-version"],
created_at: created_at,
lixcol_version_id: "global",
},
],
});

// Set it as the active account
updateUntrackedState({
lix: { sqlite, db },
changes: [
{
entity_id: `active_${activeAccountId}`,
schema_key: LixActiveAccountSchema["x-lix-key"],
file_id: "lix",
plugin_key: "lix_own_entity",
snapshot_content: JSON.stringify({
account_id: activeAccountId,
} satisfies LixActiveAccount),
schema_version: LixActiveAccountSchema["x-lix-version"],
created_at: created_at,
lixcol_version_id: "global",
},
],
});
updateUntrackedState({
lix: { sqlite, db },
changes: [
{
entity_id: `active_${activeAccountId}`,
schema_key: LixActiveAccountSchema["x-lix-key"],
file_id: "lix",
plugin_key: "lix_own_entity",
snapshot_content: JSON.stringify({
account_id: activeAccountId,
} satisfies LixActiveAccount),
schema_version: LixActiveAccountSchema["x-lix-version"],
created_at: created_at,
lixcol_version_id: "global",
},
],
});

// Handle other untracked key values
const untrackedKeyValues = args?.keyValues?.filter(
(kv) => kv.lixcol_untracked === true
);
if (untrackedKeyValues) {
for (const kv of untrackedKeyValues) {
const versionId = kv.lixcol_version_id ?? "global";
updateUntrackedState({
lix: { sqlite, db },
changes: [
{
entity_id: kv.key,
schema_key: "lix_key_value",
file_id: "lix",
plugin_key: "lix_own_entity",
snapshot_content: JSON.stringify({
key: kv.key,
value: kv.value,
}),
schema_version: LixKeyValueSchema["x-lix-version"],
created_at: created_at,
lixcol_version_id: versionId,
},
],
});
}
for (const kv of untrackedKeyValues) {
const versionId = kv.lixcol_version_id ?? "global";
updateUntrackedState({
lix: { sqlite, db },
changes: [
{
entity_id: kv.key,
schema_key: "lix_key_value",
file_id: "lix",
plugin_key: "lix_own_entity",
snapshot_content: JSON.stringify({
key: kv.key,
value: kv.value,
}),
schema_version: LixKeyValueSchema["x-lix-version"],
created_at: created_at,
lixcol_version_id: versionId,
},
],
});
}
}

try {
Expand Down
Loading
Loading