bun-query-builder 0.1.39 → 0.1.40

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/bin/cli.js CHANGED
@@ -24517,6 +24517,25 @@ function collectBelongsToManyKeys(definition) {
24517
24517
  btmKeysCache.set(definition, keys);
24518
24518
  return keys;
24519
24519
  }
24520
+ function normalizeAttributeKeys(data) {
24521
+ const result = {};
24522
+ for (const [key, value] of Object.entries(data)) {
24523
+ result[toSnakeCase(key)] = value;
24524
+ }
24525
+ return result;
24526
+ }
24527
+ function findAttributeDef(attrs, key) {
24528
+ if (attrs[key])
24529
+ return attrs[key];
24530
+ const snake = toSnakeCase(key);
24531
+ if (attrs[snake])
24532
+ return attrs[snake];
24533
+ for (const k2 of Object.keys(attrs)) {
24534
+ if (toSnakeCase(k2) === snake)
24535
+ return attrs[k2];
24536
+ }
24537
+ return;
24538
+ }
24520
24539
 
24521
24540
  class ModelInstance {
24522
24541
  _attributes;
@@ -24526,7 +24545,7 @@ class ModelInstance {
24526
24545
  _relations = {};
24527
24546
  constructor(definition, attributes = {}) {
24528
24547
  this._definition = definition;
24529
- this._attributes = { ...attributes };
24548
+ this._attributes = normalizeAttributeKeys({ ...attributes });
24530
24549
  this._original = null;
24531
24550
  const btmKeys = collectBelongsToManyKeys(definition);
24532
24551
  if (btmKeys.size === 0)
@@ -24566,10 +24585,10 @@ class ModelInstance {
24566
24585
  return v2;
24567
24586
  } catch {}
24568
24587
  }
24569
- return this._attributes[key];
24588
+ return this._attributes[toSnakeCase(key)];
24570
24589
  }
24571
24590
  getAttribute(key) {
24572
- return this._attributes[key];
24591
+ return this._attributes[toSnakeCase(key)];
24573
24592
  }
24574
24593
  getAttributes() {
24575
24594
  return { ...this._attributes };
@@ -24577,7 +24596,7 @@ class ModelInstance {
24577
24596
  set(key, value) {
24578
24597
  if (this._original === null)
24579
24598
  this._original = { ...this._attributes };
24580
- this._attributes[key] = value;
24599
+ this._attributes[toSnakeCase(key)] = value;
24581
24600
  }
24582
24601
  only(keys) {
24583
24602
  const out = {};
@@ -24640,11 +24659,11 @@ class ModelInstance {
24640
24659
  fill(data) {
24641
24660
  const attrs = this._definition.attributes;
24642
24661
  for (const [key, value] of Object.entries(data)) {
24643
- const attr = attrs[key];
24662
+ const attr = findAttributeDef(attrs, key);
24644
24663
  if (attr?.fillable && !attr?.guarded) {
24645
24664
  if (this._original === null)
24646
24665
  this._original = { ...this._attributes };
24647
- this._attributes[key] = value;
24666
+ this._attributes[toSnakeCase(key)] = value;
24648
24667
  }
24649
24668
  }
24650
24669
  return this;
@@ -24652,7 +24671,7 @@ class ModelInstance {
24652
24671
  forceFill(data) {
24653
24672
  if (this._original === null)
24654
24673
  this._original = { ...this._attributes };
24655
- Object.assign(this._attributes, data);
24674
+ Object.assign(this._attributes, normalizeAttributeKeys(data));
24656
24675
  return this;
24657
24676
  }
24658
24677
  async save() {
@@ -24686,8 +24705,9 @@ class ModelInstance {
24686
24705
  for (const [key, attr] of Object.entries(attrs)) {
24687
24706
  if (attr.guarded)
24688
24707
  continue;
24689
- if (this._attributes[key] !== undefined) {
24690
- data[key] = this._attributes[key];
24708
+ const col = toSnakeCase(key);
24709
+ if (this._attributes[col] !== undefined) {
24710
+ data[col] = this._attributes[col];
24691
24711
  }
24692
24712
  }
24693
24713
  if (timestampsEnabled(this._definition)) {
@@ -30748,7 +30768,7 @@ function getPrefix() {
30748
30768
  }
30749
30769
  var prefix = getPrefix();
30750
30770
  // package.json
30751
- var version2 = "0.1.39";
30771
+ var version2 = "0.1.40";
30752
30772
 
30753
30773
  // bin/cli.ts
30754
30774
  init_actions();
package/dist/src/index.js CHANGED
@@ -24517,6 +24517,25 @@ function collectBelongsToManyKeys(definition) {
24517
24517
  btmKeysCache.set(definition, keys);
24518
24518
  return keys;
24519
24519
  }
24520
+ function normalizeAttributeKeys(data) {
24521
+ const result = {};
24522
+ for (const [key, value] of Object.entries(data)) {
24523
+ result[toSnakeCase(key)] = value;
24524
+ }
24525
+ return result;
24526
+ }
24527
+ function findAttributeDef(attrs, key) {
24528
+ if (attrs[key])
24529
+ return attrs[key];
24530
+ const snake = toSnakeCase(key);
24531
+ if (attrs[snake])
24532
+ return attrs[snake];
24533
+ for (const k2 of Object.keys(attrs)) {
24534
+ if (toSnakeCase(k2) === snake)
24535
+ return attrs[k2];
24536
+ }
24537
+ return;
24538
+ }
24520
24539
 
24521
24540
  class ModelInstance {
24522
24541
  _attributes;
@@ -24526,7 +24545,7 @@ class ModelInstance {
24526
24545
  _relations = {};
24527
24546
  constructor(definition, attributes = {}) {
24528
24547
  this._definition = definition;
24529
- this._attributes = { ...attributes };
24548
+ this._attributes = normalizeAttributeKeys({ ...attributes });
24530
24549
  this._original = null;
24531
24550
  const btmKeys = collectBelongsToManyKeys(definition);
24532
24551
  if (btmKeys.size === 0)
@@ -24566,10 +24585,10 @@ class ModelInstance {
24566
24585
  return v2;
24567
24586
  } catch {}
24568
24587
  }
24569
- return this._attributes[key];
24588
+ return this._attributes[toSnakeCase(key)];
24570
24589
  }
24571
24590
  getAttribute(key) {
24572
- return this._attributes[key];
24591
+ return this._attributes[toSnakeCase(key)];
24573
24592
  }
24574
24593
  getAttributes() {
24575
24594
  return { ...this._attributes };
@@ -24577,7 +24596,7 @@ class ModelInstance {
24577
24596
  set(key, value) {
24578
24597
  if (this._original === null)
24579
24598
  this._original = { ...this._attributes };
24580
- this._attributes[key] = value;
24599
+ this._attributes[toSnakeCase(key)] = value;
24581
24600
  }
24582
24601
  only(keys) {
24583
24602
  const out = {};
@@ -24640,11 +24659,11 @@ class ModelInstance {
24640
24659
  fill(data) {
24641
24660
  const attrs = this._definition.attributes;
24642
24661
  for (const [key, value] of Object.entries(data)) {
24643
- const attr = attrs[key];
24662
+ const attr = findAttributeDef(attrs, key);
24644
24663
  if (attr?.fillable && !attr?.guarded) {
24645
24664
  if (this._original === null)
24646
24665
  this._original = { ...this._attributes };
24647
- this._attributes[key] = value;
24666
+ this._attributes[toSnakeCase(key)] = value;
24648
24667
  }
24649
24668
  }
24650
24669
  return this;
@@ -24652,7 +24671,7 @@ class ModelInstance {
24652
24671
  forceFill(data) {
24653
24672
  if (this._original === null)
24654
24673
  this._original = { ...this._attributes };
24655
- Object.assign(this._attributes, data);
24674
+ Object.assign(this._attributes, normalizeAttributeKeys(data));
24656
24675
  return this;
24657
24676
  }
24658
24677
  async save() {
@@ -24686,8 +24705,9 @@ class ModelInstance {
24686
24705
  for (const [key, attr] of Object.entries(attrs)) {
24687
24706
  if (attr.guarded)
24688
24707
  continue;
24689
- if (this._attributes[key] !== undefined) {
24690
- data[key] = this._attributes[key];
24708
+ const col = toSnakeCase(key);
24709
+ if (this._attributes[col] !== undefined) {
24710
+ data[col] = this._attributes[col];
24691
24711
  }
24692
24712
  }
24693
24713
  if (timestampsEnabled(this._definition)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-query-builder",
3
3
  "type": "module",
4
- "version": "0.1.39",
4
+ "version": "0.1.40",
5
5
  "description": "A simple yet performant query builder for TypeScript. Built with Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",