diff --git a/inlang/source-code/sdk2/src/database/initDb.ts b/inlang/source-code/sdk2/src/database/initDb.ts index 3b7457c78a..728e41b0e0 100644 --- a/inlang/source-code/sdk2/src/database/initDb.ts +++ b/inlang/source-code/sdk2/src/database/initDb.ts @@ -2,7 +2,7 @@ import { CamelCasePlugin, Kysely, ParseJSONResultsPlugin } from "kysely"; import type { InlangDatabaseSchema } from "./schema.js"; import { createDialect, type SqliteDatabase } from "sqlite-wasm-kysely"; import { v4 } from "uuid"; -import { generateBundleId } from "../bundle-id/bundle-id.js"; +import { humanId } from "../human-id/human-id.js"; import { SerializeJsonPlugin } from "./serializeJsonPlugin.js"; export function initDb(args: { sqlite: SqliteDatabase }) { @@ -27,8 +27,8 @@ function initDefaultValueFunctions(args: { sqlite: SqliteDatabase }) { xFunc: () => v4(), }); args.sqlite.createFunction({ - name: "bundle_id", + name: "human_id", arity: 0, - xFunc: () => generateBundleId(), + xFunc: () => humanId(), }); } diff --git a/inlang/source-code/sdk2/src/database/initDbAndSchema.test.ts b/inlang/source-code/sdk2/src/database/initDbAndSchema.test.ts index 2278a1a359..a981cd30ca 100644 --- a/inlang/source-code/sdk2/src/database/initDbAndSchema.test.ts +++ b/inlang/source-code/sdk2/src/database/initDbAndSchema.test.ts @@ -1,7 +1,7 @@ import { createInMemoryDatabase } from "sqlite-wasm-kysely"; import { test, expect } from "vitest"; import { initDb } from "./initDb.js"; -import { isBundleId } from "../bundle-id/bundle-id.js"; +import { isHumanId } from "../human-id/human-id.js"; import { validate as isUuid } from "uuid"; import { createSchema } from "./schema.js"; @@ -18,7 +18,7 @@ test("bundle default values", async () => { .returningAll() .executeTakeFirstOrThrow(); - expect(isBundleId(bundle.id)).toBe(true); + expect(isHumanId(bundle.id)).toBe(true); expect(bundle.alias).toStrictEqual({}); }); diff --git a/inlang/source-code/sdk2/src/database/schema.ts b/inlang/source-code/sdk2/src/database/schema.ts index 5336efa4c9..722c531a83 100644 --- a/inlang/source-code/sdk2/src/database/schema.ts +++ b/inlang/source-code/sdk2/src/database/schema.ts @@ -7,7 +7,7 @@ export async function createSchema(args: { sqlite: SqliteDatabase }) { PRAGMA foreign_keys = ON; CREATE TABLE bundle ( - id TEXT PRIMARY KEY DEFAULT (bundle_id()), + id TEXT PRIMARY KEY DEFAULT (human_id()), alias TEXT NOT NULL DEFAULT '{}' ) strict; diff --git a/inlang/source-code/sdk2/src/helper.ts b/inlang/source-code/sdk2/src/helper.ts index 659480b433..22fe4c7b83 100644 --- a/inlang/source-code/sdk2/src/helper.ts +++ b/inlang/source-code/sdk2/src/helper.ts @@ -1,6 +1,6 @@ import { v4 as uuid } from "uuid"; import type { ProjectSettings } from "./json-schema/settings.js"; -import { generateBundleId } from "./bundle-id/bundle-id.js"; +import { humanId } from "./human-id/human-id.js"; import type { Bundle, MessageNested, @@ -26,7 +26,7 @@ export function createBundle(args: { alias?: Bundle["alias"]; }): NewBundleNested { return { - id: args.id ?? generateBundleId(), + id: args.id ?? humanId(), alias: args.alias ?? {}, messages: args.messages, }; diff --git a/inlang/source-code/sdk2/src/bundle-id/bundle-id.ts b/inlang/source-code/sdk2/src/human-id/human-id.ts similarity index 84% rename from inlang/source-code/sdk2/src/bundle-id/bundle-id.ts rename to inlang/source-code/sdk2/src/human-id/human-id.ts index 77d0494e90..f4295b9cd2 100644 --- a/inlang/source-code/sdk2/src/bundle-id/bundle-id.ts +++ b/inlang/source-code/sdk2/src/human-id/human-id.ts @@ -2,7 +2,7 @@ import murmurhash3 from "murmurhash3js"; import { adjectives, animals, verbs, adverbs } from "./words.js"; -export function generateBundleId() { +export function humanId() { return `${adjectives[Math.floor(Math.random() * 256)]}_${ adjectives[Math.floor(Math.random() * 256)] }_${animals[Math.floor(Math.random() * 256)]}_${ @@ -10,7 +10,7 @@ export function generateBundleId() { }`; } -export function isBundleId(id: string): boolean { +export function isHumanId(id: string): boolean { // naive implementation (good enough for now) return id.split("_").length === 4; } @@ -19,10 +19,10 @@ export function isBundleId(id: string): boolean { * The function generated a stable bundle id based on the input value. * * @example - * generateStableBundleId("login-button-header") // => "..." + * stableHumanId("login-button-header") // => "..." * */ -export function generateStableBundleId(value: string, offset: number = 0) { +export function stableHumanId(value: string, offset: number = 0) { // Seed value can be any arbitrary value const seed = 42; diff --git a/inlang/source-code/sdk2/src/bundle-id/words.test.ts b/inlang/source-code/sdk2/src/human-id/words.test.ts similarity index 100% rename from inlang/source-code/sdk2/src/bundle-id/words.test.ts rename to inlang/source-code/sdk2/src/human-id/words.test.ts diff --git a/inlang/source-code/sdk2/src/bundle-id/words.ts b/inlang/source-code/sdk2/src/human-id/words.ts similarity index 100% rename from inlang/source-code/sdk2/src/bundle-id/words.ts rename to inlang/source-code/sdk2/src/human-id/words.ts diff --git a/inlang/source-code/sdk2/src/index.ts b/inlang/source-code/sdk2/src/index.ts index 00f6ec8898..338868b856 100644 --- a/inlang/source-code/sdk2/src/index.ts +++ b/inlang/source-code/sdk2/src/index.ts @@ -8,12 +8,11 @@ export * from "./mock/index.js"; export * from "./helper.js"; export * from "./query-utilities/index.js"; export { - generateBundleId, + humanId, /** - * @deprecated use newBundleId instead + * @deprecated use `humandId()` instead (it's a rename) */ - generateBundleId as randomHumanId, -} from "./bundle-id/bundle-id.js"; +} from "./human-id/human-id.js"; export type { InlangDatabaseSchema } from "./database/schema.js"; export type { ResourceFile } from "./project/api.js"; export type { InlangPlugin } from "./plugin/schema.js"; diff --git a/inlang/source-code/sdk2/src/json-schema/old-v1-message/fromMessageV1.ts b/inlang/source-code/sdk2/src/json-schema/old-v1-message/fromMessageV1.ts index 0e908f65b9..da73dc1db1 100644 --- a/inlang/source-code/sdk2/src/json-schema/old-v1-message/fromMessageV1.ts +++ b/inlang/source-code/sdk2/src/json-schema/old-v1-message/fromMessageV1.ts @@ -1,9 +1,9 @@ -import { generateStableBundleId } from "../../bundle-id/bundle-id.js"; import type { BundleNested, MessageNested, Variant, } from "../../database/schema.js"; +import { stableHumanId } from "../../human-id/human-id.js"; import type { InlangPlugin } from "../../plugin/schema.js"; import type { Declaration, Expression, Pattern } from "../pattern.js"; import type { MessageV1, PatternV1 } from "./schemaV1.js"; @@ -17,7 +17,7 @@ export function fromMessageV1( messageV1: MessageV1, pluginKey: NonNullable ): BundleNested { - const bundleId = generateStableBundleId(messageV1.id); + const bundleId = stableHumanId(messageV1.id); const languages = [ ...new Set(messageV1.variants.map((variant) => variant.languageTag)),