@workglow/storage 0.0.58 → 0.0.60

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/bun.js CHANGED
@@ -1520,13 +1520,31 @@ class SqliteTabularRepository extends BaseSqlTabularRepository {
1520
1520
  return this.db;
1521
1521
  }
1522
1522
  jsToSqlValue(column, value) {
1523
+ if (value !== null && value !== undefined && typeof value === "object") {
1524
+ if (value instanceof Date) {
1525
+ return super.jsToSqlValue(column, value);
1526
+ }
1527
+ if (value instanceof Uint8Array) {
1528
+ return super.jsToSqlValue(column, value);
1529
+ }
1530
+ if (typeof Buffer !== "undefined" && value instanceof Buffer) {
1531
+ return super.jsToSqlValue(column, value);
1532
+ }
1533
+ return JSON.stringify(value);
1534
+ }
1535
+ if (value === null) {
1536
+ const typeDef2 = this.schema.properties[column];
1537
+ if (typeDef2 && this.isNullable(typeDef2)) {
1538
+ return null;
1539
+ }
1540
+ }
1523
1541
  const typeDef = this.schema.properties[column];
1524
1542
  if (typeDef) {
1525
1543
  const actualType = this.getNonNullType(typeDef);
1526
- if (typeof actualType !== "boolean" && actualType.type === "boolean") {
1527
- if (value === null && this.isNullable(typeDef)) {
1528
- return null;
1529
- }
1544
+ const isObject = typeDef === true || typeof actualType !== "boolean" && actualType.type === "object";
1545
+ const isArray = typeDef === true || typeof actualType !== "boolean" && actualType.type === "array";
1546
+ const isBoolean = typeDef === true || typeof actualType !== "boolean" && actualType.type === "boolean";
1547
+ if (isBoolean) {
1530
1548
  const v = value;
1531
1549
  if (typeof v === "boolean")
1532
1550
  return v ? 1 : 0;
@@ -1535,8 +1553,22 @@ class SqliteTabularRepository extends BaseSqlTabularRepository {
1535
1553
  if (typeof v === "string")
1536
1554
  return v === "1" || v.toLowerCase() === "true" ? 1 : 0;
1537
1555
  }
1556
+ if ((isObject || isArray) && value !== null && typeof value === "object") {
1557
+ if (!(value instanceof Date) && !(value instanceof Uint8Array) && (typeof Buffer === "undefined" || !(value instanceof Buffer))) {
1558
+ if (Array.isArray(value) || Object.getPrototypeOf(value) === Object.prototype) {
1559
+ return JSON.stringify(value);
1560
+ }
1561
+ }
1562
+ }
1563
+ }
1564
+ const result = super.jsToSqlValue(column, value);
1565
+ if (result !== null && typeof result === "object") {
1566
+ const resultObj = result;
1567
+ if (!(resultObj instanceof Uint8Array) && (typeof Buffer === "undefined" || !(resultObj instanceof Buffer))) {
1568
+ return JSON.stringify(resultObj);
1569
+ }
1538
1570
  }
1539
- return super.jsToSqlValue(column, value);
1571
+ return result;
1540
1572
  }
1541
1573
  sqlToJsValue(column, value) {
1542
1574
  const typeDef = this.schema.properties[column];
@@ -1545,14 +1577,27 @@ class SqliteTabularRepository extends BaseSqlTabularRepository {
1545
1577
  return null;
1546
1578
  }
1547
1579
  const actualType = this.getNonNullType(typeDef);
1548
- if (typeof actualType !== "boolean" && actualType.type === "boolean") {
1580
+ const isObject = typeDef === true || typeof actualType !== "boolean" && actualType.type === "object";
1581
+ const isArray = typeDef === true || typeof actualType !== "boolean" && actualType.type === "array";
1582
+ const isBoolean = typeDef === true || typeof actualType !== "boolean" && actualType.type === "boolean";
1583
+ if (isBoolean) {
1549
1584
  const v = value;
1550
1585
  if (typeof v === "boolean")
1551
1586
  return v;
1552
1587
  if (typeof v === "number")
1553
- return v !== 0;
1588
+ return v !== 0 ? true : false;
1554
1589
  if (typeof v === "string")
1555
- return v === "1" || v.toLowerCase() === "true";
1590
+ return v === "1" || v.toLowerCase() === "true" ? true : false;
1591
+ }
1592
+ if (isArray || isObject) {
1593
+ if (typeof value === "string") {
1594
+ try {
1595
+ return JSON.parse(value);
1596
+ } catch (e) {
1597
+ return value;
1598
+ }
1599
+ }
1600
+ return value;
1556
1601
  }
1557
1602
  }
1558
1603
  return super.sqlToJsValue(column, value);
@@ -1604,6 +1649,50 @@ class SqliteTabularRepository extends BaseSqlTabularRepository {
1604
1649
  const primaryKeyParams = this.getPrimaryKeyAsOrderedArray(key);
1605
1650
  const valueParams = this.getValueAsOrderedArray(value);
1606
1651
  const params = [...primaryKeyParams, ...valueParams];
1652
+ for (let i = 0;i < params.length; i++) {
1653
+ let param = params[i];
1654
+ if (param === undefined) {
1655
+ params[i] = null;
1656
+ continue;
1657
+ }
1658
+ if (param !== null && typeof param === "object") {
1659
+ const paramObj = param;
1660
+ if (paramObj instanceof Uint8Array) {
1661
+ continue;
1662
+ }
1663
+ if (typeof Buffer !== "undefined" && paramObj instanceof Buffer) {
1664
+ params[i] = new Uint8Array(paramObj);
1665
+ continue;
1666
+ }
1667
+ try {
1668
+ params[i] = JSON.stringify(paramObj);
1669
+ } catch (e) {
1670
+ throw new Error(`Failed to stringify param at index ${i} for column binding: ${String(e)}`);
1671
+ }
1672
+ continue;
1673
+ }
1674
+ }
1675
+ const invalidParams = [];
1676
+ for (let i = 0;i < params.length; i++) {
1677
+ const param = params[i];
1678
+ if (param === null || param === undefined || typeof param === "string" || typeof param === "number" || typeof param === "boolean" || typeof param === "bigint") {
1679
+ continue;
1680
+ }
1681
+ if (typeof param === "object") {
1682
+ const paramObj = param;
1683
+ if (paramObj instanceof Uint8Array || typeof Buffer !== "undefined" && paramObj instanceof Buffer) {
1684
+ continue;
1685
+ }
1686
+ invalidParams.push({ index: i, type: typeof param, value: param });
1687
+ } else {
1688
+ invalidParams.push({ index: i, type: typeof param, value: param });
1689
+ }
1690
+ }
1691
+ if (invalidParams.length > 0) {
1692
+ console.error("Invalid params detected:", invalidParams);
1693
+ console.error("All params:", params.map((p, i) => ({ i, type: typeof p, value: p, isArray: Array.isArray(p) })));
1694
+ throw new Error(`Invalid SQLite params detected at indices: ${invalidParams.map((p) => p.index).join(", ")}`);
1695
+ }
1607
1696
  const updatedEntity = stmt.get(...params);
1608
1697
  for (const k in this.schema.properties) {
1609
1698
  updatedEntity[k] = this.sqlToJsValue(k, updatedEntity[k]);
@@ -1631,6 +1720,17 @@ class SqliteTabularRepository extends BaseSqlTabularRepository {
1631
1720
  const primaryKeyParams = this.getPrimaryKeyAsOrderedArray(key);
1632
1721
  const valueParams = this.getValueAsOrderedArray(value);
1633
1722
  const params = [...primaryKeyParams, ...valueParams];
1723
+ for (let i = 0;i < params.length; i++) {
1724
+ let param = params[i];
1725
+ if (param === undefined) {
1726
+ params[i] = null;
1727
+ } else if (param !== null && typeof param === "object") {
1728
+ const paramObj = param;
1729
+ if (!(paramObj instanceof Uint8Array) && (typeof Buffer === "undefined" || !(paramObj instanceof Buffer))) {
1730
+ params[i] = JSON.stringify(paramObj);
1731
+ }
1732
+ }
1733
+ }
1634
1734
  const updatedEntity = stmt.get(...params);
1635
1735
  for (const k in this.schema.properties) {
1636
1736
  updatedEntity[k] = this.sqlToJsValue(k, updatedEntity[k]);
@@ -5642,4 +5742,4 @@ export {
5642
5742
  CACHED_TABULAR_REPOSITORY
5643
5743
  };
5644
5744
 
5645
- //# debugId=DBE095F06C6029D864756E2164756E21
5745
+ //# debugId=69EE3CC6572AC11564756E2164756E21