Skip to content

Commit

Permalink
fix(cli): type 'Null' is not a subtype of type 'bool' in type cast #273
Browse files Browse the repository at this point in the history
  • Loading branch information
Seven Du committed Nov 27, 2023
1 parent 3e57f2e commit cc7ad64
Show file tree
Hide file tree
Showing 20 changed files with 11,324 additions and 2,059 deletions.
8 changes: 6 additions & 2 deletions bin/orm.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/// Prisma Dart client generator
library prisma.generator;

import 'package:prisma_generator_helper/prisma_generator_helper.dart';
import 'package:orm/prisma_generator_helper/prisma_generator_helper.dart';

import 'src/generator.dart';

Future<void> main() => generator(PrismaDartClientGenerator());
Future<void> main() async {
final client = PrismaDartClientGenerator();

await generator(client);
}
34 changes: 14 additions & 20 deletions bin/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import 'dart:io';
import 'package:code_builder/code_builder.dart' as code;
import 'package:crypto/crypto.dart' as crypto;
import 'package:dart_style/dart_style.dart' show DartFormatter;
import 'package:orm/prisma_generator_helper/prisma_generator_helper.dart';
import 'package:path/path.dart' as path;
import 'package:prisma_generator_helper/dmmf.dart' as dmmf;
import 'package:prisma_generator_helper/prisma_generator_helper.dart';
import 'package:orm/prisma_generator_helper/dmmf.dart' as dmmf;

import 'packages.dart' as packages;
import 'prisma_info.dart';
Expand Down Expand Up @@ -39,6 +39,7 @@ class PrismaDartClientGenerator implements Handler {
'prisma',
]),
requiresEngines: [EngineType.queryEngine],
version: "v3.x",
);
}

Expand Down Expand Up @@ -120,6 +121,10 @@ extension WriteLibrary on PrismaDartClientGenerator {

/// Write library to file
void writeLibrary() {
this.library.ignoreForFile.addAll([
'invalid_use_of_internal_member',
]);

final library = this.library.build();
final original = library.accept(emitter);

Expand Down Expand Up @@ -332,10 +337,10 @@ extension InputObjectTypesGenerator on PrismaDartClientGenerator {

/// Build field type
code.Reference _buildFieldType(dmmf.SchemaArg field) {
/// TODO: bug https://github.com/odroe/prisma-dart/issues/209
withoutJsonValueInput(String name) {
withoutInputs(String name) {
if (name == 'NullableJsonNullValueInput') return false;
if (name == 'JsonNullValueInput') return false;
if (name.endsWith('FieldRefInput')) return false;

return true;
}
Expand All @@ -346,8 +351,8 @@ extension InputObjectTypesGenerator on PrismaDartClientGenerator {
dmmf.EnumArgType(value: final enum_) => enum_.name,
};

final types = field.inputTypes.where(
(element) => withoutJsonValueInput(readArgTypeName(element.type)));
final types = field.inputTypes
.where((element) => withoutInputs(readArgTypeName(element.type)));

// If the types is a single type, return it.
if (types.length == 1) {
Expand Down Expand Up @@ -388,17 +393,6 @@ extension InputObjectTypesGenerator on PrismaDartClientGenerator {
isList: types.first.isList,
isNullable: !field.isRequired,
);

// TODO: Build union type
// Build union type
// final reference = code.TypeReference((code.TypeReferenceBuilder updates) {
// updates
// ..symbol = 'PrismaUnion${types.length}'
// ..url = packages.orm
// ..types.addAll(types.map((e) => scalar(e, false)));
// });

// return field.isRequired ? reference : reference.nullable;
}

/// Build to json method
Expand Down Expand Up @@ -1653,10 +1647,10 @@ extension PrismaClientGenerator on PrismaDartClientGenerator {

/// Find binary engine executable
code.Expression _findBinaryEngineExecutable() {
final executable = options.binaryPaths?.queryEngine?[info.platform];
final executable =
options.binaryPaths?.queryEngine?.entries.firstOrNull?.value;
if (executable == null) {
throw Exception(
'Could not find query engine for platform ${info.platform}');
throw Exception('Could not find query engine');
}

return code.literalString(executable, raw: true);
Expand Down
7 changes: 2 additions & 5 deletions bin/src/prisma_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ class PrismaInfo {
/// Prisma version
final String version;

/// Current platform
final String platform;

const PrismaInfo._(this.version, this.platform);
const PrismaInfo._(this.version);

/// Lookup the Prisma version and platform.
factory PrismaInfo.lookup(String excutable) {
Expand All @@ -62,6 +59,6 @@ class PrismaInfo {
.map((e) => MapEntry(e.key.trim().toLowerCase(), e.value.trim()));
final json = Map.fromEntries(entries);

return PrismaInfo._(json['prisma']!, json['current platform']!);
return PrismaInfo._(json['prisma']!);
}
}
2 changes: 1 addition & 1 deletion bin/src/scalars.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:code_builder/code_builder.dart';
import 'package:prisma_generator_helper/dmmf.dart';
import 'package:orm/prisma_generator_helper/dmmf.dart';

import 'packages.dart' as packages;
import 'utils.dart';
Expand Down
Binary file added bun.lockb
Binary file not shown.
12 changes: 12 additions & 0 deletions debug.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'dart:convert';
import 'dart:io';

import 'package:orm/prisma_generator_helper/prisma_generator_helper.dart';

void main() {
final dmmf = json.decode(
File('dmmf.json').readAsStringSync(),
);

GeneratorOptions.fromJson(dmmf);
}
1 change: 1 addition & 0 deletions dmmf.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions example/lib/prisma_client.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: invalid_use_of_internal_member

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:json_annotation/json_annotation.dart';
import 'package:orm/binary_engine.dart' as _i5;
Expand Down Expand Up @@ -82,6 +84,10 @@ class UserWhereUniqueInput implements _i1.JsonSerializable {
const UserWhereUniqueInput({
this.id,
this.name,
this.AND,
this.OR,
this.NOT,
this.createdAt,
});

factory UserWhereUniqueInput.fromJson(Map<String, dynamic> json) =>
Expand All @@ -91,6 +97,14 @@ class UserWhereUniqueInput implements _i1.JsonSerializable {

final String? name;

final Iterable<UserWhereInput>? AND;

final Iterable<UserWhereInput>? OR;

final Iterable<UserWhereInput>? NOT;

final DateTimeFilter? createdAt;

@override
Map<String, dynamic> toJson() => _$UserWhereUniqueInputToJson(this);
}
Expand Down Expand Up @@ -1615,6 +1629,7 @@ class PrismaClient extends _i1.BasePrismaClient<PrismaClient> {
headers: headers ?? _headers,
transaction: transaction ?? _transaction,
);

_i1.ModelDelegate<User> get user => _i1.ModelDelegate<User>(
_engine,
headers: _headers,
Expand Down
Loading

0 comments on commit cc7ad64

Please sign in to comment.