@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
@@ -0,0 +1,723 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ import { arrayWrap, resetIndex, strToList } from '../utils.js';
3
+ /**
4
+ * @name TypeName
5
+ * @description represents a single valid GraphQL Type Name used in the GraphQL Schema provided
6
+ * @exampleMarkdown
7
+ * ```ts filename:"config.ts"
8
+ * // returns a TypeName
9
+ * let typeName: TypeName = TypeName.fromString('Droid');
10
+ *
11
+ * // to configure a FactoryBlock, use the `TypeName.fromUnionOfTypeNames(className, factoryName)`
12
+ * let typeName: TypeName = TypeName.fromUnionOfTypeNames(SearchResult, Droid);
13
+
14
+ * // the following will throw an error
15
+ * // can contain only a single value...
16
+ * let typeName: TypeName = TypeName.fromString('Droid, Human'); // throws an Error
17
+ *
18
+ * // value can not be an empty string...
19
+ * let typeName: TypeName = TypeName.fromString(''); // throws an Error
20
+ *
21
+ * // value must contain only AlphaNumeric characters only...
22
+ * let typeName: TypeName = TypeName.fromString('Invalid.Name'); // throws an Error
23
+ * ```
24
+ */
25
+ export class TypeName {
26
+ constructor(value) {
27
+ this._value = value;
28
+ }
29
+ get value() {
30
+ return this._value;
31
+ }
32
+ static get allTypeNames() {
33
+ return '@*TypeNames';
34
+ }
35
+ }
36
+ TypeName.fromUnionOfTypeNames = (className, factoryName) => new TypeName(`${className.value}_${factoryName.value}`);
37
+ TypeName.fromString = (value) => {
38
+ if (value === undefined || value.length < 1) {
39
+ throw new Error('TypeName is the name of a GraphQL Type and it cannot be empty');
40
+ }
41
+ else if (/([^a-zA-Z0-9_])/gim.test(value)) {
42
+ throw new Error('TypeName is the name of a GraphQL Type and it must consist of only AlphaNumeric characters');
43
+ }
44
+ return new TypeName(value.trim());
45
+ };
46
+ /**
47
+ * @name FieldName
48
+ * @description Represents a single valid name of a field belong to a Graphql Type.
49
+ * @exampleMarkdown
50
+ * ```ts filename:"config.ts"
51
+ * // returns a FieldName
52
+ * let fieldName: FieldName = FieldName.fromString('id');
53
+ *
54
+ * // the following will throw an error
55
+ * // can contain only a single value...
56
+ * let fieldName: FieldName = FieldName.fromString('id, name'); // throws an Error
57
+ *
58
+ * // value can not be an empty string...
59
+ * let fieldName: FieldName = FieldName.fromString(''); // throws an Error
60
+ *
61
+ * // value must contain only AlphaNumeric characters only...
62
+ * let fieldName: FieldName = FieldName.fromString('Invalid.Name'); // throws an Error
63
+ * ```
64
+ */
65
+ export class FieldName {
66
+ constructor(value) {
67
+ this._value = value;
68
+ }
69
+ get value() {
70
+ return this._value;
71
+ }
72
+ static get allFieldNames() {
73
+ return '@*FieldNames';
74
+ }
75
+ }
76
+ FieldName.fromString = (value) => {
77
+ if (value === undefined || value.length < 1) {
78
+ throw new Error('FieldName is the name of a field in a GraphQL Type and it cannot be empty');
79
+ }
80
+ else if (/([^a-zA-Z0-9_])/gim.test(value)) {
81
+ throw new Error('FieldName is the name of a field in a GraphQL Type and it must consist of only AlphaNumeric characters');
82
+ }
83
+ return new FieldName(value.trim());
84
+ };
85
+ /**
86
+ * @name Pattern
87
+ * @description The base class for TypeNamePattern and FieldNamePattern
88
+ * @see {@link url TypeNamePattern}
89
+ * @see {@link url FieldNamePattern}
90
+ */
91
+ export class Pattern {
92
+ constructor(value) {
93
+ this._value = value;
94
+ }
95
+ get value() {
96
+ return this._value;
97
+ }
98
+ }
99
+ Pattern.fromString = (value) => {
100
+ if (value === undefined || value.length < 1) {
101
+ throw new Error('Pattern cannot be created from an empty string');
102
+ }
103
+ return new Pattern(value.endsWith(';') ? value : `${value};`);
104
+ };
105
+ // #region attemptMatchAndConfigure
106
+ Pattern.attemptMatchAndConfigure = (pattern, typeName, fieldName) => {
107
+ if (pattern.value.split(';').filter(_pattern => _pattern.length > 0).length !== 1) {
108
+ throw new Error('attemptMatchAndConfigure can only handle one pattern at a time... use the `splitPatterns(...)` helper function to split your patterns into a list and loop over the list calling the `attemptMatchAndConfigure(...)` for each single pattern');
109
+ }
110
+ const isTypeNamePattern = (baseName) => {
111
+ if (fieldName === undefined &&
112
+ (baseName === 'TypeNames' || baseName === 'AllTypeNames' || baseName === 'AllTypeNamesExcludeTypeNames')) {
113
+ return true;
114
+ }
115
+ return false;
116
+ };
117
+ const regexpFor = (baseName) => {
118
+ return isTypeNamePattern(baseName)
119
+ ? TypeNamePattern[`regexpFor${baseName}`]
120
+ : FieldNamePattern[`regexpFor${baseName}`];
121
+ };
122
+ const matchAndConfigure = (baseName, pattern, ...args) => {
123
+ return isTypeNamePattern(baseName)
124
+ ? TypeNamePattern[`matchAndConfigure${baseName}`](pattern, ...args)
125
+ : FieldNamePattern[`matchAndConfigure${baseName}`](pattern, ...args); // check if fieldName is passed in ...args
126
+ };
127
+ const matchList = Pattern.getMatchList(fieldName === undefined ? 'TypeNamePattern' : 'FieldNamePattern');
128
+ for (let i = 0; i < matchList.length; i++) {
129
+ const baseName = matchList[i];
130
+ if (regexpFor(baseName).test(pattern.value)) {
131
+ return matchAndConfigure(baseName, pattern, typeName, fieldName);
132
+ }
133
+ }
134
+ return undefined;
135
+ };
136
+ //#endregion
137
+ //#region composePatterns
138
+ Pattern.compose = (data) => {
139
+ if (data.length < 1) {
140
+ throw new Error('Pattern cannot be created... an empty array was passed as parameter');
141
+ }
142
+ return Pattern.fromString(data.map(pattern => pattern.value).join(''));
143
+ };
144
+ //#endregion
145
+ //#region split
146
+ Pattern.split = (pattern) => {
147
+ return pattern.value
148
+ .split(';')
149
+ .filter(_pattern => _pattern.length > 0)
150
+ .map(_pattern => Pattern.fromString(_pattern));
151
+ };
152
+ //#endregion
153
+ //#region helper methods
154
+ Pattern.getMatchList = (patternType) => {
155
+ const baseNamesForTypeNamePattern = Object.getOwnPropertyNames(TypeNamePattern)
156
+ .filter(property => TypeNamePattern[property] instanceof RegExp)
157
+ .map(regexpForName => regexpForName.slice(9));
158
+ const baseNamesForFieldNamePattern = Object.getOwnPropertyNames(FieldNamePattern)
159
+ .filter(property => FieldNamePattern[property] instanceof RegExp)
160
+ .map(regexpForName => regexpForName.slice(9));
161
+ return patternType === 'TypeNamePattern'
162
+ ? baseNamesForTypeNamePattern
163
+ : patternType === 'FieldNamePattern'
164
+ ? baseNamesForFieldNamePattern
165
+ : [...baseNamesForTypeNamePattern, ...baseNamesForFieldNamePattern];
166
+ };
167
+ //#endregion
168
+ /**
169
+ * finds the last pattern that configures the typeName and/or fieldName given
170
+ * @param pattern
171
+ * @param typeName
172
+ * @param fieldName
173
+ * @returns true if a pattern marks the typeName and or fieldName given to be configured, otherwise false
174
+ */
175
+ Pattern.findLastConfiguration = (pattern, typeName, fieldName) => {
176
+ const key = fieldName ? `${typeName.value}.${fieldName.value}` : typeName.value;
177
+ return Pattern.split(pattern)
178
+ .map(pattern => {
179
+ var _a;
180
+ const result = Pattern.attemptMatchAndConfigure(pattern, typeName, fieldName);
181
+ return (_a = result === null || result === void 0 ? void 0 : result[key]) === null || _a === void 0 ? void 0 : _a.shouldBeConfigured;
182
+ })
183
+ .filter(value => value !== undefined)
184
+ .reduce((_acc, value) => value, false);
185
+ };
186
+ /**
187
+ * @name TypeNamePattern
188
+ *
189
+ * @description A compact string of patterns used in the config for granular configuration of Graphql Types.
190
+ *
191
+ * The string can contain one or more patterns, each pattern ends with a semi-colon (`;`).
192
+ *
193
+ * To apply an option to all Graphql Types or all fields, use the allTypeNames (`@*TypeNames`) tokens.
194
+ *
195
+ * Wherever you use the allTypeNames token, know very well that you can make some exceptions. After all, to every rule, there is an exception.
196
+ *
197
+ * A **square bracket** (`[]`) is used to specify what should be included and a **negated square bracket** (`-[]`) is used to specify what should be excluded.
198
+ *
199
+ * 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.
200
+ *
201
+ * ## Available Builder Methods and the patterns they make
202
+ * ```ts
203
+ * const Droid = TypeName.fromString('Droid');
204
+ * const Starship = TypeName.fromString('Starship');
205
+ * const Human = TypeName.fromString('Human');
206
+ * const Movie = TypeName.fromString('Movie');
207
+
208
+ *
209
+ * // Configuring specific Graphql Types
210
+ * const pattern = TypeNamePattern.forTypeNames([Droid, Starship]);
211
+ * console.log(pattern); // "Droid;Starship;"
212
+ *
213
+ * // Configuring all Graphql Types
214
+ * const pattern = TypeNamePattern.forAllTypeNames();
215
+ * console.log(pattern); // "@*TypeNames;"
216
+
217
+ * // Configuring all Graphql Types except those specified in the exclusion list of TypeNames
218
+ * const pattern = TypeNamePattern.forAllTypeNamesExcludeTypeNames([Droid, Starship]);
219
+ * console.log(pattern); // "@*TypeNames-[Droid,Starship];"
220
+ *
221
+ */
222
+ export class TypeNamePattern extends Pattern {
223
+ constructor(value) {
224
+ super(value);
225
+ }
226
+ }
227
+ //#region `'TypeName;AnotherTypeName;'`
228
+ TypeNamePattern.forTypeNames = (typeNames) => {
229
+ typeNames = arrayWrap(typeNames);
230
+ if (typeNames.length < 1) {
231
+ throw new Error('Pattern cannot be created... No TypeNames were specified');
232
+ }
233
+ return TypeNamePattern.fromString(arrayWrap(typeNames)
234
+ .map(typeName => `${typeName.value};`)
235
+ .join(''));
236
+ };
237
+ TypeNamePattern.regexpForTypeNames = /\b(?!TypeNames|FieldNames\b)(?<typeName>\w+;)/gim; // TODO: fix this: regexp.test('@*TypeName;') returns true which shouldn't happen
238
+ TypeNamePattern.matchAndConfigureTypeNames = (pattern, typeName) => {
239
+ const regexp = TypeNamePattern.regexpForTypeNames;
240
+ resetIndex(regexp);
241
+ let result;
242
+ const matchAndConfigure = {};
243
+ while ((result = regexp.exec(pattern.value)) !== null) {
244
+ const _typeName = result.groups.typeName.replace(';', '');
245
+ const key = _typeName;
246
+ const matchFound = _typeName === typeName.value;
247
+ const shouldBeConfigured = matchFound;
248
+ matchAndConfigure[key] = { matchFound, shouldBeConfigured };
249
+ }
250
+ resetIndex(regexp);
251
+ return matchAndConfigure;
252
+ };
253
+ //#endregion
254
+ //#region `'@*TypeNames;'`
255
+ TypeNamePattern.forAllTypeNames = () => Pattern.fromString(TypeName.allTypeNames);
256
+ TypeNamePattern.regexpForAllTypeNames = /(?<allTypeNames>@\*TypeNames;)/gim;
257
+ TypeNamePattern.matchAndConfigureAllTypeNames = (pattern, typeName) => {
258
+ const regexp = TypeNamePattern.regexpForAllTypeNames;
259
+ resetIndex(regexp);
260
+ const matchAndConfigure = {};
261
+ const key = typeName.value;
262
+ const matchFound = regexp.test(pattern.value);
263
+ const shouldBeConfigured = matchFound;
264
+ matchAndConfigure[key] = { matchFound, shouldBeConfigured };
265
+ resetIndex(regexp);
266
+ return matchAndConfigure;
267
+ };
268
+ //#endregion
269
+ //#region `'@*TypeNames-[excludeTypeNames];'`
270
+ TypeNamePattern.forAllTypeNamesExcludeTypeNames = (typeNames) => {
271
+ typeNames = arrayWrap(typeNames);
272
+ if (typeNames.length < 1) {
273
+ throw new Error('Pattern cannot be created... No TypeNames were excluded');
274
+ }
275
+ const _typeNames = typeNames.map(typeName => typeName.value).join();
276
+ return Pattern.fromString(`${TypeName.allTypeNames}-[${_typeNames}];`);
277
+ };
278
+ TypeNamePattern.regexpForAllTypeNamesExcludeTypeNames = /@\*TypeNames-\[\s*(?<typeNames>(\w+,?\s*)*)\];/gim;
279
+ TypeNamePattern.matchAndConfigureAllTypeNamesExcludeTypeNames = (pattern, typeName) => {
280
+ const regexp = TypeNamePattern.regexpForAllTypeNamesExcludeTypeNames;
281
+ resetIndex(regexp);
282
+ let result;
283
+ const matchAndConfigure = {};
284
+ // typeNames that were excluded...
285
+ while ((result = regexp.exec(pattern.value)) !== null) {
286
+ const _typeNames = strToList(result.groups.typeNames);
287
+ _typeNames.forEach(_typeName => {
288
+ const key = _typeName;
289
+ const matchFound = true;
290
+ const shouldBeConfigured = false;
291
+ matchAndConfigure[key] = { matchFound, shouldBeConfigured };
292
+ });
293
+ }
294
+ // interpret global pattern: if typeName is not excluded ...
295
+ const key = typeName.value;
296
+ if (matchAndConfigure[key] === undefined) {
297
+ matchAndConfigure[key] = { matchFound: false, shouldBeConfigured: true };
298
+ }
299
+ resetIndex(regexp);
300
+ return matchAndConfigure;
301
+ };
302
+ /**
303
+ * @name FieldNamePattern
304
+ *
305
+ * @description A compact string of patterns used in the config for granular configuration the fields of a Graphql Type
306
+ *
307
+ * The string can contain one or more patterns, each pattern ends with a semi-colon (`;`).
308
+ *
309
+ * A dot (`.`) is used to separate the TypeName from the FieldNames in each pattern.
310
+ *
311
+ * To apply an option to all Graphql Types or all fields, use the allTypeNames (`@*TypeNames`) and allFieldNames (`@*FieldNames`) tokens respectively.
312
+ *
313
+ * 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.
314
+ *
315
+ * A **square bracket** (`[]`) is used to specify what should be included and a **negated square bracket** (`-[]`) is used to specify what should be excluded.
316
+ *
317
+ * 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.
318
+ *
319
+ * ## Available Builder Methods and the patterns they make
320
+ * ```ts
321
+ * const Droid = TypeName.fromString('Droid');
322
+ * const Starship = TypeName.fromString('Starship');
323
+ * const Human = TypeName.fromString('Human');
324
+ * const Movie = TypeName.fromString('Movie');
325
+ *
326
+ * const id = FieldName.fromString('id');
327
+ * const name = FieldName.fromString('name');
328
+ * const friends = FieldName.fromString('friends');
329
+ * const friend = FieldName.fromString('friend');
330
+ * const title = FieldName.fromString('title');
331
+ * const episode = FieldName.fromString('episode');
332
+ * const length = FieldName.fromString('length');
333
+ *
334
+ * // Configuring specific fields of a specific Graphql Type
335
+ * const pattern = FieldNamePattern.forFieldNamesOfTypeName([
336
+ * [Droid, [id, name, friends]], // individual
337
+ * [Human, [id, name, title]], // individual
338
+ * [Starship, [name, length]], // individual
339
+ * ]);
340
+ * console.log(pattern); // "Droid.[id,name,friends];Human.[id,name,title];Starship.[name,length];"
341
+ *
342
+ * // Configuring all fields of a specific Graphql Type
343
+ * const pattern = FieldNamePattern.forAllFieldNamesOfTypeName([Droid, Movie]);
344
+ * console.log(pattern); // "Droid.@*FieldNames;Movie.@*FieldNames;"
345
+ *
346
+ * // Configuring all fields except those specified in the exclusion list of FieldNames for a specific GraphQL Type
347
+ * const pattern = FieldNamePattern.forAllFieldNamesExcludeFieldNamesOfTypeName([
348
+ * [Droid, [id, name, friends]], // individual
349
+ * [Human, [id, name, title]], // individual
350
+ * [Starship, [name, length]], // individual
351
+ * ]);
352
+ * console.log(pattern); // "Droid.@*FieldNames-[id,name,friends];Human.@*FieldNames-[id,name,title];Starship.@*FieldNames-[name,length];"
353
+ *
354
+ * // Configuring specific fields of all Graphql Types
355
+ * const pattern = FieldNamePattern.forFieldNamesOfAllTypeNames([id, name, friends]);
356
+ * console.log(pattern); // "@*TypeNames.[id,name,friends];"
357
+ *
358
+ * // Configuring all fields of all Graphql Types
359
+ * const pattern = FieldNamePattern.forAllFieldNamesOfAllTypeNames();
360
+ * console.log(pattern); // "@*TypeNames.@*FieldNames;"
361
+ *
362
+ * // Configuring all fields except those specified in the exclusion list of FieldNames for all GraphQL Types
363
+ * const pattern = FieldNamePattern.forAllFieldNamesExcludeFieldNamesOfAllTypeNames([id, name, friends]);
364
+ * console.log(pattern); // "@*TypeNames.@*FieldNames-[id,name,friends];"
365
+ *
366
+ * // Configuring specific fields of all GraphQL Types except those specified in the exclusion list of TypeNames
367
+ * const pattern = FieldNamePattern.forFieldNamesOfAllTypeNamesExcludeTypeNames([Droid, Human], [id, name, friends]);
368
+ * console.log(pattern); // "@*TypeNames-[Droid,Human].[id,name,friends];"
369
+ *
370
+ * // Configuring all fields of all GraphQL Types except those specified in the exclusion list of TypeNames
371
+ * const pattern = FieldNamePattern.forAllFieldNamesOfAllTypeNamesExcludeTypeNames([Droid, Human]);
372
+ * console.log(pattern); // "@*TypeNames-[Droid,Human].@*FieldNames;"
373
+ *
374
+ * // 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
375
+ * const pattern = FieldNamePattern.forAllFieldNamesExcludeFieldNamesOfAllTypeNamesExcludeTypeNames(
376
+ * [Droid, Human],
377
+ * [id, name, friends]
378
+ * );
379
+ * console.log(pattern); // "@*TypeNames-[Droid,Human].@*FieldNames-[id,name,friends];"
380
+ * ```
381
+ *
382
+ */
383
+ export class FieldNamePattern extends Pattern {
384
+ constructor(value) {
385
+ super(value);
386
+ }
387
+ }
388
+ //#region `'TypeName.[fieldNames];'`
389
+ FieldNamePattern.forFieldNamesOfTypeName = (data) => {
390
+ const expandedPattern = {};
391
+ if (data.length < 1) {
392
+ throw new Error('Pattern cannot be created... an empty array was passed as parameter');
393
+ }
394
+ data.forEach(([typeNames, fieldNames]) => {
395
+ const _typeNames = arrayWrap(typeNames);
396
+ const _fieldNames = arrayWrap(fieldNames);
397
+ if (_typeNames.length < 1) {
398
+ throw new Error('Pattern cannot be created... No TypeNames were specified');
399
+ }
400
+ else if (_fieldNames.length < 1) {
401
+ throw new Error('Pattern cannot be created... No FieldNames were specified');
402
+ }
403
+ _typeNames.forEach(typeName => {
404
+ var _a;
405
+ expandedPattern[typeName.value] = [...((_a = expandedPattern[typeName.value]) !== null && _a !== void 0 ? _a : []), ..._fieldNames];
406
+ });
407
+ });
408
+ return FieldNamePattern.fromString(Object.keys(expandedPattern)
409
+ .map(_typeName => {
410
+ const _fieldNames = expandedPattern[_typeName].map(fieldName => fieldName.value).join();
411
+ return `${_typeName}.[${_fieldNames}];`;
412
+ })
413
+ .join(''));
414
+ };
415
+ FieldNamePattern.regexpForFieldNamesOfTypeName = /(?<typeName>\w+\s*)(?<!\s*@\s*\*\s*TypeNames\s*)\.\[\s*(?<fieldNames>(\w+,?\s*)*)\];/gim;
416
+ FieldNamePattern.matchAndConfigureFieldNamesOfTypeName = (pattern, typeName, fieldName) => {
417
+ const regexp = FieldNamePattern.regexpForFieldNamesOfTypeName;
418
+ resetIndex(regexp);
419
+ let result;
420
+ const matchAndConfigure = {};
421
+ // typeName and fieldNames that were specified in the pattern
422
+ while ((result = regexp.exec(pattern.value)) !== null) {
423
+ const _typeName = result.groups.typeName;
424
+ const _fieldNames = strToList(result.groups.fieldNames);
425
+ _fieldNames.forEach(_fieldName => {
426
+ const key = `${_typeName}.${_fieldName}`;
427
+ const matchFound = true;
428
+ const shouldBeConfigured = true;
429
+ matchAndConfigure[key] = { matchFound, shouldBeConfigured };
430
+ });
431
+ }
432
+ resetIndex(regexp);
433
+ return matchAndConfigure;
434
+ };
435
+ //#endregion
436
+ //#region `'TypeName.@*FieldNames;'`
437
+ FieldNamePattern.forAllFieldNamesOfTypeName = (typeNames) => {
438
+ const _typeNames = arrayWrap(typeNames);
439
+ if (_typeNames.length < 1) {
440
+ throw new Error('Pattern cannot be created... No TypeNames were specified');
441
+ }
442
+ return FieldNamePattern.fromString(_typeNames.map(_typeName => `${_typeName.value}.${FieldName.allFieldNames};`).join(''));
443
+ };
444
+ FieldNamePattern.regexpForAllFieldNamesOfTypeName = /(?<typeName>\w+\s*)(?<!\s*@\s*\*\s*TypeNames\s*)\.@\*FieldNames;/gim;
445
+ FieldNamePattern.matchAndConfigureAllFieldNamesOfTypeName = (pattern, typeName, fieldName) => {
446
+ const regexp = FieldNamePattern.regexpForAllFieldNamesOfTypeName;
447
+ resetIndex(regexp);
448
+ let result;
449
+ const matchAndConfigure = {};
450
+ while ((result = regexp.exec(pattern.value)) !== null) {
451
+ const _typeName = result.groups.typeName;
452
+ const key = `${_typeName}.${fieldName.value}`;
453
+ const matchFound = true;
454
+ const shouldBeConfigured = true;
455
+ matchAndConfigure[key] = { matchFound, shouldBeConfigured };
456
+ }
457
+ resetIndex(regexp);
458
+ return matchAndConfigure;
459
+ };
460
+ //#endregion
461
+ //#region `'TypeName.@*FieldNames-[excludeFieldNames];'`
462
+ FieldNamePattern.forAllFieldNamesExcludeFieldNamesOfTypeName = (data) => {
463
+ const expandedPattern = {};
464
+ if (data.length < 1) {
465
+ throw new Error('Pattern cannot be created... an empty array was passed as parameter');
466
+ }
467
+ data.forEach(([typeNames, fieldNames]) => {
468
+ const _typeNames = arrayWrap(typeNames);
469
+ const _fieldNames = arrayWrap(fieldNames);
470
+ if (_typeNames.length < 1) {
471
+ throw new Error('Pattern cannot be created... No TypeNames were specified');
472
+ }
473
+ else if (_fieldNames.length < 1) {
474
+ throw new Error('Pattern cannot be created... No FieldNames were specified');
475
+ }
476
+ _typeNames.forEach(typeName => {
477
+ var _a;
478
+ expandedPattern[typeName.value] = [...((_a = expandedPattern[typeName.value]) !== null && _a !== void 0 ? _a : []), ..._fieldNames];
479
+ });
480
+ });
481
+ return FieldNamePattern.fromString(Object.keys(expandedPattern)
482
+ .map(_typeName => {
483
+ const _fieldNames = expandedPattern[_typeName].map(fieldName => fieldName.value).join();
484
+ return `${_typeName}.${FieldName.allFieldNames}-[${_fieldNames}];`;
485
+ })
486
+ .join(''));
487
+ };
488
+ FieldNamePattern.regexpForAllFieldNamesExcludeFieldNamesOfTypeName = /(?<typeName>\w+\s*)(?<!\s*@\s*\*\s*TypeNames\s*)\.@\*FieldNames-\[\s*(?<fieldNames>(\w+,?\s*)*)\];/gim;
489
+ FieldNamePattern.matchAndConfigureAllFieldNamesExcludeFieldNamesOfTypeName = (pattern, typeName, fieldName) => {
490
+ const regexp = FieldNamePattern.regexpForAllFieldNamesExcludeFieldNamesOfTypeName;
491
+ resetIndex(regexp);
492
+ let result;
493
+ const matchAndConfigure = {};
494
+ // typeName.fieldName that was excluded...
495
+ while ((result = regexp.exec(pattern.value)) !== null) {
496
+ const _typeName = result.groups.typeName;
497
+ const _fieldNames = strToList(result.groups.fieldNames);
498
+ _fieldNames.forEach(_fieldName => {
499
+ const key = `${_typeName}.${_fieldName}`;
500
+ const matchFound = true;
501
+ const shouldBeConfigured = false;
502
+ matchAndConfigure[key] = { matchFound, shouldBeConfigured };
503
+ });
504
+ // interpret global pattern: typeName.fieldName that was included
505
+ const key = `${_typeName}.${fieldName.value}`;
506
+ if (matchAndConfigure[key] === undefined) {
507
+ matchAndConfigure[key] = { matchFound: false, shouldBeConfigured: true };
508
+ }
509
+ }
510
+ resetIndex(regexp);
511
+ return matchAndConfigure;
512
+ };
513
+ //#endregion
514
+ //#region `'@*TypeNames.[fieldNames];'`
515
+ FieldNamePattern.forFieldNamesOfAllTypeNames = (fieldNames) => {
516
+ fieldNames = arrayWrap(fieldNames);
517
+ if (fieldNames.length < 1) {
518
+ throw new Error('Pattern cannot be created... No FieldNames were specified');
519
+ }
520
+ const _fieldNames = fieldNames.map(fieldName => fieldName.value).join();
521
+ return FieldNamePattern.fromString(`${TypeName.allTypeNames}.[${_fieldNames}];`);
522
+ };
523
+ FieldNamePattern.regexpForFieldNamesOfAllTypeNames = /@\*TypeNames\.\[\s*(?<fieldNames>(\w+,?\s*)*)\];/gim;
524
+ FieldNamePattern.matchAndConfigureFieldNamesOfAllTypeNames = (pattern, typeName, fieldName) => {
525
+ const regexp = FieldNamePattern.regexpForFieldNamesOfAllTypeNames;
526
+ resetIndex(regexp);
527
+ let result;
528
+ const matchAndConfigure = {};
529
+ while ((result = regexp.exec(pattern.value)) !== null) {
530
+ const _fieldNames = strToList(result.groups.fieldNames);
531
+ _fieldNames.forEach(_fieldName => {
532
+ const key = `${typeName.value}.${_fieldName}`;
533
+ const matchFound = true;
534
+ const shouldBeConfigured = true;
535
+ matchAndConfigure[key] = { matchFound, shouldBeConfigured };
536
+ });
537
+ }
538
+ resetIndex(regexp);
539
+ return matchAndConfigure;
540
+ };
541
+ //#endregion
542
+ //#region `'@*TypeNames.@*FieldNames;'`
543
+ FieldNamePattern.forAllFieldNamesOfAllTypeNames = () => {
544
+ return FieldNamePattern.fromString(`${TypeName.allTypeNames}.${FieldName.allFieldNames};`);
545
+ };
546
+ FieldNamePattern.regexpForAllFieldNamesOfAllTypeNames = /@\*TypeNames\.@\*FieldNames;/gim;
547
+ FieldNamePattern.matchAndConfigureAllFieldNamesOfAllTypeNames = (pattern, typeName, fieldName) => {
548
+ const regexp = FieldNamePattern.regexpForAllFieldNamesOfAllTypeNames;
549
+ resetIndex(regexp);
550
+ const matchAndConfigure = {};
551
+ const key = `${typeName.value}.${fieldName.value}`;
552
+ const matchFound = regexp.test(pattern.value);
553
+ const shouldBeConfigured = matchFound;
554
+ matchAndConfigure[key] = { matchFound, shouldBeConfigured };
555
+ resetIndex(regexp);
556
+ return matchAndConfigure;
557
+ };
558
+ //#endregion
559
+ //#region `'@*TypeNames.@*FieldNames-[excludeFieldNames];'`
560
+ FieldNamePattern.forAllFieldNamesExcludeFieldNamesOfAllTypeNames = (fieldNames) => {
561
+ fieldNames = arrayWrap(fieldNames);
562
+ if (fieldNames.length < 1) {
563
+ throw new Error('Pattern cannot be created... No FieldNames were excluded');
564
+ }
565
+ const _fieldNames = fieldNames.map(fieldName => fieldName.value).join();
566
+ return FieldNamePattern.fromString(`${TypeName.allTypeNames}.${FieldName.allFieldNames}-[${_fieldNames}];`);
567
+ };
568
+ FieldNamePattern.regexpForAllFieldNamesExcludeFieldNamesOfAllTypeNames = /@\*TypeNames\.@\*FieldNames-\[\s*(?<fieldNames>(\w+,?\s*)*)\];/gim;
569
+ FieldNamePattern.matchAndConfigureAllFieldNamesExcludeFieldNamesOfAllTypeNames = (pattern, typeName, fieldName) => {
570
+ const regexp = FieldNamePattern.regexpForAllFieldNamesExcludeFieldNamesOfAllTypeNames;
571
+ resetIndex(regexp);
572
+ let result;
573
+ const matchAndConfigure = {};
574
+ while ((result = regexp.exec(pattern.value)) !== null) {
575
+ const _fieldNames = strToList(result.groups.fieldNames);
576
+ // typeName.fieldName that was excluded...
577
+ _fieldNames.forEach(_fieldName => {
578
+ const key = `${typeName.value}.${_fieldName}`;
579
+ const matchFound = true;
580
+ const shouldBeConfigured = false;
581
+ matchAndConfigure[key] = { matchFound, shouldBeConfigured };
582
+ });
583
+ }
584
+ // interpret global pattern: typeName.fieldName that was included...
585
+ const key = `${typeName.value}.${fieldName.value}`;
586
+ if (matchAndConfigure[key] === undefined) {
587
+ matchAndConfigure[key] = { matchFound: false, shouldBeConfigured: true };
588
+ }
589
+ resetIndex(regexp);
590
+ return matchAndConfigure;
591
+ };
592
+ //#endregion
593
+ //#region `'@*TypeNames-[excludeTypeNames].[fieldNames];'`
594
+ FieldNamePattern.forFieldNamesOfAllTypeNamesExcludeTypeNames = (typeNames, fieldNames) => {
595
+ typeNames = arrayWrap(typeNames);
596
+ fieldNames = arrayWrap(fieldNames);
597
+ if (typeNames.length < 1) {
598
+ throw new Error('Pattern cannot be created... No TypeNames were excluded');
599
+ }
600
+ else if (fieldNames.length < 1) {
601
+ throw new Error('Pattern cannot be created... No FieldNames were specified');
602
+ }
603
+ const _typeNames = typeNames.map(typeName => typeName.value).join();
604
+ const _fieldNames = fieldNames.map(fieldName => fieldName.value).join();
605
+ return FieldNamePattern.fromString(`${TypeName.allTypeNames}-[${_typeNames}].[${_fieldNames}];`);
606
+ };
607
+ FieldNamePattern.regexpForFieldNamesOfAllTypeNamesExcludeTypeNames = /@\*TypeNames-\[\s*(?<typeNames>(\w+,?\s*)*)\]\.\[\s*(?<fieldNames>(\w+,?\s*)*)\];/gim;
608
+ FieldNamePattern.matchAndConfigureFieldNamesOfAllTypeNamesExcludeTypeNames = (pattern, typeName, fieldName) => {
609
+ const regexp = FieldNamePattern.regexpForFieldNamesOfAllTypeNamesExcludeTypeNames;
610
+ resetIndex(regexp);
611
+ let result;
612
+ const matchAndConfigure = {};
613
+ while ((result = regexp.exec(pattern.value)) !== null) {
614
+ const _typeNames = strToList(result.groups.typeNames);
615
+ const _fieldNames = strToList(result.groups.fieldNames);
616
+ // typeName.fieldName that was excluded
617
+ _typeNames.forEach(_typeName => _fieldNames.forEach(_fieldName => {
618
+ const key = `${_typeName}.${_fieldName}`;
619
+ const matchFound = true;
620
+ const shouldBeConfigured = false;
621
+ matchAndConfigure[key] = { matchFound, shouldBeConfigured };
622
+ }));
623
+ // interpret the global pattern:
624
+ // for fieldNames specified in the list of fieldNames for other typeNames not specified in the exclusion list of TypeNames
625
+ _fieldNames.forEach(_fieldName => {
626
+ const key = `${typeName.value}.${_fieldName}`;
627
+ if (!_typeNames.includes(typeName.value) && matchAndConfigure[key] === undefined) {
628
+ const matchFound = false;
629
+ const shouldBeConfigured = true;
630
+ matchAndConfigure[key] = { matchFound, shouldBeConfigured };
631
+ }
632
+ });
633
+ }
634
+ resetIndex(regexp);
635
+ return matchAndConfigure;
636
+ };
637
+ //#endregion
638
+ //#region `'@*TypeNames-[excludeTypeNames].@*FieldNames;'`
639
+ FieldNamePattern.forAllFieldNamesOfAllTypeNamesExcludeTypeNames = (typeNames) => {
640
+ typeNames = arrayWrap(typeNames);
641
+ if (typeNames.length < 1) {
642
+ throw new Error('Pattern cannot be created... No TypeNames were excluded');
643
+ }
644
+ const _typeNames = typeNames.map(typeName => typeName.value).join();
645
+ return FieldNamePattern.fromString(`${TypeName.allTypeNames}-[${_typeNames}].${FieldName.allFieldNames};`);
646
+ };
647
+ FieldNamePattern.regexpForAllFieldNamesOfAllTypeNamesExcludeTypeNames = /@\*TypeNames-\[\s*(?<typeNames>(\w+,?\s*)*)\]\.@\*FieldNames;/gim;
648
+ FieldNamePattern.matchAndConfigureAllFieldNamesOfAllTypeNamesExcludeTypeNames = (pattern, typeName, fieldName) => {
649
+ const regexp = FieldNamePattern.regexpForAllFieldNamesOfAllTypeNamesExcludeTypeNames;
650
+ resetIndex(regexp);
651
+ let result;
652
+ const matchAndConfigure = {};
653
+ while ((result = regexp.exec(pattern.value)) !== null) {
654
+ const _typeNames = strToList(result.groups.typeNames);
655
+ _typeNames.forEach(_typeName => {
656
+ const key = `${_typeName}.${fieldName.value}`;
657
+ const matchFound = true;
658
+ const shouldBeConfigured = false;
659
+ matchAndConfigure[key] = { matchFound, shouldBeConfigured };
660
+ });
661
+ // interpret the global pattern:
662
+ // for all other typeName.fieldName combination where the typeName is not in the exclusion list of TypeNames
663
+ const key = `${typeName.value}.${fieldName.value}`;
664
+ if (matchAndConfigure[key] === undefined) {
665
+ matchAndConfigure[key] = { matchFound: false, shouldBeConfigured: true };
666
+ }
667
+ }
668
+ resetIndex(regexp);
669
+ return matchAndConfigure;
670
+ };
671
+ //#endregion
672
+ //#region `'@*TypeNames-[excludeTypeNames].@*FieldNames-[excludeFieldNames];'`
673
+ FieldNamePattern.forAllFieldNamesExcludeFieldNamesOfAllTypeNamesExcludeTypeNames = (typeNames, fieldNames) => {
674
+ typeNames = arrayWrap(typeNames);
675
+ fieldNames = arrayWrap(fieldNames);
676
+ if (typeNames.length < 1) {
677
+ throw new Error('Pattern cannot be created... No TypeNames were excluded');
678
+ }
679
+ else if (fieldNames.length < 1) {
680
+ throw new Error('Pattern cannot be created... No FieldNames were excluded');
681
+ }
682
+ const _typeNames = typeNames.map(typeName => typeName.value).join();
683
+ const _fieldNames = fieldNames.map(fieldName => fieldName.value).join();
684
+ return FieldNamePattern.fromString(`${TypeName.allTypeNames}-[${_typeNames}].${FieldName.allFieldNames}-[${_fieldNames}];`);
685
+ };
686
+ FieldNamePattern.regexpForAllFieldNamesExcludeFieldNamesOfAllTypeNamesExcludeTypeNames = /@\*TypeNames-\[\s*(?<typeNames>(\w+,?\s*)*)\]\.@\*FieldNames-\[\s*(?<fieldNames>(\w+,?\s*)*)\];/gim;
687
+ FieldNamePattern.matchAndConfigureAllFieldNamesExcludeFieldNamesOfAllTypeNamesExcludeTypeNames = (pattern, typeName, fieldName) => {
688
+ const regexp = FieldNamePattern.regexpForAllFieldNamesExcludeFieldNamesOfAllTypeNamesExcludeTypeNames;
689
+ resetIndex(regexp);
690
+ let result;
691
+ const matchAndConfigure = {};
692
+ while ((result = regexp.exec(pattern.value)) !== null) {
693
+ const _typeNames = strToList(result.groups.typeNames);
694
+ const _fieldNames = strToList(result.groups.fieldNames);
695
+ _typeNames.forEach(_typeName => _fieldNames.forEach(_fieldName => {
696
+ const key = `${_typeName}.${_fieldName}`;
697
+ const matchFound = true;
698
+ const shouldBeConfigured = false;
699
+ matchAndConfigure[key] = { matchFound, shouldBeConfigured };
700
+ }));
701
+ }
702
+ // interpret the global pattern
703
+ // for any other typeName.fieldName combination which is not excluded in the pattern
704
+ const key = `${typeName.value}.${fieldName.value}`;
705
+ if (matchAndConfigure[key] === undefined) {
706
+ matchAndConfigure[key] = { matchFound: false, shouldBeConfigured: true };
707
+ }
708
+ resetIndex(regexp);
709
+ return matchAndConfigure;
710
+ };
711
+ // type MatchAndConfigure =
712
+ // | 'matchAndConfigureTypeNames'
713
+ // | 'matchAndConfigureAllTypeNames'
714
+ // | 'matchAndConfigureAllTypeNamesExcludeTypeNames'
715
+ // | 'matchAndConfigureFieldNamesOfTypeName'
716
+ // | 'matchAndConfigureAllFieldNamesOfTypeName'
717
+ // | 'matchAndConfigureAllFieldNamesExcludeFieldNamesOfTypeName'
718
+ // | 'matchAndConfigureFieldNamesOfAllTypeNames'
719
+ // | 'matchAndConfigureAllFieldNamesOfAllTypeNames'
720
+ // | 'matchAndConfigureAllFieldNamesExcludeFieldNamesOfAllTypeNames'
721
+ // | 'matchAndConfigureFieldNamesOfAllTypeNamesExcludeTypeNames'
722
+ // | 'matchAndConfigureAllFieldNamesOfAllTypeNamesExcludeTypeNames'
723
+ // | 'matchAndConfigureAllFieldNamesExcludeFieldNamesOfAllTypeNamesExcludeTypeNames';