This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add CouchDB JavaScript context
implement #232
- Loading branch information
Showing
5 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Emits a key-value pair for further processing by CouchDB after the map function is done. | ||
* @param {string} key - The view key | ||
* @param {any} value - The key’s associated value | ||
* @returns {void} | ||
*/ | ||
declare function emit(key: string, value: any): void | ||
/** | ||
* @deprecated since version 2.0 | ||
* Extracts the next row from a related view result. | ||
* @returns {Object} - View result row | ||
*/ | ||
declare function getRow<T>(): T | ||
|
||
/** | ||
* A helper function to check if the provided value is an Array. | ||
* @param {Object} obj - Any JavaScript value | ||
* @returns {boolean} | ||
*/ | ||
declare function isArray<T>(obj: T): boolean | ||
|
||
/** | ||
* Log a message to the CouchDB log (at the INFO level). | ||
* @param {string} message - Message to be logged | ||
* @returns {void} | ||
*/ | ||
declare function log(message: string): void | ||
|
||
/** | ||
* @deprecated since version 2.0 | ||
* Registers callable handler for specified MIME key. | ||
* @param {string} key - MIME key previously defined by registerType() | ||
* @param {Function} value - MIME type handler | ||
* @returns {void} | ||
*/ | ||
declare function provides(key: string, func: Function): void | ||
|
||
/** | ||
* @deprecated since version 2.0 | ||
* Registers list of MIME types by associated key. | ||
* @param {string} key - MIME types | ||
* @param {string[]} mimes - MMIME types enumeration | ||
* @returns {void} | ||
*/ | ||
declare function registerType(key: string, mimes: string[]): void | ||
|
||
/** | ||
* @deprecated since version 2.0 | ||
* Sends a single string chunk in response. | ||
* @param {string} chunk - Text chunk | ||
* @returns {void} | ||
*/ | ||
declare function send(chunk: string): void | ||
|
||
interface InitResp { | ||
code: number | ||
json: object | ||
body: string | ||
base64: string | ||
headers: any | ||
stop: boolean | ||
} | ||
|
||
/** | ||
* @deprecated since version 2.0 | ||
* Initiates chunked response. As an option, a custom response object may be sent at this point. For list-functions only! | ||
* @param {Object} init_resp - InitResp object | ||
* @returns {void} | ||
*/ | ||
// eslint-disable-next-line | ||
declare function start(init_resp?: InitResp): void | ||
|
||
/** | ||
* Sum arr’s items. | ||
* @param {number[]} arr - Array of numbers | ||
* @returns {number} | ||
*/ | ||
declare function sum(arr: number[]): number | ||
|
||
/** | ||
* Encodes obj to JSON string. This is an alias for the JSON.stringify method. | ||
* @param {any} obj - Array of numbers | ||
* @returns {string} | ||
*/ | ||
declare function toJSON(obj: any): string | ||
|
||
/** | ||
* Reduce functions take two required arguments of keys and values lists - the result of the related map function - and an optional third value which indicates if rereduce mode is active or not. | ||
* Rereduce is used for additional reduce values list, so when it is true there is no information about related keys (first argument is null). | ||
* @param {string[] | null} keys - Array of pairs of docid-key for related map function results. Always null if rereduce is running (has true value). | ||
* @returns {void} | ||
*/ | ||
declare type redfun = (keys: [string, string][] | null, values: any[], rereduce?: boolean) => any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export interface Design<T> { | ||
_id: string | ||
_rev?: string | ||
language: 'javascript' | ||
views?: { | ||
[key: string]: { | ||
/** | ||
* Map functions accept a single document as the argument and (optionally) emit() key/value pairs that are stored in a view. | ||
* Since version 1.1.0, map supports CommonJS modules and the require() function. | ||
* @param {Object} doc - The document that is being processed | ||
* @returns {void} | ||
*/ | ||
map?(doc: T): void | ||
/** | ||
* Reduce functions take two required arguments of keys and values lists - the result of the related map function - and an optional third value which indicates if rereduce mode is active or not. | ||
* Rereduce is used for additional reduce values list, so when it is true there is no information about related keys (first argument is null). | ||
* @param {string[] | null} keys - Array of pairs of docid-key for related map function results. Always null if rereduce is running (has true value). | ||
* @returns {any} | ||
*/ | ||
reduce?(keys: [string, string][] | null, values: any[], rereduce?: boolean): any | ||
} | ||
} | ||
shows?: { | ||
[key: string]: () => void | ||
} | ||
lists?: { | ||
[key: string]: () => void | ||
} | ||
updates?: { | ||
[key: string]: () => void | ||
} | ||
filters?: { | ||
[key: string]: () => void | ||
} | ||
validate_doc_update?: { | ||
[key: string]: () => void | ||
} | ||
} | ||
|
||
export default Design |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// we need this custom tsconfig.json to handle CouchDB Javascript Context locally to this folder | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": [ | ||
"." | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
], | ||
"compilerOptions": { | ||
"typeRoots": [ | ||
"../../node_modules/@types", | ||
"./context.d.ts" | ||
], | ||
"outDir": "../../dist/db", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ | |
], | ||
"exclude": [ | ||
"node_modules", | ||
"dist" | ||
"dist", | ||
"src/db" | ||
], | ||
"compilerOptions": { | ||
"typeRoots": [ | ||
|