Skip to content
This repository has been archived by the owner on Nov 27, 2019. It is now read-only.

Add call signatures to generated library code and enable build-time linting #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"author": "Music Glue",
"license": "MIT",
"scripts": {
"build": "npm run clean && tsc && npm run copy-templates",
"build": "npm run clean && npm run lint && tsc && npm run copy-templates",
"clean": "rm -rf dist",
"lint": "tslint --format prose --project .",
"copy-templates": "npm run purge-templates && cp -R src/writers/templates dist/writers",
"make-executable": "chmod +x dist/cli.js",
"prepare-templates-dir": "mkdir -p dist/writers/templates",
Expand Down
4 changes: 2 additions & 2 deletions src/schemaVisitor/visitObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export const visitObject: Visitor = visitSchema => schema => {
type: "object",
};

const type: VisitedType = {
const type2: VisitedType = {
class: basicType,
name: nameFromNotes(schema),
};

return some(type);
return some(type2);
}

const fields: Field[] = children.map(
Expand Down
6 changes: 3 additions & 3 deletions src/writers/templates/optionTypeFns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ export const cloneToPlainObject = (obj: any) => unwrapOptions(cloneDeep(obj));
export function coerceFactory<T>(
factory: Factory.IFactory,
schema: joi.Schema,
) {
): (attrs?: any, options?: any) => T {
return (attrs?: any, options?: any): T =>
coerceValue<T>(schema)(factory.build(attrs, options));
}

export function coerceValue<T>(schema: joi.Schema) {
export function coerceValue<T>(schema: joi.Schema): (object: any, options?: any) => T {
return (object: any, options?: any): T => {
const resolvedOptions = Object.assign({}, defaultOptions, options);
let coerced: any;
Expand All @@ -164,6 +164,6 @@ export function coerceValue<T>(schema: joi.Schema) {

export const isValueless = (obj: any) => obj === undefined || obj === null;

export function mapOptionalFieldsToOptions<T>(schema: joi.Schema) {
export function mapOptionalFieldsToOptions<T>(schema: joi.Schema): (obj: any) => T {
return (obj: any): T => wrapOptions(schema, obj);
}
4 changes: 2 additions & 2 deletions src/writers/templates/standardFns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const defaultOptions: joi.ValidationOptions = {
export function coerceFactory<T>(
factory: Factory.IFactory,
schema: joi.Schema,
) {
): (attrs?: any, options?: any) => T {
return (attrs?: any, options?: any): T =>
coerceValue<T>(schema)(factory.build(attrs, options));
}

export function coerceValue<T>(schema: joi.Schema) {
export function coerceValue<T>(schema: joi.Schema): (object: any, options?: any) => T {
return (object: any, options?: any): T => {
const resolvedOptions = Object.assign({}, defaultOptions, options);
let coerced: any;
Expand Down
4 changes: 4 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
],
"interface-name": [
false
],
"typedef": [
true,
"call-signature"
]
},
"rulesDirectory": []
Expand Down