Skip to content

Commit

Permalink
Merge pull request #3298 from opral/lixdk-253-non-nullable-version-na…
Browse files Browse the repository at this point in the history
…me-with-default-human-id

adds unique and default human readable version names
  • Loading branch information
samuelstroschein authored Dec 21, 2024
2 parents 7e2dbf6 + 1a80595 commit 2d5486b
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 35 deletions.
8 changes: 8 additions & 0 deletions .changeset/nine-seahorses-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@lix-js/sdk": minor
---

adds unique and default human readable version names

- removes nullability of `version.name` which eases conditional logic.
- apps don't need custom default version naming logic anymore
1 change: 0 additions & 1 deletion packages/csv-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"@shoelace-style/shoelace": "^2.17.1",
"@xyflow/react": "^12.3.4",
"clsx": "^2.1.1",
"human-id": "^4.1.1",
"jotai": "^2.10.1",
"lodash-es": "^4.17.21",
"native-file-system-adapter": "^3.0.1",
Expand Down
6 changes: 0 additions & 6 deletions packages/csv-app/src/layouts/OpenFileLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
switchVersion,
mergeVersion,
} from "@lix-js/sdk";
import { humanId } from "human-id";
import CustomLink from "../components/CustomLink.tsx";

export default function Layout(props: { children: React.ReactNode }) {
Expand Down Expand Up @@ -277,11 +276,6 @@ const VersionDropdown = () => {
const newversion = await createVersion({
lix,
from: currentVersion,
name: humanId({
separator: "-",
capitalize: false,
adjectiveCount: 0,
}),
});
await switchToversion(newversion);
}}
Expand Down
1 change: 0 additions & 1 deletion packages/lix-file-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"date-fns": "^2.29.3",
"human-id": "^4.1.1",
"jotai": "^2.10.1",
"lodash-es": "^4.17.21",
"lucide-react": "^0.460.0",
Expand Down
6 changes: 0 additions & 6 deletions packages/lix-file-manager/src/components/VersionDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
} from "../state.js";
import { Version, createVersion, switchVersion } from "@lix-js/sdk";
import { saveLixToOpfs } from "../helper/saveLixToOpfs.js";
import { humanId } from "human-id";
import { Check, Trash2, ChevronDown, Plus } from "lucide-react";
import { MergeDialog } from "./MergeDialog.js";
import IconMerge from "./icons/IconMerge.js";
Expand Down Expand Up @@ -56,11 +55,6 @@ export function VersionDropdown() {
const newVersion = await createVersion({
lix,
from: currentVersion,
name: humanId({
separator: "-",
capitalize: false,
adjectiveCount: 0,
}),
});

await switchToVersion(newVersion);
Expand Down
2 changes: 1 addition & 1 deletion packages/lix-file-manager/src/components/ui/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { cn } from "@/lib/utils"
// @ts-expect-error - no types
import { Label } from "@/components/ui/label"

const Form = FormProvider
const Form: any = FormProvider;

type FormFieldContextValue<
TFieldValues extends FieldValues = FieldValues,
Expand Down
9 changes: 1 addition & 8 deletions packages/lix-sdk/src/database/apply-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,7 @@ export function applySchema(args: { sqlite: SqliteDatabase }): SqliteDatabase {
CREATE TABLE IF NOT EXISTS version (
id TEXT PRIMARY KEY DEFAULT (uuid_v7()),
-- name is optional.
--
-- "anonymous" versiones can ease workflows.
-- For example, a user can create a version
-- without a name to experiment with
-- changes with no mental overhead of
-- naming the version.
name TEXT
name TEXT NOT NULL UNIQUE DEFAULT (human_id())
) STRICT;
CREATE TABLE IF NOT EXISTS version_change (
Expand Down
14 changes: 14 additions & 0 deletions packages/lix-sdk/src/database/init-db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,17 @@ test("version_change must have a unique entity_id, file_id, version_id, and sche
.values({ ...versionChange, version_id: version1.id })
.execute();
});

test("versions have a unique and default human readable name", async () => {
const lix = await openLixInMemory({});

const version0 = await createVersion({ lix });
const version1 = await createVersion({ lix });

expect(version0.name).not.toBe(version1.name);

await expect(
createVersion({ lix, name: version0.name }),
"version.name is unique"
).rejects.toThrow();
});
7 changes: 7 additions & 0 deletions packages/lix-sdk/src/database/init-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ParseJsonBPluginV1 } from "./kysely-plugin/parse-jsonb-plugin-v1.js";
import { SerializeJsonBPlugin } from "./kysely-plugin/serialize-jsonb-plugin.js";
import { createSession } from "./mutation-log/lix-session.js";
import { applyOwnChangeControlTriggers } from "../own-change-control/database-triggers.js";
import { humanId } from "human-id";

export function initDb(args: {
sqlite: SqliteDatabase;
Expand Down Expand Up @@ -91,4 +92,10 @@ function initFunctions(args: { sqlite: SqliteDatabase }) {
arity: 0,
xFunc: () => lixSession.sessionClockTick(),
});

args.sqlite.createFunction({
name: "human_id",
arity: 0,
xFunc: () => humanId({ separator: "-", capitalize: false }),
});
}
2 changes: 1 addition & 1 deletion packages/lix-sdk/src/database/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export type Newversion = Insertable<VersionTable>;
export type VersionUpdate = Updateable<VersionTable>;
type VersionTable = {
id: Generated<string>;
name: string | null;
name: Generated<string>;
};

export type VersionChange = Selectable<VersionChangeTable>;
Expand Down
1 change: 0 additions & 1 deletion packages/lix-sdk/src/file-queue/file-queue-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export async function initFileQueueProcess(args: {
let hasMoreEntriesSince: number | undefined = undefined;

async function queueWorker(trail = false) {

if (args.lix.sqlite.isOpen() === false) {
console.log("sqlite is closed");
return;
Expand Down
3 changes: 2 additions & 1 deletion packages/lix-website-server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ app.use(express.static(`${node_modules}/lix-website/build/client`));
// Serve the website server routes
app.all(
"*",
// @ts-ignore
createRequestHandler({
build: require(`${node_modules}/lix-website/build/server`),
}),
})
);

// Start the server
Expand Down
45 changes: 36 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2d5486b

Please sign in to comment.