go-mokapi 0.25.4 → 0.27.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.25.4",
3
+ "version": "0.27.0",
4
4
  "description": "Easy and flexible API mocking",
5
5
  "homepage": "https://mokapi.io",
6
6
  "repository": {
package/types/http.d.ts CHANGED
@@ -86,13 +86,25 @@ export function del(url: string, body?: JSONValue, args?: Args): Response;
86
86
  */
87
87
  export function options(url: string, body?: JSONValue, args?: Args): Response;
88
88
 
89
+ export function fetch(url: string, args: FetchOptions): Promise<Response>
90
+
91
+ export interface FetchOptions {
92
+ method: string
93
+ body: any
94
+ }
95
+
89
96
  /**
90
97
  * Request arguments.
91
98
  * Used to add headers to a request.
92
99
  */
93
100
  export interface Args {
94
101
  /** Request headers. */
95
- header?: { [name: string]: string };
102
+ headers?: { [name: string]: string };
103
+ /**
104
+ * The number of redirects to follow for this request.
105
+ * @default 5
106
+ **/
107
+ maxRedirects: number
96
108
  }
97
109
 
98
110
  /**
package/types/index.d.ts CHANGED
@@ -130,7 +130,10 @@ export type HttpEventHandler = (request: HttpRequest, response: HttpResponse) =>
130
130
  * https://mokapi.io/docs/javascript-api/mokapi/eventhandler/httprequest
131
131
  */
132
132
  export interface HttpRequest {
133
- /** Request method. */
133
+ /**
134
+ * Request method.
135
+ * @example GET
136
+ * */
134
137
  readonly method: string;
135
138
 
136
139
  /** Represents a parsed URL. */
@@ -151,6 +154,9 @@ export interface HttpRequest {
151
154
  /** Object contains cookie parameters specified by OpenAPI cookie parameters. */
152
155
  readonly cookie: { [key: string]: any };
153
156
 
157
+ /** Object contains querystring parameters specified by OpenAPI querystring parameters. */
158
+ readonly querystring: any;
159
+
154
160
  /** Path value specified by the OpenAPI path */
155
161
  readonly key: string;
156
162
 
@@ -535,4 +541,100 @@ export function patch(target: any, patch: any): any;
535
541
  * const result = patch({ name: "foo", age: 42 }, { age: Delete })
536
542
  * // result: { name: "foo" }
537
543
  */
538
- export const Delete: unique symbol;
544
+ export const Delete: unique symbol;
545
+
546
+ export interface SharedMemory {
547
+ /**
548
+ * Returns the value associated with the given key.
549
+ * @param key The key to retrieve.
550
+ * @returns The stored value, or `undefined` if not found.
551
+ */
552
+ get<T = any>(key: string): T | undefined
553
+
554
+ /**
555
+ * Sets a value for the given key.
556
+ * If the key already exists, its value will be replaced.
557
+ * @param key The key to store the value under.
558
+ * @param value The value to store.
559
+ */
560
+ set<T = any>(key: string, value: T): void
561
+
562
+ /**
563
+ * Updates a value atomically using an updater function.
564
+ * The current value is passed into the updater function.
565
+ * The returned value is stored and also returned by this method.
566
+ *
567
+ * Example:
568
+ * ```js
569
+ * mokapi.shared.update("requests", count => (count ?? 0) + 1)
570
+ * ```
571
+ *
572
+ * @param key The key to update.
573
+ * @param updater Function that receives the current value and returns the new value.
574
+ * @returns The new value after update.
575
+ */
576
+ update<T = any>(key: string, updater: (value: T | undefined) => T): T
577
+
578
+ /**
579
+ * Checks if the given key exists in shared memory.
580
+ * @param key The key to check.
581
+ * @returns `true` if the key exists, otherwise `false`.
582
+ */
583
+ has(key: string): boolean
584
+
585
+ /**
586
+ * Removes the specified key and its value from shared memory.
587
+ * @param key The key to remove.
588
+ */
589
+ delete(key: string): void
590
+
591
+ /**
592
+ * Removes all stored entries from shared memory.
593
+ * Use with caution — this clears all shared state.
594
+ */
595
+ clear(): void
596
+
597
+ /**
598
+ * Returns a list of all stored keys.
599
+ * @returns An array of key names.
600
+ */
601
+ keys(): string[]
602
+
603
+ /**
604
+ * Creates or returns a namespaced shared memory store.
605
+ * Namespaces help avoid key collisions between unrelated scripts.
606
+ *
607
+ * Example:
608
+ * ```js
609
+ * const petstore = mokapi.shared.namespace("petstore")
610
+ * petstore.set("sessions", [])
611
+ * ```
612
+ *
613
+ * @param name The namespace identifier.
614
+ * @returns A `SharedMemory` object scoped to the given namespace.
615
+ */
616
+ namespace(name: string): SharedMemory
617
+ }
618
+
619
+ /**
620
+ * Shared memory API for Mokapi scripts.
621
+ *
622
+ * The `mokapi.shared` object provides a way to persist and share
623
+ * data between multiple scripts running in the same Mokapi instance.
624
+ *
625
+ * Values are stored in memory and shared across all scripts.
626
+ * This allows you to coordinate state, cache data, or simulate
627
+ * application-level variables without using global variables.
628
+ * All values are persisted for the lifetime of the Mokapi process.
629
+ *
630
+ * Example:
631
+ * ```js
632
+ * // Increment a shared counter
633
+ * mokapi.shared.update("counter", c => (c ?? 0) + 1)
634
+ *
635
+ * // Retrieve the current counter value
636
+ * const count = mokapi.shared.get("counter")
637
+ * mokapi.log(`Current counter: ${count}`)
638
+ * ```
639
+ */
640
+ export const shared: SharedMemory