@suss/contract-prisma 0.11.0 → 0.13.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 +35 -13
- package/dist/index.js +35 -13
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -184,13 +184,21 @@ function relationField(field, modelNames) {
|
|
|
184
184
|
if (!modelNames.has(field.fieldType)) {
|
|
185
185
|
return null;
|
|
186
186
|
}
|
|
187
|
+
const key = relationKeyOf(field);
|
|
187
188
|
return {
|
|
188
189
|
name: field.name,
|
|
189
190
|
type: field.array === true ? `${field.fieldType}[]` : field.fieldType,
|
|
190
191
|
nullable: field.optional === true,
|
|
191
|
-
derived: true
|
|
192
|
+
derived: true,
|
|
193
|
+
...key === null ? {} : { relationKey: key }
|
|
192
194
|
};
|
|
193
195
|
}
|
|
196
|
+
function relationKeyOf(field) {
|
|
197
|
+
const relation = (field.attributes ?? []).find(
|
|
198
|
+
(attr) => attr.name === "relation"
|
|
199
|
+
);
|
|
200
|
+
return relation === void 0 ? null : readKeyedArrayArg(relation, "fields");
|
|
201
|
+
}
|
|
194
202
|
function fieldToColumn(field, modelNames, enumNames) {
|
|
195
203
|
if (field.array === true) {
|
|
196
204
|
return null;
|
|
@@ -258,25 +266,39 @@ function blockAttributeToIndex(attr) {
|
|
|
258
266
|
return { fields, unique: attr.name !== "index" };
|
|
259
267
|
}
|
|
260
268
|
function readArrayArg(attr) {
|
|
269
|
+
for (const arg of attr.args ?? []) {
|
|
270
|
+
const names = arrayNames(arg.value);
|
|
271
|
+
if (names !== null) {
|
|
272
|
+
return names;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
function readKeyedArrayArg(attr, key) {
|
|
261
278
|
for (const arg of attr.args ?? []) {
|
|
262
279
|
const value = arg.value;
|
|
263
|
-
if (value
|
|
280
|
+
if (value?.type !== "keyValue" || value.key !== key) {
|
|
264
281
|
continue;
|
|
265
282
|
}
|
|
266
|
-
|
|
267
|
-
const out = [];
|
|
268
|
-
for (const item of value.args) {
|
|
269
|
-
if (typeof item === "string") {
|
|
270
|
-
out.push(item);
|
|
271
|
-
} else if (typeof item === "object" && item !== null && "name" in item && typeof item.name === "string") {
|
|
272
|
-
out.push(item.name);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return out;
|
|
276
|
-
}
|
|
283
|
+
return arrayNames(value.value);
|
|
277
284
|
}
|
|
278
285
|
return null;
|
|
279
286
|
}
|
|
287
|
+
function arrayNames(value) {
|
|
288
|
+
const array = value;
|
|
289
|
+
if (array?.type !== "array" || !Array.isArray(array.args)) {
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
const out = [];
|
|
293
|
+
for (const item of array.args) {
|
|
294
|
+
if (typeof item === "string") {
|
|
295
|
+
out.push(item);
|
|
296
|
+
} else if (typeof item === "object" && item !== null && "name" in item && typeof item.name === "string") {
|
|
297
|
+
out.push(item.name);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return out;
|
|
301
|
+
}
|
|
280
302
|
function readProviderString(ds) {
|
|
281
303
|
for (const a of ds.assignments) {
|
|
282
304
|
if (a.key !== "provider") {
|
package/dist/index.js
CHANGED
|
@@ -149,13 +149,21 @@ function relationField(field, modelNames) {
|
|
|
149
149
|
if (!modelNames.has(field.fieldType)) {
|
|
150
150
|
return null;
|
|
151
151
|
}
|
|
152
|
+
const key = relationKeyOf(field);
|
|
152
153
|
return {
|
|
153
154
|
name: field.name,
|
|
154
155
|
type: field.array === true ? `${field.fieldType}[]` : field.fieldType,
|
|
155
156
|
nullable: field.optional === true,
|
|
156
|
-
derived: true
|
|
157
|
+
derived: true,
|
|
158
|
+
...key === null ? {} : { relationKey: key }
|
|
157
159
|
};
|
|
158
160
|
}
|
|
161
|
+
function relationKeyOf(field) {
|
|
162
|
+
const relation = (field.attributes ?? []).find(
|
|
163
|
+
(attr) => attr.name === "relation"
|
|
164
|
+
);
|
|
165
|
+
return relation === void 0 ? null : readKeyedArrayArg(relation, "fields");
|
|
166
|
+
}
|
|
159
167
|
function fieldToColumn(field, modelNames, enumNames) {
|
|
160
168
|
if (field.array === true) {
|
|
161
169
|
return null;
|
|
@@ -223,25 +231,39 @@ function blockAttributeToIndex(attr) {
|
|
|
223
231
|
return { fields, unique: attr.name !== "index" };
|
|
224
232
|
}
|
|
225
233
|
function readArrayArg(attr) {
|
|
234
|
+
for (const arg of attr.args ?? []) {
|
|
235
|
+
const names = arrayNames(arg.value);
|
|
236
|
+
if (names !== null) {
|
|
237
|
+
return names;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
function readKeyedArrayArg(attr, key) {
|
|
226
243
|
for (const arg of attr.args ?? []) {
|
|
227
244
|
const value = arg.value;
|
|
228
|
-
if (value
|
|
245
|
+
if (value?.type !== "keyValue" || value.key !== key) {
|
|
229
246
|
continue;
|
|
230
247
|
}
|
|
231
|
-
|
|
232
|
-
const out = [];
|
|
233
|
-
for (const item of value.args) {
|
|
234
|
-
if (typeof item === "string") {
|
|
235
|
-
out.push(item);
|
|
236
|
-
} else if (typeof item === "object" && item !== null && "name" in item && typeof item.name === "string") {
|
|
237
|
-
out.push(item.name);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return out;
|
|
241
|
-
}
|
|
248
|
+
return arrayNames(value.value);
|
|
242
249
|
}
|
|
243
250
|
return null;
|
|
244
251
|
}
|
|
252
|
+
function arrayNames(value) {
|
|
253
|
+
const array = value;
|
|
254
|
+
if (array?.type !== "array" || !Array.isArray(array.args)) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
const out = [];
|
|
258
|
+
for (const item of array.args) {
|
|
259
|
+
if (typeof item === "string") {
|
|
260
|
+
out.push(item);
|
|
261
|
+
} else if (typeof item === "object" && item !== null && "name" in item && typeof item.name === "string") {
|
|
262
|
+
out.push(item.name);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return out;
|
|
266
|
+
}
|
|
245
267
|
function readProviderString(ds) {
|
|
246
268
|
for (const a of ds.assignments) {
|
|
247
269
|
if (a.key !== "provider") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suss/contract-prisma",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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.
|
|
50
|
+
"@suss/behavioral-ir": "0.13.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"tsup": "*",
|