@pollium/readable-contracts 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,49 @@
1
+ export declare const baseCodeOf: (code: string) => string;
2
+ export interface ErrorTable {
3
+ readonly domain: string;
4
+ readonly causes: Readonly<Record<string, number>>;
5
+ }
6
+ export type ErrorCode<T extends ErrorTable> = `${T['domain']}::${Extract<keyof T['causes'], string>}`;
7
+ export declare const GatewayErrors: {
8
+ readonly domain: "Gateway";
9
+ readonly causes: {
10
+ readonly MissingChannel: 500;
11
+ readonly MalformedFrame: 400;
12
+ readonly UnknownMessageType: 400;
13
+ readonly Internal: 500;
14
+ };
15
+ };
16
+ export type GatewayErrorCode = ErrorCode<typeof GatewayErrors>;
17
+ export declare const RateLimitErrors: {
18
+ readonly domain: "RateLimit";
19
+ readonly causes: {
20
+ readonly TooManyRequests: 429;
21
+ };
22
+ };
23
+ export type RateLimitErrorCode = ErrorCode<typeof RateLimitErrors>;
24
+ export declare const RequestErrors: {
25
+ readonly domain: "Request";
26
+ readonly causes: {
27
+ readonly InvalidId: 400;
28
+ readonly InvalidPagination: 400;
29
+ readonly FileMissing: 400;
30
+ readonly FileTooLarge: 413;
31
+ readonly ValidationFailed: 400;
32
+ };
33
+ };
34
+ export type RequestErrorCode = ErrorCode<typeof RequestErrors>;
35
+ export declare const AuthErrors: {
36
+ readonly domain: "Auth";
37
+ readonly causes: {
38
+ readonly Unauthorized: 401;
39
+ readonly InvalidToken: 401;
40
+ };
41
+ };
42
+ export type AuthErrorCode = ErrorCode<typeof AuthErrors>;
43
+ export declare const ServerErrors: {
44
+ readonly domain: "Server";
45
+ readonly causes: {
46
+ readonly Internal: 500;
47
+ };
48
+ };
49
+ export type ServerErrorCode = ErrorCode<typeof ServerErrors>;
package/dist/errors.js ADDED
@@ -0,0 +1,38 @@
1
+ // src/errors.ts
2
+ const BASE_CODE = /^([^:]+::[^:]+)/;
3
+ const baseCodeOf = (code) => BASE_CODE.exec(code)?.[1] ?? code;
4
+ const GatewayErrors = {
5
+ domain: "Gateway",
6
+ causes: {
7
+ MissingChannel: 500,
8
+ MalformedFrame: 400,
9
+ UnknownMessageType: 400,
10
+ Internal: 500
11
+ }
12
+ };
13
+ const RateLimitErrors = {
14
+ domain: "RateLimit",
15
+ causes: { TooManyRequests: 429 }
16
+ };
17
+ const RequestErrors = {
18
+ domain: "Request",
19
+ causes: {
20
+ InvalidId: 400,
21
+ InvalidPagination: 400,
22
+ FileMissing: 400,
23
+ FileTooLarge: 413,
24
+ ValidationFailed: 400
25
+ }
26
+ };
27
+ const AuthErrors = {
28
+ domain: "Auth",
29
+ causes: {
30
+ Unauthorized: 401,
31
+ InvalidToken: 401
32
+ }
33
+ };
34
+ const ServerErrors = {
35
+ domain: "Server",
36
+ causes: { Internal: 500 }
37
+ };
38
+ export { AuthErrors, GatewayErrors, RateLimitErrors, RequestErrors, ServerErrors, baseCodeOf };
package/dist/http.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ export interface PageQuery {
2
+ limit?: number;
3
+ offset?: number;
4
+ }
5
+ export interface PageMeta {
6
+ total: number;
7
+ limit: number;
8
+ offset: number;
9
+ }
10
+ export interface PageOf<T> {
11
+ items: T[];
12
+ meta: PageMeta;
13
+ }
14
+ export interface ApiResponse<T> {
15
+ data: T;
16
+ meta?: PageMeta;
17
+ }
18
+ export interface ApiError {
19
+ error: string;
20
+ errors?: Record<string, string>;
21
+ }
package/dist/http.js ADDED
File without changes
@@ -0,0 +1,11 @@
1
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
2
+ export interface Endpoint<Input = never, Output = void> {
3
+ readonly method: HttpMethod;
4
+ readonly path: string;
5
+ readonly __io?: (input: Input) => Output;
6
+ }
7
+ export declare const get: <Output>(path: string) => Endpoint<never, Output>;
8
+ export declare const post: <Input, Output = void>(path: string) => Endpoint<Input, Output>;
9
+ export declare const patch: <Input, Output = void>(path: string) => Endpoint<Input, Output>;
10
+ export declare const put: <Input, Output = void>(path: string) => Endpoint<Input, Output>;
11
+ export declare const del: <Output = void>(path: string) => Endpoint<never, Output>;
@@ -0,0 +1,22 @@
1
+ // src/routing.ts
2
+ const get = (path) => ({
3
+ method: "GET",
4
+ path
5
+ });
6
+ const post = (path) => ({
7
+ method: "POST",
8
+ path
9
+ });
10
+ const patch = (path) => ({
11
+ method: "PATCH",
12
+ path
13
+ });
14
+ const put = (path) => ({
15
+ method: "PUT",
16
+ path
17
+ });
18
+ const del = (path) => ({
19
+ method: "DELETE",
20
+ path
21
+ });
22
+ export { del, get, patch, post, put };
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "@pollium/readable-contracts",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "The routes, envelopes and error tables a Readable API and its web app share.",
5
+ "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Pollium/Readable.git",
9
+ "directory": "packages/contracts"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "exports": {
15
+ "./*": {
16
+ "types": "./dist/*.d.ts",
17
+ "default": "./dist/*.js"
18
+ }
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "devDependencies": {
24
+ "oxlint": "^1.71.0",
25
+ "typescript": "~6.0.2"
26
+ },
27
+ "scripts": {
28
+ "build": "tsdown",
29
+ "lint": "oxlint --deny-warnings",
30
+ "typecheck": "tsc --noEmit -p tsconfig.json"
31
+ }
6
32
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.