Deno support for deps.ts

Hi team! I´m trying Deno, and following one of their best practices, they recommend moving all the dependencies with a url or a npm prefix to a deps.ts file: https://deno.land/manual@v1.5.1/examples/manage_dependencies Given that the "xata codegen" tool generates the client code and builds something like:
import { buildClient } from "npm:@xata.io/client@latest";
import type {
BaseClientOptions,
SchemaInference,
XataRecord,
} from "npm:@xata.io/client@latest";
import { buildClient } from "npm:@xata.io/client@latest";
import type {
BaseClientOptions,
SchemaInference,
XataRecord,
} from "npm:@xata.io/client@latest";
Is there a recommended way to handle it, as we should not change generated code...
Deno
Manage Dependencies | Manual | Deno
In Deno there is no concept of a package manager as external modules are imported directly into local modules. This raises the question of how to manage remote dependencies without a package manager.
2 Replies
kostas
kostas2y ago
That's right, the src/xata.ts output shouldn't be edited as its content can be overwritten by next CLI actions. What about exporting the XataClient in the deps.ts file?
deps.ts

export {
XataClient
} from "./src/xata.ts";
deps.ts

export {
XataClient
} from "./src/xata.ts";
You could then call it in your code like in this example, with a custom getXataClient if options need to be passed to it https://xata.io/docs/typescript-client/configuration#configuration-overrides i.e.
import {
XataClient
} from "./deps.ts";

let instance: XataClient | undefined = undefined;

export const getXataClient = () => {

if (instance) return instance

instance = new XataClient({
databaseURL: "https://test-347b7r.eu-west-1.xata.sh/db/mydb1",
apiKey: "mykey",
})

return instance
}
import {
XataClient
} from "./deps.ts";

let instance: XataClient | undefined = undefined;

export const getXataClient = () => {

if (instance) return instance

instance = new XataClient({
databaseURL: "https://test-347b7r.eu-west-1.xata.sh/db/mydb1",
apiKey: "mykey",
})

return instance
}
Eusebio Trigo
Eusebio Trigo2y ago
Thanks! I'll built it through this approach!
Want results from more Discord servers?
Add your server