@haustle/notion-orm 0.0.38 → 0.0.41

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/src/queryTypes.ts DELETED
@@ -1,160 +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
- | "date";
21
-
22
- type TextPropertyFilters = {
23
- equals: string;
24
- does_not_equal: string;
25
- contains: string;
26
- does_not_contain: string;
27
- starts_with: string;
28
- ends_with: string;
29
- is_empty: true;
30
- is_not_empty: true;
31
- };
32
-
33
- type NumberPropertyFilters = {
34
- equals: number;
35
- does_not_equals: number;
36
- greater_than: number;
37
- less_than: number;
38
- greater_than_or_equal_to: number;
39
- less_than_or_equal_to: number;
40
- is_empty: true;
41
- is_not_empty: true;
42
- };
43
-
44
- type CheckBoxPropertyFilters = {
45
- equals: boolean;
46
- does_not_equal: boolean;
47
- };
48
-
49
- //
50
- type SelectPropertyFilters<T> = {
51
- equals: (T extends Array<any> ? T[number] : T) | (string & {});
52
- does_not_equal: (T extends Array<any> ? T[number] : T) | (string & {});
53
- is_empty: true;
54
- is_not_empty: true;
55
- };
56
-
57
- // pay in array --> need to turn into union
58
- type MultiSelectPropertyFilters<T> = {
59
- contains: (T extends Array<any> ? T[number] : T) | (string & {});
60
- does_not_contain: (T extends Array<any> ? T[number] : T) | (string & {});
61
- is_empty: true;
62
- is_not_empty: true;
63
- };
64
-
65
- type DatePropertyFilters = {
66
- equals: string;
67
- before: string;
68
- after: string;
69
- on_or_before: string;
70
- is_empty: true;
71
- is_not_empty: true;
72
- on_or_after: string;
73
- past_week: {};
74
- past_month: {};
75
- past_year: {};
76
- this_week: {};
77
- next_week: {};
78
- next_month: {};
79
- next_year: {};
80
- };
81
-
82
- export type FilterOptions<T = []> = {
83
- text: TextPropertyFilters;
84
- title: TextPropertyFilters;
85
- number: NumberPropertyFilters;
86
- checkbox: CheckBoxPropertyFilters;
87
- select: SelectPropertyFilters<T>;
88
- multi_select: MultiSelectPropertyFilters<T>;
89
- url: string;
90
- date: DatePropertyFilters;
91
- };
92
-
93
- /**
94
- * Types to build query object user types out
95
- */
96
-
97
- const x = {
98
- character: "multi_select",
99
- };
100
-
101
- type ColumnNameToNotionColumnType<T> = Record<keyof T, FilterOptionNames>;
102
- type ColumnNameToPossibleValues = Record<string, any>;
103
- // T is a column name to column type
104
- // Y is the collection type
105
- export type SingleFilter<
106
- Y extends Record<string, any>,
107
- T extends ColumnNameToNotionColumnType<Y>
108
- > = {
109
- // Passing the type from collection
110
- [Property in keyof Y]?: Partial<FilterOptions<Y[Property]>[T[Property]]>;
111
- };
112
-
113
- export type CompoundFilters<
114
- Y extends Record<string, any>,
115
- T extends Record<keyof Y, FilterOptionNames>
116
- > =
117
- | { and: Array<SingleFilter<Y, T> | CompoundFilters<Y, T>> }
118
- | { or: Array<SingleFilter<Y, T> | CompoundFilters<Y, T>> };
119
-
120
- export type QueryFilter<
121
- Y extends Record<string, any>,
122
- T extends Record<keyof Y, FilterOptionNames>
123
- > = SingleFilter<Y, T> | CompoundFilters<Y, T>;
124
-
125
- export type Query<
126
- Y extends Record<string, any>,
127
- T extends Record<keyof Y, FilterOptionNames>
128
- > = {
129
- filter?: QueryFilter<Y, T>;
130
- sort?: [];
131
- };
132
-
133
- export type apiFilterQuery = {
134
- filter?: apiSingleFilter | apiAndFilter | apiOrFilter;
135
- };
136
-
137
- /**
138
- * Transform the types above to build types to
139
- * actually build schema for query request
140
- */
141
-
142
- type apiColumnTypeToOptions = {
143
- [prop in keyof FilterOptions]?: Partial<FilterOptions[prop]>;
144
- };
145
- export interface apiSingleFilter extends apiColumnTypeToOptions {
146
- property: string;
147
- }
148
-
149
- export type apiFilterType =
150
- | apiSingleFilter
151
- | apiAndFilter
152
- | apiOrFilter
153
- | undefined;
154
- type apiAndFilter = {
155
- and: Array<apiFilterType>;
156
- };
157
-
158
- type apiOrFilter = {
159
- or: Array<apiFilterType>;
160
- };