@domainkit/react 0.1.1 → 0.3.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/index.mjs CHANGED
@@ -1,8 +1,34 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { Dialog } from "@base-ui/react/dialog";
3
- import { createContext, useCallback, useContext, useEffect, useId, useInsertionEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
3
+ import { RegistryProvider, useAtomSet, useAtomValue } from "@effect/atom-react";
4
+ import { Transport } from "domainkit";
5
+ import * as Data from "effect/Data";
6
+ import * as Effect from "effect/Effect";
7
+ import * as Atom from "effect/unstable/reactivity/Atom";
8
+ import { createContext, useCallback, useContext, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from "react";
4
9
  import { useRender } from "@base-ui/react/use-render";
5
10
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
11
+ import * as AsyncResult from "effect/unstable/reactivity/AsyncResult";
12
+ //#region src/atom.ts
13
+ const Failure = Data.taggedEnum();
14
+ const failureFromError = (error) => Failure.Failure({
15
+ message: error.message,
16
+ operation: error.operation,
17
+ retry: error.retry
18
+ });
19
+ const failureFromDefect = (operation, message) => Failure.Failure({
20
+ message,
21
+ operation,
22
+ retry: "safe"
23
+ });
24
+ const recordsIdentity = (records) => JSON.stringify(records.map(({ id, name, priority, type, value }) => ({
25
+ id,
26
+ name,
27
+ priority,
28
+ type,
29
+ value
30
+ })));
31
+ //#endregion
6
32
  //#region src/composition.tsx
7
33
  function usePart(defaultTagName, componentProps, state, internalProps) {
8
34
  const { className, render, style, ...externalProps } = componentProps;
@@ -81,6 +107,7 @@ const english = {
81
107
  cleaningDns: "Removing records…",
82
108
  connectProvider: () => "Connect",
83
109
  connected: (provider) => `${provider} connected`,
110
+ providerAvailable: (provider) => `${provider} manages DNS for this domain`,
84
111
  connecting: "Connecting…",
85
112
  close: "Close",
86
113
  detectingProvider: "Detecting DNS provider…",
@@ -128,7 +155,7 @@ function toStyle(theme = {}) {
128
155
  //#endregion
129
156
  //#region src/domain-kit.tsx
130
157
  var domain_kit_exports = /* @__PURE__ */ __exportAll({
131
- Root: () => Root$2,
158
+ Root: () => Root$6,
132
159
  useDomainKit: () => useDomainKit
133
160
  });
134
161
  const Context = createContext(null);
@@ -154,7 +181,8 @@ const usePortalContainer = (container) => {
154
181
  const getSnapshot = useCallback(() => resolvePortalContainer(container, ownerDocument), [container, ownerDocument]);
155
182
  return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
156
183
  };
157
- function Root$2({ children, colorScheme = "inherit", icons, marks = {}, messages, navigate = navigateInBrowser, portalContainer = null, theme, transport, ...props }) {
184
+ function Root$6({ children, colorScheme = "inherit", icons, marks = {}, messages, navigate = navigateInBrowser, portalContainer = null, theme, transport, ...props }) {
185
+ const runtime = useMemo(() => Atom.runtime(transport), [transport]);
158
186
  const themeStyle = toStyle(theme);
159
187
  const resolvedPortalContainer = usePortalContainer(portalContainer);
160
188
  const portalContainerRef = useMemo(() => ({ current: resolvedPortalContainer }), [resolvedPortalContainer]);
@@ -164,21 +192,21 @@ function Root$2({ children, colorScheme = "inherit", icons, marks = {}, messages
164
192
  "data-domainkit-root": "",
165
193
  style: themeStyle
166
194
  });
167
- return /* @__PURE__ */ jsx(Context.Provider, {
195
+ return /* @__PURE__ */ jsx(RegistryProvider, { children: /* @__PURE__ */ jsx(Context.Provider, {
168
196
  value: {
169
197
  colorScheme,
170
198
  marks,
171
199
  messages: merge(messages),
172
200
  navigate,
173
201
  portalContainer: portalContainerRef,
174
- themeStyle,
175
- transport
202
+ runtime,
203
+ themeStyle
176
204
  },
177
205
  children: /* @__PURE__ */ jsx(IconsProvider, {
178
206
  ...icons === void 0 ? {} : { icons },
179
207
  children: content
180
208
  })
181
- });
209
+ }) });
182
210
  }
183
211
  function useDomainKit() {
184
212
  const value = useContext(Context);
@@ -186,249 +214,221 @@ function useDomainKit() {
186
214
  return value;
187
215
  }
188
216
  //#endregion
189
- //#region src/request-state.ts
190
- function useController$4(identity, initial) {
191
- const currentIdentity = useRef(identity);
192
- const revision = useRef(0);
193
- const [snapshot, setSnapshot] = useState(() => ({
194
- identity,
195
- state: initial
196
- }));
197
- useInsertionEffect(() => {
198
- currentIdentity.current = identity;
199
- revision.current += 1;
200
- }, [identity]);
201
- useEffect(() => {
202
- setSnapshot({
203
- identity,
204
- state: initial
205
- });
206
- }, [identity]);
207
- return {
208
- begin: useCallback((state) => {
209
- const request = ++revision.current;
210
- setSnapshot({
211
- identity: currentIdentity.current,
212
- state
213
- });
214
- return request;
215
- }, []),
216
- commit: useCallback((request, state) => {
217
- if (revision.current !== request) return false;
218
- setSnapshot({
219
- identity: currentIdentity.current,
220
- state
221
- });
222
- return true;
223
- }, []),
224
- reset: useCallback((state) => {
225
- revision.current += 1;
226
- setSnapshot({
227
- identity: currentIdentity.current,
228
- state
229
- });
230
- }, []),
231
- state: snapshot.identity === identity ? snapshot.state : initial
217
+ //#region src/operations.tsx
218
+ var operations_exports = /* @__PURE__ */ __exportAll({
219
+ Item: () => Item,
220
+ Kind: () => Kind,
221
+ List: () => List,
222
+ Name: () => Name,
223
+ Priority: () => Priority$1,
224
+ Reason: () => Reason,
225
+ Record: () => Record,
226
+ Root: () => Root$5,
227
+ Type: () => Type,
228
+ Value: () => Value$1
229
+ });
230
+ function leafPart$1(defaultTagName, part) {
231
+ return function Leaf(props) {
232
+ return usePart(defaultTagName, props, {}, { "data-domainkit-part": part });
232
233
  };
233
234
  }
234
- const recordsIdentity = (records) => JSON.stringify(records.map((record) => [
235
- record.id,
236
- record.name,
237
- record.priority ?? null,
238
- record.type,
239
- record.value
240
- ]));
235
+ const Kind = leafPart$1("span", "operation-kind");
236
+ const Type = leafPart$1("strong", "operation-type");
237
+ const Record = leafPart$1("span", "operation-record");
238
+ const Name = leafPart$1("span", "operation-name");
239
+ const Value$1 = leafPart$1("code", "operation-value");
240
+ const Priority$1 = leafPart$1("span", "operation-priority");
241
+ const Reason = leafPart$1("span", "operation-reason");
242
+ function Item({ operation, ...props }) {
243
+ return usePart("li", props, { operation: operation._tag }, {
244
+ children: /* @__PURE__ */ jsxs(Fragment, { children: [
245
+ /* @__PURE__ */ jsx(Kind, { children: operation._tag }),
246
+ " ",
247
+ /* @__PURE__ */ jsx(Type, { children: operation.record.type }),
248
+ " ",
249
+ /* @__PURE__ */ jsxs(Record, { children: [
250
+ /* @__PURE__ */ jsx(Name, { children: operation.record.name }),
251
+ /* @__PURE__ */ jsx(Value$1, { children: operation.record.value }),
252
+ operation.record.priority === void 0 ? null : /* @__PURE__ */ jsxs(Priority$1, { children: ["Priority ", operation.record.priority] }),
253
+ "reason" in operation ? /* @__PURE__ */ jsx(Reason, { children: operation.reason }) : null
254
+ ] })
255
+ ] }),
256
+ "data-domainkit-part": "operation-item",
257
+ "data-operation": operation._tag
258
+ });
259
+ }
260
+ function Root$5({ count = 0, lifecycle, ...props }) {
261
+ return usePart("ul", props, {
262
+ count,
263
+ lifecycle
264
+ }, {
265
+ "data-domainkit-part": lifecycle === "provisioning" ? "plan-operations" : "cleanup-operations",
266
+ "data-lifecycle": lifecycle
267
+ });
268
+ }
269
+ function List({ lifecycle, operations, ...props }) {
270
+ return /* @__PURE__ */ jsx(Root$5, {
271
+ count: operations.length,
272
+ lifecycle,
273
+ ...props,
274
+ children: operations.map((operation) => /* @__PURE__ */ jsx(Item, { operation }, operation.id))
275
+ });
276
+ }
241
277
  //#endregion
242
278
  //#region src/cleanup.tsx
243
279
  var cleanup_exports = /* @__PURE__ */ __exportAll({
280
+ Command: () => Command$3,
281
+ Dialog: () => Dialog$3,
244
282
  Flow: () => Flow$3,
245
- useController: () => useController$3
283
+ Outcome: () => Outcome$2,
284
+ Root: () => Root$4,
285
+ State: () => State$3,
286
+ useController: () => useController$3,
287
+ useModel: () => useModel$3
246
288
  });
247
- function useController$3(connection, receiptId) {
248
- const { transport } = useDomainKit();
249
- const requestState = useController$4(`${connection.connectionId}:${connection.domain}:${receiptId}`, { _tag: "Idle" });
250
- const state = requestState.state;
251
- const plan = useCallback(async () => {
252
- const request = requestState.begin({ _tag: "Planning" });
253
- try {
254
- const result = await transport.cleanup.plan({
255
- connectionId: connection.connectionId,
256
- domain: connection.domain,
257
- receiptId
258
- });
259
- requestState.commit(request, result._tag === "CleanupPlan" ? {
260
- _tag: "Review",
261
- plan: result
262
- } : result);
263
- } catch (cause) {
264
- requestState.commit(request, toFailure(cause));
265
- }
289
+ const State$3 = Data.taggedEnum();
290
+ const Command$3 = Data.taggedEnum();
291
+ function useModel$3(connection, receiptId) {
292
+ const { runtime } = useDomainKit();
293
+ return useMemo(() => {
294
+ const state = Atom.make(State$3.Idle());
295
+ return {
296
+ command: runtime.fn()((command, get) => {
297
+ if (command._tag === "Dismiss") {
298
+ get.set(state, State$3.Idle());
299
+ return Effect.void;
300
+ }
301
+ if (command._tag === "Plan") {
302
+ get.set(state, State$3.Planning());
303
+ return Effect.flatMap(Transport.Service, (transport) => transport.cleanup.plan({
304
+ connectionId: connection.connectionId,
305
+ domain: connection.domain,
306
+ receiptId
307
+ })).pipe(Effect.tap((plan) => Effect.sync(() => get.set(state, State$3.Review({ plan })))), Effect.catch((error) => Effect.sync(() => get.set(state, failureFromError(error)))), Effect.asVoid);
308
+ }
309
+ const current = get(state);
310
+ if (current._tag !== "Review" || current.plan.operations.some((operation) => operation._tag === "Blocked")) return Effect.void;
311
+ const plan = current.plan;
312
+ get.set(state, State$3.Cleaning({ plan }));
313
+ return Effect.flatMap(Transport.Service, (transport) => transport.cleanup.apply({
314
+ connectionId: connection.connectionId,
315
+ domain: connection.domain,
316
+ planDigest: plan.digest,
317
+ receiptId
318
+ })).pipe(Effect.tap((result) => Effect.sync(() => get.set(state, result._tag === "Cleaned" ? State$3.Cleaned({ result }) : result._tag === "Partial" ? State$3.Partial({ result }) : result))), Effect.catch((error) => Effect.sync(() => get.set(state, failureFromError(error)))), Effect.asVoid);
319
+ }),
320
+ state
321
+ };
266
322
  }, [
267
323
  connection.connectionId,
268
324
  connection.domain,
269
325
  receiptId,
270
- requestState,
271
- transport
326
+ runtime
272
327
  ]);
328
+ }
329
+ function useController$3(connection, receiptId) {
330
+ const model = useModel$3(connection, receiptId);
331
+ const state = useAtomValue(model.state);
332
+ const execute = useAtomSet(model.command);
273
333
  return {
274
- apply: useCallback(async () => {
275
- if (state._tag !== "Review") return;
276
- const reviewedPlan = state.plan;
277
- if (reviewedPlan.operations.some((operation) => operation._tag === "Blocked")) return;
278
- const request = requestState.begin({
279
- _tag: "Cleaning",
280
- plan: reviewedPlan
281
- });
282
- try {
283
- const result = await transport.cleanup.apply({
284
- connectionId: connection.connectionId,
285
- domain: connection.domain,
286
- planDigest: reviewedPlan.digest,
287
- receiptId
288
- });
289
- requestState.commit(request, result._tag === "Cleaned" ? {
290
- _tag: "Cleaned",
291
- result
292
- } : result._tag === "Partial" ? {
293
- _tag: "Partial",
294
- result
295
- } : result);
296
- } catch (cause) {
297
- requestState.commit(request, toFailure(cause));
298
- }
299
- }, [
300
- connection.connectionId,
301
- connection.domain,
302
- receiptId,
303
- requestState,
304
- state,
305
- transport
306
- ]),
307
- dismiss: () => requestState.reset({ _tag: "Idle" }),
308
- plan,
334
+ apply: () => execute(Command$3.Apply()),
335
+ dismiss: () => execute(Command$3.Dismiss()),
336
+ plan: () => execute(Command$3.Plan()),
309
337
  state
310
338
  };
311
339
  }
312
- const toFailure = (cause) => ({
313
- _tag: "Failure",
314
- message: cause instanceof Error ? cause.message : "Domain cleanup failed",
315
- retry: "safe"
316
- });
317
- function Flow$3({ connection, receiptId, ...props }) {
318
- const controller = useController$3(connection, receiptId);
340
+ function Root$4({ status, ...props }) {
341
+ return usePart("div", props, { status }, {
342
+ "data-domainkit-part": "cleanup-flow",
343
+ "data-state": status
344
+ });
345
+ }
346
+ function Outcome$2({ state }) {
347
+ const { messages } = useDomainKit();
348
+ if (state._tag === "Cleaned") return /* @__PURE__ */ jsx("p", {
349
+ "data-domainkit-part": "flow-outcome",
350
+ "data-tone": "success",
351
+ children: messages.cleanupComplete
352
+ });
353
+ if (state._tag === "Partial" || state._tag === "Failure" || state._tag === "Stale") return /* @__PURE__ */ jsx("p", {
354
+ "data-domainkit-part": "flow-outcome",
355
+ "data-tone": "danger",
356
+ role: "alert",
357
+ children: state._tag === "Partial" ? messages.cleanupPartial : state.message
358
+ });
359
+ return null;
360
+ }
361
+ function Dialog$3({ controller }) {
319
362
  const { colorScheme, messages, portalContainer, themeStyle } = useDomainKit();
320
363
  const state = controller.state;
321
364
  const plan = state._tag === "Review" || state._tag === "Cleaning" ? state.plan : void 0;
322
- return usePart("div", props, { status: state._tag }, {
323
- children: /* @__PURE__ */ jsxs(Fragment, { children: [
324
- state._tag === "Cleaned" ? /* @__PURE__ */ jsx("p", {
325
- "data-domainkit-part": "flow-outcome",
326
- "data-tone": "success",
327
- children: messages.cleanupComplete
328
- }) : null,
329
- state._tag === "Partial" || state._tag === "Failure" || state._tag === "Stale" ? /* @__PURE__ */ jsx("p", {
330
- "data-domainkit-part": "flow-outcome",
331
- "data-tone": "danger",
332
- role: "alert",
333
- children: state._tag === "Partial" ? messages.cleanupPartial : state.message
334
- }) : null,
335
- /* @__PURE__ */ jsxs(Dialog.Root, {
336
- onOpenChange: (open) => {
337
- if (!open) controller.dismiss();
338
- },
339
- open: plan !== void 0,
340
- children: [/* @__PURE__ */ jsx(Dialog.Trigger, {
341
- "data-domainkit-part": "cleanup-trigger",
342
- disabled: state._tag === "Planning" || state._tag === "Cleaning",
343
- onClick: () => void controller.plan(),
344
- children: state._tag === "Planning" ? messages.planningCleanup : messages.reviewCleanup
345
- }), plan === void 0 ? null : /* @__PURE__ */ jsxs(Dialog.Portal, {
346
- container: portalContainer ?? void 0,
347
- children: [/* @__PURE__ */ jsx(Dialog.Backdrop, { "data-domainkit-part": "dialog-backdrop" }), /* @__PURE__ */ jsxs(Dialog.Popup, {
348
- "data-color-scheme": colorScheme,
349
- "data-domainkit-part": "cleanup-dialog",
350
- "data-domainkit-root": "",
351
- style: themeStyle,
352
- children: [
353
- /* @__PURE__ */ jsxs("div", {
354
- "data-domainkit-part": "dialog-header",
355
- children: [/* @__PURE__ */ jsxs("div", {
356
- "data-domainkit-part": "dialog-heading",
357
- children: [/* @__PURE__ */ jsx(Dialog.Title, {
358
- "data-domainkit-part": "dialog-title",
359
- children: messages.reviewCleanup
360
- }), /* @__PURE__ */ jsx(Dialog.Description, {
361
- "data-domainkit-part": "dialog-description",
362
- children: messages.cleanupConsent
363
- })]
364
- }), /* @__PURE__ */ jsx(Dialog.Close, {
365
- "aria-label": messages.close,
366
- "data-domainkit-part": "dialog-close",
367
- children: "×"
368
- })]
369
- }),
370
- /* @__PURE__ */ jsx("div", {
371
- "data-domainkit-part": "dialog-body",
372
- children: /* @__PURE__ */ jsx("ul", {
373
- "data-domainkit-part": "cleanup-operations",
374
- children: plan.operations.map((operation) => /* @__PURE__ */ jsxs("li", {
375
- "data-operation": operation._tag,
376
- children: [
377
- /* @__PURE__ */ jsx("span", {
378
- "data-domainkit-part": "operation-kind",
379
- children: operation._tag
380
- }),
381
- " ",
382
- /* @__PURE__ */ jsx("strong", {
383
- "data-domainkit-part": "operation-type",
384
- children: operation.record.type
385
- }),
386
- " ",
387
- /* @__PURE__ */ jsxs("span", {
388
- "data-domainkit-part": "operation-record",
389
- children: [
390
- /* @__PURE__ */ jsx("span", {
391
- "data-domainkit-part": "operation-name",
392
- children: operation.record.name
393
- }),
394
- /* @__PURE__ */ jsx("code", {
395
- "data-domainkit-part": "operation-value",
396
- children: operation.record.value
397
- }),
398
- operation.record.priority === void 0 ? null : /* @__PURE__ */ jsxs("span", {
399
- "data-domainkit-part": "operation-priority",
400
- children: ["Priority ", operation.record.priority]
401
- }),
402
- operation._tag === "Blocked" ? /* @__PURE__ */ jsx("span", {
403
- "data-domainkit-part": "operation-reason",
404
- children: operation.reason
405
- }) : null
406
- ]
407
- })
408
- ]
409
- }, operation.id))
410
- })
411
- }),
412
- /* @__PURE__ */ jsxs("div", {
413
- "data-domainkit-part": "dialog-footer",
414
- children: [/* @__PURE__ */ jsx(Dialog.Close, {
415
- "data-domainkit-part": "dialog-cancel",
416
- children: messages.cancel
417
- }), /* @__PURE__ */ jsx("button", {
418
- "data-domainkit-part": "cleanup-apply",
419
- disabled: state._tag === "Cleaning" || plan.operations.some((operation) => operation._tag === "Blocked"),
420
- onClick: () => void controller.apply(),
421
- type: "button",
422
- children: state._tag === "Cleaning" ? messages.cleaningDns : messages.applyCleanup
423
- })]
424
- })
425
- ]
426
- })]
427
- })]
428
- })
429
- ] }),
430
- "data-domainkit-part": "cleanup-flow",
431
- "data-state": state._tag
365
+ return /* @__PURE__ */ jsxs(Dialog.Root, {
366
+ onOpenChange: (open) => {
367
+ if (!open) controller.dismiss();
368
+ },
369
+ open: plan !== void 0,
370
+ children: [/* @__PURE__ */ jsx(Dialog.Trigger, {
371
+ "data-domainkit-part": "cleanup-trigger",
372
+ disabled: state._tag === "Planning" || state._tag === "Cleaning",
373
+ onClick: () => controller.plan(),
374
+ children: state._tag === "Planning" ? messages.planningCleanup : messages.reviewCleanup
375
+ }), plan === void 0 ? null : /* @__PURE__ */ jsxs(Dialog.Portal, {
376
+ container: portalContainer ?? void 0,
377
+ children: [/* @__PURE__ */ jsx(Dialog.Backdrop, { "data-domainkit-part": "dialog-backdrop" }), /* @__PURE__ */ jsxs(Dialog.Popup, {
378
+ "data-color-scheme": colorScheme,
379
+ "data-domainkit-part": "cleanup-dialog",
380
+ "data-domainkit-root": "",
381
+ style: themeStyle,
382
+ children: [
383
+ /* @__PURE__ */ jsxs("div", {
384
+ "data-domainkit-part": "dialog-header",
385
+ children: [/* @__PURE__ */ jsxs("div", {
386
+ "data-domainkit-part": "dialog-heading",
387
+ children: [/* @__PURE__ */ jsx(Dialog.Title, {
388
+ "data-domainkit-part": "dialog-title",
389
+ children: messages.reviewCleanup
390
+ }), /* @__PURE__ */ jsx(Dialog.Description, {
391
+ "data-domainkit-part": "dialog-description",
392
+ children: messages.cleanupConsent
393
+ })]
394
+ }), /* @__PURE__ */ jsx(Dialog.Close, {
395
+ "aria-label": messages.close,
396
+ "data-domainkit-part": "dialog-close",
397
+ children: "×"
398
+ })]
399
+ }),
400
+ /* @__PURE__ */ jsx("div", {
401
+ "data-domainkit-part": "dialog-body",
402
+ children: /* @__PURE__ */ jsx(List, {
403
+ lifecycle: "cleanup",
404
+ operations: plan.operations
405
+ })
406
+ }),
407
+ /* @__PURE__ */ jsxs("div", {
408
+ "data-domainkit-part": "dialog-footer",
409
+ children: [/* @__PURE__ */ jsx(Dialog.Close, {
410
+ "data-domainkit-part": "dialog-cancel",
411
+ children: messages.cancel
412
+ }), /* @__PURE__ */ jsx("button", {
413
+ "data-domainkit-part": "cleanup-apply",
414
+ disabled: state._tag === "Cleaning" || plan.operations.some((operation) => operation._tag === "Blocked"),
415
+ onClick: () => controller.apply(),
416
+ type: "button",
417
+ children: state._tag === "Cleaning" ? messages.cleaningDns : messages.applyCleanup
418
+ })]
419
+ })
420
+ ]
421
+ })]
422
+ })]
423
+ });
424
+ }
425
+ function Flow$3({ connection, receiptId, ...props }) {
426
+ const controller = useController$3(connection, receiptId);
427
+ const state = controller.state;
428
+ return /* @__PURE__ */ jsxs(Root$4, {
429
+ status: state._tag,
430
+ ...props,
431
+ children: [/* @__PURE__ */ jsx(Outcome$2, { state }), /* @__PURE__ */ jsx(Dialog$3, { controller })]
432
432
  });
433
433
  }
434
434
  //#endregion
@@ -531,139 +531,128 @@ function Mark({ provider, ...props }) {
531
531
  //#endregion
532
532
  //#region src/connection.tsx
533
533
  var connection_exports = /* @__PURE__ */ __exportAll({
534
- Dialog: () => Dialog$1,
534
+ Command: () => Command$2,
535
+ ConnectTrigger: () => ConnectTrigger,
536
+ Dialog: () => Dialog$2,
535
537
  DisconnectAction: () => DisconnectAction,
538
+ DisconnectState: () => DisconnectState,
536
539
  Flow: () => Flow$2,
537
540
  OAuthAction: () => OAuthAction,
538
- RetryAction: () => RetryAction,
541
+ RetryAction: () => RetryAction$1,
539
542
  ReuseAction: () => ReuseAction,
540
- Root: () => Root$1,
543
+ Root: () => Root$3,
544
+ State: () => State$2,
541
545
  Status: () => Status$2,
542
546
  TokenAction: () => TokenAction,
543
547
  Trigger: () => Trigger,
544
548
  useController: () => useController$2,
545
- useDisconnect: () => useDisconnect
549
+ useDisconnect: () => useDisconnect,
550
+ useModel: () => useModel$2
546
551
  });
547
- const failure$1 = (cause) => ({
548
- _tag: "Failure",
549
- message: cause instanceof Error ? cause.message : "The connection request failed",
550
- retry: "safe"
551
- });
552
- function useController$2(domain) {
553
- const { navigate, transport } = useDomainKit();
554
- const [attempt, setAttempt] = useState(0);
555
- const [state, setState] = useState({ _tag: "Loading" });
556
- const activeRequest = useRef(0);
557
- useEffect(() => {
558
- const request = ++activeRequest.current;
559
- setState({ _tag: "Loading" });
560
- transport.connection.inspect({ domain }).then((snapshot) => {
561
- if (activeRequest.current === request) setState(snapshot);
562
- }, (cause) => {
563
- if (activeRequest.current === request) setState(failure$1(cause));
552
+ const State$2 = Data.taggedEnum();
553
+ const Command$2 = Data.taggedEnum();
554
+ function useModel$2(domain) {
555
+ const { navigate, runtime } = useDomainKit();
556
+ return useMemo(() => {
557
+ const actionState = Atom.make(void 0);
558
+ const inspect = runtime.atom(Effect.flatMap(Transport.Service, (transport) => transport.connection.inspect({ domain })));
559
+ const state = Atom.make((get) => {
560
+ const action = get(actionState);
561
+ if (action !== void 0) return action;
562
+ const inspection = get(inspect);
563
+ return AsyncResult.matchWithError(inspection, {
564
+ onDefect: () => failureFromDefect("connection.inspect", "Provider detection failed"),
565
+ onError: failureFromError,
566
+ onInitial: () => State$2.Loading(),
567
+ onSuccess: ({ value }) => value
568
+ });
564
569
  });
565
- return () => {
566
- if (activeRequest.current === request) activeRequest.current += 1;
570
+ return {
571
+ command: runtime.fn()((input, get) => {
572
+ if (input._tag === "Retry") {
573
+ get.set(actionState, void 0);
574
+ get.refresh(inspect);
575
+ return Effect.void;
576
+ }
577
+ const snapshot = get(state);
578
+ if (snapshot._tag !== "Disconnected") return Effect.void;
579
+ const reusableConnection = snapshot.reusableConnection;
580
+ if (input._tag === "Reuse" && reusableConnection === void 0) return Effect.void;
581
+ get.set(actionState, State$2.Submitting({ snapshot }));
582
+ const complete = (request) => request.pipe(Effect.tap((result) => Effect.sync(() => {
583
+ if (result._tag === "Redirect") {
584
+ get.set(actionState, State$2.Redirecting({ snapshot }));
585
+ navigate(result.authorizationUrl);
586
+ } else get.set(actionState, result);
587
+ })), Effect.catch((error) => Effect.sync(() => get.set(actionState, failureFromError(error)))), Effect.asVoid);
588
+ if (input._tag === "Connect") return complete(Effect.flatMap(Transport.Service, (transport) => transport.connection.connect({
589
+ domain,
590
+ method: input.method,
591
+ providerId: snapshot.provider.id
592
+ })));
593
+ if (reusableConnection === void 0) return Effect.void;
594
+ return complete(Effect.flatMap(Transport.Service, (transport) => transport.connection.reuse({
595
+ connectionId: reusableConnection.connectionId,
596
+ domain
597
+ })));
598
+ }),
599
+ state
567
600
  };
568
601
  }, [
569
- attempt,
570
602
  domain,
571
- transport
603
+ navigate,
604
+ runtime
572
605
  ]);
606
+ }
607
+ function useController$2(domain) {
608
+ const model = useModel$2(domain);
609
+ const state = useAtomValue(model.state);
610
+ const execute = useAtomSet(model.command);
573
611
  return {
574
- connect: useCallback(async (method, token, parameters) => {
575
- if (state._tag !== "Disconnected") return;
576
- const request = ++activeRequest.current;
577
- const snapshot = state;
578
- setState({
579
- _tag: "Submitting",
580
- snapshot
581
- });
582
- try {
583
- const result = await transport.connection.connect({
584
- domain,
585
- method,
586
- ...parameters === void 0 ? {} : { parameters },
587
- providerId: snapshot.provider.id,
588
- ...token === void 0 ? {} : { token }
589
- });
590
- if (activeRequest.current !== request) return;
591
- if (result._tag === "Redirect") {
592
- setState({
593
- _tag: "Redirecting",
594
- snapshot
595
- });
596
- navigate(result.authorizationUrl);
597
- return;
598
- }
599
- setState(result);
600
- } catch (cause) {
601
- if (activeRequest.current === request) setState(failure$1(cause));
602
- }
603
- }, [
604
- domain,
605
- navigate,
606
- state,
607
- transport
608
- ]),
609
- retry: () => setAttempt((current) => current + 1),
610
- reuse: useCallback(async () => {
611
- if (state._tag !== "Disconnected" || state.reusableConnection === void 0) return;
612
- const request = ++activeRequest.current;
613
- const snapshot = state;
614
- const reusableConnection = state.reusableConnection;
615
- setState({
616
- _tag: "Submitting",
617
- snapshot
618
- });
619
- try {
620
- const result = await transport.connection.reuse({
621
- connectionId: reusableConnection.connectionId,
622
- domain
623
- });
624
- if (activeRequest.current === request) setState(result);
625
- } catch (cause) {
626
- if (activeRequest.current === request) setState(failure$1(cause));
627
- }
628
- }, [
629
- domain,
630
- state,
631
- transport
632
- ]),
612
+ connect: (method) => execute(Command$2.Connect({ method })),
613
+ retry: () => execute(Command$2.Retry()),
614
+ reuse: () => execute(Command$2.Reuse()),
633
615
  state
634
616
  };
635
617
  }
636
- function Root$1({ children, status = "Loading", ...props }) {
618
+ function Root$3({ children, status = "Loading", ...props }) {
637
619
  return usePart("div", props, { status }, {
638
620
  children,
639
621
  "data-domainkit-part": "connection-root"
640
622
  });
641
623
  }
642
- function Status$2({ state, ...props }) {
624
+ function Status$2({ children, state, ...props }) {
643
625
  const { messages } = useDomainKit();
644
- const text = state._tag === "Loading" ? messages.detectingProvider : state._tag === "Connected" ? messages.connected(state.provider.name) : state._tag === "Unsupported" ? messages.automaticUnavailable : state._tag === "Failure" ? state.message : state._tag === "Redirecting" ? messages.openingAuthorization : state._tag === "Submitting" ? messages.connecting : `${state.provider.name} is available`;
626
+ const text = state._tag === "Loading" ? messages.detectingProvider : state._tag === "Connected" ? messages.connected(state.provider.name) : state._tag === "Unsupported" ? messages.automaticUnavailable : state._tag === "Failure" ? state.message : state._tag === "Redirecting" ? messages.openingAuthorization : state._tag === "Submitting" ? messages.connecting : messages.providerAvailable(state.provider.name);
645
627
  return usePart("div", props, { status: state._tag }, {
646
- children: text,
628
+ children: children ?? text,
647
629
  "data-domainkit-part": "connection-status",
648
630
  "data-state": state._tag
649
631
  });
650
632
  }
651
- function Trigger({ provider, ...props }) {
652
- const { messages } = useDomainKit();
653
- return /* @__PURE__ */ jsxs(Dialog.Trigger, {
633
+ function Trigger({ children, ...props }) {
634
+ return /* @__PURE__ */ jsx(Dialog.Trigger, {
654
635
  "data-domainkit-part": "connection-trigger",
655
636
  ...props,
656
- children: [/* @__PURE__ */ jsx(Mark, {
637
+ children
638
+ });
639
+ }
640
+ function ConnectTrigger({ children, provider, ...props }) {
641
+ const { messages } = useDomainKit();
642
+ return /* @__PURE__ */ jsx(Trigger, {
643
+ ...props,
644
+ "data-domainkit-recipe": "connect",
645
+ children: children ?? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Mark, {
657
646
  "aria-hidden": "true",
658
647
  provider
659
- }), messages.connectProvider(provider.name)]
648
+ }), messages.connectProvider(provider.name)] })
660
649
  });
661
650
  }
662
651
  function OAuthAction({ controller, label, ...props }) {
663
652
  return usePart("button", props, { authentication: "oauth" }, {
664
653
  children: label,
665
654
  "data-domainkit-part": "oauth-connect",
666
- onClick: () => void controller.connect("oauth"),
655
+ onClick: () => controller.connect(Transport.Method.OAuth()),
667
656
  type: "button"
668
657
  });
669
658
  }
@@ -683,7 +672,10 @@ function TokenAction({ controller, method, ...props }) {
683
672
  event.preventDefault();
684
673
  if (token.length > 0) {
685
674
  const populated = Object.fromEntries(Object.entries(parameters).filter(([, value]) => value.length > 0));
686
- controller.connect("token", token, Object.keys(populated).length === 0 ? void 0 : populated);
675
+ controller.connect(Transport.Method.Token({
676
+ token,
677
+ ...Object.keys(populated).length === 0 ? {} : { parameters: populated }
678
+ }));
687
679
  }
688
680
  };
689
681
  const missingRequiredParameter = method.parameters?.some((parameter) => parameter.required === true && !parameters[parameter.key]);
@@ -725,7 +717,7 @@ function TokenAction({ controller, method, ...props }) {
725
717
  onSubmit: submit
726
718
  });
727
719
  }
728
- function Dialog$1({ controller, snapshot }) {
720
+ function Dialog$2({ controller, snapshot }) {
729
721
  const { colorScheme, messages, portalContainer, themeStyle } = useDomainKit();
730
722
  return /* @__PURE__ */ jsxs(Dialog.Portal, {
731
723
  container: portalContainer,
@@ -788,23 +780,23 @@ function Flow$2({ domain, ...props }) {
788
780
  const controller = useController$2(domain);
789
781
  const state = controller.state;
790
782
  const snapshot = state._tag === "Disconnected" ? state : state._tag === "Submitting" || state._tag === "Redirecting" ? state.snapshot : void 0;
791
- return /* @__PURE__ */ jsxs(Root$1, {
783
+ return /* @__PURE__ */ jsxs(Root$3, {
792
784
  ...props,
793
785
  status: state._tag,
794
786
  children: [
795
787
  /* @__PURE__ */ jsx(Status$2, { state }),
796
- state._tag === "Failure" && state.retry !== "never" ? /* @__PURE__ */ jsx(RetryAction, {
788
+ state._tag === "Failure" && state.retry !== "never" ? /* @__PURE__ */ jsx(RetryAction$1, {
797
789
  controller,
798
790
  kind: state.retry === "after-user-action" ? "after-user-action" : "retry"
799
791
  }) : null,
800
- snapshot === void 0 ? null : /* @__PURE__ */ jsxs(Dialog.Root, { children: [/* @__PURE__ */ jsx(Trigger, { provider: snapshot.provider }), /* @__PURE__ */ jsx(Dialog$1, {
792
+ snapshot === void 0 ? null : /* @__PURE__ */ jsxs(Dialog.Root, { children: [/* @__PURE__ */ jsx(ConnectTrigger, { provider: snapshot.provider }), /* @__PURE__ */ jsx(Dialog$2, {
801
793
  controller,
802
794
  snapshot
803
795
  })] })
804
796
  ]
805
797
  });
806
798
  }
807
- function RetryAction({ controller, kind = "retry", ...props }) {
799
+ function RetryAction$1({ controller, kind = "retry", ...props }) {
808
800
  const { messages } = useDomainKit();
809
801
  return usePart("button", props, { status: "Failure" }, {
810
802
  children: kind === "after-user-action" ? messages.checkAgain : messages.retry,
@@ -813,28 +805,32 @@ function RetryAction({ controller, kind = "retry", ...props }) {
813
805
  type: "button"
814
806
  });
815
807
  }
808
+ const DisconnectState = Data.taggedEnum();
816
809
  function useDisconnect(connection) {
817
- const { transport } = useDomainKit();
818
- const requestState = useController$4(`${connection.connectionId}:${connection.domain}:disconnect`, { _tag: "Idle" });
819
- return {
820
- disconnect: useCallback(async () => {
821
- const request = requestState.begin({ _tag: "Disconnecting" });
822
- try {
823
- requestState.commit(request, await transport.connection.removeDomain({
810
+ const { runtime } = useDomainKit();
811
+ const controller = useMemo(() => {
812
+ const state = Atom.make(DisconnectState.Idle());
813
+ return {
814
+ disconnect: runtime.fn()((_, get) => {
815
+ get.set(state, DisconnectState.Disconnecting());
816
+ return Effect.flatMap(Transport.Service, (transport) => transport.connection.removeDomain({
824
817
  connectionId: connection.connectionId,
825
818
  domain: connection.domain,
826
819
  preserveDns: true
827
- }));
828
- } catch (cause) {
829
- requestState.commit(request, failure$1(cause));
830
- }
831
- }, [
832
- connection.connectionId,
833
- connection.domain,
834
- requestState,
835
- transport
836
- ]),
837
- state: requestState.state
820
+ })).pipe(Effect.tap((result) => Effect.sync(() => get.set(state, result))), Effect.catch((error) => Effect.sync(() => get.set(state, failureFromError(error)))), Effect.asVoid);
821
+ }),
822
+ state
823
+ };
824
+ }, [
825
+ connection.connectionId,
826
+ connection.domain,
827
+ runtime
828
+ ]);
829
+ const state = useAtomValue(controller.state);
830
+ const disconnect = useAtomSet(controller.disconnect);
831
+ return {
832
+ disconnect: () => disconnect(),
833
+ state
838
834
  };
839
835
  }
840
836
  function DisconnectAction({ connection, ...props }) {
@@ -880,13 +876,16 @@ var records_exports = /* @__PURE__ */ __exportAll({
880
876
  Head: () => Head,
881
877
  Header: () => Header,
882
878
  Priority: () => Priority,
883
- Root: () => Root,
879
+ Root: () => Root$2,
884
880
  Row: () => Row,
885
881
  Status: () => Status$1,
886
882
  Table: () => Table,
887
883
  Value: () => Value,
888
884
  ZoneFile: () => ZoneFile,
889
- toZoneFile: () => toZoneFile
885
+ copyText: () => copyText,
886
+ downloadZoneFile: () => downloadZoneFile,
887
+ toZoneFile: () => toZoneFile,
888
+ useCopy: () => useCopy
890
889
  });
891
890
  const copyText = (value) => {
892
891
  if (typeof navigator === "undefined" || navigator.clipboard === void 0) return Promise.resolve(false);
@@ -952,23 +951,31 @@ function leafPart(defaultTagName, part) {
952
951
  return usePart(defaultTagName, props, {}, { "data-domainkit-part": part });
953
952
  };
954
953
  }
955
- function CopyValue({ copiedIcon, copiedLabel = "Copied", copyIcon, copyLabel = "Copy", value, ...props }) {
956
- const icons = useIcons();
954
+ function useCopy(value, resetAfter = 2e3) {
957
955
  const [copied, setCopied] = useState(false);
958
956
  const reset = useRef(void 0);
959
957
  useEffect(() => () => clearTimeout(reset.current), []);
958
+ return {
959
+ copied,
960
+ copy: () => {
961
+ copyText(value).then((ok) => {
962
+ if (!ok) return;
963
+ setCopied(true);
964
+ clearTimeout(reset.current);
965
+ reset.current = setTimeout(() => setCopied(false), resetAfter);
966
+ });
967
+ }
968
+ };
969
+ }
970
+ function CopyValue({ copiedIcon, copiedLabel = "Copied", copyIcon, copyLabel = "Copy", value, ...props }) {
971
+ const icons = useIcons();
972
+ const controller = useCopy(value);
973
+ const copied = controller.copied;
960
974
  return usePart("span", props, { copied }, {
961
975
  children: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("code", { children: value }), /* @__PURE__ */ jsxs("button", {
962
976
  "aria-label": `${copied ? copiedLabel : copyLabel} ${value}`,
963
977
  "data-domainkit-part": "copy-action",
964
- onClick: () => {
965
- copyText(value).then((ok) => {
966
- if (!ok) return;
967
- setCopied(true);
968
- clearTimeout(reset.current);
969
- reset.current = setTimeout(() => setCopied(false), 2e3);
970
- });
971
- },
978
+ onClick: controller.copy,
972
979
  type: "button",
973
980
  children: [/* @__PURE__ */ jsx("span", {
974
981
  "aria-hidden": "true",
@@ -990,22 +997,13 @@ function CopyValue({ copiedIcon, copiedLabel = "Copied", copyIcon, copyLabel = "
990
997
  }
991
998
  function ZoneFile({ copiedIcon, copiedLabel = "Copied", copyIcon, copyLabel = "Copy zone", domain, downloadIcon, downloadLabel = "Download", records, ...props }) {
992
999
  const icons = useIcons();
993
- const [copied, setCopied] = useState(false);
994
- const reset = useRef(void 0);
995
- const zone = toZoneFile(records);
996
- useEffect(() => () => clearTimeout(reset.current), []);
1000
+ const controller = useCopy(toZoneFile(records));
1001
+ const copied = controller.copied;
997
1002
  return usePart("div", props, { count: records.length }, {
998
1003
  children: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("button", {
999
1004
  "aria-label": copied ? copiedLabel : copyLabel,
1000
1005
  "data-domainkit-part": "zone-copy",
1001
- onClick: () => {
1002
- copyText(zone).then((ok) => {
1003
- if (!ok) return;
1004
- setCopied(true);
1005
- clearTimeout(reset.current);
1006
- reset.current = setTimeout(() => setCopied(false), 2e3);
1007
- });
1008
- },
1006
+ onClick: controller.copy,
1009
1007
  type: "button",
1010
1008
  children: [/* @__PURE__ */ jsx("span", {
1011
1009
  "aria-hidden": "true",
@@ -1014,7 +1012,7 @@ function ZoneFile({ copiedIcon, copiedLabel = "Copied", copyIcon, copyLabel = "C
1014
1012
  }), copied ? copiedLabel : copyLabel]
1015
1013
  }), /* @__PURE__ */ jsxs("button", {
1016
1014
  "data-domainkit-part": "zone-download",
1017
- onClick: () => downloadText(`${domain}.txt`, zone),
1015
+ onClick: () => downloadZoneFile(domain, records),
1018
1016
  type: "button",
1019
1017
  children: [/* @__PURE__ */ jsx("span", {
1020
1018
  "aria-hidden": "true",
@@ -1049,7 +1047,7 @@ const Value = leafPart("span", "record-value");
1049
1047
  const CardHeader = leafPart("div", "record-card-head");
1050
1048
  const CardTitle = leafPart("strong", "record-card-title");
1051
1049
  const CardContent = leafPart("dl", "record-card-content");
1052
- function Root({ count = 0, ...props }) {
1050
+ function Root$2({ count = 0, ...props }) {
1053
1051
  return /* @__PURE__ */ jsx("div", {
1054
1052
  "data-domainkit-part": "records-panel",
1055
1053
  children: usePart("table", props, { count }, { "data-domainkit-part": "records-table" })
@@ -1072,7 +1070,7 @@ function Card({ copiedIcon, copyIcon, evidence, record, ...props }) {
1072
1070
  }
1073
1071
  function Table({ copiedIcon, copyIcon, evidence, records, ...props }) {
1074
1072
  const status = evidence !== void 0;
1075
- return /* @__PURE__ */ jsxs(Root, {
1073
+ return /* @__PURE__ */ jsxs(Root$2, {
1076
1074
  count: records.length,
1077
1075
  ...props,
1078
1076
  children: [/* @__PURE__ */ jsx(Header, { children: /* @__PURE__ */ jsxs(Row, { children: [
@@ -1113,257 +1111,251 @@ function Table({ copiedIcon, copyIcon, evidence, records, ...props }) {
1113
1111
  });
1114
1112
  }
1115
1113
  const toZoneFile = (records) => `${records.map((record) => `${absoluteDomainName(record.name)} IN ${record.type} ${record.priority === void 0 ? "" : `${record.priority} `}${zoneValue(record)}`).join("\n")}\n`;
1114
+ const downloadZoneFile = (domain, records) => downloadText(`${domain}.txt`, toZoneFile(records));
1116
1115
  //#endregion
1117
1116
  //#region src/provisioning.tsx
1118
1117
  var provisioning_exports = /* @__PURE__ */ __exportAll({
1118
+ Command: () => Command$1,
1119
+ Dialog: () => Dialog$1,
1119
1120
  Flow: () => Flow$1,
1120
- OperationList: () => OperationList,
1121
- useController: () => useController$1
1122
- });
1123
- const failure = (cause) => ({
1124
- _tag: "Failure",
1125
- message: cause instanceof Error ? cause.message : "DNS provisioning failed",
1126
- retry: "safe"
1121
+ Outcome: () => Outcome$1,
1122
+ RetryAction: () => RetryAction,
1123
+ Root: () => Root$1,
1124
+ State: () => State$1,
1125
+ useController: () => useController$1,
1126
+ useModel: () => useModel$1
1127
1127
  });
1128
- function useController$1(connection, records, onApplied) {
1129
- const { transport } = useDomainKit();
1130
- const requestState = useController$4(`${connection.connectionId}:${connection.domain}:${recordsIdentity(records)}`, { _tag: "Idle" });
1131
- const state = requestState.state;
1132
- const plan = useCallback(async () => {
1133
- const request = requestState.begin({ _tag: "Planning" });
1134
- try {
1135
- const result = await transport.provisioning.plan({
1136
- connectionId: connection.connectionId,
1137
- domain: connection.domain,
1138
- records
1139
- });
1140
- requestState.commit(request, result._tag === "Plan" ? {
1141
- _tag: "Review",
1142
- plan: result
1143
- } : result);
1144
- } catch (cause) {
1145
- requestState.commit(request, failure(cause));
1146
- }
1128
+ const State$1 = Data.taggedEnum();
1129
+ const Command$1 = Data.taggedEnum();
1130
+ function useModel$1(connection, records, onApplied) {
1131
+ const { runtime } = useDomainKit();
1132
+ const recordKey = recordsIdentity(records);
1133
+ const onAppliedRef = useRef(onApplied);
1134
+ onAppliedRef.current = onApplied;
1135
+ return useMemo(() => {
1136
+ const state = Atom.make(State$1.Idle());
1137
+ return {
1138
+ command: runtime.fn()((command, get) => {
1139
+ if (command._tag === "Dismiss") {
1140
+ get.set(state, State$1.Idle());
1141
+ return Effect.void;
1142
+ }
1143
+ if (command._tag === "Plan") {
1144
+ get.set(state, State$1.Planning());
1145
+ return Effect.flatMap(Transport.Service, (transport) => transport.provisioning.plan({
1146
+ connectionId: connection.connectionId,
1147
+ domain: connection.domain,
1148
+ records
1149
+ })).pipe(Effect.tap((plan) => Effect.sync(() => get.set(state, State$1.Review({ plan })))), Effect.catch((error) => Effect.sync(() => get.set(state, failureFromError(error)))), Effect.asVoid);
1150
+ }
1151
+ const current = get(state);
1152
+ if (current._tag !== "Review" || current.plan.operations.some((operation) => operation._tag === "Conflict")) return Effect.void;
1153
+ const plan = current.plan;
1154
+ get.set(state, State$1.Applying({ plan }));
1155
+ return Effect.flatMap(Transport.Service, (transport) => transport.provisioning.apply({
1156
+ connectionId: connection.connectionId,
1157
+ domain: connection.domain,
1158
+ planDigest: plan.digest
1159
+ })).pipe(Effect.tap((result) => Effect.sync(() => {
1160
+ if (result._tag === "Applied") {
1161
+ get.set(state, State$1.Complete({ result }));
1162
+ onAppliedRef.current?.(result);
1163
+ } else if (result._tag === "Partial") {
1164
+ get.set(state, State$1.Partial({ result }));
1165
+ onAppliedRef.current?.(result);
1166
+ } else get.set(state, result);
1167
+ })), Effect.catch((error) => Effect.sync(() => get.set(state, failureFromError(error)))), Effect.asVoid);
1168
+ }),
1169
+ state
1170
+ };
1147
1171
  }, [
1148
1172
  connection.connectionId,
1149
1173
  connection.domain,
1150
- records,
1151
- requestState,
1152
- transport
1174
+ recordKey,
1175
+ runtime
1153
1176
  ]);
1177
+ }
1178
+ function useController$1(connection, records, onApplied) {
1179
+ const model = useModel$1(connection, records, onApplied);
1180
+ const state = useAtomValue(model.state);
1181
+ const execute = useAtomSet(model.command);
1154
1182
  return {
1155
- apply: useCallback(async () => {
1156
- if (state._tag !== "Review") return;
1157
- const reviewedPlan = state.plan;
1158
- if (reviewedPlan.operations.some((operation) => operation._tag === "Conflict")) return;
1159
- const request = requestState.begin({
1160
- _tag: "Applying",
1161
- plan: reviewedPlan
1162
- });
1163
- try {
1164
- const result = await transport.provisioning.apply({
1165
- connectionId: connection.connectionId,
1166
- domain: connection.domain,
1167
- planDigest: reviewedPlan.digest
1168
- });
1169
- if (result._tag === "Applied") {
1170
- if (requestState.commit(request, {
1171
- _tag: "Complete",
1172
- result
1173
- })) onApplied?.(result);
1174
- } else if (result._tag === "Partial") {
1175
- if (requestState.commit(request, {
1176
- _tag: "Partial",
1177
- result
1178
- })) onApplied?.(result);
1179
- } else requestState.commit(request, result);
1180
- } catch (cause) {
1181
- requestState.commit(request, failure(cause));
1182
- }
1183
- }, [
1184
- connection.connectionId,
1185
- connection.domain,
1186
- onApplied,
1187
- requestState,
1188
- state,
1189
- transport
1190
- ]),
1191
- dismiss: () => requestState.reset({ _tag: "Idle" }),
1192
- plan,
1193
- retry: plan,
1183
+ apply: () => execute(Command$1.Apply()),
1184
+ dismiss: () => execute(Command$1.Dismiss()),
1185
+ plan: () => execute(Command$1.Plan()),
1186
+ retry: () => execute(Command$1.Plan()),
1194
1187
  state
1195
1188
  };
1196
1189
  }
1197
- function Flow$1({ connection, onApplied, records, showRecords = true, ...props }) {
1198
- const controller = useController$1(connection, records, onApplied);
1190
+ function Root$1({ status, ...props }) {
1191
+ return usePart("div", props, { status }, {
1192
+ "data-domainkit-part": "provisioning-flow",
1193
+ "data-state": status
1194
+ });
1195
+ }
1196
+ function Outcome$1({ state }) {
1197
+ const { messages } = useDomainKit();
1198
+ if (state._tag === "Complete") return /* @__PURE__ */ jsx("p", {
1199
+ "data-domainkit-part": "flow-outcome",
1200
+ "data-tone": "success",
1201
+ children: messages.recordsApplied
1202
+ });
1203
+ if (state._tag === "Partial" || state._tag === "Failure" || state._tag === "Stale") return /* @__PURE__ */ jsx("p", {
1204
+ "data-domainkit-part": "flow-outcome",
1205
+ "data-tone": "danger",
1206
+ role: "alert",
1207
+ children: state._tag === "Partial" ? messages.recordsPartiallyApplied : state.message
1208
+ });
1209
+ return null;
1210
+ }
1211
+ function Dialog$1({ controller }) {
1199
1212
  const { colorScheme, messages, portalContainer, themeStyle } = useDomainKit();
1200
1213
  const state = controller.state;
1201
1214
  const plan = state._tag === "Review" || state._tag === "Applying" ? state.plan : void 0;
1202
- return usePart("div", props, { status: state._tag }, {
1203
- children: /* @__PURE__ */ jsxs(Fragment, { children: [
1204
- showRecords ? /* @__PURE__ */ jsx(Table, { records }) : null,
1205
- state._tag === "Complete" ? /* @__PURE__ */ jsx("p", {
1206
- "data-domainkit-part": "flow-outcome",
1207
- "data-tone": "success",
1208
- children: messages.recordsApplied
1209
- }) : null,
1210
- state._tag === "Partial" ? /* @__PURE__ */ jsx("p", {
1211
- "data-domainkit-part": "flow-outcome",
1212
- "data-tone": "danger",
1213
- role: "alert",
1214
- children: messages.recordsPartiallyApplied
1215
- }) : null,
1216
- state._tag === "Failure" || state._tag === "Stale" ? /* @__PURE__ */ jsx("p", {
1217
- "data-domainkit-part": "flow-outcome",
1218
- "data-tone": "danger",
1219
- role: "alert",
1220
- children: state.message
1221
- }) : null,
1222
- /* @__PURE__ */ jsxs(Dialog.Root, {
1223
- onOpenChange: (open) => {
1224
- if (!open) controller.dismiss();
1225
- },
1226
- open: plan !== void 0,
1227
- children: [/* @__PURE__ */ jsx(Dialog.Trigger, {
1228
- "data-domainkit-part": "plan-trigger",
1229
- disabled: state._tag === "Planning" || state._tag === "Applying",
1230
- onClick: () => void controller.plan(),
1231
- children: state._tag === "Planning" ? messages.planningDns : messages.reviewDns
1232
- }), plan === void 0 ? null : /* @__PURE__ */ jsxs(Dialog.Portal, {
1233
- container: portalContainer ?? void 0,
1234
- children: [/* @__PURE__ */ jsx(Dialog.Backdrop, { "data-domainkit-part": "dialog-backdrop" }), /* @__PURE__ */ jsxs(Dialog.Popup, {
1235
- "data-color-scheme": colorScheme,
1236
- "data-domainkit-part": "plan-dialog",
1237
- "data-domainkit-root": "",
1238
- style: themeStyle,
1239
- children: [
1240
- /* @__PURE__ */ jsxs("div", {
1241
- "data-domainkit-part": "dialog-header",
1242
- children: [/* @__PURE__ */ jsxs("div", {
1243
- "data-domainkit-part": "dialog-heading",
1244
- children: [/* @__PURE__ */ jsx(Dialog.Title, {
1245
- "data-domainkit-part": "dialog-title",
1246
- children: messages.reviewDns
1247
- }), /* @__PURE__ */ jsx(Dialog.Description, {
1248
- "data-domainkit-part": "dialog-description",
1249
- children: messages.planConsent
1250
- })]
1251
- }), /* @__PURE__ */ jsx(Dialog.Close, {
1252
- "aria-label": messages.close,
1253
- "data-domainkit-part": "dialog-close",
1254
- children: "×"
1255
- })]
1256
- }),
1257
- /* @__PURE__ */ jsx("div", {
1258
- "data-domainkit-part": "dialog-body",
1259
- children: /* @__PURE__ */ jsx(OperationList, { plan })
1260
- }),
1261
- /* @__PURE__ */ jsxs("div", {
1262
- "data-domainkit-part": "dialog-footer",
1263
- children: [/* @__PURE__ */ jsx(Dialog.Close, {
1264
- "data-domainkit-part": "dialog-cancel",
1265
- children: messages.cancel
1266
- }), /* @__PURE__ */ jsx("button", {
1267
- "data-domainkit-part": "plan-apply",
1268
- disabled: state._tag === "Applying" || plan.operations.some((operation) => operation._tag === "Conflict"),
1269
- onClick: () => void controller.apply(),
1270
- type: "button",
1271
- children: state._tag === "Applying" ? messages.applyingDns : messages.applyDns
1272
- })]
1273
- })
1274
- ]
1275
- })]
1276
- })]
1277
- }),
1278
- state._tag === "Failure" || state._tag === "Stale" || state._tag === "Partial" ? /* @__PURE__ */ jsx("button", {
1279
- "data-domainkit-part": "provisioning-retry",
1280
- onClick: () => void controller.retry(),
1281
- type: "button",
1282
- children: messages.retry
1283
- }) : null
1284
- ] }),
1285
- "data-domainkit-part": "provisioning-flow",
1286
- "data-state": state._tag
1215
+ return /* @__PURE__ */ jsxs(Dialog.Root, {
1216
+ onOpenChange: (open) => {
1217
+ if (!open) controller.dismiss();
1218
+ },
1219
+ open: plan !== void 0,
1220
+ children: [/* @__PURE__ */ jsx(Dialog.Trigger, {
1221
+ "data-domainkit-part": "plan-trigger",
1222
+ disabled: state._tag === "Planning" || state._tag === "Applying",
1223
+ onClick: () => controller.plan(),
1224
+ children: state._tag === "Planning" ? messages.planningDns : messages.reviewDns
1225
+ }), plan === void 0 ? null : /* @__PURE__ */ jsxs(Dialog.Portal, {
1226
+ container: portalContainer ?? void 0,
1227
+ children: [/* @__PURE__ */ jsx(Dialog.Backdrop, { "data-domainkit-part": "dialog-backdrop" }), /* @__PURE__ */ jsxs(Dialog.Popup, {
1228
+ "data-color-scheme": colorScheme,
1229
+ "data-domainkit-part": "plan-dialog",
1230
+ "data-domainkit-root": "",
1231
+ style: themeStyle,
1232
+ children: [
1233
+ /* @__PURE__ */ jsxs("div", {
1234
+ "data-domainkit-part": "dialog-header",
1235
+ children: [/* @__PURE__ */ jsxs("div", {
1236
+ "data-domainkit-part": "dialog-heading",
1237
+ children: [/* @__PURE__ */ jsx(Dialog.Title, {
1238
+ "data-domainkit-part": "dialog-title",
1239
+ children: messages.reviewDns
1240
+ }), /* @__PURE__ */ jsx(Dialog.Description, {
1241
+ "data-domainkit-part": "dialog-description",
1242
+ children: messages.planConsent
1243
+ })]
1244
+ }), /* @__PURE__ */ jsx(Dialog.Close, {
1245
+ "aria-label": messages.close,
1246
+ "data-domainkit-part": "dialog-close",
1247
+ children: "×"
1248
+ })]
1249
+ }),
1250
+ /* @__PURE__ */ jsx("div", {
1251
+ "data-domainkit-part": "dialog-body",
1252
+ children: /* @__PURE__ */ jsx(List, {
1253
+ lifecycle: "provisioning",
1254
+ operations: plan.operations
1255
+ })
1256
+ }),
1257
+ /* @__PURE__ */ jsxs("div", {
1258
+ "data-domainkit-part": "dialog-footer",
1259
+ children: [/* @__PURE__ */ jsx(Dialog.Close, {
1260
+ "data-domainkit-part": "dialog-cancel",
1261
+ children: messages.cancel
1262
+ }), /* @__PURE__ */ jsx("button", {
1263
+ "data-domainkit-part": "plan-apply",
1264
+ disabled: state._tag === "Applying" || plan.operations.some((operation) => operation._tag === "Conflict"),
1265
+ onClick: () => controller.apply(),
1266
+ type: "button",
1267
+ children: state._tag === "Applying" ? messages.applyingDns : messages.applyDns
1268
+ })]
1269
+ })
1270
+ ]
1271
+ })]
1272
+ })]
1287
1273
  });
1288
1274
  }
1289
- function OperationList({ plan }) {
1290
- return /* @__PURE__ */ jsx("ul", {
1291
- "data-domainkit-part": "plan-operations",
1292
- children: plan.operations.map((operation) => /* @__PURE__ */ jsxs("li", {
1293
- "data-operation": operation._tag,
1294
- children: [
1295
- /* @__PURE__ */ jsx("span", {
1296
- "data-domainkit-part": "operation-kind",
1297
- children: operation._tag
1298
- }),
1299
- " ",
1300
- /* @__PURE__ */ jsx("strong", {
1301
- "data-domainkit-part": "operation-type",
1302
- children: operation.record.type
1303
- }),
1304
- " ",
1305
- /* @__PURE__ */ jsxs("span", {
1306
- "data-domainkit-part": "operation-record",
1307
- children: [
1308
- /* @__PURE__ */ jsx("span", {
1309
- "data-domainkit-part": "operation-name",
1310
- children: operation.record.name
1311
- }),
1312
- /* @__PURE__ */ jsx("code", {
1313
- "data-domainkit-part": "operation-value",
1314
- children: operation.record.value
1315
- }),
1316
- operation.record.priority === void 0 ? null : /* @__PURE__ */ jsxs("span", {
1317
- "data-domainkit-part": "operation-priority",
1318
- children: ["Priority ", operation.record.priority]
1319
- }),
1320
- operation._tag === "Conflict" ? /* @__PURE__ */ jsx("span", {
1321
- "data-domainkit-part": "operation-reason",
1322
- children: operation.reason
1323
- }) : null
1324
- ]
1325
- })
1326
- ]
1327
- }, operation.id))
1275
+ function RetryAction({ controller }) {
1276
+ const { messages } = useDomainKit();
1277
+ const state = controller.state;
1278
+ if (state._tag !== "Failure" && state._tag !== "Stale" && state._tag !== "Partial") return null;
1279
+ return /* @__PURE__ */ jsx("button", {
1280
+ "data-domainkit-part": "provisioning-retry",
1281
+ onClick: () => controller.retry(),
1282
+ type: "button",
1283
+ children: messages.retry
1284
+ });
1285
+ }
1286
+ function Flow$1({ connection, onApplied, records, showRecords = true, ...props }) {
1287
+ const controller = useController$1(connection, records, onApplied);
1288
+ const state = controller.state;
1289
+ return /* @__PURE__ */ jsxs(Root$1, {
1290
+ status: state._tag,
1291
+ ...props,
1292
+ children: [
1293
+ showRecords ? /* @__PURE__ */ jsx(Table, { records }) : null,
1294
+ /* @__PURE__ */ jsx(Outcome$1, { state }),
1295
+ /* @__PURE__ */ jsx(Dialog$1, { controller }),
1296
+ /* @__PURE__ */ jsx(RetryAction, { controller })
1297
+ ]
1328
1298
  });
1329
1299
  }
1330
1300
  //#endregion
1331
1301
  //#region src/verification.tsx
1332
1302
  var verification_exports = /* @__PURE__ */ __exportAll({
1303
+ Command: () => Command,
1304
+ Evidence: () => Evidence,
1305
+ ObserveAction: () => ObserveAction,
1306
+ Outcome: () => Outcome,
1307
+ Root: () => Root,
1308
+ State: () => State,
1333
1309
  Status: () => Status,
1334
- useController: () => useController
1310
+ useController: () => useController,
1311
+ useModel: () => useModel
1335
1312
  });
1336
- function useController(config) {
1337
- const { transport } = useDomainKit();
1338
- const sources = {
1339
- provider: config.sources?.provider ?? config.connection !== void 0,
1340
- publicDns: config.sources?.publicDns ?? true
1341
- };
1342
- const requestState = useController$4(`${config.connection?.connectionId ?? "public"}:${config.domain}:${sources.provider}:${sources.publicDns}:${recordsIdentity(config.records)}`, { _tag: "Idle" });
1343
- const state = requestState.state;
1344
- return {
1345
- observe: useCallback(async () => {
1346
- const request = requestState.begin({ _tag: "Observing" });
1347
- try {
1348
- requestState.commit(request, await transport.verification.observe({
1313
+ const State = Data.taggedEnum();
1314
+ const Command = Data.taggedEnum();
1315
+ function useModel(config) {
1316
+ const { runtime } = useDomainKit();
1317
+ const provider = config.sources?.provider ?? config.connection !== void 0;
1318
+ const publicDns = config.sources?.publicDns ?? true;
1319
+ const recordKey = recordsIdentity(config.records);
1320
+ return useMemo(() => {
1321
+ const state = Atom.make(State.Idle());
1322
+ return {
1323
+ command: runtime.fn()((command, get) => {
1324
+ if (command._tag === "Reset") {
1325
+ get.set(state, State.Idle());
1326
+ return Effect.void;
1327
+ }
1328
+ get.set(state, State.Observing());
1329
+ return Effect.flatMap(Transport.Service, (transport) => transport.verification.observe({
1349
1330
  ...config.connection === void 0 ? {} : { connectionId: config.connection.connectionId },
1350
1331
  domain: config.domain,
1351
1332
  records: config.records,
1352
- sources
1353
- }));
1354
- } catch (cause) {
1355
- requestState.commit(request, {
1356
- _tag: "Failure",
1357
- message: cause instanceof Error ? cause.message : "DNS observation failed",
1358
- retry: "safe"
1359
- });
1360
- }
1361
- }, [
1362
- config,
1363
- requestState,
1364
- sources,
1365
- transport
1366
- ]),
1333
+ sources: {
1334
+ provider,
1335
+ publicDns
1336
+ }
1337
+ })).pipe(Effect.tap((observation) => Effect.sync(() => get.set(state, observation))), Effect.catch((error) => Effect.sync(() => get.set(state, failureFromError(error)))), Effect.asVoid);
1338
+ }),
1339
+ state
1340
+ };
1341
+ }, [
1342
+ config.connection?.connectionId,
1343
+ config.domain,
1344
+ provider,
1345
+ publicDns,
1346
+ recordKey,
1347
+ runtime
1348
+ ]);
1349
+ }
1350
+ function useController(config) {
1351
+ const model = useModel(config);
1352
+ const state = useAtomValue(model.state);
1353
+ const dispatch = useAtomSet(model.command);
1354
+ const observe = () => dispatch(Command.Observe());
1355
+ const reset = () => dispatch(Command.Reset());
1356
+ return {
1357
+ observe,
1358
+ reset,
1367
1359
  state
1368
1360
  };
1369
1361
  }
@@ -1383,46 +1375,66 @@ const observationGroups = (observation) => [{
1383
1375
  evidence: observation.publicDns,
1384
1376
  label: "Public DNS"
1385
1377
  }].filter((group) => group.evidence.length > 0);
1378
+ function Root({ status, ...props }) {
1379
+ return usePart("div", props, { status }, {
1380
+ "data-domainkit-part": "verification-status",
1381
+ "data-state": status
1382
+ });
1383
+ }
1384
+ function Evidence({ observation }) {
1385
+ return /* @__PURE__ */ jsx("div", {
1386
+ "data-domainkit-part": "observation-list",
1387
+ children: observationGroups(observation).map((group) => /* @__PURE__ */ jsxs("section", {
1388
+ "data-domainkit-part": "observation-group",
1389
+ children: [/* @__PURE__ */ jsx("p", {
1390
+ "data-domainkit-part": "observation-source",
1391
+ children: group.label
1392
+ }), /* @__PURE__ */ jsx("ul", { children: group.evidence.map((evidence, index) => {
1393
+ const note = evidenceNote(evidence);
1394
+ return /* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsxs("div", {
1395
+ "data-domainkit-part": "observation-row",
1396
+ children: [/* @__PURE__ */ jsx("span", {
1397
+ "data-domainkit-part": "observation-record",
1398
+ children: evidence.recordId
1399
+ }), /* @__PURE__ */ jsx(Status$1, { evidence })]
1400
+ }), note === void 0 ? null : /* @__PURE__ */ jsx("p", {
1401
+ "data-domainkit-part": "observation-note",
1402
+ children: note
1403
+ })] }, `${evidence._tag}-${evidence.recordId}-${index}`);
1404
+ }) })]
1405
+ }, group.label))
1406
+ });
1407
+ }
1408
+ function Outcome({ state }) {
1409
+ if (state._tag !== "Failure") return null;
1410
+ return /* @__PURE__ */ jsx("p", {
1411
+ "data-domainkit-part": "flow-outcome",
1412
+ "data-tone": "danger",
1413
+ role: "alert",
1414
+ children: state.message
1415
+ });
1416
+ }
1417
+ function ObserveAction({ controller }) {
1418
+ const { messages } = useDomainKit();
1419
+ return /* @__PURE__ */ jsx("button", {
1420
+ "data-domainkit-part": "observe-action",
1421
+ disabled: controller.state._tag === "Observing",
1422
+ onClick: () => controller.observe(),
1423
+ type: "button",
1424
+ children: controller.state._tag === "Observing" ? messages.checkingDns : messages.checkDns
1425
+ });
1426
+ }
1386
1427
  function Status({ config, ...props }) {
1387
1428
  const controller = useController(config);
1388
- const { messages } = useDomainKit();
1389
1429
  const state = controller.state;
1390
- return usePart("div", props, { status: state._tag }, {
1391
- children: /* @__PURE__ */ jsxs(Fragment, { children: [state._tag === "Observation" ? /* @__PURE__ */ jsx("div", {
1392
- "data-domainkit-part": "observation-list",
1393
- children: observationGroups(state).map((group) => /* @__PURE__ */ jsxs("section", {
1394
- "data-domainkit-part": "observation-group",
1395
- children: [/* @__PURE__ */ jsx("p", {
1396
- "data-domainkit-part": "observation-source",
1397
- children: group.label
1398
- }), /* @__PURE__ */ jsx("ul", { children: group.evidence.map((evidence, index) => {
1399
- const note = evidenceNote(evidence);
1400
- return /* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsxs("div", {
1401
- "data-domainkit-part": "observation-row",
1402
- children: [/* @__PURE__ */ jsx("span", {
1403
- "data-domainkit-part": "observation-record",
1404
- children: evidence.recordId
1405
- }), /* @__PURE__ */ jsx(Status$1, { evidence })]
1406
- }), note === void 0 ? null : /* @__PURE__ */ jsx("p", {
1407
- "data-domainkit-part": "observation-note",
1408
- children: note
1409
- })] }, `${evidence._tag}-${evidence.recordId}-${index}`);
1410
- }) })]
1411
- }, group.label))
1412
- }) : state._tag === "Failure" ? /* @__PURE__ */ jsx("p", {
1413
- "data-domainkit-part": "flow-outcome",
1414
- "data-tone": "danger",
1415
- role: "alert",
1416
- children: state.message
1417
- }) : null, /* @__PURE__ */ jsx("button", {
1418
- "data-domainkit-part": "observe-action",
1419
- disabled: state._tag === "Observing",
1420
- onClick: () => void controller.observe(),
1421
- type: "button",
1422
- children: state._tag === "Observing" ? messages.checkingDns : messages.checkDns
1423
- })] }),
1424
- "data-domainkit-part": "verification-status",
1425
- "data-state": state._tag
1430
+ return /* @__PURE__ */ jsxs(Root, {
1431
+ status: state._tag,
1432
+ ...props,
1433
+ children: [
1434
+ state._tag === "Observation" ? /* @__PURE__ */ jsx(Evidence, { observation: state }) : null,
1435
+ /* @__PURE__ */ jsx(Outcome, { state }),
1436
+ /* @__PURE__ */ jsx(ObserveAction, { controller })
1437
+ ]
1426
1438
  });
1427
1439
  }
1428
1440
  //#endregion
@@ -1431,12 +1443,12 @@ var domain_exports = /* @__PURE__ */ __exportAll({ Flow: () => Flow });
1431
1443
  function Flow({ domain, receiptId, records }) {
1432
1444
  const connection = useController$2(domain);
1433
1445
  const state = connection.state;
1434
- return /* @__PURE__ */ jsxs(Root$1, {
1446
+ return /* @__PURE__ */ jsxs(Root$3, {
1435
1447
  status: state._tag,
1436
1448
  children: [
1437
1449
  state._tag === "Connected" ? null : /* @__PURE__ */ jsx(Status$2, { state }),
1438
- state._tag === "Failure" && (state.retry === "safe" || state.retry === "unknown") ? /* @__PURE__ */ jsx(RetryAction, { controller: connection }) : null,
1439
- state._tag === "Disconnected" ? /* @__PURE__ */ jsxs(Dialog.Root, { children: [/* @__PURE__ */ jsx(Trigger, { provider: state.provider }), /* @__PURE__ */ jsx(Dialog$1, {
1450
+ state._tag === "Failure" && (state.retry === "safe" || state.retry === "unknown") ? /* @__PURE__ */ jsx(RetryAction$1, { controller: connection }) : null,
1451
+ state._tag === "Disconnected" ? /* @__PURE__ */ jsxs(Dialog.Root, { children: [/* @__PURE__ */ jsx(ConnectTrigger, { provider: state.provider }), /* @__PURE__ */ jsx(Dialog$2, {
1440
1452
  controller: connection,
1441
1453
  snapshot: state
1442
1454
  })] }) : null,
@@ -1537,8 +1549,7 @@ function makeFakeTransport(options) {
1537
1549
  reuse: []
1538
1550
  };
1539
1551
  const inspections = Array.isArray(options.inspect) ? [...options.inspect] : [options.inspect];
1540
- return {
1541
- calls,
1552
+ const transport = {
1542
1553
  cleanup: {
1543
1554
  apply: async (input) => {
1544
1555
  calls.cleanupApply.push(input);
@@ -1570,7 +1581,14 @@ function makeFakeTransport(options) {
1570
1581
  },
1571
1582
  inspect: async (input) => {
1572
1583
  calls.inspect.push(input);
1573
- return inspections.shift() ?? inspections.at(-1) ?? options.inspect;
1584
+ const snapshot = inspections.shift() ?? inspections.at(-1) ?? options.inspect;
1585
+ if (Array.isArray(snapshot)) throw new Error("Fake inspection sequence is empty");
1586
+ if (snapshot._tag === "Failure") throw new Transport.Failure({
1587
+ message: snapshot.message,
1588
+ operation: snapshot.operation ?? "connection.inspect",
1589
+ retry: snapshot.retry
1590
+ });
1591
+ return snapshot;
1574
1592
  },
1575
1593
  reuse: async (input) => {
1576
1594
  calls.reuse.push(input);
@@ -1630,11 +1648,9 @@ function makeFakeTransport(options) {
1630
1648
  };
1631
1649
  } }
1632
1650
  };
1651
+ return Object.assign(Transport.layerFromAsync(transport), transport, { calls });
1633
1652
  }
1634
1653
  //#endregion
1635
- //#region src/transport.ts
1636
- var transport_exports = /* @__PURE__ */ __exportAll({});
1637
- //#endregion
1638
- export { cleanup_exports as Cleanup, connection_exports as Connection, domain_exports as Domain, domain_kit_exports as DomainKit, messages_exports as Messages, provider_exports as Provider, provisioning_exports as Provisioning, records_exports as Records, testing_exports as Testing, theme_exports as Theme, transport_exports as Transport, verification_exports as Verification };
1654
+ export { cleanup_exports as Cleanup, connection_exports as Connection, domain_exports as Domain, domain_kit_exports as DomainKit, messages_exports as Messages, operations_exports as Operations, provider_exports as Provider, provisioning_exports as Provisioning, records_exports as Records, testing_exports as Testing, theme_exports as Theme, verification_exports as Verification };
1639
1655
 
1640
1656
  //# sourceMappingURL=index.mjs.map