@webiny/api-headless-cms-pg-os 0.0.0-unstable.0d717d18dd → 0.0.0-unstable.eb81deee7e
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/features/SyncWriter/BuildSyncRecord.d.ts +3 -1
- package/features/SyncWriter/BuildSyncRecord.js +8 -4
- package/features/SyncWriter/BuildSyncRecord.js.map +1 -1
- package/features/SyncWriter/RemoveEntry.js +2 -2
- package/features/SyncWriter/RemoveEntry.js.map +1 -1
- package/features/SyncWriter/RemoveLatest.js +1 -1
- package/features/SyncWriter/RemoveLatest.js.map +1 -1
- package/features/SyncWriter/RemovePublished.js +1 -1
- package/features/SyncWriter/RemovePublished.js.map +1 -1
- package/features/SyncWriter/WriteEntry.js +4 -1
- package/features/SyncWriter/WriteEntry.js.map +1 -1
- package/features/SyncWriter/WriteLatest.js +4 -1
- package/features/SyncWriter/WriteLatest.js.map +1 -1
- package/features/SyncWriter/WritePublished.js +4 -1
- package/features/SyncWriter/WritePublished.js.map +1 -1
- package/features/syncTableManager/SyncTableManager.js +4 -3
- package/features/syncTableManager/SyncTableManager.js.map +1 -1
- package/operations/entry/EntrySearchOperations.d.ts +2 -1
- package/operations/entry/EntrySearchOperations.js +6 -3
- package/operations/entry/EntrySearchOperations.js.map +1 -1
- package/operations/entry/search/getUniqueFieldValues.js +3 -2
- package/operations/entry/search/getUniqueFieldValues.js.map +1 -1
- package/operations/entry/search/list.js +3 -2
- package/operations/entry/search/list.js.map +1 -1
- package/operations/entry/search/types.d.ts +2 -0
- package/package.json +23 -23
- package/testing/simulatePgStream.js +6 -5
- package/testing/simulatePgStream.js.map +1 -1
|
@@ -2,11 +2,13 @@ import type { CmsEntryValues } from "@webiny/api-headless-cms/types/index.js";
|
|
|
2
2
|
import { BuildSyncRecord as Abstraction } from "./abstractions/BuildSyncRecord.js";
|
|
3
3
|
import { CmsEntryOpenSearchFieldIndexRegistry } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
|
|
4
4
|
import { CompressionHandler } from "@webiny/utils/exports/api.js";
|
|
5
|
+
import { CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/features/CmsModelOpenSearchIndex/CmsModelOpenSearchIndexProvider.js";
|
|
5
6
|
import { OperationType } from "@webiny/api-sync-to-opensearch/features/Operations/Operations.js";
|
|
6
7
|
declare class BuildSyncRecordImpl implements Abstraction.Interface {
|
|
7
8
|
private readonly fieldIndexRegistry;
|
|
8
9
|
private readonly compressionHandler;
|
|
9
|
-
|
|
10
|
+
private readonly indexProvider;
|
|
11
|
+
constructor(fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface, compressionHandler: CompressionHandler.Interface, indexProvider: CmsModelOpenSearchIndexProvider.Interface);
|
|
10
12
|
execute<T extends CmsEntryValues = CmsEntryValues>(params: Abstraction.Params<T>): Promise<{
|
|
11
13
|
id: string;
|
|
12
14
|
entryId: string;
|
|
@@ -3,12 +3,14 @@ import { CmsEntryOpenSearchFieldIndexRegistry } from "@webiny/api-headless-cms-u
|
|
|
3
3
|
import { CompressionHandler } from "@webiny/utils/exports/api.js";
|
|
4
4
|
import { transformEntryToIndex } from "@webiny/api-headless-cms-utils-os/operations/entry/transformations/transformEntryToIndex.js";
|
|
5
5
|
import { createLatestRecordType, createPublishedRecordType } from "@webiny/api-headless-cms-utils-os/operations/entry/recordType.js";
|
|
6
|
-
import {
|
|
6
|
+
import { CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/features/CmsModelOpenSearchIndex/CmsModelOpenSearchIndexProvider.js";
|
|
7
|
+
import { createConfigurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
|
|
7
8
|
import { OperationType } from "@webiny/api-sync-to-opensearch/features/Operations/Operations.js";
|
|
8
9
|
class BuildSyncRecordImpl {
|
|
9
|
-
constructor(fieldIndexRegistry, compressionHandler){
|
|
10
|
+
constructor(fieldIndexRegistry, compressionHandler, indexProvider){
|
|
10
11
|
this.fieldIndexRegistry = fieldIndexRegistry;
|
|
11
12
|
this.compressionHandler = compressionHandler;
|
|
13
|
+
this.indexProvider = indexProvider;
|
|
12
14
|
}
|
|
13
15
|
async execute(params) {
|
|
14
16
|
const { model, entry, storageEntry, kind } = params;
|
|
@@ -31,7 +33,8 @@ class BuildSyncRecordImpl {
|
|
|
31
33
|
__type: recordType
|
|
32
34
|
};
|
|
33
35
|
const compressed = await this.compressionHandler.compress(document);
|
|
34
|
-
const
|
|
36
|
+
const configurations = createConfigurations(this.indexProvider);
|
|
37
|
+
const { index } = await configurations.es({
|
|
35
38
|
model
|
|
36
39
|
});
|
|
37
40
|
return {
|
|
@@ -48,7 +51,8 @@ const BuildSyncRecord_BuildSyncRecord = BuildSyncRecord.createImplementation({
|
|
|
48
51
|
implementation: BuildSyncRecordImpl,
|
|
49
52
|
dependencies: [
|
|
50
53
|
CmsEntryOpenSearchFieldIndexRegistry,
|
|
51
|
-
CompressionHandler
|
|
54
|
+
CompressionHandler,
|
|
55
|
+
CmsModelOpenSearchIndexProvider
|
|
52
56
|
]
|
|
53
57
|
});
|
|
54
58
|
export { BuildSyncRecord_BuildSyncRecord as BuildSyncRecord };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/SyncWriter/BuildSyncRecord.js","sources":["../../../src/features/SyncWriter/BuildSyncRecord.ts"],"sourcesContent":["import type { CmsEntryValues } from \"@webiny/api-headless-cms/types/index.js\";\nimport { BuildSyncRecord as Abstraction } from \"./abstractions/BuildSyncRecord.js\";\nimport { CmsEntryOpenSearchFieldIndexRegistry } from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport { transformEntryToIndex } from \"@webiny/api-headless-cms-utils-os/operations/entry/transformations/transformEntryToIndex.js\";\nimport {\n createLatestRecordType,\n createPublishedRecordType\n} from \"@webiny/api-headless-cms-utils-os/operations/entry/recordType.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/SyncWriter/BuildSyncRecord.js","sources":["../../../src/features/SyncWriter/BuildSyncRecord.ts"],"sourcesContent":["import type { CmsEntryValues } from \"@webiny/api-headless-cms/types/index.js\";\nimport { BuildSyncRecord as Abstraction } from \"./abstractions/BuildSyncRecord.js\";\nimport { CmsEntryOpenSearchFieldIndexRegistry } from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport { transformEntryToIndex } from \"@webiny/api-headless-cms-utils-os/operations/entry/transformations/transformEntryToIndex.js\";\nimport {\n createLatestRecordType,\n createPublishedRecordType\n} from \"@webiny/api-headless-cms-utils-os/operations/entry/recordType.js\";\nimport { CmsModelOpenSearchIndexProvider } from \"@webiny/api-headless-cms-utils-os/features/CmsModelOpenSearchIndex/CmsModelOpenSearchIndexProvider.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { OperationType } from \"@webiny/api-sync-to-opensearch/features/Operations/Operations.js\";\n\nclass BuildSyncRecordImpl implements Abstraction.Interface {\n public constructor(\n private readonly fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n private readonly compressionHandler: CompressionHandler.Interface,\n private readonly indexProvider: CmsModelOpenSearchIndexProvider.Interface\n ) {}\n\n public async execute<T extends CmsEntryValues = CmsEntryValues>(params: Abstraction.Params<T>) {\n const { model, entry, storageEntry, kind } = params;\n\n const indexEntry = transformEntryToIndex({\n model,\n entry,\n storageEntry,\n fieldIndexRegistry: this.fieldIndexRegistry\n });\n\n const isLatest = kind === \"latest\";\n const recordType = isLatest ? createLatestRecordType() : createPublishedRecordType();\n\n const document = {\n ...indexEntry,\n ...(isLatest ? { latest: true } : { published: true }),\n TYPE: recordType,\n __type: recordType\n };\n\n const compressed = await this.compressionHandler.compress(document);\n const configurations = createConfigurations(this.indexProvider);\n const { index } = await configurations.es({ model });\n\n return {\n id: `${entry.entryId}:${isLatest ? \"L\" : \"P\"}`,\n entryId: entry.entryId,\n index,\n operation: OperationType.MODIFY,\n data: JSON.stringify(compressed),\n tenant: entry.tenant\n };\n }\n}\n\nexport const BuildSyncRecord = Abstraction.createImplementation({\n implementation: BuildSyncRecordImpl,\n dependencies: [\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n CmsModelOpenSearchIndexProvider\n ]\n});\n"],"names":["BuildSyncRecordImpl","fieldIndexRegistry","compressionHandler","indexProvider","params","model","entry","storageEntry","kind","indexEntry","transformEntryToIndex","isLatest","recordType","createLatestRecordType","createPublishedRecordType","document","compressed","configurations","createConfigurations","index","OperationType","JSON","BuildSyncRecord","Abstraction","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsModelOpenSearchIndexProvider"],"mappings":";;;;;;;;AAaA,MAAMA;IACF,YACqBC,kBAAkE,EAClEC,kBAAgD,EAChDC,aAAwD,CAC3E;aAHmBF,kBAAkB,GAAlBA;aACAC,kBAAkB,GAAlBA;aACAC,aAAa,GAAbA;IAClB;IAEH,MAAa,QAAmDC,MAA6B,EAAE;QAC3F,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAEC,YAAY,EAAEC,IAAI,EAAE,GAAGJ;QAE7C,MAAMK,aAAaC,sBAAsB;YACrCL;YACAC;YACAC;YACA,oBAAoB,IAAI,CAAC,kBAAkB;QAC/C;QAEA,MAAMI,WAAWH,AAAS,aAATA;QACjB,MAAMI,aAAaD,WAAWE,2BAA2BC;QAEzD,MAAMC,WAAW;YACb,GAAGN,UAAU;YACb,GAAIE,WAAW;gBAAE,QAAQ;YAAK,IAAI;gBAAE,WAAW;YAAK,CAAC;YACrD,MAAMC;YACN,QAAQA;QACZ;QAEA,MAAMI,aAAa,MAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAACD;QAC1D,MAAME,iBAAiBC,qBAAqB,IAAI,CAAC,aAAa;QAC9D,MAAM,EAAEC,KAAK,EAAE,GAAG,MAAMF,eAAe,EAAE,CAAC;YAAEZ;QAAM;QAElD,OAAO;YACH,IAAI,GAAGC,MAAM,OAAO,CAAC,CAAC,EAAEK,WAAW,MAAM,KAAK;YAC9C,SAASL,MAAM,OAAO;YACtBa;YACA,WAAWC,cAAc,MAAM;YAC/B,MAAMC,KAAK,SAAS,CAACL;YACrB,QAAQV,MAAM,MAAM;QACxB;IACJ;AACJ;AAEO,MAAMgB,kCAAkBC,gBAAAA,oBAAgC,CAAC;IAC5D,gBAAgBvB;IAChB,cAAc;QACVwB;QACAC;QACAC;KACH;AACL"}
|
|
@@ -5,8 +5,8 @@ class RemoveEntryImpl {
|
|
|
5
5
|
this.syncRowQuery = syncRowQuery;
|
|
6
6
|
}
|
|
7
7
|
async execute(params) {
|
|
8
|
-
const { entryId } = params;
|
|
9
|
-
await this.syncRowQuery.create().whereIn("id", [
|
|
8
|
+
const { model, entryId } = params;
|
|
9
|
+
await this.syncRowQuery.create().where("tenant", model.tenant).whereIn("id", [
|
|
10
10
|
`${entryId}:L`,
|
|
11
11
|
`${entryId}:P`
|
|
12
12
|
]).delete();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/SyncWriter/RemoveEntry.js","sources":["../../../src/features/SyncWriter/RemoveEntry.ts"],"sourcesContent":["import { RemoveEntry as Abstraction } from \"./abstractions/RemoveEntry.js\";\nimport { SyncRowQuery } from \"./abstractions/SyncRowQuery.js\";\n\nclass RemoveEntryImpl implements Abstraction.Interface {\n public constructor(private readonly syncRowQuery: SyncRowQuery.Interface) {}\n\n public async execute(params: Abstraction.Params) {\n const { entryId } = params;\n await this.syncRowQuery\n .create()\n .whereIn(\"id\", [`${entryId}:L`, `${entryId}:P`])\n .delete();\n }\n}\n\nexport const RemoveEntry = Abstraction.createImplementation({\n implementation: RemoveEntryImpl,\n dependencies: [SyncRowQuery]\n});\n"],"names":["RemoveEntryImpl","syncRowQuery","params","entryId","RemoveEntry","Abstraction","SyncRowQuery"],"mappings":";;AAGA,MAAMA;IACF,YAAoCC,YAAoC,CAAE;aAAtCA,YAAY,GAAZA;IAAuC;IAE3E,MAAa,QAAQC,MAA0B,EAAE;QAC7C,MAAM,EAAEC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"features/SyncWriter/RemoveEntry.js","sources":["../../../src/features/SyncWriter/RemoveEntry.ts"],"sourcesContent":["import { RemoveEntry as Abstraction } from \"./abstractions/RemoveEntry.js\";\nimport { SyncRowQuery } from \"./abstractions/SyncRowQuery.js\";\n\nclass RemoveEntryImpl implements Abstraction.Interface {\n public constructor(private readonly syncRowQuery: SyncRowQuery.Interface) {}\n\n public async execute(params: Abstraction.Params) {\n const { model, entryId } = params;\n await this.syncRowQuery\n .create()\n .where(\"tenant\", model.tenant)\n .whereIn(\"id\", [`${entryId}:L`, `${entryId}:P`])\n .delete();\n }\n}\n\nexport const RemoveEntry = Abstraction.createImplementation({\n implementation: RemoveEntryImpl,\n dependencies: [SyncRowQuery]\n});\n"],"names":["RemoveEntryImpl","syncRowQuery","params","model","entryId","RemoveEntry","Abstraction","SyncRowQuery"],"mappings":";;AAGA,MAAMA;IACF,YAAoCC,YAAoC,CAAE;aAAtCA,YAAY,GAAZA;IAAuC;IAE3E,MAAa,QAAQC,MAA0B,EAAE;QAC7C,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAE,GAAGF;QAC3B,MAAM,IAAI,CAAC,YAAY,CAClB,MAAM,GACN,KAAK,CAAC,UAAUC,MAAM,MAAM,EAC5B,OAAO,CAAC,MAAM;YAAC,GAAGC,QAAQ,EAAE,CAAC;YAAE,GAAGA,QAAQ,EAAE,CAAC;SAAC,EAC9C,MAAM;IACf;AACJ;AAEO,MAAMC,0BAAcC,YAAAA,oBAAgC,CAAC;IACxD,gBAAgBN;IAChB,cAAc;QAACO;KAAa;AAChC"}
|
|
@@ -5,7 +5,7 @@ class RemoveLatestImpl {
|
|
|
5
5
|
this.syncRowQuery = syncRowQuery;
|
|
6
6
|
}
|
|
7
7
|
async execute(params) {
|
|
8
|
-
await this.syncRowQuery.create().where("id", `${params.entryId}:L`).delete();
|
|
8
|
+
await this.syncRowQuery.create().where("tenant", params.model.tenant).andWhere("id", `${params.entryId}:L`).delete();
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
const RemoveLatest_RemoveLatest = RemoveLatest.createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/SyncWriter/RemoveLatest.js","sources":["../../../src/features/SyncWriter/RemoveLatest.ts"],"sourcesContent":["import { RemoveLatest as Abstraction } from \"./abstractions/RemoveLatest.js\";\nimport { SyncRowQuery } from \"./abstractions/SyncRowQuery.js\";\n\nclass RemoveLatestImpl implements Abstraction.Interface {\n public constructor(private readonly syncRowQuery: SyncRowQuery.Interface) {}\n\n public async execute(params: Abstraction.Params) {\n await this.syncRowQuery.create().where(\"id\", `${params.entryId}:L`).delete();\n }\n}\n\nexport const RemoveLatest = Abstraction.createImplementation({\n implementation: RemoveLatestImpl,\n dependencies: [SyncRowQuery]\n});\n"],"names":["RemoveLatestImpl","syncRowQuery","params","RemoveLatest","Abstraction","SyncRowQuery"],"mappings":";;AAGA,MAAMA;IACF,YAAoCC,YAAoC,CAAE;aAAtCA,YAAY,GAAZA;IAAuC;IAE3E,MAAa,QAAQC,MAA0B,EAAE;QAC7C,MAAM,IAAI,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"features/SyncWriter/RemoveLatest.js","sources":["../../../src/features/SyncWriter/RemoveLatest.ts"],"sourcesContent":["import { RemoveLatest as Abstraction } from \"./abstractions/RemoveLatest.js\";\nimport { SyncRowQuery } from \"./abstractions/SyncRowQuery.js\";\n\nclass RemoveLatestImpl implements Abstraction.Interface {\n public constructor(private readonly syncRowQuery: SyncRowQuery.Interface) {}\n\n public async execute(params: Abstraction.Params) {\n await this.syncRowQuery\n .create()\n .where(\"tenant\", params.model.tenant)\n .andWhere(\"id\", `${params.entryId}:L`)\n .delete();\n }\n}\n\nexport const RemoveLatest = Abstraction.createImplementation({\n implementation: RemoveLatestImpl,\n dependencies: [SyncRowQuery]\n});\n"],"names":["RemoveLatestImpl","syncRowQuery","params","RemoveLatest","Abstraction","SyncRowQuery"],"mappings":";;AAGA,MAAMA;IACF,YAAoCC,YAAoC,CAAE;aAAtCA,YAAY,GAAZA;IAAuC;IAE3E,MAAa,QAAQC,MAA0B,EAAE;QAC7C,MAAM,IAAI,CAAC,YAAY,CAClB,MAAM,GACN,KAAK,CAAC,UAAUA,OAAO,KAAK,CAAC,MAAM,EACnC,QAAQ,CAAC,MAAM,GAAGA,OAAO,OAAO,CAAC,EAAE,CAAC,EACpC,MAAM;IACf;AACJ;AAEO,MAAMC,4BAAeC,aAAAA,oBAAgC,CAAC;IACzD,gBAAgBJ;IAChB,cAAc;QAACK;KAAa;AAChC"}
|
|
@@ -5,7 +5,7 @@ class RemovePublishedImpl {
|
|
|
5
5
|
this.syncRowQuery = syncRowQuery;
|
|
6
6
|
}
|
|
7
7
|
async execute(params) {
|
|
8
|
-
await this.syncRowQuery.create().where("id", `${params.entryId}:P`).delete();
|
|
8
|
+
await this.syncRowQuery.create().where("tenant", params.model.tenant).andWhere("id", `${params.entryId}:P`).delete();
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
const RemovePublished_RemovePublished = RemovePublished.createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/SyncWriter/RemovePublished.js","sources":["../../../src/features/SyncWriter/RemovePublished.ts"],"sourcesContent":["import { RemovePublished as Abstraction } from \"./abstractions/RemovePublished.js\";\nimport { SyncRowQuery } from \"./abstractions/SyncRowQuery.js\";\n\nclass RemovePublishedImpl implements Abstraction.Interface {\n public constructor(private readonly syncRowQuery: SyncRowQuery.Interface) {}\n\n public async execute(params: Abstraction.Params) {\n await this.syncRowQuery.create().where(\"id\", `${params.entryId}:P`).delete();\n }\n}\n\nexport const RemovePublished = Abstraction.createImplementation({\n implementation: RemovePublishedImpl,\n dependencies: [SyncRowQuery]\n});\n"],"names":["RemovePublishedImpl","syncRowQuery","params","RemovePublished","Abstraction","SyncRowQuery"],"mappings":";;AAGA,MAAMA;IACF,YAAoCC,YAAoC,CAAE;aAAtCA,YAAY,GAAZA;IAAuC;IAE3E,MAAa,QAAQC,MAA0B,EAAE;QAC7C,MAAM,IAAI,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"features/SyncWriter/RemovePublished.js","sources":["../../../src/features/SyncWriter/RemovePublished.ts"],"sourcesContent":["import { RemovePublished as Abstraction } from \"./abstractions/RemovePublished.js\";\nimport { SyncRowQuery } from \"./abstractions/SyncRowQuery.js\";\n\nclass RemovePublishedImpl implements Abstraction.Interface {\n public constructor(private readonly syncRowQuery: SyncRowQuery.Interface) {}\n\n public async execute(params: Abstraction.Params) {\n await this.syncRowQuery\n .create()\n .where(\"tenant\", params.model.tenant)\n .andWhere(\"id\", `${params.entryId}:P`)\n .delete();\n }\n}\n\nexport const RemovePublished = Abstraction.createImplementation({\n implementation: RemovePublishedImpl,\n dependencies: [SyncRowQuery]\n});\n"],"names":["RemovePublishedImpl","syncRowQuery","params","RemovePublished","Abstraction","SyncRowQuery"],"mappings":";;AAGA,MAAMA;IACF,YAAoCC,YAAoC,CAAE;aAAtCA,YAAY,GAAZA;IAAuC;IAE3E,MAAa,QAAQC,MAA0B,EAAE;QAC7C,MAAM,IAAI,CAAC,YAAY,CAClB,MAAM,GACN,KAAK,CAAC,UAAUA,OAAO,KAAK,CAAC,MAAM,EACnC,QAAQ,CAAC,MAAM,GAAGA,OAAO,OAAO,CAAC,EAAE,CAAC,EACpC,MAAM;IACf;AACJ;AAEO,MAAMC,kCAAkBC,gBAAAA,oBAAgC,CAAC;IAC5D,gBAAgBJ;IAChB,cAAc;QAACK;KAAa;AAChC"}
|
|
@@ -17,7 +17,10 @@ class WriteEntryImpl {
|
|
|
17
17
|
...params,
|
|
18
18
|
kind: "published"
|
|
19
19
|
}));
|
|
20
|
-
await this.syncRowQuery.create().insert(rows).onConflict(
|
|
20
|
+
await this.syncRowQuery.create().insert(rows).onConflict([
|
|
21
|
+
"tenant",
|
|
22
|
+
"id"
|
|
23
|
+
]).merge();
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
26
|
const WriteEntry_WriteEntry = WriteEntry.createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/SyncWriter/WriteEntry.js","sources":["../../../src/features/SyncWriter/WriteEntry.ts"],"sourcesContent":["import type { CmsEntryValues } from \"@webiny/api-headless-cms/types/index.js\";\nimport { WriteEntry as Abstraction } from \"./abstractions/WriteEntry.js\";\nimport { BuildSyncRecord } from \"./abstractions/BuildSyncRecord.js\";\nimport { SyncRowQuery } from \"./abstractions/SyncRowQuery.js\";\nimport type { ISyncRow } from \"~/types.js\";\n\nclass WriteEntryImpl implements Abstraction.Interface {\n public constructor(\n private readonly buildSyncRecord: BuildSyncRecord.Interface,\n private readonly syncRowQuery: SyncRowQuery.Interface\n ) {}\n\n public async execute<T extends CmsEntryValues = CmsEntryValues>(params: Abstraction.Params<T>) {\n const rows: ISyncRow[] = [\n await this.buildSyncRecord.execute({ ...params, kind: \"latest\" })\n ];\n\n if (params.entry.status === \"published\") {\n rows.push(await this.buildSyncRecord.execute({ ...params, kind: \"published\" }));\n }\n\n await this.syncRowQuery.create().insert(rows).onConflict(\"id\").merge();\n }\n}\n\nexport const WriteEntry = Abstraction.createImplementation({\n implementation: WriteEntryImpl,\n dependencies: [BuildSyncRecord, SyncRowQuery]\n});\n"],"names":["WriteEntryImpl","buildSyncRecord","syncRowQuery","params","rows","WriteEntry","Abstraction","BuildSyncRecord","SyncRowQuery"],"mappings":";;;AAMA,MAAMA;IACF,YACqBC,eAA0C,EAC1CC,YAAoC,CACvD;aAFmBD,eAAe,GAAfA;aACAC,YAAY,GAAZA;IAClB;IAEH,MAAa,QAAmDC,MAA6B,EAAE;QAC3F,MAAMC,OAAmB;YACrB,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC;gBAAE,GAAGD,MAAM;gBAAE,MAAM;YAAS;SAClE;QAED,IAAIA,AAAwB,gBAAxBA,OAAO,KAAK,CAAC,MAAM,EACnBC,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC;YAAE,GAAGD,MAAM;YAAE,MAAM;QAAY;QAGhF,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,MAAM,CAACC,MAAM,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"features/SyncWriter/WriteEntry.js","sources":["../../../src/features/SyncWriter/WriteEntry.ts"],"sourcesContent":["import type { CmsEntryValues } from \"@webiny/api-headless-cms/types/index.js\";\nimport { WriteEntry as Abstraction } from \"./abstractions/WriteEntry.js\";\nimport { BuildSyncRecord } from \"./abstractions/BuildSyncRecord.js\";\nimport { SyncRowQuery } from \"./abstractions/SyncRowQuery.js\";\nimport type { ISyncRow } from \"~/types.js\";\n\nclass WriteEntryImpl implements Abstraction.Interface {\n public constructor(\n private readonly buildSyncRecord: BuildSyncRecord.Interface,\n private readonly syncRowQuery: SyncRowQuery.Interface\n ) {}\n\n public async execute<T extends CmsEntryValues = CmsEntryValues>(params: Abstraction.Params<T>) {\n const rows: ISyncRow[] = [\n await this.buildSyncRecord.execute({ ...params, kind: \"latest\" })\n ];\n\n if (params.entry.status === \"published\") {\n rows.push(await this.buildSyncRecord.execute({ ...params, kind: \"published\" }));\n }\n\n await this.syncRowQuery.create().insert(rows).onConflict([\"tenant\", \"id\"]).merge();\n }\n}\n\nexport const WriteEntry = Abstraction.createImplementation({\n implementation: WriteEntryImpl,\n dependencies: [BuildSyncRecord, SyncRowQuery]\n});\n"],"names":["WriteEntryImpl","buildSyncRecord","syncRowQuery","params","rows","WriteEntry","Abstraction","BuildSyncRecord","SyncRowQuery"],"mappings":";;;AAMA,MAAMA;IACF,YACqBC,eAA0C,EAC1CC,YAAoC,CACvD;aAFmBD,eAAe,GAAfA;aACAC,YAAY,GAAZA;IAClB;IAEH,MAAa,QAAmDC,MAA6B,EAAE;QAC3F,MAAMC,OAAmB;YACrB,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC;gBAAE,GAAGD,MAAM;gBAAE,MAAM;YAAS;SAClE;QAED,IAAIA,AAAwB,gBAAxBA,OAAO,KAAK,CAAC,MAAM,EACnBC,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC;YAAE,GAAGD,MAAM;YAAE,MAAM;QAAY;QAGhF,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,MAAM,CAACC,MAAM,UAAU,CAAC;YAAC;YAAU;SAAK,EAAE,KAAK;IACpF;AACJ;AAEO,MAAMC,wBAAaC,WAAAA,oBAAgC,CAAC;IACvD,gBAAgBN;IAChB,cAAc;QAACO;QAAiBC;KAAa;AACjD"}
|
|
@@ -11,7 +11,10 @@ class WriteLatestImpl {
|
|
|
11
11
|
...params,
|
|
12
12
|
kind: "latest"
|
|
13
13
|
});
|
|
14
|
-
await this.syncRowQuery.create().insert(row).onConflict(
|
|
14
|
+
await this.syncRowQuery.create().insert(row).onConflict([
|
|
15
|
+
"tenant",
|
|
16
|
+
"id"
|
|
17
|
+
]).merge();
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
const WriteLatest_WriteLatest = WriteLatest.createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/SyncWriter/WriteLatest.js","sources":["../../../src/features/SyncWriter/WriteLatest.ts"],"sourcesContent":["import type { CmsEntryValues } from \"@webiny/api-headless-cms/types/index.js\";\nimport { WriteLatest as Abstraction } from \"./abstractions/WriteLatest.js\";\nimport { BuildSyncRecord } from \"./abstractions/BuildSyncRecord.js\";\nimport { SyncRowQuery } from \"./abstractions/SyncRowQuery.js\";\n\nclass WriteLatestImpl implements Abstraction.Interface {\n public constructor(\n private readonly buildSyncRecord: BuildSyncRecord.Interface,\n private readonly syncRowQuery: SyncRowQuery.Interface\n ) {}\n\n public async execute<T extends CmsEntryValues = CmsEntryValues>(params: Abstraction.Params<T>) {\n const row = await this.buildSyncRecord.execute({ ...params, kind: \"latest\" });\n await this.syncRowQuery.create().insert(row).onConflict(\"id\").merge();\n }\n}\n\nexport const WriteLatest = Abstraction.createImplementation({\n implementation: WriteLatestImpl,\n dependencies: [BuildSyncRecord, SyncRowQuery]\n});\n"],"names":["WriteLatestImpl","buildSyncRecord","syncRowQuery","params","row","WriteLatest","Abstraction","BuildSyncRecord","SyncRowQuery"],"mappings":";;;AAKA,MAAMA;IACF,YACqBC,eAA0C,EAC1CC,YAAoC,CACvD;aAFmBD,eAAe,GAAfA;aACAC,YAAY,GAAZA;IAClB;IAEH,MAAa,QAAmDC,MAA6B,EAAE;QAC3F,MAAMC,MAAM,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC;YAAE,GAAGD,MAAM;YAAE,MAAM;QAAS;QAC3E,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,MAAM,CAACC,KAAK,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"features/SyncWriter/WriteLatest.js","sources":["../../../src/features/SyncWriter/WriteLatest.ts"],"sourcesContent":["import type { CmsEntryValues } from \"@webiny/api-headless-cms/types/index.js\";\nimport { WriteLatest as Abstraction } from \"./abstractions/WriteLatest.js\";\nimport { BuildSyncRecord } from \"./abstractions/BuildSyncRecord.js\";\nimport { SyncRowQuery } from \"./abstractions/SyncRowQuery.js\";\n\nclass WriteLatestImpl implements Abstraction.Interface {\n public constructor(\n private readonly buildSyncRecord: BuildSyncRecord.Interface,\n private readonly syncRowQuery: SyncRowQuery.Interface\n ) {}\n\n public async execute<T extends CmsEntryValues = CmsEntryValues>(params: Abstraction.Params<T>) {\n const row = await this.buildSyncRecord.execute({ ...params, kind: \"latest\" });\n await this.syncRowQuery.create().insert(row).onConflict([\"tenant\", \"id\"]).merge();\n }\n}\n\nexport const WriteLatest = Abstraction.createImplementation({\n implementation: WriteLatestImpl,\n dependencies: [BuildSyncRecord, SyncRowQuery]\n});\n"],"names":["WriteLatestImpl","buildSyncRecord","syncRowQuery","params","row","WriteLatest","Abstraction","BuildSyncRecord","SyncRowQuery"],"mappings":";;;AAKA,MAAMA;IACF,YACqBC,eAA0C,EAC1CC,YAAoC,CACvD;aAFmBD,eAAe,GAAfA;aACAC,YAAY,GAAZA;IAClB;IAEH,MAAa,QAAmDC,MAA6B,EAAE;QAC3F,MAAMC,MAAM,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC;YAAE,GAAGD,MAAM;YAAE,MAAM;QAAS;QAC3E,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,MAAM,CAACC,KAAK,UAAU,CAAC;YAAC;YAAU;SAAK,EAAE,KAAK;IACnF;AACJ;AAEO,MAAMC,0BAAcC,YAAAA,oBAAgC,CAAC;IACxD,gBAAgBN;IAChB,cAAc;QAACO;QAAiBC;KAAa;AACjD"}
|
|
@@ -11,7 +11,10 @@ class WritePublishedImpl {
|
|
|
11
11
|
...params,
|
|
12
12
|
kind: "published"
|
|
13
13
|
});
|
|
14
|
-
await this.syncRowQuery.create().insert(row).onConflict(
|
|
14
|
+
await this.syncRowQuery.create().insert(row).onConflict([
|
|
15
|
+
"tenant",
|
|
16
|
+
"id"
|
|
17
|
+
]).merge();
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
const WritePublished_WritePublished = WritePublished.createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/SyncWriter/WritePublished.js","sources":["../../../src/features/SyncWriter/WritePublished.ts"],"sourcesContent":["import type { CmsEntryValues } from \"@webiny/api-headless-cms/types/index.js\";\nimport { WritePublished as Abstraction } from \"./abstractions/WritePublished.js\";\nimport { BuildSyncRecord } from \"./abstractions/BuildSyncRecord.js\";\nimport { SyncRowQuery } from \"./abstractions/SyncRowQuery.js\";\n\nclass WritePublishedImpl implements Abstraction.Interface {\n public constructor(\n private readonly buildSyncRecord: BuildSyncRecord.Interface,\n private readonly syncRowQuery: SyncRowQuery.Interface\n ) {}\n\n public async execute<T extends CmsEntryValues = CmsEntryValues>(params: Abstraction.Params<T>) {\n const row = await this.buildSyncRecord.execute({ ...params, kind: \"published\" });\n await this.syncRowQuery.create().insert(row).onConflict(\"id\").merge();\n }\n}\n\nexport const WritePublished = Abstraction.createImplementation({\n implementation: WritePublishedImpl,\n dependencies: [BuildSyncRecord, SyncRowQuery]\n});\n"],"names":["WritePublishedImpl","buildSyncRecord","syncRowQuery","params","row","WritePublished","Abstraction","BuildSyncRecord","SyncRowQuery"],"mappings":";;;AAKA,MAAMA;IACF,YACqBC,eAA0C,EAC1CC,YAAoC,CACvD;aAFmBD,eAAe,GAAfA;aACAC,YAAY,GAAZA;IAClB;IAEH,MAAa,QAAmDC,MAA6B,EAAE;QAC3F,MAAMC,MAAM,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC;YAAE,GAAGD,MAAM;YAAE,MAAM;QAAY;QAC9E,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,MAAM,CAACC,KAAK,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"features/SyncWriter/WritePublished.js","sources":["../../../src/features/SyncWriter/WritePublished.ts"],"sourcesContent":["import type { CmsEntryValues } from \"@webiny/api-headless-cms/types/index.js\";\nimport { WritePublished as Abstraction } from \"./abstractions/WritePublished.js\";\nimport { BuildSyncRecord } from \"./abstractions/BuildSyncRecord.js\";\nimport { SyncRowQuery } from \"./abstractions/SyncRowQuery.js\";\n\nclass WritePublishedImpl implements Abstraction.Interface {\n public constructor(\n private readonly buildSyncRecord: BuildSyncRecord.Interface,\n private readonly syncRowQuery: SyncRowQuery.Interface\n ) {}\n\n public async execute<T extends CmsEntryValues = CmsEntryValues>(params: Abstraction.Params<T>) {\n const row = await this.buildSyncRecord.execute({ ...params, kind: \"published\" });\n await this.syncRowQuery.create().insert(row).onConflict([\"tenant\", \"id\"]).merge();\n }\n}\n\nexport const WritePublished = Abstraction.createImplementation({\n implementation: WritePublishedImpl,\n dependencies: [BuildSyncRecord, SyncRowQuery]\n});\n"],"names":["WritePublishedImpl","buildSyncRecord","syncRowQuery","params","row","WritePublished","Abstraction","BuildSyncRecord","SyncRowQuery"],"mappings":";;;AAKA,MAAMA;IACF,YACqBC,eAA0C,EAC1CC,YAAoC,CACvD;aAFmBD,eAAe,GAAfA;aACAC,YAAY,GAAZA;IAClB;IAEH,MAAa,QAAmDC,MAA6B,EAAE;QAC3F,MAAMC,MAAM,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC;YAAE,GAAGD,MAAM;YAAE,MAAM;QAAY;QAC9E,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,MAAM,CAACC,KAAK,UAAU,CAAC;YAAC;YAAU;SAAK,EAAE,KAAK;IACnF;AACJ;AAEO,MAAMC,gCAAiBC,eAAAA,oBAAgC,CAAC;IAC3D,gBAAgBN;IAChB,cAAc;QAACO;QAAiBC;KAAa;AACjD"}
|
|
@@ -33,14 +33,15 @@ class SyncTableManagerImpl {
|
|
|
33
33
|
async createTable() {
|
|
34
34
|
try {
|
|
35
35
|
await this.knex.client.schema.createTable(this.tableName, (table)=>{
|
|
36
|
-
table.text("id").
|
|
36
|
+
table.text("id").notNullable();
|
|
37
37
|
table.text("entryId").notNullable();
|
|
38
38
|
table.text("index").notNullable();
|
|
39
39
|
table.text("operation").notNullable();
|
|
40
40
|
table.text("data").notNullable();
|
|
41
41
|
table.text("tenant").notNullable();
|
|
42
|
-
table.
|
|
43
|
-
"tenant"
|
|
42
|
+
table.primary([
|
|
43
|
+
"tenant",
|
|
44
|
+
"id"
|
|
44
45
|
]);
|
|
45
46
|
});
|
|
46
47
|
} catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/syncTableManager/SyncTableManager.js","sources":["../../../src/features/syncTableManager/SyncTableManager.ts"],"sourcesContent":["import { KnexClient } from \"@webiny/api-core-sql\";\nimport { SyncTableManager as SyncTableManagerAbstraction } from \"./abstractions.js\";\nimport { TableNameResolver } from \"@webiny/api-headless-cms-sql/features/tableNameResolver/abstractions.js\";\n\nclass SyncTableManagerImpl implements SyncTableManagerAbstraction.Interface {\n private readonly knex;\n private readonly tableName;\n private initialized = false;\n private initPromise?: Promise<void>;\n\n constructor(knex: KnexClient.Interface, tableNameResolver: TableNameResolver.Interface) {\n this.knex = knex;\n this.tableName = tableNameResolver.resolve(\"os_sync\");\n\n const g = globalThis as Record<string, unknown>;\n const managers = (g.__sqlTableManagers ??= []) as SyncTableManagerAbstraction.Interface[];\n managers.push(this);\n }\n\n public reset(): void {\n this.initialized = false;\n this.initPromise = undefined;\n }\n\n public async ensureTable(): Promise<void> {\n if (this.initialized) {\n return;\n }\n if (!this.initPromise) {\n this.initPromise = this.doEnsureTable().catch(err => {\n this.initPromise = undefined;\n throw err;\n });\n }\n return this.initPromise;\n }\n\n public getTableName(): string {\n return this.tableName;\n }\n\n private async doEnsureTable(): Promise<void> {\n const exists = await this.knex.client.schema.hasTable(this.tableName);\n\n if (!exists) {\n await this.createTable();\n }\n\n this.initialized = true;\n }\n\n private async createTable(): Promise<void> {\n try {\n await this.knex.client.schema.createTable(this.tableName, table => {\n table.text(\"id\").
|
|
1
|
+
{"version":3,"file":"features/syncTableManager/SyncTableManager.js","sources":["../../../src/features/syncTableManager/SyncTableManager.ts"],"sourcesContent":["import { KnexClient } from \"@webiny/api-core-sql\";\nimport { SyncTableManager as SyncTableManagerAbstraction } from \"./abstractions.js\";\nimport { TableNameResolver } from \"@webiny/api-headless-cms-sql/features/tableNameResolver/abstractions.js\";\n\nclass SyncTableManagerImpl implements SyncTableManagerAbstraction.Interface {\n private readonly knex;\n private readonly tableName;\n private initialized = false;\n private initPromise?: Promise<void>;\n\n constructor(knex: KnexClient.Interface, tableNameResolver: TableNameResolver.Interface) {\n this.knex = knex;\n this.tableName = tableNameResolver.resolve(\"os_sync\");\n\n const g = globalThis as Record<string, unknown>;\n const managers = (g.__sqlTableManagers ??= []) as SyncTableManagerAbstraction.Interface[];\n managers.push(this);\n }\n\n public reset(): void {\n this.initialized = false;\n this.initPromise = undefined;\n }\n\n public async ensureTable(): Promise<void> {\n if (this.initialized) {\n return;\n }\n if (!this.initPromise) {\n this.initPromise = this.doEnsureTable().catch(err => {\n this.initPromise = undefined;\n throw err;\n });\n }\n return this.initPromise;\n }\n\n public getTableName(): string {\n return this.tableName;\n }\n\n private async doEnsureTable(): Promise<void> {\n const exists = await this.knex.client.schema.hasTable(this.tableName);\n\n if (!exists) {\n await this.createTable();\n }\n\n this.initialized = true;\n }\n\n private async createTable(): Promise<void> {\n try {\n await this.knex.client.schema.createTable(this.tableName, table => {\n table.text(\"id\").notNullable();\n table.text(\"entryId\").notNullable();\n table.text(\"index\").notNullable();\n table.text(\"operation\").notNullable();\n table.text(\"data\").notNullable();\n table.text(\"tenant\").notNullable();\n\n table.primary([\"tenant\", \"id\"]);\n });\n } catch (err) {\n if (await this.knex.client.schema.hasTable(this.tableName)) {\n return;\n }\n throw err;\n }\n }\n}\n\nexport const SyncTableManager = SyncTableManagerAbstraction.createImplementation({\n implementation: SyncTableManagerImpl,\n dependencies: [KnexClient, TableNameResolver]\n});\n"],"names":["SyncTableManagerImpl","knex","tableNameResolver","g","globalThis","managers","undefined","err","exists","table","SyncTableManager","SyncTableManagerAbstraction","KnexClient","TableNameResolver"],"mappings":";;;AAIA,MAAMA;IAMF,YAAYC,IAA0B,EAAEC,iBAA8C,CAAE;aAHhF,WAAW,GAAG;QAIlB,IAAI,CAAC,IAAI,GAAGD;QACZ,IAAI,CAAC,SAAS,GAAGC,kBAAkB,OAAO,CAAC;QAE3C,MAAMC,IAAIC;QACV,MAAMC,WAAYF,EAAE,kBAAkB,KAAK,EAAE;QAC7CE,SAAS,IAAI,CAAC,IAAI;IACtB;IAEO,QAAc;QACjB,IAAI,CAAC,WAAW,GAAG;QACnB,IAAI,CAAC,WAAW,GAAGC;IACvB;IAEA,MAAa,cAA6B;QACtC,IAAI,IAAI,CAAC,WAAW,EAChB;QAEJ,IAAI,CAAC,IAAI,CAAC,WAAW,EACjB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,aAAa,GAAG,KAAK,CAACC,CAAAA;YAC1C,IAAI,CAAC,WAAW,GAAGD;YACnB,MAAMC;QACV;QAEJ,OAAO,IAAI,CAAC,WAAW;IAC3B;IAEO,eAAuB;QAC1B,OAAO,IAAI,CAAC,SAAS;IACzB;IAEA,MAAc,gBAA+B;QACzC,MAAMC,SAAS,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS;QAEpE,IAAI,CAACA,QACD,MAAM,IAAI,CAAC,WAAW;QAG1B,IAAI,CAAC,WAAW,GAAG;IACvB;IAEA,MAAc,cAA6B;QACvC,IAAI;YACA,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,EAAEC,CAAAA;gBACtDA,MAAM,IAAI,CAAC,MAAM,WAAW;gBAC5BA,MAAM,IAAI,CAAC,WAAW,WAAW;gBACjCA,MAAM,IAAI,CAAC,SAAS,WAAW;gBAC/BA,MAAM,IAAI,CAAC,aAAa,WAAW;gBACnCA,MAAM,IAAI,CAAC,QAAQ,WAAW;gBAC9BA,MAAM,IAAI,CAAC,UAAU,WAAW;gBAEhCA,MAAM,OAAO,CAAC;oBAAC;oBAAU;iBAAK;YAClC;QACJ,EAAE,OAAOF,KAAK;YACV,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,GACrD;YAEJ,MAAMA;QACV;IACJ;AACJ;AAEO,MAAMG,oCAAmBC,iBAAAA,oBAAgD,CAAC;IAC7E,gBAAgBX;IAChB,cAAc;QAACY;QAAYC;KAAkB;AACjD"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { IEntrySearchOperations } from "./abstractions/EntrySearchOperations.js";
|
|
2
2
|
import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
|
|
3
3
|
import { CmsEntryOpenSearchBodyBuilder, CmsEntryOpenSearchFieldIndexRegistry } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
|
|
4
|
+
import { CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/features/CmsModelOpenSearchIndex/CmsModelOpenSearchIndexProvider.js";
|
|
4
5
|
import { CmsModelFieldToGraphQLRegistry } from "@webiny/api-headless-cms/exports/api/cms/graphql.js";
|
|
5
6
|
import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
6
7
|
declare class EntrySearchOperationsImpl implements IEntrySearchOperations {
|
|
7
8
|
readonly list: IEntrySearchOperations["list"];
|
|
8
9
|
readonly get: IEntrySearchOperations["get"];
|
|
9
10
|
readonly getUniqueFieldValues: IEntrySearchOperations["getUniqueFieldValues"];
|
|
10
|
-
constructor(openSearchClient: OpenSearchClient.Interface, bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface, fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface, fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface, storageModelProvider: CmsStorageModelProvider.Interface);
|
|
11
|
+
constructor(openSearchClient: OpenSearchClient.Interface, bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface, fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface, fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface, storageModelProvider: CmsStorageModelProvider.Interface, indexProvider: CmsModelOpenSearchIndexProvider.Interface);
|
|
11
12
|
}
|
|
12
13
|
export declare const EntrySearchOperations: typeof EntrySearchOperationsImpl & {
|
|
13
14
|
__abstraction: import("@webiny/di").Abstraction<IEntrySearchOperations>;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { EntrySearchOperations } from "./abstractions/EntrySearchOperations.js";
|
|
2
2
|
import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
|
|
3
3
|
import { CmsEntryOpenSearchBodyBuilder, CmsEntryOpenSearchFieldIndexRegistry } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
|
|
4
|
+
import { CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/features/CmsModelOpenSearchIndex/CmsModelOpenSearchIndexProvider.js";
|
|
4
5
|
import { CmsModelFieldToGraphQLRegistry } from "@webiny/api-headless-cms/exports/api/cms/graphql.js";
|
|
5
6
|
import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
6
7
|
import { createListOperation } from "./search/list.js";
|
|
7
8
|
import { createGetOperation } from "./search/get.js";
|
|
8
9
|
import { createGetUniqueFieldValuesOperation } from "./search/getUniqueFieldValues.js";
|
|
9
10
|
class EntrySearchOperationsImpl {
|
|
10
|
-
constructor(openSearchClient, bodyBuilder, fieldRegistry, fieldIndexRegistry, storageModelProvider){
|
|
11
|
+
constructor(openSearchClient, bodyBuilder, fieldRegistry, fieldIndexRegistry, storageModelProvider, indexProvider){
|
|
11
12
|
const deps = {
|
|
12
13
|
elasticsearch: openSearchClient.use(),
|
|
13
14
|
bodyBuilder,
|
|
14
15
|
fieldRegistry,
|
|
15
16
|
fieldIndexRegistry,
|
|
16
|
-
getStorageOperationsModel: (model)=>storageModelProvider.getModel(model)
|
|
17
|
+
getStorageOperationsModel: (model)=>storageModelProvider.getModel(model),
|
|
18
|
+
indexProvider
|
|
17
19
|
};
|
|
18
20
|
this.list = createListOperation(deps);
|
|
19
21
|
this.get = createGetOperation(deps);
|
|
@@ -27,7 +29,8 @@ const EntrySearchOperations_EntrySearchOperations = EntrySearchOperations.create
|
|
|
27
29
|
CmsEntryOpenSearchBodyBuilder,
|
|
28
30
|
CmsModelFieldToGraphQLRegistry,
|
|
29
31
|
CmsEntryOpenSearchFieldIndexRegistry,
|
|
30
|
-
CmsStorageModelProvider
|
|
32
|
+
CmsStorageModelProvider,
|
|
33
|
+
CmsModelOpenSearchIndexProvider
|
|
31
34
|
]
|
|
32
35
|
});
|
|
33
36
|
export { EntrySearchOperations_EntrySearchOperations as EntrySearchOperations };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/EntrySearchOperations.js","sources":["../../../src/operations/entry/EntrySearchOperations.ts"],"sourcesContent":["import { EntrySearchOperations as Abstraction } from \"./abstractions/EntrySearchOperations.js\";\nimport type { IEntrySearchOperations } from \"./abstractions/EntrySearchOperations.js\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport {\n CmsEntryOpenSearchBodyBuilder,\n CmsEntryOpenSearchFieldIndexRegistry\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/exports/api/cms/graphql.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport type { SearchOperationDeps } from \"./search/types.js\";\nimport { createListOperation } from \"./search/list.js\";\nimport { createGetOperation } from \"./search/get.js\";\nimport { createGetUniqueFieldValuesOperation } from \"./search/getUniqueFieldValues.js\";\n\nclass EntrySearchOperationsImpl implements IEntrySearchOperations {\n public readonly list: IEntrySearchOperations[\"list\"];\n public readonly get: IEntrySearchOperations[\"get\"];\n public readonly getUniqueFieldValues: IEntrySearchOperations[\"getUniqueFieldValues\"];\n\n public constructor(\n openSearchClient: OpenSearchClient.Interface,\n bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface,\n fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface,\n fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n storageModelProvider: CmsStorageModelProvider.Interface\n ) {\n const deps: SearchOperationDeps = {\n elasticsearch: openSearchClient.use(),\n bodyBuilder,\n fieldRegistry,\n fieldIndexRegistry,\n getStorageOperationsModel: model => storageModelProvider.getModel(model)\n };\n\n this.list = createListOperation(deps);\n this.get = createGetOperation(deps);\n this.getUniqueFieldValues = createGetUniqueFieldValuesOperation(deps);\n }\n}\n\nexport const EntrySearchOperations = Abstraction.createImplementation({\n implementation: EntrySearchOperationsImpl,\n dependencies: [\n OpenSearchClient,\n CmsEntryOpenSearchBodyBuilder,\n CmsModelFieldToGraphQLRegistry,\n CmsEntryOpenSearchFieldIndexRegistry,\n CmsStorageModelProvider\n ]\n});\n"],"names":["EntrySearchOperationsImpl","openSearchClient","bodyBuilder","fieldRegistry","fieldIndexRegistry","storageModelProvider","deps","model","createListOperation","createGetOperation","createGetUniqueFieldValuesOperation","EntrySearchOperations","Abstraction","OpenSearchClient","CmsEntryOpenSearchBodyBuilder","CmsModelFieldToGraphQLRegistry","CmsEntryOpenSearchFieldIndexRegistry","CmsStorageModelProvider"],"mappings":"
|
|
1
|
+
{"version":3,"file":"operations/entry/EntrySearchOperations.js","sources":["../../../src/operations/entry/EntrySearchOperations.ts"],"sourcesContent":["import { EntrySearchOperations as Abstraction } from \"./abstractions/EntrySearchOperations.js\";\nimport type { IEntrySearchOperations } from \"./abstractions/EntrySearchOperations.js\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport {\n CmsEntryOpenSearchBodyBuilder,\n CmsEntryOpenSearchFieldIndexRegistry\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { CmsModelOpenSearchIndexProvider } from \"@webiny/api-headless-cms-utils-os/features/CmsModelOpenSearchIndex/CmsModelOpenSearchIndexProvider.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/exports/api/cms/graphql.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport type { SearchOperationDeps } from \"./search/types.js\";\nimport { createListOperation } from \"./search/list.js\";\nimport { createGetOperation } from \"./search/get.js\";\nimport { createGetUniqueFieldValuesOperation } from \"./search/getUniqueFieldValues.js\";\n\nclass EntrySearchOperationsImpl implements IEntrySearchOperations {\n public readonly list: IEntrySearchOperations[\"list\"];\n public readonly get: IEntrySearchOperations[\"get\"];\n public readonly getUniqueFieldValues: IEntrySearchOperations[\"getUniqueFieldValues\"];\n\n public constructor(\n openSearchClient: OpenSearchClient.Interface,\n bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface,\n fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface,\n fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n storageModelProvider: CmsStorageModelProvider.Interface,\n indexProvider: CmsModelOpenSearchIndexProvider.Interface\n ) {\n const deps: SearchOperationDeps = {\n elasticsearch: openSearchClient.use(),\n bodyBuilder,\n fieldRegistry,\n fieldIndexRegistry,\n getStorageOperationsModel: model => storageModelProvider.getModel(model),\n indexProvider\n };\n\n this.list = createListOperation(deps);\n this.get = createGetOperation(deps);\n this.getUniqueFieldValues = createGetUniqueFieldValuesOperation(deps);\n }\n}\n\nexport const EntrySearchOperations = Abstraction.createImplementation({\n implementation: EntrySearchOperationsImpl,\n dependencies: [\n OpenSearchClient,\n CmsEntryOpenSearchBodyBuilder,\n CmsModelFieldToGraphQLRegistry,\n CmsEntryOpenSearchFieldIndexRegistry,\n CmsStorageModelProvider,\n CmsModelOpenSearchIndexProvider\n ]\n});\n"],"names":["EntrySearchOperationsImpl","openSearchClient","bodyBuilder","fieldRegistry","fieldIndexRegistry","storageModelProvider","indexProvider","deps","model","createListOperation","createGetOperation","createGetUniqueFieldValuesOperation","EntrySearchOperations","Abstraction","OpenSearchClient","CmsEntryOpenSearchBodyBuilder","CmsModelFieldToGraphQLRegistry","CmsEntryOpenSearchFieldIndexRegistry","CmsStorageModelProvider","CmsModelOpenSearchIndexProvider"],"mappings":";;;;;;;;;AAeA,MAAMA;IAKF,YACIC,gBAA4C,EAC5CC,WAAoD,EACpDC,aAAuD,EACvDC,kBAAkE,EAClEC,oBAAuD,EACvDC,aAAwD,CAC1D;QACE,MAAMC,OAA4B;YAC9B,eAAeN,iBAAiB,GAAG;YACnCC;YACAC;YACAC;YACA,2BAA2BI,CAAAA,QAASH,qBAAqB,QAAQ,CAACG;YAClEF;QACJ;QAEA,IAAI,CAAC,IAAI,GAAGG,oBAAoBF;QAChC,IAAI,CAAC,GAAG,GAAGG,mBAAmBH;QAC9B,IAAI,CAAC,oBAAoB,GAAGI,oCAAoCJ;IACpE;AACJ;AAEO,MAAMK,8CAAwBC,sBAAAA,oBAAgC,CAAC;IAClE,gBAAgBb;IAChB,cAAc;QACVc;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import _webiny_error from "@webiny/error";
|
|
2
2
|
import { shouldIgnoreEsResponseError } from "@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js";
|
|
3
|
-
import {
|
|
3
|
+
import { createConfigurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
|
|
4
4
|
const createGetUniqueFieldValuesOperation = (deps)=>async (model, uniqueFieldValuesParams)=>{
|
|
5
5
|
const { where, fieldId } = uniqueFieldValuesParams;
|
|
6
|
-
const
|
|
6
|
+
const configurations = createConfigurations(deps.indexProvider);
|
|
7
|
+
const { index } = await configurations.es({
|
|
7
8
|
model
|
|
8
9
|
});
|
|
9
10
|
const field = model.fields.find((f)=>f.fieldId === fieldId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/search/getUniqueFieldValues.js","sources":["../../../../src/operations/entry/search/getUniqueFieldValues.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { OpenSearchSearchResponse } from \"@webiny/api-opensearch\";\nimport { shouldIgnoreEsResponseError } from \"@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"operations/entry/search/getUniqueFieldValues.js","sources":["../../../../src/operations/entry/search/getUniqueFieldValues.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { OpenSearchSearchResponse } from \"@webiny/api-opensearch\";\nimport { shouldIgnoreEsResponseError } from \"@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport type { SearchOperationDeps } from \"./types.js\";\nimport type { GetUniqueFieldValuesStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/GetUniqueFieldValuesStorageOperation.js\";\n\nexport const createGetUniqueFieldValuesOperation = (\n deps: SearchOperationDeps\n): GetUniqueFieldValuesStorageOperation.Interface[\"execute\"] => {\n return async (model, uniqueFieldValuesParams) => {\n const { where, fieldId } = uniqueFieldValuesParams;\n const configurations = createConfigurations(deps.indexProvider);\n const { index } = await configurations.es({ model });\n\n const field = model.fields.find(f => f.fieldId === fieldId);\n if (!field) {\n return [];\n }\n\n const initialBody = deps.bodyBuilder.build({\n model,\n params: { limit: 1, where }\n });\n\n const body = {\n ...initialBody,\n size: 0,\n aggregations: {\n getUniqueFieldValues: {\n terms: {\n field: `values.${field.storageId}.keyword`,\n size: 1000000\n }\n }\n }\n };\n\n let response: OpenSearchSearchResponse;\n try {\n response = await deps.elasticsearch.search({ index, body });\n } catch (error) {\n if (shouldIgnoreEsResponseError(error)) {\n return [];\n }\n throw new WebinyError(error.message, error.code || \"OPENSEARCH_ERROR\", {\n error,\n index,\n model,\n body\n });\n }\n\n const aggregations = response.body.aggregations || {};\n const agg = aggregations[\"getUniqueFieldValues\"];\n const buckets = agg && \"buckets\" in agg && Array.isArray(agg.buckets) ? agg.buckets : [];\n return buckets.map((bucket: { key: string; doc_count: number }) => ({\n value: bucket.key,\n count: bucket.doc_count\n }));\n };\n};\n"],"names":["createGetUniqueFieldValuesOperation","deps","model","uniqueFieldValuesParams","where","fieldId","configurations","createConfigurations","index","field","f","initialBody","body","response","error","shouldIgnoreEsResponseError","WebinyError","aggregations","agg","buckets","Array","bucket"],"mappings":";;;AAOO,MAAMA,sCAAsC,CAC/CC,OAEO,OAAOC,OAAOC;QACjB,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAE,GAAGF;QAC3B,MAAMG,iBAAiBC,qBAAqBN,KAAK,aAAa;QAC9D,MAAM,EAAEO,KAAK,EAAE,GAAG,MAAMF,eAAe,EAAE,CAAC;YAAEJ;QAAM;QAElD,MAAMO,QAAQP,MAAM,MAAM,CAAC,IAAI,CAACQ,CAAAA,IAAKA,EAAE,OAAO,KAAKL;QACnD,IAAI,CAACI,OACD,OAAO,EAAE;QAGb,MAAME,cAAcV,KAAK,WAAW,CAAC,KAAK,CAAC;YACvCC;YACA,QAAQ;gBAAE,OAAO;gBAAGE;YAAM;QAC9B;QAEA,MAAMQ,OAAO;YACT,GAAGD,WAAW;YACd,MAAM;YACN,cAAc;gBACV,sBAAsB;oBAClB,OAAO;wBACH,OAAO,CAAC,OAAO,EAAEF,MAAM,SAAS,CAAC,QAAQ,CAAC;wBAC1C,MAAM;oBACV;gBACJ;YACJ;QACJ;QAEA,IAAII;QACJ,IAAI;YACAA,WAAW,MAAMZ,KAAK,aAAa,CAAC,MAAM,CAAC;gBAAEO;gBAAOI;YAAK;QAC7D,EAAE,OAAOE,OAAO;YACZ,IAAIC,4BAA4BD,QAC5B,OAAO,EAAE;YAEb,MAAM,IAAIE,cAAYF,MAAM,OAAO,EAAEA,MAAM,IAAI,IAAI,oBAAoB;gBACnEA;gBACAN;gBACAN;gBACAU;YACJ;QACJ;QAEA,MAAMK,eAAeJ,SAAS,IAAI,CAAC,YAAY,IAAI,CAAC;QACpD,MAAMK,MAAMD,YAAY,CAAC,uBAAuB;QAChD,MAAME,UAAUD,OAAO,aAAaA,OAAOE,MAAM,OAAO,CAACF,IAAI,OAAO,IAAIA,IAAI,OAAO,GAAG,EAAE;QACxF,OAAOC,QAAQ,GAAG,CAAC,CAACE,SAAgD;gBAChE,OAAOA,OAAO,GAAG;gBACjB,OAAOA,OAAO,SAAS;YAC3B;IACJ"}
|
|
@@ -2,11 +2,12 @@ import _webiny_error from "@webiny/error";
|
|
|
2
2
|
import { createLimit, decodeCursor, encodeCursor, getTotalCount } from "@webiny/api-opensearch";
|
|
3
3
|
import { shouldIgnoreEsResponseError } from "@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js";
|
|
4
4
|
import { extractEntriesFromIndex } from "@webiny/api-headless-cms-utils-os/helpers/entryIndexHelpers.js";
|
|
5
|
-
import {
|
|
5
|
+
import { createConfigurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
|
|
6
6
|
const createListOperation = (deps)=>async (initialModel, listParams)=>{
|
|
7
7
|
const model = deps.getStorageOperationsModel(initialModel);
|
|
8
8
|
const limit = createLimit(listParams.limit);
|
|
9
|
-
const
|
|
9
|
+
const configurations = createConfigurations(deps.indexProvider);
|
|
10
|
+
const { index } = await configurations.es({
|
|
10
11
|
model
|
|
11
12
|
});
|
|
12
13
|
const body = deps.bodyBuilder.build({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/search/list.js","sources":["../../../../src/operations/entry/search/list.ts"],"sourcesContent":["import type {\n CmsEntryValues,\n CmsModel,\n CmsEntryStorageOperationsListParams,\n CmsEntryStorageOperationsListResponse,\n CmsEntry\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport {\n createLimit,\n decodeCursor,\n encodeCursor,\n getTotalCount,\n type OpenSearchSearchResponse\n} from \"@webiny/api-opensearch\";\nimport { shouldIgnoreEsResponseError } from \"@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js\";\nimport { extractEntriesFromIndex } from \"@webiny/api-headless-cms-utils-os/helpers/entryIndexHelpers.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"operations/entry/search/list.js","sources":["../../../../src/operations/entry/search/list.ts"],"sourcesContent":["import type {\n CmsEntryValues,\n CmsModel,\n CmsEntryStorageOperationsListParams,\n CmsEntryStorageOperationsListResponse,\n CmsEntry\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport {\n createLimit,\n decodeCursor,\n encodeCursor,\n getTotalCount,\n type OpenSearchSearchResponse\n} from \"@webiny/api-opensearch\";\nimport { shouldIgnoreEsResponseError } from \"@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js\";\nimport { extractEntriesFromIndex } from \"@webiny/api-headless-cms-utils-os/helpers/entryIndexHelpers.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport type { CmsIndexEntry } from \"@webiny/api-headless-cms-utils-os/types.js\";\nimport type { SearchOperationDeps } from \"./types.js\";\n\nexport const createListOperation = (deps: SearchOperationDeps) => {\n return async <T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n listParams: CmsEntryStorageOperationsListParams\n ): Promise<CmsEntryStorageOperationsListResponse<CmsEntry<T>>> => {\n const model = deps.getStorageOperationsModel<T>(initialModel);\n const limit = createLimit(listParams.limit);\n\n const configurations = createConfigurations(deps.indexProvider);\n const { index } = await configurations.es({ model });\n\n const body = deps.bodyBuilder.build({\n model,\n params: {\n ...listParams,\n limit,\n after: decodeCursor(listParams.after)\n }\n });\n\n let response: OpenSearchSearchResponse;\n try {\n response = await deps.elasticsearch.search({ index, body });\n } catch (error) {\n if (shouldIgnoreEsResponseError(error)) {\n return { hasMoreItems: false, totalCount: 0, cursor: null, items: [] };\n }\n throw new WebinyError(error.message, error.code || \"OPENSEARCH_ERROR\", {\n error,\n index,\n body,\n model\n });\n }\n\n const { hits, total } = response.body.hits;\n\n const items = extractEntriesFromIndex<T>({\n fieldRegistry: deps.fieldRegistry,\n fieldIndexRegistry: deps.fieldIndexRegistry,\n model,\n entries: hits.map(item => item._source as CmsIndexEntry<T>)\n });\n\n const hasMoreItems = items.length > limit;\n if (hasMoreItems) {\n items.pop();\n }\n\n // @ts-expect-error - `sort` is present on the hit, but narrowed away by `_source: false` typing.\n const cursor = items.length > 0 ? encodeCursor(hits[items.length - 1].sort) || null : null;\n\n return {\n hasMoreItems,\n totalCount: getTotalCount(total),\n cursor,\n items\n };\n };\n};\n"],"names":["createListOperation","deps","initialModel","listParams","model","limit","createLimit","configurations","createConfigurations","index","body","decodeCursor","response","error","shouldIgnoreEsResponseError","WebinyError","hits","total","items","extractEntriesFromIndex","item","hasMoreItems","cursor","encodeCursor","getTotalCount"],"mappings":";;;;;AAqBO,MAAMA,sBAAsB,CAACC,OACzB,OACHC,cACAC;QAEA,MAAMC,QAAQH,KAAK,yBAAyB,CAAIC;QAChD,MAAMG,QAAQC,YAAYH,WAAW,KAAK;QAE1C,MAAMI,iBAAiBC,qBAAqBP,KAAK,aAAa;QAC9D,MAAM,EAAEQ,KAAK,EAAE,GAAG,MAAMF,eAAe,EAAE,CAAC;YAAEH;QAAM;QAElD,MAAMM,OAAOT,KAAK,WAAW,CAAC,KAAK,CAAC;YAChCG;YACA,QAAQ;gBACJ,GAAGD,UAAU;gBACbE;gBACA,OAAOM,aAAaR,WAAW,KAAK;YACxC;QACJ;QAEA,IAAIS;QACJ,IAAI;YACAA,WAAW,MAAMX,KAAK,aAAa,CAAC,MAAM,CAAC;gBAAEQ;gBAAOC;YAAK;QAC7D,EAAE,OAAOG,OAAO;YACZ,IAAIC,4BAA4BD,QAC5B,OAAO;gBAAE,cAAc;gBAAO,YAAY;gBAAG,QAAQ;gBAAM,OAAO,EAAE;YAAC;YAEzE,MAAM,IAAIE,cAAYF,MAAM,OAAO,EAAEA,MAAM,IAAI,IAAI,oBAAoB;gBACnEA;gBACAJ;gBACAC;gBACAN;YACJ;QACJ;QAEA,MAAM,EAAEY,IAAI,EAAEC,KAAK,EAAE,GAAGL,SAAS,IAAI,CAAC,IAAI;QAE1C,MAAMM,QAAQC,wBAA2B;YACrC,eAAelB,KAAK,aAAa;YACjC,oBAAoBA,KAAK,kBAAkB;YAC3CG;YACA,SAASY,KAAK,GAAG,CAACI,CAAAA,OAAQA,KAAK,OAAO;QAC1C;QAEA,MAAMC,eAAeH,MAAM,MAAM,GAAGb;QACpC,IAAIgB,cACAH,MAAM,GAAG;QAIb,MAAMI,SAASJ,MAAM,MAAM,GAAG,IAAIK,aAAaP,IAAI,CAACE,MAAM,MAAM,GAAG,EAAE,CAAC,IAAI,KAAK,OAAO;QAEtF,OAAO;YACHG;YACA,YAAYG,cAAcP;YAC1BK;YACAJ;QACJ;IACJ"}
|
|
@@ -2,6 +2,7 @@ import type { CmsEntryValues, CmsModel, StorageOperationsCmsModel } from "@webin
|
|
|
2
2
|
import type { Client as OpenSearchClient } from "@webiny/api-opensearch";
|
|
3
3
|
import type { CmsModelFieldToGraphQLRegistry } from "@webiny/api-headless-cms/exports/api/cms/graphql.js";
|
|
4
4
|
import type { CmsEntryOpenSearchFieldIndexRegistry } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
|
|
5
|
+
import type { CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/features/CmsModelOpenSearchIndex/CmsModelOpenSearchIndexProvider.js";
|
|
5
6
|
export type GetStorageOperationsModel = <T extends CmsEntryValues = CmsEntryValues>(model: CmsModel) => StorageOperationsCmsModel<T>;
|
|
6
7
|
export interface OpenSearchBodyBuilderBuildParams {
|
|
7
8
|
model: CmsModel;
|
|
@@ -16,4 +17,5 @@ export interface SearchOperationDeps {
|
|
|
16
17
|
fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface;
|
|
17
18
|
fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface;
|
|
18
19
|
getStorageOperationsModel: GetStorageOperationsModel;
|
|
20
|
+
indexProvider: CmsModelOpenSearchIndexProvider.Interface;
|
|
19
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms-pg-os",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.eb81deee7e",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -23,32 +23,32 @@
|
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"author": "Webiny Ltd.",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@webiny/api": "0.0.0-unstable.
|
|
27
|
-
"@webiny/api-core-sql": "0.0.0-unstable.
|
|
28
|
-
"@webiny/api-headless-cms": "0.0.0-unstable.
|
|
29
|
-
"@webiny/api-headless-cms-sql": "0.0.0-unstable.
|
|
30
|
-
"@webiny/api-headless-cms-storage": "0.0.0-unstable.
|
|
31
|
-
"@webiny/api-headless-cms-utils-os": "0.0.0-unstable.
|
|
32
|
-
"@webiny/api-opensearch": "0.0.0-unstable.
|
|
33
|
-
"@webiny/api-sync-to-opensearch": "0.0.0-unstable.
|
|
34
|
-
"@webiny/db-utils": "0.0.0-unstable.
|
|
35
|
-
"@webiny/error": "0.0.0-unstable.
|
|
36
|
-
"@webiny/feature": "0.0.0-unstable.
|
|
37
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
38
|
-
"@webiny/plugins": "0.0.0-unstable.
|
|
39
|
-
"@webiny/utils": "0.0.0-unstable.
|
|
26
|
+
"@webiny/api": "0.0.0-unstable.eb81deee7e",
|
|
27
|
+
"@webiny/api-core-sql": "0.0.0-unstable.eb81deee7e",
|
|
28
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.eb81deee7e",
|
|
29
|
+
"@webiny/api-headless-cms-sql": "0.0.0-unstable.eb81deee7e",
|
|
30
|
+
"@webiny/api-headless-cms-storage": "0.0.0-unstable.eb81deee7e",
|
|
31
|
+
"@webiny/api-headless-cms-utils-os": "0.0.0-unstable.eb81deee7e",
|
|
32
|
+
"@webiny/api-opensearch": "0.0.0-unstable.eb81deee7e",
|
|
33
|
+
"@webiny/api-sync-to-opensearch": "0.0.0-unstable.eb81deee7e",
|
|
34
|
+
"@webiny/db-utils": "0.0.0-unstable.eb81deee7e",
|
|
35
|
+
"@webiny/error": "0.0.0-unstable.eb81deee7e",
|
|
36
|
+
"@webiny/feature": "0.0.0-unstable.eb81deee7e",
|
|
37
|
+
"@webiny/handler": "0.0.0-unstable.eb81deee7e",
|
|
38
|
+
"@webiny/plugins": "0.0.0-unstable.eb81deee7e",
|
|
39
|
+
"@webiny/utils": "0.0.0-unstable.eb81deee7e",
|
|
40
40
|
"knex": "3.3.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@electric-sql/pglite": "0.5.
|
|
44
|
-
"@electric-sql/pglite-socket": "0.2.
|
|
45
|
-
"@webiny/api-
|
|
46
|
-
"@webiny/
|
|
47
|
-
"@webiny/
|
|
48
|
-
"@webiny/
|
|
49
|
-
"@webiny/stdlib": "0.0.
|
|
43
|
+
"@electric-sql/pglite": "0.5.5",
|
|
44
|
+
"@electric-sql/pglite-socket": "0.2.8",
|
|
45
|
+
"@webiny/api-core": "0.0.0-unstable.eb81deee7e",
|
|
46
|
+
"@webiny/api-sync-pg-to-opensearch": "0.0.0-unstable.eb81deee7e",
|
|
47
|
+
"@webiny/build-tools": "0.0.0-unstable.eb81deee7e",
|
|
48
|
+
"@webiny/di": "1.1.0",
|
|
49
|
+
"@webiny/stdlib": "0.0.17",
|
|
50
50
|
"typescript": "7.0.2",
|
|
51
|
-
"vitest": "4.1.
|
|
51
|
+
"vitest": "4.1.11"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
@@ -8,6 +8,7 @@ const toSyncEvent = (row, type)=>({
|
|
|
8
8
|
data: row.data
|
|
9
9
|
} : {}
|
|
10
10
|
});
|
|
11
|
+
const createRowKey = (row)=>`${row.tenant}:${row.id}`;
|
|
11
12
|
const simulatePgStream = (params)=>{
|
|
12
13
|
const { knex, tableName, handler } = params;
|
|
13
14
|
const query = ()=>knex(tableName);
|
|
@@ -23,24 +24,24 @@ const simulatePgStream = (params)=>{
|
|
|
23
24
|
if (!isInsert && !isDelete) return originalQuery(connection, obj);
|
|
24
25
|
const rowsBefore = await query().select("*");
|
|
25
26
|
const beforeMap = new Map(rowsBefore.map((row)=>[
|
|
26
|
-
row
|
|
27
|
+
createRowKey(row),
|
|
27
28
|
row
|
|
28
29
|
]));
|
|
29
30
|
const result = await originalQuery(connection, obj);
|
|
30
31
|
const rowsAfter = await query().select("*");
|
|
31
32
|
const afterMap = new Map(rowsAfter.map((row)=>[
|
|
32
|
-
row
|
|
33
|
+
createRowKey(row),
|
|
33
34
|
row
|
|
34
35
|
]));
|
|
35
36
|
const events = [];
|
|
36
|
-
if (isInsert) for (const [
|
|
37
|
-
const before = beforeMap.get(
|
|
37
|
+
if (isInsert) for (const [key, row] of afterMap){
|
|
38
|
+
const before = beforeMap.get(key);
|
|
38
39
|
if (before) {
|
|
39
40
|
if (before.data !== row.data) events.push(toSyncEvent(row, "MODIFY"));
|
|
40
41
|
} else events.push(toSyncEvent(row, "INSERT"));
|
|
41
42
|
}
|
|
42
43
|
if (isDelete) {
|
|
43
|
-
for (const [
|
|
44
|
+
for (const [key, row] of beforeMap)if (!afterMap.has(key)) events.push(toSyncEvent(row, "REMOVE"));
|
|
44
45
|
}
|
|
45
46
|
if (events.length > 0) await handler(events);
|
|
46
47
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing/simulatePgStream.js","sources":["../../src/testing/simulatePgStream.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type { SyncEvent, ISyncRow, SyncEventType } from \"~/types.js\";\n\nexport interface SimulatePgStreamParams {\n knex: Knex;\n tableName: string;\n handler: (events: SyncEvent[]) => Promise<void>;\n}\n\nconst toSyncEvent = (row: ISyncRow, type: SyncEventType): SyncEvent => ({\n type,\n id: row.id,\n entryId: row.entryId,\n tenant: row.tenant,\n index: row.index,\n ...(type !== \"REMOVE\" ? { data: row.data } : {})\n});\n\n/**\n * Simulates a PostgreSQL -> OpenSearch sync stream (the PG equivalent of the\n * DynamoDB Streams simulation in `@webiny/project-utils/testing/dynamodb`) by\n * monkey-patching knex's internal `client.query` method.\n *\n * Uses a snapshot-diff approach: capture all rows in the target table before\n * the operation, execute the operation, capture all rows after, then diff the\n * two snapshots to determine which `SyncEvent`s occurred. This is robust\n * against SQL structure changes, since it never has to parse bindings or SQL\n * text to reconstruct row data.\n */\nexport const simulatePgStream = (params: SimulatePgStreamParams): void => {\n const { knex, tableName, handler } = params;\n const query = () => knex<ISyncRow>(tableName);\n\n const originalClient = knex.client;\n const originalQuery = originalClient.query.bind(originalClient);\n\n originalClient.query = async (connection: unknown, obj: unknown) => {\n const sql: string = typeof obj === \"string\" ? obj : ((obj as { sql?: string })?.sql ?? \"\");\n const isTargetTable = sql.includes(tableName);\n\n if (!isTargetTable) {\n return originalQuery(connection, obj);\n }\n\n const upperSql = sql.toUpperCase();\n const isInsert = upperSql.includes(\"INSERT\");\n const isDelete = upperSql.includes(\"DELETE\");\n\n if (!isInsert && !isDelete) {\n return originalQuery(connection, obj);\n }\n\n const rowsBefore = await query().select(\"*\");\n const beforeMap = new Map(rowsBefore.map(row => [row
|
|
1
|
+
{"version":3,"file":"testing/simulatePgStream.js","sources":["../../src/testing/simulatePgStream.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type { SyncEvent, ISyncRow, SyncEventType } from \"~/types.js\";\n\nexport interface SimulatePgStreamParams {\n knex: Knex;\n tableName: string;\n handler: (events: SyncEvent[]) => Promise<void>;\n}\n\nconst toSyncEvent = (row: ISyncRow, type: SyncEventType): SyncEvent => ({\n type,\n id: row.id,\n entryId: row.entryId,\n tenant: row.tenant,\n index: row.index,\n ...(type !== \"REMOVE\" ? { data: row.data } : {})\n});\n\nconst createRowKey = (row: ISyncRow): string => {\n return `${row.tenant}:${row.id}`;\n};\n\n/**\n * Simulates a PostgreSQL -> OpenSearch sync stream (the PG equivalent of the\n * DynamoDB Streams simulation in `@webiny/project-utils/testing/dynamodb`) by\n * monkey-patching knex's internal `client.query` method.\n *\n * Uses a snapshot-diff approach: capture all rows in the target table before\n * the operation, execute the operation, capture all rows after, then diff the\n * two snapshots to determine which `SyncEvent`s occurred. This is robust\n * against SQL structure changes, since it never has to parse bindings or SQL\n * text to reconstruct row data.\n */\nexport const simulatePgStream = (params: SimulatePgStreamParams): void => {\n const { knex, tableName, handler } = params;\n const query = () => knex<ISyncRow>(tableName);\n\n const originalClient = knex.client;\n const originalQuery = originalClient.query.bind(originalClient);\n\n originalClient.query = async (connection: unknown, obj: unknown) => {\n const sql: string = typeof obj === \"string\" ? obj : ((obj as { sql?: string })?.sql ?? \"\");\n const isTargetTable = sql.includes(tableName);\n\n if (!isTargetTable) {\n return originalQuery(connection, obj);\n }\n\n const upperSql = sql.toUpperCase();\n const isInsert = upperSql.includes(\"INSERT\");\n const isDelete = upperSql.includes(\"DELETE\");\n\n if (!isInsert && !isDelete) {\n return originalQuery(connection, obj);\n }\n\n const rowsBefore = await query().select(\"*\");\n const beforeMap = new Map(rowsBefore.map(row => [createRowKey(row), row]));\n\n const result = await originalQuery(connection, obj);\n\n const rowsAfter = await query().select(\"*\");\n const afterMap = new Map(rowsAfter.map(row => [createRowKey(row), row]));\n\n const events: SyncEvent[] = [];\n\n if (isInsert) {\n for (const [key, row] of afterMap) {\n const before = beforeMap.get(key);\n if (!before) {\n events.push(toSyncEvent(row, \"INSERT\"));\n } else if (before.data !== row.data) {\n events.push(toSyncEvent(row, \"MODIFY\"));\n }\n }\n }\n\n if (isDelete) {\n for (const [key, row] of beforeMap) {\n if (!afterMap.has(key)) {\n events.push(toSyncEvent(row, \"REMOVE\"));\n }\n }\n }\n\n if (events.length > 0) {\n await handler(events);\n }\n\n return result;\n };\n};\n"],"names":["toSyncEvent","row","type","createRowKey","simulatePgStream","params","knex","tableName","handler","query","originalClient","originalQuery","connection","obj","sql","isTargetTable","upperSql","isInsert","isDelete","rowsBefore","beforeMap","Map","result","rowsAfter","afterMap","events","key","before"],"mappings":"AASA,MAAMA,cAAc,CAACC,KAAeC,OAAoC;QACpEA;QACA,IAAID,IAAI,EAAE;QACV,SAASA,IAAI,OAAO;QACpB,QAAQA,IAAI,MAAM;QAClB,OAAOA,IAAI,KAAK;QAChB,GAAIC,AAAS,aAATA,OAAoB;YAAE,MAAMD,IAAI,IAAI;QAAC,IAAI,CAAC,CAAC;IACnD;AAEA,MAAME,eAAe,CAACF,MACX,GAAGA,IAAI,MAAM,CAAC,CAAC,EAAEA,IAAI,EAAE,EAAE;AAc7B,MAAMG,mBAAmB,CAACC;IAC7B,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAEC,OAAO,EAAE,GAAGH;IACrC,MAAMI,QAAQ,IAAMH,KAAeC;IAEnC,MAAMG,iBAAiBJ,KAAK,MAAM;IAClC,MAAMK,gBAAgBD,eAAe,KAAK,CAAC,IAAI,CAACA;IAEhDA,eAAe,KAAK,GAAG,OAAOE,YAAqBC;QAC/C,MAAMC,MAAc,AAAe,YAAf,OAAOD,MAAmBA,MAAQA,KAA0B,OAAO;QACvF,MAAME,gBAAgBD,IAAI,QAAQ,CAACP;QAEnC,IAAI,CAACQ,eACD,OAAOJ,cAAcC,YAAYC;QAGrC,MAAMG,WAAWF,IAAI,WAAW;QAChC,MAAMG,WAAWD,SAAS,QAAQ,CAAC;QACnC,MAAME,WAAWF,SAAS,QAAQ,CAAC;QAEnC,IAAI,CAACC,YAAY,CAACC,UACd,OAAOP,cAAcC,YAAYC;QAGrC,MAAMM,aAAa,MAAMV,QAAQ,MAAM,CAAC;QACxC,MAAMW,YAAY,IAAIC,IAAIF,WAAW,GAAG,CAAClB,CAAAA,MAAO;gBAACE,aAAaF;gBAAMA;aAAI;QAExE,MAAMqB,SAAS,MAAMX,cAAcC,YAAYC;QAE/C,MAAMU,YAAY,MAAMd,QAAQ,MAAM,CAAC;QACvC,MAAMe,WAAW,IAAIH,IAAIE,UAAU,GAAG,CAACtB,CAAAA,MAAO;gBAACE,aAAaF;gBAAMA;aAAI;QAEtE,MAAMwB,SAAsB,EAAE;QAE9B,IAAIR,UACA,KAAK,MAAM,CAACS,KAAKzB,IAAI,IAAIuB,SAAU;YAC/B,MAAMG,SAASP,UAAU,GAAG,CAACM;YAC7B,IAAKC,QAEE;gBAAA,IAAIA,OAAO,IAAI,KAAK1B,IAAI,IAAI,EAC/BwB,OAAO,IAAI,CAACzB,YAAYC,KAAK;YACjC,OAHIwB,OAAO,IAAI,CAACzB,YAAYC,KAAK;QAIrC;QAGJ,IAAIiB,UACA;YAAA,KAAK,MAAM,CAACQ,KAAKzB,IAAI,IAAImB,UACrB,IAAI,CAACI,SAAS,GAAG,CAACE,MACdD,OAAO,IAAI,CAACzB,YAAYC,KAAK;QAErC;QAGJ,IAAIwB,OAAO,MAAM,GAAG,GAChB,MAAMjB,QAAQiB;QAGlB,OAAOH;IACX;AACJ"}
|