Skip to content

Commit

Permalink
Merge pull request #13 from LucaFinancial/chore/merge-conflicts-1-0-7
Browse files Browse the repository at this point in the history
chore: merge
  • Loading branch information
jwaspin authored May 1, 2024
2 parents ee8fb4f + 09ebd72 commit 528eb3e
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 84 deletions.
9 changes: 2 additions & 7 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-beta.4",
"description": "Schemas for the Luca Ledger application",
"author": "Johnathan Aspinwall",
"main": "dist/index.js",
Expand Down Expand Up @@ -54,12 +54,7 @@
}
},
"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"
]
Expand Down
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,
constantsSrc,
indexSrc,
validatorsSrc,
validatorSrc,
esmConstantsDst,
esmIndexDst,
esmValidatorsDst,
esmSchemasDst,
esmValidatorDst,
esmSchemasDst
} = config;

const copyConstants = async () => {
return fs
.copy(constantsSrc, esmConstantsDst)
.then(() => console.log('Copy constants.js completed!'))
.catch(err =>
console.error('An error occurred while copying constants.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 copyConstants();
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 constantsSrc = path.join(srcPath, 'constants.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 esmConstantsDst = path.join(esmPath, 'constants.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,
esmConstantsDst,
esmIndexDst,
esmValidatorsDst,
esmValidatorDst,
esmSchemasDst,
srcPath,
constantsSrc,
examplesSrc,
indexSrc,
schemasSrc,
validatorsSrc,
validatorSrc
};
67 changes: 67 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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 RepeatedTransactionFrequencyEnum = Object.freeze({
DAY: 'DAY',
WEEK: 'WEEK',
MONTH: 'MONTH',
YEAR: 'YEAR'
});

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

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

const constants = {
TransactionStateEnum,
CategoryTypeEnum,
EntityTypeEnum,
EntityStatusEnum,
RepeatedTransactionFrequencyEnum,
RepeatedTransactionStateEnum,
RepeatedTransactionOccurrenceStatusEnum
};

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

export { schemas, validators };
export { constants, 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
4 changes: 2 additions & 2 deletions src/tests/transactions.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import exampleData from '../examples/transactions.json';
import validators from '../validators';
import { lucaValidator } from '../';

const { validateTransaction } = validators;
const validateTransaction = lucaValidator.getSchema('transaction');

test('examples are valid transactions', () => {
exampleData.forEach(example => {
Expand Down
28 changes: 0 additions & 28 deletions src/validators.js

This file was deleted.

0 comments on commit 528eb3e

Please sign in to comment.