@orion-js/resolvers
Advanced tools
Comparing version 3.0.0-alpha.19 to 3.0.0-alpha.20
@@ -11,3 +11,3 @@ "use strict"; | ||
if (rawParams.__isModel) { | ||
rawParams = rawParams.schema; | ||
rawParams = rawParams.getSchema(); | ||
} | ||
@@ -14,0 +14,0 @@ const params = (0, clone_1.default)(rawParams); |
@@ -74,5 +74,2 @@ "use strict"; | ||
it('should create typed model resolvers', async () => { | ||
const resolve = async function (model, params) { | ||
return model.value * 2; | ||
}; | ||
const resolver = (0, index_1.default)({ | ||
@@ -85,3 +82,5 @@ params: { | ||
returns: Number, | ||
resolve | ||
resolve: async function (model, params) { | ||
return model.value * 2; | ||
} | ||
}); | ||
@@ -95,1 +94,35 @@ const inModel = resolver.resolve; | ||
}); | ||
it('should accept a model as params', async () => { | ||
const aModel = { | ||
__isModel: true, | ||
name: 'ResolverParams', | ||
getSchema() { | ||
return { | ||
value: { | ||
type: 'string' | ||
} | ||
}; | ||
} | ||
}; | ||
const resolver = (0, index_1.default)({ | ||
params: aModel, | ||
returns: Number, | ||
resolve: async function (params) { | ||
return params.value * 2; | ||
} | ||
}); | ||
const inModel = resolver.resolve; | ||
const inModelResult = await inModel({ value: 2 }); | ||
/** | ||
* We are testing the typescript removes one argument on the resolve function. | ||
*/ | ||
expect(inModelResult).toBe(4); | ||
}); | ||
it('should correctly clean params when no params are passed', async () => { | ||
const resolver = (0, index_1.default)({ | ||
resolve: async ({ title }) => { | ||
return `${title}`; | ||
} | ||
}); | ||
expect(await resolver.execute({ params: { title: 'test' } })).toBe('test'); | ||
}); |
@@ -37,10 +37,10 @@ import { OrionCache } from '@orion-js/cache'; | ||
} | ||
export interface Resolver<ResolveFunction = BaseResolveFunction> extends SharedResolverOptions { | ||
execute: Execute; | ||
declare type AnyFunction = (...args: any) => any; | ||
export interface Resolver<ResolveFunction extends AnyFunction = AnyFunction> extends SharedResolverOptions { | ||
execute: Execute<ReturnType<ResolveFunction>>; | ||
resolve: ResolveFunction; | ||
} | ||
export declare type BaseResolveFunction = GlobalResolve | ModelResolve; | ||
export declare type CreateResolver = <ResolveFunction = BaseResolveFunction>(options: ResolverOptions) => Resolver<ResolveFunction>; | ||
export declare type CreateResolver = <ResolveFunction extends AnyFunction>(options: ResolverOptions) => Resolver<ResolveFunction>; | ||
declare type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never; | ||
export declare type ModelResolverFunction<F extends ModelResolve> = OmitFirstArg<F>; | ||
export {}; |
{ | ||
"name": "@orion-js/resolvers", | ||
"version": "3.0.0-alpha.19", | ||
"version": "3.0.0-alpha.20", | ||
"main": "lib/index.js", | ||
@@ -34,3 +34,3 @@ "types": "lib/index.d.ts", | ||
}, | ||
"gitHead": "6a6ad914c4f0af4d0220d4911768c5ecd0b91144" | ||
"gitHead": "145e17f5a9d6bbf02f166c5faa416be60752a42f" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21127
534