@graphql-codegen/flutter-freezed 2.11.1 → 2.11.2-alpha-20221101104558-48d03d759

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.
@@ -61,7 +61,7 @@ class FreezedDeclarationBlock {
61
61
  // @deprecated
62
62
  // if this._decorators doesn't include an @deprecated decorator but the field is marked as @deprecated...
63
63
  if (!this._decorators.includes('@deprecated') && isDeprecated) {
64
- this._decorators = [...this._decorators, '@deprecated'];
64
+ this._decorators = [...this._decorators, '@deprecated\n'];
65
65
  }
66
66
  return this;
67
67
  }
@@ -69,33 +69,46 @@ class FreezedDeclarationBlock {
69
69
  const use_unfreezed = () => {
70
70
  if (!this._freezedConfigValue.get('immutable') ||
71
71
  (this._node.kind === graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION && this._freezedConfigValue.get('mutableInputs'))) {
72
- return '@unfreezed';
72
+ return '@unfreezed\n';
73
73
  }
74
74
  return use_Freezed_or_freezed();
75
75
  };
76
76
  const use_Freezed_or_freezed = () => {
77
- // if any of these options is not null, use the @Freezed() decorator passing in that option
78
- const [isCustomized, copyWith, equal, makeCollectionsUnmodifiable, unionKey, unionValueCase] = isCustomizedFreezed();
79
- if (isCustomized) {
80
- return `@Freezed(\n
81
- ${copyWith ? (0, visitor_plugin_common_1.indent)(`copyWith: ${copyWith},\n`) : ''}
82
- ${equal ? (0, visitor_plugin_common_1.indent)(`equal: ${equal},\n`) : ''}
83
- ${makeCollectionsUnmodifiable ? (0, visitor_plugin_common_1.indent)(`makeCollectionsUnmodifiable: ${makeCollectionsUnmodifiable},\n`) : ''}
84
- ${unionKey ? (0, visitor_plugin_common_1.indent)(`unionKey: ${unionKey},\n`) : ''}
85
- ${unionValueCase ? (0, visitor_plugin_common_1.indent)(`unionValueCase: ${unionValueCase},\n`) : ''}
86
- )`;
77
+ if (isCustomizedFreezed()) {
78
+ const copyWith = this._freezedConfigValue.get('copyWith');
79
+ const equal = this._freezedConfigValue.get('equal');
80
+ const makeCollectionsUnmodifiable = this._freezedConfigValue.get('makeCollectionsUnmodifiable');
81
+ const unionKey = this._freezedConfigValue.get('unionKey');
82
+ const unionValueCase = this._freezedConfigValue.get('unionValueCase');
83
+ let atFreezed = '@Freezed(\n';
84
+ if (copyWith !== undefined) {
85
+ atFreezed += (0, visitor_plugin_common_1.indent)(`copyWith: ${copyWith},\n`);
86
+ }
87
+ if (equal !== undefined) {
88
+ atFreezed += (0, visitor_plugin_common_1.indent)(`equal: ${equal},\n`);
89
+ }
90
+ if (makeCollectionsUnmodifiable !== undefined) {
91
+ atFreezed += (0, visitor_plugin_common_1.indent)(`makeCollectionsUnmodifiable: ${makeCollectionsUnmodifiable},\n`);
92
+ }
93
+ if (unionKey !== undefined) {
94
+ atFreezed += (0, visitor_plugin_common_1.indent)(`unionKey: ${unionKey},\n`);
95
+ }
96
+ if (unionValueCase !== undefined) {
97
+ atFreezed += (0, visitor_plugin_common_1.indent)(`unionValueCase: '${unionValueCase}',\n`);
98
+ }
99
+ atFreezed += ')\n';
100
+ return atFreezed;
87
101
  }
88
102
  // else fallback to the normal @freezed decorator
89
- return '@freezed';
103
+ return '@freezed\n';
90
104
  };
91
105
  const isCustomizedFreezed = () => {
92
- const copyWith = this._freezedConfigValue.get('copyWith');
93
- const equal = this._freezedConfigValue.get('equal');
94
- const makeCollectionsUnmodifiable = this._freezedConfigValue.get('makeCollectionsUnmodifiable');
95
- const unionKey = this._freezedConfigValue.get('unionKey');
96
- const unionValueCase = this._freezedConfigValue.get('unionValueCase');
97
- const isCustomized = copyWith || equal || makeCollectionsUnmodifiable || unionKey || unionValueCase;
98
- return [isCustomized, copyWith, equal, makeCollectionsUnmodifiable, unionKey, unionValueCase];
106
+ return (this._freezedConfigValue.get('copyWith') !== undefined ||
107
+ this._freezedConfigValue.get('equal') !== undefined ||
108
+ this._freezedConfigValue.get('makeCollectionsUnmodifiable') !== undefined ||
109
+ this._freezedConfigValue.get('unionKey') !== undefined ||
110
+ this._freezedConfigValue.get('unionValueCase') !==
111
+ undefined);
99
112
  };
100
113
  // this is the start of the pipeline of decisions to determine which Freezed decorator to use
101
114
  return use_unfreezed();
@@ -135,7 +148,7 @@ class FreezedDeclarationBlock {
135
148
  this._shape = (_a = this._node.values) === null || _a === void 0 ? void 0 : _a.map((value) => {
136
149
  var _a;
137
150
  shape = (0, visitor_plugin_common_1.indent)(this.getEnumComment(value));
138
- if ((_a = this._config.lowercaseEnums) !== null && _a !== void 0 ? _a : true) {
151
+ if ((_a = this._config.camelCasedEnums) !== null && _a !== void 0 ? _a : true) {
139
152
  shape += `@JsonKey(name: ${value.name.value}) ${value.name.value.toLowerCase()}`;
140
153
  }
141
154
  else {
@@ -170,9 +183,10 @@ class FreezedDeclarationBlock {
170
183
  if (this._node.kind === graphql_1.Kind.OBJECT_TYPE_DEFINITION && mergeInputs) {
171
184
  // replace token for the InputTypes(a.k.a namedConstructors) as a union/sealed class
172
185
  mergeInputs.forEach(input => {
173
- namedConstructor = (0, change_case_all_1.camelCase)(input.split('$').join('_'));
186
+ const separator = input.includes('$') ? '$' : input.includes(name) ? name : '*';
187
+ namedConstructor = (0, change_case_all_1.camelCase)(input.split(separator).join('_'));
174
188
  factoryBlockKey = input.replace('$', name);
175
- shape += `==>factory==>${factoryBlockKey}==>${'union_factory'}==>${name}==>${namedConstructor}\n`;
189
+ shape += `==>factory==>${factoryBlockKey}==>${'merged_input_factory'}==>${name}==>${namedConstructor}\n`;
176
190
  });
177
191
  }
178
192
  }
@@ -187,10 +201,7 @@ class FreezedDeclarationBlock {
187
201
  //append comment
188
202
  block += this._comment;
189
203
  // append the decorators
190
- block += this._decorators.join('\n');
191
- if (this._decorators !== []) {
192
- block += '\n';
193
- }
204
+ block += this._decorators.join('');
194
205
  // handle enums differently
195
206
  if (this._node.kind === graphql_1.Kind.ENUM_TYPE_DEFINITION) {
196
207
  block += `enum ${this._name}{\n${this._shape}}\n\n`;
@@ -64,9 +64,13 @@ class FreezedFactoryBlock {
64
64
  }
65
65
  setParameters() {
66
66
  var _a, _b, _c;
67
+ // TODO: get this from config directly
68
+ const mergeInputs = this._freezedConfigValue.get('mergeInputs');
67
69
  const appliesOn = this._namedConstructor
68
70
  ? ['union_factory_parameter']
69
- : ['class_factory_parameter'];
71
+ : (mergeInputs !== null && mergeInputs !== void 0 ? mergeInputs : mergeInputs !== [])
72
+ ? ['merged_input_parameter']
73
+ : ['class_factory_parameter'];
70
74
  if (this._node.kind !== graphql_1.Kind.UNION_TYPE_DEFINITION && this._node.kind !== graphql_1.Kind.ENUM_TYPE_DEFINITION) {
71
75
  this._parameters =
72
76
  (_c = (_b = (_a = this._node) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.map((field) => new parameter_block_js_1.FreezedParameterBlock(this._config, appliesOn, this._node, field).init())) !== null && _c !== void 0 ? _c : [];
@@ -82,7 +86,7 @@ class FreezedFactoryBlock {
82
86
  //append comment
83
87
  block += this._comment;
84
88
  // append the decorators
85
- block += this._decorators.map(d => (0, visitor_plugin_common_1.indent)(`${d}\n`)).join('');
89
+ block += this._decorators.map(d => (0, visitor_plugin_common_1.indent)(d)).join('');
86
90
  block += (0, visitor_plugin_common_1.indent)('');
87
91
  // decide if to use const or not
88
92
  if (this._freezedConfigValue.get('immutable')) {
@@ -67,7 +67,7 @@ class FreezedParameterBlock {
67
67
  const isDeprecated = (_d = (_c = (_b = (_a = this._config.typeSpecificFreezedConfig) === null || _a === void 0 ? void 0 : _a[nodeName]) === null || _b === void 0 ? void 0 : _b.fields) === null || _c === void 0 ? void 0 : _c[fieldName]) === null || _d === void 0 ? void 0 : _d.deprecated;
68
68
  const defaultValue = (_h = (_g = (_f = (_e = this._config.typeSpecificFreezedConfig) === null || _e === void 0 ? void 0 : _e[nodeName]) === null || _f === void 0 ? void 0 : _f.fields) === null || _g === void 0 ? void 0 : _g[fieldName]) === null || _h === void 0 ? void 0 : _h.defaultValue;
69
69
  if (this._freezedConfigValue.get('alwaysUseJsonKeyName') || fieldName !== (0, change_case_all_1.camelCase)(fieldName)) {
70
- this._decorators = [...this._decorators, `@JsonKey(name: '${fieldName}')`];
70
+ this._decorators = [...this._decorators, `@JsonKey(name: '${fieldName}')\n`];
71
71
  }
72
72
  this._decorators = [
73
73
  ...this._decorators,
@@ -76,13 +76,13 @@ class FreezedParameterBlock {
76
76
  // @deprecated
77
77
  // if this._decorators doesn't include an @deprecated decorator but the field is marked as @deprecated...
78
78
  if (!this._decorators.includes('@deprecated') && isDeprecated) {
79
- this._decorators = [...this._decorators, '@deprecated'];
79
+ this._decorators = [...this._decorators, '@deprecated\n'];
80
80
  }
81
81
  // @Default
82
82
  if (defaultValue) {
83
83
  //overwrite the customDecorator's defaultValue
84
84
  this._decorators = this._decorators.filter(d => !d.startsWith('@Default'));
85
- this._decorators = [...this._decorators, `@Default(value: ${defaultValue})`];
85
+ this._decorators = [...this._decorators, `@Default(value: ${defaultValue})\n`];
86
86
  }
87
87
  return this;
88
88
  }
@@ -112,7 +112,7 @@ class FreezedParameterBlock {
112
112
  // append the decorators
113
113
  shape += this._decorators
114
114
  .filter(d => d !== 'final')
115
- .map(d => (0, visitor_plugin_common_1.indent)(`${d}\n`, 2))
115
+ .map(d => (0, visitor_plugin_common_1.indent)(d, 2))
116
116
  .join('');
117
117
  // append required for non-nullable types
118
118
  shape += (0, visitor_plugin_common_1.indent)(this._required ? 'required ' : '', 2);
package/cjs/index.js CHANGED
@@ -15,13 +15,12 @@ const plugin = (schema, _documents, config) => {
15
15
  const generated = visitorResult.definitions.filter((def) => def instanceof index_js_1.FreezedDeclarationBlock);
16
16
  return ((0, utils_js_1.addFreezedImportStatements)(config.fileName) +
17
17
  generated
18
- .map(freezedDeclarationBlock => freezedDeclarationBlock.toString().replace(/==>factory==>.+/gm, s => {
18
+ .map(freezedDeclarationBlock => freezedDeclarationBlock.toString().replace(/==>factory==>.+\n/gm, s => {
19
19
  const pattern = s.replace('==>factory==>', '').trim();
20
20
  const [key, appliesOn, name, typeName] = pattern.split('==>');
21
- return freezedFactoryBlockRepository.retrieve(key, appliesOn, name, typeName !== null && typeName !== void 0 ? typeName : null).toString();
21
+ return freezedFactoryBlockRepository.retrieve(key, appliesOn, name, typeName !== null && typeName !== void 0 ? typeName : null);
22
22
  }))
23
23
  .join('')
24
- .trim() +
25
- '\n');
24
+ .trim());
26
25
  };
27
26
  exports.plugin = plugin;
package/cjs/utils.js CHANGED
@@ -80,11 +80,11 @@ function transformCustomDecorators(customDecorators, node, field) {
80
80
  // if the custom directives have arguments,
81
81
  if (args && args !== []) {
82
82
  // join them with a comma in the parenthesis
83
- result = [...result, `${key}(${args.join(', ')})`];
83
+ result = [...result, `${key}(${args.join(', ')})\n`];
84
84
  }
85
85
  else {
86
86
  // else return the customDecorator key just as it is
87
- result = [...result, key];
87
+ result = [...result, key + '\n'];
88
88
  }
89
89
  }
90
90
  });
@@ -109,18 +109,18 @@ function directiveToString(directive, customDecorators) {
109
109
  // if the args is not empty
110
110
  if (args !== []) {
111
111
  // returns "@directiveName(argName: argValue, argName: argValue ...)"
112
- return `@${directive.name.value}(${args === null || args === void 0 ? void 0 : args.join(', ')})`;
112
+ return `@${directive.name.value}(${args === null || args === void 0 ? void 0 : args.join(', ')})\n`;
113
113
  }
114
114
  }
115
115
  else if (value.mapsToFreezedAs === '@Default') {
116
116
  const defaultValue = (_c = directive === null || directive === void 0 ? void 0 : directive.arguments) === null || _c === void 0 ? void 0 : _c[argToInt((_e = (_d = value === null || value === void 0 ? void 0 : value.arguments) === null || _d === void 0 ? void 0 : _d[0]) !== null && _e !== void 0 ? _e : '0')];
117
117
  if (defaultValue) {
118
- return `@Default(value: ${defaultValue})`;
118
+ return `@Default(value: ${defaultValue})\n`;
119
119
  }
120
120
  }
121
121
  // returns either "@deprecated" || "final".
122
122
  // `final` to be filtered from the decorators array when applying the decorators
123
- return value.mapsToFreezedAs;
123
+ return value.mapsToFreezedAs + '\n';
124
124
  }
125
125
  /** transforms string template: "$0" into an integer: 1 */
126
126
  function argToInt(arg) {
@@ -133,8 +133,8 @@ function addFreezedImportStatements(fileName) {
133
133
  return [
134
134
  "import 'package:freezed_annotation/freezed_annotation.dart';\n",
135
135
  "import 'package:flutter/foundation.dart';\n\n",
136
- `part ${fileName}.dart;\n`,
137
- `part '${fileName}.g.dart';\n\n`,
136
+ `part ${fileName.replace(/\.dart/g, '')}.dart;\n`,
137
+ `part '${fileName.replace(/\.dart/g, '')}.g.dart';\n\n`,
138
138
  ].join('');
139
139
  }
140
140
  exports.addFreezedImportStatements = addFreezedImportStatements;
@@ -169,17 +169,24 @@ class FreezedFactoryBlockRepository {
169
169
  constructor() {
170
170
  this._store = {};
171
171
  }
172
+ get(key) {
173
+ return this._store[key];
174
+ }
172
175
  register(key, value) {
173
176
  this._store[key] = value;
174
177
  return value;
175
178
  }
176
179
  retrieve(key, appliesOn, name, typeName) {
177
- return this._store[key]
178
- .setDecorators(appliesOn, key)
179
- .setKey(key)
180
- .setName(name)
181
- .setNamedConstructor(typeName)
182
- .init();
180
+ if (this._store[key]) {
181
+ return (this._store[key]
182
+ .setDecorators(appliesOn, key)
183
+ .setKey(key)
184
+ .setName(name)
185
+ .setNamedConstructor(typeName)
186
+ .init()
187
+ .toString() + '\n');
188
+ }
189
+ return '';
183
190
  }
184
191
  }
185
192
  exports.FreezedFactoryBlockRepository = FreezedFactoryBlockRepository;
@@ -188,12 +195,12 @@ class DefaultFreezedPluginConfig {
188
195
  constructor(config = {}) {
189
196
  var _a, _b, _c, _d, _e, _f;
190
197
  Object.assign(this, {
191
- customScalars: (_a = config.customScalars) !== null && _a !== void 0 ? _a : {},
192
- fileName: (_b = config.fileName) !== null && _b !== void 0 ? _b : 'app_models',
193
- globalFreezedConfig: { ...new DefaultFreezedConfig(), ...((_c = config.globalFreezedConfig) !== null && _c !== void 0 ? _c : {}) },
194
- typeSpecificFreezedConfig: (_d = config.typeSpecificFreezedConfig) !== null && _d !== void 0 ? _d : {},
195
- ignoreTypes: (_e = config.ignoreTypes) !== null && _e !== void 0 ? _e : [],
196
- lowercaseEnums: (_f = config.lowercaseEnums) !== null && _f !== void 0 ? _f : true,
198
+ camelCasedEnums: (_a = config.camelCasedEnums) !== null && _a !== void 0 ? _a : true,
199
+ customScalars: (_b = config.customScalars) !== null && _b !== void 0 ? _b : {},
200
+ fileName: (_c = config.fileName) !== null && _c !== void 0 ? _c : 'app_models',
201
+ globalFreezedConfig: { ...new DefaultFreezedConfig(), ...((_d = config.globalFreezedConfig) !== null && _d !== void 0 ? _d : {}) },
202
+ typeSpecificFreezedConfig: (_e = config.typeSpecificFreezedConfig) !== null && _e !== void 0 ? _e : {},
203
+ ignoreTypes: (_f = config.ignoreTypes) !== null && _f !== void 0 ? _f : [],
197
204
  });
198
205
  }
199
206
  }
@@ -58,7 +58,7 @@ export class FreezedDeclarationBlock {
58
58
  // @deprecated
59
59
  // if this._decorators doesn't include an @deprecated decorator but the field is marked as @deprecated...
60
60
  if (!this._decorators.includes('@deprecated') && isDeprecated) {
61
- this._decorators = [...this._decorators, '@deprecated'];
61
+ this._decorators = [...this._decorators, '@deprecated\n'];
62
62
  }
63
63
  return this;
64
64
  }
@@ -66,33 +66,46 @@ export class FreezedDeclarationBlock {
66
66
  const use_unfreezed = () => {
67
67
  if (!this._freezedConfigValue.get('immutable') ||
68
68
  (this._node.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION && this._freezedConfigValue.get('mutableInputs'))) {
69
- return '@unfreezed';
69
+ return '@unfreezed\n';
70
70
  }
71
71
  return use_Freezed_or_freezed();
72
72
  };
73
73
  const use_Freezed_or_freezed = () => {
74
- // if any of these options is not null, use the @Freezed() decorator passing in that option
75
- const [isCustomized, copyWith, equal, makeCollectionsUnmodifiable, unionKey, unionValueCase] = isCustomizedFreezed();
76
- if (isCustomized) {
77
- return `@Freezed(\n
78
- ${copyWith ? indent(`copyWith: ${copyWith},\n`) : ''}
79
- ${equal ? indent(`equal: ${equal},\n`) : ''}
80
- ${makeCollectionsUnmodifiable ? indent(`makeCollectionsUnmodifiable: ${makeCollectionsUnmodifiable},\n`) : ''}
81
- ${unionKey ? indent(`unionKey: ${unionKey},\n`) : ''}
82
- ${unionValueCase ? indent(`unionValueCase: ${unionValueCase},\n`) : ''}
83
- )`;
74
+ if (isCustomizedFreezed()) {
75
+ const copyWith = this._freezedConfigValue.get('copyWith');
76
+ const equal = this._freezedConfigValue.get('equal');
77
+ const makeCollectionsUnmodifiable = this._freezedConfigValue.get('makeCollectionsUnmodifiable');
78
+ const unionKey = this._freezedConfigValue.get('unionKey');
79
+ const unionValueCase = this._freezedConfigValue.get('unionValueCase');
80
+ let atFreezed = '@Freezed(\n';
81
+ if (copyWith !== undefined) {
82
+ atFreezed += indent(`copyWith: ${copyWith},\n`);
83
+ }
84
+ if (equal !== undefined) {
85
+ atFreezed += indent(`equal: ${equal},\n`);
86
+ }
87
+ if (makeCollectionsUnmodifiable !== undefined) {
88
+ atFreezed += indent(`makeCollectionsUnmodifiable: ${makeCollectionsUnmodifiable},\n`);
89
+ }
90
+ if (unionKey !== undefined) {
91
+ atFreezed += indent(`unionKey: ${unionKey},\n`);
92
+ }
93
+ if (unionValueCase !== undefined) {
94
+ atFreezed += indent(`unionValueCase: '${unionValueCase}',\n`);
95
+ }
96
+ atFreezed += ')\n';
97
+ return atFreezed;
84
98
  }
85
99
  // else fallback to the normal @freezed decorator
86
- return '@freezed';
100
+ return '@freezed\n';
87
101
  };
88
102
  const isCustomizedFreezed = () => {
89
- const copyWith = this._freezedConfigValue.get('copyWith');
90
- const equal = this._freezedConfigValue.get('equal');
91
- const makeCollectionsUnmodifiable = this._freezedConfigValue.get('makeCollectionsUnmodifiable');
92
- const unionKey = this._freezedConfigValue.get('unionKey');
93
- const unionValueCase = this._freezedConfigValue.get('unionValueCase');
94
- const isCustomized = copyWith || equal || makeCollectionsUnmodifiable || unionKey || unionValueCase;
95
- return [isCustomized, copyWith, equal, makeCollectionsUnmodifiable, unionKey, unionValueCase];
103
+ return (this._freezedConfigValue.get('copyWith') !== undefined ||
104
+ this._freezedConfigValue.get('equal') !== undefined ||
105
+ this._freezedConfigValue.get('makeCollectionsUnmodifiable') !== undefined ||
106
+ this._freezedConfigValue.get('unionKey') !== undefined ||
107
+ this._freezedConfigValue.get('unionValueCase') !==
108
+ undefined);
96
109
  };
97
110
  // this is the start of the pipeline of decisions to determine which Freezed decorator to use
98
111
  return use_unfreezed();
@@ -132,7 +145,7 @@ export class FreezedDeclarationBlock {
132
145
  this._shape = (_a = this._node.values) === null || _a === void 0 ? void 0 : _a.map((value) => {
133
146
  var _a;
134
147
  shape = indent(this.getEnumComment(value));
135
- if ((_a = this._config.lowercaseEnums) !== null && _a !== void 0 ? _a : true) {
148
+ if ((_a = this._config.camelCasedEnums) !== null && _a !== void 0 ? _a : true) {
136
149
  shape += `@JsonKey(name: ${value.name.value}) ${value.name.value.toLowerCase()}`;
137
150
  }
138
151
  else {
@@ -167,9 +180,10 @@ export class FreezedDeclarationBlock {
167
180
  if (this._node.kind === Kind.OBJECT_TYPE_DEFINITION && mergeInputs) {
168
181
  // replace token for the InputTypes(a.k.a namedConstructors) as a union/sealed class
169
182
  mergeInputs.forEach(input => {
170
- namedConstructor = camelCase(input.split('$').join('_'));
183
+ const separator = input.includes('$') ? '$' : input.includes(name) ? name : '*';
184
+ namedConstructor = camelCase(input.split(separator).join('_'));
171
185
  factoryBlockKey = input.replace('$', name);
172
- shape += `==>factory==>${factoryBlockKey}==>${'union_factory'}==>${name}==>${namedConstructor}\n`;
186
+ shape += `==>factory==>${factoryBlockKey}==>${'merged_input_factory'}==>${name}==>${namedConstructor}\n`;
173
187
  });
174
188
  }
175
189
  }
@@ -184,10 +198,7 @@ export class FreezedDeclarationBlock {
184
198
  //append comment
185
199
  block += this._comment;
186
200
  // append the decorators
187
- block += this._decorators.join('\n');
188
- if (this._decorators !== []) {
189
- block += '\n';
190
- }
201
+ block += this._decorators.join('');
191
202
  // handle enums differently
192
203
  if (this._node.kind === Kind.ENUM_TYPE_DEFINITION) {
193
204
  block += `enum ${this._name}{\n${this._shape}}\n\n`;
@@ -61,9 +61,13 @@ export class FreezedFactoryBlock {
61
61
  }
62
62
  setParameters() {
63
63
  var _a, _b, _c;
64
+ // TODO: get this from config directly
65
+ const mergeInputs = this._freezedConfigValue.get('mergeInputs');
64
66
  const appliesOn = this._namedConstructor
65
67
  ? ['union_factory_parameter']
66
- : ['class_factory_parameter'];
68
+ : (mergeInputs !== null && mergeInputs !== void 0 ? mergeInputs : mergeInputs !== [])
69
+ ? ['merged_input_parameter']
70
+ : ['class_factory_parameter'];
67
71
  if (this._node.kind !== Kind.UNION_TYPE_DEFINITION && this._node.kind !== Kind.ENUM_TYPE_DEFINITION) {
68
72
  this._parameters =
69
73
  (_c = (_b = (_a = this._node) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.map((field) => new FreezedParameterBlock(this._config, appliesOn, this._node, field).init())) !== null && _c !== void 0 ? _c : [];
@@ -79,7 +83,7 @@ export class FreezedFactoryBlock {
79
83
  //append comment
80
84
  block += this._comment;
81
85
  // append the decorators
82
- block += this._decorators.map(d => indent(`${d}\n`)).join('');
86
+ block += this._decorators.map(d => indent(d)).join('');
83
87
  block += indent('');
84
88
  // decide if to use const or not
85
89
  if (this._freezedConfigValue.get('immutable')) {
@@ -64,7 +64,7 @@ export class FreezedParameterBlock {
64
64
  const isDeprecated = (_d = (_c = (_b = (_a = this._config.typeSpecificFreezedConfig) === null || _a === void 0 ? void 0 : _a[nodeName]) === null || _b === void 0 ? void 0 : _b.fields) === null || _c === void 0 ? void 0 : _c[fieldName]) === null || _d === void 0 ? void 0 : _d.deprecated;
65
65
  const defaultValue = (_h = (_g = (_f = (_e = this._config.typeSpecificFreezedConfig) === null || _e === void 0 ? void 0 : _e[nodeName]) === null || _f === void 0 ? void 0 : _f.fields) === null || _g === void 0 ? void 0 : _g[fieldName]) === null || _h === void 0 ? void 0 : _h.defaultValue;
66
66
  if (this._freezedConfigValue.get('alwaysUseJsonKeyName') || fieldName !== camelCase(fieldName)) {
67
- this._decorators = [...this._decorators, `@JsonKey(name: '${fieldName}')`];
67
+ this._decorators = [...this._decorators, `@JsonKey(name: '${fieldName}')\n`];
68
68
  }
69
69
  this._decorators = [
70
70
  ...this._decorators,
@@ -73,13 +73,13 @@ export class FreezedParameterBlock {
73
73
  // @deprecated
74
74
  // if this._decorators doesn't include an @deprecated decorator but the field is marked as @deprecated...
75
75
  if (!this._decorators.includes('@deprecated') && isDeprecated) {
76
- this._decorators = [...this._decorators, '@deprecated'];
76
+ this._decorators = [...this._decorators, '@deprecated\n'];
77
77
  }
78
78
  // @Default
79
79
  if (defaultValue) {
80
80
  //overwrite the customDecorator's defaultValue
81
81
  this._decorators = this._decorators.filter(d => !d.startsWith('@Default'));
82
- this._decorators = [...this._decorators, `@Default(value: ${defaultValue})`];
82
+ this._decorators = [...this._decorators, `@Default(value: ${defaultValue})\n`];
83
83
  }
84
84
  return this;
85
85
  }
@@ -109,7 +109,7 @@ export class FreezedParameterBlock {
109
109
  // append the decorators
110
110
  shape += this._decorators
111
111
  .filter(d => d !== 'final')
112
- .map(d => indent(`${d}\n`, 2))
112
+ .map(d => indent(d, 2))
113
113
  .join('');
114
114
  // append required for non-nullable types
115
115
  shape += indent(this._required ? 'required ' : '', 2);
package/esm/index.js CHANGED
@@ -12,12 +12,11 @@ export const plugin = (schema, _documents, config) => {
12
12
  const generated = visitorResult.definitions.filter((def) => def instanceof FreezedDeclarationBlock);
13
13
  return (addFreezedImportStatements(config.fileName) +
14
14
  generated
15
- .map(freezedDeclarationBlock => freezedDeclarationBlock.toString().replace(/==>factory==>.+/gm, s => {
15
+ .map(freezedDeclarationBlock => freezedDeclarationBlock.toString().replace(/==>factory==>.+\n/gm, s => {
16
16
  const pattern = s.replace('==>factory==>', '').trim();
17
17
  const [key, appliesOn, name, typeName] = pattern.split('==>');
18
- return freezedFactoryBlockRepository.retrieve(key, appliesOn, name, typeName !== null && typeName !== void 0 ? typeName : null).toString();
18
+ return freezedFactoryBlockRepository.retrieve(key, appliesOn, name, typeName !== null && typeName !== void 0 ? typeName : null);
19
19
  }))
20
20
  .join('')
21
- .trim() +
22
- '\n');
21
+ .trim());
23
22
  };
package/esm/utils.js CHANGED
@@ -74,11 +74,11 @@ export function transformCustomDecorators(customDecorators, node, field) {
74
74
  // if the custom directives have arguments,
75
75
  if (args && args !== []) {
76
76
  // join them with a comma in the parenthesis
77
- result = [...result, `${key}(${args.join(', ')})`];
77
+ result = [...result, `${key}(${args.join(', ')})\n`];
78
78
  }
79
79
  else {
80
80
  // else return the customDecorator key just as it is
81
- result = [...result, key];
81
+ result = [...result, key + '\n'];
82
82
  }
83
83
  }
84
84
  });
@@ -102,18 +102,18 @@ function directiveToString(directive, customDecorators) {
102
102
  // if the args is not empty
103
103
  if (args !== []) {
104
104
  // returns "@directiveName(argName: argValue, argName: argValue ...)"
105
- return `@${directive.name.value}(${args === null || args === void 0 ? void 0 : args.join(', ')})`;
105
+ return `@${directive.name.value}(${args === null || args === void 0 ? void 0 : args.join(', ')})\n`;
106
106
  }
107
107
  }
108
108
  else if (value.mapsToFreezedAs === '@Default') {
109
109
  const defaultValue = (_c = directive === null || directive === void 0 ? void 0 : directive.arguments) === null || _c === void 0 ? void 0 : _c[argToInt((_e = (_d = value === null || value === void 0 ? void 0 : value.arguments) === null || _d === void 0 ? void 0 : _d[0]) !== null && _e !== void 0 ? _e : '0')];
110
110
  if (defaultValue) {
111
- return `@Default(value: ${defaultValue})`;
111
+ return `@Default(value: ${defaultValue})\n`;
112
112
  }
113
113
  }
114
114
  // returns either "@deprecated" || "final".
115
115
  // `final` to be filtered from the decorators array when applying the decorators
116
- return value.mapsToFreezedAs;
116
+ return value.mapsToFreezedAs + '\n';
117
117
  }
118
118
  /** transforms string template: "$0" into an integer: 1 */
119
119
  function argToInt(arg) {
@@ -126,8 +126,8 @@ export function addFreezedImportStatements(fileName) {
126
126
  return [
127
127
  "import 'package:freezed_annotation/freezed_annotation.dart';\n",
128
128
  "import 'package:flutter/foundation.dart';\n\n",
129
- `part ${fileName}.dart;\n`,
130
- `part '${fileName}.g.dart';\n\n`,
129
+ `part ${fileName.replace(/\.dart/g, '')}.dart;\n`,
130
+ `part '${fileName.replace(/\.dart/g, '')}.g.dart';\n\n`,
131
131
  ].join('');
132
132
  }
133
133
  /** a class variant of the getFreezedConfigValue helper function
@@ -160,17 +160,24 @@ export class FreezedFactoryBlockRepository {
160
160
  constructor() {
161
161
  this._store = {};
162
162
  }
163
+ get(key) {
164
+ return this._store[key];
165
+ }
163
166
  register(key, value) {
164
167
  this._store[key] = value;
165
168
  return value;
166
169
  }
167
170
  retrieve(key, appliesOn, name, typeName) {
168
- return this._store[key]
169
- .setDecorators(appliesOn, key)
170
- .setKey(key)
171
- .setName(name)
172
- .setNamedConstructor(typeName)
173
- .init();
171
+ if (this._store[key]) {
172
+ return (this._store[key]
173
+ .setDecorators(appliesOn, key)
174
+ .setKey(key)
175
+ .setName(name)
176
+ .setNamedConstructor(typeName)
177
+ .init()
178
+ .toString() + '\n');
179
+ }
180
+ return '';
174
181
  }
175
182
  }
176
183
  /** initializes a FreezedPluginConfig with the defaults values */
@@ -178,12 +185,12 @@ export class DefaultFreezedPluginConfig {
178
185
  constructor(config = {}) {
179
186
  var _a, _b, _c, _d, _e, _f;
180
187
  Object.assign(this, {
181
- customScalars: (_a = config.customScalars) !== null && _a !== void 0 ? _a : {},
182
- fileName: (_b = config.fileName) !== null && _b !== void 0 ? _b : 'app_models',
183
- globalFreezedConfig: { ...new DefaultFreezedConfig(), ...((_c = config.globalFreezedConfig) !== null && _c !== void 0 ? _c : {}) },
184
- typeSpecificFreezedConfig: (_d = config.typeSpecificFreezedConfig) !== null && _d !== void 0 ? _d : {},
185
- ignoreTypes: (_e = config.ignoreTypes) !== null && _e !== void 0 ? _e : [],
186
- lowercaseEnums: (_f = config.lowercaseEnums) !== null && _f !== void 0 ? _f : true,
188
+ camelCasedEnums: (_a = config.camelCasedEnums) !== null && _a !== void 0 ? _a : true,
189
+ customScalars: (_b = config.customScalars) !== null && _b !== void 0 ? _b : {},
190
+ fileName: (_c = config.fileName) !== null && _c !== void 0 ? _c : 'app_models',
191
+ globalFreezedConfig: { ...new DefaultFreezedConfig(), ...((_d = config.globalFreezedConfig) !== null && _d !== void 0 ? _d : {}) },
192
+ typeSpecificFreezedConfig: (_e = config.typeSpecificFreezedConfig) !== null && _e !== void 0 ? _e : {},
193
+ ignoreTypes: (_f = config.ignoreTypes) !== null && _f !== void 0 ? _f : [],
187
194
  });
188
195
  }
189
196
  }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@graphql-codegen/flutter-freezed",
3
- "version": "2.11.1",
3
+ "version": "2.11.2-alpha-20221101104558-48d03d759",
4
4
  "description": "GraphQL Code Generator plugin to generate Freezed models from your GraphQL schema",
5
5
  "peerDependencies": {
6
6
  "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
7
7
  },
8
8
  "dependencies": {
9
- "@graphql-codegen/plugin-helpers": "^2.6.0",
9
+ "@graphql-codegen/plugin-helpers": "2.7.2-alpha-20221101104558-48d03d759",
10
10
  "@graphql-codegen/schema-ast": "^2.5.0",
11
- "@graphql-codegen/visitor-plugin-common": "2.12.0",
11
+ "@graphql-codegen/visitor-plugin-common": "2.13.1-alpha-20221101104558-48d03d759",
12
12
  "auto-bind": "~4.0.0",
13
13
  "tslib": "~2.4.0",
14
14
  "change-case-all": "1.0.14"
@@ -1,15 +1,19 @@
1
1
  /**
2
- * @name
2
+ * @name ApplyDecoratorOn
3
3
  * @description Values that are passed to the `DecoratorToFreezed.applyOn` field that specifies where the custom decorator should be applied
4
4
  */
5
- export declare type ApplyDecoratorOn = 'enum' | 'class' | 'class_factory' | 'union_factory' | 'class_factory_parameter' | 'union_factory_parameter';
5
+ export declare type ApplyDecoratorOn = 'enum' | 'enum_field' | 'class' | 'class_factory' | 'union_factory' | 'merged_input_factory' | 'class_factory_parameter' | 'union_factory_parameter' | 'merged_input_parameter';
6
+ /**
7
+ * @name DecoratorToFreezed
8
+ * @description the value of a `CustomDecorator`. This value specifies how the the decorator should be handled by Freezed
9
+ */
6
10
  export declare type DecoratorToFreezed = {
7
11
  /**
8
12
  * @name arguments
9
- * @description arrange the arguments of the directive in order of how the should be outputted
13
+ * @description Arguments to be applied on the decorator. if the `mapsToFreezedAs === 'directive'`, use template string such `['$0', '$2', '$3']` to select/order the arguments of the directive to be used($0 is the first argument, $1 is the second).
10
14
  * @default undefined
11
15
  * @exampleMarkdown
12
- * ```yml
16
+ * ```yaml
13
17
  * arguments: [$0] # $0 is the first argument, $1 is the 2nd ...
14
18
  * ```
15
19
  */
@@ -18,17 +22,27 @@ export declare type DecoratorToFreezed = {
18
22
  * @name applyOn
19
23
  * @description Specify where the decorator should be applied
20
24
  * @exampleMarkdown
21
- * ```yml
25
+ * ```yaml
22
26
  * applyOn: ['class_factory','union_factory'], # applies this decorator on both class and union factory blocks
23
27
  * ```
24
28
  */
25
29
  applyOn: ApplyDecoratorOn[];
26
30
  /**
27
31
  * @name mapsToFreezedAs
28
- * @description maps to a Freezed decorator or use `custom` to use a custom decorator */
32
+ * @description maps to a Freezed decorator or use `custom` to use a custom decorator.If `mapsToFreezedAs === 'directive'` don't include the `@` prefix in the key of the customDecorator. If `mapsToFreezedAs === 'custom'` value, whatever you use as the key of the customDecorator is used just as it is, and the arguments spread into a parenthesis () */
29
33
  mapsToFreezedAs: '@Default' | '@deprecated' | 'final' | 'directive' | 'custom';
30
34
  };
35
+ /**
36
+ * @name CustomDecorator
37
+ * @description
38
+ * use this option to add annotations/decorators for the the generated output. Also use this to add @Assert decorators to validate the properties of the model
39
+ */
31
40
  export declare type CustomDecorator = Record<string, DecoratorToFreezed>;
41
+ /**
42
+ * @name FreezedConfig
43
+ * @description configure what Freeze should generate
44
+ * @default DefaultFreezedConfig
45
+ */
32
46
  export interface FreezedConfig {
33
47
  /**
34
48
  * @name alwaysUseJsonKeyName
@@ -36,7 +50,7 @@ export interface FreezedConfig {
36
50
  * @default false
37
51
  *
38
52
  * @exampleMarkdown
39
- * ```yml
53
+ * ```yaml
40
54
  * generates:
41
55
  * flutter_app/lib/data/models/app_models.dart
42
56
  * plugins:
@@ -53,7 +67,7 @@ export interface FreezedConfig {
53
67
  * @default undefined
54
68
  *
55
69
  * @exampleMarkdown
56
- * ```yml
70
+ * ```yaml
57
71
  * generates:
58
72
  * flutter_app/lib/data/models/app_models.dart
59
73
  * plugins:
@@ -65,11 +79,11 @@ export interface FreezedConfig {
65
79
  copyWith?: boolean;
66
80
  /**
67
81
  * @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 ()
82
+ * @description annotate/decorate the generated output. Also use this option to map GraphQL directives to freezed decorators.
69
83
  * @default {}
70
84
  *
71
85
  * @exampleMarkdown
72
- * ```yml
86
+ * ```yaml
73
87
  * generates:
74
88
  * flutter_app/lib/data/models/app_models.dart
75
89
  * plugins:
@@ -101,11 +115,11 @@ export interface FreezedConfig {
101
115
  customDecorators?: CustomDecorator;
102
116
  /**
103
117
  * @name defaultUnionConstructor
104
- * @description generate empty constructors for Union Types
118
+ * @description generate empty constructors for Union Types and mergedInputs
105
119
  * @default true
106
120
  *
107
121
  * @exampleMarkdown
108
- * ```yml
122
+ * ```yaml
109
123
  * generates:
110
124
  * flutter_app/lib/data/models/app_models.dart
111
125
  * plugins:
@@ -121,7 +135,7 @@ export interface FreezedConfig {
121
135
  * @default undefined
122
136
  *
123
137
  * @exampleMarkdown
124
- * ```yml
138
+ * ```yaml
125
139
  * generates:
126
140
  * flutter_app/lib/data/models/app_models.dart
127
141
  * plugins:
@@ -137,7 +151,7 @@ export interface FreezedConfig {
137
151
  * @default true
138
152
  *
139
153
  * @exampleMarkdown
140
- * ```yml
154
+ * ```yaml
141
155
  * generates:
142
156
  * flutter_app/lib/data/models/app_models.dart
143
157
  * plugins:
@@ -154,7 +168,7 @@ export interface FreezedConfig {
154
168
  * @default true
155
169
  *
156
170
  * @exampleMarkdown
157
- * ```yml
171
+ * ```yaml
158
172
  * generates:
159
173
  * flutter_app/lib/data/models/app_models.dart
160
174
  * plugins:
@@ -171,7 +185,7 @@ export interface FreezedConfig {
171
185
  * @default undefined
172
186
  *
173
187
  * @exampleMarkdown
174
- * ```yml
188
+ * ```yaml
175
189
  * generates:
176
190
  * flutter_app/lib/data/models/app_models.dart
177
191
  * plugins:
@@ -188,7 +202,7 @@ export interface FreezedConfig {
188
202
  * @default []
189
203
  *
190
204
  * @exampleMarkdown
191
- * ```yml
205
+ * ```yaml
192
206
  * generates:
193
207
  * flutter_app/lib/data/models/app_models.dart
194
208
  * plugins:
@@ -204,7 +218,7 @@ export interface FreezedConfig {
204
218
  * @default true
205
219
  *
206
220
  * @exampleMarkdown
207
- * ```yml
221
+ * ```yaml
208
222
  * generates:
209
223
  * flutter_app/lib/data/models/app_models.dart
210
224
  * plugins:
@@ -221,7 +235,7 @@ export interface FreezedConfig {
221
235
  * @default true
222
236
  *
223
237
  * @exampleMarkdown
224
- * ```yml
238
+ * ```yaml
225
239
  * generates:
226
240
  * flutter_app/lib/data/models/app_models.dart
227
241
  * plugins:
@@ -238,7 +252,7 @@ export interface FreezedConfig {
238
252
  * @default undefined
239
253
  *
240
254
  * @exampleMarkdown
241
- * ```yml
255
+ * ```yaml
242
256
  * generates:
243
257
  * flutter_app/lib/data/models/app_models.dart
244
258
  * plugins:
@@ -255,7 +269,7 @@ export interface FreezedConfig {
255
269
  * @default undefined
256
270
  *
257
271
  * @exampleMarkdown
258
- * ```yml
272
+ * ```yaml
259
273
  * generates:
260
274
  * flutter_app/lib/data/models/app_models.dart
261
275
  * plugins:
@@ -267,6 +281,10 @@ export interface FreezedConfig {
267
281
  */
268
282
  unionValueCase?: 'FreezedUnionCase.camel' | 'FreezedUnionCase.pascal';
269
283
  }
284
+ /**
285
+ * @name FieldConfig
286
+ * @description configuration for the field
287
+ */
270
288
  export interface FieldConfig {
271
289
  /**
272
290
  * @name final
@@ -291,7 +309,7 @@ export interface FieldConfig {
291
309
  * @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
310
  * @default undefined
293
311
  * @exampleMarkdown
294
- * ```yml
312
+ * ```yaml
295
313
  * customDecorators: {
296
314
  * 'default' : {
297
315
  * mapsToFreezedAs: '@Default',
@@ -316,22 +334,46 @@ export interface FieldConfig {
316
334
  */
317
335
  customDecorators?: CustomDecorator;
318
336
  }
337
+ /**
338
+ * @name TypeSpecificFreezedConfig
339
+ * @description override the `FlutterFreezedPluginConfig.globalFreezedConfig` option for a specific type
340
+ */
319
341
  export interface TypeSpecificFreezedConfig {
320
342
  /** marks a type as deprecated */
321
343
  deprecated?: boolean;
322
344
  /** overrides the `globalFreezedConfig` for this type */
323
345
  config?: FreezedConfig;
324
- /** configure fields for this type */
346
+ /** configure fields for this type. The GraphQL field name is the key */
325
347
  fields?: Record<string, FieldConfig>;
326
348
  }
349
+ /**
350
+ * @name FlutterFreezedPluginConfig
351
+ * @description configure the `flutter-freezed` plugin
352
+ */
327
353
  export interface FlutterFreezedPluginConfig {
354
+ /**
355
+ * @name camelCasedEnums
356
+ * @description Dart's recommended lint uses camelCase for enum fields. Set this option to `false` to use the same case as used in the GraphQL Schema but note this can cause lint issues.
357
+ * @default true
358
+ *
359
+ * @exampleMarkdown
360
+ * ```yaml
361
+ * generates:
362
+ * flutter_app/lib/data/models/app_models.dart
363
+ * plugins:
364
+ * - flutter-freezed
365
+ * config:
366
+ * camelCasedEnums: true
367
+ * ```
368
+ */
369
+ camelCasedEnums?: boolean;
328
370
  /**
329
371
  * @name customScalars
330
372
  * @description map custom Scalars to Dart built-in types
331
373
  * @default {}
332
374
  *
333
375
  * @exampleMarkdown
334
- * ```yml
376
+ * ```yaml
335
377
  * generates:
336
378
  * flutter_app/lib/data/models/app_models.dart
337
379
  * plugins:
@@ -350,11 +392,11 @@ export interface FlutterFreezedPluginConfig {
350
392
  };
351
393
  /**
352
394
  * @name fileName
353
- * @description if `modular` is set to false, this fileName will be used for the generated output file
395
+ * @description this fileName will be used for the generated output file
354
396
  * @default "app_models"
355
397
  *
356
398
  * @exampleMarkdown
357
- * ```yml
399
+ * ```yaml
358
400
  * generates:
359
401
  * flutter_app/lib/data/models/app_models.dart
360
402
  * plugins:
@@ -368,10 +410,10 @@ export interface FlutterFreezedPluginConfig {
368
410
  /**
369
411
  * @name globalFreezedConfig
370
412
  * @description use the same Freezed configuration for every generated output
371
- * @default undefined
413
+ * @default DefaultFreezedConfig
372
414
  *
373
415
  * @exampleMarkdown
374
- * ```yml
416
+ * ```yaml
375
417
  * generates:
376
418
  * flutter_app/lib/data/models/app_models.dart
377
419
  * plugins:
@@ -388,11 +430,11 @@ export interface FlutterFreezedPluginConfig {
388
430
  globalFreezedConfig?: FreezedConfig;
389
431
  /**
390
432
  * @name typeSpecificFreezedConfig
391
- * @description override the `globalFreezedConfig` for specific types
433
+ * @description override the `globalFreezedConfig` for specific types. The GraphQL Type name is the key
392
434
  * @default undefined
393
435
  *
394
436
  * @exampleMarkdown
395
- * ```yml
437
+ * ```yaml
396
438
  * generates:
397
439
  * flutter_app/lib/data/models/app_models.dart
398
440
  * plugins:
@@ -423,7 +465,7 @@ export interface FlutterFreezedPluginConfig {
423
465
  * @default []
424
466
  *
425
467
  * @exampleMarkdown
426
- * ```yml
468
+ * ```yaml
427
469
  * generates:
428
470
  * flutter_app/lib/data/models/app_models.dart
429
471
  * plugins:
@@ -434,20 +476,4 @@ export interface FlutterFreezedPluginConfig {
434
476
  * ```
435
477
  */
436
478
  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
479
  }
@@ -1,15 +1,19 @@
1
1
  /**
2
- * @name
2
+ * @name ApplyDecoratorOn
3
3
  * @description Values that are passed to the `DecoratorToFreezed.applyOn` field that specifies where the custom decorator should be applied
4
4
  */
5
- export declare type ApplyDecoratorOn = 'enum' | 'class' | 'class_factory' | 'union_factory' | 'class_factory_parameter' | 'union_factory_parameter';
5
+ export declare type ApplyDecoratorOn = 'enum' | 'enum_field' | 'class' | 'class_factory' | 'union_factory' | 'merged_input_factory' | 'class_factory_parameter' | 'union_factory_parameter' | 'merged_input_parameter';
6
+ /**
7
+ * @name DecoratorToFreezed
8
+ * @description the value of a `CustomDecorator`. This value specifies how the the decorator should be handled by Freezed
9
+ */
6
10
  export declare type DecoratorToFreezed = {
7
11
  /**
8
12
  * @name arguments
9
- * @description arrange the arguments of the directive in order of how the should be outputted
13
+ * @description Arguments to be applied on the decorator. if the `mapsToFreezedAs === 'directive'`, use template string such `['$0', '$2', '$3']` to select/order the arguments of the directive to be used($0 is the first argument, $1 is the second).
10
14
  * @default undefined
11
15
  * @exampleMarkdown
12
- * ```yml
16
+ * ```yaml
13
17
  * arguments: [$0] # $0 is the first argument, $1 is the 2nd ...
14
18
  * ```
15
19
  */
@@ -18,17 +22,27 @@ export declare type DecoratorToFreezed = {
18
22
  * @name applyOn
19
23
  * @description Specify where the decorator should be applied
20
24
  * @exampleMarkdown
21
- * ```yml
25
+ * ```yaml
22
26
  * applyOn: ['class_factory','union_factory'], # applies this decorator on both class and union factory blocks
23
27
  * ```
24
28
  */
25
29
  applyOn: ApplyDecoratorOn[];
26
30
  /**
27
31
  * @name mapsToFreezedAs
28
- * @description maps to a Freezed decorator or use `custom` to use a custom decorator */
32
+ * @description maps to a Freezed decorator or use `custom` to use a custom decorator.If `mapsToFreezedAs === 'directive'` don't include the `@` prefix in the key of the customDecorator. If `mapsToFreezedAs === 'custom'` value, whatever you use as the key of the customDecorator is used just as it is, and the arguments spread into a parenthesis () */
29
33
  mapsToFreezedAs: '@Default' | '@deprecated' | 'final' | 'directive' | 'custom';
30
34
  };
35
+ /**
36
+ * @name CustomDecorator
37
+ * @description
38
+ * use this option to add annotations/decorators for the the generated output. Also use this to add @Assert decorators to validate the properties of the model
39
+ */
31
40
  export declare type CustomDecorator = Record<string, DecoratorToFreezed>;
41
+ /**
42
+ * @name FreezedConfig
43
+ * @description configure what Freeze should generate
44
+ * @default DefaultFreezedConfig
45
+ */
32
46
  export interface FreezedConfig {
33
47
  /**
34
48
  * @name alwaysUseJsonKeyName
@@ -36,7 +50,7 @@ export interface FreezedConfig {
36
50
  * @default false
37
51
  *
38
52
  * @exampleMarkdown
39
- * ```yml
53
+ * ```yaml
40
54
  * generates:
41
55
  * flutter_app/lib/data/models/app_models.dart
42
56
  * plugins:
@@ -53,7 +67,7 @@ export interface FreezedConfig {
53
67
  * @default undefined
54
68
  *
55
69
  * @exampleMarkdown
56
- * ```yml
70
+ * ```yaml
57
71
  * generates:
58
72
  * flutter_app/lib/data/models/app_models.dart
59
73
  * plugins:
@@ -65,11 +79,11 @@ export interface FreezedConfig {
65
79
  copyWith?: boolean;
66
80
  /**
67
81
  * @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 ()
82
+ * @description annotate/decorate the generated output. Also use this option to map GraphQL directives to freezed decorators.
69
83
  * @default {}
70
84
  *
71
85
  * @exampleMarkdown
72
- * ```yml
86
+ * ```yaml
73
87
  * generates:
74
88
  * flutter_app/lib/data/models/app_models.dart
75
89
  * plugins:
@@ -101,11 +115,11 @@ export interface FreezedConfig {
101
115
  customDecorators?: CustomDecorator;
102
116
  /**
103
117
  * @name defaultUnionConstructor
104
- * @description generate empty constructors for Union Types
118
+ * @description generate empty constructors for Union Types and mergedInputs
105
119
  * @default true
106
120
  *
107
121
  * @exampleMarkdown
108
- * ```yml
122
+ * ```yaml
109
123
  * generates:
110
124
  * flutter_app/lib/data/models/app_models.dart
111
125
  * plugins:
@@ -121,7 +135,7 @@ export interface FreezedConfig {
121
135
  * @default undefined
122
136
  *
123
137
  * @exampleMarkdown
124
- * ```yml
138
+ * ```yaml
125
139
  * generates:
126
140
  * flutter_app/lib/data/models/app_models.dart
127
141
  * plugins:
@@ -137,7 +151,7 @@ export interface FreezedConfig {
137
151
  * @default true
138
152
  *
139
153
  * @exampleMarkdown
140
- * ```yml
154
+ * ```yaml
141
155
  * generates:
142
156
  * flutter_app/lib/data/models/app_models.dart
143
157
  * plugins:
@@ -154,7 +168,7 @@ export interface FreezedConfig {
154
168
  * @default true
155
169
  *
156
170
  * @exampleMarkdown
157
- * ```yml
171
+ * ```yaml
158
172
  * generates:
159
173
  * flutter_app/lib/data/models/app_models.dart
160
174
  * plugins:
@@ -171,7 +185,7 @@ export interface FreezedConfig {
171
185
  * @default undefined
172
186
  *
173
187
  * @exampleMarkdown
174
- * ```yml
188
+ * ```yaml
175
189
  * generates:
176
190
  * flutter_app/lib/data/models/app_models.dart
177
191
  * plugins:
@@ -188,7 +202,7 @@ export interface FreezedConfig {
188
202
  * @default []
189
203
  *
190
204
  * @exampleMarkdown
191
- * ```yml
205
+ * ```yaml
192
206
  * generates:
193
207
  * flutter_app/lib/data/models/app_models.dart
194
208
  * plugins:
@@ -204,7 +218,7 @@ export interface FreezedConfig {
204
218
  * @default true
205
219
  *
206
220
  * @exampleMarkdown
207
- * ```yml
221
+ * ```yaml
208
222
  * generates:
209
223
  * flutter_app/lib/data/models/app_models.dart
210
224
  * plugins:
@@ -221,7 +235,7 @@ export interface FreezedConfig {
221
235
  * @default true
222
236
  *
223
237
  * @exampleMarkdown
224
- * ```yml
238
+ * ```yaml
225
239
  * generates:
226
240
  * flutter_app/lib/data/models/app_models.dart
227
241
  * plugins:
@@ -238,7 +252,7 @@ export interface FreezedConfig {
238
252
  * @default undefined
239
253
  *
240
254
  * @exampleMarkdown
241
- * ```yml
255
+ * ```yaml
242
256
  * generates:
243
257
  * flutter_app/lib/data/models/app_models.dart
244
258
  * plugins:
@@ -255,7 +269,7 @@ export interface FreezedConfig {
255
269
  * @default undefined
256
270
  *
257
271
  * @exampleMarkdown
258
- * ```yml
272
+ * ```yaml
259
273
  * generates:
260
274
  * flutter_app/lib/data/models/app_models.dart
261
275
  * plugins:
@@ -267,6 +281,10 @@ export interface FreezedConfig {
267
281
  */
268
282
  unionValueCase?: 'FreezedUnionCase.camel' | 'FreezedUnionCase.pascal';
269
283
  }
284
+ /**
285
+ * @name FieldConfig
286
+ * @description configuration for the field
287
+ */
270
288
  export interface FieldConfig {
271
289
  /**
272
290
  * @name final
@@ -291,7 +309,7 @@ export interface FieldConfig {
291
309
  * @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
310
  * @default undefined
293
311
  * @exampleMarkdown
294
- * ```yml
312
+ * ```yaml
295
313
  * customDecorators: {
296
314
  * 'default' : {
297
315
  * mapsToFreezedAs: '@Default',
@@ -316,22 +334,46 @@ export interface FieldConfig {
316
334
  */
317
335
  customDecorators?: CustomDecorator;
318
336
  }
337
+ /**
338
+ * @name TypeSpecificFreezedConfig
339
+ * @description override the `FlutterFreezedPluginConfig.globalFreezedConfig` option for a specific type
340
+ */
319
341
  export interface TypeSpecificFreezedConfig {
320
342
  /** marks a type as deprecated */
321
343
  deprecated?: boolean;
322
344
  /** overrides the `globalFreezedConfig` for this type */
323
345
  config?: FreezedConfig;
324
- /** configure fields for this type */
346
+ /** configure fields for this type. The GraphQL field name is the key */
325
347
  fields?: Record<string, FieldConfig>;
326
348
  }
349
+ /**
350
+ * @name FlutterFreezedPluginConfig
351
+ * @description configure the `flutter-freezed` plugin
352
+ */
327
353
  export interface FlutterFreezedPluginConfig {
354
+ /**
355
+ * @name camelCasedEnums
356
+ * @description Dart's recommended lint uses camelCase for enum fields. Set this option to `false` to use the same case as used in the GraphQL Schema but note this can cause lint issues.
357
+ * @default true
358
+ *
359
+ * @exampleMarkdown
360
+ * ```yaml
361
+ * generates:
362
+ * flutter_app/lib/data/models/app_models.dart
363
+ * plugins:
364
+ * - flutter-freezed
365
+ * config:
366
+ * camelCasedEnums: true
367
+ * ```
368
+ */
369
+ camelCasedEnums?: boolean;
328
370
  /**
329
371
  * @name customScalars
330
372
  * @description map custom Scalars to Dart built-in types
331
373
  * @default {}
332
374
  *
333
375
  * @exampleMarkdown
334
- * ```yml
376
+ * ```yaml
335
377
  * generates:
336
378
  * flutter_app/lib/data/models/app_models.dart
337
379
  * plugins:
@@ -350,11 +392,11 @@ export interface FlutterFreezedPluginConfig {
350
392
  };
351
393
  /**
352
394
  * @name fileName
353
- * @description if `modular` is set to false, this fileName will be used for the generated output file
395
+ * @description this fileName will be used for the generated output file
354
396
  * @default "app_models"
355
397
  *
356
398
  * @exampleMarkdown
357
- * ```yml
399
+ * ```yaml
358
400
  * generates:
359
401
  * flutter_app/lib/data/models/app_models.dart
360
402
  * plugins:
@@ -368,10 +410,10 @@ export interface FlutterFreezedPluginConfig {
368
410
  /**
369
411
  * @name globalFreezedConfig
370
412
  * @description use the same Freezed configuration for every generated output
371
- * @default undefined
413
+ * @default DefaultFreezedConfig
372
414
  *
373
415
  * @exampleMarkdown
374
- * ```yml
416
+ * ```yaml
375
417
  * generates:
376
418
  * flutter_app/lib/data/models/app_models.dart
377
419
  * plugins:
@@ -388,11 +430,11 @@ export interface FlutterFreezedPluginConfig {
388
430
  globalFreezedConfig?: FreezedConfig;
389
431
  /**
390
432
  * @name typeSpecificFreezedConfig
391
- * @description override the `globalFreezedConfig` for specific types
433
+ * @description override the `globalFreezedConfig` for specific types. The GraphQL Type name is the key
392
434
  * @default undefined
393
435
  *
394
436
  * @exampleMarkdown
395
- * ```yml
437
+ * ```yaml
396
438
  * generates:
397
439
  * flutter_app/lib/data/models/app_models.dart
398
440
  * plugins:
@@ -423,7 +465,7 @@ export interface FlutterFreezedPluginConfig {
423
465
  * @default []
424
466
  *
425
467
  * @exampleMarkdown
426
- * ```yml
468
+ * ```yaml
427
469
  * generates:
428
470
  * flutter_app/lib/data/models/app_models.dart
429
471
  * plugins:
@@ -434,20 +476,4 @@ export interface FlutterFreezedPluginConfig {
434
476
  * ```
435
477
  */
436
478
  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
479
  }
@@ -33,7 +33,7 @@ export declare class FreezedConfigValue {
33
33
  * for a specific type if given typeName
34
34
  * or else fallback to the global FreezedConfig value
35
35
  */
36
- get(option: OptionName): any;
36
+ get<T>(option: OptionName): T;
37
37
  }
38
38
  /**
39
39
  * stores an instance of FreezedFactoryBlock using the node names as the key
@@ -41,11 +41,13 @@ export declare class FreezedConfigValue {
41
41
  * */
42
42
  export declare class FreezedFactoryBlockRepository {
43
43
  _store: Record<string, FreezedFactoryBlock>;
44
+ get(key: string): FreezedFactoryBlock | undefined;
44
45
  register(key: string, value: FreezedFactoryBlock): FreezedFactoryBlock;
45
- retrieve(key: string, appliesOn: string, name: string, typeName: string | undefined): FreezedFactoryBlock;
46
+ retrieve(key: string, appliesOn: string, name: string, typeName: string | undefined): string;
46
47
  }
47
48
  /** initializes a FreezedPluginConfig with the defaults values */
48
49
  export declare class DefaultFreezedPluginConfig implements FlutterFreezedPluginConfig {
50
+ camelCasedEnums?: boolean;
49
51
  customScalars?: {
50
52
  [name: string]: string;
51
53
  };
@@ -53,10 +55,6 @@ export declare class DefaultFreezedPluginConfig implements FlutterFreezedPluginC
53
55
  globalFreezedConfig?: FreezedConfig;
54
56
  typeSpecificFreezedConfig?: Record<string, TypeSpecificFreezedConfig>;
55
57
  ignoreTypes?: string[];
56
- interfaceNamePrefix?: string;
57
- interfaceNameSuffix?: string;
58
- lowercaseEnums?: boolean;
59
- modular?: boolean;
60
58
  constructor(config?: FlutterFreezedPluginConfig);
61
59
  }
62
60
  /** initializes a FreezedConfig with the defaults values */
@@ -33,7 +33,7 @@ export declare class FreezedConfigValue {
33
33
  * for a specific type if given typeName
34
34
  * or else fallback to the global FreezedConfig value
35
35
  */
36
- get(option: OptionName): any;
36
+ get<T>(option: OptionName): T;
37
37
  }
38
38
  /**
39
39
  * stores an instance of FreezedFactoryBlock using the node names as the key
@@ -41,11 +41,13 @@ export declare class FreezedConfigValue {
41
41
  * */
42
42
  export declare class FreezedFactoryBlockRepository {
43
43
  _store: Record<string, FreezedFactoryBlock>;
44
+ get(key: string): FreezedFactoryBlock | undefined;
44
45
  register(key: string, value: FreezedFactoryBlock): FreezedFactoryBlock;
45
- retrieve(key: string, appliesOn: string, name: string, typeName: string | undefined): FreezedFactoryBlock;
46
+ retrieve(key: string, appliesOn: string, name: string, typeName: string | undefined): string;
46
47
  }
47
48
  /** initializes a FreezedPluginConfig with the defaults values */
48
49
  export declare class DefaultFreezedPluginConfig implements FlutterFreezedPluginConfig {
50
+ camelCasedEnums?: boolean;
49
51
  customScalars?: {
50
52
  [name: string]: string;
51
53
  };
@@ -53,10 +55,6 @@ export declare class DefaultFreezedPluginConfig implements FlutterFreezedPluginC
53
55
  globalFreezedConfig?: FreezedConfig;
54
56
  typeSpecificFreezedConfig?: Record<string, TypeSpecificFreezedConfig>;
55
57
  ignoreTypes?: string[];
56
- interfaceNamePrefix?: string;
57
- interfaceNameSuffix?: string;
58
- lowercaseEnums?: boolean;
59
- modular?: boolean;
60
58
  constructor(config?: FlutterFreezedPluginConfig);
61
59
  }
62
60
  /** initializes a FreezedConfig with the defaults values */