@microsoft/paris
Advanced tools
Comparing version 1.3.7 to 1.3.8
@@ -1,2 +0,6 @@ | ||
import { AjaxRequest } from "rxjs/ajax"; | ||
import { AjaxRequest, AjaxResponse } from "rxjs/ajax"; | ||
import { Observable } from "rxjs"; | ||
export interface AjaxService { | ||
(urlOrRequest: string | AjaxRequest): Observable<AjaxResponse>; | ||
} | ||
export interface ParisConfig<TConfigData = any> { | ||
@@ -8,3 +12,4 @@ apiRoot?: string; | ||
http?: AjaxRequest; | ||
ajaxService?: AjaxService; | ||
} | ||
export declare const defaultConfig: Partial<ParisConfig>; |
import { Observable } from "rxjs"; | ||
import { AjaxRequest } from "rxjs/ajax"; | ||
import { ParisConfig } from "../config/paris-config"; | ||
import { HttpOptions, RequestMethod, SaveRequestMethod } from "./http.service"; | ||
import { Http, HttpOptions, RequestMethod, SaveRequestMethod } from "./http.service"; | ||
export declare class DataStoreService { | ||
private config; | ||
private activeRequests; | ||
readonly httpService: Http; | ||
constructor(config: ParisConfig); | ||
@@ -9,0 +10,0 @@ get<T = any>(endpoint: string, data?: HttpOptions, baseUrl?: string, httpConfig?: AjaxRequest): Observable<T>; |
@@ -8,2 +8,3 @@ import * as jsonStringify from 'json-stringify-safe'; | ||
this.activeRequests = new Map(); | ||
this.httpService = new Http(config.ajaxService); | ||
} | ||
@@ -23,3 +24,3 @@ DataStoreService.prototype.get = function (endpoint, data, baseUrl, httpConfig) { | ||
var endpointUrl = this.getEndpointUrl(endpoint, baseUrl); | ||
return this.setActiveRequest(Http.request(method, endpointUrl, data, fullHttpConfig), method, endpointUrl, data); | ||
return this.setActiveRequest(this.httpService.request(method, endpointUrl, data, fullHttpConfig), method, endpointUrl, data); | ||
}; | ||
@@ -26,0 +27,0 @@ DataStoreService.prototype.getEndpointUrl = function (endpoint, baseUrl) { |
import { Observable } from "rxjs"; | ||
import { AjaxRequest } from "rxjs/ajax"; | ||
import { AjaxService } from "../config/paris-config"; | ||
export declare type SaveRequestMethod = "POST" | "PUT" | "PATCH"; | ||
export declare type RequestMethod = "GET" | "DELETE" | SaveRequestMethod; | ||
export declare class Http { | ||
static get(url: string, options?: HttpOptions, httpConfig?: AjaxRequest): Observable<any>; | ||
static post(url: string, options?: HttpOptions, httpConfig?: AjaxRequest): Observable<any>; | ||
static put(url: string, options?: HttpOptions, httpConfig?: AjaxRequest): Observable<any>; | ||
static delete(url: string, options?: HttpOptions, httpConfig?: AjaxRequest): Observable<any>; | ||
static patch(url: string, options?: HttpOptions, httpConfig?: AjaxRequest): Observable<any>; | ||
static request<T = any>(method: RequestMethod, url: string, options?: HttpOptions, httpConfig?: AjaxRequest): Observable<any>; | ||
private ajaxService?; | ||
constructor(ajaxService?: AjaxService); | ||
get(url: string, options?: HttpOptions, httpConfig?: AjaxRequest): Observable<any>; | ||
post(url: string, options?: HttpOptions, httpConfig?: AjaxRequest): Observable<any>; | ||
put(url: string, options?: HttpOptions, httpConfig?: AjaxRequest): Observable<any>; | ||
delete(url: string, options?: HttpOptions, httpConfig?: AjaxRequest): Observable<any>; | ||
patch(url: string, options?: HttpOptions, httpConfig?: AjaxRequest): Observable<any>; | ||
request<T = any>(method: RequestMethod, url: string, options?: HttpOptions, httpConfig?: AjaxRequest): Observable<any>; | ||
static httpOptionsToRequestInit(options?: HttpOptions, httpConfig?: AjaxRequest): AjaxRequest; | ||
@@ -13,0 +16,0 @@ static addParamsToUrl(url: string, params?: UrlParams, separateArrayParams?: boolean): string; |
@@ -6,20 +6,21 @@ import { ajax } from "rxjs/ajax"; | ||
var Http = /** @class */ (function () { | ||
function Http() { | ||
function Http(ajaxService) { | ||
this.ajaxService = ajaxService; | ||
} | ||
Http.get = function (url, options, httpConfig) { | ||
return Http.request("GET", url, options, httpConfig); | ||
Http.prototype.get = function (url, options, httpConfig) { | ||
return this.request("GET", url, options, httpConfig); | ||
}; | ||
Http.post = function (url, options, httpConfig) { | ||
return Http.request("POST", url, options, httpConfig); | ||
Http.prototype.post = function (url, options, httpConfig) { | ||
return this.request("POST", url, options, httpConfig); | ||
}; | ||
Http.put = function (url, options, httpConfig) { | ||
return Http.request("PUT", url, options, httpConfig); | ||
Http.prototype.put = function (url, options, httpConfig) { | ||
return this.request("PUT", url, options, httpConfig); | ||
}; | ||
Http.delete = function (url, options, httpConfig) { | ||
return Http.request("DELETE", url, options, httpConfig); | ||
Http.prototype.delete = function (url, options, httpConfig) { | ||
return this.request("DELETE", url, options, httpConfig); | ||
}; | ||
Http.patch = function (url, options, httpConfig) { | ||
return Http.request("PATCH", url, options, httpConfig); | ||
Http.prototype.patch = function (url, options, httpConfig) { | ||
return this.request("PATCH", url, options, httpConfig); | ||
}; | ||
Http.request = function (method, url, options, httpConfig) { | ||
Http.prototype.request = function (method, url, options, httpConfig) { | ||
var fullUrl = options && options.params ? Http.addParamsToUrl(url, options.params, options.separateArrayParams) : url; | ||
@@ -37,3 +38,3 @@ var currentHttpConfig = clone(httpConfig); | ||
} | ||
return ajax(Object.assign({ | ||
return (this.ajaxService || ajax)(Object.assign({ | ||
method: method, | ||
@@ -40,0 +41,0 @@ url: fullUrl, |
@@ -21,3 +21,3 @@ export { DataQuery } from "./data_access/data-query"; | ||
export { EntityModelConfigBase } from "./config/entity-config-base.interface"; | ||
export { ParisConfig } from "./config/paris-config"; | ||
export { AjaxService, ParisConfig } from "./config/paris-config"; | ||
export { DataTransformersService, DataTransformer } from "./modeling/data-transformers.service"; | ||
@@ -24,0 +24,0 @@ export { ModelEntity, EntityConfig, ModelEntityCacheConfig } from "./config/entity.config"; |
{ | ||
"name": "@microsoft/paris", | ||
"version": "1.3.7", | ||
"version": "1.3.8", | ||
"description": "Library for the implementation of Domain Driven Design with TypeScript + RxJS", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -1,9 +0,8 @@ | ||
import {DataStoreService} from "../../lib/data_access/data-store.service"; | ||
import {Http} from "../../lib/data_access/http.service"; | ||
import {of} from "rxjs"; | ||
import {ParisConfig} from "../../lib/config/paris-config"; | ||
import { DataStoreService } from "../../lib/data_access/data-store.service"; | ||
import { of } from "rxjs"; | ||
import { ParisConfig } from "../../lib/config/paris-config"; | ||
describe('DataStore', () => { | ||
let dataStore:DataStoreService; | ||
let request:jest.Mock; | ||
let dataStore: DataStoreService; | ||
let request: jest.Mock; | ||
@@ -26,3 +25,3 @@ const endpoint = 'todo'; | ||
const parisConfig:ParisConfig = { | ||
const parisConfig: ParisConfig = { | ||
apiRoot: apiRoot, | ||
@@ -39,14 +38,14 @@ http: { | ||
dataStore = new DataStoreService(parisConfig); | ||
Http.request = request; | ||
dataStore.httpService.request = request; | ||
}); | ||
describe('Request', () => { | ||
it ('calls Http.request with the correct parameters (baseUrl)', () => { | ||
it('calls Http.request with the correct parameters (baseUrl)', () => { | ||
dataStore.request(getMethod, endpoint, httpOptions, baseUrl, localHttpConfig); | ||
expect(Http.request).toBeCalledWith(getMethod, `${baseUrl}/${endpoint}`, httpOptions, { ...parisConfig.http, ...localHttpConfig }); | ||
expect(dataStore.httpService.request).toBeCalledWith(getMethod, `${baseUrl}/${endpoint}`, httpOptions, { ...parisConfig.http, ...localHttpConfig }); | ||
}); | ||
it ('calls Http.request with the correct parameters (apiRoot)', () => { | ||
it('calls Http.request with the correct parameters (apiRoot)', () => { | ||
dataStore.request(getMethod, endpoint, httpOptions, null, localHttpConfig); | ||
expect(Http.request).toBeCalledWith(getMethod, `${apiRoot}/${endpoint}`, httpOptions, { ...parisConfig.http, ...localHttpConfig }); | ||
expect(dataStore.httpService.request).toBeCalledWith(getMethod, `${apiRoot}/${endpoint}`, httpOptions, { ...parisConfig.http, ...localHttpConfig }); | ||
}); | ||
@@ -53,0 +52,0 @@ }); |
@@ -7,3 +7,2 @@ import { Observable, of } from 'rxjs'; | ||
import { DataOptions, defaultDataOptions } from '../lib/data_access/data.options'; | ||
import { Http } from '../lib/data_access/http.service'; | ||
import { Paris } from '../lib/paris'; | ||
@@ -18,4 +17,4 @@ import { mergeMap } from '../node_modules/rxjs/operators'; | ||
import { UpdateTodoApiCall } from './mock/update-todo.api-call'; | ||
import {setMockData} from "./mock/mock-data.service"; | ||
import {DataSet} from "../lib/data_access/dataset"; | ||
import { setMockData } from "./mock/mock-data.service"; | ||
import { DataSet } from "../lib/data_access/dataset"; | ||
@@ -45,3 +44,3 @@ describe('Paris main', () => { | ||
it.skip("should return null if entity doesn't exist", () => {}); | ||
it.skip("should return null if entity doesn't exist", () => { }); | ||
}); | ||
@@ -51,12 +50,3 @@ | ||
let repo: Repository<Todo>, item$: Observable<Todo>; | ||
let httpRequestSpy: jest.SpyInstance<Http>; | ||
beforeAll(() => { | ||
httpRequestSpy = jest.spyOn(Http, 'request'); | ||
}); | ||
afterAll(() => { | ||
httpRequestSpy.mockRestore(); | ||
}); | ||
beforeEach(() => { | ||
@@ -66,2 +56,3 @@ paris = new Paris(); | ||
jest.spyOn(paris.dataStore.httpService, 'request'); | ||
jest.spyOn(repo, 'getItemById'); | ||
@@ -77,5 +68,8 @@ jest.spyOn(paris.dataStore, 'request'); | ||
it('should call Http.request with correct default params', () => { | ||
expect(Http.request).toHaveBeenCalledWith('GET', '/todo/1', undefined, { | ||
timeout: 20000, | ||
}); | ||
expect(paris.dataStore.httpService.request).toHaveBeenCalledWith( | ||
'GET', | ||
'/todo/1', | ||
undefined, | ||
{ timeout: 20000 } | ||
); | ||
}); | ||
@@ -89,3 +83,4 @@ | ||
it('should call Http.request with correct params', () => { | ||
expect(Http.request).toHaveBeenCalledWith( | ||
paris.getItemById(Todo, 1, null, { test: 1 }); | ||
expect(paris.dataStore.httpService.request).toHaveBeenCalledWith( | ||
'GET', | ||
@@ -102,3 +97,3 @@ '/todo/1', | ||
it.skip('should throw error if getItem is not supported', () => {}); | ||
it.skip('should throw error if getItem is not supported', () => { }); | ||
@@ -171,4 +166,4 @@ it('should call datastore.request', () => { | ||
it("should have a 'next' property in the DataSet", done => { | ||
paris.query(Todo).subscribe((dataSet:DataSet<Todo>) => { | ||
expect (dataSet.next).toEqual(next); | ||
paris.query(Todo).subscribe((dataSet: DataSet<Todo>) => { | ||
expect(dataSet.next).toEqual(next); | ||
done(); | ||
@@ -180,17 +175,9 @@ }); | ||
describe('apiCall', () => { | ||
let httpRequestSpy: jest.SpyInstance<Http>; | ||
let jestGetApiCallCacheSpy: jest.SpyInstance<Paris>; | ||
let jestMakeApiCallSpy: jest.SpyInstance<Paris>; | ||
beforeAll(() => { | ||
httpRequestSpy = jest.spyOn(Http, 'request'); | ||
}); | ||
afterAll(() => { | ||
httpRequestSpy.mockRestore(); | ||
}); | ||
beforeEach(() => { | ||
paris = new Paris(); | ||
jest.spyOn(paris.dataStore.httpService, 'request'); | ||
jestGetApiCallCacheSpy = jest.spyOn(paris, 'getApiCallCache' as any); | ||
@@ -212,3 +199,3 @@ jestMakeApiCallSpy = jest.spyOn(paris, 'makeApiCall' as any); | ||
expect((<any>paris).makeApiCall).not.toHaveBeenCalled(); | ||
expect(Http.request).not.toHaveBeenCalled(); | ||
expect(paris.dataStore.httpService.request).not.toHaveBeenCalled(); | ||
expect(fakeCache.get).toHaveBeenCalled(); | ||
@@ -241,25 +228,25 @@ }); | ||
it('should always add newer data to cache if cache exists', () => {}); | ||
it('should always add newer data to cache if cache exists', () => { }); | ||
it('should not cache null/undefined values', () => {}); | ||
it('should not cache null/undefined values', () => { }); | ||
it('should call makeApiCall with correct params', () => {}); | ||
it('should call makeApiCall with correct params', () => { }); | ||
it('should call makeApiCall with correct default params', () => {}); | ||
it('should call makeApiCall with correct default params', () => { }); | ||
it('should emit from error$ if encountered an error', () => {}); | ||
it('should emit from error$ if encountered an error', () => { }); | ||
it('should call modelArray if repo exists data is array', () => {}); | ||
it('should call modelArray if repo exists data is array', () => { }); | ||
it('should call createItem if repo exists and data is not an array', () => {}); | ||
it('should call createItem if repo exists and data is not an array', () => { }); | ||
it("should call DataTransformersService.parse if repo doesn't exist and data type is defined", () => {}); | ||
it("should call DataTransformersService.parse if repo doesn't exist and data type is defined", () => { }); | ||
it('should call parse if defined', () => {}); | ||
it('should call parse if defined', () => { }); | ||
it('should return an Observable', () => {}); | ||
it('should return an Observable', () => { }); | ||
it('should throw an error if no endpoint is configured', () => {}); | ||
it('should throw an error if no endpoint is configured', () => { }); | ||
it('should throw an error if no endpoint is configured', () => {}); | ||
it('should throw an error if no endpoint is configured', () => { }); | ||
@@ -270,5 +257,5 @@ it.skip('should call datastore.request', () => { | ||
it('should call Http.request with correct default params', () => {}); | ||
it('should call Http.request with correct default params', () => { }); | ||
it('should call Http.request with correct params', () => {}); | ||
it('should call Http.request with correct params', () => { }); | ||
}); | ||
@@ -280,11 +267,11 @@ | ||
}); | ||
it('should call makeApiCall with correct params', () => {}); | ||
it('should call makeApiCall with correct params', () => { }); | ||
it('should call makeApiCall with correct default params', () => {}); | ||
it('should call makeApiCall with correct default params', () => { }); | ||
it('should call rawDataToDataSet with correct params', () => {}); | ||
it('should call rawDataToDataSet with correct params', () => { }); | ||
it('should emit from error$ if encountered an error', () => {}); | ||
it('should emit from error$ if encountered an error', () => { }); | ||
it('should return an Observable', () => {}); | ||
it('should return an Observable', () => { }); | ||
@@ -295,5 +282,5 @@ it.skip('should call datastore.request', () => { | ||
it('should call Http.request with correct default params', () => {}); | ||
it('should call Http.request with correct default params', () => { }); | ||
it('should call Http.request with correct params', () => {}); | ||
it('should call Http.request with correct params', () => { }); | ||
}); | ||
@@ -325,5 +312,5 @@ | ||
}); | ||
it('should call RelationshipRepository.queryForItem with correct params', () => {}); | ||
it('should call RelationshipRepository.queryForItem with correct params', () => { }); | ||
it('should call RelationshipRepository.queryForItem with correct default params', () => {}); | ||
it('should call RelationshipRepository.queryForItem with correct default params', () => { }); | ||
@@ -334,3 +321,3 @@ it("should throw error if repo doesn't exist", () => { | ||
it('should return an Observable', () => {}); | ||
it('should return an Observable', () => { }); | ||
}); | ||
@@ -342,5 +329,5 @@ | ||
}); | ||
it('should call RelationshipRepository.getRelatedItem with correct params', () => {}); | ||
it('should call RelationshipRepository.getRelatedItem with correct params', () => { }); | ||
it('should call RelationshipRepository.getRelatedItem with correct default params', () => {}); | ||
it('should call RelationshipRepository.getRelatedItem with correct default params', () => { }); | ||
@@ -370,3 +357,3 @@ it("should throw error if the relationship repository doesn't exist", () => { | ||
it("should return null if repo doesn't exist", () => { | ||
class SomeClass {} | ||
class SomeClass { } | ||
expect(paris.getValue(SomeClass, 1)).toBe(null); | ||
@@ -373,0 +360,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
244473
4988