Function: makeTranslateObjectFormula¶
▸ makeTranslateObjectFormula<ParamDefsT
, ResultT
>(__namedParameters
): { cacheTtlSecs?
: number
; connectionRequirement?
: ConnectionRequirement
; description
: string
; examples?
: { params
: (undefined
| PackFormulaValue
)[] ; result
: PackFormulaResult
}[] ; extraOAuthScopes?
: string
[] ; isAction?
: boolean
; isExperimental?
: boolean
; isSystem?
: boolean
; name
: string
; network?
: Network
; parameters
: ParamDefsT
; varargParameters?
: ParamDefs
} & { execute
: (params
: ParamValues
<ParamDefsT
>, context
: ExecutionContext
) => Promise
<SchemaType
<ResultT
>> ; resultType
: object
; schema
: undefined
| ResultT
= response.schema }
Helper to generate a formula that fetches a list of entities from a given URL and returns them.
One of the simplest but most common use cases for a pack formula is to make a request to an API
endpoint that returns a list of objects, and then return those objects either as-is
or with slight transformations. The can be accomplished with an execute
function that does
exactly that, but alternatively you could use makeTranslateObjectFormula
and an
execute
implementation will be generated for you.
example
``
makeTranslateObjectFormula({
name: "Users",
description: "Returns a list of users."
// This will generate an
executefunction that makes a GET request to the given URL.
request: {
method: 'GET',
url: 'https://api.example.com/users',
},
response: {
// Suppose the response body has the form
, { ...user2 }]}.
// This "projection" key tells the
executefunction that the list of results to return
// can be found in the object property
users`. If omitted, the response body itself
// should be the list of results.
projectKey: 'users',
schema: UserSchema,
},
});
Type parameters¶
Name | Type |
---|---|
ParamDefsT |
extends ParamDefs |
ResultT |
extends Schema |
Parameters¶
Name | Type |
---|---|
__namedParameters |
ObjectArrayFormulaDef <ParamDefsT , ResultT > |
Returns¶
{ cacheTtlSecs?
: number
; connectionRequirement?
: ConnectionRequirement
; description
: string
; examples?
: { params
: (undefined
| PackFormulaValue
)[] ; result
: PackFormulaResult
}[] ; extraOAuthScopes?
: string
[] ; isAction?
: boolean
; isExperimental?
: boolean
; isSystem?
: boolean
; name
: string
; network?
: Network
; parameters
: ParamDefsT
; varargParameters?
: ParamDefs
} & { execute
: (params
: ParamValues
<ParamDefsT
>, context
: ExecutionContext
) => Promise
<SchemaType
<ResultT
>> ; resultType
: object
; schema
: undefined
| ResultT
= response.schema }