1+ import { BagPermissionLevel , RecipePermissionLevel } from "@tiddlywiki/mws-prisma" ;
12
23const halfWidth = "half" as const ;
34const fullWidth = "full" as const ;
@@ -21,6 +22,7 @@ export type FieldSection = "authored" | "runtime" | "operations";
2122
2223
2324export type FieldType =
25+ | "template-type"
2426 | "string"
2527 | "text"
2628 | "search"
@@ -205,6 +207,7 @@ const tabs = {
205207 { key : "validationStatus" , label : "Validation" } ,
206208 ] ,
207209 fields : [
210+ { key : "type" , label : "Type" , type : "template-type" , section : "authored" , mode : "create" } ,
208211 { key : "name" , label : "Name" , type : "string" , section : "authored" , mode : "create edit" } ,
209212 { key : "description" , label : "Description" , type : "text" , section : "authored" , mode : "create edit" } ,
210213 { key : "lastUpdatedAt" , label : "Updated" , type : "string" , section : "runtime" , mode : "server" } ,
@@ -279,7 +282,7 @@ const tabs = {
279282 label : "Dependent wikis" ,
280283 type : "relationship-table" ,
281284 section : "runtime" ,
282- mode : "server " ,
285+ mode : "" ,
283286 architecture : "Read-only relationship view listing all wikis that reference this template and will be revalidated or recompiled if it changes." ,
284287 } ,
285288 {
@@ -432,19 +435,19 @@ const tabs = {
432435 eyebrow : "Access profiles" ,
433436 description : "Named access profiles that can be assigned to user accounts." ,
434437 columns : [
435- { key : "roleId " , label : "Role name" } ,
438+ { key : "name " , label : "Role name" } ,
436439 { key : "description" , label : "Role description" } ,
437440 ] ,
438441 fields : [
439- { key : "roleId " , label : "Role name" , type : "string" , section : "authored" , mode : "create edit" } ,
442+ { key : "name " , label : "Role name" , type : "string" , section : "authored" , mode : "create edit" } ,
440443 { key : "description" , label : "Role description" , type : "text" , section : "authored" , mode : "create edit" } ,
441444 ] ,
442445 fieldGroups : {
443446 authored : [
444- { title : "Role basics" , keys : [ "roleId " , "description" ] , width : fullWidth , layout : stackLayout } ,
447+ { title : "Role basics" , keys : [ "name " , "description" ] , width : fullWidth , layout : stackLayout } ,
445448 ] ,
446449 } ,
447- sidebarDisplay : [ "roleId " , "description" ] ,
450+ sidebarDisplay : [ "name " , "description" ] ,
448451 } ,
449452 users : {
450453 id : "users" ,
@@ -505,26 +508,20 @@ export function getSectionHeading(section: FieldSection, mode: "create" | "edit"
505508}
506509
507510
508- type StoredTabKeys < T extends TabDefinition > = {
509- [ K in keyof TabDef ] : MapFieldDefinitions < T [ "fields" ] > [ number ] | "id"
510- } [ keyof TabDef ] ;
511-
512- type t1 = TabDef [ TabId ] [ "fields" ] [ number ] [ "key" ]
513-
514511
515- type StoredTabRecord < D extends TabDefinition , T > = Pick < T , StoredTabKeys < D > & keyof T > ;
512+ type StoredTabRecord < D extends TabDefinition , T > = Pick < T , TabFieldKeys < D , "" | "create edit temp" | "create temp" | "edit temp" > & keyof T > ;
513+ type SavedTabRecord < D extends TabDefinition , T > = Pick < T , TabFieldKeys < D , "" | "create edit temp" | "create temp" | "edit temp" | "server" > & keyof T > ;
516514
515+ type TabFieldKeys < T extends TabDefinition , M extends Mode > = {
516+ [ K in keyof TabDef ] : MapFieldDefinitions < T [ "fields" ] , M > [ number ] | "id"
517+ } [ keyof TabDef ] ;
517518
518- type MapFieldDefinitions < T > =
519- T extends [ infer F extends FieldDefinition , ...infer R ] ? [ FilterServerFields < F > , ...MapFieldDefinitions < R > ] :
520- T extends [ infer F extends FieldDefinition ] ? [ FilterServerFields < F > ] : [ ] ;
519+ type MapFieldDefinitions < T , M extends Mode > =
520+ T extends [ infer F extends FieldDefinition , ...infer R ] ? [ FilterServerFields < F , M > , ...MapFieldDefinitions < R , M > ] :
521+ T extends [ infer F extends FieldDefinition ] ? [ FilterServerFields < F , M > ] : [ ] ;
521522
522- type FilterServerFields < T extends FieldDefinition > =
523- T [ "mode" ] extends "" ? never :
524- T [ "mode" ] extends "create edit temp" ? never :
525- T [ "mode" ] extends "create temp" ? never :
526- T [ "mode" ] extends "edit temp" ? never :
527- T [ "key" ] ;
523+ type FilterServerFields < T extends FieldDefinition , M extends Mode > =
524+ T [ "mode" ] extends M ? never : T [ "key" ] ;
528525
529526export interface AdminRecordStore {
530527 wikis : WikiAdminRecord [ ] ;
@@ -548,6 +545,17 @@ export interface DataStore {
548545 availablePluginNames : Set < string > ;
549546} ;
550547
548+ export interface DataSave {
549+ wikis : SavedTabRecord < TabDef [ "wikis" ] , WikiAdminRecord > [ ] ;
550+ templates : SavedTabRecord < TabDef [ "templates" ] , TemplateAdminRecord > [ ] ;
551+ bags : SavedTabRecord < TabDef [ "bags" ] , BagAdminRecord > [ ] ;
552+ plugins : SavedTabRecord < TabDef [ "plugins" ] , PluginAdminRecord > [ ] ;
553+ roles : SavedTabRecord < TabDef [ "roles" ] , RoleAdminRecord > [ ] ;
554+ users : SavedTabRecord < TabDef [ "users" ] , UserAdminRecord > [ ] ;
555+ availableBagNames : Set < string > ;
556+ availablePluginNames : Set < string > ;
557+ } ;
558+
551559export interface WikiAdminRecord {
552560 // server fields
553561 id : string ;
@@ -558,7 +566,7 @@ export interface WikiAdminRecord {
558566 writablePrefixBags : readonly MappingRow [ ] ;
559567 readonlyBags : readonly string [ ] ;
560568 plugins : readonly string [ ] ;
561- recipePermissions : readonly PermissionRow [ ] ;
569+ recipePermissions : readonly PermissionRow < RecipePermissionLevel > [ ] ;
562570 // client field
563571 templateName : string ;
564572 defaultWritableBag : string ;
@@ -576,15 +584,18 @@ export interface WikiAdminRecord {
576584 titleResolutionPreview : string ;
577585}
578586
587+ export type TemplateTypes = "simpleV1" ;
588+
579589export interface TemplateAdminRecord {
580590 // server fields
581591 id : string ;
592+ type : TemplateTypes ;
582593 name : string ;
583594 description : string ;
584595 writablePrefixBags : readonly MappingRow [ ] ;
585596 readonlyBags : readonly string [ ] ;
586597 plugins : readonly string [ ] ;
587- templatePermissions : readonly PermissionRow [ ] ;
598+ templatePermissions : readonly PermissionRow < RecipePermissionLevel > [ ] ;
588599 requiredPluginsEnabled : boolean ;
589600 customHtmlEnabled : boolean ;
590601 htmlContent : string ;
@@ -604,7 +615,7 @@ export interface BagAdminRecord {
604615 id : string ;
605616 name : string ;
606617 description : string ;
607- permissions : readonly PermissionRow [ ] ;
618+ permissions : readonly PermissionRow < BagPermissionLevel > [ ] ;
608619 usedByCount : string ;
609620 readonlyUsageCount : string ;
610621 writableUsageCount : string ;
@@ -629,7 +640,7 @@ export interface PluginAdminRecord {
629640
630641export interface RoleAdminRecord {
631642 id : string ;
632- roleId : string ;
643+ name : string ;
633644 description : string ;
634645}
635646
0 commit comments