@0001-labs/idv1 1.0.6 → 2.0.0

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/README.md CHANGED
@@ -1,61 +1,57 @@
1
1
  # IDv1
2
2
 
3
- Six-character IDs for agents: five shapes, taxonomy and namespaces, and a command that reads a codebase's `.id` file.
3
+ Six-character IDs with five structural shapes, named by their patterns. Applications choose what those shapes mean.
4
4
 
5
5
  ```sh
6
6
  npm install @0001-labs/idv1
7
7
  ```
8
8
 
9
9
  ```ts
10
- import { codeCandidate, parseCode } from '@0001-labs/idv1'
10
+ import { codeCandidate, parseCode, type LLNNXXId } from '@0001-labs/idv1'
11
11
 
12
- const candidate = codeCandidate('item')
12
+ const candidate: LLNNXXId = codeCandidate('LLNNXX')
13
13
  const parsed = parseCode(candidate)
14
14
  ```
15
15
 
16
- `parseCode(unknown)` returns a discriminated `{ kind, id }` with a shape-branded TypeScript `Id`, or `null`. `codeKind` and the `isCodeOf`/shape predicates use that parser. Validation establishes syntax, not an assigned record. `AccountId`, `ListId`, `ProjectId`, `ItemId` and `EventId` are distinct types.
16
+ `parseCode(unknown)` returns `{ shape, id }` with a shape-branded ID, or `null`. `codeShape` and `isCodeOf(shape, value)` use the same parser. The types are `LLNNNNId`, `NNLLLLId`, `LLLLNNId`, `LLNNXXId` and `XXXXXXId`, also available as `Id<Shape>`. Validation establishes syntax, not an assigned record.
17
17
 
18
- `codeCandidate(kind)` draws with Web Crypto and returns the corresponding branded ID. All generators use mixed-case ASCII letters. Account and Project accept an optional exact two-letter prefix, preserving case: `codeCandidate('project', { letters: 'AR' })`. Candidates obey word filters; Project also excludes blocked digit pairs. A bounded draw fails after 1,000 attempts. An injected `random` must return finite numbers in `[0, 1)`. These are candidate generators, not allocators: claim a candidate in its namespace and store it next to the record's UUID. A code is a short handle for agents, not a permanent identity; when a pool runs out it resets and its codes are issued again.
18
+ | Shape | Structure |
19
+ | --- | --- |
20
+ | `LLNNNN` | Two ASCII letters, four digits |
21
+ | `NNLLLL` | Two digits, four ASCII letters |
22
+ | `LLLLNN` | Four ASCII letters, two digits |
23
+ | `LLNNXX` | Two letters, two digits, two letters or digits; the final pair contains at least one letter |
24
+ | `XXXXXX` | Every remaining exact six-character ASCII base62 string |
25
+
26
+ `codeCandidate(shape)` draws with Web Crypto. `LLNNNN` and `LLLLNN` accept an optional exact two-letter prefix, preserving case. Candidates obey word filters; `LLLLNN` also excludes blocked digit pairs. A bounded draw fails after 1,000 attempts. An injected `random` must return finite numbers in `[0, 1)`. Claim a candidate in its namespace and store it beside the record’s UUID. A code is a short handle; its pool can reset and reissue codes.
19
27
 
20
- `ID_CAPACITY` counts the five structural pools before generation filters; `TOTAL_ID_CAPACITY` is their sum. Event is part of the main API, without a separate expanded classifier. Scan encoding retains its checksum and payload format, accepts exactly the same six-character IDs, and all scanner paths support all five shapes. Scan results are branded IDs; use `parseCode` to read their kind.
28
+ `ID_CAPACITY` is keyed by the same patterns and counts structural capacity before generation filters. `TOTAL_ID_CAPACITY` is their sum. Scan encoding keeps its checksum and payload format; `parseCode` reads the shape of a branded scan result. `isScanIdOf(shape, value)` checks one shape.
21
29
 
22
30
  ## The idv1 command
23
31
 
24
- A codebase that uses IDv1 keeps one `.id` file at its root: its namespaces and taxonomies, each with its shorthand and real name, then its parts and the facts between them ([format](https://idv1.0001.dev/docs/annotate)). The `idv1` command reads it from any folder below:
32
+ A codebase keeps a `.id` file with optional `shapes` names keyed by pattern, namespaces, taxonomies, parts and facts. A shape name is a label, not a taxonomy reservation. Taxonomies declare their own pattern and structural shape.
25
33
 
26
34
  ```sh
27
- npx idv1 directory # namespaces, taxonomies, the parts as a tree, the facts
28
- npx idv1 status # counts by shape and taxonomy, and whether it is healthy
29
- npx idv1 health # every broken rule; exits 1 so it can run in a build
30
- npx idv1 resolve co14Ch # one id, a -SH- qualified id or a junction, with its facts
35
+ npx idv1 directory
36
+ npx idv1 status
37
+ npx idv1 health
38
+ npx idv1 resolve co14Ch
31
39
  ```
32
40
 
33
- It runs on Node 22.18 or later. The same functions are exported for apps: `readDirectory`, `directoryHealth`, `resolveCode`, `taxonomyOf`, `describeDirectory`, `describeStatus` and `runDirectoryCommand`.
41
+ The same operations are exported: `readDirectory`, `directoryHealth`, `resolveCode`, `taxonomyOf`, `describeDirectory`, `describeStatus` and `runDirectoryCommand`.
34
42
 
35
- The package ships TypeScript source. Bundlers and `tsx` read it as is; for a plain Node script, import `@0001-labs/idv1/register` first, then load the code that imports the package with `await import()`.
43
+ The package ships TypeScript source. Bundlers and `tsx` read it directly. Plain Node 22.18 or later imports `@0001-labs/idv1/register` first, then dynamically imports the package.
36
44
 
37
45
  ## Explorer utility
38
46
 
39
- Import `createExplorer` and `mountExplorer` from `@0001-labs/idv1/explorer`, and `@0001-labs/idv1/explorer.css` for the browser view. Supply `ExplorerData`: namespace names, shapes, taxonomies, identifiers, nodes and their links. The utility owns drill-down, counts, identifier resolution, taxonomy highlighting, keyboard navigation and URL history. Optional `collections` carry existing source records and lazy `load` functions; records may link to their host’s details with `href`. It contains no application records or network requests.
40
-
41
- `createExplorer(data)` returns `entries(path)`, `title(path)` and `stepName(path, depth)` for any renderer. `mountExplorer(element, data)` renders that model and returns a cleanup function. Theme it with the `--idv1-explorer-*` CSS variables; its host owns loading and authorization.
47
+ Import `createExplorer` and `mountExplorer` from `@0001-labs/idv1/explorer`, and `@0001-labs/idv1/explorer.css` for the browser view. Supply `ExplorerData`: namespace names, shapes, taxonomies, identifiers, nodes and links. The utility owns drill-down, counts, identifier resolution, taxonomy highlighting, keyboard navigation and URL history.
42
48
 
43
- ## Upgrading from 0.3.x to Release 1
49
+ Optional `collections` carry source records and lazy `load` functions. Records may link to host details with `href`. The utility contains no application records or network requests. `createExplorer(data)` returns `entries(path)`, `title(path)`, `stepName(path, depth)` and `load(path)`. `mountExplorer(element, data)` renders it and returns a cleanup function. Theme it with `--idv1-explorer-*` CSS variables; the host owns loading and authorization.
44
50
 
45
- Release 1 uses five shapes. Here `L` is an ASCII letter and `N` is a digit.
51
+ ## Upgrading from 1.x
46
52
 
47
- | Kind | Shape |
48
- | --- | --- |
49
- | Account | `LLNNNN` |
50
- | List | `NNLLLL` |
51
- | Project | `LLLLNN`, formerly also accepted as Account |
52
- | Item | `LLNN` followed by two ASCII letters or digits, with at least one letter |
53
- | Event | Any remaining string of exactly six ASCII letters or digits |
54
-
55
- Use the root export and `parseCode` in place of the `advanced` subpath and its classifier. The Product kind and studio-specific account reservations were removed. Keep reservations in the application, choose the intended shape for each former Product use, and review stored codes before changing how your app classifies them.
53
+ Release 2 changes API names, not code grammar, scan payloads or capacity. Replace semantic shape arguments with patterns, `parseCode(...).kind` with `.shape`, and `codeKind` with `codeShape`. Use `codeCandidate(shape)` and `isCodeOf(shape, value)` in place of per-kind wrappers. Regex constants are pattern-named, such as `LLNNXX_CODE`; `blockedLLLLNNCode` replaces the semantic name of its filter. `.id` part and taxonomy `shape` values use patterns. Keep application words in the optional `shapes` map.
56
54
 
57
55
  ## Documentation
58
56
 
59
- The [IDv1 specification](https://idv1.0001.dev/docs/spec) is the authoritative reference for identifier shapes, namespaces, taxonomy, allocation and message examples. See the [documentation index](https://idv1.0001.dev/docs) for the remaining guides.
60
-
61
- [MIT license](LICENSE)
57
+ The [specification](https://idv1.0001.dev/docs/spec) owns the code design. [MIT license](LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0001-labs/idv1",
3
- "version": "1.0.6",
3
+ "version": "2.0.0",
4
4
  "description": "Six-character IDs for agents: five shapes, taxonomy and namespaces, and a CLI that reads a codebase's .id file.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/directory.ts CHANGED
@@ -1,4 +1,3 @@
1
- export type { AccountId, ListId, ProjectId, ItemId, EventId } from './identifier'
2
1
  export * from './identifier'
3
2
  export type { Namespace } from './namespace'
4
3
  export { taxonomyOf, type Taxonomy } from './taxonomy'
package/src/identifier.ts CHANGED
@@ -1,44 +1,39 @@
1
- import { blockedCodeLetters, blockedProjectCode } from './util/blockedWords'
1
+ import { blockedCodeLetters, blockedLLLLNNCode } from './util/blockedWords'
2
2
 
3
3
  export const LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
4
4
  export const CAPITALS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5
5
  export const DIGITS = '0123456789'
6
6
  export const ALPHABET = DIGITS + LETTERS
7
7
 
8
- export const ACCOUNT_CODE = /^[A-Za-z]{2}[0-9]{4}(?![\s\S])/
9
- export const LIST_CODE = /^[0-9]{2}[A-Za-z]{4}(?![\s\S])/
10
- export const PROJECT_CODE = /^[A-Za-z]{4}[0-9]{2}(?![\s\S])/
11
- export const ITEM_CODE = /^[A-Za-z]{2}[0-9]{2}(?:[A-Za-z][A-Za-z0-9]|[0-9][A-Za-z])(?![\s\S])/
8
+ export const LLNNNN_CODE = /^[A-Za-z]{2}[0-9]{4}(?![\s\S])/
9
+ export const NNLLLL_CODE = /^[0-9]{2}[A-Za-z]{4}(?![\s\S])/
10
+ export const LLLLNN_CODE = /^[A-Za-z]{4}[0-9]{2}(?![\s\S])/
11
+ export const LLNNXX_CODE = /^[A-Za-z]{2}[0-9]{2}(?:[A-Za-z][A-Za-z0-9]|[0-9][A-Za-z])(?![\s\S])/
12
12
  export const ANY_CODE = /^[A-Za-z0-9]{6}(?![\s\S])/
13
- export const EVENT_CODE = new RegExp(`^(?!${[ACCOUNT_CODE, LIST_CODE, PROJECT_CODE, ITEM_CODE].map(pattern => pattern.source.slice(1)).join('|')})[A-Za-z0-9]{6}(?![\\s\\S])`)
13
+ export const XXXXXX_CODE = new RegExp(`^(?!${[LLNNNN_CODE, NNLLLL_CODE, LLLLNN_CODE, LLNNXX_CODE].map(pattern => pattern.source.slice(1)).join('|')})[A-Za-z0-9]{6}(?![\\s\\S])`)
14
14
 
15
- export type CodeKind = 'account' | 'list' | 'project' | 'item' | 'event'
15
+ export type CodeShape = 'LLNNNN' | 'NNLLLL' | 'LLLLNN' | 'LLNNXX' | 'XXXXXX'
16
16
  declare const idBrand: unique symbol
17
- export type Id<K extends CodeKind = CodeKind> = string & { readonly [idBrand]: K }
18
- export type AccountId = Id<'account'>
19
- export type ListId = Id<'list'>
20
- export type ProjectId = Id<'project'>
21
- export type ItemId = Id<'item'>
22
- export type EventId = Id<'event'>
23
- export type ParsedCode = { [K in CodeKind]: { kind: K; id: Id<K> } }[CodeKind]
17
+ export type Id<K extends CodeShape = CodeShape> = string & { readonly [idBrand]: K }
18
+ export type LLNNNNId = Id<'LLNNNN'>
19
+ export type NNLLLLId = Id<'NNLLLL'>
20
+ export type LLLLNNId = Id<'LLLLNN'>
21
+ export type LLNNXXId = Id<'LLNNXX'>
22
+ export type XXXXXXId = Id<'XXXXXX'>
23
+ export type ParsedCode = { [K in CodeShape]: { shape: K; id: Id<K> } }[CodeShape]
24
24
 
25
- export const CODE_PATTERN = { account: ACCOUNT_CODE, list: LIST_CODE, project: PROJECT_CODE, item: ITEM_CODE, event: EVENT_CODE } as const
25
+ export const CODE_PATTERN = { LLNNNN: LLNNNN_CODE, NNLLLL: NNLLLL_CODE, LLLLNN: LLLLNN_CODE, LLNNXX: LLNNXX_CODE, XXXXXX: XXXXXX_CODE } as const
26
26
 
27
27
  export function parseCode(value: unknown): ParsedCode | null {
28
28
  if (typeof value !== 'string' || !ANY_CODE.test(value)) return null
29
- for (const kind of ['account', 'list', 'project', 'item'] as const) {
30
- if (CODE_PATTERN[kind].test(value)) return { kind, id: value } as ParsedCode
29
+ for (const shape of ['LLNNNN', 'NNLLLL', 'LLLLNN', 'LLNNXX'] as const) {
30
+ if (CODE_PATTERN[shape].test(value)) return { shape, id: value } as ParsedCode
31
31
  }
32
- return { kind: 'event', id: value as EventId }
32
+ return { shape: 'XXXXXX', id: value as XXXXXXId }
33
33
  }
34
34
 
35
- export const codeKind = (value: unknown): CodeKind | null => parseCode(value)?.kind ?? null
36
- export const isCodeOf = <K extends CodeKind>(kind: K, value: unknown): value is Id<K> => codeKind(value) === kind
37
- export const isAccountCode = (value: unknown): value is AccountId => isCodeOf('account', value)
38
- export const isListCode = (value: unknown): value is ListId => isCodeOf('list', value)
39
- export const isProjectCode = (value: unknown): value is ProjectId => isCodeOf('project', value)
40
- export const isItemCode = (value: unknown): value is ItemId => isCodeOf('item', value)
41
- export const isEventCode = (value: unknown): value is EventId => isCodeOf('event', value)
35
+ export const codeShape = (value: unknown): CodeShape | null => parseCode(value)?.shape ?? null
36
+ export const isCodeOf = <K extends CodeShape>(shape: K, value: unknown): value is Id<K> => codeShape(value) === shape
42
37
 
43
38
  export type Random = () => number
44
39
 
@@ -73,35 +68,30 @@ export function nameLetters(name: string, email = ''): string | null {
73
68
  return null
74
69
  }
75
70
 
76
- export function codeCandidate<K extends CodeKind>(kind: K, options: { letters?: string | null; random?: Random } = {}): Id<K> {
71
+ export function codeCandidate<K extends CodeShape>(shape: K, options: { letters?: string | null; random?: Random } = {}): Id<K> {
77
72
  const random = options.random ?? secureRandom
78
73
  const prefix = options.letters ?? ''
79
- if (prefix && (!['account', 'project'].includes(kind) || !/^[A-Za-z]{2}(?![\s\S])/.test(prefix))) {
80
- throw new Error('A prefix must be exactly two ASCII letters for an Account or Project.')
74
+ if (prefix && (!['LLNNNN', 'LLLLNN'].includes(shape) || !/^[A-Za-z]{2}(?![\s\S])/.test(prefix))) {
75
+ throw new Error('A prefix must be exactly two ASCII letters for LLNNNN or LLLLNN.')
81
76
  }
82
77
  for (let attempt = 0; attempt < 1000; attempt++) {
83
78
  let candidate: string
84
- switch (kind) {
85
- case 'account': candidate = (prefix || draw(LETTERS, 2, random)) + draw(DIGITS, 4, random); break
86
- case 'list': candidate = draw(DIGITS, 2, random) + draw(LETTERS, 4, random); break
87
- case 'project': candidate = (prefix || draw(LETTERS, 2, random)) + draw(LETTERS, 2, random) + draw(DIGITS, 2, random); break
88
- case 'item': candidate = draw(LETTERS, 2, random) + draw(DIGITS, 2, random) + draw(ALPHABET, 2, random); break
89
- case 'event': candidate = draw(ALPHABET, 6, random); break
79
+ switch (shape) {
80
+ case 'LLNNNN': candidate = (prefix || draw(LETTERS, 2, random)) + draw(DIGITS, 4, random); break
81
+ case 'NNLLLL': candidate = draw(DIGITS, 2, random) + draw(LETTERS, 4, random); break
82
+ case 'LLLLNN': candidate = (prefix || draw(LETTERS, 2, random)) + draw(LETTERS, 2, random) + draw(DIGITS, 2, random); break
83
+ case 'LLNNXX': candidate = draw(LETTERS, 2, random) + draw(DIGITS, 2, random) + draw(ALPHABET, 2, random); break
84
+ case 'XXXXXX': candidate = draw(ALPHABET, 6, random); break
90
85
  default: throw new Error('Unknown IDv1 shape.')
91
86
  }
92
87
  const parsed = parseCode(candidate)
93
- if (parsed?.kind === kind && !(kind === 'project' ? blockedProjectCode(candidate) : blockedCodeLetters(candidate))) return parsed.id as Id<K>
88
+ if (parsed?.shape === shape && !(shape === 'LLLLNN' ? blockedLLLLNNCode(candidate) : blockedCodeLetters(candidate))) return parsed.id as Id<K>
94
89
  }
95
- throw new Error(`No ${kind} code could be drawn.`)
90
+ throw new Error(`No ${shape} code could be drawn.`)
96
91
  }
97
92
 
98
- export const accountCodeCandidate = (letters: string | null = null, random: Random = secureRandom): AccountId => codeCandidate('account', { letters, random })
99
- export const listCodeCandidate = (random: Random = secureRandom): ListId => codeCandidate('list', { random })
100
- export const projectCodeCandidate = (letters: string | null = null, random: Random = secureRandom): ProjectId => codeCandidate('project', { letters, random })
101
- export const itemCodeCandidate = (random: Random = secureRandom): ItemId => codeCandidate('item', { random })
102
- export const eventCodeCandidate = (random: Random = secureRandom): EventId => codeCandidate('event', { random })
103
93
 
104
- export function accountCodeCaseVariants(code: string): string[] {
94
+ export function caseVariantsLLNNNN(code: string): string[] {
105
95
  const [first, second] = [code[0], code[1]].map(letter => [...new Set([letter.toUpperCase(), letter.toLowerCase()])])
106
96
  return first.flatMap(a => second.map(b => a + b + code.slice(2)))
107
97
  }
@@ -110,15 +100,15 @@ export const JUNCTION_SEPARATOR = '-'
110
100
 
111
101
  export function junction(...codes: string[]): string {
112
102
  if (codes.length < 2) throw new Error('A junction joins two codes or more.')
113
- for (const code of codes) if (!codeKind(code)) throw new Error(`${code} is no IDv1 code.`)
103
+ for (const code of codes) if (!codeShape(code)) throw new Error(`${code} is no IDv1 code.`)
114
104
  return codes.join(JUNCTION_SEPARATOR)
115
105
  }
116
106
 
117
- export function junctionParts(value: string): { code: string; kind: CodeKind }[] | null {
107
+ export function junctionParts(value: string): { code: string; shape: CodeShape }[] | null {
118
108
  const codes = value.split(JUNCTION_SEPARATOR)
119
109
  if (codes.length < 2) return null
120
- const parts = codes.map(code => ({ code, kind: codeKind(code) }))
121
- return parts.every((part): part is { code: string; kind: CodeKind } => part.kind !== null) ? parts : null
110
+ const parts = codes.map(code => ({ code, shape: codeShape(code) }))
111
+ return parts.every((part): part is { code: string; shape: CodeShape } => part.shape !== null) ? parts : null
122
112
  }
123
113
 
124
114
  export const isJunction = (value: string): boolean => junctionParts(value) !== null
package/src/idv1.ts CHANGED
@@ -1,24 +1,24 @@
1
- import { JUNCTION_SEPARATOR, parseCode, type CodeKind } from './identifier'
2
- import { blockedCodeLetters, blockedProjectCode } from './util/blockedWords'
1
+ import { JUNCTION_SEPARATOR, parseCode, type CodeShape } from './identifier'
2
+ import { blockedCodeLetters, blockedLLLLNNCode } from './util/blockedWords'
3
3
  import { namespaceHealth, namespaceOf, type Namespace } from './namespace'
4
4
  import { taxonomyHealth, taxonomyOf, type Taxonomy } from './taxonomy'
5
5
 
6
- export type { Namespace } from './namespace'
7
- export { taxonomyOf, type Taxonomy } from './taxonomy'
8
- export type Part = { id: string; shape: CodeKind; name: string; path: string | null }
9
- export type Directory = { namespaces: Namespace[]; taxonomies: Taxonomy[]; parts: Part[]; facts: string[] }
10
- export type Resolved = { id: string; shape: CodeKind | null; namespace?: Namespace; taxonomy?: Taxonomy; part?: Part; facts: string[] }
6
+ export type Part = { id: string; shape: CodeShape; name: string; path: string | null }
7
+ export type ShapeNames = Partial<Record<CodeShape, string>>
8
+ export type Directory = { shapes?: ShapeNames; namespaces: Namespace[]; taxonomies: Taxonomy[]; parts: Part[]; facts: string[] }
9
+ export type Resolved = { id: string; shape: CodeShape | null; namespace?: Namespace; taxonomy?: Taxonomy; part?: Part; facts: string[] }
11
10
 
12
- const SHAPES: CodeKind[] = ['account', 'list', 'project', 'item', 'event']
11
+ const SHAPES: CodeShape[] = ['LLNNNN', 'NNLLLL', 'LLLLNN', 'LLNNXX', 'XXXXXX']
13
12
  const list = <T>(value: unknown): T[] => (Array.isArray(value) ? value : []) as T[]
14
13
 
15
14
  export function readDirectory(text: string): Directory {
16
15
  const value = JSON.parse(text) as Partial<Directory>
17
- return { namespaces: list(value.namespaces), taxonomies: list(value.taxonomies), parts: list(value.parts), facts: list(value.facts) }
16
+ return { shapes: value.shapes ?? {}, namespaces: list(value.namespaces), taxonomies: list(value.taxonomies), parts: list(value.parts), facts: list(value.facts) }
18
17
  }
19
18
 
20
19
  export function directoryHealth(directory: Directory, exists: (path: string) => boolean = () => true): string[] {
21
20
  const problems: string[] = []
21
+ for (const [shape, name] of Object.entries(directory.shapes ?? {})) if (!SHAPES.includes(shape as CodeShape) || typeof name !== 'string' || !name.trim()) problems.push(`Invalid shape name: ${shape}`)
22
22
  const seen = (values: string[], what: string) => values.forEach((value, index) => { if (values.indexOf(value) !== index) problems.push(`${what} ${value} is declared twice`) })
23
23
  problems.push(...namespaceHealth(directory.namespaces), ...taxonomyHealth(directory.taxonomies))
24
24
  seen(directory.namespaces.map(namespace => namespace.shorthand), 'Namespace')
@@ -26,9 +26,9 @@ export function directoryHealth(directory: Directory, exists: (path: string) =>
26
26
  seen(directory.parts.map(part => part.id), 'Id')
27
27
  const ids = new Set(directory.parts.map(part => part.id))
28
28
  for (const part of directory.parts) {
29
- const shape = parseCode(part.id)?.kind
29
+ const shape = parseCode(part.id)?.shape
30
30
  if (shape !== part.shape) problems.push(`${part.id} reads as ${shape ?? 'no shape'}, not ${part.shape}`)
31
- else if (shape === 'project' ? blockedProjectCode(part.id) : blockedCodeLetters(part.id)) problems.push(`${part.id} uses blocked letters or digits`)
31
+ else if (shape === 'LLLLNN' ? blockedLLLLNNCode(part.id) : blockedCodeLetters(part.id)) problems.push(`${part.id} uses blocked letters or digits`)
32
32
  if (!part.name) problems.push(`${part.id} has no name`)
33
33
  if (part.path && !exists(part.path)) problems.push(`${part.id}: ${part.path} is gone`)
34
34
  }
@@ -44,7 +44,7 @@ export function resolveCode(directory: Directory, value: string): Resolved[] {
44
44
  const qualified = /^-([A-Z]{2})-(.+)$/.exec(value)
45
45
  const ids = (qualified ? qualified[2] : value).split(JUNCTION_SEPARATOR)
46
46
  return ids.map(id => {
47
- const shape = parseCode(id)?.kind ?? null
47
+ const shape = parseCode(id)?.shape ?? null
48
48
  const namespace = namespaceOf(directory, id, qualified?.[1])
49
49
  const facts = directory.facts.filter(fact => { const [subject, , object] = fact.split(' '); return subject === id || object === id })
50
50
  return { id, shape, namespace, taxonomy: shape ? taxonomyOf(directory, id) : undefined, part: directory.parts.find(part => part.id === id), facts }
@@ -72,7 +72,7 @@ export function describeStatus(directory: Directory, problems: string[]): string
72
72
  `${count(directory.parts.length, 'part')} · ${count(directory.facts.length, 'fact')} · ${count(directory.namespaces.length, 'namespace')} · ${count(directory.taxonomies.length, 'taxonomy', 'taxonomies')}`,
73
73
  problems.length ? `${count(problems.length, 'problem')}: run idv1 health` : 'healthy',
74
74
  '',
75
- ...shapes.map(([shape, n]) => ` ${shape.padEnd(9)}${n}`),
75
+ ...shapes.map(([shape, n]) => ` ${shape.padEnd(9)}${n} ${directory.shapes?.[shape] ?? shape}`),
76
76
  ...directory.taxonomies.map(taxonomy => ` ${taxonomy.shorthand.padEnd(9)}${directory.parts.filter(part => taxonomyOf(directory, part.id) === taxonomy).length} ${taxonomy.name}`),
77
77
  ].join('\n')
78
78
  }
@@ -84,6 +84,9 @@ export function describeDirectory(directory: Directory): string {
84
84
  const line = (part: Part | undefined, id: string, depth: number) => `${' '.repeat(depth)}${id} ${part?.name ?? '?'}${part && taxonomyOf(directory, id) ? ` (${taxonomyOf(directory, id)!.name})` : ''}${part?.path ? ` ${part.path}` : ''}`
85
85
  const tree = (id: string, depth: number, trail: Set<string>): string[] => trail.has(id) ? [] : [line(directory.parts.find(part => part.id === id), id, depth), ...children(id).flatMap(child => tree(child, depth + 1, new Set([...trail, id])))]
86
86
  return [
87
+ 'Shapes',
88
+ ...SHAPES.map(shape => ` ${shape} ${directory.shapes?.[shape] ?? shape}`),
89
+ '',
87
90
  'Namespaces',
88
91
  ...directory.namespaces.map(({ shorthand, name }) => ` ${shorthand} ${name}`),
89
92
  '',
package/src/namespace.ts CHANGED
@@ -3,7 +3,7 @@ import { parseCode } from './identifier'
3
3
  export type Namespace = { shorthand: string; name: string }
4
4
 
5
5
  export function namespaceOf({ namespaces }: { namespaces: Namespace[] }, id: string, qualified?: string): Namespace | undefined {
6
- const shorthand = qualified ?? (parseCode(id)?.kind === 'project' ? id.slice(0, 2) : undefined)
6
+ const shorthand = qualified ?? (parseCode(id)?.shape === 'LLLLNN' ? id.slice(0, 2) : undefined)
7
7
  return namespaces.find(namespace => namespace.shorthand === shorthand) ?? (namespaces.length === 1 ? namespaces[0] : undefined)
8
8
  }
9
9
 
package/src/taxonomy.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { CODE_PATTERN, parseCode, type CodeKind } from './identifier'
1
+ import { CODE_PATTERN, parseCode, type CodeShape } from './identifier'
2
2
 
3
- export type Taxonomy = { shorthand: string; name: string; shape: CodeKind; pattern: string }
3
+ export type Taxonomy = { shorthand: string; name: string; shape: CodeShape; pattern: string }
4
4
 
5
5
  export function taxonomyOf(directory: { taxonomies: Taxonomy[] }, id: string): Taxonomy | undefined {
6
- const shape = parseCode(id)?.kind
6
+ const shape = parseCode(id)?.shape
7
7
  return directory.taxonomies.find(taxonomy => {
8
8
  const at = taxonomy.pattern.replace(/\s/g, '').indexOf(taxonomy.shorthand)
9
9
  return taxonomy.shape === shape && at >= 0 && id.slice(at, at + 2) === taxonomy.shorthand
@@ -19,6 +19,6 @@ export function blockedCodeLetters(letters: string): boolean {
19
19
  return BLOCKED_CODE_WORDS.some(word => small.includes(word))
20
20
  }
21
21
 
22
- export function blockedProjectCode(code: string): boolean {
22
+ export function blockedLLLLNNCode(code: string): boolean {
23
23
  return blockedCodeLetters(code.slice(0, 4)) || BLOCKED_CODE_DIGITS.includes(code.slice(4))
24
24
  }
@@ -1,16 +1,16 @@
1
1
  const LETTERS = 52
2
2
  const DIGITS = 10
3
3
  export const TOTAL_ID_CAPACITY = (LETTERS + DIGITS) ** 6
4
- const accounts = LETTERS ** 2 * DIGITS ** 4
5
- const lists = DIGITS ** 2 * LETTERS ** 4
6
- const projects = LETTERS ** 4 * DIGITS ** 2
7
- const items = LETTERS ** 2 * DIGITS ** 2 * ((LETTERS + DIGITS) ** 2 - DIGITS ** 2)
4
+ const LLNNNN = LETTERS ** 2 * DIGITS ** 4
5
+ const NNLLLL = DIGITS ** 2 * LETTERS ** 4
6
+ const LLLLNN = LETTERS ** 4 * DIGITS ** 2
7
+ const LLNNXX = LETTERS ** 2 * DIGITS ** 2 * ((LETTERS + DIGITS) ** 2 - DIGITS ** 2)
8
8
 
9
- export const ID_CAPACITY = { accounts, lists, projects, items, events: TOTAL_ID_CAPACITY - accounts - lists - projects - items } as const
10
- export type IdCapacityKind = keyof typeof ID_CAPACITY
9
+ export const ID_CAPACITY = { LLNNNN, NNLLLL, LLLLNN, LLNNXX, XXXXXX: TOTAL_ID_CAPACITY - LLNNNN - NNLLLL - LLLLNN - LLNNXX } as const
10
+ export type IdCapacityShape = keyof typeof ID_CAPACITY
11
11
 
12
- export function idUsage(kind: IdCapacityKind, used: number): { used: number; capacity: number; left: number; percent: number } {
13
- const capacity = ID_CAPACITY[kind]
12
+ export function idUsage(shape: IdCapacityShape, used: number): { used: number; capacity: number; left: number; percent: number } {
13
+ const capacity = ID_CAPACITY[shape]
14
14
  if (!Number.isSafeInteger(used) || used < 0) throw new RangeError('Usage must be a nonnegative safe integer.')
15
15
  return { used, capacity, left: Math.max(0, capacity - used), percent: (used / capacity) * 100 }
16
16
  }
package/src/util/scan.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ALPHABET, isAccountCode, isListCode, parseCode, type Id } from '../identifier'
1
+ import { ALPHABET, isCodeOf, parseCode, type CodeShape, type Id } from '../identifier'
2
2
 
3
3
  const alphabet = ALPHABET
4
4
  export const scanColumns = 16
@@ -93,8 +93,7 @@ export function decodeScan(bits: readonly boolean[]): Id | null {
93
93
  return parseCode(id)?.id ?? null
94
94
  }
95
95
 
96
- export const isListScanId = (id: string): boolean => isListCode(id)
97
- export const isUserScanId = (id: string): boolean => isAccountCode(id)
96
+ export const isScanIdOf = (shape: CodeShape, id: string): boolean => isCodeOf(shape, id)
98
97
  export const isSupportedScanId = (id: string): boolean => parseCode(id) !== null
99
98
 
100
99
  export type ScanRect = { x: number; y: number; width: number; height: number }