@rxap/ts-morph 1.1.0-dev.0 → 1.1.0-dev.1

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 (47) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/package.json +2 -2
  3. package/src/index.d.ts +10 -0
  4. package/src/index.js +10 -0
  5. package/src/index.js.map +1 -1
  6. package/src/lib/angular/coerce-component-import.d.ts +11 -0
  7. package/src/lib/angular/coerce-component-import.js +30 -0
  8. package/src/lib/angular/coerce-component-import.js.map +1 -0
  9. package/src/lib/angular/coerce-component-input.d.ts +18 -0
  10. package/src/lib/angular/coerce-component-input.js +67 -0
  11. package/src/lib/angular/coerce-component-input.js.map +1 -0
  12. package/src/lib/angular/coerce-component.d.ts +2 -2
  13. package/src/lib/angular/coerce-component.js +33 -20
  14. package/src/lib/angular/coerce-component.js.map +1 -1
  15. package/src/lib/angular/get-component-class.d.ts +2 -0
  16. package/src/lib/angular/get-component-class.js +12 -0
  17. package/src/lib/angular/get-component-class.js.map +1 -0
  18. package/src/lib/angular/get-component-decorator-object.d.ts +2 -0
  19. package/src/lib/angular/get-component-decorator-object.js +19 -0
  20. package/src/lib/angular/get-component-decorator-object.js.map +1 -0
  21. package/src/lib/coerce-accessor-declaration.d.ts +19 -0
  22. package/src/lib/coerce-accessor-declaration.js +38 -0
  23. package/src/lib/coerce-accessor-declaration.js.map +1 -0
  24. package/src/lib/coerce-array-element.d.ts +2 -1
  25. package/src/lib/coerce-array-element.js +14 -2
  26. package/src/lib/coerce-array-element.js.map +1 -1
  27. package/src/lib/coerce-class-property.d.ts +3 -0
  28. package/src/lib/coerce-class-property.js +3 -0
  29. package/src/lib/coerce-class-property.js.map +1 -1
  30. package/src/lib/coerce-default-class-export.d.ts +2 -0
  31. package/src/lib/coerce-default-class-export.js +27 -0
  32. package/src/lib/coerce-default-class-export.js.map +1 -0
  33. package/src/lib/coerce-property-declaration.d.ts +3 -0
  34. package/src/lib/coerce-property-declaration.js +13 -0
  35. package/src/lib/coerce-property-declaration.js.map +1 -0
  36. package/src/lib/data-property.d.ts +15 -0
  37. package/src/lib/data-property.js +63 -0
  38. package/src/lib/data-property.js.map +1 -0
  39. package/src/lib/has-constructor-parameter.d.ts +10 -0
  40. package/src/lib/has-constructor-parameter.js +17 -0
  41. package/src/lib/has-constructor-parameter.js.map +1 -0
  42. package/src/lib/type-import.d.ts +10 -0
  43. package/src/lib/type-import.js +42 -1
  44. package/src/lib/type-import.js.map +1 -1
  45. package/src/lib/write-type.d.ts +18 -0
  46. package/src/lib/write-type.js +74 -0
  47. package/src/lib/write-type.js.map +1 -0
package/CHANGELOG.md CHANGED
@@ -3,6 +3,29 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.1.0-dev.1](https://gitlab.com/rxap/packages/compare/@rxap/ts-morph@1.1.0-dev.0...@rxap/ts-morph@1.1.0-dev.1) (2024-02-22)
7
+
8
+ ### Bug Fixes
9
+
10
+ - change property order ([8266705](https://gitlab.com/rxap/packages/commit/8266705b791f8d3ca65c8b804b449cf47b2751b7))
11
+ - check if type import is required ([8dcd733](https://gitlab.com/rxap/packages/commit/8dcd733deab33097ef89f1ff8625864b5ead0235))
12
+ - initial component class creation ([070552a](https://gitlab.com/rxap/packages/commit/070552a35cd3a8a01e0c27f2d5316c9083ad72b3))
13
+ - simplify function use ([8ad2237](https://gitlab.com/rxap/packages/commit/8ad2237aff141651d7cfe09e09ae6ec88780d186))
14
+ - simplify function use ([3d1c202](https://gitlab.com/rxap/packages/commit/3d1c20272faf7bc7ae473a438a7d2393590f0a02))
15
+ - small issues ([93f69c5](https://gitlab.com/rxap/packages/commit/93f69c5e2f445994db265360c6dd4a1e8228bfdb))
16
+ - support type guessing ([90a8624](https://gitlab.com/rxap/packages/commit/90a8624fb704a98d2cfbf9cc13f77a598b52d50c))
17
+ - type import and data property to ts morph library ([91f9abc](https://gitlab.com/rxap/packages/commit/91f9abc3f43f82419b9b8d9b056af5d2e88e3a2c))
18
+ - unify coerce component functions ([3bc1701](https://gitlab.com/rxap/packages/commit/3bc170116d7e794b94ef323251c59579a7887355))
19
+ - unify type import concept ([9cb2f7b](https://gitlab.com/rxap/packages/commit/9cb2f7b07e28eb36849b1f3afdba15989ba17c72))
20
+
21
+ ### Features
22
+
23
+ - add CoerceDefaultClassExport function ([a3c89f7](https://gitlab.com/rxap/packages/commit/a3c89f7a7079bcde09980e632fe8edb25fef1ce7))
24
+ - add default find existing element function ([ee18576](https://gitlab.com/rxap/packages/commit/ee18576b1cfd2af4d67ae4b4022d794760115165))
25
+ - add new utility functions ([fbb52c6](https://gitlab.com/rxap/packages/commit/fbb52c60844a0113677094ae5fa6620be2df73b8))
26
+ - add new utility functions ([026e266](https://gitlab.com/rxap/packages/commit/026e266821485602e84030a9e68cd0352c6c0a1e))
27
+ - move WriteType to ts-morph package ([af6357a](https://gitlab.com/rxap/packages/commit/af6357a2f642199dc7807e21e5e369395872d595))
28
+
6
29
  # [1.1.0-dev.0](https://gitlab.com/rxap/packages/compare/@rxap/ts-morph@1.0.1...@rxap/ts-morph@1.1.0-dev.0) (2024-02-09)
7
30
 
8
31
  ### Features
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.0-dev.0",
2
+ "version": "1.1.0-dev.1",
3
3
  "name": "@rxap/ts-morph",
4
4
  "license": "GPL-3.0-or-later",
5
5
  "dependencies": {
@@ -42,7 +42,7 @@
42
42
  "directory": "packages/ts-morph"
43
43
  },
44
44
  "type": "commonjs",
45
- "gitHead": "c72606219a2dc28185f6e21617ec127d7c82715c",
45
+ "gitHead": "f7c69031c4849d91b4a852bf9e5c31cabf3f98c9",
46
46
  "main": "./src/index.js",
47
47
  "types": "./src/index.d.ts"
48
48
  }
package/src/index.d.ts CHANGED
@@ -28,25 +28,35 @@ export * from './lib/nest/operation-id-utilities';
28
28
  export * from './lib/nest/remove-nest-module-provider';
29
29
  export * from './lib/nest/remove-nest-provider-to-array';
30
30
  export * from './lib/angular/coerce-app-config-provider';
31
+ export * from './lib/angular/coerce-component-import';
32
+ export * from './lib/angular/coerce-component-input';
31
33
  export * from './lib/angular/coerce-component';
34
+ export * from './lib/angular/get-component-class';
35
+ export * from './lib/angular/get-component-decorator-object';
32
36
  export * from './lib/add-provider-to-array';
37
+ export * from './lib/coerce-accessor-declaration';
33
38
  export * from './lib/coerce-array-element';
34
39
  export * from './lib/coerce-class-constructor';
35
40
  export * from './lib/coerce-class-method';
36
41
  export * from './lib/coerce-class-property';
37
42
  export * from './lib/coerce-class';
38
43
  export * from './lib/coerce-decorator';
44
+ export * from './lib/coerce-default-class-export';
39
45
  export * from './lib/coerce-dependency-injection';
40
46
  export * from './lib/coerce-imports';
41
47
  export * from './lib/coerce-mapping-class-method';
48
+ export * from './lib/coerce-property-declaration';
42
49
  export * from './lib/coerce-source-file';
43
50
  export * from './lib/coerce-statements';
44
51
  export * from './lib/coerce-variable-declaration';
45
52
  export * from './lib/create-project';
53
+ export * from './lib/data-property';
46
54
  export * from './lib/find-function';
47
55
  export * from './lib/get-class-decorator-arguments';
48
56
  export * from './lib/get-class';
49
57
  export * from './lib/get-coerce-array-literal-form-object-literal';
58
+ export * from './lib/has-constructor-parameter';
50
59
  export * from './lib/provider-object';
51
60
  export * from './lib/to-mapping-object';
52
61
  export * from './lib/type-import';
62
+ export * from './lib/write-type';
package/src/index.js CHANGED
@@ -34,29 +34,39 @@ tslib_1.__exportStar(require("./lib/nest/remove-nest-provider-to-array"), export
34
34
  // endregion
35
35
  // region angular
36
36
  tslib_1.__exportStar(require("./lib/angular/coerce-app-config-provider"), exports);
37
+ tslib_1.__exportStar(require("./lib/angular/coerce-component-import"), exports);
38
+ tslib_1.__exportStar(require("./lib/angular/coerce-component-input"), exports);
37
39
  tslib_1.__exportStar(require("./lib/angular/coerce-component"), exports);
40
+ tslib_1.__exportStar(require("./lib/angular/get-component-class"), exports);
41
+ tslib_1.__exportStar(require("./lib/angular/get-component-decorator-object"), exports);
38
42
  // endregion
39
43
  // region
40
44
  tslib_1.__exportStar(require("./lib/add-provider-to-array"), exports);
45
+ tslib_1.__exportStar(require("./lib/coerce-accessor-declaration"), exports);
41
46
  tslib_1.__exportStar(require("./lib/coerce-array-element"), exports);
42
47
  tslib_1.__exportStar(require("./lib/coerce-class-constructor"), exports);
43
48
  tslib_1.__exportStar(require("./lib/coerce-class-method"), exports);
44
49
  tslib_1.__exportStar(require("./lib/coerce-class-property"), exports);
45
50
  tslib_1.__exportStar(require("./lib/coerce-class"), exports);
46
51
  tslib_1.__exportStar(require("./lib/coerce-decorator"), exports);
52
+ tslib_1.__exportStar(require("./lib/coerce-default-class-export"), exports);
47
53
  tslib_1.__exportStar(require("./lib/coerce-dependency-injection"), exports);
48
54
  tslib_1.__exportStar(require("./lib/coerce-imports"), exports);
49
55
  tslib_1.__exportStar(require("./lib/coerce-mapping-class-method"), exports);
56
+ tslib_1.__exportStar(require("./lib/coerce-property-declaration"), exports);
50
57
  tslib_1.__exportStar(require("./lib/coerce-source-file"), exports);
51
58
  tslib_1.__exportStar(require("./lib/coerce-statements"), exports);
52
59
  tslib_1.__exportStar(require("./lib/coerce-variable-declaration"), exports);
53
60
  tslib_1.__exportStar(require("./lib/create-project"), exports);
61
+ tslib_1.__exportStar(require("./lib/data-property"), exports);
54
62
  tslib_1.__exportStar(require("./lib/find-function"), exports);
55
63
  tslib_1.__exportStar(require("./lib/get-class-decorator-arguments"), exports);
56
64
  tslib_1.__exportStar(require("./lib/get-class"), exports);
57
65
  tslib_1.__exportStar(require("./lib/get-coerce-array-literal-form-object-literal"), exports);
66
+ tslib_1.__exportStar(require("./lib/has-constructor-parameter"), exports);
58
67
  tslib_1.__exportStar(require("./lib/provider-object"), exports);
59
68
  tslib_1.__exportStar(require("./lib/to-mapping-object"), exports);
60
69
  tslib_1.__exportStar(require("./lib/type-import"), exports);
70
+ tslib_1.__exportStar(require("./lib/write-type"), exports);
61
71
  // endregion
62
72
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/ts-morph/src/index.ts"],"names":[],"mappings":";;;AAAA,cAAc;AACd,yEAA+C;AAC/C,0EAAgD;AAChD,mFAAyD;AACzD,+EAAqD;AACrD,8EAAoD;AACpD,0EAAgD;AAChD,4EAAkD;AAClD,gFAAsD;AACtD,4EAAkD;AAClD,sFAA4D;AAC5D,4EAAkD;AAClD,sFAA4D;AAC5D,iFAAuD;AACvD,mFAAyD;AACzD,+EAAqD;AACrD,iFAAuD;AACvD,wEAA8C;AAC9C,2EAAiD;AACjD,mFAAyD;AACzD,yFAA+D;AAC/D,kFAAwD;AACxD,0EAAgD;AAChD,8EAAoD;AACpD,2EAAiD;AACjD,0EAAgD;AAChD,0EAAgD;AAChD,4EAAkD;AAClD,iFAAuD;AACvD,mFAAyD;AACzD,YAAY;AAEZ,iBAAiB;AACjB,mFAAyD;AACzD,yEAA+C;AAC/C,YAAY;AAEZ,UAAU;AACV,sEAA4C;AAC5C,qEAA2C;AAC3C,yEAA+C;AAC/C,oEAA0C;AAC1C,sEAA4C;AAC5C,6DAAmC;AACnC,iEAAuC;AACvC,4EAAkD;AAClD,+DAAqC;AACrC,4EAAkD;AAClD,mEAAyC;AACzC,kEAAwC;AACxC,4EAAkD;AAClD,+DAAqC;AACrC,8DAAoC;AACpC,8EAAoD;AACpD,0DAAgC;AAChC,6FAAmE;AACnE,gEAAsC;AACtC,kEAAwC;AACxC,4DAAkC;AAClC,YAAY"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/ts-morph/src/index.ts"],"names":[],"mappings":";;;AAAA,cAAc;AACd,yEAA+C;AAC/C,0EAAgD;AAChD,mFAAyD;AACzD,+EAAqD;AACrD,8EAAoD;AACpD,0EAAgD;AAChD,4EAAkD;AAClD,gFAAsD;AACtD,4EAAkD;AAClD,sFAA4D;AAC5D,4EAAkD;AAClD,sFAA4D;AAC5D,iFAAuD;AACvD,mFAAyD;AACzD,+EAAqD;AACrD,iFAAuD;AACvD,wEAA8C;AAC9C,2EAAiD;AACjD,mFAAyD;AACzD,yFAA+D;AAC/D,kFAAwD;AACxD,0EAAgD;AAChD,8EAAoD;AACpD,2EAAiD;AACjD,0EAAgD;AAChD,0EAAgD;AAChD,4EAAkD;AAClD,iFAAuD;AACvD,mFAAyD;AACzD,YAAY;AAEZ,iBAAiB;AACjB,mFAAyD;AACzD,gFAAsD;AACtD,+EAAqD;AACrD,yEAA+C;AAC/C,4EAAkD;AAClD,uFAA6D;AAC7D,YAAY;AAEZ,UAAU;AACV,sEAA4C;AAC5C,4EAAkD;AAClD,qEAA2C;AAC3C,yEAA+C;AAC/C,oEAA0C;AAC1C,sEAA4C;AAC5C,6DAAmC;AACnC,iEAAuC;AACvC,4EAAkD;AAClD,4EAAkD;AAClD,+DAAqC;AACrC,4EAAkD;AAClD,4EAAkD;AAClD,mEAAyC;AACzC,kEAAwC;AACxC,4EAAkD;AAClD,+DAAqC;AACrC,8DAAoC;AACpC,8DAAoC;AACpC,8EAAoD;AACpD,0DAAgC;AAChC,6FAAmE;AACnE,0EAAgD;AAChD,gEAAsC;AACtC,kEAAwC;AACxC,4DAAkC;AAClC,2DAAiC;AACjC,YAAY"}
@@ -0,0 +1,11 @@
1
+ import { TypeImport } from '@rxap/ts-morph';
2
+ import { ClassDeclaration, SourceFile } from 'ts-morph';
3
+ /**
4
+ * Coerces the component import by adding it to the imports array of the component decorator object.
5
+ * If a module specifier is provided, the import is also coerced at the file level.
6
+ *
7
+ * @param sourceFileOrClassDeclaration - The source file or class declaration that contains the component import.
8
+ * @param componentImport - The name or TypeImport of the import to coerce.
9
+ * @returns - The updated imports array after coercing the import.
10
+ */
11
+ export declare function CoerceComponentImport(sourceFileOrClassDeclaration: SourceFile | ClassDeclaration, componentImport: string | TypeImport): import("ts-morph").ArrayLiteralExpression;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CoerceComponentImport = void 0;
4
+ const ts_morph_1 = require("@rxap/ts-morph");
5
+ const coerce_imports_1 = require("../coerce-imports");
6
+ const ts_morph_2 = require("ts-morph");
7
+ const get_coerce_array_literal_form_object_literal_1 = require("../get-coerce-array-literal-form-object-literal");
8
+ const get_component_decorator_object_1 = require("./get-component-decorator-object");
9
+ /**
10
+ * Coerces the component import by adding it to the imports array of the component decorator object.
11
+ * If a module specifier is provided, the import is also coerced at the file level.
12
+ *
13
+ * @param sourceFileOrClassDeclaration - The source file or class declaration that contains the component import.
14
+ * @param componentImport - The name or TypeImport of the import to coerce.
15
+ * @returns - The updated imports array after coercing the import.
16
+ */
17
+ function CoerceComponentImport(sourceFileOrClassDeclaration, componentImport) {
18
+ const classDeclaration = sourceFileOrClassDeclaration instanceof ts_morph_2.ClassDeclaration ? sourceFileOrClassDeclaration : (0, ts_morph_1.GetComponentClass)(sourceFileOrClassDeclaration);
19
+ const sourceFile = sourceFileOrClassDeclaration instanceof ts_morph_2.SourceFile ? sourceFileOrClassDeclaration : sourceFileOrClassDeclaration.getSourceFile();
20
+ const importName = typeof componentImport === 'string' ? componentImport : componentImport.name;
21
+ if ((0, ts_morph_1.IsTypeImport)(componentImport)) {
22
+ (0, coerce_imports_1.CoerceImports)(sourceFile, (0, ts_morph_1.TypeImportToImportStructure)(componentImport));
23
+ }
24
+ const componentDecoratorObject = (0, get_component_decorator_object_1.GetComponentDecoratorObject)(classDeclaration);
25
+ const importsArray = (0, get_coerce_array_literal_form_object_literal_1.GetCoerceArrayLiteralFromObjectLiteral)(componentDecoratorObject, 'imports');
26
+ (0, ts_morph_1.CoerceArrayElement)(importsArray, importName);
27
+ return importsArray;
28
+ }
29
+ exports.CoerceComponentImport = CoerceComponentImport;
30
+ //# sourceMappingURL=coerce-component-import.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coerce-component-import.js","sourceRoot":"","sources":["../../../../../../packages/ts-morph/src/lib/angular/coerce-component-import.ts"],"names":[],"mappings":";;;AAAA,6CAMwB;AACxB,sDAAkD;AAClD,uCAGkB;AAClB,kHAAyG;AACzG,qFAA+E;AAE/E;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CACnC,4BAA2D,EAC3D,eAAoC;IAGpC,MAAM,gBAAgB,GAAG,4BAA4B,YAAY,2BAAgB,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,IAAA,4BAAiB,EAAC,4BAA4B,CAAC,CAAC;IACnK,MAAM,UAAU,GAAG,4BAA4B,YAAY,qBAAU,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,4BAA4B,CAAC,aAAa,EAAE,CAAC;IAEpJ,MAAM,UAAU,GAAG,OAAO,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC;IAEhG,IAAI,IAAA,uBAAY,EAAC,eAAe,CAAC,EAAE;QACjC,IAAA,8BAAa,EAAC,UAAU,EAAE,IAAA,sCAA2B,EAAC,eAAe,CAAC,CAAC,CAAC;KACzE;IAED,MAAM,wBAAwB,GAAG,IAAA,4DAA2B,EAAC,gBAAgB,CAAC,CAAC;IAE/E,MAAM,YAAY,GAAG,IAAA,qFAAsC,EAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;IAEjG,IAAA,6BAAkB,EAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IAE7C,OAAO,YAAY,CAAC;AAEtB,CAAC;AAtBD,sDAsBC"}
@@ -0,0 +1,18 @@
1
+ import { ClassDeclaration, DecoratableNode, PropertyDeclaration, PropertyNamedNode, SetAccessorDeclaration, SourceFile, WriterFunction } from 'ts-morph';
2
+ import { TypeImport } from '../type-import';
3
+ export interface ComponentInputDefinition {
4
+ alias?: string;
5
+ isRequired?: boolean;
6
+ initializer?: string | WriterFunction;
7
+ asSetAccessor?: boolean;
8
+ }
9
+ export interface SetComponentInputDefinition extends ComponentInputDefinition {
10
+ asSetAccessor: true;
11
+ }
12
+ export type PropertyComponentInputDefinition = Omit<ComponentInputDefinition, 'asSetAccessor'>;
13
+ export declare function CoerceComponentInput(classDeclaration: ClassDeclaration, name: string, type: string | TypeImport | WriterFunction, options?: PropertyComponentInputDefinition): PropertyDeclaration;
14
+ export declare function CoerceComponentInput(sourceFile: SourceFile, name: string, type: string | TypeImport | WriterFunction, options?: PropertyComponentInputDefinition): PropertyDeclaration;
15
+ export declare function CoerceComponentInput(classDeclaration: ClassDeclaration, name: string, type: string | TypeImport | WriterFunction, options?: SetComponentInputDefinition): SetAccessorDeclaration;
16
+ export declare function CoerceComponentInput(sourceFile: SourceFile, name: string, type: string | TypeImport | WriterFunction, options?: SetComponentInputDefinition): SetAccessorDeclaration;
17
+ export declare function CoerceComponentInput(classDeclaration: ClassDeclaration, name: string, type: string | TypeImport | WriterFunction, options?: ComponentInputDefinition): PropertyNamedNode & DecoratableNode;
18
+ export declare function CoerceComponentInput(sourceFile: SourceFile, name: string, type: string | TypeImport | WriterFunction, options?: ComponentInputDefinition): PropertyNamedNode & DecoratableNode;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CoerceComponentInput = void 0;
4
+ const ts_morph_1 = require("@rxap/ts-morph");
5
+ const coerce_accessor_declaration_1 = require("../coerce-accessor-declaration");
6
+ const coerce_imports_1 = require("../coerce-imports");
7
+ const ts_morph_2 = require("ts-morph");
8
+ const coerce_property_declaration_1 = require("../coerce-property-declaration");
9
+ const has_constructor_parameter_1 = require("../has-constructor-parameter");
10
+ const get_component_class_1 = require("./get-component-class");
11
+ const write_type_1 = require("../write-type");
12
+ function CoerceComponentInput(sourceFileOrClassDeclaration, name, type, { initializer, alias, isRequired, asSetAccessor } = {}) {
13
+ const classDeclaration = sourceFileOrClassDeclaration instanceof ts_morph_2.ClassDeclaration ? sourceFileOrClassDeclaration : (0, get_component_class_1.GetComponentClass)(sourceFileOrClassDeclaration);
14
+ const sourceFile = sourceFileOrClassDeclaration instanceof ts_morph_2.SourceFile ? sourceFileOrClassDeclaration : sourceFileOrClassDeclaration.getSourceFile();
15
+ if ((0, has_constructor_parameter_1.HasConstructorParameter)(classDeclaration, name, true)) {
16
+ throw new Error(`The component '${classDeclaration.getName()}' already has a constructor parameter that is a class member with the name '${name}'. Cannot add an input with the same name!`);
17
+ }
18
+ (0, coerce_imports_1.CoerceImports)(sourceFile, {
19
+ namedImports: ['Input'],
20
+ moduleSpecifier: '@angular/core',
21
+ });
22
+ const inputDecoratorStructure = {
23
+ name: 'Input',
24
+ arguments: [],
25
+ };
26
+ if (alias || isRequired) {
27
+ const inputArgument = {};
28
+ if (alias) {
29
+ inputArgument['alias'] = w => w.quote(alias);
30
+ }
31
+ if (isRequired) {
32
+ inputArgument['required'] = 'true';
33
+ }
34
+ inputDecoratorStructure.arguments = [ts_morph_2.Writers.object(inputArgument)];
35
+ }
36
+ let propertyNode;
37
+ if (asSetAccessor) {
38
+ propertyNode = (0, coerce_accessor_declaration_1.CoerceSetAccessorDeclaration)(classDeclaration, name, { statements: `this._${name} = ${name};` }).set({
39
+ scope: ts_morph_2.Scope.Public,
40
+ parameters: [
41
+ {
42
+ name: name,
43
+ type: (0, write_type_1.WriteType)(type, sourceFile),
44
+ },
45
+ ],
46
+ });
47
+ (0, coerce_property_declaration_1.CoercePropertyDeclaration)(classDeclaration, '_' + name, { scope: ts_morph_2.Scope.Private }).set({
48
+ type: (0, write_type_1.WriteType)(type, sourceFile),
49
+ initializer: initializer,
50
+ hasQuestionToken: !initializer && !isRequired,
51
+ hasExclamationToken: !initializer && isRequired,
52
+ });
53
+ }
54
+ else {
55
+ propertyNode = (0, coerce_property_declaration_1.CoercePropertyDeclaration)(classDeclaration, name).set({
56
+ scope: ts_morph_2.Scope.Public,
57
+ type: (0, write_type_1.WriteType)(type, sourceFile),
58
+ initializer,
59
+ hasQuestionToken: !initializer && !isRequired,
60
+ hasExclamationToken: !initializer && isRequired,
61
+ });
62
+ }
63
+ (0, ts_morph_1.CoerceDecorator)(propertyNode, 'Input', inputDecoratorStructure);
64
+ return propertyNode;
65
+ }
66
+ exports.CoerceComponentInput = CoerceComponentInput;
67
+ //# sourceMappingURL=coerce-component-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coerce-component-input.js","sourceRoot":"","sources":["../../../../../../packages/ts-morph/src/lib/angular/coerce-component-input.ts"],"names":[],"mappings":";;;AAAA,6CAAiD;AACjD,gFAA8E;AAE9E,sDAE2B;AAC3B,uCAYkB;AAClB,gFAA2E;AAC3E,4EAAuE;AACvE,+DAA0D;AAE1D,8CAA0C;AAoD1C,SAAgB,oBAAoB,CAClC,4BAA2D,EAC3D,IAAY,EACZ,IAA0C,EAC1C,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,aAAa,KAA+B,EAAE;IAGhF,MAAM,gBAAgB,GAAG,4BAA4B,YAAY,2BAAgB,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,IAAA,uCAAiB,EAAC,4BAA4B,CAAC,CAAC;IACnK,MAAM,UAAU,GAAG,4BAA4B,YAAY,qBAAU,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,4BAA4B,CAAC,aAAa,EAAE,CAAC;IAEpJ,IAAI,IAAA,mDAAuB,EAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;QACzD,MAAM,IAAI,KAAK,CAAC,kBAAkB,gBAAgB,CAAC,OAAO,EAAG,+EAAgF,IAAK,4CAA4C,CAAC,CAAC;KACjM;IAED,IAAA,8BAAa,EAAC,UAAU,EAAE;QACxB,YAAY,EAAE,CAAE,OAAO,CAAE;QACzB,eAAe,EAAE,eAAe;KACjC,CAAC,CAAC;IAEH,MAAM,uBAAuB,GAAqC;QAChE,IAAI,EAAE,OAAO;QACb,SAAS,EAAE,EAAE;KACd,CAAC;IAEF,IAAI,KAAK,IAAI,UAAU,EAAE;QACvB,MAAM,aAA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ACX,gBAAgB,EAAE,CAAC,WAAW,IAAI,CAAC,UAAU;YAC7C,mBAAmB,EAAE,CAAC,WAAW,IAAI,UAAU;SAChD,CAAC,CAAC;KAEJ;IAED,IAAA,0BAAe,EAAC,YAAY,EAAE,OAAO,EAAE,uBAAuB,CAAC,CAAC;IAEhE,OAAO,YAAY,CAAC;AAEtB,CAAC;AAxED,oDAwEC"}
@@ -1,6 +1,7 @@
1
1
  import { ClassDeclarationStructure, ObjectLiteralExpression, OptionalKind, SourceFile } from 'ts-morph';
2
2
  export interface CoerceComponentOptions {
3
3
  selector?: string;
4
+ prefix?: string;
4
5
  template?: string;
5
6
  styles?: string;
6
7
  /**
@@ -11,10 +12,9 @@ export interface CoerceComponentOptions {
11
12
  * true - use the component name to generate a styleUrl
12
13
  */
13
14
  styleUrls?: string | string[] | true;
15
+ changeDetection?: 'OnPush' | 'Default';
14
16
  }
15
17
  export declare function CoerceComponent(sourceFile: SourceFile, name: string, options?: CoerceComponentOptions, classStructure?: Omit<OptionalKind<ClassDeclarationStructure>, 'name'>): {
16
18
  classDeclaration: import("ts-morph").ClassDeclaration;
17
19
  componentDecoratorObject: ObjectLiteralExpression;
18
- providersArray: import("ts-morph").ArrayLiteralExpression;
19
- importsArray: import("ts-morph").ArrayLiteralExpression;
20
20
  };
@@ -1,21 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CoerceComponent = void 0;
4
- const coerce_decorator_1 = require("../coerce-decorator");
5
4
  const utilities_1 = require("@rxap/utilities");
6
5
  const ts_morph_1 = require("ts-morph");
7
6
  const coerce_class_1 = require("../coerce-class");
8
- const get_coerce_array_literal_form_object_literal_1 = require("../get-coerce-array-literal-form-object-literal");
7
+ const coerce_decorator_1 = require("../coerce-decorator");
8
+ const coerce_imports_1 = require("../coerce-imports");
9
9
  function CoerceComponent(sourceFile, name, options = {}, classStructure = {}) {
10
10
  var _a;
11
- const className = (0, utilities_1.CoerceSuffix)((0, utilities_1.dasherize)(name), '-component');
11
+ const className = (0, utilities_1.classify)((0, utilities_1.CoerceSuffix)((0, utilities_1.dasherize)(name), '-component'));
12
+ const { prefix, changeDetection, } = options;
12
13
  let { selector, template, templateUrl, styles, styleUrls, } = options;
13
- selector !== null && selector !== void 0 ? selector : (selector = (0, utilities_1.dasherize)(name));
14
- if (templateUrl === true) {
14
+ selector !== null && selector !== void 0 ? selector : (selector = prefix ? `${prefix}-${(0, utilities_1.dasherize)(name)}` : (0, utilities_1.dasherize)(name));
15
+ if (templateUrl === true || !template) {
15
16
  template = undefined;
16
17
  templateUrl = `./${(0, utilities_1.dasherize)(name)}.component.html`;
17
18
  }
18
- if (styleUrls === true) {
19
+ if (styleUrls === true || !styles) {
19
20
  styles = undefined;
20
21
  styleUrls = [`./${(0, utilities_1.dasherize)(name)}.component.scss`];
21
22
  }
@@ -28,23 +29,37 @@ function CoerceComponent(sourceFile, name, options = {}, classStructure = {}) {
28
29
  if (Array.isArray(styleUrls)) {
29
30
  styleUrls = `['${styleUrls.join('\',\n\'')}']`;
30
31
  }
31
- if (!(styleUrls === null || styleUrls === void 0 ? void 0 : styleUrls.startsWith('['))) {
32
+ if (styleUrls && !(styleUrls === null || styleUrls === void 0 ? void 0 : styleUrls.startsWith('['))) {
32
33
  styleUrls = `[${styleUrls}]`;
33
34
  }
34
35
  (_a = classStructure.isExported) !== null && _a !== void 0 ? _a : (classStructure.isExported = true);
35
36
  const classDeclaration = (0, coerce_class_1.CoerceClass)(sourceFile, className, classStructure);
37
+ const componentOptions = {
38
+ standalone: 'true',
39
+ selector: w => w.quote(selector),
40
+ };
41
+ if (changeDetection) {
42
+ componentOptions['changeDetection'] = `ChangeDetectionStrategy.${changeDetection}`;
43
+ (0, coerce_imports_1.CoerceImports)(sourceFile, {
44
+ namedImports: ['Component', 'ChangeDetectionStrategy'],
45
+ moduleSpecifier: '@angular/core',
46
+ });
47
+ }
48
+ if (template) {
49
+ componentOptions['template'] = w => w.quote(template);
50
+ }
51
+ if (templateUrl) {
52
+ componentOptions['templateUrl'] = w => w.quote(templateUrl);
53
+ }
54
+ if (styles) {
55
+ componentOptions['styles'] = w => w.quote(styles);
56
+ }
57
+ if (styleUrls) {
58
+ componentOptions['styleUrls'] = styleUrls;
59
+ }
36
60
  const componentDecoratorDeclaration = (0, coerce_decorator_1.CoerceDecorator)(classDeclaration, 'Component', {
37
61
  arguments: [
38
- ts_morph_1.Writers.object({
39
- standalone: 'true',
40
- selector: w => w.quote(selector),
41
- template: template !== undefined ? w => w.quote(template) : undefined,
42
- templateUrl: templateUrl !== undefined ? w => w.quote(templateUrl) : undefined,
43
- styles: styles !== undefined ? w => w.quote(styles) : undefined,
44
- styleUrls: styleUrls !== undefined ? w => w.quote(styleUrls) : undefined,
45
- providers: '[]',
46
- imports: '[]',
47
- }),
62
+ ts_morph_1.Writers.object(componentOptions),
48
63
  ]
49
64
  });
50
65
  const componentDecoratorObject = componentDecoratorDeclaration.getArguments()[0];
@@ -54,9 +69,7 @@ function CoerceComponent(sourceFile, name, options = {}, classStructure = {}) {
54
69
  if (!(componentDecoratorObject instanceof ts_morph_1.ObjectLiteralExpression)) {
55
70
  throw new Error(`Component decorator object for component '${className}' is not an object literal expression`);
56
71
  }
57
- const providersArray = (0, get_coerce_array_literal_form_object_literal_1.GetCoerceArrayLiteralFromObjectLiteral)(componentDecoratorObject, 'providers');
58
- const importsArray = (0, get_coerce_array_literal_form_object_literal_1.GetCoerceArrayLiteralFromObjectLiteral)(componentDecoratorObject, 'providers');
59
- return { classDeclaration, componentDecoratorObject, providersArray, importsArray };
72
+ return { classDeclaration, componentDecoratorObject };
60
73
  }
61
74
  exports.CoerceComponent = CoerceComponent;
62
75
  //# sourceMappingURL=coerce-component.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"coerce-component.js","sourceRoot":"","sources":["../../../../../../packages/ts-morph/src/lib/angular/coerce-component.ts"],"names":[],"mappings":";;;AAAA,0DAE6B;AAC7B,+CAGyB;AACzB,uCAMkB;AAClB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AAM,IAAI,KAAK,CAAC,6CAA8C,SAAU,uCAAuC,CAAC,CAAC;KAClH;IACD,MAAM,cAAc,GAAG,IAAA,qFAAsC,EAAC,wBAAwB,EAAE,WAAW,CAAC,CAAC;IACrG,MAAM,YAAY,GAAG,IAAA,qFAAsC,EAAC,wBAAwB,EAAE,WAAW,CAAC,CAAC;IAEnG,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC;AACtF,CAAC;AAnED,0CAmEC"}
1
+ {"version":3,"file":"coerce-component.js","sourceRoot":"","sources":["../../../../../../packages/ts-morph/src/lib/angular/coerce-component.ts"],"names":[],"mappings":";;;AAAA,+CAIyB;AACzB,uCAOkB;AAClB,kDAA8C;AAC9C,0DAAsD;AACtD,sDAAkD;AAmBlD,SAAgB,eAAe,CAC7B,UAAsB,EACtB,IAAY,EACZ,UAAkC,EAAE,EACpC,iBAAwE,EAAE;;IAE1E,MAAM,SAAS,GAAG,IAAA,oBAAQ,EAAC,IAAA,wBAAY,EAAC,IAAA,qBAAS,EAAC,IAAI,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC;IACxE,MAAM,EACJ,MAAM,EACN,eAAe,GAChB,GAAG,OAAO,CAAC;IACZ,IAAI,EACF,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,MAAM,EACN,SAAS,GACV,GAAG,OAAO,CAAC;IAEZ,QAAQ,aAAR,QAAQ,cAAR,QAAQ,IAAR,QAAQ,GAAK,MAAM,CAAC,CAAC,CAAC,GAAI,MAAO,IAAK,IAAA,qBAAS,EAAC,IAAI,CAAE,EAAE,CAAC,CAAC,CAAC,IAAA,qBAAS,EAAC,IAAI,CAAC,EAAC;IAC3E,IAAI,WAAW,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE;QACrC,QAAQ,GAAG,SAAS,CAAC;QACrB,WAAW,GAAG,KAAM,IAAA,qBAAS,EAAC,IAAI,CAAE,iBAAiB,CAAC;KACvD;IACD,IAAI,SA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,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,QAAS,CAAC,CAAC;KACxD;IAED,IAAI,WAAW,EAAE;QACf,gBAAgB,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,WAAqB,CAAC,CAAC;KACvE;IAED,IAAI,MAAM,EAAE;QACV,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAO,CAAC,CAAC;KACpD;IAED,IAAI,SAAS,EAAE;QACb,gBAAgB,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC;KAC3C;IAED,MAAM,6BAA6B,GAAG,IAAA,kCAAe,EAAC,gBAAgB,EAAE,WAAW,EAAE;QACnF,SAAS,EAAE;YACT,kBAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC;SACjC;KACF,CAAC,CAAC;IAEH,MAAM,wBAAwB,GAAG,6BAA6B,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC;IACjF,IAAI,CAAC,wBAAwB,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,4DAA6D,SAAU,GAAG,CAAC,CAAC;KAC7F;IACD,IAAI,CAAC,CAAC,wBAAwB,YAAY,kCAAuB,CAAC,EAAE;QAClE,MAAM,IAAI,KAAK,CAAC,6CAA8C,SAAU,uCAAuC,CAAC,CAAC;KAClH;IAED,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,CAAC;AACxD,CAAC;AAzFD,0CAyFC"}
@@ -0,0 +1,2 @@
1
+ import { ClassDeclaration, SourceFile } from 'ts-morph';
2
+ export declare function GetComponentClass(sourceFile: SourceFile): ClassDeclaration;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetComponentClass = void 0;
4
+ function GetComponentClass(sourceFile) {
5
+ const classWithComponent = sourceFile.getClasses().find(cls => cls.getDecorator('Component'));
6
+ if (!classWithComponent) {
7
+ throw new Error('Could not find class with Component decorator!');
8
+ }
9
+ return classWithComponent;
10
+ }
11
+ exports.GetComponentClass = GetComponentClass;
12
+ //# sourceMappingURL=get-component-class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-component-class.js","sourceRoot":"","sources":["../../../../../../packages/ts-morph/src/lib/angular/get-component-class.ts"],"names":[],"mappings":";;;AAKA,SAAgB,iBAAiB,CAAC,UAAsB;IACtD,MAAM,kBAAkB,GAAG,UAAU,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC;IAE9F,IAAI,CAAC,kBAAkB,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;KACnE;IAED,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AARD,8CAQC"}
@@ -0,0 +1,2 @@
1
+ import { ClassDeclaration, ObjectLiteralExpression, SourceFile } from 'ts-morph';
2
+ export declare function GetComponentDecoratorObject(sourceFileOrClassDeclaration: SourceFile | ClassDeclaration): ObjectLiteralExpression;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetComponentDecoratorObject = void 0;
4
+ const ts_morph_1 = require("@rxap/ts-morph");
5
+ const ts_morph_2 = require("ts-morph");
6
+ function GetComponentDecoratorObject(sourceFileOrClassDeclaration) {
7
+ const classDeclaration = sourceFileOrClassDeclaration instanceof ts_morph_2.ClassDeclaration ? sourceFileOrClassDeclaration : (0, ts_morph_1.GetComponentClass)(sourceFileOrClassDeclaration);
8
+ const componentDecorator = classDeclaration.getDecorator('Component');
9
+ let componentOptions = componentDecorator.getArguments()[0];
10
+ if (!componentOptions) {
11
+ componentOptions = componentDecorator.addArgument(ts_morph_2.Writers.object({}));
12
+ }
13
+ if (!(componentOptions instanceof ts_morph_2.ObjectLiteralExpression)) {
14
+ throw new Error('The Component options is not an object literal expression');
15
+ }
16
+ return componentOptions;
17
+ }
18
+ exports.GetComponentDecoratorObject = GetComponentDecoratorObject;
19
+ //# sourceMappingURL=get-component-decorator-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-component-decorator-object.js","sourceRoot":"","sources":["../../../../../../packages/ts-morph/src/lib/angular/get-component-decorator-object.ts"],"names":[],"mappings":";;;AAAA,6CAAmD;AACnD,uCAKkB;AAElB,SAAgB,2BAA2B,CACzC,4BAA2D;IAG3D,MAAM,gBAAgB,GAAG,4BAA4B,YAAY,2BAAgB,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,IAAA,4BAAiB,EAAC,4BAA4B,CAAC,CAAC;IAGnK,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,YAAY,CAAC,WAAW,CAAE,CAAC;IACvE,IAAI,gBAAgB,GAAG,kBAAkB,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC;IAE5D,IAAI,CAAC,gBAAgB,EAAE;QACrB,gBAAgB,GAAG,kBAAkB,CAAC,WAAW,CAAC,kBAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;KACvE;IAED,IAAI,CAAC,CAAC,gBAAgB,YAAY,kCAAuB,CAAC,EAAE;QAC1D,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;KAC9E;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAnBD,kEAmBC"}
@@ -0,0 +1,19 @@
1
+ import { ClassLikeDeclarationBase, GetAccessorDeclaration, GetAccessorDeclarationStructure, SetAccessorDeclaration, SetAccessorDeclarationStructure } from 'ts-morph';
2
+ /**
3
+ * Coerces a set accessor declaration within a class-like declaration.
4
+ *
5
+ * @param {ClassLikeDeclarationBase} classLikeDeclaration - The class-like declaration that should contain the set accessor.
6
+ * @param {string} name - The name of the set accessor.
7
+ * @param {Partial<SetAccessorDeclarationStructure>} [structure={}] - Optional structure to set on the set accessor.
8
+ * @returns {SetAccessorDeclaration} - The coerced or added set accessor declaration.
9
+ */
10
+ export declare function CoerceSetAccessorDeclaration(classLikeDeclaration: ClassLikeDeclarationBase, name: string, structure?: Partial<SetAccessorDeclarationStructure>): SetAccessorDeclaration;
11
+ /**
12
+ * Coerces a get accessor declaration for a class-like declaration.
13
+ *
14
+ * @param {ClassLikeDeclarationBase} classLikeDeclaration - The class-like declaration to coerce the get accessor for.
15
+ * @param {string} name - The name of the get accessor.
16
+ * @param {Partial<GetAccessorDeclarationStructure>} structure - The structure to set on the get accessor declaration. (Optional)
17
+ * @returns {GetAccessorDeclaration} - The coerced or created get accessor declaration.
18
+ */
19
+ export declare function CoerceGetAccessorDeclaration(classLikeDeclaration: ClassLikeDeclarationBase, name: string, structure?: Partial<GetAccessorDeclarationStructure>): GetAccessorDeclaration;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CoerceGetAccessorDeclaration = exports.CoerceSetAccessorDeclaration = void 0;
4
+ /**
5
+ * Coerces a set accessor declaration within a class-like declaration.
6
+ *
7
+ * @param {ClassLikeDeclarationBase} classLikeDeclaration - The class-like declaration that should contain the set accessor.
8
+ * @param {string} name - The name of the set accessor.
9
+ * @param {Partial<SetAccessorDeclarationStructure>} [structure={}] - Optional structure to set on the set accessor.
10
+ * @returns {SetAccessorDeclaration} - The coerced or added set accessor declaration.
11
+ */
12
+ function CoerceSetAccessorDeclaration(classLikeDeclaration, name, structure = {}) {
13
+ let setAccessorDeclaration = classLikeDeclaration.getSetAccessor(name);
14
+ if (!setAccessorDeclaration) {
15
+ setAccessorDeclaration = classLikeDeclaration.addSetAccessor({ name });
16
+ setAccessorDeclaration.set(structure);
17
+ }
18
+ return setAccessorDeclaration;
19
+ }
20
+ exports.CoerceSetAccessorDeclaration = CoerceSetAccessorDeclaration;
21
+ /**
22
+ * Coerces a get accessor declaration for a class-like declaration.
23
+ *
24
+ * @param {ClassLikeDeclarationBase} classLikeDeclaration - The class-like declaration to coerce the get accessor for.
25
+ * @param {string} name - The name of the get accessor.
26
+ * @param {Partial<GetAccessorDeclarationStructure>} structure - The structure to set on the get accessor declaration. (Optional)
27
+ * @returns {GetAccessorDeclaration} - The coerced or created get accessor declaration.
28
+ */
29
+ function CoerceGetAccessorDeclaration(classLikeDeclaration, name, structure = {}) {
30
+ let getAccessorDeclaration = classLikeDeclaration.getGetAccessor(name);
31
+ if (!getAccessorDeclaration) {
32
+ getAccessorDeclaration = classLikeDeclaration.addGetAccessor({ name });
33
+ getAccessorDeclaration.set(structure);
34
+ }
35
+ return getAccessorDeclaration;
36
+ }
37
+ exports.CoerceGetAccessorDeclaration = CoerceGetAccessorDeclaration;
38
+ //# sourceMappingURL=coerce-accessor-declaration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coerce-accessor-declaration.js","sourceRoot":"","sources":["../../../../../packages/ts-morph/src/lib/coerce-accessor-declaration.ts"],"names":[],"mappings":";;;AAQA;;;;;;;GAOG;AACH,SAAgB,4BAA4B,CAC1C,oBAA8C,EAC9C,IAAY,EACZ,YAAsD,EAAE;IAExD,IAAI,sBAAsB,GAAG,oBAAoB,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACvE,IAAI,CAAC,sBAAsB,EAAE;QAC3B,sBAAsB,GAAG,oBAAoB,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QACvE,sBAAsB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;KACvC;IACD,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAXD,oEAWC;AAED;;;;;;;GAOG;AACH,SAAgB,4BAA4B,CAC1C,oBAA8C,EAC9C,IAAY,EACZ,YAAsD,EAAE;IAExD,IAAI,sBAAsB,GAAG,oBAAoB,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACvE,IAAI,CAAC,sBAAsB,EAAE;QAC3B,sBAAsB,GAAG,oBAAoB,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QACvE,sBAAsB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;KACvC;IACD,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAXD,oEAWC"}
@@ -1,3 +1,4 @@
1
1
  import { ArrayLiteralExpression, Expression, WriterFunction } from 'ts-morph';
2
2
  export declare function FindArrayElementByObjectProperty(property: string, value: string): (e: Expression) => boolean;
3
- export declare function CoerceArrayElement(array: ArrayLiteralExpression, findExisting: (e: Expression) => boolean, element: string | WriterFunction, insertAt?: (array: ArrayLiteralExpression) => number): Expression;
3
+ export declare function DefaultFindExistingElement(element: string): (e: Expression) => boolean;
4
+ export declare function CoerceArrayElement(array: ArrayLiteralExpression, element: string | WriterFunction, findExisting?: (e: Expression) => boolean, insertAt?: (array: ArrayLiteralExpression) => number): Expression;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CoerceArrayElement = exports.FindArrayElementByObjectProperty = void 0;
3
+ exports.CoerceArrayElement = exports.DefaultFindExistingElement = exports.FindArrayElementByObjectProperty = void 0;
4
4
  const ts_morph_1 = require("ts-morph");
5
5
  function FindArrayElementByObjectProperty(property, value) {
6
6
  return (e) => {
@@ -17,7 +17,19 @@ function FindArrayElementByObjectProperty(property, value) {
17
17
  };
18
18
  }
19
19
  exports.FindArrayElementByObjectProperty = FindArrayElementByObjectProperty;
20
- function CoerceArrayElement(array, findExisting, element, insertAt) {
20
+ function DefaultFindExistingElement(element) {
21
+ return (e) => e.getText().trim() === element;
22
+ }
23
+ exports.DefaultFindExistingElement = DefaultFindExistingElement;
24
+ function CoerceArrayElement(array, element, findExisting, insertAt) {
25
+ if (!findExisting) {
26
+ if (typeof element === 'string') {
27
+ findExisting = DefaultFindExistingElement(element);
28
+ }
29
+ else {
30
+ throw new Error('The findExisting function is required or the element must be a string!');
31
+ }
32
+ }
21
33
  for (const e of array.getElements()) {
22
34
  if (findExisting(e)) {
23
35
  return e;
@@ -1 +1 @@
1
- {"version":3,"file":"coerce-array-element.js","sourceRoot":"","sources":["../../../../../packages/ts-morph/src/lib/coerce-array-element.ts"],"names":[],"mappings":";;;AAAA,uCAOkB;AAElB,SAAgB,gCAAgC,CAAC,QAAgB,EAAE,KAAa;IAC9E,OAAO,CAAC,CAAa,EAAE,EAAE;QACvB,IAAI,CAAC,YAAY,kCAAuB,EAAE;YACxC,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;YAClC,IAAI,CAAC,IAAI,CAAC,YAAY,6BAAkB,EAAE;gBACxC,MAAM,CAAC,GAAG,CAAC,CAAC,oBAAoB,CAAC,qBAAU,CAAC,aAAa,CAAC,CAAC;gBAC3D,IAAI,CAAC,EAAE;oBACL,OAAO,CAAC,CAAC,cAAc,EAAE,KAAK,KAAK,CAAC;iBACrC;aACF;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAbD,4EAaC;AAED,SAAgB,kBAAkB,CAChC,KAA6B,EAC7B,YAAwC,EACxC,OAAgC,EAChC,QAAoD;IAGpD,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE;QACnC,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE;YACnB,OAAO,CAAC,CAAC;SACV;KACF;IAED,IAAI,QAAQ,EAAE;QACZ,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;KACtD;IAED,OAAO,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAEnC,CAAC;AAnBD,gDAmBC"}
1
+ {"version":3,"file":"coerce-array-element.js","sourceRoot":"","sources":["../../../../../packages/ts-morph/src/lib/coerce-array-element.ts"],"names":[],"mappings":";;;AAAA,uCAOkB;AAElB,SAAgB,gCAAgC,CAAC,QAAgB,EAAE,KAAa;IAC9E,OAAO,CAAC,CAAa,EAAE,EAAE;QACvB,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clarationStructure } from 'ts-morph';
2
+ /**
3
+ * @deprecated instead use the CoercePropertyDeclaration function from @rxap/ts-morph
4
+ */
2
5
  export declare function CoerceClassProperty(classDeclaration: ClassDeclaration, propertyName: string, propertyStructure: Omit<OptionalKind<PropertyDeclarationStructure>, 'name'>): PropertyDeclaration;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CoerceClassProperty = void 0;
4
+ /**
5
+ * @deprecated instead use the CoercePropertyDeclaration function from @rxap/ts-morph
6
+ */
4
7
  function CoerceClassProperty(classDeclaration, propertyName, propertyStructure) {
5
8
  let propertyDeclaration = classDeclaration.getProperty(propertyName);
6
9
  if (!propertyDeclaration) {
@@ -1 +1 @@
1
- {"version":3,"file":"coerce-class-property.js","sourceRoot":"","sources":["../../../../../packages/ts-morph/src/lib/coerce-class-property.ts"],"names":[],"mappings":";;;AAOA,SAAgB,mBAAmB,CACjC,gBAAkC,EAClC,YAAoB,EACpB,iBAA2E;IAG3E,IAAI,mBAAmB,GAAG,gBAAgB,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAErE,IAAI,CAAC,mBAAmB,EAAE;QACxB,mBAAmB,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC,kCAClD,iBAAiB,KACpB,IAAI,EAAE,YAAY,IAClB,CAAC;KACJ;IAED,OAAO,mBAAmB,CAAC;AAC7B,CAAC;AAhBD,kDAgBC"}
1
+ {"version":3,"file":"coerce-class-property.js","sourceRoot":"","sources":["../../../../../packages/ts-morph/src/lib/coerce-class-property.ts"],"names":[],"mappings":";;;AAOA;;GAEG;AACH,SAAgB,mBAAmB,CACjC,gBAAkC,EAClC,YAAoB,EACpB,iBAA2E;IAG3E,IAAI,mBAAmB,GAAG,gBAAgB,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAErE,IAAI,CAAC,mBAAmB,EAAE;QACxB,mBAAmB,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC,kCAClD,iBAAiB,KACpB,IAAI,EAAE,YAAY,IAClB,CAAC;KACJ;IAED,OAAO,mBAAmB,CAAC;AAC7B,CAAC;AAhBD,kDAgBC"}
@@ -0,0 +1,2 @@
1
+ import { ClassDeclaration, SourceFile } from 'ts-morph';
2
+ export declare function CoerceDefaultClassExport(sourceFileOrClassDeclaration: SourceFile | ClassDeclaration, standalone?: boolean): void;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CoerceDefaultClassExport = void 0;
4
+ const ts_morph_1 = require("ts-morph");
5
+ function CoerceDefaultClassExport(sourceFileOrClassDeclaration, standalone = false) {
6
+ const classDeclaration = sourceFileOrClassDeclaration instanceof ts_morph_1.SourceFile ? sourceFileOrClassDeclaration.getClasses().filter(cd => !cd.isDefaultExport())[0] : sourceFileOrClassDeclaration;
7
+ const sourceFile = sourceFileOrClassDeclaration instanceof ts_morph_1.SourceFile ? sourceFileOrClassDeclaration : sourceFileOrClassDeclaration.getSourceFile();
8
+ if (!ts_morph_1.ClassDeclaration) {
9
+ throw new Error('No class declaration');
10
+ }
11
+ if (standalone) {
12
+ console.log('standalone', sourceFile.getExportAssignments().map(ed => ed.getExpression().getText()));
13
+ if (!sourceFile.getExportAssignments().some(ed => ed.getExpression().getText() === classDeclaration.getName())) {
14
+ sourceFile.addExportAssignment({
15
+ isExportEquals: false,
16
+ expression: classDeclaration.getName(),
17
+ });
18
+ }
19
+ }
20
+ else {
21
+ if (!sourceFile.getClasses().some(cd => cd.isDefaultExport() && cd.getName() === classDeclaration.getName())) {
22
+ classDeclaration.setIsDefaultExport(true);
23
+ }
24
+ }
25
+ }
26
+ exports.CoerceDefaultClassExport = CoerceDefaultClassExport;
27
+ //# sourceMappingURL=coerce-default-class-export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coerce-default-class-export.js","sourceRoot":"","sources":["../../../../../packages/ts-morph/src/lib/coerce-default-class-export.ts"],"names":[],"mappings":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B,CAAC,IAAI,CAAC,CAAC;SAC3C;KACF;AAEH,CAAC;AAvBD,4DAuBC"}
@@ -0,0 +1,3 @@
1
+ import { ClassLikeDeclarationBase, PropertyDeclaration, PropertyDeclarationStructure, PropertySignature, TypeElementMemberedNode } from 'ts-morph';
2
+ export declare function CoercePropertyDeclaration(typeElementMemberedNode: TypeElementMemberedNode, name: string, structure?: Partial<PropertyDeclarationStructure>): PropertySignature;
3
+ export declare function CoercePropertyDeclaration(classLikeDeclarationBase: ClassLikeDeclarationBase, name: string, structure?: Partial<PropertyDeclarationStructure>): PropertyDeclaration;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CoercePropertyDeclaration = void 0;
4
+ function CoercePropertyDeclaration(node, name, structure = {}) {
5
+ let property = node.getProperty(name);
6
+ if (!property) {
7
+ property = node.addProperty({ name });
8
+ property.set(structure);
9
+ }
10
+ return property;
11
+ }
12
+ exports.CoercePropertyDeclaration = CoercePropertyDeclaration;
13
+ //# sourceMappingURL=coerce-property-declaration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coerce-property-declaration.js","sourceRoot":"","sources":["../../../../../packages/ts-morph/src/lib/coerce-property-declaration.ts"],"names":[],"mappings":";;;AAoBA,SAAgB,yBAAyB,CACvC,IAAwD,EACxD,IAAY,EACZ,YAA+H,EAAE;IAEjI,IAAI,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,CAAC,QAAQ,EAAE;QACb,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QACtC,QAAQ,CAAC,GAAG,CAAC,SAAgB,CAAC,CAAC;KAChC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAXD,8DAWC"}
@@ -0,0 +1,15 @@
1
+ import { TypeImport } from '@rxap/ts-morph';
2
+ import { Normalized } from '@rxap/utilities';
3
+ import { OptionalKind, PropertySignatureStructure, SourceFile } from 'ts-morph';
4
+ import { NormalizedTypeImport } from './type-import';
5
+ export interface DataProperty {
6
+ name: string;
7
+ type?: string | TypeImport;
8
+ isArray?: boolean;
9
+ }
10
+ export interface NormalizedDataProperty extends Readonly<Normalized<DataProperty>> {
11
+ type: NormalizedTypeImport;
12
+ }
13
+ export declare function NormalizeDataProperty(property: string | Readonly<DataProperty>, defaultType?: string): NormalizedDataProperty;
14
+ export declare function NormalizeDataPropertyList(propertyList?: Array<string | DataProperty>, defaultType?: string): ReadonlyArray<NormalizedDataProperty>;
15
+ export declare function NormalizeDataPropertyToPropertySignatureStructure(property: DataProperty, sourceFile: SourceFile): OptionalKind<PropertySignatureStructure>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NormalizeDataPropertyToPropertySignatureStructure = exports.NormalizeDataPropertyList = exports.NormalizeDataProperty = void 0;
4
+ const type_import_1 = require("./type-import");
5
+ const write_type_1 = require("./write-type");
6
+ function guessType(name) {
7
+ switch (name) {
8
+ case 'uuid':
9
+ case 'name':
10
+ return 'string';
11
+ }
12
+ if (name.match(/^(is|has)[A-Z]/)) {
13
+ return 'boolean';
14
+ }
15
+ return 'unknown';
16
+ }
17
+ function NormalizeDataProperty(property, defaultType = 'unknown') {
18
+ var _a, _b;
19
+ let name;
20
+ let type = 'unknown';
21
+ let isArray = false;
22
+ if (typeof property === 'string') {
23
+ // name:type
24
+ // username:string
25
+ const fragments = property.split(':');
26
+ name = fragments[0];
27
+ type = fragments[1] || guessType(name); // convert an empty string to undefined
28
+ }
29
+ else {
30
+ name = property.name;
31
+ type = (_a = property.type) !== null && _a !== void 0 ? _a : guessType(name);
32
+ isArray = (_b = property.isArray) !== null && _b !== void 0 ? _b : isArray;
33
+ }
34
+ if (name.endsWith('[]')) {
35
+ isArray = true;
36
+ name = name.slice(0, -2);
37
+ }
38
+ if (name.startsWith('Array<') && name.endsWith('>')) {
39
+ isArray = true;
40
+ name = name.slice(6, -1);
41
+ }
42
+ type !== null && type !== void 0 ? type : (type = defaultType);
43
+ name = name.replace(/\.\?/g, '.').split('.').join('.?');
44
+ return Object.freeze({
45
+ name,
46
+ type: (0, type_import_1.NormalizeTypeImport)(type),
47
+ isArray,
48
+ });
49
+ }
50
+ exports.NormalizeDataProperty = NormalizeDataProperty;
51
+ function NormalizeDataPropertyList(propertyList, defaultType = 'unknown') {
52
+ var _a;
53
+ return Object.freeze((_a = propertyList === null || propertyList === void 0 ? void 0 : propertyList.map(property => NormalizeDataProperty(property, defaultType))) !== null && _a !== void 0 ? _a : []);
54
+ }
55
+ exports.NormalizeDataPropertyList = NormalizeDataPropertyList;
56
+ function NormalizeDataPropertyToPropertySignatureStructure(property, sourceFile) {
57
+ return {
58
+ type: (0, write_type_1.WriteType)(property, sourceFile),
59
+ name: property.name,
60
+ };
61
+ }
62
+ exports.NormalizeDataPropertyToPropertySignatureStructure = NormalizeDataPropertyToPropertySignatureStructure;
63
+ //# sourceMappingURL=data-property.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-property.js","sourceRoot":"","sources":["../../../../../packages/ts-morph/src/lib/data-property.ts"],"names":[],"mappings":";;;AAOA,+CAGuB;AACvB,6CAAyC;AAYzC,SAAS,SAAS,CAAC,IAAY;IAC7B,QAAQ,IAAI,EAAE;QACZ,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC;KACnB;IACD,IAAI,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE;QAChC,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAgB,qBAAqB,CAAC,QAAyC,EAAE,WAAW,GAAG,SAAS;;IACtG,IAAI,IAAY,CAAC;IACjB,IAAI,IAAI,GAAwB,SAAS,CAAC;IAC1C,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAChC,Y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,OAAO,MAAM,CAAC,MAAM,CAAC,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,qBAAqB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,mCAAI,EAAE,CAAC,CAAC;AAC1G,CAAC;AAFD,8DAEC;AAED,SAAgB,iDAAiD,CAC/D,QAAsB,EACtB,UAAsB;IAEtB,OAAO;QACL,IAAI,EAAE,IAAA,sBAAS,EAAC,QAAQ,EAAE,UAAU,CAAC;QACrC,IAAI,EAAE,QAAQ,CAAC,IAAI;KACpB,CAAC;AACJ,CAAC;AARD,8GAQC"}
@@ -0,0 +1,10 @@
1
+ import { ClassDeclaration } from 'ts-morph';
2
+ /**
3
+ * Checks if a constructor parameter with the given name exists in a class.
4
+ *
5
+ * @param {ClassDeclaration} classDeclaration - The class declaration to check.
6
+ * @param {string} parameterName - The name of the constructor parameter.
7
+ * @param {boolean} isAlsoClassMember - Optional. Determines if only constructor parameter that are also class members are checked. Default is false.
8
+ * @returns {boolean} - True if a constructor parameter with the given name exists, false otherwise.
9
+ */
10
+ export declare function HasConstructorParameter(classDeclaration: ClassDeclaration, parameterName: string, isAlsoClassMember?: boolean): boolean;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HasConstructorParameter = void 0;
4
+ /**
5
+ * Checks if a constructor parameter with the given name exists in a class.
6
+ *
7
+ * @param {ClassDeclaration} classDeclaration - The class declaration to check.
8
+ * @param {string} parameterName - The name of the constructor parameter.
9
+ * @param {boolean} isAlsoClassMember - Optional. Determines if only constructor parameter that are also class members are checked. Default is false.
10
+ * @returns {boolean} - True if a constructor parameter with the given name exists, false otherwise.
11
+ */
12
+ function HasConstructorParameter(classDeclaration, parameterName, isAlsoClassMember = false) {
13
+ return classDeclaration.getConstructors().some(cotr => cotr.getParameters()
14
+ .some(param => (!isAlsoClassMember || !!param.getScope()) && param.getName() === parameterName));
15
+ }
16
+ exports.HasConstructorParameter = HasConstructorParameter;
17
+ //# sourceMappingURL=has-constructor-parameter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-constructor-parameter.js","sourceRoot":"","sources":["../../../../../packages/ts-morph/src/lib/has-constructor-parameter.ts"],"names":[],"mappings":";;;AAEA;;;;;;;GAOG;AACH,SAAgB,uBAAuB,CACrC,gBAAkC,EAClC,aAAqB,EACrB,iBAAiB,GAAG,KAAK;IAEzB,OAAO,gBAAgB,CAAC,eAAe,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE;SACxE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,IAAI,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,KAAK,aAAa,CAAC,CAAC,CAAC;AACrG,CAAC;AAPD,0DAOC"}
@@ -7,5 +7,15 @@ export interface TypeImport {
7
7
  isTypeOnly?: boolean | null;
8
8
  defaultImport?: string | null;
9
9
  }
10
+ export declare function IsTypeImport(value: any): value is TypeImport;
10
11
  export declare function RequiresTypeImport(typeImport: TypeImport): boolean;
11
12
  export declare function TypeImportToImportStructure(typeImport: TypeImport): OptionalKind<ImportDeclarationStructure>;
13
+ export interface NormalizedTypeImport {
14
+ name: string;
15
+ moduleSpecifier: string | null;
16
+ namedImport: string | null;
17
+ namespaceImport: string | null;
18
+ isTypeOnly: boolean | null;
19
+ defaultImport: string | null;
20
+ }
21
+ export declare function NormalizeTypeImport(typeImport?: Readonly<TypeImport> | string): NormalizedTypeImport;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TypeImportToImportStructure = exports.RequiresTypeImport = void 0;
3
+ exports.NormalizeTypeImport = exports.TypeImportToImportStructure = exports.RequiresTypeImport = exports.IsTypeImport = void 0;
4
+ function IsTypeImport(value) {
5
+ return typeof value === 'object' && typeof value.name === 'string';
6
+ }
7
+ exports.IsTypeImport = IsTypeImport;
4
8
  function RequiresTypeImport(typeImport) {
5
9
  return !!typeImport.moduleSpecifier;
6
10
  }
@@ -27,4 +31,41 @@ function TypeImportToImportStructure(typeImport) {
27
31
  return structure;
28
32
  }
29
33
  exports.TypeImportToImportStructure = TypeImportToImportStructure;
34
+ function NormalizeTypeImport(typeImport) {
35
+ var _a, _b, _c, _d, _e;
36
+ let name;
37
+ let moduleSpecifier = null;
38
+ let namedImport = null;
39
+ let namespaceImport = null;
40
+ let isTypeOnly = false;
41
+ let defaultImport = null;
42
+ if (!typeImport) {
43
+ name = 'unknown';
44
+ }
45
+ else if (typeof typeImport === 'string') {
46
+ // name:moduleSpecifier:namedImport
47
+ // IconConfig:@rxap/utilities
48
+ const fragments = typeImport.split(':');
49
+ name = fragments[0] || 'unknown';
50
+ moduleSpecifier = fragments[1] || null; // use || instead of ?? because the moduleSpecifier can be an empty string
51
+ namedImport = fragments[2] || null; // use || instead of ?? because the namedImport can be an empty string
52
+ }
53
+ else {
54
+ name = typeImport.name;
55
+ moduleSpecifier = (_a = typeImport.moduleSpecifier) !== null && _a !== void 0 ? _a : moduleSpecifier;
56
+ namedImport = (_b = typeImport.namedImport) !== null && _b !== void 0 ? _b : namedImport;
57
+ namespaceImport = (_c = typeImport.namespaceImport) !== null && _c !== void 0 ? _c : namespaceImport;
58
+ isTypeOnly = (_d = typeImport.isTypeOnly) !== null && _d !== void 0 ? _d : isTypeOnly;
59
+ defaultImport = (_e = typeImport.defaultImport) !== null && _e !== void 0 ? _e : defaultImport;
60
+ }
61
+ return ({
62
+ name,
63
+ moduleSpecifier,
64
+ namedImport,
65
+ namespaceImport,
66
+ isTypeOnly,
67
+ defaultImport,
68
+ });
69
+ }
70
+ exports.NormalizeTypeImport = NormalizeTypeImport;
30
71
  //# sourceMappingURL=type-import.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-import.js","sourceRoot":"","sources":["../../../../../packages/ts-morph/src/lib/type-import.ts"],"names":[],"mappings":";;;AAcA,SAAgB,kBAAkB,CAAC,UAAsB;IACvD,OAAO,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC;AACtC,CAAC;AAFD,gDAEC;AAED,SAAgB,2BAA2B,CAAC,UAAsB;IAChE,IAAI,CAAC,UAAU,CAAC,eAAe,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;KACpD;IACD,MAAM,SAAS,GAA6C;QAC1D,eAAe,EAAE,UAAU,CAAC,eAAe;KAC5C,CAAC;IACF,IAAI,CAAC,UAAU,CAAC,WAAW,IAAI,CAAC,UAAU,CAAC,eAAe,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE;QACvF,SAAS,CAAC,YAAY,GAAG,CAAE,UAAU,CAAC,IAAI,CAAE,CAAC;KAC9C;IACD,IAAI,UAAU,CAAC,WAAW,EAAE;QAC1B,SAAS,CAAC,YAAY,GAAG,CAAE,UAAU,CAAC,WAAW,CAAE,CAAC;KACrD;IACD,IAAI,UAAU,CAAC,eAAe,EAAE;QAC9B,SAAS,CAAC,eAAe,GAAG,UAAU,CAAC,eAAe,CAAC;KACxD;IACD,IAAI,UAAU,CAAC,aAAa,EAAE;QAC5B,SAAS,CAAC,aAAa,GAAG,UAAU,CAAC,aAAa,CAAC;KACpD;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AApBD,kEAoBC"}
1
+ {"version":3,"file":"type-import.js","sourceRoot":"","sources":["../../../../../packages/ts-morph/src/lib/type-import.ts"],"names":[],"mappings":";;;AAcA,SAAgB,YAAY,CAAC,KAAU;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;AACrE,CAAC;AAFD,oCAEC;AAED,SAAgB,kBAAkB,CAAC,UAAsB;IACvD,OAAO,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC;AACtC,CAAC;AAFD,gDAEC;AAED,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AS,CAAC;QACjC,eAAe,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,0EAA0E;QAClH,WAAW,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,sEAAsE;KAC3G;SAAM;QACL,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;QACvB,eAAe,GAAG,MAAA,UAAU,CAAC,eAAe,mCAAI,eAAe,CAAC;QAChE,WAAW,GAAG,MAAA,UAAU,CAAC,WAAW,mCAAI,WAAW,CAAC;QACpD,eAAe,GAAG,MAAA,UAAU,CAAC,eAAe,mCAAI,eAAe,CAAC;QAChE,UAAU,GAAG,MAAA,UAAU,CAAC,UAAU,mCAAI,UAAU,CAAC;QACjD,aAAa,GAAG,MAAA,UAAU,CAAC,aAAa,mCAAI,aAAa,CAAC;KAC3D;IACD,OAAO,CAAC;QACN,IAAI;QACJ,eAAe;QACf,WAAW;QACX,eAAe;QACf,UAAU;QACV,aAAa;KACd,CAAC,CAAC;AACL,CAAC;AAhCD,kDAgCC"}
@@ -0,0 +1,18 @@
1
+ import { CodeBlockWriter, SourceFile, WriterFunction } from 'ts-morph';
2
+ import { TypeImport } from './type-import';
3
+ export type WriteType = string | TypeImport | WriterFunction;
4
+ export interface WriteTypeOptions {
5
+ isArray?: boolean | null;
6
+ type: WriteType;
7
+ }
8
+ export declare function IsWriteTypeOptions(value: any): value is WriteTypeOptions;
9
+ /**
10
+ * Uses the CodeBlockWriter to write the type to the AST thereby the value of the property type is evaluated
11
+ * to determine the value that should be written to the AST
12
+ * @param type
13
+ * @param w
14
+ * @constructor
15
+ */
16
+ export declare function WriteStringType(type: string, w: CodeBlockWriter): void;
17
+ export declare function WriteType(type: WriteType, sourceFile: SourceFile): WriterFunction;
18
+ export declare function WriteType(property: WriteTypeOptions, sourceFile: SourceFile): WriterFunction;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WriteType = exports.WriteStringType = exports.IsWriteTypeOptions = void 0;
4
+ const coerce_imports_1 = require("./coerce-imports");
5
+ const type_import_1 = require("./type-import");
6
+ function IsWriteTypeOptions(value) {
7
+ return value && typeof value === 'object' && value.type;
8
+ }
9
+ exports.IsWriteTypeOptions = IsWriteTypeOptions;
10
+ /**
11
+ * Uses the CodeBlockWriter to write the type to the AST thereby the value of the property type is evaluated
12
+ * to determine the value that should be written to the AST
13
+ * @param type
14
+ * @param w
15
+ * @constructor
16
+ */
17
+ function WriteStringType(type, w) {
18
+ switch (type) {
19
+ case 'date':
20
+ w.write('Date');
21
+ break;
22
+ case 'uuid':
23
+ w.write('string');
24
+ break;
25
+ default:
26
+ w.write(type);
27
+ break;
28
+ }
29
+ }
30
+ exports.WriteStringType = WriteStringType;
31
+ function WriteType(propertyOrType, sourceFile) {
32
+ var _a;
33
+ let isArray = false;
34
+ let type;
35
+ if (IsWriteTypeOptions(propertyOrType)) {
36
+ isArray = (_a = propertyOrType.isArray) !== null && _a !== void 0 ? _a : isArray;
37
+ type = propertyOrType.type;
38
+ }
39
+ else {
40
+ type = propertyOrType;
41
+ }
42
+ if ((0, type_import_1.IsTypeImport)(type)) {
43
+ if (sourceFile) {
44
+ if ((0, type_import_1.RequiresTypeImport)(type)) {
45
+ (0, coerce_imports_1.CoerceImports)(sourceFile, (0, type_import_1.TypeImportToImportStructure)(type));
46
+ }
47
+ }
48
+ else {
49
+ console.warn('WriteType :: No source file provided to coerce imports');
50
+ }
51
+ }
52
+ return (w) => {
53
+ if (isArray) {
54
+ w.write('Array<');
55
+ }
56
+ if (typeof type === 'string') {
57
+ WriteStringType(type, w);
58
+ }
59
+ else if (typeof type === 'function') {
60
+ type(w);
61
+ }
62
+ else if ((0, type_import_1.IsTypeImport)(type)) {
63
+ WriteStringType(type.name, w);
64
+ }
65
+ else {
66
+ throw new Error('Invalid type');
67
+ }
68
+ if (isArray) {
69
+ w.write('>');
70
+ }
71
+ };
72
+ }
73
+ exports.WriteType = WriteType;
74
+ //# sourceMappingURL=write-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-type.js","sourceRoot":"","sources":["../../../../../packages/ts-morph/src/lib/write-type.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAMjD,+CAKuB;AASvB,SAAgB,kBAAkB,CAAC,KAAU;IAC3C,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC;AAC1D,CAAC;AAFD,gDAEC;AAED;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,IAAY,EAAE,CAAkB;IAC9D,QAAQ,IAAI,EAAE;QACZ,KAAK,MAAM;YACT,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAChB,MAAM;QACR,KAAK,MAAM;YACT,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAClB,MAAM;QACR;YACE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACd,MAAM;KACT;AACH,CAAC;AAZD,0CAYC;AAID,SAAgB,SAAS,CAAC,cAA4C,EAAE,UAAsB;;IAC5F,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,IAAe,CAAC;IACpB,IAAI,kBAAkB,CAAC,cAAc,CAAC,EAAE;QACtC,OAAO,GAAG,MAAA,cAAc,CAAC,OAAO,mCAAI,OAAO,CAAC;QAC5C,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC;KAC5B;SAAM;QACL,IAAI,GAAG,cAAc,CAAC;KACvB;IACD,IAAI,IAAA,0BAAY,EAAC,IAAI,CAAC,EAAE;QACtB,IAAI,UAAU,EAAE;YACd,IAAI,IAAA,gCAAkB,EAAC,IAAI,CAAC,EAAE;gBAC5B,IAAA,8BAAa,EAAC,UAAU,EAAE,IAAA,yCAA2B,EAAC,IAAI,CAAC,CAAC,CAAC;aAC9D;SACF;aAAM;YACL,OAAO,CAAC,IAAI,CAAC,wDAAwD,CAAC,CAAC;SACxE;KACF;IACD,OAAO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