1.0.55 • Published 6 days ago

document-model v1.0.55

Weekly downloads
-
License
AGPL-3.0-only
Repository
-
Last release
6 days ago

Powerhouse Document Model

Getting started

Install the library:

  • NPM: npm install @acaldas/document-model-libs
  • Yarn: yarn add @acaldas/document-model-libs

Documentation

The full documentation for this package is available at: https://acaldas.github.io/document-model-libs/

There are two ways to interact with a document:

Functional:

import {
    actions,
    reducer,
    utils,
} from '@acaldas/document-model-libs/budget-statement';

let budgetStatement = utils.createDocument({
    name: 'March report',
    data: { month: '2023/01' },
});

budgetStatement = reducer(
    budgetStatement,
    actions.addAccount([{ address: 'eth:0x00' }])
);

Object oriented:

import { BudgetStatement } from '@acaldas/document-model-libs/budget-statement';

const budgetStatement = new BudgetStatement({
    name: 'march',
    data: { month: '2023/01' },
});
budgetStatement.addAccount([{ address: 'eth:0x00' }]);

Architecture

This implementation is inspired by the Flux architecture pattern. All state changes are performed by a reducer, which is a pure function that enforces state transitions:

const newState = reducer(state, action);

The business logic is implemented in pure functions, making it easy to test and integrate into different applications. The operations history is kept to allow reverting changes.

An action is a JSON object with the action name and payload:

{
    type: 'SET_NAME';
    input: {
        name: 'March report';
    }
}

To make it easier to create actions and avoid bugs, an action creator is provided for each action. This is a function that accepts the action input and returns the JSON structure. For the case above the action creator would be:

state = reducer(state, setName('March report'));

An Object-oriented version is also provided. A document can be instantiated and interacted in an imperative way:

const document = new Document();
document.setName('March report');

Base Document Model

All document models extend the Base Document model, which provides some common features. A document has the following structure:

{
    name: "SES 2023-01 expense report", // name of the document
    documentType: "powerhouse/budget-statement", // type of the document model
    revision: 4, // number of operations applied to the document
    created: "2023-02-05 12:15:01", // date of creation of the document
    lastModified: "2023-02-05 12:15:01", // date of the last modification
    data: {} // specific state of the document, to be implemented by document models
}

Base Document Actions

Document reducers are wrapped by the Base Document reducer, which is responsible for updating the document attributes described above and adds support for some base document features.

▸ For more information on Document actions, please refer to the complete documentation.

  • SET_NAME: Changes the name of the document
setName(name: string);
  • UNDO: Cancels the last X operations. Defaults to 1.
undo(count: number);
  • REDO: Cancels the last X UNDO operations. Defaults to 1.
redo(count: number);
  • PRUNE: Joins multiple operations into a single LOAD_STATE operation. Useful to keep operations history smaller. Operations to prune are selected by index, similar to the slice method in Arrays.
prune(start?: number, end?: number);

Budget Statement Model

A Budget statement follows the following data structure:

{
    name: "SES January 2023",
    documentType: "powerhouse/budget-statement",
    revision: 10,
    created: "2023-02-21 10:15:26",
    lastModified: "2023-02-21 13:12:49",
    data: {
        owner: {
            ref: "makerdao/core-unit",
            id: "SES-001",
            title: "Sustainable Ecosystem Scaling"
        },
        month: "2023/01",
        quoteCurrency: "DAI",
        auditReports: [
            {
                timestamp: "2023-02-21 13:12:49",
                report: "attachment://audits/report.pdf",
                status: "Approved" | "ApprovedWithComments" | "NeedsAction" | "Escalated"
            }
        ],
        accounts: [
            {
                address: "eth:0xb5eB779cE300024EDB3dF9b6C007E312584f6F4f",
                name: "Grants Program",
                lineItems: [
                    {
                        category: {
                            ref: "makerdao/budget-category",
                            id: "TravelAndEntertainment",
                            title: "Travel & Entertainment",
                            headcountExpense: true
                        },
                        group: {
                            ref: "makerdao/project",
                            id: "core-unit/SES/2023/005",
                            title: "Core Unit Operational Support"
                        },
                        budgetCap: 10000,
                        payment: 0,
                        actual: 4000,
                        forecast: [
                            {
                                month: "2023/02",
                                value: 30000
                            },
                            {
                                month: "2023/03",
                                value: 40000
                            },
                            {
                                month: "2023/04",
                                value: 30000
                            }
                        ]
                    }
                ]
            }
        ]
    }
}

Budget Statement Actions

▸ For more information on Budget Statement actions, please refer to the complete documentation.

1.0.55

16 days ago

1.0.54

16 days ago

1.0.53

19 days ago

1.0.52

20 days ago

1.0.49

23 days ago

1.0.51

23 days ago

1.0.50

23 days ago

1.0.44

24 days ago

1.0.43

24 days ago

1.0.42

24 days ago

1.0.48

24 days ago

1.0.47

24 days ago

1.0.46

24 days ago

1.0.45

24 days ago

1.0.41

26 days ago

1.0.39

27 days ago

1.0.40

27 days ago

1.0.38

30 days ago

1.0.37

30 days ago

1.0.36

1 month ago

1.0.33

1 month ago

1.0.35

1 month ago

1.0.34

1 month ago

1.0.32

2 months ago

1.0.31

2 months ago

1.0.30

3 months ago

1.0.29

3 months ago

1.0.28

3 months ago

1.0.27

3 months ago

1.0.26

4 months ago

1.0.25

4 months ago

1.0.24

4 months ago

1.0.23

4 months ago

1.0.22

4 months ago

1.0.21

4 months ago

1.0.20

4 months ago

1.0.19

5 months ago

1.0.18

5 months ago

1.0.17

5 months ago

1.0.16

5 months ago

1.0.15

5 months ago

1.0.14

5 months ago

1.0.13

5 months ago

1.0.12

5 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago