@webiny/api-aco 0.0.0-unstable.7f63ea0744 → 0.0.0-unstable.99666aeb00

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 (107) hide show
  1. package/README.md +6 -6
  2. package/apps/AcoApp.d.ts +16 -0
  3. package/apps/AcoApp.js +108 -0
  4. package/apps/AcoApp.js.map +1 -0
  5. package/apps/AcoApps.d.ts +10 -0
  6. package/apps/AcoApps.js +76 -0
  7. package/apps/AcoApps.js.map +1 -0
  8. package/apps/app.gql.d.ts +3 -0
  9. package/apps/app.gql.js +58 -0
  10. package/apps/app.gql.js.map +1 -0
  11. package/apps/index.d.ts +2 -0
  12. package/apps/index.js +27 -0
  13. package/apps/index.js.map +1 -0
  14. package/createAcoContext.js +50 -13
  15. package/createAcoContext.js.map +1 -1
  16. package/createAcoGraphQL.d.ts +2 -2
  17. package/createAcoGraphQL.js +44 -14
  18. package/createAcoGraphQL.js.map +1 -1
  19. package/createAcoModels.js +0 -25
  20. package/createAcoModels.js.map +1 -1
  21. package/{createAcoFields.d.ts → fields/index.d.ts} +1 -1
  22. package/fields/index.js +12 -0
  23. package/fields/index.js.map +1 -0
  24. package/fields/location.d.ts +2 -0
  25. package/fields/location.js +44 -0
  26. package/fields/location.js.map +1 -0
  27. package/folder/folder.crud.js +18 -0
  28. package/folder/folder.crud.js.map +1 -1
  29. package/folder/folder.gql.js +20 -5
  30. package/folder/folder.gql.js.map +1 -1
  31. package/folder/folder.model.d.ts +3 -3
  32. package/folder/folder.model.js +3 -25
  33. package/folder/folder.model.js.map +1 -1
  34. package/folder/folder.so.d.ts +1 -6
  35. package/folder/folder.so.js +103 -108
  36. package/folder/folder.so.js.map +1 -1
  37. package/folder/folder.types.d.ts +9 -3
  38. package/folder/folder.types.js.map +1 -1
  39. package/folder/onFolderBeforeDelete.hook.js +40 -27
  40. package/folder/onFolderBeforeDelete.hook.js.map +1 -1
  41. package/index.d.ts +5 -1
  42. package/index.js +48 -6
  43. package/index.js.map +1 -1
  44. package/package.json +34 -31
  45. package/plugins/AcoAppModifierPlugin.d.ts +43 -0
  46. package/plugins/AcoAppModifierPlugin.js +59 -0
  47. package/plugins/AcoAppModifierPlugin.js.map +1 -0
  48. package/plugins/AcoAppRegisterPlugin.d.ts +8 -0
  49. package/plugins/AcoAppRegisterPlugin.js +22 -0
  50. package/plugins/AcoAppRegisterPlugin.js.map +1 -0
  51. package/plugins/index.d.ts +2 -0
  52. package/plugins/index.js +27 -0
  53. package/plugins/index.js.map +1 -0
  54. package/record/graphql/createAppResolvers.d.ts +14 -0
  55. package/record/graphql/createAppResolvers.js +108 -0
  56. package/record/graphql/createAppResolvers.js.map +1 -0
  57. package/record/graphql/createAppSchema.d.ts +9 -0
  58. package/record/graphql/createAppSchema.js +142 -0
  59. package/record/graphql/createAppSchema.js.map +1 -0
  60. package/record/record.crud.js +46 -12
  61. package/record/record.crud.js.map +1 -1
  62. package/record/record.gql.d.ts +8 -3
  63. package/record/record.gql.js +36 -113
  64. package/record/record.gql.js.map +1 -1
  65. package/record/record.model.d.ts +10 -4
  66. package/record/record.model.js +39 -28
  67. package/record/record.model.js.map +1 -1
  68. package/record/record.so.d.ts +1 -6
  69. package/record/record.so.js +112 -62
  70. package/record/record.so.js.map +1 -1
  71. package/record/record.types.d.ts +66 -15
  72. package/record/record.types.js.map +1 -1
  73. package/types.d.ts +56 -3
  74. package/types.js +35 -1
  75. package/types.js.map +1 -1
  76. package/utils/acoRecordId.d.ts +6 -0
  77. package/utils/acoRecordId.js +33 -0
  78. package/utils/acoRecordId.js.map +1 -0
  79. package/utils/checkPermissions.d.ts +2 -0
  80. package/utils/checkPermissions.js +14 -0
  81. package/utils/checkPermissions.js.map +1 -0
  82. package/utils/createListSort.d.ts +2 -0
  83. package/utils/createListSort.js +13 -0
  84. package/utils/createListSort.js.map +1 -0
  85. package/utils/createModelField.d.ts +0 -1
  86. package/utils/createModelField.js +2 -4
  87. package/utils/createModelField.js.map +1 -1
  88. package/utils/createOperationsWrapper.d.ts +9 -0
  89. package/utils/createOperationsWrapper.js +29 -0
  90. package/utils/createOperationsWrapper.js.map +1 -0
  91. package/utils/getFieldValues.d.ts +4 -1
  92. package/utils/getFieldValues.js +6 -2
  93. package/utils/getFieldValues.js.map +1 -1
  94. package/utils/getFolderAndItsAncestors.d.ts +7 -0
  95. package/utils/getFolderAndItsAncestors.js +48 -0
  96. package/utils/getFolderAndItsAncestors.js.map +1 -0
  97. package/utils/modelFactory.d.ts +3 -3
  98. package/utils/modelFactory.js +4 -2
  99. package/utils/modelFactory.js.map +1 -1
  100. package/utils/resolve.d.ts +2 -1
  101. package/utils/resolve.js +11 -2
  102. package/utils/resolve.js.map +1 -1
  103. package/createAcoCrud.d.ts +0 -2
  104. package/createAcoCrud.js +0 -17
  105. package/createAcoCrud.js.map +0 -1
  106. package/createAcoFields.js +0 -40
  107. package/createAcoFields.js.map +0 -1
@@ -9,147 +9,142 @@ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/obje
9
9
  var _error = _interopRequireDefault(require("@webiny/error"));
10
10
  var _folder = require("./folder.model");
11
11
  var _createAcoStorageOperations = require("../createAcoStorageOperations");
12
+ var _createListSort = require("../utils/createListSort");
13
+ var _createOperationsWrapper = require("../utils/createOperationsWrapper");
12
14
  var _getFieldValues = require("../utils/getFieldValues");
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)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
22
+ modelName: _folder.FOLDER_MODEL_ID
23
+ }));
24
+ const getFolder = ({
28
25
  id,
29
26
  slug,
30
27
  type,
31
28
  parentId
32
29
  }) => {
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: {
30
+ return withModel(async model => {
31
+ let entry;
32
+ if (id) {
33
+ entry = await cms.getEntryById(model, id);
34
+ } else if (slug && type) {
35
+ entry = await cms.getEntry(model, {
36
+ where: {
37
+ slug,
38
+ type,
39
+ parentId,
40
+ latest: true
41
+ }
42
+ });
43
+ }
44
+ if (!entry) {
45
+ throw new _error.default("Could not load folder.", "GET_FOLDER_ERROR", {
46
+ id,
41
47
  slug,
42
48
  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);
49
+ parentId
50
+ });
51
+ }
52
+ return (0, _getFieldValues.getFolderFieldValues)(entry, _createAcoStorageOperations.baseFields);
53
+ });
58
54
  };
59
- const checkExistingFolder = async ({
55
+ const checkExistingFolder = ({
60
56
  id,
61
57
  params
62
58
  }) => {
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: {
59
+ return withModel(async model => {
60
+ const {
72
61
  type,
73
62
  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
63
+ parentId
64
+ } = params;
65
+ const [existings] = await cms.listLatestEntries(model, {
66
+ where: {
67
+ type,
68
+ slug,
69
+ parentId,
70
+ id_not: id
71
+ },
72
+ limit: 1
83
73
  });
84
- }
85
- security.enableAuthorization();
86
- return;
74
+ if (existings.length > 0) {
75
+ throw new _error.default(`Folder with slug "${slug}" already exists at this level.`, "FOLDER_ALREADY_EXISTS", {
76
+ id,
77
+ params
78
+ });
79
+ }
80
+ return;
81
+ });
87
82
  };
88
83
  return {
89
- getFolderModel,
90
84
  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];
85
+ listFolders(params) {
86
+ return withModel(async model => {
87
+ const {
88
+ sort,
89
+ where
90
+ } = params;
91
+ const [entries, meta] = await cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
92
+ sort: (0, _createListSort.createListSort)(sort),
93
+ where: (0, _objectSpread2.default)({}, where || {})
94
+ }));
95
+ return [entries.map(entry => (0, _getFieldValues.getFolderFieldValues)(entry, _createAcoStorageOperations.baseFields)), meta];
96
+ });
99
97
  },
100
- async createFolder({
98
+ createFolder({
101
99
  data
102
100
  }) {
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
- }
101
+ return withModel(async model => {
102
+ await checkExistingFolder({
103
+ params: {
104
+ type: data.type,
105
+ slug: data.slug,
106
+ parentId: data.parentId
107
+ }
108
+ });
109
+ const entry = await cms.createEntry(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
110
+ parentId: data.parentId || null
111
+ }));
112
+ return (0, _getFieldValues.getFolderFieldValues)(entry, _createAcoStorageOperations.baseFields);
111
113
  });
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
114
  },
118
- async updateFolder({
115
+ updateFolder({
119
116
  id,
120
117
  data
121
118
  }) {
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
- });
119
+ return withModel(async model => {
120
+ const {
121
+ slug,
122
+ parentId
123
+ } = data;
124
+ const original = await getFolder({
125
+ id
126
+ });
127
+ await checkExistingFolder({
128
+ id,
129
+ params: {
130
+ type: original.type,
131
+ slug: slug || original.slug,
132
+ parentId: parentId !== undefined ? parentId : original.parentId // parentId can be `null`
133
+ }
134
+ });
139
135
 
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);
136
+ const input = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, original), data);
137
+ const entry = await cms.updateEntry(model, id, input);
138
+ return (0, _getFieldValues.getFolderFieldValues)(entry, _createAcoStorageOperations.baseFields);
139
+ });
144
140
  },
145
- async deleteFolder({
141
+ deleteFolder({
146
142
  id
147
143
  }) {
148
- const model = await getFolderModel();
149
- security.disableAuthorization();
150
- await cms.deleteEntry(model, id);
151
- security.enableAuthorization();
152
- return true;
144
+ return withModel(async model => {
145
+ await cms.deleteEntry(model, id);
146
+ return true;
147
+ });
153
148
  }
154
149
  };
155
150
  };
@@ -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,GA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7B;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":["createFolderOperations","params","cms","withModel","createOperationsWrapper","modelName","FOLDER_MODEL_ID","getFolder","id","slug","type","parentId","model","entry","getEntryById","getEntry","where","latest","WebinyError","getFolderFieldValues","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 { getFolderFieldValues } 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 getFolderFieldValues(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 => getFolderFieldValues(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 getFolderFieldValues(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 getFolderFieldValues(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,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AAE5B,EAAE;MAAE0B;IAAK,CAAC,EAAE;MACvB,OAAO/B,SAAS,CAAC,MAAMS,KAAK,IAAI;QAC5B,MAAM;UAAEH,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,oCAAoB,EAACN,KAAK,EAAEO,sCAAU,CAAC;MAClD,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,6 +1,11 @@
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
+ export interface Folder {
4
+ id: string;
5
+ entryId: string;
6
+ createdOn: string;
7
+ createdBy: User;
8
+ savedOn: string;
4
9
  title: string;
5
10
  slug: string;
6
11
  type: string;
@@ -12,7 +17,7 @@ export interface ListFoldersWhere {
12
17
  }
13
18
  export interface ListFoldersParams {
14
19
  where: ListFoldersWhere;
15
- sort?: string[];
20
+ sort?: ListSort;
16
21
  limit?: number;
17
22
  after?: string | null;
18
23
  }
@@ -67,6 +72,7 @@ export interface AcoFolderCrud {
67
72
  create(data: CreateFolderParams): Promise<Folder>;
68
73
  update(id: string, data: UpdateFolderParams): Promise<Folder>;
69
74
  delete(id: string): Promise<Boolean>;
75
+ getFolderWithAncestors(id: string): Promise<Folder[]>;
70
76
  onFolderBeforeCreate: Topic<OnFolderBeforeCreateTopicParams>;
71
77
  onFolderAfterCreate: Topic<OnFolderAfterCreateTopicParams>;
72
78
  onFolderBeforeUpdate: Topic<OnFolderBeforeUpdateTopicParams>;
@@ -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\";\n\nexport interface Folder {\n id: string;\n entryId: string;\n createdOn: string;\n createdBy: User;\n savedOn: string;\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 getFolderWithAncestors(id: string): Promise<Folder[]>;\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":""}
@@ -6,19 +6,25 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.onFolderBeforeDeleteHook = void 0;
8
8
  var _error = _interopRequireDefault(require("@webiny/error"));
9
+ const throwDeleteError = folder => {
10
+ throw new _error.default("Error: delete all child folders and entries before proceeding.", "DELETE_FOLDER_WITH_CHILDREN", {
11
+ folder
12
+ });
13
+ };
9
14
  const onFolderBeforeDeleteHook = ({
10
15
  aco
11
16
  }) => {
12
- try {
13
- aco.folder.onFolderBeforeDelete.subscribe(async ({
14
- folder
15
- }) => {
17
+ aco.folder.onFolderBeforeDelete.subscribe(async ({
18
+ folder
19
+ }) => {
20
+ try {
16
21
  const {
17
22
  id,
18
23
  type
19
24
  } = folder;
20
-
21
- // Fetching all child folders
25
+ /**
26
+ * First we check for the child folders.
27
+ */
22
28
  const [children] = await aco.folder.list({
23
29
  where: {
24
30
  type,
@@ -26,28 +32,35 @@ const onFolderBeforeDeleteHook = ({
26
32
  },
27
33
  limit: 1
28
34
  });
29
-
30
- // Fetching all records inside the folder
31
- const [records] = await aco.search.list({
32
- where: {
33
- type,
34
- location: {
35
- folderId: id
36
- }
37
- },
38
- limit: 1
39
- });
40
- if (children.length > 0 || records.length > 0) {
41
- throw new _error.default("Error: delete all child folders and entries before proceeding.", "DELETE_FOLDER_WITH_CHILDREN", {
42
- folder
35
+ if (children.length > 0) {
36
+ throwDeleteError(folder);
37
+ }
38
+ /**
39
+ * Then for entries in each of the apps.
40
+ * Because we split the apps we must do it like this.
41
+ */
42
+ const apps = aco.listApps();
43
+ for (const app of apps) {
44
+ const [records] = await app.search.list({
45
+ where: {
46
+ type,
47
+ location: {
48
+ folderId: id
49
+ }
50
+ },
51
+ limit: 1
43
52
  });
53
+ if (records.length === 0) {
54
+ continue;
55
+ }
56
+ throwDeleteError(folder);
44
57
  }
45
- });
46
- } catch (error) {
47
- throw _error.default.from(error, {
48
- message: "Error while executing onFolderBeforeDelete hook",
49
- code: "ACO_BEFORE_FOLDER_DELETE_HOOK"
50
- });
51
- }
58
+ } catch (error) {
59
+ throw _error.default.from(error, {
60
+ message: "Error while executing onFolderBeforeDelete hook",
61
+ code: "ACO_BEFORE_FOLDER_DELETE_HOOK"
62
+ });
63
+ }
64
+ });
52
65
  };
53
66
  exports.onFolderBeforeDeleteHook = onFolderBeforeDeleteHook;
@@ -1 +1 @@
1
- {"version":3,"names":["onFolderBeforeDeleteHook","aco","folder","onFolderBeforeDelete","subscribe","id","type","children","list","where","parentId","limit","records","search","location","folderId","length","WebinyError","error","from","message","code"],"sources":["onFolderBeforeDelete.hook.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { AcoContext } from \"~/types\";\n\nexport const onFolderBeforeDeleteHook = ({ aco }: AcoContext) => {\n try {\n aco.folder.onFolderBeforeDelete.subscribe(async ({ folder }) => {\n const { id, type } = folder;\n\n // Fetching all child folders\n const [children] = await aco.folder.list({\n where: { type, parentId: id },\n limit: 1\n });\n\n // Fetching all records inside the folder\n const [records] = await aco.search.list({\n where: { type, location: { folderId: id } },\n limit: 1\n });\n\n if (children.length > 0 || records.length > 0) {\n throw new WebinyError(\n \"Error: delete all child folders and entries before proceeding.\",\n \"DELETE_FOLDER_WITH_CHILDREN\",\n {\n folder\n }\n );\n }\n });\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing onFolderBeforeDelete hook\",\n code: \"ACO_BEFORE_FOLDER_DELETE_HOOK\"\n });\n }\n};\n"],"mappings":";;;;;;;AAAA;AAGO,MAAMA,wBAAwB,GAAG,CAAC;EAAEC;AAAgB,CAAC,KAAK;EAC7D,IAAI;IACAA,GAAG,CAACC,MAAM,CAACC,oBAAoB,CAACC,SAAS,CAAC,OAAO;MAAEF;IAAO,CAAC,KAAK;MAC5D,MAAM;QAAEG,EAAE;QAAEC;MAAK,CAAC,GAAGJ,MAAM;;MAE3B;MACA,MAAM,CAACK,QAAQ,CAAC,GAAG,MAAMN,GAAG,CAACC,MAAM,CAACM,IAAI,CAAC;QACrCC,KAAK,EAAE;UAAEH,IAAI;UAAEI,QAAQ,EAAEL;QAAG,CAAC;QAC7BM,KAAK,EAAE;MACX,CAAC,CAAC;;MAEF;MACA,MAAM,CAACC,OAAO,CAAC,GAAG,MAAMX,GAAG,CAACY,MAAM,CAACL,IAAI,CAAC;QACpCC,KAAK,EAAE;UAAEH,IAAI;UAAEQ,QAAQ,EAAE;YAAEC,QAAQ,EAAEV;UAAG;QAAE,CAAC;QAC3CM,KAAK,EAAE;MACX,CAAC,CAAC;MAEF,IAAIJ,QAAQ,CAACS,MAAM,GAAG,CAAC,IAAIJ,OAAO,CAACI,MAAM,GAAG,CAAC,EAAE;QAC3C,MAAM,IAAIC,cAAW,CACjB,gEAAgE,EAChE,6BAA6B,EAC7B;UACIf;QACJ,CAAC,CACJ;MACL;IACJ,CAAC,CAAC;EACN,CAAC,CAAC,OAAOgB,KAAK,EAAE;IACZ,MAAMD,cAAW,CAACE,IAAI,CAACD,KAAK,EAAE;MAC1BE,OAAO,EAAE,iDAAiD;MAC1DC,IAAI,EAAE;IACV,CAAC,CAAC;EACN;AACJ,CAAC;AAAC"}
1
+ {"version":3,"names":["throwDeleteError","folder","WebinyError","onFolderBeforeDeleteHook","aco","onFolderBeforeDelete","subscribe","id","type","children","list","where","parentId","limit","length","apps","listApps","app","records","search","location","folderId","error","from","message","code"],"sources":["onFolderBeforeDelete.hook.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { AcoContext, Folder } from \"~/types\";\n\nconst throwDeleteError = (folder: Folder) => {\n throw new WebinyError(\n \"Error: delete all child folders and entries before proceeding.\",\n \"DELETE_FOLDER_WITH_CHILDREN\",\n {\n folder\n }\n );\n};\n\nexport const onFolderBeforeDeleteHook = ({ 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 if (children.length > 0) {\n throwDeleteError(folder);\n }\n /**\n * Then for entries in each of the apps.\n * Because we split the apps we must do it like this.\n */\n const apps = aco.listApps();\n for (const app of apps) {\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 continue;\n }\n throwDeleteError(folder);\n }\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing onFolderBeforeDelete hook\",\n code: \"ACO_BEFORE_FOLDER_DELETE_HOOK\"\n });\n }\n });\n};\n"],"mappings":";;;;;;;AAAA;AAGA,MAAMA,gBAAgB,GAAIC,MAAc,IAAK;EACzC,MAAM,IAAIC,cAAW,CACjB,gEAAgE,EAChE,6BAA6B,EAC7B;IACID;EACJ,CAAC,CACJ;AACL,CAAC;AAEM,MAAME,wBAAwB,GAAG,CAAC;EAAEC;AAAgB,CAAC,KAAK;EAC7DA,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;MACF,IAAIJ,QAAQ,CAACK,MAAM,GAAG,CAAC,EAAE;QACrBd,gBAAgB,CAACC,MAAM,CAAC;MAC5B;MACA;AACZ;AACA;AACA;MACY,MAAMc,IAAI,GAAGX,GAAG,CAACY,QAAQ,EAAE;MAC3B,KAAK,MAAMC,GAAG,IAAIF,IAAI,EAAE;QACpB,MAAM,CAACG,OAAO,CAAC,GAAG,MAAMD,GAAG,CAACE,MAAM,CAACT,IAAI,CAAC;UACpCC,KAAK,EAAE;YACHH,IAAI;YACJY,QAAQ,EAAE;cACNC,QAAQ,EAAEd;YACd;UACJ,CAAC;UACDM,KAAK,EAAE;QACX,CAAC,CAAC;QACF,IAAIK,OAAO,CAACJ,MAAM,KAAK,CAAC,EAAE;UACtB;QACJ;QACAd,gBAAgB,CAACC,MAAM,CAAC;MAC5B;IACJ,CAAC,CAAC,OAAOqB,KAAK,EAAE;MACZ,MAAMpB,cAAW,CAACqB,IAAI,CAACD,KAAK,EAAE;QAC1BE,OAAO,EAAE,iDAAiD;QAC1DC,IAAI,EAAE;MACV,CAAC,CAAC;IACN;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
package/index.d.ts CHANGED
@@ -1 +1,5 @@
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 * from "./apps";
4
+ export * from "./plugins";
5
+ export declare const createAco: () => (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,54 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.createACO = void 0;
7
- var _apiAdminSettings = require("@webiny/api-admin-settings");
6
+ var _exportNames = {
7
+ createAco: true,
8
+ SEARCH_RECORD_MODEL_ID: true,
9
+ FOLDER_MODEL_ID: true
10
+ };
11
+ Object.defineProperty(exports, "FOLDER_MODEL_ID", {
12
+ enumerable: true,
13
+ get: function () {
14
+ return _folder.FOLDER_MODEL_ID;
15
+ }
16
+ });
17
+ Object.defineProperty(exports, "SEARCH_RECORD_MODEL_ID", {
18
+ enumerable: true,
19
+ get: function () {
20
+ return _record.SEARCH_RECORD_MODEL_ID;
21
+ }
22
+ });
23
+ exports.createAco = void 0;
8
24
  var _createAcoContext = require("./createAcoContext");
9
- var _createAcoFields = require("./createAcoFields");
10
25
  var _createAcoGraphQL = require("./createAcoGraphQL");
11
- const createACO = () => {
12
- return [...(0, _apiAdminSettings.createAdminSettingsContext)(), (0, _createAcoContext.createAcoContext)(), (0, _createAcoFields.createAcoFields)(), (0, _createAcoGraphQL.createAcoGraphQL)()];
26
+ var _fields = require("./fields");
27
+ var _record = require("./record/record.model");
28
+ var _folder = require("./folder/folder.model");
29
+ var _apps = require("./apps");
30
+ Object.keys(_apps).forEach(function (key) {
31
+ if (key === "default" || key === "__esModule") return;
32
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
33
+ if (key in exports && exports[key] === _apps[key]) return;
34
+ Object.defineProperty(exports, key, {
35
+ enumerable: true,
36
+ get: function () {
37
+ return _apps[key];
38
+ }
39
+ });
40
+ });
41
+ var _plugins = require("./plugins");
42
+ Object.keys(_plugins).forEach(function (key) {
43
+ if (key === "default" || key === "__esModule") return;
44
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
45
+ if (key in exports && exports[key] === _plugins[key]) return;
46
+ Object.defineProperty(exports, key, {
47
+ enumerable: true,
48
+ get: function () {
49
+ return _plugins[key];
50
+ }
51
+ });
52
+ });
53
+ const createAco = () => {
54
+ return [...(0, _fields.createFields)(), (0, _createAcoContext.createAcoContext)(), ...(0, _createAcoGraphQL.createAcoGraphQL)()];
13
55
  };
14
- exports.createACO = createACO;
56
+ exports.createAco = createAco;
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":["createAco","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 * from \"./apps\";\nexport * from \"./plugins\";\n\nexport const createAco = () => {\n return [...createFields(), createAcoContext(), ...createAcoGraphQL()];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AAEA;AACA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAEO,MAAMA,SAAS,GAAG,MAAM;EAC3B,OAAO,CAAC,GAAG,IAAAC,oBAAY,GAAE,EAAE,IAAAC,kCAAgB,GAAE,EAAE,GAAG,IAAAC,kCAAgB,GAAE,CAAC;AACzE,CAAC;AAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-aco",
3
- "version": "0.0.0-unstable.7f63ea0744",
3
+ "version": "0.0.0-unstable.99666aeb00",
4
4
  "main": "index.js",
5
5
  "keywords": [
6
6
  "aco:base"
@@ -21,37 +21,40 @@
21
21
  "access": "public",
22
22
  "directory": "dist"
23
23
  },
24
- "devDependencies": {
25
- "@babel/cli": "^7.19.3",
26
- "@babel/core": "^7.19.3",
27
- "@babel/preset-env": "^7.19.4",
28
- "@babel/preset-typescript": "^7.18.6",
29
- "@babel/runtime": "^7.19.0",
30
- "@webiny/api-headless-cms-ddb": "^0.0.0-unstable.7f63ea0744",
31
- "@webiny/api-i18n-ddb": "^0.0.0-unstable.7f63ea0744",
32
- "@webiny/api-security-so-ddb": "^0.0.0-unstable.7f63ea0744",
33
- "@webiny/api-tenancy-so-ddb": "^0.0.0-unstable.7f63ea0744",
34
- "@webiny/api-wcp": "^0.0.0-unstable.7f63ea0744",
35
- "@webiny/cli": "^0.0.0-unstable.7f63ea0744",
36
- "@webiny/handler-aws": "^0.0.0-unstable.7f63ea0744",
37
- "@webiny/plugins": "^0.0.0-unstable.7f63ea0744",
38
- "@webiny/project-utils": "^0.0.0-unstable.7f63ea0744",
39
- "rimraf": "^3.0.2",
40
- "ttypescript": "^1.5.13",
41
- "typescript": "^4.7.4"
42
- },
43
24
  "dependencies": {
44
- "@webiny/api": "0.0.0-unstable.7f63ea0744",
45
- "@webiny/api-admin-settings": "0.0.0-unstable.7f63ea0744",
46
- "@webiny/api-headless-cms": "0.0.0-unstable.7f63ea0744",
47
- "@webiny/api-i18n": "0.0.0-unstable.7f63ea0744",
48
- "@webiny/api-security": "0.0.0-unstable.7f63ea0744",
49
- "@webiny/api-tenancy": "0.0.0-unstable.7f63ea0744",
50
- "@webiny/error": "0.0.0-unstable.7f63ea0744",
51
- "@webiny/handler": "0.0.0-unstable.7f63ea0744",
52
- "@webiny/handler-graphql": "0.0.0-unstable.7f63ea0744",
53
- "@webiny/pubsub": "0.0.0-unstable.7f63ea0744",
25
+ "@ungap/structured-clone": "1.2.0",
26
+ "@webiny/api": "0.0.0-unstable.99666aeb00",
27
+ "@webiny/api-headless-cms": "0.0.0-unstable.99666aeb00",
28
+ "@webiny/api-i18n": "0.0.0-unstable.99666aeb00",
29
+ "@webiny/api-security": "0.0.0-unstable.99666aeb00",
30
+ "@webiny/api-tenancy": "0.0.0-unstable.99666aeb00",
31
+ "@webiny/error": "0.0.0-unstable.99666aeb00",
32
+ "@webiny/handler": "0.0.0-unstable.99666aeb00",
33
+ "@webiny/handler-graphql": "0.0.0-unstable.99666aeb00",
34
+ "@webiny/pubsub": "0.0.0-unstable.99666aeb00",
35
+ "@webiny/utils": "0.0.0-unstable.99666aeb00",
54
36
  "lodash": "4.17.21"
55
37
  },
56
- "gitHead": "7f63ea0744c9e31977e5dabb95538d22b4db585c"
38
+ "devDependencies": {
39
+ "@babel/cli": "7.20.7",
40
+ "@babel/core": "7.20.12",
41
+ "@babel/preset-env": "7.20.2",
42
+ "@babel/preset-typescript": "7.18.6",
43
+ "@babel/runtime": "7.20.13",
44
+ "@types/ungap__structured-clone": "0.3.0",
45
+ "@webiny/api-i18n-ddb": "0.0.0-unstable.99666aeb00",
46
+ "@webiny/api-security-so-ddb": "0.0.0-unstable.99666aeb00",
47
+ "@webiny/api-tenancy-so-ddb": "0.0.0-unstable.99666aeb00",
48
+ "@webiny/api-wcp": "0.0.0-unstable.99666aeb00",
49
+ "@webiny/cli": "0.0.0-unstable.99666aeb00",
50
+ "@webiny/handler-aws": "0.0.0-unstable.99666aeb00",
51
+ "@webiny/plugins": "0.0.0-unstable.99666aeb00",
52
+ "@webiny/project-utils": "0.0.0-unstable.99666aeb00",
53
+ "graphql": "16.6.0",
54
+ "prettier": "2.8.8",
55
+ "rimraf": "3.0.2",
56
+ "ttypescript": "1.5.15",
57
+ "typescript": "4.7.4"
58
+ },
59
+ "gitHead": "99666aeb00056c56292eeb5dbb6aba7fda2439e2"
57
60
  }