@webiny/api-headless-cms-es-tasks 6.1.0 → 6.2.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms-es-tasks",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"description": "Elasticsearch Background tasks for Webiny Headless CMS",
|
|
@@ -14,28 +14,29 @@
|
|
|
14
14
|
},
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@webiny/api-core": "6.
|
|
18
|
-
"@webiny/api-headless-cms": "6.
|
|
19
|
-
"@webiny/api-headless-cms-ddb-es": "6.
|
|
20
|
-
"@webiny/api-opensearch": "6.
|
|
21
|
-
"@webiny/
|
|
22
|
-
"@webiny/handler
|
|
23
|
-
"@webiny/
|
|
24
|
-
"@webiny/
|
|
17
|
+
"@webiny/api-core": "6.2.0-beta.0",
|
|
18
|
+
"@webiny/api-headless-cms": "6.2.0-beta.0",
|
|
19
|
+
"@webiny/api-headless-cms-ddb-es": "6.2.0-beta.0",
|
|
20
|
+
"@webiny/api-opensearch": "6.2.0-beta.0",
|
|
21
|
+
"@webiny/error": "6.2.0-beta.0",
|
|
22
|
+
"@webiny/handler": "6.2.0-beta.0",
|
|
23
|
+
"@webiny/handler-aws": "6.2.0-beta.0",
|
|
24
|
+
"@webiny/tasks": "6.2.0-beta.0",
|
|
25
|
+
"@webiny/utils": "6.2.0-beta.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"@webiny/api": "6.
|
|
28
|
-
"@webiny/build-tools": "6.
|
|
29
|
-
"@webiny/handler-graphql": "6.
|
|
30
|
-
"@webiny/plugins": "6.
|
|
31
|
-
"@webiny/project-utils": "6.
|
|
32
|
-
"@webiny/wcp": "6.
|
|
28
|
+
"@webiny/api": "6.2.0-beta.0",
|
|
29
|
+
"@webiny/build-tools": "6.2.0-beta.0",
|
|
30
|
+
"@webiny/handler-graphql": "6.2.0-beta.0",
|
|
31
|
+
"@webiny/plugins": "6.2.0-beta.0",
|
|
32
|
+
"@webiny/project-utils": "6.2.0-beta.0",
|
|
33
|
+
"@webiny/wcp": "6.2.0-beta.0",
|
|
33
34
|
"typescript": "5.9.3",
|
|
34
|
-
"vitest": "4.1.
|
|
35
|
+
"vitest": "4.1.4"
|
|
35
36
|
},
|
|
36
37
|
"publishConfig": {
|
|
37
38
|
"access": "public",
|
|
38
39
|
"directory": "dist"
|
|
39
40
|
},
|
|
40
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "3d3148358b6febbc857371930871743bec3b3939"
|
|
41
42
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createGroupData } from "./group.js";
|
|
2
2
|
import { createCarsModel } from "./model.js";
|
|
3
3
|
import { createIndex } from "../../utils/index.js";
|
|
4
|
+
import { CmsEntryOpenSearchIndex } from "@webiny/api-headless-cms-ddb-es/exports/api/cms/opensearch.js";
|
|
4
5
|
export const createModelAndGroup = async params => {
|
|
5
6
|
const {
|
|
6
7
|
context,
|
|
@@ -29,7 +30,7 @@ export const createModelAndGroup = async params => {
|
|
|
29
30
|
await createIndex({
|
|
30
31
|
model,
|
|
31
32
|
client: context.opensearch,
|
|
32
|
-
|
|
33
|
+
indexConfigs: context.container.resolveAll(CmsEntryOpenSearchIndex)
|
|
33
34
|
});
|
|
34
35
|
return {
|
|
35
36
|
group: group,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createGroupData","createCarsModel","createIndex","createModelAndGroup","params","context","modelId","overwrite","model","cms","listModels","find","m","group","listGroups","slug","groupData","createGroup","carsModel","createModel","client","opensearch","
|
|
1
|
+
{"version":3,"names":["createGroupData","createCarsModel","createIndex","CmsEntryOpenSearchIndex","createModelAndGroup","params","context","modelId","overwrite","model","cms","listModels","find","m","group","listGroups","slug","groupData","createGroup","carsModel","createModel","client","opensearch","indexConfigs","container","resolveAll"],"sources":["createModelAndGroup.ts"],"sourcesContent":["import type { CmsGroup, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { Context } from \"~/types.js\";\nimport { createGroupData } from \"./group.js\";\nimport { createCarsModel } from \"./model.js\";\nimport { createIndex } from \"~/utils/index.js\";\nimport { CmsEntryOpenSearchIndex } from \"@webiny/api-headless-cms-ddb-es/exports/api/cms/opensearch.js\";\n\ninterface ICreateModelAndGroupParams {\n context: Context;\n modelId: string;\n overwrite?: boolean;\n}\nexport interface ICreateModelAndGroupResultSuccess {\n group: CmsGroup;\n model: CmsModel;\n}\nexport type ICreateModelAndGroupResult = string | ICreateModelAndGroupResultSuccess;\n\nexport const createModelAndGroup = async (\n params: ICreateModelAndGroupParams\n): Promise<ICreateModelAndGroupResult> => {\n const { context, modelId, overwrite = false } = params;\n /**\n * First we need to check if the model already exists in the database. If not, we need to create it.\n */\n let model = (await context.cms.listModels()).find(m => m.modelId === modelId);\n let group: CmsGroup | undefined;\n if (model && !overwrite) {\n return `Model \"${modelId}\" already exists.`;\n } else if (!model) {\n group = (await context.cms.listGroups()).find(group => group.slug === \"mocks\");\n if (!group) {\n const groupData = createGroupData();\n group = await context.cms.createGroup(groupData);\n }\n /**\n * Possibly we need to create the model.\n */\n const carsModel = createCarsModel(group);\n model = await context.cms.createModel(carsModel);\n }\n await createIndex({\n model,\n client: context.opensearch,\n indexConfigs: context.container.resolveAll(CmsEntryOpenSearchIndex)\n });\n\n return {\n group: group as CmsGroup,\n model: model as CmsModel\n };\n};\n"],"mappings":"AAEA,SAASA,eAAe;AACxB,SAASC,eAAe;AACxB,SAASC,WAAW;AACpB,SAASC,uBAAuB,QAAQ,+DAA+D;AAavG,OAAO,MAAMC,mBAAmB,GAAG,MAC/BC,MAAkC,IACI;EACtC,MAAM;IAAEC,OAAO;IAAEC,OAAO;IAAEC,SAAS,GAAG;EAAM,CAAC,GAAGH,MAAM;EACtD;AACJ;AACA;EACI,IAAII,KAAK,GAAG,CAAC,MAAMH,OAAO,CAACI,GAAG,CAACC,UAAU,CAAC,CAAC,EAAEC,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACN,OAAO,KAAKA,OAAO,CAAC;EAC7E,IAAIO,KAA2B;EAC/B,IAAIL,KAAK,IAAI,CAACD,SAAS,EAAE;IACrB,OAAO,UAAUD,OAAO,mBAAmB;EAC/C,CAAC,MAAM,IAAI,CAACE,KAAK,EAAE;IACfK,KAAK,GAAG,CAAC,MAAMR,OAAO,CAACI,GAAG,CAACK,UAAU,CAAC,CAAC,EAAEH,IAAI,CAACE,KAAK,IAAIA,KAAK,CAACE,IAAI,KAAK,OAAO,CAAC;IAC9E,IAAI,CAACF,KAAK,EAAE;MACR,MAAMG,SAAS,GAAGjB,eAAe,CAAC,CAAC;MACnCc,KAAK,GAAG,MAAMR,OAAO,CAACI,GAAG,CAACQ,WAAW,CAACD,SAAS,CAAC;IACpD;IACA;AACR;AACA;IACQ,MAAME,SAAS,GAAGlB,eAAe,CAACa,KAAK,CAAC;IACxCL,KAAK,GAAG,MAAMH,OAAO,CAACI,GAAG,CAACU,WAAW,CAACD,SAAS,CAAC;EACpD;EACA,MAAMjB,WAAW,CAAC;IACdO,KAAK;IACLY,MAAM,EAAEf,OAAO,CAACgB,UAAU;IAC1BC,YAAY,EAAEjB,OAAO,CAACkB,SAAS,CAACC,UAAU,CAACtB,uBAAuB;EACtE,CAAC,CAAC;EAEF,OAAO;IACHW,KAAK,EAAEA,KAAiB;IACxBL,KAAK,EAAEA;EACX,CAAC;AACL,CAAC","ignoreList":[]}
|
package/utils/createIndex.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Client } from "@webiny/api-opensearch";
|
|
2
2
|
import type { CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { CmsEntryOpenSearchIndex } from "@webiny/api-headless-cms-ddb-es/exports/api/cms/opensearch.js";
|
|
4
4
|
export interface ICreateIndexParams {
|
|
5
5
|
client: Client;
|
|
6
|
-
model: Pick<CmsModel, "modelId" | "tenant">;
|
|
7
|
-
|
|
6
|
+
model: Pick<CmsModel, "modelId" | "tenant" | "group">;
|
|
7
|
+
indexConfigs: CmsEntryOpenSearchIndex.Interface[];
|
|
8
8
|
}
|
|
9
9
|
export declare const createIndex: (params: ICreateIndexParams) => Promise<void>;
|
package/utils/createIndex.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WebinyError } from "@webiny/error";
|
|
2
2
|
import { configurations } from "@webiny/api-headless-cms-ddb-es/configurations.js";
|
|
3
|
-
import { CmsEntryElasticsearchIndexPlugin } from "@webiny/api-headless-cms-ddb-es/plugins/index.js";
|
|
4
3
|
export const createIndex = async params => {
|
|
5
4
|
const {
|
|
6
5
|
client,
|
|
7
6
|
model,
|
|
8
|
-
|
|
7
|
+
indexConfigs
|
|
9
8
|
} = params;
|
|
10
9
|
const {
|
|
11
10
|
index
|
|
@@ -18,12 +17,21 @@ export const createIndex = async params => {
|
|
|
18
17
|
if (result.body) {
|
|
19
18
|
return;
|
|
20
19
|
}
|
|
21
|
-
|
|
20
|
+
const usable = indexConfigs.filter(c => c.canUse({
|
|
21
|
+
model
|
|
22
|
+
}));
|
|
23
|
+
if (usable.length === 0) {
|
|
24
|
+
/**
|
|
25
|
+
* Should not happen in production as we have a default index configuration, but it can happen in tests if the test setup is not correct.
|
|
26
|
+
*/
|
|
27
|
+
throw new WebinyError("Could not find a single usable CmsEntryOpenSearchIndex.", "OPENSEARCH_INDEX_TEMPLATE_ERROR");
|
|
28
|
+
}
|
|
29
|
+
const config = usable[usable.length - 1];
|
|
30
|
+
await client.indices.create({
|
|
22
31
|
index,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
type: CmsEntryElasticsearchIndexPlugin.type
|
|
32
|
+
body: {
|
|
33
|
+
...config.body
|
|
34
|
+
}
|
|
27
35
|
});
|
|
28
36
|
};
|
|
29
37
|
|
package/utils/createIndex.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["WebinyError","configurations","createIndex","params","client","model","indexConfigs","index","es","result","indices","exists","body","usable","filter","c","canUse","length","config","create"],"sources":["createIndex.ts"],"sourcesContent":["import type { Client } from \"@webiny/api-opensearch\";\nimport { WebinyError } from \"@webiny/error\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { configurations } from \"@webiny/api-headless-cms-ddb-es/configurations.js\";\nimport type { CmsEntryOpenSearchIndex } from \"@webiny/api-headless-cms-ddb-es/exports/api/cms/opensearch.js\";\n\nexport interface ICreateIndexParams {\n client: Client;\n model: Pick<CmsModel, \"modelId\" | \"tenant\" | \"group\">;\n indexConfigs: CmsEntryOpenSearchIndex.Interface[];\n}\n\nexport const createIndex = async (params: ICreateIndexParams): Promise<void> => {\n const { client, model, indexConfigs } = params;\n\n const { index } = configurations.es({\n model\n });\n\n const result = await client.indices.exists({\n index\n });\n if (result.body) {\n return;\n }\n\n const usable = indexConfigs.filter(c => c.canUse({ model }));\n if (usable.length === 0) {\n /**\n * Should not happen in production as we have a default index configuration, but it can happen in tests if the test setup is not correct.\n */\n throw new WebinyError(\n \"Could not find a single usable CmsEntryOpenSearchIndex.\",\n \"OPENSEARCH_INDEX_TEMPLATE_ERROR\"\n );\n }\n const config = usable[usable.length - 1];\n\n await client.indices.create({\n index,\n body: {\n ...config.body\n }\n });\n};\n"],"mappings":"AACA,SAASA,WAAW,QAAQ,eAAe;AAE3C,SAASC,cAAc,QAAQ,mDAAmD;AASlF,OAAO,MAAMC,WAAW,GAAG,MAAOC,MAA0B,IAAoB;EAC5E,MAAM;IAAEC,MAAM;IAAEC,KAAK;IAAEC;EAAa,CAAC,GAAGH,MAAM;EAE9C,MAAM;IAAEI;EAAM,CAAC,GAAGN,cAAc,CAACO,EAAE,CAAC;IAChCH;EACJ,CAAC,CAAC;EAEF,MAAMI,MAAM,GAAG,MAAML,MAAM,CAACM,OAAO,CAACC,MAAM,CAAC;IACvCJ;EACJ,CAAC,CAAC;EACF,IAAIE,MAAM,CAACG,IAAI,EAAE;IACb;EACJ;EAEA,MAAMC,MAAM,GAAGP,YAAY,CAACQ,MAAM,CAACC,CAAC,IAAIA,CAAC,CAACC,MAAM,CAAC;IAAEX;EAAM,CAAC,CAAC,CAAC;EAC5D,IAAIQ,MAAM,CAACI,MAAM,KAAK,CAAC,EAAE;IACrB;AACR;AACA;IACQ,MAAM,IAAIjB,WAAW,CACjB,yDAAyD,EACzD,iCACJ,CAAC;EACL;EACA,MAAMkB,MAAM,GAAGL,MAAM,CAACA,MAAM,CAACI,MAAM,GAAG,CAAC,CAAC;EAExC,MAAMb,MAAM,CAACM,OAAO,CAACS,MAAM,CAAC;IACxBZ,KAAK;IACLK,IAAI,EAAE;MACF,GAAGM,MAAM,CAACN;IACd;EACJ,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|