
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
A simple compatibility layer for dynamodb models to be compatible with the datastar model API
A simple compatibility layer for dynamodb models to be compatible with the datastar model API
npm install dynastar --save
When defining your dynamodb
models,
you use dynastar
to expose them with
a datastar
API. You can optionally pass
functions you would like to attach to the Dynastar class.
const Dynastar = require('dynastar');
const Joi = require('joi');
function defineMyModel(dynamo) {
const model = dynamo.define('mymodel', {
hashKey: 'hashme',
rangeKey: 'ranger',
schema: {
hashme: Joi.string(),
ranger: dynamo.types.timeUUID()
}
});
//
// A sync function must have a length of less than 2 if you want
// to use the AwaitWrap wrapper
//
function exampleSyncFn(data) {
// do something sync
return someSyncResult;
}
function exampleAsyncFn(data, next) {
// do something async
next(null, someAsyncResult);
}
return new Dynastar({ model, hashKey: 'hashme', rangeKey: 'ranger', exampleSyncFn, exampleAsyncFn });
}
const mymodel = defineMyModel(require('dynamodb'));
AwaitWrap
If you would like to enable an await
able model, we have a class for that.
Building on the previous example...
const { AwaitWrap } = require('dynastar');
const myAwaitModel = new AwaitWrap(mymodel);
// In this circumstance we have a sync function and async function that was
// added as "extra" onto the model itself. In this context the sync function
// is left untouched but the async callback function is made to be a `thenable`
// that can be awaited
const asyncResult = await myAwaitModel.exampleAsyncFn(data);
const syncResult = myAwaitModel.exampleSyncFn(data);
Dynastar supports key builders for the hash and range keys. These are useful for combining multiple values into one.
createHashKey
(or simply createKey
) can be used to build a compound hash key.
const Dynastar = require('dynastar');
const Joi = require('joi');
function defineMyModel(dynamo) {
const model = dynamo.define('mymodel', {
hashKey: 'key',
rangeKey: 'ranger',
schema: {
key: Joi.string(),
ranger: Joi.string(),
firstName: Joi.string(),
lastName: Joi.string(),
birthday: Joi.date()
}
});
return new Dynastar({
model,
hashKey: 'key',
rangeKey: 'ranger',
createHashKey: ({ firstName, lastName, birthday }) => `${firstName}!${lastName}!${birthday}`
});
}
createRangeKey
can be used to build a compound range key.
const Dynastar = require('dynastar');
const Joi = require('joi');
function defineMyModel(dynamo) {
const model = dynamo.define('mymodel', {
hashKey: 'hashme',
rangeKey: 'ranger',
schema: {
hashme: Joi.string(),
ranger: Joi.string(),
time: Joi.date().iso(),
uuid: dynamo.types.uuid()
}
});
return new Dynastar({
model,
hashKey: 'hashme',
rangeKey: 'ranger',
createRangeKey: ({ time, uuid }) => `${time}#${uuid}`
});
}
Run localstack locally in one terminal
npm run localstack
Run npm tests
npm test
1.3.1
FAQs
A simple compatibility layer for dynamodb models to be compatible with the datastar model API
The npm package dynastar receives a total of 10 weekly downloads. As such, dynastar popularity was classified as not popular.
We found that dynastar demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 15 open source maintainers 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
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.