1599213900
Graphviz library for Deno 🦕
Runtime independent APIs and specifications are compatible with the ts-graphviz package.
renderDot
function outputs the dot command execution result to the specified path by supplying diagram object.
renderDot
function requiresallow-write
,allow-run
permission, and dot command.
import * as path from "https://deno.land/std@0.67.0/path/mod.ts";
import { digraph, attribute, renderDot } from "https://deno.land/x/graphviz/mod.ts";
const G = digraph("G", (g) => {
const a = g.node("aa");
const b = g.node("bb");
const c = g.node("cc");
g.edge([a, b, c], {
[attribute.color]: "red",
});
g.subgraph("A", (A) => {
const Aa = A.node("Aaa", {
[attribute.color]: "pink",
});
const Ab = A.node("Abb", {
[attribute.color]: "violet",
});
const Ac = A.node("Acc");
A.edge([Aa.port({ compass: "c" }), Ab, Ac, "E"], {
[attribute.color]: "red",
});
});
});
const __dirname = new URL(".", import.meta.url).pathname;
await renderDot(G, path.resolve(__dirname, "./example.svg"), {
format: "svg",
});
Convert the diagram object to dot format with toDot function.
import { digraph, toDot } from "https://deno.land/x/graphviz/mod.ts";
const g = digraph("G");
const subgraphA = g.createSubgraph("A");
const nodeA1 = subgraphA.createNode("A_node1");
const nodeA2 = subgraphA.createNode("A_node2");
subgraphA.createEdge([nodeA1, nodeA2]);
const subgraphB = g.createSubgraph("B");
const nodeB1 = subgraphB.createNode("B_node1");
const nodeB2 = subgraphB.createNode("B_node2");
subgraphA.createEdge([nodeB1, nodeB2]);
const node1 = g.createNode("node1");
const node2 = g.createNode("node2");
g.createEdge([node1, node2]);
const dot = toDot(g);
console.log(dot);
digraph "G" {
"node1";
"node2";
subgraph "A" {
"A_node1";
"A_node2";
"A_node1" -> "A_node2";
"B_node1" -> "B_node2";
}
subgraph "B" {
"B_node1";
"B_node2";
}
"node1" -> "node2";
}
Author: ts-graphviz
Demo: https://deno.land/x/graphviz@v0.2.1
Source Code: https://github.com/ts-graphviz/deno
#deno #nodejs #node #javascript
1599213900
Graphviz library for Deno 🦕
Runtime independent APIs and specifications are compatible with the ts-graphviz package.
renderDot
function outputs the dot command execution result to the specified path by supplying diagram object.
renderDot
function requiresallow-write
,allow-run
permission, and dot command.
import * as path from "https://deno.land/std@0.67.0/path/mod.ts";
import { digraph, attribute, renderDot } from "https://deno.land/x/graphviz/mod.ts";
const G = digraph("G", (g) => {
const a = g.node("aa");
const b = g.node("bb");
const c = g.node("cc");
g.edge([a, b, c], {
[attribute.color]: "red",
});
g.subgraph("A", (A) => {
const Aa = A.node("Aaa", {
[attribute.color]: "pink",
});
const Ab = A.node("Abb", {
[attribute.color]: "violet",
});
const Ac = A.node("Acc");
A.edge([Aa.port({ compass: "c" }), Ab, Ac, "E"], {
[attribute.color]: "red",
});
});
});
const __dirname = new URL(".", import.meta.url).pathname;
await renderDot(G, path.resolve(__dirname, "./example.svg"), {
format: "svg",
});
Convert the diagram object to dot format with toDot function.
import { digraph, toDot } from "https://deno.land/x/graphviz/mod.ts";
const g = digraph("G");
const subgraphA = g.createSubgraph("A");
const nodeA1 = subgraphA.createNode("A_node1");
const nodeA2 = subgraphA.createNode("A_node2");
subgraphA.createEdge([nodeA1, nodeA2]);
const subgraphB = g.createSubgraph("B");
const nodeB1 = subgraphB.createNode("B_node1");
const nodeB2 = subgraphB.createNode("B_node2");
subgraphA.createEdge([nodeB1, nodeB2]);
const node1 = g.createNode("node1");
const node2 = g.createNode("node2");
g.createEdge([node1, node2]);
const dot = toDot(g);
console.log(dot);
digraph "G" {
"node1";
"node2";
subgraph "A" {
"A_node1";
"A_node2";
"A_node1" -> "A_node2";
"B_node1" -> "B_node2";
}
subgraph "B" {
"B_node1";
"B_node2";
}
"node1" -> "node2";
}
Author: ts-graphviz
Demo: https://deno.land/x/graphviz@v0.2.1
Source Code: https://github.com/ts-graphviz/deno
#deno #nodejs #node #javascript
1597865220
🦕 A simple WebSocket library like ws of node.js library for deno
Server side
$ deno run --allow-net https://deno.land/x/websocket@v0.0.3/example/server.ts
Client side
$ deno run --allow-net https://deno.land/x/websocket@v0.0.3/example/client.ts
ws connected! (type 'close' to quit)
> something
Server side
import { WebSocket, WebSocketServer } from "https://deno.land/x/websocket@v0.0.3/mod.ts";
const wss = new WebSocketServer(8080);
wss.on("connection", function (ws: WebSocket) {
ws.on("message", function (message: string) {
console.log(message);
ws.send(message)
});
});
Client side
import { WebSocket } from "https://deno.land/x/websocket@v0.0.3/mod.ts";
const endpoint = "ws://127.0.0.1:8080";
const ws: WebSocket = new WebSocket(endpoint);
ws.on("open", function() {
console.log("ws connected!");
});
ws.on("message", function (message: string) {
console.log(message);
});
ws.send("something");
event | detail |
---|---|
connection | Emitted when the handshake is complete |
error | Emitted when an error occurs |
field | detail | type |
---|---|---|
server.clients | A set that stores all connected clients | Set<WebSocket> |
method | detail |
---|---|
close() | Close the server |
event | detail |
---|---|
open | Emitted when the connection is established |
close | Emitted when the connection is closed |
message | Emitted when a message is received from the server |
ping | Emitted when a ping is received from the server |
pong | Emitted when a pong is received from the server |
error | Emitted when an error occurs |
field | detail | type |
---|---|---|
websocket.isClose | Get the close flag | Boolean |
method | detail |
---|---|
send(message:string | Unit8Array) |
ping(message:string | Unit8Array) |
close([code:int[, reason:string]]) | Close the connection with the server |
forceClose() | Forcibly close the connection with the server |
Author: ryo-ma
Demo: https://deno.land/x/websocket@v0.0.3
Source Code: https://github.com/ryo-ma/deno-websocket
#deno #node #nodejs #javascript
1625629740
In this tutorial, we’ll be talking about what a library is and how they are useful. We will be looking at some examples in C, including the C Standard I/O Library and the C Standard Math Library, but these concepts can be applied to many different languages. Thank you for watching and happy coding!
Need some new tech gadgets or a new charger? Buy from my Amazon Storefront https://www.amazon.com/shop/blondiebytes
Also check out…
What is a Framework? https://youtu.be/HXqBlAywTjU
What is a JSON Object? https://youtu.be/nlYiOcMNzyQ
What is an API? https://youtu.be/T74OdSCBJfw
What are API Keys? https://youtu.be/1yFggyk--Zo
Using APIs with Postman https://youtu.be/0LFKxiATLNQ
Check out my courses on LinkedIn Learning!
REFERRAL CODE: https://linkedin-learning.pxf.io/blondiebytes
https://www.linkedin.com/learning/instructors/kathryn-hodge
Support me on Patreon!
https://www.patreon.com/blondiebytes
Check out my Python Basics course on Highbrow!
https://gohighbrow.com/portfolio/python-basics/
Check out behind-the-scenes and more tech tips on my Instagram!
https://instagram.com/blondiebytes/
Free HACKATHON MODE playlist:
https://open.spotify.com/user/12124758083/playlist/6cuse5033woPHT2wf9NdDa?si=VFe9mYuGSP6SUoj8JBYuwg
MY FAVORITE THINGS:
Stitch Fix Invite Code: https://www.stitchfix.com/referral/10013108?sod=w&som=c
FabFitFun Invite Code: http://xo.fff.me/h9-GH
Uber Invite Code: kathrynh1277ue
Postmates Invite Code: 7373F
SoulCycle Invite Code: https://www.soul-cycle.com/r/WY3DlxF0/
Rent The Runway: https://rtr.app.link/e/rfHlXRUZuO
Want to BINGE?? Check out these playlists…
Quick Code Tutorials: https://www.youtube.com/watch?v=4K4QhIAfGKY&index=1&list=PLcLMSci1ZoPu9ryGJvDDuunVMjwKhDpkB
Command Line: https://www.youtube.com/watch?v=Jm8-UFf8IMg&index=1&list=PLcLMSci1ZoPvbvAIn_tuSzMgF1c7VVJ6e
30 Days of Code: https://www.youtube.com/watch?v=K5WxmFfIWbo&index=2&list=PLcLMSci1ZoPs6jV0O3LBJwChjRon3lE1F
Intermediate Web Dev Tutorials: https://www.youtube.com/watch?v=LFa9fnQGb3g&index=1&list=PLcLMSci1ZoPubx8doMzttR2ROIl4uzQbK
GitHub | https://github.com/blondiebytes
Twitter | https://twitter.com/blondiebytes
LinkedIn | https://www.linkedin.com/in/blondiebytes
#blondiebytes #c library #code tutorial #library
1605127860
dso
is a simple ORM Library based on deno_mysql
import {
BaseModel,
Defaults,
dso,
Field,
FieldType,
CharsetType,
Index,
IndexType,
Join,
Model,
Where
} from "https://deno.land/x/dso@v1.0.0/mod.ts";
// Define a database model
@Model("users")
class UserModel extends BaseModel {
// Character set for whole table. UTF-8 is default and is not necessary to define.
charset: CharsetType.utf8;
// The ! operator is needed for primary key since it's never null
@Field({
type: FieldType.INT,
primary: true,
length: 11,
autoIncrement: true
})
id: number;
@Field({ type: FieldType.STRING, length: 30 })
name: string;
@Field({ type: FieldType.STRING, length: 30 })
password: string;
// Charset can be explicitly defined for each column.
@Field({ type: FieldType.STRING, length: 60, charset: CharsetType.utf8mb4 })
namespace: string;
// Index can be created [index/unique/spatial/fulltext] for each field
@Field({ type: FieldType.STRING, length: 30, unique: true })
email: string;
// Multi column index can be defined by decorated @Index
@Index({ type: IndexType.UNIQUE, columns: ["username","namespace"] })
public myUniqueIndex!: Index;
}
const userModel = dso.define(UserModel);
async function main() {
// The database must be created before linking
await dso.connect({
hostname: "127.0.0.1",
port: 3306,
username: "root",
password: "",
db: "dbname"
});
/*
When installing or initializing a database,
you can use dso.sync to synchronize the database model to the database.
Use false as the parameter if you want to sync only newly added models,
Use true as the parameter if you want to sync the whole defined models
to the database tables.
== WARNING! ==
Using true as the parameter will reset your whole database! Use with caution.
*/
await dso.sync(false);
// You can add records using insert method
const insertId = await userModel.insert({
name: "user1",
password: "password"
});
// You can use the Model.findById method to get a record
const user = await userModel.findById(1);
// You can use Where clause too to get a record. For more information on
// clauses such as join, order, etc. please consult:
// https://github.com/manyuanrong/sql-builder
// findOne + Where
const userWhere = await userModel.findOne(Where.from({ name: "user1" }));
// findAll + Where
const userAll = await userModel.findAll(Where.from({ name: "user1" }));
// findAll + expr like
const userLike = await userModel.findAll(Where.expr("name like 'user%'"));
console.log("Found user by id:", user);
console.log("Found user by where eq clause:", userWhere);
console.log("All users by where eq clause:", userAll);
console.log("All users by where like clause:", userLike);
console.log("User has these columns in index:", user.myUniqueIndex.columns);
}
main();
Since this library needs to use Typescript Decorators and other features, a custom tsconfig.json
needs to be added. Example config file can be found here, or just copy the contents below and create a new tsconfig.json
file in your root directory.
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "esnext",
"isolatedModules": false
}
}
To run, use:
deno run --allow-net -c tsconfig.json main.ts
where main.ts
is your Typescript file for Deno.
Set whether query debugging information is displayed
dso.showQueryLog = true;
You need to use this method to link to the database before you can manipulate the database
await dso.connect({
hostname: "127.0.0.1", // database hostname
port: 3306, // database port
username: "root", // database username
password: "", // database password
db: "dbname" // database name. (tips: The database must be created before linking)
});
Add an annotated Model
instance and return the instance.
@Model("users")
class UserModel extends BaseModel {
@Field({
type: FieldType.INT,
primary: true,
length: 11,
autoIncrement: true
})
id!: number;
@Field({ type: FieldType.STRING, length: 30 })
name?: string;
@Field({ type: FieldType.STRING, length: 30 })
password: string;
@Field({
type: FieldType.STRING,
unique: true,
length: 20})
phoneNumber?: string;
}
}
export default const userModel = dso.define(UserModel);
// userModel.findById(...)
// userModel.findAll(...)
// userModel.findOne(...)
// userModel.insert(...)
// userModel.update(...)
// userModel.delete(...)
When installing or initializing a database, you can use sync to synchronize the database model to the database.
// If set to FORCE, tables will be deleted before they are created,
// otherwise only new models will be synchronized.
const force = true; // force
await dso.sync(force);
Create and start a transaction.
New Model
instances must be obtained through getModel(Model)
. Otherwise, it will not be controlled by transactions.
const result = await dso.transaction<boolean>(async trans => {
const userModel = trans.getModel(UserModel);
const topicModel = trans.getModel(TopicModel);
userId = await userModel.insert({ nickName: "foo", password: "bar", phoneNumber: "08135539123" });
topicId = await topicModel.insert({ title: "zoo", userId });
return true;
});
DATE
INT
TEXT
STRING
BOOLEAN
Field type describes the following properties of a field
key | type | default value | desc |
---|---|---|---|
type | one of the FieldTypes | null | types of database fields |
length | number | unfixed | field length |
primary | boolean | false | database primary key? |
default | any | null | default values for fields |
autoIncrement | boolean | false | identify auto-increment fields. It can only be used for INT types |
notNull | boolean | false | identity fields can not be null |
autoUpdate | boolean | false | updated automatically according to the current timestamp. It can only be used for DATE types |
unique | boolean | false | database unique index? |
spatial | boolean | false | database spatial index? |
fullText | boolean | false | database fullText index? |
index | boolean | false | database non unique index? |
Following types of an index are available
key | multi column |
---|---|
index | true |
unique | true |
spatial | false |
fulltext | true |
list of valid character sets is based on https://dev.mysql.com/doc/refman/8.0/en/charset-charsets.html
Author: manyuanrong
Source Code: https://github.com/manyuanrong/dso
#deno #node #nodejs #javascript
1597966500
Simple desired state configuration library for deno
. Inspired by Powershell DSC.
When you need to get your system into desired state. Quickly, reliably, repeatedly. You can use Ansible, Puppet, Powershell or something else. But this is simple and you can use JavaScript/TypeScript. Deno
is the only runtime dependency.
I have built this to spin up my development machine using my dotfiles.
Based on your configuration the library build a dependency graph and executes everything missing in right order. Every configuration is first tested and only executed, when the test does not pass. Therefore it is idempotent - you can start it multiple times without worries.
Add configuration type and implement the resource
export interface LoginShellConfig extends Config {
shell: "zsh";
}
export const LoginShell: Resource<LoginShellConfig> = {
name: "loginShell",
get: (config) => {
//...
},
test: async (config, verbose) => {
//...
},
set: async (config, verbose) => {
//...
}
};
Add to list of types of resources
type MyResources = Resources | Resource<LoginShellConfig>;
Registr the new resource
registerResource(LoginShell);
Author: lttr
Source Code: https://github.com/lttr/deno-dsc
#deno #nodejs #javascript #node