@basictech/react 0.7.0-beta.1 → 0.7.0-beta.2
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/changelog.md +6 -0
- package/dist/index.d.mts +107 -1
- package/dist/index.d.ts +107 -1
- package/dist/index.js +719 -356
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +716 -344
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/AuthContext.tsx +178 -402
- package/src/index.ts +6 -31
- package/src/sync/index.ts +1 -1
- package/src/updater/updateMigrations.ts +22 -0
- package/src/updater/versionUpdater.ts +160 -0
- package/src/utils/network.ts +82 -0
- package/src/utils/schema.ts +120 -0
- package/src/utils/storage.ts +62 -0
- package/src/schema.ts +0 -159
package/changelog.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -7,6 +7,7 @@ interface BasicStorage {
|
|
|
7
7
|
set(key: string, value: string): Promise<void>;
|
|
8
8
|
remove(key: string): Promise<void>;
|
|
9
9
|
}
|
|
10
|
+
|
|
10
11
|
declare enum DBStatus {
|
|
11
12
|
LOADING = "LOADING",
|
|
12
13
|
OFFLINE = "OFFLINE",
|
|
@@ -45,7 +46,112 @@ declare function useBasic(): {
|
|
|
45
46
|
getToken: () => Promise<string>;
|
|
46
47
|
getSignInLink: (redirectUri?: string) => Promise<string>;
|
|
47
48
|
db: any;
|
|
49
|
+
remoteDb: any;
|
|
48
50
|
dbStatus: DBStatus;
|
|
49
51
|
};
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
type FieldType = "string" | "boolean" | "number" | "json";
|
|
54
|
+
interface SchemaField {
|
|
55
|
+
type: FieldType;
|
|
56
|
+
indexed?: boolean;
|
|
57
|
+
}
|
|
58
|
+
interface TableSchema {
|
|
59
|
+
fields: Record<string, SchemaField>;
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
}
|
|
62
|
+
interface DBSchema {
|
|
63
|
+
project_id: string;
|
|
64
|
+
version: number;
|
|
65
|
+
tables: Record<string, TableSchema>;
|
|
66
|
+
}
|
|
67
|
+
type OrderDirection = "asc" | "desc";
|
|
68
|
+
type FilterValue = string | number | boolean | null | string[];
|
|
69
|
+
interface OperatorFilter {
|
|
70
|
+
eq?: FilterValue;
|
|
71
|
+
neq?: FilterValue;
|
|
72
|
+
gt?: number | string;
|
|
73
|
+
gte?: number | string;
|
|
74
|
+
lt?: number | string;
|
|
75
|
+
lte?: number | string;
|
|
76
|
+
like?: string;
|
|
77
|
+
ilike?: string;
|
|
78
|
+
in?: string[] | number[];
|
|
79
|
+
is?: boolean | null;
|
|
80
|
+
not?: OperatorFilter;
|
|
81
|
+
}
|
|
82
|
+
type FilterCondition = FilterValue | OperatorFilter;
|
|
83
|
+
interface QueryOptions {
|
|
84
|
+
id?: string;
|
|
85
|
+
order?: string;
|
|
86
|
+
limit?: number;
|
|
87
|
+
offset?: number;
|
|
88
|
+
filters?: Record<string, FilterCondition>;
|
|
89
|
+
}
|
|
90
|
+
type FieldTypeToTS<T extends FieldType> = T extends "string" ? string : T extends "boolean" ? boolean : T extends "number" ? number : T extends "json" ? Record<string, any> : never;
|
|
91
|
+
type TableData<T extends TableSchema> = {
|
|
92
|
+
id: string;
|
|
93
|
+
created_at: string;
|
|
94
|
+
} & {
|
|
95
|
+
[K in keyof T["fields"]]: T["fields"][K] extends {
|
|
96
|
+
type: FieldType;
|
|
97
|
+
} ? FieldTypeToTS<T["fields"][K]["type"]> : never;
|
|
98
|
+
};
|
|
99
|
+
interface SDKConfig<S extends DBSchema> {
|
|
100
|
+
project_id: string;
|
|
101
|
+
token?: string;
|
|
102
|
+
getToken?: () => Promise<string>;
|
|
103
|
+
baseUrl?: string;
|
|
104
|
+
schema: S;
|
|
105
|
+
}
|
|
106
|
+
declare class QueryBuilder<T> {
|
|
107
|
+
private tableClient;
|
|
108
|
+
private tableSchema?;
|
|
109
|
+
private params;
|
|
110
|
+
constructor(tableClient: TableClient<T>, tableSchema?: TableSchema | undefined);
|
|
111
|
+
private reservedFields;
|
|
112
|
+
private validateField;
|
|
113
|
+
private validateOperator;
|
|
114
|
+
order(field: string, direction?: OrderDirection): QueryBuilder<T>;
|
|
115
|
+
filter(conditions: Record<string, FilterCondition>): QueryBuilder<T>;
|
|
116
|
+
limit(count: number): QueryBuilder<T>;
|
|
117
|
+
offset(count: number): QueryBuilder<T>;
|
|
118
|
+
then<TResult1 = T[], TResult2 = never>(onfulfilled?: ((value: T[]) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
119
|
+
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<T[] | TResult>;
|
|
120
|
+
finally(onfinally?: (() => void) | null): Promise<T[]>;
|
|
121
|
+
}
|
|
122
|
+
declare class TableClient<T> {
|
|
123
|
+
private baseUrl;
|
|
124
|
+
private projectId;
|
|
125
|
+
private token;
|
|
126
|
+
private table;
|
|
127
|
+
private getToken;
|
|
128
|
+
private schema?;
|
|
129
|
+
private tableSchema?;
|
|
130
|
+
constructor(baseUrl: string, projectId: string, token: string, table: string, getToken: () => Promise<string>, schema?: DBSchema | undefined);
|
|
131
|
+
private headers;
|
|
132
|
+
private handleRequest;
|
|
133
|
+
private buildQueryParams;
|
|
134
|
+
private addFilterParam;
|
|
135
|
+
executeQuery(options?: QueryOptions): Promise<T[]>;
|
|
136
|
+
getAll(): QueryBuilder<T>;
|
|
137
|
+
get(id: string): Promise<T>;
|
|
138
|
+
create(value: Partial<T>): Promise<T>;
|
|
139
|
+
update(id: string, value: Partial<T>): Promise<T>;
|
|
140
|
+
replace(id: string, value: Partial<T>): Promise<T>;
|
|
141
|
+
delete(id: string): Promise<T>;
|
|
142
|
+
}
|
|
143
|
+
declare class BasicDBSDK<S extends DBSchema> {
|
|
144
|
+
private projectId;
|
|
145
|
+
private getToken;
|
|
146
|
+
private baseUrl;
|
|
147
|
+
private schema;
|
|
148
|
+
private tableNames;
|
|
149
|
+
constructor(config: SDKConfig<S>);
|
|
150
|
+
table<K extends keyof S["tables"] & string>(name: K): TableClient<TableData<S["tables"][K]>>;
|
|
151
|
+
get tables(): {
|
|
152
|
+
[K in keyof S["tables"]]: TableData<S["tables"][K]>;
|
|
153
|
+
};
|
|
154
|
+
fields<K extends keyof S["tables"] & string>(table: K): (keyof S["tables"][K]["fields"] & string)[];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export { BasicDBSDK, BasicProvider, useBasic };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ interface BasicStorage {
|
|
|
7
7
|
set(key: string, value: string): Promise<void>;
|
|
8
8
|
remove(key: string): Promise<void>;
|
|
9
9
|
}
|
|
10
|
+
|
|
10
11
|
declare enum DBStatus {
|
|
11
12
|
LOADING = "LOADING",
|
|
12
13
|
OFFLINE = "OFFLINE",
|
|
@@ -45,7 +46,112 @@ declare function useBasic(): {
|
|
|
45
46
|
getToken: () => Promise<string>;
|
|
46
47
|
getSignInLink: (redirectUri?: string) => Promise<string>;
|
|
47
48
|
db: any;
|
|
49
|
+
remoteDb: any;
|
|
48
50
|
dbStatus: DBStatus;
|
|
49
51
|
};
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
type FieldType = "string" | "boolean" | "number" | "json";
|
|
54
|
+
interface SchemaField {
|
|
55
|
+
type: FieldType;
|
|
56
|
+
indexed?: boolean;
|
|
57
|
+
}
|
|
58
|
+
interface TableSchema {
|
|
59
|
+
fields: Record<string, SchemaField>;
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
}
|
|
62
|
+
interface DBSchema {
|
|
63
|
+
project_id: string;
|
|
64
|
+
version: number;
|
|
65
|
+
tables: Record<string, TableSchema>;
|
|
66
|
+
}
|
|
67
|
+
type OrderDirection = "asc" | "desc";
|
|
68
|
+
type FilterValue = string | number | boolean | null | string[];
|
|
69
|
+
interface OperatorFilter {
|
|
70
|
+
eq?: FilterValue;
|
|
71
|
+
neq?: FilterValue;
|
|
72
|
+
gt?: number | string;
|
|
73
|
+
gte?: number | string;
|
|
74
|
+
lt?: number | string;
|
|
75
|
+
lte?: number | string;
|
|
76
|
+
like?: string;
|
|
77
|
+
ilike?: string;
|
|
78
|
+
in?: string[] | number[];
|
|
79
|
+
is?: boolean | null;
|
|
80
|
+
not?: OperatorFilter;
|
|
81
|
+
}
|
|
82
|
+
type FilterCondition = FilterValue | OperatorFilter;
|
|
83
|
+
interface QueryOptions {
|
|
84
|
+
id?: string;
|
|
85
|
+
order?: string;
|
|
86
|
+
limit?: number;
|
|
87
|
+
offset?: number;
|
|
88
|
+
filters?: Record<string, FilterCondition>;
|
|
89
|
+
}
|
|
90
|
+
type FieldTypeToTS<T extends FieldType> = T extends "string" ? string : T extends "boolean" ? boolean : T extends "number" ? number : T extends "json" ? Record<string, any> : never;
|
|
91
|
+
type TableData<T extends TableSchema> = {
|
|
92
|
+
id: string;
|
|
93
|
+
created_at: string;
|
|
94
|
+
} & {
|
|
95
|
+
[K in keyof T["fields"]]: T["fields"][K] extends {
|
|
96
|
+
type: FieldType;
|
|
97
|
+
} ? FieldTypeToTS<T["fields"][K]["type"]> : never;
|
|
98
|
+
};
|
|
99
|
+
interface SDKConfig<S extends DBSchema> {
|
|
100
|
+
project_id: string;
|
|
101
|
+
token?: string;
|
|
102
|
+
getToken?: () => Promise<string>;
|
|
103
|
+
baseUrl?: string;
|
|
104
|
+
schema: S;
|
|
105
|
+
}
|
|
106
|
+
declare class QueryBuilder<T> {
|
|
107
|
+
private tableClient;
|
|
108
|
+
private tableSchema?;
|
|
109
|
+
private params;
|
|
110
|
+
constructor(tableClient: TableClient<T>, tableSchema?: TableSchema | undefined);
|
|
111
|
+
private reservedFields;
|
|
112
|
+
private validateField;
|
|
113
|
+
private validateOperator;
|
|
114
|
+
order(field: string, direction?: OrderDirection): QueryBuilder<T>;
|
|
115
|
+
filter(conditions: Record<string, FilterCondition>): QueryBuilder<T>;
|
|
116
|
+
limit(count: number): QueryBuilder<T>;
|
|
117
|
+
offset(count: number): QueryBuilder<T>;
|
|
118
|
+
then<TResult1 = T[], TResult2 = never>(onfulfilled?: ((value: T[]) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
119
|
+
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<T[] | TResult>;
|
|
120
|
+
finally(onfinally?: (() => void) | null): Promise<T[]>;
|
|
121
|
+
}
|
|
122
|
+
declare class TableClient<T> {
|
|
123
|
+
private baseUrl;
|
|
124
|
+
private projectId;
|
|
125
|
+
private token;
|
|
126
|
+
private table;
|
|
127
|
+
private getToken;
|
|
128
|
+
private schema?;
|
|
129
|
+
private tableSchema?;
|
|
130
|
+
constructor(baseUrl: string, projectId: string, token: string, table: string, getToken: () => Promise<string>, schema?: DBSchema | undefined);
|
|
131
|
+
private headers;
|
|
132
|
+
private handleRequest;
|
|
133
|
+
private buildQueryParams;
|
|
134
|
+
private addFilterParam;
|
|
135
|
+
executeQuery(options?: QueryOptions): Promise<T[]>;
|
|
136
|
+
getAll(): QueryBuilder<T>;
|
|
137
|
+
get(id: string): Promise<T>;
|
|
138
|
+
create(value: Partial<T>): Promise<T>;
|
|
139
|
+
update(id: string, value: Partial<T>): Promise<T>;
|
|
140
|
+
replace(id: string, value: Partial<T>): Promise<T>;
|
|
141
|
+
delete(id: string): Promise<T>;
|
|
142
|
+
}
|
|
143
|
+
declare class BasicDBSDK<S extends DBSchema> {
|
|
144
|
+
private projectId;
|
|
145
|
+
private getToken;
|
|
146
|
+
private baseUrl;
|
|
147
|
+
private schema;
|
|
148
|
+
private tableNames;
|
|
149
|
+
constructor(config: SDKConfig<S>);
|
|
150
|
+
table<K extends keyof S["tables"] & string>(name: K): TableClient<TableData<S["tables"][K]>>;
|
|
151
|
+
get tables(): {
|
|
152
|
+
[K in keyof S["tables"]]: TableData<S["tables"][K]>;
|
|
153
|
+
};
|
|
154
|
+
fields<K extends keyof S["tables"] & string>(table: K): (keyof S["tables"][K]["fields"] & string)[];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export { BasicDBSDK, BasicProvider, useBasic };
|