Skip to content

Commit 9e3c14b

Browse files
committed
Refactoring: merge types from src/api/mustache/types/* to src/api/mustache/types.ts.
1 parent d6e133b commit 9e3c14b

24 files changed

Lines changed: 188 additions & 189 deletions

src/api/mustache/generator/DebugMixinProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { DebugMixin } from "@mustache/types/DebugMixin";
1+
import type { DebugMixin } from "@mustache/types";
22

33
export class DebugMixinProvider {
44
constructor(private readonly mode: "FORMATTED" | "COMPACT") {}

src/api/mustache/generator/LambdaMixinProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NameGenerator } from "@mustache/generator/NameGenerator";
2-
import type { LambdaMixin } from "@mustache/types/LambdaMixin";
2+
import type { LambdaMixin } from "@mustache/types";
33
import { camelCase, kebabCase, pascalCase, snakeCase } from "@root/api/writer-generator/utils";
44

55
export class LambdaMixinProvider {

src/api/mustache/generator/ListElementInformationMixinProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ListElementInformationMixin } from "@mustache/types/ListElementInformationMixin";
1+
import type { ListElementInformationMixin } from "@mustache/types";
22

33
export class ListElementInformationMixinProvider {
44
private static _array<T>(value: T[] | Set<T>): T[] {

src/api/mustache/generator/SchemaLoaderFacade.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { FilterType } from "@mustache/types/FilterType";
1+
import type { FilterType } from "@mustache/types";
22
import type { TypeSchemaIndex } from "@root/typeschema/utils";
33
import type { Identifier, RegularTypeSchema, TypeSchema } from "@typeschema/types";
44

src/api/mustache/generator/TemplateFileCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from "node:fs";
22
import Path from "node:path";
3-
import type { Rendering } from "@mustache/types/Rendering";
3+
import type { Rendering } from "@mustache/types";
44

55
export class TemplateFileCache {
66
private readonly templateBaseDir: string;

src/api/mustache/generator/ViewModelFactory.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { ListElementInformationMixinProvider } from "@mustache/generator/ListElementInformationMixinProvider";
22
import type { NameGenerator } from "@mustache/generator/NameGenerator";
33
import type { SchemaLoaderFacade } from "@mustache/generator/SchemaLoaderFacade";
4-
import type { EnumViewModel } from "@mustache/types/EnumViewModel";
5-
import type { FieldViewModel } from "@mustache/types/FieldViewModel";
6-
import type { NamedViewModel } from "@mustache/types/NamedViewModel";
7-
import { PRIMITIVE_TYPES } from "@mustache/types/PrimitiveType";
8-
import type { ResolvedTypeViewModel } from "@mustache/types/ResolvedTypeViewModel";
9-
import type { RootViewModel } from "@mustache/types/RootViewModel";
10-
import type { TypeViewModel } from "@mustache/types/TypeViewModel";
11-
import type { ViewModel } from "@mustache/types/ViewModel";
4+
import type {
5+
EnumViewModel,
6+
FieldViewModel,
7+
NamedViewModel,
8+
ResolvedTypeViewModel,
9+
RootViewModel,
10+
TypeViewModel,
11+
ViewModel,
12+
} from "@mustache/types";
13+
import { PRIMITIVE_TYPES } from "@mustache/types";
1214
import type { IsPrefixed } from "@mustache/UtilityTypes";
1315
import type { Field, Identifier, NestedType, TypeSchema } from "@typeschema/types";
1416

src/api/mustache/types.ts

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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>;

src/api/mustache/types/DebugMixin.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/api/mustache/types/EnumValueViewModel.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/api/mustache/types/EnumViewModel.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)