Skip to main content

UUID

UUID namespace

Index

Codec

__decode__

  • __decode__(this: void, input: unknown, context: Context<UUID>): Result<UUID, CodecError>
  • Returns the decoded input, Result.Ok or Result.Error()

    @example
    interface SomeObject {
    foo: string
    }
    const someCodec: Codec<SomeObject> = ...;
    const input: unknown = ...;
    const decoded = Codec.decode(someCodec, input);

__encode__

  • __encode__(this: void, input: UUID): unknown
  • Returns the encoded input

    @example
    interface SomeObject {
    foo: string
    }
    const someCodec: Codec<SomeObject> = ...;
    const someObject: SomeObject = { foo: "bar" }
    const encoded = Codec.decode(someCodec, someObject);

__schema__

  • __schema__(this: void): JSONValue
  • Returns the JSONSchema corresponding to the decoded type

    @example
    const someCodec: Codec<unknown> = ...;
    const jsonSchema = Codec.schema(someCodec);

Constructor

empty

  • Returns an UUID with only 0

    @example
    const emptyUUID = UUID.empty();// '00000000-0000-0000-0000-000000000000'

of

  • of(value: `${string}-${string}-${string}-${string}-${string}`): UUID
  • UUID constructor

    @example
    const uuid = UUID.of('1c19548b-7cac-4222-b722-dc38f2870669');

Formatting

asString

  • asString(this: void, self: UUID): string
  • Converts the given value to a String.

    @example
    Number.asString(123); // '123'

Type

__inspect__

__inspect__: Option<(anyValue: UUID, depth: number, options: InspectOptions, inspect: InspectFunction) => string>

When defined, returns a custom string representation. To be useful, it should be bound to a prototype (ex: Struct)

@example
import { inspect } from 'node:util';

interface Foo {
foo: boolean;
}
const Foo = Struct.define<Foo>({
typeName: 'Foo',
__inspect__: (self) => `Foo { ${String(self.foo)} }`,
});
const myStruct = Struct.create(Foo, { foo: true });// 'Foo { true }'
inspect(myStruct);// 'Foo { true }'
@param

asInstance

  • asInstance(anyValue: unknown): Option<UUID>
  • Try to convert anyValue to enum value or else returns Option.None

    @example
    const StringType: Type<string>;
    StringType.asInstance('foo'); // Option.Some('foo')
    StringType.asInstance(12); // Option.None

hasInstance

  • hasInstance(anyValue: unknown): anyValue is UUID
  • Return true if the given value is an instance of the class.

    @example
    const StringType: Type<string>;
    StringType.hasInstance('foo'); // true
    StringType.hasInstance(42); // false

Other

typeName

Re-exports typeName

readonlyid

id: ApplicationId

Application id

readonlyinitialConfiguration

initialConfiguration: UUIDConfiguration

Application initial configuration

readonlystate

state: Ref<ApplicationState>

Ref to application state

__call__

  • __call__(value: `${string}-${string}-${string}-${string}-${string}`): UUID

configure

  • configure(updater: Partial<UUIDConfiguration>): void
  • Return the configuration value

    @example
    const app = Application('my-app', {
    myVar: 1
    });
    app.configure({
    myVar: 2
    });
    app.get('myVar');// 2

get

  • get<Key>(key: Key): UUIDConfiguration[Key]
  • Return the configuration value

    @example
    const app = Application('my-app', {
    myVar: 1
    });
    app.get(app, 'myVar');// 1

    Type parameters

    • Key: randomUUIDGenerator

toBigInt

  • toBigInt(self: UUID): bigint
  • Returns a bigint from UUID

    @example
    const uuid = UUID('1c19548b-7cac-4222-b722-dc38f2870669');
    const bigint = UUID.toBigInt(uuid);// BigInt('Ox1c19548b7cac4222b722dc38f2870669');

toUint32Array

  • toUint32Array(self: UUID): Uint32Array
  • Converts a UUID to an array of uint32 values.

    @example
    const uuid: UUID;
    const parts = UUID.toUint32Array(uuid);

unwrap

  • unwrap(value: UUID): `${string}-${string}-${string}-${string}-${string}`
  • Convert a tagged value to the underlying type

wrap

  • wrap(value: `${string}-${string}-${string}-${string}-${string}`): UUID
  • Convert an underlying type to a tagged type