@bedrockio/model 0.18.6 → 0.19.0
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/CHANGELOG.md +4 -0
- package/README.md +1 -3
- package/dist/cjs/clone.js +3 -4
- package/package.json +1 -1
- package/src/clone.js +3 -5
- package/types/schema.d.ts +0 -1
- package/types/schema.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1785,9 +1785,7 @@ shop.name; // Now "My New Shop"
|
|
|
1785
1785
|
|
|
1786
1786
|
### Clone
|
|
1787
1787
|
|
|
1788
|
-
Adds a single `clone` method on documents
|
|
1789
|
-
testing that will immediately create a copy of the document. It makes up for
|
|
1790
|
-
some of the shortcomings of the Mongoose `$clone` method:
|
|
1788
|
+
Adds a single `clone` method on documents that makes up for some of the shortcomings of the Mongoose `$clone` method:
|
|
1791
1789
|
|
|
1792
1790
|
- A new `id` will be generated.
|
|
1793
1791
|
- Populated and self-referencing documents are handled.
|
package/dist/cjs/clone.js
CHANGED
|
@@ -13,11 +13,11 @@ exports.applyClone = applyClone;
|
|
|
13
13
|
// - Cannot deal with unique fields.
|
|
14
14
|
//
|
|
15
15
|
function applyClone(schema) {
|
|
16
|
-
schema.method('clone',
|
|
17
|
-
return
|
|
16
|
+
schema.method('clone', function clone() {
|
|
17
|
+
return cloneDocument(this);
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
function cloneDocument(doc) {
|
|
21
21
|
const Model = doc.constructor;
|
|
22
22
|
const clone = new Model();
|
|
23
23
|
for (let [key, typedef] of Object.entries(Model.schema.obj)) {
|
|
@@ -31,7 +31,6 @@ async function cloneDocument(doc) {
|
|
|
31
31
|
}
|
|
32
32
|
clone.set(key, value);
|
|
33
33
|
}
|
|
34
|
-
await clone.save();
|
|
35
34
|
return clone;
|
|
36
35
|
}
|
|
37
36
|
let counter = 1;
|
package/package.json
CHANGED
package/src/clone.js
CHANGED
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
// - Cannot deal with unique fields.
|
|
8
8
|
//
|
|
9
9
|
export function applyClone(schema) {
|
|
10
|
-
schema.method('clone',
|
|
11
|
-
return
|
|
10
|
+
schema.method('clone', function clone() {
|
|
11
|
+
return cloneDocument(this);
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
function cloneDocument(doc) {
|
|
16
16
|
const Model = doc.constructor;
|
|
17
17
|
const clone = new Model();
|
|
18
18
|
|
|
@@ -26,8 +26,6 @@ async function cloneDocument(doc) {
|
|
|
26
26
|
clone.set(key, value);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
await clone.save();
|
|
30
|
-
|
|
31
29
|
return clone;
|
|
32
30
|
}
|
|
33
31
|
|
package/types/schema.d.ts
CHANGED
|
@@ -19,7 +19,6 @@ export function createSchema(definition: object, options?: mongoose.SchemaOption
|
|
|
19
19
|
};
|
|
20
20
|
collation?: mongoose.mongo.CollationOptions;
|
|
21
21
|
collectionOptions?: mongoose.mongo.CreateCollectionOptions;
|
|
22
|
-
lean?: boolean | mongoose.LeanOptions;
|
|
23
22
|
timeseries?: mongoose.mongo.TimeSeriesCollectionOptions;
|
|
24
23
|
expireAfterSeconds?: number;
|
|
25
24
|
expires?: number | string;
|
package/types/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.js"],"names":[],"mappings":"AAyBA;;;;;;;GAOG;AACH,yCAJW,MAAM,YACN,QAAQ,CAAC,aAAa;;;;;;;YA2C7B,CAAC;WAAa,CAAC;mBACH,CAAC
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.js"],"names":[],"mappings":"AAyBA;;;;;;;GAOG;AACH,yCAJW,MAAM,YACN,QAAQ,CAAC,aAAa;;;;;;;YA2C7B,CAAC;WAAa,CAAC;mBACH,CAAC;;;;;;;;;;;;;;;;;;;;;;;SAgIb,CAAC;gBAA4B,CAAA;SAAW,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aA3H5C;AAED,iEAcC;qBA9FoB,UAAU"}
|