AK-21/Graphite-Industrial-Intelligence
0
1"use strict";2var __defProp = Object.defineProperty;3var __getOwnPropDesc = Object.getOwnPropertyDescriptor;4var __getOwnPropNames = Object.getOwnPropertyNames;5var __hasOwnProp = Object.prototype.hasOwnProperty;6var __export = (target, all) => {7 for (var name in all)8 __defProp(target, name, { get: all[name], enumerable: true });9};10var __copyProps = (to, from, except, desc) => {11 if (from && typeof from === "object" || typeof from === "function") {12 for (let key of __getOwnPropNames(from))13 if (!__hasOwnProp.call(to, key) && key !== except)14 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });15 }16 return to;17};18var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);19var blob_exports = {};20__export(blob_exports, {21 SQLiteBigInt: () => SQLiteBigInt,22 SQLiteBigIntBuilder: () => SQLiteBigIntBuilder,23 SQLiteBlobBuffer: () => SQLiteBlobBuffer,24 SQLiteBlobBufferBuilder: () => SQLiteBlobBufferBuilder,25 SQLiteBlobJson: () => SQLiteBlobJson,26 SQLiteBlobJsonBuilder: () => SQLiteBlobJsonBuilder,27 blob: () => blob28});29module.exports = __toCommonJS(blob_exports);30var import_entity = require("../../entity.cjs");31var import_utils = require("../../utils.cjs");32var import_common = require("./common.cjs");33class SQLiteBigIntBuilder extends import_common.SQLiteColumnBuilder {34 static [import_entity.entityKind] = "SQLiteBigIntBuilder";35 constructor(name) {36 super(name, "bigint", "SQLiteBigInt");37 }38 /** @internal */39 build(table) {40 return new SQLiteBigInt(table, this.config);41 }42}43class SQLiteBigInt extends import_common.SQLiteColumn {44 static [import_entity.entityKind] = "SQLiteBigInt";45 getSQLType() {46 return "blob";47 }48 mapFromDriverValue(value) {49 if (typeof Buffer !== "undefined" && Buffer.from) {50 const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);51 return BigInt(buf.toString("utf8"));52 }53 return BigInt(import_utils.textDecoder.decode(value));54 }55 mapToDriverValue(value) {56 return Buffer.from(value.toString());57 }58}59class SQLiteBlobJsonBuilder extends import_common.SQLiteColumnBuilder {60 static [import_entity.entityKind] = "SQLiteBlobJsonBuilder";61 constructor(name) {62 super(name, "json", "SQLiteBlobJson");63 }64 /** @internal */65 build(table) {66 return new SQLiteBlobJson(67 table,68 this.config69 );70 }71}72class SQLiteBlobJson extends import_common.SQLiteColumn {73 static [import_entity.entityKind] = "SQLiteBlobJson";74 getSQLType() {75 return "blob";76 }77 mapFromDriverValue(value) {78 if (typeof Buffer !== "undefined" && Buffer.from) {79 const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);80 return JSON.parse(buf.toString("utf8"));81 }82 return JSON.parse(import_utils.textDecoder.decode(value));83 }84 mapToDriverValue(value) {85 return Buffer.from(JSON.stringify(value));86 }87}88class SQLiteBlobBufferBuilder extends import_common.SQLiteColumnBuilder {89 static [import_entity.entityKind] = "SQLiteBlobBufferBuilder";90 constructor(name) {91 super(name, "buffer", "SQLiteBlobBuffer");92 }93 /** @internal */94 build(table) {95 return new SQLiteBlobBuffer(table, this.config);96 }97}98class SQLiteBlobBuffer extends import_common.SQLiteColumn {99 static [import_entity.entityKind] = "SQLiteBlobBuffer";100 mapFromDriverValue(value) {101 if (Buffer.isBuffer(value)) {102 return value;103 }104 return Buffer.from(value);105 }106 getSQLType() {107 return "blob";108 }109}110function blob(a, b) {111 const { name, config } = (0, import_utils.getColumnNameAndConfig)(a, b);112 if (config?.mode === "json") {113 return new SQLiteBlobJsonBuilder(name);114 }115 if (config?.mode === "bigint") {116 return new SQLiteBigIntBuilder(name);117 }118 return new SQLiteBlobBufferBuilder(name);119}120// Annotate the CommonJS export names for ESM import in node:1210 && (module.exports = {122 SQLiteBigInt,123 SQLiteBigIntBuilder,124 SQLiteBlobBuffer,125 SQLiteBlobBufferBuilder,126 SQLiteBlobJson,127 SQLiteBlobJsonBuilder,128 blob129});130//# sourceMappingURL=blob.cjs.map