@webiny/api-headless-cms-ddb 5.17.4 → 5.18.0-beta.3

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 (91) hide show
  1. package/definitions/entry.d.ts +6 -4
  2. package/definitions/entry.js +19 -8
  3. package/definitions/group.d.ts +8 -0
  4. package/definitions/group.js +74 -0
  5. package/definitions/model.d.ts +8 -0
  6. package/definitions/model.js +96 -0
  7. package/definitions/settings.d.ts +8 -0
  8. package/definitions/settings.js +62 -0
  9. package/definitions/system.d.ts +8 -0
  10. package/definitions/system.js +50 -0
  11. package/definitions/table.d.ts +6 -12
  12. package/definitions/table.js +15 -15
  13. package/dynamoDb/index.d.ts +1 -1
  14. package/dynamoDb/index.js +4 -3
  15. package/dynamoDb/path/plainObject.js +1 -2
  16. package/dynamoDb/path/ref.js +1 -2
  17. package/dynamoDb/storage/date.d.ts +2 -2
  18. package/dynamoDb/storage/date.js +17 -21
  19. package/dynamoDb/storage/longText.d.ts +7 -0
  20. package/dynamoDb/storage/longText.js +83 -0
  21. package/dynamoDb/storage/richText.d.ts +2 -2
  22. package/dynamoDb/storage/richText.js +69 -67
  23. package/dynamoDb/transformValue/datetime.d.ts +1 -1
  24. package/dynamoDb/transformValue/datetime.js +1 -2
  25. package/index.d.ts +2 -6
  26. package/index.js +108 -13
  27. package/operations/entry/dataLoaders.d.ts +34 -19
  28. package/operations/entry/dataLoaders.js +158 -138
  29. package/operations/entry/index.d.ts +8 -4
  30. package/operations/entry/index.js +812 -16
  31. package/operations/entry/keys.d.ts +25 -0
  32. package/operations/entry/keys.js +62 -0
  33. package/operations/entry/systemFields.d.ts +2 -2
  34. package/operations/entry/systemFields.js +1 -2
  35. package/operations/entry/utils.d.ts +13 -9
  36. package/operations/entry/utils.js +62 -18
  37. package/operations/group/index.d.ts +8 -0
  38. package/operations/group/index.js +198 -0
  39. package/operations/model/index.d.ts +6 -3
  40. package/operations/model/index.js +153 -18
  41. package/operations/settings/index.d.ts +6 -3
  42. package/operations/settings/index.js +132 -16
  43. package/operations/system/index.d.ts +6 -3
  44. package/operations/system/index.js +94 -14
  45. package/package.json +11 -11
  46. package/types.d.ts +38 -8
  47. package/types.js +11 -1
  48. package/configurations.d.ts +0 -18
  49. package/configurations.js +0 -24
  50. package/configurations.js.map +0 -1
  51. package/definitions/entry.js.map +0 -1
  52. package/definitions/table.js.map +0 -1
  53. package/dynamoDb/index.js.map +0 -1
  54. package/dynamoDb/path/plainObject.js.map +0 -1
  55. package/dynamoDb/path/ref.js.map +0 -1
  56. package/dynamoDb/storage/date.js.map +0 -1
  57. package/dynamoDb/storage/richText.js.map +0 -1
  58. package/dynamoDb/transformValue/datetime.js.map +0 -1
  59. package/index.js.map +0 -1
  60. package/operations/entry/CmsContentEntryDynamo.d.ts +0 -86
  61. package/operations/entry/CmsContentEntryDynamo.js +0 -972
  62. package/operations/entry/CmsContentEntryDynamo.js.map +0 -1
  63. package/operations/entry/dataLoaders.js.map +0 -1
  64. package/operations/entry/index.js.map +0 -1
  65. package/operations/entry/systemFields.js.map +0 -1
  66. package/operations/entry/utils.js.map +0 -1
  67. package/operations/helpers.d.ts +0 -5
  68. package/operations/helpers.js +0 -96
  69. package/operations/helpers.js.map +0 -1
  70. package/operations/model/CmsContentModelDynamo.d.ts +0 -18
  71. package/operations/model/CmsContentModelDynamo.js +0 -234
  72. package/operations/model/CmsContentModelDynamo.js.map +0 -1
  73. package/operations/model/index.js.map +0 -1
  74. package/operations/modelGroup/CmsContentModelGroupDynamo.d.ts +0 -42
  75. package/operations/modelGroup/CmsContentModelGroupDynamo.js +0 -230
  76. package/operations/modelGroup/CmsContentModelGroupDynamo.js.map +0 -1
  77. package/operations/modelGroup/index.d.ts +0 -3
  78. package/operations/modelGroup/index.js +0 -26
  79. package/operations/modelGroup/index.js.map +0 -1
  80. package/operations/settings/CmsSettingsDynamo.d.ts +0 -16
  81. package/operations/settings/CmsSettingsDynamo.js +0 -145
  82. package/operations/settings/CmsSettingsDynamo.js.map +0 -1
  83. package/operations/settings/index.js.map +0 -1
  84. package/operations/system/CmsSystemDynamo.d.ts +0 -16
  85. package/operations/system/CmsSystemDynamo.js +0 -126
  86. package/operations/system/CmsSystemDynamo.js.map +0 -1
  87. package/operations/system/index.js.map +0 -1
  88. package/types.js.map +0 -1
  89. package/utils.d.ts +0 -5
  90. package/utils.js +0 -62
  91. package/utils.js.map +0 -1
@@ -1,8 +1,8 @@
1
- import { CmsModelFieldToStoragePlugin } from "@webiny/api-headless-cms/types";
1
+ import { StorageTransformPlugin } from "@webiny/api-headless-cms/content/plugins/storage/StorageTransformPlugin";
2
2
  export declare type OriginalValue = Record<string, any> | any[];
3
3
  export interface StorageValue {
4
4
  compression: string;
5
5
  value: any;
6
6
  }
7
- declare const _default: () => CmsModelFieldToStoragePlugin<OriginalValue, StorageValue>;
7
+ declare const _default: () => StorageTransformPlugin<any, any>;
8
8
  export default _default;
@@ -11,12 +11,18 @@ var _jsonpack = _interopRequireDefault(require("jsonpack"));
11
11
 
12
12
  var _error = _interopRequireDefault(require("@webiny/error"));
13
13
 
14
+ var _StorageTransformPlugin = require("@webiny/api-headless-cms/content/plugins/storage/StorageTransformPlugin");
15
+
14
16
  /**
15
17
  * Remove when jsonpack gets PR with a fix merged
16
18
  * https://github.com/rgcl/jsonpack/pull/25/files
17
19
  * NOTE 2021-07-28: it seems PR is not going to be merged so keep this.
18
20
  */
19
21
  const transformArray = value => {
22
+ if (!value) {
23
+ return value;
24
+ }
25
+
20
26
  let isArray = Array.isArray(value);
21
27
  const shouldBeArray = value instanceof Array === false && isArray;
22
28
 
@@ -34,75 +40,71 @@ const transformArray = value => {
34
40
  return value;
35
41
  };
36
42
 
37
- var _default = () => {
38
- return {
39
- type: "cms-model-field-to-storage",
40
- name: "cms-model-field-to-storage-rich-text",
41
- fieldType: "rich-text",
42
-
43
- async fromStorage({
44
- field,
45
- value: storageValue
46
- }) {
47
- if (!storageValue) {
48
- return storageValue;
49
- } else if (typeof storageValue !== "object") {
50
- throw new _error.default(`Value received in "fromStorage" function is not an object in field "${field.fieldId}".`);
51
- }
52
- /**
53
- * This is to circumvent a bug introduced with 5.8.0 storage operations.
54
- * Do not remove.
55
- */
56
-
57
-
58
- if (storageValue.hasOwnProperty("compression") === false) {
59
- return storageValue;
60
- }
61
-
62
- const {
63
- compression,
64
- value
65
- } = storageValue;
66
-
67
- if (!compression) {
68
- throw new _error.default(`Missing compression in "fromStorage" function in field "${field.fieldId}": ${JSON.stringify(storageValue)}.`, "MISSING_COMPRESSION", {
69
- value: storageValue
70
- });
71
- }
72
-
73
- if (compression !== "jsonpack") {
74
- throw new _error.default(`This plugin cannot transform something not packed with "jsonpack".`, "WRONG_COMPRESSION", {
75
- compression
76
- });
77
- }
78
-
79
- try {
80
- return _jsonpack.default.unpack(value);
81
- } catch {
82
- return null;
83
- }
84
- },
85
-
86
- async toStorage({
43
+ const plugin = new _StorageTransformPlugin.StorageTransformPlugin({
44
+ fieldType: "rich-text",
45
+ fromStorage: async ({
46
+ field,
47
+ value: storageValue
48
+ }) => {
49
+ if (!storageValue) {
50
+ return storageValue;
51
+ } else if (typeof storageValue !== "object") {
52
+ throw new _error.default(`RichText value received in "fromStorage" function is not an object in field "${field.fieldId}".`);
53
+ }
54
+ /**
55
+ * This is to circumvent a bug introduced with 5.8.0 storage operations.
56
+ * Do not remove.
57
+ */
58
+
59
+
60
+ if (storageValue.hasOwnProperty("compression") === false) {
61
+ return storageValue;
62
+ }
63
+
64
+ const {
65
+ compression,
87
66
  value
88
- }) {
89
- /**
90
- * There is a possibility that we are trying to compress already compressed value.
91
- * Introduced a bug with 5.8.0 storage operations, so just return the value to correct it.
92
- */
93
- if (value && value.hasOwnProperty("compression") === true) {
94
- return value;
95
- }
96
-
97
- value = transformArray(value);
98
- return {
99
- compression: "jsonpack",
100
- value: value ? _jsonpack.default.pack(value) : value
101
- };
67
+ } = storageValue;
68
+
69
+ if (!compression) {
70
+ throw new _error.default(`Missing compression in "fromStorage" function in field "${field.fieldId}": ${JSON.stringify(storageValue)}.`, "MISSING_COMPRESSION", {
71
+ value: storageValue
72
+ });
102
73
  }
103
74
 
104
- };
75
+ if (compression !== "jsonpack") {
76
+ throw new _error.default(`This plugin cannot transform something not packed with "jsonpack".`, "WRONG_COMPRESSION", {
77
+ compression
78
+ });
79
+ }
80
+
81
+ try {
82
+ return _jsonpack.default.unpack(value);
83
+ } catch {
84
+ return null;
85
+ }
86
+ },
87
+ toStorage: async ({
88
+ value
89
+ }) => {
90
+ /**
91
+ * There is a possibility that we are trying to compress already compressed value.
92
+ * Introduced a bug with 5.8.0 storage operations, so just return the value to correct it.
93
+ */
94
+ if (value && value.hasOwnProperty("compression") === true) {
95
+ return value;
96
+ }
97
+
98
+ value = transformArray(value);
99
+ return {
100
+ compression: "jsonpack",
101
+ value: value ? _jsonpack.default.pack(value) : value
102
+ };
103
+ }
104
+ });
105
+
106
+ var _default = () => {
107
+ return plugin;
105
108
  };
106
109
 
107
- exports.default = _default;
108
- //# sourceMappingURL=richText.js.map
110
+ exports.default = _default;
@@ -1,3 +1,3 @@
1
1
  import { CmsFieldFilterValueTransformPlugin } from "../../types";
2
- declare const _default: () => CmsFieldFilterValueTransformPlugin<Date | string | number, number>;
2
+ declare const _default: () => CmsFieldFilterValueTransformPlugin;
3
3
  export default _default;
@@ -44,5 +44,4 @@ var _default = () => ({
44
44
  }
45
45
  });
46
46
 
47
- exports.default = _default;
48
- //# sourceMappingURL=datetime.js.map
47
+ exports.default = _default;
package/index.d.ts CHANGED
@@ -1,6 +1,2 @@
1
- import { CmsContentEntryConfiguration } from "./operations/entry/CmsContentEntryDynamo";
2
- interface Configuration {
3
- entry?: CmsContentEntryConfiguration;
4
- }
5
- declare const _default: (configuration?: Configuration) => (import("@webiny/api-headless-cms/types").CmsContentModelGroupStorageOperationsProvider | import("@webiny/api-headless-cms/types").CmsContentModelStorageOperationsProvider | import("@webiny/api-headless-cms/types").CmsContentEntryStorageOperationsProvider | import("@webiny/api-headless-cms/types").CmsSettingsStorageOperationsProviderPlugin | import("@webiny/api-headless-cms/types").CmsSystemStorageOperationsProviderPlugin | (import("./types").CmsFieldFilterPathPlugin | import("@webiny/api-headless-cms/types").CmsModelFieldToStoragePlugin<import("./dynamoDb/storage/richText").OriginalValue, import("./dynamoDb/storage/richText").StorageValue> | import("@webiny/api-headless-cms/types").CmsModelFieldToStoragePlugin<string | Date, string> | import("./types").CmsFieldFilterValueTransformPlugin<string | number | Date, number>)[])[];
6
- export default _default;
1
+ import { StorageOperationsFactory } from "./types";
2
+ export declare const createStorageOperations: StorageOperationsFactory;
package/index.js CHANGED
@@ -5,26 +5,121 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = void 0;
8
+ exports.createStorageOperations = void 0;
9
9
 
10
- var _settings = _interopRequireDefault(require("./operations/settings"));
10
+ var _filters = _interopRequireDefault(require("@webiny/db-dynamodb/plugins/filters"));
11
11
 
12
- var _system = _interopRequireDefault(require("./operations/system"));
12
+ var _dynamoDb = _interopRequireDefault(require("./dynamoDb"));
13
13
 
14
- var _modelGroup = _interopRequireDefault(require("./operations/modelGroup"));
14
+ var _types = require("./types");
15
15
 
16
- var _model = _interopRequireDefault(require("./operations/model"));
16
+ var _table = require("./definitions/table");
17
17
 
18
- var _entry = _interopRequireDefault(require("./operations/entry"));
18
+ var _settings = require("./definitions/settings");
19
19
 
20
- var _dynamoDb = _interopRequireDefault(require("./dynamoDb"));
20
+ var _system = require("./definitions/system");
21
+
22
+ var _group = require("./definitions/group");
23
+
24
+ var _model = require("./definitions/model");
25
+
26
+ var _entry = require("./definitions/entry");
27
+
28
+ var _plugins = require("@webiny/plugins");
29
+
30
+ var _system2 = require("./operations/system");
31
+
32
+ var _settings2 = require("./operations/settings");
33
+
34
+ var _group2 = require("./operations/group");
35
+
36
+ var _model2 = require("./operations/model");
37
+
38
+ var _entry2 = require("./operations/entry");
21
39
 
22
- var _default = configuration => {
40
+ const createStorageOperations = params => {
23
41
  const {
24
- entry
25
- } = configuration || {};
26
- return [(0, _settings.default)(), (0, _system.default)(), (0, _modelGroup.default)(), (0, _model.default)(), (0, _entry.default)(entry), (0, _dynamoDb.default)()];
42
+ attributes = {},
43
+ table,
44
+ documentClient,
45
+ plugins: customPlugins,
46
+ modelFieldToGraphQLPlugins
47
+ } = params;
48
+ const tableInstance = (0, _table.createTable)({
49
+ table,
50
+ documentClient
51
+ });
52
+ const entities = {
53
+ settings: (0, _settings.createSettingsEntity)({
54
+ entityName: _types.ENTITIES.SETTINGS,
55
+ table: tableInstance,
56
+ attributes: attributes[_types.ENTITIES.SETTINGS]
57
+ }),
58
+ system: (0, _system.createSystemEntity)({
59
+ entityName: _types.ENTITIES.SYSTEM,
60
+ table: tableInstance,
61
+ attributes: attributes[_types.ENTITIES.SYSTEM]
62
+ }),
63
+ groups: (0, _group.createGroupEntity)({
64
+ entityName: _types.ENTITIES.GROUPS,
65
+ table: tableInstance,
66
+ attributes: attributes[_types.ENTITIES.GROUPS]
67
+ }),
68
+ models: (0, _model.createModelEntity)({
69
+ entityName: _types.ENTITIES.MODELS,
70
+ table: tableInstance,
71
+ attributes: attributes[_types.ENTITIES.MODELS]
72
+ }),
73
+ entries: (0, _entry.createEntryEntity)({
74
+ entityName: _types.ENTITIES.ENTRIES,
75
+ table: tableInstance,
76
+ attributes: attributes[_types.ENTITIES.ENTRIES]
77
+ })
78
+ };
79
+ const plugins = new _plugins.PluginsContainer([
80
+ /**
81
+ * User defined custom plugins.
82
+ */
83
+ ...(customPlugins || []),
84
+ /**
85
+ * Plugins of type CmsModelFieldToGraphQLPlugin.
86
+ */
87
+ modelFieldToGraphQLPlugins,
88
+ /**
89
+ * DynamoDB filter plugins for the where conditions.
90
+ */
91
+ (0, _filters.default)(),
92
+ /**
93
+ * Field plugins for DynamoDB.
94
+ */
95
+ (0, _dynamoDb.default)()]);
96
+ return {
97
+ plugins: [
98
+ /**
99
+ * Field plugins for DynamoDB.
100
+ * We must pass them to the base application.
101
+ */
102
+ (0, _dynamoDb.default)()],
103
+ getEntities: () => entities,
104
+ getTable: () => tableInstance,
105
+ system: (0, _system2.createSystemStorageOperations)({
106
+ entity: entities.system
107
+ }),
108
+ settings: (0, _settings2.createSettingsStorageOperations)({
109
+ entity: entities.settings
110
+ }),
111
+ groups: (0, _group2.createGroupsStorageOperations)({
112
+ entity: entities.groups,
113
+ plugins
114
+ }),
115
+ models: (0, _model2.createModelsStorageOperations)({
116
+ entity: entities.models
117
+ }),
118
+ entries: (0, _entry2.createEntriesStorageOperations)({
119
+ entity: entities.entries,
120
+ plugins
121
+ })
122
+ };
27
123
  };
28
124
 
29
- exports.default = _default;
30
- //# sourceMappingURL=index.js.map
125
+ exports.createStorageOperations = createStorageOperations;
@@ -1,23 +1,38 @@
1
- import { CmsContentEntry, CmsContentModel, CmsContext } from "@webiny/api-headless-cms/types";
2
- import { CmsContentEntryDynamo } from "./CmsContentEntryDynamo";
1
+ import { CmsEntry, CmsModel } from "@webiny/api-headless-cms/types";
2
+ import { Entity } from "dynamodb-toolbox";
3
+ export interface GetAllEntryRevisionsParams {
4
+ ids: readonly string[];
5
+ model: CmsModel;
6
+ }
7
+ export interface GetRevisionByIdParams {
8
+ ids: readonly string[];
9
+ model: CmsModel;
10
+ }
11
+ export interface GetPublishedRevisionByEntryIdParams {
12
+ ids: readonly string[];
13
+ model: CmsModel;
14
+ }
15
+ export interface GetLatestRevisionByEntryIdParams {
16
+ ids: readonly string[];
17
+ model: CmsModel;
18
+ }
19
+ interface ClearLoaderParams {
20
+ model: CmsModel;
21
+ entry?: CmsEntry;
22
+ }
23
+ export interface Params {
24
+ entity: Entity<any>;
25
+ }
3
26
  export declare class DataLoadersHandler {
4
- private readonly _loaders;
5
- private readonly _context;
6
- private readonly _storageOperations;
7
- constructor(context: CmsContext, storageOperations: CmsContentEntryDynamo);
8
- getAllEntryRevisions(model: CmsContentModel, ids: readonly string[]): Promise<CmsContentEntry[]>;
9
- clearAllEntryRevisions(model: CmsContentModel, entry?: CmsContentEntry): void;
10
- getRevisionById(model: CmsContentModel, ids: readonly string[]): Promise<CmsContentEntry[]>;
11
- clearRevisionById(model: CmsContentModel, entry?: CmsContentEntry): void;
12
- getPublishedRevisionByEntryId(model: CmsContentModel, ids: readonly string[]): Promise<CmsContentEntry[]>;
13
- clearPublishedRevisionByEntryId(model: CmsContentModel, entry?: CmsContentEntry): void;
14
- getLatestRevisionByEntryId(model: CmsContentModel, ids: readonly string[]): Promise<CmsContentEntry[]>;
15
- clearLatestRevisionByEntryId(model: CmsContentModel, entry?: CmsContentEntry): void;
27
+ private readonly loaders;
28
+ private readonly entity;
29
+ constructor(params: any);
30
+ getAllEntryRevisions(params: GetAllEntryRevisionsParams): Promise<CmsEntry[]>;
31
+ getRevisionById(params: GetRevisionByIdParams): Promise<CmsEntry[]>;
32
+ getPublishedRevisionByEntryId(params: GetPublishedRevisionByEntryIdParams): Promise<CmsEntry[]>;
33
+ getLatestRevisionByEntryId(params: GetLatestRevisionByEntryIdParams): Promise<CmsEntry[]>;
16
34
  private getLoader;
17
35
  private loadMany;
18
- /**
19
- * Helper to clear the cache for certain data loader.
20
- * If entry is passed then clear target key only.
21
- */
22
- private clear;
36
+ clearAll(params: Omit<ClearLoaderParams, "entry">): void;
23
37
  }
38
+ export {};