bun-query-builder 0.1.39 → 0.1.41
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 +36 -10
- package/dist/src/index.js +35 -9
- package/package.json +1 -1
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,12 @@ 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
|
|
24644
|
-
|
|
24662
|
+
const attr = findAttributeDef(attrs, key);
|
|
24663
|
+
const isImplicitForeignKey = !attr && toSnakeCase(key).endsWith("_id");
|
|
24664
|
+
if (attr?.fillable && !attr?.guarded || isImplicitForeignKey) {
|
|
24645
24665
|
if (this._original === null)
|
|
24646
24666
|
this._original = { ...this._attributes };
|
|
24647
|
-
this._attributes[key] = value;
|
|
24667
|
+
this._attributes[toSnakeCase(key)] = value;
|
|
24648
24668
|
}
|
|
24649
24669
|
}
|
|
24650
24670
|
return this;
|
|
@@ -24652,7 +24672,7 @@ class ModelInstance {
|
|
|
24652
24672
|
forceFill(data) {
|
|
24653
24673
|
if (this._original === null)
|
|
24654
24674
|
this._original = { ...this._attributes };
|
|
24655
|
-
Object.assign(this._attributes, data);
|
|
24675
|
+
Object.assign(this._attributes, normalizeAttributeKeys(data));
|
|
24656
24676
|
return this;
|
|
24657
24677
|
}
|
|
24658
24678
|
async save() {
|
|
@@ -24686,7 +24706,13 @@ class ModelInstance {
|
|
|
24686
24706
|
for (const [key, attr] of Object.entries(attrs)) {
|
|
24687
24707
|
if (attr.guarded)
|
|
24688
24708
|
continue;
|
|
24689
|
-
|
|
24709
|
+
const col = toSnakeCase(key);
|
|
24710
|
+
if (this._attributes[col] !== undefined) {
|
|
24711
|
+
data[col] = this._attributes[col];
|
|
24712
|
+
}
|
|
24713
|
+
}
|
|
24714
|
+
for (const key of Object.keys(this._attributes)) {
|
|
24715
|
+
if (key.endsWith("_id") && key !== pk && !(key in data)) {
|
|
24690
24716
|
data[key] = this._attributes[key];
|
|
24691
24717
|
}
|
|
24692
24718
|
}
|
|
@@ -30748,7 +30774,7 @@ function getPrefix() {
|
|
|
30748
30774
|
}
|
|
30749
30775
|
var prefix = getPrefix();
|
|
30750
30776
|
// package.json
|
|
30751
|
-
var version2 = "0.1.
|
|
30777
|
+
var version2 = "0.1.41";
|
|
30752
30778
|
|
|
30753
30779
|
// bin/cli.ts
|
|
30754
30780
|
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,12 @@ 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
|
|
24644
|
-
|
|
24662
|
+
const attr = findAttributeDef(attrs, key);
|
|
24663
|
+
const isImplicitForeignKey = !attr && toSnakeCase(key).endsWith("_id");
|
|
24664
|
+
if (attr?.fillable && !attr?.guarded || isImplicitForeignKey) {
|
|
24645
24665
|
if (this._original === null)
|
|
24646
24666
|
this._original = { ...this._attributes };
|
|
24647
|
-
this._attributes[key] = value;
|
|
24667
|
+
this._attributes[toSnakeCase(key)] = value;
|
|
24648
24668
|
}
|
|
24649
24669
|
}
|
|
24650
24670
|
return this;
|
|
@@ -24652,7 +24672,7 @@ class ModelInstance {
|
|
|
24652
24672
|
forceFill(data) {
|
|
24653
24673
|
if (this._original === null)
|
|
24654
24674
|
this._original = { ...this._attributes };
|
|
24655
|
-
Object.assign(this._attributes, data);
|
|
24675
|
+
Object.assign(this._attributes, normalizeAttributeKeys(data));
|
|
24656
24676
|
return this;
|
|
24657
24677
|
}
|
|
24658
24678
|
async save() {
|
|
@@ -24686,7 +24706,13 @@ class ModelInstance {
|
|
|
24686
24706
|
for (const [key, attr] of Object.entries(attrs)) {
|
|
24687
24707
|
if (attr.guarded)
|
|
24688
24708
|
continue;
|
|
24689
|
-
|
|
24709
|
+
const col = toSnakeCase(key);
|
|
24710
|
+
if (this._attributes[col] !== undefined) {
|
|
24711
|
+
data[col] = this._attributes[col];
|
|
24712
|
+
}
|
|
24713
|
+
}
|
|
24714
|
+
for (const key of Object.keys(this._attributes)) {
|
|
24715
|
+
if (key.endsWith("_id") && key !== pk && !(key in data)) {
|
|
24690
24716
|
data[key] = this._attributes[key];
|
|
24691
24717
|
}
|
|
24692
24718
|
}
|
package/package.json
CHANGED