Skip to content

Commit 50d0bb6

Browse files
committed
Fix ids
1 parent 72fa4b3 commit 50d0bb6

28 files changed

+306
-233
lines changed

Diff for: dist/actions/destroy.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default class Destroy extends Action {
77
/**
88
* @param {State} state The Vuex state
99
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
10-
* @param {string} id ID of the record to delete
10+
* @param {number} id ID of the record to delete
1111
* @returns {Promise<any>} true
1212
*/
1313
static call({ state, dispatch }: ActionParams, { id, args }: ActionParams): Promise<boolean>;

Diff for: dist/actions/persist.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default class Persist extends Action {
77
/**
88
* @param {any} state The Vuex state
99
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
10-
* @param {string} id ID of the record to persist
10+
* @param {number|string} id ID of the record to persist
1111
* @returns {Promise<Data>} The saved record
1212
*/
1313
static call({ state, dispatch }: ActionParams, { id, args }: ActionParams): Promise<Data>;

Diff for: dist/orm/model.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ export default class Model {
9494
isTypeFieldOfPolymorphicRelation(name: string): boolean;
9595
/**
9696
* Returns a record of this model with the given ID.
97-
* @param {string} id
97+
* @param {number|string} id
9898
* @returns {any}
9999
*/
100-
getRecordWithId(id: string): import("@vuex-orm/core").Item<PatchedModel>;
100+
getRecordWithId(id: number | string): import("@vuex-orm/core").Item<PatchedModel>;
101101
/**
102102
* Determines if we should eager load (means: add as a field in the graphql query) a related entity. belongsTo,
103103
* hasOne and morphOne related entities are always eager loaded. Others can be added to the `eagerLoad` array

Diff for: dist/support/utils.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ export declare function clone(input: any): any;
5252
export declare function takeWhile(array: Array<any>, predicate: (x: any, idx: number, array: Array<any>) => any): any[];
5353
export declare function matches(source: any): (object: any) => boolean;
5454
export declare function removeSymbols(input: any): any;
55+
/**
56+
* Converts the argument into a number.
57+
*/
58+
export declare function toNumber(input: string | number | null): number | string;

Diff for: dist/vuex-orm-graphql.cjs.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -7746,6 +7746,17 @@ function takeWhile(array, predicate) {
77467746
}
77477747
function removeSymbols(input) {
77487748
return JSON.parse(JSON.stringify(input));
7749+
}
7750+
/**
7751+
* Converts the argument into a number.
7752+
*/
7753+
function toNumber(input) {
7754+
if (input === null)
7755+
return 0;
7756+
if (typeof input === "string" && input.startsWith("$uid")) {
7757+
return input;
7758+
}
7759+
return parseInt(input.toString(), 10);
77497760
}
77507761

77517762
/**
@@ -7901,8 +7912,8 @@ var Model = /** @class */ (function () {
79017912
if (!field)
79027913
return false;
79037914
var context = Context.getInstance();
7904-
// Remove UID cause it must be a string
7905-
return field instanceof context.components.Number;
7915+
return field instanceof context.components.Number ||
7916+
field instanceof context.components.Uid;
79067917
};
79077918
/**
79087919
* Tells if a field is a attribute (and thus not a relation)
@@ -8058,14 +8069,14 @@ var Model = /** @class */ (function () {
80588069
};
80598070
/**
80608071
* Returns a record of this model with the given ID.
8061-
* @param {string} id
8072+
* @param {number|string} id
80628073
* @returns {any}
80638074
*/
80648075
Model.prototype.getRecordWithId = function (id) {
80658076
return this.baseModel
80668077
.query()
80678078
.withAllRecursive()
8068-
.where("id", id)
8079+
.where("id", toNumber(id))
80698080
.first();
80708081
};
80718082
/**
@@ -15338,7 +15349,7 @@ var Action = /** @class */ (function () {
1533815349
if (!(name !== context.adapter.getNameForDestroy(model))) return [3 /*break*/, 4];
1533915350
newData = newData[Object.keys(newData)[0]];
1534015351
// IDs as String cause terrible issues, so we convert them to integers.
15341-
newData.id = parseInt(newData.id, 10);
15352+
newData.id = toNumber(newData.id);
1534215353
return [4 /*yield*/, Store.insertData((_a = {}, _a[model.pluralName] = newData, _a), dispatch)];
1534315354
case 3:
1534415355
insertedData = _b.sent();
@@ -15423,7 +15434,7 @@ var Destroy = /** @class */ (function (_super) {
1542315434
/**
1542415435
* @param {State} state The Vuex state
1542515436
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
15426-
* @param {string} id ID of the record to delete
15437+
* @param {number} id ID of the record to delete
1542715438
* @returns {Promise<any>} true
1542815439
*/
1542915440
Destroy.call = function (_a, _b) {
@@ -15575,7 +15586,7 @@ var Persist = /** @class */ (function (_super) {
1557515586
/**
1557615587
* @param {any} state The Vuex state
1557715588
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
15578-
* @param {string} id ID of the record to persist
15589+
* @param {number|string} id ID of the record to persist
1557915590
* @returns {Promise<Data>} The saved record
1558015591
*/
1558115592
Persist.call = function (_a, _b) {
@@ -15591,7 +15602,7 @@ var Persist = /** @class */ (function (_super) {
1559115602
mutationName = Context.getInstance().adapter.getNameForPersist(model);
1559215603
oldRecord = model.getRecordWithId(id);
1559315604
mockReturnValue = model.$mockHook("persist", {
15594-
id: id,
15605+
id: toNumber(id),
1559515606
args: args || {}
1559615607
});
1559715608
if (!mockReturnValue) return [3 /*break*/, 3];
@@ -15922,7 +15933,7 @@ var VuexORMGraphQL = /** @class */ (function () {
1592215933
return __generator(this, function (_b) {
1592315934
args = args || {};
1592415935
if (!args["id"])
15925-
args["id"] = this.$id;
15936+
args["id"] = toNumber(this.$id);
1592615937
return [2 /*return*/, this.$dispatch("mutate", { name: name, args: args, multiple: multiple })];
1592715938
});
1592815939
});
@@ -15933,7 +15944,7 @@ var VuexORMGraphQL = /** @class */ (function () {
1593315944
return __generator(this, function (_b) {
1593415945
filter = filter || {};
1593515946
if (!filter["id"])
15936-
filter["id"] = this.$id;
15947+
filter["id"] = toNumber(this.$id);
1593715948
return [2 /*return*/, this.$dispatch("query", { name: name, filter: filter, multiple: multiple, bypassCache: bypassCache })];
1593815949
});
1593915950
});
@@ -15955,7 +15966,7 @@ var VuexORMGraphQL = /** @class */ (function () {
1595515966
model.$destroy = function () {
1595615967
return __awaiter(this, void 0, void 0, function () {
1595715968
return __generator(this, function (_a) {
15958-
return [2 /*return*/, this.$dispatch("destroy", { id: this.$id })];
15969+
return [2 /*return*/, this.$dispatch("destroy", { id: toNumber(this.$id) })];
1595915970
});
1596015971
});
1596115972
};

Diff for: dist/vuex-orm-graphql.esm-bundler.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -7644,6 +7644,17 @@ function takeWhile(array, predicate) {
76447644
}
76457645
function removeSymbols(input) {
76467646
return JSON.parse(JSON.stringify(input));
7647+
}
7648+
/**
7649+
* Converts the argument into a number.
7650+
*/
7651+
function toNumber(input) {
7652+
if (input === null)
7653+
return 0;
7654+
if (typeof input === "string" && input.startsWith("$uid")) {
7655+
return input;
7656+
}
7657+
return parseInt(input.toString(), 10);
76477658
}
76487659

76497660
/**
@@ -7785,8 +7796,8 @@ class Model {
77857796
if (!field)
77867797
return false;
77877798
const context = Context.getInstance();
7788-
// Remove UID cause it must be a string
7789-
return field instanceof context.components.Number;
7799+
return field instanceof context.components.Number ||
7800+
field instanceof context.components.Uid;
77907801
}
77917802
/**
77927803
* Tells if a field is a attribute (and thus not a relation)
@@ -7940,14 +7951,14 @@ class Model {
79407951
}
79417952
/**
79427953
* Returns a record of this model with the given ID.
7943-
* @param {string} id
7954+
* @param {number|string} id
79447955
* @returns {any}
79457956
*/
79467957
getRecordWithId(id) {
79477958
return this.baseModel
79487959
.query()
79497960
.withAllRecursive()
7950-
.where("id", id)
7961+
.where("id", toNumber(id))
79517962
.first();
79527963
}
79537964
/**
@@ -15315,7 +15326,7 @@ class Action {
1531515326
if (name !== context.adapter.getNameForDestroy(model)) {
1531615327
newData = newData[Object.keys(newData)[0]];
1531715328
// IDs as String cause terrible issues, so we convert them to integers.
15318-
newData.id = parseInt(newData.id, 10);
15329+
newData.id = toNumber(newData.id);
1531915330
const insertedData = await Store.insertData({ [model.pluralName]: newData }, dispatch);
1532015331
// Try to find the record to return
1532115332
const records = insertedData[model.pluralName];
@@ -15392,7 +15403,7 @@ class Destroy extends Action {
1539215403
/**
1539315404
* @param {State} state The Vuex state
1539415405
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
15395-
* @param {string} id ID of the record to delete
15406+
* @param {number} id ID of the record to delete
1539615407
* @returns {Promise<any>} true
1539715408
*/
1539815409
static async call({ state, dispatch }, { id, args }) {
@@ -15497,7 +15508,7 @@ class Persist extends Action {
1549715508
/**
1549815509
* @param {any} state The Vuex state
1549915510
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
15500-
* @param {string} id ID of the record to persist
15511+
* @param {number|string} id ID of the record to persist
1550115512
* @returns {Promise<Data>} The saved record
1550215513
*/
1550315514
static async call({ state, dispatch }, { id, args }) {
@@ -15506,7 +15517,7 @@ class Persist extends Action {
1550615517
const mutationName = Context.getInstance().adapter.getNameForPersist(model);
1550715518
const oldRecord = model.getRecordWithId(id);
1550815519
const mockReturnValue = model.$mockHook("persist", {
15509-
id,
15520+
id: toNumber(id),
1551015521
args: args || {}
1551115522
});
1551215523
if (mockReturnValue) {
@@ -15749,13 +15760,13 @@ class VuexORMGraphQL {
1574915760
model.$mutate = async function ({ name, args, multiple }) {
1575015761
args = args || {};
1575115762
if (!args["id"])
15752-
args["id"] = this.$id;
15763+
args["id"] = toNumber(this.$id);
1575315764
return this.$dispatch("mutate", { name, args, multiple });
1575415765
};
1575515766
model.$customQuery = async function ({ name, filter, multiple, bypassCache }) {
1575615767
filter = filter || {};
1575715768
if (!filter["id"])
15758-
filter["id"] = this.$id;
15769+
filter["id"] = toNumber(this.$id);
1575915770
return this.$dispatch("query", { name, filter, multiple, bypassCache });
1576015771
};
1576115772
model.$persist = async function (args) {
@@ -15765,7 +15776,7 @@ class VuexORMGraphQL {
1576515776
return this.$dispatch("push", { data: this, args });
1576615777
};
1576715778
model.$destroy = async function () {
15768-
return this.$dispatch("destroy", { id: this.$id });
15779+
return this.$dispatch("destroy", { id: toNumber(this.$id) });
1576915780
};
1577015781
model.$deleteAndDestroy = async function () {
1577115782
await this.$delete();

Diff for: dist/vuex-orm-graphql.esm.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -7644,6 +7644,17 @@ function takeWhile(array, predicate) {
76447644
}
76457645
function removeSymbols(input) {
76467646
return JSON.parse(JSON.stringify(input));
7647+
}
7648+
/**
7649+
* Converts the argument into a number.
7650+
*/
7651+
function toNumber(input) {
7652+
if (input === null)
7653+
return 0;
7654+
if (typeof input === "string" && input.startsWith("$uid")) {
7655+
return input;
7656+
}
7657+
return parseInt(input.toString(), 10);
76477658
}
76487659

76497660
/**
@@ -7785,8 +7796,8 @@ class Model {
77857796
if (!field)
77867797
return false;
77877798
const context = Context.getInstance();
7788-
// Remove UID cause it must be a string
7789-
return field instanceof context.components.Number;
7799+
return field instanceof context.components.Number ||
7800+
field instanceof context.components.Uid;
77907801
}
77917802
/**
77927803
* Tells if a field is a attribute (and thus not a relation)
@@ -7940,14 +7951,14 @@ class Model {
79407951
}
79417952
/**
79427953
* Returns a record of this model with the given ID.
7943-
* @param {string} id
7954+
* @param {number|string} id
79447955
* @returns {any}
79457956
*/
79467957
getRecordWithId(id) {
79477958
return this.baseModel
79487959
.query()
79497960
.withAllRecursive()
7950-
.where("id", id)
7961+
.where("id", toNumber(id))
79517962
.first();
79527963
}
79537964
/**
@@ -15315,7 +15326,7 @@ class Action {
1531515326
if (name !== context.adapter.getNameForDestroy(model)) {
1531615327
newData = newData[Object.keys(newData)[0]];
1531715328
// IDs as String cause terrible issues, so we convert them to integers.
15318-
newData.id = parseInt(newData.id, 10);
15329+
newData.id = toNumber(newData.id);
1531915330
const insertedData = await Store.insertData({ [model.pluralName]: newData }, dispatch);
1532015331
// Try to find the record to return
1532115332
const records = insertedData[model.pluralName];
@@ -15392,7 +15403,7 @@ class Destroy extends Action {
1539215403
/**
1539315404
* @param {State} state The Vuex state
1539415405
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
15395-
* @param {string} id ID of the record to delete
15406+
* @param {number} id ID of the record to delete
1539615407
* @returns {Promise<any>} true
1539715408
*/
1539815409
static async call({ state, dispatch }, { id, args }) {
@@ -15497,7 +15508,7 @@ class Persist extends Action {
1549715508
/**
1549815509
* @param {any} state The Vuex state
1549915510
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
15500-
* @param {string} id ID of the record to persist
15511+
* @param {number|string} id ID of the record to persist
1550115512
* @returns {Promise<Data>} The saved record
1550215513
*/
1550315514
static async call({ state, dispatch }, { id, args }) {
@@ -15506,7 +15517,7 @@ class Persist extends Action {
1550615517
const mutationName = Context.getInstance().adapter.getNameForPersist(model);
1550715518
const oldRecord = model.getRecordWithId(id);
1550815519
const mockReturnValue = model.$mockHook("persist", {
15509-
id,
15520+
id: toNumber(id),
1551015521
args: args || {}
1551115522
});
1551215523
if (mockReturnValue) {
@@ -15749,13 +15760,13 @@ class VuexORMGraphQL {
1574915760
model.$mutate = async function ({ name, args, multiple }) {
1575015761
args = args || {};
1575115762
if (!args["id"])
15752-
args["id"] = this.$id;
15763+
args["id"] = toNumber(this.$id);
1575315764
return this.$dispatch("mutate", { name, args, multiple });
1575415765
};
1575515766
model.$customQuery = async function ({ name, filter, multiple, bypassCache }) {
1575615767
filter = filter || {};
1575715768
if (!filter["id"])
15758-
filter["id"] = this.$id;
15769+
filter["id"] = toNumber(this.$id);
1575915770
return this.$dispatch("query", { name, filter, multiple, bypassCache });
1576015771
};
1576115772
model.$persist = async function (args) {
@@ -15765,7 +15776,7 @@ class VuexORMGraphQL {
1576515776
return this.$dispatch("push", { data: this, args });
1576615777
};
1576715778
model.$destroy = async function () {
15768-
return this.$dispatch("destroy", { id: this.$id });
15779+
return this.$dispatch("destroy", { id: toNumber(this.$id) });
1576915780
};
1577015781
model.$deleteAndDestroy = async function () {
1577115782
await this.$delete();

0 commit comments

Comments
 (0)