Skip to content

Commit cc4b0d6

Browse files
committed
validate manifest
1 parent fe7a408 commit cc4b0d6

File tree

10 files changed

+110
-29
lines changed

10 files changed

+110
-29
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# v0.4.12 (unreleased)
22
- fix: version number
3+
- feat: validate manifest when building and deploying
34

45
# v0.4.11
56
- fix: show error message when `arkive deploy` fails

cli/deploy/mod.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { parseArkiveManifest } from '../../mod.ts'
12
import { join, wait } from '../deps.ts'
23
import { cleanup } from './cleanup.ts'
34
import { pkg } from './pkg.ts'
45
import { upload } from './upload.ts'
56

67
export const action = async (
7-
options: { public?: true; major?: true, env?: string },
8+
options: { public?: true; major?: true; env?: string },
89
directory: string,
910
) => {
1011
const dev = options.env?.toLowerCase() === 'dev'
@@ -35,6 +36,11 @@ export const action = async (
3536
throw new Error(`Manifest must have a name property.`)
3637
}
3738

39+
const { problems } = parseArkiveManifest.manifest(manifest)
40+
if (problems) {
41+
throw new Error(`Invalid manifest: ${problems}`)
42+
}
43+
3844
spinner.text = 'Uploading package...'
3945
// upload package
4046
await upload(fileName, tempPath, manifest, options)

deno.lock

+46-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mod.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ export {
1616
JSONBigIntReplacer,
1717
JSONBigIntReviver,
1818
} from './src/utils.ts'
19+
export { parseArkiveManifest } from './src/arkiver/manifest-validator.ts'

src/arkiver/manifest-builder.ts

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
mongoose,
2020
} from '../deps.ts'
2121
import { getChainObjFromChainName } from '../utils.ts'
22+
import { parseArkiveManifest } from './manifest-validator.ts'
2223

2324
export const manifestVersion = 'v1'
2425

@@ -78,6 +79,11 @@ export class Manifest<TName extends string = ''> {
7879
}
7980

8081
public build() {
82+
const { problems } = parseArkiveManifest.manifest(this.manifest)
83+
if (problems) {
84+
throw new Error(`Invalid manifest: ${problems}`)
85+
}
86+
console.log(this.manifest)
8187
return this.manifest
8288
}
8389
}

src/arkiver/manifest-validator.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { supportedChains } from '../chains.ts'
2+
import { scope } from '../deps.ts'
3+
4+
export const parseArkiveManifest = scope({
5+
manifest: {
6+
name: 'string',
7+
'version?': /^v\d+$/,
8+
dataSources: Object.fromEntries(
9+
Object.keys(supportedChains).map((chain) => [`${chain}?`, 'dataSource']),
10+
) as Record<`${keyof typeof supportedChains}?`, 'dataSource'>,
11+
entities: 'entity[]',
12+
},
13+
dataSource: {
14+
options: 'chainOptions',
15+
'contracts?': 'contract[]',
16+
'blockHandlers?': 'blockHandler[]',
17+
},
18+
entity: {
19+
model: 'any',
20+
list: 'boolean',
21+
name: 'string',
22+
},
23+
chainOptions: {
24+
blockRange: 'bigint',
25+
rpcUrl: 'string',
26+
},
27+
contract: {
28+
id: 'string',
29+
abi: 'any[]',
30+
sources: 'source[]',
31+
events: 'eventSource[]',
32+
},
33+
blockHandler: {
34+
handler: 'Function',
35+
startBlockHeight: 'bigint|"live"',
36+
blockInterval: 'bigint',
37+
name: 'string',
38+
},
39+
source: {
40+
address: /^0x[a-fA-F0-9]{40}$/,
41+
startBlockHeight: 'bigint',
42+
},
43+
eventSource: {
44+
name: 'string',
45+
handler: 'Function',
46+
},
47+
}).compile()

src/deps.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export {
33
type Block,
44
createPublicClient,
55
decodeEventLog,
6+
type DecodeEventLogReturnType,
67
encodeEventTopics,
78
getContract,
89
type GetContractReturnType,
@@ -11,7 +12,6 @@ export {
1112
type Log,
1213
type PublicClient,
1314
type RpcLog,
14-
type DecodeEventLogReturnType
1515
} from 'npm:viem'
1616
export {
1717
type Abi,
@@ -33,3 +33,4 @@ export {
3333
ConsoleHandler,
3434
} from 'https://deno.land/std@0.181.0/log/handlers.ts'
3535
export { crypto } from 'https://deno.land/std@0.186.0/crypto/mod.ts'
36+
export { scope } from 'npm:arktype'

test-retries/.vscode/settings.json

-4
This file was deleted.

test-retries/deps.ts

-6
This file was deleted.

test-retries/manifest.ts

-15
This file was deleted.

0 commit comments

Comments
 (0)