@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.
@@ -1,10 +1,13 @@
1
+ /**
2
+ * Responsible for consuming notion.config.js
3
+ */
4
+
1
5
  import { Client } from "@notionhq/client";
2
6
  import { GetDatabaseResponse } from "@notionhq/client/build/src/api-endpoints";
3
7
  import { createTypescriptFileForDatabase } from "./GenerateTypes";
4
8
  import * as ts from "typescript";
5
9
  import fs from "fs";
6
10
  import path from "path";
7
- require("dotenv").config();
8
11
 
9
12
  export const DATABASES_DIR = path.join(__dirname, "../../build", "databases");
10
13
 
@@ -13,13 +16,8 @@ export type NotionConfigType = {
13
16
  databaseIds: string[];
14
17
  };
15
18
 
16
- type importClassType = {
17
- databaseId: string;
18
- databaseClassName: string;
19
- };
20
-
21
- export const createDatabaseTypes = async (notionInfo: NotionConfigType) => {
22
- const { auth, databaseIds } = notionInfo;
19
+ export const createDatabaseTypes = async (args: NotionConfigType) => {
20
+ const { auth, databaseIds } = args;
23
21
 
24
22
  // Making sure the user is passing valid arguments
25
23
  if (!auth) {
@@ -62,7 +60,6 @@ export const createDatabaseTypes = async (notionInfo: NotionConfigType) => {
62
60
  databaseClassExportStatements.push(
63
61
  databaseExportStatement({
64
62
  databaseClassName,
65
- databaseId,
66
63
  })
67
64
  );
68
65
  } catch (e) {
@@ -72,12 +69,16 @@ export const createDatabaseTypes = async (notionInfo: NotionConfigType) => {
72
69
  }
73
70
 
74
71
  // Create a file that exports all databases
75
- createNotionFile([...databaseClassExportStatements]);
72
+ createDatabaseBarrelFile({
73
+ databaseClassExportStatements,
74
+ });
76
75
  return { databaseNames };
77
76
  };
78
77
 
79
- // Create the import statement for notion.ts file
80
- function databaseExportStatement(dbClass: importClassType) {
78
+ // Create the export statement for database file file
79
+ // export { databaseName } from "./databaseName"
80
+ function databaseExportStatement(args: { databaseClassName: string }) {
81
+ const { databaseClassName } = args;
81
82
  return ts.factory.createExportDeclaration(
82
83
  undefined,
83
84
  false,
@@ -85,17 +86,20 @@ function databaseExportStatement(dbClass: importClassType) {
85
86
  ts.factory.createExportSpecifier(
86
87
  false,
87
88
  undefined,
88
- ts.factory.createIdentifier(dbClass.databaseClassName)
89
+ ts.factory.createIdentifier(databaseClassName)
89
90
  ),
90
91
  ]),
91
- ts.factory.createStringLiteral(`./${dbClass.databaseId}`),
92
+ ts.factory.createStringLiteral(`./${databaseClassName}`),
92
93
  undefined
93
94
  );
94
95
  }
95
96
 
96
97
  // Creates file that import all generated notion database Ids
97
- function createNotionFile(nodeArr: ts.Node[]) {
98
- const nodes = ts.factory.createNodeArray(nodeArr);
98
+ function createDatabaseBarrelFile(args: {
99
+ databaseClassExportStatements: ts.Node[];
100
+ }) {
101
+ const { databaseClassExportStatements } = args;
102
+ const nodes = ts.factory.createNodeArray(databaseClassExportStatements);
99
103
  const sourceFile = ts.createSourceFile(
100
104
  "placeholder.ts",
101
105
  "",
@@ -122,11 +126,11 @@ function createNotionFile(nodeArr: ts.Node[]) {
122
126
 
123
127
  // Create TypeScript and JavaScript file
124
128
  fs.writeFileSync(
125
- path.resolve(DATABASES_DIR, "notion.ts"),
129
+ path.resolve(DATABASES_DIR, "index.ts"),
126
130
  typescriptCodeToString
127
131
  );
128
132
  fs.writeFileSync(
129
- path.resolve(DATABASES_DIR, "notion.js"),
130
- typescriptCodeToString
133
+ path.resolve(DATABASES_DIR, "index.js"),
134
+ transpileToJavaScript
131
135
  );
132
136
  }
package/src/queryTypes.ts CHANGED
@@ -6,18 +6,22 @@
6
6
  import { PageObjectResponse } from "@notionhq/client/build/src/api-endpoints";
7
7
 
8
8
  type columnDiscriminatedUnionTypes = PageObjectResponse["properties"];
9
- type NotionColumnTypes =
9
+ export type NotionColumnTypes =
10
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
- | "date";
11
+ // type SupportedQueryableNotionColumnTypes = Exclude<NotionColumnTypes, "created_by" | >
12
+
13
+ export type SupportedNotionColumnTypes = Exclude<
14
+ NotionColumnTypes,
15
+ | "formula"
16
+ | "files"
17
+ | "people"
18
+ | "relation"
19
+ | "rollup"
20
+ | "created_by"
21
+ | "last_edited_by"
22
+ | "created_time"
23
+ | "last_edited_time"
24
+ >;
21
25
 
22
26
  type TextPropertyFilters = {
23
27
  equals: string;
@@ -62,11 +66,14 @@ type MultiSelectPropertyFilters<T> = {
62
66
  is_not_empty: true;
63
67
  };
64
68
 
69
+ type StatusPropertyFilters<T> = SelectPropertyFilters<T>;
70
+
71
+ type ISO8601Date = string;
65
72
  type DatePropertyFilters = {
66
- equals: string;
67
- before: string;
68
- after: string;
69
- on_or_before: string;
73
+ equals: ISO8601Date;
74
+ before: ISO8601Date;
75
+ after: ISO8601Date;
76
+ on_or_before: ISO8601Date;
70
77
  is_empty: true;
71
78
  is_not_empty: true;
72
79
  on_or_after: string;
@@ -80,25 +87,27 @@ type DatePropertyFilters = {
80
87
  };
81
88
 
82
89
  export type FilterOptions<T = []> = {
83
- text: TextPropertyFilters;
90
+ rich_text: TextPropertyFilters;
84
91
  title: TextPropertyFilters;
85
92
  number: NumberPropertyFilters;
86
93
  checkbox: CheckBoxPropertyFilters;
87
94
  select: SelectPropertyFilters<T>;
88
95
  multi_select: MultiSelectPropertyFilters<T>;
89
- url: string;
96
+ url: TextPropertyFilters;
90
97
  date: DatePropertyFilters;
98
+ status: StatusPropertyFilters<T>;
99
+ email: TextPropertyFilters;
100
+ phone_number: TextPropertyFilters;
91
101
  };
92
102
 
93
103
  /**
94
104
  * Types to build query object user types out
95
105
  */
96
106
 
97
- const x = {
98
- character: "multi_select",
99
- };
100
-
101
- type ColumnNameToNotionColumnType<T> = Record<keyof T, FilterOptionNames>;
107
+ type ColumnNameToNotionColumnType<T> = Record<
108
+ keyof T,
109
+ SupportedNotionColumnTypes
110
+ >;
102
111
  type ColumnNameToPossibleValues = Record<string, any>;
103
112
  // T is a column name to column type
104
113
  // Y is the collection type
@@ -112,19 +121,19 @@ export type SingleFilter<
112
121
 
113
122
  export type CompoundFilters<
114
123
  Y extends Record<string, any>,
115
- T extends Record<keyof Y, FilterOptionNames>
124
+ T extends Record<keyof Y, SupportedNotionColumnTypes>
116
125
  > =
117
126
  | { and: Array<SingleFilter<Y, T> | CompoundFilters<Y, T>> }
118
127
  | { or: Array<SingleFilter<Y, T> | CompoundFilters<Y, T>> };
119
128
 
120
129
  export type QueryFilter<
121
130
  Y extends Record<string, any>,
122
- T extends Record<keyof Y, FilterOptionNames>
131
+ T extends Record<keyof Y, SupportedNotionColumnTypes>
123
132
  > = SingleFilter<Y, T> | CompoundFilters<Y, T>;
124
133
 
125
134
  export type Query<
126
135
  Y extends Record<string, any>,
127
- T extends Record<keyof Y, FilterOptionNames>
136
+ T extends Record<keyof Y, SupportedNotionColumnTypes>
128
137
  > = {
129
138
  filter?: QueryFilter<Y, T>;
130
139
  sort?: [];
@@ -1,9 +0,0 @@
1
- export declare const DATABASES_DIR: string;
2
- export type NotionConfigType = {
3
- auth: string;
4
- databaseIds: string[];
5
- };
6
- export declare const createDatabaseTypes: (notionInfo: NotionConfigType) => Promise<{
7
- databaseNames: string[];
8
- }>;
9
- //# sourceMappingURL=NotionConfig.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NotionConfig.d.ts","sourceRoot":"","sources":["../../src/NotionConfig.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,aAAa,QAAmD,CAAC;AAE9E,MAAM,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAOF,eAAO,MAAM,mBAAmB,eAAsB,gBAAgB;;EAwDrE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"NotionConfig.js","sourceRoot":"","sources":["../../src/NotionConf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