@furystack/rest-service 12.3.5 → 14.0.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/CHANGELOG.md +55 -0
- package/README.md +47 -28
- package/esm/actions/get-current-user.spec.js +10 -6
- package/esm/actions/get-current-user.spec.js.map +1 -1
- package/esm/actions/index.d.ts +0 -1
- package/esm/actions/index.d.ts.map +1 -1
- package/esm/actions/index.js +0 -1
- package/esm/actions/index.js.map +1 -1
- package/esm/actions/is-authenticated.spec.js +10 -6
- package/esm/actions/is-authenticated.spec.js.map +1 -1
- package/esm/actions/logout-action.spec.js +11 -9
- package/esm/actions/logout-action.spec.js.map +1 -1
- package/esm/actions/logout.js +1 -1
- package/esm/actions/logout.js.map +1 -1
- package/esm/actions/password-login-action.js +1 -1
- package/esm/actions/password-login-action.js.map +1 -1
- package/esm/actions/password-login-action.spec.js +23 -28
- package/esm/actions/password-login-action.spec.js.map +1 -1
- package/esm/authenticate.js +1 -1
- package/esm/authenticate.js.map +1 -1
- package/esm/authenticate.spec.js +41 -33
- package/esm/authenticate.spec.js.map +1 -1
- package/esm/authorize.spec.js +34 -29
- package/esm/authorize.spec.js.map +1 -1
- package/esm/endpoint-generators/create-delete-endpoint.d.ts +6 -11
- package/esm/endpoint-generators/create-delete-endpoint.d.ts.map +1 -1
- package/esm/endpoint-generators/create-delete-endpoint.js +7 -11
- package/esm/endpoint-generators/create-delete-endpoint.js.map +1 -1
- package/esm/endpoint-generators/create-delete-endpoint.spec.js +14 -21
- package/esm/endpoint-generators/create-delete-endpoint.spec.js.map +1 -1
- package/esm/endpoint-generators/create-get-collection-endpoint.d.ts +11 -11
- package/esm/endpoint-generators/create-get-collection-endpoint.d.ts.map +1 -1
- package/esm/endpoint-generators/create-get-collection-endpoint.js +13 -12
- package/esm/endpoint-generators/create-get-collection-endpoint.js.map +1 -1
- package/esm/endpoint-generators/create-get-collection-endpoint.spec.js +43 -70
- package/esm/endpoint-generators/create-get-collection-endpoint.spec.js.map +1 -1
- package/esm/endpoint-generators/create-get-entity-endpoint.d.ts +6 -11
- package/esm/endpoint-generators/create-get-entity-endpoint.d.ts.map +1 -1
- package/esm/endpoint-generators/create-get-entity-endpoint.js +7 -11
- package/esm/endpoint-generators/create-get-entity-endpoint.js.map +1 -1
- package/esm/endpoint-generators/create-get-entity-endpoint.spec.js +16 -33
- package/esm/endpoint-generators/create-get-entity-endpoint.spec.js.map +1 -1
- package/esm/endpoint-generators/create-get-openapi-document-action.d.ts +1 -15
- package/esm/endpoint-generators/create-get-openapi-document-action.d.ts.map +1 -1
- package/esm/endpoint-generators/create-get-openapi-document-action.js +1 -24
- package/esm/endpoint-generators/create-get-openapi-document-action.js.map +1 -1
- package/esm/endpoint-generators/create-get-schema-action.d.ts +1 -1
- package/esm/endpoint-generators/create-get-schema-action.d.ts.map +1 -1
- package/esm/endpoint-generators/create-get-schema-action.js.map +1 -1
- package/esm/endpoint-generators/create-patch-endpoint.d.ts +7 -13
- package/esm/endpoint-generators/create-patch-endpoint.d.ts.map +1 -1
- package/esm/endpoint-generators/create-patch-endpoint.js +8 -13
- package/esm/endpoint-generators/create-patch-endpoint.js.map +1 -1
- package/esm/endpoint-generators/create-patch-endpoint.spec.js +10 -17
- package/esm/endpoint-generators/create-patch-endpoint.spec.js.map +1 -1
- package/esm/endpoint-generators/create-post-endpoint.d.ts +7 -13
- package/esm/endpoint-generators/create-post-endpoint.d.ts.map +1 -1
- package/esm/endpoint-generators/create-post-endpoint.js +8 -13
- package/esm/endpoint-generators/create-post-endpoint.js.map +1 -1
- package/esm/endpoint-generators/create-post-endpoint.spec.js +41 -14
- package/esm/endpoint-generators/create-post-endpoint.spec.js.map +1 -1
- package/esm/endpoint-generators/utils.d.ts +17 -2
- package/esm/endpoint-generators/utils.d.ts.map +1 -1
- package/esm/endpoint-generators/utils.js +33 -20
- package/esm/endpoint-generators/utils.js.map +1 -1
- package/esm/endpoint-generators/with-schema-and-openapi-action.d.ts +0 -2
- package/esm/endpoint-generators/with-schema-and-openapi-action.d.ts.map +1 -1
- package/esm/get-schema-from-api.d.ts +1 -1
- package/esm/get-schema-from-api.d.ts.map +1 -1
- package/esm/get-schema-from-api.spec.js.map +1 -1
- package/esm/helpers.d.ts +53 -87
- package/esm/helpers.d.ts.map +1 -1
- package/esm/helpers.js +91 -92
- package/esm/helpers.js.map +1 -1
- package/esm/helpers.spec.d.ts +2 -1
- package/esm/helpers.spec.d.ts.map +1 -1
- package/esm/helpers.spec.js +41 -38
- package/esm/helpers.spec.js.map +1 -1
- package/esm/http-authentication-settings.d.ts +35 -12
- package/esm/http-authentication-settings.d.ts.map +1 -1
- package/esm/http-authentication-settings.js +21 -29
- package/esm/http-authentication-settings.js.map +1 -1
- package/esm/http-server-pool.d.ts +64 -0
- package/esm/http-server-pool.d.ts.map +1 -0
- package/esm/http-server-pool.js +95 -0
- package/esm/http-server-pool.js.map +1 -0
- package/esm/http-server-pool.spec.d.ts +2 -0
- package/esm/http-server-pool.spec.d.ts.map +1 -0
- package/esm/http-server-pool.spec.js +193 -0
- package/esm/http-server-pool.spec.js.map +1 -0
- package/esm/http-user-context.d.ts +31 -44
- package/esm/http-user-context.d.ts.map +1 -1
- package/esm/http-user-context.js +76 -95
- package/esm/http-user-context.js.map +1 -1
- package/esm/http-user-context.spec.d.ts +8 -2
- package/esm/http-user-context.spec.d.ts.map +1 -1
- package/esm/http-user-context.spec.js +189 -337
- package/esm/http-user-context.spec.js.map +1 -1
- package/esm/index.d.ts +6 -4
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +6 -4
- package/esm/index.js.map +1 -1
- package/esm/login-response-strategy.d.ts +11 -10
- package/esm/login-response-strategy.d.ts.map +1 -1
- package/esm/login-response-strategy.js +7 -6
- package/esm/login-response-strategy.js.map +1 -1
- package/esm/login-response-strategy.spec.js +25 -29
- package/esm/login-response-strategy.spec.js.map +1 -1
- package/esm/openapi/generate-openapi-document.d.ts +0 -8
- package/esm/openapi/generate-openapi-document.d.ts.map +1 -1
- package/esm/openapi/generate-openapi-document.js +0 -2
- package/esm/openapi/generate-openapi-document.js.map +1 -1
- package/esm/proxy-manager.spec.js +152 -176
- package/esm/proxy-manager.spec.js.map +1 -1
- package/esm/proxy-runtime.d.ts +27 -0
- package/esm/proxy-runtime.d.ts.map +1 -0
- package/esm/proxy-runtime.js +45 -0
- package/esm/proxy-runtime.js.map +1 -0
- package/esm/proxy-runtime.spec.d.ts +2 -0
- package/esm/proxy-runtime.spec.d.ts.map +1 -0
- package/esm/proxy-runtime.spec.js +39 -0
- package/esm/proxy-runtime.spec.js.map +1 -0
- package/esm/rest-api-runtime.d.ts +76 -0
- package/esm/rest-api-runtime.d.ts.map +1 -0
- package/esm/rest-api-runtime.js +131 -0
- package/esm/rest-api-runtime.js.map +1 -0
- package/esm/rest-api-runtime.spec.d.ts +2 -0
- package/esm/rest-api-runtime.spec.d.ts.map +1 -0
- package/esm/rest-api-runtime.spec.js +58 -0
- package/esm/rest-api-runtime.spec.js.map +1 -0
- package/esm/rest-service.integration.spec.d.ts +1 -1
- package/esm/rest-service.integration.spec.d.ts.map +1 -1
- package/esm/rest-service.integration.spec.js +60 -82
- package/esm/rest-service.integration.spec.js.map +1 -1
- package/esm/rest.integration.test.js +26 -84
- package/esm/rest.integration.test.js.map +1 -1
- package/esm/server-telemetry.d.ts +57 -0
- package/esm/server-telemetry.d.ts.map +1 -0
- package/esm/server-telemetry.js +26 -0
- package/esm/server-telemetry.js.map +1 -0
- package/esm/server-telemetry.spec.d.ts +2 -0
- package/esm/server-telemetry.spec.d.ts.map +1 -0
- package/esm/server-telemetry.spec.js +52 -0
- package/esm/server-telemetry.spec.js.map +1 -0
- package/esm/static-server-manager.spec.js +60 -125
- package/esm/static-server-manager.spec.js.map +1 -1
- package/esm/static-site-runtime.d.ts +21 -0
- package/esm/static-site-runtime.d.ts.map +1 -0
- package/esm/static-site-runtime.js +48 -0
- package/esm/static-site-runtime.js.map +1 -0
- package/esm/static-site-runtime.spec.d.ts +2 -0
- package/esm/static-site-runtime.spec.d.ts.map +1 -0
- package/esm/static-site-runtime.spec.js +30 -0
- package/esm/static-site-runtime.spec.js.map +1 -0
- package/esm/user-store.d.ts +39 -0
- package/esm/user-store.d.ts.map +1 -0
- package/esm/user-store.js +62 -0
- package/esm/user-store.js.map +1 -0
- package/esm/user-store.spec.d.ts +2 -0
- package/esm/user-store.spec.d.ts.map +1 -0
- package/esm/user-store.spec.js +72 -0
- package/esm/user-store.spec.js.map +1 -0
- package/esm/validate.integration.spec.js +26 -83
- package/esm/validate.integration.spec.js.map +1 -1
- package/package.json +8 -8
- package/src/actions/get-current-user.spec.ts +11 -10
- package/src/actions/index.ts +0 -1
- package/src/actions/is-authenticated.spec.ts +12 -7
- package/src/actions/logout-action.spec.ts +12 -12
- package/src/actions/logout.ts +1 -1
- package/src/actions/password-login-action.spec.ts +30 -30
- package/src/actions/password-login-action.ts +1 -1
- package/src/authenticate.spec.ts +45 -51
- package/src/authenticate.ts +1 -1
- package/src/authorize.spec.ts +37 -39
- package/src/endpoint-generators/create-delete-endpoint.spec.ts +16 -24
- package/src/endpoint-generators/create-delete-endpoint.ts +11 -17
- package/src/endpoint-generators/create-get-collection-endpoint.spec.ts +45 -78
- package/src/endpoint-generators/create-get-collection-endpoint.ts +17 -19
- package/src/endpoint-generators/create-get-entity-endpoint.spec.ts +17 -33
- package/src/endpoint-generators/create-get-entity-endpoint.ts +11 -17
- package/src/endpoint-generators/create-get-openapi-document-action.ts +2 -38
- package/src/endpoint-generators/create-get-schema-action.ts +1 -1
- package/src/endpoint-generators/create-patch-endpoint.spec.ts +11 -18
- package/src/endpoint-generators/create-patch-endpoint.ts +12 -23
- package/src/endpoint-generators/create-post-endpoint.spec.ts +45 -14
- package/src/endpoint-generators/create-post-endpoint.ts +13 -23
- package/src/endpoint-generators/utils.ts +36 -28
- package/src/endpoint-generators/with-schema-and-openapi-action.ts +0 -3
- package/src/get-schema-from-api.spec.ts +1 -1
- package/src/get-schema-from-api.ts +1 -1
- package/src/helpers.spec.ts +51 -41
- package/src/helpers.ts +140 -109
- package/src/http-authentication-settings.ts +51 -25
- package/src/http-server-pool.spec.ts +220 -0
- package/src/http-server-pool.ts +169 -0
- package/src/http-user-context.spec.ts +203 -383
- package/src/http-user-context.ts +114 -91
- package/src/index.ts +6 -4
- package/src/login-response-strategy.spec.ts +32 -31
- package/src/login-response-strategy.ts +13 -12
- package/src/openapi/generate-openapi-document.ts +0 -3
- package/src/proxy-manager.spec.ts +152 -182
- package/src/proxy-runtime.spec.ts +50 -0
- package/src/proxy-runtime.ts +75 -0
- package/src/rest-api-runtime.spec.ts +77 -0
- package/src/rest-api-runtime.ts +204 -0
- package/src/rest-service.integration.spec.ts +68 -87
- package/src/rest.integration.test.ts +27 -87
- package/src/server-telemetry.spec.ts +56 -0
- package/src/server-telemetry.ts +51 -0
- package/src/static-server-manager.spec.ts +63 -151
- package/src/static-site-runtime.spec.ts +39 -0
- package/src/static-site-runtime.ts +75 -0
- package/src/user-store.spec.ts +86 -0
- package/src/user-store.ts +68 -0
- package/src/validate.integration.spec.ts +39 -97
- package/esm/actions/login-action.spec.d.ts +0 -2
- package/esm/actions/login-action.spec.d.ts.map +0 -1
- package/esm/actions/login-action.spec.js +0 -34
- package/esm/actions/login-action.spec.js.map +0 -1
- package/esm/actions/login.d.ts +0 -19
- package/esm/actions/login.d.ts.map +0 -1
- package/esm/actions/login.js +0 -27
- package/esm/actions/login.js.map +0 -1
- package/esm/api-manager.d.ts +0 -104
- package/esm/api-manager.d.ts.map +0 -1
- package/esm/api-manager.js +0 -180
- package/esm/api-manager.js.map +0 -1
- package/esm/proxy-manager.d.ts +0 -53
- package/esm/proxy-manager.d.ts.map +0 -1
- package/esm/proxy-manager.js +0 -84
- package/esm/proxy-manager.js.map +0 -1
- package/esm/server-manager.d.ts +0 -48
- package/esm/server-manager.d.ts.map +0 -1
- package/esm/server-manager.js +0 -100
- package/esm/server-manager.js.map +0 -1
- package/esm/static-server-manager.d.ts +0 -19
- package/esm/static-server-manager.d.ts.map +0 -1
- package/esm/static-server-manager.js +0 -65
- package/esm/static-server-manager.js.map +0 -1
- package/esm/swagger/generate-swagger-json.spec.d.ts +0 -2
- package/esm/swagger/generate-swagger-json.spec.d.ts.map +0 -1
- package/esm/swagger/generate-swagger-json.spec.js +0 -215
- package/esm/swagger/generate-swagger-json.spec.js.map +0 -1
- package/src/actions/login-action.spec.ts +0 -42
- package/src/actions/login.ts +0 -32
- package/src/api-manager.ts +0 -308
- package/src/proxy-manager.ts +0 -102
- package/src/server-manager.ts +0 -135
- package/src/static-server-manager.ts +0 -90
- package/src/swagger/generate-swagger-json.spec.ts +0 -250
|
@@ -1,38 +1,31 @@
|
|
|
1
1
|
import { getPort } from '@furystack/core/port-generator';
|
|
2
|
-
import {
|
|
3
|
-
import { getDataSetFor } from '@furystack/repository';
|
|
2
|
+
import { createInjector } from '@furystack/inject';
|
|
4
3
|
import { usingAsync } from '@furystack/utils';
|
|
5
4
|
import { describe, expect, it } from 'vitest';
|
|
6
5
|
import { useRestService } from '../helpers.js';
|
|
7
6
|
import { createPatchEndpoint } from './create-patch-endpoint.js';
|
|
8
|
-
import {
|
|
7
|
+
import { MockDataSet, setupContext } from './utils.js';
|
|
9
8
|
describe('createPatchEndpoint', () => {
|
|
10
|
-
it('
|
|
11
|
-
await usingAsync(
|
|
9
|
+
it('updates the entity and responds 200', async () => {
|
|
10
|
+
await usingAsync(createInjector(), async (i) => {
|
|
12
11
|
setupContext(i);
|
|
13
12
|
const port = getPort();
|
|
14
13
|
await useRestService({
|
|
15
14
|
injector: i,
|
|
16
15
|
root: '/api',
|
|
17
16
|
port,
|
|
18
|
-
api: {
|
|
19
|
-
PATCH: {
|
|
20
|
-
'/:id': createPatchEndpoint({ model: MockClass, primaryKey: 'id' }),
|
|
21
|
-
},
|
|
22
|
-
},
|
|
17
|
+
api: { PATCH: { '/:id': createPatchEndpoint(MockDataSet) } },
|
|
23
18
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
expect(
|
|
19
|
+
const dataSet = i.get(MockDataSet);
|
|
20
|
+
await dataSet.add(i, { id: 'mock', value: 'mock' });
|
|
21
|
+
expect(await dataSet.count(i)).toBe(1);
|
|
27
22
|
const response = await fetch(`http://127.0.0.1:${port}/api/mock`, {
|
|
28
23
|
method: 'PATCH',
|
|
29
24
|
body: JSON.stringify({ value: 'updated' }),
|
|
30
25
|
});
|
|
31
26
|
expect(response.status).toBe(200);
|
|
32
|
-
|
|
33
|
-
expect(
|
|
34
|
-
const updated = await getDataSetFor(i, MockClass, 'id').get(i, 'mock');
|
|
35
|
-
expect(updated?.value).toBe('updated');
|
|
27
|
+
expect(await response.json()).toEqual({});
|
|
28
|
+
expect((await dataSet.get(i, 'mock'))?.value).toBe('updated');
|
|
36
29
|
});
|
|
37
30
|
});
|
|
38
31
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-patch-endpoint.spec.js","sourceRoot":"","sources":["../../src/endpoint-generators/create-patch-endpoint.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA;AACxD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"create-patch-endpoint.spec.js","sourceRoot":"","sources":["../../src/endpoint-generators/create-patch-endpoint.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAEhE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEtD,QAAQ,CAA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AC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import type { Constructable } from '@furystack/inject';
|
|
2
|
-
import type { PostEndpoint } from '@furystack/rest';
|
|
3
|
-
import '@furystack/repository';
|
|
4
|
-
import type { RequestAction } from '../request-action-implementation.js';
|
|
5
1
|
import type { WithOptionalId } from '@furystack/core';
|
|
2
|
+
import type { DataSetToken } from '@furystack/repository';
|
|
3
|
+
import type { PostEndpoint } from '@furystack/rest';
|
|
4
|
+
import { type RequestAction } from '../request-action-implementation.js';
|
|
6
5
|
/**
|
|
7
|
-
* Creates a POST endpoint
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @param options.primaryKey The field name used as primary key
|
|
11
|
-
* @returns a boolean that indicates the success
|
|
6
|
+
* Creates a POST endpoint that inserts a new entity into the DataSet
|
|
7
|
+
* resolved from `dataSet`. Returns `201 Created` on success; throws a
|
|
8
|
+
* `RequestError(404)` when the underlying store returns no created entity.
|
|
12
9
|
*/
|
|
13
|
-
export declare const createPostEndpoint: <T extends object, TPrimaryKey extends keyof T, TWritableData = WithOptionalId<T, TPrimaryKey>>(
|
|
14
|
-
model: Constructable<T>;
|
|
15
|
-
primaryKey: TPrimaryKey;
|
|
16
|
-
}) => RequestAction<PostEndpoint<T, TPrimaryKey, TWritableData>>;
|
|
10
|
+
export declare const createPostEndpoint: <T extends object, TPrimaryKey extends keyof T, TWritableData = WithOptionalId<T, TPrimaryKey>>(dataSet: DataSetToken<T, TPrimaryKey, TWritableData>) => RequestAction<PostEndpoint<T, TPrimaryKey, TWritableData>>;
|
|
17
11
|
//# sourceMappingURL=create-post-endpoint.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-post-endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/create-post-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"create-post-endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/create-post-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAGnD,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAEpF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAC7B,CAAC,SAAS,MAAM,EAChB,WAAW,SAAS,MAAM,CAAC,EAC3B,aAAa,GAAG,cAAc,CAAC,CAAC,EAAE,WAAW,CAAC,EAE9C,SAAS,YAAY,CAAC,CAAC,EAAE,WAAW,EAAE,aAAa,CAAC,KACnD,aAAa,CAAC,YAAY,CAAC,CAAC,EAAE,WAAW,EAAE,aAAa,CAAC,CAU3D,CAAA"}
|
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
import { RequestError } from '@furystack/rest';
|
|
2
|
-
import '@furystack/repository';
|
|
3
|
-
import { JsonResult } from '../request-action-implementation.js';
|
|
4
|
-
import { getRepository } from '@furystack/repository';
|
|
5
2
|
import { readPostBody } from '../read-post-body.js';
|
|
3
|
+
import { JsonResult } from '../request-action-implementation.js';
|
|
6
4
|
/**
|
|
7
|
-
* Creates a POST endpoint
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @param options.primaryKey The field name used as primary key
|
|
11
|
-
* @returns a boolean that indicates the success
|
|
5
|
+
* Creates a POST endpoint that inserts a new entity into the DataSet
|
|
6
|
+
* resolved from `dataSet`. Returns `201 Created` on success; throws a
|
|
7
|
+
* `RequestError(404)` when the underlying store returns no created entity.
|
|
12
8
|
*/
|
|
13
|
-
export const createPostEndpoint = (
|
|
14
|
-
|
|
15
|
-
const
|
|
9
|
+
export const createPostEndpoint = (dataSet) => {
|
|
10
|
+
return async ({ injector, request }) => {
|
|
11
|
+
const ds = injector.get(dataSet);
|
|
16
12
|
const entityToCreate = await readPostBody(request);
|
|
17
|
-
const { created } = await
|
|
13
|
+
const { created } = await ds.add(injector, entityToCreate);
|
|
18
14
|
if (!created || !created.length) {
|
|
19
15
|
throw new RequestError('Entity not found', 404);
|
|
20
16
|
}
|
|
21
17
|
return JsonResult(created[0], 201);
|
|
22
18
|
};
|
|
23
|
-
return endpoint;
|
|
24
19
|
};
|
|
25
20
|
//# sourceMappingURL=create-post-endpoint.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-post-endpoint.js","sourceRoot":"","sources":["../../src/endpoint-generators/create-post-endpoint.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-post-endpoint.js","sourceRoot":"","sources":["../../src/endpoint-generators/create-post-endpoint.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAsB,MAAM,qCAAqC,CAAA;AAEpF;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAKhC,OAAoD,EACQ,EAAE;IAC9D,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE;QACrC,MAAM,EAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAChC,MAAM,cAAc,GAAG,MAAM,YAAY,CAAgB,OAAO,CAAC,CAAA;QACjE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;QAC1D,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YAChC,MAAM,IAAI,YAAY,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAA;QACjD,CAAC;QACD,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACpC,CAAC,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
import { getPort } from '@furystack/core/port-generator';
|
|
2
|
-
import {
|
|
3
|
-
import { getDataSetFor } from '@furystack/repository';
|
|
2
|
+
import { createInjector } from '@furystack/inject';
|
|
4
3
|
import { usingAsync } from '@furystack/utils';
|
|
5
4
|
import { describe, expect, it } from 'vitest';
|
|
6
5
|
import { useRestService } from '../helpers.js';
|
|
7
6
|
import { createPostEndpoint } from './create-post-endpoint.js';
|
|
8
|
-
import {
|
|
7
|
+
import { MockDataSet, MockStore, setupContext } from './utils.js';
|
|
9
8
|
describe('createPostEndpoint', () => {
|
|
10
|
-
it('
|
|
11
|
-
await usingAsync(
|
|
9
|
+
it('creates the entity and responds 201', async () => {
|
|
10
|
+
await usingAsync(createInjector(), async (i) => {
|
|
12
11
|
setupContext(i);
|
|
13
12
|
const port = getPort();
|
|
14
13
|
await useRestService({
|
|
15
14
|
injector: i,
|
|
16
15
|
root: '/api',
|
|
17
16
|
port,
|
|
18
|
-
api: {
|
|
19
|
-
POST: {
|
|
20
|
-
'/': createPostEndpoint({ model: MockClass, primaryKey: 'id' }),
|
|
21
|
-
},
|
|
22
|
-
},
|
|
17
|
+
api: { POST: { '/': createPostEndpoint(MockDataSet) } },
|
|
23
18
|
});
|
|
24
19
|
const entityToPost = { id: 'mock', value: 'posted' };
|
|
25
20
|
const response = await fetch(`http://127.0.0.1:${port}/api`, {
|
|
@@ -27,10 +22,42 @@ describe('createPostEndpoint', () => {
|
|
|
27
22
|
body: JSON.stringify(entityToPost),
|
|
28
23
|
});
|
|
29
24
|
expect(response.status).toBe(201);
|
|
30
|
-
|
|
31
|
-
expect(
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
expect(await response.json()).toEqual(entityToPost);
|
|
26
|
+
expect((await i.get(MockDataSet).get(i, entityToPost.id))?.value).toBe('posted');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
it('responds 404 when the underlying data set returned no created entity', async () => {
|
|
30
|
+
await usingAsync(createInjector(), async (i) => {
|
|
31
|
+
setupContext(i);
|
|
32
|
+
// Swap the dataset binding for a stub whose `add` comes back empty --
|
|
33
|
+
// this is the only way to exercise the `!created.length` branch.
|
|
34
|
+
i.bind(MockDataSet, () => ({ add: async () => ({ created: [] }) }));
|
|
35
|
+
const port = getPort();
|
|
36
|
+
await useRestService({
|
|
37
|
+
injector: i,
|
|
38
|
+
root: '/api',
|
|
39
|
+
port,
|
|
40
|
+
api: { POST: { '/': createPostEndpoint(MockDataSet) } },
|
|
41
|
+
});
|
|
42
|
+
const response = await fetch(`http://127.0.0.1:${port}/api`, {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
body: JSON.stringify({ id: 'mock', value: 'x' }),
|
|
45
|
+
});
|
|
46
|
+
expect(response.status).toBe(404);
|
|
47
|
+
expect(await response.json()).toEqual({ message: 'Entity not found' });
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('endpoint-generators/utils', () => {
|
|
52
|
+
it('MockStore throws from its default factory when setupContext was not called', async () => {
|
|
53
|
+
await usingAsync(createInjector(), async (i) => {
|
|
54
|
+
expect(() => i.get(MockStore)).toThrow(/MockStore is not configured/);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
it('setupContext binds MockStore in-memory so the default factory is bypassed', async () => {
|
|
58
|
+
await usingAsync(createInjector(), async (i) => {
|
|
59
|
+
setupContext(i);
|
|
60
|
+
expect(i.get(MockStore)).toBeDefined();
|
|
34
61
|
});
|
|
35
62
|
});
|
|
36
63
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-post-endpoint.spec.js","sourceRoot":"","sources":["../../src/endpoint-generators/create-post-endpoint.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA;AACxD,OA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,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACjC,MAAM,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAAC,CAAA;QACxE,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACzC,EAAE,CAAC,4EAA4E,EAAE,KAAK,IAAI,EAAE;QAC1F,MAAM,UAAU,CAAC,cAAc,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YAC7C,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC,CAAA;QACvE,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,2EAA2E,EAAE,KAAK,IAAI,EAAE;QACzF,MAAM,UAAU,CAAC,cAAc,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YAC7C,YAAY,CAAC,CAAC,CAAC,CAAA;YACf,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;QACxC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import type { Injector } from '@furystack/inject';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Mock entity used by endpoint-generator specs.
|
|
4
|
+
*/
|
|
4
5
|
export declare class MockClass {
|
|
5
6
|
id: string;
|
|
6
7
|
value: string;
|
|
7
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Store token for {@link MockClass}. The default factory throws so each spec
|
|
11
|
+
* explicitly opts into an in-memory backing via `setupContext`.
|
|
12
|
+
*/
|
|
13
|
+
export declare const MockStore: import("@furystack/core").StoreToken<MockClass, "id">;
|
|
14
|
+
/**
|
|
15
|
+
* Data set token over {@link MockStore}.
|
|
16
|
+
*/
|
|
17
|
+
export declare const MockDataSet: import("@furystack/repository").DataSetToken<MockClass, "id", import("@furystack/core").WithOptionalId<MockClass, "id">>;
|
|
18
|
+
/**
|
|
19
|
+
* Binds in-memory implementations of {@link UserStore}, {@link SessionStore}
|
|
20
|
+
* and {@link MockStore} on the provided injector. Endpoint-generator specs
|
|
21
|
+
* and integration tests call this at setup time.
|
|
22
|
+
*/
|
|
8
23
|
export declare const setupContext: (i: Injector) => void;
|
|
9
24
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAKjD;;GAEG;AACH,qBAAa,SAAS;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;CACtB;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,uDAOpB,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,0HAGtB,CAAA;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,GAAG,QAAQ,KAAG,IAI1C,CAAA"}
|
|
@@ -1,26 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineStore, InMemoryStore, User } from '@furystack/core';
|
|
2
|
+
import { defineDataSet } from '@furystack/repository';
|
|
2
3
|
import { DefaultSession } from '../models/default-session.js';
|
|
3
|
-
import '
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { SessionStore, UserStore } from '../user-store.js';
|
|
5
|
+
/**
|
|
6
|
+
* Mock entity used by endpoint-generator specs.
|
|
7
|
+
*/
|
|
6
8
|
export class MockClass {
|
|
7
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Store token for {@link MockClass}. The default factory throws so each spec
|
|
12
|
+
* explicitly opts into an in-memory backing via `setupContext`.
|
|
13
|
+
*/
|
|
14
|
+
export const MockStore = defineStore({
|
|
15
|
+
name: 'test/MockStore',
|
|
16
|
+
model: MockClass,
|
|
17
|
+
primaryKey: 'id',
|
|
18
|
+
factory: () => {
|
|
19
|
+
throw new Error('MockStore is not configured in this injector');
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Data set token over {@link MockStore}.
|
|
24
|
+
*/
|
|
25
|
+
export const MockDataSet = defineDataSet({
|
|
26
|
+
name: 'test/MockDataSet',
|
|
27
|
+
store: MockStore,
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Binds in-memory implementations of {@link UserStore}, {@link SessionStore}
|
|
31
|
+
* and {@link MockStore} on the provided injector. Endpoint-generator specs
|
|
32
|
+
* and integration tests call this at setup time.
|
|
33
|
+
*/
|
|
8
34
|
export const setupContext = (i) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}))
|
|
13
|
-
.addStore(new InMemoryStore({
|
|
14
|
-
model: User,
|
|
15
|
-
primaryKey: 'username',
|
|
16
|
-
}))
|
|
17
|
-
.addStore(new InMemoryStore({
|
|
18
|
-
model: DefaultSession,
|
|
19
|
-
primaryKey: 'sessionId',
|
|
20
|
-
}));
|
|
21
|
-
getRepository(i)
|
|
22
|
-
.createDataSet(MockClass, 'id')
|
|
23
|
-
.createDataSet(User, 'username')
|
|
24
|
-
.createDataSet(DefaultSession, 'sessionId');
|
|
35
|
+
i.bind(UserStore, () => new InMemoryStore({ model: User, primaryKey: 'username' }));
|
|
36
|
+
i.bind(SessionStore, () => new InMemoryStore({ model: DefaultSession, primaryKey: 'sessionId' }));
|
|
37
|
+
i.bind(MockStore, () => new InMemoryStore({ model: MockClass, primaryKey: 'id' }));
|
|
25
38
|
};
|
|
26
39
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/endpoint-generators/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/endpoint-generators/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAElE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAE1D;;GAEG;AACH,MAAM,OAAO,SAAS;CAGrB;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC;IACnC,IAAI,EAAE,gBAAgB;IACtB,KAAK,EAAE,SAAS;IAChB,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,GAAG,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;IACjE,CAAC;CACF,CAAC,CAAA;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC;IACvC,IAAI,EAAE,kBAAkB;IACxB,KAAK,EAAE,SAAS;CACjB,CAAC,CAAA;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAW,EAAQ,EAAE;IAChD,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,aAAa,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,CAAA;IACnF,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,aAAa,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC,CAAA;IACjG,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,aAAa,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AACpF,CAAC,CAAA"}
|
|
@@ -18,6 +18,4 @@ export type WithSchemaAndOpenApiAction<T extends RestApi> = T & {
|
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
-
/** @deprecated Use WithSchemaAndOpenApiAction instead */
|
|
22
|
-
export type WithSchemaAndSwaggerAction<T extends RestApi> = WithSchemaAndOpenApiAction<T>;
|
|
23
21
|
//# sourceMappingURL=with-schema-and-openapi-action.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-schema-and-openapi-action.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/with-schema-and-openapi-action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAElF;;GAEG;AACH,MAAM,MAAM,0BAA0B,CAAC,CAAC,SAAS,OAAO,IAAI,CAAC,GAAG;IAC9D,GAAG,EAAE;QACH,SAAS,EAAE;YAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;YAAC,OAAO,EAAE;gBAAE,MAAM,EAAE,yBAAyB,CAAA;aAAE,CAAA;SAAE,CAAA;QAC3F,eAAe,EAAE;YAAE,MAAM,EAAE,eAAe,CAAC;YAAC,OAAO,EAAE;gBAAE,MAAM,EAAE,kBAAkB,CAAA;aAAE,CAAA;SAAE,CAAA;KACtF,CAAA;CACF,CAAA
|
|
1
|
+
{"version":3,"file":"with-schema-and-openapi-action.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/with-schema-and-openapi-action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAElF;;GAEG;AACH,MAAM,MAAM,0BAA0B,CAAC,CAAC,SAAS,OAAO,IAAI,CAAC,GAAG;IAC9D,GAAG,EAAE;QACH,SAAS,EAAE;YAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;YAAC,OAAO,EAAE;gBAAE,MAAM,EAAE,yBAAyB,CAAA;aAAE,CAAA;SAAE,CAAA;QAC3F,eAAe,EAAE;YAAE,MAAM,EAAE,eAAe,CAAC;YAAC,OAAO,EAAE;gBAAE,MAAM,EAAE,kBAAkB,CAAA;aAAE,CAAA;SAAE,CAAA;KACtF,CAAA;CACF,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ApiEndpointSchema, RestApi, Schema } from '@furystack/rest';
|
|
2
|
-
import type { RestApiImplementation } from './api-
|
|
2
|
+
import type { RestApiImplementation } from './rest-api-runtime.js';
|
|
3
3
|
export declare const defaultSchema: Schema;
|
|
4
4
|
export declare const getSchemaFromApi: <T extends RestApiImplementation<RestApi>>({ api, name, description, version, }: {
|
|
5
5
|
api: T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-schema-from-api.d.ts","sourceRoot":"","sources":["../src/get-schema-from-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,iBAAiB,EAAU,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"get-schema-from-api.d.ts","sourceRoot":"","sources":["../src/get-schema-from-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,iBAAiB,EAAU,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAExG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAElE,eAAO,MAAM,aAAa,EAAE,MA2B3B,CAAA;AAcD,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,qBAAqB,CAAC,OAAO,CAAC,EAAE,sCAKxE;IACD,GAAG,EAAE,CAAC,CAAA;IACN,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,KAAG,iBAuBH,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-schema-from-api.spec.js","sourceRoot":"","sources":["../src/get-schema-from-api.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"get-schema-from-api.spec.js","sourceRoot":"","sources":["../src/get-schema-from-api.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAE1E,OAAO,EAAE,UAAU,EAAsB,MAAM,oCAAoC,CAAA;AACnF,OAAO,gBAAgB,MAAM,yCAAyC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAC5F,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,MAAM,aAAa,GAAuB,KAAK,IAAI,EAAE;IACnD,OAAO,UAAU,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;AACtC,CAAC,CAAA;AAED,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,GAAG,GAAG;YACV,GAAG,EAAE;gBACH,UAAU,EAAE,aAAa;aAC1B;SAC4C,CAAA;QAE/C,MAAM,MAAM,GAAG,gBAAgB,CAAC;YAC9B,GAAG,EAAE,GAAG;YACR,IAAI,EAAE,UA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esm/helpers.d.ts
CHANGED
|
@@ -1,105 +1,71 @@
|
|
|
1
|
-
import type { User } from '@furystack/core';
|
|
2
1
|
import type { Injector } from '@furystack/inject';
|
|
3
2
|
import type { RestApi } from '@furystack/rest';
|
|
4
|
-
import type { ImplementApiOptions } from './api-manager.js';
|
|
5
3
|
import { HttpAuthenticationSettings } from './http-authentication-settings.js';
|
|
6
|
-
import type
|
|
7
|
-
import type {
|
|
8
|
-
import type
|
|
4
|
+
import { type ServerApi } from './http-server-pool.js';
|
|
5
|
+
import type { CorsOptions } from './models/cors-options.js';
|
|
6
|
+
import { type ProxyOptions } from './proxy-runtime.js';
|
|
7
|
+
import { type RestApiImplementation } from './rest-api-runtime.js';
|
|
8
|
+
import { type StaticServerOptions } from './static-site-runtime.js';
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @returns a promise that resolves when the API is added to the server
|
|
10
|
+
* Options accepted by {@link useRestService}. Mirrors the pre-migration
|
|
11
|
+
* shape, minus fields that have moved to tokens.
|
|
13
12
|
*/
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
export interface ImplementApiOptions<T extends RestApi> {
|
|
14
|
+
/** The structure of the implemented API. */
|
|
15
|
+
api: RestApiImplementation<T>;
|
|
16
|
+
/** Injector used to resolve request-scoped services and to acquire the HTTP server. */
|
|
17
|
+
injector: Injector;
|
|
18
|
+
/** Optional host name; defaults to `localhost`. */
|
|
19
|
+
hostName?: string;
|
|
20
|
+
/** Root path prepended to every API route. */
|
|
21
|
+
root: string;
|
|
22
|
+
/** Port the API should listen on. */
|
|
23
|
+
port: number;
|
|
24
|
+
/** Optional CORS configuration applied to every matched request. */
|
|
25
|
+
cors?: CorsOptions;
|
|
26
|
+
/** Optional query-string deserialiser override. */
|
|
27
|
+
deserializeQueryParams?: (param: string) => Record<string, unknown>;
|
|
28
|
+
/** When `true`, adds `GET /schema` and `GET /openapi.json` endpoints. */
|
|
29
|
+
enableGetSchema?: boolean;
|
|
30
|
+
/** OpenAPI display name. */
|
|
31
|
+
name?: string;
|
|
32
|
+
/** OpenAPI description. */
|
|
33
|
+
description?: string;
|
|
34
|
+
/** OpenAPI version. */
|
|
35
|
+
version?: string;
|
|
36
|
+
}
|
|
18
37
|
/**
|
|
19
|
-
*
|
|
38
|
+
* Acquires a pooled HTTP server, compiles the user-supplied API definition
|
|
39
|
+
* and attaches a {@link ServerApi} that dispatches matching requests.
|
|
20
40
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
41
|
+
* Public contract is unchanged from the pre-migration release; internally
|
|
42
|
+
* everything goes through the functional tokens.
|
|
43
|
+
*/
|
|
44
|
+
export declare const useRestService: <T extends RestApi>(options: ImplementApiOptions<T>) => Promise<ServerApi>;
|
|
45
|
+
/**
|
|
46
|
+
* Installs HTTP authentication on the given injector: builds the provider
|
|
47
|
+
* chain (Basic + Cookie by default), appends any caller-provided providers
|
|
48
|
+
* and rebinds {@link HttpAuthenticationSettings}.
|
|
23
49
|
*
|
|
24
|
-
* @
|
|
25
|
-
*
|
|
50
|
+
* Prerequisite: {@link UserStore} and {@link SessionStore} must be bound to
|
|
51
|
+
* persistent implementations before calling this helper, since the Basic
|
|
52
|
+
* and Cookie providers need to read users and sessions immediately.
|
|
26
53
|
*/
|
|
27
|
-
export declare const useHttpAuthentication:
|
|
54
|
+
export declare const useHttpAuthentication: (injector: Injector, overrides?: Partial<HttpAuthenticationSettings>) => void;
|
|
28
55
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @param options.injector The Injector instance
|
|
32
|
-
* @param options.settings Settings for the static file server
|
|
33
|
-
* @returns a promise that resolves when the server is ready
|
|
56
|
+
* Attaches a static-file {@link ServerApi} to the pooled HTTP server
|
|
57
|
+
* identified by `options.port`/`options.hostName`.
|
|
34
58
|
*/
|
|
35
59
|
export declare const useStaticFiles: (options: {
|
|
36
60
|
injector: Injector;
|
|
37
|
-
} & StaticServerOptions) => Promise<
|
|
61
|
+
} & StaticServerOptions) => Promise<ServerApi>;
|
|
38
62
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* and emits 'onProxyFailed' events for monitoring.
|
|
44
|
-
*
|
|
45
|
-
* WebSocket connections can also be proxied by setting `enableWebsockets: true`, allowing
|
|
46
|
-
* bidirectional real-time communication through the proxy.
|
|
47
|
-
*
|
|
48
|
-
* @param options The settings for the proxy server
|
|
49
|
-
* @param options.injector The Injector instance
|
|
50
|
-
* @param options.sourceBaseUrl The base URL path to match for proxying (e.g., '/api', '/old').
|
|
51
|
-
* Can be specified with or without a trailing slash.
|
|
52
|
-
* @param options.targetBaseUrl The target server URL (must be a valid HTTP/HTTPS URL)
|
|
53
|
-
* @param options.pathRewrite Optional function to rewrite the path before forwarding.
|
|
54
|
-
* Receives the path after sourceBaseUrl, including leading slash and query string.
|
|
55
|
-
* Example: for 'GET /api/users?active=true' with sourceBaseUrl='/api',
|
|
56
|
-
* pathRewrite receives '/users?active=true'
|
|
57
|
-
* @param options.sourceHostName The hostname for the source server (optional, defaults to all interfaces)
|
|
58
|
-
* @param options.sourcePort The port for the source server
|
|
59
|
-
* @param options.headers Optional function to transform request headers.
|
|
60
|
-
* **Note**: Receives headers AFTER filtering hop-by-hop headers
|
|
61
|
-
* (Connection, Keep-Alive, Transfer-Encoding, Upgrade, etc.) for security
|
|
62
|
-
* and protocol compliance. The proxy automatically adds X-Forwarded-* headers.
|
|
63
|
-
* This transformation applies to both HTTP and WebSocket requests.
|
|
64
|
-
* @param options.cookies Optional function to transform request cookies (array of cookie strings)
|
|
65
|
-
* @param options.responseCookies Optional function to transform response Set-Cookie headers
|
|
66
|
-
* @param options.timeout Optional timeout in milliseconds for proxy requests (default: 30000).
|
|
67
|
-
* If exceeded, the request is aborted and 502 is returned.
|
|
68
|
-
* Applies to both HTTP and WebSocket upgrade requests.
|
|
69
|
-
* @param options.enableWebsockets Optional flag to enable WebSocket proxying (default: false).
|
|
70
|
-
* When enabled, WebSocket upgrade requests will be forwarded to the target.
|
|
71
|
-
* @returns a promise that resolves when the proxy is set up
|
|
72
|
-
* @example
|
|
73
|
-
* ```ts
|
|
74
|
-
* // Basic HTTP proxy with timeout
|
|
75
|
-
* await useProxy({
|
|
76
|
-
* injector,
|
|
77
|
-
* sourceBaseUrl: '/api',
|
|
78
|
-
* targetBaseUrl: 'https://api.example.com',
|
|
79
|
-
* sourcePort: 3000,
|
|
80
|
-
* timeout: 5000,
|
|
81
|
-
* })
|
|
82
|
-
*
|
|
83
|
-
* // Proxy with WebSocket support
|
|
84
|
-
* await useProxy({
|
|
85
|
-
* injector,
|
|
86
|
-
* sourceBaseUrl: '/ws',
|
|
87
|
-
* targetBaseUrl: 'https://ws.example.com',
|
|
88
|
-
* sourcePort: 3000,
|
|
89
|
-
* enableWebsockets: true,
|
|
90
|
-
* })
|
|
91
|
-
*
|
|
92
|
-
* // Proxy with error monitoring (HTTP and WebSocket)
|
|
93
|
-
* const proxyManager = injector.getInstance(ProxyManager)
|
|
94
|
-
* proxyManager.subscribe('onProxyFailed', ({ from, to, error }) => {
|
|
95
|
-
* console.error(`HTTP Proxy failed: ${from} -> ${to}`, error)
|
|
96
|
-
* })
|
|
97
|
-
* proxyManager.subscribe('onWebSocketProxyFailed', ({ from, to, error }) => {
|
|
98
|
-
* console.error(`WebSocket Proxy failed: ${from} -> ${to}`, error)
|
|
99
|
-
* })
|
|
100
|
-
* ```
|
|
63
|
+
* Attaches a proxy {@link ServerApi} that forwards HTTP (and optionally
|
|
64
|
+
* WebSocket) traffic from `options.sourceBaseUrl` to `options.targetBaseUrl`.
|
|
65
|
+
* Emits `onProxyFailed` and `onWebSocketProxyFailed` events into the shared
|
|
66
|
+
* {@link ServerTelemetryToken} — subscribe there for observability.
|
|
101
67
|
*/
|
|
102
68
|
export declare const useProxy: (options: {
|
|
103
69
|
injector: Injector;
|
|
104
|
-
} & ProxyOptions) => Promise<
|
|
70
|
+
} & ProxyOptions) => Promise<ServerApi>;
|
|
105
71
|
//# sourceMappingURL=helpers.d.ts.map
|
package/esm/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAS9C,OAAO,EAAqC,0BAA0B,EAAE,MAAM,mCAAmC,CAAA;AACjH,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAE3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAC3E,OAAO,EAAgC,KAAK,qBAAqB,EAAqB,MAAM,uBAAuB,CAAA;AAEnH,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAE7F;;;GAGG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,OAAO;IACpD,4CAA4C;IAC5C,GAAG,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAA;IAC7B,uFAAuF;IACvF,QAAQ,EAAE,QAAQ,CAAA;IAClB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAA;IACZ,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAA;IACZ,oEAAoE;IACpE,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,mDAAmD;IACnD,sBAAsB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnE,yEAAy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