@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.
Files changed (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/configurations.d.ts +18 -0
  4. package/configurations.js +24 -0
  5. package/configurations.js.map +1 -0
  6. package/definitions/entry.d.ts +6 -0
  7. package/definitions/entry.js +86 -0
  8. package/definitions/entry.js.map +1 -0
  9. package/definitions/table.d.ts +14 -0
  10. package/definitions/table.js +30 -0
  11. package/definitions/table.js.map +1 -0
  12. package/dynamoDb/index.d.ts +2 -0
  13. package/dynamoDb/index.js +23 -0
  14. package/dynamoDb/index.js.map +1 -0
  15. package/dynamoDb/path/plainObject.d.ts +3 -0
  16. package/dynamoDb/path/plainObject.js +34 -0
  17. package/dynamoDb/path/plainObject.js.map +1 -0
  18. package/dynamoDb/path/ref.d.ts +3 -0
  19. package/dynamoDb/path/ref.js +28 -0
  20. package/dynamoDb/path/ref.js.map +1 -0
  21. package/dynamoDb/storage/date.d.ts +3 -0
  22. package/dynamoDb/storage/date.js +69 -0
  23. package/dynamoDb/storage/date.js.map +1 -0
  24. package/dynamoDb/storage/richText.d.ts +8 -0
  25. package/dynamoDb/storage/richText.js +108 -0
  26. package/dynamoDb/storage/richText.js.map +1 -0
  27. package/dynamoDb/transformValue/datetime.d.ts +3 -0
  28. package/dynamoDb/transformValue/datetime.js +48 -0
  29. package/dynamoDb/transformValue/datetime.js.map +1 -0
  30. package/index.d.ts +6 -0
  31. package/index.js +30 -0
  32. package/index.js.map +1 -0
  33. package/operations/entry/CmsContentEntryDynamo.d.ts +86 -0
  34. package/operations/entry/CmsContentEntryDynamo.js +972 -0
  35. package/operations/entry/CmsContentEntryDynamo.js.map +1 -0
  36. package/operations/entry/dataLoaders.d.ts +23 -0
  37. package/operations/entry/dataLoaders.js +283 -0
  38. package/operations/entry/dataLoaders.js.map +1 -0
  39. package/operations/entry/index.d.ts +4 -0
  40. package/operations/entry/index.js +25 -0
  41. package/operations/entry/index.js.map +1 -0
  42. package/operations/entry/systemFields.d.ts +2 -0
  43. package/operations/entry/systemFields.js +51 -0
  44. package/operations/entry/systemFields.js.map +1 -0
  45. package/operations/entry/utils.d.ts +26 -0
  46. package/operations/entry/utils.js +362 -0
  47. package/operations/entry/utils.js.map +1 -0
  48. package/operations/helpers.d.ts +5 -0
  49. package/operations/helpers.js +96 -0
  50. package/operations/helpers.js.map +1 -0
  51. package/operations/model/CmsContentModelDynamo.d.ts +18 -0
  52. package/operations/model/CmsContentModelDynamo.js +234 -0
  53. package/operations/model/CmsContentModelDynamo.js.map +1 -0
  54. package/operations/model/index.d.ts +3 -0
  55. package/operations/model/index.js +26 -0
  56. package/operations/model/index.js.map +1 -0
  57. package/operations/modelGroup/CmsContentModelGroupDynamo.d.ts +42 -0
  58. package/operations/modelGroup/CmsContentModelGroupDynamo.js +230 -0
  59. package/operations/modelGroup/CmsContentModelGroupDynamo.js.map +1 -0
  60. package/operations/modelGroup/index.d.ts +3 -0
  61. package/operations/modelGroup/index.js +26 -0
  62. package/operations/modelGroup/index.js.map +1 -0
  63. package/operations/settings/CmsSettingsDynamo.d.ts +16 -0
  64. package/operations/settings/CmsSettingsDynamo.js +145 -0
  65. package/operations/settings/CmsSettingsDynamo.js.map +1 -0
  66. package/operations/settings/index.d.ts +3 -0
  67. package/operations/settings/index.js +25 -0
  68. package/operations/settings/index.js.map +1 -0
  69. package/operations/system/CmsSystemDynamo.d.ts +16 -0
  70. package/operations/system/CmsSystemDynamo.js +126 -0
  71. package/operations/system/CmsSystemDynamo.js.map +1 -0
  72. package/operations/system/index.d.ts +3 -0
  73. package/operations/system/index.js +25 -0
  74. package/operations/system/index.js.map +1 -0
  75. package/package.json +61 -0
  76. package/types.d.ts +54 -0
  77. package/types.js +6 -0
  78. package/types.js.map +1 -0
  79. package/utils.d.ts +5 -0
  80. package/utils.js +62 -0
  81. package/utils.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/operations/settings/index.ts"],"names":["type","name","provide","context","CmsSettingsDynamo"],"mappings":";;;;;;;;;AAAA;;eAGe,OAAmD;AAC9DA,EAAAA,IAAI,EAAE,0CADwD;AAE9DC,EAAAA,IAAI,EAAE,0CAFwD;AAG9DC,EAAAA,OAAO,EAAE,OAAO;AAAEC,IAAAA;AAAF,GAAP,KAAuB;AAC5B,WAAO,IAAIC,0BAAJ,CAAsB;AACzBD,MAAAA;AADyB,KAAtB,CAAP;AAGH;AAP6D,CAAnD,C","sourcesContent":["import CmsSettingsDynamo from \"./CmsSettingsDynamo\";\nimport { CmsSettingsStorageOperationsProviderPlugin } from \"@webiny/api-headless-cms/types\";\n\nexport default (): CmsSettingsStorageOperationsProviderPlugin => ({\n type: \"cms-settings-storage-operations-provider\",\n name: \"cms-settings-storage-operations-ddb-crud\",\n provide: async ({ context }) => {\n return new CmsSettingsDynamo({\n context\n });\n }\n});\n"],"file":"index.js"}
@@ -0,0 +1,16 @@
1
+ import { CmsContext, CmsSystem, CmsSystemStorageOperations } from "@webiny/api-headless-cms/types";
2
+ interface ConstructorArgs {
3
+ context: CmsContext;
4
+ }
5
+ export default class CmsSystemDynamo implements CmsSystemStorageOperations {
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<CmsSystem>;
13
+ create(data: CmsSystem): Promise<void>;
14
+ update(data: CmsSystem): Promise<void>;
15
+ }
16
+ export {};
@@ -0,0 +1,126 @@
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 _dynamodbToolbox = require("dynamodb-toolbox");
17
+
18
+ var _helpers = require("../helpers");
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
+ const SYSTEM_SORT_KEY = "CMS";
25
+
26
+ class CmsSystemDynamo {
27
+ get context() {
28
+ return this._context;
29
+ }
30
+
31
+ get partitionKey() {
32
+ const tenant = this._context.tenancy.getCurrentTenant();
33
+
34
+ if (!tenant) {
35
+ throw new _error.default("Tenant missing.", "TENANT_NOT_FOUND");
36
+ }
37
+
38
+ return `T#${tenant.id}#SYSTEM`;
39
+ }
40
+
41
+ constructor({
42
+ context
43
+ }) {
44
+ (0, _defineProperty2.default)(this, "_context", void 0);
45
+ (0, _defineProperty2.default)(this, "_table", void 0);
46
+ (0, _defineProperty2.default)(this, "_entity", void 0);
47
+ this._context = context;
48
+ this._table = new _dynamodbToolbox.Table({
49
+ name: _configurations.default.db().table || (0, _helpers.getTable)(context),
50
+ partitionKey: "PK",
51
+ sortKey: "SK",
52
+ DocumentClient: (0, _helpers.getDocumentClient)(context)
53
+ });
54
+ this._entity = new _dynamodbToolbox.Entity({
55
+ name: "System",
56
+ table: this._table,
57
+ attributes: {
58
+ PK: {
59
+ partitionKey: true
60
+ },
61
+ SK: {
62
+ sortKey: true
63
+ },
64
+ version: {
65
+ type: "string"
66
+ },
67
+ readAPIKey: {
68
+ type: "string"
69
+ }
70
+ }
71
+ });
72
+ }
73
+
74
+ async get() {
75
+ const response = await this._entity.get({
76
+ PK: this.partitionKey,
77
+ SK: SYSTEM_SORT_KEY
78
+ });
79
+
80
+ if (!response || !response.Item) {
81
+ return null;
82
+ }
83
+
84
+ return response.Item;
85
+ }
86
+
87
+ async create(data) {
88
+ try {
89
+ const result = await this._entity.put(_objectSpread({
90
+ PK: this.partitionKey,
91
+ SK: SYSTEM_SORT_KEY
92
+ }, data));
93
+
94
+ if (!result) {
95
+ throw new _error.default("Could not create the system data - no result.", "CREATE_SYSTEM_ERROR");
96
+ }
97
+ } catch (ex) {
98
+ throw new _error.default(ex.message || "Could not create the system data.", ex.code || "CREATE_SYSTEM_ERROR", {
99
+ error: ex,
100
+ data
101
+ });
102
+ }
103
+ }
104
+
105
+ async update(data) {
106
+ try {
107
+ const result = await this._entity.update(_objectSpread({
108
+ PK: this.partitionKey,
109
+ SK: SYSTEM_SORT_KEY
110
+ }, data));
111
+
112
+ if (!result) {
113
+ throw new _error.default("Could not update the system data - no result.", "CREATE_SYSTEM_ERROR");
114
+ }
115
+ } catch (ex) {
116
+ throw new _error.default(ex.message || "Could not update the system data.", ex.code || "UPDATE_SYSTEM_ERROR", {
117
+ error: ex,
118
+ data
119
+ });
120
+ }
121
+ }
122
+
123
+ }
124
+
125
+ exports.default = CmsSystemDynamo;
126
+ //# sourceMappingURL=CmsSystemDynamo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/operations/system/CmsSystemDynamo.ts"],"names":["SYSTEM_SORT_KEY","CmsSystemDynamo","context","_context","partitionKey","tenant","tenancy","getCurrentTenant","WebinyError","id","constructor","_table","Table","name","configurations","db","table","sortKey","DocumentClient","_entity","Entity","attributes","PK","SK","version","type","readAPIKey","get","response","Item","create","data","result","put","ex","message","code","error","update"],"mappings":";;;;;;;;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AACE,IAAH,IAAW,qBAFT,EAGF;AACIC,QAAAA,KAAK,EAAEH,EADX;AAEIH,QAAAA;AAFJ,OAHE,CAAN;AAQH;AACJ;;AA1GsE","sourcesContent":["import { CmsContext, CmsSystem, CmsSystemStorageOperations } from \"@webiny/api-headless-cms/types\";\nimport configurations from \"../../configurations\";\nimport WebinyError from \"@webiny/error\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { getDocumentClient, getTable } from \"../helpers\";\n\ninterface ConstructorArgs {\n context: CmsContext;\n}\n\nconst SYSTEM_SORT_KEY = \"CMS\";\n\nexport default class CmsSystemDynamo implements CmsSystemStorageOperations {\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 const tenant = this._context.tenancy.getCurrentTenant();\n if (!tenant) {\n throw new WebinyError(\"Tenant missing.\", \"TENANT_NOT_FOUND\");\n }\n return `T#${tenant.id}#SYSTEM`;\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\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 version: {\n type: \"string\"\n },\n readAPIKey: {\n type: \"string\"\n }\n }\n });\n }\n\n public async get(): Promise<CmsSystem> {\n const response = await this._entity.get({\n PK: this.partitionKey,\n SK: SYSTEM_SORT_KEY\n });\n\n if (!response || !response.Item) {\n return null;\n }\n return response.Item;\n }\n\n public async create(data: CmsSystem): Promise<void> {\n try {\n const result = await this._entity.put({\n PK: this.partitionKey,\n SK: SYSTEM_SORT_KEY,\n ...data\n });\n if (!result) {\n throw new WebinyError(\n \"Could not create the system data - no result.\",\n \"CREATE_SYSTEM_ERROR\"\n );\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create the system data.\",\n ex.code || \"CREATE_SYSTEM_ERROR\",\n {\n error: ex,\n data\n }\n );\n }\n }\n\n public async update(data: CmsSystem): Promise<void> {\n try {\n const result = await this._entity.update({\n PK: this.partitionKey,\n SK: SYSTEM_SORT_KEY,\n ...data\n });\n if (!result) {\n throw new WebinyError(\n \"Could not update the system data - no result.\",\n \"CREATE_SYSTEM_ERROR\"\n );\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update the system data.\",\n ex.code || \"UPDATE_SYSTEM_ERROR\",\n {\n error: ex,\n data\n }\n );\n }\n }\n}\n"],"file":"CmsSystemDynamo.js"}
@@ -0,0 +1,3 @@
1
+ import { CmsSystemStorageOperationsProviderPlugin } from "@webiny/api-headless-cms/types";
2
+ declare const _default: () => CmsSystemStorageOperationsProviderPlugin;
3
+ export default _default;
@@ -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 _CmsSystemDynamo = _interopRequireDefault(require("./CmsSystemDynamo"));
11
+
12
+ var _default = () => ({
13
+ type: "cms-system-storage-operations-provider",
14
+ name: "cms-system-storage-operations-ddb-crud",
15
+ provide: async ({
16
+ context
17
+ }) => {
18
+ return new _CmsSystemDynamo.default({
19
+ context
20
+ });
21
+ }
22
+ });
23
+
24
+ exports.default = _default;
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/operations/system/index.ts"],"names":["type","name","provide","context","CmsSystemDynamo"],"mappings":";;;;;;;;;AAAA;;eAGe,OAAiD;AAC5DA,EAAAA,IAAI,EAAE,wCADsD;AAE5DC,EAAAA,IAAI,EAAE,wCAFsD;AAG5DC,EAAAA,OAAO,EAAE,OAAO;AAAEC,IAAAA;AAAF,GAAP,KAAuB;AAC5B,WAAO,IAAIC,wBAAJ,CAAoB;AACvBD,MAAAA;AADuB,KAApB,CAAP;AAGH;AAP2D,CAAjD,C","sourcesContent":["import CmsSystemDynamo from \"./CmsSystemDynamo\";\nimport { CmsSystemStorageOperationsProviderPlugin } from \"@webiny/api-headless-cms/types\";\n\nexport default (): CmsSystemStorageOperationsProviderPlugin => ({\n type: \"cms-system-storage-operations-provider\",\n name: \"cms-system-storage-operations-ddb-crud\",\n provide: async ({ context }) => {\n return new CmsSystemDynamo({\n context\n });\n }\n});\n"],"file":"index.js"}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@webiny/api-headless-cms-ddb",
3
+ "version": "5.15.0-beta.0",
4
+ "main": "index.js",
5
+ "keywords": [
6
+ "@webiny/api-headless-cms",
7
+ "storage-operations",
8
+ "dynamodb",
9
+ "cms:ddb"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/webiny/webiny-js.git",
14
+ "directory": "packages/api-headless-cms-ddb"
15
+ },
16
+ "description": "DynamoDB storage operations plugin for Headless CMS API.",
17
+ "contributors": [
18
+ "Pavel Denisjuk <pavel@webiny.com>",
19
+ "Sven Al Hamad <sven@webiny.com>",
20
+ "Adrian Smijulj <adrian@webiny.com>"
21
+ ],
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "@babel/runtime": "7.15.3",
25
+ "@webiny/api-headless-cms": "5.15.0-beta.0",
26
+ "@webiny/db-dynamodb": "5.15.0-beta.0",
27
+ "@webiny/error": "5.15.0-beta.0",
28
+ "@webiny/handler-db": "5.15.0-beta.0",
29
+ "aws-sdk": "2.868.0",
30
+ "dataloader": "2.0.0",
31
+ "dot-prop": "5.3.0",
32
+ "dynamodb-toolbox": "0.3.4",
33
+ "jsonpack": "1.1.5",
34
+ "lodash.clonedeep": "4.5.0",
35
+ "lodash.sortby": "4.7.0"
36
+ },
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",
42
+ "@types/jsonpack": "^1.1.0",
43
+ "@webiny/cli": "^5.15.0-beta.0",
44
+ "@webiny/plugins": "^5.15.0-beta.0",
45
+ "@webiny/project-utils": "^5.15.0-beta.0",
46
+ "jest": "^26.6.3",
47
+ "jest-dynalite": "^3.2.0",
48
+ "jest-environment-node": "^26.6.2",
49
+ "ttypescript": "^1.5.12",
50
+ "typescript": "^4.1.3"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public",
54
+ "directory": "dist"
55
+ },
56
+ "scripts": {
57
+ "build": "yarn webiny run build",
58
+ "watch": "yarn webiny run watch"
59
+ },
60
+ "gitHead": "baf2dbb8cae1b623b59d20fedc0cd0e11a310ca1"
61
+ }
package/types.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ import { Plugin } from "@webiny/plugins/types";
2
+ import { CmsContentModelField } from "@webiny/api-headless-cms/types";
3
+ interface CmsFieldFilterValueTransformArgs<T> {
4
+ /**
5
+ * A field which value we are transforming.
6
+ */
7
+ field: CmsContentModelField;
8
+ value: any;
9
+ }
10
+ export interface CmsFieldFilterValueTransformPlugin<T = any, R = any> extends Plugin {
11
+ /**
12
+ * A plugin type.
13
+ */
14
+ type: "cms-field-filter-value-transform";
15
+ /**
16
+ * A field type this plugin is for.
17
+ */
18
+ fieldType: string;
19
+ /**
20
+ * Transform method which expect field definition and value to transform.
21
+ */
22
+ transform: (args: CmsFieldFilterValueTransformArgs<T>) => R;
23
+ }
24
+ interface CmsFieldFilterPathArgs {
25
+ /**
26
+ * A field for which we are creating the value path.
27
+ */
28
+ field: CmsContentModelField;
29
+ /**
30
+ * If value is an array we will need index position.
31
+ * It is up to the developer to add.
32
+ */
33
+ index?: number | string;
34
+ }
35
+ export interface CmsFieldFilterPathPlugin extends Plugin {
36
+ /**
37
+ * A plugin type.
38
+ */
39
+ type: "cms-field-filter-path";
40
+ /**
41
+ * A field type this plugin is for.
42
+ */
43
+ fieldType: string;
44
+ /**
45
+ * A field id this plugin is for.
46
+ * It is meant for targeting only specific fields in a certain type.
47
+ */
48
+ fieldId?: string[];
49
+ /**
50
+ * Get a path for given field.
51
+ */
52
+ createPath: (args: CmsFieldFilterPathArgs) => string;
53
+ }
54
+ export {};
package/types.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=types.js.map
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"types.js"}
package/utils.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { CmsContext } from "@webiny/api-headless-cms/types";
2
+ export declare const createBasePartitionKey: ({ tenancy, cms }: CmsContext) => string;
3
+ export declare const encodePaginationCursor: (cursor?: any) => string;
4
+ export declare const decodePaginationCursor: (cursor?: string) => any;
5
+ export declare const paginateBatch: <T = Record<string, any>>(items: T[], perPage: number, execute: (items: T[]) => Promise<any>) => Promise<void>;
package/utils.js ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.paginateBatch = exports.decodePaginationCursor = exports.encodePaginationCursor = exports.createBasePartitionKey = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ const createBasePartitionKey = ({
13
+ tenancy,
14
+ cms
15
+ }) => {
16
+ const tenant = tenancy.getCurrentTenant();
17
+
18
+ if (!tenant) {
19
+ throw new _error.default("Tenant missing.", "TENANT_NOT_FOUND");
20
+ }
21
+
22
+ const locale = cms.getLocale();
23
+
24
+ if (!locale) {
25
+ throw new _error.default("Locale missing.", "LOCALE_NOT_FOUND");
26
+ }
27
+
28
+ return `T#${tenant.id}#L#${locale.code}#CMS`;
29
+ };
30
+
31
+ exports.createBasePartitionKey = createBasePartitionKey;
32
+
33
+ const encodePaginationCursor = cursor => {
34
+ if (!cursor) {
35
+ return null;
36
+ }
37
+
38
+ return Buffer.from(JSON.stringify(cursor)).toString("base64");
39
+ };
40
+
41
+ exports.encodePaginationCursor = encodePaginationCursor;
42
+
43
+ const decodePaginationCursor = cursor => {
44
+ if (!cursor) {
45
+ return null;
46
+ }
47
+
48
+ return JSON.parse(Buffer.from(cursor, "base64").toString("ascii"));
49
+ };
50
+
51
+ exports.decodePaginationCursor = decodePaginationCursor;
52
+
53
+ const paginateBatch = async (items, perPage, execute) => {
54
+ const pages = Math.ceil(items.length / perPage);
55
+
56
+ for (let i = 0; i < pages; i++) {
57
+ await execute(items.slice(i * perPage, i * perPage + perPage));
58
+ }
59
+ };
60
+
61
+ exports.paginateBatch = paginateBatch;
62
+ //# sourceMappingURL=utils.js.map
package/utils.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts"],"names":["createBasePartitionKey","tenancy","cms","tenant","getCurrentTenant","WebinyError","locale","getLocale","id","code","encodePaginationCursor","cursor","Buffer","from","JSON","stringify","toString","decodePaginationCursor","parse","paginateBatch","items","perPage","execute","pages","Math","ceil","length","i","slice"],"mappings":";;;;;;;;;AAAA;;AAGO,MAAMA,sBAAsB,GAAG,CAAC;AAAEC,EAAAA,OAAF;AAAWC,EAAAA;AAAX,CAAD,KAA0C;AAC5E,QAAMC,MAAM,GAAGF,OAAO,CAACG,gBAAR,EAAf;;AACA,MAAI,CAACD,MAAL,EAAa;AACT,UAAM,IAAIE,cAAJ,CAAgB,iBAAhB,EAAmC,kBAAnC,CAAN;AACH;;AAED,QAAMC,MAAM,GAAGJ,GAAG,CAACK,SAAJ,EAAf;;AACA,MAAI,CAACD,MAAL,EAAa;AACT,UAAM,IAAID,cAAJ,CAAgB,iBAAhB,EAAmC,kBAAnC,CAAN;AACH;;AAED,SAAQ,KAAIF,MAAM,CAACK,EAAG,MAAKF,MAAM,CAACG,IAAK,MAAvC;AACH,CAZM;;;;AAcA,MAAMC,sBAAsB,GAAIC,MAAD,IAAkB;AACpD,MAAI,CAACA,MAAL,EAAa;AACT,WAAO,IAAP;AACH;;AAED,SAAOC,MAAM,CAACC,IAAP,CAAYC,IAAI,CAACC,SAAL,CAAeJ,MAAf,CAAZ,EAAoCK,QAApC,CAA6C,QAA7C,CAAP;AACH,CANM;;;;AAQA,MAAMC,sBAAsB,GAAIN,MAAD,IAAqB;AACvD,MAAI,CAACA,MAAL,EAAa;AACT,WAAO,IAAP;AACH;;AAED,SAAOG,IAAI,CAACI,KAAL,CAAWN,MAAM,CAACC,IAAP,CAAYF,MAAZ,EAAoB,QAApB,EAA8BK,QAA9B,CAAuC,OAAvC,CAAX,CAAP;AACH,CANM;;;;AAQA,MAAMG,aAAa,GAAG,OACzBC,KADyB,EAEzBC,OAFyB,EAGzBC,OAHyB,KAIxB;AACD,QAAMC,KAAK,GAAGC,IAAI,CAACC,IAAL,CAAUL,KAAK,CAACM,MAAN,GAAeL,OAAzB,CAAd;;AACA,OAAK,IAAIM,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGJ,KAApB,EAA2BI,CAAC,EAA5B,EAAgC;AAC5B,UAAML,OAAO,CAACF,KAAK,CAACQ,KAAN,CAAYD,CAAC,GAAGN,OAAhB,EAAyBM,CAAC,GAAGN,OAAJ,GAAcA,OAAvC,CAAD,CAAb;AACH;AACJ,CATM","sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsContext } from \"@webiny/api-headless-cms/types\";\n\nexport const createBasePartitionKey = ({ tenancy, cms }: CmsContext): string => {\n const tenant = tenancy.getCurrentTenant();\n if (!tenant) {\n throw new WebinyError(\"Tenant missing.\", \"TENANT_NOT_FOUND\");\n }\n\n const locale = cms.getLocale();\n if (!locale) {\n throw new WebinyError(\"Locale missing.\", \"LOCALE_NOT_FOUND\");\n }\n\n return `T#${tenant.id}#L#${locale.code}#CMS`;\n};\n\nexport const encodePaginationCursor = (cursor?: any) => {\n if (!cursor) {\n return null;\n }\n\n return Buffer.from(JSON.stringify(cursor)).toString(\"base64\");\n};\n\nexport const decodePaginationCursor = (cursor?: string) => {\n if (!cursor) {\n return null;\n }\n\n return JSON.parse(Buffer.from(cursor, \"base64\").toString(\"ascii\"));\n};\n\nexport const paginateBatch = async <T = Record<string, any>>(\n items: T[],\n perPage: number,\n execute: (items: T[]) => Promise<any>\n) => {\n const pages = Math.ceil(items.length / perPage);\n for (let i = 0; i < pages; i++) {\n await execute(items.slice(i * perPage, i * perPage + perPage));\n }\n};\n"],"file":"utils.js"}