@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.
- package/definitions/entry.d.ts +6 -4
- package/definitions/entry.js +19 -8
- package/definitions/group.d.ts +8 -0
- package/definitions/group.js +74 -0
- package/definitions/model.d.ts +8 -0
- package/definitions/model.js +96 -0
- package/definitions/settings.d.ts +8 -0
- package/definitions/settings.js +62 -0
- package/definitions/system.d.ts +8 -0
- package/definitions/system.js +50 -0
- package/definitions/table.d.ts +6 -12
- package/definitions/table.js +15 -15
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +4 -3
- package/dynamoDb/path/plainObject.js +1 -2
- package/dynamoDb/path/ref.js +1 -2
- package/dynamoDb/storage/date.d.ts +2 -2
- package/dynamoDb/storage/date.js +17 -21
- package/dynamoDb/storage/longText.d.ts +7 -0
- package/dynamoDb/storage/longText.js +83 -0
- package/dynamoDb/storage/richText.d.ts +2 -2
- package/dynamoDb/storage/richText.js +69 -67
- package/dynamoDb/transformValue/datetime.d.ts +1 -1
- package/dynamoDb/transformValue/datetime.js +1 -2
- package/index.d.ts +2 -6
- package/index.js +108 -13
- package/operations/entry/dataLoaders.d.ts +34 -19
- package/operations/entry/dataLoaders.js +158 -138
- package/operations/entry/index.d.ts +8 -4
- package/operations/entry/index.js +812 -16
- package/operations/entry/keys.d.ts +25 -0
- package/operations/entry/keys.js +62 -0
- package/operations/entry/systemFields.d.ts +2 -2
- package/operations/entry/systemFields.js +1 -2
- package/operations/entry/utils.d.ts +13 -9
- package/operations/entry/utils.js +62 -18
- package/operations/group/index.d.ts +8 -0
- package/operations/group/index.js +198 -0
- package/operations/model/index.d.ts +6 -3
- package/operations/model/index.js +153 -18
- package/operations/settings/index.d.ts +6 -3
- package/operations/settings/index.js +132 -16
- package/operations/system/index.d.ts +6 -3
- package/operations/system/index.js +94 -14
- package/package.json +11 -11
- package/types.d.ts +38 -8
- package/types.js +11 -1
- package/configurations.d.ts +0 -18
- package/configurations.js +0 -24
- package/configurations.js.map +0 -1
- package/definitions/entry.js.map +0 -1
- package/definitions/table.js.map +0 -1
- package/dynamoDb/index.js.map +0 -1
- package/dynamoDb/path/plainObject.js.map +0 -1
- package/dynamoDb/path/ref.js.map +0 -1
- package/dynamoDb/storage/date.js.map +0 -1
- package/dynamoDb/storage/richText.js.map +0 -1
- package/dynamoDb/transformValue/datetime.js.map +0 -1
- package/index.js.map +0 -1
- package/operations/entry/CmsContentEntryDynamo.d.ts +0 -86
- package/operations/entry/CmsContentEntryDynamo.js +0 -972
- package/operations/entry/CmsContentEntryDynamo.js.map +0 -1
- package/operations/entry/dataLoaders.js.map +0 -1
- package/operations/entry/index.js.map +0 -1
- package/operations/entry/systemFields.js.map +0 -1
- package/operations/entry/utils.js.map +0 -1
- package/operations/helpers.d.ts +0 -5
- package/operations/helpers.js +0 -96
- package/operations/helpers.js.map +0 -1
- package/operations/model/CmsContentModelDynamo.d.ts +0 -18
- package/operations/model/CmsContentModelDynamo.js +0 -234
- package/operations/model/CmsContentModelDynamo.js.map +0 -1
- package/operations/model/index.js.map +0 -1
- package/operations/modelGroup/CmsContentModelGroupDynamo.d.ts +0 -42
- package/operations/modelGroup/CmsContentModelGroupDynamo.js +0 -230
- package/operations/modelGroup/CmsContentModelGroupDynamo.js.map +0 -1
- package/operations/modelGroup/index.d.ts +0 -3
- package/operations/modelGroup/index.js +0 -26
- package/operations/modelGroup/index.js.map +0 -1
- package/operations/settings/CmsSettingsDynamo.d.ts +0 -16
- package/operations/settings/CmsSettingsDynamo.js +0 -145
- package/operations/settings/CmsSettingsDynamo.js.map +0 -1
- package/operations/settings/index.js.map +0 -1
- package/operations/system/CmsSystemDynamo.d.ts +0 -16
- package/operations/system/CmsSystemDynamo.js +0 -126
- package/operations/system/CmsSystemDynamo.js.map +0 -1
- package/operations/system/index.js.map +0 -1
- package/types.js.map +0 -1
- package/utils.d.ts +0 -5
- package/utils.js +0 -62
- package/utils.js.map +0 -1
|
@@ -1,126 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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":";;;;;;;;;;;AACA;;AACA;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W,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"}
|
|
@@ -1 +0,0 @@
|
|
|
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/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"types.js"}
|
package/utils.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
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.encodePaginationCursor = exports.decodePaginationCursor = 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
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|