-import { Injectable } from '@angular/core';
+import {Injectable} from '@angular/core';
// Added globally by /IDL2js
declare var _preload_fieldmapper_IDL: Object;
/**
- * NOTE: To achieve full type strictness and avoid compile warnings,
- * we would likely have to pre-compile the IDL down to a .ts file with all
- * of the IDL class and field definitions.
- */
-
-/**
* Every IDL object class implements this interface.
*/
export interface EgIdlObject {
a: any[];
- classname: String;
- _isfieldmapper: Boolean;
+ classname: string;
+ _isfieldmapper: boolean;
// Dynamically appended functions from the IDL.
[fields: string]: any;
}
*
* constructor(private net : EgNetService) {
* ...
- * egNet.request(service, method, param1 [, param2, ...])
+ * this.net.request(service, method, param1 [, param2, ...])
* .subscribe(
* (res) => console.log('received one resopnse: ' + res),
* (err) => console.error('recived request error: ' + err),
* )
* );
* ...
+ *
+ * // Example translating a net request into a promise.
+ * this.net.request(service, method, param1)
+ * .toPromise().then(result => console.log(result));
+ *
* }
*
- * Each response is relayed via Observable onNext(). The interface is
+ * Each response is relayed via Observable.next(). The interface is
* the same for streaming and atomic requests.
*/
import {Injectable, EventEmitter} from '@angular/core';
declare var OpenSRF, OSRF_TRANSPORT_TYPE_WS;
export class EgNetRequest {
- service : String;
- method : String;
+ service : string;
+ method : string;
params : any[];
observer : Observer<any>;
- superseded : Boolean = false;
+ superseded : boolean = false;
// If set, this will be used instead of a one-off OpenSRF.ClientSession.
session? : any;
// True if we're using a single-use local session
// event will be available here.
evt: EgEvent;
- constructor(service: String, method: String, params: any[], session?: any) {
+ constructor(service: string, method: string, params: any[], session?: any) {
this.service = service;
this.method = method;
this.params = params;
}
// Standard request call -- Variadic params version
- request(service: String, method: String, ...params: any[]): Observable<any> {
+ request(service: string, method: string, ...params: any[]): Observable<any> {
return this.requestWithParamList(service, method, params);
}
// Array params version
- requestWithParamList(service: String,
- method: String, params: any[]): Observable<any> {
+ requestWithParamList(service: string,
+ method: string, params: any[]): Observable<any> {
return this.requestCompiled(
new EgNetRequest(service, method, params));
}
+ // Request with pre-compiled EgNetRequest
requestCompiled(request: EgNetRequest): Observable<any> {
return Observable.create(
observer => {
);
}
- // Version with pre-compiled EgNetRequest object
+ // Send the compiled request to the server via WebSockets
sendCompiledRequest(request: EgNetRequest): void {
OpenSRF.Session.transport = OSRF_TRANSPORT_TYPE_WS;
console.debug(`EgNet: request ${request.method}`);
request.session.request({
- async : true,
+ async : true, // WS only operates in async mode
method : request.method,
params : request.params,
oncomplete : () => {