{"id":15822281,"url":"https://github.com/sambacha/dsn-parser","last_synced_at":"2025-04-01T06:52:12.911Z","repository":{"id":103231613,"uuid":"497749788","full_name":"sambacha/dsn-parser","owner":"sambacha","description":"Data Source Name Parser with reason responses semantically guaranteed and no leakage","archived":false,"fork":false,"pushed_at":"2023-08-24T11:21:42.000Z","size":182,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T23:44:20.682Z","etag":null,"topics":["data-source","data-source-name","dsn","dsn3","uri-encoding","web3"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sambacha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-05-30T01:20:34.000Z","updated_at":"2022-07-03T13:27:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"f84ebff0-8d51-4f25-8af2-484bd34ca0f1","html_url":"https://github.com/sambacha/dsn-parser","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fdsn-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fdsn-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fdsn-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fdsn-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sambacha","download_url":"https://codeload.github.com/sambacha/dsn-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246598198,"owners_count":20802975,"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":["data-source","data-source-name","dsn","dsn3","uri-encoding","web3"],"created_at":"2024-10-05T08:00:57.042Z","updated_at":"2025-04-01T06:52:12.895Z","avatar_url":"https://github.com/sambacha.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `data source name parser`\n\n## Overview\n\n- query params\n- validations\n- assertions \n\n### Validation\n\n`parseDsn` wraps its result in a [discriminated union](#) to enable the retrieval of validation errors. No `try... catch`needed and full typescript support.\n\n\nReason codes are guaranteed in semantic versions and messages does not leak credentials\n\n```typescript\nconst parsed = parseDsn(\"redis://localhost:65636\");\nassert.deepEqual(parsed, {\n  success: false,\n  reason: \"INVALID_PORT\",\n  message: \"Invalid port: 65636\",\n});\nif (!parsed.success) {\n  // `success: false` narrows the type to\n  // {\n  //   reason: 'PARSE_ERROR'|'INVALID_ARGUMENT'|...\n  //   message: string\n  // }\n  log(parsed.reason);\n}\n```\n\n| Reason               | Message                 | Comment         |\n| -------------------- | ----------------------- | --------------- |\n| `'PARSE_ERROR'`      | `Cannot parse DSN`      | _Regexp failed_ |\n| `'INVALID_ARGUMENT'` | `DSN must be a string`  |                 |\n| `'EMPTY_DSN'`        | `DSN cannot be empty`   |                 |\n| `'INVALID_PORT'`     | `Invalid port: ${port}` | [1-65535]       |\n\n\n\n## Usage\n\n```typescript\nimport { parseDsn } from 'dsnp';\n\nconst dsn = 'redis://user:p@/ss@localhost:6379/0?ssl=true''\n\nconst parsed = parseDsn(dsn);\n\nif (parsed.success) {\n  assert.deepEqual(parsed.value, {\n    driver: 'redis',\n    pass: 'p@/ss',\n    host: 'localhost',\n    user: 'user',\n    port: 6379,\n    db: '0',\n    params: {\n      ssl: true,\n    },\n  });\n} else {\n  assert.deepEqual(parsed, {\n    success: false,\n    // Reasons might vary\n    reason: 'INVALID_PORT',\n    message: 'Invalid http port: 12345678',\n  });\n}\n```\n\n\n| Params            | Type                   | Description                               |\n| ----------------- | ---------------------- | ----------------------------------------- |\n| `lowercaseDriver` | `\u003cboolean\u003e`            | Driver name in lowercase, default `false` |\n| `overrides`       | `DSN must be a string` |                                           |\n\n\n### Packaging\n\nGenerates a platform-dependant script used to register the custom URI handler 'dsn3:', which can be used to execute DSN3 from other applications.\n\n```python3\n#!/usr/bin/env python3\n'''\nGenerates a platform-dependant script used to register the custom URI handler 'dsn3:',\nwhich can be used to execute DSN3 from other applications.\n\nHow to use:\n- once the 'dsn3:' URI handler is registered, other applications can invoke DSN3\n- standard parameters MUST be URL-encoded and provided after the URI\n'''\n\nimport os\nimport platform\nimport sys\n\nn = platform.system()\ntext = None\noutname = None\n\nif n == 'Windows':\n  template = r'''Windows Registry Editor Version 5.00\n\n[HKEY_CURRENT_USER\\Software\\Classes\\dsn3]\n\"URL Protocol\"=\"\"\n@=\"URL:dsn3 protocol\"\n\n[HKEY_CURRENT_USER\\Software\\Classes\\dsn3\\DefaultIcon]\n@=\"dsn3.exe,1\"\n\n[HKEY_CURRENT_USER\\Software\\Classes\\dsn3\\shell]\n\n[HKEY_CURRENT_USER\\Software\\Classes\\dsn3\\shell\\open]\n\n[HKEY_CURRENT_USER\\Software\\Classes\\dsn3\\shell\\open\\command]\n@=\"\\\"%s\\\" \\\"%%1\\\"\"\n'''\n  path = os.path.abspath(os.getcwd() + r'\\..\\..\\dsn3_wincon.bat')\n  text = template % path.replace('\\\\', '\\\\\\\\')\n  outname = 'RegisterDsn3UriScheme.reg'\n\nelif n == 'Linux':\n  template = r'''#!/bin/sh\nset -uex\n\nif which xdg-mime \u003e /dev/null; then\n  DESKTOP_DIR=\"$HOME/.local/share/applications\"\n  DESKTOP_PATH=\"$DESKTOP_DIR/dsn3-opener.desktop\"\n\n  cat \u003c\u003c EOF \u003e \"$DESKTOP_PATH\"\n[Desktop Entry]\nType=Application\nName=DSN3 scheme handler\nExec=\"{dsn3_bin_path}\" %u\nStartupNotify=true\nMimeType=x-scheme-handler/dsn3;\nEOF\n\n  xdg-mime default \"$DESKTOP_PATH\" x-scheme-handler/dsn3\n  update-desktop-database \"$DESKTOP_DIR\"\nfi\n\nif which gconftool-2 \u003e /dev/null; then\n  gconftool-2 -t string -s /desktop/gnome/url-handlers/dsn3/command '\"{dsn3_bin_path}\" \"%s\"'\n  gconftool-2 -s /desktop/gnome/url-handlers/dsn3/needs_terminal false -t bool\n  gconftool-2 -s /desktop/gnome/url-handlers/dsn3/enabled true -t bool\nfi\n'''\n  path = os.path.abspath(os.getcwd() + r'/../../dsn3_linux.sh')\n  text = template.format(dsn3_bin_path=path)\n  outname = 'RegisterDsn3UriScheme.sh'\n\nelse:\n  print('Not implemented for platform %s!' % n)\n  sys.exit(-1)\n\nwith open(outname, 'w') as f:\n  f.write(text)\nprint('Execute the generated file %s to register the DSN3 URI scheme.' % outname)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsambacha%2Fdsn-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsambacha%2Fdsn-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsambacha%2Fdsn-parser/lists"}