@rest-vir/implement-service 0.4.0 → 0.5.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.
|
@@ -29,6 +29,7 @@ export type GenericServiceImplementation = Omit<ServiceDefinition, 'endpoints' |
|
|
|
29
29
|
webSockets: Record<EndpointPathBase, ImplementedWebSocket>;
|
|
30
30
|
createContext: ContextInit<any, any, any, any> | undefined;
|
|
31
31
|
logger: ServiceLogger;
|
|
32
|
+
customHeaders: string[];
|
|
32
33
|
};
|
|
33
34
|
/**
|
|
34
35
|
* A fully implemented WebSocket.
|
|
@@ -22,6 +22,8 @@ export type CustomErrorHandler = (error: Error) => MaybePromise<void>;
|
|
|
22
22
|
* @package [`@rest-vir/implement-service`](https://www.npmjs.com/package/@rest-vir/implement-service)
|
|
23
23
|
*/
|
|
24
24
|
export type ServiceImplementationInit<Context, ServiceName extends string, EndpointsInit extends BaseServiceEndpointsInit, WebSocketsInit extends BaseServiceWebSocketsInit> = {
|
|
25
|
+
/** Set all custom headers that you'll be using here so that CORS will allow them. */
|
|
26
|
+
customHeaders?: string[];
|
|
25
27
|
service: ServiceDefinition<ServiceName, EndpointsInit, WebSocketsInit>;
|
|
26
28
|
/**
|
|
27
29
|
* Logger for the service. Use {@link silentServiceLogger} to disable logging entirely (even
|
|
@@ -62,7 +64,7 @@ export type ServiceImplementationsParams<Context, ServiceName extends string, En
|
|
|
62
64
|
*/
|
|
63
65
|
export declare function implementService<const ServiceName extends string, const EndpointsInit extends BaseServiceEndpointsInit, const WebSocketsInit extends BaseServiceWebSocketsInit, const Context = undefined>(
|
|
64
66
|
/** Init must be first so that TypeScript can infer the type for `Context`. */
|
|
65
|
-
{ service, createContext, logger, }: ServiceImplementationInit<Context, ServiceName, EndpointsInit, WebSocketsInit>, { endpoints: endpointImplementations, webSockets: webSocketImplementations, }: ServiceImplementationsParams<NoInfer<Context>, NoInfer<ServiceName>, NoInfer<EndpointsInit>, NoInfer<WebSocketsInit>>): ServiceImplementation<Context, ServiceName, EndpointsInit, WebSocketsInit>;
|
|
67
|
+
{ service, createContext, logger, customHeaders, }: ServiceImplementationInit<Context, ServiceName, EndpointsInit, WebSocketsInit>, { endpoints: endpointImplementations, webSockets: webSocketImplementations, }: ServiceImplementationsParams<NoInfer<Context>, NoInfer<ServiceName>, NoInfer<EndpointsInit>, NoInfer<WebSocketsInit>>): ServiceImplementation<Context, ServiceName, EndpointsInit, WebSocketsInit>;
|
|
66
68
|
/**
|
|
67
69
|
* A finalized service implementation created by {@link implementService}.
|
|
68
70
|
*
|
|
@@ -79,6 +81,7 @@ export type ServiceImplementation<Context = any, ServiceName extends string = an
|
|
|
79
81
|
};
|
|
80
82
|
createContext: ContextInit<Context, ServiceName, EndpointsInit, WebSocketsInit> | undefined;
|
|
81
83
|
logger: ServiceLogger;
|
|
84
|
+
customHeaders: string[];
|
|
82
85
|
};
|
|
83
86
|
/**
|
|
84
87
|
* A type util that converts a {@link ServiceDefinition} instance type into its companion
|
|
@@ -15,7 +15,7 @@ import { assertValidWebSocketImplementations, } from './implement-web-socket.js'
|
|
|
15
15
|
*/
|
|
16
16
|
export function implementService(
|
|
17
17
|
/** Init must be first so that TypeScript can infer the type for `Context`. */
|
|
18
|
-
{ service, createContext, logger, }, { endpoints: endpointImplementations, webSockets: webSocketImplementations, }) {
|
|
18
|
+
{ service, createContext, logger, customHeaders, }, { endpoints: endpointImplementations, webSockets: webSocketImplementations, }) {
|
|
19
19
|
assertValidEndpointImplementations(service, endpointImplementations || {});
|
|
20
20
|
assertValidWebSocketImplementations(service, webSocketImplementations || {});
|
|
21
21
|
const endpoints = mapObjectValues(service.endpoints, (endpointPath, endpoint) => {
|
|
@@ -48,6 +48,7 @@ export function implementService(
|
|
|
48
48
|
});
|
|
49
49
|
const serviceImplementation = {
|
|
50
50
|
...service,
|
|
51
|
+
customHeaders: customHeaders || [],
|
|
51
52
|
endpoints,
|
|
52
53
|
webSockets,
|
|
53
54
|
createContext,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rest-vir/implement-service",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Implement a service defined by @rest-vir/define-service.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rest",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@augment-vir/assert": "^31.9.4",
|
|
43
43
|
"@augment-vir/common": "^31.9.4",
|
|
44
|
-
"@rest-vir/define-service": "^0.
|
|
44
|
+
"@rest-vir/define-service": "^0.5.0",
|
|
45
45
|
"@types/ws": "^8.18.0",
|
|
46
46
|
"fastify": "^5.2.1",
|
|
47
47
|
"path-to-regexp": "^8.2.0",
|