Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch for getInstancesOf #369

Merged
merged 4 commits into from
Jun 3, 2022
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: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
15 changes: 13 additions & 2 deletions src/durableentitybindinginfo.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
18 changes: 15 additions & 3 deletions src/durableorchestrationbindinginfo.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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);
}
}
7 changes: 6 additions & 1 deletion src/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Signal,
Utils,
} from "./classes";
import { DurableEntityBindingInfoReqFields } from "./durableentitybindinginfo";

/** @hidden */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -26,7 +27,11 @@ export class Entity<T> {
private async handle(context: IEntityFunctionContext<T>): Promise<void> {
const entityBinding = Utils.getInstancesOf<DurableEntityBindingInfo>(
context.bindings,
new DurableEntityBindingInfo(new EntityId("samplename", "samplekey"), true, "", [])
new DurableEntityBindingInfoReqFields(
new EntityId("samplename", "samplekey"),
true,
[]
) as DurableEntityBindingInfo
)[0];

if (entityBinding === undefined) {
Expand Down
3 changes: 2 additions & 1 deletion src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,7 +29,7 @@ export class Orchestrator {
this.taskOrchestrationExecutor = new TaskOrchestrationExecutor();
const orchestrationBinding = Utils.getInstancesOf<DurableOrchestrationBindingInfo>(
context.bindings,
new DurableOrchestrationBindingInfo()
new DurableOrchestrationBindingInfoReqFields() as DurableOrchestrationBindingInfo
)[0];

if (!orchestrationBinding) {
Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export class Utils {
}
public static getInstancesOf<T>(
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);
Expand Down