-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate json-schema based on Prisma schema
Showing
14 changed files
with
765 additions
and
94 deletions.
There are no files selected for viewing
143 changes: 143 additions & 0 deletions
143
libs/api/core/data-access/src/prisma/json-schema/json-schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"definitions": { | ||
"User": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "string" | ||
}, | ||
"createdAt": { | ||
"type": "string", | ||
"format": "date-time" | ||
}, | ||
"updatedAt": { | ||
"type": "string", | ||
"format": "date-time" | ||
}, | ||
"role": { | ||
"type": "string", | ||
"enum": ["Admin", "User"] | ||
}, | ||
"developer": { | ||
"type": "boolean" | ||
}, | ||
"email": { | ||
"type": "string" | ||
}, | ||
"username": { | ||
"type": "string" | ||
}, | ||
"password": { | ||
"type": ["string", "null"] | ||
}, | ||
"firstName": { | ||
"type": ["string", "null"] | ||
}, | ||
"lastName": { | ||
"type": ["string", "null"] | ||
}, | ||
"avatarUrl": { | ||
"type": ["string", "null"] | ||
}, | ||
"location": { | ||
"type": ["string", "null"] | ||
}, | ||
"phone": { | ||
"type": ["string", "null"] | ||
}, | ||
"bio": { | ||
"type": ["string", "null"] | ||
}, | ||
"products": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/Product" | ||
} | ||
} | ||
} | ||
}, | ||
"Product": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "string" | ||
}, | ||
"createdAt": { | ||
"type": "string", | ||
"format": "date-time" | ||
}, | ||
"updatedAt": { | ||
"type": "string", | ||
"format": "date-time" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"description": { | ||
"type": "string" | ||
}, | ||
"price": { | ||
"type": "integer" | ||
}, | ||
"owner": { | ||
"anyOf": [ | ||
{ | ||
"$ref": "#/definitions/User" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
}, | ||
"category": { | ||
"anyOf": [ | ||
{ | ||
"$ref": "#/definitions/Category" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"Category": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "string" | ||
}, | ||
"createdAt": { | ||
"type": "string", | ||
"format": "date-time" | ||
}, | ||
"updatedAt": { | ||
"type": "string", | ||
"format": "date-time" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"products": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/Product" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"type": "object", | ||
"properties": { | ||
"user": { | ||
"$ref": "#/definitions/User" | ||
}, | ||
"product": { | ||
"$ref": "#/definitions/Product" | ||
}, | ||
"category": { | ||
"$ref": "#/definitions/Category" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { LoadChildren, Route } from '@angular/router' | ||
|
||
export function route(r: Route): Route { | ||
return { path: '', ...r } | ||
} | ||
|
||
export function routeRedirect(path: string): Route { | ||
return route({ pathMatch: 'full', redirectTo: path }) | ||
} | ||
|
||
export function routeLazy(path: string, loadChildren: LoadChildren): Route { | ||
return route({ path, loadChildren }) | ||
} | ||
|
||
export function routeChildren(component: any, children: Route[]): Route { | ||
return route({ component, children }) | ||
} | ||
|
||
export function routeGroup(path: string, children: Route[]): Route { | ||
return route({ path, children }) | ||
} |
17 changes: 17 additions & 0 deletions
17
libs/web/meta/feature/src/lib/model-create/meta-model-create.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Component } from '@angular/core' | ||
import { MetaModelCreateStore } from './meta-model-create.store' | ||
|
||
@Component({ | ||
template: ` | ||
<ng-container *ngIf="vm$ | async as vm"> | ||
<div class="bg-gray-800 p-4 rounded shadow"> | ||
<meta-model [model]="vm?.model"></meta-model> | ||
</div> | ||
</ng-container> | ||
`, | ||
providers: [MetaModelCreateStore], | ||
}) | ||
export class MetaModelCreateComponent { | ||
readonly vm$ = this.store.vm$ | ||
constructor(private readonly store: MetaModelCreateStore) {} | ||
} |
15 changes: 15 additions & 0 deletions
15
libs/web/meta/feature/src/lib/model-create/meta-model-create.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { CommonModule } from '@angular/common' | ||
import { NgModule } from '@angular/core' | ||
import { RouterModule } from '@angular/router' | ||
import { UiMetaModelModule } from '@nx-prisma-admin/web/meta/ui' | ||
import { MetaModelCreateComponent } from './meta-model-create.component' | ||
|
||
@NgModule({ | ||
declarations: [MetaModelCreateComponent], | ||
imports: [ | ||
CommonModule, | ||
RouterModule.forChild([{ path: '', component: MetaModelCreateComponent }]), | ||
UiMetaModelModule, | ||
], | ||
}) | ||
export class MetaModelCreateModule {} |
29 changes: 29 additions & 0 deletions
29
libs/web/meta/feature/src/lib/model-create/meta-model-create.store.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Injectable } from '@angular/core' | ||
import { ActivatedRoute } from '@angular/router' | ||
import { ComponentStore } from '@ngrx/component-store' | ||
import { MetaModel } from '@nx-prisma-admin/web/util/sdk' | ||
import { map, pluck, switchMap } from 'rxjs/operators' | ||
import { WebMetaFeatureStore } from '../web-meta-feature.store' | ||
|
||
interface WebMetaModelState { | ||
model?: MetaModel | ||
} | ||
|
||
@Injectable() | ||
export class MetaModelCreateStore extends ComponentStore<WebMetaModelState> { | ||
readonly model$ = this.select(this.state$, ({ model }) => model) | ||
readonly vm$ = this.select(this.meta.schema$, this.model$, (schema, model) => ({ schema, model })) | ||
|
||
constructor(route: ActivatedRoute, private readonly meta: WebMetaFeatureStore) { | ||
super({}) | ||
this.loadModelEffect(route.params.pipe(pluck('modelId'))) | ||
} | ||
|
||
readonly loadModelEffect = this.effect<string>((modelId$) => | ||
modelId$.pipe( | ||
switchMap((modelId: string) => | ||
this.meta.vm$.pipe(map((res) => this.patchState({ model: res?.schema?.models.find((m) => m.id === modelId) }))), | ||
), | ||
), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters