serlo / cloudflare-worker

Cloudflare worker which works as a proxy for https://serlo.org/
Apache License 2.0
9 stars 1 forks source link

Update KV and createKV definition #97

Closed kulla closed 3 years ago

kulla commented 3 years ago

There are several tasks to do:

Change KV definition:

The KV definition at https://github.com/serlo/serlo.org-cloudflare-worker/blob/master/src/kv.d.ts#L30-L37 needs to be updated. The final definition shall be:

declare interface KV<Key extends string> {
  get: (key: Key) => Promise<string | null>
  put: (
    key: Key,
    value: string,
    options?: { expirationTtl: number }
  ) => Promise<void>
}

Change createKV() definition:

The values property of createKV shall be deleted at https://github.com/serlo/serlo.org-cloudflare-worker/blob/master/__tests__/__utils__/kv.ts#L23

Thus instead of https://github.com/serlo/serlo.org-cloudflare-worker/blob/master/__tests__/maintenance.ts#L52 we need to be

await global.MAINTENANCE_KV.put("enabled", JSON.stringify(value))

Therefore all KVs need to be initialized at https://github.com/serlo/serlo.org-cloudflare-worker/blob/master/jest.setup.ts#L56-L58

change signature of createKV


function createKV<Keys extends string>(): KV<Keys>
kulla commented 3 years ago

Fixed by #121