@omniaura/scenario-sim 0.1.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.
package/dist/vite.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { Plugin } from 'vite';
2
+ import { a as SimulatorOptions, b as ScenarioDefinition } from './engine-2w32ngB2.js';
3
+
4
+ /**
5
+ * @omniaura/scenario-sim/vite — serve a Simulator from the Vite dev server so
6
+ * the app and its mock share one origin (no CORS, one port, WebSocket
7
+ * upgrades included).
8
+ *
9
+ * import scenarioSim from "@omniaura/scenario-sim/vite";
10
+ * plugins: [scenarioSim({ scenarios: () => import("./scenarios"), match: (p) => p.startsWith("/api/") })]
11
+ */
12
+
13
+ interface ScenarioSimVitePluginOptions extends Omit<SimulatorOptions, "scenarios"> {
14
+ /** Scenario definitions, or a loader (lets you import scenario files lazily). */
15
+ scenarios: ScenarioDefinition[] | (() => Promise<ScenarioDefinition[] | {
16
+ default: ScenarioDefinition[];
17
+ } | {
18
+ scenarios: ScenarioDefinition[];
19
+ }>);
20
+ /** Which paths the simulator owns (default: `/api/` prefix and the control path). */
21
+ match?: (pathname: string) => boolean;
22
+ /** Only in `--mode simulator` / when VITE_SIMULATOR=true (default true). */
23
+ onlyInSimulatorMode?: boolean;
24
+ }
25
+ declare function scenarioSim(options: ScenarioSimVitePluginOptions): Plugin;
26
+
27
+ export { type ScenarioSimVitePluginOptions, scenarioSim as default };
package/dist/vite.js ADDED
@@ -0,0 +1,48 @@
1
+ import {
2
+ attachWebSockets,
3
+ sendWebResponse,
4
+ toWebRequest
5
+ } from "./chunk-7HBAY3QY.js";
6
+ import {
7
+ Simulator
8
+ } from "./chunk-KU4W4SKO.js";
9
+
10
+ // src/vite.ts
11
+ function scenarioSim(options) {
12
+ let sim = null;
13
+ const controlPath = (options.controlPath ?? "/__sim").replace(/\/$/, "");
14
+ const match = options.match ?? ((p) => p.startsWith("/api/"));
15
+ const owns = (p) => match(p) || p === controlPath || p.startsWith(`${controlPath}/`);
16
+ let enabled = true;
17
+ return {
18
+ name: "scenario-sim",
19
+ apply: "serve",
20
+ configResolved(config) {
21
+ const only = options.onlyInSimulatorMode ?? true;
22
+ enabled = !only || config.mode === "simulator" || process.env.VITE_SIMULATOR === "true";
23
+ },
24
+ async configureServer(server) {
25
+ if (!enabled) return;
26
+ const loaded = typeof options.scenarios === "function" ? await options.scenarios() : options.scenarios;
27
+ const scenarios = Array.isArray(loaded) ? loaded : "default" in loaded ? loaded.default : loaded.scenarios;
28
+ sim = new Simulator({ ...options, scenarios, log: options.log ?? ((l) => server.config.logger.info(` ${l}`)) });
29
+ const base = () => {
30
+ const addr = server.httpServer?.address();
31
+ const port = typeof addr === "object" && addr ? addr.port : server.config.server.port ?? 5173;
32
+ return `http://localhost:${port}`;
33
+ };
34
+ if (server.httpServer) attachWebSockets(sim, server.httpServer, { base, match: owns });
35
+ server.middlewares.use((req, res, next) => {
36
+ const pathname = new URL(req.url ?? "/", base()).pathname;
37
+ if (!sim || !owns(pathname)) return next();
38
+ void sim.handle(toWebRequest(req, base())).then((response) => sendWebResponse(res, response));
39
+ });
40
+ server.httpServer?.once("listening", () => server.config.logger.info(` \u25A3 scenario-sim: ${base()}${controlPath}/status (scenarios: ${scenarios.map((s) => s.name).join(", ")})`));
41
+ server.httpServer?.once("close", () => sim?.dispose());
42
+ }
43
+ };
44
+ }
45
+ export {
46
+ scenarioSim as default
47
+ };
48
+ //# sourceMappingURL=vite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/vite.ts"],"sourcesContent":["/**\n * @omniaura/scenario-sim/vite — serve a Simulator from the Vite dev server so\n * the app and its mock share one origin (no CORS, one port, WebSocket\n * upgrades included).\n *\n * import scenarioSim from \"@omniaura/scenario-sim/vite\";\n * plugins: [scenarioSim({ scenarios: () => import(\"./scenarios\"), match: (p) => p.startsWith(\"/api/\") })]\n */\n\nimport type { Plugin, ViteDevServer } from \"vite\";\nimport type { Server as HttpServer } from \"node:http\";\nimport { Simulator, type SimulatorOptions } from \"./core/engine.js\";\nimport type { ScenarioDefinition } from \"./core/scenario.js\";\nimport { attachWebSockets, sendWebResponse, toWebRequest } from \"./server.js\";\n\nexport interface ScenarioSimVitePluginOptions extends Omit<SimulatorOptions, \"scenarios\"> {\n /** Scenario definitions, or a loader (lets you import scenario files lazily). */\n scenarios: ScenarioDefinition[] | (() => Promise<ScenarioDefinition[] | { default: ScenarioDefinition[] } | { scenarios: ScenarioDefinition[] }>);\n /** Which paths the simulator owns (default: `/api/` prefix and the control path). */\n match?: (pathname: string) => boolean;\n /** Only in `--mode simulator` / when VITE_SIMULATOR=true (default true). */\n onlyInSimulatorMode?: boolean;\n}\n\nexport default function scenarioSim(options: ScenarioSimVitePluginOptions): Plugin {\n let sim: Simulator | null = null;\n const controlPath = (options.controlPath ?? \"/__sim\").replace(/\\/$/, \"\");\n const match = options.match ?? ((p: string) => p.startsWith(\"/api/\"));\n const owns = (p: string) => match(p) || p === controlPath || p.startsWith(`${controlPath}/`);\n let enabled = true;\n\n return {\n name: \"scenario-sim\",\n apply: \"serve\",\n configResolved(config) {\n const only = options.onlyInSimulatorMode ?? true;\n enabled = !only || config.mode === \"simulator\" || process.env.VITE_SIMULATOR === \"true\";\n },\n async configureServer(server: ViteDevServer) {\n if (!enabled) return;\n const loaded = typeof options.scenarios === \"function\" ? await options.scenarios() : options.scenarios;\n const scenarios = Array.isArray(loaded) ? loaded : \"default\" in loaded ? loaded.default : loaded.scenarios;\n sim = new Simulator({ ...options, scenarios, log: options.log ?? ((l) => server.config.logger.info(` ${l}`)) });\n const base = () => {\n const addr = server.httpServer?.address();\n const port = typeof addr === \"object\" && addr ? addr.port : (server.config.server.port ?? 5173);\n return `http://localhost:${port}`;\n };\n if (server.httpServer) attachWebSockets(sim, server.httpServer as HttpServer, { base, match: owns });\n server.middlewares.use((req, res, next) => {\n const pathname = new URL(req.url ?? \"/\", base()).pathname;\n if (!sim || !owns(pathname)) return next();\n void sim.handle(toWebRequest(req, base())).then((response) => sendWebResponse(res, response));\n });\n server.httpServer?.once(\"listening\", () => server.config.logger.info(` ▣ scenario-sim: ${base()}${controlPath}/status (scenarios: ${scenarios.map((s) => s.name).join(\", \")})`));\n server.httpServer?.once(\"close\", () => sim?.dispose());\n },\n };\n}\n"],"mappings":";;;;;;;;;;AAwBe,SAAR,YAA6B,SAA+C;AACjF,MAAI,MAAwB;AAC5B,QAAM,eAAe,QAAQ,eAAe,UAAU,QAAQ,OAAO,EAAE;AACvE,QAAM,QAAQ,QAAQ,UAAU,CAAC,MAAc,EAAE,WAAW,OAAO;AACnE,QAAM,OAAO,CAAC,MAAc,MAAM,CAAC,KAAK,MAAM,eAAe,EAAE,WAAW,GAAG,WAAW,GAAG;AAC3F,MAAI,UAAU;AAEd,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,eAAe,QAAQ;AACrB,YAAM,OAAO,QAAQ,uBAAuB;AAC5C,gBAAU,CAAC,QAAQ,OAAO,SAAS,eAAe,QAAQ,IAAI,mBAAmB;AAAA,IACnF;AAAA,IACA,MAAM,gBAAgB,QAAuB;AAC3C,UAAI,CAAC,QAAS;AACd,YAAM,SAAS,OAAO,QAAQ,cAAc,aAAa,MAAM,QAAQ,UAAU,IAAI,QAAQ;AAC7F,YAAM,YAAY,MAAM,QAAQ,MAAM,IAAI,SAAS,aAAa,SAAS,OAAO,UAAU,OAAO;AACjG,YAAM,IAAI,UAAU,EAAE,GAAG,SAAS,WAAW,KAAK,QAAQ,QAAQ,CAAC,MAAM,OAAO,OAAO,OAAO,KAAK,KAAK,CAAC,EAAE,GAAG,CAAC;AAC/G,YAAM,OAAO,MAAM;AACjB,cAAM,OAAO,OAAO,YAAY,QAAQ;AACxC,cAAM,OAAO,OAAO,SAAS,YAAY,OAAO,KAAK,OAAQ,OAAO,OAAO,OAAO,QAAQ;AAC1F,eAAO,oBAAoB,IAAI;AAAA,MACjC;AACA,UAAI,OAAO,WAAY,kBAAiB,KAAK,OAAO,YAA0B,EAAE,MAAM,OAAO,KAAK,CAAC;AACnG,aAAO,YAAY,IAAI,CAAC,KAAK,KAAK,SAAS;AACzC,cAAM,WAAW,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,CAAC,EAAE;AACjD,YAAI,CAAC,OAAO,CAAC,KAAK,QAAQ,EAAG,QAAO,KAAK;AACzC,aAAK,IAAI,OAAO,aAAa,KAAK,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,aAAa,gBAAgB,KAAK,QAAQ,CAAC;AAAA,MAC9F,CAAC;AACD,aAAO,YAAY,KAAK,aAAa,MAAM,OAAO,OAAO,OAAO,KAAK,0BAAqB,KAAK,CAAC,GAAG,WAAW,wBAAwB,UAAU,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC;AACjL,aAAO,YAAY,KAAK,SAAS,MAAM,KAAK,QAAQ,CAAC;AAAA,IACvD;AAAA,EACF;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@omniaura/scenario-sim",
3
+ "version": "0.1.0",
4
+ "description": "Deterministic scenario simulator for frontend QA: stateful CRUD routes, seeded RNG, virtual clock, response sequences, faults and overrides, SSE and WebSocket routes with scheduled events and resume, per-run isolation, inspectable event log. Runtime-neutral core (Web Request/Response) with Bun/Node server, Vite middleware and in-browser adapters.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "bin": {
10
+ "scenario-sim": "dist/cli.js"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ },
17
+ "./server": {
18
+ "types": "./dist/server.d.ts",
19
+ "import": "./dist/server.js"
20
+ },
21
+ "./vite": {
22
+ "types": "./dist/vite.d.ts",
23
+ "import": "./dist/vite.js"
24
+ },
25
+ "./browser": {
26
+ "types": "./dist/browser.d.ts",
27
+ "import": "./dist/browser.js"
28
+ },
29
+ "./pulse": {
30
+ "types": "./dist/pulse.d.ts",
31
+ "import": "./dist/pulse.js"
32
+ },
33
+ "./examples": {
34
+ "types": "./dist/examples.d.ts",
35
+ "import": "./dist/examples.js"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "README.md",
41
+ "LICENSE"
42
+ ],
43
+ "scripts": {
44
+ "build": "tsup",
45
+ "test": "bun test",
46
+ "typecheck": "tsc --noEmit",
47
+ "prepublishOnly": "bun run build"
48
+ },
49
+ "keywords": [
50
+ "mock",
51
+ "simulator",
52
+ "scenario",
53
+ "msw",
54
+ "sse",
55
+ "websocket",
56
+ "deterministic",
57
+ "seeded",
58
+ "qa",
59
+ "vite-plugin",
60
+ "solid",
61
+ "tanstack-query"
62
+ ],
63
+ "license": "MIT",
64
+ "author": "omniaura",
65
+ "repository": {
66
+ "type": "git",
67
+ "url": "git+https://github.com/omniaura/solid-pulse.git",
68
+ "directory": "packages/scenario-sim"
69
+ },
70
+ "homepage": "https://github.com/omniaura/solid-pulse/tree/main/packages/scenario-sim#readme",
71
+ "bugs": {
72
+ "url": "https://github.com/omniaura/solid-pulse/issues"
73
+ },
74
+ "publishConfig": {
75
+ "access": "public"
76
+ },
77
+ "peerDependencies": {
78
+ "vite": ">=5.0.0"
79
+ },
80
+ "peerDependenciesMeta": {
81
+ "vite": {
82
+ "optional": true
83
+ }
84
+ },
85
+ "dependencies": {
86
+ "ws": "^8.18.0"
87
+ },
88
+ "devDependencies": {
89
+ "@types/ws": "^8.5.12"
90
+ }
91
+ }