@bedrockio/model 0.2.3 → 0.2.5
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/cjs/soft-delete.js +20 -5
- package/dist/cjs/validation.js +5 -4
- package/package.json +1 -1
- package/src/soft-delete.js +40 -5
- package/src/validation.js +4 -3
- package/types/soft-delete.d.ts.map +1 -1
- package/types/validation.d.ts.map +1 -1
package/dist/cjs/soft-delete.js
CHANGED
|
@@ -55,7 +55,10 @@ function applyQueries(schema) {
|
|
|
55
55
|
|
|
56
56
|
schema.static('deleteOne', function deleteOne(filter, ...rest) {
|
|
57
57
|
const update = getDelete();
|
|
58
|
-
const query = this.updateOne(
|
|
58
|
+
const query = this.updateOne({
|
|
59
|
+
...filter,
|
|
60
|
+
deleted: false
|
|
61
|
+
}, update, ...omitCallback(rest));
|
|
59
62
|
return (0, _query.wrapQuery)(query, async promise => {
|
|
60
63
|
const res = await promise;
|
|
61
64
|
return {
|
|
@@ -66,7 +69,10 @@ function applyQueries(schema) {
|
|
|
66
69
|
});
|
|
67
70
|
schema.static('deleteMany', function deleteMany(filter, ...rest) {
|
|
68
71
|
const update = getDelete();
|
|
69
|
-
const query = this.updateMany(
|
|
72
|
+
const query = this.updateMany({
|
|
73
|
+
...filter,
|
|
74
|
+
deleted: false
|
|
75
|
+
}, update, ...omitCallback(rest));
|
|
70
76
|
return (0, _query.wrapQuery)(query, async promise => {
|
|
71
77
|
const res = await promise;
|
|
72
78
|
return {
|
|
@@ -76,10 +82,16 @@ function applyQueries(schema) {
|
|
|
76
82
|
});
|
|
77
83
|
});
|
|
78
84
|
schema.static('findOneAndDelete', function findOneAndDelete(filter, ...rest) {
|
|
79
|
-
return this.findOneAndUpdate(
|
|
85
|
+
return this.findOneAndUpdate({
|
|
86
|
+
...filter,
|
|
87
|
+
deleted: false
|
|
88
|
+
}, getDelete(), ...omitCallback(rest));
|
|
80
89
|
});
|
|
81
90
|
schema.static('restoreOne', function restoreOne(filter, ...rest) {
|
|
82
|
-
const query = this.updateOne(
|
|
91
|
+
const query = this.updateOne({
|
|
92
|
+
...filter,
|
|
93
|
+
deleted: true
|
|
94
|
+
}, getRestore(), ...omitCallback(rest));
|
|
83
95
|
return (0, _query.wrapQuery)(query, async promise => {
|
|
84
96
|
const res = await promise;
|
|
85
97
|
return {
|
|
@@ -89,7 +101,10 @@ function applyQueries(schema) {
|
|
|
89
101
|
});
|
|
90
102
|
});
|
|
91
103
|
schema.static('restoreMany', function restoreMany(filter, ...rest) {
|
|
92
|
-
const query = this.updateMany(
|
|
104
|
+
const query = this.updateMany({
|
|
105
|
+
...filter,
|
|
106
|
+
deleted: true
|
|
107
|
+
}, getRestore(), ...omitCallback(rest));
|
|
93
108
|
return (0, _query.wrapQuery)(query, async promise => {
|
|
94
109
|
const res = await promise;
|
|
95
110
|
return {
|
package/dist/cjs/validation.js
CHANGED
|
@@ -131,7 +131,7 @@ function applyValidation(schema, definition) {
|
|
|
131
131
|
allowInclude: true,
|
|
132
132
|
expandDotSyntax: true,
|
|
133
133
|
unwindArrayFields: true,
|
|
134
|
-
|
|
134
|
+
requireReadAccess: true,
|
|
135
135
|
stripDeleted: !includeDeleted,
|
|
136
136
|
appendSchema: (0, _search.searchValidation)({
|
|
137
137
|
defaults,
|
|
@@ -145,7 +145,8 @@ function applyValidation(schema, definition) {
|
|
|
145
145
|
});
|
|
146
146
|
schema.static('getBaseSchema', function getBaseSchema() {
|
|
147
147
|
return getSchemaFromMongoose(schema, {
|
|
148
|
-
stripDeleted: true
|
|
148
|
+
stripDeleted: true,
|
|
149
|
+
requireReadAccess: true
|
|
149
150
|
});
|
|
150
151
|
});
|
|
151
152
|
}
|
|
@@ -297,7 +298,7 @@ function getSchemaForTypedef(typedef, options = {}) {
|
|
|
297
298
|
if (options.allowSearch) {
|
|
298
299
|
schema = getSearchSchema(schema, type);
|
|
299
300
|
}
|
|
300
|
-
if (typedef.readAccess && options.
|
|
301
|
+
if (typedef.readAccess && options.requireReadAccess) {
|
|
301
302
|
schema = validateReadAccess(schema, typedef.readAccess, options);
|
|
302
303
|
}
|
|
303
304
|
if (typedef.writeAccess && options.requireWriteAccess) {
|
|
@@ -377,7 +378,7 @@ function isExcludedField(field, options) {
|
|
|
377
378
|
if ((0, _utils.isSchemaTypedef)(field)) {
|
|
378
379
|
if (options.requireWriteAccess) {
|
|
379
380
|
return field.writeAccess === 'none';
|
|
380
|
-
} else if (options.
|
|
381
|
+
} else if (options.requireReadAccess) {
|
|
381
382
|
return field.readAccess === 'none' || field.readAccess === 'self';
|
|
382
383
|
}
|
|
383
384
|
}
|
package/package.json
CHANGED
package/src/soft-delete.js
CHANGED
|
@@ -48,7 +48,14 @@ function applyQueries(schema) {
|
|
|
48
48
|
|
|
49
49
|
schema.static('deleteOne', function deleteOne(filter, ...rest) {
|
|
50
50
|
const update = getDelete();
|
|
51
|
-
const query = this.updateOne(
|
|
51
|
+
const query = this.updateOne(
|
|
52
|
+
{
|
|
53
|
+
...filter,
|
|
54
|
+
deleted: false,
|
|
55
|
+
},
|
|
56
|
+
update,
|
|
57
|
+
...omitCallback(rest)
|
|
58
|
+
);
|
|
52
59
|
return wrapQuery(query, async (promise) => {
|
|
53
60
|
const res = await promise;
|
|
54
61
|
return {
|
|
@@ -60,7 +67,14 @@ function applyQueries(schema) {
|
|
|
60
67
|
|
|
61
68
|
schema.static('deleteMany', function deleteMany(filter, ...rest) {
|
|
62
69
|
const update = getDelete();
|
|
63
|
-
const query = this.updateMany(
|
|
70
|
+
const query = this.updateMany(
|
|
71
|
+
{
|
|
72
|
+
...filter,
|
|
73
|
+
deleted: false,
|
|
74
|
+
},
|
|
75
|
+
update,
|
|
76
|
+
...omitCallback(rest)
|
|
77
|
+
);
|
|
64
78
|
return wrapQuery(query, async (promise) => {
|
|
65
79
|
const res = await promise;
|
|
66
80
|
return {
|
|
@@ -71,11 +85,25 @@ function applyQueries(schema) {
|
|
|
71
85
|
});
|
|
72
86
|
|
|
73
87
|
schema.static('findOneAndDelete', function findOneAndDelete(filter, ...rest) {
|
|
74
|
-
return this.findOneAndUpdate(
|
|
88
|
+
return this.findOneAndUpdate(
|
|
89
|
+
{
|
|
90
|
+
...filter,
|
|
91
|
+
deleted: false,
|
|
92
|
+
},
|
|
93
|
+
getDelete(),
|
|
94
|
+
...omitCallback(rest)
|
|
95
|
+
);
|
|
75
96
|
});
|
|
76
97
|
|
|
77
98
|
schema.static('restoreOne', function restoreOne(filter, ...rest) {
|
|
78
|
-
const query = this.updateOne(
|
|
99
|
+
const query = this.updateOne(
|
|
100
|
+
{
|
|
101
|
+
...filter,
|
|
102
|
+
deleted: true,
|
|
103
|
+
},
|
|
104
|
+
getRestore(),
|
|
105
|
+
...omitCallback(rest)
|
|
106
|
+
);
|
|
79
107
|
return wrapQuery(query, async (promise) => {
|
|
80
108
|
const res = await promise;
|
|
81
109
|
return {
|
|
@@ -86,7 +114,14 @@ function applyQueries(schema) {
|
|
|
86
114
|
});
|
|
87
115
|
|
|
88
116
|
schema.static('restoreMany', function restoreMany(filter, ...rest) {
|
|
89
|
-
const query = this.updateMany(
|
|
117
|
+
const query = this.updateMany(
|
|
118
|
+
{
|
|
119
|
+
...filter,
|
|
120
|
+
deleted: true,
|
|
121
|
+
},
|
|
122
|
+
getRestore(),
|
|
123
|
+
...omitCallback(rest)
|
|
124
|
+
);
|
|
90
125
|
return wrapQuery(query, async (promise) => {
|
|
91
126
|
const res = await promise;
|
|
92
127
|
return {
|
package/src/validation.js
CHANGED
|
@@ -145,7 +145,7 @@ export function applyValidation(schema, definition) {
|
|
|
145
145
|
allowInclude: true,
|
|
146
146
|
expandDotSyntax: true,
|
|
147
147
|
unwindArrayFields: true,
|
|
148
|
-
|
|
148
|
+
requireReadAccess: true,
|
|
149
149
|
stripDeleted: !includeDeleted,
|
|
150
150
|
appendSchema: searchValidation({
|
|
151
151
|
defaults,
|
|
@@ -163,6 +163,7 @@ export function applyValidation(schema, definition) {
|
|
|
163
163
|
schema.static('getBaseSchema', function getBaseSchema() {
|
|
164
164
|
return getSchemaFromMongoose(schema, {
|
|
165
165
|
stripDeleted: true,
|
|
166
|
+
requireReadAccess: true,
|
|
166
167
|
});
|
|
167
168
|
});
|
|
168
169
|
}
|
|
@@ -314,7 +315,7 @@ function getSchemaForTypedef(typedef, options = {}) {
|
|
|
314
315
|
if (options.allowSearch) {
|
|
315
316
|
schema = getSearchSchema(schema, type);
|
|
316
317
|
}
|
|
317
|
-
if (typedef.readAccess && options.
|
|
318
|
+
if (typedef.readAccess && options.requireReadAccess) {
|
|
318
319
|
schema = validateReadAccess(schema, typedef.readAccess, options);
|
|
319
320
|
}
|
|
320
321
|
if (typedef.writeAccess && options.requireWriteAccess) {
|
|
@@ -432,7 +433,7 @@ function isExcludedField(field, options) {
|
|
|
432
433
|
if (isSchemaTypedef(field)) {
|
|
433
434
|
if (options.requireWriteAccess) {
|
|
434
435
|
return field.writeAccess === 'none';
|
|
435
|
-
} else if (options.
|
|
436
|
+
} else if (options.requireReadAccess) {
|
|
436
437
|
return field.readAccess === 'none' || field.readAccess === 'self';
|
|
437
438
|
}
|
|
438
439
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"soft-delete.d.ts","sourceRoot":"","sources":["../src/soft-delete.js"],"names":[],"mappings":"AAKA,mDAIC;
|
|
1
|
+
{"version":3,"file":"soft-delete.d.ts","sourceRoot":"","sources":["../src/soft-delete.js"],"names":[],"mappings":"AAKA,mDAIC;AAoTD,oEAsBC;AAgDD,2DAKC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"AAiFA,kDAEC;AAED,
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"AAiFA,kDAEC;AAED,oEAmFC;AAsBD,wEAkBC;AA0RD;;;EAEC;AAED;;;EAOC;AAneD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQK"}
|