-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathplugin-config.ts
More file actions
846 lines (799 loc) · 28.3 KB
/
plugin-config.ts
File metadata and controls
846 lines (799 loc) · 28.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
import {
EnumTypeDefinitionNode,
FieldDefinitionNode,
InputObjectTypeDefinitionNode,
InputValueDefinitionNode,
ObjectTypeDefinitionNode,
UnionTypeDefinitionNode,
} from 'graphql';
import { FieldNamePattern, Pattern, TypeName, TypeNamePattern } from './pattern.js';
//#region PluginConfig
/**
* @name FlutterFreezedPluginConfig
* @description configure the `flutter-freezed` plugin
*/
export type FlutterFreezedPluginConfig = {
/**
* @name camelCasedEnums
* @summary Specify how Enum values should be cased.
* @description Setting this option to `true` will camelCase enum values as required by Dart's recommended linter.
*
* If set to false, the original casing as specified in the Graphql Schema is used
*
* You can also transform the casing by specifying your preferred casing for Enum values.
*
* Available options are: `'snake_case'`, `'camelCase'` and `'PascalCase'`
*
* For consistency, this option applies the same configuration to all Enum Types in the GraphQL Schema
* @exampleMarkdown
* ## Usage:
* ```ts filename='codegen.ts'
* import type { CodegenConfig } from '@graphql-codegen/cli';
*
* const config: CodegenConfig = {
* // ...
* generates: {
* 'lib/data/models/app_models.dart': {
* plugins: {
* 'flutter-freezed': {
* // ...
* camelCasedEnums: true, // or false
* // OR: specify a DartIdentifierCasing
* camelCasedEnums: 'snake_case',
* },
* },
* },
* },
* };
* export default config;
* ```
*/
camelCasedEnums?: boolean | DartIdentifierCasing;
/**
* @name copyWith
* @see {@link https://pub.dev/packages/freezed#how-copywith-works How copyWith works}
* @see {@link https://pub.dev/documentation/freezed_annotation/latest/freezed_annotation/Freezed/copyWith.html Freezed annotation copyWith property}
* @summary enables Freezed copyWith helper method
* @description The [`freezed`](https://pub.dev/packages/freezed) library has this option enabled by default.
* Use this option to enable/disable this option completely.
*
* The plugin by default generates immutable Freezed models using the `@freezed` decorator.
*
* If this option is configured, the plugin will generate immutable Freezed models using the `@Freezed(copyWith: value)` instead.
*
* Setting a boolean value will enable/disable this option globally for every GraphQL Type
* but you can also set this option to `true` for one or more GraphQL Types using a `TypeNamePattern`.
* @exampleMarkdown
* ## Usage:
* ```ts filename='codegen.ts'
* import type { CodegenConfig } from '@graphql-codegen/cli';
*
* const Droid = TypeName.fromString('Droid');
* const Starship = TypeName.fromString('Starship');
*
* const config: CodegenConfig = {
* // ...
* generates: {
* 'lib/data/models/app_models.dart': {
* plugins: {
* 'flutter-freezed': {
* // ...
* copyWith: true,
* // OR: enable it for only Droid and Starship GraphQL types
* copyWith: TypeNamePattern.forTypeNames([Droid, Starship]),
* },
* },
* },
* },
* };
* export default config;
* ```
*/
copyWith?: boolean | TypeNamePattern;
/**
* @name customScalars
* @summary Maps GraphQL Scalar Types to Dart built-in types
* @description The `key` is the GraphQL Scalar Type and the `value` is the equivalent Dart Type
*
* The plugin automatically handles built-in GraphQL Scalar Types so only specify the custom Scalars in your Graphql Schema.
* @exampleMarkdown
* ## Usage
* ```ts filename='codegen.ts'
* import type { CodegenConfig } from '@graphql-codegen/cli';
*
* const config: CodegenConfig = {
* // ...
* generates: {
* 'lib/data/models/app_models.dart': {
* plugins: {
* 'flutter-freezed': {
* // ...
* customScalars: {
* jsonb: 'Map<String, dynamic>',
* timestamp: 'DateTime',
* UUID: 'String',
* },
* },
* },
* },
* },
* };
* export default config;
* ```
*/
customScalars?: Record<string, string>;
/**
* @name defaultValues
* @see {@link https://pub.dev/packages/freezed#default-values Default values}
* @see {@link https://pub.dev/documentation/freezed_annotation/latest/freezed_annotation/Default-class.html Default class}
* @summary set the default value for a field.
* @description This will annotate the generated parameter with a `@Default(value: defaultValue)` decorator.
*
* The default value will be interpolated into the `@Default(value: ${value})` decorator so
* Use backticks for the value element so that you can use quotation marks for string values.
* E.g: `"I'm a string default value"` but `Episode.jedi` is not a string value.
*
* Use the `appliesOn` to specify where this option should be applied on
*
* @exampleMarkdown
* ## Usage:
* ```ts filename='codegen.ts'
* import type { CodegenConfig } from '@graphql-codegen/cli';
*
* const MovieCharacter = TypeName.fromString('MovieCharacter');
* const appearsIn = FieldName.fromString('appearsIn');
*
* const config: CodegenConfig = {
* // ...
* generates: {
* 'lib/data/models/app_models.dart': {
* plugins: {
* 'flutter-freezed': {
* // ...
* defaultValues: [
* [FieldNamePattern.forFieldNamesOfTypeName(MovieCharacter, appearsIn), `Episode.jedi`, ['default_factory_parameter']],
* ],
* },
* },
* },
* },
* };
* export default config;
* ```
*/
defaultValues?: [
pattern: FieldNamePattern,
value: string, // use backticks for string values
appliesOn: AppliesOnParameters[],
][];
/**
* @name deprecated
* @see {@link https://pub.dev/packages/freezed#decorators-and-comments Decorators and comments}
* @summary a list of Graphql Types(factory constructors) or fields(parameters) to be marked as deprecated.
* @description Using a TypeNamePattern, you can mark an entire factory constructor for one or more GraphQL types as deprecated.
*
* Likewise, using a FieldNamePattern, you can mark one or more fields as deprecated
*
* Since the first element in the tuple has a type signature of `Pattern`,
* you can use either TypeNamePattern or FieldNamePattern or use both
* by composing them with `Pattern.compose(...)`
*
* Use the `appliesOn` to specify which block this option should be applied on
* @exampleMarkdown
* ## Usage:
*
* ```ts filename='codegen.ts'
* import type { CodegenConfig } from '@graphql-codegen/cli';
*
* const MovieCharacter = TypeName.fromString('MovieCharacter');
* const Droid = TypeName.fromString('Droid');
* const Starship = TypeName.fromString('Starship');
* const Human = TypeName.fromString('Human');
*
* const name = FieldName.fromString('name');
* const appearsIn = FieldName.fromString('appearsIn');
*
* const config: CodegenConfig = {
* // ...
* generates: {
* 'lib/data/models/app_models.dart': {
* plugins: {
* 'flutter-freezed': {
* // ...
* deprecated: [
* // using FieldNamePattern
* [FieldNamePattern.forFieldNamesOfTypeName(MovieCharacter, [appearsIn, name]), ['default_factory_parameter']],
* // using TypeNamePattern
* [TypeNamePattern.forTypeNames([Starship,Droid,Human]), ['union_factory']],
* ],
* },
* },
* },
* },
* };
* export default config;
* ```
*/
deprecated?: [pattern: Pattern, appliesOn: (AppliesOnFactory | AppliesOnParameters)[]][];
/**
* @name equal
* @see {@link https://pub.dev/packages/freezed#changing-the-behavior-for-a-specific-model Freezed equal helper method usage}
* @see {@link https://pub.dev/documentation/freezed_annotation/latest/freezed_annotation/Freezed/equal.html Freezed annotation equal property}
* @summary enables Freezed equal helper method
* @description The [`freezed`](https://pub.dev/packages/freezed) library has this option enabled by default.
* Use this option to enable/disable this option completely.
*
* The plugin by default generates immutable Freezed models using the `@freezed` decorator.
*
* If this option is configured, the plugin will generate immutable Freezed models using the `@Freezed(equal: value)` instead.
*
* Setting a boolean value will enable/disable this option globally for every GraphQL Type
* but you can also set this option to `true` for one or more GraphQL Types using a `TypeNamePattern`.
* @exampleMarkdown
* ## Usage:
* ```ts filename='codegen.ts'
* import type { CodegenConfig } from '@graphql-codegen/cli';
*
* const Droid = TypeName.fromString('Droid');
* const Starship = TypeName.fromString('Starship');
*
* const config: CodegenConfig = {
* // ...
* generates: {
* 'lib/data/models/app_models.dart': {
* plugins: {
* 'flutter-freezed': {
* // ...
* equal: true,
* // OR: enable it for only Droid and Starship GraphQL types
* equal: TypeNamePattern.forTypeNames([Droid, Starship]),
* },
* },
* },
* },
* };
* export default config;
* ```
*/
equal?: boolean | TypeNamePattern;
/**
* @name escapeDartKeywords
* @see_also [dartKeywordEscapePrefix,dartKeywordEscapeSuffix]
* @summary ensures that the generated Freezed models do not use any of Dart's reserved keywords as identifiers
* @description Wraps the fields names that are valid Dart keywords with the prefix and suffix given
*
* @exampleMarkdown
* ## Usage:
*
* ```ts filename='codegen.ts'
* import type { CodegenConfig } from '@graphql-codegen/cli';
*
* const Episode = TypeName.fromString('Episode');
*
* const config: CodegenConfig = {
* // ...
* generates: {
* 'lib/data/models/app_models.dart': {
* plugins: {
* 'flutter-freezed': {
* // ...
* // WARNING: Setting this option to `false` might generate output that contains Dart keywords as identifiers. Defaults to `true`
* escapeDartKeywords: false,
* // OR configure how Dart keywords are handled for each type
* escapeDartKeywords: [
* [
* Pattern.compose([
* TypeNamePattern.forAllTypeNames(),
* FieldNamePattern.forAllFieldNamesOfTypeName([Episode]),
* ]),
* // `prefix`: defaults to an empty string `''` if undefined.
* // WARNING: Note that using a underscore `_` as a prefix will make the field as private
* undefined,
* // `suffix`: defaults to an underscore `_` if undefined
* undefined,
* // `appliesOn`: defaults to an ['enum', 'enum_value', 'class', 'factory', 'parameter'] if undefined.
* undefined,
* ],
* ],
* },
* },
* },
* },
* };
* export default config;
* ```
*/
escapeDartKeywords?:
| boolean
| [pattern: Pattern, prefix?: string, suffix?: string, appliesOn?: AppliesOn[]][];
/**
* @name final
* @see {@link https://pub.dev/packages/freezed#defining-a-mutable-class-instead-of-an-immutable-one Freezed annotation equal property}
* @summary marks fields as final
* @description This will mark the specified parameters as final
* @exampleMarkdown
* ## Usage:
* ```ts filename='codegen.ts'
* import type { CodegenConfig } from '@graphql-codegen/cli';
*
* const id = FieldName.fromString('id');
*
* const config: CodegenConfig = {
* // ...
* generates: {
* 'lib/data/models/app_models.dart': {
* plugins: {
* 'flutter-freezed': {
* // ...
* final: [[FieldNamePattern.forFieldNamesOfAllTypeNames([id]), ['parameter']]],
* },
* },
* },
* },
* };
* export default config;
* ```
*/
final?: [pattern: FieldNamePattern, appliesOn: AppliesOnParameters[]][];
/**
* @name ignoreTypes
* @description names of GraphQL types to ignore when generating Freezed classes
*
* @exampleMarkdown
* ## Usage:
* ```ts filename='codegen.ts'
* import type { CodegenConfig } from '@graphql-codegen/cli';
*
* const PaginatorInfo = TypeName.fromString('PaginatorInfo');
*
* const config: CodegenConfig = {
* // ...
* generates: {
* 'lib/data/models/app_models.dart': {
* plugins: {
* 'flutter-freezed': {
* // ...
* ignoreTypes: TypeNamePattern.forTypeNames([PaginatorInfo]),
* },
* },
* },
* },
* };
* export default config;
* ```
*/
ignoreTypes?: TypeNamePattern;
/**
* @name immutable
* @see {@link https://pub.dev/packages/freezed#creating-a-model-using-freezed Creating a Model using Freezed}
* @summary enables Freezed immutable helper method
* @description set to true to use the `@freezed` decorator or false to use the `@unfreezed` decorator
* @description The [`freezed`](https://pub.dev/packages/freezed) library by default generates immutable models decorated with the `@freezed` decorator.
* This option if set to `false` the plugin will generate mutable Freezed models using the `@unfreezed` decorator instead.
*
* Setting a boolean value will enable/disable this option globally for every GraphQL Type
* but you can also set this option to `true` for one or more GraphQL Types using a `TypeNamePattern`.
* @exampleMarkdown
* ## Usage:
* ```ts filename='codegen.ts'
* import type { CodegenConfig } from '@graphql-codegen/cli';
*
* const Droid = TypeName.fromString('Droid');
* const Starship = TypeName.fromString('Starship');
*
* const config: CodegenConfig = {
* // ...
* generates: {
* 'lib/data/models/app_models.dart': {
* plugins: {
* 'flutter-freezed': {
* // ...
* immutable: true,
* // OR: enable it for all GraphQL types except Droid and Starship types
* immutable: TypeNamePattern.forTypeNamesExcludeTypeNames([Droid, Starship]),
* },
* },
* },
* },
* };
* export default config;
* ```
*/
immutable?: boolean | TypeNamePattern;
/**
* @name makeCollectionsUnmodifiable
* @see {@link https://pub.dev/packages/freezed#allowing-the-mutation-of-listsmapssets Allowing the mutation of Lists/Maps/Sets}
* @description allows collections(lists/maps) to be modified even if class is immutable
*
* @exampleMarkdown
* ## Usage:
* ```ts filename='codegen.ts'
* import type { CodegenConfig } from '@graphql-codegen/cli';
*
* const Droid = TypeName.fromString('Droid');
* const Starship = TypeName.fromString('Starship');
*
* const config: CodegenConfig = {
* // ...
* generates: {
* 'lib/data/models/app_models.dart': {
* plugins: {
* 'flutter-freezed': {
* // ...
* makeCollectionsUnmodifiable: true,
* // OR: enable it for only Droid and Starship GraphQL types
* makeCollectionsUnmodifiable: TypeNamePattern.forTypeNames([Droid, Starship]),
* },
* },
* },
* },
* };
* export default config;
* ```
*/
makeCollectionsUnmodifiable?: boolean | TypeNamePattern;
/**
* @name mergeTypes
* @description maps over the value(array of typeNames) and transform each as a named factory constructor inside a class generated for the key(target GraphQL Object Type).
* @exampleMarkdown
* ## Usage:
* ```ts filename='codegen.ts'
* import type { CodegenConfig } from '@graphql-codegen/cli';
*
* const Movie = TypeName.fromString('Movie');
* const CreateMovieInput = TypeName.fromString('CreateMovieInput');
* const UpdateMovieInput = TypeName.fromString('UpdateMovieInput');
* const UpsertMovieInput = TypeName.fromString('UpsertMovieInput');
*
* const config: CodegenConfig = {
* // ...
* generates: {
* 'lib/data/models/app_models.dart': {
* plugins: {
* 'flutter-freezed': {
* // ...
* mergeTypes: {
* [Movie.value]: [CreateMovieInput, UpdateMovieInput, UpsertMovieInput],
* },
* },
* },
* },
* },
* };
* export default config;
* ```
*/
mergeTypes?: Record<string, TypeName[]>;
/**
* @name mutableInputs
* @description since inputs will be used to collect data, it makes sense to make them mutable with Freezed's `@unfreezed` decorator.
*
* This overrides(in order words: has a higher precedence than) the `immutable` config value `ONLY` for GraphQL `input types`.
*
* @exampleMarkdown
* ## Usage:
* ```ts filename='codegen.ts'
* import type { CodegenConfig } from '@graphql-codegen/cli';
*
* const CreateMovieInput = TypeName.fromString('CreateMovieInput');
* const UpdateMovieInput = TypeName.fromString('UpdateMovieInput');
*
* const config: CodegenConfig = {
* // ...
* generates: {
* 'lib/data/models/app_models.dart': {
* plugins: {
* 'flutter-freezed': {
* // ...
* mutableInputs: true,
* // OR: enable it for only Droid and Starship GraphQL types
* mutableInputs: TypeNamePattern.forTypeNames([CreateMovieInput, UpdateMovieInput]),
* },
* },
* },
* },
* };
* export default config;
* ```
*/
mutableInputs?: boolean | TypeNamePattern;
/**
* @name privateEmptyConstructor
* @description if true, defines a private empty constructor to allow getter and methods to work on the class
*
* @exampleMarkdown
* ## Usage:
* ```ts filename='codegen.ts'
* import type { CodegenConfig } from '@graphql-codegen/cli';
*
* const Droid = TypeName.fromString('Droid');
* const Starship = TypeName.fromString('Starship');
*
* const config: CodegenConfig = {
* // ...
* generates: {
* 'lib/data/models/app_models.dart': {
* plugins: {
* 'flutter-freezed': {
* // ...
* privateEmptyConstructor: true,
* // OR: enable it for only Droid and Starship GraphQL types
* privateEmptyConstructor: TypeNamePattern.forTypeNames([Droid, Starship]),
* },
* },
* },
* },
* };
* export default config;
* ```
*/
privateEmptyConstructor?: boolean | TypeNamePattern;
/**
* @name unionClass
* @description customize the key to be used for fromJson with multiple constructors
* @see {@link https://pub.dev/packages/freezed#fromjson---classes-with-multiple-constructors fromJSON - classes with multiple constructors}
* @exampleMarkdown
* ## Usage:
* ```ts filename='codegen.ts'
* import type { CodegenConfig } from '@graphql-codegen/cli';
*
* const config: CodegenConfig = {
* // ...
* generates: {
* 'lib/data/models/app_models.dart': {
* plugins: {
* 'flutter-freezed': {
* // ...
* unionClass: [
* [
* 'SearchResult', // <-- unionTypeName
* 'namedConstructor', // <-- unionKey
* 'FreezedUnionCase.pascal', // <-- unionValueCase
* [ // <-- unionValuesNameMap
* [ Droid, 'special droid'],
* [ Human, 'astronaut'],
* [ Starship, 'space_Shuttle'],
* ],
* ],
* ],
* },
* },
* },
* },
* };
* export default config;
* ```
*/
unionClass?: [
/**
* The name of the Graphql Union Type (or in the case of merged types, the base type on which other types are merged with)
*/
unionTypeName: TypeNamePattern,
/**
* in a fromJSON/toJson encoding a response/object({key:value}), you can specify what name should be used as the key ?
*/
unionKey?: string,
/**
* normally in camelCase but you can change that to PascalCase
*/
unionValueCase?: UnionValueCase,
/**
* just as the unionKey changes the key used, this changes the value for each union/sealed factories
*/
unionValuesNameMap?: [typeName: TypeName, unionValueKey: string][],
][];
};
//#endregion
//#region type alias
/**
* @name ApplyDecoratorOn
* @description Values that are passed to the `DecoratorToFreezed.applyOn` field that specifies where the custom decorator should be applied
*/
export type AppliesOn =
| 'enum' // applies on the Enum itself
| 'enum_value' // applies to the value of an Enum
| 'class' // applies on the class itself
| 'factory' // applies on all class factory constructor
| 'default_factory' // applies on the main default factory constructor
| 'named_factory' // applies on all of the named factory constructors in a class
| 'union_factory' // applies on the named factory constructors for a specified(or all when the `*` is used as the key) GraphQL Object Type when it appears in a class as a named factory constructor and that class was generated for a GraphQL Union Type. E.g: `Droid` in `SearchResult` in the StarWars Schema
| 'merged_factory' // applies on the named factory constructors for a GraphQL Input Type when it appears in a class as a named factory constructor and that class was generated for a GraphQL Object Type and it Type is to be merged with the GraphQL Object Type. E.g: `CreateMovieInput` merged with `Movie` in the StarWars Schema
| 'parameter' // applies on all parameters for both default constructors and named factory constructors
| 'default_factory_parameter' // applies on parameters for ONLY default constructors for a specified(or all when the `*` is used as the key) field on a GraphQL Object/Input Type
| 'named_factory_parameter' // applies on parameters for all named factory constructors for a specified(or all when the `*` is used as the key) field on a GraphQL Object/Input Type
| 'union_factory_parameter' // like `named_factory_parameters` but ONLY for a parameter in a named factory constructor which for a GraphQL Union Type
| 'merged_factory_parameter'; // like `named_factory_parameters` but ONLY for a parameter in a named factory constructor which for a GraphQL Input Type that is merged inside an a class generated for a GraphQL Object Type
export const APPLIES_ON_ENUM = ['enum'] as const;
export type AppliesOnEnum = (typeof APPLIES_ON_ENUM)[number];
export const APPLIES_ON_ENUM_VALUE = ['enum_value'] as const;
export type AppliesOnEnumValue = (typeof APPLIES_ON_ENUM_VALUE)[number];
export const APPLIES_ON_CLASS = ['class'] as const;
export type AppliesOnClass = (typeof APPLIES_ON_CLASS)[number];
export const APPLIES_ON_DEFAULT_FACTORY = ['factory', 'default_factory'] as const;
export type AppliesOnDefaultFactory = (typeof APPLIES_ON_DEFAULT_FACTORY)[number];
export const APPLIES_ON_UNION_FACTORY = ['factory', 'named_factory', 'union_factory'] as const;
export type AppliesOnUnionFactory = (typeof APPLIES_ON_UNION_FACTORY)[number];
export const APPLIES_ON_MERGED_FACTORY = ['factory', 'named_factory', 'merged_factory'] as const;
export type AppliesOnMergedFactory = (typeof APPLIES_ON_MERGED_FACTORY)[number];
export type AppliesOnNamedFactory = AppliesOnUnionFactory | AppliesOnMergedFactory;
export const APPLIES_ON_FACTORY = [
'factory',
'default_factory',
'named_factory',
'merged_factory',
'union_factory',
];
export type AppliesOnFactory = AppliesOnDefaultFactory | AppliesOnNamedFactory;
export const APPLIES_ON_DEFAULT_FACTORY_PARAMETERS = [
'parameter',
'default_factory_parameter',
] as const;
export type AppliesOnDefaultFactoryParameters =
(typeof APPLIES_ON_DEFAULT_FACTORY_PARAMETERS)[number];
export const APPLIES_ON_UNION_FACTORY_PARAMETERS = [
'parameter',
'named_factory_parameter',
'union_factory_parameter',
] as const;
export type AppliesOnUnionFactoryParameters = (typeof APPLIES_ON_UNION_FACTORY_PARAMETERS)[number];
export const APPLIES_ON_MERGED_FACTORY_PARAMETERS = [
'parameter',
'named_factory_parameter',
'merged_factory_parameter',
] as const;
export type AppliesOnMergedFactoryParameters =
(typeof APPLIES_ON_MERGED_FACTORY_PARAMETERS)[number];
export type AppliesOnNamedParameters =
| AppliesOnUnionFactoryParameters
| AppliesOnMergedFactoryParameters;
export const APPLIES_ON_PARAMETERS = [
'parameter',
'default_factory_parameter',
'named_factory_parameter',
'union_factory_parameter',
'merged_factory_parameter',
] as const;
export type AppliesOnParameters = AppliesOnDefaultFactoryParameters | AppliesOnNamedParameters;
export const APPLIES_ON_ALL_BLOCKS = [
'enum',
'enum_value',
'class',
'factory',
'parameter',
] as const;
export type DartIdentifierCasing = 'snake_case' | 'camelCase' | 'PascalCase';
export type NodeType =
| ObjectTypeDefinitionNode
| InputObjectTypeDefinitionNode
| UnionTypeDefinitionNode
| EnumTypeDefinitionNode;
export type FieldType = FieldDefinitionNode | InputValueDefinitionNode;
export type ObjectType = ObjectTypeDefinitionNode | InputObjectTypeDefinitionNode;
export type ConfigOption = keyof FlutterFreezedPluginConfig;
export type FreezedOption = Extract<
ConfigOption,
| 'copyWith'
| 'equal'
| 'immutable'
| 'makeCollectionsUnmodifiable'
| 'mutableInputs'
| 'privateEmptyConstructor'
>;
export type TypeFieldNameOption = Extract<
ConfigOption,
'defaultValues' | 'deprecated' | 'escapeDartKeywords' | 'final' | 'fromJsonToJson'
>;
export type MultiConstructorOption = FlutterFreezedPluginConfig['unionClass'];
export type UnionValueCase = 'FreezedUnionCase.camel' | 'FreezedUnionCase.pascal';
/**
* maps GraphQL scalar types to Dart's scalar types
*/
export const DART_SCALARS: Record<string, string> = {
ID: 'String',
String: 'String',
Boolean: 'bool',
Int: 'int',
Float: 'double',
DateTime: 'DateTime',
};
export const DART_KEYWORDS = {
abstract: 'built-in',
else: 'reserved',
import: 'built-in',
show: 'context',
as: 'built-in',
enum: 'reserved',
in: 'reserved',
static: 'built-in',
assert: 'reserved',
export: 'built-in',
interface: 'built-in',
super: 'reserved',
async: 'context',
extends: 'reserved',
is: 'reserved',
switch: 'reserved',
await: 'async-reserved',
extension: 'built-in',
late: 'built-in',
sync: 'context',
break: 'reserved',
external: 'built-in',
library: 'built-in',
this: 'reserved',
case: 'reserved',
factory: 'built-in',
mixin: 'built-in',
throw: 'reserved',
catch: 'reserved',
false: 'reserved',
new: 'reserved',
true: 'reserved',
class: 'reserved',
final: 'reserved',
null: 'reserved',
try: 'reserved',
const: 'reserved',
finally: 'reserved',
on: 'context',
typedef: 'built-in',
continue: 'reserved',
for: 'reserved',
operator: 'built-in',
var: 'reserved',
covariant: 'built-in',
Function: 'built-in',
part: 'built-in',
void: 'reserved',
default: 'reserved',
get: 'built-in',
required: 'built-in',
while: 'reserved',
deferred: 'built-in',
hide: 'context',
rethrow: 'reserved',
with: 'reserved',
do: 'reserved',
if: 'reserved',
return: 'reserved',
yield: 'async-reserved',
dynamic: 'built-in',
implements: 'built-in',
set: 'built-in',
// built-in types
int: 'reserved',
double: 'reserved',
String: 'reserved',
bool: 'reserved',
List: 'reserved',
Set: 'reserved',
Map: 'reserved',
Runes: 'reserved',
Symbol: 'reserved',
Object: 'reserved',
Null: 'reserved',
Never: 'reserved',
Enum: 'reserved',
Future: 'reserved',
Iterable: 'reserved',
};
/** initializes a FreezedPluginConfig with the defaults values */
export const defaultFreezedPluginConfig: FlutterFreezedPluginConfig = {
camelCasedEnums: true,
copyWith: undefined,
customScalars: {},
defaultValues: undefined,
deprecated: undefined,
equal: undefined,
escapeDartKeywords: true,
final: undefined,
// fromJsonToJson: true, // TODO: @next-version
ignoreTypes: undefined,
immutable: true,
makeCollectionsUnmodifiable: undefined,
mergeTypes: undefined,
mutableInputs: true,
privateEmptyConstructor: true,
unionClass: undefined,
};
//#endregion