@rayondigital/nest-dapr 0.9.13 → 0.9.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actors/nest-actor-manager.d.ts +1 -0
- package/dist/actors/nest-actor-manager.js +39 -0
- package/dist/actors/stateful.actor.d.ts +1 -1
- package/dist/actors/stateful.actor.js +13 -10
- package/dist/dapr-actor-state.decorator.d.ts +2 -2
- package/dist/dapr.loader.js +1 -0
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import { DaprContextService } from '../dapr-context-service';
|
|
|
4
4
|
import { DaprModuleActorOptions } from '../dapr.module';
|
|
5
5
|
export declare class NestActorManager {
|
|
6
6
|
setup(moduleRef: ModuleRef, options: DaprModuleActorOptions, onActivateFn?: (actorId: ActorId, instance: AbstractActor) => Promise<void>): void;
|
|
7
|
+
setupRemindersAndTimers(): void;
|
|
7
8
|
setupReentrancy(): void;
|
|
8
9
|
setupCSLWrapper(contextService: DaprContextService, invokeWrapperFn?: (actorId: ActorId, methodName: string, data: any, method: (actorId: ActorId, methodName: string, data: any) => Promise<any>) => Promise<any>): void;
|
|
9
10
|
private resolveDependencies;
|
|
@@ -23,6 +23,8 @@ exports.NestActorManager = void 0;
|
|
|
23
23
|
const crypto_1 = require("crypto");
|
|
24
24
|
const ActorClientHTTP_1 = __importDefault(require("@dapr/dapr/actors/client/ActorClient/ActorClientHTTP"));
|
|
25
25
|
const ActorManager_1 = __importDefault(require("@dapr/dapr/actors/runtime/ActorManager"));
|
|
26
|
+
const ActorReminderData_1 = __importDefault(require("@dapr/dapr/actors/runtime/ActorReminderData"));
|
|
27
|
+
const ActorTimerData_1 = __importDefault(require("@dapr/dapr/actors/runtime/ActorTimerData"));
|
|
26
28
|
const common_1 = require("@nestjs/common");
|
|
27
29
|
const instance_wrapper_1 = require("@nestjs/core/injector/instance-wrapper");
|
|
28
30
|
const dapr_context_service_1 = require("../dapr-context-service");
|
|
@@ -50,6 +52,43 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
|
|
|
50
52
|
});
|
|
51
53
|
};
|
|
52
54
|
}
|
|
55
|
+
setupRemindersAndTimers() {
|
|
56
|
+
const originalFireReminder = ActorManager_1.default.prototype.fireReminder;
|
|
57
|
+
const originalFireTimer = ActorManager_1.default.prototype.fireTimer;
|
|
58
|
+
ActorManager_1.default.prototype.fireReminder = function (actorId, reminderName, requestBody) {
|
|
59
|
+
var _a;
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
try {
|
|
62
|
+
const requestBodyDeserialized = this.serializer.deserialize(requestBody || Buffer.from(''));
|
|
63
|
+
const reminderData = ActorReminderData_1.default.fromObject(reminderName, requestBodyDeserialized);
|
|
64
|
+
const reminderState = reminderData.state;
|
|
65
|
+
let methodName = 'receiveReminder';
|
|
66
|
+
if (reminderState !== undefined && typeof reminderState === 'object') {
|
|
67
|
+
methodName = (_a = reminderState === null || reminderState === void 0 ? void 0 : reminderState.callback) !== null && _a !== void 0 ? _a : reminderState.method;
|
|
68
|
+
}
|
|
69
|
+
return yield this.callActorMethod(actorId, methodName !== null && methodName !== void 0 ? methodName : 'receiveReminder', [reminderState, reminderName]);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
common_1.Logger.error(`Error firing reminder ${actorId}/${reminderName}`);
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
ActorManager_1.default.prototype.fireTimer = function (actorId, timerName, requestBody) {
|
|
78
|
+
var _a;
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
try {
|
|
81
|
+
const requestBodyDeserialized = this.serializer.deserialize(requestBody || Buffer.from(''));
|
|
82
|
+
const timerData = ActorTimerData_1.default.fromObject(timerName, requestBodyDeserialized);
|
|
83
|
+
return yield this.callActorMethod(actorId, (_a = timerData.callback) !== null && _a !== void 0 ? _a : 'handleTimer', [timerData.state, timerName]);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
common_1.Logger.error(`Error firing timer ${actorId}/${timerName}`);
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
}
|
|
53
92
|
setupReentrancy() {
|
|
54
93
|
ActorClientHTTP_1.default.prototype.invoke = function (actorType, actorId, methodName, body, reentrancyId) {
|
|
55
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -13,5 +13,5 @@ export declare class StatefulActor extends AbstractActor {
|
|
|
13
13
|
getAllState(): Promise<void>;
|
|
14
14
|
setAllStateFromProperties(): Promise<void>;
|
|
15
15
|
getState<T>(stateName: string, defaultValue?: T): Promise<T | undefined>;
|
|
16
|
-
private
|
|
16
|
+
private createStatePropertyInstance;
|
|
17
17
|
}
|
|
@@ -59,18 +59,12 @@ class StatefulActor extends dapr_1.AbstractActor {
|
|
|
59
59
|
this[property.key] = property.defaultValue;
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
|
-
this[property.key] = this.
|
|
62
|
+
this[property.key] = this.createStatePropertyInstance(property);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
66
66
|
if (property.serializable) {
|
|
67
|
-
|
|
68
|
-
if (typeof property.defaultValue === 'function') {
|
|
69
|
-
instance = property.defaultValue();
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
instance = this.createInstance(property.type);
|
|
73
|
-
}
|
|
67
|
+
const instance = this.createStatePropertyInstance(property);
|
|
74
68
|
this[property.key] = (_a = instance.fromJSON(rawValue)) !== null && _a !== void 0 ? _a : instance;
|
|
75
69
|
}
|
|
76
70
|
else {
|
|
@@ -110,9 +104,18 @@ class StatefulActor extends dapr_1.AbstractActor {
|
|
|
110
104
|
}
|
|
111
105
|
});
|
|
112
106
|
}
|
|
113
|
-
|
|
107
|
+
createStatePropertyInstance(property) {
|
|
114
108
|
try {
|
|
115
|
-
|
|
109
|
+
if (property.defaultValue !== undefined) {
|
|
110
|
+
if (property.defaultValue instanceof Function || typeof property.defaultValue === 'function') {
|
|
111
|
+
return property.defaultValue();
|
|
112
|
+
}
|
|
113
|
+
return property.defaultValue;
|
|
114
|
+
}
|
|
115
|
+
if (property.type || property.serializable) {
|
|
116
|
+
const type = property.type;
|
|
117
|
+
return new type();
|
|
118
|
+
}
|
|
116
119
|
}
|
|
117
120
|
catch (e) {
|
|
118
121
|
return undefined;
|
|
@@ -3,10 +3,10 @@ export interface StateProperty {
|
|
|
3
3
|
key: string | symbol;
|
|
4
4
|
name: string;
|
|
5
5
|
type: Function | Type<any>;
|
|
6
|
-
defaultValue?: any
|
|
6
|
+
defaultValue?: (() => any) | Function | Type<any>;
|
|
7
7
|
serializable?: boolean;
|
|
8
8
|
}
|
|
9
9
|
export declare function State(options?: {
|
|
10
|
-
defaultValue?: any
|
|
10
|
+
defaultValue?: (() => any) | Function | Type<any>;
|
|
11
11
|
name?: string;
|
|
12
12
|
}): PropertyDecorator;
|
package/dist/dapr.loader.js
CHANGED
|
@@ -57,6 +57,7 @@ let DaprLoader = DaprLoader_1 = class DaprLoader {
|
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
59
|
this.actorManager.setup(this.moduleRef, this.options.actorOptions);
|
|
60
|
+
this.actorManager.setupRemindersAndTimers();
|
|
60
61
|
if (this.options.contextProvider !== dapr_module_1.DaprContextProvider.None) {
|
|
61
62
|
this.actorManager.setupCSLWrapper(this.contextService);
|
|
62
63
|
}
|
package/package.json
CHANGED