Documentation
¶
Index ¶
- Constants
- Variables
- func CodeGeneratorNgCommitNbFromBack(modelPkg *models.ModelPkg, apiPath string)
- func CodeGeneratorNgEnum(modelPkg *models.ModelPkg)
- func CodeGeneratorNgFrontRepo(modelPkg *models.ModelPkg)
- func CodeGeneratorNgNullInt64(modelPkg *models.ModelPkg)
- func CodeGeneratorNgPublicApi(modelPkg *models.ModelPkg)
- func CodeGeneratorNgPushFromFrontNb(modelPkg *models.ModelPkg, apiPath string)
- func MultiCodeGeneratorNgClass(modelPkg *models.ModelPkg)
- func MultiCodeGeneratorNgClassAPI(modelPkg *models.ModelPkg)
- func MultiCodeGeneratorNgService(modelPkg *models.ModelPkg, apiPath string)
- type BackRepoDataTSInsertionPoint
- type FrontRepoInsertionPointId
- type NgClassAPISubTemplate
- type NgClassAPITsInsertionPoint
- type NgClassSubTemplate
- type NgClassTsInsertionPoint
- type NgEnumInsertionPoint
- type NgEnumSubTemplate
- type NgLibFrontRepoServiceSubSubTemplate
- type NgPublicApiInsertionPoint
- type NgPublicApiSubTemplate
- type NgServiceSubTemplate
- type NgServiceTsInsertionPoint
Constants ¶
const BackRepoTemplateTS = `// generated code - do not edit //insertion point for imports{{` + string(rune(BackRepoDataImports)) + `}} export class BackRepoData { // insertion point for declarations{{` + string(rune(BackRepoInsertionEnumsExportDeclaration)) + `}} // index of the web socket for this stack type (unique among all stack instances) GONG__Index : number constructor(data?: Partial<BackRepoData>) { // insertion point for copies{{` + string(rune(BackRepoInsertionEnumsExportCopies)) + `}} this.GONG__Index = data?.GONG__Index ?? -1; // Assign Index here } }`
const EmebedNgDistNg = `` /* 225-byte string literal not displayed */
const NgClassAPITmpl = `// insertion point for imports{{` + string(rune(NgClassAPITsInsertionPerStructImports)) + `}} // usefull for managing pointer ID values that can be nullable import { NullInt64 } from './null-int64' export class {{Structname}}API { static GONGSTRUCT_NAME = "{{Structname}}" CreatedAt?: string DeletedAt?: string ID: number = 0 // insertion point for basic fields declarations{{` + string(rune(NgClassAPITsInsertionPerStructBasicFieldsDecl)) + `}} // insertion point for other decls{{` + string(rune(NgClassAPITsInsertionPerStructOtherDecls)) + `}} {{Structname}}PointersEncoding: {{Structname}}PointersEncoding = new {{Structname}}PointersEncoding } export class {{Structname}}PointersEncoding { // insertion point for pointers and slices of pointers encoding fields{{` + string(rune(NgClassAPITsInsertionPerStructPointersEncoding)) + `}} } `
const NgClassTmpl = `// generated code - do not edit import { {{Structname}}API } from './{{structname}}-api' import { FrontRepo } from './front-repo.service'; // insertion point for imports{{` + string(rune(NgClassTsInsertionPerStructImports)) + `}} // usefull for managing pointer ID values that can be nullable import { NullInt64 } from './null-int64' export class {{Structname}} { static GONGSTRUCT_NAME = "{{Structname}}" CreatedAt?: string DeletedAt?: string ID: number = 0 // insertion point for basic fields declarations{{` + string(rune(NgClassTsInsertionPerStructBasicFieldsDecl)) + `}} // insertion point for pointers and slices of pointers declarations{{` + string(rune(NgClassTsInsertionPerStructOtherDecls)) + `}} } export function Copy{{Structname}}To{{Structname}}API({{structname}}: {{Structname}}, {{structname}}API: {{Structname}}API) { {{structname}}API.CreatedAt = {{structname}}.CreatedAt {{structname}}API.DeletedAt = {{structname}}.DeletedAt {{structname}}API.ID = {{structname}}.ID // insertion point for basic fields copy operations{{` + string(rune(NgClassTsInsertionPerStructBasicFieldsCopyToAPI)) + `}} // insertion point for pointer fields encoding{{` + string(rune(NgClassTsInsertionPerStructPointerFieldsCopyToAPI)) + `}} // insertion point for slice of pointers fields encoding{{` + string(rune(NgClassTsInsertionPerStructSliceOfPointersFieldsCopyToAPI)) + `}} } // Copy{{Structname}}APITo{{Structname}} update basic, pointers and slice of pointers fields of {{structname}} // from respectively the basic fields and encoded fields of pointers and slices of pointers of {{structname}}API // this function uses frontRepo.map_ID_<structname> to decode the encoded fields // a condition is that those maps has to be initialized before export function Copy{{Structname}}APITo{{Structname}}({{structname}}API: {{Structname}}API, {{structname}}: {{Structname}}, frontRepo: FrontRepo) { {{structname}}.CreatedAt = {{structname}}API.CreatedAt {{structname}}.DeletedAt = {{structname}}API.DeletedAt {{structname}}.ID = {{structname}}API.ID // insertion point for basic fields copy operations{{` + string(rune(NgClassTsInsertionPerStructBasicFieldsCopyFromAPI)) + `}} // insertion point for pointer fields encoding{{` + string(rune(NgClassTsInsertionPerStructPointerFieldsCopyFromAPI)) + `}} // insertion point for slice of pointers fields encoding{{` + string(rune(NgClassTsInsertionPerStructSliceOfPointersFieldsCopyFromAPI)) + `}} } `
const NgCommitNbFromBackTemplateTS = `` /* 2810-byte string literal not displayed */
const NgEnumTemplateTS = `// generated from ng_file_enum.ts.go export enum {{EnumName}} { // insertion point {{` + string(rune(NgEnumInsertionPointEnumDeclaration)) + `}} } export interface {{EnumName}}Select { value: {{type}}; viewValue: string; } export const {{EnumName}}List: {{EnumName}}Select[] = [ // insertion point {{` + string(rune(NgEnumValuesInsertionPointDeclarationForPullDownSelect)) + `}} ]; `
const NgFileAppComponentHtml = `` /* 3315-byte string literal not displayed */
const NgFileAppComponentTs = `` /* 2699-byte string literal not displayed */
const NgFileAppConfig = `` /* 434-byte string literal not displayed */
const NgFileIndex = `` /* 422-byte string literal not displayed */
const NgFileModuleSpecific = `` /* 741-byte string literal not displayed */
const NgLibFrontRepoServiceTemplate = `import { Injectable } from '@angular/core' import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http' import { Observable, combineLatest, BehaviorSubject, of } from 'rxjs' // insertion point sub template for services imports{{` + string(rune(NgLibFrontRepoServiceImports)) + `}} import { BackRepoData } from './back-repo-data' export const StackType = "{{PkgPathRoot}}/models" // FrontRepo stores all instances in a front repository (design pattern repository) export class FrontRepo { // insertion point sub template{{` + string(rune(NgLibFrontRepoMapDecl)) + `}} public GONG__Index = -1 // getFrontArray allows for a get function that is robust to refactoring of the named struct name // for instance frontRepo.getArray<Astruct>( Astruct.GONGSTRUCT_NAME), is robust to a refactoring of Astruct identifier // contrary to frontRepo.Astructs_array which is not refactored when Astruct identifier is modified getFrontArray<Type>(gongStructName: string): Array<Type> { switch (gongStructName) { // insertion point{{` + string(rune(NgLibFrontRepoSwitchGetFrontArray)) + `}} default: throw new Error("Type not recognized"); } } getFrontMap<Type>(gongStructName: string): Map<number, Type> { switch (gongStructName) { // insertion point{{` + string(rune(NgLibFrontRepoSwitchGetFrontMap)) + `}} default: throw new Error("Type not recognized"); } } } // the table component is called in different ways // // DISPLAY or ASSOCIATION MODE // // in ASSOCIATION MODE, it is invoked within a diaglo and a Dialog Data item is used to // configure the component // DialogData define the interface for information that is forwarded from the calling instance to // the select table export class DialogData { ID: number = 0 // ID of the calling instance // the reverse pointer is the name of the generated field on the destination // struct of the ONE-MANY association ReversePointer: string = "" // field of {{Structname}} that serve as reverse pointer OrderingMode: boolean = false // if true, this is for ordering items // there are different selection mode : ONE_MANY or MANY_MANY SelectionMode: SelectionMode = SelectionMode.ONE_MANY_ASSOCIATION_MODE // used if SelectionMode is MANY_MANY_ASSOCIATION_MODE // // In Gong, a MANY-MANY association is implemented as a ONE-ZERO/ONE followed by a ONE_MANY association // // in the MANY_MANY_ASSOCIATION_MODE case, we need also the Struct and the FieldName that are // at the end of the ONE-MANY association SourceStruct: string = "" // The "Aclass" SourceField: string = "" // the "AnarrayofbUse" IntermediateStruct: string = "" // the "AclassBclassUse" IntermediateStructField: string = "" // the "Bclass" as field NextAssociationStruct: string = "" // the "Bclass" GONG__StackPath: string = "" } export enum SelectionMode { ONE_MANY_ASSOCIATION_MODE = "ONE_MANY_ASSOCIATION_MODE", MANY_MANY_ASSOCIATION_MODE = "MANY_MANY_ASSOCIATION_MODE", } // // observable that fetch all elements of the stack and store them in the FrontRepo // @Injectable({ providedIn: 'root' }) export class FrontRepoService { GONG__StackPath: string = "" private socket: WebSocket | undefined httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) }; // // Store of all instances of the stack // frontRepo = new (FrontRepo) constructor( private http: HttpClient, // insertion point sub template {{` + string(rune(NgLibFrontRepoServiceDecl)) + `}} ) { } // postService provides a post function for each struct name postService(structName: string, instanceToBePosted: any) { let service = this[structName.toLowerCase() + "Service" + "Service" as keyof FrontRepoService] let servicePostFunction = service[("post" + structName) as keyof typeof service] as (instance: typeof instanceToBePosted) => Observable<typeof instanceToBePosted> servicePostFunction(instanceToBePosted).subscribe( instance => { let behaviorSubject = instanceToBePosted[(structName + "ServiceChanged") as keyof typeof instanceToBePosted] as unknown as BehaviorSubject<string> behaviorSubject.next("post") } ); } // deleteService provides a delete function for each struct name deleteService(structName: string, instanceToBeDeleted: any) { let service = this[structName.toLowerCase() + "Service" as keyof FrontRepoService] let serviceDeleteFunction = service["delete" + structName as keyof typeof service] as (instance: typeof instanceToBeDeleted) => Observable<typeof instanceToBeDeleted> serviceDeleteFunction(instanceToBeDeleted).subscribe( instance => { let behaviorSubject = instanceToBeDeleted[(structName + "ServiceChanged") as keyof typeof instanceToBeDeleted] as unknown as BehaviorSubject<string> behaviorSubject.next("delete") } ); } // typing of observable can be messy in typescript. Therefore, one force the type observableFrontRepo!: [ Observable<null>, // see below for the of(null) observable // insertion point sub template {{` + string(rune(NgLibFrontRepoObservableArrayType)) + `}} ]; // // pull performs a GET on all struct of the stack and redeem association pointers // // This is an observable. Therefore, the control flow forks with // - pull() return immediatly the observable // - the observable observer, if it subscribe, is called when all GET calls are performs pull(GONG__StackPath: string = ""): Observable<FrontRepo> { this.GONG__StackPath = GONG__StackPath this.observableFrontRepo = [ of(null), // see above for justification // insertion point sub template{{` + string(rune(NgLibFrontRepoObservableRefs)) + `}} ] return new Observable<FrontRepo>( (observer) => { combineLatest( this.observableFrontRepo ).subscribe( ([ ___of_null, // see above for the explanation about of // insertion point sub template for declarations {{` + string(rune(NgLibFrontRepoArraysDecls)) + `}} ]) => { let _this = this // Typing can be messy with many items. Therefore, type casting is necessary here // insertion point sub template for type casting {{` + string(rune(NgLibFrontRepoTypeCasting)) + `}} // // First Step: init map of instances // insertion point sub template for init {{` + string(rune(NgLibFrontRepoInitMapInstances)) + `}} // // Second Step: reddeem front objects // insertion point sub template for redeem {{` + string(rune(NgLibFrontRepoInitFrontObjects)) + `}} // hand over control flow to observer observer.next(this.frontRepo) } ) } ) } public connectToWebSocket(GONG__StackPath: string): Observable<FrontRepo> { this.GONG__StackPath = GONG__StackPath let params = new HttpParams().set("GONG__StackPath", this.GONG__StackPath) let basePath = 'ws://localhost:8080/api/{{PkgPathRoot}}/v1/ws/stage' let paramString = params.toString() let url = ` + "`" + "${basePath}?${paramString}" + "`" + ` this.socket = new WebSocket(url) return new Observable(observer => { this.socket!.onmessage = event => { const backRepoData = new BackRepoData(JSON.parse(event.data)) let frontRepo = new (FrontRepo) frontRepo.GONG__Index = backRepoData.GONG__Index // // First Step: init map of instances // insertion point sub template for init // init the arrays // insertion point sub template for init {{` + string(rune(NgLibFrontRepoInitMapInstancesFromWebSocket)) + `}} // // Second Step: reddeem front objects // insertion point sub template for redeem // fill up front objects // insertion point sub template for redeem {{` + string(rune(NgLibFrontRepoInitFrontObjectsFromWebSocket)) + `}} observer.next(frontRepo) } this.socket!.onerror = event => { observer.error(event) } this.socket!.onclose = event => { observer.complete() } return () => { this.socket!.close() } }) } } // insertion point for get unique ID per struct {{` + string(rune(NgLibFrontRepoPerStructGetUniqueID)) + `}} `
const NgLibModuleTemplate = `` /* 165-byte string literal not displayed */
const NgNullInt64TemplateTS = `` /* 151-byte string literal not displayed */
const NgPublicApiTemplateTS = `// generated from ng_file_public_api_ts.go /* * Public API Surface of {{PkgName}} */ export * from './lib/{{pkgname}}.module' export * from './lib/front-repo.service' export * from './lib/null-int64' export * from './lib/commitnbfromback.service' export * from './lib/push_from_front_nb.service' export * from './lib/back-repo-data' export * from './lib/web-socket-service' {{` + string(rune(NgPublicApiInsertionStructComponentsExportDeclaration)) + `}} {{` + string(rune(NgPublicApiInsertionEnumsExportDeclaration)) + `}} `
const NgPushFromFrontTemplateTS = `` /* 3055-byte string literal not displayed */
const NgServiceTmpl = `// generated by ng_file_service_ts import { Injectable, Component, Inject } from '@angular/core'; import { HttpParams } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { DOCUMENT, Location } from '@angular/common' /* * Behavior subject */ import { BehaviorSubject } from 'rxjs' import { Observable, of } from 'rxjs' import { catchError, map, tap } from 'rxjs/operators' import { {{Structname}}API } from './{{structname}}-api' import { {{Structname}}, Copy{{Structname}}To{{Structname}}API } from './{{structname}}' import { FrontRepo, FrontRepoService } from './front-repo.service'; // insertion point for imports{{` + string(rune(NgServiceTsInsertionImports)) + `}} @Injectable({ providedIn: 'root' }) export class {{Structname}}Service { // Kamar Raïmo: Adding a way to communicate between components that share information // so that they are notified of a change. {{Structname}}ServiceChanged: BehaviorSubject<string> = new BehaviorSubject(""); private {{structname}}sUrl: string constructor( private http: HttpClient, @Inject(DOCUMENT) private document: Document ) { // path to the service share the same origin with the path to the document // get the origin in the URL to the document let origin = this.document.location.origin // if debugging with ng, replace 4200 with 8080 origin = origin.replace("4200", "8080") // compute path to the service this.{{structname}}sUrl = origin + '/api/{{PkgPathRoot}}/v1/{{structname}}s'; } /** GET {{structname}}s from the server */ // gets is more robust to refactoring gets(GONG__StackPath: string, frontRepo: FrontRepo): Observable<{{Structname}}API[]> { return this.get{{Structname}}s(GONG__StackPath, frontRepo) } get{{Structname}}s(GONG__StackPath: string, frontRepo: FrontRepo): Observable<{{Structname}}API[]> { let params = new HttpParams().set("GONG__StackPath", GONG__StackPath) return this.http.get<{{Structname}}API[]>(this.{{structname}}sUrl, { params: params }) .pipe( tap(), catchError(this.handleError<{{Structname}}API[]>('get{{Structname}}s', [])) ); } /** GET {{structname}} by id. Will 404 if id not found */ // more robust API to refactoring get(id: number, GONG__StackPath: string, frontRepo: FrontRepo): Observable<{{Structname}}API> { return this.get{{Structname}}(id, GONG__StackPath, frontRepo) } get{{Structname}}(id: number, GONG__StackPath: string, frontRepo: FrontRepo): Observable<{{Structname}}API> { let params = new HttpParams().set("GONG__StackPath", GONG__StackPath) const url = ` + "`" + `${this.{{structname}}sUrl}/${id}` + "`" + `; return this.http.get<{{Structname}}API>(url, { params: params }).pipe( // tap(_ => this.log(` + "`" + `fetched {{structname}} id=${id}` + "`" + `)), catchError(this.handleError<{{Structname}}API>(` + "`" + `get{{Structname}} id=${id}` + "`" + `)) ); } // postFront copy {{structname}} to a version with encoded pointers and post to the back postFront({{structname}}: {{Structname}}, GONG__StackPath: string): Observable<{{Structname}}API> { let {{structname}}API = new {{Structname}}API Copy{{Structname}}To{{Structname}}API({{structname}}, {{structname}}API) const id = typeof {{structname}}API === 'number' ? {{structname}}API : {{structname}}API.ID const url = ` + "`" + `${this.{{structname}}sUrl}/${id}` + "`" + `; let params = new HttpParams().set("GONG__StackPath", GONG__StackPath) let httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }), params: params } return this.http.post<{{Structname}}API>(url, {{structname}}API, httpOptions).pipe( tap(_ => { }), catchError(this.handleError<{{Structname}}API>('post{{Structname}}')) ); } /** POST: add a new {{structname}} to the server */ post({{structname}}db: {{Structname}}API, GONG__StackPath: string, frontRepo: FrontRepo): Observable<{{Structname}}API> { return this.post{{Structname}}({{structname}}db, GONG__StackPath, frontRepo) } post{{Structname}}({{structname}}db: {{Structname}}API, GONG__StackPath: string, frontRepo: FrontRepo): Observable<{{Structname}}API> { let params = new HttpParams().set("GONG__StackPath", GONG__StackPath) let httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }), params: params } return this.http.post<{{Structname}}API>(this.{{structname}}sUrl, {{structname}}db, httpOptions).pipe( tap(_ => { // this.log(` + "`" + `posted {{structname}}db id=${{{structname}}db.ID}` + "`" + `) }), catchError(this.handleError<{{Structname}}API>('post{{Structname}}')) ); } /** DELETE: delete the {{structname}}db from the server */ delete({{structname}}db: {{Structname}}API | number, GONG__StackPath: string): Observable<{{Structname}}API> { return this.delete{{Structname}}({{structname}}db, GONG__StackPath) } delete{{Structname}}({{structname}}db: {{Structname}}API | number, GONG__StackPath: string): Observable<{{Structname}}API> { const id = typeof {{structname}}db === 'number' ? {{structname}}db : {{structname}}db.ID; const url = ` + "`" + `${this.{{structname}}sUrl}/${id}` + "`" + `; let params = new HttpParams().set("GONG__StackPath", GONG__StackPath) let httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }), params: params }; return this.http.delete<{{Structname}}API>(url, httpOptions).pipe( tap(_ => this.log(` + "`" + `deleted {{structname}}db id=${id}` + "`" + `)), catchError(this.handleError<{{Structname}}API>('delete{{Structname}}')) ); } // updateFront copy {{structname}} to a version with encoded pointers and update to the back updateFront({{structname}}: {{Structname}}, GONG__StackPath: string): Observable<{{Structname}}API> { let {{structname}}API = new {{Structname}}API Copy{{Structname}}To{{Structname}}API({{structname}}, {{structname}}API) const id = typeof {{structname}}API === 'number' ? {{structname}}API : {{structname}}API.ID const url = ` + "`" + `${this.{{structname}}sUrl}/${id}` + "`" + `; let params = new HttpParams().set("GONG__StackPath", GONG__StackPath) let httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }), params: params } return this.http.put<{{Structname}}API>(url, {{structname}}API, httpOptions).pipe( tap(_ => { }), catchError(this.handleError<{{Structname}}API>('update{{Structname}}')) ); } /** PUT: update the {{structname}}db on the server */ update({{structname}}db: {{Structname}}API, GONG__StackPath: string, frontRepo: FrontRepo): Observable<{{Structname}}API> { return this.update{{Structname}}({{structname}}db, GONG__StackPath, frontRepo) } update{{Structname}}({{structname}}db: {{Structname}}API, GONG__StackPath: string, frontRepo: FrontRepo): Observable<{{Structname}}API> { const id = typeof {{structname}}db === 'number' ? {{structname}}db : {{structname}}db.ID; const url = ` + "`" + `${this.{{structname}}sUrl}/${id}` + "`" + `; let params = new HttpParams().set("GONG__StackPath", GONG__StackPath) let httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }), params: params }; return this.http.put<{{Structname}}API>(url, {{structname}}db, httpOptions).pipe( tap(_ => { // this.log(` + "`" + `updated {{structname}}db id=${{{structname}}db.ID}` + "`" + `) }), catchError(this.handleError<{{Structname}}API>('update{{Structname}}')) ); } /** * Handle Http operation that failed. * Let the app continue. * @param operation - name of the operation that failed * @param result - optional value to return as the observable result */ private handleError<T>(operation = 'operation in {{Structname}}Service', result?: T) { return (error: any): Observable<T> => { // TODO: send the error to remote logging infrastructure console.error("{{Structname}}Service" + error); // log to console instead // TODO: better job of transforming error for user consumption this.log(` + "`" + `${operation} failed: ${error.message}` + "`" + `); // Let the app keep running by returning an empty result. return of(result as T); }; } private log(message: string) { console.log(message) } } `
const StylesCssInsert = `
@import 'material-icons/iconfont/material-icons.css';
`
const TsConfigInsertForPaths = `` /* 205-byte string literal not displayed */
const WebSocketServiceTemplate = `import { Injectable } from '@angular/core'
import { Observable } from 'rxjs'
import { DOCUMENT } from '@angular/common';
import { HttpParams } from '@angular/common/http';
import { Component, Inject, Input, OnInit } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class WebSocketService {
private socket: WebSocket | undefined
public connect(stackPath: string): Observable<any> {
let params = new HttpParams().set("GONG__StackPath", stackPath)
let basePath = 'ws://localhost:8080/api/{{PkgPathRoot}}/v1/ws/stage'
let paramString = params.toString()
let url = ` + "`" + "${basePath}?${paramString}" + "`" + `
this.socket = new WebSocket(url)
return new Observable(observer => {
this.socket!.onmessage = event => {
observer.next(event)
}
this.socket!.onerror = event => {
observer.error(event)
}
this.socket!.onclose = event => {
observer.complete()
}
return () => {
this.socket!.close()
}
})
}
}
`
Variables ¶
var BackRepoHtmlSubTemplateCode map[string]string = map[string]string{ string(rune(BackRepoDataImports)): ` import { {{Structname}}API } from './{{structname}}-api' `, string(rune(BackRepoInsertionEnumsExportDeclaration)): ` {{Structname}}APIs = new Array<{{Structname}}API>() `, string(rune(BackRepoInsertionEnumsExportCopies)): ` this.{{Structname}}APIs = data?.{{Structname}}APIs || []; `, }
var NgClassAPISubTemplateCode map[NgClassAPISubTemplate]string = map[NgClassAPISubTemplate]string{ NgClassAPITSBasicFieldImports: ` import { {{AssocStructName}}API } from './{{assocStructName}}-api'`, NgClassAPITSBasicFieldDecls: ` {{FieldName}}: {{TypeInput}} = {{NullValue}}`, NgClassAPITSTimeFieldDecls: ` {{FieldName}}: Date = new Date`, NgClassAPITSPointerToStructFieldsEncodingDecl: ` {{FieldName}}ID: NullInt64 = new NullInt64 // if pointer is null, {{FieldName}}.ID = 0 `, NgClassAPIPointersEncodingTSSliceOfPtrToStructFieldsDecl: ` {{FieldName}}: number[] = []`, NgClassAPITSOtherDeclsTimeDuration: ` {{FieldName}}_string?: string`, NgClassAPITSOtherDeclsEnumInt: ` {{FieldName}}_string?: string`, }
var NgClassSubTemplateCode map[NgClassSubTemplate]string = map[NgClassSubTemplate]string{ NgClassTSBasicFieldImports: ` import { {{AssocStructName}} } from './{{assocStructName}}'`, NgClassTSBasicFieldDecls: ` {{FieldName}}: {{TypeInput}} = {{NullValue}}`, NgClassTSBasicFieldCopyToAPI: ` {{structname}}API.{{FieldName}} = {{structname}}.{{FieldName}}`, NgClassTSPointerFieldCopyToAPI: ` {{structname}}API.{{Structname}}PointersEncoding.{{FieldName}}ID.Valid = true if ({{structname}}.{{FieldName}} != undefined) { {{structname}}API.{{Structname}}PointersEncoding.{{FieldName}}ID.Int64 = {{structname}}.{{FieldName}}.ID } else { {{structname}}API.{{Structname}}PointersEncoding.{{FieldName}}ID.Int64 = 0 } `, NgClassTSSliceOfPointersFieldCopyToAPI: ` {{structname}}API.{{Structname}}PointersEncoding.{{FieldName}} = [] for (let _{{assocStructName}} of {{structname}}.{{FieldName}}) { {{structname}}API.{{Structname}}PointersEncoding.{{FieldName}}.push(_{{assocStructName}}.ID) } `, NgClassTSBasicFieldCopyFromAPI: ` {{structname}}.{{FieldName}} = {{structname}}API.{{FieldName}}`, NgClassTSPointerFieldCopyFromAPI: ` {{structname}}.{{FieldName}} = frontRepo.map_ID_{{AssocStructName}}.get({{structname}}API.{{Structname}}PointersEncoding.{{FieldName}}ID.Int64)`, NgClassTSSliceOfPointersFieldCopyFromAPI: ` if (!Array.isArray({{structname}}API.{{Structname}}PointersEncoding.{{FieldName}})) { console.error('Rects is not an array:', {{structname}}API.{{Structname}}PointersEncoding.{{FieldName}}); return; } {{structname}}.{{FieldName}} = new Array<{{AssocStructName}}>() for (let _id of {{structname}}API.{{Structname}}PointersEncoding.{{FieldName}}) { let _{{assocStructName}} = frontRepo.map_ID_{{AssocStructName}}.get(_id) if (_{{assocStructName}} != undefined) { {{structname}}.{{FieldName}}.push(_{{assocStructName}}!) } }`, NgClassTSTimeFieldDecls: ` {{FieldName}}: Date = new Date`, NgClassTSPointerToStructFieldsDecl: ` {{FieldName}}?: {{TypeInput}} `, NgClassTSSliceOfPtrToStructFieldsDecl: ` {{FieldName}}: Array<{{TypeInput}}> = []`, NgClassTSOtherDeclsTimeDuration: ` {{FieldName}}_string?: string`, NgClassTSOtherDeclsEnumInt: ` {{FieldName}}_string?: string`, }
var NgEnumHtmlSubTemplateCode map[NgEnumSubTemplate]string = map[NgEnumSubTemplate]string{ NgEnumDeclaration: ` {{ConstName}} = {{ConstValue}},`, NgEnumDeclarationForPullDownSelect: ` { value: {{EnumName}}.{{ConstName}}, viewValue: {{ConstValue}} },`, }
var NgFrontRepoPerStructTmplCodes map[FrontRepoInsertionPointId]string = map[FrontRepoInsertionPointId]string{ NgLibFrontRepoServiceImports: ` import { {{Structname}}API } from './{{structname}}-api' import { {{Structname}}, Copy{{Structname}}APITo{{Structname}} } from './{{structname}}' import { {{Structname}}Service } from './{{structname}}.service' `, NgLibFrontRepoMapDecl: ` array_{{Structname}}s = new Array<{{Structname}}>() // array of front instances map_ID_{{Structname}} = new Map<number, {{Structname}}>() // map of front instances `, NgLibFrontRepoSwitchGetFrontArray: ` case '{{Structname}}': return this.array_{{Structname}}s as unknown as Array<Type>`, NgLibFrontRepoSwitchGetFrontMap: ` case '{{Structname}}': return this.map_ID_{{Structname}} as unknown as Map<number, Type>`, NgLibFrontRepoObservableArrayType: ` Observable<{{Structname}}API[]>,`, NgLibFrontRepoServiceDecl: ` private {{structname}}Service: {{Structname}}Service,`, NgLibFrontRepoObservableRefs: ` this.{{structname}}Service.get{{Structname}}s(this.GONG__StackPath, this.frontRepo),`, NgLibFrontRepoArraysDecls: ` {{structname}}s_,`, NgLibFrontRepoTypeCasting: ` var {{structname}}s: {{Structname}}API[] {{structname}}s = {{structname}}s_ as {{Structname}}API[]`, NgLibFrontRepoInitMapInstances: ` // init the arrays this.frontRepo.array_{{Structname}}s = [] this.frontRepo.map_ID_{{Structname}}.clear() {{structname}}s.forEach( {{structname}}API => { let {{structname}} = new {{Structname}} this.frontRepo.array_{{Structname}}s.push({{structname}}) this.frontRepo.map_ID_{{Structname}}.set({{structname}}API.ID, {{structname}}) } ) `, NgLibFrontRepoInitMapInstancesFromWebSocket: ` // init the arrays frontRepo.array_{{Structname}}s = [] frontRepo.map_ID_{{Structname}}.clear() backRepoData.{{Structname}}APIs.forEach( {{structname}}API => { let {{structname}} = new {{Structname}} frontRepo.array_{{Structname}}s.push({{structname}}) frontRepo.map_ID_{{Structname}}.set({{structname}}API.ID, {{structname}}) } ) `, NgLibFrontRepoInitFrontObjects: ` // fill up front objects {{structname}}s.forEach( {{structname}}API => { let {{structname}} = this.frontRepo.map_ID_{{Structname}}.get({{structname}}API.ID) Copy{{Structname}}APITo{{Structname}}({{structname}}API, {{structname}}!, this.frontRepo) } ) `, NgLibFrontRepoInitFrontObjectsFromWebSocket: ` // fill up front objects backRepoData.{{Structname}}APIs.forEach( {{structname}}API => { let {{structname}} = frontRepo.map_ID_{{Structname}}.get({{structname}}API.ID) Copy{{Structname}}APITo{{Structname}}({{structname}}API, {{structname}}!, frontRepo) } ) `, NgLibFrontRepoRedeemPointers: ` {{structname}}s.forEach( {{structname}} => { // insertion point sub sub template for ONE-/ZERO-ONE associations pointers redeeming{{` + string(rune(NgFrontRepoPtrToStructRedeeming)) + `}} } )`, NgLibFrontRepoSlicesOfPointersDecode: ` {{structname}}s.forEach( {{structname}} => { // insertion point sub sub template for ONE-/ZERO-ONE associations pointers redeeming{{` + string(rune(NgFrontRepoPtrToStructRedeeming)) + `}} // insertion point for pointers decoding{{` + string(rune(NgFrontRepoSliceOfPointerSorting)) + `}} } )`, NgLibFrontRepoPerStructGetUniqueID: ` export function get{{Structname}}UniqueID(id: number): number { return {{Prime}} * id }`, }
var NgFrontRepoPtrToStructTmplCodes map[NgLibFrontRepoServiceSubSubTemplate]string = map[NgLibFrontRepoServiceSubSubTemplate]string{ NgFrontRepoPtrToStructRedeeming: ` // insertion point for pointer field {{FieldName}} redeeming { let _{{assocStructName}} = this.frontRepo.{{AssocStructName}}s.get({{structname}}.{{Structname}}PointersEncoding.{{FieldName}}ID.Int64) if (_{{assocStructName}}) { {{structname}}.{{FieldName}} = _{{assocStructName}} } }`, NgFrontRepoSliceOfPointerSorting: ` {{structname}}.{{FieldName}} = new Array<{{AssocStructName}}API>() for (let _id of {{structname}}.{{Structname}}PointersEncoding.{{FieldName}}) { let _{{assocStructName}} = this.frontRepo.{{AssocStructName}}s.get(_id) if (_{{assocStructName}} != undefined) { {{structname}}.{{FieldName}}.push(_{{assocStructName}}!) } }`, }
var NgLibFrontRepoPointerToStructSubSubToSubMap map[NgLibFrontRepoServiceSubSubTemplate]string = map[NgLibFrontRepoServiceSubSubTemplate]string{ NgFrontRepoPtrToStructRedeeming: string(rune(NgLibFrontRepoRedeemPointers)), }
for each sub sub template, what sub template it relates to
var NgPublicApiHtmlSubTemplateCode map[NgPublicApiSubTemplate]string = map[NgPublicApiSubTemplate]string{ NgPublicApiStructComponentsExportDeclaration: ` export * from './lib/{{structname}}-api' export * from './lib/{{structname}}' export * from './lib/{{structname}}.service' `, NgPublicApiDEnumsExportDeclaration: ` export * from './lib/{{Enumname}}'`, }
var NgServiceSubTemplateCode map[NgServiceSubTemplate]string = map[NgServiceSubTemplate]string{ NgServiceTSPointerToGongStructImports: ` import { {{AssocStructName}}API } from './{{assocStructName}}-api'`, }
Functions ¶
func CodeGeneratorNgCommitNbFromBack ¶
MultiCodeGeneratorNgCommitNb parses mdlPkg and generates the code for the CommitNb components
func CodeGeneratorNgEnum ¶
MultiCodeGeneratorNgEnum parses mdlPkg and generates the code for the Enum components
func CodeGeneratorNgNullInt64 ¶
MultiCodeGeneratorNgCommitNb parses mdlPkg and generates the code for the CommitNb components
func CodeGeneratorNgPublicApi ¶
MultiCodeGeneratorNgPublicApi parses mdlPkg and generates the code for the PublicApi components
func CodeGeneratorNgPushFromFrontNb ¶
MultiCodeGeneratorNgPushFromFrontNb parses mdlPkg and generates the code for the PushFromFrontNb components
func MultiCodeGeneratorNgClass ¶
MultiCodeGeneratorNgTable generates the code for the Detail components
func MultiCodeGeneratorNgClassAPI ¶
MultiCodeGeneratorNgTable generates the code for the Detail components
func MultiCodeGeneratorNgService ¶
MultiCodeGeneratorNgService generates the code for the services
Types ¶
type BackRepoDataTSInsertionPoint ¶
type BackRepoDataTSInsertionPoint int
insertion points
const ( BackRepoDataImports BackRepoDataTSInsertionPoint = iota BackRepoInsertionEnumsExportDeclaration BackRepoInsertionEnumsExportCopies BackRepoNbInsertionPoints )
type FrontRepoInsertionPointId ¶
type FrontRepoInsertionPointId int
const ( NgLibFrontRepoServiceImports FrontRepoInsertionPointId = iota NgLibFrontRepoMapDecl NgLibFrontRepoSwitchGetFrontArray NgLibFrontRepoSwitchGetFrontMap NgLibFrontRepoObservableArrayType NgLibFrontRepoTypeCasting NgLibFrontRepoServiceDecl NgLibFrontRepoObservableRefs NgLibFrontRepoArraysDecls NgLibFrontRepoInitMapInstances NgLibFrontRepoInitMapInstancesFromWebSocket NgLibFrontRepoRedeemPointers NgLibFrontRepoInitFrontObjects NgLibFrontRepoInitFrontObjectsFromWebSocket NgLibFrontRepoSlicesOfPointersDecode NgLibFrontRepoPerStructGetUniqueID )
type NgClassAPISubTemplate ¶
type NgClassAPISubTemplate int
const ( NgClassAPITSBasicFieldImports NgClassAPISubTemplate = iota NgClassAPITSBasicFieldDecls NgClassAPITSTimeFieldDecls NgClassAPITSOtherDecls NgClassAPITSPointerToStructFieldsEncodingDecl NgClassAPIPointersEncodingTSSliceOfPtrToStructFieldsDecl NgClassAPITSOtherDeclsTimeDuration NgClassAPITSOtherDeclsEnumInt )
type NgClassAPITsInsertionPoint ¶
type NgClassAPITsInsertionPoint int
Insertion points insertion points in the main template
const ( NgClassAPITsInsertionPerStructImports NgClassAPITsInsertionPoint = iota NgClassAPITsInsertionPerStructBasicFieldsDecl NgClassAPITsInsertionPerStructOtherDecls NgClassAPITsInsertionPerStructPointersEncoding NgClassAPITsInsertionsNb )
type NgClassSubTemplate ¶
type NgClassSubTemplate int
const ( NgClassTSBasicFieldImports NgClassSubTemplate = iota NgClassTSBasicFieldDecls NgClassTSBasicFieldCopyToAPI NgClassTSPointerFieldCopyToAPI NgClassTSSliceOfPointersFieldCopyToAPI NgClassTSBasicFieldCopyFromAPI NgClassTSPointerFieldCopyFromAPI NgClassTSSliceOfPointersFieldCopyFromAPI NgClassTSTimeFieldDecls NgClassTSOtherDecls NgClassTSPointerToStructFieldsDecl NgClassTSSliceOfPtrToStructFieldsDecl NgClassTSOtherDeclsTimeDuration NgClassTSOtherDeclsEnumInt )
type NgClassTsInsertionPoint ¶
type NgClassTsInsertionPoint int
Insertion points insertion points in the main template
const ( NgClassTsInsertionPerStructImports NgClassTsInsertionPoint = iota NgClassTsInsertionPerStructBasicFieldsDecl NgClassTsInsertionPerStructBasicFieldsCopyToAPI NgClassTsInsertionPerStructPointerFieldsCopyToAPI NgClassTsInsertionPerStructSliceOfPointersFieldsCopyToAPI NgClassTsInsertionPerStructBasicFieldsCopyFromAPI NgClassTsInsertionPerStructPointerFieldsCopyFromAPI NgClassTsInsertionPerStructSliceOfPointersFieldsCopyFromAPI NgClassTsInsertionPerStructOtherDecls NgClassTsInsertionsNb )
type NgEnumInsertionPoint ¶
type NgEnumInsertionPoint int
insertion points
const ( NgEnumInsertionPointEnumDeclaration NgEnumInsertionPoint = iota NgEnumValuesInsertionPointDeclarationForPullDownSelect NgEnumNbInsertionPoints )
type NgEnumSubTemplate ¶
type NgEnumSubTemplate int
Sub Templates
const ( NgEnumDeclaration NgEnumSubTemplate = iota NgEnumDeclarationForPullDownSelect )
type NgLibFrontRepoServiceSubSubTemplate ¶
type NgLibFrontRepoServiceSubSubTemplate int
const ( NgFrontRepoPtrToStructRedeeming NgLibFrontRepoServiceSubSubTemplate = iota + 1789 NgFrontRepoSliceOfPointerSorting )
type NgPublicApiInsertionPoint ¶
type NgPublicApiInsertionPoint int
insertion points
const ( NgPublicApiInsertionStructComponentsExportDeclaration NgPublicApiInsertionPoint = iota NgPublicApiInsertionEnumsExportDeclaration NgPublicApiNbInsertionPoints )
type NgPublicApiSubTemplate ¶
type NgPublicApiSubTemplate int
Sub Templates
const ( NgPublicApiStructComponentsExportDeclaration NgPublicApiSubTemplate = iota NgPublicApiDEnumsExportDeclaration )
type NgServiceSubTemplate ¶
type NgServiceSubTemplate int
const ( NgServiceTSPointerToGongStructImports NgServiceSubTemplate = iota NgServiceTSReversePointerToSliceOfGongStructImports )
type NgServiceTsInsertionPoint ¶
type NgServiceTsInsertionPoint int
Insertion points insertion points in the main template
const ( NgServiceTsInsertionImports NgServiceTsInsertionPoint = iota NgServiceTsInsertionsNb )
Source Files
¶
- back_repo_data.go
- front-repo.service.go
- go_file_emebd_ng_dist_ng.go
- ng_file_app_component_html.go
- ng_file_app_component_ts.go
- ng_file_app_config.go
- ng_file_commit_nb_from_back_ts.go
- ng_file_enum_ts.go
- ng_file_index.go
- ng_file_module_specific.go
- ng_file_null_int64_ts.go
- ng_file_public_api_ts.go
- ng_file_push_from_front_nb_ts.go
- ng_file_service_ts.go
- ng_lib_module.go
- per_struct_class-db.go
- per_struct_class.go
- styles_css_insert.go
- tsconfig_imports.go
- web-socket-service.go