@webiny/api-aco 0.0.0-unstable.d7f521b032 → 0.0.0-unstable.de38392959

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.
Files changed (192) hide show
  1. package/README.md +6 -6
  2. package/apps/AcoApp.d.ts +21 -0
  3. package/apps/AcoApp.js +143 -0
  4. package/apps/AcoApp.js.map +1 -0
  5. package/apps/AcoApps.d.ts +10 -0
  6. package/apps/AcoApps.js +75 -0
  7. package/apps/AcoApps.js.map +1 -0
  8. package/apps/app.gql.d.ts +3 -0
  9. package/apps/app.gql.js +60 -0
  10. package/apps/app.gql.js.map +1 -0
  11. package/apps/index.d.ts +2 -0
  12. package/apps/index.js +29 -0
  13. package/apps/index.js.map +1 -0
  14. package/createAcoContext.d.ts +5 -1
  15. package/createAcoContext.js +159 -28
  16. package/createAcoContext.js.map +1 -1
  17. package/createAcoGraphQL.d.ts +2 -2
  18. package/createAcoGraphQL.js +49 -15
  19. package/createAcoGraphQL.js.map +1 -1
  20. package/createAcoHooks.js +9 -3
  21. package/createAcoHooks.js.map +1 -1
  22. package/createAcoModels.js +6 -44
  23. package/createAcoModels.js.map +1 -1
  24. package/createAcoStorageOperations.d.ts +0 -1
  25. package/createAcoStorageOperations.js +10 -7
  26. package/createAcoStorageOperations.js.map +1 -1
  27. package/filter/filter.crud.d.ts +3 -0
  28. package/filter/filter.crud.js +94 -0
  29. package/filter/filter.crud.js.map +1 -0
  30. package/filter/filter.gql.d.ts +3 -0
  31. package/filter/filter.gql.js +153 -0
  32. package/filter/filter.gql.js.map +1 -0
  33. package/filter/filter.model.d.ts +2 -0
  34. package/filter/filter.model.js +125 -0
  35. package/filter/filter.model.js.map +1 -0
  36. package/filter/filter.so.d.ts +3 -0
  37. package/filter/filter.so.js +98 -0
  38. package/filter/filter.so.js.map +1 -0
  39. package/filter/filter.types.d.ts +95 -0
  40. package/filter/filter.types.js +14 -0
  41. package/filter/filter.types.js.map +1 -0
  42. package/folder/folder.crud.d.ts +8 -1
  43. package/folder/folder.crud.js +201 -4
  44. package/folder/folder.crud.js.map +1 -1
  45. package/folder/folder.gql.js +99 -7
  46. package/folder/folder.gql.js.map +1 -1
  47. package/folder/folder.model.d.ts +2 -4
  48. package/folder/folder.model.js +56 -31
  49. package/folder/folder.model.js.map +1 -1
  50. package/folder/folder.so.d.ts +1 -6
  51. package/folder/folder.so.js +127 -112
  52. package/folder/folder.so.js.map +1 -1
  53. package/folder/folder.types.d.ts +36 -4
  54. package/folder/folder.types.js +3 -1
  55. package/folder/folder.types.js.map +1 -1
  56. package/folder/onFolderBeforeDeleteAco.hook.d.ts +2 -0
  57. package/folder/onFolderBeforeDeleteAco.hook.js +67 -0
  58. package/folder/onFolderBeforeDeleteAco.hook.js.map +1 -0
  59. package/folder/onFolderBeforeDeleteFm.hook.d.ts +2 -0
  60. package/folder/onFolderBeforeDeleteFm.hook.js +49 -0
  61. package/folder/onFolderBeforeDeleteFm.hook.js.map +1 -0
  62. package/folder/onFolderBeforeDeleteHcms.hook.d.ts +2 -0
  63. package/folder/onFolderBeforeDeleteHcms.hook.js +56 -0
  64. package/folder/onFolderBeforeDeleteHcms.hook.js.map +1 -0
  65. package/index.d.ts +9 -1
  66. package/index.js +57 -6
  67. package/index.js.map +1 -1
  68. package/package.json +38 -31
  69. package/plugins/AcoAppModifierPlugin.d.ts +43 -0
  70. package/plugins/AcoAppModifierPlugin.js +58 -0
  71. package/plugins/AcoAppModifierPlugin.js.map +1 -0
  72. package/plugins/AcoAppRegisterPlugin.d.ts +8 -0
  73. package/plugins/AcoAppRegisterPlugin.js +21 -0
  74. package/plugins/AcoAppRegisterPlugin.js.map +1 -0
  75. package/plugins/index.d.ts +2 -0
  76. package/plugins/index.js +29 -0
  77. package/plugins/index.js.map +1 -0
  78. package/record/graphql/createAppResolvers.d.ts +14 -0
  79. package/record/graphql/createAppResolvers.js +115 -0
  80. package/record/graphql/createAppResolvers.js.map +1 -0
  81. package/record/graphql/createAppSchema.d.ts +9 -0
  82. package/record/graphql/createAppSchema.js +147 -0
  83. package/record/graphql/createAppSchema.js.map +1 -0
  84. package/record/record.crud.js +49 -13
  85. package/record/record.crud.js.map +1 -1
  86. package/record/record.gql.d.ts +8 -3
  87. package/record/record.gql.js +38 -113
  88. package/record/record.gql.js.map +1 -1
  89. package/record/record.model.d.ts +8 -4
  90. package/record/record.model.js +44 -33
  91. package/record/record.model.js.map +1 -1
  92. package/record/record.so.d.ts +1 -6
  93. package/record/record.so.js +126 -64
  94. package/record/record.so.js.map +1 -1
  95. package/record/record.types.d.ts +69 -17
  96. package/record/record.types.js +3 -1
  97. package/record/record.types.js.map +1 -1
  98. package/types.d.ts +78 -8
  99. package/types.js +56 -1
  100. package/types.js.map +1 -1
  101. package/utils/FolderLevelPermissions.d.ts +71 -0
  102. package/utils/FolderLevelPermissions.js +353 -0
  103. package/utils/FolderLevelPermissions.js.map +1 -0
  104. package/utils/acoRecordId.d.ts +6 -0
  105. package/utils/acoRecordId.js +35 -0
  106. package/utils/acoRecordId.js.map +1 -0
  107. package/utils/createListSort.d.ts +2 -0
  108. package/utils/createListSort.js +15 -0
  109. package/utils/createListSort.js.map +1 -0
  110. package/utils/createModelField.d.ts +0 -1
  111. package/utils/createModelField.js +5 -5
  112. package/utils/createModelField.js.map +1 -1
  113. package/utils/createOperationsWrapper.d.ts +9 -0
  114. package/utils/createOperationsWrapper.js +31 -0
  115. package/utils/createOperationsWrapper.js.map +1 -0
  116. package/utils/decorators/CmsEntriesCrudDecorators.d.ts +11 -0
  117. package/utils/decorators/CmsEntriesCrudDecorators.js +190 -0
  118. package/utils/decorators/CmsEntriesCrudDecorators.js.map +1 -0
  119. package/utils/decorators/constants.d.ts +1 -0
  120. package/utils/decorators/constants.js +10 -0
  121. package/utils/decorators/constants.js.map +1 -0
  122. package/utils/decorators/createFolderType.d.ts +2 -0
  123. package/utils/decorators/createFolderType.js +18 -0
  124. package/utils/decorators/createFolderType.js.map +1 -0
  125. package/utils/decorators/filterEntriesByFolderFactory.d.ts +6 -0
  126. package/utils/decorators/filterEntriesByFolderFactory.js +37 -0
  127. package/utils/decorators/filterEntriesByFolderFactory.js.map +1 -0
  128. package/utils/decorators/isPageModel.d.ts +5 -0
  129. package/utils/decorators/isPageModel.js +20 -0
  130. package/utils/decorators/isPageModel.js.map +1 -0
  131. package/utils/decorators/where.d.ts +15 -0
  132. package/utils/decorators/where.js +60 -0
  133. package/utils/decorators/where.js.map +1 -0
  134. package/utils/ensureAuthentication.d.ts +2 -0
  135. package/utils/ensureAuthentication.js +16 -0
  136. package/utils/ensureAuthentication.js.map +1 -0
  137. package/utils/getFolderAndItsAncestors.d.ts +7 -0
  138. package/utils/getFolderAndItsAncestors.js +53 -0
  139. package/utils/getFolderAndItsAncestors.js.map +1 -0
  140. package/utils/isInstallationPending.js +3 -1
  141. package/utils/isInstallationPending.js.map +1 -1
  142. package/utils/modelFactory.d.ts +2 -4
  143. package/utils/modelFactory.js +7 -8
  144. package/utils/modelFactory.js.map +1 -1
  145. package/utils/pickEntryFieldValues.d.ts +3 -0
  146. package/utils/pickEntryFieldValues.js +31 -0
  147. package/utils/pickEntryFieldValues.js.map +1 -0
  148. package/utils/resolve.d.ts +3 -2
  149. package/utils/resolve.js +13 -2
  150. package/utils/resolve.js.map +1 -1
  151. package/context/folders.d.ts +0 -2
  152. package/context/folders.js +0 -261
  153. package/context/folders.js.map +0 -1
  154. package/context/index.d.ts +0 -2
  155. package/context/index.js +0 -22
  156. package/context/index.js.map +0 -1
  157. package/context/links.d.ts +0 -2
  158. package/context/links.js +0 -270
  159. package/context/links.js.map +0 -1
  160. package/createAcoCrud.d.ts +0 -2
  161. package/createAcoCrud.js +0 -17
  162. package/createAcoCrud.js.map +0 -1
  163. package/createAcoFields.d.ts +0 -2
  164. package/createAcoFields.js +0 -40
  165. package/createAcoFields.js.map +0 -1
  166. package/folder/onFolderBeforeDelete.hook.d.ts +0 -2
  167. package/folder/onFolderBeforeDelete.hook.js +0 -53
  168. package/folder/onFolderBeforeDelete.hook.js.map +0 -1
  169. package/graphql/base.gql.d.ts +0 -3
  170. package/graphql/base.gql.js +0 -63
  171. package/graphql/base.gql.js.map +0 -1
  172. package/graphql/folders.gql.d.ts +0 -3
  173. package/graphql/folders.gql.js +0 -126
  174. package/graphql/folders.gql.js.map +0 -1
  175. package/graphql/index.d.ts +0 -1
  176. package/graphql/index.js +0 -15
  177. package/graphql/index.js.map +0 -1
  178. package/graphql/links.gql.d.ts +0 -3
  179. package/graphql/links.gql.js +0 -123
  180. package/graphql/links.gql.js.map +0 -1
  181. package/subscriptions/afterFolderDelete.d.ts +0 -3
  182. package/subscriptions/afterFolderDelete.js +0 -62
  183. package/subscriptions/afterFolderDelete.js.map +0 -1
  184. package/subscriptions/index.d.ts +0 -3
  185. package/subscriptions/index.js +0 -14
  186. package/subscriptions/index.js.map +0 -1
  187. package/utils/fieldResolver.d.ts +0 -16
  188. package/utils/fieldResolver.js +0 -44
  189. package/utils/fieldResolver.js.map +0 -1
  190. package/utils/getFieldValues.d.ts +0 -2
  191. package/utils/getFieldValues.js +0 -12
  192. package/utils/getFieldValues.js.map +0 -1
@@ -5,152 +5,167 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.createFolderOperations = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
8
+ var _omit = _interopRequireDefault(require("lodash/omit"));
9
9
  var _error = _interopRequireDefault(require("@webiny/error"));
10
10
  var _folder = require("./folder.model");
11
- var _createAcoStorageOperations = require("../createAcoStorageOperations");
12
- var _getFieldValues = require("../utils/getFieldValues");
11
+ var _createListSort = require("../utils/createListSort");
12
+ var _createOperationsWrapper = require("../utils/createOperationsWrapper");
13
+ var _pickEntryFieldValues = require("../utils/pickEntryFieldValues");
14
+ var _constants = require("@webiny/api-headless-cms/constants");
13
15
  const createFolderOperations = params => {
14
16
  const {
15
- cms,
16
- security
17
+ cms
17
18
  } = params;
18
- const getFolderModel = async () => {
19
- security.disableAuthorization();
20
- const model = await cms.getModel(_folder.FOLDER_MODEL_ID);
21
- security.enableAuthorization();
22
- if (!model) {
23
- throw new _error.default(`Could not find "${_folder.FOLDER_MODEL_ID}" model.`, "MODEL_NOT_FOUND_ERROR");
24
- }
25
- return model;
26
- };
27
- const getFolder = async ({
19
+ const {
20
+ withModel
21
+ } = (0, _createOperationsWrapper.createOperationsWrapper)({
22
+ ...params,
23
+ modelName: _folder.FOLDER_MODEL_ID
24
+ });
25
+ const getFolder = ({
28
26
  id,
29
27
  slug,
30
28
  type,
31
29
  parentId
32
30
  }) => {
33
- const model = await getFolderModel();
34
- security.disableAuthorization();
35
- let entry;
36
- if (id) {
37
- entry = await cms.getEntryById(model, id);
38
- } else if (slug && type) {
39
- entry = await cms.getEntry(model, {
40
- where: {
31
+ return withModel(async model => {
32
+ let entry;
33
+ if (id) {
34
+ entry = await cms.getEntryById(model, id);
35
+ } else if (slug && type) {
36
+ entry = await cms.getEntry(model, {
37
+ where: {
38
+ slug,
39
+ type,
40
+ parentId,
41
+ latest: true
42
+ }
43
+ });
44
+ }
45
+ if (!entry) {
46
+ throw new _error.default("Could not load folder.", "GET_FOLDER_ERROR", {
47
+ id,
41
48
  slug,
42
49
  type,
43
- parentId,
44
- latest: true
45
- }
46
- });
47
- }
48
- if (!entry) {
49
- throw new _error.default("Could not load folder.", "GET_FOLDER_ERROR", {
50
- id,
51
- slug,
52
- type,
53
- parentId
54
- });
55
- }
56
- security.enableAuthorization();
57
- return (0, _getFieldValues.getFieldValues)(entry, _createAcoStorageOperations.baseFields);
50
+ parentId
51
+ });
52
+ }
53
+ return (0, _pickEntryFieldValues.pickEntryFieldValues)(entry);
54
+ });
58
55
  };
59
- const checkExistingFolder = async ({
56
+ const checkExistingFolder = ({
60
57
  id,
61
58
  params
62
59
  }) => {
63
- const model = await getFolderModel();
64
- security.disableAuthorization();
65
- const {
66
- type,
67
- slug,
68
- parentId
69
- } = params;
70
- const [existings] = await cms.listLatestEntries(model, {
71
- where: {
60
+ return withModel(async model => {
61
+ const {
72
62
  type,
73
63
  slug,
74
- parentId,
75
- id_not: id
76
- },
77
- limit: 1
78
- });
79
- if (existings.length > 0) {
80
- throw new _error.default(`Folder with slug "${slug}" already exists at this level.`, "FOLDER_ALREADY_EXISTS", {
81
- id,
82
- params
64
+ parentId
65
+ } = params;
66
+
67
+ // We don't need to perform any kind of authorization or checks here. We just need to check
68
+ // if the folder already exists in the database. Hence the direct storage operations access.
69
+ const listResult = await cms.storageOperations.entries.list(model, {
70
+ ...params,
71
+ where: {
72
+ // Folders always work with latest entries. We never publish them.
73
+ latest: true,
74
+ type,
75
+ slug,
76
+ parentId,
77
+ id_not: id
78
+ },
79
+ limit: 1
83
80
  });
84
- }
85
- security.enableAuthorization();
86
- return;
81
+ if (listResult?.items?.length > 0) {
82
+ throw new _error.default(`Folder with slug "${slug}" already exists at this level.`, "FOLDER_ALREADY_EXISTS", {
83
+ id,
84
+ params
85
+ });
86
+ }
87
+ return;
88
+ });
87
89
  };
88
90
  return {
89
- getFolderModel,
90
91
  getFolder,
91
- async listFolders(params) {
92
- const model = await getFolderModel();
93
- security.disableAuthorization();
94
- const [entries, meta] = await cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
95
- where: (0, _objectSpread2.default)({}, params.where || {})
96
- }));
97
- security.enableAuthorization();
98
- return [entries.map(entry => (0, _getFieldValues.getFieldValues)(entry, _createAcoStorageOperations.baseFields)), meta];
92
+ listFolders(params) {
93
+ return withModel(async model => {
94
+ const {
95
+ sort,
96
+ where
97
+ } = params;
98
+ const [entries, meta] = await cms.listLatestEntries(model, {
99
+ ...params,
100
+ sort: (0, _createListSort.createListSort)(sort),
101
+ where: {
102
+ ...(where || {})
103
+ }
104
+ });
105
+ return [entries.map(_pickEntryFieldValues.pickEntryFieldValues), meta];
106
+ });
99
107
  },
100
- async createFolder({
108
+ createFolder({
101
109
  data
102
110
  }) {
103
- const model = await getFolderModel();
104
- security.disableAuthorization();
105
- await checkExistingFolder({
106
- params: {
107
- type: data.type,
108
- slug: data.slug,
109
- parentId: data.parentId
110
- }
111
+ return withModel(async model => {
112
+ await checkExistingFolder({
113
+ params: {
114
+ type: data.type,
115
+ slug: data.slug,
116
+ parentId: data.parentId
117
+ }
118
+ });
119
+ const entry = await cms.createEntry(model, {
120
+ ...data,
121
+ parentId: data.parentId || null
122
+ });
123
+ return (0, _pickEntryFieldValues.pickEntryFieldValues)(entry);
111
124
  });
112
- const entry = await cms.createEntry(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
113
- parentId: data.parentId || null
114
- }));
115
- security.enableAuthorization();
116
- return (0, _getFieldValues.getFieldValues)(entry, _createAcoStorageOperations.baseFields);
117
125
  },
118
- async updateFolder({
126
+ updateFolder({
119
127
  id,
120
128
  data
121
129
  }) {
122
- const {
123
- slug,
124
- parentId
125
- } = data;
126
- const model = await getFolderModel();
127
- security.disableAuthorization();
128
- const original = await getFolder({
129
- id
130
- });
131
- await checkExistingFolder({
132
- id,
133
- params: {
134
- type: original.type,
135
- slug: slug || original.slug,
136
- parentId: parentId !== undefined ? parentId : original.parentId // parentId can be `null`
137
- }
138
- });
130
+ return withModel(async model => {
131
+ const {
132
+ slug,
133
+ parentId
134
+ } = data;
135
+ const original = await getFolder({
136
+ id
137
+ });
138
+ await checkExistingFolder({
139
+ id,
140
+ params: {
141
+ type: original.type,
142
+ slug: slug || original.slug,
143
+ parentId: parentId !== undefined ? parentId : original.parentId // parentId can be `null`
144
+ }
145
+ });
139
146
 
140
- const input = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, original), data);
141
- const entry = await cms.updateEntry(model, id, input);
142
- security.enableAuthorization();
143
- return (0, _getFieldValues.getFieldValues)(entry, _createAcoStorageOperations.baseFields);
147
+ const input = {
148
+ /**
149
+ * We are omitting the standard entry meta fields:
150
+ * we don't want to override them with the ones coming from the `original` entry.
151
+ */
152
+ ...(0, _omit.default)(original, _constants.ENTRY_META_FIELDS),
153
+ ...data
154
+ };
155
+ const entry = await cms.updateEntry(model, id, input);
156
+ return (0, _pickEntryFieldValues.pickEntryFieldValues)(entry);
157
+ });
144
158
  },
145
- async deleteFolder({
159
+ deleteFolder({
146
160
  id
147
161
  }) {
148
- const model = await getFolderModel();
149
- security.disableAuthorization();
150
- await cms.deleteEntry(model, id);
151
- security.enableAuthorization();
152
- return true;
162
+ return withModel(async model => {
163
+ await cms.deleteEntry(model, id);
164
+ return true;
165
+ });
153
166
  }
154
167
  };
155
168
  };
156
- exports.createFolderOperations = createFolderOperations;
169
+ exports.createFolderOperations = createFolderOperations;
170
+
171
+ //# sourceMappingURL=folder.so.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createFolderOperations","params","cms","security","getFolderModel","disableAuthorization","model","getModel","FOLDER_MODEL_ID","enableAuthorization","WebinyError","getFolder","id","slug","type","parentId","entry","getEntryById","getEntry","where","latest","getFieldValues","baseFields","checkExistingFolder","existings","listLatestEntries","id_not","limit","length","listFolders","entries","meta","map","createFolder","data","createEntry","updateFolder","original","undefined","input","updateEntry","deleteFolder","deleteEntry"],"sources":["folder.so.ts"],"sourcesContent":["import { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport WebinyError from \"@webiny/error\";\n\nimport { FOLDER_MODEL_ID } from \"./folder.model\";\nimport { baseFields, CreateAcoStorageOperationsParams } from \"~/createAcoStorageOperations\";\nimport { getFieldValues } from \"~/utils/getFieldValues\";\n\nimport { AcoFolderStorageOperations as BaseAcoFolderStorageOperations } from \"./folder.types\";\n\ninterface AcoFolderStorageOperations extends BaseAcoFolderStorageOperations {\n getFolderModel(): Promise<CmsModel>;\n}\n\ninterface AcoCheckExistingFolderParams {\n params: {\n type: string;\n slug: string;\n parentId?: string | null;\n };\n id?: string;\n}\n\nexport const createFolderOperations = (\n params: CreateAcoStorageOperationsParams\n): AcoFolderStorageOperations => {\n const { cms, security } = params;\n const getFolderModel = async () => {\n security.disableAuthorization();\n const model = await cms.getModel(FOLDER_MODEL_ID);\n security.enableAuthorization();\n if (!model) {\n throw new WebinyError(\n `Could not find \"${FOLDER_MODEL_ID}\" model.`,\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n\n const getFolder: AcoFolderStorageOperations[\"getFolder\"] = async ({\n id,\n slug,\n type,\n parentId\n }) => {\n const model = await getFolderModel();\n security.disableAuthorization();\n\n let entry;\n\n if (id) {\n entry = await cms.getEntryById(model, id);\n } else if (slug && type) {\n entry = await cms.getEntry(model, { where: { slug, type, parentId, latest: true } });\n }\n\n if (!entry) {\n throw new WebinyError(\"Could not load folder.\", \"GET_FOLDER_ERROR\", {\n id,\n slug,\n type,\n parentId\n });\n }\n\n security.enableAuthorization();\n return getFieldValues(entry, baseFields);\n };\n\n const checkExistingFolder = async ({ id, params }: AcoCheckExistingFolderParams) => {\n const model = await getFolderModel();\n security.disableAuthorization();\n\n const { type, slug, parentId } = params;\n\n const [existings] = await cms.listLatestEntries(model, {\n where: {\n type,\n slug,\n parentId,\n id_not: id\n },\n limit: 1\n });\n\n if (existings.length > 0) {\n throw new WebinyError(\n `Folder with slug \"${slug}\" already exists at this level.`,\n \"FOLDER_ALREADY_EXISTS\",\n {\n id,\n params\n }\n );\n }\n\n security.enableAuthorization();\n return;\n };\n\n return {\n getFolderModel,\n getFolder,\n async listFolders(params) {\n const model = await getFolderModel();\n security.disableAuthorization();\n\n const [entries, meta] = await cms.listLatestEntries(model, {\n ...params,\n where: {\n ...(params.where || {})\n }\n });\n\n security.enableAuthorization();\n return [entries.map(entry => getFieldValues(entry, baseFields)), meta];\n },\n async createFolder({ data }) {\n const model = await getFolderModel();\n security.disableAuthorization();\n\n await checkExistingFolder({\n params: {\n type: data.type,\n slug: data.slug,\n parentId: data.parentId\n }\n });\n\n const entry = await cms.createEntry(model, {\n ...data,\n parentId: data.parentId || null\n });\n\n security.enableAuthorization();\n return getFieldValues(entry, baseFields);\n },\n async updateFolder({ id, data }) {\n const { slug, parentId } = data;\n const model = await getFolderModel();\n security.disableAuthorization();\n\n const original = await getFolder({ id });\n\n await checkExistingFolder({\n id,\n params: {\n type: original.type,\n slug: slug || original.slug,\n parentId: parentId !== undefined ? parentId : original.parentId // parentId can be `null`\n }\n });\n\n const input = {\n ...original,\n ...data\n };\n\n const entry = await cms.updateEntry(model, id, input);\n security.enableAuthorization();\n return getFieldValues(entry, baseFields);\n },\n async deleteFolder({ id }) {\n const model = await getFolderModel();\n security.disableAuthorization();\n\n await cms.deleteEntry(model, id);\n\n security.enableAuthorization();\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;AACA;AAEA;AACA;AACA;AAiBO,MAAMA,sBAAsB,GAC/BC,MAAwC,IACX;EAC7B,MAAM;IAAEC,GAAG;IAAEC;EAAS,CAAC,GAAGF,MAAM;EAChC,MAAMG,cAAc,GAAG,YAAY;IAC/BD,QAAQ,CAACE,oBAAoB,EAAE;IAC/B,MAAMC,KAAK,GAAG,MAAMJ,GAAG,CAACK,QAAQ,CAACC,uBAAe,CAAC;IACjDL,QAAQ,CAACM,mBAAmB,EAAE;IAC9B,IAAI,CAACH,KAAK,EAAE;MACR,MAAM,IAAII,cAAW,CAChB,mBAAkBF,uBAAgB,UAAS,EAC5C,uBAAuB,CAC1B;IACL;IACA,OAAOF,KAAK;EAChB,CAAC;EAED,MAAMK,SAAkD,GAAG,OAAO;IAC9DC,EAAE;IACFC,IAAI;IACJC,IAAI;IACJC;EACJ,CAAC,KAAK;IACF,MAAMT,KAAK,GAAG,MAAMF,cAAc,EAAE;IACpCD,QAAQ,CAACE,oBAAoB,EAAE;IAE/B,IAAIW,KAAK;IAET,IAAIJ,EAAE,EAAE;MACJI,KAAK,GAAG,MAAMd,GAAG,CAACe,YAAY,CAACX,KAAK,EAAEM,EAAE,CAAC;IAC7C,CAAC,MAAM,IAAIC,IAAI,IAAIC,IAAI,EAAE;MACrBE,KAAK,GAAG,MAAMd,GAAG,CAACgB,QAAQ,CAACZ,KAAK,EAAE;QAAEa,KAAK,EAAE;UAAEN,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UACnBD,IAAI,EAAEA,IAAI,IAAIwB,QAAQ,CAACxB,IAAI;UAC3BE,QAAQ,EAAEA,QAAQ,KAAKuB,SAAS,GAAGvB,QAAQ,GAAGsB,QAAQ,CAACtB,QAAQ,CAAC;QACpE;MACJ,CAAC,CAAC;;MAEF,MAAMwB,KAAK,+DACJF,QAAQ,GACRH,IAAI,CACV;MAED,MAAMlB,KAAK,GAAG,MAAMd,GAAG,CAACsC,WAAW,CAAClC,KAAK,EAAEM,EAAE,EAAE2B,KAAK,CAAC;MACrDpC,QAAQ,CAACM,mBAAmB,EAAE;MAC9B,OAAO,IAAAY,8BAAc,EAACL,KAAK,EAAEM,sCAAU,CAAC;IAC5C,CAAC;IACD,MAAMmB,YAAY,CAAC;MAAE7B;IAAG,CAAC,EAAE;MACvB,MAAMN,KAAK,GAAG,MAAMF,cAAc,EAAE;MACpCD,QAAQ,CAACE,oBAAoB,EAAE;MAE/B,MAAMH,GAAG,CAACwC,WAAW,CAACpC,KAAK,EAAEM,EAAE,CAAC;MAEhCT,QAAQ,CAACM,mBAAmB,EAAE;MAC9B,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["_omit","_interopRequireDefault","require","_error","_folder","_createListSort","_createOperationsWrapper","_pickEntryFieldValues","_constants","createFolderOperations","params","cms","withModel","createOperationsWrapper","modelName","FOLDER_MODEL_ID","getFolder","id","slug","type","parentId","model","entry","getEntryById","getEntry","where","latest","WebinyError","pickEntryFieldValues","checkExistingFolder","listResult","storageOperations","entries","list","id_not","limit","items","length","listFolders","sort","meta","listLatestEntries","createListSort","map","createFolder","data","createEntry","updateFolder","original","undefined","input","omit","ENTRY_META_FIELDS","updateEntry","deleteFolder","deleteEntry","exports"],"sources":["folder.so.ts"],"sourcesContent":["import omit from \"lodash/omit\";\nimport WebinyError from \"@webiny/error\";\nimport { FOLDER_MODEL_ID } from \"./folder.model\";\nimport { CreateAcoStorageOperationsParams } from \"~/createAcoStorageOperations\";\nimport { createListSort } from \"~/utils/createListSort\";\nimport { createOperationsWrapper } from \"~/utils/createOperationsWrapper\";\nimport { pickEntryFieldValues } from \"~/utils/pickEntryFieldValues\";\nimport { AcoFolderStorageOperations, Folder } from \"./folder.types\";\nimport { ENTRY_META_FIELDS } from \"@webiny/api-headless-cms/constants\";\n\ninterface AcoCheckExistingFolderParams {\n params: {\n type: string;\n slug: string;\n parentId?: string | null;\n };\n id?: string;\n}\n\nexport const createFolderOperations = (\n params: CreateAcoStorageOperationsParams\n): AcoFolderStorageOperations => {\n const { cms } = params;\n\n const { withModel } = createOperationsWrapper({\n ...params,\n modelName: FOLDER_MODEL_ID\n });\n\n const getFolder: AcoFolderStorageOperations[\"getFolder\"] = ({ id, slug, type, parentId }) => {\n return withModel(async model => {\n let entry;\n\n if (id) {\n entry = await cms.getEntryById(model, id);\n } else if (slug && type) {\n entry = await cms.getEntry(model, {\n where: { slug, type, parentId, latest: true }\n });\n }\n\n if (!entry) {\n throw new WebinyError(\"Could not load folder.\", \"GET_FOLDER_ERROR\", {\n id,\n slug,\n type,\n parentId\n });\n }\n\n return pickEntryFieldValues(entry);\n });\n };\n\n const checkExistingFolder = ({ id, params }: AcoCheckExistingFolderParams) => {\n return withModel(async model => {\n const { type, slug, parentId } = params;\n\n // We don't need to perform any kind of authorization or checks here. We just need to check\n // if the folder already exists in the database. Hence the direct storage operations access.\n const listResult = await cms.storageOperations.entries.list(model, {\n ...params,\n where: {\n // Folders always work with latest entries. We never publish them.\n latest: true,\n type,\n slug,\n parentId,\n id_not: id\n },\n limit: 1\n });\n\n if (listResult?.items?.length > 0) {\n throw new WebinyError(\n `Folder with slug \"${slug}\" already exists at this level.`,\n \"FOLDER_ALREADY_EXISTS\",\n {\n id,\n params\n }\n );\n }\n\n return;\n });\n };\n\n return {\n getFolder,\n listFolders(params) {\n return withModel(async model => {\n const { sort, where } = params;\n\n const [entries, meta] = await cms.listLatestEntries(model, {\n ...params,\n sort: createListSort(sort),\n where: {\n ...(where || {})\n }\n });\n\n return [entries.map(pickEntryFieldValues<Folder>), meta];\n });\n },\n createFolder({ data }) {\n return withModel(async model => {\n await checkExistingFolder({\n params: {\n type: data.type,\n slug: data.slug,\n parentId: data.parentId\n }\n });\n\n const entry = await cms.createEntry(model, {\n ...data,\n parentId: data.parentId || null\n });\n\n return pickEntryFieldValues(entry);\n });\n },\n updateFolder({ id, data }) {\n return withModel(async model => {\n const { slug, parentId } = data;\n\n const original = await getFolder({ id });\n\n await checkExistingFolder({\n id,\n params: {\n type: original.type,\n slug: slug || original.slug,\n parentId: parentId !== undefined ? parentId : original.parentId // parentId can be `null`\n }\n });\n\n const input = {\n /**\n * We are omitting the standard entry meta fields:\n * we don't want to override them with the ones coming from the `original` entry.\n */\n ...omit(original, ENTRY_META_FIELDS),\n ...data\n };\n\n const entry = await cms.updateEntry(model, id, input);\n return pickEntryFieldValues(entry);\n });\n },\n deleteFolder({ id }) {\n return withModel(async model => {\n await cms.deleteEntry(model, id);\n return true;\n });\n }\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAEA,IAAAG,eAAA,GAAAH,OAAA;AACA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,qBAAA,GAAAL,OAAA;AAEA,IAAAM,UAAA,GAAAN,OAAA;AAWO,MAAMO,sBAAsB,GAC/BC,MAAwC,IACX;EAC7B,MAAM;IAAEC;EAAI,CAAC,GAAGD,MAAM;EAEtB,MAAM;IAAEE;EAAU,CAAC,GAAG,IAAAC,gDAAuB,EAAC;IAC1C,GAAGH,MAAM;IACTI,SAAS,EAAEC;EACf,CAAC,CAAC;EAEF,MAAMC,SAAkD,GAAGA,CAAC;IAAEC,EAAE;IAAEC,IAAI;IAAEC,IAAI;IAAEC;EAAS,CAAC,KAAK;IACzF,OAAOR,SAAS,CAAC,MAA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EE;QAAS,CAAC,GAAGyB,IAAI;QAE/B,MAAMG,QAAQ,GAAG,MAAMhC,SAAS,CAAC;UAAEC;QAAG,CAAC,CAAC;QAExC,MAAMY,mBAAmB,CAAC;UACtBZ,EAAE;UACFP,MAAM,EAAE;YACJS,IAAI,EAAE6B,QAAQ,CAAC7B,IAAI;YACnBD,IAAI,EAAEA,IAAI,IAAI8B,QAAQ,CAAC9B,IAAI;YAC3BE,QAAQ,EAAEA,QAAQ,KAAK6B,SAAS,GAAG7B,QAAQ,GAAG4B,QAAQ,CAAC5B,QAAQ,CAAC;UACpE;QACJ,CAAC,CAAC;;QAEF,MAAM8B,KAAK,GAAG;UACV;AACpB;AACA;AACA;UACoB,GAAG,IAAAC,aAAI,EAACH,QAAQ,EAAEI,4BAAiB,CAAC;UACpC,GAAGP;QACP,CAAC;QAED,MAAMvB,KAAK,GAAG,MAAMX,GAAG,CAAC0C,WAAW,CAAChC,KAAK,EAAEJ,EAAE,EAAEiC,KAAK,CAAC;QACrD,OAAO,IAAAtB,0CAAoB,EAACN,KAAK,CAAC;MACtC,CAAC,CAAC;IACN,CAAC;IACDgC,YAAYA,CAAC;MAAErC;IAAG,CAAC,EAAE;MACjB,OAAOL,SAAS,CAAC,MAAMS,KAAK,IAAI;QAC5B,MAAMV,GAAG,CAAC4C,WAAW,CAAClC,KAAK,EAAEJ,EAAE,CAAC;QAChC,OAAO,IAAI;MACf,CAAC,CAAC;IACN;EACJ,CAAC;AACL,CAAC;AAACuC,OAAA,CAAA/C,sBAAA,GAAAA,sBAAA"}
@@ -1,8 +1,18 @@
1
- import { AcoBaseFields, ListMeta } from "../types";
1
+ import { ListMeta, ListSort, User } from "../types";
2
2
  import { Topic } from "@webiny/pubsub/types";
3
- export interface Folder extends AcoBaseFields {
3
+ import { FolderPermission } from "../utils/FolderLevelPermissions";
4
+ export interface Folder {
5
+ id: string;
6
+ entryId: string;
7
+ createdOn: string;
8
+ modifiedOn: string | null;
9
+ savedOn: string;
10
+ createdBy: User;
11
+ modifiedBy: User | null;
12
+ savedBy: User;
4
13
  title: string;
5
14
  slug: string;
15
+ permissions?: FolderPermission[];
6
16
  type: string;
7
17
  parentId?: string | null;
8
18
  }
@@ -12,19 +22,31 @@ export interface ListFoldersWhere {
12
22
  }
13
23
  export interface ListFoldersParams {
14
24
  where: ListFoldersWhere;
15
- sort?: string[];
25
+ sort?: ListSort;
16
26
  limit?: number;
17
27
  after?: string | null;
18
28
  }
29
+ export declare type ListAllFoldersParams = Omit<ListFoldersParams, "limit" | "after">;
19
30
  export declare type CreateFolderParams = Pick<Folder, "title" | "slug" | "type" | "parentId">;
20
31
  export interface UpdateFolderParams {
21
32
  title?: string;
22
33
  slug?: string;
34
+ permissions?: FolderPermission[];
23
35
  parentId?: string;
24
36
  }
25
37
  export interface DeleteFolderParams {
26
38
  id: string;
27
39
  }
40
+ export interface FolderLevelPermissionsTarget<TMeta = Record<string, any>> {
41
+ id: string;
42
+ target: string;
43
+ name: string;
44
+ type: string;
45
+ meta: TMeta;
46
+ }
47
+ export interface FolderLevelPermissionsTargetListMeta {
48
+ totalCount: number;
49
+ }
28
50
  export interface StorageOperationsGetFolderParams {
29
51
  id?: string;
30
52
  slug?: string;
@@ -64,9 +86,19 @@ export interface OnFolderAfterDeleteTopicParams {
64
86
  export interface AcoFolderCrud {
65
87
  get(id: string): Promise<Folder>;
66
88
  list(params: ListFoldersParams): Promise<[Folder[], ListMeta]>;
89
+ listFolderLevelPermissionsTargets(): Promise<[
90
+ FolderLevelPermissionsTarget[],
91
+ FolderLevelPermissionsTargetListMeta
92
+ ]>;
93
+ listAll(params: ListAllFoldersParams): Promise<[Folder[], ListMeta]>;
67
94
  create(data: CreateFolderParams): Promise<Folder>;
68
95
  update(id: string, data: UpdateFolderParams): Promise<Folder>;
69
- delete(id: string): Promise<Boolean>;
96
+ delete(id: string): Promise<boolean>;
97
+ getAncestors(folder: Folder): Promise<Folder[]>;
98
+ /**
99
+ * @deprecated use `getAncestors` instead
100
+ */
101
+ getFolderWithAncestors(id: string): Promise<Folder[]>;
70
102
  onFolderBeforeCreate: Topic<OnFolderBeforeCreateTopicParams>;
71
103
  onFolderAfterCreate: Topic<OnFolderAfterCreateTopicParams>;
72
104
  onFolderBeforeUpdate: Topic<OnFolderBeforeUpdateTopicParams>;
@@ -2,4 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
5
+ });
6
+
7
+ //# sourceMappingURL=folder.types.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["folder.types.ts"],"sourcesContent":["import { AcoBaseFields, ListMeta } from \"~/types\";\nimport { Topic } from \"@webiny/pubsub/types\";\n\nexport interface Folder extends AcoBaseFields {\n title: string;\n slug: string;\n type: string;\n parentId?: string | null;\n}\n\nexport interface ListFoldersWhere {\n type: string;\n parentId?: string | null;\n}\n\nexport interface ListFoldersParams {\n where: ListFoldersWhere;\n sort?: string[];\n limit?: number;\n after?: string | null;\n}\n\nexport type CreateFolderParams = Pick<Folder, \"title\" | \"slug\" | \"type\" | \"parentId\">;\n\nexport interface UpdateFolderParams {\n title?: string;\n slug?: string;\n parentId?: string;\n}\n\nexport interface DeleteFolderParams {\n id: string;\n}\n\nexport interface StorageOperationsGetFolderParams {\n id?: string;\n slug?: string;\n type?: string;\n parentId?: string | null;\n}\n\nexport type StorageOperationsListFoldersParams = ListFoldersParams;\n\nexport interface StorageOperationsCreateFolderParams {\n data: CreateFolderParams;\n}\n\nexport interface StorageOperationsUpdateFolderParams {\n id: string;\n data: UpdateFolderParams;\n}\n\nexport type StorageOperationsDeleteFolderParams = DeleteFolderParams;\n\nexport interface OnFolderBeforeCreateTopicParams {\n input: CreateFolderParams;\n}\n\nexport interface OnFolderAfterCreateTopicParams {\n folder: Folder;\n}\n\nexport interface OnFolderBeforeUpdateTopicParams {\n original: Folder;\n input: Record<string, any>;\n}\n\nexport interface OnFolderAfterUpdateTopicParams {\n original: Folder;\n folder: Folder;\n input: Record<string, any>;\n}\n\nexport interface OnFolderBeforeDeleteTopicParams {\n folder: Folder;\n}\n\nexport interface OnFolderAfterDeleteTopicParams {\n folder: Folder;\n}\n\nexport interface AcoFolderCrud {\n get(id: string): Promise<Folder>;\n list(params: ListFoldersParams): Promise<[Folder[], ListMeta]>;\n create(data: CreateFolderParams): Promise<Folder>;\n update(id: string, data: UpdateFolderParams): Promise<Folder>;\n delete(id: string): Promise<Boolean>;\n onFolderBeforeCreate: Topic<OnFolderBeforeCreateTopicParams>;\n onFolderAfterCreate: Topic<OnFolderAfterCreateTopicParams>;\n onFolderBeforeUpdate: Topic<OnFolderBeforeUpdateTopicParams>;\n onFolderAfterUpdate: Topic<OnFolderAfterUpdateTopicParams>;\n onFolderBeforeDelete: Topic<OnFolderBeforeDeleteTopicParams>;\n onFolderAfterDelete: Topic<OnFolderAfterDeleteTopicParams>;\n}\n\nexport interface AcoFolderStorageOperations {\n getFolder(params: StorageOperationsGetFolderParams): Promise<Folder>;\n listFolders(params: StorageOperationsListFoldersParams): Promise<[Folder[], ListMeta]>;\n createFolder(params: StorageOperationsCreateFolderParams): Promise<Folder>;\n updateFolder(params: StorageOperationsUpdateFolderParams): Promise<Folder>;\n deleteFolder(params: StorageOperationsDeleteFolderParams): Promise<boolean>;\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["folder.types.ts"],"sourcesContent":["import { ListMeta, ListSort, User } from \"~/types\";\nimport { Topic } from \"@webiny/pubsub/types\";\nimport { FolderPermission } from \"~/utils/FolderLevelPermissions\";\n\nexport interface Folder {\n id: string;\n entryId: string;\n createdOn: string;\n modifiedOn: string | null;\n savedOn: string;\n createdBy: User;\n modifiedBy: User | null;\n savedBy: User;\n title: string;\n slug: string;\n permissions?: FolderPermission[];\n type: string;\n parentId?: string | null;\n}\n\nexport interface ListFoldersWhere {\n type: string;\n parentId?: string | null;\n}\n\nexport interface ListFoldersParams {\n where: ListFoldersWhere;\n sort?: ListSort;\n limit?: number;\n after?: string | null;\n}\n\nexport type ListAllFoldersParams = Omit<ListFoldersParams, \"limit\" | \"after\">;\n\nexport type CreateFolderParams = Pick<Folder, \"title\" | \"slug\" | \"type\" | \"parentId\">;\n\nexport interface UpdateFolderParams {\n title?: string;\n slug?: string;\n permissions?: FolderPermission[];\n parentId?: string;\n}\n\nexport interface DeleteFolderParams {\n id: string;\n}\n\nexport interface FolderLevelPermissionsTarget<TMeta = Record<string, any>> {\n id: string;\n target: string;\n name: string;\n type: string;\n meta: TMeta;\n}\n\nexport interface FolderLevelPermissionsTargetListMeta {\n totalCount: number;\n}\n\nexport interface StorageOperationsGetFolderParams {\n id?: string;\n slug?: string;\n type?: string;\n parentId?: string | null;\n}\n\nexport type StorageOperationsListFoldersParams = ListFoldersParams;\n\nexport interface StorageOperationsCreateFolderParams {\n data: CreateFolderParams;\n}\n\nexport interface StorageOperationsUpdateFolderParams {\n id: string;\n data: UpdateFolderParams;\n}\n\nexport type StorageOperationsDeleteFolderParams = DeleteFolderParams;\n\nexport interface OnFolderBeforeCreateTopicParams {\n input: CreateFolderParams;\n}\n\nexport interface OnFolderAfterCreateTopicParams {\n folder: Folder;\n}\n\nexport interface OnFolderBeforeUpdateTopicParams {\n original: Folder;\n input: Record<string, any>;\n}\n\nexport interface OnFolderAfterUpdateTopicParams {\n original: Folder;\n folder: Folder;\n input: Record<string, any>;\n}\n\nexport interface OnFolderBeforeDeleteTopicParams {\n folder: Folder;\n}\n\nexport interface OnFolderAfterDeleteTopicParams {\n folder: Folder;\n}\n\nexport interface AcoFolderCrud {\n get(id: string): Promise<Folder>;\n\n list(params: ListFoldersParams): Promise<[Folder[], ListMeta]>;\n\n listFolderLevelPermissionsTargets(): Promise<\n [FolderLevelPermissionsTarget[], FolderLevelPermissionsTargetListMeta]\n >;\n\n listAll(params: ListAllFoldersParams): Promise<[Folder[], ListMeta]>;\n\n create(data: CreateFolderParams): Promise<Folder>;\n\n update(id: string, data: UpdateFolderParams): Promise<Folder>;\n\n delete(id: string): Promise<boolean>;\n\n getAncestors(folder: Folder): Promise<Folder[]>;\n\n /**\n * @deprecated use `getAncestors` instead\n */\n getFolderWithAncestors(id: string): Promise<Folder[]>;\n\n onFolderBeforeCreate: Topic<OnFolderBeforeCreateTopicParams>;\n onFolderAfterCreate: Topic<OnFolderAfterCreateTopicParams>;\n onFolderBeforeUpdate: Topic<OnFolderBeforeUpdateTopicParams>;\n onFolderAfterUpdate: Topic<OnFolderAfterUpdateTopicParams>;\n onFolderBeforeDelete: Topic<OnFolderBeforeDeleteTopicParams>;\n onFolderAfterDelete: Topic<OnFolderAfterDeleteTopicParams>;\n}\n\nexport interface AcoFolderStorageOperations {\n getFolder(params: StorageOperationsGetFolderParams): Promise<Folder>;\n\n listFolders(params: StorageOperationsListFoldersParams): Promise<[Folder[], ListMeta]>;\n\n createFolder(params: StorageOperationsCreateFolderParams): Promise<Folder>;\n\n updateFolder(params: StorageOperationsUpdateFolderParams): Promise<Folder>;\n\n deleteFolder(params: StorageOperationsDeleteFolderParams): Promise<boolean>;\n}\n"],"mappings":""}
@@ -0,0 +1,2 @@
1
+ import { AcoContext } from "../types";
2
+ export declare const onFolderBeforeDeleteAcoHook: ({ aco }: AcoContext) => void;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.onFolderBeforeDeleteAcoHook = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ const throwDeleteError = folder => {
10
+ throw new _error.default("Delete all child folders and entries before proceeding.", "DELETE_FOLDER_WITH_CHILDREN", {
11
+ folder
12
+ });
13
+ };
14
+ const onFolderBeforeDeleteAcoHook = ({
15
+ aco
16
+ }) => {
17
+ aco.folder.onFolderBeforeDelete.subscribe(async ({
18
+ folder
19
+ }) => {
20
+ try {
21
+ const {
22
+ id,
23
+ type
24
+ } = folder;
25
+ /**
26
+ * First we check for the child folders.
27
+ */
28
+ const [children] = await aco.folder.list({
29
+ where: {
30
+ type,
31
+ parentId: id
32
+ },
33
+ limit: 1
34
+ });
35
+ if (children.length > 0) {
36
+ throwDeleteError(folder);
37
+ }
38
+ let app = undefined;
39
+ try {
40
+ app = aco.getApp(type);
41
+ } catch {
42
+ return;
43
+ }
44
+ const [records] = await app.search.list({
45
+ where: {
46
+ type,
47
+ location: {
48
+ folderId: id
49
+ }
50
+ },
51
+ limit: 1
52
+ });
53
+ if (records.length === 0) {
54
+ return;
55
+ }
56
+ throwDeleteError(folder);
57
+ } catch (error) {
58
+ throw _error.default.from(error, {
59
+ message: "Error while executing onFolderBeforeDeleteAcoHook hook.",
60
+ code: "ACO_BEFORE_FOLDER_DELETE_ACO_HOOK"
61
+ });
62
+ }
63
+ });
64
+ };
65
+ exports.onFolderBeforeDeleteAcoHook = onFolderBeforeDeleteAcoHook;
66
+
67
+ //# sourceMappingURL=onFolderBeforeDeleteAco.hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","throwDeleteError","folder","WebinyError","onFolderBeforeDeleteAcoHook","aco","onFolderBeforeDelete","subscribe","id","type","children","list","where","parentId","limit","length","app","undefined","getApp","records","search","location","folderId","error","from","message","code","exports"],"sources":["onFolderBeforeDeleteAco.hook.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { AcoContext, Folder, IAcoApp } from \"~/types\";\n\nconst throwDeleteError = (folder: Folder) => {\n throw new WebinyError(\n \"Delete all child folders and entries before proceeding.\",\n \"DELETE_FOLDER_WITH_CHILDREN\",\n {\n folder\n }\n );\n};\n\nexport const onFolderBeforeDeleteAcoHook = ({ aco }: AcoContext) => {\n aco.folder.onFolderBeforeDelete.subscribe(async ({ folder }) => {\n try {\n const { id, type } = folder;\n /**\n * First we check for the child folders.\n */\n const [children] = await aco.folder.list({\n where: {\n type,\n parentId: id\n },\n limit: 1\n });\n\n if (children.length > 0) {\n throwDeleteError(folder);\n }\n\n let app: IAcoApp | undefined = undefined;\n try {\n app = aco.getApp(type);\n } catch {\n return;\n }\n const [records] = await app.search.list({\n where: {\n type,\n location: {\n folderId: id\n }\n },\n limit: 1\n });\n if (records.length === 0) {\n return;\n }\n throwDeleteError(folder);\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing onFolderBeforeDeleteAcoHook hook.\",\n code: \"ACO_BEFORE_FOLDER_DELETE_ACO_HOOK\"\n });\n }\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,MAAMC,gBAAgB,GAAIC,MAAc,IAAK;EACzC,MAAM,IAAIC,cAAW,CACjB,yDAAyD,EACzD,6BAA6B,EAC7B;IACID;EACJ,CACJ,CAAC;AACL,CAAC;AAEM,MAAME,2BAA2B,GAAGA,CAAC;EAAEC;AAAgB,CAAC,KAAK;EAChEA,GAAG,CAACH,MAAM,CAACI,oBAAoB,CAACC,SAAS,CAAC,OAAO;IAAEL;EAAO,CAAC,KAAK;IAC5D,IAAI;MACA,MAAM;QAAEM,EAAE;QAAEC;MAAK,CAAC,GAAGP,MAAM;MAC3B;AACZ;AACA;MACY,MAAM,CAACQ,QAAQ,CAAC,GAAG,MAAML,GAAG,CAACH,MAAM,CAACS,IAAI,CAAC;QACrCC,KAAK,EAAE;UACHH,IAAI;UACJI,QAAQ,EAAEL;QACd,CAAC;QACDM,KAAK,EAAE;MACX,CAAC,CAAC;MAEF,IAAIJ,QAAQ,CAACK,MAAM,GAAG,CAAC,EAAE;QACrBd,gBAAgB,CAACC,MAAM,CAAC;MAC5B;MAEA,IAAIc,GAAwB,GAAGC,SAAS;MACxC,IAAI;QACAD,GAAG,GAAGX,GAAG,CAACa,MAAM,CAACT,IAAI,CAAC;MAC1B,CAAC,CAAC,MAAM;QACJ;MACJ;MACA,MAAM,CAACU,OAAO,CAAC,GAAG,MAAMH,GAAG,CAACI,MAAM,CAACT,IAAI,CAAC;QACpCC,KAAK,EAAE;UACHH,IAAI;UACJY,QAAQ,EAAE;YACNC,QAAQ,EAAEd;UACd;QACJ,CAAC;QACDM,KAAK,EAAE;MACX,CAAC,CAAC;MACF,IAAIK,OAAO,CAACJ,MAAM,KAAK,CAAC,EAAE;QACtB;MACJ;MACAd,gBAAgB,CAACC,MAAM,CAAC;IAC5B,CAAC,CAAC,OAAOqB,KAAK,EAAE;MACZ,MAAMpB,cAAW,CAACqB,IAAI,CAACD,KAAK,EAAE;QAC1BE,OAAO,EAAE,yDAAyD;QAClEC,IAAI,EAAE;MACV,CAAC,CAAC;IACN;EACJ,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAvB,2BAAA,GAAAA,2BAAA"}
@@ -0,0 +1,2 @@
1
+ import { AcoContext } from "../types";
2
+ export declare const onFolderBeforeDeleteFmHook: (context: AcoContext) => void;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.onFolderBeforeDeleteFmHook = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ const onFolderBeforeDeleteFmHook = context => {
10
+ context.aco.folder.onFolderBeforeDelete.subscribe(async ({
11
+ folder
12
+ }) => {
13
+ try {
14
+ const {
15
+ id,
16
+ type
17
+ } = folder;
18
+
19
+ /**
20
+ * Exit if the folder type is not related to File Manager
21
+ */
22
+ if (type !== "FmFile") {
23
+ return;
24
+ }
25
+ const [files] = await context.fileManager.listFiles({
26
+ where: {
27
+ location: {
28
+ folderId: id
29
+ }
30
+ },
31
+ limit: 1
32
+ });
33
+ if (files.length === 0) {
34
+ return;
35
+ }
36
+ throw new _error.default("Delete all child folders and files before proceeding.", "DELETE_FOLDER_WITH_CHILDREN", {
37
+ folder
38
+ });
39
+ } catch (error) {
40
+ throw _error.default.from(error, {
41
+ message: "Error while executing onFolderBeforeDeleteFmHook hook.",
42
+ code: "ACO_BEFORE_FOLDER_DELETE_FILE_HOOK"
43
+ });
44
+ }
45
+ });
46
+ };
47
+ exports.onFolderBeforeDeleteFmHook = onFolderBeforeDeleteFmHook;
48
+
49
+ //# sourceMappingURL=onFolderBeforeDeleteFm.hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","onFolderBeforeDeleteFmHook","context","aco","folder","onFolderBeforeDelete","subscribe","id","type","files","fileManager","listFiles","where","location","folderId","limit","length","WebinyError","error","from","message","code","exports"],"sources":["onFolderBeforeDeleteFm.hook.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { AcoContext } from \"~/types\";\n\nexport const onFolderBeforeDeleteFmHook = (context: AcoContext) => {\n context.aco.folder.onFolderBeforeDelete.subscribe(async ({ folder }) => {\n try {\n const { id, type } = folder;\n\n /**\n * Exit if the folder type is not related to File Manager\n */\n if (type !== \"FmFile\") {\n return;\n }\n\n const [files] = await context.fileManager.listFiles({\n where: {\n location: {\n folderId: id\n }\n },\n limit: 1\n });\n\n if (files.length === 0) {\n return;\n }\n\n throw new WebinyError(\n \"Delete all child folders and files before proceeding.\",\n \"DELETE_FOLDER_WITH_CHILDREN\",\n {\n folder\n }\n );\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing onFolderBeforeDeleteFmHook hook.\",\n code: \"ACO_BEFORE_FOLDER_DELETE_FILE_HOOK\"\n });\n }\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGO,MAAMC,0BAA0B,GAAIC,OAAmB,IAAK;EAC/DA,OAAO,CAACC,GAAG,CAACC,MAAM,CAACC,oBAAoB,CAACC,SAAS,CAAC,OAAO;IAAEF;EAAO,CAAC,KAAK;IACpE,IAAI;MACA,MAAM;QAAEG,EAAE;QAAEC;MAAK,CAAC,GAAGJ,MAAM;;MAE3B;AACZ;AACA;MACY,IAAII,IAAI,KAAK,QAAQ,EAAE;QACnB;MACJ;MAEA,MAAM,CAACC,KAAK,CAAC,GAAG,MAAMP,OAAO,CAACQ,WAAW,CAACC,SAAS,CAAC;QAChDC,KAAK,EAAE;UACHC,QAAQ,EAAE;YACNC,QAAQ,EAAEP;UACd;QACJ,CAAC;QACDQ,KAAK,EAAE;MACX,CAAC,CAAC;MAEF,IAAIN,KAAK,CAACO,MAAM,KAAK,CAAC,EAAE;QACpB;MACJ;MAEA,MAAM,IAAIC,cAAW,CACjB,uDAAuD,EACvD,6BAA6B,EAC7B;QACIb;MACJ,CACJ,CAAC;IACL,CAAC,CAAC,OAAOc,KAAK,EAAE;MACZ,MAAMD,cAAW,CAACE,IAAI,CAACD,KAAK,EAAE;QAC1BE,OAAO,EAAE,wDAAwD;QACjEC,IAAI,EAAE;MACV,CAAC,CAAC;IACN;EACJ,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAArB,0BAAA,GAAAA,0BAAA"}
@@ -0,0 +1,2 @@
1
+ import { AcoContext } from "../types";
2
+ export declare const onFolderBeforeDeleteHcmsHook: (context: AcoContext) => void;