@e22m4u/js-repository-mongodb-adapter 0.1.0 → 0.1.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e22m4u/js-repository-mongodb-adapter",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "MongoDB адаптер для @e22m4u/js-repository",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@e22m4u/js-format": "*",
|
|
40
40
|
"@e22m4u/js-service": "*",
|
|
41
|
-
"@e22m4u/js-repository": "~0.1.
|
|
41
|
+
"@e22m4u/js-repository": "~0.1.2"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@commitlint/cli": "^18.4.3",
|
package/src/mongodb-adapter.js
CHANGED
|
@@ -601,7 +601,7 @@ export class MongodbAdapter extends Adapter {
|
|
|
601
601
|
async create(modelName, modelData, filter = undefined) {
|
|
602
602
|
const idPropName = this._getIdPropName(modelName);
|
|
603
603
|
const idValue = modelData[idPropName];
|
|
604
|
-
if (idValue == null || idValue === '') {
|
|
604
|
+
if (idValue == null || idValue === '' || idValue === 0) {
|
|
605
605
|
const pkType = this._getIdType(modelName);
|
|
606
606
|
if (pkType !== DataType.STRING && pkType !== DataType.ANY)
|
|
607
607
|
throw new InvalidArgumentError(
|
|
@@ -662,7 +662,7 @@ export class MongodbAdapter extends Adapter {
|
|
|
662
662
|
const idPropName = this._getIdPropName(modelName);
|
|
663
663
|
let idValue = modelData[idPropName];
|
|
664
664
|
idValue = this._coerceId(idValue);
|
|
665
|
-
if (idValue == null || idValue === '') {
|
|
665
|
+
if (idValue == null || idValue === '' || idValue === 0) {
|
|
666
666
|
const pkType = this._getIdType(modelName);
|
|
667
667
|
if (pkType !== DataType.STRING && pkType !== DataType.ANY)
|
|
668
668
|
throw new InvalidArgumentError(
|
|
@@ -1093,6 +1093,16 @@ describe('MongodbAdapter', function () {
|
|
|
1093
1093
|
expect(result[DEF_PK]).to.have.lengthOf(24);
|
|
1094
1094
|
});
|
|
1095
1095
|
|
|
1096
|
+
it('generates a new identifier when a value of a primary key is zero', async function () {
|
|
1097
|
+
const schema = createSchema();
|
|
1098
|
+
schema.defineModel({name: 'model', datasource: 'mongodb'});
|
|
1099
|
+
const rep = schema.getRepository('model');
|
|
1100
|
+
const result = await rep.create({[DEF_PK]: 0, foo: 'bar'});
|
|
1101
|
+
expect(result).to.be.eql({[DEF_PK]: result[DEF_PK], foo: 'bar'});
|
|
1102
|
+
expect(typeof result[DEF_PK]).to.be.eq('string');
|
|
1103
|
+
expect(result[DEF_PK]).to.have.lengthOf(24);
|
|
1104
|
+
});
|
|
1105
|
+
|
|
1096
1106
|
it('generates a new identifier for a primary key of a "string" type', async function () {
|
|
1097
1107
|
const schema = createSchema();
|
|
1098
1108
|
schema.defineModel({
|
|
@@ -2031,6 +2041,16 @@ describe('MongodbAdapter', function () {
|
|
|
2031
2041
|
expect(result[DEF_PK]).to.have.lengthOf(24);
|
|
2032
2042
|
});
|
|
2033
2043
|
|
|
2044
|
+
it('generates a new identifier when a value of a primary key is zero', async function () {
|
|
2045
|
+
const schema = createSchema();
|
|
2046
|
+
schema.defineModel({name: 'model', datasource: 'mongodb'});
|
|
2047
|
+
const rep = schema.getRepository('model');
|
|
2048
|
+
const result = await rep.replaceOrCreate({[DEF_PK]: 0, foo: 'bar'});
|
|
2049
|
+
expect(result).to.be.eql({[DEF_PK]: result[DEF_PK], foo: 'bar'});
|
|
2050
|
+
expect(typeof result[DEF_PK]).to.be.eq('string');
|
|
2051
|
+
expect(result[DEF_PK]).to.have.lengthOf(24);
|
|
2052
|
+
});
|
|
2053
|
+
|
|
2034
2054
|
it('generates a new identifier for a primary key of a "string" type', async function () {
|
|
2035
2055
|
const schema = createSchema();
|
|
2036
2056
|
schema.defineModel({
|