prisma-arktype 2.1.0 → 2.2.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.js +86 -39
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -181,17 +181,17 @@ function stringifyEnum(enumData) {
|
|
|
181
181
|
const processedPlain = [];
|
|
182
182
|
function processPlain(models) {
|
|
183
183
|
for (const model of models) {
|
|
184
|
-
const
|
|
185
|
-
if (
|
|
184
|
+
const result = stringifyPlain(model);
|
|
185
|
+
if (result) {
|
|
186
186
|
processedPlain.push({
|
|
187
187
|
name: model.name,
|
|
188
|
-
stringified
|
|
188
|
+
stringified: result.stringified,
|
|
189
|
+
enumDependencies: result.enumDependencies
|
|
189
190
|
});
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
Object.freeze(processedPlain);
|
|
193
194
|
}
|
|
194
|
-
const enumMatch$1 = /type\("(.+)"\)/;
|
|
195
195
|
function stringifyPlain(model, isInputCreate = false, isInputUpdate = false) {
|
|
196
196
|
const config = getConfig();
|
|
197
197
|
const { hidden } = extractAnnotations(
|
|
@@ -201,6 +201,7 @@ function stringifyPlain(model, isInputCreate = false, isInputUpdate = false) {
|
|
|
201
201
|
return;
|
|
202
202
|
}
|
|
203
203
|
const fields = [];
|
|
204
|
+
const enumDependencies = [];
|
|
204
205
|
for (const field of model.fields) {
|
|
205
206
|
const {
|
|
206
207
|
annotations: fieldAnnotations,
|
|
@@ -227,17 +228,28 @@ function stringifyPlain(model, isInputCreate = false, isInputUpdate = false) {
|
|
|
227
228
|
} else if (field.kind === "enum") {
|
|
228
229
|
const enumDef = processedEnums.find((e) => e.name === field.type);
|
|
229
230
|
if (!enumDef) continue;
|
|
230
|
-
|
|
231
|
-
|
|
231
|
+
if (!enumDependencies.includes(field.type)) {
|
|
232
|
+
enumDependencies.push(field.type);
|
|
233
|
+
}
|
|
234
|
+
fieldType = field.type;
|
|
232
235
|
} else {
|
|
233
236
|
continue;
|
|
234
237
|
}
|
|
238
|
+
const isEnumType = field.kind === "enum" && !typeOverwrite;
|
|
235
239
|
if (field.isList) {
|
|
236
|
-
|
|
240
|
+
if (isEnumType) {
|
|
241
|
+
fieldType = `${fieldType}.array()`;
|
|
242
|
+
} else {
|
|
243
|
+
fieldType = `"${wrapPrimitiveWithArray(fieldType.slice(1, -1))}"`;
|
|
244
|
+
}
|
|
237
245
|
}
|
|
238
246
|
if (!field.isRequired) {
|
|
239
|
-
|
|
240
|
-
|
|
247
|
+
if (isEnumType) {
|
|
248
|
+
fieldType = `${fieldType}.or("null")`;
|
|
249
|
+
} else {
|
|
250
|
+
const inner = fieldType.slice(1, -1);
|
|
251
|
+
fieldType = `"${inner} | null"`;
|
|
252
|
+
}
|
|
241
253
|
fieldName += "?";
|
|
242
254
|
}
|
|
243
255
|
if (field.hasDefaultValue || isInputUpdate) {
|
|
@@ -247,9 +259,12 @@ function stringifyPlain(model, isInputCreate = false, isInputUpdate = false) {
|
|
|
247
259
|
}
|
|
248
260
|
fields.push(`"${fieldName}": ${fieldType}`);
|
|
249
261
|
}
|
|
250
|
-
return
|
|
262
|
+
return {
|
|
263
|
+
stringified: `{
|
|
251
264
|
${fields.join(",\n ")}
|
|
252
|
-
}
|
|
265
|
+
}`,
|
|
266
|
+
enumDependencies
|
|
267
|
+
};
|
|
253
268
|
}
|
|
254
269
|
function stringifyPlainInputCreate(model) {
|
|
255
270
|
return stringifyPlain(model, true, false);
|
|
@@ -263,11 +278,12 @@ function processCreate(models) {
|
|
|
263
278
|
for (const model of models) {
|
|
264
279
|
const { hidden } = extractAnnotations(model.documentation);
|
|
265
280
|
if (hidden) continue;
|
|
266
|
-
const
|
|
267
|
-
if (
|
|
281
|
+
const result = stringifyPlainInputCreate(model);
|
|
282
|
+
if (result) {
|
|
268
283
|
processedCreate.push({
|
|
269
284
|
name: model.name,
|
|
270
|
-
stringified
|
|
285
|
+
stringified: result.stringified,
|
|
286
|
+
enumDependencies: result.enumDependencies
|
|
271
287
|
});
|
|
272
288
|
}
|
|
273
289
|
}
|
|
@@ -530,11 +546,12 @@ function processUpdate(models) {
|
|
|
530
546
|
for (const model of models) {
|
|
531
547
|
const { hidden } = extractAnnotations(model.documentation);
|
|
532
548
|
if (hidden) continue;
|
|
533
|
-
const
|
|
534
|
-
if (
|
|
549
|
+
const result = stringifyPlainInputUpdate(model);
|
|
550
|
+
if (result) {
|
|
535
551
|
processedUpdate.push({
|
|
536
552
|
name: model.name,
|
|
537
|
-
stringified
|
|
553
|
+
stringified: result.stringified,
|
|
554
|
+
enumDependencies: result.enumDependencies
|
|
538
555
|
});
|
|
539
556
|
}
|
|
540
557
|
}
|
|
@@ -545,25 +562,26 @@ const processedWhere = [];
|
|
|
545
562
|
const processedWhereUnique = [];
|
|
546
563
|
function processWhere(models) {
|
|
547
564
|
for (const model of models) {
|
|
548
|
-
const
|
|
549
|
-
if (
|
|
565
|
+
const result = stringifyWhere(model);
|
|
566
|
+
if (result) {
|
|
550
567
|
processedWhere.push({
|
|
551
568
|
name: model.name,
|
|
552
|
-
stringified
|
|
569
|
+
stringified: result.stringified,
|
|
570
|
+
enumDependencies: result.enumDependencies
|
|
553
571
|
});
|
|
554
572
|
}
|
|
555
|
-
const
|
|
556
|
-
if (
|
|
573
|
+
const uniqueResult = stringifyWhereUnique(model);
|
|
574
|
+
if (uniqueResult) {
|
|
557
575
|
processedWhereUnique.push({
|
|
558
576
|
name: model.name,
|
|
559
|
-
stringified:
|
|
577
|
+
stringified: uniqueResult.stringified,
|
|
578
|
+
enumDependencies: uniqueResult.enumDependencies
|
|
560
579
|
});
|
|
561
580
|
}
|
|
562
581
|
}
|
|
563
582
|
Object.freeze(processedWhere);
|
|
564
583
|
Object.freeze(processedWhereUnique);
|
|
565
584
|
}
|
|
566
|
-
const enumMatch = /type\("(.+)"\)/;
|
|
567
585
|
function stringifyWhere(model) {
|
|
568
586
|
const { hidden } = extractAnnotations(
|
|
569
587
|
model.documentation
|
|
@@ -572,6 +590,7 @@ function stringifyWhere(model) {
|
|
|
572
590
|
return;
|
|
573
591
|
}
|
|
574
592
|
const fields = [];
|
|
593
|
+
const enumDependencies = [];
|
|
575
594
|
for (const field of model.fields) {
|
|
576
595
|
const { annotations: fieldAnnotations, hidden: fieldHidden } = extractAnnotations(field.documentation);
|
|
577
596
|
if (fieldHidden) continue;
|
|
@@ -585,20 +604,30 @@ function stringifyWhere(model) {
|
|
|
585
604
|
} else if (field.kind === "enum") {
|
|
586
605
|
const enumDef = processedEnums.find((e) => e.name === field.type);
|
|
587
606
|
if (!enumDef) continue;
|
|
588
|
-
|
|
589
|
-
|
|
607
|
+
if (!enumDependencies.includes(field.type)) {
|
|
608
|
+
enumDependencies.push(field.type);
|
|
609
|
+
}
|
|
610
|
+
fieldType = field.type;
|
|
590
611
|
} else {
|
|
591
612
|
continue;
|
|
592
613
|
}
|
|
614
|
+
const isEnumType = field.kind === "enum" && !typeOverwrite;
|
|
593
615
|
if (field.isList) {
|
|
594
|
-
|
|
595
|
-
|
|
616
|
+
if (isEnumType) {
|
|
617
|
+
fieldType = `${fieldType}.array()`;
|
|
618
|
+
} else {
|
|
619
|
+
const inner = fieldType.slice(1, -1);
|
|
620
|
+
fieldType = `"${wrapPrimitiveWithArray(inner)}"`;
|
|
621
|
+
}
|
|
596
622
|
}
|
|
597
623
|
fields.push(`"${field.name}?": ${fieldType}`);
|
|
598
624
|
}
|
|
599
|
-
return
|
|
625
|
+
return {
|
|
626
|
+
stringified: `{
|
|
600
627
|
${fields.join(",\n ")}
|
|
601
|
-
}
|
|
628
|
+
}`,
|
|
629
|
+
enumDependencies
|
|
630
|
+
};
|
|
602
631
|
}
|
|
603
632
|
function stringifyWhereUnique(model) {
|
|
604
633
|
const { hidden } = extractAnnotations(
|
|
@@ -608,6 +637,7 @@ function stringifyWhereUnique(model) {
|
|
|
608
637
|
return;
|
|
609
638
|
}
|
|
610
639
|
const fields = [];
|
|
640
|
+
const enumDependencies = [];
|
|
611
641
|
for (const field of model.fields) {
|
|
612
642
|
const { annotations: fieldAnnotations, hidden: fieldHidden } = extractAnnotations(field.documentation);
|
|
613
643
|
if (fieldHidden) continue;
|
|
@@ -622,8 +652,10 @@ function stringifyWhereUnique(model) {
|
|
|
622
652
|
} else if (field.kind === "enum") {
|
|
623
653
|
const enumDef = processedEnums.find((e) => e.name === field.type);
|
|
624
654
|
if (!enumDef) continue;
|
|
625
|
-
|
|
626
|
-
|
|
655
|
+
if (!enumDependencies.includes(field.type)) {
|
|
656
|
+
enumDependencies.push(field.type);
|
|
657
|
+
}
|
|
658
|
+
fieldType = field.type;
|
|
627
659
|
} else {
|
|
628
660
|
continue;
|
|
629
661
|
}
|
|
@@ -632,14 +664,24 @@ function stringifyWhereUnique(model) {
|
|
|
632
664
|
if (fields.length === 0) {
|
|
633
665
|
return;
|
|
634
666
|
}
|
|
635
|
-
return
|
|
667
|
+
return {
|
|
668
|
+
stringified: `{
|
|
636
669
|
${fields.join(",\n ")}
|
|
637
|
-
}
|
|
670
|
+
}`,
|
|
671
|
+
enumDependencies
|
|
672
|
+
};
|
|
638
673
|
}
|
|
639
674
|
|
|
640
675
|
async function format(input) {
|
|
641
676
|
return input;
|
|
642
677
|
}
|
|
678
|
+
function generateEnumImports(enumDependencies) {
|
|
679
|
+
if (!enumDependencies || enumDependencies.length === 0) {
|
|
680
|
+
return "";
|
|
681
|
+
}
|
|
682
|
+
return `${enumDependencies.map((enumName) => `import { ${enumName} } from "./${enumName}";`).join("\n")}
|
|
683
|
+
`;
|
|
684
|
+
}
|
|
643
685
|
function mapAllModelsForWrite(processedEnums, processedPlain, processedRelations, processedWhere, processedWhereUnique, processedCreate, processedUpdate, processedRelationsCreate, processedRelationsUpdate, processedSelect, processedInclude, processedOrderBy) {
|
|
644
686
|
const config = getConfig();
|
|
645
687
|
const modelMap = /* @__PURE__ */ new Map();
|
|
@@ -652,7 +694,8 @@ function mapAllModelsForWrite(processedEnums, processedPlain, processedRelations
|
|
|
652
694
|
modelMap.set(model.name, content);
|
|
653
695
|
}
|
|
654
696
|
for (const model of processedPlain) {
|
|
655
|
-
const
|
|
697
|
+
const enumImports = generateEnumImports(model.enumDependencies);
|
|
698
|
+
const content = `${arktypeImport}${enumImports}export const ${model.name}Plain = type(${model.stringified});
|
|
656
699
|
`;
|
|
657
700
|
modelMap.set(`${model.name}Plain`, content);
|
|
658
701
|
}
|
|
@@ -679,22 +722,26 @@ export const ${plain.name} = ${plain.name}Plain;
|
|
|
679
722
|
}
|
|
680
723
|
}
|
|
681
724
|
for (const model of processedWhere) {
|
|
682
|
-
const
|
|
725
|
+
const enumImports = generateEnumImports(model.enumDependencies);
|
|
726
|
+
const content = `${arktypeImport}${enumImports}export const ${model.name}Where = type(${model.stringified});
|
|
683
727
|
`;
|
|
684
728
|
modelMap.set(`${model.name}Where`, content);
|
|
685
729
|
}
|
|
686
730
|
for (const model of processedWhereUnique) {
|
|
687
|
-
const
|
|
731
|
+
const enumImports = generateEnumImports(model.enumDependencies);
|
|
732
|
+
const content = `${arktypeImport}${enumImports}export const ${model.name}WhereUnique = type(${model.stringified});
|
|
688
733
|
`;
|
|
689
734
|
modelMap.set(`${model.name}WhereUnique`, content);
|
|
690
735
|
}
|
|
691
736
|
for (const model of processedCreate) {
|
|
692
|
-
const
|
|
737
|
+
const enumImports = generateEnumImports(model.enumDependencies);
|
|
738
|
+
const content = `${arktypeImport}${enumImports}export const ${model.name}Create = type(${model.stringified});
|
|
693
739
|
`;
|
|
694
740
|
modelMap.set(`${model.name}Create`, content);
|
|
695
741
|
}
|
|
696
742
|
for (const model of processedUpdate) {
|
|
697
|
-
const
|
|
743
|
+
const enumImports = generateEnumImports(model.enumDependencies);
|
|
744
|
+
const content = `${arktypeImport}${enumImports}export const ${model.name}Update = type(${model.stringified});
|
|
698
745
|
`;
|
|
699
746
|
modelMap.set(`${model.name}Update`, content);
|
|
700
747
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prisma-arktype",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Generate ArkType schemas from your Prisma schema",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@biomejs/biome": "2.3.11",
|
|
44
|
-
"@changesets/cli": "
|
|
44
|
+
"@changesets/cli": "2.29.8",
|
|
45
45
|
"@commitlint/cli": "^20.1.0",
|
|
46
46
|
"@commitlint/config-conventional": "^20.0.0",
|
|
47
47
|
"@prisma/client": "^6.18.0",
|