@haustle/notion-orm 0.0.3 → 0.0.4
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/build/{NotionActions → src}/BuildCall.d.ts +0 -0
- package/build/src/BuildCall.d.ts.map +1 -0
- package/build/{NotionActions → src}/BuildCall.js +0 -0
- package/build/src/BuildCall.js.map +1 -0
- package/build/{NotionActions/NotionCollection.d.ts → src/DatabaseActions.d.ts} +4 -4
- package/build/src/DatabaseActions.d.ts.map +1 -0
- package/build/{NotionActions/NotionCollection.js → src/DatabaseActions.js} +11 -6
- package/build/src/DatabaseActions.js.map +1 -0
- package/build/{NotionActions → src}/GenerateTypes.d.ts +0 -0
- package/build/src/GenerateTypes.d.ts.map +1 -0
- package/build/{NotionActions → src}/GenerateTypes.js +52 -59
- package/build/src/GenerateTypes.js.map +1 -0
- package/build/src/NotionConfig.d.ts +9 -0
- package/build/src/NotionConfig.d.ts.map +1 -0
- package/build/{NotionActions → src}/NotionConfig.js +36 -28
- package/build/src/NotionConfig.js.map +1 -0
- package/build/src/cli.d.ts +3 -0
- package/build/src/cli.d.ts.map +1 -0
- package/build/{index.js → src/cli.js} +2 -3
- package/build/src/cli.js.map +1 -0
- package/build/{NotionActions → src}/queryTypes.d.ts +18 -1
- package/build/src/queryTypes.d.ts.map +1 -0
- package/build/{NotionActions → src}/queryTypes.js +0 -0
- package/build/src/queryTypes.js.map +1 -0
- package/package.json +6 -8
- package/build/NotionActions/BuildCall.d.ts.map +0 -1
- package/build/NotionActions/BuildCall.js.map +0 -1
- package/build/NotionActions/GenerateTypes.d.ts.map +0 -1
- package/build/NotionActions/GenerateTypes.js.map +0 -1
- package/build/NotionActions/NotionCollection.d.ts.map +0 -1
- package/build/NotionActions/NotionCollection.js.map +0 -1
- package/build/NotionActions/NotionConfig.d.ts +0 -8
- package/build/NotionActions/NotionConfig.d.ts.map +0 -1
- package/build/NotionActions/NotionConfig.js.map +0 -1
- package/build/NotionActions/queryTypes.d.ts.map +0 -1
- package/build/NotionActions/queryTypes.js.map +0 -1
- package/build/index.d.ts +0 -3
- package/build/index.d.ts.map +0 -1
- package/build/index.js.map +0 -1
- package/src/NotionActions/BuildCall.ts +0 -85
- package/src/NotionActions/GenerateTypes.ts +0 -430
- package/src/NotionActions/NotionCollection.ts +0 -126
- package/src/NotionActions/NotionConfig.ts +0 -115
- package/src/NotionActions/queryTypes.ts +0 -141
- package/src/index.ts +0 -43
- package/tsconfig.json +0 -25
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NotionConfig.d.ts","sourceRoot":"","sources":["../../src/NotionActions/NotionConfig.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAOF,eAAO,MAAM,mBAAmB,eAAsB,gBAAgB;;EA0DrE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NotionConfig.js","sourceRoot":"","sources":["../../src/NotionActions/NotionConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA0C;AAE1C,mDAAkE;AAClE,+CAAiC;AACjC,4CAAoB;AACpB,gDAAwB;AAExB,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC;AAYpB,MAAM,mBAAmB,GAAG,CAAO,UAA4B,EAAE,EAAE;IACzE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,UAAU,CAAC;IAEzC,kDAAkD;IAClD,IAAI,CAAC,IAAI,EAAE;QACV,OAAO,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAChB;IACD,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;QAC3B,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,CA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AC,CAAC;CAC1B,CAAC;AAEF,KAAK,WAAW,GAAG;IAClB,EAAE,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;CACzB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queryTypes.js","sourceRoot":"","sources":["../../src/NotionActions/queryTypes.ts"],"names":[],"mappings":";AAAA;;GAEG;AACH,gCAAgC;;AAsEhC;;GAEG;AAEH,MAAM,CAAC,GAAG;IACT,SAAS,EAAE,cAAc;CACzB,CAAC"}
|
package/build/index.d.ts
DELETED
package/build/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/build/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,4CAAoB;AACpB,+DAAmE;AACnE,gDAAwB;AACxB,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC;AAE3B,SAAe,IAAI;;QAClB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAEnC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE;YAChD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;YAE9B,MAAM,iBAAiB,GAAG,YAAE,CAAC,UAAU,CACtC,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,kBAAkB,CAAC,CACtC,CAAC;YACF,MAAM,iBAAiB,GAAG,YAAE,CAAC,UAAU,CACtC,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,kBAAkB,CAAC,CACtC,CAAC;YAEF,OAAO,CAAC,GAAG,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;YACjD,IAAI,iBAAiB,IAAI,iBAAiB,EAAE;gBAC3C,kDAAkD;gBAElD,MAAM,MAAM,GAAG,OAAO,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;gBAE5D,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,IAAA,kCAAmB,EAAC,MAAM,CAAC,CAAC;gBAC5D,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;oBAC7B,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;iBAClC;qBAAM;oBACN,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;oBAC9D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;wBAC9C,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;qBACzC;iBACD;aACD;iBAAM;gBACN,OAAO,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC;gBAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aAChB;SACD;IACF,CAAC;CAAA;AAED,IAAI,EAAE,CAAC"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { PropertyType } from "./GenerateTypes";
|
|
2
|
-
|
|
3
|
-
export function getCall(args: {
|
|
4
|
-
type: PropertyType;
|
|
5
|
-
value: string | number | boolean;
|
|
6
|
-
}) {
|
|
7
|
-
const { type, value } = args;
|
|
8
|
-
console.log(type, value, typeof value);
|
|
9
|
-
if (type === "select" && typeof value === "string") {
|
|
10
|
-
return selectCall({ value });
|
|
11
|
-
} else if (type === "multi_select" && Array.isArray(value)) {
|
|
12
|
-
return multiSelectCall({ value });
|
|
13
|
-
} else if (type === "number" && typeof value === "number") {
|
|
14
|
-
return numberCall({ value });
|
|
15
|
-
} else if (type === "url" && typeof value === "string") {
|
|
16
|
-
return urlCall({ url: value });
|
|
17
|
-
} else if (type === "checkbox" && typeof value === "boolean") {
|
|
18
|
-
return checkboxCall({ checked: value });
|
|
19
|
-
} else if (type === "title" && typeof value === "string") {
|
|
20
|
-
return titleCall({ title: value });
|
|
21
|
-
} else if (type === "text" && typeof value === "string") {
|
|
22
|
-
return textCall({ text: value });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/*
|
|
27
|
-
======================================================
|
|
28
|
-
GENERATE OBJECT BASED ON TYPE
|
|
29
|
-
======================================================
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
const selectCall = (args: { value: string }) => {
|
|
33
|
-
const { value } = args;
|
|
34
|
-
const select = {
|
|
35
|
-
name: value,
|
|
36
|
-
};
|
|
37
|
-
return { select };
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const multiSelectCall = (args: { value: Array<string> }) => {
|
|
41
|
-
const { value } = args;
|
|
42
|
-
const multi_select = value.map((option) => ({ name: option }));
|
|
43
|
-
return { multi_select };
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const textCall = (args: { text: string }) => {
|
|
47
|
-
const { text } = args;
|
|
48
|
-
const rich_text = [
|
|
49
|
-
{
|
|
50
|
-
text: {
|
|
51
|
-
content: text,
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
return { rich_text };
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const titleCall = (args: { title: string }) => {
|
|
60
|
-
const { title } = args;
|
|
61
|
-
const titleObject = [
|
|
62
|
-
{
|
|
63
|
-
text: {
|
|
64
|
-
content: title,
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
];
|
|
68
|
-
|
|
69
|
-
return { title: titleObject };
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const numberCall = (args: { value: number }) => {
|
|
73
|
-
const { value: number } = args;
|
|
74
|
-
return { number };
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const urlCall = (args: { url: string }) => {
|
|
78
|
-
const { url } = args;
|
|
79
|
-
return { url };
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const checkboxCall = (args: { checked: boolean }) => {
|
|
83
|
-
const { checked: checkbox } = args;
|
|
84
|
-
return { checkbox };
|
|
85
|
-
};
|
|
@@ -1,430 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DatabaseObjectResponse,
|
|
3
|
-
GetDatabaseResponse,
|
|
4
|
-
} from "@notionhq/client/build/src/api-endpoints";
|
|
5
|
-
import * as ts from "typescript";
|
|
6
|
-
import fs from "fs";
|
|
7
|
-
import path from "path";
|
|
8
|
-
|
|
9
|
-
// This can be grabbed from // api-endpoints.d.ts with some work
|
|
10
|
-
const propertyArr = [
|
|
11
|
-
"text",
|
|
12
|
-
"select",
|
|
13
|
-
"title",
|
|
14
|
-
"number",
|
|
15
|
-
"multi_select",
|
|
16
|
-
"checkbox",
|
|
17
|
-
"url",
|
|
18
|
-
];
|
|
19
|
-
export type PropertyType = typeof propertyArr[number];
|
|
20
|
-
|
|
21
|
-
type propNameToColumnNameType = Record<
|
|
22
|
-
string,
|
|
23
|
-
{ columnName: string; type: PropertyType }
|
|
24
|
-
>;
|
|
25
|
-
|
|
26
|
-
/*
|
|
27
|
-
Responsible for generating `.ts` files
|
|
28
|
-
*/
|
|
29
|
-
export async function createTypescriptFileForDatabase(
|
|
30
|
-
dbResponse: GetDatabaseResponse
|
|
31
|
-
) {
|
|
32
|
-
const {
|
|
33
|
-
id: databaseId,
|
|
34
|
-
properties,
|
|
35
|
-
title,
|
|
36
|
-
} = dbResponse as DatabaseObjectResponse;
|
|
37
|
-
const propNameToColumnName: propNameToColumnNameType = {};
|
|
38
|
-
const databaseName = title[0].plain_text;
|
|
39
|
-
const databaseClassName = camelize(databaseName).replace(/[^a-zA-Z0-9]/g, "");
|
|
40
|
-
|
|
41
|
-
const databaseColumnTypeProps: ts.TypeElement[] = [];
|
|
42
|
-
|
|
43
|
-
// Looping through each column of database
|
|
44
|
-
Object.values(properties).forEach((value) => {
|
|
45
|
-
const { type: columnType, name: columnName } = value;
|
|
46
|
-
|
|
47
|
-
// Taking the column name and camelizing it for typescript use
|
|
48
|
-
const camelizedColumnName = camelize(columnName);
|
|
49
|
-
|
|
50
|
-
// Creating map of column name to the column's name in the database's typescript type
|
|
51
|
-
propNameToColumnName[camelizedColumnName] = {
|
|
52
|
-
columnName,
|
|
53
|
-
type: columnType,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
if (columnType === "title" || columnType === "rich_text") {
|
|
57
|
-
// add text column to collection type
|
|
58
|
-
databaseColumnTypeProps.push(
|
|
59
|
-
createTextProperty(camelizedColumnName, columnType === "title")
|
|
60
|
-
);
|
|
61
|
-
} else if (columnType === "number") {
|
|
62
|
-
// add number column to collection type
|
|
63
|
-
databaseColumnTypeProps.push(createNumberProperty(camelizedColumnName));
|
|
64
|
-
} else if (columnType === "url") {
|
|
65
|
-
// add url column to collection type
|
|
66
|
-
databaseColumnTypeProps.push(
|
|
67
|
-
createTextProperty(camelizedColumnName, false)
|
|
68
|
-
);
|
|
69
|
-
} else if (columnType === "date") {
|
|
70
|
-
// add Date column to collection type
|
|
71
|
-
databaseColumnTypeProps.push(createDateProperty(camelizedColumnName));
|
|
72
|
-
} else if (columnType == "select" || columnType == "multi_select") {
|
|
73
|
-
// @ts-ignore
|
|
74
|
-
const options = value[columnType].options.map((x) => x.name);
|
|
75
|
-
databaseColumnTypeProps.push(
|
|
76
|
-
createMultiOptionProp(
|
|
77
|
-
camelizedColumnName,
|
|
78
|
-
options,
|
|
79
|
-
// This determines whether the property needs to be a union or a union array
|
|
80
|
-
columnType === "multi_select"
|
|
81
|
-
)
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// Object type that represents the database schema
|
|
87
|
-
const CollectionType = ts.factory.createTypeAliasDeclaration(
|
|
88
|
-
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
89
|
-
ts.factory.createIdentifier("CollectionType"),
|
|
90
|
-
undefined,
|
|
91
|
-
ts.factory.createTypeLiteralNode(databaseColumnTypeProps)
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
// Top level non-nested variable, functions, types
|
|
95
|
-
const nodeArr = [
|
|
96
|
-
importCollectionClass(),
|
|
97
|
-
createDatabaseIdVariable(databaseId),
|
|
98
|
-
CollectionType,
|
|
99
|
-
mapPropNameToColumnDetails(propNameToColumnName),
|
|
100
|
-
ColNameToType(),
|
|
101
|
-
exportCollectionActions(databaseClassName),
|
|
102
|
-
];
|
|
103
|
-
|
|
104
|
-
const nodes = ts.factory.createNodeArray(nodeArr);
|
|
105
|
-
|
|
106
|
-
const sourceFile = ts.createSourceFile(
|
|
107
|
-
"placeholder.ts",
|
|
108
|
-
"",
|
|
109
|
-
ts.ScriptTarget.ESNext,
|
|
110
|
-
true,
|
|
111
|
-
ts.ScriptKind.TS
|
|
112
|
-
);
|
|
113
|
-
const printer = ts.createPrinter();
|
|
114
|
-
|
|
115
|
-
const typescriptCodeToString = printer.printList(
|
|
116
|
-
ts.ListFormat.MultiLine,
|
|
117
|
-
nodes,
|
|
118
|
-
sourceFile
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const transpileToJavaScript = ts.transpile(typescriptCodeToString, {
|
|
122
|
-
module: ts.ModuleKind.None,
|
|
123
|
-
target: ts.ScriptTarget.ES2015,
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// Create our output folder
|
|
127
|
-
const outputDir = path.join(
|
|
128
|
-
__dirname,
|
|
129
|
-
"../../build",
|
|
130
|
-
"NotionActions",
|
|
131
|
-
"DatabaseTypes"
|
|
132
|
-
);
|
|
133
|
-
if (!fs.existsSync(outputDir)) {
|
|
134
|
-
fs.mkdirSync(outputDir);
|
|
135
|
-
}
|
|
136
|
-
fs.writeFileSync(
|
|
137
|
-
path.resolve(outputDir, `${databaseId}.ts`),
|
|
138
|
-
typescriptCodeToString
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
fs.writeFileSync(
|
|
142
|
-
path.resolve(outputDir, `${databaseId}.js`),
|
|
143
|
-
transpileToJavaScript
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
return { databaseName, databaseClassName, databaseId };
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// generate text property
|
|
150
|
-
function createTextProperty(name: string, isTitle: boolean) {
|
|
151
|
-
const text = ts.factory.createPropertySignature(
|
|
152
|
-
undefined,
|
|
153
|
-
ts.factory.createIdentifier(name),
|
|
154
|
-
!isTitle ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) : undefined,
|
|
155
|
-
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
|
|
156
|
-
);
|
|
157
|
-
return text;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Generate number property to go inside a type
|
|
162
|
-
* name: number
|
|
163
|
-
*/
|
|
164
|
-
function createNumberProperty(name: string) {
|
|
165
|
-
const number = ts.factory.createPropertySignature(
|
|
166
|
-
undefined,
|
|
167
|
-
ts.factory.createIdentifier(name),
|
|
168
|
-
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
169
|
-
ts.factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword)
|
|
170
|
-
);
|
|
171
|
-
return number;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
*
|
|
176
|
-
* @param name name of property
|
|
177
|
-
* @param options
|
|
178
|
-
* @param array
|
|
179
|
-
* @returns
|
|
180
|
-
*
|
|
181
|
-
* For selects and multi-select collection properties
|
|
182
|
-
*
|
|
183
|
-
* array = true for multi-select
|
|
184
|
-
*
|
|
185
|
-
* name = ("x" | "y" | "z")[]
|
|
186
|
-
*/
|
|
187
|
-
function createMultiOptionProp(
|
|
188
|
-
name: string,
|
|
189
|
-
options: string[],
|
|
190
|
-
array: boolean
|
|
191
|
-
) {
|
|
192
|
-
return ts.factory.createPropertySignature(
|
|
193
|
-
undefined,
|
|
194
|
-
ts.factory.createIdentifier(name),
|
|
195
|
-
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
196
|
-
array
|
|
197
|
-
? ts.factory.createArrayTypeNode(
|
|
198
|
-
ts.factory.createParenthesizedType(
|
|
199
|
-
ts.factory.createUnionTypeNode([
|
|
200
|
-
...options.map((option) =>
|
|
201
|
-
ts.factory.createLiteralTypeNode(
|
|
202
|
-
ts.factory.createStringLiteral(option)
|
|
203
|
-
)
|
|
204
|
-
),
|
|
205
|
-
createOtherStringProp(),
|
|
206
|
-
])
|
|
207
|
-
)
|
|
208
|
-
)
|
|
209
|
-
: ts.factory.createUnionTypeNode([
|
|
210
|
-
...options.map((option) =>
|
|
211
|
-
ts.factory.createLiteralTypeNode(
|
|
212
|
-
ts.factory.createStringLiteral(option)
|
|
213
|
-
)
|
|
214
|
-
),
|
|
215
|
-
createOtherStringProp(),
|
|
216
|
-
])
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// string & {}. Allows users to pass in values
|
|
221
|
-
function createOtherStringProp() {
|
|
222
|
-
return ts.factory.createIntersectionTypeNode([
|
|
223
|
-
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
|
|
224
|
-
ts.factory.createTypeLiteralNode([]),
|
|
225
|
-
]);
|
|
226
|
-
}
|
|
227
|
-
function createDateProperty(name: string) {
|
|
228
|
-
return ts.factory.createPropertySignature(
|
|
229
|
-
undefined,
|
|
230
|
-
ts.factory.createIdentifier("s"),
|
|
231
|
-
undefined,
|
|
232
|
-
ts.factory.createTypeReferenceNode(
|
|
233
|
-
ts.factory.createIdentifier("Date"),
|
|
234
|
-
undefined
|
|
235
|
-
)
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// Generate database Id variable
|
|
240
|
-
// const databaseId = <database-id>
|
|
241
|
-
function createDatabaseIdVariable(databaseId: string) {
|
|
242
|
-
return ts.factory.createVariableStatement(
|
|
243
|
-
undefined,
|
|
244
|
-
ts.factory.createVariableDeclarationList(
|
|
245
|
-
[
|
|
246
|
-
ts.factory.createVariableDeclaration(
|
|
247
|
-
ts.factory.createIdentifier("databaseId"),
|
|
248
|
-
undefined,
|
|
249
|
-
undefined,
|
|
250
|
-
ts.factory.createStringLiteral(databaseId)
|
|
251
|
-
),
|
|
252
|
-
],
|
|
253
|
-
ts.NodeFlags.Const
|
|
254
|
-
)
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Instead of refering to the column names 1:1 such as "Book Rating", we transform them to
|
|
260
|
-
* camelcase (eg. bookRating). So we need to keep track of the original name and the type
|
|
261
|
-
* for when we construct request for API
|
|
262
|
-
*
|
|
263
|
-
* Example
|
|
264
|
-
*
|
|
265
|
-
* const propMap = {
|
|
266
|
-
*
|
|
267
|
-
* "bookRating": {
|
|
268
|
-
* columnName: "Book Rating",
|
|
269
|
-
* type: "select"
|
|
270
|
-
* },
|
|
271
|
-
* "genre": {
|
|
272
|
-
* columnName: "Genre",
|
|
273
|
-
* type: "multi_select"
|
|
274
|
-
* }
|
|
275
|
-
*
|
|
276
|
-
* }
|
|
277
|
-
* @param colMap
|
|
278
|
-
* @returns
|
|
279
|
-
*/
|
|
280
|
-
function mapPropNameToColumnDetails(colMap: propNameToColumnNameType) {
|
|
281
|
-
return ts.factory.createVariableDeclarationList(
|
|
282
|
-
[
|
|
283
|
-
ts.factory.createVariableDeclaration(
|
|
284
|
-
ts.factory.createIdentifier("propMap"),
|
|
285
|
-
undefined,
|
|
286
|
-
undefined,
|
|
287
|
-
ts.factory.createAsExpression(
|
|
288
|
-
ts.factory.createObjectLiteralExpression(
|
|
289
|
-
[
|
|
290
|
-
...Object.entries(colMap).map(([propName, value]) =>
|
|
291
|
-
ts.factory.createPropertyAssignment(
|
|
292
|
-
ts.factory.createStringLiteral(propName),
|
|
293
|
-
ts.factory.createObjectLiteralExpression(
|
|
294
|
-
[
|
|
295
|
-
ts.factory.createPropertyAssignment(
|
|
296
|
-
ts.factory.createIdentifier("columnName"),
|
|
297
|
-
ts.factory.createStringLiteral(value.columnName)
|
|
298
|
-
),
|
|
299
|
-
ts.factory.createPropertyAssignment(
|
|
300
|
-
ts.factory.createIdentifier("type"),
|
|
301
|
-
ts.factory.createStringLiteral(value.type)
|
|
302
|
-
),
|
|
303
|
-
],
|
|
304
|
-
true
|
|
305
|
-
)
|
|
306
|
-
)
|
|
307
|
-
),
|
|
308
|
-
],
|
|
309
|
-
true
|
|
310
|
-
),
|
|
311
|
-
ts.factory.createTypeReferenceNode(
|
|
312
|
-
ts.factory.createIdentifier("const"),
|
|
313
|
-
undefined
|
|
314
|
-
)
|
|
315
|
-
)
|
|
316
|
-
),
|
|
317
|
-
],
|
|
318
|
-
ts.NodeFlags.Const
|
|
319
|
-
);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
function ColNameToType() {
|
|
323
|
-
return ts.factory.createTypeAliasDeclaration(
|
|
324
|
-
undefined,
|
|
325
|
-
ts.factory.createIdentifier("ColNameToType"),
|
|
326
|
-
undefined,
|
|
327
|
-
ts.factory.createMappedTypeNode(
|
|
328
|
-
undefined,
|
|
329
|
-
ts.factory.createTypeParameterDeclaration(
|
|
330
|
-
undefined,
|
|
331
|
-
ts.factory.createIdentifier("Property"),
|
|
332
|
-
ts.factory.createTypeOperatorNode(
|
|
333
|
-
ts.SyntaxKind.KeyOfKeyword,
|
|
334
|
-
ts.factory.createTypeQueryNode(
|
|
335
|
-
ts.factory.createIdentifier("propMap"),
|
|
336
|
-
undefined
|
|
337
|
-
)
|
|
338
|
-
),
|
|
339
|
-
undefined
|
|
340
|
-
),
|
|
341
|
-
undefined,
|
|
342
|
-
undefined,
|
|
343
|
-
ts.factory.createIndexedAccessTypeNode(
|
|
344
|
-
ts.factory.createIndexedAccessTypeNode(
|
|
345
|
-
ts.factory.createTypeQueryNode(
|
|
346
|
-
ts.factory.createIdentifier("propMap"),
|
|
347
|
-
undefined
|
|
348
|
-
),
|
|
349
|
-
ts.factory.createTypeReferenceNode(
|
|
350
|
-
ts.factory.createIdentifier("Property"),
|
|
351
|
-
undefined
|
|
352
|
-
)
|
|
353
|
-
),
|
|
354
|
-
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral("type"))
|
|
355
|
-
),
|
|
356
|
-
undefined
|
|
357
|
-
/* unknown */
|
|
358
|
-
)
|
|
359
|
-
);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// Need to import the class responsible for adding and querying the database
|
|
363
|
-
function importCollectionClass() {
|
|
364
|
-
return ts.factory.createImportDeclaration(
|
|
365
|
-
undefined,
|
|
366
|
-
ts.factory.createImportClause(
|
|
367
|
-
false,
|
|
368
|
-
undefined,
|
|
369
|
-
ts.factory.createNamedImports([
|
|
370
|
-
ts.factory.createImportSpecifier(
|
|
371
|
-
false,
|
|
372
|
-
undefined,
|
|
373
|
-
ts.factory.createIdentifier("CollectionActions")
|
|
374
|
-
),
|
|
375
|
-
])
|
|
376
|
-
),
|
|
377
|
-
ts.factory.createStringLiteral("../NotionCollection"),
|
|
378
|
-
undefined
|
|
379
|
-
);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
// We export the database with the class above.
|
|
383
|
-
// export
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* We export the database with
|
|
387
|
-
* @param databaseName
|
|
388
|
-
*
|
|
389
|
-
* const <datbase-name> = new CollectionActions<CollectionType>(datbaseId, propMap)
|
|
390
|
-
*/
|
|
391
|
-
function exportCollectionActions(databaseName: string) {
|
|
392
|
-
return ts.factory.createVariableStatement(
|
|
393
|
-
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
394
|
-
ts.factory.createVariableDeclarationList(
|
|
395
|
-
[
|
|
396
|
-
ts.factory.createVariableDeclaration(
|
|
397
|
-
ts.factory.createIdentifier(databaseName),
|
|
398
|
-
undefined,
|
|
399
|
-
undefined,
|
|
400
|
-
ts.factory.createNewExpression(
|
|
401
|
-
ts.factory.createIdentifier("CollectionActions"),
|
|
402
|
-
[
|
|
403
|
-
ts.factory.createTypeReferenceNode(
|
|
404
|
-
ts.factory.createIdentifier("CollectionType"),
|
|
405
|
-
undefined
|
|
406
|
-
),
|
|
407
|
-
ts.factory.createTypeReferenceNode(
|
|
408
|
-
ts.factory.createIdentifier("ColNameToType"),
|
|
409
|
-
undefined
|
|
410
|
-
),
|
|
411
|
-
],
|
|
412
|
-
[
|
|
413
|
-
ts.factory.createIdentifier("databaseId"),
|
|
414
|
-
ts.factory.createIdentifier("propMap"),
|
|
415
|
-
]
|
|
416
|
-
)
|
|
417
|
-
),
|
|
418
|
-
],
|
|
419
|
-
ts.NodeFlags.Const
|
|
420
|
-
)
|
|
421
|
-
);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
// for a type's property name
|
|
425
|
-
function camelize(str: string) {
|
|
426
|
-
return str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function (match, index) {
|
|
427
|
-
if (+match === 0) return ""; // or if (/\s+/.test(match)) for white spaces
|
|
428
|
-
return index === 0 ? match.toLowerCase() : match.toUpperCase();
|
|
429
|
-
});
|
|
430
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CreatePageParameters,
|
|
3
|
-
QueryDatabaseParameters,
|
|
4
|
-
} from "@notionhq/client/build/src/api-endpoints";
|
|
5
|
-
import { Client } from "@notionhq/client";
|
|
6
|
-
import { getCall } from "./BuildCall";
|
|
7
|
-
import { PropertyType } from "./GenerateTypes";
|
|
8
|
-
import {
|
|
9
|
-
apiFilterType,
|
|
10
|
-
apiSingleFilter,
|
|
11
|
-
CompoundFilters,
|
|
12
|
-
FilterOptionNames,
|
|
13
|
-
Query,
|
|
14
|
-
QueryFilter,
|
|
15
|
-
SingleFilter,
|
|
16
|
-
} from "./queryTypes";
|
|
17
|
-
require("dotenv").config();
|
|
18
|
-
|
|
19
|
-
export type propNameToColumnNameType = Record<
|
|
20
|
-
string,
|
|
21
|
-
{ columnName: string; type: PropertyType }
|
|
22
|
-
>;
|
|
23
|
-
|
|
24
|
-
export class CollectionActions<
|
|
25
|
-
CollectionType extends Record<string, any>,
|
|
26
|
-
ColNameToType extends Record<keyof CollectionType, FilterOptionNames>
|
|
27
|
-
> {
|
|
28
|
-
private NotionClient: Client = new Client({
|
|
29
|
-
auth: process.env.NOTION_KEY,
|
|
30
|
-
});
|
|
31
|
-
private databaseId: string;
|
|
32
|
-
private propNameToColumnName: propNameToColumnNameType;
|
|
33
|
-
private columnNames: string[];
|
|
34
|
-
|
|
35
|
-
constructor(
|
|
36
|
-
datbaseId: string,
|
|
37
|
-
propNameToColumnName: propNameToColumnNameType
|
|
38
|
-
) {
|
|
39
|
-
this.databaseId = datbaseId;
|
|
40
|
-
this.propNameToColumnName = propNameToColumnName;
|
|
41
|
-
this.columnNames = Object.keys(propNameToColumnName);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Add page to a database
|
|
45
|
-
async add(pageObject: CollectionType) {
|
|
46
|
-
const callBody: CreatePageParameters = {
|
|
47
|
-
parent: {
|
|
48
|
-
database_id: this.databaseId,
|
|
49
|
-
},
|
|
50
|
-
properties: {},
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const columnTypePropNames = Object.keys(pageObject);
|
|
54
|
-
columnTypePropNames.forEach((propName) => {
|
|
55
|
-
const { type, columnName } = this.propNameToColumnName[propName];
|
|
56
|
-
const columnObject = getCall({
|
|
57
|
-
type,
|
|
58
|
-
value: pageObject[propName],
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
callBody.properties[columnName] = columnObject!;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// console.log(JSON.stringify(callBody, null, 4));
|
|
65
|
-
await this.NotionClient.pages.create(callBody);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Look for page inside the database
|
|
69
|
-
async query(query: Query<CollectionType, ColNameToType>) {
|
|
70
|
-
const queryCall: QueryDatabaseParameters = {
|
|
71
|
-
database_id: this.databaseId,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const filters = query.filter
|
|
75
|
-
? this.recursivelyBuildFilter(query.filter)
|
|
76
|
-
: undefined;
|
|
77
|
-
if (filters) {
|
|
78
|
-
// @ts-ignore errors vs notion api types
|
|
79
|
-
queryCall["filter"] = filters;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
console.log(JSON.stringify(queryCall, null, 4));
|
|
83
|
-
|
|
84
|
-
const sort = query.sort;
|
|
85
|
-
|
|
86
|
-
const apiQuery = await this.NotionClient.databases.query(queryCall);
|
|
87
|
-
console.log(apiQuery);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
private recursivelyBuildFilter(
|
|
91
|
-
queryFilter: QueryFilter<CollectionType, ColNameToType>
|
|
92
|
-
): apiFilterType {
|
|
93
|
-
// Need to loop because we don't kno
|
|
94
|
-
for (const prop in queryFilter) {
|
|
95
|
-
// if the filter is "and" || "or" we need to recursively
|
|
96
|
-
if (prop === "and" || prop === "or") {
|
|
97
|
-
const compoundFilters: QueryFilter<CollectionType, ColNameToType>[] =
|
|
98
|
-
// @ts-ignore
|
|
99
|
-
queryFilter[prop];
|
|
100
|
-
|
|
101
|
-
const compoundApiFilters = compoundFilters.map(
|
|
102
|
-
(i: QueryFilter<CollectionType, ColNameToType>) => {
|
|
103
|
-
return this.recursivelyBuildFilter(i);
|
|
104
|
-
}
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
// Either have an `and` or an `or` compound filter
|
|
108
|
-
let temp: apiFilterType = {
|
|
109
|
-
...(prop === "and"
|
|
110
|
-
? { and: compoundApiFilters }
|
|
111
|
-
: { or: compoundApiFilters }),
|
|
112
|
-
};
|
|
113
|
-
return temp;
|
|
114
|
-
} else {
|
|
115
|
-
const propType = this.propNameToColumnName[prop].type;
|
|
116
|
-
const temp: apiSingleFilter = {
|
|
117
|
-
property: this.propNameToColumnName[prop].columnName,
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
//@ts-ignore
|
|
121
|
-
temp[propType] = (queryFilter as SingleFilter<ColNameToType>)[prop];
|
|
122
|
-
return temp;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|