@adobe/data 0.9.21 → 0.9.23
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/ecs/database/database.d.ts +1 -1
- package/dist/ecs/persistence-service/persistence-service.d.ts +1 -1
- package/dist/ecs/undo-redo-service/undo-redo-service.d.ts +1 -1
- package/dist/internal/data-view-32/data-view-32.d.ts +1 -5
- package/dist/internal/data-view-32/data-view-32.js +1 -0
- package/dist/internal/data-view-32/data-view-32.js.map +1 -1
- package/dist/service/agentic-service/action-error.d.ts +1 -0
- package/dist/service/agentic-service/action-error.js +3 -0
- package/dist/service/agentic-service/action-error.js.map +1 -0
- package/dist/service/agentic-service/action.d.ts +7 -0
- package/dist/service/agentic-service/action.js +3 -0
- package/dist/service/agentic-service/action.js.map +1 -0
- package/dist/service/agentic-service/agentic-service.d.ts +21 -0
- package/dist/service/agentic-service/agentic-service.js +3 -0
- package/dist/service/agentic-service/agentic-service.js.map +1 -0
- package/dist/service/agentic-service/create-from-config.d.ts +45 -0
- package/dist/service/agentic-service/create-from-config.js +85 -0
- package/dist/service/agentic-service/create-from-config.js.map +1 -0
- package/dist/service/agentic-service/create.d.ts +45 -0
- package/dist/service/agentic-service/create.interface-first-spike.type-test.d.ts +1 -0
- package/dist/service/agentic-service/create.interface-first-spike.type-test.js +119 -0
- package/dist/service/agentic-service/create.interface-first-spike.type-test.js.map +1 -0
- package/dist/service/agentic-service/create.js +85 -0
- package/dist/service/agentic-service/create.js.map +1 -0
- package/dist/service/agentic-service/create.test.d.ts +1 -0
- package/dist/service/agentic-service/create.test.js +542 -0
- package/dist/service/agentic-service/create.test.js.map +1 -0
- package/dist/service/agentic-service/create.type-test.d.ts +1 -0
- package/dist/service/agentic-service/create.type-test.js +121 -0
- package/dist/service/agentic-service/create.type-test.js.map +1 -0
- package/dist/service/agentic-service/index.d.ts +1 -0
- package/dist/service/agentic-service/index.js +3 -0
- package/dist/service/agentic-service/index.js.map +1 -0
- package/dist/service/agentic-service/public.d.ts +5 -0
- package/dist/service/agentic-service/public.js +3 -0
- package/dist/service/agentic-service/public.js.map +1 -0
- package/dist/service/agentic-service/state.d.ts +5 -0
- package/dist/service/agentic-service/state.js +3 -0
- package/dist/service/agentic-service/state.js.map +1 -0
- package/dist/service/dynamic-service/create.d.ts +84 -0
- package/dist/service/dynamic-service/create.interface-first-spike.type-test.d.ts +1 -0
- package/dist/service/dynamic-service/create.interface-first-spike.type-test.js +118 -0
- package/dist/service/dynamic-service/create.interface-first-spike.type-test.js.map +1 -0
- package/dist/service/dynamic-service/create.js +97 -0
- package/dist/service/dynamic-service/create.js.map +1 -0
- package/dist/service/dynamic-service/create.test.d.ts +1 -0
- package/dist/service/dynamic-service/create.test.js +688 -0
- package/dist/service/dynamic-service/create.test.js.map +1 -0
- package/dist/service/dynamic-service/dynamic-service.d.ts +2 -1
- package/dist/service/dynamic-service/dynamic-service.js.map +1 -1
- package/dist/service/dynamic-service/public.d.ts +1 -1
- package/dist/service/dynamic-service/public.js +1 -1
- package/dist/service/dynamic-service/public.js.map +1 -1
- package/dist/service/index.d.ts +1 -1
- package/dist/service/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/typed-buffer/data-view-32.d.ts +5 -0
- package/dist/typed-buffer/data-view-32.js +3 -0
- package/dist/typed-buffer/data-view-32.js.map +1 -0
- package/dist/typed-buffer/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// © 2026 Adobe. MIT License. See /LICENSE for details.
|
|
2
|
+
//
|
|
3
|
+
// Compile-time type checks for createFromConfig API.
|
|
4
|
+
import { Observe } from "../../observe/index.js";
|
|
5
|
+
import { create, } from "./create.js";
|
|
6
|
+
const iface = {
|
|
7
|
+
health: {
|
|
8
|
+
type: "number",
|
|
9
|
+
description: "Current health points",
|
|
10
|
+
},
|
|
11
|
+
stats: {
|
|
12
|
+
type: "object",
|
|
13
|
+
description: "Current player stats",
|
|
14
|
+
properties: {
|
|
15
|
+
hp: { type: "number" },
|
|
16
|
+
label: { type: "string" },
|
|
17
|
+
},
|
|
18
|
+
required: ["hp"],
|
|
19
|
+
additionalProperties: false,
|
|
20
|
+
},
|
|
21
|
+
heal: {
|
|
22
|
+
description: "Increase health by amount",
|
|
23
|
+
input: { type: "number" },
|
|
24
|
+
},
|
|
25
|
+
configure: {
|
|
26
|
+
description: "Configure stats",
|
|
27
|
+
input: {
|
|
28
|
+
type: "object",
|
|
29
|
+
properties: {
|
|
30
|
+
hp: { type: "number" },
|
|
31
|
+
label: { type: "string" },
|
|
32
|
+
},
|
|
33
|
+
required: ["hp"],
|
|
34
|
+
additionalProperties: false,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
reset: {
|
|
38
|
+
description: "Reset values",
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
create({
|
|
42
|
+
description: "Player health and actions for agentic access",
|
|
43
|
+
declaration: iface,
|
|
44
|
+
implementation: {
|
|
45
|
+
health: Observe.fromConstant(42),
|
|
46
|
+
stats: Observe.fromConstant({ hp: 100, label: "ok" }),
|
|
47
|
+
heal: (input) => {
|
|
48
|
+
},
|
|
49
|
+
configure: (input) => {
|
|
50
|
+
},
|
|
51
|
+
reset: () => { },
|
|
52
|
+
},
|
|
53
|
+
conditional: {
|
|
54
|
+
health: Observe.fromConstant(true),
|
|
55
|
+
heal: Observe.fromConstant(false),
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
create({
|
|
59
|
+
description: "Player health and actions for agentic access",
|
|
60
|
+
declaration: iface,
|
|
61
|
+
implementation: {
|
|
62
|
+
// @ts-expect-error - health state requires Observe<number>
|
|
63
|
+
health: Observe.fromConstant("wrong"),
|
|
64
|
+
stats: Observe.fromConstant({ hp: 100 }),
|
|
65
|
+
heal: (input) => { },
|
|
66
|
+
configure: (input) => { },
|
|
67
|
+
reset: () => { },
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
create({
|
|
71
|
+
description: "Player health and actions for agentic access",
|
|
72
|
+
declaration: iface,
|
|
73
|
+
implementation: {
|
|
74
|
+
health: Observe.fromConstant(100),
|
|
75
|
+
stats: Observe.fromConstant({ hp: 100 }),
|
|
76
|
+
// @ts-expect-error - heal input schema requires number
|
|
77
|
+
heal: (input) => { },
|
|
78
|
+
configure: (input) => { },
|
|
79
|
+
reset: () => { },
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
create({
|
|
83
|
+
description: "Player health and actions for agentic access",
|
|
84
|
+
declaration: iface,
|
|
85
|
+
implementation: {
|
|
86
|
+
health: Observe.fromConstant(100),
|
|
87
|
+
stats: Observe.fromConstant({ hp: 100 }),
|
|
88
|
+
heal: (input) => { },
|
|
89
|
+
configure: (input) => { },
|
|
90
|
+
// @ts-expect-error - reset action has no input schema
|
|
91
|
+
reset: (input) => { },
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
create({
|
|
95
|
+
description: "Player health and actions for agentic access",
|
|
96
|
+
declaration: iface,
|
|
97
|
+
// @ts-expect-error - implementation must include every definition key
|
|
98
|
+
implementation: {
|
|
99
|
+
health: Observe.fromConstant(100),
|
|
100
|
+
stats: Observe.fromConstant({ hp: 100 }),
|
|
101
|
+
heal: (input) => { },
|
|
102
|
+
configure: (input) => { },
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
create({
|
|
106
|
+
description: "Player health and actions for agentic access",
|
|
107
|
+
declaration: iface,
|
|
108
|
+
implementation: {
|
|
109
|
+
health: Observe.fromConstant(100),
|
|
110
|
+
stats: Observe.fromConstant({ hp: 100 }),
|
|
111
|
+
heal: (input) => { },
|
|
112
|
+
configure: (input) => { },
|
|
113
|
+
reset: () => { },
|
|
114
|
+
},
|
|
115
|
+
conditional: {
|
|
116
|
+
health: Observe.fromConstant(true),
|
|
117
|
+
// @ts-expect-error - conditional values must be Observe<boolean>
|
|
118
|
+
heal: Observe.fromConstant(1),
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
//# sourceMappingURL=create.type-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.type-test.js","sourceRoot":"","sources":["../../../src/service/agentic-service/create.type-test.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,EAAE;AACF,qDAAqD;AAErD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EACH,MAAM,GAET,MAAM,aAAa,CAAC;AAyBrB,MAAM,KAAK,GAAG;IACV,MAAM,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,uBAAuB;KACvC;IACD,KAAK,EAAE;QACH,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,sBAAsB;QACnC,UAAU,EAAE;YACR,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACtB,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC5B;QACD,QAAQ,EAAE,CAAC,IAAI,CAAC;QAChB,oBAAoB,EAAE,KAAK;KAC9B;IACD,IAAI,EAAE;QACF,WAAW,EAAE,2BAA2B;QACxC,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC5B;IACD,SAAS,EAAE;QACP,WAAW,EAAE,iBAAiB;QAC9B,KAAK,EAAE;YACH,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACR,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACtB,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;aAC5B;YACD,QAAQ,EAAE,CAAC,IAAI,CAAC;YAChB,oBAAoB,EAAE,KAAK;SAC9B;KACJ;IACD,KAAK,EAAE;QACH,WAAW,EAAE,cAAc;KAC9B;CACK,CAAC;AAEX,MAAM,CAAC;IACH,WAAW,EAAE,8CAA8C;IAC3D,WAAW,EAAE,KAAK;IAClB,cAAc,EAAE;QACZ,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QAChC,KAAK,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,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;KAChC;CACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as AgenticService from "./public.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/service/agentic-service/index.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD,OAAO,KAAK,cAAc,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.js","sourceRoot":"","sources":["../../../src/service/agentic-service/public.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAMvD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/service/agentic-service/state.ts"],"names":[],"mappings":"AAAA,uDAAuD"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Observe } from "../../observe/index.js";
|
|
2
|
+
import { Schema } from "../../schema/index.js";
|
|
3
|
+
import type { ActionError } from "./dynamic-service.js";
|
|
4
|
+
import type { DynamicService } from "./dynamic-service.js";
|
|
5
|
+
/**
|
|
6
|
+
* Internal types for the create configuration entries.
|
|
7
|
+
* These are the runtime shapes after going through the typed helpers.
|
|
8
|
+
*/
|
|
9
|
+
type StateEntry = {
|
|
10
|
+
schema: Schema;
|
|
11
|
+
enabled?: Observe<boolean>;
|
|
12
|
+
value: Observe<unknown>;
|
|
13
|
+
};
|
|
14
|
+
type ActionEntry = {
|
|
15
|
+
description: string;
|
|
16
|
+
schema: Schema | false;
|
|
17
|
+
enabled?: Observe<boolean>;
|
|
18
|
+
execute: (...args: any[]) => Promise<void | ActionError> | void;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Creates a typed state entry for use with `create()`.
|
|
22
|
+
* Captures the schema type as a direct generic parameter, ensuring
|
|
23
|
+
* Schema.ToType<S> resolves correctly for the value observable.
|
|
24
|
+
*/
|
|
25
|
+
export declare const state: <const S extends Schema>(config: {
|
|
26
|
+
schema: S;
|
|
27
|
+
enabled?: Observe<boolean>;
|
|
28
|
+
value: Observe<Schema.ToType<S>>;
|
|
29
|
+
}) => StateEntry;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a typed action entry for use with `create()`.
|
|
32
|
+
* Captures the schema type as a direct generic parameter, ensuring
|
|
33
|
+
* Schema.ToType<S> resolves correctly for the execute input parameter.
|
|
34
|
+
*
|
|
35
|
+
* TypeScript cannot resolve Schema.ToType<AS[K]> through indexed access
|
|
36
|
+
* types in mapped types for complex schemas (objects, arrays, etc.).
|
|
37
|
+
* This helper works around that by using a direct generic S parameter.
|
|
38
|
+
*/
|
|
39
|
+
export declare const action: {
|
|
40
|
+
<const S extends Schema>(config: {
|
|
41
|
+
description: string;
|
|
42
|
+
schema: S;
|
|
43
|
+
enabled?: Observe<boolean>;
|
|
44
|
+
execute: (input: Schema.ToType<S>) => Promise<void | ActionError> | void;
|
|
45
|
+
}): ActionEntry;
|
|
46
|
+
(config: {
|
|
47
|
+
description: string;
|
|
48
|
+
schema: false;
|
|
49
|
+
enabled?: Observe<boolean>;
|
|
50
|
+
execute: () => Promise<void | ActionError> | void;
|
|
51
|
+
}): ActionEntry;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Creates a DynamicService from a configuration of states and actions.
|
|
55
|
+
*
|
|
56
|
+
* Use `DynamicService.state()` and `DynamicService.action()` helpers
|
|
57
|
+
* for each entry to get strict type inference on value observables
|
|
58
|
+
* and execute input parameters:
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* DynamicService.create({
|
|
62
|
+
* states: {
|
|
63
|
+
* health: DynamicService.state({
|
|
64
|
+
* schema: { type: "number" },
|
|
65
|
+
* value: healthObserve,
|
|
66
|
+
* }),
|
|
67
|
+
* },
|
|
68
|
+
* actions: {
|
|
69
|
+
* heal: DynamicService.action({
|
|
70
|
+
* description: "Heal the player",
|
|
71
|
+
* schema: { type: "number" },
|
|
72
|
+
* execute: (input) => { // input: number ✓
|
|
73
|
+
* healPlayer(input);
|
|
74
|
+
* },
|
|
75
|
+
* }),
|
|
76
|
+
* },
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare const create: (props: {
|
|
81
|
+
states: Record<string, StateEntry>;
|
|
82
|
+
actions: Record<string, ActionEntry>;
|
|
83
|
+
}) => DynamicService;
|
|
84
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// © 2026 Adobe. MIT License. See /LICENSE for details.
|
|
2
|
+
import { Observe } from "../../observe/index.js";
|
|
3
|
+
const iface = {
|
|
4
|
+
health: {
|
|
5
|
+
type: "number",
|
|
6
|
+
description: "Current health points",
|
|
7
|
+
},
|
|
8
|
+
stats: {
|
|
9
|
+
type: "object",
|
|
10
|
+
description: "Current player stats",
|
|
11
|
+
properties: {
|
|
12
|
+
hp: { type: "number" },
|
|
13
|
+
label: { type: "string" },
|
|
14
|
+
},
|
|
15
|
+
required: ["hp"],
|
|
16
|
+
additionalProperties: false,
|
|
17
|
+
},
|
|
18
|
+
heal: {
|
|
19
|
+
description: "Increase health by amount",
|
|
20
|
+
input: { type: "number" },
|
|
21
|
+
},
|
|
22
|
+
configure: {
|
|
23
|
+
description: "Configure stats",
|
|
24
|
+
input: {
|
|
25
|
+
type: "object",
|
|
26
|
+
properties: {
|
|
27
|
+
hp: { type: "number" },
|
|
28
|
+
label: { type: "string" },
|
|
29
|
+
},
|
|
30
|
+
required: ["hp"],
|
|
31
|
+
additionalProperties: false,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
reset: {
|
|
35
|
+
description: "Reset values",
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
create({
|
|
39
|
+
description: "Player health and actions for agentic access",
|
|
40
|
+
declaration: iface,
|
|
41
|
+
implementation: {
|
|
42
|
+
health: Observe.fromConstant(42),
|
|
43
|
+
stats: Observe.fromConstant({ hp: 100, label: "ok" }),
|
|
44
|
+
heal: (input) => {
|
|
45
|
+
},
|
|
46
|
+
configure: (input) => {
|
|
47
|
+
},
|
|
48
|
+
reset: () => { },
|
|
49
|
+
},
|
|
50
|
+
conditional: {
|
|
51
|
+
health: Observe.fromConstant(true),
|
|
52
|
+
heal: Observe.fromConstant(false),
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
create({
|
|
56
|
+
description: "Player health and actions for agentic access",
|
|
57
|
+
declaration: iface,
|
|
58
|
+
implementation: {
|
|
59
|
+
// @ts-expect-error - health state requires Observe<number>
|
|
60
|
+
health: Observe.fromConstant("wrong"),
|
|
61
|
+
stats: Observe.fromConstant({ hp: 100 }),
|
|
62
|
+
heal: (input) => { },
|
|
63
|
+
configure: (input) => { },
|
|
64
|
+
reset: () => { },
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
create({
|
|
68
|
+
description: "Player health and actions for agentic access",
|
|
69
|
+
declaration: iface,
|
|
70
|
+
implementation: {
|
|
71
|
+
health: Observe.fromConstant(100),
|
|
72
|
+
stats: Observe.fromConstant({ hp: 100 }),
|
|
73
|
+
// @ts-expect-error - heal input schema requires number
|
|
74
|
+
heal: (input) => { },
|
|
75
|
+
configure: (input) => { },
|
|
76
|
+
reset: () => { },
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
create({
|
|
80
|
+
description: "Player health and actions for agentic access",
|
|
81
|
+
declaration: iface,
|
|
82
|
+
implementation: {
|
|
83
|
+
health: Observe.fromConstant(100),
|
|
84
|
+
stats: Observe.fromConstant({ hp: 100 }),
|
|
85
|
+
heal: (input) => { },
|
|
86
|
+
configure: (input) => { },
|
|
87
|
+
// @ts-expect-error - reset action has no input schema
|
|
88
|
+
reset: (input) => { },
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
create({
|
|
92
|
+
description: "Player health and actions for agentic access",
|
|
93
|
+
declaration: iface,
|
|
94
|
+
// @ts-expect-error - implementation must include every definition key
|
|
95
|
+
implementation: {
|
|
96
|
+
health: Observe.fromConstant(100),
|
|
97
|
+
stats: Observe.fromConstant({ hp: 100 }),
|
|
98
|
+
heal: (input) => { },
|
|
99
|
+
configure: (input) => { },
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
create({
|
|
103
|
+
description: "Player health and actions for agentic access",
|
|
104
|
+
declaration: iface,
|
|
105
|
+
implementation: {
|
|
106
|
+
health: Observe.fromConstant(100),
|
|
107
|
+
stats: Observe.fromConstant({ hp: 100 }),
|
|
108
|
+
heal: (input) => { },
|
|
109
|
+
configure: (input) => { },
|
|
110
|
+
reset: () => { },
|
|
111
|
+
},
|
|
112
|
+
conditional: {
|
|
113
|
+
health: Observe.fromConstant(true),
|
|
114
|
+
// @ts-expect-error - conditional values must be Observe<boolean>
|
|
115
|
+
heal: Observe.fromConstant(1),
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
//# sourceMappingURL=create.interface-first-spike.type-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.interface-first-spike.type-test.js","sourceRoot":"","sources":["../../../src/service/dynamic-service/create.interface-first-spike.type-test.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAiEjD,MAAM,KAAK,GAAG;IACV,MAAM,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,uBAAuB;KACvC;IACD,KAAK,EAAE;QACH,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,sBAAsB;QACnC,UAAU,EAAE;YACR,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACtB,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC5B;QACD,QAAQ,EAAE,CAAC,IAAI,CAAC;QAChB,oBAAoB,EAAE,K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E,CAAC;QACxC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,GAAE,CAAC;QACnB,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,GAAE,CAAC;KAC3B;CACJ,CAAC,CAAC;AAEH,MAAM,CAAC;IACH,WAAW,EAAE,8CAA8C;IAC3D,WAAW,EAAE,KAAK;IAClB,cAAc,EAAE;QACZ,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC;QACjC,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC;QACxC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,GAAE,CAAC;QACnB,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,GAAE,CAAC;QACxB,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;KAClB;IACD,WAAW,EAAE;QACT,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC;QAClC,iEAAiE;QACjE,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;KAChC;CACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Observe } from "../../observe/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a typed state entry for use with `create()`.
|
|
4
|
+
* Captures the schema type as a direct generic parameter, ensuring
|
|
5
|
+
* Schema.ToType<S> resolves correctly for the value observable.
|
|
6
|
+
*/
|
|
7
|
+
export const state = (config) => config;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a typed action entry for use with `create()`.
|
|
10
|
+
* Captures the schema type as a direct generic parameter, ensuring
|
|
11
|
+
* Schema.ToType<S> resolves correctly for the execute input parameter.
|
|
12
|
+
*
|
|
13
|
+
* TypeScript cannot resolve Schema.ToType<AS[K]> through indexed access
|
|
14
|
+
* types in mapped types for complex schemas (objects, arrays, etc.).
|
|
15
|
+
* This helper works around that by using a direct generic S parameter.
|
|
16
|
+
*/
|
|
17
|
+
export const action = (config) => config;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a DynamicService from a configuration of states and actions.
|
|
20
|
+
*
|
|
21
|
+
* Use `DynamicService.state()` and `DynamicService.action()` helpers
|
|
22
|
+
* for each entry to get strict type inference on value observables
|
|
23
|
+
* and execute input parameters:
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* DynamicService.create({
|
|
27
|
+
* states: {
|
|
28
|
+
* health: DynamicService.state({
|
|
29
|
+
* schema: { type: "number" },
|
|
30
|
+
* value: healthObserve,
|
|
31
|
+
* }),
|
|
32
|
+
* },
|
|
33
|
+
* actions: {
|
|
34
|
+
* heal: DynamicService.action({
|
|
35
|
+
* description: "Heal the player",
|
|
36
|
+
* schema: { type: "number" },
|
|
37
|
+
* execute: (input) => { // input: number ✓
|
|
38
|
+
* healPlayer(input);
|
|
39
|
+
* },
|
|
40
|
+
* }),
|
|
41
|
+
* },
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export const create = (props) => {
|
|
46
|
+
const alwaysEnabled = Observe.fromConstant(true);
|
|
47
|
+
// Build per-state observables combining enabled + value
|
|
48
|
+
const stateEntries = Object.entries(props.states);
|
|
49
|
+
const perStateObservables = {};
|
|
50
|
+
const stateSchemas = {};
|
|
51
|
+
for (const [key, entry] of stateEntries) {
|
|
52
|
+
stateSchemas[key] = entry.schema;
|
|
53
|
+
perStateObservables[key] = Observe.fromProperties({
|
|
54
|
+
enabled: entry.enabled ?? alwaysEnabled,
|
|
55
|
+
value: entry.value,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const states = Observe.withMap(Observe.fromProperties(perStateObservables), (raw) => {
|
|
59
|
+
const result = {};
|
|
60
|
+
for (const [key, entry] of Object.entries(raw)) {
|
|
61
|
+
const { enabled, value } = entry;
|
|
62
|
+
if (enabled) {
|
|
63
|
+
result[key] = { schema: stateSchemas[key], value };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
});
|
|
68
|
+
// Build per-action enabled observables, capture execute functions
|
|
69
|
+
const actionEntries = Object.entries(props.actions);
|
|
70
|
+
const actionMeta = {};
|
|
71
|
+
const enabledObservables = {};
|
|
72
|
+
for (const [key, entry] of actionEntries) {
|
|
73
|
+
actionMeta[key] = { description: entry.description, schema: entry.schema, execute: entry.execute };
|
|
74
|
+
enabledObservables[key] = entry.enabled ?? alwaysEnabled;
|
|
75
|
+
}
|
|
76
|
+
const actions = Observe.withMap(Observe.fromProperties(enabledObservables), (enabledMap) => {
|
|
77
|
+
const result = {};
|
|
78
|
+
for (const [key, enabled] of Object.entries(enabledMap)) {
|
|
79
|
+
if (!enabled)
|
|
80
|
+
continue;
|
|
81
|
+
const { description, schema, execute } = actionMeta[key];
|
|
82
|
+
result[key] = { description, schema, execute };
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
});
|
|
86
|
+
// Track current actions for execute dispatch
|
|
87
|
+
let currentActions = {};
|
|
88
|
+
actions((a) => { currentActions = a; });
|
|
89
|
+
const execute = async (action, input) => {
|
|
90
|
+
const entry = currentActions[action];
|
|
91
|
+
if (!entry)
|
|
92
|
+
return `Action "${action}" is not available`;
|
|
93
|
+
return entry.execute(input);
|
|
94
|
+
};
|
|
95
|
+
return { serviceName: "dynamic-service", states, actions, execute };
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/service/dynamic-service/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAsBjD;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAyB,MAI7C,EAAc,EAAE,CAAC,MAAoB,CAAC;AAEvC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,MAAM,GAaf,CAAC,MAAW,EAAE,EAAE,CAAC,MAAqB,CAAC;AAE3C;;;;;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