@typed/id 0.17.2 → 1.0.0-beta.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.
Files changed (80) hide show
  1. package/README.md +164 -0
  2. package/dist/Cuid.d.ts +28 -17
  3. package/dist/Cuid.d.ts.map +1 -0
  4. package/dist/Cuid.js +41 -46
  5. package/dist/DateTimes.d.ts +15 -15
  6. package/dist/DateTimes.d.ts.map +1 -0
  7. package/dist/DateTimes.js +18 -15
  8. package/dist/Id.test.d.ts +2 -0
  9. package/dist/Id.test.d.ts.map +1 -0
  10. package/dist/Id.test.js +190 -0
  11. package/dist/Ids.d.ts +71 -0
  12. package/dist/Ids.d.ts.map +1 -0
  13. package/dist/Ids.js +51 -0
  14. package/dist/Ksuid.d.ts +8 -7
  15. package/dist/Ksuid.d.ts.map +1 -0
  16. package/dist/Ksuid.js +26 -33
  17. package/dist/NanoId.d.ts +8 -32
  18. package/dist/NanoId.d.ts.map +1 -0
  19. package/dist/NanoId.js +10 -14
  20. package/dist/RandomValues.d.ts +13 -0
  21. package/dist/RandomValues.d.ts.map +1 -0
  22. package/dist/RandomValues.js +19 -0
  23. package/dist/Ulid.d.ts +8 -30
  24. package/dist/Ulid.d.ts.map +1 -0
  25. package/dist/Ulid.js +15 -20
  26. package/dist/Uuid4.d.ts +7 -6
  27. package/dist/Uuid4.d.ts.map +1 -0
  28. package/dist/Uuid4.js +8 -10
  29. package/dist/Uuid5.d.ts +13 -19
  30. package/dist/Uuid5.d.ts.map +1 -0
  31. package/dist/Uuid5.js +14 -16
  32. package/dist/Uuid7.d.ts +35 -18
  33. package/dist/Uuid7.d.ts.map +1 -0
  34. package/dist/Uuid7.js +23 -22
  35. package/dist/_sha.d.ts +4 -0
  36. package/dist/_sha.d.ts.map +1 -0
  37. package/dist/_sha.js +3 -0
  38. package/dist/{UuidStringify.d.ts → _uuid-stringify.d.ts} +1 -0
  39. package/dist/_uuid-stringify.d.ts.map +1 -0
  40. package/dist/_uuid-stringify.js +28 -0
  41. package/dist/index.d.ts +11 -9
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +10 -10
  44. package/package.json +19 -30
  45. package/src/Cuid.ts +87 -100
  46. package/src/DateTimes.ts +22 -26
  47. package/src/Id.test.ts +217 -0
  48. package/src/Ids.ts +124 -0
  49. package/src/Ksuid.ts +54 -62
  50. package/src/NanoId.ts +20 -47
  51. package/src/RandomValues.ts +33 -0
  52. package/src/Ulid.ts +37 -68
  53. package/src/Uuid4.ts +20 -18
  54. package/src/Uuid5.ts +39 -46
  55. package/src/Uuid7.ts +79 -80
  56. package/src/_sha.ts +11 -0
  57. package/src/_uuid-stringify.ts +30 -0
  58. package/src/index.ts +10 -9
  59. package/tsconfig.json +5 -25
  60. package/vitest.config.ts +8 -0
  61. package/.nvmrc +0 -1
  62. package/biome.json +0 -36
  63. package/dist/Cuid.js.map +0 -1
  64. package/dist/DateTimes.js.map +0 -1
  65. package/dist/GetRandomValues.d.ts +0 -11
  66. package/dist/GetRandomValues.js +0 -17
  67. package/dist/GetRandomValues.js.map +0 -1
  68. package/dist/Ksuid.js.map +0 -1
  69. package/dist/NanoId.js.map +0 -1
  70. package/dist/Ulid.js.map +0 -1
  71. package/dist/Uuid4.js.map +0 -1
  72. package/dist/Uuid5.js.map +0 -1
  73. package/dist/Uuid7.js.map +0 -1
  74. package/dist/UuidStringify.js +0 -29
  75. package/dist/UuidStringify.js.map +0 -1
  76. package/dist/index.js.map +0 -1
  77. package/readme.md +0 -169
  78. package/src/GetRandomValues.ts +0 -29
  79. package/src/UuidStringify.ts +0 -31
  80. package/src/id.test.ts +0 -133
package/dist/Ids.d.ts ADDED
@@ -0,0 +1,71 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Layer from "effect/Layer";
3
+ import * as ServiceMap from "effect/ServiceMap";
4
+ import type { Cuid } from "./Cuid.js";
5
+ import { CuidState } from "./Cuid.js";
6
+ import { DateTimes } from "./DateTimes.js";
7
+ import type { Ksuid } from "./Ksuid.js";
8
+ import type { NanoId } from "./NanoId.js";
9
+ import { RandomValues } from "./RandomValues.js";
10
+ import type { Ulid } from "./Ulid.js";
11
+ import type { Uuid4 } from "./Uuid4.js";
12
+ import { type Uuid5, Uuid5Namespace } from "./Uuid5.js";
13
+ import type { Uuid7 } from "./Uuid7.js";
14
+ import { Uuid7State } from "./Uuid7.js";
15
+ declare const Ids_base: ServiceMap.ServiceClass<Ids, "@typed/id/Ids", {
16
+ cuid: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/CUID">, never, never>;
17
+ ksuid: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/KSUID">, never, never>;
18
+ nanoId: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/NanoId">, never, never>;
19
+ ulid: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/ULID">, never, never>;
20
+ uuid4: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/UUID4">, never, never>;
21
+ uuid5: {
22
+ (namespace: Uuid5Namespace): (name: string) => Effect.Effect<Uuid5>;
23
+ (name: string, namespace: Uuid5Namespace): Effect.Effect<Uuid5>;
24
+ readonly dns: (name: string) => Effect.Effect<Uuid5>;
25
+ readonly url: (name: string) => Effect.Effect<Uuid5>;
26
+ readonly oid: (name: string) => Effect.Effect<Uuid5>;
27
+ readonly x500: (name: string) => Effect.Effect<Uuid5>;
28
+ };
29
+ uuid7: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/UUID7">, never, never>;
30
+ }> & {
31
+ readonly make: Effect.Effect<{
32
+ cuid: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/CUID">, never, never>;
33
+ ksuid: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/KSUID">, never, never>;
34
+ nanoId: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/NanoId">, never, never>;
35
+ ulid: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/ULID">, never, never>;
36
+ uuid4: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/UUID4">, never, never>;
37
+ uuid5: {
38
+ (namespace: Uuid5Namespace): (name: string) => Effect.Effect<Uuid5>;
39
+ (name: string, namespace: Uuid5Namespace): Effect.Effect<Uuid5>;
40
+ readonly dns: (name: string) => Effect.Effect<Uuid5>;
41
+ readonly url: (name: string) => Effect.Effect<Uuid5>;
42
+ readonly oid: (name: string) => Effect.Effect<Uuid5>;
43
+ readonly x500: (name: string) => Effect.Effect<Uuid5>;
44
+ };
45
+ uuid7: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/UUID7">, never, never>;
46
+ }, never, CuidState | DateTimes | RandomValues | Uuid7State>;
47
+ };
48
+ export declare class Ids extends Ids_base {
49
+ static readonly cuid: Effect.Effect<Cuid, never, Ids>;
50
+ static readonly ksuid: Effect.Effect<Ksuid, never, Ids>;
51
+ static readonly nanoId: Effect.Effect<NanoId, never, Ids>;
52
+ static readonly ulid: Effect.Effect<Ulid, never, Ids>;
53
+ static readonly uuid4: Effect.Effect<Uuid4, never, Ids>;
54
+ static readonly uuid5: {
55
+ (namespace: Uuid5Namespace): (name: string) => Effect.Effect<Uuid5, never, Ids>;
56
+ (name: string, namespace: Uuid5Namespace): Effect.Effect<Uuid5, never, Ids>;
57
+ readonly dns: (name: string) => Effect.Effect<Uuid5, never, Ids>;
58
+ readonly url: (name: string) => Effect.Effect<Uuid5, never, Ids>;
59
+ readonly oid: (name: string) => Effect.Effect<Uuid5, never, Ids>;
60
+ readonly x500: (name: string) => Effect.Effect<Uuid5, never, Ids>;
61
+ };
62
+ static readonly uuid7: Effect.Effect<Uuid7, never, Ids>;
63
+ static readonly Default: Layer.Layer<Ids | DateTimes | RandomValues, never, never>;
64
+ static readonly Test: (options?: TestOptions) => Layer.Layer<Ids | DateTimes | RandomValues>;
65
+ }
66
+ export type TestOptions = {
67
+ readonly currentTime?: number | string | Date;
68
+ readonly envData?: string;
69
+ };
70
+ export {};
71
+ //# sourceMappingURL=Ids.d.ts.map
@@ -0,0 +1 @@
1
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,0 +1,51 @@
1
+ import * as Effect from "effect/Effect";
2
+ import { dual } from "effect/Function";
3
+ import * as Layer from "effect/Layer";
4
+ import * as ServiceMap from "effect/ServiceMap";
5
+ import { cuid, CuidState } from "./Cuid.js";
6
+ import { DateTimes } from "./DateTimes.js";
7
+ import { ksuid } from "./Ksuid.js";
8
+ import { nanoId } from "./NanoId.js";
9
+ import { RandomValues } from "./RandomValues.js";
10
+ import { ulid } from "./Ulid.js";
11
+ import { uuid4 } from "./Uuid4.js";
12
+ import { uuid5, Uuid5Namespace } from "./Uuid5.js";
13
+ import { uuid7, Uuid7State } from "./Uuid7.js";
14
+ export class Ids extends ServiceMap.Service()("@typed/id/Ids", {
15
+ make: Effect.gen(function* () {
16
+ const services = yield* Effect.services();
17
+ const uuid5_ = Object.assign(dual(2, (name, namespace) => Effect.provide(uuid5(name, namespace), services)), {
18
+ dns: uuid5(Uuid5Namespace.DNS),
19
+ url: uuid5(Uuid5Namespace.URL),
20
+ oid: uuid5(Uuid5Namespace.OID),
21
+ x500: uuid5(Uuid5Namespace.X500),
22
+ });
23
+ return {
24
+ cuid: Effect.provide(cuid, services),
25
+ ksuid: Effect.provide(ksuid, services),
26
+ nanoId: Effect.provide(nanoId, services),
27
+ ulid: Effect.provide(ulid, services),
28
+ uuid4: Effect.provide(uuid4, services),
29
+ uuid5: uuid5_,
30
+ uuid7: Effect.provide(uuid7, services),
31
+ };
32
+ }),
33
+ }) {
34
+ static cuid = Effect.flatMap(Ids.asEffect(), ({ cuid }) => cuid);
35
+ static ksuid = Effect.flatMap(Ids.asEffect(), ({ ksuid }) => ksuid);
36
+ static nanoId = Effect.flatMap(Ids.asEffect(), ({ nanoId }) => nanoId);
37
+ static ulid = Effect.flatMap(Ids.asEffect(), ({ ulid }) => ulid);
38
+ static uuid4 = Effect.flatMap(Ids.asEffect(), ({ uuid4 }) => uuid4);
39
+ static uuid5 = Object.assign(dual(2, (name, namespace) => Effect.flatMap(Ids.asEffect(), ({ uuid5 }) => uuid5(name, namespace))), {
40
+ dns: (name) => Effect.flatMap(Ids.asEffect(), ({ uuid5 }) => uuid5.dns(name)),
41
+ url: (name) => Effect.flatMap(Ids.asEffect(), ({ uuid5 }) => uuid5.url(name)),
42
+ oid: (name) => Effect.flatMap(Ids.asEffect(), ({ uuid5 }) => uuid5.oid(name)),
43
+ x500: (name) => Effect.flatMap(Ids.asEffect(), ({ uuid5 }) => uuid5.x500(name)),
44
+ });
45
+ static uuid7 = Effect.flatMap(Ids.asEffect(), ({ uuid7 }) => uuid7);
46
+ static Default = Layer.effect(Ids, Ids.make).pipe(Layer.provide([CuidState.Default, Uuid7State.Default]), Layer.provideMerge([DateTimes.Default, RandomValues.Default]));
47
+ static Test = (options) => Layer.effect(Ids, Ids.make).pipe(Layer.provide([
48
+ Layer.effect(CuidState, CuidState.make(options?.envData ?? "node")),
49
+ Uuid7State.Default,
50
+ ]), Layer.provideMerge([DateTimes.Fixed(options?.currentTime ?? 0), RandomValues.Random]));
51
+ }
package/dist/Ksuid.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import * as Effect from 'effect/Effect';
2
- import * as Schema from 'effect/Schema';
3
- import { DateTimes } from './DateTimes.js';
4
- import { GetRandomValues } from './GetRandomValues.js';
5
- export declare const Ksuid: Schema.brand<Schema.filter<typeof Schema.String>, "@typed/id/KSUID">;
6
- export type Ksuid = Schema.Schema.Type<typeof Ksuid>;
1
+ import * as Effect from "effect/Effect";
2
+ import * as Schema from "effect/Schema";
3
+ import { DateTimes } from "./DateTimes.js";
4
+ import { RandomValues } from "./RandomValues.js";
5
+ export declare const Ksuid: Schema.brand<Schema.String, "@typed/id/KSUID">;
6
+ export type Ksuid = typeof Ksuid.Type;
7
7
  export declare const isKsuid: (value: string) => value is Ksuid;
8
- export declare const makeKsuid: Effect.Effect<Ksuid, never, DateTimes | GetRandomValues>;
8
+ export declare const ksuid: Effect.Effect<Ksuid, never, DateTimes | RandomValues>;
9
+ //# sourceMappingURL=Ksuid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Ksuid.d.ts","sourceRoot":"","sources":["../src/Ksuid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAUjD,eAAO,MAAM,KAAK,gDAGjB,CAAC;AACF,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC,IAAI,CAAC;AAEtC,eAAO,MAAM,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,IAAI,KAAwB,CAAC;AAM3E,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,GAAG,YAAY,CAyBvE,CAAC"}
package/dist/Ksuid.js CHANGED
@@ -1,7 +1,7 @@
1
- import * as Effect from 'effect/Effect';
2
- import * as Schema from 'effect/Schema';
3
- import { DateTimes } from './DateTimes.js';
4
- import { GetRandomValues } from './GetRandomValues.js';
1
+ import * as Effect from "effect/Effect";
2
+ import * as Schema from "effect/Schema";
3
+ import { DateTimes } from "./DateTimes.js";
4
+ import { RandomValues } from "./RandomValues.js";
5
5
  // Constants
6
6
  const EPOCH = 14e11; // 2014-03-01T00:00:00Z
7
7
  const TIMESTAMP_BYTES = 4;
@@ -9,28 +9,10 @@ const PAYLOAD_BYTES = 16;
9
9
  const TOTAL_BYTES = TIMESTAMP_BYTES + PAYLOAD_BYTES;
10
10
  const STRING_LENGTH = 27;
11
11
  // Schema
12
- export const Ksuid = Schema.String.pipe(Schema.pattern(/^[0-9a-zA-Z]{27}$/), Schema.brand('@typed/id/KSUID'));
12
+ export const Ksuid = Schema.String.pipe(Schema.check(Schema.isPattern(/^[0-9a-zA-Z]{27}$/)), Schema.brand("@typed/id/KSUID"));
13
13
  export const isKsuid = Schema.is(Ksuid);
14
- // Utilities
15
- const base62Chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
16
- const base = BigInt(base62Chars.length);
17
- function base62Encode(bytes) {
18
- let number = 0n;
19
- for (const byte of bytes) {
20
- number = (number << 8n) + BigInt(byte);
21
- }
22
- const chars = new Array(STRING_LENGTH);
23
- let i = chars.length;
24
- while (i > 0) {
25
- i--;
26
- const remainder = Number(number % base);
27
- chars[i] = base62Chars[remainder];
28
- number = number / base;
29
- }
30
- return chars.join('');
31
- }
32
- // Core Functions
33
- function ksuidFromSeed({ timestamp, payload }) {
14
+ // Public API
15
+ export const ksuid = Effect.zipWith(DateTimes.now, RandomValues.call(PAYLOAD_BYTES), (timestamp, payload) => {
34
16
  // Create the combined bytes
35
17
  const bytes = new Uint8Array(TOTAL_BYTES);
36
18
  // Support for timestamps before the epoch, usually for testing
@@ -46,12 +28,23 @@ function ksuidFromSeed({ timestamp, payload }) {
46
28
  // Copy payload
47
29
  bytes.set(payload, TIMESTAMP_BYTES);
48
30
  // Encode as base62
49
- return Ksuid.make(base62Encode(bytes));
50
- }
51
- // Public API
52
- export const makeKsuid = Effect.gen(function* () {
53
- const timestamp = yield* DateTimes.now;
54
- const payload = yield* GetRandomValues.apply(PAYLOAD_BYTES);
55
- return ksuidFromSeed({ timestamp, payload });
31
+ return Ksuid.makeUnsafe(base62Encode(bytes));
56
32
  });
57
- //# sourceMappingURL=Ksuid.js.map
33
+ // Utilities
34
+ const base62Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
35
+ const base = BigInt(base62Chars.length);
36
+ function base62Encode(bytes) {
37
+ let number = 0n;
38
+ for (const byte of bytes) {
39
+ number = (number << 8n) + BigInt(byte);
40
+ }
41
+ const chars = Array(STRING_LENGTH);
42
+ let i = chars.length;
43
+ while (i > 0) {
44
+ i--;
45
+ const remainder = Number(number % base);
46
+ chars[i] = base62Chars[remainder];
47
+ number = number / base;
48
+ }
49
+ return chars.join("");
50
+ }
package/dist/NanoId.d.ts CHANGED
@@ -1,32 +1,8 @@
1
- import * as Effect from 'effect/Effect';
2
- import * as Schema from 'effect/Schema';
3
- import { GetRandomValues } from './GetRandomValues.js';
4
- export declare const isNanoId: (id: string) => id is NanoId;
5
- export declare const NanoId: Schema.brand<typeof Schema.String, "@typed/id/NanoId">;
6
- export type NanoId = Schema.Schema.Type<typeof NanoId>;
7
- export type NanoIdSeed = readonly [
8
- zero: number,
9
- one: number,
10
- two: number,
11
- three: number,
12
- four: number,
13
- five: number,
14
- six: number,
15
- seven: number,
16
- eight: number,
17
- nine: number,
18
- ten: number,
19
- eleven: number,
20
- twelve: number,
21
- thirteen: number,
22
- fourteen: number,
23
- fifteen: number,
24
- sixteen: number,
25
- seventeen: number,
26
- eighteen: number,
27
- nineteen: number,
28
- twenty: number
29
- ];
30
- export declare const nanoId: (seed: NanoIdSeed) => NanoId;
31
- export declare const makeNanoIdSeed: Effect.Effect<NanoIdSeed, never, GetRandomValues>;
32
- export declare const makeNanoId: Effect.Effect<NanoId, never, GetRandomValues>;
1
+ import * as Effect from "effect/Effect";
2
+ import * as Schema from "effect/Schema";
3
+ import { RandomValues } from "./RandomValues.js";
4
+ export declare const NanoId: Schema.brand<Schema.String, "@typed/id/NanoId">;
5
+ export type NanoId = typeof NanoId.Type;
6
+ export declare const isNanoId: (value: string) => value is NanoId;
7
+ export declare const nanoId: Effect.Effect<NanoId, never, RandomValues>;
8
+ //# sourceMappingURL=NanoId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NanoId.d.ts","sourceRoot":"","sources":["../src/NanoId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,eAAO,MAAM,MAAM,iDAGlB,CAAC;AACF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC,IAAI,CAAC;AAExC,eAAO,MAAM,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,IAAI,MAA0B,CAAC;AAI9E,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,YAAY,CAG7D,CAAC"}
package/dist/NanoId.js CHANGED
@@ -1,10 +1,10 @@
1
- import * as Effect from 'effect/Effect';
2
- import * as Schema from 'effect/Schema';
3
- import { GetRandomValues } from './GetRandomValues.js';
4
- const nanoIdPattern = /[0-9a-zA-Z_-]/;
5
- export const isNanoId = (id) => nanoIdPattern.test(id);
6
- export const NanoId = Schema.String.pipe(Schema.brand('@typed/id/NanoId'));
7
- const numToCharacter = (byte) => {
1
+ import * as Effect from "effect/Effect";
2
+ import * as Schema from "effect/Schema";
3
+ import { RandomValues } from "./RandomValues.js";
4
+ export const NanoId = Schema.String.pipe(Schema.check(Schema.isPattern(/^[0-9a-zA-Z_-]+$/)), Schema.brand("@typed/id/NanoId"));
5
+ export const isNanoId = Schema.is(NanoId);
6
+ export const nanoId = Effect.map(RandomValues.call(21), (seed) => NanoId.makeUnsafe(Array.from(seed, numToCharacter).join("")));
7
+ function numToCharacter(byte) {
8
8
  byte &= 63;
9
9
  if (byte < 36) {
10
10
  // `0-9a-z`
@@ -15,13 +15,9 @@ const numToCharacter = (byte) => {
15
15
  return (byte - 26).toString(36).toUpperCase();
16
16
  }
17
17
  else if (byte > 62) {
18
- return '-';
18
+ return "-";
19
19
  }
20
20
  else {
21
- return '_';
21
+ return "_";
22
22
  }
23
- };
24
- export const nanoId = (seed) => NanoId.make(seed.reduce((id, x) => id + numToCharacter(x), ''));
25
- export const makeNanoIdSeed = GetRandomValues.apply(21);
26
- export const makeNanoId = Effect.map(makeNanoIdSeed, nanoId);
27
- //# sourceMappingURL=NanoId.js.map
23
+ }
@@ -0,0 +1,13 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Layer from "effect/Layer";
3
+ import * as ServiceMap from "effect/ServiceMap";
4
+ declare const RandomValues_base: ServiceMap.ServiceClass<RandomValues, "@typed/id/RandomValues", <A extends Uint8Array>(length: A["length"]) => Effect.Effect<A>> & {
5
+ readonly make: Effect.Effect<(<A extends Uint8Array>(length: A["length"]) => Effect.Effect<A>), never, never>;
6
+ };
7
+ export declare class RandomValues extends RandomValues_base {
8
+ static readonly call: <A extends Uint8Array>(length: A["length"]) => Effect.Effect<A, never, RandomValues>;
9
+ static readonly Default: Layer.Layer<RandomValues, never, never>;
10
+ static readonly Random: Layer.Layer<RandomValues, never, never>;
11
+ }
12
+ export {};
13
+ //# sourceMappingURL=RandomValues.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RandomValues.d.ts","sourceRoot":"","sources":["../src/RandomValues.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;kGAI3C,CAAC,SAAS,UAAU,UAAU,CAAC,CAAC,QAAQ,CAAC,KAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;mCAA5D,CAAC,SAAS,UAAU,UAAU,CAAC,CAAC,QAAQ,CAAC,KAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;;AAFjE,qBAAa,YAAa,SAAQ,iBAKhC;IACA,gBAAyB,IAAI,GAAI,CAAC,SAAS,UAAU,EACnD,QAAQ,CAAC,CAAC,QAAQ,CAAC,KAClB,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAC+C;IAEvF,MAAM,CAAC,QAAQ,CAAC,OAAO,0CAAiD;IAExE,MAAM,CAAC,QAAQ,CAAC,MAAM,0CAapB;CACH"}
@@ -0,0 +1,19 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Layer from "effect/Layer";
3
+ import * as Random from "effect/Random";
4
+ import * as ServiceMap from "effect/ServiceMap";
5
+ export class RandomValues extends ServiceMap.Service()("@typed/id/RandomValues", {
6
+ make: Effect.succeed((length) => Effect.sync(() => crypto.getRandomValues(new Uint8Array(length)))),
7
+ }) {
8
+ static call = (length) => RandomValues.asEffect().pipe(Effect.flatMap((randomValues) => randomValues(length)));
9
+ static Default = Layer.effect(RandomValues, RandomValues.make);
10
+ static Random = Layer.effect(RandomValues, Effect.gen(function* () {
11
+ const random = yield* Random.Random;
12
+ return RandomValues.of((length) => Effect.sync(() => {
13
+ const view = new Uint8Array(length);
14
+ for (let i = 0; i < length; ++i)
15
+ view[i] = random.nextIntUnsafe();
16
+ return view;
17
+ }));
18
+ }));
19
+ }
package/dist/Ulid.d.ts CHANGED
@@ -1,31 +1,9 @@
1
- import * as Effect from 'effect/Effect';
2
- import { GetRandomValues } from './GetRandomValues.js';
3
- import { Schema } from 'effect';
4
- import { DateTimes } from './DateTimes.js';
1
+ import * as Effect from "effect/Effect";
2
+ import * as Schema from "effect/Schema";
3
+ import { DateTimes } from "./DateTimes.js";
4
+ import { RandomValues } from "./RandomValues.js";
5
+ export declare const Ulid: Schema.brand<Schema.String, "@typed/id/ULID">;
6
+ export type Ulid = typeof Ulid.Type;
5
7
  export declare const isUlid: (value: string) => value is Ulid;
6
- export declare const Ulid: Schema.brand<typeof Schema.ULID, "@typed/id/ULID">;
7
- export type Ulid = Schema.Schema.Type<typeof Ulid>;
8
- export type UlidSeed = {
9
- readonly seed: readonly [
10
- zero: number,
11
- one: number,
12
- two: number,
13
- three: number,
14
- four: number,
15
- five: number,
16
- six: number,
17
- seven: number,
18
- eight: number,
19
- nine: number,
20
- ten: number,
21
- eleven: number,
22
- twelve: number,
23
- thirteen: number,
24
- fourteen: number,
25
- fifteen: number
26
- ];
27
- readonly now: number;
28
- };
29
- export declare const makeUlidSeed: Effect.Effect<UlidSeed, never, GetRandomValues | DateTimes>;
30
- export declare const makeUlid: Effect.Effect<Ulid, never, GetRandomValues | DateTimes>;
31
- export declare function ulid(seed: UlidSeed['seed'], now: UlidSeed['now']): Ulid;
8
+ export declare const ulid: Effect.Effect<Ulid, never, RandomValues | DateTimes>;
9
+ //# sourceMappingURL=Ulid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Ulid.d.ts","sourceRoot":"","sources":["../src/Ulid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,eAAO,MAAM,IAAI,+CAGhB,CAAC;AACF,MAAM,MAAM,IAAI,GAAG,OAAO,IAAI,CAAC,IAAI,CAAC;AAEpC,eAAO,MAAM,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,IAAI,IAAsB,CAAC;AAWxE,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,YAAY,GAAG,SAAS,CAUrE,CAAC"}
package/dist/Ulid.js CHANGED
@@ -1,19 +1,23 @@
1
- import * as Effect from 'effect/Effect';
2
- import { GetRandomValues } from './GetRandomValues.js';
3
- import { Schema } from 'effect';
4
- import { DateTimes } from './DateTimes.js';
5
- export const isUlid = Schema.is(Schema.ULID);
6
- export const Ulid = Schema.ULID.pipe(Schema.brand('@typed/id/ULID'));
1
+ import * as Effect from "effect/Effect";
2
+ import * as Schema from "effect/Schema";
3
+ import { DateTimes } from "./DateTimes.js";
4
+ import { RandomValues } from "./RandomValues.js";
5
+ export const Ulid = Schema.String.pipe(Schema.check(Schema.isULID()), Schema.brand("@typed/id/ULID"));
6
+ export const isUlid = Schema.is(Ulid);
7
7
  // Crockford's Base32
8
- const ENCODING = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
8
+ const ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
9
9
  const ENCODING_LEN = ENCODING.length;
10
10
  const TIME_MAX = 2 ** 48 - 1;
11
11
  const TIME_LEN = 10;
12
12
  const RANDOM_LEN = 16;
13
- export const makeUlidSeed = DateTimes.now.pipe(Effect.bindTo('now'), Effect.bind('seed', () => GetRandomValues.apply(16)));
14
- export const makeUlid = Effect.map(makeUlidSeed, ({ seed, now }) => ulid(seed, now));
13
+ export const ulid = Effect.zipWith(DateTimes.now, RandomValues.call(16), (now, seed) => {
14
+ if (now > TIME_MAX) {
15
+ throw new Error("Cannot generate ULID due to timestamp overflow");
16
+ }
17
+ return Ulid.makeUnsafe(encodeTime(now, TIME_LEN) + encodeRandom(seed));
18
+ });
15
19
  function encodeTime(now, len) {
16
- let str = '';
20
+ let str = "";
17
21
  for (let i = len - 1; i >= 0; i--) {
18
22
  const mod = now % ENCODING_LEN;
19
23
  str = ENCODING.charAt(mod) + str;
@@ -22,18 +26,9 @@ function encodeTime(now, len) {
22
26
  return str;
23
27
  }
24
28
  function encodeRandom(seed) {
25
- let str = '';
29
+ let str = "";
26
30
  for (let i = 0; i < RANDOM_LEN; i++) {
27
31
  str = str + ENCODING.charAt(seed[i] % ENCODING_LEN);
28
32
  }
29
33
  return str;
30
34
  }
31
- export function ulid(seed, now) {
32
- if (now > TIME_MAX) {
33
- throw new Error('Cannot generate ULID due to timestamp overflow');
34
- }
35
- const time = encodeTime(now, TIME_LEN);
36
- const random = encodeRandom(seed);
37
- return Ulid.make(time + random);
38
- }
39
- //# sourceMappingURL=Ulid.js.map
package/dist/Uuid4.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import * as Effect from 'effect/Effect';
2
- import * as Schema from 'effect/Schema';
3
- import { GetRandomValues } from './GetRandomValues.js';
4
- export declare const Uuid4: Schema.brand<typeof Schema.UUID, "@typed/id/UUID4">;
5
- export type Uuid4 = Schema.Schema.Type<typeof Uuid4>;
1
+ import * as Effect from "effect/Effect";
2
+ import * as Schema from "effect/Schema";
3
+ import { RandomValues } from "./RandomValues.js";
4
+ export declare const Uuid4: Schema.brand<Schema.String, "@typed/id/UUID4">;
5
+ export type Uuid4 = typeof Uuid4.Type;
6
6
  export declare const isUuid4: (value: string) => value is Uuid4;
7
- export declare const makeUuid4: Effect.Effect<Uuid4, never, GetRandomValues>;
7
+ export declare const uuid4: Effect.Effect<Uuid4, never, RandomValues>;
8
+ //# sourceMappingURL=Uuid4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Uuid4.d.ts","sourceRoot":"","sources":["../src/Uuid4.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,eAAO,MAAM,KAAK,gDAGjB,CAAC;AACF,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC,IAAI,CAAC;AAEtC,eAAO,MAAM,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,IAAI,KAAwB,CAAC;AAI3E,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,YAAY,CAQ3D,CAAC"}
package/dist/Uuid4.js CHANGED
@@ -1,14 +1,12 @@
1
- import * as Effect from 'effect/Effect';
2
- import * as Schema from 'effect/Schema';
3
- import { GetRandomValues } from './GetRandomValues.js';
4
- import { uuidStringify } from './UuidStringify.js';
5
- export const Uuid4 = Schema.UUID.pipe(Schema.brand('@typed/id/UUID4'));
1
+ import * as Effect from "effect/Effect";
2
+ import * as Schema from "effect/Schema";
3
+ import { uuidStringify } from "./_uuid-stringify.js";
4
+ import { RandomValues } from "./RandomValues.js";
5
+ export const Uuid4 = Schema.String.pipe(Schema.check(Schema.isUUID(4)), Schema.brand("@typed/id/UUID4"));
6
6
  export const isUuid4 = Schema.is(Uuid4);
7
- export const makeUuid4 = Effect.map(GetRandomValues.apply(16), uuid4FromSeed);
8
- function uuid4FromSeed(seed) {
7
+ export const uuid4 = Effect.map(RandomValues.call(16), (seed) => {
9
8
  // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
10
9
  seed[6] = (seed[6] & 0x0f) | 0x40;
11
10
  seed[8] = (seed[8] & 0x3f) | 0x80;
12
- return Uuid4.make(uuidStringify(seed));
13
- }
14
- //# sourceMappingURL=Uuid4.js.map
11
+ return Uuid4.makeUnsafe(uuidStringify(seed));
12
+ });
package/dist/Uuid5.d.ts CHANGED
@@ -1,21 +1,8 @@
1
- import * as Effect from 'effect/Effect';
2
- import * as Layer from 'effect/Layer';
3
- import * as Schema from 'effect/Schema';
4
- export declare const Uuid5: Schema.brand<typeof Schema.UUID, "@typed/id/UUID5">;
5
- export type Uuid5 = Schema.Schema.Type<typeof Uuid5>;
1
+ import * as Effect from "effect/Effect";
2
+ import * as Schema from "effect/Schema";
3
+ export declare const Uuid5: Schema.brand<Schema.String, "@typed/id/UUID5">;
4
+ export type Uuid5 = typeof Uuid5.Type;
6
5
  export declare const isUuid5: (value: string) => value is Uuid5;
7
- declare const Sha1_base: import("effect/Context").TagClass<Sha1, "Sha1", {
8
- readonly hash: (data: Uint8Array) => Effect.Effect<Uint8Array, never>;
9
- }> & Effect.Tag.Proxy<Sha1, {
10
- readonly hash: (data: Uint8Array) => Effect.Effect<Uint8Array, never>;
11
- }> & {
12
- use: <X>(body: (_: {
13
- readonly hash: (data: Uint8Array) => Effect.Effect<Uint8Array, never>;
14
- }) => X) => [X] extends [Effect.Effect<infer A, infer E, infer R>] ? Effect.Effect<A, E, R | Sha1> : [X] extends [PromiseLike<infer A_1>] ? Effect.Effect<A_1, import("effect/Cause").UnknownException, Sha1> : Effect.Effect<X, never, Sha1>;
15
- };
16
- export declare class Sha1 extends Sha1_base {
17
- static readonly Default: Layer.Layer<Sha1, never, never>;
18
- }
19
6
  export type Uuid5Namespace = Uint8Array;
20
7
  export declare const Uuid5Namespace: {
21
8
  readonly DNS: Uint8Array<ArrayBuffer>;
@@ -23,5 +10,12 @@ export declare const Uuid5Namespace: {
23
10
  readonly OID: Uint8Array<ArrayBuffer>;
24
11
  readonly X500: Uint8Array<ArrayBuffer>;
25
12
  };
26
- export declare function makeUuid5(namespace: Uuid5Namespace, name: string): Effect.Effect<Uuid5, never, Sha1>;
27
- export {};
13
+ export declare const uuid5: {
14
+ (namespace: Uuid5Namespace): (name: string) => Effect.Effect<Uuid5>;
15
+ (name: string, namespace: Uuid5Namespace): Effect.Effect<Uuid5>;
16
+ };
17
+ export declare const dnsUuid5: (name: string) => Effect.Effect<Uuid5>;
18
+ export declare const urlUuid5: (name: string) => Effect.Effect<Uuid5>;
19
+ export declare const oidUuid5: (name: string) => Effect.Effect<Uuid5>;
20
+ export declare const x500Uuid5: (name: string) => Effect.Effect<Uuid5>;
21
+ //# sourceMappingURL=Uuid5.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Uuid5.d.ts","sourceRoot":"","sources":["../src/Uuid5.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAIxC,eAAO,MAAM,KAAK,gDAGjB,CAAC;AACF,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC,IAAI,CAAC;AAEtC,eAAO,MAAM,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,IAAI,KAAwB,CAAC;AAE3E,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC;AAKxC,eAAO,MAAM,cAAc;;;;;CAgBjB,CAAC;AAEX,eAAO,MAAM,KAAK,EAAE;IAClB,CAAC,SAAS,EAAE,cAAc,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpE,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;CA0BhE,CAAC;AAEH,eAAO,MAAM,QAAQ,SA7BiB,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,CA6BnB,CAAC;AAClD,eAAO,MAAM,QAAQ,SA9BiB,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,CA8BnB,CAAC;AAClD,eAAO,MAAM,QAAQ,SA/BiB,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,CA+BnB,CAAC;AAClD,eAAO,MAAM,SAAS,SAhCgB,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,CAgCjB,CAAC"}
package/dist/Uuid5.js CHANGED
@@ -1,14 +1,10 @@
1
- import * as Effect from 'effect/Effect';
2
- import * as Layer from 'effect/Layer';
3
- import * as Schema from 'effect/Schema';
4
- import { uuidStringify } from './UuidStringify.js';
5
- export const Uuid5 = Schema.UUID.pipe(Schema.brand('@typed/id/UUID5'));
1
+ import * as Effect from "effect/Effect";
2
+ import { dual } from "effect/Function";
3
+ import * as Schema from "effect/Schema";
4
+ import { sha1 } from "./_sha.js";
5
+ import { uuidStringify } from "./_uuid-stringify.js";
6
+ export const Uuid5 = Schema.String.pipe(Schema.check(Schema.isUUID(5)), Schema.brand("@typed/id/UUID5"));
6
7
  export const isUuid5 = Schema.is(Uuid5);
7
- export class Sha1 extends Effect.Tag('Sha1')() {
8
- static Default = Layer.succeed(this, {
9
- hash: (data) => Effect.promise(() => crypto.subtle.digest('SHA-1', data).then((hash) => new Uint8Array(hash))),
10
- });
11
- }
12
8
  const textEncoder = new TextEncoder();
13
9
  // Pre-defined namespaces from RFC 4122
14
10
  export const Uuid5Namespace = {
@@ -25,9 +21,8 @@ export const Uuid5Namespace = {
25
21
  0x6b, 0xa7, 0xb8, 0x14, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8,
26
22
  ]),
27
23
  };
28
- export function makeUuid5(namespace, name) {
24
+ export const uuid5 = dual(2, function uuid5(name, namespace) {
29
25
  return Effect.gen(function* () {
30
- const sha1 = yield* Sha1;
31
26
  // Convert name to UTF-8 bytes
32
27
  const nameBytes = textEncoder.encode(name);
33
28
  // Concatenate namespace and name
@@ -35,7 +30,7 @@ export function makeUuid5(namespace, name) {
35
30
  buffer.set(namespace);
36
31
  buffer.set(nameBytes, namespace.length);
37
32
  // Hash the concatenated bytes
38
- const hash = yield* sha1.hash(buffer);
33
+ const hash = yield* sha1(buffer);
39
34
  // Format as UUID v5
40
35
  const result = new Uint8Array(16);
41
36
  // Copy first 16 bytes of the hash
@@ -43,7 +38,10 @@ export function makeUuid5(namespace, name) {
43
38
  // Set version (5) and variant bits
44
39
  result[6] = (result[6] & 0x0f) | 0x50; // version 5
45
40
  result[8] = (result[8] & 0x3f) | 0x80; // variant 1
46
- return Uuid5.make(uuidStringify(result));
41
+ return Uuid5.makeUnsafe(uuidStringify(result));
47
42
  });
48
- }
49
- //# sourceMappingURL=Uuid5.js.map
43
+ });
44
+ export const dnsUuid5 = uuid5(Uuid5Namespace.DNS);
45
+ export const urlUuid5 = uuid5(Uuid5Namespace.URL);
46
+ export const oidUuid5 = uuid5(Uuid5Namespace.OID);
47
+ export const x500Uuid5 = uuid5(Uuid5Namespace.X500);