@elumixor/notion-orm 0.1.1

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.
@@ -0,0 +1,10 @@
1
+ export type NotionConfigType = {
2
+ auth: string;
3
+ databases: Record<string, string>;
4
+ };
5
+ export declare function validateConfig(): Promise<void>;
6
+ export declare function findConfigFile(): {
7
+ path: string;
8
+ isTS: true;
9
+ } | undefined;
10
+ export declare function initializeNotionConfigFile(): Promise<void>;
@@ -0,0 +1,5 @@
1
+ import type { NotionConfigType } from "./helpers";
2
+ export declare function loadUserConfig(absolutePath: string): Promise<unknown>;
3
+ export declare function loadConfig(configPath: string): Promise<NotionConfigType>;
4
+ export declare function getNotionConfig(): Promise<NotionConfigType>;
5
+ export declare function clearConfigCache(): void;
@@ -0,0 +1,47 @@
1
+ import type { CreatePageParameters, CreatePageResponse, UpdatePageParameters } from "@notionhq/client/build/src/api-endpoints";
2
+ import type { ZodTypeAny } from "zod";
3
+ import type { Query, QueryFilter, QueryResultType, SupportedNotionColumnType } from "./queryTypes";
4
+ export type camelPropertyNameToNameAndTypeMapType = Record<string, {
5
+ columnName: string;
6
+ type: SupportedNotionColumnType;
7
+ }>;
8
+ export declare class DatabaseClient<DatabaseSchemaType extends Record<string, any>, ColumnNameToColumnType extends Record<keyof DatabaseSchemaType, SupportedNotionColumnType>> {
9
+ private client;
10
+ private id;
11
+ private camelPropertyNameToNameAndTypeMap;
12
+ private schema;
13
+ name: string;
14
+ private loggedSchemaValidationIssues;
15
+ constructor(args: {
16
+ id: string;
17
+ camelPropertyNameToNameAndTypeMap: camelPropertyNameToNameAndTypeMapType;
18
+ auth: string;
19
+ name: string;
20
+ schema: ZodTypeAny;
21
+ });
22
+ add(args: {
23
+ properties: DatabaseSchemaType;
24
+ icon?: CreatePageParameters["icon"];
25
+ }): Promise<CreatePageParameters | CreatePageResponse>;
26
+ update(id: string, properties: Partial<DatabaseSchemaType>, icon?: UpdatePageParameters["icon"]): Promise<void>;
27
+ delete(id: string): Promise<void>;
28
+ upsert(args: {
29
+ where: QueryFilter<DatabaseSchemaType, ColumnNameToColumnType>;
30
+ properties: DatabaseSchemaType;
31
+ icon?: CreatePageParameters["icon"];
32
+ }): Promise<{
33
+ created: boolean;
34
+ id: string;
35
+ }>;
36
+ query<Args extends Query<DatabaseSchemaType, ColumnNameToColumnType> & {
37
+ pagination: {
38
+ pageSize: number;
39
+ };
40
+ }>(query: Args): AsyncIterable<QueryResultType<DatabaseSchemaType, Args>>;
41
+ query<Args extends Omit<Query<DatabaseSchemaType, ColumnNameToColumnType>, "pagination">>(query: Args): Promise<QueryResultType<DatabaseSchemaType, Args>[]>;
42
+ private buildQueryCall;
43
+ private fetchAllPages;
44
+ private paginatedIterable;
45
+ private applySelectOmit;
46
+ private validateDatabaseSchema;
47
+ }
@@ -0,0 +1,44 @@
1
+ import { SupportedNotionColumnType } from "./queryTypes";
2
+ export declare function buildPropertyValueForAddPage(args: {
3
+ type: SupportedNotionColumnType;
4
+ value: string | number | boolean;
5
+ }): {
6
+ select: {
7
+ name: string;
8
+ };
9
+ } | {
10
+ multi_select: {
11
+ name: string;
12
+ }[];
13
+ } | {
14
+ status: {
15
+ name: string;
16
+ };
17
+ } | {
18
+ number: number;
19
+ } | {
20
+ email: string;
21
+ } | {
22
+ date: {
23
+ start: string;
24
+ end?: string;
25
+ };
26
+ } | {
27
+ phone_number: string;
28
+ } | {
29
+ url: string;
30
+ } | {
31
+ checkbox: boolean;
32
+ } | {
33
+ title: {
34
+ text: {
35
+ content: string;
36
+ };
37
+ }[];
38
+ } | {
39
+ rich_text: {
40
+ text: {
41
+ content: string;
42
+ };
43
+ }[];
44
+ } | undefined;
@@ -0,0 +1,17 @@
1
+ import type { QueryDataSourceResponse } from "@notionhq/client/build/src/api-endpoints";
2
+ import type { apiFilterType, QueryFilter, SupportedNotionColumnType } from "./queryTypes";
3
+ import type { camelPropertyNameToNameAndTypeMapType } from "./DatabaseClient";
4
+ /**
5
+ * Transforms Notion API query response into simplified format
6
+ */
7
+ export declare function buildQueryResponse<DatabaseSchemaType extends Record<string, any>>(res: QueryDataSourceResponse, camelPropertyNameToNameAndTypeMap: camelPropertyNameToNameAndTypeMapType, validateSchema: (result: Partial<DatabaseSchemaType>) => void): (Partial<DatabaseSchemaType> & {
8
+ id: string;
9
+ })[];
10
+ /**
11
+ * Extracts value from Notion property object based on column type
12
+ */
13
+ export declare function getResponseValue(prop: SupportedNotionColumnType, x: Record<string, any>): any;
14
+ /**
15
+ * Recursively converts user query filters to Notion API filter format
16
+ */
17
+ export declare function recursivelyBuildFilter<DatabaseSchemaType extends Record<string, any>, ColumnNameToColumnType extends Record<keyof DatabaseSchemaType, SupportedNotionColumnType>>(queryFilter: QueryFilter<DatabaseSchemaType, ColumnNameToColumnType>, camelPropertyNameToNameAndTypeMap: camelPropertyNameToNameAndTypeMapType): apiFilterType;
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Column types' for all query options
3
+ */
4
+ import type { DataSourceObjectResponse, QueryDataSourceParameters } from "@notionhq/client/build/src/api-endpoints";
5
+ type NotionPropertyTypeToConfigMap = DataSourceObjectResponse["properties"];
6
+ export type DatabasePropertyType = NotionPropertyTypeToConfigMap[keyof NotionPropertyTypeToConfigMap]["type"];
7
+ export declare const SUPPORTED_PROPERTY_TYPES: {
8
+ readonly files: false;
9
+ readonly people: false;
10
+ readonly rollup: true;
11
+ readonly created_by: false;
12
+ readonly last_edited_by: false;
13
+ readonly created_time: false;
14
+ readonly last_edited_time: false;
15
+ readonly formula: true;
16
+ readonly relation: true;
17
+ readonly url: true;
18
+ readonly phone_number: true;
19
+ readonly title: true;
20
+ readonly email: true;
21
+ readonly checkbox: true;
22
+ readonly date: true;
23
+ readonly multi_select: true;
24
+ readonly status: true;
25
+ readonly number: true;
26
+ readonly rich_text: true;
27
+ readonly select: true;
28
+ readonly unique_id: true;
29
+ };
30
+ export declare function isSupportedPropertyType(propertyType: DatabasePropertyType): propertyType is SupportedNotionColumnType;
31
+ export type SupportedNotionColumnType = {
32
+ [K in keyof typeof SUPPORTED_PROPERTY_TYPES]: (typeof SUPPORTED_PROPERTY_TYPES)[K] extends true ? K : never;
33
+ }[keyof typeof SUPPORTED_PROPERTY_TYPES];
34
+ type TextPropertyFilters = {
35
+ equals: string;
36
+ does_not_equal: string;
37
+ contains: string;
38
+ does_not_contain: string;
39
+ starts_with: string;
40
+ ends_with: string;
41
+ is_empty: true;
42
+ is_not_empty: true;
43
+ };
44
+ type NumberPropertyFilters = {
45
+ equals: number;
46
+ does_not_equals: number;
47
+ greater_than: number;
48
+ less_than: number;
49
+ greater_than_or_equal_to: number;
50
+ less_than_or_equal_to: number;
51
+ is_empty: true;
52
+ is_not_empty: true;
53
+ };
54
+ type CheckBoxPropertyFilters = {
55
+ equals: boolean;
56
+ does_not_equal: boolean;
57
+ };
58
+ type SelectPropertyFilters<T> = {
59
+ equals: (T extends Array<any> ? T[number] : T) | (string & {});
60
+ does_not_equal: (T extends Array<any> ? T[number] : T) | (string & {});
61
+ is_empty: true;
62
+ is_not_empty: true;
63
+ };
64
+ type MultiSelectPropertyFilters<T> = {
65
+ contains: (T extends Array<any> ? T[number] : T) | (string & {});
66
+ does_not_contain: (T extends Array<any> ? T[number] : T) | (string & {});
67
+ is_empty: true;
68
+ is_not_empty: true;
69
+ };
70
+ type StatusPropertyFilters<T> = SelectPropertyFilters<T>;
71
+ type ISO8601Date = string;
72
+ type DatePropertyFilters = {
73
+ equals: ISO8601Date;
74
+ before: ISO8601Date;
75
+ after: ISO8601Date;
76
+ on_or_before: ISO8601Date;
77
+ is_empty: true;
78
+ is_not_empty: true;
79
+ on_or_after: string;
80
+ past_week: {};
81
+ past_month: {};
82
+ past_year: {};
83
+ this_week: {};
84
+ next_week: {};
85
+ next_month: {};
86
+ next_year: {};
87
+ };
88
+ export type FilterOptions<T = []> = {
89
+ rich_text: TextPropertyFilters;
90
+ title: TextPropertyFilters;
91
+ number: NumberPropertyFilters;
92
+ checkbox: CheckBoxPropertyFilters;
93
+ select: SelectPropertyFilters<T>;
94
+ multi_select: MultiSelectPropertyFilters<T>;
95
+ url: TextPropertyFilters;
96
+ date: DatePropertyFilters;
97
+ status: StatusPropertyFilters<T>;
98
+ email: TextPropertyFilters;
99
+ phone_number: TextPropertyFilters;
100
+ };
101
+ /**
102
+ * Types to build query object user types out
103
+ */
104
+ type ColumnNameToNotionColumnType<T> = Record<keyof T, SupportedNotionColumnType>;
105
+ export type SingleFilter<Y extends Record<string, any>, T extends ColumnNameToNotionColumnType<Y>> = {
106
+ [Property in keyof Y]?: T[Property] extends keyof FilterOptions<Y[Property]> ? Partial<FilterOptions<Y[Property]>[T[Property]]> : never;
107
+ };
108
+ export type CompoundFilters<Y extends Record<string, any>, T extends Record<keyof Y, SupportedNotionColumnType>> = {
109
+ and: Array<SingleFilter<Y, T> | CompoundFilters<Y, T>>;
110
+ } | {
111
+ or: Array<SingleFilter<Y, T> | CompoundFilters<Y, T>>;
112
+ };
113
+ export type QueryFilter<Y extends Record<string, any>, T extends Record<keyof Y, SupportedNotionColumnType>> = SingleFilter<Y, T> | CompoundFilters<Y, T>;
114
+ export type Query<Y extends Record<string, any>, T extends Record<keyof Y, SupportedNotionColumnType>> = {
115
+ filter?: QueryFilter<Y, T>;
116
+ sort?: QueryDataSourceParameters["sorts"];
117
+ select?: Partial<Record<keyof Y, true>>;
118
+ omit?: Partial<Record<keyof Y, true>>;
119
+ limit?: number;
120
+ pagination?: {
121
+ pageSize: number;
122
+ };
123
+ };
124
+ export type apiFilterQuery = {
125
+ filter?: apiSingleFilter | apiAndFilter | apiOrFilter;
126
+ };
127
+ /**
128
+ * Transform the types above to build types to
129
+ * actually build schema for query request
130
+ */
131
+ type apiColumnTypeToOptions = {
132
+ [prop in keyof FilterOptions]?: Partial<FilterOptions[prop]>;
133
+ };
134
+ export interface apiSingleFilter extends apiColumnTypeToOptions {
135
+ property: string;
136
+ }
137
+ export type apiFilterType = apiSingleFilter | apiAndFilter | apiOrFilter | undefined;
138
+ type apiAndFilter = {
139
+ and: Array<apiFilterType>;
140
+ };
141
+ type apiOrFilter = {
142
+ or: Array<apiFilterType>;
143
+ };
144
+ export type QueryResult<DatabaseSchema> = Partial<DatabaseSchema> & {
145
+ id: string;
146
+ };
147
+ export type QueryResultType<Y, Args> = Args extends {
148
+ select: infer S extends Record<string, unknown>;
149
+ } ? {
150
+ [K in Extract<keyof S, keyof Y>]?: Y[K];
151
+ } & {
152
+ id: string;
153
+ } : Args extends {
154
+ omit: infer O extends Record<string, unknown>;
155
+ } ? {
156
+ [K in Exclude<keyof Y, keyof O>]?: Y[K];
157
+ } & {
158
+ id: string;
159
+ } : Partial<Y> & {
160
+ id: string;
161
+ };
162
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare function camelize(str: string): string;
2
+ type Entries<T> = {
3
+ [K in keyof T]-?: [K, T[K]];
4
+ }[keyof T][];
5
+ export declare function objectEntries<T extends object>(obj: T): Entries<T>;
6
+ export {};