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

can-fixture

Package Overview
Dependencies
Maintainers
11
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-fixture - npm Package Compare versions

Comparing version 3.0.0-pre.1 to 3.0.0-pre.2

2

core.js
// Adds
var sub = require("can-get/sub/sub");
var sub = require("can-key/sub/sub");
var canReflect = require("can-reflect");

@@ -4,0 +4,0 @@ var matches = require("./matches");

@@ -129,4 +129,4 @@ @module {function} can-fixture

```js
const todoAlgebra = new set.Algebra(
set.props.id( "id" )
const todoQueryLogic = new QueryLogic(
{identity: ["id"]}
);

@@ -136,3 +136,3 @@ const todoStore = fixture.store( [

{ id: 2, name: "Walk the dog" }
], todoAlgebra );
], todoQueryLogic );

@@ -139,0 +139,0 @@ fixture( "/api/todos/{id}", todoStore ); // can also be written fixture("/api/todos", todoStore);

@function can-fixture.store store
@parent can-fixture.properties
@signature `fixture.store(baseItems, algebra)`
@signature `fixture.store(baseItems, queryLogic)`
Create a store that starts with `baseItems` for a service layer
described by `algebra`.
described by `queryLogic`.
```js
const Todo = DefineMap.extend({
id: {identity: true, type: "number"},
completed: "boolean"
})
// Describe the services parameters:
const todoAlgebra = new set.Algebra(
set.props.id( "_id" ),
set.props.boolean( "completed" ),
set.props.rangeInclusive( "start", "end" ),
set.props.sort( "orderBy" ),
);
const todoQueryLogic = new QueryLogic(Todo);

@@ -30,3 +30,3 @@ // Create a store with initial data.

} ],
todoAlgebra );
todoQueryLogic );

@@ -37,3 +37,3 @@ // Hookup urls to the store:

@param {Array} baseItems An array of items that will populate the store.
@param {can-set.Algebra} algebra A description of the service layer's parameters.
@param {can-query-logic} QueryLogic A description of the service layer's parameters.
@return {can-fixture/StoreType} A store that can be used to simulate

@@ -44,5 +44,5 @@ a restful service layer that supports filtering, pagination, and

@signature `fixture.store(count, makeItems, algebra)`
@signature `fixture.store(count, makeItems, queryLogic)`
Similar to `fixture.store(baseItems, algebra)`, except that
Similar to `fixture.store(baseItems, queryLogic)`, except that
it uses `makeItems` to create `count` entries in the store.

@@ -52,3 +52,3 @@

// Describe the services parameters:
const todoAlgebra = new set.Algebra( /* ... */ );
const todoQueryLogic = new QueryLogic( /* ... */ );

@@ -66,3 +66,3 @@ // Create a store with initial data.

},
todoAlgebra );
todoQueryLogic );

@@ -74,5 +74,5 @@ // Hookup urls to the store:

@param {function} makeItems A function that will generate `baseItems`
@param {can-set.Algebra} algebra A description of the service layer's parameters.
@param {can-query-logic} queryLogic A description of the service layer's parameters.
@return {can-fixture/StoreType} A store that can be used to simulate
a restful service layer that supports filtering, pagination, and
more.

@@ -12,3 +12,3 @@ @function can-fixture/StoreType.prototype.reset reset

[ { id: 1, name: "dishes" } ],
new set.Algebra() );
new QueryLogic({identity: ["id"]}) );
fixture( "/todos/{id}", todoStore );

@@ -15,0 +15,0 @@ todoStore.getList( {} ).length; //-> 1

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

var BasicQuery = require("can-query/src/types/basic-query");
var set = require("can-query/src/set");
var BasicQuery = require("can-query-logic/src/types/basic-query");
var set = require("can-query-logic/src/set");
var canReflect = require("can-reflect");
var dataFromUrl = require("./data-from-url");
var Query = require("can-query");
var Query = require("can-query-logic");

@@ -175,3 +175,3 @@

identity: ["id"],
properties: {
keys: {
url: types.TemplateUrl,

@@ -196,3 +196,3 @@ fixture: types.Ignore,

request: function(requestData, fixtureData) {
return query.has({filter: fixtureData}, requestData);
return query.isMember({filter: fixtureData}, requestData);
},

@@ -199,0 +199,0 @@ matches: function(settings, fixture, exact) {

{
"name": "can-fixture",
"version": "3.0.0-pre.1",
"version": "3.0.0-pre.2",
"description": "Intercept AJAX requests and simulate responses.",

@@ -21,9 +21,11 @@ "main": "fixture.js",

"can-deparam": "^1.0.1",
"can-key": "<2.0.0",
"can-log": "^1.0.0",
"can-memory-store": "<2.0.0",
"can-namespace": "1.0.0",
"can-query": "<2.0.0",
"can-reflect": "^1.13.4"
"can-query-logic": "<2.0.0",
"can-reflect": "^1.15.1"
},
"devDependencies": {
"can-set-legacy": "^0.1.0",
"detect-cyclic-packages": "^1.1.0",

@@ -30,0 +32,0 @@ "jquery": "^3.1.1",

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

var Query = require("can-query");
var QueryLogic = require("can-query-logic");

@@ -8,8 +8,9 @@ var canReflect = require("can-reflect");

// Returns a function that calls the method on a connection.
// Wires up fixture signature to a connection signature.
var connectToConnection = function(method){
var connectToConnection = function(method, convert){
return function(req, res){
// have to get data from
this.connection[method](req.data).then(function(data){
this.connection[method]( convert.call(this, req.data) ).then(function(data){
res(data);

@@ -39,4 +40,34 @@ }, function(err){

var stringToAny = function(str){
switch(str) {
case "NaN":
case "Infinity":
return +str;
case "null":
return null;
case "undefined":
return undefined;
case "true":
case "false":
return str === "true";
default:
var val = +str;
if(!isNaN(val)) {
return val;
} else {
return str;
}
}
};
// A store constructor function
var Store = function(connection, makeItems, idProp){
var schema = connection.queryLogic.schema;
var identityKey = schema.identity[0],
keys = schema.keys;
if(!keys || !keys[identityKey]) {
console.warn("No type specified for identity key. Going to convert strings to reasonable type.");
}
this.connection = connection;

@@ -51,5 +82,33 @@ this.makeItems = makeItems;

};
var doNotConvert = function(v){ return v; };
function typeConvert(data){
var schema = this.connection.queryLogic.schema;
var identityKey = schema.identity[0],
keys = schema.keys;
if(!keys || !keys[identityKey]) {
keys = {};
keys[identityKey] = function(value){
return typeof value === "string" ? stringToAny(value) : value;
};
}
// this probably needs to be recursive, but this is ok for now
var copy = {};
canReflect.eachKey(data, function(value, key){
if(keys[key]) {
copy[key] = canReflect.convert(value, keys[key]);
} else {
copy[key] = value;
}
});
// clone the data
return copy;
}
canReflect.assignMap(Store.prototype,{
getListData: connectToConnection("getListData"),
getData: connectToConnection( "getData"),
getListData: connectToConnection("getListData",doNotConvert),
getData: connectToConnection( "getData",typeConvert),

@@ -62,3 +121,3 @@ // used

this.connection.createData(req.data).then(function(data){
this.connection.createData( typeConvert.call(this,req.data) ).then(function(data){
var responseData = {};

@@ -71,4 +130,4 @@ responseData[idProp] = req.data[idProp];

},
updateData: connectToConnection("updateData"),
destroyData: connectToConnection("destroyData"),
updateData: connectToConnection("updateData",typeConvert),
destroyData: connectToConnection("destroyData",typeConvert),
reset: function(newItems){

@@ -83,3 +142,3 @@ if(newItems) {

get: function (params) {
var id = this.connection.algebra.id(params);
var id = this.connection.queryLogic.memberIdentity(params);
return this.connection.getInstance(id);

@@ -95,3 +154,3 @@ },

// Make a store of objects to use when making requests against fixtures.
Store.make = function (count, make, algebra) {
Store.make = function (count, make, queryLogic) {
/*jshint eqeqeq:false */

@@ -104,6 +163,6 @@

if(typeof count === "number") {
if(!algebra) {
algebra = new Query({});
if(!queryLogic) {
queryLogic = new QueryLogic({});
}
idProp = algebra.getIdentityKeys()[0] || "id";
idProp = queryLogic.identityKeys()[0] || "id";
makeItems = function () {

@@ -129,7 +188,7 @@ var items = [];

} else if(Array.isArray(count)){
algebra = make;
if(!algebra) {
algebra = new Query({});
queryLogic = make;
if(!queryLogic) {
queryLogic = new QueryLogic({});
}
idProp = algebra.getIdentityKeys()[0] || "id";
idProp = queryLogic.identityKeys()[0] || "id";
makeItems = makeMakeItems(count, idProp);

@@ -139,3 +198,3 @@ }

var connection = memoryStore({
algebra: algebra,
queryLogic: queryLogic,
errorOnMissingRecord: true

@@ -142,0 +201,0 @@ });

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