@actor-system/spawn-protocol 0.0.1
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/behavior.d.ts +6 -0
- package/dist/behavior.internal.d.ts +6 -0
- package/dist/behavior.js +13 -0
- package/dist/command.d.ts +17 -0
- package/dist/command.internal.d.ts +17 -0
- package/dist/command.js +14 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.internal.d.ts +4 -0
- package/dist/index.js +3 -0
- package/package.json +44 -0
package/dist/behavior.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { receive, same } from '@actor-system/behaviors';
|
|
2
|
+
import { isSpawn } from './command.js';
|
|
3
|
+
|
|
4
|
+
const behavior = () => receive((msg, context) => {
|
|
5
|
+
if (!isSpawn(msg))
|
|
6
|
+
return same;
|
|
7
|
+
const { behavior, name, replyTo } = msg;
|
|
8
|
+
const actorRef = context.spawn(behavior, name);
|
|
9
|
+
replyTo.tell(actorRef);
|
|
10
|
+
return same;
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export { behavior };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ActorProps, Behavior, ActorRef } from '@actor-system/core';
|
|
2
|
+
import { Letter } from '@actor-system/mail';
|
|
3
|
+
|
|
4
|
+
type Command<T = unknown> = Spawn<T>;
|
|
5
|
+
interface Spawn<T> extends Letter<typeof $spawn> {
|
|
6
|
+
readonly name?: string;
|
|
7
|
+
readonly props?: ActorProps;
|
|
8
|
+
readonly behavior: Behavior<T>;
|
|
9
|
+
readonly replyTo: ActorRef<ActorRef<T>>;
|
|
10
|
+
}
|
|
11
|
+
declare const $spawn: "spawn";
|
|
12
|
+
declare const spawn: <T>({ name, props, replyTo, behavior, }: Letter.ExcludeLabel<Spawn<T>>) => Spawn<T>;
|
|
13
|
+
declare const isSpawn: <T>(value: unknown) => value is Spawn<T>;
|
|
14
|
+
declare const isCommand: <T>(value: unknown) => value is Command<T>;
|
|
15
|
+
|
|
16
|
+
export { $spawn, isCommand, isSpawn, spawn };
|
|
17
|
+
export type { Command, Spawn };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ActorProps, Behavior, ActorRef } from '@actor-system/core/internal';
|
|
2
|
+
import { Letter } from '@actor-system/mail/internal';
|
|
3
|
+
|
|
4
|
+
type Command<T = unknown> = Spawn<T>;
|
|
5
|
+
interface Spawn<T> extends Letter<typeof $spawn> {
|
|
6
|
+
readonly name?: string;
|
|
7
|
+
readonly props?: ActorProps;
|
|
8
|
+
readonly behavior: Behavior<T>;
|
|
9
|
+
readonly replyTo: ActorRef<ActorRef<T>>;
|
|
10
|
+
}
|
|
11
|
+
declare const $spawn: "spawn";
|
|
12
|
+
declare const spawn: <T>({ name, props, replyTo, behavior, }: Letter.ExcludeLabel<Spawn<T>>) => Spawn<T>;
|
|
13
|
+
declare const isSpawn: <T>(value: unknown) => value is Spawn<T>;
|
|
14
|
+
declare const isCommand: <T>(value: unknown) => value is Command<T>;
|
|
15
|
+
|
|
16
|
+
export { $spawn, isCommand, isSpawn, spawn };
|
|
17
|
+
export type { Command, Spawn };
|
package/dist/command.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { letterGuard } from '@actor-system/mail';
|
|
2
|
+
|
|
3
|
+
const $spawn = "spawn";
|
|
4
|
+
const spawn = ({ name, props, replyTo, behavior, }) => ({
|
|
5
|
+
name,
|
|
6
|
+
props,
|
|
7
|
+
replyTo,
|
|
8
|
+
behavior,
|
|
9
|
+
label: $spawn,
|
|
10
|
+
});
|
|
11
|
+
const isSpawn = letterGuard($spawn);
|
|
12
|
+
const isCommand = letterGuard($spawn);
|
|
13
|
+
|
|
14
|
+
export { $spawn, isCommand, isSpawn, spawn };
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@actor-system/spawn-protocol",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"type-check": "tsc -b src",
|
|
7
|
+
"lint": "eslint src",
|
|
8
|
+
"lint:fix": "eslint src --fix",
|
|
9
|
+
"publint": "publint",
|
|
10
|
+
"build:tsc:internal": "tsc -b src/tsconfig.lib.json",
|
|
11
|
+
"build:tsc:trimmed": "tsc -b src/tsconfig.lib.trimmed.json",
|
|
12
|
+
"build:rollup": "rollup -c node:config/rollup-config"
|
|
13
|
+
},
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./internal": {
|
|
26
|
+
"types": "./dist/index.internal.d.ts",
|
|
27
|
+
"import": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"bundleDependencies": [
|
|
32
|
+
"@actor-system/shared"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@actor-system/behaviors": "0.0.1",
|
|
36
|
+
"@actor-system/core": "0.0.1",
|
|
37
|
+
"@actor-system/mail": "0.0.1"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@actor-system/testing": "0.0.1",
|
|
41
|
+
"@actor-system/shared": "0.0.1",
|
|
42
|
+
"config": "^1.0.0"
|
|
43
|
+
}
|
|
44
|
+
}
|