Skip to content

Commit 0b8c220

Browse files
committed
feat: Add minimal User schema and model to be expanded in plugins
1 parent 3c39822 commit 0b8c220

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { validateDriverModel } from '@db/driver'
2+
import { User } from '../schemas/User.schema'
3+
import { createSchemaModel } from '@db/driver'
4+
5+
/* --- Model ----------------------------------------------------------------------------------- */
6+
7+
export const Users = createSchemaModel(User)
8+
9+
/* --- Drivers --------------------------------------------------------------------------------- */
10+
11+
export const driverModel = validateDriverModel(Users.driver)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { z, schema } from '@green-stack/schemas'
2+
import { partials } from '@app/registries/schemas.partials'
3+
4+
/* --- Description ----------------------------------------------------------------------------- */
5+
6+
const d = "Essential user info"
7+
8+
/** --- User ----------------------------------------------------------------------------------- */
9+
/** -i- Essential user info */
10+
export const User = schema('User', {
11+
12+
userId: z
13+
.string()
14+
.index()
15+
.unique()
16+
.describe('Auth provider sub or user ID'),
17+
email: z
18+
.string()
19+
.unique()
20+
.describe('Primary Github email used during OAuth'),
21+
22+
// -i- Partial fields from other modules / features / packages / plugins
23+
24+
...partials.User,
25+
26+
}).describe(d)
27+
28+
/* --- Type Alias ------------------------------------------------------------------------------ */
29+
30+
export type User = z.input<typeof User>

packages/@green-stack-core/scripts/collect-schemas.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ const collectSchemas = () => {
4646
if (isEmpty(allPartialSchemaPaths)) {
4747
fs.writeFileSync('../../packages/@registries/schemas.partials.ts', [
4848

49-
genMsg,
50-
`import { z } from '@green-stack/schemas'`,
49+
`${genMsg}import { z } from '@green-stack/schemas'`,
5150

52-
createDivider('Exports'),
51+
`${createDivider('Exports')}\n`,
5352

54-
`export const partials = {} as Record<string, z.ZodRawShape>`,
53+
`export const partials = {} as Record<string, z.ZodRawShape>\n`,
5554

5655
].join('\n'))
5756
return
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
// -i- Auto generated with "npx turbo run @green-stack/core#collect:schemas"
2+
export { User } from '@app/core/schemas/User.schema'
23
export { HealthCheckOutput } from '@app/core/schemas/HealthCheckOutput'
34
export { HealthCheckInput } from '@app/core/schemas/HealthCheckInput'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// -i- Auto generated with "npx turbo run @green-stack/core#collect:schemas"
2-
32
import { z } from '@green-stack/schemas'
43
/* --- Exports --------------------------------------------------------------------------------- */
5-
export const partials = {} as Record<string, z.ZodRawShape>
4+
5+
export const partials = {} as Record<string, z.ZodRawShape>

0 commit comments

Comments
 (0)