@graphql-codegen/flutter-freezed 2.11.1

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.
Files changed (34) hide show
  1. package/cjs/config.js +2 -0
  2. package/cjs/freezed-declaration-blocks/class-block.js +221 -0
  3. package/cjs/freezed-declaration-blocks/factory-block.js +121 -0
  4. package/cjs/freezed-declaration-blocks/index.js +6 -0
  5. package/cjs/freezed-declaration-blocks/parameter-block.js +150 -0
  6. package/cjs/index.js +27 -0
  7. package/cjs/package.json +1 -0
  8. package/cjs/schema-visitor.js +15 -0
  9. package/cjs/utils.js +221 -0
  10. package/esm/config.js +1 -0
  11. package/esm/freezed-declaration-blocks/class-block.js +217 -0
  12. package/esm/freezed-declaration-blocks/factory-block.js +117 -0
  13. package/esm/freezed-declaration-blocks/index.js +3 -0
  14. package/esm/freezed-declaration-blocks/parameter-block.js +146 -0
  15. package/esm/index.js +23 -0
  16. package/esm/schema-visitor.js +11 -0
  17. package/esm/utils.js +209 -0
  18. package/package.json +46 -0
  19. package/typings/config.d.cts +453 -0
  20. package/typings/config.d.ts +453 -0
  21. package/typings/freezed-declaration-blocks/class-block.d.cts +36 -0
  22. package/typings/freezed-declaration-blocks/class-block.d.ts +36 -0
  23. package/typings/freezed-declaration-blocks/factory-block.d.cts +38 -0
  24. package/typings/freezed-declaration-blocks/factory-block.d.ts +38 -0
  25. package/typings/freezed-declaration-blocks/index.d.cts +3 -0
  26. package/typings/freezed-declaration-blocks/index.d.ts +3 -0
  27. package/typings/freezed-declaration-blocks/parameter-block.d.cts +45 -0
  28. package/typings/freezed-declaration-blocks/parameter-block.d.ts +45 -0
  29. package/typings/index.d.cts +3 -0
  30. package/typings/index.d.ts +3 -0
  31. package/typings/schema-visitor.d.cts +10 -0
  32. package/typings/schema-visitor.d.ts +10 -0
  33. package/typings/utils.d.cts +78 -0
  34. package/typings/utils.d.ts +78 -0
@@ -0,0 +1,453 @@
1
+ /**
2
+ * @name
3
+ * @description Values that are passed to the `DecoratorToFreezed.applyOn` field that specifies where the custom decorator should be applied
4
+ */
5
+ export declare type ApplyDecoratorOn = 'enum' | 'class' | 'class_factory' | 'union_factory' | 'class_factory_parameter' | 'union_factory_parameter';
6
+ export declare type DecoratorToFreezed = {
7
+ /**
8
+ * @name arguments
9
+ * @description arrange the arguments of the directive in order of how the should be outputted
10
+ * @default undefined
11
+ * @exampleMarkdown
12
+ * ```yml
13
+ * arguments: [$0] # $0 is the first argument, $1 is the 2nd ...
14
+ * ```
15
+ */
16
+ arguments?: string[];
17
+ /**
18
+ * @name applyOn
19
+ * @description Specify where the decorator should be applied
20
+ * @exampleMarkdown
21
+ * ```yml
22
+ * applyOn: ['class_factory','union_factory'], # applies this decorator on both class and union factory blocks
23
+ * ```
24
+ */
25
+ applyOn: ApplyDecoratorOn[];
26
+ /**
27
+ * @name mapsToFreezedAs
28
+ * @description maps to a Freezed decorator or use `custom` to use a custom decorator */
29
+ mapsToFreezedAs: '@Default' | '@deprecated' | 'final' | 'directive' | 'custom';
30
+ };
31
+ export declare type CustomDecorator = Record<string, DecoratorToFreezed>;
32
+ export interface FreezedConfig {
33
+ /**
34
+ * @name alwaysUseJsonKeyName
35
+ * @description Use @JsonKey(name: 'name') even if the name is already camelCased
36
+ * @default false
37
+ *
38
+ * @exampleMarkdown
39
+ * ```yml
40
+ * generates:
41
+ * flutter_app/lib/data/models/app_models.dart
42
+ * plugins:
43
+ * - flutter-freezed
44
+ * config:
45
+ * alwaysUseJsonKeyName: true
46
+ *
47
+ * ```
48
+ */
49
+ alwaysUseJsonKeyName?: boolean;
50
+ /**
51
+ * @name copyWith
52
+ * @description set to false to disable Freezed copyWith method helper
53
+ * @default undefined
54
+ *
55
+ * @exampleMarkdown
56
+ * ```yml
57
+ * generates:
58
+ * flutter_app/lib/data/models/app_models.dart
59
+ * plugins:
60
+ * - flutter-freezed
61
+ * config:
62
+ * copyWith: false
63
+ * ```
64
+ */
65
+ copyWith?: boolean;
66
+ /**
67
+ * @name customDecorators
68
+ * @description maps GraphQL directives to freezed decorators. Arguments of the directive are passed using template strings: $1 is the first argument, $2 is the second... All `mapsToFreezedAs` values except `custom` are parsed so use the name of the directive without the `@` symbol as the key of the customDecorators. With the `custom` value, whatever you use as the key of the custom directive is used just as it is, and the arguments spread into a parenthesis ()
69
+ * @default {}
70
+ *
71
+ * @exampleMarkdown
72
+ * ```yml
73
+ * generates:
74
+ * flutter_app/lib/data/models/app_models.dart
75
+ * plugins:
76
+ * - flutter-freezed
77
+ * config:
78
+ * customDecorators: {
79
+ * 'default' : {
80
+ * mapsToFreezedAs: '@Default',
81
+ * arguments: ['$0'],
82
+ * },
83
+ * 'deprecated' : {
84
+ * mapsToFreezedAs: '@deprecated',
85
+ * },
86
+ * 'readonly' : {
87
+ * mapsToFreezedAs: 'final',
88
+ * },
89
+ * '@Assert' : {
90
+ * mapsToFreezedAs: 'custom',
91
+ * applyOn: ['class_factory','union_factory'], # @Assert should ONLY be used on factories
92
+ * arguments: [
93
+ * '(email != null && email != "") || (phoneNumber != null && phoneNumber != "")',
94
+ * 'provide either an email or a phoneNumber',
95
+ * ],
96
+ * }, # custom are used just as it given
97
+ * }
98
+ *
99
+ * ```
100
+ */
101
+ customDecorators?: CustomDecorator;
102
+ /**
103
+ * @name defaultUnionConstructor
104
+ * @description generate empty constructors for Union Types
105
+ * @default true
106
+ *
107
+ * @exampleMarkdown
108
+ * ```yml
109
+ * generates:
110
+ * flutter_app/lib/data/models/app_models.dart
111
+ * plugins:
112
+ * - flutter-freezed
113
+ * config:
114
+ * defaultUnionConstructor: true
115
+ * ```
116
+ */
117
+ defaultUnionConstructor?: boolean;
118
+ /**
119
+ * @name equal
120
+ * @description set to false to disable Freezed equal method helper
121
+ * @default undefined
122
+ *
123
+ * @exampleMarkdown
124
+ * ```yml
125
+ * generates:
126
+ * flutter_app/lib/data/models/app_models.dart
127
+ * plugins:
128
+ * - flutter-freezed
129
+ * config:
130
+ * equal: false
131
+ * ```
132
+ */
133
+ equal?: boolean;
134
+ /**
135
+ * @name fromJsonToJson
136
+ * @description generate fromJson toJson methods on the classes with json_serialization. Requires the [json_serializable](https://pub.dev/packages/json_serializable) to be installed in your Flutter app
137
+ * @default true
138
+ *
139
+ * @exampleMarkdown
140
+ * ```yml
141
+ * generates:
142
+ * flutter_app/lib/data/models/app_models.dart
143
+ * plugins:
144
+ * - flutter-freezed
145
+ * config:
146
+ * fromJsonToJson: true
147
+ *
148
+ * ```
149
+ */
150
+ fromJsonToJson?: boolean;
151
+ /**
152
+ * @name immutable
153
+ * @description set to true to use the `@freezed` decorator or false to use the `@unfreezed` decorator
154
+ * @default true
155
+ *
156
+ * @exampleMarkdown
157
+ * ```yml
158
+ * generates:
159
+ * flutter_app/lib/data/models/app_models.dart
160
+ * plugins:
161
+ * - flutter-freezed
162
+ * config:
163
+ * immutable: true
164
+ *
165
+ * ```
166
+ */
167
+ immutable?: boolean;
168
+ /**
169
+ * @name makeCollectionsUnmodifiable
170
+ * @description allows collections(lists/maps) to be modified even if class is immutable
171
+ * @default undefined
172
+ *
173
+ * @exampleMarkdown
174
+ * ```yml
175
+ * generates:
176
+ * flutter_app/lib/data/models/app_models.dart
177
+ * plugins:
178
+ * - flutter-freezed
179
+ * config:
180
+ * makeCollectionsUnmodifiable: true
181
+ *
182
+ * ```
183
+ */
184
+ makeCollectionsUnmodifiable?: boolean;
185
+ /**
186
+ * @name mergeInputs
187
+ * @description merge InputTypes as a union of an ObjectType where ObjectType is denoted by a $ in the pattern.
188
+ * @default []
189
+ *
190
+ * @exampleMarkdown
191
+ * ```yml
192
+ * generates:
193
+ * flutter_app/lib/data/models/app_models.dart
194
+ * plugins:
195
+ * - flutter-freezed
196
+ * config:
197
+ * mergeInputs: ["Create$Input", "Update$Input", "Delete$Input"]
198
+ * ```
199
+ */
200
+ mergeInputs?: string[];
201
+ /**
202
+ * @name mutableInputs
203
+ * @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`.
204
+ * @default true
205
+ *
206
+ * @exampleMarkdown
207
+ * ```yml
208
+ * generates:
209
+ * flutter_app/lib/data/models/app_models.dart
210
+ * plugins:
211
+ * - flutter-freezed
212
+ * config:
213
+ * mutableInputs: true
214
+ *
215
+ * ```
216
+ */
217
+ mutableInputs?: boolean;
218
+ /**
219
+ * @name privateEmptyConstructor
220
+ * @description if true, defines a private empty constructor to allow getter and methods to work on the class
221
+ * @default true
222
+ *
223
+ * @exampleMarkdown
224
+ * ```yml
225
+ * generates:
226
+ * flutter_app/lib/data/models/app_models.dart
227
+ * plugins:
228
+ * - flutter-freezed
229
+ * config:
230
+ * privateEmptyConstructor: true
231
+ *
232
+ * ```
233
+ */
234
+ privateEmptyConstructor?: boolean;
235
+ /**
236
+ * @name unionKey
237
+ * @description specify the key to be used for Freezed union/sealed classes
238
+ * @default undefined
239
+ *
240
+ * @exampleMarkdown
241
+ * ```yml
242
+ * generates:
243
+ * flutter_app/lib/data/models/app_models.dart
244
+ * plugins:
245
+ * - flutter-freezed
246
+ * config:
247
+ * unionKey: 'type'
248
+ *
249
+ * ```
250
+ */
251
+ unionKey?: string;
252
+ /**
253
+ * @name unionValueCase
254
+ * @description specify the casing style to be used for Freezed union/sealed classes
255
+ * @default undefined
256
+ *
257
+ * @exampleMarkdown
258
+ * ```yml
259
+ * generates:
260
+ * flutter_app/lib/data/models/app_models.dart
261
+ * plugins:
262
+ * - flutter-freezed
263
+ * config:
264
+ * unionValueCase: 'FreezedUnionCase.pascal'
265
+ *
266
+ * ```
267
+ */
268
+ unionValueCase?: 'FreezedUnionCase.camel' | 'FreezedUnionCase.pascal';
269
+ }
270
+ export interface FieldConfig {
271
+ /**
272
+ * @name final
273
+ * @description marks a field as final
274
+ * @default undefined
275
+ */
276
+ final?: boolean;
277
+ /**
278
+ * @name deprecated
279
+ * @description marks a field as deprecated
280
+ * @default undefined
281
+ */
282
+ deprecated?: boolean;
283
+ /**
284
+ * @name defaultValue
285
+ * @description annotate a field with a @Default(value: defaultValue) decorator
286
+ * @default undefined
287
+ */
288
+ defaultValue?: any;
289
+ /**
290
+ * @name customDecorators
291
+ * @description specific directives to apply to the field. All `mapsToFreezedAs` values except `custom` are parsed so use the name of the directive without the `@` symbol as the key of the customDecorators. With the `custom` value, whatever you use as the key of the custom directive is used just as it is, and the arguments spread into a parenthesis ()
292
+ * @default undefined
293
+ * @exampleMarkdown
294
+ * ```yml
295
+ * customDecorators: {
296
+ * 'default' : {
297
+ * mapsToFreezedAs: '@Default',
298
+ * applyOn: ['class_factory_parameter],
299
+ * arguments: ['$0'],
300
+ * },
301
+ * 'deprecated' : {
302
+ * mapsToFreezedAs: '@deprecated',
303
+ * applyOn: ['union_factory_parameter],
304
+ * },
305
+ * 'readonly' : {
306
+ * mapsToFreezedAs: 'final',
307
+ * applyOn: ['class_factory_parameter','union_factory_parameter'],
308
+ * },
309
+ * '@HiveField' : {
310
+ * mapsToFreezedAs: 'custom',
311
+ * applyOn: ['class_factory_parameter'],
312
+ * arguments: ['1'],
313
+ * }, # custom are used just as it given
314
+ * }
315
+ * ```
316
+ */
317
+ customDecorators?: CustomDecorator;
318
+ }
319
+ export interface TypeSpecificFreezedConfig {
320
+ /** marks a type as deprecated */
321
+ deprecated?: boolean;
322
+ /** overrides the `globalFreezedConfig` for this type */
323
+ config?: FreezedConfig;
324
+ /** configure fields for this type */
325
+ fields?: Record<string, FieldConfig>;
326
+ }
327
+ export interface FlutterFreezedPluginConfig {
328
+ /**
329
+ * @name customScalars
330
+ * @description map custom Scalars to Dart built-in types
331
+ * @default {}
332
+ *
333
+ * @exampleMarkdown
334
+ * ```yml
335
+ * generates:
336
+ * flutter_app/lib/data/models/app_models.dart
337
+ * plugins:
338
+ * - flutter-freezed
339
+ * config:
340
+ * customScalars:
341
+ * {
342
+ * "jsonb": "Map<String, dynamic>",
343
+ * "timestamptz": "DateTime",
344
+ * "UUID": "String",
345
+ * }
346
+ * ```
347
+ */
348
+ customScalars?: {
349
+ [name: string]: string;
350
+ };
351
+ /**
352
+ * @name fileName
353
+ * @description if `modular` is set to false, this fileName will be used for the generated output file
354
+ * @default "app_models"
355
+ *
356
+ * @exampleMarkdown
357
+ * ```yml
358
+ * generates:
359
+ * flutter_app/lib/data/models/app_models.dart
360
+ * plugins:
361
+ * - flutter-freezed
362
+ * config:
363
+ * fileName: app_models
364
+ *
365
+ * ```
366
+ */
367
+ fileName?: string;
368
+ /**
369
+ * @name globalFreezedConfig
370
+ * @description use the same Freezed configuration for every generated output
371
+ * @default undefined
372
+ *
373
+ * @exampleMarkdown
374
+ * ```yml
375
+ * generates:
376
+ * flutter_app/lib/data/models/app_models.dart
377
+ * plugins:
378
+ * - flutter-freezed
379
+ * config:
380
+ * globalFreezedConfig:
381
+ * {
382
+ * immutable: false,
383
+ * unionValueCase: FreezedUnionCase.pascal,
384
+ * }
385
+ *
386
+ * ```
387
+ */
388
+ globalFreezedConfig?: FreezedConfig;
389
+ /**
390
+ * @name typeSpecificFreezedConfig
391
+ * @description override the `globalFreezedConfig` for specific types
392
+ * @default undefined
393
+ *
394
+ * @exampleMarkdown
395
+ * ```yml
396
+ * generates:
397
+ * flutter_app/lib/data/models/app_models.dart
398
+ * plugins:
399
+ * - flutter-freezed
400
+ * config:
401
+ * typeSpecificFreezedConfig:
402
+ * {
403
+ * 'Starship':{
404
+ * config: {
405
+ * immutable: false,
406
+ * unionValueCase: FreezedUnionCase.pascal,
407
+ * },
408
+ * fields: {
409
+ * 'id': {
410
+ * final: true,
411
+ * defaultValue: NanoId.id(),
412
+ * },
413
+ * },
414
+ * },
415
+ * },
416
+ *
417
+ * ```
418
+ */
419
+ typeSpecificFreezedConfig?: Record<string, TypeSpecificFreezedConfig>;
420
+ /**
421
+ * @name ignoreTypes
422
+ * @description names of GraphQL types to ignore when generating Freezed classes
423
+ * @default []
424
+ *
425
+ * @exampleMarkdown
426
+ * ```yml
427
+ * generates:
428
+ * flutter_app/lib/data/models/app_models.dart
429
+ * plugins:
430
+ * - flutter-freezed
431
+ * config:
432
+ * ignoreTypes: ["PaginatorInfo"]
433
+ *
434
+ * ```
435
+ */
436
+ ignoreTypes?: string[];
437
+ /**
438
+ * @name lowercaseEnums
439
+ * @description make enum fields lowercase
440
+ * @default true
441
+ *
442
+ * @exampleMarkdown
443
+ * ```yml
444
+ * generates:
445
+ * flutter_app/lib/data/models/app_models.dart
446
+ * plugins:
447
+ * - flutter-freezed
448
+ * config:
449
+ * lowercaseEnums: true
450
+ * ```
451
+ */
452
+ lowercaseEnums?: boolean;
453
+ }