@0xobelisk/sui-common 1.0.5 → 1.1.0
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 +3 -1
- package/dist/index.js +88 -101
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/codegen/utils/formatAndWrite.ts +2 -2
- package/src/codegen/utils/renderMove/generateDefaultSchema.ts +7 -7
- package/src/codegen/utils/renderMove/generateInit.ts +30 -4
- package/src/codegen/utils/renderMove/generateScript.ts +11 -59
- package/src/codegen/utils/renderMove/generateToml.ts +1 -1
- package/src/index.ts +1 -0
- package/src/parseData/index.ts +1 -0
- package/src/parseData/parser/index.ts +25 -0
package/dist/index.d.ts
CHANGED
|
@@ -47,4 +47,6 @@ declare function schemaGen(config: DubheConfig, srcPrefix?: string, network?: 'm
|
|
|
47
47
|
declare function loadConfig(configPath?: string): Promise<unknown>;
|
|
48
48
|
declare function resolveConfigPath(configPath: string | undefined, toFileURL?: boolean): Promise<string>;
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
declare const parseData: (data: unknown) => any;
|
|
51
|
+
|
|
52
|
+
export { BaseType, BaseValueType, DubheConfig, ErrorData, EventData, MoveType, SchemaData, SchemaType, StorageDataType, StorageMapType, formatAndWriteMove, formatAndWriteTypescript, formatMove, formatTypescript, loadConfig, parseData, posixPath, resolveConfigPath, schemaGen };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import y from"prettier";import X from"prettier-plugin-move-js";async function
|
|
1
|
+
import y from"prettier";import X from"prettier-plugin-move-js";async function M(e,t){let r;t&&(r=await y.resolveConfig(t));try{return y.format(e,{plugins:[X],parser:"move-parse",printWidth:120,semi:!0,tabWidth:2,useTabs:!1,bracketSpacing:!0,...r})}catch(a){let s;return a instanceof Error?s=a.message:s=a,console.log(`Error during output formatting: ${s}`),e}}async function T(e){return y.format(e,{parser:"typescript"})}import S from"node:fs/promises";import R from"node:path";import j from"debug";var b=j("dubhe:common"),Y=j("dubhe:common");b.log=console.debug.bind(console);Y.log=console.error.bind(console);var $=b.extend("codegen"),q=b.extend("codegen");$.log=console.debug.bind(console);q.log=console.error.bind(console);async function c(e,t,r){let a=await M(e),s=` // Copyright (c) Obelisk Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
#[allow(unused_use)]
|
|
4
4
|
|
|
5
5
|
/* Autogenerated file. Do not edit manually. */
|
|
6
6
|
|
|
7
|
-
`,o="#[test_only]",s
|
|
7
|
+
`,o="#[test_only]",n=s+a,i="#[allow(lint(share_owned))]";t.includes(".toml")||t.includes("system")||t.includes("migrate")?n=a:t.includes("init")?n=o+a:t.includes("genesis")&&(n=i+a),await S.mkdir(R.dirname(t),{recursive:!0}),await S.writeFile(t,n),$(`${r}: ${t}`)}async function Ce(e,t,r){let a=await T(e);await S.mkdir(R.dirname(t),{recursive:!0}),await S.writeFile(t,a),$(`${r}: ${t}`)}function Me(e){return e.replace(/\\/g,"/")}import{existsSync as k}from"fs";import g from"fs";function w(e){g.existsSync(e)&&(g.readdirSync(e).forEach(t=>{let r=`${e}/${t}`;g.lstatSync(r).isDirectory()?w(r):g.unlinkSync(r)}),g.rmdirSync(e))}function f(e){return Object.entries(e).map(([t,r])=>`${t}`).join(",")}function W(e){return`(${Object.entries(e).map(([t,r])=>`${r}`)})`}function u(e){return Object.entries(e).map(([t,r])=>`${t}: ${r}`)}function E(e){return Object.entries(e).map(([t,r])=>`self.${t}`)}async function G(e,t){console.log(`
|
|
8
8
|
\u{1F4C4} Starting Move.toml Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/Move.toml`);let r=`[package]
|
|
9
9
|
name = "${e.name}"
|
|
10
10
|
version = "1.0.0"
|
|
@@ -12,54 +12,54 @@ edition = "2024"
|
|
|
12
12
|
|
|
13
13
|
[dependencies]
|
|
14
14
|
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.38.3" }
|
|
15
|
-
Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe-mainnet-v1.
|
|
15
|
+
Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe-mainnet-v1.1.0" }
|
|
16
16
|
|
|
17
17
|
[addresses]
|
|
18
18
|
sui = "0x2"
|
|
19
19
|
${e.name} = "0x0"
|
|
20
20
|
`;await c(r,`${t}/contracts/${e.name}/Move.toml`,"formatAndWriteMove"),console.log(`\u2705 Move.toml Generation Complete
|
|
21
|
-
`)}function J(e){return e.sort((t,r)=>{let a=t.charAt(0).toLowerCase(),
|
|
21
|
+
`)}function J(e){return e.sort((t,r)=>{let a=t.charAt(0).toLowerCase(),s=r.charAt(0).toLowerCase();return a<s?-1:a>s?1:0})}function N(e,t){return Object.entries(t).map(([r,a])=>`public(package) fun set_${r}(self: &mut ${e}, ${r}: ${a}) {
|
|
22
22
|
self.${r} = ${r};
|
|
23
23
|
}`).join(`
|
|
24
24
|
`)}function P(e,t){return`public(package) fun set(self: &mut ${e}, ${u(t)}) {
|
|
25
25
|
${Object.entries(t).map(([r])=>`self.${r} = ${r};`).join(`
|
|
26
26
|
`)}
|
|
27
27
|
}`}function ee(e,t){return`public fun get(self: &${e}): ${W(t)} {
|
|
28
|
-
(${
|
|
28
|
+
(${E(t)})
|
|
29
29
|
}`}function te(e,t){return Object.entries(t).map(([r,a])=>`public fun get_${r}(self: &${e}): ${a} {
|
|
30
30
|
self.${r}
|
|
31
31
|
}`).join(`
|
|
32
32
|
`)}function l(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function O(e,t,r){console.log(`
|
|
33
|
-
\u{1F4E6} Starting Schema Data Generation...`);for(let a of Object.keys(t)){let
|
|
34
|
-
public enum ${
|
|
33
|
+
\u{1F4E6} Starting Schema Data Generation...`);for(let a of Object.keys(t)){let s=a,o=t[a];console.log(` \u2514\u2500 Generating ${s} ${Array.isArray(o)?"(enum)":"(struct)"}`);let n="",i=Object.keys(t).filter(p=>Array.isArray(t[p])).map(p=>p);if(console.log(i),Array.isArray(o)){let p=J(o);n=`module ${e}::${l(s)} {
|
|
34
|
+
public enum ${s} has copy, drop , store {
|
|
35
35
|
${p}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
${p.map(d=>`public fun new_${l(d)}(): ${
|
|
39
|
-
${
|
|
40
|
-
}`).join("")}`}else
|
|
38
|
+
${p.map(d=>`public fun new_${l(d)}(): ${s} {
|
|
39
|
+
${s}::${d}
|
|
40
|
+
}`).join("")}`}else n=`module ${e}::${l(s)} {
|
|
41
41
|
use std::ascii::String;
|
|
42
42
|
${i.map(p=>`use ${e}::${l(p)}::${p};`).join(`
|
|
43
43
|
`)}
|
|
44
44
|
|
|
45
|
-
public struct ${
|
|
45
|
+
public struct ${s} has copy, drop , store {
|
|
46
46
|
${u(o)}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
public fun new(${u(o)}): ${
|
|
50
|
-
${
|
|
49
|
+
public fun new(${u(o)}): ${s} {
|
|
50
|
+
${s} {
|
|
51
51
|
${f(o)}
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
${ee(
|
|
56
|
-
${te(
|
|
57
|
-
${N(
|
|
58
|
-
${P(
|
|
59
|
-
}`;await c(
|
|
55
|
+
${ee(s,o)}
|
|
56
|
+
${te(s,o)}
|
|
57
|
+
${N(s,o)}
|
|
58
|
+
${P(s,o)}
|
|
59
|
+
}`;await c(n,`${r}/contracts/${e}/sources/codegen/data/${l(s)}.move`,"formatAndWriteMove")}console.log(`\u2705 Schema Data Generation Complete
|
|
60
60
|
`)}function re(e,t){return t!=null?Object.keys(t).map(a=>`use ${e}::${l(a)}::${a};`).join(`
|
|
61
|
-
`):""}async function
|
|
62
|
-
\u{1F528} Starting Schema Structure Generation...`),console.log(` \u251C\u2500 Output path: ${a}/contracts/${e}/sources/codegen/schema.move`),console.log(` \u2514\u2500 Structure fields: ${Object.values(r).length}`);let
|
|
61
|
+
`):""}async function v(e,t,r,a){console.log(`
|
|
62
|
+
\u{1F528} Starting Schema Structure Generation...`),console.log(` \u251C\u2500 Output path: ${a}/contracts/${e}/sources/codegen/schema.move`),console.log(` \u2514\u2500 Structure fields: ${Object.values(r).length}`);let s=`module ${e}::schema {
|
|
63
63
|
use std::ascii::String;
|
|
64
64
|
use std::ascii::string;
|
|
65
65
|
use sui::package::UpgradeCap;
|
|
@@ -74,11 +74,11 @@ ${e.name} = "0x0"
|
|
|
74
74
|
|
|
75
75
|
public struct Schema has key, store { id: UID }
|
|
76
76
|
|
|
77
|
-
${Object.entries(r).map(([o,
|
|
77
|
+
${Object.entries(r).map(([o,n])=>`public fun borrow_${o}(self: &Schema) : &${n} {
|
|
78
78
|
storage::borrow_field(&self.id, b"${o}")
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
public(package) fun ${o}(self: &mut Schema): &mut ${
|
|
81
|
+
public(package) fun ${o}(self: &mut Schema): &mut ${n} {
|
|
82
82
|
storage::borrow_mut_field(&mut self.id, b"${o}")
|
|
83
83
|
}
|
|
84
84
|
`).join("")}
|
|
@@ -86,7 +86,7 @@ ${e.name} = "0x0"
|
|
|
86
86
|
|
|
87
87
|
public(package) fun create(ctx: &mut TxContext): Schema {
|
|
88
88
|
let mut id = object::new(ctx);
|
|
89
|
-
${Object.entries(r).map(([o,
|
|
89
|
+
${Object.entries(r).map(([o,n])=>{let i="";return n.includes("StorageValue")?i=`storage_value::new(b"${o}", ctx)`:n.includes("StorageMap")?i=`storage_map::new(b"${o}", ctx)`:n.includes("StorageDoubleMap")&&(i=`storage_double_map::new(b"${o}", ctx)`),`storage::add_field<${n}>(&mut id, b"${o}", ${i});`}).join(`
|
|
90
90
|
`)}
|
|
91
91
|
|
|
92
92
|
Schema { id }
|
|
@@ -96,103 +96,71 @@ ${e.name} = "0x0"
|
|
|
96
96
|
|
|
97
97
|
|
|
98
98
|
// ======================================== View Functions ========================================
|
|
99
|
-
${Object.entries(r).map(([o,
|
|
99
|
+
${Object.entries(r).map(([o,n])=>{let i=n.match(/<(.+)>/)[1].split(",").map(Z=>Z.trim()),p=[],d="",_="";return n.includes("StorageValue")?(p=[],d=`${i[0]}`,_="get()"):n.includes("StorageMap")?(p=[`key: ${i[0]}`],d=`${i[1]}`,_="get(key)"):n.includes("StorageDoubleMap")&&(p=[`key1: ${i[0]}`,`key2: ${i[1]}`],d=`${i[2]}`,_="get(key1, key2)"),`public fun get_${o}(self: &Schema, ${p}) : &${d} {
|
|
100
100
|
self.borrow_${o}().${_}
|
|
101
101
|
}`}).join(`
|
|
102
102
|
`)}
|
|
103
103
|
// =========================================================================================================
|
|
104
|
-
}`;await c(
|
|
105
|
-
`)}import{existsSync as
|
|
106
|
-
\u{1F4DD} Starting Deploy Hook Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/scripts/deploy_hook.move`);let r
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
// Create schemas
|
|
116
|
-
let mut schema = ${e.name}::schema::create(ctx);
|
|
117
|
-
// Logic that needs to be automated once the contract is deployed
|
|
118
|
-
{
|
|
119
|
-
};
|
|
120
|
-
// Authorize schemas and public share objects
|
|
121
|
-
dapp.add_schema(schema);
|
|
122
|
-
sui::transfer::public_share_object(dapp);
|
|
123
|
-
}
|
|
124
|
-
}`;else{let s=oe(n);o=`module ${e.name}::deploy_hook {
|
|
125
|
-
use std::ascii::string;
|
|
126
|
-
use sui::clock::Clock;
|
|
127
|
-
use ${e.name}::dapp_system;
|
|
128
|
-
public entry fun run(clock: &Clock, ctx: &mut TxContext) {
|
|
129
|
-
// Create a dapp.
|
|
130
|
-
let mut dapp = dapp_system::create(string(b"${e.name}"),string(b"${e.description}"), clock , ctx);
|
|
131
|
-
|
|
132
|
-
// Create schemas
|
|
133
|
-
let mut schema = ${e.name}::schema::create(ctx);
|
|
134
|
-
// Logic that needs to be automated once the contract is deployed
|
|
135
|
-
|
|
136
|
-
{
|
|
137
|
-
${s}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
// Authorize schemas and public share objects
|
|
141
|
-
dapp.add_schema(schema);
|
|
142
|
-
sui::transfer::public_share_object(dapp);
|
|
143
|
-
}
|
|
144
|
-
}`}await c(o,n,"formatAndWriteMove"),console.log(`\u2705 Deploy Hook Generation Complete
|
|
145
|
-
`)}async function U(e,t){if(!L(`${t}/contracts/${e.name}/sources/scripts/migrate.move`)){let r=`module ${e.name}::migrate {
|
|
104
|
+
}`;await c(s,`${a}/contracts/${e}/sources/codegen/schema.move`,"formatAndWriteMove"),console.log(`\u2705 Schema Structure Generation Complete
|
|
105
|
+
`)}import{existsSync as V}from"fs";async function L(e,t){console.log(`
|
|
106
|
+
\u{1F4DD} Starting Deploy Hook Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/scripts/deploy_hook.move`);let r=`${t}/contracts/${e.name}/sources/scripts/deploy_hook.move`;if(!V(r)){let a=`module ${e.name}::deploy_hook {
|
|
107
|
+
use ${e.name}::schema::Schema;
|
|
108
|
+
|
|
109
|
+
public(package) fun run(_schema: &mut Schema, _ctx: &mut TxContext) {
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
}`;await c(a,r,"formatAndWriteMove")}console.log(`\u2705 Deploy Hook Generation Complete
|
|
113
|
+
`)}async function F(e,t){if(!V(`${t}/contracts/${e.name}/sources/scripts/migrate.move`)){let r=`module ${e.name}::migrate {
|
|
146
114
|
const ON_CHAIN_VERSION: u32 = 1;
|
|
147
115
|
|
|
148
116
|
public fun on_chain_version(): u32 {
|
|
149
117
|
ON_CHAIN_VERSION
|
|
150
118
|
}
|
|
151
119
|
}
|
|
152
|
-
`;await c(r,`${t}/contracts/${e.name}/sources/scripts/migrate.move`,"formatAndWriteMove")}}function m(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}function
|
|
153
|
-
`):""}async function
|
|
154
|
-
\u{1F4E6} Starting Schema Event Generation...`);for(let o of Object.keys(r)){let
|
|
120
|
+
`;await c(r,`${t}/contracts/${e.name}/sources/scripts/migrate.move`,"formatAndWriteMove")}}function m(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}function U(e,t){return t!=null?Object.keys(t).map(a=>`use ${e}::${m(a)}::${a};`).join(`
|
|
121
|
+
`):""}async function x(e,t,r,a){console.log(`
|
|
122
|
+
\u{1F4E6} Starting Schema Event Generation...`);for(let o of Object.keys(r)){let n=o,i=r[o];console.log(` \u2514\u2500 Generating ${n} event: ${i}`);let p=`module ${e}::${m(n)}_event {
|
|
155
123
|
use sui::event;
|
|
156
124
|
use std::ascii::String;
|
|
157
|
-
${
|
|
125
|
+
${U(e,t)}
|
|
158
126
|
|
|
159
|
-
public struct ${
|
|
127
|
+
public struct ${n}Event has copy, drop {
|
|
160
128
|
${u(i)}
|
|
161
129
|
}
|
|
162
130
|
|
|
163
|
-
public fun new(${u(i)}): ${
|
|
164
|
-
${
|
|
131
|
+
public fun new(${u(i)}): ${n}Event {
|
|
132
|
+
${n}Event {
|
|
165
133
|
${f(i)}
|
|
166
134
|
}
|
|
167
135
|
}
|
|
168
|
-
}`;await c(p,`${a}/contracts/${e}/sources/codegen/data/${m(
|
|
136
|
+
}`;await c(p,`${a}/contracts/${e}/sources/codegen/data/${m(n)}_event.move`,"formatAndWriteMove")}let s=`module ${e}::events {
|
|
169
137
|
use std::ascii::{String, string};
|
|
170
|
-
${
|
|
171
|
-
${Object.entries(r).map(([o,
|
|
138
|
+
${U(e,t)}
|
|
139
|
+
${Object.entries(r).map(([o,n])=>`
|
|
172
140
|
use ${e}::${m(o)}_event::${o}Event;
|
|
173
141
|
use ${e}::${m(o)}_event;
|
|
174
|
-
public fun ${m(o)}_event(${u(
|
|
142
|
+
public fun ${m(o)}_event(${u(n)}) {
|
|
175
143
|
dubhe::storage_event::emit_set_record<${o}Event, ${o}Event, ${o}Event>(
|
|
176
144
|
string(b"${m(o)}_event"),
|
|
177
145
|
option::none(),
|
|
178
146
|
option::none(),
|
|
179
|
-
option::some(${m(o)}_event::new(${f(
|
|
147
|
+
option::some(${m(o)}_event::new(${f(n)}))
|
|
180
148
|
)
|
|
181
149
|
}
|
|
182
150
|
`).join(`
|
|
183
151
|
`)}
|
|
184
|
-
}`;await c(
|
|
185
|
-
`)}import{existsSync as
|
|
186
|
-
\u2699\uFE0F Starting System Generation...`),console.log(" \u251C\u2500 Generating systems"),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/systems`),
|
|
187
|
-
`)}function
|
|
152
|
+
}`;await c(s,`${a}/contracts/${e}/sources/codegen/events.move`,"formatAndWriteMove"),console.log(`\u2705 Schema Event Generation Complete
|
|
153
|
+
`)}import{existsSync as ae}from"fs";import oe from"node:fs/promises";async function I(e,t){console.log(`
|
|
154
|
+
\u2699\uFE0F Starting System Generation...`),console.log(" \u251C\u2500 Generating systems"),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/systems`),ae(`${t}/contracts/${e.name}/sources/systems`)||await oe.mkdir(`${t}/contracts/${e.name}/sources/systems`,{recursive:!0}),console.log(`\u2705 System Generation Complete
|
|
155
|
+
`)}function se(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function B(e,t,r){console.log(`
|
|
188
156
|
\u{1F4E6} Starting Schema Error Generation...`);let a=`module ${e}::errors {
|
|
189
|
-
${Object.entries(t).map(([
|
|
190
|
-
const ${
|
|
191
|
-
public fun ${
|
|
157
|
+
${Object.entries(t).map(([s,o])=>(console.log(` \u251C\u2500 Generating Error: ${s}`),console.log(` \u2502 \u2514\u2500 Message: ${o}`),`#[error]
|
|
158
|
+
const ${s}: vector<u8> = b"${o}";
|
|
159
|
+
public fun ${se(s)}_error(condition: bool) { assert!(condition, ${s}) }
|
|
192
160
|
`)).join(`
|
|
193
161
|
`)}
|
|
194
162
|
}`;await c(a,`${r}/contracts/${e}/sources/codegen/errors.move`,"formatAndWriteMove"),console.log(`\u2705 Schema Error Generation Complete
|
|
195
|
-
`)}import{existsSync as
|
|
163
|
+
`)}import{existsSync as D}from"fs";async function z(e,t){await ne(e,t),await ie(e,t),await ce(e,t)}async function ne(e,t){let r=`${t}/contracts/${e.name}/sources/codegen/dapp/metadata.move`;if(!D(r)){let a=`module ${e.name}::dapp_metadata {
|
|
196
164
|
use std::ascii::String;
|
|
197
165
|
|
|
198
166
|
public struct DappMetadata has drop, copy, store {
|
|
@@ -263,32 +231,32 @@ use ${e}::${m(o)}_event;
|
|
|
263
231
|
self.partners = partners;
|
|
264
232
|
}
|
|
265
233
|
|
|
266
|
-
public fun get_name(self: DappMetadata): String {
|
|
234
|
+
public fun get_name(self: &DappMetadata): String {
|
|
267
235
|
self.name
|
|
268
236
|
}
|
|
269
237
|
|
|
270
|
-
public fun get_description(self: DappMetadata): String {
|
|
238
|
+
public fun get_description(self: &DappMetadata): String {
|
|
271
239
|
self.description
|
|
272
240
|
}
|
|
273
241
|
|
|
274
|
-
public fun get_icon_url(self: DappMetadata): String {
|
|
242
|
+
public fun get_icon_url(self: &DappMetadata): String {
|
|
275
243
|
self.icon_url
|
|
276
244
|
}
|
|
277
245
|
|
|
278
|
-
public fun get_website_url(self: DappMetadata): String {
|
|
246
|
+
public fun get_website_url(self: &DappMetadata): String {
|
|
279
247
|
self.website_url
|
|
280
248
|
}
|
|
281
249
|
|
|
282
|
-
public fun get_created_at(self: DappMetadata): u64 {
|
|
250
|
+
public fun get_created_at(self: &DappMetadata): u64 {
|
|
283
251
|
self.created_at
|
|
284
252
|
}
|
|
285
253
|
|
|
286
|
-
public fun get_partners(self: DappMetadata): vector<String> {
|
|
254
|
+
public fun get_partners(self: &DappMetadata): vector<String> {
|
|
287
255
|
self.partners
|
|
288
256
|
}
|
|
289
257
|
|
|
290
258
|
}
|
|
291
|
-
`;await c(a,r,"formatAndWriteMove")}}async function
|
|
259
|
+
`;await c(a,r,"formatAndWriteMove")}}async function ie(e,t){let r=`${t}/contracts/${e.name}/sources/codegen/dapp/schema.move`;if(!D(r)){let a=`module ${e.name}::dapp_schema {
|
|
292
260
|
use ${e.name}::dapp_metadata::DappMetadata;
|
|
293
261
|
use dubhe::storage_value;
|
|
294
262
|
use dubhe::storage_value::StorageValue;
|
|
@@ -389,7 +357,7 @@ use ${e}::${m(o)}_event;
|
|
|
389
357
|
id.delete();
|
|
390
358
|
}
|
|
391
359
|
}
|
|
392
|
-
`;await c(a,r,"formatAndWriteMove")}}async function
|
|
360
|
+
`;await c(a,r,"formatAndWriteMove")}}async function ce(e,t){let r=`${t}/contracts/${e.name}/sources/codegen/dapp/system.move`;if(!D(r)){let a=`module ${e.name}::dapp_system {
|
|
393
361
|
use std::ascii::String;
|
|
394
362
|
use std::ascii;
|
|
395
363
|
use dubhe::type_info;
|
|
@@ -436,7 +404,7 @@ use ${e}::${m(o)}_event;
|
|
|
436
404
|
) {
|
|
437
405
|
let admin = dapp.admin().try_get();
|
|
438
406
|
assert!(admin == option::some(ctx.sender()), 0);
|
|
439
|
-
let created_at = dapp.metadata().
|
|
407
|
+
let created_at = dapp.metadata().get().get_created_at();
|
|
440
408
|
dapp.metadata().set(
|
|
441
409
|
dapp_metadata::new(
|
|
442
410
|
name,
|
|
@@ -476,7 +444,7 @@ use ${e}::${m(o)}_event;
|
|
|
476
444
|
}
|
|
477
445
|
|
|
478
446
|
|
|
479
|
-
`;await c(a,r,"formatAndWriteMove")}}async function
|
|
447
|
+
`;await c(a,r,"formatAndWriteMove")}}async function H(e,t){console.log(`
|
|
480
448
|
\u{1F4DD} Starting Init Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/tests/init.move`);let r=`module ${e.name}::init_test {
|
|
481
449
|
use ${e.name}::dapp_schema::Dapp;
|
|
482
450
|
use sui::clock;
|
|
@@ -487,15 +455,34 @@ use ${e}::${m(o)}_event;
|
|
|
487
455
|
let mut scenario = test_scenario::begin(sender);
|
|
488
456
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
489
457
|
let clock = clock::create_for_testing(ctx);
|
|
490
|
-
${e.name}::
|
|
458
|
+
${e.name}::genesis::run(&clock, ctx);
|
|
491
459
|
clock::destroy_for_testing(clock);
|
|
492
460
|
test_scenario::next_tx(&mut scenario,sender);
|
|
493
461
|
let dapp = test_scenario::take_shared<Dapp>(&scenario);
|
|
494
462
|
(scenario, dapp)
|
|
495
463
|
}
|
|
496
464
|
}
|
|
497
|
-
`;await c(r,`${t}/contracts/${e.name}/sources/tests/init.move`,"formatAndWriteMove")
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
465
|
+
`;await c(r,`${t}/contracts/${e.name}/sources/tests/init.move`,"formatAndWriteMove");let a=`module ${e.name}::genesis {
|
|
466
|
+
use std::ascii::string;
|
|
467
|
+
|
|
468
|
+
use sui::clock::Clock;
|
|
469
|
+
|
|
470
|
+
use ${e.name}::dapp_system;
|
|
471
|
+
|
|
472
|
+
public entry fun run(clock: &Clock, ctx: &mut TxContext) {
|
|
473
|
+
// Create a dapp.
|
|
474
|
+
let mut dapp = dapp_system::create(string(b"${e.name}"),string(b"${e.description}"), clock , ctx);
|
|
475
|
+
// Create schemas
|
|
476
|
+
let mut schema = ${e.name}::schema::create(ctx);
|
|
477
|
+
// Logic that needs to be automated once the contract is deployed
|
|
478
|
+
${e.name}::deploy_hook::run(&mut schema, ctx);
|
|
479
|
+
// Authorize schemas and public share objects
|
|
480
|
+
dapp.add_schema(schema);
|
|
481
|
+
sui::transfer::public_share_object(dapp);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
`;await c(a,`${t}/contracts/${e.name}/sources/codegen/genesis.move`,"formatAndWriteMove"),console.log(`\u2705 Init Generation Complete
|
|
485
|
+
`)}async function lt(e,t,r){console.log(`
|
|
486
|
+
\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: ${r||"testnet"}`);let a=t??process.cwd();k(`${a}/contracts/${e.name}`)&&w(`${a}/contracts/${e.name}/sources/codegen`),k(`${a}/contracts/${e.name}/Move.toml`)||await G(e,a),k(`${a}/contracts/${e.name}/sources/script/deploy_hook.move`)||await L(e,a),e.events&&(e.data?await x(e.name,e.data,e.events,a):await x(e.name,null,e.events,a)),e.data?(await O(e.name,e.data,a),await v(e.name,e.data,e.schemas,a)):await v(e.name,null,e.schemas,a),e.errors&&await B(e.name,e.errors,a),await z(e,a),await H(e,a),await I(e,a),await F(e,a),console.log(`\u2705 Schema Generation Process Complete!
|
|
487
|
+
`)}import{findUp as pe}from"find-up";import C from"path";import ue from"esbuild";var h=class extends Error{name="NotInsideProjectError";message="You are not inside a Dubhe project"};import{rmSync as me}from"fs";import{pathToFileURL as de}from"url";import le from"os";var ge=["dubhe.config.js","dubhe.config.mjs","dubhe.config.ts","dubhe.config.mts"],A="dubhe.config.example.mjs";async function vt(e){e=await K(e);try{return await ue.build({entryPoints:[e],format:"esm",outfile:A,platform:"node",bundle:!0,packages:"external"}),e=await K(A,!0),(await import(e+`?update=${Date.now()}`)).dubheConfig}finally{me(A,{force:!0})}}async function K(e,t){return e===void 0?e=await fe():C.isAbsolute(e)||(e=C.join(process.cwd(),e),e=C.normalize(e)),t&&le.platform()==="win32"?de(e).href:e}async function fe(){let e=await pe(ge);if(e===void 0)throw new h;return e}var Q=e=>{if(typeof e!="object"||e===null)return e;let t={};for(let r in e)if(e.hasOwnProperty(r)){let a=e[r];typeof a=="object"&&a!==null&&!Array.isArray(a)?a.hasOwnProperty("variant")?t[r]=a.variant:a.hasOwnProperty("fields")?t[r]=Q(a.fields):t[r]=Q(a):t[r]=a}return t};export{c as formatAndWriteMove,Ce as formatAndWriteTypescript,M as formatMove,T as formatTypescript,vt as loadConfig,Q as parseData,Me as posixPath,K as resolveConfigPath,lt as schemaGen};
|
|
501
488
|
//# 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/generateEvent.ts","../src/codegen/utils/renderMove/generateSystem.ts","../src/codegen/utils/renderMove/generateError.ts","../src/codegen/utils/renderMove/generateDefaultSchema.ts","../src/codegen/utils/renderMove/generateInit.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: Apache-2.0\n #[allow(unused_use)]\n \n /* Autogenerated file. Do not edit manually. */\n \n `\n\n let initPrefix = `#[test_only]`\n\n let code = schemaPrefix + formattedOutput\n\n let deployHookPrefix = `#[allow(lint(share_owned), unused_let_mut)]`\n\n if (fullOutputPath.includes(\".toml\") || fullOutputPath.includes(\"system\") || fullOutputPath.includes(\"migrate\")) {\n code = formattedOutput\n } else if (fullOutputPath.includes(\"init\")) {\n code = initPrefix + 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';\nimport { generateSchemaError } from './generateError';\nimport {generateDefaultSchema} from \"./generateDefaultSchema\";\nimport {generateInit} from \"./generateInit\";\n\nexport async function schemaGen(\n config: DubheConfig,\n srcPrefix?: string,\n network?: 'mainnet' | 'testnet' | 'devnet' | 'localnet'\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\n const path = srcPrefix ?? process.cwd();\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);\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 if (config.events) {\n if (config.data) {\n await generateSchemaEvent(config.name, config.data, config.events, path);\n } else {\n await generateSchemaEvent(config.name, null, config.events, path);\n }\n }\n\n if (config.data) {\n await generateSchemaData(config.name, config.data, path);\n await generateSchemaStructure(config.name, config.data, config.schemas, path);\n } else {\n await generateSchemaStructure(config.name, null, config.schemas, path);\n }\n\n if (config.errors) {\n await generateSchemaError(config.name, config.errors, path);\n }\n\n await generateDefaultSchema(config, path);\n await generateInit(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) {\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 = \"1.0.0\"\nedition = \"2024\"\n\n[dependencies]\nSui = { git = \"https://github.com/MystenLabs/sui.git\", subdir = \"crates/sui-framework/packages/sui-framework\", rev = \"mainnet-v1.38.3\" }\nDubhe = { git = \"https://github.com/0xobelisk/dubhe-framework.git\", rev = \"dubhe-mainnet-v1.0.0\" }\n\n[addresses]\nsui = \"0x2\"\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, SchemaData, SchemaType} from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport {\n\tgetStructAttrsWithType,\n\tgetStructAttrs,\n\tgetStructTypes,\n\tgetStructAttrsQuery,\n} from './common';\n\nfunction sortByFirstLetter(arr: string[]): string[] {\n\treturn arr.sort((a, b) => {\n\t\tconst firstLetterA = a.charAt(0).toLowerCase();\n\t\tconst firstLetterB = b.charAt(0).toLowerCase();\n\n\t\tif (firstLetterA < firstLetterB) {\n\t\t\treturn -1;\n\t\t}\n\t\tif (firstLetterA > firstLetterB) {\n\t\t\treturn 1;\n\t\t}\n\t\treturn 0;\n\t});\n}\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\tdata: Record<string, SchemaData>,\n\tpath: string,\n) {\n\tconsole.log('\\n📦 Starting Schema Data Generation...');\n\tfor (const key of Object.keys(data)) {\n\t\t\t\tconst name = key;\n\t\t\t\tconst fields = data[key];\n\t\t\t\tconsole.log(\n\t\t\t\t\t` └─ Generating ${name} ${\n\t\t\t\t\t\tArray.isArray(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 = Object.keys(data)\n\t\t\t\t\t.filter(item => Array.isArray(data[item]))\n\t\t\t\t\t.map(item => item);\n\n\t\t\tconsole.log(enumNames)\n\n\t\t\t\tif (Array.isArray(fields)) {\n\t\t\t\t\tconst sortByFirstLetterFields = sortByFirstLetter(fields);\n\t\t\t\t\tcode = `module ${projectName}::${convertToSnakeCase(\n\t\t\t\t\t\tname,\n\t\t\t\t\t)} {\n public enum ${name} has copy, drop , store {\n ${sortByFirstLetterFields}\n }\n \n ${sortByFirstLetterFields\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)}(): ${name} {\n ${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}::${convertToSnakeCase(\n\t\t\t\t\t\tname,\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}::${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 ${name} has copy, drop , store {\n ${getStructAttrsWithType(fields)}\n }\n \n public fun new(${getStructAttrsWithType(\n\t\t\t\t\t\tfields,\n\t\t\t\t\t)}): ${name} {\n ${name} {\n ${getStructAttrs(fields)}\n }\n }\n \n ${renderGetAllFunc(name, fields)}\n ${renderGetAttrsFunc(name, fields)}\n ${renderSetAttrsFunc(name, fields)}\n ${renderSetFunc(name, 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/data/${convertToSnakeCase(\n\t\t\t\t\t\tname,\n\t\t\t\t\t)}.move`,\n\t\t\t\t\t'formatAndWriteMove',\n\t\t\t\t);\n\t\t\t}\n\tconsole.log('✅ Schema Data Generation Complete\\n');\n}\n\nfunction generateImport(\n\tprojectName: string,\n\tdata: Record<string, SchemaData> | null,\n) {\n\tif (data != null) {\n\t\tconst names = Object.keys(data);\n\t\treturn names\n\t\t\t.map(name => {\n\t\t\t\treturn `use ${projectName}::${convertToSnakeCase(\n\t\t\t\t\tname,\n\t\t\t\t)}::${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\tdata: Record<string, SchemaData> | null,\n\tschemas: Record<string, SchemaType>,\n\tpath: string,\n) {\n\tconsole.log('\\n🔨 Starting Schema Structure Generation...');\n\t\tconsole.log(\n\t\t\t` ├─ Output path: ${path}/contracts/${projectName}/sources/codegen/schema.move`,\n\t\t);\n\t\tconsole.log(\n\t\t\t` └─ Structure fields: ${\n\t\t\t\tObject.values(schemas).length\n\t\t\t}`,\n\t\t);\n\t\tconst schemaMoudle = `module ${projectName}::schema {\n use std::ascii::String;\n use std::ascii::string;\n use sui::package::UpgradeCap;\n use std::type_name; \n use dubhe::storage;\n use dubhe::storage_value::{Self, StorageValue};\n use dubhe::storage_map::{Self, StorageMap};\n use dubhe::storage_double_map::{Self, StorageDoubleMap};\n use sui::dynamic_field as df;\n \n ${generateImport(projectName, data)}\n\n public struct Schema has key, store { id: UID } \n \n ${Object.entries(schemas)\n\t\t\t.map(([key, value]) => {\n\t\t\t\treturn `public fun borrow_${key}(self: &Schema) : &${value} {\n storage::borrow_field(&self.id, b\"${key}\")\n }\n \n public(package) fun ${key}(self: &mut Schema): &mut ${value} {\n storage::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): Schema {\n let mut id = object::new(ctx);\n ${Object.entries(schemas)\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(b\"${key}\", ctx)`;\n\t\t\t\t} else if (value.includes('StorageMap')) {\n\t\t\t\t\tstorage_type = `storage_map::new(b\"${key}\", ctx)`;\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(b\"${key}\", ctx)`;\n\t\t\t\t}\n\t\t\t\treturn `storage::add_field<${value}>(&mut id, b\"${key}\", ${storage_type});`;\n\t\t\t})\n\t\t\t.join('\\n')}\n \n Schema { id }\n }\n \n public fun migrate(_schema: &mut Schema, _cap: &UpgradeCap, _ctx: &mut TxContext) { }\n\n \n // ======================================== View Functions ========================================\n ${Object.entries(schemas)\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\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 = '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 = 'get(key)';\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 = 'get(key1, key2)';\n\t\t\t\t}\n\t\t\t\treturn `public fun get_${key}(self: &Schema, ${para_key}) : &${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}).join('\\n')}\n // =========================================================================================================\n\t\t\t}`\n\t\tawait formatAndWriteMove(\n\t\t\tschemaMoudle,\n\t\t\t`${path}/contracts/${projectName}/sources/codegen/schema.move`,\n\t\t\t'formatAndWriteMove',\n\t\t);\n\t\tconsole.log('✅ Schema Structure Generation Complete\\n');\n}\n\n","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport { existsSync } from 'fs';\nimport { capitalizeAndRemoveUnderscores } from './generateSchema';\n\nimport { readFileSync } from 'fs';\n\nexport function extractLogicAndAuthorizationContent(filePath: string): string {\n\tconst fileContent = readFileSync(filePath, 'utf-8');\n\tconst logicAndAuthRegex = /\\/\\/ Logic that needs to be automated once the contract is deployed\\s*\\{([\\s\\S]*?)\\}\\s*;\\s*\\/\\/ Authorize schemas and public share objects/;\n\tconst match = fileContent.match(logicAndAuthRegex);\n\n\tif (match) {\n\t\treturn match[1].trim();\n\t} else {\n\t\tthrow new Error('Logic and authorization block not found in the file.');\n\t}\n}\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/scripts/deploy_hook.move`\n\t);\n\n\tconst schemas = Object.keys(config.schemas).map(schemaName => { return `_${schemaName}: &mut ${capitalizeAndRemoveUnderscores(schemaName)}`}).join(',')\n\tconst importSchemas = Object.keys(config.schemas).map(schemaName => { return `use ${config.name}::${schemaName}_schema::${capitalizeAndRemoveUnderscores(schemaName)};`}).join('\\n')\n\tconst path = `${srcPrefix}/contracts/${config.name}/sources/scripts/deploy_hook.move`;\n\tlet code = '';\n\tif (!existsSync(path)) {\n\t\tcode = `module ${config.name}::deploy_hook {\n\t\t\tuse std::ascii::string;\n\t\t\tuse sui::clock::Clock;\n\t\t\tuse ${config.name}::dapp_system;\n\t\t public entry fun run(clock: &Clock, ctx: &mut TxContext) {\n\t\t // Create a dapp.\n \t let mut dapp = dapp_system::create(string(b\"${config.name}\"),string(b\"${config.description}\"), clock , ctx);\n \n\t\t // Create schemas\n\t\tlet mut schema = ${config.name}::schema::create(ctx);\n\t\t\t// Logic that needs to be automated once the contract is deployed\n\t\t\t{\n\t\t\t};\n\t\t\t// Authorize schemas and public share objects\n\t\t\t dapp.add_schema(schema);\n\t\t\t sui::transfer::public_share_object(dapp);\n\t\t }\n}` } else {\n\t\tconst content = extractLogicAndAuthorizationContent(path);\n\t\tcode = `module ${config.name}::deploy_hook {\n\t\t\tuse std::ascii::string;\n\t\t\tuse sui::clock::Clock;\n\t\t\tuse ${config.name}::dapp_system;\n\t\t public entry fun run(clock: &Clock, ctx: &mut TxContext) {\n\t\t // Create a dapp.\n \t let mut dapp = dapp_system::create(string(b\"${config.name}\"),string(b\"${config.description}\"), clock , ctx);\n \n\t\t // Create schemas\n\t\t\tlet mut schema = ${config.name}::schema::create(ctx);\n\t\t\t// Logic that needs to be automated once the contract is deployed\n\t\t\t\n\t\t\t{\n\t\t\t${content}\n\t\t\t};\n\t\t\t\n\t\t\t// Authorize schemas and public share objects\n\t\t\t dapp.add_schema(schema);\n\t\t\t sui::transfer::public_share_object(dapp);\n\t\t }\n}`\n\t}\n\tawait formatAndWriteMove(\n\t\tcode,\n\t\tpath,\n\t\t'formatAndWriteMove'\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/scripts/migrate.move`\n\t\t)\n\t) {\n\t\tlet code = `module ${config.name}::migrate {\n const ON_CHAIN_VERSION: u32 = 1;\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/scripts/migrate.move`,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n}\n","import {BaseType, EventData, SchemaData, 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\nfunction generateImport(\n\tprojectName: string,\n\tdata: Record<string, SchemaData> | null,\n) {\n\tif (data != null) {\n\t\tconst names = Object.keys(data);\n\t\treturn names\n\t\t\t.map(name => {\n\t\t\t\treturn `use ${projectName}::${convertToSnakeCase(\n\t\t\t\t\tname,\n\t\t\t\t)}::${name};`;\n\t\t\t})\n\t\t\t.join('\\n');\n\t} else {\n\t\treturn '';\n\t}\n}\n\nexport async function generateSchemaEvent(\n\tprojectName: string,\n\tdata: Record<string, SchemaData> | null,\n\tevents: Record<string, EventData>,\n\tpath: string\n) {\n\tconsole.log('\\n📦 Starting Schema Event Generation...');\n\tfor (const key of Object.keys(events)) {\n\t\t\t\tconst name = key;\n\t\t\t\tconst fields = events[key];\n\t\t\t\tconsole.log(\n\t\t\t\t\t` └─ Generating ${name} event: ${fields}`\n\t\t\t\t);\n\n\t\t\t\tlet\tcode = `module ${projectName}::${convertToSnakeCase(name)}_event {\n\t\t\t\t\t\tuse sui::event;\n\t\t\t\t\t\tuse std::ascii::String;\n\t\t\t\t\t\t${generateImport(projectName, data)}\n\n public struct ${name}Event has copy, drop {\n ${getStructAttrsWithType(fields as Record<string, string>)}\n }\n\n public fun new(${getStructAttrsWithType(fields as Record<string, string>)}): ${name}Event {\n ${name}Event {\n ${getStructAttrs(fields as Record<string, string>)}\n }\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/data/${convertToSnakeCase(\n\t\t\t\t\t\tname\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\n\tlet\tcode = `module ${projectName}::events {\n\t \tuse std::ascii::{String, string};\n\t \t${generateImport(projectName, data)}\n\t\t${Object.entries(events).map(([name, fields]) => {\n\t\treturn `\nuse ${projectName}::${convertToSnakeCase(name)}_event::${name}Event;\nuse ${projectName}::${convertToSnakeCase(name)}_event;\n\t\t\tpublic fun ${convertToSnakeCase(name)}_event(${getStructAttrsWithType(fields as Record<string, string>)}) {\n\t\t\t dubhe::storage_event::emit_set_record<${name}Event, ${name}Event, ${name}Event>(\n\t\t\t\tstring(b\"${convertToSnakeCase(name)}_event\"),\n\t\t\t\toption::none(),\n\t\t\t \toption::none(),\n\t\t\t option::some(${convertToSnakeCase(name)}_event::new(${getStructAttrs(fields as Record<string, string>)}))\n\t\t\t )\n\t\t\t}\n\t\t`\n\t}).join('\\n')}\t\t\n }`\n\n\n\tawait formatAndWriteMove(\n\t\tcode,\n\t\t`${path}/contracts/${projectName}/sources/codegen/events.move`,\n\t\t'formatAndWriteMove'\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 {BaseType, ErrorData, SchemaType} from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport {\n\tgetStructAttrsWithType,\n\tgetStructAttrs,\n\tgetStructTypes,\n\tgetStructAttrsQuery,\n} from './common';\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 generateSchemaError(\n\tprojectName: string,\n\terrors: ErrorData,\n\tpath: string\n) {\n\tconsole.log('\\n📦 Starting Schema Error Generation...');\n\n\tlet\tcode = `module ${projectName}::errors {\n\t\t${Object.entries(errors).map(([name, message]) => {\n\t\t\tconsole.log(` ├─ Generating Error: ${name}`);\n\t\tconsole.log(` │ └─ Message: ${message}`);\n\t\treturn `#[error]\n\t\t\t\tconst ${name}: vector<u8> = b\"${message}\";\n\t\t\t\tpublic fun ${convertToSnakeCase(name)}_error(condition: bool) { assert!(condition, ${name}) }\n\t\t`\n\t}).join('\\n')}\t\t\n }`\n\n\n\tawait formatAndWriteMove(\n\t\tcode,\n\t\t`${path}/contracts/${projectName}/sources/codegen/errors.move`,\n\t\t'formatAndWriteMove'\n\t);\n\tconsole.log('✅ Schema Error Generation Complete\\n');\n}","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport { existsSync } from 'fs';\nimport { capitalizeAndRemoveUnderscores } from './generateSchema';\n\nexport async function generateDefaultSchema(\n\tconfig: DubheConfig,\n\tsrcPrefix: string\n) {\n\tawait generateDappSchemaMetadata(config, srcPrefix);\n\tawait generateDappSchema(config, srcPrefix);\n\tawait generateDappSystem(config, srcPrefix);\n}\n\nasync function generateDappSchemaMetadata(config: DubheConfig, srcPrefix: string) {\n\tconst path = `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp/metadata.move`\n\tif (!existsSync(path)) {\n\t\tlet code = `module ${config.name}::dapp_metadata {\n use std::ascii::String;\n\n public struct DappMetadata has drop, copy, store {\n name: String,\n description: String,\n icon_url: String,\n website_url: String,\n created_at: u64,\n partners: vector<String>,\n }\n\n public fun new(\n name: String,\n description: String,\n icon_url: String,\n website_url: String,\n created_at: u64,\n partners: vector<String>,\n ): DappMetadata {\n DappMetadata {\n name,\n description,\n icon_url,\n website_url,\n created_at,\n partners,\n }\n }\n\n public fun set(\n self: &mut DappMetadata,\n name: String,\n description: String,\n icon_url: String,\n website_url: String,\n created_at: u64,\n partners: vector<String>,\n ) {\n self.name = name;\n self.description = description;\n self.icon_url = icon_url;\n self.website_url = website_url;\n self.created_at = created_at;\n self.partners = partners;\n }\n\n public fun set_name(self: &mut DappMetadata, name: String) {\n self.name = name;\n }\n\n public fun set_description(self: &mut DappMetadata, description: String) {\n self.description = description;\n }\n\n public fun set_icon_url(self: &mut DappMetadata, icon_url: String) {\n self.icon_url = icon_url;\n }\n\n public fun set_website_url(self: &mut DappMetadata, website_url: String) {\n self.website_url = website_url;\n }\n\n public fun set_created_at(self: &mut DappMetadata, created_at: u64) {\n self.created_at = created_at;\n }\n\n public fun set_partners(self: &mut DappMetadata, partners: vector<String>) {\n self.partners = partners;\n }\n\n public fun get_name(self: DappMetadata): String {\n self.name\n }\n\n public fun get_description(self: DappMetadata): String {\n self.description\n }\n\n public fun get_icon_url(self: DappMetadata): String {\n self.icon_url\n }\n\n public fun get_website_url(self: DappMetadata): String {\n self.website_url\n }\n\n public fun get_created_at(self: DappMetadata): u64 {\n self.created_at\n }\n\n public fun get_partners(self: DappMetadata): vector<String> {\n self.partners\n }\n\n}\n`;\n\t\tawait formatAndWriteMove(\n\t\t\tcode,\n\t\t\tpath,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n}\n\n\nasync function generateDappSchema(config: DubheConfig, srcPrefix: string) {\n\tconst path = `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp/schema.move`\n\tif (!existsSync(path)) {\n\t\tlet code = `module ${config.name}::dapp_schema {\n use ${config.name}::dapp_metadata::DappMetadata;\n use dubhe::storage_value;\n use dubhe::storage_value::StorageValue;\n use dubhe::storage;\n use sui::transfer::public_share_object;\n use dubhe::type_info;\n \n public struct Dapp has key, store {\n id: UID,\n }\n\n public fun borrow_admin(self: &Dapp): &StorageValue<address> {\n storage::borrow_field(&self.id, b\"admin\")\n }\n\n public(package) fun admin(self: &mut Dapp): &mut StorageValue<address> {\n storage::borrow_mut_field(&mut self.id, b\"admin\")\n }\n\n public fun borrow_package_id(self: &Dapp): &StorageValue<address> {\n storage::borrow_field(&self.id, b\"package_id\")\n }\n\n public(package) fun package_id(self: &mut Dapp): &mut StorageValue<address> {\n storage::borrow_mut_field(&mut self.id, b\"package_id\")\n }\n\n public fun borrow_version(self: &Dapp): &StorageValue<u32> {\n storage::borrow_field(&self.id, b\"version\")\n }\n\n public(package) fun version(self: &mut Dapp): &mut StorageValue<u32> {\n storage::borrow_mut_field(&mut self.id, b\"version\")\n }\n\n public fun borrow_metadata(self: &Dapp): &StorageValue<DappMetadata> {\n storage::borrow_field(&self.id, b\"metadata\")\n }\n\n public(package) fun metadata(self: &mut Dapp): &mut StorageValue<DappMetadata> {\n storage::borrow_mut_field(&mut self.id, b\"metadata\")\n }\n\n public fun borrow_safe_mode(self: &Dapp): &StorageValue<bool> {\n storage::borrow_field(&self.id, b\"safe_mode\")\n }\n\n public(package) fun safe_mode(self: &mut Dapp): &mut StorageValue<bool> {\n storage::borrow_mut_field(&mut self.id, b\"safe_mode\")\n }\n \n public(package) fun borrow_schemas(self: &Dapp): &StorageValue<vector<address>> {\n storage::borrow_field(&self.id, b\"schemas\")\n }\n\n public(package) fun schemas(self: &mut Dapp): &mut StorageValue<vector<address>> {\n storage::borrow_mut_field(&mut self.id, b\"schemas\")\n }\n\n\n public(package) fun create(ctx: &mut TxContext): Dapp {\n let mut id = object::new(ctx);\n storage::add_field<StorageValue<address>>(&mut id, b\"admin\", storage_value::new(b\"admin\", ctx));\n storage::add_field<StorageValue<address>>(&mut id, b\"package_id\", storage_value::new(b\"package_id\", ctx));\n storage::add_field<StorageValue<u32>>(&mut id, b\"version\", storage_value::new(b\"version\", ctx));\n storage::add_field<StorageValue<DappMetadata>>(&mut id, b\"metadata\", storage_value::new(b\"metadata\", ctx));\n storage::add_field<StorageValue<bool>>(&mut id, b\"safe_mode\", storage_value::new(b\"safe_mode\", ctx));\n storage::add_field<StorageValue<vector<address>>>(&mut id, b\"schemas\", storage_value::new(b\"schemas\", ctx));\n Dapp { id }\n }\n\n public(package) fun upgrade<DappKey: drop>(dapp: &mut Dapp, ctx: &TxContext) {\n assert!(dapp.borrow_metadata().contains(), 0);\n assert!(dapp.borrow_admin().get() == ctx.sender(), 0);\n let new_package_id = type_info::current_package_id<DappKey>();\n dapp.package_id().set(new_package_id);\n let current_version = dapp.version()[];\n dapp.version().set(current_version + 1);\n }\n \n public(package) fun add_schema<Schema: key + store>(dapp: &mut Dapp, schema: Schema) {\n let mut schemas = dapp.schemas()[];\n schemas.push_back(object::id_address<Schema>(&schema));\n dapp.schemas().set(schemas);\n public_share_object(schema);\n }\n\n #[test_only]\n\n public fun create_dapp_for_testing(ctx: &mut TxContext): Dapp {\n create(ctx)\n }\n\n #[test_only]\n\n public fun distroy_dapp_for_testing(dapp: Dapp) {\n let Dapp { id } = dapp;\n id.delete();\n }\n}\n`;\n\t\tawait formatAndWriteMove(\n\t\t\tcode,\n\t\t\tpath,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n}\n\nasync function generateDappSystem(config: DubheConfig, srcPrefix: string) {\n\tconst path = `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp/system.move`\n\tif (!existsSync(path)) {\n\t\tlet code = `module ${config.name}::dapp_system {\n use std::ascii::String;\n use std::ascii;\n use dubhe::type_info;\n use sui::clock::Clock;\n use ${config.name}::dapp_schema;\n use ${config.name}::dapp_metadata;\n use ${config.name}::dapp_schema::Dapp;\n \n public struct DappKey has drop {}\n public(package) fun new(): DappKey {\n DappKey { }\n }\n\n public(package) fun create(name: String, description: String, clock: &Clock, ctx: &mut TxContext): Dapp {\n let mut dapp = dapp_schema::create(ctx);\n assert!(!dapp.borrow_metadata().contains(), 0);\n dapp.metadata().set(\n dapp_metadata::new(\n name,\n description,\n ascii::string(b\"\"),\n ascii::string(b\"\"),\n clock.timestamp_ms(),\n vector[]\n )\n );\n let package_id = type_info::current_package_id<DappKey>();\n dapp.package_id().set(package_id);\n dapp.admin().set(ctx.sender());\n dapp.version().set(1);\n dapp.safe_mode().set(false);\n dapp.schemas().set(vector[]);\n dapp\n }\n\n public entry fun set_metadata(\n dapp: &mut Dapp,\n name: String,\n description: String,\n icon_url: String,\n website_url: String,\n partners: vector<String>,\n ctx: &TxContext,\n ) {\n let admin = dapp.admin().try_get();\n assert!(admin == option::some(ctx.sender()), 0);\n let created_at = dapp.metadata().remove().get_created_at();\n dapp.metadata().set(\n dapp_metadata::new(\n name,\n description,\n icon_url,\n website_url,\n created_at,\n partners\n )\n );\n }\n\n public entry fun transfer_ownership(dapp: &mut Dapp, new_admin: address, ctx: &mut TxContext) {\n let admin = dapp.admin().try_get();\n assert!(admin == option::some(ctx.sender()), 0);\n dapp.admin().set(new_admin);\n }\n\n public entry fun set_safe_mode(dapp: &mut Dapp, safe_mode: bool, ctx: &TxContext) {\n let admin = dapp.admin().try_get();\n assert!(admin == option::some(ctx.sender()), 0);\n dapp.safe_mode().set(safe_mode);\n }\n\n public fun ensure_no_safe_mode(dapp: &Dapp) {\n assert!(!dapp.borrow_safe_mode()[], 0);\n }\n\n public fun ensure_has_authority(dapp: &Dapp, ctx: &TxContext) {\n assert!(dapp.borrow_admin().get() == ctx.sender(), 0);\n }\n\n public fun ensure_has_schema<Schema: key + store>(dapp: &Dapp, schema: &Schema) {\n let schema_id = object::id_address(schema);\n assert!(dapp.borrow_schemas().get().contains(&schema_id), 0);\n }\n}\n\n\n`;\n\t\tawait formatAndWriteMove(\n\t\t\tcode,\n\t\t\tpath,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n}","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport { existsSync } from 'fs';\nimport { capitalizeAndRemoveUnderscores } from './generateSchema';\n\nexport async function generateInit(\n\tconfig: DubheConfig,\n\tsrcPrefix: string\n) {\n\tconsole.log('\\n📝 Starting Init Generation...');\n\tconsole.log(\n\t\t` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/tests/init.move`\n\t);\n\n\t\tlet code = `module ${config.name}::init_test {\n use ${config.name}::dapp_schema::Dapp;\n use sui::clock;\n use sui::test_scenario;\n use sui::test_scenario::Scenario;\n \n public fun deploy_dapp_for_testing(sender: address): (Scenario, Dapp) {\n let mut scenario = test_scenario::begin(sender);\n let ctx = test_scenario::ctx(&mut scenario);\n let clock = clock::create_for_testing(ctx);\n ${config.name}::deploy_hook::run(&clock, ctx);\n clock::destroy_for_testing(clock);\n test_scenario::next_tx(&mut scenario,sender);\n let dapp = test_scenario::take_shared<Dapp>(&scenario);\n (scenario, dapp)\n }\n}\n`;\n\t\tawait formatAndWriteMove(\n\t\t\tcode,\n\t\t\t`${srcPrefix}/contracts/${config.name}/sources/tests/init.move`,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\n\tconsole.log('✅ Deploy Hook Generation Complete\\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,QAE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,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","initPrefix","code","deployHookPrefix","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","code","formatAndWriteMove","sortByFirstLetter","arr","a","b","firstLetterA","firstLetterB","capitalizeAndRemoveUnderscores","input","word","index","renderSetAttrsFunc","schemaName","fields","key","type","renderSetFunc","getStructAttrsWithType","fieldName","renderGetAllFunc","getStructTypes","getStructAttrsQuery","renderGetAttrsFunc","convertToSnakeCase","generateSchemaData","projectName","data","path","name","code","enumNames","item","sortByFirstLetterFields","field","getStructAttrs","formatAndWriteMove","generateImport","generateSchemaStructure","schemas","schemaMoudle","value","storage_type","all_types","para_key","para_value","borrow_key","existsSync","readFileSync","extractLogicAndAuthorizationContent","filePath","fileContent","logicAndAuthRegex","match","generateDeployHook","config","srcPrefix","schemas","schemaName","capitalizeAndRemoveUnderscores","importSchemas","path","code","existsSync","content","formatAndWriteMove","generateMigrate","convertToSnakeCase","input","generateImport","projectName","data","name","generateSchemaEvent","events","path","key","fields","code","getStructAttrsWithType","getStructAttrs","formatAndWriteMove","existsSync","fs","generateSystem","config","srcPrefix","convertToSnakeCase","input","generateSchemaError","projectName","errors","path","code","name","message","formatAndWriteMove","existsSync","generateDefaultSchema","config","srcPrefix","generateDappSchemaMetadata","generateDappSchema","generateDappSystem","path","code","formatAndWriteMove","generateInit","config","srcPrefix","code","formatAndWriteMove","schemaGen","config","srcPrefix","network","path","existsSync","deleteFolderRecursive","generateToml","generateDeployHook","generateSchemaEvent","generateSchemaData","generateSchemaStructure","generateSchemaError","generateDefaultSchema","generateInit","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/generateEvent.ts","../src/codegen/utils/renderMove/generateSystem.ts","../src/codegen/utils/renderMove/generateError.ts","../src/codegen/utils/renderMove/generateDefaultSchema.ts","../src/codegen/utils/renderMove/generateInit.ts","../src/codegen/utils/config.ts","../src/codegen/utils/errors.ts","../src/parseData/parser/index.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: Apache-2.0\n #[allow(unused_use)]\n \n /* Autogenerated file. Do not edit manually. */\n \n `\n\n let initPrefix = `#[test_only]`\n\n let code = schemaPrefix + formattedOutput\n\n let deployHookPrefix = `#[allow(lint(share_owned))]`\n\n if (fullOutputPath.includes(\".toml\") || fullOutputPath.includes(\"system\") || fullOutputPath.includes(\"migrate\")) {\n code = formattedOutput\n } else if (fullOutputPath.includes(\"init\")) {\n code = initPrefix + formattedOutput\n } else if (fullOutputPath.includes(\"genesis\")) {\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';\nimport { generateSchemaError } from './generateError';\nimport {generateDefaultSchema} from \"./generateDefaultSchema\";\nimport {generateInit} from \"./generateInit\";\n\nexport async function schemaGen(\n config: DubheConfig,\n srcPrefix?: string,\n network?: 'mainnet' | 'testnet' | 'devnet' | 'localnet'\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\n const path = srcPrefix ?? process.cwd();\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);\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 if (config.events) {\n if (config.data) {\n await generateSchemaEvent(config.name, config.data, config.events, path);\n } else {\n await generateSchemaEvent(config.name, null, config.events, path);\n }\n }\n\n if (config.data) {\n await generateSchemaData(config.name, config.data, path);\n await generateSchemaStructure(config.name, config.data, config.schemas, path);\n } else {\n await generateSchemaStructure(config.name, null, config.schemas, path);\n }\n\n if (config.errors) {\n await generateSchemaError(config.name, config.errors, path);\n }\n\n await generateDefaultSchema(config, path);\n await generateInit(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) {\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 = \"1.0.0\"\nedition = \"2024\"\n\n[dependencies]\nSui = { git = \"https://github.com/MystenLabs/sui.git\", subdir = \"crates/sui-framework/packages/sui-framework\", rev = \"mainnet-v1.38.3\" }\nDubhe = { git = \"https://github.com/0xobelisk/dubhe-framework.git\", rev = \"dubhe-mainnet-v1.1.0\" }\n\n[addresses]\nsui = \"0x2\"\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, SchemaData, SchemaType} from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport {\n\tgetStructAttrsWithType,\n\tgetStructAttrs,\n\tgetStructTypes,\n\tgetStructAttrsQuery,\n} from './common';\n\nfunction sortByFirstLetter(arr: string[]): string[] {\n\treturn arr.sort((a, b) => {\n\t\tconst firstLetterA = a.charAt(0).toLowerCase();\n\t\tconst firstLetterB = b.charAt(0).toLowerCase();\n\n\t\tif (firstLetterA < firstLetterB) {\n\t\t\treturn -1;\n\t\t}\n\t\tif (firstLetterA > firstLetterB) {\n\t\t\treturn 1;\n\t\t}\n\t\treturn 0;\n\t});\n}\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\tdata: Record<string, SchemaData>,\n\tpath: string,\n) {\n\tconsole.log('\\n📦 Starting Schema Data Generation...');\n\tfor (const key of Object.keys(data)) {\n\t\t\t\tconst name = key;\n\t\t\t\tconst fields = data[key];\n\t\t\t\tconsole.log(\n\t\t\t\t\t` └─ Generating ${name} ${\n\t\t\t\t\t\tArray.isArray(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 = Object.keys(data)\n\t\t\t\t\t.filter(item => Array.isArray(data[item]))\n\t\t\t\t\t.map(item => item);\n\n\t\t\tconsole.log(enumNames)\n\n\t\t\t\tif (Array.isArray(fields)) {\n\t\t\t\t\tconst sortByFirstLetterFields = sortByFirstLetter(fields);\n\t\t\t\t\tcode = `module ${projectName}::${convertToSnakeCase(\n\t\t\t\t\t\tname,\n\t\t\t\t\t)} {\n public enum ${name} has copy, drop , store {\n ${sortByFirstLetterFields}\n }\n \n ${sortByFirstLetterFields\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)}(): ${name} {\n ${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}::${convertToSnakeCase(\n\t\t\t\t\t\tname,\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}::${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 ${name} has copy, drop , store {\n ${getStructAttrsWithType(fields)}\n }\n \n public fun new(${getStructAttrsWithType(\n\t\t\t\t\t\tfields,\n\t\t\t\t\t)}): ${name} {\n ${name} {\n ${getStructAttrs(fields)}\n }\n }\n \n ${renderGetAllFunc(name, fields)}\n ${renderGetAttrsFunc(name, fields)}\n ${renderSetAttrsFunc(name, fields)}\n ${renderSetFunc(name, 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/data/${convertToSnakeCase(\n\t\t\t\t\t\tname,\n\t\t\t\t\t)}.move`,\n\t\t\t\t\t'formatAndWriteMove',\n\t\t\t\t);\n\t\t\t}\n\tconsole.log('✅ Schema Data Generation Complete\\n');\n}\n\nfunction generateImport(\n\tprojectName: string,\n\tdata: Record<string, SchemaData> | null,\n) {\n\tif (data != null) {\n\t\tconst names = Object.keys(data);\n\t\treturn names\n\t\t\t.map(name => {\n\t\t\t\treturn `use ${projectName}::${convertToSnakeCase(\n\t\t\t\t\tname,\n\t\t\t\t)}::${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\tdata: Record<string, SchemaData> | null,\n\tschemas: Record<string, SchemaType>,\n\tpath: string,\n) {\n\tconsole.log('\\n🔨 Starting Schema Structure Generation...');\n\t\tconsole.log(\n\t\t\t` ├─ Output path: ${path}/contracts/${projectName}/sources/codegen/schema.move`,\n\t\t);\n\t\tconsole.log(\n\t\t\t` └─ Structure fields: ${\n\t\t\t\tObject.values(schemas).length\n\t\t\t}`,\n\t\t);\n\t\tconst schemaMoudle = `module ${projectName}::schema {\n use std::ascii::String;\n use std::ascii::string;\n use sui::package::UpgradeCap;\n use std::type_name; \n use dubhe::storage;\n use dubhe::storage_value::{Self, StorageValue};\n use dubhe::storage_map::{Self, StorageMap};\n use dubhe::storage_double_map::{Self, StorageDoubleMap};\n use sui::dynamic_field as df;\n \n ${generateImport(projectName, data)}\n\n public struct Schema has key, store { id: UID } \n \n ${Object.entries(schemas)\n\t\t\t.map(([key, value]) => {\n\t\t\t\treturn `public fun borrow_${key}(self: &Schema) : &${value} {\n storage::borrow_field(&self.id, b\"${key}\")\n }\n \n public(package) fun ${key}(self: &mut Schema): &mut ${value} {\n storage::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): Schema {\n let mut id = object::new(ctx);\n ${Object.entries(schemas)\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(b\"${key}\", ctx)`;\n\t\t\t\t} else if (value.includes('StorageMap')) {\n\t\t\t\t\tstorage_type = `storage_map::new(b\"${key}\", ctx)`;\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(b\"${key}\", ctx)`;\n\t\t\t\t}\n\t\t\t\treturn `storage::add_field<${value}>(&mut id, b\"${key}\", ${storage_type});`;\n\t\t\t})\n\t\t\t.join('\\n')}\n \n Schema { id }\n }\n \n public fun migrate(_schema: &mut Schema, _cap: &UpgradeCap, _ctx: &mut TxContext) { }\n\n \n // ======================================== View Functions ========================================\n ${Object.entries(schemas)\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\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 = '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 = 'get(key)';\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 = 'get(key1, key2)';\n\t\t\t\t}\n\t\t\t\treturn `public fun get_${key}(self: &Schema, ${para_key}) : &${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}).join('\\n')}\n // =========================================================================================================\n\t\t\t}`\n\t\tawait formatAndWriteMove(\n\t\t\tschemaMoudle,\n\t\t\t`${path}/contracts/${projectName}/sources/codegen/schema.move`,\n\t\t\t'formatAndWriteMove',\n\t\t);\n\t\tconsole.log('✅ Schema Structure Generation Complete\\n');\n}\n\n","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport { existsSync } from 'fs';\nimport { capitalizeAndRemoveUnderscores } from './generateSchema';\n\nimport { readFileSync } from 'fs';\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/scripts/deploy_hook.move`\n\t);\n\n\tconst path = `${srcPrefix}/contracts/${config.name}/sources/scripts/deploy_hook.move`;\n\tif (!existsSync(path)) {\n\t\tconst code = `module ${config.name}::deploy_hook {\n\t\t\t use ${config.name}::schema::Schema;\n\n public(package) fun run(_schema: &mut Schema, _ctx: &mut TxContext) {\n\n }\n}`\n\t\tawait formatAndWriteMove(\n\t\t\tcode,\n\t\t\tpath,\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/scripts/migrate.move`\n\t\t)\n\t) {\n\t\tlet code = `module ${config.name}::migrate {\n const ON_CHAIN_VERSION: u32 = 1;\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/scripts/migrate.move`,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n}\n","import {BaseType, EventData, SchemaData, 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\nfunction generateImport(\n\tprojectName: string,\n\tdata: Record<string, SchemaData> | null,\n) {\n\tif (data != null) {\n\t\tconst names = Object.keys(data);\n\t\treturn names\n\t\t\t.map(name => {\n\t\t\t\treturn `use ${projectName}::${convertToSnakeCase(\n\t\t\t\t\tname,\n\t\t\t\t)}::${name};`;\n\t\t\t})\n\t\t\t.join('\\n');\n\t} else {\n\t\treturn '';\n\t}\n}\n\nexport async function generateSchemaEvent(\n\tprojectName: string,\n\tdata: Record<string, SchemaData> | null,\n\tevents: Record<string, EventData>,\n\tpath: string\n) {\n\tconsole.log('\\n📦 Starting Schema Event Generation...');\n\tfor (const key of Object.keys(events)) {\n\t\t\t\tconst name = key;\n\t\t\t\tconst fields = events[key];\n\t\t\t\tconsole.log(\n\t\t\t\t\t` └─ Generating ${name} event: ${fields}`\n\t\t\t\t);\n\n\t\t\t\tlet\tcode = `module ${projectName}::${convertToSnakeCase(name)}_event {\n\t\t\t\t\t\tuse sui::event;\n\t\t\t\t\t\tuse std::ascii::String;\n\t\t\t\t\t\t${generateImport(projectName, data)}\n\n public struct ${name}Event has copy, drop {\n ${getStructAttrsWithType(fields as Record<string, string>)}\n }\n\n public fun new(${getStructAttrsWithType(fields as Record<string, string>)}): ${name}Event {\n ${name}Event {\n ${getStructAttrs(fields as Record<string, string>)}\n }\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/data/${convertToSnakeCase(\n\t\t\t\t\t\tname\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\n\tlet\tcode = `module ${projectName}::events {\n\t \tuse std::ascii::{String, string};\n\t \t${generateImport(projectName, data)}\n\t\t${Object.entries(events).map(([name, fields]) => {\n\t\treturn `\nuse ${projectName}::${convertToSnakeCase(name)}_event::${name}Event;\nuse ${projectName}::${convertToSnakeCase(name)}_event;\n\t\t\tpublic fun ${convertToSnakeCase(name)}_event(${getStructAttrsWithType(fields as Record<string, string>)}) {\n\t\t\t dubhe::storage_event::emit_set_record<${name}Event, ${name}Event, ${name}Event>(\n\t\t\t\tstring(b\"${convertToSnakeCase(name)}_event\"),\n\t\t\t\toption::none(),\n\t\t\t \toption::none(),\n\t\t\t option::some(${convertToSnakeCase(name)}_event::new(${getStructAttrs(fields as Record<string, string>)}))\n\t\t\t )\n\t\t\t}\n\t\t`\n\t}).join('\\n')}\t\t\n }`\n\n\n\tawait formatAndWriteMove(\n\t\tcode,\n\t\t`${path}/contracts/${projectName}/sources/codegen/events.move`,\n\t\t'formatAndWriteMove'\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 {BaseType, ErrorData, SchemaType} from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport {\n\tgetStructAttrsWithType,\n\tgetStructAttrs,\n\tgetStructTypes,\n\tgetStructAttrsQuery,\n} from './common';\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 generateSchemaError(\n\tprojectName: string,\n\terrors: ErrorData,\n\tpath: string\n) {\n\tconsole.log('\\n📦 Starting Schema Error Generation...');\n\n\tlet\tcode = `module ${projectName}::errors {\n\t\t${Object.entries(errors).map(([name, message]) => {\n\t\t\tconsole.log(` ├─ Generating Error: ${name}`);\n\t\tconsole.log(` │ └─ Message: ${message}`);\n\t\treturn `#[error]\n\t\t\t\tconst ${name}: vector<u8> = b\"${message}\";\n\t\t\t\tpublic fun ${convertToSnakeCase(name)}_error(condition: bool) { assert!(condition, ${name}) }\n\t\t`\n\t}).join('\\n')}\t\t\n }`\n\n\n\tawait formatAndWriteMove(\n\t\tcode,\n\t\t`${path}/contracts/${projectName}/sources/codegen/errors.move`,\n\t\t'formatAndWriteMove'\n\t);\n\tconsole.log('✅ Schema Error Generation Complete\\n');\n}","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport { existsSync } from 'fs';\nimport { capitalizeAndRemoveUnderscores } from './generateSchema';\n\nexport async function generateDefaultSchema(\n\tconfig: DubheConfig,\n\tsrcPrefix: string\n) {\n\tawait generateDappSchemaMetadata(config, srcPrefix);\n\tawait generateDappSchema(config, srcPrefix);\n\tawait generateDappSystem(config, srcPrefix);\n}\n\nasync function generateDappSchemaMetadata(config: DubheConfig, srcPrefix: string) {\n\tconst path = `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp/metadata.move`\n\tif (!existsSync(path)) {\n\t\tlet code = `module ${config.name}::dapp_metadata {\n use std::ascii::String;\n\n public struct DappMetadata has drop, copy, store {\n name: String,\n description: String,\n icon_url: String,\n website_url: String,\n created_at: u64,\n partners: vector<String>,\n }\n\n public fun new(\n name: String,\n description: String,\n icon_url: String,\n website_url: String,\n created_at: u64,\n partners: vector<String>,\n ): DappMetadata {\n DappMetadata {\n name,\n description,\n icon_url,\n website_url,\n created_at,\n partners,\n }\n }\n\n public fun set(\n self: &mut DappMetadata,\n name: String,\n description: String,\n icon_url: String,\n website_url: String,\n created_at: u64,\n partners: vector<String>,\n ) {\n self.name = name;\n self.description = description;\n self.icon_url = icon_url;\n self.website_url = website_url;\n self.created_at = created_at;\n self.partners = partners;\n }\n\n public fun set_name(self: &mut DappMetadata, name: String) {\n self.name = name;\n }\n\n public fun set_description(self: &mut DappMetadata, description: String) {\n self.description = description;\n }\n\n public fun set_icon_url(self: &mut DappMetadata, icon_url: String) {\n self.icon_url = icon_url;\n }\n\n public fun set_website_url(self: &mut DappMetadata, website_url: String) {\n self.website_url = website_url;\n }\n\n public fun set_created_at(self: &mut DappMetadata, created_at: u64) {\n self.created_at = created_at;\n }\n\n public fun set_partners(self: &mut DappMetadata, partners: vector<String>) {\n self.partners = partners;\n }\n\n public fun get_name(self: &DappMetadata): String {\n self.name\n }\n\n public fun get_description(self: &DappMetadata): String {\n self.description\n }\n\n public fun get_icon_url(self: &DappMetadata): String {\n self.icon_url\n }\n\n public fun get_website_url(self: &DappMetadata): String {\n self.website_url\n }\n\n public fun get_created_at(self: &DappMetadata): u64 {\n self.created_at\n }\n\n public fun get_partners(self: &DappMetadata): vector<String> {\n self.partners\n }\n\n}\n`;\n\t\tawait formatAndWriteMove(\n\t\t\tcode,\n\t\t\tpath,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n}\n\n\nasync function generateDappSchema(config: DubheConfig, srcPrefix: string) {\n\tconst path = `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp/schema.move`\n\tif (!existsSync(path)) {\n\t\tlet code = `module ${config.name}::dapp_schema {\n use ${config.name}::dapp_metadata::DappMetadata;\n use dubhe::storage_value;\n use dubhe::storage_value::StorageValue;\n use dubhe::storage;\n use sui::transfer::public_share_object;\n use dubhe::type_info;\n \n public struct Dapp has key, store {\n id: UID,\n }\n\n public fun borrow_admin(self: &Dapp): &StorageValue<address> {\n storage::borrow_field(&self.id, b\"admin\")\n }\n\n public(package) fun admin(self: &mut Dapp): &mut StorageValue<address> {\n storage::borrow_mut_field(&mut self.id, b\"admin\")\n }\n\n public fun borrow_package_id(self: &Dapp): &StorageValue<address> {\n storage::borrow_field(&self.id, b\"package_id\")\n }\n\n public(package) fun package_id(self: &mut Dapp): &mut StorageValue<address> {\n storage::borrow_mut_field(&mut self.id, b\"package_id\")\n }\n\n public fun borrow_version(self: &Dapp): &StorageValue<u32> {\n storage::borrow_field(&self.id, b\"version\")\n }\n\n public(package) fun version(self: &mut Dapp): &mut StorageValue<u32> {\n storage::borrow_mut_field(&mut self.id, b\"version\")\n }\n\n public fun borrow_metadata(self: &Dapp): &StorageValue<DappMetadata> {\n storage::borrow_field(&self.id, b\"metadata\")\n }\n\n public(package) fun metadata(self: &mut Dapp): &mut StorageValue<DappMetadata> {\n storage::borrow_mut_field(&mut self.id, b\"metadata\")\n }\n\n public fun borrow_safe_mode(self: &Dapp): &StorageValue<bool> {\n storage::borrow_field(&self.id, b\"safe_mode\")\n }\n\n public(package) fun safe_mode(self: &mut Dapp): &mut StorageValue<bool> {\n storage::borrow_mut_field(&mut self.id, b\"safe_mode\")\n }\n \n public(package) fun borrow_schemas(self: &Dapp): &StorageValue<vector<address>> {\n storage::borrow_field(&self.id, b\"schemas\")\n }\n\n public(package) fun schemas(self: &mut Dapp): &mut StorageValue<vector<address>> {\n storage::borrow_mut_field(&mut self.id, b\"schemas\")\n }\n\n\n public(package) fun create(ctx: &mut TxContext): Dapp {\n let mut id = object::new(ctx);\n storage::add_field<StorageValue<address>>(&mut id, b\"admin\", storage_value::new(b\"admin\", ctx));\n storage::add_field<StorageValue<address>>(&mut id, b\"package_id\", storage_value::new(b\"package_id\", ctx));\n storage::add_field<StorageValue<u32>>(&mut id, b\"version\", storage_value::new(b\"version\", ctx));\n storage::add_field<StorageValue<DappMetadata>>(&mut id, b\"metadata\", storage_value::new(b\"metadata\", ctx));\n storage::add_field<StorageValue<bool>>(&mut id, b\"safe_mode\", storage_value::new(b\"safe_mode\", ctx));\n storage::add_field<StorageValue<vector<address>>>(&mut id, b\"schemas\", storage_value::new(b\"schemas\", ctx));\n Dapp { id }\n }\n\n public(package) fun upgrade<DappKey: drop>(dapp: &mut Dapp, ctx: &TxContext) {\n assert!(dapp.borrow_metadata().contains(), 0);\n assert!(dapp.borrow_admin().get() == ctx.sender(), 0);\n let new_package_id = type_info::current_package_id<DappKey>();\n dapp.package_id().set(new_package_id);\n let current_version = dapp.version()[];\n dapp.version().set(current_version + 1);\n }\n \n public(package) fun add_schema<Schema: key + store>(dapp: &mut Dapp, schema: Schema) {\n let mut schemas = dapp.schemas()[];\n schemas.push_back(object::id_address<Schema>(&schema));\n dapp.schemas().set(schemas);\n public_share_object(schema);\n }\n\n #[test_only]\n\n public fun create_dapp_for_testing(ctx: &mut TxContext): Dapp {\n create(ctx)\n }\n\n #[test_only]\n\n public fun distroy_dapp_for_testing(dapp: Dapp) {\n let Dapp { id } = dapp;\n id.delete();\n }\n}\n`;\n\t\tawait formatAndWriteMove(\n\t\t\tcode,\n\t\t\tpath,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n}\n\nasync function generateDappSystem(config: DubheConfig, srcPrefix: string) {\n\tconst path = `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp/system.move`\n\tif (!existsSync(path)) {\n\t\tlet code = `module ${config.name}::dapp_system {\n use std::ascii::String;\n use std::ascii;\n use dubhe::type_info;\n use sui::clock::Clock;\n use ${config.name}::dapp_schema;\n use ${config.name}::dapp_metadata;\n use ${config.name}::dapp_schema::Dapp;\n \n public struct DappKey has drop {}\n public(package) fun new(): DappKey {\n DappKey { }\n }\n\n public(package) fun create(name: String, description: String, clock: &Clock, ctx: &mut TxContext): Dapp {\n let mut dapp = dapp_schema::create(ctx);\n assert!(!dapp.borrow_metadata().contains(), 0);\n dapp.metadata().set(\n dapp_metadata::new(\n name,\n description,\n ascii::string(b\"\"),\n ascii::string(b\"\"),\n clock.timestamp_ms(),\n vector[]\n )\n );\n let package_id = type_info::current_package_id<DappKey>();\n dapp.package_id().set(package_id);\n dapp.admin().set(ctx.sender());\n dapp.version().set(1);\n dapp.safe_mode().set(false);\n dapp.schemas().set(vector[]);\n dapp\n }\n\n public entry fun set_metadata(\n dapp: &mut Dapp,\n name: String,\n description: String,\n icon_url: String,\n website_url: String,\n partners: vector<String>,\n ctx: &TxContext,\n ) {\n let admin = dapp.admin().try_get();\n assert!(admin == option::some(ctx.sender()), 0);\n let created_at = dapp.metadata().get().get_created_at();\n dapp.metadata().set(\n dapp_metadata::new(\n name,\n description,\n icon_url,\n website_url,\n created_at,\n partners\n )\n );\n }\n\n public entry fun transfer_ownership(dapp: &mut Dapp, new_admin: address, ctx: &mut TxContext) {\n let admin = dapp.admin().try_get();\n assert!(admin == option::some(ctx.sender()), 0);\n dapp.admin().set(new_admin);\n }\n\n public entry fun set_safe_mode(dapp: &mut Dapp, safe_mode: bool, ctx: &TxContext) {\n let admin = dapp.admin().try_get();\n assert!(admin == option::some(ctx.sender()), 0);\n dapp.safe_mode().set(safe_mode);\n }\n\n public fun ensure_no_safe_mode(dapp: &Dapp) {\n assert!(!dapp.borrow_safe_mode()[], 0);\n }\n\n public fun ensure_has_authority(dapp: &Dapp, ctx: &TxContext) {\n assert!(dapp.borrow_admin().get() == ctx.sender(), 0);\n }\n\n public fun ensure_has_schema<Schema: key + store>(dapp: &Dapp, schema: &Schema) {\n let schema_id = object::id_address(schema);\n assert!(dapp.borrow_schemas().get().contains(&schema_id), 0);\n }\n}\n\n\n`;\n\t\tawait formatAndWriteMove(\n\t\t\tcode,\n\t\t\tpath,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n}","import { DubheConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport { existsSync } from 'fs';\nimport { capitalizeAndRemoveUnderscores } from './generateSchema';\n\nexport async function generateInit(\n\tconfig: DubheConfig,\n\tsrcPrefix: string\n) {\n\tconsole.log('\\n📝 Starting Init Generation...');\n\tconsole.log(\n\t\t` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/tests/init.move`\n\t);\n\n\t\tlet init_test_code = `module ${config.name}::init_test {\n use ${config.name}::dapp_schema::Dapp;\n use sui::clock;\n use sui::test_scenario;\n use sui::test_scenario::Scenario;\n \n public fun deploy_dapp_for_testing(sender: address): (Scenario, Dapp) {\n let mut scenario = test_scenario::begin(sender);\n let ctx = test_scenario::ctx(&mut scenario);\n let clock = clock::create_for_testing(ctx);\n ${config.name}::genesis::run(&clock, ctx);\n clock::destroy_for_testing(clock);\n test_scenario::next_tx(&mut scenario,sender);\n let dapp = test_scenario::take_shared<Dapp>(&scenario);\n (scenario, dapp)\n }\n}\n`;\n\t\tawait formatAndWriteMove(\n\t\t\tinit_test_code,\n\t\t\t`${srcPrefix}/contracts/${config.name}/sources/tests/init.move`,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\n\tlet init_code = `module ${config.name}::genesis {\n use std::ascii::string;\n\n use sui::clock::Clock;\n\n use ${config.name}::dapp_system;\n\n public entry fun run(clock: &Clock, ctx: &mut TxContext) {\n // Create a dapp.\n let mut dapp = dapp_system::create(string(b\"${config.name}\"),string(b\"${config.description}\"), clock , ctx);\n // Create schemas\n let mut schema = ${config.name}::schema::create(ctx);\n // Logic that needs to be automated once the contract is deployed\n ${config.name}::deploy_hook::run(&mut schema, ctx);\n // Authorize schemas and public share objects\n dapp.add_schema(schema);\n sui::transfer::public_share_object(dapp);\n }\n}\n`;\n\tawait formatAndWriteMove(\n\t\tinit_code,\n\t\t`${srcPrefix}/contracts/${config.name}/sources/codegen/genesis.move`,\n\t\t'formatAndWriteMove'\n\t);\n\n\tconsole.log('✅ Init Generation Complete\\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}","export const parseData = (data: unknown) => {\n if (typeof data !== 'object' || data === null) {\n return data;\n }\n const parsedData: any = {};\n for (const key in data) {\n if (data.hasOwnProperty(key)) {\n // @ts-ignore\n const value = data[key];\n // console.log(\"===========\", value)\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n if (value.hasOwnProperty('variant')) {\n parsedData[key] = value.variant;\n } else if (value.hasOwnProperty('fields')) {\n parsedData[key] = parseData(value.fields);\n } else {\n parsedData[key] = parseData(value);\n }\n } else {\n parsedData[key] = value;\n }\n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AOE,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,CEnEO,IAAMG,EAAaC,GAAkB,CACxC,GAAI,OAAOA,GAAS,UAAYA,IAAS,KACrC,OAAOA,EAEX,IAAMC,EAAkB,CAAC,EACzB,QAAWC,KAAOF,EACd,GAAIA,EAAK,eAAeE,CAAG,EAAG,CAE1B,IAAMC,EAAQH,EAAKE,CAAG,EAElB,OAAOC,GAAU,UAAYA,IAAU,MAAQ,CAAC,MAAM,QAAQA,CAAK,EAC/DA,EAAM,eAAe,SAAS,EAC9BF,EAAWC,CAAG,EAAIC,EAAM,QACjBA,EAAM,eAAe,QAAQ,EACpCF,EAAWC,CAAG,EAAIH,EAAUI,EAAM,MAAM,EAExCF,EAAWC,CAAG,EAAIH,EAAUI,CAAK,EAGrCF,EAAWC,CAAG,EAAIC,EAI9B,OAAOF,CACX","names":["prettier","prettierPluginMove","formatMove","content","prettierConfigPath","config","error","message","formatTypescript","fs","path","createDebug","debug","error","debug","error","formatAndWriteMove","output","fullOutputPath","logPrefix","formattedOutput","formatMove","schemaPrefix","initPrefix","code","deployHookPrefix","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","code","formatAndWriteMove","sortByFirstLetter","arr","a","b","firstLetterA","firstLetterB","renderSetAttrsFunc","schemaName","fields","key","type","renderSetFunc","getStructAttrsWithType","fieldName","renderGetAllFunc","getStructTypes","getStructAttrsQuery","renderGetAttrsFunc","convertToSnakeCase","input","generateSchemaData","projectName","data","path","name","code","enumNames","item","sortByFirstLetterFields","sortByFirstLetter","field","getStructAttrs","formatAndWriteMove","generateImport","generateSchemaStructure","schemas","schemaMoudle","value","storage_type","all_types","para_key","para_value","borrow_key","existsSync","generateDeployHook","config","srcPrefix","path","code","formatAndWriteMove","generateMigrate","convertToSnakeCase","input","generateImport","projectName","data","name","generateSchemaEvent","events","path","key","fields","code","getStructAttrsWithType","getStructAttrs","formatAndWriteMove","existsSync","fs","generateSystem","config","srcPrefix","convertToSnakeCase","input","generateSchemaError","projectName","errors","path","code","name","message","formatAndWriteMove","existsSync","generateDefaultSchema","config","srcPrefix","generateDappSchemaMetadata","generateDappSchema","generateDappSystem","path","code","formatAndWriteMove","generateInit","config","srcPrefix","init_test_code","formatAndWriteMove","init_code","schemaGen","config","srcPrefix","network","path","existsSync","deleteFolderRecursive","generateToml","generateDeployHook","generateSchemaEvent","generateSchemaData","generateSchemaStructure","generateSchemaError","generateDefaultSchema","generateInit","generateSystem","generateMigrate","findUp","path","esbuild","NotInsideProjectError","rmSync","pathToFileURL","os","configFiles","TEMP_CONFIG","loadConfig","configPath","resolveConfigPath","esbuild","toFileURL","getUserConfigPath","path","tsConfigPath","findUp","NotInsideProjectError","parseData","data","parsedData","key","value"]}
|
package/package.json
CHANGED
|
@@ -22,13 +22,13 @@ export async function formatAndWriteMove(
|
|
|
22
22
|
|
|
23
23
|
let code = schemaPrefix + formattedOutput
|
|
24
24
|
|
|
25
|
-
let deployHookPrefix = `#[allow(lint(share_owned)
|
|
25
|
+
let deployHookPrefix = `#[allow(lint(share_owned))]`
|
|
26
26
|
|
|
27
27
|
if (fullOutputPath.includes(".toml") || fullOutputPath.includes("system") || fullOutputPath.includes("migrate")) {
|
|
28
28
|
code = formattedOutput
|
|
29
29
|
} else if (fullOutputPath.includes("init")) {
|
|
30
30
|
code = initPrefix + formattedOutput
|
|
31
|
-
} else if (fullOutputPath.includes("
|
|
31
|
+
} else if (fullOutputPath.includes("genesis")) {
|
|
32
32
|
code = deployHookPrefix + formattedOutput
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -86,27 +86,27 @@ async function generateDappSchemaMetadata(config: DubheConfig, srcPrefix: string
|
|
|
86
86
|
self.partners = partners;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
public fun get_name(self: DappMetadata): String {
|
|
89
|
+
public fun get_name(self: &DappMetadata): String {
|
|
90
90
|
self.name
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
public fun get_description(self: DappMetadata): String {
|
|
93
|
+
public fun get_description(self: &DappMetadata): String {
|
|
94
94
|
self.description
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
public fun get_icon_url(self: DappMetadata): String {
|
|
97
|
+
public fun get_icon_url(self: &DappMetadata): String {
|
|
98
98
|
self.icon_url
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
public fun get_website_url(self: DappMetadata): String {
|
|
101
|
+
public fun get_website_url(self: &DappMetadata): String {
|
|
102
102
|
self.website_url
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
public fun get_created_at(self: DappMetadata): u64 {
|
|
105
|
+
public fun get_created_at(self: &DappMetadata): u64 {
|
|
106
106
|
self.created_at
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
public fun get_partners(self: DappMetadata): vector<String> {
|
|
109
|
+
public fun get_partners(self: &DappMetadata): vector<String> {
|
|
110
110
|
self.partners
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -284,7 +284,7 @@ async function generateDappSystem(config: DubheConfig, srcPrefix: string) {
|
|
|
284
284
|
) {
|
|
285
285
|
let admin = dapp.admin().try_get();
|
|
286
286
|
assert!(admin == option::some(ctx.sender()), 0);
|
|
287
|
-
let created_at = dapp.metadata().
|
|
287
|
+
let created_at = dapp.metadata().get().get_created_at();
|
|
288
288
|
dapp.metadata().set(
|
|
289
289
|
dapp_metadata::new(
|
|
290
290
|
name,
|
|
@@ -12,7 +12,7 @@ export async function generateInit(
|
|
|
12
12
|
` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/tests/init.move`
|
|
13
13
|
);
|
|
14
14
|
|
|
15
|
-
let
|
|
15
|
+
let init_test_code = `module ${config.name}::init_test {
|
|
16
16
|
use ${config.name}::dapp_schema::Dapp;
|
|
17
17
|
use sui::clock;
|
|
18
18
|
use sui::test_scenario;
|
|
@@ -22,7 +22,7 @@ export async function generateInit(
|
|
|
22
22
|
let mut scenario = test_scenario::begin(sender);
|
|
23
23
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
24
24
|
let clock = clock::create_for_testing(ctx);
|
|
25
|
-
${config.name}::
|
|
25
|
+
${config.name}::genesis::run(&clock, ctx);
|
|
26
26
|
clock::destroy_for_testing(clock);
|
|
27
27
|
test_scenario::next_tx(&mut scenario,sender);
|
|
28
28
|
let dapp = test_scenario::take_shared<Dapp>(&scenario);
|
|
@@ -31,10 +31,36 @@ export async function generateInit(
|
|
|
31
31
|
}
|
|
32
32
|
`;
|
|
33
33
|
await formatAndWriteMove(
|
|
34
|
-
|
|
34
|
+
init_test_code,
|
|
35
35
|
`${srcPrefix}/contracts/${config.name}/sources/tests/init.move`,
|
|
36
36
|
'formatAndWriteMove'
|
|
37
37
|
);
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
let init_code = `module ${config.name}::genesis {
|
|
40
|
+
use std::ascii::string;
|
|
41
|
+
|
|
42
|
+
use sui::clock::Clock;
|
|
43
|
+
|
|
44
|
+
use ${config.name}::dapp_system;
|
|
45
|
+
|
|
46
|
+
public entry fun run(clock: &Clock, ctx: &mut TxContext) {
|
|
47
|
+
// Create a dapp.
|
|
48
|
+
let mut dapp = dapp_system::create(string(b"${config.name}"),string(b"${config.description}"), clock , ctx);
|
|
49
|
+
// Create schemas
|
|
50
|
+
let mut schema = ${config.name}::schema::create(ctx);
|
|
51
|
+
// Logic that needs to be automated once the contract is deployed
|
|
52
|
+
${config.name}::deploy_hook::run(&mut schema, ctx);
|
|
53
|
+
// Authorize schemas and public share objects
|
|
54
|
+
dapp.add_schema(schema);
|
|
55
|
+
sui::transfer::public_share_object(dapp);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
await formatAndWriteMove(
|
|
60
|
+
init_code,
|
|
61
|
+
`${srcPrefix}/contracts/${config.name}/sources/codegen/genesis.move`,
|
|
62
|
+
'formatAndWriteMove'
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
console.log('✅ Init Generation Complete\n');
|
|
40
66
|
}
|
|
@@ -5,18 +5,6 @@ import { capitalizeAndRemoveUnderscores } from './generateSchema';
|
|
|
5
5
|
|
|
6
6
|
import { readFileSync } from 'fs';
|
|
7
7
|
|
|
8
|
-
export function extractLogicAndAuthorizationContent(filePath: string): string {
|
|
9
|
-
const fileContent = readFileSync(filePath, 'utf-8');
|
|
10
|
-
const logicAndAuthRegex = /\/\/ Logic that needs to be automated once the contract is deployed\s*\{([\s\S]*?)\}\s*;\s*\/\/ Authorize schemas and public share objects/;
|
|
11
|
-
const match = fileContent.match(logicAndAuthRegex);
|
|
12
|
-
|
|
13
|
-
if (match) {
|
|
14
|
-
return match[1].trim();
|
|
15
|
-
} else {
|
|
16
|
-
throw new Error('Logic and authorization block not found in the file.');
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
8
|
export async function generateDeployHook(
|
|
21
9
|
config: DubheConfig,
|
|
22
10
|
srcPrefix: string
|
|
@@ -26,57 +14,21 @@ export async function generateDeployHook(
|
|
|
26
14
|
` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/scripts/deploy_hook.move`
|
|
27
15
|
);
|
|
28
16
|
|
|
29
|
-
const schemas = Object.keys(config.schemas).map(schemaName => { return `_${schemaName}: &mut ${capitalizeAndRemoveUnderscores(schemaName)}`}).join(',')
|
|
30
|
-
const importSchemas = Object.keys(config.schemas).map(schemaName => { return `use ${config.name}::${schemaName}_schema::${capitalizeAndRemoveUnderscores(schemaName)};`}).join('\n')
|
|
31
17
|
const path = `${srcPrefix}/contracts/${config.name}/sources/scripts/deploy_hook.move`;
|
|
32
|
-
let code = '';
|
|
33
18
|
if (!existsSync(path)) {
|
|
34
|
-
code = `module ${config.name}::deploy_hook {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
let mut dapp = dapp_system::create(string(b"${config.name}"),string(b"${config.description}"), clock , ctx);
|
|
41
|
-
|
|
42
|
-
// Create schemas
|
|
43
|
-
let mut schema = ${config.name}::schema::create(ctx);
|
|
44
|
-
// Logic that needs to be automated once the contract is deployed
|
|
45
|
-
{
|
|
46
|
-
};
|
|
47
|
-
// Authorize schemas and public share objects
|
|
48
|
-
dapp.add_schema(schema);
|
|
49
|
-
sui::transfer::public_share_object(dapp);
|
|
50
|
-
}
|
|
51
|
-
}` } else {
|
|
52
|
-
const content = extractLogicAndAuthorizationContent(path);
|
|
53
|
-
code = `module ${config.name}::deploy_hook {
|
|
54
|
-
use std::ascii::string;
|
|
55
|
-
use sui::clock::Clock;
|
|
56
|
-
use ${config.name}::dapp_system;
|
|
57
|
-
public entry fun run(clock: &Clock, ctx: &mut TxContext) {
|
|
58
|
-
// Create a dapp.
|
|
59
|
-
let mut dapp = dapp_system::create(string(b"${config.name}"),string(b"${config.description}"), clock , ctx);
|
|
60
|
-
|
|
61
|
-
// Create schemas
|
|
62
|
-
let mut schema = ${config.name}::schema::create(ctx);
|
|
63
|
-
// Logic that needs to be automated once the contract is deployed
|
|
64
|
-
|
|
65
|
-
{
|
|
66
|
-
${content}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// Authorize schemas and public share objects
|
|
70
|
-
dapp.add_schema(schema);
|
|
71
|
-
sui::transfer::public_share_object(dapp);
|
|
72
|
-
}
|
|
19
|
+
const code = `module ${config.name}::deploy_hook {
|
|
20
|
+
use ${config.name}::schema::Schema;
|
|
21
|
+
|
|
22
|
+
public(package) fun run(_schema: &mut Schema, _ctx: &mut TxContext) {
|
|
23
|
+
|
|
24
|
+
}
|
|
73
25
|
}`
|
|
26
|
+
await formatAndWriteMove(
|
|
27
|
+
code,
|
|
28
|
+
path,
|
|
29
|
+
'formatAndWriteMove'
|
|
30
|
+
);
|
|
74
31
|
}
|
|
75
|
-
await formatAndWriteMove(
|
|
76
|
-
code,
|
|
77
|
-
path,
|
|
78
|
-
'formatAndWriteMove'
|
|
79
|
-
);
|
|
80
32
|
console.log('✅ Deploy Hook Generation Complete\n');
|
|
81
33
|
}
|
|
82
34
|
|
|
@@ -17,7 +17,7 @@ edition = "2024"
|
|
|
17
17
|
|
|
18
18
|
[dependencies]
|
|
19
19
|
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.38.3" }
|
|
20
|
-
Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe-mainnet-v1.
|
|
20
|
+
Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe-mainnet-v1.1.0" }
|
|
21
21
|
|
|
22
22
|
[addresses]
|
|
23
23
|
sui = "0x2"
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./parser"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const parseData = (data: unknown) => {
|
|
2
|
+
if (typeof data !== 'object' || data === null) {
|
|
3
|
+
return data;
|
|
4
|
+
}
|
|
5
|
+
const parsedData: any = {};
|
|
6
|
+
for (const key in data) {
|
|
7
|
+
if (data.hasOwnProperty(key)) {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const value = data[key];
|
|
10
|
+
// console.log("===========", value)
|
|
11
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
12
|
+
if (value.hasOwnProperty('variant')) {
|
|
13
|
+
parsedData[key] = value.variant;
|
|
14
|
+
} else if (value.hasOwnProperty('fields')) {
|
|
15
|
+
parsedData[key] = parseData(value.fields);
|
|
16
|
+
} else {
|
|
17
|
+
parsedData[key] = parseData(value);
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
parsedData[key] = value;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return parsedData;
|
|
25
|
+
}
|