@stacks/clarinet-sdk 3.23.1 → 3.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/cjs/common/src/sdkProxy.d.ts +32 -0
  2. package/dist/cjs/common/src/sdkProxy.js +88 -0
  3. package/dist/cjs/common/src/sdkProxy.js.map +1 -0
  4. package/dist/cjs/common/src/sdkProxyHelpers.d.ts +34 -12
  5. package/dist/cjs/common/src/sdkProxyHelpers.js +40 -8
  6. package/dist/cjs/common/src/sdkProxyHelpers.js.map +1 -1
  7. package/dist/cjs/node/src/debugClient.d.ts +78 -0
  8. package/dist/cjs/node/src/debugClient.js +242 -0
  9. package/dist/cjs/node/src/debugClient.js.map +1 -0
  10. package/dist/cjs/node/src/index.d.ts +3 -1
  11. package/dist/cjs/node/src/index.js +21 -1
  12. package/dist/cjs/node/src/index.js.map +1 -1
  13. package/dist/cjs/node/src/sdkProxy.d.ts +3 -10
  14. package/dist/cjs/node/src/sdkProxy.js +7 -98
  15. package/dist/cjs/node/src/sdkProxy.js.map +1 -1
  16. package/dist/cjs/node/src/syncDebugSimnet.d.ts +46 -0
  17. package/dist/cjs/node/src/syncDebugSimnet.js +180 -0
  18. package/dist/cjs/node/src/syncDebugSimnet.js.map +1 -0
  19. package/dist/cjs/node/src/syncDebugSocket.d.ts +12 -0
  20. package/dist/cjs/node/src/syncDebugSocket.js +281 -0
  21. package/dist/cjs/node/src/syncDebugSocket.js.map +1 -0
  22. package/dist/cjs/node/src/vfs.d.ts +2 -2
  23. package/dist/cjs/node/src/vfs.js.map +1 -1
  24. package/dist/cjs/node/tsconfig.cjs.tsbuildinfo +1 -1
  25. package/dist/esm/common/src/sdkProxy.d.ts +32 -0
  26. package/dist/esm/common/src/sdkProxy.js +85 -0
  27. package/dist/esm/common/src/sdkProxy.js.map +1 -0
  28. package/dist/esm/common/src/sdkProxyHelpers.d.ts +34 -12
  29. package/dist/esm/common/src/sdkProxyHelpers.js +40 -9
  30. package/dist/esm/common/src/sdkProxyHelpers.js.map +1 -1
  31. package/dist/esm/node/src/debugClient.d.ts +78 -0
  32. package/dist/esm/node/src/debugClient.js +204 -0
  33. package/dist/esm/node/src/debugClient.js.map +1 -0
  34. package/dist/esm/node/src/index.d.ts +3 -1
  35. package/dist/esm/node/src/index.js +18 -0
  36. package/dist/esm/node/src/index.js.map +1 -1
  37. package/dist/esm/node/src/sdkProxy.d.ts +3 -10
  38. package/dist/esm/node/src/sdkProxy.js +8 -99
  39. package/dist/esm/node/src/sdkProxy.js.map +1 -1
  40. package/dist/esm/node/src/syncDebugSimnet.d.ts +46 -0
  41. package/dist/esm/node/src/syncDebugSimnet.js +177 -0
  42. package/dist/esm/node/src/syncDebugSimnet.js.map +1 -0
  43. package/dist/esm/node/src/syncDebugSocket.d.ts +12 -0
  44. package/dist/esm/node/src/syncDebugSocket.js +276 -0
  45. package/dist/esm/node/src/syncDebugSocket.js.map +1 -0
  46. package/dist/esm/node/src/vfs.d.ts +2 -2
  47. package/dist/esm/node/src/vitest/index.d.ts +20 -20
  48. package/dist/esm/node/src/vitest/index.js +4 -7
  49. package/dist/esm/node/src/vitest/index.js.map +1 -1
  50. package/dist/esm/node/tsconfig.tsbuildinfo +1 -1
  51. package/package.json +11 -10
@@ -0,0 +1,32 @@
1
+ import { type CallFn, type CallReadOnlyFn, type DeployContract, type Execute, type GetDataVar, type GetMapEntry, type MineBlock, type TransferSTX } from "./sdkProxyHelpers.js";
2
+ type WasmTransactionRes = {
3
+ result: string;
4
+ events: string;
5
+ costs: string;
6
+ performance?: string;
7
+ };
8
+ type ProxySdk = {
9
+ callReadOnlyFn(args: unknown): WasmTransactionRes;
10
+ callPublicFn(args: unknown): WasmTransactionRes;
11
+ callPrivateFn(args: unknown): WasmTransactionRes;
12
+ deployContract(args: unknown): WasmTransactionRes;
13
+ execute(snippet: string): WasmTransactionRes;
14
+ getDataVar(contract: string, varName: string): string;
15
+ getMapEntry(contract: string, mapName: string, mapKey: Uint8Array): string;
16
+ mineBlock(txs: unknown[]): WasmTransactionRes[];
17
+ runSnippet(snippet: string): string;
18
+ transferSTX(args: unknown): WasmTransactionRes;
19
+ };
20
+ /** @deprecated use `simnet.execute(command)` instead */
21
+ type RunSnippet<S extends ProxySdk> = S["runSnippet"];
22
+ export type ProxiedSimnet<S extends ProxySdk> = {
23
+ [K in keyof S]: K extends "callReadOnlyFn" ? CallReadOnlyFn : K extends "callPublicFn" | "callPrivateFn" ? CallFn : K extends "execute" ? Execute : K extends "runSnippet" ? RunSnippet<S> : K extends "deployContract" ? DeployContract : K extends "transferSTX" ? TransferSTX : K extends "mineBlock" ? MineBlock : K extends "getDataVar" ? GetDataVar : K extends "getMapEntry" ? GetMapEntry : S[K];
24
+ };
25
+ type ProxyBindings<ContractOptions> = {
26
+ CallFnArgs: new (contract: string, method: string, args: Uint8Array[], sender: string, postConditions?: string[], postConditionMode?: string) => unknown;
27
+ ContractOptions: new (clarityVersion?: number) => ContractOptions;
28
+ DeployContractArgs: new (name: string, content: string, options: ContractOptions, sender: string, postConditions?: string[], postConditionMode?: string) => unknown;
29
+ TransferSTXArgs: new (amount: bigint, recipient: string, sender: string, postConditions?: string[], postConditionMode?: string) => unknown;
30
+ };
31
+ export declare function createSessionProxy<S extends ProxySdk, ContractOptions>(bindings: ProxyBindings<ContractOptions>): ProxyHandler<S>;
32
+ export {};
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSessionProxy = createSessionProxy;
4
+ const transactions_1 = require("@stacks/transactions");
5
+ const sdkProxyHelpers_js_1 = require("./sdkProxyHelpers.js");
6
+ function parseTxResponse(response) {
7
+ return {
8
+ result: transactions_1.Cl.deserialize(response.result),
9
+ events: (0, sdkProxyHelpers_js_1.parseEvents)(response.events),
10
+ costs: (0, sdkProxyHelpers_js_1.parseCosts)(response.costs),
11
+ performance: response.performance,
12
+ };
13
+ }
14
+ function createSessionProxy(bindings) {
15
+ const { CallFnArgs, ContractOptions, DeployContractArgs, TransferSTXArgs } = bindings;
16
+ return {
17
+ get(session, prop, receiver) {
18
+ const sdk = session;
19
+ if (prop === "callReadOnlyFn" || prop === "callPublicFn" || prop === "callPrivateFn") {
20
+ const callFn = (contract, method, args, sender, options) => {
21
+ const { postConditions, postConditionMode } = (0, sdkProxyHelpers_js_1.serializePostConditions)(options);
22
+ const response = sdk[prop](new CallFnArgs(contract, method, args.map(transactions_1.serializeCVBytes), sender, postConditions, postConditionMode));
23
+ return parseTxResponse(response);
24
+ };
25
+ return callFn;
26
+ }
27
+ if (prop === "execute") {
28
+ const execute = (snippet) => parseTxResponse(sdk.execute(snippet));
29
+ return execute;
30
+ }
31
+ if (prop === "deployContract") {
32
+ const deployContract = (name, content, options, sender, postConditionOptions) => {
33
+ const rustOptions = options
34
+ ? new ContractOptions(options.clarityVersion)
35
+ : new ContractOptions();
36
+ const { postConditions, postConditionMode } = (0, sdkProxyHelpers_js_1.serializePostConditions)(postConditionOptions);
37
+ return parseTxResponse(sdk.deployContract(new DeployContractArgs(name, content, rustOptions, sender, postConditions, postConditionMode)));
38
+ };
39
+ return deployContract;
40
+ }
41
+ if (prop === "transferSTX") {
42
+ const transferSTX = (amount, recipient, sender, options) => {
43
+ const { postConditions, postConditionMode } = (0, sdkProxyHelpers_js_1.serializePostConditions)(options);
44
+ return parseTxResponse(sdk.transferSTX(new TransferSTXArgs(BigInt(amount), recipient, sender, postConditions, postConditionMode)));
45
+ };
46
+ return transferSTX;
47
+ }
48
+ if (prop === "mineBlock") {
49
+ const mineBlock = (txs) => {
50
+ const serializedTxs = txs.map((tx) => {
51
+ if (tx.callPublicFn) {
52
+ return {
53
+ callPublicFn: {
54
+ ...tx.callPublicFn,
55
+ args_maps: tx.callPublicFn.args.map(transactions_1.serializeCVBytes),
56
+ },
57
+ };
58
+ }
59
+ if (tx.callPrivateFn) {
60
+ return {
61
+ callPrivateFn: {
62
+ ...tx.callPrivateFn,
63
+ args_maps: tx.callPrivateFn.args.map(transactions_1.serializeCVBytes),
64
+ },
65
+ };
66
+ }
67
+ if (tx.deployContract) {
68
+ return { deployContract: { ...tx.deployContract } };
69
+ }
70
+ return tx;
71
+ });
72
+ return sdk.mineBlock(serializedTxs).map(parseTxResponse);
73
+ };
74
+ return mineBlock;
75
+ }
76
+ if (prop === "getDataVar") {
77
+ const getDataVar = (...args) => transactions_1.Cl.deserialize(sdk.getDataVar(...args));
78
+ return getDataVar;
79
+ }
80
+ if (prop === "getMapEntry") {
81
+ const getMapEntry = (contract, mapName, mapKey) => transactions_1.Cl.deserialize(sdk.getMapEntry(contract, mapName, (0, transactions_1.serializeCVBytes)(mapKey)));
82
+ return getMapEntry;
83
+ }
84
+ return Reflect.get(session, prop, receiver);
85
+ },
86
+ };
87
+ }
88
+ //# sourceMappingURL=sdkProxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdkProxy.js","sourceRoot":"","sources":["../../../../../common/src/sdkProxy.ts"],"names":[],"mappings":";;;AAAA,uDAA4D;AAE5D,6DAa8B;AA0E9B,SAAS,eAAe,CAAC,QAA4B;IACnD,OAAO;QACL,MAAM,EAAE,iBAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC;QACvC,MAAM,EAAE,IAAA,gCAAW,EAAC,QAAQ,CAAC,MAAM,CAAC;QACpC,KAAK,EAAE,IAAA,+BAAU,EAAC,QAAQ,CAAC,KAAK,CAAC;QACjC,WAAW,EAAE,QAAQ,CAAC,WAAW;KAClC,CAAC;AACJ,CAAC;AAED,4BACE,QAAwC;IAExC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,kBAAkB,EAAE,eAAe,EAAE,GAAG,QAAQ,CAAC;IAEtF,OAAO;QACL,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ;YACzB,MAAM,GAAG,GAAa,OAAO,CAAC;YAE9B,IAAI,IAAI,KAAK,gBAAgB,IAAI,IAAI,KAAK,cAAc,IAAI,IAAI,KAA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CAAC;oBACZ,CAAC,CAAC,CAAC;oBACH,OAAO,GAAG,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;gBAC3D,CAAC,CAAC;gBACF,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;gBAC1B,MAAM,UAAU,GAAe,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,iBAAE,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;gBACpF,OAAO,UAAU,CAAC;YACpB,CAAC;YAED,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;gBAC3B,MAAM,WAAW,GAAgB,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAC7D,iBAAE,CAAC,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAA,+BAAgB,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAC/E,OAAO,WAAW,CAAC;YACrB,CAAC;YAED,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC9C,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,4 +1,4 @@
1
- import { ClarityValue, ClarityVersion } from "@stacks/transactions";
1
+ import { ClarityValue, ClarityVersion, ContractCallOptions, PostConditionModeName } from "@stacks/transactions";
2
2
  export type ClarityEvent = {
3
3
  event: string;
4
4
  data: {
@@ -26,19 +26,41 @@ export type ParsedTransactionResult = {
26
26
  costs: ClarityCosts | null;
27
27
  performance: string | undefined;
28
28
  };
29
- export type CallFn = (contract: string, method: string, args: ClarityValue[], sender: string) => ParsedTransactionResult;
29
+ /**
30
+ * Post-conditions to enforce on a simnet transaction.
31
+ *
32
+ * Conditions use the same builder, wire, and hex formats as stacks.js. Hex is
33
+ * also the escape hatch for conditions that stacks.js cannot build yet.
34
+ *
35
+ * Passing neither field preserves the SDK's unchecked behavior. Passing either
36
+ * enables enforcement; `postConditionMode` defaults to `"deny"`.
37
+ */
38
+ export type PostConditionOptions = Pick<ContractCallOptions, "postConditions" | "postConditionMode">;
39
+ /** `PostConditionOptions` as the Wasm SDK takes it: conditions already encoded. */
40
+ export type SerializedPostConditions = {
41
+ postConditions?: string[];
42
+ postConditionMode?: PostConditionModeName;
43
+ };
44
+ export declare function serializePostConditions(options?: PostConditionOptions): SerializedPostConditions;
45
+ export type CallFn = (contract: string, method: string, args: ClarityValue[], sender: string, options?: PostConditionOptions) => ParsedTransactionResult;
46
+ /** A read-only call moves no assets, so it takes no post-conditions. */
47
+ export type CallReadOnlyFn = (contract: string, method: string, args: ClarityValue[], sender: string) => ParsedTransactionResult;
30
48
  export type DeployContractOptions = {
31
49
  clarityVersion: ClarityVersion;
32
50
  };
33
- export type DeployContract = (name: string, content: string, options: DeployContractOptions | null, sender: string) => ParsedTransactionResult;
34
- export type TransferSTX = (amount: number | bigint, recipient: string, sender: string) => ParsedTransactionResult;
51
+ export type DeployContract = (name: string, content: string, options: DeployContractOptions | null, sender: string, postConditionOptions?: PostConditionOptions) => ParsedTransactionResult;
52
+ export type TransferSTX = (amount: number | bigint, recipient: string, sender: string, options?: PostConditionOptions) => ParsedTransactionResult;
53
+ /**
54
+ * A transaction in a `mineBlock` batch. Post-conditions are already encoded,
55
+ * because the batch is handed to Wasm as plain JSON.
56
+ */
35
57
  export type Tx = {
36
58
  callPublicFn: {
37
59
  contract: string;
38
60
  method: string;
39
61
  args: ClarityValue[];
40
62
  sender: string;
41
- };
63
+ } & SerializedPostConditions;
42
64
  callPrivateFn?: never;
43
65
  deployContract?: never;
44
66
  transferSTX?: never;
@@ -49,7 +71,7 @@ export type Tx = {
49
71
  method: string;
50
72
  args: ClarityValue[];
51
73
  sender: string;
52
- };
74
+ } & SerializedPostConditions;
53
75
  deployContract?: never;
54
76
  transferSTX?: never;
55
77
  } | {
@@ -60,7 +82,7 @@ export type Tx = {
60
82
  content: string;
61
83
  options: DeployContractOptions | null;
62
84
  sender: string;
63
- };
85
+ } & SerializedPostConditions;
64
86
  transferSTX?: never;
65
87
  } | {
66
88
  callPublicFn?: never;
@@ -70,13 +92,13 @@ export type Tx = {
70
92
  amount: number;
71
93
  recipient: string;
72
94
  sender: string;
73
- };
95
+ } & SerializedPostConditions;
74
96
  };
75
97
  export declare const tx: {
76
- callPublicFn: (contract: string, method: string, args: ClarityValue[], sender: string) => Tx;
77
- callPrivateFn: (contract: string, method: string, args: ClarityValue[], sender: string) => Tx;
78
- deployContract: (name: string, content: string, options: DeployContractOptions | null, sender: string) => Tx;
79
- transferSTX: (amount: number, recipient: string, sender: string) => Tx;
98
+ callPublicFn: (contract: string, method: string, args: ClarityValue[], sender: string, options?: PostConditionOptions) => Tx;
99
+ callPrivateFn: (contract: string, method: string, args: ClarityValue[], sender: string, options?: PostConditionOptions) => Tx;
100
+ deployContract: (name: string, content: string, options: DeployContractOptions | null, sender: string, postConditionOptions?: PostConditionOptions) => Tx;
101
+ transferSTX: (amount: number, recipient: string, sender: string, options?: PostConditionOptions) => Tx;
80
102
  };
81
103
  export declare function parseEvents(events: string): ClarityEvent[];
82
104
  export declare function parseCosts(costs: string): ClarityCosts | null;
@@ -1,21 +1,53 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tx = void 0;
4
+ exports.serializePostConditions = serializePostConditions;
4
5
  exports.parseEvents = parseEvents;
5
6
  exports.parseCosts = parseCosts;
6
7
  const transactions_1 = require("@stacks/transactions");
8
+ function serializePostConditions(options) {
9
+ const conditions = options?.postConditions;
10
+ const mode = options?.postConditionMode;
11
+ // Preserve the distinction between an omitted list and an explicit empty one.
12
+ return {
13
+ ...(conditions !== undefined && {
14
+ postConditions: conditions.map((pc) => {
15
+ if (typeof pc === "string")
16
+ return pc;
17
+ return typeof pc.type === "string"
18
+ ? (0, transactions_1.postConditionToHex)(pc)
19
+ : (0, transactions_1.serializePostConditionWire)(pc);
20
+ }),
21
+ }),
22
+ ...(mode !== undefined && {
23
+ postConditionMode: mode === transactions_1.PostConditionMode.Allow
24
+ ? "allow"
25
+ : mode === transactions_1.PostConditionMode.Deny
26
+ ? "deny"
27
+ : mode === transactions_1.PostConditionMode.Originator
28
+ ? "originator"
29
+ : mode,
30
+ }),
31
+ };
32
+ }
7
33
  exports.tx = {
8
- callPublicFn: (contract, method, args, sender) => ({
9
- callPublicFn: { contract, method, args, sender },
34
+ callPublicFn: (contract, method, args, sender, options) => ({
35
+ callPublicFn: { contract, method, args, sender, ...serializePostConditions(options) },
10
36
  }),
11
- callPrivateFn: (contract, method, args, sender) => ({
12
- callPrivateFn: { contract, method, args, sender },
37
+ callPrivateFn: (contract, method, args, sender, options) => ({
38
+ callPrivateFn: { contract, method, args, sender, ...serializePostConditions(options) },
13
39
  }),
14
- deployContract: (name, content, options, sender) => ({
15
- deployContract: { name, content, options, sender },
40
+ deployContract: (name, content, options, sender, postConditionOptions) => ({
41
+ deployContract: {
42
+ name,
43
+ content,
44
+ options,
45
+ sender,
46
+ ...serializePostConditions(postConditionOptions),
47
+ },
16
48
  }),
17
- transferSTX: (amount, recipient, sender) => ({
18
- transferSTX: { amount, recipient, sender },
49
+ transferSTX: (amount, recipient, sender, options) => ({
50
+ transferSTX: { amount, recipient, sender, ...serializePostConditions(options) },
19
51
  }),
20
52
  };
21
53
  function parseEvents(events) {
@@ -1 +1 @@
1
- {"version":3,"file":"sdkProxyHelpers.js","sourceRoot":"","sources":["../../../../../common/src/sdkProxyHelpers.ts"],"names":[],"mappings":";;;AAiHA,kCAiBC;AAED,gCAwBC;AA5JD,uDAAwE;AA6F3D,QAAA,EAAE,GAAG;IAChB,YAAY,EAAE,CAAC,QAAgB,EAAE,MAAc,EAAE,IAAoB,EAAE,MAAc,EAAM,EAAE,CAAC,CAAC;QAC7F,YAAY,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE;KACj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CAAC,WAAW;gBAC7B,SAAS,EAAE,KAAK,CAAC,UAAU;gBAC3B,OAAO,EAAE,KAAK,CAAC,OAAO;aACvB;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,78 @@
1
+ import * as net from "net";
2
+ import { type ChildProcess } from "child_process";
3
+ import { type ClarityValue } from "@stacks/transactions";
4
+ export type DebugCallResult = {
5
+ /** The Clarity return value as a human-readable string, e.g. `"(ok u1)"`. */
6
+ value: string;
7
+ };
8
+ /**
9
+ * A client that connects to a `clarinet dap --dap-port … --sdk-port …` server
10
+ * and evaluates Clarity expressions under DAP debugger control.
11
+ *
12
+ * Breakpoints set in VSCode (or another DAP-capable editor) in `.clar` source
13
+ * files will be hit when the corresponding contract code is reached.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const debugger = await startDebugServer();
18
+ * const result = await debugger.callPublicFn("counter", "increment", [], deployer);
19
+ * expect(result.value).toBe("(ok u1)");
20
+ * await debugger.disconnect();
21
+ * ```
22
+ */
23
+ export declare class DebugClient {
24
+ private readonly socket;
25
+ private nextId;
26
+ private readonly pending;
27
+ private buffer;
28
+ /** Set when this client owns the `clarinet dap` process (via `startDebugServer`). */
29
+ private readonly _process?;
30
+ constructor(socket: net.Socket, process?: ChildProcess);
31
+ private send;
32
+ /**
33
+ * Call a public contract function through the debug server.
34
+ * Breakpoints in the contract source will pause execution.
35
+ */
36
+ callPublicFn(contract: string, method: string, args: ClarityValue[], sender: string): Promise<DebugCallResult>;
37
+ /**
38
+ * Evaluate an arbitrary Clarity snippet in the simnet session under the debugger.
39
+ */
40
+ execute(snippet: string): Promise<DebugCallResult>;
41
+ /** Gracefully disconnect from the debug server. */
42
+ disconnect(): Promise<void>;
43
+ }
44
+ /**
45
+ * Start or connect to a `clarinet dap` debug server and return a
46
+ * {@link DebugClient}.
47
+ *
48
+ * **Auto-spawn mode** (default): when no `port` is provided and
49
+ * `CLARINET_DEBUG_PORT` is not set, `clarinet dap` is spawned automatically.
50
+ * The returned client owns the process and kills it on
51
+ * {@link DebugClient.disconnect}.
52
+ *
53
+ * **Connect mode**: when `port` is provided (or `CLARINET_DEBUG_PORT` is set),
54
+ * the function connects to a server that is already running — for example one
55
+ * started by the VSCode extension's CodeLens button.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * // Zero-config — server is spawned automatically
60
+ * const client = await startDebugServer({ manifest: "./Clarinet.toml" });
61
+ * const result = await client.callPublicFn("counter", "increment", [], deployer);
62
+ * await client.disconnect();
63
+ * ```
64
+ */
65
+ export declare function startDebugServer(options?: {
66
+ /** Path to Clarinet.toml. Defaults to `"./Clarinet.toml"`. */
67
+ manifest?: string;
68
+ /**
69
+ * Connect to this port instead of spawning a new server.
70
+ * Falls back to `CLARINET_DEBUG_PORT` env var, then auto-spawn.
71
+ */
72
+ port?: number;
73
+ /**
74
+ * When auto-spawning, also open a DAP port so a DAP client (e.g. VSCode)
75
+ * can attach and hit breakpoints. Ignored in connect mode.
76
+ */
77
+ dapPort?: number;
78
+ }): Promise<DebugClient>;
@@ -0,0 +1,242 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.DebugClient = void 0;
37
+ exports.startDebugServer = startDebugServer;
38
+ const net = __importStar(require("net"));
39
+ const child_process_1 = require("child_process");
40
+ const transactions_1 = require("@stacks/transactions");
41
+ /**
42
+ * A client that connects to a `clarinet dap --dap-port … --sdk-port …` server
43
+ * and evaluates Clarity expressions under DAP debugger control.
44
+ *
45
+ * Breakpoints set in VSCode (or another DAP-capable editor) in `.clar` source
46
+ * files will be hit when the corresponding contract code is reached.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const debugger = await startDebugServer();
51
+ * const result = await debugger.callPublicFn("counter", "increment", [], deployer);
52
+ * expect(result.value).toBe("(ok u1)");
53
+ * await debugger.disconnect();
54
+ * ```
55
+ */
56
+ class DebugClient {
57
+ socket;
58
+ nextId = 1;
59
+ pending = new Map();
60
+ buffer = "";
61
+ /** Set when this client owns the `clarinet dap` process (via `startDebugServer`). */
62
+ _process;
63
+ constructor(socket, process) {
64
+ this.socket = socket;
65
+ this._process = process;
66
+ socket.on("data", (chunk) => {
67
+ this.buffer += chunk.toString("utf8");
68
+ const lines = this.buffer.split("\n");
69
+ // Keep any incomplete line in the buffer
70
+ this.buffer = lines.pop() ?? "";
71
+ for (const line of lines) {
72
+ const trimmed = line.trim();
73
+ if (!trimmed)
74
+ continue;
75
+ try {
76
+ const response = JSON.parse(trimmed);
77
+ const pending = this.pending.get(response.id);
78
+ if (pending) {
79
+ this.pending.delete(response.id);
80
+ pending.resolve(response);
81
+ }
82
+ }
83
+ catch {
84
+ // Ignore malformed lines
85
+ }
86
+ }
87
+ });
88
+ const rejectPending = (err) => {
89
+ for (const { reject } of this.pending.values()) {
90
+ reject(err);
91
+ }
92
+ this.pending.clear();
93
+ };
94
+ socket.on("error", rejectPending);
95
+ socket.on("close", () => {
96
+ rejectPending(new Error("debug server connection closed"));
97
+ });
98
+ }
99
+ send(request) {
100
+ const id = this.nextId++;
101
+ return new Promise((resolve, reject) => {
102
+ this.pending.set(id, { resolve, reject });
103
+ this.socket.write(JSON.stringify({ ...request, id }) + "\n");
104
+ });
105
+ }
106
+ /**
107
+ * Call a public contract function through the debug server.
108
+ * Breakpoints in the contract source will pause execution.
109
+ */
110
+ async callPublicFn(contract, method, args, sender) {
111
+ const argStrings = args.map((a) => transactions_1.Cl.stringify(a));
112
+ const response = await this.send({
113
+ method: "call",
114
+ contract,
115
+ function: method,
116
+ args: argStrings,
117
+ sender,
118
+ });
119
+ if (response.error)
120
+ throw new Error(response.error);
121
+ return { value: transactions_1.Cl.stringify(transactions_1.Cl.deserialize(response.result.result)) };
122
+ }
123
+ /**
124
+ * Evaluate an arbitrary Clarity snippet in the simnet session under the debugger.
125
+ */
126
+ async execute(snippet) {
127
+ const response = await this.send({ method: "eval", snippet });
128
+ if (response.error)
129
+ throw new Error(response.error);
130
+ return { value: transactions_1.Cl.stringify(transactions_1.Cl.deserialize(response.result.result)) };
131
+ }
132
+ /** Gracefully disconnect from the debug server. */
133
+ async disconnect() {
134
+ try {
135
+ await this.send({ method: "disconnect" });
136
+ }
137
+ finally {
138
+ this.socket.destroy();
139
+ try {
140
+ this._process?.kill();
141
+ }
142
+ catch {
143
+ // ignore: process may have already exited
144
+ }
145
+ }
146
+ }
147
+ }
148
+ exports.DebugClient = DebugClient;
149
+ function openSocket(port) {
150
+ return new Promise((resolve, reject) => {
151
+ const socket = net.createConnection({ port, host: "127.0.0.1" }, () => {
152
+ socket.removeListener("error", reject);
153
+ resolve(socket);
154
+ });
155
+ socket.once("error", reject);
156
+ });
157
+ }
158
+ /**
159
+ * Start or connect to a `clarinet dap` debug server and return a
160
+ * {@link DebugClient}.
161
+ *
162
+ * **Auto-spawn mode** (default): when no `port` is provided and
163
+ * `CLARINET_DEBUG_PORT` is not set, `clarinet dap` is spawned automatically.
164
+ * The returned client owns the process and kills it on
165
+ * {@link DebugClient.disconnect}.
166
+ *
167
+ * **Connect mode**: when `port` is provided (or `CLARINET_DEBUG_PORT` is set),
168
+ * the function connects to a server that is already running — for example one
169
+ * started by the VSCode extension's CodeLens button.
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * // Zero-config — server is spawned automatically
174
+ * const client = await startDebugServer({ manifest: "./Clarinet.toml" });
175
+ * const result = await client.callPublicFn("counter", "increment", [], deployer);
176
+ * await client.disconnect();
177
+ * ```
178
+ */
179
+ async function startDebugServer(options) {
180
+ const envPort = process.env["CLARINET_DEBUG_PORT"]
181
+ ? Number(process.env["CLARINET_DEBUG_PORT"])
182
+ : undefined;
183
+ const connectPort = options?.port ?? envPort;
184
+ // Connect mode: server is already running externally.
185
+ if (connectPort != null) {
186
+ const socket = await openSocket(connectPort);
187
+ return new DebugClient(socket);
188
+ }
189
+ // Auto-spawn mode: launch clarinet dap ourselves. Ask the OS for a free SDK
190
+ // port so parallel test runs don't contend for a fixed port.
191
+ let sdkPort;
192
+ const manifest = options?.manifest ?? "./Clarinet.toml";
193
+ const args = ["dap", "--sdk-port", "0", "--manifest", manifest];
194
+ if (options?.dapPort != null) {
195
+ args.push("--dap-port", String(options.dapPort));
196
+ }
197
+ const child = (0, child_process_1.spawn)("clarinet", args, {
198
+ stdio: ["ignore", "ignore", "pipe"],
199
+ });
200
+ // Wait for the ready signal printed to stderr by run_dap_server.
201
+ await new Promise((resolve, reject) => {
202
+ const readyPattern = /CLARINET_DAP_SDK_READY:(\d+)/;
203
+ let stderrBuf = "";
204
+ const timeout = setTimeout(() => reject(new Error("clarinet dap server did not start within 15 s")), 15_000);
205
+ const cleanup = () => {
206
+ clearTimeout(timeout);
207
+ child.stderr.removeListener("data", onStderr);
208
+ child.removeListener("error", onError);
209
+ child.removeListener("exit", onExit);
210
+ };
211
+ const onStderr = (chunk) => {
212
+ stderrBuf += chunk.toString("utf8");
213
+ const match = readyPattern.exec(stderrBuf);
214
+ if (match) {
215
+ sdkPort = Number(match[1]);
216
+ cleanup();
217
+ // Keep draining stderr so the pipe doesn't fill and block the server,
218
+ // and so crash messages appear in the parent process output.
219
+ child.stderr.on("data", (c) => process.stderr.write(c));
220
+ resolve();
221
+ }
222
+ };
223
+ const onError = (err) => {
224
+ cleanup();
225
+ reject(new Error(`failed to spawn clarinet: ${err.message}`));
226
+ };
227
+ const onExit = (code) => {
228
+ cleanup();
229
+ reject(new Error(`clarinet dap exited unexpectedly with code ${code}`));
230
+ };
231
+ child.stderr.on("data", onStderr);
232
+ child.on("error", onError);
233
+ child.on("exit", onExit);
234
+ });
235
+ if (sdkPort == null) {
236
+ child.kill();
237
+ throw new Error("clarinet dap did not report an SDK port");
238
+ }
239
+ const socket = await openSocket(sdkPort);
240
+ return new DebugClient(socket, child);
241
+ }
242
+ //# sourceMappingURL=debugClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debugClient.js","sourceRoot":"","sources":["../../../../src/debugClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAY,GAAG,gCAAY;AAC3B,iDAAyD;AAEzD,uDAA6D;AAkB7D;;;;;;;;;;;;;;GAcG;AACH;IACmB,MAAM,CAAa;IAC5B,MAAM,GAAG,CAAC,CAAC;IACF,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;IACrD,MAAM,GAAG,EAAE,CAAC;IACpB,qFAAqF;IACpE,QAAQ,CAAgB;IAEzC,YAAY,MAAkB,EAAE,OAAsB;QACpD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,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AC3B,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,KAAK,CAAC,IAAI,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,CAAC;IACzC,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export { tx, type ClarityEvent, type ParsedTransactionResult, type DeployContractOptions, type Tx, type TransferSTX, } from "../../common/src/sdkProxyHelpers.js";
2
+ import type { SDK } from "@stacks/clarinet-sdk-wasm";
2
3
  import { Simnet } from "./sdkProxy.js";
3
4
  export { type Simnet } from "./sdkProxy.js";
4
5
  type Options = {
@@ -14,4 +15,5 @@ export declare const initSimnet: (manifestPath?: string, noCache?: boolean, opti
14
15
  trackPerformance?: boolean;
15
16
  performanceCostField?: string;
16
17
  apiUrl?: string;
17
- }) => Promise<Simnet>;
18
+ }) => Promise<import("../../common/src/sdkProxy.js").ProxiedSimnet<SDK>>;
19
+ export { startDebugServer, DebugClient, type DebugCallResult, } from "./debugClient.js";