Skip to content

Commit

Permalink
feat: export and import for the headless cms (#4166)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunozoric authored Sep 20, 2024
1 parent 0a32c9c commit 84d28b3
Show file tree
Hide file tree
Showing 315 changed files with 19,626 additions and 2,726 deletions.
2 changes: 1 addition & 1 deletion cypress-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"nanoid": "^3.3.7",
"node-fetch": "^2.6.1",
"typescript": "4.9.5",
"uniqid": "^5.2.0"
"uniqid": "^5.4.0"
},
"scripts": {
"cypress:open": "yarn cypress open",
Expand Down
4 changes: 2 additions & 2 deletions packages/api-aco/src/record/record.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AcoBaseFields, ListMeta } from "~/types";
import { Topic } from "@webiny/pubsub/types";
import { CmsModel } from "@webiny/api-headless-cms/types";
import { CmsEntryListSort, CmsModel } from "@webiny/api-headless-cms/types";

export type GenericSearchData = {
[key: string]: any;
Expand Down Expand Up @@ -39,7 +39,7 @@ export interface ListSearchRecordsWhere<TData extends GenericSearchData = Generi
export interface ListSearchRecordsParams {
where?: ListSearchRecordsWhere;
search?: string;
sort?: string[];
sort?: CmsEntryListSort;
limit?: number;
after?: string | null;
}
Expand Down
11 changes: 9 additions & 2 deletions packages/api-aco/src/utils/createListSort.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { ListSort } from "~/types";
import {
CmsEntryListSort,
CmsEntryListSortAsc,
CmsEntryListSortDesc
} from "@webiny/api-headless-cms/types";

export const createListSort = (sort?: ListSort): string[] | undefined => {
export const createListSort = (sort?: ListSort): CmsEntryListSort | undefined => {
if (!sort) {
return;
}

return Object.keys(sort).map(key => `${key}_${sort[key]}`);
return Object.keys(sort).map(key => {
return `${key}_${sort[key]}` as CmsEntryListSortAsc | CmsEntryListSortDesc;
});
};
5 changes: 3 additions & 2 deletions packages/api-apw/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
CmsEntry as BaseCmsEntry,
OnEntryBeforePublishTopicParams,
OnEntryAfterPublishTopicParams,
OnEntryAfterUnpublishTopicParams
OnEntryAfterUnpublishTopicParams,
CmsEntryListSort
} from "@webiny/api-headless-cms/types";
import {
Page,
Expand Down Expand Up @@ -62,7 +63,7 @@ export interface ListWhere {

export interface ListParams {
where?: ListWhere;
sort?: string[];
sort?: CmsEntryListSort;
limit?: number;
after?: string | null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ROOT_FOLDER } from "~/contants";
import { NotAuthorizedError } from "@webiny/api-security";
import { getDate } from "@webiny/api-headless-cms/utils/date";
import { getIdentity as utilsGetIdentity } from "@webiny/api-headless-cms/utils/identity";
import { CmsEntryListSort } from "@webiny/api-headless-cms/types";

export const createFilesCrud = (config: FileManagerConfig): FilesCRUD => {
const {
Expand Down Expand Up @@ -301,7 +302,7 @@ export const createFilesCrud = (config: FileManagerConfig): FilesCRUD => {
where.createdBy = identity.id;
}

const sort =
const sort: CmsEntryListSort =
Array.isArray(initialSort) && initialSort.length > 0 ? initialSort : ["id_DESC"];
try {
return await storageOperations.files.list({
Expand Down
6 changes: 3 additions & 3 deletions packages/api-file-manager/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Context } from "@webiny/api/types";
import { FileLifecycleEvents } from "./types/file.lifecycle";
import { CreatedBy, File } from "./types/file";
import { Topic } from "@webiny/pubsub/types";
import { CmsContext } from "@webiny/api-headless-cms/types";
import { CmsContext, CmsEntryListSort } from "@webiny/api-headless-cms/types";
import { Context as TasksContext } from "@webiny/tasks/types";

export * from "./types/file.lifecycle";
Expand Down Expand Up @@ -68,7 +68,7 @@ export interface FilesListOpts {
limit?: number;
after?: string;
where?: FileListWhereParams;
sort?: string[];
sort?: CmsEntryListSort;
}

export interface FileListMeta {
Expand Down Expand Up @@ -325,7 +325,7 @@ export interface FileManagerFilesStorageOperationsListParamsWhere {
*/
export interface FileManagerFilesStorageOperationsListParams {
where: FileManagerFilesStorageOperationsListParamsWhere;
sort: string[];
sort: CmsEntryListSort;
limit: number;
after: string | null;
search?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/api-file-manager/src/types/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface File {
createdBy: CreatedBy;
modifiedBy: CreatedBy | null;
savedBy: CreatedBy;
extensions?: Record<string, any>;

/**
* Added with new storage operations refactoring.
Expand Down
8 changes: 4 additions & 4 deletions packages/api-headless-cms-bulk-actions/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
"include": ["src"],
"references": [
{ "path": "../api-headless-cms/tsconfig.build.json" },
{ "path": "../handler/tsconfig.build.json" },
{ "path": "../handler-aws/tsconfig.build.json" },
{ "path": "../tasks/tsconfig.build.json" },
{ "path": "../utils/tsconfig.build.json" },
{ "path": "../api/tsconfig.build.json" },
{ "path": "../api-admin-users/tsconfig.build.json" },
{ "path": "../api-i18n/tsconfig.build.json" },
{ "path": "../api-security/tsconfig.build.json" },
{ "path": "../api-tenancy/tsconfig.build.json" },
{ "path": "../api-wcp/tsconfig.build.json" },
{ "path": "../handler/tsconfig.build.json" },
{ "path": "../handler-aws/tsconfig.build.json" },
{ "path": "../handler-graphql/tsconfig.build.json" },
{ "path": "../plugins/tsconfig.build.json" },
{ "path": "../tasks/tsconfig.build.json" },
{ "path": "../utils/tsconfig.build.json" },
{ "path": "../wcp/tsconfig.build.json" }
],
"compilerOptions": {
Expand Down
30 changes: 15 additions & 15 deletions packages/api-headless-cms-bulk-actions/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
"extends": "../../tsconfig.json",
"include": ["src", "__tests__"],
"references": [
{ "path": "../api-headless-cms" },
{ "path": "../handler" },
{ "path": "../handler-aws" },
{ "path": "../tasks" },
{ "path": "../utils" },
{ "path": "../api" },
{ "path": "../api-admin-users" },
{ "path": "../api-headless-cms" },
{ "path": "../api-i18n" },
{ "path": "../api-security" },
{ "path": "../api-tenancy" },
{ "path": "../api-wcp" },
{ "path": "../handler" },
{ "path": "../handler-aws" },
{ "path": "../handler-graphql" },
{ "path": "../plugins" },
{ "path": "../tasks" },
{ "path": "../utils" },
{ "path": "../wcp" }
],
"compilerOptions": {
Expand All @@ -24,12 +24,20 @@
"paths": {
"~/*": ["./src/*"],
"~tests/*": ["./__tests__/*"],
"@webiny/api-headless-cms/*": ["../api-headless-cms/src/*"],
"@webiny/api-headless-cms": ["../api-headless-cms/src"],
"@webiny/handler/*": ["../handler/src/*"],
"@webiny/handler": ["../handler/src"],
"@webiny/handler-aws/*": ["../handler-aws/src/*"],
"@webiny/handler-aws": ["../handler-aws/src"],
"@webiny/tasks/*": ["../tasks/src/*"],
"@webiny/tasks": ["../tasks/src"],
"@webiny/utils/*": ["../utils/src/*"],
"@webiny/utils": ["../utils/src"],
"@webiny/api/*": ["../api/src/*"],
"@webiny/api": ["../api/src"],
"@webiny/api-admin-users/*": ["../api-admin-users/src/*"],
"@webiny/api-admin-users": ["../api-admin-users/src"],
"@webiny/api-headless-cms/*": ["../api-headless-cms/src/*"],
"@webiny/api-headless-cms": ["../api-headless-cms/src"],
"@webiny/api-i18n/*": ["../api-i18n/src/*"],
"@webiny/api-i18n": ["../api-i18n/src"],
"@webiny/api-security/*": ["../api-security/src/*"],
Expand All @@ -38,18 +46,10 @@
"@webiny/api-tenancy": ["../api-tenancy/src"],
"@webiny/api-wcp/*": ["../api-wcp/src/*"],
"@webiny/api-wcp": ["../api-wcp/src"],
"@webiny/handler/*": ["../handler/src/*"],
"@webiny/handler": ["../handler/src"],
"@webiny/handler-aws/*": ["../handler-aws/src/*"],
"@webiny/handler-aws": ["../handler-aws/src"],
"@webiny/handler-graphql/*": ["../handler-graphql/src/*"],
"@webiny/handler-graphql": ["../handler-graphql/src"],
"@webiny/plugins/*": ["../plugins/src/*"],
"@webiny/plugins": ["../plugins/src"],
"@webiny/tasks/*": ["../tasks/src/*"],
"@webiny/tasks": ["../tasks/src"],
"@webiny/utils": ["../utils/src"],
"@webiny/utils/*": ["../utils/src/*"],
"@webiny/wcp/*": ["../wcp/src/*"],
"@webiny/wcp": ["../wcp/src"]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const convertFromStorageEntry = (params: ConvertStorageEntryParams): CmsStorageE
};
};

const MAX_LIST_LIMIT = 10000;
const MAX_LIST_LIMIT = 1000000;

export interface CreateEntriesStorageOperationsParams {
entity: Entity<any>;
Expand Down
6 changes: 3 additions & 3 deletions packages/api-headless-cms-es-tasks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"@webiny/utils": "0.0.0"
},
"devDependencies": {
"@babel/cli": "^7.22.6",
"@babel/core": "^7.22.8",
"@babel/preset-env": "^7.22.7",
"@babel/cli": "^7.23.9",
"@babel/core": "^7.24.0",
"@babel/preset-env": "^7.24.0",
"@faker-js/faker": "^8.4.1",
"@webiny/api": "0.0.0",
"@webiny/api-i18n": "0.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/api-headless-cms-import-export/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("@webiny/project-utils").createBabelConfigForNode({ path: __dirname });
21 changes: 21 additions & 0 deletions packages/api-headless-cms-import-export/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Webiny

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
15 changes: 15 additions & 0 deletions packages/api-headless-cms-import-export/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# @webiny/api-headless-cms-import-export
[![](https://img.shields.io/npm/dw/@webiny/api-headless-cms-import-export.svg)](https://www.npmjs.com/package/@webiny/api-headless-cms-import-export)
[![](https://img.shields.io/npm/v/@webiny/api-headless-cms-import-export.svg)](https://www.npmjs.com/package/@webiny/api-headless-cms-import-export)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)

## Install
```
npm install --save @webiny/api-headless-cms-import-export
```

Or if you prefer yarn:
```
yarn add @webiny/api-headless-cms-import-export
```
Loading

0 comments on commit 84d28b3

Please sign in to comment.