3.0.10 • Published 8 days ago

@snickerdoodlelabs/objects v3.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
8 days ago

objects

This package provides the base business objects and abstractions that are used throughout Snickerdoodle Labs's packages.

Concepts

Branding

We make heavy use of an idea called Type Branding, implemented via a library called ts-brand. This allows us to differentiate basic types such as string, number and bigint, to indicate they contain particular types of values. We refer to these as Primitives internally. An example would be URLString. The underlying data type is just string, but in the type system, you can pass a URLString to anything taking a string or URLString, but not to FamilyName. This sometimes requires wrapping up your values using the brand, like so:

import { URLString } from "@snickerdoodlelabs/objects";

const str = "http://snickerdoodle.com";
const urlString = URLString(str);

The compiled code does not represent this wrapping, it exists only within Typescript. We make efforts to do validation BEFORE a value is branded- meaning, we know it's a URL before we wrap it with URLString. Methods that take a URLString therefore assume that it is a valid URL and do not verify the value, and may error in unexpected ways. This is a liability in a pure javascript environment perhaps, but allows us to let the compiler catch most of what could be runtime errors, since we know the point where an unknown value becomes a URLString and can be sure to do the validation there.

Immutability

Our domain objects (also referred to as business objects) are all simple POCOs (Plain Old Common Object)/DTOs (Data Transfer Objects), and are designed explicitly to do one thing- contain and transfer state. They all use only primitive types, and avoiding nesting. They are meant for easy JSON-based serialization and deserialization (although we recommend using ObjectUtils.serialize()/deserialize() from the @snickerdoodlelabs/common-utils package). As state transfer objects, they avoid any business logic inside them, although some do contain display logic. You must be careful about using methods on these objects after deserialization- as the methods do not transfer. This isn't a problem unique to Snickerdoodle but is something we are careful to track.

The objects are not technically immutable, but in general are used as if they are, and the patterns are familiar.

Errors

Our Error objects are all extended from the base Error object by way of BaseError. BaseError adds the fields needed by the Moleculer microservice framework. Most of our errors contain the same fields, and thus would be vulnerable to Typescript's duck typing and merging. BlockchainError | AjaxError could very easily be combined together by Typescript, so we introduce a private errorCode property that prevents this. This makes sure our unioned error types remain distinct all the way through the code.

Versioned Objects

A subset of our domain objects are derived from VersionedObject. These are objects that maintain an upgrade path as they change, and are packaged with a VersionMigrator object. These objects are for data that is stored in persistent backups, where old data is still valid but the shape may have changed over time. The VersionMigrator takes the data and version, and returns the most current version of the VersionedObject, making up or removing data as necessary.

Publishing

Run the following command, after updating the version in the package.json, from the root:

yarn workspace @snickerdoodlelabs/objects npm publish
3.0.10

8 days ago

3.0.9

21 days ago

3.0.8

26 days ago

3.0.7

28 days ago

3.0.6

29 days ago

3.0.5

29 days ago

3.0.4

1 month ago

3.0.3

1 month ago

3.0.2

1 month ago

2.0.14

1 month ago

2.0.13

1 month ago

2.0.12

2 months ago

2.0.11

2 months ago

3.0.1

2 months ago

3.0.0

2 months ago

2.0.10

2 months ago

2.0.9

2 months ago

2.0.8

2 months ago

2.0.7

2 months ago

2.0.5

2 months ago

2.0.6

2 months ago

2.0.3

2 months ago

2.0.4

2 months ago

2.0.2

3 months ago

2.0.1

3 months ago

2.0.0

3 months ago

1.2.4

3 months ago

1.2.3

3 months ago

1.2.2

3 months ago

1.2.1

4 months ago

1.2.0

4 months ago

1.1.17

5 months ago

1.1.16

5 months ago

1.1.15

5 months ago

1.1.14

5 months ago

1.1.13

5 months ago

1.1.12

5 months ago

1.1.11

5 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

0.0.73

8 months ago

0.0.70

10 months ago

0.0.71

9 months ago

0.0.72

9 months ago

1.1.1

7 months ago

1.1.0

7 months ago

0.0.64

10 months ago

0.0.65

10 months ago

0.0.66

10 months ago

0.0.67

10 months ago

0.0.68

10 months ago

0.0.69

10 months ago

1.1.9

5 months ago

1.1.8

6 months ago

1.1.7

6 months ago

1.1.6

6 months ago

1.1.5

6 months ago

1.1.4

6 months ago

1.1.3

7 months ago

1.1.2

7 months ago

1.1.10

5 months ago

0.0.60-1

11 months ago

0.0.62

11 months ago

0.0.63

11 months ago

0.0.60

12 months ago

0.0.61

12 months ago

0.0.59

12 months ago

0.0.53-1

11 months ago

0.0.55

1 year ago

0.0.56

12 months ago

0.0.57

12 months ago

0.0.58

12 months ago

0.0.40

1 year ago

0.0.41

1 year ago

0.0.42

1 year ago

0.0.43

1 year ago

0.0.44

1 year ago

0.0.45

1 year ago

0.0.46

1 year ago

0.0.47

1 year ago

0.0.37

1 year ago

0.0.38

1 year ago

0.0.39

1 year ago

0.0.35

1 year ago

0.0.36

1 year ago

0.0.51

1 year ago

0.0.52

1 year ago

0.0.53

1 year ago

0.0.54

1 year ago

0.0.50

1 year ago

0.0.48

1 year ago

0.0.49

1 year ago

0.0.34

1 year ago

0.0.20

1 year ago

0.0.21

1 year ago

0.0.22

1 year ago

0.0.23

1 year ago

0.0.24

1 year ago

0.0.25

1 year ago

0.0.18

1 year ago

0.0.19

1 year ago

0.0.30

1 year ago

0.0.31

1 year ago

0.0.32

1 year ago

0.0.33

1 year ago

0.0.26

1 year ago

0.0.27

1 year ago

0.0.28

1 year ago

0.0.29

1 year ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.17

1 year ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.1

2 years ago