UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

1 lines 3.06 kB
{"version":3,"file":"cache-keys.mjs","names":[],"sources":["../../../src/libs/kv/cache-keys.ts"],"sourcesContent":["const HTTP_STATIC_PREFIX = \"http:static:\";\n\nconst authTenantCacheSegment = (tenantKey?: string | null) =>\n\ttenantKey == null ? \"no-tenant\" : `tenant:${encodeURIComponent(tenantKey)}`;\n\nconst cacheKeys = {\n\t/**\n\t * Generate cache keys for collection schema + migration metadata.\n\t */\n\tcollection: {\n\t\tschema: (collectionKey: string) => `collection:schema:${collectionKey}`,\n\t},\n\t/**\n\t * Generate cache keys for rate limiting (used by rate limiter middleware)\n\t */\n\trateLimit: {\n\t\tip: (ip: string) => `rate-limit:ip:${ip}`,\n\t\tuser: (userId: string | number) => `rate-limit:user:${userId}`,\n\t\tclient: (clientId: string | number) => `rate-limit:client:${clientId}`,\n\t\trecord: (key: string) => `rate-limit:record:${key}`,\n\t},\n\t/**\n\t * Generate cache keys for authentication\n\t */\n\tauth: {\n\t\tuser: (\n\t\t\tuserId: string | number,\n\t\t\tnamespaceToken: string,\n\t\t\ttenantKey?: string | null,\n\t\t) =>\n\t\t\t`auth:user:${namespaceToken}:${userId}:${authTenantCacheSegment(tenantKey)}`,\n\t\t/**\n\t\t * Cache key for refresh token existence\n\t\t */\n\t\trefresh: (token: string) => `auth:refresh:${token}`,\n\t},\n\t/**\n\t * Generate namespace keys for token-based invalidation/versioning.\n\t */\n\tnamespace: {\n\t\ttoken: (namespace: string) => `_namespace:${namespace}`,\n\t},\n\t/**\n\t * Generate cache keys for HTTP responses (used by cache middleware)\n\t */\n\thttp: {\n\t\tresponse: (hash: string) => `http:${hash}`,\n\t\ttags: {\n\t\t\tclientLocales: \"client-locales\",\n\t\t\tclientMedia: \"client-media\",\n\t\t\tclientDocuments: \"client-documents\",\n\t\t\tclientDocumentsCollection: (collectionKey: string) =>\n\t\t\t\t`client-documents:${collectionKey}`,\n\t\t},\n\t\tstatic: {\n\t\t\tclientLocales: `${HTTP_STATIC_PREFIX}client-locales`,\n\t\t\tclientMediaSingle: (id: string | number, tenantKey?: string | null) =>\n\t\t\t\t`${HTTP_STATIC_PREFIX}client-media:${tenantKey ?? \"global\"}:${id}` as `${typeof HTTP_STATIC_PREFIX}client-media:${string}`,\n\t\t},\n\t},\n} as const;\n\ntype HttpStaticValue<T> = T extends (...args: infer _A) => infer R ? R : T;\n\nexport type HttpStaticValues = {\n\t[K in keyof typeof cacheKeys.http.static]: HttpStaticValue<\n\t\t(typeof cacheKeys.http.static)[K]\n\t>;\n}[keyof typeof cacheKeys.http.static];\n\nexport default cacheKeys;\n"],"mappings":"AAAA,MAAM,EAAqB,eAErB,EAA0B,GAC/B,GAAa,KAAO,YAAc,UAAU,mBAAmB,CAAS,IAEnE,EAAY,CAIjB,WAAY,CACX,OAAS,GAA0B,qBAAqB,GACzD,EAIA,UAAW,CACV,GAAK,GAAe,iBAAiB,IACrC,KAAO,GAA4B,mBAAmB,IACtD,OAAS,GAA8B,qBAAqB,IAC5D,OAAS,GAAgB,qBAAqB,GAC/C,EAIA,KAAM,CACL,MACC,EACA,EACA,IAEA,aAAa,EAAe,GAAG,EAAO,GAAG,EAAuB,CAAS,IAI1E,QAAU,GAAkB,gBAAgB,GAC7C,EAIA,UAAW,CACV,MAAQ,GAAsB,cAAc,GAC7C,EAIA,KAAM,CACL,SAAW,GAAiB,QAAQ,IACpC,KAAM,CACL,cAAe,iBACf,YAAa,eACb,gBAAiB,mBACjB,0BAA4B,GAC3B,oBAAoB,GACtB,EACA,OAAQ,CACP,cAAe,GAAG,EAAmB,gBACrC,mBAAoB,EAAqB,IACxC,GAAG,EAAmB,eAAe,GAAa,SAAS,GAAG,GAChE,CACD,CACD"}