Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/vitepress/docs/.vitepress/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions examples/vitepress/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
37 changes: 37 additions & 0 deletions examples/vitepress/docs/custom-objects/Sample_Platform_Event__e.md
Original file line number Diff line number Diff line change
@@ -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*
4 changes: 4 additions & 0 deletions examples/vitepress/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<deploymentStatus>Deployed</deploymentStatus>
<description>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.</description>
<eventType>HighVolume</eventType>
<label>Sample Platform Event</label>
<pluralLabel>Sample Platform Events</pluralLabel>
<publishBehavior>PublishImmediately</publishBehavior>
</CustomObject>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Required_Platform_Event_Field__c</fullName>
<externalId>false</externalId>
<isFilteringDisabled>false</isFilteringDisabled>
<isNameField>false</isNameField>
<isSortingDisabled>false</isSortingDisabled>
<label>Required Platform Event Field</label>
<required>true</required>
<type>Date</type>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Sample_Platform_Event_Field__c</fullName>
<externalId>false</externalId>
<isFilteringDisabled>false</isFilteringDisabled>
<isNameField>false</isNameField>
<isSortingDisabled>false</isSortingDisabled>
<label>Sample Platform Event Field</label>
<length>255</length>
<required>false</required>
<type>Text</type>
<unique>false</unique>
</CustomField>
25 changes: 25 additions & 0 deletions src/core/markdown/__test__/generating-custom-object-docs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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'));
});
});
});
});
14 changes: 13 additions & 1 deletion src/core/markdown/adapters/type-to-renderable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -274,6 +285,7 @@ function objectMetadataToRenderable(
heading: 'Records',
value: objectMetadata.metadataRecords.map((metadata) => customMetadataToRenderable(metadata, 3)),
},
publishBehavior: toRenderablePublishBehavior(objectMetadata.publishBehavior),
};
}

Expand Down
6 changes: 6 additions & 0 deletions src/core/markdown/templates/custom-object-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
3 changes: 3 additions & 0 deletions src/core/reflection/sobject/reflect-custom-object-sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +22,7 @@ export type CustomObjectMetadata = {
description: string | null;
fields: CustomFieldMetadata[];
metadataRecords: CustomMetadataMetadata[];
publishBehavior?: PublishBehavior;
};

export function reflectCustomObjectSources(
Expand Down
1 change: 1 addition & 0 deletions src/core/renderables/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export type RenderableCustomObject = Omit<RenderableType, 'meta'> & {
hasRecords: boolean;
fields: RenderableSection<RenderableCustomField[]>;
metadataRecords: RenderableSection<RenderableCustomMetadata[]>;
publishBehavior: string | null;
};

export type RenderableCustomField = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 `
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<deploymentStatus>${this.deploymentStatus}</deploymentStatus>
<description>Eu exceptincididunt anicat aut</description>
<eventType>HighVolume</eventType>
<label>${this.label}</label>
<pluralLabel>Sample Platform Events</pluralLabel>
<publishBehavior>${this.publishBehavior}</publishBehavior>
</CustomObject>
`;
}
}