Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Expand the Identifier type? #2

Open
adam-rocska opened this issue Apr 1, 2023 · 0 comments
Open

Expand the Identifier type? #2

adam-rocska opened this issue Apr 1, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@adam-rocska
Copy link
Member

Within 21Gram we only use "string" identifiers. Numbers are not ok internally as they open the doors for exploits such as intel guesswork (autoincrements). Instead, we always stick to GUID, UUID, etc. expressed as string ¯_(ツ)_/¯

7gobri

If someone out there in the wilderness would like to have number support, just hit a thumbs up or smthn, we don't have issues with voluntarily shooting yourselves in the foot.

Reminder:

/**
 * @summary Represents the identifier of a REST resource.
 * @description
 * This weirdo type makes sure that the identifier of a
 * REST resource is a `string` but keeps the door open for
 * more strongly typed identifiers.
 * @example
 * The most basic "untyped" string example:
 * ```ts
 * // This is a valid identifier
 * const id: Identifier<string> = 'foo';
 * // This is not a valid identifier
 * const id: Identifier<string> = 42;
 * ```
 * @example
 * A more advanced, typed example:
 * ```ts
 * type ServiceID = 'auth' | 'paymentGateway' | 'cms' | 'crm';
 * // This is a valid identifier
 * const healthCheckId: Identifier<ServiceID> = 'auth';
 * // This is not a valid identifier
 * const healthCheckId: ServiceID = 'foo';
 * ```
 */
export type Identifier<T> = T extends string ? T : never;
@adam-rocska adam-rocska added the enhancement New feature or request label Apr 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant