@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
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type { Database } from "./database.js";
|
|
2
|
+
import type { DateFormat, Icon, NumberFormat, SelectOption, StatusGroup } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* A schema defining the structure of a single property in a data source.
|
|
5
|
+
*/
|
|
6
|
+
export type PropertyConfiguration = {
|
|
7
|
+
type: "title";
|
|
8
|
+
} | {
|
|
9
|
+
type: "text";
|
|
10
|
+
} | {
|
|
11
|
+
type: "url";
|
|
12
|
+
} | {
|
|
13
|
+
type: "email";
|
|
14
|
+
} | {
|
|
15
|
+
type: "phone_number";
|
|
16
|
+
} | {
|
|
17
|
+
type: "checkbox";
|
|
18
|
+
} | {
|
|
19
|
+
type: "file";
|
|
20
|
+
} | {
|
|
21
|
+
type: "number";
|
|
22
|
+
format?: NumberFormat;
|
|
23
|
+
} | {
|
|
24
|
+
type: "date";
|
|
25
|
+
date_format?: DateFormat;
|
|
26
|
+
} | {
|
|
27
|
+
type: "select";
|
|
28
|
+
options: SelectOption[];
|
|
29
|
+
} | {
|
|
30
|
+
type: "multi_select";
|
|
31
|
+
options: SelectOption[];
|
|
32
|
+
} | {
|
|
33
|
+
type: "status";
|
|
34
|
+
groups: StatusGroup[];
|
|
35
|
+
} | {
|
|
36
|
+
type: "people";
|
|
37
|
+
} | {
|
|
38
|
+
type: "place";
|
|
39
|
+
} | {
|
|
40
|
+
type: "relation";
|
|
41
|
+
/**
|
|
42
|
+
* The related database, referenced by identity. It must be declared
|
|
43
|
+
* under `src/databases/`; the build resolves the reference to the
|
|
44
|
+
* database's key when emitting the manifest.
|
|
45
|
+
*/
|
|
46
|
+
database: Database;
|
|
47
|
+
config: {
|
|
48
|
+
twoWay: false;
|
|
49
|
+
} | {
|
|
50
|
+
twoWay: true;
|
|
51
|
+
relatedPropertyName: string;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* The property definitions for a database, keyed by property name.
|
|
56
|
+
*/
|
|
57
|
+
export type PropertySchema = Record<string, PropertyConfiguration>;
|
|
58
|
+
/**
|
|
59
|
+
* A database schema.
|
|
60
|
+
*/
|
|
61
|
+
export type Schema<S extends PropertySchema = PropertySchema> = {
|
|
62
|
+
/**
|
|
63
|
+
* Optional icon to use as the icon for the database page.
|
|
64
|
+
* If not provided, defaults to 📋.
|
|
65
|
+
*/
|
|
66
|
+
databaseIcon?: Icon;
|
|
67
|
+
properties: S;
|
|
68
|
+
/**
|
|
69
|
+
* Optional configuration for sub-item relations.
|
|
70
|
+
* If provided, the parent and child properties must be part of a two-way self-relation.
|
|
71
|
+
*/
|
|
72
|
+
subItems?: {
|
|
73
|
+
parentPropertyName: string;
|
|
74
|
+
childPropertyName: string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Builders for property definitions in a database schema.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* import { Schema } from "@notionhq/workers/alpha/schema";
|
|
83
|
+
*
|
|
84
|
+
* const schema = {
|
|
85
|
+
* properties: {
|
|
86
|
+
* "Task Name": Schema.title(),
|
|
87
|
+
* "Task ID": Schema.richText(),
|
|
88
|
+
* Status: Schema.select([
|
|
89
|
+
* { name: "Open", color: "default" },
|
|
90
|
+
* { name: "Done", color: "green" },
|
|
91
|
+
* ]),
|
|
92
|
+
* },
|
|
93
|
+
* };
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare const Schema: {
|
|
97
|
+
/**
|
|
98
|
+
* Creates a title property definition.
|
|
99
|
+
*/
|
|
100
|
+
title(): PropertyConfiguration;
|
|
101
|
+
/**
|
|
102
|
+
* Creates a rich text property definition.
|
|
103
|
+
*/
|
|
104
|
+
richText(): PropertyConfiguration;
|
|
105
|
+
/**
|
|
106
|
+
* Creates a URL property definition.
|
|
107
|
+
*/
|
|
108
|
+
url(): PropertyConfiguration;
|
|
109
|
+
/**
|
|
110
|
+
* Creates an email property definition.
|
|
111
|
+
*/
|
|
112
|
+
email(): PropertyConfiguration;
|
|
113
|
+
/**
|
|
114
|
+
* Creates a phone number property definition.
|
|
115
|
+
*/
|
|
116
|
+
phoneNumber(): PropertyConfiguration;
|
|
117
|
+
/**
|
|
118
|
+
* Creates a checkbox property definition.
|
|
119
|
+
*/
|
|
120
|
+
checkbox(): PropertyConfiguration;
|
|
121
|
+
/**
|
|
122
|
+
* Creates a file property definition.
|
|
123
|
+
*/
|
|
124
|
+
file(): PropertyConfiguration;
|
|
125
|
+
/**
|
|
126
|
+
* Creates a number property definition with optional formatting.
|
|
127
|
+
*/
|
|
128
|
+
number(format?: NumberFormat): PropertyConfiguration;
|
|
129
|
+
/**
|
|
130
|
+
* Creates a date property definition with optional formatting.
|
|
131
|
+
*/
|
|
132
|
+
date(date_format?: DateFormat): PropertyConfiguration;
|
|
133
|
+
/**
|
|
134
|
+
* Creates a select property definition with predefined options.
|
|
135
|
+
*/
|
|
136
|
+
select(options: SelectOption[]): PropertyConfiguration;
|
|
137
|
+
/**
|
|
138
|
+
* Creates a multi-select property definition with predefined options.
|
|
139
|
+
*/
|
|
140
|
+
multiSelect(options: SelectOption[]): PropertyConfiguration;
|
|
141
|
+
/**
|
|
142
|
+
* Creates a status property definition with groups.
|
|
143
|
+
*/
|
|
144
|
+
status(config: {
|
|
145
|
+
groups: StatusGroup[];
|
|
146
|
+
}): PropertyConfiguration;
|
|
147
|
+
/**
|
|
148
|
+
* Creates a people property definition.
|
|
149
|
+
*/
|
|
150
|
+
people(): PropertyConfiguration;
|
|
151
|
+
/**
|
|
152
|
+
* Creates a place property definition for storing geographic locations.
|
|
153
|
+
*/
|
|
154
|
+
place(): PropertyConfiguration;
|
|
155
|
+
/**
|
|
156
|
+
* Creates a relation property definition that references another database.
|
|
157
|
+
* The related database must be declared under `src/databases/` and is
|
|
158
|
+
* referenced by importing it:
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* // src/databases/tasks.ts
|
|
163
|
+
* import projects from "./projects.js";
|
|
164
|
+
*
|
|
165
|
+
* export default createDatabase({
|
|
166
|
+
* type: "managed",
|
|
167
|
+
* primaryKey: "Task ID",
|
|
168
|
+
* schema: {
|
|
169
|
+
* properties: {
|
|
170
|
+
* Title: Schema.title(),
|
|
171
|
+
* "Task ID": Schema.richText(),
|
|
172
|
+
* Project: Schema.relation(projects),
|
|
173
|
+
* },
|
|
174
|
+
* },
|
|
175
|
+
* });
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
relation(database: Database<any>, config?: {
|
|
179
|
+
twoWay: false;
|
|
180
|
+
} | {
|
|
181
|
+
twoWay: true;
|
|
182
|
+
relatedPropertyName: string;
|
|
183
|
+
}): PropertyConfiguration;
|
|
184
|
+
};
|
|
185
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/alpha/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE5F;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GACf;IAAE,I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;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,MAAM;IAClB;;OAEG;aACM,qBAAqB;IAI9B;;OAEG;gBACS,qBAAqB;IAIjC;;OAEG;WACI,qBAAqB;IAI5B;;OAEG;aACM,qBAAqB;IAI9B;;OAEG;mBACY,qBAAqB;IAIpC;;OAEG;gBACS,qBAAqB;IAIjC;;OAEG;YACK,qBAAqB;IAI7B;;OAEG;oBACa,YAAY,GAAG,qBAAqB;IAIpD;;OAEG;uBACgB,UAAU,GAAG,qBAAqB;IAIrD;;OAEG;oBACa,YAAY,EAAE,GAAG,qBAAqB;IAItD;;OAEG;yBACkB,YAAY,EAAE,GAAG,qBAAqB;IAI3D;;OAEG;mBACY;QAAE,MAAM,EAAE,WAAW,EAAE,CAAA;KAAE,GAAG,qBAAqB;IAIhE;;OAEG;cACO,qBAAqB;IAI/B;;OAEG;aACM,qBAAqB;IAI9B;;;;;;;;;;;;;;;;;;;;;;OAsBG;uBAIQ,QAAQ,CAAC,GAAG,CAAC,WACd;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE,GAAG;QAAE,MAAM,EAAE,IAAI,CAAC;QAAC,mBAAmB,EAAE,MAAM,CAAA;KAAE,GACxE,qBAAqB;CAGxB,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
const Schema = {
|
|
2
|
+
/**
|
|
3
|
+
* Creates a title property definition.
|
|
4
|
+
*/
|
|
5
|
+
title() {
|
|
6
|
+
return { type: "title" };
|
|
7
|
+
},
|
|
8
|
+
/**
|
|
9
|
+
* Creates a rich text property definition.
|
|
10
|
+
*/
|
|
11
|
+
richText() {
|
|
12
|
+
return { type: "text" };
|
|
13
|
+
},
|
|
14
|
+
/**
|
|
15
|
+
* Creates a URL property definition.
|
|
16
|
+
*/
|
|
17
|
+
url() {
|
|
18
|
+
return { type: "url" };
|
|
19
|
+
},
|
|
20
|
+
/**
|
|
21
|
+
* Creates an email property definition.
|
|
22
|
+
*/
|
|
23
|
+
email() {
|
|
24
|
+
return { type: "email" };
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* Creates a phone number property definition.
|
|
28
|
+
*/
|
|
29
|
+
phoneNumber() {
|
|
30
|
+
return { type: "phone_number" };
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* Creates a checkbox property definition.
|
|
34
|
+
*/
|
|
35
|
+
checkbox() {
|
|
36
|
+
return { type: "checkbox" };
|
|
37
|
+
},
|
|
38
|
+
/**
|
|
39
|
+
* Creates a file property definition.
|
|
40
|
+
*/
|
|
41
|
+
file() {
|
|
42
|
+
return { type: "file" };
|
|
43
|
+
},
|
|
44
|
+
/**
|
|
45
|
+
* Creates a number property definition with optional formatting.
|
|
46
|
+
*/
|
|
47
|
+
number(format) {
|
|
48
|
+
return format ? { type: "number", format } : { type: "number" };
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* Creates a date property definition with optional formatting.
|
|
52
|
+
*/
|
|
53
|
+
date(date_format) {
|
|
54
|
+
return date_format ? { type: "date", date_format } : { type: "date" };
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Creates a select property definition with predefined options.
|
|
58
|
+
*/
|
|
59
|
+
select(options) {
|
|
60
|
+
return { type: "select", options };
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
* Creates a multi-select property definition with predefined options.
|
|
64
|
+
*/
|
|
65
|
+
multiSelect(options) {
|
|
66
|
+
return { type: "multi_select", options };
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* Creates a status property definition with groups.
|
|
70
|
+
*/
|
|
71
|
+
status(config) {
|
|
72
|
+
return { type: "status", groups: config.groups };
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* Creates a people property definition.
|
|
76
|
+
*/
|
|
77
|
+
people() {
|
|
78
|
+
return { type: "people" };
|
|
79
|
+
},
|
|
80
|
+
/**
|
|
81
|
+
* Creates a place property definition for storing geographic locations.
|
|
82
|
+
*/
|
|
83
|
+
place() {
|
|
84
|
+
return { type: "place" };
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Creates a relation property definition that references another database.
|
|
88
|
+
* The related database must be declared under `src/databases/` and is
|
|
89
|
+
* referenced by importing it:
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* // src/databases/tasks.ts
|
|
94
|
+
* import projects from "./projects.js";
|
|
95
|
+
*
|
|
96
|
+
* export default createDatabase({
|
|
97
|
+
* type: "managed",
|
|
98
|
+
* primaryKey: "Task ID",
|
|
99
|
+
* schema: {
|
|
100
|
+
* properties: {
|
|
101
|
+
* Title: Schema.title(),
|
|
102
|
+
* "Task ID": Schema.richText(),
|
|
103
|
+
* Project: Schema.relation(projects),
|
|
104
|
+
* },
|
|
105
|
+
* },
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
relation(database, config) {
|
|
110
|
+
return { type: "relation", database, config: config ?? { twoWay: false } };
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
export {
|
|
114
|
+
Schema
|
|
115
|
+
};
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import type { CapabilityContext } from "./context.js";
|
|
2
|
+
import type { Database } from "./database.js";
|
|
3
|
+
import { type PacerEntry } from "./pacer.js";
|
|
4
|
+
import type { PropertyConfiguration, PropertySchema, Schema } from "./schema.js";
|
|
5
|
+
import type { Cover, HandlerOptions, Icon, NormalizedSchedule, PeopleValue, PlaceValue, RelationValue, Schedule, TextValue } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Maps a property configuration to its corresponding value type.
|
|
8
|
+
*/
|
|
9
|
+
type PropertyValueType<T extends PropertyConfiguration> = T extends {
|
|
10
|
+
type: "people";
|
|
11
|
+
} ? PeopleValue : T extends {
|
|
12
|
+
type: "place";
|
|
13
|
+
} ? PlaceValue : T extends {
|
|
14
|
+
type: "relation";
|
|
15
|
+
} ? RelationValue : TextValue;
|
|
16
|
+
/**
|
|
17
|
+
* Sync mode determines how the sync handles data lifecycle.
|
|
18
|
+
*/
|
|
19
|
+
export type SyncMode = "replace" | "incremental";
|
|
20
|
+
/**
|
|
21
|
+
* A change representing a record to be created or updated.
|
|
22
|
+
*/
|
|
23
|
+
export type SyncChangeUpsert<S extends PropertySchema = PropertySchema> = {
|
|
24
|
+
/** The type of change. Use `"upsert"` to create or update a record. */
|
|
25
|
+
type: "upsert";
|
|
26
|
+
/** A unique identifier for this record, used to match against existing pages. */
|
|
27
|
+
key: string;
|
|
28
|
+
/**
|
|
29
|
+
* The property values for this record.
|
|
30
|
+
* Keys must match the property names defined in the schema.
|
|
31
|
+
* Use the Builder helpers (e.g. `Builder.title()`, `Builder.richText()`)
|
|
32
|
+
* to create values.
|
|
33
|
+
*/
|
|
34
|
+
properties: {
|
|
35
|
+
[Property in keyof S]: PropertyValueType<S[Property]>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* When this record was last updated in the upstream system.
|
|
39
|
+
* ISO 8601 string (e.g. `"2026-03-19T12:00:00Z"`).
|
|
40
|
+
* Used for conflict resolution when multiple syncs write to the same
|
|
41
|
+
* database. Recommended, but optional.
|
|
42
|
+
*/
|
|
43
|
+
upstreamUpdatedAt?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Optional icon to use as the icon for this row's page.
|
|
46
|
+
* Use the `Builder.emojiIcon()`, `Builder.notionIcon()`, or
|
|
47
|
+
* `Builder.imageIcon()` helpers.
|
|
48
|
+
*/
|
|
49
|
+
icon?: Icon;
|
|
50
|
+
/**
|
|
51
|
+
* Optional cover to use as the cover for this row's page.
|
|
52
|
+
* Use the `Builder.imageCover()` helper.
|
|
53
|
+
*/
|
|
54
|
+
cover?: Cover;
|
|
55
|
+
/**
|
|
56
|
+
* Optional markdown content to add to the page body.
|
|
57
|
+
* This will be converted to Notion blocks and added as page content.
|
|
58
|
+
*/
|
|
59
|
+
pageContentMarkdown?: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* A change representing a record to be deleted.
|
|
63
|
+
* Only applicable when using `mode: "incremental"`.
|
|
64
|
+
*/
|
|
65
|
+
export type SyncChangeDelete = {
|
|
66
|
+
/** The type of change. Use `"delete"` to remove a record. */
|
|
67
|
+
type: "delete";
|
|
68
|
+
/** The unique identifier of the record to delete. */
|
|
69
|
+
key: string;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* A change to be applied to the synced database.
|
|
73
|
+
*/
|
|
74
|
+
export type SyncChange<S extends PropertySchema = PropertySchema> = SyncChangeUpsert<S> | SyncChangeDelete;
|
|
75
|
+
/**
|
|
76
|
+
* Result returned from a sync handler.
|
|
77
|
+
*/
|
|
78
|
+
export type SyncHandlerResult<S extends PropertySchema = PropertySchema, State = unknown> = {
|
|
79
|
+
/** The batch of changes to apply in this execution. */
|
|
80
|
+
changes: SyncChange<S>[];
|
|
81
|
+
/**
|
|
82
|
+
* Indicates whether there is more data to fetch. When `true`, the
|
|
83
|
+
* handler is called again with `nextState`.
|
|
84
|
+
*
|
|
85
|
+
* @default false
|
|
86
|
+
*/
|
|
87
|
+
hasMore?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Optional state data to pass to the next execution.
|
|
90
|
+
* Required if `hasMore` is `true`, ignored otherwise.
|
|
91
|
+
* This can be any type of data (cursor, page number, timestamp, etc.);
|
|
92
|
+
* the same data is provided as `state` in the next execution.
|
|
93
|
+
*/
|
|
94
|
+
nextState?: State;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Configuration passed to {@link createSync}.
|
|
98
|
+
*/
|
|
99
|
+
export type SyncConfiguration<S extends PropertySchema = PropertySchema, State = unknown> = {
|
|
100
|
+
/**
|
|
101
|
+
* The database to sync data into, declared with `createDatabase(...)`.
|
|
102
|
+
* Declare it inline for a database private to this sync, or import a
|
|
103
|
+
* shared instance that other syncs (and `Schema.relation(...)`) also
|
|
104
|
+
* reference.
|
|
105
|
+
*/
|
|
106
|
+
database: Database<S>;
|
|
107
|
+
/**
|
|
108
|
+
* How the sync handles data lifecycle:
|
|
109
|
+
* - "replace": Each run returns the complete dataset; unseen pages are deleted.
|
|
110
|
+
* - "incremental": Each run returns changes only; use delete markers to remove pages.
|
|
111
|
+
*
|
|
112
|
+
* @default "replace"
|
|
113
|
+
*/
|
|
114
|
+
mode?: SyncMode;
|
|
115
|
+
/**
|
|
116
|
+
* How often the sync should run.
|
|
117
|
+
* - "continuous": Run as frequently as the system allows
|
|
118
|
+
* - "manual": Only run when explicitly triggered
|
|
119
|
+
* - Interval string: Run at specified intervals, e.g. "1h", "30m", "1d"
|
|
120
|
+
*
|
|
121
|
+
* @default "30m"
|
|
122
|
+
*/
|
|
123
|
+
schedule?: Schedule;
|
|
124
|
+
/**
|
|
125
|
+
* Fetches the data to sync from the third-party service.
|
|
126
|
+
*
|
|
127
|
+
* This function can return all data at once, or implement pagination by
|
|
128
|
+
* returning a batch of changes with `hasMore: true` and a `nextState`;
|
|
129
|
+
* the runtime calls it again with that state until `hasMore` is `false`.
|
|
130
|
+
*
|
|
131
|
+
* @param state - User-defined state from the previous execution (undefined on first call)
|
|
132
|
+
* @param context - Runtime context, including the Notion client
|
|
133
|
+
*/
|
|
134
|
+
handler: (state: State | undefined, context: CapabilityContext) => Promise<SyncHandlerResult<S, State>>;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* The pre-manifest configuration of a sync: everything from
|
|
138
|
+
* {@link SyncConfiguration} except the handler, with the schedule
|
|
139
|
+
* normalized for the backend and the database's schema type erased.
|
|
140
|
+
*
|
|
141
|
+
* The `database` here is still an object reference; the build resolves it
|
|
142
|
+
* to the database's *name* when emitting the manifest.
|
|
143
|
+
*/
|
|
144
|
+
export type SyncManifestConfig = {
|
|
145
|
+
database: {
|
|
146
|
+
_tag: "database";
|
|
147
|
+
name: string;
|
|
148
|
+
config: {
|
|
149
|
+
type: "managed";
|
|
150
|
+
initialTitle?: string;
|
|
151
|
+
primaryKey: string;
|
|
152
|
+
schema: Schema;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
mode: SyncMode | undefined;
|
|
156
|
+
schedule: NormalizedSchedule | undefined;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* The runtime context the platform passes when invoking a sync.
|
|
160
|
+
*/
|
|
161
|
+
export type SyncRuntimeContext = {
|
|
162
|
+
/** The user-defined state (cursor, pagination state, etc.). */
|
|
163
|
+
state?: unknown;
|
|
164
|
+
/** Legacy field for user-defined state. */
|
|
165
|
+
userContext?: unknown;
|
|
166
|
+
/** Pacer state from the server for rate limiting. */
|
|
167
|
+
pacers?: Record<string, PacerEntry>;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* The result a sync run reports to the platform, via the notion_output
|
|
171
|
+
* envelope on stdout (or directly, under `concreteOutput`). This is the
|
|
172
|
+
* same wire shape v1 syncs produce.
|
|
173
|
+
*/
|
|
174
|
+
export type SyncRunResult = {
|
|
175
|
+
changes: (SyncChange & {
|
|
176
|
+
targetDatabaseKey: string;
|
|
177
|
+
})[];
|
|
178
|
+
hasMore: boolean;
|
|
179
|
+
nextUserContext?: unknown;
|
|
180
|
+
nextPacerStates: Record<string, PacerEntry>;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* A sync capability as returned by {@link createSync}.
|
|
184
|
+
*
|
|
185
|
+
* Note that a sync carries no key of its own — the build tool derives the
|
|
186
|
+
* capability key from the file the sync is default-exported from.
|
|
187
|
+
*/
|
|
188
|
+
export type Sync = {
|
|
189
|
+
_tag: "sync";
|
|
190
|
+
config: SyncManifestConfig;
|
|
191
|
+
handler: (runtimeContext?: SyncRuntimeContext, options?: HandlerOptions) => Promise<SyncRunResult>;
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* Create a sync capability.
|
|
195
|
+
*
|
|
196
|
+
* Default-export the result from a file directly under `src/syncs/` —
|
|
197
|
+
* the file's basename becomes the sync's key.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* // src/syncs/tasks.ts
|
|
202
|
+
* import { createDatabase } from "@notionhq/workers/alpha/database";
|
|
203
|
+
* import { Schema } from "@notionhq/workers/alpha/schema";
|
|
204
|
+
* import { createSync } from "@notionhq/workers/alpha/sync";
|
|
205
|
+
*
|
|
206
|
+
* export default createSync({
|
|
207
|
+
* database: createDatabase("tasks", {
|
|
208
|
+
* type: "managed",
|
|
209
|
+
* primaryKey: "Task ID",
|
|
210
|
+
* schema: {
|
|
211
|
+
* properties: {
|
|
212
|
+
* Title: Schema.title(),
|
|
213
|
+
* "Task ID": Schema.richText(),
|
|
214
|
+
* },
|
|
215
|
+
* },
|
|
216
|
+
* }),
|
|
217
|
+
* mode: "replace",
|
|
218
|
+
* schedule: "24h",
|
|
219
|
+
* handler: async () => ({
|
|
220
|
+
* changes: [
|
|
221
|
+
* {
|
|
222
|
+
* type: "upsert",
|
|
223
|
+
* key: "1",
|
|
224
|
+
* properties: { Title: [["Item 1"]], "Task ID": [["1"]] },
|
|
225
|
+
* },
|
|
226
|
+
* ],
|
|
227
|
+
* }),
|
|
228
|
+
* });
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
export declare function createSync<S extends PropertySchema, State = unknown>(configuration: SyncConfiguration<S, State>): Sync;
|
|
232
|
+
export {};
|
|
233
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/alpha/sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,OAAO,EAA+B,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAE1E,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,K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G;IAChC,+DAA+D;IAC/D,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,2CAA2C;IAC3C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACpC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG;IAC3B,OAAO,EAAE,CAAC,UAAU,GAAG;QAAE,iBAAiB,EAAE,MAAM,CAAA;KAAE,CAAC,EAAE,CAAC;IACxD,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CAC5C,CAAC;AASF;;;;;GAKG;AACH,MAAM,MAAM,IAAI,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,kBAAkB,CAAC;IAC3B,OAAO,EAAE,CACR,cAAc,CAAC,EAAE,kBAAkB,EACnC,OAAO,CAAC,EAAE,cAAc,KACpB,OAAO,CAAC,aAAa,CAAC,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,cAAc,EAAE,KAAK,GAAG,OAAO,EACnE,aAAa,EAAE,iBAAiB,CAAC,CAAC,EAAE,KAAK,CAAC,GACxC,IAAI,CAsEN"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createCapabilityContext } from "./context.js";
|
|
2
|
+
import { ExecutionError, RateLimitError } from "./error.js";
|
|
3
|
+
import { writeOutput } from "./output.js";
|
|
4
|
+
import { initPacerState, pacerStates } from "./pacer.js";
|
|
5
|
+
import { parseSchedule } from "./schedule.js";
|
|
6
|
+
function createSync(configuration) {
|
|
7
|
+
return {
|
|
8
|
+
_tag: "sync",
|
|
9
|
+
config: {
|
|
10
|
+
database: configuration.database,
|
|
11
|
+
mode: configuration.mode,
|
|
12
|
+
schedule: configuration.schedule ? parseSchedule(configuration.schedule) : void 0
|
|
13
|
+
},
|
|
14
|
+
async handler(runtimeContext, options) {
|
|
15
|
+
const state = runtimeContext?.state ?? runtimeContext?.userContext;
|
|
16
|
+
initPacerState(runtimeContext?.pacers);
|
|
17
|
+
let handlerResult;
|
|
18
|
+
try {
|
|
19
|
+
handlerResult = await configuration.handler(state, createCapabilityContext("sync"));
|
|
20
|
+
} catch (err) {
|
|
21
|
+
if (err instanceof RateLimitError) {
|
|
22
|
+
if (!options?.concreteOutput) {
|
|
23
|
+
const envelope = {
|
|
24
|
+
_tag: "error",
|
|
25
|
+
error: {
|
|
26
|
+
_tag: "rate_limit",
|
|
27
|
+
name: err.name,
|
|
28
|
+
message: err.message,
|
|
29
|
+
...err.retryAfter !== void 0 ? { retryAfter: err.retryAfter } : {}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
writeOutput(envelope);
|
|
33
|
+
}
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
const error = new ExecutionError(err);
|
|
37
|
+
if (!options?.concreteOutput) {
|
|
38
|
+
const envelope = {
|
|
39
|
+
_tag: "error",
|
|
40
|
+
error: {
|
|
41
|
+
_tag: "generic",
|
|
42
|
+
name: error.name,
|
|
43
|
+
message: error.message
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
writeOutput(envelope);
|
|
47
|
+
}
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
const changes = handlerResult.changes.map((change) => ({
|
|
51
|
+
...change,
|
|
52
|
+
targetDatabaseKey: configuration.database.name
|
|
53
|
+
}));
|
|
54
|
+
const result = {
|
|
55
|
+
changes,
|
|
56
|
+
hasMore: handlerResult.hasMore ?? false,
|
|
57
|
+
nextUserContext: handlerResult.nextState,
|
|
58
|
+
nextPacerStates: pacerStates()
|
|
59
|
+
};
|
|
60
|
+
if (options?.concreteOutput) {
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
writeOutput({ _tag: "success", value: result });
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
createSync
|
|
70
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.test.d.ts","sourceRoot":"","sources":["../../src/alpha/sync.test.ts"],"names":[],"mappings":""}
|