@skyblock-finance/actions 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/$schema.json +32 -16
- package/data/bits-crafts.json +35 -1
- package/data/bits.json +55 -55
- package/data/gems.json +90 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/data.d.ts +11 -78
- package/dist/data.js +4 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +6 -1
- package/dist/schema.d.ts +59 -51
- package/dist/schema.js +16 -14
- package/dist/types.d.ts +7 -0
- package/dist/types.js +2 -0
- package/package.json +2 -2
- package/source/data.test.ts +60 -63
- package/source/data.ts +5 -2
- package/source/index.ts +13 -1
- package/source/schema.ts +15 -18
- package/source/types.ts +13 -0
package/source/data.test.ts
CHANGED
|
@@ -1,85 +1,82 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { actionSchema } from './schema'
|
|
2
2
|
import { allActions } from './data'
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
import { describe, expect, test } from 'bun:test'
|
|
5
5
|
import assert from 'node:assert'
|
|
6
|
+
import { ActionIoItem } from './types'
|
|
6
7
|
|
|
7
8
|
test('all actions follow the schema', () => {
|
|
8
9
|
expect(() => z.array(actionSchema).parse(allActions)).not.toThrow()
|
|
9
10
|
})
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const result = new Map<string, number>()
|
|
12
|
+
/**
|
|
13
|
+
* Simplifies and "sorts" action input/output items
|
|
14
|
+
*/
|
|
15
|
+
const sumUp = (ios: ActionIoItem[]): Map<string, number> => {
|
|
16
|
+
const result = new Map<string, number>()
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return result
|
|
18
|
+
for (const io of ios) {
|
|
19
|
+
const previousValue = result.get(io.id) ?? 0
|
|
20
|
+
result.set(io.id, previousValue + io.amount)
|
|
24
21
|
}
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
23
|
+
return result
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
test('sumUp works', () => {
|
|
27
|
+
expect(
|
|
28
|
+
sumUp([
|
|
29
|
+
{
|
|
30
|
+
amount: 1,
|
|
31
|
+
id: 'FOO',
|
|
32
|
+
type: 'item',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
amount: 2,
|
|
36
|
+
id: 'BAR',
|
|
37
|
+
type: 'item',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
amount: 1,
|
|
41
|
+
id: 'BAZ',
|
|
42
|
+
type: 'item',
|
|
43
|
+
},
|
|
44
|
+
]),
|
|
45
|
+
).toEqual(
|
|
46
|
+
sumUp([
|
|
47
|
+
{
|
|
48
|
+
amount: 1,
|
|
49
|
+
id: 'BAR',
|
|
50
|
+
type: 'item',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
amount: 1,
|
|
54
|
+
id: 'FOO',
|
|
55
|
+
type: 'item',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
amount: 1,
|
|
59
|
+
id: 'BAZ',
|
|
60
|
+
type: 'item',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
amount: 1,
|
|
64
|
+
id: 'BAR',
|
|
65
|
+
type: 'item',
|
|
66
|
+
},
|
|
67
|
+
]),
|
|
68
|
+
)
|
|
69
|
+
})
|
|
70
70
|
|
|
71
|
+
describe('every action’s inputs match its crafing grid', () => {
|
|
71
72
|
for (const action of allActions) {
|
|
72
73
|
for (const grid of action.place.filter((x) => x.type === 'workbench')) {
|
|
73
74
|
test(`${JSON.stringify(action.outputs)} is valid`, () => {
|
|
74
75
|
assert(grid.type === 'workbench')
|
|
75
76
|
|
|
76
|
-
const actual = sumUp(
|
|
77
|
-
action.inputs.filter((x) => x.type === 'item') as ActionIoItem[],
|
|
78
|
-
)
|
|
77
|
+
const actual = sumUp(action.inputs.filter((x) => x.type === 'item'))
|
|
79
78
|
|
|
80
|
-
const expected = sumUp(
|
|
81
|
-
grid.grid.filter((x) => x !== null) as ActionIoItem[],
|
|
82
|
-
)
|
|
79
|
+
const expected = sumUp(grid.grid.filter((x) => x !== null))
|
|
83
80
|
|
|
84
81
|
expect(actual).toEqual(expected)
|
|
85
82
|
})
|
package/source/data.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { actions as _bits } from '../data/bits.json'
|
|
2
2
|
import { actions as _bitsCrafts } from '../data/bits-crafts.json'
|
|
3
|
-
import {
|
|
3
|
+
import { actions as _gems } from '../data/gems.json'
|
|
4
|
+
import { Action } from './types'
|
|
4
5
|
|
|
5
6
|
export const bits = _bits as Action[]
|
|
6
7
|
export const bitsCrafts = _bitsCrafts as Action[]
|
|
7
8
|
|
|
8
|
-
export const
|
|
9
|
+
export const gems = _gems as Action[]
|
|
10
|
+
|
|
11
|
+
export const allActions = [...bits, ...bitsCrafts, ...gems]
|
package/source/index.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
export * from './data'
|
|
2
|
-
export
|
|
2
|
+
export {
|
|
3
|
+
Action,
|
|
4
|
+
ActionCurrency,
|
|
5
|
+
ActionIo,
|
|
6
|
+
ActionIoCurrency,
|
|
7
|
+
ActionIoItem,
|
|
8
|
+
} from './types'
|
|
9
|
+
export {
|
|
10
|
+
actionIoItemSchema,
|
|
11
|
+
actionIoSchema,
|
|
12
|
+
actionPlaceSchema,
|
|
13
|
+
actionSchema,
|
|
14
|
+
} from './schema'
|
package/source/schema.ts
CHANGED
|
@@ -2,32 +2,25 @@ import { z } from 'zod'
|
|
|
2
2
|
|
|
3
3
|
export const actionIoItemSchema = z
|
|
4
4
|
.object({
|
|
5
|
-
amount: z.number().
|
|
5
|
+
amount: z.number().finite(),
|
|
6
6
|
id: z.string(),
|
|
7
7
|
type: z.literal('item'),
|
|
8
8
|
})
|
|
9
9
|
.strict()
|
|
10
10
|
|
|
11
|
-
export
|
|
11
|
+
export const actionIoCurrencySchema = z
|
|
12
|
+
.object({
|
|
13
|
+
amount: z.number().finite(),
|
|
14
|
+
id: z.enum(['bit', 'coin', 'gem', 'northStar', 'second', 'usd']),
|
|
15
|
+
type: z.literal('currency'),
|
|
16
|
+
})
|
|
17
|
+
.strict()
|
|
12
18
|
|
|
13
19
|
export const actionIoSchema = z.discriminatedUnion('type', [
|
|
14
|
-
|
|
15
|
-
.object({
|
|
16
|
-
amount: z.number().int().finite(),
|
|
17
|
-
type: z.literal('bit'),
|
|
18
|
-
})
|
|
19
|
-
.strict(),
|
|
20
|
-
z
|
|
21
|
-
.object({
|
|
22
|
-
amount: z.number().int().finite(),
|
|
23
|
-
type: z.literal('coin'),
|
|
24
|
-
})
|
|
25
|
-
.strict(),
|
|
20
|
+
actionIoCurrencySchema,
|
|
26
21
|
actionIoItemSchema,
|
|
27
22
|
])
|
|
28
23
|
|
|
29
|
-
export type ActionIo = z.output<typeof actionIoSchema>
|
|
30
|
-
|
|
31
24
|
export const actionPlaceSchema = z.discriminatedUnion('type', [
|
|
32
25
|
z
|
|
33
26
|
.object({
|
|
@@ -35,6 +28,12 @@ export const actionPlaceSchema = z.discriminatedUnion('type', [
|
|
|
35
28
|
type: z.literal('npc'),
|
|
36
29
|
})
|
|
37
30
|
.strict(),
|
|
31
|
+
z
|
|
32
|
+
.object({
|
|
33
|
+
type: z.literal('website'),
|
|
34
|
+
url: z.string().url(),
|
|
35
|
+
})
|
|
36
|
+
.strict(),
|
|
38
37
|
z
|
|
39
38
|
.object({
|
|
40
39
|
grid: z.array(actionIoItemSchema.nullable()).length(9),
|
|
@@ -50,5 +49,3 @@ export const actionSchema = z
|
|
|
50
49
|
place: z.array(actionPlaceSchema),
|
|
51
50
|
})
|
|
52
51
|
.strict()
|
|
53
|
-
|
|
54
|
-
export type Action = z.output<typeof actionSchema>
|
package/source/types.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import {
|
|
3
|
+
actionIoCurrencySchema,
|
|
4
|
+
actionIoItemSchema,
|
|
5
|
+
actionIoSchema,
|
|
6
|
+
actionSchema,
|
|
7
|
+
} from './schema'
|
|
8
|
+
|
|
9
|
+
export type Action = z.output<typeof actionSchema>
|
|
10
|
+
export type ActionCurrency = z.output<typeof actionIoCurrencySchema.shape.id>
|
|
11
|
+
export type ActionIo = z.output<typeof actionIoSchema>
|
|
12
|
+
export type ActionIoCurrency = z.output<typeof actionIoCurrencySchema>
|
|
13
|
+
export type ActionIoItem = z.output<typeof actionIoItemSchema>
|