From 1d7a49ced13b7a97ec8ea53114ccad899f9d74f3 Mon Sep 17 00:00:00 2001 From: James Brumond Date: Sun, 20 Aug 2023 20:13:43 -0700 Subject: [PATCH] add some id and http types --- .gitea/workflows/pubilsh.yaml | 4 ++-- package.json | 6 +++--- readme.md | 38 ++++++++++++++++++----------------- src/http.d.ts | 20 ++++++++++++++++++ src/identifiers.d.ts | 6 ++++++ src/index.d.ts | 4 +++- src/logger.d.ts | 19 ++++++++++++++++++ 7 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 src/http.d.ts create mode 100644 src/identifiers.d.ts create mode 100644 src/logger.d.ts diff --git a/.gitea/workflows/pubilsh.yaml b/.gitea/workflows/pubilsh.yaml index d155937..efd6a14 100644 --- a/.gitea/workflows/pubilsh.yaml +++ b/.gitea/workflows/pubilsh.yaml @@ -23,8 +23,8 @@ jobs: - name: Login to package registry run: | - npm config set @:registry https://gitea.jbrumond.me/api/packages//npm/ - npm config set -- '//gitea.jbrumond.me/api/packages//npm/:_authToken' "$NPM_PUBLISH_TOKEN" + npm config set @js:registry https://gitea.jbrumond.me/api/packages/js/npm/ + npm config set -- '//gitea.jbrumond.me/api/packages/js/npm/:_authToken' "$NPM_PUBLISH_TOKEN" - name: Publish package run: npm publish diff --git a/package.json b/package.json index d25f3d1..a58caf2 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,15 @@ { - "name": "@templates/typescript-types", + "name": "@js/types", "version": "1.0.0", "description": "Template project for creating new TypeScript type-definition-only packages", "main": "src/index.d.ts", "types": "src/index.d.ts", "publishConfig": { - "registry": "https://gitea.jbrumond.me/api/packages/templates/npm/" + "registry": "https://gitea.jbrumond.me/api/packages/js/npm/" }, "repository": { "type": "git", - "url": "https://gitea.jbrumond.me/templates/typescript-types.git" + "url": "https://gitea.jbrumond.me/js/typescript-types.git" }, "author": "James Brumond ", "license": "ISC", diff --git a/readme.md b/readme.md index 47e4ca3..3523406 100644 --- a/readme.md +++ b/readme.md @@ -1,27 +1,29 @@ -Template project for creating new TypeScript type-definition-only packages - ---- - -## Get Started - -### Pull down the code +Collection of general-purpose type definitions ```bash -git init -git pull https://gitea.jbrumond.me/templates/typescript-types.git master +# Update project npm config to refer to correct registry for the @js scope +echo '@js:registry=https://gitea.jbrumond.me/api/packages/js/npm/' >> ./.npmrc + +npm install --save-dev @js/types ``` -### Update configuration - -- In `package.json`, update any fields like `name`, `description`, `repository`, etc. - - - -## Building - -No build step is necessary, as the types are written directly as `.d.ts` files to begin with. +## Types +```ts +import { + // Various identifier strings + HttpURL, + UUID, + SnowflakeID, + // HTTP verbs + HttpVerb, + HttpVerbExtended, + // Pino-compatible logger interface + Logger, + LogFn, +} from '@js/types'; +``` diff --git a/src/http.d.ts b/src/http.d.ts new file mode 100644 index 0000000..d91379f --- /dev/null +++ b/src/http.d.ts @@ -0,0 +1,20 @@ + +/** */ +export type HttpVerb + = 'GET' + | 'HEAD' + | 'POST' + | 'PUT' + | 'DELETE' + | 'OPTIONS' + ; + +/** */ +export type HttpVerbExtended + = HttpVerb + | 'PATCH' + | 'QUERY' + | 'CONNECT' + | 'TRACE' + ; + diff --git a/src/identifiers.d.ts b/src/identifiers.d.ts new file mode 100644 index 0000000..7e0d388 --- /dev/null +++ b/src/identifiers.d.ts @@ -0,0 +1,6 @@ + +export type HttpURL = `http://${string}` | `https://${string}`; + +export type UUID = `${string}-${string}-${string}-${string}-${string}`; + +export type SnowflakeID = `${bigint}`; diff --git a/src/index.d.ts b/src/index.d.ts index 1fe032c..aa0cc5a 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,2 +1,4 @@ -export function hello() : string; +export * from './http'; +export * from './identifiers'; +export * from './logger'; diff --git a/src/logger.d.ts b/src/logger.d.ts new file mode 100644 index 0000000..6fafd08 --- /dev/null +++ b/src/logger.d.ts @@ -0,0 +1,19 @@ + +// These types are based on / compatible with the pino Logger object + +export interface LogFn { + (obj: T, msg?: string, ...args: any[]): void; + (obj: unknown, msg?: string, ...args: any[]): void; + (msg: string, ...args: any[]): void; +} + +export interface Logger { + child(bindings: Record, options?: any): Logger; + fatal: LogFn; + error: LogFn; + warn: LogFn; + info: LogFn; + debug: LogFn; + trace: LogFn; + silent: LogFn; +}