@webiny/api-aco 0.0.0-ee-vpcs.549378cf03 → 0.0.0-unstable.085ff6572f

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 (149) hide show
  1. package/README.md +15 -0
  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.d.ts +3 -0
  15. package/createAcoContext.js +100 -0
  16. package/createAcoContext.js.map +1 -0
  17. package/createAcoGraphQL.d.ts +3 -0
  18. package/createAcoGraphQL.js +121 -0
  19. package/createAcoGraphQL.js.map +1 -0
  20. package/createAcoHooks.d.ts +2 -0
  21. package/createAcoHooks.js +11 -0
  22. package/createAcoHooks.js.map +1 -0
  23. package/createAcoModels.d.ts +2 -0
  24. package/createAcoModels.js +42 -0
  25. package/createAcoModels.js.map +1 -0
  26. package/createAcoStorageOperations.d.ts +10 -0
  27. package/createAcoStorageOperations.js +19 -0
  28. package/createAcoStorageOperations.js.map +1 -0
  29. package/fields/index.d.ts +2 -0
  30. package/fields/index.js +12 -0
  31. package/fields/index.js.map +1 -0
  32. package/fields/location.d.ts +2 -0
  33. package/fields/location.js +44 -0
  34. package/fields/location.js.map +1 -0
  35. package/folder/folder.crud.d.ts +3 -0
  36. package/folder/folder.crud.js +110 -0
  37. package/folder/folder.crud.js.map +1 -0
  38. package/folder/folder.gql.d.ts +3 -0
  39. package/folder/folder.gql.js +118 -0
  40. package/folder/folder.gql.js.map +1 -0
  41. package/folder/folder.model.d.ts +4 -0
  42. package/folder/folder.model.js +75 -0
  43. package/folder/folder.model.js.map +1 -0
  44. package/folder/folder.so.d.ts +3 -0
  45. package/folder/folder.so.js +151 -0
  46. package/folder/folder.so.js.map +1 -0
  47. package/folder/folder.types.d.ts +89 -0
  48. package/folder/folder.types.js +5 -0
  49. package/folder/folder.types.js.map +1 -0
  50. package/folder/onFolderBeforeDelete.hook.d.ts +2 -0
  51. package/folder/onFolderBeforeDelete.hook.js +66 -0
  52. package/folder/onFolderBeforeDelete.hook.js.map +1 -0
  53. package/index.d.ts +5 -9
  54. package/index.js +48 -63
  55. package/index.js.map +1 -1
  56. package/package.json +35 -30
  57. package/plugins/AcoAppModifierPlugin.d.ts +43 -0
  58. package/plugins/AcoAppModifierPlugin.js +59 -0
  59. package/plugins/AcoAppModifierPlugin.js.map +1 -0
  60. package/plugins/AcoAppRegisterPlugin.d.ts +8 -0
  61. package/plugins/AcoAppRegisterPlugin.js +22 -0
  62. package/plugins/AcoAppRegisterPlugin.js.map +1 -0
  63. package/plugins/index.d.ts +2 -0
  64. package/plugins/index.js +27 -0
  65. package/plugins/index.js.map +1 -0
  66. package/record/graphql/createAppResolvers.d.ts +14 -0
  67. package/record/graphql/createAppResolvers.js +108 -0
  68. package/record/graphql/createAppResolvers.js.map +1 -0
  69. package/record/graphql/createAppSchema.d.ts +9 -0
  70. package/record/graphql/createAppSchema.js +142 -0
  71. package/record/graphql/createAppSchema.js.map +1 -0
  72. package/record/record.crud.d.ts +3 -0
  73. package/record/record.crud.js +126 -0
  74. package/record/record.crud.js.map +1 -0
  75. package/record/record.gql.d.ts +8 -0
  76. package/record/record.gql.js +41 -0
  77. package/record/record.gql.js.map +1 -0
  78. package/record/record.model.d.ts +10 -0
  79. package/record/record.model.js +86 -0
  80. package/record/record.model.js.map +1 -0
  81. package/record/record.so.d.ts +3 -0
  82. package/record/record.so.js +150 -0
  83. package/record/record.so.js.map +1 -0
  84. package/record/record.types.d.ts +143 -0
  85. package/record/record.types.js +5 -0
  86. package/record/record.types.js.map +1 -0
  87. package/types.d.ts +73 -201
  88. package/types.js +35 -1
  89. package/types.js.map +1 -1
  90. package/utils/acoRecordId.d.ts +6 -0
  91. package/utils/acoRecordId.js +33 -0
  92. package/utils/acoRecordId.js.map +1 -0
  93. package/utils/checkPermissions.d.ts +2 -0
  94. package/utils/checkPermissions.js +14 -0
  95. package/utils/checkPermissions.js.map +1 -0
  96. package/utils/createListSort.d.ts +2 -0
  97. package/utils/createListSort.js +13 -0
  98. package/utils/createListSort.js.map +1 -0
  99. package/utils/createModelField.d.ts +5 -0
  100. package/utils/createModelField.js +37 -0
  101. package/utils/createModelField.js.map +1 -0
  102. package/utils/createOperationsWrapper.d.ts +9 -0
  103. package/utils/createOperationsWrapper.js +29 -0
  104. package/utils/createOperationsWrapper.js.map +1 -0
  105. package/utils/fieldResolver.d.ts +16 -0
  106. package/utils/fieldResolver.js +44 -0
  107. package/utils/fieldResolver.js.map +1 -0
  108. package/utils/getFieldValues.d.ts +5 -0
  109. package/utils/getFieldValues.js +16 -0
  110. package/utils/getFieldValues.js.map +1 -0
  111. package/utils/getFolderAndItsAncestors.d.ts +7 -0
  112. package/utils/getFolderAndItsAncestors.js +48 -0
  113. package/utils/getFolderAndItsAncestors.js.map +1 -0
  114. package/utils/isInstallationPending.d.ts +4 -0
  115. package/utils/isInstallationPending.js +21 -0
  116. package/utils/isInstallationPending.js.map +1 -0
  117. package/utils/modelFactory.d.ts +15 -0
  118. package/utils/modelFactory.js +25 -0
  119. package/utils/modelFactory.js.map +1 -0
  120. package/utils/resolve.d.ts +3 -0
  121. package/utils/resolve.js +24 -0
  122. package/utils/resolve.js.map +1 -0
  123. package/context/folders.d.ts +0 -2
  124. package/context/folders.js +0 -261
  125. package/context/folders.js.map +0 -1
  126. package/context/index.d.ts +0 -2
  127. package/context/index.js +0 -22
  128. package/context/index.js.map +0 -1
  129. package/context/links.d.ts +0 -2
  130. package/context/links.js +0 -270
  131. package/context/links.js.map +0 -1
  132. package/graphql/base.gql.d.ts +0 -3
  133. package/graphql/base.gql.js +0 -63
  134. package/graphql/base.gql.js.map +0 -1
  135. package/graphql/folders.gql.d.ts +0 -3
  136. package/graphql/folders.gql.js +0 -126
  137. package/graphql/folders.gql.js.map +0 -1
  138. package/graphql/index.d.ts +0 -1
  139. package/graphql/index.js +0 -15
  140. package/graphql/index.js.map +0 -1
  141. package/graphql/links.gql.d.ts +0 -3
  142. package/graphql/links.gql.js +0 -123
  143. package/graphql/links.gql.js.map +0 -1
  144. package/subscriptions/afterFolderDelete.d.ts +0 -3
  145. package/subscriptions/afterFolderDelete.js +0 -62
  146. package/subscriptions/afterFolderDelete.js.map +0 -1
  147. package/subscriptions/index.d.ts +0 -3
  148. package/subscriptions/index.js +0 -14
  149. package/subscriptions/index.js.map +0 -1
package/README.md CHANGED
@@ -16,3 +16,18 @@ Or if you prefer yarn:
16
16
  ```
17
17
  yarn add @webiny/api-aco
18
18
  ```
19
+ ## Testing
20
+
21
+ To run tests api-aco tests with targeted storage operations loaded use:
22
+
23
+ ### DynamoDB
24
+
25
+ ```
26
+ yarn test packages/api-aco/* --keyword=cms:ddb --keyword=aco:base
27
+ ```
28
+
29
+ ### DynamoDB + ElasticSearch
30
+
31
+ ```
32
+ yarn test packages/api-aco/* --keyword=cms:ddb-es --keyword=aco:base
33
+ ```
@@ -0,0 +1,16 @@
1
+ import { AcoContext, AcoSearchRecordCrudBase, IAcoApp, IAcoAppModifyFieldCallableCallback, IAcoAppParams } from "../types";
2
+ import { CmsModel, CmsModelField } from "@webiny/api-headless-cms/types";
3
+ export declare class AcoApp implements IAcoApp {
4
+ readonly name: string;
5
+ readonly context: AcoContext;
6
+ readonly model: CmsModel;
7
+ private readonly fields;
8
+ get search(): AcoSearchRecordCrudBase;
9
+ get folder(): import("../types").AcoFolderCrud;
10
+ private constructor();
11
+ static create(context: AcoContext, params: IAcoAppParams): AcoApp;
12
+ getFields(): CmsModelField[];
13
+ addField(field: CmsModelField): void;
14
+ removeField(id: string): void;
15
+ modifyField(id: string, cb: IAcoAppModifyFieldCallableCallback): void;
16
+ }
package/apps/AcoApp.js ADDED
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.AcoApp = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _error = _interopRequireDefault(require("@webiny/error"));
10
+ var _structuredClone = _interopRequireDefault(require("@ungap/structured-clone"));
11
+ var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
12
+ var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
13
+ var _record = require("../record/record.model");
14
+ const createApiName = name => {
15
+ return (0, _upperFirst.default)((0, _camelCase.default)(name));
16
+ };
17
+ class AcoApp {
18
+ get search() {
19
+ return {
20
+ create: async data => {
21
+ return this.context.aco.search.create(this.model, data);
22
+ },
23
+ update: async (id, data) => {
24
+ /**
25
+ * Required to have as any atm as TS is breaking on the return type.
26
+ */
27
+ return await this.context.aco.search.update(this.model, id, data);
28
+ },
29
+ move: async (id, folderId) => {
30
+ return this.context.aco.search.move(this.model, id, folderId);
31
+ },
32
+ get: async id => {
33
+ return this.context.aco.search.get(this.model, id);
34
+ },
35
+ list: async params => {
36
+ return this.context.aco.search.list(this.model, params);
37
+ },
38
+ delete: async id => {
39
+ return this.context.aco.search.delete(this.model, id);
40
+ },
41
+ listTags: async params => {
42
+ return this.context.aco.search.listTags(this.model, params);
43
+ }
44
+ };
45
+ }
46
+ get folder() {
47
+ return this.context.aco.folder;
48
+ }
49
+ constructor(context, params) {
50
+ var _this$model$fields$in;
51
+ (0, _defineProperty2.default)(this, "name", void 0);
52
+ (0, _defineProperty2.default)(this, "context", void 0);
53
+ (0, _defineProperty2.default)(this, "model", void 0);
54
+ (0, _defineProperty2.default)(this, "fields", void 0);
55
+ this.context = context;
56
+ this.name = params.name;
57
+ this.model = (0, _structuredClone.default)(params.model);
58
+ /**
59
+ * We can safely define the api name of the model as we control everything here.
60
+ */
61
+ this.model.name = `${this.model.name} ${this.name}`;
62
+ this.model.modelId = `${this.model.modelId}-${this.name.toLowerCase()}`;
63
+ const apiName = `AcoSearchRecord${createApiName(params.apiName)}`;
64
+ this.model.singularApiName = apiName;
65
+ this.model.pluralApiName = apiName;
66
+ const index = this.model.fields.findIndex(f => f.fieldId === "data");
67
+ if (index === -1) {
68
+ throw new _error.default(`The "data" field does not exist in model "${this.model.modelId}".`, "MODEL_DATA_FIELD_ERROR", {
69
+ modelId: this.model.modelId
70
+ });
71
+ } else if (!((_this$model$fields$in = this.model.fields[index].settings) !== null && _this$model$fields$in !== void 0 && _this$model$fields$in.fields)) {
72
+ this.model.fields[index].settings.fields = [];
73
+ }
74
+ this.fields = this.model.fields[index].settings.fields;
75
+ this.fields.push(...params.fields);
76
+ }
77
+ static create(context, params) {
78
+ return new AcoApp(context, params);
79
+ }
80
+ getFields() {
81
+ return this.fields;
82
+ }
83
+ addField(field) {
84
+ this.fields.push(field);
85
+ }
86
+ removeField(id) {
87
+ if (_record.DEFAULT_FIELDS.includes(id)) {
88
+ throw new _error.default(`Cannot remove the default field from the ACO App.`, "REMOVE_DEFAULT_FIELD_ERROR", {
89
+ fieldId: id
90
+ });
91
+ }
92
+ const index = this.fields.findIndex(field => field.id === id);
93
+ if (index === -1) {
94
+ return;
95
+ }
96
+ this.fields.splice(index, 1);
97
+ }
98
+ modifyField(id, cb) {
99
+ const index = this.fields.findIndex(field => field.id === id);
100
+ if (index === -1) {
101
+ throw new _error.default(`There is no field "${id}" in app "${this.name}".`, "FIELD_NOT_FOUND_ERROR", {
102
+ id
103
+ });
104
+ }
105
+ this.fields[index] = cb((0, _structuredClone.default)(this.fields[index]));
106
+ }
107
+ }
108
+ exports.AcoApp = AcoApp;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createApiName","name","lodashUpperFirst","lodashCamelCase","AcoApp","search","create","data","context","aco","model","update","id","move","folderId","get","list","params","delete","listTags","folder","constructor","structuredClone","modelId","toLowerCase","apiName","singularApiName","pluralApiName","index","fields","findIndex","f","fieldId","WebinyError","settings","push","getFields","addField","field","removeField","DEFAULT_FIELDS","includes","splice","modifyField","cb"],"sources":["AcoApp.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport structuredClone from \"@ungap/structured-clone\";\nimport {\n AcoContext,\n AcoSearchRecordCrudBase,\n CreateSearchRecordParams,\n IAcoApp,\n IAcoAppModifyFieldCallableCallback,\n IAcoAppParams,\n ListSearchRecordsParams,\n ListSearchRecordTagsParams,\n SearchRecord\n} from \"~/types\";\nimport { CmsModel, CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport lodashUpperFirst from \"lodash/upperFirst\";\nimport lodashCamelCase from \"lodash/camelCase\";\nimport { DEFAULT_FIELDS } from \"~/record/record.model\";\n\nconst createApiName = (name: string) => {\n return lodashUpperFirst(lodashCamelCase(name));\n};\n\nexport class AcoApp implements IAcoApp {\n public readonly name: string;\n public readonly context: AcoContext;\n public readonly model: CmsModel;\n private readonly fields: CmsModelField[];\n\n public get search(): AcoSearchRecordCrudBase {\n return {\n create: async <TData>(data: CreateSearchRecordParams<TData>) => {\n return this.context.aco.search.create<TData>(this.model, data);\n },\n update: async <TData>(id: string, data: SearchRecord<TData>) => {\n /**\n * Required to have as any atm as TS is breaking on the return type.\n */\n return (await this.context.aco.search.update<TData>(this.model, id, data)) as any;\n },\n move: async (id: string, folderId?: string) => {\n return this.context.aco.search.move(this.model, id, folderId);\n },\n get: async <TData>(id: string) => {\n return this.context.aco.search.get<TData>(this.model, id);\n },\n list: async <TData>(params: ListSearchRecordsParams) => {\n return this.context.aco.search.list<TData>(this.model, params);\n },\n delete: async (id: string): Promise<Boolean> => {\n return this.context.aco.search.delete(this.model, id);\n },\n listTags: async (params: ListSearchRecordTagsParams) => {\n return this.context.aco.search.listTags(this.model, params);\n }\n };\n }\n\n public get folder() {\n return this.context.aco.folder;\n }\n\n private constructor(context: AcoContext, params: IAcoAppParams) {\n this.context = context;\n this.name = params.name;\n this.model = structuredClone(params.model);\n /**\n * We can safely define the api name of the model as we control everything here.\n */\n this.model.name = `${this.model.name} ${this.name}`;\n this.model.modelId = `${this.model.modelId}-${this.name.toLowerCase()}`;\n const apiName = `AcoSearchRecord${createApiName(params.apiName)}`;\n this.model.singularApiName = apiName;\n this.model.pluralApiName = apiName;\n\n const index = this.model.fields.findIndex(f => f.fieldId === \"data\");\n if (index === -1) {\n throw new WebinyError(\n `The \"data\" field does not exist in model \"${this.model.modelId}\".`,\n \"MODEL_DATA_FIELD_ERROR\",\n {\n modelId: this.model.modelId\n }\n );\n } else if (!this.model.fields[index].settings?.fields) {\n this.model.fields[index].settings!.fields = [];\n }\n this.fields = this.model.fields[index].settings!.fields as CmsModelField[];\n this.fields.push(...params.fields);\n }\n\n public static create(context: AcoContext, params: IAcoAppParams) {\n return new AcoApp(context, params);\n }\n\n public getFields(): CmsModelField[] {\n return this.fields;\n }\n\n public addField(field: CmsModelField): void {\n this.fields.push(field);\n }\n\n public removeField(id: string): void {\n if (DEFAULT_FIELDS.includes(id)) {\n throw new WebinyError(\n `Cannot remove the default field from the ACO App.`,\n \"REMOVE_DEFAULT_FIELD_ERROR\",\n {\n fieldId: id\n }\n );\n }\n const index = this.fields.findIndex(field => field.id === id);\n if (index === -1) {\n return;\n }\n this.fields.splice(index, 1);\n }\n\n public modifyField(id: string, cb: IAcoAppModifyFieldCallableCallback): void {\n const index = this.fields.findIndex(field => field.id === id);\n if (index === -1) {\n throw new WebinyError(\n `There is no field \"${id}\" in app \"${this.name}\".`,\n \"FIELD_NOT_FOUND_ERROR\",\n {\n id\n }\n );\n }\n this.fields[index] = cb(structuredClone(this.fields[index]));\n }\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AAaA;AACA;AACA;AAEA,MAAMA,aAAa,GAAIC,IAAY,IAAK;EACpC,OAAO,IAAAC,mBAAgB,EAAC,IAAAC,kBAAe,EAACF,IAAI,CAAC,CAAC;AA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;IAC7D,IAAIgB,KAAK,KAAK,CAAC,CAAC,EAAE;MACd,MAAM,IAAIK,cAAW,CAChB,sBAAqBrB,EAAG,aAAY,IAAI,CAACX,IAAK,IAAG,EAClD,uBAAuB,EACvB;QACIW;MACJ,CAAC,CACJ;IACL;IACA,IAAI,CAACiB,MAAM,CAACD,KAAK,CAAC,GAAGgB,EAAE,CAAC,IAAAtB,wBAAe,EAAC,IAAI,CAACO,MAAM,CAACD,KAAK,CAAC,CAAC,CAAC;EAChE;AACJ;AAAC"}
@@ -0,0 +1,10 @@
1
+ import { AcoContext, IAcoApp, IAcoAppParams, IAcoApps, IAcoAppsOptions } from "../types";
2
+ export declare class AcoApps implements IAcoApps {
3
+ private readonly apps;
4
+ private readonly context;
5
+ private readonly options;
6
+ constructor(context: AcoContext, options: IAcoAppsOptions);
7
+ get(name: string): IAcoApp;
8
+ list(): IAcoApp[];
9
+ register(options: IAcoAppParams): Promise<IAcoApp>;
10
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.AcoApps = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+ var _AcoApp = require("./AcoApp");
12
+ var _plugins = require("../plugins");
13
+ var _apiHeadlessCms = require("@webiny/api-headless-cms");
14
+ var _record = require("../record/record.gql");
15
+ class AcoApps {
16
+ constructor(context, options) {
17
+ (0, _defineProperty2.default)(this, "apps", new Map());
18
+ (0, _defineProperty2.default)(this, "context", void 0);
19
+ (0, _defineProperty2.default)(this, "options", void 0);
20
+ this.context = context;
21
+ this.options = options;
22
+ }
23
+ get(name) {
24
+ const app = this.apps.get(name);
25
+ if (app) {
26
+ return app;
27
+ }
28
+ throw new _error.default(`App "${name}" is not registered.`, "APP_NOT_REGISTERED", {
29
+ name,
30
+ apps: Array.from(this.apps.keys())
31
+ });
32
+ }
33
+ list() {
34
+ return Array.from(this.apps.values());
35
+ }
36
+ async register(options) {
37
+ const exists = this.apps.has(options.name);
38
+ if (exists) {
39
+ throw new _error.default(`An app with the name "${options.name}" is already registered.`, "APP_EXISTS", {
40
+ name: options.name
41
+ });
42
+ }
43
+ /**
44
+ * We need to create the app and run the modifiers on it.
45
+ */
46
+ const app = _AcoApp.AcoApp.create(this.context, options);
47
+ const modifiers = this.context.plugins.byType(_plugins.AcoAppModifierPlugin.type);
48
+ for (const modifier of modifiers) {
49
+ if (modifier.canUse(app) === false) {
50
+ continue;
51
+ }
52
+ await modifier.modify({
53
+ context: this.context,
54
+ app
55
+ });
56
+ }
57
+ /**
58
+ * Also, we need to register the app model as the plugin one, so it can be used in the CMS.
59
+ * We do not need to validate model or show it in the API.
60
+ */
61
+ this.context.plugins.register(new _apiHeadlessCms.CmsModelPlugin((0, _objectSpread2.default)((0, _objectSpread2.default)({}, app.model), {}, {
62
+ singularApiName: undefined,
63
+ pluralApiName: undefined,
64
+ isPrivate: true,
65
+ noValidate: true
66
+ })));
67
+ this.apps.set(app.name, app);
68
+ const searchRecordSchema = await (0, _record.createSchema)({
69
+ context: this.context,
70
+ app
71
+ });
72
+ this.context.plugins.register(searchRecordSchema);
73
+ return app;
74
+ }
75
+ }
76
+ exports.AcoApps = AcoApps;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AcoApps","constructor","context","options","Map","get","name","app","apps","WebinyError","Array","from","keys","list","values","register","exists","has","AcoApp","create","modifiers","plugins","byType","AcoAppModifierPlugin","type","modifier","canUse","modify","CmsModelPlugin","model","singularApiName","undefined","pluralApiName","isPrivate","noValidate","set","searchRecordSchema","createSchema"],"sources":["AcoApps.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { AcoApp } from \"./AcoApp\";\nimport { AcoAppModifierPlugin } from \"~/plugins\";\nimport { AcoContext, IAcoApp, IAcoAppParams, IAcoApps, IAcoAppsOptions } from \"~/types\";\nimport { CmsModelPlugin } from \"@webiny/api-headless-cms\";\nimport { createSchema } from \"~/record/record.gql\";\n\nexport class AcoApps implements IAcoApps {\n private readonly apps: Map<string, IAcoApp> = new Map();\n private readonly context: AcoContext;\n private readonly options: IAcoAppsOptions;\n\n public constructor(context: AcoContext, options: IAcoAppsOptions) {\n this.context = context;\n this.options = options;\n }\n\n public get(name: string): IAcoApp {\n const app = this.apps.get(name);\n if (app) {\n return app;\n }\n throw new WebinyError(`App \"${name}\" is not registered.`, \"APP_NOT_REGISTERED\", {\n name,\n apps: Array.from(this.apps.keys())\n });\n }\n\n public list(): IAcoApp[] {\n return Array.from(this.apps.values());\n }\n\n public async register(options: IAcoAppParams): Promise<IAcoApp> {\n const exists = this.apps.has(options.name);\n if (exists) {\n throw new WebinyError(\n `An app with the name \"${options.name}\" is already registered.`,\n \"APP_EXISTS\",\n {\n name: options.name\n }\n );\n }\n /**\n * We need to create the app and run the modifiers on it.\n */\n const app = AcoApp.create(this.context, options);\n const modifiers = this.context.plugins.byType<AcoAppModifierPlugin>(\n AcoAppModifierPlugin.type\n );\n for (const modifier of modifiers) {\n if (modifier.canUse(app) === false) {\n continue;\n }\n await modifier.modify({\n context: this.context,\n app\n });\n }\n /**\n * Also, we need to register the app model as the plugin one, so it can be used in the CMS.\n * We do not need to validate model or show it in the API.\n */\n this.context.plugins.register(\n new CmsModelPlugin({\n ...app.model,\n singularApiName: undefined,\n pluralApiName: undefined,\n isPrivate: true,\n noValidate: true\n })\n );\n this.apps.set(app.name, app);\n\n const searchRecordSchema = await createSchema({\n context: this.context,\n app\n });\n this.context.plugins.register(searchRecordSchema);\n\n return app;\n }\n}\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AAEA;AACA;AAEO,MAAMA,OAAO,CAAqB;EAK9BC,WAAW,CAACC,OAAmB,EAAEC,OAAwB,EAAE;IAAA,4CA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CAAC;QAClBzB,OAAO,EAAE,IAAI,CAACA,OAAO;QACrBK;MACJ,CAAC,CAAC;IACN;IACA;AACR;AACA;AACA;IACQ,IAAI,CAACL,OAAO,CAACmB,OAAO,CAACN,QAAQ,CACzB,IAAIa,8BAAc,6DACXrB,GAAG,CAACsB,KAAK;MACZC,eAAe,EAAEC,SAAS;MAC1BC,aAAa,EAAED,SAAS;MACxBE,SAAS,EAAE,IAAI;MACfC,UAAU,EAAE;IAAI,GAClB,CACL;IACD,IAAI,CAAC1B,IAAI,CAAC2B,GAAG,CAAC5B,GAAG,CAACD,IAAI,EAAEC,GAAG,CAAC;IAE5B,MAAM6B,kBAAkB,GAAG,MAAM,IAAAC,oBAAY,EAAC;MAC1CnC,OAAO,EAAE,IAAI,CAACA,OAAO;MACrBK;IACJ,CAAC,CAAC;IACF,IAAI,CAACL,OAAO,CAACmB,OAAO,CAACN,QAAQ,CAACqB,kBAAkB,CAAC;IAEjD,OAAO7B,GAAG;EACd;AACJ;AAAC"}
@@ -0,0 +1,3 @@
1
+ import { GraphQLSchemaPlugin } from "@webiny/handler-graphql";
2
+ import { AcoContext } from "../types";
3
+ export declare const appGql: GraphQLSchemaPlugin<AcoContext>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.appGql = void 0;
8
+ var _handlerGraphql = require("@webiny/handler-graphql");
9
+ var _omit = _interopRequireDefault(require("lodash/omit"));
10
+ var _checkPermissions = require("../utils/checkPermissions");
11
+ var _resolve = require("../utils/resolve");
12
+ const cleanModel = model => {
13
+ return (0, _omit.default)(model, ["webinyVersion", "tags", "locale", "tenant", "layout", "group", "description", "isPrivate"]);
14
+ };
15
+ const appGql = new _handlerGraphql.GraphQLSchemaPlugin({
16
+ typeDefs: /* GraphQL */`
17
+ type AcoApp {
18
+ id: ID!
19
+ name: String!
20
+ model: JSON!
21
+ }
22
+ type GetAppResponse {
23
+ data: AcoApp
24
+ error: AcoError
25
+ }
26
+ type GetAppModelResponse {
27
+ data: JSON
28
+ error: AcoError
29
+ }
30
+ extend type AcoQuery {
31
+ getApp(id: ID!): GetAppResponse!
32
+ getAppModel(id: ID!): GetAppModelResponse!
33
+ }
34
+ `,
35
+ resolvers: {
36
+ AcoQuery: {
37
+ getApp: async (_, args, context) => {
38
+ return (0, _resolve.resolve)(async () => {
39
+ (0, _checkPermissions.checkPermissions)(context);
40
+ const app = context.aco.getApp(args.id);
41
+ return {
42
+ id: args.id,
43
+ name: app.name,
44
+ model: cleanModel(app.model)
45
+ };
46
+ });
47
+ },
48
+ getAppModel: async (_, args, context) => {
49
+ return (0, _resolve.resolve)(async () => {
50
+ (0, _checkPermissions.checkPermissions)(context);
51
+ const app = context.aco.getApp(args.id);
52
+ return cleanModel(app.model);
53
+ });
54
+ }
55
+ }
56
+ }
57
+ });
58
+ exports.appGql = appGql;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["cleanModel","model","lodashOmit","appGql","GraphQLSchemaPlugin","typeDefs","resolvers","AcoQuery","getApp","_","args","context","resolve","checkPermissions","app","aco","id","name","getAppModel"],"sources":["app.gql.ts"],"sourcesContent":["import { GraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\nimport { AcoContext } from \"~/types\";\nimport { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport lodashOmit from \"lodash/omit\";\nimport { checkPermissions } from \"~/utils/checkPermissions\";\nimport { resolve } from \"~/utils/resolve\";\n\nconst cleanModel = (model: CmsModel): Partial<CmsModel> => {\n return lodashOmit(model, [\n \"webinyVersion\",\n \"tags\",\n \"locale\",\n \"tenant\",\n \"layout\",\n \"group\",\n \"description\",\n \"isPrivate\"\n ]);\n};\n\nexport const appGql = new GraphQLSchemaPlugin<AcoContext>({\n typeDefs: /* GraphQL */ `\n type AcoApp {\n id: ID!\n name: String!\n model: JSON!\n }\n type GetAppResponse {\n data: AcoApp\n error: AcoError\n }\n type GetAppModelResponse {\n data: JSON\n error: AcoError\n }\n extend type AcoQuery {\n getApp(id: ID!): GetAppResponse!\n getAppModel(id: ID!): GetAppModelResponse!\n }\n `,\n resolvers: {\n AcoQuery: {\n getApp: async (_, args, context) => {\n return resolve(async () => {\n checkPermissions(context);\n const app = context.aco.getApp(args.id);\n return {\n id: args.id,\n name: app.name,\n model: cleanModel(app.model)\n };\n });\n },\n getAppModel: async (_, args, context) => {\n return resolve(async () => {\n checkPermissions(context);\n const app = context.aco.getApp(args.id);\n return cleanModel(app.model);\n });\n }\n }\n }\n});\n"],"mappings":";;;;;;;AAAA;AAGA;AACA;AACA;AAEA,MAAMA,UAAU,GAAIC,KAAe,IAAwB;EACvD,OAAO,IAAAC,aAAU,EAACD,KAAK,EAAE,CACrB,eAAe,EACf,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,aAAa,EACb,WAAW,CACd,CAAC;AACN,CAAC;AAEM,MAAME,MAAM,GAAG,IAAIC,mCAAmB,CAAa;EACtDC,QAAQ,EAAE,aAAe;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;EACDC,SAAS,EAAE;IACPC,QAAQ,EAAE;MACNC,MAAM,EAAE,OAAOC,CAAC,EAAEC,IAAI,EAAEC,OAAO,KAAK;QAChC,OAAO,IAAAC,gBAAO,EAAC,YAAY;UACvB,IAAAC,kCAAgB,EAACF,OAAO,CAAC;UACzB,MAAMG,GAAG,GAAGH,OAAO,CAACI,GAAG,CAACP,MAAM,CAACE,IAAI,CAACM,EAAE,CAAC;UACvC,OAAO;YACHA,EAAE,EAAEN,IAAI,CAACM,EAAE;YACXC,IAAI,EAAEH,GAAG,CAACG,IAAI;YACdhB,KAAK,EAAED,UAAU,CAACc,GAAG,CAACb,KAAK;UAC/B,CAAC;QACL,CAAC,CAAC;MACN,CAAC;MACDiB,WAAW,EAAE,OAAOT,CAAC,EAAEC,IAAI,EAAEC,OAAO,KAAK;QACrC,OAAO,IAAAC,gBAAO,EAAC,YAAY;UACvB,IAAAC,kCAAgB,EAACF,OAAO,CAAC;UACzB,MAAMG,GAAG,GAAGH,OAAO,CAACI,GAAG,CAACP,MAAM,CAACE,IAAI,CAACM,EAAE,CAAC;UACvC,OAAOhB,UAAU,CAACc,GAAG,CAACb,KAAK,CAAC;QAChC,CAAC,CAAC;MACN;IACJ;EACJ;AACJ,CAAC,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./AcoApp";
2
+ export * from "./AcoApps";
package/apps/index.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _AcoApp = require("./AcoApp");
7
+ Object.keys(_AcoApp).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _AcoApp[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _AcoApp[key];
14
+ }
15
+ });
16
+ });
17
+ var _AcoApps = require("./AcoApps");
18
+ Object.keys(_AcoApps).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _AcoApps[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _AcoApps[key];
25
+ }
26
+ });
27
+ });
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./AcoApp\";\nexport * from \"./AcoApps\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -0,0 +1,3 @@
1
+ import { ContextPlugin } from "@webiny/api";
2
+ import { AcoContext } from "./types";
3
+ export declare const createAcoContext: () => ContextPlugin<AcoContext>;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createAcoContext = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _error = _interopRequireDefault(require("@webiny/error"));
10
+ var _api = require("@webiny/api");
11
+ var _createAcoHooks = require("./createAcoHooks");
12
+ var _createAcoStorageOperations = require("./createAcoStorageOperations");
13
+ var _isInstallationPending = require("./utils/isInstallationPending");
14
+ var _folder = require("./folder/folder.crud");
15
+ var _record = require("./record/record.crud");
16
+ var _apps = require("./apps");
17
+ var _record2 = require("./record/record.model");
18
+ var _plugins = require("./plugins");
19
+ const setupAcoContext = async context => {
20
+ const {
21
+ tenancy,
22
+ security,
23
+ i18n
24
+ } = context;
25
+ const getLocale = () => {
26
+ const locale = i18n.getContentLocale();
27
+ if (!locale) {
28
+ throw new _error.default("Missing content locale in api-aco/plugins/context.ts", "LOCALE_ERROR");
29
+ }
30
+ return locale;
31
+ };
32
+ const getTenant = () => {
33
+ return tenancy.getCurrentTenant();
34
+ };
35
+ const getIdentity = () => security.getIdentity();
36
+ const params = {
37
+ getLocale,
38
+ getIdentity,
39
+ getTenant,
40
+ storageOperations: (0, _createAcoStorageOperations.createAcoStorageOperations)({
41
+ /**
42
+ * TODO: We need to figure out a way to pass "cms" from outside (e.g. apps/api/graphql)
43
+ */
44
+ cms: context.cms,
45
+ /**
46
+ * TODO: This is required for "entryFieldFromStorageTransform" which access plugins from context.
47
+ */
48
+ getCmsContext: () => context,
49
+ security
50
+ })
51
+ };
52
+ const defaultRecordModel = await context.security.withoutAuthorization(async () => {
53
+ return context.cms.getModel(_record2.SEARCH_RECORD_MODEL_ID);
54
+ });
55
+ if (!defaultRecordModel) {
56
+ throw new _error.default(`There is no default record model in ${_record2.SEARCH_RECORD_MODEL_ID}`);
57
+ }
58
+
59
+ /**
60
+ * First we need to create all the apps.
61
+ */
62
+ const apps = new _apps.AcoApps(context, params);
63
+ const plugins = context.plugins.byType(_plugins.AcoAppRegisterPlugin.type);
64
+ for (const plugin of plugins) {
65
+ await apps.register((0, _objectSpread2.default)({
66
+ model: defaultRecordModel
67
+ }, plugin.app));
68
+ }
69
+ context.aco = {
70
+ folder: (0, _folder.createFolderCrudMethods)(params),
71
+ search: (0, _record.createSearchRecordCrudMethods)(params),
72
+ apps,
73
+ getApp: name => apps.get(name),
74
+ listApps: () => apps.list(),
75
+ registerApp: async params => {
76
+ return apps.register((0, _objectSpread2.default)({
77
+ model: defaultRecordModel
78
+ }, params));
79
+ }
80
+ };
81
+ };
82
+ const createAcoContext = () => {
83
+ const plugin = new _api.ContextPlugin(async context => {
84
+ /**
85
+ * We can skip the ACO initialization if the installation is pending.
86
+ */
87
+ if ((0, _isInstallationPending.isInstallationPending)(context)) {
88
+ return;
89
+ }
90
+ await context.benchmark.measure("aco.context.setup", async () => {
91
+ await setupAcoContext(context);
92
+ });
93
+ await context.benchmark.measure("aco.context.hooks", async () => {
94
+ await (0, _createAcoHooks.createAcoHooks)(context);
95
+ });
96
+ });
97
+ plugin.name = "aco.createContext";
98
+ return plugin;
99
+ };
100
+ exports.createAcoContext = createAcoContext;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["setupAcoContext","context","tenancy","security","i18n","getLocale","locale","getContentLocale","WebinyError","getTenant","getCurrentTenant","getIdentity","params","storageOperations","createAcoStorageOperations","cms","getCmsContext","defaultRecordModel","withoutAuthorization","getModel","SEARCH_RECORD_MODEL_ID","apps","AcoApps","plugins","byType","AcoAppRegisterPlugin","type","plugin","register","model","app","aco","folder","createFolderCrudMethods","search","createSearchRecordCrudMethods","getApp","name","get","listApps","list","registerApp","createAcoContext","ContextPlugin","isInstallationPending","benchmark","measure","createAcoHooks"],"sources":["createAcoContext.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { createAcoHooks } from \"~/createAcoHooks\";\nimport { createAcoStorageOperations } from \"~/createAcoStorageOperations\";\nimport { isInstallationPending } from \"~/utils/isInstallationPending\";\nimport { AcoContext, CreateAcoParams, IAcoAppRegisterParams } from \"~/types\";\nimport { createFolderCrudMethods } from \"~/folder/folder.crud\";\nimport { createSearchRecordCrudMethods } from \"~/record/record.crud\";\nimport { AcoApps } from \"./apps\";\nimport { SEARCH_RECORD_MODEL_ID } from \"~/record/record.model\";\nimport { AcoAppRegisterPlugin } from \"~/plugins\";\n\nconst setupAcoContext = async (context: AcoContext): Promise<void> => {\n const { tenancy, security, i18n } = context;\n\n const getLocale = (): I18NLocale => {\n const locale = i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale in api-aco/plugins/context.ts\",\n \"LOCALE_ERROR\"\n );\n }\n\n return locale;\n };\n\n const getTenant = (): Tenant => {\n return tenancy.getCurrentTenant();\n };\n\n const getIdentity = () => security.getIdentity();\n\n const params: CreateAcoParams = {\n getLocale,\n getIdentity,\n getTenant,\n storageOperations: createAcoStorageOperations({\n /**\n * TODO: We need to figure out a way to pass \"cms\" from outside (e.g. apps/api/graphql)\n */\n cms: context.cms,\n /**\n * TODO: This is required for \"entryFieldFromStorageTransform\" which access plugins from context.\n */\n getCmsContext: () => context,\n security\n })\n };\n\n const defaultRecordModel = await context.security.withoutAuthorization(async () => {\n return context.cms.getModel(SEARCH_RECORD_MODEL_ID);\n });\n if (!defaultRecordModel) {\n throw new WebinyError(`There is no default record model in ${SEARCH_RECORD_MODEL_ID}`);\n }\n\n /**\n * First we need to create all the apps.\n */\n const apps = new AcoApps(context, params);\n const plugins = context.plugins.byType<AcoAppRegisterPlugin>(AcoAppRegisterPlugin.type);\n for (const plugin of plugins) {\n await apps.register({\n model: defaultRecordModel,\n ...plugin.app\n });\n }\n\n context.aco = {\n folder: createFolderCrudMethods(params),\n search: createSearchRecordCrudMethods(params),\n apps,\n getApp: (name: string) => apps.get(name),\n listApps: () => apps.list(),\n registerApp: async (params: IAcoAppRegisterParams) => {\n return apps.register({\n model: defaultRecordModel,\n ...params\n });\n }\n };\n};\n\nexport const createAcoContext = () => {\n const plugin = new ContextPlugin<AcoContext>(async context => {\n /**\n * We can skip the ACO initialization if the installation is pending.\n */\n if (isInstallationPending(context)) {\n return;\n }\n await context.benchmark.measure(\"aco.context.setup\", async () => {\n await setupAcoContext(context);\n });\n\n await context.benchmark.measure(\"aco.context.hooks\", async () => {\n await createAcoHooks(context);\n });\n });\n\n plugin.name = \"aco.createContext\";\n\n return plugin;\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AAGA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA,MAAMA,eAAe,GAAG,MAAOC,OAAmB,IAAoB;EAClE,MAAM;IAAEC,OAAO;IAAEC,QAAQ;IAAEC;EAAK,CAAC,GAAGH,OAAO;EAE3C,MAAMI,SAAS,GAAG,MAAkB;IAChC,MAAMC,MAAM,GAAGF,IAAI,CAACG,gBAAgB,EAAE;IACtC,IAAI,CAACD,MAAM,EAAE;MACT,MAAM,IAAIE,cAAW,CACjB,sDAAsD,EACtD,cAAc,CACjB;IACL;IAEA,OAAOF,MAAM;EACjB,CAAC;EAED,MAAMG,SAAS,GAAG,MAAc;IAC5B,OAAOP,OAAO,CAACQ,gBAAgB,EAAE;EACrC,CAAC;EAED,MAAMC,WAAW,GAAG,MAAMR,QAAQ,CAACQ,WAAW,EAAE;EAEhD,MAAMC,MAAuB,GAAG;IAC5BP,SAAS;IACTM,WAAW;IACXF,SAAS;IACTI,iBAAiB,EAAE,IAAAC,sDAA0B,EAAC;MAC1C;AACZ;AACA;MACYC,GAAG,EAAEd,OAAO,CAACc,GAAG;MAChB;AACZ;AACA;MACYC,aAAa,EAAE,MAAMf,OAAO;MAC5BE;IACJ,CAAC;EACL,CAAC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4C,SAAS,CAACC,OAAO,CAAC,mBAAmB,EAAE,YAAY;MAC7D,MAAM9C,eAAe,CAACC,OAAO,CAAC;IAClC,CAAC,CAAC;IAEF,MAAMA,OAAO,CAAC4C,SAAS,CAACC,OAAO,CAAC,mBAAmB,EAAE,YAAY;MAC7D,MAAM,IAAAC,8BAAc,EAAC9C,OAAO,CAAC;IACjC,CAAC,CAAC;EACN,CAAC,CAAC;EAEF0B,MAAM,CAACU,IAAI,GAAG,mBAAmB;EAEjC,OAAOV,MAAM;AACjB,CAAC;AAAC"}
@@ -0,0 +1,3 @@
1
+ import { GraphQLSchemaPlugin } from "@webiny/handler-graphql";
2
+ import { AcoContext } from "./types";
3
+ export declare const createAcoGraphQL: () => GraphQLSchemaPlugin<AcoContext>[];
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createAcoGraphQL = void 0;
7
+ var _handlerGraphql = require("@webiny/handler-graphql");
8
+ var _folder = require("./folder/folder.gql");
9
+ var _app = require("./apps/app.gql");
10
+ const emptyResolver = () => ({});
11
+ const baseSchema = new _handlerGraphql.GraphQLSchemaPlugin({
12
+ typeDefs: /* GraphQL */`
13
+ type AcoQuery {
14
+ _empty: String
15
+ }
16
+
17
+ type AcoMutation {
18
+ _empty: String
19
+ }
20
+
21
+ type SearchQuery {
22
+ _empty: String
23
+ }
24
+
25
+ type SearchMutation {
26
+ _empty: String
27
+ }
28
+
29
+ type AcoMeta {
30
+ hasMoreItems: Boolean
31
+ totalCount: Int
32
+ cursor: String
33
+ }
34
+
35
+ type AcoUser {
36
+ id: ID
37
+ displayName: String
38
+ type: String
39
+ }
40
+
41
+ type AcoError {
42
+ code: String
43
+ message: String
44
+ data: JSON
45
+ stack: String
46
+ }
47
+
48
+ type AcoBooleanResponse {
49
+ data: Boolean
50
+ error: AcoError
51
+ }
52
+
53
+ enum AcoSortDirection {
54
+ ASC
55
+ DESC
56
+ }
57
+
58
+ input AcoSort {
59
+ id: AcoSortDirection
60
+ createdOn: AcoSortDirection
61
+ savedOn: AcoSortDirection
62
+ title: AcoSortDirection
63
+ }
64
+
65
+ input AcoSearchRecordTagListWhereInput {
66
+ tags_in: [String!]
67
+ tags_startsWith: String
68
+ tags_not_startsWith: String
69
+ createdBy: ID
70
+ AND: [AcoSearchRecordTagListWhereInput!]
71
+ OR: [AcoSearchRecordTagListWhereInput!]
72
+ }
73
+
74
+ type AcoSearchRecordMoveResponse {
75
+ data: Boolean
76
+ error: AcoError
77
+ }
78
+
79
+ type TagItem {
80
+ tag: String!
81
+ count: Int!
82
+ }
83
+
84
+ type AcoSearchRecordTagListResponse {
85
+ data: [TagItem!]
86
+ error: AcoError
87
+ meta: AcoMeta
88
+ }
89
+
90
+ type AcoSearchLocationType {
91
+ folderId: ID!
92
+ }
93
+ input AcoSearchLocationInput {
94
+ folderId: ID!
95
+ }
96
+
97
+ extend type Query {
98
+ aco: AcoQuery
99
+ search: SearchQuery
100
+ }
101
+
102
+ extend type Mutation {
103
+ aco: AcoMutation
104
+ search: SearchMutation
105
+ }
106
+ `,
107
+ resolvers: {
108
+ Query: {
109
+ aco: emptyResolver,
110
+ search: emptyResolver
111
+ },
112
+ Mutation: {
113
+ aco: emptyResolver,
114
+ search: emptyResolver
115
+ }
116
+ }
117
+ });
118
+ const createAcoGraphQL = () => {
119
+ return [baseSchema, _app.appGql, _folder.folderSchema];
120
+ };
121
+ exports.createAcoGraphQL = createAcoGraphQL;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["emptyResolver","baseSchema","GraphQLSchemaPlugin","typeDefs","resolvers","Query","aco","search","Mutation","createAcoGraphQL","appGql","folderSchema"],"sources":["createAcoGraphQL.ts"],"sourcesContent":["import { GraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\nimport { folderSchema } from \"~/folder/folder.gql\";\nimport { appGql } from \"~/apps/app.gql\";\nimport { AcoContext } from \"~/types\";\n\nconst emptyResolver = () => ({});\n\nconst baseSchema = new GraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n type AcoQuery {\n _empty: String\n }\n\n type AcoMutation {\n _empty: String\n }\n\n type SearchQuery {\n _empty: String\n }\n\n type SearchMutation {\n _empty: String\n }\n\n type AcoMeta {\n hasMoreItems: Boolean\n totalCount: Int\n cursor: String\n }\n\n type AcoUser {\n id: ID\n displayName: String\n type: String\n }\n\n type AcoError {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type AcoBooleanResponse {\n data: Boolean\n error: AcoError\n }\n\n enum AcoSortDirection {\n ASC\n DESC\n }\n\n input AcoSort {\n id: AcoSortDirection\n createdOn: AcoSortDirection\n savedOn: AcoSortDirection\n title: AcoSortDirection\n }\n\n input AcoSearchRecordTagListWhereInput {\n tags_in: [String!]\n tags_startsWith: String\n tags_not_startsWith: String\n createdBy: ID\n AND: [AcoSearchRecordTagListWhereInput!]\n OR: [AcoSearchRecordTagListWhereInput!]\n }\n\n type AcoSearchRecordMoveResponse {\n data: Boolean\n error: AcoError\n }\n\n type TagItem {\n tag: String!\n count: Int!\n }\n\n type AcoSearchRecordTagListResponse {\n data: [TagItem!]\n error: AcoError\n meta: AcoMeta\n }\n\n type AcoSearchLocationType {\n folderId: ID!\n }\n input AcoSearchLocationInput {\n folderId: ID!\n }\n\n extend type Query {\n aco: AcoQuery\n search: SearchQuery\n }\n\n extend type Mutation {\n aco: AcoMutation\n search: SearchMutation\n }\n `,\n resolvers: {\n Query: {\n aco: emptyResolver,\n search: emptyResolver\n },\n Mutation: {\n aco: emptyResolver,\n search: emptyResolver\n }\n }\n});\n\nexport const createAcoGraphQL = (): GraphQLSchemaPlugin<AcoContext>[] => {\n return [baseSchema, appGql, folderSchema];\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AAGA,MAAMA,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;AAEhC,MAAMC,UAAU,GAAG,IAAIC,mCAAmB,CAAC;EACvCC,QAAQ,EAAE,aAAe;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;EACDC,SAAS,EAAE;IACPC,KAAK,EAAE;MACHC,GAAG,EAAEN,aAAa;MAClBO,MAAM,EAAEP;IACZ,CAAC;IACDQ,QAAQ,EAAE;MACNF,GAAG,EAAEN,aAAa;MAClBO,MAAM,EAAEP;IACZ;EACJ;AACJ,CAAC,CAAC;AAEK,MAAMS,gBAAgB,GAAG,MAAyC;EACrE,OAAO,CAACR,UAAU,EAAES,WAAM,EAAEC,oBAAY,CAAC;AAC7C,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { AcoContext } from "./types";
2
+ export declare const createAcoHooks: (context: AcoContext) => void;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createAcoHooks = void 0;
7
+ var _onFolderBeforeDelete = require("./folder/onFolderBeforeDelete.hook");
8
+ const createAcoHooks = context => {
9
+ (0, _onFolderBeforeDelete.onFolderBeforeDeleteHook)(context);
10
+ };
11
+ exports.createAcoHooks = createAcoHooks;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createAcoHooks","context","onFolderBeforeDeleteHook"],"sources":["createAcoHooks.ts"],"sourcesContent":["import { onFolderBeforeDeleteHook } from \"~/folder/onFolderBeforeDelete.hook\";\n\nimport { AcoContext } from \"~/types\";\n\nexport const createAcoHooks = (context: AcoContext) => {\n onFolderBeforeDeleteHook(context);\n};\n"],"mappings":";;;;;;AAAA;AAIO,MAAMA,cAAc,GAAIC,OAAmB,IAAK;EACnD,IAAAC,8CAAwB,EAACD,OAAO,CAAC;AACrC,CAAC;AAAC"}