@fastnear/repl 0.7.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.
@@ -0,0 +1,30 @@
1
+ near.exp.borsh.deserialize(near.exp.borshSchema.SignedTransaction, unborsh)
2
+ v(unborsh)
3
+ unborsh
4
+ unborsh = near.exp.borsh.serialize(near.exp.borshSchema.SignedTransaction, mockTx)
5
+ v(near.exp.borsh.serialize(near.exp.borshSchema.SignedTransaction, mockTx))
6
+ near.exp.borsh.serialize(near.exp.borshSchema.SignedTransaction, mockTx)
7
+ near.exp.borshSchema.SignedTransaction
8
+ near.exp.borshSchema
9
+ near.exp.borshSchema()
10
+ near.exp.borshSchema().SignedTransaction
11
+ near.exp.borshSchema
12
+ near.exp.borshSchema.SignedTransaction
13
+ near.exp.borsh.serialize(near.exp.borshSchema.SignedTransaction, mockTx)
14
+ near.utils.bor
15
+ near.borsh
16
+ near.borsh.
17
+ v(mockTx)
18
+ mockTx
19
+ near.actions.functionCall()
20
+ near.actions.functionCall
21
+ near.actions
22
+ near
23
+ v(mockTx)
24
+ mockTx
25
+ {"hi":"mike"}
26
+ near.queryRpc['?']
27
+ Object.getOwnPropertyNames(near.queryRpc)
28
+ near.queryRpc.?
29
+ near.queryRpc
30
+ near.queryRpc.''
package/index.mjs ADDED
@@ -0,0 +1,130 @@
1
+ import "./setup-mock-window.mjs"
2
+ import * as api from "@fastnear/api"
3
+ import { start } from "repl";
4
+
5
+ import util from "util";
6
+
7
+ const { toBase58 } = api.utils
8
+
9
+ console.log("REPL going. Try `near.` <tab>");
10
+ console.log("Use `v(obj)` to print verbose objects in a readable format.");
11
+
12
+ let r = start({
13
+ prompt: "» ",
14
+ terminal: true,
15
+ useGlobal: true,
16
+ useColors: true,
17
+ preview: true,
18
+ writer: (output) => util.inspect(deepTransform(output), {
19
+ depth: 10,
20
+ colors: true,
21
+ compact: 3,
22
+ breakLength: 100,
23
+ numericSeparator: true,
24
+ maxArrayLength: 3,
25
+ })
26
+ });
27
+
28
+ // Ensure `r.context` is set before assigning values
29
+ if (!r.context) {
30
+ throw new Error("REPL context is not available.");
31
+ }
32
+
33
+ r.context.near = api;
34
+
35
+ const historyPath = '.fastnear-repl-history';
36
+ r.setupHistory(historyPath, (err) => {
37
+ if (err) console.warn('History file setup failed:', err);
38
+ });
39
+
40
+ // Debugging mock transaction
41
+ r.context.mockTx = {
42
+ transaction: {
43
+ signerId: "mike.near",
44
+ publicKey: { ed25519Key: { data: new Uint8Array([43, 42, 151, 72, 199, 53, 179, 42, 8, 123, 194, 172, 211, 250, 107, 15, 228, 162, 48, 243, 218, 222, 41, 215, 6, 236, 110, 137, 115, 14, 126, 103]) } },
45
+ nonce: "138915472000056",
46
+ receiverId: "berryclub.ek.near",
47
+ // blockHash: new Uint8Array([9, 200, 86, 207, 242, 138, 105, 234, 157, 248, 62, 2, 163, 22, 134, 158, 174, 99, 12, 51, 240, 88, 111, 127, 61, 177, 43, 18, 234, 171, 103, 253]),
48
+ blockHash: new Uint8Array([85,135,31,232,88,212,73,163,9,119,126,75,46,134,99,103,94,101,197,142,119,95,125,36,69,60,92,84,72,121,190,171]),
49
+ actions: [
50
+ {
51
+ functionCall: {
52
+ methodName: "draw",
53
+ args: new Uint8Array([123, 34, 112, 105, 120, 101, 108, 115, 34, 58, 91, 123, 34, 120, 34, 58, 50, 44, 34, 121, 34, 58, 50, 49, 44, 34, 99, 111, 108, 111, 114, 34, 58, 51, 57, 51, 53, 55, 52, 56, 125, 93, 125]),
54
+ gas: "100000000000000",
55
+ deposit: "0",
56
+ },
57
+ },
58
+ ],
59
+ },
60
+ signature: { ed25519Signature: { data: new Uint8Array([249, 246, 195, 70, 237, 194, 62, 136, 248, 144, 192, 136, 242, 61, 221, 240, 131, 208, 27, 121, 93, 77, 167, 19, 180, 198, 153, 95, 168, 236, 89, 12, 120, 81, 133, 15, 116, 27, 223, 190, 168, 32, 28, 147, 175, 16, 226, 112, 48, 203, 126, 117, 193, 47, 169, 38, 64, 3, 246, 251, 4, 190, 80, 9]) } }
61
+ };
62
+
63
+ const encoder = new TextDecoder("utf-8");
64
+
65
+ const formatArray = (arr) => {
66
+ if (!(arr instanceof Uint8Array)) return arr;
67
+ return `Uint8Array(${arr.length}) [ ${[...arr.slice(0, 3)].join(", ")}, … ]`;
68
+ };
69
+
70
+ const deepTransform = (input) => {
71
+ if (typeof input !== "object" || input === null) return input;
72
+
73
+ if (input instanceof Uint8Array) return formatArray(input);
74
+
75
+ const newObj = {};
76
+ for (const key in input) {
77
+ if (key === "args" && input[key] instanceof Uint8Array) {
78
+ try {
79
+ const utf8Decoded = encoder.decode(input[key]);
80
+ const jsonParsed = JSON.parse(utf8Decoded);
81
+ newObj["__argsObject"] = jsonParsed;
82
+ } catch (err) {
83
+ // Silently skip invalid JSON
84
+ }
85
+ newObj[key] = formatArray(input[key]);
86
+ } else if (key === "ed25519Signature" && input[key]?.data instanceof Uint8Array) {
87
+ newObj["__signatureBase58"] = toBase58(input[key].data);
88
+ newObj[key] = deepTransform(input[key]);
89
+ } else if (key === "blockHash" && input[key] instanceof Uint8Array) {
90
+ newObj["__blockHashBase58"] = toBase58(input[key]);
91
+ newObj[key] = formatArray(input[key]);
92
+ } else if (key === "ed25519Key" && input[key]?.data instanceof Uint8Array) {
93
+ newObj["__publicKeyBase58"] = toBase58(input[key].data);
94
+ newObj[key] = deepTransform(input[key]);
95
+ } else {
96
+ newObj[key] = deepTransform(input[key]);
97
+ }
98
+ }
99
+ return newObj;
100
+ };
101
+
102
+ r.context.v = (obj, depth = null) => {
103
+ const transformUint8Arrays = (input) => {
104
+ if (input instanceof Uint8Array) {
105
+ return Array.from(input);
106
+ }
107
+ if (typeof input === "object" && input !== null) {
108
+ if (Array.isArray(input)) {
109
+ return input.map(transformUint8Arrays);
110
+ }
111
+ return Object.fromEntries(
112
+ Object.entries(input).map(([key, value]) => [key, transformUint8Arrays(value)])
113
+ );
114
+ }
115
+ return input;
116
+ };
117
+
118
+ const transformedObj = transformUint8Arrays(obj);
119
+
120
+ console.log(
121
+ util.inspect(obj, {
122
+ depth: null,
123
+ colors: true,
124
+ maxArrayLength: null,
125
+ })
126
+ );
127
+
128
+ console.log("\n------ JSON:\n");
129
+ return JSON.stringify(transformedObj, null, '');
130
+ };
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@fastnear/repl",
3
+ "version": "0.7.0",
4
+ "license": "MIT",
5
+ "description": "Simple REPL to explore NEAR blockchain objects",
6
+ "bin": "./index.mjs",
7
+ "type": "module",
8
+ "scripts": {
9
+ "start": "node index.mjs",
10
+ "publish": "yarn npm publish",
11
+ "clean": "yarn rimraf node_modules"
12
+ },
13
+ "dependencies": {
14
+ "@fastnear/api": "0.7.0"
15
+ },
16
+ "devDependencies": {
17
+ "rimraf": "*"
18
+ }
19
+ }
@@ -0,0 +1,18 @@
1
+ import { EventEmitter } from "events";
2
+
3
+ global.window = Object.assign(new EventEmitter(), {
4
+ location: { href: "http://localhost/" },
5
+ addEventListener(event, handler) {
6
+ this.on(event, handler);
7
+ },
8
+ removeEventListener(event, handler) {
9
+ this.off(event, handler);
10
+ },
11
+ dispatchEvent(event) {
12
+ this.emit(event.type, event);
13
+ },
14
+ history: {
15
+ replaceState() {},
16
+ pushState() {},
17
+ },
18
+ });