@suss/contract-prisma 0.9.0 → 0.11.0

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/dist/index.cjs CHANGED
@@ -118,6 +118,7 @@ function buildModelSummary(opts) {
118
118
  const columns = [];
119
119
  const indexes = [];
120
120
  const physicalTable = physicalTableOf(opts.model);
121
+ let hasRelation = false;
121
122
  for (const property of opts.model.properties) {
122
123
  if (property.type === "field") {
123
124
  const field = property;
@@ -125,6 +126,11 @@ function buildModelSummary(opts) {
125
126
  if (column !== null) {
126
127
  columns.push(column);
127
128
  }
129
+ const related = relationField(field, opts.modelNames);
130
+ if (related !== null) {
131
+ hasRelation = true;
132
+ columns.push(related);
133
+ }
128
134
  } else if (property.type === "attribute") {
129
135
  const attr = property;
130
136
  const index = blockAttributeToIndex(attr);
@@ -133,6 +139,14 @@ function buildModelSummary(opts) {
133
139
  }
134
140
  }
135
141
  }
142
+ if (hasRelation) {
143
+ columns.push({
144
+ name: "_count",
145
+ type: "PrismaCount",
146
+ nullable: false,
147
+ derived: true
148
+ });
149
+ }
136
150
  return {
137
151
  kind: "library",
138
152
  location: {
@@ -166,6 +180,17 @@ function buildModelSummary(opts) {
166
180
  }
167
181
  };
168
182
  }
183
+ function relationField(field, modelNames) {
184
+ if (!modelNames.has(field.fieldType)) {
185
+ return null;
186
+ }
187
+ return {
188
+ name: field.name,
189
+ type: field.array === true ? `${field.fieldType}[]` : field.fieldType,
190
+ nullable: field.optional === true,
191
+ derived: true
192
+ };
193
+ }
169
194
  function fieldToColumn(field, modelNames, enumNames) {
170
195
  if (field.array === true) {
171
196
  return null;
package/dist/index.js CHANGED
@@ -83,6 +83,7 @@ function buildModelSummary(opts) {
83
83
  const columns = [];
84
84
  const indexes = [];
85
85
  const physicalTable = physicalTableOf(opts.model);
86
+ let hasRelation = false;
86
87
  for (const property of opts.model.properties) {
87
88
  if (property.type === "field") {
88
89
  const field = property;
@@ -90,6 +91,11 @@ function buildModelSummary(opts) {
90
91
  if (column !== null) {
91
92
  columns.push(column);
92
93
  }
94
+ const related = relationField(field, opts.modelNames);
95
+ if (related !== null) {
96
+ hasRelation = true;
97
+ columns.push(related);
98
+ }
93
99
  } else if (property.type === "attribute") {
94
100
  const attr = property;
95
101
  const index = blockAttributeToIndex(attr);
@@ -98,6 +104,14 @@ function buildModelSummary(opts) {
98
104
  }
99
105
  }
100
106
  }
107
+ if (hasRelation) {
108
+ columns.push({
109
+ name: "_count",
110
+ type: "PrismaCount",
111
+ nullable: false,
112
+ derived: true
113
+ });
114
+ }
101
115
  return {
102
116
  kind: "library",
103
117
  location: {
@@ -131,6 +145,17 @@ function buildModelSummary(opts) {
131
145
  }
132
146
  };
133
147
  }
148
+ function relationField(field, modelNames) {
149
+ if (!modelNames.has(field.fieldType)) {
150
+ return null;
151
+ }
152
+ return {
153
+ name: field.name,
154
+ type: field.array === true ? `${field.fieldType}[]` : field.fieldType,
155
+ nullable: field.optional === true,
156
+ derived: true
157
+ };
158
+ }
134
159
  function fieldToColumn(field, modelNames, enumNames) {
135
160
  if (field.array === true) {
136
161
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suss/contract-prisma",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "description": "Generate suss behavioral summaries from Prisma schema declarations.",
6
6
  "keywords": [
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@mrleebo/prisma-ast": "^0.15.0",
50
- "@suss/behavioral-ir": "0.9.0"
50
+ "@suss/behavioral-ir": "0.11.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "tsup": "*",