@project-ajax/sdk 0.0.57 → 0.0.60
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/builder.d.ts +6 -1
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +4 -0
- package/dist/capabilities/sync.d.ts +64 -13
- package/dist/capabilities/sync.d.ts.map +1 -1
- package/dist/capabilities/sync.js +8 -6
- package/dist/cli/io.d.ts.map +1 -1
- package/dist/cli/io.js +7 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/schema.d.ts +7 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +4 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/builder.ts +15 -1
- package/src/capabilities/sync.ts +90 -19
- package/src/cli/io.ts +10 -7
- package/src/index.ts +5 -0
- package/src/schema.ts +11 -2
- package/src/types.ts +15 -0
package/dist/builder.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NoticonName } from "./icon-names.js";
|
|
2
|
-
import type { Icon, NoticonColor, TextValue } from "./types.js";
|
|
2
|
+
import type { Icon, NoticonColor, PeopleValue, TextValue } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a rich text value.
|
|
5
5
|
*/
|
|
@@ -73,6 +73,11 @@ export declare function multiSelect(...values: string[]): TextValue;
|
|
|
73
73
|
* Creates a status value from a status option name.
|
|
74
74
|
*/
|
|
75
75
|
export declare function status(value: string): TextValue;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a people value from email addresses.
|
|
78
|
+
* @param emails - Array of email addresses for people to include
|
|
79
|
+
*/
|
|
80
|
+
export declare function people(...emails: string[]): PeopleValue;
|
|
76
81
|
/**
|
|
77
82
|
* Creates an emoji icon.
|
|
78
83
|
* @param emoji - An emoji string (e.g., "🎯", "✨", "🚀")
|
package/dist/builder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAEX,IAAI,EACJ,YAAY,EACZ,WAAW,EACX,SAAS,EACT,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAEnD;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAE1C;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAEhD;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAE/C;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAE9C;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAEpD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAElE;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAK/C;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CASlD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAYjE;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAWvE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC5B,SAAS,EAAE,IAAI,EACf,OAAO,EAAE,IAAI,EACb,QAAQ,CAAC,EAAE,MAAM,GACf,SAAS,CAcX;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAEhE;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAE/C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAK1D;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAE/C;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,WAAW,CAEvD;AA4CD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAK7C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACzB,IAAI,EAAE,WAAW,EACjB,KAAK,GAAE,YAAqB,GAC1B,IAAI,CAMN"}
|
package/dist/builder.js
CHANGED
|
@@ -85,6 +85,9 @@ function multiSelect(...values) {
|
|
|
85
85
|
function status(value) {
|
|
86
86
|
return [[value]];
|
|
87
87
|
}
|
|
88
|
+
function people(...emails) {
|
|
89
|
+
return emails.map((email2) => ({ email: email2 }));
|
|
90
|
+
}
|
|
88
91
|
function validateDateString(dateString) {
|
|
89
92
|
if (!/^\d{4}-\d{2}-\d{2}$/.test(dateString)) {
|
|
90
93
|
throw new Error(
|
|
@@ -136,6 +139,7 @@ export {
|
|
|
136
139
|
multiSelect,
|
|
137
140
|
notionIcon,
|
|
138
141
|
number,
|
|
142
|
+
people,
|
|
139
143
|
phoneNumber,
|
|
140
144
|
richText,
|
|
141
145
|
select,
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import type { PropertySchema, Schema } from "../schema.js";
|
|
2
|
-
import type { Icon, TextValue } from "../types.js";
|
|
1
|
+
import type { PropertyConfiguration, PropertySchema, Schema } from "../schema.js";
|
|
2
|
+
import type { Icon, PeopleValue, TextValue } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Maps a property configuration to its corresponding value type.
|
|
5
|
+
*/
|
|
6
|
+
type PropertyValueType<T extends PropertyConfiguration> = T extends {
|
|
7
|
+
type: "people";
|
|
8
|
+
} ? PeopleValue : TextValue;
|
|
3
9
|
/**
|
|
4
10
|
* An object representing a third-party record to be synced.
|
|
5
11
|
*/
|
|
6
12
|
export type SyncedObject<PK extends string, S extends PropertySchema<PK>> = {
|
|
7
13
|
key: string;
|
|
8
14
|
properties: {
|
|
9
|
-
[Property in keyof S]:
|
|
15
|
+
[Property in keyof S]: PropertyValueType<S[Property]>;
|
|
10
16
|
};
|
|
11
17
|
/**
|
|
12
18
|
* Optional icon to use as the icon for this row's page.
|
|
@@ -19,11 +25,33 @@ export type SyncedObject<PK extends string, S extends PropertySchema<PK>> = {
|
|
|
19
25
|
*/
|
|
20
26
|
pageContentMarkdown?: string;
|
|
21
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Result returned from the sync execute function.
|
|
30
|
+
*/
|
|
31
|
+
export type SyncExecutionResult<PK extends string, Context = unknown> = {
|
|
32
|
+
/**
|
|
33
|
+
* The batch of objects fetched in this execution.
|
|
34
|
+
*/
|
|
35
|
+
objects: SyncedObject<PK, PropertySchema<PK>>[];
|
|
36
|
+
/**
|
|
37
|
+
* Indicates whether the sync is complete.
|
|
38
|
+
* - `true`: No more data to fetch, sync is complete
|
|
39
|
+
* - `false`: More data available, will trigger another execution with nextContext
|
|
40
|
+
*/
|
|
41
|
+
done: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Optional context data to pass to the next execution.
|
|
44
|
+
* Required if `done` is `false`, ignored if `done` is `true`.
|
|
45
|
+
* This can be any type of data (cursor, page number, timestamp, etc.).
|
|
46
|
+
* The same data will be provided in the context parameter of the next execution.
|
|
47
|
+
*/
|
|
48
|
+
nextContext?: Context;
|
|
49
|
+
};
|
|
22
50
|
/**
|
|
23
51
|
* A configuration object that enables synchronization between a data
|
|
24
52
|
* source and a third-party source.
|
|
25
53
|
*/
|
|
26
|
-
export type SyncConfiguration<PK extends string, S extends Schema<PK
|
|
54
|
+
export type SyncConfiguration<PK extends string, S extends Schema<PK>, Context = unknown> = {
|
|
27
55
|
/**
|
|
28
56
|
* The property of the data source that maps to a "primary key" in the
|
|
29
57
|
* third-party data. This is used to match existing pages to
|
|
@@ -34,18 +62,38 @@ export type SyncConfiguration<PK extends string, S extends Schema<PK>> = {
|
|
|
34
62
|
* The schema defining the structure of properties in the collection.
|
|
35
63
|
*/
|
|
36
64
|
schema: S;
|
|
65
|
+
/**
|
|
66
|
+
* Whether to delete pages from the collection that are not returned
|
|
67
|
+
* from any of the sync executions (mark-and-sweep deletion).
|
|
68
|
+
*
|
|
69
|
+
* - `true`: Pages not seen in any execution batch will be deleted
|
|
70
|
+
* - `false` (default): Only upsert pages, never delete
|
|
71
|
+
*
|
|
72
|
+
* @default false
|
|
73
|
+
*/
|
|
74
|
+
deleteUnreturnedPages?: boolean;
|
|
37
75
|
/**
|
|
38
76
|
* A function that fetches the data to sync from the third-party service.
|
|
39
77
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
78
|
+
* This function can return all data at once, or implement pagination by:
|
|
79
|
+
* 1. Returning a batch of objects with `done: false` and a `nextContext`
|
|
80
|
+
* 2. The runtime will call execute again with that context data
|
|
81
|
+
* 3. Continue until `done: true` is returned
|
|
82
|
+
*
|
|
83
|
+
* The runtime will handle diffing against the data source and creating,
|
|
84
|
+
* updating, and deleting pages as necessary.
|
|
85
|
+
*
|
|
86
|
+
* @param context - Optional context data from previous execution (undefined on first call)
|
|
87
|
+
* @returns A result containing objects, done status, and optional nextContext
|
|
43
88
|
*/
|
|
44
|
-
execute: () => Promise<
|
|
89
|
+
execute: (context?: Context) => Promise<SyncExecutionResult<PK, Context>>;
|
|
45
90
|
};
|
|
46
|
-
export type SyncHandlerResult<PK extends string> = {
|
|
91
|
+
export type SyncHandlerResult<PK extends string, Context = unknown> = {
|
|
47
92
|
primaryKeyProperty: PK;
|
|
48
93
|
objects: SyncedObject<PK, PropertySchema<PK>>[];
|
|
94
|
+
done: boolean;
|
|
95
|
+
nextContext?: Context;
|
|
96
|
+
deleteUnreturnedPages?: boolean;
|
|
49
97
|
};
|
|
50
98
|
/**
|
|
51
99
|
* Creates a special handler for syncing third-party data to a collection.
|
|
@@ -54,15 +102,18 @@ export type SyncHandlerResult<PK extends string> = {
|
|
|
54
102
|
* @returns A handler function that executes the sync function, and passes data
|
|
55
103
|
* needed to complete the sync back to the platform.
|
|
56
104
|
*/
|
|
57
|
-
export declare function sync<PK extends string, S extends Schema<PK
|
|
105
|
+
export declare function sync<PK extends string, S extends Schema<PK>, Context = unknown>(syncConfiguration: SyncConfiguration<PK, S, Context>): {
|
|
58
106
|
_tag: string;
|
|
59
107
|
config: {
|
|
108
|
+
primaryKeyProperty: PK;
|
|
60
109
|
schema: S;
|
|
110
|
+
deleteUnreturnedPages: boolean | undefined;
|
|
61
111
|
};
|
|
62
|
-
handler(): Promise<{
|
|
63
|
-
schema: S;
|
|
64
|
-
primaryKeyProperty: PK;
|
|
112
|
+
handler(context?: Context): Promise<{
|
|
65
113
|
objects: SyncedObject<PK, PropertySchema<PK>>[];
|
|
114
|
+
done: boolean;
|
|
115
|
+
nextContext: Context | undefined;
|
|
66
116
|
}>;
|
|
67
117
|
};
|
|
118
|
+
export {};
|
|
68
119
|
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/capabilities/sync.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/capabilities/sync.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,qBAAqB,EACrB,cAAc,EACd,MAAM,EACN,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEhE;;GAEG;AACH,KAAK,iBAAiB,CAAC,CAAC,SAAS,qBAAqB,IAAI,CAAC,SAAS;IACnE,IAAI,EAAE,QAAQ,CAAC;CACf,GACE,WAAW,GACX,SAAS,CAAC;AAEb;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC,SAAS,cAAc,CAAC,EAAE,CAAC,IAAI;IAC3E,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE;SACV,QAAQ,IAAI,MAAM,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;KACrD,CAAC;IACF;;;OAGG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,OAAO,GAAG,OAAO,IAAI;IACvE;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC,EAAE,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAEhD;;;;OAIG;IACH,IAAI,EAAE,OAAO,CAAC;IAEd;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,iBAAiB,CAC5B,EAAE,SAAS,MAAM,EACjB,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,EACpB,OAAO,GAAG,OAAO,IACd;IACH;;;;OAIG;IACH,kBAAkB,EAAE,EAAE,CAAC;IAEvB;;OAEG;IACH,MAAM,EAAE,CAAC,CAAC;IAEV;;;;;;;;OAQG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;;;;;;;;;;;;OAaG;IACH,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,mBAAmB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;CAC1E,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,OAAO,GAAG,OAAO,IAAI;IACrE,kBAAkB,EAAE,EAAE,CAAC;IACvB,OAAO,EAAE,YAAY,CAAC,EAAE,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAChD,IAAI,EAAE,OAAO,CAAC;IACd,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,qBAAqB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,IAAI,CACnB,EAAE,SAAS,MAAM,EACjB,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,EACpB,OAAO,GAAG,OAAO,EAChB,iBAAiB,EAAE,iBAAiB,CAAC,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC;;;;;;;sBAQ5B,OAAO;;;;;EAkBhC"}
|
|
@@ -3,16 +3,18 @@ function sync(syncConfiguration) {
|
|
|
3
3
|
return {
|
|
4
4
|
_tag: "sync",
|
|
5
5
|
config: {
|
|
6
|
-
|
|
6
|
+
primaryKeyProperty: syncConfiguration.primaryKeyProperty,
|
|
7
|
+
schema: syncConfiguration.schema,
|
|
8
|
+
deleteUnreturnedPages: syncConfiguration.deleteUnreturnedPages
|
|
7
9
|
},
|
|
8
|
-
async handler() {
|
|
9
|
-
const
|
|
10
|
+
async handler(context) {
|
|
11
|
+
const executionResult = await syncConfiguration.execute(context).catch((err) => {
|
|
10
12
|
throw new ExecutionError(err);
|
|
11
13
|
});
|
|
12
14
|
const result = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
objects: executionResult.objects,
|
|
16
|
+
done: executionResult.done,
|
|
17
|
+
nextContext: executionResult.nextContext
|
|
16
18
|
};
|
|
17
19
|
process.stdout.write(`
|
|
18
20
|
<output>${JSON.stringify(result)}</output>
|
package/dist/cli/io.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../../src/cli/io.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../../src/cli/io.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAe,KAAK,SAAS,EAAkB,MAAM,mBAAmB,CAAC;AAEhF,MAAM,WAAW,aAAa;IAC7B,YAAY,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC5B,OAAO,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,EAAE,CAAC;IACrC,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;CACf;AAED,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG;IACxB,KAAK,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,qBAAa,EAAE;;IACd,YAAY,EAAE,OAAO,CAAC;gBAEV,OAAO,EAAE,aAAa;IAIlC;;;;OAIG;IACH,KAAK,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC;IAW7C;;;;OAIG;IACH,QAAQ,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IAIzD;;;;OAIG;IACH,QAAQ,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IAIzD;;;;OAIG;IACH,aAAa,CAAC,WAAW,EAAE,YAAY;IAKvC;;;;OAIG;IACH,aAAa,CAAC,WAAW,EAAE,YAAY;IAKvC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAKjE,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;CAuC7D"}
|
package/dist/cli/io.js
CHANGED
|
@@ -54,18 +54,19 @@ class IO {
|
|
|
54
54
|
this.writeErr(content);
|
|
55
55
|
}
|
|
56
56
|
confirm(config) {
|
|
57
|
-
|
|
58
|
-
this.writeErr(config.noTTY);
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
57
|
+
this.#ensureTTY(config.noTTY);
|
|
61
58
|
return prompts.confirm(config).catch(this.#handlePromptExit.bind(this));
|
|
62
59
|
}
|
|
63
60
|
input(config) {
|
|
61
|
+
this.#ensureTTY(config.noTTY);
|
|
62
|
+
return prompts.input(config).catch(this.#handlePromptExit.bind(this));
|
|
63
|
+
}
|
|
64
|
+
#ensureTTY(noTTY) {
|
|
64
65
|
if (!process.stdin.isTTY) {
|
|
65
|
-
this.writeErr(
|
|
66
|
+
this.writeErr(noTTY);
|
|
66
67
|
process.exit(1);
|
|
67
68
|
}
|
|
68
|
-
return
|
|
69
|
+
return true;
|
|
69
70
|
}
|
|
70
71
|
#handlePromptExit(err) {
|
|
71
72
|
if (err instanceof Error && err.name === "ExitPromptError") {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { emojiIcon, notionIcon } from "./builder.js";
|
|
2
2
|
export { slashCommand } from "./capabilities/slashCommand.js";
|
|
3
|
+
export type { SyncConfiguration, SyncExecutionResult, SyncedObject, } from "./capabilities/sync.js";
|
|
3
4
|
export { sync } from "./capabilities/sync.js";
|
|
4
5
|
export { tool } from "./capabilities/tool.js";
|
|
5
6
|
export type { Icon, NoticonColor, NoticonName } from "./types.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,YAAY,EACX,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,GACZ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { DateFormat, Icon, NumberFormat, SelectOption, StatusGroup } from "
|
|
|
2
2
|
/**
|
|
3
3
|
* Supported property types for sync schemas.
|
|
4
4
|
*/
|
|
5
|
-
export type PropertyType = "title" | "rich_text" | "url" | "email" | "phone_number" | "checkbox" | "file" | "number" | "date" | "select" | "multi_select" | "status";
|
|
5
|
+
export type PropertyType = "title" | "rich_text" | "url" | "email" | "phone_number" | "checkbox" | "file" | "number" | "date" | "select" | "multi_select" | "status" | "people";
|
|
6
6
|
/**
|
|
7
7
|
* Definition of a single property in a sync schema.
|
|
8
8
|
*/
|
|
@@ -41,6 +41,8 @@ export type PropertyConfiguration = {
|
|
|
41
41
|
} | {
|
|
42
42
|
type: "status";
|
|
43
43
|
groups: StatusGroup[];
|
|
44
|
+
} | {
|
|
45
|
+
type: "people";
|
|
44
46
|
};
|
|
45
47
|
export type Schema<PK extends string> = {
|
|
46
48
|
dataSourceTitle: string;
|
|
@@ -110,4 +112,8 @@ export declare function multiSelect(options: SelectOption[]): PropertyConfigurat
|
|
|
110
112
|
export declare function status(config: {
|
|
111
113
|
groups: StatusGroup[];
|
|
112
114
|
}): PropertyConfiguration;
|
|
115
|
+
/**
|
|
116
|
+
* Creates a people property definition.
|
|
117
|
+
*/
|
|
118
|
+
export declare function people(): PropertyConfiguration;
|
|
113
119
|
//# sourceMappingURL=schema.d.ts.map
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,UAAU,EACV,IAAI,EACJ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,MAAM,YAAY,GACrB,OAAO,GACP,WAAW,GACX,KAAK,GACL,OAAO,GACP,cAAc,GACd,UAAU,GACV,MAAM,GACN,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,cAAc,GACd,QAAQ,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAChC,IAAI,EAAE,YAAY,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI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Q,IAAI,qBAAqB,CAEhD;AAED;;GAEG;AACH,wBAAgB,IAAI,IAAI,qBAAqB,CAE5C;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,qBAAqB,CAEnE;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,WAAW,CAAC,EAAE,UAAU,GAAG,qBAAqB,CAEpE;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,qBAAqB,CAErE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,qBAAqB,CAE1E;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE;IAC9B,MAAM,EAAE,WAAW,EAAE,CAAC;CACtB,GAAG,qBAAqB,CAExB;AAED;;GAEG;AACH,wBAAgB,MAAM,IAAI,qBAAqB,CAE9C"}
|
package/dist/schema.js
CHANGED
|
@@ -34,6 +34,9 @@ function multiSelect(options) {
|
|
|
34
34
|
function status(config) {
|
|
35
35
|
return { type: "status", groups: config.groups };
|
|
36
36
|
}
|
|
37
|
+
function people() {
|
|
38
|
+
return { type: "people" };
|
|
39
|
+
}
|
|
37
40
|
export {
|
|
38
41
|
checkbox,
|
|
39
42
|
date,
|
|
@@ -41,6 +44,7 @@ export {
|
|
|
41
44
|
file,
|
|
42
45
|
multiSelect,
|
|
43
46
|
number,
|
|
47
|
+
people,
|
|
44
48
|
phoneNumber,
|
|
45
49
|
richText,
|
|
46
50
|
select,
|
package/dist/types.d.ts
CHANGED
|
@@ -106,5 +106,18 @@ export interface NoticonIcon {
|
|
|
106
106
|
* All possible icon types
|
|
107
107
|
*/
|
|
108
108
|
export type Icon = EmojiIcon | NoticonIcon;
|
|
109
|
+
/**
|
|
110
|
+
* Person reference - represents a user in a people property
|
|
111
|
+
*/
|
|
112
|
+
export interface PersonReference {
|
|
113
|
+
/**
|
|
114
|
+
* The email address of the user
|
|
115
|
+
*/
|
|
116
|
+
email: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* A PeopleValue is an array of person references
|
|
120
|
+
*/
|
|
121
|
+
export type PeopleValue = PersonReference[];
|
|
109
122
|
export type { NoticonName } from "./icon-names.js";
|
|
110
123
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,KAAK,SAAS,GAAG,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,WAAW,GACpB,SAAS,GACT,MAAM,GACN,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,MAAM,GACN,QAAQ,GACR,MAAM,GACN,KAAK,CAAC;AAET;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,aAAa,GAAG,UAAU,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,YAAY,EAAE,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,SA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CHANGED
package/src/builder.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { NoticonName } from "./icon-names.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
DateValue,
|
|
4
|
+
Icon,
|
|
5
|
+
NoticonColor,
|
|
6
|
+
PeopleValue,
|
|
7
|
+
TextValue,
|
|
8
|
+
} from "./types.js";
|
|
3
9
|
|
|
4
10
|
/**
|
|
5
11
|
* Creates a rich text value.
|
|
@@ -173,6 +179,14 @@ export function status(value: string): TextValue {
|
|
|
173
179
|
return [[value]];
|
|
174
180
|
}
|
|
175
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Creates a people value from email addresses.
|
|
184
|
+
* @param emails - Array of email addresses for people to include
|
|
185
|
+
*/
|
|
186
|
+
export function people(...emails: string[]): PeopleValue {
|
|
187
|
+
return emails.map((email) => ({ email }));
|
|
188
|
+
}
|
|
189
|
+
|
|
176
190
|
/**
|
|
177
191
|
* Validates a date string is in YYYY-MM-DD format and represents a valid date.
|
|
178
192
|
*/
|
package/src/capabilities/sync.ts
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import { ExecutionError } from "../error.js";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type {
|
|
3
|
+
PropertyConfiguration,
|
|
4
|
+
PropertySchema,
|
|
5
|
+
Schema,
|
|
6
|
+
} from "../schema.js";
|
|
7
|
+
import type { Icon, PeopleValue, TextValue } from "../types.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Maps a property configuration to its corresponding value type.
|
|
11
|
+
*/
|
|
12
|
+
type PropertyValueType<T extends PropertyConfiguration> = T extends {
|
|
13
|
+
type: "people";
|
|
14
|
+
}
|
|
15
|
+
? PeopleValue
|
|
16
|
+
: TextValue;
|
|
4
17
|
|
|
5
18
|
/**
|
|
6
19
|
* An object representing a third-party record to be synced.
|
|
7
20
|
*/
|
|
8
21
|
export type SyncedObject<PK extends string, S extends PropertySchema<PK>> = {
|
|
9
22
|
key: string;
|
|
10
|
-
properties: {
|
|
23
|
+
properties: {
|
|
24
|
+
[Property in keyof S]: PropertyValueType<S[Property]>;
|
|
25
|
+
};
|
|
11
26
|
/**
|
|
12
27
|
* Optional icon to use as the icon for this row's page.
|
|
13
28
|
* Use the `icon()` builder to create an icon value.
|
|
@@ -20,11 +35,40 @@ export type SyncedObject<PK extends string, S extends PropertySchema<PK>> = {
|
|
|
20
35
|
pageContentMarkdown?: string;
|
|
21
36
|
};
|
|
22
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Result returned from the sync execute function.
|
|
40
|
+
*/
|
|
41
|
+
export type SyncExecutionResult<PK extends string, Context = unknown> = {
|
|
42
|
+
/**
|
|
43
|
+
* The batch of objects fetched in this execution.
|
|
44
|
+
*/
|
|
45
|
+
objects: SyncedObject<PK, PropertySchema<PK>>[];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Indicates whether the sync is complete.
|
|
49
|
+
* - `true`: No more data to fetch, sync is complete
|
|
50
|
+
* - `false`: More data available, will trigger another execution with nextContext
|
|
51
|
+
*/
|
|
52
|
+
done: boolean;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Optional context data to pass to the next execution.
|
|
56
|
+
* Required if `done` is `false`, ignored if `done` is `true`.
|
|
57
|
+
* This can be any type of data (cursor, page number, timestamp, etc.).
|
|
58
|
+
* The same data will be provided in the context parameter of the next execution.
|
|
59
|
+
*/
|
|
60
|
+
nextContext?: Context;
|
|
61
|
+
};
|
|
62
|
+
|
|
23
63
|
/**
|
|
24
64
|
* A configuration object that enables synchronization between a data
|
|
25
65
|
* source and a third-party source.
|
|
26
66
|
*/
|
|
27
|
-
export type SyncConfiguration<
|
|
67
|
+
export type SyncConfiguration<
|
|
68
|
+
PK extends string,
|
|
69
|
+
S extends Schema<PK>,
|
|
70
|
+
Context = unknown,
|
|
71
|
+
> = {
|
|
28
72
|
/**
|
|
29
73
|
* The property of the data source that maps to a "primary key" in the
|
|
30
74
|
* third-party data. This is used to match existing pages to
|
|
@@ -37,19 +81,40 @@ export type SyncConfiguration<PK extends string, S extends Schema<PK>> = {
|
|
|
37
81
|
*/
|
|
38
82
|
schema: S;
|
|
39
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Whether to delete pages from the collection that are not returned
|
|
86
|
+
* from any of the sync executions (mark-and-sweep deletion).
|
|
87
|
+
*
|
|
88
|
+
* - `true`: Pages not seen in any execution batch will be deleted
|
|
89
|
+
* - `false` (default): Only upsert pages, never delete
|
|
90
|
+
*
|
|
91
|
+
* @default false
|
|
92
|
+
*/
|
|
93
|
+
deleteUnreturnedPages?: boolean;
|
|
94
|
+
|
|
40
95
|
/**
|
|
41
96
|
* A function that fetches the data to sync from the third-party service.
|
|
42
97
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
98
|
+
* This function can return all data at once, or implement pagination by:
|
|
99
|
+
* 1. Returning a batch of objects with `done: false` and a `nextContext`
|
|
100
|
+
* 2. The runtime will call execute again with that context data
|
|
101
|
+
* 3. Continue until `done: true` is returned
|
|
102
|
+
*
|
|
103
|
+
* The runtime will handle diffing against the data source and creating,
|
|
104
|
+
* updating, and deleting pages as necessary.
|
|
105
|
+
*
|
|
106
|
+
* @param context - Optional context data from previous execution (undefined on first call)
|
|
107
|
+
* @returns A result containing objects, done status, and optional nextContext
|
|
46
108
|
*/
|
|
47
|
-
execute: () => Promise<
|
|
109
|
+
execute: (context?: Context) => Promise<SyncExecutionResult<PK, Context>>;
|
|
48
110
|
};
|
|
49
111
|
|
|
50
|
-
export type SyncHandlerResult<PK extends string> = {
|
|
112
|
+
export type SyncHandlerResult<PK extends string, Context = unknown> = {
|
|
51
113
|
primaryKeyProperty: PK;
|
|
52
114
|
objects: SyncedObject<PK, PropertySchema<PK>>[];
|
|
115
|
+
done: boolean;
|
|
116
|
+
nextContext?: Context;
|
|
117
|
+
deleteUnreturnedPages?: boolean;
|
|
53
118
|
};
|
|
54
119
|
|
|
55
120
|
/**
|
|
@@ -59,23 +124,29 @@ export type SyncHandlerResult<PK extends string> = {
|
|
|
59
124
|
* @returns A handler function that executes the sync function, and passes data
|
|
60
125
|
* needed to complete the sync back to the platform.
|
|
61
126
|
*/
|
|
62
|
-
export function sync<
|
|
63
|
-
|
|
64
|
-
|
|
127
|
+
export function sync<
|
|
128
|
+
PK extends string,
|
|
129
|
+
S extends Schema<PK>,
|
|
130
|
+
Context = unknown,
|
|
131
|
+
>(syncConfiguration: SyncConfiguration<PK, S, Context>) {
|
|
65
132
|
return {
|
|
66
133
|
_tag: "sync",
|
|
67
134
|
config: {
|
|
135
|
+
primaryKeyProperty: syncConfiguration.primaryKeyProperty,
|
|
68
136
|
schema: syncConfiguration.schema,
|
|
137
|
+
deleteUnreturnedPages: syncConfiguration.deleteUnreturnedPages,
|
|
69
138
|
},
|
|
70
|
-
async handler() {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
139
|
+
async handler(context?: Context) {
|
|
140
|
+
const executionResult = await syncConfiguration
|
|
141
|
+
.execute(context)
|
|
142
|
+
.catch((err) => {
|
|
143
|
+
throw new ExecutionError(err);
|
|
144
|
+
});
|
|
74
145
|
|
|
75
146
|
const result = {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
147
|
+
objects: executionResult.objects,
|
|
148
|
+
done: executionResult.done,
|
|
149
|
+
nextContext: executionResult.nextContext,
|
|
79
150
|
};
|
|
80
151
|
|
|
81
152
|
process.stdout.write(`\n<output>${JSON.stringify(result)}</output>\n`);
|
package/src/cli/io.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
// biome-ignore lint/style/noRestrictedImports: This file contains safe wrappers for prompts.
|
|
1
2
|
import * as prompts from "@inquirer/prompts";
|
|
3
|
+
// biome-ignore lint/style/noRestrictedImports: This is the one allowed location for this import.
|
|
2
4
|
import { createTable, type TableCell, type TableItem } from "@visulima/tabular";
|
|
3
5
|
|
|
4
6
|
export interface WriterOptions {
|
|
@@ -80,21 +82,22 @@ export class IO {
|
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
confirm(config: WithSafety<Parameters<typeof prompts.confirm>[0]>) {
|
|
83
|
-
|
|
84
|
-
this.writeErr(config.noTTY);
|
|
85
|
-
process.exit(1);
|
|
86
|
-
}
|
|
87
|
-
|
|
85
|
+
this.#ensureTTY(config.noTTY);
|
|
88
86
|
return prompts.confirm(config).catch(this.#handlePromptExit.bind(this));
|
|
89
87
|
}
|
|
90
88
|
|
|
91
89
|
input(config: WithSafety<Parameters<typeof prompts.input>[0]>) {
|
|
90
|
+
this.#ensureTTY(config.noTTY);
|
|
91
|
+
return prompts.input(config).catch(this.#handlePromptExit.bind(this));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
#ensureTTY(noTTY: string): true | never {
|
|
92
95
|
if (!process.stdin.isTTY) {
|
|
93
|
-
this.writeErr(
|
|
96
|
+
this.writeErr(noTTY);
|
|
94
97
|
process.exit(1);
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
return
|
|
100
|
+
return true;
|
|
98
101
|
}
|
|
99
102
|
|
|
100
103
|
#handlePromptExit(err: unknown) {
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export { emojiIcon, notionIcon } from "./builder.js";
|
|
2
2
|
export { slashCommand } from "./capabilities/slashCommand.js";
|
|
3
|
+
export type {
|
|
4
|
+
SyncConfiguration,
|
|
5
|
+
SyncExecutionResult,
|
|
6
|
+
SyncedObject,
|
|
7
|
+
} from "./capabilities/sync.js";
|
|
3
8
|
export { sync } from "./capabilities/sync.js";
|
|
4
9
|
export { tool } from "./capabilities/tool.js";
|
|
5
10
|
export type { Icon, NoticonColor, NoticonName } from "./types.js";
|
package/src/schema.ts
CHANGED
|
@@ -21,7 +21,8 @@ export type PropertyType =
|
|
|
21
21
|
| "date"
|
|
22
22
|
| "select"
|
|
23
23
|
| "multi_select"
|
|
24
|
-
| "status"
|
|
24
|
+
| "status"
|
|
25
|
+
| "people";
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Definition of a single property in a sync schema.
|
|
@@ -60,7 +61,8 @@ export type PropertyConfiguration =
|
|
|
60
61
|
| {
|
|
61
62
|
type: "status";
|
|
62
63
|
groups: StatusGroup[];
|
|
63
|
-
}
|
|
64
|
+
}
|
|
65
|
+
| { type: "people" };
|
|
64
66
|
|
|
65
67
|
export type Schema<PK extends string> = {
|
|
66
68
|
dataSourceTitle: string;
|
|
@@ -167,3 +169,10 @@ export function status(config: {
|
|
|
167
169
|
}): PropertyConfiguration {
|
|
168
170
|
return { type: "status", groups: config.groups };
|
|
169
171
|
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Creates a people property definition.
|
|
175
|
+
*/
|
|
176
|
+
export function people(): PropertyConfiguration {
|
|
177
|
+
return { type: "people" };
|
|
178
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -160,4 +160,19 @@ export interface NoticonIcon {
|
|
|
160
160
|
*/
|
|
161
161
|
export type Icon = EmojiIcon | NoticonIcon;
|
|
162
162
|
|
|
163
|
+
/**
|
|
164
|
+
* Person reference - represents a user in a people property
|
|
165
|
+
*/
|
|
166
|
+
export interface PersonReference {
|
|
167
|
+
/**
|
|
168
|
+
* The email address of the user
|
|
169
|
+
*/
|
|
170
|
+
email: string;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* A PeopleValue is an array of person references
|
|
175
|
+
*/
|
|
176
|
+
export type PeopleValue = PersonReference[];
|
|
177
|
+
|
|
163
178
|
export type { NoticonName } from "./icon-names.js";
|