@0001-labs/idv1 0.3.3 → 0.3.4

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
@@ -21,19 +21,20 @@ Every code is six letters and digits, and its shape alone says what it names:
21
21
 
22
22
  | Shape | Pattern | Example | For |
23
23
  |---|---|---|---|
24
- | Account | `LLnnnn` | `Jo4712` | a person |
25
- | Product | `LLLLnn` | `ABCD12` | a thing with a code printed on it |
26
- | List | `nnLLLL` | `12ABCD` | something that holds things |
27
- | Item | `LLnnXX` | `Ab12Cd` | one thing kept |
24
+ | Account | `LLNNNN` | `Jo4712` | a person |
25
+ | Product | `LLLLNN` | `ABCD12` | a thing with a code printed on it |
26
+ | List | `NNLLLL` | `12ABCD` | something that holds things |
27
+ | Item | `LLNNxx` | `Ab12Cd` | one thing kept |
28
+ | Project | `NLLLLL` | `1Syste` | a project, a digit and five letters |
28
29
 
29
- `L` is a letter, `n` a digit, and an item's last two are letters or digits but never both digits, or it would be an account. `codeCandidate(kind)` draws a code at random in a shape. An app can go further and lay a template over a shape, fixing some characters so a code also says which kind of thing in that app it is and which thing it names.
30
+ `L` is a letter, `N` a digit and `x` either, and an item's last two are never both digits, or it would be an account. Every other six letters and digits are left for event codes (`advanced`). `codeCandidate(kind)` draws a code at random in a shape. An app can go further and lay a template over a shape, fixing some characters so a code also says which kind of thing in that app it is and which thing it names.
30
31
 
31
32
  ### Building a template
32
33
 
33
- - **A fixed prefix per kind.** A list's two digits can mark the kind: `01Abcd` for projects, `02Abcd` for one kind, `03Abcd` for another.
34
- - **Letters that read as the name.** The letters come from the thing's name, then vary letter by letter until the code is free: a project called Design system 1 is `01Desi`.
35
- - **An owner's two letters lead an item.** An item starts with its owner's two letters, and the first digit can mark the kind inside that owner: `Ds10Bu` is a component of Design system 1, `Ez20Li` one of an app's tools.
36
- - **People and agents take an account's shape.** Two letters from the name and four digits, `Le0125`, whether the account is a person or an agent.
34
+ - **A fixed prefix per kind.** Fixed characters mark the kind: a project's digit (`1LLLLL`), a list's two digits (`02LLLL`, `03LLLL`), or a small letter that no name starts with, as `aLNNNN` for an agent.
35
+ - **Letters that read as the name.** The letters come from the thing's name, then vary letter by letter until the code is free: a project called Design system 1 is `1Desig`.
36
+ - **An owner's two letters lead an item.** An item starts with its owner's two letters, and the first digit can mark the kind inside that owner: `Ds10Bu` is a component of Design system 1.
37
+ - **People and agents take an account's shape.** A person's two name letters and four digits, `Le0125`; an agent's `a`, its initial and four digits, `aG4008`.
37
38
 
38
39
  A fixed character spends space. A list prefix leaves 26⁴ = 456,976 codes in capitals; an item template with fixed owner letters and a fixed kind digit leaves 10 × 26 × 26 = 6,760 per owner and kind if its last pair is a capital and a small letter. Fix only what a reader needs.
39
40
 
@@ -43,25 +44,32 @@ A fixed character spends space. A list prefix leaves 26⁴ = 456,976 codes in ca
43
44
 
44
45
  | Kind | Template | How |
45
46
  |---|---|---|
46
- | Account | `LLnnnn` | the person's name letters, then four drawn digits |
47
- | Product | `LLLLnn` | drawn, again if the letters or digits are blocked |
48
- | List | `nnLLLL` | drawn, in capitals |
49
- | Item | `LLnnXX` | drawn |
47
+ | Account | `LLNNNN` | the person's name letters, then four drawn digits |
48
+ | Product | `LLLLNN` | drawn, again if the letters or digits are blocked |
49
+ | List | `NNLLLL` | drawn, in capitals |
50
+ | Item | `LLNNxx` | drawn |
50
51
 
51
52
  **System derives.** An inventory of a few hundred named parts wants codes a reader can place on sight, so each kind has a template and the letters come from the name:
52
53
 
53
54
  | Kind | Shape | Template | Example |
54
55
  |---|---|---|---|
55
- | Projects | list | `01Abcd` | `01Desi` |
56
- | Stack | list | `02Abcd` | `02Conv` |
57
- | Integrations | list | `03Abcd` | `03Clou` |
58
- | Components | item | owner, `1n`, name | `Ds10Bu` |
59
- | MCP tools | item | owner, `2n`, name | `Ez20Li` |
60
- | Engineers and agents | account | `Ab1234` | `Le0125` |
61
- | Harnesses | product | `Abcd01` | `Clau01` |
56
+ | Projects | project | `1LLLLL` | `1Desig` |
57
+ | Stack | list | `02LLLL` | `02Conv` |
58
+ | Platforms | list | `03LLLL` | `03Webx` |
59
+ | Connections | list | `04LLLL` | `04Gmai` |
60
+ | Components | item | owner's `LL`, `1N`, `LL` | `Ds10Bu` |
61
+ | Tool calls | product | `tc`, the HTTP verb (`G`, `P`, `U`, `D`), `LNN` | `tcGi02` |
62
+ | Issue tags | event | `ixxxxx` | `iImpro` |
63
+ | Engineers | account | `LLNNNN` | `Le0125` |
64
+ | Agents | account | `aLNNNN` | `aG4008` |
65
+ | Harnesses | product | `hLLLNN` | `hCla01` |
62
66
 
63
67
  An app with many short-lived things should draw; one naming a small catalogue can derive. Either way a code, once given, stays when the name changes.
64
68
 
69
+ ### Junctions
70
+
71
+ Codes joined by a hyphen name the place where things meet, and each part still says what it is: `1Ezoxx-tcGi02` is a tool of a project, `1Syste-Sy10Us-Sy10Fl` a path down a tree, `01Sysm-MJ99ST` an item in a list. `junction(...codes)` joins them and refuses anything that is not a code; `junctionParts(value)` reads one back with each part's kind.
72
+
65
73
  ### Rules every template keeps
66
74
 
67
75
  - **Six characters**, letters `A–Z a–z` and digits only.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0001-labs/idv1",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "An ID system for short, memorable IDs that are easy to keep unique.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/advanced.ts CHANGED
@@ -43,6 +43,7 @@ export const ADVANCED_SPACE = (() => {
43
43
  letters ** 2 * digits ** 4 +
44
44
  letters ** 4 * digits ** 2 +
45
45
  digits ** 2 * letters ** 4 +
46
- letters ** 2 * digits ** 2 * ((letters + digits) ** 2 - digits ** 2)
46
+ letters ** 2 * digits ** 2 * ((letters + digits) ** 2 - digits ** 2) +
47
+ digits * letters ** 5
47
48
  return { all, shapes, events: all - shapes } as const
48
49
  })()
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './shapes'
2
2
  export * from './space'
3
+ export * from './junction'
3
4
  export * from './words'
4
5
  export * from './scanCode'
@@ -0,0 +1,18 @@
1
+ import { codeKind, type CodeKind } from './shapes'
2
+
3
+ export const JUNCTION_SEPARATOR = '-'
4
+
5
+ export function junction(...codes: string[]): string {
6
+ if (codes.length < 2) throw new Error('A junction joins two codes or more.')
7
+ for (const code of codes) if (!codeKind(code)) throw new Error(`${code} is no IDv1 code.`)
8
+ return codes.join(JUNCTION_SEPARATOR)
9
+ }
10
+
11
+ export function junctionParts(value: string): { code: string; kind: CodeKind }[] | null {
12
+ const codes = value.split(JUNCTION_SEPARATOR)
13
+ if (codes.length < 2) return null
14
+ const parts = codes.map(code => ({ code, kind: codeKind(code) }))
15
+ return parts.every((part): part is { code: string; kind: CodeKind } => part.kind !== null) ? parts : null
16
+ }
17
+
18
+ export const isJunction = (value: string): boolean => junctionParts(value) !== null
package/src/shapes.ts CHANGED
@@ -7,21 +7,24 @@ export const PRODUCT_CODE = /^[A-Za-z]{4}\d{2}$/
7
7
  export const ACCOUNT_CODE = /^(?:[A-Za-z]{2}\d{4}|[A-Za-z]{4}\d{2})$/
8
8
  export const LIST_CODE = /^\d{2}[A-Za-z]{4}$/
9
9
  export const ITEM_CODE = /^[A-Za-z]{2}\d{2}(?:[A-Za-z][A-Za-z0-9]|\d[A-Za-z])$/
10
+ export const PROJECT_CODE = /^\d[A-Za-z]{5}$/
10
11
 
11
- import { blockedProductCode } from './words'
12
+ import { blockedCodeLetters, blockedProductCode } from './words'
12
13
 
13
- export type CodeKind = 'account' | 'product' | 'list' | 'item'
14
+ export type CodeKind = 'account' | 'product' | 'list' | 'item' | 'project'
14
15
 
15
16
  export const isAccountCode = (value: string): boolean => ACCOUNT_CODE.test(value)
16
17
  export const isProductCode = (value: string): boolean => PRODUCT_CODE.test(value)
17
18
  export const isListCode = (value: string): boolean => LIST_CODE.test(value)
18
19
  export const isItemCode = (value: string): boolean => ITEM_CODE.test(value)
20
+ export const isProjectCode = (value: string): boolean => PROJECT_CODE.test(value)
19
21
 
20
22
  export function codeKind(value: string): CodeKind | null {
21
23
  if (NAME_CODE.test(value)) return 'account'
22
24
  if (PRODUCT_CODE.test(value)) return 'product'
23
25
  if (LIST_CODE.test(value)) return 'list'
24
26
  if (ITEM_CODE.test(value)) return 'item'
27
+ if (PROJECT_CODE.test(value)) return 'project'
25
28
  return null
26
29
  }
27
30
 
@@ -96,7 +99,18 @@ export function itemCodeCandidate(random: Random = Math.random): string {
96
99
  return start + (/\d/.test(first) && /\d/.test(second) ? pick(LETTERS, random) : first) + second
97
100
  }
98
101
 
99
- export const CODE_PATTERN: Record<CodeKind, RegExp> = { account: ACCOUNT_CODE, product: PRODUCT_CODE, list: LIST_CODE, item: ITEM_CODE }
102
+ export function projectCodeCandidate(letters: string | null = null, random: Random = Math.random): string {
103
+ const named = letters ? latinLetters(letters) : ''
104
+ for (let attempt = 0; attempt < 1000; attempt++) {
105
+ const drawn = (named + Array.from({ length: 5 }, () => pick(CAPITALS, random).toLowerCase()).join('')).slice(0, 5)
106
+ const tail = attempt && named ? named.slice(0, 4) + pick(CAPITALS, random).toLowerCase() : drawn
107
+ const code = pick(DIGITS, random) + tail[0].toUpperCase() + tail.slice(1)
108
+ if (!blockedCodeLetters(code)) return code
109
+ }
110
+ throw new Error('No project code could be drawn.')
111
+ }
112
+
113
+ export const CODE_PATTERN: Record<CodeKind, RegExp> = { account: ACCOUNT_CODE, product: PRODUCT_CODE, list: LIST_CODE, item: ITEM_CODE, project: PROJECT_CODE }
100
114
 
101
115
  export const isCodeOf = (kind: CodeKind, value: string): boolean => CODE_PATTERN[kind].test(value)
102
116
 
@@ -105,6 +119,7 @@ export function codeCandidate(kind: CodeKind, options: { letters?: string | null
105
119
  if (kind === 'account') return accountCodeCandidate(options.letters ?? null, random)
106
120
  if (kind === 'product') return productCodeCandidate(random)
107
121
  if (kind === 'list') return listCodeCandidate(random)
122
+ if (kind === 'project') return projectCodeCandidate(options.letters ?? null, random)
108
123
  return itemCodeCandidate(random)
109
124
  }
110
125
 
package/src/space.ts CHANGED
@@ -7,6 +7,7 @@ export const ID_SPACE = {
7
7
  products: LETTERS ** 4 * DIGITS ** 2,
8
8
  lists: DIGITS ** 2 * CAPITALS ** 4,
9
9
  items: LETTERS ** 2 * DIGITS ** 2 * ((LETTERS + DIGITS) ** 2 - DIGITS ** 2),
10
+ projects: DIGITS * LETTERS ** 5,
10
11
  } as const
11
12
 
12
13
  export type IdSpaceKind = keyof typeof ID_SPACE