go-mokapi 0.9.11 → 0.9.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "go-mokapi",
3
- "version": "0.9.11",
3
+ "version": "0.9.13",
4
4
  "description": "Easy and flexible API mocking",
5
5
  "homepage": "https://mokapi.io",
6
6
  "repository": {
package/types/faker.d.ts CHANGED
@@ -1,27 +1,68 @@
1
- declare module 'mokapi/faker' {
2
- /**
3
- * Creates a fake based on the given schema
4
- * @param schema
5
- */
6
- function fake(schema: Schema): any
7
- }
1
+ import { JSONValue } from ".";
2
+
3
+ /**
4
+ * Creates a fake based on the given schema
5
+ * https://mokapi.io/docs/javascript-api/mokapi-faker/fake
6
+ * @param schema schema - OpenAPI Schema object contains definition of a type
7
+ * @example
8
+ * export default function() {
9
+ * console.log(fake({type: 'string'}))
10
+ * console.log(fake({type: 'number'}))
11
+ * console.log(fake({type: 'string', format: 'date-time'}))
12
+ * console.log(fake({type: 'string', pattern: '^\d{3}-\d{2}-\d{4}$'})) // 123-45-6789
13
+ * }
14
+ */
15
+ export function fake(schema: Schema): JSONValue;
16
+
17
+ export interface Schema {
18
+ /** Type of fake value */
19
+ type?: "object" | "array" | "number" | "integer" | "string" | "boolean";
20
+
21
+ /** Serves as a hint at the contents and format of the string. */
22
+ format?: string;
23
+
24
+ /** Specifies regular expression that fake must match. */
25
+ pattern?: string;
26
+
27
+ /** Describes the type and format of array items. */
28
+ items?: Schema;
29
+
30
+ /** Specifies a list of required properties. */
31
+ required?: string[];
32
+
33
+ /** Specify possible value for this schema. */
34
+ enum?: JSONValue[];
35
+
36
+ /** Specifies the minimum range of possible values. */
37
+ minimum?: number;
38
+
39
+ /** Specifies the maximum range of possible values. */
40
+ maximum?: number;
8
41
 
9
- declare interface Schema {
10
- type: "object" | "array" | "number" | "integer" | "string" | "boolean"
11
- format?: string
12
- pattern?: string
13
- items?: Schema
14
- required?: string[]
15
- enum?: any[]
16
- minimum?: number
17
- maximum?: number
18
- exclusiveMinimum?: boolean
19
- exclusiveMaximum?: boolean
20
- anyOf?: Schema[]
21
- allOf?: Schema[]
22
- oneOf?: Schema[]
23
- minItems?: number
24
- maxItems?: number
25
- shuffleItems?: boolean
26
- uniqueItems?: boolean
27
- }
42
+ /** Specifies whether minimum value is exluded. Default is false. */
43
+ exclusiveMinimum?: boolean;
44
+
45
+ /** ** Specifies whether maximum value is exluded. Default is false. */
46
+ exclusiveMaximum?: boolean;
47
+
48
+ /** Valid against one of the specified schemas. */
49
+ anyOf?: Schema[];
50
+
51
+ /** Valid against all of the specified schemas. */
52
+ allOf?: Schema[];
53
+
54
+ /** Valid against exactly one of the specified schemas. */
55
+ oneOf?: Schema[];
56
+
57
+ /** Specifies the minimum number of items an array must have. */
58
+ minItems?: number;
59
+
60
+ /** Specifies the maximum number of items an array must have. */
61
+ maxItems?: number;
62
+
63
+ /** Specifies whether items in array should have random order. The default is false */
64
+ shuffleItems?: boolean;
65
+
66
+ /** Specifies whether all items in an array must be unique. */
67
+ uniqueItems?: boolean;
68
+ }
@@ -0,0 +1,27 @@
1
+ export {};
2
+
3
+ declare global {
4
+ /**
5
+ * Opens an existing file and reads its entire contents.
6
+ * https://mokapi.io/docs/javascript-api/globals/open
7
+ * @param filePath - Path to the file.
8
+ * @param args - Args object containing additional arguments
9
+ * @returns File content
10
+ * @example
11
+ * const data = JSON.parse(open("/path/to/file.json"));
12
+ * export default function() {
13
+ * mokapi.on("http", function(request, response) {
14
+ * response.data = data;
15
+ * return true;
16
+ * });
17
+ * }
18
+ */
19
+ function open(filePath: string, args?: Args): string;
20
+
21
+ interface Args {
22
+ /**
23
+ * By default contents of the file are read as string, but with binary the file will be read as binary.
24
+ */
25
+ as: "binary" | "string";
26
+ }
27
+ }
package/types/http.d.ts CHANGED
@@ -1,20 +1,120 @@
1
- declare module 'mokapi/http' {
2
- function get(url: string, args?: Args): Response
3
- function post(url: string, body?: any, args?: Args): Response
4
- function put(url: string, body?: any, args?: Args): Response
5
- function head(url: string, args?: Args): Response
6
- function patch(url: string, args?: Args): Response
7
- function del(url: string, body?: any, args?: Args): Response
8
- function options(url: string, body?: any, args?: Args): Response
9
- }
1
+ import { JSONValue } from ".";
2
+
3
+ /**
4
+ * Make GET request.
5
+ * https://mokapi.io/docs/javascript-api/mokapi-http/get
6
+ * @param url url - Request URL.
7
+ * @param args args - Request arguments.
8
+ * @returns Resulting response.
9
+ * @example
10
+ * get('https://mokapi.io')
11
+ */
12
+ export function get(url: string, args?: Args): Response;
13
+
14
+ /**
15
+ * Make POST request.
16
+ * https://mokapi.io/docs/javascript-api/mokapi-http/post
17
+ * @param url url - Request URL.
18
+ * @param body body - Request body.
19
+ * @param args args - Request arguments.
20
+ * @returns Resulting response.
21
+ * @example
22
+ * post("https://foo.bar/foo", { "foo":"bar" }, {
23
+ * headers: { 'Content-Type': "application/json" }
24
+ * })
25
+ */
26
+ export function post(url: string, body?: JSONValue, args?: Args): Response;
27
+
28
+ /**
29
+ * Make PUT request.
30
+ * https://mokapi.io/docs/javascript-api/mokapi-http/put
31
+ * @param url url - Request URL.
32
+ * @param body body - Request body.
33
+ * @param args args - Request arguments.
34
+ * @returns Resulting response.
35
+ * @example
36
+ * post("https://foo.bar/foo", { "foo":"bar" }, {
37
+ * headers: { 'Content-Type': "application/json" }
38
+ * })
39
+ */
40
+ export function put(url: string, body?: JSONValue, args?: Args): Response;
41
+
42
+ /**
43
+ * Make HEAD request.
44
+ * https://mokapi.io/docs/javascript-api/mokapi-http/head
45
+ * @param url url - Request URL.
46
+ * @param args args - Request arguments.
47
+ * @returns Resulting response.
48
+ * @example
49
+ * head("https://foo.bar/foo")
50
+ */
51
+ export function head(url: string, args?: Args): Response;
52
+
53
+ /**
54
+ * Make PATCH request.
55
+ * https://mokapi.io/docs/javascript-api/mokapi-http/patch
56
+ * @param url url - Request URL.
57
+ * @param body body - Request body.
58
+ * @param args args - Request arguments.
59
+ * @returns Resulting response.
60
+ * @example
61
+ * patch("https://foo.bar/foo")
62
+ */
63
+ export function patch(url: string, body?: JSONValue, args?: Args): Response;
10
64
 
11
- declare interface Args {
12
- headers?: { [name: string]: any };
65
+ /**
66
+ * Make PATCH request.
67
+ * https://mokapi.io/docs/javascript-api/mokapi-http/delete
68
+ * @param url url - Request URL.
69
+ * @param body body - Request body.
70
+ * @param args args - Request arguments.
71
+ * @returns Resulting response.
72
+ * @example
73
+ * del("https://foo.bar/foo")
74
+ */
75
+ export function del(url: string, body?: JSONValue, args?: Args): Response;
76
+
77
+ /**
78
+ * Make OPTIONS request.
79
+ * https://mokapi.io/docs/javascript-api/mokapi-http/options
80
+ * @param url url - Request URL.
81
+ * @param body body - Request body.
82
+ * @param args args - Request arguments.
83
+ * @returns Resulting response.
84
+ * @example
85
+ * options("https://foo.bar/foo")
86
+ */
87
+ export function options(url: string, body?: JSONValue, args?: Args): Response;
88
+
89
+ /**
90
+ * Request arguments.
91
+ * Used to add headers to a request.
92
+ */
93
+ export interface Args {
94
+ /** Request headers. */
95
+ header?: { [name: string]: string };
13
96
  }
14
97
 
15
- declare interface Response {
16
- body: string
17
- statusCode: number
18
- headers: { [name: string]: string[] }
19
- json(): any
20
- }
98
+ /**
99
+ * Response of an HTTP request
100
+ * https://mokapi.io/docs/javascript-api/mokapi-http/httpresponse
101
+ */
102
+ export interface Response {
103
+ /** Response body */
104
+ body: string;
105
+
106
+ /** HTTP status code */
107
+ statusCode: number;
108
+
109
+ /** Response headers */
110
+ headers: { [name: string]: string[] };
111
+
112
+ /**
113
+ * Parse body as JSON
114
+ * @returns Returns a JS object, array or value
115
+ * @example
116
+ * const res = get(url)
117
+ * res.json()
118
+ */
119
+ json(): JSONValue;
120
+ }
@@ -0,0 +1,275 @@
1
+ /**
2
+ * Mokapi JavaScript API
3
+ * https://mokapi.io/docs/guides/get-started/welcome
4
+ */
5
+
6
+ import "./faker";
7
+ import "./global";
8
+ import "./http";
9
+ import { KafkaEventHandler } from "./kafka";
10
+ import { LdapEventHandler } from "./ldap";
11
+ import "./mustache";
12
+ import "./yaml";
13
+
14
+ /**
15
+ * Attaches an event handler for the given event.
16
+ * https://mokapi.io/docs/javascript-api/mokapi/on
17
+ * @param event Event type such as http
18
+ * @param handler An EventHandler to execute when the event is triggered
19
+ * @param args EventArgs object contains additional event arguments.
20
+ * @example
21
+ * export default function() {
22
+ * on('http', function(request, response) {
23
+ * if (request.url.path === '/echo') {
24
+ * response.data = {
25
+ * url: request.url.toString(),
26
+ * body: request.body,
27
+ * }
28
+ * }
29
+ * })
30
+ * }
31
+ */
32
+ export function on<T extends keyof EventHandler>(event: T, handler: EventHandler[T], args?: EventArgs): void;
33
+
34
+ /**
35
+ * Schedules a new periodic job with interval.
36
+ * @param interval interval - Scheduled interval.
37
+ * @param f f - Scheduled event handler
38
+ * @param args args - Additional arguments
39
+ * @example
40
+ * export default function() {
41
+ * every('1m', function() {
42
+ * console.log('foo')
43
+ * })
44
+ * }
45
+ */
46
+ export function every(interval: Interval, f: ScheduledEventHandler, args?: ScheduledEventArgs): void;
47
+
48
+ /**
49
+ * Schedules a new periodic job with a cron expression.
50
+ * @param expr expr - Cron expression
51
+ * @param f f - cheduled event handler
52
+ * @param args args - Additional arguments
53
+ * @example
54
+ * export default function() {
55
+ * cron('* * * * *', function() {
56
+ * console.log('foo')
57
+ * })
58
+ * }
59
+ */
60
+ export function cron(expr: string, f: ScheduledEventHandler, args?: ScheduledEventArgs): void;
61
+
62
+ /**
63
+ * Retrieves the value of the environment variable named by the key.
64
+ * @param name name - The name of the environment variable.
65
+ * @returns The value of the environment variable specified by variable, or an empty string
66
+ * if the environment variable is not found.
67
+ * @example
68
+ * export default function() {
69
+ * console.log(env('foo'))
70
+ * }
71
+ */
72
+ export function env(name: string): string;
73
+
74
+ /**
75
+ * Returns a textual representation of the date.
76
+ * https://mokapi.io/docs/javascript-api/mokapi/date
77
+ * @description Default layout is RFC3339. Default timestamp is current UTC
78
+ * @param args args - Adjusting textual representation
79
+ * @example
80
+ * export default function() {
81
+ * console.log(date())
82
+ * console.log(date({layout: 'UnixDate'}))
83
+ * console.log(date({timestamp: new Date().getTime()}))
84
+ * }
85
+ */
86
+ export function date(args?: DateArgs): string;
87
+
88
+ /**
89
+ * Suspends the execution for the specified duration.
90
+ * https://mokapi.io/docs/javascript-api/mokapi/sleep
91
+ * @param time Duration in milliseconds or duration as string with unit.
92
+ * Valid time units are `ns`, `us` (or `µs`), `ms`, `s`, `m`, `h`
93
+ */
94
+ export function sleep(time: number | string): void;
95
+
96
+ /**
97
+ * Specifies the interval of a periodic job.
98
+ * Interval string is a possibly signed sequence of decimal numbers, each with optional
99
+ * fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m".
100
+ * Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
101
+ */
102
+ export type Interval = string;
103
+
104
+ export interface EventHandler {
105
+ http: HttpEventHandler;
106
+ kafka: KafkaEventHandler;
107
+ ldap: LdapEventHandler;
108
+ }
109
+
110
+ /**
111
+ * HttpEventHandler is a function that is executed when an HTTP event is triggered.
112
+ * https://mokapi.io/docs/javascript-api/mokapi/eventhandler/httpeventhandler
113
+ * @example
114
+ * export default function() {
115
+ * on('http', function(request, response) {
116
+ * if (request.operationId === 'time') {
117
+ * response.body = date()
118
+ * return true
119
+ * }
120
+ * return false
121
+ * })
122
+ * }
123
+ */
124
+ export type HttpEventHandler = (request: HttpRequest, response: HttpResponse) => boolean;
125
+
126
+ /**
127
+ * HttpRequest is an object used by HttpEventHandler that contains request-specific
128
+ * data such as HTTP headers.
129
+ * https://mokapi.io/docs/javascript-api/mokapi/eventhandler/httprequest
130
+ */
131
+ export interface HttpRequest {
132
+ /** Request method. */
133
+ readonly method: string;
134
+
135
+ /** Represents a parsed URL. */
136
+ readonly url: Url;
137
+
138
+ /** Body contains request body specified by OpenAPI request body. */
139
+ readonly body: JSONValue;
140
+
141
+ /** Object contains path parameters specified by OpenAPI path parameters. */
142
+ readonly path: { [key: string]: JSONValue };
143
+
144
+ /** Object contains query parameters specified by OpenAPI query parameters. */
145
+ readonly query: { [key: string]: JSONValue };
146
+
147
+ /** Object contains header parameters specified by OpenAPI header parameters. */
148
+ readonly header: { [key: string]: JSONValue };
149
+
150
+ /** Object contains cookie parameters specified by OpenAPI cookie parameters. */
151
+ readonly cookie: { [key: string]: JSONValue };
152
+
153
+ /** Path value specified by the OpenAPI path */
154
+ readonly key: string;
155
+
156
+ /** OperationId defined in OpenAPI */
157
+ readonly operationId: string;
158
+ }
159
+
160
+ /**
161
+ * HttpResponse is an object used by HttpEventHandler that contains response-specific data such as HTTP headers.
162
+ * https://mokapi.io/docs/javascript-api/mokapi/eventhandler/httpresponse
163
+ */
164
+ export interface HttpResponse {
165
+ /** Object contains header parameters specified by OpenAPI header parameters. */
166
+ headers: { [key: string]: string };
167
+
168
+ /** Specifies the http status used to select the OpenAPI response definition. */
169
+ statusCode: number;
170
+
171
+ /** Response body. It has a higher precedence than data. */
172
+ body: string;
173
+
174
+ /** Data will be encoded with the OpenAPI response definition. */
175
+ data: JSONValue;
176
+ }
177
+
178
+ /**
179
+ * Represents an URL
180
+ */
181
+ export interface Url {
182
+ /** URL scheme. */
183
+ readonly scheme: string;
184
+
185
+ /** URL host. */
186
+ readonly host: string;
187
+
188
+ /** URL path. */
189
+ readonly path: string;
190
+
191
+ /** URL query string. */
192
+ readonly query: string;
193
+ }
194
+
195
+ /**
196
+ * Contains optional arguments to format a datetime object
197
+ */
198
+ export interface DateArgs {
199
+ /**
200
+ * The format of the textual representation, default is RFC3339
201
+ */
202
+ layout?: DateLayout;
203
+
204
+ /**
205
+ * The timestamp of the date, default is current UTC time
206
+ */
207
+ timestamp?: number;
208
+ }
209
+
210
+ /**
211
+ * These are predefined layouts for use in date()
212
+ */
213
+ export type DateLayout =
214
+ | "DateTime"
215
+ | "DateOnly"
216
+ | "TimeOnly"
217
+ | "UnixDate"
218
+ | "RFC882"
219
+ | "RFC822Z"
220
+ | "RFC850"
221
+ | "RFC1123"
222
+ | "RFC1123Z"
223
+ | "RFC3339"
224
+ | "RFC3339Nano";
225
+
226
+ /**
227
+ * Additional event arguments
228
+ */
229
+ export interface EventArgs {
230
+ /**
231
+ * Adds or overrides existing tags used in dashboard
232
+ */
233
+ tags?: { [key: string]: string };
234
+ }
235
+
236
+ /**
237
+ * cheduledEventArgs is an object used by every and cron function.
238
+ * https://mokapi.io/docs/javascript-api/mokapi/eventhandler/scheduledeventargs
239
+ * @example
240
+ * export default function() {
241
+ * every('1m', function() {
242
+ * console.log('foo')
243
+ * }, {times: 1, runFirstTimeImmediately: false})
244
+ * }
245
+ */
246
+ export type ScheduledEventHandler = () => void;
247
+
248
+ export interface ScheduledEventArgs {
249
+ /**
250
+ * Adds or overrides existing tags used in dashboard
251
+ */
252
+ tags?: { [key: string]: string };
253
+
254
+ /**
255
+ * Defines the number of times the scheduled function is executed.
256
+ */
257
+ times?: number;
258
+
259
+ /**
260
+ * Toggles behavior of first execution. Default is true
261
+ */
262
+ runFirstTimeImmediately?: boolean;
263
+ }
264
+
265
+ /**
266
+ * JavaScript value representable with JSON.
267
+ */
268
+ export type JSONValue = null | boolean | number | string | JSONValue[] | JSONObject;
269
+
270
+ /**
271
+ * Object representable with JSON.
272
+ */
273
+ export interface JSONObject {
274
+ [key: string]: JSONValue;
275
+ }
package/types/kafka.d.ts CHANGED
@@ -1,36 +1,113 @@
1
- declare module 'mokapi/kafka' {
2
- function produce(args: ProduceArgs): ProduceResult
3
- }
1
+ import { JSONValue } from ".";
4
2
 
5
- declare interface ProduceArgs {
6
- cluster?: string
7
- topic?: string
8
- partition?: number
9
- key?: any
10
- value?: any
11
- headers?: {[key: string]: any; }
12
- }
3
+ /**
4
+ * Sends a single message to a Kafka topic.
5
+ * https://mokapi.io/docs/javascript-api/mokapi-kafka/produce
6
+ * @param args - ProduceArgs object contains Kafka produce arguments.
7
+ * @returns The produce result.
8
+ * @example
9
+ * export default function() {
10
+ * const res = produce({
11
+ * topic: 'foo',
12
+ * key: 'foo-1',
13
+ * value: { foo: "bar" }
14
+ * });
15
+ * console.log(`new kafka message written with offset: ${res.offset}`)
16
+ * }
17
+ */
18
+ export function produce(args: ProduceArgs): ProduceResult;
19
+
20
+ /**
21
+ * Contains produce-specific arguments.
22
+ * https://mokapi.io/docs/javascript-api/mokapi-kafka/produceargs
23
+ * @example
24
+ * export default function() {
25
+ * const res = produce({
26
+ * topic: 'foo',
27
+ * key: 'foo-1',
28
+ * value: { foo: "bar"}
29
+ * });
30
+ * }
31
+ */
32
+ export interface ProduceArgs {
33
+ /** Kafka cluster name. Used when topic name is not unique. */
34
+ cluster?: string;
35
+
36
+ /** Kafka topic name. If not specified, message will be written to a random topic. */
37
+ topic?: string;
38
+
39
+ /** Kafka partition index. If not specified, the message will be written to any partition */
40
+ partition?: number;
13
41
 
14
- declare interface ProduceResult {
15
- cluster: string
16
- topic: string
17
- partition: number
18
- offset: number
19
- key: string
20
- value: string
42
+ /** Kafka message key. If not specified, a random key will be generated based on the topic configuration. */
43
+ key?: JSONValue;
44
+
45
+ /** Kafka message value. If not specified, a random value will be generated based on the topic configuration. */
46
+ value?: JSONValue;
47
+
48
+ /** Kafka message headers. */
49
+ headers?: { [name: string]: JSONValue };
21
50
  }
22
51
 
23
- type KafkaEventHandler = (record: KafkaRecord) => boolean
52
+ /**
53
+ * Contains information of the written Kafka message.
54
+ * https://mokapi.io/docs/javascript-api/mokapi-kafka/produceresult
55
+ * @example
56
+ * export default function() {
57
+ * const res = produce({ topic: 'foo' })
58
+ * console.log(`new kafka message written with offset: ${res.offset}`)
59
+ * }
60
+ */
61
+ export interface ProduceResult {
62
+ /** Name of the Kafka cluster where the message was written. */
63
+ readonly cluster: string;
64
+
65
+ /** Kafka topic name where the message was written. */
66
+ readonly topic: string;
67
+
68
+ /** Kafka partition where the message was written. */
69
+ readonly partition: number;
24
70
 
25
- declare interface KafkaRecord {
26
- offset: number
27
- time: number
28
- key: number[]
29
- value: number[]
30
- headers: { [name: string]: string }
71
+ /** The offset of the written message. */
72
+ readonly offset: number;
73
+
74
+ /** The key of the written message, */
75
+ readonly key: string;
76
+
77
+ /** The value of the written message. */
78
+ readonly value: string;
79
+
80
+ /** The headers of the written message */
81
+ readonly headers: { [name: string]: string };
31
82
  }
32
83
 
33
- declare interface KafkaHeader {
34
- key: string
35
- value: string
36
- }
84
+ /**
85
+ * KafkaEventHandler is a function that is executed when a Kafka message is received.
86
+ * https://mokapi.io/docs/javascript-api/mokapi/eventhandler/KafkaEventHandler
87
+ * @example
88
+ * export default function() {
89
+ * on('kafka', function(record) {
90
+ * // add header 'foo' to every Kafka message
91
+ * record.headers = { foo: 'bar' }
92
+ * })
93
+ * }
94
+ */
95
+ export type KafkaEventHandler = (record: KafkaRecord) => boolean;
96
+
97
+ /**
98
+ * KafkaRecord is an object used by KafkaEventHandler that contains Kafka-specific message data.
99
+ * https://mokapi.io/docs/javascript-api/mokapi/eventhandler/KafkaRecord
100
+ */
101
+ export interface KafkaRecord {
102
+ /** Kafka partition where the message was written to (read-only). */
103
+ readonly offset: number;
104
+
105
+ /** Kafka message key */
106
+ key: string;
107
+
108
+ /** Kafka message value */
109
+ value: string;
110
+
111
+ /** Kafka message headers */
112
+ headers: { [name: string]: string } | null;
113
+ }
package/types/ldap.d.ts CHANGED
@@ -1,54 +1,118 @@
1
- type LdapEventHandler = (request: LdapSearchRequest, response: LdapSearchResponse) => boolean
2
-
3
- declare module 'mokapi/ldap' {
4
- enum SearchScope {
5
- BaseObject,
6
- SingleLevel,
7
- WholeSubtree
8
- }
9
- enum ResultCode {
10
- Success = 0,
11
- OperationsError = 1,
12
- ProtocolError = 2,
13
- SizeLimitExceeded = 3,
14
- AuthMethodNotSupported = 4,
15
- CannotCancel = 121
16
- }
17
- }
1
+ /**
2
+ * LdapEventHandler is a function that is executed when a LDAP search query is triggered.
3
+ * @example
4
+ * export default function() {
5
+ * on('ldap', function(request, response) {
6
+ * if (request.filter === '(objectClass=foo)') {
7
+ * response.results = [
8
+ * {
9
+ * dn: 'CN=bob,CN=users,DC=mokapi,DC=io',
10
+ * attributes: {
11
+ * mail: ['bob@mokapi.io'],
12
+ * objectClass: ['foo']
13
+ * }
14
+ * }
15
+ * ]
16
+ * }
17
+ * })
18
+ * }
19
+ */
20
+ export type LdapEventHandler = (request: LdapSearchRequest, response: LdapSearchResponse) => boolean;
21
+
22
+ /**
23
+ * LdapSearchRequest is an object used by LdapEventHandler that contains request-specific data.
24
+ */
25
+ export interface LdapSearchRequest {
26
+ /** Search base DN. */
27
+ baseDN: string;
28
+
29
+ /** Search scope. */
30
+ scope: LdapSearchScope;
31
+
32
+ /** Alias dereference policy. */
33
+ dereferencePolicy: number;
34
+
35
+ /** Maximum number of entries to return from the search. */
36
+ sizeLimit: number;
18
37
 
19
- declare interface LdapSearchRequest {
20
- baseDN: string
21
- scope: LdapSearchScope,
22
- dereferencePolicy: number,
23
- sizeLimit: number,
24
- timeLimit: number,
25
- typesOnly: number,
26
- filter: string
27
- attributes: string[]
38
+ /** Maximum length of time in seconds to allow for the search. */
39
+ timeLimit: number;
40
+
41
+ /** Only retrieve attribute names but not their values. */
42
+ typesOnly: number;
43
+
44
+ /** String representation of an LDAP search filter. */
45
+ filter: string;
46
+
47
+ /** Attribute list specifies the attributes to return in the entries found by the search. */
48
+ attributes: string[];
28
49
  }
29
50
 
30
- declare interface LdapSearchResponse{
31
- results: LdapSearchResult[]
32
- status: LdapResultStatus
33
- message: string
51
+ /**
52
+ * LdapSearchResponse is an object used by LdapEventHandler that contains response-specific data.
53
+ */
54
+ export interface LdapSearchResponse {
55
+ /** List of search result */
56
+ results: LdapSearchResult[];
57
+
58
+ /** Status of search operation */
59
+ status: LdapResultStatus;
60
+
61
+ /** Search response message */
62
+ message: string;
34
63
  }
35
64
 
36
- declare interface LdapSearchResult {
37
- dn: string
38
- attributes: { [name: string]: string[] }
65
+ /**
66
+ * LdapSearchResult is an object used by LdapSearchResponse that contains one result of a search request.
67
+ */
68
+ export interface LdapSearchResult {
69
+ /** LDAP distinguished name of this result. */
70
+ dn: string;
71
+
72
+ /** Attribute list of this result */
73
+ attributes: { [name: string]: string[] };
39
74
  }
40
75
 
41
- declare enum LdapSearchScope {
76
+ /**
77
+ * Specifies the portion of the target subtree that should be considered.
78
+ */
79
+ export enum LdapSearchScope {
80
+ /**
81
+ * Indicates that only the entry specified as sthe search base should be considered.
82
+ * None of its subordinates will be considered.
83
+ */
42
84
  BaseObject,
85
+
86
+ /**
87
+ * Indicates that only the immediate children of the entry specified should be considered.
88
+ */
43
89
  SingleLevel,
44
- WholeSubtree
90
+
91
+ /**
92
+ * Indicates that the entry specified as the search base, and all of its subordinates to any depth.
93
+ */
94
+ WholeSubtree,
45
95
  }
46
96
 
47
- declare enum LdapResultStatus {
97
+ /**
98
+ * Defines a number of result codes that are intended to be used in LdapSearchResponse.
99
+ */
100
+ export enum LdapResultStatus {
101
+ /** The success result code is used to indicate that the associated operation completed successfully. */
48
102
  Success = 0,
103
+
104
+ /** Indicates that the operation could not be processed because it wasn’t in the expected
105
+ * order relative to other operations on the same connection.
106
+ */
49
107
  OperationsError = 1,
108
+
109
+ /** Indicates that there was a problem with the client’s use of the LDAP protocol. */
50
110
  ProtocolError = 2,
51
- SizeLimitExceeded = 3,
52
- AuthMethodNotSupported = 4,
53
- CannotCancel = 121
54
- }
111
+
112
+ /**
113
+ * indicates that the associated search operation failed because the server has determined
114
+ * that the number of entries that would be returned in response to the search would exceed
115
+ * the upper bound for that operation.
116
+ */
117
+ SizeLimitExceeded = 4,
118
+ }
@@ -1,3 +1,34 @@
1
- declare module 'mokapi/mustache' {
2
- function render(template: string, data: any): string
1
+ import { JSONValue } from ".";
2
+
3
+ /**
4
+ * Renders the given mustache template with the given data.
5
+ * https://mokapi.io/docs/javascript-api/mokapi-mustache/render
6
+ * @param template template - A mustache template.
7
+ * @param data data - A scope object that contains the data needed to render the template.
8
+ * @returns The rendered template
9
+ * @example
10
+ * export default function() {
11
+ * const scope = {
12
+ * firstname: fake({
13
+ * type: 'string',
14
+ * format: '{firstname}'
15
+ * }),
16
+ * calc: () => ( 3 + 4 )
17
+ * }
18
+ *
19
+ * const output = render("{{firstname}} has {{calc}} apples", scope)
20
+ * console.log(output)
21
+ * }
22
+ */
23
+ export function render(template: string, data: Scope): string;
24
+
25
+ export type Scope = null | Scope[] | ScopeObject | JSONValue;
26
+
27
+ /**
28
+ * Object representable with JSON.
29
+ */
30
+ export interface ScopeObject {
31
+ [key: string]: Scope | ScopeFunction;
3
32
  }
33
+
34
+ export type ScopeFunction = () => Scope;
package/types/yaml.d.ts CHANGED
@@ -1,4 +1,38 @@
1
- declare module 'mokapi/yaml' {
2
- function parse(s: string): any
3
- function stringify(value: any): string
4
- }
1
+ import { JSONValue } from ".";
2
+
3
+ /**
4
+ * Parses a YAML string, constructing the JavaScript value or object described by the string.
5
+ * https://mokapi.io/docs/javascript-api/mokapi-yaml/parse
6
+ * @param text text - The string to parse as YAML.
7
+ * @returns The value corresponding to the given YAML text.
8
+ * @example
9
+ * export default function() {
10
+ * const orders = parse(open('orders.yaml'))
11
+ * console.log(outout[0].orderId)
12
+ * }
13
+ */
14
+ export function parse(text: string): JSONValue;
15
+
16
+ /**
17
+ * Converts a JavaScript value to a YAML string.
18
+ * @param value value - The value to convert to a YAML string.
19
+ * @returns A YAML string representing the given value
20
+ * @example
21
+ * export default function() {
22
+ * const orders = [
23
+ * {
24
+ * orderId: 345,
25
+ * customer: 'Bob'
26
+ * },
27
+ * {
28
+ * orderId: 874,
29
+ * customer: 'Alice'
30
+ * }
31
+ * ]
32
+ *
33
+ * on('http', function(request, response) {
34
+ * response.body = stringify(orders)
35
+ * })
36
+ * }
37
+ */
38
+ export function stringify(value: JSONValue): string;