angular

package
v0.0.0-...-2684b26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const BackRepoTemplateTS = `// generated code - do not edit

//insertion point for imports{{` + string(rune(BackRepoDataImports)) + `}}

export class BackRepoData {
	// insertion point for declarations{{` + string(rune(BackRepoInsertionEnumsExportDeclaration)) + `}}


	constructor(data?: Partial<BackRepoData>) {
		// insertion point for copies{{` + string(rune(BackRepoInsertionEnumsExportCopies)) + `}}
	}

}`
View Source
const EmebedNgDistNg = `` /* 191-byte string literal not displayed */
View Source
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)) + `}}
}
`
View Source
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)) + `}}
}
`
View Source
const NgCommitNbFromBackTemplateTS = `` /* 2828-byte string literal not displayed */
View Source
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)) + `}}
];
`
View Source
const NgFileAppComponentHtml = `` /* 1735-byte string literal not displayed */
View Source
const NgFileAppComponentTs = `` /* 727-byte string literal not displayed */
View Source
const NgFileIndex = `` /* 422-byte string literal not displayed */
View Source
const NgFileModule = `` /* 2772-byte string literal not displayed */
View Source
const NgFileModuleSpecific = `` /* 741-byte string literal not displayed */
View Source
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)) + `}}

	// 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)) + `}}
	] = [
			// Using "combineLatest" with a placeholder observable.
			//
			// This allows the typescript compiler to pass when no GongStruct is present in the front API
			//
			// The "of(null)" is a "meaningless" observable that emits a single value (null) and completes.
			// This is used as a workaround to satisfy TypeScript requirements and the "combineLatest" 
			// expectation for a non-empty array of observables.
			of(null), // 
			// insertion point sub template{{` + string(rune(NgLibFrontRepoObservableRefs)) + `}}
		];

	//
	// 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 => {
				let _this = this

				const backRepoData = new BackRepoData(JSON.parse(event.data))

				// 
				// 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(this.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)) + `}}
`
View Source
const NgLibModuleTemplate = `` /* 2114-byte string literal not displayed */
View Source
const NgNullInt64TemplateTS = `` /* 151-byte string literal not displayed */
View Source
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)) + `}}
`
View Source
const NgPushFromFrontTemplateTS = `` /* 3073-byte string literal not displayed */
View Source
const NgRoutingTemplate = `` /* 243-byte string literal not displayed */
View Source
const NgServiceTmpl = `// generated by ng_file_service_ts
import { Injectable, Component, Inject } from '@angular/core';
import { HttpClientModule, 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)
  }
}
`
View Source
const StylesCssInsert = `
@import '@fontsource/roboto';
@import '@fontsource/open-sans';
@import 'material-icons/iconfont/material-icons.css';
`
View Source
const TsConfigInsertForPaths = `` /* 2533-byte string literal not displayed */
View Source
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

View Source
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 || [];
`,
}
View Source
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`,
}
View Source
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: `
	{{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`,
}
View Source
var NgEnumHtmlSubTemplateCode map[NgEnumSubTemplate]string = map[NgEnumSubTemplate]string{
	NgEnumDeclaration: `
	{{ConstName}} = {{ConstValue}},`,

	NgEnumDeclarationForPullDownSelect: `
	{ value: {{EnumName}}.{{ConstName}}, viewValue: {{ConstValue}} },`,
}
View Source
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
				this.frontRepo.array_{{Structname}}s = []
				this.frontRepo.map_ID_{{Structname}}.clear()

				backRepoData.{{Structname}}APIs.forEach(
					{{structname}}API => {
						let {{structname}} = new {{Structname}}
						this.frontRepo.array_{{Structname}}s.push({{structname}})
						this.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}} = this.frontRepo.map_ID_{{Structname}}.get({{structname}}API.ID)
						Copy{{Structname}}APITo{{Structname}}({{structname}}API, {{structname}}!, this.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
}`,
}
View Source
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}}!)
									}
								}`,
}

for each sub sub template, what sub template it relates to

View Source
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}}'`,
}
View Source
var NgServiceSubTemplateCode map[NgServiceSubTemplate]string = map[NgServiceSubTemplate]string{

	NgServiceTSPointerToGongStructImports: `
import { {{AssocStructName}}API } from './{{assocStructName}}-api'`,
}

Functions

func CodeGeneratorNgCommitNbFromBack

func CodeGeneratorNgCommitNbFromBack(
	modelPkg *models.ModelPkg,
	apiPath string)

MultiCodeGeneratorNgCommitNb parses mdlPkg and generates the code for the CommitNb components

func CodeGeneratorNgEnum

func CodeGeneratorNgEnum(modelPkg *models.ModelPkg)

MultiCodeGeneratorNgEnum parses mdlPkg and generates the code for the Enum components

func CodeGeneratorNgFrontRepo

func CodeGeneratorNgFrontRepo(modelPkg *models.ModelPkg)

func CodeGeneratorNgNullInt64

func CodeGeneratorNgNullInt64(modelPkg *models.ModelPkg)

MultiCodeGeneratorNgCommitNb parses mdlPkg and generates the code for the CommitNb components

func CodeGeneratorNgPublicApi

func CodeGeneratorNgPublicApi(modelPkg *models.ModelPkg)

MultiCodeGeneratorNgPublicApi parses mdlPkg and generates the code for the PublicApi components

func CodeGeneratorNgPushFromFrontNb

func CodeGeneratorNgPushFromFrontNb(
	modelPkg *models.ModelPkg,
	apiPath string)

MultiCodeGeneratorNgPushFromFrontNb parses mdlPkg and generates the code for the PushFromFrontNb components

func MultiCodeGeneratorNgClass

func MultiCodeGeneratorNgClass(modelPkg *models.ModelPkg)

MultiCodeGeneratorNgTable generates the code for the Detail components

func MultiCodeGeneratorNgClassAPI

func MultiCodeGeneratorNgClassAPI(modelPkg *models.ModelPkg)

MultiCodeGeneratorNgTable generates the code for the Detail components

func MultiCodeGeneratorNgService

func MultiCodeGeneratorNgService(
	modelPkg *models.ModelPkg,
	apiPath string)

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
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL