@0xobelisk/sui-common 1.2.0-pre.113 → 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.
Files changed (30) hide show
  1. package/README.md +11 -11
  2. package/dist/index.d.ts +8 -22
  3. package/dist/index.js +266 -201
  4. package/dist/index.js.map +1 -1
  5. package/package.json +1 -1
  6. package/src/codegen/debug.ts +0 -4
  7. package/src/codegen/types/index.ts +9 -3
  8. package/src/codegen/utils/config.ts +1 -1
  9. package/src/codegen/utils/format.ts +0 -6
  10. package/src/codegen/utils/formatAndWrite.ts +10 -30
  11. package/src/codegen/utils/index.ts +0 -1
  12. package/src/codegen/utils/renderMove/common.ts +0 -65
  13. package/src/codegen/utils/renderMove/generateDappKey.ts +18 -18
  14. package/src/codegen/utils/renderMove/generateError.ts +30 -13
  15. package/src/codegen/utils/renderMove/generateGenesis.ts +55 -22
  16. package/src/codegen/utils/renderMove/generateInitTest.ts +26 -14
  17. package/src/codegen/utils/renderMove/generateResources.ts +306 -214
  18. package/src/codegen/utils/renderMove/generateScript.ts +4 -12
  19. package/src/codegen/utils/renderMove/generateSystem.ts +0 -2
  20. package/src/codegen/utils/renderMove/generateUserStorageInit.ts +33 -0
  21. package/src/codegen/utils/renderMove/schemaGen.ts +5 -12
  22. package/src/index.ts +0 -1
  23. package/src/modules.d.ts +0 -10
  24. package/src/codegen/utils/posixPath.ts +0 -8
  25. package/src/codegen/utils/renderMove/generateDefaultSchema.ts +0 -216
  26. package/src/codegen/utils/renderMove/generateEvent.ts +0 -99
  27. package/src/codegen/utils/renderMove/generateSchema.ts +0 -287
  28. package/src/codegen/utils/renderMove/generateSchemaHub.ts +0 -60
  29. package/src/parseData/index.ts +0 -1
  30. package/src/parseData/parser/index.ts +0 -47
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @0xobelisk/sui-common
2
2
 
3
- Dubhe 框架的底层公共逻辑包。提供 `schemagen` 代码生成器(供 CLI 调用)、`DubheConfig` 类型定义,以及 CLI 和 SDK 共用的工具函数。
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/ # schemagen —— 根据 DubheConfig 生成 Move 源文件
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
- ## schemagen 执行流程
319
+ ## generate 执行流程
320
320
 
321
- `schemaGen(rootDir, config, network?)` 是 `dubhe schemagen` 命令调用的主入口,**按顺序**执行以下步骤:
321
+ `schemaGen(rootDir, config, network?)` 是 `dubhe generate` 命令调用的主入口,**按顺序**执行以下步骤:
322
322
 
323
323
  ```
324
- schemagen
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 schemagen` 后,目录结构如下:
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
- `schemagen` 生成的 Move 合约代码并非独立运行,它必须搭配 **Dubhe Framework**(链上已部署的 `dubhe` 包)才能工作。Framework 是一个已部署在 Sui 链上的基础设施包,为所有通过 Dubhe 构建的 DApp 提供存储引擎、事件系统、费用计量、权限管理和版本控制能力。
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 schemagen
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
- `schemagen` 生成的 `dapp_key.move` 中定义了一个空结构体:
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'` 配置为例,`schemagen` 会生成 `health.move`,其核心写入路径为:
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 schemagen` 或 `dubhe publish` 时,CLI 会调用 `loadConfig(configPath?)`,流程如下:
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
@@ -1,21 +1,6 @@
1
1
  declare function formatMove(content: string, prettierConfigPath?: string): Promise<string>;
2
- declare function formatTypescript(content: string): Promise<string>;
3
2
 
4
3
  declare function formatAndWriteMove(output: string, fullOutputPath: string, logPrefix?: string): Promise<void>;
5
- /**
6
- * Formats typescript code using prettier and write it to a file
7
- * @param output typescript code
8
- * @param fullOutputPath full path to the output file
9
- * @param logPrefix prefix for debug logs
10
- */
11
- declare function formatAndWriteTypescript(output: string, fullOutputPath: string, logPrefix: string): Promise<void>;
12
-
13
- /**
14
- * Explicitly normalize a given path to a posix path (using `/` as separator).
15
- * This should be used for generating Solidity files that will be consumed by solc,
16
- * because solc expects `/` as path separator, but path.join produces `\` if the user is on windows.
17
- */
18
- declare function posixPath(path: string): string;
19
4
 
20
5
  type ComponentType = 'Onchain' | 'Offchain';
21
6
  type MoveType = 'address' | 'bool' | 'u8' | 'u32' | 'u64' | 'u128' | 'u256' | 'String' | 'vector<address>' | 'vector<bool>' | 'vector<u8>' | 'vector<vector<u8>>' | 'vector<u32>' | 'vector<u64>' | 'vector<u128>' | 'vector<u256>' | string;
@@ -25,19 +10,23 @@ type Component = {
25
10
  fields: Record<string, MoveType>;
26
11
  keys?: string[];
27
12
  };
13
+ type ErrorDefinition = {
14
+ message: string;
15
+ };
16
+ type ErrorEntry = string | ErrorDefinition;
28
17
  type DubheConfig = {
29
18
  name: string;
30
19
  description: string;
31
20
  enums?: Record<string, string[]>;
32
- resources: Record<string, Component | MoveType>;
33
- errors?: Record<string, string>;
21
+ resources?: Record<string, Component | MoveType>;
22
+ errors?: Record<string, ErrorEntry>;
34
23
  };
35
24
  type DubheMetadata = {
36
25
  resources: Record<string, Component | MoveType>;
37
26
  enums: Record<string, string[]>;
38
27
  };
39
28
  type BaseType = any;
40
- type ErrorData = any;
29
+ type ErrorData = Record<string, ErrorEntry>;
41
30
  type EventData = any;
42
31
  type SchemaData = any;
43
32
  type SchemaType = any;
@@ -47,9 +36,6 @@ declare function schemaGen(rootDir: string, config: DubheConfig, network?: 'main
47
36
  declare const defineConfig: (config: DubheConfig) => DubheConfig;
48
37
 
49
38
  declare function loadConfig(configPath?: string): Promise<unknown>;
50
- declare function resolveConfigPath(configPath: string | undefined, toFileURL?: boolean): Promise<string>;
51
-
52
- declare const parseData: (data: any) => any;
53
39
 
54
40
  declare enum SubscriptionKind {
55
41
  Event = "event",
@@ -64,4 +50,4 @@ type SubscribableType = {
64
50
  name?: string;
65
51
  };
66
52
 
67
- export { BaseType, Component, ComponentType, DubheConfig, DubheMetadata, ErrorData, EventData, MoveType, SchemaData, SchemaType, SubscribableType, SubscriptionKind, defineConfig, formatAndWriteMove, formatAndWriteTypescript, formatMove, formatTypescript, loadConfig, parseData, posixPath, resolveConfigPath, schemaGen };
53
+ export { BaseType, Component, ComponentType, DubheConfig, DubheMetadata, ErrorData, ErrorDefinition, ErrorEntry, EventData, MoveType, SchemaData, SchemaType, SubscribableType, SubscriptionKind, defineConfig, formatAndWriteMove, formatMove, loadConfig, schemaGen };