Skip to content

Instantly share code, notes, and snippets.

@daffl
daffl / package.json
Created April 14, 2020 18:30
GitHub action that updates all dependencies once a week
{
"scripts": {
"update-dependencies": "ncu -u"
},
"devDependencies": {
"npm-check-updates": "^4.1.2"
}
}
@daffl
daffl / hooks.ts
Created January 14, 2020 16:29
Async middleware with TypeScript
import { hooks, HookContext, NextFunction } from '@feathersjs/hooks';
const logRuntime = async (context: HookContext, next: NextFunction) => {
const start = new Date().getTime();
await next();
const end = new Date().getTime();
console.log(`Function '${context.method || '[no name]'}' returned '${context.result}' after ${end - start}ms`);
@daffl
daffl / hooks.js
Created January 14, 2020 16:28
Async middleware with JavaScript
const { hooks } = require('@feathersjs/hooks');
const logRuntime = async (context, next) => {
const start = new Date().getTime();
await next();
const end = new Date().getTime();
console.log(`Function '${context.method || '[no name]'}' returned '${context.result}' after ${end - start}ms`);
@daffl
daffl / models.js
Created November 6, 2019 18:06
Feathers Schema proposal ideas
const { setSchema } = require('@feathersjs/schema');
class User {}
setSchema(User, {
id: {
type: Number
},
email: {
description: 'The user email',
@daffl
daffl / app.ts
Last active April 25, 2019 17:53
Feathers Wings sketch outline
@Entity()
class User {
@PrimaryGeneratedColumn()
id: string;
@toLowerCase()
@validate('email')
@Column()
email: string;
@daffl
daffl / whitelist.js
Created January 4, 2019 21:31
Database adapters: Whitelisting
const service = require('feathers-<database>');
// Allow multi create, patch and remove
service({
whitelist: [ '$regex' ]
});
@daffl
daffl / multi-adapter.js
Created January 4, 2019 21:30
Database adapters: Multi updates
const service = require('feathers-<database>');
// Allow multi create, patch and remove
service({
multi: true
});
// Only allow create with an array
service({
multi: [ 'create' ]
@daffl
daffl / hookless.js
Created January 4, 2019 21:30
Database adapters: Hook-less methods
// Call `get` without running any hooks
const message = await app.service('/messages')._get('<message id>');
@daffl
daffl / querying.js
Created January 4, 2019 21:30
Database adapters: Querying by id
// Will throw `NotFound` if `companyId` does not match
// Even if the `id` is available
app.service('/messages').get('<message id>', {
query: { companyId: '<my company>' }
});
@daffl
daffl / app.js
Created January 3, 2019 03:54
Root level service
const feathers = require('@feathersjs/feathers');
const app = feathers();
app.use('/', myService);