@casekit/orm2-fixtures 0.0.1
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/package.json +49 -0
- package/src/index.ts +21 -0
- package/src/models/audit.ts +9 -0
- package/src/models/color.ts +8 -0
- package/src/models/counter.ts +5 -0
- package/src/models/friendship.ts +30 -0
- package/src/models/friendshipStats.ts +29 -0
- package/src/models/index.ts +21 -0
- package/src/models/kitchenSink.ts +77 -0
- package/src/models/like.ts +43 -0
- package/src/models/post.ts +66 -0
- package/src/models/user.ts +42 -0
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@casekit/orm2-fixtures",
|
|
3
|
+
"description": "",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"author": "",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"es-toolkit": "^1.39.3",
|
|
8
|
+
"@casekit/orm2-schema": "0.0.1",
|
|
9
|
+
"@casekit/sql": "0.0.1",
|
|
10
|
+
"@casekit/orm2-config": "0.0.1"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
|
|
14
|
+
"@types/node": "^24.0.3",
|
|
15
|
+
"@types/pg": "^8.15.4",
|
|
16
|
+
"@types/uuid": "^10.0.0",
|
|
17
|
+
"prettier": "^3.5.3",
|
|
18
|
+
"ts-essentials": "^10.1.1",
|
|
19
|
+
"typescript": "^5.8.3",
|
|
20
|
+
"typescript-eslint": "^8.34.1",
|
|
21
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
22
|
+
"@casekit/tsconfig": "0.0.1",
|
|
23
|
+
"@casekit/prettier-config": "0.0.1"
|
|
24
|
+
},
|
|
25
|
+
"exports": {
|
|
26
|
+
".": "./src/index.ts"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"/src"
|
|
30
|
+
],
|
|
31
|
+
"imports": {
|
|
32
|
+
"#*": "./src/*"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [],
|
|
35
|
+
"license": "ISC",
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"pg": "^8.13.1",
|
|
38
|
+
"zod": "^4.0.17"
|
|
39
|
+
},
|
|
40
|
+
"prettier": "@casekit/prettier-config",
|
|
41
|
+
"type": "module",
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "rm -rf ./build && tsc",
|
|
44
|
+
"format:check": "prettier --check .",
|
|
45
|
+
"format": "prettier --write .",
|
|
46
|
+
"lint": "eslint src --max-warnings 0",
|
|
47
|
+
"typecheck": "tsc --noEmit"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { snakeCase } from "es-toolkit";
|
|
2
|
+
|
|
3
|
+
import { Config } from "@casekit/orm2-schema";
|
|
4
|
+
|
|
5
|
+
import { models } from "./models/index.js";
|
|
6
|
+
|
|
7
|
+
export { models } from "./models/index.js";
|
|
8
|
+
|
|
9
|
+
export type Models = typeof models;
|
|
10
|
+
export type Operators = { where: Record<symbol, never> };
|
|
11
|
+
|
|
12
|
+
export const config = {
|
|
13
|
+
schema: "orm",
|
|
14
|
+
models,
|
|
15
|
+
naming: {
|
|
16
|
+
table: snakeCase,
|
|
17
|
+
column: snakeCase,
|
|
18
|
+
},
|
|
19
|
+
extensions: ["uuid-ossp"],
|
|
20
|
+
pool: true,
|
|
21
|
+
} satisfies Config;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ModelDefinition } from "@casekit/orm2-schema";
|
|
2
|
+
|
|
3
|
+
export const friendship = {
|
|
4
|
+
fields: {
|
|
5
|
+
userId: { type: "integer" },
|
|
6
|
+
friendId: { type: "integer" },
|
|
7
|
+
},
|
|
8
|
+
primaryKey: ["userId", "friendId"],
|
|
9
|
+
relations: {
|
|
10
|
+
user: {
|
|
11
|
+
type: "N:1",
|
|
12
|
+
model: "user",
|
|
13
|
+
fromField: "userId",
|
|
14
|
+
toField: "id",
|
|
15
|
+
},
|
|
16
|
+
friend: {
|
|
17
|
+
type: "N:1",
|
|
18
|
+
model: "user",
|
|
19
|
+
fromField: "friendId",
|
|
20
|
+
toField: "id",
|
|
21
|
+
},
|
|
22
|
+
stats: {
|
|
23
|
+
type: "N:1",
|
|
24
|
+
model: "friendshipStats",
|
|
25
|
+
fromField: ["userId", "friendId"],
|
|
26
|
+
toField: ["userId", "friendId"],
|
|
27
|
+
optional: true,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
} as const satisfies ModelDefinition;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ModelDefinition } from "@casekit/orm2-schema";
|
|
2
|
+
|
|
3
|
+
export const friendshipStats = {
|
|
4
|
+
fields: {
|
|
5
|
+
id: { type: "serial", primaryKey: true },
|
|
6
|
+
userId: { type: "integer" },
|
|
7
|
+
friendId: { type: "integer" },
|
|
8
|
+
messagesSent: { type: "integer", default: 0 },
|
|
9
|
+
likesGiven: { type: "integer", default: 0 },
|
|
10
|
+
},
|
|
11
|
+
foreignKeys: [
|
|
12
|
+
{
|
|
13
|
+
fields: ["userId", "friendId"],
|
|
14
|
+
references: {
|
|
15
|
+
model: "friendship",
|
|
16
|
+
fields: ["userId", "friendId"],
|
|
17
|
+
},
|
|
18
|
+
onDelete: "CASCADE",
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
relations: {
|
|
22
|
+
friendship: {
|
|
23
|
+
type: "N:1",
|
|
24
|
+
model: "friendship",
|
|
25
|
+
fromField: ["userId", "friendId"],
|
|
26
|
+
toField: ["userId", "friendId"],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
} as const satisfies ModelDefinition;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { audit } from "./audit.js";
|
|
2
|
+
import { color } from "./color.js";
|
|
3
|
+
import { counter } from "./counter.js";
|
|
4
|
+
import { friendship } from "./friendship.js";
|
|
5
|
+
import { friendshipStats } from "./friendshipStats.js";
|
|
6
|
+
import { kitchenSink } from "./kitchenSink.js";
|
|
7
|
+
import { like } from "./like.js";
|
|
8
|
+
import { post } from "./post.js";
|
|
9
|
+
import { user } from "./user.js";
|
|
10
|
+
|
|
11
|
+
export const models = {
|
|
12
|
+
audit,
|
|
13
|
+
counter,
|
|
14
|
+
user,
|
|
15
|
+
post,
|
|
16
|
+
like,
|
|
17
|
+
color,
|
|
18
|
+
friendship,
|
|
19
|
+
friendshipStats,
|
|
20
|
+
kitchenSink,
|
|
21
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ModelDefinition } from "@casekit/orm2-schema";
|
|
2
|
+
|
|
3
|
+
export const kitchenSink = {
|
|
4
|
+
fields: {
|
|
5
|
+
id: { type: "serial", primaryKey: true },
|
|
6
|
+
charField: { type: "char" },
|
|
7
|
+
characterField: { type: "character" },
|
|
8
|
+
characterNField: { type: "character(24)" },
|
|
9
|
+
varcharField: { type: "character varying" },
|
|
10
|
+
varcharNField: { type: "character varying(24)" },
|
|
11
|
+
textField: { type: "text" },
|
|
12
|
+
bitField: { type: "bit" },
|
|
13
|
+
bitNField: { type: "bit(3)" },
|
|
14
|
+
bitVaryingField: { type: "bit varying" },
|
|
15
|
+
bitVaryingNField: { type: "bit varying(3)" },
|
|
16
|
+
numericField: { type: "numeric" },
|
|
17
|
+
numericPrecisionField: { type: "numeric(5,2)" },
|
|
18
|
+
integerField: { type: "integer" },
|
|
19
|
+
bigintField: { type: "bigint" },
|
|
20
|
+
smallintField: { type: "smallint" },
|
|
21
|
+
serialField: { type: "serial" },
|
|
22
|
+
bigserialField: { type: "bigserial" },
|
|
23
|
+
smallserialField: { type: "smallserial" },
|
|
24
|
+
doublePrecisionField: { type: "double precision" },
|
|
25
|
+
realField: { type: "real" },
|
|
26
|
+
moneyField: { type: "money" },
|
|
27
|
+
booleanField: { type: "boolean" },
|
|
28
|
+
uuidField: { type: "uuid" },
|
|
29
|
+
dateField: { type: "date" },
|
|
30
|
+
timeField: { type: "time" },
|
|
31
|
+
timeWithPrecisionField: { type: "time(3)" },
|
|
32
|
+
timetzField: { type: "timetz" },
|
|
33
|
+
timeWithTzField: { type: "time with time zone" },
|
|
34
|
+
timestampField: { type: "timestamp" },
|
|
35
|
+
timestampWithPrecisionField: { type: "timestamp(6)" },
|
|
36
|
+
timestamptzField: { type: "timestamptz" },
|
|
37
|
+
timestampWithTzField: { type: "timestamp with time zone" },
|
|
38
|
+
// intervalField: { type: "interval" },
|
|
39
|
+
jsonField: { type: "json" },
|
|
40
|
+
jsonbField: { type: "jsonb" },
|
|
41
|
+
// pointField: { type: "point" },
|
|
42
|
+
lineField: { type: "line" },
|
|
43
|
+
lsegField: { type: "lseg" },
|
|
44
|
+
boxField: { type: "box" },
|
|
45
|
+
polygonField: { type: "polygon" },
|
|
46
|
+
// circleField: { type: "circle" },
|
|
47
|
+
cidrField: { type: "cidr" },
|
|
48
|
+
inetField: { type: "inet" },
|
|
49
|
+
macaddrField: { type: "macaddr" },
|
|
50
|
+
macaddr8Field: { type: "macaddr8" },
|
|
51
|
+
byteaField: { type: "bytea" },
|
|
52
|
+
xmlField: { type: "xml" },
|
|
53
|
+
pathField: { type: "path" },
|
|
54
|
+
tsqueryField: { type: "tsquery" },
|
|
55
|
+
tsvectorField: { type: "tsvector" },
|
|
56
|
+
int4rangeField: { type: "int4range" },
|
|
57
|
+
int8rangeField: { type: "int8range" },
|
|
58
|
+
numrangeField: { type: "numrange" },
|
|
59
|
+
tsrangeField: { type: "tsrange" },
|
|
60
|
+
tstzrangeField: { type: "tstzrange" },
|
|
61
|
+
daterangeField: { type: "daterange" },
|
|
62
|
+
int2vectorField: { type: "int2vector" },
|
|
63
|
+
oidField: { type: "oid" },
|
|
64
|
+
pglsnField: { type: "pg_lsn" },
|
|
65
|
+
regclassField: { type: "regclass" },
|
|
66
|
+
regnamespaceField: { type: "regnamespace" },
|
|
67
|
+
regprocField: { type: "regproc" },
|
|
68
|
+
regprocedureField: { type: "regprocedure" },
|
|
69
|
+
regroleField: { type: "regrole" },
|
|
70
|
+
regtypeField: { type: "regtype" },
|
|
71
|
+
tidField: { type: "tid" },
|
|
72
|
+
xidField: { type: "xid" },
|
|
73
|
+
txidSnapshotField: { type: "txid_snapshot" },
|
|
74
|
+
arrayField: { type: "text[]" },
|
|
75
|
+
multiArrayField: { type: "text[][][]" },
|
|
76
|
+
},
|
|
77
|
+
} as const satisfies ModelDefinition;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ModelDefinition } from "@casekit/orm2-schema";
|
|
2
|
+
import { sql } from "@casekit/sql";
|
|
3
|
+
|
|
4
|
+
export const like = {
|
|
5
|
+
fields: {
|
|
6
|
+
id: { type: "serial", primaryKey: true },
|
|
7
|
+
userId: {
|
|
8
|
+
type: "integer",
|
|
9
|
+
references: {
|
|
10
|
+
model: "user",
|
|
11
|
+
field: "id",
|
|
12
|
+
onDelete: "CASCADE",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
postId: {
|
|
16
|
+
type: "integer",
|
|
17
|
+
references: {
|
|
18
|
+
model: "post",
|
|
19
|
+
field: "id",
|
|
20
|
+
onDelete: "CASCADE",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
createdAt: { type: "timestamp", default: sql`now()` },
|
|
24
|
+
deletedAt: { type: "timestamp", nullable: true },
|
|
25
|
+
},
|
|
26
|
+
uniqueConstraints: [
|
|
27
|
+
{ fields: ["userId", "postId"], where: sql`deleted_at IS NULL` },
|
|
28
|
+
],
|
|
29
|
+
relations: {
|
|
30
|
+
user: {
|
|
31
|
+
type: "N:1",
|
|
32
|
+
model: "user",
|
|
33
|
+
fromField: "userId",
|
|
34
|
+
toField: "id",
|
|
35
|
+
},
|
|
36
|
+
post: {
|
|
37
|
+
type: "N:1",
|
|
38
|
+
model: "post",
|
|
39
|
+
fromField: "postId",
|
|
40
|
+
toField: "id",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
} as const satisfies ModelDefinition;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
import { ModelDefinition } from "@casekit/orm2-schema";
|
|
4
|
+
import { sql } from "@casekit/sql";
|
|
5
|
+
|
|
6
|
+
export const post = {
|
|
7
|
+
fields: {
|
|
8
|
+
id: { type: "serial", primaryKey: true },
|
|
9
|
+
title: { type: "text" },
|
|
10
|
+
content: { type: "text" },
|
|
11
|
+
tags: { type: "text[]", default: "{}" },
|
|
12
|
+
authorId: {
|
|
13
|
+
type: "integer",
|
|
14
|
+
references: {
|
|
15
|
+
model: "user",
|
|
16
|
+
field: "id",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
backgroundColorValue: {
|
|
20
|
+
type: "text",
|
|
21
|
+
nullable: true,
|
|
22
|
+
references: {
|
|
23
|
+
model: "color",
|
|
24
|
+
field: "hex",
|
|
25
|
+
onDelete: "SET NULL",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
metadata: {
|
|
29
|
+
type: "jsonb",
|
|
30
|
+
default: "{}",
|
|
31
|
+
zodSchema: z.object({
|
|
32
|
+
foo: z.enum(["a", "b", "c"]),
|
|
33
|
+
bar: z.array(
|
|
34
|
+
z.object({
|
|
35
|
+
baz: z.enum(["good", "bad", "indifferent"]),
|
|
36
|
+
quux: z.boolean(),
|
|
37
|
+
}),
|
|
38
|
+
),
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
createdAt: { type: "timestamp", default: sql`now()` },
|
|
42
|
+
publishedAt: { type: "timestamp", nullable: true },
|
|
43
|
+
deletedAt: { type: "timestamp", nullable: true },
|
|
44
|
+
},
|
|
45
|
+
relations: {
|
|
46
|
+
author: {
|
|
47
|
+
type: "N:1",
|
|
48
|
+
model: "user",
|
|
49
|
+
fromField: "authorId",
|
|
50
|
+
toField: "id",
|
|
51
|
+
},
|
|
52
|
+
backgroundColor: {
|
|
53
|
+
type: "N:1",
|
|
54
|
+
model: "color",
|
|
55
|
+
fromField: "backgroundColorValue",
|
|
56
|
+
toField: "hex",
|
|
57
|
+
optional: true,
|
|
58
|
+
},
|
|
59
|
+
likes: {
|
|
60
|
+
type: "1:N",
|
|
61
|
+
model: "like",
|
|
62
|
+
fromField: "id",
|
|
63
|
+
toField: "postId",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
} as const satisfies ModelDefinition;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
import { ModelDefinition } from "@casekit/orm2-schema";
|
|
4
|
+
import { sql } from "@casekit/sql";
|
|
5
|
+
|
|
6
|
+
export const user = {
|
|
7
|
+
fields: {
|
|
8
|
+
id: { type: "serial", primaryKey: true },
|
|
9
|
+
name: { type: "text" },
|
|
10
|
+
email: { type: "text", zodSchema: z.email() },
|
|
11
|
+
role: { type: "text", zodSchema: z.enum(["user", "admin"]) },
|
|
12
|
+
preferences: { type: "jsonb", default: "{}" },
|
|
13
|
+
createdAt: { type: "timestamp", default: sql`now()` },
|
|
14
|
+
deletedAt: { type: "timestamp", nullable: true },
|
|
15
|
+
},
|
|
16
|
+
uniqueConstraints: [
|
|
17
|
+
{ fields: ["email", "deletedAt"], nullsNotDistinct: true },
|
|
18
|
+
],
|
|
19
|
+
relations: {
|
|
20
|
+
posts: {
|
|
21
|
+
type: "1:N",
|
|
22
|
+
model: "post",
|
|
23
|
+
fromField: "id",
|
|
24
|
+
toField: "authorId",
|
|
25
|
+
},
|
|
26
|
+
friends: {
|
|
27
|
+
type: "N:N",
|
|
28
|
+
model: "user",
|
|
29
|
+
through: {
|
|
30
|
+
model: "friendship",
|
|
31
|
+
fromRelation: "user",
|
|
32
|
+
toRelation: "friend",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
friendships: {
|
|
36
|
+
type: "1:N",
|
|
37
|
+
model: "friendship",
|
|
38
|
+
fromField: "id",
|
|
39
|
+
toField: "userId",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
} as const satisfies ModelDefinition;
|