@notionhq/workers 0.5.0 → 0.7.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/alpha/ajv-formats.d.js +0 -0
- package/dist/alpha/builder.d.ts +149 -0
- package/dist/alpha/builder.d.ts.map +1 -0
- package/dist/alpha/builder.js +260 -0
- package/dist/alpha/builder.test.d.ts +2 -0
- package/dist/alpha/builder.test.d.ts.map +1 -0
- package/dist/alpha/cli/build.d.ts +13 -0
- package/dist/alpha/cli/build.d.ts.map +1 -0
- package/dist/alpha/cli/build.js +36 -0
- package/dist/alpha/cli/build.test.d.ts +2 -0
- package/dist/alpha/cli/build.test.d.ts.map +1 -0
- package/dist/alpha/cli/codegen.d.ts +10 -0
- package/dist/alpha/cli/codegen.d.ts.map +1 -0
- package/dist/alpha/cli/codegen.js +41 -0
- package/dist/alpha/cli/codegen.test.d.ts +2 -0
- package/dist/alpha/cli/codegen.test.d.ts.map +1 -0
- package/dist/alpha/cli/discover.d.ts +35 -0
- package/dist/alpha/cli/discover.d.ts.map +1 -0
- package/dist/alpha/cli/discover.js +39 -0
- package/dist/alpha/cli/discover.test.d.ts +2 -0
- package/dist/alpha/cli/discover.test.d.ts.map +1 -0
- package/dist/alpha/cli/emit-manifest.d.ts +33 -0
- package/dist/alpha/cli/emit-manifest.d.ts.map +1 -0
- package/dist/alpha/cli/emit-manifest.js +266 -0
- package/dist/alpha/cli/emit-manifest.test.d.ts +2 -0
- package/dist/alpha/cli/emit-manifest.test.d.ts.map +1 -0
- package/dist/alpha/cli/index.d.ts +3 -0
- package/dist/alpha/cli/index.d.ts.map +1 -0
- package/dist/alpha/cli/index.js +36 -0
- package/dist/alpha/context.d.ts +8 -0
- package/dist/alpha/context.d.ts.map +1 -0
- package/dist/alpha/context.js +33 -0
- package/dist/alpha/database.d.ts +90 -0
- package/dist/alpha/database.d.ts.map +1 -0
- package/dist/alpha/database.js +9 -0
- package/dist/alpha/error.d.ts +41 -0
- package/dist/alpha/error.d.ts.map +1 -0
- package/dist/alpha/error.js +25 -0
- package/dist/alpha/icon-names.d.ts +6 -0
- package/dist/alpha/icon-names.d.ts.map +1 -0
- package/dist/alpha/icon-names.js +0 -0
- package/dist/alpha/json-schema.d.ts +117 -0
- package/dist/alpha/json-schema.d.ts.map +1 -0
- package/dist/alpha/json-schema.js +0 -0
- package/dist/alpha/manifest.d.ts +44 -0
- package/dist/alpha/manifest.d.ts.map +1 -0
- package/dist/alpha/manifest.js +0 -0
- package/dist/alpha/output.d.ts +7 -0
- package/dist/alpha/output.d.ts.map +1 -0
- package/dist/alpha/output.js +8 -0
- package/dist/alpha/pacer.d.ts +74 -0
- package/dist/alpha/pacer.d.ts.map +1 -0
- package/dist/alpha/pacer.js +66 -0
- package/dist/alpha/pacer.test.d.ts +2 -0
- package/dist/alpha/pacer.test.d.ts.map +1 -0
- package/dist/alpha/schedule.d.ts +6 -0
- package/dist/alpha/schedule.d.ts.map +1 -0
- package/dist/alpha/schedule.js +43 -0
- package/dist/alpha/schedule.test.d.ts +2 -0
- package/dist/alpha/schedule.test.d.ts.map +1 -0
- package/dist/alpha/schema-builder.d.ts +79 -0
- package/dist/alpha/schema-builder.d.ts.map +1 -0
- package/dist/alpha/schema-builder.js +135 -0
- package/dist/alpha/schema.d.ts +185 -0
- package/dist/alpha/schema.d.ts.map +1 -0
- package/dist/alpha/schema.js +115 -0
- package/dist/alpha/sync.d.ts +233 -0
- package/dist/alpha/sync.d.ts.map +1 -0
- package/dist/alpha/sync.js +70 -0
- package/dist/alpha/sync.test.d.ts +2 -0
- package/dist/alpha/sync.test.d.ts.map +1 -0
- package/dist/alpha/tool.d.ts +132 -0
- package/dist/alpha/tool.d.ts.map +1 -0
- package/dist/alpha/tool.js +156 -0
- package/dist/alpha/tool.test.d.ts +2 -0
- package/dist/alpha/tool.test.d.ts.map +1 -0
- package/dist/alpha/triggers.d.ts +365 -0
- package/dist/alpha/triggers.d.ts.map +1 -0
- package/dist/alpha/triggers.generated.d.ts +246 -0
- package/dist/alpha/triggers.generated.d.ts.map +1 -0
- package/dist/alpha/triggers.generated.js +239 -0
- package/dist/alpha/triggers.js +0 -0
- package/dist/alpha/types.d.ts +228 -0
- package/dist/alpha/types.d.ts.map +1 -0
- package/dist/alpha/types.js +0 -0
- package/dist/alpha/workflow.d.ts +70 -0
- package/dist/alpha/workflow.d.ts.map +1 -0
- package/dist/alpha/workflow.js +39 -0
- package/dist/alpha/workflow.test.d.ts +2 -0
- package/dist/alpha/workflow.test.d.ts.map +1 -0
- package/dist/block.d.ts.map +1 -1
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +2 -6
- package/dist/capabilities/ai_connector.d.ts.map +1 -1
- package/dist/capabilities/automation.d.ts.map +1 -1
- package/dist/capabilities/context.d.ts.map +1 -1
- package/dist/capabilities/oauth.d.ts.map +1 -1
- package/dist/capabilities/output.d.ts.map +1 -1
- package/dist/capabilities/output.js +2 -4
- package/dist/capabilities/stateful-capability.d.ts.map +1 -1
- package/dist/capabilities/stateful-capability.js +2 -6
- package/dist/capabilities/sync.d.ts.map +1 -1
- package/dist/capabilities/sync.js +2 -8
- package/dist/capabilities/tool.d.ts.map +1 -1
- package/dist/capabilities/tool.js +6 -20
- package/dist/capabilities/webhook.d.ts.map +1 -1
- package/dist/capabilities/workflow.d.ts +2 -2
- package/dist/capabilities/workflow.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -7
- package/dist/json-schema.d.ts.map +1 -1
- package/dist/schema-builder.d.ts.map +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +1 -4
- package/package.json +74 -14
- package/src/alpha/ajv-formats.d.ts +7 -0
- package/src/alpha/builder.test.ts +197 -0
- package/src/alpha/builder.ts +338 -0
- package/src/alpha/cli/build.test.ts +240 -0
- package/src/alpha/cli/build.ts +57 -0
- package/src/alpha/cli/codegen.test.ts +31 -0
- package/src/alpha/cli/codegen.ts +51 -0
- package/src/alpha/cli/discover.test.ts +43 -0
- package/src/alpha/cli/discover.ts +81 -0
- package/src/alpha/cli/emit-manifest.test.ts +45 -0
- package/src/alpha/cli/emit-manifest.ts +409 -0
- package/src/alpha/cli/index.ts +41 -0
- package/src/alpha/context.ts +61 -0
- package/src/alpha/database.ts +102 -0
- package/src/alpha/error.ts +49 -0
- package/src/alpha/icon-names.ts +890 -0
- package/src/alpha/json-schema.ts +180 -0
- package/src/alpha/manifest.ts +47 -0
- package/src/alpha/output.ts +8 -0
- package/src/alpha/pacer.test.ts +81 -0
- package/src/alpha/pacer.ts +181 -0
- package/src/alpha/schedule.test.ts +31 -0
- package/src/alpha/schedule.ts +53 -0
- package/src/alpha/schema-builder.ts +193 -0
- package/src/alpha/schema.ts +222 -0
- package/src/alpha/sync.test.ts +191 -0
- package/src/alpha/sync.ts +340 -0
- package/src/alpha/tool.test.ts +116 -0
- package/src/alpha/tool.ts +319 -0
- package/src/alpha/triggers.generated.ts +489 -0
- package/src/alpha/triggers.ts +500 -0
- package/src/alpha/types.ts +284 -0
- package/src/alpha/workflow.test.ts +84 -0
- package/src/alpha/workflow.ts +131 -0
- package/src/block.ts +1 -5
- package/src/builder.test.ts +28 -60
- package/src/builder.ts +3 -10
- package/src/capabilities/ai_connector.test.ts +9 -32
- package/src/capabilities/ai_connector.ts +5 -17
- package/src/capabilities/automation.test.ts +3 -12
- package/src/capabilities/automation.ts +3 -11
- package/src/capabilities/context.ts +3 -6
- package/src/capabilities/oauth.test.ts +1 -0
- package/src/capabilities/oauth.ts +1 -3
- package/src/capabilities/output.ts +1 -3
- package/src/capabilities/stateful-capability.test.ts +1 -0
- package/src/capabilities/stateful-capability.ts +2 -6
- package/src/capabilities/sync.test.ts +15 -45
- package/src/capabilities/sync.ts +10 -40
- package/src/capabilities/tool.test.ts +106 -146
- package/src/capabilities/tool.ts +17 -39
- package/src/capabilities/webhook.ts +3 -10
- package/src/capabilities/workflow.test.ts +10 -31
- package/src/capabilities/workflow.ts +5 -12
- package/src/index.ts +2 -12
- package/src/json-schema.test.ts +2 -4
- package/src/json-schema.ts +7 -6
- package/src/pacer.test.ts +1 -3
- package/src/pacer_internal.ts +1 -5
- package/src/schema-builder.test.ts +10 -35
- package/src/schema-builder.ts +5 -16
- package/src/schema.ts +2 -10
- package/src/types.ts +1 -7
- package/src/worker.ts +8 -34
package/src/json-schema.ts
CHANGED
|
@@ -45,16 +45,18 @@ interface ForbiddenCompositionKeywords {
|
|
|
45
45
|
|
|
46
46
|
// ---- Individual schema definitions ----
|
|
47
47
|
|
|
48
|
-
export interface JSONSchemaStringDef<
|
|
49
|
-
extends
|
|
48
|
+
export interface JSONSchemaStringDef<
|
|
49
|
+
T extends string = string,
|
|
50
|
+
> extends ForbiddenCompositionKeywords {
|
|
50
51
|
type: "string";
|
|
51
52
|
description?: string;
|
|
52
53
|
format?: JSONSchemaStringFormat;
|
|
53
54
|
enum?: readonly T[];
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
export interface JSONSchemaNumberDef<
|
|
57
|
-
extends
|
|
57
|
+
export interface JSONSchemaNumberDef<
|
|
58
|
+
T extends number = number,
|
|
59
|
+
> extends ForbiddenCompositionKeywords {
|
|
58
60
|
type: "number" | "integer";
|
|
59
61
|
description?: string;
|
|
60
62
|
enum?: readonly T[];
|
|
@@ -70,8 +72,7 @@ export interface JSONSchemaNullDef extends ForbiddenCompositionKeywords {
|
|
|
70
72
|
description?: string;
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
export interface JSONSchemaArrayDef<E = unknown>
|
|
74
|
-
extends ForbiddenCompositionKeywords {
|
|
75
|
+
export interface JSONSchemaArrayDef<E = unknown> extends ForbiddenCompositionKeywords {
|
|
75
76
|
type: "array";
|
|
76
77
|
description?: string;
|
|
77
78
|
items: JSONSchema<E>;
|
package/src/pacer.test.ts
CHANGED
|
@@ -83,9 +83,7 @@ describe("pacerWait", () => {
|
|
|
83
83
|
it("throws when pacer key not found in runtime context", async () => {
|
|
84
84
|
setPacerState({ pacers: {} });
|
|
85
85
|
|
|
86
|
-
await expect(pacerWait("unknown")).rejects.toThrow(
|
|
87
|
-
'Pacer "unknown" not found',
|
|
88
|
-
);
|
|
86
|
+
await expect(pacerWait("unknown")).rejects.toThrow('Pacer "unknown" not found');
|
|
89
87
|
});
|
|
90
88
|
|
|
91
89
|
it("preserves allowedRequests and intervalMs across calls", async () => {
|
package/src/pacer_internal.ts
CHANGED
|
@@ -39,11 +39,7 @@ export function initPacerState(
|
|
|
39
39
|
declarations?: readonly PacerDeclaration[],
|
|
40
40
|
): void {
|
|
41
41
|
const pacers = runtimePacers ?? {};
|
|
42
|
-
if (
|
|
43
|
-
Object.keys(pacers).length === 0 &&
|
|
44
|
-
declarations &&
|
|
45
|
-
declarations.length > 0
|
|
46
|
-
) {
|
|
42
|
+
if (Object.keys(pacers).length === 0 && declarations && declarations.length > 0) {
|
|
47
43
|
const localPacers: Record<string, PacerEntry> = {};
|
|
48
44
|
for (const decl of declarations) {
|
|
49
45
|
localPacers[decl.key] = {
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
2
3
|
import type { JSONSchema } from "./json-schema.js";
|
|
3
|
-
import {
|
|
4
|
-
getSchema,
|
|
5
|
-
type Infer,
|
|
6
|
-
j,
|
|
7
|
-
type SchemaBuilder,
|
|
8
|
-
} from "./schema-builder.js";
|
|
4
|
+
import { getSchema, type Infer, j, type SchemaBuilder } from "./schema-builder.js";
|
|
9
5
|
|
|
10
6
|
// ---------------------------------------------------------------------------
|
|
11
7
|
// 1. Primitives
|
|
@@ -188,9 +184,7 @@ describe("json-schema-builder — array", () => {
|
|
|
188
184
|
});
|
|
189
185
|
|
|
190
186
|
it("array of objects", () => {
|
|
191
|
-
const schema = getSchema(
|
|
192
|
-
j.array(j.object({ name: j.string(), age: j.number() })),
|
|
193
|
-
);
|
|
187
|
+
const schema = getSchema(j.array(j.object({ name: j.string(), age: j.number() })));
|
|
194
188
|
expect(schema).toEqual({
|
|
195
189
|
type: "array",
|
|
196
190
|
items: {
|
|
@@ -351,9 +345,7 @@ describe("json-schema-builder — anyOf", () => {
|
|
|
351
345
|
});
|
|
352
346
|
|
|
353
347
|
it("anyOf with description", () => {
|
|
354
|
-
expect(
|
|
355
|
-
getSchema(j.anyOf(j.string(), j.number()).describe("string or number")),
|
|
356
|
-
).toEqual({
|
|
348
|
+
expect(getSchema(j.anyOf(j.string(), j.number()).describe("string or number"))).toEqual({
|
|
357
349
|
anyOf: [{ type: "string" }, { type: "number" }],
|
|
358
350
|
description: "string or number",
|
|
359
351
|
});
|
|
@@ -463,12 +455,8 @@ describe("json-schema-builder — discriminated unions", () => {
|
|
|
463
455
|
|
|
464
456
|
it("discriminated union with descriptions on individual variants", () => {
|
|
465
457
|
const schema = j.anyOf(
|
|
466
|
-
j
|
|
467
|
-
|
|
468
|
-
.describe("A text node"),
|
|
469
|
-
j
|
|
470
|
-
.object({ type: j.enum("image"), url: j.string() })
|
|
471
|
-
.describe("An image node"),
|
|
458
|
+
j.object({ type: j.enum("text"), value: j.string() }).describe("A text node"),
|
|
459
|
+
j.object({ type: j.enum("image"), url: j.string() }).describe("An image node"),
|
|
472
460
|
);
|
|
473
461
|
|
|
474
462
|
const raw = getSchema(schema) as unknown as {
|
|
@@ -497,9 +485,7 @@ describe("json-schema-builder — discriminated unions", () => {
|
|
|
497
485
|
expect(raw.properties.content.anyOf).toHaveLength(2);
|
|
498
486
|
|
|
499
487
|
// The content field is in required
|
|
500
|
-
expect(
|
|
501
|
-
(getSchema(schema) as unknown as Record<string, unknown>).required,
|
|
502
|
-
).toContain("content");
|
|
488
|
+
expect((getSchema(schema) as unknown as Record<string, unknown>).required).toContain("content");
|
|
503
489
|
});
|
|
504
490
|
|
|
505
491
|
it("nullable discriminated union", () => {
|
|
@@ -614,15 +600,7 @@ describe("json-schema-builder — integration", () => {
|
|
|
614
600
|
},
|
|
615
601
|
createdAt: { type: "string", format: "date-time" },
|
|
616
602
|
},
|
|
617
|
-
required: [
|
|
618
|
-
"foo",
|
|
619
|
-
"bar",
|
|
620
|
-
"count",
|
|
621
|
-
"tags",
|
|
622
|
-
"address",
|
|
623
|
-
"nickname",
|
|
624
|
-
"createdAt",
|
|
625
|
-
],
|
|
603
|
+
required: ["foo", "bar", "count", "tags", "address", "nickname", "createdAt"],
|
|
626
604
|
additionalProperties: false,
|
|
627
605
|
});
|
|
628
606
|
});
|
|
@@ -634,9 +612,7 @@ describe("json-schema-builder — integration", () => {
|
|
|
634
612
|
|
|
635
613
|
describe("json-schema-builder — constraint enforcement", () => {
|
|
636
614
|
it("object always has required matching properties keys", () => {
|
|
637
|
-
const schema = getSchema(
|
|
638
|
-
j.object({ x: j.number(), y: j.string(), z: j.boolean() }),
|
|
639
|
-
);
|
|
615
|
+
const schema = getSchema(j.object({ x: j.number(), y: j.string(), z: j.boolean() }));
|
|
640
616
|
const raw = schema as unknown as Record<string, unknown>;
|
|
641
617
|
expect(raw.required).toEqual(["x", "y", "z"]);
|
|
642
618
|
expect(raw.additionalProperties).toBe(false);
|
|
@@ -669,8 +645,7 @@ describe("json-schema-builder — constraint enforcement", () => {
|
|
|
669
645
|
}),
|
|
670
646
|
);
|
|
671
647
|
const raw = schema as unknown as Record<string, unknown>;
|
|
672
|
-
const outer = (raw as { properties: { outer: Record<string, unknown> } })
|
|
673
|
-
.properties.outer;
|
|
648
|
+
const outer = (raw as { properties: { outer: Record<string, unknown> } }).properties.outer;
|
|
674
649
|
expect(outer.required).toEqual(["inner"]);
|
|
675
650
|
expect(outer.additionalProperties).toBe(false);
|
|
676
651
|
});
|
package/src/schema-builder.ts
CHANGED
|
@@ -47,12 +47,8 @@ function makeBuilder<T>(schema: AnyJSONSchema): SchemaBuilder<T> {
|
|
|
47
47
|
return makeBuilder<T>({ ...schema, description: text });
|
|
48
48
|
},
|
|
49
49
|
nullable() {
|
|
50
|
-
const { description: desc, ...rest } = schema as unknown as Record<
|
|
51
|
-
|
|
52
|
-
unknown
|
|
53
|
-
>;
|
|
54
|
-
const inner =
|
|
55
|
-
desc !== undefined ? (rest as unknown as AnyJSONSchema) : schema;
|
|
50
|
+
const { description: desc, ...rest } = schema as unknown as Record<string, unknown>;
|
|
51
|
+
const inner = desc !== undefined ? (rest as unknown as AnyJSONSchema) : schema;
|
|
56
52
|
const wrapper: Record<string, unknown> = {
|
|
57
53
|
anyOf: [inner, { type: "null" }],
|
|
58
54
|
};
|
|
@@ -82,15 +78,9 @@ export function boolean(): SchemaBuilder<boolean> {
|
|
|
82
78
|
|
|
83
79
|
// ---- Enum ----
|
|
84
80
|
|
|
85
|
-
function enumBuilder<T extends string>(
|
|
86
|
-
|
|
87
|
-
): SchemaBuilder<
|
|
88
|
-
function enumBuilder<T extends number>(
|
|
89
|
-
...values: readonly T[]
|
|
90
|
-
): SchemaBuilder<T>;
|
|
91
|
-
function enumBuilder(
|
|
92
|
-
...values: readonly (string | number)[]
|
|
93
|
-
): SchemaBuilder<unknown> {
|
|
81
|
+
function enumBuilder<T extends string>(...values: readonly T[]): SchemaBuilder<T>;
|
|
82
|
+
function enumBuilder<T extends number>(...values: readonly T[]): SchemaBuilder<T>;
|
|
83
|
+
function enumBuilder(...values: readonly (string | number)[]): SchemaBuilder<unknown> {
|
|
94
84
|
const type = typeof values[0] === "string" ? "string" : "number";
|
|
95
85
|
return makeBuilder({ type, enum: values } as AnyJSONSchema);
|
|
96
86
|
}
|
|
@@ -155,7 +145,6 @@ export function object<P extends Record<string, SchemaBuilder<unknown>>>(
|
|
|
155
145
|
const schemaProps: Record<string, AnyJSONSchema> = {};
|
|
156
146
|
const keys = Object.keys(properties);
|
|
157
147
|
for (const key of keys) {
|
|
158
|
-
// biome-ignore lint/style/noNonNullAssertion: key comes from Object.keys(properties)
|
|
159
148
|
schemaProps[key] = getSchema(properties[key]!);
|
|
160
149
|
}
|
|
161
150
|
return makeBuilder({
|
package/src/schema.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
DateFormat,
|
|
3
|
-
Icon,
|
|
4
|
-
NumberFormat,
|
|
5
|
-
SelectOption,
|
|
6
|
-
StatusGroup,
|
|
7
|
-
} from "./types.js";
|
|
1
|
+
import type { DateFormat, Icon, NumberFormat, SelectOption, StatusGroup } from "./types.js";
|
|
8
2
|
|
|
9
3
|
/**
|
|
10
4
|
* Supported property types for sync schemas.
|
|
@@ -182,9 +176,7 @@ export function multiSelect(options: SelectOption[]): PropertyConfiguration {
|
|
|
182
176
|
/**
|
|
183
177
|
* Creates a status property definition with groups.
|
|
184
178
|
*/
|
|
185
|
-
export function status(config: {
|
|
186
|
-
groups: StatusGroup[];
|
|
187
|
-
}): PropertyConfiguration {
|
|
179
|
+
export function status(config: { groups: StatusGroup[] }): PropertyConfiguration {
|
|
188
180
|
return { type: "status", groups: config.groups };
|
|
189
181
|
}
|
|
190
182
|
|
package/src/types.ts
CHANGED
|
@@ -118,13 +118,7 @@ export type NumberFormat =
|
|
|
118
118
|
/**
|
|
119
119
|
* Date format types
|
|
120
120
|
*/
|
|
121
|
-
export type DateFormat =
|
|
122
|
-
| "relative"
|
|
123
|
-
| "MM/DD/YYYY"
|
|
124
|
-
| "DD/MM/YYYY"
|
|
125
|
-
| "YYYY/MM/DD"
|
|
126
|
-
| "ll"
|
|
127
|
-
| "MMM d";
|
|
121
|
+
export type DateFormat = "relative" | "MM/DD/YYYY" | "DD/MM/YYYY" | "YYYY/MM/DD" | "ll" | "MMM d";
|
|
128
122
|
|
|
129
123
|
import type { NoticonName } from "./icon-names.js";
|
|
130
124
|
|
package/src/worker.ts
CHANGED
|
@@ -27,10 +27,7 @@ import type {
|
|
|
27
27
|
WebhookConfiguration,
|
|
28
28
|
WebhookEvent,
|
|
29
29
|
} from "./capabilities/webhook.js";
|
|
30
|
-
import {
|
|
31
|
-
createWebhookCapability,
|
|
32
|
-
WebhookVerificationError,
|
|
33
|
-
} from "./capabilities/webhook.js";
|
|
30
|
+
import { createWebhookCapability, WebhookVerificationError } from "./capabilities/webhook.js";
|
|
34
31
|
import type {
|
|
35
32
|
WorkflowCapability,
|
|
36
33
|
WorkflowConfiguration,
|
|
@@ -68,7 +65,6 @@ export { WebhookVerificationError };
|
|
|
68
65
|
type Capability =
|
|
69
66
|
| SyncCapability
|
|
70
67
|
| AiConnectorCapability
|
|
71
|
-
// biome-ignore lint/suspicious/noExplicitAny: tool capabilities are generic over arbitrary input/output payloads.
|
|
72
68
|
| ToolCapability<any, any>
|
|
73
69
|
| AutomationCapability
|
|
74
70
|
| WorkflowCapability
|
|
@@ -92,19 +88,13 @@ export type CapabilityType = Capability["_tag"];
|
|
|
92
88
|
// incoming context matches the capability's declared input.
|
|
93
89
|
|
|
94
90
|
/** A tool capability as stored: its input/output types are erased. */
|
|
95
|
-
type StoredToolCapability = Omit<
|
|
96
|
-
Extract<Capability, { _tag: "tool" }>,
|
|
97
|
-
"handler"
|
|
98
|
-
> & {
|
|
91
|
+
type StoredToolCapability = Omit<Extract<Capability, { _tag: "tool" }>, "handler"> & {
|
|
99
92
|
handler: (input: never, options?: HandlerOptions) => Promise<unknown>;
|
|
100
93
|
};
|
|
101
94
|
|
|
102
95
|
/** A workflow capability as stored: its event type is erased. */
|
|
103
96
|
type StoredWorkflowCapability = Omit<WorkflowCapability, "handler"> & {
|
|
104
|
-
handler: (
|
|
105
|
-
event: never,
|
|
106
|
-
options?: HandlerOptions,
|
|
107
|
-
) => Promise<{ status: "success" } | undefined>;
|
|
97
|
+
handler: (event: never, options?: HandlerOptions) => Promise<{ status: "success" } | undefined>;
|
|
108
98
|
};
|
|
109
99
|
|
|
110
100
|
/** How `Worker` stores registered capabilities internally. */
|
|
@@ -148,10 +138,7 @@ export type ManagedDatabaseConfig<PK extends string, S extends Schema<PK>> = {
|
|
|
148
138
|
* Configuration union for all database types.
|
|
149
139
|
* Currently only `"managed"` is supported.
|
|
150
140
|
*/
|
|
151
|
-
export type DatabaseConfig<
|
|
152
|
-
PK extends string,
|
|
153
|
-
S extends Schema<PK>,
|
|
154
|
-
> = ManagedDatabaseConfig<PK, S>;
|
|
141
|
+
export type DatabaseConfig<PK extends string, S extends Schema<PK>> = ManagedDatabaseConfig<PK, S>;
|
|
155
142
|
|
|
156
143
|
/**
|
|
157
144
|
* An opaque handle returned by `worker.database()`. Pass this to
|
|
@@ -495,10 +482,7 @@ export class Worker {
|
|
|
495
482
|
* @param config - The automation configuration.
|
|
496
483
|
* @returns The capability object.
|
|
497
484
|
*/
|
|
498
|
-
automation(
|
|
499
|
-
key: string,
|
|
500
|
-
config: AutomationConfiguration,
|
|
501
|
-
): AutomationCapability {
|
|
485
|
+
automation(key: string, config: AutomationConfiguration): AutomationCapability {
|
|
502
486
|
this.#validateUniqueKey(key);
|
|
503
487
|
const capability = createAutomationCapability(key, config);
|
|
504
488
|
this.#capabilities.set(key, capability);
|
|
@@ -532,9 +516,7 @@ export class Worker {
|
|
|
532
516
|
* @param config - The workflow configuration.
|
|
533
517
|
* @returns The capability object.
|
|
534
518
|
*/
|
|
535
|
-
workflow<
|
|
536
|
-
const TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]],
|
|
537
|
-
>(
|
|
519
|
+
workflow<const TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]]>(
|
|
538
520
|
key: string,
|
|
539
521
|
config: WorkflowConfiguration<TTriggers>,
|
|
540
522
|
): WorkflowCapability<TTriggers> {
|
|
@@ -655,11 +637,7 @@ export class Worker {
|
|
|
655
637
|
* @param options - Additional options for execution (e.g. for testing).
|
|
656
638
|
* @returns The result of the capability execution.
|
|
657
639
|
*/
|
|
658
|
-
async run(
|
|
659
|
-
key: string,
|
|
660
|
-
context: unknown,
|
|
661
|
-
options: HandlerOptions = {},
|
|
662
|
-
): Promise<unknown> {
|
|
640
|
+
async run(key: string, context: unknown, options: HandlerOptions = {}): Promise<unknown> {
|
|
663
641
|
const capability = this.#capabilities.get(key);
|
|
664
642
|
|
|
665
643
|
if (!capability) {
|
|
@@ -687,11 +665,7 @@ export class Worker {
|
|
|
687
665
|
if (!key || typeof key !== "string") {
|
|
688
666
|
throw new Error("Capability key must be a non-empty string");
|
|
689
667
|
}
|
|
690
|
-
if (
|
|
691
|
-
this.#capabilities.has(key) ||
|
|
692
|
-
this.#databases.has(key) ||
|
|
693
|
-
this.#pacers.has(key)
|
|
694
|
-
) {
|
|
668
|
+
if (this.#capabilities.has(key) || this.#databases.has(key) || this.#pacers.has(key)) {
|
|
695
669
|
throw new Error(`Worker item with key "${key}" already registered`);
|
|
696
670
|
}
|
|
697
671
|
}
|