@decafhub/decaf-client-extras - v0.7.0
    Preparing search index...

    Namespace id

    This module provides a collection of DECAF record identifier type definitions. It is not exhaustive and it will be improved on an ongoing basis.

    Typically, a DECAF record identifier is either number or string. Some DECAF API endoints can consume string values even though a number is expected. We are sticking here to the original type: No number | string definitions.

    Methodologically, we are using a type trick to emulate newtypes in this module: For example, DECAF artifact identifier type is defined as:

    export type DecafArtifactId = number & { readonly __tag: unique symbol };
    

    In runtime, there is only a number. The & { readonly __tag: unique symbol } is provided to the compiler to distinguish in between number identifier values which are representing different DECAF record types.

    The construction and deconstruction of DECAF record identifiers are done via, respecively, mkDecafRecordId and unDecafRecordId:

    const exampleDecafArtifactIdValue: number = unDecafRecordId(exampleDecafArtifactId);
    const exampleDecafArtifactId: DecafArtifactId = mkDecafRecordId(42);
    expect(exampleDecafArtifactIdValue).toBe(42);

    const exampleDecafActionId: DecafActionId = mkDecafRecordId(42);
    const exampleDecafActionIdValue: number = unDecafRecordId(exampleDecafActionId);
    expect(exampleDecafActionIdValue).toBe(42);

    const exampleDecafArtifactTypeId: DecafArtifactTypeId = mkDecafRecordId('CCY');
    const exampleDecafArtifactTypeIdValue: string = unDecafRecordId(exampleDecafArtifactTypeId);
    expect(exampleDecafArtifactTypeIdValue).toBe('CCY');

    To re-iterate, the runtime representation is not affected by how DECAF record identifier types are defined:

    interface DecafArtifact {
    id: DecafArtifactId;
    type: DecafArtifactTypeId;
    }

    const exampleDecafArtifact: DecafArtifact = { id: mkDecafRecordId(10), type: mkDecafRecordId('CCY') };
    expect(exampleDecafArtifact).toStrictEqual({ id: 10, type: 'CCY' });

    References

    _DecafRecordIdFromNumber → _DecafRecordIdFromNumber
    _DecafRecordIdFromString → _DecafRecordIdFromString
    DecafAccountId → DecafAccountId
    DecafActionId → DecafActionId
    DecafArtifactId → DecafArtifactId
    DecafArtifactTypeId → DecafArtifactTypeId
    DecafExternalValuationId → DecafExternalValuationId
    DecafInstitutionId → DecafInstitutionId
    DecafOhlcSeriesId → DecafOhlcSeriesId
    DecafPortfolioGroupId → DecafPortfolioGroupId
    DecafPortfolioId → DecafPortfolioId
    DecafPrincipalId → DecafPrincipalId
    DecafShareClassFeeScheduleId → DecafShareClassFeeScheduleId
    DecafShareClassId → DecafShareClassId
    DecafTeamId → DecafTeamId
    mkDecafRecordId → mkDecafRecordId
    unDecafRecordId → unDecafRecordId