npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@azimutt/aml

v0.1.8

Published

Parse and Generate AML: the easiest language to define database schema.

Downloads

51

Readme

AML (Azimutt Markup Language) is the easiest language to design databases.
Made to be fast to learn and write.

Why AML?

  • Structured text is WAY better than GUI: portable, copy/paste, find/replace, versioning, column edition...
  • It's simpler, faster to write and less error-prone than SQL or other database schema DSLs
  • Made for humans: readable, flexible, can hold custom properties
  • Database agnostic: hold concepts, not specific syntax, can be converted to other dialects
  • Free as 🕊️ but also 🍺

In short, it's perfect for fast prototyping and brainstorming. To know more, have a look at the AML documentation.

Example

users
  id uuid pk
  name varchar
  email varchar index
  role user_role(admin, guest)=guest

posts
  id uuid pk
  title varchar
  content text | formatted in markdown
  created_at timestamp=`now()`
  created_by uuid -> users(id) # inline relation

How to use it

  • In Azimutt designer: design your database schema with AML
  • In Dialect converters: convert AML to other dialects such as SQL, JSON, Markdown...
  • As a code library (see API below)

API

This package has a very simple API:

function parseAml(content: string): ParserResult<Database> { /* ... */ }
function generateAml(database: Database): string { /* ... */ }

You can look at the Database definition, it's how Azimutt model any database schema (offers zod validations and TypeScript types).

ParserResult is just a class with a result and errors fields.

Here is a sample usage:

const aml = 'users\  id int pk\n  name varchar\n'
const parsed = parseAml(aml)
if (parsed.errors) {
    parsed.errors.forEach(e => console.log('paring error', e.message))
}
if (parsed.result) {
    console.log('database', parsed.result)
    const generated: string = generateAml(parsed.result)
    console.log('generated', generated)
}

You can have both, a result and some errors as there is syntax recovery and some errors are warnings (see level field).

This package also offer a few more features:

function generateDot(database: Database) {} // generate a DOT graph
function generateMermaid(database: Database) {} // generate a Mermaid erDiagram
function generateMarkdown(database: Database) {} // generate markdown documentation
function generateJsonDatabase(database: Database): string {} // generate nice JSON (similar to `JSON.stringify(db, null, 2), but more compact)
function parseJsonDatabase(content: string): ParserResult<Database> {} // parse and validate JSON (`zod.safeParse()` adapted to Azimutt APIs)
const schemaJsonDatabase: JSONSchema = {} // the JSON Schema object for the Database type

The last useful thing is the Monaco Editor helpers:

const monaco = {language, completion, codeAction, codeLens, createMarker}

You can set up Monaco Editor to be a powerful IDE for AML:

monaco.languages.register({id: 'aml'})
monaco.languages.setMonarchTokensProvider('aml', aml.monaco.language()) // syntax highlighting
monaco.languages.registerCompletionItemProvider('aml', aml.monaco.completion()) // auto-complete
monaco.languages.registerCodeActionProvider('aml', aml.monaco.codeAction()) // quick-fixes
monaco.languages.registerCodeLensProvider('aml', aml.monaco.codeLens()) // hints with actions

const model = monaco.editor.createModel('users\n  id int pk\n  name varchar index\n', 'aml')
var editor = monaco.editor.create(document.getElementById('aml-editor'), {
  model,
  theme: 'vs-light',
  minimap: {enabled: false},
  automaticLayout: true,
  scrollBeyondLastLine: true,
})
editor.onDidChangeModelContent(e => {
  const parsed = parseAml(editor.getValue())
  monaco.editor.setModelMarkers(model, 'owner', (parsed.errors || []).map(e => aml.monaco.createMarker(e, model, editor)))
  const db = parsed.result // <= here is your Database object (or undefined ^^)
})

You can also use the Database JSON Schema for improved JSON editing experience in Monaco.
As an example you can try the AML to JSON converter or the JSON to AML converter

Publish

  • update package.json version
  • update lib versions (pnpm -w run update + manual)
  • test with pnpm run dry-publish and check azimutt-aml-x.y.z.tgz content
  • launch pnpm publish --no-git-checks --access public

View it on npm.

Dev

If you need to develop on multiple libs at the same time (ex: want to update a connector and try it through the CLI), depend on local libs but publish & revert before commit.

  • Depend on a local lib: pnpm add <lib>, ex: pnpm add @azimutt/models
  • "Publish" lib locally by building it: pnpm run build