Skip to content

Instantly share code, notes, and snippets.

View arisris's full-sized avatar
👨‍🦱
Open to work

Aris Riswanto arisris

👨‍🦱
Open to work
View GitHub Profile
@arisris
arisris / kysely-table-prefixed.ts
Created November 2, 2023 14:18
Simple Kysely Plugins to prefix table name
import {
type KyselyPlugin,
type PluginTransformQueryArgs,
type RootOperationNode,
type PluginTransformResultArgs,
type QueryResult,
type UnknownRow,
OperationNodeTransformer,
TableNode,
} from "kysely";
@arisris
arisris / README.md
Last active March 28, 2023 15:09
save: @auth/core implementation in fresh framework

how to use it?

To resolve dependencies defined by @auth/core First you need to modify ./import_map.json and add this scope

{
  "imports": {...},
  "scopes": {
 ...
@arisris
arisris / session.ts
Last active March 4, 2023 12:50
Deno typed session
// deno-lint-ignore-file ban-ts-comment
import { Cookie, getCookies, setCookie } from "https://deno.land/std/http/mod.ts";
type Primitive = string | boolean | number | bigint | null;
type Primitives = Primitive | Record<string, Primitive> | Primitive[];
type PrimitivesRecord = { [x: string]: Primitives };
// deno-lint-ignore no-explicit-any
type TAny = any;
type BaseSession<
@arisris
arisris / jwt-session.ts
Created January 31, 2023 04:20
Hono Session JWT
// deno-lint-ignore-files
import { Context } from "hono/mod.ts";
import { Jwt } from "hono/utils/jwt/index.ts";
import { AlgorithmTypes } from "hono/utils/jwt/types.ts";
import { CookieOptions } from "hono/utils/cookie.ts";
import ms from "https://esm.sh/ms@2.1.3";
type Primitive = string | boolean | number | bigint | null;
type Primitives = Primitive | Record<string, Primitive> | Primitive[];
type PrimitivesRecord = Record<string, Primitives>;
@arisris
arisris / trpc-model.ts
Last active January 24, 2023 23:54
Safe call trpc procedure at serverside
import {
AnyProcedure,
AnyRouter,
inferRouterContext,
ProcedureArgs,
ProcedureType,
procedureTypes,
TRPCError,
} from "@trpc/server";
import { createRecursiveProxy } from "@trpc/server/shared";
@arisris
arisris / pgproxy.ts
Created January 5, 2023 15:12
Deno deploy Postgres proxy
import "https://deno.land/std@0.170.0/dotenv/load.ts";
import { parse } from "https://deno.land/std@0.170.0/flags/mod.ts";
import { serve, Status } from "https://deno.land/std@0.170.0/http/mod.ts";
import { Pool, PoolClient } from "https://deno.land/x/postgres@v0.17.0/mod.ts";
const args = parse(Deno.args, {
string: ["dsn", "port", "key"],
alias: { "d": "dsn", "p": "port", "k": "key" },
default: {
dsn: Deno.env.get("PG_DSN"),
@arisris
arisris / _seeder.ts
Last active January 2, 2023 15:11
Kysely & Deno postgres
import { hash } from "https://deno.land/x/bcrypt@v0.4.1/mod.ts";
import { Kysely } from "https://esm.sh/kysely@0.22.0";
export async function seed(db: Kysely<unknown>) {
const userAdmin = await db.selectFrom("users" as never).where(
"email",
"=",
"admin@example.net" as never,
).executeTakeFirst();
if (!userAdmin) {
@arisris
arisris / worker-router.ts
Created November 25, 2022 03:13
Simple Worker Router
interface ICtx {
readonly req: Request;
readonly params: Record<string, any>;
readonly env: Record<string, any>;
readonly executionContext: Record<string, any>;
}
type TExecResult = {
groups: Record<string, string>;
};
type THandler = (
@arisris
arisris / router.ts
Last active November 1, 2022 16:24
Simple Http Router Using JS Proxy Hack
export type TRouter<Value, Method extends string> =
& {
find: (method: Method, pathname: string) => TMatchedRoute<Value>;
}
& {
[k in Lowercase<Method>]: (
pathname: string,
...values: Value[]
) => TRouter<Value, Method>;
};
@arisris
arisris / react_test.md
Created October 31, 2022 06:19
React SSR Suspense fallback & streaming suport : Example Code
// file: react_test.ts
// it just for my note
import React from "https://esm.sh/react@18.2.0";
import ReactDomServer from "https://esm.sh/react-dom@18.2.0/server";
import { Handler, serve } from "https://deno.land/std@0.161.0/http/server.ts";

const Module = {
  default: () =>
    React.createElement("div", {