@sapporta/rest-core 3.52.1 → 3.52.2

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +75 -10
  3. package/index.cjs.d.ts +1 -0
  4. package/index.cjs.default.js +1 -0
  5. package/index.cjs.js +807 -0
  6. package/index.cjs.mjs +2 -0
  7. package/index.esm.js +762 -0
  8. package/package.json +13 -3
  9. package/src/lib/client.d.ts +107 -0
  10. package/src/lib/dsl.d.ts +222 -0
  11. package/src/lib/infer-types.d.ts +78 -0
  12. package/src/lib/paths.d.ts +30 -0
  13. package/src/lib/query.d.ts +17 -0
  14. package/src/lib/response-error.d.ts +20 -0
  15. package/src/lib/response-validation-error.d.ts +14 -0
  16. package/src/lib/server.d.ts +18 -0
  17. package/src/lib/standard-schema-utils.d.ts +68 -0
  18. package/src/lib/standard-schema.d.ts +55 -0
  19. package/src/lib/status-codes.d.ts +6 -0
  20. package/src/lib/{test-helpers.ts → test-helpers.d.ts} +1 -6
  21. package/src/lib/type-guards.d.ts +12 -0
  22. package/src/lib/type-utils.d.ts +96 -0
  23. package/src/lib/unknown-status-error.d.ts +10 -0
  24. package/src/lib/validation-error.d.ts +11 -0
  25. package/.babelrc +0 -10
  26. package/.eslintrc.json +0 -21
  27. package/LICENCE +0 -21
  28. package/jest.config.ts +0 -16
  29. package/project.json +0 -51
  30. package/src/lib/client.spec.ts +0 -1330
  31. package/src/lib/client.ts +0 -481
  32. package/src/lib/dsl.spec.ts +0 -1308
  33. package/src/lib/dsl.ts +0 -472
  34. package/src/lib/fetch.spec.ts +0 -102
  35. package/src/lib/infer-types.spec.ts +0 -935
  36. package/src/lib/infer-types.ts +0 -282
  37. package/src/lib/paths.spec.ts +0 -138
  38. package/src/lib/paths.ts +0 -61
  39. package/src/lib/query.spec.ts +0 -329
  40. package/src/lib/query.ts +0 -114
  41. package/src/lib/response-error.spec.ts +0 -67
  42. package/src/lib/response-error.ts +0 -61
  43. package/src/lib/response-validation-error.ts +0 -24
  44. package/src/lib/server.spec.ts +0 -163
  45. package/src/lib/server.ts +0 -83
  46. package/src/lib/standard-schema-utils.spec.ts +0 -218
  47. package/src/lib/standard-schema-utils.ts +0 -280
  48. package/src/lib/standard-schema.ts +0 -71
  49. package/src/lib/status-codes.ts +0 -75
  50. package/src/lib/type-guards.spec.ts +0 -355
  51. package/src/lib/type-guards.ts +0 -99
  52. package/src/lib/type-utils.spec.ts +0 -59
  53. package/src/lib/type-utils.ts +0 -234
  54. package/src/lib/unknown-status-error.ts +0 -15
  55. package/src/lib/validation-error.ts +0 -36
  56. package/tsconfig.json +0 -22
  57. package/tsconfig.lib.json +0 -10
  58. package/tsconfig.spec.json +0 -9
  59. package/typedoc.json +0 -5
  60. /package/src/{index.ts → index.d.ts} +0 -0
@@ -0,0 +1,55 @@
1
+ /** The Standard Schema interface. */
2
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
3
+ /** The Standard Schema properties. */
4
+ readonly '~standard': StandardSchemaV1.Props<Input, Output>;
5
+ }
6
+ export declare namespace StandardSchemaV1 {
7
+ /** The Standard Schema properties interface. */
8
+ interface Props<Input = unknown, Output = Input> {
9
+ /** The version number of the standard. */
10
+ readonly version: 1;
11
+ /** The vendor name of the schema library. */
12
+ readonly vendor: string;
13
+ /** Validates unknown input values. */
14
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
15
+ /** Inferred types associated with the schema. */
16
+ readonly types?: Types<Input, Output> | undefined;
17
+ }
18
+ /** The result interface of the validate function. */
19
+ type Result<Output> = SuccessResult<Output> | FailureResult;
20
+ /** The result interface if validation succeeds. */
21
+ interface SuccessResult<Output> {
22
+ /** The typed output value. */
23
+ readonly value: Output;
24
+ /** The non-existent issues. */
25
+ readonly issues?: undefined;
26
+ }
27
+ /** The result interface if validation fails. */
28
+ interface FailureResult {
29
+ /** The issues of failed validation. */
30
+ readonly issues: ReadonlyArray<Issue>;
31
+ }
32
+ /** The issue interface of the failure output. */
33
+ interface Issue {
34
+ /** The error message of the issue. */
35
+ readonly message: string;
36
+ /** The path of the issue, if any. */
37
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
38
+ }
39
+ /** The path segment interface of the issue. */
40
+ interface PathSegment {
41
+ /** The key representing a path segment. */
42
+ readonly key: PropertyKey;
43
+ }
44
+ /** The Standard Schema types interface. */
45
+ interface Types<Input = unknown, Output = Input> {
46
+ /** The input type of the schema. */
47
+ readonly input: Input;
48
+ /** The output type of the schema. */
49
+ readonly output: Output;
50
+ }
51
+ /** Infers the input type of a Standard Schema. */
52
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
53
+ /** Infers the output type of a Standard Schema. */
54
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
55
+ }
@@ -0,0 +1,6 @@
1
+ export type SuccessfulHttpStatusCode = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207;
2
+ /**
3
+ * All available HTTP Status codes
4
+ */
5
+ export type HTTPStatusCode = 100 | 101 | 102 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 300 | 301 | 302 | 303 | 304 | 305 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 507 | 511;
6
+ export type ErrorHttpStatusCode = Exclude<HTTPStatusCode, SuccessfulHttpStatusCode>;
@@ -1,7 +1,2 @@
1
- export type Equal<a, b> = (<T>() => T extends a ? 1 : 2) extends <
2
- T,
3
- >() => T extends b ? 1 : 2
4
- ? true
5
- : false;
6
-
1
+ export type Equal<a, b> = (<T>() => T extends a ? 1 : 2) extends <T>() => T extends b ? 1 : 2 ? true : false;
7
2
  export type Expect<a extends true> = a;
@@ -0,0 +1,12 @@
1
+ import { AppRoute } from './dsl';
2
+ import { ClientInferResponses, InferResponseUndefinedStatusCodes } from './infer-types';
3
+ import { ErrorHttpStatusCode, HTTPStatusCode, SuccessfulHttpStatusCode } from './status-codes';
4
+ export declare const isResponse: <T extends AppRoute>(response: unknown, contractEndpoint?: T | undefined) => response is ClientInferResponses<T, HTTPStatusCode>;
5
+ export declare const isSuccessResponse: <T extends AppRoute>(response: unknown, contractEndpoint?: T | undefined) => response is ClientInferResponses<T, SuccessfulHttpStatusCode>;
6
+ export declare const isErrorResponse: <T extends AppRoute>(response: unknown, contractEndpoint?: T | undefined) => response is ClientInferResponses<T, ErrorHttpStatusCode>;
7
+ export declare const isUnknownResponse: <T extends AppRoute>(response: unknown, contractEndpoint: T) => response is ClientInferResponses<T, InferResponseUndefinedStatusCodes<T>, "ignore">;
8
+ export declare const isUnknownSuccessResponse: <T extends AppRoute>(response: unknown, contractEndpoint: T) => response is ClientInferResponses<T, InferResponseUndefinedStatusCodes<T, SuccessfulHttpStatusCode>, "ignore">;
9
+ export declare const isUnknownErrorResponse: <T extends AppRoute>(response: unknown, contractEndpoint: T) => response is ClientInferResponses<T, InferResponseUndefinedStatusCodes<T, ErrorHttpStatusCode>, "ignore">;
10
+ export declare const exhaustiveGuard: <T extends {
11
+ status: never;
12
+ }>(response: T) => never;
@@ -0,0 +1,96 @@
1
+ import type { z } from 'zod';
2
+ import { ContractNoBodyType, ContractNullType, ContractPlainType } from './dsl';
3
+ import { StandardSchemaV1 } from './standard-schema';
4
+ type GetIndexedField<T, K> = K extends keyof T ? T[K] : K extends `${number}` ? '0' extends keyof T ? undefined : number extends keyof T ? T[number] : undefined : undefined;
5
+ type FieldWithPossiblyUndefined<T, Key> = GetFieldType<Exclude<T, undefined>, Key> | Extract<T, undefined>;
6
+ type IndexedFieldWithPossiblyUndefined<T, Key> = GetIndexedField<Exclude<T, undefined>, Key> | Extract<T, undefined>;
7
+ export type GetFieldType<T, P> = P extends `${infer Left}.${infer Right}` ? Left extends keyof T ? FieldWithPossiblyUndefined<T[Left], Right> : Left extends `${infer FieldKey}[${infer IndexKey}]` ? FieldKey extends keyof T ? FieldWithPossiblyUndefined<IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey>, Right> : undefined : undefined : P extends keyof T ? T[P] : P extends `${infer FieldKey}[${infer IndexKey}]` ? FieldKey extends keyof T ? IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey> : undefined : undefined;
8
+ type ExcludeKeysWithTypeOf<T, V> = {
9
+ [K in keyof T]-?: [Exclude<T[K], undefined>] extends [V] ? never : K;
10
+ }[keyof T];
11
+ type ExcludeKeysWithoutTypeOf<T, V> = {
12
+ [K in keyof T]-?: [Exclude<T[K], undefined>] extends [V] ? K : never;
13
+ }[keyof T];
14
+ export type Without<T, V> = Pick<T, ExcludeKeysWithTypeOf<T, V>>;
15
+ export type With<T, V> = Pick<T, ExcludeKeysWithoutTypeOf<T, V>>;
16
+ export type SchemaOutputOrType<T> = T extends ContractNullType ? null : T extends ContractNoBodyType ? undefined : T extends ContractPlainType<infer U> ? U : T extends z.ZodTypeAny ? z.output<T> : T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : T;
17
+ /** @deprecated use SchemaOutputOrType */
18
+ export type ZodInferOrType<T> = SchemaOutputOrType<T>;
19
+ export type SchemaInputOrType<T> = T extends ContractNullType ? null : T extends ContractNoBodyType ? undefined : T extends ContractPlainType<infer U> ? U : T extends z.ZodTypeAny ? z.input<T> : T extends StandardSchemaV1 ? StandardSchemaV1.InferInput<T> : T;
20
+ /** @deprecated use SchemaInputOrType */
21
+ export type ZodInputOrType<T> = SchemaInputOrType<T>;
22
+ export type Merge<T, U> = Omit<T, keyof U> & U;
23
+ type Try<A, B, C> = A extends B ? A : C;
24
+ type NarrowRaw<T> = (T extends Function ? T : never) | (T extends string | number | bigint | boolean ? T : never) | (T extends [] ? [] : never) | {
25
+ [K in keyof T]: K extends 'description' ? T[K] : NarrowNotSchema<T[K]>;
26
+ };
27
+ type NarrowNotSchema<T> = Try<T, StandardSchemaV1, NarrowRaw<T>>;
28
+ export type Narrow<T> = Try<T, [], NarrowNotSchema<T>>;
29
+ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
30
+ /**
31
+ * Makes the properties of `T` specified by `K` optional, where `K` can be any type (not necessarily keys of `T`).
32
+ * If `K` is not a key of `T`, it is ignored.
33
+ *
34
+ * @template T - The base object type.
35
+ * @template K - The keys to make optional (can be any type, only keys of `T` are used).
36
+ */
37
+ export type PartialByLooseKeys<T, K> = Omit<T, K extends keyof T ? K : never> & Partial<Pick<T, K extends keyof T ? K : never>>;
38
+ type OptionalKeys<T> = T extends unknown ? {
39
+ [K in keyof T]-?: undefined extends {
40
+ [K2 in keyof T]: K2;
41
+ }[K] ? K : never;
42
+ }[keyof T] : never;
43
+ export type AreAllPropertiesOptional<T> = T extends Record<string, unknown> ? Exclude<keyof T, OptionalKeys<T>> extends never ? true : false : false;
44
+ export type IfAllPropertiesOptional<T, TIf, TElse> = T extends Record<string, unknown> ? Exclude<keyof T, OptionalKeys<T>> extends never ? TIf : TElse : TElse;
45
+ export type OptionalIfAllOptional<T, Select extends keyof T = keyof T> = PartialBy<T, Select & {
46
+ [K in keyof T]: AreAllPropertiesOptional<T[K]> extends true ? K : never;
47
+ }[keyof T]>;
48
+ export type Prettify<T> = {
49
+ [K in keyof T]: T[K];
50
+ } & {};
51
+ export type DefinedOrEmpty<T, K extends keyof NonNullable<T>> = undefined extends T ? {} : NonNullable<T>[K];
52
+ declare const tag: unique symbol;
53
+ declare type Tagged<Token> = {
54
+ readonly [tag]: Token;
55
+ };
56
+ export type Opaque<Type, Token = unknown> = Type & Tagged<Token>;
57
+ export type UnwrapOpaque<OpaqueType extends Tagged<unknown>> = OpaqueType extends Opaque<infer Type, OpaqueType[typeof tag]> ? Type : OpaqueType;
58
+ export type WithoutUnknown<T> = Pick<T, {
59
+ [K in keyof T]: unknown extends Exclude<T[K], undefined> ? never : K;
60
+ }[keyof T]>;
61
+ export type LowercaseKeys<T> = Prettify<{
62
+ [K in keyof T as K extends string ? Lowercase<K> : K]: T[K];
63
+ }>;
64
+ export type Extends<T, U> = T extends U ? true : false;
65
+ export type And<B1 extends boolean, B2 extends boolean> = {
66
+ false: {
67
+ false: false;
68
+ true: false;
69
+ };
70
+ true: {
71
+ false: false;
72
+ true: true;
73
+ };
74
+ }[`${B1}`][`${B2}`];
75
+ export type Or<B1 extends boolean, B2 extends boolean> = {
76
+ false: {
77
+ false: false;
78
+ true: true;
79
+ };
80
+ true: {
81
+ false: true;
82
+ true: true;
83
+ };
84
+ }[`${B1}`][`${B2}`];
85
+ export type Not<B extends boolean> = {
86
+ false: true;
87
+ true: false;
88
+ }[`${B}`];
89
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
90
+ type CommonKeys<T, R = {}> = R extends T ? keyof T & CommonKeys<Exclude<T, R>> : keyof T;
91
+ type Common<T> = Pick<T, CommonKeys<T>>;
92
+ type RemoveUnionProperties<T> = {
93
+ [TKey in keyof T as [T[TKey]] extends [UnionToIntersection<T[TKey]>] ? TKey : never]: T[TKey];
94
+ };
95
+ export type CommonAndEqual<T> = RemoveUnionProperties<Common<T>>;
96
+ export {};
@@ -0,0 +1,10 @@
1
+ export declare class UnknownStatusError extends Error {
2
+ response: {
3
+ status: number;
4
+ body: unknown;
5
+ };
6
+ constructor(response: {
7
+ status: number;
8
+ body: unknown;
9
+ }, knownResponseStatuses: string[]);
10
+ }
@@ -0,0 +1,11 @@
1
+ import { StandardSchemaV1 } from './standard-schema';
2
+ /**
3
+ * The error class for standard schema validation errors.
4
+ *
5
+ * @see {@link StandardSchemaV1.FailureResult}
6
+ */
7
+ export declare class StandardSchemaError extends Error implements StandardSchemaV1.FailureResult {
8
+ readonly issues: readonly StandardSchemaV1.Issue[];
9
+ constructor(issues: ReadonlyArray<StandardSchemaV1.Issue>);
10
+ toString(): string;
11
+ }
package/.babelrc DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "presets": [
3
- [
4
- "@nrwl/js/babel",
5
- {
6
- "useBuiltIns": "usage"
7
- }
8
- ]
9
- ]
10
- }
package/.eslintrc.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "extends": ["../../../.eslintrc.json"],
3
- "ignorePatterns": ["!**/*"],
4
- "overrides": [
5
- {
6
- "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7
- "rules": {
8
- "@typescript-eslint/no-unused-vars": ["warn"],
9
- "@typescript-eslint/no-explicit-any": ["warn"]
10
- }
11
- },
12
- {
13
- "files": ["*.ts", "*.tsx"],
14
- "rules": {}
15
- },
16
- {
17
- "files": ["*.js", "*.jsx"],
18
- "rules": {}
19
- }
20
- ]
21
- }
package/LICENCE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Oliver Butler
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/jest.config.ts DELETED
@@ -1,16 +0,0 @@
1
- /* eslint-disable */
2
- export default {
3
- displayName: 'sapporta-rest-core',
4
- preset: '../../../jest.preset.js',
5
- globals: {},
6
- transform: {
7
- '^.+\\.[tj]s$': [
8
- 'ts-jest',
9
- {
10
- tsconfig: '<rootDir>/tsconfig.spec.json',
11
- },
12
- ],
13
- },
14
- moduleFileExtensions: ['ts', 'js', 'html'],
15
- testEnvironment: 'node',
16
- };
package/project.json DELETED
@@ -1,51 +0,0 @@
1
- {
2
- "name": "sapporta-rest-core",
3
- "$schema": "../../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "libs/ts-rest/core/src",
5
- "projectType": "library",
6
- "targets": {
7
- "build": {
8
- "executor": "@nx/rollup:rollup",
9
- "outputs": ["{options.outputPath}"],
10
- "options": {
11
- "project": "libs/ts-rest/core/package.json",
12
- "outputPath": "dist/libs/ts-rest/core",
13
- "main": "libs/ts-rest/core/src/index.ts",
14
- "tsConfig": "libs/ts-rest/core/tsconfig.lib.json",
15
- "assets": [
16
- {
17
- "glob": "CHANGELOG.md",
18
- "input": "libs/ts-rest/core",
19
- "output": "."
20
- },
21
- {
22
- "glob": "README.md",
23
- "input": ".",
24
- "output": "."
25
- }
26
- ],
27
- "format": ["esm", "cjs"],
28
- "compiler": "tsc",
29
- "rollupConfig": "tools/scripts/rollup.config.js",
30
- "generateExportsField": true,
31
- "updateBuildableProjectDepsInPackageJson": true
32
- }
33
- },
34
- "lint": {
35
- "executor": "@nx/eslint:lint",
36
- "outputs": ["{options.outputFile}"],
37
- "options": {
38
- "lintFilePatterns": ["libs/ts-rest/core/**/*.ts"]
39
- }
40
- },
41
- "test": {
42
- "executor": "@nx/jest:jest",
43
- "outputs": ["{workspaceRoot}/coverage/libs/ts-rest/core"],
44
- "options": {
45
- "jestConfig": "libs/ts-rest/core/jest.config.ts",
46
- "coverageReporters": ["lcov", "text-summary"]
47
- }
48
- }
49
- },
50
- "tags": []
51
- }