Skip to content

Commit 1dd0da8

Browse files
committed
feat: @ckb-ccc/molecule
1 parent 8e1fcf9 commit 1dd0da8

30 files changed

+7508
-2942
lines changed

packages/core/src/molecule/predefined.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ export const Bool: Codec<boolean> = Codec.from({
5757
export const BoolOpt = option(Bool);
5858
export const BoolVec = vector(Bool);
5959

60+
export const Byte: Codec<HexLike, Hex> = Codec.from({
61+
byteLength: 1,
62+
encode: (value) => bytesFrom(value),
63+
decode: (buffer) => hexFrom(buffer),
64+
});
65+
export const ByteOpt = option(Byte);
66+
6067
export const Byte4: Codec<HexLike, Hex> = Codec.from({
6168
byteLength: 4,
6269
encode: (value) => bytesFrom(value),

packages/molecule/.npmignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
node_modules/
2+
misc/
3+
4+
*test.js
5+
*test.ts
6+
*test.d.ts
7+
*test.d.ts.map
8+
*spec.js
9+
*spec.ts
10+
*spec.d.ts
11+
*spec.d.ts.map
12+
13+
tsconfig.json
14+
tsconfig.*.json
15+
eslint.config.mjs
16+
.prettierrc
17+
.prettierignore
18+
19+
tsconfig.tsbuildinfo
20+
tsconfig.*.tsbuildinfo
21+
.github/

packages/molecule/.prettierignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
node_modules/
2+
3+
dist/
4+
dist.commonjs/
5+
6+
.npmignore
7+
.prettierrc
8+
tsconfig.json
9+
eslint.config.mjs
10+
.prettierrc
11+
12+
tsconfig.tsbuildinfo
13+
.github/

packages/molecule/.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": false,
3+
"trailingComma": "all",
4+
"plugins": ["prettier-plugin-organize-imports"]
5+
}

packages/molecule/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<p align="center">
2+
<a href="https://app.ckbccc.com/">
3+
<img alt="Logo" src="https://raw.githubusercontent.com/ckb-devrel/ccc/master/assets/logoAndText.svg" style="height: 8rem; max-width: 90%; padding: 0.5rem 0;" />
4+
</a>
5+
</p>
6+
7+
<h1 align="center" style="font-size: 48px;">
8+
CCC's Support for Molecule
9+
</h1>
10+
11+
<p align="center">
12+
<a href="https://www.npmjs.com/package/@ckb-ccc/ssri"><img
13+
alt="NPM Version" src="https://img.shields.io/npm/v/%40ckb-ccc%2Fssri"
14+
/></a>
15+
<img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/ckb-devrel/ccc" />
16+
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/ckb-devrel/ccc/master" />
17+
<img alt="GitHub branch check runs" src="https://img.shields.io/github/check-runs/ckb-devrel/ccc/master" />
18+
<a href="https://live.ckbccc.com/"><img
19+
alt="Playground" src="https://img.shields.io/website?url=https%3A%2F%2Flive.ckbccc.com%2F&label=Playground"
20+
/></a>
21+
<a href="https://app.ckbccc.com/"><img
22+
alt="App" src="https://img.shields.io/website?url=https%3A%2F%2Fapp.ckbccc.com%2F&label=App"
23+
/></a>
24+
<a href="https://docs.ckbccc.com/"><img
25+
alt="Docs" src="https://img.shields.io/website?url=https%3A%2F%2Fdocs.ckbccc.com%2F&label=Docs"
26+
/></a>
27+
</p>
28+
29+
<p align="center">
30+
CCC - CKBers' Codebase is a one-stop solution for your CKB JS/TS ecosystem development.
31+
<br />
32+
Empower yourself with CCC to discover the unlimited potential of CKB.
33+
<br />
34+
Interoperate with wallets from different chain ecosystems.
35+
<br />
36+
Fully enabling CKB's Turing completeness and cryptographic freedom power.
37+
</p>
38+
39+
Get `CodecMap` from Molecule schema.
40+
41+
<h3 align="center">
42+
Read more about CCC on <a href="https://docs.ckbccc.com">our website</a> or <a href="https://github.com/ckb-devrel/ccc">GitHub Repo</a>.
43+
</h3>

packages/molecule/eslint.config.mjs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// @ts-check
2+
3+
import eslint from "@eslint/js";
4+
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
5+
import tseslint from "typescript-eslint";
6+
7+
import { dirname } from "path";
8+
import { fileURLToPath } from "url";
9+
10+
export default [
11+
{
12+
ignores: ["**/grammar.js"],
13+
},
14+
...tseslint.config({
15+
files: ["**/*.ts"],
16+
extends: [
17+
eslint.configs.recommended,
18+
...tseslint.configs.recommendedTypeChecked,
19+
],
20+
rules: {
21+
"@typescript-eslint/no-unused-vars": [
22+
"error",
23+
{
24+
args: "all",
25+
argsIgnorePattern: "^_",
26+
caughtErrors: "all",
27+
caughtErrorsIgnorePattern: "^_",
28+
destructuredArrayIgnorePattern: "^_",
29+
varsIgnorePattern: "^_",
30+
ignoreRestSiblings: true,
31+
},
32+
],
33+
"@typescript-eslint/unbound-method": ["error", { ignoreStatic: true }],
34+
"@typescript-eslint/no-unsafe-member-access": "off",
35+
"@typescript-eslint/require-await": "off",
36+
"no-empty": "off",
37+
"prefer-const": [
38+
"error",
39+
{ ignoreReadBeforeAssign: true, destructuring: "all" },
40+
],
41+
},
42+
languageOptions: {
43+
parserOptions: {
44+
project: true,
45+
tsconfigRootDir: dirname(fileURLToPath(import.meta.url)),
46+
},
47+
},
48+
}),
49+
eslintPluginPrettierRecommended,
50+
];

packages/molecule/jest.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
testMatch: ["**/*.spec.ts"],
6+
moduleFileExtensions: ["ts", "js", "json", "peggy", "node"],
7+
transform: {
8+
"^.+\\.ts$": ["ts-jest", { tsconfig: "tsconfig.json" }],
9+
"^.+\\.peggy$": [
10+
"<rootDir>/peggy-transformer.js",
11+
{ tsconfig: "tsconfig.json" },
12+
],
13+
},
14+
};

packages/molecule/package.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"name": "@ckb-ccc/molecule",
3+
"version": "0.0.1",
4+
"description": "Molecule parser for CKB",
5+
"author": "Alive24 <xct24@live.com>",
6+
"homepage": "https://github.com/ckb-devrel/ccc",
7+
"license": "MIT",
8+
"main": "./dist.commonjs/index.js",
9+
"module": "./dist/index.js",
10+
"exports": {
11+
".": {
12+
"import": "./dist/index.js",
13+
"default": "./dist.commonjs/index.js"
14+
},
15+
"./barrel": {
16+
"import": "./dist/barrel.js",
17+
"default": "./dist.commonjs/barrel.js"
18+
}
19+
},
20+
"private": false,
21+
"engines": {
22+
"node": ">=12.0.0"
23+
},
24+
"repository": {
25+
"type": "git",
26+
"url": "git+https://github.com/ckb-devrel/ccc.git"
27+
},
28+
"bugs": {
29+
"url": "https://github.com/ckb-devrel/ccc/issues"
30+
},
31+
"scripts": {
32+
"test": "jest",
33+
"fmt": "prettier --write \"{src,tests,examples}/**/*.ts\" package.json",
34+
"lint": "eslint ./src",
35+
"build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
36+
"clean": "rm -rf lib"
37+
},
38+
"dependencies": {
39+
"@ckb-ccc/core": "workspace:*",
40+
"glob": "^10.3.10",
41+
"relative": "^3.0.2"
42+
},
43+
"devDependencies": {
44+
"@eslint/js": "^9.1.1",
45+
"eslint": "^9.1.0",
46+
"eslint-config-prettier": "^9.1.0",
47+
"eslint-plugin-prettier": "^5.1.3",
48+
"typescript-eslint": "^7.7.0",
49+
"@types/js-yaml": "^4.0.9",
50+
"copyfiles": "^2.4.1",
51+
"js-yaml": "^4.1.0",
52+
"jsbi": "^4.1.0",
53+
"peggy": "^4.0.3",
54+
"rimraf": "^5.0.5",
55+
"prettier-plugin-organize-imports": "^3.2.4"
56+
},
57+
"publishConfig": {
58+
"access": "public"
59+
}
60+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const peggy = require("peggy");
2+
3+
module.exports = {
4+
process(sourceText) {
5+
const parser = peggy.generate(sourceText, {
6+
output: "source",
7+
format: "commonjs",
8+
});
9+
10+
return {
11+
code: parser,
12+
};
13+
},
14+
};

packages/molecule/src/barrel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./molecule";
2+
export * from "./type";

0 commit comments

Comments
 (0)