@basictech/react 0.7.0-beta.2 → 0.7.0-beta.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/.turbo/turbo-build.log +10 -10
- package/AUTH_IMPLEMENTATION_GUIDE.md +2009 -0
- package/changelog.md +12 -0
- package/dist/index.d.mts +19 -113
- package/dist/index.d.ts +19 -113
- package/dist/index.js +62 -387
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -386
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/AuthContext.tsx +82 -18
- package/src/index.ts +4 -4
- package/src/utils/storage.ts +1 -0
package/changelog.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -7,7 +7,24 @@ interface BasicStorage {
|
|
|
7
7
|
set(key: string, value: string): Promise<void>;
|
|
8
8
|
remove(key: string): Promise<void>;
|
|
9
9
|
}
|
|
10
|
+
declare class LocalStorageAdapter implements BasicStorage {
|
|
11
|
+
get(key: string): Promise<string | null>;
|
|
12
|
+
set(key: string, value: string): Promise<void>;
|
|
13
|
+
remove(key: string): Promise<void>;
|
|
14
|
+
}
|
|
10
15
|
|
|
16
|
+
type AuthConfig = {
|
|
17
|
+
scopes?: string | string[];
|
|
18
|
+
server_url?: string;
|
|
19
|
+
};
|
|
20
|
+
type BasicProviderProps = {
|
|
21
|
+
children: React.ReactNode;
|
|
22
|
+
project_id?: string;
|
|
23
|
+
schema?: any;
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
storage?: BasicStorage;
|
|
26
|
+
auth?: AuthConfig;
|
|
27
|
+
};
|
|
11
28
|
declare enum DBStatus {
|
|
12
29
|
LOADING = "LOADING",
|
|
13
30
|
OFFLINE = "OFFLINE",
|
|
@@ -25,13 +42,7 @@ type User = {
|
|
|
25
42
|
};
|
|
26
43
|
fullName?: string;
|
|
27
44
|
};
|
|
28
|
-
declare function BasicProvider({ children, project_id, schema, debug, storage }:
|
|
29
|
-
children: React.ReactNode;
|
|
30
|
-
project_id?: string;
|
|
31
|
-
schema?: any;
|
|
32
|
-
debug?: boolean;
|
|
33
|
-
storage?: BasicStorage;
|
|
34
|
-
}): react_jsx_runtime.JSX.Element;
|
|
45
|
+
declare function BasicProvider({ children, project_id, schema, debug, storage, auth }: BasicProviderProps): react_jsx_runtime.JSX.Element;
|
|
35
46
|
declare function useBasic(): {
|
|
36
47
|
unicorn: string;
|
|
37
48
|
isAuthReady: boolean;
|
|
@@ -46,112 +57,7 @@ declare function useBasic(): {
|
|
|
46
57
|
getToken: () => Promise<string>;
|
|
47
58
|
getSignInLink: (redirectUri?: string) => Promise<string>;
|
|
48
59
|
db: any;
|
|
49
|
-
remoteDb: any;
|
|
50
60
|
dbStatus: DBStatus;
|
|
51
61
|
};
|
|
52
62
|
|
|
53
|
-
|
|
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 };
|
|
63
|
+
export { AuthConfig, BasicProvider, BasicProviderProps, BasicStorage, LocalStorageAdapter, useBasic };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,24 @@ interface BasicStorage {
|
|
|
7
7
|
set(key: string, value: string): Promise<void>;
|
|
8
8
|
remove(key: string): Promise<void>;
|
|
9
9
|
}
|
|
10
|
+
declare class LocalStorageAdapter implements BasicStorage {
|
|
11
|
+
get(key: string): Promise<string | null>;
|
|
12
|
+
set(key: string, value: string): Promise<void>;
|
|
13
|
+
remove(key: string): Promise<void>;
|
|
14
|
+
}
|
|
10
15
|
|
|
16
|
+
type AuthConfig = {
|
|
17
|
+
scopes?: string | string[];
|
|
18
|
+
server_url?: string;
|
|
19
|
+
};
|
|
20
|
+
type BasicProviderProps = {
|
|
21
|
+
children: React.ReactNode;
|
|
22
|
+
project_id?: string;
|
|
23
|
+
schema?: any;
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
storage?: BasicStorage;
|
|
26
|
+
auth?: AuthConfig;
|
|
27
|
+
};
|
|
11
28
|
declare enum DBStatus {
|
|
12
29
|
LOADING = "LOADING",
|
|
13
30
|
OFFLINE = "OFFLINE",
|
|
@@ -25,13 +42,7 @@ type User = {
|
|
|
25
42
|
};
|
|
26
43
|
fullName?: string;
|
|
27
44
|
};
|
|
28
|
-
declare function BasicProvider({ children, project_id, schema, debug, storage }:
|
|
29
|
-
children: React.ReactNode;
|
|
30
|
-
project_id?: string;
|
|
31
|
-
schema?: any;
|
|
32
|
-
debug?: boolean;
|
|
33
|
-
storage?: BasicStorage;
|
|
34
|
-
}): react_jsx_runtime.JSX.Element;
|
|
45
|
+
declare function BasicProvider({ children, project_id, schema, debug, storage, auth }: BasicProviderProps): react_jsx_runtime.JSX.Element;
|
|
35
46
|
declare function useBasic(): {
|
|
36
47
|
unicorn: string;
|
|
37
48
|
isAuthReady: boolean;
|
|
@@ -46,112 +57,7 @@ declare function useBasic(): {
|
|
|
46
57
|
getToken: () => Promise<string>;
|
|
47
58
|
getSignInLink: (redirectUri?: string) => Promise<string>;
|
|
48
59
|
db: any;
|
|
49
|
-
remoteDb: any;
|
|
50
60
|
dbStatus: DBStatus;
|
|
51
61
|
};
|
|
52
62
|
|
|
53
|
-
|
|
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 };
|
|
63
|
+
export { AuthConfig, BasicProvider, BasicProviderProps, BasicStorage, LocalStorageAdapter, useBasic };
|