@sqlrooms/utils 0.0.0 → 0.0.1-alpha.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.
- package/CHANGELOG.md +2 -0
- package/package.json +2 -2
- package/.turbo/turbo-build.log +0 -4
- package/.turbo/turbo-dev.log +0 -203
- package/.turbo/turbo-lint.log +0 -16
- package/.turbo/turbo-test.log +0 -51
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/eslint.config.js +0 -4
- package/src/color.ts +0 -11
- package/src/format.ts +0 -12
- package/src/helpers.ts +0 -68
- package/src/index.ts +0 -6
- package/src/storage.ts +0 -14
- package/src/str.test.ts +0 -65
- package/src/str.ts +0 -166
- package/src/xhr.ts +0 -124
- package/tsconfig.json +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.0.1-alpha.0 (2025-01-30)
|
|
6
7
|
|
|
8
|
+
**Note:** Version bump only for package @sqlrooms/utils
|
|
7
9
|
|
|
8
10
|
**Note:** Version bump only for package @sqlrooms/utils
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqlrooms/utils",
|
|
3
|
-
"version": "0.0.0",
|
|
3
|
+
"version": "0.0.1-alpha.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "src/index.ts",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"@types/d3-time-format": "^4.0.3",
|
|
33
33
|
"@types/seedrandom": "^3.0.8"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "8e3c0b884db7755c8b892a590af49c0081336d8d"
|
|
36
36
|
}
|
package/.turbo/turbo-build.log
DELETED
package/.turbo/turbo-dev.log
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
> @sqlrooms/utils@1.0.0 dev /Users/ilya/Workspace/sqlrooms/packages/utils
|
|
4
|
-
> tsc -w
|
|
5
|
-
|
|
6
|
-
[2J[3J[H[[90m7:31:02 PM[0m] Starting compilation in watch mode...
|
|
7
|
-
|
|
8
|
-
[96msrc/color.ts[0m:[93m1[0m:[93m32[0m - [91merror[0m[90m TS7016: [0mCould not find a declaration file for module 'd3-color'. '/Users/ilya/Workspace/sqlrooms/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/index.js' implicitly has an 'any' type.
|
|
9
|
-
Try `npm i --save-dev @types/d3-color` if it exists or add a new declaration (.d.ts) file containing `declare module 'd3-color';`
|
|
10
|
-
|
|
11
|
-
[7m1[0m import {color as d3color} from 'd3-color';
|
|
12
|
-
[7m [0m [91m ~~~~~~~~~~[0m
|
|
13
|
-
|
|
14
|
-
[96msrc/format.ts[0m:[93m1[0m:[93m27[0m - [91merror[0m[90m TS7016: [0mCould not find a declaration file for module 'd3-format'. '/Users/ilya/Workspace/sqlrooms/node_modules/d3-format/src/index.js' implicitly has an 'any' type.
|
|
15
|
-
Try `npm i --save-dev @types/d3-format` if it exists or add a new declaration (.d.ts) file containing `declare module 'd3-format';`
|
|
16
|
-
|
|
17
|
-
[7m1[0m import * as d3Format from 'd3-format';
|
|
18
|
-
[7m [0m [91m ~~~~~~~~~~~[0m
|
|
19
|
-
|
|
20
|
-
[96msrc/helpers.ts[0m:[93m1[0m:[93m26[0m - [91merror[0m[90m TS7016: [0mCould not find a declaration file for module 'd3-time-format'. '/Users/ilya/Workspace/sqlrooms/node_modules/.pnpm/d3-time-format@3.0.0/node_modules/d3-time-format/dist/d3-time-format.js' implicitly has an 'any' type.
|
|
21
|
-
Try `npm i --save-dev @types/d3-time-format` if it exists or add a new declaration (.d.ts) file containing `declare module 'd3-time-format';`
|
|
22
|
-
|
|
23
|
-
[7m1[0m import {timeFormat} from 'd3-time-format';
|
|
24
|
-
[7m [0m [91m ~~~~~~~~~~~~~~~~[0m
|
|
25
|
-
|
|
26
|
-
[96msrc/helpers.ts[0m:[93m2[0m:[93m20[0m - [91merror[0m[90m TS7016: [0mCould not find a declaration file for module 'seedrandom'. '/Users/ilya/Workspace/sqlrooms/node_modules/.pnpm/seedrandom@3.0.5/node_modules/seedrandom/index.js' implicitly has an 'any' type.
|
|
27
|
-
Try `npm i --save-dev @types/seedrandom` if it exists or add a new declaration (.d.ts) file containing `declare module 'seedrandom';`
|
|
28
|
-
|
|
29
|
-
[7m2[0m import {alea} from 'seedrandom';
|
|
30
|
-
[7m [0m [91m ~~~~~~~~~~~~[0m
|
|
31
|
-
|
|
32
|
-
[96msrc/str.test.ts[0m:[93m7[0m:[93m1[0m - [91merror[0m[90m TS2582: [0mCannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
|
|
33
|
-
|
|
34
|
-
[7m7[0m test('generateUniqueName generates unique table names', () => {
|
|
35
|
-
[7m [0m [91m~~~~[0m
|
|
36
|
-
|
|
37
|
-
[96msrc/str.test.ts[0m:[93m8[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
38
|
-
|
|
39
|
-
[7m8[0m expect(generateUniqueName('foo', [])).toBe('foo');
|
|
40
|
-
[7m [0m [91m ~~~~~~[0m
|
|
41
|
-
|
|
42
|
-
[96msrc/str.test.ts[0m:[93m9[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
43
|
-
|
|
44
|
-
[7m9[0m expect(generateUniqueName('foo', ['345'])).toBe('foo');
|
|
45
|
-
[7m [0m [91m ~~~~~~[0m
|
|
46
|
-
|
|
47
|
-
[96msrc/str.test.ts[0m:[93m10[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
48
|
-
|
|
49
|
-
[7m10[0m expect(generateUniqueName('foo', ['foo_1'])).toBe('foo');
|
|
50
|
-
[7m [0m [91m ~~~~~~[0m
|
|
51
|
-
|
|
52
|
-
[96msrc/str.test.ts[0m:[93m11[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
53
|
-
|
|
54
|
-
[7m11[0m expect(generateUniqueName('foo', ['foo', 'foo_1'])).toBe('foo_2');
|
|
55
|
-
[7m [0m [91m ~~~~~~[0m
|
|
56
|
-
|
|
57
|
-
[96msrc/str.test.ts[0m:[93m12[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
58
|
-
|
|
59
|
-
[7m12[0m expect(generateUniqueName('foo_1', ['foo_1'])).toBe('foo_2');
|
|
60
|
-
[7m [0m [91m ~~~~~~[0m
|
|
61
|
-
|
|
62
|
-
[96msrc/str.test.ts[0m:[93m13[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
63
|
-
|
|
64
|
-
[7m13[0m expect(generateUniqueName('foo_2', ['foo_2'])).toBe('foo_3');
|
|
65
|
-
[7m [0m [91m ~~~~~~[0m
|
|
66
|
-
|
|
67
|
-
[96msrc/str.test.ts[0m:[93m14[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
68
|
-
|
|
69
|
-
[7m14[0m expect(generateUniqueName('foo', ['foo', 'foo_1', 'foo_2'])).toBe('foo_3');
|
|
70
|
-
[7m [0m [91m ~~~~~~[0m
|
|
71
|
-
|
|
72
|
-
[96msrc/str.test.ts[0m:[93m15[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
73
|
-
|
|
74
|
-
[7m15[0m expect(generateUniqueName('')).toBe('');
|
|
75
|
-
[7m [0m [91m ~~~~~~[0m
|
|
76
|
-
|
|
77
|
-
[96msrc/str.test.ts[0m:[93m16[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
78
|
-
|
|
79
|
-
[7m16[0m expect(generateUniqueName('', [''])).toBe('_1');
|
|
80
|
-
[7m [0m [91m ~~~~~~[0m
|
|
81
|
-
|
|
82
|
-
[96msrc/str.test.ts[0m:[93m17[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
83
|
-
|
|
84
|
-
[7m17[0m expect(generateUniqueName('_', ['_'])).toBe('__1');
|
|
85
|
-
[7m [0m [91m ~~~~~~[0m
|
|
86
|
-
|
|
87
|
-
[96msrc/str.test.ts[0m:[93m20[0m:[93m1[0m - [91merror[0m[90m TS2582: [0mCannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
|
|
88
|
-
|
|
89
|
-
[7m20[0m test('generateUniquePath generates unique paths', () => {
|
|
90
|
-
[7m [0m [91m~~~~[0m
|
|
91
|
-
|
|
92
|
-
[96msrc/str.test.ts[0m:[93m21[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
93
|
-
|
|
94
|
-
[7m21[0m expect(generateUniquePath('/foo/bar.csv', [])).toBe('/foo/bar.csv');
|
|
95
|
-
[7m [0m [91m ~~~~~~[0m
|
|
96
|
-
|
|
97
|
-
[96msrc/str.test.ts[0m:[93m22[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
98
|
-
|
|
99
|
-
[7m22[0m expect(generateUniquePath('/foo/bar.csv', ['345'])).toBe('/foo/bar.csv');
|
|
100
|
-
[7m [0m [91m ~~~~~~[0m
|
|
101
|
-
|
|
102
|
-
[96msrc/str.test.ts[0m:[93m23[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
103
|
-
|
|
104
|
-
[7m23[0m expect(generateUniquePath('/foo/bar.csv', ['/foo/bar.csv'])).toBe(
|
|
105
|
-
[7m [0m [91m ~~~~~~[0m
|
|
106
|
-
|
|
107
|
-
[96msrc/str.test.ts[0m:[93m26[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
108
|
-
|
|
109
|
-
[7m26[0m expect(generateUniquePath('/foo/bar.csv', ['/foo/bar_1.csv'])).toBe(
|
|
110
|
-
[7m [0m [91m ~~~~~~[0m
|
|
111
|
-
|
|
112
|
-
[96msrc/str.test.ts[0m:[93m29[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
113
|
-
|
|
114
|
-
[7m29[0m expect(
|
|
115
|
-
[7m [0m [91m ~~~~~~[0m
|
|
116
|
-
|
|
117
|
-
[96msrc/str.test.ts[0m:[93m32[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
118
|
-
|
|
119
|
-
[7m32[0m expect(
|
|
120
|
-
[7m [0m [91m ~~~~~~[0m
|
|
121
|
-
|
|
122
|
-
[96msrc/str.test.ts[0m:[93m39[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
123
|
-
|
|
124
|
-
[7m39[0m expect(generateUniquePath('/foo/bar_1.csv', ['/foo/bar_1.csv'])).toBe(
|
|
125
|
-
[7m [0m [91m ~~~~~~[0m
|
|
126
|
-
|
|
127
|
-
[96msrc/str.test.ts[0m:[93m42[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
128
|
-
|
|
129
|
-
[7m42[0m expect(generateUniquePath('/foo/bar_2.csv', ['/foo/bar_2.csv'])).toBe(
|
|
130
|
-
[7m [0m [91m ~~~~~~[0m
|
|
131
|
-
|
|
132
|
-
[96msrc/str.test.ts[0m:[93m45[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
133
|
-
|
|
134
|
-
[7m45[0m expect(generateUniquePath('/foo', [])).toBe('/foo');
|
|
135
|
-
[7m [0m [91m ~~~~~~[0m
|
|
136
|
-
|
|
137
|
-
[96msrc/str.test.ts[0m:[93m46[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
138
|
-
|
|
139
|
-
[7m46[0m expect(generateUniquePath('/foo/bar', [])).toBe('/foo/bar');
|
|
140
|
-
[7m [0m [91m ~~~~~~[0m
|
|
141
|
-
|
|
142
|
-
[96msrc/str.test.ts[0m:[93m47[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
143
|
-
|
|
144
|
-
[7m47[0m expect(generateUniquePath('/foo/bar', ['/foo/bar'])).toBe('/foo/bar_1');
|
|
145
|
-
[7m [0m [91m ~~~~~~[0m
|
|
146
|
-
|
|
147
|
-
[96msrc/str.test.ts[0m:[93m48[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
148
|
-
|
|
149
|
-
[7m48[0m expect(generateUniquePath('/', [])).toBe('/');
|
|
150
|
-
[7m [0m [91m ~~~~~~[0m
|
|
151
|
-
|
|
152
|
-
[96msrc/str.test.ts[0m:[93m49[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
153
|
-
|
|
154
|
-
[7m49[0m expect(generateUniquePath('', [])).toBe('');
|
|
155
|
-
[7m [0m [91m ~~~~~~[0m
|
|
156
|
-
|
|
157
|
-
[96msrc/str.test.ts[0m:[93m50[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
158
|
-
|
|
159
|
-
[7m50[0m expect(generateUniquePath('', [''])).toBe('_1');
|
|
160
|
-
[7m [0m [91m ~~~~~~[0m
|
|
161
|
-
|
|
162
|
-
[96msrc/str.test.ts[0m:[93m51[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
163
|
-
|
|
164
|
-
[7m51[0m expect(generateUniquePath('_', ['_'])).toBe('__1');
|
|
165
|
-
[7m [0m [91m ~~~~~~[0m
|
|
166
|
-
|
|
167
|
-
[96msrc/str.test.ts[0m:[93m54[0m:[93m1[0m - [91merror[0m[90m TS2582: [0mCannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
|
|
168
|
-
|
|
169
|
-
[7m54[0m test('convertToUniqueS3ObjectName works correctly', () => {
|
|
170
|
-
[7m [0m [91m~~~~[0m
|
|
171
|
-
|
|
172
|
-
[96msrc/str.test.ts[0m:[93m55[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
173
|
-
|
|
174
|
-
[7m55[0m expect(convertToUniqueS3ObjectName('/flows.csv', [])).toBe('_flows.csv');
|
|
175
|
-
[7m [0m [91m ~~~~~~[0m
|
|
176
|
-
|
|
177
|
-
[96msrc/str.test.ts[0m:[93m56[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
178
|
-
|
|
179
|
-
[7m56[0m expect(convertToUniqueS3ObjectName('&flows.csv', [])).toBe('_flows.csv');
|
|
180
|
-
[7m [0m [91m ~~~~~~[0m
|
|
181
|
-
|
|
182
|
-
[96msrc/str.test.ts[0m:[93m57[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
183
|
-
|
|
184
|
-
[7m57[0m expect(convertToUniqueS3ObjectName('@flows.csv', [])).toBe('_flows.csv');
|
|
185
|
-
[7m [0m [91m ~~~~~~[0m
|
|
186
|
-
|
|
187
|
-
[96msrc/str.test.ts[0m:[93m58[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
188
|
-
|
|
189
|
-
[7m58[0m expect(convertToUniqueS3ObjectName('/flows.csv', [])).toBe('_flows.csv');
|
|
190
|
-
[7m [0m [91m ~~~~~~[0m
|
|
191
|
-
|
|
192
|
-
[96msrc/str.test.ts[0m:[93m59[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
193
|
-
|
|
194
|
-
[7m59[0m expect(convertToUniqueS3ObjectName('flows.csv', ['flows.csv'])).toBe(
|
|
195
|
-
[7m [0m [91m ~~~~~~[0m
|
|
196
|
-
|
|
197
|
-
[96msrc/str.test.ts[0m:[93m62[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
198
|
-
|
|
199
|
-
[7m62[0m expect(
|
|
200
|
-
[7m [0m [91m ~~~~~~[0m
|
|
201
|
-
|
|
202
|
-
[[90m7:31:04 PM[0m] Found 38 errors. Watching for file changes.
|
|
203
|
-
|
package/.turbo/turbo-lint.log
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @sqlrooms/utils@0.0.0 lint /Users/ilya/Workspace/sqlrooms/packages/utils
|
|
3
|
-
> eslint .
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/Users/ilya/Workspace/sqlrooms/packages/utils/src/helpers.ts
|
|
7
|
-
63:46 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
|
8
|
-
|
|
9
|
-
/Users/ilya/Workspace/sqlrooms/packages/utils/src/str.ts
|
|
10
|
-
118:22 warning Unnecessary escape character: \. no-useless-escape
|
|
11
|
-
|
|
12
|
-
/Users/ilya/Workspace/sqlrooms/packages/utils/src/xhr.ts
|
|
13
|
-
6:25 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
|
14
|
-
|
|
15
|
-
✖ 3 problems (0 errors, 3 warnings)
|
|
16
|
-
|
package/.turbo/turbo-test.log
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
> @sqlrooms/utils@0.0.0 test /Users/ilya/Workspace/sqlrooms/packages/utils
|
|
4
|
-
> jest
|
|
5
|
-
|
|
6
|
-
[1m[2mDetermining test suites to run...[22m[22m[999D[K
|
|
7
|
-
|
|
8
|
-
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2mdist/[22m[1mstr.test.js[22m
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2mdist/[22m[1mstr.test.js[22m
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
[1m[31mJest encountered an unexpected token[39m[22m
|
|
15
|
-
|
|
16
|
-
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
|
|
17
|
-
|
|
18
|
-
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
|
|
19
|
-
|
|
20
|
-
By default "node_modules" folder is ignored by transformers.
|
|
21
|
-
|
|
22
|
-
Here's what you can do:
|
|
23
|
-
• If you are trying to use ECMAScript Modules, see [4mhttps://jestjs.io/docs/ecmascript-modules[24m for how to enable it.
|
|
24
|
-
• If you are trying to use TypeScript, see [4mhttps://jestjs.io/docs/getting-started#using-typescript[24m
|
|
25
|
-
• To have some of your "node_modules" files transformed, you can specify a custom [1m"transformIgnorePatterns"[22m in your config.
|
|
26
|
-
• If you need a custom transformation specify a [1m"transform"[22m option in your config.
|
|
27
|
-
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the [1m"moduleNameMapper"[22m config option.
|
|
28
|
-
|
|
29
|
-
You'll find more details and examples of these config options in the docs:
|
|
30
|
-
[36mhttps://jestjs.io/docs/configuration[39m
|
|
31
|
-
For information about custom transformations, see:
|
|
32
|
-
[36mhttps://jestjs.io/docs/code-transformation[39m
|
|
33
|
-
|
|
34
|
-
[1m[31mDetails:[39m[22m
|
|
35
|
-
|
|
36
|
-
/Users/ilya/Workspace/sqlrooms/packages/utils/dist/str.test.js:1
|
|
37
|
-
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { convertToUniqueS3ObjectName, generateUniqueName, generateUniquePath } from './str';
|
|
38
|
-
^^^^^^
|
|
39
|
-
|
|
40
|
-
SyntaxError: Cannot use import statement outside a module
|
|
41
|
-
|
|
42
|
-
[2mat Runtime.createScriptFromCode ([22m../../node_modules/.pnpm/jest-runtime@29.7.0/node_modules/jest-runtime/build/index.js[2m:1505:14)[22m
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2mdist/[22m[1mstr.test.js[22m
|
|
46
|
-
|
|
47
|
-
[1mTests: [22m0 total
|
|
48
|
-
[1mSnapshots: [22m0 total
|
|
49
|
-
[1mTime:[22m 0.208 s
|
|
50
|
-
[2mRan all test suites[22m[2m.[22m
|
|
51
|
-
[41m[30m ELIFECYCLE [39m[49m [31mTest failed. See above for more details.[39m
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"program":{"fileNames":["../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es2016.intl.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.decorators.d.ts","../../../node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../node_modules/.pnpm/@types+react@18.3.18/node_modules/@types/react/global.d.ts","../../../node_modules/.pnpm/csstype@3.1.3/node_modules/csstype/index.d.ts","../../../node_modules/.pnpm/@types+prop-types@15.7.14/node_modules/@types/prop-types/index.d.ts","../../../node_modules/.pnpm/@types+react@18.3.18/node_modules/@types/react/index.d.ts","../../../node_modules/.pnpm/@types+react@18.3.18/node_modules/@types/react/jsx-runtime.d.ts","../../../node_modules/.pnpm/@types+d3-color@3.1.3/node_modules/@types/d3-color/index.d.ts","../src/color.ts","../../../node_modules/.pnpm/@types+d3-format@3.0.4/node_modules/@types/d3-format/index.d.ts","../src/format.ts","../../../node_modules/.pnpm/@types+d3-time-format@4.0.3/node_modules/@types/d3-time-format/index.d.ts","../../../node_modules/.pnpm/@types+seedrandom@3.0.8/node_modules/@types/seedrandom/index.d.ts","../../../node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/locale/types.d.ts","../../../node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/locale/index.d.ts","../../../node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/index.d.ts","../../../node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/plugin/relativetime.d.ts","../src/helpers.ts","../src/xhr.ts","../src/storage.ts","../src/str.ts","../src/index.ts","../src/str.test.ts","../../../node_modules/.pnpm/@jest+expect-utils@29.7.0/node_modules/@jest/expect-utils/build/index.d.ts","../../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/index.d.ts","../../../node_modules/.pnpm/@sinclair+typebox@0.27.8/node_modules/@sinclair/typebox/typebox.d.ts","../../../node_modules/.pnpm/@jest+schemas@29.6.3/node_modules/@jest/schemas/build/index.d.ts","../../../node_modules/.pnpm/pretty-format@29.7.0/node_modules/pretty-format/build/index.d.ts","../../../node_modules/.pnpm/jest-diff@29.7.0/node_modules/jest-diff/build/index.d.ts","../../../node_modules/.pnpm/jest-matcher-utils@29.7.0/node_modules/jest-matcher-utils/build/index.d.ts","../../../node_modules/.pnpm/expect@29.7.0/node_modules/expect/build/index.d.ts","../../../node_modules/.pnpm/@types+jest@29.5.14/node_modules/@types/jest/index.d.ts","../../../node_modules/.pnpm/@types+mocha@10.0.10/node_modules/@types/mocha/index.d.ts","../../../node_modules/.pnpm/@types+react-dom@18.3.5_@types+react@18.3.18/node_modules/@types/react-dom/index.d.ts"],"fileInfos":[{"version":"44e584d4f6444f58791784f1d530875970993129442a847597db702a073ca68c","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75",{"version":"4af6b0c727b7a2896463d512fafd23634229adf69ac7c00e2ae15a09cb084fad","affectsGlobalScope":true},{"version":"9c00a480825408b6a24c63c1b71362232927247595d7c97659bc24dc68ae0757","affectsGlobalScope":true},{"version":"6920e1448680767498a0b77c6a00a8e77d14d62c3da8967b171f1ddffa3c18e4","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"ea011c76963fb15ef1cdd7ce6a6808b46322c527de2077b6cfdf23ae6f5f9ec7","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},{"version":"36a2e4c9a67439aca5f91bb304611d5ae6e20d420503e96c230cf8fcdc948d94","affectsGlobalScope":true},"8a8eb4ebffd85e589a1cc7c178e291626c359543403d58c9cd22b81fab5b1fb9","65ff5a0aefd7817a03c1ad04fee85c9cdd3ec415cc3c9efec85d8008d4d5e4ee",{"version":"b89c2ddec6bd955e8721d41e24ca667de06882338d88b183c2cdc1f41f4c5a34","affectsGlobalScope":true},"42c169fb8c2d42f4f668c624a9a11e719d5d07dacbebb63cbcf7ef365b0a75b3","6fc1a4f64372593767a9b7b774e9b3b92bf04e8785c3f9ea98973aa9f4bbe490","e33a7456f02ff96e9ee751532f9ff26541070229f240ec0e8776c4410590bee5","189266dd5f90a981910c70d7dfa05e2bca901a4f8a2680d7030c3abbfb5b1e23","fc1450f026c1e9019adfa69b8cf6cb593b2f8e39a9a0a509626c171b155e1df2","dd8936160e41420264a9d5fade0ff95cc92cab56032a84c74a46b4c38e43121e","bb5d24e66d38263b1bda38d0f9b7a72aa2a9de2f7dfd840132a2e372bffd95d8",{"version":"73a0ee6395819b063df4b148211985f2e1442945c1a057204cf4cf6281760dc3","affectsGlobalScope":true},"d05d8c67116dceafc62e691c47ac89f8f10cf7313cd1b2fb4fe801c2bf1bb1a7","3c5bb5207df7095882400323d692957e90ec17323ccff5fd5f29a1ecf3b165d0","f684f2969931de8fb9a5164f8c8f51aaea4025f4eede98406a17642a605c2842","1f4390e16ab10668dc316a909d1b1bc42479e06ee4fc129b3c6e6948ac104d92","c13a38d11c837670628513f9de2d2c25272be5574ec1fd61fbe60ad02699aa05","8faa2cfac01b22e2328f7474d30b110ee2ec16ef2cabd1ae3f838e0bb8dc80fa","f1f981926e310e6c6936769f0f8b9b7e7994fd703c75d38589b25d0f47d49a49","fc51df5c5b5ae7f838f977732152b66984adeacdc14f4e55e144a4a5230af4e9","724777dc2b82b308dc37481e4b77b09ec8fa696227547712e01aaacd3d20b7a0","cdcc132f207d097d7d3aa75615ab9a2e71d6a478162dde8b67f88ea19f3e54de","0d14fa22c41fdc7277e6f71473b20ebc07f40f00e38875142335d5b63cdfc9d2","c085e9aa62d1ae1375794c1fb927a445fa105fed891a7e24edbb1c3300f7384a","f315e1e65a1f80992f0509e84e4ae2df15ecd9ef73df975f7c98813b71e4c8da","5b9586e9b0b6322e5bfbd2c29bd3b8e21ab9d871f82346cb71020e3d84bae73e","3e70a7e67c2cb16f8cd49097360c0309fe9d1e3210ff9222e9dac1f8df9d4fb6","ab68d2a3e3e8767c3fba8f80de099a1cfc18c0de79e42cb02ae66e22dfe14a66","d96cc6598148bf1a98fb2e8dcf01c63a4b3558bdaec6ef35e087fd0562eb40ec",{"version":"f8db4fea512ab759b2223b90ecbbe7dae919c02f8ce95ec03f7fb1cf757cfbeb","affectsGlobalScope":true},{"version":"29f72ec1289ae3aeda78bf14b38086d3d803262ac13904b400422941a26a3636","affectsGlobalScope":true},"17ed71200119e86ccef2d96b73b02ce8854b76ad6bd21b5021d4269bec527b5f"],"root":[25,27,[34,39]],"options":{"allowJs":true,"downlevelIteration":true,"esModuleInterop":true,"jsx":4,"module":99,"noImplicitAny":true,"outDir":"./","skipLibCheck":true,"strict":true,"target":99},"fileIdsList":[[42],[44,47],[22],[19,20,21],[31],[30],[32],[40,46],[44],[41,45],[43],[23,24],[23,26],[23,28,29,32,33],[23,25,27,34,35,36,37],[23,35],[23,37],[23]],"referencedMap":[[43,1],[48,2],[50,3],[22,4],[23,3],[32,5],[31,6],[33,7],[47,8],[45,9],[46,10],[44,11],[25,12],[27,13],[34,14],[38,15],[36,16],[39,17],[37,18],[35,18]]},"version":"5.5.4"}
|
package/eslint.config.js
DELETED
package/src/color.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {color as d3color} from 'd3-color';
|
|
2
|
-
|
|
3
|
-
export function opacifyHex(hexCode: string, opacity: number): string {
|
|
4
|
-
const c = d3color(hexCode);
|
|
5
|
-
if (!c) {
|
|
6
|
-
console.warn('Invalid color: ', hexCode);
|
|
7
|
-
return `rgba(255, 255, 255, ${opacity})`;
|
|
8
|
-
}
|
|
9
|
-
const col = c.rgb();
|
|
10
|
-
return `rgba(${col.r}, ${col.g}, ${col.b}, ${opacity})`;
|
|
11
|
-
}
|
package/src/format.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as d3Format from 'd3-format';
|
|
2
|
-
|
|
3
|
-
export const formatCount = d3Format.format(',.0f');
|
|
4
|
-
export const formatCount4 = d3Format.format('.4~s');
|
|
5
|
-
export const formatCountShort = d3Format.format(',.0s');
|
|
6
|
-
|
|
7
|
-
export function shorten(str: string, maxLength = 10): string {
|
|
8
|
-
if (str.length <= maxLength) {
|
|
9
|
-
return str;
|
|
10
|
-
}
|
|
11
|
-
return `${str.substring(0, maxLength - 3)}…`;
|
|
12
|
-
}
|
package/src/helpers.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import {timeFormat} from 'd3-time-format';
|
|
2
|
-
import {alea} from 'seedrandom';
|
|
3
|
-
|
|
4
|
-
import dayjs, {ConfigType} from 'dayjs';
|
|
5
|
-
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
6
|
-
|
|
7
|
-
dayjs.extend(relativeTime);
|
|
8
|
-
|
|
9
|
-
export const toDateTime = (secs: number) => {
|
|
10
|
-
const t = new Date('1970-01-01T00:30:00Z'); // Unix epoch start.
|
|
11
|
-
t.setSeconds(secs);
|
|
12
|
-
return t;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export function genRandomStr(length: number, seed?: string) {
|
|
16
|
-
const rnd = seed ? alea(seed) : Math.random;
|
|
17
|
-
return Array.from(
|
|
18
|
-
(function* () {
|
|
19
|
-
for (let i = 0; i < length; i++) {
|
|
20
|
-
const v = Math.floor(rnd() * (26 * 2 + 10));
|
|
21
|
-
if (v < 26) {
|
|
22
|
-
yield String.fromCharCode(v + 65); // 'A' - 'Z'
|
|
23
|
-
} else if (v < 52) {
|
|
24
|
-
yield String.fromCharCode(v + 71); // 'a' - 'z'
|
|
25
|
-
} else {
|
|
26
|
-
yield String.fromCharCode(v + 48); // '0' - '9'
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
})(),
|
|
30
|
-
).join('');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const NUMBER_FORMAT = new Intl.NumberFormat('en-US', {
|
|
34
|
-
minimumFractionDigits: 0,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
export const formatNumber = (n: number) => NUMBER_FORMAT.format(n);
|
|
38
|
-
|
|
39
|
-
const TIME_OF_DAY_FORMAT = timeFormat('%I:%M %p');
|
|
40
|
-
const DATE_TIME_FORMAT = timeFormat('%a %Y-%m-%d %I:%M %p');
|
|
41
|
-
const DATE_FORMAT = timeFormat('%Y-%m-%d');
|
|
42
|
-
|
|
43
|
-
export const formatDateTime = (d: Date | number | bigint) => {
|
|
44
|
-
const date = d instanceof Date ? d : new Date(Number(d));
|
|
45
|
-
// return date.toISOString();
|
|
46
|
-
return DATE_TIME_FORMAT(date);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const formatDate = (d: Date | number | bigint) => {
|
|
50
|
-
const date = d instanceof Date ? d : new Date(Number(d));
|
|
51
|
-
return DATE_FORMAT(date);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const formatTimeOfDay = (d: Date | number | bigint) => {
|
|
55
|
-
const date = d instanceof Date ? d : new Date(Number(d));
|
|
56
|
-
return TIME_OF_DAY_FORMAT(date);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const formatTimeRelative = (d: ConfigType) => {
|
|
60
|
-
return dayjs().to(d);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const getErrorMessageForDisplay = (e: any) => {
|
|
64
|
-
let msg = e instanceof Error ? e.message : String(e);
|
|
65
|
-
msg = msg.replace(/Query failed: Error: /, '');
|
|
66
|
-
const firstNl = msg.indexOf('\n');
|
|
67
|
-
return firstNl >= 0 ? msg.substring(0, firstNl) : msg;
|
|
68
|
-
};
|
package/src/index.ts
DELETED
package/src/storage.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {postData} from './xhr';
|
|
2
|
-
|
|
3
|
-
// TODO: this should live in app
|
|
4
|
-
export async function getSignedFileUrl(
|
|
5
|
-
params:
|
|
6
|
-
| {fname: string; upload?: boolean}
|
|
7
|
-
| {projectId: string; fname: string; upload?: boolean; password?: string},
|
|
8
|
-
) {
|
|
9
|
-
const {url: locationsUrl} = await postData({
|
|
10
|
-
url: '/api/gen-signed-url',
|
|
11
|
-
data: params,
|
|
12
|
-
});
|
|
13
|
-
return locationsUrl;
|
|
14
|
-
}
|
package/src/str.test.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
convertToUniqueS3ObjectName,
|
|
3
|
-
generateUniqueName,
|
|
4
|
-
generateUniquePath,
|
|
5
|
-
} from './str';
|
|
6
|
-
|
|
7
|
-
test('generateUniqueName generates unique table names', () => {
|
|
8
|
-
expect(generateUniqueName('foo', [])).toBe('foo');
|
|
9
|
-
expect(generateUniqueName('foo', ['345'])).toBe('foo');
|
|
10
|
-
expect(generateUniqueName('foo', ['foo_1'])).toBe('foo');
|
|
11
|
-
expect(generateUniqueName('foo', ['foo', 'foo_1'])).toBe('foo_2');
|
|
12
|
-
expect(generateUniqueName('foo_1', ['foo_1'])).toBe('foo_2');
|
|
13
|
-
expect(generateUniqueName('foo_2', ['foo_2'])).toBe('foo_3');
|
|
14
|
-
expect(generateUniqueName('foo', ['foo', 'foo_1', 'foo_2'])).toBe('foo_3');
|
|
15
|
-
expect(generateUniqueName('')).toBe('');
|
|
16
|
-
expect(generateUniqueName('', [''])).toBe('_1');
|
|
17
|
-
expect(generateUniqueName('_', ['_'])).toBe('__1');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('generateUniquePath generates unique paths', () => {
|
|
21
|
-
expect(generateUniquePath('/foo/bar.csv', [])).toBe('/foo/bar.csv');
|
|
22
|
-
expect(generateUniquePath('/foo/bar.csv', ['345'])).toBe('/foo/bar.csv');
|
|
23
|
-
expect(generateUniquePath('/foo/bar.csv', ['/foo/bar.csv'])).toBe(
|
|
24
|
-
'/foo/bar_1.csv',
|
|
25
|
-
);
|
|
26
|
-
expect(generateUniquePath('/foo/bar.csv', ['/foo/bar_1.csv'])).toBe(
|
|
27
|
-
'/foo/bar.csv',
|
|
28
|
-
);
|
|
29
|
-
expect(
|
|
30
|
-
generateUniquePath('/foo/bar.csv', ['/foo/bar.csv', '/foo/bar_1.csv']),
|
|
31
|
-
).toBe('/foo/bar_2.csv');
|
|
32
|
-
expect(
|
|
33
|
-
generateUniquePath('/foo/bar.csv', [
|
|
34
|
-
'/foo/bar.csv',
|
|
35
|
-
'/foo/bar_1.csv',
|
|
36
|
-
'/foo/bar_2.csv',
|
|
37
|
-
]),
|
|
38
|
-
).toBe('/foo/bar_3.csv');
|
|
39
|
-
expect(generateUniquePath('/foo/bar_1.csv', ['/foo/bar_1.csv'])).toBe(
|
|
40
|
-
'/foo/bar_2.csv',
|
|
41
|
-
);
|
|
42
|
-
expect(generateUniquePath('/foo/bar_2.csv', ['/foo/bar_2.csv'])).toBe(
|
|
43
|
-
'/foo/bar_3.csv',
|
|
44
|
-
);
|
|
45
|
-
expect(generateUniquePath('/foo', [])).toBe('/foo');
|
|
46
|
-
expect(generateUniquePath('/foo/bar', [])).toBe('/foo/bar');
|
|
47
|
-
expect(generateUniquePath('/foo/bar', ['/foo/bar'])).toBe('/foo/bar_1');
|
|
48
|
-
expect(generateUniquePath('/', [])).toBe('/');
|
|
49
|
-
expect(generateUniquePath('', [])).toBe('');
|
|
50
|
-
expect(generateUniquePath('', [''])).toBe('_1');
|
|
51
|
-
expect(generateUniquePath('_', ['_'])).toBe('__1');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('convertToUniqueS3ObjectName works correctly', () => {
|
|
55
|
-
expect(convertToUniqueS3ObjectName('/flows.csv', [])).toBe('_flows.csv');
|
|
56
|
-
expect(convertToUniqueS3ObjectName('&flows.csv', [])).toBe('_flows.csv');
|
|
57
|
-
expect(convertToUniqueS3ObjectName('@flows.csv', [])).toBe('_flows.csv');
|
|
58
|
-
expect(convertToUniqueS3ObjectName('/flows.csv', [])).toBe('_flows.csv');
|
|
59
|
-
expect(convertToUniqueS3ObjectName('flows.csv', ['flows.csv'])).toBe(
|
|
60
|
-
'flows_1.csv',
|
|
61
|
-
);
|
|
62
|
-
expect(
|
|
63
|
-
convertToUniqueS3ObjectName('flows.csv', ['flows.csv', 'flows_1.csv']),
|
|
64
|
-
).toBe('flows_2.csv');
|
|
65
|
-
});
|
package/src/str.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
export function formatBytes(bytes: number): string {
|
|
2
|
-
if (bytes === 0) return '0 Bytes';
|
|
3
|
-
|
|
4
|
-
const k = 1024;
|
|
5
|
-
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
6
|
-
|
|
7
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
8
|
-
|
|
9
|
-
let sizeValue = bytes / Math.pow(k, i);
|
|
10
|
-
// Use floor to check if there's a non-zero fractional part, format accordingly
|
|
11
|
-
sizeValue =
|
|
12
|
-
sizeValue != Math.floor(sizeValue)
|
|
13
|
-
? parseFloat(sizeValue.toFixed(2))
|
|
14
|
-
: Math.floor(sizeValue);
|
|
15
|
-
|
|
16
|
-
return sizeValue + ' ' + sizes[i];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function splitFilePath(filePath: string): {
|
|
20
|
-
dir: string;
|
|
21
|
-
name: string;
|
|
22
|
-
ext: string;
|
|
23
|
-
} {
|
|
24
|
-
const pathParts = filePath.split('/');
|
|
25
|
-
const file = pathParts.pop() || '';
|
|
26
|
-
|
|
27
|
-
const dotIndex = file.lastIndexOf('.');
|
|
28
|
-
if (dotIndex === -1 || dotIndex === 0)
|
|
29
|
-
return {dir: pathParts.join('/'), name: file, ext: ''};
|
|
30
|
-
|
|
31
|
-
const name = file.substring(0, dotIndex);
|
|
32
|
-
const ext = file.substring(dotIndex + 1);
|
|
33
|
-
|
|
34
|
-
return {dir: pathParts.join('/'), name, ext};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function convertToUniqueColumnOrTableName(
|
|
38
|
-
filename: string,
|
|
39
|
-
existingTables?: string[],
|
|
40
|
-
): string {
|
|
41
|
-
// Remove file extension
|
|
42
|
-
const base = filename.replace(/\.[^/.]+$/, '');
|
|
43
|
-
|
|
44
|
-
// Replace any invalid character with underscore, and convert to lowercase
|
|
45
|
-
let tableName = base.replace(/[^a-z0-9_]/gi, '_');
|
|
46
|
-
|
|
47
|
-
// If the first character is a number, prepend an underscore
|
|
48
|
-
if (/^\d/.test(tableName)) {
|
|
49
|
-
tableName = '_' + tableName;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Truncate to the max length 63
|
|
53
|
-
if (tableName.length > 63) {
|
|
54
|
-
tableName = tableName.substring(0, 63);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
tableName = generateUniqueName(tableName, existingTables);
|
|
58
|
-
|
|
59
|
-
return tableName;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function generateUniqueName(name: string, usedNames?: string[]) {
|
|
63
|
-
const usedNamesLower = usedNames?.map((n) => n.toLowerCase());
|
|
64
|
-
|
|
65
|
-
// If tableName exists in the list
|
|
66
|
-
if (usedNamesLower?.includes(name.toLowerCase())) {
|
|
67
|
-
let baseName: string | undefined = name;
|
|
68
|
-
let i = 0;
|
|
69
|
-
|
|
70
|
-
// If tableName ends with `_${i}` pattern, update the baseTableName and i
|
|
71
|
-
const matched = name.match(/^(.+)_(\d+)$/);
|
|
72
|
-
if (matched) {
|
|
73
|
-
baseName = matched[1];
|
|
74
|
-
i = Number(matched[2]);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
do {
|
|
78
|
-
i++;
|
|
79
|
-
name = `${baseName}_${i}`;
|
|
80
|
-
} while (usedNamesLower.includes(name.toLowerCase()));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return name;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function generateUniquePath(
|
|
87
|
-
filePath: string,
|
|
88
|
-
existingPaths: string[],
|
|
89
|
-
): string {
|
|
90
|
-
let nextPath = filePath;
|
|
91
|
-
if (existingPaths?.includes(filePath)) {
|
|
92
|
-
const {dir, name, ext} = splitFilePath(filePath);
|
|
93
|
-
|
|
94
|
-
let i = 0;
|
|
95
|
-
let baseName: string | undefined = name;
|
|
96
|
-
const matched = name.match(/^(.+)_(\d+)$/);
|
|
97
|
-
if (matched) {
|
|
98
|
-
baseName = matched[1];
|
|
99
|
-
i = Number(matched[2]);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
do {
|
|
103
|
-
i++;
|
|
104
|
-
const fname = `${baseName}_${i}${ext ? `.${ext}` : ''}`;
|
|
105
|
-
nextPath = `${dir}${dir ? '/' : ''}${fname}`;
|
|
106
|
-
} while (existingPaths.includes(nextPath));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return nextPath;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function convertToUniqueS3ObjectName(
|
|
113
|
-
str: string,
|
|
114
|
-
existingObjects?: string[],
|
|
115
|
-
): string {
|
|
116
|
-
let rv = str
|
|
117
|
-
.trim() // Remove leading and trailing white spaces
|
|
118
|
-
.replace(/[^\w\s-\.]/g, '_') // Replace special characters with underscores
|
|
119
|
-
.replace(/\s+/g, '_') // Replace consecutive spaces with a single underscore
|
|
120
|
-
// .replace(/_+/g, '_') // Remove consecutive underscores
|
|
121
|
-
// .replace(/^_/, '') // Remove leading underscores
|
|
122
|
-
// .replace(/_$/, '') // Remove trailing underscores
|
|
123
|
-
.slice(0, 255); // Truncate the string if it exceeds 255 characters
|
|
124
|
-
|
|
125
|
-
if (existingObjects?.length) {
|
|
126
|
-
rv = generateUniquePath(rv, existingObjects);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return rv;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function convertToUniqueS3FolderPath(
|
|
133
|
-
str: string,
|
|
134
|
-
existingObjects?: string[],
|
|
135
|
-
): string {
|
|
136
|
-
let next = convertToUniqueS3ObjectName(str, existingObjects);
|
|
137
|
-
if (!next.endsWith('/')) next += '/'; // Add trailing slash if not present
|
|
138
|
-
return next;
|
|
139
|
-
// return (
|
|
140
|
-
// str
|
|
141
|
-
// .trim() // Remove leading and trailing white spaces
|
|
142
|
-
// .replace(/\/+/g, '/') // Replace consecutive slashes with a single slash
|
|
143
|
-
// .replace(/[^\w\s-\/]/g, '_') // Replace special characters with underscores
|
|
144
|
-
// .replace(/\s+/g, '_') // Replace consecutive spaces with a single underscore
|
|
145
|
-
// .replace(/^\//, '') + // Remove leading slash
|
|
146
|
-
// (str.endsWith('/') ? '' : '/')
|
|
147
|
-
// );
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export function camelCaseToTitle(camelCase: string): string {
|
|
151
|
-
// Split the string into words on the camelCase boundaries
|
|
152
|
-
const words = camelCase.match(/^[a-z]+|[A-Z][a-z]*/g);
|
|
153
|
-
|
|
154
|
-
// If words are found, transform them and join into a title string
|
|
155
|
-
if (words) {
|
|
156
|
-
return words
|
|
157
|
-
.map((word) => {
|
|
158
|
-
// Capitalize the first letter of each word
|
|
159
|
-
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
160
|
-
})
|
|
161
|
-
.join(' '); // Join the words with space
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// If no words were found, just capitalize the whole string
|
|
165
|
-
return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
|
|
166
|
-
}
|
package/src/xhr.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
export const postData = async ({
|
|
2
|
-
url,
|
|
3
|
-
data,
|
|
4
|
-
}: {
|
|
5
|
-
url: string;
|
|
6
|
-
data?: Record<string, any>;
|
|
7
|
-
}) => {
|
|
8
|
-
const res: Response = await fetch(url, {
|
|
9
|
-
method: 'POST',
|
|
10
|
-
headers: new Headers({'Content-Type': 'application/json'}),
|
|
11
|
-
credentials: 'same-origin',
|
|
12
|
-
body: JSON.stringify(data),
|
|
13
|
-
});
|
|
14
|
-
if (!res.ok) {
|
|
15
|
-
console.error('Error in postData', {url, data, res});
|
|
16
|
-
let message = res.statusText;
|
|
17
|
-
try {
|
|
18
|
-
message = (await res.json()).error.message;
|
|
19
|
-
console.error(message);
|
|
20
|
-
} catch {
|
|
21
|
-
// ignore
|
|
22
|
-
}
|
|
23
|
-
throw new Error(message);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return res.json();
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type ProgressInfo = {loaded: number; total: number; ratio: number};
|
|
30
|
-
|
|
31
|
-
// TODO: use range requests to download in chunks
|
|
32
|
-
// https://github.com/duckdb/duckdb-wasm/blob/d9ea9c919b6301e7c6dc8a9b3fd527e86f69a38e/packages/duckdb-wasm/src/bindings/runtime_browser.ts#L307
|
|
33
|
-
|
|
34
|
-
export async function downloadFile(
|
|
35
|
-
url: string,
|
|
36
|
-
opts: {
|
|
37
|
-
method?: string;
|
|
38
|
-
headers?: Record<string, string>;
|
|
39
|
-
onProgress?: (info: ProgressInfo) => void;
|
|
40
|
-
} = {},
|
|
41
|
-
): Promise<Uint8Array> {
|
|
42
|
-
const {method = 'GET', headers = {}, onProgress} = opts;
|
|
43
|
-
return await new Promise((resolve, reject) => {
|
|
44
|
-
const xhr = new XMLHttpRequest();
|
|
45
|
-
|
|
46
|
-
// https://www.html5rocks.com/en/tutorials/file/xhr2/#toc-bin-data
|
|
47
|
-
xhr.open(method, url, true);
|
|
48
|
-
xhr.responseType = 'arraybuffer';
|
|
49
|
-
Object.keys(headers).map((key) => {
|
|
50
|
-
if (headers[key]) {
|
|
51
|
-
xhr.setRequestHeader(key, headers[key]);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
xhr.onload = () => resolve(new Uint8Array(xhr.response));
|
|
56
|
-
|
|
57
|
-
xhr.onreadystatechange = () => {
|
|
58
|
-
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
59
|
-
if (xhr.status >= 200 && xhr.status < 300) {
|
|
60
|
-
// already handled by onload
|
|
61
|
-
} else {
|
|
62
|
-
reject({status: xhr.status, error: `File download failed`});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
xhr.onerror = () =>
|
|
67
|
-
reject({status: xhr.status, error: `File download failed`});
|
|
68
|
-
|
|
69
|
-
if (onProgress) {
|
|
70
|
-
xhr.onprogress = (event) => {
|
|
71
|
-
const {lengthComputable, loaded, total} = event;
|
|
72
|
-
if (lengthComputable) {
|
|
73
|
-
onProgress({loaded, total, ratio: total ? loaded / total : 0});
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
xhr.send(null);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// TODO: upload in chunks https://www.html5rocks.com/en/tutorials/file/xhr2/
|
|
82
|
-
|
|
83
|
-
export async function uploadFile(
|
|
84
|
-
url: string,
|
|
85
|
-
content: File | Blob | FormData,
|
|
86
|
-
opts: {
|
|
87
|
-
method?: string;
|
|
88
|
-
headers?: Record<string, string>;
|
|
89
|
-
onProgress?: (info: ProgressInfo) => void;
|
|
90
|
-
} = {},
|
|
91
|
-
): Promise<Response> {
|
|
92
|
-
const {method = 'POST', headers = {}, onProgress} = opts;
|
|
93
|
-
return await new Promise((resolve, reject) => {
|
|
94
|
-
const xhr = new XMLHttpRequest();
|
|
95
|
-
xhr.open(method, url, true);
|
|
96
|
-
Object.keys(headers).map((key) => {
|
|
97
|
-
if (headers[key]) {
|
|
98
|
-
xhr.setRequestHeader(key, headers[key]);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
xhr.onreadystatechange = () => {
|
|
102
|
-
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
103
|
-
if (xhr.status >= 200 && xhr.status < 300) {
|
|
104
|
-
resolve(xhr.response);
|
|
105
|
-
} else {
|
|
106
|
-
reject({
|
|
107
|
-
status: xhr.status,
|
|
108
|
-
error: xhr.responseText,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
xhr.onerror = () => reject({status: xhr.status, error: xhr.responseText});
|
|
114
|
-
if (onProgress) {
|
|
115
|
-
xhr.upload.onprogress = (event) => {
|
|
116
|
-
const {lengthComputable, loaded, total} = event;
|
|
117
|
-
if (lengthComputable) {
|
|
118
|
-
onProgress({loaded, total, ratio: total ? loaded / total : 0});
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
xhr.send(content);
|
|
123
|
-
});
|
|
124
|
-
}
|