@certik/skynet 0.24.0 → 0.25.0

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/examples/api.ts +0 -0
  3. package/examples/indexer.ts +0 -0
  4. package/examples/mode-indexer.ts +0 -0
  5. package/package.json +1 -10
  6. package/src/graphql.ts +14 -4
  7. package/src/por.ts +18 -23
  8. package/.vscode/settings.json +0 -5
  9. package/dist/abi.d.ts +0 -111
  10. package/dist/abi.js +0 -571
  11. package/dist/address.d.ts +0 -2
  12. package/dist/address.js +0 -24
  13. package/dist/api.d.ts +0 -31
  14. package/dist/api.js +0 -260
  15. package/dist/app.d.ts +0 -101
  16. package/dist/app.js +0 -2077
  17. package/dist/availability.d.ts +0 -23
  18. package/dist/availability.js +0 -133
  19. package/dist/cli.d.ts +0 -5
  20. package/dist/cli.js +0 -41
  21. package/dist/const.d.ts +0 -34
  22. package/dist/const.js +0 -162
  23. package/dist/databricks.d.ts +0 -3
  24. package/dist/databricks.js +0 -208
  25. package/dist/date.d.ts +0 -5
  26. package/dist/date.js +0 -56
  27. package/dist/deploy.d.ts +0 -75
  28. package/dist/deploy.js +0 -587
  29. package/dist/dynamodb.d.ts +0 -16
  30. package/dist/dynamodb.js +0 -479
  31. package/dist/env.d.ts +0 -6
  32. package/dist/env.js +0 -26
  33. package/dist/goalert.d.ts +0 -19
  34. package/dist/goalert.js +0 -43
  35. package/dist/graphql.d.ts +0 -5
  36. package/dist/graphql.js +0 -28
  37. package/dist/indexer.d.ts +0 -69
  38. package/dist/indexer.js +0 -1099
  39. package/dist/log.d.ts +0 -13
  40. package/dist/log.js +0 -63
  41. package/dist/object-hash.d.ts +0 -1
  42. package/dist/object-hash.js +0 -61
  43. package/dist/por.d.ts +0 -37
  44. package/dist/por.js +0 -120
  45. package/dist/s3.d.ts +0 -20
  46. package/dist/s3.js +0 -122
  47. package/dist/search.d.ts +0 -5
  48. package/dist/search.js +0 -105
  49. package/dist/selector.d.ts +0 -17
  50. package/dist/selector.js +0 -44
  51. package/dist/slack.d.ts +0 -14
  52. package/dist/slack.js +0 -29
  53. package/dist/util.d.ts +0 -4
  54. package/dist/util.js +0 -27
  55. package/src/databricks.ts +0 -82
@@ -1,23 +0,0 @@
1
- import pThrottle from "p-throttle";
2
- import { type CacheStorage } from "p-memoize";
3
- import type { AsyncReturnType } from "type-fest";
4
- export declare type AnyAsyncFunction = (...arguments_: readonly any[]) => Promise<any>;
5
- export declare function wait(time: number): Promise<unknown>;
6
- export declare function exponentialRetry<T>(func: () => Promise<T>, { maxRetry, initialDuration, growFactor, test, verbose, }: {
7
- maxRetry: number;
8
- initialDuration?: number;
9
- growFactor?: number;
10
- test: (result: T) => boolean;
11
- verbose?: boolean;
12
- }): Promise<T>;
13
- export declare function withRetry<F extends AnyAsyncFunction>(func: F, options?: {
14
- maxRetry?: number;
15
- initialDuration?: number;
16
- growFactor?: number;
17
- }): F;
18
- export declare function memoize<F extends AnyAsyncFunction>(func: F, options?: {
19
- cache?: CacheStorage<string, AsyncReturnType<F>> | false;
20
- cacheKey?: (args: Parameters<F>) => string;
21
- lruMaxSize?: number;
22
- }): F;
23
- export { pThrottle as throttle };
@@ -1,133 +0,0 @@
1
- // src/object-hash.ts
2
- import xh from "@node-rs/xxhash";
3
- function getHash(obj) {
4
- const xxh3 = xh.xxh3.Xxh3.withSeed();
5
- hash(obj, xxh3);
6
- return xxh3.digest().toString(16);
7
- }
8
- function hash(obj, xxh3) {
9
- if (obj === null) {
10
- xxh3.update("null");
11
- } else if (obj === undefined) {
12
- xxh3.update("undefined");
13
- } else if (typeof obj === "string") {
14
- xxh3.update(obj);
15
- } else if (typeof obj === "number") {
16
- xxh3.update(obj.toString());
17
- } else if (typeof obj === "boolean") {
18
- xxh3.update(obj.toString());
19
- } else if (typeof obj === "bigint") {
20
- xxh3.update(obj.toString());
21
- } else if (obj instanceof Date) {
22
- xxh3.update(obj.toISOString());
23
- } else if (Array.isArray(obj)) {
24
- arrayHash(obj, xxh3);
25
- } else if (obj instanceof Set) {
26
- setHash(obj, xxh3);
27
- } else if (obj instanceof Map) {
28
- mapHash(obj, xxh3);
29
- } else if (typeof obj === "object") {
30
- objectHash(obj, xxh3);
31
- } else {
32
- throw new Error(`Unsupported type: ${obj}`);
33
- }
34
- }
35
- function arrayHash(array, xxh3) {
36
- xxh3.update("[");
37
- for (const obj of array) {
38
- hash(obj, xxh3);
39
- }
40
- xxh3.update("]");
41
- }
42
- function setHash(_set, _xxh3) {
43
- throw new Error("Set hashing not implemented");
44
- }
45
- function mapHash(map, xxh3) {
46
- const array = Array.from(map.entries()).sort(([aKey], [bKey]) => aKey.localeCompare(bKey));
47
- for (const [key, value] of array) {
48
- hash(key, xxh3);
49
- hash(value, xxh3);
50
- }
51
- }
52
- function objectHash(obj, xxh3) {
53
- const array = Object.entries(obj).sort(([aKey], [bKey]) => aKey.localeCompare(bKey));
54
- for (const [key, value] of array) {
55
- hash(key, xxh3);
56
- hash(value, xxh3);
57
- }
58
- }
59
-
60
- // src/availability.ts
61
- import pThrottle from "p-throttle";
62
- import pMemoize from "p-memoize";
63
- import QuickLRU from "quick-lru";
64
- async function wait(time) {
65
- return new Promise((resolve) => {
66
- setTimeout(resolve, time);
67
- });
68
- }
69
- async function exponentialRetry(func, {
70
- maxRetry,
71
- initialDuration,
72
- growFactor,
73
- test,
74
- verbose
75
- }) {
76
- let retries = maxRetry;
77
- let duration = initialDuration || 5000;
78
- const growFactorFinal = growFactor || 2;
79
- let result = await func();
80
- while (!test(result) && retries > 0) {
81
- if (verbose) {
82
- console.log("failed attempt result", result);
83
- console.log(`sleep for ${duration}ms after failed attempt, remaining ${retries} attempts`);
84
- }
85
- retries = retries - 1;
86
- await wait(duration);
87
- result = await func();
88
- duration = duration * growFactorFinal;
89
- }
90
- if (verbose) {
91
- console.log(`function to retry ends with status ${test(result)}, number of retries done: ${maxRetry - retries}}`);
92
- }
93
- return result;
94
- }
95
- function withRetry(func, options) {
96
- let retries = options?.maxRetry || 3;
97
- let duration = options?.initialDuration || 500;
98
- const growFactorFinal = options?.growFactor || 2;
99
- return async (...args) => {
100
- do {
101
- try {
102
- return await func(...args);
103
- } catch (error) {
104
- retries = retries - 1;
105
- if (retries <= 0) {
106
- throw error;
107
- }
108
- await wait(duration);
109
- duration = duration * growFactorFinal;
110
- }
111
- } while (retries > 0);
112
- throw new Error("unreachable");
113
- };
114
- }
115
- function memoize(func, options) {
116
- if (!options) {
117
- options = {};
118
- }
119
- if (!options.cache) {
120
- options.cache = new QuickLRU({ maxSize: options.lruMaxSize || 1e4 });
121
- }
122
- if (!options.cacheKey) {
123
- options.cacheKey = (args) => getHash(args);
124
- }
125
- return pMemoize(func, options);
126
- }
127
- export {
128
- withRetry,
129
- wait,
130
- pThrottle as throttle,
131
- memoize,
132
- exponentialRetry
133
- };
package/dist/cli.d.ts DELETED
@@ -1,5 +0,0 @@
1
- declare function getBinaryName(): string;
2
- declare function detectSkynetDirectory(): string;
3
- declare function detectWorkingDirectory(): string;
4
- declare function detectBin(): string;
5
- export { getBinaryName, detectSkynetDirectory, detectWorkingDirectory, detectBin };
package/dist/cli.js DELETED
@@ -1,41 +0,0 @@
1
- // src/cli.ts
2
- import path from "path";
3
- import fs from "fs";
4
- function getBinaryName() {
5
- const binaryNameParts = process.argv[1].split(path.sep);
6
- const binaryName = binaryNameParts[binaryNameParts.length - 1];
7
- return binaryName;
8
- }
9
- function detectSkynetDirectory() {
10
- return detectDirectory(process.argv[1], "SkynetAPIDefinitions.yml");
11
- }
12
- function detectWorkingDirectory() {
13
- const wd = detectDirectory(process.argv[1], "package.json");
14
- const skynetd = detectDirectory(process.argv[1], "SkynetAPIDefinitions.yml");
15
- return wd.slice(skynetd.length + path.sep.length).replace(path.sep, "/");
16
- }
17
- function detectDirectory(fullBinPath, sentinel = "package.json") {
18
- let parentFolder = path.dirname(fullBinPath);
19
- while (parentFolder) {
20
- const sentinelPath = path.join(parentFolder, sentinel);
21
- if (fs.existsSync(sentinelPath)) {
22
- return parentFolder;
23
- }
24
- const newParentFolder = path.dirname(parentFolder);
25
- if (newParentFolder === parentFolder) {
26
- break;
27
- }
28
- parentFolder = newParentFolder;
29
- }
30
- throw new Error("Cannot detect current working directory");
31
- }
32
- function detectBin() {
33
- const wd = detectDirectory(process.argv[1], "package.json");
34
- return process.argv[1].slice(wd.length + path.sep.length).replace(path.sep, "/");
35
- }
36
- export {
37
- getBinaryName,
38
- detectWorkingDirectory,
39
- detectSkynetDirectory,
40
- detectBin
41
- };
package/dist/const.d.ts DELETED
@@ -1,34 +0,0 @@
1
- type Protocol = {
2
- nativeTokenName: string;
3
- nativeTokenSymbol: string;
4
- nativeTokenDecimals: number;
5
- nativeTokenAddress: string;
6
- nativeTokenLogo?: string;
7
- nativeTokenCoinGeckoId?: string;
8
- nativeTokenCmcId?: number;
9
- endpoint: string;
10
- backupEndpoint?: string;
11
- archiveEndpoint?: string;
12
- tokenStandard: string;
13
- scanApi?: {
14
- endpoint: string;
15
- key?: string;
16
- };
17
- multiCallProvider?: string;
18
- scanUrl?: string;
19
- chainId: number;
20
- };
21
- type TimeIntervals = {
22
- SECOND: number;
23
- MINUTE: number;
24
- HOUR: number;
25
- DAY: number;
26
- WEEK: number;
27
- YEAR: number;
28
- };
29
- declare const PROTOCOLS: Record<string, Protocol>;
30
- declare const TIME: {
31
- BY_MS: TimeIntervals;
32
- BY_S: TimeIntervals;
33
- };
34
- export { PROTOCOLS, TIME };
package/dist/const.js DELETED
@@ -1,162 +0,0 @@
1
- // src/env.ts
2
- function ensureAndGet(envName, defaultValue) {
3
- return process.env[envName] || defaultValue;
4
- }
5
- function getEnvironment() {
6
- return ensureAndGet("SKYNET_ENVIRONMENT", "dev");
7
- }
8
- function getEnvOrThrow(envName) {
9
- if (!process.env[envName]) {
10
- throw new Error(`Must set environment variable ${envName}`);
11
- }
12
- return process.env[envName];
13
- }
14
- function isProduction() {
15
- return getEnvironment() === "prd";
16
- }
17
- function isDev() {
18
- return getEnvironment() === "dev";
19
- }
20
- // src/const.ts
21
- function getNodeRealApiKey(identifier) {
22
- return ensureAndGet(`SKYNET_NODEREAL_API_${identifier.toUpperCase()}_KEY`) ?? ensureAndGet("SKYNET_NODEREAL_API_KEY");
23
- }
24
- var PROTOCOLS = {
25
- eth: {
26
- nativeTokenName: "Ethereum",
27
- nativeTokenSymbol: "ETH",
28
- nativeTokenDecimals: 18,
29
- nativeTokenAddress: "eth:0x0000000000000000000000000000000000000000",
30
- nativeTokenLogo: `https://d1w63vqp8iwj2x.cloudfront.net/eth:0x0000000000000000000000000000000000000000.png`,
31
- nativeTokenCoinGeckoId: "ethereum",
32
- nativeTokenCmcId: 1027,
33
- endpoint: `https://eth-mainnet.nodereal.io/v1/${getNodeRealApiKey("ETH")}`,
34
- archiveEndpoint: `https://eth-mainnet.nodereal.io/v1/${getNodeRealApiKey("ETH")}`,
35
- tokenStandard: "ERC20",
36
- scanApi: {
37
- endpoint: "https://api.etherscan.io/api",
38
- key: ensureAndGet("SKYNET_ETHER_SCAN_API_KEY")
39
- },
40
- multiCallProvider: "0xCa731e0f33Afbcfa9363d6F7449d1f5447d10C80",
41
- scanUrl: "https://etherscan.io/",
42
- chainId: 1
43
- },
44
- bsc: {
45
- nativeTokenName: "Binance Coin",
46
- nativeTokenSymbol: "BNB",
47
- nativeTokenDecimals: 18,
48
- nativeTokenAddress: "bsc:0x0000000000000000000000000000000000000000",
49
- nativeTokenLogo: `https://d1w63vqp8iwj2x.cloudfront.net/bsc:0x0000000000000000000000000000000000000000.png`,
50
- nativeTokenCoinGeckoId: "binance-coin",
51
- nativeTokenCmcId: 1839,
52
- endpoint: `https://bsc-mainnet.nodereal.io/v1/${getNodeRealApiKey("BSC")}`,
53
- archiveEndpoint: `https://bsc-mainnet.nodereal.io/v1/${getNodeRealApiKey("BSC")}`,
54
- tokenStandard: "BEP20",
55
- scanApi: {
56
- endpoint: "https://api.bscscan.com/api",
57
- key: ensureAndGet("SKYNET_BSC_SCAN_API_KEY")
58
- },
59
- multiCallProvider: "0xe7144e57d832c9005D252f415d205b4b8D78228e",
60
- scanUrl: "https://bscscan.com/",
61
- chainId: 56
62
- },
63
- polygon: {
64
- nativeTokenName: "Polygon",
65
- nativeTokenSymbol: "MATIC",
66
- nativeTokenDecimals: 18,
67
- nativeTokenAddress: "polygon:0x0000000000000000000000000000000000000000",
68
- nativeTokenLogo: `https://d1w63vqp8iwj2x.cloudfront.net/polygon:0x0000000000000000000000000000000000000000.png`,
69
- nativeTokenCoinGeckoId: "matic-network",
70
- nativeTokenCmcId: 3890,
71
- endpoint: `https://polygon-mainnet.nodereal.io/v1/${getNodeRealApiKey("POLYGON")}`,
72
- archiveEndpoint: `https://polygon-mainnet.nodereal.io/v1/${getNodeRealApiKey("POLYGON")}`,
73
- backupEndpoint: `https://polygon-mainnet.nodereal.io/v1/${getNodeRealApiKey("POLYGON")}`,
74
- tokenStandard: "ERC20",
75
- scanApi: {
76
- endpoint: "https://api.polygonscan.com/api",
77
- key: ensureAndGet("SKYNET_POLYGON_SCAN_API_KEY")
78
- },
79
- multiCallProvider: "0x8eC86392e0aDB57d00fDffbA39b8870e107c0757",
80
- scanUrl: "https://polygonscan.com/",
81
- chainId: 137
82
- },
83
- heco: {
84
- nativeTokenName: "Heco",
85
- nativeTokenSymbol: "HT",
86
- nativeTokenDecimals: 18,
87
- nativeTokenAddress: "heco:0x0000000000000000000000000000000000000000",
88
- endpoint: `https://http-mainnet.hecochain.com`,
89
- tokenStandard: "HRC20",
90
- multiCallProvider: "0xe7144e57d832c9005d252f415d205b4b8d78228e",
91
- scanUrl: "https://hecoinfo.com/",
92
- chainId: 128
93
- },
94
- avax: {
95
- nativeTokenName: "Avalanche",
96
- nativeTokenSymbol: "AVAX",
97
- nativeTokenDecimals: 18,
98
- nativeTokenAddress: "avax:0x0000000000000000000000000000000000000000",
99
- nativeTokenLogo: `https://d1w63vqp8iwj2x.cloudfront.net/avax:0x0000000000000000000000000000000000000000.png`,
100
- nativeTokenCoinGeckoId: "avalanche-2",
101
- nativeTokenCmcId: 5805,
102
- endpoint: `https://api.avax.network/ext/bc/C/rpc`,
103
- tokenStandard: "ARC20",
104
- scanApi: {
105
- endpoint: "https://api.snowtrace.io/api",
106
- key: ensureAndGet("SKYNET_AVASCAN_API_KEY")
107
- },
108
- scanUrl: "https://snowtrace.io/",
109
- chainId: 43114
110
- },
111
- ftm: {
112
- nativeTokenName: "Fantom",
113
- nativeTokenSymbol: "FTM",
114
- nativeTokenDecimals: 18,
115
- nativeTokenAddress: "ftm:0x0000000000000000000000000000000000000000",
116
- nativeTokenLogo: `https://d1w63vqp8iwj2x.cloudfront.net/ftm:0x0000000000000000000000000000000000000000.png`,
117
- nativeTokenCoinGeckoId: "fantom",
118
- nativeTokenCmcId: 3513,
119
- endpoint: `https://rpcapi.fantom.network`,
120
- tokenStandard: "ERC20",
121
- scanApi: {
122
- endpoint: "https://api.ftmscan.com/api",
123
- key: ensureAndGet("SKYNET_FTMSCAN_API_KEY")
124
- },
125
- scanUrl: "https://ftmscan.com/",
126
- chainId: 250
127
- },
128
- algo: {
129
- nativeTokenName: "Algorand",
130
- nativeTokenSymbol: "ALGO",
131
- nativeTokenDecimals: 6,
132
- nativeTokenAddress: "algo:native",
133
- nativeTokenLogo: `https://d1w63vqp8iwj2x.cloudfront.net/algo:native.png`,
134
- nativeTokenCoinGeckoId: "algorand",
135
- nativeTokenCmcId: 4030,
136
- endpoint: "https://algo-node.certik-skynet.com/",
137
- tokenStandard: "ASA",
138
- chainId: 1300
139
- }
140
- };
141
- var TIME = {
142
- BY_MS: {
143
- SECOND: 1000,
144
- MINUTE: 1000 * 60,
145
- HOUR: 1000 * 60 * 60,
146
- DAY: 1000 * 60 * 60 * 24,
147
- WEEK: 1000 * 60 * 60 * 24 * 7,
148
- YEAR: 1000 * 60 * 60 * 24 * 365
149
- },
150
- BY_S: {
151
- SECOND: 1,
152
- MINUTE: 60,
153
- HOUR: 60 * 60,
154
- DAY: 60 * 60 * 24,
155
- WEEK: 60 * 60 * 24 * 7,
156
- YEAR: 60 * 60 * 24 * 365
157
- }
158
- };
159
- export {
160
- TIME,
161
- PROTOCOLS
162
- };
@@ -1,3 +0,0 @@
1
- import type { DBSQLParameterValue } from "@databricks/sql/dist/DBSQLParameter.js";
2
- declare function executeSql<T>(sql: string, bindings: Record<string, DBSQLParameterValue>): Promise<T[]>;
3
- export { executeSql };
@@ -1,208 +0,0 @@
1
- // src/env.ts
2
- function ensureAndGet(envName, defaultValue) {
3
- return process.env[envName] || defaultValue;
4
- }
5
- function getEnvironment() {
6
- return ensureAndGet("SKYNET_ENVIRONMENT", "dev");
7
- }
8
- function getEnvOrThrow(envName) {
9
- if (!process.env[envName]) {
10
- throw new Error(`Must set environment variable ${envName}`);
11
- }
12
- return process.env[envName];
13
- }
14
- function isProduction() {
15
- return getEnvironment() === "prd";
16
- }
17
- function isDev() {
18
- return getEnvironment() === "dev";
19
- }
20
- // src/object-hash.ts
21
- import xh from "@node-rs/xxhash";
22
- function getHash(obj) {
23
- const xxh3 = xh.xxh3.Xxh3.withSeed();
24
- hash(obj, xxh3);
25
- return xxh3.digest().toString(16);
26
- }
27
- function hash(obj, xxh3) {
28
- if (obj === null) {
29
- xxh3.update("null");
30
- } else if (obj === undefined) {
31
- xxh3.update("undefined");
32
- } else if (typeof obj === "string") {
33
- xxh3.update(obj);
34
- } else if (typeof obj === "number") {
35
- xxh3.update(obj.toString());
36
- } else if (typeof obj === "boolean") {
37
- xxh3.update(obj.toString());
38
- } else if (typeof obj === "bigint") {
39
- xxh3.update(obj.toString());
40
- } else if (obj instanceof Date) {
41
- xxh3.update(obj.toISOString());
42
- } else if (Array.isArray(obj)) {
43
- arrayHash(obj, xxh3);
44
- } else if (obj instanceof Set) {
45
- setHash(obj, xxh3);
46
- } else if (obj instanceof Map) {
47
- mapHash(obj, xxh3);
48
- } else if (typeof obj === "object") {
49
- objectHash(obj, xxh3);
50
- } else {
51
- throw new Error(`Unsupported type: ${obj}`);
52
- }
53
- }
54
- function arrayHash(array, xxh3) {
55
- xxh3.update("[");
56
- for (const obj of array) {
57
- hash(obj, xxh3);
58
- }
59
- xxh3.update("]");
60
- }
61
- function setHash(_set, _xxh3) {
62
- throw new Error("Set hashing not implemented");
63
- }
64
- function mapHash(map, xxh3) {
65
- const array = Array.from(map.entries()).sort(([aKey], [bKey]) => aKey.localeCompare(bKey));
66
- for (const [key, value] of array) {
67
- hash(key, xxh3);
68
- hash(value, xxh3);
69
- }
70
- }
71
- function objectHash(obj, xxh3) {
72
- const array = Object.entries(obj).sort(([aKey], [bKey]) => aKey.localeCompare(bKey));
73
- for (const [key, value] of array) {
74
- hash(key, xxh3);
75
- hash(value, xxh3);
76
- }
77
- }
78
-
79
- // src/availability.ts
80
- import pThrottle from "p-throttle";
81
- import pMemoize from "p-memoize";
82
- import QuickLRU from "quick-lru";
83
- async function wait(time) {
84
- return new Promise((resolve) => {
85
- setTimeout(resolve, time);
86
- });
87
- }
88
- async function exponentialRetry(func, {
89
- maxRetry,
90
- initialDuration,
91
- growFactor,
92
- test,
93
- verbose
94
- }) {
95
- let retries = maxRetry;
96
- let duration = initialDuration || 5000;
97
- const growFactorFinal = growFactor || 2;
98
- let result = await func();
99
- while (!test(result) && retries > 0) {
100
- if (verbose) {
101
- console.log("failed attempt result", result);
102
- console.log(`sleep for ${duration}ms after failed attempt, remaining ${retries} attempts`);
103
- }
104
- retries = retries - 1;
105
- await wait(duration);
106
- result = await func();
107
- duration = duration * growFactorFinal;
108
- }
109
- if (verbose) {
110
- console.log(`function to retry ends with status ${test(result)}, number of retries done: ${maxRetry - retries}}`);
111
- }
112
- return result;
113
- }
114
- function withRetry(func, options) {
115
- let retries = options?.maxRetry || 3;
116
- let duration = options?.initialDuration || 500;
117
- const growFactorFinal = options?.growFactor || 2;
118
- return async (...args) => {
119
- do {
120
- try {
121
- return await func(...args);
122
- } catch (error) {
123
- retries = retries - 1;
124
- if (retries <= 0) {
125
- throw error;
126
- }
127
- await wait(duration);
128
- duration = duration * growFactorFinal;
129
- }
130
- } while (retries > 0);
131
- throw new Error("unreachable");
132
- };
133
- }
134
- function memoize(func, options) {
135
- if (!options) {
136
- options = {};
137
- }
138
- if (!options.cache) {
139
- options.cache = new QuickLRU({ maxSize: options.lruMaxSize || 1e4 });
140
- }
141
- if (!options.cacheKey) {
142
- options.cacheKey = (args) => getHash(args);
143
- }
144
- return pMemoize(func, options);
145
- }
146
- // src/databricks.ts
147
- import { DBSQLClient, DBSQLParameter } from "@databricks/sql";
148
- var client = null;
149
- var session = null;
150
- async function initSession() {
151
- if (!client) {
152
- client = new DBSQLClient;
153
- await client.connect({
154
- authType: "access-token",
155
- token: getEnvOrThrow("SKYNET_DATABRICKS_TOKEN"),
156
- host: getEnvOrThrow("SKYNET_DATABRICKS_SERVER_HOSTNAME"),
157
- path: getEnvOrThrow("SKYNET_DATABRICKS_HTTP_PATH")
158
- });
159
- }
160
- if (!session) {
161
- session = await client.openSession();
162
- }
163
- }
164
- async function executeSql(sql, bindings) {
165
- const results = await exponentialRetry(async () => {
166
- let queryOperation;
167
- try {
168
- await initSession();
169
- if (!session)
170
- throw new Error("Session is not initialized");
171
- queryOperation = await session.executeStatement(sql, {
172
- runAsync: true,
173
- namedParameters: objToParameter(bindings)
174
- });
175
- const result = await queryOperation.fetchAll();
176
- return result;
177
- } catch (err) {
178
- if (!checkIsDatabricksError(err)) {
179
- throw err;
180
- }
181
- return err;
182
- } finally {
183
- await queryOperation?.close();
184
- }
185
- }, {
186
- maxRetry: 3,
187
- initialDuration: 500,
188
- test: (result) => {
189
- return !checkIsDatabricksError(result);
190
- }
191
- });
192
- if (checkIsDatabricksError(results)) {
193
- throw results;
194
- }
195
- return results;
196
- }
197
- function checkIsDatabricksError(err) {
198
- return err?.errno === "ECONNRESET" || err?.message?.includes("java.lang.NullPointerException");
199
- }
200
- function objToParameter(obj) {
201
- return Object.entries(obj).reduce((acc, [key, value]) => {
202
- acc[key] = new DBSQLParameter({ value });
203
- return acc;
204
- }, {});
205
- }
206
- export {
207
- executeSql
208
- };
package/dist/date.d.ts DELETED
@@ -1,5 +0,0 @@
1
- declare function getDateOnly(date: number | string | Date): string;
2
- declare function findDateAfter(date: number | string | Date, n: number): string;
3
- declare function daysInRange(from: number | string | Date, to: number | string | Date): string[];
4
- declare function dateRange(from: number | string | Date, to: number | string | Date, step: number): [string, string][];
5
- export { getDateOnly, findDateAfter, daysInRange, dateRange };
package/dist/date.js DELETED
@@ -1,56 +0,0 @@
1
- // src/util.ts
2
- function range(startAt, endAt, step) {
3
- const arr = [];
4
- for (let i = startAt;i <= endAt; i += step) {
5
- arr.push([i, Math.min(endAt, i + step - 1)]);
6
- }
7
- return arr;
8
- }
9
- function arrayGroup(array, groupSize) {
10
- const groups = [];
11
- for (let i = 0;i < array.length; i += groupSize) {
12
- groups.push(array.slice(i, i + groupSize));
13
- }
14
- return groups;
15
- }
16
- function fillRange(start, end) {
17
- const result = [];
18
- for (let i = start;i <= end; i++) {
19
- result.push(i);
20
- }
21
- return result;
22
- }
23
- // src/date.ts
24
- var MS_IN_A_DAY = 3600 * 24 * 1000;
25
- function getDateOnly(date) {
26
- return new Date(date).toISOString().split("T")[0];
27
- }
28
- function findDateAfter(date, n) {
29
- const d = new Date(date);
30
- const after = new Date(d.getTime() + MS_IN_A_DAY * n);
31
- return getDateOnly(after);
32
- }
33
- function daysInRange(from, to) {
34
- const fromTime = new Date(from).getTime();
35
- const toTime = new Date(to).getTime();
36
- if (fromTime > toTime) {
37
- throw new Error(`range to date couldn't be earlier than range from date`);
38
- }
39
- const daysBetween = Math.floor((toTime - fromTime) / MS_IN_A_DAY);
40
- const dates = [getDateOnly(new Date(fromTime))];
41
- for (let i = 1;i <= daysBetween; i += 1) {
42
- dates.push(getDateOnly(new Date(fromTime + i * MS_IN_A_DAY)));
43
- }
44
- return dates;
45
- }
46
- function dateRange(from, to, step) {
47
- const days = daysInRange(from, to);
48
- const windows = arrayGroup(days, step);
49
- return windows.map((w) => [w[0], w[w.length - 1]]);
50
- }
51
- export {
52
- getDateOnly,
53
- findDateAfter,
54
- daysInRange,
55
- dateRange
56
- };