Skip to content

Instantly share code, notes, and snippets.

@baer
baer / base-data-model.js
Last active May 28, 2019 16:42
multi table + multi data source customer model
const { isUndefined, omitBy } = require(`lodash/fp`);
const hash = require(`object-hash`);
class DataModel {
constructor(cache) {
if (isUndefined(cache)) {
throw new Error(`Data Models require a cache`);
}
this._cache = cache;
// ------------
// REST
// ------------
// This is approxamately the function you would run to fetch the "Customer"
// resource for a REST endpoint. The HTTP stuff is normally be left to your
// framework so I'll leave that out.
app.serve("customer/:id", (urlParams) => {
return myORM.queryById(Customer, urlParams.id);
})
const logAllRoutes = function logAllRoutes(app) {
app._router.stack
.map((middleware) => {
// Return routes registered directly on the app
if (middleware.route) { return middleware.route }
// Return routes registered using Router middleware
if (middleware.name === 'router') {
return middleware.handle.stack.map(handler => handler.route);
}
@baer
baer / Rectangle.js
Last active September 10, 2015 21:52
Proposed Llama API
"use strict";
import {params, returns} from "llama/decorators";
import types from from "llama/types";
@params([
["length", types.number.natural()],
["width", types.number.natural()],
["id", types.string.guid(), ```
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin dapibus tellus iaculis,