@typed/id 0.10.0 → 0.12.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 (65) hide show
  1. package/.nvmrc +1 -0
  2. package/biome.json +36 -0
  3. package/dist/DateTimes.d.ts +25 -0
  4. package/dist/DateTimes.js +20 -0
  5. package/dist/DateTimes.js.map +1 -0
  6. package/dist/GetRandomValues.d.ts +11 -0
  7. package/dist/GetRandomValues.js +17 -0
  8. package/dist/GetRandomValues.js.map +1 -0
  9. package/dist/{dts/NanoId.d.ts → NanoId.d.ts} +5 -30
  10. package/dist/NanoId.js +27 -0
  11. package/dist/NanoId.js.map +1 -0
  12. package/dist/Ulid.d.ts +31 -0
  13. package/dist/Ulid.js +39 -0
  14. package/dist/Ulid.js.map +1 -0
  15. package/dist/{dts/Uuid.d.ts → Uuid.d.ts} +5 -31
  16. package/dist/{esm/Uuid.js → Uuid.js} +13 -31
  17. package/dist/Uuid.js.map +1 -0
  18. package/dist/index.d.ts +5 -0
  19. package/dist/index.js +6 -0
  20. package/dist/index.js.map +1 -0
  21. package/package.json +34 -57
  22. package/readme.md +86 -0
  23. package/src/DateTimes.ts +37 -0
  24. package/src/GetRandomValues.ts +28 -77
  25. package/src/NanoId.ts +16 -40
  26. package/src/Ulid.ts +82 -0
  27. package/src/Uuid.ts +34 -57
  28. package/src/id.test.ts +50 -0
  29. package/src/index.ts +5 -16
  30. package/tsconfig.json +26 -0
  31. package/GetRandomValues/package.json +0 -6
  32. package/LICENSE +0 -21
  33. package/NanoId/package.json +0 -6
  34. package/README.md +0 -5
  35. package/Schema/package.json +0 -6
  36. package/Uuid/package.json +0 -6
  37. package/dist/cjs/GetRandomValues.js +0 -65
  38. package/dist/cjs/GetRandomValues.js.map +0 -1
  39. package/dist/cjs/NanoId.js +0 -53
  40. package/dist/cjs/NanoId.js.map +0 -1
  41. package/dist/cjs/Schema.js +0 -31
  42. package/dist/cjs/Schema.js.map +0 -1
  43. package/dist/cjs/Uuid.js +0 -55
  44. package/dist/cjs/Uuid.js.map +0 -1
  45. package/dist/cjs/index.js +0 -39
  46. package/dist/cjs/index.js.map +0 -1
  47. package/dist/dts/GetRandomValues.d.ts +0 -38
  48. package/dist/dts/GetRandomValues.d.ts.map +0 -1
  49. package/dist/dts/NanoId.d.ts.map +0 -1
  50. package/dist/dts/Schema.d.ts +0 -15
  51. package/dist/dts/Schema.d.ts.map +0 -1
  52. package/dist/dts/Uuid.d.ts.map +0 -1
  53. package/dist/dts/index.d.ts +0 -16
  54. package/dist/dts/index.d.ts.map +0 -1
  55. package/dist/esm/GetRandomValues.js +0 -57
  56. package/dist/esm/GetRandomValues.js.map +0 -1
  57. package/dist/esm/NanoId.js +0 -45
  58. package/dist/esm/NanoId.js.map +0 -1
  59. package/dist/esm/Schema.js +0 -16
  60. package/dist/esm/Schema.js.map +0 -1
  61. package/dist/esm/Uuid.js.map +0 -1
  62. package/dist/esm/index.js +0 -16
  63. package/dist/esm/index.js.map +0 -1
  64. package/dist/esm/package.json +0 -4
  65. package/src/Schema.ts +0 -29
@@ -1,78 +1,29 @@
1
- /**
2
- * @since 1.0.0
3
- */
4
-
5
- import * as Context from "@typed/context"
6
- import * as Effect from "effect/Effect"
7
- import type * as Layer from "effect/Layer"
8
- import * as Random from "effect/Random"
9
-
10
- /**
11
- * @since 1.0.0
12
- */
13
- export const GetRandomValues = Context.Fn<(length: number) => Effect.Effect<Uint8Array>>()(
14
- (_) => (class GetRandomValues extends _("@typed/id/GetRandomValues") {})
15
- )
16
- /**
17
- * @since 1.0.0
18
- */
19
- export interface GetRandomValues extends Context.Fn.Identifier<typeof GetRandomValues> {}
20
-
21
- const getRandomValuesWeb = (crypto: Crypto, length: number) => crypto.getRandomValues(new Uint8Array(length))
22
-
23
- /**
24
- * @since 1.0.0
25
- */
26
- export const webCrypto = (crypto: Crypto): Layer.Layer<GetRandomValues> =>
27
- GetRandomValues.implement((length) => Effect.sync(() => getRandomValuesWeb(crypto, length)))
28
-
29
- /**
30
- * @since 1.0.0
31
- */
32
- // eslint-disable-next-line @typescript-eslint/consistent-type-imports
33
- export const getRandomValuesNode = (crypto: typeof import("node:crypto"), length: number) => {
34
- const bytes = crypto.randomBytes(length)
35
- const view = new Uint8Array(length)
36
- for (let i = 0; i < bytes.length; ++i) {
37
- view[i] = bytes[i]
38
- }
39
- return view
1
+ import * as Context from 'effect/Context'
2
+ import * as Effect from 'effect/Effect'
3
+ import * as Layer from 'effect/Layer'
4
+ import * as Random from 'effect/Random'
5
+
6
+ export class GetRandomValues extends Context.Tag('GetRandomValues')<
7
+ GetRandomValues,
8
+ (length: number) => Effect.Effect<Uint8Array>
9
+ >() {
10
+ static readonly layer = (f: (length: number) => Effect.Effect<Uint8Array>) =>
11
+ Layer.succeed(GetRandomValues, f)
12
+
13
+ static readonly apply = (length: number) => Effect.flatMap(GetRandomValues, (f) => f(length))
14
+
15
+ static readonly PseudoRandom = this.layer((length) =>
16
+ Effect.gen(function* () {
17
+ const view = new Uint8Array(length)
18
+ for (let i = 0; i < length; ++i) {
19
+ view[i] = yield* Random.nextInt
20
+ }
21
+
22
+ return view
23
+ }),
24
+ )
25
+
26
+ static readonly CryptoRandom = this.layer((length) =>
27
+ Effect.sync(() => crypto.getRandomValues(new Uint8Array(length))),
28
+ )
40
29
  }
41
-
42
- /**
43
- * @since 1.0.0
44
- */
45
- // eslint-disable-next-line @typescript-eslint/consistent-type-imports
46
- export const nodeCrypto = (crypto: typeof import("node:crypto")): Layer.Layer<GetRandomValues> =>
47
- GetRandomValues.implement((length) => Effect.sync(() => getRandomValuesNode(crypto, length)))
48
-
49
- /**
50
- * @since 1.0.0
51
- */
52
- export const pseudoRandom: Layer.Layer<GetRandomValues> = GetRandomValues.implement((length) =>
53
- Effect.gen(function*() {
54
- const view = new Uint8Array(length)
55
-
56
- for (let i = 0; i < length; ++i) {
57
- view[i] = yield* Random.nextInt
58
- }
59
-
60
- return view
61
- })
62
- )
63
-
64
- /**
65
- * @since 1.0.0
66
- */
67
- export const getRandomValues: Layer.Layer<GetRandomValues> = GetRandomValues.layer(
68
- Effect.gen(function*() {
69
- if (typeof crypto === "undefined") {
70
- // eslint-disable-next-line @typescript-eslint/consistent-type-imports
71
- const crypto: typeof import("node:crypto") = yield* Effect.promise(() => import("node:crypto"))
72
-
73
- return (length: number) => Effect.sync(() => getRandomValuesNode(crypto, length))
74
- } else {
75
- return (length: number) => Effect.sync(() => getRandomValuesWeb(crypto, length))
76
- }
77
- })
78
- )
package/src/NanoId.ts CHANGED
@@ -1,34 +1,14 @@
1
- /**
2
- * @since 1.0.0
3
- */
4
-
5
- import * as Brand from "effect/Brand"
6
- import * as Effect from "effect/Effect"
7
- import { GetRandomValues } from "./GetRandomValues.js"
1
+ import { Schema } from 'effect'
2
+ import * as Effect from 'effect/Effect'
3
+ import { GetRandomValues } from './GetRandomValues.js'
8
4
 
9
5
  const nanoIdPattern = /[0-9a-zA-Z_-]/
10
6
 
11
- /**
12
- * @since 1.0.0
13
- */
14
7
  export const isNanoId = (id: string): id is NanoId => nanoIdPattern.test(id)
15
8
 
16
- /**
17
- * @since 1.0.0
18
- */
19
- export type NanoId = string & Brand.Brand<"@typed/id/NanoId">
20
-
21
- /**
22
- * @since 1.0.0
23
- */
24
- export const NanoId = Brand.refined<NanoId>(
25
- isNanoId,
26
- (input) => Brand.error(`Expected a NanoID but received ${input}.`)
27
- )
9
+ export const NanoId = Schema.String.pipe(Schema.brand('@typed/id/NanoId'))
10
+ export type NanoId = Schema.Schema.Type<typeof NanoId>
28
11
 
29
- /**
30
- * @since 1.0.0
31
- */
32
12
  export type NanoIdSeed = readonly [
33
13
  zero: number,
34
14
  one: number,
@@ -50,7 +30,7 @@ export type NanoIdSeed = readonly [
50
30
  seventeen: number,
51
31
  eighteen: number,
52
32
  nineteen: number,
53
- twenty: number
33
+ twenty: number,
54
34
  ]
55
35
 
56
36
  const numToCharacter = (byte: number): string => {
@@ -62,23 +42,19 @@ const numToCharacter = (byte: number): string => {
62
42
  // `A-Z`
63
43
  return (byte - 26).toString(36).toUpperCase()
64
44
  } else if (byte > 62) {
65
- return "-"
45
+ return '-'
66
46
  } else {
67
- return "_"
47
+ return '_'
68
48
  }
69
49
  }
70
50
 
71
- /**
72
- * @since 1.0.0
73
- */
74
- export const nanoId = (seed: NanoIdSeed): NanoId => NanoId(seed.reduce((id, x) => id + numToCharacter(x), ""))
51
+ export const nanoId = (seed: NanoIdSeed): NanoId =>
52
+ NanoId.make(seed.reduce((id, x) => id + numToCharacter(x), ''))
75
53
 
76
- /**
77
- * @since 1.0.0
78
- */
79
- export const makeNanoIdSeed: Effect.Effect<NanoIdSeed, never, GetRandomValues> = GetRandomValues(21) as any
54
+ export const makeNanoIdSeed: Effect.Effect<NanoIdSeed, never, GetRandomValues> =
55
+ GetRandomValues.apply(21) as any
80
56
 
81
- /**
82
- * @since 1.0.0
83
- */
84
- export const makeNanoId: Effect.Effect<NanoId, never, GetRandomValues> = Effect.map(makeNanoIdSeed, nanoId)
57
+ export const makeNanoId: Effect.Effect<NanoId, never, GetRandomValues> = Effect.map(
58
+ makeNanoIdSeed,
59
+ nanoId,
60
+ )
package/src/Ulid.ts ADDED
@@ -0,0 +1,82 @@
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
+
6
+ export const isUlid: (value: string) => value is Ulid = Schema.is(Schema.ULID) as any
7
+
8
+ export const Ulid = Schema.ULID.pipe(Schema.brand('@typed/id/ULID'))
9
+ export type Ulid = Schema.Schema.Type<typeof Ulid>
10
+
11
+ export type UlidSeed = {
12
+ readonly seed: readonly [
13
+ zero: number,
14
+ one: number,
15
+ two: number,
16
+ three: number,
17
+ four: number,
18
+ five: number,
19
+ six: number,
20
+ seven: number,
21
+ eight: number,
22
+ nine: number,
23
+ ten: number,
24
+ eleven: number,
25
+ twelve: number,
26
+ thirteen: number,
27
+ fourteen: number,
28
+ fifteen: number,
29
+ ]
30
+ readonly now: number
31
+ }
32
+
33
+ // Crockford's Base32
34
+ const ENCODING = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'
35
+ const ENCODING_LEN = ENCODING.length
36
+ const TIME_MAX = 2 ** 48 - 1
37
+ const TIME_LEN = 10
38
+ const RANDOM_LEN = 16
39
+
40
+ export const makeUlidSeed: Effect.Effect<UlidSeed, never, GetRandomValues | DateTimes> =
41
+ DateTimes.now.pipe(
42
+ Effect.bindTo('now'),
43
+ Effect.bind(
44
+ 'seed',
45
+ () =>
46
+ GetRandomValues.apply(16) as any as Effect.Effect<UlidSeed['seed'], never, GetRandomValues>,
47
+ ),
48
+ )
49
+
50
+ export const makeUlid: Effect.Effect<Ulid, never, GetRandomValues | DateTimes> = Effect.map(
51
+ makeUlidSeed,
52
+ ({ seed, now }) => ulid(seed, now),
53
+ )
54
+
55
+ function encodeTime(now: number, len: number): string {
56
+ let str = ''
57
+ for (let i = len - 1; i >= 0; i--) {
58
+ const mod = now % ENCODING_LEN
59
+ str = ENCODING.charAt(mod) + str
60
+ now = (now - mod) / ENCODING_LEN
61
+ }
62
+ return str
63
+ }
64
+
65
+ function encodeRandom(seed: UlidSeed['seed']): string {
66
+ let str = ''
67
+ for (let i = 0; i < RANDOM_LEN; i++) {
68
+ str = str + ENCODING.charAt(seed[i] % ENCODING_LEN)
69
+ }
70
+ return str
71
+ }
72
+
73
+ export function ulid(seed: UlidSeed['seed'], now: UlidSeed['now']): Ulid {
74
+ if (now > TIME_MAX) {
75
+ throw new Error('Cannot generate ULID due to timestamp overflow')
76
+ }
77
+
78
+ const time = encodeTime(now, TIME_LEN)
79
+ const random = encodeRandom(seed)
80
+
81
+ return Ulid.make(time + random)
82
+ }
package/src/Uuid.ts CHANGED
@@ -1,31 +1,12 @@
1
- /**
2
- * @since 1.0.0
3
- */
4
-
5
- import * as Brand from "effect/Brand"
6
- import * as Effect from "effect/Effect"
7
- import { GetRandomValues } from "./GetRandomValues.js"
1
+ import * as Effect from 'effect/Effect'
2
+ import { GetRandomValues } from './GetRandomValues.js'
3
+ import { Schema } from 'effect'
8
4
 
9
- const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
5
+ export const isUuid: (value: string) => value is Uuid = Schema.is(Schema.UUID) as any
10
6
 
11
- /**
12
- * Returns `true` if a string is a UUID.
13
- * @since 1.0.0
14
- */
15
- export const isUuid: (value: string) => value is Uuid = (value: string): value is Uuid => uuidPattern.test(value)
16
-
17
- /**
18
- * @since 1.0.0
19
- */
20
- export type Uuid = string & Brand.Brand<"@typed/id/UUID">
21
- /**
22
- * @since 1.0.0
23
- */
24
- export const Uuid = Brand.refined<Uuid>(isUuid, (input) => Brand.error(`Expected a UUID but received ${input}.`))
7
+ export const Uuid = Schema.UUID.pipe(Schema.brand('@typed/id/UUID'))
8
+ export type Uuid = Schema.Schema.Type<typeof Uuid>
25
9
 
26
- /**
27
- * @since 1.0.0
28
- */
29
10
  export type UuidSeed = readonly [
30
11
  zero: number,
31
12
  one: number,
@@ -42,17 +23,13 @@ export type UuidSeed = readonly [
42
23
  twelve: number,
43
24
  thirteen: number,
44
25
  fourteen: number,
45
- fifteen: number
26
+ fifteen: number,
46
27
  ]
47
28
 
48
- /**
49
- * @since 1.0.0
50
- */
51
- export const makeUuidSeed: Effect.Effect<UuidSeed, never, GetRandomValues> = GetRandomValues(32) as any
29
+ export const makeUuidSeed: Effect.Effect<UuidSeed, never, GetRandomValues> = GetRandomValues.apply(
30
+ 32,
31
+ ) as any
52
32
 
53
- /**
54
- * @since 1.0.0
55
- */
56
33
  export const makeUuid: Effect.Effect<Uuid, never, GetRandomValues> = Effect.map(makeUuidSeed, uuid4)
57
34
 
58
35
  /**
@@ -65,9 +42,6 @@ for (let i = 0; i < 256; ++i) {
65
42
  byteToHex.push((i + 0x100).toString(16).slice(1))
66
43
  }
67
44
 
68
- /**
69
- * @since 1.0.0
70
- */
71
45
  export function uuid4(seed: UuidSeed): Uuid {
72
46
  // Note: Be careful editing this code! It's been tuned for performance
73
47
  // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
@@ -75,25 +49,28 @@ export function uuid4(seed: UuidSeed): Uuid {
75
49
  // Note to future-self: No, you can't remove the `toLowerCase()` call.
76
50
  // REF: https://github.com/uuidjs/uuid/pull/677#issuecomment-1757351351
77
51
  return (
78
- byteToHex[seed[0]] +
79
- byteToHex[seed[1]] +
80
- byteToHex[seed[2]] +
81
- byteToHex[seed[3]] +
82
- "-" +
83
- byteToHex[seed[4]] +
84
- byteToHex[seed[5]] +
85
- "-" +
86
- byteToHex[seed[6]] +
87
- byteToHex[seed[7]] +
88
- "-" +
89
- byteToHex[seed[8]] +
90
- byteToHex[seed[9]] +
91
- "-" +
92
- byteToHex[seed[10]] +
93
- byteToHex[seed[11]] +
94
- byteToHex[seed[12]] +
95
- byteToHex[seed[13]] +
96
- byteToHex[seed[14]] +
97
- byteToHex[seed[15]]
98
- ).toLowerCase() as Uuid
52
+ (
53
+ // biome-ignore lint/style/useTemplate: <explanation>
54
+ byteToHex[seed[0]] +
55
+ byteToHex[seed[1]] +
56
+ byteToHex[seed[2]] +
57
+ byteToHex[seed[3]] +
58
+ '-' +
59
+ byteToHex[seed[4]] +
60
+ byteToHex[seed[5]] +
61
+ '-' +
62
+ byteToHex[seed[6]] +
63
+ byteToHex[seed[7]] +
64
+ '-' +
65
+ byteToHex[seed[8]] +
66
+ byteToHex[seed[9]] +
67
+ '-' +
68
+ byteToHex[seed[10]] +
69
+ byteToHex[seed[11]] +
70
+ byteToHex[seed[12]] +
71
+ byteToHex[seed[13]] +
72
+ byteToHex[seed[14]] +
73
+ byteToHex[seed[15]]
74
+ ).toLowerCase() as Uuid
75
+ )
99
76
  }
package/src/id.test.ts ADDED
@@ -0,0 +1,50 @@
1
+ import { describe, expect, it } from '@effect/vitest'
2
+ import { Effect } from 'effect'
3
+ import { DateTimes, GetRandomValues, isUuid, makeNanoId, makeUlid, makeUuid } from './index.js'
4
+
5
+ const makeTestValues = (length: number) => {
6
+ const values = new Uint8Array(length)
7
+ for (let i = 0; i < length; ++i) {
8
+ values[i] = i
9
+ }
10
+ return values
11
+ }
12
+
13
+ const provideTestValues = Effect.provide([
14
+ GetRandomValues.layer((length) => Effect.succeed(makeTestValues(length))),
15
+ DateTimes.Fixed(new Date(0)),
16
+ ])
17
+
18
+ describe(__filename, () => {
19
+ describe('Uuid', () => {
20
+ it.effect('generates a UUID', () =>
21
+ Effect.gen(function* (_) {
22
+ const id = yield* _(makeUuid)
23
+ expect(id).toEqual('00010203-0405-0607-0809-0a0b0c0d0e0f')
24
+ expect(id.length).toEqual(36)
25
+ expect(isUuid(id)).toEqual(true)
26
+ }).pipe(provideTestValues),
27
+ )
28
+ })
29
+
30
+ describe('NanoId', () => {
31
+ it.effect('generates a NanoId', () =>
32
+ Effect.gen(function* (_) {
33
+ const id = yield* _(makeNanoId)
34
+
35
+ expect(id).toEqual('0123456789abcdefghijk')
36
+ expect(id.length).toEqual(21)
37
+ }).pipe(provideTestValues),
38
+ )
39
+ })
40
+
41
+ describe('Ulid', () => {
42
+ it.effect('generates a Ulid', () =>
43
+ Effect.gen(function* (_) {
44
+ const id = yield* _(makeUlid)
45
+ expect(id).toMatchInlineSnapshot(`"00000000000123456789ABCDEF"`)
46
+ expect(id.length).toEqual(26)
47
+ }).pipe(provideTestValues),
48
+ )
49
+ })
50
+ })
package/src/index.ts CHANGED
@@ -1,16 +1,5 @@
1
- /**
2
- * @since 1.18.0
3
- */
4
-
5
- /**
6
- * @since 1.18.0
7
- */
8
- export * from "./GetRandomValues.js"
9
- /**
10
- * @since 1.18.0
11
- */
12
- export * from "./NanoId.js"
13
- /**
14
- * @since 1.18.0
15
- */
16
- export * from "./Uuid.js"
1
+ export * from './DateTimes.js'
2
+ export * from './GetRandomValues.js'
3
+ export * from './NanoId.js'
4
+ export * from './Ulid.js'
5
+ export * from './Uuid.js'
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": [
7
+ "ES2022"
8
+ ],
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "declaration": true,
14
+ "sourceMap": true,
15
+ "outDir": "dist",
16
+ "rootDir": "src"
17
+ },
18
+ "include": [
19
+ "src/**/*"
20
+ ],
21
+ "exclude": [
22
+ "node_modules",
23
+ "dist",
24
+ "**/*.test.ts"
25
+ ]
26
+ }
@@ -1,6 +0,0 @@
1
- {
2
- "main": "../dist/cjs/GetRandomValues.js",
3
- "module": "../dist/esm/GetRandomValues.js",
4
- "types": "../dist/dts/GetRandomValues.d.ts",
5
- "sideEffects": []
6
- }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
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.
@@ -1,6 +0,0 @@
1
- {
2
- "main": "../dist/cjs/NanoId.js",
3
- "module": "../dist/esm/NanoId.js",
4
- "types": "../dist/dts/NanoId.d.ts",
5
- "sideEffects": []
6
- }
package/README.md DELETED
@@ -1,5 +0,0 @@
1
- # @typed/id
2
-
3
- > WIP
4
-
5
- Docs: https://tylors.github.io/typed/docs/id
@@ -1,6 +0,0 @@
1
- {
2
- "main": "../dist/cjs/Schema.js",
3
- "module": "../dist/esm/Schema.js",
4
- "types": "../dist/dts/Schema.d.ts",
5
- "sideEffects": []
6
- }
package/Uuid/package.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "main": "../dist/cjs/Uuid.js",
3
- "module": "../dist/esm/Uuid.js",
4
- "types": "../dist/dts/Uuid.d.ts",
5
- "sideEffects": []
6
- }
@@ -1,65 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.webCrypto = exports.pseudoRandom = exports.nodeCrypto = exports.getRandomValuesNode = exports.getRandomValues = exports.GetRandomValues = void 0;
7
- var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@typed/context"));
8
- var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));
9
- var Random = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Random"));
10
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /**
12
- * @since 1.0.0
13
- */
14
- /**
15
- * @since 1.0.0
16
- */
17
- const GetRandomValues = exports.GetRandomValues = /*#__PURE__*/Context.Fn()(_ => class GetRandomValues extends _("@typed/id/GetRandomValues") {});
18
- const getRandomValuesWeb = (crypto, length) => crypto.getRandomValues(new Uint8Array(length));
19
- /**
20
- * @since 1.0.0
21
- */
22
- const webCrypto = crypto => GetRandomValues.implement(length => Effect.sync(() => getRandomValuesWeb(crypto, length)));
23
- /**
24
- * @since 1.0.0
25
- */
26
- // eslint-disable-next-line @typescript-eslint/consistent-type-imports
27
- exports.webCrypto = webCrypto;
28
- const getRandomValuesNode = (crypto, length) => {
29
- const bytes = crypto.randomBytes(length);
30
- const view = new Uint8Array(length);
31
- for (let i = 0; i < bytes.length; ++i) {
32
- view[i] = bytes[i];
33
- }
34
- return view;
35
- };
36
- /**
37
- * @since 1.0.0
38
- */
39
- // eslint-disable-next-line @typescript-eslint/consistent-type-imports
40
- exports.getRandomValuesNode = getRandomValuesNode;
41
- const nodeCrypto = crypto => GetRandomValues.implement(length => Effect.sync(() => getRandomValuesNode(crypto, length)));
42
- /**
43
- * @since 1.0.0
44
- */
45
- exports.nodeCrypto = nodeCrypto;
46
- const pseudoRandom = exports.pseudoRandom = /*#__PURE__*/GetRandomValues.implement(length => Effect.gen(function* () {
47
- const view = new Uint8Array(length);
48
- for (let i = 0; i < length; ++i) {
49
- view[i] = yield* Random.nextInt;
50
- }
51
- return view;
52
- }));
53
- /**
54
- * @since 1.0.0
55
- */
56
- const getRandomValues = exports.getRandomValues = /*#__PURE__*/GetRandomValues.layer( /*#__PURE__*/Effect.gen(function* () {
57
- if (typeof crypto === "undefined") {
58
- // eslint-disable-next-line @typescript-eslint/consistent-type-imports
59
- const crypto = yield* Effect.promise(() => Promise.resolve().then(() => _interopRequireWildcard(require("node:crypto"))));
60
- return length => Effect.sync(() => getRandomValuesNode(crypto, length));
61
- } else {
62
- return length => Effect.sync(() => getRandomValuesWeb(crypto, length));
63
- }
64
- }));
65
- //# sourceMappingURL=GetRandomValues.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"GetRandomValues.js","names":["Context","_interopRequireWildcard","require","Effect","Random","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","GetRandomValues","exports","Fn","_","getRandomValuesWeb","crypto","length","getRandomValues","Uint8Array","webCrypto","implement","sync","getRandomValuesNode","bytes","randomBytes","view","nodeCrypto","pseudoRandom","gen","nextInt","layer","promise","Promise","resolve","then"],"sources":["../../src/GetRandomValues.ts"],"sourcesContent":[null],"mappings":";;;;;;AAIA,IAAAA,OAAA,gBAAAC,uBAAA,eAAAC,OAAA;AACA,IAAAC,MAAA,gBAAAF,uBAAA,eAAAC,OAAA;AAEA,IAAAE,MAAA,gBAAAH,uBAAA,eAAAC,OAAA;AAAuC,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBA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