@notionhq/workers 0.4.0 → 0.6.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.
Files changed (204) hide show
  1. package/dist/alpha/builder.d.ts +149 -0
  2. package/dist/alpha/builder.d.ts.map +1 -0
  3. package/dist/alpha/builder.js +260 -0
  4. package/dist/alpha/builder.test.d.ts +2 -0
  5. package/dist/alpha/builder.test.d.ts.map +1 -0
  6. package/dist/alpha/cli/build.d.ts +13 -0
  7. package/dist/alpha/cli/build.d.ts.map +1 -0
  8. package/dist/alpha/cli/build.js +36 -0
  9. package/dist/alpha/cli/build.test.d.ts +2 -0
  10. package/dist/alpha/cli/build.test.d.ts.map +1 -0
  11. package/dist/alpha/cli/codegen.d.ts +10 -0
  12. package/dist/alpha/cli/codegen.d.ts.map +1 -0
  13. package/dist/alpha/cli/codegen.js +41 -0
  14. package/dist/alpha/cli/codegen.test.d.ts +2 -0
  15. package/dist/alpha/cli/codegen.test.d.ts.map +1 -0
  16. package/dist/alpha/cli/discover.d.ts +35 -0
  17. package/dist/alpha/cli/discover.d.ts.map +1 -0
  18. package/dist/alpha/cli/discover.js +39 -0
  19. package/dist/alpha/cli/discover.test.d.ts +2 -0
  20. package/dist/alpha/cli/discover.test.d.ts.map +1 -0
  21. package/dist/alpha/cli/emit-manifest.d.ts +33 -0
  22. package/dist/alpha/cli/emit-manifest.d.ts.map +1 -0
  23. package/dist/alpha/cli/emit-manifest.js +266 -0
  24. package/dist/alpha/cli/emit-manifest.test.d.ts +2 -0
  25. package/dist/alpha/cli/emit-manifest.test.d.ts.map +1 -0
  26. package/dist/alpha/cli/index.d.ts +3 -0
  27. package/dist/alpha/cli/index.d.ts.map +1 -0
  28. package/dist/alpha/cli/index.js +36 -0
  29. package/dist/alpha/context.d.ts +8 -0
  30. package/dist/alpha/context.d.ts.map +1 -0
  31. package/dist/alpha/context.js +33 -0
  32. package/dist/alpha/database.d.ts +90 -0
  33. package/dist/alpha/database.d.ts.map +1 -0
  34. package/dist/alpha/database.js +9 -0
  35. package/dist/alpha/error.d.ts +41 -0
  36. package/dist/alpha/error.d.ts.map +1 -0
  37. package/dist/alpha/error.js +25 -0
  38. package/dist/alpha/icon-names.d.ts +6 -0
  39. package/dist/alpha/icon-names.d.ts.map +1 -0
  40. package/dist/alpha/icon-names.js +0 -0
  41. package/dist/alpha/json-schema.d.ts +117 -0
  42. package/dist/alpha/json-schema.d.ts.map +1 -0
  43. package/dist/alpha/json-schema.js +0 -0
  44. package/dist/alpha/manifest.d.ts +44 -0
  45. package/dist/alpha/manifest.d.ts.map +1 -0
  46. package/dist/alpha/manifest.js +0 -0
  47. package/dist/alpha/output.d.ts +7 -0
  48. package/dist/alpha/output.d.ts.map +1 -0
  49. package/dist/alpha/output.js +8 -0
  50. package/dist/alpha/pacer.d.ts +74 -0
  51. package/dist/alpha/pacer.d.ts.map +1 -0
  52. package/dist/alpha/pacer.js +66 -0
  53. package/dist/alpha/pacer.test.d.ts +2 -0
  54. package/dist/alpha/pacer.test.d.ts.map +1 -0
  55. package/dist/alpha/schedule.d.ts +6 -0
  56. package/dist/alpha/schedule.d.ts.map +1 -0
  57. package/dist/alpha/schedule.js +43 -0
  58. package/dist/alpha/schedule.test.d.ts +2 -0
  59. package/dist/alpha/schedule.test.d.ts.map +1 -0
  60. package/dist/alpha/schema-builder.d.ts +79 -0
  61. package/dist/alpha/schema-builder.d.ts.map +1 -0
  62. package/dist/alpha/schema-builder.js +135 -0
  63. package/dist/alpha/schema.d.ts +185 -0
  64. package/dist/alpha/schema.d.ts.map +1 -0
  65. package/dist/alpha/schema.js +115 -0
  66. package/dist/alpha/sync.d.ts +233 -0
  67. package/dist/alpha/sync.d.ts.map +1 -0
  68. package/dist/alpha/sync.js +70 -0
  69. package/dist/alpha/sync.test.d.ts +2 -0
  70. package/dist/alpha/sync.test.d.ts.map +1 -0
  71. package/dist/alpha/tool.d.ts +132 -0
  72. package/dist/alpha/tool.d.ts.map +1 -0
  73. package/dist/alpha/tool.js +156 -0
  74. package/dist/alpha/tool.test.d.ts +2 -0
  75. package/dist/alpha/tool.test.d.ts.map +1 -0
  76. package/dist/alpha/triggers.d.ts +365 -0
  77. package/dist/alpha/triggers.d.ts.map +1 -0
  78. package/dist/alpha/triggers.generated.d.ts +246 -0
  79. package/dist/alpha/triggers.generated.d.ts.map +1 -0
  80. package/dist/alpha/triggers.generated.js +239 -0
  81. package/dist/alpha/triggers.js +0 -0
  82. package/dist/alpha/types.d.ts +228 -0
  83. package/dist/alpha/types.d.ts.map +1 -0
  84. package/dist/alpha/types.js +0 -0
  85. package/dist/alpha/workflow.d.ts +70 -0
  86. package/dist/alpha/workflow.d.ts.map +1 -0
  87. package/dist/alpha/workflow.js +39 -0
  88. package/dist/alpha/workflow.test.d.ts +2 -0
  89. package/dist/alpha/workflow.test.d.ts.map +1 -0
  90. package/dist/builder.d.ts +7 -1
  91. package/dist/builder.d.ts.map +1 -1
  92. package/dist/builder.js +12 -3
  93. package/dist/capabilities/ai_connector.d.ts.map +1 -1
  94. package/dist/capabilities/automation.d.ts.map +1 -1
  95. package/dist/capabilities/context.d.ts.map +1 -1
  96. package/dist/capabilities/context.js +1 -1
  97. package/dist/capabilities/custom-block.d.ts +124 -0
  98. package/dist/capabilities/custom-block.d.ts.map +1 -0
  99. package/dist/capabilities/custom-block.js +22 -0
  100. package/dist/capabilities/oauth.d.ts.map +1 -1
  101. package/dist/capabilities/output.d.ts.map +1 -1
  102. package/dist/capabilities/output.js +2 -4
  103. package/dist/capabilities/stateful-capability.d.ts.map +1 -1
  104. package/dist/capabilities/stateful-capability.js +3 -7
  105. package/dist/capabilities/sync.d.ts +11 -1
  106. package/dist/capabilities/sync.d.ts.map +1 -1
  107. package/dist/capabilities/sync.js +2 -8
  108. package/dist/capabilities/tool.d.ts.map +1 -1
  109. package/dist/capabilities/tool.js +6 -20
  110. package/dist/capabilities/webhook.d.ts.map +1 -1
  111. package/dist/capabilities/workflow.d.ts +50 -0
  112. package/dist/capabilities/workflow.d.ts.map +1 -0
  113. package/dist/capabilities/workflow.js +40 -0
  114. package/dist/capabilities/workflow.test.d.ts +2 -0
  115. package/dist/capabilities/workflow.test.d.ts.map +1 -0
  116. package/dist/index.d.ts +5 -3
  117. package/dist/index.d.ts.map +1 -1
  118. package/dist/index.js +2 -1
  119. package/dist/json-schema.d.ts.map +1 -1
  120. package/dist/schema-builder.d.ts.map +1 -1
  121. package/dist/schema.d.ts.map +1 -1
  122. package/dist/triggers.d.ts +365 -0
  123. package/dist/triggers.d.ts.map +1 -0
  124. package/dist/triggers.generated.d.ts +246 -0
  125. package/dist/triggers.generated.d.ts.map +1 -0
  126. package/dist/triggers.generated.js +239 -0
  127. package/dist/triggers.js +0 -0
  128. package/dist/types.d.ts +18 -0
  129. package/dist/types.d.ts.map +1 -1
  130. package/dist/worker.d.ts +72 -2
  131. package/dist/worker.d.ts.map +1 -1
  132. package/dist/worker.js +85 -4
  133. package/package.json +81 -14
  134. package/src/alpha/ajv-formats.d.ts +7 -0
  135. package/src/alpha/builder.test.ts +197 -0
  136. package/src/alpha/builder.ts +338 -0
  137. package/src/alpha/cli/build.test.ts +240 -0
  138. package/src/alpha/cli/build.ts +57 -0
  139. package/src/alpha/cli/codegen.test.ts +31 -0
  140. package/src/alpha/cli/codegen.ts +51 -0
  141. package/src/alpha/cli/discover.test.ts +43 -0
  142. package/src/alpha/cli/discover.ts +81 -0
  143. package/src/alpha/cli/emit-manifest.test.ts +45 -0
  144. package/src/alpha/cli/emit-manifest.ts +409 -0
  145. package/src/alpha/cli/index.ts +41 -0
  146. package/src/alpha/context.ts +61 -0
  147. package/src/alpha/database.ts +102 -0
  148. package/src/alpha/error.ts +49 -0
  149. package/src/alpha/icon-names.ts +890 -0
  150. package/src/alpha/json-schema.ts +180 -0
  151. package/src/alpha/manifest.ts +47 -0
  152. package/src/alpha/output.ts +8 -0
  153. package/src/alpha/pacer.test.ts +81 -0
  154. package/src/alpha/pacer.ts +181 -0
  155. package/src/alpha/schedule.test.ts +31 -0
  156. package/src/alpha/schedule.ts +53 -0
  157. package/src/alpha/schema-builder.ts +193 -0
  158. package/src/alpha/schema.ts +222 -0
  159. package/src/alpha/sync.test.ts +191 -0
  160. package/src/alpha/sync.ts +340 -0
  161. package/src/alpha/tool.test.ts +116 -0
  162. package/src/alpha/tool.ts +319 -0
  163. package/src/alpha/triggers.generated.ts +489 -0
  164. package/src/alpha/triggers.ts +500 -0
  165. package/src/alpha/types.ts +284 -0
  166. package/src/alpha/workflow.test.ts +84 -0
  167. package/src/alpha/workflow.ts +131 -0
  168. package/src/builder.test.ts +28 -60
  169. package/src/builder.ts +20 -7
  170. package/src/capabilities/ai_connector.test.ts +9 -32
  171. package/src/capabilities/ai_connector.ts +5 -17
  172. package/src/capabilities/automation.test.ts +3 -12
  173. package/src/capabilities/automation.ts +3 -11
  174. package/src/capabilities/context.ts +5 -8
  175. package/src/capabilities/custom-block.ts +181 -0
  176. package/src/capabilities/oauth.test.ts +1 -0
  177. package/src/capabilities/oauth.ts +1 -3
  178. package/src/capabilities/output.ts +1 -3
  179. package/src/capabilities/stateful-capability.test.ts +1 -0
  180. package/src/capabilities/stateful-capability.ts +3 -7
  181. package/src/capabilities/sync.test.ts +76 -42
  182. package/src/capabilities/sync.ts +16 -40
  183. package/src/capabilities/tool.test.ts +106 -146
  184. package/src/capabilities/tool.ts +17 -39
  185. package/src/capabilities/webhook.ts +3 -10
  186. package/src/capabilities/workflow.test.ts +163 -0
  187. package/src/capabilities/workflow.ts +112 -0
  188. package/src/index.ts +18 -6
  189. package/src/json-schema.test.ts +2 -4
  190. package/src/json-schema.ts +7 -6
  191. package/src/pacer.test.ts +1 -3
  192. package/src/pacer_internal.ts +1 -5
  193. package/src/schema-builder.test.ts +10 -35
  194. package/src/schema-builder.ts +6 -16
  195. package/src/schema.ts +2 -10
  196. package/src/triggers.generated.ts +489 -0
  197. package/src/triggers.ts +504 -0
  198. package/src/types.ts +21 -7
  199. package/src/worker.test.ts +147 -0
  200. package/src/worker.ts +155 -32
  201. package/dist/block.d.ts +0 -321
  202. package/dist/block.d.ts.map +0 -1
  203. package/src/block.ts +0 -529
  204. /package/dist/{block.js → alpha/ajv-formats.d.js} +0 -0
@@ -0,0 +1,117 @@
1
+ /**
2
+ * JSON Schema types compatible with both Anthropic and OpenAI structured
3
+ * output APIs.
4
+ *
5
+ * Constraints enforced by this type (intersection of both providers):
6
+ * - Objects must have `additionalProperties: false`
7
+ * - All object properties should be listed in `required`
8
+ * (use `anyOf` with `null` for optional fields)
9
+ * - No recursive schemas
10
+ * - No `allOf`, `not`, `if/then/else`
11
+ * - No string constraints (`minLength`, `maxLength`, `pattern`)
12
+ * - No number constraints (`minimum`, `maximum`, `multipleOf`)
13
+ * - Array `minItems` limited to 0 or 1; no `maxItems`
14
+ * - String `format` limited to: date-time, time, date, duration,
15
+ * email, hostname, ipv4, ipv6, uuid
16
+ * - `$ref` and `$defs` supported (no external refs)
17
+ */
18
+ /**
19
+ * String formats supported by both Anthropic and OpenAI structured outputs.
20
+ */
21
+ export type JSONSchemaStringFormat = "date-time" | "time" | "date" | "duration" | "email" | "hostname" | "ipv4" | "ipv6" | "uuid";
22
+ interface ForbiddenCompositionKeywords {
23
+ anyOf?: never;
24
+ allOf?: never;
25
+ not?: never;
26
+ if?: never;
27
+ then?: never;
28
+ else?: never;
29
+ }
30
+ export interface JSONSchemaStringDef<T extends string = string> extends ForbiddenCompositionKeywords {
31
+ type: "string";
32
+ description?: string;
33
+ format?: JSONSchemaStringFormat;
34
+ enum?: readonly T[];
35
+ }
36
+ export interface JSONSchemaNumberDef<T extends number = number> extends ForbiddenCompositionKeywords {
37
+ type: "number" | "integer";
38
+ description?: string;
39
+ enum?: readonly T[];
40
+ }
41
+ export interface JSONSchemaBooleanDef extends ForbiddenCompositionKeywords {
42
+ type: "boolean";
43
+ description?: string;
44
+ }
45
+ export interface JSONSchemaNullDef extends ForbiddenCompositionKeywords {
46
+ type: "null";
47
+ description?: string;
48
+ }
49
+ export interface JSONSchemaArrayDef<E = unknown> extends ForbiddenCompositionKeywords {
50
+ type: "array";
51
+ description?: string;
52
+ items: JSONSchema<E>;
53
+ minItems?: 0 | 1;
54
+ }
55
+ export interface JSONSchemaObjectDef<T extends Record<string, unknown> = Record<string, unknown>> extends ForbiddenCompositionKeywords {
56
+ type: "object";
57
+ description?: string;
58
+ properties: {
59
+ [K in keyof T]-?: JSONSchema<T[K]>;
60
+ };
61
+ required: readonly (keyof T & string)[];
62
+ additionalProperties: false;
63
+ $defs?: Record<string, AnyJSONSchema>;
64
+ }
65
+ export interface JSONSchemaRefDef extends ForbiddenCompositionKeywords {
66
+ $ref: string;
67
+ description?: string;
68
+ }
69
+ export interface JSONSchemaAnyOfDef<T = unknown> {
70
+ anyOf: readonly JSONSchema<T>[];
71
+ description?: string;
72
+ }
73
+ export type AnyJSONSchema = JSONSchemaStringDef | JSONSchemaNumberDef | JSONSchemaBooleanDef | JSONSchemaNullDef | JSONSchemaArrayDef | JSONSchemaObjectDef | JSONSchemaRefDef | JSONSchemaAnyOfDef;
74
+ /**
75
+ * Maps a TypeScript type T to its corresponding JSON Schema definition.
76
+ *
77
+ * Uses `[T] extends [X]` (non-distributing) so that union types like
78
+ * `string | number` fall through to `AnyJSONSchema` instead of distributing
79
+ * into `JSONSchemaStringDef | JSONSchemaNumberDef`.
80
+ *
81
+ * The `T & X` intersections (e.g. `T & string`) satisfy the generic
82
+ * constraints on each def without widening T.
83
+ *
84
+ * A `$ref` is always valid in any schema position, so `JSONSchemaRefDef`
85
+ * is unioned in at the end.
86
+ */
87
+ type JSONSchemaFor<T> = JSONSchemaRefDef | ([T] extends [string] ? JSONSchemaStringDef<T & string> : [T] extends [number] ? JSONSchemaNumberDef<T & number> : [T] extends [boolean] ? JSONSchemaBooleanDef : [T] extends [readonly (infer E)[]] ? JSONSchemaArrayDef<E> : [T] extends [Record<string, unknown>] ? JSONSchemaObjectDef<T & Record<string, unknown>> : AnyJSONSchema);
88
+ /**
89
+ * Wraps a non-null schema in an `anyOf` with `{ type: "null" }` for
90
+ * nullable types (e.g. `string | null`).
91
+ */
92
+ type JSONSchemaNullable<T> = {
93
+ anyOf: readonly [JSONSchemaFor<T>, JSONSchemaNullDef];
94
+ description?: string;
95
+ };
96
+ /**
97
+ * A JSON Schema definition compatible with both Anthropic and OpenAI
98
+ * structured output APIs.
99
+ *
100
+ * When the generic parameter `T` is provided, the schema structure is
101
+ * constrained at compile time to match `T`:
102
+ *
103
+ * ```ts
104
+ * // Schema is checked against the type:
105
+ * const schema: JSONSchema<{ name: string }> = {
106
+ * type: "object",
107
+ * properties: { name: { type: "string" } },
108
+ * required: ["name"],
109
+ * additionalProperties: false,
110
+ * };
111
+ * ```
112
+ *
113
+ * @template T - The TypeScript type the schema should describe.
114
+ */
115
+ export type JSONSchema<T = unknown> = unknown extends T ? AnyJSONSchema : null extends T ? JSONSchemaNullable<NonNullable<T>> : JSONSchemaFor<T>;
116
+ export {};
117
+ //# sourceMappingURL=json-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../../src/alpha/json-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAC/B,WAAW,GACX,MAAM,GACN,MAAM,GACN,UAAU,GACV,OAAO,GACP,UAAU,GACV,MAAM,GACN,MAAM,GACN,MAAM,CAAC;AAMV,UAAU,4BAA4B;IACrC,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,GAAG,CAAC,EAAE,KAAK,CAAC;IACZ,EAAE,CAAC,EAAE,KAAK,CAAC;IACX,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,IAAI,CAAC,EAAE,KAAK,CAAC;CACb;AAID,MAAM,WAAW,mBAAmB,CACnC,CAAC,SAAS,MAAM,GAAG,MAAM,CACxB,SAAQ,4BAA4B;IACrC,IAAI,EAAE,QAAQ,C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iB,CAAC,CAAC;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAIF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,OAAO,IAAI,OAAO,SAAS,CAAC,GACpD,aAAa,GACb,IAAI,SAAS,CAAC,GACb,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAClC,aAAa,CAAC,CAAC,CAAC,CAAC"}
File without changes
@@ -0,0 +1,44 @@
1
+ /**
2
+ * A capability type identifier (e.g. "sync", "tool"). The set of types the
3
+ * build tool can discover is defined by `CAPABILITY_TYPES` in the CLI; the
4
+ * manifest treats the type as an opaque string.
5
+ */
6
+ export type CapabilityType = string;
7
+ /**
8
+ * One capability in the manifest: its type, its key (derived from its
9
+ * filename), and its handler-free configuration.
10
+ */
11
+ export type CapabilityManifestEntry = {
12
+ type: CapabilityType;
13
+ key: string;
14
+ config: unknown;
15
+ };
16
+ /**
17
+ * One database in the manifest: its key (derived from its filename under
18
+ * `src/databases/`, or from the owning sync's key for inline databases)
19
+ * and its configuration, with `relation` properties resolved to
20
+ * `relatedDatabaseKey` references.
21
+ */
22
+ export type DatabaseManifestEntry = {
23
+ key: string;
24
+ config: unknown;
25
+ };
26
+ /**
27
+ * One pacer in the manifest: its stable name and its rate-limit config.
28
+ */
29
+ export type PacerManifestEntry = {
30
+ key: string;
31
+ config: unknown;
32
+ };
33
+ /**
34
+ * The full worker manifest, emitted by `notion-workers build` as
35
+ * `dist/manifest.json` and read by the platform at deploy time. This is a
36
+ * complete, static description of the worker.
37
+ */
38
+ export type WorkerManifest = {
39
+ sdkVersion: string;
40
+ databases: DatabaseManifestEntry[];
41
+ pacers: PacerManifestEntry[];
42
+ capabilities: CapabilityManifestEntry[];
43
+ };
44
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/alpha/manifest.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAEpC;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACrC,IAAI,EAAE,cAAc,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAAG;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,qBAAqB,EAAE,CAAC;IACnC,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAC7B,YAAY,EAAE,uBAAuB,EAAE,CAAC;CACxC,CAAC"}
File without changes
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Writes a notion_output envelope to stdout using the shared wire format.
3
+ * The platform runner scans a run's log stream for this envelope to
4
+ * recover the capability's result.
5
+ */
6
+ export declare function writeOutput(value: unknown): void;
7
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/alpha/output.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAEhD"}
@@ -0,0 +1,8 @@
1
+ function writeOutput(value) {
2
+ process.stdout.write(`
3
+ <__notion_output__>${JSON.stringify(value)}</__notion_output__>
4
+ `);
5
+ }
6
+ export {
7
+ writeOutput
8
+ };
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Configuration for a pacer that rate-limits requests to an external API.
3
+ * When multiple syncs share a pacer, the platform apportions the budget
4
+ * across them.
5
+ */
6
+ export type PacerConfig = {
7
+ /** Maximum number of requests allowed per interval. */
8
+ allowedRequests: number;
9
+ /** The interval window in milliseconds. */
10
+ intervalMs: number;
11
+ };
12
+ /**
13
+ * Runtime pacing state for one pacer, as exchanged with the platform: the
14
+ * server sends entries with the *apportioned* budget (the declared budget
15
+ * divided across the syncs sharing the pacer), and the SDK returns the
16
+ * updated entries after a run so the server can persist `lastScheduledAtMs`.
17
+ * The wire shape matches v1.
18
+ */
19
+ export type PacerEntry = {
20
+ lastScheduledAtMs: number;
21
+ /** Server-provided (apportioned) request budget. */
22
+ allowedRequests: number;
23
+ /** Server-provided interval window in milliseconds. */
24
+ intervalMs: number;
25
+ };
26
+ /**
27
+ * A pacer as returned by {@link createPacer}.
28
+ */
29
+ export type Pacer = {
30
+ _tag: "pacer";
31
+ name: string;
32
+ config: PacerConfig;
33
+ /**
34
+ * Wait until a request can proceed under this pacer's rate limit.
35
+ * Call this before every API request the pacer covers.
36
+ *
37
+ * Requests are evenly spaced over the interval window. Inside a sync
38
+ * run, pacing continues from the server-provided state (which carries
39
+ * the budget apportioned across the syncs sharing this pacer); outside
40
+ * one, pacing starts fresh from the declared config.
41
+ */
42
+ wait(): Promise<void>;
43
+ };
44
+ /**
45
+ * Declare a pacer for rate-limiting requests to an external API.
46
+ *
47
+ * Like databases, a pacer is a named resource that can live anywhere —
48
+ * typically in a shared module next to the API client it paces. Unlike
49
+ * databases, a pacer is not attached to sync config: handlers use as many
50
+ * pacers as they need by importing them and calling `wait()`. Creating a
51
+ * pacer registers it, so every pacer in a module the worker imports is
52
+ * included in the manifest automatically.
53
+ *
54
+ * The `name` is the pacer's stable identity across deploys — the platform
55
+ * uses it to persist pacing state. Two `createPacer(...)` calls sharing a
56
+ * name fail the build; share one instance via import instead.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * // src/lib/jira.ts
61
+ * import { createPacer } from "@notionhq/workers/alpha/pacer";
62
+ *
63
+ * export const jiraPacer = createPacer("jira", {
64
+ * allowedRequests: 10,
65
+ * intervalMs: 1000,
66
+ * });
67
+ *
68
+ * // src/syncs/issues.ts — inside the handler:
69
+ * // await jiraPacer.wait();
70
+ * // const issues = await fetchIssues();
71
+ * ```
72
+ */
73
+ export declare function createPacer(name: string, config: PacerConfig): Pacer;
74
+ //# sourceMappingURL=pacer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pacer.d.ts","sourceRoot":"","sources":["../../src/alpha/pacer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG;IACzB,uDAAuD;IACvD,eAAe,EAAE,MAAM,CAAC;IACxB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oDAAoD;IACpD,eAAe,EAAE,MAAM,CAAC;IACxB,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;CACnB,CAAC;AAsBF;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IACpB;;;;;;;;OAQG;IACH,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,KAAK,CA0CpE"}
@@ -0,0 +1,66 @@
1
+ const REGISTRY_KEY = /* @__PURE__ */ Symbol.for("@notionhq/workers/alpha/pacer-registry");
2
+ const STATE_KEY = /* @__PURE__ */ Symbol.for("@notionhq/workers/alpha/pacer-state");
3
+ function registry() {
4
+ const holder = globalThis;
5
+ holder[REGISTRY_KEY] ??= /* @__PURE__ */ new Map();
6
+ return holder[REGISTRY_KEY];
7
+ }
8
+ function state() {
9
+ const holder = globalThis;
10
+ holder[STATE_KEY] ??= /* @__PURE__ */ new Map();
11
+ return holder[STATE_KEY];
12
+ }
13
+ function createPacer(name, config) {
14
+ if (!name || typeof name !== "string") {
15
+ throw new Error("Pacer name must be a non-empty string");
16
+ }
17
+ if (registry().has(name)) {
18
+ throw new Error(
19
+ `Two distinct pacers are named "${name}". A name identifies one pacer \u2014 share a single createPacer(...) instance via import instead of declaring it twice`
20
+ );
21
+ }
22
+ const pacer = {
23
+ _tag: "pacer",
24
+ name,
25
+ config,
26
+ async wait() {
27
+ const entry = state().get(name) ?? {
28
+ lastScheduledAtMs: 0,
29
+ allowedRequests: config.allowedRequests,
30
+ intervalMs: config.intervalMs
31
+ };
32
+ const paceMs = Math.ceil(entry.intervalMs / entry.allowedRequests);
33
+ const now = Date.now();
34
+ const scheduledAtMs = Math.max(entry.lastScheduledAtMs + paceMs, now);
35
+ const delayMs = scheduledAtMs - now;
36
+ state().set(name, { ...entry, lastScheduledAtMs: scheduledAtMs });
37
+ if (delayMs > 0) {
38
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
39
+ }
40
+ }
41
+ };
42
+ registry().set(name, pacer);
43
+ return pacer;
44
+ }
45
+ function initPacerState(runtimePacers) {
46
+ state().clear();
47
+ for (const [name, entry] of Object.entries(runtimePacers ?? {})) {
48
+ state().set(name, entry);
49
+ }
50
+ }
51
+ function pacerStates() {
52
+ return Object.fromEntries(state());
53
+ }
54
+ function registeredPacers() {
55
+ return Array.from(registry().values());
56
+ }
57
+ function clearRegisteredPacers() {
58
+ registry().clear();
59
+ }
60
+ export {
61
+ clearRegisteredPacers,
62
+ createPacer,
63
+ initPacerState,
64
+ pacerStates,
65
+ registeredPacers
66
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=pacer.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pacer.test.d.ts","sourceRoot":"","sources":["../../src/alpha/pacer.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { NormalizedSchedule, Schedule } from "./types.js";
2
+ /**
3
+ * Parses a user-friendly schedule string into the normalized backend format.
4
+ */
5
+ export declare function parseSchedule(schedule: Schedule): NormalizedSchedule;
6
+ //# sourceMappingURL=schedule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../src/alpha/schedule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAY,MAAM,YAAY,CAAC;AASzE;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,kBAAkB,CAwCpE"}
@@ -0,0 +1,43 @@
1
+ const MS_PER_MINUTE = 60 * 1e3;
2
+ const MS_PER_HOUR = 60 * MS_PER_MINUTE;
3
+ const MS_PER_DAY = 24 * MS_PER_HOUR;
4
+ const MIN_INTERVAL_MS = MS_PER_MINUTE;
5
+ const MAX_INTERVAL_MS = 7 * MS_PER_DAY;
6
+ function parseSchedule(schedule) {
7
+ if (schedule === "continuous") {
8
+ return { type: "continuous" };
9
+ }
10
+ if (schedule === "manual") {
11
+ return { type: "manual" };
12
+ }
13
+ const match = schedule.match(/^(\d+)(m|h|d)$/);
14
+ if (!match?.[1] || !match[2]) {
15
+ throw new Error(
16
+ `Invalid schedule format: "${schedule}". Use "continuous" or an interval like "30m", "1h", "1d".`
17
+ );
18
+ }
19
+ const value = parseInt(match[1], 10);
20
+ const unit = match[2];
21
+ let intervalMs;
22
+ switch (unit) {
23
+ case "m":
24
+ intervalMs = value * MS_PER_MINUTE;
25
+ break;
26
+ case "h":
27
+ intervalMs = value * MS_PER_HOUR;
28
+ break;
29
+ case "d":
30
+ intervalMs = value * MS_PER_DAY;
31
+ break;
32
+ }
33
+ if (intervalMs < MIN_INTERVAL_MS) {
34
+ throw new Error(`Schedule interval must be at least 1 minute. Got: "${schedule}"`);
35
+ }
36
+ if (intervalMs > MAX_INTERVAL_MS) {
37
+ throw new Error(`Schedule interval must be at most 7 days. Got: "${schedule}"`);
38
+ }
39
+ return { type: "interval", intervalMs };
40
+ }
41
+ export {
42
+ parseSchedule
43
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=schedule.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule.test.d.ts","sourceRoot":"","sources":["../../src/alpha/schedule.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Zod-like builder for JSONSchema objects.
3
+ *
4
+ * Guarantees output always complies with the model provider constraints
5
+ * enforced by `json-schema.ts` — all object properties in `required`,
6
+ * `additionalProperties: false`, no forbidden composition keywords, etc.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { j } from "@notionhq/workers/alpha/schema-builder";
11
+ *
12
+ * const schema = j.object({
13
+ * foo: j.enum("a", "b", "c").describe("The foo field"),
14
+ * bar: j.string(),
15
+ * count: j.number(),
16
+ * tags: j.array(j.string()),
17
+ * nickname: j.string().nullable(),
18
+ * createdAt: j.datetime(),
19
+ * });
20
+ * ```
21
+ */
22
+ import type { AnyJSONSchema, JSONSchema } from "./json-schema.js";
23
+ declare const SCHEMA: unique symbol;
24
+ export interface SchemaBuilder<T> {
25
+ readonly [SCHEMA]: AnyJSONSchema;
26
+ /** Set the JSONSchema description field. Chainable. */
27
+ describe(text: string): SchemaBuilder<T>;
28
+ /** Wrap in anyOf with null. Chainable. */
29
+ nullable(): SchemaBuilder<T | null>;
30
+ }
31
+ /** Extracts `T` from `SchemaBuilder<T>` (type-level only). */
32
+ export type Infer<S> = S extends SchemaBuilder<infer T> ? T : never;
33
+ /** Extract the plain JSONSchema from a builder. */
34
+ export declare function getSchema<T>(builder: SchemaBuilder<T>): JSONSchema<T>;
35
+ export declare function string(): SchemaBuilder<string>;
36
+ export declare function number(): SchemaBuilder<number>;
37
+ export declare function integer(): SchemaBuilder<number>;
38
+ export declare function boolean(): SchemaBuilder<boolean>;
39
+ declare function enumBuilder<T extends string>(...values: readonly T[]): SchemaBuilder<T>;
40
+ declare function enumBuilder<T extends number>(...values: readonly T[]): SchemaBuilder<T>;
41
+ export { enumBuilder as enum };
42
+ export declare function datetime(): SchemaBuilder<string>;
43
+ export declare function date(): SchemaBuilder<string>;
44
+ export declare function time(): SchemaBuilder<string>;
45
+ export declare function duration(): SchemaBuilder<string>;
46
+ export declare function email(): SchemaBuilder<string>;
47
+ export declare function hostname(): SchemaBuilder<string>;
48
+ export declare function ipv4(): SchemaBuilder<string>;
49
+ export declare function ipv6(): SchemaBuilder<string>;
50
+ export declare function uuid(): SchemaBuilder<string>;
51
+ export declare function array<T>(items: SchemaBuilder<T>, options?: {
52
+ minItems?: 0 | 1;
53
+ }): SchemaBuilder<T[]>;
54
+ export declare function object<P extends Record<string, SchemaBuilder<unknown>>>(properties: P): SchemaBuilder<{
55
+ [K in keyof P]: Infer<P[K]>;
56
+ }>;
57
+ export declare function anyOf<S extends SchemaBuilder<unknown>[]>(...schemas: S): SchemaBuilder<Infer<S[number]>>;
58
+ export declare function ref(path: string): SchemaBuilder<unknown>;
59
+ export declare const j: {
60
+ string: typeof string;
61
+ number: typeof number;
62
+ integer: typeof integer;
63
+ boolean: typeof boolean;
64
+ enum: typeof enumBuilder;
65
+ datetime: typeof datetime;
66
+ date: typeof date;
67
+ time: typeof time;
68
+ duration: typeof duration;
69
+ email: typeof email;
70
+ hostname: typeof hostname;
71
+ ipv4: typeof ipv4;
72
+ ipv6: typeof ipv6;
73
+ uuid: typeof uuid;
74
+ array: typeof array;
75
+ object: typeof object;
76
+ anyOf: typeof anyOf;
77
+ ref: typeof ref;
78
+ };
79
+ //# sourceMappingURL=schema-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-builder.d.ts","sourceRoot":"","sources":["../../src/alpha/schema-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,a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return builder[SCHEMA];
4
+ }
5
+ function makeBuilder(schema) {
6
+ return {
7
+ [SCHEMA]: schema,
8
+ describe(text) {
9
+ return makeBuilder({ ...schema, description: text });
10
+ },
11
+ nullable() {
12
+ const { description: desc, ...rest } = schema;
13
+ const inner = desc !== void 0 ? rest : schema;
14
+ const wrapper = {
15
+ anyOf: [inner, { type: "null" }]
16
+ };
17
+ if (desc !== void 0) wrapper.description = desc;
18
+ return makeBuilder(wrapper);
19
+ }
20
+ };
21
+ }
22
+ function string() {
23
+ return makeBuilder({ type: "string" });
24
+ }
25
+ function number() {
26
+ return makeBuilder({ type: "number" });
27
+ }
28
+ function integer() {
29
+ return makeBuilder({ type: "integer" });
30
+ }
31
+ function boolean() {
32
+ return makeBuilder({ type: "boolean" });
33
+ }
34
+ function enumBuilder(...values) {
35
+ const type = typeof values[0] === "string" ? "string" : "number";
36
+ return makeBuilder({ type, enum: values });
37
+ }
38
+ function datetime() {
39
+ return makeBuilder({ type: "string", format: "date-time" });
40
+ }
41
+ function date() {
42
+ return makeBuilder({ type: "string", format: "date" });
43
+ }
44
+ function time() {
45
+ return makeBuilder({ type: "string", format: "time" });
46
+ }
47
+ function duration() {
48
+ return makeBuilder({ type: "string", format: "duration" });
49
+ }
50
+ function email() {
51
+ return makeBuilder({ type: "string", format: "email" });
52
+ }
53
+ function hostname() {
54
+ return makeBuilder({ type: "string", format: "hostname" });
55
+ }
56
+ function ipv4() {
57
+ return makeBuilder({ type: "string", format: "ipv4" });
58
+ }
59
+ function ipv6() {
60
+ return makeBuilder({ type: "string", format: "ipv6" });
61
+ }
62
+ function uuid() {
63
+ return makeBuilder({ type: "string", format: "uuid" });
64
+ }
65
+ function array(items, options) {
66
+ const schema = {
67
+ type: "array",
68
+ items: getSchema(items)
69
+ };
70
+ if (options?.minItems !== void 0) schema.minItems = options.minItems;
71
+ return makeBuilder(schema);
72
+ }
73
+ function object(properties) {
74
+ const schemaProps = {};
75
+ const keys = Object.keys(properties);
76
+ for (const key of keys) {
77
+ schemaProps[key] = getSchema(properties[key]);
78
+ }
79
+ return makeBuilder({
80
+ type: "object",
81
+ properties: schemaProps,
82
+ required: keys,
83
+ additionalProperties: false
84
+ });
85
+ }
86
+ function anyOf(...schemas) {
87
+ return makeBuilder({
88
+ anyOf: schemas.map(getSchema)
89
+ });
90
+ }
91
+ function ref(path) {
92
+ return makeBuilder({ $ref: path });
93
+ }
94
+ const j = {
95
+ string,
96
+ number,
97
+ integer,
98
+ boolean,
99
+ enum: enumBuilder,
100
+ datetime,
101
+ date,
102
+ time,
103
+ duration,
104
+ email,
105
+ hostname,
106
+ ipv4,
107
+ ipv6,
108
+ uuid,
109
+ array,
110
+ object,
111
+ anyOf,
112
+ ref
113
+ };
114
+ export {
115
+ anyOf,
116
+ array,
117
+ boolean,
118
+ date,
119
+ datetime,
120
+ duration,
121
+ email,
122
+ enumBuilder as enum,
123
+ getSchema,
124
+ hostname,
125
+ integer,
126
+ ipv4,
127
+ ipv6,
128
+ j,
129
+ number,
130
+ object,
131
+ ref,
132
+ string,
133
+ time,
134
+ uuid
135
+ };