datai-sdk 1.1.1 → 1.1.2
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.
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { Writer, Reader } from "as-proto/assembly";
|
|
7
7
|
import { TokenBalancePb } from "./TokenBalancePb";
|
|
8
|
-
import { Timestamp } from "
|
|
8
|
+
import { Timestamp } from "../../google/protobuf/Timestamp";
|
|
9
9
|
import { NftItemPb } from "./NftItemPb";
|
|
10
10
|
import { PerpPositionPb } from "./PerpPositionPb";
|
|
11
11
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Patch @graphprotocol/graph-ts to fix AssemblyScript type inference issue
|
|
3
|
+
*
|
|
4
|
+
* The issue: `assert(this !== null, ...)` in BigInt/BigDecimal methods causes
|
|
5
|
+
* AssemblyScript to infer `this` as `T | null`, which breaks type checking.
|
|
6
|
+
*
|
|
7
|
+
* This script removes the problematic assertions since:
|
|
8
|
+
* 1. In AssemblyScript, `this` in a class method can never be null when called normally
|
|
9
|
+
* 2. The assertions were added for defensive purposes but break compilation
|
|
10
|
+
*
|
|
11
|
+
* Run this script after `npm install` in the consuming project.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const path = require('path');
|
|
16
|
+
|
|
17
|
+
// Find the graph-ts installation
|
|
18
|
+
const possiblePaths = [
|
|
19
|
+
path.resolve(__dirname, 'node_modules/@graphprotocol/graph-ts/common/numbers.ts'),
|
|
20
|
+
path.resolve(__dirname, '../node_modules/@graphprotocol/graph-ts/common/numbers.ts'),
|
|
21
|
+
path.resolve(process.cwd(), 'node_modules/@graphprotocol/graph-ts/common/numbers.ts'),
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
let numbersPath = null;
|
|
25
|
+
for (const p of possiblePaths) {
|
|
26
|
+
if (fs.existsSync(p)) {
|
|
27
|
+
numbersPath = p;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!numbersPath) {
|
|
33
|
+
console.log('graph-ts numbers.ts not found. Skipping patch (may already be patched or graph-ts not installed).');
|
|
34
|
+
process.exit(0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
console.log(`Patching ${numbersPath}...`);
|
|
38
|
+
|
|
39
|
+
let content = fs.readFileSync(numbersPath, 'utf8');
|
|
40
|
+
|
|
41
|
+
// Pattern to match assertions like:
|
|
42
|
+
// assert(this !== null, "Failed to ... because left hand side is 'null'");
|
|
43
|
+
// or "... value of it is 'null'"
|
|
44
|
+
const assertPattern = /assert\(this !== null, "Failed to [^"]+"\);\n/g;
|
|
45
|
+
|
|
46
|
+
// Count matches
|
|
47
|
+
const matches = content.match(assertPattern);
|
|
48
|
+
if (!matches || matches.length === 0) {
|
|
49
|
+
console.log('File appears to already be patched or has different format. Skipping.');
|
|
50
|
+
process.exit(0);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
console.log(`Found ${matches.length} assertions to remove.`);
|
|
54
|
+
|
|
55
|
+
// Remove the problematic assertions
|
|
56
|
+
const patched = content.replace(assertPattern, '');
|
|
57
|
+
|
|
58
|
+
// Backup original
|
|
59
|
+
const backupPath = numbersPath + '.bak';
|
|
60
|
+
if (!fs.existsSync(backupPath)) {
|
|
61
|
+
fs.writeFileSync(backupPath, content);
|
|
62
|
+
console.log(`Backup created at ${backupPath}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Write patched version
|
|
66
|
+
fs.writeFileSync(numbersPath, patched);
|
|
67
|
+
console.log('Patch applied successfully!');
|
|
68
|
+
console.log('Removed assert(this !== null, ...) statements from BigInt and BigDecimal methods.');
|
package/postinstall-script.js
CHANGED
|
@@ -34,3 +34,52 @@ if (fs.existsSync(destinationFolder)) {
|
|
|
34
34
|
fs.renameSync(sourceFolder, destinationFolder);
|
|
35
35
|
|
|
36
36
|
console.log(`Folder "${sourceFolder}" moved to "${destinationFolder}".`);
|
|
37
|
+
|
|
38
|
+
// ============================================================
|
|
39
|
+
// Apply graph-ts patch to fix AssemblyScript type inference bug
|
|
40
|
+
// ============================================================
|
|
41
|
+
// The issue: `assert(this !== null, ...)` in BigInt/BigDecimal methods causes
|
|
42
|
+
// AssemblyScript to infer `this` as `T | null`, which breaks type checking.
|
|
43
|
+
// We remove these assertions as `this` can never be null in normal class method calls.
|
|
44
|
+
|
|
45
|
+
const graphTsPaths = [
|
|
46
|
+
// When installed as dependency (looks in parent's node_modules)
|
|
47
|
+
path.resolve(__dirname, "../node_modules/@graphprotocol/graph-ts/common/numbers.ts"),
|
|
48
|
+
// When running from project root
|
|
49
|
+
path.resolve(process.cwd(), "node_modules/@graphprotocol/graph-ts/common/numbers.ts"),
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
let patchApplied = false;
|
|
53
|
+
for (const numbersPath of graphTsPaths) {
|
|
54
|
+
if (fs.existsSync(numbersPath)) {
|
|
55
|
+
try {
|
|
56
|
+
let content = fs.readFileSync(numbersPath, "utf8");
|
|
57
|
+
const assertPattern = /assert\(this !== null, "Failed to [^"]+"\);\n/g;
|
|
58
|
+
const matches = content.match(assertPattern);
|
|
59
|
+
|
|
60
|
+
if (matches && matches.length > 0) {
|
|
61
|
+
console.log(`Patching ${numbersPath}...`);
|
|
62
|
+
console.log(`Found ${matches.length} assertions to remove.`);
|
|
63
|
+
|
|
64
|
+
// Backup original
|
|
65
|
+
const backupPath = numbersPath + ".bak";
|
|
66
|
+
if (!fs.existsSync(backupPath)) {
|
|
67
|
+
fs.writeFileSync(backupPath, content);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Remove assertions
|
|
71
|
+
const patched = content.replace(assertPattern, "");
|
|
72
|
+
fs.writeFileSync(numbersPath, patched);
|
|
73
|
+
console.log("graph-ts patch applied successfully!");
|
|
74
|
+
patchApplied = true;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
} catch (e) {
|
|
78
|
+
console.log(`Warning: Could not patch ${numbersPath}: ${e.message}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!patchApplied) {
|
|
84
|
+
console.log("graph-ts already patched or not found. Skipping patch.");
|
|
85
|
+
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// Code generated by protoc-gen-as. DO NOT EDIT.
|
|
2
|
-
// Versions:
|
|
3
|
-
// protoc-gen-as v1.3.0
|
|
4
|
-
// protoc v6.33.4
|
|
5
|
-
|
|
6
|
-
import { Writer, Reader } from "as-proto/assembly";
|
|
7
|
-
|
|
8
|
-
export class Timestamp {
|
|
9
|
-
static encode(message: Timestamp, writer: Writer): void {
|
|
10
|
-
writer.uint32(8);
|
|
11
|
-
writer.int64(message.seconds);
|
|
12
|
-
|
|
13
|
-
writer.uint32(16);
|
|
14
|
-
writer.int32(message.nanos);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
static decode(reader: Reader, length: i32): Timestamp {
|
|
18
|
-
const end: usize = length < 0 ? reader.end : reader.ptr + length;
|
|
19
|
-
const message = new Timestamp();
|
|
20
|
-
|
|
21
|
-
while (reader.ptr < end) {
|
|
22
|
-
const tag = reader.uint32();
|
|
23
|
-
switch (tag >>> 3) {
|
|
24
|
-
case 1:
|
|
25
|
-
message.seconds = reader.int64();
|
|
26
|
-
break;
|
|
27
|
-
|
|
28
|
-
case 2:
|
|
29
|
-
message.nanos = reader.int32();
|
|
30
|
-
break;
|
|
31
|
-
|
|
32
|
-
default:
|
|
33
|
-
reader.skipType(tag & 7);
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return message;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
seconds: i64;
|
|
42
|
-
nanos: i32;
|
|
43
|
-
|
|
44
|
-
constructor(seconds: i64 = 0, nanos: i32 = 0) {
|
|
45
|
-
this.seconds = seconds;
|
|
46
|
-
this.nanos = nanos;
|
|
47
|
-
}
|
|
48
|
-
}
|