@dappworks/kit 0.4.176 → 0.4.178
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/StorageState-qzikHBY8.d.ts +66 -0
- package/dist/aiem.mjs +3 -1231
- package/dist/aiem.mjs.map +1 -1
- package/dist/chunk-2EXDWOHY.mjs +58 -0
- package/dist/chunk-3DOB34HY.mjs +292 -0
- package/dist/chunk-3DOB34HY.mjs.map +1 -0
- package/dist/{chunk-3O7QI47S.mjs → chunk-3HD22664.mjs} +2 -2
- package/dist/chunk-5JMONDHE.mjs +436 -0
- package/dist/chunk-5JMONDHE.mjs.map +1 -0
- package/dist/chunk-L6XS2K2K.mjs +76 -0
- package/dist/chunk-L6XS2K2K.mjs.map +1 -0
- package/dist/{chunk-AIZ7XDNV.mjs → chunk-TQNAAA4I.mjs} +22 -21
- package/dist/chunk-TQNAAA4I.mjs.map +1 -0
- package/dist/{chunk-GKK6EXKY.mjs → chunk-XSLAZWOE.mjs} +4 -4
- package/dist/dev.d.mts +3 -3
- package/dist/dev.mjs +2 -2
- package/dist/experimental.d.mts +3 -3
- package/dist/experimental.mjs +1 -1
- package/dist/form.d.mts +15 -15
- package/dist/form.mjs +2 -2
- package/dist/form.mjs.map +1 -1
- package/dist/index.d.mts +6 -67
- package/dist/index.mjs +3 -291
- package/dist/index.mjs.map +1 -1
- package/dist/inspector.d.mts +2 -2
- package/dist/inspector.mjs +1 -1
- package/dist/jsontable.d.mts +8 -8
- package/dist/jsontable.mjs +4 -4
- package/dist/metrics.d.mts +15 -15
- package/dist/metrics.mjs +4 -4
- package/dist/plugins.d.mts +11 -11
- package/dist/plugins.mjs +21 -83
- package/dist/plugins.mjs.map +1 -1
- package/dist/ui.d.mts +7 -7
- package/dist/ui.mjs +3 -3
- package/dist/utils.mjs +1 -1
- package/dist/wallet.d.mts +160 -0
- package/dist/wallet.mjs +3652 -0
- package/dist/wallet.mjs.map +1 -0
- package/package.json +13 -3
- package/dist/chunk-AIZ7XDNV.mjs.map +0 -1
- package/dist/chunk-R4SQKVDQ.mjs +0 -35
- /package/dist/{chunk-R4SQKVDQ.mjs.map → chunk-2EXDWOHY.mjs.map} +0 -0
- /package/dist/{chunk-3O7QI47S.mjs.map → chunk-3HD22664.mjs.map} +0 -0
- /package/dist/{chunk-GKK6EXKY.mjs.map → chunk-XSLAZWOE.mjs.map} +0 -0
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
import { helper } from './chunk-UPGWJHSO.mjs';
|
|
2
|
+
import { __spreadProps, __spreadValues, __objRest } from './chunk-2EXDWOHY.mjs';
|
|
3
|
+
import { createPublicClient, http, getContract, encodeFunctionData } from 'viem';
|
|
4
|
+
import { iotexTestnet, mainnet, iotex, bsc, polygon } from 'viem/chains';
|
|
5
|
+
import TTLCache from '@isaacs/ttlcache';
|
|
6
|
+
import 'reflect-metadata';
|
|
7
|
+
import BigNumber from 'bignumber.js';
|
|
8
|
+
|
|
9
|
+
var FIELD_KEY = Symbol("aiem_field");
|
|
10
|
+
var metadataCache = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
var Fields = class _Fields {
|
|
12
|
+
static hide(options = {}) {
|
|
13
|
+
return function(target, propertyKey, descriptor) {
|
|
14
|
+
_Fields.setMetadata(target, propertyKey, { type: "hide", options });
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
static read(options = {}) {
|
|
18
|
+
return function(target, propertyKey, descriptor) {
|
|
19
|
+
_Fields.setMetadata(target, propertyKey, { type: "read", options });
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
static write(options = {}) {
|
|
23
|
+
return function(target, propertyKey, descriptor) {
|
|
24
|
+
_Fields.setMetadata(target, propertyKey, { type: "write", options });
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
static custom(func = {}) {
|
|
28
|
+
return function(target, propertyKey, descriptor) {
|
|
29
|
+
_Fields.setMetadata(target, propertyKey, { type: "custom", func });
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
static relation(entity, options) {
|
|
33
|
+
return function(target, propertyKey, descriptor) {
|
|
34
|
+
_Fields.setMetadata(target, propertyKey, { type: "entity", entity, targetKey: options });
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
static contract(entity, options) {
|
|
38
|
+
return function(target, propertyKey, descriptor) {
|
|
39
|
+
_Fields.setMetadata(target, propertyKey, { type: "entity", entity, targetKey: options });
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
static setMetadata(target, propertyKey, metadata) {
|
|
43
|
+
let targetMetadata = metadataCache.get(target);
|
|
44
|
+
if (!targetMetadata) {
|
|
45
|
+
targetMetadata = /* @__PURE__ */ new Map();
|
|
46
|
+
metadataCache.set(target, targetMetadata);
|
|
47
|
+
}
|
|
48
|
+
targetMetadata.set(propertyKey, metadata);
|
|
49
|
+
Reflect.defineMetadata(FIELD_KEY, metadata, target, propertyKey);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
function getFieldMetadata(target, propertyKey) {
|
|
53
|
+
const targetMetadata = metadataCache.get(target);
|
|
54
|
+
if (targetMetadata) {
|
|
55
|
+
return targetMetadata.get(propertyKey);
|
|
56
|
+
}
|
|
57
|
+
return Reflect.getMetadata(FIELD_KEY, target, propertyKey);
|
|
58
|
+
}
|
|
59
|
+
BigInt.prototype.toJSON = function() {
|
|
60
|
+
return this.toString();
|
|
61
|
+
};
|
|
62
|
+
iotexTestnet.contracts = {
|
|
63
|
+
multicall3: {
|
|
64
|
+
//@ts-ignore
|
|
65
|
+
address: "0xb5cecd6894c6f473ec726a176f1512399a2e355d",
|
|
66
|
+
blockCreated: 24347592
|
|
67
|
+
}
|
|
68
|
+
}, //@ts-ignore
|
|
69
|
+
mainnet.rpcUrls.default.http = ["https://rpc.ankr.com/eth"];
|
|
70
|
+
mainnet.rpcUrls.default.webSocket = ["wss://ethereum-rpc.publicnode.com"];
|
|
71
|
+
var Cache = class {
|
|
72
|
+
constructor() {
|
|
73
|
+
this.kv = new TTLCache({ max: 1e4, ttl: 1e3 * 60 });
|
|
74
|
+
}
|
|
75
|
+
wrap(key, fn, config = {}) {
|
|
76
|
+
if (this.kv.has(key)) {
|
|
77
|
+
return this.kv.get(key);
|
|
78
|
+
}
|
|
79
|
+
const result = fn();
|
|
80
|
+
if (result instanceof Promise) {
|
|
81
|
+
const promiseResult = result.then((res) => {
|
|
82
|
+
this.kv.set(key, res, config);
|
|
83
|
+
return res;
|
|
84
|
+
});
|
|
85
|
+
this.kv.set(key, promiseResult, config);
|
|
86
|
+
return promiseResult;
|
|
87
|
+
} else {
|
|
88
|
+
this.kv.set(key, result, config);
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var _AIem = class _AIem {
|
|
94
|
+
constructor(args = {}) {
|
|
95
|
+
this.cache = new Cache();
|
|
96
|
+
//@ts-ignore
|
|
97
|
+
this.chainMap = {
|
|
98
|
+
[iotex.id]: iotex,
|
|
99
|
+
[mainnet.id]: mainnet,
|
|
100
|
+
[bsc.id]: bsc,
|
|
101
|
+
[polygon.id]: polygon,
|
|
102
|
+
[iotexTestnet.id]: iotexTestnet
|
|
103
|
+
};
|
|
104
|
+
this.funcMap = {};
|
|
105
|
+
this.Set(args);
|
|
106
|
+
this.contracts = new Proxy(
|
|
107
|
+
{},
|
|
108
|
+
{
|
|
109
|
+
//@ts-ignore
|
|
110
|
+
get: (target, contractName) => {
|
|
111
|
+
if (target[contractName])
|
|
112
|
+
return target[contractName];
|
|
113
|
+
if (!this.nameMap[contractName]) {
|
|
114
|
+
throw new Error(`Contract ${String(contractName)} not found`);
|
|
115
|
+
}
|
|
116
|
+
target[contractName] = new Proxy(
|
|
117
|
+
{},
|
|
118
|
+
{
|
|
119
|
+
//@ts-ignore
|
|
120
|
+
get: (innerTarget, contractAlias) => {
|
|
121
|
+
var _a;
|
|
122
|
+
const addressStr = (_a = this.nameMap[contractName]) == null ? void 0 : _a[contractAlias];
|
|
123
|
+
if (!addressStr) {
|
|
124
|
+
throw new Error(`Alias ${String(contractAlias)} for contract ${String(contractName)} not found`);
|
|
125
|
+
}
|
|
126
|
+
const [chainId, address] = addressStr.split("-");
|
|
127
|
+
return this.Get(contractName, String(chainId), address);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
return target[contractName];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
get _cache() {
|
|
137
|
+
return _AIem.cache;
|
|
138
|
+
}
|
|
139
|
+
static Set(args) {
|
|
140
|
+
return this.init().Set(args);
|
|
141
|
+
}
|
|
142
|
+
Set(args) {
|
|
143
|
+
const _a = args || {}, { chainMap = {}, contractMap = {}, funcMap } = _a, rest = __objRest(_a, ["chainMap", "contractMap", "funcMap"]);
|
|
144
|
+
this.chainMap = Object.assign({}, this.chainMap || {}, chainMap);
|
|
145
|
+
this.contractMap = Object.assign({}, this.contractMap || {}, contractMap);
|
|
146
|
+
this.funcMap = Object.assign({}, this.funcMap || {}, funcMap);
|
|
147
|
+
Object.assign(this, rest);
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
// WsClient<C extends keyof Chains>(chainId: C): PublicClient<WebSocketTransport, Chain, any, any> {
|
|
151
|
+
// //@ts-ignore
|
|
152
|
+
// return this.cache.wrap(`wsClient-${String(chainId)}`, () => {
|
|
153
|
+
// // const wsUrl = this.chainMap[chainId]?.rpcUrls?.default?.webSocket?.[0]
|
|
154
|
+
// // if (!wsUrl) throw new Error(`rpcUrls.default.webSocket[0] is not defined for chainId ${String(chainId)}`)
|
|
155
|
+
// // //@ts-ignore
|
|
156
|
+
// return createPublicClient({
|
|
157
|
+
// //@ts-ignore
|
|
158
|
+
// chain: this.chainMap[chainId],
|
|
159
|
+
// transport: webSocket()
|
|
160
|
+
// }) as PublicClient<WebSocketTransport, Chain, any, any>
|
|
161
|
+
// })
|
|
162
|
+
// }
|
|
163
|
+
static PubClient(chainId, options = { multicall: true }) {
|
|
164
|
+
return this.init().PubClient(chainId, options);
|
|
165
|
+
}
|
|
166
|
+
PubClient(chainId, options = { multicall: true }) {
|
|
167
|
+
const chain = this.chainMap[chainId];
|
|
168
|
+
if (options.rpcUrls) {
|
|
169
|
+
chain.rpcUrls = options.rpcUrls;
|
|
170
|
+
}
|
|
171
|
+
return this._cache.wrap(`publicClient-${String(chainId)}-${chain.rpcUrls.default.http}-${options == null ? void 0 : options.multicall}`, () => {
|
|
172
|
+
return createPublicClient(__spreadProps(__spreadValues({
|
|
173
|
+
//@ts-ignore
|
|
174
|
+
chain
|
|
175
|
+
}, (options == null ? void 0 : options.multicall) ? {
|
|
176
|
+
batch: {
|
|
177
|
+
multicall: true
|
|
178
|
+
}
|
|
179
|
+
} : {}), {
|
|
180
|
+
//@ts-ignore
|
|
181
|
+
transport: http()
|
|
182
|
+
}));
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
//@ts-ignore
|
|
186
|
+
static Get(abi, chainId, address, wallet, options = { multicall: true }) {
|
|
187
|
+
const aiem = this.init();
|
|
188
|
+
if (!wallet) {
|
|
189
|
+
wallet = aiem.getWallet ? aiem.getWallet() : null;
|
|
190
|
+
}
|
|
191
|
+
const cacheKey = `contract ${chainId}-${address}-${wallet ? wallet.account.address : null}`;
|
|
192
|
+
return aiem._cache.wrap(cacheKey, () => {
|
|
193
|
+
const pubClient = aiem.PubClient(chainId, options);
|
|
194
|
+
return aiem.getContract({
|
|
195
|
+
client: {
|
|
196
|
+
//@ts-ignore
|
|
197
|
+
public: pubClient,
|
|
198
|
+
//@ts-ignore
|
|
199
|
+
wallet
|
|
200
|
+
},
|
|
201
|
+
address,
|
|
202
|
+
abi
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
//@ts-ignore
|
|
207
|
+
Get(contractName, chainId, address, options = { multicall: true }) {
|
|
208
|
+
const wallet = this.getWallet ? this.getWallet() : null;
|
|
209
|
+
const cacheKey = `contract ${chainId}-${address}-${wallet ? wallet.account.address : null}`;
|
|
210
|
+
return this._cache.wrap(cacheKey, () => {
|
|
211
|
+
const contract = this.contractMap[contractName];
|
|
212
|
+
const pubClient = this.PubClient(chainId, options);
|
|
213
|
+
return this.getContract({
|
|
214
|
+
client: {
|
|
215
|
+
//@ts-ignore
|
|
216
|
+
public: pubClient,
|
|
217
|
+
//@ts-ignore
|
|
218
|
+
wallet
|
|
219
|
+
},
|
|
220
|
+
address,
|
|
221
|
+
abi: contract
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
getContract({
|
|
226
|
+
client,
|
|
227
|
+
address,
|
|
228
|
+
abi
|
|
229
|
+
}) {
|
|
230
|
+
const handler = {
|
|
231
|
+
get: (target, funcName) => {
|
|
232
|
+
if (funcName == "encode") {
|
|
233
|
+
return new Proxy(
|
|
234
|
+
{},
|
|
235
|
+
{
|
|
236
|
+
get(t1, f1) {
|
|
237
|
+
return async (args) => {
|
|
238
|
+
return encodeFunctionData({
|
|
239
|
+
abi,
|
|
240
|
+
functionName: f1,
|
|
241
|
+
args
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
if (typeof target[funcName] === "function") {
|
|
249
|
+
return async (...args) => {
|
|
250
|
+
var _a;
|
|
251
|
+
const methodConfig = (_a = this.funcMap) == null ? void 0 : _a[funcName];
|
|
252
|
+
const cacheKey = `call ${client.public.chain.id}-${address}-${funcName}-${JSON.stringify(args)}`;
|
|
253
|
+
if (methodConfig) {
|
|
254
|
+
return this.cache.wrap(
|
|
255
|
+
cacheKey,
|
|
256
|
+
() => {
|
|
257
|
+
return target[funcName](...args);
|
|
258
|
+
},
|
|
259
|
+
methodConfig
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
return target[funcName](...args);
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
return new Proxy(target[funcName], handler);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
const contract = getContract({
|
|
269
|
+
//@ts-ignore
|
|
270
|
+
client,
|
|
271
|
+
address,
|
|
272
|
+
abi
|
|
273
|
+
});
|
|
274
|
+
return new Proxy(contract, handler);
|
|
275
|
+
}
|
|
276
|
+
static init() {
|
|
277
|
+
if (!globalThis.aiem) {
|
|
278
|
+
globalThis.aiem = new _AIem();
|
|
279
|
+
}
|
|
280
|
+
return globalThis.aiem;
|
|
281
|
+
}
|
|
282
|
+
static async getPrice({ chainId = "4689", address }) {
|
|
283
|
+
const priceMap = await this.cache.wrap(
|
|
284
|
+
`token-price`,
|
|
285
|
+
async () => {
|
|
286
|
+
const res = await (await fetch("https://api.iopay.me/api/rest/price")).json();
|
|
287
|
+
return Object.values(res).flat().reduce((p, c) => {
|
|
288
|
+
p[`${4689}-${c.platforms.toLowerCase()}`] = c.current_price;
|
|
289
|
+
return p;
|
|
290
|
+
}, {});
|
|
291
|
+
},
|
|
292
|
+
{ ttl: 1e3 * 60 }
|
|
293
|
+
);
|
|
294
|
+
return priceMap[`${chainId}-${address}`];
|
|
295
|
+
}
|
|
296
|
+
static QueryMany(entity, select) {
|
|
297
|
+
return async (_entities) => {
|
|
298
|
+
return this.Query(entity, select)(_entities);
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
static Query(entity, select) {
|
|
302
|
+
return async (entities) => {
|
|
303
|
+
const isArrayInput = Array.isArray(entities);
|
|
304
|
+
try {
|
|
305
|
+
const results = [];
|
|
306
|
+
if (!isArrayInput) {
|
|
307
|
+
entities = [entities];
|
|
308
|
+
}
|
|
309
|
+
for (const entityData of entities) {
|
|
310
|
+
const instance = Object.assign(new entity(), entityData);
|
|
311
|
+
const fetchFields = async (obj, sel) => {
|
|
312
|
+
var _a, _b;
|
|
313
|
+
const promises = [];
|
|
314
|
+
for (const key in sel) {
|
|
315
|
+
const fieldMetadata = getFieldMetadata(obj, key);
|
|
316
|
+
let call;
|
|
317
|
+
const enableMulticall = entity.multicall == false ? false : true;
|
|
318
|
+
if (sel[key] == false) {
|
|
319
|
+
call = async () => null;
|
|
320
|
+
} else {
|
|
321
|
+
switch (fieldMetadata == null ? void 0 : fieldMetadata.type) {
|
|
322
|
+
case "read":
|
|
323
|
+
if (Array.isArray(sel[key])) {
|
|
324
|
+
call = () => this.Get(entity.abi, instance.chainId, instance.address, null, { multicall: enableMulticall }).read[key](sel[key]);
|
|
325
|
+
} else {
|
|
326
|
+
call = () => this.Get(entity.abi, instance.chainId, instance.address, null, { multicall: enableMulticall }).read[key]();
|
|
327
|
+
}
|
|
328
|
+
break;
|
|
329
|
+
case "write":
|
|
330
|
+
obj[key] = encodeFunctionData({
|
|
331
|
+
//@ts-ignore
|
|
332
|
+
abi: entity.abi,
|
|
333
|
+
functionName: key,
|
|
334
|
+
args: sel[key]
|
|
335
|
+
});
|
|
336
|
+
break;
|
|
337
|
+
case "custom":
|
|
338
|
+
const func = fieldMetadata.func;
|
|
339
|
+
call = () => func(instance);
|
|
340
|
+
break;
|
|
341
|
+
case "entity":
|
|
342
|
+
const targetMetadata = getFieldMetadata(instance, fieldMetadata.targetKey);
|
|
343
|
+
if (typeof fieldMetadata.targetKey == "string") {
|
|
344
|
+
if ((_a = targetMetadata == null ? void 0 : targetMetadata.options) == null ? void 0 : _a.ttl) {
|
|
345
|
+
const cacheKey = `call ${instance.chainId}-${instance.address}-${fieldMetadata.targetKey}`;
|
|
346
|
+
call = () => new Promise(async (resolve) => {
|
|
347
|
+
const address = await this.cache.wrap(
|
|
348
|
+
cacheKey,
|
|
349
|
+
async () => (
|
|
350
|
+
//@ts-ignore
|
|
351
|
+
this.Get(entity.abi, instance.chainId, instance.address, null, { multicall: enableMulticall }).read[fieldMetadata.targetKey]()
|
|
352
|
+
)
|
|
353
|
+
);
|
|
354
|
+
resolve(this.Query(fieldMetadata.entity(), sel[key])({ address, chainId: instance.chainId }));
|
|
355
|
+
});
|
|
356
|
+
} else {
|
|
357
|
+
call = () => (
|
|
358
|
+
//@ts-ignore
|
|
359
|
+
this.Get(entity.abi, instance.chainId, instance.address, null, { multicall: enableMulticall }).read[fieldMetadata.targetKey]().then((address) => {
|
|
360
|
+
return this.Query(fieldMetadata.entity(), sel[key])({ address, chainId: instance.chainId });
|
|
361
|
+
})
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
} else {
|
|
365
|
+
call = () => fieldMetadata.targetKey(instance).then((args) => {
|
|
366
|
+
return Array.isArray(args) ? this.QueryMany(fieldMetadata.entity(), sel[key])(args) : this.Query(fieldMetadata.entity(), sel[key])(args);
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
break;
|
|
370
|
+
default:
|
|
371
|
+
if (typeof obj[key] == "function") {
|
|
372
|
+
call = () => obj[key](...Array.isArray(sel[key]) ? sel[key] : []);
|
|
373
|
+
}
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (call) {
|
|
378
|
+
if ((_b = fieldMetadata == null ? void 0 : fieldMetadata.options) == null ? void 0 : _b.ttl) {
|
|
379
|
+
const cacheKey = `call ${instance.chainId}-${instance.address}-${key}-${JSON.stringify(sel[key])}`;
|
|
380
|
+
promises.push(
|
|
381
|
+
new Promise(async (resolve) => {
|
|
382
|
+
const value = await this.cache.wrap(cacheKey, async () => call().catch((i) => null), fieldMetadata.options);
|
|
383
|
+
obj[key] = value;
|
|
384
|
+
resolve(value);
|
|
385
|
+
})
|
|
386
|
+
);
|
|
387
|
+
} else {
|
|
388
|
+
promises.push(
|
|
389
|
+
call().then((value) => {
|
|
390
|
+
obj[key] = value;
|
|
391
|
+
}).catch((i) => obj[key] = null)
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
await Promise.all(promises);
|
|
397
|
+
};
|
|
398
|
+
await fetchFields(instance, select);
|
|
399
|
+
results.push(instance);
|
|
400
|
+
}
|
|
401
|
+
if (isArrayInput) {
|
|
402
|
+
return results;
|
|
403
|
+
} else {
|
|
404
|
+
return results[0];
|
|
405
|
+
}
|
|
406
|
+
} catch (error) {
|
|
407
|
+
if (isArrayInput) {
|
|
408
|
+
return [];
|
|
409
|
+
} else {
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
_AIem.cache = new Cache();
|
|
417
|
+
_AIem.defaultFuncMap = {
|
|
418
|
+
totalSupply: { ttl: 15 * 1e3 },
|
|
419
|
+
symbol: { ttl: 60 * 1e3 },
|
|
420
|
+
name: { ttl: 60 * 1e3 },
|
|
421
|
+
decimals: { ttl: 60 * 1e3 },
|
|
422
|
+
balanceOf: { ttl: 5 * 1e3 }
|
|
423
|
+
};
|
|
424
|
+
_AIem.utils = {
|
|
425
|
+
autoFormat: async ({ value, decimals, chainId, address }) => {
|
|
426
|
+
const wrap = helper.number.warpBigNumber(value, decimals, { format: "0,0.000000", fallback: "" });
|
|
427
|
+
const price = await _AIem.getPrice({ chainId, address: address.toLowerCase() });
|
|
428
|
+
const usd = new BigNumber(wrap.originFormat).multipliedBy(price || 1).toFixed(2);
|
|
429
|
+
return __spreadProps(__spreadValues({}, wrap), { usd });
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
var AIem = _AIem;
|
|
433
|
+
|
|
434
|
+
export { AIem, Cache, Fields };
|
|
435
|
+
//# sourceMappingURL=out.js.map
|
|
436
|
+
//# sourceMappingURL=chunk-5JMONDHE.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../aiem.ts","../lib/decorators.ts"],"names":[],"mappings":";;;;;;;;;;AAAA;AAAA,EASE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,OAAO,SAAS,KAAK,SAAS,oBAAoB;AAC3D,OAAO,cAAc;;;ACfrB,OAAO;AAGA,IAAM,YAAY,OAAO,YAAY;AAQ5C,IAAM,gBAAgB,oBAAI,QAA4B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AC;AAAA,QACV,OAAO;AACL,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AArca,MACJ,QAAgB,IAAI,MAAM;AADtB,MAmBJ,iBAAiB;AAAA,EACtB,aAAa,EAAE,KAAK,KAAK,IAAK;AAAA,EAC9B,QAAQ,EAAE,KAAK,KAAK,IAAK;AAAA,EACzB,MAAM,EAAE,KAAK,KAAK,IAAK;AAAA,EACvB,UAAU,EAAE,KAAK,KAAK,IAAK;AAAA,EAC3B,WAAW,EAAE,KAAK,IAAI,IAAK;AAC7B;AAzBW,MAoSJ,QAAQ;AAAA,EACb,YAAY,OAAO,EAAE,OAAO,UAAU,SAAS,QAAQ,MAA6E;AAClI,UAAM,OAAO,OAAO,OAAO,cAAc,OAAO,UAAU,EAAE,QAAQ,cAAc,UAAU,GAAG,CAAC;AAChG,UAAM,QAAQ,MAAM,MAAK,SAAS,EAAE,SAAS,SAAS,QAAQ,YAAY,EAAE,CAAC;AAC7E,UAAM,MAAM,IAAI,UAAU,KAAK,YAAY,EAAE,aAAa,SAAS,CAAC,EAAE,QAAQ,CAAC;AAC/E,WAAO,iCAAK,OAAL,EAAW,IAAI;AAAA,EACxB;AACF;AA3SK,IAAM,OAAN","sourcesContent":["import {\n type Chain,\n type GetContractReturnType,\n type Abi,\n type PublicClient,\n type HttpTransport,\n type WalletClient,\n type Transport,\n type Account,\n encodeFunctionData,\n http,\n getContract,\n createPublicClient,\n} from \"viem\";\nimport { iotex, mainnet, bsc, polygon, iotexTestnet } from \"viem/chains\";\nimport TTLCache from \"@isaacs/ttlcache\";\nimport { ClassType } from \"./lib/interface\";\nimport { getFieldMetadata } from \"./lib/decorators\";\nimport { helper } from \"./utils\";\nimport BigNumber from \"bignumber.js\";\n\n//@ts-ignore\nBigInt.prototype.toJSON = function () {\n return this.toString();\n};\n\n(iotexTestnet.contracts = {\n multicall3: {\n //@ts-ignore\n address: \"0xb5cecd6894c6f473ec726a176f1512399a2e355d\",\n blockCreated: 24347592,\n },\n}),\n //@ts-ignore\n (mainnet.rpcUrls.default.http = [\"https://rpc.ankr.com/eth\"]);\n//@ts-ignore\nmainnet.rpcUrls.default.webSocket = [\"wss://ethereum-rpc.publicnode.com\"];\n\nexport { Fields } from \"./lib/decorators\";\n\nexport class Cache {\n kv = new TTLCache<string, any>({ max: 10000, ttl: 1000 * 60 });\n\n wrap<T>(key: string, fn: () => T | Promise<T>, config: TTLCache.Options<any, any> = {}): T | Promise<T> {\n if (this.kv.has(key)) {\n // console.log(`load ${key} from cache`)\n return this.kv.get(key);\n }\n\n const result = fn();\n if (result instanceof Promise) {\n const promiseResult = result.then((res) => {\n this.kv.set(key, res, config);\n return res;\n });\n this.kv.set(key, promiseResult, config);\n return promiseResult;\n } else {\n this.kv.set(key, result, config);\n return result;\n }\n }\n}\n\nexport type GetOptions = {\n multicall?: boolean;\n rpcUrls?: Chain[\"rpcUrls\"]\n};\n\nexport class AIem<Contracts extends Record<string, Abi>, Chains extends Record<string, Chain>, Addrs extends { [K in keyof Contracts]?: { [key: string]: `${string}-0x${string}` } }> {\n static cache?: Cache = new Cache();\n cache?: Cache = new Cache();\n contractMap?: Contracts;\n //@ts-ignore\n chainMap?: Chains = {\n [iotex.id]: iotex,\n [mainnet.id]: mainnet,\n [bsc.id]: bsc,\n [polygon.id]: polygon,\n [iotexTestnet.id]: iotexTestnet,\n };\n nameMap?: Addrs;\n contracts: {\n [K in keyof Addrs & keyof Contracts]: {\n //@ts-ignore\n [KK in keyof Addrs[K]]: GetContractReturnType<Contracts[K], PublicClient<HttpTransport, Chain, any, any>, any, any>;\n };\n };\n static defaultFuncMap = {\n totalSupply: { ttl: 15 * 1000 },\n symbol: { ttl: 60 * 1000 },\n name: { ttl: 60 * 1000 },\n decimals: { ttl: 60 * 1000 },\n balanceOf: { ttl: 5 * 1000 },\n };\n funcMap?: { [key: string]: { ttl?: number } } = {};\n\n get _cache() {\n return AIem.cache;\n }\n\n //@ts-ignore\n getWallet?: () => WalletClient;\n\n static Set<Contracts extends Record<string, Abi>, Chains extends Record<string, Chain>, Addrs extends { [K in keyof Contracts]?: { [key: string]: `${string}-0x${string}` } }>(\n args: Pick<AIem<Contracts, Chains, Addrs>, \"contractMap\" | \"chainMap\" | \"nameMap\" | \"getWallet\" | \"cache\" | \"funcMap\">,\n ) {\n return this.init().Set(args);\n }\n\n Set<Contracts extends Record<string, Abi>, Chains extends Record<string, Chain>, Addrs extends { [K in keyof Contracts]?: { [key: string]: `${string}-0x${string}` } }>(\n args: Pick<AIem<Contracts, Chains, Addrs>, \"contractMap\" | \"chainMap\" | \"nameMap\" | \"getWallet\" | \"cache\" | \"funcMap\">,\n ): AIem<Contracts, Chains, Addrs> {\n const { chainMap = {}, contractMap = {}, funcMap, ...rest } = args || {};\n //@ts-ignore\n this.chainMap = Object.assign({}, this.chainMap || {}, chainMap);\n //@ts-ignore\n this.contractMap = Object.assign({}, this.contractMap || {}, contractMap);\n //@ts-ignore\n this.funcMap = Object.assign({}, this.funcMap || {}, funcMap);\n\n Object.assign(this, rest);\n return this as any;\n }\n\n constructor(args: Pick<AIem<Contracts, Chains, Addrs>, \"contractMap\" | \"chainMap\" | \"nameMap\" | \"getWallet\" | \"cache\" | \"funcMap\"> = {}) {\n this.Set(args);\n\n this.contracts = new Proxy(\n {},\n {\n //@ts-ignore\n get: (target: any, contractName: keyof Addrs & keyof Contracts) => {\n if (target[contractName]) return target[contractName];\n\n if (!this.nameMap[contractName]) {\n throw new Error(`Contract ${String(contractName)} not found`);\n }\n\n target[contractName] = new Proxy(\n {},\n {\n //@ts-ignore\n get: (innerTarget: any, contractAlias: keyof Addrs[keyof Addrs]) => {\n const addressStr = this.nameMap[contractName]?.[contractAlias];\n if (!addressStr) {\n throw new Error(`Alias ${String(contractAlias)} for contract ${String(contractName)} not found`);\n }\n const [chainId, address] = addressStr.split(\"-\");\n\n // Assuming getContractInstance is a function that retrieves a contract instance\n return this.Get(contractName, String(chainId), address as `0x${string}`);\n },\n },\n );\n return target[contractName];\n },\n },\n ) as any;\n }\n\n // WsClient<C extends keyof Chains>(chainId: C): PublicClient<WebSocketTransport, Chain, any, any> {\n // //@ts-ignore\n // return this.cache.wrap(`wsClient-${String(chainId)}`, () => {\n // // const wsUrl = this.chainMap[chainId]?.rpcUrls?.default?.webSocket?.[0]\n // // if (!wsUrl) throw new Error(`rpcUrls.default.webSocket[0] is not defined for chainId ${String(chainId)}`)\n // // //@ts-ignore\n // return createPublicClient({\n // //@ts-ignore\n // chain: this.chainMap[chainId],\n // transport: webSocket()\n // }) as PublicClient<WebSocketTransport, Chain, any, any>\n // })\n // }\n\n static PubClient(chainId: string, options: GetOptions = { multicall: true }): PublicClient<HttpTransport, Chain, any, any> {\n //@ts-ignore\n return this.init().PubClient(chainId, options);\n }\n\n PubClient<C extends keyof Chains>(chainId: C, options: GetOptions = { multicall: true }): PublicClient<HttpTransport, Chain, any, any> {\n const chain = this.chainMap[chainId]\n if (options.rpcUrls) {\n chain.rpcUrls = options.rpcUrls\n }\n //@ts-ignore\n return this._cache.wrap(`publicClient-${String(chainId)}-${chain.rpcUrls.default.http}-${options?.multicall}`, () => {\n //@ts-ignore\n return createPublicClient({\n //@ts-ignore\n chain,\n ...(options?.multicall\n ? {\n batch: {\n multicall: true,\n },\n }\n : {}),\n\n //@ts-ignore\n transport: http(),\n });\n });\n }\n\n //@ts-ignore\n static Get<TAbi extends Abi = any, ReturnType extends GetContractReturnType<TAbi, WalletClient<Transport, Chain, Account>>>(\n abi: TAbi,\n chainId: any,\n address: any,\n wallet?: WalletClient,\n //@ts-ignore\n options?: GetOptions = { multicall: true },\n //@ts-ignore\n ): ReturnType & { encode: ReturnType[\"write\"] } {\n const aiem = this.init();\n if (!wallet) {\n wallet = aiem.getWallet ? aiem.getWallet() : null;\n }\n\n const cacheKey = `contract ${chainId}-${address}-${wallet ? wallet.account.address : null}`;\n return aiem._cache.wrap(cacheKey, () => {\n //@ts-ignore\n const pubClient = aiem.PubClient(chainId, options);\n\n //@ts-ignore\n return aiem.getContract({\n client: {\n //@ts-ignore\n public: pubClient,\n //@ts-ignore\n wallet,\n },\n address,\n abi,\n });\n }) as any;\n }\n\n //@ts-ignore\n Get<K extends keyof Contracts, C extends keyof Chains, Addr extends `0x${string}`>(\n contractName: K,\n chainId: C,\n address: Addr,\n options: GetOptions = { multicall: true },\n //@ts-ignore\n ): GetContractReturnType<Contracts[K], PublicClient<HttpTransport, Chain, any, any>> & { encode: GetContractReturnType<Contracts[K], WalletClient<HttpTransport, Chain, Account, any>>[\"write\"] } {\n const wallet = this.getWallet ? this.getWallet() : null;\n //@ts-ignore\n const cacheKey = `contract ${chainId}-${address}-${wallet ? wallet.account.address : null}`;\n return this._cache.wrap(cacheKey, () => {\n //@ts-ignore\n const contract = this.contractMap[contractName];\n //@ts-ignore\n const pubClient = this.PubClient(chainId, options);\n\n //@ts-ignore\n return this.getContract({\n client: {\n //@ts-ignore\n public: pubClient,\n //@ts-ignore\n wallet,\n },\n address,\n abi: contract,\n });\n }) as any;\n }\n\n getContract({\n client,\n address,\n abi,\n }: {\n client: {\n public: PublicClient<HttpTransport, Chain, any, any>;\n wallet?: WalletClient;\n };\n address: `0x${string}`;\n abi: any;\n }) {\n const handler = {\n get: (target: any, funcName: any) => {\n if (funcName == \"encode\") {\n return new Proxy(\n {},\n {\n get(t1, f1) {\n return async (args: any) => {\n // @ts-ignore\n return encodeFunctionData({\n abi,\n functionName: f1,\n args,\n });\n };\n },\n },\n );\n }\n\n if (typeof target[funcName] === \"function\") {\n return async (...args: any[]) => {\n const methodConfig = this.funcMap?.[funcName as string];\n // const cacheKey = `method:${client.public.chain.id}-${address}-${String(funcName)}-${JSON.stringify(args)}`;\n const cacheKey = `call ${client.public.chain.id}-${address}-${funcName}-${JSON.stringify(args)}`;\n\n if (methodConfig) {\n return this.cache.wrap(\n cacheKey,\n () => {\n return target[funcName](...args);\n },\n methodConfig,\n );\n }\n\n return target[funcName](...args);\n };\n }\n return new Proxy(target[funcName], handler);\n },\n };\n\n //@ts-ignore\n const contract = getContract({\n //@ts-ignore\n client,\n address,\n abi,\n });\n return new Proxy(contract, handler) as any;\n }\n\n static init(): AIem<any, any, any> {\n if (!globalThis.aiem) {\n //@ts-ignore\n globalThis.aiem = new AIem();\n }\n\n return globalThis.aiem;\n }\n\n static async getPrice({ chainId = \"4689\", address }: { chainId?: string; address: string }) {\n const priceMap = await this.cache.wrap(\n `token-price`,\n async () => {\n const res = await (await fetch(\"https://api.iopay.me/api/rest/price\")).json();\n return Object.values(res)\n .flat()\n .reduce((p, c: { platforms: string; current_price: number }) => {\n p[`${4689}-${c.platforms.toLowerCase()}`] = c.current_price;\n return p;\n }, {});\n },\n { ttl: 1000 * 60 },\n );\n return priceMap[`${chainId}-${address}`];\n }\n\n static utils = {\n autoFormat: async ({ value, decimals, chainId, address }: { value: string; decimals: number; chainId: string; address: string }) => {\n const wrap = helper.number.warpBigNumber(value, decimals, { format: \"0,0.000000\", fallback: \"\" });\n const price = await this.getPrice({ chainId, address: address.toLowerCase() });\n const usd = new BigNumber(wrap.originFormat).multipliedBy(price || 1).toFixed(2);\n return { ...wrap, usd };\n },\n };\n\n static QueryMany<E, S extends QuerySelect<E>>(entity: ClassType<E>, select: S) {\n return async (_entities: Partial<E>[]): Promise<QueryReturnType<E, S>[]> => {\n //@ts-ignore\n return this.Query(entity, select)(_entities) as any;\n };\n }\n\n static Query<E, S extends QuerySelect<E>>(entity: ClassType<E>, select: S) {\n return async (entities: Partial<E>): Promise<QueryReturnType<E, S>> => {\n const isArrayInput = Array.isArray(entities);\n\n try {\n const results: Array<QueryReturnType<E, S>> = [];\n\n if (!isArrayInput) {\n //@ts-ignore\n entities = [entities];\n }\n //@ts-ignore\n for (const entityData of entities) {\n const instance = Object.assign(new entity(), entityData);\n // const result: any = {};\n\n const fetchFields = async (obj: any, sel: any) => {\n const promises = [];\n for (const key in sel) {\n // return console.log(key, getFieldMetadata(obj, key))\n // Check if the property is annotated with @Fields.read(), @Fields.custom(), or @Fields.contract()\n const fieldMetadata = getFieldMetadata(obj, key);\n let call: any;\n //@ts-ignore\n const enableMulticall = entity.multicall == false ? false : true;\n // console.log(key, fieldMetadata, instance)\n if (sel[key] == false) {\n call = async () => null;\n } else {\n switch (fieldMetadata?.type) {\n case \"read\":\n if (Array.isArray(sel[key])) {\n //@ts-ignore\n call = () => this.Get(entity.abi, instance.chainId, instance.address, null, { multicall: enableMulticall }).read[key](sel[key]);\n } else {\n //@ts-ignore\n call = () => this.Get(entity.abi, instance.chainId, instance.address, null, { multicall: enableMulticall }).read[key]();\n }\n break;\n case \"write\":\n // @ts-ignore\n obj[key] = encodeFunctionData({\n //@ts-ignore\n abi: entity.abi,\n functionName: key,\n args: sel[key],\n });\n\n break;\n case \"custom\":\n const func = fieldMetadata.func\n call = () => func(instance)\n break;\n case \"entity\":\n const targetMetadata = getFieldMetadata(instance, fieldMetadata.targetKey);\n\n if (typeof fieldMetadata.targetKey == \"string\") {\n if (targetMetadata?.options?.ttl) {\n //@ts-ignore\n const cacheKey = `call ${instance.chainId}-${instance.address}-${fieldMetadata.targetKey}`;\n //@ts-ignore\n call = () =>\n new Promise(async (resolve) => {\n //@ts-ignore\n const address = await this.cache.wrap(cacheKey, async () =>\n //@ts-ignore\n this.Get(entity.abi, instance.chainId, instance.address, null, { multicall: enableMulticall }).read[fieldMetadata.targetKey](),\n );\n //@ts-ignore\n resolve(this.Query(fieldMetadata.entity(), sel[key])({ address, chainId: instance.chainId }));\n });\n } else {\n call = () =>\n //@ts-ignore\n this.Get(entity.abi, instance.chainId, instance.address, null, { multicall: enableMulticall })\n //@ts-ignore\n .read[fieldMetadata.targetKey]()\n .then((address: any) => {\n // console.log({ address, sel: sel[key] })\n //@ts-ignore\n return this.Query(fieldMetadata.entity(), sel[key])({ address, chainId: instance.chainId });\n });\n }\n } else {\n //@ts-ignore\n call = () =>\n fieldMetadata.targetKey(instance).then((args) => {\n // console.log(args)\n return Array.isArray(args) ? this.QueryMany(fieldMetadata.entity(), sel[key])(args) : this.Query(fieldMetadata.entity(), sel[key])(args);\n });\n }\n break;\n default:\n if (typeof obj[key] == \"function\") {\n call = () => obj[key](...(Array.isArray(sel[key]) ? sel[key] : []));\n }\n break;\n }\n }\n\n if (call) {\n if (fieldMetadata?.options?.ttl) {\n //@ts-ignore\n const cacheKey = `call ${instance.chainId}-${instance.address}-${key}-${JSON.stringify(sel[key])}`;\n promises.push(\n new Promise(async (resolve) => {\n const value = await this.cache.wrap(cacheKey, async () => call().catch(i => null), fieldMetadata.options)\n obj[key] = value;\n resolve(value);\n })\n );\n } else {\n promises.push(\n call()\n .then((value) => {\n obj[key] = value;\n })\n .catch((i) => (obj[key] = null)),\n );\n }\n }\n }\n\n await Promise.all(promises);\n };\n\n await fetchFields(instance, select);\n //@ts-ignore\n results.push(instance);\n }\n\n if (isArrayInput) {\n return results as any;\n } else {\n return results[0] as any;\n }\n } catch (error) {\n if (isArrayInput) {\n return [] as any;\n } else {\n return null as any;\n }\n }\n };\n }\n}\nexport type Item<T> = T extends (infer U)[] ? U : T;\n\n// export type QueryResult<E, S extends QuerySelect<E>> =\n// E extends Array<any> ? Promise<Array<QueryReturnType<E[number], S>>> :\n// E extends object ? Promise<QueryReturnType<E, S>> :\n// never;\n\ntype QuerySelect<E> = {\n [K in keyof E]?: E[K] extends (...args: any[]) => any ? Parameters<E[K]> | boolean : E[K] extends object ? QuerySelect<Item<E[K]>> | boolean : boolean;\n};\n\n// type FunctionReturn<T> = T extends (...args: any[]) => any ? Awaited<ReturnType<T>> : T;\n// type NestedReturn<E, S> = E extends object ? S extends object ? QueryReturnType<E, S> : E : E;\n\nexport type QueryReturnType<E, S extends QuerySelect<E>> = {\n [K in keyof E]: K extends keyof S\n ? E[K] extends (...args: any[]) => any\n ? Awaited<ReturnType<E[K]>>\n : E[K] extends object\n ? S[K] extends object\n ? QueryReturnType<E[K], S[K]>\n : E[K]\n : E[K]\n : E[K];\n};\n","import \"reflect-metadata\";\nimport { ClassType } from \"./interface\";\n\nexport const FIELD_KEY = Symbol(\"aiem_field\");\n\nexport interface FieldParams {\n ttl?: number;\n}\n\nexport type ContractParams<T extends any = any, K extends keyof T = keyof T> = K;\n\nconst metadataCache = new WeakMap<any, Map<any, any>>();\n\nexport class Fields {\n static hide(options: any = {}) {\n return function (target: any, propertyKey: any, descriptor?: PropertyDescriptor) {\n Fields.setMetadata(target, propertyKey, { type: \"hide\", options });\n };\n }\n\n static read(options: any = {}) {\n return function (target: any, propertyKey: any, descriptor?: PropertyDescriptor) {\n Fields.setMetadata(target, propertyKey, { type: \"read\", options });\n };\n }\n\n static write(options: any = {}) {\n return function (target: any, propertyKey: any, descriptor?: PropertyDescriptor) {\n Fields.setMetadata(target, propertyKey, { type: \"write\", options });\n };\n }\n\n static custom(func: any = {}) {\n return function (target: any, propertyKey: any, descriptor?: PropertyDescriptor) {\n Fields.setMetadata(target, propertyKey, { type: \"custom\", func });\n };\n }\n\n static relation<T = any, R = any>(entity: () => ClassType<R>, options: ((e: T) => Promise<Partial<R> | Partial<R>[]>) | string) {\n return function (target: any, propertyKey: any, descriptor?: PropertyDescriptor) {\n Fields.setMetadata(target, propertyKey, { type: \"entity\", entity, targetKey: options });\n };\n }\n\n static contract<T = any, R = any>(entity: () => ClassType<R>, options: ((e: T) => Promise<Partial<R> | Partial<R>[]>) | string) {\n return function (target: any, propertyKey: any, descriptor?: PropertyDescriptor) {\n Fields.setMetadata(target, propertyKey, { type: \"entity\", entity, targetKey: options });\n };\n }\n private static setMetadata(target: any, propertyKey: any, metadata: any) {\n let targetMetadata = metadataCache.get(target);\n if (!targetMetadata) {\n targetMetadata = new Map<any, any>();\n metadataCache.set(target, targetMetadata);\n }\n targetMetadata.set(propertyKey, metadata);\n // @ts-ignore \n Reflect.defineMetadata(FIELD_KEY, metadata, target, propertyKey);\n }\n}\n\nexport function getFieldMetadata(target: any, propertyKey: string) {\n const targetMetadata = metadataCache.get(target);\n if (targetMetadata) {\n return targetMetadata.get(propertyKey);\n }\n // @ts-ignore \n return Reflect.getMetadata(FIELD_KEY, target, propertyKey);\n}\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { getStyle } from './chunk-K73JTEJQ.mjs';
|
|
2
|
+
import { useStore, rootStore } from './chunk-XSGTWROT.mjs';
|
|
3
|
+
import { __spreadValues, __spreadProps } from './chunk-2EXDWOHY.mjs';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { makeAutoObservable } from 'mobx';
|
|
6
|
+
import { Modal, ModalContent, ModalHeader, ModalBody } from '@nextui-org/react';
|
|
7
|
+
import { observer } from 'mobx-react-lite';
|
|
8
|
+
|
|
9
|
+
var Dialog = observer(() => {
|
|
10
|
+
const rootStore2 = useStore();
|
|
11
|
+
const modal = rootStore2.get(DialogStore);
|
|
12
|
+
const { className, classNames, isOpen, placement, title, size, content, isDismissable } = modal;
|
|
13
|
+
const Content = typeof content === "function" ? content : () => content;
|
|
14
|
+
return /* @__PURE__ */ React.createElement(
|
|
15
|
+
Modal,
|
|
16
|
+
{
|
|
17
|
+
isOpen,
|
|
18
|
+
size,
|
|
19
|
+
placement,
|
|
20
|
+
onOpenChange: (open) => {
|
|
21
|
+
if (!open) {
|
|
22
|
+
modal.close();
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
className,
|
|
26
|
+
classNames,
|
|
27
|
+
isDismissable
|
|
28
|
+
},
|
|
29
|
+
/* @__PURE__ */ React.createElement(ModalContent, { className: "max-h-screen overflow-auto" }, () => /* @__PURE__ */ React.createElement(React.Fragment, null, title && /* @__PURE__ */ React.createElement(ModalHeader, { className: "flex flex-col gap-1" }, title), /* @__PURE__ */ React.createElement(ModalBody, null, /* @__PURE__ */ React.createElement(Content, null))))
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
var Provider_default = Dialog;
|
|
33
|
+
|
|
34
|
+
// module/Dialog/index.tsx
|
|
35
|
+
var DialogStore = class _DialogStore {
|
|
36
|
+
constructor(args) {
|
|
37
|
+
this.sid = "DialogStore";
|
|
38
|
+
this.provider = () => /* @__PURE__ */ React.createElement(Provider_default, null);
|
|
39
|
+
this.isOpen = false;
|
|
40
|
+
this.title = "";
|
|
41
|
+
this.size = "md";
|
|
42
|
+
this.className = "";
|
|
43
|
+
this.theme = "default";
|
|
44
|
+
this.content = "";
|
|
45
|
+
this.isDismissable = true;
|
|
46
|
+
const modalStyle = getStyle((args == null ? void 0 : args.theme) || "default", "Modal");
|
|
47
|
+
const classNames = __spreadValues(__spreadValues({}, modalStyle.classNames), args == null ? void 0 : args.classNames);
|
|
48
|
+
Object.assign(this, args, { classNames });
|
|
49
|
+
makeAutoObservable(this);
|
|
50
|
+
}
|
|
51
|
+
setData(v) {
|
|
52
|
+
Object.assign(this, v);
|
|
53
|
+
}
|
|
54
|
+
close() {
|
|
55
|
+
this.isOpen = false;
|
|
56
|
+
this.title = "";
|
|
57
|
+
this.content = "";
|
|
58
|
+
this.size = "md";
|
|
59
|
+
this.isDismissable = true;
|
|
60
|
+
}
|
|
61
|
+
static show(v) {
|
|
62
|
+
const modalStyle = getStyle((v == null ? void 0 : v.theme) || "default", "Modal");
|
|
63
|
+
const classNames = __spreadValues(__spreadValues({}, modalStyle.classNames), v == null ? void 0 : v.classNames);
|
|
64
|
+
rootStore.get(_DialogStore).setData(__spreadProps(__spreadValues({}, v), {
|
|
65
|
+
classNames,
|
|
66
|
+
isOpen: true
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
static close() {
|
|
70
|
+
rootStore.get(_DialogStore).close();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export { DialogStore };
|
|
75
|
+
//# sourceMappingURL=out.js.map
|
|
76
|
+
//# sourceMappingURL=chunk-L6XS2K2K.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../module/Dialog/index.tsx","../module/Dialog/Provider.tsx"],"names":["React","rootStore"],"mappings":";;;;;;;;;;;;;AAAA,OAAOA,YAAW;AAClB,SAAS,0BAA0B;;;ACDnC,OAAO,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AAgB;AAAA,EACvB;AAAA,EAEA,OAAO,KAAK,GAAyB;AACnC,UAAM,aAAa,UAAS,uBAAG,UAAS,WAAW,OAAO;AAC1D,UAAM,aAAa,kCACd,WAAW,aACX,uBAAG;AAER,cAAU,IAAI,YAAW,EAAE,QAAQ,iCAC9B,IAD8B;AAAA,MAEjC;AAAA,MACA,QAAQ;AAAA,IAEV,EAAC;AAAA,EACH;AAAA,EAEA,OAAO,QAAQ;AACb,cAAU,IAAI,YAAW,EAAE,MAAM;AAAA,EACnC;AACF","sourcesContent":["import React from \"react\";\nimport { makeAutoObservable } from \"mobx\";\nimport { rootStore } from \"../../store\";\nimport { Store } from \"../../store/standard/base\";\nimport Provider from \"./Provider\";\nimport { ModalSlots, SlotsToClasses } from \"@nextui-org/react\";\nimport { getStyle, ThemeType } from \"../../themes\";\n\nexport class DialogStore implements Store {\n sid = \"DialogStore\";\n provider = () => <Provider />;\n\n isOpen = false;\n placement: \"center\" | \"auto\" | \"top\" | \"bottom\" | \"top-center\" | \"bottom-center\";\n title = \"\";\n size: \"sm\" | \"md\" | \"lg\" | \"xl\" | \"2xl\" | \"full\" | \"xs\" | \"3xl\" | \"4xl\" | \"5xl\" = \"md\";\n className: string = \"\";\n classNames?: SlotsToClasses<ModalSlots>;\n theme: ThemeType = \"default\";\n content: React.ReactNode | ((props: any) => React.ReactNode) = \"\";\n isDismissable = true;\n\n constructor(args?: Partial<DialogStore>) {\n const modalStyle = getStyle(args?.theme || 'default', 'Modal');\n const classNames = {\n ...modalStyle.classNames,\n ...args?.classNames\n }\n Object.assign(this, args, { classNames });\n makeAutoObservable(this);\n }\n\n\n setData(v: Partial<DialogStore>) {\n Object.assign(this, v);\n }\n\n close() {\n this.isOpen = false;\n this.title = \"\";\n this.content = \"\";\n this.size = \"md\";\n this.isDismissable = true;\n }\n\n static show(v: Partial<DialogStore>) {\n const modalStyle = getStyle(v?.theme || 'default', 'Modal');\n const classNames = {\n ...modalStyle.classNames,\n ...v?.classNames\n }\n rootStore.get(DialogStore).setData({\n ...v,\n classNames,\n isOpen: true,\n\n });\n }\n\n static close() {\n rootStore.get(DialogStore).close();\n }\n}\n","import React from \"react\";\nimport { Modal, ModalBody, ModalContent, ModalHeader } from \"@nextui-org/react\";\nimport { observer } from \"mobx-react-lite\";\nimport { DialogStore } from \".\";\nimport { useStore } from \"../../store/index\";\n\nconst Dialog = observer(() => {\n const rootStore = useStore();\n const modal = rootStore.get(DialogStore);\n const { className, classNames, isOpen, placement, title, size, content, isDismissable } = modal;\n const Content = typeof content === 'function' ? content : () => content;\n return (\n <Modal\n isOpen={isOpen}\n size={size}\n placement={placement}\n onOpenChange={(open: boolean) => {\n if (!open) {\n modal.close();\n }\n }}\n className={className}\n classNames={classNames}\n isDismissable={isDismissable}\n >\n <ModalContent className=\"max-h-screen overflow-auto\">\n {() => (\n <>\n {title && <ModalHeader className=\"flex flex-col gap-1\">{title}</ModalHeader>}\n <ModalBody>\n <Content />\n </ModalBody>\n </>\n )}\n </ModalContent>\n </Modal >\n );\n});\n\nexport default Dialog;"]}
|