diff --git a/package-lock.json b/package-lock.json index 58a929c..374a8e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "durable-functions", - "version": "2.0.1", + "version": "2.0.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "durable-functions", - "version": "2.0.1", + "version": "2.0.2", "license": "MIT", "dependencies": { "@azure/functions": "^1.2.3", diff --git a/package.json b/package.json index d9a7f16..5648519 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "durable-functions", - "version": "2.0.1", + "version": "2.0.2", "description": "Durable Functions library for Node.js Azure Functions", "license": "MIT", "repository": { diff --git a/src/durableentitybindinginfo.ts b/src/durableentitybindinginfo.ts index a996f5a..17f66bc 100644 --- a/src/durableentitybindinginfo.ts +++ b/src/durableentitybindinginfo.ts @@ -1,11 +1,22 @@ import { EntityId, RequestMessage } from "./classes"; /** @hidden */ -export class DurableEntityBindingInfo { +export class DurableEntityBindingInfoReqFields { constructor( public readonly self: EntityId, public readonly exists: boolean, - public readonly state: string | undefined, public readonly batch: RequestMessage[] ) {} } + +/** @hidden */ +export class DurableEntityBindingInfo extends DurableEntityBindingInfoReqFields { + constructor( + public readonly self: EntityId, + public readonly exists: boolean, + public readonly state: string | undefined, + public readonly batch: RequestMessage[] + ) { + super(self, exists, batch); + } +} diff --git a/src/durableorchestrationbindinginfo.ts b/src/durableorchestrationbindinginfo.ts index 2896ff1..17db123 100644 --- a/src/durableorchestrationbindinginfo.ts +++ b/src/durableorchestrationbindinginfo.ts @@ -1,8 +1,18 @@ import { HistoryEvent } from "./classes"; -import { LatestReplaySchema, ReplaySchema } from "./replaySchema"; +import { ReplaySchema } from "./replaySchema"; /** @hidden */ -export class DurableOrchestrationBindingInfo { +export class DurableOrchestrationBindingInfoReqFields { + constructor( + public readonly history: HistoryEvent[] = [], + public readonly instanceId: string = "", + public readonly isReplaying: boolean = false, + public readonly upperSchemaVersion: ReplaySchema = ReplaySchema.V1 // TODO: Implement entity locking // public readonly contextLocks?: EntityId[], + ) {} +} + +/** @hidden */ +export class DurableOrchestrationBindingInfo extends DurableOrchestrationBindingInfoReqFields { public readonly upperSchemaVersionNew?: ReplaySchema; constructor( @@ -15,5 +25,7 @@ export class DurableOrchestrationBindingInfo { public readonly longRunningTimerIntervalDuration?: string, public readonly defaultHttpAsyncRequestSleepTimeMillseconds?: number, public readonly upperSchemaVersion: ReplaySchema = ReplaySchema.V1 // TODO: Implement entity locking // public readonly contextLocks?: EntityId[], - ) {} + ) { + super(history, instanceId, isReplaying, upperSchemaVersion); + } } diff --git a/src/entity.ts b/src/entity.ts index 24dfb45..5a07207 100644 --- a/src/entity.ts +++ b/src/entity.ts @@ -10,6 +10,7 @@ import { Signal, Utils, } from "./classes"; +import { DurableEntityBindingInfoReqFields } from "./durableentitybindinginfo"; /** @hidden */ // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -26,7 +27,11 @@ export class Entity { private async handle(context: IEntityFunctionContext): Promise { const entityBinding = Utils.getInstancesOf( context.bindings, - new DurableEntityBindingInfo(new EntityId("samplename", "samplekey"), true, "", []) + new DurableEntityBindingInfoReqFields( + new EntityId("samplename", "samplekey"), + true, + [] + ) as DurableEntityBindingInfo )[0]; if (entityBinding === undefined) { diff --git a/src/orchestrator.ts b/src/orchestrator.ts index 4f350c2..8a5b982 100644 --- a/src/orchestrator.ts +++ b/src/orchestrator.ts @@ -8,6 +8,7 @@ import { import { DurableOrchestrationContext } from "./durableorchestrationcontext"; import { TaskOrchestrationExecutor } from "./taskorchestrationexecutor"; import { LatestReplaySchema, ReplaySchema } from "./replaySchema"; +import { DurableOrchestrationBindingInfoReqFields } from "./durableorchestrationbindinginfo"; /** @hidden */ export class Orchestrator { @@ -28,7 +29,7 @@ export class Orchestrator { this.taskOrchestrationExecutor = new TaskOrchestrationExecutor(); const orchestrationBinding = Utils.getInstancesOf( context.bindings, - new DurableOrchestrationBindingInfo() + new DurableOrchestrationBindingInfoReqFields() as DurableOrchestrationBindingInfo )[0]; if (!orchestrationBinding) { diff --git a/src/utils.ts b/src/utils.ts index d65b2d0..6c296e3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -12,11 +12,11 @@ export class Utils { } public static getInstancesOf( collection: { [index: string]: unknown }, - typeInstance: T + abstractClass: T // this should be an abstract class that contains only the _required_ properties ): T[] { - if (collection && typeInstance) { + if (collection && abstractClass) { const candidateObjects = Object.values(collection).filter((value) => - this.hasAllPropertiesOf(value, typeInstance) + this.hasAllPropertiesOf(value, abstractClass) ); this.parseTimestampsAsDates(candidateObjects);