@0xtorch/csv 0.0.14 → 0.0.16
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/_cjs/index.js +7 -3
- package/_cjs/index.js.map +1 -1
- package/_cjs/{parseCsvFileToAccountActions.js → parseCsvFileToActions.js} +11 -11
- package/_cjs/parseCsvFileToActions.js.map +1 -0
- package/_cjs/parseRowsToActions/allValue.js +54 -0
- package/_cjs/parseRowsToActions/allValue.js.map +1 -0
- package/_cjs/parseRowsToActions/asset.js +95 -0
- package/_cjs/parseRowsToActions/asset.js.map +1 -0
- package/_cjs/parseRowsToActions/cellValue.js +8 -0
- package/_cjs/parseRowsToActions/cellValue.js.map +1 -0
- package/_cjs/parseRowsToActions/index.js +74 -0
- package/_cjs/parseRowsToActions/index.js.map +1 -0
- package/_cjs/parseRowsToActions/joinValue.js +52 -0
- package/_cjs/parseRowsToActions/joinValue.js.map +1 -0
- package/_cjs/parseRowsToActions/key.js +8 -0
- package/_cjs/parseRowsToActions/key.js.map +1 -0
- package/_cjs/parseRowsToActions/mathValue.js +123 -0
- package/_cjs/parseRowsToActions/mathValue.js.map +1 -0
- package/_cjs/parseRowsToActions/parse.js +72 -0
- package/_cjs/parseRowsToActions/parse.js.map +1 -0
- package/_cjs/parseRowsToActions/pattern.js +27 -0
- package/_cjs/parseRowsToActions/pattern.js.map +1 -0
- package/_cjs/parseRowsToActions/simpleValue.js +22 -0
- package/_cjs/parseRowsToActions/simpleValue.js.map +1 -0
- package/_cjs/parseRowsToActions/sliceValue.js +35 -0
- package/_cjs/parseRowsToActions/sliceValue.js.map +1 -0
- package/_cjs/parseRowsToActions/splitValue.js +11 -0
- package/_cjs/parseRowsToActions/splitValue.js.map +1 -0
- package/_cjs/parseRowsToActions/transfer.js +110 -0
- package/_cjs/parseRowsToActions/transfer.js.map +1 -0
- package/_cjs/schemas/{schemas.js → format.js} +2 -2
- package/_cjs/schemas/format.js.map +1 -0
- package/_cjs/schemas/index.js +2 -2
- package/_cjs/schemas/index.js.map +1 -1
- package/_cjs/schemas/parser.js +117 -72
- package/_cjs/schemas/parser.js.map +1 -1
- package/_esm/index.js +3 -1
- package/_esm/index.js.map +1 -1
- package/_esm/{parseCsvFileToAccountActions.js → parseCsvFileToActions.js} +9 -9
- package/_esm/parseCsvFileToActions.js.map +1 -0
- package/_esm/parseRowsToActions/allValue.js +50 -0
- package/_esm/parseRowsToActions/allValue.js.map +1 -0
- package/_esm/parseRowsToActions/asset.js +89 -0
- package/_esm/parseRowsToActions/asset.js.map +1 -0
- package/_esm/parseRowsToActions/cellValue.js +4 -0
- package/_esm/parseRowsToActions/cellValue.js.map +1 -0
- package/_esm/parseRowsToActions/index.js +72 -0
- package/_esm/parseRowsToActions/index.js.map +1 -0
- package/_esm/parseRowsToActions/joinValue.js +48 -0
- package/_esm/parseRowsToActions/joinValue.js.map +1 -0
- package/_esm/parseRowsToActions/key.js +4 -0
- package/_esm/parseRowsToActions/key.js.map +1 -0
- package/_esm/parseRowsToActions/mathValue.js +119 -0
- package/_esm/parseRowsToActions/mathValue.js.map +1 -0
- package/_esm/parseRowsToActions/parse.js +70 -0
- package/_esm/parseRowsToActions/parse.js.map +1 -0
- package/_esm/parseRowsToActions/pattern.js +23 -0
- package/_esm/parseRowsToActions/pattern.js.map +1 -0
- package/_esm/parseRowsToActions/simpleValue.js +18 -0
- package/_esm/parseRowsToActions/simpleValue.js.map +1 -0
- package/_esm/parseRowsToActions/sliceValue.js +31 -0
- package/_esm/parseRowsToActions/sliceValue.js.map +1 -0
- package/_esm/parseRowsToActions/splitValue.js +7 -0
- package/_esm/parseRowsToActions/splitValue.js.map +1 -0
- package/_esm/parseRowsToActions/transfer.js +106 -0
- package/_esm/parseRowsToActions/transfer.js.map +1 -0
- package/_esm/schemas/{schemas.js → format.js} +3 -3
- package/_esm/schemas/format.js.map +1 -0
- package/_esm/schemas/index.js +1 -1
- package/_esm/schemas/index.js.map +1 -1
- package/_esm/schemas/parser.js +126 -93
- package/_esm/schemas/parser.js.map +1 -1
- package/_types/index.d.ts +3 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/parseCsvFileToActions.d.ts +14 -0
- package/_types/parseCsvFileToActions.d.ts.map +1 -0
- package/_types/parseRowsToActions/allValue.d.ts +9 -0
- package/_types/parseRowsToActions/allValue.d.ts.map +1 -0
- package/_types/parseRowsToActions/asset.d.ts +30 -0
- package/_types/parseRowsToActions/asset.d.ts.map +1 -0
- package/_types/parseRowsToActions/cellValue.d.ts +8 -0
- package/_types/parseRowsToActions/cellValue.d.ts.map +1 -0
- package/_types/parseRowsToActions/index.d.ts +18 -0
- package/_types/parseRowsToActions/index.d.ts.map +1 -0
- package/_types/parseRowsToActions/joinValue.d.ts +9 -0
- package/_types/parseRowsToActions/joinValue.d.ts.map +1 -0
- package/_types/parseRowsToActions/key.d.ts +8 -0
- package/_types/parseRowsToActions/key.d.ts.map +1 -0
- package/_types/parseRowsToActions/mathValue.d.ts +10 -0
- package/_types/parseRowsToActions/mathValue.d.ts.map +1 -0
- package/_types/parseRowsToActions/parse.d.ts +17 -0
- package/_types/parseRowsToActions/parse.d.ts.map +1 -0
- package/_types/parseRowsToActions/pattern.d.ts +7 -0
- package/_types/parseRowsToActions/pattern.d.ts.map +1 -0
- package/_types/parseRowsToActions/simpleValue.d.ts +9 -0
- package/_types/parseRowsToActions/simpleValue.d.ts.map +1 -0
- package/_types/parseRowsToActions/sliceValue.d.ts +9 -0
- package/_types/parseRowsToActions/sliceValue.d.ts.map +1 -0
- package/_types/parseRowsToActions/splitValue.d.ts +9 -0
- package/_types/parseRowsToActions/splitValue.d.ts.map +1 -0
- package/_types/parseRowsToActions/transfer.d.ts +15 -0
- package/_types/parseRowsToActions/transfer.d.ts.map +1 -0
- package/_types/schemas/format.d.ts +35204 -0
- package/_types/schemas/format.d.ts.map +1 -0
- package/_types/schemas/index.d.ts +1 -1
- package/_types/schemas/index.d.ts.map +1 -1
- package/_types/schemas/parser.d.ts +78521 -916
- package/_types/schemas/parser.d.ts.map +1 -1
- package/_types/types.d.ts +2 -2
- package/_types/types.d.ts.map +1 -1
- package/index.ts +3 -1
- package/package.json +1 -1
- package/parseCsvFileToActions.ts +52 -0
- package/parseRowsToActions/allValue.ts +61 -0
- package/parseRowsToActions/asset.ts +152 -0
- package/parseRowsToActions/cellValue.ts +13 -0
- package/parseRowsToActions/index.ts +115 -0
- package/parseRowsToActions/joinValue.ts +68 -0
- package/parseRowsToActions/key.ts +13 -0
- package/parseRowsToActions/mathValue.ts +160 -0
- package/parseRowsToActions/parse.ts +108 -0
- package/parseRowsToActions/pattern.ts +35 -0
- package/parseRowsToActions/simpleValue.ts +29 -0
- package/parseRowsToActions/sliceValue.ts +51 -0
- package/parseRowsToActions/splitValue.ts +18 -0
- package/parseRowsToActions/transfer.ts +167 -0
- package/schemas/{schemas.ts → format.ts} +2 -2
- package/schemas/index.ts +1 -1
- package/schemas/parser.ts +143 -93
- package/tests/assets.ts +2 -1
- package/tests/coincheck-standard.csv +0 -10
- package/tests/coincheck.ts +196 -106
- package/types.ts +2 -2
- package/_cjs/parseCsvFileToAccountActions.js.map +0 -1
- package/_cjs/parseCsvRowToAction/amount.js +0 -48
- package/_cjs/parseCsvRowToAction/amount.js.map +0 -1
- package/_cjs/parseCsvRowToAction/asset.js +0 -63
- package/_cjs/parseCsvRowToAction/asset.js.map +0 -1
- package/_cjs/parseCsvRowToAction/condition.js +0 -32
- package/_cjs/parseCsvRowToAction/condition.js.map +0 -1
- package/_cjs/parseCsvRowToAction/index.js +0 -6
- package/_cjs/parseCsvRowToAction/index.js.map +0 -1
- package/_cjs/parseCsvRowToAction/nft.js +0 -16
- package/_cjs/parseCsvRowToAction/nft.js.map +0 -1
- package/_cjs/parseCsvRowToAction/parseCsvRowToAction.js +0 -79
- package/_cjs/parseCsvRowToAction/parseCsvRowToAction.js.map +0 -1
- package/_cjs/parseCsvRowToAction/text.js +0 -29
- package/_cjs/parseCsvRowToAction/text.js.map +0 -1
- package/_cjs/parseCsvRowToAction/timestamp.js +0 -12
- package/_cjs/parseCsvRowToAction/timestamp.js.map +0 -1
- package/_cjs/parseCsvRowToAction/transfer.js +0 -25
- package/_cjs/parseCsvRowToAction/transfer.js.map +0 -1
- package/_cjs/parseCsvRowsToActions.js +0 -34
- package/_cjs/parseCsvRowsToActions.js.map +0 -1
- package/_cjs/schemas/schemas.js.map +0 -1
- package/_esm/parseCsvFileToAccountActions.js.map +0 -1
- package/_esm/parseCsvRowToAction/amount.js +0 -44
- package/_esm/parseCsvRowToAction/amount.js.map +0 -1
- package/_esm/parseCsvRowToAction/asset.js +0 -59
- package/_esm/parseCsvRowToAction/asset.js.map +0 -1
- package/_esm/parseCsvRowToAction/condition.js +0 -28
- package/_esm/parseCsvRowToAction/condition.js.map +0 -1
- package/_esm/parseCsvRowToAction/index.js +0 -2
- package/_esm/parseCsvRowToAction/index.js.map +0 -1
- package/_esm/parseCsvRowToAction/nft.js +0 -12
- package/_esm/parseCsvRowToAction/nft.js.map +0 -1
- package/_esm/parseCsvRowToAction/parseCsvRowToAction.js +0 -77
- package/_esm/parseCsvRowToAction/parseCsvRowToAction.js.map +0 -1
- package/_esm/parseCsvRowToAction/text.js +0 -25
- package/_esm/parseCsvRowToAction/text.js.map +0 -1
- package/_esm/parseCsvRowToAction/timestamp.js +0 -8
- package/_esm/parseCsvRowToAction/timestamp.js.map +0 -1
- package/_esm/parseCsvRowToAction/transfer.js +0 -21
- package/_esm/parseCsvRowToAction/transfer.js.map +0 -1
- package/_esm/parseCsvRowsToActions.js +0 -32
- package/_esm/parseCsvRowsToActions.js.map +0 -1
- package/_esm/schemas/schemas.js.map +0 -1
- package/_types/parseCsvFileToAccountActions.d.ts +0 -14
- package/_types/parseCsvFileToAccountActions.d.ts.map +0 -1
- package/_types/parseCsvRowToAction/amount.d.ts +0 -11
- package/_types/parseCsvRowToAction/amount.d.ts.map +0 -1
- package/_types/parseCsvRowToAction/asset.d.ts +0 -17
- package/_types/parseCsvRowToAction/asset.d.ts.map +0 -1
- package/_types/parseCsvRowToAction/condition.d.ts +0 -10
- package/_types/parseCsvRowToAction/condition.d.ts.map +0 -1
- package/_types/parseCsvRowToAction/index.d.ts +0 -2
- package/_types/parseCsvRowToAction/index.d.ts.map +0 -1
- package/_types/parseCsvRowToAction/nft.d.ts +0 -12
- package/_types/parseCsvRowToAction/nft.d.ts.map +0 -1
- package/_types/parseCsvRowToAction/parseCsvRowToAction.d.ts +0 -16
- package/_types/parseCsvRowToAction/parseCsvRowToAction.d.ts.map +0 -1
- package/_types/parseCsvRowToAction/text.d.ts +0 -11
- package/_types/parseCsvRowToAction/text.d.ts.map +0 -1
- package/_types/parseCsvRowToAction/timestamp.d.ts +0 -8
- package/_types/parseCsvRowToAction/timestamp.d.ts.map +0 -1
- package/_types/parseCsvRowToAction/transfer.d.ts +0 -18
- package/_types/parseCsvRowToAction/transfer.d.ts.map +0 -1
- package/_types/parseCsvRowsToActions.d.ts +0 -16
- package/_types/parseCsvRowsToActions.d.ts.map +0 -1
- package/_types/schemas/schemas.d.ts +0 -593
- package/_types/schemas/schemas.d.ts.map +0 -1
- package/parseCsvFileToAccountActions.ts +0 -52
- package/parseCsvRowToAction/amount.ts +0 -66
- package/parseCsvRowToAction/asset.ts +0 -93
- package/parseCsvRowToAction/condition.ts +0 -39
- package/parseCsvRowToAction/index.ts +0 -1
- package/parseCsvRowToAction/nft.ts +0 -28
- package/parseCsvRowToAction/parseCsvRowToAction.ts +0 -128
- package/parseCsvRowToAction/text.ts +0 -38
- package/parseCsvRowToAction/timestamp.ts +0 -19
- package/parseCsvRowToAction/transfer.ts +0 -48
- package/parseCsvRowsToActions.ts +0 -54
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type BigDecimal,
|
|
3
|
-
absoluteValue,
|
|
4
|
-
divide,
|
|
5
|
-
minus,
|
|
6
|
-
plus,
|
|
7
|
-
times,
|
|
8
|
-
} from '@0xtorch/big-decimal'
|
|
9
|
-
import type { z } from 'zod'
|
|
10
|
-
import type { amountComponentSchema } from '../schemas/parser'
|
|
11
|
-
import type { FormattedRow } from '../types'
|
|
12
|
-
|
|
13
|
-
type CreateAmountByComponentParameters = {
|
|
14
|
-
readonly row: FormattedRow
|
|
15
|
-
readonly component: z.infer<typeof amountComponentSchema>
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const createAmountByComponent = ({
|
|
19
|
-
row,
|
|
20
|
-
component,
|
|
21
|
-
}: CreateAmountByComponentParameters): BigDecimal => {
|
|
22
|
-
if (typeof component === 'string') {
|
|
23
|
-
return getColumnAbsAmount(row, component)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
switch (component.type) {
|
|
27
|
-
case 'plus': {
|
|
28
|
-
let amount = getColumnAbsAmount(row, component.columns[0])
|
|
29
|
-
for (const column of component.columns.slice(1)) {
|
|
30
|
-
amount = plus(amount, getColumnAbsAmount(row, column))
|
|
31
|
-
}
|
|
32
|
-
return amount
|
|
33
|
-
}
|
|
34
|
-
case 'minus': {
|
|
35
|
-
let amount = getColumnAbsAmount(row, component.columns[0])
|
|
36
|
-
for (const column of component.columns.slice(1)) {
|
|
37
|
-
amount = minus(amount, getColumnAbsAmount(row, column))
|
|
38
|
-
}
|
|
39
|
-
return amount
|
|
40
|
-
}
|
|
41
|
-
case 'times': {
|
|
42
|
-
let amount = getColumnAbsAmount(row, component.columns[0])
|
|
43
|
-
for (const column of component.columns.slice(1)) {
|
|
44
|
-
amount = times(amount, getColumnAbsAmount(row, column), 18)
|
|
45
|
-
}
|
|
46
|
-
return amount
|
|
47
|
-
}
|
|
48
|
-
case 'divide': {
|
|
49
|
-
let amount = getColumnAbsAmount(row, component.columns[0])
|
|
50
|
-
for (const column of component.columns.slice(1)) {
|
|
51
|
-
amount = divide(amount, getColumnAbsAmount(row, column), 18)
|
|
52
|
-
}
|
|
53
|
-
return amount
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const getColumnAbsAmount = (row: FormattedRow, column: string): BigDecimal => {
|
|
59
|
-
const amount = row[column]
|
|
60
|
-
if (typeof amount !== 'object') {
|
|
61
|
-
throw new TypeError(
|
|
62
|
-
`amount needs to be BigDecimal but got ${typeof amount}`,
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
return absoluteValue(amount)
|
|
66
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import type { CryptoCurrency, FiatCurrency, Nft } from '@0xtorch/core'
|
|
2
|
-
import type { z } from 'zod'
|
|
3
|
-
import type { assetComponentSchema } from '../schemas/parser'
|
|
4
|
-
import type { FormattedRow } from '../types'
|
|
5
|
-
import { createNftByNftComponent } from './nft'
|
|
6
|
-
|
|
7
|
-
type CreateAssetByComponentParameters = {
|
|
8
|
-
readonly row: FormattedRow
|
|
9
|
-
readonly service: string
|
|
10
|
-
readonly symbolAssetMap: { [symbol: string]: string } | undefined
|
|
11
|
-
readonly component: z.infer<typeof assetComponentSchema>
|
|
12
|
-
readonly cryptoCurrencies: readonly CryptoCurrency[]
|
|
13
|
-
readonly fiatCurrencies: readonly FiatCurrency[]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const createAssetByComponent = ({
|
|
17
|
-
row,
|
|
18
|
-
service,
|
|
19
|
-
symbolAssetMap,
|
|
20
|
-
component,
|
|
21
|
-
cryptoCurrencies,
|
|
22
|
-
fiatCurrencies,
|
|
23
|
-
}: CreateAssetByComponentParameters): CryptoCurrency | FiatCurrency | Nft => {
|
|
24
|
-
switch (component.type) {
|
|
25
|
-
case 'custom': {
|
|
26
|
-
switch (component.assetType) {
|
|
27
|
-
case 'CryptoCurrency': {
|
|
28
|
-
const asset = cryptoCurrencies.find(
|
|
29
|
-
(cryptoCurrency) => cryptoCurrency.id === component.assetId,
|
|
30
|
-
)
|
|
31
|
-
if (asset === undefined) {
|
|
32
|
-
throw new Error(`asset not found: ${component.assetId}`)
|
|
33
|
-
}
|
|
34
|
-
return asset
|
|
35
|
-
}
|
|
36
|
-
case 'FiatCurrency': {
|
|
37
|
-
const asset = fiatCurrencies.find(
|
|
38
|
-
(fiatCurrency) => fiatCurrency.id === component.assetId,
|
|
39
|
-
)
|
|
40
|
-
if (asset === undefined) {
|
|
41
|
-
throw new Error(`asset not found: ${component.assetId}`)
|
|
42
|
-
}
|
|
43
|
-
return asset
|
|
44
|
-
}
|
|
45
|
-
case 'Nft': {
|
|
46
|
-
return {
|
|
47
|
-
type: 'Nft',
|
|
48
|
-
id: component.assetId,
|
|
49
|
-
updatedAt: 0,
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
throw new Error('Not reachable')
|
|
54
|
-
}
|
|
55
|
-
case 'column': {
|
|
56
|
-
const symbol = row[component.column]
|
|
57
|
-
if (typeof symbol !== 'string') {
|
|
58
|
-
throw new TypeError(
|
|
59
|
-
`symbol needs to be string but got ${typeof symbol}`,
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
if (symbolAssetMap !== undefined && symbol in symbolAssetMap) {
|
|
63
|
-
const assetId = symbolAssetMap[symbol]
|
|
64
|
-
const asset = cryptoCurrencies.find(
|
|
65
|
-
(cryptoCurrency) => cryptoCurrency.id === assetId,
|
|
66
|
-
)
|
|
67
|
-
if (asset !== undefined) {
|
|
68
|
-
return asset
|
|
69
|
-
}
|
|
70
|
-
throw new Error(`asset not found: ${assetId}`)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const upperSymbol = symbol.toUpperCase()
|
|
74
|
-
const fiat = fiatCurrencies.find(
|
|
75
|
-
(fiatCurrency) => fiatCurrency.symbol.toUpperCase() === upperSymbol,
|
|
76
|
-
)
|
|
77
|
-
if (fiat !== undefined) {
|
|
78
|
-
return fiat
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const crypto = cryptoCurrencies.find(
|
|
82
|
-
(cryptoCurrency) => cryptoCurrency.symbol.toUpperCase() === upperSymbol,
|
|
83
|
-
)
|
|
84
|
-
if (crypto !== undefined) {
|
|
85
|
-
return crypto
|
|
86
|
-
}
|
|
87
|
-
throw new Error(`asset not found: ${symbol}`)
|
|
88
|
-
}
|
|
89
|
-
case 'nft': {
|
|
90
|
-
return createNftByNftComponent({ row, service, component })
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { z } from 'zod'
|
|
2
|
-
import type { conditionComponentSchema } from '../schemas/parser'
|
|
3
|
-
import type { FormattedRow } from '../types'
|
|
4
|
-
|
|
5
|
-
type MatchConditionParameters = {
|
|
6
|
-
readonly row: FormattedRow
|
|
7
|
-
readonly component: z.infer<typeof conditionComponentSchema>
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const matchCondition = ({
|
|
11
|
-
row,
|
|
12
|
-
component,
|
|
13
|
-
}: MatchConditionParameters): boolean => {
|
|
14
|
-
const { column, pattern } = component
|
|
15
|
-
const value = row[column]
|
|
16
|
-
if (typeof pattern === 'string' || typeof pattern === 'number') {
|
|
17
|
-
return value === pattern
|
|
18
|
-
}
|
|
19
|
-
switch (pattern.type) {
|
|
20
|
-
case 'defined': {
|
|
21
|
-
return value !== undefined
|
|
22
|
-
}
|
|
23
|
-
case 'undefined': {
|
|
24
|
-
return value === undefined
|
|
25
|
-
}
|
|
26
|
-
case 'in': {
|
|
27
|
-
if (value === undefined || typeof value === 'object') {
|
|
28
|
-
return false
|
|
29
|
-
}
|
|
30
|
-
return pattern.values.includes(value)
|
|
31
|
-
}
|
|
32
|
-
case 'not-in': {
|
|
33
|
-
if (value === undefined || typeof value === 'object') {
|
|
34
|
-
return false
|
|
35
|
-
}
|
|
36
|
-
return !pattern.values.includes(value)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { parseCsvRowToAction } from './parseCsvRowToAction'
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Nft } from '@0xtorch/core'
|
|
2
|
-
import type { z } from 'zod'
|
|
3
|
-
import type { nftComponentSchema } from '../schemas/parser'
|
|
4
|
-
import type { FormattedRow } from '../types'
|
|
5
|
-
import { createTextByComponent } from './text'
|
|
6
|
-
|
|
7
|
-
type CreateNftByNftComponentParameters = {
|
|
8
|
-
readonly row: FormattedRow
|
|
9
|
-
readonly service: string
|
|
10
|
-
readonly component: z.infer<typeof nftComponentSchema>
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const createNftByNftComponent = ({
|
|
14
|
-
row,
|
|
15
|
-
service,
|
|
16
|
-
component,
|
|
17
|
-
}: CreateNftByNftComponentParameters): Nft => {
|
|
18
|
-
const id = component.id
|
|
19
|
-
.map((idComponent) =>
|
|
20
|
-
createTextByComponent({ row, service, component: idComponent }),
|
|
21
|
-
)
|
|
22
|
-
.join('')
|
|
23
|
-
return {
|
|
24
|
-
type: 'Nft',
|
|
25
|
-
id,
|
|
26
|
-
updatedAt: 0,
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import type { Action, CryptoCurrency, FiatCurrency } from '@0xtorch/core'
|
|
2
|
-
import type { FormattedRow, Parser } from '../types'
|
|
3
|
-
import { matchCondition } from './condition'
|
|
4
|
-
import { createNftByNftComponent } from './nft'
|
|
5
|
-
import { createTextByComponent } from './text'
|
|
6
|
-
import { createTimestampByRow } from './timestamp'
|
|
7
|
-
import { createTransferByComponent } from './transfer'
|
|
8
|
-
|
|
9
|
-
type ParseCsvRowToActionParameters = {
|
|
10
|
-
readonly row: FormattedRow
|
|
11
|
-
readonly service: string
|
|
12
|
-
readonly parsers: readonly Parser[]
|
|
13
|
-
readonly symbolAssetMap: { [symbol: string]: string } | undefined
|
|
14
|
-
readonly accountId: string
|
|
15
|
-
readonly cryptoCurrencies: readonly CryptoCurrency[]
|
|
16
|
-
readonly fiatCurrencies: readonly FiatCurrency[]
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const parseCsvRowToAction = ({
|
|
20
|
-
row,
|
|
21
|
-
service,
|
|
22
|
-
parsers,
|
|
23
|
-
symbolAssetMap,
|
|
24
|
-
accountId,
|
|
25
|
-
cryptoCurrencies,
|
|
26
|
-
fiatCurrencies,
|
|
27
|
-
}: ParseCsvRowToActionParameters): Action | undefined => {
|
|
28
|
-
for (const parser of parsers) {
|
|
29
|
-
try {
|
|
30
|
-
const action = parseCsvRowToActionByParser({
|
|
31
|
-
row,
|
|
32
|
-
service,
|
|
33
|
-
parser,
|
|
34
|
-
symbolAssetMap,
|
|
35
|
-
accountId,
|
|
36
|
-
cryptoCurrencies,
|
|
37
|
-
fiatCurrencies,
|
|
38
|
-
})
|
|
39
|
-
if (action !== undefined) {
|
|
40
|
-
return action
|
|
41
|
-
}
|
|
42
|
-
} catch (error) {
|
|
43
|
-
// TODO 意図しないエラーは別途記録できるようにしたい
|
|
44
|
-
console.debug(error)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return undefined
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
type ParseCsvRowToActionByParserParameters = {
|
|
51
|
-
readonly row: FormattedRow
|
|
52
|
-
readonly service: string
|
|
53
|
-
readonly parser: Parser
|
|
54
|
-
readonly symbolAssetMap: { [symbol: string]: string } | undefined
|
|
55
|
-
readonly accountId: string
|
|
56
|
-
readonly cryptoCurrencies: readonly CryptoCurrency[]
|
|
57
|
-
readonly fiatCurrencies: readonly FiatCurrency[]
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const parseCsvRowToActionByParser = ({
|
|
61
|
-
row,
|
|
62
|
-
service,
|
|
63
|
-
parser,
|
|
64
|
-
symbolAssetMap,
|
|
65
|
-
accountId,
|
|
66
|
-
cryptoCurrencies,
|
|
67
|
-
fiatCurrencies,
|
|
68
|
-
}: ParseCsvRowToActionByParserParameters): Action | undefined => {
|
|
69
|
-
// 合致しない condition がある場合は undefined を返す
|
|
70
|
-
for (const condition of parser.conditions) {
|
|
71
|
-
if (!matchCondition({ row, component: condition })) {
|
|
72
|
-
return undefined
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
source: parser.source
|
|
78
|
-
.map((component) => createTextByComponent({ row, service, component }))
|
|
79
|
-
.join(''),
|
|
80
|
-
order: 0,
|
|
81
|
-
type: parser.action,
|
|
82
|
-
evidence: 'system-rule',
|
|
83
|
-
timestamp: createTimestampByRow({ row, column: parser.timestamp }),
|
|
84
|
-
comment:
|
|
85
|
-
parser.comment === undefined
|
|
86
|
-
? undefined
|
|
87
|
-
: parser.comment
|
|
88
|
-
.map((component) =>
|
|
89
|
-
createTextByComponent({ row, service, component }),
|
|
90
|
-
)
|
|
91
|
-
.join(''),
|
|
92
|
-
app: undefined,
|
|
93
|
-
transfers: parser.transfers
|
|
94
|
-
.map((component) =>
|
|
95
|
-
createTransferByComponent({
|
|
96
|
-
row,
|
|
97
|
-
service,
|
|
98
|
-
symbolAssetMap,
|
|
99
|
-
component,
|
|
100
|
-
accountId,
|
|
101
|
-
cryptoCurrencies,
|
|
102
|
-
fiatCurrencies,
|
|
103
|
-
}),
|
|
104
|
-
)
|
|
105
|
-
.filter(({ amount }) => amount.value > 0n),
|
|
106
|
-
crossId:
|
|
107
|
-
parser.crossId === undefined
|
|
108
|
-
? undefined
|
|
109
|
-
: parser.crossId
|
|
110
|
-
.map((component) =>
|
|
111
|
-
createTextByComponent({ row, service, component }),
|
|
112
|
-
)
|
|
113
|
-
.join(''),
|
|
114
|
-
crossType: parser.crossType,
|
|
115
|
-
loanId:
|
|
116
|
-
parser.loanId === undefined
|
|
117
|
-
? undefined
|
|
118
|
-
: parser.loanId
|
|
119
|
-
.map((component) =>
|
|
120
|
-
createTextByComponent({ row, service, component }),
|
|
121
|
-
)
|
|
122
|
-
.join(''),
|
|
123
|
-
target:
|
|
124
|
-
parser.target === undefined
|
|
125
|
-
? undefined
|
|
126
|
-
: createNftByNftComponent({ row, service, component: parser.target }),
|
|
127
|
-
}
|
|
128
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { toStringBigDecimal } from '@0xtorch/big-decimal'
|
|
2
|
-
import type { z } from 'zod'
|
|
3
|
-
import type { textComponentSchema } from '../schemas/parser'
|
|
4
|
-
import type { FormattedRow } from '../types'
|
|
5
|
-
|
|
6
|
-
type CreateTextByComponentParameters = {
|
|
7
|
-
readonly row: FormattedRow
|
|
8
|
-
readonly service: string
|
|
9
|
-
readonly component: z.infer<typeof textComponentSchema>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const createTextByComponent = ({
|
|
13
|
-
row,
|
|
14
|
-
service,
|
|
15
|
-
component,
|
|
16
|
-
}: CreateTextByComponentParameters): string => {
|
|
17
|
-
if (typeof component === 'string') {
|
|
18
|
-
return component
|
|
19
|
-
}
|
|
20
|
-
switch (component.type) {
|
|
21
|
-
case 'service': {
|
|
22
|
-
return service
|
|
23
|
-
}
|
|
24
|
-
case 'column': {
|
|
25
|
-
const value = row[component.column]
|
|
26
|
-
if (value === undefined) {
|
|
27
|
-
return ''
|
|
28
|
-
}
|
|
29
|
-
if (typeof value === 'string') {
|
|
30
|
-
return value
|
|
31
|
-
}
|
|
32
|
-
if (typeof value === 'number') {
|
|
33
|
-
return value.toString()
|
|
34
|
-
}
|
|
35
|
-
return toStringBigDecimal(value)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { FormattedRow } from '../types'
|
|
2
|
-
|
|
3
|
-
type CreateTimestampByRowParameters = {
|
|
4
|
-
readonly row: FormattedRow
|
|
5
|
-
readonly column: string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const createTimestampByRow = ({
|
|
9
|
-
row,
|
|
10
|
-
column,
|
|
11
|
-
}: CreateTimestampByRowParameters): number => {
|
|
12
|
-
const timestamp = row[column]
|
|
13
|
-
if (typeof timestamp !== 'number') {
|
|
14
|
-
throw new TypeError(
|
|
15
|
-
`timestamp needs to be number but got ${typeof timestamp}`,
|
|
16
|
-
)
|
|
17
|
-
}
|
|
18
|
-
return timestamp
|
|
19
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { CryptoCurrency, FiatCurrency, Transfer } from '@0xtorch/core'
|
|
2
|
-
import type { z } from 'zod'
|
|
3
|
-
import type { transferComponentSchema } from '../schemas/parser'
|
|
4
|
-
import type { FormattedRow } from '../types'
|
|
5
|
-
import { createAmountByComponent } from './amount'
|
|
6
|
-
import { createAssetByComponent } from './asset'
|
|
7
|
-
|
|
8
|
-
type CreateTransferByComponentParameters = {
|
|
9
|
-
readonly row: FormattedRow
|
|
10
|
-
readonly service: string
|
|
11
|
-
readonly symbolAssetMap: { [symbol: string]: string } | undefined
|
|
12
|
-
readonly component: z.infer<typeof transferComponentSchema>
|
|
13
|
-
readonly accountId: string
|
|
14
|
-
readonly cryptoCurrencies: readonly CryptoCurrency[]
|
|
15
|
-
readonly fiatCurrencies: readonly FiatCurrency[]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const createTransferByComponent = ({
|
|
19
|
-
row,
|
|
20
|
-
service,
|
|
21
|
-
symbolAssetMap,
|
|
22
|
-
component,
|
|
23
|
-
accountId,
|
|
24
|
-
cryptoCurrencies,
|
|
25
|
-
fiatCurrencies,
|
|
26
|
-
}: CreateTransferByComponentParameters): Transfer => {
|
|
27
|
-
const {
|
|
28
|
-
direction,
|
|
29
|
-
asset: assetComponent,
|
|
30
|
-
amount: amountComponent,
|
|
31
|
-
} = component
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
from: direction === 'in' ? undefined : accountId,
|
|
35
|
-
to: direction === 'in' ? accountId : undefined,
|
|
36
|
-
asset: createAssetByComponent({
|
|
37
|
-
row,
|
|
38
|
-
service,
|
|
39
|
-
symbolAssetMap,
|
|
40
|
-
component: assetComponent,
|
|
41
|
-
cryptoCurrencies,
|
|
42
|
-
fiatCurrencies,
|
|
43
|
-
}),
|
|
44
|
-
amount: createAmountByComponent({ row, component: amountComponent }),
|
|
45
|
-
price: undefined,
|
|
46
|
-
direction,
|
|
47
|
-
}
|
|
48
|
-
}
|
package/parseCsvRowsToActions.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { Action, CryptoCurrency, FiatCurrency } from '@0xtorch/core'
|
|
2
|
-
import { parseCsvRowToAction } from './parseCsvRowToAction'
|
|
3
|
-
import type { FormattedRow, Parser } from './types'
|
|
4
|
-
|
|
5
|
-
type ParseCsvRowsToActionsParameters = {
|
|
6
|
-
readonly rows: readonly FormattedRow[]
|
|
7
|
-
readonly service: string
|
|
8
|
-
readonly parsers: readonly Parser[]
|
|
9
|
-
readonly symbolAssetMap: { [symbol: string]: string } | undefined
|
|
10
|
-
readonly accountId: string
|
|
11
|
-
readonly cryptoCurrencies: readonly CryptoCurrency[]
|
|
12
|
-
readonly fiatCurrencies: readonly FiatCurrency[]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const parseCsvRowsToActions = ({
|
|
16
|
-
rows,
|
|
17
|
-
service,
|
|
18
|
-
parsers,
|
|
19
|
-
symbolAssetMap,
|
|
20
|
-
accountId,
|
|
21
|
-
cryptoCurrencies,
|
|
22
|
-
fiatCurrencies,
|
|
23
|
-
}: ParseCsvRowsToActionsParameters): readonly Action[] => {
|
|
24
|
-
// marketCap で降順 sort
|
|
25
|
-
const sortedCryptoCurrencies = cryptoCurrencies.toSorted(
|
|
26
|
-
(a, b) => (b.market?.marketCapUsd ?? -1) - (a.market?.marketCapUsd ?? -1),
|
|
27
|
-
)
|
|
28
|
-
const actions = rows.flatMap((row) => {
|
|
29
|
-
const action = parseCsvRowToAction({
|
|
30
|
-
row,
|
|
31
|
-
service,
|
|
32
|
-
parsers,
|
|
33
|
-
symbolAssetMap,
|
|
34
|
-
accountId,
|
|
35
|
-
cryptoCurrencies: sortedCryptoCurrencies,
|
|
36
|
-
fiatCurrencies,
|
|
37
|
-
})
|
|
38
|
-
if (action === undefined) {
|
|
39
|
-
// TODO action が生成できなかった行を記録したい
|
|
40
|
-
return []
|
|
41
|
-
}
|
|
42
|
-
return action
|
|
43
|
-
})
|
|
44
|
-
const mut_sources: string[] = []
|
|
45
|
-
const mut_actions: Action[] = []
|
|
46
|
-
for (const action of actions) {
|
|
47
|
-
mut_actions.push({
|
|
48
|
-
...action,
|
|
49
|
-
order: mut_sources.filter((source) => source === action.source).length,
|
|
50
|
-
})
|
|
51
|
-
mut_sources.push(action.source)
|
|
52
|
-
}
|
|
53
|
-
return mut_actions
|
|
54
|
-
}
|