payload 1.6.23 → 1.6.25
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/admin/components/Routes.js +1 -3
- package/dist/admin/components/Routes.js.map +1 -1
- package/dist/admin/components/elements/ColumnSelector/index.js +2 -0
- package/dist/admin/components/elements/ColumnSelector/index.js.map +1 -1
- package/dist/admin/components/elements/{UploadGallery → DeleteMany}/index.d.ts +2 -2
- package/dist/admin/components/elements/DeleteMany/index.js +104 -0
- package/dist/admin/components/elements/DeleteMany/index.js.map +1 -0
- package/dist/admin/components/elements/DeleteMany/index.scss +17 -0
- package/dist/admin/components/elements/DeleteMany/types.d.ts +7 -0
- package/dist/admin/components/elements/DeleteMany/types.js.map +1 -0
- package/dist/admin/components/elements/EditMany/index.d.ts +5 -0
- package/dist/admin/components/elements/EditMany/index.js +131 -0
- package/dist/admin/components/elements/EditMany/index.js.map +1 -0
- package/dist/admin/components/elements/EditMany/index.scss +190 -0
- package/dist/admin/components/elements/{UploadGallery → EditMany}/types.d.ts +2 -2
- package/dist/admin/components/elements/EditMany/types.js +3 -0
- package/dist/admin/components/elements/EditMany/types.js.map +1 -0
- package/dist/admin/components/elements/FieldSelect/index.d.ts +9 -0
- package/dist/admin/components/elements/FieldSelect/index.js +107 -0
- package/dist/admin/components/elements/FieldSelect/index.js.map +1 -0
- package/dist/admin/components/elements/FieldSelect/index.scss +5 -0
- package/dist/admin/components/elements/ListControls/index.js +16 -3
- package/dist/admin/components/elements/ListControls/index.js.map +1 -1
- package/dist/admin/components/elements/ListControls/index.scss +34 -31
- package/dist/admin/components/elements/ListControls/types.d.ts +2 -0
- package/dist/admin/components/elements/ListDrawer/DrawerContent.js +0 -10
- package/dist/admin/components/elements/ListDrawer/DrawerContent.js.map +1 -1
- package/dist/admin/components/elements/ListSelection/index.d.ts +7 -0
- package/dist/admin/components/elements/ListSelection/index.js +45 -0
- package/dist/admin/components/elements/ListSelection/index.js.map +1 -0
- package/dist/admin/components/elements/ListSelection/index.scss +19 -0
- package/dist/admin/components/elements/PublishMany/index.d.ts +5 -0
- package/dist/admin/components/elements/PublishMany/index.js +106 -0
- package/dist/admin/components/elements/PublishMany/index.js.map +1 -0
- package/dist/admin/components/elements/PublishMany/index.scss +17 -0
- package/dist/admin/components/elements/PublishMany/types.d.ts +6 -0
- package/dist/admin/components/elements/PublishMany/types.js +3 -0
- package/dist/admin/components/elements/PublishMany/types.js.map +1 -0
- package/dist/admin/components/elements/SearchFilter/index.scss +11 -1
- package/dist/admin/components/elements/TableColumns/buildColumns.d.ts +1 -3
- package/dist/admin/components/elements/TableColumns/buildColumns.js +24 -29
- package/dist/admin/components/elements/TableColumns/buildColumns.js.map +1 -1
- package/dist/admin/components/elements/TableColumns/columnReducer.d.ts +0 -4
- package/dist/admin/components/elements/TableColumns/columnReducer.js +3 -6
- package/dist/admin/components/elements/TableColumns/columnReducer.js.map +1 -1
- package/dist/admin/components/elements/TableColumns/index.js +11 -14
- package/dist/admin/components/elements/TableColumns/index.js.map +1 -1
- package/dist/admin/components/elements/Thumbnail/index.js +2 -1
- package/dist/admin/components/elements/Thumbnail/index.js.map +1 -1
- package/dist/admin/components/elements/Thumbnail/types.d.ts +1 -0
- package/dist/admin/components/elements/UnpublishMany/index.d.ts +5 -0
- package/dist/admin/components/elements/UnpublishMany/index.js +106 -0
- package/dist/admin/components/elements/UnpublishMany/index.js.map +1 -0
- package/dist/admin/components/elements/UnpublishMany/index.scss +17 -0
- package/dist/admin/components/elements/UnpublishMany/types.d.ts +6 -0
- package/dist/admin/components/elements/UnpublishMany/types.js +3 -0
- package/dist/admin/components/elements/UnpublishMany/types.js.map +1 -0
- package/dist/admin/components/icons/Line/index.d.ts +4 -0
- package/dist/admin/components/icons/Line/index.js +11 -0
- package/dist/admin/components/icons/Line/index.js.map +1 -0
- package/dist/admin/components/icons/Line/index.scss +11 -0
- package/dist/admin/components/views/collections/List/Cell/field-types/File/index.d.ts +8 -0
- package/dist/admin/components/views/collections/List/Cell/field-types/File/index.js +19 -0
- package/dist/admin/components/views/collections/List/Cell/field-types/File/index.js.map +1 -0
- package/dist/admin/components/views/collections/List/Cell/field-types/File/index.scss +18 -0
- package/dist/admin/components/views/collections/List/Cell/field-types/index.d.ts +5 -0
- package/dist/admin/components/views/collections/List/Cell/field-types/index.js +2 -0
- package/dist/admin/components/views/collections/List/Cell/field-types/index.js.map +1 -1
- package/dist/admin/components/views/collections/List/Cell/index.js +14 -8
- package/dist/admin/components/views/collections/List/Cell/index.js.map +1 -1
- package/dist/admin/components/views/collections/List/Default.js +45 -43
- package/dist/admin/components/views/collections/List/Default.js.map +1 -1
- package/dist/admin/components/views/collections/List/SelectAll/index.d.ts +4 -0
- package/dist/admin/components/views/collections/List/SelectAll/index.js +21 -0
- package/dist/admin/components/views/collections/List/SelectAll/index.js.map +1 -0
- package/dist/admin/components/views/collections/List/SelectAll/index.scss +30 -0
- package/dist/admin/components/views/collections/List/SelectRow/index.d.ts +6 -0
- package/dist/admin/components/views/collections/List/SelectRow/index.js +22 -0
- package/dist/admin/components/views/collections/List/SelectRow/index.js.map +1 -0
- package/dist/admin/components/views/collections/List/SelectRow/index.scss +44 -0
- package/dist/admin/components/views/collections/List/SelectionProvider/index.d.ts +25 -0
- package/dist/admin/components/views/collections/List/SelectionProvider/index.js +154 -0
- package/dist/admin/components/views/collections/List/SelectionProvider/index.js.map +1 -0
- package/dist/admin/components/views/collections/List/formatFields.js +22 -20
- package/dist/admin/components/views/collections/List/formatFields.js.map +1 -1
- package/dist/admin/components/views/collections/List/index.js +40 -14
- package/dist/admin/components/views/collections/List/index.js.map +1 -1
- package/dist/admin/components/views/collections/List/index.scss +34 -29
- package/dist/admin/components/views/collections/List/types.d.ts +7 -2
- package/dist/collections/buildEndpoints.js +15 -3
- package/dist/collections/buildEndpoints.js.map +1 -1
- package/dist/collections/config/types.d.ts +10 -2
- package/dist/collections/graphql/resolvers/delete.js +2 -2
- package/dist/collections/graphql/resolvers/delete.js.map +1 -1
- package/dist/collections/graphql/resolvers/update.js +2 -2
- package/dist/collections/graphql/resolvers/update.js.map +1 -1
- package/dist/collections/operations/delete.d.ts +9 -2
- package/dist/collections/operations/delete.js +114 -109
- package/dist/collections/operations/delete.js.map +1 -1
- package/dist/collections/operations/deleteByID.d.ts +14 -0
- package/dist/collections/operations/deleteByID.js +127 -0
- package/dist/collections/operations/deleteByID.js.map +1 -0
- package/dist/collections/operations/local/delete.d.ts +17 -5
- package/dist/collections/operations/local/delete.js +9 -3
- package/dist/collections/operations/local/delete.js.map +1 -1
- package/dist/collections/operations/local/index.d.ts +9 -3
- package/dist/collections/operations/local/index.js +8 -2
- package/dist/collections/operations/local/index.js.map +1 -1
- package/dist/collections/operations/local/update.d.ts +16 -4
- package/dist/collections/operations/local/update.js +7 -2
- package/dist/collections/operations/local/update.js.map +1 -1
- package/dist/collections/operations/update.d.ts +4 -4
- package/dist/collections/operations/update.js +208 -227
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/collections/operations/updateByID.d.ts +20 -0
- package/dist/collections/operations/updateByID.js +256 -0
- package/dist/collections/operations/updateByID.js.map +1 -0
- package/dist/collections/requestHandlers/delete.js +23 -6
- package/dist/collections/requestHandlers/delete.js.map +1 -1
- package/dist/collections/requestHandlers/deleteByID.d.ts +8 -0
- package/dist/collections/requestHandlers/deleteByID.js +27 -0
- package/dist/collections/requestHandlers/deleteByID.js.map +1 -0
- package/dist/collections/requestHandlers/update.d.ts +1 -2
- package/dist/collections/requestHandlers/update.js +21 -17
- package/dist/collections/requestHandlers/update.js.map +1 -1
- package/dist/collections/requestHandlers/updateByID.d.ts +8 -0
- package/dist/collections/requestHandlers/updateByID.js +43 -0
- package/dist/collections/requestHandlers/updateByID.js.map +1 -0
- package/dist/fields/config/schema.js +1 -0
- package/dist/fields/config/schema.js.map +1 -1
- package/dist/fields/config/types.d.ts +2 -0
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/hooks/afterChange/promise.js +5 -5
- package/dist/fields/hooks/afterChange/promise.js.map +1 -1
- package/dist/fields/validations.d.ts +1 -0
- package/dist/index.js.map +1 -1
- package/dist/payload.d.ts +23 -6
- package/dist/payload.js +9 -10
- package/dist/payload.js.map +1 -1
- package/dist/translations/cs.json +18 -1
- package/dist/translations/de.json +32 -11
- package/dist/translations/en.json +25 -8
- package/dist/translations/es.json +25 -8
- package/dist/translations/fr.json +30 -10
- package/dist/translations/hr.json +25 -8
- package/dist/translations/hu.json +18 -1
- package/dist/translations/index.d.ts +630 -191
- package/dist/translations/it.json +36 -10
- package/dist/translations/ja.json +14 -2
- package/dist/translations/my.json +37 -8
- package/dist/translations/nb.json +26 -8
- package/dist/translations/nl.json +37 -9
- package/dist/translations/pl.json +38 -9
- package/dist/translations/pt.json +38 -9
- package/dist/translations/ru.json +28 -10
- package/dist/translations/sv.json +37 -9
- package/dist/translations/th.json +26 -9
- package/dist/translations/tr.json +53 -35
- package/dist/translations/ua.json +25 -8
- package/dist/translations/vi.json +38 -11
- package/dist/translations/zh.json +25 -8
- package/dist/uploads/deleteAssociatedFiles.d.ts +14 -0
- package/dist/uploads/deleteAssociatedFiles.js +41 -0
- package/dist/uploads/deleteAssociatedFiles.js.map +1 -0
- package/dist/uploads/getBaseFields.js +1 -0
- package/dist/uploads/getBaseFields.js.map +1 -1
- package/dist/uploads/unlinkTempFiles.d.ts +13 -0
- package/dist/uploads/unlinkTempFiles.js +28 -0
- package/dist/uploads/unlinkTempFiles.js.map +1 -0
- package/dist/versions/baseFields.js +1 -0
- package/dist/versions/baseFields.js.map +1 -1
- package/dist/versions/drafts/queryDrafts.d.ts +1 -1
- package/dist/versions/drafts/queryDrafts.js +22 -15
- package/dist/versions/drafts/queryDrafts.js.map +1 -1
- package/docs/fields/overview.mdx +13 -12
- package/docs/local-api/overview.mdx +62 -1
- package/docs/rest-api/overview.mdx +9 -7
- package/package.json +1 -1
- package/dist/admin/components/elements/UploadGallery/index.js +0 -19
- package/dist/admin/components/elements/UploadGallery/index.js.map +0 -1
- package/dist/admin/components/elements/UploadGallery/index.scss +0 -32
- package/dist/admin/components/elements/UploadGallery/types.js.map +0 -1
- package/dist/admin/components/views/collections/List/Cell/field-types/Upload/index.d.ts +0 -0
- package/dist/admin/components/views/collections/List/Cell/field-types/Upload/index.js +0 -1
- package/dist/admin/components/views/collections/List/Cell/field-types/Upload/index.js.map +0 -1
- /package/dist/admin/components/elements/{UploadGallery → DeleteMany}/types.js +0 -0
|
@@ -3,15 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
6
|
+
const http_status_1 = __importDefault(require("http-status"));
|
|
8
7
|
const sanitizeInternalFields_1 = __importDefault(require("../../utilities/sanitizeInternalFields"));
|
|
9
8
|
const errors_1 = require("../../errors");
|
|
10
9
|
const executeAccess_1 = __importDefault(require("../../auth/executeAccess"));
|
|
11
10
|
const types_1 = require("../../auth/types");
|
|
12
|
-
const fileExists_1 = __importDefault(require("../../uploads/fileExists"));
|
|
13
11
|
const afterRead_1 = require("../../fields/hooks/afterRead");
|
|
14
12
|
const deleteCollectionVersions_1 = require("../../versions/deleteCollectionVersions");
|
|
13
|
+
const deleteAssociatedFiles_1 = require("../../uploads/deleteAssociatedFiles");
|
|
15
14
|
async function deleteOperation(incomingArgs) {
|
|
16
15
|
let args = incomingArgs;
|
|
17
16
|
// /////////////////////////////////////
|
|
@@ -24,132 +23,138 @@ async function deleteOperation(incomingArgs) {
|
|
|
24
23
|
operation: 'delete',
|
|
25
24
|
})) || args;
|
|
26
25
|
}, Promise.resolve());
|
|
27
|
-
const { depth, collection: { Model, config: collectionConfig, },
|
|
26
|
+
const { depth, collection: { Model, config: collectionConfig, }, where, req, req: { t, locale, payload, payload: { config, preferences, }, }, overrideAccess, showHiddenFields, } = args;
|
|
27
|
+
if (!where) {
|
|
28
|
+
throw new errors_1.APIError('Missing \'where\' query of documents to delete.', http_status_1.default.BAD_REQUEST);
|
|
29
|
+
}
|
|
28
30
|
// /////////////////////////////////////
|
|
29
31
|
// Access
|
|
30
32
|
// /////////////////////////////////////
|
|
31
|
-
const accessResults = !overrideAccess ? await (0, executeAccess_1.default)({ req, id }, collectionConfig.access.delete) : true;
|
|
32
|
-
const hasWhereAccess = (0, types_1.hasWhereAccessResult)(accessResults);
|
|
33
|
-
// /////////////////////////////////////
|
|
34
|
-
// beforeDelete - Collection
|
|
35
|
-
// /////////////////////////////////////
|
|
36
|
-
await collectionConfig.hooks.beforeDelete.reduce(async (priorHook, hook) => {
|
|
37
|
-
await priorHook;
|
|
38
|
-
return hook({
|
|
39
|
-
req,
|
|
40
|
-
id,
|
|
41
|
-
});
|
|
42
|
-
}, Promise.resolve());
|
|
43
|
-
// /////////////////////////////////////
|
|
44
|
-
// Retrieve document
|
|
45
|
-
// /////////////////////////////////////
|
|
46
33
|
const queryToBuild = {
|
|
47
34
|
where: {
|
|
48
|
-
and: [
|
|
49
|
-
{
|
|
50
|
-
id: {
|
|
51
|
-
equals: id,
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
],
|
|
35
|
+
and: [],
|
|
55
36
|
},
|
|
56
37
|
};
|
|
57
|
-
if (
|
|
58
|
-
queryToBuild.where
|
|
38
|
+
if (where) {
|
|
39
|
+
queryToBuild.where = {
|
|
40
|
+
and: [],
|
|
41
|
+
...where,
|
|
42
|
+
};
|
|
43
|
+
if (Array.isArray(where.AND)) {
|
|
44
|
+
queryToBuild.where.and = [
|
|
45
|
+
...queryToBuild.where.and,
|
|
46
|
+
...where.AND,
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
let accessResult;
|
|
51
|
+
if (!overrideAccess) {
|
|
52
|
+
accessResult = await (0, executeAccess_1.default)({ req }, collectionConfig.access.delete);
|
|
53
|
+
if ((0, types_1.hasWhereAccessResult)(accessResult)) {
|
|
54
|
+
queryToBuild.where.and.push(accessResult);
|
|
55
|
+
}
|
|
59
56
|
}
|
|
60
57
|
const query = await Model.buildQuery(queryToBuild, locale);
|
|
61
|
-
const docToDelete = await Model.findOne(query);
|
|
62
|
-
if (!docToDelete && !hasWhereAccess)
|
|
63
|
-
throw new errors_1.NotFound(t);
|
|
64
|
-
if (!docToDelete && hasWhereAccess)
|
|
65
|
-
throw new errors_1.Forbidden(t);
|
|
66
|
-
const resultToDelete = docToDelete.toJSON({ virtuals: true });
|
|
67
58
|
// /////////////////////////////////////
|
|
68
|
-
//
|
|
69
|
-
// /////////////////////////////////////
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
59
|
+
// Retrieve documents
|
|
60
|
+
// /////////////////////////////////////
|
|
61
|
+
const docs = await Model.find(query, {}, { lean: true });
|
|
62
|
+
const errors = [];
|
|
63
|
+
/* eslint-disable no-param-reassign */
|
|
64
|
+
const promises = docs.map(async (doc) => {
|
|
65
|
+
let result;
|
|
66
|
+
// custom id type reset
|
|
67
|
+
doc.id = doc._id;
|
|
68
|
+
doc = JSON.stringify(doc);
|
|
69
|
+
doc = JSON.parse(doc);
|
|
70
|
+
doc = (0, sanitizeInternalFields_1.default)(doc);
|
|
71
|
+
const { id } = doc;
|
|
72
|
+
try {
|
|
73
|
+
// /////////////////////////////////////
|
|
74
|
+
// beforeDelete - Collection
|
|
75
|
+
// /////////////////////////////////////
|
|
76
|
+
await collectionConfig.hooks.beforeDelete.reduce(async (priorHook, hook) => {
|
|
77
|
+
await priorHook;
|
|
78
|
+
return hook({
|
|
79
|
+
req,
|
|
80
|
+
id,
|
|
81
|
+
});
|
|
82
|
+
}, Promise.resolve());
|
|
83
|
+
await (0, deleteAssociatedFiles_1.deleteAssociatedFiles)({ config, collectionConfig, doc, t, overrideDelete: true });
|
|
84
|
+
// /////////////////////////////////////
|
|
85
|
+
// Delete document
|
|
86
|
+
// /////////////////////////////////////
|
|
87
|
+
await Model.deleteOne({ _id: id }, { lean: true });
|
|
88
|
+
// /////////////////////////////////////
|
|
89
|
+
// Delete versions
|
|
90
|
+
// /////////////////////////////////////
|
|
91
|
+
if (collectionConfig.versions) {
|
|
92
|
+
(0, deleteCollectionVersions_1.deleteCollectionVersions)({
|
|
93
|
+
payload,
|
|
94
|
+
id,
|
|
95
|
+
slug: collectionConfig.slug,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
// /////////////////////////////////////
|
|
99
|
+
// afterDelete - Collection
|
|
100
|
+
// /////////////////////////////////////
|
|
101
|
+
await collectionConfig.hooks.afterDelete.reduce(async (priorHook, hook) => {
|
|
102
|
+
await priorHook;
|
|
103
|
+
result = await hook({
|
|
104
|
+
req,
|
|
105
|
+
id,
|
|
106
|
+
doc,
|
|
107
|
+
}) || doc;
|
|
108
|
+
}, Promise.resolve());
|
|
109
|
+
// /////////////////////////////////////
|
|
110
|
+
// afterRead - Fields
|
|
111
|
+
// /////////////////////////////////////
|
|
112
|
+
result = await (0, afterRead_1.afterRead)({
|
|
113
|
+
depth,
|
|
114
|
+
doc: result || doc,
|
|
115
|
+
entityConfig: collectionConfig,
|
|
116
|
+
overrideAccess,
|
|
117
|
+
req,
|
|
118
|
+
showHiddenFields,
|
|
79
119
|
});
|
|
120
|
+
// /////////////////////////////////////
|
|
121
|
+
// afterRead - Collection
|
|
122
|
+
// /////////////////////////////////////
|
|
123
|
+
await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {
|
|
124
|
+
await priorHook;
|
|
125
|
+
result = await hook({
|
|
126
|
+
req,
|
|
127
|
+
doc: result || doc,
|
|
128
|
+
}) || result;
|
|
129
|
+
}, Promise.resolve());
|
|
130
|
+
// /////////////////////////////////////
|
|
131
|
+
// 8. Return results
|
|
132
|
+
// /////////////////////////////////////
|
|
133
|
+
return result;
|
|
80
134
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
fs_1.default.unlink(sizeToDelete, (err) => {
|
|
86
|
-
if (err) {
|
|
87
|
-
throw new errors_1.ErrorDeletingFile(t);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
errors.push({
|
|
137
|
+
message: error.message,
|
|
138
|
+
id: doc.id,
|
|
91
139
|
});
|
|
92
140
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// /////////////////////////////////////
|
|
97
|
-
const doc = await Model.findOneAndDelete({ _id: id });
|
|
98
|
-
let result = doc.toJSON({ virtuals: true });
|
|
99
|
-
// custom id type reset
|
|
100
|
-
result.id = result._id;
|
|
101
|
-
result = JSON.stringify(result);
|
|
102
|
-
result = JSON.parse(result);
|
|
103
|
-
result = (0, sanitizeInternalFields_1.default)(result);
|
|
141
|
+
return null;
|
|
142
|
+
});
|
|
143
|
+
const awaitedDocs = await Promise.all(promises);
|
|
104
144
|
// /////////////////////////////////////
|
|
105
145
|
// Delete Preferences
|
|
106
146
|
// /////////////////////////////////////
|
|
107
147
|
if (collectionConfig.auth) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// /////////////////////////////////////
|
|
112
|
-
// Delete versions
|
|
113
|
-
// /////////////////////////////////////
|
|
114
|
-
if (collectionConfig.versions) {
|
|
115
|
-
(0, deleteCollectionVersions_1.deleteCollectionVersions)({
|
|
116
|
-
payload,
|
|
117
|
-
id,
|
|
118
|
-
slug: collectionConfig.slug,
|
|
148
|
+
preferences.Model.deleteMany({
|
|
149
|
+
user: { in: docs.map(({ id }) => id) },
|
|
150
|
+
userCollection: collectionConfig.slug,
|
|
119
151
|
});
|
|
120
152
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
result = await hook({ req, id, doc: result }) || result;
|
|
127
|
-
}, Promise.resolve());
|
|
128
|
-
// /////////////////////////////////////
|
|
129
|
-
// afterRead - Fields
|
|
130
|
-
// /////////////////////////////////////
|
|
131
|
-
result = await (0, afterRead_1.afterRead)({
|
|
132
|
-
depth,
|
|
133
|
-
doc: result,
|
|
134
|
-
entityConfig: collectionConfig,
|
|
135
|
-
overrideAccess,
|
|
136
|
-
req,
|
|
137
|
-
showHiddenFields,
|
|
138
|
-
});
|
|
139
|
-
// /////////////////////////////////////
|
|
140
|
-
// afterRead - Collection
|
|
141
|
-
// /////////////////////////////////////
|
|
142
|
-
await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {
|
|
143
|
-
await priorHook;
|
|
144
|
-
result = await hook({
|
|
145
|
-
req,
|
|
146
|
-
doc: result,
|
|
147
|
-
}) || result;
|
|
148
|
-
}, Promise.resolve());
|
|
149
|
-
// /////////////////////////////////////
|
|
150
|
-
// 8. Return results
|
|
151
|
-
// /////////////////////////////////////
|
|
152
|
-
return result;
|
|
153
|
+
preferences.Model.deleteMany({ key: { in: docs.map(({ id }) => `collection-${collectionConfig.slug}-${id}`) } });
|
|
154
|
+
return {
|
|
155
|
+
docs: awaitedDocs.filter(Boolean),
|
|
156
|
+
errors,
|
|
157
|
+
};
|
|
153
158
|
}
|
|
154
159
|
exports.default = deleteOperation;
|
|
155
160
|
//# sourceMappingURL=delete.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../src/collections/operations/delete.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../src/collections/operations/delete.ts"],"names":[],"mappings":";;;;;AACA,8DAAqC;AAGrC,oGAA4E;AAC5E,yCAAwC;AACxC,6EAAqD;AAGrD,4CAAwD;AACxD,4DAAyD;AACzD,sFAAmF;AACnF,+EAA4E;AAW5E,KAAK,UAAU,eAAe,CAC5B,YAAuB;IAQvB,IAAI,IAAI,GAAG,YAAY,CAAC;IAExB,wCAAwC;IAC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ayloadRequest } from '../../express/types';
|
|
3
|
+
import { Collection } from '../config/types';
|
|
4
|
+
import { Document } from '../../types';
|
|
5
|
+
export type Arguments = {
|
|
6
|
+
depth?: number;
|
|
7
|
+
collection: Collection;
|
|
8
|
+
id: string | number;
|
|
9
|
+
req: PayloadRequest;
|
|
10
|
+
overrideAccess?: boolean;
|
|
11
|
+
showHiddenFields?: boolean;
|
|
12
|
+
};
|
|
13
|
+
declare function deleteByID<TSlug extends keyof GeneratedTypes['collections']>(incomingArgs: Arguments): Promise<Document>;
|
|
14
|
+
export default deleteByID;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const sanitizeInternalFields_1 = __importDefault(require("../../utilities/sanitizeInternalFields"));
|
|
7
|
+
const errors_1 = require("../../errors");
|
|
8
|
+
const executeAccess_1 = __importDefault(require("../../auth/executeAccess"));
|
|
9
|
+
const types_1 = require("../../auth/types");
|
|
10
|
+
const afterRead_1 = require("../../fields/hooks/afterRead");
|
|
11
|
+
const deleteCollectionVersions_1 = require("../../versions/deleteCollectionVersions");
|
|
12
|
+
const deleteAssociatedFiles_1 = require("../../uploads/deleteAssociatedFiles");
|
|
13
|
+
async function deleteByID(incomingArgs) {
|
|
14
|
+
let args = incomingArgs;
|
|
15
|
+
// /////////////////////////////////////
|
|
16
|
+
// beforeOperation - Collection
|
|
17
|
+
// /////////////////////////////////////
|
|
18
|
+
await args.collection.config.hooks.beforeOperation.reduce(async (priorHook, hook) => {
|
|
19
|
+
await priorHook;
|
|
20
|
+
args = (await hook({
|
|
21
|
+
args,
|
|
22
|
+
operation: 'delete',
|
|
23
|
+
})) || args;
|
|
24
|
+
}, Promise.resolve());
|
|
25
|
+
const { depth, collection: { Model, config: collectionConfig, }, id, req, req: { t, locale, payload, payload: { config, preferences, }, }, overrideAccess, showHiddenFields, } = args;
|
|
26
|
+
// /////////////////////////////////////
|
|
27
|
+
// Access
|
|
28
|
+
// /////////////////////////////////////
|
|
29
|
+
const accessResults = !overrideAccess ? await (0, executeAccess_1.default)({ req, id }, collectionConfig.access.delete) : true;
|
|
30
|
+
const hasWhereAccess = (0, types_1.hasWhereAccessResult)(accessResults);
|
|
31
|
+
// /////////////////////////////////////
|
|
32
|
+
// beforeDelete - Collection
|
|
33
|
+
// /////////////////////////////////////
|
|
34
|
+
await collectionConfig.hooks.beforeDelete.reduce(async (priorHook, hook) => {
|
|
35
|
+
await priorHook;
|
|
36
|
+
return hook({
|
|
37
|
+
req,
|
|
38
|
+
id,
|
|
39
|
+
});
|
|
40
|
+
}, Promise.resolve());
|
|
41
|
+
// /////////////////////////////////////
|
|
42
|
+
// Retrieve document
|
|
43
|
+
// /////////////////////////////////////
|
|
44
|
+
const queryToBuild = {
|
|
45
|
+
where: {
|
|
46
|
+
and: [
|
|
47
|
+
{
|
|
48
|
+
id: {
|
|
49
|
+
equals: id,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
if ((0, types_1.hasWhereAccessResult)(accessResults)) {
|
|
56
|
+
queryToBuild.where.and.push(accessResults);
|
|
57
|
+
}
|
|
58
|
+
const query = await Model.buildQuery(queryToBuild, locale);
|
|
59
|
+
const docToDelete = await Model.findOne(query);
|
|
60
|
+
if (!docToDelete && !hasWhereAccess)
|
|
61
|
+
throw new errors_1.NotFound(t);
|
|
62
|
+
if (!docToDelete && hasWhereAccess)
|
|
63
|
+
throw new errors_1.Forbidden(t);
|
|
64
|
+
const resultToDelete = docToDelete.toJSON({ virtuals: true });
|
|
65
|
+
await (0, deleteAssociatedFiles_1.deleteAssociatedFiles)({ config, collectionConfig, doc: resultToDelete, t, overrideDelete: true });
|
|
66
|
+
// /////////////////////////////////////
|
|
67
|
+
// Delete document
|
|
68
|
+
// /////////////////////////////////////
|
|
69
|
+
const doc = await Model.findOneAndDelete({ _id: id });
|
|
70
|
+
let result = doc.toJSON({ virtuals: true });
|
|
71
|
+
// custom id type reset
|
|
72
|
+
result.id = result._id;
|
|
73
|
+
result = JSON.stringify(result);
|
|
74
|
+
result = JSON.parse(result);
|
|
75
|
+
result = (0, sanitizeInternalFields_1.default)(result);
|
|
76
|
+
// /////////////////////////////////////
|
|
77
|
+
// Delete Preferences
|
|
78
|
+
// /////////////////////////////////////
|
|
79
|
+
if (collectionConfig.auth) {
|
|
80
|
+
await preferences.Model.deleteMany({ user: id, userCollection: collectionConfig.slug });
|
|
81
|
+
}
|
|
82
|
+
await preferences.Model.deleteMany({ key: `collection-${collectionConfig.slug}-${id}` });
|
|
83
|
+
// /////////////////////////////////////
|
|
84
|
+
// Delete versions
|
|
85
|
+
// /////////////////////////////////////
|
|
86
|
+
if (collectionConfig.versions) {
|
|
87
|
+
(0, deleteCollectionVersions_1.deleteCollectionVersions)({
|
|
88
|
+
payload,
|
|
89
|
+
id,
|
|
90
|
+
slug: collectionConfig.slug,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
// /////////////////////////////////////
|
|
94
|
+
// afterDelete - Collection
|
|
95
|
+
// /////////////////////////////////////
|
|
96
|
+
await collectionConfig.hooks.afterDelete.reduce(async (priorHook, hook) => {
|
|
97
|
+
await priorHook;
|
|
98
|
+
result = await hook({ req, id, doc: result }) || result;
|
|
99
|
+
}, Promise.resolve());
|
|
100
|
+
// /////////////////////////////////////
|
|
101
|
+
// afterRead - Fields
|
|
102
|
+
// /////////////////////////////////////
|
|
103
|
+
result = await (0, afterRead_1.afterRead)({
|
|
104
|
+
depth,
|
|
105
|
+
doc: result,
|
|
106
|
+
entityConfig: collectionConfig,
|
|
107
|
+
overrideAccess,
|
|
108
|
+
req,
|
|
109
|
+
showHiddenFields,
|
|
110
|
+
});
|
|
111
|
+
// /////////////////////////////////////
|
|
112
|
+
// afterRead - Collection
|
|
113
|
+
// /////////////////////////////////////
|
|
114
|
+
await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {
|
|
115
|
+
await priorHook;
|
|
116
|
+
result = await hook({
|
|
117
|
+
req,
|
|
118
|
+
doc: result,
|
|
119
|
+
}) || result;
|
|
120
|
+
}, Promise.resolve());
|
|
121
|
+
// /////////////////////////////////////
|
|
122
|
+
// 8. Return results
|
|
123
|
+
// /////////////////////////////////////
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
exports.default = deleteByID;
|
|
127
|
+
//# sourceMappingURL=deleteByID.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteByID.js","sourceRoot":"","sources":["../../../src/collections/operations/deleteByID.ts"],"names":[],"mappings":";;;;;AAEA,oGAA4E;AAC5E,yCAAmD;AACnD,6EAAqD;AAGrD,4CAAwD;AACxD,4DAAyD;AACzD,sFAAmF;AACnF,+EAA4E;AAW5E,KAAK,UAAU,UAAU,CAAoD,YAAuB;IAClG,IAAI,IAAI,GAAG,YAAY,CAAC;IAExB,wCAAwC;IACxC,+BAA+B;IAC/B,wCAAwC;IAExC,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,KAAK,EAAE,SAA8C,EAAE,IAAyB,EAAE,EAAE;QAC5I,MAAM,SAAS,CAAC;QAEhB,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC;YACjB,IAAI;YACJ,SAAS,EAAE,QAAQ;SACpB,CAAC,CAAC,IAAI,IAAI,CAAC;IACd,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAEtB,MAAM,EACJ,KAAK,EACL,UAAU,EAAE,EACV,KAAK,EACL,MAAM,EAAE,gBAAgB,GACzB,EACD,EAAE,EACF,GAAG,EACH,GAAG,EAAE,EACH,CAAC,EACD,MAAM,EACN,OAAO,EACP,OAAO,EAAE,EACP,MAAM,EACN,WAAW,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;YACP,EAAE;YACF,IAAI,EAAE,gBAAgB,CAAC,IAAI;SAC5B,CAAC,CAAC;KACJ;IAED,wCAAwC;IACxC,2BAA2B;IAC3B,wCAAwC;IAExC,MAAM,gBAAgB,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE;QACxE,MAAM,SAAS,CAAC;QAEhB,MAAM,GAAG,MAAM,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,IAAI,MAAM,CAAC;IAC1D,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAGtB,wCAAwC;IACxC,qBAAqB;IACrB,wCAAwC;IAExC,MAAM,GAAG,MAAM,IAAA,qBAAS,EAAC;QACvB,KAAK;QACL,GAAG,EAAE,MAAM;QACX,YAAY,EAAE,gBAAgB;QAC9B,cAAc;QACd,GAAG;QACH,gBAAgB;KACjB,CAAC,CAAC;IAEH,wCAAwC;IACxC,yBAAyB;IACzB,wCAAwC;IAExC,MAAM,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE;QACtE,MAAM,SAAS,CAAC;QAEhB,MAAM,GAAG,MAAM,IAAI,CAAC;YAClB,GAAG;YACH,GAAG,EAAE,MAAM;SACZ,CAAC,IAAI,MAAM,CAAC;IACf,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAEtB,wCAAwC;IACxC,oBAAoB;IACpB,wCAAwC;IAExC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,kBAAe,UAAU,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Config as GeneratedTypes } from '
|
|
2
|
-
import { Document } from '../../../types';
|
|
1
|
+
import { Config as GeneratedTypes } from '../../../generated-types';
|
|
2
|
+
import { Document, Where } from '../../../types';
|
|
3
3
|
import { Payload } from '../../../payload';
|
|
4
|
-
|
|
4
|
+
import { BulkOperationResult } from '../../config/types';
|
|
5
|
+
export type BaseOptions<T extends keyof GeneratedTypes['collections']> = {
|
|
5
6
|
collection: T;
|
|
6
|
-
id: string;
|
|
7
|
+
id: string | number;
|
|
7
8
|
depth?: number;
|
|
8
9
|
locale?: string;
|
|
9
10
|
fallbackLocale?: string;
|
|
@@ -11,4 +12,15 @@ export type Options<T extends keyof GeneratedTypes['collections']> = {
|
|
|
11
12
|
overrideAccess?: boolean;
|
|
12
13
|
showHiddenFields?: boolean;
|
|
13
14
|
};
|
|
14
|
-
export
|
|
15
|
+
export type ByIDOptions<T extends keyof GeneratedTypes['collections']> = BaseOptions<T> & {
|
|
16
|
+
where?: never;
|
|
17
|
+
};
|
|
18
|
+
export type ManyOptions<T extends keyof GeneratedTypes['collections']> = BaseOptions<T> & {
|
|
19
|
+
where: Where;
|
|
20
|
+
id?: never;
|
|
21
|
+
};
|
|
22
|
+
export type Options<TSlug extends keyof GeneratedTypes['collections']> = ByIDOptions<TSlug> | ManyOptions<TSlug>;
|
|
23
|
+
declare function deleteLocal<TSlug extends keyof GeneratedTypes['collections']>(payload: Payload, options: ByIDOptions<TSlug>): Promise<GeneratedTypes['collections'][TSlug]>;
|
|
24
|
+
declare function deleteLocal<TSlug extends keyof GeneratedTypes['collections']>(payload: Payload, options: ManyOptions<TSlug>): Promise<BulkOperationResult<TSlug>>;
|
|
25
|
+
declare function deleteLocal<TSlug extends keyof GeneratedTypes['collections']>(payload: Payload, options: Options<TSlug>): Promise<GeneratedTypes['collections'][TSlug] | BulkOperationResult<TSlug>>;
|
|
26
|
+
export default deleteLocal;
|
|
@@ -4,12 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const delete_1 = __importDefault(require("../delete"));
|
|
7
|
+
const deleteByID_1 = __importDefault(require("../deleteByID"));
|
|
7
8
|
const dataloader_1 = require("../../dataloader");
|
|
8
9
|
const init_1 = __importDefault(require("../../../translations/init"));
|
|
9
10
|
const errors_1 = require("../../../errors");
|
|
10
11
|
async function deleteLocal(payload, options) {
|
|
11
12
|
var _a, _b, _c;
|
|
12
|
-
const { collection: collectionSlug, depth, id, locale = null, fallbackLocale = null, user, overrideAccess = true, showHiddenFields, } = options;
|
|
13
|
+
const { collection: collectionSlug, depth, id, where, locale = null, fallbackLocale = null, user, overrideAccess = true, showHiddenFields, } = options;
|
|
13
14
|
const collection = payload.collections[collectionSlug];
|
|
14
15
|
const defaultLocale = ((_a = payload === null || payload === void 0 ? void 0 : payload.config) === null || _a === void 0 ? void 0 : _a.localization) ? (_c = (_b = payload === null || payload === void 0 ? void 0 : payload.config) === null || _b === void 0 ? void 0 : _b.localization) === null || _c === void 0 ? void 0 : _c.defaultLocale : null;
|
|
15
16
|
if (!collection) {
|
|
@@ -27,14 +28,19 @@ async function deleteLocal(payload, options) {
|
|
|
27
28
|
req.t = req.i18n.t;
|
|
28
29
|
if (!req.payloadDataLoader)
|
|
29
30
|
req.payloadDataLoader = (0, dataloader_1.getDataLoader)(req);
|
|
30
|
-
|
|
31
|
+
const args = {
|
|
31
32
|
depth,
|
|
32
33
|
id,
|
|
34
|
+
where,
|
|
33
35
|
collection,
|
|
34
36
|
overrideAccess,
|
|
35
37
|
showHiddenFields,
|
|
36
38
|
req,
|
|
37
|
-
}
|
|
39
|
+
};
|
|
40
|
+
if (options.id) {
|
|
41
|
+
return (0, deleteByID_1.default)(args);
|
|
42
|
+
}
|
|
43
|
+
return (0, delete_1.default)(args);
|
|
38
44
|
}
|
|
39
45
|
exports.default = deleteLocal;
|
|
40
46
|
//# sourceMappingURL=delete.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../../src/collections/operations/local/delete.ts"],"names":[],"mappings":";;;;;AAIA,uDAAwC;AACxC,iDAAiD;AACjD,sEAA8C;AAC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GAAG,CAAC,iBAAiB;QAAE,GAAG,CAAC,iBAAiB,GAAG,IAAA,0BAAa,EAAC,GAAG,CAAC,CAAC;IAEvE,MAAM,IAAI,GAAG;QACX,KAAK;QACL,EAAE;QACF,KAAK;QACL,UAAU;QACV,cAAc;QACd,gBAAgB;QAChB,GAAG;KACJ,CAAC;IAEF,IAAI,OAAO,CAAC,EAAE,EAAE;QACd,OAAO,IAAA,oBAAU,EAAQ,IAAI,CAAC,CAAC;KAChC;IACD,OAAO,IAAA,gBAAe,EAAQ,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,kBAAe,WAAW,CAAC"}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
+
import { Config as GeneratedTypes } from 'payload/generated-types';
|
|
1
2
|
import find from './find';
|
|
2
3
|
import findByID from './findByID';
|
|
3
4
|
import create from './create';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
5
|
+
import { ByIDOptions as UpdateByIDOptions, ManyOptions as UpdateManyOptions } from './update';
|
|
6
|
+
import { ByIDOptions as DeleteByIDOptions, ManyOptions as DeleteManyOptions } from './delete';
|
|
6
7
|
import findVersionByID from './findVersionByID';
|
|
7
8
|
import findVersions from './findVersions';
|
|
8
9
|
import restoreVersion from './restoreVersion';
|
|
10
|
+
import { BulkOperationResult } from '../../config/types';
|
|
11
|
+
declare function localUpdate<T extends keyof GeneratedTypes['collections']>(options: UpdateByIDOptions<T>): Promise<GeneratedTypes['collections'][T]>;
|
|
12
|
+
declare function localUpdate<T extends keyof GeneratedTypes['collections']>(options: UpdateManyOptions<T>): Promise<BulkOperationResult<T>>;
|
|
13
|
+
declare function localDelete<T extends keyof GeneratedTypes['collections']>(options: DeleteByIDOptions<T>): Promise<GeneratedTypes['collections'][T]>;
|
|
14
|
+
declare function localDelete<T extends keyof GeneratedTypes['collections']>(options: DeleteManyOptions<T>): Promise<BulkOperationResult<T>>;
|
|
9
15
|
declare const _default: {
|
|
10
16
|
find: typeof find;
|
|
11
17
|
findByID: typeof findByID;
|
|
12
18
|
create: typeof create;
|
|
13
|
-
update: typeof
|
|
19
|
+
update: typeof localUpdate;
|
|
14
20
|
localDelete: typeof localDelete;
|
|
15
21
|
auth: {
|
|
16
22
|
login: typeof import("../../../auth/operations/local/login").default;
|
|
@@ -12,12 +12,18 @@ const local_1 = __importDefault(require("../../../auth/operations/local"));
|
|
|
12
12
|
const findVersionByID_1 = __importDefault(require("./findVersionByID"));
|
|
13
13
|
const findVersions_1 = __importDefault(require("./findVersions"));
|
|
14
14
|
const restoreVersion_1 = __importDefault(require("./restoreVersion"));
|
|
15
|
+
async function localUpdate(options) {
|
|
16
|
+
return (0, update_1.default)(this, options);
|
|
17
|
+
}
|
|
18
|
+
async function localDelete(options) {
|
|
19
|
+
return (0, delete_1.default)(this, options);
|
|
20
|
+
}
|
|
15
21
|
exports.default = {
|
|
16
22
|
find: find_1.default,
|
|
17
23
|
findByID: findByID_1.default,
|
|
18
24
|
create: create_1.default,
|
|
19
|
-
update:
|
|
20
|
-
localDelete
|
|
25
|
+
update: localUpdate,
|
|
26
|
+
localDelete,
|
|
21
27
|
auth: local_1.default,
|
|
22
28
|
findVersionByID: findVersionByID_1.default,
|
|
23
29
|
findVersions: findVersions_1.default,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/collections/operations/local/index.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/collections/operations/local/index.ts"],"names":[],"mappings":";;;;;AACA,kDAA0B;AAC1B,0DAAkC;AAClC,sDAA8B;AAC9B,sDAAgI;AAChI,sDAAqI;AACrI,2EAAkD;AAClD,wEAAgD;AAChD,kEAA0C;AAC1C,sEAA8C;AAK9C,KAAK,UAAU,WAAW,CAAiD,OAAyB;IAClG,OAAO,IAAA,gBAAM,EAAI,IAAI,EAAE,OAAO,CAAC,CAAC;AAClC,CAAC;AAID,KAAK,UAAU,WAAW,CAAiD,OAAyB;IAClG,OAAO,IAAA,gBAAW,EAAI,IAAI,EAAE,OAAO,CAAC,CAAC;AACvC,CAAC;AAED,kBAAe;IACb,IAAI,EAAJ,cAAI;IACJ,QAAQ,EAAR,kBAAQ;IACR,MAAM,EAAN,gBAAM;IACN,MAAM,EAAE,WAAW;IACnB,WAAW;IACX,IAAI,EAAJ,eAAI;IACJ,eAAe,EAAf,yBAAe;IACf,YAAY,EAAZ,sBAAY;IACZ,cAAc,EAAd,wBAAc;CACf,CAAC"}
|