New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

angular-in-memory-web-api

Package Overview
Dependencies
Maintainers
3
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-in-memory-web-api - npm Package Compare versions

Comparing version 0.4.3 to 0.4.4

27

backend.service.d.ts

@@ -17,2 +17,3 @@ import { Observable } from 'rxjs/Observable';

private passThruBackend;
protected requestInfoUtils: RequestInfoUtilities;
constructor(inMemDbService: InMemoryDbService, config?: InMemoryBackendConfigArgs);

@@ -121,17 +122,18 @@ protected readonly dbReady: Observable<boolean>;

* Generate the next available id for item in this collection
* Use method from `inMemDbService` if it exists and returns a value,
* else delegates to `genIdDefault`.
* @param collection - collection of items with `id` key property
* Use method from `inMemDbService` if it exists and returns a value,
* else delegates to genIdDefault
*/
protected genId<T extends {
id: any;
}>(collection: T[]): any;
}>(collection: T[], collectionName: string): any;
/**
* Default generator of the next available id for item in this collection
* This default implementation works only for numeric ids.
* @param collection - collection of items with `id` key property
* This default implementation assumes integer ids; returns `1` otherwise
* @param collectionName - name of the collection
*/
protected genIdDefault<T extends {
id: any;
}>(collection: T[]): any;
}>(collection: T[], collectionName: string): any;
protected get({collection, collectionName, headers, id, query, url}: RequestInfo): ResponseOptions;

@@ -150,2 +152,7 @@ /** Get JSON body from the request object */

/**
* Get utility methods from this service instance.
* Useful within an HTTP method override
*/
protected getRequestInfoUtils(): RequestInfoUtilities;
/**
* return canonical HTTP method name (lowercase) from the request object

@@ -159,4 +166,11 @@ * e.g. (req.method || 'get').toLowerCase();

/** Parse the id as a number. Return original value if not a number. */
protected parseId(id: string): any;
protected parseId(collection: any[], collectionName: string, id: string): any;
/**
* return true if can determine that the collection's `item.id` is a number
* This implementation can't tell if the collection is empty so it assumes NO
* */
protected isCollectionIdNumeric<T extends {
id: any;
}>(collection: T[], collectionName: string): boolean;
/**
* Parses the request URL into a `ParsedRequestUrl` object.

@@ -182,3 +196,2 @@ * Parsing depends upon certain values of `config`: `apiBase`, `host`, and `urlRoot`.

protected removeById(collection: any[], id: number): boolean;
protected readonly requestInfoUtils: RequestInfoUtilities;
/**

@@ -185,0 +198,0 @@ * Tell your in-mem "database" to reset.

@@ -24,2 +24,3 @@ import { Observable } from 'rxjs/Observable';

this.config = new InMemoryBackendConfig();
this.requestInfoUtils = this.getRequestInfoUtils();
var loc = this.getLocation('/');

@@ -88,3 +89,3 @@ this.config.host = loc.host; // default to app web server host

headers: this.createHeaders({ 'Content-Type': 'application/json' }),
id: this.parseId(parsed.id),
id: this.parseId(collection, collectionName, parsed.id),
method: this.getRequestMethod(req),

@@ -173,3 +174,2 @@ query: parsed.query,

BackendService.prototype.collectionHandler = function (reqInfo) {
var collection = this.db[reqInfo.collectionName];
// const req = reqInfo.req;

@@ -265,4 +265,12 @@ var resOptions;

BackendService.prototype.createResponseOptions$ = function (resOptionsFactory) {
var _this = this;
return new Observable(function (responseObserver) {
var resOptions = resOptionsFactory();
var resOptions;
try {
resOptions = resOptionsFactory();
}
catch (error) {
var err = error.message || error;
resOptions = _this.createErrorResponseOptions('', STATUS.INTERNAL_SERVER_ERROR, "" + err);
}
var status = resOptions.status;

@@ -305,10 +313,10 @@ try {

* Generate the next available id for item in this collection
* Use method from `inMemDbService` if it exists and returns a value,
* else delegates to `genIdDefault`.
* @param collection - collection of items with `id` key property
* Use method from `inMemDbService` if it exists and returns a value,
* else delegates to genIdDefault
*/
BackendService.prototype.genId = function (collection) {
BackendService.prototype.genId = function (collection, collectionName) {
var genId = this.bind('genId');
if (genId) {
var id = genId(collection);
var id = genId(collection, collectionName);
// tslint:disable-next-line:triple-equals

@@ -319,10 +327,14 @@ if (id != undefined) {

}
return this.genIdDefault(collection);
return this.genIdDefault(collection, collectionName);
};
/**
* Default generator of the next available id for item in this collection
* This default implementation works only for numeric ids.
* @param collection - collection of items with `id` key property
* This default implementation assumes integer ids; returns `1` otherwise
* @param collectionName - name of the collection
*/
BackendService.prototype.genIdDefault = function (collection) {
BackendService.prototype.genIdDefault = function (collection, collectionName) {
if (!this.isCollectionIdNumeric(collection, collectionName)) {
throw new Error("Collection '" + collectionName + "' id type is non-numeric or unknown. Can only generate numeric ids.");
}
var maxId = 0;

@@ -376,2 +388,20 @@ collection.reduce(function (prev, item) {

};
/**
* Get utility methods from this service instance.
* Useful within an HTTP method override
*/
BackendService.prototype.getRequestInfoUtils = function () {
var _this = this;
return {
createResponse$: this.createResponse$.bind(this),
findById: this.findById.bind(this),
isCollectionIdNumeric: this.isCollectionIdNumeric.bind(this),
getConfig: function () { return _this.config; },
getDb: function () { return _this.db; },
getJsonBody: this.getJsonBody.bind(this),
getLocation: this.getLocation.bind(this),
getPassThruBackend: this.getPassThruBackend.bind(this),
parseRequestUrl: this.parseRequestUrl.bind(this),
};
};
BackendService.prototype.indexOf = function (collection, id) {

@@ -381,3 +411,8 @@ return collection.findIndex(function (item) { return item.id === id; });

/** Parse the id as a number. Return original value if not a number. */
BackendService.prototype.parseId = function (id) {
BackendService.prototype.parseId = function (collection, collectionName, id) {
if (!this.isCollectionIdNumeric(collection, collectionName)) {
// Can't confirm that `id` is a numeric type; don't parse as a number
// or else `'42'` -> `42` and _get by id_ fails.
return id;
}
var idNum = parseFloat(id);

@@ -387,2 +422,11 @@ return isNaN(idNum) ? id : idNum;

/**
* return true if can determine that the collection's `item.id` is a number
* This implementation can't tell if the collection is empty so it assumes NO
* */
BackendService.prototype.isCollectionIdNumeric = function (collection, collectionName) {
// collectionName not used now but override might maintain collection type information
// so that it could know the type of the `id` even when the collection is empty.
return !!(collection && collection[0]) && typeof collection[0].id === 'number';
};
/**
* Parses the request URL into a `ParsedRequestUrl` object.

@@ -457,3 +501,15 @@ * Parsing depends upon certain values of `config`: `apiBase`, `host`, and `urlRoot`.

if (item.id == undefined) {
item.id = id || this.genId(collection);
try {
item.id = id || this.genId(collection, collectionName);
}
catch (err) {
var emsg = err.message || '';
if (/id type is non-numeric/.test(emsg)) {
return this.createErrorResponseOptions(url, STATUS.UNPROCESSABLE_ENTRY, emsg);
}
else {
console.error(err);
return this.createErrorResponseOptions(url, STATUS.INTERNAL_SERVER_ERROR, "Failed to generate new id for '" + collectionName + "'");
}
}
}

@@ -524,19 +580,2 @@ if (id && id !== item.id) {

};
Object.defineProperty(BackendService.prototype, "requestInfoUtils", {
get: function () {
var _this = this;
return {
config: this.config,
createResponse$: this.createResponse$.bind(this),
findById: this.findById.bind(this),
getDb: function () { return _this.db; },
getJsonBody: this.getJsonBody.bind(this),
getLocation: this.getLocation.bind(this),
getPassThruBackend: this.getPassThruBackend.bind(this),
parseRequestUrl: this.parseRequestUrl.bind(this),
};
},
enumerable: true,
configurable: true
});
/**

@@ -543,0 +582,0 @@ * Tell your in-mem "database" to reset.

@@ -1,1 +0,1 @@

[{"__symbolic":"module","version":3,"metadata":{"BackendService":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"./interfaces","name":"InMemoryDbService"},{"__symbolic":"reference","module":"./interfaces","name":"InMemoryBackendConfigArgs"}]}],"handleRequest":[{"__symbolic":"method"}],"handleRequest_":[{"__symbolic":"method"}],"addDelay":[{"__symbolic":"method"}],"applyQuery":[{"__symbolic":"method"}],"bind":[{"__symbolic":"method"}],"bodify":[{"__symbolic":"method"}],"clone":[{"__symbolic":"method"}],"collectionHandler":[{"__symbolic":"method"}],"commands":[{"__symbolic":"method"}],"createErrorResponseOptions":[{"__symbolic":"method"}],"createHeaders":[{"__symbolic":"method"}],"createPassThruBackend":[{"__symbolic":"method"}],"createQueryMap":[{"__symbolic":"method"}],"createResponse$":[{"__symbolic":"method"}],"createResponse$fromResponseOptions$":[{"__symbolic":"method"}],"createResponseOptions$":[{"__symbolic":"method"}],"delete":[{"__symbolic":"method"}],"findById":[{"__symbolic":"method"}],"genId":[{"__symbolic":"method"}],"genIdDefault":[{"__symbolic":"method"}],"get":[{"__symbolic":"method"}],"getJsonBody":[{"__symbolic":"method"}],"getLocation":[{"__symbolic":"method"}],"getPassThruBackend":[{"__symbolic":"method"}],"getRequestMethod":[{"__symbolic":"method"}],"indexOf":[{"__symbolic":"method"}],"parseId":[{"__symbolic":"method"}],"parseRequestUrl":[{"__symbolic":"method"}],"post":[{"__symbolic":"method"}],"put":[{"__symbolic":"method"}],"removeById":[{"__symbolic":"method"}],"resetDb":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"BackendService":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"./interfaces","name":"InMemoryDbService"},{"__symbolic":"reference","module":"./interfaces","name":"InMemoryBackendConfigArgs"}]}],"handleRequest":[{"__symbolic":"method"}],"handleRequest_":[{"__symbolic":"method"}],"addDelay":[{"__symbolic":"method"}],"applyQuery":[{"__symbolic":"method"}],"bind":[{"__symbolic":"method"}],"bodify":[{"__symbolic":"method"}],"clone":[{"__symbolic":"method"}],"collectionHandler":[{"__symbolic":"method"}],"commands":[{"__symbolic":"method"}],"createErrorResponseOptions":[{"__symbolic":"method"}],"createHeaders":[{"__symbolic":"method"}],"createPassThruBackend":[{"__symbolic":"method"}],"createQueryMap":[{"__symbolic":"method"}],"createResponse$":[{"__symbolic":"method"}],"createResponse$fromResponseOptions$":[{"__symbolic":"method"}],"createResponseOptions$":[{"__symbolic":"method"}],"delete":[{"__symbolic":"method"}],"findById":[{"__symbolic":"method"}],"genId":[{"__symbolic":"method"}],"genIdDefault":[{"__symbolic":"method"}],"get":[{"__symbolic":"method"}],"getJsonBody":[{"__symbolic":"method"}],"getLocation":[{"__symbolic":"method"}],"getPassThruBackend":[{"__symbolic":"method"}],"getRequestMethod":[{"__symbolic":"method"}],"indexOf":[{"__symbolic":"method"}],"parseId":[{"__symbolic":"method"}],"parseRequestUrl":[{"__symbolic":"method"}],"post":[{"__symbolic":"method"}],"put":[{"__symbolic":"method"}],"removeById":[{"__symbolic":"method"}],"resetDb":[{"__symbolic":"method"}]}}}}]
[{"__symbolic":"module","version":3,"metadata":{"BackendService":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"./interfaces","name":"InMemoryDbService"},{"__symbolic":"reference","module":"./interfaces","name":"InMemoryBackendConfigArgs"}]}],"handleRequest":[{"__symbolic":"method"}],"handleRequest_":[{"__symbolic":"method"}],"addDelay":[{"__symbolic":"method"}],"applyQuery":[{"__symbolic":"method"}],"bind":[{"__symbolic":"method"}],"bodify":[{"__symbolic":"method"}],"clone":[{"__symbolic":"method"}],"collectionHandler":[{"__symbolic":"method"}],"commands":[{"__symbolic":"method"}],"createErrorResponseOptions":[{"__symbolic":"method"}],"createHeaders":[{"__symbolic":"method"}],"createPassThruBackend":[{"__symbolic":"method"}],"createQueryMap":[{"__symbolic":"method"}],"createResponse$":[{"__symbolic":"method"}],"createResponse$fromResponseOptions$":[{"__symbolic":"method"}],"createResponseOptions$":[{"__symbolic":"method"}],"delete":[{"__symbolic":"method"}],"findById":[{"__symbolic":"method"}],"genId":[{"__symbolic":"method"}],"genIdDefault":[{"__symbolic":"method"}],"get":[{"__symbolic":"method"}],"getJsonBody":[{"__symbolic":"method"}],"getLocation":[{"__symbolic":"method"}],"getPassThruBackend":[{"__symbolic":"method"}],"getRequestInfoUtils":[{"__symbolic":"method"}],"getRequestMethod":[{"__symbolic":"method"}],"indexOf":[{"__symbolic":"method"}],"parseId":[{"__symbolic":"method"}],"isCollectionIdNumeric":[{"__symbolic":"method"}],"parseRequestUrl":[{"__symbolic":"method"}],"post":[{"__symbolic":"method"}],"put":[{"__symbolic":"method"}],"removeById":[{"__symbolic":"method"}],"resetDb":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"BackendService":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"./interfaces","name":"InMemoryDbService"},{"__symbolic":"reference","module":"./interfaces","name":"InMemoryBackendConfigArgs"}]}],"handleRequest":[{"__symbolic":"method"}],"handleRequest_":[{"__symbolic":"method"}],"addDelay":[{"__symbolic":"method"}],"applyQuery":[{"__symbolic":"method"}],"bind":[{"__symbolic":"method"}],"bodify":[{"__symbolic":"method"}],"clone":[{"__symbolic":"method"}],"collectionHandler":[{"__symbolic":"method"}],"commands":[{"__symbolic":"method"}],"createErrorResponseOptions":[{"__symbolic":"method"}],"createHeaders":[{"__symbolic":"method"}],"createPassThruBackend":[{"__symbolic":"method"}],"createQueryMap":[{"__symbolic":"method"}],"createResponse$":[{"__symbolic":"method"}],"createResponse$fromResponseOptions$":[{"__symbolic":"method"}],"createResponseOptions$":[{"__symbolic":"method"}],"delete":[{"__symbolic":"method"}],"findById":[{"__symbolic":"method"}],"genId":[{"__symbolic":"method"}],"genIdDefault":[{"__symbolic":"method"}],"get":[{"__symbolic":"method"}],"getJsonBody":[{"__symbolic":"method"}],"getLocation":[{"__symbolic":"method"}],"getPassThruBackend":[{"__symbolic":"method"}],"getRequestInfoUtils":[{"__symbolic":"method"}],"getRequestMethod":[{"__symbolic":"method"}],"indexOf":[{"__symbolic":"method"}],"parseId":[{"__symbolic":"method"}],"isCollectionIdNumeric":[{"__symbolic":"method"}],"parseRequestUrl":[{"__symbolic":"method"}],"post":[{"__symbolic":"method"}],"put":[{"__symbolic":"method"}],"removeById":[{"__symbolic":"method"}],"resetDb":[{"__symbolic":"method"}]}}}}]

@@ -11,2 +11,9 @@ # "angular-in-memory-web-api" versions

<a id="0.4.4"></a>
## 0.4.4 (2017-09-11)
closes #136
A **breaking change** if you expected `genId` to generate ids for a collection
with non-numeric `item.id`.
<a id="0.4.3"></a>

@@ -13,0 +20,0 @@ ## 0.4.3 (2017-09-11)

@@ -153,8 +153,6 @@ import { Observable } from 'rxjs/Observable';

/**
* Interface for methods and current data from this service instance
* Interface for utility methods from this service instance.
* Useful within an HTTP method override
*/
export interface RequestInfoUtilities {
/** The current, active configuration which is a blend of defaults and overrides */
config: InMemoryBackendConfigArgs;
/**

@@ -167,2 +165,12 @@ * Create a cold response Observable from a factory for ResponseOptions

createResponse$: (resOptionsFactory: () => ResponseOptions) => Observable<any>;
/**
* Find first instance of item in collection by `item.id`
* @param collection
* @param id
*/
findById<T extends {
id: any;
}>(collection: T[], id: any): T;
/** return the current, active configuration which is a blend of defaults and overrides */
getConfig(): InMemoryBackendConfigArgs;
/** Get the in-mem service's copy of the "database" */

@@ -175,4 +183,10 @@ getDb(): {};

/** Get (or create) the "real" backend */
getPassThruBackend: PassThruBackend;
getPassThruBackend(): PassThruBackend;
/**
* return true if can determine that the collection's `item.id` is a number
* */
isCollectionIdNumeric<T extends {
id: any;
}>(collection: T[], collectionName: string): boolean;
/**
* Parses the request URL into a `ParsedRequestUrl` object.

@@ -182,9 +196,2 @@ * Parsing depends upon certain values of `config`: `apiBase`, `host`, and `urlRoot`.

parseRequestUrl(url: string): ParsedRequestUrl;
/**
* Find first instance of item in collection by `item.id`
* @param collection
* @param id
*/ findById<T extends {
id: any;
}>(collection: T[], id: any): T;
}

@@ -191,0 +198,0 @@ /**

{
"name": "angular-in-memory-web-api",
"version": "0.4.3",
"version": "0.4.4",
"description": "An in-memory web api for Angular demos and tests",

@@ -74,4 +74,4 @@ "main": "bundles/in-memory-web-api.umd.js",

"rimraf": "^2.6.1",
"rollup": "^0.49.0",
"rollup-stream": "^1.23.0",
"rollup": "^0.49.3",
"rollup-stream": "^1.24.1",
"rxjs": "^5.1.0",

@@ -78,0 +78,0 @@ "systemjs": "0.20.18",

@@ -27,3 +27,3 @@ # Angular in-memory-web-api

>
>`'angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js'`
>`'@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js'`
>

@@ -431,2 +431,14 @@ >You've already made this change if you are using `HttpClient` today.

## Rollup
The gulp "umd" task runs rollup for tree-shaking.
I don't remember it ever working without a lot of warnings.
In v.0.4.x, updated to v.0.49 ... which required updating of the `rollup.config.js`.
Still weirdly runs an unspecified `cjs` rollup config first that I can’t find (which produces numerous warnings) before doing the right thing and running the `umd` config.
Also does not work if follow instructions and use the `output` property of `rollup.config.js`; does work when config it “wrong” and put the options in the root.
Ignoring these issues for now.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc