@zingage/postgres-multi-tenant-ids
Version:
PostgreSQL IDs for secure multi-tenant applications
28 lines (27 loc) • 1.79 kB
JavaScript
import { isUnscopedId as _isUnscopedId, stringIsUnscopedId as _stringIsUnscopedId, makeMakeUnscopedIdBound, } from "./id-kind-implementations/cross-tenant-entity-ids.js";
import { getTenantShortIdFromFullId, isTenantId, makeTenantId, stringIsTenantId, uuidV4ToTenantId, } from "./id-kind-implementations/tenant-ids.js";
import { getTenantShortIdFromScopedId as _getTenantShortIdFromScopedId, isScopedId as _isScopedId, scopedIdsBelongToSameTenant as _scopedIdsBelongToSameTenant, stringIsScopedId as _stringIsScopedId, makeMakeScopedIdBound, } from "./id-kind-implementations/tenant-scoped-entity-ids.js";
export function initialize(config) {
return {
config,
makeScopedId: makeMakeScopedIdBound(config.tenantScoped),
isScopedId: _isScopedId,
stringIsScopedId: _stringIsScopedId,
getTenantShortIdFromScopedId: _getTenantShortIdFromScopedId,
scopedIdsBelongToSameTenant: _scopedIdsBelongToSameTenant,
makeUnscopedId: makeMakeUnscopedIdBound(config.crossTenant),
isUnscopedId: _isUnscopedId,
stringIsUnscopedId: _stringIsUnscopedId,
// Upcasting is needed so that TS doesn't complain when a user of this type
// tries to consume it. The issue is that, without the upcast, the type of
// the export is simply `typeof makeTenantId`, but that's defined in
// `tenant-ids.js` and it is not directly a public export, so TS complains
// that there's no way for the consumer of this module (in its generated
// declarations) to refer to that type.
isTenantId: isTenantId,
makeTenantId: makeTenantId,
uuidV4ToTenantId: uuidV4ToTenantId,
getTenantShortIdFromFullId: getTenantShortIdFromFullId,
stringIsTenantId: stringIsTenantId,
};
}