
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
falcor-local-datasource
Advanced tools
An implementation of the Falcor DataSource interface exposing a local JSONGraph object
Falcor DataSource interface exposing a local JSON Graph object for frontend storage.
Use cases:
Simply using a falcor model with a cache supports all model.get()
and model.set()
functionality: const model = new falcor.Model({ cache: myJSONGraphObject });
. However, the model cache does not allow function methods to be defined on the JSONGraph object, and hence does not expose model.call()
operations to, for example, add or delete nodes to/from the graph.
To initialize the LocalDataSource, simply define methods on the JSONGraph object and pass to the LocalDataSource class constructor. JSONGraph functions can now be invoked via model.call(callPath:Path, arguments:any[], refPaths?: PathSet[], thisPaths?:PathSet[])
. The function signature is (graph:JSONGraph, arguments:any[])
.
Similar to the Falcor Router, JSONGraph methods must return a JSONGraphEnvelope or Array of PathValues that describe the changes to the graph. It is recommended that you not mutate the graph directly, but rather describe the changes to the graph via the returned JSONGraphEnvelope or PathValues array.
const falcor = require('falcor');
const LocalDatasource = require('../src/index');
const graph = {
todos: {
0: { $type: 'ref', value: ['todosById', 'id_0'] },
1: { $type: 'ref', value: ['todosById', 'id_1'] },
length: 2,
add(graph, args) {
const newTodoLabel = args[0];
const todoCount = graph.todos.length;
// NOTE: this is a pretty naive way to derive new ids. a more robust approach might generate unique ids using
// a specific node in the graph, or use a closure, or some other mechanism to yield unique incremental values
const newId = `id_${todoCount}`;
// return array of pathValues
return [
{
path: ['todos', todoCount],
value: { $type: 'ref', value: ['todosById', newId] }
},
{
path: ['todosById', newId, 'label'],
value: newTodoLabel
},
{
path: ['todosById', newId, 'completed'],
value: false
},
{
path: ['todos', 'length'],
value: todoCount + 1
}
];
}
},
todosById: {
id_0: { label: 'tap dance', completed: false },
id_1: { label: 'see above', completed: false }
}
};
const model = new falcor.Model({ source: new LocalDatasource(graph) });
As with the Falcor Router, the values returned from the call to model.call()
are managed by the refPaths and thisPaths arguments.
model.call(['todos', 'add'], ['dupstep dance party'])
.subscribe(res => {
// never runs
}, err => {
console.error('Error adding new Todo', err);
}, () => {
console.log('added new todo');
});
// > added new todo
model.call(['todos', 'add'], ['jumpstyle'], [[['label', 'completed']]], [['length']])
.subscribe(res => {
console.log('returned', res.json);
}, err => {
console.error('Error adding new Todo', err);
}, () => {
console.log('added new todo');
});
// > { todos: { id_3: { label: 'jumpstyle', completed: false } }, length: 4 }
// > added new todo
Current builds only support NPM. If you use a different package manager, or no package manager, either download and build locally, or post an issue and I'll expand the build step.
npm install --save falcor-local-datasource
To test:
npm run test
To publish:
npm run validate && npm publish
Kudos to Asa Ayers for the package name!
FAQs
An implementation of the Falcor DataSource interface exposing a local JSONGraph object
We found that falcor-local-datasource demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.