@casekit/orm2-config 0.0.0-20250331202540 → 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 +19 -19
- package/{build/index.d.ts → src/index.ts} +7 -1
- package/{build/normalize/defaultZodSchema.test.js → src/normalize/defaultZodSchema.test.ts} +13 -5
- package/{build/normalize/defaultZodSchema.js → src/normalize/defaultZodSchema.ts} +22 -30
- package/{build/normalize/getColumns.test.js → src/normalize/getColumns.test.ts} +17 -4
- package/{build/normalize/getColumns.js → src/normalize/getColumns.ts} +6 -1
- package/{build/normalize/normalizeConfig.test.js → src/normalize/normalizeConfig.test.ts} +70 -24
- package/{build/normalize/normalizeConfig.js → src/normalize/normalizeConfig.ts} +7 -2
- package/{build/normalize/normalizeField.test.js → src/normalize/normalizeField.test.ts} +12 -7
- package/src/normalize/normalizeField.ts +16 -0
- package/{build/normalize/normalizeForeignKeys.test.js → src/normalize/normalizeForeignKeys.test.ts} +26 -7
- package/src/normalize/normalizeForeignKeys.ts +89 -0
- package/{build/normalize/normalizeModel.test.js → src/normalize/normalizeModel.test.ts} +42 -18
- package/{build/normalize/normalizeModel.js → src/normalize/normalizeModel.ts} +8 -1
- package/{build/normalize/normalizePrimaryKey.test.js → src/normalize/normalizePrimaryKey.test.ts} +31 -7
- package/src/normalize/normalizePrimaryKey.ts +30 -0
- package/{build/normalize/normalizeRelations.test.js → src/normalize/normalizeRelations.test.ts} +38 -9
- package/{build/normalize/normalizeRelations.js → src/normalize/normalizeRelations.ts} +34 -12
- package/{build/normalize/normalizeUniqueConstraints.test.js → src/normalize/normalizeUniqueConstraints.test.ts} +46 -15
- package/src/normalize/normalizeUniqueConstraints.ts +58 -0
- package/src/normalize/populateField.test.ts +253 -0
- package/{build/normalize/populateField.js → src/normalize/populateField.ts} +9 -1
- package/{build/normalize/populateModels.test.js → src/normalize/populateModels.test.ts} +35 -14
- package/{build/normalize/populateModels.js → src/normalize/populateModels.ts} +11 -2
- package/{build/types/NormalizedConfig.d.ts → src/types/NormalizedConfig.ts} +8 -1
- package/{build/types/NormalizedFieldDefinition.d.ts → src/types/NormalizedFieldDefinition.ts} +2 -1
- package/{build/types/NormalizedModelDefinition.d.ts → src/types/NormalizedModelDefinition.ts} +1 -0
- package/{build/types/NormalizedRelationDefinition.d.ts → src/types/NormalizedRelationDefinition.ts} +7 -1
- package/{build/types/NormalizedUniqueConstraintDefinition.d.ts → src/types/NormalizedUniqueConstraintDefinition.ts} +1 -0
- package/{build/types/PopulatedFieldDefinition.d.ts → src/types/PopulatedFieldDefinition.ts} +1 -0
- package/{build/types/PopulatedModelDefinition.d.ts → src/types/PopulatedModelDefinition.ts} +2 -0
- package/src/util.ts +38 -0
- package/build/index.js +0 -4
- package/build/normalize/defaultZodSchema.d.ts +0 -8
- package/build/normalize/defaultZodSchema.test.d.ts +0 -1
- package/build/normalize/getColumns.d.ts +0 -2
- package/build/normalize/getColumns.test.d.ts +0 -1
- package/build/normalize/normalizeConfig.d.ts +0 -3
- package/build/normalize/normalizeConfig.test.d.ts +0 -1
- package/build/normalize/normalizeField.d.ts +0 -3
- package/build/normalize/normalizeField.js +0 -11
- package/build/normalize/normalizeField.test.d.ts +0 -1
- package/build/normalize/normalizeForeignKeys.d.ts +0 -5
- package/build/normalize/normalizeForeignKeys.js +0 -50
- package/build/normalize/normalizeForeignKeys.test.d.ts +0 -1
- package/build/normalize/normalizeModel.d.ts +0 -3
- package/build/normalize/normalizeModel.test.d.ts +0 -1
- package/build/normalize/normalizePrimaryKey.d.ts +0 -3
- package/build/normalize/normalizePrimaryKey.js +0 -18
- package/build/normalize/normalizePrimaryKey.test.d.ts +0 -1
- package/build/normalize/normalizeRelations.d.ts +0 -3
- package/build/normalize/normalizeRelations.test.d.ts +0 -1
- package/build/normalize/normalizeUniqueConstraints.d.ts +0 -5
- package/build/normalize/normalizeUniqueConstraints.js +0 -29
- package/build/normalize/normalizeUniqueConstraints.test.d.ts +0 -1
- package/build/normalize/populateField.d.ts +0 -3
- package/build/normalize/populateField.test.d.ts +0 -1
- package/build/normalize/populateField.test.js +0 -198
- package/build/normalize/populateModels.d.ts +0 -3
- package/build/normalize/populateModels.test.d.ts +0 -1
- package/build/types/NormalizedConfig.js +0 -1
- package/build/types/NormalizedFieldDefinition.js +0 -1
- package/build/types/NormalizedForeignKeyDefinition.js +0 -1
- package/build/types/NormalizedModelDefinition.js +0 -1
- package/build/types/NormalizedPrimaryKey.js +0 -1
- package/build/types/NormalizedRelationDefinition.js +0 -1
- package/build/types/NormalizedUniqueConstraintDefinition.js +0 -1
- package/build/types/PopulatedFieldDefinition.js +0 -1
- package/build/types/PopulatedModelDefinition.js +0 -1
- package/build/util.d.ts +0 -6
- package/build/util.js +0 -21
- /package/{build/types/NormalizedForeignKeyDefinition.d.ts → src/types/NormalizedForeignKeyDefinition.ts} +0 -0
- /package/{build/types/NormalizedPrimaryKey.d.ts → src/types/NormalizedPrimaryKey.ts} +0 -0
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import { snakeCase } from "es-toolkit";
|
|
2
|
-
import { describe, expect, test } from "vitest";
|
|
3
|
-
import { ZodSchema, z } from "zod";
|
|
4
|
-
import { populateField } from "./populateField.js";
|
|
5
|
-
describe("populateField", () => {
|
|
6
|
-
test("populates minimal field definition with defaults", () => {
|
|
7
|
-
const result = populateField({
|
|
8
|
-
models: {
|
|
9
|
-
user: {
|
|
10
|
-
fields: {
|
|
11
|
-
name: { type: "text" },
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
}, { type: "text" }, "name");
|
|
16
|
-
expect(result).toEqual({
|
|
17
|
-
name: "name",
|
|
18
|
-
column: "name",
|
|
19
|
-
type: "text",
|
|
20
|
-
zodSchema: expect.any(ZodSchema),
|
|
21
|
-
default: null,
|
|
22
|
-
references: null,
|
|
23
|
-
nullable: false,
|
|
24
|
-
unique: false,
|
|
25
|
-
primaryKey: false,
|
|
26
|
-
provided: false,
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
test("applies naming function to column name when provided", () => {
|
|
30
|
-
const result = populateField({
|
|
31
|
-
naming: { column: snakeCase },
|
|
32
|
-
models: {
|
|
33
|
-
user: {
|
|
34
|
-
fields: {
|
|
35
|
-
fullName: { type: "text" },
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
}, { type: "text" }, "fullName");
|
|
40
|
-
expect(result.column).toBe("full_name");
|
|
41
|
-
});
|
|
42
|
-
test("uses explicit column name over naming function", () => {
|
|
43
|
-
const result = populateField({
|
|
44
|
-
naming: { column: snakeCase },
|
|
45
|
-
models: {
|
|
46
|
-
user: {
|
|
47
|
-
fields: {
|
|
48
|
-
fullName: { type: "text", column: "explicit_name" },
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
}, { type: "text", column: "explicit_name" }, "fullName");
|
|
53
|
-
expect(result.column).toBe("explicit_name");
|
|
54
|
-
});
|
|
55
|
-
test("preserves custom zodSchema", () => {
|
|
56
|
-
const customSchema = z.string().email();
|
|
57
|
-
const result = populateField({
|
|
58
|
-
models: {
|
|
59
|
-
user: {
|
|
60
|
-
fields: {
|
|
61
|
-
email: { type: "text", zodSchema: customSchema },
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
}, { type: "text", zodSchema: customSchema }, "email");
|
|
66
|
-
expect(result.zodSchema).toEqual(customSchema);
|
|
67
|
-
});
|
|
68
|
-
test("preserves all provided values", () => {
|
|
69
|
-
const result = populateField({
|
|
70
|
-
models: {
|
|
71
|
-
user: {
|
|
72
|
-
fields: {
|
|
73
|
-
id: {
|
|
74
|
-
type: "integer",
|
|
75
|
-
column: "custom_id",
|
|
76
|
-
zodSchema: z.number().min(1),
|
|
77
|
-
default: 42,
|
|
78
|
-
references: { model: "other", field: "id" },
|
|
79
|
-
nullable: true,
|
|
80
|
-
unique: true,
|
|
81
|
-
primaryKey: true,
|
|
82
|
-
provided: true,
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
other: {
|
|
87
|
-
fields: {
|
|
88
|
-
id: { type: "serial", primaryKey: true },
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
}, {
|
|
93
|
-
type: "integer",
|
|
94
|
-
column: "custom_id",
|
|
95
|
-
zodSchema: z.number().min(1),
|
|
96
|
-
default: 42,
|
|
97
|
-
references: { model: "other", field: "id" },
|
|
98
|
-
nullable: true,
|
|
99
|
-
unique: true,
|
|
100
|
-
primaryKey: true,
|
|
101
|
-
provided: true,
|
|
102
|
-
}, "id");
|
|
103
|
-
expect(result).toEqual({
|
|
104
|
-
name: "id",
|
|
105
|
-
type: "integer",
|
|
106
|
-
column: "custom_id",
|
|
107
|
-
zodSchema: expect.any(ZodSchema),
|
|
108
|
-
default: 42,
|
|
109
|
-
references: { model: "other", field: "id" },
|
|
110
|
-
nullable: true,
|
|
111
|
-
unique: true,
|
|
112
|
-
primaryKey: true,
|
|
113
|
-
provided: true,
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
test("handles array types", () => {
|
|
117
|
-
const result = populateField({
|
|
118
|
-
models: {
|
|
119
|
-
post: {
|
|
120
|
-
fields: {
|
|
121
|
-
tags: { type: "text[]" },
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
}, { type: "text[]" }, "tags");
|
|
126
|
-
expect(result).toEqual({
|
|
127
|
-
name: "tags",
|
|
128
|
-
column: "tags",
|
|
129
|
-
type: "text[]",
|
|
130
|
-
zodSchema: expect.any(ZodSchema),
|
|
131
|
-
default: null,
|
|
132
|
-
references: null,
|
|
133
|
-
nullable: false,
|
|
134
|
-
unique: false,
|
|
135
|
-
primaryKey: false,
|
|
136
|
-
provided: false,
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
test("handles nullable fields", () => {
|
|
140
|
-
const result = populateField({
|
|
141
|
-
models: {
|
|
142
|
-
post: {
|
|
143
|
-
fields: {
|
|
144
|
-
description: { type: "text", nullable: true },
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
}, { type: "text", nullable: true }, "description");
|
|
149
|
-
expect(result.nullable).toBe(true);
|
|
150
|
-
});
|
|
151
|
-
test("handles fields with defaults", () => {
|
|
152
|
-
const result = populateField({
|
|
153
|
-
models: {
|
|
154
|
-
user: {
|
|
155
|
-
fields: {
|
|
156
|
-
active: { type: "boolean", default: false },
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
}, { type: "boolean", default: false }, "active");
|
|
161
|
-
expect(result.default).toBe(false);
|
|
162
|
-
});
|
|
163
|
-
test("handles fields with foreign keys", () => {
|
|
164
|
-
const result = populateField({
|
|
165
|
-
models: {
|
|
166
|
-
user: {
|
|
167
|
-
fields: {
|
|
168
|
-
id: { type: "serial", primaryKey: true },
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
post: {
|
|
172
|
-
fields: {
|
|
173
|
-
userId: {
|
|
174
|
-
type: "integer",
|
|
175
|
-
references: {
|
|
176
|
-
model: "user",
|
|
177
|
-
field: "id",
|
|
178
|
-
onDelete: "CASCADE",
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
}, {
|
|
185
|
-
type: "integer",
|
|
186
|
-
references: {
|
|
187
|
-
model: "user",
|
|
188
|
-
field: "id",
|
|
189
|
-
onDelete: "CASCADE",
|
|
190
|
-
},
|
|
191
|
-
}, "userId");
|
|
192
|
-
expect(result.references).toEqual({
|
|
193
|
-
model: "user",
|
|
194
|
-
field: "id",
|
|
195
|
-
onDelete: "CASCADE",
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/build/util.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { NormalizedFieldDefinition } from "./types/NormalizedFieldDefinition.js";
|
|
2
|
-
import { NormalizedModelDefinition } from "./types/NormalizedModelDefinition.js";
|
|
3
|
-
import { NormalizedRelationDefinition } from "./types/NormalizedRelationDefinition.js";
|
|
4
|
-
export declare const getModel: (models: Record<string, NormalizedModelDefinition>, name: string) => NormalizedModelDefinition;
|
|
5
|
-
export declare const getRelation: (model: NormalizedModelDefinition, name: string) => NormalizedRelationDefinition;
|
|
6
|
-
export declare const getField: (model: NormalizedModelDefinition, name: string) => NormalizedFieldDefinition;
|
package/build/util.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export const getModel = (models, name) => {
|
|
2
|
-
const model = models[name];
|
|
3
|
-
if (!model) {
|
|
4
|
-
throw new Error(`Model "${name}" not found in config`);
|
|
5
|
-
}
|
|
6
|
-
return model;
|
|
7
|
-
};
|
|
8
|
-
export const getRelation = (model, name) => {
|
|
9
|
-
const relation = model.relations[name];
|
|
10
|
-
if (!relation) {
|
|
11
|
-
throw new Error(`Relation "${name}" not found in model "${model.name}"`);
|
|
12
|
-
}
|
|
13
|
-
return relation;
|
|
14
|
-
};
|
|
15
|
-
export const getField = (model, name) => {
|
|
16
|
-
const field = model.fields[name];
|
|
17
|
-
if (!field) {
|
|
18
|
-
throw new Error(`Field "${name}" not found in model "${model.name}"`);
|
|
19
|
-
}
|
|
20
|
-
return field;
|
|
21
|
-
};
|
|
File without changes
|
|
File without changes
|