Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('handles missing content object', () => {
// no content object at all
const dat = deepclone({ response });
emit(dat, action);
assert.deepEqual(dat, { response, content: {} });
});
});
it(wat, () => {
const { proc } = procMd(md);
// Discard position info
const nodes = flattenTree(proc,
(node, recurse) => concat([node], recurse(node.children || [])));
each(nodes, (node) => {
delete node.position;
});
assert.deepStrictEqual(proc.children, yaml.safeLoad(ast));
});
};
it(wat, () => {
const { proc } = procMd(md);
// Discard position info
const nodes = flattenTree(proc,
(node, recurse) => concat([node], recurse(node.children || [])));
each(nodes, (node) => {
delete node.position;
});
assert.deepStrictEqual(proc.children, yaml.safeLoad(ast));
});
};
(context) => {
const { content } = context;
const res = setdefault(context, 'response', {});
// this is the main function (normally it would be the template function)
// but we use it to assert that pre-processing has happened
assert.ok(content.body);
assert.ok(content.mdast);
assert.ok(content.meta);
assert.equal(content.meta.template, 'Medium');
assert.equal(content.intro, 'Project Helix');
assert.equal(content.title, 'Bill, Welcome to the future');
// and return a different status code
res.status = 201;
res.body = { foo: 'bar' };
setdefault(res, 'headers', {})['Content-Type'] = 'text/plain+json';
},
{},
function makeheader(schema) {
// console.log('making header for', schema[s.filename], schema[s.pointer]);
if (header) {
return [
heading(1, text(i18n`${gentitle(schema[s.titles], schema[keyword`type`])} Schema`)),
paragraph(code('txt', schema[s.id] + (schema[s.pointer] ? `#${schema[s.pointer]}` : ''))),
schema[s.meta].longdescription,
...makecomment(schema),
table('left', [
// iterate over header
tableRow(
flist(
map(headerprops,
({ name, title }) => {
if (links[name]) {
return tableCell(link(links[name], i18n`What does ${title} mean?`, text(title)));
}
return tableCell(text(title));
}), Array,
),
),
tableRow(
flist(
map(headerprops,
(prop) => {
// this is a linked property
if (schema[s.meta]
&& typeof schema[s.meta][prop.name] === 'object'
&& schema[s.meta][prop.name].link
const typefact = (() => {
if (nulltype) {
return [inlineCode(`null${isarray}`), text(i18n`, the value must be null`)];
} else if (singletype && firsttype && typeof firsttype === 'string') {
return [inlineCode(firsttype + isarray)];
} else if (!singletype) {
return [text(isarray ? i18n`an array of the following:` : i18n`any of the folllowing: `), ...flist(flat(realtypes.map((mytype, index) => [inlineCode(mytype || i18n`not defined`), text(index === realtypes.length - 1 ? '' : i18n` or `)])))];
} else if (merged) {
return [text(isarray ? 'an array of merged types' : i18n`merged type`)];
}
// console.log('unknown type', realtypes, singletype, merged, definition[s.pointer]);
return [text(i18n`unknown` + isarray)];
})();
},
};
const cnt = block.end - block.start + 1;
mdast.children.splice(block.start + off, cnt, dat);
off += -cnt + 1; // cnt removed, 1 inserted
} else {
const { warning, source, start } = block;
const fst = mdast.children[start + off];
// This also needs to account for settext headings
// hence the usage of end here, instead of using start
const { line } = fst.position.end;
// Source file pretty printing with line numbers
const sourceref = pipe(
source.split('\n'),
zipLeast2(range(line, Infinity)),
map(([l, no]) => ` ${no} | ${l} `),
join('\n'),
);
const err = new FrontmatterParsingError(`${warning}\n${sourceref}`);
if (!production()) {
logger.warn(err);
}
logger.debug(err);
}
}
};
return (schemas) => {
if (readme) {
console.log('building readme');
const toplevel = flist(pipe(
schemas,
filter(schema => !schema[s.parent]), // remove schemas with a parent
mapSort(schema => gentitle(schema[s.titles], schema[keyword`type`])),
map(schema => listItem(paragraph([
link(`./${schema[s.slug]}.md`, gendescription(schema), [text(gentitle(schema[s.titles], schema[keyword`type`]))]),
text(' – '),
inlineCode(schema[keyword`$id`] || '-'),
]))),
), Array);
const bytype = type => flist(pipe(
schemas,
filter(schema => schema[keyword`type`] === type), // remove schemas without matching type
filter(schema => !!schema[s.parent]), // keep only schemas with a parent
mapSort(schema => gentitle(schema[s.titles], schema[keyword`type`])),
map(schema => listItem(paragraph([
mdast.children.splice(block.start + off, cnt, dat);
off += -cnt + 1; // cnt removed, 1 inserted
} else {
const { warning, source, start } = block;
const fst = mdast.children[start + off];
// This also needs to account for settext headings
// hence the usage of end here, instead of using start
const { line } = fst.position.end;
// Source file pretty printing with line numbers
const sourceref = pipe(
source.split('\n'),
zipLeast2(range(line, Infinity)),
map(([l, no]) => ` ${no} | ${l} `),
join('\n'),
);
const err = new FrontmatterParsingError(`${warning}\n${sourceref}`);
if (!production()) {
logger.warn(err);
}
logger.debug(err);
}
}
};
return (schemas) => {
if (readme) {
console.log('building readme');
const toplevel = flist(pipe(
schemas,
filter(schema => !schema[s.parent]), // remove schemas with a parent
mapSort(schema => gentitle(schema[s.titles], schema[keyword`type`])),
map(schema => listItem(paragraph([
link(`./${schema[s.slug]}.md`, gendescription(schema), [text(gentitle(schema[s.titles], schema[keyword`type`]))]),
text(' – '),
inlineCode(schema[keyword`$id`] || '-'),
]))),
), Array);
const bytype = type => flist(pipe(
schemas,
filter(schema => schema[keyword`type`] === type), // remove schemas without matching type
filter(schema => !!schema[s.parent]), // keep only schemas with a parent
mapSort(schema => gentitle(schema[s.titles], schema[keyword`type`])),
map(schema => listItem(paragraph([
link(`./${schema[s.slug]}.md`, gendescription(schema), [text(gentitle(schema[s.titles], schema[keyword`type`]))]),
text(' – '),
inlineCode(`${schema[s.id]}#${schema[s.pointer]}`),