@haustle/notion-orm 0.0.2 → 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/src/BuildCall.d.ts +32 -0
- package/build/src/BuildCall.d.ts.map +1 -0
- package/build/{NotionActions → src}/BuildCall.js +1 -0
- package/build/src/BuildCall.js.map +1 -0
- package/build/src/DatabaseActions.d.ts +17 -0
- package/build/src/DatabaseActions.d.ts.map +1 -0
- package/build/{NotionActions/NotionCollection.js → src/DatabaseActions.js} +11 -5
- package/build/src/DatabaseActions.js.map +1 -0
- package/build/src/GenerateTypes.d.ts +10 -0
- package/build/src/GenerateTypes.d.ts.map +1 -0
- package/build/{NotionActions → src}/GenerateTypes.js +56 -57
- 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 +37 -40
- 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 -2
- package/build/src/cli.js.map +1 -0
- package/build/src/queryTypes.d.ts +102 -0
- package/build/src/queryTypes.d.ts.map +1 -0
- package/build/{NotionActions → src}/queryTypes.js +1 -0
- package/build/src/queryTypes.js.map +1 -0
- package/package.json +7 -13
- package/src/NotionActions/BuildCall.ts +0 -85
- package/src/NotionActions/GenerateTypes.ts +0 -417
- package/src/NotionActions/NotionCollection.ts +0 -126
- package/src/NotionActions/NotionConfig.ts +0 -150
- package/src/NotionActions/queryTypes.ts +0 -141
- package/src/index.ts +0 -43
- package/tsconfig.json +0 -22
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { Client } from "@notionhq/client";
|
|
2
|
-
import { GetDatabaseResponse } from "@notionhq/client/build/src/api-endpoints";
|
|
3
|
-
import { createTypescriptFileForDatabase } from "./GenerateTypes";
|
|
4
|
-
import * as ts from "typescript";
|
|
5
|
-
import fs from "fs";
|
|
6
|
-
import path from "path";
|
|
7
|
-
|
|
8
|
-
require("dotenv").config();
|
|
9
|
-
|
|
10
|
-
export type NotionConfigType = {
|
|
11
|
-
auth: string;
|
|
12
|
-
databaseIds: string[];
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
type importClassType = {
|
|
16
|
-
databaseId: string;
|
|
17
|
-
databaseClassName: string;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const createDatabaseTypes = async (notionInfo: NotionConfigType) => {
|
|
21
|
-
const { auth, databaseIds } = notionInfo;
|
|
22
|
-
|
|
23
|
-
// Making sure the user is passing valid arguments
|
|
24
|
-
if (!auth) {
|
|
25
|
-
console.error("Please pass a valid Notion Integration Key");
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
28
|
-
if (databaseIds.length < 0) {
|
|
29
|
-
console.error("Please pass some database Ids");
|
|
30
|
-
process.exit(1);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Initialize client
|
|
34
|
-
const NotionClient = new Client({
|
|
35
|
-
auth: auth,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const databaseNames: string[] = [];
|
|
39
|
-
|
|
40
|
-
// retrieve the database object
|
|
41
|
-
const databaseClassImports: ts.ImportDeclaration[] = [];
|
|
42
|
-
const databaseCamelizedNames: string[] = [];
|
|
43
|
-
|
|
44
|
-
for (const database_id of databaseIds) {
|
|
45
|
-
let dbOjbect: GetDatabaseResponse;
|
|
46
|
-
|
|
47
|
-
// Try to get the database schema
|
|
48
|
-
try {
|
|
49
|
-
dbOjbect = await NotionClient.databases.retrieve({
|
|
50
|
-
database_id,
|
|
51
|
-
});
|
|
52
|
-
} catch (e) {
|
|
53
|
-
console.error(e);
|
|
54
|
-
return { databaseNames: [] };
|
|
55
|
-
}
|
|
56
|
-
const { databaseClassName, databaseId, databaseName } =
|
|
57
|
-
await createTypescriptFileForDatabase(dbOjbect);
|
|
58
|
-
databaseNames.push(databaseName);
|
|
59
|
-
databaseCamelizedNames.push(databaseClassName);
|
|
60
|
-
|
|
61
|
-
databaseClassImports.push(
|
|
62
|
-
databaseImportStatement({
|
|
63
|
-
databaseClassName,
|
|
64
|
-
databaseId,
|
|
65
|
-
})
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const nodeArr = [
|
|
70
|
-
...databaseClassImports,
|
|
71
|
-
mainNotionVariable(databaseCamelizedNames),
|
|
72
|
-
];
|
|
73
|
-
createNotionFile(nodeArr);
|
|
74
|
-
return { databaseNames };
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// Create the import statement for notion.ts file
|
|
78
|
-
function databaseImportStatement(dbClass: importClassType) {
|
|
79
|
-
return ts.factory.createImportDeclaration(
|
|
80
|
-
undefined,
|
|
81
|
-
ts.factory.createImportClause(
|
|
82
|
-
false,
|
|
83
|
-
undefined,
|
|
84
|
-
ts.factory.createNamedImports([
|
|
85
|
-
ts.factory.createImportSpecifier(
|
|
86
|
-
false,
|
|
87
|
-
undefined,
|
|
88
|
-
ts.factory.createIdentifier(dbClass.databaseClassName)
|
|
89
|
-
),
|
|
90
|
-
])
|
|
91
|
-
),
|
|
92
|
-
|
|
93
|
-
// We've setup paths to allow @notion-database access
|
|
94
|
-
ts.factory.createStringLiteral(`@notion-database/${dbClass.databaseId}`),
|
|
95
|
-
undefined
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function mainNotionVariable(databaseNames: string[]) {
|
|
100
|
-
return ts.factory.createVariableStatement(
|
|
101
|
-
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
102
|
-
ts.factory.createVariableDeclarationList(
|
|
103
|
-
[
|
|
104
|
-
ts.factory.createVariableDeclaration(
|
|
105
|
-
ts.factory.createIdentifier("notion"),
|
|
106
|
-
undefined,
|
|
107
|
-
undefined,
|
|
108
|
-
ts.factory.createObjectLiteralExpression(
|
|
109
|
-
[
|
|
110
|
-
...databaseNames.map((name) =>
|
|
111
|
-
ts.factory.createShorthandPropertyAssignment(
|
|
112
|
-
ts.factory.createIdentifier(name),
|
|
113
|
-
undefined
|
|
114
|
-
)
|
|
115
|
-
),
|
|
116
|
-
],
|
|
117
|
-
true
|
|
118
|
-
)
|
|
119
|
-
),
|
|
120
|
-
],
|
|
121
|
-
ts.NodeFlags.Const
|
|
122
|
-
)
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Creates file that import all generated notion database Ids
|
|
127
|
-
function createNotionFile(nodeArr: ts.Node[]) {
|
|
128
|
-
const nodes = ts.factory.createNodeArray(nodeArr);
|
|
129
|
-
const sourceFile = ts.createSourceFile(
|
|
130
|
-
"placeholder.ts",
|
|
131
|
-
"",
|
|
132
|
-
ts.ScriptTarget.ESNext,
|
|
133
|
-
true,
|
|
134
|
-
ts.ScriptKind.TS
|
|
135
|
-
);
|
|
136
|
-
const printer = ts.createPrinter();
|
|
137
|
-
|
|
138
|
-
const outputFile = printer.printList(
|
|
139
|
-
ts.ListFormat.MultiLine,
|
|
140
|
-
nodes,
|
|
141
|
-
sourceFile
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const outputDir = path.join(__dirname, "../../src", "NotionActions");
|
|
145
|
-
|
|
146
|
-
if (!fs.existsSync(outputDir)) {
|
|
147
|
-
fs.mkdirSync(outputDir);
|
|
148
|
-
}
|
|
149
|
-
fs.writeFileSync(path.resolve(outputDir, "notion.ts"), outputFile);
|
|
150
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Column types' for all query options
|
|
3
|
-
*/
|
|
4
|
-
// import { PageObjectResponse }
|
|
5
|
-
|
|
6
|
-
import { PageObjectResponse } from "@notionhq/client/build/src/api-endpoints";
|
|
7
|
-
|
|
8
|
-
type columnDiscriminatedUnionTypes = PageObjectResponse["properties"];
|
|
9
|
-
type NotionColumnTypes =
|
|
10
|
-
columnDiscriminatedUnionTypes[keyof columnDiscriminatedUnionTypes]["type"];
|
|
11
|
-
|
|
12
|
-
export type FilterOptionNames =
|
|
13
|
-
| "text"
|
|
14
|
-
| "title"
|
|
15
|
-
| "number"
|
|
16
|
-
| "checkbox"
|
|
17
|
-
| "select"
|
|
18
|
-
| "multi_select"
|
|
19
|
-
| "url";
|
|
20
|
-
|
|
21
|
-
type TextPropertyFilters = {
|
|
22
|
-
equals: string;
|
|
23
|
-
does_not_equal: string;
|
|
24
|
-
contains: string;
|
|
25
|
-
does_not_contain: string;
|
|
26
|
-
starts_with: string;
|
|
27
|
-
ends_with: string;
|
|
28
|
-
is_empty: true;
|
|
29
|
-
is_not_empty: true;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
type NumberPropertyFilters = {
|
|
33
|
-
equals: number;
|
|
34
|
-
does_not_equals: number;
|
|
35
|
-
greater_than: number;
|
|
36
|
-
less_than: number;
|
|
37
|
-
greater_than_or_equal_to: number;
|
|
38
|
-
less_than_or_equal_to: number;
|
|
39
|
-
is_empty: true;
|
|
40
|
-
is_not_empty: true;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
type CheckBoxPropertyFilters = {
|
|
44
|
-
equals: boolean;
|
|
45
|
-
does_not_equal: boolean;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
//
|
|
49
|
-
type SelectPropertyFilters<T> = {
|
|
50
|
-
equals: (T extends Array<any> ? T[number] : T) | (string & {});
|
|
51
|
-
does_not_equal: (T extends Array<any> ? T[number] : T) | (string & {});
|
|
52
|
-
is_empty: true;
|
|
53
|
-
is_not_empty: true;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// pay in array --> need to turn into union
|
|
57
|
-
type MultiSelectPropertyFilters<T> = {
|
|
58
|
-
contains: (T extends Array<any> ? T[number] : T) | (string & {});
|
|
59
|
-
does_not_contain: (T extends Array<any> ? T[number] : T) | (string & {});
|
|
60
|
-
is_empty: true;
|
|
61
|
-
is_not_empty: true;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export type FilterOptions<T = []> = {
|
|
65
|
-
text: TextPropertyFilters;
|
|
66
|
-
title: TextPropertyFilters;
|
|
67
|
-
number: NumberPropertyFilters;
|
|
68
|
-
checkbox: CheckBoxPropertyFilters;
|
|
69
|
-
select: SelectPropertyFilters<T>;
|
|
70
|
-
multi_select: MultiSelectPropertyFilters<T>;
|
|
71
|
-
url: string;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Types to build query object user types out
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
const x = {
|
|
79
|
-
character: "multi_select",
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
type ColumnNameToNotionColumnType<T> = Record<keyof T, FilterOptionNames>;
|
|
83
|
-
type ColumnNameToPossibleValues = Record<string, any>;
|
|
84
|
-
// T is a column name to column type
|
|
85
|
-
// Y is the collection type
|
|
86
|
-
export type SingleFilter<
|
|
87
|
-
Y extends Record<string, any>,
|
|
88
|
-
T extends ColumnNameToNotionColumnType<Y>
|
|
89
|
-
> = {
|
|
90
|
-
// Passing the type from collection
|
|
91
|
-
[Property in keyof Y]?: Partial<FilterOptions<Y[Property]>[T[Property]]>;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export type CompoundFilters<
|
|
95
|
-
Y extends Record<string, any>,
|
|
96
|
-
T extends Record<keyof Y, FilterOptionNames>
|
|
97
|
-
> =
|
|
98
|
-
| { and: Array<SingleFilter<Y, T> | CompoundFilters<Y, T>> }
|
|
99
|
-
| { or: Array<SingleFilter<Y, T> | CompoundFilters<Y, T>> };
|
|
100
|
-
|
|
101
|
-
export type QueryFilter<
|
|
102
|
-
Y extends Record<string, any>,
|
|
103
|
-
T extends Record<keyof Y, FilterOptionNames>
|
|
104
|
-
> = SingleFilter<Y, T> | CompoundFilters<Y, T>;
|
|
105
|
-
|
|
106
|
-
export type Query<
|
|
107
|
-
Y extends Record<string, any>,
|
|
108
|
-
T extends Record<keyof Y, FilterOptionNames>
|
|
109
|
-
> = {
|
|
110
|
-
filter?: QueryFilter<Y, T>;
|
|
111
|
-
sort?: [];
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export type apiFilterQuery = {
|
|
115
|
-
filter?: apiSingleFilter | apiAndFilter | apiOrFilter;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Transform the types above to build types to
|
|
120
|
-
* actually build schema for query request
|
|
121
|
-
*/
|
|
122
|
-
|
|
123
|
-
type apiColumnTypeToOptions = {
|
|
124
|
-
[prop in keyof FilterOptions]?: Partial<FilterOptions[prop]>;
|
|
125
|
-
};
|
|
126
|
-
export interface apiSingleFilter extends apiColumnTypeToOptions {
|
|
127
|
-
property: string;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export type apiFilterType =
|
|
131
|
-
| apiSingleFilter
|
|
132
|
-
| apiAndFilter
|
|
133
|
-
| apiOrFilter
|
|
134
|
-
| undefined;
|
|
135
|
-
type apiAndFilter = {
|
|
136
|
-
and: Array<apiFilterType>;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
type apiOrFilter = {
|
|
140
|
-
or: Array<apiFilterType>;
|
|
141
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import { createDatabaseTypes } from "./NotionActions/NotionConfig";
|
|
5
|
-
import path from "path";
|
|
6
|
-
require("dotenv").config();
|
|
7
|
-
|
|
8
|
-
async function main() {
|
|
9
|
-
const args = process.argv.slice(2);
|
|
10
|
-
|
|
11
|
-
if (args.length === 1 && args[0] === "generate") {
|
|
12
|
-
const projDir = process.cwd();
|
|
13
|
-
|
|
14
|
-
const notionConfigDirJS = fs.existsSync(
|
|
15
|
-
path.join(projDir, "notion.config.js")
|
|
16
|
-
);
|
|
17
|
-
const notionConfigDirTS = fs.existsSync(
|
|
18
|
-
path.join(projDir, "notion.config.ts")
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
console.log(path.join(projDir, "notion.config"));
|
|
22
|
-
if (notionConfigDirJS || notionConfigDirTS) {
|
|
23
|
-
// this is a relative import, so we can escape out
|
|
24
|
-
|
|
25
|
-
const config = require(path.join(projDir, "notion.config"));
|
|
26
|
-
|
|
27
|
-
const { databaseNames } = await createDatabaseTypes(config);
|
|
28
|
-
if (databaseNames.length < 0) {
|
|
29
|
-
console.log("generated no types");
|
|
30
|
-
} else {
|
|
31
|
-
console.log("Generated types for the following Database's: ");
|
|
32
|
-
for (let x = 0; x < databaseNames.length; x++) {
|
|
33
|
-
console.log(`${x}. ${databaseNames[x]}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
console.error("Could not find file `notion.config.ts` in root");
|
|
38
|
-
process.exit(1);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
main();
|
package/tsconfig.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
-
"target": "es2016",
|
|
5
|
-
"lib": ["es6"],
|
|
6
|
-
"module": "commonjs",
|
|
7
|
-
"rootDir": "src",
|
|
8
|
-
"resolveJsonModule": true,
|
|
9
|
-
"allowJs": true,
|
|
10
|
-
"outDir": "build",
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"strict": true,
|
|
13
|
-
"baseUrl": "src",
|
|
14
|
-
"noImplicitAny": true,
|
|
15
|
-
"paths": {
|
|
16
|
-
"@notion-database/*":["NotionActions/DatabaseTypes/*"]
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"include": ["src/**/*", "src/NotionActions/DatabaseTypes"]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|