Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/merge-conflicts #19

Merged
merged 15 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import globals from 'globals';
import pluginJs from '@eslint/js';
import prettierPlugin from 'eslint-plugin-prettier';
import jsonPlugin from 'eslint-plugin-json';

export default [
{
languageOptions: {
globals: globals.browser,
ecmaVersion: 2023,
sourceType: 'module'
},
parserOptions: {
requireConfigFile: false,
babelOptions: {
presets: ['@babel/preset-env']
}
}
},
pluginJs.configs.recommended,
prettierPlugin.configs.recommended,
jsonPlugin.configs.recommended,
{
settings: {
jest: {
version: 29
}
},
plugins: {
prettier: prettierPlugin,
json: jsonPlugin
},
rules: {
'prettier/prettier': ['error'],
}
}
];
41 changes: 21 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luca-financial/luca-schema",
"version": "1.0.6",
"version": "1.0.7",
"description": "Schemas for the Luca Ledger application",
"author": "Johnathan Aspinwall",
"main": "dist/index.js",
Expand Down Expand Up @@ -31,18 +31,6 @@
"publish-beta": "yarn && yarn build && yarn publish --tag beta --access public",
"test": "yarn build && jest"
},
"devDependencies": {
"@babel/cli": "^7.24.1",
"@babel/core": "^7.24.4",
"@babel/preset-env": "^7.24.4",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"babel-jest": "^29.7.0",
"fs-extra": "^11.2.0",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"rimraf": "^5.0.5"
},
"exports": {
".": {
"import": "./dist/esm/index.js",
Expand All @@ -54,13 +42,26 @@
}
},
"files": [
"dist/cjs/index.js",
"dist/cjs/validators.js",
"dist/cjs/schemas/",
"dist/esm/index.js",
"dist/esm/validators.js",
"dist/esm/schemas/",
"dist/",
"LICENSE",
"README.md"
]
],
"devDependencies": {
"@babel/cli": "^7.24.1",
"@babel/core": "^7.24.4",
"@babel/preset-env": "^7.24.4",
"@eslint/js": "^9.1.1",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"babel-jest": "^29.7.0",
"eslint": "^9.1.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-prettier": "^5.1.3",
"fs-extra": "^11.2.0",
"globals": "^15.1.0",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"rimraf": "^5.0.5"
}
}
46 changes: 29 additions & 17 deletions scripts/buildEsm.cjs
Original file line number Diff line number Diff line change
@@ -1,46 +1,58 @@
const fs = require("fs-extra");
const fs = require('fs-extra');

const config = require("./config.cjs");
const config = require('./config.cjs');

const {
schemasSrc,
enumsSrc,
indexSrc,
validatorsSrc,
validatorSrc,
esmEnumsDst,
esmIndexDst,
esmValidatorsDst,
esmSchemasDst,
esmValidatorDst,
esmSchemasDst
} = config;

const copyEnums = async () => {
return fs
.copy(enumsSrc, esmEnumsDst)
.then(() => console.log('Copy enums.js completed!'))
.catch(err =>
console.error('An error occurred while copying enums.js', err)
);
};

const copyIndex = async () => {
return fs
.copy(indexSrc, esmIndexDst)
.then(() => console.log("Copy index.js completed!"))
.catch((err) =>
console.error("An error occurred while copying index.js", err)
.then(() => console.log('Copy index.js completed!'))
.catch(err =>
console.error('An error occurred while copying index.js', err)
);
};

const copyValidators = async () => {
const copyValidator = async () => {
return fs
.copy(validatorsSrc, esmValidatorsDst)
.then(() => console.log("Copy validators.js completed!"))
.catch((err) =>
console.error("An error occurred while copying validators.js", err)
.copy(validatorSrc, esmValidatorDst)
.then(() => console.log('Copy validators.js completed!'))
.catch(err =>
console.error('An error occurred while copying validators.js', err)
);
};

const copySchemas = async () => {
return fs
.copy(schemasSrc, esmSchemasDst, { overwrite: true })
.then(() => console.log("Copy schemas/ to cjs/ completed!"))
.catch((err) =>
console.error("An error occurred while copying the schemas/ folder.", err)
.then(() => console.log('Copy schemas/ to cjs/ completed!'))
.catch(err =>
console.error('An error occurred while copying the schemas/ folder.', err)
);
};

const buildEsm = async () => {
await copyEnums();
await copyIndex();
await copyValidators();
await copyValidator();
await copySchemas();
};

Expand Down
36 changes: 20 additions & 16 deletions scripts/config.cjs
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
const path = require("path");
const path = require('path');

const srcPath = path.join(__dirname, "..", "src");
const examplesSrc = path.join(srcPath, "examples");
const indexSrc = path.join(srcPath, "index.js");
const schemasSrc = path.join(srcPath, "schemas");
const validatorsSrc = path.join(srcPath, "validators.js");
const srcPath = path.join(__dirname, '..', 'src');
const enumsSrc = path.join(srcPath, 'enums.js');
const examplesSrc = path.join(srcPath, 'examples');
const indexSrc = path.join(srcPath, 'index.js');
const schemasSrc = path.join(srcPath, 'schemas');
const validatorSrc = path.join(srcPath, 'lucaValidator.js');

const distPath = path.join(__dirname, "..", "dist");
const distPath = path.join(__dirname, '..', 'dist');

const cjsPath = path.join(distPath, "cjs");
const cjsExamplesDst = path.join(cjsPath, "examples");
const cjsSchemasDst = path.join(cjsPath, "schemas");
const cjsPath = path.join(distPath, 'cjs');
const cjsExamplesDst = path.join(cjsPath, 'examples');
const cjsSchemasDst = path.join(cjsPath, 'schemas');

const esmPath = path.join(distPath, "esm");
const esmIndexDst = path.join(esmPath, "index.js");
const esmSchemasDst = path.join(esmPath, "schemas");
const esmValidatorsDst = path.join(esmPath, "validators.js");
const esmPath = path.join(distPath, 'esm');
const esmEnumsDst = path.join(esmPath, 'enums.js');
const esmIndexDst = path.join(esmPath, 'index.js');
const esmSchemasDst = path.join(esmPath, 'schemas');
const esmValidatorDst = path.join(esmPath, 'lucaValidator.js');

module.exports = {
distPath,
cjsPath,
esmPath,
cjsExamplesDst,
cjsSchemasDst,
esmEnumsDst,
esmIndexDst,
esmValidatorsDst,
esmValidatorDst,
esmSchemasDst,
srcPath,
enumsSrc,
examplesSrc,
indexSrc,
schemasSrc,
validatorsSrc,
validatorSrc
};
77 changes: 77 additions & 0 deletions src/enums.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const SchemasEnum = Object.freeze({
CATEGORY: 'category',
ENTITY: 'entity',
LUCASCHEMA: 'lucaSchema',
RECURRING_TRANSACTION: 'recurringTransaction',
RECURRING_TRANSACTION_EVENT: 'recurringTransactionEvent',
SCHEMA: 'schema',
TRANSACTION: 'transaction'
});

const TransactionStateEnum = Object.freeze({
PLANNED: 'PLANNED',
SCHEDULED: 'SCHEDULED',
PENDING: 'PENDING',
COMPLETED: 'COMPLETED',
CANCELLED: 'CANCELLED',
FAILED: 'FAILED',
DISPUTED: 'DISPUTED',
REFUNDED: 'REFUNDED',
TENTATIVE: 'TENTATIVE',
UPCOMING: 'UPCOMING',
DELETED: 'DELETED'
});

const CategoryTypeEnum = Object.freeze({
DEFAULT: 'DEFAULT',
MODIFIED: 'MODIFIED',
CUSTOM: 'CUSTOM'
});

const EntityTypeEnum = Object.freeze({
ACCOUNT: 'ACCOUNT',
RETAILER: 'RETAILER',
BUSINESS: 'BUSINESS',
INDIVIDUAL: 'INDIVIDUAL',
UTILITY: 'UTILITY',
GOVERNMENT: 'GOVERNMENT'
});

const EntityStatusEnum = Object.freeze({
ACTIVE: 'ACTIVE',
INACTIVE: 'INACTIVE',
SUSPENDED: 'SUSPENDED',
DELETED: 'DELETED',
CLOSED: 'CLOSED'
});

const RecurringTransactionFrequencyEnum = Object.freeze({
DAY: 'DAY',
WEEK: 'WEEK',
MONTH: 'MONTH',
YEAR: 'YEAR'
});

const RecurringTransactionStateEnum = Object.freeze({
ACTIVE: 'ACTIVE',
PAUSED: 'PAUSED',
COMPLETED: 'COMPLETED',
CANCELLED: 'CANCELLED'
});

const RecurringTransactionEventStatusEnum = Object.freeze({
MODIFIED: 'MODIFIED',
DELETED: 'DELETED'
});

const enums = {
TransactionStateEnum,
CategoryTypeEnum,
EntityTypeEnum,
EntityStatusEnum,
RecurringTransactionFrequencyEnum,
RecurringTransactionStateEnum,
RecurringTransactionEventStatusEnum
};

export default enums;
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import enums from './enums';
import lucaValidator from './lucaValidator';
import schemas from './schemas';
import validators from './validators';

export { schemas, validators };
export { enums, lucaValidator, schemas };
18 changes: 18 additions & 0 deletions src/lucaValidator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Ajv2020 from 'ajv/dist/2020';
import addFormats from 'ajv-formats';

import schemas from './schemas';

const lucaValidator = new Ajv2020();
addFormats(lucaValidator);

Object.entries(schemas).forEach(([key, schema]) => {
if (!lucaValidator.validateSchema(schema)) {
console.error(`Invalid schema: ${key}`);
console.error(lucaValidator.errors);
} else {
lucaValidator.addSchema(schema, key);
}
});

export default lucaValidator;
4 changes: 2 additions & 2 deletions src/tests/categories.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import exampleData from '../examples/categories.json';
import validators from '../validators';
import { lucaValidator } from '../';

const { validateCategory } = validators;
const validateCategory = lucaValidator.getSchema('category');

test('examples are valid categories', () => {
exampleData.forEach(example => {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/entities.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import exampleData from '../examples/entities.json';
import validators from '../validators';
import { lucaValidator } from '../';

const { validateEntity } = validators;
const validateEntity = lucaValidator.getSchema('entity');

test('examples are valid entities', () => {
exampleData.forEach(example => {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/lucaSchema.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import exampleData from '../examples/lucaSchema.json';
import validators from '../validators';
import { lucaValidator } from '../';

const { validateLucaSchema } = validators;
const validateLucaSchema = lucaValidator.getSchema('lucaSchema');

test('full luca schema object is valid', () => {
const valid = validateLucaSchema(exampleData);
Expand Down
4 changes: 2 additions & 2 deletions src/tests/recurringTransactionEvents.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import exampleData from '../examples/recurringTransactionEvents.json';
import validators from '../validators';
import { lucaValidator } from '../';

const { validateRecurringTransactionEvent } = validators;
const validateRecurringTransactionEvent = lucaValidator.getSchema('recurringTransactionEvent');

test('examples are valid recurringTransactionEvents', () => {
exampleData.forEach(example => {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/recurringTransactions.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import exampleData from '../examples/recurringTransactions.json';
import validators from '../validators';
import { lucaValidator } from '../';

const { validateRecurringTransaction } = validators;
const validateRecurringTransaction = lucaValidator.getSchema('recurringTransaction');

test('examples are valid recurringTransactions', () => {
exampleData.forEach(example => {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/schemas.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import exampleData from '../examples/schemas.json';
import validators from '../validators';
import { lucaValidator } from '../';

const { validateSchema } = validators;
const validateSchema = lucaValidator.getSchema('schema');

test('examples are valid schema objects', () => {
exampleData.forEach(example => {
Expand Down
Loading
Loading