@equinor/fusion-framework 8.0.15 → 8.1.0-next.1
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 +197 -0
- package/README.md +30 -0
- package/dist/esm/__tests__/mock/application-module.test.js +53 -0
- package/dist/esm/__tests__/mock/application-module.test.js.map +1 -0
- package/dist/esm/__tests__/mock/documented-usage.test.js +73 -0
- package/dist/esm/__tests__/mock/documented-usage.test.js.map +1 -0
- package/dist/esm/__tests__/mock/mock-framework.test.js +212 -0
- package/dist/esm/__tests__/mock/mock-framework.test.js.map +1 -0
- package/dist/esm/init.js +7 -2
- package/dist/esm/init.js.map +1 -1
- package/dist/esm/mock/FrameworkMockConfigurator.js +233 -0
- package/dist/esm/mock/FrameworkMockConfigurator.js.map +1 -0
- package/dist/esm/mock/index.js +32 -0
- package/dist/esm/mock/index.js.map +1 -0
- package/dist/esm/mock/mock-framework.js +55 -0
- package/dist/esm/mock/mock-framework.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/__tests__/mock/application-module.test.d.ts +1 -0
- package/dist/types/__tests__/mock/documented-usage.test.d.ts +1 -0
- package/dist/types/__tests__/mock/mock-framework.test.d.ts +1 -0
- package/dist/types/mock/FrameworkMockConfigurator.d.ts +185 -0
- package/dist/types/mock/index.d.ts +29 -0
- package/dist/types/mock/mock-framework.d.ts +58 -0
- package/dist/types/version.d.ts +1 -1
- package/docs/testing-api.md +25 -0
- package/docs/testing-choosing-a-layer.md +90 -0
- package/docs/testing-design.md +63 -0
- package/docs/testing-extending.md +102 -0
- package/docs/testing.md +178 -0
- package/package.json +17 -11
- package/src/__tests__/mock/application-module.test.ts +87 -0
- package/src/__tests__/mock/documented-usage.test.ts +98 -0
- package/src/__tests__/mock/mock-framework.test.ts +278 -0
- package/src/init.ts +7 -2
- package/src/mock/FrameworkMockConfigurator.ts +270 -0
- package/src/mock/index.ts +62 -0
- package/src/mock/mock-framework.ts +72 -0
- package/src/version.ts +1 -1
- package/vitest.config.ts +1 -1
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { contextMockModule, } from '@equinor/fusion-framework-module-context/mock';
|
|
2
|
+
import { module as httpModule, } from '@equinor/fusion-framework-module-http';
|
|
3
|
+
import { msalMockModule, } from '@equinor/fusion-framework-module-msal/mock';
|
|
4
|
+
import { serviceDiscoveryMockModule, } from '@equinor/fusion-framework-module-service-discovery/mock';
|
|
5
|
+
import servicesModule from '@equinor/fusion-framework-module-services';
|
|
6
|
+
import { telemetryMockModule, } from '@equinor/fusion-framework-module-telemetry/mock';
|
|
7
|
+
import { FrameworkConfigurator } from '../FrameworkConfigurator.js';
|
|
8
|
+
/**
|
|
9
|
+
* The real framework configurator, with every built-in module that reaches
|
|
10
|
+
* outside the process backed by a test double, and every other built-in
|
|
11
|
+
* module reachable the same way.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Nothing else changes: the same module set, the same configuration pipeline and
|
|
15
|
+
* the same lifecycle are used. Only the boundaries that would need credentials or
|
|
16
|
+
* network access are substituted, so a test still exercises module wiring,
|
|
17
|
+
* configuration validation and lifecycle hooks.
|
|
18
|
+
*
|
|
19
|
+
* Every built-in module exposes its own configurator as a property, so a test
|
|
20
|
+
* reaches it directly instead of registering a callback to receive it. `http`
|
|
21
|
+
* is the real configurator — fake a response by registering a
|
|
22
|
+
* short-circuiting middleware through `.http.addMiddleware(...)` instead of
|
|
23
|
+
* swapping the module out; see `@equinor/fusion-framework-module-http/mock`'s
|
|
24
|
+
* `createOpenApiMockMiddleware` for faking a whole `@equinor/fusion-openapi-mock`
|
|
25
|
+
* document that way. `services` is not backed by a test double yet either, so
|
|
26
|
+
* calls through its configurator still reach the network — but
|
|
27
|
+
* the configurator itself is reachable the same way `.msal` is, since its
|
|
28
|
+
* `configure` factory takes no `ref` and so loses nothing by being pinned early.
|
|
29
|
+
*
|
|
30
|
+
* `event` is deliberately not pinned: its `configure` factory reads `ref` to
|
|
31
|
+
* wire bubbling to a parent event provider when this configurator is hoisted
|
|
32
|
+
* inside a host framework, and pinning would freeze that decision before a
|
|
33
|
+
* `ref` could ever be known.
|
|
34
|
+
*
|
|
35
|
+
* Because this *is* a `FrameworkConfigurator`, every `enableX` helper an
|
|
36
|
+
* application already uses accepts it unchanged — including the ones an
|
|
37
|
+
* application team writes for their own modules.
|
|
38
|
+
*
|
|
39
|
+
* @typeParam TModules - Module descriptors beyond the built-in set. Supply this
|
|
40
|
+
* when a test registers application modules, so they are typed on the resulting
|
|
41
|
+
* instance.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const configurator = new FrameworkMockConfigurator();
|
|
46
|
+
*
|
|
47
|
+
* configurator.msal.setAccount({ name: 'Ada Lovelace' });
|
|
48
|
+
* configurator.serviceDiscovery.setBaseUri('http://localhost:6669');
|
|
49
|
+
*
|
|
50
|
+
* const fusion = await init(configurator);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export class FrameworkMockConfigurator extends FrameworkConfigurator {
|
|
54
|
+
static className = 'FrameworkMockConfigurator';
|
|
55
|
+
// Keyed by module name, so `_getConfig` can look a pinned configurator up
|
|
56
|
+
// without needing the module descriptor again.
|
|
57
|
+
#configurators = new Map();
|
|
58
|
+
/**
|
|
59
|
+
* Creates a framework configurator backed by the built-in mock modules.
|
|
60
|
+
*/
|
|
61
|
+
constructor() {
|
|
62
|
+
super();
|
|
63
|
+
// Pinning up front — rather than waiting for an accessor to be read — is
|
|
64
|
+
// what replaces the modules `FrameworkConfigurator`'s own constructor
|
|
65
|
+
// already registered, whether or not a test ever touches the accessor.
|
|
66
|
+
this._pin(msalMockModule);
|
|
67
|
+
this._pin(serviceDiscoveryMockModule);
|
|
68
|
+
this._pin(httpModule);
|
|
69
|
+
this._pin(servicesModule);
|
|
70
|
+
this._pin(contextMockModule);
|
|
71
|
+
this._pin(telemetryMockModule);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Pins a module to a single configurator instance for the lifetime of this
|
|
75
|
+
* configurator, so it can be reached by name through {@link _getConfig}.
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* The module system otherwise builds a fresh configurator from its own
|
|
79
|
+
* `configure` factory during the configure phase — too late for a test to
|
|
80
|
+
* reach, and a new instance on every call besides. This replaces that
|
|
81
|
+
* factory with one that always returns the same instance, and registers the
|
|
82
|
+
* result under the module's own name.
|
|
83
|
+
*
|
|
84
|
+
* A subclass registering a module supplied through {@link TModules} uses
|
|
85
|
+
* this the same way `.msal` and `.serviceDiscovery` do, to expose its own
|
|
86
|
+
* named accessor:
|
|
87
|
+
*
|
|
88
|
+
* ```typescript
|
|
89
|
+
* class MyMockConfigurator extends FrameworkMockConfigurator<[InvoiceModule]> {
|
|
90
|
+
* constructor() {
|
|
91
|
+
* super();
|
|
92
|
+
* this._pin(invoiceMockModule);
|
|
93
|
+
* }
|
|
94
|
+
*
|
|
95
|
+
* public get invoices(): InvoiceMockConfigurator {
|
|
96
|
+
* return this._getConfig('invoices');
|
|
97
|
+
* }
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @param module - The module descriptor to pin a configurator for.
|
|
102
|
+
* @template TModule - The specific module descriptor type being pinned.
|
|
103
|
+
* @throws {Error} If the module declares no `configure` factory to pin, or
|
|
104
|
+
* the factory returns a promise instead of a configurator — pinning is
|
|
105
|
+
* synchronous, so a test can reach the accessor immediately.
|
|
106
|
+
*/
|
|
107
|
+
_pin(module) {
|
|
108
|
+
// A module without a configure factory has nothing this method could pin
|
|
109
|
+
if (!module.configure) {
|
|
110
|
+
throw new Error(`Cannot pin "${module.name}": it declares no configure factory.`);
|
|
111
|
+
}
|
|
112
|
+
const instance = module.configure();
|
|
113
|
+
// Async factories would make the pinned instance unavailable until the module system
|
|
114
|
+
// resolves it later, defeating the point of pinning it for immediate synchronous access
|
|
115
|
+
if (instance instanceof Promise) {
|
|
116
|
+
throw new Error(`Cannot pin "${module.name}": its configure factory returns a promise, so it cannot be resolved synchronously.`);
|
|
117
|
+
}
|
|
118
|
+
this.#configurators.set(module.name, instance);
|
|
119
|
+
this.addConfig({ module: { ...module, configure: () => instance } });
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Returns the configurator pinned for a module by name.
|
|
123
|
+
*
|
|
124
|
+
* @param name - The module's name, as passed to {@link _pin}.
|
|
125
|
+
* @template TConfig - The specific configurator type expected for this module.
|
|
126
|
+
* @returns The configurator pinned under `name`.
|
|
127
|
+
* @throws {Error} If no configurator has been pinned for that name.
|
|
128
|
+
*/
|
|
129
|
+
_getConfig(name) {
|
|
130
|
+
const config = this.#configurators.get(name);
|
|
131
|
+
// A missing entry means _pin was never called for this module name
|
|
132
|
+
if (config === undefined) {
|
|
133
|
+
throw new Error(`No configurator is pinned for module "${name}" — call this._pin(module) before this._getConfig("${name}").`);
|
|
134
|
+
}
|
|
135
|
+
return config;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Configures the user the framework signs in.
|
|
139
|
+
*
|
|
140
|
+
* @remarks
|
|
141
|
+
* The same {@link MsalMockConfigurator} the auth module is configured from, so
|
|
142
|
+
* a change made here is what the module sees.
|
|
143
|
+
*
|
|
144
|
+
* @returns The MSAL mock configurator.
|
|
145
|
+
*/
|
|
146
|
+
get msal() {
|
|
147
|
+
return this._getConfig(msalMockModule.name);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Configures the registry services are resolved from.
|
|
151
|
+
*
|
|
152
|
+
* @remarks
|
|
153
|
+
* The same {@link ServiceDiscoveryMockConfigurator} the service discovery
|
|
154
|
+
* module is configured from, so a change made here is what the module sees.
|
|
155
|
+
*
|
|
156
|
+
* @returns The service discovery mock configurator.
|
|
157
|
+
*/
|
|
158
|
+
get serviceDiscovery() {
|
|
159
|
+
return this._getConfig(serviceDiscoveryMockModule.name);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Configures the HTTP module's named clients.
|
|
163
|
+
*
|
|
164
|
+
* @remarks
|
|
165
|
+
* The same {@link IHttpClientConfigurator} the HTTP module is configured
|
|
166
|
+
* from — the real one, not a test double. Register a short-circuiting
|
|
167
|
+
* {@link HttpMiddleware} through `addMiddleware` to answer from that
|
|
168
|
+
* instead of the network.
|
|
169
|
+
*
|
|
170
|
+
* @returns The real HTTP configurator.
|
|
171
|
+
*/
|
|
172
|
+
get http() {
|
|
173
|
+
return this._getConfig(httpModule.name);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Configures the typed API clients the `services` module builds.
|
|
177
|
+
*
|
|
178
|
+
* @remarks
|
|
179
|
+
* The real configurator — `services` has no test double yet.
|
|
180
|
+
*
|
|
181
|
+
* @returns The real API configurator.
|
|
182
|
+
*/
|
|
183
|
+
get services() {
|
|
184
|
+
return this._getConfig(servicesModule.name);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Configures context resolution.
|
|
188
|
+
*
|
|
189
|
+
* @remarks
|
|
190
|
+
* The same {@link ContextMockConfigurator} the context module is configured
|
|
191
|
+
* from, so seeding an item here is what `fusion.modules.context` resolves.
|
|
192
|
+
*
|
|
193
|
+
* @returns The context mock configurator.
|
|
194
|
+
*/
|
|
195
|
+
get context() {
|
|
196
|
+
return this._getConfig(contextMockModule.name);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Configures telemetry.
|
|
200
|
+
*
|
|
201
|
+
* @remarks
|
|
202
|
+
* The same {@link TelemetryMockConfigurator} the telemetry module is
|
|
203
|
+
* configured from, so a tracked event or measurement can be read back from
|
|
204
|
+
* its adapter instead of reaching Application Insights.
|
|
205
|
+
*
|
|
206
|
+
* @returns The telemetry mock configurator.
|
|
207
|
+
*/
|
|
208
|
+
get telemetry() {
|
|
209
|
+
return this._getConfig(telemetryMockModule.name);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Registers a module through its own enabler.
|
|
213
|
+
*
|
|
214
|
+
* @remarks
|
|
215
|
+
* Sugar for calling the enabler directly — `enableMyModuleMock(configurator)`
|
|
216
|
+
* works just as well, because this class *is* a `FrameworkConfigurator`. Use
|
|
217
|
+
* whichever reads better at the call site.
|
|
218
|
+
*
|
|
219
|
+
* @param configure - Callback receiving this configurator.
|
|
220
|
+
* @returns This configurator, for chaining.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```typescript
|
|
224
|
+
* configurator.addModule((c) => enableMyModuleMock(c, { total: 42 }));
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
addModule(configure) {
|
|
228
|
+
configure(this);
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
export default FrameworkMockConfigurator;
|
|
233
|
+
//# sourceMappingURL=FrameworkMockConfigurator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FrameworkMockConfigurator.js","sourceRoot":"","sources":["../../../src/mock/FrameworkMockConfigurator.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-configuration Fusion Framework instances for tests.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Lets an application initialize the real framework — real modules, real
|
|
6
|
+
* configuration pipeline, real lifecycle — while the boundaries that reach
|
|
7
|
+
* outside the process are substituted with deterministic fakes. No credentials,
|
|
8
|
+
* no network access and no configuration are required.
|
|
9
|
+
*
|
|
10
|
+
* This entry point holds **no mock logic**. Each module owns and exports its own
|
|
11
|
+
* test double from its `./mock` entry point; this entry point only composes the
|
|
12
|
+
* built-in set into a ready-to-use instance. An application module follows the
|
|
13
|
+
* same pattern and plugs in identically.
|
|
14
|
+
*
|
|
15
|
+
* This entry point is test-runner agnostic: it contains no dependency on Vitest
|
|
16
|
+
* or any other test framework, so the same helpers work under any runner.
|
|
17
|
+
*
|
|
18
|
+
* Fixture generators with realistic fake data (e.g. `createContextItems`) live
|
|
19
|
+
* on each module's own `/mock/fixtures` entry point instead of here, since they
|
|
20
|
+
* pull in an extra dependency ({@link https://fakerjs.dev/ | faker}) that
|
|
21
|
+
* plain configurator mocking doesn't need.
|
|
22
|
+
*
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
export { mockFramework } from './mock-framework.js';
|
|
26
|
+
export { FrameworkMockConfigurator } from './FrameworkMockConfigurator.js';
|
|
27
|
+
// Re-exported so a test can reach the built-in module mocks without importing
|
|
28
|
+
// each module's `./mock` entry point directly. The mocks are owned by their modules.
|
|
29
|
+
export { enableMsalMock, msalMockModule, MsalMockConfigurator, MsalMockClient, createMsalMockClient, createMockToken, } from '@equinor/fusion-framework-module-msal/mock';
|
|
30
|
+
export { mockServiceDiscovery, enableServiceDiscoveryMock, serviceDiscoveryMockModule, ServiceDiscoveryMockClient, ServiceDiscoveryMockConfigurator, createMockService, defaultServiceDiscoveryMockServices, } from '@equinor/fusion-framework-module-service-discovery/mock';
|
|
31
|
+
export { enableContextMock, contextMockModule, ContextMockConfigurator, } from '@equinor/fusion-framework-module-context/mock';
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mock/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,aAAa,EAAiC,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,8EAA8E;AAC9E,qFAAqF;AACrF,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,eAAe,GAIhB,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EACL,oBAAoB,EACpB,0BAA0B,EAC1B,0BAA0B,EAC1B,0BAA0B,EAC1B,gCAAgC,EAChC,iBAAiB,EACjB,mCAAmC,GAIpC,MAAM,yDAAyD,CAAC;AAEjE,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,GAGxB,MAAM,+CAA+C,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { init } from '../init.js';
|
|
2
|
+
import { FrameworkMockConfigurator } from './FrameworkMockConfigurator.js';
|
|
3
|
+
/**
|
|
4
|
+
* Starts a Fusion framework instance that needs no credentials and no network.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The real framework is started: the real module set, the real configuration
|
|
8
|
+
* pipeline and the real lifecycle. Only the boundaries that would need
|
|
9
|
+
* credentials or network access are substituted, so a test exercises the wiring
|
|
10
|
+
* an application actually depends on rather than a reimplementation of it.
|
|
11
|
+
*
|
|
12
|
+
* The configurator passed to `configure` is a {@link FrameworkMockConfigurator},
|
|
13
|
+
* which *is* a `FrameworkConfigurator`. Every `enableX` helper therefore accepts
|
|
14
|
+
* it unchanged — including the ones an application team writes for their own
|
|
15
|
+
* modules.
|
|
16
|
+
*
|
|
17
|
+
* Spying on individual calls is left to the test runner. The framework makes the
|
|
18
|
+
* runtime substitutable; `vi.spyOn`, `bun:test` `spyOn` and `t.mock.method` all
|
|
19
|
+
* work against the resulting instance with no framework support.
|
|
20
|
+
*
|
|
21
|
+
* @typeParam TModules - Module descriptors beyond the built-in set. Supply this
|
|
22
|
+
* when a test registers application modules, so they are typed on the result.
|
|
23
|
+
* @template TModules - Module descriptors beyond the built-in set.
|
|
24
|
+
* @param configure - Callback that configures the framework before it starts.
|
|
25
|
+
* @returns The initialized framework instance.
|
|
26
|
+
*
|
|
27
|
+
* @example Zero configuration
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const fusion = await mockFramework();
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example Configure the built-in mocks
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const fusion = await mockFramework((configurator) => {
|
|
35
|
+
* configurator.msal.setAccount({ name: 'Ada Lovelace' });
|
|
36
|
+
* configurator.serviceDiscovery.setBaseUri('http://localhost:6669');
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example Register an application module
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const fusion = await mockFramework<[InvoiceModule]>((configurator) => {
|
|
43
|
+
* enableInvoicesMock(configurator, { total: 42 });
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* await fusion.modules.invoices.getInvoice('1');
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export async function mockFramework(configure) {
|
|
50
|
+
const configurator = new FrameworkMockConfigurator();
|
|
51
|
+
await configure?.(configurator);
|
|
52
|
+
return await init(configurator);
|
|
53
|
+
}
|
|
54
|
+
export default mockFramework;
|
|
55
|
+
//# sourceMappingURL=mock-framework.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-framework.js","sourceRoot":"","sources":["../../../src/mock/mock-framework.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGlC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAY3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,SAA8C;IAE9C,MAAM,YAAY,GAAG,IAAI,yBAAyB,EAAY,CAAC;IAC/D,MAAM,SAAS,EAAE,CAAC,YAAY,CAAC,CAAC;IAChC,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,CAAC;AAClC,CAAC;AAED,eAAe,aAAa,CAAC"}
|
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,MAAM,CAAC,MAAM,OAAO,GAAG,cAAc,CAAC"}
|