Skip to content

Commit

Permalink
fix: update ts
Browse files Browse the repository at this point in the history
  • Loading branch information
unional committed Apr 26, 2024
1 parent f56dcc3 commit 912c75e
Show file tree
Hide file tree
Showing 18 changed files with 233 additions and 186 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-seals-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'global-store': patch
---

Fix handling when `key` is unknown in `initializeAsyncStore()`
8 changes: 8 additions & 0 deletions .changeset/weak-mirrors-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'global-store': patch
'stable-store': patch
---

Update TypeScript to 5.4.5.
Adjust type to support `exactOptionalPropertyTypes`.

3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"dbaeumer.vscode-eslint",
"astro-build.astro-vscode",
"bradlc.vscode-tailwindcss",
"redhat.vscode-yaml"
"redhat.vscode-yaml",
"biomejs.biome"
]
}
2 changes: 1 addition & 1 deletion examples/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"tailwindcss": "^3.0.24"
},
"devDependencies": {
"@repobuddy/typescript": "^1.1.2"
"@repobuddy/typescript": "^2.0.0"
}
}
5 changes: 2 additions & 3 deletions examples/library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"devDependencies": {
"@jest/globals": "^29.7.0",
"@repobuddy/jest": "^4.0.0",
"@repobuddy/typescript": "^1.1.2",
"@repobuddy/typescript": "^2.0.0",
"@size-limit/preset-small-lib": "~8.2.4",
"cross-env": "^7.0.3",
"depcheck": "~1.4.3",
Expand All @@ -59,8 +59,7 @@
"rimraf": "~5.0.0",
"size-limit": "~8.2.4",
"stable-store": "workspace:*",
"ts-jest": "^29.1.2",
"typescript": "^5.0.4"
"ts-jest": "^29.1.2"
},
"peerDependencies": {
"global-store": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"npm-run-all": "^4.1.5",
"pinst": "^3.0.0",
"turbo": "^1.13.3",
"typescript": "^5.0.4"
"typescript": "^5.4.5"
},
"packageManager": "pnpm@9.0.6"
}
2 changes: 1 addition & 1 deletion packages/global-store/dist/global-store.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/global-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"devDependencies": {
"@babel/core": "^7.18.10",
"@repobuddy/jest": "^4.0.0",
"@repobuddy/typescript": "^2.0.0",
"@rollup/plugin-typescript": "^11.0.0",
"@size-limit/preset-small-lib": "^8.0.1",
"@types/jest": "^29.5.12",
Expand All @@ -58,8 +59,7 @@
"size-limit": "^8.0.1",
"ts-jest": "^29.1.2",
"tslib": "^2.4.0",
"type-plus": "^6.0.0",
"typescript": "5.0.4"
"type-plus": "^6.0.0"
},
"size-limit": [
{
Expand Down
8 changes: 8 additions & 0 deletions packages/global-store/ts/createAsyncStore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ test('calling initializeAsyncStore() with no createAsyncStore() call does nothin
initializeAsyncStore('unknown-module')
})

it('unknown key', async () => {
const moduleName = 'module-one-store-init-with-key'
const key = '6e9dec9c-db22-4bbd-a088-ce734e34b5fd'
createAsyncStore({ moduleName, key, version: 0, initializer: () => ({ a: 1 }) })
initializeAsyncStore(moduleName, 'some-unknown-key')

})

test('init single store with key', async () => {
const moduleName = 'module-one-store-init-with-key'
const key = '6e9dec9c-db22-4bbd-a088-ce734e34b5fd'
Expand Down
9 changes: 5 additions & 4 deletions packages/global-store/ts/createAsyncStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ export async function createAsyncStore<T extends StoreValue>({
* @see https://github.com/unional/global-store#initializeAsyncStore
*/
export function initializeAsyncStore(moduleName: string, key?: string) {
const creatorsOfModules = asyncStoreCreators[moduleName]
if (!creatorsOfModules) return
const s = asyncStoreCreators[moduleName]
if (!s) return
if (key &&!s[key]) return

const keys = key ? [key] : Object.keys(creatorsOfModules)
keys.forEach((key) => resolveCreators(moduleName, key, creatorsOfModules[key], createStore))
const keys = key ? [key] : Object.keys(s)
keys.forEach((key) => resolveCreators(moduleName, key, s[key]!, createStore))
}
4 changes: 2 additions & 2 deletions packages/global-store/ts/createStore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('freeze store', () => {
})
store.freeze()
store.value
a.throws(() => (store.value.b = 2), TypeError)
a.throws(() => (store.value['b'] = 2), TypeError)
})

test('cannot be freezed again', () => {
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('freeze store', () => {
initializer: () => ({ a: [{ x: 'x' }] })
})
store.freeze()
store.value.a[0].x = 'y'
store.value.a[0]!.x = 'y'
})

test('freeze provided value but not array property', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/global-store/ts/typesInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { StoreInitializer, StoreValue, StoreVersion } from './types.js'

export interface StoreId {
moduleName: string
key?: string
key?: string | undefined
}

export type Stores = Record<
Expand Down
4 changes: 2 additions & 2 deletions packages/global-store/ts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export function resetStoreValue(stores: Stores, id: StoreId) {
store.versions = []
store.value = store.initializers.reduce<StoreValue>((value, initializer, i) => {
value = initializer(value, store.versions)
store.versions.push(versions[i])
store.versions.push(versions[i]!)
return value
}, {})
}

export function getStore(stores: Stores, id: StoreId) {
const moduleStore = (stores[id.moduleName] = stores[id.moduleName] || Object.create(null))
const moduleStore: Stores[string] = (stores[id.moduleName] = stores[id.moduleName] || Object.create(null))
const key = id.key ?? 'default'
return (moduleStore[key] = moduleStore[key] || { versions: [], value: {}, initializers: [] })
}
Expand Down
20 changes: 3 additions & 17 deletions packages/global-store/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
{
"extends": "@repobuddy/typescript/tsconfig/monorepo",
"compilerOptions": {
"composite": true,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"inlineSources": true,
"lib": ["ES2015", "ES2021.Promise"],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"newLine": "LF",
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "lib",
"removeComments": false,
"rootDir": "ts",
"sourceMap": true,
"strict": true,
"target": "ES2020"
"rootDir": "ts"
},
"include": ["ts", "typings"]
"include": ["ts", "types"]
}
3 changes: 1 addition & 2 deletions packages/stable-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"rimraf": "~5.0.0",
"size-limit": "~8.2.4",
"ts-jest": "^29.1.2",
"type-plus": "^6.0.0",
"typescript": "^5.0.4"
"type-plus": "^6.0.0"
}
}
Loading

0 comments on commit 912c75e

Please sign in to comment.