Skip to content

Commit

Permalink
feat(core): leaveOnlyLastestPerEnv -> keepOnlyLatest
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Rename `LocalFileStore.recordRemoval.leaveOnlyLastestPerEnv` to `LocalFileStore.recordRemoval.keepOnlyLatest`
  • Loading branch information
jjangga0214 committed Nov 6, 2023
1 parent 5ba82bb commit 4ea13ec
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/core-store-keepOnlyLatest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@haetae/core': patch
---

BREAKING CHANGE: Rename `LocalFileStore.recordRemoval.leaveOnlyLastestPerEnv` to `LocalFileStore.recordRemoval.keepOnlyLatest`
8 changes: 4 additions & 4 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ export interface LocalFileStoreOptions {
age?: number | string
count?: number
// countPerEnv?: number // TODO: Implement this
leaveOnlyLastestPerEnv?: boolean
keepOnlyLatest?: boolean
}
}

Expand All @@ -574,7 +574,7 @@ export function localFileStore({
age = Number.POSITIVE_INFINITY,
// countPerEnv = Number.POSITIVE_INFINITY, // TODO: Implement this
count = Number.POSITIVE_INFINITY,
leaveOnlyLastestPerEnv = true,
keepOnlyLatest = true,
} = {},
filename = '.haetae/store.json',
}: LocalFileStoreOptions = {}): LocalFileStoreConnector {
Expand Down Expand Up @@ -627,7 +627,7 @@ export function localFileStore({
draft.specVersion = localFileStoreSpecVersion
draft.commands = draft.commands || {}
draft.commands[command] = draft.commands[command] || []
if (leaveOnlyLastestPerEnv) {
if (keepOnlyLatest) {
draft.commands[command] = draft.commands[command].filter(
// remove old record with same env. So there's only one record left for each env.
(oldRecord) => record.envHash !== oldRecord.envHash,
Expand All @@ -639,7 +639,7 @@ export function localFileStore({
// @ts-ignore
draft.commands[command] = draft.commands[command]
.filter(
(r) => !leaveOnlyLastestPerEnv || r.envHash !== record.envHash,
(r) => !keepOnlyLatest || r.envHash !== record.envHash,
)
.filter(
(r) => Date.now() - r.time < this.localFileStore.recordRemoval.age,
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/pages/apis/core.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ interface LocalFileStoreOptions {
recordRemoval?: {
age?: number | string
count?: number
leaveOnlyLastestPerEnv?: boolean
keepOnlyLatest?: boolean
}
}
```
Expand Down Expand Up @@ -824,7 +824,7 @@ Records whose age is older than this value are to be removed when calling [`addR
When the number of records becomes larger than this value, old records are removed to satisfy the threshold
when calling [`addRecord`](#addrecord). This task is executed after `recordRemoval.age{:ts}` is used.
<small>(default: `Number.POSITIVE_INFINITY{:ts}`) </small>
- `recordRemoval.leaveOnlyLastestPerEnv?{:ts}` : If `true{:ts}`, only the lastet records per `env` exist in the store file.
- `recordRemoval.keepOnlyLatest?{:ts}` : If `true{:ts}`, only the latest records per `env` exist in the store file.
This is useful if you only depend on the latest record per `env`.
<small>(default: `true{:ts}`) </small>
Expand Down
14 changes: 7 additions & 7 deletions packages/docs/pages/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -984,14 +984,14 @@ The practical guide with [`utils.hash(){:ts}`](./apis/utils#hash) is explained j
</Callout>

<Callout>
**`recordRemoval.leaveOnlyLastestPerEnv` of [`localFileStore`](./apis/core#localfilestore)** <br/>
**`recordRemoval.keepOnlyLatest` of [`LocalFileStore`](./apis/core#localfilestore)** <br/>
By default, you're using [`localFileStore`](./apis/core#localfilestore) as a *'Store Connector'*.
[`localFileStore`](./apis/core#localfilestore) stores records into a file (*`.haetae/store.json`*).
The option `recordRemoval.leaveOnlyLastestPerEnv{:ts}` is `true{:ts}` by default.
So only the last records per `env` exist in the store file.
This is useful when you only depend on the latest *Records*.
[`localFileStore`](./apis/core#localfilestore) stores records into the local file *`.haetae/store.json`*.
The option `recordRemoval.keepOnlyLatest{:ts}` is `true{:ts}` by default.
So only the single lastest *Record*s per *Env* per *Command* exist in the store file.
This is sensible when you only need the latest *Record*.
To utilize further past *Records*, you can set the option `false{:ts}`.
Changing or configuring *'Store Connector'* is guided later.
Changing or configuring *'Store Connector'* is guided from the [Custom Store](#custom-store) section.
</Callout>

5 Records are found in total.
Expand Down Expand Up @@ -1606,7 +1606,7 @@ export default configure({
// You can pass custom `LocalFileStoreOptions`
filename: '.haetae/store.json'
recordRemoval: {
leaveOnlyLastestPerEnv: true,
keepOnlyLatest: true,
// and more ...
}
),
Expand Down

1 comment on commit 4ea13ec

@vercel
Copy link

@vercel vercel bot commented on 4ea13ec Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

haetae – ./

haetae-git-main-jjangga0214.vercel.app
haetae-jjangga0214.vercel.app
haetae-mu.vercel.app

Please sign in to comment.