@suss/contract-prisma 0.0.1 → 0.1.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 +28 -1
- package/dist/index.js +28 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -117,6 +117,7 @@ function prismaSchemaFileToSummaries(schemaPath, options = {}) {
|
|
|
117
117
|
function buildModelSummary(opts) {
|
|
118
118
|
const columns = [];
|
|
119
119
|
const indexes = [];
|
|
120
|
+
const physicalTable = physicalTableOf(opts.model);
|
|
120
121
|
for (const property of opts.model.properties) {
|
|
121
122
|
if (property.type === "field") {
|
|
122
123
|
const field = property;
|
|
@@ -156,7 +157,8 @@ function buildModelSummary(opts) {
|
|
|
156
157
|
metadata: {
|
|
157
158
|
storageContract: {
|
|
158
159
|
columns,
|
|
159
|
-
indexes
|
|
160
|
+
indexes,
|
|
161
|
+
...physicalTable !== null && physicalTable !== opts.model.name ? { physicalTable } : {}
|
|
160
162
|
}
|
|
161
163
|
}
|
|
162
164
|
};
|
|
@@ -192,6 +194,31 @@ function fieldToColumn(field, modelNames, enumNames) {
|
|
|
192
194
|
...unique ? { unique: true } : {}
|
|
193
195
|
};
|
|
194
196
|
}
|
|
197
|
+
function physicalTableOf(model) {
|
|
198
|
+
for (const property of model.properties) {
|
|
199
|
+
if (property.type !== "attribute") {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const attr = property;
|
|
203
|
+
if (attr.name !== "map") {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
const name = readStringArg(attr);
|
|
207
|
+
if (name !== null) {
|
|
208
|
+
return name;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
function readStringArg(attr) {
|
|
214
|
+
for (const arg of attr.args ?? []) {
|
|
215
|
+
const value = arg.value;
|
|
216
|
+
if (typeof value === "string") {
|
|
217
|
+
return value.replace(/^"|"$/g, "");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
195
222
|
function blockAttributeToIndex(attr) {
|
|
196
223
|
if (attr.name !== "index" && attr.name !== "unique" && attr.name !== "id") {
|
|
197
224
|
return null;
|
package/dist/index.js
CHANGED
|
@@ -82,6 +82,7 @@ function prismaSchemaFileToSummaries(schemaPath, options = {}) {
|
|
|
82
82
|
function buildModelSummary(opts) {
|
|
83
83
|
const columns = [];
|
|
84
84
|
const indexes = [];
|
|
85
|
+
const physicalTable = physicalTableOf(opts.model);
|
|
85
86
|
for (const property of opts.model.properties) {
|
|
86
87
|
if (property.type === "field") {
|
|
87
88
|
const field = property;
|
|
@@ -121,7 +122,8 @@ function buildModelSummary(opts) {
|
|
|
121
122
|
metadata: {
|
|
122
123
|
storageContract: {
|
|
123
124
|
columns,
|
|
124
|
-
indexes
|
|
125
|
+
indexes,
|
|
126
|
+
...physicalTable !== null && physicalTable !== opts.model.name ? { physicalTable } : {}
|
|
125
127
|
}
|
|
126
128
|
}
|
|
127
129
|
};
|
|
@@ -157,6 +159,31 @@ function fieldToColumn(field, modelNames, enumNames) {
|
|
|
157
159
|
...unique ? { unique: true } : {}
|
|
158
160
|
};
|
|
159
161
|
}
|
|
162
|
+
function physicalTableOf(model) {
|
|
163
|
+
for (const property of model.properties) {
|
|
164
|
+
if (property.type !== "attribute") {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const attr = property;
|
|
168
|
+
if (attr.name !== "map") {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const name = readStringArg(attr);
|
|
172
|
+
if (name !== null) {
|
|
173
|
+
return name;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
function readStringArg(attr) {
|
|
179
|
+
for (const arg of attr.args ?? []) {
|
|
180
|
+
const value = arg.value;
|
|
181
|
+
if (typeof value === "string") {
|
|
182
|
+
return value.replace(/^"|"$/g, "");
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
160
187
|
function blockAttributeToIndex(attr) {
|
|
161
188
|
if (attr.name !== "index" && attr.name !== "unique" && attr.name !== "id") {
|
|
162
189
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suss/contract-prisma",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.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.0
|
|
50
|
+
"@suss/behavioral-ir": "0.1.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"tsup": "*",
|