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