@iota-uz/sdk 0.16.0 → 0.17.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/dist/client-host/identity.d.ts +4 -4
- package/dist/client-host/identity.js +2 -2
- package/dist/lens/{CascadePanel-jtC2EUUS.js → CascadePanel-Sd2OKQx-.js} +15 -15
- package/dist/lens/{ChartDataEquivalent-BFDdHoQn.js → ChartDataEquivalent-DgCAb4Ov.js} +14 -13
- package/dist/lens/ChartPanel-CiAahY9O.js +709 -0
- package/dist/lens/{CoveragePanel-5LWQwFMZ.js → CoveragePanel-DeeKg8gF.js} +10 -10
- package/dist/lens/{GaugePanel-eVYvp3Hk.js → GaugePanel-8rsf_XHS.js} +8 -8
- package/dist/lens/{MapPanel-CzpZKz1Y.js → MapPanel-Bq0mfVCB.js} +14 -14
- package/dist/lens/{MetricFlowPanel-CG2Bj7s6.js → MetricFlowPanel-ZBJqPFpc.js} +2 -2
- package/dist/lens/{MetricHierarchyPanel-Difdcafn.js → MetricHierarchyPanel-DStGwvVU.js} +2 -2
- package/dist/lens/{MetricRelationshipPanel-Cq1dFTeY.js → MetricRelationshipPanel-D6ItmGCS.js} +2 -2
- package/dist/lens/{PrintReport-BiUdo8XG.js → PrintReport-Dr-6xXVr.js} +413 -397
- package/dist/lens/{TablePanel-_6j7epQg.js → TablePanel-CzLP8gG0.js} +1 -1
- package/dist/lens/{adapter-DRShqW45.js → adapter-BwEwcw2W.js} +4960 -4956
- package/dist/lens/adapter-CgoRd_uP.js +6 -0
- package/dist/lens/charts/adapter.d.ts +1 -0
- package/dist/lens/charts/adapter.d.ts.map +1 -1
- package/dist/lens/charts/echarts/options.d.ts.map +1 -1
- package/dist/lens/charts/keys.d.ts +2 -0
- package/dist/lens/charts/keys.d.ts.map +1 -1
- package/dist/lens/contract/schemas.d.ts.map +1 -1
- package/dist/lens/contract/types.d.ts +1 -0
- package/dist/lens/contract/types.d.ts.map +1 -1
- package/dist/lens/{index-CmXDbBaF.js → index-B6anZ5Pr.js} +1 -1
- package/dist/lens/{index-BBtBPnTb.js → index-R9mnOHaj.js} +684 -667
- package/dist/lens/index.js +1 -1
- package/dist/lens/{install-ByIx15ES.js → install-CsNOaFxV.js} +1 -1
- package/dist/lens/{install-DKwCLbtk.js → install-CumkiUJn.js} +1 -1
- package/dist/lens/{install-ByEamXef.js → install-D5OiGDnd.js} +1 -1
- package/dist/lens/{install-DIbrzh5h.js → install-VEXJv-Wi.js} +1 -1
- package/dist/lens/keys-6_gqLhcv.js +78 -0
- package/dist/lens/{metricViews-IoSavtwn.js → metricViews-De-9pff-.js} +1 -1
- package/dist/lens/panels/ChartPanel.d.ts.map +1 -1
- package/dist/lens/panels/data.d.ts +2 -0
- package/dist/lens/panels/data.d.ts.map +1 -1
- package/dist/lens/{prefetch-CrMQhAEy.js → prefetch-C_qYKOTU.js} +2 -2
- package/dist/lens/{prefetchPanels-BbWAAYrz.js → prefetchPanels-CD4C-A5q.js} +1 -1
- package/dist/lens/print/PrintReport.d.ts.map +1 -1
- package/dist/lens/{print-CLo-mTEP.js → print-Iu804kRb.js} +18 -18
- package/dist/lens/{scales-CChHRiVq.js → scales-CWTA0tSQ.js} +53 -53
- package/dist/sdk-identity.cjs +3 -3
- package/dist/sdk-identity.js +3 -3
- package/dist/sdk-identity.json +2 -2
- package/dist/testing/driver.d.ts +19 -0
- package/dist/testing/driver.js +103 -30
- package/dist/testing/fixtures.d.ts +27 -0
- package/dist/testing/fixtures.js +19 -4
- package/dist/testing/index.d.ts +3 -2
- package/dist/testing/index.js +6 -30
- package/dist/testing/lease.d.ts +11 -0
- package/dist/testing/lease.js +44 -0
- package/package.json +1 -1
- package/dist/lens/ChartHost-DTnhnwkn.js +0 -68
- package/dist/lens/ChartPanel-_S4IVYdJ.js +0 -730
- package/dist/lens/keys-DenV5HsJ.js +0 -12
package/dist/testing/driver.js
CHANGED
|
@@ -1,74 +1,146 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createInterface } from 'node:readline';
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
|
+
export class DriverError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
operation;
|
|
7
|
+
environmentId;
|
|
8
|
+
artifactDirectory;
|
|
9
|
+
descriptor;
|
|
10
|
+
causes;
|
|
11
|
+
constructor(message, details) {
|
|
12
|
+
super(message, { cause: details.cause });
|
|
13
|
+
this.name = 'DriverError';
|
|
14
|
+
this.code = details.code;
|
|
15
|
+
this.operation = details.operation;
|
|
16
|
+
this.environmentId = details.environmentId;
|
|
17
|
+
this.artifactDirectory = details.artifactDirectory;
|
|
18
|
+
this.descriptor = details.descriptor;
|
|
19
|
+
this.causes = details.causes ?? [];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
4
22
|
/** One persistent, shell-free driver owns every environment it creates. */
|
|
5
23
|
export function createProcessEnvironmentDriver(options) {
|
|
6
24
|
const timeoutMs = options.timeoutMs ?? 120_000;
|
|
7
|
-
|
|
8
|
-
|
|
25
|
+
const closeTimeoutMs = options.closeTimeoutMs ?? 35_000;
|
|
26
|
+
const killTimeoutMs = options.killTimeoutMs ?? 10_000;
|
|
27
|
+
for (const [name, value] of Object.entries({ timeoutMs, closeTimeoutMs, killTimeoutMs })) {
|
|
28
|
+
if (!Number.isInteger(value) || value <= 0)
|
|
29
|
+
throw new Error(`${name} must be a positive integer`);
|
|
30
|
+
}
|
|
9
31
|
const child = spawn(options.command, [...options.args ?? []], { cwd: options.cwd, env: options.env, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
10
32
|
const pending = new Map();
|
|
33
|
+
const environments = new Map();
|
|
11
34
|
let stderr = '';
|
|
12
35
|
let closed = false;
|
|
36
|
+
let closing;
|
|
13
37
|
child.stderr.on('data', chunk => { stderr = (stderr + chunk).slice(-16_384); });
|
|
14
|
-
const
|
|
38
|
+
const failure = (request, code, message, cause) => new DriverError(message, {
|
|
39
|
+
code, operation: request.operation, environmentId: request.environmentId,
|
|
40
|
+
artifactDirectory: request.environmentId ? environments.get(request.environmentId)?.artifactDirectory : undefined, cause,
|
|
41
|
+
});
|
|
42
|
+
const rejectAll = (code, message, cause) => {
|
|
15
43
|
closed = true;
|
|
16
|
-
for (const
|
|
17
|
-
clearTimeout(
|
|
18
|
-
|
|
44
|
+
for (const item of pending.values()) {
|
|
45
|
+
clearTimeout(item.timer);
|
|
46
|
+
item.reject(failure(item.request, code, message, cause));
|
|
19
47
|
}
|
|
20
48
|
pending.clear();
|
|
21
49
|
};
|
|
22
50
|
const exit = new Promise((resolve, reject) => {
|
|
23
|
-
child.once('error', error => {
|
|
51
|
+
child.once('error', error => {
|
|
52
|
+
rejectAll('process_error', error.message, error);
|
|
53
|
+
reject(failure({ operation: 'close' }, 'process_error', error.message, error));
|
|
54
|
+
});
|
|
24
55
|
child.once('exit', (code, signal) => {
|
|
25
|
-
const
|
|
26
|
-
rejectAll(
|
|
56
|
+
const message = `Test environment driver exited (${code ?? signal}): ${stderr}`;
|
|
57
|
+
rejectAll('process_exit', message);
|
|
27
58
|
if (code === 0)
|
|
28
59
|
resolve();
|
|
29
60
|
else
|
|
30
|
-
reject(
|
|
61
|
+
reject(failure({ operation: 'close' }, 'process_exit', message));
|
|
31
62
|
});
|
|
32
63
|
});
|
|
33
|
-
// Keep unexpected process exits observed even before the caller closes the driver.
|
|
34
64
|
void exit.catch(() => { });
|
|
35
65
|
const lines = createInterface({ input: child.stdout });
|
|
66
|
+
const close = () => closing ??= (async () => {
|
|
67
|
+
closed = true;
|
|
68
|
+
child.stdin.end();
|
|
69
|
+
let timer;
|
|
70
|
+
const settled = async (ms) => {
|
|
71
|
+
try {
|
|
72
|
+
return await Promise.race([exit.then(() => true), new Promise(resolve => { timer = setTimeout(() => resolve(false), ms); })]);
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
if (timer)
|
|
76
|
+
clearTimeout(timer);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
try {
|
|
80
|
+
if (await settled(closeTimeoutMs))
|
|
81
|
+
return;
|
|
82
|
+
child.kill('SIGINT');
|
|
83
|
+
if (await settled(killTimeoutMs))
|
|
84
|
+
return;
|
|
85
|
+
child.kill('SIGKILL');
|
|
86
|
+
// Only this spawned driver receives the hard kill; never await its exit
|
|
87
|
+
// beyond the shutdown deadline. Its rejection remains observed above.
|
|
88
|
+
throw failure({ operation: 'close' }, 'close_timeout', 'Test environment driver did not close before its shutdown deadline');
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
lines.close();
|
|
92
|
+
}
|
|
93
|
+
})();
|
|
36
94
|
lines.on('line', line => {
|
|
37
95
|
let response;
|
|
96
|
+
const validError = (error) => error !== null && typeof error === 'object' && typeof error.code === 'string' && typeof error.message === 'string' && (error.causes === undefined || Array.isArray(error.causes) && error.causes.every(validError));
|
|
38
97
|
try {
|
|
39
98
|
response = JSON.parse(line);
|
|
99
|
+
if (response === null || typeof response !== 'object' || typeof response.id !== 'string' || (response.error !== undefined && !validError(response.error)))
|
|
100
|
+
throw new Error('Invalid response envelope');
|
|
40
101
|
}
|
|
41
102
|
catch {
|
|
42
|
-
rejectAll(
|
|
43
|
-
|
|
103
|
+
rejectAll('invalid_response', 'Test environment driver emitted invalid JSON');
|
|
104
|
+
void close().catch(() => { });
|
|
44
105
|
return;
|
|
45
106
|
}
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
107
|
+
const item = pending.get(response.id);
|
|
108
|
+
if (!item)
|
|
48
109
|
return;
|
|
49
110
|
pending.delete(response.id);
|
|
50
|
-
clearTimeout(
|
|
51
|
-
if (response.error)
|
|
52
|
-
|
|
111
|
+
clearTimeout(item.timer);
|
|
112
|
+
if (response.error) {
|
|
113
|
+
const convert = (error) => new DriverError(`${error.code}: ${error.message}`, {
|
|
114
|
+
code: error.code, operation: error.operation ?? item.request.operation,
|
|
115
|
+
environmentId: error.environmentId ?? response.descriptor?.environmentId ?? item.request.environmentId,
|
|
116
|
+
artifactDirectory: error.artifactDirectory ?? response.descriptor?.artifactDirectory ?? (item.request.environmentId ? environments.get(item.request.environmentId)?.artifactDirectory : undefined),
|
|
117
|
+
descriptor: response.descriptor, causes: error.causes?.map(convert),
|
|
118
|
+
});
|
|
119
|
+
item.reject(convert(response.error));
|
|
120
|
+
}
|
|
53
121
|
else
|
|
54
|
-
|
|
122
|
+
item.resolve(response.descriptor);
|
|
123
|
+
});
|
|
124
|
+
child.stdin.on('error', error => {
|
|
125
|
+
rejectAll('write_failed', error.message, error);
|
|
126
|
+
void close().catch(() => { });
|
|
55
127
|
});
|
|
56
128
|
const invoke = (request) => {
|
|
57
129
|
if (closed)
|
|
58
|
-
return Promise.reject(
|
|
130
|
+
return Promise.reject(failure(request, 'driver_closed', 'Test environment driver is closed'));
|
|
59
131
|
const id = randomUUID();
|
|
60
132
|
return new Promise((resolve, reject) => {
|
|
61
133
|
const timer = setTimeout(() => {
|
|
62
134
|
pending.delete(id);
|
|
63
|
-
reject(
|
|
64
|
-
|
|
135
|
+
reject(failure(request, 'request_timeout', 'Test environment driver request timed out'));
|
|
136
|
+
void close().catch(() => { });
|
|
65
137
|
}, timeoutMs);
|
|
66
|
-
pending.set(id, { resolve, reject, timer });
|
|
138
|
+
pending.set(id, { request, resolve, reject, timer });
|
|
67
139
|
child.stdin.write(`${JSON.stringify({ id, ...request })}\n`, error => {
|
|
68
140
|
if (error) {
|
|
69
141
|
clearTimeout(timer);
|
|
70
142
|
pending.delete(id);
|
|
71
|
-
reject(error);
|
|
143
|
+
reject(failure(request, 'write_failed', error.message, error));
|
|
72
144
|
}
|
|
73
145
|
});
|
|
74
146
|
});
|
|
@@ -77,14 +149,15 @@ export function createProcessEnvironmentDriver(options) {
|
|
|
77
149
|
start: async (workerIndex) => {
|
|
78
150
|
const descriptor = await invoke({ operation: 'start', spec: options.spec(workerIndex) });
|
|
79
151
|
if (!descriptor?.environmentId || !descriptor?.baseURL || !descriptor?.artifactDirectory) {
|
|
80
|
-
|
|
81
|
-
throw new
|
|
152
|
+
void close().catch(() => { });
|
|
153
|
+
throw new DriverError('Incomplete test environment descriptor', { code: 'invalid_descriptor', operation: 'start', environmentId: descriptor?.environmentId, artifactDirectory: descriptor?.artifactDirectory, descriptor });
|
|
82
154
|
}
|
|
83
|
-
|
|
155
|
+
const environment = { ...descriptor, runId: descriptor.environmentId, artifactDir: descriptor.artifactDirectory };
|
|
156
|
+
environments.set(environment.environmentId, environment);
|
|
157
|
+
return environment;
|
|
84
158
|
},
|
|
85
|
-
// Driver start returns only after the configured real readiness probe succeeds.
|
|
86
159
|
ready: async () => { },
|
|
87
|
-
stop: async (environment) => { await invoke({ operation: 'stop', environmentId: environment.environmentId }); },
|
|
160
|
+
stop: async (environment) => { await invoke({ operation: 'stop', environmentId: environment.environmentId }); environments.delete(environment.environmentId); },
|
|
88
161
|
};
|
|
89
|
-
return { lifecycle, close
|
|
162
|
+
return { lifecycle, close };
|
|
90
163
|
}
|
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
import type { Browser, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, TestType } from '@playwright/test';
|
|
2
2
|
import { type EnvironmentDescriptor, type EnvironmentLifecycle, type ScenarioControl, type ScenarioLease, type IdentityLease } from './index.js';
|
|
3
|
+
export interface EnvironmentLeaseInfo {
|
|
4
|
+
workerIndex: number;
|
|
5
|
+
parallelIndex: number;
|
|
6
|
+
testId?: string;
|
|
7
|
+
retry?: number;
|
|
8
|
+
runName: string;
|
|
9
|
+
environmentName: string;
|
|
10
|
+
}
|
|
11
|
+
type LeaseFixtureOptions<E extends EnvironmentDescriptor> = {
|
|
12
|
+
scope: 'test' | 'worker';
|
|
13
|
+
runName?: string;
|
|
14
|
+
name?(info: Omit<EnvironmentLeaseInfo, 'environmentName'>): string;
|
|
15
|
+
lifecycle(info: EnvironmentLeaseInfo): EnvironmentLifecycle<E> & {
|
|
16
|
+
close?(): Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare function createEnvironmentLeaseTest<T extends {}, W extends {}, E extends EnvironmentDescriptor>(base: TestType<T, W>, options: LeaseFixtureOptions<E> & {
|
|
20
|
+
scope: 'test';
|
|
21
|
+
}): TestType<T & {
|
|
22
|
+
environmentLease: E;
|
|
23
|
+
}, W>;
|
|
24
|
+
export declare function createEnvironmentLeaseTest<T extends {}, W extends {}, E extends EnvironmentDescriptor>(base: TestType<T, W>, options: LeaseFixtureOptions<E> & {
|
|
25
|
+
scope: 'worker';
|
|
26
|
+
}): TestType<T, W & {
|
|
27
|
+
environmentLease: E;
|
|
28
|
+
}>;
|
|
3
29
|
export declare function createEnvironmentTest<E extends EnvironmentDescriptor, Input, State, Key, Identity>(base: TestType<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>, options: {
|
|
4
30
|
lifecycle: EnvironmentLifecycle<E>;
|
|
5
31
|
scenarios(environment: E): ScenarioControl<Input, State>;
|
|
@@ -11,3 +37,4 @@ export declare function createEnvironmentTest<E extends EnvironmentDescriptor, I
|
|
|
11
37
|
environment: E;
|
|
12
38
|
workerIdentity: IdentityLease<Key, Identity>;
|
|
13
39
|
}>;
|
|
40
|
+
export {};
|
package/dist/testing/fixtures.js
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { lazyIdentities, withEnvironment } from './index.js';
|
|
2
|
+
import { preservingCleanup, withEnvironmentLease } from './lease.js';
|
|
3
|
+
export function createEnvironmentLeaseTest(base, options) {
|
|
4
|
+
const runName = options.runName ?? crypto.randomUUID();
|
|
5
|
+
const fixtures = {
|
|
6
|
+
environmentLease: [async ({}, use, info) => {
|
|
7
|
+
const identity = { workerIndex: info.workerIndex, parallelIndex: info.parallelIndex, testId: info.testId, retry: info.retry, runName };
|
|
8
|
+
const environmentName = options.name?.(identity) ?? `${runName}-w${info.workerIndex}-${info.testId ? `t${info.testId}-r${info.retry}` : 'worker'}`;
|
|
9
|
+
const lifecycle = options.lifecycle({ ...identity, environmentName });
|
|
10
|
+
await withEnvironmentLease(lifecycle, info.workerIndex, use, { closeDriver: lifecycle.close?.bind(lifecycle) });
|
|
11
|
+
}, { scope: options.scope }],
|
|
12
|
+
baseURL: async ({ environmentLease }, use) => { await use(environmentLease.baseURL); },
|
|
13
|
+
};
|
|
14
|
+
// The runtime scope selects which fixture namespace owns the same lease;
|
|
15
|
+
// overloads preserve that namespace for the consumer's injected base test.
|
|
16
|
+
return base.extend(fixtures);
|
|
17
|
+
}
|
|
2
18
|
export function createEnvironmentTest(base, options) {
|
|
3
19
|
return base.extend({
|
|
4
20
|
environment: [async ({}, use, info) => {
|
|
@@ -12,19 +28,18 @@ export function createEnvironmentTest(base, options) {
|
|
|
12
28
|
scenario: async ({ environment }, use, info) => {
|
|
13
29
|
const control = options.scenarios(environment);
|
|
14
30
|
const scopes = [];
|
|
15
|
-
|
|
31
|
+
await preservingCleanup(async () => {
|
|
16
32
|
await use(async (input) => {
|
|
17
33
|
const scope = `${environment.runId}-w${info.workerIndex}-r${info.retry}-${crypto.randomUUID()}`;
|
|
18
34
|
scopes.push(scope);
|
|
19
35
|
return control.prepare(input, scope);
|
|
20
36
|
});
|
|
21
|
-
}
|
|
22
|
-
finally {
|
|
37
|
+
}, async () => {
|
|
23
38
|
const results = await Promise.allSettled(scopes.map(scope => control.dispose(scope)));
|
|
24
39
|
const errors = results.filter((result) => result.status === 'rejected').map(result => result.reason);
|
|
25
40
|
if (errors.length)
|
|
26
41
|
throw new AggregateError(errors, 'Scenario teardown failed');
|
|
27
|
-
}
|
|
42
|
+
});
|
|
28
43
|
},
|
|
29
44
|
});
|
|
30
45
|
}
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -55,8 +55,9 @@ export declare function withScenario<Input, State, Result>(control: ScenarioCont
|
|
|
55
55
|
export declare function lazyIdentities<Key, State>(create: (identity: Key) => Promise<State>): (identity: Key) => Promise<State>;
|
|
56
56
|
export type ScenarioLease<Input, State> = (input: Input) => Promise<State>;
|
|
57
57
|
export type IdentityLease<Key, State> = (identity: Key) => Promise<State>;
|
|
58
|
-
export { createEnvironmentTest } from './fixtures.js';
|
|
59
|
-
export { createProcessEnvironmentDriver, type DriverDescriptor } from './driver.js';
|
|
58
|
+
export { createEnvironmentTest, createEnvironmentLeaseTest, type EnvironmentLeaseInfo } from './fixtures.js';
|
|
59
|
+
export { createProcessEnvironmentDriver, DriverError, type DriverDescriptor } from './driver.js';
|
|
60
|
+
export { acquireEnvironmentLease, withEnvironmentLease, preservingCleanup, type EnvironmentLease, type LeaseOptions } from './lease.js';
|
|
60
61
|
export declare function expectFontsReady(page: Page, options?: WaitOptions): Promise<void>;
|
|
61
62
|
export declare function expectChartsReady(charts: Locator, options?: WaitOptions & {
|
|
62
63
|
allowEmpty?: boolean;
|
package/dist/testing/index.js
CHANGED
|
@@ -189,36 +189,10 @@ export async function actionAndHtmxResponse(page, match, action, options = {}) {
|
|
|
189
189
|
}
|
|
190
190
|
/** Teardown runs even when readiness, the scenario or the browser assertion fails. */
|
|
191
191
|
export async function withEnvironment(lifecycle, workerIndex, use) {
|
|
192
|
-
|
|
193
|
-
let failed = false;
|
|
194
|
-
let failure;
|
|
195
|
-
try {
|
|
196
|
-
await lifecycle.ready(environment);
|
|
197
|
-
return await use(environment);
|
|
198
|
-
}
|
|
199
|
-
catch (error) {
|
|
200
|
-
failed = true;
|
|
201
|
-
failure = error;
|
|
202
|
-
throw error;
|
|
203
|
-
}
|
|
204
|
-
finally {
|
|
205
|
-
try {
|
|
206
|
-
await lifecycle.stop(environment);
|
|
207
|
-
}
|
|
208
|
-
catch (error) {
|
|
209
|
-
if (failed)
|
|
210
|
-
throw new AggregateError([failure, error], 'Environment failed and teardown failed');
|
|
211
|
-
throw error;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
192
|
+
return withEnvironmentLease(lifecycle, workerIndex, use);
|
|
214
193
|
}
|
|
215
194
|
export async function withScenario(control, input, scopeId, use) {
|
|
216
|
-
|
|
217
|
-
return await use(await control.prepare(input, scopeId));
|
|
218
|
-
}
|
|
219
|
-
finally {
|
|
220
|
-
await control.dispose(scopeId);
|
|
221
|
-
}
|
|
195
|
+
return preservingCleanup(async () => use(await control.prepare(input, scopeId)), () => control.dispose(scopeId));
|
|
222
196
|
}
|
|
223
197
|
/** Instantiate per worker/environment; identities are materialised only when requested. */
|
|
224
198
|
export function lazyIdentities(create) {
|
|
@@ -232,8 +206,10 @@ export function lazyIdentities(create) {
|
|
|
232
206
|
return state;
|
|
233
207
|
};
|
|
234
208
|
}
|
|
235
|
-
export { createEnvironmentTest } from './fixtures.js';
|
|
236
|
-
export { createProcessEnvironmentDriver } from './driver.js';
|
|
209
|
+
export { createEnvironmentTest, createEnvironmentLeaseTest } from './fixtures.js';
|
|
210
|
+
export { createProcessEnvironmentDriver, DriverError } from './driver.js';
|
|
211
|
+
import { preservingCleanup, withEnvironmentLease } from './lease.js';
|
|
212
|
+
export { acquireEnvironmentLease, withEnvironmentLease, preservingCleanup } from './lease.js';
|
|
237
213
|
export async function expectFontsReady(page, options = {}) {
|
|
238
214
|
await page.waitForFunction(() => document.fonts.status === 'loaded', undefined, { timeout: timeout(options) });
|
|
239
215
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EnvironmentDescriptor, EnvironmentLifecycle } from './index.js';
|
|
2
|
+
export interface EnvironmentLease<E extends EnvironmentDescriptor> {
|
|
3
|
+
environment: E;
|
|
4
|
+
close(): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export interface LeaseOptions {
|
|
7
|
+
closeDriver?(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare function preservingCleanup<Result>(use: () => Promise<Result>, cleanup: () => Promise<void>): Promise<Result>;
|
|
10
|
+
export declare function acquireEnvironmentLease<E extends EnvironmentDescriptor>(lifecycle: EnvironmentLifecycle<E>, workerIndex?: number, options?: LeaseOptions): Promise<EnvironmentLease<E>>;
|
|
11
|
+
export declare function withEnvironmentLease<E extends EnvironmentDescriptor, Result>(lifecycle: EnvironmentLifecycle<E>, workerIndex: number, use: (environment: E) => Promise<Result>, options?: LeaseOptions): Promise<Result>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export async function preservingCleanup(use, cleanup) {
|
|
2
|
+
let failed = false;
|
|
3
|
+
let failure;
|
|
4
|
+
try {
|
|
5
|
+
return await use();
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
failed = true;
|
|
9
|
+
failure = error;
|
|
10
|
+
throw error;
|
|
11
|
+
}
|
|
12
|
+
finally {
|
|
13
|
+
try {
|
|
14
|
+
await cleanup();
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (failed)
|
|
18
|
+
throw new AggregateError([failure, error], 'Operation and cleanup failed');
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export async function acquireEnvironmentLease(lifecycle, workerIndex = 0, options = {}) {
|
|
24
|
+
let environment;
|
|
25
|
+
try {
|
|
26
|
+
environment = await lifecycle.start(workerIndex);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return preservingCleanup(async () => { throw error; }, async () => { await options.closeDriver?.(); });
|
|
30
|
+
}
|
|
31
|
+
let closing;
|
|
32
|
+
const close = () => closing ??= preservingCleanup(() => lifecycle.stop(environment), async () => { await options.closeDriver?.(); });
|
|
33
|
+
try {
|
|
34
|
+
await lifecycle.ready(environment);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return preservingCleanup(async () => { throw error; }, close);
|
|
38
|
+
}
|
|
39
|
+
return { environment, close };
|
|
40
|
+
}
|
|
41
|
+
export async function withEnvironmentLease(lifecycle, workerIndex, use, options = {}) {
|
|
42
|
+
const lease = await acquireEnvironmentLease(lifecycle, workerIndex, options);
|
|
43
|
+
return preservingCleanup(() => use(lease.environment), lease.close);
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { jsxs as C, jsx as v } from "react/jsx-runtime";
|
|
2
|
-
import { useRef as i, useState as H, useCallback as S, useEffect as p } from "react";
|
|
3
|
-
import { u as $ } from "./index-BBtBPnTb.js";
|
|
4
|
-
import "@iota-uz/sdk/client-host";
|
|
5
|
-
function U({ input: o, panelId: E, onSelect: N, onHover: R, adapter: u, label: j, drillable: b = !1, resetZoomKey: g = 0 }) {
|
|
6
|
-
const d = i(null), t = i(), h = i(o), f = i({ onSelect: N, onHover: R }), [m, c] = H(), w = $();
|
|
7
|
-
h.current = o, f.current = { onSelect: N, onHover: R };
|
|
8
|
-
const s = S((e, a) => {
|
|
9
|
-
const r = e instanceof Error ? e : new Error(a);
|
|
10
|
-
return console.error(`[lens] chart panel ${E ?? "(unknown)"} failed to render`, r), r;
|
|
11
|
-
}, [E]);
|
|
12
|
-
return p(() => {
|
|
13
|
-
let e = !0;
|
|
14
|
-
const a = {
|
|
15
|
-
onSelect: (r, n, l) => {
|
|
16
|
-
var k, x;
|
|
17
|
-
return (x = (k = f.current).onSelect) == null ? void 0 : x.call(k, r, n, l);
|
|
18
|
-
},
|
|
19
|
-
onHover: (r) => {
|
|
20
|
-
var n, l;
|
|
21
|
-
return (l = (n = f.current).onHover) == null ? void 0 : l.call(n, r);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
return (u ? Promise.resolve(u) : import("./index-CmXDbBaF.js").then(({ getChartAdapter: r }) => r(h.current.kind))).then((r) => {
|
|
25
|
-
if (!(!e || !d.current)) {
|
|
26
|
-
c(void 0);
|
|
27
|
-
try {
|
|
28
|
-
t.current = r.mount(d.current, h.current, a);
|
|
29
|
-
} catch (n) {
|
|
30
|
-
c(s(n, "chart failed to render"));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}).catch((r) => {
|
|
34
|
-
e && c(s(r, "chart adapter failed to load"));
|
|
35
|
-
}), () => {
|
|
36
|
-
var r;
|
|
37
|
-
e = !1, (r = t.current) == null || r.dispose(), t.current = void 0;
|
|
38
|
-
};
|
|
39
|
-
}, [u, s]), p(() => {
|
|
40
|
-
if (t.current)
|
|
41
|
-
try {
|
|
42
|
-
t.current.update(o);
|
|
43
|
-
} catch (e) {
|
|
44
|
-
c(s(e, "chart failed to update"));
|
|
45
|
-
}
|
|
46
|
-
}, [o, s]), p(() => {
|
|
47
|
-
var e, a;
|
|
48
|
-
g > 0 && ((a = (e = t.current) == null ? void 0 : e.resetZoom) == null || a.call(e));
|
|
49
|
-
}, [g]), /* @__PURE__ */ C(
|
|
50
|
-
"div",
|
|
51
|
-
{
|
|
52
|
-
className: `lens-chart-host${b ? " lens-chart-host-drillable" : ""}`,
|
|
53
|
-
"aria-label": j,
|
|
54
|
-
role: "img",
|
|
55
|
-
"data-drillable": b || void 0,
|
|
56
|
-
children: [
|
|
57
|
-
/* @__PURE__ */ v("div", { ref: d, className: "lens-chart-canvas" }),
|
|
58
|
-
m && /* @__PURE__ */ C("div", { className: "lens-chart-load-error", role: "alert", children: [
|
|
59
|
-
/* @__PURE__ */ v("span", { className: "lens-chart-load-error-message", children: w("chart.error", "Unable to render chart.") }),
|
|
60
|
-
m.message && /* @__PURE__ */ v("span", { className: "lens-chart-load-error-detail", children: m.message })
|
|
61
|
-
] })
|
|
62
|
-
]
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
export {
|
|
67
|
-
U as C
|
|
68
|
-
};
|