@webiny/api-headless-cms-ddb 5.15.0-beta.0
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/LICENSE +21 -0
- package/README.md +25 -0
- package/configurations.d.ts +18 -0
- package/configurations.js +24 -0
- package/configurations.js.map +1 -0
- package/definitions/entry.d.ts +6 -0
- package/definitions/entry.js +86 -0
- package/definitions/entry.js.map +1 -0
- package/definitions/table.d.ts +14 -0
- package/definitions/table.js +30 -0
- package/definitions/table.js.map +1 -0
- package/dynamoDb/index.d.ts +2 -0
- package/dynamoDb/index.js +23 -0
- package/dynamoDb/index.js.map +1 -0
- package/dynamoDb/path/plainObject.d.ts +3 -0
- package/dynamoDb/path/plainObject.js +34 -0
- package/dynamoDb/path/plainObject.js.map +1 -0
- package/dynamoDb/path/ref.d.ts +3 -0
- package/dynamoDb/path/ref.js +28 -0
- package/dynamoDb/path/ref.js.map +1 -0
- package/dynamoDb/storage/date.d.ts +3 -0
- package/dynamoDb/storage/date.js +69 -0
- package/dynamoDb/storage/date.js.map +1 -0
- package/dynamoDb/storage/richText.d.ts +8 -0
- package/dynamoDb/storage/richText.js +108 -0
- package/dynamoDb/storage/richText.js.map +1 -0
- package/dynamoDb/transformValue/datetime.d.ts +3 -0
- package/dynamoDb/transformValue/datetime.js +48 -0
- package/dynamoDb/transformValue/datetime.js.map +1 -0
- package/index.d.ts +6 -0
- package/index.js +30 -0
- package/index.js.map +1 -0
- package/operations/entry/CmsContentEntryDynamo.d.ts +86 -0
- package/operations/entry/CmsContentEntryDynamo.js +972 -0
- package/operations/entry/CmsContentEntryDynamo.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +23 -0
- package/operations/entry/dataLoaders.js +283 -0
- package/operations/entry/dataLoaders.js.map +1 -0
- package/operations/entry/index.d.ts +4 -0
- package/operations/entry/index.js +25 -0
- package/operations/entry/index.js.map +1 -0
- package/operations/entry/systemFields.d.ts +2 -0
- package/operations/entry/systemFields.js +51 -0
- package/operations/entry/systemFields.js.map +1 -0
- package/operations/entry/utils.d.ts +26 -0
- package/operations/entry/utils.js +362 -0
- package/operations/entry/utils.js.map +1 -0
- package/operations/helpers.d.ts +5 -0
- package/operations/helpers.js +96 -0
- package/operations/helpers.js.map +1 -0
- package/operations/model/CmsContentModelDynamo.d.ts +18 -0
- package/operations/model/CmsContentModelDynamo.js +234 -0
- package/operations/model/CmsContentModelDynamo.js.map +1 -0
- package/operations/model/index.d.ts +3 -0
- package/operations/model/index.js +26 -0
- package/operations/model/index.js.map +1 -0
- package/operations/modelGroup/CmsContentModelGroupDynamo.d.ts +42 -0
- package/operations/modelGroup/CmsContentModelGroupDynamo.js +230 -0
- package/operations/modelGroup/CmsContentModelGroupDynamo.js.map +1 -0
- package/operations/modelGroup/index.d.ts +3 -0
- package/operations/modelGroup/index.js +26 -0
- package/operations/modelGroup/index.js.map +1 -0
- package/operations/settings/CmsSettingsDynamo.d.ts +16 -0
- package/operations/settings/CmsSettingsDynamo.js +145 -0
- package/operations/settings/CmsSettingsDynamo.js.map +1 -0
- package/operations/settings/index.d.ts +3 -0
- package/operations/settings/index.js +25 -0
- package/operations/settings/index.js.map +1 -0
- package/operations/system/CmsSystemDynamo.d.ts +16 -0
- package/operations/system/CmsSystemDynamo.js +126 -0
- package/operations/system/CmsSystemDynamo.js.map +1 -0
- package/operations/system/index.d.ts +3 -0
- package/operations/system/index.js +25 -0
- package/operations/system/index.js.map +1 -0
- package/package.json +61 -0
- package/types.d.ts +54 -0
- package/types.js +6 -0
- package/types.js.map +1 -0
- package/utils.d.ts +5 -0
- package/utils.js +62 -0
- package/utils.js.map +1 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _configurations = _interopRequireDefault(require("../../configurations"));
|
|
15
|
+
|
|
16
|
+
var _utils = require("../../utils");
|
|
17
|
+
|
|
18
|
+
var _dynamodbToolbox = require("dynamodb-toolbox");
|
|
19
|
+
|
|
20
|
+
var _helpers = require("../helpers");
|
|
21
|
+
|
|
22
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
+
|
|
24
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
25
|
+
|
|
26
|
+
class CmsContentModelGroupDynamo {
|
|
27
|
+
get context() {
|
|
28
|
+
return this._context;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get partitionKey() {
|
|
32
|
+
return `${(0, _utils.createBasePartitionKey)(this.context)}#CMG`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
constructor({
|
|
36
|
+
context
|
|
37
|
+
}) {
|
|
38
|
+
(0, _defineProperty2.default)(this, "_context", void 0);
|
|
39
|
+
(0, _defineProperty2.default)(this, "_table", void 0);
|
|
40
|
+
(0, _defineProperty2.default)(this, "_entity", void 0);
|
|
41
|
+
this._context = context;
|
|
42
|
+
this._table = new _dynamodbToolbox.Table({
|
|
43
|
+
name: _configurations.default.db().table || (0, _helpers.getTable)(context),
|
|
44
|
+
partitionKey: "PK",
|
|
45
|
+
sortKey: "SK",
|
|
46
|
+
DocumentClient: (0, _helpers.getDocumentClient)(context)
|
|
47
|
+
});
|
|
48
|
+
this._entity = new _dynamodbToolbox.Entity({
|
|
49
|
+
name: "ContentModelGroup",
|
|
50
|
+
table: this._table,
|
|
51
|
+
attributes: {
|
|
52
|
+
PK: {
|
|
53
|
+
partitionKey: true
|
|
54
|
+
},
|
|
55
|
+
SK: {
|
|
56
|
+
sortKey: true
|
|
57
|
+
},
|
|
58
|
+
TYPE: {
|
|
59
|
+
type: "string"
|
|
60
|
+
},
|
|
61
|
+
webinyVersion: {
|
|
62
|
+
type: "string"
|
|
63
|
+
},
|
|
64
|
+
id: {
|
|
65
|
+
type: "string"
|
|
66
|
+
},
|
|
67
|
+
name: {
|
|
68
|
+
type: "string"
|
|
69
|
+
},
|
|
70
|
+
slug: {
|
|
71
|
+
type: "string"
|
|
72
|
+
},
|
|
73
|
+
locale: {
|
|
74
|
+
type: "string"
|
|
75
|
+
},
|
|
76
|
+
description: {
|
|
77
|
+
type: "string"
|
|
78
|
+
},
|
|
79
|
+
icon: {
|
|
80
|
+
type: "string"
|
|
81
|
+
},
|
|
82
|
+
createdBy: {
|
|
83
|
+
type: "map"
|
|
84
|
+
},
|
|
85
|
+
createdOn: {
|
|
86
|
+
type: "string"
|
|
87
|
+
},
|
|
88
|
+
savedOn: {
|
|
89
|
+
type: "string"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async create({
|
|
96
|
+
data
|
|
97
|
+
}) {
|
|
98
|
+
const dbData = _objectSpread(_objectSpread({
|
|
99
|
+
PK: this.partitionKey,
|
|
100
|
+
SK: data.id,
|
|
101
|
+
TYPE: "cms.group"
|
|
102
|
+
}, data), {}, {
|
|
103
|
+
webinyVersion: this.context.WEBINY_VERSION
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
const result = await this._entity.put(dbData);
|
|
108
|
+
|
|
109
|
+
if (!result) {
|
|
110
|
+
throw new _error.default("Could not create the content model group - no result.", "CREATE_CONTENT_MODEL_GROUP_ERROR");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return dbData;
|
|
114
|
+
} catch (ex) {
|
|
115
|
+
throw new _error.default(ex.message || "Could not create content model group.", ex.code || "CREATE_CONTENT_MODEL_GROUP_ERROR", {
|
|
116
|
+
error: ex,
|
|
117
|
+
data: dbData
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async delete({
|
|
123
|
+
group
|
|
124
|
+
}) {
|
|
125
|
+
const {
|
|
126
|
+
id
|
|
127
|
+
} = group;
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
const result = await this._entity.delete({
|
|
131
|
+
PK: this.partitionKey,
|
|
132
|
+
SK: id
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
if (!result) {
|
|
136
|
+
throw new _error.default("Could not delete content model group - no result.", "DELETE_CONTENT_MODEL_GROUP_ERROR", {
|
|
137
|
+
id
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
} catch (ex) {
|
|
141
|
+
throw new _error.default("Could not delete content model group.", "DELETE_CONTENT_MODEL_GROUP_ERROR", {
|
|
142
|
+
id
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async get({
|
|
150
|
+
id
|
|
151
|
+
}) {
|
|
152
|
+
const response = await this._entity.get({
|
|
153
|
+
PK: this.partitionKey,
|
|
154
|
+
SK: id
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
if (!response || !response.Item) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return response.Item;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async list({
|
|
165
|
+
where,
|
|
166
|
+
limit
|
|
167
|
+
}) {
|
|
168
|
+
let groups;
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
const result = await this._entity.query(this.partitionKey, {
|
|
172
|
+
limit
|
|
173
|
+
}, {});
|
|
174
|
+
|
|
175
|
+
if (!result || !Array.isArray(result.Items)) {
|
|
176
|
+
throw new _error.default("Could not list content model groups - not an array.", "LIST_CONTENT_MODEL_GROUP_ERROR", {
|
|
177
|
+
where,
|
|
178
|
+
limit
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
groups = result.Items;
|
|
183
|
+
} catch (ex) {
|
|
184
|
+
throw new _error.default("Could not list content model groups.", "LIST_CONTENT_MODEL_GROUP_ERROR", {
|
|
185
|
+
where,
|
|
186
|
+
limit
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const whereKeys = Object.keys(where || {});
|
|
191
|
+
|
|
192
|
+
if (whereKeys.length === 0) {
|
|
193
|
+
return groups;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return groups.filter((0, _helpers.whereFilterFactory)(where));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async update({
|
|
200
|
+
group,
|
|
201
|
+
data
|
|
202
|
+
}) {
|
|
203
|
+
const dbData = _objectSpread(_objectSpread({
|
|
204
|
+
PK: this.partitionKey,
|
|
205
|
+
SK: group.id,
|
|
206
|
+
TYPE: "cms.group"
|
|
207
|
+
}, data), {}, {
|
|
208
|
+
webinyVersion: this.context.WEBINY_VERSION
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
try {
|
|
212
|
+
const result = await this._entity.update(dbData);
|
|
213
|
+
|
|
214
|
+
if (!result) {
|
|
215
|
+
throw new _error.default("Could not create the content model group - no result.", "CREATE_CONTENT_MODEL_GROUP_ERROR");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return _objectSpread(_objectSpread({}, group), data);
|
|
219
|
+
} catch (ex) {
|
|
220
|
+
throw new _error.default(ex.message || "Could not create content model group.", ex.code || "CREATE_CONTENT_MODEL_GROUP_ERROR", {
|
|
221
|
+
error: ex,
|
|
222
|
+
data: dbData
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
exports.default = CmsContentModelGroupDynamo;
|
|
230
|
+
//# sourceMappingURL=CmsContentModelGroupDynamo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/operations/modelGroup/CmsContentModelGroupDynamo.ts"],"names":["CmsContentModelGroupDynamo","context","_context","partitionKey","constructor","_table","Table","name","configurations","db","table","sortKey","DocumentClient","_entity","Entity","attributes","PK","SK","TYPE","type","webinyVersion","id","slug","locale","description","icon","createdBy","createdOn","savedOn","create","data","dbData","WEBINY_VERSION","result","put","WebinyError","ex","message","code","error","delete","group","get","response","Item","list","where","limit","groups","query","Array","isArray","Items","whereKeys","Object","keys","length","filter","update"],"mappings":";;;;;;;;;;;AASA;;AACA;;AACA;;AACA;;AACA;;;;;;AAMe,MAAMA,0BAAN,CAAkF;AAK1E,MAAPC,OAAO,GAAe;AAC9B,WAAO,KAAKC,QAAZ;AACH;;AAEuB,MAAZC,YAAY,GAAW;AAC/B,WAAQ,GAAE,mCAAuB,KAAKF,OAA5B,CAAqC,MAA/C;AACH;;AAEMG,EAAAA,WAAW,CAAC;AAAEH,IAAAA;AAAF,GAAD,EAA+B;AAAA;AAAA;AAAA;AAC7C,SAAKC,QAAL,GAAgBD,OAAhB;AACA,SAAKI,MAAL,GAAc,IAAIC,sBAAJ,CAAU;AACpBC,MAAAA,IAAI,EAAEC,wBAAeC,EAAf,GAAoBC,KAApB,IAA6B,uBAAST,OAAT,CADf;AAEpBE,MAAAA,YAAY,EAAE,IAFM;AAGpBQ,MAAAA,OAAO,EAAE,IAHW;AAIpBC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MAAAA,EAAE,EAAEwB,KAAK,CAACpB,EAFF;AAGRH,MAAAA,IAAI,EAAE;AAHE,OAILY,IAJK;AAKRV,MAAAA,aAAa,EAAE,KAAKnB,OAAL,CAAa+B;AALpB,MAAZ;;AAQA,QAAI;AACA,YAAMC,MAAM,GAAG,MAAM,KAAKpB,OAAL,CAAa6C,MAAb,CAAoB3B,MAApB,CAArB;;AACA,UAAI,CAACE,MAAL,EAAa;AACT,cAAM,IAAIE,cAAJ,CACF,uDADE,EAEF,kCAFE,CAAN;AAIH;;AACD,6CACOM,KADP,GAEOX,IAFP;AAIH,KAZD,CAYE,OAAOM,EAAP,EAAW;AACT,YAAM,IAAID,cAAJ,CACFC,EAAE,CAACC,OAAH,IAAc,uCADZ,EAEFD,EAAE,CAACE,IAAH,IAAW,kCAFT,EAGF;AACIC,QAAAA,KAAK,EAAEH,EADX;AAEIN,QAAAA,IAAI,EAAEC;AAFV,OAHE,CAAN;AAQH;AACJ;;AA9M4F","sourcesContent":["import {\n CmsContentModelGroupStorageOperations,\n CmsContentModelGroupStorageOperationsCreateArgs,\n CmsContentModelGroupStorageOperationsDeleteArgs,\n CmsContentModelGroupStorageOperationsGetArgs,\n CmsContentModelGroupStorageOperationsListArgs,\n CmsContentModelGroupStorageOperationsUpdateArgs,\n CmsContext\n} from \"@webiny/api-headless-cms/types\";\nimport WebinyError from \"@webiny/error\";\nimport configurations from \"../../configurations\";\nimport { createBasePartitionKey } from \"../../utils\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { getDocumentClient, getTable, whereFilterFactory } from \"../helpers\";\n\ninterface ConstructorArgs {\n context: CmsContext;\n}\n\nexport default class CmsContentModelGroupDynamo implements CmsContentModelGroupStorageOperations {\n private readonly _context: CmsContext;\n private readonly _table: Table;\n private readonly _entity: Entity<any>;\n\n private get context(): CmsContext {\n return this._context;\n }\n\n private get partitionKey(): string {\n return `${createBasePartitionKey(this.context)}#CMG`;\n }\n\n public constructor({ context }: ConstructorArgs) {\n this._context = context;\n this._table = new Table({\n name: configurations.db().table || getTable(context),\n partitionKey: \"PK\",\n sortKey: \"SK\",\n DocumentClient: getDocumentClient(context)\n });\n this._entity = new Entity({\n name: \"ContentModelGroup\",\n table: this._table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n TYPE: {\n type: \"string\"\n },\n webinyVersion: {\n type: \"string\"\n },\n id: {\n type: \"string\"\n },\n name: {\n type: \"string\"\n },\n slug: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n description: {\n type: \"string\"\n },\n icon: {\n type: \"string\"\n },\n createdBy: {\n type: \"map\"\n },\n createdOn: {\n type: \"string\"\n },\n savedOn: {\n type: \"string\"\n }\n }\n });\n }\n\n public async create({ data }: CmsContentModelGroupStorageOperationsCreateArgs) {\n const dbData = {\n PK: this.partitionKey,\n SK: data.id,\n TYPE: \"cms.group\",\n ...data,\n webinyVersion: this.context.WEBINY_VERSION\n };\n\n try {\n const result = await this._entity.put(dbData);\n if (!result) {\n throw new WebinyError(\n \"Could not create the content model group - no result.\",\n \"CREATE_CONTENT_MODEL_GROUP_ERROR\"\n );\n }\n return dbData;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create content model group.\",\n ex.code || \"CREATE_CONTENT_MODEL_GROUP_ERROR\",\n {\n error: ex,\n data: dbData\n }\n );\n }\n }\n public async delete({ group }: CmsContentModelGroupStorageOperationsDeleteArgs) {\n const { id } = group;\n try {\n const result = await this._entity.delete({\n PK: this.partitionKey,\n SK: id\n });\n if (!result) {\n throw new WebinyError(\n \"Could not delete content model group - no result.\",\n \"DELETE_CONTENT_MODEL_GROUP_ERROR\",\n {\n id\n }\n );\n }\n } catch (ex) {\n throw new WebinyError(\n \"Could not delete content model group.\",\n \"DELETE_CONTENT_MODEL_GROUP_ERROR\",\n {\n id\n }\n );\n }\n return true;\n }\n public async get({ id }: CmsContentModelGroupStorageOperationsGetArgs) {\n const response = await this._entity.get({\n PK: this.partitionKey,\n SK: id\n });\n\n if (!response || !response.Item) {\n return null;\n }\n return response.Item;\n }\n public async list({ where, limit }: CmsContentModelGroupStorageOperationsListArgs) {\n let groups;\n try {\n const result = await this._entity.query(\n this.partitionKey,\n {\n limit\n },\n {}\n );\n if (!result || !Array.isArray(result.Items)) {\n throw new WebinyError(\n \"Could not list content model groups - not an array.\",\n \"LIST_CONTENT_MODEL_GROUP_ERROR\",\n {\n where,\n limit\n }\n );\n }\n groups = result.Items;\n } catch (ex) {\n throw new WebinyError(\n \"Could not list content model groups.\",\n \"LIST_CONTENT_MODEL_GROUP_ERROR\",\n {\n where,\n limit\n }\n );\n }\n\n const whereKeys = Object.keys(where || {});\n if (whereKeys.length === 0) {\n return groups;\n }\n\n return groups.filter(whereFilterFactory(where));\n }\n\n public async update({ group, data }: CmsContentModelGroupStorageOperationsUpdateArgs) {\n const dbData = {\n PK: this.partitionKey,\n SK: group.id,\n TYPE: \"cms.group\",\n ...data,\n webinyVersion: this.context.WEBINY_VERSION\n };\n\n try {\n const result = await this._entity.update(dbData);\n if (!result) {\n throw new WebinyError(\n \"Could not create the content model group - no result.\",\n \"CREATE_CONTENT_MODEL_GROUP_ERROR\"\n );\n }\n return {\n ...group,\n ...data\n };\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create content model group.\",\n ex.code || \"CREATE_CONTENT_MODEL_GROUP_ERROR\",\n {\n error: ex,\n data: dbData\n }\n );\n }\n }\n}\n"],"file":"CmsContentModelGroupDynamo.js"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _CmsContentModelGroupDynamo = _interopRequireDefault(require("./CmsContentModelGroupDynamo"));
|
|
11
|
+
|
|
12
|
+
const contentModelGroupStorageOperationsProvider = () => ({
|
|
13
|
+
type: "cms-content-model-group-storage-operations-provider",
|
|
14
|
+
name: "cms-content-model-group-storage-operations-ddb-crud",
|
|
15
|
+
provide: async ({
|
|
16
|
+
context
|
|
17
|
+
}) => {
|
|
18
|
+
return new _CmsContentModelGroupDynamo.default({
|
|
19
|
+
context
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
var _default = contentModelGroupStorageOperationsProvider;
|
|
25
|
+
exports.default = _default;
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/operations/modelGroup/index.ts"],"names":["contentModelGroupStorageOperationsProvider","type","name","provide","context","CmsContentModelGroupDynamo"],"mappings":";;;;;;;;;AAAA;;AAGA,MAAMA,0CAA0C,GAC5C,OAAsD;AAClDC,EAAAA,IAAI,EAAE,qDAD4C;AAElDC,EAAAA,IAAI,EAAE,qDAF4C;AAGlDC,EAAAA,OAAO,EAAE,OAAO;AAAEC,IAAAA;AAAF,GAAP,KAAuB;AAC5B,WAAO,IAAIC,mCAAJ,CAA+B;AAClCD,MAAAA;AADkC,KAA/B,CAAP;AAGH;AAPiD,CAAtD,CADJ;;eAWeJ,0C","sourcesContent":["import CmsContentModelGroupDynamo from \"./CmsContentModelGroupDynamo\";\nimport { CmsContentModelGroupStorageOperationsProvider } from \"@webiny/api-headless-cms/types\";\n\nconst contentModelGroupStorageOperationsProvider =\n (): CmsContentModelGroupStorageOperationsProvider => ({\n type: \"cms-content-model-group-storage-operations-provider\",\n name: \"cms-content-model-group-storage-operations-ddb-crud\",\n provide: async ({ context }) => {\n return new CmsContentModelGroupDynamo({\n context\n });\n }\n });\n\nexport default contentModelGroupStorageOperationsProvider;\n"],"file":"index.js"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CmsContext, CmsSettings, CmsSettingsStorageOperations } from "@webiny/api-headless-cms/types";
|
|
2
|
+
interface ConstructorArgs {
|
|
3
|
+
context: CmsContext;
|
|
4
|
+
}
|
|
5
|
+
export default class CmsSettingsDynamo implements CmsSettingsStorageOperations {
|
|
6
|
+
private readonly _context;
|
|
7
|
+
private readonly _table;
|
|
8
|
+
private readonly _entity;
|
|
9
|
+
private get context();
|
|
10
|
+
private get partitionKey();
|
|
11
|
+
constructor({ context }: ConstructorArgs);
|
|
12
|
+
get(): Promise<CmsSettings>;
|
|
13
|
+
create(data: CmsSettings): Promise<void>;
|
|
14
|
+
update(data: CmsSettings): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _configurations = _interopRequireDefault(require("../../configurations"));
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _utils = require("../../utils");
|
|
17
|
+
|
|
18
|
+
var _dynamodbToolbox = require("dynamodb-toolbox");
|
|
19
|
+
|
|
20
|
+
var _helpers = require("../helpers");
|
|
21
|
+
|
|
22
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
+
|
|
24
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
25
|
+
|
|
26
|
+
const convertToDbData = data => {
|
|
27
|
+
return _objectSpread(_objectSpread({}, data), {}, {
|
|
28
|
+
contentModelLastChange: data.contentModelLastChange.toISOString()
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const convertFromDbData = data => {
|
|
33
|
+
if (!data) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let contentModelLastChange;
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
contentModelLastChange = new Date(data.contentModelLastChange);
|
|
41
|
+
} catch {
|
|
42
|
+
contentModelLastChange = new Date();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return _objectSpread(_objectSpread({}, data), {}, {
|
|
46
|
+
contentModelLastChange
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const SETTINGS_SECONDARY_KEY = "settings";
|
|
51
|
+
|
|
52
|
+
class CmsSettingsDynamo {
|
|
53
|
+
get context() {
|
|
54
|
+
return this._context;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get partitionKey() {
|
|
58
|
+
return `${(0, _utils.createBasePartitionKey)(this.context)}#SETTINGS`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
constructor({
|
|
62
|
+
context
|
|
63
|
+
}) {
|
|
64
|
+
(0, _defineProperty2.default)(this, "_context", void 0);
|
|
65
|
+
(0, _defineProperty2.default)(this, "_table", void 0);
|
|
66
|
+
(0, _defineProperty2.default)(this, "_entity", void 0);
|
|
67
|
+
this._context = context;
|
|
68
|
+
this._table = new _dynamodbToolbox.Table({
|
|
69
|
+
name: _configurations.default.db().table || (0, _helpers.getTable)(context),
|
|
70
|
+
partitionKey: "PK",
|
|
71
|
+
sortKey: "SK",
|
|
72
|
+
DocumentClient: (0, _helpers.getDocumentClient)(context)
|
|
73
|
+
});
|
|
74
|
+
this._entity = new _dynamodbToolbox.Entity({
|
|
75
|
+
name: "System",
|
|
76
|
+
table: this._table,
|
|
77
|
+
attributes: {
|
|
78
|
+
PK: {
|
|
79
|
+
partitionKey: true
|
|
80
|
+
},
|
|
81
|
+
SK: {
|
|
82
|
+
sortKey: true
|
|
83
|
+
},
|
|
84
|
+
contentModelLastChange: {
|
|
85
|
+
type: "string"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async get() {
|
|
92
|
+
const response = await this._entity.get({
|
|
93
|
+
PK: this.partitionKey,
|
|
94
|
+
SK: SETTINGS_SECONDARY_KEY
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
if (!response || !response.Item) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return convertFromDbData(response.Item);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async create(data) {
|
|
105
|
+
const dbData = convertToDbData(data);
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const result = await this._entity.put(_objectSpread({
|
|
109
|
+
PK: this.partitionKey,
|
|
110
|
+
SK: SETTINGS_SECONDARY_KEY
|
|
111
|
+
}, dbData));
|
|
112
|
+
|
|
113
|
+
if (!result) {
|
|
114
|
+
throw new _error.default("Could not create the settings data - no result.", "CREATE_SETTINGS_ERROR");
|
|
115
|
+
}
|
|
116
|
+
} catch (ex) {
|
|
117
|
+
throw new _error.default(ex.message || "Could not create settings.", ex.code || "CREATE_SETTINGS_ERROR", {
|
|
118
|
+
error: ex,
|
|
119
|
+
data
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async update(data) {
|
|
125
|
+
try {
|
|
126
|
+
const result = await this._entity.update(_objectSpread({
|
|
127
|
+
PK: this.partitionKey,
|
|
128
|
+
SK: SETTINGS_SECONDARY_KEY
|
|
129
|
+
}, convertToDbData(data)));
|
|
130
|
+
|
|
131
|
+
if (!result) {
|
|
132
|
+
throw new _error.default("Could not update the settings data - no result.", "CREATE_SETTINGS_ERROR");
|
|
133
|
+
}
|
|
134
|
+
} catch (ex) {
|
|
135
|
+
throw new _error.default(ex.message || "Could not update settings.", ex.code || "UPDATE_SETTINGS_ERROR", {
|
|
136
|
+
error: ex,
|
|
137
|
+
data
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
exports.default = CmsSettingsDynamo;
|
|
145
|
+
//# sourceMappingURL=CmsSettingsDynamo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/operations/settings/CmsSettingsDynamo.ts"],"names":["convertToDbData","data","contentModelLastChange","toISOString","convertFromDbData","Date","SETTINGS_SECONDARY_KEY","CmsSettingsDynamo","context","_context","partitionKey","constructor","_table","Table","name","configurations","db","table","sortKey","DocumentClient","_entity","Entity","attributes","PK","SK","type","get","response","Item","create","dbData","result","put","WebinyError","ex","message","code","error","update"],"mappings":";;;;;;;;;;;AAKA;;AACA;;AACA;;AACA;;AACA;;;;;;AAUA,MAAMA,eAAe,GAAIC,IAAD,IAAsC;AAC1D,yCACOA,IADP;AAEIC,IAAAA,sBAAsB,EAAED,IAAI,CAACC,sBAAL,CAA4BC,WAA5B;AAF5B;AAIH,CALD;;AAOA,MAAMC,iBAAiB,GAAIH,IAAD,IAA8C;AACpE,MAAI,CAACA,IAAL,EAAW;AACP,WAAO,IAAP;AACH;;AACD,MAAIC,sBAAJ;;AACA,MAAI;AACAA,IAAAA,sBAAsB,GAAG,IAAIG,IAAJ,CAASJ,IAAI,CAACC,sBAAd,CAAzB;AACH,GAFD,CAEE,MAAM;AACJA,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IjC,QAAAA;AAFJ,OAHE,CAAN;AAQH;AACJ;;AApG0E","sourcesContent":["import {\n CmsContext,\n CmsSettings,\n CmsSettingsStorageOperations\n} from \"@webiny/api-headless-cms/types\";\nimport configurations from \"../../configurations\";\nimport WebinyError from \"@webiny/error\";\nimport { createBasePartitionKey } from \"../../utils\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { getDocumentClient, getTable } from \"../helpers\";\n\ninterface ConstructorArgs {\n context: CmsContext;\n}\n// @ts-ignore\ninterface CmsSettingsDb extends CmsSettings {\n contentModelLastChange: string;\n}\n\nconst convertToDbData = (data: CmsSettings): CmsSettingsDb => {\n return {\n ...data,\n contentModelLastChange: data.contentModelLastChange.toISOString()\n };\n};\n\nconst convertFromDbData = (data?: CmsSettingsDb): CmsSettings | null => {\n if (!data) {\n return null;\n }\n let contentModelLastChange;\n try {\n contentModelLastChange = new Date(data.contentModelLastChange);\n } catch {\n contentModelLastChange = new Date();\n }\n return {\n ...data,\n contentModelLastChange\n };\n};\n\nconst SETTINGS_SECONDARY_KEY = \"settings\";\n\nexport default class CmsSettingsDynamo implements CmsSettingsStorageOperations {\n private readonly _context: CmsContext;\n private readonly _table: Table;\n private readonly _entity: Entity<any>;\n\n private get context(): CmsContext {\n return this._context;\n }\n\n private get partitionKey(): string {\n return `${createBasePartitionKey(this.context)}#SETTINGS`;\n }\n\n public constructor({ context }: ConstructorArgs) {\n this._context = context;\n\n this._table = new Table({\n name: configurations.db().table || getTable(context),\n partitionKey: \"PK\",\n sortKey: \"SK\",\n DocumentClient: getDocumentClient(context)\n });\n this._entity = new Entity({\n name: \"System\",\n table: this._table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n contentModelLastChange: {\n type: \"string\"\n }\n }\n });\n }\n\n public async get(): Promise<CmsSettings> {\n const response = await this._entity.get({\n PK: this.partitionKey,\n SK: SETTINGS_SECONDARY_KEY\n });\n\n if (!response || !response.Item) {\n return null;\n }\n return convertFromDbData(response.Item);\n }\n\n public async create(data: CmsSettings): Promise<void> {\n const dbData = convertToDbData(data);\n try {\n const result = await this._entity.put({\n PK: this.partitionKey,\n SK: SETTINGS_SECONDARY_KEY,\n ...dbData\n });\n if (!result) {\n throw new WebinyError(\n \"Could not create the settings data - no result.\",\n \"CREATE_SETTINGS_ERROR\"\n );\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create settings.\",\n ex.code || \"CREATE_SETTINGS_ERROR\",\n {\n error: ex,\n data\n }\n );\n }\n }\n\n public async update(data: CmsSettings): Promise<void> {\n try {\n const result = await this._entity.update({\n PK: this.partitionKey,\n SK: SETTINGS_SECONDARY_KEY,\n ...convertToDbData(data)\n });\n if (!result) {\n throw new WebinyError(\n \"Could not update the settings data - no result.\",\n \"CREATE_SETTINGS_ERROR\"\n );\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update settings.\",\n ex.code || \"UPDATE_SETTINGS_ERROR\",\n {\n error: ex,\n data\n }\n );\n }\n }\n}\n"],"file":"CmsSettingsDynamo.js"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _CmsSettingsDynamo = _interopRequireDefault(require("./CmsSettingsDynamo"));
|
|
11
|
+
|
|
12
|
+
var _default = () => ({
|
|
13
|
+
type: "cms-settings-storage-operations-provider",
|
|
14
|
+
name: "cms-settings-storage-operations-ddb-crud",
|
|
15
|
+
provide: async ({
|
|
16
|
+
context
|
|
17
|
+
}) => {
|
|
18
|
+
return new _CmsSettingsDynamo.default({
|
|
19
|
+
context
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
exports.default = _default;
|
|
25
|
+
//# sourceMappingURL=index.js.map
|