@graphql-codegen/flutter-freezed 2.11.2-alpha-20221101110911-a036e7a25 → 3.0.0

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 +140 -0
  4. package/cjs/freezed-declaration-blocks/class-block.js +87 -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 +137 -0
  16. package/esm/freezed-declaration-blocks/class-block.js +86 -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 +6 -6
  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 +683 -0
  31. package/typings/config/plugin-config.d.ts +683 -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/esm/utils.js CHANGED
@@ -1,216 +1,60 @@
1
- import { FreezedDeclarationBlock } from './freezed-declaration-blocks/index.js';
2
- export function transformDefinition(config, freezedFactoryBlockRepository, node) {
3
- var _a;
4
- // ignore these...
5
- if (['Query', 'Mutation', 'Subscription', ...((_a = config === null || config === void 0 ? void 0 : config.ignoreTypes) !== null && _a !== void 0 ? _a : [])].includes(node.name.value)) {
6
- return '';
7
- }
8
- return new FreezedDeclarationBlock(config, freezedFactoryBlockRepository, node).init();
9
- }
1
+ //#region helpers
2
+ import { camelCase, pascalCase, snakeCase } from 'change-case-all';
3
+ import { Kind } from 'graphql';
4
+ import { Config } from './config/config-value.js';
5
+ import { DART_KEYWORDS } from './config/plugin-config.js';
6
+ export const strToList = (str) => (str.length < 1 ? [] : str.split(/\s*,\s*/gim).filter(s => s.length > 0));
7
+ export const arrayWrap = (value) => value === undefined ? [] : Array.isArray(value) ? value : [value];
8
+ export const resetIndex = (regexp) => (regexp.lastIndex = 0);
9
+ export const nodeIsObjectType = (node) => node.kind === Kind.OBJECT_TYPE_DEFINITION || node.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION;
10
+ export const appliesOnBlock = (configAppliesOn, blockAppliesOn) => configAppliesOn.some(a => blockAppliesOn.includes(a));
11
+ export const dartCasing = (name, casing) => {
12
+ if (casing === 'camelCase') {
13
+ return camelCase(name);
14
+ }
15
+ else if (casing === 'PascalCase') {
16
+ return pascalCase(name);
17
+ }
18
+ else if (casing === 'snake_case') {
19
+ return snakeCase(name);
20
+ }
21
+ return name;
22
+ };
10
23
  /**
11
- * returns the value of the FreezedConfig option
12
- * for a specific type if given typeName
13
- * or else fallback to the global FreezedConfig value
24
+ * checks whether name is a Dart Language keyword
25
+ * @param identifier The name or identifier to be checked
26
+ * @returns `true` if name is a Dart Language keyword, otherwise `false`
14
27
  */
15
- export function getFreezedConfigValue(option, config, typeName) {
16
- var _a, _b, _c, _d, _e;
17
- if (typeName) {
18
- 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);
19
- }
20
- return (_e = config === null || config === void 0 ? void 0 : config.globalFreezedConfig) === null || _e === void 0 ? void 0 : _e[option];
21
- }
22
- /**
23
- * @description filters the customDirectives to return those that are applied on a list of blocks
24
- */
25
- export function getCustomDecorators(config, appliesOn, nodeName, fieldName) {
26
- var _a, _b, _c, _d, _e, _f, _g, _h;
27
- const filteredCustomDecorators = {};
28
- 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 : {};
29
- let customDecorators = { ...globalCustomDecorators };
30
- if (nodeName) {
31
- const typeConfig = (_c = config === null || config === void 0 ? void 0 : config.typeSpecificFreezedConfig) === null || _c === void 0 ? void 0 : _c[nodeName];
32
- 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 : {};
33
- customDecorators = { ...customDecorators, ...typeSpecificCustomDecorators };
34
- if (fieldName) {
35
- 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 : {};
36
- customDecorators = { ...customDecorators, ...fieldSpecificCustomDecorators };
37
- }
38
- }
39
- Object.entries(customDecorators).forEach(([key, value]) => {
40
- var _a;
41
- return (_a = value === null || value === void 0 ? void 0 : value.applyOn) === null || _a === void 0 ? void 0 : _a.forEach(a => {
42
- if (appliesOn.includes(a)) {
43
- filteredCustomDecorators[key] = value;
44
- }
45
- });
46
- });
47
- return filteredCustomDecorators;
48
- }
49
- export function transformCustomDecorators(customDecorators, node, field) {
50
- var _a, _b;
51
- let result = [];
52
- result = [
53
- ...result,
54
- ...((_a = node === null || node === void 0 ? void 0 : node.directives) !== null && _a !== void 0 ? _a : [])
55
- .concat((_b = field === null || field === void 0 ? void 0 : field.directives) !== null && _b !== void 0 ? _b : [])
56
- // extract only the directives whose names were specified as keys
57
- // and have values that not undefined or null in the customDecorator record
58
- .filter(d => {
59
- var _a;
60
- const key = d.name.value;
61
- const value = (_a = customDecorators[key]) !== null && _a !== void 0 ? _a : customDecorators[`@${key}`];
62
- if (value && value.mapsToFreezedAs !== 'custom') {
63
- return true;
64
- }
65
- return false;
66
- })
67
- // transform each directive to string
68
- .map(d => directiveToString(d, customDecorators)),
69
- ];
70
- // for decorators that mapsToFreezedAs === 'custom'
71
- Object.entries(customDecorators).forEach(([key, value]) => {
72
- if (value.mapsToFreezedAs === 'custom') {
73
- const args = value === null || value === void 0 ? void 0 : value.arguments;
74
- // if the custom directives have arguments,
75
- if (args && args !== []) {
76
- // join them with a comma in the parenthesis
77
- result = [...result, `${key}(${args.join(', ')})\n`];
78
- }
79
- else {
80
- // else return the customDecorator key just as it is
81
- result = [...result, key + '\n'];
82
- }
83
- }
84
- });
85
- return result;
86
- }
28
+ export const isDartKeyword = (identifier) => DART_KEYWORDS[identifier] !== undefined;
87
29
  /**
88
- * transforms the directive into a decorator array
89
- * this decorator array might contain a `final` string which would be filtered out
90
- * and used to mark the parameter block as final
30
+ * Ensures that the blockName isn't a valid Dart language reserved keyword.
31
+ * It wraps the identifier with the prefix and suffix then transforms the casing as specified in the config
32
+ * @param config
33
+ * @param name
34
+ * @param typeName
35
+ * @returns
91
36
  */
92
- function directiveToString(directive, customDecorators) {
93
- var _a, _b, _c, _d, _e;
94
- const key = directive.name.value;
95
- const value = customDecorators[key];
96
- if (value.mapsToFreezedAs === 'directive') {
97
- // get the directive's arguments
98
- const directiveArgs = (_a = directive === null || directive === void 0 ? void 0 : directive.arguments) !== null && _a !== void 0 ? _a : [];
99
- // extract the directive's argument using the template index: ["$0", "$1", ...]
100
- // specified in the customDecorator.arguments array
101
- 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}`);
102
- // if the args is not empty
103
- if (args !== []) {
104
- // returns "@directiveName(argName: argValue, argName: argValue ...)"
105
- return `@${directive.name.value}(${args === null || args === void 0 ? void 0 : args.join(', ')})\n`;
106
- }
107
- }
108
- else if (value.mapsToFreezedAs === '@Default') {
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
- if (defaultValue) {
111
- return `@Default(value: ${defaultValue})\n`;
112
- }
113
- }
114
- // returns either "@deprecated" || "final".
115
- // `final` to be filtered from the decorators array when applying the decorators
116
- return value.mapsToFreezedAs + '\n';
117
- }
118
- /** transforms string template: "$0" into an integer: 1 */
119
- function argToInt(arg) {
120
- var _a;
121
- const parsedIndex = Number.parseInt((_a = arg.replace('$', '').trim()) !== null && _a !== void 0 ? _a : '0'); // '$1 => 1
122
- return parsedIndex ? parsedIndex : 0;
123
- }
124
- /** returns freezed import statements */
125
- export function addFreezedImportStatements(fileName) {
126
- return [
127
- "import 'package:freezed_annotation/freezed_annotation.dart';\n",
128
- "import 'package:flutter/foundation.dart';\n\n",
129
- `part ${fileName.replace(/\.dart/g, '')}.dart;\n`,
130
- `part '${fileName.replace(/\.dart/g, '')}.g.dart';\n\n`,
131
- ].join('');
132
- }
133
- /** a class variant of the getFreezedConfigValue helper function
134
- *
135
- * returns the value of the FreezedConfig option
136
- * for a specific type if given typeName
137
- * or else fallback to the global FreezedConfig value
138
- */
139
- export class FreezedConfigValue {
140
- constructor(_config, _typeName) {
141
- this._config = _config;
142
- this._typeName = _typeName;
143
- this._config = _config;
144
- this._typeName = _typeName;
145
- }
146
- /**
147
- * returns the value of the FreezedConfig option
148
- * for a specific type if given typeName
149
- * or else fallback to the global FreezedConfig value
150
- */
151
- get(option) {
152
- return getFreezedConfigValue(option, this._config, this._typeName);
153
- }
154
- }
155
- /**
156
- * stores an instance of FreezedFactoryBlock using the node names as the key
157
- * and returns that instance when replacing tokens
158
- * */
159
- export class FreezedFactoryBlockRepository {
160
- constructor() {
161
- this._store = {};
162
- }
163
- get(key) {
164
- return this._store[key];
165
- }
166
- register(key, value) {
167
- this._store[key] = value;
168
- return value;
169
- }
170
- retrieve(key, appliesOn, name, typeName) {
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 '';
181
- }
182
- }
183
- /** initializes a FreezedPluginConfig with the defaults values */
184
- export class DefaultFreezedPluginConfig {
185
- constructor(config = {}) {
186
- var _a, _b, _c, _d, _e, _f;
187
- Object.assign(this, {
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 : [],
194
- });
195
- }
196
- }
197
- /** initializes a FreezedConfig with the defaults values */
198
- export class DefaultFreezedConfig {
199
- constructor() {
200
- Object.assign(this, {
201
- alwaysUseJsonKeyName: false,
202
- copyWith: undefined,
203
- customDecorators: {},
204
- defaultUnionConstructor: true,
205
- equal: undefined,
206
- fromJsonToJson: true,
207
- immutable: true,
208
- makeCollectionsUnmodifiable: undefined,
209
- mergeInputs: [],
210
- mutableInputs: true,
211
- privateEmptyConstructor: true,
212
- unionKey: undefined,
213
- unionValueCase: undefined,
214
- });
215
- }
216
- }
37
+ export const escapeDartKeyword = (config, blockAppliesOn, identifier, typeName, fieldName) => {
38
+ if (isDartKeyword(identifier)) {
39
+ const [prefix, suffix] = Config.escapeDartKeywords(config, blockAppliesOn, typeName, fieldName);
40
+ return `${prefix}${identifier}${suffix}`;
41
+ }
42
+ return identifier;
43
+ };
44
+ export const atJsonKeyDecorator = ({ defaultValue, disallowNullValue, fromJson, ignore, includeIfNull, name, required, toJson, }) => {
45
+ const body = [
46
+ stringIsNotEmpty(defaultValue) ? `defaultValue: ${defaultValue}` : undefined,
47
+ disallowNullValue ? `disallowNullValue: ${disallowNullValue}` : undefined,
48
+ stringIsNotEmpty(fromJson) ? `fromJson: ${fromJson}` : undefined,
49
+ ignore ? `ignore: ${ignore}` : undefined,
50
+ includeIfNull ? `includeIfNull: ${includeIfNull}` : undefined,
51
+ stringIsNotEmpty(name) ? `name: '${name}'` : undefined,
52
+ required ? `required: ${required}` : undefined,
53
+ stringIsNotEmpty(toJson) ? `toJson: ${toJson}` : undefined,
54
+ ]
55
+ .filter(value => value !== undefined)
56
+ .join(',');
57
+ return stringIsNotEmpty(body) ? `@JsonKey(${body})\n` : '';
58
+ };
59
+ export const stringIsNotEmpty = (str) => (str === null || str === void 0 ? void 0 : str.length) > 0;
60
+ //#endregion
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "@graphql-codegen/flutter-freezed",
3
- "version": "2.11.2-alpha-20221101110911-a036e7a25",
3
+ "version": "3.0.0",
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.7.2-alpha-20221101110911-a036e7a25",
9
+ "@graphql-codegen/plugin-helpers": "^3.0.0",
10
10
  "@graphql-codegen/schema-ast": "^2.5.0",
11
- "@graphql-codegen/visitor-plugin-common": "2.13.1-alpha-20221101110911-a036e7a25",
11
+ "@graphql-codegen/visitor-plugin-common": "2.13.1",
12
12
  "auto-bind": "~4.0.0",
13
- "tslib": "~2.4.0",
14
- "change-case-all": "1.0.14"
13
+ "change-case-all": "1.0.15",
14
+ "tslib": "~2.4.0"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
18
- "url": "https://github.com/dotansimha/graphql-code-generator.git",
18
+ "url": "https://github.com/dotansimha/graphql-code-generator-community.git",
19
19
  "directory": "packages/plugins/typescript/typescript"
20
20
  },
21
21
  "license": "MIT",
@@ -0,0 +1,24 @@
1
+ import { FieldName, TypeName, TypeNamePattern } from './pattern.cjs';
2
+ import { AppliesOn, AppliesOnFactory, AppliesOnParameters, FlutterFreezedPluginConfig } from './plugin-config.cjs';
3
+ export declare class Config {
4
+ static camelCasedEnums: (config: FlutterFreezedPluginConfig) => import("./plugin-config.js").DartIdentifierCasing;
5
+ static copyWith: (config: FlutterFreezedPluginConfig, typeName?: TypeName) => boolean;
6
+ static customScalars: (config: FlutterFreezedPluginConfig, graphqlScalar: string) => string;
7
+ static defaultValues: (config: FlutterFreezedPluginConfig, blockAppliesOn: readonly AppliesOnParameters[], typeName: TypeName, fieldName: FieldName) => string;
8
+ static deprecated: (config: FlutterFreezedPluginConfig, blockAppliesOn: readonly (AppliesOnFactory | AppliesOnParameters)[], typeName: TypeName, fieldName?: FieldName) => "" | "@deprecated\n";
9
+ static equal: (config: FlutterFreezedPluginConfig, typeName?: TypeName) => boolean;
10
+ static escapeDartKeywords: (config: FlutterFreezedPluginConfig, blockAppliesOn: readonly AppliesOn[], typeName?: TypeName, fieldName?: FieldName) => [prefix?: string, suffix?: string];
11
+ static final: (config: FlutterFreezedPluginConfig, blockAppliesOn: readonly AppliesOnParameters[], typeName: TypeName, fieldName: FieldName) => boolean;
12
+ static ignoreTypes: (config: FlutterFreezedPluginConfig, typeName: TypeName) => string[];
13
+ static immutable: (config: FlutterFreezedPluginConfig, typeName?: TypeName) => boolean;
14
+ static makeCollectionsUnmodifiable: (config: FlutterFreezedPluginConfig, typeName?: TypeName) => boolean;
15
+ static mergeTypes: (config: FlutterFreezedPluginConfig, typeName: TypeName) => string[];
16
+ static mutableInputs: (config: FlutterFreezedPluginConfig, typeName?: TypeName) => boolean;
17
+ static privateEmptyConstructor: (config: FlutterFreezedPluginConfig, typeName?: TypeName) => boolean;
18
+ static unionClass: () => any;
19
+ static unionKey: () => string | undefined;
20
+ static unionValueCase: () => string | undefined;
21
+ static unionValueDecorator: () => any;
22
+ static enableWithBooleanOrTypeFieldName: (value?: boolean | TypeNamePattern, typeName?: TypeName) => boolean;
23
+ static create: (...config: Partial<FlutterFreezedPluginConfig>[]) => FlutterFreezedPluginConfig;
24
+ }
@@ -0,0 +1,24 @@
1
+ import { FieldName, TypeName, TypeNamePattern } from './pattern.js';
2
+ import { AppliesOn, AppliesOnFactory, AppliesOnParameters, FlutterFreezedPluginConfig } from './plugin-config.js';
3
+ export declare class Config {
4
+ static camelCasedEnums: (config: FlutterFreezedPluginConfig) => import("./plugin-config.js").DartIdentifierCasing;
5
+ static copyWith: (config: FlutterFreezedPluginConfig, typeName?: TypeName) => boolean;
6
+ static customScalars: (config: FlutterFreezedPluginConfig, graphqlScalar: string) => string;
7
+ static defaultValues: (config: FlutterFreezedPluginConfig, blockAppliesOn: readonly AppliesOnParameters[], typeName: TypeName, fieldName: FieldName) => string;
8
+ static deprecated: (config: FlutterFreezedPluginConfig, blockAppliesOn: readonly (AppliesOnFactory | AppliesOnParameters)[], typeName: TypeName, fieldName?: FieldName) => "" | "@deprecated\n";
9
+ static equal: (config: FlutterFreezedPluginConfig, typeName?: TypeName) => boolean;
10
+ static escapeDartKeywords: (config: FlutterFreezedPluginConfig, blockAppliesOn: readonly AppliesOn[], typeName?: TypeName, fieldName?: FieldName) => [prefix?: string, suffix?: string];
11
+ static final: (config: FlutterFreezedPluginConfig, blockAppliesOn: readonly AppliesOnParameters[], typeName: TypeName, fieldName: FieldName) => boolean;
12
+ static ignoreTypes: (config: FlutterFreezedPluginConfig, typeName: TypeName) => string[];
13
+ static immutable: (config: FlutterFreezedPluginConfig, typeName?: TypeName) => boolean;
14
+ static makeCollectionsUnmodifiable: (config: FlutterFreezedPluginConfig, typeName?: TypeName) => boolean;
15
+ static mergeTypes: (config: FlutterFreezedPluginConfig, typeName: TypeName) => string[];
16
+ static mutableInputs: (config: FlutterFreezedPluginConfig, typeName?: TypeName) => boolean;
17
+ static privateEmptyConstructor: (config: FlutterFreezedPluginConfig, typeName?: TypeName) => boolean;
18
+ static unionClass: () => any;
19
+ static unionKey: () => string | undefined;
20
+ static unionValueCase: () => string | undefined;
21
+ static unionValueDecorator: () => any;
22
+ static enableWithBooleanOrTypeFieldName: (value?: boolean | TypeNamePattern, typeName?: TypeName) => boolean;
23
+ static create: (...config: Partial<FlutterFreezedPluginConfig>[]) => FlutterFreezedPluginConfig;
24
+ }
@@ -0,0 +1,252 @@
1
+ /**
2
+ * A list of GraphQL Type Names
3
+ */
4
+ declare type TypeNames = TypeName | TypeName[];
5
+ /**
6
+ * A list of field names of a GraphQL Type
7
+ */
8
+ declare type FieldNames = FieldName | FieldName[];
9
+ /**
10
+ * @name TypeName
11
+ * @description represents a single valid GraphQL Type Name used in the GraphQL Schema provided
12
+ * @exampleMarkdown
13
+ * ```ts filename:"config.ts"
14
+ * // returns a TypeName
15
+ * let typeName: TypeName = TypeName.fromString('Droid');
16
+ *
17
+ * // to configure a FactoryBlock, use the `TypeName.fromUnionOfTypeNames(className, factoryName)`
18
+ * let typeName: TypeName = TypeName.fromUnionOfTypeNames(SearchResult, Droid);
19
+
20
+ * // the following will throw an error
21
+ * // can contain only a single value...
22
+ * let typeName: TypeName = TypeName.fromString('Droid, Human'); // throws an Error
23
+ *
24
+ * // value can not be an empty string...
25
+ * let typeName: TypeName = TypeName.fromString(''); // throws an Error
26
+ *
27
+ * // value must contain only AlphaNumeric characters only...
28
+ * let typeName: TypeName = TypeName.fromString('Invalid.Name'); // throws an Error
29
+ * ```
30
+ */
31
+ export declare class TypeName {
32
+ private _value;
33
+ private constructor();
34
+ get value(): string;
35
+ static get allTypeNames(): string;
36
+ static fromUnionOfTypeNames: (className: TypeName, factoryName: TypeName) => TypeName;
37
+ static fromString: (value: string) => TypeName;
38
+ }
39
+ /**
40
+ * @name FieldName
41
+ * @description Represents a single valid name of a field belong to a Graphql Type.
42
+ * @exampleMarkdown
43
+ * ```ts filename:"config.ts"
44
+ * // returns a FieldName
45
+ * let fieldName: FieldName = FieldName.fromString('id');
46
+ *
47
+ * // the following will throw an error
48
+ * // can contain only a single value...
49
+ * let fieldName: FieldName = FieldName.fromString('id, name'); // throws an Error
50
+ *
51
+ * // value can not be an empty string...
52
+ * let fieldName: FieldName = FieldName.fromString(''); // throws an Error
53
+ *
54
+ * // value must contain only AlphaNumeric characters only...
55
+ * let fieldName: FieldName = FieldName.fromString('Invalid.Name'); // throws an Error
56
+ * ```
57
+ */
58
+ export declare class FieldName {
59
+ private _value;
60
+ private constructor();
61
+ get value(): string;
62
+ static get allFieldNames(): string;
63
+ static fromString: (value: string) => FieldName;
64
+ }
65
+ /**
66
+ * @name Pattern
67
+ * @description The base class for TypeNamePattern and FieldNamePattern
68
+ * @see {@link url TypeNamePattern}
69
+ * @see {@link url FieldNamePattern}
70
+ */
71
+ export declare class Pattern {
72
+ private _value;
73
+ protected constructor(value: string);
74
+ get value(): string;
75
+ protected static fromString: (value: string) => Pattern;
76
+ static attemptMatchAndConfigure: (pattern: FieldNamePattern, typeName: TypeName, fieldName?: FieldName) => MatchAndConfigure;
77
+ static compose: (data: Pattern[]) => Pattern;
78
+ static split: (pattern: Pattern) => Pattern[];
79
+ static getMatchList: (patternType: 'TypeNamePattern' | 'FieldNamePattern' | 'Pattern') => string[];
80
+ /**
81
+ * finds the last pattern that configures the typeName and/or fieldName given
82
+ * @param pattern
83
+ * @param typeName
84
+ * @param fieldName
85
+ * @returns true if a pattern marks the typeName and or fieldName given to be configured, otherwise false
86
+ */
87
+ static findLastConfiguration: (pattern: Pattern, typeName: TypeName, fieldName?: FieldName) => boolean;
88
+ }
89
+ /**
90
+ * @name TypeNamePattern
91
+ *
92
+ * @description A compact string of patterns used in the config for granular configuration of Graphql Types.
93
+ *
94
+ * The string can contain one or more patterns, each pattern ends with a semi-colon (`;`).
95
+ *
96
+ * To apply an option to all Graphql Types or all fields, use the allTypeNames (`@*TypeNames`) tokens.
97
+ *
98
+ * Wherever you use the allTypeNames token, know very well that you can make some exceptions. After all, to every rule, there is an exception.
99
+ *
100
+ * A **square bracket** (`[]`) is used to specify what should be included and a **negated square bracket** (`-[]`) is used to specify what should be excluded.
101
+ *
102
+ * Manually typing out a pattern may be prone to typos resulting in invalid patterns therefore the [`TypeNamePattern`]() class exposes some builder methods to be used in the plugin config file.
103
+ *
104
+ * ## Available Builder Methods and the patterns they make
105
+ * ```ts
106
+ * const Droid = TypeName.fromString('Droid');
107
+ * const Starship = TypeName.fromString('Starship');
108
+ * const Human = TypeName.fromString('Human');
109
+ * const Movie = TypeName.fromString('Movie');
110
+
111
+ *
112
+ * // Configuring specific Graphql Types
113
+ * const pattern = TypeNamePattern.forTypeNames([Droid, Starship]);
114
+ * console.log(pattern); // "Droid;Starship;"
115
+ *
116
+ * // Configuring all Graphql Types
117
+ * const pattern = TypeNamePattern.forAllTypeNames();
118
+ * console.log(pattern); // "@*TypeNames;"
119
+
120
+ * // Configuring all Graphql Types except those specified in the exclusion list of TypeNames
121
+ * const pattern = TypeNamePattern.forAllTypeNamesExcludeTypeNames([Droid, Starship]);
122
+ * console.log(pattern); // "@*TypeNames-[Droid,Starship];"
123
+ *
124
+ */
125
+ export declare class TypeNamePattern extends Pattern {
126
+ private constructor();
127
+ static forTypeNames: (typeNames: TypeNames) => TypeNamePattern;
128
+ static regexpForTypeNames: RegExp;
129
+ static matchAndConfigureTypeNames: (pattern: TypeNamePattern, typeName: TypeName) => MatchAndConfigure;
130
+ static forAllTypeNames: () => TypeNamePattern;
131
+ static regexpForAllTypeNames: RegExp;
132
+ static matchAndConfigureAllTypeNames: (pattern: TypeNamePattern, typeName: TypeName) => MatchAndConfigure;
133
+ static forAllTypeNamesExcludeTypeNames: (typeNames: TypeNames) => TypeNamePattern;
134
+ static regexpForAllTypeNamesExcludeTypeNames: RegExp;
135
+ static matchAndConfigureAllTypeNamesExcludeTypeNames: (pattern: TypeNamePattern, typeName: TypeName) => MatchAndConfigure;
136
+ }
137
+ /**
138
+ * @name FieldNamePattern
139
+ *
140
+ * @description A compact string of patterns used in the config for granular configuration the fields of a Graphql Type
141
+ *
142
+ * The string can contain one or more patterns, each pattern ends with a semi-colon (`;`).
143
+ *
144
+ * A dot (`.`) is used to separate the TypeName from the FieldNames in each pattern.
145
+ *
146
+ * To apply an option to all Graphql Types or all fields, use the allTypeNames (`@*TypeNames`) and allFieldNames (`@*FieldNames`) tokens respectively.
147
+ *
148
+ * Wherever you use the allTypeNames and the allFieldNames, know very well that you can make some exceptions. After all, to every rule, there is an exception.
149
+ *
150
+ * A **square bracket** (`[]`) is used to specify what should be included and a **negated square bracket** (`-[]`) is used to specify what should be excluded.
151
+ *
152
+ * Manually typing out a pattern may be prone to typos resulting in invalid patterns therefore the [`FieldName`]() class exposes some builder methods to be used in your plugin config file.
153
+ *
154
+ * ## Available Builder Methods and the patterns they make
155
+ * ```ts
156
+ * const Droid = TypeName.fromString('Droid');
157
+ * const Starship = TypeName.fromString('Starship');
158
+ * const Human = TypeName.fromString('Human');
159
+ * const Movie = TypeName.fromString('Movie');
160
+ *
161
+ * const id = FieldName.fromString('id');
162
+ * const name = FieldName.fromString('name');
163
+ * const friends = FieldName.fromString('friends');
164
+ * const friend = FieldName.fromString('friend');
165
+ * const title = FieldName.fromString('title');
166
+ * const episode = FieldName.fromString('episode');
167
+ * const length = FieldName.fromString('length');
168
+ *
169
+ * // Configuring specific fields of a specific Graphql Type
170
+ * const pattern = FieldNamePattern.forFieldNamesOfTypeName([
171
+ * [Droid, [id, name, friends]], // individual
172
+ * [Human, [id, name, title]], // individual
173
+ * [Starship, [name, length]], // individual
174
+ * ]);
175
+ * console.log(pattern); // "Droid.[id,name,friends];Human.[id,name,title];Starship.[name,length];"
176
+ *
177
+ * // Configuring all fields of a specific Graphql Type
178
+ * const pattern = FieldNamePattern.forAllFieldNamesOfTypeName([Droid, Movie]);
179
+ * console.log(pattern); // "Droid.@*FieldNames;Movie.@*FieldNames;"
180
+ *
181
+ * // Configuring all fields except those specified in the exclusion list of FieldNames for a specific GraphQL Type
182
+ * const pattern = FieldNamePattern.forAllFieldNamesExcludeFieldNamesOfTypeName([
183
+ * [Droid, [id, name, friends]], // individual
184
+ * [Human, [id, name, title]], // individual
185
+ * [Starship, [name, length]], // individual
186
+ * ]);
187
+ * console.log(pattern); // "Droid.@*FieldNames-[id,name,friends];Human.@*FieldNames-[id,name,title];Starship.@*FieldNames-[name,length];"
188
+ *
189
+ * // Configuring specific fields of all Graphql Types
190
+ * const pattern = FieldNamePattern.forFieldNamesOfAllTypeNames([id, name, friends]);
191
+ * console.log(pattern); // "@*TypeNames.[id,name,friends];"
192
+ *
193
+ * // Configuring all fields of all Graphql Types
194
+ * const pattern = FieldNamePattern.forAllFieldNamesOfAllTypeNames();
195
+ * console.log(pattern); // "@*TypeNames.@*FieldNames;"
196
+ *
197
+ * // Configuring all fields except those specified in the exclusion list of FieldNames for all GraphQL Types
198
+ * const pattern = FieldNamePattern.forAllFieldNamesExcludeFieldNamesOfAllTypeNames([id, name, friends]);
199
+ * console.log(pattern); // "@*TypeNames.@*FieldNames-[id,name,friends];"
200
+ *
201
+ * // Configuring specific fields of all GraphQL Types except those specified in the exclusion list of TypeNames
202
+ * const pattern = FieldNamePattern.forFieldNamesOfAllTypeNamesExcludeTypeNames([Droid, Human], [id, name, friends]);
203
+ * console.log(pattern); // "@*TypeNames-[Droid,Human].[id,name,friends];"
204
+ *
205
+ * // Configuring all fields of all GraphQL Types except those specified in the exclusion list of TypeNames
206
+ * const pattern = FieldNamePattern.forAllFieldNamesOfAllTypeNamesExcludeTypeNames([Droid, Human]);
207
+ * console.log(pattern); // "@*TypeNames-[Droid,Human].@*FieldNames;"
208
+ *
209
+ * // Configuring all fields except those specified in the exclusion list of FieldNames of all GraphQL Types except those specified in the exclusion list of TypeNames
210
+ * const pattern = FieldNamePattern.forAllFieldNamesExcludeFieldNamesOfAllTypeNamesExcludeTypeNames(
211
+ * [Droid, Human],
212
+ * [id, name, friends]
213
+ * );
214
+ * console.log(pattern); // "@*TypeNames-[Droid,Human].@*FieldNames-[id,name,friends];"
215
+ * ```
216
+ *
217
+ */
218
+ export declare class FieldNamePattern extends Pattern {
219
+ private constructor();
220
+ static forFieldNamesOfTypeName: (data: [typeNames: TypeNames, fieldNames: FieldNames][]) => FieldNamePattern;
221
+ static regexpForFieldNamesOfTypeName: RegExp;
222
+ static matchAndConfigureFieldNamesOfTypeName: (pattern: FieldNamePattern, typeName: TypeName, fieldName: FieldName) => MatchAndConfigure;
223
+ static forAllFieldNamesOfTypeName: (typeNames: TypeNames) => FieldNamePattern;
224
+ static regexpForAllFieldNamesOfTypeName: RegExp;
225
+ static matchAndConfigureAllFieldNamesOfTypeName: (pattern: FieldNamePattern, typeName: TypeName, fieldName: FieldName) => MatchAndConfigure;
226
+ static forAllFieldNamesExcludeFieldNamesOfTypeName: (data: [typeNames: TypeNames, fieldNames: FieldNames][]) => FieldNamePattern;
227
+ static regexpForAllFieldNamesExcludeFieldNamesOfTypeName: RegExp;
228
+ static matchAndConfigureAllFieldNamesExcludeFieldNamesOfTypeName: (pattern: FieldNamePattern, typeName: TypeName, fieldName: FieldName) => MatchAndConfigure;
229
+ static forFieldNamesOfAllTypeNames: (fieldNames: FieldNames) => FieldNamePattern;
230
+ static regexpForFieldNamesOfAllTypeNames: RegExp;
231
+ static matchAndConfigureFieldNamesOfAllTypeNames: (pattern: FieldNamePattern, typeName: TypeName, fieldName: FieldName) => MatchAndConfigure;
232
+ static forAllFieldNamesOfAllTypeNames: () => FieldNamePattern;
233
+ static regexpForAllFieldNamesOfAllTypeNames: RegExp;
234
+ static matchAndConfigureAllFieldNamesOfAllTypeNames: (pattern: FieldNamePattern, typeName: TypeName, fieldName: FieldName) => MatchAndConfigure;
235
+ static forAllFieldNamesExcludeFieldNamesOfAllTypeNames: (fieldNames: FieldNames) => FieldNamePattern;
236
+ static regexpForAllFieldNamesExcludeFieldNamesOfAllTypeNames: RegExp;
237
+ static matchAndConfigureAllFieldNamesExcludeFieldNamesOfAllTypeNames: (pattern: FieldNamePattern, typeName: TypeName, fieldName: FieldName) => MatchAndConfigure;
238
+ static forFieldNamesOfAllTypeNamesExcludeTypeNames: (typeNames: TypeNames, fieldNames: FieldNames) => FieldNamePattern;
239
+ static regexpForFieldNamesOfAllTypeNamesExcludeTypeNames: RegExp;
240
+ static matchAndConfigureFieldNamesOfAllTypeNamesExcludeTypeNames: (pattern: FieldNamePattern, typeName: TypeName, fieldName: FieldName) => MatchAndConfigure;
241
+ static forAllFieldNamesOfAllTypeNamesExcludeTypeNames: (typeNames: TypeNames) => FieldNamePattern;
242
+ static regexpForAllFieldNamesOfAllTypeNamesExcludeTypeNames: RegExp;
243
+ static matchAndConfigureAllFieldNamesOfAllTypeNamesExcludeTypeNames: (pattern: FieldNamePattern, typeName: TypeName, fieldName: FieldName) => MatchAndConfigure;
244
+ static forAllFieldNamesExcludeFieldNamesOfAllTypeNamesExcludeTypeNames: (typeNames: TypeNames, fieldNames: FieldNames) => FieldNamePattern;
245
+ static regexpForAllFieldNamesExcludeFieldNamesOfAllTypeNamesExcludeTypeNames: RegExp;
246
+ static matchAndConfigureAllFieldNamesExcludeFieldNamesOfAllTypeNamesExcludeTypeNames: (pattern: FieldNamePattern, typeName: TypeName, fieldName: FieldName) => MatchAndConfigure;
247
+ }
248
+ export declare type MatchAndConfigure = Record<string, {
249
+ matchFound: boolean;
250
+ shouldBeConfigured: boolean;
251
+ }>;
252
+ export {};