@0xobelisk/sui-common 0.5.20 ā 0.5.21
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/index.d.ts
CHANGED
|
@@ -17,9 +17,9 @@ declare function formatAndWriteTypescript(output: string, fullOutputPath: string
|
|
|
17
17
|
*/
|
|
18
18
|
declare function posixPath(path: string): string;
|
|
19
19
|
|
|
20
|
-
type BaseType =
|
|
21
|
-
type StorageDataType =
|
|
22
|
-
type StorageMapType =
|
|
20
|
+
type BaseType = 'String' | 'vector<String>' | 'address' | 'bool' | 'u8' | 'u32' | 'u64' | 'u128' | 'vector<address>' | 'vector<bool>' | 'vector<u8>' | 'vector<vector<u8>>' | 'vector<u32>' | 'vector<u64>' | 'vector<u128>' | string;
|
|
21
|
+
type StorageDataType = 'Struct' | 'Enum';
|
|
22
|
+
type StorageMapType = 'Map' | 'Bag' | 'Table';
|
|
23
23
|
type Address = string;
|
|
24
24
|
type Bool = boolean;
|
|
25
25
|
type U8 = number;
|
|
@@ -42,9 +42,8 @@ type DubheConfig = {
|
|
|
42
42
|
name: string;
|
|
43
43
|
description: string;
|
|
44
44
|
schemas: Record<string, SchemaType>;
|
|
45
|
-
migration_enabled: boolean;
|
|
46
45
|
};
|
|
47
|
-
type MoveType =
|
|
46
|
+
type MoveType = 'string' | 'vector<string>' | 'String' | 'vector<String>' | 'address' | 'bool' | 'u8' | 'u32' | 'u64' | 'u128' | 'vector<address>' | 'vector<bool>' | 'vector<u8>' | 'vector<vector<u8>>' | 'vector<u32>' | 'vector<u64>' | 'vector<u128>';
|
|
48
47
|
|
|
49
48
|
declare function schemaGen(config: DubheConfig, srcPrefix?: string, network?: 'mainnet' | 'testnet' | 'devnet' | 'localnet', frameworkId?: string): Promise<void>;
|
|
50
49
|
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import v from"prettier";import Z from"prettier-plugin-move-js";async function D(e,t){let o;t&&(o=await v.resolveConfig(t));try{return v.format(e,{plugins:[Z],parser:"move-parse",printWidth:120,semi:!0,tabWidth:2,useTabs:!1,bracketSpacing:!0,...o})}catch(r){let n;return r instanceof Error?n=r.message:n=r,console.log(`Error during output formatting: ${n}`),e}}async function T(e){return v.format(e,{parser:"typescript"})}import y from"node:fs/promises";import j from"node:path";import M from"debug";var b=M("dubhe:common"),X=M("dubhe:common");b.log=console.debug.bind(console);X.log=console.error.bind(console);var _=b.extend("codegen"),Y=b.extend("codegen");_.log=console.debug.bind(console);Y.log=console.error.bind(console);async function m(e,t,o){let r=await D(e),n=` // Copyright (c) Obelisk Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
#[allow(unused_use)]
|
|
4
4
|
|
|
5
5
|
/* Autogenerated file. Do not edit manually. */
|
|
6
6
|
|
|
7
|
-
`,
|
|
7
|
+
`,s=`#[allow(lint(share_owned))]
|
|
8
8
|
|
|
9
|
-
`,
|
|
10
|
-
\u{1F4C4} Starting Move.toml Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/Move.toml`);let
|
|
9
|
+
`,a=n+r;t.includes(".toml")||t.includes("system")||t.includes("migrate")?a=r:t.includes("deploy_hook")&&(a=s+r),await y.mkdir(j.dirname(t),{recursive:!0}),await y.writeFile(t,a),_(`${o}: ${t}`)}async function xe(e,t,o){let r=await T(e);await y.mkdir(j.dirname(t),{recursive:!0}),await y.writeFile(t,r),_(`${o}: ${t}`)}function we(e){return e.replace(/\\/g,"/")}import{existsSync as k}from"fs";import d from"fs";function w(e){d.existsSync(e)&&(d.readdirSync(e).forEach(t=>{let o=`${e}/${t}`;d.lstatSync(o).isDirectory()?w(o):d.unlinkSync(o)}),d.rmdirSync(e))}function g(e){return Object.entries(e).map(([t,o])=>`${t}`).join(",")}function W(e){return`(${Object.entries(e).map(([t,o])=>`${o}`)})`}function p(e){return Object.entries(e).map(([t,o])=>`${t}: ${o}`)}function G(e){return Object.entries(e).map(([t,o])=>`self.${t}`)}async function R(e,t,o){console.log(`
|
|
10
|
+
\u{1F4C4} Starting Move.toml Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/Move.toml`);let r=`[package]
|
|
11
11
|
name = "${e.name}"
|
|
12
12
|
version = "0.0.1"
|
|
13
13
|
edition = "2024.beta"
|
|
@@ -18,51 +18,51 @@ Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "relea
|
|
|
18
18
|
|
|
19
19
|
[addresses]
|
|
20
20
|
sui = "0x2"
|
|
21
|
-
dubhe = "${
|
|
21
|
+
dubhe = "${o}"
|
|
22
22
|
${e.name} = "0x0"
|
|
23
|
-
`;await m(
|
|
24
|
-
`)}function u(e){return e.split("_").map((t,
|
|
25
|
-
self.${
|
|
23
|
+
`;await m(r,`${t}/contracts/${e.name}/Move.toml`,"formatAndWriteMove"),console.log(`\u2705 Move.toml Generation Complete
|
|
24
|
+
`)}function u(e){return e.split("_").map((t,o)=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("")}function q(e,t){return Object.entries(t).map(([o,r])=>`public(package) fun set_${o}(self: &mut ${e}, ${o}: ${r}) {
|
|
25
|
+
self.${o} = ${o};
|
|
26
26
|
}`).join(`
|
|
27
|
-
`)}function
|
|
28
|
-
${Object.entries(t).map(([
|
|
27
|
+
`)}function J(e,t){return`public(package) fun set(self: &mut ${e}, ${p(t)}) {
|
|
28
|
+
${Object.entries(t).map(([o])=>`self.${o} = ${o};`).join(`
|
|
29
29
|
`)}
|
|
30
|
-
}`}function
|
|
31
|
-
(${
|
|
32
|
-
}`}function
|
|
33
|
-
self.${
|
|
30
|
+
}`}function P(e,t){return`public fun get(self: &${e}): ${W(t)} {
|
|
31
|
+
(${G(t)})
|
|
32
|
+
}`}function ee(e,t){return Object.entries(t).map(([o,r])=>`public fun get_${o}(self: &${e}): ${r} {
|
|
33
|
+
self.${o}
|
|
34
34
|
}`).join(`
|
|
35
|
-
`)}function
|
|
36
|
-
\u{1F4E6} Starting Schema Data Generation...`);for(let
|
|
37
|
-
public enum ${
|
|
38
|
-
${
|
|
35
|
+
`)}function l(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function H(e,t,o){console.log(`
|
|
36
|
+
\u{1F4E6} Starting Schema Data Generation...`);for(let r in t){let n=t[r];if(n.data){console.log(` \u251C\u2500 Processing schema: ${r}`);for(let s of n.data){console.log(` \u2514\u2500 Generating ${s.name} ${Array.isArray(s.fields)?"(enum)":"(struct)"}`);let a="",c=n.data.filter(i=>Array.isArray(i.fields)).map(i=>i.name);Array.isArray(s.fields)?a=`module ${e}::${r}_${l(s.name)} {
|
|
37
|
+
public enum ${s.name} has copy, drop , store {
|
|
38
|
+
${s.fields}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
${
|
|
42
|
-
${
|
|
43
|
-
}`).join("")}`:
|
|
41
|
+
${s.fields.map(i=>`public fun new_${l(i)}(): ${s.name} {
|
|
42
|
+
${s.name}::${i}
|
|
43
|
+
}`).join("")}`:a=`module ${e}::${r}_${l(s.name)} {
|
|
44
44
|
use std::ascii::String;
|
|
45
|
-
${
|
|
45
|
+
${c.map(i=>`use ${e}::${r}_${l(i)}::${i};`).join(`
|
|
46
46
|
`)}
|
|
47
47
|
|
|
48
|
-
public struct ${
|
|
49
|
-
${
|
|
48
|
+
public struct ${s.name} has copy, drop , store {
|
|
49
|
+
${p(s.fields)}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
public fun new(${
|
|
53
|
-
${
|
|
54
|
-
${
|
|
52
|
+
public fun new(${p(s.fields)}): ${s.name} {
|
|
53
|
+
${s.name} {
|
|
54
|
+
${g(s.fields)}
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
${
|
|
59
|
-
${
|
|
60
|
-
${
|
|
61
|
-
${
|
|
62
|
-
}`,await m(
|
|
63
|
-
`)}function
|
|
64
|
-
`):""}async function
|
|
65
|
-
\u{1F528} Starting Schema Structure Generation...`);for(let
|
|
58
|
+
${P(s.name,s.fields)}
|
|
59
|
+
${ee(s.name,s.fields)}
|
|
60
|
+
${q(s.name,s.fields)}
|
|
61
|
+
${J(s.name,s.fields)}
|
|
62
|
+
}`,await m(a,`${o}/contracts/${e}/sources/codegen/schemas/${r}_${l(s.name)}.move`,"formatAndWriteMove")}}}console.log(`\u2705 Schema Data Generation Complete
|
|
63
|
+
`)}function te(e,t,o){return o.data?o.data.map(r=>`use ${e}::${t}_${l(r.name)}::${r.name};`).join(`
|
|
64
|
+
`):""}async function O(e,t,o){console.log(`
|
|
65
|
+
\u{1F528} Starting Schema Structure Generation...`);for(let r in t){console.log(` \u251C\u2500 Generating schema: ${r}`),console.log(` \u251C\u2500 Output path: ${o}/contracts/${e}/sources/codegen/schemas/${r}.move`),console.log(` \u2514\u2500 Structure fields: ${Object.keys(t[r].structure).length}`);let n=t[r],s=`module ${e}::${r}_schema {
|
|
66
66
|
use std::ascii::String;
|
|
67
67
|
use std::ascii::string;
|
|
68
68
|
use sui::package::UpgradeCap;
|
|
@@ -75,55 +75,56 @@ ${e.name} = "0x0"
|
|
|
75
75
|
use dubhe::storage_double_map::{Self, StorageDoubleMap};
|
|
76
76
|
use ${e}::dapp_key::DappKey;
|
|
77
77
|
use sui::dynamic_field as df;
|
|
78
|
-
${
|
|
78
|
+
${te(e,r,n)}
|
|
79
79
|
|
|
80
|
-
public struct ${u(
|
|
80
|
+
public struct ${u(r)} has key, store {
|
|
81
81
|
id: UID
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
${Object.entries(n.structure).map(([
|
|
85
|
-
storage_migrate::borrow_field(&self.id, b"${
|
|
84
|
+
${Object.entries(n.structure).map(([a,c])=>`public fun borrow_${a}(self: &${u(r)}) : &${c} {
|
|
85
|
+
storage_migrate::borrow_field(&self.id, b"${a}")
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
public(package) fun borrow_mut_${
|
|
89
|
-
storage_migrate::borrow_mut_field(&mut self.id, b"${
|
|
88
|
+
public(package) fun borrow_mut_${a}(self: &mut ${u(r)}): &mut ${c} {
|
|
89
|
+
storage_migrate::borrow_mut_field(&mut self.id, b"${a}")
|
|
90
90
|
}
|
|
91
91
|
`).join("")}
|
|
92
92
|
|
|
93
93
|
|
|
94
|
-
public(package) fun create(ctx: &mut TxContext): ${u(
|
|
94
|
+
public(package) fun create(ctx: &mut TxContext): ${u(r)} {
|
|
95
95
|
let mut id = object::new(ctx);
|
|
96
|
-
${Object.entries(n.structure).map(([
|
|
96
|
+
${Object.entries(n.structure).map(([a,c])=>{let i="";return c.includes("StorageValue")?i="storage_value::new()":c.includes("StorageMap")?i="storage_map::new()":c.includes("StorageDoubleMap")&&(i="storage_double_map::new()"),`storage_migrate::add_field<${c}>(&mut id, b"${a}", ${i});`}).join("")}
|
|
97
97
|
|
|
98
|
-
${u(
|
|
98
|
+
${u(r)} { id }
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
public fun migrate(_${r}: &mut ${u(r)}, _cap: &UpgradeCap) { }
|
|
102
|
+
|
|
102
103
|
|
|
103
104
|
|
|
104
105
|
// ======================================== View Functions ========================================
|
|
105
|
-
${Object.entries(n.structure).map(([
|
|
106
|
-
self.borrow_${
|
|
106
|
+
${Object.entries(n.structure).map(([a,c])=>{let i=c.match(/<(.+)>/)[1].split(",").map(Q=>Q.trim()),f=[],$="",h="",x="";return c.includes("StorageValue")?(f=[],$=`${i[0]}`,h="try_get()"):c.includes("StorageMap")?(f=[`key: ${i[0]}`],$=`${i[1]}`,h="try_get(key)",x=`public fun get_${a}_keys(self: &${u(r)}) : vector<${i[0]}> {
|
|
107
|
+
self.borrow_${a}().keys()
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
public fun get_${
|
|
110
|
-
self.borrow_${
|
|
111
|
-
}`):
|
|
112
|
-
self.borrow_${
|
|
110
|
+
public fun get_${a}_values(self: &${u(r)}) : vector<${i[1]}> {
|
|
111
|
+
self.borrow_${a}().values()
|
|
112
|
+
}`):c.includes("StorageDoubleMap")&&(f=[`key1: ${i[0]}`,`key2: ${i[1]}`],$=`${i[2]}`,h="try_get(key1, key2)",x=`public fun get_${a}_keys(self: &${u(r)}) : (vector<${i[0]}>, vector<${i[1]}>) {
|
|
113
|
+
self.borrow_${a}().keys()
|
|
113
114
|
}
|
|
114
115
|
|
|
115
|
-
public fun get_${
|
|
116
|
-
self.borrow_${
|
|
117
|
-
}`),`public fun get_${
|
|
118
|
-
self.borrow_${
|
|
116
|
+
public fun get_${a}_values(self: &${u(r)}) : vector<${i[2]}> {
|
|
117
|
+
self.borrow_${a}().values()
|
|
118
|
+
}`),`public fun get_${a}(self: &${u(r)}, ${f}) : Option<${$}> {
|
|
119
|
+
self.borrow_${a}().${h}
|
|
119
120
|
}
|
|
120
|
-
`+
|
|
121
|
+
`+x}).join("")}
|
|
121
122
|
// =========================================================================================================
|
|
122
123
|
|
|
123
124
|
|
|
124
|
-
}`;await m(
|
|
125
|
-
`)}import{existsSync as
|
|
126
|
-
\u{1F4DD} Starting Deploy Hook Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/script/deploy_hook.move`),!
|
|
125
|
+
}`;await m(s,`${o}/contracts/${e}/sources/codegen/schemas/${r}.move`,"formatAndWriteMove")}console.log(`\u2705 Schema Structure Generation Complete
|
|
126
|
+
`)}import{existsSync as z}from"fs";async function E(e,t){if(console.log(`
|
|
127
|
+
\u{1F4DD} Starting Deploy Hook Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/script/deploy_hook.move`),!z(`${t}/contracts/${e.name}/sources/script/deploy_hook.move`)){let o=`module ${e.name}::deploy_hook {
|
|
127
128
|
use dubhe::dapps_schema::Dapps;
|
|
128
129
|
use dubhe::dapps_system;
|
|
129
130
|
use ${e.name}::schema_hub::SchemaHub;
|
|
@@ -131,7 +132,7 @@ ${e.name} = "0x0"
|
|
|
131
132
|
use sui::clock::Clock;
|
|
132
133
|
use sui::package::UpgradeCap;
|
|
133
134
|
use sui::transfer::public_share_object;
|
|
134
|
-
${Object.keys(e.schemas).map(
|
|
135
|
+
${Object.keys(e.schemas).map(r=>`use ${e.name}::${r}_schema::${u(r)};`).join(`
|
|
135
136
|
`)}
|
|
136
137
|
#[test_only]
|
|
137
138
|
use sui::clock;
|
|
@@ -150,7 +151,7 @@ ${e.name} = "0x0"
|
|
|
150
151
|
// Register the dapp to dubhe.
|
|
151
152
|
dapps_system::register(dapps,cap,string(b"${e.name}"),string(b"${e.description}"),clock,ctx);
|
|
152
153
|
// Create schemas
|
|
153
|
-
${Object.keys(e.schemas).map(
|
|
154
|
+
${Object.keys(e.schemas).map(r=>`let ${r} = ${e.name}::${r}_schema::create(ctx);`).join(`
|
|
154
155
|
`)}
|
|
155
156
|
// Logic that needs to be automated once the contract is deployed
|
|
156
157
|
|
|
@@ -159,9 +160,9 @@ ${e.name} = "0x0"
|
|
|
159
160
|
|
|
160
161
|
|
|
161
162
|
// Authorize schemas and public share objects
|
|
162
|
-
${Object.keys(e.schemas).map(
|
|
163
|
-
schema_hub.authorize_schema<${u(
|
|
164
|
-
public_share_object(${
|
|
163
|
+
${Object.keys(e.schemas).map(r=>`
|
|
164
|
+
schema_hub.authorize_schema<${u(r)}>();
|
|
165
|
+
public_share_object(${r});
|
|
165
166
|
`).join(`
|
|
166
167
|
`)}
|
|
167
168
|
}
|
|
@@ -188,16 +189,16 @@ ${e.name} = "0x0"
|
|
|
188
189
|
(scenario, schema_hub, dapps)
|
|
189
190
|
}
|
|
190
191
|
}
|
|
191
|
-
`;await m(
|
|
192
|
-
`)}async function
|
|
192
|
+
`;await m(o,`${t}/contracts/${e.name}/sources/script/deploy_hook.move`,"formatAndWriteMove")}console.log(`\u2705 Deploy Hook Generation Complete
|
|
193
|
+
`)}async function U(e,t){if(!z(`${t}/contracts/${e.name}/sources/script/migrate.move`)){let o=`module ${e.name}::migrate {
|
|
193
194
|
const ON_CHAIN_VERSION: u32 = 0;
|
|
194
195
|
|
|
195
196
|
public fun on_chain_version(): u32 {
|
|
196
197
|
ON_CHAIN_VERSION
|
|
197
198
|
}
|
|
198
199
|
}
|
|
199
|
-
`;await m(
|
|
200
|
-
\u{1F511} Starting DappKey Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/codegen/dapp_key.move`);let
|
|
200
|
+
`;await m(o,`${t}/contracts/${e.name}/sources/script/migrate.move`,"formatAndWriteMove")}}async function F(e,t){console.log(`
|
|
201
|
+
\u{1F511} Starting DappKey Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/codegen/dapp_key.move`);let o=`module ${e.name}::dapp_key {
|
|
201
202
|
/// Authorization token for the app.
|
|
202
203
|
public struct DappKey has drop {}
|
|
203
204
|
|
|
@@ -205,30 +206,30 @@ ${e.name} = "0x0"
|
|
|
205
206
|
DappKey { }
|
|
206
207
|
}
|
|
207
208
|
}
|
|
208
|
-
`;await m(
|
|
209
|
-
`)}function
|
|
210
|
-
\u{1F4E6} Starting Schema Event Generation...`);for(let
|
|
209
|
+
`;await m(o,`${t}/contracts/${e.name}/sources/codegen/dapp_key.move`,"formatAndWriteMove"),console.log(`\u2705 DappKey Generation Complete
|
|
210
|
+
`)}function L(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function I(e,t,o){console.log(`
|
|
211
|
+
\u{1F4E6} Starting Schema Event Generation...`);for(let r in t){let n=t[r];if(n.events){console.log(` \u251C\u2500 Processing schema: ${r}`);for(let s of n.events){console.log(` \u2514\u2500 Generating ${s.name} ${Array.isArray(s.fields)?"(enum)":"(struct)"}`);let a=`module ${e}::${r}_${L(s.name)}_event {
|
|
211
212
|
use sui::event;
|
|
212
213
|
use std::ascii::String;
|
|
213
|
-
public struct ${
|
|
214
|
-
${
|
|
214
|
+
public struct ${s.name}Event has copy, drop {
|
|
215
|
+
${p(s.fields)}
|
|
215
216
|
}
|
|
216
217
|
|
|
217
|
-
public fun new(${
|
|
218
|
-
${
|
|
219
|
-
${
|
|
218
|
+
public fun new(${p(s.fields)}): ${s.name}Event {
|
|
219
|
+
${s.name}Event {
|
|
220
|
+
${g(s.fields)}
|
|
220
221
|
}
|
|
221
222
|
}
|
|
222
223
|
|
|
223
|
-
public fun emit(${
|
|
224
|
-
event::emit(${
|
|
225
|
-
${
|
|
224
|
+
public fun emit(${p(s.fields)}) {
|
|
225
|
+
event::emit(${s.name}Event {
|
|
226
|
+
${g(s.fields)}
|
|
226
227
|
});
|
|
227
|
-
}`;await m(
|
|
228
|
-
`)}import{existsSync as
|
|
229
|
-
\u2699\uFE0F Starting System Generation...`),console.log(" \u251C\u2500 Generating systems"),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/systems`),
|
|
230
|
-
`)}async function
|
|
231
|
-
\u{1F511} Starting DappKey Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/codegen/schema_hub.move`);let
|
|
228
|
+
}`;await m(a,`${o}/contracts/${e}/sources/codegen/events/${r}_${L(s.name)}_event.move`,"formatAndWriteMove")}}}console.log(`\u2705 Schema Event Generation Complete
|
|
229
|
+
`)}import{existsSync as re}from"fs";import oe from"node:fs/promises";async function K(e,t){console.log(`
|
|
230
|
+
\u2699\uFE0F Starting System Generation...`),console.log(" \u251C\u2500 Generating systems"),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/systems`),re(`${t}/contracts/${e.name}/sources/systems`)||await oe.mkdir(`${t}/contracts/${e.name}/sources/systems`,{recursive:!0}),console.log(`\u2705 System Generation Complete
|
|
231
|
+
`)}async function B(e,t){console.log(`
|
|
232
|
+
\u{1F511} Starting DappKey Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/codegen/schema_hub.move`);let o=`module ${e.name}::schema_hub {
|
|
232
233
|
use sui::transfer::public_share_object;
|
|
233
234
|
use sui::dynamic_field as df;
|
|
234
235
|
|
|
@@ -273,9 +274,9 @@ ${e.name} = "0x0"
|
|
|
273
274
|
init(ctx);
|
|
274
275
|
}
|
|
275
276
|
}
|
|
276
|
-
`;await m(
|
|
277
|
-
`)}function
|
|
278
|
-
\u{1F680} Starting Schema Generation Process...`),console.log("\u{1F4CB} Project Configuration:"),console.log(` \u251C\u2500 Name: ${e.name}`),console.log(` \u251C\u2500 Description: ${e.description||"No description provided"}`),console.log(` \u251C\u2500 Network: ${
|
|
279
|
-
`);let
|
|
280
|
-
`)}import{findUp as
|
|
277
|
+
`;await m(o,`${t}/contracts/${e.name}/sources/codegen/schema_hub.move`,"formatAndWriteMove"),console.log(`\u2705 DappKey Generation Complete
|
|
278
|
+
`)}function V(e){switch(e){case"testnet":return"0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6";case"localnet":return"0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6";default:return"0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6"}}async function nt(e,t,o,r){console.log(`
|
|
279
|
+
\u{1F680} Starting Schema Generation Process...`),console.log("\u{1F4CB} Project Configuration:"),console.log(` \u251C\u2500 Name: ${e.name}`),console.log(` \u251C\u2500 Description: ${e.description||"No description provided"}`),console.log(` \u251C\u2500 Network: ${o||"testnet"}`),console.log(` \u2514\u2500 Framework ID: ${r||V(o??"testnet")}
|
|
280
|
+
`);let n=t??process.cwd();r=r||V(o??"testnet"),k(`${n}/contracts/${e.name}`)&&w(`${n}/contracts/${e.name}/sources/codegen`),k(`${n}/contracts/${e.name}/Move.toml`)||await R(e,n,r),k(`${n}/contracts/${e.name}/sources/script/deploy_hook.move`)||await E(e,n),await H(e.name,e.schemas,n),await O(e.name,e.schemas,n),await I(e.name,e.schemas,n),await F(e,n),await B(e,n),await K(e,n),await U(e,n),console.log(`\u2705 Schema Generation Process Complete!
|
|
281
|
+
`)}import{findUp as se}from"find-up";import A from"path";import ne from"esbuild";var S=class extends Error{name="NotInsideProjectError";message="You are not inside a Dubhe project"};import{rmSync as ae}from"fs";import{pathToFileURL as ie}from"url";import ce from"os";var me=["dubhe.config.js","dubhe.config.mjs","dubhe.config.ts","dubhe.config.mts"],C="dubhe.config.example.mjs";async function ft(e){e=await N(e);try{return await ne.build({entryPoints:[e],format:"esm",outfile:C,platform:"node",bundle:!0,packages:"external"}),e=await N(C,!0),(await import(e+`?update=${Date.now()}`)).dubheConfig}finally{ae(C,{force:!0})}}async function N(e,t){return e===void 0?e=await ue():A.isAbsolute(e)||(e=A.join(process.cwd(),e),e=A.normalize(e)),t&&ce.platform()==="win32"?ie(e).href:e}async function ue(){let e=await se(me);if(e===void 0)throw new S;return e}export{m as formatAndWriteMove,xe as formatAndWriteTypescript,D as formatMove,T as formatTypescript,ft as loadConfig,we as posixPath,N as resolveConfigPath,nt as schemaGen};
|
|
281
282
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/codegen/utils/format.ts","../src/codegen/utils/formatAndWrite.ts","../src/debug.ts","../src/codegen/debug.ts","../src/codegen/utils/posixPath.ts","../src/codegen/utils/renderMove/schemaGen.ts","../src/codegen/utils/renderMove/common.ts","../src/codegen/utils/renderMove/generateToml.ts","../src/codegen/utils/renderMove/generateSchema.ts","../src/codegen/utils/renderMove/generateScript.ts","../src/codegen/utils/renderMove/generateDappKey.ts","../src/codegen/utils/renderMove/generateEvent.ts","../src/codegen/utils/renderMove/generateSystem.ts","../src/codegen/utils/renderMove/generateSchemaHub.ts","../src/codegen/utils/config.ts","../src/codegen/utils/errors.ts"],"sourcesContent":["import prettier from 'prettier';\nimport prettierPluginMove from 'prettier-plugin-move-js';\n\nexport async function formatMove(\n\tcontent: string,\n\tprettierConfigPath?: string\n): Promise<string> {\n\tlet config;\n\tif (prettierConfigPath) {\n\t\tconfig = await prettier.resolveConfig(prettierConfigPath);\n\t}\n\ttry {\n\t\treturn prettier.format(content, {\n\t\t\tplugins: [prettierPluginMove],\n\t\t\tparser: 'move-parse',\n\t\t\tprintWidth: 120,\n\t\t\tsemi: true,\n\t\t\ttabWidth: 2,\n\t\t\tuseTabs: false,\n\t\t\tbracketSpacing: true,\n\t\t\t...config,\n\t\t});\n\t} catch (error) {\n\t\tlet message;\n\t\tif (error instanceof Error) {\n\t\t\tmessage = error.message;\n\t\t} else {\n\t\t\tmessage = error;\n\t\t}\n\t\tconsole.log(`Error during output formatting: ${message}`);\n\t\treturn content;\n\t}\n}\n\nexport async function formatTypescript(content: string): Promise<string> {\n\treturn prettier.format(content, {\n\t\tparser: 'typescript',\n\t});\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { formatMove, formatTypescript } from \"./format\";\nimport { debug } from \"../debug\";\n\nexport async function formatAndWriteMove(\n output: string,\n fullOutputPath: string,\n logPrefix?: string\n): Promise<void> {\n const formattedOutput = await formatMove(output);\n let schemaPrefix =\n` // Copyright (c) Obelisk Labs, Inc.\n // SPDX-License-Identifier: MIT\n #[allow(unused_use)]\n \n /* Autogenerated file. Do not edit manually. */\n \n `\n\n let deployHookPrefix = `#[allow(lint(share_owned))]\n \n `\n\n let code = schemaPrefix + formattedOutput\n\n if (fullOutputPath.includes(\".toml\") || fullOutputPath.includes(\"system\") || fullOutputPath.includes(\"migrate\")) {\n code = formattedOutput\n } else if (fullOutputPath.includes(\"deploy_hook\")) {\n code = deployHookPrefix + formattedOutput\n }\n\n await fs.mkdir(path.dirname(fullOutputPath), { recursive: true });\n await fs.writeFile(fullOutputPath, code);\n debug(`${logPrefix}: ${fullOutputPath}`);\n}\n\n/**\n * Formats typescript code using prettier and write it to a file\n * @param output typescript code\n * @param fullOutputPath full path to the output file\n * @param logPrefix prefix for debug logs\n */\nexport async function formatAndWriteTypescript(\n output: string,\n fullOutputPath: string,\n logPrefix: string,\n): Promise<void> {\n const formattedOutput = await formatTypescript(output);\n\n await fs.mkdir(path.dirname(fullOutputPath), { recursive: true });\n\n await fs.writeFile(fullOutputPath, formattedOutput);\n debug(`${logPrefix}: ${fullOutputPath}`);\n}\n","import createDebug from \"debug\";\n\nexport const debug = createDebug(\"dubhe:common\");\nexport const error = createDebug(\"dubhe:common\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n","import { debug as parentDebug } from \"../debug\";\n\nexport const debug = parentDebug.extend(\"codegen\");\nexport const error = parentDebug.extend(\"codegen\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n","/**\n * Explicitly normalize a given path to a posix path (using `/` as separator).\n * This should be used for generating Solidity files that will be consumed by solc,\n * because solc expects `/` as path separator, but path.join produces `\\` if the user is on windows.\n */\nexport function posixPath(path: string): string {\n return path.replace(/\\\\/g, \"/\");\n}\n","import { SchemaType, DubheConfig } from '../../types';\nimport { rmdirSync, existsSync } from 'fs';\nimport { deleteFolderRecursive } from './common';\nimport { generateToml } from './generateToml';\nimport { generateSchemaData, generateSchemaStructure } from './generateSchema';\nimport { generateDeployHook, generateMigrate } from './generateScript';\nimport { generateDappKey } from './generateDappKey';\nimport {generateSchemaEvent} from \"./generateEvent\";\nimport { generateSystem } from './generateSystem';\nimport { generateSchemaHub } from './generateSchemaHub';\n\nfunction matchFrameworkId(\n\tnetwork: 'mainnet' | 'testnet' | 'devnet' | 'localnet'\n): string {\n\tswitch (network) {\n\t\tcase 'testnet':\n\t\t\treturn '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';\n\t\tcase 'localnet':\n\t\t\treturn '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';\n\t\tdefault:\n\t\t\treturn '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';\n\t}\n}\n\nexport async function schemaGen(\n\tconfig: DubheConfig,\n\tsrcPrefix?: string,\n\tnetwork?: 'mainnet' | 'testnet' | 'devnet' | 'localnet',\n\tframeworkId?: string\n) {\n\tconsole.log('\\nš Starting Schema Generation Process...');\n\tconsole.log('š Project Configuration:');\n\tconsole.log(` āā Name: ${config.name}`);\n\tconsole.log(\n\t\t` āā Description: ${config.description || 'No description provided'}`\n\t);\n\tconsole.log(` āā Network: ${network || 'testnet'}`);\n\tconsole.log(\n\t\t` āā Framework ID: ${\n\t\t\tframeworkId || matchFrameworkId(network ?? 'testnet')\n\t\t}\\n`\n\t);\n\n\tconst path = srcPrefix ?? process.cwd();\n\n\tframeworkId = frameworkId || matchFrameworkId(network ?? 'testnet');\n\n\tif (existsSync(`${path}/contracts/${config.name}`)) {\n\t\tdeleteFolderRecursive(\n\t\t\t`${path}/contracts/${config.name}/sources/codegen`\n\t\t);\n\t}\n\n\tif (!existsSync(`${path}/contracts/${config.name}/Move.toml`)) {\n\t\tawait generateToml(config, path, frameworkId);\n\t}\n\n\tif (\n\t\t!existsSync(\n\t\t\t`${path}/contracts/${config.name}/sources/script/deploy_hook.move`\n\t\t)\n\t) {\n\t\tawait generateDeployHook(config, path);\n\t}\n\n\tawait generateSchemaData(config.name, config.schemas, path);\n\tawait generateSchemaStructure(config.name, config.schemas, path, config.migration_enabled);\n\tawait generateSchemaEvent(config.name, config.schemas, path);\n\tawait generateDappKey(config, path);\n\tawait generateSchemaHub(config, path);\n\tawait generateSystem(config, path);\n\tif (config.migration_enabled) {\n\t\tawait generateMigrate(config, path);\n\t}\n\tconsole.log('ā
Schema Generation Process Complete!\\n');\n}\n","import { MoveType } from '../../types';\nimport fs from 'fs';\n\nexport function deleteFolderRecursive(path: string) {\n\tif (fs.existsSync(path)) {\n\t\tfs.readdirSync(path).forEach(file => {\n\t\t\tconst curPath = `${path}/${file}`;\n\t\t\tif (fs.lstatSync(curPath).isDirectory()) {\n\t\t\t\tdeleteFolderRecursive(curPath);\n\t\t\t} else {\n\t\t\t\tfs.unlinkSync(curPath);\n\t\t\t}\n\t\t});\n\t\tfs.rmdirSync(path);\n\t}\n}\n\nexport function capitalizeFirstLetter(input: string): string {\n\treturn input.charAt(0).toUpperCase() + input.slice(1);\n}\n\n/**\n *\n * @param values\n * @param prefixArgs\n * @return [ name, age, birth_time ]\n */\nexport function getStructAttrs(\n\tvalues: Record<string, string> | string\n): string {\n\treturn Object.entries(values)\n\t\t.map(([key, _]) => `${key}`)\n\t\t.join(',');\n}\n\nfunction isAddress(str: string): boolean {\n\tconst regex = /^0x[a-fA-F0-9]+$/;\n\treturn regex.test(str);\n}\n\n/**\n *\n * @param values\n * @return ( bool , u64 , u64)\n */\n// export function getStructTypes(values: SchemaType): string {\nexport function getStructTypes(\n\tvalues: Record<string, string>\n): string {\n\treturn `(${Object.entries(values).map(([_, type]) => `${type}`)})`;\n}\n\n/**\n *\n * @param values\n * @return Attributes and types of the struct. [ name: string, age: u64 ]\n */\nexport function getStructAttrsWithType(\n\tvalues: Record<string, string>\n): string[] {\n\treturn Object.entries(values).map(([key, type]) => `${key}: ${type}`);\n}\n\n/**\n * @param values\n * @return [ data.name, data.age ]\n */\nexport function getStructAttrsQuery(\n\tvalues: Record<string, string>,\n): string[] {\n\treturn Object.entries(values).map(([key, _]) => `self.${key}`);\n}\n","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\n\nexport async function generateToml(\n\tconfig: DubheConfig,\n\tsrcPrefix: string,\n\tframeworkId: string\n) {\n\tconsole.log('\\nš Starting Move.toml Generation...');\n\tconsole.log(\n\t\t` āā Output path: ${srcPrefix}/contracts/${config.name}/Move.toml`\n\t);\n\n\tlet code = `[package]\nname = \"${config.name}\"\nversion = \"0.0.1\"\nedition = \"2024.beta\"\n\n[dependencies]\nSui = { git = \"https://github.com/MystenLabs/sui.git\", subdir = \"crates/sui-framework/packages/sui-framework\", rev = \"mainnet-v1.36.2\" }\nDubhe = { git = \"https://github.com/0xobelisk/dubhe-framework.git\", rev = \"release-dubhe-v1.0.0-rc1\" }\n\n[addresses]\nsui = \"0x2\"\ndubhe = \"${frameworkId}\"\n${config.name} = \"0x0\"\n`;\n\tawait formatAndWriteMove(\n\t\tcode,\n\t\t`${srcPrefix}/contracts/${config.name}/Move.toml`,\n\t\t'formatAndWriteMove'\n\t);\n\tconsole.log('ā
Move.toml Generation Complete\\n');\n}\n","import { BaseType, SchemaType } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport {\n\tgetStructAttrsWithType,\n\tgetStructAttrs,\n\tgetStructTypes,\n\tgetStructAttrsQuery,\n} from './common';\n\nexport function capitalizeAndRemoveUnderscores(input: string): string {\n\treturn input\n\t\t.split('_')\n\t\t.map((word, index) => {\n\t\t\treturn index === 0\n\t\t\t\t? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()\n\t\t\t\t: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();\n\t\t})\n\t\t.join('');\n}\n\nexport function renderSetAttrsFunc(\n\tschemaName: string,\n\tfields: BaseType | Record<string, BaseType>\n): string {\n\treturn Object.entries(fields)\n\t\t.map(\n\t\t\t([key, type]) =>\n\t\t\t\t`public(package) fun set_${key}(self: &mut ${schemaName}, ${key}: ${type}) {\n self.${key} = ${key};\n }`\n\t\t)\n\t\t.join('\\n');\n}\n\nexport function renderSetFunc(\n\tschemaName: string,\n\tfields: Record<string, string>\n): string {\n\treturn `public(package) fun set(self: &mut ${schemaName}, ${getStructAttrsWithType(\n\t\tfields\n\t)}) {\n ${Object.entries(fields)\n\t\t\t\t.map(([fieldName]) => `self.${fieldName} = ${fieldName};`)\n\t\t\t\t.join('\\n')}\n }`;\n}\n\nexport function renderGetAllFunc(\n\tschemaName: string,\n\tfields: Record<string, string>\n): string {\n\treturn `public fun get(self: &${schemaName}): ${getStructTypes(fields)} {\n (${getStructAttrsQuery(fields)})\n }`;\n}\n\nexport function renderGetAttrsFunc(\n\tschemaName: string,\n\tfields: BaseType | Record<string, BaseType>\n): string {\n\treturn Object.entries(fields)\n\t\t.map(\n\t\t\t([\n\t\t\t\tkey,\n\t\t\t\ttype,\n\t\t\t]) => `public fun get_${key}(self: &${schemaName}): ${type} {\n self.${key}\n }`\n\t\t)\n\t\t.join('\\n');\n}\n\nfunction convertToSnakeCase(input: string): string {\n\treturn input\n\t\t.replace(/([A-Z])/g, '_$1')\n\t\t.toLowerCase()\n\t\t.replace(/^_/, '');\n}\n\nexport async function generateSchemaData(\n\tprojectName: string,\n\tschemas: Record<string, SchemaType>,\n\tpath: string\n) {\n\tconsole.log('\\nš¦ Starting Schema Data Generation...');\n\tfor (const schemaName in schemas) {\n\t\tconst schema = schemas[schemaName];\n\t\tif (schema.data) {\n\t\t\tconsole.log(` āā Processing schema: ${schemaName}`);\n\t\t\tfor (const item of schema.data) {\n\t\t\t\tconsole.log(\n\t\t\t\t\t` āā Generating ${item.name} ${\n\t\t\t\t\t\tArray.isArray(item.fields) ? '(enum)' : '(struct)'\n\t\t\t\t\t}`\n\t\t\t\t);\n\t\t\t\tlet code = '';\n\n\t\t\t\tconst enumNames = schema.data\n\t\t\t\t\t.filter(item => Array.isArray(item.fields))\n\t\t\t\t\t.map(item => item.name);\n\n\t\t\t\tif (Array.isArray(item.fields)) {\n\t\t\t\t\tcode = `module ${projectName}::${schemaName}_${convertToSnakeCase(\n\t\t\t\t\t\titem.name\n\t\t\t\t\t)} {\n public enum ${item.name} has copy, drop , store {\n ${item.fields}\n }\n \n ${item.fields\n\t\t\t\t\t\t\t.map((field: string) => {\n\t\t\t\t\t\t\t\treturn `public fun new_${convertToSnakeCase(\n\t\t\t\t\t\t\t\t\tfield\n\t\t\t\t\t\t\t\t)}(): ${item.name} {\n ${item.name}::${field}\n }`;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.join('')}`;\n\t\t\t\t} else {\n\t\t\t\t\tcode = `module ${projectName}::${schemaName}_${convertToSnakeCase(\n\t\t\t\t\t\titem.name\n\t\t\t\t\t)} {\n use std::ascii::String;\n ${enumNames\n\t\t\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t\t\tname =>\n\t\t\t\t\t\t\t\t\t\t`use ${projectName}::${schemaName}_${convertToSnakeCase(\n\t\t\t\t\t\t\t\t\t\t\tname\n\t\t\t\t\t\t\t\t\t\t)}::${name};`\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.join('\\n')}\n\n public struct ${item.name} has copy, drop , store {\n ${getStructAttrsWithType(item.fields)}\n }\n \n public fun new(${getStructAttrsWithType(\n\t\t\t\t\t\t\t\titem.fields\n\t\t\t\t\t\t\t)}): ${item.name} {\n ${item.name} {\n ${getStructAttrs(item.fields)}\n }\n }\n \n ${renderGetAllFunc(item.name, item.fields)}\n ${renderGetAttrsFunc(item.name, item.fields)}\n ${renderSetAttrsFunc(item.name, item.fields)}\n ${renderSetFunc(item.name, item.fields)}\n }`;\n\t\t\t\t}\n\n\t\t\t\tawait formatAndWriteMove(\n\t\t\t\t\tcode,\n\t\t\t\t\t`${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}_${convertToSnakeCase(\n\t\t\t\t\t\titem.name\n\t\t\t\t\t)}.move`,\n\t\t\t\t\t'formatAndWriteMove'\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\tconsole.log('ā
Schema Data Generation Complete\\n');\n}\n\nfunction generateImport(\n\tprojectName: string,\n\tschemaName: string,\n\tschema: SchemaType\n) {\n\tif (schema.data) {\n\t\treturn schema.data\n\t\t\t.map(item => {\n\t\t\t\treturn `use ${projectName}::${schemaName}_${convertToSnakeCase(\n\t\t\t\t\titem.name\n\t\t\t\t)}::${item.name};`;\n\t\t\t})\n\t\t\t.join('\\n');\n\t} else {\n\t\treturn '';\n\t}\n}\n\nexport async function generateSchemaStructure(\n\tprojectName: string,\n\tschemas: Record<string, SchemaType>,\n\tpath: string,\n\tmigration_enabled: boolean\n) {\n\tconsole.log('\\nšØ Starting Schema Structure Generation...');\n\tfor (const schemaName in schemas) {\n\t\tconsole.log(` āā Generating schema: ${schemaName}`);\n\t\tconsole.log(\n\t\t\t` āā Output path: ${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`\n\t\t);\n\t\tconsole.log(\n\t\t\t` āā Structure fields: ${\n\t\t\t\tObject.keys(schemas[schemaName].structure).length\n\t\t\t}`\n\t\t);\n\t\tconst schema = schemas[schemaName];\n\t\tconst schemaMoudle = `module ${projectName}::${schemaName}_schema {\n use std::ascii::String;\n use std::ascii::string;\n use sui::package::UpgradeCap;\n use std::type_name;\n use dubhe::dapps_system;\n use dubhe::storage_migrate;\n use dubhe::dapps_schema::Dapps;\n use dubhe::storage_value::{Self, StorageValue};\n use dubhe::storage_map::{Self, StorageMap};\n use dubhe::storage_double_map::{Self, StorageDoubleMap};\n use ${projectName}::dapp_key::DappKey;\n use sui::dynamic_field as df;\n ${generateImport(projectName, schemaName, schema)}\n\n public struct ${capitalizeAndRemoveUnderscores(\n\t\t\t\t\t\tschemaName\n\t\t\t\t\t)} has key, store {\n id: UID\n\t\t\t\t\t\t\t\t\t\t\t} \n \n ${Object.entries(schema.structure)\n\t\t\t\t\t\t\t.map(([key, value]) => {\n\t\t\t\t\t\t\t\treturn `public fun borrow_${key}(self: &${capitalizeAndRemoveUnderscores(\n\t\t\t\t\t\t\t\t\tschemaName\n\t\t\t\t\t\t\t\t)}) : &${value} {\n storage_migrate::borrow_field(&self.id, b\"${key}\")\n }\n \n public(package) fun borrow_mut_${key}(self: &mut ${capitalizeAndRemoveUnderscores(\n\t\t\t\t\t\tschemaName\n\t\t\t\t\t)}): &mut ${value} {\n storage_migrate::borrow_mut_field(&mut self.id, b\"${key}\")\n }\n `;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.join('')} \n \n \n public(package) fun create(ctx: &mut TxContext): ${capitalizeAndRemoveUnderscores(\n\t\t\t\t\t\tschemaName\n\t\t\t\t\t)} {\n let mut id = object::new(ctx);\n ${Object.entries(schema.structure)\n\t\t\t\t\t\t\t\t\t\t\t.map(([key, value]) => {\n\t\t\t\t\t\t\t\t\t\t\t\tlet storage_type = '';\n\t\t\t\t\t\t\t\t\t\t\t\tif (value.includes('StorageValue')) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tstorage_type = `storage_value::new()`;\n\t\t\t\t\t\t\t\t\t\t\t\t} else if (value.includes('StorageMap')) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tstorage_type = `storage_map::new()`;\n\t\t\t\t\t\t\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue.includes('StorageDoubleMap')\n\t\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tstorage_type = `storage_double_map::new()`;\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\treturn `storage_migrate::add_field<${value}>(&mut id, b\"${key}\", ${storage_type});`\n\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\t.join('')}\n \n ${capitalizeAndRemoveUnderscores(schemaName)} { id }\n }\n \n ${ migration_enabled ? `public fun migrate(_${schemaName}: &mut ${capitalizeAndRemoveUnderscores(schemaName)}, _cap: &UpgradeCap) { }`\n\t\t\t\t\t : \"\"\n\t\t\t\t\t\t\t\t\t\t}\n \n \n // ======================================== View Functions ========================================\n ${Object.entries(schema.structure)\n\t\t\t.map(([key, value]) => {\n\t\t\t\t// @ts-ignore\n\t\t\t\tlet all_types = value.match(/<(.+)>/)[1].split(',').map(type => type.trim())\n\t\t\t\tlet para_key: string[] = []\n\t\t\t\tlet para_value = \"\"\n\t\t\t\tlet borrow_key = \"\"\n\t\t\t\tlet extra_code = \"\"\n\t\t\t\tif (value.includes('StorageValue')) {\n\t\t\t\t\tpara_key = []\n\t\t\t\t\tpara_value = `${all_types[0]}`\n\t\t\t\t\tborrow_key = 'try_get()'\n\t\t\t\t} else if (value.includes('StorageMap')) {\n\t\t\t\t\tpara_key = [`key: ${all_types[0]}`]\n\t\t\t\t\tpara_value = `${all_types[1]}`\n\t\t\t\t\tborrow_key = 'try_get(key)'\n\t\t\t\t\textra_code = `public fun get_${key}_keys(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : vector<${all_types[0]}> {\n\t\t\t\t\t\t\t\t\tself.borrow_${key}().keys()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tpublic fun get_${key}_values(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : vector<${all_types[1]}> {\n\t\t\t\t\t\t\t\t\tself.borrow_${key}().values()\n\t\t\t\t\t\t\t\t}`\n\t\t\t\t} else if (value.includes('StorageDoubleMap')) {\n\t\t\t\t\tpara_key = [`key1: ${all_types[0]}`, `key2: ${all_types[1]}`]\n\t\t\t\t\tpara_value = `${all_types[2]}`\n\t\t\t\t\tborrow_key = 'try_get(key1, key2)'\n\t\t\t\t\textra_code = `public fun get_${key}_keys(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : (vector<${all_types[0]}>, vector<${all_types[1]}>) {\n\t\t\t\t\t\t\t\t\tself.borrow_${key}().keys()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tpublic fun get_${key}_values(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : vector<${all_types[2]}> {\n\t\t\t\t\t\t\t\t\tself.borrow_${key}().values()\n\t\t\t\t\t\t\t\t}`\n\t\t\t\t}\n\t\t\t\treturn `public fun get_${key}(self: &${capitalizeAndRemoveUnderscores(schemaName)}, ${para_key}) : Option<${para_value}> {\n\t\t\t\t\t\t\t\t\tself.borrow_${key}().${borrow_key}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t` + extra_code;\n\t\t\t})\n\t\t\t.join('')} \n // =========================================================================================================\n \n \n }`;\n\t\tawait formatAndWriteMove(\n\t\t\tschemaMoudle,\n\t\t\t`${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n\tconsole.log('ā
Schema Structure Generation Complete\\n');\n}\n","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport { existsSync } from 'fs';\nimport { capitalizeAndRemoveUnderscores } from './generateSchema';\n\nexport async function generateDeployHook(\n\tconfig: DubheConfig,\n\tsrcPrefix: string\n) {\n\tconsole.log('\\nš Starting Deploy Hook Generation...');\n\tconsole.log(\n\t\t` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`\n\t);\n\n\tif (\n\t\t!existsSync(\n\t\t\t`${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`\n\t\t)\n\t) {\n\t\tlet code = `module ${config.name}::deploy_hook {\n use dubhe::dapps_schema::Dapps;\n use dubhe::dapps_system;\n use ${config.name}::schema_hub::SchemaHub;\n use std::ascii::string;\n use sui::clock::Clock;\n use sui::package::UpgradeCap;\n use sui::transfer::public_share_object;\n ${Object.keys(config.schemas).map(schemaName => {\n\t\t\treturn `use ${config.name}::${schemaName}_schema::${capitalizeAndRemoveUnderscores(schemaName)};`}).join('\\n')\n\t\t}\n #[test_only]\n use sui::clock;\n #[test_only]\n use sui::test_scenario;\n #[test_only]\n use sui::package;\n #[test_only]\n use ${config.name}::schema_hub; \n #[test_only]\n use dubhe::dapps_schema;\n #[test_only]\n use sui::test_scenario::Scenario;\n\n public entry fun run(schema_hub: &mut SchemaHub, dapps: &mut Dapps, cap: &UpgradeCap, clock: &Clock, ctx: &mut TxContext) {\n // Register the dapp to dubhe.\n dapps_system::register(dapps,cap,string(b\"${config.name}\"),string(b\"${config.description}\"),clock,ctx);\n // Create schemas\n ${Object.keys(config.schemas).map(schemaName => {\n\t\t\t\treturn `let ${schemaName} = ${config.name}::${schemaName}_schema::create(ctx);`;\n\t\t\t}).join('\\n')}\n // Logic that needs to be automated once the contract is deployed\n\t\t\t\t${`\\n`}\n\t\t\t\t${`\\n`}\n\t\t\t\t\n // Authorize schemas and public share objects\n ${Object.keys(config.schemas).map(schemaName => {\n\t\t\t\t return `\n\t\t\t\t schema_hub.authorize_schema<${capitalizeAndRemoveUnderscores(schemaName)}>();\n\t\t\t\t public_share_object(${schemaName});\n\t\t\t\t `;\n\t\t\t}).join('\\n')}\n }\n\n #[test_only]\n public fun deploy_hook_for_testing(): (Scenario, SchemaHub, Dapps) {\n let mut scenario = test_scenario::begin(@0xA);\n {\n let ctx = test_scenario::ctx(&mut scenario);\n dapps_schema::init_dapps_for_testing(ctx);\n schema_hub::init_schema_hub_for_testing(ctx);\n test_scenario::next_tx(&mut scenario,@0xA);\n };\n let mut dapps = test_scenario::take_shared<Dapps>(&scenario);\n let mut schema_hub = test_scenario::take_shared<SchemaHub>(&scenario);\n let ctx = test_scenario::ctx(&mut scenario);\n let clock = clock::create_for_testing(ctx);\n let upgrade_cap = package::test_publish(@0x42.to_id(), ctx);\n run(&mut schema_hub, &mut dapps, &upgrade_cap, &clock, ctx);\n\n clock::destroy_for_testing(clock);\n upgrade_cap.make_immutable();\n test_scenario::next_tx(&mut scenario,@0xA);\n (scenario, schema_hub, dapps)\n }\n}\n`;\n\t\tawait formatAndWriteMove(\n\t\t\tcode,\n\t\t\t`${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n\tconsole.log('ā
Deploy Hook Generation Complete\\n');\n}\n\nexport async function generateMigrate(config: DubheConfig, srcPrefix: string) {\n\tif (\n\t\t!existsSync(\n\t\t\t`${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`\n\t\t)\n\t) {\n\t\tlet code = `module ${config.name}::migrate {\n const ON_CHAIN_VERSION: u32 = 0;\n\n public fun on_chain_version(): u32 {\n ON_CHAIN_VERSION\n }\n}\n`;\n\t\tawait formatAndWriteMove(\n\t\t\tcode,\n\t\t\t`${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n}\n","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\n\nexport async function generateDappKey(\n\tconfig: DubheConfig,\n\tsrcPrefix: string\n) {\n\tconsole.log('\\nš Starting DappKey Generation...');\n\tconsole.log(\n\t\t` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`\n\t);\n\n\tlet code = `module ${config.name}::dapp_key {\n\\t/// Authorization token for the app.\n\\tpublic struct DappKey has drop {}\n\n\\tpublic(package) fun new(): DappKey {\n\\t\\tDappKey { }\n\\t}\n}\n`;\n\tawait formatAndWriteMove(\n\t\tcode,\n\t\t`${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`,\n\t\t'formatAndWriteMove'\n\t);\n\tconsole.log('ā
DappKey Generation Complete\\n');\n}\n","import { BaseType, SchemaType } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport {\n\tgetStructAttrsWithType,\n\tgetStructAttrs,\n\tgetStructTypes,\n\tgetStructAttrsQuery,\n} from './common';\n\nfunction capitalizeAndRemoveUnderscores(input: string): string {\n\treturn input\n\t\t.split('_')\n\t\t.map((word, index) => {\n\t\t\treturn index === 0\n\t\t\t\t? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()\n\t\t\t\t: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();\n\t\t})\n\t\t.join('');\n}\n\nfunction convertToSnakeCase(input: string): string {\n\treturn input\n\t\t.replace(/([A-Z])/g, '_$1')\n\t\t.toLowerCase()\n\t\t.replace(/^_/, '');\n}\n\nexport async function generateSchemaEvent(\n\tprojectName: string,\n\tschemas: Record<string, SchemaType>,\n\tpath: string\n) {\n\tconsole.log('\\nš¦ Starting Schema Event Generation...');\n\tfor (const schemaName in schemas) {\n\t\tconst schema = schemas[schemaName];\n\t\tif (schema.events) {\n\t\t\tconsole.log(` āā Processing schema: ${schemaName}`);\n\t\t\tfor (const item of schema.events) {\n\t\t\t\tconsole.log(\n\t\t\t\t\t` āā Generating ${item.name} ${\n\t\t\t\t\t\tArray.isArray(item.fields) ? '(enum)' : '(struct)'\n\t\t\t\t\t}`\n\t\t\t\t);\n\n\t\t\t\tlet\tcode = `module ${projectName}::${schemaName}_${convertToSnakeCase(item.name)}_event {\n\t\t\t\t\t\tuse sui::event;\n\t\t\t\t\t\tuse std::ascii::String;\n public struct ${item.name}Event has copy, drop {\n ${getStructAttrsWithType(item.fields as Record<string, string>)}\n }\n \n public fun new(${getStructAttrsWithType(item.fields as Record<string, string>)}): ${item.name}Event {\n ${item.name}Event {\n ${getStructAttrs(item.fields as Record<string, string>)}\n }\n }\n \n public fun emit(${getStructAttrsWithType(item.fields as Record<string, string>)}) {\n event::emit(${item.name}Event {\n ${getStructAttrs(item.fields as Record<string, string>)}\n });\n }`;\n\t\t\t\tawait formatAndWriteMove(\n\t\t\t\t\tcode,\n\t\t\t\t\t`${path}/contracts/${projectName}/sources/codegen/events/${schemaName}_${convertToSnakeCase(\n\t\t\t\t\t\titem.name\n\t\t\t\t\t)}_event.move`,\n\t\t\t\t\t'formatAndWriteMove'\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\tconsole.log('ā
Schema Event Generation Complete\\n');\n}","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport { existsSync } from 'fs';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\n\nexport async function generateSystem(config: DubheConfig, srcPrefix: string) {\n\tconsole.log('\\nāļø Starting System Generation...');\n\t\tconsole.log(` āā Generating systems`);\n\t\tconsole.log(\n\t\t\t` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/systems`\n\t\t);\n\n\t\tif (\n\t\t\t!existsSync(\n\t\t\t\t`${srcPrefix}/contracts/${config.name}/sources/systems`\n\t\t\t)\n\t\t) {\n\t\t\tawait fs.mkdir(`${srcPrefix}/contracts/${config.name}/sources/systems`, { recursive: true })\n\t\t}\n\tconsole.log('ā
System Generation Complete\\n');\n}\n","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\n\nexport async function generateSchemaHub(\n\tconfig: DubheConfig,\n\tsrcPrefix: string\n) {\n\tconsole.log('\\nš Starting DappKey Generation...');\n\tconsole.log(\n\t\t` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/codegen/schema_hub.move`\n\t);\n\n\tlet code = `module ${config.name}::schema_hub {\n use sui::transfer::public_share_object;\n use sui::dynamic_field as df;\n\n public struct SchemaHub has key, store {\n id: UID,\n admin: address,\n }\n \n public struct SchemaTypeWapper<phantom Schema: key + store> has copy, store, drop {}\n\n /// Authorize an schema to access protected features of the SchemaHub.\n public(package) fun authorize_schema<Schema: key + store>(self: &mut SchemaHub) {\n df::add(&mut self.id, SchemaTypeWapper<Schema> {}, true);\n }\n\n /// Deauthorize an schema by removing its authorization key.\n public(package) fun deauthorize_schema<Schema: key + store>(self: &mut SchemaHub) {\n df::remove<SchemaTypeWapper<Schema>, bool>(&mut self.id, SchemaTypeWapper<Schema> {});\n }\n\n /// Check if an schema is authorized to access protected features of\n /// the SchemaHub.\n public fun is_schema_authorized<Schema: key + store>(self: &SchemaHub): bool {\n df::exists_(&self.id, SchemaTypeWapper<Schema> {})\n }\n\n /// Assert that an schema is authorized to access protected features of\n /// the SchemaHub. Aborts with \\`EAppNotAuthorized\\` if not.\n public fun ensure_schema_authorized<Schema: key + store>(self: &SchemaHub) {\n assert!(self.is_schema_authorized<Schema>(), 0);\n }\n\n fun init(ctx: &mut TxContext) {\n public_share_object(SchemaHub {\n id: object::new(ctx),\n admin: ctx.sender(),\n });\n }\n\n #[test_only]\n public fun init_schema_hub_for_testing(ctx: &mut TxContext) {\n init(ctx);\n }\n}\n`;\n\tawait formatAndWriteMove(\n\t\tcode,\n\t\t`${srcPrefix}/contracts/${config.name}/sources/codegen/schema_hub.move`,\n\t\t'formatAndWriteMove'\n\t);\n\tconsole.log('ā
DappKey Generation Complete\\n');\n}\n","import { findUp } from \"find-up\";\nimport path from \"path\";\nimport esbuild from \"esbuild\";\nimport { NotInsideProjectError } from \"./errors\";\nimport { rmSync } from \"fs\";\nimport { pathToFileURL } from \"url\";\nimport os from \"os\";\n\n// In order of preference files are checked\nconst configFiles = [\n \"dubhe.config.js\",\n \"dubhe.config.mjs\",\n \"dubhe.config.ts\",\n \"dubhe.config.mts\",\n];\nconst TEMP_CONFIG = \"dubhe.config.example.mjs\";\n\nexport async function loadConfig(configPath?: string): Promise<unknown> {\n configPath = await resolveConfigPath(configPath);\n try {\n await esbuild.build({\n entryPoints: [configPath],\n format: \"esm\",\n outfile: TEMP_CONFIG,\n // https://esbuild.github.io/getting-started/#bundling-for-node\n platform: \"node\",\n // bundle local imports (otherwise it may error, js can't import ts)\n bundle: true,\n // avoid bundling external imports (it's unnecessary and esbuild can't handle all node features)\n packages: \"external\",\n });\n configPath = await resolveConfigPath(TEMP_CONFIG, true);\n // Node.js caches dynamic imports, so without appending a cache breaking\n // param like `?update={Date.now()}` this import always returns the same config\n // if called multiple times in a single process, like the `dev-contracts` cli\n return (await import(configPath + `?update=${Date.now()}`)).dubheConfig;\n } finally {\n rmSync(TEMP_CONFIG, { force: true });\n }\n}\n\nexport async function resolveConfigPath(\n configPath: string | undefined,\n toFileURL?: boolean\n) {\n if (configPath === undefined) {\n configPath = await getUserConfigPath();\n } else {\n if (!path.isAbsolute(configPath)) {\n configPath = path.join(process.cwd(), configPath);\n configPath = path.normalize(configPath);\n }\n }\n\n // Add `file:///` for Windows support\n // (see https://github.com/nodejs/node/issues/31710)\n return toFileURL && os.platform() === \"win32\"\n ? pathToFileURL(configPath).href\n : configPath;\n}\n\nasync function getUserConfigPath() {\n const tsConfigPath = await findUp(configFiles);\n if (tsConfigPath === undefined) {\n throw new NotInsideProjectError();\n }\n return tsConfigPath;\n}\n","\nexport class NotInsideProjectError extends Error {\nname = \"NotInsideProjectError\";\nmessage = \"You are not inside a Dubhe project\";\n}"],"mappings":"AAAA,OAAOA,MAAc,WACrB,OAAOC,MAAwB,0BAE/B,eAAsBC,EACrBC,EACAC,EACkB,CAClB,IAAIC,EACAD,IACHC,EAAS,MAAML,EAAS,cAAcI,CAAkB,GAEzD,GAAI,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,OAAc,UACvB,OAAOC,MAAU,OACjB,OAAOC,OAAa,UCDb,IAAMC,EAAN,cAAoC,KAAM,CACjD,KAAO,wBACP,QAAU,oCACV,EDAA,OAAS,UAAAC,OAAc,KACvB,OAAS,iBAAAC,OAAqB,MAC9B,OAAOC,OAAQ,KAGf,IAAMC,GAAc,CAClB,kBACA,mBACA,kBACA,kBACF,EACMC,EAAc,2BAEpB,eAAsBC,GAAWC,EAAuC,CACtEA,EAAa,MAAMC,EAAkBD,CAAU,EAC/C,GAAI,CACF,aAAME,GAAQ,MAAM,CAClB,YAAa,CAACF,CAAU,EACxB,OAAQ,MACR,QAASF,EAET,SAAU,OAEV,OAAQ,GAER,SAAU,UACZ,CAAC,EACDE,EAAa,MAAMC,EAAkBH,EAAa,EAAI,GAI9C,MAAM,OAAOE,EAAa,WAAW,KAAK,IAAI,MAAM,WAC9D,QAAE,CACAN,GAAOI,EAAa,CAAE,MAAO,EAAK,CAAC,CACrC,CACF,CAEA,eAAsBG,EACpBD,EACAG,EACA,CACA,OAAIH,IAAe,OACjBA,EAAa,MAAMI,GAAkB,EAEhCC,EAAK,WAAWL,CAAU,IAC7BA,EAAaK,EAAK,KAAK,QAAQ,IAAI,EAAGL,CAAU,EAChDA,EAAaK,EAAK,UAAUL,CAAU,GAMnCG,GAAaP,GAAG,SAAS,IAAM,QAClCD,GAAcK,CAAU,EAAE,KAC1BA,CACN,CAEA,eAAeI,IAAoB,CACjC,IAAME,EAAe,MAAMC,GAAOV,EAAW,EAC7C,GAAIS,IAAiB,OACnB,MAAM,IAAIE,EAEZ,OAAOF,CACT","names":["prettier","prettierPluginMove","formatMove","content","prettierConfigPath","config","error","message","formatTypescript","fs","path","createDebug","debug","error","debug","error","formatAndWriteMove","output","fullOutputPath","logPrefix","formattedOutput","formatMove","schemaPrefix","deployHookPrefix","code","fs","path","debug","formatAndWriteTypescript","formatTypescript","posixPath","path","existsSync","fs","deleteFolderRecursive","path","file","curPath","getStructAttrs","values","key","_","getStructTypes","values","_","type","getStructAttrsWithType","key","getStructAttrsQuery","generateToml","config","srcPrefix","frameworkId","code","formatAndWriteMove","capitalizeAndRemoveUnderscores","input","word","index","renderSetAttrsFunc","schemaName","fields","key","type","renderSetFunc","getStructAttrsWithType","fieldName","renderGetAllFunc","getStructTypes","getStructAttrsQuery","renderGetAttrsFunc","convertToSnakeCase","generateSchemaData","projectName","schemas","path","schema","item","code","enumNames","field","name","getStructAttrs","formatAndWriteMove","generateImport","generateSchemaStructure","migration_enabled","schemaMoudle","value","storage_type","all_types","para_key","para_value","borrow_key","extra_code","existsSync","generateDeployHook","config","srcPrefix","existsSync","code","schemaName","capitalizeAndRemoveUnderscores","formatAndWriteMove","generateMigrate","generateDappKey","config","srcPrefix","code","formatAndWriteMove","convertToSnakeCase","input","generateSchemaEvent","projectName","schemas","path","schemaName","schema","item","code","getStructAttrsWithType","getStructAttrs","formatAndWriteMove","existsSync","fs","generateSystem","config","srcPrefix","generateSchemaHub","config","srcPrefix","code","formatAndWriteMove","matchFrameworkId","network","schemaGen","config","srcPrefix","frameworkId","path","existsSync","deleteFolderRecursive","generateToml","generateDeployHook","generateSchemaData","generateSchemaStructure","generateSchemaEvent","generateDappKey","generateSchemaHub","generateSystem","generateMigrate","findUp","path","esbuild","NotInsideProjectError","rmSync","pathToFileURL","os","configFiles","TEMP_CONFIG","loadConfig","configPath","resolveConfigPath","esbuild","toFileURL","getUserConfigPath","path","tsConfigPath","findUp","NotInsideProjectError"]}
|
|
1
|
+
{"version":3,"sources":["../src/codegen/utils/format.ts","../src/codegen/utils/formatAndWrite.ts","../src/debug.ts","../src/codegen/debug.ts","../src/codegen/utils/posixPath.ts","../src/codegen/utils/renderMove/schemaGen.ts","../src/codegen/utils/renderMove/common.ts","../src/codegen/utils/renderMove/generateToml.ts","../src/codegen/utils/renderMove/generateSchema.ts","../src/codegen/utils/renderMove/generateScript.ts","../src/codegen/utils/renderMove/generateDappKey.ts","../src/codegen/utils/renderMove/generateEvent.ts","../src/codegen/utils/renderMove/generateSystem.ts","../src/codegen/utils/renderMove/generateSchemaHub.ts","../src/codegen/utils/config.ts","../src/codegen/utils/errors.ts"],"sourcesContent":["import prettier from 'prettier';\nimport prettierPluginMove from 'prettier-plugin-move-js';\n\nexport async function formatMove(\n\tcontent: string,\n\tprettierConfigPath?: string\n): Promise<string> {\n\tlet config;\n\tif (prettierConfigPath) {\n\t\tconfig = await prettier.resolveConfig(prettierConfigPath);\n\t}\n\ttry {\n\t\treturn prettier.format(content, {\n\t\t\tplugins: [prettierPluginMove],\n\t\t\tparser: 'move-parse',\n\t\t\tprintWidth: 120,\n\t\t\tsemi: true,\n\t\t\ttabWidth: 2,\n\t\t\tuseTabs: false,\n\t\t\tbracketSpacing: true,\n\t\t\t...config,\n\t\t});\n\t} catch (error) {\n\t\tlet message;\n\t\tif (error instanceof Error) {\n\t\t\tmessage = error.message;\n\t\t} else {\n\t\t\tmessage = error;\n\t\t}\n\t\tconsole.log(`Error during output formatting: ${message}`);\n\t\treturn content;\n\t}\n}\n\nexport async function formatTypescript(content: string): Promise<string> {\n\treturn prettier.format(content, {\n\t\tparser: 'typescript',\n\t});\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { formatMove, formatTypescript } from \"./format\";\nimport { debug } from \"../debug\";\n\nexport async function formatAndWriteMove(\n output: string,\n fullOutputPath: string,\n logPrefix?: string\n): Promise<void> {\n const formattedOutput = await formatMove(output);\n let schemaPrefix =\n` // Copyright (c) Obelisk Labs, Inc.\n // SPDX-License-Identifier: MIT\n #[allow(unused_use)]\n \n /* Autogenerated file. Do not edit manually. */\n \n `\n\n let deployHookPrefix = `#[allow(lint(share_owned))]\n \n `\n\n let code = schemaPrefix + formattedOutput\n\n if (fullOutputPath.includes(\".toml\") || fullOutputPath.includes(\"system\") || fullOutputPath.includes(\"migrate\")) {\n code = formattedOutput\n } else if (fullOutputPath.includes(\"deploy_hook\")) {\n code = deployHookPrefix + formattedOutput\n }\n\n await fs.mkdir(path.dirname(fullOutputPath), { recursive: true });\n await fs.writeFile(fullOutputPath, code);\n debug(`${logPrefix}: ${fullOutputPath}`);\n}\n\n/**\n * Formats typescript code using prettier and write it to a file\n * @param output typescript code\n * @param fullOutputPath full path to the output file\n * @param logPrefix prefix for debug logs\n */\nexport async function formatAndWriteTypescript(\n output: string,\n fullOutputPath: string,\n logPrefix: string,\n): Promise<void> {\n const formattedOutput = await formatTypescript(output);\n\n await fs.mkdir(path.dirname(fullOutputPath), { recursive: true });\n\n await fs.writeFile(fullOutputPath, formattedOutput);\n debug(`${logPrefix}: ${fullOutputPath}`);\n}\n","import createDebug from \"debug\";\n\nexport const debug = createDebug(\"dubhe:common\");\nexport const error = createDebug(\"dubhe:common\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n","import { debug as parentDebug } from \"../debug\";\n\nexport const debug = parentDebug.extend(\"codegen\");\nexport const error = parentDebug.extend(\"codegen\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n","/**\n * Explicitly normalize a given path to a posix path (using `/` as separator).\n * This should be used for generating Solidity files that will be consumed by solc,\n * because solc expects `/` as path separator, but path.join produces `\\` if the user is on windows.\n */\nexport function posixPath(path: string): string {\n return path.replace(/\\\\/g, \"/\");\n}\n","import { SchemaType, DubheConfig } from '../../types';\nimport { rmdirSync, existsSync } from 'fs';\nimport { deleteFolderRecursive } from './common';\nimport { generateToml } from './generateToml';\nimport { generateSchemaData, generateSchemaStructure } from './generateSchema';\nimport { generateDeployHook, generateMigrate } from './generateScript';\nimport { generateDappKey } from './generateDappKey';\nimport { generateSchemaEvent } from './generateEvent';\nimport { generateSystem } from './generateSystem';\nimport { generateSchemaHub } from './generateSchemaHub';\n\nfunction matchFrameworkId(\n network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',\n): string {\n switch (network) {\n case 'testnet':\n return '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';\n case 'localnet':\n return '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';\n default:\n return '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';\n }\n}\n\nexport async function schemaGen(\n config: DubheConfig,\n srcPrefix?: string,\n network?: 'mainnet' | 'testnet' | 'devnet' | 'localnet',\n frameworkId?: string,\n) {\n console.log('\\nš Starting Schema Generation Process...');\n console.log('š Project Configuration:');\n console.log(` āā Name: ${config.name}`);\n console.log(\n ` āā Description: ${config.description || 'No description provided'}`,\n );\n console.log(` āā Network: ${network || 'testnet'}`);\n console.log(\n ` āā Framework ID: ${\n frameworkId || matchFrameworkId(network ?? 'testnet')\n }\\n`,\n );\n\n const path = srcPrefix ?? process.cwd();\n\n frameworkId = frameworkId || matchFrameworkId(network ?? 'testnet');\n\n if (existsSync(`${path}/contracts/${config.name}`)) {\n deleteFolderRecursive(\n `${path}/contracts/${config.name}/sources/codegen`,\n );\n }\n\n if (!existsSync(`${path}/contracts/${config.name}/Move.toml`)) {\n await generateToml(config, path, frameworkId);\n }\n\n if (\n !existsSync(\n `${path}/contracts/${config.name}/sources/script/deploy_hook.move`,\n )\n ) {\n await generateDeployHook(config, path);\n }\n\n await generateSchemaData(config.name, config.schemas, path);\n await generateSchemaStructure(config.name, config.schemas, path);\n await generateSchemaEvent(config.name, config.schemas, path);\n await generateDappKey(config, path);\n await generateSchemaHub(config, path);\n await generateSystem(config, path);\n await generateMigrate(config, path);\n\n console.log('ā
Schema Generation Process Complete!\\n');\n}\n","import { MoveType } from '../../types';\nimport fs from 'fs';\n\nexport function deleteFolderRecursive(path: string) {\n\tif (fs.existsSync(path)) {\n\t\tfs.readdirSync(path).forEach(file => {\n\t\t\tconst curPath = `${path}/${file}`;\n\t\t\tif (fs.lstatSync(curPath).isDirectory()) {\n\t\t\t\tdeleteFolderRecursive(curPath);\n\t\t\t} else {\n\t\t\t\tfs.unlinkSync(curPath);\n\t\t\t}\n\t\t});\n\t\tfs.rmdirSync(path);\n\t}\n}\n\nexport function capitalizeFirstLetter(input: string): string {\n\treturn input.charAt(0).toUpperCase() + input.slice(1);\n}\n\n/**\n *\n * @param values\n * @param prefixArgs\n * @return [ name, age, birth_time ]\n */\nexport function getStructAttrs(\n\tvalues: Record<string, string> | string\n): string {\n\treturn Object.entries(values)\n\t\t.map(([key, _]) => `${key}`)\n\t\t.join(',');\n}\n\nfunction isAddress(str: string): boolean {\n\tconst regex = /^0x[a-fA-F0-9]+$/;\n\treturn regex.test(str);\n}\n\n/**\n *\n * @param values\n * @return ( bool , u64 , u64)\n */\n// export function getStructTypes(values: SchemaType): string {\nexport function getStructTypes(\n\tvalues: Record<string, string>\n): string {\n\treturn `(${Object.entries(values).map(([_, type]) => `${type}`)})`;\n}\n\n/**\n *\n * @param values\n * @return Attributes and types of the struct. [ name: string, age: u64 ]\n */\nexport function getStructAttrsWithType(\n\tvalues: Record<string, string>\n): string[] {\n\treturn Object.entries(values).map(([key, type]) => `${key}: ${type}`);\n}\n\n/**\n * @param values\n * @return [ data.name, data.age ]\n */\nexport function getStructAttrsQuery(\n\tvalues: Record<string, string>,\n): string[] {\n\treturn Object.entries(values).map(([key, _]) => `self.${key}`);\n}\n","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\n\nexport async function generateToml(\n\tconfig: DubheConfig,\n\tsrcPrefix: string,\n\tframeworkId: string\n) {\n\tconsole.log('\\nš Starting Move.toml Generation...');\n\tconsole.log(\n\t\t` āā Output path: ${srcPrefix}/contracts/${config.name}/Move.toml`\n\t);\n\n\tlet code = `[package]\nname = \"${config.name}\"\nversion = \"0.0.1\"\nedition = \"2024.beta\"\n\n[dependencies]\nSui = { git = \"https://github.com/MystenLabs/sui.git\", subdir = \"crates/sui-framework/packages/sui-framework\", rev = \"mainnet-v1.36.2\" }\nDubhe = { git = \"https://github.com/0xobelisk/dubhe-framework.git\", rev = \"release-dubhe-v1.0.0-rc1\" }\n\n[addresses]\nsui = \"0x2\"\ndubhe = \"${frameworkId}\"\n${config.name} = \"0x0\"\n`;\n\tawait formatAndWriteMove(\n\t\tcode,\n\t\t`${srcPrefix}/contracts/${config.name}/Move.toml`,\n\t\t'formatAndWriteMove'\n\t);\n\tconsole.log('ā
Move.toml Generation Complete\\n');\n}\n","import { BaseType, SchemaType } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport {\n\tgetStructAttrsWithType,\n\tgetStructAttrs,\n\tgetStructTypes,\n\tgetStructAttrsQuery,\n} from './common';\n\nexport function capitalizeAndRemoveUnderscores(input: string): string {\n\treturn input\n\t\t.split('_')\n\t\t.map((word, index) => {\n\t\t\treturn index === 0\n\t\t\t\t? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()\n\t\t\t\t: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();\n\t\t})\n\t\t.join('');\n}\n\nexport function renderSetAttrsFunc(\n\tschemaName: string,\n\tfields: BaseType | Record<string, BaseType>,\n): string {\n\treturn Object.entries(fields)\n\t\t.map(\n\t\t\t([key, type]) =>\n\t\t\t\t`public(package) fun set_${key}(self: &mut ${schemaName}, ${key}: ${type}) {\n self.${key} = ${key};\n }`,\n\t\t)\n\t\t.join('\\n');\n}\n\nexport function renderSetFunc(\n\tschemaName: string,\n\tfields: Record<string, string>,\n): string {\n\treturn `public(package) fun set(self: &mut ${schemaName}, ${getStructAttrsWithType(\n\t\tfields,\n\t)}) {\n ${Object.entries(fields)\n\t\t.map(([fieldName]) => `self.${fieldName} = ${fieldName};`)\n\t\t.join('\\n')}\n }`;\n}\n\nexport function renderGetAllFunc(\n\tschemaName: string,\n\tfields: Record<string, string>,\n): string {\n\treturn `public fun get(self: &${schemaName}): ${getStructTypes(fields)} {\n (${getStructAttrsQuery(fields)})\n }`;\n}\n\nexport function renderGetAttrsFunc(\n\tschemaName: string,\n\tfields: BaseType | Record<string, BaseType>,\n): string {\n\treturn Object.entries(fields)\n\t\t.map(\n\t\t\t([\n\t\t\t\t key,\n\t\t\t\t type,\n\t\t\t ]) => `public fun get_${key}(self: &${schemaName}): ${type} {\n self.${key}\n }`,\n\t\t)\n\t\t.join('\\n');\n}\n\nfunction convertToSnakeCase(input: string): string {\n\treturn input\n\t\t.replace(/([A-Z])/g, '_$1')\n\t\t.toLowerCase()\n\t\t.replace(/^_/, '');\n}\n\nexport async function generateSchemaData(\n\tprojectName: string,\n\tschemas: Record<string, SchemaType>,\n\tpath: string,\n) {\n\tconsole.log('\\nš¦ Starting Schema Data Generation...');\n\tfor (const schemaName in schemas) {\n\t\tconst schema = schemas[schemaName];\n\t\tif (schema.data) {\n\t\t\tconsole.log(` āā Processing schema: ${schemaName}`);\n\t\t\tfor (const item of schema.data) {\n\t\t\t\tconsole.log(\n\t\t\t\t\t` āā Generating ${item.name} ${\n\t\t\t\t\t\tArray.isArray(item.fields) ? '(enum)' : '(struct)'\n\t\t\t\t\t}`,\n\t\t\t\t);\n\t\t\t\tlet code = '';\n\n\t\t\t\tconst enumNames = schema.data\n\t\t\t\t\t.filter(item => Array.isArray(item.fields))\n\t\t\t\t\t.map(item => item.name);\n\n\t\t\t\tif (Array.isArray(item.fields)) {\n\t\t\t\t\tcode = `module ${projectName}::${schemaName}_${convertToSnakeCase(\n\t\t\t\t\t\titem.name,\n\t\t\t\t\t)} {\n public enum ${item.name} has copy, drop , store {\n ${item.fields}\n }\n \n ${item.fields\n\t\t\t\t\t\t.map((field: string) => {\n\t\t\t\t\t\t\treturn `public fun new_${convertToSnakeCase(\n\t\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\t)}(): ${item.name} {\n ${item.name}::${field}\n }`;\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join('')}`;\n\t\t\t\t} else {\n\t\t\t\t\tcode = `module ${projectName}::${schemaName}_${convertToSnakeCase(\n\t\t\t\t\t\titem.name,\n\t\t\t\t\t)} {\n use std::ascii::String;\n ${enumNames\n\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\tname =>\n\t\t\t\t\t\t\t\t`use ${projectName}::${schemaName}_${convertToSnakeCase(\n\t\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\t)}::${name};`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join('\\n')}\n\n public struct ${item.name} has copy, drop , store {\n ${getStructAttrsWithType(item.fields)}\n }\n \n public fun new(${getStructAttrsWithType(\n\t\t\t\t\t\titem.fields,\n\t\t\t\t\t)}): ${item.name} {\n ${item.name} {\n ${getStructAttrs(item.fields)}\n }\n }\n \n ${renderGetAllFunc(item.name, item.fields)}\n ${renderGetAttrsFunc(item.name, item.fields)}\n ${renderSetAttrsFunc(item.name, item.fields)}\n ${renderSetFunc(item.name, item.fields)}\n }`;\n\t\t\t\t}\n\n\t\t\t\tawait formatAndWriteMove(\n\t\t\t\t\tcode,\n\t\t\t\t\t`${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}_${convertToSnakeCase(\n\t\t\t\t\t\titem.name,\n\t\t\t\t\t)}.move`,\n\t\t\t\t\t'formatAndWriteMove',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\tconsole.log('ā
Schema Data Generation Complete\\n');\n}\n\nfunction generateImport(\n\tprojectName: string,\n\tschemaName: string,\n\tschema: SchemaType,\n) {\n\tif (schema.data) {\n\t\treturn schema.data\n\t\t\t.map(item => {\n\t\t\t\treturn `use ${projectName}::${schemaName}_${convertToSnakeCase(\n\t\t\t\t\titem.name,\n\t\t\t\t)}::${item.name};`;\n\t\t\t})\n\t\t\t.join('\\n');\n\t} else {\n\t\treturn '';\n\t}\n}\n\nexport async function generateSchemaStructure(\n\tprojectName: string,\n\tschemas: Record<string, SchemaType>,\n\tpath: string,\n) {\n\tconsole.log('\\nšØ Starting Schema Structure Generation...');\n\tfor (const schemaName in schemas) {\n\t\tconsole.log(` āā Generating schema: ${schemaName}`);\n\t\tconsole.log(\n\t\t\t` āā Output path: ${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,\n\t\t);\n\t\tconsole.log(\n\t\t\t` āā Structure fields: ${\n\t\t\t\tObject.keys(schemas[schemaName].structure).length\n\t\t\t}`,\n\t\t);\n\t\tconst schema = schemas[schemaName];\n\t\tconst schemaMoudle = `module ${projectName}::${schemaName}_schema {\n use std::ascii::String;\n use std::ascii::string;\n use sui::package::UpgradeCap;\n use std::type_name;\n use dubhe::dapps_system;\n use dubhe::storage_migrate;\n use dubhe::dapps_schema::Dapps;\n use dubhe::storage_value::{Self, StorageValue};\n use dubhe::storage_map::{Self, StorageMap};\n use dubhe::storage_double_map::{Self, StorageDoubleMap};\n use ${projectName}::dapp_key::DappKey;\n use sui::dynamic_field as df;\n ${generateImport(projectName, schemaName, schema)}\n\n public struct ${capitalizeAndRemoveUnderscores(\n\t\t\tschemaName,\n\t\t)} has key, store {\n id: UID\n\t\t\t\t\t\t\t\t\t\t\t} \n \n ${Object.entries(schema.structure)\n\t\t\t.map(([key, value]) => {\n\t\t\t\treturn `public fun borrow_${key}(self: &${capitalizeAndRemoveUnderscores(\n\t\t\t\t\tschemaName,\n\t\t\t\t)}) : &${value} {\n storage_migrate::borrow_field(&self.id, b\"${key}\")\n }\n \n public(package) fun borrow_mut_${key}(self: &mut ${capitalizeAndRemoveUnderscores(\n\t\t\t\t\tschemaName,\n\t\t\t\t)}): &mut ${value} {\n storage_migrate::borrow_mut_field(&mut self.id, b\"${key}\")\n }\n `;\n\t\t\t})\n\t\t\t.join('')} \n \n \n public(package) fun create(ctx: &mut TxContext): ${capitalizeAndRemoveUnderscores(\n\t\t\tschemaName,\n\t\t)} {\n let mut id = object::new(ctx);\n ${Object.entries(schema.structure)\n\t\t\t.map(([key, value]) => {\n\t\t\t\tlet storage_type = '';\n\t\t\t\tif (value.includes('StorageValue')) {\n\t\t\t\t\tstorage_type = `storage_value::new()`;\n\t\t\t\t} else if (value.includes('StorageMap')) {\n\t\t\t\t\tstorage_type = `storage_map::new()`;\n\t\t\t\t} else if (\n\t\t\t\t\tvalue.includes('StorageDoubleMap')\n\t\t\t\t) {\n\t\t\t\t\tstorage_type = `storage_double_map::new()`;\n\t\t\t\t}\n\t\t\t\treturn `storage_migrate::add_field<${value}>(&mut id, b\"${key}\", ${storage_type});`;\n\t\t\t})\n\t\t\t.join('')}\n \n ${capitalizeAndRemoveUnderscores(schemaName)} { id }\n }\n \n public fun migrate(_${schemaName}: &mut ${capitalizeAndRemoveUnderscores(schemaName)}, _cap: &UpgradeCap) { }\n\n \n \n // ======================================== View Functions ========================================\n ${Object.entries(schema.structure)\n\t\t\t.map(([key, value]) => {\n\t\t\t\t// @ts-ignore\n\t\t\t\tlet all_types = value.match(/<(.+)>/)[1].split(',').map(type => type.trim());\n\t\t\t\tlet para_key: string[] = [];\n\t\t\t\tlet para_value = '';\n\t\t\t\tlet borrow_key = '';\n\t\t\t\tlet extra_code = '';\n\t\t\t\tif (value.includes('StorageValue')) {\n\t\t\t\t\tpara_key = [];\n\t\t\t\t\tpara_value = `${all_types[0]}`;\n\t\t\t\t\tborrow_key = 'try_get()';\n\t\t\t\t} else if (value.includes('StorageMap')) {\n\t\t\t\t\tpara_key = [`key: ${all_types[0]}`];\n\t\t\t\t\tpara_value = `${all_types[1]}`;\n\t\t\t\t\tborrow_key = 'try_get(key)';\n\t\t\t\t\textra_code = `public fun get_${key}_keys(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : vector<${all_types[0]}> {\n\t\t\t\t\t\t\t\t\tself.borrow_${key}().keys()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tpublic fun get_${key}_values(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : vector<${all_types[1]}> {\n\t\t\t\t\t\t\t\t\tself.borrow_${key}().values()\n\t\t\t\t\t\t\t\t}`;\n\t\t\t\t} else if (value.includes('StorageDoubleMap')) {\n\t\t\t\t\tpara_key = [`key1: ${all_types[0]}`, `key2: ${all_types[1]}`];\n\t\t\t\t\tpara_value = `${all_types[2]}`;\n\t\t\t\t\tborrow_key = 'try_get(key1, key2)';\n\t\t\t\t\textra_code = `public fun get_${key}_keys(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : (vector<${all_types[0]}>, vector<${all_types[1]}>) {\n\t\t\t\t\t\t\t\t\tself.borrow_${key}().keys()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tpublic fun get_${key}_values(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : vector<${all_types[2]}> {\n\t\t\t\t\t\t\t\t\tself.borrow_${key}().values()\n\t\t\t\t\t\t\t\t}`;\n\t\t\t\t}\n\t\t\t\treturn `public fun get_${key}(self: &${capitalizeAndRemoveUnderscores(schemaName)}, ${para_key}) : Option<${para_value}> {\n\t\t\t\t\t\t\t\t\tself.borrow_${key}().${borrow_key}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t` + extra_code;\n\t\t\t})\n\t\t\t.join('')} \n // =========================================================================================================\n \n \n }`;\n\t\tawait formatAndWriteMove(\n\t\t\tschemaMoudle,\n\t\t\t`${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,\n\t\t\t'formatAndWriteMove',\n\t\t);\n\t}\n\tconsole.log('ā
Schema Structure Generation Complete\\n');\n}\n","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport { existsSync } from 'fs';\nimport { capitalizeAndRemoveUnderscores } from './generateSchema';\n\nexport async function generateDeployHook(\n\tconfig: DubheConfig,\n\tsrcPrefix: string\n) {\n\tconsole.log('\\nš Starting Deploy Hook Generation...');\n\tconsole.log(\n\t\t` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`\n\t);\n\n\tif (\n\t\t!existsSync(\n\t\t\t`${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`\n\t\t)\n\t) {\n\t\tlet code = `module ${config.name}::deploy_hook {\n use dubhe::dapps_schema::Dapps;\n use dubhe::dapps_system;\n use ${config.name}::schema_hub::SchemaHub;\n use std::ascii::string;\n use sui::clock::Clock;\n use sui::package::UpgradeCap;\n use sui::transfer::public_share_object;\n ${Object.keys(config.schemas).map(schemaName => {\n\t\t\treturn `use ${config.name}::${schemaName}_schema::${capitalizeAndRemoveUnderscores(schemaName)};`}).join('\\n')\n\t\t}\n #[test_only]\n use sui::clock;\n #[test_only]\n use sui::test_scenario;\n #[test_only]\n use sui::package;\n #[test_only]\n use ${config.name}::schema_hub; \n #[test_only]\n use dubhe::dapps_schema;\n #[test_only]\n use sui::test_scenario::Scenario;\n\n public entry fun run(schema_hub: &mut SchemaHub, dapps: &mut Dapps, cap: &UpgradeCap, clock: &Clock, ctx: &mut TxContext) {\n // Register the dapp to dubhe.\n dapps_system::register(dapps,cap,string(b\"${config.name}\"),string(b\"${config.description}\"),clock,ctx);\n // Create schemas\n ${Object.keys(config.schemas).map(schemaName => {\n\t\t\t\treturn `let ${schemaName} = ${config.name}::${schemaName}_schema::create(ctx);`;\n\t\t\t}).join('\\n')}\n // Logic that needs to be automated once the contract is deployed\n\t\t\t\t${`\\n`}\n\t\t\t\t${`\\n`}\n\t\t\t\t\n // Authorize schemas and public share objects\n ${Object.keys(config.schemas).map(schemaName => {\n\t\t\t\t return `\n\t\t\t\t schema_hub.authorize_schema<${capitalizeAndRemoveUnderscores(schemaName)}>();\n\t\t\t\t public_share_object(${schemaName});\n\t\t\t\t `;\n\t\t\t}).join('\\n')}\n }\n\n #[test_only]\n public fun deploy_hook_for_testing(): (Scenario, SchemaHub, Dapps) {\n let mut scenario = test_scenario::begin(@0xA);\n {\n let ctx = test_scenario::ctx(&mut scenario);\n dapps_schema::init_dapps_for_testing(ctx);\n schema_hub::init_schema_hub_for_testing(ctx);\n test_scenario::next_tx(&mut scenario,@0xA);\n };\n let mut dapps = test_scenario::take_shared<Dapps>(&scenario);\n let mut schema_hub = test_scenario::take_shared<SchemaHub>(&scenario);\n let ctx = test_scenario::ctx(&mut scenario);\n let clock = clock::create_for_testing(ctx);\n let upgrade_cap = package::test_publish(@0x42.to_id(), ctx);\n run(&mut schema_hub, &mut dapps, &upgrade_cap, &clock, ctx);\n\n clock::destroy_for_testing(clock);\n upgrade_cap.make_immutable();\n test_scenario::next_tx(&mut scenario,@0xA);\n (scenario, schema_hub, dapps)\n }\n}\n`;\n\t\tawait formatAndWriteMove(\n\t\t\tcode,\n\t\t\t`${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n\tconsole.log('ā
Deploy Hook Generation Complete\\n');\n}\n\nexport async function generateMigrate(config: DubheConfig, srcPrefix: string) {\n\tif (\n\t\t!existsSync(\n\t\t\t`${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`\n\t\t)\n\t) {\n\t\tlet code = `module ${config.name}::migrate {\n const ON_CHAIN_VERSION: u32 = 0;\n\n public fun on_chain_version(): u32 {\n ON_CHAIN_VERSION\n }\n}\n`;\n\t\tawait formatAndWriteMove(\n\t\t\tcode,\n\t\t\t`${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n}\n","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\n\nexport async function generateDappKey(\n\tconfig: DubheConfig,\n\tsrcPrefix: string\n) {\n\tconsole.log('\\nš Starting DappKey Generation...');\n\tconsole.log(\n\t\t` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`\n\t);\n\n\tlet code = `module ${config.name}::dapp_key {\n\\t/// Authorization token for the app.\n\\tpublic struct DappKey has drop {}\n\n\\tpublic(package) fun new(): DappKey {\n\\t\\tDappKey { }\n\\t}\n}\n`;\n\tawait formatAndWriteMove(\n\t\tcode,\n\t\t`${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`,\n\t\t'formatAndWriteMove'\n\t);\n\tconsole.log('ā
DappKey Generation Complete\\n');\n}\n","import { BaseType, SchemaType } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport {\n\tgetStructAttrsWithType,\n\tgetStructAttrs,\n\tgetStructTypes,\n\tgetStructAttrsQuery,\n} from './common';\n\nfunction capitalizeAndRemoveUnderscores(input: string): string {\n\treturn input\n\t\t.split('_')\n\t\t.map((word, index) => {\n\t\t\treturn index === 0\n\t\t\t\t? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()\n\t\t\t\t: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();\n\t\t})\n\t\t.join('');\n}\n\nfunction convertToSnakeCase(input: string): string {\n\treturn input\n\t\t.replace(/([A-Z])/g, '_$1')\n\t\t.toLowerCase()\n\t\t.replace(/^_/, '');\n}\n\nexport async function generateSchemaEvent(\n\tprojectName: string,\n\tschemas: Record<string, SchemaType>,\n\tpath: string\n) {\n\tconsole.log('\\nš¦ Starting Schema Event Generation...');\n\tfor (const schemaName in schemas) {\n\t\tconst schema = schemas[schemaName];\n\t\tif (schema.events) {\n\t\t\tconsole.log(` āā Processing schema: ${schemaName}`);\n\t\t\tfor (const item of schema.events) {\n\t\t\t\tconsole.log(\n\t\t\t\t\t` āā Generating ${item.name} ${\n\t\t\t\t\t\tArray.isArray(item.fields) ? '(enum)' : '(struct)'\n\t\t\t\t\t}`\n\t\t\t\t);\n\n\t\t\t\tlet\tcode = `module ${projectName}::${schemaName}_${convertToSnakeCase(item.name)}_event {\n\t\t\t\t\t\tuse sui::event;\n\t\t\t\t\t\tuse std::ascii::String;\n public struct ${item.name}Event has copy, drop {\n ${getStructAttrsWithType(item.fields as Record<string, string>)}\n }\n \n public fun new(${getStructAttrsWithType(item.fields as Record<string, string>)}): ${item.name}Event {\n ${item.name}Event {\n ${getStructAttrs(item.fields as Record<string, string>)}\n }\n }\n \n public fun emit(${getStructAttrsWithType(item.fields as Record<string, string>)}) {\n event::emit(${item.name}Event {\n ${getStructAttrs(item.fields as Record<string, string>)}\n });\n }`;\n\t\t\t\tawait formatAndWriteMove(\n\t\t\t\t\tcode,\n\t\t\t\t\t`${path}/contracts/${projectName}/sources/codegen/events/${schemaName}_${convertToSnakeCase(\n\t\t\t\t\t\titem.name\n\t\t\t\t\t)}_event.move`,\n\t\t\t\t\t'formatAndWriteMove'\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\tconsole.log('ā
Schema Event Generation Complete\\n');\n}","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport { existsSync } from 'fs';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\n\nexport async function generateSystem(config: DubheConfig, srcPrefix: string) {\n\tconsole.log('\\nāļø Starting System Generation...');\n\t\tconsole.log(` āā Generating systems`);\n\t\tconsole.log(\n\t\t\t` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/systems`\n\t\t);\n\n\t\tif (\n\t\t\t!existsSync(\n\t\t\t\t`${srcPrefix}/contracts/${config.name}/sources/systems`\n\t\t\t)\n\t\t) {\n\t\t\tawait fs.mkdir(`${srcPrefix}/contracts/${config.name}/sources/systems`, { recursive: true })\n\t\t}\n\tconsole.log('ā
System Generation Complete\\n');\n}\n","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\n\nexport async function generateSchemaHub(\n\tconfig: DubheConfig,\n\tsrcPrefix: string\n) {\n\tconsole.log('\\nš Starting DappKey Generation...');\n\tconsole.log(\n\t\t` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/codegen/schema_hub.move`\n\t);\n\n\tlet code = `module ${config.name}::schema_hub {\n use sui::transfer::public_share_object;\n use sui::dynamic_field as df;\n\n public struct SchemaHub has key, store {\n id: UID,\n admin: address,\n }\n \n public struct SchemaTypeWapper<phantom Schema: key + store> has copy, store, drop {}\n\n /// Authorize an schema to access protected features of the SchemaHub.\n public(package) fun authorize_schema<Schema: key + store>(self: &mut SchemaHub) {\n df::add(&mut self.id, SchemaTypeWapper<Schema> {}, true);\n }\n\n /// Deauthorize an schema by removing its authorization key.\n public(package) fun deauthorize_schema<Schema: key + store>(self: &mut SchemaHub) {\n df::remove<SchemaTypeWapper<Schema>, bool>(&mut self.id, SchemaTypeWapper<Schema> {});\n }\n\n /// Check if an schema is authorized to access protected features of\n /// the SchemaHub.\n public fun is_schema_authorized<Schema: key + store>(self: &SchemaHub): bool {\n df::exists_(&self.id, SchemaTypeWapper<Schema> {})\n }\n\n /// Assert that an schema is authorized to access protected features of\n /// the SchemaHub. Aborts with \\`EAppNotAuthorized\\` if not.\n public fun ensure_schema_authorized<Schema: key + store>(self: &SchemaHub) {\n assert!(self.is_schema_authorized<Schema>(), 0);\n }\n\n fun init(ctx: &mut TxContext) {\n public_share_object(SchemaHub {\n id: object::new(ctx),\n admin: ctx.sender(),\n });\n }\n\n #[test_only]\n public fun init_schema_hub_for_testing(ctx: &mut TxContext) {\n init(ctx);\n }\n}\n`;\n\tawait formatAndWriteMove(\n\t\tcode,\n\t\t`${srcPrefix}/contracts/${config.name}/sources/codegen/schema_hub.move`,\n\t\t'formatAndWriteMove'\n\t);\n\tconsole.log('ā
DappKey Generation Complete\\n');\n}\n","import { findUp } from \"find-up\";\nimport path from \"path\";\nimport esbuild from \"esbuild\";\nimport { NotInsideProjectError } from \"./errors\";\nimport { rmSync } from \"fs\";\nimport { pathToFileURL } from \"url\";\nimport os from \"os\";\n\n// In order of preference files are checked\nconst configFiles = [\n \"dubhe.config.js\",\n \"dubhe.config.mjs\",\n \"dubhe.config.ts\",\n \"dubhe.config.mts\",\n];\nconst TEMP_CONFIG = \"dubhe.config.example.mjs\";\n\nexport async function loadConfig(configPath?: string): Promise<unknown> {\n configPath = await resolveConfigPath(configPath);\n try {\n await esbuild.build({\n entryPoints: [configPath],\n format: \"esm\",\n outfile: TEMP_CONFIG,\n // https://esbuild.github.io/getting-started/#bundling-for-node\n platform: \"node\",\n // bundle local imports (otherwise it may error, js can't import ts)\n bundle: true,\n // avoid bundling external imports (it's unnecessary and esbuild can't handle all node features)\n packages: \"external\",\n });\n configPath = await resolveConfigPath(TEMP_CONFIG, true);\n // Node.js caches dynamic imports, so without appending a cache breaking\n // param like `?update={Date.now()}` this import always returns the same config\n // if called multiple times in a single process, like the `dev-contracts` cli\n return (await import(configPath + `?update=${Date.now()}`)).dubheConfig;\n } finally {\n rmSync(TEMP_CONFIG, { force: true });\n }\n}\n\nexport async function resolveConfigPath(\n configPath: string | undefined,\n toFileURL?: boolean\n) {\n if (configPath === undefined) {\n configPath = await getUserConfigPath();\n } else {\n if (!path.isAbsolute(configPath)) {\n configPath = path.join(process.cwd(), configPath);\n configPath = path.normalize(configPath);\n }\n }\n\n // Add `file:///` for Windows support\n // (see https://github.com/nodejs/node/issues/31710)\n return toFileURL && os.platform() === \"win32\"\n ? pathToFileURL(configPath).href\n : configPath;\n}\n\nasync function getUserConfigPath() {\n const tsConfigPath = await findUp(configFiles);\n if (tsConfigPath === undefined) {\n throw new NotInsideProjectError();\n }\n return tsConfigPath;\n}\n","\nexport class NotInsideProjectError extends Error {\nname = \"NotInsideProjectError\";\nmessage = \"You are not inside a Dubhe project\";\n}"],"mappings":"AAAA,OAAOA,MAAc,WACrB,OAAOC,MAAwB,0BAE/B,eAAsBC,EACrBC,EACAC,EACkB,CAClB,IAAIC,EACAD,IACHC,EAAS,MAAML,EAAS,cAAcI,CAAkB,GAEzD,GAAI,CACH,OAAOJ,EAAS,OAAOG,EAAS,CAC/B,QAAS,CAACF,CAAkB,EAC5B,OAAQ,aACR,WAAY,IACZ,KAAM,GACN,SAAU,EACV,QAAS,GACT,eAAgB,GAChB,GAAGI,CACJ,CAAC,CACF,OAASC,EAAP,CACD,IAAIC,EACJ,OAAID,aAAiB,MACpBC,EAAUD,EAAM,QAEhBC,EAAUD,EAEX,QAAQ,IAAI,mCAAmCC,GAAS,EACjDJ,CACR,CACD,CAEA,eAAsBK,EAAiBL,EAAkC,CACxE,OAAOH,EAAS,OAAOG,EAAS,CAC/B,OAAQ,YACT,CAAC,CACF,CCtCA,OAAOM,MAAQ,mB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Aa,EAAI,GAI9C,MAAM,OAAOE,EAAa,WAAW,KAAK,IAAI,MAAM,WAC9D,QAAE,CACAN,GAAOI,EAAa,CAAE,MAAO,EAAK,CAAC,CACrC,CACF,CAEA,eAAsBG,EACpBD,EACAG,EACA,CACA,OAAIH,IAAe,OACjBA,EAAa,MAAMI,GAAkB,EAEhCC,EAAK,WAAWL,CAAU,IAC7BA,EAAaK,EAAK,KAAK,QAAQ,IAAI,EAAGL,CAAU,EAChDA,EAAaK,EAAK,UAAUL,CAAU,GAMnCG,GAAaP,GAAG,SAAS,IAAM,QAClCD,GAAcK,CAAU,EAAE,KAC1BA,CACN,CAEA,eAAeI,IAAoB,CACjC,IAAME,EAAe,MAAMC,GAAOV,EAAW,EAC7C,GAAIS,IAAiB,OACnB,MAAM,IAAIE,EAEZ,OAAOF,CACT","names":["prettier","prettierPluginMove","formatMove","content","prettierConfigPath","config","error","message","formatTypescript","fs","path","createDebug","debug","error","debug","error","formatAndWriteMove","output","fullOutputPath","logPrefix","formattedOutput","formatMove","schemaPrefix","deployHookPrefix","code","fs","path","debug","formatAndWriteTypescript","formatTypescript","posixPath","path","existsSync","fs","deleteFolderRecursive","path","file","curPath","getStructAttrs","values","key","_","getStructTypes","values","_","type","getStructAttrsWithType","key","getStructAttrsQuery","generateToml","config","srcPrefix","frameworkId","code","formatAndWriteMove","capitalizeAndRemoveUnderscores","input","word","index","renderSetAttrsFunc","schemaName","fields","key","type","renderSetFunc","getStructAttrsWithType","fieldName","renderGetAllFunc","getStructTypes","getStructAttrsQuery","renderGetAttrsFunc","convertToSnakeCase","generateSchemaData","projectName","schemas","path","schema","item","code","enumNames","field","name","getStructAttrs","formatAndWriteMove","generateImport","generateSchemaStructure","schemaMoudle","value","storage_type","all_types","para_key","para_value","borrow_key","extra_code","existsSync","generateDeployHook","config","srcPrefix","existsSync","code","schemaName","capitalizeAndRemoveUnderscores","formatAndWriteMove","generateMigrate","generateDappKey","config","srcPrefix","code","formatAndWriteMove","convertToSnakeCase","input","generateSchemaEvent","projectName","schemas","path","schemaName","schema","item","code","getStructAttrsWithType","getStructAttrs","formatAndWriteMove","existsSync","fs","generateSystem","config","srcPrefix","generateSchemaHub","config","srcPrefix","code","formatAndWriteMove","matchFrameworkId","network","schemaGen","config","srcPrefix","frameworkId","path","existsSync","deleteFolderRecursive","generateToml","generateDeployHook","generateSchemaData","generateSchemaStructure","generateSchemaEvent","generateDappKey","generateSchemaHub","generateSystem","generateMigrate","findUp","path","esbuild","NotInsideProjectError","rmSync","pathToFileURL","os","configFiles","TEMP_CONFIG","loadConfig","configPath","resolveConfigPath","esbuild","toFileURL","getUserConfigPath","path","tsConfigPath","findUp","NotInsideProjectError"]}
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
export type BaseType =
|
|
2
|
-
|
|
|
3
|
-
|
|
|
4
|
-
|
|
|
5
|
-
|
|
|
6
|
-
|
|
|
7
|
-
|
|
|
8
|
-
|
|
|
9
|
-
|
|
|
10
|
-
|
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
|
|
|
2
|
+
| 'String'
|
|
3
|
+
| 'vector<String>'
|
|
4
|
+
| 'address'
|
|
5
|
+
| 'bool'
|
|
6
|
+
| 'u8'
|
|
7
|
+
| 'u32'
|
|
8
|
+
| 'u64'
|
|
9
|
+
| 'u128'
|
|
10
|
+
| 'vector<address>'
|
|
11
|
+
| 'vector<bool>'
|
|
12
|
+
| 'vector<u8>'
|
|
13
|
+
| 'vector<vector<u8>>'
|
|
14
|
+
| 'vector<u32>'
|
|
15
|
+
| 'vector<u64>'
|
|
16
|
+
| 'vector<u128>'
|
|
17
17
|
| string;
|
|
18
18
|
|
|
19
19
|
export type StorageDataType =
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
| 'Struct'
|
|
21
|
+
| 'Enum';
|
|
22
22
|
|
|
23
23
|
export type StorageMapType =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
| 'Map'
|
|
25
|
+
| 'Bag'
|
|
26
|
+
| 'Table';
|
|
27
27
|
|
|
28
28
|
type Address = string;
|
|
29
29
|
type Bool = boolean;
|
|
@@ -49,13 +49,13 @@ export type BaseValueType =
|
|
|
49
49
|
| Vector<U128>;
|
|
50
50
|
|
|
51
51
|
|
|
52
|
-
export type SchemaData =
|
|
52
|
+
export type SchemaData = {
|
|
53
53
|
name: string;
|
|
54
54
|
type?: StorageDataType;
|
|
55
55
|
fields: Record<string, BaseType> | string[];
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
export type SchemaType =
|
|
58
|
+
export type SchemaType = {
|
|
59
59
|
data?: SchemaData[];
|
|
60
60
|
structure: Record<string, string>;
|
|
61
61
|
events?: SchemaData[];
|
|
@@ -65,24 +65,23 @@ export type DubheConfig = {
|
|
|
65
65
|
name: string;
|
|
66
66
|
description: string;
|
|
67
67
|
schemas: Record<string, SchemaType>;
|
|
68
|
-
migration_enabled: boolean
|
|
69
68
|
};
|
|
70
69
|
|
|
71
70
|
export type MoveType =
|
|
72
|
-
|
|
|
73
|
-
|
|
|
74
|
-
|
|
|
75
|
-
|
|
|
76
|
-
|
|
|
77
|
-
|
|
|
78
|
-
|
|
|
79
|
-
|
|
|
80
|
-
|
|
|
81
|
-
|
|
|
82
|
-
|
|
|
83
|
-
|
|
|
84
|
-
|
|
|
85
|
-
|
|
|
86
|
-
|
|
|
87
|
-
|
|
|
88
|
-
|
|
|
71
|
+
| 'string'
|
|
72
|
+
| 'vector<string>'
|
|
73
|
+
| 'String'
|
|
74
|
+
| 'vector<String>'
|
|
75
|
+
| 'address'
|
|
76
|
+
| 'bool'
|
|
77
|
+
| 'u8'
|
|
78
|
+
| 'u32'
|
|
79
|
+
| 'u64'
|
|
80
|
+
| 'u128'
|
|
81
|
+
| 'vector<address>'
|
|
82
|
+
| 'vector<bool>'
|
|
83
|
+
| 'vector<u8>'
|
|
84
|
+
| 'vector<vector<u8>>'
|
|
85
|
+
| 'vector<u32>'
|
|
86
|
+
| 'vector<u64>'
|
|
87
|
+
| 'vector<u128>';
|
|
@@ -20,34 +20,34 @@ export function capitalizeAndRemoveUnderscores(input: string): string {
|
|
|
20
20
|
|
|
21
21
|
export function renderSetAttrsFunc(
|
|
22
22
|
schemaName: string,
|
|
23
|
-
fields: BaseType | Record<string, BaseType
|
|
23
|
+
fields: BaseType | Record<string, BaseType>,
|
|
24
24
|
): string {
|
|
25
25
|
return Object.entries(fields)
|
|
26
26
|
.map(
|
|
27
27
|
([key, type]) =>
|
|
28
28
|
`public(package) fun set_${key}(self: &mut ${schemaName}, ${key}: ${type}) {
|
|
29
29
|
self.${key} = ${key};
|
|
30
|
-
}
|
|
30
|
+
}`,
|
|
31
31
|
)
|
|
32
32
|
.join('\n');
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export function renderSetFunc(
|
|
36
36
|
schemaName: string,
|
|
37
|
-
fields: Record<string, string
|
|
37
|
+
fields: Record<string, string>,
|
|
38
38
|
): string {
|
|
39
39
|
return `public(package) fun set(self: &mut ${schemaName}, ${getStructAttrsWithType(
|
|
40
|
-
fields
|
|
40
|
+
fields,
|
|
41
41
|
)}) {
|
|
42
42
|
${Object.entries(fields)
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
.map(([fieldName]) => `self.${fieldName} = ${fieldName};`)
|
|
44
|
+
.join('\n')}
|
|
45
45
|
}`;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export function renderGetAllFunc(
|
|
49
49
|
schemaName: string,
|
|
50
|
-
fields: Record<string, string
|
|
50
|
+
fields: Record<string, string>,
|
|
51
51
|
): string {
|
|
52
52
|
return `public fun get(self: &${schemaName}): ${getStructTypes(fields)} {
|
|
53
53
|
(${getStructAttrsQuery(fields)})
|
|
@@ -56,16 +56,16 @@ export function renderGetAllFunc(
|
|
|
56
56
|
|
|
57
57
|
export function renderGetAttrsFunc(
|
|
58
58
|
schemaName: string,
|
|
59
|
-
fields: BaseType | Record<string, BaseType
|
|
59
|
+
fields: BaseType | Record<string, BaseType>,
|
|
60
60
|
): string {
|
|
61
61
|
return Object.entries(fields)
|
|
62
62
|
.map(
|
|
63
63
|
([
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
key,
|
|
65
|
+
type,
|
|
66
|
+
]) => `public fun get_${key}(self: &${schemaName}): ${type} {
|
|
67
67
|
self.${key}
|
|
68
|
-
}
|
|
68
|
+
}`,
|
|
69
69
|
)
|
|
70
70
|
.join('\n');
|
|
71
71
|
}
|
|
@@ -80,7 +80,7 @@ function convertToSnakeCase(input: string): string {
|
|
|
80
80
|
export async function generateSchemaData(
|
|
81
81
|
projectName: string,
|
|
82
82
|
schemas: Record<string, SchemaType>,
|
|
83
|
-
path: string
|
|
83
|
+
path: string,
|
|
84
84
|
) {
|
|
85
85
|
console.log('\nš¦ Starting Schema Data Generation...');
|
|
86
86
|
for (const schemaName in schemas) {
|
|
@@ -91,7 +91,7 @@ export async function generateSchemaData(
|
|
|
91
91
|
console.log(
|
|
92
92
|
` āā Generating ${item.name} ${
|
|
93
93
|
Array.isArray(item.fields) ? '(enum)' : '(struct)'
|
|
94
|
-
}
|
|
94
|
+
}`,
|
|
95
95
|
);
|
|
96
96
|
let code = '';
|
|
97
97
|
|
|
@@ -101,42 +101,42 @@ export async function generateSchemaData(
|
|
|
101
101
|
|
|
102
102
|
if (Array.isArray(item.fields)) {
|
|
103
103
|
code = `module ${projectName}::${schemaName}_${convertToSnakeCase(
|
|
104
|
-
item.name
|
|
104
|
+
item.name,
|
|
105
105
|
)} {
|
|
106
106
|
public enum ${item.name} has copy, drop , store {
|
|
107
107
|
${item.fields}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
${item.fields
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
.map((field: string) => {
|
|
112
|
+
return `public fun new_${convertToSnakeCase(
|
|
113
|
+
field,
|
|
114
|
+
)}(): ${item.name} {
|
|
115
115
|
${item.name}::${field}
|
|
116
116
|
}`;
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
})
|
|
118
|
+
.join('')}`;
|
|
119
119
|
} else {
|
|
120
120
|
code = `module ${projectName}::${schemaName}_${convertToSnakeCase(
|
|
121
|
-
item.name
|
|
121
|
+
item.name,
|
|
122
122
|
)} {
|
|
123
123
|
use std::ascii::String;
|
|
124
124
|
${enumNames
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
125
|
+
.map(
|
|
126
|
+
name =>
|
|
127
|
+
`use ${projectName}::${schemaName}_${convertToSnakeCase(
|
|
128
|
+
name,
|
|
129
|
+
)}::${name};`,
|
|
130
|
+
)
|
|
131
|
+
.join('\n')}
|
|
132
132
|
|
|
133
133
|
public struct ${item.name} has copy, drop , store {
|
|
134
134
|
${getStructAttrsWithType(item.fields)}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
public fun new(${getStructAttrsWithType(
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
item.fields,
|
|
139
|
+
)}): ${item.name} {
|
|
140
140
|
${item.name} {
|
|
141
141
|
${getStructAttrs(item.fields)}
|
|
142
142
|
}
|
|
@@ -152,9 +152,9 @@ export async function generateSchemaData(
|
|
|
152
152
|
await formatAndWriteMove(
|
|
153
153
|
code,
|
|
154
154
|
`${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}_${convertToSnakeCase(
|
|
155
|
-
item.name
|
|
155
|
+
item.name,
|
|
156
156
|
)}.move`,
|
|
157
|
-
'formatAndWriteMove'
|
|
157
|
+
'formatAndWriteMove',
|
|
158
158
|
);
|
|
159
159
|
}
|
|
160
160
|
}
|
|
@@ -165,13 +165,13 @@ export async function generateSchemaData(
|
|
|
165
165
|
function generateImport(
|
|
166
166
|
projectName: string,
|
|
167
167
|
schemaName: string,
|
|
168
|
-
schema: SchemaType
|
|
168
|
+
schema: SchemaType,
|
|
169
169
|
) {
|
|
170
170
|
if (schema.data) {
|
|
171
171
|
return schema.data
|
|
172
172
|
.map(item => {
|
|
173
173
|
return `use ${projectName}::${schemaName}_${convertToSnakeCase(
|
|
174
|
-
item.name
|
|
174
|
+
item.name,
|
|
175
175
|
)}::${item.name};`;
|
|
176
176
|
})
|
|
177
177
|
.join('\n');
|
|
@@ -184,18 +184,17 @@ export async function generateSchemaStructure(
|
|
|
184
184
|
projectName: string,
|
|
185
185
|
schemas: Record<string, SchemaType>,
|
|
186
186
|
path: string,
|
|
187
|
-
migration_enabled: boolean
|
|
188
187
|
) {
|
|
189
188
|
console.log('\nšØ Starting Schema Structure Generation...');
|
|
190
189
|
for (const schemaName in schemas) {
|
|
191
190
|
console.log(` āā Generating schema: ${schemaName}`);
|
|
192
191
|
console.log(
|
|
193
|
-
` āā Output path: ${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move
|
|
192
|
+
` āā Output path: ${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,
|
|
194
193
|
);
|
|
195
194
|
console.log(
|
|
196
195
|
` āā Structure fields: ${
|
|
197
196
|
Object.keys(schemas[schemaName].structure).length
|
|
198
|
-
}
|
|
197
|
+
}`,
|
|
199
198
|
);
|
|
200
199
|
const schema = schemas[schemaName];
|
|
201
200
|
const schemaMoudle = `module ${projectName}::${schemaName}_schema {
|
|
@@ -214,92 +213,91 @@ export async function generateSchemaStructure(
|
|
|
214
213
|
${generateImport(projectName, schemaName, schema)}
|
|
215
214
|
|
|
216
215
|
public struct ${capitalizeAndRemoveUnderscores(
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
schemaName,
|
|
217
|
+
)} has key, store {
|
|
219
218
|
id: UID
|
|
220
219
|
}
|
|
221
220
|
|
|
222
221
|
${Object.entries(schema.structure)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
222
|
+
.map(([key, value]) => {
|
|
223
|
+
return `public fun borrow_${key}(self: &${capitalizeAndRemoveUnderscores(
|
|
224
|
+
schemaName,
|
|
225
|
+
)}) : &${value} {
|
|
227
226
|
storage_migrate::borrow_field(&self.id, b"${key}")
|
|
228
227
|
}
|
|
229
228
|
|
|
230
229
|
public(package) fun borrow_mut_${key}(self: &mut ${capitalizeAndRemoveUnderscores(
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
schemaName,
|
|
231
|
+
)}): &mut ${value} {
|
|
233
232
|
storage_migrate::borrow_mut_field(&mut self.id, b"${key}")
|
|
234
233
|
}
|
|
235
234
|
`;
|
|
236
|
-
|
|
237
|
-
|
|
235
|
+
})
|
|
236
|
+
.join('')}
|
|
238
237
|
|
|
239
238
|
|
|
240
239
|
public(package) fun create(ctx: &mut TxContext): ${capitalizeAndRemoveUnderscores(
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
schemaName,
|
|
241
|
+
)} {
|
|
243
242
|
let mut id = object::new(ctx);
|
|
244
243
|
${Object.entries(schema.structure)
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
244
|
+
.map(([key, value]) => {
|
|
245
|
+
let storage_type = '';
|
|
246
|
+
if (value.includes('StorageValue')) {
|
|
247
|
+
storage_type = `storage_value::new()`;
|
|
248
|
+
} else if (value.includes('StorageMap')) {
|
|
249
|
+
storage_type = `storage_map::new()`;
|
|
250
|
+
} else if (
|
|
251
|
+
value.includes('StorageDoubleMap')
|
|
252
|
+
) {
|
|
253
|
+
storage_type = `storage_double_map::new()`;
|
|
254
|
+
}
|
|
255
|
+
return `storage_migrate::add_field<${value}>(&mut id, b"${key}", ${storage_type});`;
|
|
256
|
+
})
|
|
257
|
+
.join('')}
|
|
259
258
|
|
|
260
259
|
${capitalizeAndRemoveUnderscores(schemaName)} { id }
|
|
261
260
|
}
|
|
262
261
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
262
|
+
public fun migrate(_${schemaName}: &mut ${capitalizeAndRemoveUnderscores(schemaName)}, _cap: &UpgradeCap) { }
|
|
263
|
+
|
|
266
264
|
|
|
267
265
|
|
|
268
266
|
// ======================================== View Functions ========================================
|
|
269
267
|
${Object.entries(schema.structure)
|
|
270
268
|
.map(([key, value]) => {
|
|
271
269
|
// @ts-ignore
|
|
272
|
-
let all_types = value.match(/<(.+)>/)[1].split(',').map(type => type.trim())
|
|
273
|
-
let para_key: string[] = []
|
|
274
|
-
let para_value =
|
|
275
|
-
let borrow_key =
|
|
276
|
-
let extra_code =
|
|
270
|
+
let all_types = value.match(/<(.+)>/)[1].split(',').map(type => type.trim());
|
|
271
|
+
let para_key: string[] = [];
|
|
272
|
+
let para_value = '';
|
|
273
|
+
let borrow_key = '';
|
|
274
|
+
let extra_code = '';
|
|
277
275
|
if (value.includes('StorageValue')) {
|
|
278
|
-
para_key = []
|
|
279
|
-
para_value = `${all_types[0]}
|
|
280
|
-
borrow_key = 'try_get()'
|
|
276
|
+
para_key = [];
|
|
277
|
+
para_value = `${all_types[0]}`;
|
|
278
|
+
borrow_key = 'try_get()';
|
|
281
279
|
} else if (value.includes('StorageMap')) {
|
|
282
|
-
para_key = [`key: ${all_types[0]}`]
|
|
283
|
-
para_value = `${all_types[1]}
|
|
284
|
-
borrow_key = 'try_get(key)'
|
|
280
|
+
para_key = [`key: ${all_types[0]}`];
|
|
281
|
+
para_value = `${all_types[1]}`;
|
|
282
|
+
borrow_key = 'try_get(key)';
|
|
285
283
|
extra_code = `public fun get_${key}_keys(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : vector<${all_types[0]}> {
|
|
286
284
|
self.borrow_${key}().keys()
|
|
287
285
|
}
|
|
288
286
|
|
|
289
287
|
public fun get_${key}_values(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : vector<${all_types[1]}> {
|
|
290
288
|
self.borrow_${key}().values()
|
|
291
|
-
}
|
|
289
|
+
}`;
|
|
292
290
|
} else if (value.includes('StorageDoubleMap')) {
|
|
293
|
-
para_key = [`key1: ${all_types[0]}`, `key2: ${all_types[1]}`]
|
|
294
|
-
para_value = `${all_types[2]}
|
|
295
|
-
borrow_key = 'try_get(key1, key2)'
|
|
291
|
+
para_key = [`key1: ${all_types[0]}`, `key2: ${all_types[1]}`];
|
|
292
|
+
para_value = `${all_types[2]}`;
|
|
293
|
+
borrow_key = 'try_get(key1, key2)';
|
|
296
294
|
extra_code = `public fun get_${key}_keys(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : (vector<${all_types[0]}>, vector<${all_types[1]}>) {
|
|
297
295
|
self.borrow_${key}().keys()
|
|
298
296
|
}
|
|
299
297
|
|
|
300
298
|
public fun get_${key}_values(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : vector<${all_types[2]}> {
|
|
301
299
|
self.borrow_${key}().values()
|
|
302
|
-
}
|
|
300
|
+
}`;
|
|
303
301
|
}
|
|
304
302
|
return `public fun get_${key}(self: &${capitalizeAndRemoveUnderscores(schemaName)}, ${para_key}) : Option<${para_value}> {
|
|
305
303
|
self.borrow_${key}().${borrow_key}
|
|
@@ -314,7 +312,7 @@ export async function generateSchemaStructure(
|
|
|
314
312
|
await formatAndWriteMove(
|
|
315
313
|
schemaMoudle,
|
|
316
314
|
`${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,
|
|
317
|
-
'formatAndWriteMove'
|
|
315
|
+
'formatAndWriteMove',
|
|
318
316
|
);
|
|
319
317
|
}
|
|
320
318
|
console.log('ā
Schema Structure Generation Complete\n');
|
|
@@ -5,72 +5,71 @@ import { generateToml } from './generateToml';
|
|
|
5
5
|
import { generateSchemaData, generateSchemaStructure } from './generateSchema';
|
|
6
6
|
import { generateDeployHook, generateMigrate } from './generateScript';
|
|
7
7
|
import { generateDappKey } from './generateDappKey';
|
|
8
|
-
import {generateSchemaEvent} from
|
|
8
|
+
import { generateSchemaEvent } from './generateEvent';
|
|
9
9
|
import { generateSystem } from './generateSystem';
|
|
10
10
|
import { generateSchemaHub } from './generateSchemaHub';
|
|
11
11
|
|
|
12
12
|
function matchFrameworkId(
|
|
13
|
-
|
|
13
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
14
14
|
): string {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
switch (network) {
|
|
16
|
+
case 'testnet':
|
|
17
|
+
return '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';
|
|
18
|
+
case 'localnet':
|
|
19
|
+
return '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';
|
|
20
|
+
default:
|
|
21
|
+
return '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';
|
|
22
|
+
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export async function schemaGen(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
config: DubheConfig,
|
|
27
|
+
srcPrefix?: string,
|
|
28
|
+
network?: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
29
|
+
frameworkId?: string,
|
|
30
30
|
) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
console.log('\nš Starting Schema Generation Process...');
|
|
32
|
+
console.log('š Project Configuration:');
|
|
33
|
+
console.log(` āā Name: ${config.name}`);
|
|
34
|
+
console.log(
|
|
35
|
+
` āā Description: ${config.description || 'No description provided'}`,
|
|
36
|
+
);
|
|
37
|
+
console.log(` āā Network: ${network || 'testnet'}`);
|
|
38
|
+
console.log(
|
|
39
|
+
` āā Framework ID: ${
|
|
40
|
+
frameworkId || matchFrameworkId(network ?? 'testnet')
|
|
41
|
+
}\n`,
|
|
42
|
+
);
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
const path = srcPrefix ?? process.cwd();
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
frameworkId = frameworkId || matchFrameworkId(network ?? 'testnet');
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
if (existsSync(`${path}/contracts/${config.name}`)) {
|
|
49
|
+
deleteFolderRecursive(
|
|
50
|
+
`${path}/contracts/${config.name}/sources/codegen`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
if (!existsSync(`${path}/contracts/${config.name}/Move.toml`)) {
|
|
55
|
+
await generateToml(config, path, frameworkId);
|
|
56
|
+
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
if (
|
|
59
|
+
!existsSync(
|
|
60
|
+
`${path}/contracts/${config.name}/sources/script/deploy_hook.move`,
|
|
61
|
+
)
|
|
62
|
+
) {
|
|
63
|
+
await generateDeployHook(config, path);
|
|
64
|
+
}
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
console.log('ā
Schema Generation Process Complete!\n');
|
|
66
|
+
await generateSchemaData(config.name, config.schemas, path);
|
|
67
|
+
await generateSchemaStructure(config.name, config.schemas, path);
|
|
68
|
+
await generateSchemaEvent(config.name, config.schemas, path);
|
|
69
|
+
await generateDappKey(config, path);
|
|
70
|
+
await generateSchemaHub(config, path);
|
|
71
|
+
await generateSystem(config, path);
|
|
72
|
+
await generateMigrate(config, path);
|
|
73
|
+
|
|
74
|
+
console.log('ā
Schema Generation Process Complete!\n');
|
|
76
75
|
}
|