@clarigen/cli 0.2.4 → 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/cli.esm.js DELETED
@@ -1,1304 +0,0 @@
1
- export { run } from '@oclif/command';
2
- import { resolve, relative, join, dirname } from 'path';
3
- import { readFile } from 'fs/promises';
4
- import { parse } from '@ltd/j-toml';
5
- import { getStxAddress, generateWallet } from '@stacks/wallet-sdk';
6
- import { isClarityAbiPrimitive, isClarityAbiBuffer, isClarityAbiResponse, isClarityAbiOptional, isClarityAbiTuple, isClarityAbiList, isClarityAbiStringAscii, isClarityAbiStringUtf8 } from '@stacks/transactions';
7
- import { toCamelCase, getContractNameFromPath } from '@clarigen/core';
8
- import { createClarityBin } from '@clarigen/native-bin';
9
-
10
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
11
- try {
12
- var info = gen[key](arg);
13
- var value = info.value;
14
- } catch (error) {
15
- reject(error);
16
- return;
17
- }
18
-
19
- if (info.done) {
20
- resolve(value);
21
- } else {
22
- Promise.resolve(value).then(_next, _throw);
23
- }
24
- }
25
-
26
- function _asyncToGenerator(fn) {
27
- return function () {
28
- var self = this,
29
- args = arguments;
30
- return new Promise(function (resolve, reject) {
31
- var gen = fn.apply(self, args);
32
-
33
- function _next(value) {
34
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
35
- }
36
-
37
- function _throw(err) {
38
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
39
- }
40
-
41
- _next(undefined);
42
- });
43
- };
44
- }
45
-
46
- function _extends() {
47
- _extends = Object.assign || function (target) {
48
- for (var i = 1; i < arguments.length; i++) {
49
- var source = arguments[i];
50
-
51
- for (var key in source) {
52
- if (Object.prototype.hasOwnProperty.call(source, key)) {
53
- target[key] = source[key];
54
- }
55
- }
56
- }
57
-
58
- return target;
59
- };
60
-
61
- return _extends.apply(this, arguments);
62
- }
63
-
64
- function createCommonjsModule(fn, module) {
65
- return module = { exports: {} }, fn(module, module.exports), module.exports;
66
- }
67
-
68
- var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
69
- /**
70
- * Copyright (c) 2014-present, Facebook, Inc.
71
- *
72
- * This source code is licensed under the MIT license found in the
73
- * LICENSE file in the root directory of this source tree.
74
- */
75
- var runtime = function (exports) {
76
-
77
- var Op = Object.prototype;
78
- var hasOwn = Op.hasOwnProperty;
79
- var undefined$1; // More compressible than void 0.
80
-
81
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
82
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
83
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
84
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
85
-
86
- function define(obj, key, value) {
87
- Object.defineProperty(obj, key, {
88
- value: value,
89
- enumerable: true,
90
- configurable: true,
91
- writable: true
92
- });
93
- return obj[key];
94
- }
95
-
96
- try {
97
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
98
- define({}, "");
99
- } catch (err) {
100
- define = function define(obj, key, value) {
101
- return obj[key] = value;
102
- };
103
- }
104
-
105
- function wrap(innerFn, outerFn, self, tryLocsList) {
106
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
107
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
108
- var generator = Object.create(protoGenerator.prototype);
109
- var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
110
- // .throw, and .return methods.
111
-
112
- generator._invoke = makeInvokeMethod(innerFn, self, context);
113
- return generator;
114
- }
115
-
116
- exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
117
- // record like context.tryEntries[i].completion. This interface could
118
- // have been (and was previously) designed to take a closure to be
119
- // invoked without arguments, but in all the cases we care about we
120
- // already have an existing method we want to call, so there's no need
121
- // to create a new function object. We can even get away with assuming
122
- // the method takes exactly one argument, since that happens to be true
123
- // in every case, so we don't have to touch the arguments object. The
124
- // only additional allocation required is the completion record, which
125
- // has a stable shape and so hopefully should be cheap to allocate.
126
-
127
- function tryCatch(fn, obj, arg) {
128
- try {
129
- return {
130
- type: "normal",
131
- arg: fn.call(obj, arg)
132
- };
133
- } catch (err) {
134
- return {
135
- type: "throw",
136
- arg: err
137
- };
138
- }
139
- }
140
-
141
- var GenStateSuspendedStart = "suspendedStart";
142
- var GenStateSuspendedYield = "suspendedYield";
143
- var GenStateExecuting = "executing";
144
- var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
145
- // breaking out of the dispatch switch statement.
146
-
147
- var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
148
- // .constructor.prototype properties for functions that return Generator
149
- // objects. For full spec compliance, you may wish to configure your
150
- // minifier not to mangle the names of these two functions.
151
-
152
- function Generator() {}
153
-
154
- function GeneratorFunction() {}
155
-
156
- function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
157
- // don't natively support it.
158
-
159
-
160
- var IteratorPrototype = {};
161
-
162
- IteratorPrototype[iteratorSymbol] = function () {
163
- return this;
164
- };
165
-
166
- var getProto = Object.getPrototypeOf;
167
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
168
-
169
- if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
170
- // This environment has a native %IteratorPrototype%; use it instead
171
- // of the polyfill.
172
- IteratorPrototype = NativeIteratorPrototype;
173
- }
174
-
175
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
176
- GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
177
- GeneratorFunctionPrototype.constructor = GeneratorFunction;
178
- GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
179
- // Iterator interface in terms of a single ._invoke method.
180
-
181
- function defineIteratorMethods(prototype) {
182
- ["next", "throw", "return"].forEach(function (method) {
183
- define(prototype, method, function (arg) {
184
- return this._invoke(method, arg);
185
- });
186
- });
187
- }
188
-
189
- exports.isGeneratorFunction = function (genFun) {
190
- var ctor = typeof genFun === "function" && genFun.constructor;
191
- return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
192
- // do is to check its .name property.
193
- (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
194
- };
195
-
196
- exports.mark = function (genFun) {
197
- if (Object.setPrototypeOf) {
198
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
199
- } else {
200
- genFun.__proto__ = GeneratorFunctionPrototype;
201
- define(genFun, toStringTagSymbol, "GeneratorFunction");
202
- }
203
-
204
- genFun.prototype = Object.create(Gp);
205
- return genFun;
206
- }; // Within the body of any async function, `await x` is transformed to
207
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
208
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
209
- // meant to be awaited.
210
-
211
-
212
- exports.awrap = function (arg) {
213
- return {
214
- __await: arg
215
- };
216
- };
217
-
218
- function AsyncIterator(generator, PromiseImpl) {
219
- function invoke(method, arg, resolve, reject) {
220
- var record = tryCatch(generator[method], generator, arg);
221
-
222
- if (record.type === "throw") {
223
- reject(record.arg);
224
- } else {
225
- var result = record.arg;
226
- var value = result.value;
227
-
228
- if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
229
- return PromiseImpl.resolve(value.__await).then(function (value) {
230
- invoke("next", value, resolve, reject);
231
- }, function (err) {
232
- invoke("throw", err, resolve, reject);
233
- });
234
- }
235
-
236
- return PromiseImpl.resolve(value).then(function (unwrapped) {
237
- // When a yielded Promise is resolved, its final value becomes
238
- // the .value of the Promise<{value,done}> result for the
239
- // current iteration.
240
- result.value = unwrapped;
241
- resolve(result);
242
- }, function (error) {
243
- // If a rejected Promise was yielded, throw the rejection back
244
- // into the async generator function so it can be handled there.
245
- return invoke("throw", error, resolve, reject);
246
- });
247
- }
248
- }
249
-
250
- var previousPromise;
251
-
252
- function enqueue(method, arg) {
253
- function callInvokeWithMethodAndArg() {
254
- return new PromiseImpl(function (resolve, reject) {
255
- invoke(method, arg, resolve, reject);
256
- });
257
- }
258
-
259
- return previousPromise = // If enqueue has been called before, then we want to wait until
260
- // all previous Promises have been resolved before calling invoke,
261
- // so that results are always delivered in the correct order. If
262
- // enqueue has not been called before, then it is important to
263
- // call invoke immediately, without waiting on a callback to fire,
264
- // so that the async generator function has the opportunity to do
265
- // any necessary setup in a predictable way. This predictability
266
- // is why the Promise constructor synchronously invokes its
267
- // executor callback, and why async functions synchronously
268
- // execute code before the first await. Since we implement simple
269
- // async functions in terms of async generators, it is especially
270
- // important to get this right, even though it requires care.
271
- previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
272
- // invocations of the iterator.
273
- callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
274
- } // Define the unified helper method that is used to implement .next,
275
- // .throw, and .return (see defineIteratorMethods).
276
-
277
-
278
- this._invoke = enqueue;
279
- }
280
-
281
- defineIteratorMethods(AsyncIterator.prototype);
282
-
283
- AsyncIterator.prototype[asyncIteratorSymbol] = function () {
284
- return this;
285
- };
286
-
287
- exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
288
- // AsyncIterator objects; they just return a Promise for the value of
289
- // the final result produced by the iterator.
290
-
291
- exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
292
- if (PromiseImpl === void 0) PromiseImpl = Promise;
293
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
294
- return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
295
- : iter.next().then(function (result) {
296
- return result.done ? result.value : iter.next();
297
- });
298
- };
299
-
300
- function makeInvokeMethod(innerFn, self, context) {
301
- var state = GenStateSuspendedStart;
302
- return function invoke(method, arg) {
303
- if (state === GenStateExecuting) {
304
- throw new Error("Generator is already running");
305
- }
306
-
307
- if (state === GenStateCompleted) {
308
- if (method === "throw") {
309
- throw arg;
310
- } // Be forgiving, per 25.3.3.3.3 of the spec:
311
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
312
-
313
-
314
- return doneResult();
315
- }
316
-
317
- context.method = method;
318
- context.arg = arg;
319
-
320
- while (true) {
321
- var delegate = context.delegate;
322
-
323
- if (delegate) {
324
- var delegateResult = maybeInvokeDelegate(delegate, context);
325
-
326
- if (delegateResult) {
327
- if (delegateResult === ContinueSentinel) continue;
328
- return delegateResult;
329
- }
330
- }
331
-
332
- if (context.method === "next") {
333
- // Setting context._sent for legacy support of Babel's
334
- // function.sent implementation.
335
- context.sent = context._sent = context.arg;
336
- } else if (context.method === "throw") {
337
- if (state === GenStateSuspendedStart) {
338
- state = GenStateCompleted;
339
- throw context.arg;
340
- }
341
-
342
- context.dispatchException(context.arg);
343
- } else if (context.method === "return") {
344
- context.abrupt("return", context.arg);
345
- }
346
-
347
- state = GenStateExecuting;
348
- var record = tryCatch(innerFn, self, context);
349
-
350
- if (record.type === "normal") {
351
- // If an exception is thrown from innerFn, we leave state ===
352
- // GenStateExecuting and loop back for another invocation.
353
- state = context.done ? GenStateCompleted : GenStateSuspendedYield;
354
-
355
- if (record.arg === ContinueSentinel) {
356
- continue;
357
- }
358
-
359
- return {
360
- value: record.arg,
361
- done: context.done
362
- };
363
- } else if (record.type === "throw") {
364
- state = GenStateCompleted; // Dispatch the exception by looping back around to the
365
- // context.dispatchException(context.arg) call above.
366
-
367
- context.method = "throw";
368
- context.arg = record.arg;
369
- }
370
- }
371
- };
372
- } // Call delegate.iterator[context.method](context.arg) and handle the
373
- // result, either by returning a { value, done } result from the
374
- // delegate iterator, or by modifying context.method and context.arg,
375
- // setting context.delegate to null, and returning the ContinueSentinel.
376
-
377
-
378
- function maybeInvokeDelegate(delegate, context) {
379
- var method = delegate.iterator[context.method];
380
-
381
- if (method === undefined$1) {
382
- // A .throw or .return when the delegate iterator has no .throw
383
- // method always terminates the yield* loop.
384
- context.delegate = null;
385
-
386
- if (context.method === "throw") {
387
- // Note: ["return"] must be used for ES3 parsing compatibility.
388
- if (delegate.iterator["return"]) {
389
- // If the delegate iterator has a return method, give it a
390
- // chance to clean up.
391
- context.method = "return";
392
- context.arg = undefined$1;
393
- maybeInvokeDelegate(delegate, context);
394
-
395
- if (context.method === "throw") {
396
- // If maybeInvokeDelegate(context) changed context.method from
397
- // "return" to "throw", let that override the TypeError below.
398
- return ContinueSentinel;
399
- }
400
- }
401
-
402
- context.method = "throw";
403
- context.arg = new TypeError("The iterator does not provide a 'throw' method");
404
- }
405
-
406
- return ContinueSentinel;
407
- }
408
-
409
- var record = tryCatch(method, delegate.iterator, context.arg);
410
-
411
- if (record.type === "throw") {
412
- context.method = "throw";
413
- context.arg = record.arg;
414
- context.delegate = null;
415
- return ContinueSentinel;
416
- }
417
-
418
- var info = record.arg;
419
-
420
- if (!info) {
421
- context.method = "throw";
422
- context.arg = new TypeError("iterator result is not an object");
423
- context.delegate = null;
424
- return ContinueSentinel;
425
- }
426
-
427
- if (info.done) {
428
- // Assign the result of the finished delegate to the temporary
429
- // variable specified by delegate.resultName (see delegateYield).
430
- context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
431
-
432
- context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
433
- // exception, let the outer generator proceed normally. If
434
- // context.method was "next", forget context.arg since it has been
435
- // "consumed" by the delegate iterator. If context.method was
436
- // "return", allow the original .return call to continue in the
437
- // outer generator.
438
-
439
- if (context.method !== "return") {
440
- context.method = "next";
441
- context.arg = undefined$1;
442
- }
443
- } else {
444
- // Re-yield the result returned by the delegate method.
445
- return info;
446
- } // The delegate iterator is finished, so forget it and continue with
447
- // the outer generator.
448
-
449
-
450
- context.delegate = null;
451
- return ContinueSentinel;
452
- } // Define Generator.prototype.{next,throw,return} in terms of the
453
- // unified ._invoke helper method.
454
-
455
-
456
- defineIteratorMethods(Gp);
457
- define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
458
- // @@iterator function is called on it. Some browsers' implementations of the
459
- // iterator prototype chain incorrectly implement this, causing the Generator
460
- // object to not be returned from this call. This ensures that doesn't happen.
461
- // See https://github.com/facebook/regenerator/issues/274 for more details.
462
-
463
- Gp[iteratorSymbol] = function () {
464
- return this;
465
- };
466
-
467
- Gp.toString = function () {
468
- return "[object Generator]";
469
- };
470
-
471
- function pushTryEntry(locs) {
472
- var entry = {
473
- tryLoc: locs[0]
474
- };
475
-
476
- if (1 in locs) {
477
- entry.catchLoc = locs[1];
478
- }
479
-
480
- if (2 in locs) {
481
- entry.finallyLoc = locs[2];
482
- entry.afterLoc = locs[3];
483
- }
484
-
485
- this.tryEntries.push(entry);
486
- }
487
-
488
- function resetTryEntry(entry) {
489
- var record = entry.completion || {};
490
- record.type = "normal";
491
- delete record.arg;
492
- entry.completion = record;
493
- }
494
-
495
- function Context(tryLocsList) {
496
- // The root entry object (effectively a try statement without a catch
497
- // or a finally block) gives us a place to store values thrown from
498
- // locations where there is no enclosing try statement.
499
- this.tryEntries = [{
500
- tryLoc: "root"
501
- }];
502
- tryLocsList.forEach(pushTryEntry, this);
503
- this.reset(true);
504
- }
505
-
506
- exports.keys = function (object) {
507
- var keys = [];
508
-
509
- for (var key in object) {
510
- keys.push(key);
511
- }
512
-
513
- keys.reverse(); // Rather than returning an object with a next method, we keep
514
- // things simple and return the next function itself.
515
-
516
- return function next() {
517
- while (keys.length) {
518
- var key = keys.pop();
519
-
520
- if (key in object) {
521
- next.value = key;
522
- next.done = false;
523
- return next;
524
- }
525
- } // To avoid creating an additional object, we just hang the .value
526
- // and .done properties off the next function object itself. This
527
- // also ensures that the minifier will not anonymize the function.
528
-
529
-
530
- next.done = true;
531
- return next;
532
- };
533
- };
534
-
535
- function values(iterable) {
536
- if (iterable) {
537
- var iteratorMethod = iterable[iteratorSymbol];
538
-
539
- if (iteratorMethod) {
540
- return iteratorMethod.call(iterable);
541
- }
542
-
543
- if (typeof iterable.next === "function") {
544
- return iterable;
545
- }
546
-
547
- if (!isNaN(iterable.length)) {
548
- var i = -1,
549
- next = function next() {
550
- while (++i < iterable.length) {
551
- if (hasOwn.call(iterable, i)) {
552
- next.value = iterable[i];
553
- next.done = false;
554
- return next;
555
- }
556
- }
557
-
558
- next.value = undefined$1;
559
- next.done = true;
560
- return next;
561
- };
562
-
563
- return next.next = next;
564
- }
565
- } // Return an iterator with no values.
566
-
567
-
568
- return {
569
- next: doneResult
570
- };
571
- }
572
-
573
- exports.values = values;
574
-
575
- function doneResult() {
576
- return {
577
- value: undefined$1,
578
- done: true
579
- };
580
- }
581
-
582
- Context.prototype = {
583
- constructor: Context,
584
- reset: function reset(skipTempReset) {
585
- this.prev = 0;
586
- this.next = 0; // Resetting context._sent for legacy support of Babel's
587
- // function.sent implementation.
588
-
589
- this.sent = this._sent = undefined$1;
590
- this.done = false;
591
- this.delegate = null;
592
- this.method = "next";
593
- this.arg = undefined$1;
594
- this.tryEntries.forEach(resetTryEntry);
595
-
596
- if (!skipTempReset) {
597
- for (var name in this) {
598
- // Not sure about the optimal order of these conditions:
599
- if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
600
- this[name] = undefined$1;
601
- }
602
- }
603
- }
604
- },
605
- stop: function stop() {
606
- this.done = true;
607
- var rootEntry = this.tryEntries[0];
608
- var rootRecord = rootEntry.completion;
609
-
610
- if (rootRecord.type === "throw") {
611
- throw rootRecord.arg;
612
- }
613
-
614
- return this.rval;
615
- },
616
- dispatchException: function dispatchException(exception) {
617
- if (this.done) {
618
- throw exception;
619
- }
620
-
621
- var context = this;
622
-
623
- function handle(loc, caught) {
624
- record.type = "throw";
625
- record.arg = exception;
626
- context.next = loc;
627
-
628
- if (caught) {
629
- // If the dispatched exception was caught by a catch block,
630
- // then let that catch block handle the exception normally.
631
- context.method = "next";
632
- context.arg = undefined$1;
633
- }
634
-
635
- return !!caught;
636
- }
637
-
638
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
639
- var entry = this.tryEntries[i];
640
- var record = entry.completion;
641
-
642
- if (entry.tryLoc === "root") {
643
- // Exception thrown outside of any try block that could handle
644
- // it, so set the completion value of the entire function to
645
- // throw the exception.
646
- return handle("end");
647
- }
648
-
649
- if (entry.tryLoc <= this.prev) {
650
- var hasCatch = hasOwn.call(entry, "catchLoc");
651
- var hasFinally = hasOwn.call(entry, "finallyLoc");
652
-
653
- if (hasCatch && hasFinally) {
654
- if (this.prev < entry.catchLoc) {
655
- return handle(entry.catchLoc, true);
656
- } else if (this.prev < entry.finallyLoc) {
657
- return handle(entry.finallyLoc);
658
- }
659
- } else if (hasCatch) {
660
- if (this.prev < entry.catchLoc) {
661
- return handle(entry.catchLoc, true);
662
- }
663
- } else if (hasFinally) {
664
- if (this.prev < entry.finallyLoc) {
665
- return handle(entry.finallyLoc);
666
- }
667
- } else {
668
- throw new Error("try statement without catch or finally");
669
- }
670
- }
671
- }
672
- },
673
- abrupt: function abrupt(type, arg) {
674
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
675
- var entry = this.tryEntries[i];
676
-
677
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
678
- var finallyEntry = entry;
679
- break;
680
- }
681
- }
682
-
683
- if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
684
- // Ignore the finally entry if control is not jumping to a
685
- // location outside the try/catch block.
686
- finallyEntry = null;
687
- }
688
-
689
- var record = finallyEntry ? finallyEntry.completion : {};
690
- record.type = type;
691
- record.arg = arg;
692
-
693
- if (finallyEntry) {
694
- this.method = "next";
695
- this.next = finallyEntry.finallyLoc;
696
- return ContinueSentinel;
697
- }
698
-
699
- return this.complete(record);
700
- },
701
- complete: function complete(record, afterLoc) {
702
- if (record.type === "throw") {
703
- throw record.arg;
704
- }
705
-
706
- if (record.type === "break" || record.type === "continue") {
707
- this.next = record.arg;
708
- } else if (record.type === "return") {
709
- this.rval = this.arg = record.arg;
710
- this.method = "return";
711
- this.next = "end";
712
- } else if (record.type === "normal" && afterLoc) {
713
- this.next = afterLoc;
714
- }
715
-
716
- return ContinueSentinel;
717
- },
718
- finish: function finish(finallyLoc) {
719
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
720
- var entry = this.tryEntries[i];
721
-
722
- if (entry.finallyLoc === finallyLoc) {
723
- this.complete(entry.completion, entry.afterLoc);
724
- resetTryEntry(entry);
725
- return ContinueSentinel;
726
- }
727
- }
728
- },
729
- "catch": function _catch(tryLoc) {
730
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
731
- var entry = this.tryEntries[i];
732
-
733
- if (entry.tryLoc === tryLoc) {
734
- var record = entry.completion;
735
-
736
- if (record.type === "throw") {
737
- var thrown = record.arg;
738
- resetTryEntry(entry);
739
- }
740
-
741
- return thrown;
742
- }
743
- } // The context.catch method must only be called with a location
744
- // argument that corresponds to a known catch block.
745
-
746
-
747
- throw new Error("illegal catch attempt");
748
- },
749
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
750
- this.delegate = {
751
- iterator: values(iterable),
752
- resultName: resultName,
753
- nextLoc: nextLoc
754
- };
755
-
756
- if (this.method === "next") {
757
- // Deliberately forget the last sent value so that we don't
758
- // accidentally pass it on to the delegate.
759
- this.arg = undefined$1;
760
- }
761
-
762
- return ContinueSentinel;
763
- }
764
- }; // Regardless of whether this script is executing as a CommonJS module
765
- // or not, return the runtime object so that we can declare the variable
766
- // regeneratorRuntime in the outer scope, which allows this module to be
767
- // injected easily by `bin/regenerator --include-runtime script.js`.
768
-
769
- return exports;
770
- }( // If this script is executing as a CommonJS module, use module.exports
771
- // as the regeneratorRuntime namespace. Otherwise create a new empty
772
- // object. Either way, the resulting object will be used to initialize
773
- // the regeneratorRuntime variable at the top of this file.
774
- module.exports );
775
-
776
- try {
777
- regeneratorRuntime = runtime;
778
- } catch (accidentalStrictMode) {
779
- // This module should not be running in strict mode, so the above
780
- // assignment should always work unless something is misconfigured. Just
781
- // in case runtime.js accidentally runs in strict mode, we can escape
782
- // strict mode using a global Function call. This could conceivably fail
783
- // if a Content Security Policy forbids using Function, but in that case
784
- // the proper solution is to fix the accidental strict mode problem. If
785
- // you've misconfigured your bundler to force strict mode and applied a
786
- // CSP to forbid Function, and you're not willing to fix either of those
787
- // problems, please detail your unique predicament in a GitHub issue.
788
- Function("r", "regeneratorRuntime = r")(runtime);
789
- }
790
- });
791
-
792
- function getClarinetDevConfig(_x) {
793
- return _getClarinetDevConfig.apply(this, arguments);
794
- }
795
-
796
- function _getClarinetDevConfig() {
797
- _getClarinetDevConfig = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(folder) {
798
- var baseConfigPath, configContents, config;
799
- return runtime_1.wrap(function _callee$(_context) {
800
- while (1) {
801
- switch (_context.prev = _context.next) {
802
- case 0:
803
- baseConfigPath = resolve(folder, 'settings', 'Devnet.toml');
804
- _context.next = 3;
805
- return readFile(baseConfigPath, {
806
- encoding: 'utf-8'
807
- });
808
-
809
- case 3:
810
- configContents = _context.sent;
811
- config = parse(configContents, 1.0, '\n', false);
812
- return _context.abrupt("return", config);
813
-
814
- case 6:
815
- case "end":
816
- return _context.stop();
817
- }
818
- }
819
- }, _callee);
820
- }));
821
- return _getClarinetDevConfig.apply(this, arguments);
822
- }
823
-
824
- function getClarinetConfig(_x2) {
825
- return _getClarinetConfig.apply(this, arguments);
826
- }
827
-
828
- function _getClarinetConfig() {
829
- _getClarinetConfig = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(folder) {
830
- var baseConfigPath, configContents, config;
831
- return runtime_1.wrap(function _callee2$(_context2) {
832
- while (1) {
833
- switch (_context2.prev = _context2.next) {
834
- case 0:
835
- baseConfigPath = resolve(folder, 'Clarinet.toml');
836
- _context2.next = 3;
837
- return readFile(baseConfigPath, {
838
- encoding: 'utf-8'
839
- });
840
-
841
- case 3:
842
- configContents = _context2.sent;
843
- config = parse(configContents, 1.0, '\n', false);
844
- return _context2.abrupt("return", config);
845
-
846
- case 6:
847
- case "end":
848
- return _context2.stop();
849
- }
850
- }
851
- }, _callee2);
852
- }));
853
- return _getClarinetConfig.apply(this, arguments);
854
- }
855
-
856
- function getContractsFromClarinet(_x3, _x4) {
857
- return _getContractsFromClarinet.apply(this, arguments);
858
- }
859
-
860
- function _getContractsFromClarinet() {
861
- _getContractsFromClarinet = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(folder, accounts) {
862
- var clarinetConfig, deployerAddress, contracts;
863
- return runtime_1.wrap(function _callee3$(_context3) {
864
- while (1) {
865
- switch (_context3.prev = _context3.next) {
866
- case 0:
867
- _context3.next = 2;
868
- return getClarinetConfig(folder);
869
-
870
- case 2:
871
- clarinetConfig = _context3.sent;
872
- deployerAddress = accounts.deployer.address;
873
- contracts = Object.entries(clarinetConfig.contracts).map(function (_ref) {
874
- var info = _ref[1];
875
- var file = info.path.replace(/^contracts\//, '');
876
- return {
877
- file: file,
878
- address: deployerAddress
879
- };
880
- });
881
- return _context3.abrupt("return", contracts);
882
-
883
- case 6:
884
- case "end":
885
- return _context3.stop();
886
- }
887
- }
888
- }, _callee3);
889
- }));
890
- return _getContractsFromClarinet.apply(this, arguments);
891
- }
892
-
893
- function getClarinetAccounts(_x5) {
894
- return _getClarinetAccounts.apply(this, arguments);
895
- }
896
-
897
- function _getClarinetAccounts() {
898
- _getClarinetAccounts = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(folder) {
899
- var devConfig, accountEntries, accounts;
900
- return runtime_1.wrap(function _callee5$(_context5) {
901
- while (1) {
902
- switch (_context5.prev = _context5.next) {
903
- case 0:
904
- _context5.next = 2;
905
- return getClarinetDevConfig(folder);
906
-
907
- case 2:
908
- devConfig = _context5.sent;
909
- _context5.next = 5;
910
- return Promise.all(Object.entries(devConfig.accounts).map( /*#__PURE__*/function () {
911
- var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(_ref2) {
912
- var key, info, wallet, _wallet$accounts, account, address;
913
-
914
- return runtime_1.wrap(function _callee4$(_context4) {
915
- while (1) {
916
- switch (_context4.prev = _context4.next) {
917
- case 0:
918
- key = _ref2[0], info = _ref2[1];
919
- _context4.next = 3;
920
- return generateWallet({
921
- secretKey: info.mnemonic,
922
- password: 'password'
923
- });
924
-
925
- case 3:
926
- wallet = _context4.sent;
927
- _wallet$accounts = wallet.accounts, account = _wallet$accounts[0];
928
- address = getStxAddress({
929
- account: account
930
- });
931
- return _context4.abrupt("return", [key, _extends({}, info, {
932
- address: address
933
- })]);
934
-
935
- case 7:
936
- case "end":
937
- return _context4.stop();
938
- }
939
- }
940
- }, _callee4);
941
- }));
942
-
943
- return function (_x6) {
944
- return _ref3.apply(this, arguments);
945
- };
946
- }()));
947
-
948
- case 5:
949
- accountEntries = _context5.sent;
950
- accounts = Object.fromEntries(accountEntries);
951
- return _context5.abrupt("return", accounts);
952
-
953
- case 8:
954
- case "end":
955
- return _context5.stop();
956
- }
957
- }
958
- }, _callee5);
959
- }));
960
- return _getClarinetAccounts.apply(this, arguments);
961
- }
962
-
963
- function getConfigFile(_x) {
964
- return _getConfigFile.apply(this, arguments);
965
- }
966
-
967
- function _getConfigFile() {
968
- _getConfigFile = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(rootPath) {
969
- var fullPath, configContents, configFile, clarinetPath, accounts, contracts, contractsDir;
970
- return runtime_1.wrap(function _callee$(_context) {
971
- while (1) {
972
- switch (_context.prev = _context.next) {
973
- case 0:
974
- fullPath = resolve(rootPath, 'clarigen.config.json');
975
- _context.next = 3;
976
- return readFile(fullPath, {
977
- encoding: 'utf-8'
978
- });
979
-
980
- case 3:
981
- configContents = _context.sent;
982
- configFile = JSON.parse(configContents);
983
-
984
- if (configFile.outputDir) {
985
- _context.next = 7;
986
- break;
987
- }
988
-
989
- throw new Error('Config file missing "outputDir"');
990
-
991
- case 7:
992
- if (!('clarinet' in configFile)) {
993
- _context.next = 17;
994
- break;
995
- }
996
-
997
- clarinetPath = resolve(rootPath, configFile.clarinet);
998
- _context.next = 11;
999
- return getClarinetAccounts(clarinetPath);
1000
-
1001
- case 11:
1002
- accounts = _context.sent;
1003
- _context.next = 14;
1004
- return getContractsFromClarinet(clarinetPath, accounts);
1005
-
1006
- case 14:
1007
- contracts = _context.sent;
1008
- contractsDir = relative(process.cwd(), join(configFile.clarinet, 'contracts'));
1009
- return _context.abrupt("return", _extends({}, configFile, {
1010
- contracts: contracts,
1011
- contractsDir: contractsDir,
1012
- accounts: accounts
1013
- }));
1014
-
1015
- case 17:
1016
- if (configFile.contracts) {
1017
- _context.next = 19;
1018
- break;
1019
- }
1020
-
1021
- throw new Error('Config file missing "contracts"');
1022
-
1023
- case 19:
1024
- if (configFile.contractsDir) {
1025
- _context.next = 21;
1026
- break;
1027
- }
1028
-
1029
- throw new Error('Config file missing "contractDir"');
1030
-
1031
- case 21:
1032
- return _context.abrupt("return", configFile);
1033
-
1034
- case 22:
1035
- case "end":
1036
- return _context.stop();
1037
- }
1038
- }
1039
- }, _callee);
1040
- }));
1041
- return _getConfigFile.apply(this, arguments);
1042
- }
1043
-
1044
- var cvFromType = function cvFromType(val) {
1045
- if (isClarityAbiPrimitive(val)) {
1046
- if (val === 'uint128') {
1047
- return 'ClarityTypes.UIntCV';
1048
- } else if (val === 'int128') {
1049
- return 'ClarityTypes.IntCV';
1050
- } else if (val === 'bool') {
1051
- return 'ClarityTypes.BooleanCV';
1052
- } else if (val === 'principal') {
1053
- return 'ClarityTypes.PrincipalCV';
1054
- } else if (val === 'none') {
1055
- return 'ClarityTypes.NoneCV';
1056
- } else {
1057
- throw new Error("Unexpected Clarity ABI type primitive: " + JSON.stringify(val));
1058
- }
1059
- } else if (isClarityAbiBuffer(val)) {
1060
- return 'ClarityTypes.BufferCV';
1061
- } else if (isClarityAbiResponse(val)) {
1062
- return 'ClarityTypes.ResponseCV';
1063
- } else if (isClarityAbiOptional(val)) {
1064
- return 'ClarityTypes.OptionalCV';
1065
- } else if (isClarityAbiTuple(val)) {
1066
- return 'ClarityTypes.TupleCV';
1067
- } else if (isClarityAbiList(val)) {
1068
- return 'ClarityTypes.ListCV';
1069
- } else if (isClarityAbiStringAscii(val)) {
1070
- return 'ClarityTypes.StringAsciiCV';
1071
- } else if (isClarityAbiStringUtf8(val)) {
1072
- return 'ClarityTypes.StringUtf8CV';
1073
- } else {
1074
- throw new Error("Unexpected Clarity ABI type: " + JSON.stringify(val));
1075
- }
1076
- };
1077
- var jsTypeFromAbiType = function jsTypeFromAbiType(val, isArgument) {
1078
- if (isArgument === void 0) {
1079
- isArgument = false;
1080
- }
1081
-
1082
- if (isClarityAbiPrimitive(val)) {
1083
- if (val === 'uint128') {
1084
- if (isArgument) return 'number | bigint';
1085
- return 'bigint';
1086
- } else if (val === 'int128') {
1087
- if (isArgument) return 'number | bigint';
1088
- return 'bigint';
1089
- } else if (val === 'bool') {
1090
- return 'boolean';
1091
- } else if (val === 'principal') {
1092
- return 'string';
1093
- } else if (val === 'none') {
1094
- return 'null';
1095
- } else if (val === 'trait_reference') {
1096
- return 'string';
1097
- } else {
1098
- throw new Error("Unexpected Clarity ABI type primitive: " + JSON.stringify(val));
1099
- }
1100
- } else if (isClarityAbiBuffer(val)) {
1101
- return 'Buffer';
1102
- } else if (isClarityAbiResponse(val)) {
1103
- var ok = jsTypeFromAbiType(val.response.ok);
1104
- var err = jsTypeFromAbiType(val.response.error);
1105
- return "ClarityTypes.Response<" + ok + ", " + err + ">";
1106
- } else if (isClarityAbiOptional(val)) {
1107
- var innerType = jsTypeFromAbiType(val.optional);
1108
- return innerType + " | null";
1109
- } else if (isClarityAbiTuple(val)) {
1110
- var tupleDefs = [];
1111
- val.tuple.forEach(function (_ref) {
1112
- var name = _ref.name,
1113
- type = _ref.type;
1114
- var innerType = jsTypeFromAbiType(type);
1115
- tupleDefs.push("\"" + name + "\": " + innerType);
1116
- });
1117
- return "{\n " + tupleDefs.join(';\n ') + "\n }";
1118
- } else if (isClarityAbiList(val)) {
1119
- var _innerType = jsTypeFromAbiType(val.list.type);
1120
-
1121
- return _innerType + "[]";
1122
- } else if (isClarityAbiStringAscii(val)) {
1123
- return 'string';
1124
- } else if (isClarityAbiStringUtf8(val)) {
1125
- return 'string';
1126
- } else if (val === 'trait_reference') {
1127
- return 'string';
1128
- } else {
1129
- throw new Error("Unexpected Clarity ABI type: " + JSON.stringify(val));
1130
- }
1131
- };
1132
- var makeTypes = function makeTypes(abi) {
1133
- var typings = '';
1134
- abi.functions.forEach(function (func, index) {
1135
- if (func.access === 'private') return;
1136
- var functionLine = toCamelCase(func.name) + ": ";
1137
- var args = func.args.map(function (arg) {
1138
- return toCamelCase(arg.name) + ": " + jsTypeFromAbiType(arg.type, true);
1139
- });
1140
- functionLine += "(" + args.join(', ') + ") => ";
1141
-
1142
- if (func.access === 'public') {
1143
- var type = func.outputs.type;
1144
- if (!isClarityAbiResponse(type)) throw new Error('Expected response type for public function');
1145
- functionLine += 'Transaction';
1146
- var ok = jsTypeFromAbiType(type.response.ok);
1147
- var err = jsTypeFromAbiType(type.response.error);
1148
- functionLine += "<" + ok + ", " + err + ">;";
1149
- } else {
1150
- var jsType = jsTypeFromAbiType(func.outputs.type);
1151
- functionLine += "Promise<" + jsType + ">;"; // const { type } = func.outputs;
1152
- // if (isClarityAbiResponse(type)) {
1153
- // const ok = jsTypeFromAbiType(type.response.ok);
1154
- // const err = jsTypeFromAbiType(type.response.error);
1155
- // functionLine += `Promise<ClarityTypes.Response<${ok}, ${err}>>;`;
1156
- // } else {
1157
- // const jsType = jsTypeFromAbiType(func.outputs.type);
1158
- // functionLine += `Promise<${jsType}>;`;
1159
- // }
1160
- }
1161
-
1162
- typings += (index === 0 ? '' : '\n') + " " + functionLine;
1163
- });
1164
- return typings;
1165
- };
1166
-
1167
- var generateInterface = /*#__PURE__*/function () {
1168
- var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref) {
1169
- var _provider, contractFile, _ref$contractAddress, contractAddress, provider, contractName, receipt, output, initialization, _initialization$split, error, trace, startLine, matcher, matches, abi;
1170
-
1171
- return runtime_1.wrap(function _callee$(_context) {
1172
- while (1) {
1173
- switch (_context.prev = _context.next) {
1174
- case 0:
1175
- _provider = _ref.provider, contractFile = _ref.contractFile, _ref$contractAddress = _ref.contractAddress, contractAddress = _ref$contractAddress === void 0 ? 'S1G2081040G2081040G2081040G208105NK8PE5' : _ref$contractAddress;
1176
- _context.t0 = _provider;
1177
-
1178
- if (_context.t0) {
1179
- _context.next = 6;
1180
- break;
1181
- }
1182
-
1183
- _context.next = 5;
1184
- return createClarityBin();
1185
-
1186
- case 5:
1187
- _context.t0 = _context.sent;
1188
-
1189
- case 6:
1190
- provider = _context.t0;
1191
- contractName = getContractNameFromPath(contractFile);
1192
- _context.next = 10;
1193
- return provider.runCommand(['launch', contractAddress + "." + contractName, contractFile, provider.dbFilePath, '--output_analysis', '--costs', '--assets']);
1194
-
1195
- case 10:
1196
- receipt = _context.sent;
1197
-
1198
- if (!receipt.stderr) {
1199
- _context.next = 13;
1200
- break;
1201
- }
1202
-
1203
- throw new Error("Error on " + contractFile + ":\n " + receipt.stderr + "\n ");
1204
-
1205
- case 13:
1206
- output = JSON.parse(receipt.stdout);
1207
-
1208
- if (!output.error) {
1209
- _context.next = 24;
1210
- break;
1211
- }
1212
-
1213
- initialization = output.error.initialization;
1214
-
1215
- if (!(initialization != null && initialization.includes('\nNear:\n'))) {
1216
- _context.next = 23;
1217
- break;
1218
- }
1219
-
1220
- _initialization$split = initialization.split('\nNear:\n'), error = _initialization$split[0], trace = _initialization$split[1];
1221
- startLine = '';
1222
- matcher = /start_line: (\d+),/;
1223
- matches = matcher.exec(trace);
1224
- if (matches) startLine = matches[1];
1225
- throw new Error("Error on " + contractFile + ":\n " + error + "\n " + (startLine ? "Near line " + startLine : '') + "\n Raw trace:\n " + trace + "\n ");
1226
-
1227
- case 23:
1228
- throw new Error("Error on " + contractFile + ":\n " + JSON.stringify(output.error, null, 2) + "\n ");
1229
-
1230
- case 24:
1231
- abi = output.analysis;
1232
- return _context.abrupt("return", abi);
1233
-
1234
- case 26:
1235
- case "end":
1236
- return _context.stop();
1237
- }
1238
- }
1239
- }, _callee);
1240
- }));
1241
-
1242
- return function generateInterface(_x) {
1243
- return _ref2.apply(this, arguments);
1244
- };
1245
- }();
1246
- var generateInterfaceFile = function generateInterfaceFile(_ref3) {
1247
- var contractFile = _ref3.contractFile,
1248
- abi = _ref3.abi;
1249
- var contractName = getContractNameFromPath(contractFile);
1250
- var variableName = toCamelCase(contractName, true);
1251
- var abiString = JSON.stringify(abi, null, 2);
1252
- var fileContents = "import { ClarityAbi } from '@clarigen/core';\n\n// prettier-ignore\nexport const " + variableName + "Interface: ClarityAbi = " + abiString + ";\n";
1253
- return fileContents;
1254
- };
1255
- var generateIndexFile = function generateIndexFile(_ref4) {
1256
- var contractFile = _ref4.contractFile,
1257
- address = _ref4.address;
1258
- var contractName = getContractNameFromPath(contractFile);
1259
- var contractTitle = toCamelCase(contractName, true);
1260
- var varName = toCamelCase(contractName);
1261
- var contractType = contractTitle + "Contract";
1262
- var fileContents = "import { proxy, BaseProvider, Contract } from '@clarigen/core';\nimport type { " + contractType + " } from './types';\nimport { " + contractTitle + "Interface } from './abi';\nexport type { " + contractType + " } from './types';\n\nexport const " + varName + "Contract = (provider: BaseProvider) => {\n const contract = proxy<" + contractType + ">(" + contractTitle + "Interface, provider);\n return contract;\n};\n\nexport const " + varName + "Info: Contract<" + contractType + "> = {\n contract: " + varName + "Contract,\n address: '" + address + "',\n contractFile: '" + contractFile + "',\n};\n";
1263
- return fileContents;
1264
- };
1265
- var generateTypesFile = function generateTypesFile(abi, contractName) {
1266
- var name = toCamelCase(contractName, true);
1267
- var typings = makeTypes(abi);
1268
- var fileContents = "import { ClarityTypes, Transaction } from '@clarigen/core';\n\n// prettier-ignore\nexport interface " + name + "Contract {\n" + typings + "\n}\n";
1269
- return fileContents;
1270
- };
1271
- var generateProjectIndexFile = function generateProjectIndexFile(config) {
1272
- var imports = [];
1273
- var exports = [];
1274
- var contractMap = [];
1275
- var accounts = '';
1276
-
1277
- if ('accounts' in config) {
1278
- accounts = "\n\n// prettier-ignore\nexport const accounts = " + JSON.stringify(config.accounts, null, 2) + ";";
1279
- }
1280
-
1281
- config.contracts.forEach(function (contract) {
1282
- var contractName = getContractNameFromPath(contract.file);
1283
- var contractVar = toCamelCase(contractName);
1284
- var contractInfo = contractVar + "Info";
1285
- var contractInterface = toCamelCase(contractName, true) + "Contract";
1286
- var dirName = dirname(contract.file);
1287
- var importPath = "'./" + join(dirName || '.', contractName) + "'";
1288
-
1289
- var _import = "import { " + contractInfo + " } from " + importPath + ";";
1290
-
1291
- imports.push(_import);
1292
-
1293
- var _export = "export type { " + contractInterface + " } from " + importPath + ";";
1294
-
1295
- exports.push(_export);
1296
- var map = contractVar + ": " + contractInfo + ",";
1297
- contractMap.push(map);
1298
- });
1299
- var file = imports.join('\n') + "\n" + exports.join('\n') + "\n\nexport const contracts = {\n " + contractMap.join('\n ') + "\n};" + accounts + "\n";
1300
- return file;
1301
- };
1302
-
1303
- export { cvFromType, generateIndexFile, generateInterface, generateInterfaceFile, generateProjectIndexFile, generateTypesFile, getConfigFile, jsTypeFromAbiType, makeTypes };
1304
- //# sourceMappingURL=cli.esm.js.map