@decocms/bindings 1.0.1-alpha.19 → 1.0.1-alpha.20
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/package.json +1 -1
- package/src/index.ts +10 -0
- package/src/well-known/collections.ts +20 -12
- package/src/well-known/event-bus.ts +120 -1
- package/src/well-known/event-subscriber.ts +71 -15
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -25,6 +25,8 @@ export {
|
|
|
25
25
|
export {
|
|
26
26
|
CloudEventSchema,
|
|
27
27
|
type CloudEvent,
|
|
28
|
+
EventResultSchema,
|
|
29
|
+
type EventResult,
|
|
28
30
|
OnEventsInputSchema,
|
|
29
31
|
type OnEventsInput,
|
|
30
32
|
OnEventsOutputSchema,
|
|
@@ -56,6 +58,14 @@ export {
|
|
|
56
58
|
type EventAckInput,
|
|
57
59
|
EventAckOutputSchema,
|
|
58
60
|
type EventAckOutput,
|
|
61
|
+
SubscriptionItemSchema,
|
|
62
|
+
type SubscriptionItem,
|
|
63
|
+
SubscriptionDetailSchema,
|
|
64
|
+
type SubscriptionDetail,
|
|
65
|
+
EventSyncSubscriptionsInputSchema,
|
|
66
|
+
type EventSyncSubscriptionsInput,
|
|
67
|
+
EventSyncSubscriptionsOutputSchema,
|
|
68
|
+
type EventSyncSubscriptionsOutput,
|
|
59
69
|
EVENT_BUS_BINDING,
|
|
60
70
|
EventBusBinding,
|
|
61
71
|
type EventBusBindingClient,
|
|
@@ -45,22 +45,30 @@ const ComparisonExpressionSchema = z.object({
|
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* Where expression
|
|
49
|
-
*
|
|
48
|
+
* Where expression type for filtering
|
|
49
|
+
* Recursive to allow nested logical operators
|
|
50
50
|
*/
|
|
51
|
-
export
|
|
52
|
-
ComparisonExpressionSchema
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
]);
|
|
51
|
+
export type WhereExpression =
|
|
52
|
+
| z.infer<typeof ComparisonExpressionSchema>
|
|
53
|
+
| {
|
|
54
|
+
operator: "and" | "or" | "not";
|
|
55
|
+
conditions: WhereExpression[];
|
|
56
|
+
};
|
|
58
57
|
|
|
59
58
|
/**
|
|
60
|
-
* Where expression
|
|
61
|
-
*
|
|
59
|
+
* Where expression schema for filtering
|
|
60
|
+
* Supports TanStack DB predicate push-down patterns
|
|
61
|
+
* Recursive to allow nested logical operators
|
|
62
62
|
*/
|
|
63
|
-
export
|
|
63
|
+
export const WhereExpressionSchema: z.ZodType<WhereExpression> = z.lazy(() =>
|
|
64
|
+
z.union([
|
|
65
|
+
ComparisonExpressionSchema,
|
|
66
|
+
z.object({
|
|
67
|
+
operator: z.enum(["and", "or", "not"]),
|
|
68
|
+
conditions: z.array(WhereExpressionSchema),
|
|
69
|
+
}),
|
|
70
|
+
]),
|
|
71
|
+
);
|
|
64
72
|
|
|
65
73
|
/**
|
|
66
74
|
* Order by expression for sorting
|
|
@@ -159,6 +159,119 @@ export const EventSubscribeOutputSchema = z.object({
|
|
|
159
159
|
|
|
160
160
|
export type EventSubscribeOutput = z.infer<typeof EventSubscribeOutputSchema>;
|
|
161
161
|
|
|
162
|
+
// ============================================================================
|
|
163
|
+
// Sync Subscriptions Schemas
|
|
164
|
+
// ============================================================================
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Subscription item schema for sync operations
|
|
168
|
+
*/
|
|
169
|
+
export const SubscriptionItemSchema = z.object({
|
|
170
|
+
/** Event type pattern to match */
|
|
171
|
+
eventType: z.string().min(1).max(255).describe("Event type to subscribe to"),
|
|
172
|
+
|
|
173
|
+
/** Optional: Only receive events from this publisher connection */
|
|
174
|
+
publisher: z
|
|
175
|
+
.string()
|
|
176
|
+
.optional()
|
|
177
|
+
.describe("Filter events by publisher connection ID"),
|
|
178
|
+
|
|
179
|
+
/** Optional: JSONPath filter expression on event data */
|
|
180
|
+
filter: z
|
|
181
|
+
.string()
|
|
182
|
+
.max(1000)
|
|
183
|
+
.optional()
|
|
184
|
+
.describe("JSONPath filter expression on event data"),
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
export type SubscriptionItem = z.infer<typeof SubscriptionItemSchema>;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Subscription detail schema (returned in responses)
|
|
191
|
+
*/
|
|
192
|
+
export const SubscriptionDetailSchema = z.object({
|
|
193
|
+
/** Subscription ID */
|
|
194
|
+
id: z.string().describe("Subscription ID"),
|
|
195
|
+
|
|
196
|
+
/** Subscriber connection ID */
|
|
197
|
+
connectionId: z.string().describe("Subscriber connection ID"),
|
|
198
|
+
|
|
199
|
+
/** Event type pattern */
|
|
200
|
+
eventType: z.string().describe("Event type pattern"),
|
|
201
|
+
|
|
202
|
+
/** Publisher connection filter */
|
|
203
|
+
publisher: z.string().nullable().describe("Publisher connection filter"),
|
|
204
|
+
|
|
205
|
+
/** JSONPath filter */
|
|
206
|
+
filter: z.string().nullable().describe("JSONPath filter expression"),
|
|
207
|
+
|
|
208
|
+
/** Whether subscription is enabled */
|
|
209
|
+
enabled: z.boolean().describe("Whether subscription is enabled"),
|
|
210
|
+
|
|
211
|
+
/** Created timestamp */
|
|
212
|
+
createdAt: z.union([z.string(), z.date()]).describe("Created timestamp"),
|
|
213
|
+
|
|
214
|
+
/** Updated timestamp */
|
|
215
|
+
updatedAt: z.union([z.string(), z.date()]).describe("Updated timestamp"),
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
export type SubscriptionDetail = z.infer<typeof SubscriptionDetailSchema>;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* EVENT_SYNC_SUBSCRIPTIONS Input Schema
|
|
222
|
+
*
|
|
223
|
+
* Input for syncing subscriptions to a desired state.
|
|
224
|
+
* The system will create new, delete removed, and update changed subscriptions.
|
|
225
|
+
* Subscriptions are identified by (eventType, publisher) - only one subscription
|
|
226
|
+
* per combination is allowed.
|
|
227
|
+
*/
|
|
228
|
+
export const EventSyncSubscriptionsInputSchema = z.object({
|
|
229
|
+
/** Desired subscriptions - system will create/update/delete to match */
|
|
230
|
+
subscriptions: z
|
|
231
|
+
.array(SubscriptionItemSchema)
|
|
232
|
+
.describe(
|
|
233
|
+
"Desired subscriptions - system will create/update/delete to match",
|
|
234
|
+
),
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
export type EventSyncSubscriptionsInput = z.infer<
|
|
238
|
+
typeof EventSyncSubscriptionsInputSchema
|
|
239
|
+
>;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* EVENT_SYNC_SUBSCRIPTIONS Output Schema
|
|
243
|
+
*/
|
|
244
|
+
export const EventSyncSubscriptionsOutputSchema = z.object({
|
|
245
|
+
/** Number of new subscriptions created */
|
|
246
|
+
created: z.number().int().min(0).describe("Number of subscriptions created"),
|
|
247
|
+
|
|
248
|
+
/** Number of subscriptions with filter updated */
|
|
249
|
+
updated: z
|
|
250
|
+
.number()
|
|
251
|
+
.int()
|
|
252
|
+
.min(0)
|
|
253
|
+
.describe("Number of subscriptions with filter updated"),
|
|
254
|
+
|
|
255
|
+
/** Number of old subscriptions removed */
|
|
256
|
+
deleted: z.number().int().min(0).describe("Number of subscriptions removed"),
|
|
257
|
+
|
|
258
|
+
/** Number of subscriptions unchanged */
|
|
259
|
+
unchanged: z
|
|
260
|
+
.number()
|
|
261
|
+
.int()
|
|
262
|
+
.min(0)
|
|
263
|
+
.describe("Number of subscriptions unchanged"),
|
|
264
|
+
|
|
265
|
+
/** Current subscriptions after sync */
|
|
266
|
+
subscriptions: z
|
|
267
|
+
.array(SubscriptionDetailSchema)
|
|
268
|
+
.describe("Current subscriptions after sync"),
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
export type EventSyncSubscriptionsOutput = z.infer<
|
|
272
|
+
typeof EventSyncSubscriptionsOutputSchema
|
|
273
|
+
>;
|
|
274
|
+
|
|
162
275
|
// ============================================================================
|
|
163
276
|
// Unsubscribe Schemas
|
|
164
277
|
// ============================================================================
|
|
@@ -259,7 +372,7 @@ export type EventAckOutput = z.infer<typeof EventAckOutputSchema>;
|
|
|
259
372
|
* Event Bus Binding
|
|
260
373
|
*
|
|
261
374
|
* Defines the interface for interacting with an event bus.
|
|
262
|
-
* Implementations must provide PUBLISH, SUBSCRIBE, UNSUBSCRIBE, CANCEL, and
|
|
375
|
+
* Implementations must provide PUBLISH, SUBSCRIBE, UNSUBSCRIBE, CANCEL, ACK, and SYNC_SUBSCRIPTIONS tools.
|
|
263
376
|
*
|
|
264
377
|
* Required tools:
|
|
265
378
|
* - EVENT_PUBLISH: Publish an event (supports one-time, scheduled, and recurring via cron)
|
|
@@ -267,6 +380,7 @@ export type EventAckOutput = z.infer<typeof EventAckOutputSchema>;
|
|
|
267
380
|
* - EVENT_UNSUBSCRIBE: Remove a subscription
|
|
268
381
|
* - EVENT_CANCEL: Cancel a recurring event (stops future deliveries)
|
|
269
382
|
* - EVENT_ACK: Acknowledge event delivery (for async processing with retryAfter)
|
|
383
|
+
* - EVENT_SYNC_SUBSCRIPTIONS: Sync subscriptions to desired state
|
|
270
384
|
*/
|
|
271
385
|
export const EVENT_BUS_BINDING = [
|
|
272
386
|
{
|
|
@@ -294,6 +408,11 @@ export const EVENT_BUS_BINDING = [
|
|
|
294
408
|
inputSchema: EventAckInputSchema,
|
|
295
409
|
outputSchema: EventAckOutputSchema,
|
|
296
410
|
},
|
|
411
|
+
{
|
|
412
|
+
name: "EVENT_SYNC_SUBSCRIPTIONS" as const,
|
|
413
|
+
inputSchema: EventSyncSubscriptionsInputSchema,
|
|
414
|
+
outputSchema: EventSyncSubscriptionsOutputSchema,
|
|
415
|
+
},
|
|
297
416
|
] satisfies ToolBinder[];
|
|
298
417
|
|
|
299
418
|
/**
|
|
@@ -104,24 +104,74 @@ export const OnEventsInputSchema = z.object({
|
|
|
104
104
|
*/
|
|
105
105
|
export type OnEventsInput = z.infer<typeof OnEventsInputSchema>;
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Per-event result schema
|
|
109
|
+
* Allows granular control over each event in a batch
|
|
110
|
+
*/
|
|
111
|
+
export const EventResultSchema = z.object({
|
|
112
|
+
/** Whether this specific event was processed successfully */
|
|
113
|
+
success: z
|
|
114
|
+
.boolean()
|
|
115
|
+
.describe("Whether this event was processed successfully"),
|
|
116
|
+
|
|
117
|
+
/** Error message if success=false */
|
|
118
|
+
error: z.string().optional().describe("Error message for this event"),
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Request re-delivery of this event after this many milliseconds.
|
|
122
|
+
* Does not count toward max retry attempts.
|
|
123
|
+
*/
|
|
124
|
+
retryAfter: z
|
|
125
|
+
.number()
|
|
126
|
+
.int()
|
|
127
|
+
.positive()
|
|
128
|
+
.optional()
|
|
129
|
+
.describe("Re-deliver this event after this many ms"),
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Per-event result type
|
|
134
|
+
*/
|
|
135
|
+
export type EventResult = z.infer<typeof EventResultSchema>;
|
|
136
|
+
|
|
107
137
|
/**
|
|
108
138
|
* ON_EVENTS Output Schema
|
|
109
139
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
140
|
+
* Two modes of operation:
|
|
141
|
+
*
|
|
142
|
+
* 1. **Batch mode** (backward compatible): Use `success`, `error`, `retryAfter`
|
|
143
|
+
* to apply the same result to all events in the batch.
|
|
112
144
|
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
145
|
+
* 2. **Per-event mode**: Use `results` to specify individual outcomes for each event.
|
|
146
|
+
* Keys are event IDs, values are per-event results.
|
|
147
|
+
* Events not in `results` will use the batch-level fields as fallback.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* // Batch mode - all events succeeded
|
|
151
|
+
* { success: true }
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* // Per-event mode - mixed results
|
|
155
|
+
* {
|
|
156
|
+
* results: {
|
|
157
|
+
* "event-1": { success: true },
|
|
158
|
+
* "event-2": { success: false, error: "Validation failed" },
|
|
159
|
+
* "event-3": { retryAfter: 60000 }
|
|
160
|
+
* }
|
|
161
|
+
* }
|
|
116
162
|
*/
|
|
117
163
|
export const OnEventsOutputSchema = z.object({
|
|
118
|
-
/**
|
|
164
|
+
/** Batch-level success (applies to events not in `results`) */
|
|
119
165
|
success: z
|
|
120
166
|
.boolean()
|
|
121
|
-
.
|
|
167
|
+
.optional()
|
|
168
|
+
.describe("Batch success - applies to events not in results"),
|
|
122
169
|
|
|
123
|
-
/**
|
|
124
|
-
error: z
|
|
170
|
+
/** Batch-level error message */
|
|
171
|
+
error: z
|
|
172
|
+
.string()
|
|
173
|
+
.optional()
|
|
174
|
+
.describe("Batch error message - applies to events not in results"),
|
|
125
175
|
|
|
126
176
|
/** Optional count of successfully processed events */
|
|
127
177
|
processedCount: z
|
|
@@ -132,18 +182,24 @@ export const OnEventsOutputSchema = z.object({
|
|
|
132
182
|
.describe("Number of events successfully processed"),
|
|
133
183
|
|
|
134
184
|
/**
|
|
135
|
-
*
|
|
136
|
-
* Events remain pending until explicitly ACKed via EVENT_ACK.
|
|
137
|
-
* Does not count toward max retry attempts.
|
|
185
|
+
* Batch-level re-delivery request (applies to events not in `results`)
|
|
138
186
|
*/
|
|
139
187
|
retryAfter: z
|
|
140
188
|
.number()
|
|
141
189
|
.int()
|
|
142
190
|
.positive()
|
|
143
191
|
.optional()
|
|
144
|
-
.describe(
|
|
145
|
-
|
|
146
|
-
|
|
192
|
+
.describe("Batch retryAfter - applies to events not in results"),
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Per-event results, keyed by event ID.
|
|
196
|
+
* Allows different handling for each event in the batch.
|
|
197
|
+
* Events not specified here use batch-level fields as fallback.
|
|
198
|
+
*/
|
|
199
|
+
results: z
|
|
200
|
+
.record(z.string(), EventResultSchema)
|
|
201
|
+
.optional()
|
|
202
|
+
.describe("Per-event results keyed by event ID"),
|
|
147
203
|
});
|
|
148
204
|
|
|
149
205
|
/**
|