@kensio/simnaril 0.0.0 → 0.1.1
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/README.md +2 -0
- package/dist/api.d.ts +25 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +35 -31
- package/dist/api.js.map +1 -1
- package/dist/http/decode-form.d.ts +38 -0
- package/dist/http/decode-form.d.ts.map +1 -0
- package/dist/http/decode-form.js +119 -0
- package/dist/http/decode-form.js.map +1 -0
- package/dist/http/error-formatter.d.ts +13 -0
- package/dist/http/error-formatter.d.ts.map +1 -0
- package/dist/http/error-formatter.js +2 -0
- package/dist/http/error-formatter.js.map +1 -0
- package/dist/http/operation-router.d.ts +2 -0
- package/dist/http/operation-router.d.ts.map +1 -1
- package/dist/http/operation-router.js +16 -1
- package/dist/http/operation-router.js.map +1 -1
- package/dist/http/operation.d.ts +2 -1
- package/dist/http/operation.d.ts.map +1 -1
- package/dist/http/operation.js.map +1 -1
- package/dist/http/path-parameter.d.ts +3 -0
- package/dist/http/path-parameter.d.ts.map +1 -0
- package/dist/http/path-parameter.js +12 -0
- package/dist/http/path-parameter.js.map +1 -0
- package/dist/http/raw-operation.d.ts +16 -0
- package/dist/http/raw-operation.d.ts.map +1 -0
- package/dist/http/raw-operation.js +27 -0
- package/dist/http/raw-operation.js.map +1 -0
- package/dist/http/request-decoder.d.ts +30 -0
- package/dist/http/request-decoder.d.ts.map +1 -0
- package/dist/http/request-decoder.js +18 -0
- package/dist/http/request-decoder.js.map +1 -0
- package/dist/http/resource-operation-registry.d.ts +1 -1
- package/dist/http/resource-operation-registry.d.ts.map +1 -1
- package/dist/http/resource-operation-registry.js +6 -3
- package/dist/http/resource-operation-registry.js.map +1 -1
- package/dist/http/resource-operation.d.ts +2 -1
- package/dist/http/resource-operation.d.ts.map +1 -1
- package/dist/http/resource-operation.js +3 -3
- package/dist/http/resource-operation.js.map +1 -1
- package/dist/http/resource-path.d.ts +13 -0
- package/dist/http/resource-path.d.ts.map +1 -0
- package/dist/http/resource-path.js +23 -0
- package/dist/http/resource-path.js.map +1 -0
- package/dist/http/rest-resource-operation-defaults.d.ts +10 -0
- package/dist/http/rest-resource-operation-defaults.d.ts.map +1 -0
- package/dist/http/rest-resource-operation-defaults.js +8 -0
- package/dist/http/rest-resource-operation-defaults.js.map +1 -0
- package/dist/http/rest-resource-operations.d.ts +3 -3
- package/dist/http/rest-resource-operations.d.ts.map +1 -1
- package/dist/http/rest-resource-operations.js +37 -51
- package/dist/http/rest-resource-operations.js.map +1 -1
- package/dist/http/semantic-http-operation.d.ts +2 -1
- package/dist/http/semantic-http-operation.d.ts.map +1 -1
- package/dist/http/semantic-http-operation.js.map +1 -1
- package/dist/http/supplied-rest-resource-operation.d.ts +22 -0
- package/dist/http/supplied-rest-resource-operation.d.ts.map +1 -0
- package/dist/http/supplied-rest-resource-operation.js +27 -0
- package/dist/http/supplied-rest-resource-operation.js.map +1 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/resource.d.ts +1 -1
- package/dist/resource.d.ts.map +1 -1
- package/dist/resource.js +1 -1
- package/dist/resource.js.map +1 -1
- package/dist/rest-resource-operation.d.ts +20 -2
- package/dist/rest-resource-operation.d.ts.map +1 -1
- package/dist/rest-resource.d.ts +2 -0
- package/dist/rest-resource.d.ts.map +1 -1
- package/dist/rest-resource.js +9 -1
- package/dist/rest-resource.js.map +1 -1
- package/dist/unimplemented-route-error.d.ts +2 -1
- package/dist/unimplemented-route-error.d.ts.map +1 -1
- package/dist/unimplemented-route-error.js +4 -2
- package/dist/unimplemented-route-error.js.map +1 -1
- package/dist/webhooks.d.ts +98 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +129 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +2 -1
|
@@ -5,7 +5,7 @@ import type { HttpMiddleware, HttpOperation, SemanticOperation } from "./operati
|
|
|
5
5
|
export declare class ResourceOperationRegistry<T extends object> {
|
|
6
6
|
#private;
|
|
7
7
|
readonly operations: RestResourceOperations<T>;
|
|
8
|
-
constructor(resource: RestResource<T>,
|
|
8
|
+
constructor(resource: RestResource<T>, props: RestResourceProps);
|
|
9
9
|
use(middleware: HttpMiddleware): void;
|
|
10
10
|
add<TInput, TOutput>(name: string, props: ResourceOperationProps<T, TInput, TOutput>): SemanticOperation<TInput, TOutput, RestResource<T>>;
|
|
11
11
|
attach(registerOperation: (operation: HttpOperation) => void): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-operation-registry.d.ts","sourceRoot":"","sources":["../../src/http/resource-operation-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"resource-operation-registry.d.ts","sourceRoot":"","sources":["../../src/http/resource-operation-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAKxB,2EAA2E;AAC3E,qBAAa,yBAAyB,CAAC,CAAC,SAAS,MAAM;;IACrD,QAAQ,CAAC,UAAU,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;IAc/C,YAAY,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,iBAAiB,EAM9D;IAED,GAAG,CAAC,UAAU,EAAE,cAAc,GAAG,IAAI,CAEpC;IAED,GAAG,CAAC,MAAM,EAAE,OAAO,EACjB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,sBAAsB,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,GAChD,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAuBrD;IAED,MAAM,CAAC,iBAAiB,EAAE,CAAC,SAAS,EAAE,aAAa,KAAK,IAAI,GAAG,IAAI,CAMlE;CACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { decodeJson } from "./request-decoder.js";
|
|
1
2
|
import { resourceOperation } from "./resource-operation.js";
|
|
2
3
|
import { restResourceOperations } from "./rest-resource-operations.js";
|
|
3
4
|
/** Registers supplied and custom operations owned by one REST resource. */
|
|
@@ -13,10 +14,12 @@ export class ResourceOperationRegistry {
|
|
|
13
14
|
"delete",
|
|
14
15
|
]);
|
|
15
16
|
#resource;
|
|
17
|
+
#decode;
|
|
16
18
|
#registerOperation;
|
|
17
|
-
constructor(resource,
|
|
19
|
+
constructor(resource, props) {
|
|
18
20
|
this.#resource = resource;
|
|
19
|
-
|
|
21
|
+
this.#decode = props.decode;
|
|
22
|
+
const supplied = restResourceOperations(resource, props, this.#middleware);
|
|
20
23
|
this.#httpOperations = supplied.http;
|
|
21
24
|
this.operations = supplied.semantic;
|
|
22
25
|
}
|
|
@@ -30,7 +33,7 @@ export class ResourceOperationRegistry {
|
|
|
30
33
|
if (!props.path.startsWith("/")) {
|
|
31
34
|
throw new TypeError(`Expected a resource operation path such as "/:id/archive", received "${props.path}".`);
|
|
32
35
|
}
|
|
33
|
-
const operation = resourceOperation(this.#resource, this.#middleware, props);
|
|
36
|
+
const operation = resourceOperation(this.#resource, this.#middleware, props, props.decode ?? this.#decode ?? decodeJson);
|
|
34
37
|
this.#names.add(name);
|
|
35
38
|
this.#httpOperations.push(operation.http);
|
|
36
39
|
this.#registerOperation?.(operation.http);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-operation-registry.js","sourceRoot":"","sources":["../../src/http/resource-operation-registry.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,2EAA2E;AAC3E,MAAM,OAAO,yBAAyB;IAC3B,UAAU,CAA4B;IACtC,eAAe,CAAkB;IACjC,WAAW,GAAqB,EAAE,CAAC;IACnC,MAAM,GAAG,IAAI,GAAG,CAAS;QAChC,MAAM;QACN,QAAQ;QACR,KAAK;QACL,QAAQ;QACR,QAAQ;KACT,CAAC,CAAC;IACM,SAAS,CAAkB;
|
|
1
|
+
{"version":3,"file":"resource-operation-registry.js","sourceRoot":"","sources":["../../src/http/resource-operation-registry.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAuB,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,2EAA2E;AAC3E,MAAM,OAAO,yBAAyB;IAC3B,UAAU,CAA4B;IACtC,eAAe,CAAkB;IACjC,WAAW,GAAqB,EAAE,CAAC;IACnC,MAAM,GAAG,IAAI,GAAG,CAAS;QAChC,MAAM;QACN,QAAQ;QACR,KAAK;QACL,QAAQ;QACR,QAAQ;KACT,CAAC,CAAC;IACM,SAAS,CAAkB;IAC3B,OAAO,CAA6B;IAC7C,kBAAkB,CAAmD;IAErE,YAAY,QAAyB,EAAE,KAAwB;QAC7D,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,MAAM,QAAQ,GAAG,sBAAsB,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAC3E,IA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8 +1,9 @@
|
|
|
1
1
|
import type { RestResource } from "../rest-resource.js";
|
|
2
2
|
import type { ResourceOperationProps } from "../rest-resource-operation.js";
|
|
3
3
|
import { type HttpMiddleware, type HttpOperation, SemanticOperation } from "./operation.js";
|
|
4
|
+
import { type RequestDecoder } from "./request-decoder.js";
|
|
4
5
|
/** Builds one named semantic operation below a resource path. */
|
|
5
|
-
export declare function resourceOperation<T extends object, TInput, TOutput>(resource: RestResource<T>, middleware: readonly HttpMiddleware[], props: ResourceOperationProps<T, TInput, TOutput
|
|
6
|
+
export declare function resourceOperation<T extends object, TInput, TOutput>(resource: RestResource<T>, middleware: readonly HttpMiddleware[], props: ResourceOperationProps<T, TInput, TOutput>, decode: RequestDecoder): {
|
|
6
7
|
http: HttpOperation;
|
|
7
8
|
semantic: SemanticOperation<TInput, TOutput, RestResource<T>>;
|
|
8
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-operation.d.ts","sourceRoot":"","sources":["../../src/http/resource-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"resource-operation.d.ts","sourceRoot":"","sources":["../../src/http/resource-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAqB,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAS9E,iEAAiE;AACjE,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,OAAO,EACjE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,EACzB,UAAU,EAAE,SAAS,cAAc,EAAE,EACrC,KAAK,EAAE,sBAAsB,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EACjD,MAAM,EAAE,cAAc,GACrB;IACD,IAAI,EAAE,aAAa,CAAC;IACpB,QAAQ,EAAE,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/D,CAgBA"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { SemanticOperation, } from "./operation.js";
|
|
2
|
+
import { decodeWhenPresent } from "./request-decoder.js";
|
|
2
3
|
import { compileRoute } from "./route.js";
|
|
3
4
|
import { semanticHttpOperation } from "./semantic-http-operation.js";
|
|
4
|
-
const decodeResourceOperation = async (request) => request.body === null ? undefined : request.json();
|
|
5
5
|
const encodeResourceOperation = (output) => output === undefined
|
|
6
6
|
? new Response(undefined, { status: 204 })
|
|
7
7
|
: Response.json(output);
|
|
8
8
|
/** Builds one named semantic operation below a resource path. */
|
|
9
|
-
export function resourceOperation(resource, middleware, props) {
|
|
9
|
+
export function resourceOperation(resource, middleware, props, decode) {
|
|
10
10
|
const route = compileRoute(`${resource.path}${props.path}`);
|
|
11
11
|
const semantic = new SemanticOperation(props.handle);
|
|
12
12
|
return {
|
|
13
13
|
semantic,
|
|
14
14
|
http: semanticHttpOperation({
|
|
15
|
-
decode:
|
|
15
|
+
decode: decodeWhenPresent(decode),
|
|
16
16
|
encode: encodeResourceOperation,
|
|
17
17
|
method: props.method,
|
|
18
18
|
resource,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-operation.js","sourceRoot":"","sources":["../../src/http/resource-operation.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"resource-operation.js","sourceRoot":"","sources":["../../src/http/resource-operation.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAuB,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,MAAM,uBAAuB,GAAG,CAAC,MAAe,EAAY,EAAE,CAC5D,MAAM,KAAK,SAAS;IAClB,CAAC,CAAC,IAAI,QAAQ,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;IAC1C,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE5B,iEAAiE;AACjE,MAAM,UAAU,iBAAiB,CAC/B,QAAyB,EACzB,UAAqC,EACrC,KAAiD,EACjD,MAAsB;IAKtB,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,QAAQ,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5D,MAAM,QAAQ,GAAG,IAAI,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAErD,OAAO;QACL,QAAQ;QACR,IAAI,EAAE,qBAAqB,CAAC;YAC1B,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC;YACjC,MAAM,EAAE,uBAAuB;YAC/B,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,QAAQ;YACR,kBAAkB,EAAE,UAAU;YAC9B,KAAK;YACL,QAAQ;SACT,CAAC;KACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks that a resource path names a collection and nothing else.
|
|
3
|
+
*
|
|
4
|
+
* A query string or fragment does not belong to a collection path. URL
|
|
5
|
+
* normalization can also make the registered route differ from the string the
|
|
6
|
+
* caller passed. Named parameters are allowed because collections often belong
|
|
7
|
+
* to another resource.
|
|
8
|
+
*
|
|
9
|
+
* Anything but a canonical collection path throws a `TypeError` naming what
|
|
10
|
+
* was received.
|
|
11
|
+
*/
|
|
12
|
+
export declare function validateResourcePath(path: string): void;
|
|
13
|
+
//# sourceMappingURL=resource-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-path.d.ts","sourceRoot":"","sources":["../../src/http/resource-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAiBvD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks that a resource path names a collection and nothing else.
|
|
3
|
+
*
|
|
4
|
+
* A query string or fragment does not belong to a collection path. URL
|
|
5
|
+
* normalization can also make the registered route differ from the string the
|
|
6
|
+
* caller passed. Named parameters are allowed because collections often belong
|
|
7
|
+
* to another resource.
|
|
8
|
+
*
|
|
9
|
+
* Anything but a canonical collection path throws a `TypeError` naming what
|
|
10
|
+
* was received.
|
|
11
|
+
*/
|
|
12
|
+
export function validateResourcePath(path) {
|
|
13
|
+
const base = new URL("https://simnaril.invalid");
|
|
14
|
+
const url = new URL(path, base);
|
|
15
|
+
if (url.origin !== base.origin ||
|
|
16
|
+
url.pathname !== path ||
|
|
17
|
+
url.search !== "" ||
|
|
18
|
+
url.hash !== "" ||
|
|
19
|
+
!/^\/(?:[^/:]+|:[A-Za-z_][A-Za-z\d_]*)(?:\/(?:[^/:]+|:[A-Za-z_][A-Za-z\d_]*))*$/u.test(path)) {
|
|
20
|
+
throw new TypeError(`Expected a resource collection path such as "/widgets", received "${path}".`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=resource-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-path.js","sourceRoot":"","sources":["../../src/http/resource-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,0BAA0B,CAAC,CAAC;IACjD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAEhC,IACE,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM;QAC1B,GAAG,CAAC,QAAQ,KAAK,IAAI;QACrB,GAAG,CAAC,MAAM,KAAK,EAAE;QACjB,GAAG,CAAC,IAAI,KAAK,EAAE;QACf,CAAC,gFAAgF,CAAC,IAAI,CACpF,IAAI,CACL,EACD,CAAC;QACD,MAAM,IAAI,SAAS,CACjB,qEAAqE,IAAI,IAAI,CAC9E,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RestResourceOperationConfiguration, RestResourceOperationSetting } from "../rest-resource-operation.js";
|
|
2
|
+
import type { HttpOperation } from "./operation.js";
|
|
3
|
+
import { type RequestDecoder } from "./request-decoder.js";
|
|
4
|
+
export declare const encodeJson: (status: number) => (output: unknown) => Response;
|
|
5
|
+
export declare const encodeEmpty: () => Response;
|
|
6
|
+
export declare const bodyDecoder: (configuration: RestResourceOperationConfiguration | undefined, resource: RequestDecoder | undefined) => RequestDecoder;
|
|
7
|
+
export declare const emptyDecoder: (configuration: RestResourceOperationConfiguration | undefined) => RequestDecoder;
|
|
8
|
+
export declare const configuredOperation: (setting: RestResourceOperationSetting | undefined) => RestResourceOperationConfiguration | undefined;
|
|
9
|
+
export declare const presentHttpOperations: (...operations: (HttpOperation | undefined)[]) => HttpOperation[];
|
|
10
|
+
//# sourceMappingURL=rest-resource-operation-defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rest-resource-operation-defaults.d.ts","sourceRoot":"","sources":["../../src/http/rest-resource-operation-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kCAAkC,EAClC,4BAA4B,EAC7B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,sBAAsB,CAAC;AAE9B,eAAO,MAAM,UAAU,WACZ,MAAM,cACN,OAAO,KAAG,QACgB,CAAC;AAEtC,eAAO,MAAM,WAAW,QAAO,QACW,CAAC;AAE3C,eAAO,MAAM,WAAW,kBACP,kCAAkC,GAAG,SAAS,YACnD,cAAc,GAAG,SAAS,KACnC,cAAiE,CAAC;AAErE,eAAO,MAAM,YAAY,kBACR,kCAAkC,GAAG,SAAS,KAC5D,cAA2E,CAAC;AAE/E,eAAO,MAAM,mBAAmB,YACrB,4BAA4B,GAAG,SAAS,KAChD,kCAAkC,GAAG,SACC,CAAC;AAE1C,eAAO,MAAM,qBAAqB,kBACjB,CAAC,aAAa,GAAG,SAAS,CAAC,EAAE,KAC3C,aAAa,EAGb,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { decodeJson, decodeNothing, decodeWhenPresent, } from "./request-decoder.js";
|
|
2
|
+
export const encodeJson = (status) => (output) => Response.json(output, { status });
|
|
3
|
+
export const encodeEmpty = () => new Response(undefined, { status: 204 });
|
|
4
|
+
export const bodyDecoder = (configuration, resource) => configuration?.decode ?? resource ?? decodeJson;
|
|
5
|
+
export const emptyDecoder = (configuration) => decodeWhenPresent(configuration?.decode ?? decodeNothing);
|
|
6
|
+
export const configuredOperation = (setting) => setting === false ? undefined : setting;
|
|
7
|
+
export const presentHttpOperations = (...operations) => operations.filter((operation) => operation !== undefined);
|
|
8
|
+
//# sourceMappingURL=rest-resource-operation-defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rest-resource-operation-defaults.js","sourceRoot":"","sources":["../../src/http/rest-resource-operation-defaults.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,UAAU,EACV,aAAa,EACb,iBAAiB,GAElB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,CAAC,MAAM,UAAU,GACrB,CAAC,MAAc,EAAE,EAAE,CACnB,CAAC,MAAe,EAAY,EAAE,CAC5B,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AAEtC,MAAM,CAAC,MAAM,WAAW,GAAG,GAAa,EAAE,CACxC,IAAI,QAAQ,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;AAE3C,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,aAA6D,EAC7D,QAAoC,EACpB,EAAE,CAAC,aAAa,EAAE,MAAM,IAAI,QAAQ,IAAI,UAAU,CAAC;AAErE,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,aAA6D,EAC7C,EAAE,CAAC,iBAAiB,CAAC,aAAa,EAAE,MAAM,IAAI,aAAa,CAAC,CAAC;AAE/E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,OAAiD,EACD,EAAE,CAClD,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;AAE1C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,GAAG,UAAyC,EAC3B,EAAE,CACnB,UAAU,CAAC,MAAM,CACf,CAAC,SAAS,EAA8B,EAAE,CAAC,SAAS,KAAK,SAAS,CACnE,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { RestResource } from "../rest-resource.js";
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
2
|
+
import type { RestResourceOperations, RestResourceProps } from "../rest-resource-operation.js";
|
|
3
|
+
import type { HttpMiddleware, HttpOperation } from "./operation.js";
|
|
4
4
|
/** Builds conventional collection and item operations for one resource. */
|
|
5
|
-
export declare function restResourceOperations<T extends object>(resource: RestResource<T>,
|
|
5
|
+
export declare function restResourceOperations<T extends object>(resource: RestResource<T>, props: RestResourceProps, resourceMiddleware?: readonly HttpMiddleware[]): {
|
|
6
6
|
http: HttpOperation[];
|
|
7
7
|
semantic: RestResourceOperations<T>;
|
|
8
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-resource-operations.d.ts","sourceRoot":"","sources":["../../src/http/rest-resource-operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"rest-resource-operations.d.ts","sourceRoot":"","sources":["../../src/http/rest-resource-operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EACV,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAcpE,2EAA2E;AAC3E,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,EACrD,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,EACzB,KAAK,EAAE,iBAAiB,EACxB,kBAAkB,GAAE,SAAS,cAAc,EAAO,GACjD;IAAE,IAAI,EAAE,aAAa,EAAE,CAAC;IAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAA;CAAE,CAwFhE"}
|
|
@@ -1,90 +1,76 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const decodeEmpty = () => Promise.resolve();
|
|
5
|
-
const decodeJson = async (request) => request.json();
|
|
6
|
-
const encodeJson = (status) => (output) => Response.json(output, { status });
|
|
7
|
-
const encodeEmpty = () => new Response(undefined, { status: 204 });
|
|
8
|
-
const requiredPathParameter = (params, name) => {
|
|
9
|
-
const value = params[name];
|
|
10
|
-
if (value === undefined) {
|
|
11
|
-
throw new TypeError(`Matched operation has no ":${name}" path parameter.`);
|
|
12
|
-
}
|
|
13
|
-
return value;
|
|
14
|
-
};
|
|
15
|
-
const suppliedOperation = (props) => {
|
|
16
|
-
const semantic = new SemanticOperation(props.handle);
|
|
17
|
-
const route = compileRoute(`${props.resource.path}${props.configuration?.path ?? props.defaultPath}`, props.requiredParameters);
|
|
18
|
-
return {
|
|
19
|
-
semantic,
|
|
20
|
-
http: semanticHttpOperation({
|
|
21
|
-
decode: props.decode,
|
|
22
|
-
encode: props.encode,
|
|
23
|
-
method: props.configuration?.method ?? props.defaultMethod,
|
|
24
|
-
resource: props.resource,
|
|
25
|
-
resourceMiddleware: props.resourceMiddleware,
|
|
26
|
-
route,
|
|
27
|
-
semantic,
|
|
28
|
-
}),
|
|
29
|
-
};
|
|
30
|
-
};
|
|
1
|
+
import { bodyDecoder, configuredOperation, emptyDecoder, encodeEmpty, encodeJson, presentHttpOperations, } from "./rest-resource-operation-defaults.js";
|
|
2
|
+
import { suppliedOperation } from "./supplied-rest-resource-operation.js";
|
|
3
|
+
const requiredItemParameters = (props) => props.locate === undefined ? ["id"] : [];
|
|
31
4
|
/** Builds conventional collection and item operations for one resource. */
|
|
32
|
-
export function restResourceOperations(resource,
|
|
5
|
+
export function restResourceOperations(resource, props, resourceMiddleware = []) {
|
|
6
|
+
const configuration = props.operations ?? {};
|
|
7
|
+
const listConfiguration = configuredOperation(configuration.list);
|
|
8
|
+
const createConfiguration = configuredOperation(configuration.create);
|
|
9
|
+
const getConfiguration = configuredOperation(configuration.get);
|
|
10
|
+
const updateConfiguration = configuredOperation(configuration.update);
|
|
11
|
+
const deleteConfiguration = configuredOperation(configuration.delete);
|
|
12
|
+
const itemPath = props.itemPath ?? "/:id";
|
|
13
|
+
const itemParameters = requiredItemParameters(props);
|
|
33
14
|
const list = suppliedOperation({
|
|
34
15
|
resource,
|
|
35
16
|
resourceMiddleware,
|
|
36
|
-
configuration:
|
|
17
|
+
configuration: listConfiguration,
|
|
37
18
|
defaultMethod: "GET",
|
|
38
19
|
defaultPath: "",
|
|
39
|
-
decode:
|
|
20
|
+
decode: emptyDecoder(listConfiguration),
|
|
21
|
+
enabled: configuration.list !== false,
|
|
40
22
|
handle: ({ resource: operationResource }) => operationResource.list(),
|
|
41
23
|
encode: encodeJson(200),
|
|
42
24
|
});
|
|
43
25
|
const create = suppliedOperation({
|
|
44
26
|
resource,
|
|
45
27
|
resourceMiddleware,
|
|
46
|
-
configuration:
|
|
28
|
+
configuration: createConfiguration,
|
|
47
29
|
defaultMethod: "POST",
|
|
48
30
|
defaultPath: "",
|
|
49
|
-
decode:
|
|
31
|
+
decode: bodyDecoder(createConfiguration, props.decode),
|
|
32
|
+
enabled: configuration.create !== false,
|
|
50
33
|
handle: ({ input, resource: operationResource }) => operationResource.create(input),
|
|
51
34
|
encode: encodeJson(201),
|
|
52
35
|
});
|
|
53
36
|
const get = suppliedOperation({
|
|
54
37
|
resource,
|
|
55
38
|
resourceMiddleware,
|
|
56
|
-
configuration:
|
|
39
|
+
configuration: getConfiguration,
|
|
57
40
|
defaultMethod: "GET",
|
|
58
|
-
defaultPath:
|
|
59
|
-
decode:
|
|
60
|
-
|
|
41
|
+
defaultPath: itemPath,
|
|
42
|
+
decode: emptyDecoder(getConfiguration),
|
|
43
|
+
enabled: configuration.get !== false,
|
|
44
|
+
handle: ({ params, resource: operationResource }) => operationResource.get(operationResource.locate(params)),
|
|
61
45
|
encode: encodeJson(200),
|
|
62
|
-
requiredParameters:
|
|
46
|
+
requiredParameters: itemParameters,
|
|
63
47
|
});
|
|
64
48
|
const update = suppliedOperation({
|
|
65
49
|
resource,
|
|
66
50
|
resourceMiddleware,
|
|
67
|
-
configuration:
|
|
51
|
+
configuration: updateConfiguration,
|
|
68
52
|
defaultMethod: "PATCH",
|
|
69
|
-
defaultPath:
|
|
70
|
-
decode:
|
|
71
|
-
|
|
53
|
+
defaultPath: itemPath,
|
|
54
|
+
decode: bodyDecoder(updateConfiguration, props.decode),
|
|
55
|
+
enabled: configuration.update !== false,
|
|
56
|
+
handle: ({ input, params, resource: operationResource }) => operationResource.update(operationResource.locate(params), input),
|
|
72
57
|
encode: encodeJson(200),
|
|
73
|
-
requiredParameters:
|
|
58
|
+
requiredParameters: itemParameters,
|
|
74
59
|
});
|
|
75
60
|
const deleteOperation = suppliedOperation({
|
|
76
61
|
resource,
|
|
77
62
|
resourceMiddleware,
|
|
78
|
-
configuration:
|
|
63
|
+
configuration: deleteConfiguration,
|
|
79
64
|
defaultMethod: "DELETE",
|
|
80
|
-
defaultPath:
|
|
81
|
-
decode:
|
|
82
|
-
|
|
65
|
+
defaultPath: itemPath,
|
|
66
|
+
decode: emptyDecoder(deleteConfiguration),
|
|
67
|
+
enabled: configuration.delete !== false,
|
|
68
|
+
handle: ({ params, resource: operationResource }) => operationResource.delete(operationResource.locate(params)),
|
|
83
69
|
encode: encodeEmpty,
|
|
84
|
-
requiredParameters:
|
|
70
|
+
requiredParameters: itemParameters,
|
|
85
71
|
});
|
|
86
72
|
return {
|
|
87
|
-
http:
|
|
73
|
+
http: presentHttpOperations(list.http, create.http, get.http, update.http, deleteOperation.http),
|
|
88
74
|
semantic: {
|
|
89
75
|
list: list.semantic,
|
|
90
76
|
create: create.semantic,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-resource-operations.js","sourceRoot":"","sources":["../../src/http/rest-resource-operations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rest-resource-operations.js","sourceRoot":"","sources":["../../src/http/rest-resource-operations.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,WAAW,EACX,UAAU,EACV,qBAAqB,GACtB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAE1E,MAAM,sBAAsB,GAAG,CAAC,KAAwB,EAAqB,EAAE,CAC7E,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC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E,UAAU,CAAC,GAAG,CAAC;QACvB,kBAAkB,EAAE,cAAc;KACnC,CAAC,CAAC;IACH,MAAM,eAAe,GAAG,iBAAiB,CAAgB;QACvD,QAAQ;QACR,kBAAkB;QAClB,aAAa,EAAE,mBAAmB;QAClC,aAAa,EAAE,QAAQ;QACvB,WAAW,EAAE,QAAQ;QACrB,MAAM,EAAE,YAAY,CAAC,mBAAmB,CAAC;QACzC,OAAO,EAAE,aAAa,CAAC,MAAM,KAAK,KAAK;QACvC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,EAAE,EAAE,CAClD,iBAAiB,CAAC,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5D,MAAM,EAAE,WAAW;QACnB,kBAAkB,EAAE,cAAc;KACnC,CAAC,CAAC;IAEH,OAAO;QACL,IAAI,EAAE,qBAAqB,CACzB,IAAI,CAAC,IAAI,EACT,MAAM,CAAC,IAAI,EACX,GAAG,CAAC,IAAI,EACR,MAAM,CAAC,IAAI,EACX,eAAe,CAAC,IAAI,CACrB;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,IAAI,CAAC,QAAQ;YACnB,MAAM,EAAE,MAAM,CAAC,QAAQ;YACvB,GAAG,EAAE,GAAG,CAAC,QAAQ;YACjB,MAAM,EAAE,MAAM,CAAC,QAAQ;YACvB,MAAM,EAAE,eAAe,CAAC,QAAQ;SACjC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { RestResource } from "../rest-resource.js";
|
|
2
2
|
import { type HttpMiddleware, type HttpOperation, type SemanticOperation } from "./operation.js";
|
|
3
|
+
import type { RequestDecoder } from "./request-decoder.js";
|
|
3
4
|
import type { CompiledRoute } from "./route.js";
|
|
4
5
|
interface SemanticHttpOperationProps<T extends object, TInput, TOutput> {
|
|
5
|
-
decode:
|
|
6
|
+
decode: RequestDecoder;
|
|
6
7
|
encode: (output: unknown) => Promise<Response> | Response;
|
|
7
8
|
method: string;
|
|
8
9
|
resource: RestResource<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semantic-http-operation.d.ts","sourceRoot":"","sources":["../../src/http/semantic-http-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,aAAa,EAGlB,KAAK,iBAAiB,EACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,UAAU,0BAA0B,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,OAAO;IACpE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"semantic-http-operation.d.ts","sourceRoot":"","sources":["../../src/http/semantic-http-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,aAAa,EAGlB,KAAK,iBAAiB,EACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,UAAU,0BAA0B,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,OAAO;IACpE,MAAM,EAAE,cAAc,CAAC;IACvB,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IAC1D,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC1B,kBAAkB,EAAE,SAAS,cAAc,EAAE,CAAC;IAC9C,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/D;AAED,qEAAqE;AACrE,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,OAAO,EACrE,KAAK,EAAE,0BAA0B,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,GACpD,aAAa,CAgBf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semantic-http-operation.js","sourceRoot":"","sources":["../../src/http/semantic-http-operation.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,mBAAmB,EACnB,oBAAoB,GAErB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"semantic-http-operation.js","sourceRoot":"","sources":["../../src/http/semantic-http-operation.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,mBAAmB,EACnB,oBAAoB,GAErB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAY7C,qEAAqE;AACrE,MAAM,UAAU,qBAAqB,CACnC,KAAqD;IAErD,OAAO;QACL,GAAG,KAAK,CAAC,KAAK;QACd,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,MAAM,EAAE,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC;QACrC,UAAU,EAAE,mBAAmB,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC/C,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAC1B,oBAAoB,CAAC,KAAK,CAAC,QAAQ,EAAE;YACnC,GAAG,OAAO;YACV,KAAK,EAAE,KAAe;YACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ;SACzB,CAAC;QACJ,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;QAC5C,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO;KAChC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RestResource } from "../rest-resource.js";
|
|
2
|
+
import type { RestResourceOperationConfiguration } from "../rest-resource-operation.js";
|
|
3
|
+
import { type HttpMiddleware, type HttpOperation, SemanticOperation, type SemanticOperationContext } from "./operation.js";
|
|
4
|
+
import type { RequestDecoder } from "./request-decoder.js";
|
|
5
|
+
interface SuppliedOperationProps<TInput, TOutput, T extends object> {
|
|
6
|
+
configuration: RestResourceOperationConfiguration | undefined;
|
|
7
|
+
decode: RequestDecoder;
|
|
8
|
+
defaultMethod: string;
|
|
9
|
+
defaultPath: string;
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
encode: (output: unknown) => Promise<Response> | Response;
|
|
12
|
+
handle: (context: SemanticOperationContext<TInput, RestResource<T>>) => Promise<TOutput> | TOutput;
|
|
13
|
+
resource: RestResource<T>;
|
|
14
|
+
resourceMiddleware: readonly HttpMiddleware[];
|
|
15
|
+
requiredParameters?: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
export declare const suppliedOperation: <TInput, TOutput, T extends object>(props: SuppliedOperationProps<TInput, TOutput, T>) => {
|
|
18
|
+
http?: HttpOperation;
|
|
19
|
+
semantic: SemanticOperation<TInput, TOutput, RestResource<T>>;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=supplied-rest-resource-operation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supplied-rest-resource-operation.d.ts","sourceRoot":"","sources":["../../src/http/supplied-rest-resource-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,+BAA+B,CAAC;AACxF,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,iBAAiB,EACjB,KAAK,wBAAwB,EAC9B,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAI3D,UAAU,sBAAsB,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,SAAS,MAAM;IAChE,aAAa,EAAE,kCAAkC,GAAG,SAAS,CAAC;IAC9D,MAAM,EAAE,cAAc,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IAC1D,MAAM,EAAE,CACN,OAAO,EAAE,wBAAwB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,KACvD,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IAChC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC1B,kBAAkB,EAAE,SAAS,cAAc,EAAE,CAAC;IAC9C,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC;AAED,eAAO,MAAM,iBAAiB,GAAI,MAAM,EAAE,OAAO,EAAE,CAAC,SAAS,MAAM,SAC1D,sBAAsB,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,KAChD;IACD,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;CAiC/D,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SemanticOperation, } from "./operation.js";
|
|
2
|
+
import { compileRoute } from "./route.js";
|
|
3
|
+
import { semanticHttpOperation } from "./semantic-http-operation.js";
|
|
4
|
+
export const suppliedOperation = (props) => {
|
|
5
|
+
const semantic = new SemanticOperation(props.handle);
|
|
6
|
+
if (!props.enabled) {
|
|
7
|
+
return { semantic };
|
|
8
|
+
}
|
|
9
|
+
const relativePath = props.configuration?.path ?? props.defaultPath;
|
|
10
|
+
if (relativePath !== "" && !relativePath.startsWith("/")) {
|
|
11
|
+
throw new TypeError(`Expected a resource-relative operation path such as "/:id", received "${relativePath}".`);
|
|
12
|
+
}
|
|
13
|
+
const route = compileRoute(`${props.resource.path}${relativePath}`, props.requiredParameters);
|
|
14
|
+
return {
|
|
15
|
+
semantic,
|
|
16
|
+
http: semanticHttpOperation({
|
|
17
|
+
decode: props.decode,
|
|
18
|
+
encode: props.encode,
|
|
19
|
+
method: props.configuration?.method ?? props.defaultMethod,
|
|
20
|
+
resource: props.resource,
|
|
21
|
+
resourceMiddleware: props.resourceMiddleware,
|
|
22
|
+
route,
|
|
23
|
+
semantic,
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=supplied-rest-resource-operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supplied-rest-resource-operation.js","sourceRoot":"","sources":["../../src/http/supplied-rest-resource-operation.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,iBAAiB,GAElB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAiBrE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,KAAiD,EAIjD,EAAE;IACF,MAAM,QAAQ,GAAG,IAAI,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAErD,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,EAAE,QAAQ,EAAE,CAAC;IACtB,CAAC;IAED,MAAM,YAAY,GAAG,KAAK,CAAC,aAAa,EAAE,IAAI,IAAI,KAAK,CAAC,WAAW,CAAC;IAEpE,IAAI,YAAY,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,SAAS,CACjB,yEAAyE,YAAY,IAAI,CAC1F,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAG,YAAY,CACxB,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,GAAG,YAAY,EAAE,EACvC,KAAK,CAAC,kBAAkB,CACzB,CAAC;IAEF,OAAO;QACL,QAAQ;QACR,IAAI,EAAE,qBAAqB,CAAC;YAC1B,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,MAAM,EAAE,KAAK,CAAC,aAAa,EAAE,MAAM,IAAI,KAAK,CAAC,aAAa;YAC1D,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;YAC5C,KAAK;YACL,QAAQ;SACT,CAAC;KACH,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
export { SimApi, type
|
|
1
|
+
export { SimApi, type SimApiProps, type SimApiResourceProps } from "./api.js";
|
|
2
2
|
export { SimEnvironment, type SimEnvironmentProps, type SimService, type UnhandledRequestPolicy, } from "./environment.js";
|
|
3
3
|
export { DuplicateEntityError } from "./duplicate-entity-error.js";
|
|
4
4
|
export { EntityNotFoundError } from "./entity-not-found-error.js";
|
|
5
|
-
export {
|
|
5
|
+
export type { HttpMiddleware, HttpOperationContext, RawHttpOperation, SemanticOperationContext, SemanticOperationOverride, } from "./http/operation.js";
|
|
6
|
+
export { SemanticOperation } from "./http/operation.js";
|
|
7
|
+
export { decodeForm } from "./http/decode-form.js";
|
|
8
|
+
export type { ErrorFormatter } from "./http/error-formatter.js";
|
|
9
|
+
export { requirePathParameter } from "./http/path-parameter.js";
|
|
10
|
+
export type { RawHttpOperationHandler } from "./http/raw-operation.js";
|
|
11
|
+
export { decodeJson, type RequestDecoder } from "./http/request-decoder.js";
|
|
6
12
|
export { RestResource } from "./rest-resource.js";
|
|
7
|
-
export {
|
|
13
|
+
export type { ResourceLocator, ResourceOperationProps, RestResourceOperationConfiguration, RestResourceOperationName, RestResourceOperationSetting, RestResourceOperations, RestResourceProps, } from "./rest-resource-operation.js";
|
|
8
14
|
export { SimResource, type SimResourceProps } from "./resource.js";
|
|
9
15
|
export { UnclaimedOriginError } from "./unclaimed-origin-error.js";
|
|
16
|
+
export { SimWebhooks, type SimWebhooksProps, type WebhookDelivery, type WebhookDeliveryResult, type WebhookDeliveryTiming, } from "./webhooks.js";
|
|
10
17
|
export { UnimplementedRouteError } from "./unimplemented-route-error.js";
|
|
11
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,EACL,cAAc,EACd,KAAK,mBAAmB,EACxB,KAAK,UAAU,EACf,KAAK,sBAAsB,GAC5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,YAAY,EACV,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,YAAY,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,YAAY,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EACV,eAAe,EACf,sBAAsB,EACtB,kCAAkC,EAClC,yBAAyB,EACzB,4BAA4B,EAC5B,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EACL,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,GAC3B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
export { SimApi
|
|
1
|
+
export { SimApi } from "./api.js";
|
|
2
2
|
export { SimEnvironment, } from "./environment.js";
|
|
3
3
|
export { DuplicateEntityError } from "./duplicate-entity-error.js";
|
|
4
4
|
export { EntityNotFoundError } from "./entity-not-found-error.js";
|
|
5
|
-
export { SemanticOperation
|
|
5
|
+
export { SemanticOperation } from "./http/operation.js";
|
|
6
|
+
export { decodeForm } from "./http/decode-form.js";
|
|
7
|
+
export { requirePathParameter } from "./http/path-parameter.js";
|
|
8
|
+
export { decodeJson } from "./http/request-decoder.js";
|
|
6
9
|
export { RestResource } from "./rest-resource.js";
|
|
7
|
-
export {} from "./rest-resource-operation.js";
|
|
8
10
|
export { SimResource } from "./resource.js";
|
|
9
11
|
export { UnclaimedOriginError } from "./unclaimed-origin-error.js";
|
|
12
|
+
export { SimWebhooks, } from "./webhooks.js";
|
|
10
13
|
export { UnimplementedRouteError } from "./unimplemented-route-error.js";
|
|
11
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA8C,MAAM,UAAU,CAAC;AAC9E,OAAO,EACL,cAAc,GAIf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAQlE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,OAAO,EAAE,UAAU,EAAuB,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAUlD,OAAO,EAAE,WAAW,EAAyB,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EACL,WAAW,GAKZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC"}
|
package/dist/resource.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface SimResourceProps<T extends object> {
|
|
|
8
8
|
export declare class SimResource<T extends object> {
|
|
9
9
|
#private;
|
|
10
10
|
readonly name: string | undefined;
|
|
11
|
-
constructor(props
|
|
11
|
+
constructor(props?: SimResourceProps<T>);
|
|
12
12
|
/** Stores an exact entity for simulation arrangement. */
|
|
13
13
|
seed(entity: T): T;
|
|
14
14
|
/** Runs the resource's creation behaviour and stores its result. */
|
package/dist/resource.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAeA,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM;IAChD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,0EAA0E;AAC1E,qBAAa,WAAW,CAAC,CAAC,SAAS,MAAM;;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAKlC,YAAY,KAAK,
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAeA,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM;IAChD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,0EAA0E;AAC1E,qBAAa,WAAW,CAAC,CAAC,SAAS,MAAM;;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAKlC,YAAY,KAAK,GAAE,gBAAgB,CAAC,CAAC,CAAM,EAI1C;IAED,yDAAyD;IACzD,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAEjB;IAED,oEAAoE;IACpE,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAE3B;IAED,+DAA+D;IAC/D,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,CAQvB;IAED,kDAAkD;IAClD,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAEpC;IAED,+CAA+C;IAC/C,IAAI,IAAI,CAAC,EAAE,CAEV;IAED,8CAA8C;IAC9C,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAe/C;IAED,iDAAiD;IACjD,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,CAI1B;IAED,+CAA+C;IAC/C,KAAK,IAAI,IAAI,CAEZ;CAYF"}
|
package/dist/resource.js
CHANGED
|
@@ -13,7 +13,7 @@ export class SimResource {
|
|
|
13
13
|
#createEntity;
|
|
14
14
|
#entities = new Map();
|
|
15
15
|
#identify;
|
|
16
|
-
constructor(props) {
|
|
16
|
+
constructor(props = {}) {
|
|
17
17
|
this.name = props.name;
|
|
18
18
|
this.#createEntity = props.create ?? ((input) => input);
|
|
19
19
|
this.#identify = props.identify ?? identifyById;
|
package/dist/resource.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,SAAS,YAAY,CAAC,MAAc;IAClC,MAAM,QAAQ,GAAI,MAA2B,CAAC,EAAE,CAAC;IAEjD,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,MAAM,IAAI,SAAS,CACjB,wGAAwG,CACzG,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AASD,0EAA0E;AAC1E,MAAM,OAAO,WAAW;IACb,IAAI,CAAqB;IACzB,aAAa,CAA2B;IACxC,SAAS,GAAG,IAAI,GAAG,EAAa,CAAC;IACjC,SAAS,CAAwB;IAE1C,YAAY,
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../src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AE,CAAC;IACzB,CAAC;IAED,OAAO,CAAC,MAAS;QACf,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAExC,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,oBAAoB,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACtD,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACrC,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -1,13 +1,30 @@
|
|
|
1
1
|
import type { SemanticOperation, SemanticOperationContext } from "./http/operation.js";
|
|
2
|
+
import type { RequestDecoder } from "./http/request-decoder.js";
|
|
2
3
|
import type { RestResource } from "./rest-resource.js";
|
|
3
|
-
/**
|
|
4
|
+
/** Turns matched route parameters into one resource state identity. */
|
|
5
|
+
export type ResourceLocator = (params: Readonly<Record<string, string>>) => string;
|
|
6
|
+
/** Changes the route and request decoding of one supplied resource operation. */
|
|
4
7
|
export interface RestResourceOperationConfiguration {
|
|
8
|
+
/** Replaces the decoder inherited from the resource or API. */
|
|
9
|
+
decode?: RequestDecoder;
|
|
10
|
+
/** Replaces the supplied operation's conventional HTTP method. */
|
|
5
11
|
method?: string;
|
|
12
|
+
/** Replaces the path appended to the resource collection path. */
|
|
6
13
|
path?: string;
|
|
7
14
|
}
|
|
15
|
+
/** Configures one supplied operation or leaves its route unimplemented. */
|
|
16
|
+
export type RestResourceOperationSetting = RestResourceOperationConfiguration | false;
|
|
8
17
|
/** Configures the HTTP path and supplied operations for a simulated resource. */
|
|
9
18
|
export interface RestResourceProps {
|
|
10
|
-
operations
|
|
19
|
+
/** Reads request bodies for operations without their own decoder. */
|
|
20
|
+
decode?: RequestDecoder;
|
|
21
|
+
/** The path appended for get, update and delete. `/:id` by default. */
|
|
22
|
+
itemPath?: string;
|
|
23
|
+
/** Maps item route parameters to state identity. Reads `:id` by default. */
|
|
24
|
+
locate?: ResourceLocator;
|
|
25
|
+
/** Moves, decodes or disables the five supplied operations. */
|
|
26
|
+
operations?: Partial<Record<RestResourceOperationName, RestResourceOperationSetting>>;
|
|
27
|
+
/** The absolute collection path, including any parent parameters. */
|
|
11
28
|
path: string;
|
|
12
29
|
}
|
|
13
30
|
/** Names the supplied resource behaviours. */
|
|
@@ -22,6 +39,7 @@ export interface RestResourceOperations<T extends object> {
|
|
|
22
39
|
}
|
|
23
40
|
/** Configures a domain action under a resource path. */
|
|
24
41
|
export interface ResourceOperationProps<T extends object, TInput, TOutput> {
|
|
42
|
+
decode?: RequestDecoder;
|
|
25
43
|
handle: (context: SemanticOperationContext<TInput, RestResource<T>>) => Promise<TOutput> | TOutput;
|
|
26
44
|
method: string;
|
|
27
45
|
path: string;
|