deno.land / x / pothos@release-1713397530 / packages / plugin-relay / utils / global-ids.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// @ts-nocheckimport { decodeBase64, encodeBase64, PothosValidationError } from '../../core/index.ts';export function encodeGlobalID(typename: string, id: bigint | number | string) { return encodeBase64(`${typename}:${id}`);}const typenameRegex = /^[A-Z_a-z]\w*$/;export function decodeGlobalID(globalID: string) { let decoded; try { decoded = decodeBase64(globalID).split(":"); } catch (error) { throw error instanceof PothosValidationError ? new PothosValidationError(`Invalid global ID: ${globalID}`) : error; } const [typename, id] = decoded; if (!typename || !id || !typenameRegex.test(typename)) { throw new PothosValidationError(`Invalid global ID: ${globalID}`); } return { typename, id: decoded.length > 2 ? decoded.slice(1).join(":") : id };}
pothos

Version Info

Tagged at
a year ago