foldkit-cms 0.1.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.
@@ -0,0 +1,1204 @@
1
+ import { Option, Pipeable, Schema } from "effect";
2
+ import { AnyEntity, Entity, EntityField, EntityInput } from "foldkit-entity";
3
+ import { MutationDescriptor, MutationStatus, OptimisticOperation, RemoteClient, RemoteData, RemoteMessage } from "foldkit-remote";
4
+ import { Bundle } from "foldkit-bundle";
5
+ import * as Submodel from "foldkit/submodel";
6
+ import { Control, Draft, Submitted } from "foldkit-form";
7
+ import { Projection } from "foldkit-surface";
8
+ import { Command } from "foldkit/command";
9
+ import * as Update from "foldkit/update";
10
+ import * as ManagedResource from "foldkit/managedResource";
11
+ import * as Subscription from "foldkit/subscription";
12
+ import { CallableTaggedStruct } from "foldkit/schema";
13
+ import { Attribute, Html, HtmlBuilder } from "foldkit/html";
14
+ import "foldkit/url";
15
+ //#region src/lifecycle.d.ts
16
+ /**
17
+ * The lifecycle of a piece of content, derived. Nothing stores a status: a state
18
+ * is a pure function of facts (is there a row, can a visitor see it, is there a
19
+ * draft, has the entry been archived) and a clock, so it cannot disagree with
20
+ * them. A scheduled publish that failed reads scheduled and overdue, which is
21
+ * true, and not published, which would not be.
22
+ */
23
+ /** What is known of one entry. The server gathers it; nothing here reads a database. */
24
+ interface Facts {
25
+ /** When the entry was archived, if it was. */
26
+ readonly archivedAt: string | null;
27
+ /** The content row: none yet, one a visitor can see, or one hidden by its `published` role. */
28
+ readonly row: 'none' | 'visible' | 'hidden';
29
+ /** The entry's working copy, if it has one. */
30
+ readonly draft: {
31
+ readonly scheduledFor: string | null;
32
+ readonly scheduleError: string | null;
33
+ } | null;
34
+ }
35
+ /** A draft that is to be published at a time, and how that stands. */
36
+ interface Schedule {
37
+ readonly at: string;
38
+ /** The time has come and the draft is still a draft: the publish has not run, or failed. */
39
+ readonly overdue: boolean;
40
+ /** Why the last attempt failed, for the author to fix. */
41
+ readonly error: string | null;
42
+ }
43
+ type StateTag = 'New' | 'Published' | 'Changed' | 'Unpublished' | 'Archived';
44
+ /**
45
+ * - `New`: nothing published yet.
46
+ * - `Published`: what a visitor sees is all there is.
47
+ * - `Changed`: published, with unpublished work beside it.
48
+ * - `Unpublished`: a row a visitor cannot see.
49
+ * - `Archived`: put away; nothing else applies until it is restored.
50
+ *
51
+ * `schedule` rides beside `New` and `Changed`, the states that have a draft to publish.
52
+ */
53
+ interface State {
54
+ readonly _tag: StateTag;
55
+ readonly schedule: Schedule | null;
56
+ }
57
+ /** What an author may ask of an entry. Each is an operation the server runs after asking `allow`. */
58
+ type Transition = 'save' | 'discard' | 'publish' | 'schedule' | 'unschedule' | 'unpublish' | 'archive' | 'unarchive' | 'restore';
59
+ //#endregion
60
+ //#region src/editor.d.ts
61
+ /** How the form came to hold what it holds. */
62
+ type Resumed =
63
+ /** The draft's saved Model: the form exactly as it was left, errors and all. */
64
+ 'Model' |
65
+ /** The draft's values, key by key, keeping what the form still accepts. */
66
+ 'Values' |
67
+ /** What is published: there was no draft. */
68
+ 'Published' |
69
+ /** There was a draft and nothing of it fits the form any more; what is published is shown. */
70
+ 'Lost' |
71
+ /** Something new. */
72
+ 'Blank';
73
+ type EditorStatus = 'Closed' | 'Loading' | 'NotFound' | 'LoadFailed' |
74
+ /** Open, with nothing entered since it was opened and nothing pending. */
75
+ 'Opened' |
76
+ /** Edited since the last save. */
77
+ 'Editing' | 'Saving' | 'Saved' |
78
+ /** Someone else saved or published in between. The author's text is still in the form. */
79
+ 'Conflict' | 'SaveFailed' | 'Publishing' | 'Published' | 'PublishFailed' | 'Scheduling' |
80
+ /** Promised for later. The entry's `state` says for when, and whether it happened. */
81
+ 'Scheduled' | 'ScheduleFailed';
82
+ /**
83
+ * An editor's slice of the parent Model. `edits` counts the edits made, and
84
+ * `savedEdit` is the count the last save was started at: the form is saved when
85
+ * they agree.
86
+ */
87
+ interface EditorModel<FormModel> {
88
+ readonly form: FormModel;
89
+ readonly mode: 'closed' | 'new' | 'edit';
90
+ readonly entry: string | null;
91
+ readonly filled: boolean;
92
+ readonly resumed: Resumed | null;
93
+ readonly edits: number;
94
+ readonly savedEdit: number;
95
+ readonly saveId: string | null;
96
+ readonly saveWanted: boolean;
97
+ readonly publishId: string | null;
98
+ readonly publishWanted: boolean;
99
+ /** When the publish that is wanted, under way or last settled is a promise for later: for when. */
100
+ readonly scheduleAt: string | null;
101
+ /** The discard or unpublish in progress or last settled. */
102
+ readonly otherId: string | null;
103
+ /** Whether what is in the form is laid over the store, for the application's own views to draw. */
104
+ readonly previewing: boolean;
105
+ /** What the overlay was last made of: the edit, and the row it is shown on. */
106
+ readonly previewedAs: string | null;
107
+ /** After a conflict: waiting for the server's copy, to show it or to save over it. */
108
+ readonly settling: 'reload' | 'overwrite' | null;
109
+ }
110
+ /** What the editor asks of where it is placed; `onOut` answers each. */
111
+ type EditorOut = {
112
+ readonly _tag: 'Save';
113
+ } | {
114
+ readonly _tag: 'Publish';
115
+ } | {
116
+ readonly _tag: 'Discard';
117
+ } | {
118
+ readonly _tag: 'Restore';
119
+ readonly revision: number;
120
+ } | {
121
+ readonly _tag: 'Unpublish';
122
+ } | {
123
+ readonly _tag: 'Unschedule';
124
+ } | {
125
+ readonly _tag: 'Archive';
126
+ } | {
127
+ readonly _tag: 'Unarchive';
128
+ } | {
129
+ readonly _tag: 'Reload';
130
+ } | {
131
+ readonly _tag: 'Overwrite';
132
+ };
133
+ /** The parts of a `Form.make` result the editor drives. */
134
+ interface EditorForm<FormModel, FormMessage, Value> {
135
+ readonly name: string;
136
+ readonly input: {
137
+ readonly schema: Schema.Struct<any>;
138
+ };
139
+ readonly bundle: {
140
+ readonly Model: Schema.Codec<FormModel, unknown>;
141
+ readonly Message: Schema.Codec<FormMessage, unknown>;
142
+ readonly update: (model: FormModel, message: FormMessage, args: void) => Update.ReturnWithOutMessage<FormModel, FormMessage, Submitted<Value>, any>;
143
+ };
144
+ readonly Message: {
145
+ readonly Submitted: () => FormMessage;
146
+ readonly Refused: (payload: {
147
+ readonly key: never;
148
+ readonly error: string;
149
+ }) => FormMessage;
150
+ readonly About: (payload: {
151
+ readonly subject: Readonly<Record<string, string>>;
152
+ }) => FormMessage;
153
+ };
154
+ readonly initial: FormModel;
155
+ readonly fill: (model: FormModel, values: Partial<Value>) => {
156
+ readonly model: FormModel;
157
+ };
158
+ readonly partial: (model: FormModel) => Partial<Value>;
159
+ readonly settled: (model: FormModel) => FormModel;
160
+ /** What the form is editing; `{}` while it creates. See `Form.FormModel.subject`. */
161
+ readonly subject: (model: FormModel) => Readonly<Record<string, string>>;
162
+ readonly field: (model: FormModel, key: never) => {
163
+ readonly _tag: string;
164
+ readonly value: unknown;
165
+ readonly errors?: ReadonlyArray<string>;
166
+ };
167
+ }
168
+ /** The parts of a bound Remote domain the editor uses. */
169
+ interface EditorDomain<Root> {
170
+ mutate(model: Root, mutation: any, input: any): {
171
+ readonly model: Root;
172
+ readonly requestId: string;
173
+ readonly command: Command<RemoteMessage, never, RemoteClient>;
174
+ };
175
+ get(selection: any, id: string): Projection<Root, RemoteData<any>>;
176
+ mutation(model: Root, requestId: string): MutationStatus;
177
+ refresh(model: Root, target: any): Root;
178
+ overlay(model: Root, id: string, optimistic: ReadonlyArray<OptimisticOperation>): Root;
179
+ lift(model: Root, id: string): Root;
180
+ readonly contract: {
181
+ readonly owner?: object | undefined;
182
+ };
183
+ }
184
+ interface EditorContent<FormModel, FormMessage, Value> {
185
+ readonly name: string;
186
+ readonly entity: AnyEntity;
187
+ readonly form: EditorForm<FormModel, FormMessage, Value>;
188
+ readonly roles: {
189
+ readonly label: {
190
+ readonly key: string;
191
+ } | undefined;
192
+ readonly slug: {
193
+ readonly key: string;
194
+ } | undefined;
195
+ };
196
+ readonly preview?: ((value: Partial<Value>, id: string) => ReadonlyArray<OptimisticOperation>) | undefined;
197
+ }
198
+ declare const EditorMessage: import("foldkit/message").MessageUnion<{
199
+ readonly Rested: {
200
+ readonly edit: Schema.Number;
201
+ };
202
+ readonly PublishAsked: {};
203
+ /** Lays what is in the form over the store, until `PreviewHidden`. Nothing is sent. */
204
+ readonly PreviewShown: {};
205
+ readonly PreviewHidden: {};
206
+ /** Publishes later: the form is submitted and saved now, and the server keeps the promise. */
207
+ readonly ScheduleAsked: {
208
+ readonly at: Schema.String;
209
+ };
210
+ readonly UnscheduleAsked: {};
211
+ readonly ArchiveAsked: {};
212
+ readonly UnarchiveAsked: {};
213
+ readonly DiscardAsked: {};
214
+ /** Makes a revision's value the working copy. It replaces what is here, and publishes nothing. */
215
+ readonly RestoreAsked: {
216
+ readonly revision: Schema.Number;
217
+ };
218
+ readonly UnpublishAsked: {};
219
+ /** After a conflict: drop what is here and show the server's copy. */
220
+ readonly ReloadAsked: {};
221
+ /** After a conflict: save what is here over the server's copy. */
222
+ readonly OverwriteAsked: {};
223
+ }>;
224
+ type EditorMessage = typeof EditorMessage.Type;
225
+ //#endregion
226
+ //#region ../bundle/src/link.d.ts
227
+ declare const LinkTypeId: unique symbol;
228
+ /** The parent Message variant `Tag({ message })` that carries a child's Messages. */
229
+ type Wrapped<Tag extends string, ChildMessage> = {
230
+ readonly _tag: Tag;
231
+ readonly message: ChildMessage;
232
+ };
233
+ /**
234
+ * Both directions between a child Message and its parent variant. Spread
235
+ * `cases` into the parent's `defineMessageUnion` so the variant is part of the
236
+ * parent Message.
237
+ */
238
+ interface Wrapper<Tag extends string, ChildMessage> {
239
+ readonly tag: Tag;
240
+ readonly Schema: CallableTaggedStruct<Tag, {
241
+ readonly message: Schema.Codec<ChildMessage, unknown>;
242
+ }>;
243
+ readonly cases: { readonly [K in Tag]: {
244
+ readonly message: Schema.Codec<ChildMessage, unknown>;
245
+ }; };
246
+ readonly make: (message: ChildMessage) => Wrapped<Tag, ChildMessage>;
247
+ readonly toParentMessage: (message: ChildMessage) => Wrapped<Tag, ChildMessage>;
248
+ readonly fromParentMessage: (message: AnyMessage) => Option.Option<ChildMessage>;
249
+ }
250
+ /** Every Foldkit Message is tagged; routing only needs the tag. */
251
+ type AnyMessage = {
252
+ readonly _tag: string;
253
+ };
254
+ interface Link<Parent, ParentMessage, Child, ChildMessage> extends Pipeable.Pipeable {
255
+ readonly [LinkTypeId]: typeof LinkTypeId;
256
+ readonly read: (parent: Parent) => Option.Option<Child>;
257
+ readonly write: (parent: Parent, child: Child) => Parent;
258
+ readonly toParentMessage: (message: ChildMessage) => ParentMessage;
259
+ /** Recognises this child's variant among all of the parent's Messages. */
260
+ readonly fromParentMessage: (message: AnyMessage) => Option.Option<ChildMessage>;
261
+ /** The parent's own gate: while it returns `false`, the child's Subscriptions and resources stop. */
262
+ readonly when: Option.Option<(parent: Parent) => boolean>;
263
+ /** Where the child lives, for placement keys and diagnostics. */
264
+ readonly path: ReadonlyArray<string>;
265
+ /** The parent Message tags this link's Messages travel under, outermost first. */
266
+ readonly messages: ReadonlyArray<string>;
267
+ /** The application a Link built from a Surface field ref belongs to, for its Module contract. */
268
+ readonly owner?: object | undefined;
269
+ }
270
+ interface MakeConfig<Parent, Tag extends string, Child, ChildMessage> {
271
+ readonly read: (parent: Parent) => Option.Option<Child>;
272
+ readonly write: (parent: Parent, child: Child) => Parent;
273
+ readonly wrapper: Wrapper<Tag, ChildMessage>;
274
+ readonly when?: (parent: Parent) => boolean;
275
+ readonly path: ReadonlyArray<string>;
276
+ readonly owner?: object | undefined;
277
+ }
278
+ type OptionKeys<Parent> = { [K in keyof Parent]: Parent[K] extends Option.Option<unknown> ? K : never; }[keyof Parent] & string;
279
+ type OptionValue<A> = A extends Option.Option<infer Value> ? Value : never;
280
+ /** The parent Message variant `Tag({ key, message })` that carries one collection item's Messages. */
281
+ type KeyedWrapped<Tag extends string, ChildMessage, Key extends string = string> = {
282
+ readonly _tag: Tag;
283
+ readonly key: Key;
284
+ readonly message: ChildMessage;
285
+ };
286
+ type KeyedFields<ChildMessage, Key extends string> = {
287
+ readonly key: Schema.Codec<Key, string>;
288
+ readonly message: Schema.Codec<ChildMessage, unknown>;
289
+ };
290
+ /** Both directions between an item's Message and its keyed parent variant. */
291
+ interface KeyedWrapper<Tag extends string, ChildMessage, Key extends string = string> {
292
+ readonly tag: Tag;
293
+ readonly Schema: CallableTaggedStruct<Tag, KeyedFields<ChildMessage, Key>>;
294
+ readonly cases: { readonly [K in Tag]: KeyedFields<ChildMessage, Key>; };
295
+ readonly make: (key: Key, message: ChildMessage) => KeyedWrapped<Tag, ChildMessage, Key>;
296
+ readonly fromParentMessage: (message: AnyMessage) => Option.Option<readonly [key: Key, message: ChildMessage]>;
297
+ }
298
+ /**
299
+ * Where a keyed collection of children lives. The storage is the Link's
300
+ * business: a record by key, an array identified by id, or anything with these
301
+ * operations. `entries` is the order views and Subscriptions follow.
302
+ */
303
+ interface CollectionLink<Parent, ParentMessage, Child, ChildMessage, Key extends string = string> {
304
+ /** The storage with no items, for a parent's initial Model. */
305
+ readonly empty: unknown;
306
+ readonly entries: (parent: Parent) => ReadonlyArray<readonly [key: Key, child: Child]>;
307
+ readonly get: (parent: Parent, key: Key) => Option.Option<Child>;
308
+ /** Writes one item; `None` removes it. */
309
+ readonly write: (parent: Parent, key: Key, child: Option.Option<Child>) => Parent;
310
+ readonly toParentMessage: (key: Key, message: ChildMessage) => ParentMessage;
311
+ readonly fromParentMessage: (message: AnyMessage) => Option.Option<readonly [key: Key, message: ChildMessage]>;
312
+ /** The parent's gate per item: while it returns `false`, that item's Subscriptions stop. */
313
+ readonly when: Option.Option<(parent: Parent, key: Key) => boolean>;
314
+ readonly path: ReadonlyArray<string>;
315
+ /** The parent Message tag this collection's Messages travel under. */
316
+ readonly messages: ReadonlyArray<string>;
317
+ }
318
+ type RecordKeys<Parent> = { [K in keyof Parent]: Parent[K] extends Readonly<Record<string, unknown>> ? K : never; }[keyof Parent] & string;
319
+ type RecordValue<A> = A extends Readonly<Record<string, infer Value>> ? Value : never;
320
+ type ArrayKeys<Parent> = { [K in keyof Parent]: Parent[K] extends ReadonlyArray<unknown> ? K : never; }[keyof Parent] & string;
321
+ type ArrayItem<A> = A extends ReadonlyArray<infer Item> ? Item : never;
322
+ declare const Link: {
323
+ readonly wrapper: <const Tag extends string, ChildMessage>(tag: Tag, childMessage: Schema.Codec<ChildMessage, unknown>) => Wrapper<Tag, ChildMessage>;
324
+ readonly make: <Parent, const Tag extends string, Child, ChildMessage>(config: MakeConfig<Parent, Tag, Child, ChildMessage>) => Link<Parent, Wrapped<Tag, ChildMessage>, Child, ChildMessage>;
325
+ readonly field: <Parent>() => <const Key extends keyof Parent & string, const Tag extends string, ChildMessage>(key: Key, wrap: Wrapper<Tag, ChildMessage>, options?: {
326
+ readonly when?: (parent: Parent) => boolean;
327
+ }) => Link<Parent, Wrapped<Tag, ChildMessage>, Parent[Key], ChildMessage>;
328
+ readonly optional: <Parent>() => <const Key extends OptionKeys<Parent>, const Tag extends string, ChildMessage>(key: Key, wrap: Wrapper<Tag, ChildMessage>, options?: {
329
+ readonly when?: (parent: Parent) => boolean;
330
+ }) => Link<Parent, Wrapped<Tag, ChildMessage>, OptionValue<Parent[Key]>, ChildMessage>;
331
+ readonly compose: <A, AMessage, B, BMessage extends AnyMessage, C, CMessage>(outer: Link<A, AMessage, B, BMessage>, inner: Link<B, BMessage, C, CMessage>) => Link<A, AMessage, C, CMessage>;
332
+ readonly andThen: {
333
+ <B, BMessage extends AnyMessage, C, CMessage>(inner: Link<B, BMessage, C, CMessage>): <A, AMessage>(outer: Link<A, AMessage, B, BMessage>) => Link<A, AMessage, C, CMessage>;
334
+ <A, AMessage, B, BMessage extends AnyMessage, C, CMessage>(outer: Link<A, AMessage, B, BMessage>, inner: Link<B, BMessage, C, CMessage>): Link<A, AMessage, C, CMessage>;
335
+ };
336
+ readonly when: {
337
+ <Parent>(predicate: (parent: Parent) => boolean): <ParentMessage, Child, ChildMessage>(self: Link<Parent, ParentMessage, Child, ChildMessage>) => Link<Parent, ParentMessage, Child, ChildMessage>;
338
+ <Parent, ParentMessage, Child, ChildMessage>(self: Link<Parent, ParentMessage, Child, ChildMessage>, predicate: (parent: Parent) => boolean): Link<Parent, ParentMessage, Child, ChildMessage>;
339
+ };
340
+ readonly keyedWrapper: <const Tag extends string, ChildMessage, Key extends string = string>(tag: Tag, childMessage: Schema.Codec<ChildMessage, unknown>, key?: Schema.Codec<Key, string>) => KeyedWrapper<Tag, ChildMessage, Key>;
341
+ readonly collection: <Parent>() => <const Field extends RecordKeys<Parent>, const Tag extends string, ChildMessage, Key extends string>(field: Field, wrap: KeyedWrapper<Tag, ChildMessage, Key>, options?: {
342
+ readonly when?: (parent: Parent, key: Key) => boolean;
343
+ }) => CollectionLink<Parent, KeyedWrapped<Tag, ChildMessage, Key>, RecordValue<Parent[Field]>, ChildMessage, Key>;
344
+ readonly collectionById: <Parent>() => <const Field extends ArrayKeys<Parent>, const Tag extends string, ChildMessage, Key extends string>(field: Field, wrap: KeyedWrapper<Tag, ChildMessage, Key>, options: {
345
+ readonly id: (item: ArrayItem<Parent[Field]>) => Key;
346
+ readonly when?: (parent: Parent, key: Key) => boolean;
347
+ }) => CollectionLink<Parent, KeyedWrapped<Tag, ChildMessage, Key>, ArrayItem<Parent[Field]>, ChildMessage, Key>;
348
+ };
349
+ //#endregion
350
+ //#region ../bundle/src/placed.d.ts
351
+ declare const PlacedTypeId: unique symbol;
352
+ interface PlaceConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2> {
353
+ readonly args?: Args;
354
+ /** Handles the child's OutMessage in parent terms, with the child already written back. */
355
+ readonly onOut?: (outMessage: OutMessage, context: Update.FoldContext<Message, LinkMessage>) => Update.Step<NoInfer<Parent>, OutStepMessage, R2>;
356
+ /** Prefix for the placement's Subscription and resource keys. Defaults to `Name@path`. */
357
+ readonly key?: string;
358
+ /** A gate beside the Link's own: Subscriptions and resources run only while both hold. */
359
+ readonly when?: (parent: Parent) => boolean;
360
+ }
361
+ /** A lifted resource record: each child entry in parent terms, keyed by the placement. */
362
+ type PlacedResources<Parent, ParentMessage, Resources> = Readonly<Record<string, { readonly [K in keyof Resources]: Resources[K] extends ManagedResource.Entry<any, any, infer Requirements, infer Value, infer Service, any> ? ManagedResource.Entry<Parent, ParentMessage, Requirements, Value, Service> : never; }[keyof Resources]>>;
363
+ type PlacedHelpers<Parent, ParentMessage, R, Helpers> = { readonly [K in keyof Helpers]: Helpers[K] extends ((model: any, ...input: infer Input) => any) ? (...input: Input) => Update.Step<Parent, ParentMessage, R> : never; };
364
+ interface Placed<Name extends string, Parent, ParentMessage, Model, Message, R, S, ViewInputs, Resources, Helpers, Field extends string = string> {
365
+ readonly [PlacedTypeId]: typeof PlacedTypeId;
366
+ /** Types only: the top-level Model field this placement owns, or `string` when unknown. */
367
+ readonly field?: Field;
368
+ readonly name: Name;
369
+ /** `Name@path`, or the configured `key`: the prefix of every Subscription and resource key. */
370
+ readonly key: string;
371
+ /** The encoded args as text, when the bundle has an args Schema. */
372
+ readonly argsSummary: string | undefined;
373
+ readonly link: Link<Parent, ParentMessage, Model, Message>;
374
+ /** Writes the child's initial Model and starts its `init` Commands. */
375
+ readonly init: Update.Step<Parent, ParentMessage, R>;
376
+ /** Folds the Message when it belongs to this placement; `None` otherwise. */
377
+ readonly update: (parent: Parent, message: AnyMessage) => Option.Option<Update.Return<Parent, ParentMessage, R>>;
378
+ readonly subscriptions: Subscription.Subscriptions<Parent, ParentMessage, S>;
379
+ readonly resources: PlacedResources<Parent, ParentMessage, Resources>;
380
+ /**
381
+ * Renders the child through `h.submodel`; nothing while the child is absent.
382
+ * Generic over the parent's whole Message, which must include this placement's.
383
+ */
384
+ readonly view: PlacedView<Parent, ParentMessage, ViewInputs>;
385
+ /**
386
+ * The same view in another slot, for rendering one placement in two DOM
387
+ * positions (desktop and mobile). `h.submodel` throws on a repeated slot.
388
+ */
389
+ readonly viewIn: (slot: string) => PlacedView<Parent, ParentMessage, ViewInputs>;
390
+ readonly helpers: PlacedHelpers<Parent, ParentMessage, R, Helpers>;
391
+ }
392
+ type PlacedView<Parent, ParentMessage, ViewInputs> = [ViewInputs] extends [void] ? <H extends HtmlBuilder<any>>(parent: Parent, h: ViewBuilder<H, ParentMessage>) => Html : <H extends HtmlBuilder<any>>(parent: Parent, h: ViewBuilder<H, ParentMessage>, viewInputs: ViewInputs) => Html;
393
+ /** A readable type error: intersected onto a parameter, its message names the fix. */
394
+ interface Invalid<Message extends string> {
395
+ readonly invalid: Message;
396
+ }
397
+ type BuilderMessage<H> = H extends HtmlBuilder<infer M> ? M : never;
398
+ /**
399
+ * The parent's `h`, checked to accept this placement's Messages. Generic over the
400
+ * whole builder rather than its Message: inferring a Message through
401
+ * `HtmlBuilder` costs thousands of type instantiations per call, while the
402
+ * builder infers as itself and its Message is extracted once per builder type.
403
+ */
404
+ type ViewBuilder<H, ParentMessage> = H & ([ParentMessage] extends [BuilderMessage<H>] ? unknown : Invalid<"The parent Message does not include this placement's wrapper variant; spread its Link.wrapper(...).cases into defineMessageUnion">);
405
+ //#endregion
406
+ //#region ../bundle/src/collection.d.ts
407
+ declare const PlacedCollectionTypeId: unique symbol;
408
+ interface EachConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key extends string = string> {
409
+ /** The args every item's `init` and `update` receive. */
410
+ readonly args?: Args;
411
+ /** Handles an item's OutMessage in parent terms, with the item already written back. */
412
+ readonly onOut?: (outMessage: OutMessage, key: Key, context: Update.FoldContext<Message, LinkMessage>) => Update.Step<NoInfer<Parent>, OutStepMessage, R2>;
413
+ /** Prefix for the collection's Subscription keys. Defaults to `Name@path[]`. */
414
+ readonly key?: string;
415
+ readonly when?: (parent: Parent, key: Key) => boolean;
416
+ }
417
+ type CollectionView<Parent, ParentMessage, ViewInputs, Key extends string = string> = [ViewInputs] extends [void] ? <H extends HtmlBuilder<any>>(parent: Parent, h: ViewBuilder<H, ParentMessage>, key: Key) => Html : <H extends HtmlBuilder<any>>(parent: Parent, h: ViewBuilder<H, ParentMessage>, key: Key, viewInputs: ViewInputs) => Html;
418
+ type CollectionHelpers<Parent, ParentMessage, R, Helpers, Key extends string = string> = { readonly [K in keyof Helpers]: Helpers[K] extends ((model: any, ...input: infer Input) => any) ? (key: Key, ...input: Input) => Update.Step<Parent, ParentMessage, R> : never; };
419
+ interface PlacedCollection<Name extends string, Parent, ParentMessage, Model, Message, R, S, ViewInputs, Helpers, Field extends string = string, Key extends string = string> {
420
+ readonly [PlacedCollectionTypeId]: typeof PlacedCollectionTypeId;
421
+ /** Types only: the record field this collection owns, or `string` when unknown. */
422
+ readonly field?: Field;
423
+ readonly name: Name;
424
+ /** `Name@path[]`, or the configured `key`: the prefix of every Subscription key. */
425
+ readonly key: string;
426
+ /** The encoded args as text, when the bundle has an args Schema. */
427
+ readonly argsSummary: string | undefined;
428
+ readonly link: CollectionLink<Parent, ParentMessage, Model, Message, Key>;
429
+ /** Folds the Message into its item; `None` when it is not this collection's. A missing key leaves the parent unchanged. */
430
+ readonly update: (parent: Parent, message: AnyMessage) => Option.Option<Update.Return<Parent, ParentMessage, R>>;
431
+ /**
432
+ * Writes a new item from `init` and starts its Commands. `prepare` adjusts the
433
+ * initial Model first, for what only the parent knows, such as the item's id.
434
+ * An existing item is replaced.
435
+ */
436
+ readonly add: (key: Key, prepare?: (model: Model) => Model) => Update.Step<Parent, ParentMessage, R>;
437
+ /** Removes an item; its Subscriptions stop with it, and later Messages for it are ignored. */
438
+ readonly remove: (key: Key) => Update.Step<Parent, ParentMessage, never>;
439
+ readonly subscriptions: Subscription.Subscriptions<Parent, ParentMessage, S>;
440
+ /** One item's view; nothing when the key is missing. */
441
+ readonly view: CollectionView<Parent, ParentMessage, ViewInputs, Key>;
442
+ /** Every item's view, in the order of the Link's `entries`. */
443
+ readonly viewAll: <H extends HtmlBuilder<any>>(parent: Parent, h: ViewBuilder<H, ParentMessage>, ...viewInputs: [ViewInputs] extends [void] ? [] : [viewInputs: ViewInputs]) => ReadonlyArray<Html>;
444
+ readonly helpers: CollectionHelpers<Parent, ParentMessage, R, Helpers, Key>;
445
+ }
446
+ //#endregion
447
+ //#region ../bundle/src/bundle.d.ts
448
+ declare const BundleTypeId: unique symbol;
449
+ /** A child Managed Resource entry: its requirements are an `Option`, so the entry can release. */
450
+ type ResourceEntry<Model, Message> = ManagedResource.Entry<Model, Message, Option.Option<any>, any, any>;
451
+ type ResourceEntries<Model, Message> = Readonly<Record<string, ResourceEntry<Model, Message>>>;
452
+ /** A programmatic entry point, like `Dialog.open`: the child Model plus any input. */
453
+ type Helper<Model, Message, OutMessage, R> = (model: Model, ...input: ReadonlyArray<any>) => Update.ReturnWithOutMessage<Model, Message, OutMessage, R>;
454
+ interface BundleSpec<Name extends string, Args, Model, Message extends AnyMessage, OutMessage, R, S, ViewInputs, Resources extends ResourceEntries<Model, Message>, Helpers extends Readonly<Record<string, Helper<Model, Message, OutMessage, R>>>> {
455
+ readonly name: Name;
456
+ readonly Model: Schema.Codec<Model, unknown>;
457
+ readonly Message: Schema.Codec<Message, unknown>;
458
+ /**
459
+ * The args Schema. When given, `Args` is inferred from it, a placement's args
460
+ * are checked against it, and Module lists them.
461
+ */
462
+ readonly args?: Schema.Codec<Args, unknown>;
463
+ /** Set by `with`: the bound args, encoded as text, for Module. */
464
+ readonly preset?: string | undefined;
465
+ /** Runs when the bundle is placed; its Commands start with the placement. */
466
+ readonly init: (args: Args) => Update.Return<Model, Message, R>;
467
+ readonly update: (model: Model, message: Message, args: Args) => Update.ReturnWithOutMessage<Model, Message, OutMessage, R>;
468
+ readonly subscriptions?: (args: Args) => Subscription.Subscriptions<Model, Message, S>;
469
+ readonly resources?: (args: Args) => Resources;
470
+ readonly view?: Submodel.View<Model, Message, ViewInputs>;
471
+ readonly helpers?: Helpers;
472
+ }
473
+ interface Bundle$1<Name extends string, Args, Model, Message extends AnyMessage, OutMessage, R, S, ViewInputs, Resources extends ResourceEntries<Model, Message>, Helpers extends Readonly<Record<string, Helper<Model, Message, OutMessage, R>>>> extends BundleSpec<Name, Args, Model, Message, OutMessage, R, S, ViewInputs, Resources, Helpers>, Pipeable.Pipeable {
474
+ readonly [BundleTypeId]: typeof BundleTypeId;
475
+ /**
476
+ * A preset: the same bundle with its args bound, so placements need no `args`.
477
+ * The args are checked against the args Schema when there is one.
478
+ */
479
+ readonly with: (args: Args) => Bundle$1<Name, void, Model, Message, OutMessage, R, S, ViewInputs, Resources, Helpers>;
480
+ /** Places the bundle where `link` points. */
481
+ readonly at: <Parent, LinkMessage, OutStepMessage = never, R2 = never>(link: Link<Parent, LinkMessage, Model, Message>, ...config: PlaceConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2>) => Placed<Name, Parent, LinkMessage | OutStepMessage, Model, Message, R | R2, S, ViewInputs, Resources, Helpers>;
482
+ /** Places the bundle once per key of the collection `link` points at. */
483
+ readonly each: [keyof Resources] extends [never] ? <Parent, LinkMessage, Key extends string, OutStepMessage = never, R2 = never>(link: CollectionLink<Parent, LinkMessage, Model, Message, Key>, ...config: EachConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key>) => PlacedCollection<Name, Parent, LinkMessage | OutStepMessage, Model, Message, R | R2, S, ViewInputs, Helpers, string, Key> : Invalid<'Bundle.each does not support Managed Resources yet: the runtime provides a resource by one tag, so items would share it'>;
484
+ }
485
+ /**
486
+ * What placing needs: `args` when `init` takes them, and `onOut` when the
487
+ * bundle has an OutMessage, so an OutMessage is never dropped by omission.
488
+ */
489
+ type PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2> = {
490
+ /** Prefix for the placement's Subscription and resource keys. Defaults to `Name@path`. */
491
+ readonly key?: string;
492
+ /** A gate beside the Link's own: the child's Subscriptions and resources run only while both hold. */
493
+ readonly when?: (parent: Parent) => boolean;
494
+ } & ([Args] extends [void] ? {
495
+ readonly args?: never;
496
+ } : {
497
+ readonly args: Args;
498
+ }) & ([OutMessage] extends [never] ? {
499
+ readonly onOut?: never;
500
+ } : {
501
+ readonly onOut: Required<PlaceConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2>>['onOut'];
502
+ });
503
+ /** The config argument is optional only when it would be empty. */
504
+ type PlaceConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2> = [Args] extends [void] ? [OutMessage] extends [never] ? [config?: PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2>] : [config: PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2>] : [config: PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2>];
505
+ type EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key extends string = string> = {
506
+ readonly key?: string;
507
+ /** A gate per item beside the Link's own: an item's Subscriptions run only while both hold. */
508
+ readonly when?: (parent: Parent, key: Key) => boolean;
509
+ } & ([Args] extends [void] ? {
510
+ readonly args?: never;
511
+ } : {
512
+ readonly args: Args;
513
+ }) & ([OutMessage] extends [never] ? {
514
+ readonly onOut?: never;
515
+ } : {
516
+ readonly onOut: Required<EachConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key>>['onOut'];
517
+ });
518
+ type EachConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key extends string = string> = [Args] extends [void] ? [OutMessage] extends [never] ? [config?: EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key>] : [config: EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key>] : [config: EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key>];
519
+ //#endregion
520
+ //#region src/kinds.d.ts
521
+ interface StateWords {
522
+ readonly New?: string;
523
+ readonly Published?: string;
524
+ readonly Changed?: string;
525
+ readonly Unpublished?: string;
526
+ readonly Archived?: string;
527
+ readonly scheduled?: string;
528
+ readonly overdue?: string;
529
+ }
530
+ /** What `foldkit-mixins-form` gives a control's renderer, as far as these read it. */
531
+ interface ControlContext<Message> {
532
+ readonly control: Control;
533
+ readonly draft: Draft;
534
+ readonly change: (value: Draft) => Message;
535
+ readonly blurred: Message;
536
+ readonly state: ReadonlyArray<Attribute<Message>>;
537
+ readonly slots: {
538
+ readonly text: {
539
+ readonly attrs: (attrs: ReadonlyArray<any>) => any;
540
+ };
541
+ };
542
+ readonly h: HtmlBuilder<Message>;
543
+ }
544
+ /** What `foldkit-mixins-crud` gives a display's renderer, as far as these read it. */
545
+ interface DisplayContext<Message> {
546
+ readonly display: {
547
+ readonly kind: string;
548
+ readonly text: (value: unknown, words: any) => string;
549
+ };
550
+ readonly value: unknown;
551
+ readonly words: unknown;
552
+ readonly h: HtmlBuilder<Message>;
553
+ }
554
+ //#endregion
555
+ //#region src/index.d.ts
556
+ /** The members of an Entity that play a part a CMS knows: by key. */
557
+ export interface RoleKeys<E extends AnyEntity> {
558
+ /** What an entry is called in a list. A text field. */
559
+ readonly label?: TextKey<E>;
560
+ /** The address a visitor reaches it by. A text field, unique in its table. */
561
+ readonly slug?: TextKey<E>;
562
+ /**
563
+ * Present means a visitor may see the row. A field that admits `null`. Without
564
+ * it a content type cannot be unpublished, and every row is visible.
565
+ */
566
+ readonly published?: NullableKey<E>;
567
+ }
568
+ type TextKey<E extends AnyEntity> = { [K in keyof E['fields']]: [E['fields'][K]['schema']['Type']] extends [string] ? K : never; }[keyof E['fields']] & string;
569
+ type NullableKey<E extends AnyEntity> = { [K in keyof E['fields']]: null extends E['fields'][K]['schema']['Type'] ? K : never; }[keyof E['fields']] & string;
570
+ /** The roles of an Entity, as its Fields. */
571
+ export interface Roles {
572
+ readonly label: EntityField<string, string, Schema.Constraint> | undefined;
573
+ readonly slug: EntityField<string, string, Schema.Constraint> | undefined;
574
+ readonly published: EntityField<string, string, Schema.Constraint> | undefined;
575
+ }
576
+ /** An entry's id. Branded, so an entry is not opened with a post's id. */
577
+ export declare const EntryId: Schema.brand<Schema.String, "CmsEntryId">;
578
+ export type EntryId = typeof EntryId.Type;
579
+ /** A form as a content type needs it: what it was made from, and what it edits. */
580
+ interface ContentForm<E extends AnyEntity, Value> {
581
+ readonly name: string;
582
+ readonly input: EntityInput<E, any, any>;
583
+ readonly bundle: {
584
+ readonly Model: Schema.Codec<any, unknown>;
585
+ };
586
+ readonly initial: unknown;
587
+ readonly engine: {
588
+ readonly value: (model: any) => Value | undefined;
589
+ };
590
+ }
591
+ /** How a type of content is authored: the application's facts, beside the Entity's roles. */
592
+ export interface Content<Name extends string, E extends AnyEntity, Value, TargetId extends string, F extends ContentForm<E, Value> = ContentForm<E, Value>> {
593
+ readonly name: Name;
594
+ readonly entity: E;
595
+ /** The form as it was given, so an editor of this content is typed by it. */
596
+ readonly form: F;
597
+ readonly publish: {
598
+ /** Makes the row, the first time. Its input is the form's value; its output names the row. */
599
+ readonly create: MutationDescriptor<string, Value, {
600
+ readonly id: TargetId;
601
+ }>;
602
+ /** Changes the row, every time after. Its input is the form's value and the row's id. */
603
+ readonly update: MutationDescriptor<string, Value & {
604
+ readonly id: TargetId;
605
+ }, any>;
606
+ };
607
+ readonly roles: Roles;
608
+ readonly words: {
609
+ readonly one: string;
610
+ readonly many: string;
611
+ };
612
+ /**
613
+ * How a value of the form would look in the store: the operations an optimistic
614
+ * publish of it would show. Declared, an author can preview what they have
615
+ * entered in the application's own views; not declared, there is no preview.
616
+ * `id` is the row's, or the entry's while there is no row yet.
617
+ */
618
+ readonly preview?: ((value: Partial<Value>, id: string) => ReadonlyArray<OptimisticOperation>) | undefined;
619
+ }
620
+ export declare const Cms: {
621
+ /**
622
+ * The authoring editor of a content type: its form, the entry, and the draft
623
+ * that keeps what the author has entered. Saving is automatic and is not
624
+ * publishing; publishing submits the form.
625
+ */
626
+ editor: <const Name extends string, FormModel, FormMessage extends {
627
+ readonly _tag: string;
628
+ }, Value>(name: Name, config: {
629
+ readonly content: EditorContent<FormModel, FormMessage, Value>;
630
+ readonly rest?: import("effect/Duration").Input;
631
+ readonly version?: string;
632
+ readonly untitled?: string;
633
+ }) => {
634
+ bundle: Bundle$1<Name, void, EditorModel<FormModel>, FormMessage | {
635
+ readonly _tag: "Rested";
636
+ readonly edit: number;
637
+ } | {
638
+ readonly _tag: "PublishAsked";
639
+ } | {
640
+ readonly _tag: "PreviewShown";
641
+ } | {
642
+ readonly _tag: "PreviewHidden";
643
+ } | {
644
+ readonly _tag: "ScheduleAsked";
645
+ readonly at: string;
646
+ } | {
647
+ readonly _tag: "UnscheduleAsked";
648
+ } | {
649
+ readonly _tag: "ArchiveAsked";
650
+ } | {
651
+ readonly _tag: "UnarchiveAsked";
652
+ } | {
653
+ readonly _tag: "DiscardAsked";
654
+ } | {
655
+ readonly _tag: "RestoreAsked";
656
+ readonly revision: number;
657
+ } | {
658
+ readonly _tag: "UnpublishAsked";
659
+ } | {
660
+ readonly _tag: "ReloadAsked";
661
+ } | {
662
+ readonly _tag: "OverwriteAsked";
663
+ }, EditorOut, any, never, void, {}, {
664
+ open: (_: EditorModel<FormModel>, entry: string) => {
665
+ model: {
666
+ mode: "edit";
667
+ entry: string;
668
+ form: FormModel;
669
+ filled: boolean;
670
+ resumed: Resumed | null;
671
+ edits: number;
672
+ savedEdit: number;
673
+ saveId: string | null;
674
+ saveWanted: boolean;
675
+ publishId: string | null;
676
+ publishWanted: boolean;
677
+ scheduleAt: string | null;
678
+ otherId: string | null;
679
+ previewing: boolean;
680
+ previewedAs: string | null;
681
+ settling: "reload" | "overwrite" | null;
682
+ };
683
+ };
684
+ create: (_: EditorModel<FormModel>, entry: string) => {
685
+ model: {
686
+ mode: "new";
687
+ entry: string;
688
+ filled: boolean;
689
+ resumed: "Blank";
690
+ form: FormModel;
691
+ edits: number;
692
+ savedEdit: number;
693
+ saveId: string | null;
694
+ saveWanted: boolean;
695
+ publishId: string | null;
696
+ publishWanted: boolean;
697
+ scheduleAt: string | null;
698
+ otherId: string | null;
699
+ previewing: boolean;
700
+ previewedAs: string | null;
701
+ settling: "reload" | "overwrite" | null;
702
+ };
703
+ };
704
+ close: () => {
705
+ model: EditorModel<FormModel>;
706
+ };
707
+ }>;
708
+ Message: import("foldkit/message").MessageUnion<{
709
+ readonly Rested: {
710
+ readonly edit: Schema.Number;
711
+ };
712
+ readonly PublishAsked: {};
713
+ readonly PreviewShown: {};
714
+ readonly PreviewHidden: {};
715
+ readonly ScheduleAsked: {
716
+ readonly at: Schema.String;
717
+ };
718
+ readonly UnscheduleAsked: {};
719
+ readonly ArchiveAsked: {};
720
+ readonly UnarchiveAsked: {};
721
+ readonly DiscardAsked: {};
722
+ readonly RestoreAsked: {
723
+ readonly revision: Schema.Number;
724
+ };
725
+ readonly UnpublishAsked: {};
726
+ readonly ReloadAsked: {};
727
+ readonly OverwriteAsked: {};
728
+ }>;
729
+ formTag: string;
730
+ at: <Root>(where: {
731
+ readonly data: EditorDomain<Root>;
732
+ readonly model: import("foldkit-surface").ModelRef<Root, EditorModel<FormModel>>;
733
+ }) => {
734
+ onOut: (out: EditorOut) => import("foldkit/update").Step<Root, import("foldkit-remote").RemoteMessage, import("foldkit-remote").RemoteClient>;
735
+ actives: Readonly<Record<`${Name}.${"entry" | "state" | "draft" | "row"}`, import("foldkit-surface").ActiveSurface<Root>>>;
736
+ sync: import("foldkit/update").Step<Root, import("foldkit-remote").RemoteMessage, import("foldkit-remote").RemoteClient>;
737
+ flush: (root: Root) => Readonly<{
738
+ model: Root;
739
+ commands?: import("foldkit/update").Commands<import("foldkit-remote").RemoteMessage, import("foldkit-remote").RemoteClient>;
740
+ outMessage?: never;
741
+ }>;
742
+ after: <Message, Result extends {
743
+ readonly model: Root;
744
+ readonly commands?: ReadonlyArray<any>;
745
+ }>(update: (model: Root, message: Message) => Result) => (model: Root, message: Message) => Result;
746
+ canPreview: boolean;
747
+ previewing: (root: Root) => boolean;
748
+ pageId: (root: Root) => string | null;
749
+ entry: (root: Root) => string | null;
750
+ resumed: (root: Root) => Resumed | null;
751
+ state: (root: Root) => State | undefined;
752
+ error: (root: Root) => import("foldkit-remote").RemoteError | undefined;
753
+ status: (root: Root) => EditorStatus;
754
+ };
755
+ };
756
+ /** A form's Submodel view as its editor's, for `Bundle.withView`. */
757
+ editorView: <FormModel, FormMessage, ViewInputs>(view: import("foldkit/submodel").View<FormModel, FormMessage, ViewInputs>) => import("foldkit/submodel").View<EditorModel<FormModel>, FormMessage | EditorMessage, ViewInputs>;
758
+ /** The state of an entry, from what is known of it and a clock. */
759
+ state: (facts: Facts, now: Date) => State;
760
+ /** The transitions an entry offers now, before anyone asks who is asking. */
761
+ offers: (facts: Facts, now: Date, content: {
762
+ readonly roles: Roles;
763
+ }) => ReadonlyArray<Transition>;
764
+ Input: {
765
+ Slug: import("foldkit-form").ControlKind<{
766
+ readonly prefix: string;
767
+ }>;
768
+ DateTime: import("foldkit-form").ControlKind<Record<string, never>>;
769
+ };
770
+ Display: {
771
+ State: import("foldkit-crud").DisplayKind<{
772
+ readonly words?: StateWords | undefined;
773
+ }>;
774
+ Moment: import("foldkit-crud").DisplayKind<{
775
+ readonly now?: (() => Date) | undefined;
776
+ readonly locale?: string | undefined;
777
+ }>;
778
+ };
779
+ slugify: (text: string) => string;
780
+ slug: (from: string, options?: {
781
+ readonly prefix?: string;
782
+ readonly through?: (text: string) => string;
783
+ }) => import("foldkit-form").ControlChange;
784
+ dateTime: () => import("foldkit-form").Control;
785
+ controlRenderers: <Message>() => Readonly<Record<string, (context: ControlContext<Message>) => import("foldkit/html").Html>>;
786
+ displayRenderers: <Message>() => Readonly<Record<string, (context: DisplayContext<Message>) => import("foldkit/html").Html>>;
787
+ /**
788
+ * A pipe step naming the members of an Entity that play a CMS part. It is
789
+ * metadata: the Entity is the same Entity, and anything may read it with
790
+ * `Cms.rolesOf`. A member that cannot play the part is refused here.
791
+ */
792
+ roles: <E extends AnyEntity>(roles: RoleKeys<NoInfer<E>>) => (entity: E) => E;
793
+ /** The roles an Entity was given, as its Fields. A part nobody named is `undefined`. */
794
+ rolesOf: (entity: AnyEntity) => Roles;
795
+ /**
796
+ * A type of content: the Entity it is, the form that edits it, the operations
797
+ * that publish it, and what it is called. The form is an ordinary form; the
798
+ * operations are the application's own. It adds no fields and generates nothing.
799
+ */
800
+ content: <const Name extends string, E extends AnyEntity, Value, TargetId extends string = string, F extends ContentForm<NoInfer<E>, Value> = ContentForm<NoInfer<E>, Value>>(name: Name, config: {
801
+ readonly entity: E;
802
+ readonly form: F & ContentForm<NoInfer<E>, Value>;
803
+ readonly publish: Content<Name, E, NoInfer<Value>, TargetId>["publish"];
804
+ readonly words: {
805
+ readonly one: string;
806
+ readonly many: string;
807
+ };
808
+ readonly preview?: Content<Name, E, NoInfer<Value>, TargetId>["preview"];
809
+ }) => Content<Name, E, Value, TargetId, F>;
810
+ /** An id for something new, made where it is written: the first save of it makes the entry. */
811
+ newEntryId: () => EntryId;
812
+ /** `Entry`, `Draft` and `Revision`: register them with Remote beside the application's own. */
813
+ Entities: {
814
+ readonly Entry: Entity<"CmsEntry", {
815
+ readonly id: Schema.brand<Schema.String, "CmsEntryId">;
816
+ /** The content type's name: `Cms.content('posts', ...)`. */
817
+ readonly type: Schema.String;
818
+ /** The content row's id, once there is one. */
819
+ readonly targetId: Schema.NullOr<Schema.String>;
820
+ readonly label: Schema.String;
821
+ readonly createdAt: Schema.String;
822
+ readonly archivedAt: Schema.NullOr<Schema.String>;
823
+ /** The number of the latest published revision: what the next publish is based on. */
824
+ readonly revision: Schema.NullOr<Schema.Number>;
825
+ }, import("foldkit-entity").RelatedSpecs<{
826
+ readonly Entry: Entity<"CmsEntry", {
827
+ readonly id: Schema.brand<Schema.String, "CmsEntryId">;
828
+ /** The content type's name: `Cms.content('posts', ...)`. */
829
+ readonly type: Schema.String;
830
+ /** The content row's id, once there is one. */
831
+ readonly targetId: Schema.NullOr<Schema.String>;
832
+ readonly label: Schema.String;
833
+ readonly createdAt: Schema.String;
834
+ readonly archivedAt: Schema.NullOr<Schema.String>;
835
+ /** The number of the latest published revision: what the next publish is based on. */
836
+ readonly revision: Schema.NullOr<Schema.Number>;
837
+ }, {}, {
838
+ readonly state: import("foldkit-entity").DerivedSpec<Schema.Struct<{
839
+ readonly _tag: Schema.Literals<readonly ["New", "Published", "Changed", "Unpublished", "Archived"]>;
840
+ readonly schedule: Schema.NullOr<Schema.Struct<{
841
+ readonly at: Schema.String;
842
+ readonly overdue: Schema.Boolean;
843
+ readonly error: Schema.NullOr<Schema.String>;
844
+ }>>;
845
+ }>>;
846
+ }>;
847
+ readonly Draft: Entity<"CmsDraft", {
848
+ /** The entry's id: an entry has at most one draft. */
849
+ readonly id: Schema.brand<Schema.String, "CmsEntryId">;
850
+ /** The keys of the form's value that decode, as the operation's input encodes them. */
851
+ readonly values: Schema.Unknown;
852
+ /** The form's whole Model, encoded: what resumes unfinished work. */
853
+ readonly model: Schema.Unknown;
854
+ /** Which form made it, and at which version, so a Model is only resumed by the form that wrote it. */
855
+ readonly form: Schema.String;
856
+ readonly updatedAt: Schema.String;
857
+ readonly updatedBy: Schema.NullOr<Schema.String>;
858
+ /** The revision this draft was started from; publishing over a newer one is a conflict. */
859
+ readonly baseRevision: Schema.NullOr<Schema.Number>;
860
+ readonly scheduledFor: Schema.NullOr<Schema.String>;
861
+ readonly scheduleError: Schema.NullOr<Schema.String>;
862
+ }, {}, {}>;
863
+ readonly Revision: Entity<"CmsRevision", {
864
+ readonly id: Schema.String;
865
+ readonly n: Schema.Number;
866
+ readonly values: Schema.Unknown;
867
+ readonly publishedAt: Schema.String;
868
+ readonly publishedBy: Schema.NullOr<Schema.String>;
869
+ }, {}, {}>;
870
+ }, {
871
+ readonly Entry: {
872
+ readonly draft: import("foldkit-entity").RelationSpec<Entity<"CmsDraft", {
873
+ /** The entry's id: an entry has at most one draft. */
874
+ readonly id: Schema.brand<Schema.String, "CmsEntryId">;
875
+ /** The keys of the form's value that decode, as the operation's input encodes them. */
876
+ readonly values: Schema.Unknown;
877
+ /** The form's whole Model, encoded: what resumes unfinished work. */
878
+ readonly model: Schema.Unknown;
879
+ /** Which form made it, and at which version, so a Model is only resumed by the form that wrote it. */
880
+ readonly form: Schema.String;
881
+ readonly updatedAt: Schema.String;
882
+ readonly updatedBy: Schema.NullOr<Schema.String>;
883
+ /** The revision this draft was started from; publishing over a newer one is a conflict. */
884
+ readonly baseRevision: Schema.NullOr<Schema.Number>;
885
+ readonly scheduledFor: Schema.NullOr<Schema.String>;
886
+ readonly scheduleError: Schema.NullOr<Schema.String>;
887
+ }, {}, {}>, "one", true>;
888
+ readonly revisions: import("foldkit-entity").RelationSpec<Entity<"CmsRevision", {
889
+ readonly id: Schema.String;
890
+ readonly n: Schema.Number;
891
+ readonly values: Schema.Unknown;
892
+ readonly publishedAt: Schema.String;
893
+ readonly publishedBy: Schema.NullOr<Schema.String>;
894
+ }, {}, {}>, "many", false>;
895
+ };
896
+ }, "Entry">, {
897
+ readonly state: import("foldkit-entity").DerivedSpec<Schema.Struct<{
898
+ readonly _tag: Schema.Literals<readonly ["New", "Published", "Changed", "Unpublished", "Archived"]>;
899
+ readonly schedule: Schema.NullOr<Schema.Struct<{
900
+ readonly at: Schema.String;
901
+ readonly overdue: Schema.Boolean;
902
+ readonly error: Schema.NullOr<Schema.String>;
903
+ }>>;
904
+ }>>;
905
+ }>;
906
+ readonly Draft: Entity<"CmsDraft", {
907
+ /** The entry's id: an entry has at most one draft. */
908
+ readonly id: Schema.brand<Schema.String, "CmsEntryId">;
909
+ /** The keys of the form's value that decode, as the operation's input encodes them. */
910
+ readonly values: Schema.Unknown;
911
+ /** The form's whole Model, encoded: what resumes unfinished work. */
912
+ readonly model: Schema.Unknown;
913
+ /** Which form made it, and at which version, so a Model is only resumed by the form that wrote it. */
914
+ readonly form: Schema.String;
915
+ readonly updatedAt: Schema.String;
916
+ readonly updatedBy: Schema.NullOr<Schema.String>;
917
+ /** The revision this draft was started from; publishing over a newer one is a conflict. */
918
+ readonly baseRevision: Schema.NullOr<Schema.Number>;
919
+ readonly scheduledFor: Schema.NullOr<Schema.String>;
920
+ readonly scheduleError: Schema.NullOr<Schema.String>;
921
+ }, import("foldkit-entity").RelatedSpecs<{
922
+ readonly Entry: Entity<"CmsEntry", {
923
+ readonly id: Schema.brand<Schema.String, "CmsEntryId">;
924
+ /** The content type's name: `Cms.content('posts', ...)`. */
925
+ readonly type: Schema.String;
926
+ /** The content row's id, once there is one. */
927
+ readonly targetId: Schema.NullOr<Schema.String>;
928
+ readonly label: Schema.String;
929
+ readonly createdAt: Schema.String;
930
+ readonly archivedAt: Schema.NullOr<Schema.String>;
931
+ /** The number of the latest published revision: what the next publish is based on. */
932
+ readonly revision: Schema.NullOr<Schema.Number>;
933
+ }, {}, {
934
+ readonly state: import("foldkit-entity").DerivedSpec<Schema.Struct<{
935
+ readonly _tag: Schema.Literals<readonly ["New", "Published", "Changed", "Unpublished", "Archived"]>;
936
+ readonly schedule: Schema.NullOr<Schema.Struct<{
937
+ readonly at: Schema.String;
938
+ readonly overdue: Schema.Boolean;
939
+ readonly error: Schema.NullOr<Schema.String>;
940
+ }>>;
941
+ }>>;
942
+ }>;
943
+ readonly Draft: Entity<"CmsDraft", {
944
+ /** The entry's id: an entry has at most one draft. */
945
+ readonly id: Schema.brand<Schema.String, "CmsEntryId">;
946
+ /** The keys of the form's value that decode, as the operation's input encodes them. */
947
+ readonly values: Schema.Unknown;
948
+ /** The form's whole Model, encoded: what resumes unfinished work. */
949
+ readonly model: Schema.Unknown;
950
+ /** Which form made it, and at which version, so a Model is only resumed by the form that wrote it. */
951
+ readonly form: Schema.String;
952
+ readonly updatedAt: Schema.String;
953
+ readonly updatedBy: Schema.NullOr<Schema.String>;
954
+ /** The revision this draft was started from; publishing over a newer one is a conflict. */
955
+ readonly baseRevision: Schema.NullOr<Schema.Number>;
956
+ readonly scheduledFor: Schema.NullOr<Schema.String>;
957
+ readonly scheduleError: Schema.NullOr<Schema.String>;
958
+ }, {}, {}>;
959
+ readonly Revision: Entity<"CmsRevision", {
960
+ readonly id: Schema.String;
961
+ readonly n: Schema.Number;
962
+ readonly values: Schema.Unknown;
963
+ readonly publishedAt: Schema.String;
964
+ readonly publishedBy: Schema.NullOr<Schema.String>;
965
+ }, {}, {}>;
966
+ }, {
967
+ readonly Entry: {
968
+ readonly draft: import("foldkit-entity").RelationSpec<Entity<"CmsDraft", {
969
+ /** The entry's id: an entry has at most one draft. */
970
+ readonly id: Schema.brand<Schema.String, "CmsEntryId">;
971
+ /** The keys of the form's value that decode, as the operation's input encodes them. */
972
+ readonly values: Schema.Unknown;
973
+ /** The form's whole Model, encoded: what resumes unfinished work. */
974
+ readonly model: Schema.Unknown;
975
+ /** Which form made it, and at which version, so a Model is only resumed by the form that wrote it. */
976
+ readonly form: Schema.String;
977
+ readonly updatedAt: Schema.String;
978
+ readonly updatedBy: Schema.NullOr<Schema.String>;
979
+ /** The revision this draft was started from; publishing over a newer one is a conflict. */
980
+ readonly baseRevision: Schema.NullOr<Schema.Number>;
981
+ readonly scheduledFor: Schema.NullOr<Schema.String>;
982
+ readonly scheduleError: Schema.NullOr<Schema.String>;
983
+ }, {}, {}>, "one", true>;
984
+ readonly revisions: import("foldkit-entity").RelationSpec<Entity<"CmsRevision", {
985
+ readonly id: Schema.String;
986
+ readonly n: Schema.Number;
987
+ readonly values: Schema.Unknown;
988
+ readonly publishedAt: Schema.String;
989
+ readonly publishedBy: Schema.NullOr<Schema.String>;
990
+ }, {}, {}>, "many", false>;
991
+ };
992
+ }, "Draft">, {}>;
993
+ readonly Revision: Entity<"CmsRevision", {
994
+ readonly id: Schema.String;
995
+ readonly n: Schema.Number;
996
+ readonly values: Schema.Unknown;
997
+ readonly publishedAt: Schema.String;
998
+ readonly publishedBy: Schema.NullOr<Schema.String>;
999
+ }, import("foldkit-entity").RelatedSpecs<{
1000
+ readonly Entry: Entity<"CmsEntry", {
1001
+ readonly id: Schema.brand<Schema.String, "CmsEntryId">;
1002
+ /** The content type's name: `Cms.content('posts', ...)`. */
1003
+ readonly type: Schema.String;
1004
+ /** The content row's id, once there is one. */
1005
+ readonly targetId: Schema.NullOr<Schema.String>;
1006
+ readonly label: Schema.String;
1007
+ readonly createdAt: Schema.String;
1008
+ readonly archivedAt: Schema.NullOr<Schema.String>;
1009
+ /** The number of the latest published revision: what the next publish is based on. */
1010
+ readonly revision: Schema.NullOr<Schema.Number>;
1011
+ }, {}, {
1012
+ readonly state: import("foldkit-entity").DerivedSpec<Schema.Struct<{
1013
+ readonly _tag: Schema.Literals<readonly ["New", "Published", "Changed", "Unpublished", "Archived"]>;
1014
+ readonly schedule: Schema.NullOr<Schema.Struct<{
1015
+ readonly at: Schema.String;
1016
+ readonly overdue: Schema.Boolean;
1017
+ readonly error: Schema.NullOr<Schema.String>;
1018
+ }>>;
1019
+ }>>;
1020
+ }>;
1021
+ readonly Draft: Entity<"CmsDraft", {
1022
+ /** The entry's id: an entry has at most one draft. */
1023
+ readonly id: Schema.brand<Schema.String, "CmsEntryId">;
1024
+ /** The keys of the form's value that decode, as the operation's input encodes them. */
1025
+ readonly values: Schema.Unknown;
1026
+ /** The form's whole Model, encoded: what resumes unfinished work. */
1027
+ readonly model: Schema.Unknown;
1028
+ /** Which form made it, and at which version, so a Model is only resumed by the form that wrote it. */
1029
+ readonly form: Schema.String;
1030
+ readonly updatedAt: Schema.String;
1031
+ readonly updatedBy: Schema.NullOr<Schema.String>;
1032
+ /** The revision this draft was started from; publishing over a newer one is a conflict. */
1033
+ readonly baseRevision: Schema.NullOr<Schema.Number>;
1034
+ readonly scheduledFor: Schema.NullOr<Schema.String>;
1035
+ readonly scheduleError: Schema.NullOr<Schema.String>;
1036
+ }, {}, {}>;
1037
+ readonly Revision: Entity<"CmsRevision", {
1038
+ readonly id: Schema.String;
1039
+ readonly n: Schema.Number;
1040
+ readonly values: Schema.Unknown;
1041
+ readonly publishedAt: Schema.String;
1042
+ readonly publishedBy: Schema.NullOr<Schema.String>;
1043
+ }, {}, {}>;
1044
+ }, {
1045
+ readonly Entry: {
1046
+ readonly draft: import("foldkit-entity").RelationSpec<Entity<"CmsDraft", {
1047
+ /** The entry's id: an entry has at most one draft. */
1048
+ readonly id: Schema.brand<Schema.String, "CmsEntryId">;
1049
+ /** The keys of the form's value that decode, as the operation's input encodes them. */
1050
+ readonly values: Schema.Unknown;
1051
+ /** The form's whole Model, encoded: what resumes unfinished work. */
1052
+ readonly model: Schema.Unknown;
1053
+ /** Which form made it, and at which version, so a Model is only resumed by the form that wrote it. */
1054
+ readonly form: Schema.String;
1055
+ readonly updatedAt: Schema.String;
1056
+ readonly updatedBy: Schema.NullOr<Schema.String>;
1057
+ /** The revision this draft was started from; publishing over a newer one is a conflict. */
1058
+ readonly baseRevision: Schema.NullOr<Schema.Number>;
1059
+ readonly scheduledFor: Schema.NullOr<Schema.String>;
1060
+ readonly scheduleError: Schema.NullOr<Schema.String>;
1061
+ }, {}, {}>, "one", true>;
1062
+ readonly revisions: import("foldkit-entity").RelationSpec<Entity<"CmsRevision", {
1063
+ readonly id: Schema.String;
1064
+ readonly n: Schema.Number;
1065
+ readonly values: Schema.Unknown;
1066
+ readonly publishedAt: Schema.String;
1067
+ readonly publishedBy: Schema.NullOr<Schema.String>;
1068
+ }, {}, {}>, "many", false>;
1069
+ };
1070
+ }, "Revision">, {}>;
1071
+ };
1072
+ /** The operations, to register with Remote's `mutations`. */
1073
+ Operations: {
1074
+ /**
1075
+ * Saves the working copy, valid or not. The first save of an id nobody has
1076
+ * makes the entry, so a client names something new itself (`Cms.newEntryId`) and
1077
+ * need not wait to be told what it is called. `basedOn` is the `updatedAt` this
1078
+ * save was made from: a newer one on the server is a conflict, not an overwrite.
1079
+ */
1080
+ SaveDraft: MutationDescriptor<"CmsSaveDraft", {
1081
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1082
+ readonly type: string;
1083
+ readonly label: string;
1084
+ readonly values: unknown;
1085
+ readonly model: unknown;
1086
+ readonly form: string;
1087
+ readonly basedOn: string | null;
1088
+ }, {
1089
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1090
+ readonly updatedAt: string;
1091
+ }>;
1092
+ DiscardDraft: MutationDescriptor<"CmsDiscardDraft", {
1093
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1094
+ }, {}>;
1095
+ /**
1096
+ * Publishes the saved draft through the content type's own mutation. `basedOn`
1097
+ * is the revision the draft was started from.
1098
+ */
1099
+ Publish: MutationDescriptor<"CmsPublish", {
1100
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1101
+ readonly basedOn: number | null;
1102
+ }, {
1103
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1104
+ readonly targetId: string;
1105
+ readonly revision: number;
1106
+ }>;
1107
+ Unpublish: MutationDescriptor<"CmsUnpublish", {
1108
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1109
+ }, {}>;
1110
+ Schedule: MutationDescriptor<"CmsSchedule", {
1111
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1112
+ readonly at: string;
1113
+ }, {}>;
1114
+ Unschedule: MutationDescriptor<"CmsUnschedule", {
1115
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1116
+ }, {}>;
1117
+ Archive: MutationDescriptor<"CmsArchive", {
1118
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1119
+ }, {}>;
1120
+ Unarchive: MutationDescriptor<"CmsUnarchive", {
1121
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1122
+ }, {}>;
1123
+ /** Makes a revision's value the working copy. It publishes nothing. */
1124
+ Restore: MutationDescriptor<"CmsRestore", {
1125
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1126
+ readonly revision: number;
1127
+ }, {
1128
+ readonly updatedAt: string;
1129
+ }>;
1130
+ };
1131
+ operations: (MutationDescriptor<"CmsSaveDraft", {
1132
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1133
+ readonly type: string;
1134
+ readonly label: string;
1135
+ readonly values: unknown;
1136
+ readonly model: unknown;
1137
+ readonly form: string;
1138
+ readonly basedOn: string | null;
1139
+ }, {
1140
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1141
+ readonly updatedAt: string;
1142
+ }> | MutationDescriptor<"CmsDiscardDraft", {
1143
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1144
+ }, {}> | MutationDescriptor<"CmsPublish", {
1145
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1146
+ readonly basedOn: number | null;
1147
+ }, {
1148
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1149
+ readonly targetId: string;
1150
+ readonly revision: number;
1151
+ }> | MutationDescriptor<"CmsUnpublish", {
1152
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1153
+ }, {}> | MutationDescriptor<"CmsSchedule", {
1154
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1155
+ readonly at: string;
1156
+ }, {}> | MutationDescriptor<"CmsUnschedule", {
1157
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1158
+ }, {}> | MutationDescriptor<"CmsArchive", {
1159
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1160
+ }, {}> | MutationDescriptor<"CmsUnarchive", {
1161
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1162
+ }, {}> | MutationDescriptor<"CmsRestore", {
1163
+ readonly entry: string & import("effect/Brand").Brand<"CmsEntryId">;
1164
+ readonly revision: number;
1165
+ }, {
1166
+ readonly updatedAt: string;
1167
+ }>)[];
1168
+ /** The worklist query, to register with Remote's `queries` and list with `Crud.list`. */
1169
+ Entries: import("foldkit-remote").QueryDescriptor<"CmsEntries", {
1170
+ readonly type: string;
1171
+ readonly search: string;
1172
+ readonly archived: boolean;
1173
+ }, import("foldkit-remote").ConnectionSpec<"CmsEntry">>;
1174
+ /**
1175
+ * The query that finds a piece of content by its address: `<name>BySlug`, a
1176
+ * connection of one or none. It throws for a content type with no `slug` role:
1177
+ * a capability is declared, never implied.
1178
+ */
1179
+ bySlug: <Name extends string, E extends AnyEntity>(content: Content<Name, E, any, any, any>) => import("foldkit-remote").QueryDescriptor<`${Name}BySlug`, {
1180
+ readonly slug: string;
1181
+ }, import("foldkit-remote").ResultOf<E>>;
1182
+ /**
1183
+ * How a server says a slug is taken, as a mutation's error: `CmsSlugTaken: <key>: ...`.
1184
+ * `slugTaken.key(message)` is the form key it names, or `undefined` for another error.
1185
+ */
1186
+ slugTaken: {
1187
+ message: (key: string, slug: string) => string;
1188
+ key: (message: string) => string | undefined;
1189
+ reason: (message: string) => string;
1190
+ };
1191
+ /**
1192
+ * A form check that asks, while the author types, whether an address is already
1193
+ * used: `checks: { slug: Cms.addressFree('posts') }`. Named by the content type,
1194
+ * so a form can be made with it before the content type exists. It needs that
1195
+ * type's `bySlug` query registered, which `CmsServer` does for a content type
1196
+ * with a slug role.
1197
+ */
1198
+ addressFree: (content: string) => ((slug: string, context: {
1199
+ readonly subject: Readonly<Record<string, string>>;
1200
+ }) => import("effect/Effect").Effect<string | undefined, never, import("foldkit-remote").RemoteClient>);
1201
+ };
1202
+ //#endregion
1203
+ export type { ControlContext, DisplayContext, EditorContent, EditorDomain, EditorForm, EditorMessage, EditorModel, EditorOut, EditorStatus, Facts, Resumed, Schedule, State, StateTag, StateWords, Transition };
1204
+ //# sourceMappingURL=index.d.mts.map