@0xobelisk/sui-common 1.2.0-pre.115 → 1.2.0-pre.117
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/README.md +11 -11
- package/dist/index.d.ts +8 -4
- package/dist/index.js +265 -208
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/codegen/types/index.ts +9 -3
- package/src/codegen/utils/formatAndWrite.ts +10 -10
- package/src/codegen/utils/renderMove/generateDappKey.ts +18 -18
- package/src/codegen/utils/renderMove/generateError.ts +22 -6
- package/src/codegen/utils/renderMove/generateGenesis.ts +56 -23
- package/src/codegen/utils/renderMove/generateInitTest.ts +26 -14
- package/src/codegen/utils/renderMove/generateResources.ts +306 -214
- package/src/codegen/utils/renderMove/generateScript.ts +4 -4
- package/src/codegen/utils/renderMove/generateSystem.ts +0 -2
- package/src/codegen/utils/renderMove/generateUserStorageInit.ts +33 -0
- package/src/codegen/utils/renderMove/schemaGen.ts +5 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @0xobelisk/sui-common
|
|
2
2
|
|
|
3
|
-
Dubhe 框架的底层公共逻辑包。提供 `
|
|
3
|
+
Dubhe 框架的底层公共逻辑包。提供 `generate` 代码生成器(供 CLI 调用)、`DubheConfig` 类型定义,以及 CLI 和 SDK 共用的工具函数。
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ Dubhe 框架的底层公共逻辑包。提供 `schemagen` 代码生成器(供
|
|
|
8
8
|
|
|
9
9
|
```
|
|
10
10
|
@0xobelisk/sui-common
|
|
11
|
-
├── codegen/ #
|
|
11
|
+
├── codegen/ # generate —— 根据 DubheConfig 生成 Move 源文件
|
|
12
12
|
│ ├── types/ # DubheConfig、MoveType、Component 类型定义
|
|
13
13
|
│ └── utils/ # schemaGen() 入口 + 所有生成器模块
|
|
14
14
|
├── parseData/ # 运行时工具:解析链上 BCS 响应数据
|
|
@@ -316,12 +316,12 @@ module my_project::errors {
|
|
|
316
316
|
|
|
317
317
|
---
|
|
318
318
|
|
|
319
|
-
##
|
|
319
|
+
## generate 执行流程
|
|
320
320
|
|
|
321
|
-
`schemaGen(rootDir, config, network?)` 是 `dubhe
|
|
321
|
+
`schemaGen(rootDir, config, network?)` 是 `dubhe generate` 命令调用的主入口,**按顺序**执行以下步骤:
|
|
322
322
|
|
|
323
323
|
```
|
|
324
|
-
|
|
324
|
+
generate
|
|
325
325
|
│
|
|
326
326
|
├── 1. 删除 sources/codegen/ (每次都清空重生成)
|
|
327
327
|
│
|
|
@@ -364,7 +364,7 @@ schemagen
|
|
|
364
364
|
|
|
365
365
|
## 生成文件目录结构
|
|
366
366
|
|
|
367
|
-
对名为 `my_project` 的项目执行 `dubhe
|
|
367
|
+
对名为 `my_project` 的项目执行 `dubhe generate` 后,目录结构如下:
|
|
368
368
|
|
|
369
369
|
```
|
|
370
370
|
src/my_project/
|
|
@@ -395,14 +395,14 @@ src/my_project/
|
|
|
395
395
|
|
|
396
396
|
### 什么是 Dubhe Framework?
|
|
397
397
|
|
|
398
|
-
`
|
|
398
|
+
`generate` 生成的 Move 合约代码并非独立运行,它必须搭配 **Dubhe Framework**(链上已部署的 `dubhe` 包)才能工作。Framework 是一个已部署在 Sui 链上的基础设施包,为所有通过 Dubhe 构建的 DApp 提供存储引擎、事件系统、费用计量、权限管理和版本控制能力。
|
|
399
399
|
|
|
400
400
|
可以这样理解两者的关系:
|
|
401
401
|
|
|
402
402
|
```
|
|
403
403
|
你写的 DubheConfig(TypeScript)
|
|
404
404
|
│
|
|
405
|
-
▼ dubhe
|
|
405
|
+
▼ dubhe generate
|
|
406
406
|
你的合约代码(Move)── 调用 ──▶ Dubhe Framework(链上已部署)
|
|
407
407
|
│
|
|
408
408
|
▼
|
|
@@ -490,7 +490,7 @@ DappHub(全局共享对象)
|
|
|
490
490
|
|
|
491
491
|
### DappKey:类型级 DApp 身份证
|
|
492
492
|
|
|
493
|
-
`
|
|
493
|
+
`generate` 生成的 `dapp_key.move` 中定义了一个空结构体:
|
|
494
494
|
|
|
495
495
|
```move
|
|
496
496
|
public struct DappKey has copy, drop {}
|
|
@@ -506,7 +506,7 @@ public struct DappKey has copy, drop {}
|
|
|
506
506
|
|
|
507
507
|
### 生成的 Resource 模块是如何调用 Framework 的
|
|
508
508
|
|
|
509
|
-
以一个简单的 `health: 'u32'` 配置为例,`
|
|
509
|
+
以一个简单的 `health: 'u32'` 配置为例,`generate` 会生成 `health.move`,其核心写入路径为:
|
|
510
510
|
|
|
511
511
|
```
|
|
512
512
|
health::set(dapp_hub, resource_account, 100u32, ctx)
|
|
@@ -634,7 +634,7 @@ DappHub.accounts
|
|
|
634
634
|
|
|
635
635
|
## 配置文件加载机制
|
|
636
636
|
|
|
637
|
-
执行 `dubhe
|
|
637
|
+
执行 `dubhe generate` 或 `dubhe publish` 时,CLI 会调用 `loadConfig(configPath?)`,流程如下:
|
|
638
638
|
|
|
639
639
|
1. 从当前目录向上查找以下文件(按优先级排序):`dubhe.config.js`、`dubhe.config.mjs`、`dubhe.config.ts`、`dubhe.config.mts`
|
|
640
640
|
2. 使用 **esbuild** 将 TypeScript 配置编译为 ESM(打包本地 import,外部化 node_modules)
|
package/dist/index.d.ts
CHANGED
|
@@ -10,19 +10,23 @@ type Component = {
|
|
|
10
10
|
fields: Record<string, MoveType>;
|
|
11
11
|
keys?: string[];
|
|
12
12
|
};
|
|
13
|
+
type ErrorDefinition = {
|
|
14
|
+
message: string;
|
|
15
|
+
};
|
|
16
|
+
type ErrorEntry = string | ErrorDefinition;
|
|
13
17
|
type DubheConfig = {
|
|
14
18
|
name: string;
|
|
15
19
|
description: string;
|
|
16
20
|
enums?: Record<string, string[]>;
|
|
17
|
-
resources
|
|
18
|
-
errors?: Record<string,
|
|
21
|
+
resources?: Record<string, Component | MoveType>;
|
|
22
|
+
errors?: Record<string, ErrorEntry>;
|
|
19
23
|
};
|
|
20
24
|
type DubheMetadata = {
|
|
21
25
|
resources: Record<string, Component | MoveType>;
|
|
22
26
|
enums: Record<string, string[]>;
|
|
23
27
|
};
|
|
24
28
|
type BaseType = any;
|
|
25
|
-
type ErrorData =
|
|
29
|
+
type ErrorData = Record<string, ErrorEntry>;
|
|
26
30
|
type EventData = any;
|
|
27
31
|
type SchemaData = any;
|
|
28
32
|
type SchemaType = any;
|
|
@@ -46,4 +50,4 @@ type SubscribableType = {
|
|
|
46
50
|
name?: string;
|
|
47
51
|
};
|
|
48
52
|
|
|
49
|
-
export { BaseType, Component, ComponentType, DubheConfig, DubheMetadata, ErrorData, EventData, MoveType, SchemaData, SchemaType, SubscribableType, SubscriptionKind, defineConfig, formatAndWriteMove, formatMove, loadConfig, schemaGen };
|
|
53
|
+
export { BaseType, Component, ComponentType, DubheConfig, DubheMetadata, ErrorData, ErrorDefinition, ErrorEntry, EventData, MoveType, SchemaData, SchemaType, SubscribableType, SubscriptionKind, defineConfig, formatAndWriteMove, formatMove, loadConfig, schemaGen };
|