FunctionScript将 JavaScript 函数转为类型化的 HTTP API
FunctionScript 是一种将 JavaScript 函数转为类型化 HTTP API 的语言和规范。
它允许 JavaScript(Node.js)函数通过对 HTTP 接口进行定义(包括类型安全机制),从而无缝导出为 HTTP API。
示例代码
/**
* Select Rows from a Spreadsheet by querying it like a Database
* @param {string} spreadsheetId The id of the Spreadsheet.
* @param {string} range The A1 notation of the values to use as a table.
* @param {enum} bounds Specify the ending bounds of the table.
* ["FIRST_EMPTY_ROW", "FIRST_EMPTY_ROW"]
* ["FULL_RANGE", "FULL_RANGE"]
* @param {object} where A list of column values to filter by.
* @param {object} limit A limit representing the number of results to return
* @ {number} offset The offset of records to begin at
* @ {number} count The number of records to return, 0 will return all
* @returns {object} selectQueryResult
* @ {string} spreadsheetId
* @ {string} range
* @ {array} rows An array of objects corresponding to row values
*/
module.exports = async (
spreadsheetId = null,
range,
bounds = 'FIRST_EMPTY_ROW',
where = {},
limit = {offset: 0, count: 0},
context
) => {
/* implementation-specific JavaScript */
return {/* some data */};
};
上面的代码将会生成一个 API:
-
spreadsheetId
Astring
-
range
Astring
-
bounds
Anenum
, can be either"FIRST_EMPTY_ROW"
or"FULL_RANGE"
-
where
Anobject
-
limit
Anobject
that must contain:-
limit.offset
, anumber
-
limit.count
, anumber
-
返回一个对象:
selectQueryResult
-
selectQueryResult.spreadsheetId
must be astring
-
selectQueryResult.range
must be astring
-
selectQueryResult.rows
must be anarray
评论