UNPKG

@zingage/postgres-multi-tenant-ids

Version:

PostgreSQL IDs for secure multi-tenant applications

43 lines 3.59 kB
import type { EntityTypeHint, InsertRate, ScopedId, TenantId, TenantShortId, UnscopedId } from "./helpers/config-agnostic-types.js"; import type { UUIDV4, UUIDV8 } from "./helpers/utils.js"; export type { Id, ScopedId, TenantId, TenantShortId, UnscopedId } from "./helpers/config-agnostic-types.js"; export type { UUID, UUIDV4, UUIDV8 } from "./helpers/utils.js"; export declare function initialize<const TenantScopedEntityTypeConfigs extends NamedEntityTypeConfigs, const CrossTenantEntityTypeConfigs extends NamedEntityTypeConfigs>(config: Readonly<{ tenantScoped: TenantScopedEntityTypeConfigs; crossTenant: CrossTenantEntityTypeConfigs; }>): { config: Readonly<{ tenantScoped: TenantScopedEntityTypeConfigs; crossTenant: CrossTenantEntityTypeConfigs; }>; makeScopedId: <K extends keyof TenantScopedEntityTypeConfigs & string>(tenantId: TenantId, entityType: K, date?: Date) => ScopedId<TenantScopedEntityTypeConfigs, K>; isScopedId: <EntityType extends keyof TenantScopedEntityTypeConfigs & string>(id: UUIDV8 | ScopedId<TenantScopedEntityTypeConfigs, EntityType>) => id is ScopedId<TenantScopedEntityTypeConfigs, EntityType>; stringIsScopedId: <EntityType extends keyof TenantScopedEntityTypeConfigs & string>(id: string) => id is ScopedId<TenantScopedEntityTypeConfigs, EntityType>; getTenantShortIdFromScopedId: <EntityType extends keyof TenantScopedEntityTypeConfigs & string>(id: ScopedId<TenantScopedEntityTypeConfigs, EntityType>) => TenantShortId; scopedIdsBelongToSameTenant: <EntityType extends keyof TenantScopedEntityTypeConfigs & string>(ids: ScopedId<TenantScopedEntityTypeConfigs, EntityType>[]) => boolean; makeUnscopedId: <K extends keyof CrossTenantEntityTypeConfigs & string>(entityType: K, date?: Date) => UnscopedId<CrossTenantEntityTypeConfigs, K>; isUnscopedId: <EntityType extends keyof CrossTenantEntityTypeConfigs & string>(id: UUIDV8 | UnscopedId<CrossTenantEntityTypeConfigs, EntityType>) => id is UnscopedId<CrossTenantEntityTypeConfigs, EntityType>; stringIsUnscopedId: <EntityType extends keyof CrossTenantEntityTypeConfigs & string>(id: string) => id is UnscopedId<CrossTenantEntityTypeConfigs, EntityType>; isTenantId: (id: UUIDV8) => id is TenantId; makeTenantId: () => TenantId; uuidV4ToTenantId: (id: UUIDV4) => TenantId; getTenantShortIdFromFullId: (id: TenantId) => TenantShortId; stringIsTenantId: (id: string) => id is TenantId; }; export type EntityTypesConfig<TenantScopedConfigs extends NamedEntityTypeConfigs = NamedEntityTypeConfigs, CrossTenantConfigs extends NamedEntityTypeConfigs = NamedEntityTypeConfigs> = Readonly<{ tenantScoped: TenantScopedConfigs; crossTenant: CrossTenantConfigs; }>; export type NamedEntityTypeConfigs = { [k: string]: EntityTypeConfig; }; export type EntityTypeConfig = { insertRate: InsertRate; entityTypeHint: EntityTypeHint; }; type DuplicateTypeHints<T extends NamedEntityTypeConfigs> = { [K in keyof T]: T[K]["entityTypeHint"] extends T[Exclude<keyof T, K>]["entityTypeHint"] ? K & string : never; }[keyof T]; export type { Satisfies } from "type-party"; export type Duplicates<T extends EntityTypesConfig> = (DuplicateTypeHints<T["tenantScoped"]> extends never ? never : `ERROR: ${DuplicateTypeHints<T["tenantScoped"]>} has the same entity type hint as another tenant-scoped entity.`) | (DuplicateTypeHints<T["crossTenant"]> extends never ? never : `ERROR: ${DuplicateTypeHints<T["crossTenant"]>} has the same entity type hint as another cross-tenant entity.`); //# sourceMappingURL=index.d.ts.map