Skip to content

Commit

Permalink
Remove RawKey type
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangoree committed Nov 29, 2024
1 parent 36d671b commit 0cf3285
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions packages/drift/src/cache/ClientCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { LruSimpleCache } from "src/cache/LruSimpleCache";
import type { SimpleCache } from "src/cache/types";
import { DriftError } from "src/error/DriftError";
import { createSerializableKey } from "src/utils/createSerializableKey";
import type { RawKey, SerializableKey } from "src/utils/createSerializableKey";
import type { SerializableKey } from "src/utils/createSerializableKey";
import type { MaybePromise } from "src/utils/types";

export type ClientCacheConfig<T extends SimpleCache = SimpleCache> = {
Expand Down Expand Up @@ -63,7 +63,9 @@ export class ClientCache<T extends SimpleCache = SimpleCache>
return this.namespace;
}

async createNamespacedKey(...parts: RawKey[]): Promise<SerializableKey> {
async createNamespacedKey(
...parts: NonNullable<unknown>[]
): Promise<SerializableKey> {
const namespace = await this.resolveNamespace();
return createSerializableKey([namespace, ...parts]);
}
Expand Down
9 changes: 5 additions & 4 deletions packages/drift/src/utils/createSerializableKey.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DriftError } from "src/error/DriftError";
import type { AnyObject } from "src/utils/types";

/**
* Converts a given raw key into a `SerializableKey``.
Expand All @@ -16,7 +17,9 @@ import { DriftError } from "src/error/DriftError";
* @returns A standardized key suitable for consistent referencing within a
* cache.
*/
export function createSerializableKey(rawKey: RawKey): SerializableKey {
export function createSerializableKey(
rawKey: NonNullable<unknown>,
): SerializableKey {
switch (typeof rawKey) {
case "string":
case "number":
Expand All @@ -43,7 +46,7 @@ export function createSerializableKey(rawKey: RawKey): SerializableKey {

// sort keys to ensure consistent key generation
for (const key of objectKeys.sort()) {
const value = rawKey[key];
const value = (rawKey as AnyObject)[key];

// ignore properties with undefined or null values
if (value !== undefined && value !== null) {
Expand All @@ -65,8 +68,6 @@ export function createSerializableKey(rawKey: RawKey): SerializableKey {
}
}

export type RawKey = NonNullable<any>;

/**
* Represents possible serializable key types.
*/
Expand Down

0 comments on commit 0cf3285

Please sign in to comment.