|
| 1 | +// Reference: https://docs.couchdb.org/en/latest/query-server/javascript.html#design-functions-context |
| 2 | + |
| 3 | +declare namespace CouchDB { |
| 4 | + type HttpMethods = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS' | 'TRACE' |
| 5 | + interface InitResp { |
| 6 | + code?: number |
| 7 | + json?: object |
| 8 | + body?: string |
| 9 | + base64?: string |
| 10 | + headers?: any |
| 11 | + stop?: boolean |
| 12 | + } |
| 13 | + |
| 14 | + interface UserCtx { |
| 15 | + db: string |
| 16 | + name: string | null |
| 17 | + roles: string[] |
| 18 | + } |
| 19 | + |
| 20 | + interface SecurityObject { |
| 21 | + admins: { |
| 22 | + names: string[] |
| 23 | + roles: string[] |
| 24 | + } |
| 25 | + members: { |
| 26 | + names: string[] |
| 27 | + roles: string[] |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + interface DataBaseInformationObject { |
| 32 | + db_name: string |
| 33 | + committed_update_seq: number |
| 34 | + doc_count: number |
| 35 | + doc_del_count: number |
| 36 | + compact_running: boolean |
| 37 | + disk_format_version: number |
| 38 | + disk_size: number |
| 39 | + instance_start_time: string |
| 40 | + purge_seq: number |
| 41 | + update_seq: number |
| 42 | + sizes: { |
| 43 | + active: number |
| 44 | + disk: number |
| 45 | + external: number |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + interface RequestObject { |
| 50 | + body: string |
| 51 | + cookie: Record<string, any> |
| 52 | + form: Record<string, any> |
| 53 | + headers: Record<string, any> |
| 54 | + id: string | null |
| 55 | + info: CouchDB.DataBaseInformationObject |
| 56 | + method: HttpMethods |
| 57 | + path: string[] |
| 58 | + peer: string |
| 59 | + query: Record<string, any> |
| 60 | + raw_path: string |
| 61 | + requested_path: string[] |
| 62 | + secObj: CouchDB.SecurityObject |
| 63 | + userCtx: CouchDB.UserCtx |
| 64 | + uuid: string |
| 65 | + } |
| 66 | + |
| 67 | + interface RewriteRule { |
| 68 | + method?: string |
| 69 | + from: string |
| 70 | + to: string |
| 71 | + query: Record<string, any> |
| 72 | + } |
| 73 | + |
| 74 | + interface Request2Object { |
| 75 | + body: string |
| 76 | + cookie: Record<string, any> |
| 77 | + headers: Record<string, any> |
| 78 | + method: HttpMethods |
| 79 | + path: string[] |
| 80 | + peer: string |
| 81 | + query: Record<string, any> |
| 82 | + requested_path: string[] |
| 83 | + raw_path: string |
| 84 | + secObj: CouchDB.SecurityObject |
| 85 | + userCtx: CouchDB.UserCtx |
| 86 | + } |
| 87 | + |
| 88 | + interface RewriteReturnObject { |
| 89 | + path: string |
| 90 | + code?: number |
| 91 | + query?: Record<string, any> |
| 92 | + headers?: any |
| 93 | + method?: HttpMethods |
| 94 | + body?: string |
| 95 | + } |
| 96 | + |
| 97 | + interface ResponseObject { |
| 98 | + code?: number |
| 99 | + json?: any |
| 100 | + body?: string |
| 101 | + base64?: string |
| 102 | + headers?: any |
| 103 | + stop?: boolean |
| 104 | + } |
| 105 | + |
| 106 | + interface ViewHeadInformation { |
| 107 | + total_rows: number |
| 108 | + offset: number |
| 109 | + } |
| 110 | +} |
| 111 | +// reference: https://docs.couchdb.org/en/stable/ddocs/views/collation.html |
| 112 | +type kyesBaseTypes = null | boolean | number | string | object |
| 113 | +type emitKeys = kyesBaseTypes | kyesBaseTypes[] |
| 114 | +/** |
| 115 | + * Emits a key-value pair for further processing by CouchDB after the map function is done. |
| 116 | + * @param {string} key - The view key |
| 117 | + * @param {any} value - The key’s associated value |
| 118 | + * @returns {void} |
| 119 | + */ |
| 120 | +declare function emit<T>(key: emitKeys, value?: T): void |
| 121 | +/** |
| 122 | + * @deprecated since version 2.0 |
| 123 | + * Extracts the next row from a related view result. |
| 124 | + * @returns {Object} - View result row |
| 125 | + */ |
| 126 | +declare function getRow<T>(): T |
| 127 | + |
| 128 | +/** |
| 129 | + * A helper function to check if the provided value is an Array. |
| 130 | + * @param {Object} obj - Any JavaScript value |
| 131 | + * @returns {boolean} |
| 132 | + */ |
| 133 | +declare function isArray<T>(obj: T): boolean |
| 134 | + |
| 135 | +/** |
| 136 | + * Log a message to the CouchDB log (at the INFO level). |
| 137 | + * @param {string} message - Message to be logged |
| 138 | + * @returns {void} |
| 139 | + */ |
| 140 | +declare function log(message: string): void |
| 141 | + |
| 142 | +/** |
| 143 | + * @deprecated since version 2.0 |
| 144 | + * Registers callable handler for specified MIME key. |
| 145 | + * @param {string} key - MIME key previously defined by registerType() |
| 146 | + * @param {Function} value - MIME type handler |
| 147 | + * @returns {void} |
| 148 | + */ |
| 149 | +declare function provides(key: string, func: Function): string | CouchDB.ResponseObject |
| 150 | + |
| 151 | +/** |
| 152 | + * @deprecated since version 2.0 |
| 153 | + * Registers list of MIME types by associated key. |
| 154 | + * @param {string} key - MIME types |
| 155 | + * @param {string[]} mimes - MMIME types enumeration |
| 156 | + * @returns {void} |
| 157 | + */ |
| 158 | +declare function registerType(key: string, mimes: string[]): void |
| 159 | + |
| 160 | +/** |
| 161 | + * @deprecated since version 2.0 |
| 162 | + * Sends a single string chunk in response. |
| 163 | + * @param {string} chunk - Text chunk |
| 164 | + * @returns {void} |
| 165 | + */ |
| 166 | +declare function send(chunk: string): void |
| 167 | + |
| 168 | +/** |
| 169 | + * @deprecated since version 2.0 |
| 170 | + * Initiates chunked response. As an option, a custom response object may be sent at this point. For list-functions only! |
| 171 | + * @param {Object} init_resp - InitResp object |
| 172 | + * @returns {void} |
| 173 | + */ |
| 174 | +// eslint-disable-next-line |
| 175 | +declare function start(init_resp?: CouchDB.InitResp): void |
| 176 | + |
| 177 | +/** |
| 178 | + * Sum arr’s items. |
| 179 | + * @param {number[]} arr - Array of numbers |
| 180 | + * @returns {number} |
| 181 | + */ |
| 182 | +declare function sum(arr: number[]): number |
| 183 | + |
| 184 | +/** |
| 185 | + * Encodes obj to JSON string. This is an alias for the JSON.stringify method. |
| 186 | + * @param {any} obj - Array of numbers |
| 187 | + * @returns {string} |
| 188 | + */ |
| 189 | +declare function toJSON(obj: any): string |
| 190 | + |
| 191 | +/** |
| 192 | + * 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. |
| 193 | + * Rereduce is used for additional reduce values list, so when it is true there is no information about related keys (first argument is null). |
| 194 | + * @param {string[] | null} keys - Array of pairs of docid-key for related map function results. Always null if rereduce is running (has true value). |
| 195 | + * @returns {void} |
| 196 | + */ |
| 197 | +declare type redfun = (keys: [string, string][] | null, values: any[], rereduce?: boolean) => any |
0 commit comments