@prismatic-io/spectral 10.18.9-preview.1 → 10.19.1-preview.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/dist/generators/componentManifest/getInputs.js +2 -2
- package/dist/index.d.ts +13 -13
- package/dist/index.js +12 -12
- package/dist/serverTypes/convertComponent.js +23 -14
- package/dist/serverTypes/convertIntegration.js +33 -20
- package/dist/serverTypes/index.d.ts +3 -3
- package/dist/testing.js +1 -1
- package/dist/types/ActionInputParameters.d.ts +5 -3
- package/dist/types/Inputs.d.ts +4 -0
- package/dist/types/IntegrationDefinition.d.ts +34 -36
- package/dist/types/TriggerDefinition.d.ts +17 -17
- package/dist/types/TriggerPayload.d.ts +5 -5
- package/dist/types/TriggerPerformFunction.d.ts +1 -1
- package/package.json +1 -1
|
@@ -73,7 +73,7 @@ exports.INPUT_TYPE_MAP = {
|
|
|
73
73
|
const getInputValueType = (input) => {
|
|
74
74
|
var _a, _b;
|
|
75
75
|
if (input.type === "structuredObject") {
|
|
76
|
-
return structuredObjectTypeString((_a = input.inputs) !== null && _a !== void 0 ? _a : []);
|
|
76
|
+
return wrapCollection(structuredObjectTypeString((_a = input.inputs) !== null && _a !== void 0 ? _a : []), input.collection);
|
|
77
77
|
}
|
|
78
78
|
if (input.type === "dynamicObject") {
|
|
79
79
|
return dynamicObjectTypeString((_b = input.inputs) !== null && _b !== void 0 ? _b : []);
|
|
@@ -138,7 +138,7 @@ const getLeafBaseType = (child) => {
|
|
|
138
138
|
const getLeafTypeString = (child) => {
|
|
139
139
|
var _a;
|
|
140
140
|
if (child.type === "structuredObject") {
|
|
141
|
-
return structuredObjectTypeString((_a = child.inputs) !== null && _a !== void 0 ? _a : []);
|
|
141
|
+
return wrapCollection(structuredObjectTypeString((_a = child.inputs) !== null && _a !== void 0 ? _a : []), child.collection);
|
|
142
142
|
}
|
|
143
143
|
return wrapCollection(getLeafBaseType(child), child.collection);
|
|
144
144
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -73,23 +73,24 @@ export declare const integration: <TInputs extends Inputs, TActionInputs extends
|
|
|
73
73
|
* },
|
|
74
74
|
* });
|
|
75
75
|
*/
|
|
76
|
-
export declare const flow: <TInputs extends Inputs, TActionInputs extends Inputs, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TTriggerPayload extends TriggerPayload = TriggerPayload, TItem = unknown,
|
|
77
|
-
trigger?: BatchTrigger<TItem,
|
|
76
|
+
export declare const flow: <TInputs extends Inputs, TActionInputs extends Inputs, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TTriggerPayload extends TriggerPayload = TriggerPayload, TItem = unknown, TPaginationState extends Record<string, unknown> = Record<string, unknown>, T extends Flow<TInputs, TActionInputs, TPayload, TAllowsBranching, TResult, TTriggerPayload, TItem, TPaginationState> = Flow<TInputs, TActionInputs, TPayload, TAllowsBranching, TResult, TTriggerPayload, TItem, TPaginationState>>(definition: T & {
|
|
77
|
+
trigger?: BatchTrigger<TItem, TPaginationState>;
|
|
78
78
|
}) => T;
|
|
79
79
|
/**
|
|
80
80
|
* Builds a flow's batched `trigger` — the ergonomic way to define a batching flow. Instead of
|
|
81
81
|
* writing `onTrigger`/`onDeployTrigger` (returning a full payload) plus `triggerResolver`/
|
|
82
|
-
* `onDeployResolver` (to extract and paginate),
|
|
83
|
-
* the
|
|
84
|
-
* and synthesizes the `resolveItems`
|
|
82
|
+
* `onDeployResolver` (to extract and paginate), each trigger fire returns `{ items,
|
|
83
|
+
* paginationState? }`: the records to dispatch and, when paginating, the cursor for the next
|
|
84
|
+
* page. spectral wraps the items into the wire payload and synthesizes the `resolveItems` and
|
|
85
|
+
* `getNextPaginationState` that read them back — there is no separate pagination callback.
|
|
85
86
|
*
|
|
86
87
|
* Supply the item and pagination-state types explicitly —
|
|
87
88
|
* `batchFlowTrigger<Order, { cursor: number }>({ ... })`. They flow through the whole flow:
|
|
88
|
-
* the trigger fires return `Order[]`, `payload.
|
|
89
|
+
* the trigger fires return `Order[]`, `payload.paginationState` reads back as `{ cursor: number }`,
|
|
89
90
|
* and the flow's `onExecution` sees `params.onTrigger.results.body.data` typed as `Order | Order[]`.
|
|
90
91
|
*
|
|
91
92
|
* @typeParam TItem - the item type each batched execution receives.
|
|
92
|
-
* @typeParam TPaginationState - the pagination state round-tripped via `payload.
|
|
93
|
+
* @typeParam TPaginationState - the pagination state round-tripped via `payload.paginationState`.
|
|
93
94
|
* @see {@link https://prismatic.io/docs/integrations/code-native/flows/ | Code-Native Flows}
|
|
94
95
|
* @example
|
|
95
96
|
* import { flow, batchFlowTrigger } from "@prismatic-io/spectral";
|
|
@@ -100,12 +101,11 @@ export declare const flow: <TInputs extends Inputs, TActionInputs extends Inputs
|
|
|
100
101
|
* batchConfig: { batchSize: 50 },
|
|
101
102
|
* trigger: batchFlowTrigger<Order, { cursor: number }>({
|
|
102
103
|
* onTrigger: async (context, payload) => {
|
|
103
|
-
* const page = await fetchOrders(payload.
|
|
104
|
-
* return {
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* return next === undefined ? null : { cursor: next };
|
|
104
|
+
* const page = await fetchOrders(payload.paginationState?.cursor);
|
|
105
|
+
* return {
|
|
106
|
+
* items: page.orders,
|
|
107
|
+
* paginationState: page.nextCursor ? { cursor: page.nextCursor } : null,
|
|
108
|
+
* };
|
|
109
109
|
* },
|
|
110
110
|
* }),
|
|
111
111
|
* onExecution: async (context, params) => {
|
package/dist/index.js
CHANGED
|
@@ -103,7 +103,7 @@ exports.integration = integration;
|
|
|
103
103
|
* });
|
|
104
104
|
*/
|
|
105
105
|
const flow = (
|
|
106
|
-
// The intersection adds an explicit inference site for `TItem`/`
|
|
106
|
+
// The intersection adds an explicit inference site for `TItem`/`TPaginationState` that the
|
|
107
107
|
// `T extends Flow<...>` capture alone does not provide, while `T` still preserves the precise
|
|
108
108
|
// literal type for the return value. They are inferred from a batched `trigger`'s
|
|
109
109
|
// `items`/pagination-state types (see `batchFlowTrigger`).
|
|
@@ -112,17 +112,18 @@ exports.flow = flow;
|
|
|
112
112
|
/**
|
|
113
113
|
* Builds a flow's batched `trigger` — the ergonomic way to define a batching flow. Instead of
|
|
114
114
|
* writing `onTrigger`/`onDeployTrigger` (returning a full payload) plus `triggerResolver`/
|
|
115
|
-
* `onDeployResolver` (to extract and paginate),
|
|
116
|
-
* the
|
|
117
|
-
* and synthesizes the `resolveItems`
|
|
115
|
+
* `onDeployResolver` (to extract and paginate), each trigger fire returns `{ items,
|
|
116
|
+
* paginationState? }`: the records to dispatch and, when paginating, the cursor for the next
|
|
117
|
+
* page. spectral wraps the items into the wire payload and synthesizes the `resolveItems` and
|
|
118
|
+
* `getNextPaginationState` that read them back — there is no separate pagination callback.
|
|
118
119
|
*
|
|
119
120
|
* Supply the item and pagination-state types explicitly —
|
|
120
121
|
* `batchFlowTrigger<Order, { cursor: number }>({ ... })`. They flow through the whole flow:
|
|
121
|
-
* the trigger fires return `Order[]`, `payload.
|
|
122
|
+
* the trigger fires return `Order[]`, `payload.paginationState` reads back as `{ cursor: number }`,
|
|
122
123
|
* and the flow's `onExecution` sees `params.onTrigger.results.body.data` typed as `Order | Order[]`.
|
|
123
124
|
*
|
|
124
125
|
* @typeParam TItem - the item type each batched execution receives.
|
|
125
|
-
* @typeParam TPaginationState - the pagination state round-tripped via `payload.
|
|
126
|
+
* @typeParam TPaginationState - the pagination state round-tripped via `payload.paginationState`.
|
|
126
127
|
* @see {@link https://prismatic.io/docs/integrations/code-native/flows/ | Code-Native Flows}
|
|
127
128
|
* @example
|
|
128
129
|
* import { flow, batchFlowTrigger } from "@prismatic-io/spectral";
|
|
@@ -133,12 +134,11 @@ exports.flow = flow;
|
|
|
133
134
|
* batchConfig: { batchSize: 50 },
|
|
134
135
|
* trigger: batchFlowTrigger<Order, { cursor: number }>({
|
|
135
136
|
* onTrigger: async (context, payload) => {
|
|
136
|
-
* const page = await fetchOrders(payload.
|
|
137
|
-
* return {
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* return next === undefined ? null : { cursor: next };
|
|
137
|
+
* const page = await fetchOrders(payload.paginationState?.cursor);
|
|
138
|
+
* return {
|
|
139
|
+
* items: page.orders,
|
|
140
|
+
* paginationState: page.nextCursor ? { cursor: page.nextCursor } : null,
|
|
141
|
+
* };
|
|
142
142
|
* },
|
|
143
143
|
* }),
|
|
144
144
|
* onExecution: async (context, params) => {
|
|
@@ -27,12 +27,19 @@ const isPlainObject = (value) => value !== null && typeof value === "object" &&
|
|
|
27
27
|
const cleanerFor = (input) => {
|
|
28
28
|
if (input.type === "structuredObject") {
|
|
29
29
|
const childCleaners = Object.entries(input.inputs).reduce((acc, [childKey, childDef]) => (Object.assign(Object.assign({}, acc), { [childKey]: (0, exports.cleanerFor)(childDef) })), {});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const cleanRecord = (value) => isPlainObject(value) ? (0, perform_1.cleanParams)(value, childCleaners) : value;
|
|
31
|
+
if (input.collection === "valuelist") {
|
|
32
|
+
return (value) => (Array.isArray(value) ? value.map(cleanRecord) : value);
|
|
33
|
+
}
|
|
34
|
+
if (input.collection === "keyvaluelist") {
|
|
35
|
+
// Entries arrive as KeyValuePair envelopes; the object to clean
|
|
36
|
+
// lives under `value`.
|
|
37
|
+
return (value) => Array.isArray(value)
|
|
38
|
+
? value.map((entry) => isPlainObject(entry) && "value" in entry
|
|
39
|
+
? Object.assign(Object.assign({}, entry), { value: cleanRecord(entry.value) }) : entry)
|
|
40
|
+
: value;
|
|
41
|
+
}
|
|
42
|
+
return cleanRecord;
|
|
36
43
|
}
|
|
37
44
|
if (input.type === "dynamicObject") {
|
|
38
45
|
const configCleaners = {};
|
|
@@ -113,14 +120,15 @@ const buildTriggerResolverFields = (resolver) => {
|
|
|
113
120
|
if (!resolver) {
|
|
114
121
|
return {};
|
|
115
122
|
}
|
|
116
|
-
|
|
123
|
+
const { resolveItems, getNextPaginationState } = resolver;
|
|
124
|
+
return Object.assign(Object.assign({}, (resolveItems
|
|
117
125
|
? {
|
|
118
|
-
resolveTriggerItems:
|
|
126
|
+
resolveTriggerItems: resolveItems,
|
|
119
127
|
hasResolveTriggerItems: true,
|
|
120
128
|
}
|
|
121
|
-
: {})), (
|
|
129
|
+
: {})), (getNextPaginationState
|
|
122
130
|
? {
|
|
123
|
-
|
|
131
|
+
getNextPaginationState,
|
|
124
132
|
hasGetNextDiscoveryState: true,
|
|
125
133
|
}
|
|
126
134
|
: {}));
|
|
@@ -129,14 +137,15 @@ const buildOnDeployResolverFields = (resolver) => {
|
|
|
129
137
|
if (!resolver) {
|
|
130
138
|
return {};
|
|
131
139
|
}
|
|
132
|
-
|
|
140
|
+
const { resolveItems, getNextPaginationState } = resolver;
|
|
141
|
+
return Object.assign(Object.assign({}, (resolveItems
|
|
133
142
|
? {
|
|
134
|
-
resolveOnDeployItems:
|
|
143
|
+
resolveOnDeployItems: resolveItems,
|
|
135
144
|
hasResolveOnDeployItems: true,
|
|
136
145
|
}
|
|
137
|
-
: {})), (
|
|
146
|
+
: {})), (getNextPaginationState
|
|
138
147
|
? {
|
|
139
|
-
|
|
148
|
+
getOnDeployNextPaginationState: getNextPaginationState,
|
|
140
149
|
hasGetOnDeployNextDiscoveryState: true,
|
|
141
150
|
}
|
|
142
151
|
: {}));
|
|
@@ -46,13 +46,21 @@ exports.CONCURRENCY_LIMIT_MIN = 2;
|
|
|
46
46
|
* so extraction is just reading that array back. Authors never write this themselves.
|
|
47
47
|
*/
|
|
48
48
|
const defaultResolveItems = (_context, result) => result.payload.body.data;
|
|
49
|
+
/**
|
|
50
|
+
* Default `getNextPaginationState`: a batched fire returns the next page's cursor as
|
|
51
|
+
* `paginationState`, which the wrapper {@link normalizeBatchedFlow} builds stamps onto
|
|
52
|
+
* `payload.paginationState`. Reading it back (defaulting to `null`) is the whole loop: a
|
|
53
|
+
* non-null value re-invokes the fire, `null` ends it. Authors never write this.
|
|
54
|
+
*/
|
|
55
|
+
const defaultGetNextPaginationState = (_context, result) => { var _a; return (_a = result.payload.paginationState) !== null && _a !== void 0 ? _a : null; };
|
|
49
56
|
/**
|
|
50
57
|
* Expands a flow's batched `trigger` (built with `batchFlowTrigger`) into the flat
|
|
51
58
|
* `onTrigger`/`onDeployTrigger`/`triggerResolver`/`onDeployResolver` shape the rest of the
|
|
52
|
-
* conversion pipeline already understands. The trigger fires return
|
|
53
|
-
* wrap each into a `TriggerPerformFunction` that emits `{ payload: { …payload, body: {
|
|
54
|
-
* items } } }`, synthesize the default `resolveItems
|
|
55
|
-
*
|
|
59
|
+
* conversion pipeline already understands. The trigger fires return `{ items, paginationState? }`;
|
|
60
|
+
* here we wrap each into a `TriggerPerformFunction` that emits `{ payload: { …payload, body: {
|
|
61
|
+
* data: items }, paginationState } }`, then synthesize the default `resolveItems` (reads the
|
|
62
|
+
* items back) and `getNextPaginationState` (reads the cursor back). Flows without a `trigger`
|
|
63
|
+
* pass through unchanged.
|
|
56
64
|
*
|
|
57
65
|
* Returns the same `Flow` type it received; the synthesized `triggerResolver`/`onDeployResolver`
|
|
58
66
|
* are wire-only fields (not on the author-facing `Flow`), read downstream via `"x" in flow` checks.
|
|
@@ -62,21 +70,26 @@ const normalizeBatchedFlow = (flow) => {
|
|
|
62
70
|
if (!trigger) {
|
|
63
71
|
return flow;
|
|
64
72
|
}
|
|
65
|
-
const { onTrigger, onDeploy
|
|
66
|
-
// Wrap a batched fire (returns `{ items, response? }`) into a
|
|
67
|
-
// emits the wire payload shape
|
|
73
|
+
const { onTrigger, onDeploy } = trigger;
|
|
74
|
+
// Wrap a batched fire (returns `{ items, paginationState?, response? }`) into a
|
|
75
|
+
// TriggerPerformFunction that emits the wire payload shape: items at `body.data` and the
|
|
76
|
+
// next-page cursor at `paginationState` (defaulting `null` to terminate the loop). The
|
|
77
|
+
// incoming payload's `paginationState` was already consumed by the fire, so overwriting it
|
|
78
|
+
// with the returned cursor is safe — `getNextPaginationState` reads it straight back.
|
|
68
79
|
const wrapFire = (fire) => (context, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
-
const { items, response } = yield fire(context, payload);
|
|
70
|
-
return Object.assign({ payload: Object.assign(Object.assign({}, payload), { body: { data: items, contentType: "application/json" } }) }, (response ? { response } : {}));
|
|
80
|
+
const { items, paginationState, response } = yield fire(context, payload);
|
|
81
|
+
return Object.assign({ payload: Object.assign(Object.assign({}, payload), { body: { data: items, contentType: "application/json" }, paginationState: paginationState !== null && paginationState !== void 0 ? paginationState : null }) }, (response ? { response } : {}));
|
|
71
82
|
});
|
|
72
83
|
const _a = flow, { trigger: _omitTrigger } = _a, rest = __rest(_a, ["trigger"]);
|
|
73
|
-
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, rest), { onTrigger: wrapFire(onTrigger) }), (onDeploy ? { onDeployTrigger: wrapFire(onDeploy) } : {})), { triggerResolver:
|
|
74
|
-
|
|
75
|
-
:
|
|
84
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, rest), { onTrigger: wrapFire(onTrigger) }), (onDeploy ? { onDeployTrigger: wrapFire(onDeploy) } : {})), { triggerResolver: {
|
|
85
|
+
resolveItems: defaultResolveItems,
|
|
86
|
+
getNextPaginationState: defaultGetNextPaginationState,
|
|
87
|
+
} }), (onDeploy
|
|
76
88
|
? {
|
|
77
|
-
onDeployResolver:
|
|
78
|
-
|
|
79
|
-
:
|
|
89
|
+
onDeployResolver: {
|
|
90
|
+
resolveItems: defaultResolveItems,
|
|
91
|
+
getNextPaginationState: defaultGetNextPaginationState,
|
|
92
|
+
},
|
|
80
93
|
}
|
|
81
94
|
: {}));
|
|
82
95
|
};
|
|
@@ -474,7 +487,7 @@ const convertFlow = (rawFlow, componentRegistry, referenceKey) => {
|
|
|
474
487
|
const triggerResolver = "triggerResolver" in flow ? flow.triggerResolver : undefined;
|
|
475
488
|
const onDeployResolver = "onDeployResolver" in flow ? flow.onDeployResolver : undefined;
|
|
476
489
|
const batchConfig = "batchConfig" in flow ? flow.batchConfig : undefined;
|
|
477
|
-
// Resolver behaviors (resolveItems/
|
|
490
|
+
// Resolver behaviors (resolveItems/getNextPaginationState) are serialized onto the
|
|
478
491
|
// synthesized trigger below. On the flow wire we emit only `triggerResolver`, the single
|
|
479
492
|
// config the platform reads (`trigger_resolver_batch_size` / `trigger_resolver_enabled`)
|
|
480
493
|
// and shares between the normal and on-deploy fires. `batchConfig`/`onDeployResolver` are
|
|
@@ -907,9 +920,9 @@ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows: ra
|
|
|
907
920
|
resolveTriggerItems: triggerResolver.resolveItems,
|
|
908
921
|
hasResolveTriggerItems: true,
|
|
909
922
|
}
|
|
910
|
-
: {})), (triggerResolver.
|
|
923
|
+
: {})), (triggerResolver.getNextPaginationState
|
|
911
924
|
? {
|
|
912
|
-
|
|
925
|
+
getNextPaginationState: triggerResolver.getNextPaginationState,
|
|
913
926
|
hasGetNextDiscoveryState: true,
|
|
914
927
|
}
|
|
915
928
|
: {})) : {})), (onDeployTrigger
|
|
@@ -926,9 +939,9 @@ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows: ra
|
|
|
926
939
|
resolveOnDeployItems: onDeployResolver.resolveItems,
|
|
927
940
|
hasResolveOnDeployItems: true,
|
|
928
941
|
}
|
|
929
|
-
: {})), (onDeployResolver.
|
|
942
|
+
: {})), (onDeployResolver.getNextPaginationState
|
|
930
943
|
? {
|
|
931
|
-
|
|
944
|
+
getOnDeployNextPaginationState: onDeployResolver.getNextPaginationState,
|
|
932
945
|
hasGetOnDeployNextDiscoveryState: true,
|
|
933
946
|
}
|
|
934
947
|
: {})) : {})) });
|
|
@@ -130,7 +130,7 @@ export type TriggerEventFunctionResult = TriggerEventFunctionReturn | void;
|
|
|
130
130
|
export type TriggerEventFunction = (context: ActionContext, params: Record<string, unknown>) => Promise<TriggerEventFunctionResult>;
|
|
131
131
|
/**
|
|
132
132
|
* Wire format the platform expects for a trigger. Note: function references
|
|
133
|
-
* (perform, resolveTriggerItems,
|
|
133
|
+
* (perform, resolveTriggerItems, getNextPaginationState, ...) don't survive JSON
|
|
134
134
|
* serialization, so each callback has a paired `hasXxx: boolean` flag the
|
|
135
135
|
* server reads to detect presence. Keep the flag and its callback in sync.
|
|
136
136
|
*
|
|
@@ -175,13 +175,13 @@ export interface Trigger<TInputs extends Inputs, TActionInputs extends Inputs, T
|
|
|
175
175
|
triggerResolverDefaultConcurrentBatchLimit?: number;
|
|
176
176
|
resolveTriggerItems?: (context: ActionContext<TConfigVars>, result: TriggerBaseResult<TPayload>) => unknown[];
|
|
177
177
|
hasResolveTriggerItems?: boolean;
|
|
178
|
-
|
|
178
|
+
getNextPaginationState?: (context: ActionContext<TConfigVars>, result: TriggerBaseResult<TPayload>) => Record<string, unknown> | null;
|
|
179
179
|
hasGetNextDiscoveryState?: boolean;
|
|
180
180
|
onDeployPerform?: TriggerPerformFunction<TInputs, TConfigVars, TAllowsBranching, TResult> | PollingTriggerPerformFunction<TInputs, TActionInputs, TConfigVars, TPayload, TAllowsBranching, TResult> | CNIPollingPerformFunction<TInputs, TConfigVars, TPayload, TAllowsBranching> | ComponentRefTriggerPerformFunction<TInputs, TConfigVars>;
|
|
181
181
|
hasOnDeployPerform?: boolean;
|
|
182
182
|
resolveOnDeployItems?: (context: ActionContext<TConfigVars>, result: TriggerBaseResult<TPayload>) => unknown[];
|
|
183
183
|
hasResolveOnDeployItems?: boolean;
|
|
184
|
-
|
|
184
|
+
getOnDeployNextPaginationState?: (context: ActionContext<TConfigVars>, result: TriggerBaseResult<TPayload>) => Record<string, unknown> | null;
|
|
185
185
|
hasGetOnDeployNextDiscoveryState?: boolean;
|
|
186
186
|
examplePayload?: unknown;
|
|
187
187
|
isCommonTrigger?: boolean;
|
package/dist/testing.js
CHANGED
|
@@ -409,7 +409,7 @@ const createConfigVars = (values) => {
|
|
|
409
409
|
* });
|
|
410
410
|
*/
|
|
411
411
|
const invokeFlow = (flow_1, ...args_1) => __awaiter(void 0, [flow_1, ...args_1], void 0, function* (
|
|
412
|
-
// `any` for TItem/
|
|
412
|
+
// `any` for TItem/TPaginationState/TTriggerPayload: the tester accepts a flow with any
|
|
413
413
|
// resolver item and cursor typing; it drives the flow dynamically and does not rely on
|
|
414
414
|
// the precise `onExecution` param type.
|
|
415
415
|
flow, { configVars, context, payload, } = {}) {
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import type { ConditionalExpression } from "./conditional-logic";
|
|
2
2
|
import type { Connection, DynamicObjectInputField, InputCleanFunction, InputFieldCollection, Inputs, KeyValuePair, StructuredObjectInputField } from "./Inputs";
|
|
3
3
|
/** Resolves a single InputFieldDefinition's runtime value type.
|
|
4
|
-
* - structuredObject: record of declared children's resolved value types
|
|
4
|
+
* - structuredObject: record of declared children's resolved value types;
|
|
5
|
+
* with `collection` set, a list (`valuelist`) or `KeyValuePair` list
|
|
6
|
+
* (`keyvaluelist`) of that record.
|
|
5
7
|
* - dynamicObject: discriminated union keyed by the selected configuration,
|
|
6
8
|
* with the configuration's resolved inputs nested under `values` to avoid
|
|
7
9
|
* collisions with the `configuration` discriminant key.
|
|
8
10
|
* The depth caps (`LeafInputFieldDefinition`, `StructuredOrLeafInputFieldDefinition`)
|
|
9
11
|
* prevent unbounded recursion. */
|
|
10
|
-
type InputValue<T> = T extends StructuredObjectInputField ? {
|
|
12
|
+
type InputValue<T> = T extends StructuredObjectInputField ? ExtractValue<{
|
|
11
13
|
[K in keyof T["inputs"]]: InputValue<T["inputs"][K]>;
|
|
12
|
-
} : T extends DynamicObjectInputField ? {
|
|
14
|
+
}, T["collection"]> : T extends DynamicObjectInputField ? {
|
|
13
15
|
[C in keyof T["configurations"]]: {
|
|
14
16
|
configuration: C;
|
|
15
17
|
values: {
|
package/dist/types/Inputs.d.ts
CHANGED
|
@@ -307,6 +307,10 @@ export type StructuredOrLeafInputFieldDefinition = LeafInputFieldDefinition | St
|
|
|
307
307
|
export type StructuredObjectInputField = Omit<BaseInputField, "dataSource" | "example" | "placeholder" | "required"> & {
|
|
308
308
|
/** Data type the input will collect. */
|
|
309
309
|
type: "structuredObject";
|
|
310
|
+
/** Collection type of the input; when set, the input collects a list
|
|
311
|
+
* (`valuelist`) or keyed list (`keyvaluelist`) of objects instead of a
|
|
312
|
+
* single object. */
|
|
313
|
+
collection?: InputFieldCollection;
|
|
310
314
|
/** Nested input fields keyed by their local key. */
|
|
311
315
|
inputs: Record<string, LeafInputFieldDefinition>;
|
|
312
316
|
};
|
|
@@ -8,11 +8,11 @@ import type { HttpResponse } from "./HttpResponse";
|
|
|
8
8
|
import type { Inputs } from "./Inputs";
|
|
9
9
|
import type { PollingTriggerPerformFunction } from "./PollingTriggerDefinition";
|
|
10
10
|
import type { ScopedConfigVarMap } from "./ScopedConfigVars";
|
|
11
|
-
import type { BatchConfig
|
|
11
|
+
import type { BatchConfig } from "./TriggerDefinition";
|
|
12
12
|
import type { TriggerEventFunction } from "./TriggerEventFunction";
|
|
13
13
|
import type { TriggerPayload } from "./TriggerPayload";
|
|
14
14
|
import type { TriggerPerformFunction } from "./TriggerPerformFunction";
|
|
15
|
-
import type {
|
|
15
|
+
import type { TriggerResult } from "./TriggerResult";
|
|
16
16
|
/**
|
|
17
17
|
* Defines attributes of a code-native integration. See
|
|
18
18
|
* https://prismatic.io/docs/integrations/code-native/
|
|
@@ -49,7 +49,7 @@ export type IntegrationDefinition<TInputs extends Inputs = Inputs, TActionInputs
|
|
|
49
49
|
* Flows for this integration. See
|
|
50
50
|
* https://prismatic.io/docs/integrations/code-native/flows/
|
|
51
51
|
*
|
|
52
|
-
* The trailing `any`s for `TItem`/`
|
|
52
|
+
* The trailing `any`s for `TItem`/`TPaginationState`/`TTriggerPayload` let flows with
|
|
53
53
|
* different resolver item and cursor types live in one array. `integration` only holds
|
|
54
54
|
* and serializes these flows (it never invokes `onExecution`), so the precise — and
|
|
55
55
|
* per-flow distinct — `onExecution` param type does not need to be preserved here.
|
|
@@ -91,45 +91,43 @@ export type BatchedTriggerPayload<TPayload extends TriggerPayload, TItem> = unkn
|
|
|
91
91
|
};
|
|
92
92
|
/**
|
|
93
93
|
* The page of records a batched trigger fire (`onTrigger`/`onDeploy`) returns. The author
|
|
94
|
-
* returns
|
|
95
|
-
*
|
|
96
|
-
*
|
|
94
|
+
* returns the items plus, when paginating, the cursor for the next page. spectral wraps the
|
|
95
|
+
* items into the wire trigger payload (`body.data`), carries the `paginationState` to the next
|
|
96
|
+
* round, and synthesizes the resolver that reads both back. There is no separate pagination
|
|
97
|
+
* callback to define.
|
|
97
98
|
*/
|
|
98
|
-
export interface BatchedTriggerReturn<TItem> {
|
|
99
|
+
export interface BatchedTriggerReturn<TItem, TPaginationState extends Record<string, unknown> = Record<string, unknown>> {
|
|
99
100
|
/** The records produced by this trigger fire. Chunked into batches of the flow's `batchConfig.batchSize`. */
|
|
100
101
|
items: TItem[];
|
|
102
|
+
/**
|
|
103
|
+
* Cursor for the next page. Return it to paginate — the fire is re-invoked with this object on
|
|
104
|
+
* `payload.paginationState`. Omit or return `null` to stop. Compute it here from the fetch
|
|
105
|
+
* response, where the next-page token is still in scope.
|
|
106
|
+
*/
|
|
107
|
+
paginationState?: TPaginationState | null;
|
|
101
108
|
/** Optional HTTP response to the request that invoked the integration. */
|
|
102
109
|
response?: HttpResponse;
|
|
103
110
|
}
|
|
104
|
-
/**
|
|
105
|
-
* The pagination callback for a batched trigger fire. Returns the state for the next page,
|
|
106
|
-
* or `null` to stop. A non-null return re-invokes the corresponding trigger with this object
|
|
107
|
-
* stamped onto `payload.discoveryState`; the loop ends when it returns `null`.
|
|
108
|
-
*/
|
|
109
|
-
export type BatchPaginationStateFunction<TPaginationState extends Record<string, unknown>> = (context: ActionContext<ConfigVars>, result: TriggerBaseResult<WithDiscoveryState<TriggerPayload, TPaginationState>>) => TPaginationState | null;
|
|
110
111
|
/**
|
|
111
112
|
* A batched trigger built by {@link batchFlowTrigger}. Bundles the normal and on-deploy trigger
|
|
112
|
-
* fires
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* `TPaginationState` types `payload.
|
|
113
|
+
* fires, each returning `{ items, paginationState? }`. The two type parameters — supplied
|
|
114
|
+
* explicitly to `batchFlowTrigger<TItem, TPaginationState>(...)` — flow through to the rest of
|
|
115
|
+
* the flow: `TItem` types `onExecution`'s `params.onTrigger.results.body.data`, and
|
|
116
|
+
* `TPaginationState` types both `payload.paginationState` (read on the way in) and the
|
|
117
|
+
* `paginationState` each fire returns (the next page's cursor).
|
|
116
118
|
*/
|
|
117
119
|
export interface BatchTrigger<TItem, TPaginationState extends Record<string, unknown> = Record<string, unknown>> {
|
|
118
120
|
/**
|
|
119
|
-
* The trigger function for this flow. Fetches a page of records and returns them as `items
|
|
120
|
-
*
|
|
121
|
-
*
|
|
121
|
+
* The trigger function for this flow. Fetches a page of records and returns them as `items`,
|
|
122
|
+
* plus the next page's `paginationState` to paginate (omit/`null` to stop). Read the cursor for
|
|
123
|
+
* the current page from `payload.paginationState`.
|
|
122
124
|
*/
|
|
123
|
-
onTrigger: (context: ActionContext<ConfigVars>, payload: TriggerPayload<TPaginationState>) => Promise<BatchedTriggerReturn<TItem>>;
|
|
125
|
+
onTrigger: (context: ActionContext<ConfigVars>, payload: TriggerPayload<TPaginationState>) => Promise<BatchedTriggerReturn<TItem, TPaginationState>>;
|
|
124
126
|
/**
|
|
125
127
|
* The on-deploy trigger fire, run once on initial instance deploy. Same shape as `onTrigger`;
|
|
126
|
-
*
|
|
128
|
+
* return `paginationState` to paginate the backfill.
|
|
127
129
|
*/
|
|
128
|
-
onDeploy?: (context: ActionContext<ConfigVars>, payload: TriggerPayload<TPaginationState>) => Promise<BatchedTriggerReturn<TItem>>;
|
|
129
|
-
/** Pagination for `onTrigger`: return the next page's state, or `null` to stop. */
|
|
130
|
-
getNextOnTriggerPaginationState?: BatchPaginationStateFunction<TPaginationState>;
|
|
131
|
-
/** Pagination for `onDeploy`: return the next page's state, or `null` to stop. */
|
|
132
|
-
getNextOnDeployPaginationState?: BatchPaginationStateFunction<TPaginationState>;
|
|
130
|
+
onDeploy?: (context: ActionContext<ConfigVars>, payload: TriggerPayload<TPaginationState>) => Promise<BatchedTriggerReturn<TItem, TPaginationState>>;
|
|
133
131
|
}
|
|
134
132
|
export type FlowOnExecution<TTriggerPayload extends TriggerPayload, TItem = unknown> = ActionPerformFunction<{
|
|
135
133
|
onTrigger: {
|
|
@@ -165,7 +163,7 @@ export type FlowExecutionContextActions = FlowExecutionContext["components"];
|
|
|
165
163
|
* union is deliberate — a function property living in a union member loses contextual
|
|
166
164
|
* parameter typing, which would make `onExecution`'s `context`/`params` implicitly `any`.
|
|
167
165
|
*/
|
|
168
|
-
interface BatchFields<TItem,
|
|
166
|
+
interface BatchFields<TItem, TPaginationState extends Record<string, unknown>> {
|
|
169
167
|
/**
|
|
170
168
|
* Batch-dispatch config for this flow. Items returned by the `trigger`'s fires are chunked
|
|
171
169
|
* into batches of `batchSize`. For a CNI flow this value is authoritative (what's written
|
|
@@ -177,7 +175,7 @@ interface BatchFields<TItem, TDiscoveryState extends Record<string, unknown>> {
|
|
|
177
175
|
* (`onTrigger`/`onDeploy`) return just `items`; spectral synthesizes the resolver that
|
|
178
176
|
* extracts them and maps the pagination callbacks. Required when `batchConfig` is set.
|
|
179
177
|
*/
|
|
180
|
-
trigger: BatchTrigger<TItem,
|
|
178
|
+
trigger: BatchTrigger<TItem, TPaginationState>;
|
|
181
179
|
/** A batched flow's trigger fires live inside `trigger`; the flat `onTrigger` is forbidden. */
|
|
182
180
|
onTrigger?: never;
|
|
183
181
|
/** A batched flow's on-deploy fire lives inside `trigger`; the flat `onDeployTrigger` is forbidden. */
|
|
@@ -193,7 +191,7 @@ interface NonBatchFields {
|
|
|
193
191
|
* The discriminated union coupling `batchConfig` and the batched `trigger`. Intersected
|
|
194
192
|
* into each flow variant at {@link Flow}.
|
|
195
193
|
*/
|
|
196
|
-
type BatchDiscriminant<TItem,
|
|
194
|
+
type BatchDiscriminant<TItem, TPaginationState extends Record<string, unknown>> = BatchFields<TItem, TPaginationState> | NonBatchFields;
|
|
197
195
|
/** Base properties shared by all flow types. */
|
|
198
196
|
interface FlowBase<TTriggerPayload extends TriggerPayload = TriggerPayload, TItem = unknown> {
|
|
199
197
|
/** The unique name for this flow. */
|
|
@@ -262,23 +260,23 @@ interface FlowBase<TTriggerPayload extends TriggerPayload = TriggerPayload, TIte
|
|
|
262
260
|
}
|
|
263
261
|
export type StandardTriggerType = "standard";
|
|
264
262
|
/** A standard flow with a webhook or scheduled trigger (non-polling). */
|
|
265
|
-
interface StandardFlow<TInputs extends Inputs = Inputs, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = false, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TTriggerPayload extends TriggerPayload = TriggerPayload, TItem = unknown,
|
|
263
|
+
interface StandardFlow<TInputs extends Inputs = Inputs, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = false, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TTriggerPayload extends TriggerPayload = TriggerPayload, TItem = unknown, TPaginationState extends Record<string, unknown> = Record<string, unknown>> extends FlowBase<TTriggerPayload, TItem> {
|
|
266
264
|
triggerType?: StandardTriggerType;
|
|
267
265
|
/** Schedule configuration that defines the frequency with which this flow will be automatically executed. */
|
|
268
266
|
schedule?: (ValueExpression<string> | ConfigVarExpression) & {
|
|
269
267
|
timezone?: string;
|
|
270
268
|
};
|
|
271
269
|
/** Specifies the trigger function for this flow, which returns a payload and optional HTTP response. */
|
|
272
|
-
onTrigger?: TriggerReference | TriggerPerformFunction<TInputs, ConfigVars, TAllowsBranching, TResult,
|
|
270
|
+
onTrigger?: TriggerReference | TriggerPerformFunction<TInputs, ConfigVars, TAllowsBranching, TResult, TPaginationState>;
|
|
273
271
|
/**
|
|
274
272
|
* Function to execute on initial instance deploy, in addition to (and independent of) `onTrigger`.
|
|
275
273
|
* Typically used to backfill baseline records for systems whose webhooks only emit future events.
|
|
276
274
|
*/
|
|
277
|
-
onDeployTrigger?: TriggerPerformFunction<TInputs, ConfigVars, TAllowsBranching, TResult,
|
|
275
|
+
onDeployTrigger?: TriggerPerformFunction<TInputs, ConfigVars, TAllowsBranching, TResult, TPaginationState>;
|
|
278
276
|
}
|
|
279
277
|
export type PollingTriggerType = "polling";
|
|
280
278
|
/** A polling flow that runs on a schedule and has access to polling context (getState/setState). */
|
|
281
|
-
interface PollingFlow<TInputs extends Inputs, TActionInputs extends Inputs, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TTriggerPayload extends TriggerPayload = TriggerPayload, TItem = unknown,
|
|
279
|
+
interface PollingFlow<TInputs extends Inputs, TActionInputs extends Inputs, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TTriggerPayload extends TriggerPayload = TriggerPayload, TItem = unknown, TPaginationState extends Record<string, unknown> = Record<string, unknown>> extends FlowBase<TTriggerPayload, TItem> {
|
|
282
280
|
/**
|
|
283
281
|
* Type of trigger for this flow. A "polling" trigger runs on a schedule
|
|
284
282
|
* and can use context.polling.* functions. Requires schedule to be set.
|
|
@@ -296,10 +294,10 @@ interface PollingFlow<TInputs extends Inputs, TActionInputs extends Inputs, TPay
|
|
|
296
294
|
* Function to execute on initial instance deploy, in addition to (and independent of) `onTrigger`.
|
|
297
295
|
* Typically used to backfill baseline records for systems whose webhooks only emit future events.
|
|
298
296
|
*/
|
|
299
|
-
onDeployTrigger?: TriggerPerformFunction<TInputs, ConfigVars, TAllowsBranching, TResult,
|
|
297
|
+
onDeployTrigger?: TriggerPerformFunction<TInputs, ConfigVars, TAllowsBranching, TResult, TPaginationState>;
|
|
300
298
|
}
|
|
301
299
|
/** Defines attributes of a flow of a code-native integration. */
|
|
302
|
-
export type Flow<TInputs extends Inputs, TActionInputs extends Inputs, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TTriggerPayload extends TriggerPayload = TriggerPayload, TItem = unknown,
|
|
300
|
+
export type Flow<TInputs extends Inputs, TActionInputs extends Inputs, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TTriggerPayload extends TriggerPayload = TriggerPayload, TItem = unknown, TPaginationState extends Record<string, unknown> = Record<string, unknown>> = (StandardFlow<TInputs, TPayload, TAllowsBranching, TResult, TTriggerPayload, TItem, TPaginationState> & BatchDiscriminant<TItem, TPaginationState>) | (PollingFlow<TInputs, TActionInputs, TPayload, TAllowsBranching, TResult, TTriggerPayload, TItem, TPaginationState> & BatchDiscriminant<TItem, TPaginationState>);
|
|
303
301
|
export type FlowTriggerType = PollingTriggerType | StandardTriggerType;
|
|
304
302
|
/** Defines attributes of a Preprocess flow Configuration used by a flow of an integration. */
|
|
305
303
|
export type PreprocessFlowConfig = {
|
|
@@ -14,15 +14,15 @@ import type { TriggerBaseResult, TriggerResult } from "./TriggerResult";
|
|
|
14
14
|
* `triggerResolver` is the resolver *behavior* only; batch sizing comes from the
|
|
15
15
|
* trigger's shared `batchConfig` (see `TriggerDefinition`).
|
|
16
16
|
*/
|
|
17
|
-
export type TriggerResolverDecl<TConfigVars extends ConfigVarResultCollection, TPayload extends TriggerPayload, TItem = unknown,
|
|
17
|
+
export type TriggerResolverDecl<TConfigVars extends ConfigVarResultCollection, TPayload extends TriggerPayload, TItem = unknown, TPaginationState extends Record<string, unknown> = Record<string, unknown>> = {
|
|
18
18
|
triggerResolverSupport?: "invalid" | undefined;
|
|
19
19
|
triggerResolver?: undefined;
|
|
20
20
|
} | {
|
|
21
21
|
triggerResolverSupport: "valid";
|
|
22
|
-
triggerResolver?: TriggerResolverBehavior<TConfigVars, TPayload, TItem,
|
|
22
|
+
triggerResolver?: TriggerResolverBehavior<TConfigVars, TPayload, TItem, TPaginationState>;
|
|
23
23
|
} | {
|
|
24
24
|
triggerResolverSupport: "required";
|
|
25
|
-
triggerResolver: TriggerResolverBehavior<TConfigVars, TPayload, TItem,
|
|
25
|
+
triggerResolver: TriggerResolverBehavior<TConfigVars, TPayload, TItem, TPaginationState>;
|
|
26
26
|
};
|
|
27
27
|
/**
|
|
28
28
|
* Encodes the relationship between `onDeployPerform` and `onDeployResolver`. On-deploy is
|
|
@@ -34,12 +34,12 @@ export type TriggerResolverDecl<TConfigVars extends ConfigVarResultCollection, T
|
|
|
34
34
|
* same on-deploy fire `onDeployTrigger` (sibling to its `onTrigger`); both flatten to
|
|
35
35
|
* `onDeployPerform` on the wire.
|
|
36
36
|
*/
|
|
37
|
-
export type OnDeployDecl<TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TPayload extends TriggerPayload, TAllowsBranching extends boolean, TResult extends TriggerResult<TAllowsBranching, TPayload>, TItem = unknown,
|
|
37
|
+
export type OnDeployDecl<TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TPayload extends TriggerPayload, TAllowsBranching extends boolean, TResult extends TriggerResult<TAllowsBranching, TPayload>, TItem = unknown, TPaginationState extends Record<string, unknown> = Record<string, unknown>> = {
|
|
38
38
|
onDeployPerform?: undefined;
|
|
39
39
|
onDeployResolver?: undefined;
|
|
40
40
|
} | {
|
|
41
41
|
onDeployPerform: TriggerPerformFunction<TInputs, TConfigVars, TAllowsBranching, TResult>;
|
|
42
|
-
onDeployResolver?: TriggerResolverBehavior<TConfigVars, TPayload, TItem,
|
|
42
|
+
onDeployResolver?: TriggerResolverBehavior<TConfigVars, TPayload, TItem, TPaginationState>;
|
|
43
43
|
};
|
|
44
44
|
declare const optionChoices: readonly ["invalid", "valid", "required"];
|
|
45
45
|
export type TriggerOptionChoice = (typeof optionChoices)[number];
|
|
@@ -54,30 +54,30 @@ export declare const TriggerOptionChoices: TriggerOptionChoice[];
|
|
|
54
54
|
*
|
|
55
55
|
* perform ──▶ resolveItems ──▶ [batch of TItem] ──▶ onExecution
|
|
56
56
|
* │
|
|
57
|
-
* └─
|
|
57
|
+
* └─ getNextPaginationState ──▶ payload.paginationState ──▶ next perform
|
|
58
58
|
*
|
|
59
59
|
* @typeParam TItem - element produced by `resolveItems`. With `batchSize: 1`
|
|
60
60
|
* each execution receives one `TItem` as its trigger data; with `batchSize > 1`
|
|
61
61
|
* it receives a `TItem[]` slice.
|
|
62
|
-
* @typeParam
|
|
63
|
-
* `
|
|
64
|
-
* `payload.
|
|
65
|
-
* passed to both callbacks has its `
|
|
62
|
+
* @typeParam TPaginationState - the pagination cursor. Whatever
|
|
63
|
+
* `getNextPaginationState` returns is what the next round reads back on
|
|
64
|
+
* `payload.paginationState` (see {@link TriggerPayload}). The `result.payload`
|
|
65
|
+
* passed to both callbacks has its `paginationState` narrowed to this type, so
|
|
66
66
|
* the cursor round-trip is checked end to end.
|
|
67
67
|
*/
|
|
68
|
-
export interface TriggerResolverBehavior<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TPayload extends TriggerPayload = TriggerPayload, TItem = unknown,
|
|
68
|
+
export interface TriggerResolverBehavior<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TPayload extends TriggerPayload = TriggerPayload, TItem = unknown, TPaginationState extends Record<string, unknown> = Record<string, unknown>> {
|
|
69
69
|
/** Extracts the items to dispatch from one trigger result. Receives the same context as the trigger's perform function. With `batchSize: 1` each item is delivered to its own execution; with `batchSize > 1` items are grouped into `TItem[]` slices. */
|
|
70
|
-
resolveItems?: (context: ActionContext<TConfigVars>, result: TriggerBaseResult<
|
|
71
|
-
/** Returns the cursor for the next page, or `null` to stop. A non-null return re-invokes the trigger with this object stamped onto `payload.
|
|
72
|
-
|
|
70
|
+
resolveItems?: (context: ActionContext<TConfigVars>, result: TriggerBaseResult<WithPaginationState<TPayload, TPaginationState>>) => TItem[];
|
|
71
|
+
/** Returns the cursor for the next page, or `null` to stop. A non-null return re-invokes the trigger with this object stamped onto `payload.paginationState`. */
|
|
72
|
+
getNextPaginationState?: (context: ActionContext<TConfigVars>, result: TriggerBaseResult<WithPaginationState<TPayload, TPaginationState>>) => TPaginationState | null;
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
|
-
* A trigger payload with its `
|
|
75
|
+
* A trigger payload with its `paginationState` field narrowed to `TPaginationState`,
|
|
76
76
|
* leaving every other field of `TPayload` intact. Lets a resolver type the cursor
|
|
77
77
|
* it reads back independently of how the base payload was parameterized.
|
|
78
78
|
*/
|
|
79
|
-
export type
|
|
80
|
-
|
|
79
|
+
export type WithPaginationState<TPayload extends TriggerPayload, TPaginationState extends Record<string, unknown>> = Omit<TPayload, "paginationState"> & {
|
|
80
|
+
paginationState?: TPaginationState;
|
|
81
81
|
};
|
|
82
82
|
/**
|
|
83
83
|
* The single batch-dispatch config shared by a trigger's `triggerResolver` and
|
|
@@ -5,11 +5,11 @@ import type { IntegrationAttributes } from "./IntegrationAttributes";
|
|
|
5
5
|
import type { UserAttributes } from "./UserAttributes";
|
|
6
6
|
/** Represents a Trigger Payload, which is data passed into a Trigger to invoke an Integration execution.
|
|
7
7
|
*
|
|
8
|
-
* The optional `
|
|
9
|
-
* declare a pagination-state shape on their `
|
|
8
|
+
* The optional `TPaginationState` parameter types the `paginationState` field, so authors who
|
|
9
|
+
* declare a pagination-state shape on their `getNextPaginationState` resolver can read back
|
|
10
10
|
* the same shape on the next round's payload. Defaults to `Record<string, unknown>`.
|
|
11
11
|
*/
|
|
12
|
-
export interface TriggerPayload<
|
|
12
|
+
export interface TriggerPayload<TPaginationState extends Record<string, unknown> = Record<string, unknown>> {
|
|
13
13
|
/** The headers sent in the webhook request. */
|
|
14
14
|
headers: {
|
|
15
15
|
[key: string]: string;
|
|
@@ -56,7 +56,7 @@ export interface TriggerPayload<TDiscoveryState extends Record<string, unknown>
|
|
|
56
56
|
/** Determines whether the execution will run in debug mode. */
|
|
57
57
|
globalDebug: boolean;
|
|
58
58
|
/** Managed by the execution when this trigger invocation is a paginated re-run.
|
|
59
|
-
* Contains the object returned by `
|
|
59
|
+
* Contains the object returned by `getNextPaginationState` from the previous round.
|
|
60
60
|
* Absent on the initial invocation. */
|
|
61
|
-
|
|
61
|
+
paginationState?: TPaginationState;
|
|
62
62
|
}
|
|
@@ -4,4 +4,4 @@ import type { ConfigVarResultCollection, Inputs } from "./Inputs";
|
|
|
4
4
|
import type { TriggerPayload } from "./TriggerPayload";
|
|
5
5
|
import type { TriggerResult } from "./TriggerResult";
|
|
6
6
|
/** Definition of the function to perform when a Trigger is invoked. */
|
|
7
|
-
export type TriggerPerformFunction<TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TAllowsBranching extends boolean | undefined, TResult extends TriggerResult<TAllowsBranching, TriggerPayload>,
|
|
7
|
+
export type TriggerPerformFunction<TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TAllowsBranching extends boolean | undefined, TResult extends TriggerResult<TAllowsBranching, TriggerPayload>, TPaginationState extends Record<string, unknown> = Record<string, unknown>> = (context: ActionContext<TConfigVars>, payload: TriggerPayload<TPaginationState>, params: ActionInputParameters<TInputs>) => Promise<TResult>;
|