@rest-vir/run-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.
@@ -1,7 +1,7 @@
1
1
  import { type HttpStatus, type MaybePromise, type PartialWithUndefined } from '@augment-vir/common';
2
- import { ServerRequest, ServerResponse, type ImplementedEndpoint, type ImplementedWebSocket } from '@rest-vir/implement-service';
3
- import type { FastifyReply } from 'fastify';
4
- import { OutgoingHttpHeaders } from 'node:http';
2
+ import { type ImplementedEndpoint, type ImplementedWebSocket, type ServerRequest, type ServerResponse } from '@rest-vir/implement-service';
3
+ import { type FastifyReply } from 'fastify';
4
+ import { type OutgoingHttpHeaders } from 'node:http';
5
5
  /**
6
6
  * Options for `handleRoute`.
7
7
  *
@@ -1,5 +1,5 @@
1
- import { SelectFrom } from '@augment-vir/common';
2
- import { EndpointHandlerParams, HandledOutput } from './endpoint-handler.js';
1
+ import { type SelectFrom } from '@augment-vir/common';
2
+ import { type EndpointHandlerParams, type HandledOutput } from './endpoint-handler.js';
3
3
  /**
4
4
  * Determines the required origin for the endpoint and compares it with the given request.
5
5
  *
@@ -1,6 +1,5 @@
1
- import { check } from '@augment-vir/assert';
2
1
  import { HttpMethod } from '@augment-vir/common';
3
- import { AnyOrigin, getAllowedEndpointMethods, isAnyOrigin, restVirServiceNameHeader, } from '@rest-vir/define-service';
2
+ import { AnyOrigin, checkOriginRequirement, getAllowedEndpointMethods, isAnyOrigin, restVirServiceNameHeader, } from '@rest-vir/define-service';
4
3
  import { HttpStatus, RestVirHandlerError } from '@rest-vir/implement-service';
5
4
  import { convertDuration } from 'date-vir';
6
5
  /**
@@ -93,7 +92,7 @@ function buildOptionsRequestCorsHeaders(matchedOrigin, allowedMethods, customHea
93
92
  };
94
93
  }
95
94
  async function matchOrigin(endpoint, origin) {
96
- const endpointRequirement = await checkOriginRequirement(endpoint.requiredClientOrigin, origin);
95
+ const endpointRequirement = await checkOriginRequirement(origin, endpoint.requiredClientOrigin);
97
96
  if (isAnyOrigin(endpointRequirement)) {
98
97
  return AnyOrigin;
99
98
  }
@@ -104,7 +103,7 @@ async function matchOrigin(endpoint, origin) {
104
103
  return origin;
105
104
  }
106
105
  /** If the endpoint requirement is `undefined`, then we check the service requirement. */
107
- const serviceRequirement = await checkOriginRequirement(endpoint.service.requiredClientOrigin, origin);
106
+ const serviceRequirement = await checkOriginRequirement(origin, endpoint.service.requiredClientOrigin);
108
107
  if (isAnyOrigin(serviceRequirement)) {
109
108
  return AnyOrigin;
110
109
  }
@@ -120,34 +119,3 @@ async function matchOrigin(endpoint, origin) {
120
119
  */
121
120
  throw new RestVirHandlerError(endpoint, `Request origin '${origin}' failed to get checked for endpoint '${endpoint.path}' or service '${endpoint.service.serviceName}'`);
122
121
  }
123
- async function checkOriginRequirement(originRequirement, origin) {
124
- if (isAnyOrigin(originRequirement)) {
125
- /** Any origin has been explicitly allowed. */
126
- return AnyOrigin;
127
- }
128
- else if (originRequirement === undefined) {
129
- /** No checking occurred. */
130
- return undefined;
131
- }
132
- else if (!origin) {
133
- /** If there is an origin requirement but no origin then the origin automatically fails. */
134
- return false;
135
- }
136
- else if (check.isString(originRequirement)) {
137
- return origin === originRequirement;
138
- }
139
- else if (check.instanceOf(originRequirement, RegExp)) {
140
- return !!originRequirement.exec(origin);
141
- }
142
- else if (check.isArray(originRequirement)) {
143
- for (const requirement of originRequirement) {
144
- if (await checkOriginRequirement(requirement, origin)) {
145
- return true;
146
- }
147
- }
148
- return false;
149
- }
150
- else {
151
- return await originRequirement(origin);
152
- }
153
- }
@@ -1,5 +1,5 @@
1
- import { ImplementedEndpoint, type RunningServerInfo } from '@rest-vir/implement-service';
2
- import { EndpointHandlerParams, type HandledOutput } from './endpoint-handler.js';
1
+ import { type ImplementedEndpoint, type RunningServerInfo } from '@rest-vir/implement-service';
2
+ import { type EndpointHandlerParams, type HandledOutput } from './endpoint-handler.js';
3
3
  /**
4
4
  * Handles an endpoint's implementation execution.
5
5
  *
@@ -1,5 +1,5 @@
1
- import { SelectFrom } from '@augment-vir/common';
2
- import { HandledOutput, type EndpointHandlerParams } from './endpoint-handler.js';
1
+ import { type SelectFrom } from '@augment-vir/common';
2
+ import { type EndpointHandlerParams, type HandledOutput } from './endpoint-handler.js';
3
3
  /**
4
4
  * Verifies that a request's method matches the given endpoint's expectations. If it does not, an
5
5
  * error response is sent.
@@ -1,6 +1,6 @@
1
- import { ImplementedEndpoint, ImplementedWebSocket, RunningServerInfo, ServerRequest, ServerResponse } from '@rest-vir/implement-service';
1
+ import { type ImplementedEndpoint, type ImplementedWebSocket, type RunningServerInfo, type ServerRequest, type ServerResponse } from '@rest-vir/implement-service';
2
2
  import { type WebSocket as WsWebSocket } from 'ws';
3
- import { HandleRouteOptions } from './endpoint-handler.js';
3
+ import { type HandleRouteOptions } from './endpoint-handler.js';
4
4
  /**
5
5
  * Handles a WebSocket or Endpoint request.
6
6
  *
@@ -1,5 +1,5 @@
1
1
  import { type ErrorHttpStatusCategories, type HttpStatusByCategory, type SelectFrom } from '@augment-vir/common';
2
- import type { BaseSearchParams } from '@rest-vir/define-service';
2
+ import { type BaseSearchParams } from '@rest-vir/define-service';
3
3
  import { type ImplementedEndpoint, type ImplementedWebSocket, type ServerRequest } from '@rest-vir/implement-service';
4
4
  /**
5
5
  * Handles a request's search params and compares it against the route's required search params
@@ -1,4 +1,4 @@
1
- import { ImplementedWebSocket, ServerRequest, type RunningServerInfo } from '@rest-vir/implement-service';
1
+ import { type ImplementedWebSocket, type RunningServerInfo, type ServerRequest } from '@rest-vir/implement-service';
2
2
  import { type WebSocket as WsWebSocket } from 'ws';
3
3
  /**
4
4
  * Handles a WebSocket request.
@@ -1,5 +1,5 @@
1
1
  import { type SelectFrom } from '@augment-vir/common';
2
- import { GenericServiceImplementation, RunningServerInfo, ServerRequest, ServerResponse } from '@rest-vir/implement-service';
2
+ import { type GenericServiceImplementation, type RunningServerInfo, type ServerRequest, type ServerResponse } from '@rest-vir/implement-service';
3
3
  import { type FastifyReply } from 'fastify';
4
4
  /**
5
5
  * Handles a request before it gets to the actual route handlers.
@@ -1,8 +1,8 @@
1
- import { SelectFrom } from '@augment-vir/common';
2
- import type { BaseSearchParams, MinimalService } from '@rest-vir/define-service';
3
- import { GenericServiceImplementation, type RunningServerInfo } from '@rest-vir/implement-service';
1
+ import { type SelectFrom } from '@augment-vir/common';
2
+ import { type BaseSearchParams, type MinimalService } from '@rest-vir/define-service';
3
+ import { type GenericServiceImplementation, type RunningServerInfo } from '@rest-vir/implement-service';
4
4
  import { type FastifyInstance } from 'fastify';
5
- import { HandleRouteOptions } from '../handle-request/endpoint-handler.js';
5
+ import { type HandleRouteOptions } from '../handle-request/endpoint-handler.js';
6
6
  declare module 'fastify' {
7
7
  interface FastifyRequest {
8
8
  restVirContext: {
@@ -1,8 +1,8 @@
1
1
  import { type SelectFrom } from '@augment-vir/common';
2
- import { GenericServiceImplementation } from '@rest-vir/implement-service';
2
+ import { type GenericServiceImplementation } from '@rest-vir/implement-service';
3
3
  import { ClusterManager, type WorkerRunner } from 'cluster-vir';
4
4
  import { type FastifyInstance, type FastifyPluginCallback } from 'fastify';
5
- import { StartServiceUserOptions } from './start-service-options.js';
5
+ import { type StartServiceUserOptions } from './start-service-options.js';
6
6
  /**
7
7
  * Output of {@link startService}.
8
8
  *
@@ -1,4 +1,4 @@
1
- import { CollapsedFetchEndpointParams, EndpointDefinition } from '@rest-vir/define-service';
1
+ import { type CollapsedFetchEndpointParams, type EndpointDefinition } from '@rest-vir/define-service';
2
2
  /**
3
3
  * The type definition for {@link testEndpoint}.
4
4
  *
@@ -1,9 +1,9 @@
1
1
  import { type Overwrite, type PartialWithUndefined, type SelectFrom } from '@augment-vir/common';
2
- import { ClientWebSocket, CollapsedConnectWebSocketParams, CollapsedFetchEndpointParams, EndpointDefinition, WebSocketDefinition } from '@rest-vir/define-service';
3
- import { GenericServiceImplementation } from '@rest-vir/implement-service';
4
- import { FastifyInstance } from 'fastify';
5
- import { HandleRouteOptions } from '../handle-request/endpoint-handler.js';
6
- import { StartServiceOptions, type StartServiceUserOptions } from '../start-service/start-service-options.js';
2
+ import { type ClientWebSocket, type CollapsedConnectWebSocketParams, type CollapsedFetchEndpointParams, type EndpointDefinition, type WebSocketDefinition } from '@rest-vir/define-service';
3
+ import { type GenericServiceImplementation } from '@rest-vir/implement-service';
4
+ import { type FastifyInstance } from 'fastify';
5
+ import { type HandleRouteOptions } from '../handle-request/endpoint-handler.js';
6
+ import { type StartServiceOptions, type StartServiceUserOptions } from '../start-service/start-service-options.js';
7
7
  /**
8
8
  * Options for {@link condenseResponse}.
9
9
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rest-vir/run-service",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Run a service defined by @rest-vir/define-service and implemented by @rest-vir/implement-service.",
5
5
  "keywords": [
6
6
  "rest",
@@ -39,25 +39,25 @@
39
39
  "test:update": "npm test update"
40
40
  },
41
41
  "dependencies": {
42
- "@augment-vir/assert": "^31.14.1",
43
- "@augment-vir/common": "^31.14.1",
44
- "@augment-vir/node": "^31.14.1",
42
+ "@augment-vir/assert": "^31.16.0",
43
+ "@augment-vir/common": "^31.16.0",
44
+ "@augment-vir/node": "^31.16.0",
45
45
  "@fastify/websocket": "^11.0.2",
46
- "@rest-vir/define-service": "^0.15.0",
47
- "@rest-vir/implement-service": "^0.15.0",
46
+ "@rest-vir/define-service": "^0.16.0",
47
+ "@rest-vir/implement-service": "^0.16.0",
48
48
  "cluster-vir": "^0.1.0",
49
49
  "date-vir": "^7.3.1",
50
50
  "fastify": "^5.3.2",
51
51
  "light-my-request": "^6.6.0",
52
- "portfinder": "^1.0.36",
53
- "type-fest": "^4.40.0",
52
+ "portfinder": "^1.0.37",
53
+ "type-fest": "^4.40.1",
54
54
  "url-vir": "^2.1.3"
55
55
  },
56
56
  "devDependencies": {
57
- "@augment-vir/test": "^31.14.1",
57
+ "@augment-vir/test": "^31.16.0",
58
58
  "@fastify/multipart": "^9.0.3",
59
59
  "@types/connect": "^3.4.38",
60
- "@types/node": "^22.14.1",
60
+ "@types/node": "^22.15.3",
61
61
  "@types/ws": "^8.18.1",
62
62
  "c8": "^10.1.3",
63
63
  "istanbul-smart-text-reporter": "^1.1.5",