|
| 1 | +import type { Field, NestedType, TypeSchema } from "@typeschema/types"; |
| 2 | +import type { IsPrefixed } from "@mustache/UtilityTypes"; |
| 3 | + |
| 4 | +export type DebugMixin = { |
| 5 | + debug: string; |
| 6 | +}; |
| 7 | + |
| 8 | +export type EnumValueViewModel = { |
| 9 | + name: string; |
| 10 | + saveName: string; |
| 11 | +}; |
| 12 | + |
| 13 | +export type EnumViewModel = NamedViewModel & { |
| 14 | + values: EnumValueViewModel[]; |
| 15 | +}; |
| 16 | + |
| 17 | +export type FieldViewModel = { |
| 18 | + owner: NamedViewModel; |
| 19 | + |
| 20 | + schema: Field; |
| 21 | + name: string; |
| 22 | + saveName: string; |
| 23 | + |
| 24 | + typeName: string; |
| 25 | + |
| 26 | + isSizeConstrained: boolean; |
| 27 | + min?: number; |
| 28 | + max?: number; |
| 29 | + |
| 30 | + isArray: boolean; |
| 31 | + isRequired: boolean; |
| 32 | + isEnum: boolean; |
| 33 | + |
| 34 | + isPrimitive: Record<IsPrefixed<PrimitiveType>, boolean> | false; |
| 35 | + isComplexType: Record<IsPrefixed<string>, boolean> | false; |
| 36 | + isResource: Record<IsPrefixed<string>, boolean> | false; |
| 37 | + |
| 38 | + isCode: boolean; |
| 39 | + isIdentifier: boolean; |
| 40 | + isReference: boolean; |
| 41 | +}; |
| 42 | + |
| 43 | +export type FilterType = { |
| 44 | + whitelist?: (string | RegExp)[]; |
| 45 | + blacklist?: (string | RegExp)[]; |
| 46 | +}; |
| 47 | + |
| 48 | +export type HookType = { |
| 49 | + cmd: string; |
| 50 | + args?: string[]; |
| 51 | +}; |
| 52 | + |
| 53 | +export type LambdaMixin = { |
| 54 | + lambda: { |
| 55 | + saveEnumValueName: () => (text: string, render: (input: string) => string) => string; |
| 56 | + saveFieldName: () => (text: string, render: (input: string) => string) => string; |
| 57 | + saveTypeName: () => (text: string, render: (input: string) => string) => string; |
| 58 | + |
| 59 | + camelCase: () => (text: string, render: (input: string) => string) => string; |
| 60 | + snakeCase: () => (text: string, render: (input: string) => string) => string; |
| 61 | + pascalCase: () => (text: string, render: (input: string) => string) => string; |
| 62 | + kebabCase: () => (text: string, render: (input: string) => string) => string; |
| 63 | + lowerCase: () => (text: string, render: (input: string) => string) => string; |
| 64 | + upperCase: () => (text: string, render: (input: string) => string) => string; |
| 65 | + }; |
| 66 | +}; |
| 67 | + |
| 68 | +export type ListElementInformationMixin = { |
| 69 | + "-index": number; |
| 70 | + "-length": number; |
| 71 | + "-last": boolean; |
| 72 | + "-first": boolean; |
| 73 | +}; |
| 74 | + |
| 75 | +export type NamedViewModel = { |
| 76 | + name: string; |
| 77 | + saveName: string; |
| 78 | +}; |
| 79 | + |
| 80 | +export const PRIMITIVE_TYPES = [ |
| 81 | + "boolean", |
| 82 | + "instant", |
| 83 | + "time", |
| 84 | + "date", |
| 85 | + "dateTime", |
| 86 | + |
| 87 | + "decimal", |
| 88 | + "integer", |
| 89 | + "unsignedInt", |
| 90 | + "positiveInt", |
| 91 | + "integer64", |
| 92 | + "base64Binary", |
| 93 | + |
| 94 | + "uri", |
| 95 | + "url", |
| 96 | + "canonical", |
| 97 | + "oid", |
| 98 | + "uuid", |
| 99 | + |
| 100 | + "string", |
| 101 | + "code", |
| 102 | + "markdown", |
| 103 | + "id", |
| 104 | + "xhtml", |
| 105 | +] as const; |
| 106 | + |
| 107 | +export type PrimitiveType = (typeof PRIMITIVE_TYPES)[number]; |
| 108 | + |
| 109 | +export type Rendering = { |
| 110 | + source: string; |
| 111 | + fileNameFormat: string; |
| 112 | + path: string; |
| 113 | + filter?: FilterType; |
| 114 | + properties?: Record<string, any>; |
| 115 | +}; |
| 116 | + |
| 117 | +export type ResolvedTypeViewModel = TypeViewModel & { |
| 118 | + allFields: FieldViewModel[]; |
| 119 | + inheritedFields: FieldViewModel[]; |
| 120 | + parents: TypeViewModel[]; |
| 121 | + children: TypeViewModel[]; |
| 122 | + |
| 123 | + hasChildren: boolean; |
| 124 | + hasParents: boolean; |
| 125 | + hasInheritedFields: boolean; |
| 126 | +}; |
| 127 | + |
| 128 | +export type RootViewModel<T> = T & { |
| 129 | + resources: { name: string; saveName: string }[]; |
| 130 | + complexTypes: { name: string; saveName: string }[]; |
| 131 | +}; |
| 132 | + |
| 133 | +export type TypeViewModel = NamedViewModel & { |
| 134 | + schema: TypeSchema | NestedType; |
| 135 | + fields: FieldViewModel[]; |
| 136 | + |
| 137 | + dependencies: { |
| 138 | + resources: NamedViewModel[]; |
| 139 | + complexTypes: NamedViewModel[]; |
| 140 | + }; |
| 141 | + |
| 142 | + hasFields: boolean; |
| 143 | + hasNestedComplexTypes: boolean; |
| 144 | + hasNestedEnums: boolean; |
| 145 | + |
| 146 | + isNested: boolean; |
| 147 | + isComplexType: Record<IsPrefixed<string>, boolean> | false; |
| 148 | + isResource: Record<IsPrefixed<string>, boolean> | false; |
| 149 | + |
| 150 | + nestedComplexTypes: ResolvedTypeViewModel[]; |
| 151 | + nestedEnums: EnumViewModel[]; |
| 152 | +}; |
| 153 | + |
| 154 | +export type View<T extends ViewModel> = LambdaMixin & { |
| 155 | + model: T; |
| 156 | + meta: { |
| 157 | + timestamp: string; |
| 158 | + generator: string; |
| 159 | + }; |
| 160 | + properties: Record<string, unknown>; |
| 161 | +}; |
| 162 | + |
| 163 | +export type ViewModel = Record<string, unknown>; |
0 commit comments