go-mokapi 0.10.2 → 0.11.0

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.10.2",
3
+ "version": "0.11.0",
4
4
  "description": "Easy and flexible API mocking",
5
5
  "homepage": "https://mokapi.io",
6
6
  "repository": {
@@ -0,0 +1,28 @@
1
+ export interface Base64Encoding {
2
+ /**
3
+ * Encodes a string value to its equivalent string representation that is encoded with base-64.
4
+ * https://mokapi.io/docs/javascript-api/mokapi-encoding/base64-encode
5
+ * @param input input - The input string to base64 encode.
6
+ * @returns The base64 encoding of the input string.
7
+ * @example
8
+ * export default function() {
9
+ * console.log(`The base64 encoding of 'hello world' is: ${base.encode('hello world')}`)
10
+ * }
11
+ */
12
+ encode(input: string | ArrayBuffer): string;
13
+
14
+ /**
15
+ * Decodes a string value that is encoded with base-64 to its equivalent unencoded string representation.
16
+ * @param input input - The base64 input string to decode.
17
+ * @returns The base64 decoded version of the input string.
18
+ * @example
19
+ * export default function() {
20
+ * console.log(`The base64 decoded string of 'aGVsbG8gd29ybGQ=' is: ${base.decode('aGVsbG8gd29ybGQ=')}`)
21
+ * }
22
+ */
23
+ decode(input: string): string;
24
+ }
25
+
26
+ export const base64: Base64Encoding;
27
+
28
+
package/types/faker.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { JSONValue } from ".";
2
-
3
1
  /**
4
2
  * Creates a fake based on the given schema
5
3
  * https://mokapi.io/docs/javascript-api/mokapi-faker/fake
@@ -12,7 +10,7 @@ import { JSONValue } from ".";
12
10
  * console.log(fake({type: 'string', pattern: '^\d{3}-\d{2}-\d{4}$'})) // 123-45-6789
13
11
  * }
14
12
  */
15
- export function fake(schema: Schema | JSONSchema): JSONValue;
13
+ export function fake(schema: Schema | JSONSchema): any;
16
14
 
17
15
  /**
18
16
  * Gets the tree node with the given name
@@ -24,12 +22,12 @@ export function fake(schema: Schema | JSONSchema): JSONValue;
24
22
  * console.log(fake({type: 'string'}))
25
23
  * }
26
24
  */
27
- export function findByName(name: string): Tree
25
+ export function findByName(name: string): Tree;
28
26
 
29
27
  /**
30
28
  * The name of the root faker tree
31
29
  */
32
- export const RootName = 'Faker'
30
+ export const RootName = "Faker";
33
31
 
34
32
  /**
35
33
  * The Tree object represents a node in the faker tree
@@ -38,32 +36,32 @@ export interface Tree {
38
36
  /**
39
37
  * Gets the name of the tree node
40
38
  */
41
- name: string
39
+ name: string;
42
40
 
43
41
  /**
44
42
  * Inserts a Tree objects after the last child of this tree.
45
43
  * @param node node - A Tree node to insert after the last child.
46
44
  */
47
- append: (node: Tree | CustomTree) => void
45
+ append: (node: Tree | CustomTree) => void;
48
46
 
49
47
  /**
50
48
  * Inserts a Tree objects at a specified index position
51
49
  * @param index index - The zero-based index position of the insertion.
52
50
  * @param node node - The tree node to insert
53
51
  */
54
- insert: (index: number, node: Tree | CustomTree) => void
52
+ insert: (index: number, node: Tree | CustomTree) => void;
55
53
 
56
54
  /**
57
55
  * Removes a Tree node at the specific index position
58
56
  * @param index index - The zero-based index position to remove.
59
57
  */
60
- removeAt: (index: number) => void
58
+ removeAt: (index: number) => void;
61
59
 
62
60
  /**
63
61
  * Removes a Tree node with the given name
64
62
  * @param name name - The name of a node to remove
65
63
  */
66
- remove: (name: string) => void
64
+ remove: (name: string) => void;
67
65
  }
68
66
 
69
67
  /**
@@ -73,7 +71,7 @@ export interface CustomTree {
73
71
  /**
74
72
  * Gets the name of the custom tree node
75
73
  */
76
- name: string
74
+ name: string;
77
75
 
78
76
  /**
79
77
  * Tests whether the tree node supports the request.
@@ -92,7 +90,7 @@ export interface CustomTree {
92
90
  * return fake({ type: 'string' })
93
91
  * }
94
92
  */
95
- test: (r: Request) => boolean
93
+ test: (r: Request) => boolean;
96
94
 
97
95
  /**
98
96
  * Gets a new fake value
@@ -111,20 +109,20 @@ export interface CustomTree {
111
109
  * return fake({ type: 'string' })
112
110
  * }
113
111
  */
114
- fake: (r: Request) => JSONValue
112
+ fake: (r: Request) => any;
115
113
  }
116
114
 
117
115
  export interface Request {
118
- path: PathElement[]
116
+ path: PathElement[];
119
117
 
120
- last: () => PathElement
121
- lastName: () => string
122
- lastSchema: () => JSONSchema
118
+ last: () => PathElement;
119
+ lastName: () => string;
120
+ lastSchema: () => JSONSchema;
123
121
  }
124
122
 
125
123
  export interface PathElement {
126
- name: string
127
- schema: JSONSchema
124
+ name: string;
125
+ schema: JSONSchema;
128
126
  }
129
127
 
130
128
  /**
@@ -139,116 +137,116 @@ export interface JSONSchema {
139
137
  /**
140
138
  * Specifies the data type for a schema.
141
139
  */
142
- type: SchemaType | SchemaType[];
140
+ type?: SchemaType | SchemaType[];
143
141
 
144
142
  /**
145
143
  * The enum keyword is used to restrict a value to a fixed set of values.
146
144
  */
147
- enum: unknown[]
145
+ enum?: any[];
148
146
 
149
147
  /**
150
148
  * The const keyword is used to restrict a value to a single value.
151
149
  */
152
- const: unknown
150
+ const?: any;
153
151
 
154
152
  /**
155
153
  * Contains a list of valid examples.
156
154
  */
157
- examples: unknown[]
155
+ examples?: any[];
158
156
 
159
157
  /**
160
158
  * Specifies a default value.
161
159
  */
162
- default: unknown
160
+ default?: any;
163
161
 
164
162
  // Numbers
165
163
  /**
166
164
  * Restricts the number to a multiple of the given number
167
165
  */
168
- multipleOf: number | undefined
166
+ multipleOf?: number;
169
167
 
170
168
  /**
171
169
  * Restricts the number to a maximum number
172
170
  */
173
- maximum: number | undefined
171
+ maximum?: number;
174
172
 
175
173
  /**
176
174
  * Restricts the number to a exclusive maximum number
177
175
  */
178
- exclusiveMaximum: number | undefined
176
+ exclusiveMaximum?: number;
179
177
 
180
178
  /**
181
179
  * Restricts the number to a minimum number
182
180
  */
183
- minimum: number | undefined
181
+ minimum?: number;
184
182
 
185
183
  /**
186
184
  * Restricts the number to a exclusive minimum number
187
185
  */
188
- exclusiveMinimum: number | undefined
186
+ exclusiveMinimum?: number;
189
187
 
190
188
  // Strings
191
189
  /**
192
190
  * Restricts the string to a maximum length
193
191
  */
194
- maxLength: number | undefined
192
+ maxLength?: number;
195
193
 
196
194
  /**
197
195
  * Restricts the string to a minimum length
198
196
  */
199
- minLength: number | undefined
197
+ minLength?: number;
200
198
 
201
199
  /**
202
200
  * The pattern keyword is used to restrict a string to a particular regular expression.
203
201
  */
204
- pattern: string
202
+ pattern?: string;
205
203
 
206
204
  /**
207
205
  * The format keyword allows for basic semantic identification of certain kinds of string values that are commonly used.
208
206
  */
209
- format: string
207
+ format?: string;
210
208
 
211
209
  // Arrays
212
210
  /**
213
211
  * Specifies the schema of the items in the array.
214
212
  */
215
- items: JSONSchema | undefined
213
+ items?: JSONSchema;
216
214
 
217
215
  /**
218
216
  * Restricts the array to have a maximum length
219
217
  */
220
- maxItems: number | undefined
218
+ maxItems?: number;
221
219
 
222
220
  /**
223
221
  * Restricts the array to have a minimum length
224
222
  */
225
- minItems: number | undefined
223
+ minItems?: number;
226
224
 
227
225
  /**
228
226
  * Restricts the array to have unique items
229
227
  */
230
- uniqueItems: boolean
228
+ uniqueItems?: boolean;
231
229
 
232
230
  // Objects
233
231
  /**
234
232
  * Specifies the properties of an object
235
233
  */
236
- properties: { [name: string]: JSONSchema }
234
+ properties?: { [name: string]: JSONSchema };
237
235
 
238
236
  /**
239
237
  * Restricts the object to have a maximum of properties
240
238
  */
241
- maxProperties: number | undefined
239
+ maxProperties?: number;
242
240
 
243
241
  /**
244
242
  * Restricts the object to have a minimum of properties
245
243
  */
246
- minProperties: number | undefined
244
+ minProperties?: number;
247
245
 
248
246
  /**
249
247
  * Specifies the required properties for an object
250
248
  */
251
- required: string[] | undefined
249
+ required?: string[];
252
250
 
253
251
  /**
254
252
  * The additionalProperties keyword is used to control the handling of extra stuff,
@@ -256,32 +254,22 @@ export interface JSONSchema {
256
254
  * any of the regular expressions in the patternProperties keyword. By default, any
257
255
  * additional properties are allowed.
258
256
  */
259
- additionalProperties: boolean | JSONSchema | undefined
257
+ additionalProperties?: boolean | JSONSchema;
260
258
 
261
259
  /**
262
260
  * A value must be valid against all the schemas
263
261
  */
264
- allOf: JSONSchema[] | undefined
262
+ allOf?: JSONSchema[];
265
263
 
266
264
  /**
267
265
  * A value must be valid against any the schemas
268
266
  */
269
- anyOf: JSONSchema[] | undefined
267
+ anyOf?: JSONSchema[];
270
268
 
271
269
  /**
272
270
  * A value must be valid against exactly one the schemas
273
271
  */
274
- oneOf: JSONSchema[] | undefined
275
-
276
- isAny: () => boolean
277
- isString: () => boolean
278
- isInteger: () => boolean
279
- isNumber: () => boolean
280
- isArray: () => boolean
281
- isObject: () => boolean
282
- isNullable: () => boolean
283
- isDictionary: () => boolean
284
- is: (typeName: string) => boolean
272
+ oneOf?: JSONSchema[];
285
273
  }
286
274
 
287
275
  export type SchemaType = "object" | "array" | "number" | "integer" | "string" | "boolean" | "null";
@@ -296,6 +284,16 @@ export interface Schema {
296
284
  /** Specifies regular expression that fake must match. */
297
285
  pattern?: string;
298
286
 
287
+ /**
288
+ * Restricts the string to a minimum length
289
+ */
290
+ minLength?: number;
291
+
292
+ /**
293
+ * Restricts the string to a maximum length
294
+ */
295
+ maxLength?: number;
296
+
299
297
  /** Describes the type and format of array items. */
300
298
  items?: Schema;
301
299
 
@@ -303,7 +301,7 @@ export interface Schema {
303
301
  required?: string[];
304
302
 
305
303
  /** Specify possible value for this schema. */
306
- enum?: JSONValue[];
304
+ enum?: any[];
307
305
 
308
306
  /** Specifies the minimum range of possible values. */
309
307
  minimum?: number;
@@ -317,6 +315,19 @@ export interface Schema {
317
315
  /** ** Specifies whether maximum value is exluded. Default is false. */
318
316
  exclusiveMaximum?: number | boolean;
319
317
 
318
+ /**
319
+ * Specifies the properties of an object
320
+ */
321
+ properties?: { [name: string]: Schema };
322
+
323
+ /**
324
+ * The additionalProperties keyword is used to control the handling of extra stuff,
325
+ * that is, properties whose names are not listed in the properties keyword or match
326
+ * any of the regular expressions in the patternProperties keyword. By default, any
327
+ * additional properties are allowed.
328
+ */
329
+ additionalProperties?: boolean | Schema | undefined;
330
+
320
331
  /** Valid against one of the specified schemas. */
321
332
  anyOf?: Schema[];
322
333
 
@@ -337,4 +348,4 @@ export interface Schema {
337
348
 
338
349
  /** Specifies whether all items in an array must be unique. */
339
350
  uniqueItems?: boolean;
340
- }
351
+ }
package/types/global.d.ts CHANGED
@@ -20,9 +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.
24
- * @default binary
23
+ * By default contents of the file are read as string, but with binary the file will be read as binary.
25
24
  */
26
25
  as: "binary" | "string";
27
26
  }
28
- }
27
+ }
package/types/http.d.ts CHANGED
@@ -117,4 +117,4 @@ export interface Response {
117
117
  * res.json()
118
118
  */
119
119
  json(): JSONValue;
120
- }
120
+ }
package/types/index.d.ts CHANGED
@@ -8,6 +8,7 @@ import "./global";
8
8
  import "./http";
9
9
  import "./mustache";
10
10
  import "./yaml";
11
+ import "./encoding"
11
12
 
12
13
  /**
13
14
  * Attaches an event handler for the given event.
@@ -171,7 +172,7 @@ export interface HttpResponse {
171
172
  body: string;
172
173
 
173
174
  /** Data will be encoded with the OpenAPI response definition. */
174
- data: JSONValue;
175
+ data: any;
175
176
  }
176
177
 
177
178
  /**
@@ -341,35 +342,35 @@ export enum LdapResultStatus {
341
342
  SizeLimitExceeded = 4,
342
343
  }
343
344
 
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[]
345
+ export type SmtpEventHandler = (record: SmtpEventMessage) => boolean;
346
+
347
+ export interface SmtpEventMessage {
348
+ server: string;
349
+ sender?: Address;
350
+ from: Address[];
351
+ to: Address[];
352
+ replyTo?: Address[];
353
+ cc?: Address[];
354
+ bcc?: Address[];
355
+ messageId: string;
356
+ inReplyTo?: string;
357
+ time?: Date;
358
+ subject: string;
359
+ contentType: string;
360
+ encoding: string;
361
+ body: string;
362
+ attachments: Attachment[];
362
363
  }
363
364
 
364
- declare interface Address {
365
- name?: string
366
- address: string
365
+ export interface Address {
366
+ name?: string;
367
+ address: string;
367
368
  }
368
369
 
369
- declare interface Attachment {
370
- name: string
371
- contentType: string
372
- data: Uint8Array
370
+ export interface Attachment {
371
+ name: string;
372
+ contentType: string;
373
+ data: Uint8Array;
373
374
  }
374
375
 
375
376
  /**
@@ -454,4 +455,4 @@ export interface JSONObject {
454
455
  [key: string]: JSONValue;
455
456
  }
456
457
 
457
- declare const RFC3339 = "RFC3339"
458
+ export const RFC3339 = "RFC3339";
package/types/kafka.d.ts CHANGED
@@ -19,7 +19,28 @@ import { JSONValue } from ".";
19
19
  * console.log(`new kafka message written with offset: ${res.offset}`)
20
20
  * }
21
21
  */
22
- export function produce(args: ProduceArgs): ProduceResult;
22
+ export function produce(args?: ProduceArgs): ProduceResult;
23
+
24
+ /**
25
+ * Sends a single message to a Kafka topic asynchronously.
26
+ * https://mokapi.io/docs/javascript-api/mokapi-kafka/produce
27
+ * @param args - ProduceArgs object contains Kafka produce arguments.
28
+ * @returns The produce result.
29
+ * @example
30
+ * export default function() {
31
+ * const res = produce({
32
+ * topic: 'foo',
33
+ * messages: [
34
+ * {
35
+ * key: 'foo-1',
36
+ * data: { foo: 'bar' }
37
+ * }
38
+ * ]
39
+ * });
40
+ * console.log(`new kafka message written with offset: ${res.offset}`)
41
+ * }
42
+ */
43
+ export function produceAsync(args?: ProduceArgs): Promise<ProduceResult>;
23
44
 
24
45
  /**
25
46
  * Contains produce-specific arguments.
@@ -62,7 +83,7 @@ export interface ProduceArgs {
62
83
 
63
84
  /**
64
85
  * An array of Kafka messages
65
- * @see KafkaMessage
86
+ * @see Message
66
87
  * @example
67
88
  * export default function() {
68
89
  * const res = produce({
@@ -80,12 +101,12 @@ export interface ProduceArgs {
80
101
  * });
81
102
  * }
82
103
  */
83
- messages?: Message[]
104
+ messages?: Message[];
84
105
 
85
106
  /**
86
107
  * The retry option is used if script is executed before Kafka topic is set up.
87
108
  */
88
- retry?: ProduceRetry
109
+ retry?: ProduceRetry;
89
110
  }
90
111
 
91
112
  /**
@@ -102,7 +123,7 @@ export interface Message {
102
123
  data?: JSONValue;
103
124
 
104
125
  /** 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
126
+ value?: string | number | boolean | null;
106
127
 
107
128
  /** Kafka message headers. */
108
129
  headers?: { [name: string]: JSONValue };
@@ -124,7 +145,8 @@ export interface ProduceResult {
124
145
  /** Kafka topic name where the message was written. */
125
146
  readonly topic: string;
126
147
 
127
- messages: MessageResult[]
148
+ // ** List of produced Kafka messages */
149
+ messages: MessageResult[];
128
150
 
129
151
  /** Kafka partition where the message was written. */
130
152
  readonly partition: number;
@@ -150,27 +172,27 @@ export interface MessageResult {
150
172
  /**
151
173
  * Kafka partition index in which the message was written.
152
174
  */
153
- readonly partition: number
175
+ readonly partition: number;
154
176
 
155
177
  /**
156
178
  * Kafka offset of the written message.
157
179
  */
158
- readonly offset: number
180
+ readonly offset: number;
159
181
 
160
182
  /**
161
183
  * Kafka written message key.
162
184
  */
163
- readonly key: string
185
+ readonly key: string;
164
186
 
165
187
  /**
166
188
  * Kafka written message value.
167
189
  */
168
- readonly value: string
190
+ readonly value: string;
169
191
 
170
192
  /**
171
193
  * Kafka written message headers.
172
194
  */
173
- readonly headers: { [name: string]: string }
195
+ readonly headers: { [name: string]: string };
174
196
  }
175
197
 
176
198
  /**
@@ -190,7 +212,7 @@ export interface ProduceRetry {
190
212
  * produce({ topic: 'foo', messages: [{ value: 'value-1' }], retry: { maxRetryTime: '30s' } })
191
213
  * }
192
214
  */
193
- maxRetryTime: string | number
215
+ maxRetryTime: string | number;
194
216
 
195
217
  /**
196
218
  * Initial value used to calculate the wait time
@@ -205,7 +227,7 @@ export interface ProduceRetry {
205
227
  * produce({ topic: 'foo', messages: [{ value: 'value-1' }], retry: { initialRetryTime: '2s' } })
206
228
  * }
207
229
  */
208
- initialRetryTime: string | number
230
+ initialRetryTime: string | number;
209
231
 
210
232
  /**
211
233
  * Factor for increasing the wait time for next retry.
@@ -214,11 +236,11 @@ export interface ProduceRetry {
214
236
  * 3th retry: 4 * 800ms = 3200ms
215
237
  * @default 4
216
238
  */
217
- factor: number
239
+ factor: number;
218
240
 
219
241
  /**
220
242
  * Max number of retries
221
243
  * @default 5
222
244
  */
223
- retries: number
224
- }
245
+ retries: number;
246
+ }
@@ -31,4 +31,4 @@ export interface ScopeObject {
31
31
  [key: string]: Scope | ScopeFunction;
32
32
  }
33
33
 
34
- export type ScopeFunction = () => Scope;
34
+ export type ScopeFunction = () => Scope;
package/types/yaml.d.ts CHANGED
@@ -11,7 +11,7 @@ import { JSONValue } from ".";
11
11
  * console.log(outout[0].orderId)
12
12
  * }
13
13
  */
14
- export function parse(text: string): JSONValue;
14
+ export function parse(text: string): any;
15
15
 
16
16
  /**
17
17
  * Converts a JavaScript value to a YAML string.
@@ -35,4 +35,4 @@ export function parse(text: string): JSONValue;
35
35
  * })
36
36
  * }
37
37
  */
38
- export function stringify(value: JSONValue): string;
38
+ export function stringify(value: JSONValue): string;
@@ -1,10 +0,0 @@
1
- export {}
2
-
3
- declare global {
4
- /**
5
- * Opens a file
6
- * @param filePath - Path to the file.
7
- * @returns File content
8
- */
9
- function open(filePath: string): string
10
- }