-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First commit of `FlutterSupabaseMacro` : • Exclude `primaryKey` from `toJsonSupabase`
- Loading branch information
1 parent
896d8b9
commit 5aa4a06
Showing
10 changed files
with
723 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
|
||
name: Main CI | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
test-flutter: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: subosito/flutter-action@v2.16.0 | ||
with: | ||
channel: 'beta' | ||
|
||
- name: Install dependencies | ||
run: flutter pub get | ||
|
||
- name: Analyze project source | ||
run: flutter analyze | ||
|
||
- name: Run tests | ||
run: flutter test --enable-experiment=macros |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
library; | ||
|
||
export 'src/annotations.dart'; | ||
export 'src/supabase_macro.dart'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// ignore_for_file: deprecated_member_use, unintended_html_in_doc_comment | ||
|
||
part of '../supabase_macro.dart'; | ||
|
||
/// Shared logic for all macros which run in the declarations phase. | ||
mixin _Shared { | ||
/// Returns [type] as a [NamedTypeAnnotation] if it is one, otherwise returns | ||
/// `null` and emits relevant error diagnostics. | ||
NamedTypeAnnotation? _checkNamedType(TypeAnnotation type, Builder builder) { | ||
if (type is NamedTypeAnnotation) return type; | ||
if (type is OmittedTypeAnnotation) { | ||
builder.report( | ||
_createDiagnostic( | ||
type, | ||
message: | ||
'Only fields with explicit types are allowed on serializable ' | ||
'classes, please add a type.', | ||
), | ||
); | ||
} else { | ||
builder.report( | ||
_createDiagnostic( | ||
type, | ||
message: 'Only fields with named types are allowed on serializable ' | ||
'classes.', | ||
), | ||
); | ||
} | ||
return null; | ||
} | ||
|
||
/// Create a [Diagnostic] according with [type] and [message]. | ||
Diagnostic _createDiagnostic(TypeAnnotation type, {required String message}) { | ||
return Diagnostic( | ||
DiagnosticMessage(message, target: type.asDiagnosticTarget), | ||
Severity.error, | ||
); | ||
} | ||
|
||
/// Does some basic validation on [clazz], and shared setup logic. | ||
/// | ||
/// Returns a code representation of the [Map<String, dynamic>] class. | ||
Future<NamedTypeAnnotationCode> _setup( | ||
ClassDeclaration clazz, | ||
MemberDeclarationBuilder builder, | ||
) async { | ||
if (clazz.typeParameters.isNotEmpty) { | ||
throw DiagnosticException( | ||
Diagnostic( | ||
DiagnosticMessage( | ||
'Cannot be applied to classes with generic type parameters', | ||
), | ||
Severity.error, | ||
), | ||
); | ||
} | ||
|
||
final (map, string, dynamic) = await ( | ||
builder.resolveIdentifier(_dartCore, 'Map'), | ||
builder.resolveIdentifier(_dartCore, 'String'), | ||
builder.resolveIdentifier(_dartCore, 'dynamic'), | ||
).wait; | ||
return NamedTypeAnnotationCode( | ||
name: map, | ||
typeArguments: [ | ||
NamedTypeAnnotationCode(name: string), | ||
NamedTypeAnnotationCode(name: dynamic), | ||
], | ||
); | ||
} | ||
} |
Oops, something went wrong.