weave-typescript
v0.11.4
Published
TypeScript bindings for the Weave platform. The package ships generated protobuf message types, gRPC service clients, and Postgres query helpers so applications can talk to Weave services and databases from Node.js and modern TypeScript runtimes.
Downloads
721
Readme
weave-typescript
TypeScript bindings for the Weave platform. The package ships generated protobuf message types, gRPC service clients, and Postgres query helpers so applications can talk to Weave services and databases from Node.js and modern TypeScript runtimes.
- gRPC-ready service clients produced from Buf-managed protobuf definitions.
- Strongly-typed SQL helpers generated with
sqlcfor the WeaveSQL datasets.
Installation
pnpm add weave-typescript
# or
npm install weave-typescript
# or
yarn add weave-typescriptThe package includes runtime dependencies on @grpc/grpc-js, @bufbuild/protobuf, and pg; no extra installs are
required when using the default export.
Quick start
import { credentials } from "@grpc/grpc-js";
import { auth } from "weave-typescript";
const client = new auth.AuthClient(
"api.weave.com:443",
credentials.createSsl()
);
client.initiateOAuth(
{
provider: "github",
redirectUri: "https://example.com/oauth/callback",
state: "csrf-token",
scope: "openid profile email",
providerParams: {},
},
(err, response) => {
if (err) throw err;
console.log(response.authUrl);
}
);Every protobuf module under src/weaveapi/** is re-exported from the root package. Service namespaces expose message
types, client constructors, and server implementations that the @grpc/grpc-js ecosystem expects.
Query helpers for WeaveSQL
import { Client } from "pg";
import { getModel } from "weave-typescript/weavesql/llmxdb/models_sql";
const client = new Client({ connectionString: process.env.DATABASE_URL });
await client.connect();
const row = await getModel(client, { slug: "weave/sonnet-3" });
if (!row) {
console.log("model not found");
} else {
console.log(row.name, row.capabilities);
}Each helper follows the sqlc convention: the exported SQL text constants match the query names while the functions
perform typed marshalling to and from pg array results. When you regenerate SQL code, the TypeScript bindings stay in
sync with new database migrations.
Development
pnpm install # install dependencies
pnpm build # emit dist/ with JS and type declarations
pnpm test # run sqlc generator unit tests (tools/sqlcgen.test.js)
pnpm generate # rebuild src/index.ts barrel exports
pnpm generate:sqlc-config --schema ../schema/weavesql
# regenerate sqlc.yaml for local schemasRegenerating protobuf clients
- Sync the
schema/directory (or point Buf at the shared schema checkout). - Run
buf generate(Buf picks upbuf.gen.yamland writes intosrc/). - Execute
pnpm generateto rebuild the barrel exports. - Re-run
pnpm buildsodist/reflects the new artifacts.
SQL code generation
The tools/sqlcgen.js utility scans schema/weavesql/** (or the directory passed via --schema) and writes an
sqlc.yaml that targets the TypeScript sqlc plugin. Regenerate it before running sqlc generate so new databases or
query directories are included.
Contributing
Follow the project coding guidelines in CODE_STYLE.md, prefer small focused commits, and keep generated artifacts out
of Git history unless they are part of a release. Pull requests should include regenerated protobufs/SQL bindings when
schemas change and cover the relevant tooling scripts with tests where practical.
