Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Commit 8acf239

Browse files
committed
feat(initd): add basic filesystem-related functions
1 parent 0fece7f commit 8acf239

File tree

16 files changed

+962
-153
lines changed

16 files changed

+962
-153
lines changed

README.md

Lines changed: 1 addition & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1 @@
1-
# TSDX User Guide
2-
3-
Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it.
4-
5-
> This TSDX setup is meant for developing libraries (not apps!) that can be published to NPM. If you’re looking to build a Node app, you could use `ts-node-dev`, plain `ts-node`, or simple `tsc`.
6-
7-
> If you’re new to TypeScript, checkout [this handy cheatsheet](https://devhints.io/typescript)
8-
9-
## Commands
10-
11-
TSDX scaffolds your new library inside `/src`.
12-
13-
To run TSDX, use:
14-
15-
```bash
16-
npm start # or yarn start
17-
```
18-
19-
This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.
20-
21-
To do a one-off build, use `npm run build` or `yarn build`.
22-
23-
To run tests, use `npm test` or `yarn test`.
24-
25-
## Configuration
26-
27-
Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly.
28-
29-
### Jest
30-
31-
Jest tests are set up to run with `npm test` or `yarn test`.
32-
33-
### Bundle Analysis
34-
35-
[`size-limit`](https://github.com/ai/size-limit) is set up to calculate the real cost of your library with `npm run size` and visualize the bundle with `npm run analyze`.
36-
37-
#### Setup Files
38-
39-
This is the folder structure we set up for you:
40-
41-
```txt
42-
/src
43-
index.tsx # EDIT THIS
44-
/test
45-
blah.test.tsx # EDIT THIS
46-
.gitignore
47-
package.json
48-
README.md # EDIT THIS
49-
tsconfig.json
50-
```
51-
52-
### Rollup
53-
54-
TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.
55-
56-
### TypeScript
57-
58-
`tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs.
59-
60-
## Continuous Integration
61-
62-
### GitHub Actions
63-
64-
Two actions are added by default:
65-
66-
- `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
67-
- `size` which comments cost comparison of your library on every pull request using [`size-limit`](https://github.com/ai/size-limit)
68-
69-
## Optimizations
70-
71-
Please see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations:
72-
73-
```js
74-
// ./types/index.d.ts
75-
declare var __DEV__: boolean;
76-
77-
// inside your code...
78-
if (__DEV__) {
79-
console.log('foo');
80-
}
81-
```
82-
83-
You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions.
84-
85-
## Module Formats
86-
87-
CJS, ESModules, and UMD module formats are supported.
88-
89-
The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.
90-
91-
## Named Exports
92-
93-
Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library.
94-
95-
## Including Styles
96-
97-
There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinion on this, configure how you like.
98-
99-
For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader.
100-
101-
## Publishing to NPM
102-
103-
We recommend using [np](https://github.com/sindresorhus/np).
1+
# Valyent TypeScript SDK

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"version": "0.1.0",
3-
"license": "MIT",
3+
"license": "Apache-2.0",
44
"main": "dist/index.js",
55
"typings": "dist/index.d.ts",
66
"files": [

src/ai/ai.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { ClientCaller } from '../client';
2-
import { Predictions } from './predictions';
32
import { Sandboxes } from './sandboxes';
43

54
export class Ai {
6-
public predictions: Predictions;
75
public sandboxes: Sandboxes;
86

97
constructor(caller: ClientCaller) {
10-
this.predictions = new Predictions(caller);
118
this.sandboxes = new Sandboxes(caller);
129
}
1310
}

src/ai/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from './ai';
2-
export * from './predictions';
32
export * from './sandboxes';

src/ai/predictions.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/ai/sandboxes.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/ai/sandboxes/charts.ts

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/**
2+
* Chart types
3+
*/
4+
export enum ChartType {
5+
LINE = 'line',
6+
SCATTER = 'scatter',
7+
BAR = 'bar',
8+
PIE = 'pie',
9+
BOX_AND_WHISKER = 'box_and_whisker',
10+
SUPERCHART = 'superchart',
11+
UNKNOWN = 'unknown',
12+
}
13+
14+
15+
/**
16+
* Ax scale types
17+
*/
18+
export enum ScaleType {
19+
LINEAR = "linear",
20+
DATETIME = "datetime",
21+
CATEGORICAL = "categorical",
22+
LOG = "log",
23+
SYMLOG = "symlog",
24+
LOGIT = "logit",
25+
FUNCTION = "function",
26+
FUNCTIONLOG = "functionlog",
27+
ASINH = "asinh",
28+
}
29+
30+
/**
31+
* Represents a chart.
32+
*/
33+
export type Chart = {
34+
type: ChartType
35+
title: string
36+
elements: any[]
37+
}
38+
39+
type Chart2D = Chart & {
40+
x_label?: string
41+
y_label?: string
42+
x_unit?: string
43+
y_unit?: string
44+
}
45+
46+
export type PointData = {
47+
label: string
48+
points: [number | string, number | string][]
49+
}
50+
51+
type PointChart = Chart2D & {
52+
x_ticks: (number | string)[]
53+
x_scale: ScaleType
54+
x_tick_labels: string[]
55+
y_ticks: (number | string)[]
56+
y_scale: ScaleType
57+
y_tick_labels: string[]
58+
elements: PointData[]
59+
}
60+
61+
export type LineChart = PointChart & {
62+
type: ChartType.LINE
63+
}
64+
65+
export type ScatterChart = PointChart & {
66+
type: ChartType.SCATTER
67+
}
68+
69+
export type BarData = {
70+
label: string
71+
value: string
72+
group: string
73+
}
74+
75+
export type BarChart = Chart2D & {
76+
type: ChartType.BAR
77+
elements: BarData[]
78+
}
79+
80+
export type PieData = {
81+
label: string
82+
angle: number
83+
radius: number
84+
}
85+
86+
export type PieChart = Chart & {
87+
type: ChartType.PIE
88+
elements: PieData[]
89+
}
90+
91+
export type BoxAndWhiskerData = {
92+
label: string
93+
min: number
94+
first_quartile: number
95+
median: number
96+
third_quartile: number
97+
max: number
98+
outliers: number[]
99+
}
100+
101+
export type BoxAndWhiskerChart = Chart2D & {
102+
type: ChartType.BOX_AND_WHISKER
103+
elements: BoxAndWhiskerData[]
104+
}
105+
106+
export type SuperChart = Chart & {
107+
type: ChartType.SUPERCHART
108+
elements: Chart[]
109+
}
110+
111+
export type ChartTypes =
112+
| LineChart
113+
| ScatterChart
114+
| BarChart
115+
| PieChart
116+
| BoxAndWhiskerChart
117+
| SuperChart
118+
export function deserializeChart(data: any): Chart {
119+
switch (data.type) {
120+
case ChartType.LINE:
121+
return { ...data } as LineChart
122+
case ChartType.SCATTER:
123+
return { ...data } as ScatterChart
124+
case ChartType.BAR:
125+
return { ...data } as BarChart
126+
case ChartType.PIE:
127+
return { ...data } as PieChart
128+
case ChartType.BOX_AND_WHISKER:
129+
return { ...data } as BoxAndWhiskerChart
130+
case ChartType.SUPERCHART:
131+
const charts = data.data.map((g: any) => deserializeChart(g))
132+
delete data.data
133+
return {
134+
...data,
135+
data: charts,
136+
} as SuperChart
137+
default:
138+
return { ...data, type: ChartType.UNKNOWN } as Chart
139+
}
140+
}

src/ai/sandboxes/errors.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// This is the message for the sandbox timeout error when the response code is 502/Unavailable
2+
export function formatSandboxTimeoutError(message: string) {
3+
return new TimeoutError(
4+
`${message}: This error is likely due to sandbox timeout. You can modify the sandbox timeout by passing 'timeoutMs' when starting the sandbox or calling '.setTimeout' on the sandbox with the desired timeout.`
5+
)
6+
}
7+
8+
/**
9+
* Base class for all sandbox errors.
10+
*
11+
* Thrown when general sandbox errors occur.
12+
*/
13+
export class SandboxError extends Error {
14+
constructor(message: any) {
15+
super(message)
16+
this.name = 'SandboxError'
17+
}
18+
}
19+
20+
/**
21+
* Thrown when a timeout error occurs.
22+
*
23+
* The [unavailable] error type is caused by sandbox timeout.
24+
*
25+
* The [canceled] error type is caused by exceeding request timeout.
26+
*
27+
* The [deadline_exceeded] error type is caused by exceeding the timeout for command execution, watch, etc.
28+
*
29+
* The [unknown] error type is sometimes caused by the sandbox timeout when the request is not processed correctly.
30+
*/
31+
export class TimeoutError extends SandboxError {
32+
constructor(message: string) {
33+
super(message)
34+
this.name = 'TimeoutError'
35+
}
36+
}
37+
38+
/**
39+
* Thrown when an invalid argument is provided.
40+
*/
41+
export class InvalidArgumentError extends SandboxError {
42+
constructor(message: string) {
43+
super(message)
44+
this.name = 'InvalidArgumentError'
45+
}
46+
}
47+
48+
/**
49+
* Thrown when there is not enough disk space.
50+
*/
51+
export class NotEnoughSpaceError extends SandboxError {
52+
constructor(message: string) {
53+
super(message)
54+
this.name = 'NotEnoughSpaceError'
55+
}
56+
}
57+
58+
/**
59+
* Thrown when a resource is not found.
60+
*/
61+
export class NotFoundError extends SandboxError {
62+
constructor(message: string) {
63+
super(message)
64+
this.name = 'NotFoundError'
65+
}
66+
}
67+
68+
/**
69+
* Thrown when authentication fails.
70+
*/
71+
export class AuthenticationError extends SandboxError {
72+
constructor(message: any) {
73+
super(message)
74+
this.name = 'AuthenticationError'
75+
}
76+
}
77+
78+
/**
79+
* Thrown when the template uses old envd version. It isn't compatible with the new SDK.
80+
*/
81+
export class TemplateError extends SandboxError {
82+
constructor(message: string) {
83+
super(message)
84+
this.name = 'TemplateError'
85+
}
86+
}
87+
88+
/**
89+
* Thrown when the API rate limit is exceeded.
90+
*/
91+
export class RateLimitError extends SandboxError {
92+
constructor(message: any) {
93+
super(message)
94+
this.name = 'RateLimitError'
95+
}
96+
}

0 commit comments

Comments
 (0)