public override Task <string> BuildOutputAsync() { var b = new TypeScriptCodeBuilder(indentSize: 2); b.Lines(new [] { "import * as $metadata from './metadata.g'", "import * as $models from './models.g'", "import * as qs from 'qs'", "import { AxiosClient, ModelApiClient, ServiceApiClient, ItemResult, ListResult } from 'coalesce-vue/lib/api-client'", "import { AxiosResponse, AxiosRequestConfig } from 'axios'", }); b.Line(); foreach (var model in Model.Entities.OrderBy(e => e.ClientTypeName)) { WriteApiClientClass(b, model, $"ModelApiClient<$models.{model.ClientTypeName}>"); // Lines between classes b.Line(); b.Line(); } foreach (var model in Model.Services.OrderBy(e => e.ClientTypeName)) { WriteApiClientClass(b, model, $"ServiceApiClient<typeof $metadata.{model.ClientTypeName}>"); // Lines between classes b.Line(); b.Line(); } return(Task.FromResult(b.ToString())); }
public override Task <string> BuildOutputAsync() { var b = new TypeScriptCodeBuilder(); b.Line(); b.Line(); b.Line("// This file is automatically generated."); b.Line("// It is not in the generated folder for ease-of-use (no relative paths)."); b.Line("// This file must remain in place relative to the generated scripts (<WebProject>/Scripts/Generated)."); b.Line(); b.Line(); b.Line($"/// <reference path=\"coalesce.dependencies.d.ts\" />"); foreach (var referencePath in Model.Select(m => m.EffectiveOutputPath).OrderBy(p => p)) { // https://stackoverflow.com/a/1766773/2465631 Uri referencedFilePath = new Uri(referencePath); Uri referenceFile = new Uri(this.EffectiveOutputPath); Uri diff = referenceFile.MakeRelativeUri(referencedFilePath); string relPath = diff.OriginalString; b.Line($"/// <reference path=\"{relPath}\" />"); } return(Task.FromResult(b.ToString())); }
public override Task <string> BuildOutputAsync() { var b = new TypeScriptCodeBuilder(); b.Line(); b.Line("/// <reference path=\"../coalesce.dependencies.d.ts\" />"); if (ShouldWriteGeneratedBy) { b.Line(); b.Line("// Generated by IntelliTect.Coalesce"); } b.Line(); BuildOutput(b); return(Task.FromResult(b.ToString())); }
public override Task <string> BuildOutputAsync() { var b = new TypeScriptCodeBuilder(indentSize: 2); b.Line("import * as $metadata from './metadata.g'"); b.Line("import * as $models from './models.g'"); b.Line("import * as $apiClients from './api-clients.g'"); b.Line("import { ViewModel, ListViewModel, defineProps } from 'coalesce-vue/lib/viewmodel'"); b.Line(); foreach (var model in Model.Entities) { WriteViewModel(b, model); WriteListViewModel(b, model); b.Line(); } return(Task.FromResult(b.ToString())); }
public override Task <string> BuildOutputAsync() { var b = new TypeScriptCodeBuilder(indentSize: 2); using (b.Block("import", " from 'coalesce-vue/lib/metadata'")) { b.Line("Domain, getEnumMeta, ModelType, ObjectType,"); b.Line("PrimitiveProperty, ModelReferenceNavigationProperty, ForeignKeyProperty, PrimaryKeyProperty"); } b.Line(); b.Line(); // Assigning each property as a member of domain ensures we don't break type contracts. // Exporting each model individually offers easier usage in imports. b.Line("const domain: Domain = { enums: {}, types: {}, services: {} }"); foreach (var model in Model.ClientEnums.OrderBy(e => e.Name)) { WriteEnumMetadata(b, model); } foreach (var model in Model.ApiBackedClasses.OrderBy(e => e.ClientTypeName)) { WriteApiBackedTypeMetadata(b, model); } foreach (var model in Model.ExternalTypes.OrderBy(e => e.ClientTypeName)) { WriteExternalTypeMetadata(b, model); } foreach (var model in Model.Services.OrderBy(e => e.ClientTypeName)) { WriteServiceMetadata(b, model); } // Create an enhanced Domain definition for deep intellisense. b.Line(); using (b.Block("interface AppDomain extends Domain")) { using (b.Block("enums:")) { foreach (var model in Model.ClientEnums.OrderBy(e => e.Name)) { b.Line($"{model.Name}: typeof {model.Name}"); } } using (b.Block("types:")) { foreach (var model in Model.ClientClasses.OrderBy(e => e.ClientTypeName)) { b.Line($"{model.ClientTypeName}: typeof {model.ClientTypeName}"); } } using (b.Block("services:")) { foreach (var model in Model.Services.OrderBy(e => e.ClientTypeName)) { b.Line($"{model.ClientTypeName}: typeof {model.ClientTypeName}"); } } } b.Line(); b.Line("export default domain as AppDomain"); return(Task.FromResult(b.ToString())); }
public override Task <string> BuildOutputAsync() { var b = new TypeScriptCodeBuilder(indentSize: 2); b.Line("import * as metadata from './metadata.g'"); b.Line("import { Model, DataSource, convertToModel, mapToModel } from 'coalesce-vue/lib/model'"); // b.Line("import { Domain, getEnumMeta, ModelType, ExternalType } from './coalesce/core/metadata' "); b.Line(); foreach (var model in Model.ClientEnums.OrderBy(e => e.Name)) { using (b.Block($"export enum {model.Name}")) { foreach (var value in model.EnumValues) { b.Line($"{value.Value} = {value.Key},"); } } b.Line(); b.Line(); } foreach (var model in Model.ClientClasses .OrderByDescending(c => c.IsDbMappedType) // Entity types first .ThenBy(e => e.ClientTypeName)) { var name = model.ViewModelClassName; using (b.Block($"export interface {name} extends Model<typeof metadata.{name}>")) { foreach (var prop in model.ClientProperties) { b.DocComment(prop.Comment); var typeString = new VueType(prop.Type).TsType(); b.Line($"{prop.JsVariable}: {typeString} | null"); } } using (b.Block($"export class {name}")) { b.DocComment($"Mutates the input object and its descendents into a valid {name} implementation."); using (b.Block($"static convert(data?: Partial<{name}>): {name}")) { b.Line($"return convertToModel(data || {{}}, metadata.{name}) "); } b.DocComment($"Maps the input object and its descendents to a new, valid {name} implementation."); using (b.Block($"static map(data?: Partial<{name}>): {name}")) { b.Line($"return mapToModel(data || {{}}, metadata.{name}) "); } b.DocComment($"Instantiate a new {name}, optionally basing it on the given data."); using (b.Block($"constructor(data?: Partial<{name}> | {{[k: string]: any}})")) { b.Indented($"Object.assign(this, {name}.map(data || {{}}));"); } } var dataSources = model.ClientDataSources(Model); if (model.IsDbMappedType && dataSources.Any()) { using (b.Block($"export namespace {name}")) { using (b.Block("export namespace DataSources")) { foreach (var source in dataSources) { b.DocComment(source.Comment, true); var sourceMeta = $"metadata.{name}.dataSources.{source.ClientTypeName.ToCamelCase()}"; using (b.Block($"export class {source.ClientTypeName} implements DataSource<typeof {sourceMeta}>")) { b.Line($"readonly $metadata = {sourceMeta}"); foreach (var param in source.DataSourceParameters) { b.DocComment(param.Comment); var typeString = new VueType(param.Type).TsType(); b.Line($"{param.JsVariable}: {typeString} | null = null"); } } } } } } b.Line(); b.Line(); } return(Task.FromResult(b.ToString())); }