@murumets-ee/content 0.1.2 → 0.1.4

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.
@@ -0,0 +1,187 @@
1
+ import { B as BlockDefinition } from '../types-BYeiE1ie.js';
2
+ import * as _murumets_ee_entity from '@murumets-ee/entity';
3
+
4
+ declare const CodeBlock: BlockDefinition<{
5
+ readonly code: _murumets_ee_entity.TextField & {
6
+ readonly required: true;
7
+ };
8
+ readonly language: _murumets_ee_entity.SelectField & {
9
+ options: readonly ["javascript", "typescript", "python", "html", "css", "json", "bash", "sql", "other"];
10
+ } & Omit<Partial<_murumets_ee_entity.SelectField>, "options">;
11
+ }>;
12
+
13
+ declare const CTABlock: BlockDefinition<{
14
+ readonly heading: _murumets_ee_entity.TextField & {
15
+ readonly required: true;
16
+ readonly translatable: true;
17
+ };
18
+ readonly description: _murumets_ee_entity.TextField & {
19
+ readonly translatable: true;
20
+ };
21
+ readonly buttonText: _murumets_ee_entity.TextField & {
22
+ readonly required: true;
23
+ readonly translatable: true;
24
+ };
25
+ readonly buttonLink: _murumets_ee_entity.TextField & {
26
+ readonly required: true;
27
+ };
28
+ }>;
29
+
30
+ declare const GalleryBlock: BlockDefinition<{
31
+ readonly images: _murumets_ee_entity.ReferenceField & {
32
+ cardinality: "many";
33
+ } & Partial<Omit<_murumets_ee_entity.ReferenceField, "entity" | "cardinality">>;
34
+ readonly columns: _murumets_ee_entity.SelectField & {
35
+ options: readonly ["2", "3", "4"];
36
+ } & Omit<Partial<_murumets_ee_entity.SelectField>, "options">;
37
+ }>;
38
+
39
+ declare const HeroBlock: BlockDefinition<{
40
+ readonly heading: _murumets_ee_entity.TextField & {
41
+ readonly required: true;
42
+ readonly translatable: true;
43
+ };
44
+ readonly subheading: _murumets_ee_entity.TextField & {
45
+ readonly translatable: true;
46
+ };
47
+ readonly background: _murumets_ee_entity.MediaField & {
48
+ readonly accept: ["image/*"];
49
+ };
50
+ readonly alignment: _murumets_ee_entity.SelectField & {
51
+ options: readonly ["left", "center", "right"];
52
+ } & Omit<Partial<_murumets_ee_entity.SelectField>, "options">;
53
+ }>;
54
+
55
+ declare const ImageBlock: BlockDefinition<{
56
+ readonly image: _murumets_ee_entity.MediaField & {
57
+ readonly accept: ["image/*"];
58
+ readonly required: true;
59
+ };
60
+ readonly alt: _murumets_ee_entity.TextField & {
61
+ readonly translatable: true;
62
+ };
63
+ readonly caption: _murumets_ee_entity.TextField & {
64
+ readonly translatable: true;
65
+ };
66
+ }>;
67
+
68
+ declare const QuoteBlock: BlockDefinition<{
69
+ readonly quote: _murumets_ee_entity.TextField & {
70
+ readonly required: true;
71
+ readonly translatable: true;
72
+ };
73
+ readonly attribution: _murumets_ee_entity.TextField & {
74
+ readonly translatable: true;
75
+ };
76
+ }>;
77
+
78
+ declare const RichTextBlock: BlockDefinition<{
79
+ readonly content: _murumets_ee_entity.RichTextField & {
80
+ readonly translatable: true;
81
+ };
82
+ }>;
83
+
84
+ declare const VideoBlock: BlockDefinition<{
85
+ readonly url: _murumets_ee_entity.TextField & {
86
+ readonly required: true;
87
+ };
88
+ readonly poster: _murumets_ee_entity.MediaField & {
89
+ readonly accept: ["image/*"];
90
+ };
91
+ readonly caption: _murumets_ee_entity.TextField & {
92
+ readonly translatable: true;
93
+ };
94
+ }>;
95
+
96
+ /**
97
+ * All common blocks shipped with the toolkit.
98
+ * Use as-is or pick individual blocks from the named exports.
99
+ *
100
+ * @example
101
+ * import { commonBlocks } from '@murumets-ee/content/blocks'
102
+ * const Page = defineEntity({
103
+ * name: 'page',
104
+ * fields: {
105
+ * layout: field.blocks({ blocks: [...commonBlocks] }),
106
+ * },
107
+ * })
108
+ */
109
+ declare const commonBlocks: readonly [BlockDefinition<{
110
+ readonly content: _murumets_ee_entity.RichTextField & {
111
+ readonly translatable: true;
112
+ };
113
+ }>, BlockDefinition<{
114
+ readonly image: _murumets_ee_entity.MediaField & {
115
+ readonly accept: ["image/*"];
116
+ readonly required: true;
117
+ };
118
+ readonly alt: _murumets_ee_entity.TextField & {
119
+ readonly translatable: true;
120
+ };
121
+ readonly caption: _murumets_ee_entity.TextField & {
122
+ readonly translatable: true;
123
+ };
124
+ }>, BlockDefinition<{
125
+ readonly heading: _murumets_ee_entity.TextField & {
126
+ readonly required: true;
127
+ readonly translatable: true;
128
+ };
129
+ readonly subheading: _murumets_ee_entity.TextField & {
130
+ readonly translatable: true;
131
+ };
132
+ readonly background: _murumets_ee_entity.MediaField & {
133
+ readonly accept: ["image/*"];
134
+ };
135
+ readonly alignment: _murumets_ee_entity.SelectField & {
136
+ options: readonly ["left", "center", "right"];
137
+ } & Omit<Partial<_murumets_ee_entity.SelectField>, "options">;
138
+ }>, BlockDefinition<{
139
+ readonly images: _murumets_ee_entity.ReferenceField & {
140
+ cardinality: "many";
141
+ } & Partial<Omit<_murumets_ee_entity.ReferenceField, "entity" | "cardinality">>;
142
+ readonly columns: _murumets_ee_entity.SelectField & {
143
+ options: readonly ["2", "3", "4"];
144
+ } & Omit<Partial<_murumets_ee_entity.SelectField>, "options">;
145
+ }>, BlockDefinition<{
146
+ readonly heading: _murumets_ee_entity.TextField & {
147
+ readonly required: true;
148
+ readonly translatable: true;
149
+ };
150
+ readonly description: _murumets_ee_entity.TextField & {
151
+ readonly translatable: true;
152
+ };
153
+ readonly buttonText: _murumets_ee_entity.TextField & {
154
+ readonly required: true;
155
+ readonly translatable: true;
156
+ };
157
+ readonly buttonLink: _murumets_ee_entity.TextField & {
158
+ readonly required: true;
159
+ };
160
+ }>, BlockDefinition<{
161
+ readonly url: _murumets_ee_entity.TextField & {
162
+ readonly required: true;
163
+ };
164
+ readonly poster: _murumets_ee_entity.MediaField & {
165
+ readonly accept: ["image/*"];
166
+ };
167
+ readonly caption: _murumets_ee_entity.TextField & {
168
+ readonly translatable: true;
169
+ };
170
+ }>, BlockDefinition<{
171
+ readonly quote: _murumets_ee_entity.TextField & {
172
+ readonly required: true;
173
+ readonly translatable: true;
174
+ };
175
+ readonly attribution: _murumets_ee_entity.TextField & {
176
+ readonly translatable: true;
177
+ };
178
+ }>, BlockDefinition<{
179
+ readonly code: _murumets_ee_entity.TextField & {
180
+ readonly required: true;
181
+ };
182
+ readonly language: _murumets_ee_entity.SelectField & {
183
+ options: readonly ["javascript", "typescript", "python", "html", "css", "json", "bash", "sql", "other"];
184
+ } & Omit<Partial<_murumets_ee_entity.SelectField>, "options">;
185
+ }>];
186
+
187
+ export { CTABlock, CodeBlock, GalleryBlock, HeroBlock, ImageBlock, QuoteBlock, RichTextBlock, VideoBlock, commonBlocks };
@@ -0,0 +1,215 @@
1
+ import { Logger } from '@murumets-ee/core';
2
+ import { Entity, FieldToTS, FieldConfig } from '@murumets-ee/entity';
3
+ import { FindManyOptions } from '@murumets-ee/entity/admin';
4
+ import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
5
+ import { F as FieldDiff } from './types-Cr0ifLn_.js';
6
+ import { V as VersionEntry, D as DraftEntry, T as TranslationStatus, a as TranslationReport, L as LocalePublishStatus } from './types-BYeiE1ie.js';
7
+
8
+ /**
9
+ * ContentClient — wraps AdminClient with version history and translation status.
10
+ *
11
+ * Usage:
12
+ * import { createContentClient } from '@murumets-ee/content/client'
13
+ * const pages = createContentClient(Page)
14
+ * await pages.create({ title: 'Hello', layout: [...] })
15
+ */
16
+
17
+ /** Value type that any entity field can hold */
18
+ type EntityFieldValue = FieldToTS<FieldConfig> | null | undefined;
19
+ interface ContentClientConfig {
20
+ entity: Entity;
21
+ db: PostgresJsDatabase;
22
+ logger?: Logger;
23
+ }
24
+ declare class ContentClient {
25
+ private entity;
26
+ private db;
27
+ private logger?;
28
+ private admin;
29
+ private versionableOptions;
30
+ constructor(config: ContentClientConfig);
31
+ private getAdmin;
32
+ create(data: Record<string, EntityFieldValue>): Promise<{
33
+ id: string;
34
+ } & {} & {
35
+ [x: string]: string | number | boolean | Date | Record<string, unknown> | Record<string, unknown>[] | {
36
+ [key: string]: unknown;
37
+ _block: string;
38
+ _id: string;
39
+ }[] | null | undefined;
40
+ }>;
41
+ findById(id: string, options?: {
42
+ locale?: string;
43
+ }): Promise<({
44
+ id: string;
45
+ } & {} & {
46
+ [x: string]: string | number | boolean | Date | Record<string, unknown> | Record<string, unknown>[] | {
47
+ [key: string]: unknown;
48
+ _block: string;
49
+ _id: string;
50
+ }[] | null | undefined;
51
+ }) | null>;
52
+ findMany(options?: FindManyOptions): Promise<({
53
+ id: string;
54
+ } & {} & {
55
+ [x: string]: string | number | boolean | Date | Record<string, unknown> | Record<string, unknown>[] | {
56
+ [key: string]: unknown;
57
+ _block: string;
58
+ _id: string;
59
+ }[] | null | undefined;
60
+ })[]>;
61
+ update(id: string, data: Record<string, EntityFieldValue>): Promise<{
62
+ id: string;
63
+ } & {} & {
64
+ [x: string]: string | number | boolean | Date | Record<string, unknown> | Record<string, unknown>[] | {
65
+ [key: string]: unknown;
66
+ _block: string;
67
+ _id: string;
68
+ }[] | null | undefined;
69
+ }>;
70
+ delete(id: string): Promise<void>;
71
+ saveTranslation(entityId: string, locale: string, translations: Record<string, unknown>): Promise<void>;
72
+ deleteTranslation(entityId: string, locale?: string): Promise<void>;
73
+ /**
74
+ * Copy layout from one locale to another (for localized: true blocks).
75
+ */
76
+ copyLayout(entityId: string, options: {
77
+ from: string;
78
+ to: string | string[];
79
+ }): Promise<void>;
80
+ /**
81
+ * List versions for an entity (newest first), filtered by locale.
82
+ * Uses '_' as the locale value for default-locale snapshots.
83
+ */
84
+ getVersions(entityId: string, options?: {
85
+ limit?: number;
86
+ offset?: number;
87
+ locale?: string;
88
+ }): Promise<VersionEntry[]>;
89
+ /**
90
+ * Get a specific version snapshot.
91
+ */
92
+ getVersion(entityId: string, version: number, locale?: string): Promise<VersionEntry | null>;
93
+ /**
94
+ * Compare two versions and return field-level diff.
95
+ *
96
+ * Returns structured diffs with word-level segments for text fields
97
+ * and structural block diffs for blocks fields.
98
+ */
99
+ compareVersions(entityId: string, v1: number, v2: number, locale?: string): Promise<{
100
+ diffs: FieldDiff[];
101
+ fromVersion: VersionEntry;
102
+ toVersion: VersionEntry;
103
+ } | null>;
104
+ /**
105
+ * Compare the current draft with the live entity (or a specific version).
106
+ * Returns field-level diffs between the current published data and the draft.
107
+ */
108
+ compareDraftWithCurrent(entityId: string, locale?: string): Promise<{
109
+ diffs: FieldDiff[];
110
+ current: Record<string, unknown>;
111
+ draft: DraftEntry;
112
+ } | null>;
113
+ /**
114
+ * Restore an entity to a previous version.
115
+ */
116
+ restoreVersion(entityId: string, version: number): Promise<{
117
+ id: string;
118
+ } & {} & {
119
+ [x: string]: string | number | boolean | Date | Record<string, unknown> | Record<string, unknown>[] | {
120
+ [key: string]: unknown;
121
+ _block: string;
122
+ _id: string;
123
+ }[] | null | undefined;
124
+ }>;
125
+ /**
126
+ * Enforce maxPerDoc retention by deleting oldest versions for a locale.
127
+ */
128
+ pruneVersions(entityId: string, locale?: string): Promise<void>;
129
+ /**
130
+ * Get translation status for an entity — per-locale completion report.
131
+ */
132
+ getTranslationStatus(entityId: string): Promise<TranslationStatus>;
133
+ /**
134
+ * Get translation status for multiple entities in a single query.
135
+ * Returns a map of entityId → TranslationStatus (O(1) DB roundtrips).
136
+ */
137
+ getTranslationStatusBatch(entityIds: string[]): Promise<Map<string, TranslationStatus>>;
138
+ /**
139
+ * Get translation report across all entities of this type.
140
+ */
141
+ getTranslationReport(options?: {
142
+ locale?: string;
143
+ }): Promise<TranslationReport>;
144
+ /**
145
+ * Get per-locale publish status for an entity.
146
+ * Returns status for all non-default locales that have explicit overrides.
147
+ * Missing locale = inherits base entity status.
148
+ */
149
+ getLocaleStatus(entityId: string): Promise<LocalePublishStatus[]>;
150
+ /**
151
+ * Set per-locale publish status. Upserts into locale_status table.
152
+ * When locale === defaultLocale, updates the base entity status instead.
153
+ */
154
+ setLocaleStatus(entityId: string, locale: string, status: 'draft' | 'published'): Promise<void>;
155
+ /**
156
+ * Get per-locale publish status for multiple entities in a single query.
157
+ * Returns a map of entityId → locale → LocalePublishStatus.
158
+ */
159
+ getLocaleStatusBatch(entityIds: string[]): Promise<Map<string, Record<string, LocalePublishStatus>>>;
160
+ /**
161
+ * Save (upsert) a draft for an entity+locale.
162
+ * One draft per entity+locale — overwrites any existing draft.
163
+ */
164
+ saveDraft(entityId: string, data: Record<string, unknown>, locale?: string, user?: {
165
+ id: string;
166
+ name?: string;
167
+ }): Promise<DraftEntry>;
168
+ /**
169
+ * Get the draft for an entity+locale, or null if none exists.
170
+ */
171
+ getDraft(entityId: string, locale?: string): Promise<DraftEntry | null>;
172
+ /**
173
+ * Delete (discard) a draft for an entity+locale.
174
+ */
175
+ deleteDraft(entityId: string, locale?: string): Promise<boolean>;
176
+ /**
177
+ * Publish a draft: apply draft data to the live entity, then delete the draft.
178
+ * Runs in a transaction to ensure atomicity.
179
+ */
180
+ publishDraft(entityId: string, locale?: string, user?: {
181
+ id: string;
182
+ name?: string;
183
+ }): Promise<Record<string, unknown>>;
184
+ /**
185
+ * Quick existence check for list badges — does a draft exist?
186
+ */
187
+ hasDraft(entityId: string, locale?: string): Promise<boolean>;
188
+ /**
189
+ * Check draft existence for multiple entities in one query.
190
+ * Returns a set of entity IDs that have drafts.
191
+ */
192
+ hasDraftBatch(entityIds: string[], locale?: string): Promise<Set<string>>;
193
+ /**
194
+ * Create a version snapshot for an entity after an external update.
195
+ * Use this when the update was performed by AdminClient directly
196
+ * (e.g., the admin API handler) rather than through ContentClient.update().
197
+ *
198
+ * @param locale - The locale being edited. Use undefined or '_' for the default locale.
199
+ * @param user - The user who made the change (id + name for display).
200
+ */
201
+ createVersionSnapshot(entityId: string, currentData: Record<string, unknown>, previousData?: Record<string, unknown> | null, locale?: string, user?: {
202
+ id: string;
203
+ name?: string;
204
+ }): Promise<void>;
205
+ private saveVersionSnapshot;
206
+ private toDraftEntry;
207
+ private calculateDelta;
208
+ }
209
+ /**
210
+ * Factory — creates a ContentClient for an entity.
211
+ * Must be called after createApp().
212
+ */
213
+ declare function createContentClient(entity: Entity): Promise<ContentClient>;
214
+
215
+ export { ContentClient, type ContentClientConfig, createContentClient };
@@ -0,0 +1,142 @@
1
+ import { Behavior, NumberField, DateField, SelectField, TextField, FieldConfig } from '@murumets-ee/entity';
2
+ import { b as VersionableOptions, B as BlockDefinition } from './types-BYeiE1ie.js';
3
+ export { C as ContentConfig, D as DraftEntry, I as InferBlockData, c as InferBlocksUnion, d as LocaleConfig, e as LockInfo, f as TranslationFieldStatus, a as TranslationReport, T as TranslationStatus, V as VersionEntry } from './types-BYeiE1ie.js';
4
+ import { B as BlockDiffEntry, F as FieldDiff, D as DiffSegment } from './types-Cr0ifLn_.js';
5
+ export { a as BlockDiffStatus, P as PropDiff } from './types-Cr0ifLn_.js';
6
+
7
+ /**
8
+ * Versionable behavior — full version history with snapshots.
9
+ *
10
+ * Extends the concept of revisionable() (which only tracks a counter)
11
+ * with actual version snapshots stored in {entity}_versions table.
12
+ *
13
+ * The behavior itself adds fields + hooks for version tracking.
14
+ * Actual snapshot persistence happens in ContentClient (which has DB access).
15
+ *
16
+ * Options:
17
+ * - maxPerDoc: Maximum versions kept per document (default: 50)
18
+ * - autosave: Enable smart autosave (default: false)
19
+ */
20
+
21
+ type VersionableFields = {
22
+ _version: NumberField & {
23
+ required: true;
24
+ };
25
+ _versionedAt: DateField;
26
+ };
27
+ declare function versionable(options?: VersionableOptions): Behavior<VersionableFields>;
28
+ /**
29
+ * Extract versionable options from an entity's behaviors
30
+ */
31
+ declare function getVersionableOptions(behaviors?: Behavior[]): Required<VersionableOptions> | null;
32
+
33
+ /**
34
+ * Workflowable behavior — editorial workflow with approval gates.
35
+ *
36
+ * Adds workflow status tracking fields to an entity. Works alongside
37
+ * `publishable()` — the workflow status tracks the editorial pipeline,
38
+ * while publishable's `status` remains the public-facing state.
39
+ *
40
+ * Key invariant: `status` can only transition to 'published' when
41
+ * `_workflowStatus === 'approved'` (unless the user has direct `publish`
42
+ * permission, which bypasses the workflow).
43
+ *
44
+ * Workflow states:
45
+ * - draft → in_review (submit for review, requires 'update')
46
+ * - in_review → approved (approve, requires 'publish')
47
+ * - in_review → rejected (reject with note, requires 'publish')
48
+ * - approved → published (publish, requires 'publish')
49
+ * - rejected → in_review (resubmit, requires 'update')
50
+ * - published → draft (unpublish, requires 'publish')
51
+ */
52
+
53
+ declare const WORKFLOW_STATES: readonly ["draft", "in_review", "approved", "rejected", "published"];
54
+ type WorkflowState = (typeof WORKFLOW_STATES)[number];
55
+ type WorkflowableFields = {
56
+ _workflowStatus: SelectField & {
57
+ required: true;
58
+ };
59
+ _workflowAssignee: TextField;
60
+ _workflowNote: TextField;
61
+ _workflowUpdatedAt: DateField;
62
+ };
63
+ declare function workflowable(): Behavior<WorkflowableFields>;
64
+
65
+ /**
66
+ * Block definition API
67
+ *
68
+ * defineBlock() creates a reusable content block with typed fields.
69
+ * Uses `const F` generic to preserve literal field types for inference.
70
+ *
71
+ * Blocks are NOT entities — they lack independent identity, CRUD, and access control.
72
+ * They exist only as embedded data within a parent entity's blocks field.
73
+ *
74
+ * @example
75
+ * const HeroBlock = defineBlock({
76
+ * slug: 'hero',
77
+ * label: 'Hero Section',
78
+ * fields: {
79
+ * heading: field.text({ required: true, translatable: true }),
80
+ * background: field.media({ accept: ['image/*'] }),
81
+ * },
82
+ * })
83
+ */
84
+
85
+ declare function defineBlock<const F extends Record<string, FieldConfig>>(definition: {
86
+ slug: string;
87
+ label: string;
88
+ fields: F;
89
+ }): BlockDefinition<F>;
90
+
91
+ /**
92
+ * Structural diff for Puck block arrays.
93
+ *
94
+ * Blocks are identified by `_id`. The algorithm detects:
95
+ * - Added blocks (new _id in target)
96
+ * - Removed blocks (missing _id in target)
97
+ * - Moved blocks (same _id, different position)
98
+ * - Changed blocks (same _id, different prop values)
99
+ * - Unchanged blocks
100
+ */
101
+
102
+ /**
103
+ * Compute structural diff between two block arrays.
104
+ *
105
+ * Each block is identified by its `_id` field. Position changes,
106
+ * additions, removals, and prop-level changes are all detected.
107
+ */
108
+ declare function diffBlocks(fromBlocks: unknown[], toBlocks: unknown[]): BlockDiffEntry[];
109
+
110
+ /**
111
+ * Field-level diff — dispatches to the appropriate diff strategy per field type.
112
+ */
113
+
114
+ /**
115
+ * Compute diff for a single field, using the field's type to determine
116
+ * the best diff strategy.
117
+ */
118
+ declare function diffField(fieldName: string, from: unknown, to: unknown, fieldConfig?: FieldConfig): FieldDiff | null;
119
+ /**
120
+ * Diff all fields between two version snapshots.
121
+ * Pass fieldConfigs to get type-aware diffs; without them, types are inferred.
122
+ */
123
+ declare function diffFields(from: Record<string, unknown>, to: Record<string, unknown>, fieldConfigs?: Record<string, FieldConfig>): FieldDiff[];
124
+ /** Diff two string values and return segments (used by block-diff for string props). */
125
+ declare function diffStringValues(from: unknown, to: unknown): DiffSegment[] | undefined;
126
+
127
+ /**
128
+ * Word-level text diff using a simplified Myers algorithm.
129
+ *
130
+ * Splits text into words (preserving whitespace), computes the longest common
131
+ * subsequence, and returns an array of diff segments.
132
+ */
133
+
134
+ /**
135
+ * Compute word-level diff between two strings.
136
+ *
137
+ * Uses a simple LCS (dynamic programming) approach which is fine for
138
+ * the text sizes we deal with (entity field values, not source code).
139
+ */
140
+ declare function diffText(from: string, to: string): DiffSegment[];
141
+
142
+ export { BlockDefinition, BlockDiffEntry, DiffSegment, FieldDiff, VersionableOptions, WORKFLOW_STATES, type WorkflowState, type WorkflowableFields, defineBlock, diffBlocks, diffField, diffFields, diffStringValues, diffText, getVersionableOptions, versionable, workflowable };
@@ -0,0 +1,61 @@
1
+ import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
2
+ import { e as LockInfo } from './types-BYeiE1ie.js';
3
+ import '@murumets-ee/entity';
4
+
5
+ /**
6
+ * Content lock service — pessimistic locking for entity editing.
7
+ *
8
+ * Prevents concurrent edit conflicts by allowing only one editor at a time
9
+ * per entity+locale combination. Locks expire after 5 minutes and must
10
+ * be renewed via heartbeat.
11
+ */
12
+
13
+ interface LockServiceConfig {
14
+ db: PostgresJsDatabase;
15
+ }
16
+ declare class LockService {
17
+ private db;
18
+ constructor(config: LockServiceConfig);
19
+ private getTable;
20
+ /**
21
+ * Acquire a lock on an entity+locale.
22
+ *
23
+ * - Deletes expired locks first
24
+ * - Attempts INSERT; on conflict checks if same user (re-entrant → renew)
25
+ * - Returns { acquired: true } or { acquired: false, lock: LockInfo }
26
+ */
27
+ acquireLock(entityType: string, entityId: string, locale: string, user: {
28
+ id: string;
29
+ name?: string;
30
+ }): Promise<{
31
+ acquired: true;
32
+ } | {
33
+ acquired: false;
34
+ lock: LockInfo;
35
+ }>;
36
+ /**
37
+ * Renew an existing lock (heartbeat).
38
+ * Only succeeds if the caller holds the lock and it hasn't expired.
39
+ */
40
+ renewLock(entityType: string, entityId: string, locale: string, userId: string): Promise<boolean>;
41
+ /**
42
+ * Release a lock. Only the lock holder can release their own lock.
43
+ */
44
+ releaseLock(entityType: string, entityId: string, locale: string, userId: string): Promise<boolean>;
45
+ /**
46
+ * Force-release a lock regardless of who holds it.
47
+ * Admin-only operation — must be audit-logged by the caller.
48
+ */
49
+ forceReleaseLock(entityType: string, entityId: string, locale: string): Promise<boolean>;
50
+ /**
51
+ * Get the current lock for an entity+locale.
52
+ * Returns null if no lock or lock has expired.
53
+ */
54
+ getLock(entityType: string, entityId: string, locale: string): Promise<LockInfo | null>;
55
+ }
56
+ /**
57
+ * Factory — creates a LockService using the app's DB connection.
58
+ */
59
+ declare function createLockService(): Promise<LockService>;
60
+
61
+ export { LockService, type LockServiceConfig, createLockService };
@@ -0,0 +1,33 @@
1
+ import { Plugin } from '@murumets-ee/core';
2
+ import { C as ContentConfig } from './types-BYeiE1ie.js';
3
+ import '@murumets-ee/entity';
4
+
5
+ /**
6
+ * Content plugin — registers locale configuration and version schemas.
7
+ *
8
+ * Usage:
9
+ * import { content } from '@murumets-ee/content/plugin'
10
+ *
11
+ * export default defineConfig({
12
+ * plugins: [
13
+ * content({
14
+ * locales: [
15
+ * { code: 'en', label: 'English' },
16
+ * { code: 'de', label: 'German' },
17
+ * ],
18
+ * defaultLocale: 'en',
19
+ * }),
20
+ * ],
21
+ * })
22
+ */
23
+
24
+ /**
25
+ * Get the content configuration. Throws if plugin not initialized.
26
+ */
27
+ declare function getContentConfig(): ContentConfig;
28
+ /**
29
+ * Content plugin factory.
30
+ */
31
+ declare function content(config: ContentConfig): Plugin;
32
+
33
+ export { content, getContentConfig };
@@ -0,0 +1,67 @@
1
+ import { Logger } from '@murumets-ee/core';
2
+ import { Entity } from '@murumets-ee/entity';
3
+ import { FindByIdOptions, FindManyOptions, CountOptions } from '@murumets-ee/entity/query';
4
+ import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
5
+
6
+ /**
7
+ * ContentQueryClient — read-only content queries, safe for client bundles.
8
+ *
9
+ * Usage:
10
+ * import { createContentQueryClient } from '@murumets-ee/content/query'
11
+ * const pages = createContentQueryClient(Page)
12
+ * const page = await pages.findBySlug('about', { locale: 'de' })
13
+ */
14
+
15
+ interface ContentQueryClientConfig {
16
+ entity: Entity;
17
+ db: PostgresJsDatabase;
18
+ logger?: Logger;
19
+ }
20
+ declare class ContentQueryClient {
21
+ private entity;
22
+ private db;
23
+ private logger?;
24
+ private query;
25
+ constructor(config: ContentQueryClientConfig);
26
+ private getQuery;
27
+ findById(id: string, options?: FindByIdOptions): Promise<({
28
+ id: string;
29
+ } & {} & {
30
+ [x: string]: string | number | boolean | Record<string, unknown> | Date | Record<string, unknown>[] | {
31
+ [key: string]: unknown;
32
+ _block: string;
33
+ _id: string;
34
+ }[] | null | undefined;
35
+ }) | null>;
36
+ /**
37
+ * Find entity by slug — convenience for slug-based lookups.
38
+ */
39
+ findBySlug(slug: string, options?: {
40
+ locale?: string;
41
+ }): Promise<({
42
+ id: string;
43
+ } & {} & {
44
+ [x: string]: string | number | boolean | Record<string, unknown> | Date | Record<string, unknown>[] | {
45
+ [key: string]: unknown;
46
+ _block: string;
47
+ _id: string;
48
+ }[] | null | undefined;
49
+ }) | null>;
50
+ findMany(options?: FindManyOptions): Promise<({
51
+ id: string;
52
+ } & {} & {
53
+ [x: string]: string | number | boolean | Record<string, unknown> | Date | Record<string, unknown>[] | {
54
+ [key: string]: unknown;
55
+ _block: string;
56
+ _id: string;
57
+ }[] | null | undefined;
58
+ })[]>;
59
+ count(options?: CountOptions): Promise<number>;
60
+ }
61
+ /**
62
+ * Factory — creates a ContentQueryClient for an entity.
63
+ * Must be called after createApp().
64
+ */
65
+ declare function createContentQueryClient(entity: Entity): Promise<ContentQueryClient>;
66
+
67
+ export { ContentQueryClient, type ContentQueryClientConfig, createContentQueryClient };
@@ -0,0 +1,99 @@
1
+ import { FieldConfig, InferEntityDTO } from '@murumets-ee/entity';
2
+
3
+ /**
4
+ * Content package types
5
+ */
6
+
7
+ /**
8
+ * A block definition — describes a reusable content block's data shape.
9
+ *
10
+ * @typeParam F - The literal field map, inferred from the call site.
11
+ */
12
+ interface BlockDefinition<F extends Record<string, FieldConfig> = Record<string, FieldConfig>> {
13
+ slug: string;
14
+ label: string;
15
+ fields: F;
16
+ }
17
+ /**
18
+ * Infer the data shape of a single block definition.
19
+ * Produces `{ _block: 'hero'; _id: string; heading: string; ... }`
20
+ */
21
+ type InferBlockData<B extends BlockDefinition> = B extends BlockDefinition<infer F> ? {
22
+ _block: B['slug'];
23
+ _id: string;
24
+ } & Omit<InferEntityDTO<F>, 'id'> : never;
25
+ /**
26
+ * Infer a discriminated union from a tuple of block definitions.
27
+ *
28
+ * @example
29
+ * type Layout = InferBlocksUnion<typeof [HeroBlock, RichTextBlock]>
30
+ * // = { _block: 'hero'; ... } | { _block: 'richtext'; ... }
31
+ */
32
+ type InferBlocksUnion<T extends readonly BlockDefinition[]> = {
33
+ [K in keyof T]: T[K] extends BlockDefinition ? InferBlockData<T[K]> : never;
34
+ }[number];
35
+ interface LocaleConfig {
36
+ code: string;
37
+ label: string;
38
+ }
39
+ interface ContentConfig {
40
+ locales: LocaleConfig[];
41
+ defaultLocale: string;
42
+ }
43
+ interface VersionableOptions {
44
+ /** Maximum versions kept per document. Default: 50 */
45
+ maxPerDoc?: number;
46
+ /** Enable autosave (single mutable autosave version). Default: false */
47
+ autosave?: boolean;
48
+ }
49
+ interface VersionEntry {
50
+ id: string;
51
+ entityId: string;
52
+ version: number;
53
+ locale: string;
54
+ data: Record<string, unknown>;
55
+ delta: Record<string, unknown> | null;
56
+ status: string | null;
57
+ createdBy: string | null;
58
+ createdByName: string | null;
59
+ createdAt: Date | string;
60
+ isAutosave: boolean;
61
+ }
62
+ interface TranslationFieldStatus {
63
+ complete: boolean;
64
+ total: number;
65
+ translated: number;
66
+ missing: string[];
67
+ }
68
+ interface TranslationStatus {
69
+ [locale: string]: TranslationFieldStatus;
70
+ }
71
+ interface TranslationReport {
72
+ total: number;
73
+ complete: number;
74
+ partial: number;
75
+ missing: number;
76
+ }
77
+ interface LocalePublishStatus {
78
+ locale: string;
79
+ status: 'draft' | 'published';
80
+ publishedAt: Date | string | null;
81
+ }
82
+ interface DraftEntry {
83
+ id: string;
84
+ entityId: string;
85
+ locale: string;
86
+ data: Record<string, unknown>;
87
+ createdBy: string;
88
+ createdByName: string | null;
89
+ createdAt: Date | string;
90
+ updatedAt: Date | string;
91
+ }
92
+ interface LockInfo {
93
+ lockedBy: string;
94
+ lockedByName: string | null;
95
+ lockedAt: Date | string;
96
+ expiresAt: Date | string;
97
+ }
98
+
99
+ export type { BlockDefinition as B, ContentConfig as C, DraftEntry as D, InferBlockData as I, LocalePublishStatus as L, TranslationStatus as T, VersionEntry as V, TranslationReport as a, VersionableOptions as b, InferBlocksUnion as c, LocaleConfig as d, LockInfo as e, TranslationFieldStatus as f };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Diff result types for version comparison.
3
+ */
4
+ /** A segment within a word-level text diff. */
5
+ interface DiffSegment {
6
+ type: 'equal' | 'add' | 'remove';
7
+ value: string;
8
+ }
9
+ /** Diff result for a single scalar field. */
10
+ interface FieldDiff {
11
+ field: string;
12
+ type: 'text' | 'number' | 'boolean' | 'date' | 'select' | 'media' | 'richtext' | 'json' | 'blocks' | 'unknown';
13
+ from: unknown;
14
+ to: unknown;
15
+ /** Word-level diff segments (present for text/richtext/slug fields). */
16
+ segments?: DiffSegment[];
17
+ /** Block-level structural diff (present for blocks fields). */
18
+ blockDiffs?: BlockDiffEntry[];
19
+ }
20
+ /** Status of a single block within a structural diff. */
21
+ type BlockDiffStatus = 'added' | 'removed' | 'moved' | 'changed' | 'unchanged';
22
+ /** Diff result for a single block within a blocks field. */
23
+ interface BlockDiffEntry {
24
+ blockId: string;
25
+ blockType: string;
26
+ status: BlockDiffStatus;
27
+ fromIndex?: number;
28
+ toIndex?: number;
29
+ /** Per-prop diffs for changed blocks. */
30
+ propDiffs?: PropDiff[];
31
+ }
32
+ /** Diff for a single prop within a changed block. */
33
+ interface PropDiff {
34
+ field: string;
35
+ from: unknown;
36
+ to: unknown;
37
+ /** Word-level segments for string props. */
38
+ segments?: DiffSegment[];
39
+ }
40
+
41
+ export type { BlockDiffEntry as B, DiffSegment as D, FieldDiff as F, PropDiff as P, BlockDiffStatus as a };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@murumets-ee/content",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "license": "Elastic-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -36,10 +36,10 @@
36
36
  "drizzle-orm": "^0.45.1",
37
37
  "server-only": "^0.0.1",
38
38
  "zod": "^3.24.1",
39
- "@murumets-ee/core": "0.1.3",
40
- "@murumets-ee/logging": "0.1.3",
41
- "@murumets-ee/db": "0.1.2",
42
- "@murumets-ee/entity": "0.1.2"
39
+ "@murumets-ee/db": "0.1.4",
40
+ "@murumets-ee/entity": "0.1.4",
41
+ "@murumets-ee/core": "0.1.5",
42
+ "@murumets-ee/logging": "0.1.5"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/node": "^22.10.5",