@distilled.cloud/mongodb-atlas 0.16.2 → 0.16.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAgBxC,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAuC/C;;GAEG;AACH,eAAO,MAAM,GAAG;;;CAQd,CAAC"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAkBxC,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AA4C/C;;GAEG;AACH,eAAO,MAAM,GAAG;;;CASd,CAAC"}
package/lib/client.js CHANGED
@@ -8,6 +8,8 @@ import * as Effect from "effect/Effect";
8
8
  import * as Redacted from "effect/Redacted";
9
9
  import * as Schema from "effect/Schema";
10
10
  import { makeAPI } from "@distilled.cloud/core/client";
11
+ import { parseRetryAfterForStatus } from "@distilled.cloud/core/retry-after";
12
+ import { Retry } from "./retry.js";
11
13
  import { HTTP_STATUS_MAP, PaymentRequired, UnknownMongodbAtlasError, MongodbAtlasParseError, } from "./errors.js";
12
14
  // Extend the core status map with Atlas-specific error classes
13
15
  const STATUS_MAP = {
@@ -28,12 +30,15 @@ const ApiErrorResponse = Schema.Struct({
28
30
  /**
29
31
  * Match a Mongodb-atlas API error response to the appropriate error class based on HTTP status.
30
32
  */
31
- const matchError = (status, errorBody) => {
33
+ const matchError = (status, errorBody, _errors, headers) => {
32
34
  try {
33
35
  const parsed = Schema.decodeUnknownSync(ApiErrorResponse)(errorBody);
34
36
  const ErrorClass = STATUS_MAP[status];
35
37
  if (ErrorClass) {
36
- return Effect.fail(new ErrorClass({ message: parsed.detail ?? parsed.reason ?? "" }));
38
+ return Effect.fail(new ErrorClass({
39
+ message: parsed.detail ?? parsed.reason ?? "",
40
+ retryAfter: parseRetryAfterForStatus(status, headers),
41
+ }));
37
42
  }
38
43
  return Effect.fail(new UnknownMongodbAtlasError({
39
44
  errorCode: parsed.errorCode,
@@ -57,5 +62,6 @@ export const API = makeAPI({
57
62
  }),
58
63
  matchError,
59
64
  ParseError: MongodbAtlasParseError,
65
+ retry: Retry,
60
66
  });
61
67
  //# sourceMappingURL=client.js.map
package/lib/client.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AACvD,OAAO,EACL,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,+DAA+D;AAC/D,MAAM,UAAU,GAAwB;IACtC,GAAG,eAAe;IAClB,GAAG,EAAE,eAAe;CACrB,CAAC;AAEF,wCAAwC;AACxC,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,0CAA0C;AAC1C,kGAAkG;AAClG,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,KAAK,EAAE,MAAM,CAAC,MAAM;IACpB,SAAS,EAAE,MAAM,CAAC,MAAM;IACxB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACtC,MAAM,EAAE,MAAM,C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CAAC;YACf,OAAO,MAAM,CAAC,IAAI,CAChB,IAAI,UAAU,CAAC;gBACb,OAAO,EAAE,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,IAAI,EAAE;gBAC7C,UAAU,EAAE,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC;aACtD,CAAC,CACH,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAChB,IAAI,wBAAwB,CAAC;YAC3B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,IAAI,EAAE,SAAS;SAChB,CAAC,CACH,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,wBAAwB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;IACxE,CAAC;AACH,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,OAAO,CAAc;IACtC,WAAW,EAAE,WAAkB;IAC/B,UAAU,EAAE,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU;IAC5C,cAAc,EAAE,CAAC,KAAU,EAAE,EAAE,CAAC,CAAC;QAC/B,aAAa,EAAE,UAAU,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE;KAC7D,CAAC;IACF,UAAU;IACV,UAAU,EAAE,sBAA6B;IACzC,KAAK,EAAE,KAAY;CACpB,CAAC,CAAC"}
package/lib/retry.d.ts CHANGED
@@ -1,22 +1,33 @@
1
1
  /**
2
- * Mongodb-atlas retry configuration.
2
+ * MongoDBAtlas retry configuration.
3
+ *
4
+ * Defines the per-SDK `Retry` Context.Service tag that
5
+ * `packages/mongodb-atlas/src/client.ts` wires into `makeAPI`. Callers can
6
+ * install a blanket retry policy at the layer level and have every
7
+ * MongoDBAtlas API call below it pick it up:
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import * as MongoDBAtlas from "@distilled.cloud/mongodb-atlas";
12
+ *
13
+ * myEffect.pipe(MongoDBAtlas.Retry.transient);
14
+ * Effect.provide(myEffect, Layer.succeed(MongoDBAtlas.Retry.Retry, customPolicy));
15
+ * ```
3
16
  */
4
- import * as Effect from "effect/Effect";
5
17
  import * as Context from "effect/Context";
6
- export { type Options, type Factory, type Policy, makeDefault, jittered, capped, throttlingOptions, transientOptions, } from "@distilled.cloud/core/retry";
7
- import type { Policy } from "@distilled.cloud/core/retry";
8
- declare const Retry_base: Context.ServiceClass<Retry, "Mongodb-atlasRetry", Policy>;
9
- /**
10
- * Context tag for configuring retry behavior of Mongodb-atlas API calls.
11
- */
18
+ import * as Effect from "effect/Effect";
19
+ import { type Policy } from "@distilled.cloud/core/retry";
20
+ export { type Options, type Factory, type Policy, makeDefault, jittered, capped, throttlingOptions, transientOptions, throttlingFactory, transientFactory, } from "@distilled.cloud/core/retry";
21
+ declare const Retry_base: Context.ServiceClass<Retry, "MongoDBAtlasRetry", Policy>;
22
+ /** Context tag for configuring retry behavior of MongoDBAtlas API calls. */
12
23
  export declare class Retry extends Retry_base {
13
24
  }
14
- /**
15
- * Provides a custom retry policy to all Mongodb-atlas API calls.
16
- */
25
+ /** Provides a custom retry policy to every MongoDBAtlas API call below it. */
17
26
  export declare const policy: (optionsOrFactory: Policy) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
18
- /**
19
- * Disables all automatic retries.
20
- */
27
+ /** Disables all automatic retries. */
21
28
  export declare const none: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
29
+ /** Apply the throttling retry policy (retries throttling errors indefinitely). */
30
+ export declare const throttling: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
31
+ /** Apply the transient retry policy (retries all transient errors indefinitely). */
32
+ export declare const transient: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
22
33
  //# sourceMappingURL=retry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,WAAW,EACX,QAAQ,EACR,MAAM,EACN,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;;AAE1D;;GAEG;AACH,qBAAa,KAAM,SAAQ,UAE1B;CAAG;AAEJ;;GAEG;AACH,eAAO,MAAM,MAAM,qBAAsB,MAAM,sFACS,CAAC;AAEzD;;GAEG;AACH,eAAO,MAAM,IAAI,mFAEhB,CAAC"}
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EACL,KAAK,MAAM,EAGZ,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,WAAW,EACX,QAAQ,EACR,MAAM,EACN,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;;AAErC,4EAA4E;AAC5E,qBAAa,KAAM,SAAQ,UAE1B;CAAG;AAEJ,8EAA8E;AAC9E,eAAO,MAAM,MAAM,qBAAsB,MAAM,sFACS,CAAC;AAEzD,sCAAsC;AACtC,eAAO,MAAM,IAAI,mFAEhB,CAAC;AAEF,kFAAkF;AAClF,eAAO,MAAM,UAAU,mFAA4B,CAAC;AAEpD,oFAAoF;AACpF,eAAO,MAAM,SAAS,mFAA2B,CAAC"}
package/lib/retry.js CHANGED
@@ -1,21 +1,33 @@
1
1
  /**
2
- * Mongodb-atlas retry configuration.
2
+ * MongoDBAtlas retry configuration.
3
+ *
4
+ * Defines the per-SDK `Retry` Context.Service tag that
5
+ * `packages/mongodb-atlas/src/client.ts` wires into `makeAPI`. Callers can
6
+ * install a blanket retry policy at the layer level and have every
7
+ * MongoDBAtlas API call below it pick it up:
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import * as MongoDBAtlas from "@distilled.cloud/mongodb-atlas";
12
+ *
13
+ * myEffect.pipe(MongoDBAtlas.Retry.transient);
14
+ * Effect.provide(myEffect, Layer.succeed(MongoDBAtlas.Retry.Retry, customPolicy));
15
+ * ```
3
16
  */
17
+ import * as Context from "effect/Context";
4
18
  import * as Effect from "effect/Effect";
5
19
  import * as Layer from "effect/Layer";
6
- import * as Context from "effect/Context";
7
- export { makeDefault, jittered, capped, throttlingOptions, transientOptions, } from "@distilled.cloud/core/retry";
8
- /**
9
- * Context tag for configuring retry behavior of Mongodb-atlas API calls.
10
- */
11
- export class Retry extends Context.Service()("Mongodb-atlasRetry") {
20
+ import { throttlingFactory, transientFactory, } from "@distilled.cloud/core/retry";
21
+ export { makeDefault, jittered, capped, throttlingOptions, transientOptions, throttlingFactory, transientFactory, } from "@distilled.cloud/core/retry";
22
+ /** Context tag for configuring retry behavior of MongoDBAtlas API calls. */
23
+ export class Retry extends Context.Service()("MongoDBAtlasRetry") {
12
24
  }
13
- /**
14
- * Provides a custom retry policy to all Mongodb-atlas API calls.
15
- */
25
+ /** Provides a custom retry policy to every MongoDBAtlas API call below it. */
16
26
  export const policy = (optionsOrFactory) => Effect.provide(Layer.succeed(Retry, optionsOrFactory));
17
- /**
18
- * Disables all automatic retries.
19
- */
27
+ /** Disables all automatic retries. */
20
28
  export const none = Effect.provide(Layer.succeed(Retry, { while: () => false }));
29
+ /** Apply the throttling retry policy (retries throttling errors indefinitely). */
30
+ export const throttling = policy(throttlingFactory);
31
+ /** Apply the transient retry policy (retries all transient errors indefinitely). */
32
+ export const transient = policy(transientFactory);
21
33
  //# sourceMappingURL=retry.js.map
package/lib/retry.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAIL,WAAW,EACX,QAAQ,EACR,MAAM,EACN,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AAGrC;;GAEG;AACH,MAAM,OAAO,KAAM,SAAQ,OAAO,CAAC,OAAO,EAAiB,CACzD,oBAAoB,CACrB;CAAG;AAEJ;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,gBAAwB,EAAE,EAAE,CACjD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAEzD;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAChC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,CAC7C,CAAC"}
1
+ {"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,EAEL,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAIL,WAAW,EACX,QAAQ,EACR,MAAM,EACN,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AAErC,4EAA4E;AAC5E,MAAM,OAAO,KAAM,SAAQ,OAAO,CAAC,OAAO,EAAiB,CACzD,mBAAmB,CACpB;CAAG;AAEJ,8EAA8E;AAC9E,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,gBAAwB,EAAE,EAAE,CACjD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAEzD,sCAAsC;AACtC,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAChC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,CAC7C,CAAC;AAEF,kFAAkF;AAClF,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAEpD,oFAAoF;AACpF,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distilled.cloud/mongodb-atlas",
3
- "version": "0.16.2",
3
+ "version": "0.16.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/alchemy-run/distilled",
@@ -74,7 +74,7 @@
74
74
  "specs:update": "git -C specs/distilled-spec-mongodb-atlas fetch && git -C specs/distilled-spec-mongodb-atlas checkout main && git -C specs/distilled-spec-mongodb-atlas pull"
75
75
  },
76
76
  "dependencies": {
77
- "@distilled.cloud/core": "0.16.2",
77
+ "@distilled.cloud/core": "0.16.4",
78
78
  "effect": "4.0.0-beta.58"
79
79
  },
80
80
  "devDependencies": {
package/src/client.ts CHANGED
@@ -8,6 +8,8 @@ import * as Effect from "effect/Effect";
8
8
  import * as Redacted from "effect/Redacted";
9
9
  import * as Schema from "effect/Schema";
10
10
  import { makeAPI } from "@distilled.cloud/core/client";
11
+ import { parseRetryAfterForStatus } from "@distilled.cloud/core/retry-after";
12
+ import { Retry } from "./retry.ts";
11
13
  import {
12
14
  HTTP_STATUS_MAP,
13
15
  PaymentRequired,
@@ -40,13 +42,18 @@ const ApiErrorResponse = Schema.Struct({
40
42
  const matchError = (
41
43
  status: number,
42
44
  errorBody: unknown,
45
+ _errors?: readonly unknown[],
46
+ headers?: Record<string, string | undefined>,
43
47
  ): Effect.Effect<never, unknown> => {
44
48
  try {
45
49
  const parsed = Schema.decodeUnknownSync(ApiErrorResponse)(errorBody);
46
50
  const ErrorClass = STATUS_MAP[status];
47
51
  if (ErrorClass) {
48
52
  return Effect.fail(
49
- new ErrorClass({ message: parsed.detail ?? parsed.reason ?? "" }),
53
+ new ErrorClass({
54
+ message: parsed.detail ?? parsed.reason ?? "",
55
+ retryAfter: parseRetryAfterForStatus(status, headers),
56
+ }),
50
57
  );
51
58
  }
52
59
  return Effect.fail(
@@ -73,4 +80,5 @@ export const API = makeAPI<Credentials>({
73
80
  }),
74
81
  matchError,
75
82
  ParseError: MongodbAtlasParseError as any,
83
+ retry: Retry as any,
76
84
  });
package/src/retry.ts CHANGED
@@ -1,9 +1,28 @@
1
1
  /**
2
- * Mongodb-atlas retry configuration.
2
+ * MongoDBAtlas retry configuration.
3
+ *
4
+ * Defines the per-SDK `Retry` Context.Service tag that
5
+ * `packages/mongodb-atlas/src/client.ts` wires into `makeAPI`. Callers can
6
+ * install a blanket retry policy at the layer level and have every
7
+ * MongoDBAtlas API call below it pick it up:
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import * as MongoDBAtlas from "@distilled.cloud/mongodb-atlas";
12
+ *
13
+ * myEffect.pipe(MongoDBAtlas.Retry.transient);
14
+ * Effect.provide(myEffect, Layer.succeed(MongoDBAtlas.Retry.Retry, customPolicy));
15
+ * ```
3
16
  */
17
+ import * as Context from "effect/Context";
4
18
  import * as Effect from "effect/Effect";
5
19
  import * as Layer from "effect/Layer";
6
- import * as Context from "effect/Context";
20
+ import {
21
+ type Policy,
22
+ throttlingFactory,
23
+ transientFactory,
24
+ } from "@distilled.cloud/core/retry";
25
+
7
26
  export {
8
27
  type Options,
9
28
  type Factory,
@@ -13,25 +32,26 @@ export {
13
32
  capped,
14
33
  throttlingOptions,
15
34
  transientOptions,
35
+ throttlingFactory,
36
+ transientFactory,
16
37
  } from "@distilled.cloud/core/retry";
17
- import type { Policy } from "@distilled.cloud/core/retry";
18
38
 
19
- /**
20
- * Context tag for configuring retry behavior of Mongodb-atlas API calls.
21
- */
39
+ /** Context tag for configuring retry behavior of MongoDBAtlas API calls. */
22
40
  export class Retry extends Context.Service<Retry, Policy>()(
23
- "Mongodb-atlasRetry",
41
+ "MongoDBAtlasRetry",
24
42
  ) {}
25
43
 
26
- /**
27
- * Provides a custom retry policy to all Mongodb-atlas API calls.
28
- */
44
+ /** Provides a custom retry policy to every MongoDBAtlas API call below it. */
29
45
  export const policy = (optionsOrFactory: Policy) =>
30
46
  Effect.provide(Layer.succeed(Retry, optionsOrFactory));
31
47
 
32
- /**
33
- * Disables all automatic retries.
34
- */
48
+ /** Disables all automatic retries. */
35
49
  export const none = Effect.provide(
36
50
  Layer.succeed(Retry, { while: () => false }),
37
51
  );
52
+
53
+ /** Apply the throttling retry policy (retries throttling errors indefinitely). */
54
+ export const throttling = policy(throttlingFactory);
55
+
56
+ /** Apply the transient retry policy (retries all transient errors indefinitely). */
57
+ export const transient = policy(transientFactory);