-
Notifications
You must be signed in to change notification settings - Fork 0
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 #25 from hypercerts-org/feat/geojson_support_metadata
Support for geoJSON in metadata
- Loading branch information
Showing
20 changed files
with
1,077 additions
and
136 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import globals from "globals"; | ||
import pluginJs from "@eslint/js"; | ||
import tseslint from "typescript-eslint"; | ||
|
||
|
||
export default [ | ||
{ files: ["**/*.{js,mjs,cjs,ts}"] }, | ||
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } }, | ||
pluginJs.configs.recommended, | ||
...tseslint.configs.recommended, | ||
]; | ||
export default { | ||
root: true, | ||
env: { | ||
browser: true, | ||
node: true, | ||
}, | ||
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:chai-friendly/recommended"], | ||
parser: "@typescript-eslint/parser", | ||
plugins: ["@typescript-eslint", "chai-friendly"], | ||
rules: { | ||
"no-unused-expressions": "off", | ||
"chai-friendly/no-unused-expressions": "error", | ||
}, | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,29 @@ | ||
import { HypercertMetadata, HypercertClaimdata, AllowlistEntry } from "src/types"; | ||
import { IValidator } from "./interfaces"; | ||
import { MerkleProofData, MerkleProofValidator } from "./validators/MerkleProofValidator"; | ||
import { MetadataValidator, ClaimDataValidator } from "./validators/MetadataValidator"; | ||
import { AllowlistValidator } from "./validators/AllowListValidator"; | ||
import { AllowlistValidationParams } from "./validators/AllowListValidator"; | ||
import { PropertyValidator, PropertyValue } from "./validators/PropertyValidator"; | ||
|
||
export class ValidatorFactory { | ||
static createMetadataValidator(): IValidator<HypercertMetadata> { | ||
return new MetadataValidator(); | ||
} | ||
|
||
static createClaimDataValidator(): IValidator<HypercertClaimdata> { | ||
return new ClaimDataValidator(); | ||
} | ||
|
||
static createAllowlistValidator(): IValidator<AllowlistEntry[], AllowlistValidationParams> { | ||
return new AllowlistValidator(); | ||
} | ||
|
||
static createMerkleProofValidator(): IValidator<MerkleProofData> { | ||
return new MerkleProofValidator(); | ||
} | ||
|
||
static createPropertyValidator(): IValidator<PropertyValue> { | ||
return new PropertyValidator(); | ||
} | ||
} |
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,40 @@ | ||
import Ajv, { Schema, ErrorObject } from "ajv"; | ||
import { IValidator, ValidationError, ValidationResult } from "../interfaces"; | ||
|
||
export abstract class SchemaValidator<T> implements IValidator<T> { | ||
protected ajv: Ajv; | ||
protected schema: Schema; | ||
|
||
constructor(schema: Schema, additionalSchemas: Schema[] = []) { | ||
this.ajv = new Ajv({ allErrors: true }); | ||
// Add any additional schemas first | ||
additionalSchemas.forEach((schema) => this.ajv.addSchema(schema)); | ||
this.schema = schema; | ||
} | ||
|
||
validate(data: unknown): ValidationResult<T> { | ||
const validate = this.ajv.compile(this.schema); | ||
|
||
if (!validate(data)) { | ||
return { | ||
isValid: false, | ||
errors: this.formatErrors(validate.errors || []), | ||
}; | ||
} | ||
|
||
return { | ||
isValid: true, | ||
data: data as T, | ||
errors: [], | ||
}; | ||
} | ||
|
||
protected formatErrors(errors: ErrorObject[]): ValidationError[] { | ||
return errors.map((error) => ({ | ||
code: "SCHEMA_VALIDATION_ERROR", | ||
message: error.message || "Unknown validation error", | ||
field: error.instancePath || (error.params.missingProperty as string) || "", | ||
details: error.params, | ||
})); | ||
} | ||
} |
Oops, something went wrong.