@0xobelisk/sui-common 0.5.12 → 0.5.13
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 +52 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
- package/src/codegen/utils/format.ts +32 -32
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
declare function formatMove(content: string, prettierConfigPath?: string): Promise<string>;
|
|
2
|
+
declare function formatTypescript(content: string): Promise<string>;
|
|
3
|
+
|
|
4
|
+
declare function formatAndWriteMove(output: string, fullOutputPath: string, logPrefix?: string): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Formats typescript code using prettier and write it to a file
|
|
7
|
+
* @param output typescript code
|
|
8
|
+
* @param fullOutputPath full path to the output file
|
|
9
|
+
* @param logPrefix prefix for debug logs
|
|
10
|
+
*/
|
|
11
|
+
declare function formatAndWriteTypescript(output: string, fullOutputPath: string, logPrefix: string): Promise<void>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Explicitly normalize a given path to a posix path (using `/` as separator).
|
|
15
|
+
* This should be used for generating Solidity files that will be consumed by solc,
|
|
16
|
+
* because solc expects `/` as path separator, but path.join produces `\` if the user is on windows.
|
|
17
|
+
*/
|
|
18
|
+
declare function posixPath(path: string): string;
|
|
19
|
+
|
|
20
|
+
type BaseType = "String" | "vector<String>" | "address" | "bool" | "u8" | "u64" | "u128" | "vector<address>" | "vector<bool>" | "vector<u8>" | "vector<vector<u8>>" | "vector<u64>" | "vector<u128>" | string;
|
|
21
|
+
type StorageDataType = "Struct" | "Enum";
|
|
22
|
+
type StorageMapType = "Map" | "Bag" | "Table";
|
|
23
|
+
type Address = string;
|
|
24
|
+
type Bool = boolean;
|
|
25
|
+
type U8 = number;
|
|
26
|
+
type U64 = number;
|
|
27
|
+
type U128 = number;
|
|
28
|
+
type Vector<T> = T[];
|
|
29
|
+
type BaseValueType = String | Address | Bool | U8 | U64 | U128 | Vector<Address> | Vector<Bool> | Vector<U8> | Vector<Vector<U8>> | Vector<U64> | Vector<U128>;
|
|
30
|
+
type SchemaData = {
|
|
31
|
+
name: string;
|
|
32
|
+
type?: StorageDataType;
|
|
33
|
+
fields: Record<string, BaseType> | string[];
|
|
34
|
+
};
|
|
35
|
+
type SchemaType = {
|
|
36
|
+
data?: SchemaData[];
|
|
37
|
+
structure: Record<string, string>;
|
|
38
|
+
};
|
|
39
|
+
type ObeliskConfig = {
|
|
40
|
+
name: string;
|
|
41
|
+
description: string;
|
|
42
|
+
systems: string[];
|
|
43
|
+
schemas: Record<string, SchemaType>;
|
|
44
|
+
};
|
|
45
|
+
type MoveType = "string" | "vector<string>" | "String" | "vector<String>" | "address" | "bool" | "u8" | "u64" | "u128" | "vector<address>" | "vector<bool>" | "vector<u8>" | "vector<vector<u8>>" | "vector<u64>" | "vector<u128>";
|
|
46
|
+
|
|
47
|
+
declare function worldgen(config: ObeliskConfig, srcPrefix?: string): Promise<void>;
|
|
48
|
+
|
|
49
|
+
declare function loadConfig(configPath?: string): Promise<unknown>;
|
|
50
|
+
declare function resolveConfigPath(configPath: string | undefined, toFileURL?: boolean): Promise<string>;
|
|
51
|
+
|
|
52
|
+
export { BaseType, BaseValueType, MoveType, ObeliskConfig, SchemaData, SchemaType, StorageDataType, StorageMapType, formatAndWriteMove, formatAndWriteTypescript, formatMove, formatTypescript, loadConfig, posixPath, resolveConfigPath, worldgen };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import y from"prettier";import I from"prettier-plugin-move";async function S(e,t){let r;t&&(r=await y.resolveConfig(t));try{return y.format(e,{plugins:[I],parser:"move-parse",printWidth:120,semi:!0,tabWidth:2,useTabs:!1,bracketSpacing:!0,...r})}catch(o){let i;return o instanceof Error?i=o.message:i=o,console.log(`Error during output formatting: ${i}`),e}}async function h(e){return y.format(e,{parser:"typescript"})}import $ from"node:fs/promises";import A from"node:path";import v from"debug";var f=v("obelisk:common"),U=v("obelisk:common");f.log=console.debug.bind(console);U.log=console.error.bind(console);var g=f.extend("codegen"),B=f.extend("codegen");g.log=console.debug.bind(console);B.log=console.error.bind(console);async function a(e,t,r){let o=await S(e),s=` // Copyright (c) Obelisk Labs, Inc.
|
|
1
|
+
import y from"prettier";import I from"prettier-plugin-move-js";async function S(e,t){let r;t&&(r=await y.resolveConfig(t));try{return y.format(e,{plugins:[I],parser:"move-parse",printWidth:120,semi:!0,tabWidth:2,useTabs:!1,bracketSpacing:!0,...r})}catch(o){let i;return o instanceof Error?i=o.message:i=o,console.log(`Error during output formatting: ${i}`),e}}async function h(e){return y.format(e,{parser:"typescript"})}import $ from"node:fs/promises";import A from"node:path";import v from"debug";var f=v("obelisk:common"),U=v("obelisk:common");f.log=console.debug.bind(console);U.log=console.error.bind(console);var g=f.extend("codegen"),B=f.extend("codegen");g.log=console.debug.bind(console);B.log=console.error.bind(console);async function a(e,t,r){let o=await S(e),s=` // Copyright (c) Obelisk Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
#[allow(unused_use)]
|
|
4
4
|
|
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/worldgen.ts","../src/codegen/utils/renderMove/common.ts","../src/codegen/utils/renderMove/generateSystem.ts","../src/codegen/utils/renderMove/generateToml.ts","../src/codegen/utils/renderMove/generateSchema.ts","../src/codegen/utils/renderMove/generateScript.ts","../src/codegen/utils/renderMove/generateDappKey.ts","../src/codegen/utils/config.ts","../src/codegen/utils/errors.ts"],"sourcesContent":["import prettier from \"prettier\";\nimport prettierPluginMove from \"prettier-plugin-move\";\n\nexport async function formatMove(\n content: string,\n prettierConfigPath?: string\n): Promise<string> {\n let config;\n if (prettierConfigPath) {\n config = await prettier.resolveConfig(prettierConfigPath);\n }\n try {\n return prettier.format(content, {\n plugins: [prettierPluginMove],\n parser: \"move-parse\",\n printWidth: 120,\n semi: true,\n tabWidth: 2,\n useTabs: false,\n bracketSpacing: true,\n ...config,\n });\n } catch (error) {\n let message;\n if (error instanceof Error) {\n message = error.message;\n } else {\n message = error;\n }\n console.log(`Error during output formatting: ${message}`);\n return content;\n }\n}\n\nexport async function formatTypescript(content: string): Promise<string> {\n return prettier.format(content, {\n parser: \"typescript\",\n });\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 prefix =\n` // Copyright (c) Obelisk Labs, Inc.\n // SPDX-License-Identifier: MIT\n #[allow(unused_use)]\n \n /* Autogenerated file. Do not edit manually. */\n `\n\n let code = prefix + formattedOutput\n\n if (fullOutputPath.includes(\"deploy_hook\") || fullOutputPath.includes(\".toml\") || fullOutputPath.includes(\"system\")) {\n code = 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(\"obelisk:common\");\nexport const error = createDebug(\"obelisk: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, ObeliskConfig } from \"../../types\";\nimport { rmdirSync, existsSync } from \"fs\";\nimport { deleteFolderRecursive } from \"./common\";\nimport { generateSystem } from \"./generateSystem\";\nimport { generateToml } from \"./generateToml\";\nimport {generateSchemaData, generateSchemaStructure} from \"./generateSchema\";\nimport {generateDeployHook, generateMigrate} from \"./generateScript\";\nimport {generateDappKey} from \"./generateDappKey\";\n\nexport async function worldgen(config: ObeliskConfig, srcPrefix?: string) {\n let path = \"\";\n if (srcPrefix === undefined) {\n path = process.cwd();\n } else {\n path = srcPrefix;\n }\n\n if (existsSync(`${path}/contracts/${config.name}`)) {\n deleteFolderRecursive(`${path}/contracts/${config.name}/sources/codegen`);\n }\n\n if (!existsSync(`${path}/contracts/${config.name}/Move.toml`)) {\n await generateToml(config, path);\n }\n\n if (!existsSync(`${path}/contracts/${config.name}/sources/script/deploy_hook.move`)) {\n await generateDeployHook(config, path);\n }\n\n await generateSystem(config, path);\n await generateSchemaData(config.name, config.schemas, path);\n await generateSchemaStructure(config.name, config.schemas, path);\n await generateDappKey(config, path);\n}\n","import { BaseType, SchemaType, BaseValueType, MoveType } from \"../../types\";\nimport fs from \"fs\";\n\nexport function deleteFolderRecursive(path: string) {\n if (fs.existsSync(path)) {\n fs.readdirSync(path).forEach((file) => {\n const curPath = `${path}/${file}`;\n if (fs.lstatSync(curPath).isDirectory()) {\n deleteFolderRecursive(curPath);\n } else {\n fs.unlinkSync(curPath);\n }\n });\n fs.rmdirSync(path);\n }\n}\n\nexport function capitalizeFirstLetter(input: string): string {\n return 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 values: Record<string, string> | string,\n): string {\n return Object.entries(values).map(([key, _]) => `${key}`).join(\",\");\n}\n\nfunction isAddress(str: string): boolean {\n const regex = /^0x[a-fA-F0-9]+$/;\n return 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 values: MoveType | Record<string, MoveType>\n): string {\n return typeof values === \"string\"\n ? values\n : `(${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 values: Record<string, string>\n): string[] {\n return Object.entries(values).map(([key, type]) => `${key}: ${type}`);\n}\n\n/**\n * @param values\n * @param prefixArgs\n * @return [ data.name, data.age ]\n */\nexport function getStructAttrsQuery(\n values: MoveType | Record<string, MoveType>,\n prefixArgs: string\n): string[] {\n return typeof values === \"string\"\n ? [`${prefixArgs}self.value`]\n : Object.entries(values).map(\n ([key, _]) => `${prefixArgs}self.${key}`\n );\n}","import { ObeliskConfig } from \"../../types\";\nimport { formatAndWriteMove } from \"../formatAndWrite\";\nimport { existsSync } from \"fs\";\n\nexport async function generateSystem(config: ObeliskConfig, srcPrefix: string) {\n config.systems.map(async (systemName) => {\n if (\n !existsSync(\n `${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`\n )\n ) {\n let code = `module ${config.name}::${systemName}_system {\n\n}\n`;\n await formatAndWriteMove(\n code,\n `${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`,\n \"formatAndWriteMove\"\n );\n }\n });\n}\n","import { ObeliskConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\n\nexport async function generateToml(config: ObeliskConfig, srcPrefix: string) {\n\tlet code = `[package]\nname = \"${config.name}\"\nversion = \"0.0.1\"\nedition = \"2024.beta\"\n\n[dependencies]\nSui = { git = \"https://github.com/MystenLabs/sui.git\", subdir = \"crates/sui-framework/packages/sui-framework\", rev = \"mainnet-v1.31.1\" }\nObelisk = { git = \"https://github.com/0xobelisk/obelisk-engine.git\", subdir = \"packages/obelisk-framework\", rev = \"main\" }\n\n[addresses]\nsui = \"0x2\"\nobelisk = \"0x3dc2d6239eed38c9798444afbf4bada0998ec98edc365713864405fe64203256\"\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}\n","import {\n BaseType, SchemaType,\n} from \"../../types\";\nimport { formatAndWriteMove } from \"../formatAndWrite\";\nimport {\n getStructAttrsWithType,\n getStructAttrs,\n getStructTypes, getStructAttrsQuery,\n} from \"./common\";\n\nfunction capitalizeAndRemoveUnderscores(input: string): string {\n return input\n .split('_')\n .map((word, index) => {\n return index === 0\n ? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()\n : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();\n })\n .join('');\n}\n\nexport function renderSetAttrsFunc(\n schemaName: string,\n fields: BaseType | Record<string, BaseType>\n): string {\n return Object.entries(fields)\n .map(\n ([key, type]) =>\n `public(package) fun set_${key}(self: &mut ${schemaName}, ${key}: ${type}) {\n self.${key} = ${key};\n }`\n ).join(\"\\n\");\n}\n\nexport function renderSetFunc(\n schemaName: string,\n fields: Record<string, string>\n): string {\n return `public(package) fun set(self: &mut ${schemaName}, ${getStructAttrsWithType(fields)}) {\n ${Object.entries(fields)\n .map(([fieldName]) => `self.${fieldName} = ${fieldName};`)\n .join('\\n')}\n }`;\n}\n\nexport function renderGetAllFunc(\n schemaName: string,\n fields: BaseType | Record<string, BaseType>\n): string {\n return `public fun get(self: &${schemaName}): ${getStructTypes(fields)} {\n (${getStructAttrsQuery(fields, \"\")})\n }`;\n}\n\nexport function renderGetAttrsFunc(\n schemaName: string,\n fields: BaseType | Record<string, BaseType>\n): string {\n return Object.entries(fields)\n .map(\n ([key, type]) => `public fun get_${key}(self: &${schemaName}): ${type} {\n self.${key}\n }`\n ).join(\"\\n\");\n}\n\nfunction convertToSnakeCase(input: string): string {\n return input\n .replace(/([A-Z])/g, '_$1')\n .toLowerCase()\n .replace(/^_/, '');\n}\n\nexport async function generateSchemaData(projectName: string, schemas: Record<string, SchemaType>, path: string) {\n for (const schemaName in schemas) {\n const schema = schemas[schemaName];\n if (schema.data) {\n for (const item of schema.data) {\n let code = \"\";\n\n const enumNames = schema.data\n .filter(item => Array.isArray(item.fields))\n .map(item => item.name);\n\n if (Array.isArray(item.fields)) {\n code = `module ${projectName}::${schemaName}_${convertToSnakeCase(item.name)} {\n public enum ${item.name} has copy, drop , store {\n ${item.fields}\n }\n \n ${item.fields.map((field: string) => {\n return `public fun new_${convertToSnakeCase(field)}(): ${item.name} {\n ${item.name}::${field}\n }`\n }).join(\"\")\n }`\n } else {\n code = `module ${projectName}::${schemaName}_${convertToSnakeCase(item.name)} {\n use std::ascii::String;\n ${enumNames.map(name => `use ${projectName}::${schemaName}_${convertToSnakeCase(name)}::${name};`).join('\\n')}\n\n public struct ${item.name} has copy, drop , store {\n ${getStructAttrsWithType(item.fields)}\n }\n \n public fun new(${getStructAttrsWithType(item.fields)}): ${item.name} {\n ${item.name} {\n ${getStructAttrs(item.fields)}\n }\n }\n \n ${renderGetAllFunc(item.name, item.fields)}\n ${renderGetAttrsFunc(item.name, item.fields)}\n ${renderSetAttrsFunc(item.name, item.fields)}\n ${renderSetFunc(item.name, item.fields)}\n }`;\n }\n\n await formatAndWriteMove(\n code,\n `${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}_${convertToSnakeCase(item.name)}.move`,\n \"formatAndWriteMove\"\n );\n }\n }\n }\n}\n\nfunction generateImport(projectName: string, schemaName: string, schema: SchemaType) {\n if (schema.data) {\n return schema.data.map(item => {\n return `use ${projectName}::${schemaName}_${convertToSnakeCase(item.name)}::${item.name};`\n }).join('\\n');\n } else {\n return \"\"\n }\n}\n\nexport async function generateSchemaStructure(projectName: string, schemas: Record<string, SchemaType>, path: string) {\n for (const schemaName in schemas) {\n console.log(`Schema: ${schemaName}`);\n const schema = schemas[schemaName];\n const schemaMoudle = `module ${projectName}::${schemaName}_schema {\n use std::ascii::String;\n use std::type_name;\n use sui::transfer::{public_share_object};\n use obelisk::dapps_system;\n use obelisk::dapps_schema::Dapps;\n use obelisk::storage_value::{Self, StorageValue};\n use obelisk::storage_map::{Self, StorageMap};\n use obelisk::storage_double_map::{Self, StorageDoubleMap};\n use ${projectName}::dapp_key::DappKey;\n ${generateImport(projectName, schemaName, schema)}\n\n public struct ${capitalizeAndRemoveUnderscores(schemaName)} has key, store {\n id: UID,\n ${getStructAttrsWithType(schema.structure)}\n } \n \n ${Object.entries(schema.structure).map(([key, value]) => {\n return `public fun borrow_${key}(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : &${value} {\n &self.${key}\n }\n \n public(package) fun borrow_mut_${key}(self: &mut ${capitalizeAndRemoveUnderscores(schemaName)}): &mut ${value} {\n &mut self.${key}\n }\n `\n }).join('')} \n \n public entry fun register(dapps: &mut Dapps, ctx: &mut TxContext) {\n let package_id = dapps_system::current_package_id<DappKey>();\n assert!(dapps.borrow_metadata().contains_key(package_id), 0);\n assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);\n let schema = type_name::get<${capitalizeAndRemoveUnderscores(schemaName)}>().into_string();\n assert!(!dapps.borrow_schemas().get(package_id).contains(&schema), 0);\n \n public_share_object(${capitalizeAndRemoveUnderscores(schemaName)} {\n id: object::new(ctx),\n ${Object.entries(schema.structure).map(([key, value]) => {\n let storage_type = \"\"\n if (value.includes(\"StorageValue\")) {\n storage_type = `storage_value::new()`\n } else if (value.includes(\"StorageMap\")) {\n storage_type = `storage_map::new()`\n } else if (value.includes(\"StorageDoubleMap\")) {\n storage_type = `storage_double_map::new()`\n }\n return `${key}: ${storage_type},`\n }).join(' ')\n }\n });\n \n dapps_system::add_schema<${capitalizeAndRemoveUnderscores(schemaName)}>(dapps, package_id, ctx);\n }\n \n }`;\n await formatAndWriteMove(\n schemaMoudle,\n `${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,\n \"formatAndWriteMove\"\n );\n }\n}","import { ObeliskConfig } from \"../../types\";\nimport { formatAndWriteMove } from \"../formatAndWrite\";\nimport { existsSync } from \"fs\";\n\nexport async function generateDeployHook(config: ObeliskConfig, srcPrefix: string) {\n if (\n !existsSync(\n `${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`\n )\n ) {\n let code = `module ${config.name}::deploy_hook {\n use obelisk::dapps_schema::Dapps;\n use obelisk::dapps_system;\n use ${config.name}::dapp_key::DappKey;\n use std::ascii;\n use sui::clock::Clock;\n #[test_only]\n use obelisk::dapps_schema;\n #[test_only]\n use sui::clock;\n #[test_only]\n use sui::test_scenario;\n #[test_only]\n use sui::test_scenario::Scenario;\n\n public entry fun run(dapps: &mut Dapps, clock: &Clock, ctx: &mut TxContext) {\n // Register the dapp to obelisk.\n dapps_system::register<DappKey>(\n dapps,\n ascii::string(b\"${config.name}\"),\n ascii::string(b\"${config.description}\"),\n clock,\n ctx\n );\n ${Object.keys(config.schemas).map(schemaName => {\n return `${config.name}::${schemaName}_schema::register(dapps, ctx);`\n }).join(\"\\n\")}\n \n // Logic that needs to be automated once the contract is deployed\n\n }\n\n #[test_only]\n public fun deploy_hook_for_testing(): (Scenario, Dapps) {\n let mut scenario = test_scenario::begin(@0xA);\n {\n let ctx = test_scenario::ctx(&mut scenario);\n dapps_schema::init_dapps_for_testing(ctx);\n test_scenario::next_tx(&mut scenario,@0xA);\n };\n let mut dapps = test_scenario::take_shared<Dapps>(&scenario);\n let ctx = test_scenario::ctx(&mut scenario);\n let clock = clock::create_for_testing(ctx);\n run(&mut dapps, &clock, ctx);\n clock::destroy_for_testing(clock);\n test_scenario::next_tx(&mut scenario,@0xA);\n (scenario, dapps)\n }\n}\n`;\n await formatAndWriteMove(\n code,\n `${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`,\n \"formatAndWriteMove\"\n );\n }\n}\n\nexport function generateMigrate(config: ObeliskConfig, srcPrefix: string) {\n if (\n !existsSync(\n `${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`\n )\n ) {\n let code = `module ${config.name}::migrate {\n use obelisk::world::{World, AdminCap};\n\n /// Not the right admin for this world\n const ENotAdmin: u64 = 0;\n const EWrongVersion: u64 = 1;\n const ENotUpgrade: u64 = 2;\n const VERSION: u64 = 1;\n\n public entry fun run(world: &mut World, admin_cap: &AdminCap) {\n assert!(world.admin() == object::id(admin_cap), ENotAdmin);\n assert!(world.version() < VERSION, ENotUpgrade);\n *obelisk::world::mut_version(world, admin_cap) = VERSION;\n }\n\n public fun assert_version(world: &World){\n assert!(world.version() == VERSION, EWrongVersion);\n }\n}\n`;\n formatAndWriteMove(\n code,\n `${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`,\n \"formatAndWriteMove\"\n );\n }\n}\n\n","import { ObeliskConfig } from \"../../types\";\nimport { formatAndWriteMove } from \"../formatAndWrite\";\n\nexport async function generateDappKey(config: ObeliskConfig, srcPrefix: string) {\n let code = `module ${config.name}::dapp_key {\n /// Authorization token for the app.\n public struct DappKey has drop {}\n\n public(package) fun new(): DappKey {\n DappKey { }\n }\n}\n`;\n await formatAndWriteMove(\n code,\n `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`,\n \"formatAndWriteMove\"\n );\n}\n","import { findUp } from \"find-up\";\nimport path from \"path\";\nimport esbuild from \"esbuild\";\nimport { NotInsideProjectError } from \"./errors\";\nimport { rmSync } from \"fs\";\nimport { pathToFileURL } from \"url\";\nimport os from \"os\";\n\n// In order of preference files are checked\nconst configFiles = [\n \"obelisk.config.js\",\n \"obelisk.config.mjs\",\n \"obelisk.config.ts\",\n \"obelisk.config.mts\",\n];\nconst TEMP_CONFIG = \"obelisk.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()}`)).obeliskConfig;\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 Obelisk project\";\n}"],"mappings":"AAAA,OAAOA,MAAc,WACrB,OAAOC,MAAwB,uBAE/B,eAAsBC,EACpBC,EACAC,EACiB,CACjB,IAAIC,EACAD,IACFC,EAAS,MAAML,EAAS,cAAcI,CAAkB,GAE1D,GAAI,CACF,OAAOJ,EAAS,OAAOG,EAAS,CAC9B,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,GAMnCG,GAAaP,EAAG,SAAS,IAAM,QAClCD,EAAcK,CAAU,EAAE,KAC1BA,CACN,CAEA,eAAeI,GAAoB,CACjC,IAAME,EAAe,MAAMC,EAAOV,CAAW,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","code","fs","path","debug","formatAndWriteTypescript","formatTypescript","posixPath","path","existsSync","fs","deleteFolderRecursive","path","file","curPath","getStructAttrs","values","key","_","getStructTypes","values","_","type","getStructAttrsWithType","key","getStructAttrsQuery","prefixArgs","existsSync","generateSystem","config","srcPrefix","systemName","code","formatAndWriteMove","generateToml","config","srcPrefix","code","formatAndWriteMove","capitalizeAndRemoveUnderscores","input","word","index","renderSetAttrsFunc","schemaName","fields","key","type","renderSetFunc","getStructAttrsWithType","fieldName","renderGetAllFunc","getStructTypes","getStructAttrsQuery","renderGetAttrsFunc","convertToSnakeCase","generateSchemaData","projectName","schemas","path","schema","item","code","enumNames","field","name","getStructAttrs","formatAndWriteMove","generateImport","generateSchemaStructure","schemaMoudle","value","storage_type","existsSync","generateDeployHook","config","srcPrefix","code","schemaName","formatAndWriteMove","generateDappKey","config","srcPrefix","code","formatAndWriteMove","worldgen","config","srcPrefix","path","existsSync","deleteFolderRecursive","generateToml","generateDeployHook","generateSystem","generateSchemaData","generateSchemaStructure","generateDappKey","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/worldgen.ts","../src/codegen/utils/renderMove/common.ts","../src/codegen/utils/renderMove/generateSystem.ts","../src/codegen/utils/renderMove/generateToml.ts","../src/codegen/utils/renderMove/generateSchema.ts","../src/codegen/utils/renderMove/generateScript.ts","../src/codegen/utils/renderMove/generateDappKey.ts","../src/codegen/utils/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 prefix =\n` // Copyright (c) Obelisk Labs, Inc.\n // SPDX-License-Identifier: MIT\n #[allow(unused_use)]\n \n /* Autogenerated file. Do not edit manually. */\n `\n\n let code = prefix + formattedOutput\n\n if (fullOutputPath.includes(\"deploy_hook\") || fullOutputPath.includes(\".toml\") || fullOutputPath.includes(\"system\")) {\n code = 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(\"obelisk:common\");\nexport const error = createDebug(\"obelisk: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, ObeliskConfig } from \"../../types\";\nimport { rmdirSync, existsSync } from \"fs\";\nimport { deleteFolderRecursive } from \"./common\";\nimport { generateSystem } from \"./generateSystem\";\nimport { generateToml } from \"./generateToml\";\nimport {generateSchemaData, generateSchemaStructure} from \"./generateSchema\";\nimport {generateDeployHook, generateMigrate} from \"./generateScript\";\nimport {generateDappKey} from \"./generateDappKey\";\n\nexport async function worldgen(config: ObeliskConfig, srcPrefix?: string) {\n let path = \"\";\n if (srcPrefix === undefined) {\n path = process.cwd();\n } else {\n path = srcPrefix;\n }\n\n if (existsSync(`${path}/contracts/${config.name}`)) {\n deleteFolderRecursive(`${path}/contracts/${config.name}/sources/codegen`);\n }\n\n if (!existsSync(`${path}/contracts/${config.name}/Move.toml`)) {\n await generateToml(config, path);\n }\n\n if (!existsSync(`${path}/contracts/${config.name}/sources/script/deploy_hook.move`)) {\n await generateDeployHook(config, path);\n }\n\n await generateSystem(config, path);\n await generateSchemaData(config.name, config.schemas, path);\n await generateSchemaStructure(config.name, config.schemas, path);\n await generateDappKey(config, path);\n}\n","import { BaseType, SchemaType, BaseValueType, MoveType } from \"../../types\";\nimport fs from \"fs\";\n\nexport function deleteFolderRecursive(path: string) {\n if (fs.existsSync(path)) {\n fs.readdirSync(path).forEach((file) => {\n const curPath = `${path}/${file}`;\n if (fs.lstatSync(curPath).isDirectory()) {\n deleteFolderRecursive(curPath);\n } else {\n fs.unlinkSync(curPath);\n }\n });\n fs.rmdirSync(path);\n }\n}\n\nexport function capitalizeFirstLetter(input: string): string {\n return 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 values: Record<string, string> | string,\n): string {\n return Object.entries(values).map(([key, _]) => `${key}`).join(\",\");\n}\n\nfunction isAddress(str: string): boolean {\n const regex = /^0x[a-fA-F0-9]+$/;\n return 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 values: MoveType | Record<string, MoveType>\n): string {\n return typeof values === \"string\"\n ? values\n : `(${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 values: Record<string, string>\n): string[] {\n return Object.entries(values).map(([key, type]) => `${key}: ${type}`);\n}\n\n/**\n * @param values\n * @param prefixArgs\n * @return [ data.name, data.age ]\n */\nexport function getStructAttrsQuery(\n values: MoveType | Record<string, MoveType>,\n prefixArgs: string\n): string[] {\n return typeof values === \"string\"\n ? [`${prefixArgs}self.value`]\n : Object.entries(values).map(\n ([key, _]) => `${prefixArgs}self.${key}`\n );\n}","import { ObeliskConfig } from \"../../types\";\nimport { formatAndWriteMove } from \"../formatAndWrite\";\nimport { existsSync } from \"fs\";\n\nexport async function generateSystem(config: ObeliskConfig, srcPrefix: string) {\n config.systems.map(async (systemName) => {\n if (\n !existsSync(\n `${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`\n )\n ) {\n let code = `module ${config.name}::${systemName}_system {\n\n}\n`;\n await formatAndWriteMove(\n code,\n `${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`,\n \"formatAndWriteMove\"\n );\n }\n });\n}\n","import { ObeliskConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\n\nexport async function generateToml(config: ObeliskConfig, srcPrefix: string) {\n\tlet code = `[package]\nname = \"${config.name}\"\nversion = \"0.0.1\"\nedition = \"2024.beta\"\n\n[dependencies]\nSui = { git = \"https://github.com/MystenLabs/sui.git\", subdir = \"crates/sui-framework/packages/sui-framework\", rev = \"mainnet-v1.31.1\" }\nObelisk = { git = \"https://github.com/0xobelisk/obelisk-engine.git\", subdir = \"packages/obelisk-framework\", rev = \"main\" }\n\n[addresses]\nsui = \"0x2\"\nobelisk = \"0x3dc2d6239eed38c9798444afbf4bada0998ec98edc365713864405fe64203256\"\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}\n","import {\n BaseType, SchemaType,\n} from \"../../types\";\nimport { formatAndWriteMove } from \"../formatAndWrite\";\nimport {\n getStructAttrsWithType,\n getStructAttrs,\n getStructTypes, getStructAttrsQuery,\n} from \"./common\";\n\nfunction capitalizeAndRemoveUnderscores(input: string): string {\n return input\n .split('_')\n .map((word, index) => {\n return index === 0\n ? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()\n : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();\n })\n .join('');\n}\n\nexport function renderSetAttrsFunc(\n schemaName: string,\n fields: BaseType | Record<string, BaseType>\n): string {\n return Object.entries(fields)\n .map(\n ([key, type]) =>\n `public(package) fun set_${key}(self: &mut ${schemaName}, ${key}: ${type}) {\n self.${key} = ${key};\n }`\n ).join(\"\\n\");\n}\n\nexport function renderSetFunc(\n schemaName: string,\n fields: Record<string, string>\n): string {\n return `public(package) fun set(self: &mut ${schemaName}, ${getStructAttrsWithType(fields)}) {\n ${Object.entries(fields)\n .map(([fieldName]) => `self.${fieldName} = ${fieldName};`)\n .join('\\n')}\n }`;\n}\n\nexport function renderGetAllFunc(\n schemaName: string,\n fields: BaseType | Record<string, BaseType>\n): string {\n return `public fun get(self: &${schemaName}): ${getStructTypes(fields)} {\n (${getStructAttrsQuery(fields, \"\")})\n }`;\n}\n\nexport function renderGetAttrsFunc(\n schemaName: string,\n fields: BaseType | Record<string, BaseType>\n): string {\n return Object.entries(fields)\n .map(\n ([key, type]) => `public fun get_${key}(self: &${schemaName}): ${type} {\n self.${key}\n }`\n ).join(\"\\n\");\n}\n\nfunction convertToSnakeCase(input: string): string {\n return input\n .replace(/([A-Z])/g, '_$1')\n .toLowerCase()\n .replace(/^_/, '');\n}\n\nexport async function generateSchemaData(projectName: string, schemas: Record<string, SchemaType>, path: string) {\n for (const schemaName in schemas) {\n const schema = schemas[schemaName];\n if (schema.data) {\n for (const item of schema.data) {\n let code = \"\";\n\n const enumNames = schema.data\n .filter(item => Array.isArray(item.fields))\n .map(item => item.name);\n\n if (Array.isArray(item.fields)) {\n code = `module ${projectName}::${schemaName}_${convertToSnakeCase(item.name)} {\n public enum ${item.name} has copy, drop , store {\n ${item.fields}\n }\n \n ${item.fields.map((field: string) => {\n return `public fun new_${convertToSnakeCase(field)}(): ${item.name} {\n ${item.name}::${field}\n }`\n }).join(\"\")\n }`\n } else {\n code = `module ${projectName}::${schemaName}_${convertToSnakeCase(item.name)} {\n use std::ascii::String;\n ${enumNames.map(name => `use ${projectName}::${schemaName}_${convertToSnakeCase(name)}::${name};`).join('\\n')}\n\n public struct ${item.name} has copy, drop , store {\n ${getStructAttrsWithType(item.fields)}\n }\n \n public fun new(${getStructAttrsWithType(item.fields)}): ${item.name} {\n ${item.name} {\n ${getStructAttrs(item.fields)}\n }\n }\n \n ${renderGetAllFunc(item.name, item.fields)}\n ${renderGetAttrsFunc(item.name, item.fields)}\n ${renderSetAttrsFunc(item.name, item.fields)}\n ${renderSetFunc(item.name, item.fields)}\n }`;\n }\n\n await formatAndWriteMove(\n code,\n `${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}_${convertToSnakeCase(item.name)}.move`,\n \"formatAndWriteMove\"\n );\n }\n }\n }\n}\n\nfunction generateImport(projectName: string, schemaName: string, schema: SchemaType) {\n if (schema.data) {\n return schema.data.map(item => {\n return `use ${projectName}::${schemaName}_${convertToSnakeCase(item.name)}::${item.name};`\n }).join('\\n');\n } else {\n return \"\"\n }\n}\n\nexport async function generateSchemaStructure(projectName: string, schemas: Record<string, SchemaType>, path: string) {\n for (const schemaName in schemas) {\n console.log(`Schema: ${schemaName}`);\n const schema = schemas[schemaName];\n const schemaMoudle = `module ${projectName}::${schemaName}_schema {\n use std::ascii::String;\n use std::type_name;\n use sui::transfer::{public_share_object};\n use obelisk::dapps_system;\n use obelisk::dapps_schema::Dapps;\n use obelisk::storage_value::{Self, StorageValue};\n use obelisk::storage_map::{Self, StorageMap};\n use obelisk::storage_double_map::{Self, StorageDoubleMap};\n use ${projectName}::dapp_key::DappKey;\n ${generateImport(projectName, schemaName, schema)}\n\n public struct ${capitalizeAndRemoveUnderscores(schemaName)} has key, store {\n id: UID,\n ${getStructAttrsWithType(schema.structure)}\n } \n \n ${Object.entries(schema.structure).map(([key, value]) => {\n return `public fun borrow_${key}(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : &${value} {\n &self.${key}\n }\n \n public(package) fun borrow_mut_${key}(self: &mut ${capitalizeAndRemoveUnderscores(schemaName)}): &mut ${value} {\n &mut self.${key}\n }\n `\n }).join('')} \n \n public entry fun register(dapps: &mut Dapps, ctx: &mut TxContext) {\n let package_id = dapps_system::current_package_id<DappKey>();\n assert!(dapps.borrow_metadata().contains_key(package_id), 0);\n assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);\n let schema = type_name::get<${capitalizeAndRemoveUnderscores(schemaName)}>().into_string();\n assert!(!dapps.borrow_schemas().get(package_id).contains(&schema), 0);\n \n public_share_object(${capitalizeAndRemoveUnderscores(schemaName)} {\n id: object::new(ctx),\n ${Object.entries(schema.structure).map(([key, value]) => {\n let storage_type = \"\"\n if (value.includes(\"StorageValue\")) {\n storage_type = `storage_value::new()`\n } else if (value.includes(\"StorageMap\")) {\n storage_type = `storage_map::new()`\n } else if (value.includes(\"StorageDoubleMap\")) {\n storage_type = `storage_double_map::new()`\n }\n return `${key}: ${storage_type},`\n }).join(' ')\n }\n });\n \n dapps_system::add_schema<${capitalizeAndRemoveUnderscores(schemaName)}>(dapps, package_id, ctx);\n }\n \n }`;\n await formatAndWriteMove(\n schemaMoudle,\n `${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,\n \"formatAndWriteMove\"\n );\n }\n}","import { ObeliskConfig } from \"../../types\";\nimport { formatAndWriteMove } from \"../formatAndWrite\";\nimport { existsSync } from \"fs\";\n\nexport async function generateDeployHook(config: ObeliskConfig, srcPrefix: string) {\n if (\n !existsSync(\n `${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`\n )\n ) {\n let code = `module ${config.name}::deploy_hook {\n use obelisk::dapps_schema::Dapps;\n use obelisk::dapps_system;\n use ${config.name}::dapp_key::DappKey;\n use std::ascii;\n use sui::clock::Clock;\n #[test_only]\n use obelisk::dapps_schema;\n #[test_only]\n use sui::clock;\n #[test_only]\n use sui::test_scenario;\n #[test_only]\n use sui::test_scenario::Scenario;\n\n public entry fun run(dapps: &mut Dapps, clock: &Clock, ctx: &mut TxContext) {\n // Register the dapp to obelisk.\n dapps_system::register<DappKey>(\n dapps,\n ascii::string(b\"${config.name}\"),\n ascii::string(b\"${config.description}\"),\n clock,\n ctx\n );\n ${Object.keys(config.schemas).map(schemaName => {\n return `${config.name}::${schemaName}_schema::register(dapps, ctx);`\n }).join(\"\\n\")}\n \n // Logic that needs to be automated once the contract is deployed\n\n }\n\n #[test_only]\n public fun deploy_hook_for_testing(): (Scenario, Dapps) {\n let mut scenario = test_scenario::begin(@0xA);\n {\n let ctx = test_scenario::ctx(&mut scenario);\n dapps_schema::init_dapps_for_testing(ctx);\n test_scenario::next_tx(&mut scenario,@0xA);\n };\n let mut dapps = test_scenario::take_shared<Dapps>(&scenario);\n let ctx = test_scenario::ctx(&mut scenario);\n let clock = clock::create_for_testing(ctx);\n run(&mut dapps, &clock, ctx);\n clock::destroy_for_testing(clock);\n test_scenario::next_tx(&mut scenario,@0xA);\n (scenario, dapps)\n }\n}\n`;\n await formatAndWriteMove(\n code,\n `${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`,\n \"formatAndWriteMove\"\n );\n }\n}\n\nexport function generateMigrate(config: ObeliskConfig, srcPrefix: string) {\n if (\n !existsSync(\n `${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`\n )\n ) {\n let code = `module ${config.name}::migrate {\n use obelisk::world::{World, AdminCap};\n\n /// Not the right admin for this world\n const ENotAdmin: u64 = 0;\n const EWrongVersion: u64 = 1;\n const ENotUpgrade: u64 = 2;\n const VERSION: u64 = 1;\n\n public entry fun run(world: &mut World, admin_cap: &AdminCap) {\n assert!(world.admin() == object::id(admin_cap), ENotAdmin);\n assert!(world.version() < VERSION, ENotUpgrade);\n *obelisk::world::mut_version(world, admin_cap) = VERSION;\n }\n\n public fun assert_version(world: &World){\n assert!(world.version() == VERSION, EWrongVersion);\n }\n}\n`;\n formatAndWriteMove(\n code,\n `${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`,\n \"formatAndWriteMove\"\n );\n }\n}\n\n","import { ObeliskConfig } from \"../../types\";\nimport { formatAndWriteMove } from \"../formatAndWrite\";\n\nexport async function generateDappKey(config: ObeliskConfig, srcPrefix: string) {\n let code = `module ${config.name}::dapp_key {\n /// Authorization token for the app.\n public struct DappKey has drop {}\n\n public(package) fun new(): DappKey {\n DappKey { }\n }\n}\n`;\n await formatAndWriteMove(\n code,\n `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`,\n \"formatAndWriteMove\"\n );\n}\n","import { findUp } from \"find-up\";\nimport path from \"path\";\nimport esbuild from \"esbuild\";\nimport { NotInsideProjectError } from \"./errors\";\nimport { rmSync } from \"fs\";\nimport { pathToFileURL } from \"url\";\nimport os from \"os\";\n\n// In order of preference files are checked\nconst configFiles = [\n \"obelisk.config.js\",\n \"obelisk.config.mjs\",\n \"obelisk.config.ts\",\n \"obelisk.config.mts\",\n];\nconst TEMP_CONFIG = \"obelisk.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()}`)).obeliskConfig;\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 Obelisk project\";\n}"],"mappings":"AAAA,OAAOA,MAAc,WACrB,OAAOC,MAAwB,0BAE/B,eAAsBC,EACrBC,EACAC,EACkB,CAClB,IAAIC,EACAD,IACHC,EAAS,MAAML,EAAS,cAAcI,CAAkB,GAEzD,GAAI,CACH,OAAOJ,EAAS,OAAOG,EAAS,CAC/B,QAAS,CAACF,CAAkB,EAC5B,OAAQ,aACR,WAAY,IACZ,KAAM,GACN,SAAU,EACV,QAAS,GACT,eAAgB,GAChB,GAAGI,CACJ,CAAC,CACF,OAASC,EAAP,CACD,IAAIC,EACJ,OAAID,aAAiB,MACpBC,EAAUD,EAAM,QAEhBC,EAAUD,EAEX,QAAQ,IAAI,mCAAmCC,GAAS,EACjDJ,CACR,CACD,CAEA,eAAsBK,EAAiBL,EAAkC,CACxE,OAAOH,EAAS,OAAOG,EAAS,CAC/B,OAAQ,YACT,CAAC,CACF,CCtCA,OAAOM,MAAQ,mBACf,OAAOC,MAAU,YCDjB,OAAOC,MAAiB,QAEjB,IAAMC,EAAQD,EAAY,gBAAgB,EACpCE,EAAQF,EAAY,gBAAgB,EAGjDC,EAAM,IAAM,QAAQ,MAAM,KAAK,OAAO,EAGtCC,EAAM,IAAM,QAAQ,MAAM,KAAK,OAAO,ECP/B,IAAMC,EAAQA,EAAY,OAAO,SAAS,EACpCC,EAAQD,EAAY,OAAO,SAAS,EAGjDA,EAAM,IAAM,QAAQ,MAAM,KAAK,OAAO,EAGtCC,EAAM,IAAM,QAAQ,MAAM,KAAK,OAAO,EF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AMC,EAAkBD,CAAU,EAC/C,GAAI,CACF,aAAME,EAAQ,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,aAC9D,QAAE,CACAN,EAAOI,EAAa,CAAE,MAAO,EAAK,CAAC,CACrC,CACF,CAEA,eAAsBG,EACpBD,EACAG,EACA,CACA,OAAIH,IAAe,OACjBA,EAAa,MAAMI,EAAkB,EAEhCC,EAAK,WAAWL,CAAU,IAC7BA,EAAaK,EAAK,KAAK,QAAQ,IAAI,EAAGL,CAAU,EAChDA,EAAaK,EAAK,UAAUL,CAAU,GAMnCG,GAAaP,EAAG,SAAS,IAAM,QAClCD,EAAcK,CAAU,EAAE,KAC1BA,CACN,CAEA,eAAeI,GAAoB,CACjC,IAAME,EAAe,MAAMC,EAAOV,CAAW,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","code","fs","path","debug","formatAndWriteTypescript","formatTypescript","posixPath","path","existsSync","fs","deleteFolderRecursive","path","file","curPath","getStructAttrs","values","key","_","getStructTypes","values","_","type","getStructAttrsWithType","key","getStructAttrsQuery","prefixArgs","existsSync","generateSystem","config","srcPrefix","systemName","code","formatAndWriteMove","generateToml","config","srcPrefix","code","formatAndWriteMove","capitalizeAndRemoveUnderscores","input","word","index","renderSetAttrsFunc","schemaName","fields","key","type","renderSetFunc","getStructAttrsWithType","fieldName","renderGetAllFunc","getStructTypes","getStructAttrsQuery","renderGetAttrsFunc","convertToSnakeCase","generateSchemaData","projectName","schemas","path","schema","item","code","enumNames","field","name","getStructAttrs","formatAndWriteMove","generateImport","generateSchemaStructure","schemaMoudle","value","storage_type","existsSync","generateDeployHook","config","srcPrefix","code","schemaName","formatAndWriteMove","generateDappKey","config","srcPrefix","code","formatAndWriteMove","worldgen","config","srcPrefix","path","existsSync","deleteFolderRecursive","generateToml","generateDeployHook","generateSystem","generateSchemaData","generateSchemaStructure","generateDappKey","findUp","path","esbuild","NotInsideProjectError","rmSync","pathToFileURL","os","configFiles","TEMP_CONFIG","loadConfig","configPath","resolveConfigPath","esbuild","toFileURL","getUserConfigPath","path","tsConfigPath","findUp","NotInsideProjectError"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xobelisk/sui-common",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.13",
|
|
4
4
|
"description": "Common low level logic shared between packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sui",
|
|
@@ -24,7 +24,10 @@
|
|
|
24
24
|
"node": ">=18"
|
|
25
25
|
},
|
|
26
26
|
"exports": {
|
|
27
|
-
".":
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
}
|
|
28
31
|
},
|
|
29
32
|
"typesVersions": {
|
|
30
33
|
"*": {
|
|
@@ -33,7 +36,7 @@
|
|
|
33
36
|
]
|
|
34
37
|
}
|
|
35
38
|
},
|
|
36
|
-
"types": "
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
37
40
|
"dependencies": {
|
|
38
41
|
"@mysten/sui": "^1.7.0",
|
|
39
42
|
"chalk": "^5.0.1",
|
|
@@ -46,7 +49,7 @@
|
|
|
46
49
|
"glob": "^8.0.3",
|
|
47
50
|
"path": "^0.12.7",
|
|
48
51
|
"prettier": "^3.1.1",
|
|
49
|
-
"prettier-plugin-move": "^0.0.
|
|
52
|
+
"prettier-plugin-move-js": "^0.0.5",
|
|
50
53
|
"prettier-plugin-rust": "^0.1.9",
|
|
51
54
|
"prettier-plugin-solidity": "^1.1.2",
|
|
52
55
|
"typescript": "5.1.6",
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import prettier from
|
|
2
|
-
import prettierPluginMove from
|
|
1
|
+
import prettier from 'prettier';
|
|
2
|
+
import prettierPluginMove from 'prettier-plugin-move-js';
|
|
3
3
|
|
|
4
4
|
export async function formatMove(
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
content: string,
|
|
6
|
+
prettierConfigPath?: string
|
|
7
7
|
): Promise<string> {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
8
|
+
let config;
|
|
9
|
+
if (prettierConfigPath) {
|
|
10
|
+
config = await prettier.resolveConfig(prettierConfigPath);
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
return prettier.format(content, {
|
|
14
|
+
plugins: [prettierPluginMove],
|
|
15
|
+
parser: 'move-parse',
|
|
16
|
+
printWidth: 120,
|
|
17
|
+
semi: true,
|
|
18
|
+
tabWidth: 2,
|
|
19
|
+
useTabs: false,
|
|
20
|
+
bracketSpacing: true,
|
|
21
|
+
...config,
|
|
22
|
+
});
|
|
23
|
+
} catch (error) {
|
|
24
|
+
let message;
|
|
25
|
+
if (error instanceof Error) {
|
|
26
|
+
message = error.message;
|
|
27
|
+
} else {
|
|
28
|
+
message = error;
|
|
29
|
+
}
|
|
30
|
+
console.log(`Error during output formatting: ${message}`);
|
|
31
|
+
return content;
|
|
32
|
+
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export async function formatTypescript(content: string): Promise<string> {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
return prettier.format(content, {
|
|
37
|
+
parser: 'typescript',
|
|
38
|
+
});
|
|
39
39
|
}
|