@cparra/apexdocs 2.6.0-alpha.0 → 2.6.0-beta.2

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 (63) hide show
  1. package/README.md +32 -13
  2. package/docs/Main/SampleClass.md +14 -8
  3. package/docs/README.md +16 -3
  4. package/docs/core-utils/ClassWithDescriptionBlock.md +36 -0
  5. package/examples/force-app/main/default/classes/ClassWithDescriptionBlock.cls +31 -0
  6. package/examples/force-app/main/default/classes/SampleClass.cls +9 -0
  7. package/lib/application/Apexdocs.js.map +1 -1
  8. package/lib/cli/generate.js +11 -2
  9. package/lib/cli/generate.js.map +1 -1
  10. package/lib/model/file.js +4 -2
  11. package/lib/model/file.js.map +1 -1
  12. package/lib/model/markdown-file.js +2 -2
  13. package/lib/model/markdown-file.js.map +1 -1
  14. package/lib/model/markdown-generation-util/type-declaration-util.js +4 -2
  15. package/lib/model/markdown-generation-util/type-declaration-util.js.map +1 -1
  16. package/lib/model/markdown-home-file.js +6 -2
  17. package/lib/model/markdown-home-file.js.map +1 -1
  18. package/lib/service/metadata-processor.js +4 -2
  19. package/lib/service/metadata-processor.js.map +1 -1
  20. package/lib/settings.d.ts +4 -1
  21. package/lib/settings.js +6 -4
  22. package/lib/settings.js.map +1 -1
  23. package/lib/transpiler/markdown/class-file-generatorHelper.js.map +1 -1
  24. package/lib/transpiler/markdown/docsify/docsify-docs-processor.d.ts +2 -1
  25. package/lib/transpiler/markdown/docsify/docsify-docs-processor.js.map +1 -1
  26. package/lib/transpiler/markdown/jekyll/jekyll-docsProcessor.d.ts +2 -1
  27. package/lib/transpiler/markdown/jekyll/jekyll-docsProcessor.js.map +1 -1
  28. package/lib/transpiler/markdown/markdown-transpiler-base.d.ts +0 -2
  29. package/lib/transpiler/markdown/markdown-transpiler-base.js.map +1 -1
  30. package/lib/transpiler/markdown/plain-markdown/plain-docsProcessor.d.ts +2 -1
  31. package/lib/transpiler/markdown/plain-markdown/plain-docsProcessor.js.map +1 -1
  32. package/lib/transpiler/processor-type-transpiler.d.ts +2 -0
  33. package/lib/transpiler/processor-type-transpiler.js.map +1 -1
  34. package/lib/util/truncate.d.ts +1 -0
  35. package/lib/util/truncate.js +8 -0
  36. package/lib/util/truncate.js.map +1 -0
  37. package/package.json +3 -4
  38. package/src/application/Apexdocs.ts +1 -1
  39. package/src/cli/generate.ts +12 -2
  40. package/src/model/file.ts +4 -2
  41. package/src/model/markdown-file.ts +3 -2
  42. package/src/model/markdown-generation-util/type-declaration-util.ts +4 -2
  43. package/src/model/markdown-home-file.ts +9 -1
  44. package/src/service/metadata-processor.ts +4 -1
  45. package/src/settings.ts +10 -5
  46. package/src/transpiler/markdown/class-file-generatorHelper.ts +1 -2
  47. package/src/transpiler/markdown/docsify/docsify-docs-processor.ts +2 -1
  48. package/src/transpiler/markdown/jekyll/jekyll-docsProcessor.ts +2 -1
  49. package/src/transpiler/markdown/markdown-transpiler-base.ts +0 -4
  50. package/src/transpiler/markdown/plain-markdown/plain-docsProcessor.ts +2 -1
  51. package/src/transpiler/processor-type-transpiler.ts +4 -0
  52. package/src/util/truncate.ts +3 -0
  53. package/docs/ts/GroupedClass.d.ts +0 -3
  54. package/docs/ts/SampleClass.d.ts +0 -11
  55. package/docs/ts/SampleInterface.d.ts +0 -0
  56. package/lib/model/ts-definition-file.d.ts +0 -26
  57. package/lib/model/ts-definition-file.js +0 -137
  58. package/lib/model/ts-definition-file.js.map +0 -1
  59. package/lib/transpiler/ts-types/TsTypesTranspiler.d.ts +0 -9
  60. package/lib/transpiler/ts-types/TsTypesTranspiler.js +0 -23
  61. package/lib/transpiler/ts-types/TsTypesTranspiler.js.map +0 -1
  62. package/src/model/ts-definition-file.ts +0 -165
  63. package/src/transpiler/ts-types/TsTypesTranspiler.ts +0 -24
@@ -1,8 +1,10 @@
1
1
  import { Type } from '@cparra/apex-reflection';
2
2
  import { FileContainer } from './file-container';
3
+ export declare type LinkingStrategy = 'root-relative' | 'path-relative';
3
4
  export default abstract class ProcessorTypeTranspiler {
4
5
  onBeforeProcess: ((types: Type[]) => void) | undefined;
5
6
  abstract onProcess(type: Type): void;
6
7
  onAfterProcess: ((types: Type[]) => void) | undefined;
7
8
  abstract fileBuilder(): FileContainer;
9
+ abstract getLinkingStrategy(): LinkingStrategy;
8
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"processor-type-transpiler.js","sourceRoot":"","sources":["../../src/transpiler/processor-type-transpiler.ts"],"names":[],"mappings":";;AAGA,MAA8B,uBAAuB;CAQpD;AARD,0CAQC"}
1
+ {"version":3,"file":"processor-type-transpiler.js","sourceRoot":"","sources":["../../src/transpiler/processor-type-transpiler.ts"],"names":[],"mappings":";;AAKA,MAA8B,uBAAuB;CAUpD;AAVD,0CAUC"}
@@ -0,0 +1 @@
1
+ export declare function truncate(str: string, n: number): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.truncate = void 0;
4
+ function truncate(str, n) {
5
+ return str.length > n ? str.substr(0, n - 1) + '…' : str;
6
+ }
7
+ exports.truncate = truncate;
8
+ //# sourceMappingURL=truncate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"truncate.js","sourceRoot":"","sources":["../../src/util/truncate.ts"],"names":[],"mappings":";;;AAAA,SAAgB,QAAQ,CAAC,GAAW,EAAE,CAAS;IAC7C,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC;AAClE,CAAC;AAFD,4BAEC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cparra/apexdocs",
3
- "version": "2.6.0-alpha.0",
3
+ "version": "2.6.0-beta.2",
4
4
  "description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.",
5
5
  "keywords": [
6
6
  "apex",
@@ -25,8 +25,7 @@
25
25
  "docs:init": "docsify init docs",
26
26
  "docs:serve": "docsify serve docs",
27
27
  "execute:example": "node lib/cli/generate.js -s examples/force-app -t docs --scope global public private -g docsify --defaultGroupName API",
28
- "execute:example:index:only": "node lib/cli/generate.js -s examples/force-app -t docs --scope global public private -g docsify --indexOnly",
29
- "execute:example:ts:definitions": "node lib/cli/generate.js -s examples/force-app -t docs/ts --scope global public -g ts-def"
28
+ "execute:example:index:only": "node lib/cli/generate.js -s examples/force-app -t docs --scope global public private -g docsify --indexOnly"
30
29
  },
31
30
  "author": "Cesar Parra",
32
31
  "license": "MIT",
@@ -65,7 +64,7 @@
65
64
  ]
66
65
  },
67
66
  "dependencies": {
68
- "@cparra/apex-reflection": "^1.6.0",
67
+ "@cparra/apex-reflection": "1.6.1",
69
68
  "chalk": "^4.1.2",
70
69
  "fast-xml-parser": "^4.0.1",
71
70
  "log-update": "4.0.0",
@@ -1,6 +1,6 @@
1
1
  import { ApexFileReader } from '../service/apex-file-reader';
2
2
  import { DefaultFileSystem } from '../service/file-system';
3
- import { ReflectionResult, reflect, Type, ClassMirror } from '@cparra/apex-reflection';
3
+ import { ReflectionResult, reflect, Type } from '@cparra/apex-reflection';
4
4
  import { Logger } from '../util/logger';
5
5
  import { createManifest } from '../service/manifest-factory';
6
6
  import { RawBodyParser } from '../service/parser';
@@ -35,9 +35,9 @@ const argv = yargs.options({
35
35
  type: 'string',
36
36
  alias: 'g',
37
37
  default: 'jekyll',
38
- choices: ['jekyll', 'docsify', 'plain-markdown', 'ts-def'],
38
+ choices: ['jekyll', 'docsify', 'plain-markdown'],
39
39
  describe:
40
- 'Define the static file generator for which the documents will be created. Currently supports jekyll, docsify, plain markdown, and Typescript type definitions.',
40
+ 'Define the static file generator for which the documents will be created. Currently supports jekyll, docsify, and plain markdown.',
41
41
  },
42
42
  indexOnly: {
43
43
  type: 'boolean',
@@ -49,6 +49,15 @@ const argv = yargs.options({
49
49
  default: 'Miscellaneous',
50
50
  describe: 'Defines the @group name to be used when a file does not specify it.',
51
51
  },
52
+ sanitizeHtml: {
53
+ type: 'boolean',
54
+ default: true,
55
+ describe:
56
+ 'When on, any special character within your ApexDocs is converted into its HTML code representation. ' +
57
+ 'This is specially useful when generic objects are described within the docs, e.g. "List< Foo>", "Map<Foo, Bar>" ' +
58
+ 'because otherwise the content within < and > would be treated as HTML tags and not shown in the output. ' +
59
+ 'Content in @example blocks are never sanitized.',
60
+ },
52
61
  }).argv;
53
62
 
54
63
  Settings.build({
@@ -59,6 +68,7 @@ Settings.build({
59
68
  targetGenerator: argv.targetGenerator as GeneratorChoices,
60
69
  indexOnly: argv.indexOnly,
61
70
  defaultGroupName: argv.defaultGroupName,
71
+ sanitizeHtml: argv.sanitizeHtml,
62
72
  });
63
73
 
64
74
  Apexdocs.generate();
package/src/model/file.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import xss = require('xss');
2
+ import { Settings } from '../settings';
2
3
 
3
4
  const xssFilter = new xss.FilterXSS({
4
- whiteList: { br: [], p: [], ul: [], li: [] },
5
+ whiteList: { br: [], p: [], ul: [], li: [], code: [], pre: [] },
5
6
  });
6
7
 
7
8
  export abstract class File {
@@ -16,7 +17,8 @@ export abstract class File {
16
17
  }
17
18
 
18
19
  addText(text: string, encodeHtml = true) {
19
- const textToAdd = encodeHtml ? xssFilter.process(text) : text;
20
+ const shouldEncode = encodeHtml && Settings.getInstance().sanitizeHtml;
21
+ const textToAdd = shouldEncode ? xssFilter.process(text) : text;
20
22
  this._contents += textToAdd;
21
23
  this.addBlankLine();
22
24
  }
@@ -21,18 +21,19 @@ export class MarkdownFile extends File {
21
21
  public addText(text: string, encodeHtml = true) {
22
22
  text = MarkdownFile.replaceInlineLinks(text);
23
23
  text = MarkdownFile.replaceInlineEmails(text);
24
+
24
25
  super.addText(text, encodeHtml);
25
26
  }
26
27
 
27
28
  startCodeBlock() {
28
- this._contents += '```';
29
+ this.addText('```');
29
30
  const sourceLanguage = 'apex';
30
31
  this._contents += sourceLanguage;
31
32
  this.addBlankLine();
32
33
  }
33
34
 
34
35
  endCodeBlock() {
35
- this._contents += '```';
36
+ this.addText('```');
36
37
  this.addBlankLine();
37
38
  }
38
39
 
@@ -8,9 +8,11 @@ export function declareType(markdownFile: MarkdownFile, typeMirror: Type): void
8
8
  markdownFile.addText(`\`${currentAnnotation.type.toUpperCase()}\``);
9
9
  });
10
10
 
11
- if (typeMirror.docComment?.description) {
11
+ if (typeMirror.docComment?.descriptionLines) {
12
12
  markdownFile.addBlankLine();
13
- markdownFile.addText(typeMirror.docComment.description);
13
+ for (const currentLine of typeMirror.docComment.descriptionLines) {
14
+ markdownFile.addText(currentLine);
15
+ }
14
16
  markdownFile.addBlankLine();
15
17
  }
16
18
 
@@ -1,6 +1,7 @@
1
1
  import { Type } from '@cparra/apex-reflection';
2
2
  import ClassFileGeneratorHelper from '../transpiler/markdown/class-file-generatorHelper';
3
3
  import { MarkdownFile } from './markdown-file';
4
+ import { truncate } from '../util/truncate';
4
5
 
5
6
  export class MarkdownHomeFile extends MarkdownFile {
6
7
  constructor(public fileName: string, public types: Type[], headerContent?: string) {
@@ -26,7 +27,14 @@ export class MarkdownHomeFile extends MarkdownFile {
26
27
  this.addBlankLine();
27
28
  this.addTitle(ClassFileGeneratorHelper.getFileLink(typeMirror), 3);
28
29
  this.addBlankLine();
29
- this.addText(typeMirror.docComment?.description ?? '');
30
+
31
+ if (typeMirror.docComment?.descriptionLines) {
32
+ const description = typeMirror.docComment.descriptionLines.reduce(
33
+ (previous, current) => previous + current + '\n',
34
+ '',
35
+ );
36
+ this.addText(truncate(description, 300));
37
+ }
30
38
  }
31
39
 
32
40
  private group(classes: Type[]): Map<string, Type[]> {
@@ -7,7 +7,10 @@ export default class MetadataProcessor {
7
7
 
8
8
  map.set('apiVersion', xml.ApexClass.apiVersion ?? '');
9
9
 
10
- map.set('status', xml.ApexClass.status ?? '');
10
+ if (xml.ApexClass.status) {
11
+ map.set('status', xml.ApexClass.status);
12
+ }
13
+
11
14
  return map;
12
15
  }
13
16
  }
package/src/settings.ts CHANGED
@@ -2,9 +2,8 @@ import ProcessorTypeTranspiler from './transpiler/processor-type-transpiler';
2
2
  import { JekyllDocsProcessor } from './transpiler/markdown/jekyll/jekyll-docsProcessor';
3
3
  import DocsifyDocsProcessor from './transpiler/markdown/docsify/docsify-docs-processor';
4
4
  import { PlainMarkdownDocsProcessor } from './transpiler/markdown/plain-markdown/plain-docsProcessor';
5
- import { TsTypesTranspiler } from './transpiler/ts-types/TsTypesTranspiler';
6
5
 
7
- export type GeneratorChoices = 'jekyll' | 'docsify' | 'plain-markdown' | 'ts-def';
6
+ export type GeneratorChoices = 'jekyll' | 'docsify' | 'plain-markdown';
8
7
 
9
8
  export interface SettingsConfig {
10
9
  sourceDirectory: string;
@@ -14,6 +13,7 @@ export interface SettingsConfig {
14
13
  targetGenerator: GeneratorChoices;
15
14
  indexOnly: boolean;
16
15
  defaultGroupName: string;
16
+ sanitizeHtml: boolean;
17
17
  }
18
18
 
19
19
  export class Settings {
@@ -64,9 +64,6 @@ export class Settings {
64
64
  case 'plain-markdown':
65
65
  Settings.typeTranspilerCache = new PlainMarkdownDocsProcessor();
66
66
  return Settings.typeTranspilerCache;
67
- case 'ts-def':
68
- Settings.typeTranspilerCache = new TsTypesTranspiler();
69
- return Settings.typeTranspilerCache;
70
67
  default:
71
68
  throw Error('Invalid target generator');
72
69
  }
@@ -76,6 +73,14 @@ export class Settings {
76
73
  return this.config.indexOnly;
77
74
  }
78
75
 
76
+ get sanitizeHtml(): boolean {
77
+ return this.config.sanitizeHtml;
78
+ }
79
+
80
+ get numberOfVisibleDescriptionLinesOnHomePage() {
81
+ return 5;
82
+ }
83
+
79
84
  public getDefaultGroupName(): string {
80
85
  return this.config.defaultGroupName;
81
86
  }
@@ -2,7 +2,6 @@ import { Type } from '@cparra/apex-reflection';
2
2
  import { TypesRepository } from '../../model/types-repository';
3
3
  import { Settings } from '../../settings';
4
4
  import State from '../../service/state';
5
- import { MarkdownTranspilerBase } from './markdown-transpiler-base';
6
5
 
7
6
  export default class ClassFileGeneratorHelper {
8
7
  public static getSanitizedGroup(classModel: Type) {
@@ -26,7 +25,7 @@ export default class ClassFileGeneratorHelper {
26
25
 
27
26
  private static getDirectoryRoot(classModel: Type) {
28
27
  // root-relative links start from the root by using a leading '/'
29
- if ((Settings.getInstance().typeTranspiler as MarkdownTranspilerBase).getLinkingStrategy() === 'root-relative') {
28
+ if (Settings.getInstance().typeTranspiler.getLinkingStrategy() === 'root-relative') {
30
29
  return `/${this.getSanitizedGroup(classModel)}/`;
31
30
  }
32
31
 
@@ -1,4 +1,5 @@
1
- import { LinkingStrategy, MarkdownTranspilerBase } from '../markdown-transpiler-base';
1
+ import { MarkdownTranspilerBase } from '../markdown-transpiler-base';
2
+ import { LinkingStrategy } from '../../processor-type-transpiler';
2
3
 
3
4
  export default class DocsifyDocsProcessor extends MarkdownTranspilerBase {
4
5
  homeFileName(): string {
@@ -1,7 +1,8 @@
1
- import { LinkingStrategy, MarkdownTranspilerBase } from '../markdown-transpiler-base';
1
+ import { MarkdownTranspilerBase } from '../markdown-transpiler-base';
2
2
  import { Type } from '@cparra/apex-reflection';
3
3
  import { MarkdownHomeFile } from '../../../model/markdown-home-file';
4
4
  import { MarkdownTypeFile } from '../../../model/markdown-type-file';
5
+ import { LinkingStrategy } from '../../processor-type-transpiler';
5
6
 
6
7
  export class JekyllDocsProcessor extends MarkdownTranspilerBase {
7
8
  homeFileName(): string {
@@ -4,8 +4,6 @@ import { FileContainer } from '../file-container';
4
4
  import { MarkdownHomeFile } from '../../model/markdown-home-file';
5
5
  import { MarkdownTypeFile } from '../../model/markdown-type-file';
6
6
 
7
- export type LinkingStrategy = 'root-relative' | 'path-relative';
8
-
9
7
  export abstract class MarkdownTranspilerBase extends ProcessorTypeTranspiler {
10
8
  protected readonly _fileContainer: FileContainer;
11
9
 
@@ -27,6 +25,4 @@ export abstract class MarkdownTranspilerBase extends ProcessorTypeTranspiler {
27
25
  onProcess(type: Type): void {
28
26
  this._fileContainer.pushFile(new MarkdownTypeFile(type));
29
27
  }
30
-
31
- abstract getLinkingStrategy(): LinkingStrategy;
32
28
  }
@@ -1,4 +1,5 @@
1
- import { LinkingStrategy, MarkdownTranspilerBase } from '../markdown-transpiler-base';
1
+ import { MarkdownTranspilerBase } from '../markdown-transpiler-base';
2
+ import { LinkingStrategy } from '../../processor-type-transpiler';
2
3
 
3
4
  export class PlainMarkdownDocsProcessor extends MarkdownTranspilerBase {
4
5
  homeFileName(): string {
@@ -1,6 +1,8 @@
1
1
  import { Type } from '@cparra/apex-reflection';
2
2
  import { FileContainer } from './file-container';
3
3
 
4
+ export type LinkingStrategy = 'root-relative' | 'path-relative';
5
+
4
6
  export default abstract class ProcessorTypeTranspiler {
5
7
  onBeforeProcess: ((types: Type[]) => void) | undefined;
6
8
 
@@ -9,4 +11,6 @@ export default abstract class ProcessorTypeTranspiler {
9
11
  onAfterProcess: ((types: Type[]) => void) | undefined;
10
12
 
11
13
  abstract fileBuilder(): FileContainer;
14
+
15
+ abstract getLinkingStrategy(): LinkingStrategy;
12
16
  }
@@ -0,0 +1,3 @@
1
+ export function truncate(str: string, n: number) {
2
+ return str.length > n ? str.substr(0, n - 1) + '&hellip;' : str;
3
+ }
@@ -1,3 +0,0 @@
1
- /**
2
- * @typedef {Object} GroupedClass Uses a block style apex doc
3
- */
@@ -1,11 +0,0 @@
1
- /**
2
- * @typedef {Object} SampleClass This is a class description. This class relates to {@link SampleInterface} But this {@link ClassThatDoesNotExist} does not exist. You can also link using this syntax <<SampleInterface>>
3
- * @property {number} AnotherProp This is a Decimal property.
4
- * @property {string} MyProp This is a String property.
5
- */
6
- /**
7
- * @typedef {Object} AnotherInnerClass Inner class belonging to SampleClass.
8
- */
9
- /**
10
- * @typedef {Object} InnerClass Inner class belonging to SampleClass.
11
- */
File without changes
@@ -1,26 +0,0 @@
1
- import { File } from './file';
2
- import { WalkerListener } from '../service/walkers/walker';
3
- import { ClassMirror, ConstructorMirror, EnumMirror, FieldMirror, InterfaceMirror, MethodMirror, PropertyMirror, Type } from '@cparra/apex-reflection';
4
- export default class TsDefinitionFile extends File implements WalkerListener {
5
- fileExtension(): string;
6
- constructor(typeMirror: Type);
7
- onConstructorDeclaration(className: string, constructors: ConstructorMirror[]): void;
8
- onFieldsDeclaration(fields: FieldMirror[]): void;
9
- onInnerClassesDeclaration(classes: ClassMirror[]): void;
10
- onInnerEnumsDeclaration(enums: EnumMirror[]): void;
11
- onInnerInterfacesDeclaration(interfaces: InterfaceMirror[]): void;
12
- onMethodsDeclaration(methods: MethodMirror[]): void;
13
- onPropertiesDeclaration(properties: PropertyMirror[]): void;
14
- onTypeDeclaration(typeMirror: Type): void;
15
- private addPropertiesAndFields;
16
- private addInnerClasses;
17
- addBlankLine(): void;
18
- initializeBlock(): void;
19
- finalizeBlock(): void;
20
- declareType(className: string, docDescription: string): void;
21
- declareProperty(propertyType: string, propertyName: string, docDescription: string): void;
22
- sanitizeApexPropertyToJavascript(propertyType: string): string;
23
- isListProperty(propertyType: string): true | undefined;
24
- extractTypeFromList(propertyType: string): string;
25
- replaceAll(sourceString: string, strReplace: string, strWith: string): string;
26
- }
@@ -1,137 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const file_1 = require("./file");
4
- const walker_factory_1 = require("../service/walkers/walker-factory");
5
- class TsDefinitionFile extends file_1.File {
6
- fileExtension() {
7
- return '.d.ts';
8
- }
9
- constructor(typeMirror) {
10
- super(typeMirror.name, '');
11
- const walker = walker_factory_1.WalkerFactory.get(typeMirror);
12
- walker.walk(this);
13
- }
14
- // eslint-disable-next-line @typescript-eslint/no-empty-function
15
- onConstructorDeclaration(className, constructors) { }
16
- // eslint-disable-next-line @typescript-eslint/no-empty-function
17
- onFieldsDeclaration(fields) { }
18
- // eslint-disable-next-line @typescript-eslint/no-empty-function
19
- onInnerClassesDeclaration(classes) { }
20
- // eslint-disable-next-line @typescript-eslint/no-empty-function
21
- onInnerEnumsDeclaration(enums) { }
22
- // eslint-disable-next-line @typescript-eslint/no-empty-function
23
- onInnerInterfacesDeclaration(interfaces) { }
24
- // eslint-disable-next-line @typescript-eslint/no-empty-function
25
- onMethodsDeclaration(methods) { }
26
- // eslint-disable-next-line @typescript-eslint/no-empty-function
27
- onPropertiesDeclaration(properties) { }
28
- onTypeDeclaration(typeMirror) {
29
- var _a, _b;
30
- this.initializeBlock();
31
- this.declareType(typeMirror.name, (_b = (_a = typeMirror.docComment) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : '');
32
- this.addPropertiesAndFields(typeMirror);
33
- // TODO: Auraenabled method support
34
- // TODO: Remember that methods with getX and setX lose the get and set
35
- // TODO: Classes that dont have any auraenabled things should be skipped
36
- this.finalizeBlock();
37
- this.addInnerClasses(typeMirror);
38
- }
39
- addPropertiesAndFields(typeMirror) {
40
- const classModel = typeMirror;
41
- if (classModel.properties.length === 0 && classModel.fields.length === 0) {
42
- return;
43
- }
44
- const propertiesAndFields = [...classModel.properties, ...classModel.fields].filter((e) => e.annotations.findIndex((a) => a.name === 'auraenabled') !== -1);
45
- propertiesAndFields
46
- .sort((propA, propB) => {
47
- if (propA.name < propB.name)
48
- return -1;
49
- if (propA.name > propB.name)
50
- return 1;
51
- return 0;
52
- })
53
- .forEach((propertyModel) => {
54
- var _a, _b;
55
- this.declareProperty(propertyModel.type, propertyModel.name, (_b = (_a = propertyModel.docComment) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : '');
56
- });
57
- }
58
- addInnerClasses(typeMirror) {
59
- const classModel = typeMirror;
60
- if (classModel.classes.length > 0) {
61
- classModel.classes
62
- .sort((classA, classB) => {
63
- if (classA.name < classB.name)
64
- return -1;
65
- if (classA.name > classB.name)
66
- return 1;
67
- return 0;
68
- })
69
- .forEach((innerClass) => {
70
- this.onTypeDeclaration(innerClass);
71
- });
72
- }
73
- }
74
- addBlankLine() {
75
- this._contents += '\n';
76
- }
77
- initializeBlock() {
78
- this._contents += '/**';
79
- this.addBlankLine();
80
- }
81
- finalizeBlock() {
82
- this._contents += ' */';
83
- this.addBlankLine();
84
- }
85
- declareType(className, docDescription) {
86
- this._contents += ` * @typedef {Object} ${className} ${docDescription}`;
87
- this.addBlankLine();
88
- }
89
- declareProperty(propertyType, propertyName, docDescription) {
90
- let sanitizedType;
91
- // First we check if we are dealing with a list
92
- if (this.isListProperty(propertyType)) {
93
- // If we are then we first extract the type from the list
94
- sanitizedType = this.extractTypeFromList(propertyType);
95
- // then sanitize it
96
- sanitizedType = this.sanitizeApexPropertyToJavascript(sanitizedType);
97
- // and then we add brackets ([])
98
- sanitizedType = sanitizedType + '[]';
99
- }
100
- else {
101
- sanitizedType = this.sanitizeApexPropertyToJavascript(propertyType);
102
- }
103
- this._contents += ` * @property {${sanitizedType}} ${propertyName} ${docDescription}`;
104
- this.addBlankLine();
105
- }
106
- sanitizeApexPropertyToJavascript(propertyType) {
107
- const lowerPropertyType = propertyType.toLowerCase();
108
- if (lowerPropertyType === 'decimal' || lowerPropertyType === 'integer' || lowerPropertyType === 'double') {
109
- return 'number';
110
- }
111
- if (lowerPropertyType === 'boolean' || lowerPropertyType === 'string') {
112
- // If it is a built-in type then we return the lower-cased version.
113
- return lowerPropertyType;
114
- }
115
- // Otherwise, we respect casing
116
- return propertyType;
117
- }
118
- isListProperty(propertyType) {
119
- const lowerPropertyType = propertyType.toLowerCase();
120
- if (lowerPropertyType.includes('<') && lowerPropertyType.includes('list')) {
121
- return true;
122
- }
123
- }
124
- extractTypeFromList(propertyType) {
125
- const propertyWithoutList = this.replaceAll(propertyType, 'list', '');
126
- return propertyWithoutList.replace('list', '').replace('<', '').replace('>', '');
127
- }
128
- // Case insensitive replace
129
- replaceAll(sourceString, strReplace, strWith) {
130
- // See http://stackoverflow.com/a/3561711/556609
131
- const esc = strReplace.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
132
- const reg = new RegExp(esc, 'ig');
133
- return sourceString.replace(reg, strWith);
134
- }
135
- }
136
- exports.default = TsDefinitionFile;
137
- //# sourceMappingURL=ts-definition-file.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ts-definition-file.js","sourceRoot":"","sources":["../../src/model/ts-definition-file.ts"],"names":[],"mappings":";;AAAA,iCAA8B;AAY9B,sEAAkE;AAElE,MAAqB,gBAAiB,SAAQ,WAAI;IAChD,aAAa;QACX,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,YAAY,UAAgB;QAC1B,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC3B,MAAM,MAAM,GAAG,8BAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC7C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IAED,gEAAgE;IAChE,wBAAwB,CAAC,SAAiB,EAAE,YAAiC,IAAS,CAAC;IAEvF,gEAAgE;IAChE,mBAAmB,CAAC,MAAqB,IAAS,CAAC;IAEnD,gEAAgE;IAChE,yBAAyB,CAAC,OAAsB,IAAS,CAAC;IAE1D,gEAAgE;IAChE,uBAAuB,CAAC,KAAmB,IAAS,CAAC;IAErD,gEAAgE;IAChE,4BAA4B,CAAC,UAA6B,IAAS,CAAC;IAEpE,gEAAgE;IAChE,oBAAoB,CAAC,OAAuB,IAAS,CAAC;IAEtD,gEAAgE;IAChE,uBAAuB,CAAC,UAA4B,IAAS,CAAC;IAE9D,iBAAiB,CAAC,UAAgB;;QAChC,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,cAAE,UAAU,CAAC,UAAU,0CAAE,WAAW,mCAAI,EAAE,CAAC,CAAC;QAC5E,IAAI,CAAC,sBAAsB,CAAC,UAAU,CAAC,CAAC;QACxC,mCAAmC;QACnC,sEAAsE;QACtE,wEAAwE;QACxE,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;IAC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}
@@ -1,9 +0,0 @@
1
- import ProcessorTypeTranspiler from '../processor-type-transpiler';
2
- import { Type } from '@cparra/apex-reflection';
3
- import { FileContainer } from '../file-container';
4
- export declare class TsTypesTranspiler extends ProcessorTypeTranspiler {
5
- protected readonly _fileContainer: FileContainer;
6
- constructor();
7
- fileBuilder(): FileContainer;
8
- onProcess(type: Type): void;
9
- }
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TsTypesTranspiler = void 0;
4
- const processor_type_transpiler_1 = require("../processor-type-transpiler");
5
- const file_container_1 = require("../file-container");
6
- const ts_definition_file_1 = require("../../model/ts-definition-file");
7
- class TsTypesTranspiler extends processor_type_transpiler_1.default {
8
- constructor() {
9
- super();
10
- this._fileContainer = new file_container_1.FileContainer();
11
- }
12
- fileBuilder() {
13
- return this._fileContainer;
14
- }
15
- onProcess(type) {
16
- if (type.type_name !== 'class') {
17
- return;
18
- }
19
- this._fileContainer.pushFile(new ts_definition_file_1.default(type));
20
- }
21
- }
22
- exports.TsTypesTranspiler = TsTypesTranspiler;
23
- //# sourceMappingURL=TsTypesTranspiler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TsTypesTranspiler.js","sourceRoot":"","sources":["../../../src/transpiler/ts-types/TsTypesTranspiler.ts"],"names":[],"mappings":";;;AAAA,4EAAmE;AAEnE,sDAAkD;AAClD,uEAA8D;AAE9D,MAAa,iBAAkB,SAAQ,mCAAuB;IAG5D;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,cAAc,GAAG,IAAI,8BAAa,EAAE,CAAC;IAC5C,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED,SAAS,CAAC,IAAU;QAClB,IAAI,IAAI,CAAC,SAAS,KAAK,OAAO,EAAE;YAC9B,OAAO;SACR;QACD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,4BAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF;AAlBD,8CAkBC"}