This repository has been archived by the owner on Feb 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Route definition based requests #40
Merged
+606
−122
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9d2069c
wip route definition
kibertoad 4cf4d5c
Support route definitions
kibertoad a3525bb
Fix CI
kibertoad 98c3ad0
Fix typing
kibertoad 7aac733
switch to routes from shared-ts-libs
kibertoad da8ef93
Adjust types
kibertoad 24c19b4
Improve types
kibertoad a83a032
Add docs
kibertoad 08bf776
Merge branch 'main' of https://github.com/lokalise/frontend-http-clie…
kibertoad 711d2c9
Resolve conflicts
kibertoad ad6f6f9
fix linting
kibertoad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
{ | ||
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json", | ||
"extends": ["./node_modules/@lokalise/biome-config/configs/biome-base.jsonc"], | ||
"linter": { | ||
"rules": { | ||
"performance": { | ||
"noBarrelFile": "off", | ||
"noReExportAll": "off" | ||
}, | ||
"style": { | ||
"noUnusedTemplateLiteral": "off" | ||
} | ||
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json", | ||
"extends": ["./node_modules/@lokalise/biome-config/configs/biome-base.jsonc"], | ||
"linter": { | ||
"rules": { | ||
"performance": { | ||
"noBarrelFile": "off", | ||
"noReExportAll": "off" | ||
}, | ||
"style": { | ||
"noUnusedTemplateLiteral": "off" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
export { sendPost, sendGet, sendPut, sendDelete, sendPatch, UNKNOWN_SCHEMA } from './src/client.js' | ||
export { | ||
sendPost, | ||
sendGet, | ||
sendPut, | ||
sendDelete, | ||
sendPatch, | ||
sendByRouteDefinition, | ||
UNKNOWN_SCHEMA, | ||
} from './src/client.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,63 @@ | ||
{ | ||
"name": "@lokalise/frontend-http-client", | ||
"version": "2.1.0", | ||
"description": "Opinionated HTTP client for the frontend", | ||
"files": ["dist/**", "LICENSE", "README.md"], | ||
"main": "./dist/index.cjs", | ||
"types": "./dist/index.d.ts", | ||
"module": "./dist/index.mjs", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.mjs" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.cts", | ||
"default": "./dist/index.cjs" | ||
} | ||
} | ||
}, | ||
"author": { | ||
"name": "Lokalise", | ||
"url": "https://lokalise.com/" | ||
}, | ||
"homepage": "https://github.com/lokalise/frontend-http-client", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/lokalise/frontend-http-client.git" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"build:dev": "tsc", | ||
"build:release": "tsup", | ||
"clean": "rimraf dist", | ||
"lint": "biome check . && tsc --project tsconfig.lint.json --noEmit", | ||
"lint:fix": "biome check --write", | ||
"test": "vitest run --coverage", | ||
"prepublishOnly": "npm run clean && npm run build:release" | ||
}, | ||
"dependencies": { | ||
"fast-querystring": "^1.1.2" | ||
}, | ||
"peerDependencies": { | ||
"wretch": "^2.8.0", | ||
"zod": "^3.22.0" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.8.3", | ||
"@lokalise/biome-config": "^1.0.0", | ||
"@types/node": "^22.0.0", | ||
"@vitest/coverage-v8": "^2.0.1", | ||
"jest-fail-on-console": "^3.1.2", | ||
"mockttp": "^3.13.0", | ||
"rimraf": "^6.0.0", | ||
"tsup": "8.3.5", | ||
"typescript": "~5.7.2", | ||
"vitest": "^2.0.1" | ||
}, | ||
"keywords": ["frontend", "web", "browser", "http", "client", "zod", "validation", "typesafe"] | ||
"name": "@lokalise/frontend-http-client", | ||
"version": "2.1.0", | ||
"description": "Opinionated HTTP client for the frontend", | ||
"files": ["dist/**", "LICENSE", "README.md"], | ||
"main": "./dist/index.cjs", | ||
"types": "./dist/index.d.ts", | ||
"module": "./dist/index.mjs", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.mjs" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.cts", | ||
"default": "./dist/index.cjs" | ||
} | ||
} | ||
}, | ||
"author": { | ||
"name": "Lokalise", | ||
"url": "https://lokalise.com/" | ||
}, | ||
"homepage": "https://github.com/lokalise/frontend-http-client", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/lokalise/frontend-http-client.git" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"build:dev": "tsc", | ||
"build:release": "tsup", | ||
"clean": "rimraf dist", | ||
"lint": "biome check . && tsc --project tsconfig.lint.json --noEmit", | ||
"lint:fix": "biome check --write", | ||
"test": "vitest run --coverage", | ||
"prepublishOnly": "npm run clean && npm run build:release" | ||
}, | ||
"dependencies": { | ||
"fast-querystring": "^1.1.2" | ||
}, | ||
"peerDependencies": { | ||
"wretch": "^2.8.0", | ||
"zod": "^3.22.0" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.9.4", | ||
"@lokalise/biome-config": "^1.5.0", | ||
"@types/node": "^22.10.3", | ||
"@vitest/coverage-v8": "^2.1.8", | ||
"jest-fail-on-console": "^3.1.2", | ||
"mockttp": "^3.15.5", | ||
"rimraf": "^6.0.0", | ||
"tsup": "8.3.5", | ||
"typescript": "~5.7.2", | ||
"vitest": "^2.1.8" | ||
}, | ||
"keywords": ["frontend", "web", "browser", "http", "client", "zod", "validation", "typesafe"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import type { ZodSchema, z } from 'zod' | ||
|
||
export type RoutePathResolver<PathParams> = (pathParams: PathParams) => string | ||
|
||
export type InferSchemaOutput<T extends ZodSchema | undefined> = T extends ZodSchema<infer U> | ||
? U | ||
: T extends undefined | ||
? undefined | ||
: never | ||
|
||
export function buildRouteDefinition< | ||
IsNonJSONResponseExpected extends boolean, | ||
IsEmptyResponseExpected extends boolean, | ||
PathParams, | ||
RequestBodySchema extends z.Schema | undefined = undefined, | ||
ResponseBodySchema extends z.Schema | undefined = undefined, | ||
PathParamsSchema extends z.Schema<PathParams> | undefined = undefined, | ||
RequestQuerySchema extends z.Schema | undefined = undefined, | ||
RequestHeaderSchema extends z.Schema | undefined = undefined, | ||
>( | ||
params: ResourceChangeRouteDefinition< | ||
IsNonJSONResponseExpected, | ||
IsEmptyResponseExpected, | ||
RequestBodySchema, | ||
ResponseBodySchema, | ||
PathParamsSchema, | ||
RequestQuerySchema, | ||
RequestHeaderSchema | ||
>, | ||
): ResourceChangeRouteDefinition< | ||
IsNonJSONResponseExpected, | ||
IsEmptyResponseExpected, | ||
RequestBodySchema, | ||
ResponseBodySchema, | ||
PathParamsSchema, | ||
RequestQuerySchema, | ||
RequestHeaderSchema | ||
> { | ||
return params | ||
} | ||
|
||
export type ResourceChangeRouteDefinition< | ||
IsNonJSONResponseExpected extends boolean, | ||
IsEmptyResponseExpected extends boolean, | ||
PathParams, | ||
RequestBodySchema extends z.Schema | undefined = undefined, | ||
ResponseBodySchema extends z.Schema | undefined = undefined, | ||
PathParamsSchema extends z.Schema<PathParams> | undefined = undefined, | ||
RequestQuerySchema extends z.Schema | undefined = undefined, | ||
RequestHeaderSchema extends z.Schema | undefined = undefined, | ||
> = { | ||
method: 'post' | 'put' | 'patch' | ||
isNonJSONResponseExpected: IsNonJSONResponseExpected | ||
isEmptyResponseExpected: IsEmptyResponseExpected | ||
requestBodySchema: RequestBodySchema | ||
responseBodySchema: ResponseBodySchema | ||
requestPathParamsSchema: PathParamsSchema | ||
requestQuerySchema?: RequestQuerySchema | ||
requestHeaderSchema?: RequestHeaderSchema | ||
pathResolver: RoutePathResolver<InferSchemaOutput<PathParamsSchema>> | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
had to do reformatting, as library repos do not use package-lock file, so CI picked up the latest version of biome and rules file, and CI broke