Skip to content

Commit cfb45ee

Browse files
committed
mustache: remove filter for resources, use treeShake instead.
1 parent 3930271 commit cfb45ee

2 files changed

Lines changed: 1 addition & 36 deletions

File tree

src/api/mustache/types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ export type FieldViewModel = {
4040
isReference: boolean;
4141
};
4242

43-
export type MustacheFilter = {
44-
resource?: FilterType;
45-
complexType?: FilterType;
46-
};
47-
4843
export type FilterType = {
4944
whitelist?: (string | RegExp)[];
5045
blacklist?: (string | RegExp)[];

src/api/writer-generator/mustache.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import type { ViewModelCache } from "@mustache/generator/ViewModelFactory";
1414
import { ViewModelFactory } from "@mustache/generator/ViewModelFactory";
1515
import type {
1616
HookType,
17-
MustacheFilter,
1817
NamedViewModel,
1918
PrimitiveType,
2019
Rendering,
@@ -24,7 +23,6 @@ import type {
2423
} from "@mustache/types";
2524
import type { TypeSchemaIndex } from "@root/typeschema/utils";
2625
import type { CodegenLogger } from "@root/utils/codegen-logger";
27-
import type { Identifier } from "@typeschema/types";
2826
import { default as Mustache } from "mustache";
2927
import { FileSystemWriter, type FileSystemWriterOptions } from "./writer";
3028

@@ -37,7 +35,6 @@ export type FileBasedMustacheGeneratorOptions = {
3735
};
3836
keywords: string[];
3937
typeMap: Partial<Record<PrimitiveType, string>>;
40-
filters: MustacheFilter;
4138
meta: {
4239
timestamp?: string;
4340
generator?: string;
@@ -82,7 +79,6 @@ export const createGenerator = (
8279
debug: "OFF",
8380
hooks: {},
8481
meta: {},
85-
filters: {},
8682
keywords: [],
8783
unsaveCharacterPattern: /[^a-zA-Z0-9]/g,
8884
nameTransformations: {
@@ -127,29 +123,6 @@ function runCommand(cmd: string, args: string[] = [], options = {}) {
127123
});
128124
}
129125

130-
const mkFilterPredicate = (filters: MustacheFilter) => {
131-
return (type: Identifier) => {
132-
if (type.kind !== "complex-type" && type.kind !== "resource") {
133-
return true;
134-
}
135-
if (!filters[type.kind as "resource" | "complexType"]) {
136-
return true;
137-
}
138-
const whitelist = filters[type.kind as "resource" | "complexType"]?.whitelist ?? [];
139-
const blacklist = filters[type.kind as "resource" | "complexType"]?.blacklist ?? [];
140-
if (!whitelist.length && !blacklist.length) {
141-
return true;
142-
}
143-
if (blacklist.find((pattern: any) => type.name.match(pattern as any))) {
144-
return false;
145-
}
146-
if (whitelist.find((pattern: any) => type.name.match(pattern as any))) {
147-
return true;
148-
}
149-
return whitelist.length === 0;
150-
};
151-
};
152-
153126
export class MustacheGenerator extends FileSystemWriter<MustacheGeneratorOptions> {
154127
private readonly templateFileCache: TemplateFileCache;
155128
private readonly nameGenerator: NameGenerator;
@@ -170,24 +143,21 @@ export class MustacheGenerator extends FileSystemWriter<MustacheGeneratorOptions
170143
}
171144

172145
override async generate(tsIndex: TypeSchemaIndex) {
173-
const filterPred = mkFilterPredicate(this.opts.filters);
174-
const modelFactory = new ViewModelFactory(tsIndex, this.nameGenerator, filterPred);
146+
const modelFactory = new ViewModelFactory(tsIndex, this.nameGenerator, () => true);
175147
const cache: ViewModelCache = {
176148
resourcesByUri: {},
177149
complexTypesByUri: {},
178150
};
179151
tsIndex
180152
.collectComplexTypes()
181153
.map((i) => i.identifier)
182-
.filter((i) => filterPred(i))
183154
.sort((a, b) => a.url.localeCompare(b.url))
184155
.map((typeRef) => modelFactory.createComplexType(typeRef, cache))
185156
.forEach(this._renderComplexType.bind(this));
186157

187158
tsIndex
188159
.collectResources()
189160
.map((i) => i.identifier)
190-
.filter((i) => filterPred(i))
191161
.sort((a, b) => a.url.localeCompare(b.url))
192162
.map((typeRef) => modelFactory.createResource(typeRef, cache))
193163
.forEach(this._renderResource.bind(this));

0 commit comments

Comments
 (0)