Skip to content

Commit

Permalink
feat(ns-workflows-1): add support for Step Object (#3471)
Browse files Browse the repository at this point in the history
Refs #3392
  • Loading branch information
frankkilcommins authored Dec 1, 2023
1 parent 29a4d51 commit c63021e
Show file tree
Hide file tree
Showing 26 changed files with 1,111 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/apidom-ns-workflows-1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Only fully implemented specification objects should be checked here.
- [x] [Info Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#info-object)
- [x] [Source Description Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#source-description-object)
- [ ] [Workflow Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#workflow-object)
- [ ] [Step Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#step-object)
- [x] [Step Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#step-object)
- [x] [Parameter Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#parameter-object)
- [x] [Success Action Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#success-action-object)
- [x] [Failure Action Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#failure-action-object)
Expand Down
104 changes: 104 additions & 0 deletions packages/apidom-ns-workflows-1/src/elements/Step.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import {
ObjectElement,
ArrayElement,
StringElement,
Attributes,
Meta,
} from '@swagger-api/apidom-core';

class Step extends ObjectElement {
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
this.element = 'step';
}

get description(): StringElement | undefined {
return this.get('description');
}

set description(description: StringElement | undefined) {
this.set('description', description);
}

get stepId(): StringElement | undefined {
return this.get('stepId');
}

set stepId(stepId: StringElement | undefined) {
this.set('stepId', stepId);
}

get operationId(): StringElement | undefined {
return this.get('operationId');
}

set operationId(operationId: StringElement | undefined) {
this.set('operationId', operationId);
}

get operationRef(): StringElement | undefined {
return this.get('operationRef');
}

set operationRef(operationRef: StringElement | undefined) {
this.set('operationRef', operationRef);
}

get workflowId(): StringElement | undefined {
return this.get('workflowId');
}

set workflowId(workflowId: StringElement | undefined) {
this.set('workflowId', workflowId);
}

get parameters(): ArrayElement | undefined {
return this.get('parameters');
}

set parameters(parameters: ArrayElement | undefined) {
this.set('parameters', parameters);
}

get dependsOn(): ArrayElement | undefined {
return this.get('dependsOn');
}

set dependsOn(dependsOn: ArrayElement | undefined) {
this.set('dependsOn', dependsOn);
}

get successCriteria(): ArrayElement | undefined {
return this.get('successCriteria');
}

set successCriteria(successCriteria: ArrayElement | undefined) {
this.set('successCriteria', successCriteria);
}

get onSuccess(): ArrayElement | undefined {
return this.get('onSuccess');
}

set onSuccess(onSuccess: ArrayElement | undefined) {
this.set('onSuccess', onSuccess);
}

get onFailure(): ArrayElement | undefined {
return this.get('onFailure');
}

set onFailure(onFailure: ArrayElement | undefined) {
this.set('onFailure', onFailure);
}

get outputs(): ObjectElement | undefined {
return this.get('outputs');
}

set outputs(outputs: ObjectElement | undefined) {
this.set('outputs', outputs);
}
}

export default Step;
12 changes: 12 additions & 0 deletions packages/apidom-ns-workflows-1/src/elements/nces/StepDependsOn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ArrayElement, Attributes, Meta } from '@swagger-api/apidom-core';

class StepDependsOn extends ArrayElement {
static primaryClass = 'step-depends-on';

constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
this.classes.push(StepDependsOn.primaryClass);
}
}

export default StepDependsOn;
12 changes: 12 additions & 0 deletions packages/apidom-ns-workflows-1/src/elements/nces/StepOnFailure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ArrayElement, Attributes, Meta } from '@swagger-api/apidom-core';

class StepOnFailure extends ArrayElement {
static primaryClass = 'step-on-failure';

constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
this.classes.push(StepOnFailure.primaryClass);
}
}

export default StepOnFailure;
12 changes: 12 additions & 0 deletions packages/apidom-ns-workflows-1/src/elements/nces/StepOnSuccess.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ArrayElement, Attributes, Meta } from '@swagger-api/apidom-core';

class StepOnSuccess extends ArrayElement {
static primaryClass = 'step-on-success';

constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
this.classes.push(StepOnSuccess.primaryClass);
}
}

export default StepOnSuccess;
12 changes: 12 additions & 0 deletions packages/apidom-ns-workflows-1/src/elements/nces/StepOutputs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ObjectElement, Attributes, Meta } from '@swagger-api/apidom-core';

class StepOutputs extends ObjectElement {
static primaryClass = 'step-outputs';

constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
this.classes.push(StepOutputs.primaryClass);
}
}

export default StepOutputs;
13 changes: 13 additions & 0 deletions packages/apidom-ns-workflows-1/src/elements/nces/StepParameters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ArrayElement, Attributes, Meta } from '@swagger-api/apidom-core';

class StepParameters extends ArrayElement {
static primaryClass = 'step-parameters';

constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
this.classes.push(StepParameters.primaryClass);
this.classes.push('parameters');
}
}

export default StepParameters;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ArrayElement, Attributes, Meta } from '@swagger-api/apidom-core';

class StepSuccessCriteria extends ArrayElement {
static primaryClass = 'step-success-criteria';

constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
this.classes.push(StepSuccessCriteria.primaryClass);
this.classes.push('criteria');
}
}

export default StepSuccessCriteria;
14 changes: 14 additions & 0 deletions packages/apidom-ns-workflows-1/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ export {
isInfoElement,
isSourceDescriptionElement,
isSourceDescriptionsElement,
isStepElement,
isStepParametersElement,
isStepDependsOnElement,
isStepSuccessCriteriaElement,
isStepOnSuccessElement,
isStepOnFailureElement,
isStepOutputsElement,
isParameterElement,
isSuccessActionElement,
isSuccessActionCriteriaElement,
Expand Down Expand Up @@ -55,6 +62,7 @@ export {
WorkflowsSpecElement,
InfoElement,
SourceDescriptionElement,
StepElement,
ParameterElement,
SuccessActionElement,
FailureActionElement,
Expand All @@ -65,6 +73,12 @@ export {
} from './refractor/registration';
// NCE types
export { default as SourceDescriptionsElement } from './elements/nces/SourceDescriptions';
export { default as StepParametersElement } from './elements/nces/StepParameters';
export { default as StepDependsOnElement } from './elements/nces/StepDependsOn';
export { default as StepSuccessCriteriaElement } from './elements/nces/StepSuccessCriteria';
export { default as StepOnSuccessElement } from './elements/nces/StepOnSuccess';
export { default as StepOnFailureElement } from './elements/nces/StepOnFailure';
export { default as StepOutputsElement } from './elements/nces/StepOutputs';
export { default as SuccessActionCriteriaElement } from './elements/nces/SuccessActionCriteria';
export { default as FailureActionCriteriaElement } from './elements/nces/FailureActionCriteria';
export { default as ComponentsSchemas } from './elements/nces/ComponentsInputs';
Expand Down
2 changes: 2 additions & 0 deletions packages/apidom-ns-workflows-1/src/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import WorkflowsSpecification1Element from './elements/WorkflowsSpecification1';
import WorkflowsSpecElement from './elements/WorkflowsSpec';
import InfoElement from './elements/Info';
import SourceDescriptionElement from './elements/SourceDescription';
import StepElement from './elements/Step';
import ParameterElement from './elements/Parameter';
import SuccessActionElement from './elements/SuccessAction';
import FailureActionElement from './elements/FailureAction';
Expand All @@ -20,6 +21,7 @@ const workflows1 = {
base.register('workflowsSpec', WorkflowsSpecElement);
base.register('info', InfoElement);
base.register('sourceDescription', SourceDescriptionElement);
base.register('step', StepElement);
base.register('parameter', ParameterElement);
base.register('successAction', SuccessActionElement);
base.register('failureAction', FailureActionElement);
Expand Down
84 changes: 84 additions & 0 deletions packages/apidom-ns-workflows-1/src/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import WorkflowsSpecification1Element from './elements/WorkflowsSpecification1';
import WorkflowsSpecElement from './elements/WorkflowsSpec';
import InfoElement from './elements/Info';
import SourceDescriptionElement from './elements/SourceDescription';
import StepElement from './elements/Step';
import ParameterElement from './elements/Parameter';
import SuccessActionElement from './elements/SuccessAction';
import FailureActionElement from './elements/FailureAction';
Expand All @@ -13,6 +14,12 @@ import ReferenceElement from './elements/Reference';
import JSONSchemaElement from './elements/JSONSchema';
// NCE types
import SourceDescriptionsElement from './elements/nces/SourceDescriptions';
import StepParametersElement from './elements/nces/StepParameters';
import StepDependsOnElement from './elements/nces/StepDependsOn';
import StepSuccessCriteriaElement from './elements/nces/StepSuccessCriteria';
import StepOnSuccessElement from './elements/nces/StepOnSuccess';
import StepOnFailureElement from './elements/nces/StepOnFailure';
import StepOutputsElement from './elements/nces/StepOutputs';
import SuccessActionCriteriaElement from './elements/nces/SuccessActionCriteria';
import FailureActionCriteriaElement from './elements/nces/FailureActionCriteria';

Expand Down Expand Up @@ -70,6 +77,83 @@ export const isSourceDescriptionsElement = createPredicate(
},
);

export const isStepOnSuccessElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
return (element: unknown): element is StepOnSuccessElement =>
element instanceof StepOnSuccessElement ||
(hasBasicElementProps(element) &&
isElementType('array', element) &&
primitiveEq('array', element) &&
hasClass('step-on-success', element));
},
);

export const isStepOnFailureElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
return (element: unknown): element is StepOnFailureElement =>
element instanceof StepOnFailureElement ||
(hasBasicElementProps(element) &&
isElementType('array', element) &&
primitiveEq('array', element) &&
hasClass('step-on-failure', element));
},
);

export const isStepOutputsElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
return (element: unknown): element is StepOutputsElement =>
element instanceof StepOutputsElement ||
(hasBasicElementProps(element) &&
isElementType('array', element) &&
primitiveEq('array', element) &&
hasClass('step-outputs', element));
},
);

export const isStepElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq }) => {
return (element: unknown): element is StepElement =>
element instanceof StepElement ||
(hasBasicElementProps(element) &&
isElementType('step', element) &&
primitiveEq('object', element));
},
);

export const isStepParametersElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
return (element: unknown): element is StepParametersElement =>
element instanceof StepParametersElement ||
(hasBasicElementProps(element) &&
isElementType('array', element) &&
primitiveEq('array', element) &&
hasClass('step-parameters', element));
},
);

export const isStepDependsOnElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
return (element: unknown): element is StepDependsOnElement =>
element instanceof StepDependsOnElement ||
(hasBasicElementProps(element) &&
isElementType('array', element) &&
primitiveEq('array', element) &&
hasClass('step-depends-on', element));
},
);

export const isStepSuccessCriteriaElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
return (element: unknown): element is StepSuccessCriteriaElement =>
element instanceof StepSuccessCriteriaElement ||
(hasBasicElementProps(element) &&
isElementType('array', element) &&
primitiveEq('array', element) &&
hasClass('step-success-criteria', element) &&
hasClass('criteria', element));
},
);

export const isParameterElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq }) => {
return (element: unknown): element is ParameterElement =>
Expand Down
16 changes: 15 additions & 1 deletion packages/apidom-ns-workflows-1/src/refractor/predicates.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import { startsWith } from 'ramda';
import { MemberElement, isStringElement, toValue } from '@swagger-api/apidom-core';
import {
MemberElement,
ObjectElement,
isStringElement,
toValue,
isObjectElement,
} from '@swagger-api/apidom-core';

export interface ReferenceLikeElement extends ObjectElement {
hasKey: (value: '$ref') => true;
}

// eslint-disable-next-line import/prefer-default-export
export const isWorkflowsSpecificationExtension = (element: MemberElement): boolean => {
// @ts-ignore
return isStringElement(element.key) && startsWith('x-', toValue(element.key));
};

export const isReferenceLikeElement = (element: unknown): element is ReferenceLikeElement => {
return isObjectElement(element) && element.hasKey('$ref');
};
3 changes: 3 additions & 0 deletions packages/apidom-ns-workflows-1/src/refractor/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import WorkflowsSpecification1Element from '../elements/WorkflowsSpecification1'
import WorkflowsSpecElement from '../elements/WorkflowsSpec';
import InfoElement from '../elements/Info';
import SourceDescriptionElement from '../elements/SourceDescription';
import StepElement from '../elements/Step';
import ParameterElement from '../elements/Parameter';
import SuccessActionElement from '../elements/SuccessAction';
import FailureActionElement from '../elements/FailureAction';
Expand Down Expand Up @@ -34,6 +35,7 @@ SourceDescriptionElement.refract = createRefractor([
'SourceDescription',
'$visitor',
]);
StepElement.refract = createRefractor(['visitors', 'document', 'objects', 'Step', '$visitor']);
ParameterElement.refract = createRefractor([
'visitors',
'document',
Expand Down Expand Up @@ -89,6 +91,7 @@ export {
WorkflowsSpecElement,
InfoElement,
SourceDescriptionElement,
StepElement,
ParameterElement,
SuccessActionElement,
FailureActionElement,
Expand Down
Loading

0 comments on commit c63021e

Please sign in to comment.