File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
packages/prisma-to-json-table-schema/src/utils/transformers/intermediate Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ import { type Model } from "@mrleebo/prisma-ast" ;
2+
3+ import { formatIntermediateTableField } from "./formatIntermediateField" ;
4+ import { lookForRelation } from "./lookForRelation" ;
5+
6+ import {
7+ type IntermediateTable ,
8+ type RawRelationInfo ,
9+ type RelationType ,
10+ } from "@/types/intermediateFormattedNode" ;
11+ import { isField } from "@/utils/isTypeOf" ;
12+
13+ export const formatIntermediateTable = (
14+ node : Model ,
15+ registerRawRelation : ( info : RawRelationInfo ) => void ,
16+ registerInverseRelation : ( name : string , info : RelationType ) => void ,
17+ ) : IntermediateTable => {
18+ const fields : IntermediateTable [ "fields" ] = [ ] ;
19+
20+ for ( const mayAField of node . properties ) {
21+ if ( ! isField ( mayAField ) ) continue ;
22+
23+ const field = formatIntermediateTableField ( mayAField ) ;
24+ lookForRelation (
25+ mayAField ,
26+ node . name ,
27+ registerRawRelation ,
28+ registerInverseRelation ,
29+ ) ;
30+
31+ fields . push ( field ) ;
32+ }
33+
34+ return {
35+ fields,
36+ name : node . name ,
37+ indexes : [ ] , // TODO : also format indexes,
38+ } ;
39+ } ;
You can’t perform that action at this time.
0 commit comments