@blinkdotnew/sdk 0.14.11 → 0.14.13
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/README.md +6 -7
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +15 -10
- package/dist/index.mjs +15 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -201,14 +201,14 @@ const unsubscribe = blink.auth.onAuthStateChanged((state) => {
|
|
|
201
201
|
|
|
202
202
|
**🎉 NEW: Automatic Case Conversion!**
|
|
203
203
|
The SDK now automatically converts between JavaScript camelCase and SQL snake_case:
|
|
204
|
-
- **
|
|
205
|
-
- **
|
|
204
|
+
- **Table names**: `blink.db.emailDrafts` → `email_drafts` table
|
|
205
|
+
- **Field names**: `userId`, `createdAt`, `isCompleted` → `user_id`, `created_at`, `is_completed`
|
|
206
206
|
- **No manual conversion needed!**
|
|
207
207
|
|
|
208
208
|
**⚠️ Important: Always Use camelCase in Your Code**
|
|
209
|
-
- ✅ **Correct**: `{ userId: user.id, createdAt: new Date() }`
|
|
210
|
-
- ❌ **Wrong**: `{ user_id: user.id, created_at: new Date() }`
|
|
211
|
-
|
|
209
|
+
- ✅ **Correct**: `blink.db.emailDrafts.create({ userId: user.id, createdAt: new Date() })`
|
|
210
|
+
- ❌ **Wrong**: `blink.db.email_drafts.create({ user_id: user.id, created_at: new Date() })`
|
|
211
|
+
|
|
212
212
|
|
|
213
213
|
```typescript
|
|
214
214
|
// Create (ID auto-generated if not provided)
|
|
@@ -251,8 +251,7 @@ await blink.db.todos.createMany([
|
|
|
251
251
|
])
|
|
252
252
|
await blink.db.todos.upsertMany([...])
|
|
253
253
|
|
|
254
|
-
|
|
255
|
-
const result = await blink.db.sql('SELECT * FROM todos WHERE user_id = ?', [user.id])
|
|
254
|
+
|
|
256
255
|
```
|
|
257
256
|
|
|
258
257
|
### AI Operations
|
package/dist/index.d.mts
CHANGED
|
@@ -834,6 +834,7 @@ declare class BlinkAuth {
|
|
|
834
834
|
declare class BlinkTable<T = any> implements TableOperations<T> {
|
|
835
835
|
private tableName;
|
|
836
836
|
private httpClient;
|
|
837
|
+
private readonly actualTableName;
|
|
837
838
|
constructor(tableName: string, httpClient: HttpClient);
|
|
838
839
|
/**
|
|
839
840
|
* Create a single record
|
package/dist/index.d.ts
CHANGED
|
@@ -834,6 +834,7 @@ declare class BlinkAuth {
|
|
|
834
834
|
declare class BlinkTable<T = any> implements TableOperations<T> {
|
|
835
835
|
private tableName;
|
|
836
836
|
private httpClient;
|
|
837
|
+
private readonly actualTableName;
|
|
837
838
|
constructor(tableName: string, httpClient: HttpClient);
|
|
838
839
|
/**
|
|
839
840
|
* Create a single record
|
package/dist/index.js
CHANGED
|
@@ -1530,6 +1530,9 @@ var BlinkAuth = class {
|
|
|
1530
1530
|
};
|
|
1531
1531
|
|
|
1532
1532
|
// src/database.ts
|
|
1533
|
+
function camelToSnake3(str) {
|
|
1534
|
+
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
1535
|
+
}
|
|
1533
1536
|
function generateSecureId() {
|
|
1534
1537
|
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
1535
1538
|
const array = new Uint8Array(16);
|
|
@@ -1552,14 +1555,16 @@ var BlinkTable = class {
|
|
|
1552
1555
|
constructor(tableName, httpClient) {
|
|
1553
1556
|
this.tableName = tableName;
|
|
1554
1557
|
this.httpClient = httpClient;
|
|
1558
|
+
this.actualTableName = camelToSnake3(tableName);
|
|
1555
1559
|
}
|
|
1560
|
+
actualTableName;
|
|
1556
1561
|
/**
|
|
1557
1562
|
* Create a single record
|
|
1558
1563
|
*/
|
|
1559
1564
|
async create(data, options = {}) {
|
|
1560
1565
|
const record = ensureRecordId(data);
|
|
1561
1566
|
const response = await this.httpClient.dbPost(
|
|
1562
|
-
this.
|
|
1567
|
+
this.actualTableName,
|
|
1563
1568
|
record,
|
|
1564
1569
|
{ returning: options.returning !== false }
|
|
1565
1570
|
);
|
|
@@ -1575,7 +1580,7 @@ var BlinkTable = class {
|
|
|
1575
1580
|
async createMany(data, options = {}) {
|
|
1576
1581
|
const records = data.map(ensureRecordId);
|
|
1577
1582
|
const response = await this.httpClient.dbPost(
|
|
1578
|
-
this.
|
|
1583
|
+
this.actualTableName,
|
|
1579
1584
|
records,
|
|
1580
1585
|
{ returning: options.returning !== false }
|
|
1581
1586
|
);
|
|
@@ -1595,7 +1600,7 @@ var BlinkTable = class {
|
|
|
1595
1600
|
}
|
|
1596
1601
|
const record = ensureRecordId(data);
|
|
1597
1602
|
const response = await this.httpClient.request(
|
|
1598
|
-
`/api/db/${this.httpClient.projectId}/rest/v1/${this.
|
|
1603
|
+
`/api/db/${this.httpClient.projectId}/rest/v1/${this.actualTableName}?on_conflict=${options.onConflict || "id"}`,
|
|
1599
1604
|
{
|
|
1600
1605
|
method: "POST",
|
|
1601
1606
|
body: record,
|
|
@@ -1621,7 +1626,7 @@ var BlinkTable = class {
|
|
|
1621
1626
|
headers["Prefer"] = `${headers["Prefer"] || ""} resolution=merge-duplicates`.trim();
|
|
1622
1627
|
}
|
|
1623
1628
|
const response = await this.httpClient.request(
|
|
1624
|
-
`/api/db/${this.httpClient.projectId}/rest/v1/${this.
|
|
1629
|
+
`/api/db/${this.httpClient.projectId}/rest/v1/${this.actualTableName}?on_conflict=${options.onConflict || "id"}`,
|
|
1625
1630
|
{
|
|
1626
1631
|
method: "POST",
|
|
1627
1632
|
body: records,
|
|
@@ -1639,7 +1644,7 @@ var BlinkTable = class {
|
|
|
1639
1644
|
id: `eq.${id}`,
|
|
1640
1645
|
limit: "1"
|
|
1641
1646
|
};
|
|
1642
|
-
const response = await this.httpClient.dbGet(this.
|
|
1647
|
+
const response = await this.httpClient.dbGet(this.actualTableName, searchParams);
|
|
1643
1648
|
const records = response.data;
|
|
1644
1649
|
if (records.length === 0) {
|
|
1645
1650
|
return null;
|
|
@@ -1652,7 +1657,7 @@ var BlinkTable = class {
|
|
|
1652
1657
|
async list(options = {}) {
|
|
1653
1658
|
const queryParams = buildQuery(options);
|
|
1654
1659
|
const searchParams = queryParams;
|
|
1655
|
-
const response = await this.httpClient.dbGet(this.
|
|
1660
|
+
const response = await this.httpClient.dbGet(this.actualTableName, searchParams);
|
|
1656
1661
|
const records = response.data;
|
|
1657
1662
|
return records;
|
|
1658
1663
|
}
|
|
@@ -1664,7 +1669,7 @@ var BlinkTable = class {
|
|
|
1664
1669
|
id: `eq.${id}`
|
|
1665
1670
|
};
|
|
1666
1671
|
const response = await this.httpClient.dbPatch(
|
|
1667
|
-
this.
|
|
1672
|
+
this.actualTableName,
|
|
1668
1673
|
data,
|
|
1669
1674
|
searchParams,
|
|
1670
1675
|
{ returning: options.returning !== false }
|
|
@@ -1694,7 +1699,7 @@ var BlinkTable = class {
|
|
|
1694
1699
|
const searchParams = {
|
|
1695
1700
|
id: `eq.${id}`
|
|
1696
1701
|
};
|
|
1697
|
-
await this.httpClient.dbDelete(this.
|
|
1702
|
+
await this.httpClient.dbDelete(this.actualTableName, searchParams);
|
|
1698
1703
|
}
|
|
1699
1704
|
/**
|
|
1700
1705
|
* Delete multiple records based on filter
|
|
@@ -1702,7 +1707,7 @@ var BlinkTable = class {
|
|
|
1702
1707
|
async deleteMany(options) {
|
|
1703
1708
|
const queryParams = buildQuery({ where: options.where });
|
|
1704
1709
|
const searchParams = queryParams;
|
|
1705
|
-
await this.httpClient.dbDelete(this.
|
|
1710
|
+
await this.httpClient.dbDelete(this.actualTableName, searchParams);
|
|
1706
1711
|
}
|
|
1707
1712
|
/**
|
|
1708
1713
|
* Count records matching filter
|
|
@@ -1713,7 +1718,7 @@ var BlinkTable = class {
|
|
|
1713
1718
|
select: ["id"]
|
|
1714
1719
|
});
|
|
1715
1720
|
const response = await this.httpClient.request(
|
|
1716
|
-
`/api/db/${this.httpClient.projectId}/rest/v1/${this.
|
|
1721
|
+
`/api/db/${this.httpClient.projectId}/rest/v1/${this.actualTableName}`,
|
|
1717
1722
|
{
|
|
1718
1723
|
method: "GET",
|
|
1719
1724
|
searchParams: queryParams,
|
package/dist/index.mjs
CHANGED
|
@@ -1528,6 +1528,9 @@ var BlinkAuth = class {
|
|
|
1528
1528
|
};
|
|
1529
1529
|
|
|
1530
1530
|
// src/database.ts
|
|
1531
|
+
function camelToSnake3(str) {
|
|
1532
|
+
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
1533
|
+
}
|
|
1531
1534
|
function generateSecureId() {
|
|
1532
1535
|
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
1533
1536
|
const array = new Uint8Array(16);
|
|
@@ -1550,14 +1553,16 @@ var BlinkTable = class {
|
|
|
1550
1553
|
constructor(tableName, httpClient) {
|
|
1551
1554
|
this.tableName = tableName;
|
|
1552
1555
|
this.httpClient = httpClient;
|
|
1556
|
+
this.actualTableName = camelToSnake3(tableName);
|
|
1553
1557
|
}
|
|
1558
|
+
actualTableName;
|
|
1554
1559
|
/**
|
|
1555
1560
|
* Create a single record
|
|
1556
1561
|
*/
|
|
1557
1562
|
async create(data, options = {}) {
|
|
1558
1563
|
const record = ensureRecordId(data);
|
|
1559
1564
|
const response = await this.httpClient.dbPost(
|
|
1560
|
-
this.
|
|
1565
|
+
this.actualTableName,
|
|
1561
1566
|
record,
|
|
1562
1567
|
{ returning: options.returning !== false }
|
|
1563
1568
|
);
|
|
@@ -1573,7 +1578,7 @@ var BlinkTable = class {
|
|
|
1573
1578
|
async createMany(data, options = {}) {
|
|
1574
1579
|
const records = data.map(ensureRecordId);
|
|
1575
1580
|
const response = await this.httpClient.dbPost(
|
|
1576
|
-
this.
|
|
1581
|
+
this.actualTableName,
|
|
1577
1582
|
records,
|
|
1578
1583
|
{ returning: options.returning !== false }
|
|
1579
1584
|
);
|
|
@@ -1593,7 +1598,7 @@ var BlinkTable = class {
|
|
|
1593
1598
|
}
|
|
1594
1599
|
const record = ensureRecordId(data);
|
|
1595
1600
|
const response = await this.httpClient.request(
|
|
1596
|
-
`/api/db/${this.httpClient.projectId}/rest/v1/${this.
|
|
1601
|
+
`/api/db/${this.httpClient.projectId}/rest/v1/${this.actualTableName}?on_conflict=${options.onConflict || "id"}`,
|
|
1597
1602
|
{
|
|
1598
1603
|
method: "POST",
|
|
1599
1604
|
body: record,
|
|
@@ -1619,7 +1624,7 @@ var BlinkTable = class {
|
|
|
1619
1624
|
headers["Prefer"] = `${headers["Prefer"] || ""} resolution=merge-duplicates`.trim();
|
|
1620
1625
|
}
|
|
1621
1626
|
const response = await this.httpClient.request(
|
|
1622
|
-
`/api/db/${this.httpClient.projectId}/rest/v1/${this.
|
|
1627
|
+
`/api/db/${this.httpClient.projectId}/rest/v1/${this.actualTableName}?on_conflict=${options.onConflict || "id"}`,
|
|
1623
1628
|
{
|
|
1624
1629
|
method: "POST",
|
|
1625
1630
|
body: records,
|
|
@@ -1637,7 +1642,7 @@ var BlinkTable = class {
|
|
|
1637
1642
|
id: `eq.${id}`,
|
|
1638
1643
|
limit: "1"
|
|
1639
1644
|
};
|
|
1640
|
-
const response = await this.httpClient.dbGet(this.
|
|
1645
|
+
const response = await this.httpClient.dbGet(this.actualTableName, searchParams);
|
|
1641
1646
|
const records = response.data;
|
|
1642
1647
|
if (records.length === 0) {
|
|
1643
1648
|
return null;
|
|
@@ -1650,7 +1655,7 @@ var BlinkTable = class {
|
|
|
1650
1655
|
async list(options = {}) {
|
|
1651
1656
|
const queryParams = buildQuery(options);
|
|
1652
1657
|
const searchParams = queryParams;
|
|
1653
|
-
const response = await this.httpClient.dbGet(this.
|
|
1658
|
+
const response = await this.httpClient.dbGet(this.actualTableName, searchParams);
|
|
1654
1659
|
const records = response.data;
|
|
1655
1660
|
return records;
|
|
1656
1661
|
}
|
|
@@ -1662,7 +1667,7 @@ var BlinkTable = class {
|
|
|
1662
1667
|
id: `eq.${id}`
|
|
1663
1668
|
};
|
|
1664
1669
|
const response = await this.httpClient.dbPatch(
|
|
1665
|
-
this.
|
|
1670
|
+
this.actualTableName,
|
|
1666
1671
|
data,
|
|
1667
1672
|
searchParams,
|
|
1668
1673
|
{ returning: options.returning !== false }
|
|
@@ -1692,7 +1697,7 @@ var BlinkTable = class {
|
|
|
1692
1697
|
const searchParams = {
|
|
1693
1698
|
id: `eq.${id}`
|
|
1694
1699
|
};
|
|
1695
|
-
await this.httpClient.dbDelete(this.
|
|
1700
|
+
await this.httpClient.dbDelete(this.actualTableName, searchParams);
|
|
1696
1701
|
}
|
|
1697
1702
|
/**
|
|
1698
1703
|
* Delete multiple records based on filter
|
|
@@ -1700,7 +1705,7 @@ var BlinkTable = class {
|
|
|
1700
1705
|
async deleteMany(options) {
|
|
1701
1706
|
const queryParams = buildQuery({ where: options.where });
|
|
1702
1707
|
const searchParams = queryParams;
|
|
1703
|
-
await this.httpClient.dbDelete(this.
|
|
1708
|
+
await this.httpClient.dbDelete(this.actualTableName, searchParams);
|
|
1704
1709
|
}
|
|
1705
1710
|
/**
|
|
1706
1711
|
* Count records matching filter
|
|
@@ -1711,7 +1716,7 @@ var BlinkTable = class {
|
|
|
1711
1716
|
select: ["id"]
|
|
1712
1717
|
});
|
|
1713
1718
|
const response = await this.httpClient.request(
|
|
1714
|
-
`/api/db/${this.httpClient.projectId}/rest/v1/${this.
|
|
1719
|
+
`/api/db/${this.httpClient.projectId}/rest/v1/${this.actualTableName}`,
|
|
1715
1720
|
{
|
|
1716
1721
|
method: "GET",
|
|
1717
1722
|
searchParams: queryParams,
|
package/package.json
CHANGED