@webiny/api-aco 0.0.0-unstable.9e825fd5fb → 0.0.0-unstable.a9593f74dd

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 (183) 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 +39 -6
  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 -42
  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/{createAcoFields.d.ts → fields/index.d.ts} +1 -1
  28. package/fields/index.js +14 -0
  29. package/fields/index.js.map +1 -0
  30. package/fields/location.d.ts +2 -0
  31. package/fields/location.js +46 -0
  32. package/fields/location.js.map +1 -0
  33. package/filter/filter.crud.d.ts +3 -0
  34. package/filter/filter.crud.js +94 -0
  35. package/filter/filter.crud.js.map +1 -0
  36. package/filter/filter.gql.d.ts +3 -0
  37. package/filter/filter.gql.js +153 -0
  38. package/filter/filter.gql.js.map +1 -0
  39. package/filter/filter.model.d.ts +2 -0
  40. package/filter/filter.model.js +125 -0
  41. package/filter/filter.model.js.map +1 -0
  42. package/filter/filter.so.d.ts +3 -0
  43. package/filter/filter.so.js +98 -0
  44. package/filter/filter.so.js.map +1 -0
  45. package/filter/filter.types.d.ts +95 -0
  46. package/filter/filter.types.js +14 -0
  47. package/filter/filter.types.js.map +1 -0
  48. package/folder/folder.crud.d.ts +8 -1
  49. package/folder/folder.crud.js +201 -4
  50. package/folder/folder.crud.js.map +1 -1
  51. package/folder/folder.gql.js +98 -6
  52. package/folder/folder.gql.js.map +1 -1
  53. package/folder/folder.model.d.ts +1 -3
  54. package/folder/folder.model.js +54 -25
  55. package/folder/folder.model.js.map +1 -1
  56. package/folder/folder.so.js +38 -18
  57. package/folder/folder.so.js.map +1 -1
  58. package/folder/folder.types.d.ts +35 -3
  59. package/folder/folder.types.js +3 -1
  60. package/folder/folder.types.js.map +1 -1
  61. package/folder/onFolderBeforeDeleteAco.hook.d.ts +2 -0
  62. package/folder/onFolderBeforeDeleteAco.hook.js +67 -0
  63. package/folder/onFolderBeforeDeleteAco.hook.js.map +1 -0
  64. package/folder/onFolderBeforeDeleteFm.hook.d.ts +2 -0
  65. package/folder/onFolderBeforeDeleteFm.hook.js +49 -0
  66. package/folder/onFolderBeforeDeleteFm.hook.js.map +1 -0
  67. package/folder/onFolderBeforeDeleteHcms.hook.d.ts +2 -0
  68. package/folder/onFolderBeforeDeleteHcms.hook.js +56 -0
  69. package/folder/onFolderBeforeDeleteHcms.hook.js.map +1 -0
  70. package/index.d.ts +9 -1
  71. package/index.js +57 -5
  72. package/index.js.map +1 -1
  73. package/package.json +38 -32
  74. package/plugins/AcoAppModifierPlugin.d.ts +43 -0
  75. package/plugins/AcoAppModifierPlugin.js +58 -0
  76. package/plugins/AcoAppModifierPlugin.js.map +1 -0
  77. package/plugins/AcoAppRegisterPlugin.d.ts +8 -0
  78. package/plugins/AcoAppRegisterPlugin.js +21 -0
  79. package/plugins/AcoAppRegisterPlugin.js.map +1 -0
  80. package/plugins/index.d.ts +2 -0
  81. package/plugins/index.js +29 -0
  82. package/plugins/index.js.map +1 -0
  83. package/record/graphql/createAppResolvers.d.ts +14 -0
  84. package/record/graphql/createAppResolvers.js +115 -0
  85. package/record/graphql/createAppResolvers.js.map +1 -0
  86. package/record/graphql/createAppSchema.d.ts +9 -0
  87. package/record/graphql/createAppSchema.js +147 -0
  88. package/record/graphql/createAppSchema.js.map +1 -0
  89. package/record/record.crud.js +49 -13
  90. package/record/record.crud.js.map +1 -1
  91. package/record/record.gql.d.ts +8 -3
  92. package/record/record.gql.js +38 -112
  93. package/record/record.gql.js.map +1 -1
  94. package/record/record.model.d.ts +7 -3
  95. package/record/record.model.js +42 -13
  96. package/record/record.model.js.map +1 -1
  97. package/record/record.so.js +109 -45
  98. package/record/record.so.js.map +1 -1
  99. package/record/record.types.d.ts +71 -18
  100. package/record/record.types.js +3 -1
  101. package/record/record.types.js.map +1 -1
  102. package/types.d.ts +69 -8
  103. package/types.js +52 -4
  104. package/types.js.map +1 -1
  105. package/utils/FolderLevelPermissions.d.ts +71 -0
  106. package/utils/FolderLevelPermissions.js +353 -0
  107. package/utils/FolderLevelPermissions.js.map +1 -0
  108. package/utils/acoRecordId.d.ts +6 -0
  109. package/utils/acoRecordId.js +35 -0
  110. package/utils/acoRecordId.js.map +1 -0
  111. package/utils/createListSort.js +3 -1
  112. package/utils/createListSort.js.map +1 -1
  113. package/utils/createModelField.js +3 -1
  114. package/utils/createModelField.js.map +1 -1
  115. package/utils/createOperationsWrapper.js +3 -1
  116. package/utils/createOperationsWrapper.js.map +1 -1
  117. package/utils/decorators/CmsEntriesCrudDecorators.d.ts +11 -0
  118. package/utils/decorators/CmsEntriesCrudDecorators.js +232 -0
  119. package/utils/decorators/CmsEntriesCrudDecorators.js.map +1 -0
  120. package/utils/decorators/constants.d.ts +1 -0
  121. package/utils/decorators/constants.js +10 -0
  122. package/utils/decorators/constants.js.map +1 -0
  123. package/utils/decorators/where.d.ts +14 -0
  124. package/utils/decorators/where.js +52 -0
  125. package/utils/decorators/where.js.map +1 -0
  126. package/utils/ensureAuthentication.d.ts +2 -0
  127. package/utils/ensureAuthentication.js +16 -0
  128. package/utils/ensureAuthentication.js.map +1 -0
  129. package/utils/getFolderAndItsAncestors.d.ts +7 -0
  130. package/utils/getFolderAndItsAncestors.js +53 -0
  131. package/utils/getFolderAndItsAncestors.js.map +1 -0
  132. package/utils/isInstallationPending.js +3 -1
  133. package/utils/isInstallationPending.js.map +1 -1
  134. package/utils/modelFactory.d.ts +1 -3
  135. package/utils/modelFactory.js +7 -10
  136. package/utils/modelFactory.js.map +1 -1
  137. package/utils/pickEntryFieldValues.d.ts +3 -0
  138. package/utils/pickEntryFieldValues.js +31 -0
  139. package/utils/pickEntryFieldValues.js.map +1 -0
  140. package/utils/resolve.d.ts +3 -2
  141. package/utils/resolve.js +13 -2
  142. package/utils/resolve.js.map +1 -1
  143. package/context/folders.d.ts +0 -2
  144. package/context/folders.js +0 -261
  145. package/context/folders.js.map +0 -1
  146. package/context/index.d.ts +0 -2
  147. package/context/index.js +0 -22
  148. package/context/index.js.map +0 -1
  149. package/context/links.d.ts +0 -2
  150. package/context/links.js +0 -270
  151. package/context/links.js.map +0 -1
  152. package/createAcoCrud.d.ts +0 -2
  153. package/createAcoCrud.js +0 -17
  154. package/createAcoCrud.js.map +0 -1
  155. package/createAcoFields.js +0 -40
  156. package/createAcoFields.js.map +0 -1
  157. package/folder/onFolderBeforeDelete.hook.d.ts +0 -2
  158. package/folder/onFolderBeforeDelete.hook.js +0 -53
  159. package/folder/onFolderBeforeDelete.hook.js.map +0 -1
  160. package/graphql/base.gql.d.ts +0 -3
  161. package/graphql/base.gql.js +0 -63
  162. package/graphql/base.gql.js.map +0 -1
  163. package/graphql/folders.gql.d.ts +0 -3
  164. package/graphql/folders.gql.js +0 -126
  165. package/graphql/folders.gql.js.map +0 -1
  166. package/graphql/index.d.ts +0 -1
  167. package/graphql/index.js +0 -15
  168. package/graphql/index.js.map +0 -1
  169. package/graphql/links.gql.d.ts +0 -3
  170. package/graphql/links.gql.js +0 -123
  171. package/graphql/links.gql.js.map +0 -1
  172. package/subscriptions/afterFolderDelete.d.ts +0 -3
  173. package/subscriptions/afterFolderDelete.js +0 -62
  174. package/subscriptions/afterFolderDelete.js.map +0 -1
  175. package/subscriptions/index.d.ts +0 -3
  176. package/subscriptions/index.js +0 -14
  177. package/subscriptions/index.js.map +0 -1
  178. package/utils/fieldResolver.d.ts +0 -16
  179. package/utils/fieldResolver.js +0 -44
  180. package/utils/fieldResolver.js.map +0 -1
  181. package/utils/getFieldValues.d.ts +0 -2
  182. package/utils/getFieldValues.js +0 -19
  183. package/utils/getFieldValues.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"names":["titleField","createModelField","label","type","validation","name","message","settings","value","slugField","preset","regex","flags","typeField","parentIdField","FOLDER_MODEL_ID","createFolderModelDefinition","modelId","titleFieldId","layout","fields","description","isPrivate"],"sources":["folder.model.ts"],"sourcesContent":["import { createModelField } from \"~/utils/createModelField\";\nimport { CmsPrivateModelFull } from \"@webiny/api-headless-cms\";\n\nexport type FolderModelDefinition = Omit<CmsPrivateModelFull, \"noValidate\" | \"group\">;\n\nconst titleField = () =>\n createModelField({\n label: \"Title\",\n type: \"text\",\n validation: [\n {\n name: \"required\",\n message: \"Value is required.\"\n },\n {\n name: \"minLength\",\n settings: {\n value: \"3\"\n },\n message: \"Value is too short.\"\n }\n ]\n });\n\nconst slugField = () =>\n createModelField({\n label: \"Slug\",\n type: \"text\",\n validation: [\n {\n name: \"required\",\n message: \"Value is required.\"\n },\n {\n name: \"minLength\",\n settings: {\n value: \"3\"\n },\n message: \"Value is too short.\"\n },\n {\n name: \"maxLength\",\n settings: {\n value: \"100\"\n },\n message: \"Value is too long.\"\n },\n {\n name: \"pattern\",\n settings: {\n preset: \"custom\",\n regex: \"^[a-z0-9]+(-[a-z0-9]+)*$\",\n flags: \"g\"\n },\n message: \"Value must consist of only 'a-z', '0-9' and '-'.\"\n }\n ]\n });\n\nconst typeField = () =>\n createModelField({\n label: \"Type\",\n type: \"text\",\n validation: [\n {\n name: \"required\",\n message: \"Value is required.\"\n }\n ]\n });\n\nconst parentIdField = () =>\n createModelField({\n label: \"Parent Id\",\n type: \"text\"\n });\n\nexport const FOLDER_MODEL_ID = \"acoFolder\";\n\nexport const createFolderModelDefinition = (): FolderModelDefinition => {\n return {\n name: \"ACO - Folder\",\n modelId: FOLDER_MODEL_ID,\n titleFieldId: \"title\",\n layout: [[\"title\"], [\"slug\"], [\"type\"], [\"parentId\"]],\n fields: [titleField(), slugField(), typeField(), parentIdField()],\n description: \"ACO - Folder content model\",\n isPrivate: true\n };\n};\n"],"mappings":";;;;;;AAAA;AAKA,MAAMA,UAAU,GAAG,MACf,IAAAC,kCAAgB,EAAC;EACbC,KAAK,EAAE,OAAO;EACdC,IAAI,EAAE,MAAM;EACZC,UAAU,EAAE,CACR;IACIC,IAAI,EAAE,UAAU;IAChBC,OAAO,EAAE;EACb,CAAC,EACD;IACID,IAAI,EAAE,WAAW;IACjBE,QAAQ,EAAE;MACNC,KAAK,EAAE;IACX,CAAC;IACDF,OAAO,EAAE;EACb,CAAC;AAET,CAAC,CAAC;AAEN,MAAMG,SAAS,GAAG,MACd,IAAAR,kCAAgB,EAAC;EACbC,KAAK,EAAE,MAAM;EACbC,IAAI,EAAE,MAAM;EACZC,UAAU,EAAE,CACR;IACIC,IAAI,EAAE,UAAU;IAChBC,OAAO,EAAE;EACb,CAAC,EACD;IACID,IAAI,EAAE,WAAW;IACjBE,QAAQ,EAAE;MACNC,KAAK,EAAE;IACX,CAAC;IACDF,OAAO,EAAE;EACb,CAAC,EACD;IACID,IAAI,EAAE,WAAW;IACjBE,QAAQ,EAAE;MACNC,KAAK,EAAE;IACX,CAAC;IACDF,OAAO,EAAE;EACb,CAAC,EACD;IACID,IAAI,EAAE,SAAS;IACfE,QAAQ,EAAE;MACNG,MAAM,EAAE,QAAQ;MAChBC,KAAK,EAAE,0BAA0B;MACjCC,KAAK,EAAE;IACX,CAAC;IACDN,OAAO,EAAE;EACb,CAAC;AAET,CAAC,CAAC;AAEN,MAAMO,SAAS,GAAG,MACd,IAAAZ,kCAAgB,EAAC;EACbC,KAAK,EAAE,MAAM;EACbC,IAAI,EAAE,MAAM;EACZC,UAAU,EAAE,CACR;IACIC,IAAI,EAAE,UAAU;IAChBC,OAAO,EAAE;EACb,CAAC;AAET,CAAC,CAAC;AAEN,MAAMQ,aAAa,GAAG,MAClB,IAAAb,kCAAgB,EAAC;EACbC,KAAK,EAAE,WAAW;EAClBC,IAAI,EAAE;AACV,CAAC,CAAC;AAEC,MAAMY,eAAe,GAAG,WAAW;AAAC;AAEpC,MAAMC,2BAA2B,GAAG,MAA6B;EACpE,OAAO;IACHX,IAAI,EAAE,cAAc;IACpBY,OAAO,EAAEF,eAAe;IACxBG,YAAY,EAAE,OAAO;IACrBC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;IACrDC,MAAM,EAAE,CAACpB,UAAU,EAAE,EAAES,SAAS,EAAE,EAAEI,SAAS,EAAE,EAAEC,aAAa,EAAE,CAAC;IACjEO,WAAW,EAAE,4BAA4B;IACzCC,SAAS,EAAE;EACf,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["_createModelField","require","_apiHeadlessCms","titleField","createModelField","label","type","validation","name","message","slugField","settings","preset","regex","flags","typeField","parentIdField","permissionsField","fieldId","multipleValues","listValidation","fields","id","storageId","predefinedValues","enabled","values","value","layout","FOLDER_MODEL_ID","exports","createFolderModelDefinition","createPrivateModelDefinition","modelId","titleFieldId"],"sources":["folder.model.ts"],"sourcesContent":["import { createModelField } from \"~/utils/createModelField\";\nimport { createPrivateModelDefinition } from \"@webiny/api-headless-cms\";\n\nconst titleField = () =>\n createModelField({\n label: \"Title\",\n type: \"text\",\n validation: [\n {\n name: \"required\",\n message: \"Value is required.\"\n }\n ]\n });\n\nconst slugField = () =>\n createModelField({\n label: \"Slug\",\n type: \"text\",\n validation: [\n {\n name: \"required\",\n message: \"Value is required.\"\n },\n {\n name: \"pattern\",\n settings: {\n preset: \"custom\",\n regex: \"^[a-z0-9]+(-[a-z0-9]+)*$\",\n flags: \"g\"\n },\n message: \"Value must consist of only 'a-z', '0-9' and '-'.\"\n }\n ]\n });\n\nconst typeField = () =>\n createModelField({\n label: \"Type\",\n type: \"text\",\n validation: [\n {\n name: \"required\",\n message: \"Value is required.\"\n }\n ]\n });\n\nconst parentIdField = () =>\n createModelField({\n label: \"Parent Id\",\n type: \"text\"\n });\n\nconst permissionsField = () =>\n createModelField({\n label: \"Permissions\",\n fieldId: \"permissions\",\n type: \"object\",\n multipleValues: true,\n listValidation: [],\n settings: {\n fields: [\n {\n id: \"target\",\n type: \"text\",\n storageId: \"text@target\",\n fieldId: \"target\",\n label: \"Target\",\n validation: [\n {\n name: \"required\",\n message: \"Value is required.\"\n }\n ]\n },\n {\n id: \"level\",\n type: \"text\",\n storageId: \"text@level\",\n fieldId: \"level\",\n label: \"Level\",\n validation: [\n {\n name: \"required\",\n message: \"Value is required.\"\n }\n ],\n predefinedValues: {\n enabled: true,\n values: [\n {\n label: \"Viewer\",\n value: \"viewer\"\n },\n {\n label: \"Editor\",\n value: \"editor\"\n },\n {\n label: \"Owner\",\n value: \"owner\"\n },\n {\n label: \"Public\",\n value: \"public\"\n }\n ]\n }\n }\n ],\n layout: [[\"target\"], [\"level\"]]\n }\n });\n\nexport const FOLDER_MODEL_ID = \"acoFolder\";\n\nexport const createFolderModelDefinition = () => {\n return createPrivateModelDefinition({\n name: \"ACO - Folder\",\n modelId: FOLDER_MODEL_ID,\n titleFieldId: \"title\",\n fields: [titleField(), slugField(), typeField(), parentIdField(), permissionsField()]\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAEA,MAAME,UAAU,GAAGA,CAAA,KACf,IAAAC,kCAAgB,EAAC;EACbC,KAAK,EAAE,OAAO;E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AAC;IAET,CAAC,EACD;MACIa,EAAE,EAAE,OAAO;MACXhB,IAAI,EAAE,MAAM;MACZiB,SAAS,EAAE,YAAY;MACvBL,OAAO,EAAE,OAAO;MAChBb,KAAK,EAAE,OAAO;MACdE,UAAU,EAAE,CACR;QACIC,IAAI,EAAE,UAAU;QAChBC,OAAO,EAAE;MACb,CAAC,CACJ;MACDe,gBAAgB,EAAE;QACdC,OAAO,EAAE,IAAI;QACbC,MAAM,EAAE,CACJ;UACIrB,KAAK,EAAE,QAAQ;UACfsB,KAAK,EAAE;QACX,CAAC,EACD;UACItB,KAAK,EAAE,QAAQ;UACfsB,KAAK,EAAE;QACX,CAAC,EACD;UACItB,KAAK,EAAE,OAAO;UACdsB,KAAK,EAAE;QACX,CAAC,EACD;UACItB,KAAK,EAAE,QAAQ;UACfsB,KAAK,EAAE;QACX,CAAC;MAET;IACJ,CAAC,CACJ;IACDC,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC;EAClC;AACJ,CAAC,CAAC;AAEC,MAAMC,eAAe,GAAG,WAAW;AAACC,OAAA,CAAAD,eAAA,GAAAA,eAAA;AAEpC,MAAME,2BAA2B,GAAGA,CAAA,KAAM;EAC7C,OAAO,IAAAC,4CAA4B,EAAC;IAChCxB,IAAI,EAAE,cAAc;IACpByB,OAAO,EAAEJ,eAAe;IACxBK,YAAY,EAAE,OAAO;IACrBb,MAAM,EAAE,CAAClB,UAAU,CAAC,CAAC,EAAEO,SAAS,CAAC,CAAC,EAAEK,SAAS,CAAC,CAAC,EAAEC,aAAa,CAAC,CAAC,EAAEC,gBAAgB,CAAC,CAAC;EACxF,CAAC,CAAC;AACN,CAAC;AAACa,OAAA,CAAAC,2BAAA,GAAAA,2BAAA"}
@@ -5,22 +5,23 @@ 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
11
  var _createListSort = require("../utils/createListSort");
13
12
  var _createOperationsWrapper = require("../utils/createOperationsWrapper");
14
- var _getFieldValues = require("../utils/getFieldValues");
13
+ var _pickEntryFieldValues = require("../utils/pickEntryFieldValues");
14
+ var _constants = require("@webiny/api-headless-cms/constants");
15
15
  const createFolderOperations = params => {
16
16
  const {
17
17
  cms
18
18
  } = params;
19
19
  const {
20
20
  withModel
21
- } = (0, _createOperationsWrapper.createOperationsWrapper)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
21
+ } = (0, _createOperationsWrapper.createOperationsWrapper)({
22
+ ...params,
22
23
  modelName: _folder.FOLDER_MODEL_ID
23
- }));
24
+ });
24
25
  const getFolder = ({
25
26
  id,
26
27
  slug,
@@ -49,7 +50,7 @@ const createFolderOperations = params => {
49
50
  parentId
50
51
  });
51
52
  }
52
- return (0, _getFieldValues.getFieldValues)(entry, _createAcoStorageOperations.baseFields);
53
+ return (0, _pickEntryFieldValues.pickEntryFieldValues)(entry);
53
54
  });
54
55
  };
55
56
  const checkExistingFolder = ({
@@ -62,8 +63,14 @@ const createFolderOperations = params => {
62
63
  slug,
63
64
  parentId
64
65
  } = params;
65
- const [existings] = await cms.listLatestEntries(model, {
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,
66
71
  where: {
72
+ // Folders always work with latest entries. We never publish them.
73
+ latest: true,
67
74
  type,
68
75
  slug,
69
76
  parentId,
@@ -71,7 +78,7 @@ const createFolderOperations = params => {
71
78
  },
72
79
  limit: 1
73
80
  });
74
- if (existings.length > 0) {
81
+ if (listResult?.items?.length > 0) {
75
82
  throw new _error.default(`Folder with slug "${slug}" already exists at this level.`, "FOLDER_ALREADY_EXISTS", {
76
83
  id,
77
84
  params
@@ -88,11 +95,14 @@ const createFolderOperations = params => {
88
95
  sort,
89
96
  where
90
97
  } = params;
91
- const [entries, meta] = await cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
98
+ const [entries, meta] = await cms.listLatestEntries(model, {
99
+ ...params,
92
100
  sort: (0, _createListSort.createListSort)(sort),
93
- where: (0, _objectSpread2.default)({}, where || {})
94
- }));
95
- return [entries.map(entry => (0, _getFieldValues.getFieldValues)(entry, _createAcoStorageOperations.baseFields)), meta];
101
+ where: {
102
+ ...(where || {})
103
+ }
104
+ });
105
+ return [entries.map(_pickEntryFieldValues.pickEntryFieldValues), meta];
96
106
  });
97
107
  },
98
108
  createFolder({
@@ -106,10 +116,11 @@ const createFolderOperations = params => {
106
116
  parentId: data.parentId
107
117
  }
108
118
  });
109
- const entry = await cms.createEntry(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
119
+ const entry = await cms.createEntry(model, {
120
+ ...data,
110
121
  parentId: data.parentId || null
111
- }));
112
- return (0, _getFieldValues.getFieldValues)(entry, _createAcoStorageOperations.baseFields);
122
+ });
123
+ return (0, _pickEntryFieldValues.pickEntryFieldValues)(entry);
113
124
  });
114
125
  },
115
126
  updateFolder({
@@ -133,9 +144,16 @@ const createFolderOperations = params => {
133
144
  }
134
145
  });
135
146
 
136
- const input = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, original), data);
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
+ };
137
155
  const entry = await cms.updateEntry(model, id, input);
138
- return (0, _getFieldValues.getFieldValues)(entry, _createAcoStorageOperations.baseFields);
156
+ return (0, _pickEntryFieldValues.pickEntryFieldValues)(entry);
139
157
  });
140
158
  },
141
159
  deleteFolder({
@@ -148,4 +166,6 @@ const createFolderOperations = params => {
148
166
  }
149
167
  };
150
168
  };
151
- exports.createFolderOperations = createFolderOperations;
169
+ exports.createFolderOperations = createFolderOperations;
170
+
171
+ //# sourceMappingURL=folder.so.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createFolderOperations","params","cms","withModel","createOperationsWrapper","modelName","FOLDER_MODEL_ID","getFolder","id","slug","type","parentId","model","entry","getEntryById","getEntry","where","latest","WebinyError","getFieldValues","baseFields","checkExistingFolder","existings","listLatestEntries","id_not","limit","length","listFolders","sort","entries","meta","createListSort","map","createFolder","data","createEntry","updateFolder","original","undefined","input","updateEntry","deleteFolder","deleteEntry"],"sources":["folder.so.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n\nimport { FOLDER_MODEL_ID } from \"./folder.model\";\nimport { baseFields, CreateAcoStorageOperationsParams } from \"~/createAcoStorageOperations\";\nimport { createListSort } from \"~/utils/createListSort\";\nimport { createOperationsWrapper } from \"~/utils/createOperationsWrapper\";\nimport { getFieldValues } from \"~/utils/getFieldValues\";\n\nimport { AcoFolderStorageOperations } from \"./folder.types\";\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 getFieldValues(entry, baseFields);\n });\n };\n\n const checkExistingFolder = ({ id, params }: AcoCheckExistingFolderParams) => {\n return withModel(async model => {\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 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(entry => getFieldValues(entry, baseFields)), 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 getFieldValues(entry, baseFields);\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 ...original,\n ...data\n };\n\n const entry = await cms.updateEntry(model, id, input);\n return getFieldValues(entry, baseFields);\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;AAEA;AACA;AACA;AACA;AACA;AAaO,MAAMA,sBAAsB,GAC/BC,MAAwC,IACX;EAC7B,MAAM;IAAEC;EAAI,CAAC,GAAGD,MAAM;EAEtB,MAAM;IAAEE;EAAU,CAAC,GAAG,IAAAC,gDAAuB,8DACtCH,MAAM;IACTI,SAAS,EAAEC;EAAe,GAC5B;EAEF,MAAMC,SAAkD,GAAG,CAAC;IAAEC,E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H,IAAI;UAAEE;QAAS,CAAC,GAAGuB,IAAI;QAE/B,MAAMG,QAAQ,GAAG,MAAM9B,SAAS,CAAC;UAAEC;QAAG,CAAC,CAAC;QAExC,MAAMa,mBAAmB,CAAC;UACtBb,EAAE;UACFP,MAAM,EAAE;YACJS,IAAI,EAAE2B,QAAQ,CAAC3B,IAAI;YACnBD,IAAI,EAAEA,IAAI,IAAI4B,QAAQ,CAAC5B,IAAI;YAC3BE,QAAQ,EAAEA,QAAQ,KAAK2B,SAAS,GAAG3B,QAAQ,GAAG0B,QAAQ,CAAC1B,QAAQ,CAAC;UACpE;QACJ,CAAC,CAAC;;QAEF,MAAM4B,KAAK,+DACJF,QAAQ,GACRH,IAAI,CACV;QAED,MAAMrB,KAAK,GAAG,MAAMX,GAAG,CAACsC,WAAW,CAAC5B,KAAK,EAAEJ,EAAE,EAAE+B,KAAK,CAAC;QACrD,OAAO,IAAApB,8BAAc,EAACN,KAAK,EAAEO,sCAAU,CAAC;MAC5C,CAAC,CAAC;IACN,CAAC;IACDqB,YAAY,CAAC;MAAEjC;IAAG,CAAC,EAAE;MACjB,OAAOL,SAAS,CAAC,MAAMS,KAAK,IAAI;QAC5B,MAAMV,GAAG,CAACwC,WAAW,CAAC9B,KAAK,EAAEJ,EAAE,CAAC;QAChC,OAAO,IAAI;MACf,CAAC,CAAC;IACN;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;EAC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AAC;IACDyB,YAAYA,CAAC;MAAE9B,EAAE;MAAE4B;IAAK,CAAC,EAAE;MACvB,OAAOjC,SAAS,CAAC,MAAMS,KAAK,IAAI;QAC5B,MAAM;UAAEH,IAAI;UAAEE;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, ListSort } 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
  }
@@ -16,15 +26,27 @@ export interface ListFoldersParams {
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, ListSort } 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?: ListSort;\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;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.onFolderBeforeDeleteHcmsHook = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ const onFolderBeforeDeleteHcmsHook = context => {
10
+ context.aco.folder.onFolderBeforeDelete.subscribe(async ({
11
+ folder
12
+ }) => {
13
+ try {
14
+ const {
15
+ id,
16
+ type
17
+ } = folder;
18
+ const modelId = type.split(":")[1];
19
+ if (!modelId) {
20
+ return;
21
+ }
22
+ let model = null;
23
+ try {
24
+ model = await context.cms.getModel(modelId);
25
+ if (!model) {
26
+ return;
27
+ }
28
+ } catch {
29
+ return;
30
+ }
31
+ const [entries] = await context.cms.listEntries(model, {
32
+ where: {
33
+ latest: true,
34
+ wbyAco_location: {
35
+ folderId: id
36
+ }
37
+ },
38
+ limit: 1
39
+ });
40
+ if (entries.length === 0) {
41
+ return;
42
+ }
43
+ throw new _error.default("Delete all child folders and entries before proceeding.", "DELETE_FOLDER_WITH_CHILDREN", {
44
+ folder
45
+ });
46
+ } catch (error) {
47
+ throw _error.default.from(error, {
48
+ message: "Error while executing onFolderBeforeDeleteHcmsHook hook.",
49
+ code: "ACO_BEFORE_FOLDER_DELETE_HCMS_HOOK"
50
+ });
51
+ }
52
+ });
53
+ };
54
+ exports.onFolderBeforeDeleteHcmsHook = onFolderBeforeDeleteHcmsHook;
55
+
56
+ //# sourceMappingURL=onFolderBeforeDeleteHcms.hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","onFolderBeforeDeleteHcmsHook","context","aco","folder","onFolderBeforeDelete","subscribe","id","type","modelId","split","model","cms","getModel","entries","listEntries","where","latest","wbyAco_location","folderId","limit","length","WebinyError","error","from","message","code","exports"],"sources":["onFolderBeforeDeleteHcms.hook.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { AcoContext } from \"~/types\";\n\nexport const onFolderBeforeDeleteHcmsHook = (context: AcoContext) => {\n context.aco.folder.onFolderBeforeDelete.subscribe(async ({ folder }) => {\n try {\n const { id, type } = folder;\n\n const modelId = type.split(\":\")[1];\n\n if (!modelId) {\n return;\n }\n\n let model: CmsModel | null = null;\n try {\n model = await context.cms.getModel(modelId);\n\n if (!model) {\n return;\n }\n } catch {\n return;\n }\n\n const [entries] = await context.cms.listEntries(model, {\n where: {\n latest: true,\n wbyAco_location: {\n folderId: id\n }\n },\n limit: 1\n });\n\n if (entries.length === 0) {\n return;\n }\n\n throw new WebinyError(\n \"Delete all child folders and entries before proceeding.\",\n \"DELETE_FOLDER_WITH_CHILDREN\",\n {\n folder\n }\n );\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"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CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAA1B,4BAAA,GAAAA,4BAAA"}
package/index.d.ts CHANGED
@@ -1 +1,9 @@
1
- export declare const createAco: () => (import("@webiny/api").ContextPlugin<import("./types").AcoContext> | import("@webiny/api-headless-cms/types").CmsModelFieldToGraphQLPlugin<import("@webiny/api-headless-cms/types").CmsModelField>[] | import("@webiny/api").ContextPlugin<import("@webiny/api-admin-settings/types").AdminSettingsContext>)[];
1
+ export { SEARCH_RECORD_MODEL_ID } from "./record/record.model";
2
+ export { FOLDER_MODEL_ID } from "./folder/folder.model";
3
+ export { FILTER_MODEL_ID } from "./filter/filter.model";
4
+ export * from "./apps";
5
+ export * from "./plugins";
6
+ export interface CreateAcoParams {
7
+ useFolderLevelPermissions?: boolean;
8
+ }
9
+ export declare const createAco: (params?: CreateAcoParams) => (import("@webiny/api-headless-cms/types").CmsModelFieldToGraphQLPlugin<import("@webiny/api-headless-cms/types").CmsModelField> | import("@webiny/api").ContextPlugin<import("./types").AcoContext> | import("@webiny/handler-graphql").GraphQLSchemaPlugin<import("./types").AcoContext>)[];
package/index.js CHANGED
@@ -3,12 +3,64 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ createAco: true,
8
+ SEARCH_RECORD_MODEL_ID: true,
9
+ FOLDER_MODEL_ID: true,
10
+ FILTER_MODEL_ID: true
11
+ };
12
+ Object.defineProperty(exports, "FILTER_MODEL_ID", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _filter.FILTER_MODEL_ID;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "FOLDER_MODEL_ID", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _folder.FOLDER_MODEL_ID;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "SEARCH_RECORD_MODEL_ID", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _record.SEARCH_RECORD_MODEL_ID;
28
+ }
29
+ });
6
30
  exports.createAco = void 0;
7
- var _apiAdminSettings = require("@webiny/api-admin-settings");
8
31
  var _createAcoContext = require("./createAcoContext");
9
- var _createAcoFields = require("./createAcoFields");
10
32
  var _createAcoGraphQL = require("./createAcoGraphQL");
11
- const createAco = () => {
12
- return [...(0, _apiAdminSettings.createAdminSettingsContext)(), (0, _createAcoContext.createAcoContext)(), (0, _createAcoFields.createAcoFields)(), (0, _createAcoGraphQL.createAcoGraphQL)()];
33
+ var _fields = require("./fields");
34
+ var _record = require("./record/record.model");
35
+ var _folder = require("./folder/folder.model");
36
+ var _filter = require("./filter/filter.model");
37
+ var _apps = require("./apps");
38
+ Object.keys(_apps).forEach(function (key) {
39
+ if (key === "default" || key === "__esModule") return;
40
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
41
+ if (key in exports && exports[key] === _apps[key]) return;
42
+ Object.defineProperty(exports, key, {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _apps[key];
46
+ }
47
+ });
48
+ });
49
+ var _plugins = require("./plugins");
50
+ Object.keys(_plugins).forEach(function (key) {
51
+ if (key === "default" || key === "__esModule") return;
52
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
53
+ if (key in exports && exports[key] === _plugins[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _plugins[key];
58
+ }
59
+ });
60
+ });
61
+ const createAco = (params = {}) => {
62
+ return [...(0, _fields.createFields)(), (0, _createAcoContext.createAcoContext)(params), ...(0, _createAcoGraphQL.createAcoGraphQL)()];
13
63
  };
14
- exports.createAco = createAco;
64
+ exports.createAco = createAco;
65
+
66
+ //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["createAco","createAdminSettingsContext","createAcoContext","createAcoFields","createAcoGraphQL"],"sources":["index.ts"],"sourcesContent":["import { createAdminSettingsContext } from \"@webiny/api-admin-settings\";\n\nimport { createAcoContext } from \"~/createAcoContext\";\nimport { createAcoFields } from \"~/createAcoFields\";\nimport { createAcoGraphQL } from \"~/createAcoGraphQL\";\n\nexport const createAco = () => {\n return [\n ...createAdminSettingsContext(),\n createAcoContext(),\n createAcoFields(),\n createAcoGraphQL()\n ];\n};\n"],"mappings":";;;;;;AAAA;AAEA;AACA;AACA;AAEO,MAAMA,SAAS,GAAG,MAAM;EAC3B,OAAO,CACH,GAAG,IAAAC,4CAA0B,GAAE,EAC/B,IAAAC,kCAAgB,GAAE,EAClB,IAAAC,gCAAe,GAAE,EACjB,IAAAC,kCAAgB,GAAE,CACrB;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["_createAcoContext","require","_createAcoGraphQL","_fields","_record","_folder","_filter","_apps","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_plugins","createAco","params","createFields","createAcoContext","createAcoGraphQL"],"sources":["index.ts"],"sourcesContent":["import { createAcoContext } from \"~/createAcoContext\";\nimport { createAcoGraphQL } from \"~/createAcoGraphQL\";\nimport { createFields } from \"~/fields\";\n\nexport { SEARCH_RECORD_MODEL_ID } from \"./record/record.model\";\nexport { FOLDER_MODEL_ID } from \"./folder/folder.model\";\nexport { FILTER_MODEL_ID } from \"./filter/filter.model\";\nexport * from \"./apps\";\nexport * from \"./plugins\";\n\nexport interface CreateAcoParams {\n useFolderLevelPermissions?: boolean;\n}\n\nexport const createAco = (params: CreateAcoParams = {}) => {\n return [...createFields(), createAcoContext(params), ...createAcoGraphQL()];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AAAAO,MAAA,CAAAC,IAAA,CAAAF,KAAA,EAAAG,OAA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