@thisisagile/easy-domain 15.29.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +282 -0
  2. package/dist/chunk-3N5M6QHW.mjs +132 -0
  3. package/dist/chunk-3N5M6QHW.mjs.map +1 -0
  4. package/dist/chunk-CKW4QYDN.mjs +16 -0
  5. package/dist/chunk-CKW4QYDN.mjs.map +1 -0
  6. package/dist/chunk-H2VHSGNX.mjs +35 -0
  7. package/dist/chunk-H2VHSGNX.mjs.map +1 -0
  8. package/dist/chunk-ODLLVCBP.mjs +6634 -0
  9. package/dist/chunk-ODLLVCBP.mjs.map +1 -0
  10. package/dist/chunk-RDITZTSA.mjs +41 -0
  11. package/dist/chunk-RDITZTSA.mjs.map +1 -0
  12. package/dist/chunk-SBXA2N6H.mjs +29 -0
  13. package/dist/chunk-SBXA2N6H.mjs.map +1 -0
  14. package/dist/chunk-VAHXDD2J.mjs +268 -0
  15. package/dist/chunk-VAHXDD2J.mjs.map +1 -0
  16. package/dist/chunk-XBORRJ6W.mjs +18 -0
  17. package/dist/chunk-XBORRJ6W.mjs.map +1 -0
  18. package/dist/enums/Country.d.ts +256 -0
  19. package/dist/enums/Country.mjs +8 -0
  20. package/dist/enums/Country.mjs.map +1 -0
  21. package/dist/enums/Currency.d.ts +124 -0
  22. package/dist/enums/Currency.mjs +8 -0
  23. package/dist/enums/Currency.mjs.map +1 -0
  24. package/dist/enums/Locale.d.ts +571 -0
  25. package/dist/enums/Locale.mjs +584 -0
  26. package/dist/enums/Locale.mjs.map +1 -0
  27. package/dist/enums/UnitOfMeasurement.d.ts +10 -0
  28. package/dist/enums/UnitOfMeasurement.mjs +8 -0
  29. package/dist/enums/UnitOfMeasurement.mjs.map +1 -0
  30. package/dist/enums/UnitOfWeight.d.ts +8 -0
  31. package/dist/enums/UnitOfWeight.mjs +8 -0
  32. package/dist/enums/UnitOfWeight.mjs.map +1 -0
  33. package/dist/index.d.ts +17 -0
  34. package/dist/index.js +7997 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/index.mjs +18 -0
  37. package/dist/index.mjs.map +1 -0
  38. package/dist/structs/Address.d.ts +12 -0
  39. package/dist/structs/Address.mjs +47 -0
  40. package/dist/structs/Address.mjs.map +1 -0
  41. package/dist/structs/Box.d.ts +15 -0
  42. package/dist/structs/Box.mjs +44 -0
  43. package/dist/structs/Box.mjs.map +1 -0
  44. package/dist/structs/Dimension.d.ts +10 -0
  45. package/dist/structs/Dimension.mjs +9 -0
  46. package/dist/structs/Dimension.mjs.map +1 -0
  47. package/dist/structs/Money.d.ts +14 -0
  48. package/dist/structs/Money.mjs +48 -0
  49. package/dist/structs/Money.mjs.map +1 -0
  50. package/dist/structs/Name.d.ts +8 -0
  51. package/dist/structs/Name.mjs +26 -0
  52. package/dist/structs/Name.mjs.map +1 -0
  53. package/dist/structs/Weight.d.ts +13 -0
  54. package/dist/structs/Weight.mjs +43 -0
  55. package/dist/structs/Weight.mjs.map +1 -0
  56. package/dist/values/EAN.d.ts +5 -0
  57. package/dist/values/EAN.mjs +23 -0
  58. package/dist/values/EAN.mjs.map +1 -0
  59. package/dist/values/Email.d.ts +8 -0
  60. package/dist/values/Email.mjs +29 -0
  61. package/dist/values/Email.mjs.map +1 -0
  62. package/dist/values/IBAN.d.ts +5 -0
  63. package/dist/values/IBAN.mjs +23 -0
  64. package/dist/values/IBAN.mjs.map +1 -0
  65. package/dist/values/PostalCode.d.ts +8 -0
  66. package/dist/values/PostalCode.mjs +12 -0
  67. package/dist/values/PostalCode.mjs.map +1 -0
  68. package/dist/values/Slug.d.ts +6 -0
  69. package/dist/values/Slug.mjs +24 -0
  70. package/dist/values/Slug.mjs.map +1 -0
  71. package/dist/values/Url.d.ts +22 -0
  72. package/dist/values/Url.mjs +29 -0
  73. package/dist/values/Url.mjs.map +1 -0
  74. package/package.json +44 -0
  75. package/src/enums/Country.ts +269 -0
  76. package/src/enums/Currency.ts +131 -0
  77. package/src/enums/Locale.ts +584 -0
  78. package/src/enums/UnitOfMeasurement.ts +17 -0
  79. package/src/enums/UnitOfWeight.ts +15 -0
  80. package/src/enums/countries.json +251 -0
  81. package/src/enums/currencies.json +1073 -0
  82. package/src/enums/locales.json +565 -0
  83. package/src/index.ts +19 -0
  84. package/src/structs/Address.ts +23 -0
  85. package/src/structs/Box.ts +28 -0
  86. package/src/structs/Dimension.ts +24 -0
  87. package/src/structs/Money.ts +37 -0
  88. package/src/structs/Name.ts +13 -0
  89. package/src/structs/Weight.ts +34 -0
  90. package/src/values/EAN.ts +12 -0
  91. package/src/values/Email.ts +20 -0
  92. package/src/values/IBAN.ts +12 -0
  93. package/src/values/PostalCode.ts +17 -0
  94. package/src/values/Slug.ts +14 -0
  95. package/src/values/Url.ts +73 -0
package/README.md ADDED
@@ -0,0 +1,282 @@
1
+ # easy
2
+ The easiest framework to build robust and stable microservices in TypeScript on node.js.
3
+
4
+ <a href="https://www.npmjs.com/package/@thisisagile/easy" target="_blank"><img src="https://img.shields.io/npm/v/@thisisagile/easy.svg" alt="npm version" /></a>
5
+ <a href="https://www.npmjs.com/package/@thisisagile/easy" target="_blank"><img src="https://img.shields.io/npm/dm/@thisisagile/easy.svg" alt="npm downloads" /></a>
6
+ <a href="https://github.com/thisisagile/easy/actions?query=workflow%3A%22pipeline%22"><img src="https://github.com/thisisagile/easy/workflows/pipeline/badge.svg?branch=main" alt="pipeline status" /></a>
7
+ <a href="https://sonarcloud.io/dashboard?id=thisisagile_easy" target="_blank"><img src="https://sonarcloud.io/api/project_badges/measure?project=thisisagile_easy&metric=alert_status" alt="quality gate" /></a>
8
+ <a href="https://github.com/semantic-release/semantic-release" target="_blank"><img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg" alt="semantic-release" /></a>
9
+ <a href="https://sonarcloud.io/dashboard?id=thisisagile_easy" target="_blank"><img src="https://sonarcloud.io/api/project_badges/measure?project=thisisagile_easy&metric=coverage" alt="coverage" /></a>
10
+
11
+ ## Note
12
+ The **easy** framework captures the best practices we (the contributors) have built up while implementing microservices architectures at a diverse range of clients in Typescript, running on node.js and deployed on Amazon, Google Cloud and even on Windows Server. The companies that contribute / have contributed include a well-known Dutch insurance company, an insurance software vendor, an IoT scale-up, a software vendor in logistics and an online e-commerce company. From those practices, the **easy** framework grows step-by-step.
13
+
14
+ The **easy** framework already works fine in many situations. However, it also continuously improves and grows. It is a work-in-progress, including its documentation. Being a framework, it probably not always perfectly fits your situation. Therefore, we aim to implement **easy** so that it is straightforward, simple to use, standardized, and open to extensions.
15
+
16
+ ## Welcome!
17
+ The **easy** framework is a straightforward, smart library for building domain-driven microservice architectures, implementing a simple evolutionary architecture. This library is distilled from projects where the teams I've worked with built platforms based on a simple, common architecture where each service centers around a small part of the platform domain.
18
+
19
+ This framework will include best and foremost simple practices to support building microservices, based on the following software architecture and patterns:
20
+
21
+ ## Architecture
22
+ Microservices built with **easy** have a four layered architecture: *services*, *process*, *domain*, *data*. Each of the layers serves a single purpose and follows clear patterns and communications:
23
+
24
+ - *Services*. This layer contains resource classes, which handle requests to the microservice's endpoints.
25
+ - *Process*. This second layer contains use cases, which handle all process logic of the microservice.
26
+ - *Domain*. At the heart of each microservice lies its domain, which consists of entities, values objects, enumerations and structs. To approach the objects in the domain, this layer also contains repositories.
27
+ - *Data*. The bottom layer of each microservice contains gateways, that allow the microservice to interact with its outside world, such as relational databases, no-sql databases, file storage or other services.
28
+
29
+ The **easy** framework supports this architecture by supplying root classes (or layer supertypes) for each of the types describe above. The repository `easy-test` contains utilities to assist you with testing **easy** specific constructs, such as `toMatchText` or `toMatchPath` for checking paths in uri's. The repository `easy-sample` contains examples of microservices built with the **easy** framework.
30
+
31
+ ## Root
32
+ At the root of each microservice built using **easy**, there is a class that inherits from `Service`. These are used to initiate the service, set the `port` at which it runs, register all resource classes, and start the service. An example services class is the one below for a movie service.
33
+
34
+ SampleService.Movie
35
+ .with(MoviesResource, MovieResource)
36
+ .atPort(9001)
37
+ .start();
38
+
39
+ This movie service registers two resources, `MoviesResource` and `MovieResource`, each of which handle endpoints. The service listens at port `9001`.
40
+
41
+ In general, you will not build a single microservice, but rather a collection of microservices, each responsible for a distinct part of the complete business domain. In that case, it can be useful to build a root class for your services, such as the `SampleService` class below.
42
+
43
+ class SampleService extends Service {
44
+ static readonly Movie = new SampleService('movie');
45
+ pre = () => [correlation];
46
+ post = () => [error, notFound];
47
+ }
48
+
49
+ The `SampleService` inherits directly from the `Service` layer supertype from **easy**. The methods `pre()` and `post()` can be used to register middleware (by default **easy** uses express as its web server). However, this can easily be changed if you require so. The middlewares `correlation`, `error` and `notFound` are also provided by **easy**.
50
+
51
+ ## Services
52
+ The services layer has resource as the layer supertype, to model the API exposed.
53
+
54
+ ## Process
55
+ The process layer contains use cases, that model your process.
56
+
57
+ ## Domain
58
+ In the domain layer there are supertypes to model the domain, such as entities, records, value objects and enumerations.
59
+ The domain layer also knows the repository layer supertype, for handling instances of entities and structs.
60
+
61
+ ### Entities
62
+ Using **easy**, your entities, as described in domain driven design, inherit from the `Entity` class. This gives your entities identity. The default implementation of `Entity` provides a generated `id` property (it's a UUID by default).
63
+
64
+ All classes that inherit from `Record` or `Entity` will have an internal object called `state`. Normally, the state of an object is passed to it during construction. Using this internal object `state` allows for easy mapping of the content of an entity, which is usually JSON, to its properties. We prefer to keep our entities immutable. Properties therefore can be readonly. An update to an object is considered a state change and should therefore always return a new instance of the entity, instead of modifying the state of the current instance.
65
+
66
+ An example of an entity is the `Movie` class below. Here the content of the object comes from an external service (called OMDb), and is mapped to the actual properties of the `Movie` class.
67
+
68
+ export class Movie extends Entity {
69
+ @required() readonly id = this.state.imdbID as Id;
70
+ @required() readonly title = this.state.Title as string;
71
+ @required() readonly year = this.state.Year as number;
72
+ readonly poster = this.state.Poster as string;
73
+
74
+ update = (add?: Json): Movie => new Movie(this.toJSON(add));
75
+ }
76
+
77
+ Some properties of `Movie` have decorators, such as `@required`. These decorators can be used to validate the object, using the separate `validate()` function.
78
+
79
+ ### Enumerables
80
+ Most modern programming languages support the use of enumerables. The goal of enumerables is to allow only a limited set of values to be chosen for a particular property or passed as a parameter of a function, or its return type. Although this seems trivial, there are some drawbacks to using enumerables.
81
+
82
+ First, in most languages, you can not inherit from enumerables. As a result, if you define an enumerable in a library, and would like to add values to it in another repository, this is not possible. If you would, as we do in **easy** support a list of scopes, we could have created an enumerable `Scope`, with the scopes we see. However, if you use **easy** and would like to add your own scopes, this is not possible with a default enumerable.
83
+
84
+ Secondly, in most languages (Java not included), enumerations only have two properties, the name and the index of its items. If you want to have some more properties on you enumerations, or add some behavior, an enumerable is not your best bet.
85
+
86
+ Thirdly, and perhaps the most dangerous one, if you persist your enumerables to a storage facility (a database for instance), enumerations are usually stored using their index. This makes the data hard to interpret. After all, what does scope `2` really mean? But even worse, if you would add more items to your enumerable later on, the index of the items might alter, and hence the stored data gets a different meaning, often without noticing.
87
+
88
+ Therefore, **easy** provides an `Enum` class, which is both extendable and allows you to define meaningful identifiers for your items, and also add additional properties. And still, the behaviour of enumerables created using the `Enum` class, is comparable to traditional enumerables. Here's the `UseCase` enumerable from **easy** as an example.
89
+
90
+ export class UseCase extends Enum {
91
+ constructor(readonly scope: Scope, name: string, id: string = text(name).kebab) {
92
+ super(name, id);
93
+ }
94
+
95
+ static readonly Main = new UseCase(Scope.Basic, "Main");
96
+ static readonly Login = new UseCase(Scope.Auth, "Login");
97
+ static readonly Logout = new UseCase(Scope.Auth, "Logout");
98
+ static readonly ForgotPassword = new UseCase(Scope.Auth, "Forgot password");
99
+ static readonly ChangePassword = new UseCase(Scope.Auth, "Change password");
100
+ }
101
+
102
+ The class `UseCase` has five items, such as `UseCase.Main` or `UseCase.ChangePassword`. The constructor has an additional property `scope`, which the `Enum` class does not have, but it calls on the constructor of its superclass to actual make it work. All instances of `Enum` have a property `id`, which is used to store the enums, when used as property on entities, or for comparison.
103
+
104
+ ### Value objects
105
+ When we are not so much interested in the identity of objects, as with entities, but are merely interested in the values of the object, we use value objects. A nice useful definition of value objects is presented by Eric Evens in his seminal book *Domain Driven Design*.
106
+
107
+ > An object that represents a descriptive aspect of the domain with no conceptual identity is called a Value Object. Value Objects are instantiated to represent elements of the design that we care about only for what they are, not who or which they are.
108
+
109
+ The nice thing about value objects is that you can define them once, and then use everywhere, usually as the types of properties of entities, or even of other value objects. Straightforward examples of value objects are `Email`, and `Address`. The nice thing about value objects is that checking its validity is done at the value object itself, so reusing them does not result in validations being re-implemented everywhere.
110
+
111
+ In **easy** we have defined two base classes to implement your value objects. For single valued objects, such as `Email`, we use the base class `Value`. For value objects that have multiple properties, such as `Address` or `Money`, we tend to inherit from the base class `Struct`. Classes that derive from `Value` or `Struct` can be easily validated using the `validate()` function.
112
+
113
+ ### Value
114
+ Values are single property objects that are immutable and give meaning to that single property. If you take a string `john.doe@example.com`. This string is a valid string and any validation on whether this string is an email or not needs to be done externally.
115
+
116
+ However, if you would create an `Email` value object, the validation can be implemented internally, and the `Email` class can then be reused everywhere emails are needed.
117
+
118
+ class Email extends Value<string> {
119
+ get isValid(): boolean {
120
+ return validator.isEmail(this.value);
121
+ }
122
+ }
123
+
124
+ You can now use the above `Email` class as the type of email properties in an entity or struct to make sure that this property is a valid email.
125
+
126
+ #### DateTime
127
+ DateTime is a value object that takes either a Date object, RFC-3339 formatted string, or a number representing Epoch in milliseconds. The json is always an RFC-3339 formatted string. [luxon](https://moment.github.io/luxon/#/) is used internally.
128
+
129
+ A few examples of DateTime:
130
+
131
+ new DateTime().toJSON() // returns the date formatted as 2021-03-25T08:39:44.000Z
132
+ new DateTime(new Date()).toJSON() // same as above
133
+ DateTime.now.toJSON() // same as above
134
+ new DateTime(1617288152000).toJSON() // returns 2021-04-01T14:42:32.000Z
135
+
136
+ ## Validation
137
+ All **easy** microservices evolve around their part of the total business domain you are implementing. Quite usually, in its domain layer, a microservice contains an *aggregate*. In domain-driven design an aggregate maps to a part of the domain that is persisted together. In a relational database, this is usually guarded with a transaction. In a document database, such as MongoDB, this is more often a single serialized `Json` object.
138
+
139
+ To assure that such an aggregate is valid, when persisted, it is validated, usually starting from the *aggregate root*. In most cases, the aggregate root is the entity that is also the resource that requests are about, and in most often it is also the name of the microservice itself.
140
+
141
+ ### Validate
142
+ The **easy** framework supplies a nice and easy mechanism for validating instances of the microservice's aggregate. We supply to easy-to-use functions, named `validate(subject?: unknown): Results` and `validateReject = <T>(subject?: T): Promise<T>`. Although you can pass any object to these functions, in general, you will pass the aggregate root as an argument.
143
+
144
+ validate = (dev: Developer): Results => validate(dev);
145
+
146
+ The `validate()` function will validate its `subject`, and recursively the subjects properties. The outcome of this validation is always a `Results` object, with a list of shortcomings (in its `results` property) of the subject. The `Results` object also has a property `isValid`, which is set to `true` if the subject is valid, or to `false` when it is not.
147
+
148
+ The `validate()` validates the following:
149
+
150
+ - First it will check if the object you are validating is actually defined. If not, validation fails.
151
+ - On value objects (objects that inherit from the `Value` class), it will check the `isValid` property. Therefore, `isValid` is a suitable location for implementing your value objects validity.
152
+ - On enumerations (objects inheriting from the `Enum` class), it will also check the `isValid` property. However, usually, if enumerations are creating through their `byId()` function, if they are not valid, then `byId()` will have returned `undefined`.
153
+
154
+ ### Constraints
155
+ The easiest way to validate objects is to use constraints. By adding constraints, as decorators, to the properties and functions on the object you would like to validate, these properties and functions will be checked when the object is validated through calling `validate(myObject)`. **easy** comes with a variety of ready-to-use constraints, but it is also easy (no pun intended) to add your own.
156
+
157
+ Below is a typical example of an entity, which derives from the `Entity` class in **easy**. It has a number of properties, which are pre-filled with values from the internal state (in `state`) of the entity. As you can see, several of these properties have constraint decorators, such as `@required()`, `@valid()` and `@lt()`. As you can see, properties may have multiple constraints.
158
+
159
+ export class Product extends Entity {
160
+ @required() readonly name: string = this.state.name;
161
+ @required() readonly erpId: Id = this.state.erpId;
162
+ readonly suppliers: List<Id> = toList(this.state.suppliers);
163
+ @valid() readonly ean: Ean = new Ean(this.state.ean);
164
+ @valid() readonly type: ProductType = ProductType.byId(this.state.type);
165
+ readonly brand: string = this.state.brand;
166
+ @gt(0) @lt(100) readonly weight: number = this.state.weight;
167
+ @gt(0, 'Current value {this.height} for height is insufficient.') readonly height: number = this.state.height;
168
+ @gt(0) readonly width: number = this.state.width;
169
+
170
+ update = (add: Json): Product => new Product(this.merge(add));
171
+ }
172
+
173
+ When an instance of the `Product` class is validated, through `validate(myProduct)`, all constraint decorators will be checked.
174
+ If one or more constraints fail, the object is considered as invalid. The outcome of `validate()` will contain a `Results` object that has a list of `Result` objects (consisting of `message`, `location` and `domain`). Each failed constrained will have added a `Result` to the list.
175
+
176
+ Each constraint in **easy** comes with a pre-defined and templated message. However, if needed, you can specify your own messages by adding them to the decorators you use. In the example above, we have added a custom message to the `height` property.
177
+
178
+ ### Custom constraints
179
+ It is quite easy to create your own custom constraints. Below is an example of a custom constraint `is42`.
180
+
181
+ const is42 = (message?: Text): PropertyDecorator => constraint(v => v === 42, message ?? "Property {property} should have value '42' instead of '{actual}'.");
182
+
183
+ This custom constraint makes use of the `constraint()` function in **easy**. The first parameter for your constraint is a function that returns true or false. When you use your new constraint, as a decorator on a property, the `validate()` function will pick it up automatically. If your constraint fails, the message will be added to the results.
184
+
185
+ After creating your custom constraint, you can add them to your classes, like in the example below.
186
+
187
+ class Person extends Struct {
188
+ @valid() readonly age: Age = new Age(this.state.age);
189
+ @is42('Value for real age must be 42, not {actual}.') readonly realAge: number = this.state.age;
190
+ }
191
+
192
+ P.S. If you create custom constraints that might be helpful for other developers, don't hesitate to do a pull request on **easy**.
193
+
194
+ ## Data
195
+ Microservices can use data from a variety of sources, transform and process that data, and expose that to their users through their own API. In the different microservices architecture implementations we've seen data for instance come from:
196
+
197
+ - a variety of relational databases, such as SQL Server, MySQL, or PostgreSQL.
198
+ - a variety of non-relational databases, quite often MongoDB.
199
+ - file systems.
200
+ - systems the organization owns. such as HR, marketing, ERP or CMS.
201
+ - other microservices, internal to the own organization.
202
+ - other microservices, implemented with **easy** too.
203
+ - other services, external to the own organization.
204
+ - systems running in the cloud, such as SalesForce, Office365.
205
+ - identity access platforms, often in the cloud.
206
+ - last but not least, data could even be fixed in the service itself, as a JSON array for instance.
207
+
208
+ ### Gateways
209
+ The data layer in an **easy** microservice provide the service with gateways to all these possible sources. It is the responsibility of the classes in the data layer to fetch and deliver data from outside to the microservices. Depending on the type of the source, **easy** provides a number of gateways, which all implement the `Gateway` interface:
210
+
211
+ - `InMemoryGateway` (formerly `CollectionGateway`). Used to provide data which is statically stored inside the services, e.g. in a JSON array.
212
+ - `RouteGateway`. This allows services to talk to other API's, using a predefined URI. This gateway is often used for talking to other **easy** services, which provide a similar experience and API.
213
+ - `MappedRouteGateway`. It allows services to talk to other API's, similar to the `RouteGateway`, but with the ability to map the incoming data (in JSON format) to an internally preferred format. This mapping is based on an instance of the `Map` class.
214
+ - `TableGateway`. This allows to get data (in JSON format) from a relational database. It uses a `QueryProvider` to connect to a specific relational database. We're currently adding providers for SQL Server, MySQL, and PostgreSQL. It uses a `Table` to map the incoming data to the format internal to the service.
215
+ - `CollectionGateway` (formerly `MongoGateway`). It allows to get data (in JSON format) from a document database, for now MongoDB. It uses the `MongoProvider` to connect to the database. It uses a `Collection` to map the incoming data to the format internal to the service.
216
+
217
+ ### The `Map`, `Table`, and `Collection` mappings
218
+ Because data in existing databases rarely supplies the format you need in your service, you can define a `Map` (for other services), a `Table` (for relational databases), or a `Collection` (for MongoDB) to contain all mappings that transform the incoming data to the service internal format, as below.
219
+
220
+ export class ErpProductView extends Table {
221
+ readonly db = MyDatabase.Erp;
222
+ readonly id = this.prop('id', { convert: toId.fromLegacyId });
223
+ readonly brandId = this.prop('brandId', { convert: toId.fromLegacyId });
224
+
225
+ toString(): string {
226
+ return 'mover_product_view';
227
+ }
228
+ }
229
+
230
+ The `Map` and `Table` classes have a property called `db` that represents the database to connect to. This is usually an instance of the `Database` enumeration, which in its turn defines the database (and its provider) to connect to, as in the example below.
231
+
232
+ export class MyDatabase extends Database {
233
+ static readonly Erp = new Database('openerp', PostgreSqlProvider);
234
+ static readonly Cms = new Database('cms', MySqlProvider);
235
+ }
236
+
237
+ Next, the `Map`, `Table` and `Collection` classes, describe a list of properties that you would want mapped in the incoming JSON. Properties in the incoming JSON that are not described here are copied automatically. Properties can use converters, e.g. to converter from number to string and vice versa. Converters are bi-directional, as data that needs to go from the service to storage is mapped back to the database specific format too.
238
+
239
+ ## Handling exceptions in services
240
+ During the execution of a request, lots of things can go wrong. Here as some common failures that occur when you try to reach an endpoint, and how **easy** normally responds, and where and how such failures are handled in a typical **easy** microservices:
241
+
242
+ * For starters, you might not reach the endpoint, because you've typed in the wrong URL. If this happens, and you still reach your microservice, **easy** handles this in the `NotFoundHandler`, which is plugged-in by default.
243
+ * If you are not allowed to execute an endpoint, for instance because it is secured with one of the security decorators in **easy**, such as `@requires.useCase()`, `@requires.Scope()` or `@requires.token`, the endpoint will not execute, and you will receive a 403. In this case the middleware from the `SecurityHandler` already breaks the loop, and the code in you microservices is not executed at all.
244
+ * All other failures are handled by the `ErrorHandler`, and can result in any custom HTTP status code, most likely a 400, or a 500. In case the caller makes a mistake, the code should come from the 400 range, in cases the microservice makes the mistake, the code comes from the 500 range.
245
+
246
+ ## Utilities
247
+ Additionally, this library contains utility classes for standardizing e.g. uri's, and ids, constructors, lists, queries, and errors. Quite often these are constructed as monads, which renders robust code.
248
+
249
+ ### When
250
+ The `When` class is a utility that is usually exposed through the `when()` function. It is one of many monads we use in **easy** to make code more robust, and easier to read. It can be used to make validations in promises a little easier such as the following example.
251
+
252
+ update = (json: Json): Promise<T> =>
253
+ this.gateway
254
+ .byId(json.id as Id)
255
+ .then(j => when(j).not.isDefined.reject(Exception.DoesNotExist))
256
+ .then(j => new this.ctor(j).update(json))
257
+ .then(i => when(i).not.isValid.reject())
258
+ .then(i => this.gateway.update(toJson(i)))
259
+ .then(j => new this.ctor(j));
260
+
261
+ The `reject()` method is used to reject the chain, so it will not execute any of its following statements. The `reject()` method accept any error type. A special case is made for `when().not.isValid`. This statement validates the subject of the `when`, and reject with the results (an instance of `Results`) if no parameter is passed to `reject()`.
262
+
263
+ ## Authentication and Authorization
264
+ Access to endpoints is configured using the `@requires` decorator group. If multiple decorators are added, all conditions must be met to access the endpoint. A resource class (which is the main entry to an **easy** service) with security decorators is shown in the following example.
265
+
266
+ @route(ProductUri.Products)
267
+ export class ProductsResource {
268
+ constructor(readonly manage = new ManageProduct()) {}
269
+
270
+ @get()
271
+ @requires.useCase(UseCase.ViewProduct)
272
+ search = (req: Req): Promise<List<Product>> => this.manage.search(req.q);
273
+
274
+ @post()
275
+ @requires.useCase(UseCase.ManageProduct)
276
+ add = (req: Req): Promise<Product> => this.manage.add(req.body as Json);
277
+ }
278
+
279
+ The `@requires` decorator group also contains `@requires.labCoat()` this decorator can be added to endpoints you only want to be available on your development environment, for example a `delete`.
280
+
281
+ To use these decorators, the generic `security` middleware must be loaded first. In most cases, it should be added to the `pre` list of handlers of a service.
282
+ The security middleware takes an optional configuration object, which is documented [in code](packages/easy-express/src/express/SecurityHandler.ts).
@@ -0,0 +1,132 @@
1
+ // src/enums/Currency.ts
2
+ import { Enum } from "@thisisagile/easy";
3
+ var Currency = class _Currency extends Enum {
4
+ constructor(id, name, digits, code) {
5
+ super(name, id, code);
6
+ this.digits = digits;
7
+ }
8
+ static EUR = new _Currency("EUR", "Euro", 2, "\u20AC");
9
+ static USD = new _Currency("USD", "US Dollar", 2, "$");
10
+ static AED = new _Currency("AED", "United Arab Emirates Dirham", 2, "AED");
11
+ static AFN = new _Currency("AFN", "Afghan Afghani", 0, "Af");
12
+ static ALL = new _Currency("ALL", "Albanian Lek", 0, "ALL");
13
+ static AMD = new _Currency("AMD", "Armenian Dram", 0, "AMD");
14
+ static ARS = new _Currency("ARS", "Argentine Peso", 2, "AR$");
15
+ static AUD = new _Currency("AUD", "Australian Dollar", 2, "AU$");
16
+ static AZN = new _Currency("AZN", "Azerbaijani Manat", 2, "man.");
17
+ static BAM = new _Currency("BAM", "Bosnia-Herzegovina Convertible Mark", 2, "KM");
18
+ static BDT = new _Currency("BDT", "Bangladeshi Taka", 2, "Tk");
19
+ static BGN = new _Currency("BGN", "Bulgarian Lev", 2, "BGN");
20
+ static BHD = new _Currency("BHD", "Bahraini Dinar", 3, "BD");
21
+ static BIF = new _Currency("BIF", "Burundian Franc", 0, "FBu");
22
+ static BND = new _Currency("BND", "Brunei Dollar", 2, "BN$");
23
+ static BOB = new _Currency("BOB", "Bolivian Boliviano", 2, "Bs");
24
+ static BRL = new _Currency("BRL", "Brazilian Real", 2, "R$");
25
+ static BWP = new _Currency("BWP", "Botswanan Pula", 2, "BWP");
26
+ static BYN = new _Currency("BYN", "Belarusian Ruble", 2, "Br");
27
+ static BZD = new _Currency("BZD", "Belize Dollar", 2, "BZ$");
28
+ static CAD = new _Currency("CAD", "Canadian Dollar", 2, "CA$");
29
+ static CDF = new _Currency("CDF", "Congolese Franc", 2, "CDF");
30
+ static CHF = new _Currency("CHF", "Swiss Franc", 2, "CHF");
31
+ static CLP = new _Currency("CLP", "Chilean Peso", 0, "CL$");
32
+ static CNY = new _Currency("CNY", "Chinese Yuan", 2, "CN\xA5");
33
+ static COP = new _Currency("COP", "Colombian Peso", 0, "CO$");
34
+ static CRC = new _Currency("CRC", "Costa Rican Col\xF3n", 0, "\u20A1");
35
+ static CVE = new _Currency("CVE", "Cape Verdean Escudo", 2, "CV$");
36
+ static CZK = new _Currency("CZK", "Czech Republic Koruna", 2, "K\u010D");
37
+ static DJF = new _Currency("DJF", "Djiboutian Franc", 0, "Fdj");
38
+ static DKK = new _Currency("DKK", "Danish Krone", 2, "Dkr");
39
+ static DOP = new _Currency("DOP", "Dominican Peso", 2, "RD$");
40
+ static DZD = new _Currency("DZD", "Algerian Dinar", 2, "DA");
41
+ static EEK = new _Currency("EEK", "Estonian Kroon", 2, "Ekr");
42
+ static EGP = new _Currency("EGP", "Egyptian Pound", 2, "EGP");
43
+ static ERN = new _Currency("ERN", "Eritrean Nakfa", 2, "Nfk");
44
+ static ETB = new _Currency("ETB", "Ethiopian Birr", 2, "Br");
45
+ static GBP = new _Currency("GBP", "British Pound Sterling", 2, "\xA3");
46
+ static GEL = new _Currency("GEL", "Georgian Lari", 2, "GEL");
47
+ static GHS = new _Currency("GHS", "Ghanaian Cedi", 2, "GH\u20B5");
48
+ static GNF = new _Currency("GNF", "Guinean Franc", 0, "FG");
49
+ static GTQ = new _Currency("GTQ", "Guatemalan Quetzal", 2, "GTQ");
50
+ static HKD = new _Currency("HKD", "Hong Kong Dollar", 2, "HK$");
51
+ static HNL = new _Currency("HNL", "Honduran Lempira", 2, "HNL");
52
+ static HRK = new _Currency("HRK", "Croatian Kuna", 2, "kn");
53
+ static HUF = new _Currency("HUF", "Hungarian Forint", 0, "Ft");
54
+ static IDR = new _Currency("IDR", "Indonesian Rupiah", 0, "Rp");
55
+ static ILS = new _Currency("ILS", "Israeli New Sheqel", 2, "\u20AA");
56
+ static INR = new _Currency("INR", "Indian Rupee", 2, "Rs");
57
+ static IQD = new _Currency("IQD", "Iraqi Dinar", 0, "IQD");
58
+ static IRR = new _Currency("IRR", "Iranian Rial", 0, "IRR");
59
+ static ISK = new _Currency("ISK", "Icelandic Kr\xF3na", 0, "Ikr");
60
+ static JMD = new _Currency("JMD", "Jamaican Dollar", 2, "J$");
61
+ static JOD = new _Currency("JOD", "Jordanian Dinar", 3, "JD");
62
+ static JPY = new _Currency("JPY", "Japanese Yen", 0, "\xA5");
63
+ static KES = new _Currency("KES", "Kenyan Shilling", 2, "Ksh");
64
+ static KHR = new _Currency("KHR", "Cambodian Riel", 2, "KHR");
65
+ static KMF = new _Currency("KMF", "Comorian Franc", 0, "CF");
66
+ static KRW = new _Currency("KRW", "South Korean Won", 0, "\u20A9");
67
+ static KWD = new _Currency("KWD", "Kuwaiti Dinar", 3, "KD");
68
+ static KZT = new _Currency("KZT", "Kazakhstani Tenge", 2, "KZT");
69
+ static LBP = new _Currency("LBP", "Lebanese Pound", 0, "L.L.");
70
+ static LKR = new _Currency("LKR", "Sri Lankan Rupee", 2, "SLRs");
71
+ static LTL = new _Currency("LTL", "Lithuanian Litas", 2, "Lt");
72
+ static LVL = new _Currency("LVL", "Latvian Lats", 2, "Ls");
73
+ static LYD = new _Currency("LYD", "Libyan Dinar", 3, "LD");
74
+ static MAD = new _Currency("MAD", "Moroccan Dirham", 2, "MAD");
75
+ static MDL = new _Currency("MDL", "Moldovan Leu", 2, "MDL");
76
+ static MGA = new _Currency("MGA", "Malagasy Ariary", 0, "MGA");
77
+ static MKD = new _Currency("MKD", "Macedonian Denar", 2, "MKD");
78
+ static MMK = new _Currency("MMK", "Myanma Kyat", 0, "MMK");
79
+ static MOP = new _Currency("MOP", "Macanese Pataca", 2, "MOP$");
80
+ static MUR = new _Currency("MUR", "Mauritian Rupee", 0, "MURs");
81
+ static MXN = new _Currency("MXN", "Mexican Peso", 2, "MX$");
82
+ static MYR = new _Currency("MYR", "Malaysian Ringgit", 2, "RM");
83
+ static MZN = new _Currency("MZN", "Mozambican Metical", 2, "MTn");
84
+ static NAD = new _Currency("NAD", "Namibian Dollar", 2, "N$");
85
+ static NGN = new _Currency("NGN", "Nigerian Naira", 2, "\u20A6");
86
+ static NIO = new _Currency("NIO", "Nicaraguan C\xF3rdoba", 2, "C$");
87
+ static NOK = new _Currency("NOK", "Norwegian Krone", 2, "Nkr");
88
+ static NPR = new _Currency("NPR", "Nepalese Rupee", 2, "NPRs");
89
+ static NZD = new _Currency("NZD", "New Zealand Dollar", 2, "NZ$");
90
+ static OMR = new _Currency("OMR", "Omani Rial", 3, "OMR");
91
+ static PAB = new _Currency("PAB", "Panamanian Balboa", 2, "B/.");
92
+ static PEN = new _Currency("PEN", "Peruvian Nuevo Sol", 2, "S/.");
93
+ static PHP = new _Currency("PHP", "Philippine Peso", 2, "\u20B1");
94
+ static PKR = new _Currency("PKR", "Pakistani Rupee", 0, "PKRs");
95
+ static PLN = new _Currency("PLN", "Polish Zloty", 2, "z\u0142");
96
+ static PYG = new _Currency("PYG", "Paraguayan Guarani", 0, "\u20B2");
97
+ static QAR = new _Currency("QAR", "Qatari Rial", 2, "QR");
98
+ static RON = new _Currency("RON", "Romanian Leu", 2, "RON");
99
+ static RSD = new _Currency("RSD", "Serbian Dinar", 0, "din.");
100
+ static RUB = new _Currency("RUB", "Russian Ruble", 2, "RUB");
101
+ static RWF = new _Currency("RWF", "Rwandan Franc", 0, "RWF");
102
+ static SAR = new _Currency("SAR", "Saudi Riyal", 2, "SR");
103
+ static SDG = new _Currency("SDG", "Sudanese Pound", 2, "SDG");
104
+ static SEK = new _Currency("SEK", "Swedish Krona", 2, "Skr");
105
+ static SGD = new _Currency("SGD", "Singapore Dollar", 2, "S$");
106
+ static SOS = new _Currency("SOS", "Somali Shilling", 0, "Ssh");
107
+ static SYP = new _Currency("SYP", "Syrian Pound", 0, "SY\xA3");
108
+ static THB = new _Currency("THB", "Thai Baht", 2, "\u0E3F");
109
+ static TND = new _Currency("TND", "Tunisian Dinar", 3, "DT");
110
+ static TOP = new _Currency("TOP", "Tongan Pa\u02BBanga", 2, "T$");
111
+ static TRY = new _Currency("TRY", "Turkish Lira", 2, "TL");
112
+ static TTD = new _Currency("TTD", "Trinidad and Tobago Dollar", 2, "TT$");
113
+ static TWD = new _Currency("TWD", "New Taiwan Dollar", 2, "NT$");
114
+ static TZS = new _Currency("TZS", "Tanzanian Shilling", 0, "TSh");
115
+ static UAH = new _Currency("UAH", "Ukrainian Hryvnia", 2, "\u20B4");
116
+ static UGX = new _Currency("UGX", "Ugandan Shilling", 0, "USh");
117
+ static UYU = new _Currency("UYU", "Uruguayan Peso", 2, "$U");
118
+ static UZS = new _Currency("UZS", "Uzbekistan Som", 0, "UZS");
119
+ static VEF = new _Currency("VEF", "Venezuelan Bol\xEDvar", 2, "Bs.F.");
120
+ static VND = new _Currency("VND", "Vietnamese Dong", 0, "\u20AB");
121
+ static XAF = new _Currency("XAF", "CFA Franc BEAC", 0, "FCFA");
122
+ static XOF = new _Currency("XOF", "CFA Franc BCEAO", 0, "CFA");
123
+ static YER = new _Currency("YER", "Yemeni Rial", 0, "YR");
124
+ static ZAR = new _Currency("ZAR", "South African Rand", 2, "R");
125
+ static ZMK = new _Currency("ZMK", "Zambian Kwacha", 0, "ZK");
126
+ static ZWL = new _Currency("ZWL", "Zimbabwean Dollar", 0, "ZWL$");
127
+ };
128
+
129
+ export {
130
+ Currency
131
+ };
132
+ //# sourceMappingURL=chunk-3N5M6QHW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/enums/Currency.ts"],"sourcesContent":["import { Enum } from '@thisisagile/easy';\n\nexport class Currency extends Enum {\n constructor(\n id: string,\n name: string,\n readonly digits: number,\n code: string\n ) {\n super(name, id, code);\n }\n static readonly EUR = new Currency('EUR', 'Euro', 2, '€');\n static readonly USD = new Currency('USD', 'US Dollar', 2, '$');\n static readonly AED = new Currency('AED', 'United Arab Emirates Dirham', 2, 'AED');\n static readonly AFN = new Currency('AFN', 'Afghan Afghani', 0, 'Af');\n static readonly ALL = new Currency('ALL', 'Albanian Lek', 0, 'ALL');\n static readonly AMD = new Currency('AMD', 'Armenian Dram', 0, 'AMD');\n static readonly ARS = new Currency('ARS', 'Argentine Peso', 2, 'AR$');\n static readonly AUD = new Currency('AUD', 'Australian Dollar', 2, 'AU$');\n static readonly AZN = new Currency('AZN', 'Azerbaijani Manat', 2, 'man.');\n static readonly BAM = new Currency('BAM', 'Bosnia-Herzegovina Convertible Mark', 2, 'KM');\n static readonly BDT = new Currency('BDT', 'Bangladeshi Taka', 2, 'Tk');\n static readonly BGN = new Currency('BGN', 'Bulgarian Lev', 2, 'BGN');\n static readonly BHD = new Currency('BHD', 'Bahraini Dinar', 3, 'BD');\n static readonly BIF = new Currency('BIF', 'Burundian Franc', 0, 'FBu');\n static readonly BND = new Currency('BND', 'Brunei Dollar', 2, 'BN$');\n static readonly BOB = new Currency('BOB', 'Bolivian Boliviano', 2, 'Bs');\n static readonly BRL = new Currency('BRL', 'Brazilian Real', 2, 'R$');\n static readonly BWP = new Currency('BWP', 'Botswanan Pula', 2, 'BWP');\n static readonly BYN = new Currency('BYN', 'Belarusian Ruble', 2, 'Br');\n static readonly BZD = new Currency('BZD', 'Belize Dollar', 2, 'BZ$');\n static readonly CAD = new Currency('CAD', 'Canadian Dollar', 2, 'CA$');\n static readonly CDF = new Currency('CDF', 'Congolese Franc', 2, 'CDF');\n static readonly CHF = new Currency('CHF', 'Swiss Franc', 2, 'CHF');\n static readonly CLP = new Currency('CLP', 'Chilean Peso', 0, 'CL$');\n static readonly CNY = new Currency('CNY', 'Chinese Yuan', 2, 'CN¥');\n static readonly COP = new Currency('COP', 'Colombian Peso', 0, 'CO$');\n static readonly CRC = new Currency('CRC', 'Costa Rican Colón', 0, '₡');\n static readonly CVE = new Currency('CVE', 'Cape Verdean Escudo', 2, 'CV$');\n static readonly CZK = new Currency('CZK', 'Czech Republic Koruna', 2, 'Kč');\n static readonly DJF = new Currency('DJF', 'Djiboutian Franc', 0, 'Fdj');\n static readonly DKK = new Currency('DKK', 'Danish Krone', 2, 'Dkr');\n static readonly DOP = new Currency('DOP', 'Dominican Peso', 2, 'RD$');\n static readonly DZD = new Currency('DZD', 'Algerian Dinar', 2, 'DA');\n static readonly EEK = new Currency('EEK', 'Estonian Kroon', 2, 'Ekr');\n static readonly EGP = new Currency('EGP', 'Egyptian Pound', 2, 'EGP');\n static readonly ERN = new Currency('ERN', 'Eritrean Nakfa', 2, 'Nfk');\n static readonly ETB = new Currency('ETB', 'Ethiopian Birr', 2, 'Br');\n static readonly GBP = new Currency('GBP', 'British Pound Sterling', 2, '£');\n static readonly GEL = new Currency('GEL', 'Georgian Lari', 2, 'GEL');\n static readonly GHS = new Currency('GHS', 'Ghanaian Cedi', 2, 'GH₵');\n static readonly GNF = new Currency('GNF', 'Guinean Franc', 0, 'FG');\n static readonly GTQ = new Currency('GTQ', 'Guatemalan Quetzal', 2, 'GTQ');\n static readonly HKD = new Currency('HKD', 'Hong Kong Dollar', 2, 'HK$');\n static readonly HNL = new Currency('HNL', 'Honduran Lempira', 2, 'HNL');\n static readonly HRK = new Currency('HRK', 'Croatian Kuna', 2, 'kn');\n static readonly HUF = new Currency('HUF', 'Hungarian Forint', 0, 'Ft');\n static readonly IDR = new Currency('IDR', 'Indonesian Rupiah', 0, 'Rp');\n static readonly ILS = new Currency('ILS', 'Israeli New Sheqel', 2, '₪');\n static readonly INR = new Currency('INR', 'Indian Rupee', 2, 'Rs');\n static readonly IQD = new Currency('IQD', 'Iraqi Dinar', 0, 'IQD');\n static readonly IRR = new Currency('IRR', 'Iranian Rial', 0, 'IRR');\n static readonly ISK = new Currency('ISK', 'Icelandic Króna', 0, 'Ikr');\n static readonly JMD = new Currency('JMD', 'Jamaican Dollar', 2, 'J$');\n static readonly JOD = new Currency('JOD', 'Jordanian Dinar', 3, 'JD');\n static readonly JPY = new Currency('JPY', 'Japanese Yen', 0, '¥');\n static readonly KES = new Currency('KES', 'Kenyan Shilling', 2, 'Ksh');\n static readonly KHR = new Currency('KHR', 'Cambodian Riel', 2, 'KHR');\n static readonly KMF = new Currency('KMF', 'Comorian Franc', 0, 'CF');\n static readonly KRW = new Currency('KRW', 'South Korean Won', 0, '₩');\n static readonly KWD = new Currency('KWD', 'Kuwaiti Dinar', 3, 'KD');\n static readonly KZT = new Currency('KZT', 'Kazakhstani Tenge', 2, 'KZT');\n static readonly LBP = new Currency('LBP', 'Lebanese Pound', 0, 'L.L.');\n static readonly LKR = new Currency('LKR', 'Sri Lankan Rupee', 2, 'SLRs');\n static readonly LTL = new Currency('LTL', 'Lithuanian Litas', 2, 'Lt');\n static readonly LVL = new Currency('LVL', 'Latvian Lats', 2, 'Ls');\n static readonly LYD = new Currency('LYD', 'Libyan Dinar', 3, 'LD');\n static readonly MAD = new Currency('MAD', 'Moroccan Dirham', 2, 'MAD');\n static readonly MDL = new Currency('MDL', 'Moldovan Leu', 2, 'MDL');\n static readonly MGA = new Currency('MGA', 'Malagasy Ariary', 0, 'MGA');\n static readonly MKD = new Currency('MKD', 'Macedonian Denar', 2, 'MKD');\n static readonly MMK = new Currency('MMK', 'Myanma Kyat', 0, 'MMK');\n static readonly MOP = new Currency('MOP', 'Macanese Pataca', 2, 'MOP$');\n static readonly MUR = new Currency('MUR', 'Mauritian Rupee', 0, 'MURs');\n static readonly MXN = new Currency('MXN', 'Mexican Peso', 2, 'MX$');\n static readonly MYR = new Currency('MYR', 'Malaysian Ringgit', 2, 'RM');\n static readonly MZN = new Currency('MZN', 'Mozambican Metical', 2, 'MTn');\n static readonly NAD = new Currency('NAD', 'Namibian Dollar', 2, 'N$');\n static readonly NGN = new Currency('NGN', 'Nigerian Naira', 2, '₦');\n static readonly NIO = new Currency('NIO', 'Nicaraguan Córdoba', 2, 'C$');\n static readonly NOK = new Currency('NOK', 'Norwegian Krone', 2, 'Nkr');\n static readonly NPR = new Currency('NPR', 'Nepalese Rupee', 2, 'NPRs');\n static readonly NZD = new Currency('NZD', 'New Zealand Dollar', 2, 'NZ$');\n static readonly OMR = new Currency('OMR', 'Omani Rial', 3, 'OMR');\n static readonly PAB = new Currency('PAB', 'Panamanian Balboa', 2, 'B/.');\n static readonly PEN = new Currency('PEN', 'Peruvian Nuevo Sol', 2, 'S/.');\n static readonly PHP = new Currency('PHP', 'Philippine Peso', 2, '₱');\n static readonly PKR = new Currency('PKR', 'Pakistani Rupee', 0, 'PKRs');\n static readonly PLN = new Currency('PLN', 'Polish Zloty', 2, 'zł');\n static readonly PYG = new Currency('PYG', 'Paraguayan Guarani', 0, '₲');\n static readonly QAR = new Currency('QAR', 'Qatari Rial', 2, 'QR');\n static readonly RON = new Currency('RON', 'Romanian Leu', 2, 'RON');\n static readonly RSD = new Currency('RSD', 'Serbian Dinar', 0, 'din.');\n static readonly RUB = new Currency('RUB', 'Russian Ruble', 2, 'RUB');\n static readonly RWF = new Currency('RWF', 'Rwandan Franc', 0, 'RWF');\n static readonly SAR = new Currency('SAR', 'Saudi Riyal', 2, 'SR');\n static readonly SDG = new Currency('SDG', 'Sudanese Pound', 2, 'SDG');\n static readonly SEK = new Currency('SEK', 'Swedish Krona', 2, 'Skr');\n static readonly SGD = new Currency('SGD', 'Singapore Dollar', 2, 'S$');\n static readonly SOS = new Currency('SOS', 'Somali Shilling', 0, 'Ssh');\n static readonly SYP = new Currency('SYP', 'Syrian Pound', 0, 'SY£');\n static readonly THB = new Currency('THB', 'Thai Baht', 2, '฿');\n static readonly TND = new Currency('TND', 'Tunisian Dinar', 3, 'DT');\n static readonly TOP = new Currency('TOP', 'Tongan Paʻanga', 2, 'T$');\n static readonly TRY = new Currency('TRY', 'Turkish Lira', 2, 'TL');\n static readonly TTD = new Currency('TTD', 'Trinidad and Tobago Dollar', 2, 'TT$');\n static readonly TWD = new Currency('TWD', 'New Taiwan Dollar', 2, 'NT$');\n static readonly TZS = new Currency('TZS', 'Tanzanian Shilling', 0, 'TSh');\n static readonly UAH = new Currency('UAH', 'Ukrainian Hryvnia', 2, '₴');\n static readonly UGX = new Currency('UGX', 'Ugandan Shilling', 0, 'USh');\n static readonly UYU = new Currency('UYU', 'Uruguayan Peso', 2, '$U');\n static readonly UZS = new Currency('UZS', 'Uzbekistan Som', 0, 'UZS');\n static readonly VEF = new Currency('VEF', 'Venezuelan Bolívar', 2, 'Bs.F.');\n static readonly VND = new Currency('VND', 'Vietnamese Dong', 0, '₫');\n static readonly XAF = new Currency('XAF', 'CFA Franc BEAC', 0, 'FCFA');\n static readonly XOF = new Currency('XOF', 'CFA Franc BCEAO', 0, 'CFA');\n static readonly YER = new Currency('YER', 'Yemeni Rial', 0, 'YR');\n static readonly ZAR = new Currency('ZAR', 'South African Rand', 2, 'R');\n static readonly ZMK = new Currency('ZMK', 'Zambian Kwacha', 0, 'ZK');\n static readonly ZWL = new Currency('ZWL', 'Zimbabwean Dollar', 0, 'ZWL$');\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAEd,IAAM,WAAN,MAAM,kBAAiB,KAAK;AAAA,EACjC,YACE,IACA,MACS,QACT,MACA;AACA,UAAM,MAAM,IAAI,IAAI;AAHX;AAAA,EAIX;AAAA,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MAAM,IAAI,UAAS,OAAO,sBAAsB,GAAG,GAAG;AAAA,EACtE,OAAgB,MAAM,IAAI,UAAS,OAAO,kBAAkB,GAAG,IAAI;AAAA,EACnE,OAAgB,MAAM,IAAI,UAAS,OAAO,qBAAqB,GAAG,MAAM;AAC1E;","names":[]}
@@ -0,0 +1,16 @@
1
+ // src/enums/UnitOfWeight.ts
2
+ import { Enum } from "@thisisagile/easy";
3
+ var UnitOfWeight = class _UnitOfWeight extends Enum {
4
+ constructor(name, id, gMultiplier) {
5
+ super(name, id);
6
+ this.gMultiplier = gMultiplier;
7
+ }
8
+ static MG = new _UnitOfWeight("MilliGram", "mg", 1e-3);
9
+ static G = new _UnitOfWeight("Gram", "g", 1);
10
+ static KG = new _UnitOfWeight("Kilogram", "kg", 1e3);
11
+ };
12
+
13
+ export {
14
+ UnitOfWeight
15
+ };
16
+ //# sourceMappingURL=chunk-CKW4QYDN.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/enums/UnitOfWeight.ts"],"sourcesContent":["import { Enum } from '@thisisagile/easy';\n\nexport class UnitOfWeight extends Enum {\n static readonly MG = new UnitOfWeight('MilliGram', 'mg', 0.001);\n static readonly G = new UnitOfWeight('Gram', 'g', 1);\n static readonly KG = new UnitOfWeight('Kilogram', 'kg', 1000);\n\n constructor(\n name: string,\n id: string,\n readonly gMultiplier: number\n ) {\n super(name, id);\n }\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAEd,IAAM,eAAN,MAAM,sBAAqB,KAAK;AAAA,EAKrC,YACE,MACA,IACS,aACT;AACA,UAAM,MAAM,EAAE;AAFL;AAAA,EAGX;AAAA,EAVA,OAAgB,KAAK,IAAI,cAAa,aAAa,MAAM,IAAK;AAAA,EAC9D,OAAgB,IAAI,IAAI,cAAa,QAAQ,KAAK,CAAC;AAAA,EACnD,OAAgB,KAAK,IAAI,cAAa,YAAY,MAAM,GAAI;AAS9D;","names":[]}
@@ -0,0 +1,35 @@
1
+ import {
2
+ UnitOfMeasurement
3
+ } from "./chunk-XBORRJ6W.mjs";
4
+ import {
5
+ __decorateClass
6
+ } from "./chunk-RDITZTSA.mjs";
7
+
8
+ // src/structs/Dimension.ts
9
+ import { Struct, required } from "@thisisagile/easy";
10
+ var _Dimension = class _Dimension extends Struct {
11
+ value = this.state.value;
12
+ uom = UnitOfMeasurement.byId(this.state.uom, UnitOfMeasurement.MM);
13
+ static with = (value, uom = UnitOfMeasurement.MM) => new _Dimension({ value, uom });
14
+ /**
15
+ @deprecated use inMilliMeters getter instead
16
+ */
17
+ sizeInMM() {
18
+ return this.inMilliMeters;
19
+ }
20
+ get inMilliMeters() {
21
+ return this.value * this.uom.mmMultiplier;
22
+ }
23
+ gte(dim) {
24
+ return this.inMilliMeters >= dim.inMilliMeters;
25
+ }
26
+ };
27
+ __decorateClass([
28
+ required()
29
+ ], _Dimension.prototype, "value", 2);
30
+ var Dimension = _Dimension;
31
+
32
+ export {
33
+ Dimension
34
+ };
35
+ //# sourceMappingURL=chunk-H2VHSGNX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/structs/Dimension.ts"],"sourcesContent":["import { Struct, required } from '@thisisagile/easy';\nimport { UnitOfMeasurement } from '../enums/UnitOfMeasurement';\n\nexport class Dimension extends Struct {\n @required() readonly value = this.state.value as number;\n readonly uom = UnitOfMeasurement.byId<UnitOfMeasurement>(this.state.uom, UnitOfMeasurement.MM);\n\n static with = (value: number, uom: UnitOfMeasurement = UnitOfMeasurement.MM) => new Dimension({ value, uom });\n\n /**\n @deprecated use inMilliMeters getter instead\n */\n sizeInMM(): number {\n return this.inMilliMeters;\n }\n\n get inMilliMeters(): number {\n return this.value * this.uom.mmMultiplier;\n }\n\n gte(dim: Dimension): boolean {\n return this.inMilliMeters >= dim.inMilliMeters;\n }\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,QAAQ,gBAAgB;AAG1B,IAAM,aAAN,MAAM,mBAAkB,OAAO;AAAA,EACf,QAAQ,KAAK,MAAM;AAAA,EAC/B,MAAM,kBAAkB,KAAwB,KAAK,MAAM,KAAK,kBAAkB,EAAE;AAAA,EAE7F,OAAO,OAAO,CAAC,OAAe,MAAyB,kBAAkB,OAAO,IAAI,WAAU,EAAE,OAAO,IAAI,CAAC;AAAA;AAAA;AAAA;AAAA,EAK5G,WAAmB;AACjB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,gBAAwB;AAC1B,WAAO,KAAK,QAAQ,KAAK,IAAI;AAAA,EAC/B;AAAA,EAEA,IAAI,KAAyB;AAC3B,WAAO,KAAK,iBAAiB,IAAI;AAAA,EACnC;AACF;AAnBuB;AAAA,EAApB,SAAS;AAAA,GADC,WACU;AADhB,IAAM,YAAN;","names":[]}