nexabase-console 1.0.2 → 1.0.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/dist/index.d.ts CHANGED
@@ -22,33 +22,33 @@ export interface QueryConstraint {
22
22
  directionStr?: 'asc' | 'desc';
23
23
  limitValue?: number;
24
24
  }
25
- export interface DocumentReference {
25
+ export interface DocumentReference<T = any> {
26
26
  type: 'document';
27
27
  path: string;
28
28
  db: NexaApp;
29
29
  }
30
- export interface CollectionReference {
30
+ export interface CollectionReference<T = any> {
31
31
  type: 'collection';
32
32
  path: string;
33
33
  db: NexaApp;
34
34
  }
35
- export interface Query {
35
+ export interface Query<T = any> {
36
36
  type: 'query' | 'collection';
37
37
  path: string;
38
38
  db: NexaApp;
39
39
  constraints?: QueryConstraint[];
40
40
  }
41
- export interface DocumentSnapshot {
41
+ export interface DocumentSnapshot<T = any> {
42
42
  exists: () => boolean;
43
- data: () => any | null;
43
+ data: () => T | null;
44
44
  }
45
- export interface QueryDocumentSnapshot {
45
+ export interface QueryDocumentSnapshot<T = any> {
46
46
  id: string;
47
- data: () => any;
47
+ data: () => T;
48
48
  }
49
- export interface QuerySnapshot {
50
- docs: QueryDocumentSnapshot[];
51
- forEach: (callback: (doc: QueryDocumentSnapshot) => void) => void;
49
+ export interface QuerySnapshot<T = any> {
50
+ docs: QueryDocumentSnapshot<T>[];
51
+ forEach: (callback: (doc: QueryDocumentSnapshot<T>) => void) => void;
52
52
  empty: boolean;
53
53
  size: number;
54
54
  docChanges?: () => any[];
@@ -59,10 +59,16 @@ export interface DatabaseReference {
59
59
  onDataChanged: (callback: (data: any) => void) => void;
60
60
  }
61
61
  export interface StorageReference {
62
- put: (file: File | Blob) => Promise<{
62
+ name: string;
63
+ fullPath: string;
64
+ put: (file: File | Blob, onProgress?: (percent: number) => void) => Promise<{
63
65
  url: string;
64
66
  success: boolean;
65
67
  }>;
68
+ delete: () => Promise<{
69
+ success: boolean;
70
+ message?: string;
71
+ }>;
66
72
  }
67
73
  export interface WriteBatch {
68
74
  set: (docRef: DocumentReference, data: any) => WriteBatch;
@@ -111,6 +117,7 @@ export declare class NexaApp {
111
117
  };
112
118
  storage(): {
113
119
  ref: (path?: string) => StorageReference;
120
+ refFromURL: (url: string) => StorageReference;
114
121
  };
115
122
  _initFirestoreState(): Promise<void>;
116
123
  _getOfflineQueue(): Promise<OfflineJob[]>;
@@ -124,14 +131,14 @@ export declare class NexaApp {
124
131
  }
125
132
  export declare const initializeApp: (config: NexaConfig) => NexaApp;
126
133
  export declare const getFirestore: (app: NexaApp) => NexaApp;
127
- export declare const collection: (db: NexaApp, collectionPath: string) => CollectionReference;
128
- export declare const doc: (dbOrCollection: NexaApp | CollectionReference, ...pathSegments: string[]) => DocumentReference;
129
- export declare const query: (queryObject: Query | CollectionReference, ...queryConstraints: QueryConstraint[]) => Query;
134
+ export declare const collection: <T = any>(db: NexaApp, collectionPath: string) => CollectionReference<T>;
135
+ export declare const doc: <T = any>(dbOrCollection: NexaApp | CollectionReference<any>, ...pathSegments: string[]) => DocumentReference<T>;
136
+ export declare const query: <T = any>(queryObject: Query<T> | CollectionReference<T>, ...queryConstraints: QueryConstraint[]) => Query<T>;
130
137
  export declare const where: (fieldPath: string, opStr: "==" | ">" | "<" | ">=" | "<=" | "!=", value: any) => QueryConstraint;
131
138
  export declare const orderBy: (fieldPath: string, directionStr?: "asc" | "desc") => QueryConstraint;
132
139
  export declare const limit: (limitValue: number) => QueryConstraint;
133
- export declare const getDocs: (queryOrCollection: Query | CollectionReference) => Promise<QuerySnapshot>;
134
- export declare const getDoc: (docRef: DocumentReference) => Promise<DocumentSnapshot>;
140
+ export declare const getDocs: <T = any>(queryOrCollection: Query<T> | CollectionReference<T>) => Promise<QuerySnapshot<T>>;
141
+ export declare const getDoc: <T = any>(docRef: DocumentReference<T>) => Promise<DocumentSnapshot<T>>;
135
142
  export declare const setDoc: (docRef: DocumentReference, data: any) => Promise<any>;
136
143
  export declare const updateDoc: (docRef: DocumentReference, data: any) => Promise<any>;
137
144
  export declare const deleteDoc: (docRef: DocumentReference) => Promise<any>;
package/dist/index.js CHANGED
@@ -151,14 +151,38 @@ class NexaApp {
151
151
  // -----------------------------------------------------------------
152
152
  storage() {
153
153
  return {
154
- ref: (path = '') => ({
155
- put: async (file) => {
156
- const formData = new FormData();
157
- formData.append('file', file);
158
- const response = await this.client.post(`/api/project/${this.projectId}/storage/upload`, formData);
159
- return response.data;
160
- }
161
- })
154
+ ref: (path = '') => {
155
+ const name = path.substring(path.lastIndexOf('/') + 1) || path;
156
+ return {
157
+ name,
158
+ fullPath: path,
159
+ put: async (file, onProgress) => {
160
+ const formData = new FormData();
161
+ formData.append('file', file);
162
+ const response = await this.client.post(`/api/project/${this.projectId}/storage/upload`, formData, {
163
+ headers: {
164
+ 'Content-Type': 'multipart/form-data'
165
+ },
166
+ onUploadProgress: (progressEvent) => {
167
+ if (onProgress && progressEvent.total) {
168
+ const percent = Math.round((progressEvent.loaded * 100) / progressEvent.total);
169
+ onProgress(percent);
170
+ }
171
+ }
172
+ });
173
+ return response.data;
174
+ },
175
+ delete: async () => {
176
+ const response = await this.client.delete(`/api/project/${this.projectId}/storage/${encodeURIComponent(name)}`);
177
+ return response.data;
178
+ }
179
+ };
180
+ },
181
+ refFromURL: (url) => {
182
+ const cleanUrl = url.split('?')[0];
183
+ const filename = decodeURIComponent(cleanUrl.substring(cleanUrl.lastIndexOf('/') + 1));
184
+ return this.storage().ref(filename);
185
+ }
162
186
  };
163
187
  }
164
188
  // -----------------------------------------------------------------
@@ -476,7 +500,7 @@ const getDoc = async (docRef) => {
476
500
  throw err;
477
501
  }
478
502
  const data = db._firestoreCache[docRef.path];
479
- return { exists: () => !!data, data: () => data || null };
503
+ return { exists: () => !!data, data: () => (data || null) };
480
504
  }
481
505
  };
482
506
  exports.getDoc = getDoc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexabase-console",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "SDK Client resmi untuk NexaBase: Platform Sinkronisasi NoSQL, Realtime, File Storage, & Autentikasi Offline-First.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",