@smithy/core 3.30.0 → 3.31.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.
Files changed (23) hide show
  1. package/dist-cjs/submodules/cbor/index.js +1561 -337
  2. package/dist-es/submodules/cbor/CborCodec.js +4 -205
  3. package/dist-es/submodules/cbor/cbor-encode.js +1 -1
  4. package/dist-es/submodules/cbor/codec-v1/CborShapeDeserializer.js +113 -0
  5. package/dist-es/submodules/cbor/codec-v1/CborShapeSerializer.js +103 -0
  6. package/dist-es/submodules/cbor/codec-v2/CborShapeDeserializer2.js +621 -0
  7. package/dist-es/submodules/cbor/codec-v2/CborShapeSerializer2.js +602 -0
  8. package/dist-es/submodules/cbor/index.js +5 -1
  9. package/dist-types/submodules/cbor/CborCodec.d.ts +5 -27
  10. package/dist-types/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +2 -2
  11. package/dist-types/submodules/cbor/codec-v1/CborShapeDeserializer.d.ts +13 -0
  12. package/dist-types/submodules/cbor/codec-v1/CborShapeSerializer.d.ts +15 -0
  13. package/dist-types/submodules/cbor/codec-v2/CborShapeDeserializer2.d.ts +18 -0
  14. package/dist-types/submodules/cbor/codec-v2/CborShapeSerializer2.d.ts +35 -0
  15. package/dist-types/submodules/cbor/index.d.ts +5 -1
  16. package/dist-types/ts3.4/submodules/cbor/CborCodec.d.ts +5 -27
  17. package/dist-types/ts3.4/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +2 -2
  18. package/dist-types/ts3.4/submodules/cbor/codec-v1/CborShapeDeserializer.d.ts +13 -0
  19. package/dist-types/ts3.4/submodules/cbor/codec-v1/CborShapeSerializer.d.ts +15 -0
  20. package/dist-types/ts3.4/submodules/cbor/codec-v2/CborShapeDeserializer2.d.ts +18 -0
  21. package/dist-types/ts3.4/submodules/cbor/codec-v2/CborShapeSerializer2.d.ts +35 -0
  22. package/dist-types/ts3.4/submodules/cbor/index.d.ts +5 -1
  23. package/package.json +2 -1
@@ -0,0 +1,18 @@
1
+ import { SerdeContext } from "@smithy/core/protocols";
2
+ import type { Schema, ShapeDeserializer } from "@smithy/types";
3
+ /**
4
+ * Single-pass CBOR deserializer that reads bytes and applies Smithy schema
5
+ * transformations in one traversal using module-level state.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare class CborShapeDeserializer2 extends SerdeContext implements ShapeDeserializer<Uint8Array> {
10
+ read(schema: Schema, bytes: Uint8Array): any;
11
+ /**
12
+ * Deserialize a pre-decoded JS object per schema.
13
+ * Used by protocol error handling which passes pre-decoded objects.
14
+ *
15
+ * @internal
16
+ */
17
+ readValue(_schema: Schema, value: any): any;
18
+ }
@@ -0,0 +1,35 @@
1
+ import { SerdeContext } from "@smithy/core/protocols";
2
+ import { NormalizedSchema } from "@smithy/core/schema";
3
+ import type { Schema, ShapeSerializer } from "@smithy/types";
4
+ /**
5
+ * Single-pass CBOR serializer that walks the Smithy schema and writes CBOR bytes
6
+ * directly to a module-level buffer in one traversal. Eliminates the intermediate
7
+ * JS object tree that the multi-pass CborShapeSerializer builds.
8
+ *
9
+ * @internal
10
+ */
11
+ export declare class CborShapeSerializer2 extends SerdeContext implements ShapeSerializer<Uint8Array> {
12
+ write(schema: Schema, value: unknown): void;
13
+ flush(): Uint8Array;
14
+ }
15
+ /**
16
+ * Advance the encoding epoch. Call between serialization batches
17
+ * to allow stale cache entries to be evicted.
18
+ *
19
+ * @internal
20
+ */
21
+ export declare function advanceSinglePassEncodingEpoch(): void;
22
+ /**
23
+ * Cached CBOR struct iteration data: parallel arrays for direct indexed access.
24
+ */
25
+ export interface CborStructCache {
26
+ memberNames: string[];
27
+ memberSchemas: NormalizedSchema[];
28
+ encodedKeys: Uint8Array[];
29
+ }
30
+ /**
31
+ * Builds or retrieves the CBOR-specific struct cache for a given NormalizedSchema.
32
+ * On first call, iterates structIterator() to populate NormalizedSchema's own cache,
33
+ * then builds pre-encoded CBOR key bytes for each member.
34
+ */
35
+ export declare function loadCborStructIterator(ns: NormalizedSchema): CborStructCache;
@@ -2,4 +2,8 @@ export { cbor } from "./cbor";
2
2
  export { tag, tagSymbol } from "./cbor-types";
3
3
  export { buildHttpRpcRequest, checkCborResponse, dateToTag, loadSmithyRpcV2CborErrorCode, parseCborBody, parseCborErrorBody, } from "./parseCborBody";
4
4
  export { SmithyRpcV2CborProtocol } from "./SmithyRpcV2CborProtocol";
5
- export { CborCodec, CborShapeDeserializer, CborShapeSerializer } from "./CborCodec";
5
+ export { CborCodec } from "./CborCodec";
6
+ export { CborShapeSerializer } from "./codec-v1/CborShapeSerializer";
7
+ export { CborShapeDeserializer } from "./codec-v1/CborShapeDeserializer";
8
+ export { CborShapeSerializer2 } from "./codec-v2/CborShapeSerializer2";
9
+ export { CborShapeDeserializer2 } from "./codec-v2/CborShapeDeserializer2";
@@ -1,33 +1,11 @@
1
1
  import { SerdeContext } from "@smithy/core/protocols";
2
- import { Codec, Schema, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
2
+ import { Codec } from "@smithy/types";
3
+ import { CborShapeSerializer2 } from "./codec-v2/CborShapeSerializer2";
4
+ import { CborShapeDeserializer2 } from "./codec-v2/CborShapeDeserializer2";
3
5
  /**
4
6
  * @public
5
7
  */
6
8
  export declare class CborCodec extends SerdeContext implements Codec<Uint8Array, Uint8Array> {
7
- createSerializer(): CborShapeSerializer;
8
- createDeserializer(): CborShapeDeserializer;
9
- }
10
- /**
11
- * @public
12
- */
13
- export declare class CborShapeSerializer extends SerdeContext implements ShapeSerializer {
14
- private value;
15
- write(schema: Schema, value: unknown): void;
16
- /**
17
- * Recursive serializer transform that copies and prepares the user input object
18
- * for CBOR serialization.
19
- */
20
- serialize(schema: Schema, source: unknown): any;
21
- flush(): Uint8Array;
22
- }
23
- /**
24
- * @public
25
- */
26
- export declare class CborShapeDeserializer extends SerdeContext implements ShapeDeserializer {
27
- read(schema: Schema, bytes: Uint8Array): any;
28
- /**
29
- * Public because it's called by the protocol implementation to deserialize errors.
30
- * @internal
31
- */
32
- readValue(_schema: Schema, value: any): any;
9
+ createSerializer(): CborShapeSerializer2;
10
+ createDeserializer(): CborShapeDeserializer2;
33
11
  }
@@ -13,8 +13,8 @@ export declare class SmithyRpcV2CborProtocol extends RpcProtocol {
13
13
  */
14
14
  protected compositeErrorRegistry: TypeRegistry;
15
15
  private codec;
16
- protected serializer: import("./CborCodec").CborShapeSerializer;
17
- protected deserializer: import("./CborCodec").CborShapeDeserializer;
16
+ protected serializer: import(".").CborShapeSerializer2;
17
+ protected deserializer: import(".").CborShapeDeserializer2;
18
18
  constructor({ defaultNamespace, errorTypeRegistries, }: {
19
19
  defaultNamespace: string;
20
20
  errorTypeRegistries?: TypeRegistry[];
@@ -0,0 +1,13 @@
1
+ import { SerdeContext } from "@smithy/core/protocols";
2
+ import { Schema, ShapeDeserializer } from "@smithy/types";
3
+ /**
4
+ * @public
5
+ */
6
+ export declare class CborShapeDeserializer extends SerdeContext implements ShapeDeserializer {
7
+ read(schema: Schema, bytes: Uint8Array): any;
8
+ /**
9
+ * Public because it's called by the protocol implementation to deserialize errors.
10
+ * @internal
11
+ */
12
+ readValue(_schema: Schema, value: any): any;
13
+ }
@@ -0,0 +1,15 @@
1
+ import { SerdeContext } from "@smithy/core/protocols";
2
+ import { Schema, ShapeSerializer } from "@smithy/types";
3
+ /**
4
+ * @public
5
+ */
6
+ export declare class CborShapeSerializer extends SerdeContext implements ShapeSerializer {
7
+ private value;
8
+ write(schema: Schema, value: unknown): void;
9
+ /**
10
+ * Recursive serializer transform that copies and prepares the user input object
11
+ * for CBOR serialization.
12
+ */
13
+ serialize(schema: Schema, source: unknown): any;
14
+ flush(): Uint8Array;
15
+ }
@@ -0,0 +1,18 @@
1
+ import { SerdeContext } from "@smithy/core/protocols";
2
+ import { Schema, ShapeDeserializer } from "@smithy/types";
3
+ /**
4
+ * Single-pass CBOR deserializer that reads bytes and applies Smithy schema
5
+ * transformations in one traversal using module-level state.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare class CborShapeDeserializer2 extends SerdeContext implements ShapeDeserializer<Uint8Array> {
10
+ read(schema: Schema, bytes: Uint8Array): any;
11
+ /**
12
+ * Deserialize a pre-decoded JS object per schema.
13
+ * Used by protocol error handling which passes pre-decoded objects.
14
+ *
15
+ * @internal
16
+ */
17
+ readValue(_schema: Schema, value: any): any;
18
+ }
@@ -0,0 +1,35 @@
1
+ import { SerdeContext } from "@smithy/core/protocols";
2
+ import { NormalizedSchema } from "@smithy/core/schema";
3
+ import { Schema, ShapeSerializer } from "@smithy/types";
4
+ /**
5
+ * Single-pass CBOR serializer that walks the Smithy schema and writes CBOR bytes
6
+ * directly to a module-level buffer in one traversal. Eliminates the intermediate
7
+ * JS object tree that the multi-pass CborShapeSerializer builds.
8
+ *
9
+ * @internal
10
+ */
11
+ export declare class CborShapeSerializer2 extends SerdeContext implements ShapeSerializer<Uint8Array> {
12
+ write(schema: Schema, value: unknown): void;
13
+ flush(): Uint8Array;
14
+ }
15
+ /**
16
+ * Advance the encoding epoch. Call between serialization batches
17
+ * to allow stale cache entries to be evicted.
18
+ *
19
+ * @internal
20
+ */
21
+ export declare function advanceSinglePassEncodingEpoch(): void;
22
+ /**
23
+ * Cached CBOR struct iteration data: parallel arrays for direct indexed access.
24
+ */
25
+ export interface CborStructCache {
26
+ memberNames: string[];
27
+ memberSchemas: NormalizedSchema[];
28
+ encodedKeys: Uint8Array[];
29
+ }
30
+ /**
31
+ * Builds or retrieves the CBOR-specific struct cache for a given NormalizedSchema.
32
+ * On first call, iterates structIterator() to populate NormalizedSchema's own cache,
33
+ * then builds pre-encoded CBOR key bytes for each member.
34
+ */
35
+ export declare function loadCborStructIterator(ns: NormalizedSchema): CborStructCache;
@@ -2,4 +2,8 @@ export { cbor } from "./cbor";
2
2
  export { tag, tagSymbol } from "./cbor-types";
3
3
  export { buildHttpRpcRequest, checkCborResponse, dateToTag, loadSmithyRpcV2CborErrorCode, parseCborBody, parseCborErrorBody, } from "./parseCborBody";
4
4
  export { SmithyRpcV2CborProtocol } from "./SmithyRpcV2CborProtocol";
5
- export { CborCodec, CborShapeDeserializer, CborShapeSerializer } from "./CborCodec";
5
+ export { CborCodec } from "./CborCodec";
6
+ export { CborShapeSerializer } from "./codec-v1/CborShapeSerializer";
7
+ export { CborShapeDeserializer } from "./codec-v1/CborShapeDeserializer";
8
+ export { CborShapeSerializer2 } from "./codec-v2/CborShapeSerializer2";
9
+ export { CborShapeDeserializer2 } from "./codec-v2/CborShapeDeserializer2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/core",
3
- "version": "3.30.0",
3
+ "version": "3.31.1",
4
4
  "homepage": "https://github.com/smithy-lang/smithy-typescript/tree/main/packages/core",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -220,6 +220,7 @@
220
220
  "scripts": {
221
221
  "benchmark:cbor": "node ./scripts/cbor-perf.mjs",
222
222
  "benchmark:checksum": "node ./scripts/checksum-perf.mjs",
223
+ "benchmark:schema:cbor": "node ./scripts/cbor-shape-perf.mjs",
223
224
  "build": "concurrently 'yarn:build:types' 'yarn:build:es:cjs'",
224
225
  "build:es:cjs": "node ../../scripts/compilation/es_cjs.js",
225
226
  "build:types": "premove dist-types && yarn g:tsc -p tsconfig.types.json",