@spica-devkit/bucket 0.18.9 → 0.18.11-pre1

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/dist/index.d.ts CHANGED
@@ -1 +1,126 @@
1
- export * from "./src/index";
1
+ import { JSONSchema7, JSONSchema7TypeName } from 'json-schema';
2
+ import { Observable } from 'rxjs';
3
+
4
+ interface SuccessResponse<P, R = P> {
5
+ request: P;
6
+ response: R;
7
+ }
8
+ interface FailureResponse<P> {
9
+ request: P;
10
+ response: {
11
+ message: string;
12
+ error: string;
13
+ };
14
+ }
15
+ interface ManyResponse<P, R> {
16
+ successes: SuccessResponse<P, R>[];
17
+ failures: FailureResponse<P>[];
18
+ }
19
+
20
+ interface Bucket {
21
+ _id?: string;
22
+ title: string;
23
+ icon?: string;
24
+ description: string;
25
+ primary: string;
26
+ history?: boolean;
27
+ properties: {
28
+ [key: string]: JSONSchema7 & PropertyOptions;
29
+ };
30
+ order?: number;
31
+ }
32
+ interface PropertyOptions {
33
+ type: JSONSchema7TypeName | JSONSchema7TypeName[] | string;
34
+ options: {
35
+ translate?: boolean;
36
+ history?: boolean;
37
+ };
38
+ }
39
+ interface BucketDocument {
40
+ _id?: string;
41
+ [key: string]: any | undefined;
42
+ }
43
+ type RealtimeConnection<T> = Observable<T> & {
44
+ insert: (document: Omit<Singular<T>, "_id">) => void;
45
+ replace: (document: Singular<T> & {
46
+ _id: string;
47
+ }) => void;
48
+ patch: (document: Partial<Singular<T>> & {
49
+ _id: string;
50
+ }) => void;
51
+ remove: (document: Partial<Singular<T>> & {
52
+ _id: string;
53
+ }) => void;
54
+ };
55
+ type RealtimeConnectionOne<T> = Observable<T> & {
56
+ replace: (document: Omit<Singular<T>, "_id">) => void;
57
+ patch: (document: Omit<Partial<Singular<T>>, "_id">) => void;
58
+ remove: () => void;
59
+ };
60
+ type Singular<T> = T extends Array<any> ? T[0] : T;
61
+
62
+ interface PublicInitialization {
63
+ publicUrl?: string;
64
+ }
65
+ interface ApikeyInitialization extends PublicInitialization {
66
+ apikey: string;
67
+ }
68
+ interface IdentityInitialization extends PublicInitialization {
69
+ identity: string;
70
+ }
71
+ interface IndexResult<T> {
72
+ meta: {
73
+ total: number;
74
+ };
75
+ data: T[];
76
+ }
77
+
78
+ declare function initialize(options: ApikeyInitialization | IdentityInitialization): void;
79
+ declare function get(id: string, headers?: object): Promise<Bucket>;
80
+ declare function getAll(headers?: object): Promise<Bucket[]>;
81
+ declare function insert(bucket: Bucket, headers?: object): Promise<Bucket>;
82
+ declare function insertMany(buckets: Bucket[], headers?: object): Promise<ManyResponse<Bucket, Bucket>>;
83
+ declare function update(id: string, bucket: Bucket, headers?: object): Promise<Bucket>;
84
+ declare function remove(id: string, headers?: object): Promise<any>;
85
+ declare function removeMany(ids: string[], headers?: object): Promise<ManyResponse<string, string>>;
86
+ declare namespace data {
87
+ function get<T>(bucketId: string, documentId: string, options?: {
88
+ headers?: object;
89
+ queryParams?: {
90
+ [key: string]: any;
91
+ };
92
+ }): Promise<T>;
93
+ function getAll<T>(bucketId: string, options?: {
94
+ headers?: object;
95
+ queryParams?: {
96
+ [key: string]: any;
97
+ paginate?: false;
98
+ };
99
+ }): Promise<T[]>;
100
+ function getAll<T>(bucketId: string, options?: {
101
+ headers?: object;
102
+ queryParams?: {
103
+ [key: string]: any;
104
+ paginate?: true;
105
+ };
106
+ }): Promise<IndexResult<T>>;
107
+ function insert<T>(bucketId: string, document: Omit<T, "_id">, headers?: object): Promise<T>;
108
+ function insertMany<T>(bucketId: string, documents: T[], headers?: object): Promise<ManyResponse<T, T>>;
109
+ function update<T>(bucketId: string, documentId: string, document: T, headers?: object): Promise<T>;
110
+ function patch(bucketId: string, documentId: string, document: Partial<BucketDocument>, headers?: object): Promise<any>;
111
+ function remove(bucketId: string, documentId: string, headers?: object): Promise<any>;
112
+ function removeMany(bucketId: string, documentIds: string[], headers?: object): Promise<ManyResponse<string, string>>;
113
+ namespace realtime {
114
+ function get<T>(bucketId: string, documentId: string, messageCallback?: (res: {
115
+ status: number;
116
+ message: string;
117
+ }) => any, queryParams?: object): RealtimeConnectionOne<T>;
118
+ function getAll<T>(bucketId: string, queryParams?: object, messageCallback?: (res: {
119
+ status: number;
120
+ message: string;
121
+ }) => any): RealtimeConnection<T[]>;
122
+ }
123
+ }
124
+
125
+ export { data, get, getAll, initialize, insert, insertMany, remove, removeMany, update };
126
+ export type { Bucket, BucketDocument, RealtimeConnection, RealtimeConnectionOne };