@resistdesign/voltra 3.0.0-alpha.6 → 3.0.0-alpha.8

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.
package/common/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { b as IDGeneration, d as ItemRelationships, f as Logging, R as Routing, S as SearchUtils, c as StringTransformers, e as Testing, a as TypeParsing } from '../index-C3-iD9Mh.js';
1
+ export { b as IDGeneration, d as ItemRelationships, f as Logging, R as Routing, S as SearchUtils, c as StringTransformers, e as Testing, a as TypeParsing } from '../index-sIX5qe0K.js';
2
2
  export { H as HelperTypes, l as ItemRelationshipInfoTypes, m as SearchTypes } from '../SearchTypes-DjN6YQzE.js';
3
3
  import '../Validation-CFP59oIP.js';
4
4
  import 'typescript';
package/common/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { SyntaxKind, isLiteralTypeNode, isStringLiteral, isNumericLiteral, createSourceFile, ScriptTarget } from 'typescript';
1
+ import { SyntaxKind } from 'typescript';
2
2
  import { promises } from 'fs';
3
3
  import Path from 'path';
4
4
  import { pathToFileURL } from 'url';
@@ -15,39 +15,42 @@ __export(TypeParsing_exports, {
15
15
  Constants: () => Constants_exports,
16
16
  TypeInfo: () => TypeInfo_exports,
17
17
  TypeMapping: () => TypeMapping_exports,
18
- Validation: () => Validation_exports,
19
- getTypeInfoMapFromTypeScript: () => getTypeInfoMapFromTypeScript
18
+ Validation: () => Validation_exports
20
19
  });
21
20
 
22
- // src/common/TypeParsing/TypeMapping.ts
23
- var TypeMapping_exports = {};
24
- __export(TypeMapping_exports, {
25
- convertASTToMap: () => convertASTToMap
21
+ // src/common/TypeParsing/Validation.ts
22
+ var Validation_exports = {};
23
+ __export(Validation_exports, {
24
+ DENIED_TYPE_OPERATIONS: () => DENIED_TYPE_OPERATIONS,
25
+ ERROR_MESSAGE_CONSTANTS: () => ERROR_MESSAGE_CONSTANTS,
26
+ INVALID_CUSTOM_TYPE: () => INVALID_CUSTOM_TYPE,
27
+ PRIMITIVE_ERROR_MESSAGE_CONSTANTS: () => PRIMITIVE_ERROR_MESSAGE_CONSTANTS,
28
+ RelationshipValidationType: () => RelationshipValidationType,
29
+ TYPE_KEYWORD_VALIDATORS: () => TYPE_KEYWORD_VALIDATORS,
30
+ getValidityValue: () => getValidityValue,
31
+ hasValue: () => hasValue,
32
+ validateArrayOfTypeInfoFieldValues: () => validateArrayOfTypeInfoFieldValues,
33
+ validateCustomType: () => validateCustomType,
34
+ validateKeywordType: () => validateKeywordType,
35
+ validateTypeInfoFieldOperationAllowed: () => validateTypeInfoFieldOperationAllowed,
36
+ validateTypeInfoFieldValue: () => validateTypeInfoFieldValue,
37
+ validateTypeInfoValue: () => validateTypeInfoValue,
38
+ validateTypeOperationAllowed: () => validateTypeOperationAllowed,
39
+ validateValueMatchesPattern: () => validateValueMatchesPattern
26
40
  });
27
- var convertASTToMap = (node, map = {}, parentName) => {
28
- node.forEachChild((child) => {
29
- const { kind: childKind } = child;
30
- if (childKind === SyntaxKind.ModuleDeclaration) {
31
- const moduleNode = child;
32
- const { name: moduleName } = moduleNode;
33
- const textModuleName = moduleName.getText();
34
- const fullModuleName = parentName ? `${parentName}.${textModuleName}` : textModuleName;
35
- convertASTToMap(moduleNode, map, fullModuleName);
36
- }
37
- if (childKind === SyntaxKind.ModuleBlock) {
38
- convertASTToMap(child, map, parentName);
39
- }
40
- if (childKind === SyntaxKind.TypeAliasDeclaration) {
41
- const typeAliasDec = child;
42
- const {
43
- name: { text: typeName }
44
- } = typeAliasDec;
45
- const fullTypeName = parentName ? `${parentName}.${typeName}` : typeName;
46
- map[fullTypeName] = typeAliasDec;
47
- }
48
- });
49
- return map;
50
- };
41
+
42
+ // src/common/TypeParsing/TypeInfo.ts
43
+ var TypeInfo_exports = {};
44
+ __export(TypeInfo_exports, {
45
+ TypeOperation: () => TypeOperation
46
+ });
47
+ var TypeOperation = /* @__PURE__ */ ((TypeOperation2) => {
48
+ TypeOperation2["CREATE"] = "CREATE";
49
+ TypeOperation2["READ"] = "READ";
50
+ TypeOperation2["UPDATE"] = "UPDATE";
51
+ TypeOperation2["DELETE"] = "DELETE";
52
+ return TypeOperation2;
53
+ })(TypeOperation || {});
51
54
 
52
55
  // src/common/Routing.ts
53
56
  var Routing_exports = {};
@@ -136,581 +139,6 @@ var getParamsAndTestPath = (path, testPath, exact = false) => {
136
139
  }
137
140
  };
138
141
 
139
- // src/common/TypeParsing/ParsingUtils/extractCommentTags.ts
140
- var TAG_NAME_PATH_DELIMITER = ".";
141
- var getFlatTagValue = (tagValue) => {
142
- if (typeof tagValue === "undefined") {
143
- return "";
144
- } else if (Array.isArray(tagValue)) {
145
- const valueNodeArray = tagValue;
146
- const valueList = [];
147
- for (let i = 0; i < valueNodeArray.length; i++) {
148
- const { text } = valueNodeArray[i];
149
- valueList.push(getFlatTagValue(text));
150
- }
151
- return valueList.join(" ");
152
- } else {
153
- return `${tagValue}`;
154
- }
155
- };
156
- var getTagNameAndValue = (tag) => {
157
- let name = tag.tagName.text, value = getFlatTagValue(tag.comment);
158
- if (value.startsWith(TAG_NAME_PATH_DELIMITER)) {
159
- const extendedTagNameEndIndex = value.indexOf(" ");
160
- const hasActualValue = extendedTagNameEndIndex !== -1;
161
- name += hasActualValue ? value.slice(0, extendedTagNameEndIndex) : value;
162
- value = hasActualValue ? value.slice(extendedTagNameEndIndex + 1) : "";
163
- }
164
- if (value === "") {
165
- value = "true";
166
- }
167
- return {
168
- name,
169
- value
170
- };
171
- };
172
- var getObjectWithValueAppliedToPath = (path = [], value, baseObject) => {
173
- let baseParentObject = void 0, currentParent = void 0;
174
- if (path.length === 0) {
175
- baseParentObject = value;
176
- } else {
177
- for (let i = 0; i < path.length; i++) {
178
- const pathPart = path[i];
179
- const cleanPathPart = typeof pathPart === "number" ? pathPart : `${typeof pathPart !== "undefined" ? pathPart : ""}`;
180
- const isNum = typeof cleanPathPart === "number";
181
- let newCurrentParent = void 0;
182
- if (i === 0) {
183
- if (!baseObject) {
184
- baseParentObject = isNum ? [] : {};
185
- } else {
186
- baseParentObject = isNum ? [...Array.isArray(baseObject) ? baseObject : []] : {
187
- ...typeof baseObject === "object" ? baseObject : {}
188
- };
189
- }
190
- currentParent = baseParentObject;
191
- }
192
- if (i < path.length - 1) {
193
- const existingNewCurrentParent = currentParent[cleanPathPart];
194
- newCurrentParent = isNum ? [
195
- ...Array.isArray(existingNewCurrentParent) ? existingNewCurrentParent : []
196
- ] : {
197
- ...typeof existingNewCurrentParent === "object" ? existingNewCurrentParent : {}
198
- };
199
- currentParent[cleanPathPart] = newCurrentParent;
200
- currentParent = newCurrentParent;
201
- } else {
202
- currentParent[cleanPathPart] = value;
203
- }
204
- }
205
- }
206
- return baseParentObject;
207
- };
208
- var extractCommentTags = (node) => {
209
- const jsDocComments = node["jsDoc"];
210
- let commentTags = {};
211
- if (jsDocComments) {
212
- jsDocComments.forEach((jsDoc) => {
213
- const tags = jsDoc.tags;
214
- if (tags) {
215
- tags.forEach((tag) => {
216
- const { name: tagName, value: tagValue } = getTagNameAndValue(tag);
217
- const potentialJSONValue = getPotentialJSONValue(tagValue);
218
- commentTags = getObjectWithValueAppliedToPath(
219
- getPathArray(tagName, TAG_NAME_PATH_DELIMITER),
220
- potentialJSONValue,
221
- commentTags
222
- );
223
- });
224
- }
225
- });
226
- }
227
- return commentTags;
228
- };
229
- var extractLiteralValues = (node) => {
230
- const literalValues = [];
231
- let detectedTypeKeyword;
232
- for (const type of node.types) {
233
- if (isLiteralTypeNode(type)) {
234
- const literal = type.literal;
235
- if (isStringLiteral(literal)) {
236
- if (!detectedTypeKeyword) detectedTypeKeyword = "string";
237
- if (detectedTypeKeyword === "string") {
238
- literalValues.push(literal.text);
239
- }
240
- } else if (isNumericLiteral(literal)) {
241
- if (!detectedTypeKeyword) detectedTypeKeyword = "number";
242
- if (detectedTypeKeyword === "number") {
243
- literalValues.push(Number(literal.text));
244
- }
245
- } else if (literal.kind === SyntaxKind.TrueKeyword || literal.kind === SyntaxKind.FalseKeyword) {
246
- if (!detectedTypeKeyword) detectedTypeKeyword = "boolean";
247
- if (detectedTypeKeyword === "boolean") {
248
- literalValues.push(literal.kind === SyntaxKind.TrueKeyword);
249
- }
250
- } else if (literal.kind === SyntaxKind.NullKeyword) {
251
- literalValues.push(null);
252
- }
253
- } else {
254
- return void 0;
255
- }
256
- }
257
- return literalValues.length ? { values: literalValues, type: detectedTypeKeyword } : void 0;
258
- };
259
-
260
- // src/common/TypeParsing/ParsingUtils/checkUnionType.ts
261
- var checkUnionType = (unionType) => {
262
- const extracted = extractLiteralValues(unionType);
263
- let typeKeyword = "string";
264
- let options;
265
- if (extracted) {
266
- options = extracted.values;
267
- typeKeyword = extracted.type;
268
- }
269
- return { options: options || [], typeKeyword };
270
- };
271
- var getTypeKeyword = (node) => {
272
- switch (node.kind) {
273
- case SyntaxKind.StringKeyword:
274
- return "string";
275
- case SyntaxKind.NumberKeyword:
276
- return "number";
277
- case SyntaxKind.BooleanKeyword:
278
- return "boolean";
279
- default:
280
- return "string";
281
- }
282
- };
283
-
284
- // src/common/TypeParsing/ParsingUtils/checkType.ts
285
- var checkType = (node) => {
286
- let typeReference;
287
- let isArray = false;
288
- let typeKeyword;
289
- let options;
290
- if (node.kind === SyntaxKind.TypeReference) {
291
- typeReference = node.typeName.getText();
292
- typeKeyword = "string";
293
- } else if (node.kind === SyntaxKind.ArrayType) {
294
- isArray = true;
295
- const elementType = node.elementType;
296
- const {
297
- typeReference: elementReference,
298
- isArray: elementIsArray,
299
- typeKeyword: elementKeyword,
300
- options: elementOptions
301
- } = checkType(elementType);
302
- typeReference = elementReference;
303
- isArray = !!elementIsArray;
304
- typeKeyword = elementKeyword || "string";
305
- options = elementOptions;
306
- } else if (node.kind === SyntaxKind.UnionType) {
307
- const { types: unionTypes } = node;
308
- const { options: unionOptions, typeKeyword: unionTypeKeyword } = checkUnionType(node);
309
- options = unionOptions;
310
- typeKeyword = unionTypeKeyword;
311
- if (!options) {
312
- typeKeyword = getTypeKeyword(unionTypes[0]);
313
- }
314
- } else if (node.kind === SyntaxKind.ParenthesizedType) {
315
- const {
316
- typeReference: parenthesizedReference,
317
- isArray: parenthesizedIsArray,
318
- typeKeyword: parenthesizedKeyword,
319
- options: parenthesizedOptions
320
- } = checkType(node.type);
321
- typeReference = parenthesizedReference;
322
- isArray = !!parenthesizedIsArray;
323
- typeKeyword = parenthesizedKeyword || "string";
324
- options = parenthesizedOptions;
325
- } else {
326
- typeKeyword = getTypeKeyword(node);
327
- }
328
- return { typeReference, isArray, typeKeyword, options };
329
- };
330
-
331
- // src/common/TypeParsing/ParsingUtils/extractTypeDetails.ts
332
- var extractTypeDetails = (type) => {
333
- const { isArray, typeReference, options, typeKeyword } = checkType(type);
334
- return {
335
- type: typeKeyword || "string",
336
- typeReference,
337
- array: !!isArray,
338
- options
339
- };
340
- };
341
-
342
- // src/common/TypeParsing/ParsingUtils/getTypeInfoField.ts
343
- var getTypeInfoField = (propertySignature) => {
344
- const { type, modifiers } = propertySignature;
345
- const {
346
- array,
347
- typeReference,
348
- type: typeKeyword,
349
- options
350
- } = type ? extractTypeDetails(type) : {
351
- array: false,
352
- typeReference: void 0,
353
- type: "string",
354
- options: void 0
355
- };
356
- const readonly = modifiers ? modifiers.some((modifier) => modifier.kind === SyntaxKind.ReadonlyKeyword) : false;
357
- const optional = !!propertySignature.questionToken;
358
- let tags = extractCommentTags(propertySignature);
359
- if (readonly) {
360
- const {
361
- deniedOperations,
362
- deniedOperations: { CREATE, UPDATE, DELETE } = {}
363
- } = tags || {};
364
- tags = {
365
- ...tags,
366
- deniedOperations: {
367
- ...deniedOperations,
368
- create: CREATE ?? true,
369
- update: UPDATE ?? true,
370
- delete: DELETE ?? true
371
- }
372
- };
373
- }
374
- return {
375
- type: typeKeyword,
376
- array,
377
- readonly,
378
- optional,
379
- typeReference,
380
- possibleValues: options,
381
- tags
382
- };
383
- };
384
-
385
- // src/common/TypeParsing/ParsingUtils/getTypeInfo.ts
386
- var getTypeInfo = (typeLiteral) => {
387
- const { members } = typeLiteral;
388
- const tags = extractCommentTags(typeLiteral);
389
- let fields = {};
390
- for (const m of members) {
391
- const { name, kind } = m;
392
- if (name && kind === SyntaxKind.PropertySignature) {
393
- const fieldName = name.getText();
394
- const field = getTypeInfoField(m);
395
- fields = {
396
- ...fields,
397
- [fieldName]: field
398
- };
399
- }
400
- }
401
- return {
402
- fields,
403
- tags
404
- };
405
- };
406
- var getUnionOrIntersectionTypeInfo = (unionType, typeMap) => {
407
- const { kind, types } = unionType;
408
- const isUnion = kind === SyntaxKind.UnionType;
409
- let typeInfo;
410
- for (const t of types) {
411
- const { kind: kind2 } = t;
412
- let nextTypeInfo;
413
- if (kind2 === SyntaxKind.TypeReference) {
414
- const { typeName } = t;
415
- const refNode = typeMap[typeName.getText()];
416
- if (refNode) {
417
- nextTypeInfo = getTypeInfoFromTypeAlias(refNode, typeMap);
418
- }
419
- } else if (kind2 === SyntaxKind.TypeLiteral) {
420
- nextTypeInfo = getTypeInfo(t);
421
- }
422
- if (nextTypeInfo) {
423
- const {
424
- fields: existingFields = {},
425
- unionFieldSets: existingFieldSets = []
426
- } = typeInfo || {};
427
- const { fields: nextFields, unionFieldSets: nextUnionFieldSets = [] } = nextTypeInfo;
428
- if (isUnion && nextFields) {
429
- const newUnionFieldSet = Object.keys(nextFields);
430
- typeInfo = {
431
- ...typeInfo,
432
- unionFieldSets: [
433
- ...existingFieldSets,
434
- ...nextUnionFieldSets,
435
- newUnionFieldSet
436
- ]
437
- };
438
- }
439
- typeInfo = {
440
- ...typeInfo,
441
- fields: {
442
- ...existingFields,
443
- ...nextFields
444
- }
445
- };
446
- }
447
- }
448
- return typeInfo;
449
- };
450
-
451
- // src/common/TypeParsing/ParsingUtils/Constants.ts
452
- var FIELD_FILTERS = {
453
- OMIT: "Omit",
454
- PICK: "Pick",
455
- EXCLUDE: "Exclude"
456
- };
457
- var getUnionOrLiteralStringValues = (node) => {
458
- let values = [];
459
- if (node) {
460
- if (node.kind === SyntaxKind.LiteralType) {
461
- const { literal } = node;
462
- if (literal.kind === SyntaxKind.StringLiteral || literal.kind === SyntaxKind.NumericLiteral) {
463
- const { text } = literal;
464
- values = [text];
465
- }
466
- } else if (node.kind === SyntaxKind.UnionType) {
467
- const { types } = node;
468
- for (const type of types) {
469
- values = [...values, ...getUnionOrLiteralStringValues(type)];
470
- }
471
- }
472
- }
473
- return values;
474
- };
475
-
476
- // src/common/TypeParsing/ParsingUtils/getTypeInfoFromFieldFilter.ts
477
- var getTypeInfoFromPickOmitFieldFilters = (typeNameStr, typeRef, typeMap) => {
478
- const picking = typeNameStr === FIELD_FILTERS.PICK;
479
- const omitTypeKind = typeRef.typeArguments?.[0].kind;
480
- let typeInfo;
481
- if (omitTypeKind === SyntaxKind.TypeReference && typeRef.typeArguments && typeRef.typeArguments[0].kind === SyntaxKind.TypeReference) {
482
- const omitType = typeRef.typeArguments[0];
483
- const omitTypeFields = typeRef.typeArguments[1];
484
- const omitTypeName = omitType.typeName.getText();
485
- const refNode = typeMap[omitTypeName];
486
- if (refNode) {
487
- const {
488
- fields: existingFields = {},
489
- unionFieldSets: existingUnionFieldSets,
490
- ...typeInfoOther
491
- } = getTypeInfoFromTypeAlias(refNode, typeMap) || {};
492
- const omitFieldNames = getUnionOrLiteralStringValues(omitTypeFields);
493
- const cleanTypeInfoFields = Object.keys(
494
- existingFields
495
- ).reduce(
496
- (acc, key) => {
497
- if (acc && (picking && omitFieldNames.includes(key) || !picking && !omitFieldNames.includes(key)) && existingFields[key]) {
498
- acc[key] = existingFields[key];
499
- }
500
- return acc;
501
- },
502
- {}
503
- );
504
- const cleanUnionFieldSets = existingUnionFieldSets ? existingUnionFieldSets.map(
505
- (fieldSet) => fieldSet.filter(
506
- (field) => picking ? omitFieldNames.includes(field) : !omitFieldNames.includes(field)
507
- )
508
- ) : void 0;
509
- typeInfo = {
510
- ...typeInfoOther,
511
- fields: cleanTypeInfoFields,
512
- unionFieldSets: cleanUnionFieldSets
513
- };
514
- }
515
- }
516
- return typeInfo;
517
- };
518
- var getTypeInfoFromExcludeFieldFilter = (typeNameStr, typeRef, typeMap) => {
519
- const baseTypeKind = typeRef.typeArguments?.[0].kind;
520
- const excludeTypeKind = typeRef.typeArguments?.[1].kind;
521
- let typeInfo;
522
- if (baseTypeKind === SyntaxKind.TypeReference && excludeTypeKind === SyntaxKind.TypeReference && typeRef.typeArguments) {
523
- const baseType = typeRef.typeArguments[0];
524
- const excludeType = typeRef.typeArguments[1];
525
- const baseTypeName = baseType.typeName.getText();
526
- const excludeTypeName = excludeType.typeName.getText();
527
- const refNode = typeMap[baseTypeName];
528
- const excludeNode = typeMap[excludeTypeName];
529
- if (refNode && excludeNode) {
530
- const baseTypeInfo = getTypeInfoFromTypeAlias(refNode, typeMap);
531
- const excludeTypeInfo = getTypeInfoFromTypeAlias(excludeNode, typeMap);
532
- if (baseTypeInfo && excludeTypeInfo) {
533
- const {
534
- fields: baseFields = {},
535
- unionFieldSets: existingUnionFieldSets
536
- } = baseTypeInfo;
537
- const { fields: excludeFields = {} } = excludeTypeInfo;
538
- const excludeFieldNames = Object.keys(excludeFields);
539
- const cleanTypeInfoFields = Object.keys(
540
- baseFields
541
- ).reduce(
542
- (acc, key) => {
543
- if (acc && !excludeFieldNames.includes(key) && baseFields[key]) {
544
- acc[key] = baseFields[key];
545
- }
546
- return acc;
547
- },
548
- {}
549
- );
550
- const cleanUnionFieldSets = existingUnionFieldSets ? existingUnionFieldSets.map(
551
- (fieldSet) => fieldSet.filter((field) => !excludeFieldNames.includes(field))
552
- ) : void 0;
553
- typeInfo = {
554
- ...baseTypeInfo,
555
- fields: cleanTypeInfoFields,
556
- unionFieldSets: cleanUnionFieldSets
557
- };
558
- }
559
- }
560
- }
561
- return typeInfo;
562
- };
563
- var defaultFieldFilterProcessor = (typeNameStr, typeRef, typeMap) => {
564
- const refNode = typeNameStr ? typeMap[typeNameStr] : void 0;
565
- let typeInfo;
566
- if (refNode) {
567
- typeInfo = getTypeInfoFromTypeAlias(refNode, typeMap);
568
- }
569
- return typeInfo;
570
- };
571
- var FIELD_FILTER_PROCESSORS = {
572
- [FIELD_FILTERS.PICK]: getTypeInfoFromPickOmitFieldFilters,
573
- [FIELD_FILTERS.OMIT]: getTypeInfoFromPickOmitFieldFilters,
574
- [FIELD_FILTERS.EXCLUDE]: getTypeInfoFromExcludeFieldFilter
575
- };
576
- var getTypeInfoFromFieldFilter = (typeNameStr, typeRef, typeMap) => {
577
- const processor = typeNameStr ? FIELD_FILTER_PROCESSORS[typeNameStr] : void 0;
578
- return processor ? processor(typeNameStr, typeRef, typeMap) : defaultFieldFilterProcessor(typeNameStr, typeRef, typeMap);
579
- };
580
-
581
- // src/common/TypeParsing/ParsingUtils/getTypeInfoFromAliasType.ts
582
- var getTypeInfoFromTypeLiteral = (type) => getTypeInfo(type);
583
- var getTypeInfoFromUnionOrIntersectionType = (type, typeMap) => getUnionOrIntersectionTypeInfo(type, typeMap);
584
- var getTypeInfoFromTypeReference = (type, typeMap) => {
585
- const typeRef = type;
586
- const { typeName } = typeRef;
587
- const typeNameStr = typeName.getText();
588
- return getTypeInfoFromFieldFilter(typeNameStr, typeRef, typeMap);
589
- };
590
- var ALIAS_TYPE_PROCESSORS = {
591
- [SyntaxKind.TypeLiteral]: getTypeInfoFromTypeLiteral,
592
- [SyntaxKind.UnionType]: getTypeInfoFromUnionOrIntersectionType,
593
- [SyntaxKind.IntersectionType]: getTypeInfoFromUnionOrIntersectionType,
594
- [SyntaxKind.TypeReference]: getTypeInfoFromTypeReference
595
- };
596
- var getTypeInfoFromAliasType = (type, typeMap) => {
597
- const { kind } = type;
598
- const processor = ALIAS_TYPE_PROCESSORS[kind];
599
- const typeInfo = processor ? processor(type, typeMap) : void 0;
600
- return typeInfo;
601
- };
602
-
603
- // src/common/TypeParsing/ParsingUtils/getTypeInfoFromTypeAlias.ts
604
- var getTypeInfoFromTypeAlias = (typeAliasDec, typeMap) => {
605
- const { type } = typeAliasDec;
606
- const tags = extractCommentTags(typeAliasDec);
607
- const typeInfo = getTypeInfoFromAliasType(type, typeMap);
608
- return typeInfo ? {
609
- ...typeInfo,
610
- tags: {
611
- ...tags,
612
- ...typeInfo.tags
613
- }
614
- } : void 0;
615
- };
616
-
617
- // src/common/TypeParsing/ParsingUtils/getPrimaryFieldForTypeInfo.ts
618
- var getPrimaryFieldForTypeInfo = (typeInfo) => {
619
- const { fields } = typeInfo;
620
- let primaryField = void 0, primaryFieldReadDenied = false;
621
- for (const fieldName in fields) {
622
- const field = fields[fieldName];
623
- const {
624
- tags: {
625
- primaryField: isPrimaryField = false,
626
- deniedOperations: { READ: readDenied = false } = {}
627
- } = {}
628
- } = field;
629
- if (isPrimaryField || !primaryField) {
630
- primaryField = fieldName;
631
- primaryFieldReadDenied = readDenied;
632
- }
633
- if (isPrimaryField) {
634
- break;
635
- }
636
- }
637
- if (primaryFieldReadDenied) {
638
- throw new Error(
639
- "READ_DENIED_PRIMARY_FIELD_NOT_SUPPORTED" /* READ_DENIED_PRIMARY_FIELD_NOT_SUPPORTED */
640
- );
641
- }
642
- return primaryField;
643
- };
644
-
645
- // src/common/TypeParsing/TypeParsing.ts
646
- var getTypeInfoMapFromTypeScript = (source) => {
647
- const typeScriptNode = createSourceFile(
648
- "x.ts",
649
- source,
650
- ScriptTarget.Latest,
651
- true
652
- );
653
- const typeMap = convertASTToMap(typeScriptNode, {});
654
- const typeInfoMap = {};
655
- for (const key in typeMap) {
656
- const typeAliasDec = typeMap[key];
657
- const { modifiers } = typeAliasDec;
658
- let outputTypeInfo = false;
659
- if (modifiers) {
660
- modifiers.forEach((modifier) => {
661
- const { kind } = modifier;
662
- if (kind === SyntaxKind.ExportKeyword) {
663
- outputTypeInfo = true;
664
- }
665
- });
666
- }
667
- if (outputTypeInfo) {
668
- const typeInfo = getTypeInfoFromTypeAlias(typeAliasDec, typeMap);
669
- if (typeInfo) {
670
- typeInfoMap[key] = {
671
- ...typeInfo,
672
- primaryField: getPrimaryFieldForTypeInfo(typeInfo)
673
- };
674
- }
675
- }
676
- }
677
- return typeInfoMap;
678
- };
679
-
680
- // src/common/TypeParsing/Validation.ts
681
- var Validation_exports = {};
682
- __export(Validation_exports, {
683
- DENIED_TYPE_OPERATIONS: () => DENIED_TYPE_OPERATIONS,
684
- ERROR_MESSAGE_CONSTANTS: () => ERROR_MESSAGE_CONSTANTS,
685
- INVALID_CUSTOM_TYPE: () => INVALID_CUSTOM_TYPE,
686
- PRIMITIVE_ERROR_MESSAGE_CONSTANTS: () => PRIMITIVE_ERROR_MESSAGE_CONSTANTS,
687
- RelationshipValidationType: () => RelationshipValidationType,
688
- TYPE_KEYWORD_VALIDATORS: () => TYPE_KEYWORD_VALIDATORS,
689
- getValidityValue: () => getValidityValue,
690
- hasValue: () => hasValue,
691
- validateArrayOfTypeInfoFieldValues: () => validateArrayOfTypeInfoFieldValues,
692
- validateCustomType: () => validateCustomType,
693
- validateKeywordType: () => validateKeywordType,
694
- validateTypeInfoFieldOperationAllowed: () => validateTypeInfoFieldOperationAllowed,
695
- validateTypeInfoFieldValue: () => validateTypeInfoFieldValue,
696
- validateTypeInfoValue: () => validateTypeInfoValue,
697
- validateTypeOperationAllowed: () => validateTypeOperationAllowed,
698
- validateValueMatchesPattern: () => validateValueMatchesPattern
699
- });
700
-
701
- // src/common/TypeParsing/TypeInfo.ts
702
- var TypeInfo_exports = {};
703
- __export(TypeInfo_exports, {
704
- TypeOperation: () => TypeOperation
705
- });
706
- var TypeOperation = /* @__PURE__ */ ((TypeOperation2) => {
707
- TypeOperation2["CREATE"] = "CREATE";
708
- TypeOperation2["READ"] = "READ";
709
- TypeOperation2["UPDATE"] = "UPDATE";
710
- TypeOperation2["DELETE"] = "DELETE";
711
- return TypeOperation2;
712
- })(TypeOperation || {});
713
-
714
142
  // src/common/TypeParsing/Validation.ts
715
143
  var RelationshipValidationType = /* @__PURE__ */ ((RelationshipValidationType2) => {
716
144
  RelationshipValidationType2["INCLUDE"] = "INCLUDE";
@@ -1056,6 +484,36 @@ var validateTypeInfoValue = (value, typeInfoFullName, typeInfoMap, strict = fals
1056
484
  return results;
1057
485
  };
1058
486
 
487
+ // src/common/TypeParsing/TypeMapping.ts
488
+ var TypeMapping_exports = {};
489
+ __export(TypeMapping_exports, {
490
+ convertASTToMap: () => convertASTToMap
491
+ });
492
+ var convertASTToMap = (node, map = {}, parentName) => {
493
+ node.forEachChild((child) => {
494
+ const { kind: childKind } = child;
495
+ if (childKind === SyntaxKind.ModuleDeclaration) {
496
+ const moduleNode = child;
497
+ const { name: moduleName } = moduleNode;
498
+ const textModuleName = moduleName.getText();
499
+ const fullModuleName = parentName ? `${parentName}.${textModuleName}` : textModuleName;
500
+ convertASTToMap(moduleNode, map, fullModuleName);
501
+ }
502
+ if (childKind === SyntaxKind.ModuleBlock) {
503
+ convertASTToMap(child, map, parentName);
504
+ }
505
+ if (childKind === SyntaxKind.TypeAliasDeclaration) {
506
+ const typeAliasDec = child;
507
+ const {
508
+ name: { text: typeName }
509
+ } = typeAliasDec;
510
+ const fullTypeName = parentName ? `${parentName}.${typeName}` : typeName;
511
+ map[fullTypeName] = typeAliasDec;
512
+ }
513
+ });
514
+ return map;
515
+ };
516
+
1059
517
  // src/common/TypeParsing/Constants.ts
1060
518
  var Constants_exports = {};
1061
519
  __export(Constants_exports, {