@squide/msw 3.2.1 → 3.2.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @squide/msw
2
2
 
3
+ ## 3.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#231](https://github.com/gsoft-inc/wl-squide/pull/231) [`3c6bce0`](https://github.com/gsoft-inc/wl-squide/commit/3c6bce0cd559d0b8517d644661b6fb2b818ab2f6) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Packages now includes source code and sourcemap.
8
+
9
+ - Updated dependencies [[`3c6bce0`](https://github.com/gsoft-inc/wl-squide/commit/3c6bce0cd559d0b8517d644661b6fb2b818ab2f6)]:
10
+ - @squide/core@5.4.2
11
+
3
12
  ## 3.2.1
4
13
 
5
14
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- export { MswPlugin, MswPluginName, getMswPlugin } from './mswPlugin.js';
2
- export { MswState, MswStateChangedListener, __clearMswState, __setMswState, addMswStateChangedListener, isMswReady, removeMswStateChangedListener, setMswAsReady } from './mswState.js';
3
- export { RequestHandlerRegistry } from './requestHandlerRegistry.js';
4
- import '@squide/core';
5
- import 'msw';
1
+ export * from "./mswPlugin.ts";
2
+ export * from "./mswState.ts";
3
+ export * from "./requestHandlerRegistry.ts";
package/dist/index.js CHANGED
@@ -1,3 +1,11 @@
1
- export { MswPlugin, MswPluginName, getMswPlugin } from './chunk-NDT73ZLW.js';
2
- export { RequestHandlerRegistry } from './chunk-CL6F3JZI.js';
3
- export { MswState, __clearMswState, __setMswState, addMswStateChangedListener, isMswReady, removeMswStateChangedListener, setMswAsReady } from './chunk-YBOXRDQQ.js';
1
+ export * from "./mswPlugin.js";
2
+ export * from "./mswState.js";
3
+ export * from "./requestHandlerRegistry.js";
4
+
5
+ ;// CONCATENATED MODULE: ./src/index.ts?__rslib_entry__
6
+
7
+
8
+
9
+
10
+
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["webpack://@squide/msw/./src/index.ts"],"sourcesContent":["export * from \"./mswPlugin.ts\";\nexport * from \"./mswState.ts\";\nexport * from \"./requestHandlerRegistry.ts\";\n\n"],"names":[],"mappings":";;;;;AAA+B;AACD;AACc"}
@@ -1,13 +1,10 @@
1
- import { Plugin, Runtime } from '@squide/core';
2
- import { RequestHandler } from 'msw';
3
-
4
- declare const MswPluginName = "msw-plugin";
5
- declare class MswPlugin extends Plugin {
1
+ import { Plugin, type Runtime } from "@squide/core";
2
+ import type { RequestHandler } from "msw";
3
+ export declare const MswPluginName = "msw-plugin";
4
+ export declare class MswPlugin extends Plugin {
6
5
  #private;
7
6
  constructor(runtime: Runtime);
8
7
  registerRequestHandlers(handlers: RequestHandler[]): void;
9
8
  get requestHandlers(): RequestHandler[];
10
9
  }
11
- declare function getMswPlugin(runtime: Runtime): MswPlugin;
12
-
13
- export { MswPlugin, MswPluginName, getMswPlugin };
10
+ export declare function getMswPlugin(runtime: Runtime): MswPlugin;
package/dist/mswPlugin.js CHANGED
@@ -1,3 +1,35 @@
1
- export { MswPlugin, MswPluginName, getMswPlugin } from './chunk-NDT73ZLW.js';
2
- import './chunk-CL6F3JZI.js';
3
- import './chunk-YBOXRDQQ.js';
1
+ import * as __WEBPACK_EXTERNAL_MODULE__core_src_index_js_d19dd8a6__ from "../../core/src/index.js";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__requestHandlerRegistry_js_564606de__ from "./requestHandlerRegistry.js";
3
+
4
+ ;// CONCATENATED MODULE: external "../../core/src/index.js"
5
+
6
+ ;// CONCATENATED MODULE: external "./requestHandlerRegistry.js"
7
+
8
+ ;// CONCATENATED MODULE: ./src/mswPlugin.ts?__rslib_entry__
9
+
10
+
11
+ const MswPluginName = "msw-plugin";
12
+ class MswPlugin extends __WEBPACK_EXTERNAL_MODULE__core_src_index_js_d19dd8a6__.Plugin {
13
+ #requestHandlerRegistry = new __WEBPACK_EXTERNAL_MODULE__requestHandlerRegistry_js_564606de__.RequestHandlerRegistry();
14
+ constructor(runtime){
15
+ super(MswPluginName, runtime);
16
+ }
17
+ registerRequestHandlers(handlers) {
18
+ this.#requestHandlerRegistry.add(handlers);
19
+ this._runtime.logger.debug("[squide] The following MSW request handlers has been registered: ", handlers);
20
+ }
21
+ get requestHandlers() {
22
+ return this.#requestHandlerRegistry.handlers;
23
+ }
24
+ }
25
+ function getMswPlugin(runtime) {
26
+ const plugin = runtime.getPlugin(MswPluginName);
27
+ if ((0,__WEBPACK_EXTERNAL_MODULE__core_src_index_js_d19dd8a6__.isNil)(plugin)) {
28
+ throw new Error("[squide] The getMswPlugin function is called but no MswPlugin instance has been registered with the runtime.");
29
+ }
30
+ return plugin;
31
+ }
32
+
33
+ export { MswPlugin, MswPluginName, getMswPlugin };
34
+
35
+ //# sourceMappingURL=mswPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mswPlugin.js","sources":["webpack://@squide/msw/./src/mswPlugin.ts"],"sourcesContent":["import { Plugin, isNil, type Runtime } from \"@squide/core\";\nimport type { RequestHandler } from \"msw\";\nimport { RequestHandlerRegistry } from \"./requestHandlerRegistry.ts\";\n\nexport const MswPluginName = \"msw-plugin\";\n\nexport class MswPlugin extends Plugin {\n readonly #requestHandlerRegistry = new RequestHandlerRegistry();\n\n constructor(runtime: Runtime) {\n super(MswPluginName, runtime);\n }\n\n registerRequestHandlers(handlers: RequestHandler[]) {\n this.#requestHandlerRegistry.add(handlers);\n\n this._runtime.logger.debug(\"[squide] The following MSW request handlers has been registered: \", handlers);\n }\n\n get requestHandlers(): RequestHandler[] {\n return this.#requestHandlerRegistry.handlers;\n }\n}\n\nexport function getMswPlugin(runtime: Runtime) {\n const plugin = runtime.getPlugin(MswPluginName);\n\n if (isNil(plugin)) {\n throw new Error(\"[squide] The getMswPlugin function is called but no MswPlugin instance has been registered with the runtime.\");\n }\n\n return plugin as MswPlugin;\n}\n"],"names":["Plugin","isNil","RequestHandlerRegistry","MswPluginName","MswPlugin","runtime","handlers","getMswPlugin","plugin","Error"],"mappings":";;;;;;;;AAA2D;AAEU;AAE9D,MAAMG,gBAAgB,aAAa;AAEnC,MAAMC,kBAAkBJ,8DAAMA;IACxB,uBAAuB,GAAG,IAAIE,sFAAsBA,GAAG;IAEhE,YAAYG,OAAgB,CAAE;QAC1B,KAAK,CAACF,eAAeE;IACzB;IAEA,wBAAwBC,QAA0B,EAAE;QAChD,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAACA;QAEjC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,qEAAqEA;IACpG;IAEA,IAAI,kBAAoC;QACpC,OAAO,IAAI,CAAC,uBAAuB,CAAC,QAAQ;IAChD;AACJ;AAEO,SAASC,aAAaF,OAAgB;IACzC,MAAMG,SAASH,QAAQ,SAAS,CAACF;IAEjC,IAAIF,iEAAKA,CAACO,SAAS;QACf,MAAM,IAAIC,MAAM;IACpB;IAEA,OAAOD;AACX"}
@@ -1,16 +1,14 @@
1
- type MswStateChangedListener = () => void;
2
- declare class MswState {
1
+ export type MswStateChangedListener = () => void;
2
+ export declare class MswState {
3
3
  #private;
4
4
  addStateChangedListener(callback: MswStateChangedListener): void;
5
5
  removeStateChangedListener(callback: MswStateChangedListener): void;
6
6
  setAsReady(): void;
7
7
  get isReady(): boolean;
8
8
  }
9
- declare function __setMswState(state: MswState): void;
10
- declare function __clearMswState(): void;
11
- declare function setMswAsReady(): void;
12
- declare function isMswReady(): boolean;
13
- declare function addMswStateChangedListener(callback: MswStateChangedListener): void;
14
- declare function removeMswStateChangedListener(callback: MswStateChangedListener): void;
15
-
16
- export { MswState, type MswStateChangedListener, __clearMswState, __setMswState, addMswStateChangedListener, isMswReady, removeMswStateChangedListener, setMswAsReady };
9
+ export declare function __setMswState(state: MswState): void;
10
+ export declare function __clearMswState(): void;
11
+ export declare function setMswAsReady(): void;
12
+ export declare function isMswReady(): boolean;
13
+ export declare function addMswStateChangedListener(callback: MswStateChangedListener): void;
14
+ export declare function removeMswStateChangedListener(callback: MswStateChangedListener): void;
package/dist/mswState.js CHANGED
@@ -1 +1,54 @@
1
- export { MswState, __clearMswState, __setMswState, addMswStateChangedListener, isMswReady, removeMswStateChangedListener, setMswAsReady } from './chunk-YBOXRDQQ.js';
1
+
2
+ ;// CONCATENATED MODULE: ./src/mswState.ts?__rslib_entry__
3
+ class MswState {
4
+ #isReady = false;
5
+ #stateChangedListeners = new Set();
6
+ addStateChangedListener(callback) {
7
+ this.#stateChangedListeners.add(callback);
8
+ }
9
+ removeStateChangedListener(callback) {
10
+ this.#stateChangedListeners.delete(callback);
11
+ }
12
+ setAsReady() {
13
+ if (!this.#isReady) {
14
+ this.#isReady = true;
15
+ this.#stateChangedListeners.forEach((x)=>{
16
+ x();
17
+ });
18
+ }
19
+ }
20
+ get isReady() {
21
+ return this.#isReady;
22
+ }
23
+ }
24
+ let mswState;
25
+ function getMswState() {
26
+ if (!mswState) {
27
+ mswState = new MswState();
28
+ }
29
+ return mswState;
30
+ }
31
+ // This function should only be used by tests.
32
+ function __setMswState(state) {
33
+ mswState = state;
34
+ }
35
+ // This function should only be used by tests.
36
+ function __clearMswState() {
37
+ mswState = undefined;
38
+ }
39
+ function setMswAsReady() {
40
+ getMswState().setAsReady();
41
+ }
42
+ function isMswReady() {
43
+ return getMswState().isReady;
44
+ }
45
+ function addMswStateChangedListener(callback) {
46
+ getMswState().addStateChangedListener(callback);
47
+ }
48
+ function removeMswStateChangedListener(callback) {
49
+ getMswState().removeStateChangedListener(callback);
50
+ }
51
+
52
+ export { MswState, __clearMswState, __setMswState, addMswStateChangedListener, isMswReady, removeMswStateChangedListener, setMswAsReady };
53
+
54
+ //# sourceMappingURL=mswState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mswState.js","sources":["webpack://@squide/msw/./src/mswState.ts"],"sourcesContent":["export type MswStateChangedListener = () => void;\n\nexport class MswState {\n #isReady = false;\n\n readonly #stateChangedListeners = new Set<MswStateChangedListener>();\n\n addStateChangedListener(callback: MswStateChangedListener) {\n this.#stateChangedListeners.add(callback);\n }\n\n removeStateChangedListener(callback: MswStateChangedListener) {\n this.#stateChangedListeners.delete(callback);\n }\n\n setAsReady() {\n if (!this.#isReady) {\n this.#isReady = true;\n\n this.#stateChangedListeners.forEach(x => {\n x();\n });\n }\n }\n\n get isReady() {\n return this.#isReady;\n }\n}\n\nlet mswState: MswState | undefined;\n\nfunction getMswState() {\n if (!mswState) {\n mswState = new MswState();\n }\n\n return mswState;\n}\n\n// This function should only be used by tests.\nexport function __setMswState(state: MswState) {\n mswState = state;\n}\n\n// This function should only be used by tests.\nexport function __clearMswState() {\n mswState = undefined;\n}\n\nexport function setMswAsReady() {\n getMswState().setAsReady();\n}\n\nexport function isMswReady() {\n return getMswState().isReady;\n}\n\nexport function addMswStateChangedListener(callback: MswStateChangedListener) {\n getMswState().addStateChangedListener(callback);\n}\n\nexport function removeMswStateChangedListener(callback: MswStateChangedListener) {\n getMswState().removeStateChangedListener(callback);\n}\n"],"names":["MswState","Set","callback","x","mswState","getMswState","__setMswState","state","__clearMswState","undefined","setMswAsReady","isMswReady","addMswStateChangedListener","removeMswStateChangedListener"],"mappings":";;AAEO,MAAMA;IACT,QAAQ,GAAG,MAAM;IAER,sBAAsB,GAAG,IAAIC,MAA+B;IAErE,wBAAwBC,QAAiC,EAAE;QACvD,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAACA;IACpC;IAEA,2BAA2BA,QAAiC,EAAE;QAC1D,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAACA;IACvC;IAEA,aAAa;QACT,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAChB,IAAI,CAAC,QAAQ,GAAG;YAEhB,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAACC,CAAAA;gBAChCA;YACJ;QACJ;IACJ;IAEA,IAAI,UAAU;QACV,OAAO,IAAI,CAAC,QAAQ;IACxB;AACJ;AAEA,IAAIC;AAEJ,SAASC;IACL,IAAI,CAACD,UAAU;QACXA,WAAW,IAAIJ;IACnB;IAEA,OAAOI;AACX;AAEA,8CAA8C;AACvC,SAASE,cAAcC,KAAe;IACzCH,WAAWG;AACf;AAEA,8CAA8C;AACvC,SAASC;IACZJ,WAAWK;AACf;AAEO,SAASC;IACZL,cAAc,UAAU;AAC5B;AAEO,SAASM;IACZ,OAAON,cAAc,OAAO;AAChC;AAEO,SAASO,2BAA2BV,QAAiC;IACxEG,cAAc,uBAAuB,CAACH;AAC1C;AAEO,SAASW,8BAA8BX,QAAiC;IAC3EG,cAAc,0BAA0B,CAACH;AAC7C"}
@@ -1,9 +1,6 @@
1
- import { RequestHandler } from 'msw';
2
-
3
- declare class RequestHandlerRegistry {
1
+ import type { RequestHandler } from "msw";
2
+ export declare class RequestHandlerRegistry {
4
3
  #private;
5
4
  add(handlers: RequestHandler[]): void;
6
5
  get handlers(): RequestHandler[];
7
6
  }
8
-
9
- export { RequestHandlerRegistry };
@@ -1,2 +1,24 @@
1
- export { RequestHandlerRegistry } from './chunk-CL6F3JZI.js';
2
- import './chunk-YBOXRDQQ.js';
1
+ import * as __WEBPACK_EXTERNAL_MODULE__mswState_js_15009c7d__ from "./mswState.js";
2
+
3
+ ;// CONCATENATED MODULE: external "./mswState.js"
4
+
5
+ ;// CONCATENATED MODULE: ./src/requestHandlerRegistry.ts?__rslib_entry__
6
+
7
+ class RequestHandlerRegistry {
8
+ #handlers = [];
9
+ add(handlers) {
10
+ if ((0,__WEBPACK_EXTERNAL_MODULE__mswState_js_15009c7d__.isMswReady)()) {
11
+ throw new Error("[squide] MSW request handlers cannot be registered once MSW is started. Did you defer the registration of a MSW request handler?");
12
+ }
13
+ this.#handlers.push(...handlers);
14
+ }
15
+ // Must specify the return type, otherwise we get a TS2742: The inferred type cannot be named without a reference to X. This is likely not portable.
16
+ // A type annotation is necessary.
17
+ get handlers() {
18
+ return this.#handlers;
19
+ }
20
+ }
21
+
22
+ export { RequestHandlerRegistry };
23
+
24
+ //# sourceMappingURL=requestHandlerRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestHandlerRegistry.js","sources":["webpack://@squide/msw/./src/requestHandlerRegistry.ts"],"sourcesContent":["import type { RequestHandler } from \"msw\";\nimport { isMswReady } from \"./mswState.ts\";\n\nexport class RequestHandlerRegistry {\n readonly #handlers: RequestHandler[] = [];\n\n add(handlers: RequestHandler[]) {\n if (isMswReady()) {\n throw new Error(\"[squide] MSW request handlers cannot be registered once MSW is started. Did you defer the registration of a MSW request handler?\");\n }\n\n this.#handlers.push(...handlers);\n }\n\n // Must specify the return type, otherwise we get a TS2742: The inferred type cannot be named without a reference to X. This is likely not portable.\n // A type annotation is necessary.\n get handlers(): RequestHandler[] {\n return this.#handlers;\n }\n}\n\n"],"names":["isMswReady","RequestHandlerRegistry","handlers","Error"],"mappings":";;;;;AAC2C;AAEpC,MAAMC;IACA,SAAS,GAAqB,EAAE,CAAC;IAE1C,IAAIC,QAA0B,EAAE;QAC5B,IAAIF,gEAAUA,IAAI;YACd,MAAM,IAAIG,MAAM;QACpB;QAEA,IAAI,CAAC,SAAS,CAAC,IAAI,IAAID;IAC3B;IAEA,oJAAoJ;IACpJ,kCAAkC;IAClC,IAAI,WAA6B;QAC7B,OAAO,IAAI,CAAC,SAAS;IACzB;AACJ"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@squide/msw",
3
3
  "author": "Workleap",
4
- "version": "3.2.1",
4
+ "version": "3.2.2",
5
5
  "description": "Add support for MSW to @squide application shell.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -9,11 +9,11 @@
9
9
  "url": "git+https://github.com/gsoft-inc/wl-squide.git",
10
10
  "directory": "packages/msw"
11
11
  },
12
+ "type": "module",
12
13
  "publishConfig": {
13
14
  "access": "public",
14
15
  "provenance": true
15
16
  },
16
- "type": "module",
17
17
  "exports": {
18
18
  ".": {
19
19
  "types": "./dist/index.d.ts",
@@ -22,42 +22,40 @@
22
22
  }
23
23
  },
24
24
  "files": [
25
- "/dist",
25
+ "src",
26
+ "dist",
26
27
  "CHANGELOG.md",
27
28
  "README.md"
28
29
  ],
29
30
  "peerDependencies": {
30
- "msw": "*",
31
- "react": "*",
32
- "react-dom": "*"
31
+ "msw": "*"
33
32
  },
34
33
  "peerDependenciesMeta": {
35
34
  "msw": {
36
35
  "optional": true
37
36
  }
38
37
  },
38
+ "dependencies": {
39
+ "@squide/core": "5.4.2"
40
+ },
39
41
  "devDependencies": {
40
- "@types/react": "18.3.12",
41
- "@types/react-dom": "18.3.1",
42
- "@workleap/eslint-plugin": "3.2.3",
43
- "@workleap/tsup-configs": "3.0.6",
42
+ "@rsbuild/core": "1.1.13",
43
+ "@rslib/core": "0.3.1",
44
+ "@typescript-eslint/parser": "8.20.0",
45
+ "@workleap/eslint-plugin": "3.2.6",
46
+ "@workleap/rslib-configs": "1.0.2",
44
47
  "@workleap/typescript-configs": "3.0.2",
45
48
  "eslint": "8.57.0",
46
- "msw": "2.5.2",
47
- "react": "18.3.1",
48
- "react-dom": "18.3.1",
49
- "tsup": "8.3.5",
49
+ "msw": "2.7.0",
50
50
  "typescript": "5.5.4"
51
51
  },
52
- "dependencies": {
53
- "@squide/core": "5.4.1"
54
- },
55
52
  "sideEffects": false,
56
53
  "engines": {
57
- "node": ">=20.0.0"
54
+ "node": ">=21.1.0"
58
55
  },
59
56
  "scripts": {
60
- "dev": "tsup --config ./tsup.dev.ts",
61
- "build": "tsup --config ./tsup.build.ts"
57
+ "build": "rslib build --config ./rslib.build.ts",
58
+ "eslint": "eslint . --max-warnings=-0 --cache --cache-location node_modules/.cache/eslint",
59
+ "typecheck": "tsc"
62
60
  }
63
61
  }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./mswPlugin.ts";
2
+ export * from "./mswState.ts";
3
+ export * from "./requestHandlerRegistry.ts";
4
+
@@ -0,0 +1,33 @@
1
+ import { Plugin, isNil, type Runtime } from "@squide/core";
2
+ import type { RequestHandler } from "msw";
3
+ import { RequestHandlerRegistry } from "./requestHandlerRegistry.ts";
4
+
5
+ export const MswPluginName = "msw-plugin";
6
+
7
+ export class MswPlugin extends Plugin {
8
+ readonly #requestHandlerRegistry = new RequestHandlerRegistry();
9
+
10
+ constructor(runtime: Runtime) {
11
+ super(MswPluginName, runtime);
12
+ }
13
+
14
+ registerRequestHandlers(handlers: RequestHandler[]) {
15
+ this.#requestHandlerRegistry.add(handlers);
16
+
17
+ this._runtime.logger.debug("[squide] The following MSW request handlers has been registered: ", handlers);
18
+ }
19
+
20
+ get requestHandlers(): RequestHandler[] {
21
+ return this.#requestHandlerRegistry.handlers;
22
+ }
23
+ }
24
+
25
+ export function getMswPlugin(runtime: Runtime) {
26
+ const plugin = runtime.getPlugin(MswPluginName);
27
+
28
+ if (isNil(plugin)) {
29
+ throw new Error("[squide] The getMswPlugin function is called but no MswPlugin instance has been registered with the runtime.");
30
+ }
31
+
32
+ return plugin as MswPlugin;
33
+ }
@@ -0,0 +1,65 @@
1
+ export type MswStateChangedListener = () => void;
2
+
3
+ export class MswState {
4
+ #isReady = false;
5
+
6
+ readonly #stateChangedListeners = new Set<MswStateChangedListener>();
7
+
8
+ addStateChangedListener(callback: MswStateChangedListener) {
9
+ this.#stateChangedListeners.add(callback);
10
+ }
11
+
12
+ removeStateChangedListener(callback: MswStateChangedListener) {
13
+ this.#stateChangedListeners.delete(callback);
14
+ }
15
+
16
+ setAsReady() {
17
+ if (!this.#isReady) {
18
+ this.#isReady = true;
19
+
20
+ this.#stateChangedListeners.forEach(x => {
21
+ x();
22
+ });
23
+ }
24
+ }
25
+
26
+ get isReady() {
27
+ return this.#isReady;
28
+ }
29
+ }
30
+
31
+ let mswState: MswState | undefined;
32
+
33
+ function getMswState() {
34
+ if (!mswState) {
35
+ mswState = new MswState();
36
+ }
37
+
38
+ return mswState;
39
+ }
40
+
41
+ // This function should only be used by tests.
42
+ export function __setMswState(state: MswState) {
43
+ mswState = state;
44
+ }
45
+
46
+ // This function should only be used by tests.
47
+ export function __clearMswState() {
48
+ mswState = undefined;
49
+ }
50
+
51
+ export function setMswAsReady() {
52
+ getMswState().setAsReady();
53
+ }
54
+
55
+ export function isMswReady() {
56
+ return getMswState().isReady;
57
+ }
58
+
59
+ export function addMswStateChangedListener(callback: MswStateChangedListener) {
60
+ getMswState().addStateChangedListener(callback);
61
+ }
62
+
63
+ export function removeMswStateChangedListener(callback: MswStateChangedListener) {
64
+ getMswState().removeStateChangedListener(callback);
65
+ }
@@ -0,0 +1,21 @@
1
+ import type { RequestHandler } from "msw";
2
+ import { isMswReady } from "./mswState.ts";
3
+
4
+ export class RequestHandlerRegistry {
5
+ readonly #handlers: RequestHandler[] = [];
6
+
7
+ add(handlers: RequestHandler[]) {
8
+ if (isMswReady()) {
9
+ throw new Error("[squide] MSW request handlers cannot be registered once MSW is started. Did you defer the registration of a MSW request handler?");
10
+ }
11
+
12
+ this.#handlers.push(...handlers);
13
+ }
14
+
15
+ // Must specify the return type, otherwise we get a TS2742: The inferred type cannot be named without a reference to X. This is likely not portable.
16
+ // A type annotation is necessary.
17
+ get handlers(): RequestHandler[] {
18
+ return this.#handlers;
19
+ }
20
+ }
21
+
@@ -1,19 +0,0 @@
1
- import { isMswReady } from './chunk-YBOXRDQQ.js';
2
-
3
- // src/requestHandlerRegistry.ts
4
- var RequestHandlerRegistry = class {
5
- #handlers = [];
6
- add(handlers) {
7
- if (isMswReady()) {
8
- throw new Error("[squide] MSW request handlers cannot be registered once MSW is started. Did you defer the registration of a MSW request handler?");
9
- }
10
- this.#handlers.push(...handlers);
11
- }
12
- // Must specify the return type, otherwise we get a TS2742: The inferred type cannot be named without a reference to X. This is likely not portable.
13
- // A type annotation is necessary.
14
- get handlers() {
15
- return this.#handlers;
16
- }
17
- };
18
-
19
- export { RequestHandlerRegistry };
@@ -1,26 +0,0 @@
1
- import { RequestHandlerRegistry } from './chunk-CL6F3JZI.js';
2
- import { Plugin, isNil } from '@squide/core';
3
-
4
- var MswPluginName = "msw-plugin";
5
- var MswPlugin = class extends Plugin {
6
- #requestHandlerRegistry = new RequestHandlerRegistry();
7
- constructor(runtime) {
8
- super(MswPluginName, runtime);
9
- }
10
- registerRequestHandlers(handlers) {
11
- this.#requestHandlerRegistry.add(handlers);
12
- this._runtime.logger.debug("[squide] The following MSW request handlers has been registered: ", handlers);
13
- }
14
- get requestHandlers() {
15
- return this.#requestHandlerRegistry.handlers;
16
- }
17
- };
18
- function getMswPlugin(runtime) {
19
- const plugin = runtime.getPlugin(MswPluginName);
20
- if (isNil(plugin)) {
21
- throw new Error("[squide] The getMswPlugin function is called but no MswPlugin instance has been registered with the runtime.");
22
- }
23
- return plugin;
24
- }
25
-
26
- export { MswPlugin, MswPluginName, getMswPlugin };
@@ -1,49 +0,0 @@
1
- // src/mswState.ts
2
- var MswState = class {
3
- #isReady = false;
4
- #stateChangedListeners = /* @__PURE__ */ new Set();
5
- addStateChangedListener(callback) {
6
- this.#stateChangedListeners.add(callback);
7
- }
8
- removeStateChangedListener(callback) {
9
- this.#stateChangedListeners.delete(callback);
10
- }
11
- setAsReady() {
12
- if (!this.#isReady) {
13
- this.#isReady = true;
14
- this.#stateChangedListeners.forEach((x) => {
15
- x();
16
- });
17
- }
18
- }
19
- get isReady() {
20
- return this.#isReady;
21
- }
22
- };
23
- var mswState;
24
- function getMswState() {
25
- if (!mswState) {
26
- mswState = new MswState();
27
- }
28
- return mswState;
29
- }
30
- function __setMswState(state) {
31
- mswState = state;
32
- }
33
- function __clearMswState() {
34
- mswState = void 0;
35
- }
36
- function setMswAsReady() {
37
- getMswState().setAsReady();
38
- }
39
- function isMswReady() {
40
- return getMswState().isReady;
41
- }
42
- function addMswStateChangedListener(callback) {
43
- getMswState().addStateChangedListener(callback);
44
- }
45
- function removeMswStateChangedListener(callback) {
46
- getMswState().removeStateChangedListener(callback);
47
- }
48
-
49
- export { MswState, __clearMswState, __setMswState, addMswStateChangedListener, isMswReady, removeMswStateChangedListener, setMswAsReady };