@typed/id 1.0.0-beta.6 → 1.0.0-beta.8

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present The Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -44,6 +44,7 @@ for CUID or UUID v5 generation.
44
44
 
45
45
  ```ts
46
46
  import { Ids, Uuid5Namespace } from "@typed/id";
47
+ import { IdsTest } from "@typed/id/IdsTest";
47
48
  import * as Effect from "effect/Effect";
48
49
 
49
50
  const program = Effect.gen(function* () {
@@ -62,7 +63,8 @@ const ids = await Effect.runPromise(Effect.provide(program, Ids.Default));
62
63
  console.log(ids);
63
64
  ```
64
65
 
65
- Use `Ids.Test()` instead of `Ids.Default` when the same program needs deterministic test data.
66
+ Use `IdsTest()` from `@typed/id/IdsTest` instead of `Ids.Default` when the same program needs
67
+ deterministic test data.
66
68
 
67
69
  ## Values and serialization
68
70
 
@@ -102,7 +104,7 @@ The standalone generators have narrower requirements:
102
104
 
103
105
  `RandomValues.Default` uses Web Crypto and is the production entropy source. `RandomValues.Random`
104
106
  derives bytes from Effect's current `Random` service and is intended for controlled tests or
105
- simulations, not as a cryptographic entropy source. `Ids.Test()` supplies fixed internal entropy
107
+ simulations, not as a cryptographic entropy source. `IdsTest()` supplies fixed internal entropy
106
108
  and a controllable clock; its output is for repeatable tests, not production IDs. Service state is
107
109
  process-local and is not a serialization format or a persistence mechanism.
108
110
 
@@ -135,9 +137,9 @@ This provider is deterministic and is therefore test-only. Application code norm
135
137
 
136
138
  ## API reference
137
139
 
138
- ### Ids
140
+ ### Ids and IdsTest
139
141
 
140
- Unified service for generating all ID types. Requires `DateTimes`, `RandomValues`, `CuidState`, and `Uuid7State` (use `Ids.Default` or `Ids.Test()` to provide them).
142
+ Unified service for generating all ID types. Requires `DateTimes`, `RandomValues`, `CuidState`, and `Uuid7State` (use `Ids.Default` or `IdsTest()` to provide them).
141
143
 
142
144
  | Member | Type | Description |
143
145
  | -------------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
@@ -149,12 +151,12 @@ Unified service for generating all ID types. Requires `DateTimes`, `RandomValues
149
151
  | `Ids.uuid5` | `(name, namespace) => Effect<Uuid5, IllegalArgumentError, Ids>` | Generate a UUID v5; namespaces not exactly 16 bytes fail. Also has `.dns`, `.url`, `.oid`, and `.x500`. |
150
152
  | `Ids.uuid7` | `Effect<Uuid7, IllegalArgumentError, Ids>` | Generate a UUID v7; timestamps outside its 48-bit field fail before state mutation. |
151
153
  | `Ids.Default` | `Layer<Ids \| DateTimes \| RandomValues>` | Layer that provides `Ids` with default Cuid/Uuid7/DateTimes/RandomValues. |
152
- | `Ids.Test(options?)` | `Layer<Ids \| DateTimes \| RandomValues, IllegalArgumentError>` | Reproducible test layer; invalid `currentTime` values fail. |
154
+ | `IdsTest(options?)` | `Layer<Ids \| DateTimes \| RandomValues, IllegalArgumentError>` | Reproducible test layer; invalid `currentTime` values fail. |
153
155
 
154
- **TestOptions:**
156
+ **IdsTestOptions:**
155
157
  `{ currentTime?: number | string | Date; envData?: string }`
156
158
 
157
- `Ids.Test()` defaults to time `1_400_000_000_000` and uses fixed internal test entropy.
159
+ `IdsTest()` defaults to time `1_400_000_000_000` and uses fixed internal test entropy.
158
160
 
159
161
  ---
160
162
 
package/dist/Cuid.d.ts CHANGED
@@ -17,7 +17,7 @@ import { RandomValues } from "./RandomValues.js";
17
17
  * const id = Cuid.make("a00000000000000000000000")
18
18
  * ```
19
19
  * See [Effect Schema](https://effect.website/docs/schema/introduction/).
20
- * @category Schemas
20
+ * @category ID schemas
21
21
  * @since 1.0.0
22
22
  */
23
23
  export declare const Cuid: Schema.brand<Schema.String, "@typed/id/CUID">;
@@ -34,7 +34,7 @@ export type Cuid = Schema.Schema.Type<typeof Cuid>;
34
34
  * import { isCuid } from "@typed/id/Cuid"
35
35
  * isCuid("a00000000000000000000000")
36
36
  * ```
37
- * @category Refinements
37
+ * @category ID validation
38
38
  * @since 1.0.0
39
39
  */
40
40
  export declare const isCuid: (value: string) => value is Cuid;
@@ -50,7 +50,7 @@ export declare const isCuid: (value: string) => value is Cuid;
50
50
  * import type { CuidSeed } from "@typed/id/Cuid"
51
51
  * const seed: CuidSeed = { timestamp: 0, counter: 0, random: new Uint8Array(32) as CuidSeed["random"], fingerprint: "test" }
52
52
  * ```
53
- * @category Models
53
+ * @category ID types
54
54
  * @since 1.0.0
55
55
  */
56
56
  export type CuidSeed = {
@@ -100,7 +100,7 @@ declare const CuidState_base: Context.ServiceClass<CuidState, "@typed/id/CuidSta
100
100
  * const program = Effect.provide(cuid, CuidState.Default)
101
101
  * ```
102
102
  * See [Effect services](https://effect.website/docs/requirements-management/services/) and [Layers](https://effect.website/docs/requirements-management/layers/).
103
- * @category Services
103
+ * @category Sequence state
104
104
  * @since 1.0.0
105
105
  */
106
106
  export declare class CuidState extends CuidState_base {
@@ -129,7 +129,7 @@ export declare class CuidState extends CuidState_base {
129
129
  * The explicit Layer gives production code a standard service while keeping test and environment-specific alternatives replaceable.
130
130
  * ## Ownership and lifetime
131
131
  * Layer acquisition creates one counter state; the surrounding Layer Scope owns it. Web Crypto must be available in the runtime.
132
- * @category Layers
132
+ * @category Production layers
133
133
  * @since 1.0.0
134
134
  */
135
135
  static readonly Default: Layer.Layer<CuidState, never, never>;
@@ -147,7 +147,7 @@ export declare class CuidState extends CuidState_base {
147
147
  * import { Effect } from "effect"
148
148
  * const id = Effect.provide(cuid, CuidState.Default)
149
149
  * ```
150
- * @category Generators
150
+ * @category ID generation
151
151
  * @since 1.0.0
152
152
  */
153
153
  export declare const cuid: Effect.Effect<Cuid, never, CuidState>;
package/dist/Cuid.js CHANGED
@@ -22,7 +22,7 @@ const INITIAL_COUNT_MAX = 476782367;
22
22
  * const id = Cuid.make("a00000000000000000000000")
23
23
  * ```
24
24
  * See [Effect Schema](https://effect.website/docs/schema/introduction/).
25
- * @category Schemas
25
+ * @category ID schemas
26
26
  * @since 1.0.0
27
27
  */
28
28
  export const Cuid = Schema.String.pipe(Schema.check(Schema.isPattern(/^[a-z][0-9a-z]{23}$/)), Schema.brand("@typed/id/CUID"));
@@ -38,7 +38,7 @@ export const Cuid = Schema.String.pipe(Schema.check(Schema.isPattern(/^[a-z][0-9
38
38
  * import { isCuid } from "@typed/id/Cuid"
39
39
  * isCuid("a00000000000000000000000")
40
40
  * ```
41
- * @category Refinements
41
+ * @category ID validation
42
42
  * @since 1.0.0
43
43
  */
44
44
  export const isCuid = Schema.is(Cuid);
@@ -56,7 +56,7 @@ export const isCuid = Schema.is(Cuid);
56
56
  * const program = Effect.provide(cuid, CuidState.Default)
57
57
  * ```
58
58
  * See [Effect services](https://effect.website/docs/requirements-management/services/) and [Layers](https://effect.website/docs/requirements-management/layers/).
59
- * @category Services
59
+ * @category Sequence state
60
60
  * @since 1.0.0
61
61
  */
62
62
  export class CuidState extends Context.Service()("@typed/id/CuidState", {
@@ -106,7 +106,7 @@ export class CuidState extends Context.Service()("@typed/id/CuidState", {
106
106
  * The explicit Layer gives production code a standard service while keeping test and environment-specific alternatives replaceable.
107
107
  * ## Ownership and lifetime
108
108
  * Layer acquisition creates one counter state; the surrounding Layer Scope owns it. Web Crypto must be available in the runtime.
109
- * @category Layers
109
+ * @category Production layers
110
110
  * @since 1.0.0
111
111
  */
112
112
  static Default = Layer.effect(CuidState, CuidState.make("node")).pipe(Layer.provide([DateTimes.Default, RandomValues.Default]));
@@ -124,7 +124,7 @@ export class CuidState extends Context.Service()("@typed/id/CuidState", {
124
124
  * import { Effect } from "effect"
125
125
  * const id = Effect.provide(cuid, CuidState.Default)
126
126
  * ```
127
- * @category Generators
127
+ * @category ID generation
128
128
  * @since 1.0.0
129
129
  */
130
130
  export const cuid = Effect.flatMap(CuidState.next, cuidFromSeed);
@@ -25,7 +25,7 @@ declare const DateTimes_base: Context.ServiceClass<DateTimes, "@typed/id/DateTim
25
25
  * const now = Effect.provide(DateTimes.now, DateTimes.Default)
26
26
  * ```
27
27
  * See [Effect Clock](https://effect.website/docs/testing/testclock/).
28
- * @category Services
28
+ * @category Time services
29
29
  * @since 1.0.0
30
30
  */
31
31
  export declare class DateTimes extends DateTimes_base {
@@ -36,7 +36,7 @@ export declare class DateTimes extends DateTimes_base {
36
36
  * A service-backed read avoids hard-wiring `Date.now` into generators and tests.
37
37
  * ## Ownership and lifetime
38
38
  * This Effect acquires no resources and uses the DateTimes service for one invocation.
39
- * @category Services
39
+ * @category Time services
40
40
  * @since 1.0.0
41
41
  */
42
42
  static readonly now: Effect.Effect<number, never, DateTimes>;
@@ -47,7 +47,7 @@ export declare class DateTimes extends DateTimes_base {
47
47
  * The Date view stays aligned with the same replaceable time source as epoch-millisecond reads.
48
48
  * ## Ownership and lifetime
49
49
  * This Effect acquires no resources and uses the DateTimes service for one invocation.
50
- * @category Services
50
+ * @category Time services
51
51
  * @since 1.0.0
52
52
  */
53
53
  static readonly date: Effect.Effect<Date, never, DateTimes>;
@@ -58,7 +58,7 @@ export declare class DateTimes extends DateTimes_base {
58
58
  * The production default is explicit and replaceable rather than hidden in each generator.
59
59
  * ## Ownership and lifetime
60
60
  * The surrounding Layer Scope owns the service; reads allocate only their returned Date values.
61
- * @category Layers
61
+ * @category Time services
62
62
  * @since 1.0.0
63
63
  */
64
64
  static readonly Default: Layer.Layer<DateTimes, never, never>;
@@ -74,7 +74,7 @@ export declare class DateTimes extends DateTimes_base {
74
74
  * import { DateTimes } from "@typed/id/DateTimes"
75
75
  * const fixed = DateTimes.Fixed("2026-01-01T00:00:00Z")
76
76
  * ```
77
- * @category Layers
77
+ * @category Time services
78
78
  * @since 1.0.0
79
79
  */
80
80
  static readonly Fixed: (baseDate: number | string | Date) => Layer.Layer<DateTimes, Cause.IllegalArgumentError, never>;
package/dist/DateTimes.js CHANGED
@@ -17,7 +17,7 @@ import * as Context from "effect/Context";
17
17
  * const now = Effect.provide(DateTimes.now, DateTimes.Default)
18
18
  * ```
19
19
  * See [Effect Clock](https://effect.website/docs/testing/testclock/).
20
- * @category Services
20
+ * @category Time services
21
21
  * @since 1.0.0
22
22
  */
23
23
  export class DateTimes extends Context.Service()("@typed/id/DateTimes", {
@@ -33,7 +33,7 @@ export class DateTimes extends Context.Service()("@typed/id/DateTimes", {
33
33
  * A service-backed read avoids hard-wiring `Date.now` into generators and tests.
34
34
  * ## Ownership and lifetime
35
35
  * This Effect acquires no resources and uses the DateTimes service for one invocation.
36
- * @category Services
36
+ * @category Time services
37
37
  * @since 1.0.0
38
38
  */
39
39
  static now = Effect.flatMap(DateTimes, ({ now }) => now);
@@ -44,7 +44,7 @@ export class DateTimes extends Context.Service()("@typed/id/DateTimes", {
44
44
  * The Date view stays aligned with the same replaceable time source as epoch-millisecond reads.
45
45
  * ## Ownership and lifetime
46
46
  * This Effect acquires no resources and uses the DateTimes service for one invocation.
47
- * @category Services
47
+ * @category Time services
48
48
  * @since 1.0.0
49
49
  */
50
50
  static date = Effect.flatMap(DateTimes, ({ date }) => date);
@@ -55,7 +55,7 @@ export class DateTimes extends Context.Service()("@typed/id/DateTimes", {
55
55
  * The production default is explicit and replaceable rather than hidden in each generator.
56
56
  * ## Ownership and lifetime
57
57
  * The surrounding Layer Scope owns the service; reads allocate only their returned Date values.
58
- * @category Layers
58
+ * @category Time services
59
59
  * @since 1.0.0
60
60
  */
61
61
  static Default = Layer.effect(DateTimes, DateTimes.make);
@@ -71,7 +71,7 @@ export class DateTimes extends Context.Service()("@typed/id/DateTimes", {
71
71
  * import { DateTimes } from "@typed/id/DateTimes"
72
72
  * const fixed = DateTimes.Fixed("2026-01-01T00:00:00Z")
73
73
  * ```
74
- * @category Layers
74
+ * @category Time services
75
75
  * @since 1.0.0
76
76
  */
77
77
  static Fixed = (baseDate) => Layer.effect(DateTimes, Effect.gen(function* () {
package/dist/Ids.d.ts CHANGED
@@ -13,7 +13,6 @@ import type { Uuid4 } from "./Uuid4.js";
13
13
  import { type Uuid5, Uuid5Namespace } from "./Uuid5.js";
14
14
  import type { Uuid7 } from "./Uuid7.js";
15
15
  import { Uuid7State } from "./Uuid7.js";
16
- import { TestClock } from "effect/testing";
17
16
  declare const Ids_base: Context.ServiceClass<Ids, "@typed/id/Ids", {
18
17
  cuid: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/CUID">, never, never>;
19
18
  ksuid: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/KSUID">, Cause.IllegalArgumentError, never>;
@@ -72,7 +71,7 @@ export declare class Ids extends Ids_base {
72
71
  * The facade shares the Ids-owned CuidState instead of allocating a new sequence for every call.
73
72
  * ## Ownership and lifetime
74
73
  * This Effect acquires no resources and uses state owned by the provided Ids Layer.
75
- * @category Generators
74
+ * @category ID generation
76
75
  * @since 1.0.0
77
76
  */
78
77
  static readonly cuid: Effect.Effect<Cuid, never, Ids>;
@@ -83,7 +82,7 @@ export declare class Ids extends Ids_base {
83
82
  * The facade reuses captured time and entropy while retaining `IllegalArgumentError` for invalid KSUID timestamps.
84
83
  * ## Ownership and lifetime
85
84
  * This Effect acquires no persistent resource and uses services owned by the provided Ids Layer.
86
- * @category Generators
85
+ * @category ID generation
87
86
  * @since 1.0.0
88
87
  */
89
88
  static readonly ksuid: Effect.Effect<Ksuid, Cause.IllegalArgumentError, Ids>;
@@ -94,7 +93,7 @@ export declare class Ids extends Ids_base {
94
93
  * The facade makes the selected entropy implementation available through one application dependency.
95
94
  * ## Ownership and lifetime
96
95
  * This Effect acquires no persistent resource and uses entropy owned by the provided Ids Layer.
97
- * @category Generators
96
+ * @category ID generation
98
97
  * @since 1.0.0
99
98
  */
100
99
  static readonly nanoId: Effect.Effect<NanoId, never, Ids>;
@@ -105,7 +104,7 @@ export declare class Ids extends Ids_base {
105
104
  * The facade reuses captured time and entropy while retaining `IllegalArgumentError` for invalid 48-bit timestamps.
106
105
  * ## Ownership and lifetime
107
106
  * This Effect acquires no persistent resource and uses services owned by the provided Ids Layer.
108
- * @category Generators
107
+ * @category ID generation
109
108
  * @since 1.0.0
110
109
  */
111
110
  static readonly ulid: Effect.Effect<Ulid, Cause.IllegalArgumentError, Ids>;
@@ -116,7 +115,7 @@ export declare class Ids extends Ids_base {
116
115
  * The facade keeps entropy selection replaceable while preserving UUID version and variant semantics.
117
116
  * ## Ownership and lifetime
118
117
  * This Effect acquires no persistent resource and uses entropy owned by the provided Ids Layer.
119
- * @category Generators
118
+ * @category ID generation
120
119
  * @since 1.0.0
121
120
  */
122
121
  static readonly uuid4: Effect.Effect<Uuid4, never, Ids>;
@@ -133,7 +132,7 @@ export declare class Ids extends Ids_base {
133
132
  * import { Effect } from "effect"
134
133
  * const program = Ids.uuid5.dns("example.com").pipe(Effect.provide(Ids.Default))
135
134
  * ```
136
- * @category Generators
135
+ * @category ID generation
137
136
  * @since 1.0.0
138
137
  */
139
138
  static readonly uuid5: {
@@ -157,7 +156,7 @@ export declare class Ids extends Ids_base {
157
156
  * The facade shares one lazy Uuid7State per Ids Layer, preserving local monotonicity and typed timestamp errors.
158
157
  * ## Ownership and lifetime
159
158
  * This Effect acquires no resources and uses sequence state owned by the provided Ids Layer.
160
- * @category Generators
159
+ * @category ID generation
161
160
  * @since 1.0.0
162
161
  */
163
162
  static readonly uuid7: Effect.Effect<Uuid7, Cause.IllegalArgumentError, Ids>;
@@ -168,48 +167,10 @@ export declare class Ids extends Ids_base {
168
167
  * The standard Layer uses system time and Web Crypto while lazily creating sequence state only when CUID or UUIDv7 is first requested.
169
168
  * ## Ownership and lifetime
170
169
  * The surrounding Layer Scope owns captured services and lazy sequence state; Web Crypto must exist in the runtime.
171
- * @category Layers
170
+ * @category Production layers
172
171
  * @since 1.0.0
173
172
  */
174
173
  static readonly Default: Layer.Layer<Ids | DateTimes | RandomValues, never, never>;
175
- /**
176
- * Provides deterministic Ids, time, entropy, and TestClock services.
177
- * @remarks
178
- * ## Why
179
- * Reproducible generators make exact sequences testable; the deterministic entropy is for tests and simulations, not security.
180
- * ## Ownership and lifetime
181
- * Each Layer construction owns an independent clock, random sequence, and lazy CUID/UUIDv7 state for its Scope.
182
- * @example
183
- * ```ts
184
- * import { Ids } from "@typed/id/Ids"
185
- * import { Effect } from "effect"
186
- * const deterministic = Ids.uuid7.pipe(Effect.provide(Ids.Test({ currentTime: 0 })))
187
- * ```
188
- * @category Testing
189
- * @since 1.0.0
190
- */
191
- static readonly Test: (options?: TestOptions) => Layer.Layer<Ids | DateTimes | RandomValues | TestClock.TestClock, Cause.IllegalArgumentError>;
192
174
  }
193
- /**
194
- * Configuration for the deterministic Ids test Layer.
195
- * @remarks
196
- * ## Why
197
- * Explicit initial time and CUID environment data let tests reproduce generator sequences without ambient process state.
198
- * ## Ownership and lifetime
199
- * This plain configuration acquires no resources and is read only by Layer acquisition; TypeScript `readonly` does not freeze it at runtime.
200
- * @example
201
- * ```ts
202
- * import type { TestOptions } from "@typed/id/Ids"
203
- * const options: TestOptions = { currentTime: "2026-01-01T00:00:00Z", envData: "test-worker" }
204
- * ```
205
- * @category Testing
206
- * @since 1.0.0
207
- */
208
- export type TestOptions = {
209
- /** Base time passed to `DateTimes.Fixed`; invalid dates fail Layer acquisition. @since 1.0.0 */
210
- readonly currentTime?: number | string | Date;
211
- /** CUID caller discriminator used when the test CuidState is created. @since 1.0.0 */
212
- readonly envData?: string;
213
- };
214
175
  export {};
215
176
  //# sourceMappingURL=Ids.d.ts.map
package/dist/Ids.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Ids.d.ts","sourceRoot":"","sources":["../src/Ids.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAQ,SAAS,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,KAAK,KAAK,EAAS,cAAc,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAS,UAAU,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;;;;;;;;oBA+BxB,cAAc,GACxB,CAAC,IAAI,EAAE,MAAM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AC,CAAC;QACtF,qEAAqE;QACrE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;KACxF,CAUC;IACF;;;;;;;;;OASG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAG1E;IAEF;;;;;;;;;OASG;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,SAAS,GAAG,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,CAGZ;CACvE"}
package/dist/Ids.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import * as Effect from "effect/Effect";
2
2
  import { dual } from "effect/Function";
3
3
  import * as Layer from "effect/Layer";
4
- import * as Random from "effect/Random";
5
4
  import * as Context from "effect/Context";
6
- import { cuid, CuidState } from "./Cuid.js";
5
+ import { cuid } from "./Cuid.js";
7
6
  import { DateTimes } from "./DateTimes.js";
8
7
  import { ksuid } from "./Ksuid.js";
9
8
  import { nanoId } from "./NanoId.js";
@@ -11,9 +10,8 @@ import { RandomValues } from "./RandomValues.js";
11
10
  import { ulid } from "./Ulid.js";
12
11
  import { uuid4 } from "./Uuid4.js";
13
12
  import { uuid5, Uuid5Namespace } from "./Uuid5.js";
14
- import { uuid7, Uuid7State } from "./Uuid7.js";
15
- import { TestClock } from "effect/testing";
16
- const testRandomValues = () => Layer.effect(RandomValues, RandomValues.pipe(Effect.provide(RandomValues.Random), Random.withSeed("@typed/id/Ids.Test")));
13
+ import { uuid7 } from "./Uuid7.js";
14
+ import { makeLazyIds } from "./internal/Ids.js";
17
15
  /**
18
16
  * Unified Effect service for every Typed ID generator.
19
17
  * @remarks
@@ -58,7 +56,7 @@ export class Ids extends Context.Service()("@typed/id/Ids", {
58
56
  * The facade shares the Ids-owned CuidState instead of allocating a new sequence for every call.
59
57
  * ## Ownership and lifetime
60
58
  * This Effect acquires no resources and uses state owned by the provided Ids Layer.
61
- * @category Generators
59
+ * @category ID generation
62
60
  * @since 1.0.0
63
61
  */
64
62
  static cuid = Effect.flatMap(Ids, ({ cuid }) => cuid);
@@ -69,7 +67,7 @@ export class Ids extends Context.Service()("@typed/id/Ids", {
69
67
  * The facade reuses captured time and entropy while retaining `IllegalArgumentError` for invalid KSUID timestamps.
70
68
  * ## Ownership and lifetime
71
69
  * This Effect acquires no persistent resource and uses services owned by the provided Ids Layer.
72
- * @category Generators
70
+ * @category ID generation
73
71
  * @since 1.0.0
74
72
  */
75
73
  static ksuid = Effect.flatMap(Ids, ({ ksuid }) => ksuid);
@@ -80,7 +78,7 @@ export class Ids extends Context.Service()("@typed/id/Ids", {
80
78
  * The facade makes the selected entropy implementation available through one application dependency.
81
79
  * ## Ownership and lifetime
82
80
  * This Effect acquires no persistent resource and uses entropy owned by the provided Ids Layer.
83
- * @category Generators
81
+ * @category ID generation
84
82
  * @since 1.0.0
85
83
  */
86
84
  static nanoId = Effect.flatMap(Ids, ({ nanoId }) => nanoId);
@@ -91,7 +89,7 @@ export class Ids extends Context.Service()("@typed/id/Ids", {
91
89
  * The facade reuses captured time and entropy while retaining `IllegalArgumentError` for invalid 48-bit timestamps.
92
90
  * ## Ownership and lifetime
93
91
  * This Effect acquires no persistent resource and uses services owned by the provided Ids Layer.
94
- * @category Generators
92
+ * @category ID generation
95
93
  * @since 1.0.0
96
94
  */
97
95
  static ulid = Effect.flatMap(Ids, ({ ulid }) => ulid);
@@ -102,7 +100,7 @@ export class Ids extends Context.Service()("@typed/id/Ids", {
102
100
  * The facade keeps entropy selection replaceable while preserving UUID version and variant semantics.
103
101
  * ## Ownership and lifetime
104
102
  * This Effect acquires no persistent resource and uses entropy owned by the provided Ids Layer.
105
- * @category Generators
103
+ * @category ID generation
106
104
  * @since 1.0.0
107
105
  */
108
106
  static uuid4 = Effect.flatMap(Ids, ({ uuid4 }) => uuid4);
@@ -119,7 +117,7 @@ export class Ids extends Context.Service()("@typed/id/Ids", {
119
117
  * import { Effect } from "effect"
120
118
  * const program = Ids.uuid5.dns("example.com").pipe(Effect.provide(Ids.Default))
121
119
  * ```
122
- * @category Generators
120
+ * @category ID generation
123
121
  * @since 1.0.0
124
122
  */
125
123
  static uuid5 = Object.assign(dual(2, (name, namespace) => Effect.flatMap(Ids, ({ uuid5 }) => uuid5(name, namespace))), {
@@ -135,7 +133,7 @@ export class Ids extends Context.Service()("@typed/id/Ids", {
135
133
  * The facade shares one lazy Uuid7State per Ids Layer, preserving local monotonicity and typed timestamp errors.
136
134
  * ## Ownership and lifetime
137
135
  * This Effect acquires no resources and uses sequence state owned by the provided Ids Layer.
138
- * @category Generators
136
+ * @category ID generation
139
137
  * @since 1.0.0
140
138
  */
141
139
  static uuid7 = Effect.flatMap(Ids, ({ uuid7 }) => uuid7);
@@ -146,50 +144,8 @@ export class Ids extends Context.Service()("@typed/id/Ids", {
146
144
  * The standard Layer uses system time and Web Crypto while lazily creating sequence state only when CUID or UUIDv7 is first requested.
147
145
  * ## Ownership and lifetime
148
146
  * The surrounding Layer Scope owns captured services and lazy sequence state; Web Crypto must exist in the runtime.
149
- * @category Layers
147
+ * @category Production layers
150
148
  * @since 1.0.0
151
149
  */
152
150
  static Default = Layer.effect(Ids, makeLazyIds("node")).pipe(Layer.provideMerge([DateTimes.Default, RandomValues.Default]));
153
- /**
154
- * Provides deterministic Ids, time, entropy, and TestClock services.
155
- * @remarks
156
- * ## Why
157
- * Reproducible generators make exact sequences testable; the deterministic entropy is for tests and simulations, not security.
158
- * ## Ownership and lifetime
159
- * Each Layer construction owns an independent clock, random sequence, and lazy CUID/UUIDv7 state for its Scope.
160
- * @example
161
- * ```ts
162
- * import { Ids } from "@typed/id/Ids"
163
- * import { Effect } from "effect"
164
- * const deterministic = Ids.uuid7.pipe(Effect.provide(Ids.Test({ currentTime: 0 })))
165
- * ```
166
- * @category Testing
167
- * @since 1.0.0
168
- */
169
- static Test = (options = {}) => {
170
- const services = Layer.mergeAll(DateTimes.Fixed(options.currentTime ?? 1400000000000), testRandomValues());
171
- return Layer.effect(Ids, makeLazyIds(options.envData ?? "node")).pipe(Layer.provide(services), Layer.provideMerge(services), Layer.provideMerge(TestClock.layer({})));
172
- };
173
- }
174
- function makeLazyIds(envData) {
175
- return Effect.gen(function* () {
176
- const services = yield* Effect.context();
177
- const getCuidState = yield* Effect.cached(Effect.provide(CuidState.make(envData), services));
178
- const getUuid7State = yield* Effect.cached(Effect.provide(Uuid7State.make, services));
179
- const uuid5_ = Object.assign(dual(2, (name, namespace) => Effect.provide(uuid5(name, namespace), services)), {
180
- dns: uuid5(Uuid5Namespace.DNS),
181
- url: uuid5(Uuid5Namespace.URL),
182
- oid: uuid5(Uuid5Namespace.OID),
183
- x500: uuid5(Uuid5Namespace.X500),
184
- });
185
- return {
186
- cuid: Effect.flatMap(getCuidState, (state) => Effect.provideService(cuid, CuidState, state)),
187
- ksuid: Effect.provide(ksuid, services),
188
- nanoId: Effect.provide(nanoId, services),
189
- ulid: Effect.provide(ulid, services),
190
- uuid4: Effect.provide(uuid4, services),
191
- uuid5: uuid5_,
192
- uuid7: Effect.flatMap(getUuid7State, (state) => Effect.provideService(uuid7, Uuid7State, state)),
193
- };
194
- });
195
151
  }
@@ -0,0 +1,34 @@
1
+ import * as Cause from "effect/Cause";
2
+ import * as Layer from "effect/Layer";
3
+ import * as TestClock from "effect/testing/TestClock";
4
+ import { DateTimes } from "./DateTimes.js";
5
+ import { Ids } from "./Ids.js";
6
+ import { RandomValues } from "./RandomValues.js";
7
+ import { Uuid7State } from "./Uuid7.js";
8
+ /**
9
+ * Provides deterministic IDs, time, entropy, and TestClock services.
10
+ *
11
+ * @remarks
12
+ * This test-only entry point keeps Effect's testing runtime out of production imports of `Ids`.
13
+ * Each invocation owns an independent clock, random sequence, and lazy CUID/UUIDv7 state.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { Ids } from "@typed/id/Ids"
18
+ * import { IdsTest } from "@typed/id/IdsTest"
19
+ * import { Effect } from "effect"
20
+ * const deterministic = Ids.uuid7.pipe(Effect.provide(IdsTest({ currentTime: 0 })))
21
+ * ```
22
+ *
23
+ * @category Deterministic testing
24
+ * @since 1.0.0
25
+ */
26
+ export declare const IdsTest: (options?: IdsTestOptions) => Layer.Layer<Ids | DateTimes | RandomValues | Uuid7State | TestClock.TestClock, Cause.IllegalArgumentError>;
27
+ /** Configuration for the deterministic ID test layer. @since 1.0.0 */
28
+ export type IdsTestOptions = {
29
+ /** Fixed generator time; invalid dates fail Layer acquisition. @since 1.0.0 */
30
+ readonly currentTime?: number | string | Date;
31
+ /** CUID caller discriminator used when the test CuidState is created. @since 1.0.0 */
32
+ readonly envData?: string;
33
+ };
34
+ //# sourceMappingURL=IdsTest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IdsTest.d.ts","sourceRoot":"","sources":["../src/IdsTest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAyBxC;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,OAAO,aACT,cAAc,KACtB,KAAK,CAAC,KAAK,CACZ,GAAG,GAAG,SAAS,GAAG,YAAY,GAAG,UAAU,GAAG,SAAS,CAAC,SAAS,EACjE,KAAK,CAAC,oBAAoB,CAe3B,CAAC;AAEF,sEAAsE;AACtE,MAAM,MAAM,cAAc,GAAG;IAC3B,+EAA+E;IAC/E,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC9C,sFAAsF;IACtF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC"}
@@ -0,0 +1,44 @@
1
+ import * as Cause from "effect/Cause";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
4
+ import * as Random from "effect/Random";
5
+ import * as TestClock from "effect/testing/TestClock";
6
+ import { DateTimes } from "./DateTimes.js";
7
+ import { Ids } from "./Ids.js";
8
+ import { makeLazyIds } from "./internal/Ids.js";
9
+ import { RandomValues } from "./RandomValues.js";
10
+ import { Uuid7State } from "./Uuid7.js";
11
+ const testRandomValues = () => Layer.effect(RandomValues, RandomValues.pipe(Effect.provide(RandomValues.Random), Random.withSeed("@typed/id/IdsTest")));
12
+ const fixedDateTimes = (baseDate) => Layer.effect(DateTimes, Effect.gen(function* () {
13
+ const millis = new Date(baseDate).getTime();
14
+ if (!Number.isFinite(millis)) {
15
+ return yield* new Cause.IllegalArgumentError(`Invalid base date: ${String(baseDate)}`);
16
+ }
17
+ return DateTimes.of({
18
+ now: Effect.succeed(millis),
19
+ date: Effect.sync(() => new Date(millis)),
20
+ });
21
+ }));
22
+ /**
23
+ * Provides deterministic IDs, time, entropy, and TestClock services.
24
+ *
25
+ * @remarks
26
+ * This test-only entry point keeps Effect's testing runtime out of production imports of `Ids`.
27
+ * Each invocation owns an independent clock, random sequence, and lazy CUID/UUIDv7 state.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { Ids } from "@typed/id/Ids"
32
+ * import { IdsTest } from "@typed/id/IdsTest"
33
+ * import { Effect } from "effect"
34
+ * const deterministic = Ids.uuid7.pipe(Effect.provide(IdsTest({ currentTime: 0 })))
35
+ * ```
36
+ *
37
+ * @category Deterministic testing
38
+ * @since 1.0.0
39
+ */
40
+ export const IdsTest = (options = {}) => {
41
+ const services = Layer.mergeAll(fixedDateTimes(options.currentTime ?? 1400000000000), testRandomValues());
42
+ const uuid7State = Layer.effect(Uuid7State, Uuid7State.make).pipe(Layer.provide(services));
43
+ return Layer.effect(Ids, makeLazyIds(options.envData ?? "node")).pipe(Layer.provide(services), Layer.provideMerge(services), Layer.provideMerge(TestClock.layer({})), Layer.provideMerge(uuid7State));
44
+ };
package/dist/Ksuid.d.ts CHANGED
@@ -16,7 +16,7 @@ import { RandomValues } from "./RandomValues.js";
16
16
  * import { Schema } from "effect"
17
17
  * const id = Schema.decodeUnknownSync(Ksuid)("0ujtsYcgvSTl8PAuAdqWYSMnLOv")
18
18
  * ```
19
- * @category Schemas
19
+ * @category ID schemas
20
20
  * @since 1.0.0
21
21
  */
22
22
  export declare const Ksuid: Schema.brand<Schema.String, "@typed/id/KSUID">;
@@ -33,7 +33,7 @@ export type Ksuid = typeof Ksuid.Type;
33
33
  * import { isKsuid } from "@typed/id/Ksuid"
34
34
  * isKsuid("0ujtsYcgvSTl8PAuAdqWYSMnLOv")
35
35
  * ```
36
- * @category Refinements
36
+ * @category ID validation
37
37
  * @since 1.0.0
38
38
  */
39
39
  export declare const isKsuid: (value: string) => value is Ksuid;
@@ -52,7 +52,7 @@ export declare const isKsuid: (value: string) => value is Ksuid;
52
52
  * import { Effect, Layer } from "effect"
53
53
  * const id = Effect.provide(ksuid, Layer.merge(DateTimes.Default, RandomValues.Default))
54
54
  * ```
55
- * @category Generators
55
+ * @category ID generation
56
56
  * @since 1.0.0
57
57
  */
58
58
  export declare const ksuid: Effect.Effect<Ksuid, Cause.IllegalArgumentError, DateTimes | RandomValues>;