Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting up docs #12

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm-lock.yaml -diff
5 changes: 4 additions & 1 deletion packages/little-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@
"typescript": "^5.1.3",
"vitest": "^0.32.0"
},
"sideEffects": false
"sideEffects": false,
"dependencies": {
"typedoc": "^0.24.8"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a dependency? Not dev dependency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my mistake. I should put this as a Draft PR

}
}
10 changes: 6 additions & 4 deletions packages/little-router/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ export type PluginContext<
readonly params: Record<string, string>;
/**
* This is only used for adding typing hints to requests
* @private */
*
* @private
*/
readonly __hint?: HINT;
};
/**
* _hint is for giving hints to the consumer making the request
* regarding the request init and any possible search params
* */
* _hint is for giving hints to the consumer making the request regarding the
* request init and any possible search params
*/
export type Plugin<REST_ARGS extends unknown[] = unknown[]> = (
{ request, url, params }: PluginContext<any>,
...rest: REST_ARGS
Expand Down
4 changes: 2 additions & 2 deletions packages/little-router/src/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ describe("Router with plugins", () => {
const router = Router<[string]>().get(
"/extra-plugin",
[extra_],
async ({ value }) => {
return ok(`Plugin: ${value}`);
async () => {
return ok(200);
}
);

Expand Down
69 changes: 67 additions & 2 deletions packages/little-router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@ import { HasOverlap } from "./overlap.js";
import { Plugin, PluginContext } from "./plugin.js";
import { FetchDefinition, Queries } from "./fetch.js";

/**
* Returns an instance of RouteBuilder that you can use to build your routing
* structure.
*
* @typeParam REST_ARGS - Used to type Env and ExecutionContext from cloudflare
* workers. More info in [cloudflare workers docs]( https://developers.cloudflare.com/workers/platform/environment-variables/).
*
* The returned RouteBuilder can be build upon by using the method function,
* with names corresponding to http request methods.
*
* {@link Method | Available Methods}
*
* @example
* ```ts
* type Env = {
* MY_ENV_VAR: string;
* MY_SECRET: string;
* myKVNamespace: KVNamespace;
* };
* const router = Router<[Env, ExecutionContext]>
* ```
*
* More on cloudflare worker types in [their documentation](https://github.com/cloudflare/workerd/tree/main/npm/workers-types#using-bindings).
*/
export const Router = <REST_ARGS extends unknown[] = []>(): RouteBuilder<
REST_ARGS,
never
Expand Down Expand Up @@ -202,8 +226,49 @@ export type RouteBuilder<
REST_ARGS extends unknown[],
ROUTES extends FetchDefinition
> = {
[METHOD in Method]: RouteProxy<METHOD, ROUTES, REST_ARGS>;
} & {
/**
* @param route - The route to match for this http method handler
* @param pluginArray - A list of plugins to be applied to this route
* @param handler - A function to run when the path has been matched
* @returns an instance of RouteBuilder
*/
get: RouteProxy<"get", ROUTES, REST_ARGS>;
/**
* @param route - The route to match for this http method handler
* @param pluginArray - A list of plugins to be applied to this route
* @param handler - A function to run when the path has been matched
* @returns an instance of RouteBuilder
*/
post: RouteProxy<"post", ROUTES, REST_ARGS>;
/**
* @param route - The route to match for this http method handler
* @param pluginArray - A list of plugins to be applied to this route
* @param handler - A function to run when the path has been matched
* @returns an instance of RouteBuilder
*/
put: RouteProxy<"put", ROUTES, REST_ARGS>;
/**
* @param route - The route to match for this http method handler
* @param pluginArray - A list of plugins to be applied to this route
* @param handler - A function to run when the path has been matched
* @returns an instance of RouteBuilder
*/
delete: RouteProxy<"delete", ROUTES, REST_ARGS>;
/**
* @param route - The route to match for this http method handler
* @param pluginArray - A list of plugins to be applied to this route
* @param handler - A function to run when the path has been matched
* @returns an instance of RouteBuilder
*/
patch: RouteProxy<"patch", ROUTES, REST_ARGS>;
/**
* @param route - The route to match for this http method handler
* @param pluginArray - A list of plugins to be applied to this route
* @param handler - A function to run when the path has been matched
* @returns an instance of RouteBuilder
*/
options: RouteProxy<"options", ROUTES, REST_ARGS>;
all: RouteProxy<"all", ROUTES, REST_ARGS>;
handle: (
request: Request,
...rest: REST_ARGS
Expand Down
99 changes: 96 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tools/config/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
module.exports = {
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
plugins: ["@typescript-eslint", "eslint-plugin-tsdoc"],
root: true,
rules: {
"tsdoc/syntax": "warn",
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
"@typescript-eslint/no-explicit-any": "off",
},
Expand Down
7 changes: 3 additions & 4 deletions tools/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
"private": true,
"version": "0.0.10",
"description": "",
"files": [
"tsconfig.json",
".eslintrc.cjs"
],
"files": ["tsconfig.json", ".eslintrc.cjs"],
"scripts": {},
"keywords": [],
"author": "",
Expand All @@ -15,13 +12,15 @@
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"eslint": "^8.42.0",
"eslint-plugin-tsdoc": "^0.2.17",
"prettier": "^2.8.8",
"typescript": "^5.1.3"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1",
"eslint": "^8.39.0",
"eslint-plugin-tsdoc": "^0.2.17",
"prettier": "^2.8.8",
"typescript": "^5.0.4"
}
Expand Down