IDv1 documentation

Install the package, then draw codes where the app creates accounts, lists or items.

vp add @0001-labs/idv1

Pick the kind by what the thing is, and let IDv1 choose the shape:

import { codeCandidate, codeKind, isCodeOf, nameLetters } from '@0001-labs/idv1'

codeCandidate('list')                                              // 47KQWE
codeCandidate('item')                                              // Ab12Cd
codeCandidate('account', { letters: nameLetters('Leo Andersen') }) // Le0125
isCodeOf('list', '47KQWE')                                         // true
codeKind('Ab12Cd')                                                 // 'item'

Read codes with isCodeOf and codeKind rather than with patterns of your own, so a code reads the same in every app.

Keep the database side in the app

A candidate is only a code to try. Keep it when nothing in your database holds it yet, and draw again when something does. Store the code on the row beside the database’s own id, with an index on it, and look rows up by it.

async function newListCode(db) {
  for (;;) {
    const code = codeCandidate('list')
    if (!(await db.lists.byCode(code))) return code
  }
}

Copy it instead

An app that keeps its dependencies as source can copy IDv1’s src folder whole and import from that copy. Never edit the copy; take a new one when IDv1 changes.

Next: Shapes and counts.