@tscircuit/cli 0.0.122 → 0.0.124
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/bun.lockb +0 -0
- package/dev-server-api/bun.lockb +0 -0
- package/dev-server-api/package.json +1 -1
- package/dev-server-api/routes/api/export_files/create.ts +2 -0
- package/dev-server-api/src/db/generic-json-level.ts +126 -0
- package/dev-server-api/src/db/zod-level-db.ts +8 -7
- package/dev-server-frontend/bun.lockb +0 -0
- package/dev-server-frontend/package-lock.json +4 -4
- package/dev-server-frontend/package.json +1 -1
- package/dist/cli.js +14 -10
- package/package.json +2 -2
package/bun.lockb
CHANGED
|
Binary file
|
package/dev-server-api/bun.lockb
CHANGED
|
Binary file
|
|
@@ -16,12 +16,14 @@ export default withWinterSpec({
|
|
|
16
16
|
}),
|
|
17
17
|
auth: "none",
|
|
18
18
|
})(async (req, ctx) => {
|
|
19
|
+
console.log("putting file")
|
|
19
20
|
const export_file = await ctx.db.put("export_file", {
|
|
20
21
|
export_request_id: req.jsonBody.export_request_id,
|
|
21
22
|
file_name: req.jsonBody.file_name,
|
|
22
23
|
file_content_base64: req.jsonBody.file_content_base64,
|
|
23
24
|
created_at: new Date().toISOString(),
|
|
24
25
|
})
|
|
26
|
+
console.log("done putting file")
|
|
25
27
|
|
|
26
28
|
return ctx.json({
|
|
27
29
|
export_file,
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AbstractLevel,
|
|
3
|
+
AbstractIterator,
|
|
4
|
+
AbstractKeyIterator,
|
|
5
|
+
AbstractValueIterator,
|
|
6
|
+
} from "abstract-level"
|
|
7
|
+
import { promises as fs } from "fs"
|
|
8
|
+
import path from "path"
|
|
9
|
+
|
|
10
|
+
interface JSONLevelOptions {}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* This is not totally tested yet, but is basically a NodeJS level that doesn't
|
|
14
|
+
* use C-bindings. It could be used as a replacement for memory-level to store
|
|
15
|
+
* to disk.
|
|
16
|
+
*/
|
|
17
|
+
class GenericJsonLevel extends AbstractLevel<string, any> {
|
|
18
|
+
private location: string
|
|
19
|
+
|
|
20
|
+
constructor(location: string, options?: JSONLevelOptions) {
|
|
21
|
+
super({ ...options, encodings: { utf8: true } })
|
|
22
|
+
this.location = location
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async _open(): Promise<void> {
|
|
26
|
+
await fs.mkdir(this.location, { recursive: true })
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async _put(key: string, value: any): Promise<void> {
|
|
30
|
+
const filePath = path.join(this.location, `${key}.json`)
|
|
31
|
+
console.log("writing file", filePath)
|
|
32
|
+
await fs.writeFile(filePath, JSON.stringify(value))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async _get(key: string): Promise<any> {
|
|
36
|
+
const filePath = path.join(this.location, `${key}.json`)
|
|
37
|
+
try {
|
|
38
|
+
const data = await fs.readFile(filePath, "utf8")
|
|
39
|
+
return JSON.parse(data)
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
42
|
+
throw new Error("NotFoundError")
|
|
43
|
+
}
|
|
44
|
+
throw error
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async _del(key: string): Promise<void> {
|
|
49
|
+
const filePath = path.join(this.location, `${key}.json`)
|
|
50
|
+
try {
|
|
51
|
+
await fs.unlink(filePath)
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
|
|
54
|
+
throw error
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async _batch(
|
|
60
|
+
operations: Array<{ type: "put" | "del"; key: string; value?: any }>
|
|
61
|
+
): Promise<void> {
|
|
62
|
+
for (const op of operations) {
|
|
63
|
+
if (op.type === "put") {
|
|
64
|
+
await this._put(op.key, op.value)
|
|
65
|
+
} else if (op.type === "del") {
|
|
66
|
+
await this._del(op.key)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async _clear(): Promise<void> {
|
|
72
|
+
const files = await fs.readdir(this.location)
|
|
73
|
+
for (const file of files) {
|
|
74
|
+
if (file.endsWith(".json")) {
|
|
75
|
+
await fs.unlink(path.join(this.location, file))
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
_iterator(): AbstractIterator<this, string, any> {
|
|
81
|
+
let files: string[] = []
|
|
82
|
+
let index = 0
|
|
83
|
+
|
|
84
|
+
const nextFile = async (): Promise<{ key: string; value: any } | null> => {
|
|
85
|
+
if (index >= files.length) {
|
|
86
|
+
return null
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const file = files[index++]
|
|
90
|
+
const key = path.basename(file, ".json")
|
|
91
|
+
const filePath = path.join(this.location, file)
|
|
92
|
+
const data = await fs.readFile(filePath, "utf8")
|
|
93
|
+
const value = JSON.parse(data)
|
|
94
|
+
|
|
95
|
+
return { key, value }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
async next() {
|
|
100
|
+
if (files.length === 0) {
|
|
101
|
+
files = (await fs.readdir(this.db.location)).filter((file) =>
|
|
102
|
+
file.endsWith(".json")
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const entry = await nextFile()
|
|
107
|
+
if (entry === null) {
|
|
108
|
+
return undefined
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return [entry.key, entry.value]
|
|
112
|
+
},
|
|
113
|
+
async seek(target: string) {
|
|
114
|
+
index = files.findIndex((file) => file.startsWith(target))
|
|
115
|
+
if (index === -1) {
|
|
116
|
+
index = files.length
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
async end() {
|
|
120
|
+
// No resources to clean up
|
|
121
|
+
},
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export { GenericJsonLevel }
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { Level } from "level"
|
|
1
|
+
// import { Level } from "level"
|
|
2
|
+
// import { GenericJsonLevel } from "./generic-json-level"
|
|
3
|
+
import { MemoryLevel } from "memory-level"
|
|
2
4
|
import { z } from "zod"
|
|
3
5
|
import { DBSchema, type DBSchemaType, type DBInputSchemaType } from "./schema"
|
|
4
6
|
|
|
5
7
|
// Create a wrapper class for Level with Zod validation
|
|
6
8
|
export class ZodLevelDatabase {
|
|
7
|
-
private db:
|
|
9
|
+
private db: MemoryLevel<string, any>
|
|
8
10
|
|
|
9
11
|
constructor(location: string) {
|
|
10
|
-
this.db = new
|
|
12
|
+
this.db = new MemoryLevel() // new GenericJsonLevel(location)
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
async open() {
|
|
@@ -35,11 +37,10 @@ export class ZodLevelDatabase {
|
|
|
35
37
|
const valueLoose: any = value
|
|
36
38
|
if (!valueLoose[idkey]) {
|
|
37
39
|
// generate an id using the "count" key
|
|
38
|
-
let count = await this.db
|
|
39
|
-
|
|
40
|
-
.catch(() => 1)
|
|
40
|
+
let count = await this.db.get(`${collection}.count`).catch(() => 1)
|
|
41
|
+
if (typeof count === "string") count = parseInt(count)
|
|
41
42
|
;(value as any)[idkey] = count
|
|
42
|
-
await this.db.put(`${collection}.count`, count + 1)
|
|
43
|
+
await this.db.put(`${collection}.count`, (count + 1).toString())
|
|
43
44
|
}
|
|
44
45
|
const key = `${collection}:${valueLoose[idkey]}`
|
|
45
46
|
const validatedData = DBSchema.shape[collection].parse(value)
|
|
Binary file
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@radix-ui/react-toggle": "^1.0.3",
|
|
23
23
|
"@radix-ui/react-toggle-group": "^1.0.4",
|
|
24
24
|
"@radix-ui/react-tooltip": "^1.0.7",
|
|
25
|
-
"@tscircuit/3d-viewer": "^0.0.
|
|
25
|
+
"@tscircuit/3d-viewer": "^0.0.8",
|
|
26
26
|
"@tscircuit/builder": "^1.5.134",
|
|
27
27
|
"@tscircuit/pcb-viewer": "^1.4.0",
|
|
28
28
|
"@tscircuit/schematic-viewer": "^1.2.14",
|
|
@@ -2655,9 +2655,9 @@
|
|
|
2655
2655
|
}
|
|
2656
2656
|
},
|
|
2657
2657
|
"node_modules/@tscircuit/3d-viewer": {
|
|
2658
|
-
"version": "0.0.
|
|
2659
|
-
"resolved": "https://registry.npmjs.org/@tscircuit/3d-viewer/-/3d-viewer-0.0.
|
|
2660
|
-
"integrity": "sha512-
|
|
2658
|
+
"version": "0.0.8",
|
|
2659
|
+
"resolved": "https://registry.npmjs.org/@tscircuit/3d-viewer/-/3d-viewer-0.0.8.tgz",
|
|
2660
|
+
"integrity": "sha512-6dYUz/33Pf9jvKEptyufLJw7obM61lFE9KWB+Yuy4X05S5Z83tMmihFBqZ1FU+V11FtJ+vefVk9OTdd//yBGgA==",
|
|
2661
2661
|
"dependencies": {
|
|
2662
2662
|
"@jscad/modeling": "^2.12.2",
|
|
2663
2663
|
"@jscad/regl-renderer": "^2.6.9",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@radix-ui/react-toggle": "^1.0.3",
|
|
31
31
|
"@radix-ui/react-toggle-group": "^1.0.4",
|
|
32
32
|
"@radix-ui/react-tooltip": "^1.0.7",
|
|
33
|
-
"@tscircuit/3d-viewer": "^0.0.
|
|
33
|
+
"@tscircuit/3d-viewer": "^0.0.8",
|
|
34
34
|
"@tscircuit/builder": "^1.5.134",
|
|
35
35
|
"@tscircuit/pcb-viewer": "^1.4.0",
|
|
36
36
|
"@tscircuit/schematic-viewer": "^1.2.14",
|