diff --git a/examples/vitepress/docs/.vitepress/sidebar.json b/examples/vitepress/docs/.vitepress/sidebar.json index 7feee65d..30ad720e 100644 --- a/examples/vitepress/docs/.vitepress/sidebar.json +++ b/examples/vitepress/docs/.vitepress/sidebar.json @@ -94,6 +94,10 @@ "text": "Sample_Custom_Setting__c", "link": "custom-objects/Sample_Custom_Setting__c.md" }, + { + "text": "Sample_Platform_Event__e", + "link": "custom-objects/Sample_Platform_Event__e.md" + }, { "text": "Speaker__c", "link": "custom-objects/Speaker__c.md" diff --git a/examples/vitepress/docs/changelog.md b/examples/vitepress/docs/changelog.md index 10f90bad..e3eb7b3f 100644 --- a/examples/vitepress/docs/changelog.md +++ b/examples/vitepress/docs/changelog.md @@ -71,6 +71,9 @@ Represents a line item on a sales order. Custom object for tracking sales orders. ### Sample_Custom_Setting__c +### Sample_Platform_Event__e + +Eu excepteur irure occaecat adipisicing anim non consequat deserunt ipsum id amet eu. Labore aliqua incididunt anim id in aliquip sit excepteur ad dolor irure incididunt. Ipsum eiusmod cillum ex ullamco minim eu nisi dolore ad velit consequat ullamco elit tempor. Occaecat aliquip ex mollit nostrud qui excepteur non commodo dolore ullamco ex voluptate ut. Culpa nostrud reprehenderit ipsum do. Sit deserunt sint occaecat duis eiusmod. Sunt laborum fugiat nulla. ### Speaker__c Represents a speaker at an event. diff --git a/examples/vitepress/docs/custom-objects/Sample_Platform_Event__e.md b/examples/vitepress/docs/custom-objects/Sample_Platform_Event__e.md new file mode 100644 index 00000000..9191325d --- /dev/null +++ b/examples/vitepress/docs/custom-objects/Sample_Platform_Event__e.md @@ -0,0 +1,37 @@ +--- +title: Sample_Platform_Event__e +--- + +# Sample Platform Event + +Eu excepteur irure occaecat adipisicing anim non consequat deserunt ipsum id amet eu. Labore aliqua incididunt anim id in aliquip sit excepteur ad dolor irure incididunt. Ipsum eiusmod cillum ex ullamco minim eu nisi dolore ad velit consequat ullamco elit tempor. Occaecat aliquip ex mollit nostrud qui excepteur non commodo dolore ullamco ex voluptate ut. Culpa nostrud reprehenderit ipsum do. Sit deserunt sint occaecat duis eiusmod. Sunt laborum fugiat nulla. + +## API Name +`Sample_Platform_Event__e` + +## Publish Behavior + +**Publish Immediately** + +## Fields +### Required Platform Event Field +**Required** + +**API Name** + +`apexdocs__Required_Platform_Event_Field__c` + +**Type** + +*Date* + +--- +### Sample Platform Event Field + +**API Name** + +`apexdocs__Sample_Platform_Event_Field__c` + +**Type** + +*Text* \ No newline at end of file diff --git a/examples/vitepress/docs/index.md b/examples/vitepress/docs/index.md index 26683c81..b126b3b5 100644 --- a/examples/vitepress/docs/index.md +++ b/examples/vitepress/docs/index.md @@ -47,6 +47,10 @@ Represents a line item on a sales order. ### [Sample_Custom_Setting__c](custom-objects/Sample_Custom_Setting__c) +### [Sample_Platform_Event__e](custom-objects/Sample_Platform_Event__e) + +Eu excepteur irure occaecat adipisicing anim non consequat deserunt ipsum id amet eu. Labore aliqua incididunt anim id in aliquip sit excepteur ad dolor irure incididunt. Ipsum eiusmod cillum ex ullamco minim eu nisi dolore ad velit consequat ullamco elit tempor. Occaecat aliquip ex mollit nostrud qui excepteur non commodo dolore ullamco ex voluptate ut. Culpa nostrud reprehenderit ipsum do. Sit deserunt sint occaecat duis eiusmod. Sunt laborum fugiat nulla. + ### [Speaker__c](custom-objects/Speaker__c) Represents a speaker at an event. diff --git a/examples/vitepress/force-app/main/default/objects/Sample_Platform_Event__e/Sample_Platform_Event__e.object-meta.xml b/examples/vitepress/force-app/main/default/objects/Sample_Platform_Event__e/Sample_Platform_Event__e.object-meta.xml new file mode 100644 index 00000000..b4725341 --- /dev/null +++ b/examples/vitepress/force-app/main/default/objects/Sample_Platform_Event__e/Sample_Platform_Event__e.object-meta.xml @@ -0,0 +1,9 @@ + + + Deployed + Eu excepteur irure occaecat adipisicing anim non consequat deserunt ipsum id amet eu. Labore aliqua incididunt anim id in aliquip sit excepteur ad dolor irure incididunt. Ipsum eiusmod cillum ex ullamco minim eu nisi dolore ad velit consequat ullamco elit tempor. Occaecat aliquip ex mollit nostrud qui excepteur non commodo dolore ullamco ex voluptate ut. Culpa nostrud reprehenderit ipsum do. Sit deserunt sint occaecat duis eiusmod. Sunt laborum fugiat nulla. + HighVolume + + Sample Platform Events + PublishImmediately + diff --git a/examples/vitepress/force-app/main/default/objects/Sample_Platform_Event__e/fields/Required_Platform_Event_Field__c.field-meta.xml b/examples/vitepress/force-app/main/default/objects/Sample_Platform_Event__e/fields/Required_Platform_Event_Field__c.field-meta.xml new file mode 100644 index 00000000..d3d1847d --- /dev/null +++ b/examples/vitepress/force-app/main/default/objects/Sample_Platform_Event__e/fields/Required_Platform_Event_Field__c.field-meta.xml @@ -0,0 +1,11 @@ + + + Required_Platform_Event_Field__c + false + false + false + false + + true + Date + diff --git a/examples/vitepress/force-app/main/default/objects/Sample_Platform_Event__e/fields/Sample_Platform_Event_Field__c.field-meta.xml b/examples/vitepress/force-app/main/default/objects/Sample_Platform_Event__e/fields/Sample_Platform_Event_Field__c.field-meta.xml new file mode 100644 index 00000000..04a0ad1d --- /dev/null +++ b/examples/vitepress/force-app/main/default/objects/Sample_Platform_Event__e/fields/Sample_Platform_Event_Field__c.field-meta.xml @@ -0,0 +1,13 @@ + + + Sample_Platform_Event_Field__c + false + false + false + false + + 255 + false + Text + false + diff --git a/src/core/markdown/__test__/generating-custom-object-docs.spec.ts b/src/core/markdown/__test__/generating-custom-object-docs.spec.ts index 572c2901..a9c3b10c 100644 --- a/src/core/markdown/__test__/generating-custom-object-docs.spec.ts +++ b/src/core/markdown/__test__/generating-custom-object-docs.spec.ts @@ -6,6 +6,7 @@ import { unparsedFieldBundleFromRawString, } from '../../test-helpers/test-data-builders'; import { CustomObjectXmlBuilder } from '../../test-helpers/test-data-builders/custom-object-xml-builder'; +import { PlatformEventXmlBuilder } from '../../test-helpers/test-data-builders/platform-event-xml-builder'; describe('Generates Custom Object documentation', () => { beforeAll(() => { @@ -207,5 +208,29 @@ describe('Generates Custom Object documentation', () => { assertEither(result, (data) => expect(data).firstDocContains('TestObject.TestField__c')); }); }); + + describe('when documenting Platform Events', () => { + test('displays the publish behavior (publish immediately)', async () => { + const customObjectBundle = unparsedObjectBundleFromRawString({ + rawContent: new PlatformEventXmlBuilder().build(), + filePath: 'src/object/TestObject__e.object-meta.xml', + }); + + const result = await generateDocs([customObjectBundle])(); + expect(result).documentationBundleHasLength(1); + assertEither(result, (data) => expect(data).firstDocContains('Publish Immediately')); + }); + + test('displays the publish behavior (publish after commit)', async () => { + const customObjectBundle = unparsedObjectBundleFromRawString({ + rawContent: new PlatformEventXmlBuilder().withPublishBehavior('PublishAfterCommit').build(), + filePath: 'src/object/TestObject__e.object-meta.xml', + }); + + const result = await generateDocs([customObjectBundle])(); + expect(result).documentationBundleHasLength(1); + assertEither(result, (data) => expect(data).firstDocContains('Publish After Commit')); + }); + }); }); }); diff --git a/src/core/markdown/adapters/type-to-renderable.ts b/src/core/markdown/adapters/type-to-renderable.ts index 39220d51..b2642330 100644 --- a/src/core/markdown/adapters/type-to-renderable.ts +++ b/src/core/markdown/adapters/type-to-renderable.ts @@ -19,7 +19,7 @@ import { adaptConstructor, adaptMethod } from './methods-and-constructors'; import { adaptFieldOrProperty } from './fields-and-properties'; import { MarkdownGeneratorConfig } from '../generate-docs'; import { ExternalMetadata, SourceFileMetadata } from '../../shared/types'; -import { CustomObjectMetadata } from '../../reflection/sobject/reflect-custom-object-sources'; +import { CustomObjectMetadata, PublishBehavior } from '../../reflection/sobject/reflect-custom-object-sources'; import { getTypeGroup, isInSource } from '../../shared/utils'; import { CustomFieldMetadata } from '../../reflection/sobject/reflect-custom-field-source'; import { CustomMetadataMetadata } from '../../reflection/sobject/reflect-custom-metadata-source'; @@ -252,6 +252,17 @@ function objectMetadataToRenderable( objectMetadata: CustomObjectMetadata, config: MarkdownGeneratorConfig, ): RenderableCustomObject { + function toRenderablePublishBehavior(publishBehavior: PublishBehavior | undefined): string | null { + switch (publishBehavior) { + case 'PublishImmediately': + return 'Publish Immediately'; + case 'PublishAfterCommit': + return 'Publish After Commit'; + default: + return null; + } + } + return { type: 'customobject', headingLevel: 1, @@ -274,6 +285,7 @@ function objectMetadataToRenderable( heading: 'Records', value: objectMetadata.metadataRecords.map((metadata) => customMetadataToRenderable(metadata, 3)), }, + publishBehavior: toRenderablePublishBehavior(objectMetadata.publishBehavior), }; } diff --git a/src/core/markdown/templates/custom-object-template.ts b/src/core/markdown/templates/custom-object-template.ts index f33022fd..e427230e 100644 --- a/src/core/markdown/templates/custom-object-template.ts +++ b/src/core/markdown/templates/custom-object-template.ts @@ -6,6 +6,12 @@ export const customObjectTemplate = ` ## API Name \`{{apiName}}\` +{{#if publishBehavior}} +## Publish Behavior + +**{{publishBehavior}}** +{{/if}} + {{#if hasFields}} {{ heading fields.headingLevel fields.heading }} {{#each fields.value}} diff --git a/src/core/reflection/sobject/reflect-custom-object-sources.ts b/src/core/reflection/sobject/reflect-custom-object-sources.ts index 5654d6e8..aea2eb53 100644 --- a/src/core/reflection/sobject/reflect-custom-object-sources.ts +++ b/src/core/reflection/sobject/reflect-custom-object-sources.ts @@ -11,6 +11,8 @@ import { CustomFieldMetadata } from './reflect-custom-field-source'; import { getPickListValues } from './parse-picklist-values'; import { CustomMetadataMetadata } from './reflect-custom-metadata-source'; +export type PublishBehavior = 'PublishImmediately' | 'PublishAfterCommit'; + export type CustomObjectMetadata = { type_name: 'customobject'; deploymentStatus: string; @@ -20,6 +22,7 @@ export type CustomObjectMetadata = { description: string | null; fields: CustomFieldMetadata[]; metadataRecords: CustomMetadataMetadata[]; + publishBehavior?: PublishBehavior; }; export function reflectCustomObjectSources( diff --git a/src/core/renderables/types.d.ts b/src/core/renderables/types.d.ts index 5f1bd03a..5df71721 100644 --- a/src/core/renderables/types.d.ts +++ b/src/core/renderables/types.d.ts @@ -184,6 +184,7 @@ export type RenderableCustomObject = Omit & { hasRecords: boolean; fields: RenderableSection; metadataRecords: RenderableSection; + publishBehavior: string | null; }; export type RenderableCustomField = { diff --git a/src/core/test-helpers/test-data-builders/platform-event-xml-builder.ts b/src/core/test-helpers/test-data-builders/platform-event-xml-builder.ts new file mode 100644 index 00000000..f35860f9 --- /dev/null +++ b/src/core/test-helpers/test-data-builders/platform-event-xml-builder.ts @@ -0,0 +1,26 @@ +import { PublishBehavior } from '../../reflection/sobject/reflect-custom-object-sources'; + +export class PlatformEventXmlBuilder { + deploymentStatus = 'Deployed'; + publishBehavior: PublishBehavior = 'PublishImmediately'; + label = 'MyTestObject'; + + withPublishBehavior(publishBehavior: PublishBehavior): PlatformEventXmlBuilder { + this.publishBehavior = publishBehavior; + return this; + } + + build(): string { + return ` + + + ${this.deploymentStatus} + Eu exceptincididunt anicat aut + HighVolume + + Sample Platform Events + ${this.publishBehavior} + + `; + } +}