@0xobelisk/sui-common 1.1.6 → 1.1.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xobelisk/sui-common",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "Common low level logic shared between packages",
5
5
  "keywords": [
6
6
  "sui",
@@ -38,7 +38,6 @@
38
38
  },
39
39
  "types": "./dist/index.d.ts",
40
40
  "dependencies": {
41
- "@mysten/sui": "^1.7.0",
42
41
  "chalk": "^5.0.1",
43
42
  "debug": "^4.3.4",
44
43
  "dotenv": "^16.0.3",
@@ -65,7 +64,10 @@
65
64
  "@types/yargs": "^17.0.10",
66
65
  "tsup": "^6.7.0",
67
66
  "tsx": "^3.12.6",
68
- "vitest": "^2.1.3"
67
+ "vitest": "^2.1.3",
68
+ "eslint": "^8.56.0",
69
+ "eslint-config-prettier": "^9.1.0",
70
+ "prettier": "3.3.3"
69
71
  },
70
72
  "scripts": {
71
73
  "build": "pnpm run build:js",
@@ -74,6 +76,10 @@
74
76
  "clean:js": "rimraf dist",
75
77
  "dev": "tsup --watch",
76
78
  "lint": "eslint . --ext .ts",
77
- "test": "vitest"
79
+ "test": "vitest",
80
+ "format": "prettier --write .",
81
+ "format:check": "prettier --check .",
82
+ "type-check": "tsc --noEmit",
83
+ "validate": "pnpm format:check && pnpm type-check"
78
84
  }
79
85
  }
@@ -1,7 +1,7 @@
1
- import { debug as parentDebug } from "../debug";
1
+ import { debug as parentDebug } from '../debug';
2
2
 
3
- export const debug = parentDebug.extend("codegen");
4
- export const error = parentDebug.extend("codegen");
3
+ export const debug = parentDebug.extend('codegen');
4
+ export const error = parentDebug.extend('codegen');
5
5
 
6
6
  // Pipe debug output to stdout instead of stderr
7
7
  debug.log = console.debug.bind(console);
@@ -1,3 +1,3 @@
1
1
  // import "./modules.d";
2
- export * from "./utils";
3
- export * from "./types";
2
+ export * from './utils';
3
+ export * from './types';
@@ -1 +1 @@
1
- declare module "prettier-plugin-rust";
1
+ declare module 'prettier-plugin-rust';
@@ -16,14 +16,9 @@ export type BaseType =
16
16
  | 'vector<u128>'
17
17
  | string;
18
18
 
19
- export type StorageDataType =
20
- | 'Struct'
21
- | 'Enum';
19
+ export type StorageDataType = 'Struct' | 'Enum';
22
20
 
23
- export type StorageMapType =
24
- | 'Map'
25
- | 'Bag'
26
- | 'Table';
21
+ export type StorageMapType = 'Map' | 'Bag' | 'Table';
27
22
 
28
23
  type Address = string;
29
24
  type Bool = boolean;
@@ -48,10 +43,30 @@ export type BaseValueType =
48
43
  | Vector<U64>
49
44
  | Vector<U128>;
50
45
 
51
- export type SchemaData = Record<string, string> | string[]
52
- export type SchemaType = string
53
- export type EventData = Record<string, string>
54
- export type ErrorData = Record<string, string>
46
+ export type SchemaData = Record<string, string> | string[];
47
+ export type SchemaType = string;
48
+ export type EventData = Record<string, string>;
49
+ export type ErrorData = Record<string, string>;
50
+
51
+ type DataType = any;
52
+
53
+ export function storage<T extends DataType>(value: T): SchemaType;
54
+ export function storage<K extends DataType, V extends DataType>(key: K, value: V): SchemaType;
55
+ export function storage<K1 extends DataType, K2 extends DataType, V extends DataType>(
56
+ key1: K1,
57
+ key2: K2,
58
+ value: V
59
+ ): SchemaType;
60
+ export function storage(...args: DataType[]): SchemaType {
61
+ if (args.length === 1) {
62
+ return `StorageValue<${args[0]}>`;
63
+ } else if (args.length === 2) {
64
+ return `StorageMap<${args[0]}, ${args[1]}>`;
65
+ } else if (args.length === 3) {
66
+ return `StorageDoubleMap<${args[0]}, ${args[1]}, ${args[2]}>`;
67
+ }
68
+ throw new Error('Invalid number of arguments for storage()');
69
+ }
55
70
 
56
71
  export type DubheConfig = {
57
72
  name: string;
@@ -1,33 +1,28 @@
1
- import { findUp } from "find-up";
2
- import path from "path";
3
- import esbuild from "esbuild";
4
- import { NotInsideProjectError } from "./errors";
5
- import { rmSync } from "fs";
6
- import { pathToFileURL } from "url";
7
- import os from "os";
1
+ import { findUp } from 'find-up';
2
+ import path from 'path';
3
+ import esbuild from 'esbuild';
4
+ import { NotInsideProjectError } from './errors';
5
+ import { rmSync } from 'fs';
6
+ import { pathToFileURL } from 'url';
7
+ import os from 'os';
8
8
 
9
9
  // In order of preference files are checked
10
- const configFiles = [
11
- "dubhe.config.js",
12
- "dubhe.config.mjs",
13
- "dubhe.config.ts",
14
- "dubhe.config.mts",
15
- ];
16
- const TEMP_CONFIG = "dubhe.config.example.mjs";
10
+ const configFiles = ['dubhe.config.js', 'dubhe.config.mjs', 'dubhe.config.ts', 'dubhe.config.mts'];
11
+ const TEMP_CONFIG = 'dubhe.config.example.mjs';
17
12
 
18
13
  export async function loadConfig(configPath?: string): Promise<unknown> {
19
14
  configPath = await resolveConfigPath(configPath);
20
15
  try {
21
16
  await esbuild.build({
22
17
  entryPoints: [configPath],
23
- format: "esm",
18
+ format: 'esm',
24
19
  outfile: TEMP_CONFIG,
25
20
  // https://esbuild.github.io/getting-started/#bundling-for-node
26
- platform: "node",
21
+ platform: 'node',
27
22
  // bundle local imports (otherwise it may error, js can't import ts)
28
23
  bundle: true,
29
24
  // avoid bundling external imports (it's unnecessary and esbuild can't handle all node features)
30
- packages: "external",
25
+ packages: 'external'
31
26
  });
32
27
  configPath = await resolveConfigPath(TEMP_CONFIG, true);
33
28
  // Node.js caches dynamic imports, so without appending a cache breaking
@@ -39,10 +34,7 @@ export async function loadConfig(configPath?: string): Promise<unknown> {
39
34
  }
40
35
  }
41
36
 
42
- export async function resolveConfigPath(
43
- configPath: string | undefined,
44
- toFileURL?: boolean
45
- ) {
37
+ export async function resolveConfigPath(configPath: string | undefined, toFileURL?: boolean) {
46
38
  if (configPath === undefined) {
47
39
  configPath = await getUserConfigPath();
48
40
  } else {
@@ -54,9 +46,7 @@ export async function resolveConfigPath(
54
46
 
55
47
  // Add `file:///` for Windows support
56
48
  // (see https://github.com/nodejs/node/issues/31710)
57
- return toFileURL && os.platform() === "win32"
58
- ? pathToFileURL(configPath).href
59
- : configPath;
49
+ return toFileURL && os.platform() === 'win32' ? pathToFileURL(configPath).href : configPath;
60
50
  }
61
51
 
62
52
  async function getUserConfigPath() {
@@ -1,5 +1,4 @@
1
-
2
1
  export class NotInsideProjectError extends Error {
3
- name = "NotInsideProjectError";
4
- message = "You are not inside a Dubhe project";
5
- }
2
+ name = 'NotInsideProjectError';
3
+ message = 'You are not inside a Dubhe project';
4
+ }
@@ -1,39 +1,36 @@
1
1
  import prettier from 'prettier';
2
2
  import prettierPluginMove from 'prettier-plugin-move-js';
3
3
 
4
- export async function formatMove(
5
- content: string,
6
- prettierConfigPath?: string
7
- ): Promise<string> {
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
- }
4
+ export async function formatMove(content: string, prettierConfigPath?: string): Promise<string> {
5
+ let config;
6
+ if (prettierConfigPath) {
7
+ config = await prettier.resolveConfig(prettierConfigPath);
8
+ }
9
+ try {
10
+ return prettier.format(content, {
11
+ plugins: [prettierPluginMove],
12
+ parser: 'move-parse',
13
+ printWidth: 120,
14
+ semi: true,
15
+ tabWidth: 2,
16
+ useTabs: false,
17
+ bracketSpacing: true,
18
+ ...config
19
+ });
20
+ } catch (error) {
21
+ let message;
22
+ if (error instanceof Error) {
23
+ message = error.message;
24
+ } else {
25
+ message = error;
26
+ }
27
+ console.log(`Error during output formatting: ${message}`);
28
+ return content;
29
+ }
33
30
  }
34
31
 
35
32
  export async function formatTypescript(content: string): Promise<string> {
36
- return prettier.format(content, {
37
- parser: 'typescript',
38
- });
33
+ return prettier.format(content, {
34
+ parser: 'typescript'
35
+ });
39
36
  }
@@ -1,7 +1,7 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { formatMove, formatTypescript } from "./format";
4
- import { debug } from "../debug";
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { formatMove, formatTypescript } from './format';
4
+ import { debug } from '../debug';
5
5
 
6
6
  export async function formatAndWriteMove(
7
7
  output: string,
@@ -9,27 +9,30 @@ export async function formatAndWriteMove(
9
9
  logPrefix?: string
10
10
  ): Promise<void> {
11
11
  const formattedOutput = await formatMove(output);
12
- let schemaPrefix =
13
- ` // Copyright (c) Obelisk Labs, Inc.
12
+ let schemaPrefix = ` // Copyright (c) Obelisk Labs, Inc.
14
13
  // SPDX-License-Identifier: Apache-2.0
15
14
  #[allow(unused_use)]
16
15
 
17
16
  /* Autogenerated file. Do not edit manually. */
18
17
 
19
- `
18
+ `;
20
19
 
21
- let initPrefix = `#[test_only]`
20
+ let initPrefix = `#[test_only]`;
22
21
 
23
- let code = schemaPrefix + formattedOutput
22
+ let code = schemaPrefix + formattedOutput;
24
23
 
25
- let deployHookPrefix = `#[allow(lint(share_owned))]`
24
+ let deployHookPrefix = `#[allow(lint(share_owned))]`;
26
25
 
27
- if (fullOutputPath.includes(".toml") || fullOutputPath.includes("system") || fullOutputPath.includes("migrate")) {
28
- code = formattedOutput
29
- } else if (fullOutputPath.includes("init")) {
30
- code = initPrefix + formattedOutput
31
- } else if (fullOutputPath.includes("genesis")) {
32
- code = deployHookPrefix + formattedOutput
26
+ if (
27
+ fullOutputPath.includes('.toml') ||
28
+ fullOutputPath.includes('system') ||
29
+ fullOutputPath.includes('migrate')
30
+ ) {
31
+ code = formattedOutput;
32
+ } else if (fullOutputPath.includes('init')) {
33
+ code = initPrefix + formattedOutput;
34
+ } else if (fullOutputPath.includes('genesis')) {
35
+ code = deployHookPrefix + formattedOutput;
33
36
  }
34
37
 
35
38
  await fs.mkdir(path.dirname(fullOutputPath), { recursive: true });
@@ -44,9 +47,9 @@ export async function formatAndWriteMove(
44
47
  * @param logPrefix prefix for debug logs
45
48
  */
46
49
  export async function formatAndWriteTypescript(
47
- output: string,
48
- fullOutputPath: string,
49
- logPrefix: string,
50
+ output: string,
51
+ fullOutputPath: string,
52
+ logPrefix: string
50
53
  ): Promise<void> {
51
54
  const formattedOutput = await formatTypescript(output);
52
55
 
@@ -4,5 +4,5 @@
4
4
  * because solc expects `/` as path separator, but path.join produces `\` if the user is on windows.
5
5
  */
6
6
  export function posixPath(path: string): string {
7
- return path.replace(/\\/g, "/");
7
+ return path.replace(/\\/g, '/');
8
8
  }
@@ -2,21 +2,21 @@ import { MoveType } from '../../types';
2
2
  import fs from 'fs';
3
3
 
4
4
  export function deleteFolderRecursive(path: string) {
5
- if (fs.existsSync(path)) {
6
- fs.readdirSync(path).forEach(file => {
7
- const curPath = `${path}/${file}`;
8
- if (fs.lstatSync(curPath).isDirectory()) {
9
- deleteFolderRecursive(curPath);
10
- } else {
11
- fs.unlinkSync(curPath);
12
- }
13
- });
14
- fs.rmdirSync(path);
15
- }
5
+ if (fs.existsSync(path)) {
6
+ fs.readdirSync(path).forEach((file) => {
7
+ const curPath = `${path}/${file}`;
8
+ if (fs.lstatSync(curPath).isDirectory()) {
9
+ deleteFolderRecursive(curPath);
10
+ } else {
11
+ fs.unlinkSync(curPath);
12
+ }
13
+ });
14
+ fs.rmdirSync(path);
15
+ }
16
16
  }
17
17
 
18
18
  export function capitalizeFirstLetter(input: string): string {
19
- return input.charAt(0).toUpperCase() + input.slice(1);
19
+ return input.charAt(0).toUpperCase() + input.slice(1);
20
20
  }
21
21
 
22
22
  /**
@@ -25,17 +25,15 @@ export function capitalizeFirstLetter(input: string): string {
25
25
  * @param prefixArgs
26
26
  * @return [ name, age, birth_time ]
27
27
  */
28
- export function getStructAttrs(
29
- values: Record<string, string> | string
30
- ): string {
31
- return Object.entries(values)
32
- .map(([key, _]) => `${key}`)
33
- .join(',');
28
+ export function getStructAttrs(values: Record<string, string> | string): string {
29
+ return Object.entries(values)
30
+ .map(([key, _]) => `${key}`)
31
+ .join(',');
34
32
  }
35
33
 
36
34
  function isAddress(str: string): boolean {
37
- const regex = /^0x[a-fA-F0-9]+$/;
38
- return regex.test(str);
35
+ const regex = /^0x[a-fA-F0-9]+$/;
36
+ return regex.test(str);
39
37
  }
40
38
 
41
39
  /**
@@ -44,10 +42,8 @@ function isAddress(str: string): boolean {
44
42
  * @return ( bool , u64 , u64)
45
43
  */
46
44
  // export function getStructTypes(values: SchemaType): string {
47
- export function getStructTypes(
48
- values: Record<string, string>
49
- ): string {
50
- return `(${Object.entries(values).map(([_, type]) => `${type}`)})`;
45
+ export function getStructTypes(values: Record<string, string>): string {
46
+ return `(${Object.entries(values).map(([_, type]) => `${type}`)})`;
51
47
  }
52
48
 
53
49
  /**
@@ -55,30 +51,26 @@ export function getStructTypes(
55
51
  * @param values
56
52
  * @return Attributes and types of the struct. [ name: string, age: u64 ]
57
53
  */
58
- export function getStructAttrsWithType(
59
- values: Record<string, string>
60
- ): string[] {
61
- return Object.entries(values).map(([key, type]) => `${key}: ${type}`);
54
+ export function getStructAttrsWithType(values: Record<string, string>): string[] {
55
+ return Object.entries(values).map(([key, type]) => `${key}: ${type}`);
62
56
  }
63
57
 
64
58
  /**
65
59
  * @param values
66
60
  * @return [ data.name, data.age ]
67
61
  */
68
- export function getStructAttrsQuery(
69
- values: Record<string, string>,
70
- ): string[] {
71
- return Object.entries(values).map(([key, _]) => `self.${key}`);
62
+ export function getStructAttrsQuery(values: Record<string, string>): string[] {
63
+ return Object.entries(values).map(([key, _]) => `self.${key}`);
72
64
  }
73
65
 
74
66
  export function containsString(obj: Record<string, any>, searchString: string): boolean {
75
- for (const key in obj) {
76
- if (obj.hasOwnProperty(key)) {
77
- const value = obj[key];
78
- if (typeof value === 'string' && value === searchString) {
79
- return true;
80
- }
81
- }
82
- }
83
- return false;
67
+ for (const key in obj) {
68
+ if (obj.hasOwnProperty(key)) {
69
+ const value = obj[key];
70
+ if (typeof value === 'string' && value === searchString) {
71
+ return true;
72
+ }
73
+ }
74
+ }
75
+ return false;
84
76
  }
@@ -1,16 +1,13 @@
1
1
  import { DubheConfig } from '../../types';
2
2
  import { formatAndWriteMove } from '../formatAndWrite';
3
3
 
4
- export async function generateDappKey(
5
- config: DubheConfig,
6
- srcPrefix: string
7
- ) {
8
- console.log('\nšŸ”‘ Starting DappKey Generation...');
9
- console.log(
10
- ` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`
11
- );
4
+ export async function generateDappKey(config: DubheConfig, srcPrefix: string) {
5
+ console.log('\nšŸ”‘ Starting DappKey Generation...');
6
+ console.log(
7
+ ` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`
8
+ );
12
9
 
13
- let code = `module ${config.name}::${config.name}_dapp_key {
10
+ let code = `module ${config.name}::${config.name}_dapp_key {
14
11
  \t/// Authorization token for the app.
15
12
  \tpublic struct DappKey has drop {}
16
13
 
@@ -19,10 +16,10 @@ export async function generateDappKey(
19
16
  \t}
20
17
  }
21
18
  `;
22
- await formatAndWriteMove(
23
- code,
24
- `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`,
25
- 'formatAndWriteMove'
26
- );
27
- console.log('āœ… DappKey Generation Complete\n');
19
+ await formatAndWriteMove(
20
+ code,
21
+ `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`,
22
+ 'formatAndWriteMove'
23
+ );
24
+ console.log('āœ… DappKey Generation Complete\n');
28
25
  }
@@ -3,19 +3,16 @@ import { formatAndWriteMove } from '../formatAndWrite';
3
3
  import { existsSync } from 'fs';
4
4
  import { capitalizeAndRemoveUnderscores } from './generateSchema';
5
5
 
6
- export async function generateDefaultSchema(
7
- config: DubheConfig,
8
- srcPrefix: string
9
- ) {
10
- await generateDappSchemaMetadata(config, srcPrefix);
11
- await generateDappSchema(config, srcPrefix);
12
- await generateDappSystem(config, srcPrefix);
6
+ export async function generateDefaultSchema(config: DubheConfig, srcPrefix: string) {
7
+ await generateDappSchemaMetadata(config, srcPrefix);
8
+ await generateDappSchema(config, srcPrefix);
9
+ await generateDappSystem(config, srcPrefix);
13
10
  }
14
11
 
15
12
  async function generateDappSchemaMetadata(config: DubheConfig, srcPrefix: string) {
16
- const path = `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp/metadata.move`
17
- if (!existsSync(path)) {
18
- let code = `module ${config.name}::${config.name}_dapp_metadata {
13
+ const path = `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp/metadata.move`;
14
+ if (!existsSync(path)) {
15
+ let code = `module ${config.name}::${config.name}_dapp_metadata {
19
16
  use std::ascii::String;
20
17
 
21
18
  public struct DappMetadata has drop, copy, store {
@@ -112,19 +109,14 @@ async function generateDappSchemaMetadata(config: DubheConfig, srcPrefix: string
112
109
 
113
110
  }
114
111
  `;
115
- await formatAndWriteMove(
116
- code,
117
- path,
118
- 'formatAndWriteMove'
119
- );
120
- }
112
+ await formatAndWriteMove(code, path, 'formatAndWriteMove');
113
+ }
121
114
  }
122
115
 
123
-
124
116
  async function generateDappSchema(config: DubheConfig, srcPrefix: string) {
125
- const path = `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp/schema.move`
126
- if (!existsSync(path)) {
127
- let code = `module ${config.name}::${config.name}_dapp_schema {
117
+ const path = `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp/schema.move`;
118
+ if (!existsSync(path)) {
119
+ let code = `module ${config.name}::${config.name}_dapp_schema {
128
120
  use ${config.name}::${config.name}_dapp_metadata::DappMetadata;
129
121
  use dubhe::storage_value;
130
122
  use dubhe::storage_value::StorageValue;
@@ -226,18 +218,14 @@ async function generateDappSchema(config: DubheConfig, srcPrefix: string) {
226
218
  }
227
219
  }
228
220
  `;
229
- await formatAndWriteMove(
230
- code,
231
- path,
232
- 'formatAndWriteMove'
233
- );
234
- }
221
+ await formatAndWriteMove(code, path, 'formatAndWriteMove');
222
+ }
235
223
  }
236
224
 
237
225
  async function generateDappSystem(config: DubheConfig, srcPrefix: string) {
238
- const path = `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp/system.move`
239
- if (!existsSync(path)) {
240
- let code = `module ${config.name}::${config.name}_dapp_system {
226
+ const path = `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp/system.move`;
227
+ if (!existsSync(path)) {
228
+ let code = `module ${config.name}::${config.name}_dapp_system {
241
229
  use std::ascii::String;
242
230
  use std::ascii;
243
231
  use dubhe::type_info;
@@ -325,10 +313,6 @@ async function generateDappSystem(config: DubheConfig, srcPrefix: string) {
325
313
 
326
314
 
327
315
  `;
328
- await formatAndWriteMove(
329
- code,
330
- path,
331
- 'formatAndWriteMove'
332
- );
333
- }
334
- }
316
+ await formatAndWriteMove(code, path, 'formatAndWriteMove');
317
+ }
318
+ }
@@ -1,42 +1,39 @@
1
- import {BaseType, ErrorData, SchemaType} from '../../types';
1
+ import { BaseType, ErrorData, SchemaType } from '../../types';
2
2
  import { formatAndWriteMove } from '../formatAndWrite';
3
3
  import {
4
- getStructAttrsWithType,
5
- getStructAttrs,
6
- getStructTypes,
7
- getStructAttrsQuery,
4
+ getStructAttrsWithType,
5
+ getStructAttrs,
6
+ getStructTypes,
7
+ getStructAttrsQuery
8
8
  } from './common';
9
9
 
10
10
  function convertToSnakeCase(input: string): string {
11
- return input
12
- .replace(/([A-Z])/g, '_$1')
13
- .toLowerCase()
14
- .replace(/^_/, '');
11
+ return input
12
+ .replace(/([A-Z])/g, '_$1')
13
+ .toLowerCase()
14
+ .replace(/^_/, '');
15
15
  }
16
16
 
17
- export async function generateSchemaError(
18
- projectName: string,
19
- errors: ErrorData,
20
- path: string
21
- ) {
22
- console.log('\nšŸ“¦ Starting Schema Error Generation...');
17
+ export async function generateSchemaError(projectName: string, errors: ErrorData, path: string) {
18
+ console.log('\nšŸ“¦ Starting Schema Error Generation...');
23
19
 
24
- let code = `module ${projectName}::${projectName}_errors {
25
- ${Object.entries(errors).map(([name, message]) => {
26
- console.log(` ā”œā”€ Generating Error: ${name}`);
27
- console.log(` │ └─ Message: ${message}`);
28
- return `#[error]
29
- const ${name}: vector<u8> = b"${message}";
30
- public fun ${convertToSnakeCase(name)}_error(condition: bool) { assert!(condition, ${name}) }
31
- `
32
- }).join('\n')}
33
- }`
20
+ let code = `module ${projectName}::${projectName}_errors {
21
+ ${Object.entries(errors)
22
+ .map(([name, message]) => {
23
+ console.log(` ā”œā”€ Generating Error: ${name}`);
24
+ console.log(` │ └─ Message: ${message}`);
25
+ return `#[error]
26
+ const ${name.toUpperCase()}: vector<u8> = b"${message}";
27
+ public fun ${name}_error(condition: bool) { assert!(condition, ${name.toUpperCase()}) }
28
+ `;
29
+ })
30
+ .join('\n')}
31
+ }`;
34
32
 
35
-
36
- await formatAndWriteMove(
37
- code,
38
- `${path}/contracts/${projectName}/sources/codegen/errors.move`,
39
- 'formatAndWriteMove'
40
- );
41
- console.log('āœ… Schema Error Generation Complete\n');
42
- }
33
+ await formatAndWriteMove(
34
+ code,
35
+ `${path}/contracts/${projectName}/sources/codegen/errors.move`,
36
+ 'formatAndWriteMove'
37
+ );
38
+ console.log('āœ… Schema Error Generation Complete\n');
39
+ }