tablo-core 0.10.0

The core toolkit types for Tablo, a server-rendered admin toolkit on Topcoat and Toasty.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
//! [`DeclarationErrorKind`]: every mistake a declaration can hold.

use super::{
    ActionInputFault, AreaFault, AuthMailFault, EditableColumnFault, FieldAccessFault,
    FieldRuleFault, LocaleFault, ManyToManyFault, OidcFault, PolicyFault, ProfileFault,
    RelatedFormFault, ResetFault, SegmentFault, SignUpFault, TenancyFault, TenantProfileFault,
    TenantRegistrationFault, TwoFactorFault, VerificationFault,
};

/// What is wrong with a declaration.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeclarationErrorKind {
    /// The router holds no `toasty::Db`.
    ///
    /// Call `.with(db)` before `.panel(..)`.
    MissingDb,
    /// Auth is on, but the `Db` does not register the shipped models it needs: `AuthSession`,
    /// `AdminUser` for the shipped authenticator, `ColumnPreference` while a list has a
    /// toggleable column, `AuthToken` for a feature that mails links or two-factor sign-in, and
    /// `AuthFactor` for two-factor sign-in.
    ///
    /// Build the `Db` from `tablo::models!(..)`, add them to `toasty::models!(..)`, or opt out
    /// with `.auth(Auth::disabled())`.
    MissingAuthModels {
        /// The unregistered models.
        models: Vec<&'static str>,
    },
    /// `Panel::shell_assets` is set, but the router has no asset bundle.
    ///
    /// Call `.assets(..)` before `.panel(..)`.
    ShellAssetsWithoutBundle,
    /// `Panel::notifications` on `Auth::disabled`, which signs nobody in to notify.
    NotificationsWithoutAuth,
    /// `Panel::audit_log` over a `Db` that does not register `AuditEntry`, so every write would
    /// fail to store its entry.
    ///
    /// Build the `Db` from `tablo::models!(..)`, or add `AuditEntry` to `toasty::models!(..)`.
    MissingAuditModel,
    /// A `Brand` color that is no hex color or plain color function, which the panel's stylesheet
    /// would carry as it is.
    ///
    /// Spell it `#4f46e5` or `oklch(0.55 0.2 260)`.
    BrandColor {
        /// The refused value.
        value: String,
    },
    /// `Auth::external` beside a feature that needs Tablo to own the account's credentials.
    ///
    /// Drop the feature: the host app signs its users in, and keeps their credentials.
    ExternalAuthFeature {
        /// The builder call the panel may not declare.
        feature: &'static str,
    },
    /// A form declares a file field, but the panel installs no `Uploader` to store its bytes.
    ///
    /// Install one with `Panel::uploads` or `Panel::uploads_dir`.
    FileFieldWithoutUploader {
        /// The file field's name.
        field: String,
    },
    /// A path segment the panel routes cannot be a literal URL segment.
    ///
    /// Pick a plain segment such as `blog-posts`.
    InvalidSegment {
        /// What names the segment: `panel prefix`, `ResourceDef::slug` or `PageDef::slug`.
        item: &'static str,
        /// The refused segment.
        segment: String,
        /// Why it is refused.
        fault: SegmentFault,
    },
    /// The prefix overlaps Topcoat's runtime endpoints.
    ///
    /// Pick another prefix.
    PrefixOverlapsRuntime {
        /// The panel's prefix.
        prefix: String,
    },
    /// The prefix overlaps another panel's.
    ///
    /// Give each panel a prefix of its own.
    PrefixOverlapsPanel {
        /// The other panel's prefix.
        other: String,
    },
    /// A `Panel::endpoint` route outside Topcoat's runtime endpoints.
    ///
    /// Declare only shards and procedures; the panel's prefix guards its other routes.
    EndpointOutsideRuntime {
        /// The route's path.
        path: String,
    },
    /// A `Panel::serve_dir` pattern that does not end in a catch-all.
    ///
    /// End it in `{*file}`: `/uploads/{*file}`.
    ServeDirWithoutCatchAll {
        /// The pattern.
        path: String,
    },
    /// The panel serves the same directory pattern twice.
    ///
    /// Drop the second `serve_dir`.
    ServeDirTwice {
        /// The pattern.
        path: String,
    },
    /// Another panel already serves the directory pattern.
    ///
    /// Serve it from one panel.
    ServeDirTaken {
        /// The pattern.
        path: String,
        /// The serving panel's prefix.
        panel: String,
    },
    /// The panel's content security policy cannot be served.
    ContentSecurityPolicy(PolicyFault),
    /// A second `Panel::home` page.
    ///
    /// Keep one home page; register the other with `page`.
    SecondHome,
    /// Every resource declares [`without_navigation`](crate::ResourceDef::without_navigation) and
    /// the panel has no home page, so its root, where a sign-in lands, leads nowhere.
    ///
    /// Show one resource in the sidebar, or register a page with `Panel::home`.
    NoRoot,
    /// The resource is registered on the panel twice.
    ///
    /// Register it once; mount a variant under its own type.
    DuplicateResource,
    /// The page is registered on the panel twice, `Panel::home` included.
    ///
    /// Register it once; mount a variant under its own type.
    DuplicatePage,
    /// The resource is not mounted on the context's panel.
    ///
    /// It refuses no mount: a request answers 500 when app code asks for a resource its panel
    /// does not register, through [`wired_table`](crate::wired_table),
    /// [`scoped_query`](crate::scoped_query), [`write_create`](crate::write_create) or
    /// [`write_update`](crate::write_update). Register the resource on that panel, or reach it
    /// through a context of a panel that does.
    NotMounted,
    /// A slug naming a route the panel serves itself: `login`, `logout`, `register`, `profile`,
    /// `forgot-password`, `reset-password` or `-`.
    ///
    /// Rename it with `ResourceDef::slug` or `PageDef::slug`.
    ReservedSlug {
        /// The slug.
        slug: String,
    },
    /// A slug another resource or page already mounts at.
    ///
    /// Give each a distinct slug.
    DuplicateSlug {
        /// The slug.
        slug: String,
    },
    /// Two actions share a `NAME`.
    ///
    /// Rename one.
    DuplicateAction {
        /// The shared name.
        name: &'static str,
    },
    /// Two widgets of a page, or of a resource's list, share a name.
    ///
    /// Give one a distinct [`WidgetDef::name`](crate::WidgetDef::name).
    DuplicateWidget {
        /// The shared name.
        name: String,
    },
    /// A page's [filter](crate::PageFilter) shares its key with another, or its key is not a word
    /// a query parameter carries: ASCII letters, digits, `-` and `_`.
    ///
    /// Give each filter a distinct key of those characters.
    MisdeclaredPageFilter {
        /// The key.
        key: String,
    },
    /// A column cannot edit its field in a table's cell.
    EditableColumn {
        /// The column's name, which is its field's.
        column: String,
        /// What is wrong with it.
        fault: EditableColumnFault,
    },
    /// An action's input cannot be served.
    ActionInput {
        /// The action's `NAME`.
        action: &'static str,
        /// What is wrong with it.
        fault: ActionInputFault,
    },
    /// The panel's sign-up page cannot be served.
    SignUp(SignUpFault),
    /// The panel's profile page cannot be served.
    Profile(ProfileFault),
    /// An area cannot hold a page auth serves.
    Area(AreaFault),
    /// The panel's password reset cannot be served.
    PasswordReset(ResetFault),
    /// The panel's email verification cannot be served.
    EmailVerification(VerificationFault),
    /// The panel's tenant registration page cannot be served.
    TenantRegistration(TenantRegistrationFault),
    /// The panel's tenant settings page cannot be served.
    TenantProfile(TenantProfileFault),
    /// The panel's two-factor sign-in cannot be served.
    TwoFactor(TwoFactorFault),
    /// The panel's provider sign-in cannot be served.
    Oidc(OidcFault),
    /// The panel's auth mail cannot be sent.
    AuthMail(AuthMailFault),
    /// The panel's locales or translations cannot be served.
    Locale(LocaleFault),
    /// Two relations to the same resource.
    ///
    /// Keep one.
    DuplicateRelation,
    /// A relation to a resource the panel does not register.
    ///
    /// Register the related resource.
    UnregisteredRelation,
    /// A `has_one` relation declared as a tab: its form edits inside the record's own form.
    ///
    /// Drop `Relation::tab`.
    HasOneTab,
    /// A relationship field, or a relationship filter, whose options come from a resource the
    /// panel does not register.
    ///
    /// Register that resource.
    UnregisteredOptionSource {
        /// The field.
        field: String,
        /// The option source's type.
        source: &'static str,
    },
    /// A relation column labelling its records by a resource the panel does not register:
    /// `RelationColumn::{new, of, list}::<R>` or `CountColumn::of::<R>`.
    ///
    /// Register `R`, or use `RelationColumn::unscoped` for a model no resource administers.
    UnregisteredLabelSource {
        /// The column.
        column: String,
        /// The label source's type.
        source: &'static str,
    },
    /// A lens with more than one step where a single field of the model is needed.
    ///
    /// Name one field of the model.
    TraversalLens {
        /// The lens's step count.
        steps: usize,
    },
    /// A multi-step lens that resolves to no single column.
    ///
    /// Step only through embedded structs, enum variant fields and `#[document]` fields.
    UnresolvedLens {
        /// The lens's model.
        model: &'static str,
        /// The lens's field indices, step by step.
        steps: Vec<usize>,
    },
    /// A model whose schema no driver compiles, so its embedded paths name no column. The error
    /// gives the reason of each of Toasty's PostgreSQL, SQLite, MySQL and DynamoDB drivers.
    ///
    /// Fix the model for your driver.
    Uncompiled {
        /// The model.
        model: &'static str,
        /// Each driver's reason to refuse it.
        error: String,
    },
    /// A resource's tenancy that cannot scope its rows.
    Tenancy {
        /// What is wrong.
        fault: TenancyFault,
    },
    /// A field access that cannot hide its field everywhere the panel shows it.
    FieldAccess {
        /// What is wrong.
        fault: FieldAccessFault,
    },
    /// A table with no column.
    ///
    /// Declare columns; a resource whose model's table lists nothing declares its own `table`.
    NoColumns,
    /// `Table::page_size(0)`.
    ///
    /// Pass a page size of at least 1.
    ZeroPageSize,
    /// `Table::default_sort_by` names no sortable column.
    ///
    /// Declare its column `.sortable()`.
    UnsortableDefaultSort {
        /// The named column.
        column: String,
    },
    /// Two table columns share a name.
    ///
    /// Rename one.
    DuplicateColumn {
        /// The shared name.
        name: String,
    },
    /// Two table filters share a name.
    ///
    /// Rename one.
    DuplicateFilter {
        /// The shared name.
        name: String,
    },
    /// Two list tabs share a key.
    ///
    /// Give each [`ListTab`](crate::ListTab) a distinct key.
    DuplicateTab {
        /// The shared key.
        key: String,
    },
    /// A table offers two groupings by one field.
    ///
    /// Declare each [`Table::group_by`](crate::Table::group_by) once.
    DuplicateGrouping {
        /// The field's name.
        name: String,
    },
    /// A table filter's name holds a `.`, which its URL parameters reserve for a part:
    /// `f.<name>.<part>`.
    ///
    /// Rename it without the `.`.
    DottedFilterName {
        /// The name.
        name: String,
    },
    /// A select filter option whose value the field's type does not parse, so choosing it
    /// filters nothing.
    ///
    /// Spell it as the field's form value, or build the filter with `SelectFilter::of`.
    UnparsedFilterOption {
        /// The filter's name.
        filter: String,
        /// The option's value.
        value: String,
    },
    /// An option of [`Table::option_tabs`](crate::Table::option_tabs) whose value the field's
    /// type does not parse, so its tab admits no row.
    ///
    /// Spell the option as the field's form value.
    UnparsedTabOption {
        /// The option's value.
        value: String,
    },
    /// Two schema fields share a name.
    ///
    /// Bind each input to a distinct field.
    DuplicateField {
        /// The shared name.
        name: String,
    },
    /// A field disabled or hidden on the create form, or one a condition can disable, with no
    /// `default` and no blank answer: a create could not fill it.
    ///
    /// Give it a `default`, make it optional, or use `disabled_on_edit`.
    DisabledWithoutValue {
        /// The disabled field.
        field: String,
    },
    /// A repeater's item disables one of its row's controls or gives it a default, which a row
    /// does not apply.
    ///
    /// Disable the repeater's own field.
    RepeaterLeafModifier {
        /// The repeater.
        field: String,
        /// The control in its row.
        leaf: String,
    },
    /// A repeater's item has a password control, which an edit cannot render back, so every save
    /// would overwrite the stored secret.
    ///
    /// Keep the secret out of the repeater's item.
    RepeaterPassword {
        /// The repeater.
        field: String,
        /// The password control in its row.
        leaf: String,
    },
    /// A text field's declared length, bounds or pattern cannot work.
    FieldRule {
        /// The field, or `repeater.leaf` for a control in a repeater's rows.
        field: String,
        /// What is wrong.
        fault: FieldRuleFault,
    },
    /// A field's default is a value its control never posts: one its type does not parse, one
    /// not among a choice's options, or a list or one value where the control posts the other.
    ///
    /// Spell the default as the field's form value, a list for a multiple choice.
    UnpostedDefault {
        /// The field.
        field: String,
        /// The default, a list spelled `["a", "b"]`.
        value: String,
    },
    /// A condition watches a field the schema does not place.
    ///
    /// Place the watched field in the same schema.
    UnplacedWatchedField {
        /// The watched field.
        field: String,
    },
    /// A condition watches a field that another condition hides while what it guards still
    /// shows.
    ///
    /// Place the guarded field inside the block that hides the watched one.
    HiddenWatchedField {
        /// The watched field.
        field: String,
    },
    /// A condition, or a dependent choice, watches a field a condition disables, which posts
    /// nothing while it is disabled: the browser would follow the value the user last chose, the
    /// server the stored one or the default.
    ///
    /// Watch another field, or drop `disabled_when` from the watched one.
    DisabledWatchedField {
        /// The watched field.
        field: String,
    },
    /// A condition names a value its watched field never posts: not one of a choice's options, or
    /// neither `true` nor `false` for a toggle.
    ///
    /// Name one of its options, or `true` or `false` for a toggle.
    UnpostedConditionValue {
        /// The watched field.
        field: String,
        /// The value.
        value: String,
    },
    /// A dependent choice's column belongs to another model than its relationship's source, or
    /// the choice has no relationship.
    ///
    /// Declare `relationship::<R>()`, and name a column of `R`'s model in `depends_on`.
    MisdeclaredDependentChoice {
        /// The dependent choice.
        field: String,
    },
    /// A choice whose [`options_where`](crate::ChoiceField::options_where) narrows no
    /// relationship: declare `relationship::<R>()`, or drop `options_where`.
    UnfilterableChoice {
        /// The filtered choice.
        field: String,
    },
    /// A dependent choice that takes several options, or that depends on one that does: a
    /// multiple choice's key holds a list, which narrows nothing.
    ///
    /// Drop `depends_on` or `multiple`.
    MultipleDependentChoice {
        /// The dependent choice.
        field: String,
    },
    /// A dependent choice rendered as [radios](crate::ChoiceField::radio) or
    /// [buttons](crate::ChoiceField::buttons): the browser lists its options once, so it cannot
    /// narrow them when the parent changes.
    ///
    /// Drop `depends_on`, or `radio` or `buttons`.
    ListedDependentChoice {
        /// The dependent choice.
        field: String,
    },
    /// A [creatable](crate::ChoiceField::creatable) choice that is not a single select over a
    /// resource's records: a multiple choice, radios or buttons, a dependent or filtered choice, a
    /// source that is not a resource, no relationship, or a choice in a repeater's rows.
    ///
    /// Drop `creatable`, or declare the choice as a single select with `relationship::<R>()` over
    /// a resource `R`.
    UncreatableChoice {
        /// The creatable choice: `repeater.leaf` for one in a repeater's rows.
        field: String,
    },
    /// A dependent choice depends on a field the schema does not place.
    ///
    /// Place that field in the same schema.
    UnplacedParentField {
        /// The dependent choice.
        field: String,
        /// The field it depends on.
        parent: String,
    },
    /// A field a condition hides has no blank answer, so a submission hiding it cannot parse.
    ///
    /// Make it an `Option`, or give it `#[form(blank = ..)]`.
    RequiredConditionalField {
        /// The field.
        field: String,
    },
    /// A record-form field binding a key no control posts, after the form renders every field
    /// it does not place: a hand-written [`RecordForm::control`](crate::RecordForm::control)
    /// that renders no control for it.
    ///
    /// Render the field's control.
    MissingControl {
        /// The record-form field.
        field: String,
        /// The key it binds.
        key: String,
    },
    /// A tenant-scoped resource's record form claims the tenant column.
    ///
    /// Drop the field: the framework stamps the tenant.
    FormClaimsTenantColumn {
        /// The record-form field.
        field: String,
        /// The tenant column.
        column: String,
    },
    /// A soft-deleting resource's record form claims the soft-delete column, which only a delete
    /// and a restore write.
    ///
    /// Drop the field, or mark it `#[form(skip)]` on a `ModelForm`: only a delete and a restore
    /// write the column.
    FormClaimsSoftDeleteColumn {
        /// The record-form field.
        field: String,
        /// The soft-delete column.
        column: String,
    },
    /// A form field named after a key the form's POST carries itself: the CSRF token, the edit
    /// form's `record_version`, or the create form's `create_another`.
    ReservedFormField {
        /// The field.
        field: String,
    },
    /// A choice field with neither options nor a relationship.
    ///
    /// Declare `.options(..)`, `.relationship::<R>()`, or `#[form(relationship = R)]`.
    EmptyChoice {
        /// The field.
        field: String,
    },
    /// A relationship field, or a relationship filter, over a model with a composite primary key.
    ///
    /// Choose over a model with a single-column key.
    CompositeKeyChoice {
        /// The field, or the filter's name.
        field: String,
    },
    /// A field marked unique over a column no unique index covers.
    ///
    /// Add `#[unique]` to the model, or drop `.unique()`.
    UniqueWithoutIndex {
        /// The field.
        field: String,
    },
    /// A unique field whose non-nullable column stores one value for every empty submission.
    ///
    /// Make the field required, or an `Option`.
    OptionalUnique {
        /// The field.
        field: String,
    },
    /// [`create_column`](crate::ResourceDef::create_column) names the tenant column.
    ///
    /// Drop it: the framework stamps the tenant.
    CreateColumnsNameTenant {
        /// The tenant column.
        column: String,
    },
    /// A non-nullable column nothing writes on create, for a resource that serves a create page:
    /// not the form, not a Toasty `#[default(..)]`, not the tenant stamp, not a `create_column`.
    ///
    /// Add the field to the form, a default to the model, or a `create_column`; or turn the
    /// create page off with `without_page(ResourcePage::Create)`.
    UnwrittenColumn {
        /// The column.
        column: String,
    },
    /// [`importable`](crate::ResourceDef::importable) on a resource that serves no create page:
    /// it has no record form, or turns the page off with
    /// [`without_page`](crate::ResourceDef::without_page).
    ///
    /// Drop `importable`, or serve the create page.
    ImportWithoutCreate,
    /// A detail listing no column on a resource that serves the view page.
    ///
    /// Declare a [`detail`](crate::ResourceDef::detail) or a table, or turn the page off with
    /// `without_page(ResourcePage::View)`.
    EmptyDetail,
    /// A `has_one` relation whose related form cannot render inside the owner's form.
    RelatedForm(RelatedFormFault),
    /// A many-to-many field or relation whose join model cannot link records.
    ManyToMany {
        /// The field, or the relation's `via` field.
        field: String,
        /// What is wrong.
        fault: ManyToManyFault,
    },
}