From a36c8a790d9d57ff752c57a1501bc45fd6f72e96 Mon Sep 17 00:00:00 2001 From: JBBianchi Date: Wed, 29 Nov 2023 16:41:17 +0100 Subject: [PATCH] fix(integration): fixed typo in DataTransferObject & added json patch --- .../src/lib/data-transfer-object.ts | 2 +- .../integration/src/lib/entity-dto.ts | 4 ++-- .../neuroglia/integration/src/lib/index.ts | 2 ++ .../integration/src/lib/integration-event.ts | 4 ++-- .../integration/src/lib/json-patch.ts | 14 ++++++++++++++ .../integration/src/lib/patch-operation.ts | 18 ++++++++++++++++++ 6 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 projects/neuroglia/integration/src/lib/json-patch.ts create mode 100644 projects/neuroglia/integration/src/lib/patch-operation.ts diff --git a/projects/neuroglia/integration/src/lib/data-transfer-object.ts b/projects/neuroglia/integration/src/lib/data-transfer-object.ts index 2cec774..7b7a89e 100644 --- a/projects/neuroglia/integration/src/lib/data-transfer-object.ts +++ b/projects/neuroglia/integration/src/lib/data-transfer-object.ts @@ -3,7 +3,7 @@ import { ModelConstructor } from '@neuroglia/common'; /** * Represents the base class of all Data Transfer Objects (DTOs) */ -export abstract class DataTransfertObject extends ModelConstructor { +export abstract class DataTransferObject extends ModelConstructor { constructor(model?: any) { super(model); } diff --git a/projects/neuroglia/integration/src/lib/entity-dto.ts b/projects/neuroglia/integration/src/lib/entity-dto.ts index 2c7af14..6662472 100644 --- a/projects/neuroglia/integration/src/lib/entity-dto.ts +++ b/projects/neuroglia/integration/src/lib/entity-dto.ts @@ -1,9 +1,9 @@ -import { DataTransfertObject } from './data-transfer-object'; +import { DataTransferObject } from './data-transfer-object'; /** * Represents the base class for Data Transfer Objects used to describe an entity */ -export class EntityDataTransferObject extends DataTransfertObject { +export class EntityDataTransferObject extends DataTransferObject { constructor(model?: any) { super(model); } diff --git a/projects/neuroglia/integration/src/lib/index.ts b/projects/neuroglia/integration/src/lib/index.ts index ebbf860..3a296c9 100644 --- a/projects/neuroglia/integration/src/lib/index.ts +++ b/projects/neuroglia/integration/src/lib/index.ts @@ -4,3 +4,5 @@ export * from './command-dto'; export * from './aggregate-state-dto'; export * from './integration-event.interface'; export * from './integration-event'; +export * from './patch-operation'; +export * from './json-patch'; diff --git a/projects/neuroglia/integration/src/lib/integration-event.ts b/projects/neuroglia/integration/src/lib/integration-event.ts index 123e7b8..ca23a5f 100644 --- a/projects/neuroglia/integration/src/lib/integration-event.ts +++ b/projects/neuroglia/integration/src/lib/integration-event.ts @@ -1,10 +1,10 @@ -import { DataTransfertObject } from './data-transfer-object'; +import { DataTransferObject } from './data-transfer-object'; import { IIntegrationEvent } from './integration-event.interface'; /** * Represents the base class for all integration events */ -export class IntergrationEvent extends DataTransfertObject implements IIntegrationEvent { +export class IntergrationEvent extends DataTransferObject implements IIntegrationEvent { constructor(model?: any) { super(model); } diff --git a/projects/neuroglia/integration/src/lib/json-patch.ts b/projects/neuroglia/integration/src/lib/json-patch.ts new file mode 100644 index 0000000..40ff897 --- /dev/null +++ b/projects/neuroglia/integration/src/lib/json-patch.ts @@ -0,0 +1,14 @@ +import { ModelConstructor } from '@neuroglia/common'; +import { PatchOperation } from './patch-operation'; + +/** + * Models a JSON Patch document. + */ +export class JsonPatch extends ModelConstructor { + constructor(model?: any) { + super(model); + this.operations = (model?.operations || []).map((operation: PatchOperation) => new PatchOperation(operation)); + } + /** The collection of operations. */ + operations: PatchOperation[]; +} diff --git a/projects/neuroglia/integration/src/lib/patch-operation.ts b/projects/neuroglia/integration/src/lib/patch-operation.ts new file mode 100644 index 0000000..0bad1d4 --- /dev/null +++ b/projects/neuroglia/integration/src/lib/patch-operation.ts @@ -0,0 +1,18 @@ +import { ModelConstructor } from '@neuroglia/common'; + +/** + * Represents a single JSON Patch operation. + */ +export class PatchOperation extends ModelConstructor { + constructor(model?: any) { + super(model); + } + /** The operation type */ + op: 'add' | 'remove' | 'replace' | 'move' | 'copy' | 'test'; + /** The source path */ + from: string; + /** The target path */ + path: string; + /** The value */ + value: any; +}