@typed/id 1.0.0-beta.2 → 1.0.0-beta.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/dist/Cuid.d.ts +2 -2
- package/dist/Cuid.d.ts.map +1 -1
- package/dist/Cuid.js +3 -3
- package/dist/DateTimes.d.ts +2 -2
- package/dist/DateTimes.d.ts.map +1 -1
- package/dist/DateTimes.js +2 -2
- package/dist/Ids.d.ts +2 -2
- package/dist/Ids.d.ts.map +1 -1
- package/dist/Ids.js +3 -3
- package/dist/Ksuid.js +1 -1
- package/dist/NanoId.js +1 -1
- package/dist/RandomValues.d.ts +2 -2
- package/dist/RandomValues.d.ts.map +1 -1
- package/dist/RandomValues.js +2 -2
- package/dist/Ulid.js +1 -1
- package/dist/Uuid4.js +1 -1
- package/dist/Uuid5.js +1 -1
- package/dist/Uuid7.d.ts +2 -2
- package/dist/Uuid7.d.ts.map +1 -1
- package/dist/Uuid7.js +3 -3
- package/package.json +13 -13
- package/src/Cuid.ts +3 -3
- package/src/DateTimes.ts +2 -2
- package/src/Id.test.ts +0 -1
- package/src/Ids.ts +3 -3
- package/src/Ksuid.ts +1 -1
- package/src/NanoId.ts +1 -1
- package/src/RandomValues.ts +2 -2
- package/src/Ulid.ts +1 -1
- package/src/Uuid4.ts +1 -1
- package/src/Uuid5.ts +1 -1
- package/src/Uuid7.ts +3 -3
package/dist/Cuid.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as Layer from "effect/Layer";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
|
-
import * as
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
5
|
import { DateTimes } from "./DateTimes.js";
|
|
6
6
|
import { RandomValues } from "./RandomValues.js";
|
|
7
7
|
export declare const Cuid: Schema.brand<Schema.String, "@typed/id/CUID">;
|
|
@@ -13,7 +13,7 @@ export type CuidSeed = {
|
|
|
13
13
|
readonly random: Uint8Array;
|
|
14
14
|
readonly fingerprint: string;
|
|
15
15
|
};
|
|
16
|
-
declare const CuidState_base:
|
|
16
|
+
declare const CuidState_base: Context.ServiceClass<CuidState, "@typed/id/CuidState", Effect.Effect<{
|
|
17
17
|
timestamp: number;
|
|
18
18
|
counter: number;
|
|
19
19
|
random: Uint8Array<ArrayBufferLike>;
|
package/dist/Cuid.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cuid.d.ts","sourceRoot":"","sources":["../src/Cuid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Cuid.d.ts","sourceRoot":"","sources":["../src/Cuid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAQjD,eAAO,MAAM,IAAI,+CAGhB,CAAC;AACF,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnD,eAAO,MAAM,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,IAAI,IAAsB,CAAC;AAGxE,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B,CAAC;;;;;;;6BAGgB,MAAM;;;;;;;AADxB,qBAAa,SAAU,SAAQ,cA8B7B;IACA,MAAM,CAAC,QAAQ,CAAC,IAAI;;;;;yBAAwC;IAE5D,MAAM,CAAC,QAAQ,CAAC,OAAO,kEAErB;CACH;AAED,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAGtD,CAAC"}
|
package/dist/Cuid.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as Layer from "effect/Layer";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
|
-
import * as
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
5
|
import { sha512 } from "./_sha.js";
|
|
6
6
|
import { DateTimes } from "./DateTimes.js";
|
|
7
7
|
import { RandomValues } from "./RandomValues.js";
|
|
@@ -12,7 +12,7 @@ const INITIAL_COUNT_MAX = 476782367;
|
|
|
12
12
|
// Schema
|
|
13
13
|
export const Cuid = Schema.String.pipe(Schema.check(Schema.isPattern(/^[a-z][0-9a-z]+$/)), Schema.brand("@typed/id/CUID"));
|
|
14
14
|
export const isCuid = Schema.is(Cuid);
|
|
15
|
-
export class CuidState extends
|
|
15
|
+
export class CuidState extends Context.Service()("@typed/id/CuidState", {
|
|
16
16
|
make: (envData) => Effect.gen(function* () {
|
|
17
17
|
const { now } = yield* DateTimes;
|
|
18
18
|
const getRandomValues = yield* RandomValues;
|
|
@@ -78,6 +78,6 @@ function cuidFromSeed({ counter, fingerprint, random, timestamp }) {
|
|
|
78
78
|
const hashed = yield* hash(hashInput);
|
|
79
79
|
// Construct the final CUID
|
|
80
80
|
const id = `${firstLetter}${hashed.substring(0, DEFAULT_LENGTH - 1)}`;
|
|
81
|
-
return Cuid.
|
|
81
|
+
return Cuid.make(id);
|
|
82
82
|
});
|
|
83
83
|
}
|
package/dist/DateTimes.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as Layer from "effect/Layer";
|
|
3
|
-
import * as
|
|
4
|
-
declare const DateTimes_base:
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
declare const DateTimes_base: Context.ServiceClass<DateTimes, "@typed/id/DateTimes", {
|
|
5
5
|
now: Effect.Effect<number, never, never>;
|
|
6
6
|
date: Effect.Effect<Date, never, never>;
|
|
7
7
|
}> & {
|
package/dist/DateTimes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTimes.d.ts","sourceRoot":"","sources":["../src/DateTimes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"DateTimes.d.ts","sourceRoot":"","sources":["../src/DateTimes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;;;;;;;;;;AAE1C,qBAAa,SAAU,SAAQ,cAK7B;IACA,MAAM,CAAC,QAAQ,CAAC,GAAG,0CAA0D;IAC7E,MAAM,CAAC,QAAQ,CAAC,IAAI,wCAA4D;IAEhF,MAAM,CAAC,QAAQ,CAAC,OAAO,uCAA2C;IAElE,MAAM,CAAC,QAAQ,CAAC,KAAK,GAAI,UAAU,MAAM,GAAG,MAAM,GAAG,IAAI,0CAkBrD;CACL"}
|
package/dist/DateTimes.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as Clock from "effect/Clock";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import * as Layer from "effect/Layer";
|
|
4
|
-
import * as
|
|
5
|
-
export class DateTimes extends
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
|
+
export class DateTimes extends Context.Service()("@typed/id/DateTimes", {
|
|
6
6
|
make: Effect.succeed({
|
|
7
7
|
now: Effect.sync(() => Date.now()),
|
|
8
8
|
date: Effect.sync(() => new Date()),
|
package/dist/Ids.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as Layer from "effect/Layer";
|
|
3
|
-
import * as
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
4
|
import type { Cuid } from "./Cuid.js";
|
|
5
5
|
import { CuidState } from "./Cuid.js";
|
|
6
6
|
import { DateTimes } from "./DateTimes.js";
|
|
@@ -13,7 +13,7 @@ import { type Uuid5, Uuid5Namespace } from "./Uuid5.js";
|
|
|
13
13
|
import type { Uuid7 } from "./Uuid7.js";
|
|
14
14
|
import { Uuid7State } from "./Uuid7.js";
|
|
15
15
|
import { TestClock } from "effect/testing";
|
|
16
|
-
declare const Ids_base:
|
|
16
|
+
declare const Ids_base: Context.ServiceClass<Ids, "@typed/id/Ids", {
|
|
17
17
|
cuid: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/CUID">, never, never>;
|
|
18
18
|
ksuid: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/KSUID">, never, never>;
|
|
19
19
|
nanoId: Effect.Effect<string & import("effect/Brand").Brand<"@typed/id/NanoId">, never, never>;
|
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,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Ids.d.ts","sourceRoot":"","sources":["../src/Ids.ts"],"names":[],"mappings":"AAAA,OAAO,KA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-1,7 +1,7 @@
|
|
|
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
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
5
|
import { cuid, CuidState } from "./Cuid.js";
|
|
6
6
|
import { DateTimes } from "./DateTimes.js";
|
|
7
7
|
import { ksuid } from "./Ksuid.js";
|
|
@@ -12,9 +12,9 @@ import { uuid4 } from "./Uuid4.js";
|
|
|
12
12
|
import { uuid5, Uuid5Namespace } from "./Uuid5.js";
|
|
13
13
|
import { uuid7, Uuid7State } from "./Uuid7.js";
|
|
14
14
|
import { TestClock } from "effect/testing";
|
|
15
|
-
export class Ids extends
|
|
15
|
+
export class Ids extends Context.Service()("@typed/id/Ids", {
|
|
16
16
|
make: Effect.gen(function* () {
|
|
17
|
-
const services = yield* Effect.
|
|
17
|
+
const services = yield* Effect.context();
|
|
18
18
|
const uuid5_ = Object.assign(dual(2, (name, namespace) => Effect.provide(uuid5(name, namespace), services)), {
|
|
19
19
|
dns: uuid5(Uuid5Namespace.DNS),
|
|
20
20
|
url: uuid5(Uuid5Namespace.URL),
|
package/dist/Ksuid.js
CHANGED
|
@@ -28,7 +28,7 @@ export const ksuid = Effect.zipWith(DateTimes.now, RandomValues.call(PAYLOAD_BYT
|
|
|
28
28
|
// Copy payload
|
|
29
29
|
bytes.set(payload, TIMESTAMP_BYTES);
|
|
30
30
|
// Encode as base62
|
|
31
|
-
return Ksuid.
|
|
31
|
+
return Ksuid.make(base62Encode(bytes));
|
|
32
32
|
});
|
|
33
33
|
// Utilities
|
|
34
34
|
const base62Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
package/dist/NanoId.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as Schema from "effect/Schema";
|
|
|
3
3
|
import { RandomValues } from "./RandomValues.js";
|
|
4
4
|
export const NanoId = Schema.String.pipe(Schema.check(Schema.isPattern(/^[0-9a-zA-Z_-]+$/)), Schema.brand("@typed/id/NanoId"));
|
|
5
5
|
export const isNanoId = Schema.is(NanoId);
|
|
6
|
-
export const nanoId = Effect.map(RandomValues.call(21), (seed) => NanoId.
|
|
6
|
+
export const nanoId = Effect.map(RandomValues.call(21), (seed) => NanoId.make(Array.from(seed, numToCharacter).join("")));
|
|
7
7
|
function numToCharacter(byte) {
|
|
8
8
|
byte &= 63;
|
|
9
9
|
if (byte < 36) {
|
package/dist/RandomValues.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as Layer from "effect/Layer";
|
|
3
|
-
import * as
|
|
4
|
-
declare const RandomValues_base:
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
declare const RandomValues_base: Context.ServiceClass<RandomValues, "@typed/id/RandomValues", <A extends Uint8Array>(length: A["length"]) => Effect.Effect<A>> & {
|
|
5
5
|
readonly make: Effect.Effect<(<A extends Uint8Array>(length: A["length"]) => Effect.Effect<A>), never, never>;
|
|
6
6
|
};
|
|
7
7
|
export declare class RandomValues extends RandomValues_base {
|
|
@@ -1 +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,
|
|
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,OAAO,MAAM,gBAAgB,CAAC;+FAIrC,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"}
|
package/dist/RandomValues.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as Layer from "effect/Layer";
|
|
3
3
|
import * as Random from "effect/Random";
|
|
4
|
-
import * as
|
|
5
|
-
export class RandomValues extends
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
|
+
export class RandomValues extends Context.Service()("@typed/id/RandomValues", {
|
|
6
6
|
make: Effect.succeed((length) => Effect.sync(() => crypto.getRandomValues(new Uint8Array(length)))),
|
|
7
7
|
}) {
|
|
8
8
|
static call = (length) => RandomValues.asEffect().pipe(Effect.flatMap((randomValues) => randomValues(length)));
|
package/dist/Ulid.js
CHANGED
|
@@ -14,7 +14,7 @@ export const ulid = Effect.zipWith(DateTimes.now, RandomValues.call(16), (now, s
|
|
|
14
14
|
if (now > TIME_MAX) {
|
|
15
15
|
throw new Error("Cannot generate ULID due to timestamp overflow");
|
|
16
16
|
}
|
|
17
|
-
return Ulid.
|
|
17
|
+
return Ulid.make(encodeTime(now, TIME_LEN) + encodeRandom(seed));
|
|
18
18
|
});
|
|
19
19
|
function encodeTime(now, len) {
|
|
20
20
|
let str = "";
|
package/dist/Uuid4.js
CHANGED
|
@@ -8,5 +8,5 @@ export const uuid4 = Effect.map(RandomValues.call(16), (seed) => {
|
|
|
8
8
|
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
9
9
|
seed[6] = (seed[6] & 0x0f) | 0x40;
|
|
10
10
|
seed[8] = (seed[8] & 0x3f) | 0x80;
|
|
11
|
-
return Uuid4.
|
|
11
|
+
return Uuid4.make(uuidStringify(seed));
|
|
12
12
|
});
|
package/dist/Uuid5.js
CHANGED
|
@@ -38,7 +38,7 @@ export const uuid5 = dual(2, function uuid5(name, namespace) {
|
|
|
38
38
|
// Set version (5) and variant bits
|
|
39
39
|
result[6] = (result[6] & 0x0f) | 0x50; // version 5
|
|
40
40
|
result[8] = (result[8] & 0x3f) | 0x80; // variant 1
|
|
41
|
-
return Uuid5.
|
|
41
|
+
return Uuid5.make(uuidStringify(result));
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
44
|
export const dnsUuid5 = uuid5(Uuid5Namespace.DNS);
|
package/dist/Uuid7.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as Layer from "effect/Layer";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
|
-
import * as
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
5
|
import { DateTimes } from "./DateTimes.js";
|
|
6
6
|
import { RandomValues } from "./RandomValues.js";
|
|
7
7
|
export declare const Uuid7: Schema.brand<Schema.String, "@typed/id/UUID7">;
|
|
@@ -14,7 +14,7 @@ export type Uuid7Seed = {
|
|
|
14
14
|
length: 16;
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
|
-
declare const Uuid7State_base:
|
|
17
|
+
declare const Uuid7State_base: Context.ServiceClass<Uuid7State, "@typed/id/Uuid7State", Effect.Effect<{
|
|
18
18
|
timestamp: number;
|
|
19
19
|
seq: number;
|
|
20
20
|
randomBytes: Uint8Array<ArrayBufferLike> & {
|
package/dist/Uuid7.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Uuid7.d.ts","sourceRoot":"","sources":["../src/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uuid7.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as Layer from "effect/Layer";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
|
-
import * as
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
5
|
import { uuidStringify } from "./_uuid-stringify.js";
|
|
6
6
|
import { DateTimes } from "./DateTimes.js";
|
|
7
7
|
import { RandomValues } from "./RandomValues.js";
|
|
8
8
|
export const Uuid7 = Schema.String.pipe(Schema.check(Schema.isUUID(7)), Schema.brand("@typed/id/UUID7"));
|
|
9
9
|
export const isUuid7 = Schema.is(Uuid7);
|
|
10
|
-
export class Uuid7State extends
|
|
10
|
+
export class Uuid7State extends Context.Service()("@typed/id/Uuid7State", {
|
|
11
11
|
make: Effect.gen(function* () {
|
|
12
12
|
const { now } = yield* DateTimes;
|
|
13
13
|
const getRandomValues = yield* RandomValues;
|
|
@@ -69,5 +69,5 @@ function uuid7FromSeed({ randomBytes, seq, timestamp }) {
|
|
|
69
69
|
result[13] = randomBytes[13];
|
|
70
70
|
result[14] = randomBytes[14];
|
|
71
71
|
result[15] = randomBytes[15];
|
|
72
|
-
return Uuid7.
|
|
72
|
+
return Uuid7.make(uuidStringify(result));
|
|
73
73
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typed/id",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.4",
|
|
4
|
+
"files": [
|
|
5
|
+
"dist",
|
|
6
|
+
"src"
|
|
7
|
+
],
|
|
4
8
|
"type": "module",
|
|
5
9
|
"exports": {
|
|
6
10
|
".": {
|
|
@@ -15,19 +19,15 @@
|
|
|
15
19
|
"publishConfig": {
|
|
16
20
|
"access": "public"
|
|
17
21
|
},
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"effect": "4.0.0-beta.21"
|
|
20
|
-
},
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"typescript": "5.9.3",
|
|
23
|
-
"vitest": "4.0.18"
|
|
24
|
-
},
|
|
25
|
-
"files": [
|
|
26
|
-
"dist",
|
|
27
|
-
"src"
|
|
28
|
-
],
|
|
29
22
|
"scripts": {
|
|
30
23
|
"build": "[ -d dist ] || rm -f tsconfig.tsbuildinfo; tsc",
|
|
31
24
|
"test": "vitest run --passWithNoTests"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"effect": "catalog:"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"typescript": "catalog:",
|
|
31
|
+
"vitest": "catalog:"
|
|
32
32
|
}
|
|
33
|
-
}
|
|
33
|
+
}
|
package/src/Cuid.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as Layer from "effect/Layer";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
|
-
import * as
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
5
|
import { sha512 } from "./_sha.js";
|
|
6
6
|
import { DateTimes } from "./DateTimes.js";
|
|
7
7
|
import { RandomValues } from "./RandomValues.js";
|
|
@@ -28,7 +28,7 @@ export type CuidSeed = {
|
|
|
28
28
|
readonly fingerprint: string;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export class CuidState extends
|
|
31
|
+
export class CuidState extends Context.Service<CuidState>()("@typed/id/CuidState", {
|
|
32
32
|
make: (envData: string) =>
|
|
33
33
|
Effect.gen(function* () {
|
|
34
34
|
const { now } = yield* DateTimes;
|
|
@@ -119,6 +119,6 @@ function cuidFromSeed({ counter, fingerprint, random, timestamp }: CuidSeed): Ef
|
|
|
119
119
|
// Construct the final CUID
|
|
120
120
|
const id = `${firstLetter}${hashed.substring(0, DEFAULT_LENGTH - 1)}`;
|
|
121
121
|
|
|
122
|
-
return Cuid.
|
|
122
|
+
return Cuid.make(id);
|
|
123
123
|
});
|
|
124
124
|
}
|
package/src/DateTimes.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as Clock from "effect/Clock";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import * as Layer from "effect/Layer";
|
|
4
|
-
import * as
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
5
|
|
|
6
|
-
export class DateTimes extends
|
|
6
|
+
export class DateTimes extends Context.Service<DateTimes>()("@typed/id/DateTimes", {
|
|
7
7
|
make: Effect.succeed({
|
|
8
8
|
now: Effect.sync(() => Date.now()),
|
|
9
9
|
date: Effect.sync(() => new Date()),
|
package/src/Id.test.ts
CHANGED
|
@@ -10,7 +10,6 @@ import * as Uuid4 from "./Uuid4.js";
|
|
|
10
10
|
import * as Uuid5 from "./Uuid5.js";
|
|
11
11
|
import * as Uuid7 from "./Uuid7.js";
|
|
12
12
|
import { Random } from "effect";
|
|
13
|
-
import { TestClock } from "effect/testing";
|
|
14
13
|
|
|
15
14
|
const run = <A, E>(effect: Effect.Effect<A, E, Ids>) =>
|
|
16
15
|
Effect.runPromise(Effect.provide(effect, Ids.Test()));
|
package/src/Ids.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
5
|
import type { Cuid } from "./Cuid.js";
|
|
6
6
|
import { cuid, CuidState } from "./Cuid.js";
|
|
7
7
|
import { DateTimes } from "./DateTimes.js";
|
|
@@ -19,9 +19,9 @@ import type { Uuid7 } from "./Uuid7.js";
|
|
|
19
19
|
import { uuid7, Uuid7State } from "./Uuid7.js";
|
|
20
20
|
import { TestClock } from "effect/testing";
|
|
21
21
|
|
|
22
|
-
export class Ids extends
|
|
22
|
+
export class Ids extends Context.Service<Ids>()("@typed/id/Ids", {
|
|
23
23
|
make: Effect.gen(function* () {
|
|
24
|
-
const services = yield* Effect.
|
|
24
|
+
const services = yield* Effect.context<DateTimes | RandomValues | CuidState | Uuid7State>();
|
|
25
25
|
|
|
26
26
|
const uuid5_: {
|
|
27
27
|
(namespace: Uuid5Namespace): (name: string) => Effect.Effect<Uuid5>;
|
package/src/Ksuid.ts
CHANGED
package/src/NanoId.ts
CHANGED
|
@@ -14,7 +14,7 @@ type NanoIdSeed = Uint8Array & { length: 21 };
|
|
|
14
14
|
|
|
15
15
|
export const nanoId: Effect.Effect<NanoId, never, RandomValues> = Effect.map(
|
|
16
16
|
RandomValues.call<NanoIdSeed>(21),
|
|
17
|
-
(seed: NanoIdSeed): NanoId => NanoId.
|
|
17
|
+
(seed: NanoIdSeed): NanoId => NanoId.make(Array.from(seed, numToCharacter).join("")),
|
|
18
18
|
);
|
|
19
19
|
|
|
20
20
|
function numToCharacter(byte: number): string {
|
package/src/RandomValues.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as Layer from "effect/Layer";
|
|
3
3
|
import * as Random from "effect/Random";
|
|
4
|
-
import * as
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
5
|
|
|
6
|
-
export class RandomValues extends
|
|
6
|
+
export class RandomValues extends Context.Service<RandomValues>()("@typed/id/RandomValues", {
|
|
7
7
|
make: Effect.succeed(
|
|
8
8
|
<A extends Uint8Array>(length: A["length"]): Effect.Effect<A> =>
|
|
9
9
|
Effect.sync(() => crypto.getRandomValues(new Uint8Array(length)) as A),
|
package/src/Ulid.ts
CHANGED
|
@@ -28,7 +28,7 @@ export const ulid: Effect.Effect<Ulid, never, RandomValues | DateTimes> = Effect
|
|
|
28
28
|
throw new Error("Cannot generate ULID due to timestamp overflow");
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
return Ulid.
|
|
31
|
+
return Ulid.make(encodeTime(now, TIME_LEN) + encodeRandom(seed));
|
|
32
32
|
},
|
|
33
33
|
);
|
|
34
34
|
|
package/src/Uuid4.ts
CHANGED
|
@@ -19,6 +19,6 @@ export const uuid4: Effect.Effect<Uuid4, never, RandomValues> = Effect.map(
|
|
|
19
19
|
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
20
20
|
seed[6] = (seed[6] & 0x0f) | 0x40;
|
|
21
21
|
seed[8] = (seed[8] & 0x3f) | 0x80;
|
|
22
|
-
return Uuid4.
|
|
22
|
+
return Uuid4.make(uuidStringify(seed));
|
|
23
23
|
},
|
|
24
24
|
);
|
package/src/Uuid5.ts
CHANGED
package/src/Uuid7.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as Layer from "effect/Layer";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
|
-
import * as
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
5
|
import { uuidStringify } from "./_uuid-stringify.js";
|
|
6
6
|
import { DateTimes } from "./DateTimes.js";
|
|
7
7
|
import { RandomValues } from "./RandomValues.js";
|
|
@@ -20,7 +20,7 @@ export type Uuid7Seed = {
|
|
|
20
20
|
readonly randomBytes: Uint8Array & { length: 16 };
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
export class Uuid7State extends
|
|
23
|
+
export class Uuid7State extends Context.Service<Uuid7State>()("@typed/id/Uuid7State", {
|
|
24
24
|
make: Effect.gen(function* () {
|
|
25
25
|
const { now } = yield* DateTimes;
|
|
26
26
|
const getRandomValues = yield* RandomValues;
|
|
@@ -100,5 +100,5 @@ function uuid7FromSeed({ randomBytes, seq, timestamp }: Uuid7Seed): Uuid7 {
|
|
|
100
100
|
result[14] = randomBytes[14];
|
|
101
101
|
result[15] = randomBytes[15];
|
|
102
102
|
|
|
103
|
-
return Uuid7.
|
|
103
|
+
return Uuid7.make(uuidStringify(result));
|
|
104
104
|
}
|