knledg / distraught Goto Github PK
View Code? Open in Web Editor NEWAn Expressly dissatisfied web server
License: MIT License
An Expressly dissatisfied web server
License: MIT License
Need an option in the httpServer to not require sessions.
If something is just and API that uses JWT for auth it shouldn't need a SESSION_SECRET defined.
We need to create a Cache class that ties into Redis.
In the constructor, link this.redis
to a singleton instance of Redis using the environment variable for REDIS_URL. If there is none, fail silently.
If there is no REDIS_URL in the environment variables throw a TError saying the class cannot method get
until a REDIS_URL is added. Create a get
function that takes one parameter: key (string). Pull from redis cache with that key, if it fails return null
. It should return the value
if setting the cache was successful.
If there is no REDIS_URL in the environment variables throw a TError saying the class cannot method set
until a REDIS_URL is added. Create a set
function that takes three parameters: key (string), value (any), ttl (number until expiration, check if Redis uses seconds or ms and document that in the function notes). Set a default TTL of 5 minutes if none is set.
If value is a Fn, execute the Fn.
If the result of Fn is a promise, await the result.
If the promise is rejected, throw new TError(Unable to set cache for key ${key}, promise rejected
, {promiseErr});
Create a Fn called getOrSet
that takes the same params, as set
Fn, but will try a get internally before calling the function to execute fetching the data. Returns promise of a value.
Export from distraught, a singleton instance of the cache
Class.
Users can then following get/set pattern:
import {cache} from 'distraught'
async fetchReport() {
let report = cache.get('report');
if (! report) {
report = cache.set('report', await ReportModel.fetch());
// or specify a TTL with: report = cache.set('report', await ReportModel.fetch(), 3000);
}
return report;
}
or users can utilize the getOrSet fn:
import {cache} from 'distraught';
fetchReport() {
return cache.getOrSet('report', ReportModel.fetch, 3000); // returns promise
}
We still need to have addDbConnection available for dynamic database connections
Example:
const D = require("distraught");
D.init({
db: {
connection1: { connection: process.env.DB_URL },
},
});
D.init({
db: {
connection2: { connection: process.env.DB_URL },
},
});
// we would get a message about "DB connection connection1 already added"
When we're looping through the each
calls in the init section of the code we should make sure the key doesn't exist before we call the respecting addDatabase/addHeretic/addCache calls.
gql.helpers
namespacecacheKey
and cacheTTL
on their pgObject
On a pgObject, if the user specifies a cacheKey
, the queries will try and check for matches against Redis, before querying PG.
Note: The cacheKey
should be letters/numbers (no symbols or spaces), this is actually a prefix to the actual key that is used.
cacheKey
exists on the PG object, check that REDIS_URL is in the environment vars. If not, throw a TError saying cacheKey cannot be used without a valid REDIS_URLcacheKey
cacheTTL
, default to 5 minutesget
method from the cache singleton instance (#27) to try and return results from cache.set
method from the cache singleton instance to set the cache using the cacheKey-${filterHash}
as the full key
, the resultset as the value
, and the TTL as either the cacheTTL
specified on the pgObject or the default of 5 minutes{
"error": {
"message": "RestClient has been removed from this version of the library. Please refer to https://www.twilio.com/docs/libraries/node for more information.",
}
}
GraphQL v0.8.* supports NullValue which currently gets stripped from payloads.
This is probably a breaking change for the existing applications
Workerserver errors are getting grouped today. Try exploding the queue_name on periods and use _.startCase to prevent the grouping of all similarly named queues
In create()
, if the payload is an empty array or an empty object, throw an error saying Unable to create new database records, expected array of objects or single object, but received ${empty object|empty array}
In a GQL query a developer can request a collection's records and count:
But some PG collections get so large that running a count query is inefficient and it might be beneficial to use the count_estimate query explained here.
We should add a new option to all collections to request the countEstimate.
Example:
select count_estimate('select * from users')
For example when I am searching audit logs and I want the user who created the audit log, if no user created it (generated by the server maybe), then it will fetch the first user record.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.