{"id":20215000,"url":"https://github.com/maks11060/deno-libs","last_synced_at":"2025-03-03T11:17:31.970Z","repository":{"id":204572810,"uuid":"712141831","full_name":"MAKS11060/deno-libs","owner":"MAKS11060","description":"Useful TypeScript utilities","archived":false,"fork":false,"pushed_at":"2025-03-02T08:09:12.000Z","size":169,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-02T09:19:03.423Z","etag":null,"topics":["deno","typescript","utilities","web","webapi"],"latest_commit_sha":null,"homepage":"https://jsr.io/@maks11060","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MAKS11060.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-30T21:55:38.000Z","updated_at":"2025-03-02T08:09:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"7e857bc4-8da1-491f-be20-85239cecaeea","html_url":"https://github.com/MAKS11060/deno-libs","commit_stats":null,"previous_names":["maks11060/deno-libs"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAKS11060%2Fdeno-libs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAKS11060%2Fdeno-libs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAKS11060%2Fdeno-libs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAKS11060%2Fdeno-libs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MAKS11060","download_url":"https://codeload.github.com/MAKS11060/deno-libs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241652965,"owners_count":19997578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","typescript","utilities","web","webapi"],"created_at":"2024-11-14T06:19:15.691Z","updated_at":"2025-03-03T11:17:31.962Z","avatar_url":"https://github.com/MAKS11060.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Deno-libs\n\n[![JSR Score](https://jsr.io/badges/@maks11060)](https://jsr.io/@maks11060)\n\n| Package                          |                      Link                      |\n| -------------------------------- | :--------------------------------------------: |\n| [@maks11060/web][@maks11060/web] | [![JSR][@maks11060/web badge]][@maks11060/web] |\n| [@maks11060/kv][@maks11060/kv]   |  [![JSR][@maks11060/kv badge]][@maks11060/kv]  |\n\n[@maks11060/web]: https://jsr.io/@maks11060/web\n[@maks11060/kv]: https://jsr.io/@maks11060/kv\n\n[@maks11060/web badge]: https://jsr.io/badges/@maks11060/web\n[@maks11060/kv badge]: https://jsr.io/badges/@maks11060/kv\n\n\n## Install\n\n### Deno\n```ps\ndeno add jsr:@maks11060/web\n```\n### Other runtimes\n```ps\nnpx jsr add @maks11060/kv\n```\n```ps\npnpm dlx jsr add @maks11060/kv\n```\n\n## kv model example\n```ts\n#!/usr/bin/env -S deno run -A\n\nimport {kvProvider, printKV} from 'jsr:@maks11060/kv'\nimport {z} from 'npm:zod'\n\nconst kv = await Deno.openKv(':memory:')\nconst kvLib = kvProvider(kv)\n\nconst postSchema = z.object({\n  id: z.string(),\n  title: z.string().trim().max(256),\n  content: z.string().optional(),\n  tags: z.array(z.string()),\n})\n\nconst postModel = kvLib.model(postSchema, {\n  prefix: 'post',\n  primaryKey: 'id',\n  index: {\n    // create index 'tags'\n    tags: {\n      relation: 'many',\n      key: (post) =\u003e post.tags.map((v) =\u003e v.toLowerCase()),\n    },\n    // create index 'name'\n    name: {\n      relation: 'many',\n      key: (post) =\u003e post.title.toLowerCase(),\n    },\n  },\n})\n\n// Create post\nconst post1 = await postModel.create({title: 'Post 1', tags: ['dev', 'deno', 'backend']})\nconst post2 = await postModel.create({title: 'Post 2', tags: ['dev', 'node', 'backend']})\nconst post3 = await postModel.create({title: 'Post 3', tags: ['frontend', 'css', 'html', 'js']})\n\n// Get the latest post\nconst postList = await postModel.findMany({limit: 1, reverse: true})\n// [ {id: '01JMDGZ7YJ4ZECVF5ZVSE1S8PX', title: 'Post 3', tags: ['frontend', 'css', 'html', 'js']} ]\n\n// Get a post relative to the previous Post\nconst postListWithOffset = await postModel.findMany({\n  limit: 1,\n  reverse: true,\n  offset: postList[0].id, // post3 id\n})\n// [ {id: '01JMDHKV7353R802KS1WJV2JX1', title: 'Post 2', tags: ['dev', 'node', 'backend']} ]\n\n// Find a post ids by index\nconst postIdsByIndex = await postModel.findByIndex('tags', 'dev')\n// [ \"01JMDHH8J75B0GYX6XTZXZ5NG2\", \"01JMDHH8J8JMS27BA5M1EX4ARG\" ]\n\n// Find a post by index and resolve\nconst postsByIndex = await postModel.findByIndex('tags', 'dev', {resolve: true})\n// [\n//   {id: '01JMDHKV71N350W96TATF02P0H', title: 'Post 1', tags: ['dev', 'deno', 'backend']},\n//   {id: '01JMDHKV7353R802KS1WJV2JX1', title: 'Post 2', tags: ['dev', 'node', 'backend']},\n// ]\n\n// Update post\nawait postModel.update(\n  post3.id,\n  (val) =\u003e {\n    const currentTags = val.tags.filter((v) =\u003e v !== 'js')\n    currentTags.push('ts')\n    return {\n      tags: currentTags,\n    }\n  },\n  {force: true /* Allow override 'post' index */}\n)\nconst updatedPost3 = await postModel.find(post3.id)\n// {id: '01JMDGZ7YJ4ZECVF5ZVSE1S8PX', title: 'Post 3', tags: ['frontend', 'css', 'html', 'ts']}\n\n// View in the storage\n// await printKV(kv, ['post-tags']) // tags\nawait printKV(kv)\n```\n\n## Web\n```ts\nimport {createCachedFetch} from '@maks11060/web'\n\nconst fetch = await createCachedFetch({\n  name: 'cache-1',\n  ttl: 60 * 60 * 24, // 1 day\n  log: true,\n})\n```\n\n## wip/dev\n```ts\n// OAuth2\nimport {createGithubOauth2, oauth2Authorize, oauth2ExchangeCode} from 'https://raw.githubusercontent.com/MAKS11060/deno-libs/main/oauth2/mod.ts'\n\nconst config = createGithubOauth2({\n  clientId: Deno.env.get('GITHUB_CLIENT_ID')!,\n  clientSecret: Deno.env.get('GITHUB_CLIENT_SECRET')!,\n  redirectUri: Deno.env.get('OAUTH2_REDIRECT')!,\n})\nconst authorizeUri = oauth2Authorize(config, 'state-12345')\nconsole.log(authorizeUri.toString())\n\n\n// Hono helper\nimport {createHonoVar} from 'https://raw.githubusercontent.com/MAKS11060/deno-libs/main/hono/mod.ts'\nimport {Hono} from 'hono'\n\nconst vars = createHonoVar(async (c) =\u003e {\n  return {\n    data: 'text',\n    foo(data: string) {\n      console.log(data)\n      return data\n    }\n  }\n})\n\nconst app = new Hono()\n  .get('/test', vars, (c) =\u003e {\n    return c.text(c.var.foo('hello'))\n  })\n\n\n// Parser\nimport * as animego from 'https://raw.githubusercontent.com/MAKS11060/deno-libs/main/api/animego/animego.ts'\nimport * as hdrezka from 'https://raw.githubusercontent.com/MAKS11060/deno-libs/main/api/hdrezka/hdrezka.ts'\n\n\n// CLI\nimport {promptSelect, promptMultipleSelect} from 'https://raw.githubusercontent.com/MAKS11060/deno-libs/main/cli/prompt.ts'\n\n\n// Debugging\nimport {printBuf} from 'https://raw.githubusercontent.com/MAKS11060/deno-libs/main/debug/mod.ts'\n\nprintBuf(crypto.getRandomValues(new Uint8Array(40)))\n//       40 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15\n// 00000000 58 f7 65 1f 45 77 10 98 23 b7 60 c4 fa f8 fe a0\n// 00000010 2b 8c fd 3d fd 9c a5 d3 07 9b d5 70 48 95 67 aa\n// 00000020 d3 63 1c 4b a2 64 db 5d\n\n\n// Random utilities\nimport {weekCache} from 'https://raw.githubusercontent.com/MAKS11060/deno-libs/main/lib/mod.ts'\n\nconst authHook = useWeakCache((headers: Headers) =\u003e {\n  if (headers.get('authorization') == 'Bearer test') return true\n})\n\nconst ctx = {} // any object.\nconst headers = new Headers({'Authorization': 'Bearer test'})\nconsole.log(await authHook(ctx, headers))\nconsole.log(await authHook(ctx, headers)) // from cache\n\n\n// createModel old version\nimport {createModel} from 'https://raw.githubusercontent.com/MAKS11060/deno-libs/main/deno/mod.ts'\nimport z from 'zod'\n\nexport const kv = await Deno.openKv()\n\nexport const userSchema = z.object({\n  id: z.string().ulid(),\n  username: z.string().trim().min(2).max(64),\n  nickname: z.string().trim().min(2).max(64),\n  email: z.string().trim().min(3).max(320).email().optional(),\n})\nexport const userModel = createModel(kv, userSchema, {\n  prefix: 'user',\n  primaryKey: 'id',\n  secondaryKeys: ['username', 'email'],\n  indexOptions: {\n    username: {\n      transform: (val) =\u003e val.toLowerCase(),\n    },\n  },\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaks11060%2Fdeno-libs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaks11060%2Fdeno-libs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaks11060%2Fdeno-libs/lists"}