@wisemen/quantity 0.9.0 → 0.9.1
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.
- package/dist/index.d.ts +10 -10
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/quantities/voltage/index.d.ts +1 -0
- package/dist/quantities/voltage/index.js +1 -0
- package/dist/quantities/voltage/index.js.map +1 -1
- package/package.json +3 -2
- package/skills/getting-started/SKILL.md +78 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
1
|
+
export { Current, CurrentUnit, CurrentDto, CurrentDtoBuilder, CurrentUnitApiProperty, IsCurrent, CurrentColumn } from './quantities/current/index.js';
|
|
2
|
+
export { Distance, DistanceUnit, DistanceDto, DistanceDtoBuilder, DistanceUnitApiProperty, IsDistance, DistanceColumn } from './quantities/distance/index.js';
|
|
3
|
+
export { Duration, DurationUnit, DurationDto, DurationDtoBuilder, DurationUnitApiProperty, IsDuration, DurationColumn } from './quantities/duration/index.js';
|
|
4
|
+
export { Mass, MassUnit, MassDto, MassDtoBuilder, MassUnitApiProperty, IsMass, MassColumn } from './quantities/mass/index.js';
|
|
5
|
+
export { Temperature, TemperatureUnit, TemperatureDto, TemperatureDtoBuilder, TemperatureUnitApiProperty, IsTemperature, TemperatureColumn } from './quantities/temperature/index.js';
|
|
6
|
+
export { Energy, EnergyUnit, EnergyDto, EnergyDtoBuilder, EnergyUnitApiProperty, IsEnergy, EnergyColumn } from './quantities/energy/index.js';
|
|
7
|
+
export { Power, PowerUnit, PowerDto, PowerDtoBuilder, PowerUnitApiProperty, IsPower, PowerColumn } from './quantities/power/index.js';
|
|
8
|
+
export { Speed, SpeedUnit, SpeedDto, SpeedDtoBuilder, SpeedUnitApiProperty, IsSpeed, SpeedColumn } from './quantities/speed/index.js';
|
|
9
|
+
export { Voltage, VoltageUnit, VoltageDto, VoltageDtoBuilder, VoltageUnitApiProperty, IsVoltage, VoltageColumn } from './quantities/voltage/index.js';
|
|
10
|
+
export { Rate, RateScale, RateDto, RateDtoBuilder, RateScaleApiProperty, IsRate, RateColumn } from './rate/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
1
|
+
export { Current, CurrentUnit, CurrentDto, CurrentDtoBuilder, CurrentUnitApiProperty, IsCurrent, CurrentColumn } from './quantities/current/index.js';
|
|
2
|
+
export { Distance, DistanceUnit, DistanceDto, DistanceDtoBuilder, DistanceUnitApiProperty, IsDistance, DistanceColumn } from './quantities/distance/index.js';
|
|
3
|
+
export { Duration, DurationUnit, DurationDto, DurationDtoBuilder, DurationUnitApiProperty, IsDuration, DurationColumn } from './quantities/duration/index.js';
|
|
4
|
+
export { Mass, MassUnit, MassDto, MassDtoBuilder, MassUnitApiProperty, IsMass, MassColumn } from './quantities/mass/index.js';
|
|
5
|
+
export { Temperature, TemperatureUnit, TemperatureDto, TemperatureDtoBuilder, TemperatureUnitApiProperty, IsTemperature, TemperatureColumn } from './quantities/temperature/index.js';
|
|
6
|
+
export { Energy, EnergyUnit, EnergyDto, EnergyDtoBuilder, EnergyUnitApiProperty, IsEnergy, EnergyColumn } from './quantities/energy/index.js';
|
|
7
|
+
export { Power, PowerUnit, PowerDto, PowerDtoBuilder, PowerUnitApiProperty, IsPower, PowerColumn } from './quantities/power/index.js';
|
|
8
|
+
export { Speed, SpeedUnit, SpeedDto, SpeedDtoBuilder, SpeedUnitApiProperty, IsSpeed, SpeedColumn } from './quantities/speed/index.js';
|
|
9
|
+
export { Voltage, VoltageUnit, VoltageDto, VoltageDtoBuilder, VoltageUnitApiProperty, IsVoltage, VoltageColumn } from './quantities/voltage/index.js';
|
|
10
|
+
export { Rate, RateScale, RateDto, RateDtoBuilder, RateScaleApiProperty, IsRate, RateColumn } from './rate/index.js';
|
|
11
11
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AACrJ,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC7J,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC7J,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAC7H,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AACrL,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAK,8BAA8B,CAAA;AAC5I,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,oBAAoB,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACrI,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,oBAAoB,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACrI,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AACrJ,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/quantities/voltage/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/quantities/voltage/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wisemen/quantity",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"files": [
|
|
11
|
-
"dist/"
|
|
11
|
+
"dist/",
|
|
12
|
+
"skills/"
|
|
12
13
|
],
|
|
13
14
|
"peerDependencies": {
|
|
14
15
|
"@nestjs/common": "^11.1.19",
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: getting-started
|
|
3
|
+
description: |
|
|
4
|
+
Use when dealing with physical quantities like distance, duration, speed, power etc
|
|
5
|
+
Supports:
|
|
6
|
+
- basic arithmetic and utils
|
|
7
|
+
- columns with typeorm
|
|
8
|
+
- validation with class-validator
|
|
9
|
+
- openapi documentation with nestjs
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Quantity
|
|
13
|
+
|
|
14
|
+
- Use `@wisemen/quantity` whenever generating or reviewing TypeScript/NestJS code that represents physical quantities such as distance, duration, speed, power, mass, energy, voltage, temperature, current.
|
|
15
|
+
- Prefer dedicated Quantity classes over plain numbers. Quantities are immutable; arithmetic operations must return new instances. Inspect the class' methods to discover all available operations.
|
|
16
|
+
- When creating database entities, use `<Quantity>Column`.
|
|
17
|
+
- When creating DTOs, use `<Quantity>ApiProperty`, `<Quantity>Dto`, and `Is<Quantity>` validation where applicable.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Basic arithmetic and utils
|
|
22
|
+
|
|
23
|
+
Use a <Quantity> class to define a quantity value.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { Distance, DistanceUnit } from "@wisemen/quantity"
|
|
27
|
+
|
|
28
|
+
const radius = new Distance(100, DistanceUnit.METER)
|
|
29
|
+
const innerRadius = radius.subtract(15, DistanceUnit.METER)
|
|
30
|
+
const clippedRadius = Distance.max(innerRadius, Distance.ZERO)
|
|
31
|
+
const circumference = clippedRadius.multiply(2 * Math.PI).round()
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Quantity in database entities
|
|
35
|
+
|
|
36
|
+
Use a `<Quantity>Column` decorator in a TypeORM entity property to model the field as a database column.
|
|
37
|
+
It is required to specify in what unit the quantity value will be stored in the database.
|
|
38
|
+
TypeORM's column options like `nullable` are supported.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { Distance, DistanceUnit, DistanceColumn } from "@wisemen/quantity"
|
|
42
|
+
|
|
43
|
+
class ExampleEntity {
|
|
44
|
+
@DistanceColumn(DistanceUnit.METER, { nullable: true })
|
|
45
|
+
distance: Distance | null
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Quantity in dtos (requests command, request query and response)
|
|
50
|
+
|
|
51
|
+
Use a `<Quantity>ApiProperty` decorator in a dto to document a quantity field in the nestjs open api docs.
|
|
52
|
+
Use a `Is<Quantity>` decorator in a dto to add quantity validation functionality for class-validator if needed.
|
|
53
|
+
A minimum and maximum value can be set by the `min` and `max` optional attributes in the validation options.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { ApiProperty } from "@nestjs/swagger";
|
|
57
|
+
import { Distance, DistanceDto } from "@wisemen/quantity"
|
|
58
|
+
|
|
59
|
+
class ExampleCommand {
|
|
60
|
+
@ApiProperty({ type: DistanceDto })
|
|
61
|
+
@IsDistance({ min: Distance.ZERO })
|
|
62
|
+
distance: DistanceDto
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Available quantities
|
|
67
|
+
|
|
68
|
+
- Current
|
|
69
|
+
- Distance
|
|
70
|
+
- Duration
|
|
71
|
+
- Mass
|
|
72
|
+
- Temperature
|
|
73
|
+
- Energy
|
|
74
|
+
- Power
|
|
75
|
+
- Speed
|
|
76
|
+
- Voltage
|
|
77
|
+
|
|
78
|
+
If a required quantity is unavailable, stop and tell the user it must first be added and released to `@wisemen/quantity` before continuing.
|