weave-typescript 0.10.12 → 0.10.14
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/README.md +102 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# weave-typescript
|
|
2
|
+
|
|
3
|
+
TypeScript bindings for the Weave platform. The package ships generated protobuf message types, gRPC service clients,
|
|
4
|
+
and Postgres query helpers so applications can talk to Weave services and databases from Node.js and modern TypeScript
|
|
5
|
+
runtimes.
|
|
6
|
+
|
|
7
|
+
- gRPC-ready service clients produced from Buf-managed protobuf definitions.
|
|
8
|
+
- Strongly-typed SQL helpers generated with `sqlc` for the WeaveSQL datasets.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add weave-typescript
|
|
14
|
+
# or
|
|
15
|
+
npm install weave-typescript
|
|
16
|
+
# or
|
|
17
|
+
yarn add weave-typescript
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The package includes runtime dependencies on `@grpc/grpc-js`, `@bufbuild/protobuf`, and `pg`; no extra installs are
|
|
21
|
+
required when using the default export.
|
|
22
|
+
|
|
23
|
+
## Quick start
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { credentials } from "@grpc/grpc-js";
|
|
27
|
+
import { auth } from "weave-typescript";
|
|
28
|
+
|
|
29
|
+
const client = new auth.AuthClient(
|
|
30
|
+
"api.weave.com:443",
|
|
31
|
+
credentials.createSsl()
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
client.initiateOAuth(
|
|
35
|
+
{
|
|
36
|
+
provider: "github",
|
|
37
|
+
redirectUri: "https://example.com/oauth/callback",
|
|
38
|
+
state: "csrf-token",
|
|
39
|
+
scope: "openid profile email",
|
|
40
|
+
providerParams: {},
|
|
41
|
+
},
|
|
42
|
+
(err, response) => {
|
|
43
|
+
if (err) throw err;
|
|
44
|
+
console.log(response.authUrl);
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Every protobuf module under `src/weaveapi/**` is re-exported from the root package. Service namespaces expose message
|
|
50
|
+
types, client constructors, and server implementations that the `@grpc/grpc-js` ecosystem expects.
|
|
51
|
+
|
|
52
|
+
## Query helpers for WeaveSQL
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { Client } from "pg";
|
|
56
|
+
import { getModel } from "weave-typescript/weavesql/llmxdb/models_sql";
|
|
57
|
+
|
|
58
|
+
const client = new Client({ connectionString: process.env.DATABASE_URL });
|
|
59
|
+
await client.connect();
|
|
60
|
+
|
|
61
|
+
const row = await getModel(client, { slug: "weave/sonnet-3" });
|
|
62
|
+
if (!row) {
|
|
63
|
+
console.log("model not found");
|
|
64
|
+
} else {
|
|
65
|
+
console.log(row.name, row.capabilities);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Each helper follows the `sqlc` convention: the exported SQL text constants match the query names while the functions
|
|
70
|
+
perform typed marshalling to and from `pg` array results. When you regenerate SQL code, the TypeScript bindings stay in
|
|
71
|
+
sync with new database migrations.
|
|
72
|
+
|
|
73
|
+
## Development
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pnpm install # install dependencies
|
|
77
|
+
pnpm build # emit dist/ with JS and type declarations
|
|
78
|
+
pnpm test # run sqlc generator unit tests (tools/sqlcgen.test.js)
|
|
79
|
+
pnpm generate # rebuild src/index.ts barrel exports
|
|
80
|
+
pnpm generate:sqlc-config --schema ../schema/weavesql
|
|
81
|
+
# regenerate sqlc.yaml for local schemas
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Regenerating protobuf clients
|
|
85
|
+
|
|
86
|
+
1. Sync the `schema/` directory (or point Buf at the shared schema checkout).
|
|
87
|
+
2. Run `buf generate` (Buf picks up `buf.gen.yaml` and writes into `src/`).
|
|
88
|
+
3. Execute `pnpm generate` to rebuild the barrel exports.
|
|
89
|
+
4. Re-run `pnpm build` so `dist/` reflects the new artifacts.
|
|
90
|
+
|
|
91
|
+
### SQL code generation
|
|
92
|
+
|
|
93
|
+
The `tools/sqlcgen.js` utility scans `schema/weavesql/**` (or the directory passed via `--schema`) and writes an
|
|
94
|
+
`sqlc.yaml` that targets the TypeScript `sqlc` plugin. Regenerate it before running `sqlc generate` so new databases or
|
|
95
|
+
query directories are included.
|
|
96
|
+
|
|
97
|
+
## Contributing
|
|
98
|
+
|
|
99
|
+
Follow the project coding guidelines in `CODE_STYLE.md`, prefer small focused commits, and keep generated artifacts out
|
|
100
|
+
of Git history unless they are part of a release. Pull requests should include regenerated protobufs/SQL bindings when
|
|
101
|
+
schemas change and cover the relevant tooling scripts with tests where practical.
|
|
102
|
+
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weave-typescript",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.14",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist/**/*"
|
|
8
8
|
],
|
|
9
9
|
"author": "weave-labs",
|
|
10
|
-
"license": "
|
|
10
|
+
"license": "FCL-1.0-ALv2",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@bufbuild/protobuf": "^2.4.0",
|
|
13
13
|
"@grpc/grpc-js": "^1.13.4",
|