Skip to content

Commit

Permalink
feat(docs): Autogenerated Aztec-nr reference docs (#3481)
Browse files Browse the repository at this point in the history
JS script with a bunch of Regex for autogenerating Aztec.nr reference in
the docs

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [ ] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [ ] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [ ] Every change is related to the PR description.
- [ ] I have
[linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
this pull request to relevant issues (if any exist).

---------

Co-authored-by: José Pedro Sousa <[email protected]>
  • Loading branch information
catmcgee and signorecello authored Feb 22, 2024
1 parent 89af734 commit aebf762
Show file tree
Hide file tree
Showing 11 changed files with 380 additions and 27 deletions.
5 changes: 5 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

docs/developers/contracts/references/aztec-nr
src/preprocess/developers

/src/preprocess/AztecnrReferenceAutogenStructure.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Allows us to modify the storage by inserting a note into the set.

A hash of the note will be generated, and inserted into the note hash tree, allowing us to later use in contract interactions. Recall that the content of the note should be shared with the owner to allow them to use it, as mentioned this can be done via an [encrypted log](../../writing_contracts/events/emit_event.md#encrypted-events), or offchain via web2, or completely offline.

#include_code insert /noir-projects/aztec-nr/easy-private-state/src/easy_private_state.nr rust
#include_code insert /noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr rust

### `insert_from_public`

Expand All @@ -220,7 +220,7 @@ Nullifiers are emitted when reading values to make sure that they are up to date

An example of how to use this operation is visible in the `easy_private_state`:

#include_code remove /noir-projects/aztec-nr/easy-private-state/src/easy_private_state.nr rust
#include_code remove /noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr rust

### `get_notes`

Expand All @@ -232,7 +232,7 @@ Because of this limit, we should always consider using the second argument `Note

An example of such options is using the [filter_notes_min_sum](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/aztec-nr/value-note/src/filter.nr) to get "enough" notes to cover a given value. Essentially, this function will return just enough notes to cover the amount specified such that we don't need to read all our notes. For users with a lot of notes, this becomes increasingly important.

#include_code get_notes /noir-projects/aztec-nr/easy-private-state/src/easy_private_state.nr rust
#include_code get_notes /noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr rust

### `view_notes`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ In the public context this header is set by sequencer (sequencer executes public

Just like with the `is_contract_deployment` flag mentioned earlier. This data will only be set to true when the current transaction is one in which a contract is being deployed.

#include_code contract-deployment-data /noir-projects/noir-protocol-circuits/src/crates/types/src/contrakt/deployment_data.nr rust
#include_code contract-deployment-data /noir-projects/noir-protocol-circuits/src/crates/types/src/contrakt/contract_deployment_data.nr rust

### Private Global Variables

Expand Down
10 changes: 5 additions & 5 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"scripts": {
"docusaurus": "docusaurus",
"start": "yarn preprocess && yarn typedoc && docusaurus start --host 0.0.0.0",
"start:dev": "concurrently \"yarn preprocess:dev\" \"yarn typedoc:dev\" \"sleep 2 && docusaurus start --host 0.0.0.0\"",
"start:dev:local": "concurrently \"yarn preprocess:dev\" \"yarn typedoc:dev\" \"sleep 2 && docusaurus start\"",
"start:dev": "yarn start",
"start:dev:local": "yarn preprocess && yarn typedoc && docusaurus start",
"build": "./scripts/build.sh",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "rm -rf 'processed-docs' 'processed-docs-cache' docs/apis && docusaurus clear",
"clear": "rm -rf 'processed-docs' 'processed-docs-cache' docs/apis && docusaurus clear && rm 'src/preprocess/AztecnrReferenceAutogenStructure.json' && rm -rf 'docs/developers/references/aztec-nr'",
"serve": "docusaurus serve",
"preprocess": "yarn node -r dotenv/config ./src/preprocess/index.js",
"preprocess:dev": "nodemon --config nodemon.json ./src/preprocess/index.js",
"preprocess": "yarn node -r dotenv/config ./src/preprocess/index.js && node src/preprocess/generate_aztecnr_reference.js",
"preprocess:dev": "nodemon --config nodemon.json ./src/preprocess/index.js && nodemon --config nodemon.json src/preprocess/generate_aztecnr_reference.js ",
"typedoc": "rm -rf docs/apis && docusaurus generate-typedoc && cp -a docs/apis processed-docs/",
"typedoc:dev": "nodemon -w ../yarn-project -e '*.js,*.ts,*.nr,*.md' --exec \"rm -rf docs/apis && yarn docusaurus generate-typedoc && cp -a docs/apis processed-docs/\"",
"write-translations": "docusaurus write-translations",
Expand Down
3 changes: 3 additions & 0 deletions docs/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ fi

# Now build the docsite
echo Building docsite...
echo "Generating Aztec.nr reference docs..."
node ./src/preprocess/generate_aztecnr_reference.js
echo "Generated Aztec.nr reference docs"
yarn preprocess && yarn typedoc && yarn docusaurus build
75 changes: 58 additions & 17 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,47 @@

// @ts-check

const fs = require("fs");
const path = require("path");
// Load the structured documentation paths
const docsStructurePath = path.join(
__dirname,
"/src/preprocess/AztecnrReferenceAutogenStructure.json"
);
const docsStructure = JSON.parse(fs.readFileSync(docsStructurePath, "utf8"));

// Function to recursively build sidebar items from the structured documentation
function buildSidebarItemsFromStructure(structure, basePath = "") {
const items = [];
for (const key in structure) {
if (key === "_docs") {
// Base case: add the docs
structure[key].forEach((doc) => {
items.push(`${basePath}/${doc}`);
});
} else {
// Recursive case: process a subdirectory
const subItems = buildSidebarItemsFromStructure(
structure[key],
`${basePath}/${key}`
);
items.push({
type: "category",
label: key.charAt(0).toUpperCase() + key.slice(1), // Capitalize the label
items: subItems,
});
}
}
return items;
}

// Build sidebar for AztecNR documentation
const aztecNRSidebar = buildSidebarItemsFromStructure(
docsStructure.AztecNR,
"developers/contracts/references/aztec-nr"
);

console.log(aztecNRSidebar);
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
const sidebars = {
docsSidebar: [
Expand All @@ -22,7 +63,7 @@ const sidebars = {
// ABOUT AZTEC

{
type: "html",
type: "html",
className: "sidebar-title",
value: "LEARN",
defaultStyle: true,
Expand Down Expand Up @@ -278,9 +319,7 @@ const sidebars = {
id: "apis/pxe/interfaces/PXE",
},
],

},

],
},
{
Expand Down Expand Up @@ -331,7 +370,6 @@ const sidebars = {
type: "category",
items: [
"developers/contracts/writing_contracts/accounts/write_accounts_contract",

],
},
{
Expand Down Expand Up @@ -383,7 +421,8 @@ const sidebars = {
],
},
{
label: "Access public data from private state (Slow Updates Tree)",
label:
"Access public data from private state (Slow Updates Tree)",
type: "category",
link: {
type: "doc",
Expand All @@ -393,7 +432,6 @@ const sidebars = {
"developers/contracts/writing_contracts/historical_data/slow_updates_tree/implement_slow_updates",
],
},

],
},
{
Expand All @@ -402,16 +440,16 @@ const sidebars = {
items: [
"developers/contracts/compiling_contracts/how_to_compile_contract",
"developers/contracts/compiling_contracts/artifacts",
],
],
},
{
label: "Deploying Contracts",
type: "category",
items: [
"developers/contracts/deploying_contracts/how_to_deploy_contract",
],
],
},
"developers/contracts/testing_contracts/main",
"developers/contracts/testing_contracts/main",
{
label: "References",
type: "category",
Expand All @@ -426,7 +464,7 @@ const sidebars = {
},
items: [
"developers/contracts/references/storage/private_state",
"developers/contracts/references/storage/public_state"
"developers/contracts/references/storage/public_state",
],
},
{
Expand All @@ -439,6 +477,11 @@ const sidebars = {
"developers/contracts/references/portals/registry",
],
},
{
label: "Aztec.nr Reference",
type: "category",
items: aztecNRSidebar,
},
"developers/contracts/references/history_lib_reference",
"developers/contracts/references/slow_updates_tree",
],
Expand Down Expand Up @@ -502,7 +545,7 @@ const sidebars = {
"developers/aztecjs/guides/call_view_function",
],
},
{
{
label: "References",
type: "category",
items: [
Expand All @@ -516,9 +559,9 @@ const sidebars = {
type: "category",
items: [{ dirName: "apis/accounts", type: "autogenerated" }],
},
],
},
],
],
},
],
},
{
label: "Debugging",
Expand All @@ -544,9 +587,7 @@ const sidebars = {
type: "doc",
id: "developers/wallets/main",
},
items: [
"developers/wallets/architecture",
],
items: ["developers/wallets/architecture"],
},

/* {
Expand Down
Loading

0 comments on commit aebf762

Please sign in to comment.