@adobe/data 0.9.20 → 0.9.22

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.
Files changed (36) hide show
  1. package/dist/schema/dynamic/enumerate-patches.test.d.ts +10 -37
  2. package/dist/schema/dynamic/enumerate-patches.test.js +18 -45
  3. package/dist/schema/dynamic/enumerate-patches.test.js.map +1 -1
  4. package/dist/schema/dynamic/get-dynamic-schema.test.js +23 -29
  5. package/dist/schema/dynamic/get-dynamic-schema.test.js.map +1 -1
  6. package/dist/schema/index.d.ts +2 -2
  7. package/dist/schema/schema.d.ts +1 -17
  8. package/dist/schema/schema.js.map +1 -1
  9. package/dist/schema/to-type.d.ts +1 -1
  10. package/dist/schema/to-type.js.map +1 -1
  11. package/dist/service/dynamic-service/create-from-ecs.d.ts +17 -0
  12. package/dist/service/dynamic-service/create-from-ecs.js +56 -0
  13. package/dist/service/dynamic-service/create-from-ecs.js.map +1 -0
  14. package/dist/service/dynamic-service/create-from-ecs.test.d.ts +1 -0
  15. package/dist/service/dynamic-service/create-from-ecs.test.js +636 -0
  16. package/dist/service/dynamic-service/create-from-ecs.test.js.map +1 -0
  17. package/dist/service/dynamic-service/create.d.ts +84 -0
  18. package/dist/service/dynamic-service/create.js +97 -0
  19. package/dist/service/dynamic-service/create.js.map +1 -0
  20. package/dist/service/dynamic-service/create.test.d.ts +1 -0
  21. package/dist/service/dynamic-service/create.test.js +688 -0
  22. package/dist/service/dynamic-service/create.test.js.map +1 -0
  23. package/dist/service/dynamic-service/dynamic-service.d.ts +29 -0
  24. package/dist/service/dynamic-service/dynamic-service.js +2 -0
  25. package/dist/service/dynamic-service/dynamic-service.js.map +1 -0
  26. package/dist/service/dynamic-service/index.d.ts +1 -0
  27. package/dist/service/dynamic-service/index.js +3 -0
  28. package/dist/service/dynamic-service/index.js.map +1 -0
  29. package/dist/service/dynamic-service/public.d.ts +2 -0
  30. package/dist/service/dynamic-service/public.js +3 -0
  31. package/dist/service/dynamic-service/public.js.map +1 -0
  32. package/dist/service/index.d.ts +1 -0
  33. package/dist/service/index.js +1 -0
  34. package/dist/service/index.js.map +1 -1
  35. package/dist/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +1 -1
@@ -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,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
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