@tscircuit/cli 0.0.117 → 0.0.119
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/.github/workflows/release.yml +1 -1
- package/.github/workflows/server-tests.yml +31 -0
- package/.github/workflows/test.yml +4 -1
- package/README.md +1 -2
- package/bun.lockb +0 -0
- package/dev-server-api/bun.lockb +0 -0
- package/dev-server-api/package.json +2 -4
- package/dev-server-api/routes/api/db/download.ts +25 -0
- package/dev-server-api/routes/api/dev_package_examples/create.ts +15 -25
- package/dev-server-api/routes/api/dev_package_examples/get.ts +12 -21
- package/dev-server-api/routes/api/dev_package_examples/list.ts +17 -22
- package/dev-server-api/routes/api/dev_package_examples/update.ts +39 -37
- package/dev-server-api/routes/api/dev_server/reset.ts +6 -8
- package/dev-server-api/routes/api/export_files/create.ts +10 -13
- package/dev-server-api/routes/api/export_files/download.ts +10 -7
- package/dev-server-api/routes/api/export_requests/create.ts +11 -15
- package/dev-server-api/routes/api/export_requests/get.ts +24 -15
- package/dev-server-api/routes/api/export_requests/list.ts +9 -10
- package/dev-server-api/routes/api/export_requests/update.ts +18 -18
- package/dev-server-api/routes/api/package_info/create.ts +9 -11
- package/dev-server-api/routes/api/package_info/get.ts +5 -8
- package/dev-server-api/routes/index.ts +16 -0
- package/dev-server-api/server.ts +1 -1
- package/dev-server-api/src/db/get-db.ts +11 -102
- package/dev-server-api/src/db/schema.ts +65 -0
- package/dev-server-api/src/db/zod-level-db.ts +146 -0
- package/dev-server-api/src/middlewares/with-db.ts +7 -3
- package/dev-server-api/static-routes.ts +3 -1
- package/dev-server-api/tests/fixtures/get-test-server.ts +30 -0
- package/dev-server-api/tests/fixtures/start-server.ts +20 -0
- package/dev-server-api/tests/routes/dev_package_examples/create.test.ts +19 -0
- package/dev-server-api/tests/routes/dev_package_examples/get.test.ts +25 -0
- package/dev-server-api/tests/routes/dev_package_examples/list.test.ts +32 -0
- package/dev-server-api/tests/routes/dev_package_examples/update.test.ts +28 -0
- package/dev-server-api/tests/routes/export_files/create.test.ts +18 -0
- package/dev-server-api/tests/routes/export_files/download.test.ts +29 -0
- package/dev-server-api/tests/routes/export_requests/create.test.ts +24 -0
- package/dev-server-api/tests/routes/export_requests/get.test.ts +41 -0
- package/dev-server-api/tests/routes/export_requests/list.test.ts +35 -0
- package/dev-server-api/tests/routes/export_requests/update.test.ts +50 -0
- package/dev-server-api/tests/routes/health.test.ts +10 -0
- package/dist/cli.js +487 -368
- package/lib/cmd-fns/dev/index.ts +14 -11
- package/package.json +6 -8
- package/tests/open.test.ts +1 -2
- package/tests/soupify.test.ts +1 -1
- package/dev-server-api/src/lib/zod/export_file.ts +0 -8
- package/dev-server-api/src/lib/zod/export_package_info.ts +0 -5
- package/dev-server-api/src/lib/zod/export_request.ts +0 -21
- /package/{tests/assets/example-project → example-project}/README.md +0 -0
- /package/{tests/assets/example-project → example-project}/examples/basic-bug.tsx +0 -0
- /package/{tests/assets/example-project → example-project}/examples/basic-capacitor.tsx +0 -0
- /package/{tests/assets/example-project → example-project}/examples/basic-resistor.tsx +0 -0
- /package/{tests/assets/example-project → example-project}/index.ts +0 -0
- /package/{tests/assets/example-project → example-project}/package-lock.json +0 -0
- /package/{tests/assets/example-project → example-project}/package.json +0 -0
- /package/{tests/assets/example-project → example-project}/src/MyCircuit.tsx +0 -0
- /package/{tests/assets/example-project → example-project}/src/manual-edits.ts +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Dev Server API Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout code
|
|
17
|
+
uses: actions/checkout@v2
|
|
18
|
+
|
|
19
|
+
- name: Setup bun
|
|
20
|
+
uses: oven-sh/setup-bun@v1
|
|
21
|
+
with:
|
|
22
|
+
bun-version: latest
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: bun run bootstrap
|
|
26
|
+
|
|
27
|
+
- name: Install dependencies
|
|
28
|
+
run: bun run build
|
|
29
|
+
|
|
30
|
+
- name: Run tests
|
|
31
|
+
run: cd dev-server-api && bun test
|
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ Run `bun bootstrap` to install dependencies and `bun cli.ts` to run test the cli
|
|
|
46
46
|
To run tests, run `bun test`
|
|
47
47
|
|
|
48
48
|
If you want to test developing, run `bun dev` and visit http://localhost:5173. The project being
|
|
49
|
-
loaded is inside `
|
|
49
|
+
loaded is inside `example-project`
|
|
50
50
|
|
|
51
51
|

|
|
52
52
|
|
|
@@ -54,7 +54,6 @@ loaded is inside `tests/assets/example-project`
|
|
|
54
54
|
|
|
55
55
|

|
|
56
56
|
|
|
57
|
-
|
|
58
57
|
## Features Coming Soon
|
|
59
58
|
|
|
60
59
|
- [`tsci format`](https://github.com/tscircuit/cli/issues/1)
|
package/bun.lockb
CHANGED
|
Binary file
|
package/dev-server-api/bun.lockb
CHANGED
|
Binary file
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
"build": "winterspec bundle-routes -i ./routes -o static-routes.ts"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"@types/better-sqlite3": "^7.6.9",
|
|
11
10
|
"@types/bun": "latest",
|
|
12
11
|
"@types/sql.js": "^1.4.9",
|
|
13
12
|
"make-vfs": "^1.0.10"
|
|
@@ -16,9 +15,8 @@
|
|
|
16
15
|
"typescript": "^5.0.0"
|
|
17
16
|
},
|
|
18
17
|
"dependencies": {
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"kysely-bun-sqlite": "^0.3.2",
|
|
18
|
+
"level": "^8.0.1",
|
|
19
|
+
"redaxios": "^0.5.1",
|
|
22
20
|
"winterspec": "0.0.81",
|
|
23
21
|
"zod": "^3.22.4"
|
|
24
22
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { withWinterSpec } from "src/with-winter-spec"
|
|
2
|
+
import { z } from "zod"
|
|
3
|
+
|
|
4
|
+
export default withWinterSpec({
|
|
5
|
+
methods: ["GET"],
|
|
6
|
+
jsonResponse: z.object({
|
|
7
|
+
dev_server_database_dump: z.any(),
|
|
8
|
+
}),
|
|
9
|
+
auth: "none",
|
|
10
|
+
})(async (req, ctx) => {
|
|
11
|
+
return new Response(
|
|
12
|
+
JSON.stringify(
|
|
13
|
+
{
|
|
14
|
+
dev_server_database_dump: await ctx.db.dump(),
|
|
15
|
+
},
|
|
16
|
+
null,
|
|
17
|
+
" "
|
|
18
|
+
),
|
|
19
|
+
{
|
|
20
|
+
headers: {
|
|
21
|
+
"content-type": "application/json",
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
)
|
|
25
|
+
})
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { withWinterSpec } from "src/with-winter-spec"
|
|
2
|
-
import { NotFoundError } from "edgespec/middleware"
|
|
3
2
|
import { z } from "zod"
|
|
4
3
|
|
|
5
4
|
export default withWinterSpec({
|
|
@@ -17,35 +16,26 @@ export default withWinterSpec({
|
|
|
17
16
|
file_path: z.string(),
|
|
18
17
|
tscircuit_soup: z.any(),
|
|
19
18
|
error: z.string().nullable().optional(),
|
|
20
|
-
last_updated_at: z.string().datetime(),
|
|
19
|
+
last_updated_at: z.string().datetime().nullable(), // TODO remove nullable
|
|
21
20
|
}),
|
|
22
21
|
}),
|
|
23
22
|
auth: "none",
|
|
24
23
|
})(async (req, ctx) => {
|
|
25
24
|
const tscircuit_soup = req.jsonBody.tscircuit_soup
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.
|
|
39
|
-
|
|
40
|
-
export_name: req.jsonBody.export_name,
|
|
41
|
-
error: req.jsonBody.error,
|
|
42
|
-
tscircuit_soup,
|
|
43
|
-
is_loading: req.jsonBody.is_loading ? 1 : 0,
|
|
44
|
-
last_updated_at: new Date().toISOString(),
|
|
45
|
-
})
|
|
46
|
-
)
|
|
47
|
-
.returningAll()
|
|
48
|
-
.executeTakeFirstOrThrow()
|
|
25
|
+
|
|
26
|
+
const existingDevPackageExample = await ctx.db.find("dev_package_example", {
|
|
27
|
+
file_path: req.jsonBody.file_path,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const dev_package_example = await ctx.db.put("dev_package_example", {
|
|
31
|
+
dev_package_example_id: existingDevPackageExample?.dev_package_example_id,
|
|
32
|
+
file_path: req.jsonBody.file_path,
|
|
33
|
+
export_name: req.jsonBody.export_name,
|
|
34
|
+
error: req.jsonBody.error,
|
|
35
|
+
tscircuit_soup,
|
|
36
|
+
is_loading: Boolean(req.jsonBody.is_loading),
|
|
37
|
+
last_updated_at: new Date().toISOString(),
|
|
38
|
+
})
|
|
49
39
|
|
|
50
40
|
return ctx.json({
|
|
51
41
|
dev_package_example,
|
|
@@ -12,7 +12,7 @@ export default withWinterSpec({
|
|
|
12
12
|
dev_package_example_id: z.coerce.number(),
|
|
13
13
|
file_path: z.string(),
|
|
14
14
|
tscircuit_soup: z.any(),
|
|
15
|
-
completed_edit_events: z.array(z.any()).
|
|
15
|
+
completed_edit_events: z.array(z.any()).default([]),
|
|
16
16
|
is_loading: z.boolean(),
|
|
17
17
|
error: z.string().nullable().optional().default(null),
|
|
18
18
|
soup_last_updated_at: z.string().datetime().nullable().default(null),
|
|
@@ -26,30 +26,21 @@ export default withWinterSpec({
|
|
|
26
26
|
.datetime()
|
|
27
27
|
.nullable()
|
|
28
28
|
.default(null),
|
|
29
|
-
last_updated_at: z.string().datetime(),
|
|
29
|
+
last_updated_at: z.string().datetime().nullable(),
|
|
30
30
|
}),
|
|
31
31
|
}),
|
|
32
32
|
auth: "none",
|
|
33
33
|
})(async (req, ctx) => {
|
|
34
|
+
const dev_package_example = await ctx.db.get(
|
|
35
|
+
"dev_package_example",
|
|
36
|
+
req.commonParams.dev_package_example_id
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
if (!dev_package_example) {
|
|
40
|
+
throw new NotFoundError("Package not found")
|
|
41
|
+
}
|
|
42
|
+
|
|
34
43
|
return ctx.json({
|
|
35
|
-
dev_package_example
|
|
36
|
-
.selectFrom("dev_package_example")
|
|
37
|
-
.selectAll()
|
|
38
|
-
.where(
|
|
39
|
-
"dev_package_example_id",
|
|
40
|
-
"=",
|
|
41
|
-
req.commonParams.dev_package_example_id
|
|
42
|
-
)
|
|
43
|
-
.executeTakeFirstOrThrow((e) => {
|
|
44
|
-
throw new NotFoundError("Package not found")
|
|
45
|
-
})
|
|
46
|
-
.then((r) => ({
|
|
47
|
-
...r,
|
|
48
|
-
is_loading: r.is_loading === 1,
|
|
49
|
-
tscircuit_soup: JSON.parse(r.tscircuit_soup),
|
|
50
|
-
completed_edit_events: r.completed_edit_events
|
|
51
|
-
? JSON.parse(r.completed_edit_events)
|
|
52
|
-
: null,
|
|
53
|
-
})),
|
|
44
|
+
dev_package_example,
|
|
54
45
|
})
|
|
55
46
|
})
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { sql } from "kysely"
|
|
2
1
|
import { withWinterSpec } from "src/with-winter-spec"
|
|
3
2
|
import { z } from "zod"
|
|
4
3
|
|
|
@@ -9,32 +8,28 @@ export default withWinterSpec({
|
|
|
9
8
|
z.object({
|
|
10
9
|
dev_package_example_id: z.coerce.number(),
|
|
11
10
|
file_path: z.string(),
|
|
12
|
-
export_name: z.string(),
|
|
13
|
-
is_loading: z.
|
|
14
|
-
edit_events_last_updated_at: z
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.nullable()
|
|
18
|
-
.default(null),
|
|
19
|
-
soup_last_updated_at: z.string().datetime().nullable().default(null),
|
|
20
|
-
last_updated_at: z.string().datetime(),
|
|
11
|
+
export_name: z.string().nullable(),
|
|
12
|
+
is_loading: z.boolean(),
|
|
13
|
+
edit_events_last_updated_at: z.string().datetime().nullable(),
|
|
14
|
+
soup_last_updated_at: z.string().datetime().nullable(),
|
|
15
|
+
last_updated_at: z.string().datetime().nullable(),
|
|
21
16
|
})
|
|
22
17
|
),
|
|
23
18
|
}),
|
|
24
19
|
auth: "none",
|
|
25
20
|
})(async (req, ctx) => {
|
|
26
|
-
const dev_package_examples = await ctx.db
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
21
|
+
const dev_package_examples = (await ctx.db.list("dev_package_example")).map(
|
|
22
|
+
(dpe) => ({
|
|
23
|
+
dev_package_example_id: dpe.dev_package_example_id,
|
|
24
|
+
file_path: dpe.file_path,
|
|
25
|
+
export_name: dpe.export_name,
|
|
26
|
+
is_loading: dpe.is_loading,
|
|
27
|
+
edit_events_last_updated_at: dpe.edit_events_last_updated_at,
|
|
28
|
+
soup_last_updated_at: dpe.soup_last_updated_at,
|
|
29
|
+
last_updated_at: dpe.last_updated_at,
|
|
30
|
+
})
|
|
31
|
+
)
|
|
32
|
+
|
|
38
33
|
return ctx.json({
|
|
39
34
|
dev_package_examples,
|
|
40
35
|
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { withWinterSpec } from "src/with-winter-spec"
|
|
2
2
|
import { NotFoundError } from "edgespec/middleware"
|
|
3
3
|
import { z } from "zod"
|
|
4
|
+
import { DevPackageExampleSchema } from "src/db/schema"
|
|
4
5
|
|
|
5
6
|
export default withWinterSpec({
|
|
6
7
|
methods: ["POST"],
|
|
@@ -12,46 +13,47 @@ export default withWinterSpec({
|
|
|
12
13
|
error: z.string().nullable().optional().default(null),
|
|
13
14
|
}),
|
|
14
15
|
jsonResponse: z.object({
|
|
15
|
-
dev_package_example:
|
|
16
|
-
dev_package_example_id: z.coerce.number(),
|
|
17
|
-
tscircuit_soup: z.any(),
|
|
18
|
-
error: z.string().nullable().optional(),
|
|
19
|
-
last_updated_at: z.string().datetime(),
|
|
20
|
-
}),
|
|
16
|
+
dev_package_example: DevPackageExampleSchema,
|
|
21
17
|
}),
|
|
22
18
|
auth: "none",
|
|
23
19
|
})(async (req, ctx) => {
|
|
20
|
+
const dev_package_example = await ctx.db.get(
|
|
21
|
+
"dev_package_example",
|
|
22
|
+
req.jsonBody.dev_package_example_id
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
if (!dev_package_example) {
|
|
26
|
+
throw new NotFoundError("Package not found")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const new_dev_package_example = {
|
|
30
|
+
...dev_package_example,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (req.jsonBody.completed_edit_events !== undefined) {
|
|
34
|
+
new_dev_package_example.completed_edit_events =
|
|
35
|
+
req.jsonBody.completed_edit_events
|
|
36
|
+
new_dev_package_example.edit_events_last_updated_at =
|
|
37
|
+
new Date().toISOString()
|
|
38
|
+
}
|
|
39
|
+
if (req.jsonBody.edit_events_last_applied_at !== undefined) {
|
|
40
|
+
new_dev_package_example.edit_events_last_applied_at =
|
|
41
|
+
req.jsonBody.edit_events_last_applied_at
|
|
42
|
+
}
|
|
43
|
+
if (req.jsonBody.tscircuit_soup !== undefined) {
|
|
44
|
+
new_dev_package_example.tscircuit_soup = req.jsonBody.tscircuit_soup
|
|
45
|
+
new_dev_package_example.error = null
|
|
46
|
+
new_dev_package_example.soup_last_updated_at = new Date().toISOString()
|
|
47
|
+
}
|
|
48
|
+
if (req.jsonBody.error !== undefined) {
|
|
49
|
+
new_dev_package_example.error = req.jsonBody.error
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
new_dev_package_example.last_updated_at = new Date().toISOString()
|
|
53
|
+
|
|
54
|
+
await ctx.db.put("dev_package_example", new_dev_package_example)
|
|
55
|
+
|
|
24
56
|
return ctx.json({
|
|
25
|
-
dev_package_example:
|
|
26
|
-
.updateTable("dev_package_example")
|
|
27
|
-
.set({
|
|
28
|
-
last_updated_at: new Date().toISOString(),
|
|
29
|
-
})
|
|
30
|
-
.$if(req.jsonBody.tscircuit_soup !== undefined, (q) =>
|
|
31
|
-
q
|
|
32
|
-
.set("tscircuit_soup", req.jsonBody.tscircuit_soup)
|
|
33
|
-
.set("error", null)
|
|
34
|
-
.set("soup_last_updated_at", new Date().toISOString())
|
|
35
|
-
)
|
|
36
|
-
.$if(req.jsonBody.error !== undefined, (q) =>
|
|
37
|
-
q.set("error", req.jsonBody.error)
|
|
38
|
-
)
|
|
39
|
-
.$if(req.jsonBody.completed_edit_events !== undefined, (q) =>
|
|
40
|
-
q
|
|
41
|
-
.set(
|
|
42
|
-
"completed_edit_events",
|
|
43
|
-
JSON.stringify(req.jsonBody.completed_edit_events)
|
|
44
|
-
)
|
|
45
|
-
.set("edit_events_last_updated_at", new Date().toISOString())
|
|
46
|
-
)
|
|
47
|
-
.$if(req.jsonBody.edit_events_last_applied_at !== undefined, (q) =>
|
|
48
|
-
q.set(
|
|
49
|
-
"edit_events_last_applied_at",
|
|
50
|
-
req.jsonBody.edit_events_last_applied_at!
|
|
51
|
-
)
|
|
52
|
-
)
|
|
53
|
-
.returningAll()
|
|
54
|
-
.where("dev_package_example_id", "=", req.jsonBody.dev_package_example_id)
|
|
55
|
-
.executeTakeFirstOrThrow(),
|
|
57
|
+
dev_package_example: new_dev_package_example,
|
|
56
58
|
})
|
|
57
59
|
})
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { sql } from "kysely"
|
|
2
1
|
import { withWinterSpec } from "src/with-winter-spec"
|
|
3
|
-
import { z } from "zod"
|
|
4
|
-
import { unlinkSync } from "fs"
|
|
5
|
-
import { getDbFilePath } from "src/db/get-db"
|
|
6
|
-
|
|
7
|
-
export default (req: Request) => {
|
|
8
|
-
unlinkSync(getDbFilePath())
|
|
9
2
|
|
|
3
|
+
export default withWinterSpec({
|
|
4
|
+
methods: ["GET", "POST"],
|
|
5
|
+
auth: "none",
|
|
6
|
+
})(async (req, ctx) => {
|
|
7
|
+
await ctx.db.clear()
|
|
10
8
|
return new Response(JSON.stringify({}), {
|
|
11
9
|
headers: {
|
|
12
10
|
"content-type": "application/json",
|
|
13
11
|
},
|
|
14
12
|
})
|
|
15
|
-
}
|
|
13
|
+
})
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ExportFileSchema } from "src/db/schema"
|
|
1
2
|
import { publicMapExportFile } from "src/lib/public-mapping/public-map-export-file"
|
|
2
3
|
import { export_file } from "src/lib/zod/export_file"
|
|
3
4
|
import { withWinterSpec } from "src/with-winter-spec"
|
|
@@ -8,25 +9,21 @@ export default withWinterSpec({
|
|
|
8
9
|
jsonBody: z.object({
|
|
9
10
|
export_request_id: z.number().int(),
|
|
10
11
|
file_name: z.string(),
|
|
11
|
-
file_content_base64: z.string()
|
|
12
|
+
file_content_base64: z.string(),
|
|
12
13
|
}),
|
|
13
14
|
jsonResponse: z.object({
|
|
14
|
-
export_file,
|
|
15
|
+
export_file: ExportFileSchema.omit({ file_content_base64: true }),
|
|
15
16
|
}),
|
|
16
17
|
auth: "none",
|
|
17
18
|
})(async (req, ctx) => {
|
|
18
|
-
const
|
|
19
|
-
.
|
|
20
|
-
.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
created_at: new Date().toISOString(),
|
|
25
|
-
})
|
|
26
|
-
.returningAll()
|
|
27
|
-
.executeTakeFirstOrThrow()
|
|
19
|
+
const export_file = await ctx.db.put("export_file", {
|
|
20
|
+
export_request_id: req.jsonBody.export_request_id,
|
|
21
|
+
file_name: req.jsonBody.file_name,
|
|
22
|
+
file_content_base64: req.jsonBody.file_content_base64,
|
|
23
|
+
created_at: new Date().toISOString(),
|
|
24
|
+
})
|
|
28
25
|
|
|
29
26
|
return ctx.json({
|
|
30
|
-
export_file
|
|
27
|
+
export_file,
|
|
31
28
|
})
|
|
32
29
|
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { publicMapExportFile } from "src/lib/public-mapping/public-map-export-file"
|
|
2
2
|
import { export_file } from "src/lib/zod/export_file"
|
|
3
3
|
import { withWinterSpec } from "src/with-winter-spec"
|
|
4
|
+
import { NotFoundError } from "winterspec/middleware"
|
|
4
5
|
import { z } from "zod"
|
|
5
6
|
|
|
6
7
|
export default withWinterSpec({
|
|
@@ -10,15 +11,17 @@ export default withWinterSpec({
|
|
|
10
11
|
}),
|
|
11
12
|
auth: "none",
|
|
12
13
|
})(async (req, ctx) => {
|
|
13
|
-
const
|
|
14
|
-
.selectFrom("export_file")
|
|
15
|
-
.selectAll()
|
|
16
|
-
.where("export_file_id", "=", req.query.export_file_id)
|
|
17
|
-
.executeTakeFirstOrThrow()
|
|
14
|
+
const export_file = await ctx.db.get("export_file", req.query.export_file_id)
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
if (!export_file) {
|
|
17
|
+
throw new NotFoundError("Export file not found")
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const file_content = Buffer.from(export_file.file_content_base64!, "base64")
|
|
21
|
+
|
|
22
|
+
return new Response(file_content, {
|
|
20
23
|
headers: {
|
|
21
|
-
"Content-Disposition": `attachment; filename="${
|
|
24
|
+
"Content-Disposition": `attachment; filename="${export_file.file_name}"`,
|
|
22
25
|
},
|
|
23
26
|
})
|
|
24
27
|
})
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { withWinterSpec } from "src/with-winter-spec"
|
|
2
|
-
import { NotFoundError } from "edgespec/middleware"
|
|
3
2
|
import { z } from "zod"
|
|
4
|
-
import { export_request } from "src/lib/zod/export_request"
|
|
5
3
|
import { publicMapExportRequest } from "src/lib/public-mapping/public-map-export-request"
|
|
6
4
|
import { export_parameters } from "../../../src/lib/zod/export_parameters"
|
|
5
|
+
import { ExportRequestSchema } from "src/db/schema"
|
|
7
6
|
|
|
8
7
|
export default withWinterSpec({
|
|
9
8
|
methods: ["POST"],
|
|
@@ -13,23 +12,20 @@ export default withWinterSpec({
|
|
|
13
12
|
export_parameters: export_parameters,
|
|
14
13
|
}),
|
|
15
14
|
jsonResponse: z.object({
|
|
16
|
-
export_request,
|
|
15
|
+
export_request: ExportRequestSchema,
|
|
17
16
|
}),
|
|
18
17
|
auth: "none",
|
|
19
18
|
})(async (req, ctx) => {
|
|
20
|
-
const
|
|
21
|
-
.
|
|
22
|
-
.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
29
|
-
.returningAll()
|
|
30
|
-
.executeTakeFirstOrThrow()
|
|
19
|
+
const export_request = await ctx.db.put("export_request", {
|
|
20
|
+
example_file_path: req.jsonBody.example_file_path,
|
|
21
|
+
export_parameters: req.jsonBody.export_parameters,
|
|
22
|
+
export_name: req.jsonBody.export_name ?? "default",
|
|
23
|
+
is_complete: false,
|
|
24
|
+
has_error: false,
|
|
25
|
+
created_at: new Date().toISOString(),
|
|
26
|
+
})
|
|
31
27
|
|
|
32
28
|
return ctx.json({
|
|
33
|
-
export_request
|
|
29
|
+
export_request,
|
|
34
30
|
})
|
|
35
31
|
})
|
|
@@ -2,6 +2,9 @@ import { withWinterSpec } from "src/with-winter-spec"
|
|
|
2
2
|
import { z } from "zod"
|
|
3
3
|
import { export_request } from "src/lib/zod/export_request"
|
|
4
4
|
import { publicMapExportRequest } from "src/lib/public-mapping/public-map-export-request"
|
|
5
|
+
import { NotFoundError } from "edgespec/middleware"
|
|
6
|
+
import { ExportRequestSchema } from "src/db/schema"
|
|
7
|
+
import { file } from "bun"
|
|
5
8
|
|
|
6
9
|
export default withWinterSpec({
|
|
7
10
|
methods: ["GET", "POST"],
|
|
@@ -9,29 +12,35 @@ export default withWinterSpec({
|
|
|
9
12
|
export_request_id: z.coerce.number(),
|
|
10
13
|
}),
|
|
11
14
|
jsonResponse: z.object({
|
|
12
|
-
export_request:
|
|
15
|
+
export_request: ExportRequestSchema.extend({
|
|
16
|
+
file_summary: z.array(
|
|
17
|
+
z.object({ file_name: z.string(), export_file_id: z.coerce.number() })
|
|
18
|
+
),
|
|
19
|
+
}),
|
|
13
20
|
}),
|
|
14
21
|
auth: "none",
|
|
15
22
|
})(async (req, ctx) => {
|
|
16
23
|
const { export_request_id } = req.commonParams
|
|
17
|
-
const
|
|
18
|
-
.selectFrom("export_request")
|
|
19
|
-
.selectAll()
|
|
20
|
-
.where("export_request_id", "=", export_request_id)
|
|
21
|
-
.executeTakeFirstOrThrow()
|
|
24
|
+
const export_request = await ctx.db.get("export_request", export_request_id)
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
if (!export_request) {
|
|
27
|
+
throw new NotFoundError("Export request not found")
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const ext_export_request: Parameters<typeof ctx.json>[0]["export_request"] = {
|
|
31
|
+
...export_request,
|
|
32
|
+
file_summary: undefined as any,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const export_files = (await ctx.db.list("export_file")).filter(
|
|
36
|
+
(ef) => ef.export_request_id === export_request_id
|
|
37
|
+
)
|
|
38
|
+
ext_export_request.file_summary = export_files.map((ef) => ({
|
|
39
|
+
file_name: ef.file_name!,
|
|
31
40
|
export_file_id: ef.export_file_id,
|
|
32
41
|
}))
|
|
33
42
|
|
|
34
43
|
return ctx.json({
|
|
35
|
-
export_request:
|
|
44
|
+
export_request: ext_export_request,
|
|
36
45
|
})
|
|
37
46
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { withWinterSpec } from "src/with-winter-spec"
|
|
2
2
|
import { z } from "zod"
|
|
3
|
-
import { export_request } from "src/lib/zod/export_request"
|
|
4
3
|
import { publicMapExportRequest } from "src/lib/public-mapping/public-map-export-request"
|
|
4
|
+
import { ExportRequestSchema } from "src/db/schema"
|
|
5
5
|
|
|
6
6
|
export default withWinterSpec({
|
|
7
7
|
methods: ["GET", "POST"],
|
|
@@ -9,20 +9,19 @@ export default withWinterSpec({
|
|
|
9
9
|
is_complete: z.boolean().nullable().default(null),
|
|
10
10
|
}),
|
|
11
11
|
jsonResponse: z.object({
|
|
12
|
-
export_requests: z.array(
|
|
12
|
+
export_requests: z.array(ExportRequestSchema),
|
|
13
13
|
}),
|
|
14
14
|
auth: "none",
|
|
15
15
|
})(async (req, ctx) => {
|
|
16
16
|
const { is_complete } = req.commonParams
|
|
17
|
-
const db_export_requests = await ctx.db
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.execute()
|
|
17
|
+
const db_export_requests = await ctx.db.list("export_request")
|
|
18
|
+
|
|
19
|
+
const filtered_requests =
|
|
20
|
+
is_complete === null
|
|
21
|
+
? db_export_requests
|
|
22
|
+
: db_export_requests.filter((er) => er.is_complete === is_complete)
|
|
24
23
|
|
|
25
24
|
return ctx.json({
|
|
26
|
-
export_requests:
|
|
25
|
+
export_requests: filtered_requests,
|
|
27
26
|
})
|
|
28
27
|
})
|
|
@@ -3,7 +3,7 @@ import { NotFoundError } from "edgespec/middleware"
|
|
|
3
3
|
import { z } from "zod"
|
|
4
4
|
import { export_request } from "src/lib/zod/export_request"
|
|
5
5
|
import { publicMapExportRequest } from "src/lib/public-mapping/public-map-export-request"
|
|
6
|
-
import {
|
|
6
|
+
import { ExportRequestSchema } from "src/db/schema"
|
|
7
7
|
|
|
8
8
|
export default withWinterSpec({
|
|
9
9
|
methods: ["POST"],
|
|
@@ -13,24 +13,24 @@ export default withWinterSpec({
|
|
|
13
13
|
has_error: z.boolean().optional(),
|
|
14
14
|
error: z.string().optional(),
|
|
15
15
|
}),
|
|
16
|
-
jsonResponse: z.object({
|
|
16
|
+
jsonResponse: z.object({
|
|
17
|
+
export_request: ExportRequestSchema,
|
|
18
|
+
}),
|
|
17
19
|
auth: "none",
|
|
18
20
|
})(async (req, ctx) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
})
|
|
31
|
-
)
|
|
32
|
-
.where("export_request_id", "=", req.jsonBody.export_request_id)
|
|
33
|
-
.execute()
|
|
21
|
+
const { export_request_id, ...updateData } = req.jsonBody
|
|
22
|
+
const existingRequest = await ctx.db.get("export_request", export_request_id)
|
|
23
|
+
|
|
24
|
+
if (!existingRequest) {
|
|
25
|
+
throw new NotFoundError("Export request not found")
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const updatedRequest = await ctx.db.put("export_request", {
|
|
29
|
+
...existingRequest,
|
|
30
|
+
...updateData,
|
|
31
|
+
})
|
|
34
32
|
|
|
35
|
-
return ctx.json({
|
|
33
|
+
return ctx.json({
|
|
34
|
+
export_request: updatedRequest,
|
|
35
|
+
})
|
|
36
36
|
})
|