Skip to content

Commit 2c1730f

Browse files
committed
fixes
1 parent a440134 commit 2c1730f

33 files changed

+29700
-29754
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"@typescript-eslint/no-unsafe-member-access": "off",
5959
"@typescript-eslint/no-unsafe-return": "off",
6060
"@typescript-eslint/no-useless-empty-export": "error",
61-
"@typescript-eslint/prefer-function-type": "error",
61+
"@typescript-eslint/prefer-function-type": "off",
6262
"no-array-constructor": "off",
6363
"@typescript-eslint/no-array-constructor": "error",
6464
"no-throw-literal": "off",

code/cli/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env node
22

33
import _ from 'lodash'
4-
import { Input, Value } from './type'
5-
import * as task from './task'
4+
import { Input, Value } from './type.js'
5+
import * as task from './task.js'
66

77
call(process.argv)
88

@@ -54,25 +54,25 @@ function call(argv: Array<string>) {
5454
function read(argv: Array<string>) {
5555
let i = 2
5656
const input: Input = {
57-
action: argv[i++],
57+
action: argv[i++] as string,
5858
object: [],
5959
detail: {},
6060
}
6161

6262
while (i < argv.length) {
63-
const item = argv[i++]
63+
const item = argv[i++] as string
6464
if (item.match(/^-+/)) {
6565
const name = item
6666
const cased = name.match(/^--/) ? _.camelCase(name) : name
67-
let value: Value = argv[i++]
67+
let value: Value = argv[i++] as string
6868
if (!value) {
6969
value = true
7070
} else if (value.match(/^-+/)) {
7171
i--
7272
value = true
7373
}
74-
input.detail[cased] = input.detail[cased] || []
75-
input.detail[cased].push(value)
74+
const detail = (input.detail[cased] = input.detail[cased] || [])
75+
detail.push(value)
7676
} else {
7777
input.object.push(item)
7878
}

code/cli/task.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ call:
2323
2424
`)
2525
} else {
26-
const call = (await import('../node')).default
26+
const call = (await import('../node/index.js')).default
2727
await call('convert', input)
2828
}
2929
}
@@ -32,21 +32,22 @@ function makeInput(source: Input, map: Record<string, Link>) {
3232
const out: Record<string, Value | Array<Value>> = {}
3333
for (const name in source.detail) {
3434
const form = map[name]
35-
const detail = source.detail[name].map(v => {
36-
switch (form?.like) {
37-
case 'string':
38-
return v
39-
case 'integer':
40-
return parseInt(v as string, 10)
41-
case 'decimal':
42-
return parseFloat(v as string)
43-
}
44-
return v
45-
})
35+
const detail =
36+
source.detail[name]?.map(v => {
37+
switch (form?.like) {
38+
case 'string':
39+
return v
40+
case 'integer':
41+
return parseInt(v as string, 10)
42+
case 'decimal':
43+
return parseFloat(v as string)
44+
}
45+
return v
46+
}) ?? []
4647
const val = form?.list ? detail : detail[0]
47-
if (form.name) {
48+
if (form?.name) {
4849
_.set(out, form.name, val)
49-
} else {
50+
} else if (val != null) {
5051
out[name] = val
5152
}
5253
}

code/node/archive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { exec } from './process'
1+
import { exec } from './process.js'
22
import archiver from 'archiver'
33
import fs from 'fs'
44

code/node/base.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { RefinementCtx, z } from 'zod'
2+
import { replaceFileExtension } from '../shared/tool'
3+
4+
export const transform_input_output_file =
5+
(a: string, b: string) => (v: any, ctx: RefinementCtx) => {
6+
if (!v.input.file.path.endsWith(`.${a}`)) {
7+
ctx.addIssue({
8+
code: z.ZodIssueCode.custom,
9+
message: `Input path must have extension .${a}`,
10+
path: ['input', 'file', 'path'],
11+
})
12+
}
13+
14+
if (!v.output.file.path) {
15+
if (!v.output.file.format) {
16+
ctx.addIssue({
17+
code: z.ZodIssueCode.custom,
18+
message: `Must specify a an output file path or format.`,
19+
path: ['output', 'file'],
20+
})
21+
} else if (v.output.file.format !== b) {
22+
ctx.addIssue({
23+
code: z.ZodIssueCode.custom,
24+
message: `Output format must be ${b}`,
25+
path: ['output', 'file', 'format'],
26+
})
27+
} else {
28+
v.output.file.path = replaceFileExtension(
29+
v.input.file.path as string,
30+
`.${v.output.file.format}`,
31+
)
32+
}
33+
} else if (!v.output.file.path.endsWith(`.${b}`)) {
34+
ctx.addIssue({
35+
code: z.ZodIssueCode.custom,
36+
message: `Output path must have extension .${b}`,
37+
path: ['output', 'file', 'path'],
38+
})
39+
}
40+
41+
return v
42+
}

code/node/code.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {
44
IOPath,
55
LLVM_ARCHITECTURE_CONTENT,
66
LlvmArchitecture,
7-
} from '../shared/type'
8-
import { exec } from './process'
7+
} from '../shared/index.js'
8+
import { exec } from './process.js'
99

1010
// CSharp: .cs
1111
// Java: .java
@@ -104,3 +104,11 @@ export async function runFormatCCommand(cmd: Array<string>) {
104104
await exec(cmd.join(' '))
105105
return cmd
106106
}
107+
108+
export async function runSwiftCommand(command: Array<string>) {
109+
return await exec(command.join(' '))
110+
}
111+
112+
export async function runClangCommand(command: Array<string>) {
113+
return await exec(command.join(' '))
114+
}

code/node/crypto.ts

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -31,57 +31,57 @@ export const generate_murmur_hash = {
3131
},
3232
}
3333

34-
export function generateMurmurHash(source: GenerateMurmurHash) {
35-
const { input, seed, version } = GenerateMurmurHashModel.parse(source)
36-
if (version === '2') {
37-
return murmurhash.v2(input, seed)
38-
}
39-
return murmurhash.v3(input, seed)
40-
}
34+
// export function generateMurmurHash(source: GenerateMurmurHash) {
35+
// const { input, seed, version } = GenerateMurmurHashModel.parse(source)
36+
// if (version === '2') {
37+
// return murmurhash.v2(input, seed)
38+
// }
39+
// return murmurhash.v3(input, seed)
40+
// }
4141

42-
export const get_random_bytes = {
43-
form: 'form',
44-
link: {
45-
size: { like: 'natural_number' },
46-
},
47-
}
42+
// export const get_random_bytes = {
43+
// form: 'form',
44+
// link: {
45+
// size: { like: 'natural_number' },
46+
// },
47+
// }
4848

49-
// var key = forge.random.getBytesSync(16)
50-
// var iv = forge.random.getBytesSync(16)
51-
export async function getRandomBytes(source: GetRandomBytes) {
52-
return new Promise((res, rej) => {
53-
return forge.random.getBytes(
54-
source.size,
55-
(err: Error | null, bytes) => {
56-
if (err) {
57-
return rej(err)
58-
}
59-
return res(bytes)
60-
},
61-
)
62-
})
63-
}
49+
// // var key = forge.random.getBytesSync(16)
50+
// // var iv = forge.random.getBytesSync(16)
51+
// export async function getRandomBytes(source: GetRandomBytes) {
52+
// return new Promise((res, rej) => {
53+
// return forge.random.getBytes(
54+
// source.size,
55+
// (err: Error | null, bytes) => {
56+
// if (err) {
57+
// return rej(err)
58+
// }
59+
// return res(bytes)
60+
// },
61+
// )
62+
// })
63+
// }
6464

65-
export const encrypt_bytes_with_aes = {
66-
form: 'form',
67-
link: {
68-
mode: { like: 'string' },
69-
},
70-
}
65+
// export const encrypt_bytes_with_aes = {
66+
// form: 'form',
67+
// link: {
68+
// mode: { like: 'string' },
69+
// },
70+
// }
7171

72-
export async function encryptBytesWithAes(source: EncryptBytesWithAes) {
73-
const cipher = forge.cipher.createCipher(`AES-${mode}`, key)
74-
cipher.start({ iv: iv })
75-
cipher.update(forge.util.createBuffer(input))
76-
cipher.finish()
77-
return cipher.output.bytes()
78-
}
72+
// export async function encryptBytesWithAes(source: EncryptBytesWithAes) {
73+
// const cipher = forge.cipher.createCipher(`AES-${mode}`, key)
74+
// cipher.start({ iv: iv })
75+
// cipher.update(forge.util.createBuffer(input))
76+
// cipher.finish()
77+
// return cipher.output.bytes()
78+
// }
7979

80-
export async function decryptBytesWithAes() {
81-
const decipher = forge.cipher.createDecipher(`AES-${mode}`, key)
82-
decipher.start({ iv: iv })
83-
decipher.update(input) // input == encryptedBytes
84-
if (decipher.finish()) {
85-
return decipher.output.bytes()
86-
}
87-
}
80+
// export async function decryptBytesWithAes() {
81+
// const decipher = forge.cipher.createDecipher(`AES-${mode}`, key)
82+
// decipher.start({ iv: iv })
83+
// decipher.update(input) // input == encryptedBytes
84+
// if (decipher.finish()) {
85+
// return decipher.output.bytes()
86+
// }
87+
// }

0 commit comments

Comments
 (0)