Skip to content

Commit

Permalink
style: formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Jun 20, 2023
1 parent c2b1010 commit 98c7285
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/handler/model-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export async function handleModelPayload(
const type = typeAlias.type as ts.TypeLiteralNode;

if (type.kind !== ts.SyntaxKind.TypeLiteral) {
throw new Error(`prisma-json-types-generator: Provided model payload is not a type literal: ${type.getText()}`);
throw new Error(
`prisma-json-types-generator: Provided model payload is not a type literal: ${type.getText()}`
);
}

const scalarsField = type.members.find((m) => m.name?.getText() === 'scalars');
Expand All @@ -28,7 +30,9 @@ export async function handleModelPayload(
?.typeArguments?.[0] as ts.TypeLiteralNode;

if (!object) {
throw new Error(`prisma-json-types-generator: Payload scalars could not be resolved: ${type.getText()}`);
throw new Error(
`prisma-json-types-generator: Payload scalars could not be resolved: ${type.getText()}`
);
}

replaceObject(model, object, nsName, replacer, typeAlias.name.getText(), useType);
Expand Down
4 changes: 3 additions & 1 deletion src/handler/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export async function handleModule(
}

if (!signature.type) {
throw new Error(`prisma-json-types-generator: No type found for field ${fieldName} at model ${typeAliasName}`);
throw new Error(
`prisma-json-types-generator: No type found for field ${fieldName} at model ${typeAliasName}`
);
}

const typename = field.documentation?.match(JSON_REGEX)?.[1];
Expand Down
6 changes: 4 additions & 2 deletions src/handler/type-alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ export async function handleTypeAlias(
// not a type literal. TODO: there is a way of this happen?
if (object.kind !== ts.SyntaxKind.TypeLiteral) {
// For `model`Payload types. They were handled in `handleModelPayload` call
if (object.kind === ts.SyntaxKind.IndexedAccessType || object.kind === ts.SyntaxKind.TypeReference) {
if (
object.kind === ts.SyntaxKind.IndexedAccessType ||
object.kind === ts.SyntaxKind.TypeReference
) {
return;
}


throw new Error(`Provided object is not a type literal: ${object.getText()}`);
}

Expand Down
4 changes: 3 additions & 1 deletion src/helpers/replace-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export function replaceObject(
const signatureType = (member as ts.PropertySignature).type;

if (!typename || !signatureType) {
throw new Error(`prisma-json-types-generator: Could not find typename or signature type for ${field.name}`);
throw new Error(
`prisma-json-types-generator: Could not find typename or signature type for ${field.name}`
);
}

replaceSignature(
Expand Down
3 changes: 2 additions & 1 deletion src/on-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export async function onGenerate(options: GeneratorOptions) {

if (!prismaClientOptions.output?.value) {
throw new Error(
'prisma-json-types-generator: prisma client output not found: ' + JSON.stringify(prismaClientOptions, null, 2)
'prisma-json-types-generator: prisma client output not found: ' +
JSON.stringify(prismaClientOptions, null, 2)
);
}

Expand Down

0 comments on commit 98c7285

Please sign in to comment.