@fileverse-dev/formulajs 4.4.37 → 4.4.38-col-3

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.
package/lib/cjs/index.cjs CHANGED
@@ -8104,20 +8104,32 @@ const WEEKEND_TYPES = [
8104
8104
  [6, 6]
8105
8105
  ];
8106
8106
 
8107
- const datePartition = (date) => {
8107
+ const datePartition = (date, utc = false) => {
8108
8108
  const pad = (n) => n.toString().padStart(2, "0");
8109
8109
 
8110
- const day = pad(date.getUTCDate());
8111
- const month = pad(date.getUTCMonth() + 1);
8112
- const year = date.getUTCFullYear();
8113
- const hours = pad(date.getUTCHours());
8114
- const minutes = pad(date.getUTCMinutes());
8115
- const seconds = pad(date.getUTCSeconds());
8110
+ const day = pad(utc ? date.getUTCDate() : date.getDate());
8111
+ const month = pad(
8112
+ (utc ? date.getUTCMonth() : date.getMonth()) + 1
8113
+ );
8114
+ const year = utc
8115
+ ? date.getUTCFullYear()
8116
+ : date.getFullYear();
8117
+
8118
+ const hours = pad(
8119
+ utc ? date.getUTCHours() : date.getHours()
8120
+ );
8121
+ const minutes = pad(
8122
+ utc ? date.getUTCMinutes() : date.getMinutes()
8123
+ );
8124
+ const seconds = pad(
8125
+ utc ? date.getUTCSeconds() : date.getSeconds()
8126
+ );
8116
8127
 
8117
8128
  return { day, month, year, hours, minutes, seconds };
8118
8129
  };
8119
8130
 
8120
8131
 
8132
+
8121
8133
  /**
8122
8134
  * Returns the serial number of a particular date.
8123
8135
  *
@@ -8471,7 +8483,7 @@ function EPOCHTODATE(timestamp, timeUnit = 1) {
8471
8483
 
8472
8484
  const d = new Date(ms);
8473
8485
 
8474
- const { day, month, year, hours, minutes, seconds } = datePartition(d);
8486
+ const { day, month, year, hours, minutes, seconds } = datePartition(d, true);
8475
8487
 
8476
8488
  return `${day}/${month}/${year} ${hours}:${minutes}:${seconds}`
8477
8489
  }
@@ -17685,15 +17697,16 @@ const aaveParamsSchema = objectType({
17685
17697
  category: enumType(['tokens','markets']),
17686
17698
  param1: stringType().nonempty(),
17687
17699
  param2: stringType().optional(),
17700
+ columnName: stringType().optional(),
17688
17701
  });
17689
17702
 
17690
17703
  async function AAVE() {
17691
17704
  try {
17692
17705
 
17693
- const [graphType, category, param1, param2] = argsToArray(arguments);
17706
+ const [graphType, category, param1, param2, columnName] = argsToArray(arguments);
17694
17707
 
17695
17708
 
17696
- validateParams(aaveParamsSchema, { graphType, category, param1, param2 });
17709
+ validateParams(aaveParamsSchema, { graphType, category, param1, param2, columnName });
17697
17710
 
17698
17711
  const baseUrl = 'https://onchain-proxy.fileverse.io/third-party';
17699
17712
  const url =
@@ -17710,16 +17723,25 @@ async function AAVE() {
17710
17723
  }
17711
17724
 
17712
17725
  const json = await res.json();
17726
+ const filterColumnName = columnName?.split(',').map(s => s.trim());
17727
+
17713
17728
  if (Array.isArray(json)) {
17714
17729
  return json.map(item => {
17715
17730
  const flat = {};
17716
17731
  Object.entries(item).forEach(([k, v]) => {
17717
- if (v === null || typeof v !== 'object') flat[k] = v;
17732
+ if ((columnName && filterColumnName.includes(k)) && (v === null || typeof v !== 'object')) flat[k] = v;
17718
17733
  });
17719
17734
  return flat
17720
17735
  })
17721
17736
  }
17722
- return json
17737
+ if(columnName && typeof json === 'object') {
17738
+ const data = {};
17739
+ filterColumnName.forEach(k => {
17740
+ data[k] = json[k];
17741
+ });
17742
+ return data
17743
+ }
17744
+ return json;
17723
17745
  } catch (err) {
17724
17746
  return errorMessageHandler(err, 'AAVE')
17725
17747
  }
@@ -17759,6 +17781,7 @@ const baseSchema = objectType({
17759
17781
  endTime: dateOrTimestamp.optional(),
17760
17782
  page: numberType().int().nonnegative().default(1),
17761
17783
  offset: numberType().int().nonnegative().max(MAX_PAGE_LIMIT, {message: `"offset" must be less than or equal to ${MAX_PAGE_LIMIT}`}).default(10),
17784
+ columnName: stringType().optional(),
17762
17785
  });
17763
17786
 
17764
17787
  const eoaParamsSchema = preprocessType(
@@ -17988,9 +18011,9 @@ function toTimestamp(dateStr) {
17988
18011
 
17989
18012
  async function EOA() {
17990
18013
  try {
17991
- const [addresses, category, chains, startTime, endTime, page = 1, offset = 10] =
18014
+ const [addresses, category, chains, startTime, endTime, page = 1, offset = 10, columnName = null] =
17992
18015
  argsToArray(arguments);
17993
- validateParams(eoaParamsSchema, { addresses, category, chains, startTime, endTime, page, offset });
18016
+ validateParams(eoaParamsSchema, { addresses, category, chains, startTime, endTime, page, offset, columnName });
17994
18017
 
17995
18018
  const apiKey = window.localStorage.getItem(SERVICES_API_KEY.Etherscan);
17996
18019
 
@@ -18060,6 +18083,16 @@ async function EOA() {
18060
18083
  }
18061
18084
  }
18062
18085
  }
18086
+ if(columnName){
18087
+ const filterColumnName = columnName.split(',').map(s => s.trim());
18088
+ return out.map(obj =>
18089
+ Object.fromEntries(
18090
+ filterColumnName
18091
+ .filter(key => key in obj)
18092
+ .map(key => [key, obj[key]])
18093
+ )
18094
+ );
18095
+ }
18063
18096
  return out
18064
18097
  } catch (err) {
18065
18098
  return errorMessageHandler(err, 'EOA')
@@ -18072,6 +18105,7 @@ const gasSchema$1 = objectType({
18072
18105
  endDate: dateOrTimestamp.optional(),
18073
18106
  page: numberType().int().nonnegative().default(1),
18074
18107
  limit: numberType().int().nonnegative().max(MAX_PAGE_LIMIT, {message: `"limit" must be less than or equal to ${MAX_PAGE_LIMIT}`}).default(10),
18108
+ columnName: stringType().optional(),
18075
18109
  });
18076
18110
 
18077
18111
  const txnSchema$1 = objectType({
@@ -18081,6 +18115,7 @@ const txnSchema$1 = objectType({
18081
18115
  endDate: dateOrTimestamp.optional(),
18082
18116
  page: numberType().int().nonnegative().default(1),
18083
18117
  limit: numberType().int().nonnegative().max(MAX_PAGE_LIMIT, {message: `"limit" must be less than or equal to ${MAX_PAGE_LIMIT}`}).default(10),
18118
+ columnName: stringType().optional(),
18084
18119
  });
18085
18120
 
18086
18121
  const baseParamsSchema = discriminatedUnionType('type', [gasSchema$1, txnSchema$1]);
@@ -18157,11 +18192,11 @@ async function handleScanRequest({
18157
18192
 
18158
18193
  async function BASE() {
18159
18194
  try {
18160
- const [type, address, startDate, endDate, page, limit] = argsToArray(arguments);
18161
- validateParams(baseParamsSchema, { type, address, startDate, endDate, page, limit });
18195
+ const [type, address, startDate, endDate, page, limit, columnName] = argsToArray(arguments);
18196
+ validateParams(baseParamsSchema, { type, address, startDate, endDate, page, limit, columnName });
18162
18197
  const API_KEY = window.localStorage.getItem(SERVICES_API_KEY.Basescan);
18163
18198
 
18164
- return await handleScanRequest({
18199
+ const out = await handleScanRequest({
18165
18200
  type,
18166
18201
  address,
18167
18202
  startDate,
@@ -18172,7 +18207,18 @@ async function BASE() {
18172
18207
  functionName: 'BASE',
18173
18208
  chainId: CHAIN_ID_MAP.base,
18174
18209
  network: 'base'
18175
- })
18210
+ });
18211
+ if (columnName) {
18212
+ const filterColumnName = columnName.split(',').map(s => s.trim());
18213
+ return out.map(obj =>
18214
+ Object.fromEntries(
18215
+ filterColumnName
18216
+ .filter(key => key in obj)
18217
+ .map(key => [key, obj[key]])
18218
+ )
18219
+ );
18220
+ }
18221
+ return out
18176
18222
  } catch (error) {
18177
18223
  return errorMessageHandler(error, 'BASE')
18178
18224
  }
@@ -18292,6 +18338,7 @@ const derivativesSchema = objectType({
18292
18338
  category: literalType('derivatives'),
18293
18339
  param1: stringType().nonempty(),
18294
18340
  param2: anyType().optional(),
18341
+ columnName: stringType().optional(),
18295
18342
  });
18296
18343
  const coingeckoParamsSchema = discriminatedUnionType('category', [
18297
18344
  priceSchema$1,
@@ -18306,8 +18353,8 @@ const coingeckoParamsSchema = discriminatedUnionType('category', [
18306
18353
 
18307
18354
  async function COINGECKO() {
18308
18355
  try {
18309
- const [category, param1, param2] = argsToArray(arguments);
18310
- validateParams(coingeckoParamsSchema, { category, param1, param2 });
18356
+ const [category, param1, param2, columnName = null] = argsToArray(arguments);
18357
+ validateParams(coingeckoParamsSchema, { category, param1, param2, columnName });
18311
18358
 
18312
18359
  const apiKey = window.localStorage.getItem(SERVICES_API_KEY.Coingecko);
18313
18360
 
@@ -18342,7 +18389,7 @@ async function COINGECKO() {
18342
18389
  break
18343
18390
  }
18344
18391
  }
18345
- const {URL: finalUrl, HEADERS} = getUrlAndHeaders({url, serviceName: 'Coingecko', headers});
18392
+ const { URL: finalUrl, HEADERS } = getUrlAndHeaders({ url, serviceName: 'Coingecko', headers });
18346
18393
 
18347
18394
  const res = await fetch(finalUrl + "?refresh=true", { headers: HEADERS });
18348
18395
  const json = await res.json();
@@ -18368,6 +18415,16 @@ async function COINGECKO() {
18368
18415
  flat[key] = value;
18369
18416
  }
18370
18417
  }
18418
+ if (columnName) {
18419
+ const filterData = {};
18420
+ const filterColumnName = columnName.split(',').map(s => s.trim());
18421
+ filterColumnName.forEach(col => {
18422
+ if (flat[col] !== undefined) {
18423
+ filterData[col] = flat[col];
18424
+ }
18425
+ });
18426
+ return filterData;
18427
+ }
18371
18428
  return flat
18372
18429
  })
18373
18430
  } catch (err) {
@@ -18377,7 +18434,8 @@ async function COINGECKO() {
18377
18434
 
18378
18435
  const categories = ['protocols','yields','dex','fees'];
18379
18436
  const defillamaParamsSchema = objectType({
18380
- category: enumType(categories)
18437
+ category: enumType(categories),
18438
+ columnName: stringType().optional(),
18381
18439
  });
18382
18440
 
18383
18441
  const CATEGORY_URLS = {
@@ -18389,8 +18447,8 @@ const CATEGORY_URLS = {
18389
18447
 
18390
18448
  async function DEFILLAMA() {
18391
18449
  try {
18392
- const [category] = argsToArray(arguments);
18393
- validateParams(defillamaParamsSchema, { category });
18450
+ const [category, columnName = null] = argsToArray(arguments);
18451
+ validateParams(defillamaParamsSchema, { category, columnName });
18394
18452
  const url = CATEGORY_URLS[category];
18395
18453
  if (!url) throw new ValidationError(`Invalid category: ${category}`)
18396
18454
  const res = await fetch(url);
@@ -18410,10 +18468,12 @@ async function DEFILLAMA() {
18410
18468
  break
18411
18469
  }
18412
18470
 
18471
+ const filterColumnName = columnName?.split(',').map(s => s.trim());
18472
+
18413
18473
  return (Array.isArray(json) ? json : [json]).map(item => {
18414
18474
  const out = {};
18415
18475
  for (const [k, v] of Object.entries(item)) {
18416
- if (v === null || typeof v !== 'object') out[k] = v;
18476
+ if ((columnName && filterColumnName.includes(k)) && (v === null || typeof v !== 'object')) out[k] = v;
18417
18477
  }
18418
18478
  return out
18419
18479
  })
@@ -18428,6 +18488,7 @@ const gasSchema = objectType({
18428
18488
  endDate: dateOrTimestamp.optional(),
18429
18489
  page: numberType().int().nonnegative().default(1),
18430
18490
  limit: numberType().int().nonnegative().max(MAX_PAGE_LIMIT, {message: `"limit" must be less than or equal to ${MAX_PAGE_LIMIT}`}).default(10),
18491
+ columnName: stringType().optional(),
18431
18492
  });
18432
18493
 
18433
18494
  const txnSchema = objectType({
@@ -18438,6 +18499,7 @@ const txnSchema = objectType({
18438
18499
  chain: enumType(['ethereum','base','gnosis']),
18439
18500
  page: numberType().int().nonnegative().default(1),
18440
18501
  limit: numberType().int().nonnegative().max(MAX_PAGE_LIMIT, {message: `"limit" must be less than or equal to ${MAX_PAGE_LIMIT}`}).default(10),
18502
+ columnName: stringType().optional(),
18441
18503
  });
18442
18504
 
18443
18505
  const etherscanParamsSchema = discriminatedUnionType('type', [gasSchema, txnSchema]);
@@ -18451,18 +18513,18 @@ const etherscanParamsSchema = discriminatedUnionType('type', [gasSchema, txnSche
18451
18513
 
18452
18514
  async function ETHERSCAN() {
18453
18515
  try {
18454
- const [type, chain, address, startDate, endDate, page = 1, limit = 10] =
18516
+ const [type, chain, address, startDate, endDate, page = 1, limit = 10, columnName = null] =
18455
18517
  argsToArray(arguments);
18456
18518
 
18457
18519
 
18458
- validateParams(etherscanParamsSchema, { type, chain, address, startDate, endDate, page, limit });
18520
+ validateParams(etherscanParamsSchema, { type, chain, address, startDate, endDate, page, limit, columnName });
18459
18521
 
18460
18522
  const chainId = CHAIN_ID_MAP[chain];
18461
18523
  if (!chainId) throw new ValidationError(`Invalid chain: ${chain}`)
18462
18524
 
18463
18525
  const apiKey = window.localStorage.getItem(SERVICES_API_KEY.Etherscan);
18464
18526
 
18465
- return await handleScanRequest({
18527
+ const out = await handleScanRequest({
18466
18528
  type,
18467
18529
  address,
18468
18530
  startDate,
@@ -18473,7 +18535,18 @@ async function ETHERSCAN() {
18473
18535
  functionName: 'ETHERSCAN',
18474
18536
  chainId,
18475
18537
  network: chain,
18476
- })
18538
+ });
18539
+ if (columnName) {
18540
+ const filterColumnName = columnName.split(',').map(s => s.trim());
18541
+ return out.map(obj =>
18542
+ Object.fromEntries(
18543
+ filterColumnName
18544
+ .filter(key => key in obj)
18545
+ .map(key => [key, obj[key]])
18546
+ )
18547
+ );
18548
+ }
18549
+ return out
18477
18550
  } catch (err) {
18478
18551
  return errorMessageHandler(err, 'ETHERSCAN')
18479
18552
  }
@@ -18912,13 +18985,14 @@ const uniswapParamsSchema = objectType({
18912
18985
  category: enumType(['tokens','markets']),
18913
18986
  param1: stringType().nonempty(),
18914
18987
  param2: stringType().optional(),
18988
+ colummnName: stringType().optional(),
18915
18989
  });
18916
18990
 
18917
18991
  async function UNISWAP() {
18918
18992
  try {
18919
- const [graphType, category, param1, param2] = argsToArray(arguments);
18993
+ const [graphType, category, param1, param2, columnName] = argsToArray(arguments);
18920
18994
 
18921
- validateParams(uniswapParamsSchema, { graphType, category, param1, param2 });
18995
+ validateParams(uniswapParamsSchema, { graphType, category, param1, param2, columnName });
18922
18996
 
18923
18997
  const baseUrl = 'https://onchain-proxy.fileverse.io/third-party';
18924
18998
  const url =
@@ -18936,16 +19010,24 @@ async function UNISWAP() {
18936
19010
  }
18937
19011
 
18938
19012
  const json = await res.json();
19013
+ const filterColumnName = columnName?.split(',').map(s => s.trim());
18939
19014
  if (Array.isArray(json)) {
18940
19015
  // flatten nested
18941
19016
  return json.map(item => {
18942
19017
  const flat = {};
18943
19018
  Object.entries(item).forEach(([k, v]) => {
18944
- if (v === null || typeof v !== 'object') flat[k] = v;
19019
+ if ((columnName && filterColumnName.includes(k)) && (v === null || typeof v !== 'object')) flat[k] = v;
18945
19020
  });
18946
19021
  return flat
18947
19022
  })
18948
19023
  }
19024
+ if(columnName && typeof json === 'object') {
19025
+ const data = {};
19026
+ filterColumnName.forEach(k => {
19027
+ data[k] = json[k];
19028
+ });
19029
+ return data
19030
+ }
18949
19031
  return json
18950
19032
  } catch (err) {
18951
19033
  return errorMessageHandler(err, 'UNISWAP')
@@ -18955,6 +19037,7 @@ async function UNISWAP() {
18955
19037
  async function SMARTCONTRACT() {
18956
19038
  try {
18957
19039
  const args = argsToArray(arguments);
19040
+ console.log(args, arguments);
18958
19041
 
18959
19042
  return new Promise((resolve) => {
18960
19043
  resolve( {
@@ -29858,14 +29941,15 @@ class CirclesData {
29858
29941
  const circlesParamsSchema = objectType({
29859
29942
  functionName: enumType(['trust', 'profile', 'transactions', 'balances']),
29860
29943
  address: stringType().nonempty(),
29861
- entries: numberType().int().nonnegative().default(10)
29944
+ entries: numberType().int().nonnegative().default(10),
29945
+ columnName: stringType().optional(),
29862
29946
  });
29863
29947
 
29864
29948
  async function CIRCLES() {
29865
29949
  try {
29866
- const [functionName, address, entries] = argsToArray(arguments);
29950
+ const [functionName, address, entries, columnName] = argsToArray(arguments);
29867
29951
 
29868
- validateParams(circlesParamsSchema, { functionName, address, entries });
29952
+ validateParams(circlesParamsSchema, { functionName, address, entries, columnName });
29869
29953
 
29870
29954
  const resolved = await fromEnsNameToAddress$1.validateAndGetAddress(address);
29871
29955
  const dataClient = new CirclesData('https://rpc.aboutcircles.com');
@@ -29883,10 +29967,34 @@ async function CIRCLES() {
29883
29967
 
29884
29968
  switch (functionName) {
29885
29969
  case 'trust':
29886
- return await runOnePage(dataClient.getTrustRelations(resolved, limit))
29970
+ const dataTrust = await runOnePage(dataClient.getTrustRelations(resolved, limit));
29971
+ if (columnName) {
29972
+ const filterColumnName = columnName.split(',').map(s => s.trim());
29973
+ return dataTrust.map(obj =>
29974
+ Object.fromEntries(
29975
+ filterColumnName
29976
+ .filter(key => key in obj)
29977
+ .map(key => [key, obj[key]])
29978
+ )
29979
+ );
29980
+ } else {
29981
+ return dataTrust;
29982
+ }
29887
29983
 
29888
29984
  case 'transactions':
29889
- return await runOnePage(dataClient.getTransactionHistory(resolved, limit))
29985
+ const data = await runOnePage(dataClient.getTransactionHistory(resolved, limit));
29986
+ if (columnName) {
29987
+ const filterColumnName = columnName.split(',').map(s => s.trim());
29988
+ return data.map(obj =>
29989
+ Object.fromEntries(
29990
+ filterColumnName
29991
+ .filter(key => key in obj)
29992
+ .map(key => [key, obj[key]])
29993
+ )
29994
+ );
29995
+ } else {
29996
+ return data;
29997
+ }
29890
29998
 
29891
29999
  case 'profile': {
29892
30000
  const res = await dataClient.getAvatarInfo(resolved);