Skip to content

Commit b9fe796

Browse files
authored
Merge branch 'main' into cron-patterns
2 parents 718fcdc + 0eb9fbb commit b9fe796

File tree

6 files changed

+127
-89
lines changed

6 files changed

+127
-89
lines changed

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
11

2+
# 1.0.2 - 18 Mar 2024
3+
Change:
4+
- Add support for Elysia 1.0
5+
6+
7+
# 1.0.0 - 16 Mar 2024
8+
Change:
9+
- Add support for Elysia 1.0
10+
11+
12+
# 1.0.0-rc.0 - 1 Mar 2024
13+
Change:
14+
- Add support for Elysia 1.0
15+
16+
17+
# 1.0.0-beta.1 - 17 Feb 2024
18+
Change:
19+
- Add support for Elysia 1.0
20+
21+
22+
# 1.0.0-beta.0 - 6 Feb 2024
23+
Change:
24+
- Add support for Elysia 1.0
25+
26+
27+
# 0.8.0 - 23 Dec 2023
28+
Change:
29+
- Add support for Elysia 0.8
30+
31+
232
# 0.8.0-rc.0 - 15 Dec 2023
333
Change:
434
- Add support for Elysia 0.8

bun.lockb

1.89 KB
Binary file not shown.

package.json

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
11
{
2-
"name": "@elysiajs/cron",
3-
"version": "0.8.0",
4-
"description": "Plugin for Elysia that add support for running cronjob",
5-
"author": {
6-
"name": "saltyAom",
7-
"url": "https://github.com/SaltyAom",
8-
"email": "[email protected]"
9-
},
10-
"main": "./src/index.ts",
11-
"exports": {
12-
"bun": "./dist/index.js",
13-
"node": "./dist/cjs/index.js",
14-
"require": "./dist/cjs/index.js",
15-
"import": "./dist/index.js",
16-
"default": "./dist/index.js"
17-
},
18-
"types": "./src/index.ts",
19-
"keywords": [
20-
"elysia",
21-
"cron"
22-
],
23-
"homepage": "https://github.com/elysiajs/elysia-cron",
24-
"repository": {
25-
"type": "git",
26-
"url": "https://github.com/elysiajs/elysia-cron"
27-
},
28-
"bugs": "https://github.com/elysiajs/elysia-cron/issues",
29-
"license": "MIT",
30-
"scripts": {
31-
"dev": "bun run --hot example/index.ts",
32-
"test": "bun test && npm run test:node",
33-
"test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js",
34-
"build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
35-
"release": "npm run build && npm run test && npm publish --access public"
36-
},
37-
"peerDependencies": {
38-
"elysia": ">= 0.8.0"
39-
},
40-
"devDependencies": {
41-
"@types/node": "^20.1.4",
42-
"@typescript-eslint/eslint-plugin": "^5.59.5",
43-
"@typescript-eslint/parser": "^5.59.5",
44-
"bun-types": "^0.5.8",
45-
"elysia": "0.8.0",
46-
"eslint": "^8.40.0",
47-
"rimraf": "4.3",
48-
"typescript": "^5.0.4"
49-
},
50-
"dependencies": {
51-
"croner": "^6.0.3"
52-
},
53-
"peerDependenciesMeta": {
54-
"croner": {
55-
"optional": true
56-
}
2+
"name": "@elysiajs/cron",
3+
"version": "1.0.2",
4+
"description": "Plugin for Elysia that add support for running cronjob",
5+
"author": {
6+
"name": "saltyAom",
7+
"url": "https://github.com/SaltyAom",
8+
"email": "[email protected]"
9+
},
10+
"main": "./src/index.ts",
11+
"exports": {
12+
"bun": "./dist/index.js",
13+
"node": "./dist/cjs/index.js",
14+
"require": "./dist/cjs/index.js",
15+
"import": "./dist/index.js",
16+
"default": "./dist/index.js"
17+
},
18+
"types": "./src/index.ts",
19+
"keywords": [
20+
"elysia",
21+
"cron"
22+
],
23+
"homepage": "https://github.com/elysiajs/elysia-cron",
24+
"repository": {
25+
"type": "git",
26+
"url": "https://github.com/elysiajs/elysia-cron"
27+
},
28+
"bugs": "https://github.com/elysiajs/elysia-cron/issues",
29+
"license": "MIT",
30+
"scripts": {
31+
"dev": "bun run --hot example/index.ts",
32+
"test": "bun test && npm run test:node",
33+
"test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js",
34+
"build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
35+
"release": "npm run build && npm run test && npm publish --access public"
36+
},
37+
"peerDependencies": {
38+
"elysia": ">= 1.0.2"
39+
},
40+
"devDependencies": {
41+
"@types/bun": "^1.0.4",
42+
"@types/node": "^20.1.4",
43+
"@typescript-eslint/eslint-plugin": "^5.59.5",
44+
"@typescript-eslint/parser": "^5.59.5",
45+
"elysia": "1.0.2",
46+
"eslint": "^8.40.0",
47+
"rimraf": "4.3",
48+
"typescript": "^5.0.4"
49+
},
50+
"dependencies": {
51+
"croner": "^6.0.3"
52+
},
53+
"peerDependenciesMeta": {
54+
"croner": {
55+
"optional": true
5756
}
57+
}
5858
}

src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ export const cron =
3939
if (!pattern) throw new Error('pattern is required')
4040
if (!name) throw new Error('name is required')
4141

42-
return app.state(store => {
43-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
44-
// @ts-ignore
45-
const prevCron = app.store?.cron ?? {}
42+
return app.state((store) => {
43+
// @ts-expect-error private property
44+
const prevCron = app.singleton.store?.cron ?? {}
4645
return {
4746
...store,
4847
cron: {
4948
...prevCron,
50-
[name]: new Cron(pattern, options, () => run(app.store as any)),
49+
[name]: new Cron(pattern, options, () =>
50+
// @ts-expect-error private property
51+
run(app.singleton.store as any)
52+
)
5153
} as Record<Name, Cron>
5254
}
5355
})

test/index.test.ts

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/ban-ts-comment */
12
import { Elysia } from 'elysia'
23
import { cron } from '../src'
34
import { Patterns } from '../src/schedule'
@@ -36,7 +37,8 @@ describe('Cron', () => {
3637
})
3738
)
3839

39-
expect(Object.keys(app.store.cron)[0]).toBe('job')
40+
// @ts-expect-error
41+
expect(Object.keys(app.singleton.store.cron)[0]).toBe('job')
4042
})
4143

4244
it('stop cronjob', async () => {
@@ -70,7 +72,7 @@ describe('Mutli Cron', () => {
7072
let done2 = false
7173
let done3 = false
7274

73-
new Elysia().use(
75+
new Elysia().use(
7476
cron({
7577
pattern: '*/1 * * * * *',
7678
name: 'job1',
@@ -105,34 +107,38 @@ describe('Mutli Cron', () => {
105107
})
106108

107109
it('add cronjobs to store', async () => {
108-
const app = new Elysia().use(
109-
cron({
110-
pattern: '*/1 * * * * *',
111-
name: 'job1',
112-
run() {
113-
// Not empty
114-
}
115-
})
116-
).use(
117-
cron({
118-
pattern: '*/1 * * * * *',
119-
name: 'job2',
120-
run() {
121-
// Not empty
122-
}
123-
})
124-
).use(
125-
cron({
126-
pattern: Patterns.EVERY_SECOND,
127-
name: 'job3',
128-
run() {
129-
// Not empty
130-
}
131-
})
132-
)
110+
const app = new Elysia()
111+
.use(
112+
cron({
113+
pattern: '*/1 * * * * *',
114+
name: 'job1',
115+
run() {
116+
// Not empty
117+
}
118+
})
119+
).use(
120+
cron({
121+
pattern: '*/1 * * * * *',
122+
name: 'job2',
123+
run() {
124+
// Not empty
125+
}
126+
})
127+
).use(
128+
cron({
129+
pattern: Patterns.EVERY_SECOND,
130+
name: 'job3',
131+
run() {
132+
// Not empty
133+
}
134+
})
135+
)
133136

137+
// @ts-expect-error
134138
expect(Object.keys(app.store.cron)[0]).toBe('job1')
139+
// @ts-expect-error
135140
expect(Object.keys(app.store.cron)[1]).toBe('job2')
141+
// @ts-expect-error
136142
expect(Object.keys(app.store.cron)[2]).toBe('job3')
137143
})
138144

@@ -149,7 +155,8 @@ describe('Mutli Cron', () => {
149155
done1 = true
150156
}
151157
})
152-
).use(
158+
)
159+
.use(
153160
cron({
154161
pattern: '*/1 * * * * *',
155162
name: 'job2',

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
3333
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
3434
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35-
"types": ["bun-types"], /* Specify type package names to be included without being referenced in a source file. */
3635
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
3736
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
3837
// "resolveJsonModule": true, /* Enable importing .json files. */

0 commit comments

Comments
 (0)