@tableland/sdk
Advanced tools
Comparing version 4.4.1 to 4.4.2
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.jsonFileAliases = exports.extractChainId = exports.extractSigner = exports.extractBaseUrl = exports.checkWait = void 0; | ||
const node_fs_1 = __importDefault(require("node:fs")); | ||
const chains_js_1 = require("./chains.js"); | ||
@@ -49,16 +68,31 @@ const ethers_js_1 = require("./ethers.js"); | ||
exports.extractChainId = extractChainId; | ||
const findOrCreateFile = function (filepath) { | ||
if (!node_fs_1.default.existsSync(filepath)) { | ||
node_fs_1.default.writeFileSync(filepath, JSON.stringify({})); | ||
const findOrCreateFile = async function (filepath) { | ||
const fs = await getFsModule(); | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
if (!fs.existsSync(filepath)) { | ||
fs.writeFileSync(filepath, JSON.stringify({})); | ||
} | ||
return node_fs_1.default.readFileSync(filepath); | ||
return fs.readFileSync(filepath); | ||
}; | ||
// TODO: next major we should remove the jsonFileAliases helper and expose it | ||
// in a different package since it doesn't work in the browser. | ||
const getFsModule = (function () { | ||
let fs; | ||
return async function () { | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
if (fs) | ||
return fs; | ||
fs = await Promise.resolve().then(() => __importStar(require(/* webpackIgnore: true */ "fs"))); | ||
return fs; | ||
}; | ||
})(); | ||
function jsonFileAliases(filepath) { | ||
return { | ||
read: async function () { | ||
const jsonBuf = findOrCreateFile(filepath); | ||
const jsonBuf = await findOrCreateFile(filepath); | ||
return JSON.parse(jsonBuf.toString()); | ||
}, | ||
write: async function (nameMap) { | ||
node_fs_1.default.writeFileSync(filepath, JSON.stringify(nameMap)); | ||
const fs = await getFsModule(); | ||
fs.writeFileSync(filepath, JSON.stringify(nameMap)); | ||
}, | ||
@@ -65,0 +99,0 @@ }; |
@@ -1,2 +0,1 @@ | ||
import fs from "node:fs"; | ||
import { getBaseUrl } from "./chains.js"; | ||
@@ -39,3 +38,5 @@ import { getSigner } from "./ethers.js"; | ||
} | ||
const findOrCreateFile = function (filepath) { | ||
const findOrCreateFile = async function (filepath) { | ||
const fs = await getFsModule(); | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
if (!fs.existsSync(filepath)) { | ||
@@ -46,9 +47,22 @@ fs.writeFileSync(filepath, JSON.stringify({})); | ||
}; | ||
// TODO: next major we should remove the jsonFileAliases helper and expose it | ||
// in a different package since it doesn't work in the browser. | ||
const getFsModule = (function () { | ||
let fs; | ||
return async function () { | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
if (fs) | ||
return fs; | ||
fs = await import(/* webpackIgnore: true */ "fs"); | ||
return fs; | ||
}; | ||
})(); | ||
export function jsonFileAliases(filepath) { | ||
return { | ||
read: async function () { | ||
const jsonBuf = findOrCreateFile(filepath); | ||
const jsonBuf = await findOrCreateFile(filepath); | ||
return JSON.parse(jsonBuf.toString()); | ||
}, | ||
write: async function (nameMap) { | ||
const fs = await getFsModule(); | ||
fs.writeFileSync(filepath, JSON.stringify(nameMap)); | ||
@@ -55,0 +69,0 @@ }, |
{ | ||
"name": "@tableland/sdk", | ||
"version": "4.4.1", | ||
"version": "4.4.2", | ||
"description": "A database client and helpers for the Tableland network", | ||
@@ -86,3 +86,3 @@ "publishConfig": { | ||
"@playwright/test": "^1.30.0", | ||
"@tableland/local": "^1.3.3-dev.5", | ||
"@tableland/local": "^2.0.0", | ||
"@types/assert": "^1.5.6", | ||
@@ -89,0 +89,0 @@ "@types/mocha": "^10.0.1", |
@@ -1,2 +0,1 @@ | ||
import fs from "node:fs"; | ||
import { type WaitableTransactionReceipt } from "../registry/utils.js"; | ||
@@ -82,3 +81,5 @@ import { type ChainName, getBaseUrl } from "./chains.js"; | ||
const findOrCreateFile = function (filepath: string): Buffer { | ||
const findOrCreateFile = async function (filepath: string): Promise<Buffer> { | ||
const fs = await getFsModule(); | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
if (!fs.existsSync(filepath)) { | ||
@@ -91,9 +92,23 @@ fs.writeFileSync(filepath, JSON.stringify({})); | ||
// TODO: next major we should remove the jsonFileAliases helper and expose it | ||
// in a different package since it doesn't work in the browser. | ||
const getFsModule = (function () { | ||
let fs: any; | ||
return async function () { | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
if (fs) return fs; | ||
fs = await import(/* webpackIgnore: true */ "fs"); | ||
return fs; | ||
}; | ||
})(); | ||
export function jsonFileAliases(filepath: string): AliasesNameMap { | ||
return { | ||
read: async function (): Promise<NameMapping> { | ||
const jsonBuf = findOrCreateFile(filepath); | ||
const jsonBuf = await findOrCreateFile(filepath); | ||
return JSON.parse(jsonBuf.toString()); | ||
}, | ||
write: async function (nameMap: NameMapping) { | ||
const fs = await getFsModule(); | ||
fs.writeFileSync(filepath, JSON.stringify(nameMap)); | ||
@@ -100,0 +115,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
574048
10770
2