@graphql-codegen/flutter-freezed 2.11.2 → 3.0.1-alpha-20230130180936-04996f117

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 (53) hide show
  1. package/cjs/config/config-value.js +132 -0
  2. package/cjs/config/pattern.js +731 -0
  3. package/cjs/config/plugin-config.js +141 -0
  4. package/cjs/freezed-declaration-blocks/class-block.js +86 -224
  5. package/cjs/freezed-declaration-blocks/enum-block.js +54 -0
  6. package/cjs/freezed-declaration-blocks/factory-block.js +81 -113
  7. package/cjs/freezed-declaration-blocks/index.js +91 -4
  8. package/cjs/freezed-declaration-blocks/node-repository.js +26 -0
  9. package/cjs/freezed-declaration-blocks/parameter-block.js +55 -143
  10. package/cjs/index.js +10 -14
  11. package/cjs/schema-visitor.js +8 -7
  12. package/cjs/utils.js +64 -219
  13. package/esm/config/config-value.js +128 -0
  14. package/esm/config/pattern.js +723 -0
  15. package/esm/config/plugin-config.js +138 -0
  16. package/esm/freezed-declaration-blocks/class-block.js +85 -223
  17. package/esm/freezed-declaration-blocks/enum-block.js +50 -0
  18. package/esm/freezed-declaration-blocks/factory-block.js +81 -113
  19. package/esm/freezed-declaration-blocks/index.js +89 -3
  20. package/esm/freezed-declaration-blocks/node-repository.js +22 -0
  21. package/esm/freezed-declaration-blocks/parameter-block.js +53 -141
  22. package/esm/index.js +11 -15
  23. package/esm/schema-visitor.js +8 -7
  24. package/esm/utils.js +56 -212
  25. package/package.json +5 -5
  26. package/typings/config/config-value.d.cts +24 -0
  27. package/typings/config/config-value.d.ts +24 -0
  28. package/typings/config/pattern.d.cts +252 -0
  29. package/typings/config/pattern.d.ts +252 -0
  30. package/typings/config/plugin-config.d.cts +727 -0
  31. package/typings/config/plugin-config.d.ts +727 -0
  32. package/typings/freezed-declaration-blocks/class-block.d.cts +11 -35
  33. package/typings/freezed-declaration-blocks/class-block.d.ts +11 -35
  34. package/typings/freezed-declaration-blocks/enum-block.d.cts +10 -0
  35. package/typings/freezed-declaration-blocks/enum-block.d.ts +10 -0
  36. package/typings/freezed-declaration-blocks/factory-block.d.cts +16 -37
  37. package/typings/freezed-declaration-blocks/factory-block.d.ts +16 -37
  38. package/typings/freezed-declaration-blocks/index.d.cts +27 -3
  39. package/typings/freezed-declaration-blocks/index.d.ts +27 -3
  40. package/typings/freezed-declaration-blocks/node-repository.d.cts +10 -0
  41. package/typings/freezed-declaration-blocks/node-repository.d.ts +10 -0
  42. package/typings/freezed-declaration-blocks/parameter-block.d.cts +11 -44
  43. package/typings/freezed-declaration-blocks/parameter-block.d.ts +11 -44
  44. package/typings/index.d.cts +1 -1
  45. package/typings/index.d.ts +1 -1
  46. package/typings/schema-visitor.d.cts +7 -7
  47. package/typings/schema-visitor.d.ts +7 -7
  48. package/typings/utils.d.cts +33 -72
  49. package/typings/utils.d.ts +33 -72
  50. package/cjs/config.js +0 -2
  51. package/esm/config.js +0 -1
  52. package/typings/config.d.cts +0 -479
  53. package/typings/config.d.ts +0 -479
package/cjs/utils.js CHANGED
@@ -1,228 +1,73 @@
1
1
  "use strict";
2
+ //#region helpers
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultFreezedConfig = exports.DefaultFreezedPluginConfig = exports.FreezedFactoryBlockRepository = exports.FreezedConfigValue = exports.addFreezedImportStatements = exports.transformCustomDecorators = exports.getCustomDecorators = exports.getFreezedConfigValue = exports.transformDefinition = void 0;
4
- const index_js_1 = require("./freezed-declaration-blocks/index.js");
5
- function transformDefinition(config, freezedFactoryBlockRepository, node) {
6
- var _a;
7
- // ignore these...
8
- if (['Query', 'Mutation', 'Subscription', ...((_a = config === null || config === void 0 ? void 0 : config.ignoreTypes) !== null && _a !== void 0 ? _a : [])].includes(node.name.value)) {
9
- return '';
4
+ exports.stringIsNotEmpty = exports.atJsonKeyDecorator = exports.escapeDartKeyword = exports.isDartKeyword = exports.dartCasing = exports.appliesOnBlock = exports.nodeIsObjectType = exports.resetIndex = exports.arrayWrap = exports.strToList = void 0;
5
+ const change_case_all_1 = require("change-case-all");
6
+ const graphql_1 = require("graphql");
7
+ const config_value_js_1 = require("./config/config-value.js");
8
+ const plugin_config_js_1 = require("./config/plugin-config.js");
9
+ const strToList = (str) => (str.length < 1 ? [] : str.split(/\s*,\s*/gim).filter(s => s.length > 0));
10
+ exports.strToList = strToList;
11
+ const arrayWrap = (value) => value === undefined ? [] : Array.isArray(value) ? value : [value];
12
+ exports.arrayWrap = arrayWrap;
13
+ const resetIndex = (regexp) => (regexp.lastIndex = 0);
14
+ exports.resetIndex = resetIndex;
15
+ const nodeIsObjectType = (node) => node.kind === graphql_1.Kind.OBJECT_TYPE_DEFINITION || node.kind === graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION;
16
+ exports.nodeIsObjectType = nodeIsObjectType;
17
+ const appliesOnBlock = (configAppliesOn, blockAppliesOn) => configAppliesOn.some(a => blockAppliesOn.includes(a));
18
+ exports.appliesOnBlock = appliesOnBlock;
19
+ const dartCasing = (name, casing) => {
20
+ if (casing === 'camelCase') {
21
+ return (0, change_case_all_1.camelCase)(name);
10
22
  }
11
- return new index_js_1.FreezedDeclarationBlock(config, freezedFactoryBlockRepository, node).init();
12
- }
13
- exports.transformDefinition = transformDefinition;
14
- /**
15
- * returns the value of the FreezedConfig option
16
- * for a specific type if given typeName
17
- * or else fallback to the global FreezedConfig value
18
- */
19
- function getFreezedConfigValue(option, config, typeName) {
20
- var _a, _b, _c, _d, _e;
21
- if (typeName) {
22
- return (_d = (_c = (_b = (_a = config === null || config === void 0 ? void 0 : config.typeSpecificFreezedConfig) === null || _a === void 0 ? void 0 : _a[typeName]) === null || _b === void 0 ? void 0 : _b.config) === null || _c === void 0 ? void 0 : _c[option]) !== null && _d !== void 0 ? _d : getFreezedConfigValue(option, config);
23
+ else if (casing === 'PascalCase') {
24
+ return (0, change_case_all_1.pascalCase)(name);
23
25
  }
24
- return (_e = config === null || config === void 0 ? void 0 : config.globalFreezedConfig) === null || _e === void 0 ? void 0 : _e[option];
25
- }
26
- exports.getFreezedConfigValue = getFreezedConfigValue;
27
- /**
28
- * @description filters the customDirectives to return those that are applied on a list of blocks
29
- */
30
- function getCustomDecorators(config, appliesOn, nodeName, fieldName) {
31
- var _a, _b, _c, _d, _e, _f, _g, _h;
32
- const filteredCustomDecorators = {};
33
- const globalCustomDecorators = (_b = (_a = config === null || config === void 0 ? void 0 : config.globalFreezedConfig) === null || _a === void 0 ? void 0 : _a.customDecorators) !== null && _b !== void 0 ? _b : {};
34
- let customDecorators = { ...globalCustomDecorators };
35
- if (nodeName) {
36
- const typeConfig = (_c = config === null || config === void 0 ? void 0 : config.typeSpecificFreezedConfig) === null || _c === void 0 ? void 0 : _c[nodeName];
37
- const typeSpecificCustomDecorators = (_e = (_d = typeConfig === null || typeConfig === void 0 ? void 0 : typeConfig.config) === null || _d === void 0 ? void 0 : _d.customDecorators) !== null && _e !== void 0 ? _e : {};
38
- customDecorators = { ...customDecorators, ...typeSpecificCustomDecorators };
39
- if (fieldName) {
40
- const fieldSpecificCustomDecorators = (_h = (_g = (_f = typeConfig === null || typeConfig === void 0 ? void 0 : typeConfig.fields) === null || _f === void 0 ? void 0 : _f[fieldName]) === null || _g === void 0 ? void 0 : _g.customDecorators) !== null && _h !== void 0 ? _h : {};
41
- customDecorators = { ...customDecorators, ...fieldSpecificCustomDecorators };
42
- }
26
+ else if (casing === 'snake_case') {
27
+ return (0, change_case_all_1.snakeCase)(name);
43
28
  }
44
- Object.entries(customDecorators).forEach(([key, value]) => {
45
- var _a;
46
- return (_a = value === null || value === void 0 ? void 0 : value.applyOn) === null || _a === void 0 ? void 0 : _a.forEach(a => {
47
- if (appliesOn.includes(a)) {
48
- filteredCustomDecorators[key] = value;
49
- }
50
- });
51
- });
52
- return filteredCustomDecorators;
53
- }
54
- exports.getCustomDecorators = getCustomDecorators;
55
- function transformCustomDecorators(customDecorators, node, field) {
56
- var _a, _b;
57
- let result = [];
58
- result = [
59
- ...result,
60
- ...((_a = node === null || node === void 0 ? void 0 : node.directives) !== null && _a !== void 0 ? _a : [])
61
- .concat((_b = field === null || field === void 0 ? void 0 : field.directives) !== null && _b !== void 0 ? _b : [])
62
- // extract only the directives whose names were specified as keys
63
- // and have values that not undefined or null in the customDecorator record
64
- .filter(d => {
65
- var _a;
66
- const key = d.name.value;
67
- const value = (_a = customDecorators[key]) !== null && _a !== void 0 ? _a : customDecorators[`@${key}`];
68
- if (value && value.mapsToFreezedAs !== 'custom') {
69
- return true;
70
- }
71
- return false;
72
- })
73
- // transform each directive to string
74
- .map(d => directiveToString(d, customDecorators)),
75
- ];
76
- // for decorators that mapsToFreezedAs === 'custom'
77
- Object.entries(customDecorators).forEach(([key, value]) => {
78
- if (value.mapsToFreezedAs === 'custom') {
79
- const args = value === null || value === void 0 ? void 0 : value.arguments;
80
- // if the custom directives have arguments,
81
- if (args && args !== []) {
82
- // join them with a comma in the parenthesis
83
- result = [...result, `${key}(${args.join(', ')})\n`];
84
- }
85
- else {
86
- // else return the customDecorator key just as it is
87
- result = [...result, key + '\n'];
88
- }
89
- }
90
- });
91
- return result;
92
- }
93
- exports.transformCustomDecorators = transformCustomDecorators;
29
+ return name;
30
+ };
31
+ exports.dartCasing = dartCasing;
94
32
  /**
95
- * transforms the directive into a decorator array
96
- * this decorator array might contain a `final` string which would be filtered out
97
- * and used to mark the parameter block as final
33
+ * checks whether name is a Dart Language keyword
34
+ * @param identifier The name or identifier to be checked
35
+ * @returns `true` if name is a Dart Language keyword, otherwise `false`
98
36
  */
99
- function directiveToString(directive, customDecorators) {
100
- var _a, _b, _c, _d, _e;
101
- const key = directive.name.value;
102
- const value = customDecorators[key];
103
- if (value.mapsToFreezedAs === 'directive') {
104
- // get the directive's arguments
105
- const directiveArgs = (_a = directive === null || directive === void 0 ? void 0 : directive.arguments) !== null && _a !== void 0 ? _a : [];
106
- // extract the directive's argument using the template index: ["$0", "$1", ...]
107
- // specified in the customDecorator.arguments array
108
- const args = (_b = value === null || value === void 0 ? void 0 : value.arguments) === null || _b === void 0 ? void 0 : _b.filter(a => directiveArgs[argToInt(a)]).map(a => directiveArgs[argToInt(a)]).map(a => `${a.name}: ${a.value}`);
109
- // if the args is not empty
110
- if (args !== []) {
111
- // returns "@directiveName(argName: argValue, argName: argValue ...)"
112
- return `@${directive.name.value}(${args === null || args === void 0 ? void 0 : args.join(', ')})\n`;
113
- }
114
- }
115
- else if (value.mapsToFreezedAs === '@Default') {
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
- if (defaultValue) {
118
- return `@Default(value: ${defaultValue})\n`;
119
- }
120
- }
121
- // returns either "@deprecated" || "final".
122
- // `final` to be filtered from the decorators array when applying the decorators
123
- return value.mapsToFreezedAs + '\n';
124
- }
125
- /** transforms string template: "$0" into an integer: 1 */
126
- function argToInt(arg) {
127
- var _a;
128
- const parsedIndex = Number.parseInt((_a = arg.replace('$', '').trim()) !== null && _a !== void 0 ? _a : '0'); // '$1 => 1
129
- return parsedIndex ? parsedIndex : 0;
130
- }
131
- /** returns freezed import statements */
132
- function addFreezedImportStatements(fileName) {
133
- return [
134
- "import 'package:freezed_annotation/freezed_annotation.dart';\n",
135
- "import 'package:flutter/foundation.dart';\n\n",
136
- `part ${fileName.replace(/\.dart/g, '')}.dart;\n`,
137
- `part '${fileName.replace(/\.dart/g, '')}.g.dart';\n\n`,
138
- ].join('');
139
- }
140
- exports.addFreezedImportStatements = addFreezedImportStatements;
141
- /** a class variant of the getFreezedConfigValue helper function
142
- *
143
- * returns the value of the FreezedConfig option
144
- * for a specific type if given typeName
145
- * or else fallback to the global FreezedConfig value
146
- */
147
- class FreezedConfigValue {
148
- constructor(_config, _typeName) {
149
- this._config = _config;
150
- this._typeName = _typeName;
151
- this._config = _config;
152
- this._typeName = _typeName;
153
- }
154
- /**
155
- * returns the value of the FreezedConfig option
156
- * for a specific type if given typeName
157
- * or else fallback to the global FreezedConfig value
158
- */
159
- get(option) {
160
- return getFreezedConfigValue(option, this._config, this._typeName);
161
- }
162
- }
163
- exports.FreezedConfigValue = FreezedConfigValue;
37
+ const isDartKeyword = (identifier) => plugin_config_js_1.DART_KEYWORDS[identifier] !== undefined;
38
+ exports.isDartKeyword = isDartKeyword;
164
39
  /**
165
- * stores an instance of FreezedFactoryBlock using the node names as the key
166
- * and returns that instance when replacing tokens
167
- * */
168
- class FreezedFactoryBlockRepository {
169
- constructor() {
170
- this._store = {};
171
- }
172
- get(key) {
173
- return this._store[key];
174
- }
175
- register(key, value) {
176
- this._store[key] = value;
177
- return value;
178
- }
179
- retrieve(key, appliesOn, name, typeName) {
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 '';
190
- }
191
- }
192
- exports.FreezedFactoryBlockRepository = FreezedFactoryBlockRepository;
193
- /** initializes a FreezedPluginConfig with the defaults values */
194
- class DefaultFreezedPluginConfig {
195
- constructor(config = {}) {
196
- var _a, _b, _c, _d, _e, _f;
197
- Object.assign(this, {
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 : [],
204
- });
205
- }
206
- }
207
- exports.DefaultFreezedPluginConfig = DefaultFreezedPluginConfig;
208
- /** initializes a FreezedConfig with the defaults values */
209
- class DefaultFreezedConfig {
210
- constructor() {
211
- Object.assign(this, {
212
- alwaysUseJsonKeyName: false,
213
- copyWith: undefined,
214
- customDecorators: {},
215
- defaultUnionConstructor: true,
216
- equal: undefined,
217
- fromJsonToJson: true,
218
- immutable: true,
219
- makeCollectionsUnmodifiable: undefined,
220
- mergeInputs: [],
221
- mutableInputs: true,
222
- privateEmptyConstructor: true,
223
- unionKey: undefined,
224
- unionValueCase: undefined,
225
- });
40
+ * Ensures that the blockName isn't a valid Dart language reserved keyword.
41
+ * It wraps the identifier with the prefix and suffix then transforms the casing as specified in the config
42
+ * @param config
43
+ * @param name
44
+ * @param typeName
45
+ * @returns
46
+ */
47
+ const escapeDartKeyword = (config, blockAppliesOn, identifier, typeName, fieldName) => {
48
+ if ((0, exports.isDartKeyword)(identifier)) {
49
+ const [prefix, suffix] = config_value_js_1.Config.escapeDartKeywords(config, blockAppliesOn, typeName, fieldName);
50
+ return `${prefix}${identifier}${suffix}`;
226
51
  }
227
- }
228
- exports.DefaultFreezedConfig = DefaultFreezedConfig;
52
+ return identifier;
53
+ };
54
+ exports.escapeDartKeyword = escapeDartKeyword;
55
+ const atJsonKeyDecorator = ({ defaultValue, disallowNullValue, fromJson, ignore, includeIfNull, name, required, toJson, }) => {
56
+ const body = [
57
+ (0, exports.stringIsNotEmpty)(defaultValue) ? `defaultValue: ${defaultValue}` : undefined,
58
+ disallowNullValue ? `disallowNullValue: ${disallowNullValue}` : undefined,
59
+ (0, exports.stringIsNotEmpty)(fromJson) ? `fromJson: ${fromJson}` : undefined,
60
+ ignore ? `ignore: ${ignore}` : undefined,
61
+ includeIfNull ? `includeIfNull: ${includeIfNull}` : undefined,
62
+ (0, exports.stringIsNotEmpty)(name) ? `name: '${name}'` : undefined,
63
+ required ? `required: ${required}` : undefined,
64
+ (0, exports.stringIsNotEmpty)(toJson) ? `toJson: ${toJson}` : undefined,
65
+ ]
66
+ .filter(value => value !== undefined)
67
+ .join(',');
68
+ return (0, exports.stringIsNotEmpty)(body) ? `@JsonKey(${body})\n` : '';
69
+ };
70
+ exports.atJsonKeyDecorator = atJsonKeyDecorator;
71
+ const stringIsNotEmpty = (str) => (str === null || str === void 0 ? void 0 : str.length) > 0;
72
+ exports.stringIsNotEmpty = stringIsNotEmpty;
73
+ //#endregion
@@ -0,0 +1,128 @@
1
+ import { appliesOnBlock } from '../utils.js';
2
+ import { Pattern } from './pattern.js';
3
+ import { APPLIES_ON_ALL_BLOCKS, DART_SCALARS, defaultFreezedPluginConfig, } from './plugin-config.js';
4
+ export class Config {
5
+ }
6
+ Config.camelCasedEnums = (config) => {
7
+ const _camelCasedEnums = config.camelCasedEnums;
8
+ if (_camelCasedEnums === true) {
9
+ return 'camelCase';
10
+ }
11
+ else if (_camelCasedEnums === false) {
12
+ return undefined;
13
+ }
14
+ return _camelCasedEnums;
15
+ };
16
+ Config.copyWith = (config, typeName) => {
17
+ return Config.enableWithBooleanOrTypeFieldName(config.copyWith, typeName);
18
+ };
19
+ Config.customScalars = (config, graphqlScalar) => {
20
+ var _a, _b, _c;
21
+ return (_c = (_b = (_a = config.customScalars) === null || _a === void 0 ? void 0 : _a[graphqlScalar]) !== null && _b !== void 0 ? _b : DART_SCALARS[graphqlScalar]) !== null && _c !== void 0 ? _c : graphqlScalar;
22
+ };
23
+ Config.defaultValues = (config, blockAppliesOn, typeName, fieldName) => {
24
+ var _a, _b, _c, _d;
25
+ const decorator = (defaultValue) => (defaultValue ? `@Default(${defaultValue})\n` : '');
26
+ const defaultValue = (_d = (_c = (_b = (_a = config.defaultValues) === null || _a === void 0 ? void 0 : _a.filter(([pattern, , configAppliesOn]) => Pattern.findLastConfiguration(pattern, typeName, fieldName) && appliesOnBlock(configAppliesOn, blockAppliesOn))) === null || _b === void 0 ? void 0 : _b.slice(-1)) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d[1];
27
+ return decorator(defaultValue);
28
+ };
29
+ Config.deprecated = (config, blockAppliesOn, typeName, fieldName) => {
30
+ var _a, _b, _c;
31
+ const isDeprecated = ((_c = (_b = (_a = config.deprecated) === null || _a === void 0 ? void 0 : _a.filter(([pattern, configAppliesOn]) => Pattern.findLastConfiguration(pattern, typeName, fieldName) &&
32
+ appliesOnBlock(configAppliesOn, blockAppliesOn))) === null || _b === void 0 ? void 0 : _b.slice(-1)) === null || _c === void 0 ? void 0 : _c[0]) !== undefined;
33
+ return isDeprecated ? '@deprecated\n' : '';
34
+ };
35
+ Config.equal = (config, typeName) => {
36
+ return Config.enableWithBooleanOrTypeFieldName(config.equal, typeName);
37
+ };
38
+ Config.escapeDartKeywords = (config, blockAppliesOn, typeName, fieldName) => {
39
+ const escapeDartKeywords = config.escapeDartKeywords;
40
+ if (escapeDartKeywords === true) {
41
+ return ['', '_']; // use a suffix `_`
42
+ }
43
+ else if (typeName && Array.isArray(escapeDartKeywords) && escapeDartKeywords.length > 0) {
44
+ const [, prefix, suffix] = escapeDartKeywords
45
+ .filter(([pattern, , , configAppliesOn]) => Pattern.findLastConfiguration(pattern, typeName, fieldName) &&
46
+ appliesOnBlock(configAppliesOn !== null && configAppliesOn !== void 0 ? configAppliesOn : [...APPLIES_ON_ALL_BLOCKS], blockAppliesOn))
47
+ .slice(-1)[0];
48
+ return [prefix, suffix];
49
+ }
50
+ return ['', '']; // no suffix
51
+ };
52
+ Config.final = (config, blockAppliesOn, typeName, fieldName) => {
53
+ var _a, _b, _c;
54
+ return (((_c = (_b = (_a = config.final) === null || _a === void 0 ? void 0 : _a.filter(([pattern, configAppliesOn]) => Pattern.findLastConfiguration(pattern, typeName, fieldName) &&
55
+ appliesOnBlock(configAppliesOn, blockAppliesOn))) === null || _b === void 0 ? void 0 : _b.slice(-1)) === null || _c === void 0 ? void 0 : _c[0]) !== undefined);
56
+ };
57
+ /* static fromJsonToJson = ( // TODO: @next-version
58
+ config: FlutterFreezedPluginConfig,
59
+ blockAppliesOn?: readonly AppliesOnParameters[],
60
+ typeName?: TypeName,
61
+ fieldName?: FieldName
62
+ ) => {
63
+ const fromJsonToJson = config.fromJsonToJson;
64
+
65
+ if (typeName && fieldName && Array.isArray(fromJsonToJson)) {
66
+ const [, classOrFunctionName, useClassConverter] = (fromJsonToJson ?? [])
67
+ ?.filter(
68
+ ([pattern, , , appliesOn]) =>
69
+ Pattern.findLastConfiguration(pattern, typeName, fieldName) && appliesOnBlock(appliesOn, blockAppliesOn)
70
+ )
71
+ ?.slice(-1)?.[0];
72
+ return [classOrFunctionName, useClassConverter] as [classOrFunctionName: string, useClassConverter?: boolean];
73
+ } else if (typeName && fromJsonToJson instanceof TypeNamePattern) {
74
+ return Pattern.findLastConfiguration(fromJsonToJson, typeName);
75
+ }
76
+
77
+ return fromJsonToJson as boolean;
78
+ };
79
+ */
80
+ Config.ignoreTypes = (config, typeName) => {
81
+ const ignoreTypes = config.ignoreTypes;
82
+ if (ignoreTypes) {
83
+ const isIgnored = Pattern.findLastConfiguration(ignoreTypes, typeName);
84
+ return isIgnored ? [typeName.value] : [];
85
+ }
86
+ return [];
87
+ };
88
+ Config.immutable = (config, typeName) => {
89
+ return Config.enableWithBooleanOrTypeFieldName(config.immutable, typeName);
90
+ };
91
+ Config.makeCollectionsUnmodifiable = (config, typeName) => {
92
+ return Config.enableWithBooleanOrTypeFieldName(config.makeCollectionsUnmodifiable, typeName);
93
+ };
94
+ Config.mergeTypes = (config, typeName) => {
95
+ var _a, _b;
96
+ return (_b = (_a = config.mergeTypes) === null || _a === void 0 ? void 0 : _a[typeName.value]) !== null && _b !== void 0 ? _b : [];
97
+ };
98
+ Config.mutableInputs = (config, typeName) => {
99
+ return Config.enableWithBooleanOrTypeFieldName(config.mutableInputs, typeName);
100
+ };
101
+ Config.privateEmptyConstructor = (config, typeName) => {
102
+ return Config.enableWithBooleanOrTypeFieldName(config.privateEmptyConstructor, typeName);
103
+ };
104
+ Config.unionClass = ( /* config: FlutterFreezedPluginConfig, index: number, unionTypeName: TypeName */) => {
105
+ // const unionClass = config['unionClass'];
106
+ return undefined;
107
+ };
108
+ Config.unionKey = ( /* config: FlutterFreezedPluginConfig, typeName: TypeName */) => {
109
+ return undefined;
110
+ };
111
+ Config.unionValueCase = ( /* config: FlutterFreezedPluginConfig, typeName: TypeName */) => {
112
+ return undefined;
113
+ };
114
+ Config.unionValueFactoryDecorator = () => {
115
+ return undefined;
116
+ };
117
+ Config.enableWithBooleanOrTypeFieldName = (value, typeName) => {
118
+ if (typeof value === 'boolean') {
119
+ return value;
120
+ }
121
+ else if (value !== undefined && typeName !== undefined) {
122
+ return Pattern.findLastConfiguration(value, typeName);
123
+ }
124
+ return undefined;
125
+ };
126
+ Config.create = (...config) => {
127
+ return Object.assign({}, defaultFreezedPluginConfig, ...config);
128
+ };