sfdx-easy-sources 0.9.1-develop.3 → 0.9.1
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/lib/commands/easysources/permissionsets/delete.js +2 -74
- package/lib/commands/easysources/permissionsets/delete.js.map +1 -1
- package/lib/commands/easysources/profiles/delete.js +2 -74
- package/lib/commands/easysources/profiles/delete.js.map +1 -1
- package/lib/utils/commands/deleter.d.ts +10 -0
- package/lib/utils/commands/deleter.js +130 -0
- package/lib/utils/commands/deleter.js.map +1 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
|
@@ -10,17 +10,10 @@ exports.permissionsetDelete = void 0;
|
|
|
10
10
|
const os = require("os");
|
|
11
11
|
const command_1 = require("@salesforce/command");
|
|
12
12
|
const core_1 = require("@salesforce/core");
|
|
13
|
-
const fs = require('fs-extra');
|
|
14
|
-
const path_1 = require("path");
|
|
15
13
|
const performance_1 = require("../../../utils/performance");
|
|
16
14
|
const constants_permissionsets_1 = require("../../../utils/constants/constants_permissionsets");
|
|
17
|
-
const
|
|
18
|
-
const utils_1 = require("../../../utils/utils");
|
|
15
|
+
const deleter_1 = require("../../../utils/commands/deleter");
|
|
19
16
|
const constants_1 = require("../../../utils/constants/constants");
|
|
20
|
-
const localSettings_1 = require("../../../utils/localSettings");
|
|
21
|
-
const csvWriter_1 = require("../../../utils/csvWriter");
|
|
22
|
-
const utils_2 = require("../../../utils/commands/utils");
|
|
23
|
-
const settings = (0, localSettings_1.loadSettings)();
|
|
24
17
|
// Initialize Messages with the current plugin directory
|
|
25
18
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
26
19
|
// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core,
|
|
@@ -71,72 +64,7 @@ Delete.flagsConfig = {
|
|
|
71
64
|
* @returns Promise with delete operation result
|
|
72
65
|
*/
|
|
73
66
|
async function permissionsetDelete(options) {
|
|
74
|
-
|
|
75
|
-
const type = options.type;
|
|
76
|
-
const tagid = options.tagid;
|
|
77
|
-
if (!type)
|
|
78
|
-
throw new core_1.SfError(messages.getMessage('errorNoTypeFlag'));
|
|
79
|
-
if (!tagid)
|
|
80
|
-
throw new core_1.SfError(messages.getMessage('errorNoTagIdFlag'));
|
|
81
|
-
if (!Object.keys(constants_permissionsets_1.PERMSET_ITEMS).includes(type))
|
|
82
|
-
throw new core_1.SfError(messages.getMessage('errorNoValidTypeFlag'));
|
|
83
|
-
const baseInputDir = (0, path_1.join)((options["es-csv"] || settings['easysources-csv-path'] || constants_1.DEFAULT_ESCSV_PATH), constants_permissionsets_1.PERMSETS_SUBPATH);
|
|
84
|
-
const inputProfile = options.input;
|
|
85
|
-
try {
|
|
86
|
-
(0, filesUtils_1.checkDirOrErrorSync)(baseInputDir);
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
return (0, utils_2.jsonAndPrintError)(error.message);
|
|
90
|
-
}
|
|
91
|
-
// Initialize result object
|
|
92
|
-
const result = { result: 'OK', items: {} };
|
|
93
|
-
var dirList = [];
|
|
94
|
-
if (inputProfile) {
|
|
95
|
-
dirList = inputProfile.split(',');
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
dirList = fs.readdirSync(baseInputDir, { withFileTypes: true })
|
|
99
|
-
.filter(item => item.isDirectory())
|
|
100
|
-
.map(item => item.name);
|
|
101
|
-
}
|
|
102
|
-
// dir is the profile name without the extension
|
|
103
|
-
for (const dir of dirList) {
|
|
104
|
-
try {
|
|
105
|
-
console.log('Deleting on: ' + dir);
|
|
106
|
-
// type is a profile section (applicationVisibilities, classAccess ecc)
|
|
107
|
-
const csvFilePath = (0, path_1.join)(baseInputDir, dir, (0, filesUtils_1.calcCsvFilename)(dir, type));
|
|
108
|
-
if (fs.existsSync(csvFilePath)) {
|
|
109
|
-
var jsonMap = await (0, filesUtils_1.readCsvToJsonMap)(csvFilePath);
|
|
110
|
-
for (var k of tagid.split(',')) {
|
|
111
|
-
jsonMap.delete(k);
|
|
112
|
-
}
|
|
113
|
-
var jsonArray = Array.from(jsonMap.values());
|
|
114
|
-
const headers = constants_permissionsets_1.PERMSET_ITEMS[type].headers;
|
|
115
|
-
if (options.sort === 'true') {
|
|
116
|
-
jsonArray = (0, utils_1.sortByKey)(jsonArray);
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
const csvContent = await csvWriter.toCsv(jsonArray, headers);
|
|
120
|
-
fs.writeFileSync(csvFilePath, csvContent, { flag: 'w+' });
|
|
121
|
-
// file written successfully
|
|
122
|
-
}
|
|
123
|
-
catch (err) {
|
|
124
|
-
console.error(err);
|
|
125
|
-
throw new Error(`Error writing cleaned CSV for permissionSet ${dir}, section ${type}`);
|
|
126
|
-
}
|
|
127
|
-
// PermissionSet processed successfully
|
|
128
|
-
result.items[dir] = { result: 'OK' };
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
console.error(`Error processing permissionSet ${dir}:`, error);
|
|
133
|
-
result.items[dir] = {
|
|
134
|
-
result: 'KO',
|
|
135
|
-
error: error.message || 'Unknown error occurred'
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return result;
|
|
67
|
+
return (0, deleter_1.deleteFromCsv)(options, constants_permissionsets_1.PERMSETS_SUBPATH, constants_permissionsets_1.PERMSET_ITEMS);
|
|
140
68
|
}
|
|
141
69
|
exports.permissionsetDelete = permissionsetDelete;
|
|
142
70
|
//# sourceMappingURL=delete.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../../src/commands/easysources/permissionsets/delete.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,yBAAyB;AACzB,iDAAyD;AACzD,
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../../src/commands/easysources/permissionsets/delete.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,yBAAyB;AACzB,iDAAyD;AACzD,2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AqB,CAAC;KAC1D,CAAC;IACF,KAAK,EAAE,eAAK,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,sBAAsB,CAAC;KAC3D,CAAC;IACF,IAAI,EAAE,eAAK,CAAC,IAAI,CAAC;QACb,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,qBAAqB,EAAE,CAAC,MAAM,CAAC,CAAC;QACjE,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;QAC1B,OAAO,EAAE,MAAM;KAClB,CAAC;CACL,CAAC;AAaN;;;;;;GAMG;AACI,KAAK,UAAU,mBAAmB,CAAC,OAAY;IAClD,OAAO,IAAA,uBAAa,EAAC,OAAO,EAAE,2CAAgB,EAAE,wCAAa,CAAC,CAAC;AACnE,CAAC;AAFD,kDAEC"}
|
|
@@ -10,17 +10,10 @@ exports.profileDelete = void 0;
|
|
|
10
10
|
const os = require("os");
|
|
11
11
|
const command_1 = require("@salesforce/command");
|
|
12
12
|
const core_1 = require("@salesforce/core");
|
|
13
|
-
const fs = require('fs-extra');
|
|
14
|
-
const path_1 = require("path");
|
|
15
13
|
const performance_1 = require("../../../utils/performance");
|
|
16
14
|
const constants_profiles_1 = require("../../../utils/constants/constants_profiles");
|
|
17
|
-
const
|
|
18
|
-
const utils_1 = require("../../../utils/utils");
|
|
15
|
+
const deleter_1 = require("../../../utils/commands/deleter");
|
|
19
16
|
const constants_1 = require("../../../utils/constants/constants");
|
|
20
|
-
const localSettings_1 = require("../../../utils/localSettings");
|
|
21
|
-
const csvWriter_1 = require("../../../utils/csvWriter");
|
|
22
|
-
const utils_2 = require("../../../utils/commands/utils");
|
|
23
|
-
const settings = (0, localSettings_1.loadSettings)();
|
|
24
17
|
// Initialize Messages with the current plugin directory
|
|
25
18
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
26
19
|
// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core,
|
|
@@ -65,72 +58,7 @@ Delete.flagsConfig = {
|
|
|
65
58
|
};
|
|
66
59
|
// Export a profile-specific delete function that encapsulates profile constants
|
|
67
60
|
async function profileDelete(options) {
|
|
68
|
-
|
|
69
|
-
const type = options.type;
|
|
70
|
-
const tagid = options.tagid;
|
|
71
|
-
if (!type)
|
|
72
|
-
throw new Error('Type parameter is required');
|
|
73
|
-
if (!tagid)
|
|
74
|
-
throw new Error('TagId parameter is required');
|
|
75
|
-
if (!Object.keys(constants_profiles_1.PROFILE_ITEMS).includes(type))
|
|
76
|
-
throw new Error('Invalid type parameter');
|
|
77
|
-
const baseInputDir = (0, path_1.join)((options["es-csv"] || settings['easysources-csv-path'] || constants_1.DEFAULT_ESCSV_PATH), constants_profiles_1.PROFILES_SUBPATH);
|
|
78
|
-
const inputProfile = options.input;
|
|
79
|
-
try {
|
|
80
|
-
(0, filesUtils_1.checkDirOrErrorSync)(baseInputDir);
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
return (0, utils_2.jsonAndPrintError)(error.message);
|
|
84
|
-
}
|
|
85
|
-
// Initialize result object
|
|
86
|
-
const result = { result: 'OK', items: {} };
|
|
87
|
-
var dirList = [];
|
|
88
|
-
if (inputProfile) {
|
|
89
|
-
dirList = inputProfile.split(',');
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
dirList = fs.readdirSync(baseInputDir, { withFileTypes: true })
|
|
93
|
-
.filter(item => item.isDirectory())
|
|
94
|
-
.map(item => item.name);
|
|
95
|
-
}
|
|
96
|
-
// dir is the profile name without the extension
|
|
97
|
-
for (const dir of dirList) {
|
|
98
|
-
try {
|
|
99
|
-
console.log('Deleting on: ' + dir);
|
|
100
|
-
// type is a profile section (applicationVisibilities, classAccess ecc)
|
|
101
|
-
const csvFilePath = (0, path_1.join)(baseInputDir, dir, (0, filesUtils_1.calcCsvFilename)(dir, type));
|
|
102
|
-
if (fs.existsSync(csvFilePath)) {
|
|
103
|
-
var jsonMap = await (0, filesUtils_1.readCsvToJsonMap)(csvFilePath);
|
|
104
|
-
for (var k of tagid.split(',')) {
|
|
105
|
-
jsonMap.delete(k);
|
|
106
|
-
}
|
|
107
|
-
var jsonArray = Array.from(jsonMap.values());
|
|
108
|
-
const headers = constants_profiles_1.PROFILE_ITEMS[type].headers;
|
|
109
|
-
if (options.sort === 'true') {
|
|
110
|
-
jsonArray = (0, utils_1.sortByKey)(jsonArray);
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
const csvContent = await csvWriter.toCsv(jsonArray, headers);
|
|
114
|
-
fs.writeFileSync(csvFilePath, csvContent, { flag: 'w+' });
|
|
115
|
-
// file written successfully
|
|
116
|
-
}
|
|
117
|
-
catch (err) {
|
|
118
|
-
console.error(err);
|
|
119
|
-
throw new Error(`Error writing cleaned CSV for profile ${dir}, section ${type}`);
|
|
120
|
-
}
|
|
121
|
-
// Profile processed successfully
|
|
122
|
-
result.items[dir] = { result: 'OK' };
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
console.error(`Error processing profile ${dir}:`, error);
|
|
127
|
-
result.items[dir] = {
|
|
128
|
-
result: 'KO',
|
|
129
|
-
error: error.message || 'Unknown error occurred'
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return result;
|
|
61
|
+
return (0, deleter_1.deleteFromCsv)(options, constants_profiles_1.PROFILES_SUBPATH, constants_profiles_1.PROFILE_ITEMS);
|
|
134
62
|
}
|
|
135
63
|
exports.profileDelete = profileDelete;
|
|
136
64
|
//# sourceMappingURL=delete.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../../src/commands/easysources/profiles/delete.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,yBAAyB;AACzB,iDAAyD;AACzD,2CAA4C;AAE5C,
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../../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K,CAAC,MAAM,CAAC;QACf,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,qBAAqB,CAAC;KAC1D,CAAC;IACF,KAAK,EAAE,eAAK,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,sBAAsB,CAAC;KAC3D,CAAC;IACF,IAAI,EAAE,eAAK,CAAC,IAAI,CAAC;QACb,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,qBAAqB,EAAE,CAAC,MAAM,CAAC,CAAC;QACjE,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;QAC1B,OAAO,EAAE,MAAM;KAClB,CAAC;CACL,CAAC;AAYN,gFAAgF;AACzE,KAAK,UAAU,aAAa,CAAC,OAAY;IAC5C,OAAO,IAAA,uBAAa,EAAC,OAAO,EAAE,qCAAgB,EAAE,kCAAa,CAAC,CAAC;AACnE,CAAC;AAFD,sCAEC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic delete function for removing entries from CSV files based on tagid patterns
|
|
3
|
+
* Supports wildcard patterns for bulk deletions
|
|
4
|
+
*
|
|
5
|
+
* @param flags - Command flags containing options
|
|
6
|
+
* @param file_subpath - Subpath for the specific metadata type (e.g., PROFILES_SUBPATH, PERMSETS_SUBPATH)
|
|
7
|
+
* @param file_items - Configuration object containing metadata type definitions and headers
|
|
8
|
+
* @returns Promise with delete operation result
|
|
9
|
+
*/
|
|
10
|
+
export declare function deleteFromCsv(flags: any, file_subpath: string, file_items: any): Promise<any>;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteFromCsv = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const constants_1 = require("../constants/constants");
|
|
6
|
+
const filesUtils_1 = require("../filesUtils");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const localSettings_1 = require("../localSettings");
|
|
9
|
+
const csvWriter_1 = require("../csvWriter");
|
|
10
|
+
const utils_2 = require("./utils");
|
|
11
|
+
const fs = require('fs-extra');
|
|
12
|
+
const settings = (0, localSettings_1.loadSettings)();
|
|
13
|
+
/**
|
|
14
|
+
* Generic delete function for removing entries from CSV files based on tagid patterns
|
|
15
|
+
* Supports wildcard patterns for bulk deletions
|
|
16
|
+
*
|
|
17
|
+
* @param flags - Command flags containing options
|
|
18
|
+
* @param file_subpath - Subpath for the specific metadata type (e.g., PROFILES_SUBPATH, PERMSETS_SUBPATH)
|
|
19
|
+
* @param file_items - Configuration object containing metadata type definitions and headers
|
|
20
|
+
* @returns Promise with delete operation result
|
|
21
|
+
*/
|
|
22
|
+
async function deleteFromCsv(flags, file_subpath, file_items) {
|
|
23
|
+
const csvWriter = new csvWriter_1.default();
|
|
24
|
+
const type = flags.type;
|
|
25
|
+
const tagid = flags.tagid;
|
|
26
|
+
const baseInputDir = (0, path_1.join)((flags["es-csv"] || settings['easysources-csv-path'] || constants_1.DEFAULT_ESCSV_PATH), file_subpath);
|
|
27
|
+
const inputProfile = flags.input;
|
|
28
|
+
try {
|
|
29
|
+
if (!type)
|
|
30
|
+
throw new Error('Type parameter is required');
|
|
31
|
+
if (!tagid)
|
|
32
|
+
throw new Error('TagId parameter is required');
|
|
33
|
+
if (!Object.keys(file_items).includes(type))
|
|
34
|
+
throw new Error('Invalid type parameter');
|
|
35
|
+
(0, filesUtils_1.checkDirOrErrorSync)(baseInputDir);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return (0, utils_2.jsonAndPrintError)(error.message);
|
|
39
|
+
}
|
|
40
|
+
// Initialize result object
|
|
41
|
+
const result = { result: 'OK', items: {} };
|
|
42
|
+
var dirList = [];
|
|
43
|
+
if (inputProfile) {
|
|
44
|
+
dirList = inputProfile.split(',');
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
dirList = fs.readdirSync(baseInputDir, { withFileTypes: true })
|
|
48
|
+
.filter(item => item.isDirectory())
|
|
49
|
+
.map(item => item.name);
|
|
50
|
+
}
|
|
51
|
+
// dir is the profile/permissionset name without the extension
|
|
52
|
+
for (const dir of dirList) {
|
|
53
|
+
try {
|
|
54
|
+
console.log('Deleting on: ' + dir);
|
|
55
|
+
// type is a section (applicationVisibilities, classAccess ecc)
|
|
56
|
+
const csvFilePath = (0, path_1.join)(baseInputDir, dir, (0, filesUtils_1.calcCsvFilename)(dir, type));
|
|
57
|
+
if (fs.existsSync(csvFilePath)) {
|
|
58
|
+
var jsonMap = await (0, filesUtils_1.readCsvToJsonMap)(csvFilePath);
|
|
59
|
+
for (var k of tagid.split(',')) {
|
|
60
|
+
const trimmedK = k.trim();
|
|
61
|
+
// Check if wildcard pattern is used
|
|
62
|
+
if (trimmedK.startsWith('*') || trimmedK.endsWith('*')) {
|
|
63
|
+
const keysToDelete = [];
|
|
64
|
+
if (trimmedK.startsWith('*') && trimmedK.endsWith('*')) {
|
|
65
|
+
// *esempio* - contains
|
|
66
|
+
const searchTerm = trimmedK.slice(1, -1);
|
|
67
|
+
for (const key of jsonMap.keys()) {
|
|
68
|
+
if (key.includes(searchTerm)) {
|
|
69
|
+
keysToDelete.push(key);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (trimmedK.startsWith('*')) {
|
|
74
|
+
// *esempio - ends with
|
|
75
|
+
const searchTerm = trimmedK.slice(1);
|
|
76
|
+
for (const key of jsonMap.keys()) {
|
|
77
|
+
if (key.endsWith(searchTerm)) {
|
|
78
|
+
keysToDelete.push(key);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (trimmedK.endsWith('*')) {
|
|
83
|
+
// esempio* - starts with
|
|
84
|
+
const searchTerm = trimmedK.slice(0, -1);
|
|
85
|
+
for (const key of jsonMap.keys()) {
|
|
86
|
+
if (key.startsWith(searchTerm)) {
|
|
87
|
+
keysToDelete.push(key);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Delete all matching keys
|
|
92
|
+
for (const keyToDelete of keysToDelete) {
|
|
93
|
+
jsonMap.delete(keyToDelete);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// No wildcard - exact match
|
|
98
|
+
jsonMap.delete(trimmedK);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
var jsonArray = Array.from(jsonMap.values());
|
|
102
|
+
const headers = file_items[type].headers;
|
|
103
|
+
if (flags.sort === 'true') {
|
|
104
|
+
jsonArray = (0, utils_1.sortByKey)(jsonArray);
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const csvContent = await csvWriter.toCsv(jsonArray, headers);
|
|
108
|
+
fs.writeFileSync(csvFilePath, csvContent, { flag: 'w+' });
|
|
109
|
+
// file written successfully
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
console.error(err);
|
|
113
|
+
throw new Error(`Error writing cleaned CSV for ${dir}, section ${type}`);
|
|
114
|
+
}
|
|
115
|
+
// Item processed successfully
|
|
116
|
+
result.items[dir] = { result: 'OK' };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
console.error(`Error processing ${dir}:`, error);
|
|
121
|
+
result.items[dir] = {
|
|
122
|
+
result: 'KO',
|
|
123
|
+
error: error.message || 'Unknown error occurred'
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
exports.deleteFromCsv = deleteFromCsv;
|
|
130
|
+
//# sourceMappingURL=deleter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleter.js","sourceRoot":"","sources":["../../../src/utils/commands/deleter.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAC5B,sD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