File Explorer

/proc/self/root/proc/4/root/var/runtime/node_modules/@aws-sdk/dynamodb-codec/dist-cjs

This explorer reads the filesystem of the server it runs on, so /workspace/user isn't present here. Browsing and the terminal still work against this server's own disk from /.

index.js10.2 KB · 294 lines
const { JsonCodec, JsonShapeSerializer, JsonShapeDeserializer, JsonCodec2, JsonShapeSerializer2, JsonShapeDeserializer2 } = require("@aws-sdk/core/protocols");const { NormalizedSchema } = require("@smithy/core/schema");const { toBase64, fromBase64 } = require("@smithy/core/serde"); class DynamoDBJsonCodec extends JsonCodec {    constructor() {        super({            timestampFormat: {                useTrait: true,                default: 7,            },            jsonName: false,        });    }    createSerializer() {        const serializer = new DynamoDBJsonShapeSerializer(this.settings);        serializer.setSerdeContext(this.serdeContext);        return serializer;    }    createDeserializer() {        const deserializer = new DynamoDBJsonShapeDeserializer(this.settings);        deserializer.setSerdeContext(this.serdeContext);        return deserializer;    }}const ATTRIBUTE_VALUE$1 = "com.amazonaws.dynamodb#AttributeValue";class DynamoDBJsonShapeSerializer extends JsonShapeSerializer {    _write(schema, value, container) {        const ns = NormalizedSchema.of(schema);        if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE$1) {            if (value && typeof value === "object") {                const av = value;                const out = this.copyRemoveNulls(av);                const base64Encode = this.serdeContext?.base64Encoder ?? toBase64;                if (av.B instanceof Uint8Array) {                    out.B = base64Encode(av.B);                }                if (Array.isArray(av.BS)) {                    out.BS = av.BS.map(base64Encode);                }                if (Array.isArray(av.L)) {                    const list = [];                    for (const v of av.L) {                        if (v != null) {                            list.push(this._write(ns, v, container));                        }                    }                    out.L = list;                }                if (av.M && typeof av.M === "object") {                    out.M = {};                    for (const [k, v] of Object.entries(av.M)) {                        if (v != null) {                            out.M[k] = this._write(ns, v, container);                        }                    }                }                return out;            }        }        return super._write(ns, value, container);    }    copyRemoveNulls(v) {        if (typeof v !== "object") {            return v;        }        if (v === null) {            return {};        }        if (Array.isArray(v)) {            const out = [];            for (const item of v) {                if (item != null) {                    out.push(this.copyRemoveNulls(item));                }            }            return out;        }        const out = {};        for (const [k, _v] of Object.entries(v)) {            if (_v != null) {                if (["B", "BS", "L", "M"].includes(k)) {                    continue;                }                out[k] = this.copyRemoveNulls(_v);            }        }        return out;    }}class DynamoDBJsonShapeDeserializer extends JsonShapeDeserializer {    _read(schema, value) {        const ns = NormalizedSchema.of(schema);        if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE$1) {            if (value && typeof value === "object") {                const av = value;                const out = av;                const base64Decoder = this.serdeContext?.base64Decoder ?? fromBase64;                if (typeof av.B === "string") {                    out.B = base64Decoder(av.B);                }                if (Array.isArray(av.BS)) {                    out.BS = av.BS.map(base64Decoder);                }                if (Array.isArray(av.L)) {                    out.L = av.L.map((v) => this._read(ns, v));                }                if (av.M && typeof av.M === "object") {                    for (const [k, v] of Object.entries(av.M)) {                        out.M[k] = this._read(ns, v);                    }                }                return out;            }        }        return super._read(ns, value);    }} const ATTRIBUTE_VALUE = "com.amazonaws.dynamodb#AttributeValue";class DynamoDBJsonShapeSerializer2 extends JsonShapeSerializer2 {    writeValue(schema, value, container) {        if (value != null && typeof value === "object") {            const ns = NormalizedSchema.of(schema);            if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE) {                this.writeAttributeValue(value);                return;            }        }        super.writeValue(schema, value, container);    }    writeAttributeValue(av) {        const base64Encode = this.serdeContext?.base64Encoder ?? toBase64;        this.writeAscii("{");        let first = true;        for (const key in av) {            const val = av[key];            if (val == null)                continue;            if (!first) {                this.writeAscii(",");            }            first = false;            this.writeAsciiQuoted(key);            this.writeAscii(":");            switch (key) {                case "B":                    if (val instanceof Uint8Array) {                        this.writeBase64(val);                    }                    else {                        this.writeJsonString(val);                    }                    break;                case "BS":                    this.writeAscii("[");                    {                        const arr = val;                        for (let i = 0; i < arr.length; i++) {                            if (i > 0)                                this.writeAscii(",");                            const item = arr[i];                            if (item instanceof Uint8Array) {                                this.writeBase64(item);                            }                            else {                                this.writeJsonString(base64Encode(item));                            }                        }                    }                    this.writeAscii("]");                    break;                case "L":                    this.writeAscii("[");                    {                        const arr = val;                        for (let i = 0; i < arr.length; i++) {                            if (i > 0)                                this.writeAscii(",");                            if (arr[i] != null) {                                this.writeAttributeValue(arr[i]);                            }                            else {                                this.writeAscii("null");                            }                        }                    }                    this.writeAscii("]");                    break;                case "M":                    this.writeAscii("{");                    {                        const map = val;                        let mapFirst = true;                        for (const k in map) {                            if (map[k] == null)                                continue;                            if (!mapFirst)                                this.writeAscii(",");                            mapFirst = false;                            this.writeJsonString(k);                            this.writeAscii(":");                            this.writeAttributeValue(map[k]);                        }                    }                    this.writeAscii("}");                    break;                case "SS":                case "NS":                    this.writeAscii("[");                    {                        const arr = val;                        for (let i = 0; i < arr.length; i++) {                            if (i > 0)                                this.writeAscii(",");                            this.writeJsonString(arr[i]);                        }                    }                    this.writeAscii("]");                    break;                case "S":                case "N":                    this.writeJsonString(val);                    break;                case "BOOL":                    this.writeAscii(val ? "true" : "false");                    break;                case "NULL":                    this.writeAscii(val ? "true" : "false");                    break;                default:                    this.writeAscii(JSON.stringify(val));                    break;            }        }        this.writeAscii("}");    }}class DynamoDBJsonShapeDeserializer2 extends JsonShapeDeserializer2 {    _read(schema, value) {        const ns = NormalizedSchema.of(schema);        if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE) {            if (value && typeof value === "object") {                return this.readAttributeValue(value);            }        }        return super._read(ns, value);    }    readAttributeValue(av) {        const base64Decode = this.serdeContext?.base64Decoder ?? fromBase64;        const out = av;        if (typeof av.B === "string") {            out.B = base64Decode(av.B);        }        if (Array.isArray(av.BS)) {            out.BS = av.BS.map(base64Decode);        }        if (Array.isArray(av.L)) {            out.L = av.L.map((v) => this.readAttributeValue(v));        }        if (av.M && typeof av.M === "object") {            const m = av.M;            for (const k in m) {                m[k] = this.readAttributeValue(m[k]);            }        }        return out;    }}class DynamoDBJsonCodec2 extends JsonCodec2 {    constructor() {        super({            timestampFormat: {                useTrait: true,                default: 7,            },            jsonName: false,        });    }    createSerializer() {        const serializer = new DynamoDBJsonShapeSerializer2(this.settings);        serializer.setSerdeContext(this.serdeContext);        return serializer;    }    createDeserializer() {        const deserializer = new DynamoDBJsonShapeDeserializer2(this.settings);        deserializer.setSerdeContext(this.serdeContext);        return deserializer;    }} exports.DynamoDBJsonCodec = DynamoDBJsonCodec;exports.DynamoDBJsonCodec2 = DynamoDBJsonCodec2;