@0xobelisk/sui-common 1.0.3 → 1.0.4

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.js CHANGED
@@ -1,10 +1,10 @@
1
- import x from"prettier";import J from"prettier-plugin-move-js";async function G(e,t){let r;t&&(r=await x.resolveConfig(t));try{return x.format(e,{plugins:[J],parser:"move-parse",printWidth:120,semi:!0,tabWidth:2,useTabs:!1,bracketSpacing:!0,...r})}catch(a){let o;return a instanceof Error?o=a.message:o=a,console.log(`Error during output formatting: ${o}`),e}}async function O(e){return x.format(e,{parser:"typescript"})}import w from"node:fs/promises";import E from"node:path";import W from"debug";var h=W("dubhe:common"),N=W("dubhe:common");h.log=console.debug.bind(console);N.log=console.error.bind(console);var S=h.extend("codegen"),P=h.extend("codegen");S.log=console.debug.bind(console);P.log=console.error.bind(console);async function p(e,t,r){let a=await G(e),o=` // Copyright (c) Obelisk Labs, Inc.
1
+ import S from"prettier";import q from"prettier-plugin-move-js";async function T(e,t){let r;t&&(r=await S.resolveConfig(t));try{return S.format(e,{plugins:[q],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 j(e){return S.format(e,{parser:"typescript"})}import h from"node:fs/promises";import G from"node:path";import R from"debug";var _=R("dubhe:common"),X=R("dubhe:common");_.log=console.debug.bind(console);X.log=console.error.bind(console);var b=_.extend("codegen"),Y=_.extend("codegen");b.log=console.debug.bind(console);Y.log=console.error.bind(console);async function c(e,t,r){let a=await T(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
- `,n="#[test_only]",s=o+a,i="#[allow(lint(share_owned), unused_let_mut)]";t.includes(".toml")||t.includes("system")||t.includes("migrate")?s=a:t.includes("init")?s=n+a:t.includes("deploy_hook")&&(s=i+a),await w.mkdir(E.dirname(t),{recursive:!0}),await w.writeFile(t,s),S(`${r}: ${t}`)}async function Te(e,t,r){let a=await O(e);await w.mkdir(E.dirname(t),{recursive:!0}),await w.writeFile(t,a),S(`${r}: ${t}`)}function Ge(e){return e.replace(/\\/g,"/")}import{existsSync as j}from"fs";import g from"fs";function D(e){g.existsSync(e)&&(g.readdirSync(e).forEach(t=>{let r=`${e}/${t}`;g.lstatSync(r).isDirectory()?D(r):g.unlinkSync(r)}),g.rmdirSync(e))}function _(e){return Object.entries(e).map(([t,r])=>`${t}`).join(",")}function V(e){return`(${Object.entries(e).map(([t,r])=>`${r}`)})`}function l(e){return Object.entries(e).map(([t,r])=>`${t}: ${r}`)}function U(e){return Object.entries(e).map(([t,r])=>`self.${t}`)}async function L(e,t){console.log(`
7
+ `,o="#[test_only]",n=s+a,i="#[allow(lint(share_owned), unused_let_mut)]";t.includes(".toml")||t.includes("system")||t.includes("migrate")?n=a:t.includes("init")?n=o+a:t.includes("deploy_hook")&&(n=i+a),await h.mkdir(G.dirname(t),{recursive:!0}),await h.writeFile(t,n),b(`${r}: ${t}`)}async function Me(e,t,r){let a=await j(e);await h.mkdir(G.dirname(t),{recursive:!0}),await h.writeFile(t,a),b(`${r}: ${t}`)}function je(e){return e.replace(/\\/g,"/")}import{existsSync as C}from"fs";import l from"fs";function y(e){l.existsSync(e)&&(l.readdirSync(e).forEach(t=>{let r=`${e}/${t}`;l.lstatSync(r).isDirectory()?y(r):l.unlinkSync(r)}),l.rmdirSync(e))}function g(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 V(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"
@@ -17,201 +17,173 @@ Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe
17
17
  [addresses]
18
18
  sui = "0x2"
19
19
  ${e.name} = "0x0"
20
- `;await p(r,`${t}/contracts/${e.name}/Move.toml`,"formatAndWriteMove"),console.log(`\u2705 Move.toml Generation Complete
21
- `)}function m(e){return e.split("_").map((t,r)=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("")}function ee(e,t){return Object.entries(t).map(([r,a])=>`public(package) fun set_${r}(self: &mut ${e}, ${r}: ${a}) {
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(),s=r.charAt(0).toLowerCase();return a<s?-1:a>s?1:0})}function w(e){return e.split("_").map((t,r)=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("")}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
- `)}function te(e,t){return`public(package) fun set(self: &mut ${e}, ${l(t)}) {
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
- }`}function re(e,t){return`public fun get(self: &${e}): ${V(t)} {
28
- (${U(t)})
29
- }`}function ae(e,t){return Object.entries(t).map(([r,a])=>`public fun get_${r}(self: &${e}): ${a} {
27
+ }`}function ee(e,t){return`public fun get(self: &${e}): ${W(t)} {
28
+ (${E(t)})
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
- `)}function d(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function I(e,t,r){console.log(`
33
- \u{1F4E6} Starting Schema Data Generation...`);for(let a of Object.keys(t)){let o=a,n=t[a];console.log(` \u2514\u2500 Generating ${o} ${Array.isArray(n)?"(enum)":"(struct)"}`);let s="",i=Object.keys(t).filter(c=>Array.isArray(t[c])).map(c=>c);console.log(i),Array.isArray(n)?s=`module ${e}::${d(o)} {
34
- public enum ${o} has copy, drop , store {
35
- ${n}
32
+ `)}function d(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function L(e,t,r){console.log(`
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}::${d(s)} {
34
+ public enum ${s} has copy, drop , store {
35
+ ${p}
36
36
  }
37
37
 
38
- ${n.map(c=>`public fun new_${d(c)}(): ${o} {
39
- ${o}::${c}
40
- }`).join("")}`:s=`module ${e}::${d(o)} {
38
+ ${p.map(m=>`public fun new_${d(m)}(): ${s} {
39
+ ${s}::${m}
40
+ }`).join("")}`}else n=`module ${e}::${d(s)} {
41
41
  use std::ascii::String;
42
- ${i.map(c=>`use ${e}::${d(c)}::${c};`).join(`
42
+ ${i.map(p=>`use ${e}::${d(p)}::${p};`).join(`
43
43
  `)}
44
44
 
45
- public struct ${o} has copy, drop , store {
46
- ${l(n)}
45
+ public struct ${s} has copy, drop , store {
46
+ ${u(o)}
47
47
  }
48
48
 
49
- public fun new(${l(n)}): ${o} {
50
- ${o} {
51
- ${_(n)}
49
+ public fun new(${u(o)}): ${s} {
50
+ ${s} {
51
+ ${g(o)}
52
52
  }
53
53
  }
54
54
 
55
- ${re(o,n)}
56
- ${ae(o,n)}
57
- ${ee(o,n)}
58
- ${te(o,n)}
59
- }`,await p(s,`${r}/contracts/${e}/sources/codegen/data/${d(o)}.move`,"formatAndWriteMove")}console.log(`\u2705 Schema Data Generation Complete
60
- `)}function oe(e,t){return t!=null?Object.keys(t).map(a=>`use ${e}::${d(a)}::${a};`).join(`
61
- `):""}async function k(e,t,r,a){console.log(`
62
- \u{1F528} Starting Schema Structure Generation...`);for(let o in r){console.log(` \u251C\u2500 Generating schema: ${o}`),console.log(` \u251C\u2500 Output path: ${a}/contracts/${e}/sources/codegen/schemas/${o}.move`),console.log(` \u2514\u2500 Structure fields: ${Object.values(r[o]).length}`);let n=r[o],s=`module ${e}::${o}_schema {
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/${d(s)}.move`,"formatAndWriteMove")}console.log(`\u2705 Schema Data Generation Complete
60
+ `)}function re(e,t){return t!=null?Object.keys(t).map(a=>`use ${e}::${d(a)}::${a};`).join(`
61
+ `):""}async function x(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;
66
66
  use std::type_name;
67
- use dubhe::storage_migration;
67
+ use dubhe::storage;
68
68
  use dubhe::storage_value::{Self, StorageValue};
69
69
  use dubhe::storage_map::{Self, StorageMap};
70
70
  use dubhe::storage_double_map::{Self, StorageDoubleMap};
71
71
  use sui::dynamic_field as df;
72
- use sui::sui::SUI;
73
- use sui::coin::Coin;
74
- use sui::balance::Balance;
75
- ${oe(e,t)}
76
-
77
- public struct ${m(o)} has key, store {
78
- id: UID
79
- }
72
+
73
+ ${re(e,t)}
74
+
75
+ public struct Schema has key, store { id: UID }
80
76
 
81
- ${Object.entries(n).map(([i,c])=>`public fun borrow_${i}(self: &${m(o)}) : &${c} {
82
- storage_migration::borrow_field(&self.id, b"${i}")
77
+ ${Object.entries(r).map(([o,n])=>`public fun borrow_${o}(self: &Schema) : &${n} {
78
+ storage::borrow_field(&self.id, b"${o}")
83
79
  }
84
80
 
85
- public(package) fun ${i}(self: &mut ${m(o)}): &mut ${c} {
86
- storage_migration::borrow_mut_field(&mut self.id, b"${i}")
81
+ public(package) fun ${o}(self: &mut Schema): &mut ${n} {
82
+ storage::borrow_mut_field(&mut self.id, b"${o}")
87
83
  }
88
84
  `).join("")}
89
85
 
90
86
 
91
- public(package) fun create(ctx: &mut TxContext): ${m(o)} {
87
+ public(package) fun create(ctx: &mut TxContext): Schema {
92
88
  let mut id = object::new(ctx);
93
- ${Object.entries(n).map(([i,c])=>{let u="";return c.includes("StorageValue")?u="storage_value::new()":c.includes("StorageMap")?u="storage_map::new()":c.includes("StorageDoubleMap")&&(u="storage_double_map::new()"),`storage_migration::add_field<${c}>(&mut id, b"${i}", ${u});`}).join("")}
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
+ `)}
94
91
 
95
- ${m(o)} { id }
92
+ Schema { id }
96
93
  }
97
94
 
98
- public fun migrate(_${o}: &mut ${m(o)}, _cap: &UpgradeCap) { }
95
+ public fun migrate(_schema: &mut Schema, _cap: &UpgradeCap, _ctx: &mut TxContext) { }
99
96
 
100
-
101
97
 
102
98
  // ======================================== View Functions ========================================
103
- ${Object.entries(n).map(([i,c])=>{let u=c.match(/<(.+)>/)[1].split(",").map(Y=>Y.trim()),f=[],b="",$="",v="";return c.includes("StorageValue")?(f=[],b=`${u[0]}`,$="borrow()"):c.includes("StorageMap")?(f=[`key: ${u[0]}`],b=`${u[1]}`,$="borrow(key)",!c.includes("Balance")&&!c.includes("Coin")&&(v=`public fun get_${i}_keys(self: &${m(o)}) : vector<${u[0]}> {
104
- self.borrow_${i}().keys()
105
- }
106
-
107
- public fun get_${i}_values(self: &${m(o)}) : vector<${u[1]}> {
108
- self.borrow_${i}().values()
109
- }`)):c.includes("StorageDoubleMap")&&(f=[`key1: ${u[0]}`,`key2: ${u[1]}`],b=`${u[2]}`,$="borrow(key1, key2)",!c.includes("Balance")&&!c.includes("Coin")&&(v=`public fun get_${i}_keys(self: &${m(o)}) : (vector<${u[0]}>, vector<${u[1]}>) {
110
- self.borrow_${i}().keys()
111
- }
112
-
113
- public fun get_${i}_values(self: &${m(o)}) : vector<${u[2]}> {
114
- self.borrow_${i}().values()
115
- }`)),`public fun get_${i}(self: &${m(o)}, ${f}) : &${b} {
116
- self.borrow_${i}().${$}
117
- }
118
- `+v}).join("")}
99
+ ${Object.entries(r).map(([o,n])=>{let i=n.match(/<(.+)>/)[1].split(",").map(Z=>Z.trim()),p=[],m="",f="";return n.includes("StorageValue")?(p=[],m=`${i[0]}`,f="get()"):n.includes("StorageMap")?(p=[`key: ${i[0]}`],m=`${i[1]}`,f="get(key)"):n.includes("StorageDoubleMap")&&(p=[`key1: ${i[0]}`,`key2: ${i[1]}`],m=`${i[2]}`,f="get(key1, key2)"),`public fun get_${o}(self: &Schema, ${p}) : &${m} {
100
+ self.borrow_${o}().${f}
101
+ }`}).join(`
102
+ `)}
119
103
  // =========================================================================================================
120
-
121
-
122
- }`;await p(s,`${a}/contracts/${e}/sources/codegen/schemas/${o}.move`,"formatAndWriteMove")}console.log(`\u2705 Schema Structure Generation Complete
123
- `)}import{existsSync as F}from"fs";import{readFileSync as se}from"fs";function ne(e){let t=se(e,"utf-8"),r=/\/\/ Logic that needs to be automated once the contract is deployed\s*\{([\s\S]*?)\}\s*;\s*\/\/ Authorize schemas and public share objects/,a=t.match(r);if(a)return a[1].trim();throw new Error("Logic and authorization block not found in the file.")}async function z(e,t){console.log(`
124
- \u{1F4DD} Starting Deploy Hook Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/scripts/deploy_hook.move`);let r=Object.keys(e.schemas).map(s=>`_${s}: &mut ${m(s)}`).join(","),a=Object.keys(e.schemas).map(s=>`use ${e.name}::${s}_schema::${m(s)};`).join(`
125
- `),o=`${t}/contracts/${e.name}/sources/scripts/deploy_hook.move`,n="";if(!F(o))n=`module ${e.name}::deploy_hook {
104
+ }`;await c(s,`${a}/contracts/${e}/sources/codegen/schema.move`,"formatAndWriteMove"),console.log(`\u2705 Schema Structure Generation Complete
105
+ `)}import{existsSync as O}from"fs";import{readFileSync as ae}from"fs";function oe(e){let t=ae(e,"utf-8"),r=/\/\/ Logic that needs to be automated once the contract is deployed\s*\{([\s\S]*?)\}\s*;\s*\/\/ Authorize schemas and public share objects/,a=t.match(r);if(a)return a[1].trim();throw new Error("Logic and authorization block not found in the file.")}async function F(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=Object.keys(e.schemas).map(n=>`_${n}: &mut ${w(n)}`).join(","),a=Object.keys(e.schemas).map(n=>`use ${e.name}::${n}_schema::${w(n)};`).join(`
107
+ `),s=`${t}/contracts/${e.name}/sources/scripts/deploy_hook.move`,o="";if(!O(s))o=`module ${e.name}::deploy_hook {
126
108
  use std::ascii::string;
127
109
  use sui::clock::Clock;
128
110
  use ${e.name}::dapp_system;
129
- ${a}
130
111
  public entry fun run(clock: &Clock, ctx: &mut TxContext) {
131
112
  // Create a dapp.
132
113
  let mut dapp = dapp_system::create(string(b"${e.name}"),string(b"${e.description}"), clock , ctx);
133
114
 
134
115
  // Create schemas
135
- ${Object.keys(e.schemas).map(s=>`let mut ${s} = ${e.name}::${s}_schema::create(ctx);`).join(`
136
- `)}
116
+ let mut schema = ${e.name}::schema::create(ctx);
137
117
  // Logic that needs to be automated once the contract is deployed
138
118
  {
139
119
  };
140
120
  // Authorize schemas and public share objects
141
- ${Object.keys(e.schemas).map(s=>`
142
- dapp.add_schema<${m(s)}>(${s}, ctx);
143
- `).join(`
144
- `)}
121
+ dapp.add_schema(schema);
145
122
  sui::transfer::public_share_object(dapp);
146
123
  }
147
- }`;else{let s=ne(o);n=`module ${e.name}::deploy_hook {
124
+ }`;else{let n=oe(s);o=`module ${e.name}::deploy_hook {
148
125
  use std::ascii::string;
149
126
  use sui::clock::Clock;
150
127
  use ${e.name}::dapp_system;
151
- ${a}
152
128
  public entry fun run(clock: &Clock, ctx: &mut TxContext) {
153
129
  // Create a dapp.
154
130
  let mut dapp = dapp_system::create(string(b"${e.name}"),string(b"${e.description}"), clock , ctx);
155
131
 
156
132
  // Create schemas
157
- ${Object.keys(e.schemas).map(i=>`let mut ${i} = ${e.name}::${i}_schema::create(ctx);`).join(`
158
- `)}
133
+ let mut schema = ${e.name}::schema::create(ctx);
159
134
  // Logic that needs to be automated once the contract is deployed
160
135
 
161
136
  {
162
- ${s}
137
+ ${n}
163
138
  };
164
139
 
165
140
  // Authorize schemas and public share objects
166
- ${Object.keys(e.schemas).map(i=>`
167
- dapp.add_schema<${m(i)}>(${i}, ctx);
168
- `).join(`
169
- `)}
141
+ dapp.add_schema(schema);
170
142
  sui::transfer::public_share_object(dapp);
171
143
  }
172
- }`}await p(n,o,"formatAndWriteMove"),console.log(`\u2705 Deploy Hook Generation Complete
173
- `)}async function B(e,t){if(!F(`${t}/contracts/${e.name}/sources/scripts/migrate.move`)){let r=`module ${e.name}::migrate {
144
+ }`}await c(o,s,"formatAndWriteMove"),console.log(`\u2705 Deploy Hook Generation Complete
145
+ `)}async function U(e,t){if(!O(`${t}/contracts/${e.name}/sources/scripts/migrate.move`)){let r=`module ${e.name}::migrate {
174
146
  const ON_CHAIN_VERSION: u32 = 1;
175
147
 
176
148
  public fun on_chain_version(): u32 {
177
149
  ON_CHAIN_VERSION
178
150
  }
179
151
  }
180
- `;await p(r,`${t}/contracts/${e.name}/sources/scripts/migrate.move`,"formatAndWriteMove")}}function C(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}function ie(e,t){return t!=null?Object.keys(t).map(a=>`use ${e}::${C(a)}::${a};`).join(`
181
- `):""}async function A(e,t,r,a){console.log(`
182
- \u{1F4E6} Starting Schema Event Generation...`);for(let o of Object.keys(r)){let n=o,s=r[o];console.log(` \u2514\u2500 Generating ${n} event: ${s}`);let i=`module ${e}::${C(n)}_event {
152
+ `;await c(r,`${t}/contracts/${e.name}/sources/scripts/migrate.move`,"formatAndWriteMove")}}function v(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}function se(e,t){return t!=null?Object.keys(t).map(a=>`use ${e}::${v(a)}::${a};`).join(`
153
+ `):""}async function D(e,t,r,a){console.log(`
154
+ \u{1F4E6} Starting Schema Event Generation...`);for(let s of Object.keys(r)){let o=s,n=r[s];console.log(` \u2514\u2500 Generating ${o} event: ${n}`);let i=`module ${e}::${v(o)}_event {
183
155
  use sui::event;
184
156
  use std::ascii::String;
185
- ${ie(e,t)}
157
+ ${se(e,t)}
186
158
 
187
- public struct ${n}Event has copy, drop {
188
- ${l(s)}
159
+ public struct ${o}Event has copy, drop {
160
+ ${u(n)}
189
161
  }
190
162
 
191
- public fun new(${l(s)}): ${n}Event {
192
- ${n}Event {
193
- ${_(s)}
163
+ public fun new(${u(n)}): ${o}Event {
164
+ ${o}Event {
165
+ ${g(n)}
194
166
  }
195
167
  }
196
168
 
197
- public fun emit(${l(s)}) {
198
- event::emit(${n}Event {
199
- ${_(s)}
169
+ public fun emit(${u(n)}) {
170
+ event::emit(${o}Event {
171
+ ${g(n)}
200
172
  });
201
- }`;await p(i,`${a}/contracts/${e}/sources/codegen/events/${C(n)}_event.move`,"formatAndWriteMove")}console.log(`\u2705 Schema Event Generation Complete
202
- `)}import{existsSync as ce}from"fs";import pe from"node:fs/promises";async function H(e,t){console.log(`
203
- \u2699\uFE0F Starting System Generation...`),console.log(" \u251C\u2500 Generating systems"),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/systems`),ce(`${t}/contracts/${e.name}/sources/systems`)||await pe.mkdir(`${t}/contracts/${e.name}/sources/systems`,{recursive:!0}),console.log(`\u2705 System Generation Complete
204
- `)}function K(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function Q(e,t,r){console.log(`
205
- \u{1F4E6} Starting Schema Error Generation...`);for(let a of Object.keys(t)){let o=a,n=t[a];console.log(` \u2514\u2500 Generating ${o} message: ${n}`);let s=`module ${e}::${K(o)}_error {
173
+ }`;await c(i,`${a}/contracts/${e}/sources/codegen/events/${v(o)}_event.move`,"formatAndWriteMove")}console.log(`\u2705 Schema Event Generation Complete
174
+ `)}import{existsSync as ne}from"fs";import ie from"node:fs/promises";async function I(e,t){console.log(`
175
+ \u2699\uFE0F Starting System Generation...`),console.log(" \u251C\u2500 Generating systems"),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/systems`),ne(`${t}/contracts/${e.name}/sources/systems`)||await ie.mkdir(`${t}/contracts/${e.name}/sources/systems`,{recursive:!0}),console.log(`\u2705 System Generation Complete
176
+ `)}function z(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function B(e,t,r){console.log(`
177
+ \u{1F4E6} Starting Schema Error Generation...`);for(let a of Object.keys(t)){let s=a,o=t[a];console.log(` \u2514\u2500 Generating ${s} message: ${o}`);let n=`module ${e}::${z(s)}_error {
206
178
  #[error]
207
- const ${o}: vector<u8> = b"${n}";
179
+ const ${s}: vector<u8> = b"${o}";
208
180
  /// Get the error message.
209
- public fun message(): vector<u8> { ${o} }
181
+ public fun message(): vector<u8> { ${s} }
210
182
  /// Abort execution with the given error code.
211
- public fun emit() { abort ${o} }
183
+ public fun emit() { abort ${s} }
212
184
  /// Require that the given condition is true, otherwise abort with the given error code.
213
- public fun require(condition: bool) { if (!condition) { emit() } }`;await p(s,`${r}/contracts/${e}/sources/codegen/errors/${K(o)}_error.move`,"formatAndWriteMove")}console.log(`\u2705 Schema Error Generation Complete
214
- `)}import{existsSync as M}from"fs";async function Z(e,t){await ue(e,t),await me(e,t),await le(e,t)}async function ue(e,t){let r=`${t}/contracts/${e.name}/sources/codegen/schemas/default/dapp/metadata.move`;if(!M(r)){let a=`module ${e.name}::dapp_metadata {
185
+ public fun require(condition: bool) { if (!condition) { emit() } }`;await c(n,`${r}/contracts/${e}/sources/codegen/errors/${z(s)}_error.move`,"formatAndWriteMove")}console.log(`\u2705 Schema Error Generation Complete
186
+ `)}import{existsSync as k}from"fs";async function H(e,t){await ce(e,t),await pe(e,t),await ue(e,t)}async function ce(e,t){let r=`${t}/contracts/${e.name}/sources/codegen/dapp/metadata.move`;if(!k(r)){let a=`module ${e.name}::dapp_metadata {
215
187
  use std::ascii::String;
216
188
 
217
189
  public struct DappMetadata has drop, copy, store {
@@ -307,125 +279,125 @@ ${e.name} = "0x0"
307
279
  }
308
280
 
309
281
  }
310
- `;await p(a,r,"formatAndWriteMove")}}async function me(e,t){let r=`${t}/contracts/${e.name}/sources/codegen/schemas/default/dapp/schema.move`;if(!M(r)){let a=`module ${e.name}::dapp_schema {
311
- use ${e.name}::dapp_metadata::DappMetadata;
312
- use dubhe::storage_value;
313
- use dubhe::storage_value::StorageValue;
314
- use dubhe::storage_migration;
315
- use sui::transfer::public_share_object;
316
- use dubhe::type_info;
317
-
318
- public struct Dapp has key, store { id: UID }
319
-
320
- public fun borrow_admin(self: &Dapp): &StorageValue<address> {
321
- storage_migration::borrow_field(&self.id, b"admin")
322
- }
323
-
324
- public(package) fun borrow_mut_admin(self: &mut Dapp): &mut StorageValue<address> {
325
- storage_migration::borrow_mut_field(&mut self.id, b"admin")
326
- }
327
-
328
- public fun borrow_package_id(self: &Dapp): &StorageValue<address> {
329
- storage_migration::borrow_field(&self.id, b"package_id")
330
- }
331
-
332
- public(package) fun borrow_mut_package_id(self: &mut Dapp): &mut StorageValue<address> {
333
- storage_migration::borrow_mut_field(&mut self.id, b"package_id")
334
- }
335
-
336
- public fun borrow_version(self: &Dapp): &StorageValue<u32> {
337
- storage_migration::borrow_field(&self.id, b"version")
338
- }
282
+ `;await c(a,r,"formatAndWriteMove")}}async function pe(e,t){let r=`${t}/contracts/${e.name}/sources/codegen/dapp/schema.move`;if(!k(r)){let a=`module ${e.name}::dapp_schema {
283
+ use ${e.name}::dapp_metadata::DappMetadata;
284
+ use dubhe::storage_value;
285
+ use dubhe::storage_value::StorageValue;
286
+ use dubhe::storage;
287
+ use sui::transfer::public_share_object;
288
+ use dubhe::type_info;
289
+
290
+ public struct Dapp has key, store {
291
+ id: UID,
292
+ }
339
293
 
340
- public(package) fun borrow_mut_version(self: &mut Dapp): &mut StorageValue<u32> {
341
- storage_migration::borrow_mut_field(&mut self.id, b"version")
342
- }
294
+ public fun borrow_admin(self: &Dapp): &StorageValue<address> {
295
+ storage::borrow_field(&self.id, b"admin")
296
+ }
343
297
 
344
- public fun borrow_metadata(self: &Dapp): &StorageValue<DappMetadata> {
345
- storage_migration::borrow_field(&self.id, b"metadata")
346
- }
298
+ public(package) fun admin(self: &mut Dapp): &mut StorageValue<address> {
299
+ storage::borrow_mut_field(&mut self.id, b"admin")
300
+ }
347
301
 
348
- public(package) fun borrow_mut_metadata(self: &mut Dapp): &mut StorageValue<DappMetadata> {
349
- storage_migration::borrow_mut_field(&mut self.id, b"metadata")
350
- }
302
+ public fun borrow_package_id(self: &Dapp): &StorageValue<address> {
303
+ storage::borrow_field(&self.id, b"package_id")
304
+ }
351
305
 
352
- public fun borrow_schemas(self: &Dapp): &StorageValue<vector<address>> {
353
- storage_migration::borrow_field(&self.id, b"schemas")
354
- }
306
+ public(package) fun package_id(self: &mut Dapp): &mut StorageValue<address> {
307
+ storage::borrow_mut_field(&mut self.id, b"package_id")
308
+ }
355
309
 
356
- public(package) fun borrow_mut_schemas(self: &mut Dapp): &mut StorageValue<vector<address>> {
357
- storage_migration::borrow_mut_field(&mut self.id, b"schemas")
358
- }
310
+ public fun borrow_version(self: &Dapp): &StorageValue<u32> {
311
+ storage::borrow_field(&self.id, b"version")
312
+ }
359
313
 
360
- public fun borrow_safe_mode(self: &Dapp): &StorageValue<bool> {
361
- storage_migration::borrow_field(&self.id, b"safe_mode")
362
- }
314
+ public(package) fun version(self: &mut Dapp): &mut StorageValue<u32> {
315
+ storage::borrow_mut_field(&mut self.id, b"version")
316
+ }
363
317
 
364
- public(package) fun borrow_mut_safe_mode(self: &mut Dapp): &mut StorageValue<bool> {
365
- storage_migration::borrow_mut_field(&mut self.id, b"safe_mode")
366
- }
318
+ public fun borrow_metadata(self: &Dapp): &StorageValue<DappMetadata> {
319
+ storage::borrow_field(&self.id, b"metadata")
320
+ }
367
321
 
368
- public(package) fun create(ctx: &mut TxContext): Dapp {
369
- let mut id = object::new(ctx);
370
- storage_migration::add_field<StorageValue<address>>(&mut id, b"admin", storage_value::new());
371
- storage_migration::add_field<StorageValue<address>>(&mut id, b"package_id", storage_value::new());
372
- storage_migration::add_field<StorageValue<u32>>(&mut id, b"version", storage_value::new());
373
- storage_migration::add_field<StorageValue<DappMetadata>>(&mut id, b"metadata", storage_value::new());
374
- storage_migration::add_field<StorageValue<vector<address>>>(&mut id, b"schemas", storage_value::new());
375
- storage_migration::add_field<StorageValue<bool>>(&mut id, b"safe_mode", storage_value::new());
376
- Dapp { id }
377
- }
322
+ public(package) fun metadata(self: &mut Dapp): &mut StorageValue<DappMetadata> {
323
+ storage::borrow_mut_field(&mut self.id, b"metadata")
324
+ }
378
325
 
379
- public(package) fun upgrade<DappKey: drop>(dapp: &mut Dapp, ctx: &TxContext) {
380
- assert!(dapp.borrow_metadata().contains(), 0);
381
- assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
326
+ public fun borrow_safe_mode(self: &Dapp): &StorageValue<bool> {
327
+ storage::borrow_field(&self.id, b"safe_mode")
328
+ }
382
329
 
383
- let new_package_id = type_info::current_package_id<DappKey>();
384
- dapp.borrow_mut_package_id().set(new_package_id);
385
- dapp.borrow_mut_version().mutate!(|version| {
386
- *version = *version + 1;
387
- });
388
- }
330
+ public(package) fun safe_mode(self: &mut Dapp): &mut StorageValue<bool> {
331
+ storage::borrow_mut_field(&mut self.id, b"safe_mode")
332
+ }
333
+
334
+ public(package) fun borrow_schemas(self: &Dapp): &StorageValue<vector<address>> {
335
+ storage::borrow_field(&self.id, b"schemas")
336
+ }
337
+
338
+ public(package) fun schemas(self: &mut Dapp): &mut StorageValue<vector<address>> {
339
+ storage::borrow_mut_field(&mut self.id, b"schemas")
340
+ }
341
+
342
+
343
+ public(package) fun create(ctx: &mut TxContext): Dapp {
344
+ let mut id = object::new(ctx);
345
+ storage::add_field<StorageValue<address>>(&mut id, b"admin", storage_value::new(b"admin", ctx));
346
+ storage::add_field<StorageValue<address>>(&mut id, b"package_id", storage_value::new(b"package_id", ctx));
347
+ storage::add_field<StorageValue<u32>>(&mut id, b"version", storage_value::new(b"version", ctx));
348
+ storage::add_field<StorageValue<DappMetadata>>(&mut id, b"metadata", storage_value::new(b"metadata", ctx));
349
+ storage::add_field<StorageValue<bool>>(&mut id, b"safe_mode", storage_value::new(b"safe_mode", ctx));
350
+ storage::add_field<StorageValue<vector<address>>>(&mut id, b"schemas", storage_value::new(b"schemas", ctx));
351
+ Dapp { id }
352
+ }
353
+
354
+ public(package) fun upgrade<DappKey: drop>(dapp: &mut Dapp, ctx: &TxContext) {
355
+ assert!(dapp.borrow_metadata().contains(), 0);
356
+ assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
357
+ let new_package_id = type_info::current_package_id<DappKey>();
358
+ dapp.package_id().set(new_package_id);
359
+ let current_version = dapp.version()[];
360
+ dapp.version().set(current_version + 1);
361
+ }
362
+
363
+ public(package) fun add_schema<Schema: key + store>(dapp: &mut Dapp, schema: Schema) {
364
+ let mut schemas = dapp.schemas()[];
365
+ schemas.push_back(object::id_address<Schema>(&schema));
366
+ dapp.schemas().set(schemas);
367
+ public_share_object(schema);
368
+ }
389
369
 
390
- public(package) fun add_schema<Schema: key + store>(dapp: &mut Dapp, schema: Schema, ctx: &TxContext) {
391
- assert!(dapp.borrow_metadata().contains(), 0);
392
- assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
370
+ #[test_only]
393
371
 
394
- let schema_id = object::id_address(&schema);
395
- dapp.borrow_mut_schemas().borrow_mut().push_back(schema_id);
396
- public_share_object(schema);
397
- }
372
+ public fun create_dapp_for_testing(ctx: &mut TxContext): Dapp {
373
+ create(ctx)
374
+ }
398
375
 
399
- #[test_only]
400
- public fun create_dapp_for_testing(ctx: &mut TxContext): Dapp {
401
- create(ctx)
402
- }
376
+ #[test_only]
403
377
 
404
- #[test_only]
405
- public fun distroy_dapp_for_testing(dapp: Dapp) {
406
- let Dapp { id } = dapp;
407
- id.delete();
408
- }
378
+ public fun distroy_dapp_for_testing(dapp: Dapp) {
379
+ let Dapp { id } = dapp;
380
+ id.delete();
381
+ }
409
382
  }
410
- `;await p(a,r,"formatAndWriteMove")}}async function le(e,t){let r=`${t}/contracts/${e.name}/sources/codegen/schemas/default/dapp/system.move`;if(!M(r)){let a=`module ${e.name}::dapp_system {
411
- use std::ascii::String;
412
- use std::ascii;
413
- use dubhe::type_info;
414
- use sui::clock::Clock;
415
- use ${e.name}::dapp_schema;
416
- use ${e.name}::dapp_metadata;
417
- use ${e.name}::dapp_schema::Dapp;
418
-
419
- public struct DappKey has drop {}
420
-
421
- public(package) fun new(): DappKey {
422
- DappKey { }
423
- }
424
-
425
- public(package) fun create(name: String, description: String, clock: &Clock, ctx: &mut TxContext): Dapp {
426
- let mut dapp = dapp_schema::create(ctx);
427
- assert!(!dapp.borrow_metadata().contains(), 0);
428
- dapp.borrow_mut_metadata().set(
383
+ `;await c(a,r,"formatAndWriteMove")}}async function ue(e,t){let r=`${t}/contracts/${e.name}/sources/codegen/dapp/system.move`;if(!k(r)){let a=`module ${e.name}::dapp_system {
384
+ use std::ascii::String;
385
+ use std::ascii;
386
+ use dubhe::type_info;
387
+ use sui::clock::Clock;
388
+ use ${e.name}::dapp_schema;
389
+ use ${e.name}::dapp_metadata;
390
+ use ${e.name}::dapp_schema::Dapp;
391
+
392
+ public struct DappKey has drop {}
393
+ public(package) fun new(): DappKey {
394
+ DappKey { }
395
+ }
396
+
397
+ public(package) fun create(name: String, description: String, clock: &Clock, ctx: &mut TxContext): Dapp {
398
+ let mut dapp = dapp_schema::create(ctx);
399
+ assert!(!dapp.borrow_metadata().contains(), 0);
400
+ dapp.metadata().set(
429
401
  dapp_metadata::new(
430
402
  name,
431
403
  description,
@@ -435,20 +407,28 @@ ${e.name} = "0x0"
435
407
  vector[]
436
408
  )
437
409
  );
438
- let package_id = type_info::current_package_id<DappKey>();
439
- dapp.borrow_mut_package_id().set(package_id);
440
- dapp.borrow_mut_admin().set(ctx.sender());
441
- dapp.borrow_mut_version().set(1);
442
- dapp.borrow_mut_safe_mode().set(false);
443
- dapp.borrow_mut_schemas().set(vector[]);
444
- dapp
445
- }
446
-
447
- public entry fun set_metadata(dapp: &mut Dapp, name: String, description: String, icon_url: String, website_url: String, partners: vector<String>, ctx: &TxContext) {
448
- assert!(dapp.borrow_admin().contains(), 0);
449
- assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
450
- let created_at = dapp.borrow_mut_metadata().take().get_created_at();
451
- dapp.borrow_mut_metadata().set(
410
+ let package_id = type_info::current_package_id<DappKey>();
411
+ dapp.package_id().set(package_id);
412
+ dapp.admin().set(ctx.sender());
413
+ dapp.version().set(1);
414
+ dapp.safe_mode().set(false);
415
+ dapp.schemas().set(vector[]);
416
+ dapp
417
+ }
418
+
419
+ public entry fun set_metadata(
420
+ dapp: &mut Dapp,
421
+ name: String,
422
+ description: String,
423
+ icon_url: String,
424
+ website_url: String,
425
+ partners: vector<String>,
426
+ ctx: &TxContext,
427
+ ) {
428
+ let admin = dapp.admin().try_get();
429
+ assert!(admin == option::some(ctx.sender()), 0);
430
+ let created_at = dapp.metadata().remove().get_created_at();
431
+ dapp.metadata().set(
452
432
  dapp_metadata::new(
453
433
  name,
454
434
  description,
@@ -458,37 +438,36 @@ ${e.name} = "0x0"
458
438
  partners
459
439
  )
460
440
  );
461
- }
462
-
463
- public entry fun transfer_ownership(dapp: &mut Dapp, new_admin: address, ctx: &mut TxContext) {
464
- assert!(dapp.borrow_admin().contains(), 0);
465
- assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
466
-
467
- dapp.borrow_mut_admin().set(new_admin);
468
- }
469
-
470
- public entry fun set_safe_mode(dapp: &mut Dapp, safe_mode: bool, ctx: &TxContext) {
471
- assert!(dapp.borrow_admin().contains(), 0);
472
- assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
473
-
474
- dapp.borrow_mut_safe_mode().set(safe_mode);
475
- }
476
-
477
- public fun ensure_no_safe_mode(dapp: &Dapp) {
478
- assert!(!dapp.borrow_safe_mode().get(), 0);
479
- }
480
-
481
- public fun ensure_has_authority(dapp: &Dapp, ctx: &TxContext) {
482
- assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
483
- }
484
-
485
- public fun ensure_has_schema<Schema: key + store>(dapp: &Dapp, schema: &Schema) {
486
- let schema_id = object::id_address(schema);
487
- assert!(dapp.borrow_schemas().get().contains(&schema_id), 0);
488
- }
441
+ }
442
+
443
+ public entry fun transfer_ownership(dapp: &mut Dapp, new_admin: address, ctx: &mut TxContext) {
444
+ let admin = dapp.admin().try_get();
445
+ assert!(admin == option::some(ctx.sender()), 0);
446
+ dapp.admin().set(new_admin);
447
+ }
448
+
449
+ public entry fun set_safe_mode(dapp: &mut Dapp, safe_mode: bool, ctx: &TxContext) {
450
+ let admin = dapp.admin().try_get();
451
+ assert!(admin == option::some(ctx.sender()), 0);
452
+ dapp.safe_mode().set(safe_mode);
453
+ }
454
+
455
+ public fun ensure_no_safe_mode(dapp: &Dapp) {
456
+ assert!(!dapp.borrow_safe_mode()[], 0);
457
+ }
458
+
459
+ public fun ensure_has_authority(dapp: &Dapp, ctx: &TxContext) {
460
+ assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
461
+ }
462
+
463
+ public fun ensure_has_schema<Schema: key + store>(dapp: &Dapp, schema: &Schema) {
464
+ let schema_id = object::id_address(schema);
465
+ assert!(dapp.borrow_schemas().get().contains(&schema_id), 0);
466
+ }
489
467
  }
490
468
 
491
- `;await p(a,r,"formatAndWriteMove")}}async function q(e,t){console.log(`
469
+
470
+ `;await c(a,r,"formatAndWriteMove")}}async function K(e,t){console.log(`
492
471
  \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 {
493
472
  use ${e.name}::dapp_schema::Dapp;
494
473
  use sui::clock;
@@ -506,8 +485,8 @@ ${e.name} = "0x0"
506
485
  (scenario, dapp)
507
486
  }
508
487
  }
509
- `;await p(r,`${t}/contracts/${e.name}/sources/tests/init.move`,"formatAndWriteMove"),console.log(`\u2705 Deploy Hook Generation Complete
510
- `)}async function ht(e,t,r){console.log(`
511
- \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();j(`${a}/contracts/${e.name}`)&&D(`${a}/contracts/${e.name}/sources/codegen`),j(`${a}/contracts/${e.name}/Move.toml`)||await L(e,a),j(`${a}/contracts/${e.name}/sources/script/deploy_hook.move`)||await z(e,a),e.events&&(e.data?await A(e.name,e.data,e.events,a):await A(e.name,null,e.events,a)),e.data?(await I(e.name,e.data,a),await k(e.name,e.data,e.schemas,a)):await k(e.name,null,e.schemas,a),e.errors&&await Q(e.name,e.errors,a),await Z(e,a),await q(e,a),await H(e,a),await B(e,a),console.log(`\u2705 Schema Generation Process Complete!
512
- `)}import{findUp as de}from"find-up";import T from"path";import ge from"esbuild";var y=class extends Error{name="NotInsideProjectError";message="You are not inside a Dubhe project"};import{rmSync as _e}from"fs";import{pathToFileURL as fe}from"url";import be from"os";var $e=["dubhe.config.js","dubhe.config.mjs","dubhe.config.ts","dubhe.config.mts"],R="dubhe.config.example.mjs";async function Mt(e){e=await X(e);try{return await ge.build({entryPoints:[e],format:"esm",outfile:R,platform:"node",bundle:!0,packages:"external"}),e=await X(R,!0),(await import(e+`?update=${Date.now()}`)).dubheConfig}finally{_e(R,{force:!0})}}async function X(e,t){return e===void 0?e=await he():T.isAbsolute(e)||(e=T.join(process.cwd(),e),e=T.normalize(e)),t&&be.platform()==="win32"?fe(e).href:e}async function he(){let e=await de($e);if(e===void 0)throw new y;return e}export{p as formatAndWriteMove,Te as formatAndWriteTypescript,G as formatMove,O as formatTypescript,Mt as loadConfig,Ge as posixPath,X as resolveConfigPath,ht as schemaGen};
488
+ `;await c(r,`${t}/contracts/${e.name}/sources/tests/init.move`,"formatAndWriteMove"),console.log(`\u2705 Deploy Hook Generation Complete
489
+ `)}async function bt(e,t,r){console.log(`
490
+ \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();C(`${a}/contracts/${e.name}`)&&y(`${a}/contracts/${e.name}/sources/codegen`),C(`${a}/contracts/${e.name}/Move.toml`)||await V(e,a),C(`${a}/contracts/${e.name}/sources/script/deploy_hook.move`)||await F(e,a),e.events&&(e.data?await D(e.name,e.data,e.events,a):await D(e.name,null,e.events,a)),e.data?(await L(e.name,e.data,a),await x(e.name,e.data,e.schemas,a)):await x(e.name,null,e.schemas,a),e.errors&&await B(e.name,e.errors,a),await H(e,a),await K(e,a),await I(e,a),await U(e,a),console.log(`\u2705 Schema Generation Process Complete!
491
+ `)}import{findUp as me}from"find-up";import A from"path";import de from"esbuild";var $=class extends Error{name="NotInsideProjectError";message="You are not inside a Dubhe project"};import{rmSync as le}from"fs";import{pathToFileURL as ge}from"url";import fe from"os";var _e=["dubhe.config.js","dubhe.config.mjs","dubhe.config.ts","dubhe.config.mts"],M="dubhe.config.example.mjs";async function Ct(e){e=await Q(e);try{return await de.build({entryPoints:[e],format:"esm",outfile:M,platform:"node",bundle:!0,packages:"external"}),e=await Q(M,!0),(await import(e+`?update=${Date.now()}`)).dubheConfig}finally{le(M,{force:!0})}}async function Q(e,t){return e===void 0?e=await be():A.isAbsolute(e)||(e=A.join(process.cwd(),e),e=A.normalize(e)),t&&fe.platform()==="win32"?ge(e).href:e}async function be(){let e=await me(_e);if(e===void 0)throw new $;return e}export{c as formatAndWriteMove,Me as formatAndWriteTypescript,T as formatMove,j as formatTypescript,Ct as loadConfig,je as posixPath,Q as resolveConfigPath,bt as schemaGen};
513
492
  //# sourceMappingURL=index.js.map