@tscircuit/cli 0.0.144 → 0.0.161
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/formatbot.yml +41 -0
- package/.github/workflows/release.yml +6 -1
- package/.github/workflows/test.yml +2 -2
- package/.github/workflows/typecheck.yml +29 -0
- package/DEVELOPMENT.md +4 -1
- package/README.md +2 -6
- package/{dev-server-api/src → api}/db/generic-json-level.ts +4 -7
- package/{dev-server-api/src → api}/db/zod-level-db.ts +9 -9
- package/{dev-server-api/src → api/lib}/middlewares/with-db.ts +2 -2
- package/{dev-server-api/src → api/lib}/middlewares/with-debug-request-logging.ts +1 -1
- package/{dev-server-api/src → api/lib}/middlewares/with-error-response.ts +2 -2
- package/{dev-server-api → api}/routes/api/db/download.ts +3 -3
- package/{dev-server-api → api}/routes/api/dev_package_examples/create.ts +1 -1
- package/{dev-server-api → api}/routes/api/dev_package_examples/get.ts +3 -3
- package/{dev-server-api → api}/routes/api/dev_package_examples/list.ts +3 -3
- package/{dev-server-api → api}/routes/api/dev_package_examples/update.ts +4 -4
- package/{dev-server-api → api}/routes/api/dev_server/reset.ts +1 -1
- package/{dev-server-api → api}/routes/api/export_files/create.ts +2 -6
- package/{dev-server-api → api}/routes/api/export_files/download.ts +1 -3
- package/{dev-server-api → api}/routes/api/export_requests/create.ts +3 -4
- package/{dev-server-api → api}/routes/api/export_requests/get.ts +5 -8
- package/{dev-server-api → api}/routes/api/export_requests/list.ts +2 -3
- package/{dev-server-api → api}/routes/api/export_requests/update.ts +3 -5
- package/{dev-server-api/routes → api/routes/api}/health.ts +1 -1
- package/{dev-server-api → api}/routes/api/package_info/create.ts +1 -1
- package/{dev-server-api → api}/routes/api/package_info/get.ts +3 -2
- package/{dev-server-api/routes/api → api/routes}/health.ts +1 -1
- package/{dev-server-api → api}/routes/index.ts +2 -2
- package/{dev-server-api → api}/server.ts +2 -2
- package/api/static-routes.ts +24 -0
- package/{dev-server-api → api}/tests/fixtures/get-test-server.ts +2 -1
- package/api/tests/fixtures/start-server.ts +41 -0
- package/{dev-server-api → api}/tests/routes/dev_package_examples/create.test.ts +2 -2
- package/{dev-server-api → api}/tests/routes/dev_package_examples/get.test.ts +2 -2
- package/{dev-server-api → api}/tests/routes/dev_package_examples/list.test.ts +2 -2
- package/{dev-server-api → api}/tests/routes/dev_package_examples/update.test.ts +3 -3
- package/{dev-server-api → api}/tests/routes/export_files/create.test.ts +1 -1
- package/{dev-server-api → api}/tests/routes/export_files/download.test.ts +3 -3
- package/{dev-server-api → api}/tests/routes/export_requests/create.test.ts +2 -2
- package/{dev-server-api → api}/tests/routes/export_requests/get.test.ts +2 -2
- package/{dev-server-api → api}/tests/routes/export_requests/list.test.ts +1 -1
- package/{dev-server-api → api}/tests/routes/export_requests/update.test.ts +1 -1
- package/biome.json +49 -0
- package/bun.lockb +0 -0
- package/{lib → cli/lib}/cmd-fns/add.ts +2 -2
- package/{lib → cli/lib}/cmd-fns/auth-login.ts +2 -2
- package/{lib → cli/lib}/cmd-fns/dev/check-if-initialized.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/dev/derive-selector-from-pcb-component-id.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/dev/dev-server-request-handler.ts +5 -5
- package/{lib → cli/lib}/cmd-fns/dev/find-available-port.ts +7 -5
- package/{lib → cli/lib}/cmd-fns/dev/fulfill-export-requests.ts +27 -27
- package/{lib → cli/lib}/cmd-fns/dev/get-dev-server-axios.ts +3 -3
- package/{lib → cli/lib}/cmd-fns/dev/index.ts +4 -4
- package/{lib → cli/lib}/cmd-fns/dev/infer-export-name-from-source.ts +2 -2
- package/{lib → cli/lib}/cmd-fns/dev/soupify-and-upload-example-file.ts +6 -5
- package/{lib → cli/lib}/cmd-fns/dev/start-edit-event-watcher.ts +41 -42
- package/{lib → cli/lib}/cmd-fns/dev/start-export-request-watcher.ts +3 -4
- package/{lib → cli/lib}/cmd-fns/dev/start-fs-watcher.ts +2 -1
- package/{lib → cli/lib}/cmd-fns/dev/upload-examples-from-directory.ts +4 -3
- package/{lib → cli/lib}/cmd-fns/dev-server-fulfill-export-requests.ts +3 -3
- package/{lib → cli/lib}/cmd-fns/dev-server-upload.ts +3 -3
- package/{lib → cli/lib}/cmd-fns/export-gerbers.ts +2 -2
- package/cli/lib/cmd-fns/go.ts +14 -0
- package/{lib → cli/lib}/cmd-fns/index.ts +2 -0
- package/{lib → cli/lib}/cmd-fns/init/create-or-modify-npmrc.ts +2 -2
- package/{lib → cli/lib}/cmd-fns/init/get-generated-npmrc.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/init/index.ts +13 -9
- package/{lib → cli/lib}/cmd-fns/install.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/lint.ts +16 -10
- package/{lib → cli/lib}/cmd-fns/open.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/package-examples-create.ts +2 -2
- package/{lib → cli/lib}/cmd-fns/package-files-create.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/package-files-upload-directory.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/package-releases-create.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/package-releases-list.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/publish/index.ts +34 -34
- package/{lib → cli/lib}/cmd-fns/remove.ts +2 -2
- package/cli/lib/cmd-fns/render.ts +45 -0
- package/{lib → cli/lib}/cmd-fns/soupify.ts +2 -2
- package/{lib → cli/lib}/cmd-fns/uninstall.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/version.ts +7 -8
- package/{lib → cli/lib}/create-config-manager.ts +1 -1
- package/{lib → cli/lib}/export-fns/export-bom-csv.ts +3 -3
- package/{lib → cli/lib}/export-fns/export-gerbers.ts +6 -6
- package/{lib → cli/lib}/export-fns/export-pnp-csv.ts +3 -3
- package/{lib → cli/lib}/get-program.ts +37 -21
- package/{lib → cli/lib}/param-handlers/interact-for-package-release-id.ts +2 -3
- package/{lib → cli/lib}/param-handlers/interact-for-runtime.ts +1 -1
- package/{lib → cli/lib}/param-handlers/param-handler-type.ts +1 -1
- package/{lib → cli/lib}/posthog.ts +6 -7
- package/{lib → cli/lib}/soupify.ts +4 -4
- package/{lib → cli/lib}/util/app-context.ts +1 -1
- package/{lib → cli/lib}/util/create-context-and-run-program.ts +14 -10
- package/{lib → cli/lib}/util/get-all-package-files.ts +2 -2
- package/cli/lib/util/lint-project.ts +137 -0
- package/{tests → cli/tests}/init.test.ts +1 -1
- package/{tests → cli/tests}/open.test.ts +2 -1
- package/{tests → cli/tests}/soupify.test.ts +1 -1
- package/dist/cli.js +311 -310
- package/example-project/package.json +2 -11
- package/example-project/src/manual-edits.ts +34 -34
- package/{dev-server-frontend/src → frontend}/components/command-k.tsx +2 -2
- package/{dev-server-frontend/src → frontend}/components/dialogs/generic-export-dialog.tsx +6 -10
- package/{dev-server-frontend/src → frontend}/components/dialogs/gerber-export-dialog.tsx +5 -5
- package/{dev-server-frontend/src → frontend}/components/select-example-search.tsx +7 -7
- package/{dev-server-frontend/src → frontend}/components/ui/alert-dialog.tsx +7 -7
- package/{dev-server-frontend/src → frontend}/components/ui/alert.tsx +2 -2
- package/{dev-server-frontend/src → frontend}/components/ui/breadcrumb.tsx +2 -2
- package/{dev-server-frontend/src → frontend}/components/ui/button.tsx +3 -3
- package/{dev-server-frontend/src → frontend}/components/ui/card.tsx +2 -2
- package/{dev-server-frontend/src → frontend}/components/ui/command.tsx +7 -7
- package/{dev-server-frontend/src → frontend}/components/ui/context-menu.tsx +9 -9
- package/{dev-server-frontend/src → frontend}/components/ui/dialog.tsx +6 -6
- package/{dev-server-frontend/src → frontend}/components/ui/menubar.tsx +13 -13
- package/{dev-server-frontend/src → frontend}/components/ui/navigation-menu.tsx +7 -7
- package/{dev-server-frontend/src → frontend}/components/ui/popover.tsx +2 -2
- package/{dev-server-frontend/src → frontend}/components/ui/select.tsx +7 -7
- package/{dev-server-frontend/src → frontend}/components/ui/tabs.tsx +4 -4
- package/{dev-server-frontend/src → frontend}/components/ui/toggle-group.tsx +3 -3
- package/{dev-server-frontend/src → frontend}/components/ui/toggle.tsx +2 -2
- package/{dev-server-frontend/src → frontend}/components/ui/tooltip.tsx +2 -2
- package/{dev-server-frontend → frontend}/components.json +1 -1
- package/{dev-server-frontend/src → frontend}/hooks/use-active-dev-package-example-lite.ts +2 -2
- package/{dev-server-frontend → frontend}/index.html +1 -1
- package/{dev-server-frontend/src → frontend}/main.tsx +2 -2
- package/{dev-server-frontend → frontend}/tailwind.config.js +4 -7
- package/frontend/views/App.tsx +22 -0
- package/{dev-server-frontend/src → frontend/views}/Header.tsx +5 -5
- package/{dev-server-frontend/src → frontend/views}/HeaderMenu.tsx +51 -23
- package/{dev-server-frontend/src/ExampleContentView.tsx → frontend/views/MainContentView.tsx} +7 -7
- package/frontend/vite.config.ts +50 -0
- package/package.json +57 -18
- package/renovate.json +2 -4
- package/scripts/build-cli.ts +12 -0
- package/tsconfig.json +17 -108
- package/tsup.config.ts +3 -3
- package/.github/workflows/server-tests.yml +0 -31
- package/build-cli.ts +0 -14
- package/dev-server-api/bun.lockb +0 -0
- package/dev-server-api/edgespec.config.ts +0 -4
- package/dev-server-api/package.json +0 -23
- package/dev-server-api/src/db/create-schema.ts +0 -54
- package/dev-server-api/src/lib/public-mapping/public-map-export-file.ts +0 -17
- package/dev-server-api/src/lib/public-mapping/public-map-export-request.ts +0 -23
- package/dev-server-api/static-routes.ts +0 -24
- package/dev-server-api/tests/fixtures/start-server.ts +0 -20
- package/dev-server-api/tsconfig.json +0 -28
- package/dev-server-frontend/.eslintrc.cjs +0 -20
- package/dev-server-frontend/package-lock.json +0 -8970
- package/dev-server-frontend/package.json +0 -70
- package/dev-server-frontend/postcss.config.js +0 -6
- package/dev-server-frontend/src/App.tsx +0 -22
- package/dev-server-frontend/tsconfig.json +0 -29
- package/dev-server-frontend/tsconfig.node.json +0 -13
- package/dev-server-frontend/vite.config.ts +0 -23
- package/example-project/package-lock.json +0 -609
- package/lib/util/lint-project.ts +0 -112
- /package/{dev-server-api → api}/README.md +0 -0
- /package/{dev-server-api/src → api}/db/get-db.ts +0 -0
- /package/{dev-server-api/src → api}/db/schema.ts +0 -0
- /package/{dev-server-api → api}/index.ts +0 -0
- /package/{dev-server-api/src → api/lib}/with-winter-spec.ts +0 -0
- /package/{dev-server-api/src → api}/lib/zod/export_parameters.ts +0 -0
- /package/{dev-server-api → api}/tests/routes/health.test.ts +0 -0
- /package/{cli.ts → cli/cli.ts} +0 -0
- /package/{lib → cli/lib}/cmd-fns/auth-logout.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/auth-sessions-create.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/auth-sessions-get.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/auth-sessions-list.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/config-clear.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/config-print-config.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/config-reveal-location.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/config-set-log-requests.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/config-set-registry.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/config-set-runtime.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/config-set-session.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/dev/mark-all-examples-loading.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/dev/start-dev-server.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/init/get-generated-readme.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/init/get-generated-tsconfig.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/package-examples-get.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/package-examples-list.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/package-files-download.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/package-files-get.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/package-files-list.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/package-releases-get.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/package-releases-update.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/packages-create.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/packages-get.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/packages-list.ts +0 -0
- /package/{lib → cli/lib}/param-handlers/index.ts +0 -0
- /package/{lib → cli/lib}/param-handlers/interact-for-local-directory.ts +0 -0
- /package/{lib → cli/lib}/param-handlers/interact-for-local-file.ts +0 -0
- /package/{lib → cli/lib}/param-handlers/interact-for-package-example-id.ts +0 -0
- /package/{lib → cli/lib}/param-handlers/interact-for-package-name-with-version.ts +0 -0
- /package/{lib → cli/lib}/param-handlers/interact-for-package-name.ts +0 -0
- /package/{lib → cli/lib}/param-handlers/interact-for-registry-url.ts +0 -0
- /package/example-project/examples/{basic-bug.tsx → basic-chip.tsx} +0 -0
- /package/{dev-server-frontend → frontend}/README.md +0 -0
- /package/{dev-server-frontend → frontend}/bun.lockb +0 -0
- /package/{dev-server-frontend/src → frontend}/components/global-context-providers.tsx +0 -0
- /package/{dev-server-frontend/src → frontend}/hooks/toast-if-api-not-connected.ts +0 -0
- /package/{dev-server-frontend/src → frontend}/hooks/use-dev-package-examples.tsx +0 -0
- /package/{dev-server-frontend/src → frontend}/hooks/use-global-store.ts +0 -0
- /package/{dev-server-frontend/src → frontend}/index.css +0 -0
- /package/{dev-server-frontend/src → frontend}/lib/utils.ts +0 -0
- /package/{dev-server-frontend/src → frontend}/vite-env.d.ts +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: Format PR
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [opened, synchronize, reopened, ready_for_review]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
format:
|
|
9
|
+
name: Format code
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
if: github.event.pull_request.draft == false
|
|
12
|
+
|
|
13
|
+
steps:
|
|
14
|
+
- name: Checkout code
|
|
15
|
+
uses: actions/checkout@v3
|
|
16
|
+
with:
|
|
17
|
+
token: ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}
|
|
18
|
+
|
|
19
|
+
- name: Setup Node.js
|
|
20
|
+
uses: actions/setup-node@v3
|
|
21
|
+
with:
|
|
22
|
+
node-version: '20'
|
|
23
|
+
|
|
24
|
+
- name: Get @biomejs/biome version
|
|
25
|
+
id: get-biome-version
|
|
26
|
+
run: echo "BIOME_VERSION=$(node -p "require('./package.json').devDependencies['@biomejs/biome']")" >> $GITHUB_OUTPUT
|
|
27
|
+
|
|
28
|
+
- name: Install @biomejs/biome
|
|
29
|
+
run: npm install @biomejs/biome@${{ steps.get-biome-version.outputs.BIOME_VERSION }}
|
|
30
|
+
|
|
31
|
+
- name: Run formatter
|
|
32
|
+
run: npx @biomejs/biome format . --write
|
|
33
|
+
|
|
34
|
+
- name: Commit changes
|
|
35
|
+
uses: stefanzweifel/git-auto-commit-action@v4
|
|
36
|
+
with:
|
|
37
|
+
commit_message: "formatbot: Automatically format code"
|
|
38
|
+
branch: ${{ github.head_ref }}
|
|
39
|
+
commit_user_name: tscircuitbot
|
|
40
|
+
commit_user_email: tscircuitbot@users.noreply.github.com
|
|
41
|
+
commit_author: tscircuitbot <tscircuitbot@users.noreply.github.com>
|
|
@@ -24,7 +24,12 @@ jobs:
|
|
|
24
24
|
bun-version: latest
|
|
25
25
|
|
|
26
26
|
- name: Install project dependencies
|
|
27
|
-
run:
|
|
27
|
+
run: |
|
|
28
|
+
bun install
|
|
29
|
+
|
|
30
|
+
# Undo changes to the lockfile that might block release
|
|
31
|
+
# when this project is more mature use "bun install --frozen-lockfile"
|
|
32
|
+
git checkout -- bun.lockb
|
|
28
33
|
|
|
29
34
|
- name: Build project
|
|
30
35
|
run: bun run build
|
|
@@ -9,7 +9,7 @@ on:
|
|
|
9
9
|
- main
|
|
10
10
|
|
|
11
11
|
jobs:
|
|
12
|
-
|
|
12
|
+
tests:
|
|
13
13
|
runs-on: ubuntu-latest
|
|
14
14
|
|
|
15
15
|
steps:
|
|
@@ -22,7 +22,7 @@ jobs:
|
|
|
22
22
|
bun-version: latest
|
|
23
23
|
|
|
24
24
|
- name: Install dependencies
|
|
25
|
-
run: bun
|
|
25
|
+
run: bun install
|
|
26
26
|
|
|
27
27
|
- name: Install dependencies
|
|
28
28
|
run: bun run build
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
|
|
2
|
+
name: Type Check
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
pull_request:
|
|
8
|
+
branches: [main]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
type-check:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v3
|
|
16
|
+
|
|
17
|
+
- name: Setup bun
|
|
18
|
+
uses: oven-sh/setup-bun@v1
|
|
19
|
+
with:
|
|
20
|
+
bun-version: latest
|
|
21
|
+
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: bun i
|
|
24
|
+
|
|
25
|
+
- name: Build (required for dist imports)
|
|
26
|
+
run: bun run build
|
|
27
|
+
|
|
28
|
+
- name: Run format check
|
|
29
|
+
run: bunx tsc --noEmit
|
package/DEVELOPMENT.md
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
# Getting Started with Development for @tscircuit/cli
|
|
2
2
|
|
|
3
3
|
1. Run `bun install`
|
|
4
|
-
2. Run `bun
|
|
4
|
+
2. Run `bun run dev`
|
|
5
|
+
|
|
6
|
+
You now have a development server running on http://localhost:5173 (don't use
|
|
7
|
+
the one on port 3020, it won't auto-reload frontend changes)
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# `tsci` - The TSCircuit Command Line
|
|
1
|
+
# `tsci` - The TSCircuit Command Line & Development Tools
|
|
2
2
|
|
|
3
3
|
Command line tool for developing tscircuit projects and interacting with the
|
|
4
4
|
tscircuit registry.
|
|
@@ -41,17 +41,13 @@ tsci publish
|
|
|
41
41
|
This project is developed with [bun](https://bun.sh/), make sure you have
|
|
42
42
|
that installed.
|
|
43
43
|
|
|
44
|
-
Run `bun
|
|
44
|
+
Run `bun install` to install dependencies and `bun cli/cli.ts` to run test the cli in development, or `bun run dev` to run the dev server.
|
|
45
45
|
|
|
46
46
|
To run tests, run `bun test`
|
|
47
47
|
|
|
48
48
|
If you want to test developing, run `bun dev` and visit http://127.0.0.1:5173. The project being
|
|
49
49
|
loaded is inside `example-project`
|
|
50
50
|
|
|
51
|
-

|
|
52
|
-
|
|
53
|
-

|
|
54
|
-
|
|
55
51
|

|
|
56
52
|
|
|
57
53
|
## Features Coming Soon
|
|
@@ -57,7 +57,7 @@ class GenericJsonLevel extends AbstractLevel<string, any> {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
async _batch(
|
|
60
|
-
operations: Array<{ type: "put" | "del"; key: string; value?: any }
|
|
60
|
+
operations: Array<{ type: "put" | "del"; key: string; value?: any }>,
|
|
61
61
|
): Promise<void> {
|
|
62
62
|
for (const op of operations) {
|
|
63
63
|
if (op.type === "put") {
|
|
@@ -99,7 +99,7 @@ class GenericJsonLevel extends AbstractLevel<string, any> {
|
|
|
99
99
|
async next() {
|
|
100
100
|
if (files.length === 0) {
|
|
101
101
|
files = (await fs.readdir(this.db.location)).filter((file) =>
|
|
102
|
-
file.endsWith(".json")
|
|
102
|
+
file.endsWith(".json"),
|
|
103
103
|
)
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -108,7 +108,7 @@ class GenericJsonLevel extends AbstractLevel<string, any> {
|
|
|
108
108
|
return undefined
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
return [entry.key, entry.value]
|
|
111
|
+
return [entry.key, entry.value] as [string, any]
|
|
112
112
|
},
|
|
113
113
|
async seek(target: string) {
|
|
114
114
|
index = files.findIndex((file) => file.startsWith(target))
|
|
@@ -116,10 +116,7 @@ class GenericJsonLevel extends AbstractLevel<string, any> {
|
|
|
116
116
|
index = files.length
|
|
117
117
|
}
|
|
118
118
|
},
|
|
119
|
-
|
|
120
|
-
// No resources to clean up
|
|
121
|
-
},
|
|
122
|
-
}
|
|
119
|
+
} as any
|
|
123
120
|
}
|
|
124
121
|
}
|
|
125
122
|
|
|
@@ -22,7 +22,7 @@ export class ZodLevelDatabase {
|
|
|
22
22
|
|
|
23
23
|
async get<K extends keyof DBSchemaType>(
|
|
24
24
|
collection: K,
|
|
25
|
-
id: string | number
|
|
25
|
+
id: string | number,
|
|
26
26
|
): Promise<DBSchemaType[K] | null> {
|
|
27
27
|
const key = `${collection}:${id}`
|
|
28
28
|
const data = await this.db.get(key).catch((e) => null)
|
|
@@ -32,7 +32,7 @@ export class ZodLevelDatabase {
|
|
|
32
32
|
|
|
33
33
|
async put<K extends keyof DBSchemaType>(
|
|
34
34
|
collection: K,
|
|
35
|
-
value: DBInputSchemaType[K]
|
|
35
|
+
value: DBInputSchemaType[K],
|
|
36
36
|
): Promise<DBSchemaType[K]> {
|
|
37
37
|
const idkey = `${collection}_id`
|
|
38
38
|
const valueLoose: any = value
|
|
@@ -51,7 +51,7 @@ export class ZodLevelDatabase {
|
|
|
51
51
|
|
|
52
52
|
async del<K extends keyof DBSchemaType>(
|
|
53
53
|
collection: K,
|
|
54
|
-
id: string
|
|
54
|
+
id: string,
|
|
55
55
|
): Promise<void> {
|
|
56
56
|
const key = `${collection}:${id}`
|
|
57
57
|
await this.db.del(key)
|
|
@@ -59,7 +59,7 @@ export class ZodLevelDatabase {
|
|
|
59
59
|
|
|
60
60
|
async find<K extends keyof DBSchemaType>(
|
|
61
61
|
collection: K,
|
|
62
|
-
partialObject: Partial<DBSchemaType[K]
|
|
62
|
+
partialObject: Partial<DBSchemaType[K]>,
|
|
63
63
|
): Promise<DBSchemaType[K] | null> {
|
|
64
64
|
const schema = DBSchema.shape[collection]
|
|
65
65
|
|
|
@@ -82,14 +82,14 @@ export class ZodLevelDatabase {
|
|
|
82
82
|
|
|
83
83
|
async findOrThrow<K extends keyof DBSchemaType>(
|
|
84
84
|
collection: K,
|
|
85
|
-
partialObject: Partial<DBSchemaType[K]
|
|
85
|
+
partialObject: Partial<DBSchemaType[K]>,
|
|
86
86
|
): Promise<DBSchemaType[K]> {
|
|
87
87
|
const result = await this.find(collection, partialObject)
|
|
88
88
|
if (!result) {
|
|
89
89
|
throw new Error(
|
|
90
90
|
`No record in "${collection}" matches query ${JSON.stringify(
|
|
91
|
-
partialObject
|
|
92
|
-
)}
|
|
91
|
+
partialObject,
|
|
92
|
+
)}`,
|
|
93
93
|
)
|
|
94
94
|
}
|
|
95
95
|
return result
|
|
@@ -97,7 +97,7 @@ export class ZodLevelDatabase {
|
|
|
97
97
|
|
|
98
98
|
private matchesPartialObject<T>(
|
|
99
99
|
fullObject: T,
|
|
100
|
-
partialObject: Partial<T
|
|
100
|
+
partialObject: Partial<T>,
|
|
101
101
|
): boolean {
|
|
102
102
|
for (const [key, value] of Object.entries(partialObject)) {
|
|
103
103
|
if (fullObject[key as keyof T] !== value) {
|
|
@@ -121,7 +121,7 @@ export class ZodLevelDatabase {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
async list<K extends keyof DBSchemaType>(
|
|
124
|
-
collection: K
|
|
124
|
+
collection: K,
|
|
125
125
|
): Promise<DBSchemaType[K][]> {
|
|
126
126
|
const schema = DBSchema.shape[collection]
|
|
127
127
|
const results: DBSchemaType[K][] = []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Middleware } from "winterspec"
|
|
2
|
-
import { getDb } from "
|
|
3
|
-
import type { ZodLevelDatabase } from "
|
|
2
|
+
import { getDb } from "api/db/get-db"
|
|
3
|
+
import type { ZodLevelDatabase } from "api/db/zod-level-db"
|
|
4
4
|
|
|
5
5
|
export const withDb: Middleware<
|
|
6
6
|
{},
|
|
@@ -18,7 +18,7 @@ export const withErrorResponse: Middleware<{}, {}> = async (req, ctx, next) => {
|
|
|
18
18
|
error_code: "not_found",
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
|
-
{ status: error?.status || 404 }
|
|
21
|
+
{ status: error?.status || 404 },
|
|
22
22
|
)
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -31,7 +31,7 @@ export const withErrorResponse: Middleware<{}, {}> = async (req, ctx, next) => {
|
|
|
31
31
|
error_code: error?.error_code ?? "internal_server_error",
|
|
32
32
|
},
|
|
33
33
|
},
|
|
34
|
-
{ status: error?.status || 500 }
|
|
34
|
+
{ status: error?.status || 500 },
|
|
35
35
|
)
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { withWinterSpec } from "
|
|
1
|
+
import { withWinterSpec } from "api/lib/with-winter-spec"
|
|
2
2
|
import { z } from "zod"
|
|
3
3
|
|
|
4
4
|
export default withWinterSpec({
|
|
@@ -14,12 +14,12 @@ export default withWinterSpec({
|
|
|
14
14
|
dev_server_database_dump: await ctx.db.dump(),
|
|
15
15
|
},
|
|
16
16
|
null,
|
|
17
|
-
" "
|
|
17
|
+
" ",
|
|
18
18
|
),
|
|
19
19
|
{
|
|
20
20
|
headers: {
|
|
21
21
|
"content-type": "application/json",
|
|
22
22
|
},
|
|
23
|
-
}
|
|
23
|
+
},
|
|
24
24
|
)
|
|
25
25
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { withWinterSpec } from "
|
|
2
|
-
import { NotFoundError } from "
|
|
1
|
+
import { withWinterSpec } from "api/lib/with-winter-spec"
|
|
2
|
+
import { NotFoundError } from "winterspec/middleware"
|
|
3
3
|
import { z } from "zod"
|
|
4
4
|
|
|
5
5
|
export default withWinterSpec({
|
|
@@ -33,7 +33,7 @@ export default withWinterSpec({
|
|
|
33
33
|
})(async (req, ctx) => {
|
|
34
34
|
const dev_package_example = await ctx.db.get(
|
|
35
35
|
"dev_package_example",
|
|
36
|
-
req.commonParams.dev_package_example_id
|
|
36
|
+
req.commonParams.dev_package_example_id,
|
|
37
37
|
)
|
|
38
38
|
|
|
39
39
|
if (!dev_package_example) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { withWinterSpec } from "
|
|
1
|
+
import { withWinterSpec } from "api/lib/with-winter-spec"
|
|
2
2
|
import { z } from "zod"
|
|
3
3
|
|
|
4
4
|
export default withWinterSpec({
|
|
@@ -13,7 +13,7 @@ export default withWinterSpec({
|
|
|
13
13
|
edit_events_last_updated_at: z.string().datetime().nullable(),
|
|
14
14
|
soup_last_updated_at: z.string().datetime().nullable(),
|
|
15
15
|
last_updated_at: z.string().datetime().nullable(),
|
|
16
|
-
})
|
|
16
|
+
}),
|
|
17
17
|
),
|
|
18
18
|
}),
|
|
19
19
|
auth: "none",
|
|
@@ -27,7 +27,7 @@ export default withWinterSpec({
|
|
|
27
27
|
edit_events_last_updated_at: dpe.edit_events_last_updated_at,
|
|
28
28
|
soup_last_updated_at: dpe.soup_last_updated_at,
|
|
29
29
|
last_updated_at: dpe.last_updated_at,
|
|
30
|
-
})
|
|
30
|
+
}),
|
|
31
31
|
)
|
|
32
32
|
|
|
33
33
|
return ctx.json({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { withWinterSpec } from "
|
|
2
|
-
import { NotFoundError } from "
|
|
1
|
+
import { withWinterSpec } from "api/lib/with-winter-spec"
|
|
2
|
+
import { NotFoundError } from "winterspec/middleware"
|
|
3
3
|
import { z } from "zod"
|
|
4
|
-
import { DevPackageExampleSchema } from "
|
|
4
|
+
import { DevPackageExampleSchema } from "api/db/schema"
|
|
5
5
|
|
|
6
6
|
export default withWinterSpec({
|
|
7
7
|
methods: ["POST"],
|
|
@@ -19,7 +19,7 @@ export default withWinterSpec({
|
|
|
19
19
|
})(async (req, ctx) => {
|
|
20
20
|
const dev_package_example = await ctx.db.get(
|
|
21
21
|
"dev_package_example",
|
|
22
|
-
req.jsonBody.dev_package_example_id
|
|
22
|
+
req.jsonBody.dev_package_example_id,
|
|
23
23
|
)
|
|
24
24
|
|
|
25
25
|
if (!dev_package_example) {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { ExportFileSchema } from "
|
|
2
|
-
import {
|
|
3
|
-
import { export_file } from "src/lib/zod/export_file"
|
|
4
|
-
import { withWinterSpec } from "src/with-winter-spec"
|
|
1
|
+
import { ExportFileSchema } from "api/db/schema"
|
|
2
|
+
import { withWinterSpec } from "api/lib/with-winter-spec"
|
|
5
3
|
import { z } from "zod"
|
|
6
4
|
|
|
7
5
|
export default withWinterSpec({
|
|
@@ -16,7 +14,6 @@ export default withWinterSpec({
|
|
|
16
14
|
}),
|
|
17
15
|
auth: "none",
|
|
18
16
|
})(async (req, ctx) => {
|
|
19
|
-
console.log("putting file")
|
|
20
17
|
const export_file = await ctx.db.put("export_file", {
|
|
21
18
|
export_request_id: req.jsonBody.export_request_id,
|
|
22
19
|
file_name: req.jsonBody.file_name,
|
|
@@ -24,7 +21,6 @@ export default withWinterSpec({
|
|
|
24
21
|
created_at: new Date().toISOString(),
|
|
25
22
|
})
|
|
26
23
|
console.log("done putting file")
|
|
27
|
-
|
|
28
24
|
return ctx.json({
|
|
29
25
|
export_file,
|
|
30
26
|
})
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { export_file } from "src/lib/zod/export_file"
|
|
3
|
-
import { withWinterSpec } from "src/with-winter-spec"
|
|
1
|
+
import { withWinterSpec } from "api/lib/with-winter-spec"
|
|
4
2
|
import { NotFoundError } from "winterspec/middleware"
|
|
5
3
|
import { z } from "zod"
|
|
6
4
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { withWinterSpec } from "
|
|
1
|
+
import { withWinterSpec } from "api/lib/with-winter-spec"
|
|
2
2
|
import { z } from "zod"
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { ExportRequestSchema } from "src/db/schema"
|
|
3
|
+
import { export_parameters } from "api/lib/zod/export_parameters"
|
|
4
|
+
import { ExportRequestSchema } from "api/db/schema"
|
|
6
5
|
|
|
7
6
|
export default withWinterSpec({
|
|
8
7
|
methods: ["POST"],
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { withWinterSpec } from "
|
|
1
|
+
import { withWinterSpec } from "api/lib/with-winter-spec"
|
|
2
2
|
import { z } from "zod"
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { NotFoundError } from "edgespec/middleware"
|
|
6
|
-
import { ExportRequestSchema } from "src/db/schema"
|
|
7
|
-
import { file } from "bun"
|
|
3
|
+
import { NotFoundError } from "winterspec/middleware"
|
|
4
|
+
import { ExportRequestSchema } from "api/db/schema"
|
|
8
5
|
|
|
9
6
|
export default withWinterSpec({
|
|
10
7
|
methods: ["GET", "POST"],
|
|
@@ -14,7 +11,7 @@ export default withWinterSpec({
|
|
|
14
11
|
jsonResponse: z.object({
|
|
15
12
|
export_request: ExportRequestSchema.extend({
|
|
16
13
|
file_summary: z.array(
|
|
17
|
-
z.object({ file_name: z.string(), export_file_id: z.coerce.number() })
|
|
14
|
+
z.object({ file_name: z.string(), export_file_id: z.coerce.number() }),
|
|
18
15
|
),
|
|
19
16
|
}),
|
|
20
17
|
}),
|
|
@@ -33,7 +30,7 @@ export default withWinterSpec({
|
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
const export_files = (await ctx.db.list("export_file")).filter(
|
|
36
|
-
(ef) => ef.export_request_id === export_request_id
|
|
33
|
+
(ef) => ef.export_request_id === export_request_id,
|
|
37
34
|
)
|
|
38
35
|
ext_export_request.file_summary = export_files.map((ef) => ({
|
|
39
36
|
file_name: ef.file_name!,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { withWinterSpec } from "
|
|
1
|
+
import { withWinterSpec } from "api/lib/with-winter-spec"
|
|
2
2
|
import { z } from "zod"
|
|
3
|
-
import {
|
|
4
|
-
import { ExportRequestSchema } from "src/db/schema"
|
|
3
|
+
import { ExportRequestSchema } from "api/db/schema"
|
|
5
4
|
|
|
6
5
|
export default withWinterSpec({
|
|
7
6
|
methods: ["GET", "POST"],
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { withWinterSpec } from "
|
|
2
|
-
import { NotFoundError } from "
|
|
1
|
+
import { withWinterSpec } from "api/lib/with-winter-spec"
|
|
2
|
+
import { NotFoundError } from "winterspec/middleware"
|
|
3
3
|
import { z } from "zod"
|
|
4
|
-
import {
|
|
5
|
-
import { publicMapExportRequest } from "src/lib/public-mapping/public-map-export-request"
|
|
6
|
-
import { ExportRequestSchema } from "src/db/schema"
|
|
4
|
+
import { ExportRequestSchema } from "api/db/schema"
|
|
7
5
|
|
|
8
6
|
export default withWinterSpec({
|
|
9
7
|
methods: ["POST"],
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { PackageInfoSchema } from "
|
|
2
|
-
|
|
1
|
+
import { PackageInfoSchema } from "api/db/schema"
|
|
2
|
+
|
|
3
|
+
import { withWinterSpec } from "api/lib/with-winter-spec"
|
|
3
4
|
import { z } from "zod"
|
|
4
5
|
|
|
5
6
|
export default withWinterSpec({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { withWinterSpec } from "
|
|
1
|
+
import { withWinterSpec } from "api/lib/with-winter-spec"
|
|
2
2
|
import { z } from "zod"
|
|
3
3
|
|
|
4
4
|
export default withWinterSpec({
|
|
@@ -11,6 +11,6 @@ export default withWinterSpec({
|
|
|
11
11
|
headers: {
|
|
12
12
|
"content-type": "text/html",
|
|
13
13
|
},
|
|
14
|
-
}
|
|
14
|
+
},
|
|
15
15
|
)
|
|
16
16
|
})
|
|
@@ -3,10 +3,10 @@ import { Request as EdgeRuntimeRequest } from "@edge-runtime/primitives"
|
|
|
3
3
|
import { join } from "node:path"
|
|
4
4
|
|
|
5
5
|
const serverFetch = await createFetchHandlerFromDir(
|
|
6
|
-
join(import.meta.dir, "./routes")
|
|
6
|
+
join(import.meta.dir, "./routes"),
|
|
7
7
|
)
|
|
8
8
|
|
|
9
|
-
console.log("starting dev
|
|
9
|
+
console.log("starting dev server api on http://127.0.0.1:3021")
|
|
10
10
|
Bun.serve({
|
|
11
11
|
fetch: (bunReq) => {
|
|
12
12
|
const req = new EdgeRuntimeRequest(bunReq.url, {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
// import { WinterSpecRouteMap } from "@winterspec/types"
|
|
3
|
+
|
|
4
|
+
const routeMap = {
|
|
5
|
+
"/api/db/download": (await import('./routes/api/db/download.ts')).default,
|
|
6
|
+
"/api/dev_package_examples/create": (await import('./routes/api/dev_package_examples/create.ts')).default,
|
|
7
|
+
"/api/dev_package_examples/get": (await import('./routes/api/dev_package_examples/get.ts')).default,
|
|
8
|
+
"/api/dev_package_examples/list": (await import('./routes/api/dev_package_examples/list.ts')).default,
|
|
9
|
+
"/api/dev_package_examples/update": (await import('./routes/api/dev_package_examples/update.ts')).default,
|
|
10
|
+
"/api/dev_server/reset": (await import('./routes/api/dev_server/reset.ts')).default,
|
|
11
|
+
"/api/export_files/create": (await import('./routes/api/export_files/create.ts')).default,
|
|
12
|
+
"/api/export_files/download": (await import('./routes/api/export_files/download.ts')).default,
|
|
13
|
+
"/api/export_requests/create": (await import('./routes/api/export_requests/create.ts')).default,
|
|
14
|
+
"/api/export_requests/get": (await import('./routes/api/export_requests/get.ts')).default,
|
|
15
|
+
"/api/export_requests/list": (await import('./routes/api/export_requests/list.ts')).default,
|
|
16
|
+
"/api/export_requests/update": (await import('./routes/api/export_requests/update.ts')).default,
|
|
17
|
+
"/api/health": (await import('./routes/api/health.ts')).default,
|
|
18
|
+
"/api/package_info/create": (await import('./routes/api/package_info/create.ts')).default,
|
|
19
|
+
"/api/package_info/get": (await import('./routes/api/package_info/get.ts')).default,
|
|
20
|
+
"/health": (await import('./routes/health.ts')).default,
|
|
21
|
+
"/": (await import('./routes/index.ts')).default
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default routeMap
|
|
@@ -12,7 +12,8 @@ interface TestFixture {
|
|
|
12
12
|
export const getTestFixture = async (): Promise<TestFixture> => {
|
|
13
13
|
process.env.TSCI_DEV_SERVER_DB = tmpdir() + `/${Math.random()}` + "/devdb"
|
|
14
14
|
const port = 3001 + Math.floor(Math.random() * 999)
|
|
15
|
-
const
|
|
15
|
+
const testInstanceId = Math.random().toString(36).substring(2, 15)
|
|
16
|
+
const server = await startServer({ port })
|
|
16
17
|
const url = `http://127.0.0.1:${port}`
|
|
17
18
|
const axios = defaultAxios.create({
|
|
18
19
|
baseURL: url,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createFetchHandlerFromDir,
|
|
3
|
+
createWinterSpecBundleFromDir,
|
|
4
|
+
} from "winterspec/adapters/node"
|
|
5
|
+
import { Request as EdgeRuntimeRequest } from "@edge-runtime/primitives"
|
|
6
|
+
import { join } from "node:path"
|
|
7
|
+
import { ZodLevelDatabase } from "api/db/zod-level-db"
|
|
8
|
+
import os from "node:os"
|
|
9
|
+
import { Middleware } from "winterspec"
|
|
10
|
+
|
|
11
|
+
export const startServer = async ({ port }: { port: number }) => {
|
|
12
|
+
const db = new ZodLevelDatabase(os.tmpdir() + "/devdb")
|
|
13
|
+
|
|
14
|
+
const winterspecBundle = await createWinterSpecBundleFromDir(
|
|
15
|
+
join(import.meta.dir, "../../routes"),
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
const middleware: Middleware[] = [
|
|
19
|
+
async (req: any, ctx: any, next: any) => {
|
|
20
|
+
;(ctx as any).db = db
|
|
21
|
+
|
|
22
|
+
return next(req, ctx)
|
|
23
|
+
},
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
const server = Bun.serve({
|
|
27
|
+
fetch: (bunReq) => {
|
|
28
|
+
const req = new EdgeRuntimeRequest(bunReq.url, {
|
|
29
|
+
headers: bunReq.headers,
|
|
30
|
+
method: bunReq.method,
|
|
31
|
+
body: bunReq.body,
|
|
32
|
+
})
|
|
33
|
+
return winterspecBundle.makeRequest(req as any, {
|
|
34
|
+
middleware,
|
|
35
|
+
})
|
|
36
|
+
},
|
|
37
|
+
port,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
return server
|
|
41
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { it, expect } from "bun:test"
|
|
2
|
-
import { getTestFixture } from "tests/fixtures/get-test-server"
|
|
2
|
+
import { getTestFixture } from "api/tests/fixtures/get-test-server"
|
|
3
3
|
|
|
4
4
|
it("POST /api/dev_package_examples/create", async () => {
|
|
5
5
|
const { axios } = await getTestFixture()
|
|
@@ -14,6 +14,6 @@ it("POST /api/dev_package_examples/create", async () => {
|
|
|
14
14
|
.then((r) => r.data)
|
|
15
15
|
|
|
16
16
|
expect(res.dev_package_example.file_path).toEqual(
|
|
17
|
-
"examples/basic-resistor.tsx"
|
|
17
|
+
"examples/basic-resistor.tsx",
|
|
18
18
|
)
|
|
19
19
|
})
|