tailor.on('fragment:response', (request, fragment) => { const startTime = fragments.get(fragment); if (fragment.primary) { primaryOverhead = getMillisecs(process.hrtime(startTime)); } });
const handleTag = (request, tag, options, context) => { if (tag && tag.name === 'switcher') { const stream = processTemplate(request, options, context); process.nextTick(() => { stream.end({ name: 'fragment', attributes: { src: 'http://localhost:8081' } }); }); return stream; } return ''; }
worker.on('close', () => { console.log( 'Tailor Overhead Metrics', JSON.stringify(histogram.printObj(), null, 2) ); fragment.kill(); worker.kill(); process.exit(0); });
const generateUnsubscribeToken = ( userId: string, type: string, dataId: ?string ) => { if (!userId || !type) return null; let token; try { token = jwt.sign( { userId, type, dataId }, process.env.EMAIL_JWT_SIGNATURE, { expiresIn: 60 * 60 * 24 * 7, } ); } catch (err) { return null; } if (!token || token === undefined) { return null; } return token; }
// Tailor Events to collect Metrics tailor.on('start', request => { requests.set(request, process.hrtime()); });
async function validateHooks() { const browser = await puppeteer.launch(); const page = await browser.newPage(); try { // Forcing to wait till there are no networking events await page.goto('http://localhost:8080/index', { waitUntil: 'networkidle0' }); // Capture all the fragment related metrics const metrics = await page.evaluate(() => { // Serializing the outputs otherwise it will be undefined return [ JSON.stringify(performance.getEntriesByType('mark')), JSON.stringify(performance.getEntriesByType('measure')), JSON.stringify(window.TailorPipe.getEntries()) ]; }); const [mark, measure, entries] = [ JSON.parse(metrics[0]), JSON.parse(metrics[1]), JSON.parse(metrics[2]) ]; await analyseHooks(mark, measure, entries); await browser.close(); } catch (e) { console.error(e); process.exit(1); } }
fetchContext: () => Promise.resolve({}), fetchTemplate: fetchTemplate( templatesPath || path.join(process.cwd(), 'templates') ), fragmentTag: 'fragment',
tailor.on('response', request => { if (primaryOverhead > 0 && requests.has(request)) { const startTime = requests.get(request); const timeToHeaders = getMillisecs(process.hrtime(startTime)); updateTailorOverhead(timeToHeaders, primaryOverhead); } });
describe('showHelp', () => { it('shows the help message and exits', () => { args.showHelp() expect(console.log).to.be.calledOnce() expect(process.exit).to.be.calledWith(0) }) })
async signup(parent, args, context) { const password = await bcrypt.hash(args.password, 10) const user = await context.prisma.createUser({ ...args, password }) return { token: jwt.sign({ userId: user.id }, process.env.APP_SECRET), user, } }
function getUserId(context) { const Authorization = context.request.get('Authorization') if (Authorization) { const token = Authorization.replace('Bearer ', '') const { userId } = jwt.verify(token, process.env.APP_SECRET) return userId } throw new AuthError() }
describe('parseVolumes', () => { it('returns volumes with correct pathing', () => { expect(command.parseVolumes([ './foo:/bar', '/foo:/bar' ])).to.deep.equal([ `${process.cwd()}/foo:/bar`, '/foo:/bar' ]) }) })
tailor.on('fragment:start', (request, fragment) => { fragments.set(fragment, process.hrtime()); });
const generateEmailValidationToken = ( userId: string, email: string, communityId?: string ) => { if (!userId || !email) return null; let token; try { token = jwt.sign( { userId, email, communityId }, process.env.EMAIL_JWT_SIGNATURE, { expiresIn: 60 * 60 * 24 * 7, } ); } catch (err) { return null; } if (!token || token === undefined) { return null; } return token; }