@@ -130,7 +130,10 @@ export type HttpEventHandler = (request: HttpRequest, response: HttpResponse) =>
130130 * https://mokapi.io/docs/javascript-api/mokapi/eventhandler/httprequest
131131 */
132132export interface HttpRequest {
133- /** Request method. */
133+ /**
134+ * Request method.
135+ * @example GET
136+ * */
134137 readonly method : string ;
135138
136139 /** Represents a parsed URL. */
@@ -151,6 +154,9 @@ export interface HttpRequest {
151154 /** Object contains cookie parameters specified by OpenAPI cookie parameters. */
152155 readonly cookie : { [ key : string ] : any } ;
153156
157+ /** Object contains querystring parameters specified by OpenAPI querystring parameters. */
158+ readonly querystring : any ;
159+
154160 /** Path value specified by the OpenAPI path */
155161 readonly key : string ;
156162
@@ -406,13 +412,33 @@ export type DateLayout =
406412 | "RFC3339Nano" ;
407413
408414/**
409- * Additional event arguments
415+ * EventArgs object contains additional arguments for an event handler.
416+ * https://mokapi.io/docs/javascript-api/mokapi/on
417+ *
418+ * Use this to customize how the event appears in the dashboard or to control tracking.
419+ *
420+ * @example
421+ * export default function() {
422+ * on('http', function(req, res) {
423+ * res.data = { message: "tracked event" }
424+ * }, {
425+ * tags: { feature: 'beta', owner: 'team-a' },
426+ * track: true
427+ * })
428+ * }
410429 */
411430export interface EventArgs {
412431 /**
413- * Adds or overrides existing tags used in dashboard
432+ * Optional key-value pairs used to label the event in the dashboard.
414433 */
415434 tags ?: { [ key : string ] : string } ;
435+
436+ /**
437+ * Set to `true` to enable tracking of this event handler in the dashboard.
438+ * If omitted, Mokapi automatically checks whether the response object has
439+ * been modified and tracks the handler only if a change is detected.
440+ */
441+ track ?: boolean ;
416442}
417443
418444/**
@@ -510,3 +536,99 @@ export function patch(target: any, patch: any): any;
510536 * // result: { name: "foo" }
511537 */
512538export const Delete : unique symbol ;
539+
540+ export interface SharedMemory {
541+ /**
542+ * Returns the value associated with the given key.
543+ * @param key The key to retrieve.
544+ * @returns The stored value, or `undefined` if not found.
545+ */
546+ get ( key : string ) : any
547+
548+ /**
549+ * Sets a value for the given key.
550+ * If the key already exists, its value will be replaced.
551+ * @param key The key to store the value under.
552+ * @param value The value to store.
553+ */
554+ set ( key : string , value : any ) : void
555+
556+ /**
557+ * Updates a value atomically using an updater function.
558+ * The current value is passed into the updater function.
559+ * The returned value is stored and also returned by this method.
560+ *
561+ * Example:
562+ * ```js
563+ * mokapi.shared.update("requests", count => (count ?? 0) + 1)
564+ * ```
565+ *
566+ * @param key The key to update.
567+ * @param updater Function that receives the current value and returns the new value.
568+ * @returns The new value after update.
569+ */
570+ update < T = any > ( key : string , updater : ( value : T | undefined ) => T ) : T
571+
572+ /**
573+ * Checks if the given key exists in shared memory.
574+ * @param key The key to check.
575+ * @returns `true` if the key exists, otherwise `false`.
576+ */
577+ has ( key : string ) : boolean
578+
579+ /**
580+ * Removes the specified key and its value from shared memory.
581+ * @param key The key to remove.
582+ */
583+ delete ( key : string ) : void
584+
585+ /**
586+ * Removes all stored entries from shared memory.
587+ * Use with caution — this clears all shared state.
588+ */
589+ clear ( ) : void
590+
591+ /**
592+ * Returns a list of all stored keys.
593+ * @returns An array of key names.
594+ */
595+ keys ( ) : string [ ]
596+
597+ /**
598+ * Creates or returns a namespaced shared memory store.
599+ * Namespaces help avoid key collisions between unrelated scripts.
600+ *
601+ * Example:
602+ * ```js
603+ * const petstore = mokapi.shared.namespace("petstore")
604+ * petstore.set("sessions", [])
605+ * ```
606+ *
607+ * @param name The namespace identifier.
608+ * @returns A `SharedMemory` object scoped to the given namespace.
609+ */
610+ namespace ( name : string ) : SharedMemory
611+ }
612+
613+ /**
614+ * Shared memory API for Mokapi scripts.
615+ *
616+ * The `mokapi.shared` object provides a way to persist and share
617+ * data between multiple scripts running in the same Mokapi instance.
618+ *
619+ * Values are stored in memory and shared across all scripts.
620+ * This allows you to coordinate state, cache data, or simulate
621+ * application-level variables without using global variables.
622+ * All values are persisted for the lifetime of the Mokapi process.
623+ *
624+ * Example:
625+ * ```js
626+ * // Increment a shared counter
627+ * mokapi.shared.update("counter", c => (c ?? 0) + 1)
628+ *
629+ * // Retrieve the current counter value
630+ * const count = mokapi.shared.get("counter")
631+ * mokapi.log(`Current counter: ${count}`)
632+ * ```
633+ */
634+ export const shared : SharedMemory
0 commit comments