cogsbox-shape 0.5.193 → 0.5.194
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -3
- package/cogsbox-shape-db/dist/connect.d.ts +2 -4
- package/dist/schema.d.ts +37 -3
- package/dist/schema.js +67 -3
- package/dist/vitest/fullSchema.test.d.ts +1 -0
- package/dist/vitest/fullSchema.test.js +1367 -0
- package/dist/vitest/generateSQL.test.d.ts +1 -0
- package/dist/vitest/generateSQL.test.js +70 -0
- package/dist/vitest/packageExports.test.d.ts +1 -0
- package/dist/vitest/packageExports.test.js +15 -0
- package/package.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { mkdtemp, rm } from "fs/promises";
|
|
2
|
+
import { tmpdir } from "os";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { generateSQL } from "../generateSQL.js";
|
|
6
|
+
import { s, schema } from "../schema.js";
|
|
7
|
+
async function withOutputFile(fn) {
|
|
8
|
+
const dir = await mkdtemp(join(tmpdir(), "cogsbox-shape-sql-"));
|
|
9
|
+
try {
|
|
10
|
+
return await fn(join(dir, "schema.sql"));
|
|
11
|
+
}
|
|
12
|
+
finally {
|
|
13
|
+
await rm(dir, { recursive: true, force: true });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
describe("generateSQL dialect columns", () => {
|
|
17
|
+
it("generates SQLite enum columns as text with a check constraint", async () => {
|
|
18
|
+
const posts = schema({
|
|
19
|
+
_tableName: "posts",
|
|
20
|
+
id: s.sqlite({ type: "int", pk: true }),
|
|
21
|
+
status: s.sqlite({
|
|
22
|
+
type: "enum",
|
|
23
|
+
values: ["draft", "published", "archived"],
|
|
24
|
+
default: "draft",
|
|
25
|
+
}),
|
|
26
|
+
});
|
|
27
|
+
const sql = await withOutputFile((path) => generateSQL({ posts }, path));
|
|
28
|
+
expect(sql).toContain("id INTEGER PRIMARY KEY");
|
|
29
|
+
expect(sql).toContain("status TEXT NOT NULL DEFAULT 'draft' CHECK (status IN ('draft', 'published', 'archived'))");
|
|
30
|
+
});
|
|
31
|
+
it("generates MySQL enum columns using native ENUM", async () => {
|
|
32
|
+
const posts = schema({
|
|
33
|
+
_tableName: "posts",
|
|
34
|
+
id: s.mysql({ type: "int", pk: true }),
|
|
35
|
+
status: s.mysql({
|
|
36
|
+
type: "enum",
|
|
37
|
+
values: ["draft", "published", "archived"],
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
const sql = await withOutputFile((path) => generateSQL({ posts }, path));
|
|
41
|
+
expect(sql).toContain("id INTEGER PRIMARY KEY AUTO_INCREMENT");
|
|
42
|
+
expect(sql).toContain("status ENUM('draft', 'published', 'archived') NOT NULL");
|
|
43
|
+
});
|
|
44
|
+
it("generates Postgres enum type DDL before table DDL", async () => {
|
|
45
|
+
const posts = schema({
|
|
46
|
+
_tableName: "posts",
|
|
47
|
+
id: s.postgres({ type: "int", pk: true }),
|
|
48
|
+
status: s.postgres({
|
|
49
|
+
type: "enum",
|
|
50
|
+
name: "post_status",
|
|
51
|
+
values: ["draft", "published", "archived"],
|
|
52
|
+
}),
|
|
53
|
+
});
|
|
54
|
+
const sql = await withOutputFile((path) => generateSQL({ posts }, path));
|
|
55
|
+
expect(sql).toContain("CREATE TYPE post_status AS ENUM ('draft', 'published', 'archived');");
|
|
56
|
+
expect(sql).toContain("status post_status NOT NULL");
|
|
57
|
+
expect(sql.indexOf("CREATE TYPE post_status")).toBeLessThan(sql.indexOf("CREATE TABLE posts"));
|
|
58
|
+
});
|
|
59
|
+
it("rejects mixed SQL dialects in the same table", async () => {
|
|
60
|
+
const posts = schema({
|
|
61
|
+
_tableName: "posts",
|
|
62
|
+
id: s.sqlite({ type: "int", pk: true }),
|
|
63
|
+
status: s.mysql({
|
|
64
|
+
type: "enum",
|
|
65
|
+
values: ["draft", "published"],
|
|
66
|
+
}),
|
|
67
|
+
});
|
|
68
|
+
await expect(withOutputFile((path) => generateSQL({ posts }, path))).rejects.toThrow(/Mixed SQL dialects/);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
describe("package exports", () => {
|
|
3
|
+
it("exposes the root cogsbox-shape entry at runtime", async () => {
|
|
4
|
+
const pkg = await import("cogsbox-shape");
|
|
5
|
+
expect(pkg.s).toBeDefined();
|
|
6
|
+
expect(pkg.schema).toBeDefined();
|
|
7
|
+
expect(pkg.createSchemaBox).toBeDefined();
|
|
8
|
+
});
|
|
9
|
+
it("exposes db subpath entries at runtime", async () => {
|
|
10
|
+
const dbPkg = await import("cogsbox-shape/db");
|
|
11
|
+
const sqlitePkg = await import("cogsbox-shape/db/sqlite");
|
|
12
|
+
expect(dbPkg.connect).toBeDefined();
|
|
13
|
+
expect(sqlitePkg.createSqliteDb).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.194",
|
|
4
4
|
"description": "A TypeScript library for creating type-safe database schemas with Zod validation, SQL type definitions, and automatic client/server transformations. Unifies client, server, and database types through a single schema definition, with built-in support for relationships and serialization.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"lint": "eslint src --ext .ts",
|
|
15
15
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
16
16
|
"test": "vitest ",
|
|
17
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p src/vitest/tsconfig.json",
|
|
17
18
|
"playground": "pnpm --filter cogsbox-shape-playground dev"
|
|
18
19
|
},
|
|
19
20
|
"bin": {
|