@webiny/api-headless-cms-sql 0.0.0-unstable.0156a4c312
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/LICENSE +21 -0
- package/README.md +11 -0
- package/features/entryTableManager/EntryTableManager.d.ts +19 -0
- package/features/entryTableManager/EntryTableManager.js +80 -0
- package/features/entryTableManager/EntryTableManager.js.map +1 -0
- package/features/entryTableManager/abstractions.d.ts +9 -0
- package/features/entryTableManager/abstractions.js +5 -0
- package/features/entryTableManager/abstractions.js.map +1 -0
- package/features/entryTableManager/feature.d.ts +4 -0
- package/features/entryTableManager/feature.js +11 -0
- package/features/entryTableManager/feature.js.map +1 -0
- package/features/groupSchemaManager/GroupSchemaManager.d.ts +13 -0
- package/features/groupSchemaManager/GroupSchemaManager.js +48 -0
- package/features/groupSchemaManager/GroupSchemaManager.js.map +1 -0
- package/features/groupSchemaManager/abstractions.d.ts +8 -0
- package/features/groupSchemaManager/abstractions.js +5 -0
- package/features/groupSchemaManager/abstractions.js.map +1 -0
- package/features/groupSchemaManager/feature.d.ts +4 -0
- package/features/groupSchemaManager/feature.js +11 -0
- package/features/groupSchemaManager/feature.js.map +1 -0
- package/features/modelSchemaManager/ModelSchemaManager.d.ts +13 -0
- package/features/modelSchemaManager/ModelSchemaManager.js +58 -0
- package/features/modelSchemaManager/ModelSchemaManager.js.map +1 -0
- package/features/modelSchemaManager/abstractions.d.ts +8 -0
- package/features/modelSchemaManager/abstractions.js +5 -0
- package/features/modelSchemaManager/abstractions.js.map +1 -0
- package/features/modelSchemaManager/feature.d.ts +4 -0
- package/features/modelSchemaManager/feature.js +11 -0
- package/features/modelSchemaManager/feature.js.map +1 -0
- package/features/tableNameResolver/TableNameResolver.d.ts +13 -0
- package/features/tableNameResolver/TableNameResolver.js +24 -0
- package/features/tableNameResolver/TableNameResolver.js.map +1 -0
- package/features/tableNameResolver/abstractions.d.ts +16 -0
- package/features/tableNameResolver/abstractions.js +6 -0
- package/features/tableNameResolver/abstractions.js.map +1 -0
- package/features/tableNameResolver/feature.d.ts +4 -0
- package/features/tableNameResolver/feature.js +11 -0
- package/features/tableNameResolver/feature.js.map +1 -0
- package/index.d.ts +16 -0
- package/index.js +34 -0
- package/index.js.map +1 -0
- package/operations/entry/SqlCreateEntry.d.ts +15 -0
- package/operations/entry/SqlCreateEntry.js +35 -0
- package/operations/entry/SqlCreateEntry.js.map +1 -0
- package/operations/entry/SqlCreateEntryRevisionFrom.d.ts +16 -0
- package/operations/entry/SqlCreateEntryRevisionFrom.js +58 -0
- package/operations/entry/SqlCreateEntryRevisionFrom.js.map +1 -0
- package/operations/entry/SqlDeleteEntry.d.ts +15 -0
- package/operations/entry/SqlDeleteEntry.js +29 -0
- package/operations/entry/SqlDeleteEntry.js.map +1 -0
- package/operations/entry/SqlDeleteEntryRevision.d.ts +15 -0
- package/operations/entry/SqlDeleteEntryRevision.js +39 -0
- package/operations/entry/SqlDeleteEntryRevision.js.map +1 -0
- package/operations/entry/SqlDeleteMultipleEntries.d.ts +15 -0
- package/operations/entry/SqlDeleteMultipleEntries.js +29 -0
- package/operations/entry/SqlDeleteMultipleEntries.js.map +1 -0
- package/operations/entry/SqlGetEntriesByIds.d.ts +15 -0
- package/operations/entry/SqlGetEntriesByIds.js +35 -0
- package/operations/entry/SqlGetEntriesByIds.js.map +1 -0
- package/operations/entry/SqlGetEntry.d.ts +27 -0
- package/operations/entry/SqlGetEntry.js +65 -0
- package/operations/entry/SqlGetEntry.js.map +1 -0
- package/operations/entry/SqlGetLatestEntriesByIds.d.ts +15 -0
- package/operations/entry/SqlGetLatestEntriesByIds.js +37 -0
- package/operations/entry/SqlGetLatestEntriesByIds.js.map +1 -0
- package/operations/entry/SqlGetLatestRevisionByEntryId.d.ts +15 -0
- package/operations/entry/SqlGetLatestRevisionByEntryId.js +32 -0
- package/operations/entry/SqlGetLatestRevisionByEntryId.js.map +1 -0
- package/operations/entry/SqlGetPreviousRevision.d.ts +15 -0
- package/operations/entry/SqlGetPreviousRevision.js +30 -0
- package/operations/entry/SqlGetPreviousRevision.js.map +1 -0
- package/operations/entry/SqlGetPublishedEntriesByIds.d.ts +15 -0
- package/operations/entry/SqlGetPublishedEntriesByIds.js +37 -0
- package/operations/entry/SqlGetPublishedEntriesByIds.js.map +1 -0
- package/operations/entry/SqlGetPublishedRevisionByEntryId.d.ts +15 -0
- package/operations/entry/SqlGetPublishedRevisionByEntryId.js +32 -0
- package/operations/entry/SqlGetPublishedRevisionByEntryId.js.map +1 -0
- package/operations/entry/SqlGetRevisionById.d.ts +15 -0
- package/operations/entry/SqlGetRevisionById.js +30 -0
- package/operations/entry/SqlGetRevisionById.js.map +1 -0
- package/operations/entry/SqlGetRevisions.d.ts +15 -0
- package/operations/entry/SqlGetRevisions.js +31 -0
- package/operations/entry/SqlGetRevisions.js.map +1 -0
- package/operations/entry/SqlGetUniqueFieldValues.d.ts +27 -0
- package/operations/entry/SqlGetUniqueFieldValues.js +67 -0
- package/operations/entry/SqlGetUniqueFieldValues.js.map +1 -0
- package/operations/entry/SqlListEntries.d.ts +27 -0
- package/operations/entry/SqlListEntries.js +61 -0
- package/operations/entry/SqlListEntries.js.map +1 -0
- package/operations/entry/SqlMoveEntry.d.ts +14 -0
- package/operations/entry/SqlMoveEntry.js +30 -0
- package/operations/entry/SqlMoveEntry.js.map +1 -0
- package/operations/entry/SqlMoveToBin.d.ts +14 -0
- package/operations/entry/SqlMoveToBin.js +35 -0
- package/operations/entry/SqlMoveToBin.js.map +1 -0
- package/operations/entry/SqlPublishEntry.d.ts +15 -0
- package/operations/entry/SqlPublishEntry.js +51 -0
- package/operations/entry/SqlPublishEntry.js.map +1 -0
- package/operations/entry/SqlRestoreFromBin.d.ts +14 -0
- package/operations/entry/SqlRestoreFromBin.js +36 -0
- package/operations/entry/SqlRestoreFromBin.js.map +1 -0
- package/operations/entry/SqlUnpublishEntry.d.ts +15 -0
- package/operations/entry/SqlUnpublishEntry.js +38 -0
- package/operations/entry/SqlUnpublishEntry.js.map +1 -0
- package/operations/entry/SqlUpdateEntry.d.ts +15 -0
- package/operations/entry/SqlUpdateEntry.js +36 -0
- package/operations/entry/SqlUpdateEntry.js.map +1 -0
- package/operations/entry/feature.d.ts +4 -0
- package/operations/entry/feature.js +53 -0
- package/operations/entry/feature.js.map +1 -0
- package/operations/entry/mappers.d.ts +5 -0
- package/operations/entry/mappers.js +26 -0
- package/operations/entry/mappers.js.map +1 -0
- package/operations/entry/queryHelpers.d.ts +30 -0
- package/operations/entry/queryHelpers.js +107 -0
- package/operations/entry/queryHelpers.js.map +1 -0
- package/operations/entry/types.d.ts +11 -0
- package/operations/entry/types.js +0 -0
- package/operations/group/SqlCreateGroup.d.ts +16 -0
- package/operations/group/SqlCreateGroup.js +28 -0
- package/operations/group/SqlCreateGroup.js.map +1 -0
- package/operations/group/SqlDeleteGroup.d.ts +16 -0
- package/operations/group/SqlDeleteGroup.js +26 -0
- package/operations/group/SqlDeleteGroup.js.map +1 -0
- package/operations/group/SqlGetGroup.d.ts +16 -0
- package/operations/group/SqlGetGroup.js +29 -0
- package/operations/group/SqlGetGroup.js.map +1 -0
- package/operations/group/SqlListGroups.d.ts +16 -0
- package/operations/group/SqlListGroups.js +43 -0
- package/operations/group/SqlListGroups.js.map +1 -0
- package/operations/group/SqlUpdateGroup.d.ts +16 -0
- package/operations/group/SqlUpdateGroup.js +28 -0
- package/operations/group/SqlUpdateGroup.js.map +1 -0
- package/operations/group/feature.d.ts +4 -0
- package/operations/group/feature.js +19 -0
- package/operations/group/feature.js.map +1 -0
- package/operations/group/mappers.d.ts +4 -0
- package/operations/group/mappers.js +32 -0
- package/operations/group/mappers.js.map +1 -0
- package/operations/group/types.d.ts +18 -0
- package/operations/group/types.js +17 -0
- package/operations/group/types.js.map +1 -0
- package/operations/model/SqlCreateModel.d.ts +16 -0
- package/operations/model/SqlCreateModel.js +30 -0
- package/operations/model/SqlCreateModel.js.map +1 -0
- package/operations/model/SqlDeleteModel.d.ts +16 -0
- package/operations/model/SqlDeleteModel.js +26 -0
- package/operations/model/SqlDeleteModel.js.map +1 -0
- package/operations/model/SqlGetModel.d.ts +16 -0
- package/operations/model/SqlGetModel.js +29 -0
- package/operations/model/SqlGetModel.js.map +1 -0
- package/operations/model/SqlListModels.d.ts +16 -0
- package/operations/model/SqlListModels.js +31 -0
- package/operations/model/SqlListModels.js.map +1 -0
- package/operations/model/SqlUpdateModel.d.ts +16 -0
- package/operations/model/SqlUpdateModel.js +30 -0
- package/operations/model/SqlUpdateModel.js.map +1 -0
- package/operations/model/feature.d.ts +4 -0
- package/operations/model/feature.js +19 -0
- package/operations/model/feature.js.map +1 -0
- package/operations/model/mappers.d.ts +4 -0
- package/operations/model/mappers.js +52 -0
- package/operations/model/mappers.js.map +1 -0
- package/operations/model/types.d.ts +28 -0
- package/operations/model/types.js +27 -0
- package/operations/model/types.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/SqlMoveEntry.js","sources":["../../../src/operations/entry/SqlMoveEntry.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { MoveEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/MoveEntryStorageOperation.js\";\nimport { KnexClient } from \"@webiny/api-core-sql\";\nimport { EntryTableManager } from \"~/features/entryTableManager/abstractions.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { patchAllEntryRevisions } from \"./queryHelpers.js\";\n\nclass SqlMoveEntryImpl implements MoveEntryStorageOperation.Interface {\n private readonly knex: Knex;\n\n public constructor(\n knexClient: KnexClient.Interface,\n private readonly entryTableManager: EntryTableManager.Interface\n ) {\n this.knex = knexClient.client;\n }\n\n async execute(model: CmsModel, id: string, folderId: string) {\n await this.entryTableManager.ensureTable();\n\n const { id: entryId } = parseIdentifier(id);\n\n await patchAllEntryRevisions(\n this.knex,\n this.entryTableManager.getTableName(),\n model,\n entryId,\n parsed => {\n parsed.location = { folderId };\n }\n );\n }\n}\n\nexport const SqlMoveEntry = MoveEntryStorageOperation.createImplementation({\n implementation: SqlMoveEntryImpl,\n dependencies: [KnexClient, EntryTableManager]\n});\n"],"names":["SqlMoveEntryImpl","knexClient","entryTableManager","model","id","folderId","entryId","parseIdentifier","patchAllEntryRevisions","parsed","SqlMoveEntry","MoveEntryStorageOperation","KnexClient","EntryTableManager"],"mappings":";;;;;AAQA,MAAMA;IAGF,YACIC,UAAgC,EACfC,iBAA8C,CACjE;aADmBA,iBAAiB,GAAjBA;QAEjB,IAAI,CAAC,IAAI,GAAGD,WAAW,MAAM;IACjC;IAEA,MAAM,QAAQE,KAAe,EAAEC,EAAU,EAAEC,QAAgB,EAAE;QACzD,MAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW;QAExC,MAAM,EAAE,IAAIC,OAAO,EAAE,GAAGC,gBAAgBH;QAExC,MAAMI,uBACF,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,iBAAiB,CAAC,YAAY,IACnCL,OACAG,SACAG,CAAAA;YACIA,OAAO,QAAQ,GAAG;gBAAEJ;YAAS;QACjC;IAER;AACJ;AAEO,MAAMK,eAAeC,0BAA0B,oBAAoB,CAAC;IACvE,gBAAgBX;IAChB,cAAc;QAACY;QAAYC;KAAkB;AACjD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CmsEntryStorageOperationsMoveToBinParams, CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import { MoveToBinStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/MoveToBinStorageOperation.js";
|
|
3
|
+
import { KnexClient } from "@webiny/api-core-sql";
|
|
4
|
+
import { EntryTableManager } from "../../features/entryTableManager/abstractions.js";
|
|
5
|
+
declare class SqlMoveToBinImpl implements MoveToBinStorageOperation.Interface {
|
|
6
|
+
private readonly entryTableManager;
|
|
7
|
+
private readonly knex;
|
|
8
|
+
constructor(knexClient: KnexClient.Interface, entryTableManager: EntryTableManager.Interface);
|
|
9
|
+
execute(model: CmsModel, params: CmsEntryStorageOperationsMoveToBinParams): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare const SqlMoveToBin: typeof SqlMoveToBinImpl & {
|
|
12
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-headless-cms/features/shared/storageOperations/entry/MoveToBinStorageOperation.js").IMoveToBinStorageOperation>;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { MoveToBinStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/MoveToBinStorageOperation.js";
|
|
2
|
+
import { KnexClient } from "@webiny/api-core-sql";
|
|
3
|
+
import { EntryTableManager } from "../../features/entryTableManager/abstractions.js";
|
|
4
|
+
import { patchAllEntryRevisions } from "./queryHelpers.js";
|
|
5
|
+
class SqlMoveToBinImpl {
|
|
6
|
+
constructor(knexClient, entryTableManager){
|
|
7
|
+
this.entryTableManager = entryTableManager;
|
|
8
|
+
this.knex = knexClient.client;
|
|
9
|
+
}
|
|
10
|
+
async execute(model, params) {
|
|
11
|
+
await this.entryTableManager.ensureTable();
|
|
12
|
+
await patchAllEntryRevisions(this.knex, this.entryTableManager.getTableName(), model, params.entry.entryId, (parsed)=>{
|
|
13
|
+
const p = parsed;
|
|
14
|
+
p["wbyDeleted"] = true;
|
|
15
|
+
p["binOriginalFolderId"] = params.storageEntry.binOriginalFolderId ?? null;
|
|
16
|
+
p["location"] = params.storageEntry.location ?? null;
|
|
17
|
+
const fields = Object.keys(params.storageEntry);
|
|
18
|
+
for (const field of fields)if ("createdOn" !== field && "createdBy" !== field) {
|
|
19
|
+
if ((field.endsWith("On") || field.endsWith("By")) && !field.startsWith("revision")) p[field] = params.storageEntry[field];
|
|
20
|
+
}
|
|
21
|
+
}, {
|
|
22
|
+
wbyDeleted: true
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const SqlMoveToBin = MoveToBinStorageOperation.createImplementation({
|
|
27
|
+
implementation: SqlMoveToBinImpl,
|
|
28
|
+
dependencies: [
|
|
29
|
+
KnexClient,
|
|
30
|
+
EntryTableManager
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
export { SqlMoveToBin };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=SqlMoveToBin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/SqlMoveToBin.js","sources":["../../../src/operations/entry/SqlMoveToBin.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type {\n CmsEntryStorageOperationsMoveToBinParams,\n CmsModel\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { MoveToBinStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/MoveToBinStorageOperation.js\";\nimport { KnexClient } from \"@webiny/api-core-sql\";\nimport { EntryTableManager } from \"~/features/entryTableManager/abstractions.js\";\nimport { patchAllEntryRevisions } from \"./queryHelpers.js\";\n\nclass SqlMoveToBinImpl implements MoveToBinStorageOperation.Interface {\n private readonly knex: Knex;\n\n public constructor(\n knexClient: KnexClient.Interface,\n private readonly entryTableManager: EntryTableManager.Interface\n ) {\n this.knex = knexClient.client;\n }\n\n async execute(model: CmsModel, params: CmsEntryStorageOperationsMoveToBinParams) {\n await this.entryTableManager.ensureTable();\n\n await patchAllEntryRevisions(\n this.knex,\n this.entryTableManager.getTableName(),\n model,\n params.entry.entryId,\n parsed => {\n const p = parsed as unknown as Record<string, unknown>;\n p[\"wbyDeleted\"] = true;\n p[\"binOriginalFolderId\"] = params.storageEntry.binOriginalFolderId ?? null;\n p[\"location\"] = params.storageEntry.location ?? null;\n\n const fields = Object.keys(params.storageEntry);\n for (const field of fields) {\n if (field === \"createdOn\" || field === \"createdBy\") {\n continue;\n }\n if (\n (field.endsWith(\"On\") || field.endsWith(\"By\")) &&\n !field.startsWith(\"revision\")\n ) {\n p[field] = (params.storageEntry as Record<string, unknown>)[field];\n }\n }\n },\n {\n wbyDeleted: true\n }\n );\n }\n}\n\nexport const SqlMoveToBin = MoveToBinStorageOperation.createImplementation({\n implementation: SqlMoveToBinImpl,\n dependencies: [KnexClient, EntryTableManager]\n});\n"],"names":["SqlMoveToBinImpl","knexClient","entryTableManager","model","params","patchAllEntryRevisions","parsed","p","fields","Object","field","SqlMoveToBin","MoveToBinStorageOperation","KnexClient","EntryTableManager"],"mappings":";;;;AAUA,MAAMA;IAGF,YACIC,UAAgC,EACfC,iBAA8C,CACjE;aADmBA,iBAAiB,GAAjBA;QAEjB,IAAI,CAAC,IAAI,GAAGD,WAAW,MAAM;IACjC;IAEA,MAAM,QAAQE,KAAe,EAAEC,MAAgD,EAAE;QAC7E,MAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW;QAExC,MAAMC,uBACF,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,iBAAiB,CAAC,YAAY,IACnCF,OACAC,OAAO,KAAK,CAAC,OAAO,EACpBE,CAAAA;YACI,MAAMC,IAAID;YACVC,CAAC,CAAC,aAAa,GAAG;YAClBA,CAAC,CAAC,sBAAsB,GAAGH,OAAO,YAAY,CAAC,mBAAmB,IAAI;YACtEG,CAAC,CAAC,WAAW,GAAGH,OAAO,YAAY,CAAC,QAAQ,IAAI;YAEhD,MAAMI,SAASC,OAAO,IAAI,CAACL,OAAO,YAAY;YAC9C,KAAK,MAAMM,SAASF,OAChB,IAAIE,AAAU,gBAAVA,SAAyBA,AAAU,gBAAVA,OAG7B;gBAAA,IACKA,AAAAA,CAAAA,MAAM,QAAQ,CAAC,SAASA,MAAM,QAAQ,CAAC,KAAI,KAC5C,CAACA,MAAM,UAAU,CAAC,aAElBH,CAAC,CAACG,MAAM,GAAIN,OAAO,YAAwC,CAACM,MAAM;YACtE;QAER,GACA;YACI,YAAY;QAChB;IAER;AACJ;AAEO,MAAMC,eAAeC,0BAA0B,oBAAoB,CAAC;IACvE,gBAAgBZ;IAChB,cAAc;QAACa;QAAYC;KAAkB;AACjD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CmsEntryStorageOperationsPublishParams, CmsEntryValues, CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import { PublishEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/PublishEntryStorageOperation.js";
|
|
3
|
+
import { KnexClient } from "@webiny/api-core-sql";
|
|
4
|
+
import { EntryTableManager } from "../../features/entryTableManager/abstractions.js";
|
|
5
|
+
declare class SqlPublishEntryImpl implements PublishEntryStorageOperation.Interface {
|
|
6
|
+
private readonly entryTableManager;
|
|
7
|
+
private readonly knex;
|
|
8
|
+
constructor(knexClient: KnexClient.Interface, entryTableManager: EntryTableManager.Interface);
|
|
9
|
+
private modelQuery;
|
|
10
|
+
execute<T extends CmsEntryValues>(model: CmsModel, params: CmsEntryStorageOperationsPublishParams<T>): Promise<import("@webiny/api-headless-cms/types/types.js").CmsEntry<T>>;
|
|
11
|
+
}
|
|
12
|
+
export declare const SqlPublishEntry: typeof SqlPublishEntryImpl & {
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-headless-cms/features/shared/storageOperations/entry/PublishEntryStorageOperation.js").IPublishEntryStorageOperation>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { PublishEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/PublishEntryStorageOperation.js";
|
|
2
|
+
import { KnexClient } from "@webiny/api-core-sql";
|
|
3
|
+
import { EntryTableManager } from "../../features/entryTableManager/abstractions.js";
|
|
4
|
+
import { entryToRow } from "./mappers.js";
|
|
5
|
+
import { createModelEntryQuery, syncEntryToLatest } from "./queryHelpers.js";
|
|
6
|
+
class SqlPublishEntryImpl {
|
|
7
|
+
constructor(knexClient, entryTableManager){
|
|
8
|
+
this.entryTableManager = entryTableManager;
|
|
9
|
+
this.knex = knexClient.client;
|
|
10
|
+
}
|
|
11
|
+
modelQuery(model) {
|
|
12
|
+
return createModelEntryQuery(this.knex, this.entryTableManager.getTableName(), model);
|
|
13
|
+
}
|
|
14
|
+
async execute(model, params) {
|
|
15
|
+
await this.entryTableManager.ensureTable();
|
|
16
|
+
const oldPublishedRows = await this.modelQuery(model).andWhere("entryId", params.entry.entryId).andWhere("isPublished", true);
|
|
17
|
+
for (const row of oldPublishedRows){
|
|
18
|
+
const parsed = JSON.parse(row.data);
|
|
19
|
+
parsed.isPublished = false;
|
|
20
|
+
parsed.status = "unpublished";
|
|
21
|
+
await this.modelQuery(model).andWhere("id", row.id).update({
|
|
22
|
+
isPublished: false,
|
|
23
|
+
data: JSON.stringify(parsed)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const existing = await this.modelQuery(model).andWhere("id", params.storageEntry.id).first();
|
|
27
|
+
const se = params.storageEntry;
|
|
28
|
+
se.isLatest = existing?.isLatest ?? se.isLatest;
|
|
29
|
+
se.isPublished = true;
|
|
30
|
+
const row = entryToRow(se);
|
|
31
|
+
const { isLatest: _il, ...rowWithoutIsLatest } = row;
|
|
32
|
+
await this.modelQuery(model).andWhere("id", params.storageEntry.id).update(rowWithoutIsLatest);
|
|
33
|
+
const liveValue = {
|
|
34
|
+
version: params.entry.version
|
|
35
|
+
};
|
|
36
|
+
await syncEntryToLatest(this.knex, this.entryTableManager.getTableName(), model, se, (latest)=>{
|
|
37
|
+
latest.live = liveValue;
|
|
38
|
+
});
|
|
39
|
+
return params.entry;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const SqlPublishEntry = PublishEntryStorageOperation.createImplementation({
|
|
43
|
+
implementation: SqlPublishEntryImpl,
|
|
44
|
+
dependencies: [
|
|
45
|
+
KnexClient,
|
|
46
|
+
EntryTableManager
|
|
47
|
+
]
|
|
48
|
+
});
|
|
49
|
+
export { SqlPublishEntry };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=SqlPublishEntry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/SqlPublishEntry.js","sources":["../../../src/operations/entry/SqlPublishEntry.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type {\n CmsEntryStorageOperationsPublishParams,\n CmsEntryValues,\n CmsModel,\n CmsStorageEntry\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { PublishEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/PublishEntryStorageOperation.js\";\nimport { KnexClient } from \"@webiny/api-core-sql\";\nimport { EntryTableManager } from \"~/features/entryTableManager/abstractions.js\";\nimport type { IEntryRow } from \"./types.js\";\nimport { entryToRow } from \"./mappers.js\";\nimport { createModelEntryQuery, syncEntryToLatest } from \"./queryHelpers.js\";\n\nclass SqlPublishEntryImpl implements PublishEntryStorageOperation.Interface {\n private readonly knex: Knex;\n\n public constructor(\n knexClient: KnexClient.Interface,\n private readonly entryTableManager: EntryTableManager.Interface\n ) {\n this.knex = knexClient.client;\n }\n\n private modelQuery(model: CmsModel): Knex.QueryBuilder<IEntryRow> {\n return createModelEntryQuery(this.knex, this.entryTableManager.getTableName(), model);\n }\n\n async execute<T extends CmsEntryValues>(\n model: CmsModel,\n params: CmsEntryStorageOperationsPublishParams<T>\n ) {\n await this.entryTableManager.ensureTable();\n\n const oldPublishedRows = await this.modelQuery(model)\n .andWhere(\"entryId\", params.entry.entryId)\n .andWhere(\"isPublished\", true);\n\n for (const row of oldPublishedRows) {\n const parsed = JSON.parse(row.data);\n parsed.isPublished = false;\n parsed.status = \"unpublished\";\n\n await this.modelQuery(model)\n .andWhere(\"id\", row.id)\n .update({ isPublished: false, data: JSON.stringify(parsed) });\n }\n\n const existing = await this.modelQuery(model)\n .andWhere(\"id\", params.storageEntry.id)\n .first();\n const se = params.storageEntry as CmsStorageEntry;\n se.isLatest = existing?.isLatest ?? se.isLatest;\n se.isPublished = true;\n\n const row = entryToRow(se);\n const { isLatest: _il, ...rowWithoutIsLatest } = row;\n\n await this.modelQuery(model)\n .andWhere(\"id\", params.storageEntry.id)\n .update(rowWithoutIsLatest);\n\n const liveValue = { version: params.entry.version };\n await syncEntryToLatest(\n this.knex,\n this.entryTableManager.getTableName(),\n model,\n se,\n latest => {\n latest.live = liveValue;\n }\n );\n\n return params.entry;\n }\n}\n\nexport const SqlPublishEntry = PublishEntryStorageOperation.createImplementation({\n implementation: SqlPublishEntryImpl,\n dependencies: [KnexClient, EntryTableManager]\n});\n"],"names":["SqlPublishEntryImpl","knexClient","entryTableManager","model","createModelEntryQuery","params","oldPublishedRows","row","parsed","JSON","existing","se","entryToRow","_il","rowWithoutIsLatest","liveValue","syncEntryToLatest","latest","SqlPublishEntry","PublishEntryStorageOperation","KnexClient","EntryTableManager"],"mappings":";;;;;AAcA,MAAMA;IAGF,YACIC,UAAgC,EACfC,iBAA8C,CACjE;aADmBA,iBAAiB,GAAjBA;QAEjB,IAAI,CAAC,IAAI,GAAGD,WAAW,MAAM;IACjC;IAEQ,WAAWE,KAAe,EAAgC;QAC9D,OAAOC,sBAAsB,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,YAAY,IAAID;IACnF;IAEA,MAAM,QACFA,KAAe,EACfE,MAAiD,EACnD;QACE,MAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW;QAExC,MAAMC,mBAAmB,MAAM,IAAI,CAAC,UAAU,CAACH,OAC1C,QAAQ,CAAC,WAAWE,OAAO,KAAK,CAAC,OAAO,EACxC,QAAQ,CAAC,eAAe;QAE7B,KAAK,MAAME,OAAOD,iBAAkB;YAChC,MAAME,SAASC,KAAK,KAAK,CAACF,IAAI,IAAI;YAClCC,OAAO,WAAW,GAAG;YACrBA,OAAO,MAAM,GAAG;YAEhB,MAAM,IAAI,CAAC,UAAU,CAACL,OACjB,QAAQ,CAAC,MAAMI,IAAI,EAAE,EACrB,MAAM,CAAC;gBAAE,aAAa;gBAAO,MAAME,KAAK,SAAS,CAACD;YAAQ;QACnE;QAEA,MAAME,WAAW,MAAM,IAAI,CAAC,UAAU,CAACP,OAClC,QAAQ,CAAC,MAAME,OAAO,YAAY,CAAC,EAAE,EACrC,KAAK;QACV,MAAMM,KAAKN,OAAO,YAAY;QAC9BM,GAAG,QAAQ,GAAGD,UAAU,YAAYC,GAAG,QAAQ;QAC/CA,GAAG,WAAW,GAAG;QAEjB,MAAMJ,MAAMK,WAAWD;QACvB,MAAM,EAAE,UAAUE,GAAG,EAAE,GAAGC,oBAAoB,GAAGP;QAEjD,MAAM,IAAI,CAAC,UAAU,CAACJ,OACjB,QAAQ,CAAC,MAAME,OAAO,YAAY,CAAC,EAAE,EACrC,MAAM,CAACS;QAEZ,MAAMC,YAAY;YAAE,SAASV,OAAO,KAAK,CAAC,OAAO;QAAC;QAClD,MAAMW,kBACF,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,iBAAiB,CAAC,YAAY,IACnCb,OACAQ,IACAM,CAAAA;YACIA,OAAO,IAAI,GAAGF;QAClB;QAGJ,OAAOV,OAAO,KAAK;IACvB;AACJ;AAEO,MAAMa,kBAAkBC,6BAA6B,oBAAoB,CAAC;IAC7E,gBAAgBnB;IAChB,cAAc;QAACoB;QAAYC;KAAkB;AACjD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CmsEntryStorageOperationsRestoreFromBinParams, CmsEntryValues, CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import { RestoreFromBinStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/RestoreFromBinStorageOperation.js";
|
|
3
|
+
import { KnexClient } from "@webiny/api-core-sql";
|
|
4
|
+
import { EntryTableManager } from "../../features/entryTableManager/abstractions.js";
|
|
5
|
+
declare class SqlRestoreFromBinImpl implements RestoreFromBinStorageOperation.Interface {
|
|
6
|
+
private readonly entryTableManager;
|
|
7
|
+
private readonly knex;
|
|
8
|
+
constructor(knexClient: KnexClient.Interface, entryTableManager: EntryTableManager.Interface);
|
|
9
|
+
execute<T extends CmsEntryValues>(model: CmsModel, params: CmsEntryStorageOperationsRestoreFromBinParams<T>): Promise<import("@webiny/api-headless-cms/types/types.js").CmsEntry<T>>;
|
|
10
|
+
}
|
|
11
|
+
export declare const SqlRestoreFromBin: typeof SqlRestoreFromBinImpl & {
|
|
12
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-headless-cms/features/shared/storageOperations/entry/RestoreFromBinStorageOperation.js").IRestoreFromBinStorageOperation>;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { RestoreFromBinStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/RestoreFromBinStorageOperation.js";
|
|
2
|
+
import { KnexClient } from "@webiny/api-core-sql";
|
|
3
|
+
import { EntryTableManager } from "../../features/entryTableManager/abstractions.js";
|
|
4
|
+
import { patchAllEntryRevisions } from "./queryHelpers.js";
|
|
5
|
+
class SqlRestoreFromBinImpl {
|
|
6
|
+
constructor(knexClient, entryTableManager){
|
|
7
|
+
this.entryTableManager = entryTableManager;
|
|
8
|
+
this.knex = knexClient.client;
|
|
9
|
+
}
|
|
10
|
+
async execute(model, params) {
|
|
11
|
+
await this.entryTableManager.ensureTable();
|
|
12
|
+
await patchAllEntryRevisions(this.knex, this.entryTableManager.getTableName(), model, params.entry.entryId, (parsed)=>{
|
|
13
|
+
const p = parsed;
|
|
14
|
+
p["wbyDeleted"] = false;
|
|
15
|
+
p["binOriginalFolderId"] = null;
|
|
16
|
+
p["location"] = params.storageEntry.location ?? null;
|
|
17
|
+
const fields = Object.keys(params.storageEntry);
|
|
18
|
+
for (const field of fields)if ("createdOn" !== field && "createdBy" !== field) {
|
|
19
|
+
if ((field.endsWith("On") || field.endsWith("By")) && !field.startsWith("revision")) p[field] = params.storageEntry[field];
|
|
20
|
+
}
|
|
21
|
+
}, {
|
|
22
|
+
wbyDeleted: false
|
|
23
|
+
});
|
|
24
|
+
return params.entry;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const SqlRestoreFromBin = RestoreFromBinStorageOperation.createImplementation({
|
|
28
|
+
implementation: SqlRestoreFromBinImpl,
|
|
29
|
+
dependencies: [
|
|
30
|
+
KnexClient,
|
|
31
|
+
EntryTableManager
|
|
32
|
+
]
|
|
33
|
+
});
|
|
34
|
+
export { SqlRestoreFromBin };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=SqlRestoreFromBin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/SqlRestoreFromBin.js","sources":["../../../src/operations/entry/SqlRestoreFromBin.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type {\n CmsEntryStorageOperationsRestoreFromBinParams,\n CmsEntryValues,\n CmsModel\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { RestoreFromBinStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/RestoreFromBinStorageOperation.js\";\nimport { KnexClient } from \"@webiny/api-core-sql\";\nimport { EntryTableManager } from \"~/features/entryTableManager/abstractions.js\";\nimport { patchAllEntryRevisions } from \"./queryHelpers.js\";\n\nclass SqlRestoreFromBinImpl implements RestoreFromBinStorageOperation.Interface {\n private readonly knex: Knex;\n\n public constructor(\n knexClient: KnexClient.Interface,\n private readonly entryTableManager: EntryTableManager.Interface\n ) {\n this.knex = knexClient.client;\n }\n\n async execute<T extends CmsEntryValues>(\n model: CmsModel,\n params: CmsEntryStorageOperationsRestoreFromBinParams<T>\n ) {\n await this.entryTableManager.ensureTable();\n\n await patchAllEntryRevisions(\n this.knex,\n this.entryTableManager.getTableName(),\n model,\n params.entry.entryId,\n parsed => {\n const p = parsed as unknown as Record<string, unknown>;\n p[\"wbyDeleted\"] = false;\n p[\"binOriginalFolderId\"] = null;\n p[\"location\"] = params.storageEntry.location ?? null;\n\n const fields = Object.keys(params.storageEntry);\n for (const field of fields) {\n if (field === \"createdOn\" || field === \"createdBy\") {\n continue;\n }\n if (\n (field.endsWith(\"On\") || field.endsWith(\"By\")) &&\n !field.startsWith(\"revision\")\n ) {\n p[field] = (params.storageEntry as Record<string, unknown>)[field];\n }\n }\n },\n { wbyDeleted: false }\n );\n\n return params.entry;\n }\n}\n\nexport const SqlRestoreFromBin = RestoreFromBinStorageOperation.createImplementation({\n implementation: SqlRestoreFromBinImpl,\n dependencies: [KnexClient, EntryTableManager]\n});\n"],"names":["SqlRestoreFromBinImpl","knexClient","entryTableManager","model","params","patchAllEntryRevisions","parsed","p","fields","Object","field","SqlRestoreFromBin","RestoreFromBinStorageOperation","KnexClient","EntryTableManager"],"mappings":";;;;AAWA,MAAMA;IAGF,YACIC,UAAgC,EACfC,iBAA8C,CACjE;aADmBA,iBAAiB,GAAjBA;QAEjB,IAAI,CAAC,IAAI,GAAGD,WAAW,MAAM;IACjC;IAEA,MAAM,QACFE,KAAe,EACfC,MAAwD,EAC1D;QACE,MAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW;QAExC,MAAMC,uBACF,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,iBAAiB,CAAC,YAAY,IACnCF,OACAC,OAAO,KAAK,CAAC,OAAO,EACpBE,CAAAA;YACI,MAAMC,IAAID;YACVC,CAAC,CAAC,aAAa,GAAG;YAClBA,CAAC,CAAC,sBAAsB,GAAG;YAC3BA,CAAC,CAAC,WAAW,GAAGH,OAAO,YAAY,CAAC,QAAQ,IAAI;YAEhD,MAAMI,SAASC,OAAO,IAAI,CAACL,OAAO,YAAY;YAC9C,KAAK,MAAMM,SAASF,OAChB,IAAIE,AAAU,gBAAVA,SAAyBA,AAAU,gBAAVA,OAG7B;gBAAA,IACKA,AAAAA,CAAAA,MAAM,QAAQ,CAAC,SAASA,MAAM,QAAQ,CAAC,KAAI,KAC5C,CAACA,MAAM,UAAU,CAAC,aAElBH,CAAC,CAACG,MAAM,GAAIN,OAAO,YAAwC,CAACM,MAAM;YACtE;QAER,GACA;YAAE,YAAY;QAAM;QAGxB,OAAON,OAAO,KAAK;IACvB;AACJ;AAEO,MAAMO,oBAAoBC,+BAA+B,oBAAoB,CAAC;IACjF,gBAAgBZ;IAChB,cAAc;QAACa;QAAYC;KAAkB;AACjD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CmsEntryStorageOperationsUnpublishParams, CmsEntryValues, CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import { UnpublishEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/UnpublishEntryStorageOperation.js";
|
|
3
|
+
import { KnexClient } from "@webiny/api-core-sql";
|
|
4
|
+
import { EntryTableManager } from "../../features/entryTableManager/abstractions.js";
|
|
5
|
+
declare class SqlUnpublishEntryImpl implements UnpublishEntryStorageOperation.Interface {
|
|
6
|
+
private readonly entryTableManager;
|
|
7
|
+
private readonly knex;
|
|
8
|
+
constructor(knexClient: KnexClient.Interface, entryTableManager: EntryTableManager.Interface);
|
|
9
|
+
private modelQuery;
|
|
10
|
+
execute<T extends CmsEntryValues>(model: CmsModel, params: CmsEntryStorageOperationsUnpublishParams<T>): Promise<import("@webiny/api-headless-cms/types/types.js").CmsEntry<T>>;
|
|
11
|
+
}
|
|
12
|
+
export declare const SqlUnpublishEntry: typeof SqlUnpublishEntryImpl & {
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-headless-cms/features/shared/storageOperations/entry/UnpublishEntryStorageOperation.js").IUnpublishEntryStorageOperation>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { UnpublishEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/UnpublishEntryStorageOperation.js";
|
|
2
|
+
import { KnexClient } from "@webiny/api-core-sql";
|
|
3
|
+
import { EntryTableManager } from "../../features/entryTableManager/abstractions.js";
|
|
4
|
+
import { entryToRow } from "./mappers.js";
|
|
5
|
+
import { createModelEntryQuery, syncEntryToLatest } from "./queryHelpers.js";
|
|
6
|
+
class SqlUnpublishEntryImpl {
|
|
7
|
+
constructor(knexClient, entryTableManager){
|
|
8
|
+
this.entryTableManager = entryTableManager;
|
|
9
|
+
this.knex = knexClient.client;
|
|
10
|
+
}
|
|
11
|
+
modelQuery(model) {
|
|
12
|
+
return createModelEntryQuery(this.knex, this.entryTableManager.getTableName(), model);
|
|
13
|
+
}
|
|
14
|
+
async execute(model, params) {
|
|
15
|
+
await this.entryTableManager.ensureTable();
|
|
16
|
+
const existing = await this.modelQuery(model).andWhere("id", params.storageEntry.id).first();
|
|
17
|
+
const se = params.storageEntry;
|
|
18
|
+
se.isLatest = existing?.isLatest ?? se.isLatest;
|
|
19
|
+
se.isPublished = false;
|
|
20
|
+
const row = entryToRow(se);
|
|
21
|
+
const { isLatest: _il, ...rowWithoutIsLatest } = row;
|
|
22
|
+
await this.modelQuery(model).andWhere("id", params.storageEntry.id).update(rowWithoutIsLatest);
|
|
23
|
+
await syncEntryToLatest(this.knex, this.entryTableManager.getTableName(), model, se, (latest)=>{
|
|
24
|
+
latest.live = null;
|
|
25
|
+
});
|
|
26
|
+
return params.entry;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const SqlUnpublishEntry = UnpublishEntryStorageOperation.createImplementation({
|
|
30
|
+
implementation: SqlUnpublishEntryImpl,
|
|
31
|
+
dependencies: [
|
|
32
|
+
KnexClient,
|
|
33
|
+
EntryTableManager
|
|
34
|
+
]
|
|
35
|
+
});
|
|
36
|
+
export { SqlUnpublishEntry };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=SqlUnpublishEntry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/SqlUnpublishEntry.js","sources":["../../../src/operations/entry/SqlUnpublishEntry.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type {\n CmsEntryStorageOperationsUnpublishParams,\n CmsEntryValues,\n CmsModel,\n CmsStorageEntry\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { UnpublishEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/UnpublishEntryStorageOperation.js\";\nimport { KnexClient } from \"@webiny/api-core-sql\";\nimport { EntryTableManager } from \"~/features/entryTableManager/abstractions.js\";\nimport type { IEntryRow } from \"./types.js\";\nimport { entryToRow } from \"./mappers.js\";\nimport { createModelEntryQuery, syncEntryToLatest } from \"./queryHelpers.js\";\n\nclass SqlUnpublishEntryImpl implements UnpublishEntryStorageOperation.Interface {\n private readonly knex: Knex;\n\n public constructor(\n knexClient: KnexClient.Interface,\n private readonly entryTableManager: EntryTableManager.Interface\n ) {\n this.knex = knexClient.client;\n }\n\n private modelQuery(model: CmsModel): Knex.QueryBuilder<IEntryRow> {\n return createModelEntryQuery(this.knex, this.entryTableManager.getTableName(), model);\n }\n\n async execute<T extends CmsEntryValues>(\n model: CmsModel,\n params: CmsEntryStorageOperationsUnpublishParams<T>\n ) {\n await this.entryTableManager.ensureTable();\n\n const existing = await this.modelQuery(model)\n .andWhere(\"id\", params.storageEntry.id)\n .first();\n const se = params.storageEntry as CmsStorageEntry;\n se.isLatest = existing?.isLatest ?? se.isLatest;\n se.isPublished = false;\n\n const row = entryToRow(se);\n const { isLatest: _il, ...rowWithoutIsLatest } = row;\n\n await this.modelQuery(model)\n .andWhere(\"id\", params.storageEntry.id)\n .update(rowWithoutIsLatest);\n\n await syncEntryToLatest(\n this.knex,\n this.entryTableManager.getTableName(),\n model,\n se,\n latest => {\n latest.live = null;\n }\n );\n\n return params.entry;\n }\n}\n\nexport const SqlUnpublishEntry = UnpublishEntryStorageOperation.createImplementation({\n implementation: SqlUnpublishEntryImpl,\n dependencies: [KnexClient, EntryTableManager]\n});\n"],"names":["SqlUnpublishEntryImpl","knexClient","entryTableManager","model","createModelEntryQuery","params","existing","se","row","entryToRow","_il","rowWithoutIsLatest","syncEntryToLatest","latest","SqlUnpublishEntry","UnpublishEntryStorageOperation","KnexClient","EntryTableManager"],"mappings":";;;;;AAcA,MAAMA;IAGF,YACIC,UAAgC,EACfC,iBAA8C,CACjE;aADmBA,iBAAiB,GAAjBA;QAEjB,IAAI,CAAC,IAAI,GAAGD,WAAW,MAAM;IACjC;IAEQ,WAAWE,KAAe,EAAgC;QAC9D,OAAOC,sBAAsB,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,YAAY,IAAID;IACnF;IAEA,MAAM,QACFA,KAAe,EACfE,MAAmD,EACrD;QACE,MAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW;QAExC,MAAMC,WAAW,MAAM,IAAI,CAAC,UAAU,CAACH,OAClC,QAAQ,CAAC,MAAME,OAAO,YAAY,CAAC,EAAE,EACrC,KAAK;QACV,MAAME,KAAKF,OAAO,YAAY;QAC9BE,GAAG,QAAQ,GAAGD,UAAU,YAAYC,GAAG,QAAQ;QAC/CA,GAAG,WAAW,GAAG;QAEjB,MAAMC,MAAMC,WAAWF;QACvB,MAAM,EAAE,UAAUG,GAAG,EAAE,GAAGC,oBAAoB,GAAGH;QAEjD,MAAM,IAAI,CAAC,UAAU,CAACL,OACjB,QAAQ,CAAC,MAAME,OAAO,YAAY,CAAC,EAAE,EACrC,MAAM,CAACM;QAEZ,MAAMC,kBACF,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,iBAAiB,CAAC,YAAY,IACnCT,OACAI,IACAM,CAAAA;YACIA,OAAO,IAAI,GAAG;QAClB;QAGJ,OAAOR,OAAO,KAAK;IACvB;AACJ;AAEO,MAAMS,oBAAoBC,+BAA+B,oBAAoB,CAAC;IACjF,gBAAgBf;IAChB,cAAc;QAACgB;QAAYC;KAAkB;AACjD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CmsEntryStorageOperationsUpdateParams, CmsEntryValues, CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import { UpdateEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/UpdateEntryStorageOperation.js";
|
|
3
|
+
import { KnexClient } from "@webiny/api-core-sql";
|
|
4
|
+
import { EntryTableManager } from "../../features/entryTableManager/abstractions.js";
|
|
5
|
+
declare class SqlUpdateEntryImpl implements UpdateEntryStorageOperation.Interface {
|
|
6
|
+
private readonly entryTableManager;
|
|
7
|
+
private readonly knex;
|
|
8
|
+
constructor(knexClient: KnexClient.Interface, entryTableManager: EntryTableManager.Interface);
|
|
9
|
+
private modelQuery;
|
|
10
|
+
execute<T extends CmsEntryValues>(model: CmsModel, params: CmsEntryStorageOperationsUpdateParams<T>): Promise<import("@webiny/api-headless-cms/types/types.js").CmsEntry<T>>;
|
|
11
|
+
}
|
|
12
|
+
export declare const SqlUpdateEntry: typeof SqlUpdateEntryImpl & {
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-headless-cms/features/shared/storageOperations/entry/UpdateEntryStorageOperation.js").IUpdateEntryStorageOperation>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { UpdateEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/UpdateEntryStorageOperation.js";
|
|
2
|
+
import { KnexClient } from "@webiny/api-core-sql";
|
|
3
|
+
import { EntryTableManager } from "../../features/entryTableManager/abstractions.js";
|
|
4
|
+
import { entryToRow } from "./mappers.js";
|
|
5
|
+
import { createModelEntryQuery, syncEntryToLatest } from "./queryHelpers.js";
|
|
6
|
+
class SqlUpdateEntryImpl {
|
|
7
|
+
constructor(knexClient, entryTableManager){
|
|
8
|
+
this.entryTableManager = entryTableManager;
|
|
9
|
+
this.knex = knexClient.client;
|
|
10
|
+
}
|
|
11
|
+
modelQuery(model) {
|
|
12
|
+
return createModelEntryQuery(this.knex, this.entryTableManager.getTableName(), model);
|
|
13
|
+
}
|
|
14
|
+
async execute(model, params) {
|
|
15
|
+
await this.entryTableManager.ensureTable();
|
|
16
|
+
const existing = await this.modelQuery(model).andWhere("id", params.storageEntry.id).first();
|
|
17
|
+
const se = params.storageEntry;
|
|
18
|
+
se.isLatest = existing?.isLatest ?? se.isLatest;
|
|
19
|
+
se.isPublished = existing?.isPublished ?? se.isPublished;
|
|
20
|
+
const row = entryToRow(se);
|
|
21
|
+
const { isLatest: _il, isPublished: _ip, ...rowWithoutFlags } = row;
|
|
22
|
+
await this.modelQuery(model).andWhere("id", params.storageEntry.id).update(rowWithoutFlags);
|
|
23
|
+
await syncEntryToLatest(this.knex, this.entryTableManager.getTableName(), model, se);
|
|
24
|
+
return params.entry;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const SqlUpdateEntry = UpdateEntryStorageOperation.createImplementation({
|
|
28
|
+
implementation: SqlUpdateEntryImpl,
|
|
29
|
+
dependencies: [
|
|
30
|
+
KnexClient,
|
|
31
|
+
EntryTableManager
|
|
32
|
+
]
|
|
33
|
+
});
|
|
34
|
+
export { SqlUpdateEntry };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=SqlUpdateEntry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/SqlUpdateEntry.js","sources":["../../../src/operations/entry/SqlUpdateEntry.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type {\n CmsEntryStorageOperationsUpdateParams,\n CmsEntryValues,\n CmsModel,\n CmsStorageEntry\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { UpdateEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/UpdateEntryStorageOperation.js\";\nimport { KnexClient } from \"@webiny/api-core-sql\";\nimport { EntryTableManager } from \"~/features/entryTableManager/abstractions.js\";\nimport type { IEntryRow } from \"./types.js\";\nimport { entryToRow } from \"./mappers.js\";\nimport { createModelEntryQuery, syncEntryToLatest } from \"./queryHelpers.js\";\n\nclass SqlUpdateEntryImpl implements UpdateEntryStorageOperation.Interface {\n private readonly knex: Knex;\n\n public constructor(\n knexClient: KnexClient.Interface,\n private readonly entryTableManager: EntryTableManager.Interface\n ) {\n this.knex = knexClient.client;\n }\n\n private modelQuery(model: CmsModel): Knex.QueryBuilder<IEntryRow> {\n return createModelEntryQuery(this.knex, this.entryTableManager.getTableName(), model);\n }\n\n async execute<T extends CmsEntryValues>(\n model: CmsModel,\n params: CmsEntryStorageOperationsUpdateParams<T>\n ) {\n await this.entryTableManager.ensureTable();\n\n const existing = await this.modelQuery(model)\n .andWhere(\"id\", params.storageEntry.id)\n .first();\n const se = params.storageEntry as CmsStorageEntry;\n se.isLatest = existing?.isLatest ?? se.isLatest;\n se.isPublished = existing?.isPublished ?? se.isPublished;\n\n const row = entryToRow(se);\n const { isLatest: _il, isPublished: _ip, ...rowWithoutFlags } = row;\n\n await this.modelQuery(model).andWhere(\"id\", params.storageEntry.id).update(rowWithoutFlags);\n\n await syncEntryToLatest(this.knex, this.entryTableManager.getTableName(), model, se);\n\n return params.entry;\n }\n}\n\nexport const SqlUpdateEntry = UpdateEntryStorageOperation.createImplementation({\n implementation: SqlUpdateEntryImpl,\n dependencies: [KnexClient, EntryTableManager]\n});\n"],"names":["SqlUpdateEntryImpl","knexClient","entryTableManager","model","createModelEntryQuery","params","existing","se","row","entryToRow","_il","_ip","rowWithoutFlags","syncEntryToLatest","SqlUpdateEntry","UpdateEntryStorageOperation","KnexClient","EntryTableManager"],"mappings":";;;;;AAcA,MAAMA;IAGF,YACIC,UAAgC,EACfC,iBAA8C,CACjE;aADmBA,iBAAiB,GAAjBA;QAEjB,IAAI,CAAC,IAAI,GAAGD,WAAW,MAAM;IACjC;IAEQ,WAAWE,KAAe,EAAgC;QAC9D,OAAOC,sBAAsB,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,YAAY,IAAID;IACnF;IAEA,MAAM,QACFA,KAAe,EACfE,MAAgD,EAClD;QACE,MAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW;QAExC,MAAMC,WAAW,MAAM,IAAI,CAAC,UAAU,CAACH,OAClC,QAAQ,CAAC,MAAME,OAAO,YAAY,CAAC,EAAE,EACrC,KAAK;QACV,MAAME,KAAKF,OAAO,YAAY;QAC9BE,GAAG,QAAQ,GAAGD,UAAU,YAAYC,GAAG,QAAQ;QAC/CA,GAAG,WAAW,GAAGD,UAAU,eAAeC,GAAG,WAAW;QAExD,MAAMC,MAAMC,WAAWF;QACvB,MAAM,EAAE,UAAUG,GAAG,EAAE,aAAaC,GAAG,EAAE,GAAGC,iBAAiB,GAAGJ;QAEhE,MAAM,IAAI,CAAC,UAAU,CAACL,OAAO,QAAQ,CAAC,MAAME,OAAO,YAAY,CAAC,EAAE,EAAE,MAAM,CAACO;QAE3E,MAAMC,kBAAkB,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,YAAY,IAAIV,OAAOI;QAEjF,OAAOF,OAAO,KAAK;IACvB;AACJ;AAEO,MAAMS,iBAAiBC,4BAA4B,oBAAoB,CAAC;IAC3E,gBAAgBf;IAChB,cAAc;QAACgB;QAAYC;KAAkB;AACjD"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api/index.js";
|
|
2
|
+
import { SqlCreateEntry } from "./SqlCreateEntry.js";
|
|
3
|
+
import { SqlCreateEntryRevisionFrom } from "./SqlCreateEntryRevisionFrom.js";
|
|
4
|
+
import { SqlUpdateEntry } from "./SqlUpdateEntry.js";
|
|
5
|
+
import { SqlDeleteEntry } from "./SqlDeleteEntry.js";
|
|
6
|
+
import { SqlDeleteEntryRevision } from "./SqlDeleteEntryRevision.js";
|
|
7
|
+
import { SqlDeleteMultipleEntries } from "./SqlDeleteMultipleEntries.js";
|
|
8
|
+
import { SqlMoveToBin } from "./SqlMoveToBin.js";
|
|
9
|
+
import { SqlRestoreFromBin } from "./SqlRestoreFromBin.js";
|
|
10
|
+
import { SqlPublishEntry } from "./SqlPublishEntry.js";
|
|
11
|
+
import { SqlUnpublishEntry } from "./SqlUnpublishEntry.js";
|
|
12
|
+
import { SqlMoveEntry } from "./SqlMoveEntry.js";
|
|
13
|
+
import { SqlGetEntry } from "./SqlGetEntry.js";
|
|
14
|
+
import { SqlListEntries } from "./SqlListEntries.js";
|
|
15
|
+
import { SqlGetEntriesByIds } from "./SqlGetEntriesByIds.js";
|
|
16
|
+
import { SqlGetLatestEntriesByIds } from "./SqlGetLatestEntriesByIds.js";
|
|
17
|
+
import { SqlGetPublishedEntriesByIds } from "./SqlGetPublishedEntriesByIds.js";
|
|
18
|
+
import { SqlGetRevisions } from "./SqlGetRevisions.js";
|
|
19
|
+
import { SqlGetRevisionById } from "./SqlGetRevisionById.js";
|
|
20
|
+
import { SqlGetLatestRevisionByEntryId } from "./SqlGetLatestRevisionByEntryId.js";
|
|
21
|
+
import { SqlGetPublishedRevisionByEntryId } from "./SqlGetPublishedRevisionByEntryId.js";
|
|
22
|
+
import { SqlGetPreviousRevision } from "./SqlGetPreviousRevision.js";
|
|
23
|
+
import { SqlGetUniqueFieldValues } from "./SqlGetUniqueFieldValues.js";
|
|
24
|
+
const SqlEntryStorageOpsFeature = createFeature({
|
|
25
|
+
name: "cms.sql.entryStorageOps",
|
|
26
|
+
register: (container)=>{
|
|
27
|
+
container.register(SqlCreateEntry);
|
|
28
|
+
container.register(SqlCreateEntryRevisionFrom);
|
|
29
|
+
container.register(SqlUpdateEntry);
|
|
30
|
+
container.register(SqlDeleteEntry);
|
|
31
|
+
container.register(SqlDeleteEntryRevision);
|
|
32
|
+
container.register(SqlDeleteMultipleEntries);
|
|
33
|
+
container.register(SqlMoveToBin);
|
|
34
|
+
container.register(SqlRestoreFromBin);
|
|
35
|
+
container.register(SqlPublishEntry);
|
|
36
|
+
container.register(SqlUnpublishEntry);
|
|
37
|
+
container.register(SqlMoveEntry);
|
|
38
|
+
container.register(SqlGetEntry);
|
|
39
|
+
container.register(SqlListEntries);
|
|
40
|
+
container.register(SqlGetEntriesByIds);
|
|
41
|
+
container.register(SqlGetLatestEntriesByIds);
|
|
42
|
+
container.register(SqlGetPublishedEntriesByIds);
|
|
43
|
+
container.register(SqlGetRevisions);
|
|
44
|
+
container.register(SqlGetRevisionById);
|
|
45
|
+
container.register(SqlGetLatestRevisionByEntryId);
|
|
46
|
+
container.register(SqlGetPublishedRevisionByEntryId);
|
|
47
|
+
container.register(SqlGetPreviousRevision);
|
|
48
|
+
container.register(SqlGetUniqueFieldValues);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
export { SqlEntryStorageOpsFeature };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/feature.js","sources":["../../../src/operations/entry/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api/index.js\";\nimport { SqlCreateEntry } from \"./SqlCreateEntry.js\";\nimport { SqlCreateEntryRevisionFrom } from \"./SqlCreateEntryRevisionFrom.js\";\nimport { SqlUpdateEntry } from \"./SqlUpdateEntry.js\";\nimport { SqlDeleteEntry } from \"./SqlDeleteEntry.js\";\nimport { SqlDeleteEntryRevision } from \"./SqlDeleteEntryRevision.js\";\nimport { SqlDeleteMultipleEntries } from \"./SqlDeleteMultipleEntries.js\";\nimport { SqlMoveToBin } from \"./SqlMoveToBin.js\";\nimport { SqlRestoreFromBin } from \"./SqlRestoreFromBin.js\";\nimport { SqlPublishEntry } from \"./SqlPublishEntry.js\";\nimport { SqlUnpublishEntry } from \"./SqlUnpublishEntry.js\";\nimport { SqlMoveEntry } from \"./SqlMoveEntry.js\";\nimport { SqlGetEntry } from \"./SqlGetEntry.js\";\nimport { SqlListEntries } from \"./SqlListEntries.js\";\nimport { SqlGetEntriesByIds } from \"./SqlGetEntriesByIds.js\";\nimport { SqlGetLatestEntriesByIds } from \"./SqlGetLatestEntriesByIds.js\";\nimport { SqlGetPublishedEntriesByIds } from \"./SqlGetPublishedEntriesByIds.js\";\nimport { SqlGetRevisions } from \"./SqlGetRevisions.js\";\nimport { SqlGetRevisionById } from \"./SqlGetRevisionById.js\";\nimport { SqlGetLatestRevisionByEntryId } from \"./SqlGetLatestRevisionByEntryId.js\";\nimport { SqlGetPublishedRevisionByEntryId } from \"./SqlGetPublishedRevisionByEntryId.js\";\nimport { SqlGetPreviousRevision } from \"./SqlGetPreviousRevision.js\";\nimport { SqlGetUniqueFieldValues } from \"./SqlGetUniqueFieldValues.js\";\n\nexport const SqlEntryStorageOpsFeature = createFeature({\n name: \"cms.sql.entryStorageOps\",\n register: container => {\n container.register(SqlCreateEntry);\n container.register(SqlCreateEntryRevisionFrom);\n container.register(SqlUpdateEntry);\n container.register(SqlDeleteEntry);\n container.register(SqlDeleteEntryRevision);\n container.register(SqlDeleteMultipleEntries);\n container.register(SqlMoveToBin);\n container.register(SqlRestoreFromBin);\n container.register(SqlPublishEntry);\n container.register(SqlUnpublishEntry);\n container.register(SqlMoveEntry);\n container.register(SqlGetEntry);\n container.register(SqlListEntries);\n container.register(SqlGetEntriesByIds);\n container.register(SqlGetLatestEntriesByIds);\n container.register(SqlGetPublishedEntriesByIds);\n container.register(SqlGetRevisions);\n container.register(SqlGetRevisionById);\n container.register(SqlGetLatestRevisionByEntryId);\n container.register(SqlGetPublishedRevisionByEntryId);\n container.register(SqlGetPreviousRevision);\n container.register(SqlGetUniqueFieldValues);\n }\n});\n"],"names":["SqlEntryStorageOpsFeature","createFeature","container","SqlCreateEntry","SqlCreateEntryRevisionFrom","SqlUpdateEntry","SqlDeleteEntry","SqlDeleteEntryRevision","SqlDeleteMultipleEntries","SqlMoveToBin","SqlRestoreFromBin","SqlPublishEntry","SqlUnpublishEntry","SqlMoveEntry","SqlGetEntry","SqlListEntries","SqlGetEntriesByIds","SqlGetLatestEntriesByIds","SqlGetPublishedEntriesByIds","SqlGetRevisions","SqlGetRevisionById","SqlGetLatestRevisionByEntryId","SqlGetPublishedRevisionByEntryId","SqlGetPreviousRevision","SqlGetUniqueFieldValues"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwBO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAAUC,CAAAA;QACNA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QACnBR,UAAU,QAAQ,CAACS;QACnBT,UAAU,QAAQ,CAACU;QACnBV,UAAU,QAAQ,CAACW;QACnBX,UAAU,QAAQ,CAACY;QACnBZ,UAAU,QAAQ,CAACa;QACnBb,UAAU,QAAQ,CAACc;QACnBd,UAAU,QAAQ,CAACe;QACnBf,UAAU,QAAQ,CAACgB;QACnBhB,UAAU,QAAQ,CAACiB;QACnBjB,UAAU,QAAQ,CAACkB;QACnBlB,UAAU,QAAQ,CAACmB;QACnBnB,UAAU,QAAQ,CAACoB;QACnBpB,UAAU,QAAQ,CAACqB;QACnBrB,UAAU,QAAQ,CAACsB;IACvB;AACJ"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CmsEntry, CmsEntryValues, CmsStorageEntry } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import type { IEntryRow } from "./types.js";
|
|
3
|
+
export declare const entryToRow: (entry: CmsStorageEntry) => IEntryRow;
|
|
4
|
+
export declare const rowToEntry: <T extends CmsEntryValues = CmsEntryValues>(row: IEntryRow) => CmsEntry<T>;
|
|
5
|
+
export declare const mergeEntryLevelMeta: (source: CmsEntry, target: CmsEntry) => CmsEntry;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const IMMUTABLE_FIELDS = new Set([
|
|
2
|
+
"createdOn",
|
|
3
|
+
"createdBy"
|
|
4
|
+
]);
|
|
5
|
+
const entryToRow = (entry)=>({
|
|
6
|
+
id: entry.id,
|
|
7
|
+
entryId: entry.entryId,
|
|
8
|
+
modelId: entry.modelId,
|
|
9
|
+
tenant: entry.tenant,
|
|
10
|
+
version: entry.version,
|
|
11
|
+
isLatest: entry.isLatest,
|
|
12
|
+
isPublished: entry.isPublished,
|
|
13
|
+
wbyDeleted: entry.wbyDeleted ?? false,
|
|
14
|
+
data: JSON.stringify(entry)
|
|
15
|
+
});
|
|
16
|
+
const rowToEntry = (row)=>JSON.parse(row.data);
|
|
17
|
+
const mergeEntryLevelMeta = (source, target)=>{
|
|
18
|
+
const result = structuredClone(target);
|
|
19
|
+
for (const field of Object.keys(source))if (!IMMUTABLE_FIELDS.has(field)) {
|
|
20
|
+
if ((field.endsWith("On") || field.endsWith("By")) && !field.startsWith("revision")) result[field] = source[field];
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
export { entryToRow, mergeEntryLevelMeta, rowToEntry };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=mappers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/mappers.js","sources":["../../../src/operations/entry/mappers.ts"],"sourcesContent":["import type {\n CmsEntry,\n CmsEntryValues,\n CmsStorageEntry\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport type { IEntryRow } from \"./types.js\";\n\nconst IMMUTABLE_FIELDS = new Set([\"createdOn\", \"createdBy\"]);\n\nexport const entryToRow = (entry: CmsStorageEntry): IEntryRow => {\n return {\n id: entry.id,\n entryId: entry.entryId,\n modelId: entry.modelId,\n tenant: entry.tenant,\n version: entry.version,\n isLatest: entry.isLatest,\n isPublished: entry.isPublished,\n wbyDeleted: entry.wbyDeleted ?? false,\n data: JSON.stringify(entry)\n };\n};\n\nexport const rowToEntry = <T extends CmsEntryValues = CmsEntryValues>(\n row: IEntryRow\n): CmsEntry<T> => {\n return JSON.parse(row.data) as CmsEntry<T>;\n};\n\n/*\n * Merges entry-level meta fields from source into target.\n * Syncs all *On and *By fields except immutable ones (createdOn, createdBy)\n * and revision-level ones (revisionCreatedOn, revisionModifiedBy, etc.).\n */\nexport const mergeEntryLevelMeta = (source: CmsEntry, target: CmsEntry): CmsEntry => {\n const result = structuredClone(target);\n\n for (const field of Object.keys(source)) {\n if (IMMUTABLE_FIELDS.has(field)) {\n continue;\n }\n if ((field.endsWith(\"On\") || field.endsWith(\"By\")) && !field.startsWith(\"revision\")) {\n (result as unknown as Record<string, unknown>)[field] = (\n source as unknown as Record<string, unknown>\n )[field];\n }\n }\n\n return result;\n};\n"],"names":["IMMUTABLE_FIELDS","Set","entryToRow","entry","JSON","rowToEntry","row","mergeEntryLevelMeta","source","target","result","structuredClone","field","Object"],"mappings":"AAOA,MAAMA,mBAAmB,IAAIC,IAAI;IAAC;IAAa;CAAY;AAEpD,MAAMC,aAAa,CAACC,QAChB;QACH,IAAIA,MAAM,EAAE;QACZ,SAASA,MAAM,OAAO;QACtB,SAASA,MAAM,OAAO;QACtB,QAAQA,MAAM,MAAM;QACpB,SAASA,MAAM,OAAO;QACtB,UAAUA,MAAM,QAAQ;QACxB,aAAaA,MAAM,WAAW;QAC9B,YAAYA,MAAM,UAAU,IAAI;QAChC,MAAMC,KAAK,SAAS,CAACD;IACzB;AAGG,MAAME,aAAa,CACtBC,MAEOF,KAAK,KAAK,CAACE,IAAI,IAAI;AAQvB,MAAMC,sBAAsB,CAACC,QAAkBC;IAClD,MAAMC,SAASC,gBAAgBF;IAE/B,KAAK,MAAMG,SAASC,OAAO,IAAI,CAACL,QAC5B,KAAIR,iBAAiB,GAAG,CAACY,QAGzB;QAAA,IAAKA,AAAAA,CAAAA,MAAM,QAAQ,CAAC,SAASA,MAAM,QAAQ,CAAC,KAAI,KAAM,CAACA,MAAM,UAAU,CAAC,aACnEF,MAA6C,CAACE,MAAM,GACjDJ,MACH,CAACI,MAAM;IACZ;IAGJ,OAAOF;AACX"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Knex } from "knex";
|
|
2
|
+
import type { CmsEntry, CmsEntryStorageOperationsListParams, CmsEntryStorageOperationsListResponse, CmsEntryValues, CmsModel, CmsModelField, CmsStorageEntry } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
+
import type { StorageTransformRegistry } from "@webiny/api-headless-cms/exports/api/cms/storage.js";
|
|
4
|
+
import type { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
5
|
+
import type { ValueFilterRegistry } from "@webiny/db-utils";
|
|
6
|
+
import type { FieldFilterPathRegistry, FieldFilterValueTransformRegistry, FieldFilterCreateRegistry, FieldSortingRegistry } from "@webiny/api-headless-cms-storage";
|
|
7
|
+
import type { IEntryRow } from "./types.js";
|
|
8
|
+
export declare const MAX_LIST_LIMIT = 1000000;
|
|
9
|
+
export declare const createEntryQuery: (knex: Knex, tableName: string) => Knex.QueryBuilder<IEntryRow>;
|
|
10
|
+
export interface IEntryQueryModel {
|
|
11
|
+
tenant: string;
|
|
12
|
+
modelId: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const createModelEntryQuery: (knex: Knex, tableName: string, model: IEntryQueryModel) => Knex.QueryBuilder<IEntryRow>;
|
|
15
|
+
export declare const syncEntryToLatest: (knex: Knex, tableName: string, model: IEntryQueryModel, entry: CmsStorageEntry, extraPatch?: (latest: CmsEntry) => void) => Promise<void>;
|
|
16
|
+
export declare const patchAllEntryRevisions: (knex: Knex, tableName: string, model: IEntryQueryModel, entryId: string, patch: (entry: CmsEntry) => void, columnUpdates?: Partial<IEntryRow>) => Promise<void>;
|
|
17
|
+
export interface IListEntriesDeps {
|
|
18
|
+
knex: Knex;
|
|
19
|
+
tableName: string;
|
|
20
|
+
storageModelProvider: CmsStorageModelProvider.Interface;
|
|
21
|
+
storageTransformRegistry: StorageTransformRegistry.Interface;
|
|
22
|
+
pathRegistry: FieldFilterPathRegistry.Interface;
|
|
23
|
+
transformRegistry: FieldFilterValueTransformRegistry.Interface;
|
|
24
|
+
filterCreateRegistry: FieldFilterCreateRegistry.Interface;
|
|
25
|
+
sortingRegistry: FieldSortingRegistry.Interface;
|
|
26
|
+
valueFilterRegistry: ValueFilterRegistry.Interface;
|
|
27
|
+
/** Fields registered as `CmsEntrySystemField`, filterable under `system`. */
|
|
28
|
+
systemFields: CmsModelField[];
|
|
29
|
+
}
|
|
30
|
+
export declare const listEntries: <T extends CmsEntryValues = CmsEntryValues>(deps: IListEntriesDeps, initialModel: CmsModel, params: CmsEntryStorageOperationsListParams) => Promise<CmsEntryStorageOperationsListResponse<CmsEntry<T>>>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { decodeCursor, encodeCursor } from "@webiny/utils";
|
|
2
|
+
import { createFields, createStorageTransformCallable, filter, sort } from "@webiny/api-headless-cms-storage";
|
|
3
|
+
import { mergeEntryLevelMeta, rowToEntry } from "./mappers.js";
|
|
4
|
+
const MAX_LIST_LIMIT = 1000000;
|
|
5
|
+
const createEntryQuery = (knex, tableName)=>knex(tableName);
|
|
6
|
+
const createModelEntryQuery = (knex, tableName, model)=>createEntryQuery(knex, tableName).where("tenant", model.tenant).andWhere("modelId", model.modelId);
|
|
7
|
+
const syncEntryToLatest = async (knex, tableName, model, entry, extraPatch)=>{
|
|
8
|
+
if (entry.isLatest) return;
|
|
9
|
+
const latestRow = await createModelEntryQuery(knex, tableName, model).andWhere("entryId", entry.entryId).andWhere("isLatest", true).first();
|
|
10
|
+
if (!latestRow) return;
|
|
11
|
+
const latest = JSON.parse(latestRow.data);
|
|
12
|
+
const merged = mergeEntryLevelMeta(entry, latest);
|
|
13
|
+
if (extraPatch) extraPatch(merged);
|
|
14
|
+
await createModelEntryQuery(knex, tableName, model).andWhere("id", latestRow.id).update({
|
|
15
|
+
data: JSON.stringify(merged)
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
const patchAllEntryRevisions = async (knex, tableName, model, entryId, patch, columnUpdates)=>{
|
|
19
|
+
const rows = await createModelEntryQuery(knex, tableName, model).andWhere("entryId", entryId);
|
|
20
|
+
if (0 === rows.length) return;
|
|
21
|
+
const cases = rows.map((row)=>{
|
|
22
|
+
const parsed = JSON.parse(row.data);
|
|
23
|
+
patch(parsed);
|
|
24
|
+
return {
|
|
25
|
+
id: row.id,
|
|
26
|
+
data: JSON.stringify(parsed)
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
const update = {
|
|
30
|
+
data: knex.raw(`CASE id ${cases.map(()=>"WHEN ? THEN ?").join(" ")} END`, cases.flatMap((c)=>[
|
|
31
|
+
c.id,
|
|
32
|
+
c.data
|
|
33
|
+
])),
|
|
34
|
+
...columnUpdates
|
|
35
|
+
};
|
|
36
|
+
await createModelEntryQuery(knex, tableName, model).andWhere("entryId", entryId).update(update);
|
|
37
|
+
};
|
|
38
|
+
const listEntries = async (deps, initialModel, params)=>{
|
|
39
|
+
const model = deps.storageModelProvider.getModel(initialModel);
|
|
40
|
+
const { where: initialWhere, sort: sortBy, search, fields: searchFields, limit: initialLimit, after } = params;
|
|
41
|
+
const limit = initialLimit <= 0 || initialLimit >= MAX_LIST_LIMIT ? MAX_LIST_LIMIT : initialLimit;
|
|
42
|
+
const qb = createEntryQuery(deps.knex, deps.tableName).where("tenant", model.tenant).andWhere("modelId", model.modelId);
|
|
43
|
+
if (initialWhere.entryId) qb.andWhere("entryId", initialWhere.entryId);
|
|
44
|
+
else if (true === initialWhere.published) qb.andWhere("isPublished", true);
|
|
45
|
+
else qb.andWhere("isLatest", true);
|
|
46
|
+
if (void 0 !== initialWhere.wbyDeleted) qb.andWhere("wbyDeleted", initialWhere.wbyDeleted);
|
|
47
|
+
else qb.andWhere("wbyDeleted", false);
|
|
48
|
+
const rows = await qb;
|
|
49
|
+
if (0 === rows.length) return {
|
|
50
|
+
hasMoreItems: false,
|
|
51
|
+
totalCount: 0,
|
|
52
|
+
cursor: null,
|
|
53
|
+
items: []
|
|
54
|
+
};
|
|
55
|
+
const fromStorage = createStorageTransformCallable(deps.storageTransformRegistry, model);
|
|
56
|
+
const records = await Promise.all(rows.map(async (row)=>{
|
|
57
|
+
const entry = rowToEntry(row);
|
|
58
|
+
for (const field of model.fields)entry.values[field.fieldId] = await fromStorage(field, entry.values[field.fieldId]);
|
|
59
|
+
return entry;
|
|
60
|
+
}));
|
|
61
|
+
const where = {
|
|
62
|
+
...initialWhere
|
|
63
|
+
};
|
|
64
|
+
delete where["published"];
|
|
65
|
+
delete where["latest"];
|
|
66
|
+
delete where["entryId"];
|
|
67
|
+
delete where["wbyDeleted"];
|
|
68
|
+
const modelFields = createFields({
|
|
69
|
+
pathRegistry: deps.pathRegistry,
|
|
70
|
+
transformRegistry: deps.transformRegistry,
|
|
71
|
+
fields: model.fields,
|
|
72
|
+
systemFields: deps.systemFields
|
|
73
|
+
});
|
|
74
|
+
const filteredItems = filter({
|
|
75
|
+
items: records,
|
|
76
|
+
where,
|
|
77
|
+
filterCreateRegistry: deps.filterCreateRegistry,
|
|
78
|
+
transformRegistry: deps.transformRegistry,
|
|
79
|
+
fields: modelFields,
|
|
80
|
+
fullTextSearch: {
|
|
81
|
+
term: search,
|
|
82
|
+
fields: searchFields || []
|
|
83
|
+
},
|
|
84
|
+
valueFilterRegistry: deps.valueFilterRegistry
|
|
85
|
+
});
|
|
86
|
+
const totalCount = filteredItems.length;
|
|
87
|
+
const sortedItems = sort({
|
|
88
|
+
model,
|
|
89
|
+
items: filteredItems,
|
|
90
|
+
sort: sortBy,
|
|
91
|
+
fields: modelFields,
|
|
92
|
+
sortingRegistry: deps.sortingRegistry
|
|
93
|
+
});
|
|
94
|
+
const start = parseInt(decodeCursor(after) || "0") || 0;
|
|
95
|
+
const hasMoreItems = totalCount > start + limit;
|
|
96
|
+
const slicedItems = sortedItems.slice(start, start + limit);
|
|
97
|
+
const cursor = encodeCursor(`${start + limit}`);
|
|
98
|
+
return {
|
|
99
|
+
hasMoreItems,
|
|
100
|
+
totalCount,
|
|
101
|
+
cursor,
|
|
102
|
+
items: slicedItems
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
export { MAX_LIST_LIMIT, createEntryQuery, createModelEntryQuery, listEntries, patchAllEntryRevisions, syncEntryToLatest };
|
|
106
|
+
|
|
107
|
+
//# sourceMappingURL=queryHelpers.js.map
|