@murumets-ee/content 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocks/index.d.mts +1 -1
- package/dist/blocks/index.mjs +1 -1
- package/dist/client.d.mts +38 -311
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +1 -1
- package/dist/client.mjs.map +1 -1
- package/dist/{define-block-DpMPEEdA.mjs → define-block-D-7OpIn5.mjs} +1 -1
- package/dist/{define-block-DpMPEEdA.mjs.map → define-block-D-7OpIn5.mjs.map} +1 -1
- package/dist/errors-kkf8Ue1H.mjs +2 -0
- package/dist/errors-kkf8Ue1H.mjs.map +1 -0
- package/dist/index-dos8Dc3T.d.mts +148 -0
- package/dist/index-dos8Dc3T.d.mts.map +1 -0
- package/dist/index.d.mts +3 -71
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/locale-utils-By7EdAT1.mjs +2 -0
- package/dist/locale-utils-By7EdAT1.mjs.map +1 -0
- package/dist/lock-service.d.mts +16 -10
- package/dist/lock-service.d.mts.map +1 -1
- package/dist/lock-service.mjs +1 -1
- package/dist/lock-service.mjs.map +1 -1
- package/dist/locks-BRtmYqgS.mjs +2 -0
- package/dist/{locks-BkO2qMfm.mjs.map → locks-BRtmYqgS.mjs.map} +1 -1
- package/dist/plugin-yijaaFS7.mjs +2 -0
- package/dist/plugin-yijaaFS7.mjs.map +1 -0
- package/dist/plugin.d.mts +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +1 -2
- package/dist/query-client.d.mts +1 -1
- package/dist/query-client.d.mts.map +1 -1
- package/dist/query-client.mjs +1 -1
- package/dist/query-client.mjs.map +1 -1
- package/dist/{types-D-ATlx7t.d.mts → types-BCmX1nBL.d.mts} +6 -6
- package/dist/types-BCmX1nBL.d.mts.map +1 -0
- package/dist/versionable-B0bP2Gib.mjs +2 -0
- package/dist/versionable-B0bP2Gib.mjs.map +1 -0
- package/package.json +8 -5
- package/dist/block-diff-BBH6FoFT.mjs +0 -2
- package/dist/block-diff-BBH6FoFT.mjs.map +0 -1
- package/dist/drafts-CyOivEtr.mjs +0 -2
- package/dist/drafts-CyOivEtr.mjs.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/locale-status-DTyv4wcn.mjs +0 -2
- package/dist/locale-status-DTyv4wcn.mjs.map +0 -1
- package/dist/locks-BkO2qMfm.mjs +0 -2
- package/dist/plugin.mjs.map +0 -1
- package/dist/registry-BJSOGFEN.mjs +0 -2
- package/dist/registry-BJSOGFEN.mjs.map +0 -1
- package/dist/rolldown-runtime-DR3Ue2cl.mjs +0 -1
- package/dist/types-COcneY5H.d.mts +0 -43
- package/dist/types-COcneY5H.d.mts.map +0 -1
- package/dist/types-D-ATlx7t.d.mts.map +0 -1
- package/dist/versions-CO6oDyet.mjs +0 -2
- package/dist/versions-CO6oDyet.mjs.map +0 -1
package/dist/blocks/index.d.mts
CHANGED
package/dist/blocks/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"../define-block-
|
|
1
|
+
import{t as e}from"../define-block-D-7OpIn5.mjs";import{field as t}from"@murumets-ee/entity";const n=e({slug:`code`,label:`Code`,fields:{code:t.text({required:!0}),language:t.select({options:[`javascript`,`typescript`,`python`,`html`,`css`,`json`,`bash`,`sql`,`other`]})}}),r=e({slug:`cta`,label:`Call to Action`,fields:{heading:t.text({required:!0,translatable:!0}),description:t.text({translatable:!0}),buttonText:t.text({required:!0,translatable:!0}),buttonLink:t.text({required:!0})}}),i=e({slug:`gallery`,label:`Gallery`,fields:{images:t.reference({entity:`media`,cardinality:`many`}),columns:t.select({options:[`2`,`3`,`4`]})}}),a=e({slug:`hero`,label:`Hero Section`,fields:{heading:t.text({required:!0,translatable:!0}),subheading:t.text({translatable:!0}),background:t.media({accept:[`image/*`]}),alignment:t.select({options:[`left`,`center`,`right`]})}}),o=e({slug:`image`,label:`Image`,fields:{image:t.media({accept:[`image/*`],required:!0}),alt:t.text({translatable:!0}),caption:t.text({translatable:!0})}}),s=e({slug:`quote`,label:`Quote`,fields:{quote:t.text({required:!0,translatable:!0}),attribution:t.text({translatable:!0})}}),c=e({slug:`richtext`,label:`Rich Text`,fields:{content:t.richtext({translatable:!0})}}),l=e({slug:`video`,label:`Video`,fields:{url:t.text({required:!0}),poster:t.media({accept:[`image/*`]}),caption:t.text({translatable:!0})}}),u=[c,o,a,i,r,l,s,n];export{r as CTABlock,n as CodeBlock,i as GalleryBlock,a as HeroBlock,o as ImageBlock,s as QuoteBlock,c as RichTextBlock,l as VideoBlock,u as commonBlocks};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/client.d.mts
CHANGED
|
@@ -1,355 +1,82 @@
|
|
|
1
|
-
import { d as TranslationStatus, f as VersionEntry, r as DraftEntry, s as LocalePublishStatus, u as TranslationReport } from "./types-
|
|
2
|
-
import {
|
|
3
|
-
import { Entity, FieldConfig
|
|
1
|
+
import { d as TranslationStatus, f as VersionEntry, r as DraftEntry, s as LocalePublishStatus, u as TranslationReport } from "./types-BCmX1nBL.mjs";
|
|
2
|
+
import { o as FieldDiff } from "./index-dos8Dc3T.mjs";
|
|
3
|
+
import { Entity, FieldConfig } from "@murumets-ee/entity";
|
|
4
4
|
import { Logger } from "@murumets-ee/core";
|
|
5
|
-
import { AdminClient, FindManyOptions } from "@murumets-ee/entity/admin";
|
|
5
|
+
import { AdminClient, FindManyOptions, InferCreateInput, InferEntityDTO as InferEntityDTO$1, InferUpdateInput } from "@murumets-ee/entity/admin";
|
|
6
6
|
|
|
7
7
|
//#region src/client.d.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
admin: AdminClient;
|
|
12
|
-
entity: Entity;
|
|
8
|
+
interface ContentClientConfig<AllFields extends Record<string, FieldConfig> = Record<string, FieldConfig>> {
|
|
9
|
+
admin: AdminClient<AllFields>;
|
|
10
|
+
entity: Entity<AllFields>;
|
|
13
11
|
logger?: Logger;
|
|
14
12
|
}
|
|
15
|
-
declare class ContentClient {
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
private versionableOptions;
|
|
20
|
-
constructor(config: ContentClientConfig);
|
|
21
|
-
/** Database handle inherited from the injected AdminClient. */
|
|
22
|
-
private get db();
|
|
23
|
-
/** Lazy TableClient for the drafts table. Returns null if the entity has no drafts table. */
|
|
24
|
-
private getDraftsClient;
|
|
25
|
-
/** Lazy TableClient for the versions table. Returns null if the entity has no versions table. */
|
|
26
|
-
private getVersionsClient;
|
|
27
|
-
/** Lazy TableClient for the locale_status table. Returns null if the entity has no locale_status table. */
|
|
28
|
-
private getLocaleStatusClient;
|
|
29
|
-
create(data: Record<string, EntityFieldValue>): Promise<{
|
|
30
|
-
id: string;
|
|
31
|
-
} & {} & {
|
|
32
|
-
[x: string]: Date | Record<string, unknown>[] | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | {
|
|
33
|
-
[key: string]: string | number | boolean | /*elided*/any | /*elided*/any | null;
|
|
34
|
-
} | null)[] | {
|
|
35
|
-
[key: string]: string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null;
|
|
36
|
-
} | null)[] | {
|
|
37
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
38
|
-
} | null)[] | {
|
|
39
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
40
|
-
} | null)[] | {
|
|
41
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
42
|
-
} | null)[] | {
|
|
43
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
44
|
-
} | null)[] | {
|
|
45
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
46
|
-
} | null)[] | {
|
|
47
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
48
|
-
} | null)[] | {
|
|
49
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
50
|
-
} | null)[] | {
|
|
51
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
52
|
-
} | null)[] | {
|
|
53
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
54
|
-
} | null)[] | {
|
|
55
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
56
|
-
} | null) | {
|
|
57
|
-
[key: string]: unknown;
|
|
58
|
-
_block: string;
|
|
59
|
-
_id: string;
|
|
60
|
-
}[] | undefined;
|
|
61
|
-
}>;
|
|
13
|
+
declare class ContentClient<AllFields extends Record<string, FieldConfig> = Record<string, FieldConfig>> {
|
|
14
|
+
private ctx;
|
|
15
|
+
constructor(config: ContentClientConfig<AllFields>);
|
|
16
|
+
create(data: InferCreateInput<AllFields>): Promise<InferEntityDTO$1<AllFields>>;
|
|
62
17
|
findById(id: string, options?: {
|
|
63
18
|
locale?: string;
|
|
64
|
-
}): Promise<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
[key: string]: string | number | boolean | /*elided*/any | /*elided*/any | null;
|
|
69
|
-
} | null)[] | {
|
|
70
|
-
[key: string]: string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null;
|
|
71
|
-
} | null)[] | {
|
|
72
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
73
|
-
} | null)[] | {
|
|
74
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
75
|
-
} | null)[] | {
|
|
76
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
77
|
-
} | null)[] | {
|
|
78
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
79
|
-
} | null)[] | {
|
|
80
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
81
|
-
} | null)[] | {
|
|
82
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
83
|
-
} | null)[] | {
|
|
84
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
85
|
-
} | null)[] | {
|
|
86
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
87
|
-
} | null)[] | {
|
|
88
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
89
|
-
} | null)[] | {
|
|
90
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
91
|
-
} | null) | {
|
|
92
|
-
[key: string]: unknown;
|
|
93
|
-
_block: string;
|
|
94
|
-
_id: string;
|
|
95
|
-
}[] | undefined;
|
|
96
|
-
}) | null>;
|
|
97
|
-
findMany(options?: FindManyOptions): Promise<({
|
|
98
|
-
id: string;
|
|
99
|
-
} & {} & {
|
|
100
|
-
[x: string]: Date | Record<string, unknown>[] | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | {
|
|
101
|
-
[key: string]: string | number | boolean | /*elided*/any | /*elided*/any | null;
|
|
102
|
-
} | null)[] | {
|
|
103
|
-
[key: string]: string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null;
|
|
104
|
-
} | null)[] | {
|
|
105
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
106
|
-
} | null)[] | {
|
|
107
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
108
|
-
} | null)[] | {
|
|
109
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
110
|
-
} | null)[] | {
|
|
111
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
112
|
-
} | null)[] | {
|
|
113
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
114
|
-
} | null)[] | {
|
|
115
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
116
|
-
} | null)[] | {
|
|
117
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
118
|
-
} | null)[] | {
|
|
119
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
120
|
-
} | null)[] | {
|
|
121
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
122
|
-
} | null)[] | {
|
|
123
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
124
|
-
} | null) | {
|
|
125
|
-
[key: string]: unknown;
|
|
126
|
-
_block: string;
|
|
127
|
-
_id: string;
|
|
128
|
-
}[] | undefined;
|
|
129
|
-
})[]>;
|
|
130
|
-
update(id: string, data: Record<string, EntityFieldValue>): Promise<{
|
|
131
|
-
id: string;
|
|
132
|
-
} & {} & {
|
|
133
|
-
[x: string]: Date | Record<string, unknown>[] | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | {
|
|
134
|
-
[key: string]: string | number | boolean | /*elided*/any | /*elided*/any | null;
|
|
135
|
-
} | null)[] | {
|
|
136
|
-
[key: string]: string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null;
|
|
137
|
-
} | null)[] | {
|
|
138
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
139
|
-
} | null)[] | {
|
|
140
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
141
|
-
} | null)[] | {
|
|
142
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
143
|
-
} | null)[] | {
|
|
144
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
145
|
-
} | null)[] | {
|
|
146
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
147
|
-
} | null)[] | {
|
|
148
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
149
|
-
} | null)[] | {
|
|
150
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
151
|
-
} | null)[] | {
|
|
152
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
153
|
-
} | null)[] | {
|
|
154
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
155
|
-
} | null)[] | {
|
|
156
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
157
|
-
} | null) | {
|
|
158
|
-
[key: string]: unknown;
|
|
159
|
-
_block: string;
|
|
160
|
-
_id: string;
|
|
161
|
-
}[] | undefined;
|
|
162
|
-
}>;
|
|
163
|
-
delete(id: string): Promise<void>;
|
|
19
|
+
}): Promise<InferEntityDTO$1<AllFields> | null>;
|
|
20
|
+
findMany(options?: FindManyOptions): Promise<InferEntityDTO$1<AllFields>[]>;
|
|
21
|
+
update(id: string, data: InferUpdateInput<AllFields>): Promise<InferEntityDTO$1<AllFields>>;
|
|
22
|
+
delete(id: string): Promise<unknown>;
|
|
164
23
|
saveTranslation(entityId: string, locale: string, translations: Record<string, unknown>): Promise<void>;
|
|
165
24
|
deleteTranslation(entityId: string, locale?: string): Promise<void>;
|
|
166
|
-
/**
|
|
167
|
-
* Copy layout from one locale to another (for localized: true blocks).
|
|
168
|
-
*
|
|
169
|
-
* NOTE: Layout tables are generated in `@murumets-ee/entity` (they need
|
|
170
|
-
* FK references to the parent entity table, which `defineTable` does not
|
|
171
|
-
* currently support). So this method uses direct Drizzle queries against
|
|
172
|
-
* the layout pgTable via `schemaRegistry` — it is the one remaining
|
|
173
|
-
* escape valve in ContentClient. If `defineTable` gains FK support in the
|
|
174
|
-
* future, migrate this to a TableClient pattern like drafts/versions.
|
|
175
|
-
*/
|
|
176
25
|
copyLayout(entityId: string, options: {
|
|
177
26
|
from: string;
|
|
178
27
|
to: string | string[];
|
|
179
28
|
}): Promise<void>;
|
|
180
|
-
/**
|
|
181
|
-
* List versions for an entity (newest first), filtered by locale.
|
|
182
|
-
* Uses '_' as the locale value for default-locale snapshots.
|
|
183
|
-
*/
|
|
184
29
|
getVersions(entityId: string, options?: {
|
|
185
30
|
limit?: number;
|
|
186
31
|
offset?: number;
|
|
187
32
|
locale?: string;
|
|
188
|
-
}): Promise<VersionEntry[]>;
|
|
189
|
-
|
|
190
|
-
* Get a specific version snapshot.
|
|
191
|
-
*/
|
|
192
|
-
getVersion(entityId: string, version: number, locale?: string): Promise<VersionEntry | null>;
|
|
193
|
-
/**
|
|
194
|
-
* Compare two versions and return field-level diff.
|
|
195
|
-
*
|
|
196
|
-
* Returns structured diffs with word-level segments for text fields
|
|
197
|
-
* and structural block diffs for blocks fields.
|
|
198
|
-
*/
|
|
33
|
+
}): Promise<VersionEntry<InferEntityDTO$1<AllFields>>[]>;
|
|
34
|
+
getVersion(entityId: string, version: number, locale?: string): Promise<VersionEntry<InferEntityDTO$1<AllFields>> | null>;
|
|
199
35
|
compareVersions(entityId: string, v1: number, v2: number, locale?: string): Promise<{
|
|
200
36
|
diffs: FieldDiff[];
|
|
201
|
-
fromVersion: VersionEntry
|
|
202
|
-
toVersion: VersionEntry
|
|
203
|
-
} | null>;
|
|
204
|
-
/**
|
|
205
|
-
* Compare the current draft with the live entity (or a specific version).
|
|
206
|
-
* Returns field-level diffs between the current published data and the draft.
|
|
207
|
-
*/
|
|
208
|
-
compareDraftWithCurrent(entityId: string, locale?: string): Promise<{
|
|
209
|
-
diffs: FieldDiff[];
|
|
210
|
-
current: Record<string, unknown>;
|
|
211
|
-
draft: DraftEntry;
|
|
37
|
+
fromVersion: VersionEntry<InferEntityDTO$1<AllFields>>;
|
|
38
|
+
toVersion: VersionEntry<InferEntityDTO$1<AllFields>>;
|
|
212
39
|
} | null>;
|
|
213
|
-
|
|
214
|
-
* Restore an entity to a previous version.
|
|
215
|
-
*/
|
|
216
|
-
restoreVersion(entityId: string, version: number): Promise<{
|
|
217
|
-
id: string;
|
|
218
|
-
} & {} & {
|
|
219
|
-
[x: string]: Date | Record<string, unknown>[] | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | {
|
|
220
|
-
[key: string]: string | number | boolean | /*elided*/any | /*elided*/any | null;
|
|
221
|
-
} | null)[] | {
|
|
222
|
-
[key: string]: string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null;
|
|
223
|
-
} | null)[] | {
|
|
224
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
225
|
-
} | null)[] | {
|
|
226
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
227
|
-
} | null)[] | {
|
|
228
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
229
|
-
} | null)[] | {
|
|
230
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
231
|
-
} | null)[] | {
|
|
232
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
233
|
-
} | null)[] | {
|
|
234
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
235
|
-
} | null)[] | {
|
|
236
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
237
|
-
} | null)[] | {
|
|
238
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
239
|
-
} | null)[] | {
|
|
240
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
241
|
-
} | null)[] | {
|
|
242
|
-
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/any | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null)[] | /*elided*/any | null;
|
|
243
|
-
} | null) | {
|
|
244
|
-
[key: string]: unknown;
|
|
245
|
-
_block: string;
|
|
246
|
-
_id: string;
|
|
247
|
-
}[] | undefined;
|
|
248
|
-
}>;
|
|
249
|
-
/**
|
|
250
|
-
* Enforce maxPerDoc retention by deleting oldest versions for a locale.
|
|
251
|
-
*/
|
|
40
|
+
restoreVersion(entityId: string, version: number): Promise<InferEntityDTO$1<AllFields>>;
|
|
252
41
|
pruneVersions(entityId: string, locale?: string): Promise<void>;
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
42
|
+
createVersionSnapshot(entityId: string, currentData: Record<string, unknown>, previousData?: Record<string, unknown> | null, locale?: string, user?: {
|
|
43
|
+
id: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
}): Promise<void>;
|
|
256
46
|
getTranslationStatus(entityId: string): Promise<TranslationStatus>;
|
|
257
|
-
/**
|
|
258
|
-
* Get translation status for multiple entities in a single query.
|
|
259
|
-
* Returns a map of entityId → TranslationStatus (O(1) DB roundtrips).
|
|
260
|
-
*/
|
|
261
47
|
getTranslationStatusBatch(entityIds: string[]): Promise<Map<string, TranslationStatus>>;
|
|
262
|
-
/**
|
|
263
|
-
* Get translation report across all entities of this type.
|
|
264
|
-
*/
|
|
265
48
|
getTranslationReport(options?: {
|
|
266
49
|
locale?: string;
|
|
267
50
|
}): Promise<TranslationReport>;
|
|
268
|
-
/**
|
|
269
|
-
* Get per-locale publish status for an entity.
|
|
270
|
-
* Returns status for all non-default locales that have explicit overrides.
|
|
271
|
-
* Missing locale = inherits base entity status.
|
|
272
|
-
*/
|
|
273
51
|
getLocaleStatus(entityId: string): Promise<LocalePublishStatus[]>;
|
|
274
|
-
/**
|
|
275
|
-
* Set per-locale publish status. Upserts into locale_status table.
|
|
276
|
-
* When locale === defaultLocale, updates the base entity status instead.
|
|
277
|
-
*/
|
|
278
52
|
setLocaleStatus(entityId: string, locale: string, status: 'draft' | 'published'): Promise<void>;
|
|
279
|
-
/**
|
|
280
|
-
* Get per-locale publish status for multiple entities in a single query.
|
|
281
|
-
* Returns a map of entityId → locale → LocalePublishStatus.
|
|
282
|
-
*/
|
|
283
53
|
getLocaleStatusBatch(entityIds: string[]): Promise<Map<string, Record<string, LocalePublishStatus>>>;
|
|
284
|
-
|
|
285
|
-
* Save (upsert) a draft for an entity+locale.
|
|
286
|
-
* One draft per entity+locale — overwrites any existing draft.
|
|
287
|
-
*/
|
|
288
|
-
saveDraft(entityId: string, data: Record<string, unknown>, locale?: string, user?: {
|
|
54
|
+
saveDraft(entityId: string, data: InferUpdateInput<AllFields>, locale?: string, user?: {
|
|
289
55
|
id: string;
|
|
290
56
|
name?: string;
|
|
291
|
-
}): Promise<DraftEntry
|
|
292
|
-
|
|
293
|
-
* Get the draft for an entity+locale, or null if none exists.
|
|
294
|
-
*/
|
|
295
|
-
getDraft(entityId: string, locale?: string): Promise<DraftEntry | null>;
|
|
296
|
-
/**
|
|
297
|
-
* Delete (discard) a draft for an entity+locale.
|
|
298
|
-
*/
|
|
57
|
+
}): Promise<DraftEntry<InferUpdateInput<AllFields>>>;
|
|
58
|
+
getDraft(entityId: string, locale?: string): Promise<DraftEntry<InferUpdateInput<AllFields>> | null>;
|
|
299
59
|
deleteDraft(entityId: string, locale?: string): Promise<boolean>;
|
|
300
|
-
/**
|
|
301
|
-
* Publish a draft: apply draft data to the live entity, then delete the draft.
|
|
302
|
-
* Runs in a transaction to ensure atomicity.
|
|
303
|
-
*/
|
|
304
60
|
publishDraft(entityId: string, locale?: string, user?: {
|
|
305
61
|
id: string;
|
|
306
62
|
name?: string;
|
|
307
|
-
}): Promise<
|
|
308
|
-
/**
|
|
309
|
-
* Quick existence check for list badges — does a draft exist?
|
|
310
|
-
*/
|
|
63
|
+
}): Promise<InferEntityDTO$1<AllFields>>;
|
|
311
64
|
hasDraft(entityId: string, locale?: string): Promise<boolean>;
|
|
312
|
-
/**
|
|
313
|
-
* Count drafts for this entity type, optionally filtered by locale.
|
|
314
|
-
* Single indexed COUNT query — used by dashboard widgets.
|
|
315
|
-
*/
|
|
316
65
|
countDrafts(locale?: string): Promise<number>;
|
|
317
|
-
/**
|
|
318
|
-
* Check draft existence for multiple entities in one query.
|
|
319
|
-
* Returns a set of entity IDs that have drafts.
|
|
320
|
-
*/
|
|
321
66
|
hasDraftBatch(entityIds: string[], locale?: string): Promise<Set<string>>;
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
* @param locale - The locale being edited. Use undefined or '_' for the default locale.
|
|
328
|
-
* @param user - The user who made the change (id + name for display).
|
|
329
|
-
*/
|
|
330
|
-
createVersionSnapshot(entityId: string, currentData: Record<string, unknown>, previousData?: Record<string, unknown> | null, locale?: string, user?: {
|
|
331
|
-
id: string;
|
|
332
|
-
name?: string;
|
|
333
|
-
}): Promise<void>;
|
|
334
|
-
/**
|
|
335
|
-
* Write the `_version` column on the entity row.
|
|
336
|
-
*
|
|
337
|
-
* KNOWN EXCEPTION: this bypasses AdminClient and goes straight to the
|
|
338
|
-
* entity pgTable via `schemaRegistry` + direct Drizzle. Using
|
|
339
|
-
* `admin.update()` would retrigger the `versionable.beforeUpdate` hook
|
|
340
|
-
* and loop indefinitely. This is the only ContentClient path that still
|
|
341
|
-
* writes to an entity table directly.
|
|
342
|
-
*/
|
|
343
|
-
private writeVersionColumn;
|
|
344
|
-
private saveVersionSnapshot;
|
|
345
|
-
private toDraftEntry;
|
|
346
|
-
private calculateDelta;
|
|
67
|
+
compareDraftWithCurrent(entityId: string, locale?: string): Promise<{
|
|
68
|
+
diffs: FieldDiff[];
|
|
69
|
+
current: InferEntityDTO$1<AllFields>;
|
|
70
|
+
draft: DraftEntry<InferUpdateInput<AllFields>>;
|
|
71
|
+
} | null>;
|
|
347
72
|
}
|
|
348
73
|
/**
|
|
349
|
-
* Factory — creates a ContentClient for an entity.
|
|
350
|
-
*
|
|
74
|
+
* Factory — creates a ContentClient for an entity. Must be called
|
|
75
|
+
* after `createApp()`. Generic flows from the entity definition:
|
|
76
|
+
* `createContentClient(Article)` returns a `ContentClient<typeof
|
|
77
|
+
* Article['allFields']>` typed end-to-end.
|
|
351
78
|
*/
|
|
352
|
-
declare function createContentClient(entity: Entity):
|
|
79
|
+
declare function createContentClient<AllFields extends Record<string, FieldConfig>>(entity: Entity<AllFields>): ContentClient<AllFields>;
|
|
353
80
|
//#endregion
|
|
354
81
|
export { ContentClient, ContentClientConfig, createContentClient };
|
|
355
82
|
//# sourceMappingURL=client.d.mts.map
|
package/dist/client.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;;;UAgEiB,mBAAA,mBACG,MAAA,SAAe,WAAA,IAAe,MAAA,SAAe,WAAA;EAE/D,KAAA,EAAO,WAAA,CAAY,SAAA;EACnB,MAAA,EAAQ,MAAA,CAAO,SAAA;EACf,MAAA,GAAS,MAAA;AAAA;AAAA,cAGE,aAAA,mBACO,MAAA,SAAe,WAAA,IAAe,MAAA,SAAe,WAAA;EAAA,QAEvD,GAAA;cAEI,MAAA,EAAQ,mBAAA,CAAoB,SAAA;EASlC,MAAA,CAAO,IAAA,EAAM,gBAAA,CAAiB,SAAA,IAAa,OAAA,CAAQ,gBAAA,CAAe,SAAA;EAQxE,QAAA,CAAS,EAAA,UAAY,OAAA;IAAY,MAAA;EAAA,IAAoB,OAAA,CAAQ,gBAAA,CAAe,SAAA;EAI5E,QAAA,CAAS,OAAA,GAAU,eAAA,GAAkB,OAAA,CAAQ,gBAAA,CAAe,SAAA;EAItD,MAAA,CAAO,EAAA,UAAY,IAAA,EAAM,gBAAA,CAAiB,SAAA,IAAa,OAAA,CAAQ,gBAAA,CAAe,SAAA;EAsBpF,MAAA,CAAO,EAAA,WAAa,OAAA;EAQpB,eAAA,CAAgB,QAAA,UAAkB,MAAA,UAAgB,YAAA,EAAc,MAAA,oBAAuB,OAAA;EAIvF,iBAAA,CAAkB,QAAA,UAAkB,MAAA,YAAe,OAAA;EAQnD,UAAA,CAAW,QAAA,UAAkB,OAAA;IAAW,IAAA;IAAc,EAAA;EAAA,IAAuB,OAAA;EAQ7E,WAAA,CAAY,QAAA,UAAkB,OAAA;IAAY,KAAA;IAAgB,MAAA;IAAiB,MAAA;EAAA,IAAiB,OAAA,CAAA,YAAA,CAAA,gBAAA,CAAA,SAAA;EAI5F,UAAA,CAAW,QAAA,UAAkB,OAAA,UAAiB,MAAA,YAAe,OAAA,CAAA,YAAA,CAAA,gBAAA,CAAA,SAAA;EAI7D,eAAA,CAAgB,QAAA,UAAkB,EAAA,UAAY,EAAA,UAAY,MAAA,YAAe,OAAA;WAJZ,SAAA;;;;EAQ7D,cAAA,CAAe,QAAA,UAAkB,OAAA,WAAe,OAAA,CAAA,gBAAA,CAAA,SAAA;EAIhD,aAAA,CAAc,QAAA,UAAkB,MAAA,YAAe,OAAA;EAI/C,qBAAA,CACE,QAAA,UACA,WAAA,EAAa,MAAA,mBACb,YAAA,GAAe,MAAA,0BACf,MAAA,WACA,IAAA;IAAS,EAAA;IAAY,IAAA;EAAA,IAAe,OAAA;EAStC,oBAAA,CAAqB,QAAA,WAAgB,OAAA,CATC,iBAAA;EAatC,yBAAA,CAA0B,SAAA,aAAmB,OAAA,CAAA,GAAA,SAJR,iBAAA;EAQrC,oBAAA,CAAqB,OAAA;IAAY,MAAA;EAAA,IAAiB,OAAA,CAJL,iBAAA;EAY7C,eAAA,CAAgB,QAAA,WAAgB,OAAA,CARkB,mBAAA;EAYlD,eAAA,CAAgB,QAAA,UAAkB,MAAA,UAAgB,MAAA,0BAA6B,OAAA;EAI/E,oBAAA,CAAqB,SAAA,aAAmB,OAAA,CAAA,GAAA,SAAA,MAAA,SAJuC,mBAAA;EAY/E,SAAA,CACE,QAAA,UACA,IAAA,EAAM,gBAAA,CAAiB,SAAA,GACvB,MAAA,WACA,IAAA;IAAS,EAAA;IAAY,IAAA;EAAA,IAAe,OAAA,CAAA,UAAA,CAAA,gBAAA,CAAA,SAAA;EAKtC,QAAA,CAAS,QAAA,UAAkB,MAAA,YAAe,OAAA,CAAA,UAAA,CAAA,gBAAA,CAAA,SAAA;EAI1C,WAAA,CAAY,QAAA,UAAkB,MAAA,YAAe,OAAA;EAI7C,YAAA,CAAa,QAAA,UAAkB,MAAA,WAAiB,IAAA;IAAS,EAAA;IAAY,IAAA;EAAA,IAAe,OAAA,CAAA,gBAAA,CAAA,SAAA;EAIpF,QAAA,CAAS,QAAA,UAAkB,MAAA,YAAe,OAAA;EAI1C,WAAA,CAAY,MAAA,YAAe,OAAA;EAI3B,aAAA,CAAc,SAAA,YAAqB,MAAA,YAAe,OAAA,CAAA,GAAA;EAIlD,uBAAA,CAAwB,QAAA,UAAkB,MAAA,YAAe,OAAA;WAJP,SAAA;;;;;;;;;;;iBAepC,mBAAA,mBAAsC,MAAA,SAAe,WAAA,EAAA,CACnE,MAAA,EAAQ,MAAA,CAAO,SAAA,IACd,aAAA,CAAc,SAAA"}
|
package/dist/client.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{o as e,r as t,t as n}from"./block-diff-BBH6FoFT.mjs";import{t as r}from"./registry-BJSOGFEN.mjs";import"server-only";var i=class{entity;admin;logger;versionableOptions;constructor(t){this.entity=t.entity,this.admin=t.admin,this.logger=t.logger,this.versionableOptions=e(t.entity.behaviors)}get db(){return this.admin.getDb()}getDraftsClient(){let{drafts:e}=r(this.entity.name);return e?e.makeClient(this.db):null}getVersionsClient(){let{versions:e}=r(this.entity.name);return e?e.makeClient(this.db):null}getLocaleStatusClient(){let{localeStatus:e}=r(this.entity.name);return e?e.makeClient(this.db):null}async create(e){let t=await this.admin.create(e);return this.versionableOptions&&await this.saveVersionSnapshot(t.id,t,null,!1),t}async findById(e,t){return this.admin.findById(e,t)}async findMany(e){return this.admin.findMany(e)}async update(e,t){let n=this.admin,r=null;this.versionableOptions&&(r=await n.findById(e));let i=await n.update(e,t);if(this.versionableOptions&&r){let t=this.calculateDelta(r,i),n=await this.saveVersionSnapshot(e,i,t,!1);n!==void 0&&(await this.writeVersionColumn(e,n),i._version=n),await this.pruneVersions(e)}return i}async delete(e){return this.admin.delete(e)}async saveTranslation(e,t,n){return this.admin.saveTranslation(e,t,n)}async deleteTranslation(e,t){return this.admin.deleteTranslation(e,t)}async copyLayout(e,t){let{schemaRegistry:n}=await import(`@murumets-ee/db`),{eq:r,and:i}=await import(`drizzle-orm`),a=n.get(`${this.entity.name}_layout`);if(!a)return;let o=Array.isArray(t.to)?t.to:[t.to],s=await this.db.select().from(a).where(i(r(a.entityId,e),r(a.locale,t.from))).orderBy(a.sortOrder);if(s.length!==0){for(let t of o){await this.db.delete(a).where(i(r(a.entityId,e),r(a.locale,t)));for(let e of s)await this.db.insert(a).values({entityId:e.entityId,fieldName:e.fieldName,blockType:e.blockType,sortOrder:e.sortOrder,data:e.data,locale:t})}this.logger?.debug({entityId:e,from:t.from,to:o},`Layout copied between locales`)}}async getVersions(e,t){let n=this.getVersionsClient();return n?await n.findMany({where:{entityId:e,locale:t?.locale??`_`},orderBy:[{column:`version`,dir:`desc`}],...t?.limit===void 0?{}:{limit:t.limit},...t?.offset===void 0?{}:{offset:t.offset}}):[]}async getVersion(e,t,n=`_`){let r=this.getVersionsClient();return r?await r.findOne({entityId:e,version:t,locale:n})??null:null}async compareVersions(e,r,i,a=`_`){let[o,s]=await Promise.all([this.getVersion(e,r,a),this.getVersion(e,i,a)]);if(!o||!s)return null;let c=o.data,l=s.data,u=this.entity.allFields,d=t(c,l,u);for(let e of d)e.type===`blocks`&&Array.isArray(e.from)&&Array.isArray(e.to)&&(e.blockDiffs=n(e.from,e.to));return{diffs:d,fromVersion:o,toVersion:s}}async compareDraftWithCurrent(e,r=`_`){let i=await this.getDraft(e,r);if(!i)return null;let a=this.admin,{getContentConfig:o}=await import(`./plugin.mjs`),s=o().defaultLocale,c=r===`_`?{defaultLocale:s}:{locale:r,defaultLocale:s},l=await a.findById(e,c);if(!l)return null;let u=this.entity.allFields,d={};for(let e of Object.keys(i.data))d[e]=l[e];let f=t(d,i.data,u);for(let e of f)e.type===`blocks`&&Array.isArray(e.from)&&Array.isArray(e.to)&&(e.blockDiffs=n(e.from,e.to));return{diffs:f,current:l,draft:i}}async restoreVersion(e,t){let n=await this.getVersion(e,t);if(!n)throw Error(`Version ${t} not found for entity ${e}`);let{id:r,createdAt:i,createdBy:a,_version:o,_versionedAt:s,...c}=n.data;return this.admin.update(e,c)}async pruneVersions(e,t=`_`){if(!this.versionableOptions)return;let n=this.getVersionsClient();if(!n)return;let r=this.versionableOptions.maxPerDoc,i=await n.findMany({where:{entityId:e,locale:t},orderBy:[{column:`version`,dir:`desc`}],limit:r});if(i.length<r)return;let a=i.map(e=>e.id);await n.deleteMany({entityId:e,locale:t,id:{notIn:a}})}async getTranslationStatus(e){let{getContentConfig:t}=await import(`./plugin.mjs`),n=t(),r=Object.entries(this.entity.allFields).filter(([e,t])=>t.translatable).map(([e])=>e);if(r.length===0)return{};let{schemaRegistry:i}=await import(`@murumets-ee/db`),{eq:a}=await import(`drizzle-orm`),o=i.get(`${this.entity.name}_translations`);if(!o)return{};let s=await this.db.select().from(o).where(a(o.entityId,e)),c=new Map;for(let e of s){let t=e,n={};for(let e of r)n[e]=t[e];c.set(t.locale,n)}let l={};for(let e of n.locales){if(e.code===n.defaultLocale)continue;let t=c.get(e.code)??{},i=[];for(let e of r)(t[e]===void 0||t[e]===null)&&i.push(e);let a=r.length-i.length;l[e.code]={complete:i.length===0,total:r.length,translated:a,missing:i}}return l}async getTranslationStatusBatch(e){let t=new Map;if(e.length===0)return t;let{getContentConfig:n}=await import(`./plugin.mjs`),r=n(),i=Object.entries(this.entity.allFields).filter(([e,t])=>t.translatable).map(([e])=>e);if(i.length===0)return t;let{schemaRegistry:a}=await import(`@murumets-ee/db`),{inArray:o}=await import(`drizzle-orm`),s=a.get(`${this.entity.name}_translations`);if(!s)return t;let c=await this.db.select().from(s).where(o(s.entityId,e)),l=new Map;for(let e of c){let t=e,n=t.entityId,r=t.locale,a={};for(let e of i)a[e]=t[e];l.has(n)||l.set(n,new Map),l.get(n).set(r,a)}for(let n of e){let e=l.get(n),a={};for(let t of r.locales){if(t.code===r.defaultLocale)continue;let n=e?.get(t.code)??{},o=[];for(let e of i)(n[e]===void 0||n[e]===null)&&o.push(e);let s=i.length-o.length;a[t.code]={complete:o.length===0,total:i.length,translated:s,missing:o}}t.set(n,a)}return t}async getTranslationReport(e){let{getContentConfig:t}=await import(`./plugin.mjs`),n=t(),r=e?.locale??n.locales.find(e=>e.code!==n.defaultLocale)?.code;if(!r)return{total:0,complete:0,partial:0,missing:0};let i=await this.admin.findMany(),a=0,o=0,s=0;for(let e of i){let t=(await this.getTranslationStatus(e.id))[r];!t||t.translated===0?s++:t.complete?a++:o++}return{total:i.length,complete:a,partial:o,missing:s}}async getLocaleStatus(e){let t=this.getLocaleStatusClient();return t?(await t.findMany({where:{entityId:e}})).map(e=>({locale:e.locale,status:e.status,publishedAt:e.publishedAt??null})):[]}async setLocaleStatus(e,t,n){let{getContentConfig:r}=await import(`./plugin.mjs`);if(t===r().defaultLocale){let t=this.admin,r={status:n};n===`published`&&(r.publishedAt=new Date),await t.update(e,r);return}let i=this.getLocaleStatusClient();if(!i)return;let a=n===`published`?new Date:null;await i.upsert({entityId:e,locale:t,status:n,publishedAt:a},{target:[`entityId`,`locale`],set:{status:n,publishedAt:a}})}async getLocaleStatusBatch(e){let t=new Map;if(e.length===0)return t;let n=this.getLocaleStatusClient();if(!n)return t;let r=await n.findMany({where:{entityId:{in:e}}});for(let e of r){let n=e.entityId,r=e.locale;t.has(n)||t.set(n,{}),t.get(n)[r]={locale:r,status:e.status,publishedAt:e.publishedAt??null}}return t}async saveDraft(e,t,n=`_`,r){let i=this.getDraftsClient();if(!i)throw Error(`Drafts table not found for entity "${this.entity.name}". Is the content plugin initialized?`);let a=new Date,o=r?.id??``,s=r?.name??null,c=await i.upsert({entityId:e,locale:n,data:t,createdBy:o,createdByName:s,createdAt:a,updatedAt:a},{target:[`entityId`,`locale`],set:{data:t,updatedAt:a}});return this.toDraftEntry(c)}async getDraft(e,t=`_`){let n=this.getDraftsClient();if(!n)return null;let r=await n.findOne({entityId:e,locale:t});return r?this.toDraftEntry(r):null}async deleteDraft(e,t=`_`){let n=this.getDraftsClient();return n?(await n.deleteMany({entityId:e,locale:t})).length>0:!1}async publishDraft(e,t=`_`,n){let r=await this.getDraft(e,t);if(!r)throw Error(`No draft found for entity ${e} locale ${t}`);let i=this.admin,a=null;this.versionableOptions&&(a=await i.findById(e));let{id:o,createdAt:s,createdBy:c,_version:l,_versionedAt:u,...d}=r.data,f=await i.update(e,d);return await this.deleteDraft(e,t),this.versionableOptions&&await this.createVersionSnapshot(e,f,a,t,n),f}async hasDraft(e,t=`_`){let n=this.getDraftsClient();return n?n.exists({entityId:e,locale:t}):!1}async countDrafts(e=`_`){let t=this.getDraftsClient();return t?t.count({locale:e}):0}async hasDraftBatch(e,t=`_`){let n=new Set;if(e.length===0)return n;let r=this.getDraftsClient();if(!r)return n;let i=await r.findMany({where:{entityId:{in:e},locale:t}});for(let e of i)n.add(e.entityId);return n}async createVersionSnapshot(e,t,n,r,i){if(!this.versionableOptions)return;let a=r??`_`,o=n?this.calculateDelta(n,t):null,s=await this.saveVersionSnapshot(e,t,o,!1,a,i);s!==void 0&&a===`_`&&await this.writeVersionColumn(e,s),await this.pruneVersions(e,a)}async writeVersionColumn(e,t){let{schemaRegistry:n}=await import(`@murumets-ee/db`),{eq:r}=await import(`drizzle-orm`),i=n.get(this.entity.name);i&&await this.db.update(i).set({_version:t}).where(r(i.id,e))}async saveVersionSnapshot(e,t,n,r,i=`_`,a){let o=this.getVersionsClient();if(!o)return;let[s]=await o.aggregate({select:{maxVersion:{fn:`max`,column:`version`}},where:{entityId:e,locale:i}}),c=Number(s?.maxVersion??0)+1,l=t.status??null;if(r){let r=await o.findOne({entityId:e,isAutosave:!0,version:c,locale:i});if(r)return await o.update({id:r.id},{data:t,delta:n,status:l,createdAt:new Date}),c}return await o.insert({entityId:e,version:c,locale:i,data:t,delta:n,status:l,createdBy:a?.id??t.updatedBy??t.createdBy??null,createdByName:a?.name??null,isAutosave:r}),c}toDraftEntry(e){return{id:e.id,entityId:e.entityId,locale:e.locale,data:e.data,createdBy:e.createdBy,createdByName:e.createdByName??null,createdAt:e.createdAt,updatedAt:e.updatedAt}}calculateDelta(e,t){let n={};for(let r of Object.keys(t))r===`id`||r.startsWith(`_`)||JSON.stringify(e[r])!==JSON.stringify(t[r])&&(n[r]=t[r]);return n}};async function a(e){let{createAdminClient:t}=await import(`@murumets-ee/core/clients`),{getApp:n}=await import(`@murumets-ee/core`);return new i({admin:t(e),entity:e,logger:n().logger.child({content:e.name})})}export{i as ContentClient,a as createContentClient};
|
|
1
|
+
import{t as e}from"./versionable-B0bP2Gib.mjs";import{t}from"./errors-kkf8Ue1H.mjs";import{n,r}from"./plugin-yijaaFS7.mjs";import{t as i}from"./locale-utils-By7EdAT1.mjs";import"server-only";import{getApp as a}from"@murumets-ee/core";import{createAdminClient as o}from"@murumets-ee/core/clients";import{schemaRegistry as s}from"@murumets-ee/db";import{and as c,eq as l,inArray as u}from"drizzle-orm";function d(e){return e.match(/\S+|\s+/g)??[]}function f(e,t){if(e===t)return e?[{type:`equal`,value:e}]:[];if(!e)return[{type:`add`,value:t}];if(!t)return[{type:`remove`,value:e}];let n=d(e),r=d(t),i=n.length,a=r.length,o=Array.from({length:i+1},()=>Array(a+1).fill(0));for(let e=1;e<=i;e++)for(let t=1;t<=a;t++)n[e-1]===r[t-1]?o[e][t]=o[e-1][t-1]+1:o[e][t]=Math.max(o[e-1][t],o[e][t-1]);let s=[],c=i,l=a,u=[];for(;c>0||l>0;)c>0&&l>0&&n[c-1]===r[l-1]?(u.push({type:`equal`,value:n[c-1]}),c--,l--):l>0&&(c===0||o[c][l-1]>=o[c-1][l])?(u.push({type:`add`,value:r[l-1]}),l--):(u.push({type:`remove`,value:n[c-1]}),c--);u.reverse();for(let e of u){let t=s[s.length-1];t&&t.type===e.type?t.value+=e.value:s.push({...e})}return s}function p(e){return e.replace(/<[^>]*>/g,` `).replace(/\s+/g,` `).trim()}function m(e){return e==null?``:e instanceof Date?e.toISOString():typeof e==`object`?JSON.stringify(e):String(e)}function ee(e,t,n,r){if(JSON.stringify(t)===JSON.stringify(n))return null;switch(r?.type??g(t,n)){case`text`:case`slug`:return{field:e,type:`text`,from:t,to:n,segments:f(m(t),m(n))};case`richtext`:return{field:e,type:`richtext`,from:t,to:n,segments:f(p(m(t)),p(m(n)))};case`number`:return{field:e,type:`number`,from:t,to:n};case`boolean`:return{field:e,type:`boolean`,from:t,to:n};case`date`:return{field:e,type:`date`,from:t,to:n};case`select`:return{field:e,type:`select`,from:t,to:n};case`media`:return{field:e,type:`media`,from:t,to:n};case`json`:return{field:e,type:`json`,from:t,to:n};case`blocks`:return{field:e,type:`blocks`,from:t,to:n};default:return{field:e,type:`unknown`,from:t,to:n}}}function h(e,t,n){let r=new Set([...Object.keys(e),...Object.keys(t)]),i=[];for(let a of r){if(a===`id`||a===`createdAt`||a===`updatedAt`)continue;let r=ee(a,e[a],t[a],n?.[a]);r&&i.push(r)}return i}function g(e,t){let n=e??t;return typeof n==`number`?`number`:typeof n==`boolean`?`boolean`:n instanceof Date?`date`:typeof n==`string`?/^\d{4}-\d{2}-\d{2}/.test(n)?`date`:`text`:Array.isArray(n)?n.length>0&&typeof n[0]==`object`&&n[0]!==null&&`_block`in n[0]?`blocks`:`json`:typeof n==`object`?`json`:`unknown`}function _(e,t){if(typeof e==`string`||typeof t==`string`)return f(m(e),m(t))}function v(e){return typeof e==`object`&&!!e&&`_block`in e&&`_id`in e&&typeof e._block==`string`&&typeof e._id==`string`}function y(e,t){let n=new Set([...Object.keys(e),...Object.keys(t)]),r=[];for(let i of n){if(i===`_block`||i===`_id`)continue;let n=e[i],a=t[i];JSON.stringify(n)!==JSON.stringify(a)&&r.push({field:i,from:n,to:a,segments:_(n,a)})}return r}function b(e,t){let n=e.filter(v),r=t.filter(v),i=new Map,a=new Map;for(let e=0;e<n.length;e++)i.set(n[e]._id,{block:n[e],index:e});for(let e=0;e<r.length;e++)a.set(r[e]._id,{block:r[e],index:e});let o=[],s=new Set;for(let[e,{block:t,index:n}]of a){s.add(e);let r=i.get(e);if(!r){o.push({blockId:e,blockType:t._block,status:`added`,toIndex:n});continue}let a=r.block,c=r.index,l=y(a,t),u=c!==n;l.length===0&&!u?o.push({blockId:e,blockType:t._block,status:`unchanged`,fromIndex:c,toIndex:n}):l.length>0?o.push({blockId:e,blockType:t._block,status:`changed`,fromIndex:c,toIndex:n,propDiffs:l}):o.push({blockId:e,blockType:t._block,status:`moved`,fromIndex:c,toIndex:n})}for(let[e,{block:t,index:n}]of i)s.has(e)||o.push({blockId:e,blockType:t._block,status:`removed`,fromIndex:n});return o}function x(e,t){return{entity:e.entity,admin:e.admin,db:e.admin.getDb(),versionableOptions:t,logger:e.logger}}function S(e){let{drafts:t}=r(e.entity.name);return t?t.makeClient(e.db):null}function C(e){let{versions:t}=r(e.entity.name);return t?t.makeClient(e.db):null}function w(e){let{localeStatus:t}=r(e.entity.name);return t?t.makeClient(e.db):null}const T=new Set([`id`,`createdAt`,`createdBy`,`updatedAt`,`updatedBy`]);function E(e,t){let n=e.allFields,r={};for(let e of Object.keys(t)){if(T.has(e)||e.startsWith(`_`)||!Object.hasOwn(n,e))continue;let i=n[e];i&&i.internal===!0||(r[e]=t[e])}return r}function D(e,t){return JSON.stringify(e)===JSON.stringify(t)}function O(e,t){let n={};for(let r of Object.keys(t))r===`id`||r.startsWith(`_`)||D(e[r],t[r])||(n[r]=t[r]);return n}async function k(e,t,n){n?.locale!==void 0&&i(n.locale);let r=C(e);return r?await r.findMany({where:{entityId:t,locale:n?.locale??`_`},orderBy:[{column:`version`,dir:`desc`}],...n?.limit===void 0?{}:{limit:n.limit},...n?.offset===void 0?{}:{offset:n.offset}}):[]}async function A(e,t,n,r=`_`){i(r);let a=C(e);return a?await a.findOne({entityId:t,version:n,locale:r})??null:null}async function j(e,t,n,r,a=`_`){i(a);let[o,s]=await Promise.all([A(e,t,n,a),A(e,t,r,a)]);if(!o||!s)return null;let c=e.entity.allFields,l=h(o.data,s.data,c);for(let e of l)e.type===`blocks`&&Array.isArray(e.from)&&Array.isArray(e.to)&&(e.blockDiffs=b(e.from,e.to));return{diffs:l,fromVersion:o,toVersion:s}}async function M(e,n,r){if(!C(e))throw new t(e.entity.name,`versions`);let i=await A(e,n,r);if(!i)throw Error(`Version ${r} not found for entity ${n}`);let a=i.data,o=E(e.entity,a);return e.admin.update(n,o)}async function N(e,t,n=`_`){if(i(n),!e.versionableOptions)return;let r=C(e);if(!r)return;let a=e.versionableOptions.maxPerDoc,o=await r.findMany({where:{entityId:t,locale:n},orderBy:[{column:`version`,dir:`desc`}],limit:a});if(o.length<a)return;let s=o.map(e=>e.id);await r.deleteMany({entityId:t,locale:n,id:{notIn:s}})}async function P(e,t,n,r,a,o=`_`,s){i(o);let c=C(e);if(!c)return;let[l]=await c.aggregate({select:{maxVersion:{fn:`max`,column:`version`}},where:{entityId:t,locale:o}}),u=Number(l?.maxVersion??0)+1,d=n.status??null;if(a){let e=await c.findOne({entityId:t,isAutosave:!0,version:u,locale:o});if(e)return await c.update({id:e.id},{data:n,delta:r,status:d,createdAt:new Date}),u}return await c.insert({entityId:t,version:u,locale:o,data:n,delta:r,status:d,createdBy:s?.id??null,createdByName:s?.name??null,isAutosave:a}),u}async function F(e,t,n,r,a,o){if(a!==void 0&&i(a),!e.versionableOptions)return;let s=a??`_`,c=await P(e,t,n,r?O(r,n):null,!1,s,o);c!==void 0&&s===`_`&&await I(e,t,c),await N(e,t,s)}async function I(e,t,n){let r=s.get(e.entity.name);r&&await e.db.update(r).set({_version:n}).where(l(r.id,t))}function L(e){return{id:e.id,entityId:e.entityId,locale:e.locale,data:e.data,createdBy:e.createdBy,createdByName:e.createdByName??null,createdAt:e.createdAt,updatedAt:e.updatedAt}}async function R(e,n,r,a=`_`,o){i(a);let s=S(e);if(!s)throw new t(e.entity.name,`drafts`);let c=new Date,l=o?.id??``,u=o?.name??null;return L(await s.upsert({entityId:n,locale:a,data:r,createdBy:l,createdByName:u,createdAt:c,updatedAt:c},{target:[`entityId`,`locale`],set:{data:r,updatedAt:c}}))}async function z(e,t,n=`_`){i(n);let r=S(e);if(!r)return null;let a=await r.findOne({entityId:t,locale:n});return a?L(a):null}async function B(e,t,n=`_`){i(n);let r=S(e);return r?(await r.deleteMany({entityId:t,locale:n})).length>0:!1}async function V(e,n,r=`_`,a){if(i(r),!S(e))throw new t(e.entity.name,`drafts`);let o=await z(e,n,r);if(!o)throw Error(`No draft found for entity ${n} locale ${r}`);let s=null;e.versionableOptions&&(s=await e.admin.findById(n));let c=o.data,l=E(e.entity,c),u=await e.admin.update(n,l);return await B(e,n,r),e.versionableOptions&&await F(e,n,u,s,r,a),u}async function H(e,t,n=`_`){i(n);let r=S(e);return r?r.exists({entityId:t,locale:n}):!1}async function U(e,t=`_`){i(t);let n=S(e);return n?n.count({locale:t}):0}async function W(e,t,n=`_`){i(n);let r=new Set;if(t.length===0)return r;let a=S(e);if(!a)return r;let o=await a.findMany({where:{entityId:{in:t},locale:n}});for(let e of o)r.add(e.entityId);return r}async function G(e,t,r=`_`){i(r);let a=await z(e,t,r);if(!a)return null;let o=n().defaultLocale,s=r===`_`?{defaultLocale:o}:{locale:r,defaultLocale:o},c=await e.admin.findById(t,s);if(!c)return null;let l=e.entity.allFields,u=c,d=a.data,f={};for(let e of Object.keys(d))f[e]=u[e];let p=h(f,d,l);for(let e of p)e.type===`blocks`&&Array.isArray(e.from)&&Array.isArray(e.to)&&(e.blockDiffs=b(e.from,e.to));return{diffs:p,current:c,draft:a}}async function K(e,t,n){i(n.from);let r=Array.isArray(n.to)?n.to:[n.to];for(let e of r)i(e);let a=s.get(`${e.entity.name}_layout`);if(!a)return;let o=await e.db.select().from(a).where(c(l(a.entityId,t),l(a.locale,n.from))).orderBy(a.sortOrder);if(o.length!==0){for(let n of r){await e.db.delete(a).where(c(l(a.entityId,t),l(a.locale,n)));for(let t of o)await e.db.insert(a).values({entityId:t.entityId,fieldName:t.fieldName,blockType:t.blockType,sortOrder:t.sortOrder,data:t.data,locale:n})}e.logger?.debug({entityId:t,from:n.from,to:r},`Layout copied between locales`)}}async function q(e,t){let n=(await Y(e,[t])).get(t);return n?Object.values(n):[]}async function J(e,r,a,o){if(i(a),a===n().defaultLocale){let t={status:o};o===`published`&&(t.publishedAt=new Date),await e.admin.update(r,t);return}let s=w(e);if(!s)throw new t(e.entity.name,`localeStatus`);let c=o===`published`?new Date:null;await s.upsert({entityId:r,locale:a,status:o,publishedAt:c},{target:[`entityId`,`locale`],set:{status:o,publishedAt:c}})}async function Y(e,t){let n=new Map;if(t.length===0)return n;let r=w(e);if(!r)return n;let i=await r.findMany({where:{entityId:{in:t}}});for(let e of i){let t=e.entityId,r=e.locale,i=n.get(t);i||(i={},n.set(t,i)),i[r]={locale:r,status:e.status,publishedAt:e.publishedAt??null}}return n}function X(e,t,n,r){let i={};for(let a of n){if(a.code===r)continue;let n=t?.get(a.code)??{},o=[];for(let t of e)(n[t]===void 0||n[t]===null)&&o.push(t);i[a.code]={complete:o.length===0,total:e.length,translated:e.length-o.length,missing:o}}return i}async function Z(e,t){return(await Q(e,[t])).get(t)??{}}async function Q(e,t){let r=new Map;if(t.length===0)return r;let i=n(),a=Object.entries(e.entity.allFields).filter(([e,t])=>t.translatable).map(([e])=>e);if(a.length===0)return r;let o=s.get(`${e.entity.name}_translations`);if(!o)return r;let c=await e.db.select().from(o).where(u(o.entityId,t)),l=new Map;for(let e of c){let t=e,n=t.entityId,r=t.locale,i={};for(let e of a)i[e]=t[e];let o=l.get(n);o||(o=new Map,l.set(n,o)),o.set(r,i)}for(let e of t)r.set(e,X(a,l.get(e),i.locales,i.defaultLocale));return r}async function te(e,t){let r=n(),i=t?.locale??r.locales.find(e=>e.code!==r.defaultLocale)?.code;if(!i)return{total:0,complete:0,partial:0,missing:0};let a=await e.admin.findMany();if(a.length===0)return{total:0,complete:0,partial:0,missing:0};let o=await Q(e,a.map(e=>e.id)),s=0,c=0,l=0;for(let e of a){let t=o.get(e.id)?.[i];!t||t.translated===0?l++:t.complete?s++:c++}return{total:a.length,complete:s,partial:c,missing:l}}var $=class{ctx;constructor(t){this.ctx=x(t,e(t.entity.behaviors))}async create(e){let t=await this.ctx.admin.create(e);return this.ctx.versionableOptions&&await P(this.ctx,t.id,t,null,!1),t}findById(e,t){return this.ctx.admin.findById(e,t)}findMany(e){return this.ctx.admin.findMany(e)}async update(e,t){let n=null;this.ctx.versionableOptions&&(n=await this.ctx.admin.findById(e));let r=await this.ctx.admin.update(e,t);if(this.ctx.versionableOptions&&n){let t=O(n,r),i=await P(this.ctx,e,r,t,!1);if(i!==void 0)return await I(this.ctx,e,i),await N(this.ctx,e),{...r,_version:i};await N(this.ctx,e)}return r}delete(e){return this.ctx.admin.delete(e)}saveTranslation(e,t,n){return this.ctx.admin.saveTranslation(e,t,n)}deleteTranslation(e,t){return this.ctx.admin.deleteTranslation(e,t)}copyLayout(e,t){return K(this.ctx,e,t)}getVersions(e,t){return k(this.ctx,e,t)}getVersion(e,t,n){return A(this.ctx,e,t,n)}compareVersions(e,t,n,r){return j(this.ctx,e,t,n,r)}restoreVersion(e,t){return M(this.ctx,e,t)}pruneVersions(e,t){return N(this.ctx,e,t)}createVersionSnapshot(e,t,n,r,i){return F(this.ctx,e,t,n,r,i)}getTranslationStatus(e){return Z(this.ctx,e)}getTranslationStatusBatch(e){return Q(this.ctx,e)}getTranslationReport(e){return te(this.ctx,e)}getLocaleStatus(e){return q(this.ctx,e)}setLocaleStatus(e,t,n){return J(this.ctx,e,t,n)}getLocaleStatusBatch(e){return Y(this.ctx,e)}saveDraft(e,t,n,r){return R(this.ctx,e,t,n,r)}getDraft(e,t){return z(this.ctx,e,t)}deleteDraft(e,t){return B(this.ctx,e,t)}publishDraft(e,t,n){return V(this.ctx,e,t,n)}hasDraft(e,t){return H(this.ctx,e,t)}countDrafts(e){return U(this.ctx,e)}hasDraftBatch(e,t){return W(this.ctx,e,t)}compareDraftWithCurrent(e,t){return G(this.ctx,e,t)}};function ne(e){return new $({admin:o(e),entity:e,logger:a().logger.child({content:e.name})})}export{$ as ContentClient,ne as createContentClient};
|
|
2
2
|
//# sourceMappingURL=client.mjs.map
|