diff --git a/bun.lock b/bun.lock index 642fcde..b9484d7 100644 --- a/bun.lock +++ b/bun.lock @@ -26,7 +26,7 @@ }, "app": { "name": "bknd", - "version": "0.13.1-rc.0", + "version": "0.14.0-rc.0", "bin": "./dist/cli/index.js", "dependencies": { "@cfworker/json-schema": "^4.1.1", @@ -45,6 +45,7 @@ "bcryptjs": "^3.0.2", "dayjs": "^1.11.13", "fast-xml-parser": "^5.0.8", + "hono": "^4.7.11", "json-schema-form-react": "^0.0.2", "json-schema-library": "10.0.0-rc7", "json-schema-to-ts": "^3.1.1", @@ -82,7 +83,6 @@ "autoprefixer": "^10.4.21", "clsx": "^2.1.1", "dotenv": "^16.4.7", - "hono": "4.7.11", "jotai": "^2.12.2", "jsdom": "^26.0.0", "jsonv-ts": "^0.1.0", diff --git a/packages/postgres/src/PostgresConnection.ts b/packages/postgres/src/PostgresConnection.ts index db219fd..9ea1d2c 100644 --- a/packages/postgres/src/PostgresConnection.ts +++ b/packages/postgres/src/PostgresConnection.ts @@ -32,7 +32,13 @@ export abstract class PostgresConnection extends Connection { override getFieldSchema(spec: FieldSpec): SchemaResponse { this.validateFieldSpecType(spec.type); - let type: ColumnDataType = spec.primary ? "serial" : spec.type; + let type: ColumnDataType = spec.type; + + if (spec.primary) { + if (spec.type === "integer") { + type = "serial"; + } + } switch (spec.type) { case "blob": diff --git a/packages/postgres/test/suite.ts b/packages/postgres/test/suite.ts index bf53337..0d4feec 100644 --- a/packages/postgres/test/suite.ts +++ b/packages/postgres/test/suite.ts @@ -151,5 +151,47 @@ export function testSuite(config: TestSuiteConfig) { expect(result[0].comments[0].content).toBe("Hello"); expect(result[1].comments.length).toBe(0); }); + + it("should support uuid", async () => { + const schema = proto.em( + { + posts: proto.entity( + "posts", + { + title: proto.text().required(), + content: proto.text(), + }, + { + primary_format: "uuid", + }, + ), + comments: proto.entity("comments", { + content: proto.text(), + }), + }, + (fns, s) => { + fns.relation(s.comments).manyToOne(s.posts); + fns.index(s.posts).on(["title"], true); + }, + ); + + const app = createApp({ + connection, + initialConfig: { + data: schema.toJSON(), + }, + }); + + await app.build(); + const config = app.toJSON(); + // @ts-expect-error + expect(config.data.entities?.posts.fields?.id.config?.format).toBe("uuid"); + + const em = app.em; + const mutator = em.mutator(em.entity("posts")); + const data = await mutator.insertOne({ title: "Hello", content: "World" }); + expect(data.data.id).toBeString(); + expect(String(data.data.id).length).toBe(36); + }); }); }