@smithy/core
Advanced tools
| import { SerdeContext } from "@smithy/core/protocols"; | ||
| import { NormalizedSchema } from "@smithy/core/schema"; | ||
| import { NumericValue, _parseEpochTimestamp, fromBase64 } from "@smithy/core/serde"; | ||
| import { cbor } from "../cbor"; | ||
| export class CborShapeDeserializer extends SerdeContext { | ||
| read(schema, bytes) { | ||
| const data = cbor.deserialize(bytes); | ||
| return this.readValue(schema, data); | ||
| } | ||
| readValue(_schema, value) { | ||
| const ns = NormalizedSchema.of(_schema); | ||
| if (ns.isTimestampSchema()) { | ||
| if (typeof value === "number") { | ||
| return _parseEpochTimestamp(value); | ||
| } | ||
| if (typeof value === "object") { | ||
| if (value.tag === 1 && "value" in value) { | ||
| return _parseEpochTimestamp(value.value); | ||
| } | ||
| } | ||
| } | ||
| if (ns.isBlobSchema()) { | ||
| if (typeof value === "string") { | ||
| return (this.serdeContext?.base64Decoder ?? fromBase64)(value); | ||
| } | ||
| return value; | ||
| } | ||
| if (typeof value === "undefined" || | ||
| typeof value === "boolean" || | ||
| typeof value === "number" || | ||
| typeof value === "string" || | ||
| typeof value === "bigint" || | ||
| typeof value === "symbol") { | ||
| return value; | ||
| } | ||
| else if (typeof value === "object") { | ||
| if (value === null) { | ||
| return null; | ||
| } | ||
| if ("byteLength" in value) { | ||
| return value; | ||
| } | ||
| if (value instanceof Date) { | ||
| return value; | ||
| } | ||
| if (ns.isDocumentSchema()) { | ||
| return value; | ||
| } | ||
| if (ns.isListSchema()) { | ||
| const newArray = []; | ||
| const memberSchema = ns.getValueSchema(); | ||
| for (const item of value) { | ||
| const itemValue = this.readValue(memberSchema, item); | ||
| newArray.push(itemValue); | ||
| } | ||
| return newArray; | ||
| } | ||
| const newObject = {}; | ||
| if (ns.isMapSchema()) { | ||
| const targetSchema = ns.getValueSchema(); | ||
| for (const key in value) { | ||
| const itemValue = this.readValue(targetSchema, value[key]); | ||
| newObject[key] = itemValue; | ||
| } | ||
| } | ||
| else if (ns.isStructSchema()) { | ||
| const isUnion = ns.isUnionSchema(); | ||
| let keys; | ||
| if (isUnion) { | ||
| keys = new Set(); | ||
| for (const k in value) { | ||
| if (k !== "__type") { | ||
| keys.add(k); | ||
| } | ||
| } | ||
| } | ||
| for (const [key, memberSchema] of ns.structIterator()) { | ||
| if (isUnion) { | ||
| keys.delete(key); | ||
| } | ||
| if (value[key] != null) { | ||
| newObject[key] = this.readValue(memberSchema, value[key]); | ||
| } | ||
| } | ||
| if (isUnion && keys?.size === 1) { | ||
| let newObjectEmpty = true; | ||
| for (const _ in newObject) { | ||
| newObjectEmpty = false; | ||
| break; | ||
| } | ||
| if (newObjectEmpty) { | ||
| const k = keys.values().next().value; | ||
| newObject.$unknown = [k, value[k]]; | ||
| } | ||
| } | ||
| else if (typeof value.__type === "string") { | ||
| for (const k in value) { | ||
| if (!(k in newObject)) { | ||
| newObject[k] = value[k]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| else if (value instanceof NumericValue) { | ||
| return value; | ||
| } | ||
| return newObject; | ||
| } | ||
| else { | ||
| return value; | ||
| } | ||
| } | ||
| } |
| import { SerdeContext } from "@smithy/core/protocols"; | ||
| import { NormalizedSchema } from "@smithy/core/schema"; | ||
| import { fromBase64, generateIdempotencyToken } from "@smithy/core/serde"; | ||
| import { cbor } from "../cbor"; | ||
| import { dateToTag } from "../parseCborBody"; | ||
| export class CborShapeSerializer extends SerdeContext { | ||
| value; | ||
| write(schema, value) { | ||
| this.value = this.serialize(schema, value); | ||
| } | ||
| serialize(schema, source) { | ||
| const ns = NormalizedSchema.of(schema); | ||
| if (source == null) { | ||
| if (ns.isIdempotencyToken()) { | ||
| return generateIdempotencyToken(); | ||
| } | ||
| return source; | ||
| } | ||
| if (ns.isBlobSchema()) { | ||
| if (typeof source === "string") { | ||
| return (this.serdeContext?.base64Decoder ?? fromBase64)(source); | ||
| } | ||
| return source; | ||
| } | ||
| if (ns.isTimestampSchema()) { | ||
| if (typeof source === "number" || typeof source === "bigint") { | ||
| return dateToTag(new Date((Number(source) / 1000) | 0)); | ||
| } | ||
| return dateToTag(source); | ||
| } | ||
| if (typeof source === "function" || typeof source === "object") { | ||
| const sourceObject = source; | ||
| if (ns.isListSchema() && Array.isArray(sourceObject)) { | ||
| const sparse = !!ns.getMergedTraits().sparse; | ||
| const newArray = []; | ||
| let i = 0; | ||
| for (const item of sourceObject) { | ||
| const value = this.serialize(ns.getValueSchema(), item); | ||
| if (value != null || sparse) { | ||
| newArray[i++] = value; | ||
| } | ||
| } | ||
| return newArray; | ||
| } | ||
| if (sourceObject instanceof Date) { | ||
| return dateToTag(sourceObject); | ||
| } | ||
| const newObject = {}; | ||
| if (ns.isMapSchema()) { | ||
| const sparse = !!ns.getMergedTraits().sparse; | ||
| for (const key in sourceObject) { | ||
| const value = this.serialize(ns.getValueSchema(), sourceObject[key]); | ||
| if (value != null || sparse) { | ||
| newObject[key] = value; | ||
| } | ||
| } | ||
| } | ||
| else if (ns.isStructSchema()) { | ||
| for (const [key, memberSchema] of ns.structIterator()) { | ||
| const value = this.serialize(memberSchema, sourceObject[key]); | ||
| if (value != null) { | ||
| newObject[key] = value; | ||
| } | ||
| } | ||
| const isUnion = ns.isUnionSchema(); | ||
| if (isUnion && Array.isArray(sourceObject.$unknown)) { | ||
| const [k, v] = sourceObject.$unknown; | ||
| newObject[k] = v; | ||
| } | ||
| else if (typeof sourceObject.__type === "string") { | ||
| for (const k in sourceObject) { | ||
| if (!(k in newObject)) { | ||
| newObject[k] = this.serialize(15, sourceObject[k]); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| else if (ns.isDocumentSchema()) { | ||
| for (const key in sourceObject) { | ||
| newObject[key] = this.serialize(ns.getValueSchema(), sourceObject[key]); | ||
| } | ||
| } | ||
| else if (ns.isBigDecimalSchema()) { | ||
| return sourceObject; | ||
| } | ||
| return newObject; | ||
| } | ||
| return source; | ||
| } | ||
| flush() { | ||
| const buffer = cbor.serialize(this.value); | ||
| this.value = undefined; | ||
| return buffer; | ||
| } | ||
| } |
| import { SerdeContext } from "@smithy/core/protocols"; | ||
| import { NormalizedSchema } from "@smithy/core/schema"; | ||
| import { NumericValue, _parseEpochTimestamp, nv } from "@smithy/core/serde"; | ||
| import { extendedFloat16, extendedFloat32, extendedFloat64, extendedOneByte, majorList, majorMap, majorNegativeInt64, majorSpecial, majorTag, majorUint64, majorUnstructuredByteString, majorUtf8String, minorIndefinite, specialFalse, specialNull, specialTrue, specialUndefined, } from "../cbor-types"; | ||
| import { activateCborStructIterator } from "./SinglePassCborShapeSerializer"; | ||
| export class SinglePassCborShapeDeserializer extends SerdeContext { | ||
| constructor() { | ||
| super(); | ||
| activateCborStructIterator(); | ||
| } | ||
| read(schema, bytes) { | ||
| payload = bytes; | ||
| isBuffer = USE_BUFFER && bytes instanceof Buffer; | ||
| dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength); | ||
| pos = 0; | ||
| end = bytes.length; | ||
| cacheEpoch = (cacheEpoch + 1) & 0xffff; | ||
| return readValue(NormalizedSchema.of(schema)); | ||
| } | ||
| readValue(_schema, value) { | ||
| return transformObject(NormalizedSchema.of(_schema), value); | ||
| } | ||
| } | ||
| const USE_BUFFER = typeof Buffer !== "undefined"; | ||
| const textDecoder = new TextDecoder(); | ||
| let payload = new Uint8Array(0); | ||
| let isBuffer = false; | ||
| let dataView = new DataView(new ArrayBuffer(0)); | ||
| let pos = 0; | ||
| let end = 0; | ||
| const STRING_CACHE_SIZE = 2048; | ||
| const stringCache = new Array(STRING_CACHE_SIZE); | ||
| const stringCacheEpochs = new Uint16Array(STRING_CACHE_SIZE); | ||
| let cacheEpoch = 0; | ||
| function readValue(ns) { | ||
| if (pos >= end) { | ||
| throw new Error("unexpected end of CBOR payload."); | ||
| } | ||
| const major = (payload[pos] & 0b1110_0000) >> 5; | ||
| const minor = payload[pos] & 0b0001_1111; | ||
| if (minor === minorIndefinite && major >= 2 && major <= 5) { | ||
| return readIndefinite(ns, major); | ||
| } | ||
| switch (major) { | ||
| case majorUint64: | ||
| return readUnsignedInt(); | ||
| case majorNegativeInt64: | ||
| return readNegativeInt(); | ||
| case majorUnstructuredByteString: | ||
| return readByteString(); | ||
| case majorUtf8String: | ||
| return readUtf8String(); | ||
| case majorList: | ||
| return readList(ns); | ||
| case majorMap: | ||
| return readMap(ns); | ||
| case majorTag: | ||
| return readTag(ns); | ||
| case majorSpecial: | ||
| return readSpecial(); | ||
| default: | ||
| throw new Error(`unexpected CBOR major type ${major}.`); | ||
| } | ||
| } | ||
| function readList(ns) { | ||
| const count = decodeCount(); | ||
| const memberSchema = ns.isListSchema() ? ns.getValueSchema() : ns; | ||
| const list = Array(count); | ||
| for (let i = 0; i < count; ++i) { | ||
| list[i] = readValue(memberSchema); | ||
| } | ||
| return list; | ||
| } | ||
| function readMap(ns) { | ||
| const count = decodeCount(); | ||
| if (ns.isStructSchema()) { | ||
| return readStruct(ns, count); | ||
| } | ||
| const valueSchema = ns.isMapSchema() ? ns.getValueSchema() : ns; | ||
| const map = {}; | ||
| for (let i = 0; i < count; ++i) { | ||
| const key = readUtf8String(); | ||
| map[key] = readValue(valueSchema); | ||
| } | ||
| return map; | ||
| } | ||
| function readStruct(ns, count) { | ||
| const isUnion = ns.isUnionSchema(); | ||
| const cache = ns.structIteratorCbor(); | ||
| const { memberSchemas, encodedKeys, memberNames } = cache; | ||
| const z = encodedKeys.length; | ||
| const result = {}; | ||
| let unknownKey; | ||
| let unknownValue; | ||
| let unknownCount = 0; | ||
| let hint = 0; | ||
| for (let i = 0; i < count; ++i) { | ||
| const matchIdx = matchStructKey(encodedKeys, z, hint); | ||
| if (matchIdx >= 0) { | ||
| hint = matchIdx + 1; | ||
| if (hint >= z) { | ||
| hint = 0; | ||
| } | ||
| const val = readValue(memberSchemas[matchIdx]); | ||
| if (val != null) { | ||
| result[memberNames[matchIdx]] = val; | ||
| } | ||
| } | ||
| else { | ||
| const key = readUtf8String(); | ||
| const val = readValue(NormalizedSchema.of(15)); | ||
| if (key !== "__type") { | ||
| unknownKey = key; | ||
| unknownValue = val; | ||
| ++unknownCount; | ||
| } | ||
| } | ||
| } | ||
| if (isUnion) { | ||
| let resultEmpty = true; | ||
| for (const _ in result) { | ||
| resultEmpty = false; | ||
| break; | ||
| } | ||
| if (resultEmpty && unknownCount === 1) { | ||
| result.$unknown = [unknownKey, unknownValue]; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| function readTag(ns) { | ||
| const tagNum = decodeArgument(); | ||
| const tagNumber = typeof tagNum === "bigint" ? Number(tagNum) : tagNum; | ||
| if (tagNumber === 1) { | ||
| const docSchema = NormalizedSchema.of(15); | ||
| const epochValue = readValue(docSchema); | ||
| return _parseEpochTimestamp(epochValue); | ||
| } | ||
| if (tagNumber === 2 || tagNumber === 3) { | ||
| const byteStr = readByteString(); | ||
| let b = BigInt(0); | ||
| for (let i = 0; i < byteStr.length; ++i) { | ||
| b = (b << BigInt(8)) | BigInt(byteStr[i]); | ||
| } | ||
| return tagNumber === 3 ? -b - BigInt(1) : b; | ||
| } | ||
| if (tagNumber === 4) { | ||
| const docSchema = NormalizedSchema.of(15); | ||
| const pair = readValue(docSchema); | ||
| const [exponent, mantissa] = pair; | ||
| const normalizer = mantissa < 0 ? -1 : 1; | ||
| const mantissaStr = "0".repeat(Math.abs(exponent) + 1) + String(BigInt(normalizer) * BigInt(mantissa)); | ||
| let numericString; | ||
| const sign = mantissa < 0 ? "-" : ""; | ||
| numericString = | ||
| exponent === 0 | ||
| ? mantissaStr | ||
| : mantissaStr.slice(0, mantissaStr.length + exponent) + "." + mantissaStr.slice(exponent); | ||
| numericString = numericString.replace(/^0+/g, ""); | ||
| if (numericString === "") { | ||
| numericString = "0"; | ||
| } | ||
| if (numericString[0] === ".") { | ||
| numericString = "0" + numericString; | ||
| } | ||
| numericString = sign + numericString; | ||
| return nv(numericString); | ||
| } | ||
| const docSchema = NormalizedSchema.of(15); | ||
| const innerValue = readValue(docSchema); | ||
| return { tag: castBigInt(tagNum), value: innerValue }; | ||
| } | ||
| function readIndefinite(ns, major) { | ||
| switch (major) { | ||
| case majorUtf8String: | ||
| return readUtf8StringIndefinite(); | ||
| case majorUnstructuredByteString: | ||
| return readByteStringIndefinite(); | ||
| case majorList: | ||
| return readListIndefinite(ns); | ||
| case majorMap: | ||
| return readMapIndefinite(ns); | ||
| default: | ||
| throw new Error(`unexpected indefinite length for major ${major}.`); | ||
| } | ||
| } | ||
| function readUtf8StringIndefinite() { | ||
| pos += 1; | ||
| const chunks = []; | ||
| let totalLen = 0; | ||
| while (pos < end) { | ||
| if (payload[pos] === 0xff) { | ||
| pos += 1; | ||
| const combined = new Uint8Array(totalLen); | ||
| let offset = 0; | ||
| for (let i = 0; i < chunks.length; ++i) { | ||
| combined.set(chunks[i], offset); | ||
| offset += chunks[i].length; | ||
| } | ||
| if (USE_BUFFER) { | ||
| return Buffer.from(combined.buffer, combined.byteOffset, combined.byteLength).toString("utf-8"); | ||
| } | ||
| return textDecoder.decode(combined); | ||
| } | ||
| const bytes = readByteString(); | ||
| chunks.push(bytes); | ||
| totalLen += bytes.length; | ||
| } | ||
| throw new Error("expected break marker."); | ||
| } | ||
| function readByteStringIndefinite() { | ||
| pos += 1; | ||
| const chunks = []; | ||
| let totalLen = 0; | ||
| while (pos < end) { | ||
| if (payload[pos] === 0xff) { | ||
| pos += 1; | ||
| const combined = new Uint8Array(totalLen); | ||
| let offset = 0; | ||
| for (let i = 0; i < chunks.length; ++i) { | ||
| combined.set(chunks[i], offset); | ||
| offset += chunks[i].length; | ||
| } | ||
| return combined; | ||
| } | ||
| const bytes = readByteString(); | ||
| chunks.push(bytes); | ||
| totalLen += bytes.length; | ||
| } | ||
| throw new Error("expected break marker."); | ||
| } | ||
| function readListIndefinite(ns) { | ||
| pos += 1; | ||
| const memberSchema = ns.isListSchema() ? ns.getValueSchema() : ns; | ||
| const list = []; | ||
| while (pos < end) { | ||
| if (payload[pos] === 0xff) { | ||
| pos += 1; | ||
| return list; | ||
| } | ||
| list.push(readValue(memberSchema)); | ||
| } | ||
| throw new Error("expected break marker."); | ||
| } | ||
| function readMapIndefinite(ns) { | ||
| pos += 1; | ||
| if (ns.isStructSchema()) { | ||
| const cache = ns.structIteratorCbor(); | ||
| const { memberSchemas, encodedKeys, memberNames } = cache; | ||
| const z = encodedKeys.length; | ||
| const isUnion = ns.isUnionSchema(); | ||
| const result = {}; | ||
| let unknownKey; | ||
| let unknownValue; | ||
| let unknownCount = 0; | ||
| let hint = 0; | ||
| while (pos < end) { | ||
| if (payload[pos] === 0xff) { | ||
| pos += 1; | ||
| if (isUnion) { | ||
| let resultEmpty = true; | ||
| for (const _ in result) { | ||
| resultEmpty = false; | ||
| break; | ||
| } | ||
| if (resultEmpty && unknownCount === 1) { | ||
| result.$unknown = [unknownKey, unknownValue]; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| const matchIdx = matchStructKey(encodedKeys, z, hint); | ||
| if (matchIdx >= 0) { | ||
| hint = matchIdx + 1; | ||
| if (hint >= z) { | ||
| hint = 0; | ||
| } | ||
| const val = readValue(memberSchemas[matchIdx]); | ||
| if (val != null) { | ||
| result[memberNames[matchIdx]] = val; | ||
| } | ||
| } | ||
| else { | ||
| const key = readUtf8String(); | ||
| const val = readValue(NormalizedSchema.of(15)); | ||
| if (key !== "__type") { | ||
| unknownKey = key; | ||
| unknownValue = val; | ||
| ++unknownCount; | ||
| } | ||
| } | ||
| } | ||
| throw new Error("expected break marker."); | ||
| } | ||
| const valueSchema = ns.isMapSchema() ? ns.getValueSchema() : ns; | ||
| const map = {}; | ||
| while (pos < end) { | ||
| if (payload[pos] === 0xff) { | ||
| pos += 1; | ||
| return map; | ||
| } | ||
| const key = readUtf8String(); | ||
| map[key] = readValue(valueSchema); | ||
| } | ||
| throw new Error("expected break marker."); | ||
| } | ||
| function matchStructKey(encodedKeys, z, hint) { | ||
| const hintKey = encodedKeys[hint]; | ||
| if (pos + hintKey.length <= end && bytesMatch(pos, hintKey)) { | ||
| pos += hintKey.length; | ||
| return hint; | ||
| } | ||
| for (let i = 0; i < z; ++i) { | ||
| if (i === hint) { | ||
| continue; | ||
| } | ||
| const ek = encodedKeys[i]; | ||
| if (pos + ek.length <= end && bytesMatch(pos, ek)) { | ||
| pos += ek.length; | ||
| return i; | ||
| } | ||
| } | ||
| return -1; | ||
| } | ||
| function bytesMatch(at, expected) { | ||
| const len = expected.length; | ||
| if (payload[at] !== expected[0]) { | ||
| return false; | ||
| } | ||
| for (let i = 1; i < len; ++i) { | ||
| if (payload[at + i] !== expected[i]) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| function decodeArgument() { | ||
| const minor = payload[pos] & 0b0001_1111; | ||
| if (minor < 24) { | ||
| pos += 1; | ||
| return minor; | ||
| } | ||
| switch (minor) { | ||
| case extendedOneByte: | ||
| if (end - pos < 2) { | ||
| overflow(1); | ||
| } | ||
| pos += 2; | ||
| return payload[pos - 1]; | ||
| case extendedFloat16: | ||
| if (end - pos < 3) { | ||
| overflow(2); | ||
| } | ||
| pos += 3; | ||
| return dataView.getUint16(pos - 2); | ||
| case extendedFloat32: | ||
| if (end - pos < 5) { | ||
| overflow(4); | ||
| } | ||
| pos += 5; | ||
| return dataView.getUint32(pos - 4); | ||
| case extendedFloat64: { | ||
| if (end - pos < 9) { | ||
| overflow(8); | ||
| } | ||
| pos += 9; | ||
| const hi = dataView.getUint32(pos - 8); | ||
| if (hi < 0x00200000) { | ||
| return hi * 4294967296 + dataView.getUint32(pos - 4); | ||
| } | ||
| return dataView.getBigUint64(pos - 8); | ||
| } | ||
| default: | ||
| throw new Error(`unexpected minor value ${minor}.`); | ||
| } | ||
| } | ||
| function decodeCount() { | ||
| const val = decodeArgument(); | ||
| return typeof val === "bigint" ? Number(val) : val; | ||
| } | ||
| function readUnsignedInt() { | ||
| const val = decodeArgument(); | ||
| return castBigInt(val); | ||
| } | ||
| function readNegativeInt() { | ||
| const val = decodeArgument(); | ||
| if (typeof val === "bigint") { | ||
| return BigInt(-1) - val; | ||
| } | ||
| return -1 - val; | ||
| } | ||
| function readByteString() { | ||
| const length = decodeCount(); | ||
| if (end - pos < length) { | ||
| overflow(length); | ||
| } | ||
| const start = pos; | ||
| pos += length; | ||
| return payload.subarray(start, start + length); | ||
| } | ||
| function readUtf8String() { | ||
| const length = decodeCount(); | ||
| if (end - pos < length) { | ||
| overflow(length); | ||
| } | ||
| const start = pos; | ||
| pos += length; | ||
| if (length < 24) { | ||
| return decodeUtf8Cached(start, length); | ||
| } | ||
| if (isBuffer) { | ||
| return payload.toString("utf-8", start, start + length); | ||
| } | ||
| return textDecoder.decode(payload.subarray(start, start + length)); | ||
| } | ||
| function decodeUtf8Cached(at, length) { | ||
| let h = length; | ||
| for (let i = 0; i < length; ++i) { | ||
| h = (h * 31 + payload[at + i]) | 0; | ||
| } | ||
| const slot = (h >>> 0) & (STRING_CACHE_SIZE - 1); | ||
| const cached = stringCache[slot]; | ||
| if (cached !== undefined && cached.length === length) { | ||
| let match = true; | ||
| for (let i = 0; i < length; ++i) { | ||
| if (cached.charCodeAt(i) !== payload[at + i]) { | ||
| match = false; | ||
| break; | ||
| } | ||
| } | ||
| if (match) { | ||
| stringCacheEpochs[slot] = cacheEpoch; | ||
| return cached; | ||
| } | ||
| } | ||
| const result = isBuffer | ||
| ? payload.toString("utf-8", at, at + length) | ||
| : textDecoder.decode(payload.subarray(at, at + length)); | ||
| if (stringCacheEpochs[slot] !== cacheEpoch) { | ||
| stringCache[slot] = result; | ||
| stringCacheEpochs[slot] = cacheEpoch; | ||
| } | ||
| return result; | ||
| } | ||
| function readSpecial() { | ||
| const p = pos; | ||
| const minor = payload[p] & 0b0001_1111; | ||
| switch (minor) { | ||
| case specialTrue: | ||
| pos = p + 1; | ||
| return true; | ||
| case specialFalse: | ||
| pos = p + 1; | ||
| return false; | ||
| case specialNull: | ||
| pos = p + 1; | ||
| return null; | ||
| case specialUndefined: | ||
| pos = p + 1; | ||
| return null; | ||
| case extendedFloat16: { | ||
| if (end - p < 3) { | ||
| overflow(2); | ||
| } | ||
| pos = p + 3; | ||
| return bytesToFloat16(payload[p + 1], payload[p + 2]); | ||
| } | ||
| case extendedFloat32: { | ||
| if (end - p < 5) { | ||
| overflow(4); | ||
| } | ||
| pos = p + 5; | ||
| return dataView.getFloat32(p + 1); | ||
| } | ||
| case extendedFloat64: { | ||
| if (end - p < 9) { | ||
| overflow(8); | ||
| } | ||
| pos = p + 9; | ||
| return dataView.getFloat64(p + 1); | ||
| } | ||
| default: | ||
| throw new Error(`unexpected minor value ${minor} for major 7.`); | ||
| } | ||
| } | ||
| function bytesToFloat16(a, b) { | ||
| const sign = a >> 7; | ||
| const exponent = (a & 0b0111_1100) >> 2; | ||
| const fraction = ((a & 0b0000_0011) << 8) | b; | ||
| const scalar = sign === 0 ? 1 : -1; | ||
| if (exponent === 0b00000) { | ||
| if (fraction === 0) { | ||
| return 0; | ||
| } | ||
| return scalar * (Math.pow(2, 1 - 15) * (fraction / 1024)); | ||
| } | ||
| else if (exponent === 0b11111) { | ||
| if (fraction === 0) { | ||
| return scalar * Infinity; | ||
| } | ||
| return NaN; | ||
| } | ||
| return scalar * (Math.pow(2, exponent - 15) * (1 + fraction / 1024)); | ||
| } | ||
| function castBigInt(value) { | ||
| if (typeof value === "number") { | ||
| return value; | ||
| } | ||
| const num = Number(value); | ||
| if (Number.MIN_SAFE_INTEGER <= num && num <= Number.MAX_SAFE_INTEGER) { | ||
| return num; | ||
| } | ||
| return value; | ||
| } | ||
| function overflow(n) { | ||
| throw new Error(`CBOR: length ${n} greater than remaining buffer length.`); | ||
| } | ||
| function transformObject(ns, value) { | ||
| if (ns.isTimestampSchema()) { | ||
| if (typeof value === "number") { | ||
| return _parseEpochTimestamp(value); | ||
| } | ||
| if (typeof value === "object" && value !== null) { | ||
| if (value.tag === 1 && "value" in value) { | ||
| return _parseEpochTimestamp(value.value); | ||
| } | ||
| } | ||
| } | ||
| if (ns.isBlobSchema()) { | ||
| return value; | ||
| } | ||
| if (typeof value === "undefined" || | ||
| typeof value === "boolean" || | ||
| typeof value === "number" || | ||
| typeof value === "string" || | ||
| typeof value === "bigint" || | ||
| typeof value === "symbol") { | ||
| return value; | ||
| } | ||
| if (typeof value !== "object" || value === null) { | ||
| return value; | ||
| } | ||
| if ("byteLength" in value) { | ||
| return value; | ||
| } | ||
| if (value instanceof Date) { | ||
| return value; | ||
| } | ||
| if (value instanceof NumericValue) { | ||
| return value; | ||
| } | ||
| if (ns.isDocumentSchema()) { | ||
| return value; | ||
| } | ||
| if (ns.isListSchema()) { | ||
| const memberSchema = ns.getValueSchema(); | ||
| const out = []; | ||
| for (const item of value) { | ||
| out.push(transformObject(memberSchema, item)); | ||
| } | ||
| return out; | ||
| } | ||
| const newObject = {}; | ||
| if (ns.isMapSchema()) { | ||
| const targetSchema = ns.getValueSchema(); | ||
| for (const key in value) { | ||
| newObject[key] = transformObject(targetSchema, value[key]); | ||
| } | ||
| } | ||
| else if (ns.isStructSchema()) { | ||
| const isUnion = ns.isUnionSchema(); | ||
| let keys; | ||
| if (isUnion) { | ||
| keys = new Set(); | ||
| for (const k in value) { | ||
| if (k !== "__type") { | ||
| keys.add(k); | ||
| } | ||
| } | ||
| } | ||
| for (const [key, memberSchema] of ns.structIterator()) { | ||
| if (isUnion) { | ||
| keys.delete(key); | ||
| } | ||
| if (value[key] != null) { | ||
| newObject[key] = transformObject(memberSchema, value[key]); | ||
| } | ||
| } | ||
| if (isUnion && keys?.size === 1) { | ||
| let newObjectEmpty = true; | ||
| for (const _ in newObject) { | ||
| newObjectEmpty = false; | ||
| break; | ||
| } | ||
| if (newObjectEmpty) { | ||
| const k = keys.values().next().value; | ||
| newObject.$unknown = [k, value[k]]; | ||
| } | ||
| } | ||
| else if (typeof value.__type === "string") { | ||
| for (const k in value) { | ||
| if (!(k in newObject)) { | ||
| newObject[k] = value[k]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return newObject; | ||
| } |
| import { SerdeContext } from "@smithy/core/protocols"; | ||
| import { NormalizedSchema } from "@smithy/core/schema"; | ||
| import { NumericValue, fromBase64, generateIdempotencyToken } from "@smithy/core/serde"; | ||
| import { extendedFloat16, extendedFloat32, extendedFloat64, majorList, majorMap, majorNegativeInt64, majorSpecial, majorTag, majorUint64, majorUnstructuredByteString, majorUtf8String, specialFalse, specialNull, specialTrue, tagSymbol, } from "../cbor-types"; | ||
| export class SinglePassCborShapeSerializer extends SerdeContext { | ||
| constructor() { | ||
| super(); | ||
| activateCborStructIterator(); | ||
| } | ||
| write(schema, value) { | ||
| cursor = 0; | ||
| const ns = NormalizedSchema.of(schema); | ||
| writeValue(ns, value, undefined, this.serdeContext); | ||
| } | ||
| flush() { | ||
| const result = buf.subarray(0, cursor); | ||
| cursor = 0; | ||
| buf = allocUnsafe(INITIAL_BUFFER_SIZE); | ||
| view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength); | ||
| return result; | ||
| } | ||
| } | ||
| export function advanceSinglePassEncodingEpoch() { | ||
| encodeCacheEpoch = (encodeCacheEpoch + 1) & 0xffff; | ||
| encodeCacheSaturated = false; | ||
| } | ||
| export function activateCborStructIterator() { | ||
| NormalizedSchema.prototype.structIteratorCbor = function () { | ||
| return loadCborStructIterator(this); | ||
| }; | ||
| } | ||
| const CBOR_STRUCT_CACHE = Symbol.for("@smithy/cbor-struct-cache"); | ||
| function loadCborStructIterator(ns) { | ||
| const schema = ns.getSchema(); | ||
| const existing = schema[CBOR_STRUCT_CACHE]; | ||
| if (existing) { | ||
| return existing; | ||
| } | ||
| const memberNames = []; | ||
| const memberSchemas = []; | ||
| for (const [name, memberSchema] of ns.structIterator()) { | ||
| memberNames.push(name); | ||
| memberSchemas.push(memberSchema); | ||
| } | ||
| const encodedKeys = new Array(memberNames.length); | ||
| for (let i = 0; i < memberNames.length; ++i) { | ||
| encodedKeys[i] = encodeCborStringKey(memberNames[i]); | ||
| } | ||
| const cache = { memberNames, memberSchemas, encodedKeys }; | ||
| schema[CBOR_STRUCT_CACHE] = cache; | ||
| return cache; | ||
| } | ||
| function encodeCborStringKey(s) { | ||
| let utf8Bytes; | ||
| if (USE_BUFFER) { | ||
| utf8Bytes = Buffer.from(s, "utf-8"); | ||
| } | ||
| else { | ||
| utf8Bytes = new TextEncoder().encode(s); | ||
| } | ||
| const byteLen = utf8Bytes.length; | ||
| let headerSize; | ||
| if (byteLen < 24) { | ||
| headerSize = 1; | ||
| } | ||
| else if (byteLen < 256) { | ||
| headerSize = 2; | ||
| } | ||
| else { | ||
| headerSize = 3; | ||
| } | ||
| const result = new Uint8Array(headerSize + byteLen); | ||
| if (headerSize === 1) { | ||
| result[0] = (majorUtf8String << 5) | byteLen; | ||
| } | ||
| else if (headerSize === 2) { | ||
| result[0] = (majorUtf8String << 5) | 24; | ||
| result[1] = byteLen; | ||
| } | ||
| else { | ||
| result[0] = (majorUtf8String << 5) | extendedFloat16; | ||
| result[1] = byteLen >> 8; | ||
| result[2] = byteLen & 0xff; | ||
| } | ||
| result.set(utf8Bytes, headerSize); | ||
| return result; | ||
| } | ||
| const USE_BUFFER = typeof Buffer !== "undefined"; | ||
| const textEncoder = new TextEncoder(); | ||
| const INITIAL_BUFFER_SIZE = 2048; | ||
| let buf = USE_BUFFER ? Buffer.allocUnsafe(INITIAL_BUFFER_SIZE) : new Uint8Array(INITIAL_BUFFER_SIZE); | ||
| let view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength); | ||
| let cursor = 0; | ||
| const STRING_CACHE_MAX = 2048; | ||
| const stringEncodeCache = new Map(); | ||
| let encodeCacheEpoch = 0; | ||
| let encodeCacheSaturated = false; | ||
| function allocUnsafe(size) { | ||
| return USE_BUFFER ? Buffer.allocUnsafe(size) : new Uint8Array(size); | ||
| } | ||
| function writeValue(ns, value, container, serdeContext) { | ||
| if (value == null) { | ||
| if (value === undefined && ns.isIdempotencyToken()) { | ||
| writeString(generateIdempotencyToken()); | ||
| return; | ||
| } | ||
| if (value === undefined) { | ||
| ensure(1); | ||
| buf[cursor++] = (majorSpecial << 5) | specialNull; | ||
| return; | ||
| } | ||
| ensure(1); | ||
| buf[cursor++] = (majorSpecial << 5) | specialNull; | ||
| return; | ||
| } | ||
| const isObject = typeof value === "object"; | ||
| if (isObject) { | ||
| if (ns.isBlobSchema()) { | ||
| if (value instanceof Uint8Array) { | ||
| writeBytes(value); | ||
| return; | ||
| } | ||
| } | ||
| if (ns.isTimestampSchema()) { | ||
| if (value instanceof Date) { | ||
| writeTimestamp(value); | ||
| return; | ||
| } | ||
| } | ||
| if (ns.isStructSchema()) { | ||
| writeStruct(ns, value, serdeContext); | ||
| return; | ||
| } | ||
| if (Array.isArray(value) && (ns.isListSchema() || ns.isDocumentSchema())) { | ||
| writeList(ns, value, ns.isDocumentSchema(), serdeContext); | ||
| return; | ||
| } | ||
| if (ns.isMapSchema()) { | ||
| writeMap(ns, value, false, serdeContext); | ||
| return; | ||
| } | ||
| if (value instanceof Date) { | ||
| writeTimestamp(value); | ||
| return; | ||
| } | ||
| if (value instanceof Uint8Array) { | ||
| writeBytes(value); | ||
| return; | ||
| } | ||
| if (value instanceof NumericValue) { | ||
| writeNumericValue(value); | ||
| return; | ||
| } | ||
| if (value[tagSymbol]) { | ||
| const tagged = value; | ||
| writeTag(tagged.tag, tagged.value); | ||
| return; | ||
| } | ||
| if (ns.isDocumentSchema()) { | ||
| if (Array.isArray(value)) { | ||
| writeList(ns, value, true, serdeContext); | ||
| } | ||
| else { | ||
| writeMap(ns, value, true, serdeContext); | ||
| } | ||
| return; | ||
| } | ||
| if (ns.isBigDecimalSchema()) { | ||
| writeUntypedValue(value); | ||
| return; | ||
| } | ||
| writeMap(ns, value, true, serdeContext); | ||
| return; | ||
| } | ||
| if (typeof value === "string") { | ||
| if (ns.isBlobSchema()) { | ||
| const bytes = (serdeContext?.base64Decoder ?? fromBase64)(value); | ||
| writeBytes(bytes); | ||
| return; | ||
| } | ||
| writeString(value); | ||
| return; | ||
| } | ||
| if (typeof value === "number") { | ||
| ensure(9); | ||
| if (Number.isInteger(value) && value >= -0x20000000000000 && value <= 0x1fffffffffffff) { | ||
| writeInteger(value); | ||
| } | ||
| else { | ||
| writeFloat64(value); | ||
| } | ||
| return; | ||
| } | ||
| if (typeof value === "boolean") { | ||
| ensure(1); | ||
| buf[cursor++] = (majorSpecial << 5) | (value ? specialTrue : specialFalse); | ||
| return; | ||
| } | ||
| if (typeof value === "bigint") { | ||
| writeBigInt(value); | ||
| return; | ||
| } | ||
| writeString(String(value)); | ||
| } | ||
| function writeStruct(ns, value, serdeContext) { | ||
| if (ns.isUnionSchema()) { | ||
| let wrote = false; | ||
| for (const [memberName, memberSchema] of ns.structIterator()) { | ||
| const item = value[memberName]; | ||
| if (item != null) { | ||
| ensure(9); | ||
| encodeHeader(majorMap, 1); | ||
| writeString(memberName); | ||
| writeValue(memberSchema, item, ns, serdeContext); | ||
| wrote = true; | ||
| break; | ||
| } | ||
| } | ||
| if (!wrote) { | ||
| const { $unknown } = value; | ||
| if (Array.isArray($unknown)) { | ||
| ensure(9); | ||
| encodeHeader(majorMap, 1); | ||
| writeString($unknown[0]); | ||
| writeUntypedValue($unknown[1]); | ||
| } | ||
| else { | ||
| ensure(9); | ||
| encodeHeader(majorMap, 0); | ||
| } | ||
| } | ||
| return; | ||
| } | ||
| const cache = ns.structIteratorCbor(); | ||
| const { memberNames, memberSchemas, encodedKeys } = cache; | ||
| const z = memberNames.length; | ||
| let headerSize; | ||
| if (z < 24) { | ||
| headerSize = 1; | ||
| } | ||
| else if (z < 256) { | ||
| headerSize = 2; | ||
| } | ||
| else { | ||
| headerSize = 3; | ||
| } | ||
| ensure(headerSize); | ||
| const headerPos = cursor; | ||
| cursor += headerSize; | ||
| let count = 0; | ||
| for (let i = 0; i < z; ++i) { | ||
| const item = value[memberNames[i]]; | ||
| if (item == null && !memberSchemas[i].isIdempotencyToken()) { | ||
| continue; | ||
| } | ||
| const key = encodedKeys[i]; | ||
| ensure(key.length); | ||
| buf.set(key, cursor); | ||
| cursor += key.length; | ||
| writeValue(memberSchemas[i], item, ns, serdeContext); | ||
| ++count; | ||
| } | ||
| if (typeof value.__type === "string") { | ||
| for (const k in value) { | ||
| if (!memberNames.includes(k)) { | ||
| writeString(k); | ||
| writeUntypedValue(value[k]); | ||
| ++count; | ||
| } | ||
| } | ||
| } | ||
| if (headerSize === 1) { | ||
| buf[headerPos] = (majorMap << 5) | count; | ||
| } | ||
| else if (headerSize === 2) { | ||
| buf[headerPos] = (majorMap << 5) | 24; | ||
| buf[headerPos + 1] = count; | ||
| } | ||
| else { | ||
| buf[headerPos] = (majorMap << 5) | extendedFloat16; | ||
| buf[headerPos + 1] = count >> 8; | ||
| buf[headerPos + 2] = count & 0xff; | ||
| } | ||
| } | ||
| function writeList(ns, value, isDocument, serdeContext) { | ||
| const sparse = !!ns.getMergedTraits().sparse; | ||
| const valueSchema = ns.getValueSchema(); | ||
| if (isDocument || sparse) { | ||
| const items = []; | ||
| for (let i = 0; i < value.length; ++i) { | ||
| const item = value[i]; | ||
| if (isDocument) { | ||
| if (item !== undefined) { | ||
| items.push(item); | ||
| } | ||
| } | ||
| else { | ||
| if (item != null || sparse) { | ||
| items.push(item); | ||
| } | ||
| } | ||
| } | ||
| ensure(9); | ||
| encodeHeader(majorList, items.length); | ||
| for (let i = 0; i < items.length; ++i) { | ||
| writeValue(valueSchema, items[i], undefined, serdeContext); | ||
| } | ||
| } | ||
| else { | ||
| let count = 0; | ||
| for (let i = 0; i < value.length; ++i) { | ||
| if (value[i] != null) { | ||
| ++count; | ||
| } | ||
| } | ||
| ensure(9); | ||
| encodeHeader(majorList, count); | ||
| for (let i = 0; i < value.length; ++i) { | ||
| if (value[i] != null) { | ||
| writeValue(valueSchema, value[i], undefined, serdeContext); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| function writeMap(ns, value, isDocument, serdeContext) { | ||
| const sparse = !!ns.getMergedTraits().sparse; | ||
| const valueSchema = ns.getValueSchema(); | ||
| const keys = []; | ||
| for (const k in value) { | ||
| const v = value[k]; | ||
| if (isDocument ? v !== undefined : v != null || sparse) { | ||
| keys.push(k); | ||
| } | ||
| } | ||
| ensure(9); | ||
| encodeHeader(majorMap, keys.length); | ||
| for (let i = 0; i < keys.length; ++i) { | ||
| const k = keys[i]; | ||
| writeString(k); | ||
| writeValue(valueSchema, value[k], undefined, serdeContext); | ||
| } | ||
| } | ||
| function writeUntypedValue(value) { | ||
| if (value == null) { | ||
| ensure(1); | ||
| buf[cursor++] = (majorSpecial << 5) | specialNull; | ||
| return; | ||
| } | ||
| if (typeof value === "string") { | ||
| writeString(value); | ||
| return; | ||
| } | ||
| if (typeof value === "number") { | ||
| ensure(9); | ||
| if (Number.isInteger(value) && value >= -0x20000000000000 && value <= 0x1fffffffffffff) { | ||
| writeInteger(value); | ||
| } | ||
| else { | ||
| writeFloat64(value); | ||
| } | ||
| return; | ||
| } | ||
| if (typeof value === "boolean") { | ||
| ensure(1); | ||
| buf[cursor++] = (majorSpecial << 5) | (value ? specialTrue : specialFalse); | ||
| return; | ||
| } | ||
| if (typeof value === "bigint") { | ||
| writeBigInt(value); | ||
| return; | ||
| } | ||
| if (value instanceof Uint8Array) { | ||
| writeBytes(value); | ||
| return; | ||
| } | ||
| if (value instanceof Date) { | ||
| writeTimestamp(value); | ||
| return; | ||
| } | ||
| if (value instanceof NumericValue) { | ||
| writeNumericValue(value); | ||
| return; | ||
| } | ||
| if (value[tagSymbol]) { | ||
| const tagged = value; | ||
| writeTag(tagged.tag, tagged.value); | ||
| return; | ||
| } | ||
| if (Array.isArray(value)) { | ||
| ensure(9); | ||
| encodeHeader(majorList, value.length); | ||
| for (let i = 0; i < value.length; ++i) { | ||
| writeUntypedValue(value[i]); | ||
| } | ||
| return; | ||
| } | ||
| if (typeof value === "object") { | ||
| const keys = Object.keys(value); | ||
| ensure(9); | ||
| encodeHeader(majorMap, keys.length); | ||
| for (let i = 0; i < keys.length; ++i) { | ||
| writeString(keys[i]); | ||
| writeUntypedValue(value[keys[i]]); | ||
| } | ||
| return; | ||
| } | ||
| writeString(String(value)); | ||
| } | ||
| function ensure(n) { | ||
| if (cursor + n > buf.length) { | ||
| let newSize = buf.length * 2; | ||
| while (newSize < cursor + n) { | ||
| newSize *= 2; | ||
| } | ||
| const next = allocUnsafe(newSize); | ||
| next.set(buf.subarray(0, cursor)); | ||
| buf = next; | ||
| view = new DataView(next.buffer, next.byteOffset, next.byteLength); | ||
| } | ||
| } | ||
| function encodeHeader(major, value) { | ||
| if (value < 24) { | ||
| buf[cursor++] = (major << 5) | value; | ||
| } | ||
| else if (value < 256) { | ||
| buf[cursor++] = (major << 5) | 24; | ||
| buf[cursor++] = value; | ||
| } | ||
| else if (value < 65536) { | ||
| buf[cursor++] = (major << 5) | extendedFloat16; | ||
| buf[cursor++] = value >> 8; | ||
| buf[cursor++] = value & 0xff; | ||
| } | ||
| else if (value < 4294967296) { | ||
| buf[cursor++] = (major << 5) | extendedFloat32; | ||
| view.setUint32(cursor, value); | ||
| cursor += 4; | ||
| } | ||
| else { | ||
| buf[cursor++] = (major << 5) | extendedFloat64; | ||
| const hi = (value / 4294967296) | 0; | ||
| const lo = (value - hi * 4294967296) | 0; | ||
| view.setUint32(cursor, hi); | ||
| view.setUint32(cursor + 4, lo); | ||
| cursor += 8; | ||
| } | ||
| } | ||
| function encodeBigHeader(major, value) { | ||
| const n = Number(value); | ||
| if (n < 4294967296) { | ||
| encodeHeader(major, n); | ||
| return; | ||
| } | ||
| buf[cursor++] = (major << 5) | extendedFloat64; | ||
| view.setBigUint64(cursor, value); | ||
| cursor += 8; | ||
| } | ||
| function writeString(s) { | ||
| const len = s.length; | ||
| if (len <= 23) { | ||
| const cached = stringEncodeCache.get(s); | ||
| if (cached) { | ||
| ensure(cached.bytes.length); | ||
| buf.set(cached.bytes, cursor); | ||
| cursor += cached.bytes.length; | ||
| cached.epoch = encodeCacheEpoch; | ||
| return; | ||
| } | ||
| const start = cursor; | ||
| writeStringUncached(s, len); | ||
| const end = cursor; | ||
| const bytes = Uint8Array.prototype.slice.call(buf, start, end); | ||
| if (stringEncodeCache.size >= STRING_CACHE_MAX) { | ||
| if (encodeCacheSaturated) { | ||
| return; | ||
| } | ||
| let evicted = 0; | ||
| for (const [key, entry] of stringEncodeCache) { | ||
| if (evicted >= 1024) { | ||
| break; | ||
| } | ||
| if (entry.epoch !== encodeCacheEpoch) { | ||
| stringEncodeCache.delete(key); | ||
| ++evicted; | ||
| } | ||
| } | ||
| if (evicted === 0) { | ||
| encodeCacheSaturated = true; | ||
| return; | ||
| } | ||
| } | ||
| if (stringEncodeCache.size < STRING_CACHE_MAX) { | ||
| stringEncodeCache.set(s, { epoch: encodeCacheEpoch, bytes }); | ||
| } | ||
| return; | ||
| } | ||
| writeStringUncached(s, len); | ||
| } | ||
| function writeStringUncached(s, len) { | ||
| if (USE_BUFFER) { | ||
| const maxBytes = len * 3; | ||
| ensure(maxBytes + 9); | ||
| const byteLen = Buffer.byteLength(s); | ||
| encodeHeader(majorUtf8String, byteLen); | ||
| cursor += buf.write(s, cursor); | ||
| } | ||
| else { | ||
| const maxBytes = len * 3; | ||
| ensure(maxBytes + 9); | ||
| const headerPos = cursor; | ||
| const result = textEncoder.encodeInto(s, buf.subarray(headerPos + 9)); | ||
| const byteLen = result.written; | ||
| let headerSize; | ||
| if (byteLen < 24) { | ||
| headerSize = 1; | ||
| } | ||
| else if (byteLen < 256) { | ||
| headerSize = 2; | ||
| } | ||
| else if (byteLen < 65536) { | ||
| headerSize = 3; | ||
| } | ||
| else if (byteLen < 4294967296) { | ||
| headerSize = 5; | ||
| } | ||
| else { | ||
| headerSize = 9; | ||
| } | ||
| if (headerSize < 9) { | ||
| buf.copyWithin(headerPos + headerSize, headerPos + 9, headerPos + 9 + byteLen); | ||
| } | ||
| cursor = headerPos; | ||
| encodeHeader(majorUtf8String, byteLen); | ||
| cursor += byteLen; | ||
| } | ||
| } | ||
| function writeFloat64(value) { | ||
| ensure(9); | ||
| buf[cursor++] = (majorSpecial << 5) | extendedFloat64; | ||
| view.setFloat64(cursor, value); | ||
| cursor += 8; | ||
| } | ||
| function writeInteger(value) { | ||
| ensure(9); | ||
| const nonNegative = value >= 0; | ||
| const major = nonNegative ? majorUint64 : majorNegativeInt64; | ||
| const abs = nonNegative ? value : -value - 1; | ||
| encodeHeader(major, abs); | ||
| } | ||
| function writeBigInt(value) { | ||
| const nonNegative = value >= 0; | ||
| const major = nonNegative ? majorUint64 : majorNegativeInt64; | ||
| const abs = nonNegative ? value : -value - BigInt(1); | ||
| if (abs < BigInt("18446744073709551616")) { | ||
| ensure(9); | ||
| encodeBigHeader(major, abs); | ||
| } | ||
| else { | ||
| const binaryStr = abs.toString(2); | ||
| const byteLen = Math.ceil(binaryStr.length / 8); | ||
| const bigIntBytes = new Uint8Array(byteLen); | ||
| let b = abs; | ||
| for (let i = byteLen - 1; i >= 0; --i) { | ||
| bigIntBytes[i] = Number(b & BigInt(255)); | ||
| b >>= BigInt(8); | ||
| } | ||
| ensure(byteLen + 16); | ||
| buf[cursor++] = nonNegative ? 0b110_00010 : 0b110_00011; | ||
| encodeHeader(majorUnstructuredByteString, byteLen); | ||
| buf.set(bigIntBytes, cursor); | ||
| cursor += byteLen; | ||
| } | ||
| } | ||
| function writeBytes(data) { | ||
| ensure(data.length + 9); | ||
| encodeHeader(majorUnstructuredByteString, data.length); | ||
| buf.set(data, cursor); | ||
| cursor += data.length; | ||
| } | ||
| function writeTag(tagValue, innerValue) { | ||
| ensure(9); | ||
| if (typeof tagValue === "bigint") { | ||
| encodeBigHeader(majorTag, tagValue); | ||
| } | ||
| else { | ||
| encodeHeader(majorTag, tagValue); | ||
| } | ||
| writeUntypedValue(innerValue); | ||
| } | ||
| function writeNumericValue(nv) { | ||
| const decimalIndex = nv.string.indexOf("."); | ||
| const exponent = decimalIndex === -1 ? 0 : decimalIndex - nv.string.length + 1; | ||
| const mantissa = BigInt(nv.string.replace(".", "")); | ||
| ensure(9); | ||
| buf[cursor++] = 0b110_00100; | ||
| encodeHeader(majorList, 2); | ||
| ensure(9); | ||
| writeInteger(exponent); | ||
| writeBigInt(mantissa); | ||
| } | ||
| function writeTimestamp(date) { | ||
| ensure(18); | ||
| encodeHeader(majorTag, 1); | ||
| const epochSecs = date.getTime() / 1000; | ||
| if (Number.isInteger(epochSecs)) { | ||
| writeInteger(epochSecs); | ||
| } | ||
| else { | ||
| writeFloat64(epochSecs); | ||
| } | ||
| } |
| import { SerdeContext } from "@smithy/core/protocols"; | ||
| import type { Schema, ShapeDeserializer } from "@smithy/types"; | ||
| /** | ||
| * @public | ||
| */ | ||
| export declare class CborShapeDeserializer extends SerdeContext implements ShapeDeserializer { | ||
| read(schema: Schema, bytes: Uint8Array): any; | ||
| /** | ||
| * Public because it's called by the protocol implementation to deserialize errors. | ||
| * @internal | ||
| */ | ||
| readValue(_schema: Schema, value: any): any; | ||
| } |
| import { SerdeContext } from "@smithy/core/protocols"; | ||
| import type { Schema, ShapeSerializer } from "@smithy/types"; | ||
| /** | ||
| * @public | ||
| */ | ||
| export declare class CborShapeSerializer extends SerdeContext implements ShapeSerializer { | ||
| private value; | ||
| write(schema: Schema, value: unknown): void; | ||
| /** | ||
| * Recursive serializer transform that copies and prepares the user input object | ||
| * for CBOR serialization. | ||
| */ | ||
| serialize(schema: Schema, source: unknown): any; | ||
| flush(): Uint8Array; | ||
| } |
| import { SerdeContext } from "@smithy/core/protocols"; | ||
| import type { Schema, ShapeDeserializer } from "@smithy/types"; | ||
| /** | ||
| * Single-pass CBOR deserializer that reads bytes and applies Smithy schema | ||
| * transformations in one traversal using module-level state. | ||
| * | ||
| * @internal | ||
| */ | ||
| export declare class SinglePassCborShapeDeserializer extends SerdeContext implements ShapeDeserializer<Uint8Array> { | ||
| constructor(); | ||
| read(schema: Schema, bytes: Uint8Array): any; | ||
| /** | ||
| * Deserialize a pre-decoded JS object per schema. | ||
| * Used by protocol error handling which passes pre-decoded objects. | ||
| * | ||
| * @internal | ||
| */ | ||
| readValue(_schema: Schema, value: any): any; | ||
| } |
| import { SerdeContext } from "@smithy/core/protocols"; | ||
| import type { Schema, ShapeSerializer } from "@smithy/types"; | ||
| /** | ||
| * Single-pass CBOR serializer that walks the Smithy schema and writes CBOR bytes | ||
| * directly to a module-level buffer in one traversal. Eliminates the intermediate | ||
| * JS object tree that the multi-pass CborShapeSerializer builds. | ||
| * | ||
| * @internal | ||
| */ | ||
| export declare class SinglePassCborShapeSerializer extends SerdeContext implements ShapeSerializer<Uint8Array> { | ||
| constructor(); | ||
| write(schema: Schema, value: unknown): void; | ||
| flush(): Uint8Array; | ||
| } | ||
| /** | ||
| * Advance the encoding epoch. Call between serialization batches | ||
| * to allow stale cache entries to be evicted. | ||
| * | ||
| * @internal | ||
| */ | ||
| export declare function advanceSinglePassEncodingEpoch(): void; | ||
| export declare function activateCborStructIterator(): void; |
| import { SerdeContext } from "@smithy/core/protocols"; | ||
| import { Schema, ShapeDeserializer } from "@smithy/types"; | ||
| /** | ||
| * @public | ||
| */ | ||
| export declare class CborShapeDeserializer extends SerdeContext implements ShapeDeserializer { | ||
| read(schema: Schema, bytes: Uint8Array): any; | ||
| /** | ||
| * Public because it's called by the protocol implementation to deserialize errors. | ||
| * @internal | ||
| */ | ||
| readValue(_schema: Schema, value: any): any; | ||
| } |
| import { SerdeContext } from "@smithy/core/protocols"; | ||
| import { Schema, ShapeSerializer } from "@smithy/types"; | ||
| /** | ||
| * @public | ||
| */ | ||
| export declare class CborShapeSerializer extends SerdeContext implements ShapeSerializer { | ||
| private value; | ||
| write(schema: Schema, value: unknown): void; | ||
| /** | ||
| * Recursive serializer transform that copies and prepares the user input object | ||
| * for CBOR serialization. | ||
| */ | ||
| serialize(schema: Schema, source: unknown): any; | ||
| flush(): Uint8Array; | ||
| } |
| import { SerdeContext } from "@smithy/core/protocols"; | ||
| import { Schema, ShapeDeserializer } from "@smithy/types"; | ||
| /** | ||
| * Single-pass CBOR deserializer that reads bytes and applies Smithy schema | ||
| * transformations in one traversal using module-level state. | ||
| * | ||
| * @internal | ||
| */ | ||
| export declare class SinglePassCborShapeDeserializer extends SerdeContext implements ShapeDeserializer<Uint8Array> { | ||
| constructor(); | ||
| read(schema: Schema, bytes: Uint8Array): any; | ||
| /** | ||
| * Deserialize a pre-decoded JS object per schema. | ||
| * Used by protocol error handling which passes pre-decoded objects. | ||
| * | ||
| * @internal | ||
| */ | ||
| readValue(_schema: Schema, value: any): any; | ||
| } |
| import { SerdeContext } from "@smithy/core/protocols"; | ||
| import { Schema, ShapeSerializer } from "@smithy/types"; | ||
| /** | ||
| * Single-pass CBOR serializer that walks the Smithy schema and writes CBOR bytes | ||
| * directly to a module-level buffer in one traversal. Eliminates the intermediate | ||
| * JS object tree that the multi-pass CborShapeSerializer builds. | ||
| * | ||
| * @internal | ||
| */ | ||
| export declare class SinglePassCborShapeSerializer extends SerdeContext implements ShapeSerializer<Uint8Array> { | ||
| constructor(); | ||
| write(schema: Schema, value: unknown): void; | ||
| flush(): Uint8Array; | ||
| } | ||
| /** | ||
| * Advance the encoding epoch. Call between serialization batches | ||
| * to allow stale cache entries to be evicted. | ||
| * | ||
| * @internal | ||
| */ | ||
| export declare function advanceSinglePassEncodingEpoch(): void; | ||
| export declare function activateCborStructIterator(): void; |
@@ -1,2 +0,2 @@ | ||
| const { nv, NumericValue, calculateBodyLength, _parseEpochTimestamp, fromBase64, generateIdempotencyToken } = require("@smithy/core/serde"); | ||
| const { nv, NumericValue, calculateBodyLength, generateIdempotencyToken, fromBase64, _parseEpochTimestamp } = require("@smithy/core/serde"); | ||
| const { HttpRequest, collectBody, SerdeContext, RpcProtocol } = require("@smithy/core/protocols"); | ||
@@ -936,14 +936,2 @@ const { NormalizedSchema, deref, TypeRegistry } = require("@smithy/core/schema"); | ||
| class CborCodec extends SerdeContext { | ||
| createSerializer() { | ||
| const serializer = new CborShapeSerializer(); | ||
| serializer.setSerdeContext(this.serdeContext); | ||
| return serializer; | ||
| } | ||
| createDeserializer() { | ||
| const deserializer = new CborShapeDeserializer(); | ||
| deserializer.setSerdeContext(this.serdeContext); | ||
| return deserializer; | ||
| } | ||
| } | ||
| class CborShapeSerializer extends SerdeContext { | ||
@@ -1039,2 +1027,3 @@ value; | ||
| } | ||
| class CborShapeDeserializer extends SerdeContext { | ||
@@ -1150,2 +1139,15 @@ read(schema, bytes) { | ||
| class CborCodec extends SerdeContext { | ||
| createSerializer() { | ||
| const serializer = new CborShapeSerializer(); | ||
| serializer.setSerdeContext(this.serdeContext); | ||
| return serializer; | ||
| } | ||
| createDeserializer() { | ||
| const deserializer = new CborShapeDeserializer(); | ||
| deserializer.setSerdeContext(this.serdeContext); | ||
| return deserializer; | ||
| } | ||
| } | ||
| class SmithyRpcV2CborProtocol extends RpcProtocol { | ||
@@ -1152,0 +1154,0 @@ codec = new CborCodec(); |
@@ -532,2 +532,5 @@ const { getSmithyContext, HttpResponse, toEndpointV1 } = require("@smithy/core/transport"); | ||
| } | ||
| structIteratorCbor() { | ||
| throw new Error("@smithy/core/schema - structIteratorCbor not loaded."); | ||
| } | ||
| } | ||
@@ -534,0 +537,0 @@ function member(memberSchema, memberName) { |
| import { SerdeContext } from "@smithy/core/protocols"; | ||
| import { NormalizedSchema } from "@smithy/core/schema"; | ||
| import { NumericValue, _parseEpochTimestamp, fromBase64, generateIdempotencyToken } from "@smithy/core/serde"; | ||
| import { cbor } from "./cbor"; | ||
| import { dateToTag } from "./parseCborBody"; | ||
| import { CborShapeSerializer } from "./codec-v1/CborShapeSerializer"; | ||
| import { CborShapeDeserializer } from "./codec-v1/CborShapeDeserializer"; | ||
| export class CborCodec extends SerdeContext { | ||
@@ -18,200 +16,1 @@ createSerializer() { | ||
| } | ||
| export class CborShapeSerializer extends SerdeContext { | ||
| value; | ||
| write(schema, value) { | ||
| this.value = this.serialize(schema, value); | ||
| } | ||
| serialize(schema, source) { | ||
| const ns = NormalizedSchema.of(schema); | ||
| if (source == null) { | ||
| if (ns.isIdempotencyToken()) { | ||
| return generateIdempotencyToken(); | ||
| } | ||
| return source; | ||
| } | ||
| if (ns.isBlobSchema()) { | ||
| if (typeof source === "string") { | ||
| return (this.serdeContext?.base64Decoder ?? fromBase64)(source); | ||
| } | ||
| return source; | ||
| } | ||
| if (ns.isTimestampSchema()) { | ||
| if (typeof source === "number" || typeof source === "bigint") { | ||
| return dateToTag(new Date((Number(source) / 1000) | 0)); | ||
| } | ||
| return dateToTag(source); | ||
| } | ||
| if (typeof source === "function" || typeof source === "object") { | ||
| const sourceObject = source; | ||
| if (ns.isListSchema() && Array.isArray(sourceObject)) { | ||
| const sparse = !!ns.getMergedTraits().sparse; | ||
| const newArray = []; | ||
| let i = 0; | ||
| for (const item of sourceObject) { | ||
| const value = this.serialize(ns.getValueSchema(), item); | ||
| if (value != null || sparse) { | ||
| newArray[i++] = value; | ||
| } | ||
| } | ||
| return newArray; | ||
| } | ||
| if (sourceObject instanceof Date) { | ||
| return dateToTag(sourceObject); | ||
| } | ||
| const newObject = {}; | ||
| if (ns.isMapSchema()) { | ||
| const sparse = !!ns.getMergedTraits().sparse; | ||
| for (const key in sourceObject) { | ||
| const value = this.serialize(ns.getValueSchema(), sourceObject[key]); | ||
| if (value != null || sparse) { | ||
| newObject[key] = value; | ||
| } | ||
| } | ||
| } | ||
| else if (ns.isStructSchema()) { | ||
| for (const [key, memberSchema] of ns.structIterator()) { | ||
| const value = this.serialize(memberSchema, sourceObject[key]); | ||
| if (value != null) { | ||
| newObject[key] = value; | ||
| } | ||
| } | ||
| const isUnion = ns.isUnionSchema(); | ||
| if (isUnion && Array.isArray(sourceObject.$unknown)) { | ||
| const [k, v] = sourceObject.$unknown; | ||
| newObject[k] = v; | ||
| } | ||
| else if (typeof sourceObject.__type === "string") { | ||
| for (const k in sourceObject) { | ||
| if (!(k in newObject)) { | ||
| newObject[k] = this.serialize(15, sourceObject[k]); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| else if (ns.isDocumentSchema()) { | ||
| for (const key in sourceObject) { | ||
| newObject[key] = this.serialize(ns.getValueSchema(), sourceObject[key]); | ||
| } | ||
| } | ||
| else if (ns.isBigDecimalSchema()) { | ||
| return sourceObject; | ||
| } | ||
| return newObject; | ||
| } | ||
| return source; | ||
| } | ||
| flush() { | ||
| const buffer = cbor.serialize(this.value); | ||
| this.value = undefined; | ||
| return buffer; | ||
| } | ||
| } | ||
| export class CborShapeDeserializer extends SerdeContext { | ||
| read(schema, bytes) { | ||
| const data = cbor.deserialize(bytes); | ||
| return this.readValue(schema, data); | ||
| } | ||
| readValue(_schema, value) { | ||
| const ns = NormalizedSchema.of(_schema); | ||
| if (ns.isTimestampSchema()) { | ||
| if (typeof value === "number") { | ||
| return _parseEpochTimestamp(value); | ||
| } | ||
| if (typeof value === "object") { | ||
| if (value.tag === 1 && "value" in value) { | ||
| return _parseEpochTimestamp(value.value); | ||
| } | ||
| } | ||
| } | ||
| if (ns.isBlobSchema()) { | ||
| if (typeof value === "string") { | ||
| return (this.serdeContext?.base64Decoder ?? fromBase64)(value); | ||
| } | ||
| return value; | ||
| } | ||
| if (typeof value === "undefined" || | ||
| typeof value === "boolean" || | ||
| typeof value === "number" || | ||
| typeof value === "string" || | ||
| typeof value === "bigint" || | ||
| typeof value === "symbol") { | ||
| return value; | ||
| } | ||
| else if (typeof value === "object") { | ||
| if (value === null) { | ||
| return null; | ||
| } | ||
| if ("byteLength" in value) { | ||
| return value; | ||
| } | ||
| if (value instanceof Date) { | ||
| return value; | ||
| } | ||
| if (ns.isDocumentSchema()) { | ||
| return value; | ||
| } | ||
| if (ns.isListSchema()) { | ||
| const newArray = []; | ||
| const memberSchema = ns.getValueSchema(); | ||
| for (const item of value) { | ||
| const itemValue = this.readValue(memberSchema, item); | ||
| newArray.push(itemValue); | ||
| } | ||
| return newArray; | ||
| } | ||
| const newObject = {}; | ||
| if (ns.isMapSchema()) { | ||
| const targetSchema = ns.getValueSchema(); | ||
| for (const key in value) { | ||
| const itemValue = this.readValue(targetSchema, value[key]); | ||
| newObject[key] = itemValue; | ||
| } | ||
| } | ||
| else if (ns.isStructSchema()) { | ||
| const isUnion = ns.isUnionSchema(); | ||
| let keys; | ||
| if (isUnion) { | ||
| keys = new Set(); | ||
| for (const k in value) { | ||
| if (k !== "__type") { | ||
| keys.add(k); | ||
| } | ||
| } | ||
| } | ||
| for (const [key, memberSchema] of ns.structIterator()) { | ||
| if (isUnion) { | ||
| keys.delete(key); | ||
| } | ||
| if (value[key] != null) { | ||
| newObject[key] = this.readValue(memberSchema, value[key]); | ||
| } | ||
| } | ||
| if (isUnion && keys?.size === 1) { | ||
| let newObjectEmpty = true; | ||
| for (const _ in newObject) { | ||
| newObjectEmpty = false; | ||
| break; | ||
| } | ||
| if (newObjectEmpty) { | ||
| const k = keys.values().next().value; | ||
| newObject.$unknown = [k, value[k]]; | ||
| } | ||
| } | ||
| else if (typeof value.__type === "string") { | ||
| for (const k in value) { | ||
| if (!(k in newObject)) { | ||
| newObject[k] = value[k]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| else if (value instanceof NumericValue) { | ||
| return value; | ||
| } | ||
| return newObject; | ||
| } | ||
| else { | ||
| return value; | ||
| } | ||
| } | ||
| } |
@@ -5,2 +5,4 @@ export { cbor } from "./cbor"; | ||
| export { SmithyRpcV2CborProtocol } from "./SmithyRpcV2CborProtocol"; | ||
| export { CborCodec, CborShapeDeserializer, CborShapeSerializer } from "./CborCodec"; | ||
| export { CborCodec } from "./CborCodec"; | ||
| export { CborShapeSerializer } from "./codec-v1/CborShapeSerializer"; | ||
| export { CborShapeDeserializer } from "./codec-v1/CborShapeDeserializer"; |
@@ -291,2 +291,5 @@ import { deref } from "../deref"; | ||
| } | ||
| structIteratorCbor() { | ||
| throw new Error("@smithy/core/schema - structIteratorCbor not loaded."); | ||
| } | ||
| } | ||
@@ -293,0 +296,0 @@ function member(memberSchema, memberName) { |
| import { SerdeContext } from "@smithy/core/protocols"; | ||
| import type { Codec, Schema, ShapeDeserializer, ShapeSerializer } from "@smithy/types"; | ||
| import type { Codec } from "@smithy/types"; | ||
| import { CborShapeSerializer } from "./codec-v1/CborShapeSerializer"; | ||
| import { CborShapeDeserializer } from "./codec-v1/CborShapeDeserializer"; | ||
| /** | ||
@@ -10,25 +12,1 @@ * @public | ||
| } | ||
| /** | ||
| * @public | ||
| */ | ||
| export declare class CborShapeSerializer extends SerdeContext implements ShapeSerializer { | ||
| private value; | ||
| write(schema: Schema, value: unknown): void; | ||
| /** | ||
| * Recursive serializer transform that copies and prepares the user input object | ||
| * for CBOR serialization. | ||
| */ | ||
| serialize(schema: Schema, source: unknown): any; | ||
| flush(): Uint8Array; | ||
| } | ||
| /** | ||
| * @public | ||
| */ | ||
| export declare class CborShapeDeserializer extends SerdeContext implements ShapeDeserializer { | ||
| read(schema: Schema, bytes: Uint8Array): any; | ||
| /** | ||
| * Public because it's called by the protocol implementation to deserialize errors. | ||
| * @internal | ||
| */ | ||
| readValue(_schema: Schema, value: any): any; | ||
| } |
@@ -5,2 +5,4 @@ export { cbor } from "./cbor"; | ||
| export { SmithyRpcV2CborProtocol } from "./SmithyRpcV2CborProtocol"; | ||
| export { CborCodec, CborShapeDeserializer, CborShapeSerializer } from "./CborCodec"; | ||
| export { CborCodec } from "./CborCodec"; | ||
| export { CborShapeSerializer } from "./codec-v1/CborShapeSerializer"; | ||
| export { CborShapeDeserializer } from "./codec-v1/CborShapeDeserializer"; |
@@ -16,4 +16,4 @@ import { RpcProtocol } from "@smithy/core/protocols"; | ||
| private codec; | ||
| protected serializer: import("./CborCodec").CborShapeSerializer; | ||
| protected deserializer: import("./CborCodec").CborShapeDeserializer; | ||
| protected serializer: import(".").CborShapeSerializer; | ||
| protected deserializer: import(".").CborShapeDeserializer; | ||
| constructor({ defaultNamespace, errorTypeRegistries, }: { | ||
@@ -20,0 +20,0 @@ defaultNamespace: string; |
@@ -139,2 +139,14 @@ import type { $MemberSchema, $Schema, $SchemaRef, NormalizedSchema as INormalizedSchema, SchemaRef, SchemaTraitsObject, StaticSchema } from "@smithy/types"; | ||
| structIterator(): Generator<[string, NormalizedSchema], undefined, undefined>; | ||
| /** | ||
| * CBOR-optimized struct iteration. Returns a cache of parallel arrays | ||
| * (memberNames, memberSchemas, encodedKeys) for direct indexed iteration. | ||
| * Implementation is patched by the cbor submodule on load. | ||
| * | ||
| * @internal | ||
| */ | ||
| structIteratorCbor(): { | ||
| memberNames: string[]; | ||
| memberSchemas: NormalizedSchema[]; | ||
| encodedKeys: Uint8Array[]; | ||
| }; | ||
| } | ||
@@ -141,0 +153,0 @@ /** |
| import { SerdeContext } from "@smithy/core/protocols"; | ||
| import { Codec, Schema, ShapeDeserializer, ShapeSerializer } from "@smithy/types"; | ||
| import { Codec } from "@smithy/types"; | ||
| import { CborShapeSerializer } from "./codec-v1/CborShapeSerializer"; | ||
| import { CborShapeDeserializer } from "./codec-v1/CborShapeDeserializer"; | ||
| /** | ||
@@ -10,25 +12,1 @@ * @public | ||
| } | ||
| /** | ||
| * @public | ||
| */ | ||
| export declare class CborShapeSerializer extends SerdeContext implements ShapeSerializer { | ||
| private value; | ||
| write(schema: Schema, value: unknown): void; | ||
| /** | ||
| * Recursive serializer transform that copies and prepares the user input object | ||
| * for CBOR serialization. | ||
| */ | ||
| serialize(schema: Schema, source: unknown): any; | ||
| flush(): Uint8Array; | ||
| } | ||
| /** | ||
| * @public | ||
| */ | ||
| export declare class CborShapeDeserializer extends SerdeContext implements ShapeDeserializer { | ||
| read(schema: Schema, bytes: Uint8Array): any; | ||
| /** | ||
| * Public because it's called by the protocol implementation to deserialize errors. | ||
| * @internal | ||
| */ | ||
| readValue(_schema: Schema, value: any): any; | ||
| } |
@@ -5,2 +5,4 @@ export { cbor } from "./cbor"; | ||
| export { SmithyRpcV2CborProtocol } from "./SmithyRpcV2CborProtocol"; | ||
| export { CborCodec, CborShapeDeserializer, CborShapeSerializer } from "./CborCodec"; | ||
| export { CborCodec } from "./CborCodec"; | ||
| export { CborShapeSerializer } from "./codec-v1/CborShapeSerializer"; | ||
| export { CborShapeDeserializer } from "./codec-v1/CborShapeDeserializer"; |
@@ -16,4 +16,4 @@ import { RpcProtocol } from "@smithy/core/protocols"; | ||
| private codec; | ||
| protected serializer: import("./CborCodec").CborShapeSerializer; | ||
| protected deserializer: import("./CborCodec").CborShapeDeserializer; | ||
| protected serializer: import(".").CborShapeSerializer; | ||
| protected deserializer: import(".").CborShapeDeserializer; | ||
| constructor({ defaultNamespace, errorTypeRegistries, }: { | ||
@@ -20,0 +20,0 @@ defaultNamespace: string; |
@@ -142,2 +142,14 @@ import { $MemberSchema, $Schema, $SchemaRef, NormalizedSchema as INormalizedSchema, SchemaRef, SchemaTraitsObject, StaticSchema } from "@smithy/types"; | ||
| ], undefined, undefined>; | ||
| /** | ||
| * CBOR-optimized struct iteration. Returns a cache of parallel arrays | ||
| * (memberNames, memberSchemas, encodedKeys) for direct indexed iteration. | ||
| * Implementation is patched by the cbor submodule on load. | ||
| * | ||
| * @internal | ||
| */ | ||
| structIteratorCbor(): { | ||
| memberNames: string[]; | ||
| memberSchemas: NormalizedSchema[]; | ||
| encodedKeys: Uint8Array[]; | ||
| }; | ||
| } | ||
@@ -144,0 +156,0 @@ /** |
+2
-1
| { | ||
| "name": "@smithy/core", | ||
| "version": "3.30.0", | ||
| "version": "3.31.0", | ||
| "homepage": "https://github.com/smithy-lang/smithy-typescript/tree/main/packages/core", | ||
@@ -223,2 +223,3 @@ "license": "Apache-2.0", | ||
| "benchmark:checksum": "node ./scripts/checksum-perf.mjs", | ||
| "benchmark:schema:cbor": "node ./scripts/cbor-shape-perf.mjs", | ||
| "build": "concurrently 'yarn:build:types' 'yarn:build:es:cjs'", | ||
@@ -225,0 +226,0 @@ "build:es:cjs": "node ../../scripts/compilation/es_cjs.js", |
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
1701177
2.59%1096
1.11%42474
3.3%