Skip to content

Commit 02ef79c

Browse files
authored
feat(core/serde): add NumericValue container (#1544)
1 parent 9ffe82d commit 02ef79c

File tree

10 files changed

+82
-3
lines changed

10 files changed

+82
-3
lines changed

.changeset/neat-queens-peel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/core": minor
3+
---
4+
5+
add numeric value container for serde

packages/core/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@
4545
"import": "./dist-es/submodules/protocols/index.js",
4646
"require": "./dist-cjs/submodules/protocols/index.js",
4747
"types": "./dist-types/submodules/protocols/index.d.ts"
48+
},
49+
"./serde": {
50+
"module": "./dist-es/submodules/serde/index.js",
51+
"node": "./dist-cjs/submodules/serde/index.js",
52+
"import": "./dist-es/submodules/serde/index.js",
53+
"require": "./dist-cjs/submodules/serde/index.js",
54+
"types": "./dist-types/submodules/serde/index.d.ts"
4855
}
4956
},
5057
"author": {
@@ -78,6 +85,8 @@
7885
"./cbor.js",
7986
"./protocols.d.ts",
8087
"./protocols.js",
88+
"./serde.d.ts",
89+
"./serde.js",
8190
"dist-*/**"
8291
],
8392
"homepage": "https://github.com/awslabs/smithy-typescript/tree/main/packages/core",

packages/core/serde.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Do not edit:
3+
* This is a compatibility redirect for contexts that do not understand package.json exports field.
4+
*/
5+
declare module "@smithy/core/serde" {
6+
export * from "@smithy/core/dist-types/submodules/serde/index.d";
7+
}

packages/core/serde.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
/**
3+
* Do not edit:
4+
* This is a compatibility redirect for contexts that do not understand package.json exports field.
5+
*/
6+
module.exports = require("./dist-cjs/submodules/serde/index.js");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./value/NumericValue";
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, test as it } from "vitest";
2+
3+
import { NumericValue, nv } from "./NumericValue";
4+
5+
describe(NumericValue.name, () => {
6+
it("holds a string representation of a numeric value", () => {
7+
const num = nv("1.0");
8+
expect(num).toBeInstanceOf(NumericValue);
9+
expect(num.string).toEqual("1.0");
10+
expect(num.type).toEqual("bigDecimal");
11+
});
12+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Types which may be represented by {@link NumericValue}.
3+
*
4+
* There is currently only one option, because BigInteger and Long should
5+
* use JS BigInt directly, and all other numeric types can be contained in JS Number.
6+
*
7+
* @public
8+
*/
9+
export type NumericType = "bigDecimal";
10+
11+
/**
12+
* Serialization container for Smithy simple types that do not have a
13+
* direct JavaScript runtime representation.
14+
*
15+
* This container does not perform numeric mathematical operations.
16+
* It is a container for discerning a value's true type.
17+
*
18+
* It allows storage of numeric types not representable in JS without
19+
* making a decision on what numeric library to use.
20+
*
21+
* @public
22+
*/
23+
export class NumericValue {
24+
public constructor(
25+
public readonly string: string,
26+
public readonly type: NumericType
27+
) {}
28+
}
29+
30+
/**
31+
* Serde shortcut.
32+
* @internal
33+
*/
34+
export function nv(string: string): NumericValue {
35+
return new NumericValue(string, "bigDecimal");
36+
}

packages/core/tsconfig.cjs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"rootDir": "src",
66
"paths": {
77
"@smithy/core/cbor": ["./src/submodules/cbor/index.ts"],
8-
"@smithy/core/protocols": ["./src/submodules/protocols/index.ts"]
8+
"@smithy/core/protocols": ["./src/submodules/protocols/index.ts"],
9+
"@smithy/core/serde": ["./src/submodules/serde/index.ts"]
910
}
1011
},
1112
"extends": "../../tsconfig.cjs.json",

packages/core/tsconfig.es.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"rootDir": "src",
77
"paths": {
88
"@smithy/core/cbor": ["./src/submodules/cbor/index.ts"],
9-
"@smithy/core/protocols": ["./src/submodules/protocols/index.ts"]
9+
"@smithy/core/protocols": ["./src/submodules/protocols/index.ts"],
10+
"@smithy/core/serde": ["./src/submodules/serde/index.ts"]
1011
}
1112
},
1213
"extends": "../../tsconfig.es.json",

packages/core/tsconfig.types.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"rootDir": "src",
66
"paths": {
77
"@smithy/core/cbor": ["./src/submodules/cbor/index.ts"],
8-
"@smithy/core/protocols": ["./src/submodules/protocols/index.ts"]
8+
"@smithy/core/protocols": ["./src/submodules/protocols/index.ts"],
9+
"@smithy/core/serde": ["./src/submodules/serde/index.ts"]
910
}
1011
},
1112
"extends": "../../tsconfig.types.json",

0 commit comments

Comments
 (0)