@rest-vir/define-service 0.15.0 → 0.16.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.
- package/dist/dev-port/find-dev-port.d.ts +3 -3
- package/dist/endpoint/endpoint.d.ts +2 -2
- package/dist/frontend-connect/connect-web-socket.d.ts +4 -4
- package/dist/frontend-connect/fetch-endpoint.d.ts +2 -2
- package/dist/frontend-connect/generate-api.d.ts +8 -8
- package/dist/frontend-connect/mock-client-web-socket.d.ts +3 -3
- package/dist/frontend-connect/web-socket-protocol-parse.js +0 -1
- package/dist/service/define-service.d.ts +1 -1
- package/dist/service/define-service.js +1 -1
- package/dist/service/match-url.d.ts +1 -1
- package/dist/service/service-definition.d.ts +8 -8
- package/dist/util/origin.d.ts +25 -1
- package/dist/util/origin.js +50 -0
- package/dist/util/path-to-regexp.js +3 -3
- package/dist/web-socket/common-web-socket.d.ts +1 -1
- package/dist/web-socket/overwrite-web-socket-methods.d.ts +4 -4
- package/dist/web-socket/web-socket-definition.d.ts +8 -8
- package/package.json +6 -6
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type MaybePromise, type PartialWithUndefined, type SelectFrom } from '@augment-vir/common';
|
|
2
2
|
import { type AnyDuration } from 'date-vir';
|
|
3
|
-
import type
|
|
4
|
-
import { GenericFetchEndpointParams } from '../frontend-connect/fetch-endpoint.js';
|
|
5
|
-
import type
|
|
3
|
+
import { type EndpointPathBase } from '../endpoint/endpoint-path.js';
|
|
4
|
+
import { type GenericFetchEndpointParams } from '../frontend-connect/fetch-endpoint.js';
|
|
5
|
+
import { type ServiceDefinition } from '../service/service-definition.js';
|
|
6
6
|
/**
|
|
7
7
|
* This header is set on all responses handled by rest-vir so we know what service a response came
|
|
8
8
|
* from.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HttpMethod, type AnyObject, type Overwrite, type SelectFrom } from '@augment-vir/common';
|
|
2
2
|
import { type ShapeDefinition, type ShapeToRuntimeType } from 'object-shape-tester';
|
|
3
3
|
import { type RequireAtLeastOne } from 'type-fest';
|
|
4
4
|
import { type MinimalService } from '../service/minimal-service.js';
|
|
5
5
|
import { type NoParam } from '../util/no-param.js';
|
|
6
6
|
import { type OriginRequirement } from '../util/origin.js';
|
|
7
|
-
import { BaseSearchParams } from '../util/search-params.js';
|
|
7
|
+
import { type BaseSearchParams } from '../util/search-params.js';
|
|
8
8
|
import { type EndpointPathBase } from './endpoint-path.js';
|
|
9
9
|
/**
|
|
10
10
|
* The type for setting up an individual endpoint, used in `defineService`.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { RequiredKeysOf, SelectFrom } from '@augment-vir/common';
|
|
2
|
-
import { IsNever } from 'type-fest';
|
|
3
|
-
import { PathParams } from '../endpoint/endpoint-path.js';
|
|
1
|
+
import { type RequiredKeysOf, type SelectFrom } from '@augment-vir/common';
|
|
2
|
+
import { type IsNever } from 'type-fest';
|
|
3
|
+
import { type PathParams } from '../endpoint/endpoint-path.js';
|
|
4
4
|
import { type NoParam } from '../util/no-param.js';
|
|
5
|
-
import type
|
|
5
|
+
import { type CommonWebSocket } from '../web-socket/common-web-socket.js';
|
|
6
6
|
import { type ClientWebSocket, type ConnectWebSocketListeners, type GenericConnectWebSocketParams } from '../web-socket/overwrite-web-socket-methods.js';
|
|
7
7
|
import { type WebSocketDefinition } from '../web-socket/web-socket-definition.js';
|
|
8
8
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { HttpMethod,
|
|
1
|
+
import { HttpMethod, type ExtractKeysWithMatchingValues, type KeyCount, type MaybePromise, type RequiredKeysOf, type SelectFrom } from '@augment-vir/common';
|
|
2
2
|
import { type IsEqual, type IsNever } from 'type-fest';
|
|
3
3
|
import { type PathParams } from '../endpoint/endpoint-path.js';
|
|
4
|
-
import {
|
|
4
|
+
import { type EndpointDefinition, type EndpointExecutorData, type GenericEndpointDefinition } from '../endpoint/endpoint.js';
|
|
5
5
|
import { type NoParam } from '../util/no-param.js';
|
|
6
6
|
/**
|
|
7
7
|
* A general version of {@link FetchEndpointParams} to be used when accepting _any_ endpoint (like in
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { MaybePromise, Overwrite, PartialWithUndefined, type Values } from '@augment-vir/common';
|
|
2
|
-
import type
|
|
3
|
-
import type
|
|
4
|
-
import type
|
|
5
|
-
import { ClientWebSocket, GenericConnectWebSocketParams } from '../web-socket/overwrite-web-socket-methods.js';
|
|
6
|
-
import type
|
|
7
|
-
import { CollapsedConnectWebSocketParams } from './connect-web-socket.js';
|
|
8
|
-
import { CollapsedFetchEndpointParams, FetchEndpointOutput, GenericFetchEndpointParams } from './fetch-endpoint.js';
|
|
1
|
+
import { type MaybePromise, type Overwrite, type PartialWithUndefined, type Values } from '@augment-vir/common';
|
|
2
|
+
import { type GenericEndpointDefinition } from '../endpoint/endpoint.js';
|
|
3
|
+
import { type ServiceDefinition } from '../service/service-definition.js';
|
|
4
|
+
import { type CommonWebSocket } from '../web-socket/common-web-socket.js';
|
|
5
|
+
import { type ClientWebSocket, type GenericConnectWebSocketParams } from '../web-socket/overwrite-web-socket-methods.js';
|
|
6
|
+
import { type WebSocketDefinition } from '../web-socket/web-socket-definition.js';
|
|
7
|
+
import { type CollapsedConnectWebSocketParams } from './connect-web-socket.js';
|
|
8
|
+
import { type CollapsedFetchEndpointParams, type FetchEndpointOutput, type GenericFetchEndpointParams } from './fetch-endpoint.js';
|
|
9
9
|
/**
|
|
10
10
|
* An API generated by {@link generateApi}. This can be easily mocked by wrapping this API in
|
|
11
11
|
* {@link makeMockApi}.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type MaybePromise, type PartialWithUndefined } from '@augment-vir/common';
|
|
2
|
-
import { CommonWebSocket, CommonWebSocketEventMap
|
|
3
|
-
import {
|
|
4
|
-
import { WebSocketDefinition } from '../web-socket/web-socket-definition.js';
|
|
2
|
+
import { CommonWebSocketState, type CommonWebSocket, type CommonWebSocketEventMap } from '../web-socket/common-web-socket.js';
|
|
3
|
+
import { WebSocketLocation, type ClientWebSocket, type GenericConnectWebSocketParams } from '../web-socket/overwrite-web-socket-methods.js';
|
|
4
|
+
import { type WebSocketDefinition } from '../web-socket/web-socket-definition.js';
|
|
5
5
|
/**
|
|
6
6
|
* Parameters for {@link MockClientWebSocketClientSendCallback}.
|
|
7
7
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type BaseServiceEndpointsInit, type BaseServiceWebSocketsInit, type ServiceDefinition, type ServiceInit } from './service-definition.js';
|
|
2
2
|
/**
|
|
3
3
|
* The main entry point to the whole `@rest-vir/define-service` package. This function accepts a
|
|
4
4
|
* {@link ServiceInit} object and returns a fully defined {@link ServiceDefinition}.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assert, check } from '@augment-vir/assert';
|
|
2
|
-
import { getObjectTypedEntries, mapObjectValues, stringify } from '@augment-vir/common';
|
|
2
|
+
import { getObjectTypedEntries, mapObjectValues, stringify, } from '@augment-vir/common';
|
|
3
3
|
import { assertValidShape, defineShape } from 'object-shape-tester';
|
|
4
4
|
import { assertValidEndpoint, attachEndpointShapeTypeGetters, endpointInitShape, } from '../endpoint/endpoint.js';
|
|
5
5
|
import { assertValidWebSocketDefinition, attachWebSocketShapeTypeGetters, webSocketInitShape, } from '../web-socket/web-socket-definition.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type RequireAtLeastOne } from 'type-fest';
|
|
2
|
-
import { EndpointPathBase } from '../endpoint/endpoint-path.js';
|
|
2
|
+
import { type EndpointPathBase } from '../endpoint/endpoint-path.js';
|
|
3
3
|
/**
|
|
4
4
|
* Given a raw path or URL, finds an endpoint or WebSocket path that will match in the given
|
|
5
5
|
* service. If no match is found, this returns `undefined`.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { IsEqual, SetRequired } from 'type-fest';
|
|
3
|
-
import { EndpointPathBase } from '../endpoint/endpoint-path.js';
|
|
4
|
-
import { EndpointDefinition, EndpointInit, WithFinalEndpointProps } from '../endpoint/endpoint.js';
|
|
5
|
-
import { NoParam } from '../util/no-param.js';
|
|
6
|
-
import { OriginRequirement } from '../util/origin.js';
|
|
7
|
-
import { WebSocketDefinition, WebSocketInit, WithFinalWebSocketProps } from '../web-socket/web-socket-definition.js';
|
|
8
|
-
import { MinimalService } from './minimal-service.js';
|
|
1
|
+
import { type Overwrite } from '@augment-vir/common';
|
|
2
|
+
import { type IsEqual, type SetRequired } from 'type-fest';
|
|
3
|
+
import { type EndpointPathBase } from '../endpoint/endpoint-path.js';
|
|
4
|
+
import { type EndpointDefinition, type EndpointInit, type WithFinalEndpointProps } from '../endpoint/endpoint.js';
|
|
5
|
+
import { type NoParam } from '../util/no-param.js';
|
|
6
|
+
import { type OriginRequirement } from '../util/origin.js';
|
|
7
|
+
import { type WebSocketDefinition, type WebSocketInit, type WithFinalWebSocketProps } from '../web-socket/web-socket-definition.js';
|
|
8
|
+
import { type MinimalService } from './minimal-service.js';
|
|
9
9
|
/**
|
|
10
10
|
* A string used for type errors triggered when an endpoint path is defined without a leading slash.
|
|
11
11
|
*
|
package/dist/util/origin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MaybePromise } from '@augment-vir/common';
|
|
1
|
+
import { type MaybePromise } from '@augment-vir/common';
|
|
2
2
|
/**
|
|
3
3
|
* Explicity denotes that any origin is allowed. Use {@link isAnyOrigin} to check if something is
|
|
4
4
|
* equal to this.
|
|
@@ -56,3 +56,27 @@ export declare const originRequirementShape: import("object-shape-tester").Shape
|
|
|
56
56
|
}]>, import("object-shape-tester").ShapeClass<[RegExpConstructor]>, () => void, import("object-shape-tester").ShapeOr<[string, import("object-shape-tester").ShapeExact<readonly [{
|
|
57
57
|
anyOrigin: boolean;
|
|
58
58
|
}]>, import("object-shape-tester").ShapeClass<[RegExpConstructor]>, () => void]>[]]>, false>;
|
|
59
|
+
/**
|
|
60
|
+
* - `boolean`: the origin was explicitly checked and passed (`true`) or failed (`false`)
|
|
61
|
+
* - `undefined`: no origin checking occurred
|
|
62
|
+
* - `AnyOrigin`: requirements explicitly allow any origin.
|
|
63
|
+
*/
|
|
64
|
+
export type OriginRequirementResult = boolean | undefined | AnyOrigin;
|
|
65
|
+
/**
|
|
66
|
+
* Checks the given origin against the given origin requirement and determine if the origin matches.
|
|
67
|
+
* See {@link OriginRequirementResult} for details on what each possible return value means.
|
|
68
|
+
*
|
|
69
|
+
* @category Internal
|
|
70
|
+
* @category Package : @rest-vir/define-service
|
|
71
|
+
* @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
|
|
72
|
+
*/
|
|
73
|
+
export declare function checkOriginRequirement(origin: string | undefined, originRequirement: OriginRequirement): Promise<OriginRequirementResult>;
|
|
74
|
+
/**
|
|
75
|
+
* Narrower version of {@link checkOriginRequirement} that simply returns `true` if the origin
|
|
76
|
+
* matched or `false` otherwise.
|
|
77
|
+
*
|
|
78
|
+
* @category Internal
|
|
79
|
+
* @category Package : @rest-vir/define-service
|
|
80
|
+
* @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
|
|
81
|
+
*/
|
|
82
|
+
export declare function matchesOriginRequirement(origin: string | undefined, originRequirement: NonNullable<OriginRequirement>): Promise<boolean>;
|
package/dist/util/origin.js
CHANGED
|
@@ -31,3 +31,53 @@ export function isAnyOrigin(input) {
|
|
|
31
31
|
export const originRequirementShape = defineShape(or(undefined, '', exact(AnyOrigin), classShape(RegExp), () => { }, [
|
|
32
32
|
or('', exact(AnyOrigin), classShape(RegExp), () => { }),
|
|
33
33
|
]));
|
|
34
|
+
/**
|
|
35
|
+
* Checks the given origin against the given origin requirement and determine if the origin matches.
|
|
36
|
+
* See {@link OriginRequirementResult} for details on what each possible return value means.
|
|
37
|
+
*
|
|
38
|
+
* @category Internal
|
|
39
|
+
* @category Package : @rest-vir/define-service
|
|
40
|
+
* @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
|
|
41
|
+
*/
|
|
42
|
+
export async function checkOriginRequirement(origin, originRequirement) {
|
|
43
|
+
if (isAnyOrigin(originRequirement)) {
|
|
44
|
+
/** Any origin has been explicitly allowed. */
|
|
45
|
+
return AnyOrigin;
|
|
46
|
+
}
|
|
47
|
+
else if (originRequirement === undefined) {
|
|
48
|
+
/** No checking occurred. */
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
else if (!origin) {
|
|
52
|
+
/** If there is an origin requirement but no origin then the origin automatically fails. */
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
else if (check.isString(originRequirement)) {
|
|
56
|
+
return origin === originRequirement;
|
|
57
|
+
}
|
|
58
|
+
else if (check.instanceOf(originRequirement, RegExp)) {
|
|
59
|
+
return !!originRequirement.exec(origin);
|
|
60
|
+
}
|
|
61
|
+
else if (check.isArray(originRequirement)) {
|
|
62
|
+
for (const requirement of originRequirement) {
|
|
63
|
+
if (await checkOriginRequirement(origin, requirement)) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return await originRequirement(origin);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Narrower version of {@link checkOriginRequirement} that simply returns `true` if the origin
|
|
75
|
+
* matched or `false` otherwise.
|
|
76
|
+
*
|
|
77
|
+
* @category Internal
|
|
78
|
+
* @category Package : @rest-vir/define-service
|
|
79
|
+
* @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
|
|
80
|
+
*/
|
|
81
|
+
export async function matchesOriginRequirement(origin, originRequirement) {
|
|
82
|
+
return !!(await checkOriginRequirement(origin, originRequirement));
|
|
83
|
+
}
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* This file was copied from
|
|
6
6
|
* https://github.com/pillarjs/path-to-regexp/blob/39e861d02d959ba99d0632af994ab48d4a8eeb14/src/index.ts
|
|
7
7
|
* because its published package on Npm is not browser friendly. It has been modified here to remove
|
|
8
|
-
* all code not used in rest-vir and to meet rest-vir's coding standards.
|
|
8
|
+
* all code not used in rest-vir and to meet rest-vir's coding standards. It has also been modified
|
|
9
|
+
* to not require wildcard names.
|
|
9
10
|
*
|
|
10
11
|
* The original package and file source have the following license:
|
|
11
12
|
*
|
|
@@ -99,8 +100,7 @@ function* lexer(str) {
|
|
|
99
100
|
yield { type: 'PARAM', index: i, value };
|
|
100
101
|
}
|
|
101
102
|
else if (value === '*') {
|
|
102
|
-
|
|
103
|
-
yield { type: 'WILDCARD', index: i, value };
|
|
103
|
+
yield { type: 'WILDCARD', index: i++, value: '*' };
|
|
104
104
|
}
|
|
105
105
|
else {
|
|
106
106
|
yield { type: 'CHAR', index: i, value: chars[i++] };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { MaybePromise, Overwrite, SelectFrom } from '@augment-vir/common';
|
|
1
|
+
import { type MaybePromise, type Overwrite, type SelectFrom } from '@augment-vir/common';
|
|
2
2
|
import { type AnyDuration } from 'date-vir';
|
|
3
|
-
import type
|
|
4
|
-
import { NoParam } from '../util/no-param.js';
|
|
5
|
-
import { CommonWebSocket, CommonWebSocketEventMap } from './common-web-socket.js';
|
|
3
|
+
import { type HasRequiredKeys } from 'type-fest';
|
|
4
|
+
import { type NoParam } from '../util/no-param.js';
|
|
5
|
+
import { type CommonWebSocket, type CommonWebSocketEventMap } from './common-web-socket.js';
|
|
6
6
|
import { type WebSocketDefinition } from './web-socket-definition.js';
|
|
7
7
|
/**
|
|
8
8
|
* Location of the WebSocket in question: on a client connecting to a WebSocket host or on the host
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { AnyObject, Overwrite, type SelectFrom } from '@augment-vir/common';
|
|
2
|
-
import { ShapeDefinition, ShapeToRuntimeType } from 'object-shape-tester';
|
|
3
|
-
import type
|
|
4
|
-
import { EndpointPathBase } from '../endpoint/endpoint-path.js';
|
|
5
|
-
import { MinimalService } from '../service/minimal-service.js';
|
|
6
|
-
import { NoParam } from '../util/no-param.js';
|
|
7
|
-
import { OriginRequirement } from '../util/origin.js';
|
|
8
|
-
import type
|
|
1
|
+
import { type AnyObject, type Overwrite, type SelectFrom } from '@augment-vir/common';
|
|
2
|
+
import { type ShapeDefinition, type ShapeToRuntimeType } from 'object-shape-tester';
|
|
3
|
+
import { type IsEqual } from 'type-fest';
|
|
4
|
+
import { type EndpointPathBase } from '../endpoint/endpoint-path.js';
|
|
5
|
+
import { type MinimalService } from '../service/minimal-service.js';
|
|
6
|
+
import { type NoParam } from '../util/no-param.js';
|
|
7
|
+
import { type OriginRequirement } from '../util/origin.js';
|
|
8
|
+
import { type BaseSearchParams } from '../util/search-params.js';
|
|
9
9
|
/**
|
|
10
10
|
* Initialization for a WebSocket within a service definition..
|
|
11
11
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rest-vir/define-service",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Define an connect to a declarative and type safe REST and WebSocket service.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rest",
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
"test:update": "npm test update"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@augment-vir/assert": "^31.
|
|
44
|
-
"@augment-vir/common": "^31.
|
|
43
|
+
"@augment-vir/assert": "^31.16.0",
|
|
44
|
+
"@augment-vir/common": "^31.16.0",
|
|
45
45
|
"date-vir": "^7.3.1",
|
|
46
|
-
"type-fest": "^4.40.
|
|
46
|
+
"type-fest": "^4.40.1",
|
|
47
47
|
"url-vir": "^2.1.3"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@augment-vir/test": "^31.
|
|
50
|
+
"@augment-vir/test": "^31.16.0",
|
|
51
51
|
"@web/dev-server-esbuild": "^1.0.4",
|
|
52
52
|
"@web/test-runner": "^0.20.1",
|
|
53
53
|
"@web/test-runner-commands": "^0.9.0",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"markdown-code-example-inserter": "^3.0.3",
|
|
58
58
|
"object-shape-tester": "^5.1.5",
|
|
59
59
|
"typedoc": "^0.28.3",
|
|
60
|
-
"ws": "^8.18.
|
|
60
|
+
"ws": "^8.18.2"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"object-shape-tester": ">=5"
|