@webiny/api-file-manager 5.36.2 → 5.37.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FileManagerContextSetup.d.ts +13 -0
- package/FileManagerContextSetup.js +113 -0
- package/FileManagerContextSetup.js.map +1 -0
- package/cmsFileStorage/CmsFilesStorage.d.ts +27 -0
- package/cmsFileStorage/CmsFilesStorage.js +173 -0
- package/cmsFileStorage/CmsFilesStorage.js.map +1 -0
- package/cmsFileStorage/ListFilesWhereProcessor.d.ts +7 -0
- package/cmsFileStorage/ListFilesWhereProcessor.js +35 -0
- package/cmsFileStorage/ListFilesWhereProcessor.js.map +1 -0
- package/cmsFileStorage/ListTagsWhereProcessor.d.ts +7 -0
- package/cmsFileStorage/ListTagsWhereProcessor.js +35 -0
- package/cmsFileStorage/ListTagsWhereProcessor.js.map +1 -0
- package/cmsFileStorage/createFileManagerPlugins.d.ts +5 -0
- package/cmsFileStorage/createFileManagerPlugins.js +34 -0
- package/cmsFileStorage/createFileManagerPlugins.js.map +1 -0
- package/cmsFileStorage/createModelField.d.ts +5 -0
- package/cmsFileStorage/createModelField.js +37 -0
- package/cmsFileStorage/createModelField.js.map +1 -0
- package/cmsFileStorage/file.model.d.ts +4 -0
- package/cmsFileStorage/file.model.js +124 -0
- package/cmsFileStorage/file.model.js.map +1 -0
- package/cmsFileStorage/isInstallationPending.d.ts +4 -0
- package/cmsFileStorage/isInstallationPending.js +21 -0
- package/cmsFileStorage/isInstallationPending.js.map +1 -0
- package/contants.d.ts +1 -0
- package/contants.js +8 -0
- package/contants.js.map +1 -0
- package/createFileManager/files.crud.js +39 -61
- package/createFileManager/files.crud.js.map +1 -1
- package/createFileManager/index.d.ts +4 -2
- package/createFileManager/index.js.map +1 -1
- package/createFileManager/permissions/FilesPermissions.d.ts +4 -0
- package/createFileManager/permissions/FilesPermissions.js +9 -0
- package/createFileManager/permissions/FilesPermissions.js.map +1 -0
- package/createFileManager/settings.crud.js.map +1 -1
- package/createFileManager/system.crud.js.map +1 -1
- package/graphql/baseSchema.d.ts +3 -0
- package/graphql/baseSchema.js +117 -0
- package/graphql/baseSchema.js.map +1 -0
- package/graphql/createFilesTypeDefs.d.ts +7 -0
- package/graphql/createFilesTypeDefs.js +162 -0
- package/graphql/createFilesTypeDefs.js.map +1 -0
- package/graphql/filesSchema.d.ts +4 -0
- package/graphql/filesSchema.js +83 -0
- package/graphql/filesSchema.js.map +1 -0
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +23 -278
- package/graphql/index.js.map +1 -1
- package/graphql/utils.d.ts +11 -0
- package/graphql/utils.js +22 -0
- package/graphql/utils.js.map +1 -0
- package/handlers/download/byAlias.js +9 -9
- package/handlers/download/byAlias.js.map +1 -1
- package/handlers/download/byExactKey.js +9 -9
- package/handlers/download/byExactKey.js.map +1 -1
- package/handlers/download/extractFileInformation.js.map +1 -1
- package/handlers/download/getS3Object.d.ts +2 -0
- package/handlers/download/getS3Object.js +39 -24
- package/handlers/download/getS3Object.js.map +1 -1
- package/handlers/download/index.js.map +1 -1
- package/handlers/manage/index.js.map +1 -1
- package/handlers/transform/index.js +5 -2
- package/handlers/transform/index.js.map +1 -1
- package/handlers/transform/legacyUtils.js.map +1 -1
- package/handlers/transform/loaders/imageLoader.js.map +1 -1
- package/handlers/transform/loaders/index.js.map +1 -1
- package/handlers/transform/loaders/sanitizeImageTransformations.js.map +1 -1
- package/handlers/transform/managers/imageManager.js.map +1 -1
- package/handlers/transform/managers/index.js.map +1 -1
- package/handlers/transform/optimizeImage.js.map +1 -1
- package/handlers/transform/transformImage.d.ts +5 -2
- package/handlers/transform/transformImage.js +7 -4
- package/handlers/transform/transformImage.js.map +1 -1
- package/handlers/transform/utils.js +2 -2
- package/handlers/transform/utils.js.map +1 -1
- package/handlers/utils/getEnvironment.js.map +1 -1
- package/handlers/utils/getObjectParams.js.map +1 -1
- package/handlers/utils/index.js.map +1 -1
- package/index.d.ts +3 -2
- package/index.js +20 -36
- package/index.js.map +1 -1
- package/modelModifier/CmsModelModifier.d.ts +24 -0
- package/modelModifier/CmsModelModifier.js +59 -0
- package/modelModifier/CmsModelModifier.js.map +1 -0
- package/package.json +26 -25
- package/plugins/FilePhysicalStoragePlugin.js.map +1 -1
- package/plugins/FileStorageTransformPlugin.js.map +1 -1
- package/plugins/index.js.map +1 -1
- package/storage/FileStorage.d.ts +2 -1
- package/storage/FileStorage.js +5 -4
- package/storage/FileStorage.js.map +1 -1
- package/types/file.d.ts +5 -1
- package/types/file.js.map +1 -1
- package/types.d.ts +16 -26
- package/types.js.map +1 -1
- package/createFileManager/checkBasePermissions.d.ts +0 -5
- package/createFileManager/checkBasePermissions.js +0 -24
- package/createFileManager/checkBasePermissions.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createSystemCrud","storageOperations","getTenantId","getIdentity","WEBINY_VERSION","onSystemBeforeInstall","createTopic","onSystemAfterInstall","getVersion","system","get","tenant","version","setVersion","data","update","original","ex","WebinyError","create","install","srcPrefix","identity","NotAuthorizedError","publish","createSettings"],"sources":["system.crud.ts"],"sourcesContent":["import { createTopic } from \"@webiny/pubsub\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport {\n FileManagerContextObject,\n FileManagerSettings,\n FileManagerSystem,\n SystemCRUD\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { FileManagerConfig } from \"~/createFileManager/index\";\n\nexport const createSystemCrud = ({\n storageOperations,\n getTenantId,\n getIdentity,\n WEBINY_VERSION\n}: FileManagerConfig): SystemCRUD => {\n return {\n onSystemBeforeInstall: createTopic(\"fileManager.onSystemBeforeInstall\"),\n onSystemAfterInstall: createTopic(\"fileManager.onSystemAfterInstall\"),\n async getVersion() {\n const system = await storageOperations.system.get({ tenant: getTenantId() });\n\n return system ? system.version : null;\n },\n async setVersion(version: string) {\n const system = await storageOperations.system.get({ tenant: getTenantId() });\n\n if (system) {\n const data: FileManagerSystem = {\n ...system,\n tenant: system.tenant || getTenantId(),\n version\n };\n try {\n await storageOperations.system.update({\n original: system,\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\n \"Could not update the system data.\",\n \"SYSTEM_UPDATE_ERROR\",\n {\n data\n }\n );\n }\n }\n\n const data: FileManagerSystem = {\n version,\n tenant: getTenantId()\n };\n try {\n await storageOperations.system.create({\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\"Could not create the system data.\", \"SYSTEM_CREATE_ERROR\", {\n data\n });\n }\n },\n async install(this: FileManagerContextObject, { srcPrefix }) {\n const identity = getIdentity();\n\n if (!identity) {\n throw new NotAuthorizedError();\n }\n\n const version = await this.getVersion();\n\n if (version) {\n throw new WebinyError(\n \"File Manager is already installed.\",\n \"FILES_INSTALL_ABORTED\"\n );\n }\n\n const data: Partial<FileManagerSettings> = {};\n\n if (srcPrefix) {\n data.srcPrefix = srcPrefix;\n }\n\n await this.onSystemBeforeInstall.publish({});\n\n await this.createSettings(data);\n await this.setVersion(WEBINY_VERSION);\n\n await this.onSystemAfterInstall.publish({});\n\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AAOA;AAGO,
|
|
1
|
+
{"version":3,"names":["_pubsub","require","_apiSecurity","_error","_interopRequireDefault","createSystemCrud","storageOperations","getTenantId","getIdentity","WEBINY_VERSION","onSystemBeforeInstall","createTopic","onSystemAfterInstall","getVersion","system","get","tenant","version","setVersion","data","_objectSpread2","default","update","original","ex","WebinyError","create","install","srcPrefix","identity","NotAuthorizedError","publish","createSettings","exports"],"sources":["system.crud.ts"],"sourcesContent":["import { createTopic } from \"@webiny/pubsub\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport {\n FileManagerContextObject,\n FileManagerSettings,\n FileManagerSystem,\n SystemCRUD\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { FileManagerConfig } from \"~/createFileManager/index\";\n\nexport const createSystemCrud = ({\n storageOperations,\n getTenantId,\n getIdentity,\n WEBINY_VERSION\n}: FileManagerConfig): SystemCRUD => {\n return {\n onSystemBeforeInstall: createTopic(\"fileManager.onSystemBeforeInstall\"),\n onSystemAfterInstall: createTopic(\"fileManager.onSystemAfterInstall\"),\n async getVersion() {\n const system = await storageOperations.system.get({ tenant: getTenantId() });\n\n return system ? system.version : null;\n },\n async setVersion(version: string) {\n const system = await storageOperations.system.get({ tenant: getTenantId() });\n\n if (system) {\n const data: FileManagerSystem = {\n ...system,\n tenant: system.tenant || getTenantId(),\n version\n };\n try {\n await storageOperations.system.update({\n original: system,\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\n \"Could not update the system data.\",\n \"SYSTEM_UPDATE_ERROR\",\n {\n data\n }\n );\n }\n }\n\n const data: FileManagerSystem = {\n version,\n tenant: getTenantId()\n };\n try {\n await storageOperations.system.create({\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\"Could not create the system data.\", \"SYSTEM_CREATE_ERROR\", {\n data\n });\n }\n },\n async install(this: FileManagerContextObject, { srcPrefix }) {\n const identity = getIdentity();\n\n if (!identity) {\n throw new NotAuthorizedError();\n }\n\n const version = await this.getVersion();\n\n if (version) {\n throw new WebinyError(\n \"File Manager is already installed.\",\n \"FILES_INSTALL_ABORTED\"\n );\n }\n\n const data: Partial<FileManagerSettings> = {};\n\n if (srcPrefix) {\n data.srcPrefix = srcPrefix;\n }\n\n await this.onSystemBeforeInstall.publish({});\n\n await this.createSettings(data);\n await this.setVersion(WEBINY_VERSION);\n\n await this.onSystemAfterInstall.publish({});\n\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAOA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAGO,MAAMI,gBAAgB,GAAGA,CAAC;EAC7BC,iBAAiB;EACjBC,WAAW;EACXC,WAAW;EACXC;AACe,CAAC,KAAiB;EACjC,OAAO;IACHC,qBAAqB,EAAE,IAAAC,mBAAW,EA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OA,CAAiC;MAAEC;IAAU,CAAC,EAAE;MACzD,MAAMC,QAAQ,GAAGrB,WAAW,CAAC,CAAC;MAE9B,IAAI,CAACqB,QAAQ,EAAE;QACX,MAAM,IAAIC,+BAAkB,CAAC,CAAC;MAClC;MAEA,MAAMb,OAAO,GAAG,MAAM,IAAI,CAACJ,UAAU,CAAC,CAAC;MAEvC,IAAII,OAAO,EAAE;QACT,MAAM,IAAIQ,cAAW,CACjB,oCAAoC,EACpC,uBACJ,CAAC;MACL;MAEA,MAAMN,IAAkC,GAAG,CAAC,CAAC;MAE7C,IAAIS,SAAS,EAAE;QACXT,IAAI,CAACS,SAAS,GAAGA,SAAS;MAC9B;MAEA,MAAM,IAAI,CAAClB,qBAAqB,CAACqB,OAAO,CAAC,CAAC,CAAC,CAAC;MAE5C,MAAM,IAAI,CAACC,cAAc,CAACb,IAAI,CAAC;MAC/B,MAAM,IAAI,CAACD,UAAU,CAACT,cAAc,CAAC;MAErC,MAAM,IAAI,CAACG,oBAAoB,CAACmB,OAAO,CAAC,CAAC,CAAC,CAAC;MAE3C,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAACE,OAAA,CAAA5B,gBAAA,GAAAA,gBAAA"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createBaseSchema = void 0;
|
|
7
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
8
|
+
var _utils = require("./utils");
|
|
9
|
+
const createBaseSchema = () => {
|
|
10
|
+
const fileManagerGraphQL = new _handlerGraphql.GraphQLSchemaPlugin({
|
|
11
|
+
typeDefs: /* GraphQL */`
|
|
12
|
+
type FmError {
|
|
13
|
+
code: String
|
|
14
|
+
message: String
|
|
15
|
+
data: JSON
|
|
16
|
+
stack: String
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type FmCreatedBy {
|
|
20
|
+
id: ID
|
|
21
|
+
displayName: String
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type FmListMeta {
|
|
25
|
+
cursor: String
|
|
26
|
+
totalCount: Int
|
|
27
|
+
hasMoreItems: Boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type FmBooleanResponse {
|
|
31
|
+
data: Boolean
|
|
32
|
+
error: FmError
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type FmSettings {
|
|
36
|
+
uploadMinFileSize: Number
|
|
37
|
+
uploadMaxFileSize: Number
|
|
38
|
+
srcPrefix: String
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
input FmSettingsInput {
|
|
42
|
+
uploadMinFileSize: Number
|
|
43
|
+
uploadMaxFileSize: Number
|
|
44
|
+
srcPrefix: String
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type FmSettingsResponse {
|
|
48
|
+
data: FmSettings
|
|
49
|
+
error: FmError
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type FmQuery {
|
|
53
|
+
version: String
|
|
54
|
+
getSettings: FmSettingsResponse
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type FmDeleteResponse {
|
|
58
|
+
data: Boolean
|
|
59
|
+
error: FmError
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type FmMutation {
|
|
63
|
+
install(srcPrefix: String): FmBooleanResponse
|
|
64
|
+
updateSettings(data: FmSettingsInput): FmSettingsResponse
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
input FmInstallInput {
|
|
68
|
+
srcPrefix: String!
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
extend type Query {
|
|
72
|
+
fileManager: FmQuery
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
extend type Mutation {
|
|
76
|
+
fileManager: FmMutation
|
|
77
|
+
}
|
|
78
|
+
`,
|
|
79
|
+
resolvers: {
|
|
80
|
+
Query: {
|
|
81
|
+
fileManager: _utils.emptyResolver
|
|
82
|
+
},
|
|
83
|
+
Mutation: {
|
|
84
|
+
fileManager: _utils.emptyResolver
|
|
85
|
+
},
|
|
86
|
+
FmQuery: {
|
|
87
|
+
async version(_, __, context) {
|
|
88
|
+
const {
|
|
89
|
+
i18n,
|
|
90
|
+
tenancy,
|
|
91
|
+
fileManager
|
|
92
|
+
} = context;
|
|
93
|
+
if (!tenancy.getCurrentTenant() || !i18n.getContentLocale()) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return await fileManager.getVersion();
|
|
97
|
+
},
|
|
98
|
+
async getSettings(_, __, context) {
|
|
99
|
+
return (0, _utils.resolve)(() => context.fileManager.getSettings());
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
FmMutation: {
|
|
103
|
+
async install(_, args, context) {
|
|
104
|
+
return (0, _utils.resolve)(() => context.fileManager.install({
|
|
105
|
+
srcPrefix: args.srcPrefix
|
|
106
|
+
}));
|
|
107
|
+
},
|
|
108
|
+
async updateSettings(_, args, context) {
|
|
109
|
+
return (0, _utils.resolve)(() => context.fileManager.updateSettings(args.data));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
fileManagerGraphQL.name = "fm.graphql.base";
|
|
115
|
+
return fileManagerGraphQL;
|
|
116
|
+
};
|
|
117
|
+
exports.createBaseSchema = createBaseSchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_handlerGraphql","require","_utils","createBaseSchema","fileManagerGraphQL","GraphQLSchemaPlugin","typeDefs","resolvers","Query","fileManager","emptyResolver","Mutation","FmQuery","version","_","__","context","i18n","tenancy","getCurrentTenant","getContentLocale","getVersion","getSettings","resolve","FmMutation","install","args","srcPrefix","updateSettings","data","name","exports"],"sources":["baseSchema.ts"],"sourcesContent":["import { GraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\nimport { FileManagerContext } from \"~/types\";\nimport { emptyResolver, resolve } from \"./utils\";\n\nexport const createBaseSchema = () => {\n const fileManagerGraphQL = new GraphQLSchemaPlugin<FileManagerContext>({\n typeDefs: /* GraphQL */ `\n type FmError {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type FmCreatedBy {\n id: ID\n displayName: String\n }\n\n type FmListMeta {\n cursor: String\n totalCount: Int\n hasMoreItems: Boolean\n }\n\n type FmBooleanResponse {\n data: Boolean\n error: FmError\n }\n\n type FmSettings {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n input FmSettingsInput {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n type FmSettingsResponse {\n data: FmSettings\n error: FmError\n }\n\n type FmQuery {\n version: String\n getSettings: FmSettingsResponse\n }\n\n type FmDeleteResponse {\n data: Boolean\n error: FmError\n }\n\n type FmMutation {\n install(srcPrefix: String): FmBooleanResponse\n updateSettings(data: FmSettingsInput): FmSettingsResponse\n }\n\n input FmInstallInput {\n srcPrefix: String!\n }\n\n extend type Query {\n fileManager: FmQuery\n }\n\n extend type Mutation {\n fileManager: FmMutation\n }\n `,\n resolvers: {\n Query: {\n fileManager: emptyResolver\n },\n Mutation: {\n fileManager: emptyResolver\n },\n FmQuery: {\n async version(_, __, context) {\n const { i18n, tenancy, fileManager } = context;\n if (!tenancy.getCurrentTenant() || !i18n.getContentLocale()) {\n return null;\n }\n\n return await fileManager.getVersion();\n },\n async getSettings(_, __, context) {\n return resolve(() => context.fileManager.getSettings());\n }\n },\n FmMutation: {\n async install(_, args: any, context) {\n return resolve(() =>\n context.fileManager.install({ srcPrefix: args.srcPrefix })\n );\n },\n async updateSettings(_, args: any, context) {\n return resolve(() => context.fileManager.updateSettings(args.data));\n }\n }\n }\n });\n fileManagerGraphQL.name = \"fm.graphql.base\";\n\n return fileManagerGraphQL;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAEO,MAAME,gBAAg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IAAI,CAACC;UAAU,CAAC,CAC7D,CAAC;QACL,CAAC;QACD,MAAMC,cAAcA,CAACd,CAAC,EAAEY,IAAS,EAAEV,OAAO,EAAE;UACxC,OAAO,IAAAO,cAAO,EAAC,MAAMP,OAAO,CAACP,WAAW,CAACmB,cAAc,CAACF,IAAI,CAACG,IAAI,CAAC,CAAC;QACvE;MACJ;IACJ;EACJ,CAAC,CAAC;EACFzB,kBAAkB,CAAC0B,IAAI,GAAG,iBAAiB;EAE3C,OAAO1B,kBAAkB;AAC7B,CAAC;AAAC2B,OAAA,CAAA5B,gBAAA,GAAAA,gBAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CmsFieldTypePlugins, CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
|
+
export interface CreateFilesTypeDefsParams {
|
|
3
|
+
model: CmsModel;
|
|
4
|
+
models: CmsModel[];
|
|
5
|
+
plugins: CmsFieldTypePlugins;
|
|
6
|
+
}
|
|
7
|
+
export declare const createFilesTypeDefs: (params: CreateFilesTypeDefsParams) => string;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createFilesTypeDefs = void 0;
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
+
var _renderFields = require("@webiny/api-headless-cms/utils/renderFields");
|
|
10
|
+
var _renderInputFields = require("@webiny/api-headless-cms/utils/renderInputFields");
|
|
11
|
+
var _renderListFilterFields = require("@webiny/api-headless-cms/utils/renderListFilterFields");
|
|
12
|
+
var _renderSortEnum = require("@webiny/api-headless-cms/utils/renderSortEnum");
|
|
13
|
+
const removeFieldRequiredValidation = field => {
|
|
14
|
+
if (field.validation) {
|
|
15
|
+
field.validation = field.validation.filter(validation => validation.name !== "required");
|
|
16
|
+
}
|
|
17
|
+
if (field.listValidation) {
|
|
18
|
+
field.listValidation = field.listValidation.filter(v => v.name !== "required");
|
|
19
|
+
}
|
|
20
|
+
return field;
|
|
21
|
+
};
|
|
22
|
+
const createUpdateFields = fields => {
|
|
23
|
+
return fields.reduce((collection, field) => {
|
|
24
|
+
collection.push(removeFieldRequiredValidation((0, _objectSpread2.default)({}, field)));
|
|
25
|
+
return collection;
|
|
26
|
+
}, []);
|
|
27
|
+
};
|
|
28
|
+
const createFilesTypeDefs = params => {
|
|
29
|
+
const {
|
|
30
|
+
model,
|
|
31
|
+
models,
|
|
32
|
+
plugins: fieldTypePlugins
|
|
33
|
+
} = params;
|
|
34
|
+
const {
|
|
35
|
+
fields
|
|
36
|
+
} = model;
|
|
37
|
+
const fieldTypes = (0, _renderFields.renderFields)({
|
|
38
|
+
models,
|
|
39
|
+
model,
|
|
40
|
+
fields,
|
|
41
|
+
type: "manage",
|
|
42
|
+
fieldTypePlugins
|
|
43
|
+
});
|
|
44
|
+
const inputCreateFields = (0, _renderInputFields.renderInputFields)({
|
|
45
|
+
models,
|
|
46
|
+
model,
|
|
47
|
+
fields,
|
|
48
|
+
fieldTypePlugins
|
|
49
|
+
});
|
|
50
|
+
const inputUpdateFields = (0, _renderInputFields.renderInputFields)({
|
|
51
|
+
models,
|
|
52
|
+
model,
|
|
53
|
+
fields: createUpdateFields(fields),
|
|
54
|
+
fieldTypePlugins
|
|
55
|
+
});
|
|
56
|
+
const listFilterFieldsRender = (0, _renderListFilterFields.renderListFilterFields)({
|
|
57
|
+
model,
|
|
58
|
+
fields: model.fields,
|
|
59
|
+
type: "manage",
|
|
60
|
+
fieldTypePlugins,
|
|
61
|
+
excludeFields: ["entryId", "status"]
|
|
62
|
+
});
|
|
63
|
+
const excludeFromSorterts = ["tags", "aliases"];
|
|
64
|
+
const sortEnumRender = (0, _renderSortEnum.renderSortEnum)({
|
|
65
|
+
model,
|
|
66
|
+
fields: model.fields.filter(field => !excludeFromSorterts.includes(field.fieldId)),
|
|
67
|
+
fieldTypePlugins,
|
|
68
|
+
sorterPlugins: []
|
|
69
|
+
});
|
|
70
|
+
return (/* GraphQL */`
|
|
71
|
+
${fieldTypes.map(f => f.typeDefs).join("\n")}
|
|
72
|
+
|
|
73
|
+
type FmFile {
|
|
74
|
+
id: ID!
|
|
75
|
+
savedOn: DateTime!
|
|
76
|
+
createdOn: DateTime!
|
|
77
|
+
createdBy: FmCreatedBy!
|
|
78
|
+
src: String
|
|
79
|
+
${fieldTypes.map(f => f.fields).join("\n")}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
${inputCreateFields.map(f => f.typeDefs).join("\n")}
|
|
83
|
+
|
|
84
|
+
input FmFileCreateInput {
|
|
85
|
+
id: ID!
|
|
86
|
+
${inputCreateFields.map(f => f.fields).join("\n")}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
input FmFileUpdateInput {
|
|
90
|
+
${inputUpdateFields.map(f => f.fields).join("\n")}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
type FmFileResponse {
|
|
94
|
+
data: FmFile
|
|
95
|
+
error: FmError
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
input FmFileListWhereInput {
|
|
99
|
+
${listFilterFieldsRender}
|
|
100
|
+
AND: [FmFileListWhereInput!]
|
|
101
|
+
OR: [FmFileListWhereInput!]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
type FmFileListResponse {
|
|
105
|
+
data: [FmFile!]
|
|
106
|
+
error: FmError
|
|
107
|
+
meta: FmListMeta
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
enum FmFileListSorter {
|
|
111
|
+
${sortEnumRender}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
input FmTagsListWhereInput {
|
|
115
|
+
createdBy: String
|
|
116
|
+
tags_startsWith: String
|
|
117
|
+
tags_not_startsWith: String
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
type FmTag {
|
|
121
|
+
tag: String!
|
|
122
|
+
count: Number!
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
type FmTagsListResponse {
|
|
126
|
+
data: [FmTag!]
|
|
127
|
+
error: FmError
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
type FmCreateFilesResponse {
|
|
131
|
+
data: [FmFile!]
|
|
132
|
+
error: FmError
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
type FmFileModelResponse {
|
|
136
|
+
data: JSON
|
|
137
|
+
error: FmError
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
extend type FmQuery {
|
|
141
|
+
getFileModel: FmFileModelResponse!
|
|
142
|
+
getFile(id: ID!): FmFileResponse!
|
|
143
|
+
listFiles(
|
|
144
|
+
search: String
|
|
145
|
+
where: FmFileListWhereInput
|
|
146
|
+
limit: Int
|
|
147
|
+
after: String
|
|
148
|
+
sort: [FmFileListSorter!]
|
|
149
|
+
): FmFileListResponse!
|
|
150
|
+
listTags(where: FmTagsListWhereInput): FmTagsListResponse!
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
extend type FmMutation {
|
|
154
|
+
createFile(data: FmFileCreateInput!): FmFileResponse!
|
|
155
|
+
createFiles(data: [FmFileCreateInput!]!): FmCreateFilesResponse!
|
|
156
|
+
updateFile(id: ID!, data: FmFileUpdateInput!): FmFileResponse!
|
|
157
|
+
deleteFile(id: ID!): FmBooleanResponse!
|
|
158
|
+
}
|
|
159
|
+
`
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
exports.createFilesTypeDefs = createFilesTypeDefs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_renderFields","require","_renderInputFields","_renderListFilterFields","_renderSortEnum","removeFieldRequiredValidation","field","validation","filter","name","listValidation","v","createUpdateFields","fields","reduce","collection","push","_objectSpread2","default","createFilesTypeDefs","params","model","models","plugins","fieldTypePlugins","fieldTypes","renderFields","type","inputCreateFields","renderInputFields","inputUpdateFields","listFilterFieldsRender","renderListFilterFields","excludeFields","excludeFromSorterts","sortEnumRender","renderSortEnum","includes","fieldId","sorterPlugins","map","f","typeDefs","join","exports"],"sources":["createFilesTypeDefs.ts"],"sourcesContent":["import { CmsFieldTypePlugins, CmsModel, CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport { renderFields } from \"@webiny/api-headless-cms/utils/renderFields\";\nimport { renderInputFields } from \"@webiny/api-headless-cms/utils/renderInputFields\";\nimport { renderListFilterFields } from \"@webiny/api-headless-cms/utils/renderListFilterFields\";\nimport { renderSortEnum } from \"@webiny/api-headless-cms/utils/renderSortEnum\";\n\nexport interface CreateFilesTypeDefsParams {\n model: CmsModel;\n models: CmsModel[];\n plugins: CmsFieldTypePlugins;\n}\n\nconst removeFieldRequiredValidation = (field: CmsModelField) => {\n if (field.validation) {\n field.validation = field.validation.filter(validation => validation.name !== \"required\");\n }\n if (field.listValidation) {\n field.listValidation = field.listValidation.filter(v => v.name !== \"required\");\n }\n return field;\n};\n\nconst createUpdateFields = (fields: CmsModelField[]): CmsModelField[] => {\n return fields.reduce<CmsModelField[]>((collection, field) => {\n collection.push(removeFieldRequiredValidation({ ...field }));\n return collection;\n }, []);\n};\n\nexport const createFilesTypeDefs = (params: CreateFilesTypeDefsParams): string => {\n const { model, models, plugins: fieldTypePlugins } = params;\n const { fields } = model;\n\n const fieldTypes = renderFields({\n models,\n model,\n fields,\n type: \"manage\",\n fieldTypePlugins\n });\n const inputCreateFields = renderInputFields({\n models,\n model,\n fields,\n fieldTypePlugins\n });\n const inputUpdateFields = renderInputFields({\n models,\n model,\n fields: createUpdateFields(fields),\n fieldTypePlugins\n });\n const listFilterFieldsRender = renderListFilterFields({\n model,\n fields: model.fields,\n type: \"manage\",\n fieldTypePlugins,\n excludeFields: [\"entryId\", \"status\"]\n });\n\n const excludeFromSorterts = [\"tags\", \"aliases\"];\n\n const sortEnumRender = renderSortEnum({\n model,\n fields: model.fields.filter(field => !excludeFromSorterts.includes(field.fieldId)),\n fieldTypePlugins,\n sorterPlugins: []\n });\n\n return /* GraphQL */ `\n ${fieldTypes.map(f => f.typeDefs).join(\"\\n\")}\n\n type FmFile {\n id: ID!\n savedOn: DateTime!\n createdOn: DateTime!\n createdBy: FmCreatedBy!\n src: String\n ${fieldTypes.map(f => f.fields).join(\"\\n\")}\n }\n\n ${inputCreateFields.map(f => f.typeDefs).join(\"\\n\")}\n\n input FmFileCreateInput {\n id: ID!\n ${inputCreateFields.map(f => f.fields).join(\"\\n\")}\n }\n\n input FmFileUpdateInput {\n ${inputUpdateFields.map(f => f.fields).join(\"\\n\")}\n }\n\n type FmFileResponse {\n data: FmFile\n error: FmError\n }\n\n input FmFileListWhereInput {\n ${listFilterFieldsRender}\n AND: [FmFileListWhereInput!]\n OR: [FmFileListWhereInput!]\n }\n\n type FmFileListResponse {\n data: [FmFile!]\n error: FmError\n meta: FmListMeta\n }\n\n enum FmFileListSorter {\n ${sortEnumRender}\n }\n\n input FmTagsListWhereInput {\n createdBy: String\n tags_startsWith: String\n tags_not_startsWith: String\n }\n\n type FmTag {\n tag: String!\n count: Number!\n }\n\n type FmTagsListResponse {\n data: [FmTag!]\n error: FmError\n }\n\n type FmCreateFilesResponse {\n data: [FmFile!]\n error: FmError\n }\n \n type FmFileModelResponse {\n data: JSON\n error: FmError\n }\n\n extend type FmQuery {\n getFileModel: FmFileModelResponse!\n getFile(id: ID!): FmFileResponse!\n listFiles(\n search: String\n where: FmFileListWhereInput\n limit: Int\n after: String\n sort: [FmFileListSorter!]\n ): FmFileListResponse!\n listTags(where: FmTagsListWhereInput): FmTagsListResponse!\n }\n\n extend type FmMutation {\n createFile(data: FmFileCreateInput!): FmFileResponse!\n createFiles(data: [FmFileCreateInput!]!): FmCreateFilesResponse!\n updateFile(id: ID!, data: FmFileUpdateInput!): FmFileResponse!\n deleteFile(id: ID!): FmBooleanResponse!\n }\n `;\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC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AAE;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAcZ,sBAAuB;AACrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAcI,cAAe;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;EAAK;AACL,CAAC;AAACS,OAAA,CAAAzB,mBAAA,GAAAA,mBAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { GraphQLSchemaPlugin } from "@webiny/handler-graphql";
|
|
2
|
+
import { FileManagerContext } from "../types";
|
|
3
|
+
import { CreateFilesTypeDefsParams } from "./createFilesTypeDefs";
|
|
4
|
+
export declare const createFilesSchema: (params: CreateFilesTypeDefsParams) => GraphQLSchemaPlugin<FileManagerContext>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createFilesSchema = void 0;
|
|
7
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
8
|
+
var _utils = require("./utils");
|
|
9
|
+
var _createFilesTypeDefs = require("./createFilesTypeDefs");
|
|
10
|
+
var _apiSecurity = require("@webiny/api-security");
|
|
11
|
+
const createFilesSchema = params => {
|
|
12
|
+
const fileManagerGraphQL = new _handlerGraphql.GraphQLSchemaPlugin({
|
|
13
|
+
typeDefs: (0, _createFilesTypeDefs.createFilesTypeDefs)(params),
|
|
14
|
+
resolvers: {
|
|
15
|
+
Query: {
|
|
16
|
+
fileManager: _utils.emptyResolver
|
|
17
|
+
},
|
|
18
|
+
Mutation: {
|
|
19
|
+
fileManager: _utils.emptyResolver
|
|
20
|
+
},
|
|
21
|
+
FmFile: {
|
|
22
|
+
async src(file, _, context) {
|
|
23
|
+
const settings = await context.fileManager.getSettings();
|
|
24
|
+
return ((settings === null || settings === void 0 ? void 0 : settings.srcPrefix) || "") + file.key;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
FmQuery: {
|
|
28
|
+
getFileModel(_, __, context) {
|
|
29
|
+
const identity = context.security.getIdentity();
|
|
30
|
+
if (!identity) {
|
|
31
|
+
return new _apiSecurity.NotAuthorizedResponse();
|
|
32
|
+
}
|
|
33
|
+
return (0, _utils.resolve)(() => context.security.withoutAuthorization(() => {
|
|
34
|
+
return context.cms.getModel("fmFile");
|
|
35
|
+
}));
|
|
36
|
+
},
|
|
37
|
+
getFile(_, args, context) {
|
|
38
|
+
return (0, _utils.resolve)(() => context.fileManager.getFile(args.id));
|
|
39
|
+
},
|
|
40
|
+
async listFiles(_, args, context) {
|
|
41
|
+
try {
|
|
42
|
+
const [data, meta] = await context.fileManager.listFiles(args);
|
|
43
|
+
return new _handlerGraphql.ListResponse(data, meta);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
return new _handlerGraphql.ErrorResponse(e);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
async listTags(_, args, context) {
|
|
49
|
+
try {
|
|
50
|
+
const tags = await context.fileManager.listTags(args || {});
|
|
51
|
+
return new _handlerGraphql.Response(tags);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return new _handlerGraphql.ErrorResponse(error);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
FmMutation: {
|
|
58
|
+
async createFile(_, args, context) {
|
|
59
|
+
return (0, _utils.resolve)(() => context.fileManager.createFile(args.data, args.meta));
|
|
60
|
+
},
|
|
61
|
+
async createFiles(_, args, context) {
|
|
62
|
+
return (0, _utils.resolve)(() => context.fileManager.createFilesInBatch(args.data, args.meta));
|
|
63
|
+
},
|
|
64
|
+
async updateFile(_, args, context) {
|
|
65
|
+
return (0, _utils.resolve)(() => context.fileManager.updateFile(args.id, args.data));
|
|
66
|
+
},
|
|
67
|
+
async deleteFile(_, args, context) {
|
|
68
|
+
return (0, _utils.resolve)(async () => {
|
|
69
|
+
// TODO: Ideally, this should work via a lifecycle hook; first we delete a record from DB, then from cloud storage.
|
|
70
|
+
const file = await context.fileManager.getFile(args.id);
|
|
71
|
+
return await context.fileManager.storage.delete({
|
|
72
|
+
id: file.id,
|
|
73
|
+
key: file.key
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
fileManagerGraphQL.name = "fm.graphql.files";
|
|
81
|
+
return fileManagerGraphQL;
|
|
82
|
+
};
|
|
83
|
+
exports.createFilesSchema = createFilesSchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_handlerGraphql","require","_utils","_createFilesTypeDefs","_apiSecurity","createFilesSchema","params","fileManagerGraphQL","GraphQLSchemaPlugin","typeDefs","createFilesTypeDefs","resolvers","Query","fileManager","emptyResolver","Mutation","FmFile","src","file","_","context","settings","getSettings","srcPrefix","key","FmQuery","getFileModel","__","identity","security","getIdentity","NotAuthorizedResponse","resolve","withoutAuthorization","cms","getModel","getFile","args","id","listFiles","data","meta","ListResponse","e","ErrorResponse","listTags","tags","Response","error","FmMutation","createFile","createFiles","createFilesInBatch","updateFile","deleteFile","storage","delete","name","exports"],"sources":["filesSchema.ts"],"sourcesContent":["import {\n ErrorResponse,\n GraphQLSchemaPlugin,\n ListResponse,\n Response\n} from \"@webiny/handler-graphql\";\nimport { FileManagerContext, FilesListOpts } from \"~/types\";\nimport { emptyResolver, resolve } from \"./utils\";\nimport { createFilesTypeDefs, CreateFilesTypeDefsParams } from \"~/graphql/createFilesTypeDefs\";\nimport { NotAuthorizedResponse } from \"@webiny/api-security\";\n\nexport const createFilesSchema = (params: CreateFilesTypeDefsParams) => {\n const fileManagerGraphQL = new GraphQLSchemaPlugin<FileManagerContext>({\n typeDefs: createFilesTypeDefs(params),\n resolvers: {\n Query: {\n fileManager: emptyResolver\n },\n Mutation: {\n fileManager: emptyResolver\n },\n FmFile: {\n async src(file, _, context: FileManagerContext) {\n const settings = await context.fileManager.getSettings();\n return (settings?.srcPrefix || \"\") + file.key;\n }\n },\n FmQuery: {\n getFileModel(_, __, context) {\n const identity = context.security.getIdentity();\n if (!identity) {\n return new NotAuthorizedResponse();\n }\n\n return resolve(() =>\n context.security.withoutAuthorization(() => {\n return context.cms.getModel(\"fmFile\");\n })\n );\n },\n getFile(_, args: any, context) {\n return resolve(() => context.fileManager.getFile(args.id));\n },\n async listFiles(_, args: FilesListOpts, context) {\n try {\n const [data, meta] = await context.fileManager.listFiles(args);\n\n return new ListResponse(data, meta);\n } catch (e) {\n return new ErrorResponse(e);\n }\n },\n async listTags(_, args: any, context) {\n try {\n const tags = await context.fileManager.listTags(args || {});\n\n return new Response(tags);\n } catch (error) {\n return new ErrorResponse(error);\n }\n }\n },\n FmMutation: {\n async createFile(_, args: any, context) {\n return resolve(() => context.fileManager.createFile(args.data, args.meta));\n },\n async createFiles(_, args: any, context) {\n return resolve(() =>\n context.fileManager.createFilesInBatch(args.data, args.meta)\n );\n },\n async updateFile(_, args: any, context) {\n return resolve(() => context.fileManager.updateFile(args.id, args.data));\n },\n async deleteFile(_, args: any, context) {\n return resolve(async () => {\n // TODO: Ideally, this should work via a lifecycle hook; first we delete a record from DB, then from cloud storage.\n const file = await context.fileManager.getFile(args.id);\n return await context.fileManager.storage.delete({\n id: file.id,\n key: file.key\n });\n });\n }\n }\n }\n });\n fileManagerGraphQL.name = \"fm.graphql.files\";\n\n return fileManagerGraphQL;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAOA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,oBAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAEO,M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CAAC;QAC5E,CAAC;QACD,MAAMc,UAAUA,CAACnC,CAAC,EAAEkB,IAAS,EAAEjB,OAAO,EAAE;UACpC,OAAO,IAAAY,cAAO,EAAC,YAAY;YACvB;YACA,MAAMd,IAAI,GAAG,MAAME,OAAO,CAACP,WAAW,CAACuB,OAAO,CAACC,IAAI,CAACC,EAAE,CAAC;YACvD,OAAO,MAAMlB,OAAO,CAACP,WAAW,CAAC0C,OAAO,CAACC,MAAM,CAAC;cAC5ClB,EAAE,EAAEpB,IAAI,CAACoB,EAAE;cACXd,GAAG,EAAEN,IAAI,CAACM;YACd,CAAC,CAAC;UACN,CAAC,CAAC;QACN;MACJ;IACJ;EACJ,CAAC,CAAC;EACFjB,kBAAkB,CAACkD,IAAI,GAAG,kBAAkB;EAE5C,OAAOlD,kBAAkB;AAC7B,CAAC;AAACmD,OAAA,CAAArD,iBAAA,GAAAA,iBAAA"}
|
package/graphql/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ContextPlugin } from "@webiny/api";
|
|
2
2
|
import { FileManagerContext } from "../types";
|
|
3
|
-
export declare const createGraphQLSchemaPlugin: () => GraphQLSchemaPlugin<FileManagerContext
|
|
3
|
+
export declare const createGraphQLSchemaPlugin: () => (import("@webiny/handler-graphql").GraphQLSchemaPlugin<FileManagerContext> | ContextPlugin<FileManagerContext>)[];
|