@fileverse-dev/formulajs 4.4.36 → 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,18 +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.getDate());
8111
- const month = pad(date.getMonth() + 1);
8112
- const year = date.getFullYear();
8113
- const hours = pad(date.getHours());
8114
- const minutes = pad(date.getMinutes());
8115
- const seconds = pad(date.getSeconds());
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
+ );
8127
+
8116
8128
  return { day, month, year, hours, minutes, seconds };
8117
8129
  };
8118
8130
 
8131
+
8132
+
8119
8133
  /**
8120
8134
  * Returns the serial number of a particular date.
8121
8135
  *
@@ -8469,7 +8483,7 @@ function EPOCHTODATE(timestamp, timeUnit = 1) {
8469
8483
 
8470
8484
  const d = new Date(ms);
8471
8485
 
8472
- const { day, month, year, hours, minutes, seconds } = datePartition(d);
8486
+ const { day, month, year, hours, minutes, seconds } = datePartition(d, true);
8473
8487
 
8474
8488
  return `${day}/${month}/${year} ${hours}:${minutes}:${seconds}`
8475
8489
  }
@@ -17683,15 +17697,16 @@ const aaveParamsSchema = objectType({
17683
17697
  category: enumType(['tokens','markets']),
17684
17698
  param1: stringType().nonempty(),
17685
17699
  param2: stringType().optional(),
17700
+ columnName: stringType().optional(),
17686
17701
  });
17687
17702
 
17688
17703
  async function AAVE() {
17689
17704
  try {
17690
17705
 
17691
- const [graphType, category, param1, param2] = argsToArray(arguments);
17706
+ const [graphType, category, param1, param2, columnName] = argsToArray(arguments);
17692
17707
 
17693
17708
 
17694
- validateParams(aaveParamsSchema, { graphType, category, param1, param2 });
17709
+ validateParams(aaveParamsSchema, { graphType, category, param1, param2, columnName });
17695
17710
 
17696
17711
  const baseUrl = 'https://onchain-proxy.fileverse.io/third-party';
17697
17712
  const url =
@@ -17708,16 +17723,25 @@ async function AAVE() {
17708
17723
  }
17709
17724
 
17710
17725
  const json = await res.json();
17726
+ const filterColumnName = columnName?.split(',').map(s => s.trim());
17727
+
17711
17728
  if (Array.isArray(json)) {
17712
17729
  return json.map(item => {
17713
17730
  const flat = {};
17714
17731
  Object.entries(item).forEach(([k, v]) => {
17715
- if (v === null || typeof v !== 'object') flat[k] = v;
17732
+ if ((columnName && filterColumnName.includes(k)) && (v === null || typeof v !== 'object')) flat[k] = v;
17716
17733
  });
17717
17734
  return flat
17718
17735
  })
17719
17736
  }
17720
- 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;
17721
17745
  } catch (err) {
17722
17746
  return errorMessageHandler(err, 'AAVE')
17723
17747
  }
@@ -17757,6 +17781,7 @@ const baseSchema = objectType({
17757
17781
  endTime: dateOrTimestamp.optional(),
17758
17782
  page: numberType().int().nonnegative().default(1),
17759
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(),
17760
17785
  });
17761
17786
 
17762
17787
  const eoaParamsSchema = preprocessType(
@@ -17986,9 +18011,9 @@ function toTimestamp(dateStr) {
17986
18011
 
17987
18012
  async function EOA() {
17988
18013
  try {
17989
- const [addresses, category, chains, startTime, endTime, page = 1, offset = 10] =
18014
+ const [addresses, category, chains, startTime, endTime, page = 1, offset = 10, columnName = null] =
17990
18015
  argsToArray(arguments);
17991
- validateParams(eoaParamsSchema, { addresses, category, chains, startTime, endTime, page, offset });
18016
+ validateParams(eoaParamsSchema, { addresses, category, chains, startTime, endTime, page, offset, columnName });
17992
18017
 
17993
18018
  const apiKey = window.localStorage.getItem(SERVICES_API_KEY.Etherscan);
17994
18019
 
@@ -18058,6 +18083,16 @@ async function EOA() {
18058
18083
  }
18059
18084
  }
18060
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
+ }
18061
18096
  return out
18062
18097
  } catch (err) {
18063
18098
  return errorMessageHandler(err, 'EOA')
@@ -18070,6 +18105,7 @@ const gasSchema$1 = objectType({
18070
18105
  endDate: dateOrTimestamp.optional(),
18071
18106
  page: numberType().int().nonnegative().default(1),
18072
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(),
18073
18109
  });
18074
18110
 
18075
18111
  const txnSchema$1 = objectType({
@@ -18079,6 +18115,7 @@ const txnSchema$1 = objectType({
18079
18115
  endDate: dateOrTimestamp.optional(),
18080
18116
  page: numberType().int().nonnegative().default(1),
18081
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(),
18082
18119
  });
18083
18120
 
18084
18121
  const baseParamsSchema = discriminatedUnionType('type', [gasSchema$1, txnSchema$1]);
@@ -18155,11 +18192,11 @@ async function handleScanRequest({
18155
18192
 
18156
18193
  async function BASE() {
18157
18194
  try {
18158
- const [type, address, startDate, endDate, page, limit] = argsToArray(arguments);
18159
- 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 });
18160
18197
  const API_KEY = window.localStorage.getItem(SERVICES_API_KEY.Basescan);
18161
18198
 
18162
- return await handleScanRequest({
18199
+ const out = await handleScanRequest({
18163
18200
  type,
18164
18201
  address,
18165
18202
  startDate,
@@ -18170,7 +18207,18 @@ async function BASE() {
18170
18207
  functionName: 'BASE',
18171
18208
  chainId: CHAIN_ID_MAP.base,
18172
18209
  network: 'base'
18173
- })
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
18174
18222
  } catch (error) {
18175
18223
  return errorMessageHandler(error, 'BASE')
18176
18224
  }
@@ -18290,6 +18338,7 @@ const derivativesSchema = objectType({
18290
18338
  category: literalType('derivatives'),
18291
18339
  param1: stringType().nonempty(),
18292
18340
  param2: anyType().optional(),
18341
+ columnName: stringType().optional(),
18293
18342
  });
18294
18343
  const coingeckoParamsSchema = discriminatedUnionType('category', [
18295
18344
  priceSchema$1,
@@ -18304,8 +18353,8 @@ const coingeckoParamsSchema = discriminatedUnionType('category', [
18304
18353
 
18305
18354
  async function COINGECKO() {
18306
18355
  try {
18307
- const [category, param1, param2] = argsToArray(arguments);
18308
- validateParams(coingeckoParamsSchema, { category, param1, param2 });
18356
+ const [category, param1, param2, columnName = null] = argsToArray(arguments);
18357
+ validateParams(coingeckoParamsSchema, { category, param1, param2, columnName });
18309
18358
 
18310
18359
  const apiKey = window.localStorage.getItem(SERVICES_API_KEY.Coingecko);
18311
18360
 
@@ -18340,7 +18389,7 @@ async function COINGECKO() {
18340
18389
  break
18341
18390
  }
18342
18391
  }
18343
- const {URL: finalUrl, HEADERS} = getUrlAndHeaders({url, serviceName: 'Coingecko', headers});
18392
+ const { URL: finalUrl, HEADERS } = getUrlAndHeaders({ url, serviceName: 'Coingecko', headers });
18344
18393
 
18345
18394
  const res = await fetch(finalUrl + "?refresh=true", { headers: HEADERS });
18346
18395
  const json = await res.json();
@@ -18366,6 +18415,16 @@ async function COINGECKO() {
18366
18415
  flat[key] = value;
18367
18416
  }
18368
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
+ }
18369
18428
  return flat
18370
18429
  })
18371
18430
  } catch (err) {
@@ -18375,7 +18434,8 @@ async function COINGECKO() {
18375
18434
 
18376
18435
  const categories = ['protocols','yields','dex','fees'];
18377
18436
  const defillamaParamsSchema = objectType({
18378
- category: enumType(categories)
18437
+ category: enumType(categories),
18438
+ columnName: stringType().optional(),
18379
18439
  });
18380
18440
 
18381
18441
  const CATEGORY_URLS = {
@@ -18387,8 +18447,8 @@ const CATEGORY_URLS = {
18387
18447
 
18388
18448
  async function DEFILLAMA() {
18389
18449
  try {
18390
- const [category] = argsToArray(arguments);
18391
- validateParams(defillamaParamsSchema, { category });
18450
+ const [category, columnName = null] = argsToArray(arguments);
18451
+ validateParams(defillamaParamsSchema, { category, columnName });
18392
18452
  const url = CATEGORY_URLS[category];
18393
18453
  if (!url) throw new ValidationError(`Invalid category: ${category}`)
18394
18454
  const res = await fetch(url);
@@ -18408,10 +18468,12 @@ async function DEFILLAMA() {
18408
18468
  break
18409
18469
  }
18410
18470
 
18471
+ const filterColumnName = columnName?.split(',').map(s => s.trim());
18472
+
18411
18473
  return (Array.isArray(json) ? json : [json]).map(item => {
18412
18474
  const out = {};
18413
18475
  for (const [k, v] of Object.entries(item)) {
18414
- if (v === null || typeof v !== 'object') out[k] = v;
18476
+ if ((columnName && filterColumnName.includes(k)) && (v === null || typeof v !== 'object')) out[k] = v;
18415
18477
  }
18416
18478
  return out
18417
18479
  })
@@ -18426,6 +18488,7 @@ const gasSchema = objectType({
18426
18488
  endDate: dateOrTimestamp.optional(),
18427
18489
  page: numberType().int().nonnegative().default(1),
18428
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(),
18429
18492
  });
18430
18493
 
18431
18494
  const txnSchema = objectType({
@@ -18436,6 +18499,7 @@ const txnSchema = objectType({
18436
18499
  chain: enumType(['ethereum','base','gnosis']),
18437
18500
  page: numberType().int().nonnegative().default(1),
18438
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(),
18439
18503
  });
18440
18504
 
18441
18505
  const etherscanParamsSchema = discriminatedUnionType('type', [gasSchema, txnSchema]);
@@ -18449,18 +18513,18 @@ const etherscanParamsSchema = discriminatedUnionType('type', [gasSchema, txnSche
18449
18513
 
18450
18514
  async function ETHERSCAN() {
18451
18515
  try {
18452
- const [type, chain, address, startDate, endDate, page = 1, limit = 10] =
18516
+ const [type, chain, address, startDate, endDate, page = 1, limit = 10, columnName = null] =
18453
18517
  argsToArray(arguments);
18454
18518
 
18455
18519
 
18456
- validateParams(etherscanParamsSchema, { type, chain, address, startDate, endDate, page, limit });
18520
+ validateParams(etherscanParamsSchema, { type, chain, address, startDate, endDate, page, limit, columnName });
18457
18521
 
18458
18522
  const chainId = CHAIN_ID_MAP[chain];
18459
18523
  if (!chainId) throw new ValidationError(`Invalid chain: ${chain}`)
18460
18524
 
18461
18525
  const apiKey = window.localStorage.getItem(SERVICES_API_KEY.Etherscan);
18462
18526
 
18463
- return await handleScanRequest({
18527
+ const out = await handleScanRequest({
18464
18528
  type,
18465
18529
  address,
18466
18530
  startDate,
@@ -18471,7 +18535,18 @@ async function ETHERSCAN() {
18471
18535
  functionName: 'ETHERSCAN',
18472
18536
  chainId,
18473
18537
  network: chain,
18474
- })
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
18475
18550
  } catch (err) {
18476
18551
  return errorMessageHandler(err, 'ETHERSCAN')
18477
18552
  }
@@ -18910,13 +18985,14 @@ const uniswapParamsSchema = objectType({
18910
18985
  category: enumType(['tokens','markets']),
18911
18986
  param1: stringType().nonempty(),
18912
18987
  param2: stringType().optional(),
18988
+ colummnName: stringType().optional(),
18913
18989
  });
18914
18990
 
18915
18991
  async function UNISWAP() {
18916
18992
  try {
18917
- const [graphType, category, param1, param2] = argsToArray(arguments);
18993
+ const [graphType, category, param1, param2, columnName] = argsToArray(arguments);
18918
18994
 
18919
- validateParams(uniswapParamsSchema, { graphType, category, param1, param2 });
18995
+ validateParams(uniswapParamsSchema, { graphType, category, param1, param2, columnName });
18920
18996
 
18921
18997
  const baseUrl = 'https://onchain-proxy.fileverse.io/third-party';
18922
18998
  const url =
@@ -18934,16 +19010,24 @@ async function UNISWAP() {
18934
19010
  }
18935
19011
 
18936
19012
  const json = await res.json();
19013
+ const filterColumnName = columnName?.split(',').map(s => s.trim());
18937
19014
  if (Array.isArray(json)) {
18938
19015
  // flatten nested
18939
19016
  return json.map(item => {
18940
19017
  const flat = {};
18941
19018
  Object.entries(item).forEach(([k, v]) => {
18942
- if (v === null || typeof v !== 'object') flat[k] = v;
19019
+ if ((columnName && filterColumnName.includes(k)) && (v === null || typeof v !== 'object')) flat[k] = v;
18943
19020
  });
18944
19021
  return flat
18945
19022
  })
18946
19023
  }
19024
+ if(columnName && typeof json === 'object') {
19025
+ const data = {};
19026
+ filterColumnName.forEach(k => {
19027
+ data[k] = json[k];
19028
+ });
19029
+ return data
19030
+ }
18947
19031
  return json
18948
19032
  } catch (err) {
18949
19033
  return errorMessageHandler(err, 'UNISWAP')
@@ -18953,6 +19037,7 @@ async function UNISWAP() {
18953
19037
  async function SMARTCONTRACT() {
18954
19038
  try {
18955
19039
  const args = argsToArray(arguments);
19040
+ console.log(args, arguments);
18956
19041
 
18957
19042
  return new Promise((resolve) => {
18958
19043
  resolve( {
@@ -29856,14 +29941,15 @@ class CirclesData {
29856
29941
  const circlesParamsSchema = objectType({
29857
29942
  functionName: enumType(['trust', 'profile', 'transactions', 'balances']),
29858
29943
  address: stringType().nonempty(),
29859
- entries: numberType().int().nonnegative().default(10)
29944
+ entries: numberType().int().nonnegative().default(10),
29945
+ columnName: stringType().optional(),
29860
29946
  });
29861
29947
 
29862
29948
  async function CIRCLES() {
29863
29949
  try {
29864
- const [functionName, address, entries] = argsToArray(arguments);
29950
+ const [functionName, address, entries, columnName] = argsToArray(arguments);
29865
29951
 
29866
- validateParams(circlesParamsSchema, { functionName, address, entries });
29952
+ validateParams(circlesParamsSchema, { functionName, address, entries, columnName });
29867
29953
 
29868
29954
  const resolved = await fromEnsNameToAddress$1.validateAndGetAddress(address);
29869
29955
  const dataClient = new CirclesData('https://rpc.aboutcircles.com');
@@ -29881,10 +29967,34 @@ async function CIRCLES() {
29881
29967
 
29882
29968
  switch (functionName) {
29883
29969
  case 'trust':
29884
- 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
+ }
29885
29983
 
29886
29984
  case 'transactions':
29887
- 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
+ }
29888
29998
 
29889
29999
  case 'profile': {
29890
30000
  const res = await dataClient.getAvatarInfo(resolved);