go-mokapi 0.9.22 → 0.9.26

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.22",
3
+ "version": "0.9.26",
4
4
  "description": "Easy and flexible API mocking",
5
5
  "homepage": "https://mokapi.io",
6
6
  "repository": {
package/types/faker.d.ts CHANGED
@@ -26,27 +26,144 @@ export function fake(schema: Schema | FakeRequest): JSONValue;
26
26
  */
27
27
  export function findByName(name: string): Tree
28
28
 
29
+ /**
30
+ * The name of the root faker tree
31
+ */
29
32
  export const RootName = 'Faker'
30
33
 
34
+ /**
35
+ * The Tree object represents a node in the faker tree
36
+ */
31
37
  export interface Tree {
38
+ /**
39
+ * Gets the name of the tree node
40
+ */
32
41
  name: string
33
- readonly test: () => boolean
34
- readonly fake: () => JSONValue
35
42
 
43
+ /**
44
+ * Tests whether the tree node supports the request.
45
+ * @param request request - Request for a new fake value
46
+ * @example
47
+ * export default function() {
48
+ * const frequencyItems = ['never', 'daily', 'weekly', 'monthly', 'yearly']
49
+ * const node = findByName('Strings')
50
+ * node.append({
51
+ * name: 'Frequency',
52
+ * test: (r) => { return r.lastName() === 'frequency' },
53
+ * fake: (r) => {
54
+ * return frequencyItems[Math.floor(Math.random()*frequencyItems.length)]
55
+ * }
56
+ * })
57
+ * return fake({ type: 'string' })
58
+ * }
59
+ */
60
+ readonly test: (request: FakeRequest) => boolean
61
+
62
+ /**
63
+ * Gets a new fake value
64
+ * @param request request - Request for a new fake value
65
+ * @example
66
+ * export default function() {
67
+ * const frequencyItems = ['never', 'daily', 'weekly', 'monthly', 'yearly']
68
+ * const node = findByName('Strings')
69
+ * node.append({
70
+ * name: 'Frequency',
71
+ * test: (r) => { return r.lastName() === 'frequency' },
72
+ * fake: (r) => {
73
+ * return frequencyItems[Math.floor(Math.random()*frequencyItems.length)]
74
+ * }
75
+ * })
76
+ * return fake({ type: 'string' })
77
+ * }
78
+ */
79
+ readonly fake: (request: FakeRequest) => JSONValue
80
+
81
+ /**
82
+ * Inserts a Tree objects after the last child of this tree.
83
+ * @param node node - A Tree node to insert after the last child.
84
+ */
36
85
  append: (node: Tree | CustomTree) => void
86
+
87
+ /**
88
+ * Inserts a Tree objects at a specified index position
89
+ * @param index index - The zero-based index position of the insertion.
90
+ * @param node node - The tree node to insert
91
+ */
37
92
  insert: (index: number, node: Tree | CustomTree) => void
93
+
94
+ /**
95
+ * Removes a Tree node at the specific index position
96
+ * @param index index - The zero-based index position to remove.
97
+ */
38
98
  removeAt: (index: number) => void
99
+
100
+ /**
101
+ * Removes a Tree node with the given name
102
+ * @param name name - The name of a node to remove
103
+ */
39
104
  remove: (name: string) => void
40
105
  }
41
106
 
107
+ /**
108
+ * The CustomTree object represents a custom node in the faker tree
109
+ */
42
110
  export interface CustomTree {
111
+ /**
112
+ * Gets the name of the custom tree node
113
+ */
43
114
  name: string
115
+
116
+ /**
117
+ * Tests whether the tree node supports the request.
118
+ * @param request request - Request for a new fake value
119
+ * @example
120
+ * export default function() {
121
+ * const frequencyItems = ['never', 'daily', 'weekly', 'monthly', 'yearly']
122
+ * const node = findByName('Strings')
123
+ * node.append({
124
+ * name: 'Frequency',
125
+ * test: (r) => { return r.lastName() === 'frequency' },
126
+ * fake: (r) => {
127
+ * return frequencyItems[Math.floor(Math.random()*frequencyItems.length)]
128
+ * }
129
+ * })
130
+ * return fake({ type: 'string' })
131
+ * }
132
+ */
44
133
  test: (r: Request) => boolean
134
+
135
+ /**
136
+ * Gets a new fake value
137
+ * @param request request - Request for a new fake value
138
+ * @example
139
+ * export default function() {
140
+ * const frequencyItems = ['never', 'daily', 'weekly', 'monthly', 'yearly']
141
+ * const node = findByName('Strings')
142
+ * node.append({
143
+ * name: 'Frequency',
144
+ * test: (r) => { return r.lastName() === 'frequency' },
145
+ * fake: (r) => {
146
+ * return frequencyItems[Math.floor(Math.random()*frequencyItems.length)]
147
+ * }
148
+ * })
149
+ * return fake({ type: 'string' })
150
+ * }
151
+ */
45
152
  fake: (r: Request) => JSONValue
46
153
  }
47
154
 
155
+ /**
156
+ * Represents a request for a fake value
157
+ */
48
158
  export interface FakeRequest {
159
+ /**
160
+ * Contains a list of attribute names representing the object graph for which a new value is to be faked
161
+ */
49
162
  names: string[]
163
+
164
+ /**
165
+ * Describing the structure of JSON data to be faked
166
+ */
50
167
  schema: JSONSchema
51
168
  }
52
169
 
package/types/global.d.ts CHANGED
@@ -20,7 +20,8 @@ declare global {
20
20
 
21
21
  interface Args {
22
22
  /**
23
- * By default contents of the file are read as string, but with binary the file will be read as binary.
23
+ * By default, contents of the file are read as string, but with binary the file will be read as binary.
24
+ * @default binary
24
25
  */
25
26
  as: "binary" | "string";
26
27
  }
package/types/index.d.ts CHANGED
@@ -6,8 +6,6 @@
6
6
  import "./faker";
7
7
  import "./global";
8
8
  import "./http";
9
- import { KafkaEventHandler } from "./kafka";
10
- import { LdapEventHandler } from "./ldap";
11
9
  import "./mustache";
12
10
  import "./yaml";
13
11
 
@@ -105,6 +103,7 @@ export interface EventHandler {
105
103
  http: HttpEventHandler;
106
104
  kafka: KafkaEventHandler;
107
105
  ldap: LdapEventHandler;
106
+ smtp: SmtpEventHandler;
108
107
  }
109
108
 
110
109
  /**
@@ -192,6 +191,187 @@ export interface Url {
192
191
  readonly query: string;
193
192
  }
194
193
 
194
+ /**
195
+ * KafkaEventHandler is a function that is executed when a Kafka message is received.
196
+ * https://mokapi.io/docs/javascript-api/mokapi/eventhandler/KafkaEventHandler
197
+ * @example
198
+ * export default function() {
199
+ * on('kafka', function(msg) {
200
+ * // add header 'foo' to every Kafka message
201
+ * msg.headers = { foo: 'bar' }
202
+ * })
203
+ * }
204
+ */
205
+ export type KafkaEventHandler = (message: KafkaEventMessage) => boolean;
206
+
207
+ /**
208
+ * KafkaEventMessage is an object used by KafkaEventHandler that contains Kafka-specific message data.
209
+ * https://mokapi.io/docs/javascript-api/mokapi/eventhandler/KafkaEventMessage
210
+ */
211
+ export interface KafkaEventMessage {
212
+ /** Kafka partition where the message was written to (read-only). */
213
+ readonly offset: number;
214
+
215
+ /** Kafka message key */
216
+ key: string;
217
+
218
+ /** Kafka message value */
219
+ value: string;
220
+
221
+ /** Kafka message headers */
222
+ headers: { [name: string]: string } | null;
223
+ }
224
+
225
+ /**
226
+ * LdapEventHandler is a function that is executed when a LDAP search query is triggered.
227
+ * @example
228
+ * export default function() {
229
+ * on('ldap', function(request, response) {
230
+ * if (request.filter === '(objectClass=foo)') {
231
+ * response.results = [
232
+ * {
233
+ * dn: 'CN=bob,CN=users,DC=mokapi,DC=io',
234
+ * attributes: {
235
+ * mail: ['bob@mokapi.io'],
236
+ * objectClass: ['foo']
237
+ * }
238
+ * }
239
+ * ]
240
+ * }
241
+ * })
242
+ * }
243
+ */
244
+ export type LdapEventHandler = (request: LdapSearchRequest, response: LdapSearchResponse) => boolean;
245
+
246
+ /**
247
+ * LdapSearchRequest is an object used by LdapEventHandler that contains request-specific data.
248
+ */
249
+ export interface LdapSearchRequest {
250
+ /** Search base DN. */
251
+ baseDN: string;
252
+
253
+ /** Search scope. */
254
+ scope: LdapSearchScope;
255
+
256
+ /** Alias dereference policy. */
257
+ dereferencePolicy: number;
258
+
259
+ /** Maximum number of entries to return from the search. */
260
+ sizeLimit: number;
261
+
262
+ /** Maximum length of time in seconds to allow for the search. */
263
+ timeLimit: number;
264
+
265
+ /** Only retrieve attribute names but not their values. */
266
+ typesOnly: number;
267
+
268
+ /** String representation of an LDAP search filter. */
269
+ filter: string;
270
+
271
+ /** Attribute list specifies the attributes to return in the entries found by the search. */
272
+ attributes: string[];
273
+ }
274
+
275
+ /**
276
+ * LdapSearchResponse is an object used by LdapEventHandler that contains response-specific data.
277
+ */
278
+ export interface LdapSearchResponse {
279
+ /** List of search result */
280
+ results: LdapSearchResult[];
281
+
282
+ /** Status of search operation */
283
+ status: LdapResultStatus;
284
+
285
+ /** Search response message */
286
+ message: string;
287
+ }
288
+
289
+ /**
290
+ * LdapSearchResult is an object used by LdapSearchResponse that contains one result of a search request.
291
+ */
292
+ export interface LdapSearchResult {
293
+ /** LDAP distinguished name of this result. */
294
+ dn: string;
295
+
296
+ /** Attribute list of this result */
297
+ attributes: { [name: string]: string[] };
298
+ }
299
+
300
+ /**
301
+ * Specifies the portion of the target subtree that should be considered.
302
+ */
303
+ export enum LdapSearchScope {
304
+ /**
305
+ * Indicates that only the entry specified as sthe search base should be considered.
306
+ * None of its subordinates will be considered.
307
+ */
308
+ BaseObject,
309
+
310
+ /**
311
+ * Indicates that only the immediate children of the entry specified should be considered.
312
+ */
313
+ SingleLevel,
314
+
315
+ /**
316
+ * Indicates that the entry specified as the search base, and all of its subordinates to any depth.
317
+ */
318
+ WholeSubtree,
319
+ }
320
+
321
+ /**
322
+ * Defines a number of result codes that are intended to be used in LdapSearchResponse.
323
+ */
324
+ export enum LdapResultStatus {
325
+ /** The success result code is used to indicate that the associated operation completed successfully. */
326
+ Success = 0,
327
+
328
+ /** Indicates that the operation could not be processed because it wasn’t in the expected
329
+ * order relative to other operations on the same connection.
330
+ */
331
+ OperationsError = 1,
332
+
333
+ /** Indicates that there was a problem with the client’s use of the LDAP protocol. */
334
+ ProtocolError = 2,
335
+
336
+ /**
337
+ * indicates that the associated search operation failed because the server has determined
338
+ * that the number of entries that would be returned in response to the search would exceed
339
+ * the upper bound for that operation.
340
+ */
341
+ SizeLimitExceeded = 4,
342
+ }
343
+
344
+ type SmtpEventHandler = (record: SmtpEventMessage) => boolean
345
+
346
+ declare interface SmtpEventMessage {
347
+ server: string
348
+ sender?: Address
349
+ from: Address[]
350
+ to: Address[]
351
+ replyTo?: Address[]
352
+ cc?: Address[]
353
+ bcc?: Address[]
354
+ messageId: string
355
+ inReplyTo?: string
356
+ time?: Date
357
+ subject: string
358
+ contentType: string
359
+ encoding: string
360
+ body: string
361
+ attachments: Attachment[]
362
+ }
363
+
364
+ declare interface Address {
365
+ name?: string
366
+ address: string
367
+ }
368
+
369
+ declare interface Attachment {
370
+ name: string
371
+ contentType: string
372
+ data: Uint8Array
373
+ }
374
+
195
375
  /**
196
376
  * Contains optional arguments to format a datetime object
197
377
  */
@@ -273,3 +453,5 @@ export type JSONValue = null | boolean | number | string | JSONValue[] | JSONObj
273
453
  export interface JSONObject {
274
454
  [key: string]: JSONValue;
275
455
  }
456
+
457
+ declare const RFC3339 = "RFC3339"
package/types/kafka.d.ts CHANGED
@@ -9,8 +9,12 @@ import { JSONValue } from ".";
9
9
  * export default function() {
10
10
  * const res = produce({
11
11
  * topic: 'foo',
12
- * key: 'foo-1',
13
- * value: { foo: "bar" }
12
+ * messages: [
13
+ * {
14
+ * key: 'foo-1',
15
+ * data: { foo: 'bar' }
16
+ * }
17
+ * ]
14
18
  * });
15
19
  * console.log(`new kafka message written with offset: ${res.offset}`)
16
20
  * }
@@ -24,8 +28,16 @@ export function produce(args: ProduceArgs): ProduceResult;
24
28
  * export default function() {
25
29
  * const res = produce({
26
30
  * topic: 'foo',
27
- * key: 'foo-1',
28
- * value: { foo: "bar"}
31
+ * messages: [
32
+ * {
33
+ * key: 'foo-1',
34
+ * data: { foo: 'bar-1' }
35
+ * },
36
+ * {
37
+ * key: 'foo-2',
38
+ * data: { foo: 'bar-2' }
39
+ * }
40
+ * ]
29
41
  * });
30
42
  * }
31
43
  */
@@ -47,6 +59,53 @@ export interface ProduceArgs {
47
59
 
48
60
  /** Kafka message headers. */
49
61
  headers?: { [name: string]: JSONValue };
62
+
63
+ /**
64
+ * An array of Kafka messages
65
+ * @see KafkaMessage
66
+ * @example
67
+ * export default function() {
68
+ * const res = produce({
69
+ * topic: 'foo',
70
+ * messages: [
71
+ * {
72
+ * key: 'foo-1',
73
+ * data: { foo: 'bar-1' }
74
+ * },
75
+ * {
76
+ * key: 'foo-2',
77
+ * data: { foo: 'bar-2' }
78
+ * }
79
+ * ]
80
+ * });
81
+ * }
82
+ */
83
+ messages: Message[]
84
+
85
+ /**
86
+ * The retry option is used if script is executed before Kafka topic is set up.
87
+ */
88
+ retry: ProduceRetry
89
+ }
90
+
91
+ /**
92
+ * Represents a Kafka message
93
+ */
94
+ export interface Message {
95
+ /** Kafka partition index. If not specified, the message will be written to any partition */
96
+ partition?: number;
97
+
98
+ /** Kafka message key. If not specified, a random key will be generated based on the topic configuration. */
99
+ key?: JSONValue;
100
+
101
+ /** Kafka message value. If data and value are not specified, a random value will be generated based on the topic configuration. */
102
+ data?: JSONValue;
103
+
104
+ /** Kafka message value not validating against schema. If data and value are not specified, a random value will be generated based on the topic configuration. */
105
+ value?: string | number | boolean | null
106
+
107
+ /** Kafka message headers. */
108
+ headers?: { [name: string]: JSONValue };
50
109
  }
51
110
 
52
111
  /**
@@ -65,6 +124,8 @@ export interface ProduceResult {
65
124
  /** Kafka topic name where the message was written. */
66
125
  readonly topic: string;
67
126
 
127
+ messages: MessageResult[]
128
+
68
129
  /** Kafka partition where the message was written. */
69
130
  readonly partition: number;
70
131
 
@@ -82,32 +143,82 @@ export interface ProduceResult {
82
143
  }
83
144
 
84
145
  /**
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
- * }
146
+ * Contains information of the written Kafka message.
147
+ * https://mokapi.io/docs/javascript-api/mokapi-kafka/kafkamessageresult
94
148
  */
95
- export type KafkaEventHandler = (record: KafkaRecord) => boolean;
149
+ export interface MessageResult {
150
+ /**
151
+ * Kafka partition index in which the message was written.
152
+ */
153
+ readonly partition: number
154
+
155
+ /**
156
+ * Kafka offset of the written message.
157
+ */
158
+ readonly offset: number
159
+
160
+ /**
161
+ * Kafka written message key.
162
+ */
163
+ readonly key: string
164
+
165
+ /**
166
+ * Kafka written message value.
167
+ */
168
+ readonly value: string
169
+
170
+ /**
171
+ * Kafka written message headers.
172
+ */
173
+ readonly headers: { [name: string]: string }
174
+ }
96
175
 
97
176
  /**
98
- * KafkaRecord is an object used by KafkaEventHandler that contains Kafka-specific message data.
99
- * https://mokapi.io/docs/javascript-api/mokapi/eventhandler/KafkaRecord
177
+ * The retry option can be used to customize the configuration of the retry mechanism.
100
178
  */
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;
179
+ export interface ProduceRetry {
180
+ /**
181
+ * Maximum wait time for a retry
182
+ * MaxRetryTime number express the wait time in milliseconds.
183
+ * MaxRetryTime string is a possibly signed sequence of
184
+ * decimal numbers, each with optional fraction and a unit suffix,
185
+ * such as "300ms", "-1.5h" or "2h45m".
186
+ * Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
187
+ * @default 30000ms
188
+ * @example
189
+ * export default function() {
190
+ * produce({ topic: 'foo', messages: [{ value: 'value-1' }], retry: { maxRetryTime: '30s' } })
191
+ * }
192
+ */
193
+ maxRetryTime: string | number
194
+
195
+ /**
196
+ * Initial value used to calculate the wait time
197
+ * InitialRetryTime number express the wait time in milliseconds.
198
+ * InitialRetryTime string is a possibly signed sequence of
199
+ * decimal numbers, each with optional fraction and a unit suffix,
200
+ * such as "300ms", "-1.5h" or "2h45m".
201
+ * Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
202
+ * @default 200ms
203
+ * @example
204
+ * export default function() {
205
+ * produce({ topic: 'foo', messages: [{ value: 'value-1' }], retry: { initialRetryTime: '2s' } })
206
+ * }
207
+ */
208
+ initialRetryTime: string | number
209
+
210
+ /**
211
+ * Factor for increasing the wait time for next retry.
212
+ * 1st retry: 200ms
213
+ * 2nd retry: 4 * 200ms = 800ms
214
+ * 3th retry: 4 * 800ms = 3200ms
215
+ * @default 4
216
+ */
217
+ factor: number
218
+
219
+ /**
220
+ * Max number of retries
221
+ * @default 5
222
+ */
223
+ retries: number
113
224
  }
package/types/smtp.d.ts CHANGED
@@ -1,15 +1,11 @@
1
- declare module 'mokapi/mail' {
2
- /**
3
- * Sends an email message to an SMTP server for delivery.
4
- * @param server Host to which the message is to be sent.
5
- * @param message a Message that contains the message to send.
6
- */
7
- function send(server: string, message: Message)
8
- }
9
-
10
- type SmtpEventHandler = (record: Message) => boolean
1
+ /**
2
+ * Sends an email message to an SMTP server for delivery.
3
+ * @param server Host to which the message is to be sent.
4
+ * @param message a Message that contains the message to send.
5
+ */
6
+ export function send(server: string, message: Message)
11
7
 
12
- declare interface Message {
8
+ export interface Message {
13
9
  server: string
14
10
  sender?: Address
15
11
  from: Address[]
@@ -27,12 +23,12 @@ declare interface Message {
27
23
  attachments: Attachment[]
28
24
  }
29
25
 
30
- declare interface Address {
26
+ export interface Address {
31
27
  name?: string
32
28
  address: string
33
29
  }
34
30
 
35
- declare interface Attachment {
31
+ export interface Attachment {
36
32
  name: string
37
33
  contentType: string
38
34
  data: Uint8Array
package/types/ldap.d.ts DELETED
@@ -1,118 +0,0 @@
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;
37
-
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[];
49
- }
50
-
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;
63
- }
64
-
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[] };
74
- }
75
-
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
- */
84
- BaseObject,
85
-
86
- /**
87
- * Indicates that only the immediate children of the entry specified should be considered.
88
- */
89
- SingleLevel,
90
-
91
- /**
92
- * Indicates that the entry specified as the search base, and all of its subordinates to any depth.
93
- */
94
- WholeSubtree,
95
- }
96
-
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. */
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
- */
107
- OperationsError = 1,
108
-
109
- /** Indicates that there was a problem with the client’s use of the LDAP protocol. */
110
- ProtocolError = 2,
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
- }
package/types/mokapi.d.ts DELETED
@@ -1,137 +0,0 @@
1
- /// <reference path="ldap.d.ts" />
2
- /// <reference path="kafka.d.ts" />
3
- /// <reference path="smtp.d.ts" />
4
-
5
- declare module 'mokapi' {
6
- /**
7
- * Attaches an event handler for the given event.
8
- * @param event Event type such as http
9
- * @param handler An EventHandler to execute when the event is triggered
10
- * @param args EventArgs object contains additional event arguments.
11
- */
12
- function on<T extends keyof EventHandler>(event: T, handler: EventHandler[T], args?: EventArgs): void
13
-
14
- /** Schedules a new periodic job with interval.
15
- * Interval string is a possibly signed sequence of
16
- * decimal numbers, each with optional fraction and a unit suffix,
17
- * such as "300ms", "-1.5h" or "2h45m".
18
- * Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
19
- */
20
- function every(interval: string, f: ScheduledEventHandler, args?: ScheduledEventArgs): void
21
-
22
- /**
23
- * Schedules a new periodic job with a cron expression.
24
- * @param expr cron expression
25
- * @param f function to execute
26
- * @param args additional arguments
27
- */
28
- function cron(expr: string, f: ScheduledEventHandler, args?: ScheduledEventArgs): void
29
-
30
- /** Retrieves the value of the environment variable named by the key.
31
- It returns the value, which will be empty if the variable is not present.
32
- */
33
- function env(name: string): string
34
-
35
- /** Opens a file and reading all its content. */
36
- function open(path: string): string
37
-
38
- /** Returns a textual representation of the date. See the documentation to see
39
- * how to represent the layout format.
40
- * Default layout is RFC3339.
41
- * Default timestamp is current UTC */
42
- function date(args?: DateArgs): string
43
-
44
- /**
45
- * Suspends the execution for the specified duration.
46
- * Valid time units are `ns`, `us` (or `µs`), `ms`, `s`, `m`, `h`
47
- * @param time Duration in milliseconds or duration as string with unit.
48
- */
49
- function sleep(time: number | string )
50
- }
51
-
52
- type EventHandler = {
53
- http: HttpEventHandler
54
- ldap: LdapEventHandler
55
- kafka: KafkaEventHandler
56
- smtp: SmtpEventHandler
57
- }
58
-
59
- type HttpEventHandler = (request: HttpRequest, response: HttpResponse) => boolean
60
-
61
- declare interface HttpRequest {
62
- /** Request method. */
63
- method: string
64
- /** Request url. */
65
- url: Url
66
- /** Request body. */
67
- body: any
68
- /** Path parameters. */
69
- path: { [key: string]: any; }
70
- /** Query parameters. */
71
- query: { [key: string]: any; }
72
- /** Header parameters. */
73
- header: { [key: string]: any; }
74
- /** Cookie parameters. */
75
- cookie: { [key: string]: any; }
76
- /** Path defined in OpenAPI. */
77
- key: string
78
- /** OperationId defined in OpenAPI. */
79
- operationId: string
80
- }
81
-
82
- declare interface HttpResponse {
83
- /** Response headers. */
84
- headers: { [key: string]: string; }
85
- /** HTTP status code. */
86
- statusCode: number
87
- /** Response body. It has a higher precedence than data. */
88
- body: string
89
- /** Response data. It has a lower precedence than body. */
90
- data: any
91
- }
92
-
93
- declare interface Url {
94
- /** URL scheme. */
95
- scheme: string
96
- /** URL host. */
97
- host: string
98
- /** URL path. */
99
- path: string
100
- /** URL query string. */
101
- query: string
102
- }
103
-
104
- declare interface DateArgs {
105
- layout?: DateLayout
106
- timestamp?: number
107
- }
108
-
109
- declare type DateLayout = 'DateTime' | 'DateOnly' | 'TimeOnly' | 'UnixDate' | 'RFC882' | 'RFC822Z' | 'RFC850' | 'RFC1123' | 'RFC1123Z' | 'RFC3339' | 'RFC3339Nano'
110
-
111
- declare interface EventArgs {
112
- /**
113
- * Adds or overrides existing tags used in dashboard
114
- */
115
- tags: {[key: string]: string}
116
- }
117
-
118
- type ScheduledEventHandler = () => void
119
-
120
- declare interface ScheduledEventArgs {
121
- /**
122
- * Adds or overrides existing tags used in dashboard
123
- */
124
- tags?: {[key: string]: string}
125
-
126
- /**
127
- * Defines the number of times the scheduled function is executed.
128
- */
129
- times?: number
130
-
131
- /**
132
- * Toggles behavior of first execution. Default is true
133
- */
134
- runFirstTimeImmediately?: boolean
135
- }
136
-
137
- declare const RFC3339 = "RFC3339"