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

dojo-dstore

Package Overview
Dependencies
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dojo-dstore - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

tests/Filter.js

0

bower.json

@@ -0,0 +0,0 @@ {

19

Cache.js

@@ -84,3 +84,9 @@ define([

if (!store.isLoaded || store.isLoaded(object)) {
cachingStore.put(object);
if (cachingStore.putSync) {
// if putSync is available (from the memory store),
// use that as it is about 40x faster
cachingStore.putSync(object);
} else {
cachingStore.put(object);
}
} else {

@@ -139,6 +145,7 @@ // if anything is not loaded, we can't consider them all loaded

put: function (object, directives) {
// first remove from the cache, so it is empty until we get a response from the master store
// first update the cache, we are going to assume the update is valid while we wait to
// hear from the master store
var cachingStore = this.cachingStore;
cachingStore.remove((directives && directives.id) || this.getIdentity(object));
return when(this.inherited(arguments), function (result) {
cachingStore.put(object, directives);
return when(this.inherited(arguments)).then(function (result) {
// now put result in cache

@@ -150,2 +157,5 @@ var cachedPutResult =

return result || cachedPutResult;
}, function () {
// Assuming a rejection of a promise invalidates the local cache
cachingStore.remove((directives && directives.id) || this.getIdentity(object));
});

@@ -182,2 +192,3 @@ },

filter: cachingQuery('filter'),
select: cachingQuery('select'),

@@ -184,0 +195,0 @@ _getQuerierFactory: function (type) {

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ define(['dojo/has', 'dojo/sniff'], function (has) {

@@ -53,3 +53,3 @@ define([

if ((e.name === 'TransactionInactiveError' || e.name === 0) && cursorObject) { // == 0 is IndexedDBShim
// if the cursor has been interrupted we usually need to create a new transaction,
// if the cursor has been interrupted we usually need to create a new transaction,
// handing control back to the query/filter function to open the cursor again

@@ -541,6 +541,6 @@ cursorObject.retry();

filterValue.keyRange = from ?
to ?
IDBKeyRange.bound(from, to, filterValue.excludeFrom, filterValue.excludeTo) :
IDBKeyRange.lowerBound(from, filterValue.excludeFrom) :
IDBKeyRange.upperBound(to, filterValue.excludeTo);
to ?
IDBKeyRange.bound(from, to, filterValue.excludeFrom, filterValue.excludeTo) :
IDBKeyRange.lowerBound(from, filterValue.excludeFrom) :
IDBKeyRange.upperBound(to, filterValue.excludeTo);
})(filterValue.from, filterValue.to);

@@ -767,3 +767,3 @@ } else if (typeof filterValue === 'object' && filterValue.contains) {

// if called, open the cursor again, and continue from our current position
advance = cachedPosition.preFilterOffset;
advance = (cachedPosition.preFilterOffset + 1);
openCursor();

@@ -770,0 +770,0 @@ });

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ # Adapters

@@ -0,0 +0,0 @@ # Collection

@@ -0,0 +0,0 @@ _Do you have a contribution? We welcome contributions, but please ensure that you read the following information

@@ -0,0 +0,0 @@ This document provides some discussion of design decisions and contains rather informal notes. dstore is distinct from other data modelling frameworks in large part due to its goals. This document is intended to describe those goals and design rationales.

@@ -0,0 +0,0 @@ The purpose of this document is to give interested users a look into what may come in future releases.

@@ -20,6 +20,6 @@ # Store

`get(id)` | This retrieves an object by its identity. This returns a promise for the object. If no object was found, the resolved value should be `undefined`.
`getIdentity(object)` | This returns an object's identity (note, this should always execute synchronously).
`getIdentity(object)` | This returns an object's identity (note: this should always execute synchronously).
`put(object, [directives])` | This stores an object. It can be used to update or create an object. This returns a promise that may resolve to the object after it has been saved.
`add(object, [directives])` | This creates an object, and throws an error if the object already exists. This should return a promise for the newly created object.
`remove(id)` | This deletes an object, using the identity to indicate which object to delete. This returns a promise that resolves to a boolean value indicating whether the object was succcessfully removed.
`remove(id)` | This deletes an object, using the identity to indicate which object to delete. This returns a promise that resolves to a boolean value indicating whether the object was successfully removed.
`transaction()` | Starts a transaction and returns a transaction object. The transaction object should include a `commit()` and `abort()` to commit and abort transactions, respectively. Note, that a store user might not call `transaction()` prior to using put, delete, etc. in which case these operations effectively could be thought of as “auto-commit” style actions.

@@ -30,4 +30,15 @@ `create(properties)` | Creates and returns a new instance of the data model. The returned object will not be stored in the object store until it its save() method is called, or the store's add() is called with this object. This should always execute synchronously.

`getRootCollection()` | This should return a collection of the top level objects in a hierarchical store.
`emit(type, event)` | This can be used to dispatch event notifications, indicating changes to the objects in the collection. This should be called by `put`, `add`, and `remove` methods if the `autoEmit` property is `false`. This can also be used to notify stores if objects have changed from other sources (if a change has occurred on the server, from another user). There is a corresponding `on` method on [collections](./Collection.md#ontype-listener) for listening to data change events. Also, the [Trackable](./Stores.md#trackable) can be used to add index/position information to the events.
`emit(type, event)` | This can be used to dispatch event notifications, indicating changes to the objects in the collection. This should be called by `put`, `add`, and `remove` methods if the `autoEmit` property is `false`. This can also be used to notify stores if objects have changed from other sources (if a change has occurred on the server, from another user). There is a corresponding `on` method on [collections](./Collection.md#ontype-listener) for listening to data change events. Also, the [Trackable](./Stores.md#trackable) mixin can be used to add index/position information to the events.
Stores that can perform synchronous operations may provide analogous methods for `get`, `put`, `add`, and `remove` that end with `Sync` to provide synchronous support. For example `getSync(id)` will directly return an object instead of a promise. The `dstore/Memory` store provides `Sync` methods.
#### Synchronous Methods
Stores that can perform synchronous operations may provide analogous methods for `get`, `put`, `add`, and `remove` that end with `Sync` to provide synchronous support. For example `getSync(id)` will directly return an object instead of a promise. The `dstore/Memory` store provides `Sync` methods in addition to the promise-based methods. This behavior has been separated into distinct methods to provide consistent return types.
It is generally advisable to always use the asynchronous methods so that client code does not have to be updated in case the store is changed. However, if you have very performance intensive store accesses, the synchronous methods can be used to avoid the minor overhead imposed by promises.
Method | Description
------ | -------------
`getSync(id)` | This retrieves an object by its identity. If no object was found, the returned value should be `undefined`.
`putSync(object, [directives])` | This stores an object. It can be used to update or create an object. This returns the object after it has been saved.
`addSync(object, [directives])` | This creates an object, and throws an error if the object already exists. This should return the newly created object.
`removeSync(id)` | This deletes an object, using the identity to indicate which object to delete. This returns a boolean value indicating whether the object was successfully removed.

@@ -51,4 +51,17 @@ # Included Stores

The `Memory` store provides synchronous equivalents of standard asynchronous store methods, including `getSync(id)`, `addSync(object, options)`, `putSync(object, options)`, and `removeSync(id)`. These methods directly return objects or results, without a promise.
The array supplied as the `data` property will not be copied, it will be used as-is as the store's data. It can be changed at run-time with the `setData` method.
### Methods
The `Memory` store provides synchronous equivalents of standard asynchronous store methods that directly return objects or results, without a promise.
Name | Description
-----|------------
`getSync(id)` | Retrieve an object by its identity. If no object is found, the returned value is `undefined`.
`addSync(object, options)` | Create an object (throws an error if the object already exists). Returns the newly created object.
`putSync(object, options)` | Store an object. Can be used to update or create an object. Returns the object after it has been saved.
`removeSync(id)` | Delete an object, using the identity to indicate which object to delete. Returns a boolean value indicating whether the object was successfully removed.
`setData(data)` | Set the store's data to the specified array.
## Request

@@ -55,0 +68,0 @@

@@ -0,0 +0,0 @@ # Testing

@@ -0,0 +0,0 @@ define([

define(['dojo/_base/declare'], function (declare) {
// a Filter builder
function filterCreator(type) {
// constructs a new filter based on type, used to create each method
// constructs a new filter based on type, used to create each comparison method
return function newFilter() {

@@ -9,3 +9,4 @@ var Filter = this.constructor;

filter.type = type;
filter.args = arguments;
// ensure args is array so we can concat, slice, unshift
filter.args = Array.prototype.slice.call(arguments);
if (this.type) {

@@ -18,2 +19,31 @@ // we are chaining, so combine with an and operator

}
function logicalOperatorCreator(type) {
// constructs a new logical operator 'filter', used to create each logical operation method
return function newLogicalOperator() {
var Filter = this.constructor;
var argsArray = [];
for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i];
argsArray.push(arg instanceof Filter ? arg : new Filter(arg));
}
var filter = new Filter();
filter.type = type;
filter.args = argsArray;
if (this.type === type) {
// chaining, same type
// combine arguments
filter.args = this.args.concat(argsArray);
} else if (this.type) {
// chaining, different type
// add this filter to start of arguments
argsArray.unshift(this);
} else if (argsArray.length === 1) {
// not chaining and only one argument
// returned filter is the same as the single argument
filter.type = argsArray[0].type;
filter.args = argsArray[0].args.slice();
}
return filter;
};
}
var Filter = declare(null, {

@@ -48,4 +78,4 @@ constructor: function (filterArg) {

// define our operators
and: filterCreator('and'),
or: filterCreator('or'),
and: logicalOperatorCreator('and'),
or: logicalOperatorCreator('or'),
eq: filterCreator('eq'),

@@ -62,3 +92,4 @@ ne: filterCreator('ne'),

Filter.filterCreator = filterCreator;
Filter.logicalOperatorCreator = logicalOperatorCreator;
return Filter;
});

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ define(['./db/has!indexeddb?./db/IndexedDB:sql?./db/SQL:./db/LocalStorage'],

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ var miniExcludes = {

{
"name": "dojo-dstore",
"author": "Kris Zyp",
"version": "1.1.1",
"version": "1.1.2",
"description": "A data collection infrastructure",

@@ -15,3 +15,3 @@ "license": "BSD-3-Clause",

"devDependencies": {
"intern-geezer": "~2",
"intern-geezer": "^2",
"rql": "~0.3.3"

@@ -18,0 +18,0 @@ },

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ define([], function () {

@@ -0,0 +0,0 @@ define(['dojo/_base/lang', 'dojo/when'], function (lang, when) {

@@ -0,0 +0,0 @@ dstore

@@ -115,2 +115,9 @@ define([

_issueFetchRequest: function (requestUrl, headers) {
return request(requestUrl, {
method: 'GET',
headers: headers
});
},
_request: function (kwArgs) {

@@ -128,6 +135,3 @@ kwArgs = kwArgs || {};

var response = request(requestUrl, {
method: 'GET',
headers: headers
});
var response = this._issueFetchRequest(requestUrl, headers);
var collection = this;

@@ -298,2 +302,2 @@ var parsedResponse = response.then(function (response) {

});
});

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ define([

@@ -27,30 +27,40 @@ define([

var comparators = {
eq: function (value, required) {
eq: function eq(value, required) {
return value === required;
},
'in': function(value, required) {
'in': function inComparator(value, required) {
// allow for a collection of data
return arrayUtil.indexOf(required.data || required, value) > -1;
},
ne: function (value, required) {
ne: function ne(value, required) {
return value !== required;
},
lt: function (value, required) {
lt: function lt(value, required) {
return value < required;
},
lte: function (value, required) {
lte: function lte(value, required) {
return value <= required;
},
gt: function (value, required) {
gt: function gt(value, required) {
return value > required;
},
gte: function (value, required) {
gte: function gte(value, required) {
return value >= required;
},
match: function (value, required, object) {
match: function match(value, required, object) {
return required.test(value, object);
},
contains: function (value, required, object, key) {
contains: function contains(value, required, object, key) {
var collection = this;
return arrayUtil.every(required.data || required, function (requiredValue) {
var data;
if (required.data) {
data = required.data;
} else if(Array.isArray(required)) {
data = required;
} else {
data = [required];
}
return arrayUtil.every(data, function (requiredValue) {
if (typeof requiredValue === 'object' && requiredValue.type) {

@@ -78,6 +88,9 @@ var comparator = collection._getFilterComparator(requiredValue.type);

function getQuerier(filter) {
var currentQuerier;
var nextQuerier;
var type = filter.type;
var args = filter.args;
var comparator = collection._getFilterComparator(type);
if (comparator) {
var comparatorFunction = collection._getFilterComparator(type);
if (comparatorFunction) {
// it is a comparator

@@ -87,2 +100,3 @@ var firstArg = args[0];

var secondArg = args[1];
if (secondArg && secondArg.fetchSync) {

@@ -92,7 +106,9 @@ // if it is a collection, fetch the contents (for `in` and `contains` operators)

}
return function (object) {
return function comparator(object) {
// get the value for the property and compare to expected value
return comparator.call(collection, getProperty(object), secondArg, object, firstArg);
return comparatorFunction.call(collection, getProperty(object), secondArg, object, firstArg);
};
}
switch (type) {

@@ -102,20 +118,21 @@ case 'and': case 'or':

// combine filters, using and or or
var nextQuerier = getQuerier(args[i]);
if (querier) {
nextQuerier = getQuerier(args[i]);
if (currentQuerier) {
// combine the last querier with a new one
querier = (function(a, b) {
currentQuerier = (function(a, b) {
return type === 'and' ?
function(object) {
function and(object) {
return a(object) && b(object);
} :
function(object) {
function or(object) {
return a(object) || b(object);
};
})(querier, nextQuerier);
})(currentQuerier, nextQuerier);
} else {
querier = nextQuerier;
currentQuerier = nextQuerier;
}
}
return querier;
return currentQuerier;
case 'function':

@@ -138,2 +155,3 @@ return args[0];

}
return function (data) {

@@ -140,0 +158,0 @@ return arrayUtil.filter(data, querier);

@@ -0,0 +0,0 @@ define([

define([
'./Store',
'./SimpleQuery',
'./Filter',
'./Memory',

@@ -5,0 +6,0 @@ './Request',

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ { "identifier": "symbol", "idAttribute":"symbol", "label": "symbol","items": [

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ [

@@ -0,0 +0,0 @@ define({

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ // Learn more about configuring this file at <https://github.com/theintern/intern/wiki/Configuring-Intern>.

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ define([

@@ -33,3 +33,4 @@ define([

data: lang.clone(testData)
})
}),
idProperty: 'id'
});

@@ -106,2 +107,4 @@ store = new StoreAdapter({

'add duplicate': function () {
var dfd = this.async();
store.add({

@@ -111,6 +114,6 @@ id: 5,

}).then(function () {
assert.fail('add duplicate not rejected');
}, function () {
console.log('add duplicate failed as expected');
});
dfd.reject('add duplicate should be rejected');
}, dfd.callback(function (error) {
assert.strictEqual(error.message, 'Overwriting existing object not allowed');
}));
},

@@ -117,0 +120,0 @@

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ define([

@@ -7,2 +7,3 @@ define([

'dojo/json',
'dojo/request',
'dojo/request/registry',

@@ -23,2 +24,3 @@ 'dojo/when',

request,
requestRegistry,
when,

@@ -96,3 +98,3 @@ whenAll,

before: function () {
registryHandle = request.register(/.*mockRequest.*/, mockRequest);
registryHandle = requestRegistry.register(/.*mockRequest.*/, mockRequest);
},

@@ -159,4 +161,3 @@

return runCollectionTest(store.filter(betweenTwoAndFour), { queryParams: {
id: 'ne=2',
'(foo': 'true|foo=undefined)'
id: 'ne=2|foo=true|foo=undefined'
}});

@@ -358,2 +359,26 @@ },

});
},
'overridden request issuer': function () {
var CustomRequest = declare(Request, {
target: '/mockRequest/',
_issueFetchRequest: function (requestUrl, headers) {
return request(requestUrl, {
method: 'POST',
headers: lang.mixin({}, headers, {
'Content-Type': 'application/x-www-form-urlencoded'
})
});
}
});
var store = new CustomRequest();
mockRequest.setResponseText(JSON.stringify([]));
when(store.fetch()).then(function () {
mockRequest.assertHttpMethod('POST');
mockRequest.assertRequestHeaders({
'Content-Type': 'application/x-www-form-urlencoded'
});
});
}

@@ -360,0 +385,0 @@ };

@@ -0,0 +0,0 @@ define([

@@ -0,0 +0,0 @@ define([

@@ -132,4 +132,18 @@ define([

]);
},
'nested queries': function () {
var f = new Filter();
var isEven = f.eq('odd', false);
var isOdd = f.eq('odd', true);
var isZero = f.eq('name', 'zero');
var isOne = f.eq('name', 'one');
var query = f.or(f.and(isEven, isZero), f.and(isOdd, isOne));
var filter = simpleQuery._createFilterQuerier(query);
assert.deepEqual(filter(testData), [
{ id: 1, name: 'one', odd: true }
]);
}
});
});

@@ -0,0 +0,0 @@ define([

@@ -69,6 +69,3 @@ define([

type: 'eq',
args: { // we have to match Argument type, which is not a real array
0: 'prop1',
1: 'one'
}
args: ['prop1', 'one']
} ]

@@ -75,0 +72,0 @@ } ],

@@ -585,2 +585,14 @@ define([

'updated item - with options.beforeId and no queryExecutor - update beforeId item': function () {
var store = createPrimeNumberStore(),
collection = store.track();
var data = collection._results;
store.put(store.getSync(4), { beforeId: 4 });
var len = data.length;
for (var i = 0; i < len; i++) {
assert.strictEqual(data[i].id, i, 'Item ' + i + ' is not correct.d');
}
},
'type': function () {

@@ -587,0 +599,0 @@ assert.isFalse(store === store.track(function () {}));

@@ -0,0 +0,0 @@ define([

@@ -228,2 +228,3 @@ define([

event = lang.delegate(event, defaultEventProps[type]);
var beforeId = event.beforeId;

@@ -249,6 +250,2 @@ when(observed._results || observed._partialResults, function (resultsArray) {

var i, j, l, ranges = observed._ranges, range;
/*if(++queryRevision != revision){
throw new Error('Query is out of date, you must observe() the' +
' query prior to any data modifications');
}*/

@@ -259,3 +256,4 @@ var targetId = 'id' in event ? event.id : store.getIdentity(target);

insertedInto = -1,
insertionRangeIndex = -1;
insertionRangeIndex = -1,
removedBeforeId;
if (type === 'delete' || type === 'update') {

@@ -273,2 +271,3 @@ // remove the old one

removalRangeIndex = i;
removedBeforeId = beforeId == targetId;
resultsArray.splice(removedFrom, 1);

@@ -305,6 +304,6 @@

if ('beforeId' in event) {
candidateIndex = event.beforeId === null
if (beforeId !== undefined) {
candidateIndex = beforeId === null
? sampleArray.length
: findObject(sampleArray, event.beforeId);
: findObject(sampleArray, beforeId);
}

@@ -346,6 +345,5 @@

var range,
possibleRangeIndex = -1;
if ('beforeId' in event) {
if (event.beforeId === null) {
var possibleRangeIndex = -1;
if (beforeId !== undefined && !removedBeforeId) {
if (beforeId === null) {
insertedInto = resultsArray.length;

@@ -359,3 +357,3 @@ possibleRangeIndex = ranges.length - 1;

resultsArray,
event.beforeId,
beforeId,
range.start,

@@ -411,3 +409,3 @@ range.start + range.count

ranges[i].start++;
}
}
}

@@ -414,0 +412,0 @@ }

@@ -0,0 +0,0 @@ define([

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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