-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Famcache/rc-1.0.0
RC: 1.0.0
- Loading branch information
Showing
16 changed files
with
5,435 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs | ||
|
||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [21.x] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- run: yarn | ||
- run: yarn lint | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [21.x] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- run: yarn | ||
- run: yarn test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs | ||
|
||
name: Release | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [21.x] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- run: yarn | ||
- run: yarn lint | ||
- run: yarn test | ||
- run: yarn build | ||
- run: npx semantic-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
src | ||
node_modules | ||
example | ||
.github | ||
.gitignore | ||
.prettierrc | ||
.prettierignore | ||
eslint.config.mjs | ||
jest.config.js | ||
release.config.cjs | ||
settings.json | ||
tsconfig.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* @type {import('semantic-release').GlobalConfig} | ||
*/ | ||
module.exports = { | ||
branches: ["main"], | ||
plugins: [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator", | ||
"@semantic-release/changelog", | ||
"@semantic-release/npm", | ||
"@semantic-release/github" | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import CacheQuery from "./cache-query"; | ||
describe('CacheQuery', () => { | ||
it('should parse response string that contains data', () => { | ||
const query = CacheQuery.fromString('1 OK 10'); | ||
|
||
expect(query.id).toBe('1'); | ||
expect(query.isOk()).toBe(true); | ||
expect(query.data).toBe('10'); | ||
}) | ||
|
||
it('should parse response string that contains error', () => { | ||
const query = CacheQuery.fromString('1 ERROR'); | ||
|
||
expect(query.id).toBe('1'); | ||
expect(query.isError()).toBe(true) | ||
expect(query.data).toBe(''); | ||
}); | ||
|
||
it('should parse response string that contains data with spaces', () => { | ||
const query = CacheQuery.fromString('1 OK 10 20 30'); | ||
|
||
expect(query.id).toBe('1'); | ||
expect(query.isOk()).toBe(true); | ||
expect(query.data).toBe('10 20 30'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
type QueryStatus = 'OK' | 'ERROR'; | ||
|
||
class CacheQuery { | ||
public id: string; | ||
private status: QueryStatus; | ||
|
||
public data?: string; | ||
|
||
static fromString(data: string): CacheQuery { | ||
const [id, status, ...rest] = data.split(' '); | ||
|
||
return new CacheQuery(id, status as QueryStatus, rest.join(' ')); | ||
} | ||
|
||
constructor(id: string, status: QueryStatus, data: string) { | ||
this.id = id; | ||
this.status = status; | ||
this.data = data; | ||
} | ||
|
||
isOk() { | ||
return this.status === 'OK'; | ||
} | ||
|
||
isError() { | ||
return this.status === 'ERROR'; | ||
} | ||
} | ||
|
||
export default CacheQuery; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { set, get, del } from "./commands"; | ||
|
||
describe('commands', () => { | ||
it('should generate get command', () => { | ||
const command = get('1', 'key'); | ||
|
||
expect(command).toBe('1 GET key\n'); | ||
}); | ||
|
||
it('should generate set command', () => { | ||
const command = set('1', 'key', 'value', 1000); | ||
|
||
expect(command).toBe('1 SET key value 1000\n'); | ||
}); | ||
|
||
it('should generate set command without ttl', () => { | ||
const command = set('1', 'key', 'value'); | ||
|
||
expect(command).toBe('1 SET key value\n'); | ||
}); | ||
|
||
it('should generate del command', () => { | ||
const command = del('1', 'key'); | ||
|
||
expect(command).toBe('1 DEL key\n'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,22 @@ | ||
export function get(key: string): string { | ||
return `GET ${key}`; | ||
export function get(id: string, key: string): string { | ||
return `${id} GET ${key}\n`; | ||
} | ||
|
||
export function set(key: string, value: string, ttl?: number): string { | ||
return `SET ${key} ${value} ${ttl}`; | ||
export function set( | ||
id: string, | ||
key: string, | ||
value: string, | ||
ttl?: number, | ||
): string { | ||
const args = [key, value]; | ||
|
||
if (ttl) { | ||
args.push(ttl.toString()); | ||
} | ||
|
||
return `${id} SET ${args.join(' ')}\n`; | ||
} | ||
|
||
export function del(key: string): string { | ||
return `DEL ${key}`; | ||
export function del(id: string, key: string): string { | ||
return `${id} DEL ${key}\n`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type Optional<T> = T | null | undefined | void; | ||
|
||
export type QueueResolver = { | ||
resolve: (value: Optional<string>) => void; | ||
reject: (reason: Optional<string>) => void; | ||
}; |
Oops, something went wrong.