-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from dappnode/pablo/sdk-exports-index
Export from main `index.js`
- Loading branch information
Showing
13 changed files
with
154 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,6 @@ | ||
import { buildHandler } from "./commands/build.js"; | ||
import { fromGithubHandler } from "./commands/from_github.js"; | ||
import { increaseHandler } from "./commands/increase.js"; | ||
import { initHandler } from "./commands/init.js"; | ||
import { nextHandler } from "./commands/next.js"; | ||
import { publishHanlder } from "./commands/publish.js"; | ||
|
||
export const dappnodesdk = { | ||
build: buildHandler, | ||
fromGithub: fromGithubHandler, | ||
increase: increaseHandler, | ||
init: initHandler, | ||
next: nextHandler, | ||
publish: publishHanlder | ||
}; | ||
export * from "./params.js"; | ||
export * from "./types.js"; | ||
export { validateManifestSchema } from "./schemaValidation/validateManifestSchema.js"; | ||
export { validateDappnodeCompose } from "./files/compose/validateDappnodeCompose.js"; | ||
// The setupWizard file is not mandatory and may not be present, rn is used the filesystem | ||
// module, so it cannot be imported in browser side apps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Ajv from "ajv"; | ||
import ajvErrors from "ajv-errors"; | ||
|
||
export const ajv = new Ajv({ | ||
logger: false, | ||
allErrors: true, | ||
coerceTypes: true, | ||
strictSchema: false, | ||
allowUnionTypes: true | ||
}); | ||
|
||
ajvErrors.default(ajv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from "././validateSchema.js"; | ||
export { validateComposeSchema } from "./validateComposeSchema.js"; | ||
export { validateManifestSchema } from "./validateManifestSchema.js"; | ||
export { validateSetupWizardSchema } from "./validateSetupWizardSchema.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { ErrorObject } from "ajv"; | ||
|
||
// validate.errors = [ | ||
// { | ||
// keyword: "pattern", | ||
// dataPath: "/avatar", | ||
// schemaPath: "#/properties/avatar/pattern", | ||
// params: { pattern: "^/(ipfs|bzz)/w+$" }, | ||
// message: 'should match pattern "^/(ipfs|bzz)/w+$"' | ||
// }, | ||
// { | ||
// keyword: "pattern", | ||
// dataPath: "/image/hash", | ||
// schemaPath: "#/properties/image/properties/hash/pattern", | ||
// params: { pattern: "^/(ipfs|bzz)/w+$" }, | ||
// message: 'should match pattern "^/(ipfs|bzz)/w+$"' | ||
// }, | ||
// { | ||
// keyword: "type", | ||
// dataPath: "/image/size", | ||
// schemaPath: "#/properties/image/properties/size/type", | ||
// params: { type: "number" }, | ||
// message: "should be number" | ||
// }, | ||
// { | ||
// keyword: "pattern", | ||
// dataPath: "/image/size", | ||
// schemaPath: "#/properties/image/properties/size/pattern", | ||
// params: { pattern: "^d+$" }, | ||
// message: 'should match pattern "^d+$"' | ||
// }, | ||
// { | ||
// keyword: "required", | ||
// dataPath: "", | ||
// schemaPath: "#/required", | ||
// params: { missingProperty: "license" }, | ||
// message: "should have required property 'license'" | ||
// } | ||
// ]; | ||
|
||
/** | ||
* | ||
* @param errorObject from AJV: | ||
* { | ||
* keyword: "pattern", | ||
* dataPath: "/avatar", | ||
* schemaPath: "#/properties/avatar/pattern", | ||
* params: { pattern: "^/(ipfs|bzz)/w+$" }, | ||
* message: 'should match pattern "^/(ipfs|bzz)/w+$"' | ||
* } | ||
* @returns errorMessage: | ||
* "manifest.avatar should match pattern "^/(ipfs|bzz)/w+$"" | ||
*/ | ||
export function processError( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
errorObject: ErrorObject<string, Record<string, any>, unknown>, | ||
releaseFileType: "compose" | "manifest" | "setupWizard" | ||
): string { | ||
const { schemaPath, message } = errorObject; | ||
const path = `${releaseFileType}${schemaPath}`.replace( | ||
new RegExp("/", "g"), | ||
"." | ||
); | ||
return `${path} ${message}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { CliError } from "../params.js"; | ||
import { shell } from "../utils/shell.js"; | ||
import fs from "fs"; | ||
|
||
/** | ||
* Validates compose file with docker-compose config | ||
* @param compose | ||
*/ | ||
export async function validateComposeSchema( | ||
composeFilePath: string | ||
): Promise<void> { | ||
if (!fs.existsSync(composeFilePath)) | ||
throw Error(`Compose file ${composeFilePath} not found`); | ||
await shell(`docker-compose -f ${composeFilePath} config`).catch(e => { | ||
throw new CliError(`Invalid compose:\n${e.stderr}`); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ajv } from "./ajv.js"; | ||
import { CliError } from "../params.js"; | ||
import { Manifest } from "../types.js"; | ||
import { processError } from "./utils.js"; | ||
import manifestSchema from "./schemas/manifest.schema.json" assert { type: "json" }; | ||
|
||
/** | ||
* Validates manifest file with schema | ||
* @param manifest | ||
*/ | ||
export function validateManifestSchema(manifest: Manifest): void { | ||
const validateManifest = ajv.compile(manifestSchema); | ||
const valid = validateManifest(manifest); | ||
if (!valid) { | ||
const errors = validateManifest.errors | ||
? validateManifest.errors.map(e => processError(e, "manifest")) | ||
: []; | ||
throw new CliError( | ||
`Invalid manifest: \n${errors.map(msg => ` - ${msg}`).join("\n")}` | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ajv } from "./ajv.js"; | ||
import { readSetupWizardIfExists } from "../files/index.js"; | ||
import { CliError } from "../params.js"; | ||
import { processError } from "./utils.js"; | ||
import setupWizardSchema from "./schemas/setup-wizard.schema.json" assert { type: "json" }; | ||
|
||
/** | ||
* Validates setupWizard file with schema | ||
* @param setupWizard | ||
*/ | ||
export function validateSetupWizardSchema(dir?: string): void { | ||
// The setupwizard file is not mandatory and may not be present | ||
const setupWizard = readSetupWizardIfExists(dir); | ||
if (!setupWizard) return; | ||
const validateSetupWizard = ajv.compile(setupWizardSchema); | ||
const valid = validateSetupWizard(setupWizard); | ||
if (!valid) { | ||
const errors = validateSetupWizard.errors | ||
? validateSetupWizard.errors.map(e => processError(e, "setupWizard")) | ||
: []; | ||
throw new CliError( | ||
`Invalid setupWizard: \n${errors.map(msg => ` - ${msg}`).join("\n")}` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters