UNPKG

1.33 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.ReadonlyVisitor = void 0;
4const ts = require("typescript");
5const merge_options_1 = require("../merge-options");
6const is_filename_matched_util_1 = require("../utils/is-filename-matched.util");
7const model_class_visitor_1 = require("./model-class.visitor");
8class ReadonlyVisitor {
9 get typeImports() {
10 return this.modelClassVisitor.typeImports;
11 }
12 constructor(options) {
13 this.options = options;
14 this.key = '@nestjs/graphql';
15 this.modelClassVisitor = new model_class_visitor_1.ModelClassVisitor();
16 options.readonly = true;
17 if (!options.pathToSource) {
18 throw new Error(`"pathToSource" must be defined in plugin options`);
19 }
20 }
21 visit(program, sf) {
22 const factoryHost = { factory: ts.factory };
23 const parsedOptions = (0, merge_options_1.mergePluginOptions)(this.options);
24 if ((0, is_filename_matched_util_1.isFilenameMatched)(parsedOptions.typeFileNameSuffix, sf.fileName)) {
25 return this.modelClassVisitor.visit(sf, factoryHost, program, parsedOptions);
26 }
27 }
28 collect() {
29 return {
30 models: this.modelClassVisitor.collectedMetadata,
31 };
32 }
33}
34exports.ReadonlyVisitor = ReadonlyVisitor;