edmaxlabs-core 1.1.5 → 1.1.7

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.cts CHANGED
@@ -240,14 +240,11 @@ declare class StorageSnapshot {
240
240
 
241
241
  declare class StorageRef {
242
242
  db: EdmaxLabs;
243
- id: string;
244
- file: StorageSnapshot | undefined | null;
245
- constructor(db: EdmaxLabs, id: string);
246
- get(): Promise<StorageRef | null | undefined>;
247
- upload(srcFile: File): Promise<StorageRef | null | undefined>;
248
- getBaseUrl(): string;
249
- getDownloadUrl(): string;
250
- delete(): Promise<{
243
+ constructor(db: EdmaxLabs);
244
+ get(id: string): Promise<StorageSnapshot | null | undefined>;
245
+ getMeta(id: string): Promise<StorageSnapshot | null | undefined>;
246
+ upload(srcFile: File): Promise<StorageSnapshot | null | undefined>;
247
+ delete(id: string): Promise<{
251
248
  success: boolean;
252
249
  error: string;
253
250
  }>;
@@ -256,7 +253,7 @@ declare class StorageRef {
256
253
  declare class Storage {
257
254
  app: EdmaxLabs;
258
255
  constructor(app: EdmaxLabs);
259
- get(file_id: string): StorageRef;
256
+ getStorage(): StorageRef;
260
257
  }
261
258
 
262
259
  interface EdmaxLabsConfig {
@@ -270,7 +267,6 @@ declare class EdmaxLabs {
270
267
  private socketUrl;
271
268
  private auth;
272
269
  private _db;
273
- private _storage;
274
270
  private _hosting;
275
271
  private realtime;
276
272
  private persistence;
package/dist/index.d.ts CHANGED
@@ -240,14 +240,11 @@ declare class StorageSnapshot {
240
240
 
241
241
  declare class StorageRef {
242
242
  db: EdmaxLabs;
243
- id: string;
244
- file: StorageSnapshot | undefined | null;
245
- constructor(db: EdmaxLabs, id: string);
246
- get(): Promise<StorageRef | null | undefined>;
247
- upload(srcFile: File): Promise<StorageRef | null | undefined>;
248
- getBaseUrl(): string;
249
- getDownloadUrl(): string;
250
- delete(): Promise<{
243
+ constructor(db: EdmaxLabs);
244
+ get(id: string): Promise<StorageSnapshot | null | undefined>;
245
+ getMeta(id: string): Promise<StorageSnapshot | null | undefined>;
246
+ upload(srcFile: File): Promise<StorageSnapshot | null | undefined>;
247
+ delete(id: string): Promise<{
251
248
  success: boolean;
252
249
  error: string;
253
250
  }>;
@@ -256,7 +253,7 @@ declare class StorageRef {
256
253
  declare class Storage {
257
254
  app: EdmaxLabs;
258
255
  constructor(app: EdmaxLabs);
259
- get(file_id: string): StorageRef;
256
+ getStorage(): StorageRef;
260
257
  }
261
258
 
262
259
  interface EdmaxLabsConfig {
@@ -270,7 +267,6 @@ declare class EdmaxLabs {
270
267
  private socketUrl;
271
268
  private auth;
272
269
  private _db;
273
- private _storage;
274
270
  private _hosting;
275
271
  private realtime;
276
272
  private persistence;
package/dist/index.mjs CHANGED
@@ -1452,27 +1452,39 @@ var StorageSnapshot = class _StorageSnapshot {
1452
1452
  // src/storage/StorageRef.ts
1453
1453
  import FormData2 from "form-data";
1454
1454
  var StorageRef = class {
1455
- constructor(db, id) {
1455
+ constructor(db) {
1456
1456
  this.db = db;
1457
- this.id = id;
1458
1457
  }
1459
- async get() {
1458
+ async get(id) {
1460
1459
  const res = await new HttpsRequest({
1461
- method: "POST" /* POST */,
1462
- endpoint: this.db.getBaseUrl + "/storage/file/read",
1460
+ method: "GET" /* GET */,
1461
+ endpoint: this.db.getBaseUrl + `/storage/${id}`,
1463
1462
  headers: {
1464
- authorization: this.db.getAuth.token
1465
- },
1466
- body: {
1467
- file_id: this.id
1463
+ //authorization: this.db.getAuth.token,
1468
1464
  }
1469
1465
  }).sendRequest();
1470
1466
  if (res.success) {
1471
1467
  if (res.document === void 0)
1472
- return this;
1468
+ return void 0;
1473
1469
  const result = StorageSnapshot.fromMap(res.document);
1474
- this.file = result;
1475
- return this;
1470
+ return result;
1471
+ } else {
1472
+ return null;
1473
+ }
1474
+ }
1475
+ async getMeta(id) {
1476
+ const res = await new HttpsRequest({
1477
+ method: "GET" /* GET */,
1478
+ endpoint: this.db.getBaseUrl + `/storage/${id}/info`,
1479
+ headers: {
1480
+ //authorization: this.db.getAuth.token,
1481
+ }
1482
+ }).sendRequest();
1483
+ if (res.success) {
1484
+ if (res.document === void 0)
1485
+ return void 0;
1486
+ const result = StorageSnapshot.fromMap(res.document);
1487
+ return result;
1476
1488
  } else {
1477
1489
  return null;
1478
1490
  }
@@ -1489,34 +1501,18 @@ var StorageRef = class {
1489
1501
  headers: {
1490
1502
  authorization: this.db.getAuth.token,
1491
1503
  ...form.getHeaders()
1492
- },
1493
- body: {
1494
- file_id: this.id
1495
1504
  }
1496
1505
  }).sendRequest();
1497
1506
  if (res.success) {
1498
1507
  if (res.document === void 0)
1499
- return this;
1508
+ return void 0;
1500
1509
  const result = StorageSnapshot.fromMap(res.document);
1501
- this.file = result;
1502
- return this;
1510
+ return result;
1503
1511
  } else {
1504
1512
  return null;
1505
1513
  }
1506
1514
  }
1507
- getBaseUrl() {
1508
- if (this.file) {
1509
- return `https://api.edmaxlabs.com/storage/${this.file.id}`;
1510
- }
1511
- return "";
1512
- }
1513
- getDownloadUrl() {
1514
- if (this.file) {
1515
- return `https://api.edmaxlabs.com/storage/d/${this.file.id}`;
1516
- }
1517
- return "";
1518
- }
1519
- async delete() {
1515
+ async delete(id) {
1520
1516
  const res = await new HttpsRequest({
1521
1517
  method: "POST" /* POST */,
1522
1518
  endpoint: this.db.getBaseUrl + "/storage/file/delete",
@@ -1524,7 +1520,7 @@ var StorageRef = class {
1524
1520
  authorization: this.db.getAuth.token
1525
1521
  },
1526
1522
  body: {
1527
- file_id: this.id
1523
+ file_id: id
1528
1524
  }
1529
1525
  }).sendRequest();
1530
1526
  return res;
@@ -1536,11 +1532,8 @@ var Storage = class {
1536
1532
  constructor(app) {
1537
1533
  this.app = app;
1538
1534
  }
1539
- get(file_id) {
1540
- if (!file_id || file_id === "") {
1541
- throw new Error("File ID is Invalid");
1542
- }
1543
- return new StorageRef(this.app, file_id);
1535
+ getStorage() {
1536
+ return new StorageRef(this.app);
1544
1537
  }
1545
1538
  };
1546
1539
 
@@ -1556,7 +1549,6 @@ var _EdmaxLabs = class _EdmaxLabs {
1556
1549
  this.socketUrl = socketURI;
1557
1550
  this.auth = { token, authToken, project };
1558
1551
  this._db = new Database(this);
1559
- this._storage = new Storage(this);
1560
1552
  this._hosting = new Hosting(this);
1561
1553
  this.realtime = new Realtime(this);
1562
1554
  this.persistence_worker = new CollectionRef(this);
@@ -1588,7 +1580,7 @@ var _EdmaxLabs = class _EdmaxLabs {
1588
1580
  return this._db;
1589
1581
  }
1590
1582
  get storage() {
1591
- return this._storage;
1583
+ return new Storage(this);
1592
1584
  }
1593
1585
  get hosting() {
1594
1586
  return this._hosting;