@haustle/notion-orm 0.0.38 → 0.0.42
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/README.md +132 -0
- package/build/src/BuildCall.d.ts +15 -2
- package/build/src/BuildCall.d.ts.map +1 -1
- package/build/src/BuildCall.js +35 -2
- package/build/src/BuildCall.js.map +1 -1
- package/build/src/DatabaseActions.d.ts +3 -4
- package/build/src/DatabaseActions.d.ts.map +1 -1
- package/build/src/DatabaseActions.js +7 -2
- package/build/src/DatabaseActions.js.map +1 -1
- package/build/src/GenerateTypes.d.ts +0 -3
- package/build/src/GenerateTypes.d.ts.map +1 -1
- package/build/src/GenerateTypes.js +49 -58
- package/build/src/GenerateTypes.js.map +1 -1
- package/build/src/cli.js +2 -4
- package/build/src/cli.js.map +1 -1
- package/build/src/index.d.ts +12 -0
- package/build/src/index.d.ts.map +1 -0
- package/build/src/{NotionConfig.js → index.js} +21 -15
- package/build/src/index.js.map +1 -0
- package/build/src/queryTypes.d.ts +22 -11
- package/build/src/queryTypes.d.ts.map +1 -1
- package/build/src/queryTypes.js +0 -6
- package/build/src/queryTypes.js.map +1 -1
- package/package.json +12 -6
- package/src/BuildCall.ts +37 -4
- package/src/DatabaseActions.ts +12 -6
- package/src/GenerateTypes.ts +68 -71
- package/src/cli.ts +1 -4
- package/src/{NotionConfig.ts → index.ts} +23 -19
- package/src/queryTypes.ts +34 -25
- package/build/src/NotionConfig.d.ts +0 -9
- package/build/src/NotionConfig.d.ts.map +0 -1
- package/build/src/NotionConfig.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,eAAO,MAAM,aAAa,QAAmD,CAAC;AAE9E,MAAM,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,mBAAmB,SAAgB,gBAAgB;;EAyD/D,CAAC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Responsible for consuming notion.config.js
|
|
4
|
+
*/
|
|
2
5
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
6
|
if (k2 === undefined) k2 = k;
|
|
4
7
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -41,10 +44,9 @@ const GenerateTypes_1 = require("./GenerateTypes");
|
|
|
41
44
|
const ts = __importStar(require("typescript"));
|
|
42
45
|
const fs_1 = __importDefault(require("fs"));
|
|
43
46
|
const path_1 = __importDefault(require("path"));
|
|
44
|
-
require("dotenv").config();
|
|
45
47
|
exports.DATABASES_DIR = path_1.default.join(__dirname, "../../build", "databases");
|
|
46
|
-
const createDatabaseTypes = (
|
|
47
|
-
const { auth, databaseIds } =
|
|
48
|
+
const createDatabaseTypes = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
const { auth, databaseIds } = args;
|
|
48
50
|
// Making sure the user is passing valid arguments
|
|
49
51
|
if (!auth) {
|
|
50
52
|
console.error("Please pass a valid Notion Integration Key");
|
|
@@ -74,7 +76,6 @@ const createDatabaseTypes = (notionInfo) => __awaiter(void 0, void 0, void 0, fu
|
|
|
74
76
|
databaseNames.push(databaseName);
|
|
75
77
|
databaseClassExportStatements.push(databaseExportStatement({
|
|
76
78
|
databaseClassName,
|
|
77
|
-
databaseId,
|
|
78
79
|
}));
|
|
79
80
|
}
|
|
80
81
|
catch (e) {
|
|
@@ -83,31 +84,36 @@ const createDatabaseTypes = (notionInfo) => __awaiter(void 0, void 0, void 0, fu
|
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
// Create a file that exports all databases
|
|
86
|
-
|
|
87
|
+
createDatabaseBarrelFile({
|
|
88
|
+
databaseClassExportStatements,
|
|
89
|
+
});
|
|
87
90
|
return { databaseNames };
|
|
88
91
|
});
|
|
89
92
|
exports.createDatabaseTypes = createDatabaseTypes;
|
|
90
|
-
// Create the
|
|
91
|
-
|
|
93
|
+
// Create the export statement for database file file
|
|
94
|
+
// export { databaseName } from "./databaseName"
|
|
95
|
+
function databaseExportStatement(args) {
|
|
96
|
+
const { databaseClassName } = args;
|
|
92
97
|
return ts.factory.createExportDeclaration(undefined, false, ts.factory.createNamedExports([
|
|
93
|
-
ts.factory.createExportSpecifier(false, undefined, ts.factory.createIdentifier(
|
|
94
|
-
]), ts.factory.createStringLiteral(`./${
|
|
98
|
+
ts.factory.createExportSpecifier(false, undefined, ts.factory.createIdentifier(databaseClassName)),
|
|
99
|
+
]), ts.factory.createStringLiteral(`./${databaseClassName}`), undefined);
|
|
95
100
|
}
|
|
96
101
|
// Creates file that import all generated notion database Ids
|
|
97
|
-
function
|
|
98
|
-
const
|
|
102
|
+
function createDatabaseBarrelFile(args) {
|
|
103
|
+
const { databaseClassExportStatements } = args;
|
|
104
|
+
const nodes = ts.factory.createNodeArray(databaseClassExportStatements);
|
|
99
105
|
const sourceFile = ts.createSourceFile("placeholder.ts", "", ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS);
|
|
100
106
|
const printer = ts.createPrinter();
|
|
101
107
|
const typescriptCodeToString = printer.printList(ts.ListFormat.MultiLine, nodes, sourceFile);
|
|
102
108
|
const transpileToJavaScript = ts.transpile(typescriptCodeToString, {
|
|
103
109
|
module: ts.ModuleKind.None,
|
|
104
|
-
target: ts.ScriptTarget.
|
|
110
|
+
target: ts.ScriptTarget.ES2015,
|
|
105
111
|
});
|
|
106
112
|
if (!fs_1.default.existsSync(exports.DATABASES_DIR)) {
|
|
107
113
|
fs_1.default.mkdirSync(exports.DATABASES_DIR);
|
|
108
114
|
}
|
|
109
115
|
// Create TypeScript and JavaScript file
|
|
110
|
-
fs_1.default.writeFileSync(path_1.default.resolve(exports.DATABASES_DIR, "
|
|
111
|
-
fs_1.default.writeFileSync(path_1.default.resolve(exports.DATABASES_DIR, "
|
|
116
|
+
fs_1.default.writeFileSync(path_1.default.resolve(exports.DATABASES_DIR, "index.ts"), typescriptCodeToString);
|
|
117
|
+
fs_1.default.writeFileSync(path_1.default.resolve(exports.DATABASES_DIR, "index.js"), transpileToJavaScript);
|
|
112
118
|
}
|
|
113
|
-
//# sourceMappingURL=
|
|
119
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA0C;AAE1C,mDAAkE;AAClE,+CAAiC;AACjC,4CAAoB;AACpB,gDAAwB;AAEX,QAAA,aAAa,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;AAOvE,MAAM,mBAAmB,GAAG,CAAO,IAAsB,EAAE,EAAE;IACnE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IAEnC,kDAAkD;IAClD,IAAI,CAAC,IAAI,EAAE;QACV,OAAO,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAChB;IAED,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;QAC3B,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;QAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAChB;IAED,oBAAoB;IACpB,MAAM,YAAY,GAAG,IAAI,eAAM,CAAC;QAC/B,IAAI,EAAE,IAAI;KACV,CAAC,CAAC;IAEH,MAAM,aAAa,GAAa,EAAE,CAAC;IACnC,MAAM,6BAA6B,GAA2B,EAAE,CAAC;IAEjE,8DAA8D;IAC9D,YAAE,CAAC,KAAK,CAAC,qBAAa,EAAE,GAAG,EAAE,CA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|
+
type columnDiscriminatedUnionTypes = PageObjectResponse["properties"];
|
|
6
|
+
export type NotionColumnTypes = columnDiscriminatedUnionTypes[keyof columnDiscriminatedUnionTypes]["type"];
|
|
7
|
+
export type SupportedNotionColumnTypes = Exclude<NotionColumnTypes, "formula" | "files" | "people" | "relation" | "rollup" | "created_by" | "last_edited_by" | "created_time" | "last_edited_time">;
|
|
5
8
|
type TextPropertyFilters = {
|
|
6
9
|
equals: string;
|
|
7
10
|
does_not_equal: string;
|
|
@@ -38,11 +41,13 @@ type MultiSelectPropertyFilters<T> = {
|
|
|
38
41
|
is_empty: true;
|
|
39
42
|
is_not_empty: true;
|
|
40
43
|
};
|
|
44
|
+
type StatusPropertyFilters<T> = SelectPropertyFilters<T>;
|
|
45
|
+
type ISO8601Date = string;
|
|
41
46
|
type DatePropertyFilters = {
|
|
42
|
-
equals:
|
|
43
|
-
before:
|
|
44
|
-
after:
|
|
45
|
-
on_or_before:
|
|
47
|
+
equals: ISO8601Date;
|
|
48
|
+
before: ISO8601Date;
|
|
49
|
+
after: ISO8601Date;
|
|
50
|
+
on_or_before: ISO8601Date;
|
|
46
51
|
is_empty: true;
|
|
47
52
|
is_not_empty: true;
|
|
48
53
|
on_or_after: string;
|
|
@@ -55,26 +60,32 @@ type DatePropertyFilters = {
|
|
|
55
60
|
next_year: {};
|
|
56
61
|
};
|
|
57
62
|
export type FilterOptions<T = []> = {
|
|
58
|
-
|
|
63
|
+
rich_text: TextPropertyFilters;
|
|
59
64
|
title: TextPropertyFilters;
|
|
60
65
|
number: NumberPropertyFilters;
|
|
61
66
|
checkbox: CheckBoxPropertyFilters;
|
|
62
67
|
select: SelectPropertyFilters<T>;
|
|
63
68
|
multi_select: MultiSelectPropertyFilters<T>;
|
|
64
|
-
url:
|
|
69
|
+
url: TextPropertyFilters;
|
|
65
70
|
date: DatePropertyFilters;
|
|
71
|
+
status: StatusPropertyFilters<T>;
|
|
72
|
+
email: TextPropertyFilters;
|
|
73
|
+
phone_number: TextPropertyFilters;
|
|
66
74
|
};
|
|
67
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Types to build query object user types out
|
|
77
|
+
*/
|
|
78
|
+
type ColumnNameToNotionColumnType<T> = Record<keyof T, SupportedNotionColumnTypes>;
|
|
68
79
|
export type SingleFilter<Y extends Record<string, any>, T extends ColumnNameToNotionColumnType<Y>> = {
|
|
69
80
|
[Property in keyof Y]?: Partial<FilterOptions<Y[Property]>[T[Property]]>;
|
|
70
81
|
};
|
|
71
|
-
export type CompoundFilters<Y extends Record<string, any>, T extends Record<keyof Y,
|
|
82
|
+
export type CompoundFilters<Y extends Record<string, any>, T extends Record<keyof Y, SupportedNotionColumnTypes>> = {
|
|
72
83
|
and: Array<SingleFilter<Y, T> | CompoundFilters<Y, T>>;
|
|
73
84
|
} | {
|
|
74
85
|
or: Array<SingleFilter<Y, T> | CompoundFilters<Y, T>>;
|
|
75
86
|
};
|
|
76
|
-
export type QueryFilter<Y extends Record<string, any>, T extends Record<keyof Y,
|
|
77
|
-
export type Query<Y extends Record<string, any>, T extends Record<keyof Y,
|
|
87
|
+
export type QueryFilter<Y extends Record<string, any>, T extends Record<keyof Y, SupportedNotionColumnTypes>> = SingleFilter<Y, T> | CompoundFilters<Y, T>;
|
|
88
|
+
export type Query<Y extends Record<string, any>, T extends Record<keyof Y, SupportedNotionColumnTypes>> = {
|
|
78
89
|
filter?: QueryFilter<Y, T>;
|
|
79
90
|
sort?: [];
|
|
80
91
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryTypes.d.ts","sourceRoot":"","sources":["../../src/queryTypes.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"queryTypes.d.ts","sourceRoot":"","sources":["../../src/queryTypes.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAE9E,KAAK,6BAA6B,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC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,CAAC,EAC7B,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,EAAE,0BAA0B,CAAC,IAClD,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE/C,MAAM,MAAM,KAAK,CAChB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,EAAE,0BAA0B,CAAC,IAClD;IACH,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC3B,IAAI,CAAC,EAAE,EAAE,CAAC;CACV,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC5B,MAAM,CAAC,EAAE,eAAe,GAAG,YAAY,GAAG,WAAW,CAAC;CACtD,CAAC;AAEF;;;GAGG;AAEH,KAAK,sBAAsB,GAAG;KAC5B,IAAI,IAAI,MAAM,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;CAC5D,CAAC;AACF,MAAM,WAAW,eAAgB,SAAQ,sBAAsB;IAC9D,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,aAAa,GACtB,eAAe,GACf,YAAY,GACZ,WAAW,GACX,SAAS,CAAC;AACb,KAAK,YAAY,GAAG;IACnB,GAAG,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;CAC1B,CAAC;AAEF,KAAK,WAAW,GAAG;IAClB,EAAE,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;CACzB,CAAC"}
|
package/build/src/queryTypes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryTypes.js","sourceRoot":"","sources":["../../src/queryTypes.ts"],"names":[],"mappings":";AAAA;;GAEG;AACH,gCAAgC
|
|
1
|
+
{"version":3,"file":"queryTypes.js","sourceRoot":"","sources":["../../src/queryTypes.ts"],"names":[],"mappings":";AAAA;;GAEG;AACH,gCAAgC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haustle/notion-orm",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.42",
|
|
4
4
|
"description": "tool to bring notion databases schemas/types to typescript",
|
|
5
|
-
"main": "build/
|
|
5
|
+
"main": "build/databases/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"notion": "build/src/cli.js"
|
|
8
8
|
},
|
|
@@ -19,8 +19,14 @@
|
|
|
19
19
|
"typescript": "^4.8.4"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@notionhq/client": "^2.2.2"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
"@notionhq/client": "^2.2.2"
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/Haustle/notion-orm"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/Haustle/notion-orm#readme",
|
|
30
|
+
"keywords": ["notion orm", "typescript", "notion typesafety", "notion auto-complete", "notion databases", "notion-tables"]
|
|
31
|
+
|
|
26
32
|
}
|
package/src/BuildCall.ts
CHANGED
|
@@ -1,25 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SupportedNotionColumnTypes } from "./queryTypes";
|
|
2
2
|
|
|
3
3
|
export function getCall(args: {
|
|
4
|
-
type:
|
|
4
|
+
type: SupportedNotionColumnTypes;
|
|
5
5
|
value: string | number | boolean;
|
|
6
6
|
}) {
|
|
7
7
|
const { type, value } = args;
|
|
8
|
-
console.log(type, value, typeof value);
|
|
9
8
|
if (type === "select" && typeof value === "string") {
|
|
10
9
|
return selectCall({ value });
|
|
11
10
|
} else if (type === "multi_select" && Array.isArray(value)) {
|
|
12
11
|
return multiSelectCall({ value });
|
|
12
|
+
} else if (type === "status" && typeof value === "string") {
|
|
13
|
+
return statusCall({ option: value });
|
|
13
14
|
} else if (type === "number" && typeof value === "number") {
|
|
14
15
|
return numberCall({ value });
|
|
16
|
+
} else if (type === "email" && typeof value === "string") {
|
|
17
|
+
return emailCall({ value });
|
|
18
|
+
} else if (type === "date" && typeof value === "object") {
|
|
19
|
+
return dateCall({ value });
|
|
20
|
+
} else if (type === "phone_number" && typeof value === "string") {
|
|
21
|
+
return phoneNumberCall({ value });
|
|
15
22
|
} else if (type === "url" && typeof value === "string") {
|
|
16
23
|
return urlCall({ url: value });
|
|
17
24
|
} else if (type === "checkbox" && typeof value === "boolean") {
|
|
18
25
|
return checkboxCall({ checked: value });
|
|
19
26
|
} else if (type === "title" && typeof value === "string") {
|
|
20
27
|
return titleCall({ title: value });
|
|
21
|
-
} else if (type === "
|
|
28
|
+
} else if (type === "rich_text" && typeof value === "string") {
|
|
22
29
|
return textCall({ text: value });
|
|
30
|
+
} else {
|
|
31
|
+
console.error(
|
|
32
|
+
`'[@haustle/notion-orm] ${type}' column type currently not supported`
|
|
33
|
+
);
|
|
23
34
|
}
|
|
24
35
|
}
|
|
25
36
|
|
|
@@ -37,6 +48,23 @@ const selectCall = (args: { value: string }) => {
|
|
|
37
48
|
return { select };
|
|
38
49
|
};
|
|
39
50
|
|
|
51
|
+
const dateCall = (args: { value: { start: string; end?: string } }) => {
|
|
52
|
+
const { value } = args;
|
|
53
|
+
return { date: value };
|
|
54
|
+
};
|
|
55
|
+
const phoneNumberCall = (args: { value: string }) => {
|
|
56
|
+
const { value } = args;
|
|
57
|
+
return { phone_number: value };
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const statusCall = (args: { option: string }) => {
|
|
61
|
+
const { option } = args;
|
|
62
|
+
const status = {
|
|
63
|
+
name: option,
|
|
64
|
+
};
|
|
65
|
+
return { status };
|
|
66
|
+
};
|
|
67
|
+
|
|
40
68
|
const multiSelectCall = (args: { value: Array<string> }) => {
|
|
41
69
|
const { value } = args;
|
|
42
70
|
const multi_select = value.map((option) => ({ name: option }));
|
|
@@ -83,3 +111,8 @@ const checkboxCall = (args: { checked: boolean }) => {
|
|
|
83
111
|
const { checked: checkbox } = args;
|
|
84
112
|
return { checkbox };
|
|
85
113
|
};
|
|
114
|
+
|
|
115
|
+
const emailCall = (args: { value: string }) => {
|
|
116
|
+
const { value } = args;
|
|
117
|
+
return { email: value };
|
|
118
|
+
};
|
package/src/DatabaseActions.ts
CHANGED
|
@@ -4,32 +4,38 @@ import {
|
|
|
4
4
|
} from "@notionhq/client/build/src/api-endpoints";
|
|
5
5
|
import { Client } from "@notionhq/client";
|
|
6
6
|
import { getCall } from "./BuildCall";
|
|
7
|
-
import
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { NotionConfigType } from "./index";
|
|
8
9
|
import {
|
|
9
10
|
apiFilterType,
|
|
10
11
|
apiSingleFilter,
|
|
11
12
|
CompoundFilters,
|
|
12
|
-
FilterOptionNames,
|
|
13
13
|
Query,
|
|
14
14
|
QueryFilter,
|
|
15
15
|
SingleFilter,
|
|
16
|
+
SupportedNotionColumnTypes,
|
|
16
17
|
} from "./queryTypes";
|
|
17
|
-
require("dotenv").config();
|
|
18
18
|
|
|
19
19
|
export type propNameToColumnNameType = Record<
|
|
20
20
|
string,
|
|
21
|
-
{ columnName: string; type:
|
|
21
|
+
{ columnName: string; type: SupportedNotionColumnTypes }
|
|
22
22
|
>;
|
|
23
23
|
|
|
24
|
+
// Import auth key from config file
|
|
25
|
+
const { auth }: NotionConfigType = require(path.join(
|
|
26
|
+
process.cwd(),
|
|
27
|
+
"notion.config"
|
|
28
|
+
));
|
|
29
|
+
|
|
24
30
|
export class DatabaseActions<
|
|
25
31
|
DatabaseSchemaType extends Record<string, any>,
|
|
26
32
|
ColumnNameToColumnType extends Record<
|
|
27
33
|
keyof DatabaseSchemaType,
|
|
28
|
-
|
|
34
|
+
SupportedNotionColumnTypes
|
|
29
35
|
>
|
|
30
36
|
> {
|
|
31
37
|
private NotionClient: Client = new Client({
|
|
32
|
-
auth
|
|
38
|
+
auth,
|
|
33
39
|
});
|
|
34
40
|
private databaseId: string;
|
|
35
41
|
private propNameToColumnName: propNameToColumnNameType;
|
package/src/GenerateTypes.ts
CHANGED
|
@@ -5,23 +5,12 @@ import {
|
|
|
5
5
|
import * as ts from "typescript";
|
|
6
6
|
import fs from "fs";
|
|
7
7
|
import path from "path";
|
|
8
|
-
import { DATABASES_DIR } from "./
|
|
9
|
-
|
|
10
|
-
// This can be grabbed from // api-endpoints.d.ts with some work
|
|
11
|
-
const propertyArr = [
|
|
12
|
-
"text",
|
|
13
|
-
"select",
|
|
14
|
-
"title",
|
|
15
|
-
"number",
|
|
16
|
-
"multi_select",
|
|
17
|
-
"checkbox",
|
|
18
|
-
"url",
|
|
19
|
-
];
|
|
20
|
-
export type PropertyType = typeof propertyArr[number];
|
|
8
|
+
import { DATABASES_DIR } from "./index";
|
|
9
|
+
import { NotionColumnTypes } from "queryTypes";
|
|
21
10
|
|
|
22
11
|
type propNameToColumnNameType = Record<
|
|
23
12
|
string,
|
|
24
|
-
{ columnName: string; type:
|
|
13
|
+
{ columnName: string; type: NotionColumnTypes }
|
|
25
14
|
>;
|
|
26
15
|
|
|
27
16
|
/*
|
|
@@ -54,10 +43,18 @@ export async function createTypescriptFileForDatabase(
|
|
|
54
43
|
type: columnType,
|
|
55
44
|
};
|
|
56
45
|
|
|
57
|
-
if (
|
|
46
|
+
if (
|
|
47
|
+
columnType === "title" ||
|
|
48
|
+
columnType === "rich_text" ||
|
|
49
|
+
columnType === "email" ||
|
|
50
|
+
columnType === "phone_number"
|
|
51
|
+
) {
|
|
58
52
|
// add text column to collection type
|
|
59
53
|
databaseColumnTypeProps.push(
|
|
60
|
-
createTextProperty(
|
|
54
|
+
createTextProperty({
|
|
55
|
+
name: camelizedColumnName,
|
|
56
|
+
isTitle: columnType === "title",
|
|
57
|
+
})
|
|
61
58
|
);
|
|
62
59
|
} else if (columnType === "number") {
|
|
63
60
|
// add number column to collection type
|
|
@@ -65,21 +62,24 @@ export async function createTypescriptFileForDatabase(
|
|
|
65
62
|
} else if (columnType === "url") {
|
|
66
63
|
// add url column to collection type
|
|
67
64
|
databaseColumnTypeProps.push(
|
|
68
|
-
createTextProperty(camelizedColumnName, false)
|
|
65
|
+
createTextProperty({ name: camelizedColumnName, isTitle: false })
|
|
69
66
|
);
|
|
70
67
|
} else if (columnType === "date") {
|
|
71
68
|
// add Date column to collection type
|
|
72
69
|
databaseColumnTypeProps.push(createDateProperty(camelizedColumnName));
|
|
73
|
-
} else if (
|
|
70
|
+
} else if (
|
|
71
|
+
columnType === "select" ||
|
|
72
|
+
columnType === "status" ||
|
|
73
|
+
columnType === "multi_select"
|
|
74
|
+
) {
|
|
74
75
|
// @ts-ignore
|
|
75
76
|
const options = value[columnType].options.map((x) => x.name);
|
|
76
77
|
databaseColumnTypeProps.push(
|
|
77
|
-
createMultiOptionProp(
|
|
78
|
-
camelizedColumnName,
|
|
78
|
+
createMultiOptionProp({
|
|
79
|
+
name: camelizedColumnName,
|
|
79
80
|
options,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
)
|
|
81
|
+
isArray: columnType === "multi_select", // Union or Union Array
|
|
82
|
+
})
|
|
83
83
|
);
|
|
84
84
|
}
|
|
85
85
|
});
|
|
@@ -94,12 +94,12 @@ export async function createTypescriptFileForDatabase(
|
|
|
94
94
|
|
|
95
95
|
// Top level non-nested variable, functions, types for database files
|
|
96
96
|
const TsNodesForDatabaseFile = ts.factory.createNodeArray([
|
|
97
|
-
|
|
97
|
+
createDatabaseActionsClassImport(),
|
|
98
98
|
createDatabaseIdVariable(databaseId),
|
|
99
99
|
DatabaseSchemaType,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
createColumnNameToColumnProperties(propNameToColumnName),
|
|
101
|
+
createColumnNameToColumnType(),
|
|
102
|
+
createDatabaseClassExport({ databaseName: databaseClassName }),
|
|
103
103
|
]);
|
|
104
104
|
|
|
105
105
|
const sourceFile = ts.createSourceFile(
|
|
@@ -116,24 +116,23 @@ export async function createTypescriptFileForDatabase(
|
|
|
116
116
|
TsNodesForDatabaseFile,
|
|
117
117
|
sourceFile
|
|
118
118
|
);
|
|
119
|
-
|
|
120
119
|
const transpileToJavaScript = ts.transpile(typescriptCodeToString, {
|
|
121
120
|
module: ts.ModuleKind.None,
|
|
122
|
-
target: ts.ScriptTarget.
|
|
121
|
+
target: ts.ScriptTarget.ESNext,
|
|
123
122
|
});
|
|
124
123
|
|
|
125
|
-
// Create
|
|
124
|
+
// Create databases output folder
|
|
126
125
|
if (!fs.existsSync(DATABASES_DIR)) {
|
|
127
126
|
fs.mkdirSync(DATABASES_DIR);
|
|
128
127
|
}
|
|
129
128
|
|
|
130
129
|
// Create TypeScript and JavaScript files
|
|
131
130
|
fs.writeFileSync(
|
|
132
|
-
path.resolve(DATABASES_DIR, `${
|
|
131
|
+
path.resolve(DATABASES_DIR, `${databaseClassName}.ts`),
|
|
133
132
|
typescriptCodeToString
|
|
134
133
|
);
|
|
135
134
|
fs.writeFileSync(
|
|
136
|
-
path.resolve(DATABASES_DIR, `${
|
|
135
|
+
path.resolve(DATABASES_DIR, `${databaseClassName}.js`),
|
|
137
136
|
transpileToJavaScript
|
|
138
137
|
);
|
|
139
138
|
|
|
@@ -141,7 +140,8 @@ export async function createTypescriptFileForDatabase(
|
|
|
141
140
|
}
|
|
142
141
|
|
|
143
142
|
// generate text property
|
|
144
|
-
function createTextProperty(name: string
|
|
143
|
+
function createTextProperty(args: { name: string; isTitle: boolean }) {
|
|
144
|
+
const { name, isTitle } = args;
|
|
145
145
|
const text = ts.factory.createPropertySignature(
|
|
146
146
|
undefined,
|
|
147
147
|
ts.factory.createIdentifier(name),
|
|
@@ -166,28 +166,20 @@ function createNumberProperty(name: string) {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
|
-
*
|
|
170
|
-
* @param name name of property
|
|
171
|
-
* @param options
|
|
172
|
-
* @param array
|
|
173
|
-
* @returns
|
|
174
|
-
*
|
|
175
169
|
* For selects and multi-select collection properties
|
|
176
|
-
*
|
|
177
170
|
* array = true for multi-select
|
|
178
|
-
*
|
|
179
|
-
* name = ("x" | "y" | "z")[]
|
|
180
171
|
*/
|
|
181
|
-
function createMultiOptionProp(
|
|
182
|
-
name: string
|
|
183
|
-
options: string[]
|
|
184
|
-
|
|
185
|
-
) {
|
|
172
|
+
function createMultiOptionProp(args: {
|
|
173
|
+
name: string;
|
|
174
|
+
options: string[];
|
|
175
|
+
isArray: boolean;
|
|
176
|
+
}) {
|
|
177
|
+
const { isArray, name, options } = args;
|
|
186
178
|
return ts.factory.createPropertySignature(
|
|
187
179
|
undefined,
|
|
188
180
|
ts.factory.createIdentifier(name),
|
|
189
181
|
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
190
|
-
|
|
182
|
+
isArray
|
|
191
183
|
? ts.factory.createArrayTypeNode(
|
|
192
184
|
ts.factory.createParenthesizedType(
|
|
193
185
|
ts.factory.createUnionTypeNode([
|
|
@@ -218,15 +210,26 @@ function createOtherStringProp() {
|
|
|
218
210
|
ts.factory.createTypeLiteralNode([]),
|
|
219
211
|
]);
|
|
220
212
|
}
|
|
213
|
+
|
|
221
214
|
function createDateProperty(name: string) {
|
|
222
215
|
return ts.factory.createPropertySignature(
|
|
223
216
|
undefined,
|
|
224
217
|
ts.factory.createIdentifier(name),
|
|
225
218
|
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
226
|
-
ts.factory.
|
|
227
|
-
ts.factory.
|
|
228
|
-
|
|
229
|
-
|
|
219
|
+
ts.factory.createTypeLiteralNode([
|
|
220
|
+
ts.factory.createPropertySignature(
|
|
221
|
+
undefined,
|
|
222
|
+
ts.factory.createIdentifier("start"),
|
|
223
|
+
undefined,
|
|
224
|
+
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
|
|
225
|
+
),
|
|
226
|
+
ts.factory.createPropertySignature(
|
|
227
|
+
undefined,
|
|
228
|
+
ts.factory.createIdentifier("end"),
|
|
229
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
230
|
+
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
|
|
231
|
+
),
|
|
232
|
+
])
|
|
230
233
|
);
|
|
231
234
|
}
|
|
232
235
|
|
|
@@ -256,7 +259,7 @@ function createDatabaseIdVariable(databaseId: string) {
|
|
|
256
259
|
*
|
|
257
260
|
* Example
|
|
258
261
|
*
|
|
259
|
-
* const
|
|
262
|
+
* const columnNameToColumnProperties = {
|
|
260
263
|
*
|
|
261
264
|
* "bookRating": {
|
|
262
265
|
* columnName: "Book Rating",
|
|
@@ -268,14 +271,12 @@ function createDatabaseIdVariable(databaseId: string) {
|
|
|
268
271
|
* }
|
|
269
272
|
*
|
|
270
273
|
* }
|
|
271
|
-
* @param colMap
|
|
272
|
-
* @returns
|
|
273
274
|
*/
|
|
274
|
-
function
|
|
275
|
+
function createColumnNameToColumnProperties(colMap: propNameToColumnNameType) {
|
|
275
276
|
return ts.factory.createVariableDeclarationList(
|
|
276
277
|
[
|
|
277
278
|
ts.factory.createVariableDeclaration(
|
|
278
|
-
ts.factory.createIdentifier("
|
|
279
|
+
ts.factory.createIdentifier("columnNameToColumnProperties"),
|
|
279
280
|
undefined,
|
|
280
281
|
undefined,
|
|
281
282
|
ts.factory.createAsExpression(
|
|
@@ -313,7 +314,7 @@ function mapPropNameToColumnDetails(colMap: propNameToColumnNameType) {
|
|
|
313
314
|
);
|
|
314
315
|
}
|
|
315
316
|
|
|
316
|
-
function
|
|
317
|
+
function createColumnNameToColumnType() {
|
|
317
318
|
return ts.factory.createTypeAliasDeclaration(
|
|
318
319
|
undefined,
|
|
319
320
|
ts.factory.createIdentifier("ColumnNameToColumnType"),
|
|
@@ -326,7 +327,7 @@ function ColumnNameToColumnType() {
|
|
|
326
327
|
ts.factory.createTypeOperatorNode(
|
|
327
328
|
ts.SyntaxKind.KeyOfKeyword,
|
|
328
329
|
ts.factory.createTypeQueryNode(
|
|
329
|
-
ts.factory.createIdentifier("
|
|
330
|
+
ts.factory.createIdentifier("columnNameToColumnProperties"),
|
|
330
331
|
undefined
|
|
331
332
|
)
|
|
332
333
|
),
|
|
@@ -337,7 +338,7 @@ function ColumnNameToColumnType() {
|
|
|
337
338
|
ts.factory.createIndexedAccessTypeNode(
|
|
338
339
|
ts.factory.createIndexedAccessTypeNode(
|
|
339
340
|
ts.factory.createTypeQueryNode(
|
|
340
|
-
ts.factory.createIdentifier("
|
|
341
|
+
ts.factory.createIdentifier("columnNameToColumnProperties"),
|
|
341
342
|
undefined
|
|
342
343
|
),
|
|
343
344
|
ts.factory.createTypeReferenceNode(
|
|
@@ -353,8 +354,8 @@ function ColumnNameToColumnType() {
|
|
|
353
354
|
);
|
|
354
355
|
}
|
|
355
356
|
|
|
356
|
-
// Need to import the class
|
|
357
|
-
function
|
|
357
|
+
// Need to import the database class used to execute database actions (adding + querying)
|
|
358
|
+
function createDatabaseActionsClassImport() {
|
|
358
359
|
return ts.factory.createImportDeclaration(
|
|
359
360
|
undefined,
|
|
360
361
|
ts.factory.createImportClause(
|
|
@@ -373,16 +374,12 @@ function importCollectionClass() {
|
|
|
373
374
|
);
|
|
374
375
|
}
|
|
375
376
|
|
|
376
|
-
// We export the database with the class above.
|
|
377
|
-
// export
|
|
378
|
-
|
|
379
377
|
/**
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
* const <datbase-name> = new DatabaseActions<DatabaseSchemaType>(datbaseId, propMap)
|
|
378
|
+
* Create export statement for the database class
|
|
379
|
+
* export const <databaseName> = new DatabaseActions<DatabaseSchemaType>(datbaseId, columnNameToColumnProperties)
|
|
384
380
|
*/
|
|
385
|
-
function
|
|
381
|
+
function createDatabaseClassExport(args: { databaseName: string }) {
|
|
382
|
+
const { databaseName } = args;
|
|
386
383
|
return ts.factory.createVariableStatement(
|
|
387
384
|
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
388
385
|
ts.factory.createVariableDeclarationList(
|
|
@@ -405,7 +402,7 @@ function exportDatabaseActions(databaseName: string) {
|
|
|
405
402
|
],
|
|
406
403
|
[
|
|
407
404
|
ts.factory.createIdentifier("databaseId"),
|
|
408
|
-
ts.factory.createIdentifier("
|
|
405
|
+
ts.factory.createIdentifier("columnNameToColumnProperties"),
|
|
409
406
|
]
|
|
410
407
|
)
|
|
411
408
|
),
|
package/src/cli.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import fs from "fs";
|
|
4
|
-
import { createDatabaseTypes } from "./
|
|
4
|
+
import { createDatabaseTypes } from "./index";
|
|
5
5
|
import path from "path";
|
|
6
|
-
require("dotenv").config();
|
|
7
6
|
|
|
8
7
|
async function main() {
|
|
9
8
|
const args = process.argv.slice(2);
|
|
@@ -20,8 +19,6 @@ async function main() {
|
|
|
20
19
|
|
|
21
20
|
console.log(path.join(projDir, "notion.config"));
|
|
22
21
|
if (notionConfigDirJS || notionConfigDirTS) {
|
|
23
|
-
// this is a relative import, so we can escape out
|
|
24
|
-
|
|
25
22
|
const config = require(path.join(projDir, "notion.config"));
|
|
26
23
|
|
|
27
24
|
const { databaseNames } = await createDatabaseTypes(config);
|