automate.ax 0.1.3 → 0.2.0
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/README.md +2 -0
- package/dist/automation/actions.d.ts +6 -2
- package/dist/automation/actions.d.ts.map +1 -1
- package/dist/automation/actions.js +1 -1
- package/dist/automation/signal.d.ts +30 -2
- package/dist/automation/signal.d.ts.map +1 -1
- package/dist/automation/signal.js +22 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,6 +74,8 @@ may be any value. `signal.transform(fn)` is the unary convenience form, and
|
|
|
74
74
|
`signal.property` is shorthand for
|
|
75
75
|
`signal.transform((value) => value.property)`. Property access composes across
|
|
76
76
|
objects and primitives, so `request.path.length` is a `Signal<number>`.
|
|
77
|
+
Function-valued signals are callable and return a signal for the result, so
|
|
78
|
+
`names.join(", ")` is a `Signal<string>` when `names` is a `Signal<string[]>`.
|
|
77
79
|
|
|
78
80
|
Declare custom actions at the top level, then call them inside an automation:
|
|
79
81
|
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { type Encodable, type ObjectProducingSchema, type ProducingSchema } from "@automate.ax/codec";
|
|
2
2
|
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
3
|
import { type AccountAuthorizationAction, type IntegrationAccountReference, type IntegrationScopeRequirement, type ResolvedIntegrationAccount } from "./integrations.js";
|
|
4
|
+
import { signalValueType } from "./signal.js";
|
|
4
5
|
import type { Signal } from "./signal.js";
|
|
5
6
|
declare const DEFAULT_ACTION_INPUT_SCHEMA: StandardSchemaV1<Record<string, never>>;
|
|
6
7
|
declare const DEFAULT_ACTION_OUTPUT_SCHEMA: StandardSchemaV1<void>;
|
|
8
|
+
type ActionInputSignal<T> = Signal & {
|
|
9
|
+
readonly [signalValueType]: () => T;
|
|
10
|
+
};
|
|
7
11
|
/**
|
|
8
12
|
* Executor-only platform capabilities available to action handlers.
|
|
9
13
|
*
|
|
@@ -146,7 +150,7 @@ export type ActionSchemaInput<TInputSchema extends ObjectProducingSchema<unknown
|
|
|
146
150
|
* @template TInputSchema - Object-producing action input schema.
|
|
147
151
|
*/
|
|
148
152
|
export type ActionCallInput<TInputSchema extends ObjectProducingSchema<unknown>> = {
|
|
149
|
-
[TKey in keyof ActionSchemaInput<TInputSchema>]: ActionSchemaInput<TInputSchema>[TKey] |
|
|
153
|
+
[TKey in keyof ActionSchemaInput<TInputSchema>]: ActionSchemaInput<TInputSchema>[TKey] | ActionInputSignal<ActionSchemaInput<TInputSchema>[TKey]>;
|
|
150
154
|
};
|
|
151
155
|
/**
|
|
152
156
|
* Optional account selection added to account-backed action calls.
|
|
@@ -158,7 +162,7 @@ export type ActionCallInput<TInputSchema extends ObjectProducingSchema<unknown>>
|
|
|
158
162
|
*/
|
|
159
163
|
type ActionAccountCallInput<TAccountServiceId extends string> = {
|
|
160
164
|
/** Project account binding to use for this invocation. */
|
|
161
|
-
account?: string | IntegrationAccountReference<TAccountServiceId> |
|
|
165
|
+
account?: string | IntegrationAccountReference<TAccountServiceId> | ActionInputSignal<string | IntegrationAccountReference<TAccountServiceId>>;
|
|
162
166
|
};
|
|
163
167
|
type ActionInvocationInput<TInputSchema extends ObjectProducingSchema<unknown>, TAccountServiceId extends string> = [TAccountServiceId] extends [never] ? ActionCallInput<TInputSchema> : [TInputSchema] extends [typeof DEFAULT_ACTION_INPUT_SCHEMA] ? ActionAccountCallInput<TAccountServiceId> : ActionCallInput<TInputSchema> & ActionAccountCallInput<TAccountServiceId>;
|
|
164
168
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/automation/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAI7D,OAAO,EAKL,KAAK,0BAA0B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AAgB,CAAC,CACf,OAAO,EAAE,oBAAoB,EAC7B,GAAG,MAAM,EAAE,OAAO,EAAE,GACnB,MAAM,CAAC,MAAM,CAAC,CAchB"}
|
|
@@ -2,7 +2,7 @@ import { mapValues } from "@zachsents/zippy";
|
|
|
2
2
|
import { omit, pick } from "remeda";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { actionAccountRequirementDefinition, DEFAULT_ACCOUNT_BINDING, isIntegrationAccountReference, serializedIntegrationAccountDefinition, } from "./integrations.js";
|
|
5
|
-
import { actionProvenance, createActionSignal, isSignal, signalTransform, subscriptionProvenance, transform, } from "./signal.js";
|
|
5
|
+
import { actionProvenance, createActionSignal, isSignal, signalTransform, signalValueType, subscriptionProvenance, transform, } from "./signal.js";
|
|
6
6
|
import { consumeHookSlot } from "./runtime.js";
|
|
7
7
|
const DEFAULT_ACTION_INPUT_SCHEMA = z.record(z.string(), z.never());
|
|
8
8
|
const DEFAULT_ACTION_OUTPUT_SCHEMA = z.void();
|
|
@@ -2,10 +2,14 @@ export declare const actionProvenance: unique symbol;
|
|
|
2
2
|
export declare const signalTransform: unique symbol;
|
|
3
3
|
export declare const subscriptionProvenance: unique symbol;
|
|
4
4
|
export declare const signalValueType: unique symbol;
|
|
5
|
-
/** Maps
|
|
5
|
+
/** Maps a payload's properties to child signals. */
|
|
6
6
|
type SignalProperties<T> = {
|
|
7
7
|
readonly [TKey in keyof NonNullable<T> as TKey extends keyof SignalProtocol<T> ? never : TKey extends string | number ? TKey : never]-?: Signal<NonNullable<T>[TKey]>;
|
|
8
8
|
};
|
|
9
|
+
/** Makes signals carrying functions callable as derived-value transforms. */
|
|
10
|
+
type SignalCallable<T> = NonNullable<T> extends (...arguments_: infer TArguments) => infer TResult ? {
|
|
11
|
+
(...arguments_: TArguments): Signal<TResult>;
|
|
12
|
+
} : unknown;
|
|
9
13
|
type SignalProtocol<T> = {
|
|
10
14
|
readonly [actionProvenance]?: {
|
|
11
15
|
slot: number;
|
|
@@ -20,7 +24,31 @@ type SignalProtocol<T> = {
|
|
|
20
24
|
readonly [signalValueType]: () => T;
|
|
21
25
|
transform<TMapped>(transformer: (value: T) => TMapped): Signal<TMapped>;
|
|
22
26
|
};
|
|
23
|
-
|
|
27
|
+
/**
|
|
28
|
+
* A durable symbolic reference to a value that will be materialized during
|
|
29
|
+
* automation execution.
|
|
30
|
+
*
|
|
31
|
+
* Signals compose synchronously while their values are unavailable. Accessing a
|
|
32
|
+
* property creates a derived signal, so `request.path` is equivalent to
|
|
33
|
+
* `request.transform((value) => value.path)`. Property access can be chained
|
|
34
|
+
* across objects and primitives; for example, `request.path.length` is a
|
|
35
|
+
* `Signal<number>`. Resolving a property derived from a `null` or `undefined`
|
|
36
|
+
* value throws a `TypeError`.
|
|
37
|
+
*
|
|
38
|
+
* Function-valued signals are callable. Calling one creates another derived
|
|
39
|
+
* signal for its eventual result without invoking the function during
|
|
40
|
+
* orchestration. Functions reached through property access retain their
|
|
41
|
+
* receiver, so methods such as `names.join(", ")` behave like their ordinary
|
|
42
|
+
* JavaScript equivalents while returning a signal.
|
|
43
|
+
*
|
|
44
|
+
* TypeScript cannot preserve arbitrary generic call signatures when wrapping
|
|
45
|
+
* their return values. Generic methods such as `Array.prototype.map` therefore
|
|
46
|
+
* produce `Signal<unknown[]>`; use `transform` when the precise generic result
|
|
47
|
+
* type must be retained.
|
|
48
|
+
*
|
|
49
|
+
* @template T - Value represented by the signal.
|
|
50
|
+
*/
|
|
51
|
+
export type Signal<T = unknown> = SignalProtocol<T> & SignalProperties<T> & SignalCallable<T>;
|
|
24
52
|
export type SignalTransform = {
|
|
25
53
|
transform(...inputs: unknown[]): unknown;
|
|
26
54
|
}["transform"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../../src/automation/signal.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,EAAE,OAAO,MAErC,CAAA;AACD,eAAO,MAAM,eAAe,EAAE,OAAO,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 export const signalValueType = Symbol("automation.signalValueType");
|
|
|
8
8
|
* @param value - Value to inspect.
|
|
9
9
|
*/
|
|
10
10
|
export function isSignal(value) {
|
|
11
|
-
return (typeof value === "object" &&
|
|
11
|
+
return ((typeof value === "object" || typeof value === "function") &&
|
|
12
12
|
value !== null &&
|
|
13
13
|
signalValueType in value &&
|
|
14
14
|
typeof value[signalValueType] === "function");
|
|
@@ -38,18 +38,24 @@ export function transform(inputs, transformer) {
|
|
|
38
38
|
}
|
|
39
39
|
/** Creates the proxy that implements behavior shared by every signal. */
|
|
40
40
|
function createSignalProxy() {
|
|
41
|
-
const target = {
|
|
41
|
+
const target = Object.assign(() => {
|
|
42
|
+
throw new Error("Signal proxies cannot be called directly.");
|
|
43
|
+
}, {
|
|
42
44
|
[signalValueType]: () => {
|
|
43
45
|
throw new Error("Signal type markers cannot be called.");
|
|
44
46
|
},
|
|
45
47
|
transform(transformer) {
|
|
46
48
|
return transform([signal], transformer);
|
|
47
49
|
},
|
|
48
|
-
};
|
|
50
|
+
});
|
|
49
51
|
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Proxy traps provide the mapped properties.
|
|
50
52
|
const signal = new Proxy(target, {
|
|
51
53
|
get(target, property, receiver) {
|
|
52
|
-
if (
|
|
54
|
+
if (property === "transform" ||
|
|
55
|
+
property === actionProvenance ||
|
|
56
|
+
property === signalTransform ||
|
|
57
|
+
property === subscriptionProvenance ||
|
|
58
|
+
property === signalValueType) {
|
|
53
59
|
return Reflect.get(target, property, receiver);
|
|
54
60
|
}
|
|
55
61
|
if (typeof property !== "string")
|
|
@@ -58,7 +64,18 @@ function createSignalProxy() {
|
|
|
58
64
|
if (value == null) {
|
|
59
65
|
throw new TypeError(`Cannot read property ${property} from ${String(value)}.`);
|
|
60
66
|
}
|
|
61
|
-
|
|
67
|
+
const propertyValue = Reflect.get(Object(value), property);
|
|
68
|
+
return typeof propertyValue === "function"
|
|
69
|
+
? propertyValue.bind(value)
|
|
70
|
+
: propertyValue;
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
apply(_target, _thisArgument, argumentsList) {
|
|
74
|
+
return transform([signal], (value) => {
|
|
75
|
+
if (typeof value !== "function") {
|
|
76
|
+
throw new TypeError("Signal value is not callable.");
|
|
77
|
+
}
|
|
78
|
+
return Reflect.apply(value, undefined, argumentsList);
|
|
62
79
|
});
|
|
63
80
|
},
|
|
64
81
|
});
|