@webiny/api-headless-cms-ddb 0.0.0-mt-3 → 0.0.0-unstable.2af142b57e

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 (135) hide show
  1. package/definitions/entry.d.ts +2 -1
  2. package/definitions/entry.js +6 -12
  3. package/definitions/entry.js.map +1 -0
  4. package/definitions/group.d.ts +2 -1
  5. package/definitions/group.js +3 -12
  6. package/definitions/group.js.map +1 -0
  7. package/definitions/model.d.ts +2 -1
  8. package/definitions/model.js +8 -12
  9. package/definitions/model.js.map +1 -0
  10. package/definitions/settings.d.ts +2 -1
  11. package/definitions/settings.js +3 -12
  12. package/definitions/settings.js.map +1 -0
  13. package/definitions/system.d.ts +2 -1
  14. package/definitions/system.js +3 -12
  15. package/definitions/system.js.map +1 -0
  16. package/definitions/table.d.ts +2 -1
  17. package/definitions/table.js +0 -3
  18. package/definitions/table.js.map +1 -0
  19. package/dynamoDb/index.d.ts +1 -1
  20. package/dynamoDb/index.js +6 -17
  21. package/dynamoDb/index.js.map +1 -0
  22. package/dynamoDb/path/plainObject.d.ts +2 -3
  23. package/dynamoDb/path/plainObject.js +25 -25
  24. package/dynamoDb/path/plainObject.js.map +1 -0
  25. package/dynamoDb/storage/date.d.ts +3 -3
  26. package/dynamoDb/storage/date.js +80 -54
  27. package/dynamoDb/storage/date.js.map +1 -0
  28. package/dynamoDb/storage/longText.d.ts +7 -4
  29. package/dynamoDb/storage/longText.js +72 -64
  30. package/dynamoDb/storage/longText.js.map +1 -0
  31. package/dynamoDb/storage/richText.d.ts +2 -8
  32. package/dynamoDb/storage/richText.js +62 -77
  33. package/dynamoDb/storage/richText.js.map +1 -0
  34. package/dynamoDb/transformValue/datetime.d.ts +4 -2
  35. package/dynamoDb/transformValue/datetime.js +28 -30
  36. package/dynamoDb/transformValue/datetime.js.map +1 -0
  37. package/index.d.ts +1 -0
  38. package/index.js +50 -41
  39. package/index.js.map +1 -0
  40. package/operations/entry/dataLoaders.d.ts +12 -8
  41. package/operations/entry/dataLoaders.js +27 -52
  42. package/operations/entry/dataLoaders.js.map +1 -0
  43. package/operations/entry/filtering/createExpressions.d.ts +26 -0
  44. package/operations/entry/filtering/createExpressions.js +176 -0
  45. package/operations/entry/filtering/createExpressions.js.map +1 -0
  46. package/operations/entry/filtering/createFields.d.ts +14 -0
  47. package/operations/entry/filtering/createFields.js +105 -0
  48. package/operations/entry/filtering/createFields.js.map +1 -0
  49. package/operations/entry/filtering/extractSort.d.ts +17 -0
  50. package/operations/entry/filtering/extractSort.js +67 -0
  51. package/operations/entry/filtering/extractSort.js.map +1 -0
  52. package/operations/entry/filtering/filter.d.ts +15 -0
  53. package/operations/entry/filtering/filter.js +143 -0
  54. package/operations/entry/filtering/filter.js.map +1 -0
  55. package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
  56. package/operations/entry/filtering/fullTextSearch.js +48 -0
  57. package/operations/entry/filtering/fullTextSearch.js.map +1 -0
  58. package/operations/entry/filtering/getValue.d.ts +5 -0
  59. package/operations/entry/filtering/getValue.js +63 -0
  60. package/operations/entry/filtering/getValue.js.map +1 -0
  61. package/operations/entry/filtering/index.d.ts +2 -0
  62. package/operations/entry/filtering/index.js +19 -0
  63. package/operations/entry/filtering/index.js.map +1 -0
  64. package/operations/entry/filtering/mapPlugins.d.ts +8 -0
  65. package/operations/entry/filtering/mapPlugins.js +31 -0
  66. package/operations/entry/filtering/mapPlugins.js.map +1 -0
  67. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
  68. package/operations/entry/filtering/plugins/defaultFilterCreate.js +41 -0
  69. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
  70. package/operations/entry/filtering/plugins/index.d.ts +1 -0
  71. package/operations/entry/filtering/plugins/index.js +13 -0
  72. package/operations/entry/filtering/plugins/index.js.map +1 -0
  73. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
  74. package/operations/entry/filtering/plugins/objectFilterCreate.js +86 -0
  75. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
  76. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -0
  77. package/operations/entry/filtering/plugins/refFilterCreate.js +71 -0
  78. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
  79. package/operations/entry/filtering/sort.d.ts +12 -0
  80. package/operations/entry/filtering/sort.js +69 -0
  81. package/operations/entry/filtering/sort.js.map +1 -0
  82. package/operations/entry/filtering/systemFields.d.ts +4 -0
  83. package/operations/entry/filtering/systemFields.js +70 -0
  84. package/operations/entry/filtering/systemFields.js.map +1 -0
  85. package/operations/entry/filtering/transform.d.ts +6 -0
  86. package/operations/entry/filtering/transform.js +16 -0
  87. package/operations/entry/filtering/transform.js.map +1 -0
  88. package/operations/entry/filtering/types.d.ts +40 -0
  89. package/operations/entry/filtering/types.js +5 -0
  90. package/operations/entry/filtering/types.js.map +1 -0
  91. package/operations/entry/filtering/values.d.ts +2 -0
  92. package/operations/entry/filtering/values.js +22 -0
  93. package/operations/entry/filtering/values.js.map +1 -0
  94. package/operations/entry/filtering/where.d.ts +5 -0
  95. package/operations/entry/filtering/where.js +32 -0
  96. package/operations/entry/filtering/where.js.map +1 -0
  97. package/operations/entry/index.d.ts +2 -2
  98. package/operations/entry/index.js +273 -309
  99. package/operations/entry/index.js.map +1 -0
  100. package/operations/entry/keys.js +7 -14
  101. package/operations/entry/keys.js.map +1 -0
  102. package/operations/entry/systemFields.js +24 -2
  103. package/operations/entry/systemFields.js.map +1 -0
  104. package/operations/group/index.d.ts +3 -2
  105. package/operations/group/index.js +9 -45
  106. package/operations/group/index.js.map +1 -0
  107. package/operations/model/index.d.ts +3 -2
  108. package/operations/model/index.js +13 -37
  109. package/operations/model/index.js.map +1 -0
  110. package/operations/settings/index.d.ts +3 -2
  111. package/operations/settings/index.js +7 -37
  112. package/operations/settings/index.js.map +1 -0
  113. package/operations/system/index.d.ts +3 -2
  114. package/operations/system/index.js +5 -28
  115. package/operations/system/index.js.map +1 -0
  116. package/package.json +22 -23
  117. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +22 -0
  118. package/plugins/CmsEntryFieldFilterPathPlugin.js +41 -0
  119. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -0
  120. package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
  121. package/plugins/CmsEntryFieldFilterPlugin.js +24 -0
  122. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
  123. package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
  124. package/plugins/CmsEntryFieldSortingPlugin.js +28 -0
  125. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
  126. package/plugins/index.d.ts +3 -0
  127. package/plugins/index.js +38 -0
  128. package/plugins/index.js.map +1 -0
  129. package/types.d.ts +2 -33
  130. package/types.js +0 -1
  131. package/types.js.map +1 -0
  132. package/dynamoDb/path/ref.d.ts +0 -3
  133. package/dynamoDb/path/ref.js +0 -27
  134. package/operations/entry/utils.d.ts +0 -31
  135. package/operations/entry/utils.js +0 -406
@@ -1,62 +1,50 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createModelsStorageOperations = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
10
  var _get = require("@webiny/db-dynamodb/utils/get");
15
-
16
11
  var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
-
18
12
  var _query = require("@webiny/db-dynamodb/utils/query");
19
-
20
- 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; }
21
-
22
- 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; }
23
-
24
13
  const createPartitionKey = params => {
25
14
  const {
26
15
  tenant,
27
16
  locale
28
17
  } = params;
18
+ if (!tenant) {
19
+ throw new _error.default(`Missing tenant variable when creating model partitionKey.`);
20
+ } else if (!locale) {
21
+ throw new _error.default(`Missing locale variable when creating model partitionKey.`);
22
+ }
29
23
  return `T#${tenant}#L#${locale}#CMS#CM`;
30
24
  };
31
-
32
25
  const createSortKey = params => {
33
26
  return params.modelId;
34
27
  };
35
-
36
28
  const createKeys = params => {
37
29
  return {
38
30
  PK: createPartitionKey(params),
39
31
  SK: createSortKey(params)
40
32
  };
41
33
  };
42
-
43
34
  const createType = () => {
44
35
  return "cms.model";
45
36
  };
46
-
47
37
  const createModelsStorageOperations = params => {
48
38
  const {
49
39
  entity
50
40
  } = params;
51
-
52
41
  const create = async params => {
53
42
  const {
54
43
  model
55
44
  } = params;
56
45
  const keys = createKeys(model);
57
-
58
46
  try {
59
- await entity.put(_objectSpread(_objectSpread(_objectSpread({}, model), keys), {}, {
47
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _cleanup.cleanupItem)(entity, model)), keys), {}, {
60
48
  TYPE: createType()
61
49
  }));
62
50
  return model;
@@ -68,50 +56,42 @@ const createModelsStorageOperations = params => {
68
56
  });
69
57
  }
70
58
  };
71
-
72
59
  const update = async params => {
73
60
  const {
74
- original,
75
61
  model
76
62
  } = params;
77
63
  const keys = createKeys(model);
78
-
79
64
  try {
80
- await entity.put(_objectSpread(_objectSpread(_objectSpread({}, model), keys), {}, {
65
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _cleanup.cleanupItem)(entity, model)), keys), {}, {
81
66
  TYPE: createType()
82
67
  }));
83
68
  return model;
84
69
  } catch (ex) {
85
- throw new _error.default(ex.messatge || "Could not update model.", ex.code || "MODEL_UPDATE_ERROR", {
70
+ throw new _error.default(ex.message || "Could not update model.", ex.code || "MODEL_UPDATE_ERROR", {
86
71
  error: ex,
87
72
  model,
88
- original,
89
73
  keys
90
74
  });
91
75
  }
92
76
  };
93
-
94
77
  const deleteModel = async params => {
95
78
  const {
96
79
  model
97
80
  } = params;
98
81
  const keys = createKeys(model);
99
-
100
82
  try {
101
83
  await entity.delete(keys);
102
84
  return model;
103
85
  } catch (ex) {
104
- throw new _error.default(ex.messatge || "Could not delete model.", ex.code || "MODEL_DELETE_ERROR", {
86
+ throw new _error.default(ex.message || "Could not delete model.", ex.code || "MODEL_DELETE_ERROR", {
105
87
  error: ex,
106
88
  model,
107
89
  keys
108
90
  });
109
91
  }
110
92
  };
111
-
112
93
  const get = async params => {
113
94
  const keys = createKeys(params);
114
-
115
95
  try {
116
96
  const item = await (0, _get.get)({
117
97
  entity,
@@ -119,13 +99,12 @@ const createModelsStorageOperations = params => {
119
99
  });
120
100
  return (0, _cleanup.cleanupItem)(entity, item);
121
101
  } catch (ex) {
122
- throw new _error.default(ex.messatge || "Could not get model.", ex.code || "MODEL_GET_ERROR", {
102
+ throw new _error.default(ex.message || "Could not get model.", ex.code || "MODEL_GET_ERROR", {
123
103
  error: ex,
124
104
  keys
125
105
  });
126
106
  }
127
107
  };
128
-
129
108
  const list = async params => {
130
109
  const {
131
110
  where
@@ -137,18 +116,16 @@ const createModelsStorageOperations = params => {
137
116
  gte: " "
138
117
  }
139
118
  };
140
-
141
119
  try {
142
120
  const items = await (0, _query.queryAll)(queryAllParams);
143
121
  return (0, _cleanup.cleanupItems)(entity, items);
144
122
  } catch (ex) {
145
- throw new _error.default(ex.messatge || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
123
+ throw new _error.default(ex.message || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
146
124
  error: ex,
147
125
  partitionKey: queryAllParams.partitionKey
148
126
  });
149
127
  }
150
128
  };
151
-
152
129
  return {
153
130
  create,
154
131
  update,
@@ -157,5 +134,4 @@ const createModelsStorageOperations = params => {
157
134
  list
158
135
  };
159
136
  };
160
-
161
137
  exports.createModelsStorageOperations = createModelsStorageOperations;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createPartitionKey","params","tenant","locale","WebinyError","createSortKey","modelId","createKeys","PK","SK","createType","createModelsStorageOperations","entity","create","model","keys","put","cleanupItem","TYPE","ex","error","update","message","code","deleteModel","delete","get","item","getRecord","list","where","queryAllParams","partitionKey","options","gte","items","queryAll","cleanupItems"],"sources":["index.ts"],"sourcesContent":["import {\n CmsModel,\n CmsModelStorageOperations,\n CmsModelStorageOperationsCreateParams,\n CmsModelStorageOperationsDeleteParams,\n CmsModelStorageOperationsGetParams,\n CmsModelStorageOperationsListParams,\n CmsModelStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport { get as getRecord } from \"@webiny/db-dynamodb/utils/get\";\nimport { cleanupItem, cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\n\ninterface PartitionKeysParams {\n tenant: string;\n locale: string;\n}\nconst createPartitionKey = (params: PartitionKeysParams): string => {\n const { tenant, locale } = params;\n if (!tenant) {\n throw new WebinyError(`Missing tenant variable when creating model partitionKey.`);\n } else if (!locale) {\n throw new WebinyError(`Missing locale variable when creating model partitionKey.`);\n }\n return `T#${tenant}#L#${locale}#CMS#CM`;\n};\n\ninterface SortKeyParams {\n modelId: string;\n}\nconst createSortKey = (params: SortKeyParams): string => {\n return params.modelId;\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeysParams & SortKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey(params)\n };\n};\n\nconst createType = (): string => {\n return \"cms.model\";\n};\n\ninterface CreateModelsStorageOperationsParams {\n entity: Entity<any>;\n}\nexport const createModelsStorageOperations = (\n params: CreateModelsStorageOperationsParams\n): CmsModelStorageOperations => {\n const { entity } = params;\n\n const create = async (params: CmsModelStorageOperationsCreateParams) => {\n const { model } = params;\n\n const keys = createKeys(model);\n\n try {\n await entity.put({\n ...cleanupItem(entity, model),\n ...keys,\n TYPE: createType()\n });\n return model;\n } catch (ex) {\n throw new WebinyError(`Could not create CMS Content Model.`, \"CREATE_MODEL_ERROR\", {\n error: ex,\n model,\n keys\n });\n }\n };\n\n const update = async (params: CmsModelStorageOperationsUpdateParams) => {\n const { model } = params;\n\n const keys = createKeys(model);\n\n try {\n await entity.put({\n ...cleanupItem(entity, model),\n ...keys,\n TYPE: createType()\n });\n return model;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update model.\",\n ex.code || \"MODEL_UPDATE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n };\n\n const deleteModel = async (params: CmsModelStorageOperationsDeleteParams) => {\n const { model } = params;\n const keys = createKeys(model);\n\n try {\n await entity.delete(keys);\n return model;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete model.\",\n ex.code || \"MODEL_DELETE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n };\n\n const get = async (params: CmsModelStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const item = await getRecord<CmsModel>({\n entity,\n keys\n });\n return cleanupItem(entity, item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get model.\",\n ex.code || \"MODEL_GET_ERROR\",\n {\n error: ex,\n keys\n }\n );\n }\n };\n\n const list = async (params: CmsModelStorageOperationsListParams) => {\n const { where } = params;\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey(where),\n options: {\n gte: \" \"\n }\n };\n try {\n const items = await queryAll<CmsModel>(queryAllParams);\n\n return cleanupItems(entity, items);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list models.\",\n ex.code || \"MODEL_LIST_ERROR\",\n {\n error: ex,\n partitionKey: queryAllParams.partitionKey\n }\n );\n }\n };\n\n return {\n create,\n update,\n delete: deleteModel,\n get,\n list\n };\n};\n"],"mappings":";;;;;;;;AAUA;AACA;AACA;AACA;AAMA,MAAMA,kBAAkB,GAAIC,MAA2B,IAAa;EAChE,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGF,MAAM;EACjC,IAAI,CAACC,MAAM,EAAE;IACT,MAAM,IAAIE,cAAW,CAAE,2DAA0D,CAAC;EACtF,CAAC,MAAM,IAAI,CAACD,MAAM,EAAE;IAChB,MAAM,IAAIC,cAAW,CAAE,2DAA0D,CAAC;EACtF;EACA,OAAQ,KAAIF,MAAO,MAAKC,MAAO,SAAQ;AAC3C,CAAC;AAKD,MAAME,aAAa,GAAIJ,MAAqB,IAAa;EACrD,OAAOA,MAAM,CAACK,OAAO;AACzB,CAAC;AAMD,MAAMC,UAAU,GAAIN,MAA2C,IAAW;EACtE,OAAO;IACHO,EAAE,EAAER,kBAAkB,CAACC,MAAM,CAAC;IAC9BQ,EAAE,EAAEJ,aAAa,CAACJ,MAAM;EAC5B,CAAC;AACL,CAAC;AAED,MAAMS,UAAU,GAAG,MAAc;EAC7B,OAAO,WAAW;AACtB,CAAC;AAKM,MAAMC,6BAA6B,GACtCV,MAA2C,IACf;EAC5B,MAAM;IAAEW;EAAO,CAAC,GAAGX,MAAM;EAEzB,MAAMY,MAAM,GAAG,MAAOZ,MAA6C,IAAK;IACpE,MAAM;MAAEa;IAAM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CAAC;EAED,OAAO;IACHnB,MAAM;IACNQ,MAAM;IACNI,MAAM,EAAED,WAAW;IACnBE,GAAG;IACHG;EACJ,CAAC;AACL,CAAC;AAAC"}
@@ -1,6 +1,7 @@
1
1
  import { CmsSettingsStorageOperations } from "@webiny/api-headless-cms/types";
2
2
  import { Entity } from "dynamodb-toolbox";
3
- export interface Params {
3
+ interface CreateSettingsStorageOperationsParams {
4
4
  entity: Entity<any>;
5
5
  }
6
- export declare const createSettingsStorageOperations: (params: Params) => CmsSettingsStorageOperations;
6
+ export declare const createSettingsStorageOperations: (params: CreateSettingsStorageOperationsParams) => CmsSettingsStorageOperations;
7
+ export {};
@@ -1,80 +1,60 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createSettingsStorageOperations = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
9
  var _get = require("@webiny/db-dynamodb/utils/get");
13
-
14
10
  var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
11
  var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
-
18
- 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; }
19
-
20
- 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; }
21
-
22
12
  const convertToDbData = settings => {
23
- return _objectSpread(_objectSpread({}, settings), {}, {
13
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), {}, {
24
14
  contentModelLastChange: settings.contentModelLastChange.toISOString()
25
15
  });
26
16
  };
27
-
28
17
  const convertFromDbData = settings => {
29
18
  if (!settings) {
30
19
  return null;
31
20
  }
32
-
33
21
  let contentModelLastChange;
34
-
35
22
  try {
36
23
  contentModelLastChange = new Date(settings.contentModelLastChange);
37
24
  } catch {
38
25
  contentModelLastChange = new Date();
39
26
  }
40
-
41
- return _objectSpread(_objectSpread({}, settings), {}, {
27
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), {}, {
42
28
  contentModelLastChange
43
29
  });
44
30
  };
45
-
46
31
  const createPartitionKey = ({
47
32
  tenant,
48
33
  locale
49
34
  }) => {
50
35
  return `T#${tenant}#L#${locale}#CMS#SETTINGS`;
51
36
  };
52
-
53
37
  const createSortKey = () => {
54
38
  return "settings";
55
39
  };
56
-
57
40
  const createKeys = params => {
58
41
  return {
59
42
  PK: createPartitionKey(params),
60
43
  SK: createSortKey()
61
44
  };
62
45
  };
63
-
64
46
  const createSettingsStorageOperations = params => {
65
47
  const {
66
48
  entity
67
49
  } = params;
68
-
69
50
  const create = async params => {
70
51
  const {
71
52
  settings
72
53
  } = params;
73
54
  const keys = createKeys(settings);
74
55
  const dbSettings = convertToDbData(settings);
75
-
76
56
  try {
77
- await entity.put(_objectSpread(_objectSpread({}, dbSettings), keys));
57
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, dbSettings), keys));
78
58
  return settings;
79
59
  } catch (ex) {
80
60
  throw new _error.default(ex.message || "Could not create settings.", ex.code || "CREATE_SETTINGS_ERROR", {
@@ -85,42 +65,34 @@ const createSettingsStorageOperations = params => {
85
65
  });
86
66
  }
87
67
  };
88
-
89
68
  const update = async params => {
90
69
  const {
91
- settings,
92
- original
70
+ settings
93
71
  } = params;
94
72
  const keys = createKeys(settings);
95
73
  const dbSettings = convertToDbData(settings);
96
-
97
74
  try {
98
- await entity.put(_objectSpread(_objectSpread({}, dbSettings), keys));
75
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, dbSettings), keys));
99
76
  return settings;
100
77
  } catch (ex) {
101
78
  throw new _error.default(ex.message || "Could not update settings.", ex.code || "UPDATE_SETTINGS_ERROR", {
102
79
  error: ex,
103
80
  settings,
104
81
  dbSettings,
105
- original,
106
82
  keys
107
83
  });
108
84
  }
109
85
  };
110
-
111
86
  const get = async params => {
112
87
  const keys = createKeys(params);
113
-
114
88
  try {
115
89
  const record = await (0, _get.get)({
116
90
  entity,
117
91
  keys
118
92
  });
119
-
120
93
  if (!record) {
121
94
  return null;
122
95
  }
123
-
124
96
  const settings = (0, _cleanup.cleanupItem)(entity, record);
125
97
  return convertFromDbData(settings);
126
98
  } catch (ex) {
@@ -130,12 +102,10 @@ const createSettingsStorageOperations = params => {
130
102
  });
131
103
  }
132
104
  };
133
-
134
105
  return {
135
106
  create,
136
107
  get,
137
108
  update
138
109
  };
139
110
  };
140
-
141
111
  exports.createSettingsStorageOperations = createSettingsStorageOperations;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["convertToDbData","settings","contentModelLastChange","toISOString","convertFromDbData","Date","createPartitionKey","tenant","locale","createSortKey","createKeys","params","PK","SK","createSettingsStorageOperations","entity","create","keys","dbSettings","put","ex","WebinyError","message","code","error","update","get","record","getRecord","cleanupItem"],"sources":["index.ts"],"sourcesContent":["import {\n CmsSettings,\n CmsSettingsStorageOperations,\n CmsSettingsStorageOperationsCreateParams,\n CmsSettingsStorageOperationsGetParams,\n CmsSettingsStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { get as getRecord } from \"@webiny/db-dynamodb/utils/get\";\nimport WebinyError from \"@webiny/error\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\n\ninterface CmsSettingsDb extends Omit<CmsSettings, \"contentModelLastChange\"> {\n contentModelLastChange: string;\n}\n\nconst convertToDbData = (settings: CmsSettings): CmsSettingsDb => {\n return {\n ...settings,\n contentModelLastChange: settings.contentModelLastChange.toISOString()\n };\n};\n\nconst convertFromDbData = (settings?: CmsSettingsDb): CmsSettings | null => {\n if (!settings) {\n return null;\n }\n let contentModelLastChange;\n try {\n contentModelLastChange = new Date(settings.contentModelLastChange);\n } catch {\n contentModelLastChange = new Date();\n }\n return {\n ...settings,\n contentModelLastChange\n };\n};\n\ninterface PartitionKeyParams {\n tenant: string;\n locale: string;\n}\n\nconst createPartitionKey = ({ tenant, locale }: PartitionKeyParams): string => {\n return `T#${tenant}#L#${locale}#CMS#SETTINGS`;\n};\n\nconst createSortKey = (): string => {\n return \"settings\";\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey()\n };\n};\n\ninterface CreateSettingsStorageOperationsParams {\n entity: Entity<any>;\n}\n\nexport const createSettingsStorageOperations = (\n params: CreateSettingsStorageOperationsParams\n): CmsSettingsStorageOperations => {\n const { entity } = params;\n\n const create = async (params: CmsSettingsStorageOperationsCreateParams) => {\n const { settings } = params;\n const keys = createKeys(settings);\n\n const dbSettings: CmsSettingsDb = convertToDbData(settings);\n\n try {\n await entity.put({\n ...dbSettings,\n ...keys\n });\n return settings;\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 settings,\n dbSettings,\n keys\n }\n );\n }\n };\n\n const update = async (params: CmsSettingsStorageOperationsUpdateParams) => {\n const { settings } = params;\n\n const keys = createKeys(settings);\n\n const dbSettings: CmsSettingsDb = convertToDbData(settings);\n\n try {\n await entity.put({\n ...dbSettings,\n ...keys\n });\n return settings;\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 settings,\n dbSettings,\n keys\n }\n );\n }\n };\n\n const get = async (params: CmsSettingsStorageOperationsGetParams) => {\n const keys = createKeys(params);\n try {\n const record = await getRecord<CmsSettingsDb>({\n entity,\n keys\n });\n if (!record) {\n return null;\n }\n const settings = cleanupItem(entity, record) as CmsSettingsDb;\n return convertFromDbData(settings);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get settings.\",\n ex.code || \"GET_SETTINGS_ERROR\",\n {\n error: ex,\n keys\n }\n );\n }\n };\n\n return {\n create,\n get,\n update\n };\n};\n"],"mappings":";;;;;;;;AAQA;AACA;AACA;AAMA,MAAMA,eAAe,GAAIC,QAAqB,IAAoB;EAC9D,mEACOA,QAAQ;IACXC,sBAAsB,EAAED,QAAQ,CAACC,sBAAsB,CAACC,WAAW;EAAE;AAE7E,CAAC;AAED,MAAMC,iBAAiB,GAAIH,QAAwB,IAAyB;EACxE,IAAI,CAACA,QAAQ,EAAE;IACX,OAAO,IAAI;EACf;EACA,IAAIC,sBAAsB;EAC1B,IAAI;IACAA,sBAAsB,GAAG,IAAIG,IAAI,CAACJ,QAAQ,CAACC,sBAAsB,CAAC;EACtE,CAAC,CAAC,MAAM;IACJA,sBAAsB,GAAG,IAAIG,IAAI,EAAE;EACvC;EACA,mEACOJ,QAAQ;IACXC;EAAsB;AAE9B,CAAC;AAOD,MAAMI,kBAAkB,GAAG,CAAC;EAAEC,MAAM;EAAEC;AAA2B,CAAC,KAAa;EAC3E,OAAQ,KAAID,MAAO,MAAKC,MAAO,eAAc;AACjD,CAAC;AAED,MAAMC,aAAa,GAAG,MAAc;EAChC,OAAO,UAAU;AACrB,CAAC;AAMD,MAAMC,UAAU,GAAIC,MAA0B,IAAW;EACrD,OAAO;IACHC,EAAE,EAAEN,kBAA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CAAC;EAED,MAAMS,GAAG,GAAG,MAAOf,MAA6C,IAAK;IACjE,MAAMM,IAAI,GAAGP,UAAU,CAACC,MAAM,CAAC;IAC/B,IAAI;MACA,MAAMgB,MAAM,GAAG,MAAM,IAAAC,QAAS,EAAgB;QAC1Cb,MAAM;QACNE;MACJ,CAAC,CAAC;MACF,IAAI,CAACU,MAAM,EAAE;QACT,OAAO,IAAI;MACf;MACA,MAAM1B,QAAQ,GAAG,IAAA4B,oBAAW,EAACd,MAAM,EAAEY,MAAM,CAAkB;MAC7D,OAAOvB,iBAAiB,CAACH,QAAQ,CAAC;IACtC,CAAC,CAAC,OAAOmB,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,yBAAyB,EACvCF,EAAE,CAACG,IAAI,IAAI,oBAAoB,EAC/B;QACIC,KAAK,EAAEJ,EAAE;QACTH;MACJ,CAAC,CACJ;IACL;EACJ,CAAC;EAED,OAAO;IACHD,MAAM;IACNU,GAAG;IACHD;EACJ,CAAC;AACL,CAAC;AAAC"}
@@ -1,6 +1,7 @@
1
1
  import { CmsSystemStorageOperations } from "@webiny/api-headless-cms/types";
2
2
  import { Entity } from "dynamodb-toolbox";
3
- export interface Params {
3
+ interface CreateSystemStorageOperationsParams {
4
4
  entity: Entity<any>;
5
5
  }
6
- export declare const createSystemStorageOperations: (params: Params) => CmsSystemStorageOperations;
6
+ export declare const createSystemStorageOperations: (params: CreateSystemStorageOperationsParams) => CmsSystemStorageOperations;
7
+ export {};
@@ -1,53 +1,38 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createSystemStorageOperations = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
10
  var _get = require("@webiny/db-dynamodb/utils/get");
15
-
16
11
  var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
-
18
- 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; }
19
-
20
- 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; }
21
-
22
12
  const createPartitionKey = ({
23
13
  tenant
24
14
  }) => {
25
15
  return `T#${tenant.toLowerCase()}#SYSTEM`;
26
16
  };
27
-
28
17
  const createSortKey = () => {
29
18
  return "CMS";
30
19
  };
31
-
32
20
  const createKeys = params => {
33
21
  return {
34
22
  PK: createPartitionKey(params),
35
23
  SK: createSortKey()
36
24
  };
37
25
  };
38
-
39
26
  const createSystemStorageOperations = params => {
40
27
  const {
41
28
  entity
42
29
  } = params;
43
-
44
30
  const create = async ({
45
31
  system
46
32
  }) => {
47
33
  const keys = createKeys(system);
48
-
49
34
  try {
50
- await entity.put(_objectSpread(_objectSpread({}, system), keys));
35
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
51
36
  return system;
52
37
  } catch (ex) {
53
38
  throw new _error.default(ex.message || "Could not create system.", ex.code || "CREATE_SYSTEM_ERROR", {
@@ -57,30 +42,24 @@ const createSystemStorageOperations = params => {
57
42
  });
58
43
  }
59
44
  };
60
-
61
45
  const update = async params => {
62
46
  const {
63
- system,
64
- original
47
+ system
65
48
  } = params;
66
49
  const keys = createKeys(system);
67
-
68
50
  try {
69
- await entity.put(_objectSpread(_objectSpread({}, system), keys));
51
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
70
52
  return system;
71
53
  } catch (ex) {
72
54
  throw new _error.default(ex.message || "Could not update system.", ex.code || "UPDATE_SYSTEM_ERROR", {
73
55
  error: ex,
74
56
  system,
75
- original,
76
57
  keys
77
58
  });
78
59
  }
79
60
  };
80
-
81
61
  const get = async params => {
82
62
  const keys = createKeys(params);
83
-
84
63
  try {
85
64
  const system = await (0, _get.get)({
86
65
  entity,
@@ -94,12 +73,10 @@ const createSystemStorageOperations = params => {
94
73
  });
95
74
  }
96
75
  };
97
-
98
76
  return {
99
77
  create,
100
78
  update,
101
79
  get
102
80
  };
103
81
  };
104
-
105
82
  exports.createSystemStorageOperations = createSystemStorageOperations;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createPartitionKey","tenant","toLowerCase","createSortKey","createKeys","params","PK","SK","createSystemStorageOperations","entity","create","system","keys","put","ex","WebinyError","message","code","error","update","get","getRecord","cleanupItem"],"sources":["index.ts"],"sourcesContent":["import {\n CmsSystem,\n CmsSystemStorageOperations,\n CmsSystemStorageOperationsCreateParams,\n CmsSystemStorageOperationsGetParams,\n CmsSystemStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport { get as getRecord } from \"@webiny/db-dynamodb/utils/get\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\n\ninterface CreateSystemStorageOperationsParams {\n entity: Entity<any>;\n}\n\ninterface PartitionKeyParams {\n tenant: string;\n}\nconst createPartitionKey = ({ tenant }: PartitionKeyParams): string => {\n return `T#${tenant.toLowerCase()}#SYSTEM`;\n};\nconst createSortKey = (): string => {\n return \"CMS\";\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey()\n };\n};\n\nexport const createSystemStorageOperations = (\n params: CreateSystemStorageOperationsParams\n): CmsSystemStorageOperations => {\n const { entity } = params;\n\n const create = async ({ system }: CmsSystemStorageOperationsCreateParams) => {\n const keys = createKeys(system);\n try {\n await entity.put({\n ...system,\n ...keys\n });\n return system;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create system.\",\n ex.code || \"CREATE_SYSTEM_ERROR\",\n {\n error: ex,\n system,\n keys\n }\n );\n }\n };\n\n const update = async (params: CmsSystemStorageOperationsUpdateParams) => {\n const { system } = params;\n\n const keys = createKeys(system);\n\n try {\n await entity.put({\n ...system,\n ...keys\n });\n return system;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update system.\",\n ex.code || \"UPDATE_SYSTEM_ERROR\",\n {\n error: ex,\n system,\n keys\n }\n );\n }\n };\n\n const get = async (params: CmsSystemStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const system = await getRecord<CmsSystem>({\n entity,\n keys\n });\n return cleanupItem(entity, system);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get system.\",\n ex.code || \"GET_SYSTEM_ERROR\",\n {\n error: ex,\n keys\n }\n );\n }\n };\n\n return {\n create,\n update,\n get\n };\n};\n"],"mappings":";;;;;;;;AAQA;AACA;AACA;AASA,MAAMA,kBAAkB,GAAG,CAAC;EAAEC;AAA2B,CAAC,KAAa;EACnE,OAAQ,KAAIA,MAAM,CAACC,WAAW,EAAG,SAAQ;AAC7C,CAAC;AACD,MAAMC,aAAa,GAAG,MAAc;EAChC,OAAO,KAAK;AAChB,CAAC;AAMD,MAAMC,UAAU,GAAIC,MAA0B,IAAW;EACrD,OAAO;IACHC,EAAE,EAAEN,kBAAkB,CAACK,MAAM,CAAC;IAC9BE,EAAE,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W,EAACb,MAAM,EAAEE,MAAM,CAAC;IACtC,CAAC,CAAC,OAAOG,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,uBAAuB,EACrCF,EAAE,CAACG,IAAI,IAAI,kBAAkB,EAC7B;QACIC,KAAK,EAAEJ,EAAE;QACTF;MACJ,CAAC,CACJ;IACL;EACJ,CAAC;EAED,OAAO;IACHF,MAAM;IACNS,MAAM;IACNC;EACJ,CAAC;AACL,CAAC;AAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms-ddb",
3
- "version": "0.0.0-mt-3",
3
+ "version": "0.0.0-unstable.2af142b57e",
4
4
  "main": "index.js",
5
5
  "keywords": [
6
6
  "@webiny/api-headless-cms",
@@ -21,33 +21,32 @@
21
21
  ],
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@babel/runtime": "7.15.4",
25
- "@webiny/api-headless-cms": "0.0.0-mt-3",
26
- "@webiny/db-dynamodb": "0.0.0-mt-3",
27
- "@webiny/error": "0.0.0-mt-3",
28
- "@webiny/handler-db": "0.0.0-mt-3",
29
- "@webiny/utils": "0.0.0-mt-3",
30
- "aws-sdk": "2.1026.0",
31
- "dataloader": "2.0.0",
32
- "dot-prop": "5.3.0",
33
- "dynamodb-toolbox": "0.3.4",
24
+ "@babel/runtime": "7.20.13",
25
+ "@webiny/api-headless-cms": "0.0.0-unstable.2af142b57e",
26
+ "@webiny/db-dynamodb": "0.0.0-unstable.2af142b57e",
27
+ "@webiny/error": "0.0.0-unstable.2af142b57e",
28
+ "@webiny/handler-db": "0.0.0-unstable.2af142b57e",
29
+ "@webiny/utils": "0.0.0-unstable.2af142b57e",
30
+ "aws-sdk": "2.1310.0",
31
+ "dataloader": "2.2.1",
32
+ "dot-prop": "6.0.1",
33
+ "dynamodb-toolbox": "0.3.5",
34
34
  "jsonpack": "1.1.5",
35
- "lodash.sortby": "4.7.0"
35
+ "lodash": "4.17.21"
36
36
  },
37
37
  "devDependencies": {
38
- "@babel/cli": "^7.5.5",
39
- "@babel/core": "^7.5.5",
40
- "@babel/preset-env": "^7.5.5",
41
- "@babel/preset-flow": "^7.0.0",
38
+ "@babel/cli": "^7.19.3",
39
+ "@babel/core": "^7.19.3",
40
+ "@babel/preset-env": "^7.19.4",
42
41
  "@types/jsonpack": "^1.1.0",
43
- "@webiny/cli": "^0.0.0-mt-3",
44
- "@webiny/plugins": "^0.0.0-mt-3",
45
- "@webiny/project-utils": "^0.0.0-mt-3",
46
- "jest": "^26.6.3",
42
+ "@webiny/cli": "^0.0.0-unstable.2af142b57e",
43
+ "@webiny/plugins": "^0.0.0-unstable.2af142b57e",
44
+ "@webiny/project-utils": "^0.0.0-unstable.2af142b57e",
45
+ "jest": "^28.1.0",
47
46
  "jest-dynalite": "^3.2.0",
48
- "jest-environment-node": "^26.6.2",
47
+ "jest-environment-node": "^27.2.4",
49
48
  "ttypescript": "^1.5.12",
50
- "typescript": "^4.1.3"
49
+ "typescript": "4.7.4"
51
50
  },
52
51
  "publishConfig": {
53
52
  "access": "public",
@@ -57,5 +56,5 @@
57
56
  "build": "yarn webiny run build",
58
57
  "watch": "yarn webiny run watch"
59
58
  },
60
- "gitHead": "ebea815be2be99404591cba465cc1fe88355bd48"
59
+ "gitHead": "2af142b57e7cdc433f5098b3b6d43ae6caa5d54e"
61
60
  }
@@ -0,0 +1,22 @@
1
+ import { Plugin } from "@webiny/plugins/Plugin";
2
+ import { CmsModelField } from "@webiny/api-headless-cms/types";
3
+ export interface CreatePathCallableParams {
4
+ field: Partial<CmsModelField> & Pick<CmsModelField, "fieldId" | "storageId" | "id">;
5
+ index?: number;
6
+ }
7
+ export interface CreatePathCallable {
8
+ (params: CreatePathCallableParams): string;
9
+ }
10
+ export interface CmsEntryFieldFilterPathPluginParams {
11
+ fieldType: string;
12
+ fieldId?: string[];
13
+ path: string | CreatePathCallable;
14
+ }
15
+ export declare class CmsEntryFieldFilterPathPlugin extends Plugin {
16
+ static readonly type: string;
17
+ private readonly config;
18
+ get fieldType(): string;
19
+ constructor(config: CmsEntryFieldFilterPathPluginParams);
20
+ canUse(field: Pick<CmsModelField, "fieldId" | "type">): boolean;
21
+ createPath(params: CreatePathCallableParams): string;
22
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.CmsEntryFieldFilterPathPlugin = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _error = _interopRequireDefault(require("@webiny/error"));
10
+ var _Plugin = require("@webiny/plugins/Plugin");
11
+ class CmsEntryFieldFilterPathPlugin extends _Plugin.Plugin {
12
+ get fieldType() {
13
+ return this.config.fieldType;
14
+ }
15
+ constructor(config) {
16
+ super();
17
+ (0, _defineProperty2.default)(this, "config", void 0);
18
+ this.config = config;
19
+ this.name = `${this.constructor.type}-${this.config.fieldType}`;
20
+ }
21
+ canUse(field) {
22
+ if (field.type !== this.config.fieldType) {
23
+ return false;
24
+ }
25
+ const fieldId = this.config.fieldId;
26
+ if (!fieldId || Array.isArray(fieldId) === false || fieldId.length === 0) {
27
+ return true;
28
+ }
29
+ return fieldId.includes(field.fieldId);
30
+ }
31
+ createPath(params) {
32
+ if (typeof this.config.path === "function") {
33
+ return this.config.path(params);
34
+ } else if (typeof this.config.path === "string") {
35
+ return this.config.path;
36
+ }
37
+ throw new _error.default(`Missing path in "${this.name}" plugin.`);
38
+ }
39
+ }
40
+ exports.CmsEntryFieldFilterPathPlugin = CmsEntryFieldFilterPathPlugin;
41
+ (0, _defineProperty2.default)(CmsEntryFieldFilterPathPlugin, "type", "cms-field-filter-path");
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CmsEntryFieldFilterPathPlugin","Plugin","fieldType","config","constructor","name","type","canUse","field","fieldId","Array","isArray","length","includes","createPath","params","path","WebinyError"],"sources":["CmsEntryFieldFilterPathPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\n\nexport interface CreatePathCallableParams {\n field: Partial<CmsModelField> & Pick<CmsModelField, \"fieldId\" | \"storageId\" | \"id\">;\n index?: number;\n}\nexport interface CreatePathCallable {\n (params: CreatePathCallableParams): string;\n}\nexport interface CmsEntryFieldFilterPathPluginParams {\n fieldType: string;\n fieldId?: string[];\n path: string | CreatePathCallable;\n}\nexport class CmsEntryFieldFilterPathPlugin extends Plugin {\n public static override readonly type: string = \"cms-field-filter-path\";\n\n private readonly config: CmsEntryFieldFilterPathPluginParams;\n\n public get fieldType(): string {\n return this.config.fieldType;\n }\n\n public constructor(config: CmsEntryFieldFilterPathPluginParams) {\n super();\n\n this.config = config;\n\n this.name = `${(this.constructor as any).type}-${this.config.fieldType}`;\n }\n\n public canUse(field: Pick<CmsModelField, \"fieldId\" | \"type\">): boolean {\n if (field.type !== this.config.fieldType) {\n return false;\n }\n const fieldId = this.config.fieldId;\n if (!fieldId || Array.isArray(fieldId) === false || fieldId.length === 0) {\n return true;\n }\n return fieldId.includes(field.fieldId);\n }\n\n public createPath(params: CreatePathCallableParams): string {\n if (typeof this.config.path === \"function\") {\n return this.config.path(params);\n } else if (typeof this.config.path === \"string\") {\n return this.config.path;\n }\n throw new WebinyError(`Missing path in \"${this.name}\" plugin.`);\n }\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AAeO,MAAMA,6BAA6B,SAASC,cAAM,CAAC;EAKtD,IAAWC,SAAS,GAAW;IAC3B,OAAO,IAAI,CAACC,MAAM,CAACD,SAAS;EAChC;EAEOE,WAAW,CAACD,MAA2C,EAAE;IAC5D,KAAK,EAAE;IAAC;IAER,IAAI,CAACA,MAAM,GAAGA,MAAM;IAEpB,IAAI,CAACE,IAAI,GAAI,GAAG,IAAI,CAACD,WAAW,CAASE,IAAK,IAAG,IAAI,CAACH,MAAM,CAACD,SAAU,EAAC;EAC5E;EAEOK,MAAM,CAACC,KAA8C,EAAW;IACnE,IAAIA,KAAK,CAACF,IAAI,KAAK,IAAI,CAACH,MAAM,CAACD,SAAS,EAAE;MACtC,OAAO,KAAK;IAChB;IACA,MAAMO,OAAO,GAAG,IAAI,CAACN,MAAM,CAACM,OAAO;IACnC,IAAI,CAACA,OAAO,IAAIC,KAAK,CAACC,OAAO,CAACF,OAAO,CAAC,KAAK,KAAK,IAAIA,OAAO,CAACG,MAAM,KAAK,CAAC,EAAE;MACtE,OAAO,IAAI;IACf;IACA,OAAOH,OAAO,CAACI,QAAQ,CAACL,KAAK,CAACC,OAAO,CAAC;EAC1C;EAEOK,UAAU,CAACC,MAAgC,EAAU;IACxD,IAAI,OAAO,IAAI,CAACZ,MAAM,CAACa,IAAI,KAAK,UAAU,EAAE;MACxC,OAAO,IAAI,CAACb,MAAM,CAACa,IAAI,CAACD,MAAM,CAAC;IACnC,CAAC,MAAM,IAAI,OAAO,IAAI,CAACZ,MAAM,CAACa,IAAI,KAAK,QAAQ,EAAE;MAC7C,OAAO,IAAI,CAACb,MAAM,CAACa,IAAI;IAC3B;IACA,MAAM,IAAIC,cAAW,CAAE,oBAAmB,IAAI,CAACZ,IAAK,WAAU,CAAC;EACnE;AACJ;AAAC;AAAA,8BApCYL,6BAA6B,UACS,uBAAuB"}