@distilled.cloud/elasticsearch 1.0.0-rc.11 → 1.0.0-rc.13
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 +34 -0
- package/lib/protocol.d.ts +4 -4
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +2 -1
- package/lib/protocol.js.map +1 -1
- package/lib/response-validation.test.d.ts +6 -0
- package/lib/response-validation.test.d.ts.map +1 -0
- package/lib/response-validation.test.js +33 -0
- package/lib/response-validation.test.js.map +1 -0
- package/package.json +4 -4
- package/src/protocol.ts +10 -4
- package/src/response-validation.test.ts +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @distilled.cloud/elasticsearch
|
|
2
|
+
|
|
3
|
+
Effect-native SDK for [elasticsearch](https://www.npmjs.com/package/@distilled.cloud/elasticsearch).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @distilled.cloud/elasticsearch effect
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Effect, Layer } from "effect";
|
|
15
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
16
|
+
import * as Elasticsearch from "@distilled.cloud/elasticsearch";
|
|
17
|
+
|
|
18
|
+
const program = Effect.gen(function* () {
|
|
19
|
+
const result = yield* Elasticsearch.info({});
|
|
20
|
+
return result;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const Live = Layer.mergeAll(
|
|
24
|
+
FetchHttpClient.layer,
|
|
25
|
+
Elasticsearch.CredentialsFromEnv,
|
|
26
|
+
Elasticsearch.ElasticsearchProtocol,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
program.pipe(Effect.provide(Live), Effect.runPromise);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Auth
|
|
33
|
+
|
|
34
|
+
Required: `ELASTICSEARCH_API_KEY`, `ELASTIC_API_KEY`. Optional: `ELASTICSEARCH_API_BASE_URL`. Sent as `Authorization: Bearer`.
|
package/lib/protocol.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type * as Layer from "effect/Layer";
|
|
2
|
-
import type * as HttpClient from "effect/
|
|
3
|
-
import type * as HttpClientError from "effect/
|
|
2
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
3
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
4
4
|
import type * as API from "@distilled.cloud/core/api";
|
|
5
5
|
import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
|
|
6
6
|
import { Credentials } from "./credentials.ts";
|
|
7
|
-
import { UnknownElasticsearchError } from "./errors.ts";
|
|
7
|
+
import { UnknownElasticsearchError, ElasticsearchParseError } from "./errors.ts";
|
|
8
8
|
/**
|
|
9
9
|
* Error channel shared by every generated Elasticsearch operation. Generated
|
|
10
10
|
* service files annotate operations with `API.OperationMethod<I, O,
|
|
11
11
|
* ElasticsearchOpError, ElasticsearchOpContext>` explicitly so the compiler
|
|
12
12
|
* never infers these back out of the schema generics.
|
|
13
13
|
*/
|
|
14
|
-
export type ElasticsearchOpError = InstanceType<(typeof API_ERRORS)[number]> | UnknownElasticsearchError | ConfigError | HttpClientError.HttpClientError;
|
|
14
|
+
export type ElasticsearchOpError = InstanceType<(typeof API_ERRORS)[number]> | UnknownElasticsearchError | ConfigError | HttpClientError.HttpClientError | ElasticsearchParseError;
|
|
15
15
|
/** Context (requirements) shared by every generated Elasticsearch operation. */
|
|
16
16
|
export type ElasticsearchOpContext = Credentials | HttpClient.HttpClient;
|
|
17
17
|
export declare const ElasticsearchProtocol: Layer.Layer<API.Protocol>;
|
package/lib/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,KAAK,eAAe,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,KAAK,GAAG,MAAM,2BAA2B,CAAC;AAEtD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EACL,yBAAyB,EACzB,uBAAuB,EACxB,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAC5B,YAAY,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,GACzC,yBAAyB,GACzB,WAAW,GACX,eAAe,CAAC,eAAe,GAC/B,uBAAuB,CAAC;AAE5B,gFAAgF;AAChF,MAAM,MAAM,sBAAsB,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AAEzE,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CA2BxD,CAAC"}
|
package/lib/protocol.js
CHANGED
|
@@ -19,7 +19,7 @@ import * as Effect from "effect/Effect";
|
|
|
19
19
|
import * as Redacted from "effect/Redacted";
|
|
20
20
|
import { makeRestProtocol } from "@distilled.cloud/core/protocol-rest";
|
|
21
21
|
import { Credentials } from "./credentials.js";
|
|
22
|
-
import { UnknownElasticsearchError } from "./errors.js";
|
|
22
|
+
import { UnknownElasticsearchError, ElasticsearchParseError, } from "./errors.js";
|
|
23
23
|
export const ElasticsearchProtocol = makeRestProtocol({
|
|
24
24
|
// The Credentials service holds an effect — resolving it here (per
|
|
25
25
|
// request, on the calling fiber) picks up context-provided credentials.
|
|
@@ -42,5 +42,6 @@ export const ElasticsearchProtocol = makeRestProtocol({
|
|
|
42
42
|
message,
|
|
43
43
|
body,
|
|
44
44
|
}),
|
|
45
|
+
parseError: ({ body, cause }) => new ElasticsearchParseError({ body, cause }),
|
|
45
46
|
});
|
|
46
47
|
//# sourceMappingURL=protocol.js.map
|
package/lib/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvE,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvE,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EACL,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AAkBrB,MAAM,CAAC,MAAM,qBAAqB,GAChC,gBAAgB,CAAS;IACvB,mEAAmE;IACnE,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC/B,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC;QACnC,OAAO,KAAK,CAAC,CAAC,OAAO,CAAC;IACxB,CAAC,CAAC;IACF,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU;IACpC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACnB,aAAa,EAAE,UAAU,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;KACxD,CAAC;IACF,wEAAwE;IACxE,sEAAsE;IACtE,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CACxC,IAAI,yBAAyB,CAAC;QAC5B,IAAI,EACF,OAAO,IAAI,KAAK,QAAQ;YACtB,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,IAAI,KAAK,SAAS;gBAClB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;gBACd,CAAC,CAAC,SAAS;QACjB,OAAO;QACP,IAAI;KACL,CAAC;IACJ,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAC9B,IAAI,uBAAuB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;CAC/C,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ElasticsearchParseError } from "./errors.ts";
|
|
2
|
+
import type { ElasticsearchOpError } from "./protocol.ts";
|
|
3
|
+
export declare const parseErrorIsDeclared: [ElasticsearchParseError] extends [
|
|
4
|
+
ElasticsearchOpError
|
|
5
|
+
] ? true : false;
|
|
6
|
+
//# sourceMappingURL=response-validation.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-validation.test.d.ts","sourceRoot":"","sources":["../src/response-validation.test.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAGtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAqC1D,eAAO,MAAM,oBAAoB,EAAE,CAAC,uBAAuB,CAAC,SAAS;IACnE,oBAAoB;CACrB,GACG,IAAI,GACJ,KAAY,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { runValidationModes } from "@distilled.cloud/core/testing";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import { fromApiKey } from "./credentials.js";
|
|
5
|
+
import { ElasticsearchParseError } from "./errors.js";
|
|
6
|
+
import * as Retry from "./retry.js";
|
|
7
|
+
import { licenseGetBasicStatus } from "./services/elasticsearch.js";
|
|
8
|
+
// licenseGetBasicStatus declares `{ eligible_to_start_basic: boolean }`.
|
|
9
|
+
const run = (body) => runValidationModes(licenseGetBasicStatus({}).pipe(Retry.none, Effect.provide(fromApiKey({ apiKey: "test" }))), { body });
|
|
10
|
+
describe("Elasticsearch response validation", () => {
|
|
11
|
+
test("a matching body succeeds unchanged in both modes", async () => {
|
|
12
|
+
const body = { eligible_to_start_basic: true };
|
|
13
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
14
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
15
|
+
expect(strict).toMatchObject({ _tag: "Success", success: body });
|
|
16
|
+
});
|
|
17
|
+
test("a body missing required members: lenient returns it, strict fails", async () => {
|
|
18
|
+
const body = {};
|
|
19
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
20
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
21
|
+
expect(strict._tag).toBe("Failure");
|
|
22
|
+
expect(strict.failure).toBeInstanceOf(ElasticsearchParseError);
|
|
23
|
+
});
|
|
24
|
+
test("a non-JSON body: lenient returns the text, strict fails", async () => {
|
|
25
|
+
const { lenient, strict } = await run("not json");
|
|
26
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
|
|
27
|
+
expect(strict._tag).toBe("Failure");
|
|
28
|
+
expect(strict.failure).toBeInstanceOf(ElasticsearchParseError);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
// ElasticsearchParseError is part of every operation's declared error type.
|
|
32
|
+
export const parseErrorIsDeclared = true;
|
|
33
|
+
//# sourceMappingURL=response-validation.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-validation.test.js","sourceRoot":"","sources":["../src/response-validation.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAGpE,yEAAyE;AACzE,MAAM,GAAG,GAAG,CAAC,IAAY,EAAE,EAAE,CAC3B,kBAAkB,CAChB,qBAAqB,CAAC,EAAE,CAAC,CAAC,IAAI,CAC5B,KAAK,CAAC,IAAI,EACV,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAC/C,EACD,EAAE,IAAI,EAAE,CACT,CAAC;AAEJ,QAAQ,CAAC,mCAAmC,EAAE,GAAG,EAAE;IACjD,IAAI,CAAC,kDAAkD,EAAE,KAAK,IAAI,EAAE;QAClE,MAAM,IAAI,GAAG,EAAE,uBAAuB,EAAE,IAAI,EAAE,CAAC;QAC/C,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5D,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAClE,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,mEAAmE,EAAE,KAAK,IAAI,EAAE;QACnF,MAAM,IAAI,GAAG,EAAE,CAAC;QAChB,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5D,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAClE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACpC,MAAM,CAAE,MAAc,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,uBAAuB,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;QACzE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,CAAC;QAClD,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;QACxE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACpC,MAAM,CAAE,MAAc,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,uBAAuB,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,4EAA4E;AAC5E,MAAM,CAAC,MAAM,oBAAoB,GAIrB,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distilled.cloud/elasticsearch",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.13",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/alchemy-run/distilled",
|
|
@@ -64,15 +64,15 @@
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@distilled.cloud/core": "1.0.0-rc.
|
|
67
|
+
"@distilled.cloud/core": "1.0.0-rc.13"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@types/bun": "1.3.14",
|
|
71
71
|
"@types/node": "26.2.0",
|
|
72
|
-
"@effect/platform-bun": "
|
|
72
|
+
"@effect/platform-bun": "^4.0.0"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
|
-
"effect": "
|
|
75
|
+
"effect": "^4.0.0"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"build": "tsc -b",
|
package/src/protocol.ts
CHANGED
|
@@ -18,13 +18,16 @@
|
|
|
18
18
|
import * as Effect from "effect/Effect";
|
|
19
19
|
import type * as Layer from "effect/Layer";
|
|
20
20
|
import * as Redacted from "effect/Redacted";
|
|
21
|
-
import type * as HttpClient from "effect/
|
|
22
|
-
import type * as HttpClientError from "effect/
|
|
21
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
22
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
23
23
|
import type * as API from "@distilled.cloud/core/api";
|
|
24
24
|
import { makeRestProtocol } from "@distilled.cloud/core/protocol-rest";
|
|
25
25
|
import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
|
|
26
26
|
import { Credentials, type Config } from "./credentials.ts";
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
UnknownElasticsearchError,
|
|
29
|
+
ElasticsearchParseError,
|
|
30
|
+
} from "./errors.ts";
|
|
28
31
|
|
|
29
32
|
/**
|
|
30
33
|
* Error channel shared by every generated Elasticsearch operation. Generated
|
|
@@ -36,7 +39,8 @@ export type ElasticsearchOpError =
|
|
|
36
39
|
| InstanceType<(typeof API_ERRORS)[number]>
|
|
37
40
|
| UnknownElasticsearchError
|
|
38
41
|
| ConfigError
|
|
39
|
-
| HttpClientError.HttpClientError
|
|
42
|
+
| HttpClientError.HttpClientError
|
|
43
|
+
| ElasticsearchParseError;
|
|
40
44
|
|
|
41
45
|
/** Context (requirements) shared by every generated Elasticsearch operation. */
|
|
42
46
|
export type ElasticsearchOpContext = Credentials | HttpClient.HttpClient;
|
|
@@ -66,4 +70,6 @@ export const ElasticsearchProtocol: Layer.Layer<API.Protocol> =
|
|
|
66
70
|
message,
|
|
67
71
|
body,
|
|
68
72
|
}),
|
|
73
|
+
parseError: ({ body, cause }) =>
|
|
74
|
+
new ElasticsearchParseError({ body, cause }),
|
|
69
75
|
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { runValidationModes } from "@distilled.cloud/core/testing";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import { fromApiKey } from "./credentials.ts";
|
|
5
|
+
import { ElasticsearchParseError } from "./errors.ts";
|
|
6
|
+
import * as Retry from "./retry.ts";
|
|
7
|
+
import { licenseGetBasicStatus } from "./services/elasticsearch.ts";
|
|
8
|
+
import type { ElasticsearchOpError } from "./protocol.ts";
|
|
9
|
+
|
|
10
|
+
// licenseGetBasicStatus declares `{ eligible_to_start_basic: boolean }`.
|
|
11
|
+
const run = (body: string) =>
|
|
12
|
+
runValidationModes(
|
|
13
|
+
licenseGetBasicStatus({}).pipe(
|
|
14
|
+
Retry.none,
|
|
15
|
+
Effect.provide(fromApiKey({ apiKey: "test" })),
|
|
16
|
+
),
|
|
17
|
+
{ body },
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
describe("Elasticsearch response validation", () => {
|
|
21
|
+
test("a matching body succeeds unchanged in both modes", async () => {
|
|
22
|
+
const body = { eligible_to_start_basic: true };
|
|
23
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
24
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
25
|
+
expect(strict).toMatchObject({ _tag: "Success", success: body });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("a body missing required members: lenient returns it, strict fails", async () => {
|
|
29
|
+
const body = {};
|
|
30
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
31
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
32
|
+
expect(strict._tag).toBe("Failure");
|
|
33
|
+
expect((strict as any).failure).toBeInstanceOf(ElasticsearchParseError);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("a non-JSON body: lenient returns the text, strict fails", async () => {
|
|
37
|
+
const { lenient, strict } = await run("not json");
|
|
38
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
|
|
39
|
+
expect(strict._tag).toBe("Failure");
|
|
40
|
+
expect((strict as any).failure).toBeInstanceOf(ElasticsearchParseError);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// ElasticsearchParseError is part of every operation's declared error type.
|
|
45
|
+
export const parseErrorIsDeclared: [ElasticsearchParseError] extends [
|
|
46
|
+
ElasticsearchOpError,
|
|
47
|
+
]
|
|
48
|
+
? true
|
|
49
|
+
: false = true;
|