@@ -7750,13 +7750,18 @@ function removeSymbols(input) {
77507750/**
77517751 * Converts the argument into a number.
77527752 */
7753- function toNumber (input) {
7753+ function toPrimaryKey (input) {
77547754 if (input === null)
77557755 return 0;
7756- if (typeof input === "string" && input.startsWith("$uid")) {
7756+ if (typeof input === "string" && ( input.startsWith("$uid") || isGuid(input) )) {
77577757 return input;
77587758 }
77597759 return parseInt(input.toString(), 10);
7760+ }
7761+ function isGuid(value) {
7762+ var regex = /[a-f0-9]{8}(?:-?[a-f0-9]{4}){3}-?[a-f0-9]{12}/i;
7763+ var match = regex.exec(value);
7764+ return match != null;
77607765}
77617766
77627767/**
@@ -7894,8 +7899,8 @@ var Model = /** @class */ (function () {
78947899 this.mocks = {};
78957900 this.baseModel = baseModel;
78967901 // Generate name variants
7897- this.singularName = singularize(this.baseModel.entity);
7898- this.pluralName = pluralize$1(this.baseModel.entity);
7902+ this.singularName = this.baseModel["singularName"] || singularize(this.baseModel.entity);
7903+ this.pluralName = this.baseModel["pluralName"] || pluralize$1(this.baseModel.entity);
78997904 // Cache the fields of the model in this.fields
79007905 var fields = this.baseModel.fields();
79017906 Object.keys(fields).forEach(function (name) {
@@ -8075,7 +8080,7 @@ var Model = /** @class */ (function () {
80758080 return this.baseModel
80768081 .query()
80778082 .withAllRecursive()
8078- .where("id", toNumber (id))
8083+ .where("id", toPrimaryKey (id))
80798084 .first();
80808085 };
80818086 /**
@@ -15376,7 +15381,7 @@ var Action = /** @class */ (function () {
1537615381 if (!(name !== context.adapter.getNameForDestroy(model))) return [3 /*break*/, 4];
1537715382 newData = newData[Object.keys(newData)[0]];
1537815383 // IDs as String cause terrible issues, so we convert them to integers.
15379- newData.id = toNumber (newData.id);
15384+ newData.id = toPrimaryKey (newData.id);
1538015385 return [4 /*yield*/, Store.insertData((_a = {}, _a[model.pluralName] = newData, _a), dispatch)];
1538115386 case 3:
1538215387 insertedData = _b.sent();
@@ -15469,7 +15474,7 @@ var Destroy = /** @class */ (function (_super) {
1546915474 record.$destroy = function () {
1547015475 return __awaiter(this, void 0, void 0, function () {
1547115476 return __generator(this, function (_a) {
15472- return [2 /*return*/, this.$dispatch("destroy", { id: toNumber (this.$id) })];
15477+ return [2 /*return*/, this.$dispatch("destroy", { id: toPrimaryKey (this.$id) })];
1547315478 });
1547415479 });
1547515480 };
@@ -15626,7 +15631,7 @@ var Mutate = /** @class */ (function (_super) {
1562615631 return __generator(this, function (_b) {
1562715632 args = args || {};
1562815633 if (!args["id"])
15629- args["id"] = toNumber (this.$id);
15634+ args["id"] = toPrimaryKey (this.$id);
1563015635 return [2 /*return*/, this.$dispatch("mutate", { name: name, args: args, multiple: multiple })];
1563115636 });
1563215637 });
@@ -15719,7 +15724,7 @@ var Persist = /** @class */ (function (_super) {
1571915724 mutationName = Context.getInstance().adapter.getNameForPersist(model);
1572015725 oldRecord = model.getRecordWithId(id);
1572115726 mockReturnValue = model.$mockHook("persist", {
15722- id: toNumber (id),
15727+ id: toPrimaryKey (id),
1572315728 args: args || {}
1572415729 });
1572515730 if (!mockReturnValue) return [3 /*break*/, 3];
@@ -15874,7 +15879,7 @@ var Query = /** @class */ (function (_super) {
1587415879 return __generator(this, function (_b) {
1587515880 filter = filter || {};
1587615881 if (!filter["id"])
15877- filter["id"] = toNumber (this.$id);
15882+ filter["id"] = toPrimaryKey (this.$id);
1587815883 return [2 /*return*/, this.$dispatch("query", { name: name, filter: filter, multiple: multiple, bypassCache: bypassCache })];
1587915884 });
1588015885 });
@@ -16159,6 +16164,7 @@ function mock(action, options) {
1615916164
1616016165exports.DefaultAdapter = DefaultAdapter;
1616116166exports.Mock = Mock;
16167+ exports.Model = Model;
1616216168exports.clearORMStore = clearORMStore;
1616316169exports.default = VuexORMGraphQLPlugin;
1616416170exports.mock = mock;
0 commit comments