@auto-engineer/id 1.148.0 → 1.149.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @auto-engineer/id@1.148.0 build /home/runner/work/auto-engineer/auto-engineer/packages/id
2
+ > @auto-engineer/id@1.149.0 build /home/runner/work/auto-engineer/auto-engineer/packages/id
3
3
  > tsc && tsx ../../scripts/fix-esm-imports.ts
4
4
 
5
5
  Fixed ESM imports in dist/
@@ -1,5 +1,5 @@
1
1
 
2
- > @auto-engineer/id@1.147.0 test /home/runner/work/auto-engineer/auto-engineer/packages/id
2
+ > @auto-engineer/id@1.148.0 test /home/runner/work/auto-engineer/auto-engineer/packages/id
3
3
  > vitest run --reporter=dot
4
4
 
5
5
 
@@ -9,6 +9,6 @@
9
9
 
10
10
   Test Files  1 passed (1)
11
11
   Tests  2 passed (2)
12
-  Start at  21:35:18
13
-  Duration  2.05s (transform 407ms, setup 0ms, collect 417ms, tests 30ms, environment 0ms, prepare 630ms)
12
+  Start at  07:22:24
13
+  Duration  2.06s (transform 371ms, setup 0ms, collect 362ms, tests 26ms, environment 0ms, prepare 600ms)
14
14
 
@@ -1,4 +1,4 @@
1
1
 
2
- > @auto-engineer/id@1.147.0 type-check /home/runner/work/auto-engineer/auto-engineer/packages/id
2
+ > @auto-engineer/id@1.148.0 type-check /home/runner/work/auto-engineer/auto-engineer/packages/id
3
3
  > tsc --noEmit
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @auto-engineer/id
2
2
 
3
+ ## 1.149.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`e1eebbd`](https://github.com/BeOnAuto/auto-engineer/commit/e1eebbdf4f209780e790094d2e6887c4fa809f98) Thanks [@github-actions[bot]](https://github.com/github-actions%5Bbot%5D)! - - **server-generator-apollo-emmett**: add Given state ref hints to state.ts.ejs
8
+ - **server-generator-apollo-emmett**: context-aware nonCommandField instructions
9
+ - **server-generator-apollo-emmett**: add state context instruction
10
+ - **server-generator-apollo-emmett**: extract shared template helpers
11
+ - **server-generator-apollo-emmett**: filter state refs from hasGivenEvents in decide.ts.ejs
12
+
13
+ ### Patch Changes
14
+
15
+ - [`d38c81e`](https://github.com/BeOnAuto/auto-engineer/commit/d38c81e7bb442a39626564cf4f6d8d55b60d0a38) Thanks [@SamHatoum](https://github.com/SamHatoum)! -
16
+
3
17
  ## 1.148.0
4
18
 
5
19
  ### Minor Changes
package/README.md CHANGED
@@ -8,7 +8,14 @@ Generate cryptographically secure, URL-safe, unbiased base-62 identifiers.
8
8
 
9
9
  Without `@auto-engineer/id`, you would have to implement your own ID generation with proper cryptographic security, handle modulo bias in random number generation, and ensure URL-safe character encoding.
10
10
 
11
- This package provides compact, URL-safe identifiers using base-62 encoding with cryptographically secure random values. The implementation uses rejection sampling to ensure uniform distribution across all characters.
11
+ This package provides compact, URL-safe identifiers using base-62 encoding (`A-Za-z0-9`) with cryptographically secure random values. The implementation uses rejection sampling to eliminate modulo bias, ensuring uniform distribution across all 62 characters.
12
+
13
+ ## Key Concepts
14
+
15
+ - **Base-62 Encoding** -- Uses `A-Z`, `a-z`, `0-9` (62 characters) to produce identifiers that are safe in URLs, filenames, and HTML attributes without escaping.
16
+ - **Rejection Sampling** -- Random bytes outside an evenly divisible range are discarded, preventing modulo bias that would make some characters more likely than others.
17
+ - **Cryptographic Security** -- Built on `crypto.getRandomValues()` (Web Crypto API), not `Math.random()`.
18
+ - **Entropy** -- A default 9-character token yields 62^9 (~13.5 quadrillion) combinations, approximately 53.6 bits of entropy.
12
19
 
13
20
  ---
14
21
 
@@ -24,8 +31,7 @@ pnpm add @auto-engineer/id
24
31
  import { generateId } from '@auto-engineer/id';
25
32
 
26
33
  const id = generateId();
27
- console.log(id);
28
- // → "aP9ZfWcLQ"
34
+ // → "aP9ZfWcLQ" (9-character base-62 token)
29
35
  ```
30
36
 
31
37
  ---
@@ -38,10 +44,12 @@ console.log(id);
38
44
  import { generateId } from '@auto-engineer/id';
39
45
 
40
46
  const id = generateId();
41
- // 9-character base-62 token
47
+ // 9-character base-62 token, no prefix
42
48
  ```
43
49
 
44
- ### Generate with Prefix
50
+ ### Generate with a Prefix
51
+
52
+ Prefixes must be URL-safe (`A-Za-z0-9_-`). A trailing `-` is allowed as a separator.
45
53
 
46
54
  ```typescript
47
55
  import { generateId } from '@auto-engineer/id';
@@ -50,16 +58,16 @@ const userId = generateId({ prefix: 'user-' });
50
58
  // → "user-xYz7GhtR2"
51
59
  ```
52
60
 
53
- ### Generate with Custom Length
61
+ ### Generate with a Custom Length
54
62
 
55
63
  ```typescript
56
64
  import { generateId } from '@auto-engineer/id';
57
65
 
58
- const longId = generateId({ length: 12 });
59
- // → "QwErTyUiOp12"
66
+ const shortId = generateId({ length: 6 });
67
+ // → "Ab3Xyz"
60
68
  ```
61
69
 
62
- ### Combine Options
70
+ ### Combine Prefix and Length
63
71
 
64
72
  ```typescript
65
73
  import { generateId } from '@auto-engineer/id';
@@ -76,63 +84,58 @@ const orderId = generateId({ prefix: 'ord-', length: 6 });
76
84
 
77
85
  ```typescript
78
86
  import { generateId, type GenerateIdOptions } from '@auto-engineer/id';
79
-
80
- import { BASE62_ALPHABET, BASE62_TOKEN_REGEX, SAFE_PREFIX_REGEX } from '@auto-engineer/id/constants';
81
-
82
- import { generateBase62Token, assertSafePrefix } from '@auto-engineer/id/core';
83
87
  ```
84
88
 
85
89
  ### Functions
86
90
 
87
91
  #### `generateId(options?: GenerateIdOptions): string`
88
92
 
89
- Generate a unique identifier with optional prefix and length.
93
+ Generate a unique identifier with an optional prefix and configurable token length.
94
+
95
+ | Parameter | Type | Default | Description |
96
+ |-----------|----------|---------|----------------------------------------------------|
97
+ | `prefix` | `string` | `''` | String prepended to the token (must be URL-safe) |
98
+ | `length` | `number` | `9` | Length of the random base-62 token portion |
90
99
 
91
- | Parameter | Type | Default | Description |
92
- |-----------|------|---------|-------------|
93
- | `prefix` | `string` | - | String to prepend (must be URL-safe) |
94
- | `length` | `number` | 9 | Token length |
100
+ **Returns:** `string` -- the concatenation of `prefix` and the generated token.
95
101
 
96
- ### GenerateIdOptions
102
+ **Throws:** `Error` if `prefix` contains characters outside `A-Za-z0-9_-`.
103
+
104
+ ### Interfaces
105
+
106
+ #### `GenerateIdOptions`
97
107
 
98
108
  ```typescript
99
109
  type GenerateIdOptions = {
110
+ /** Optional string to prepend before the token. (URL-safe; trailing '-' ok) */
100
111
  prefix?: string;
112
+ /** Token length; default 9 (base-62). */
101
113
  length?: number;
102
114
  };
103
115
  ```
104
116
 
105
- ### Constants
106
-
107
- | Constant | Value | Description |
108
- |----------|-------|-------------|
109
- | `BASE62_ALPHABET` | A-Za-z0-9 | 62-character alphabet |
110
- | `BASE62_TOKEN_REGEX` | `/^[A-Za-z0-9]+$/` | Token validation |
111
- | `SAFE_PREFIX_REGEX` | `/^[A-Za-z0-9_-]+$/` | Prefix validation |
112
-
113
117
  ---
114
118
 
115
119
  ## Architecture
116
120
 
117
121
  ```
118
122
  src/
119
- ├── index.ts
120
- ├── core.ts
121
- └── constants.ts
123
+ ├── index.ts # Public API: generateId, GenerateIdOptions
124
+ ├── core.ts # assertSafePrefix, generateBase62Token (rejection sampling)
125
+ └── constants.ts # BASE62_ALPHABET, regex patterns
122
126
  ```
123
127
 
124
- ### Key Concepts
125
-
126
- - **Base-62 Encoding**: Uses A-Z, a-z, 0-9 for URL-safe identifiers
127
- - **Rejection Sampling**: Ensures unbiased character distribution
128
- - **Cryptographic Security**: Uses `crypto.getRandomValues()`
129
-
130
- ### Entropy Analysis
128
+ ### Internal Modules
131
129
 
132
- With default 9-character token:
133
- - Combinations: 62^9 = ~13.5 quadrillion
134
- - Entropy: ~53.6 bits
130
+ | File | Responsibility |
131
+ |----------------|-------------------------------------------------------------|
132
+ | `constants.ts` | Defines the 62-char alphabet and validation regexes |
133
+ | `core.ts` | Prefix validation and unbiased token generation |
134
+ | `index.ts` | Composes `core` functions into the public `generateId` API |
135
135
 
136
136
  ### Dependencies
137
137
 
138
- This package has minimal dependencies and uses the Web Crypto API for random number generation.
138
+ | Dependency | Kind | Purpose |
139
+ |------------|----------|--------------------------------|
140
+ | `nanoid` | Runtime | Listed in `dependencies` (unused in current source; reserved) |
141
+ | `vitest` | Dev-only | Test runner |
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.148.0",
12
+ "version": "1.149.0",
13
13
  "scripts": {
14
14
  "build": "tsc && tsx ../../scripts/fix-esm-imports.ts",
15
15
  "test": "vitest run --reporter=dot",