@quiverai/sdk 0.7.1 → 0.8.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.
Files changed (72) hide show
  1. package/dist/commonjs/hooks/types.d.ts +1 -0
  2. package/dist/commonjs/hooks/types.d.ts.map +1 -1
  3. package/dist/commonjs/lib/config.d.ts +3 -3
  4. package/dist/commonjs/lib/config.js +3 -3
  5. package/dist/commonjs/lib/encodings.js +12 -12
  6. package/dist/commonjs/lib/encodings.js.map +1 -1
  7. package/dist/commonjs/lib/event-streams.d.ts.map +1 -1
  8. package/dist/commonjs/lib/event-streams.js +28 -13
  9. package/dist/commonjs/lib/event-streams.js.map +1 -1
  10. package/dist/commonjs/lib/matchers.js +3 -3
  11. package/dist/commonjs/lib/matchers.js.map +1 -1
  12. package/dist/commonjs/lib/primitives.d.ts +1 -0
  13. package/dist/commonjs/lib/primitives.d.ts.map +1 -1
  14. package/dist/commonjs/lib/primitives.js +18 -0
  15. package/dist/commonjs/lib/primitives.js.map +1 -1
  16. package/dist/commonjs/lib/sdks.d.ts.map +1 -1
  17. package/dist/commonjs/lib/sdks.js +50 -16
  18. package/dist/commonjs/lib/sdks.js.map +1 -1
  19. package/dist/commonjs/sdk/models/shared/publicerrorenvelope.d.ts +0 -1
  20. package/dist/commonjs/sdk/models/shared/publicerrorenvelope.d.ts.map +1 -1
  21. package/dist/commonjs/sdk/models/shared/publicerrorenvelope.js +0 -1
  22. package/dist/commonjs/sdk/models/shared/publicerrorenvelope.js.map +1 -1
  23. package/dist/esm/hooks/types.d.ts +1 -0
  24. package/dist/esm/hooks/types.d.ts.map +1 -1
  25. package/dist/esm/lib/config.d.ts +3 -3
  26. package/dist/esm/lib/config.js +3 -3
  27. package/dist/esm/lib/encodings.js +1 -1
  28. package/dist/esm/lib/encodings.js.map +1 -1
  29. package/dist/esm/lib/event-streams.d.ts.map +1 -1
  30. package/dist/esm/lib/event-streams.js +28 -13
  31. package/dist/esm/lib/event-streams.js.map +1 -1
  32. package/dist/esm/lib/matchers.js +1 -1
  33. package/dist/esm/lib/matchers.js.map +1 -1
  34. package/dist/esm/lib/primitives.d.ts +1 -0
  35. package/dist/esm/lib/primitives.d.ts.map +1 -1
  36. package/dist/esm/lib/primitives.js +17 -0
  37. package/dist/esm/lib/primitives.js.map +1 -1
  38. package/dist/esm/lib/sdks.d.ts.map +1 -1
  39. package/dist/esm/lib/sdks.js +50 -16
  40. package/dist/esm/lib/sdks.js.map +1 -1
  41. package/dist/esm/sdk/models/shared/publicerrorenvelope.d.ts +0 -1
  42. package/dist/esm/sdk/models/shared/publicerrorenvelope.d.ts.map +1 -1
  43. package/dist/esm/sdk/models/shared/publicerrorenvelope.js +0 -1
  44. package/dist/esm/sdk/models/shared/publicerrorenvelope.js.map +1 -1
  45. package/jsr.json +1 -1
  46. package/package.json +1 -1
  47. package/src/hooks/types.ts +1 -0
  48. package/src/lib/config.ts +3 -3
  49. package/src/lib/encodings.ts +1 -1
  50. package/src/lib/event-streams.ts +31 -13
  51. package/src/lib/matchers.ts +1 -1
  52. package/src/lib/primitives.ts +16 -0
  53. package/src/lib/sdks.ts +54 -17
  54. package/src/sdk/models/shared/publicerrorenvelope.ts +0 -1
  55. package/dist/commonjs/lib/dlv.d.ts +0 -14
  56. package/dist/commonjs/lib/dlv.d.ts.map +0 -1
  57. package/dist/commonjs/lib/dlv.js +0 -49
  58. package/dist/commonjs/lib/dlv.js.map +0 -1
  59. package/dist/commonjs/lib/is-plain-object.d.ts +0 -2
  60. package/dist/commonjs/lib/is-plain-object.d.ts.map +0 -1
  61. package/dist/commonjs/lib/is-plain-object.js +0 -41
  62. package/dist/commonjs/lib/is-plain-object.js.map +0 -1
  63. package/dist/esm/lib/dlv.d.ts +0 -14
  64. package/dist/esm/lib/dlv.d.ts.map +0 -1
  65. package/dist/esm/lib/dlv.js +0 -46
  66. package/dist/esm/lib/dlv.js.map +0 -1
  67. package/dist/esm/lib/is-plain-object.d.ts +0 -2
  68. package/dist/esm/lib/is-plain-object.d.ts.map +0 -1
  69. package/dist/esm/lib/is-plain-object.js +0 -38
  70. package/dist/esm/lib/is-plain-object.js.map +0 -1
  71. package/src/lib/dlv.ts +0 -53
  72. package/src/lib/is-plain-object.ts +0 -43
@@ -11,7 +11,6 @@ export declare const Code: {
11
11
  readonly InsufficientCredits: "insufficient_credits";
12
12
  readonly AccountFrozen: "account_frozen";
13
13
  readonly ModelNotFound: "model_not_found";
14
- readonly UpstreamError: "upstream_error";
15
14
  readonly InternalError: "internal_error";
16
15
  };
17
16
  export type Code = ClosedEnum<typeof Code>;
@@ -1 +1 @@
1
- {"version":3,"file":"publicerrorenvelope.d.ts","sourceRoot":"","sources":["../../../../../src/sdk/models/shared/publicerrorenvelope.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAG5B,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,eAAO,MAAM,IAAI;;;;;;;;;;;CAWP,CAAC;AACX,MAAM,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;AAE3C,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,gBAAgB;AAChB,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,aAAa,CAAC,OAAO,IAAI,CAE3D,CAAC;AAEF,gBAAgB;AAChB,eAAO,MAAM,iCAAiC,EAAE,CAAC,CAAC,OAAO,CACvD,mBAAmB,EACnB,CAAC,CAAC,UAAU,EACZ,OAAO,CAUP,CAAC;AAEH,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,MAAM,GACjB,eAAe,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAM1D"}
1
+ {"version":3,"file":"publicerrorenvelope.d.ts","sourceRoot":"","sources":["../../../../../src/sdk/models/shared/publicerrorenvelope.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAG5B,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,eAAO,MAAM,IAAI;;;;;;;;;;CAUP,CAAC;AACX,MAAM,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;AAE3C,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,gBAAgB;AAChB,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,aAAa,CAAC,OAAO,IAAI,CAE3D,CAAC;AAEF,gBAAgB;AAChB,eAAO,MAAM,iCAAiC,EAAE,CAAC,CAAC,OAAO,CACvD,mBAAmB,EACnB,CAAC,CAAC,UAAU,EACZ,OAAO,CAUP,CAAC;AAEH,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,MAAM,GACjB,eAAe,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAM1D"}
@@ -13,7 +13,6 @@ export const Code = {
13
13
  InsufficientCredits: "insufficient_credits",
14
14
  AccountFrozen: "account_frozen",
15
15
  ModelNotFound: "model_not_found",
16
- UpstreamError: "upstream_error",
17
16
  InternalError: "internal_error",
18
17
  };
19
18
  /** @internal */
@@ -1 +1 @@
1
- {"version":3,"file":"publicerrorenvelope.js","sourceRoot":"","sources":["../../../../../src/sdk/models/shared/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,CAAC,CAAC,EAC7D,iDAAiD,CAClD,CAAC;AACJ,CAAC"}
package/jsr.json CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  {
4
4
  "name": "@quiverai/sdk",
5
- "version": "0.7.1",
5
+ "version": "0.8.0",
6
6
  "exports": {
7
7
  ".": "./src/index.ts",
8
8
  "./sdk/models/errors": "./src/sdk/models/errors/index.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quiverai/sdk",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "author": "QuiverAI",
5
5
  "type": "module",
6
6
  "tshy": {
@@ -15,6 +15,7 @@ export type HookContext = {
15
15
  retryConfig: RetryConfig;
16
16
  resolvedSecurity: SecurityState | null;
17
17
  options: SDKOptions;
18
+ timeoutMs?: number;
18
19
  };
19
20
 
20
21
  export type Awaitable<T> = T | Promise<T>;
package/src/lib/config.ts CHANGED
@@ -61,7 +61,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
61
61
  export const SDK_METADATA = {
62
62
  language: "typescript",
63
63
  openapiDocVersion: "1.0.0",
64
- sdkVersion: "0.7.1",
65
- genVersion: "2.893.0",
66
- userAgent: "speakeasy-sdk/typescript 0.7.1 2.893.0 1.0.0 @quiverai/sdk",
64
+ sdkVersion: "0.8.0",
65
+ genVersion: "2.903.5",
66
+ userAgent: "speakeasy-sdk/typescript 0.8.0 2.903.5 1.0.0 @quiverai/sdk",
67
67
  } as const;
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import { bytesToBase64 } from "./base64.js";
6
- import { isPlainObject } from "./is-plain-object.js";
6
+ import { isPlainObject } from "./primitives.js";
7
7
 
8
8
  export class EncodingError extends Error {
9
9
  constructor(message: string) {
@@ -26,22 +26,45 @@ export class EventStream<T extends SseMessage<unknown>>
26
26
  opts?: { dataRequired?: boolean },
27
27
  ) {
28
28
  const upstream = responseBody.getReader();
29
- let buffer: Uint8Array = new Uint8Array();
29
+ let buffer: Uint8Array = new Uint8Array(4096);
30
+ let bufferLen = 0;
31
+ let searchStart = 0;
30
32
  const state = { eventId: undefined as string | undefined };
31
33
  const dataRequired = opts?.dataRequired ?? true;
32
34
  super({
33
35
  async pull(downstream) {
34
36
  try {
35
37
  while (true) {
36
- const match = findBoundary(buffer);
38
+ const match = findBoundary(buffer, bufferLen, searchStart);
37
39
  if (!match) {
40
+ // Bytes before the trailing MAX_BOUNDARY_LEN-1 were already
41
+ // scanned with full lookahead and cannot start a boundary even
42
+ // once more data arrives, so the next scan can skip them.
43
+ searchStart = Math.max(0, bufferLen - MAX_BOUNDARY_LEN + 1);
38
44
  const chunk = await upstream.read();
39
45
  if (chunk.done) return downstream.close();
40
- buffer = concatBuffer(buffer, chunk.value);
46
+ if (bufferLen + chunk.value.length > buffer.length) {
47
+ const grown = new Uint8Array(
48
+ Math.max(buffer.length * 2, bufferLen + chunk.value.length),
49
+ );
50
+ grown.set(buffer.subarray(0, bufferLen));
51
+ buffer = grown;
52
+ }
53
+ buffer.set(chunk.value, bufferLen);
54
+ bufferLen += chunk.value.length;
41
55
  continue;
42
56
  }
43
57
  const message = buffer.slice(0, match.index);
44
- buffer = buffer.slice(match.index + match.length);
58
+ buffer.copyWithin(0, match.index + match.length, bufferLen);
59
+ bufferLen -= match.index + match.length;
60
+ if (buffer.length > 4096 && bufferLen <= buffer.length >> 2) {
61
+ // Release oversized capacity retained after an unusually large
62
+ // event so long-lived streams do not hold peak memory.
63
+ const shrunk = new Uint8Array(Math.max(4096, bufferLen * 2));
64
+ shrunk.set(buffer.subarray(0, bufferLen));
65
+ buffer = shrunk;
66
+ }
67
+ searchStart = 0;
45
68
  const item = parseMessage(message, parse, state, dataRequired);
46
69
  if (item && !item.done) return downstream.enqueue(item.value);
47
70
  if (item?.done) {
@@ -89,13 +112,6 @@ export class EventStream<T extends SseMessage<unknown>>
89
112
  }
90
113
  }
91
114
 
92
- function concatBuffer(a: Uint8Array, b: Uint8Array): Uint8Array {
93
- const c = new Uint8Array(a.length + b.length);
94
- c.set(a, 0);
95
- c.set(b, a.length);
96
- return c;
97
- }
98
-
99
115
  const CR = 13;
100
116
  const LF = 10;
101
117
  const BOUNDARIES = [
@@ -108,12 +124,14 @@ const BOUNDARIES = [
108
124
  [LF, CR], // \n\r
109
125
  [LF, LF], // \n\n
110
126
  ];
127
+ const MAX_BOUNDARY_LEN = BOUNDARIES.reduce((m, b) => Math.max(m, b.length), 0);
111
128
 
112
129
  function findBoundary(
113
130
  buf: Uint8Array,
131
+ len: number,
132
+ from: number,
114
133
  ): { index: number; length: number } | null {
115
- const len = buf.length;
116
- for (let i = 0; i < len; i++) {
134
+ for (let i = from; i < len; i++) {
117
135
  if (buf[i] !== CR && buf[i] !== LF) continue;
118
136
  for (const boundary of BOUNDARIES) {
119
137
  if (i + boundary.length > len) continue;
@@ -6,7 +6,7 @@ import { ResponseValidationError } from "../sdk/models/errors/responsevalidation
6
6
  import { SDKError } from "../sdk/models/errors/sdkerror.js";
7
7
  import { ERR, OK, Result } from "../sdk/types/fp.js";
8
8
  import { matchResponse, matchStatusCode, StatusCodePredicate } from "./http.js";
9
- import { isPlainObject } from "./is-plain-object.js";
9
+ import { isPlainObject } from "./primitives.js";
10
10
 
11
11
  export type Encoding =
12
12
  | "jsonl"
@@ -148,3 +148,19 @@ export function allRequired<V extends Record<string, unknown>>(
148
148
 
149
149
  return v as ReturnType<typeof allRequired<V>>;
150
150
  }
151
+
152
+ export function isPlainObject(
153
+ value: unknown,
154
+ ): value is Record<string, unknown> {
155
+ if (value === null || typeof value !== "object") return false;
156
+ if (Object.prototype.toString.call(value) !== "[object Object]") return false;
157
+ const proto = Object.getPrototypeOf(value);
158
+ if (proto === null || proto === Object.prototype) return true;
159
+ // cross-realm plain objects (vm contexts, iframes) inherit from a
160
+ // different realm's Object.prototype, which itself has a null prototype
161
+ try {
162
+ return Object.getPrototypeOf(proto) === null;
163
+ } catch {
164
+ return false;
165
+ }
166
+ }
package/src/lib/sdks.ts CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  matchContentType,
24
24
  } from "./http.js";
25
25
  import { Logger } from "./logger.js";
26
+ import { combineSignals } from "./primitives.js";
26
27
  import { retry, RetryConfig } from "./retries.js";
27
28
  import { SecurityState } from "./security.js";
28
29
 
@@ -128,27 +129,55 @@ export class ClientSDK {
128
129
  if (path) {
129
130
  baseURL.pathname = baseURL.pathname.replace(/\/+$/, "") + "/";
130
131
  reqURL = new URL(path, baseURL);
132
+ if (!reqURL.search && baseURL.search) {
133
+ reqURL.search = baseURL.search;
134
+ }
131
135
  } else {
132
136
  reqURL = baseURL;
133
137
  }
134
138
  reqURL.hash = "";
135
139
 
136
- let finalQuery = query || "";
137
-
138
- const secQuery: string[] = [];
139
- for (const [k, v] of Object.entries(security?.queryParams || {})) {
140
- const q = encodeForm(k, v, { charEncoding: "percent" });
141
- if (typeof q !== "undefined") {
142
- secQuery.push(q);
140
+ // Appends already-encoded query pairs to a query string, replacing any
141
+ // existing pairs with the same key so later sources take precedence.
142
+ const mergeQuery = (current: string, additions: string): string => {
143
+ if (!additions) {
144
+ return current;
143
145
  }
144
- }
145
- if (secQuery.length) {
146
- finalQuery += `&${secQuery.join("&")}`;
147
- }
146
+ const additionKeys = new Set(
147
+ additions
148
+ .split("&")
149
+ .filter((pair) => pair !== "")
150
+ .map((pair) => pair.split("=")[0] ?? ""),
151
+ );
152
+ const kept = current.split("&").filter((pair) => {
153
+ return pair !== "" && !additionKeys.has(pair.split("=")[0] ?? "");
154
+ });
155
+ return [...kept, additions].join("&");
156
+ };
157
+
158
+ const encodeQueryRecord = (record: Record<string, unknown>): string => {
159
+ return Object.entries(record)
160
+ .map(([k, v]) => {
161
+ if (v == null) {
162
+ return undefined;
163
+ }
164
+ const value = v;
165
+ return encodeForm(k, value, {
166
+ explode: Array.isArray(value),
167
+ charEncoding: "percent",
168
+ });
169
+ })
170
+ .filter((pair): pair is string => typeof pair !== "undefined")
171
+ .join("&");
172
+ };
173
+
174
+ const finalQuery = [
175
+ query || "",
176
+ encodeQueryRecord(security?.queryParams || {}),
177
+ ].reduce(mergeQuery, reqURL.search.slice(1));
148
178
 
149
179
  if (finalQuery) {
150
- const q = finalQuery.startsWith("&") ? finalQuery.slice(1) : finalQuery;
151
- reqURL.search = `?${q}`;
180
+ reqURL.search = `?${finalQuery}`;
152
181
  }
153
182
 
154
183
  const headers = new Headers(opHeaders);
@@ -194,9 +223,8 @@ export class ClientSDK {
194
223
  ...options?.fetchOptions,
195
224
  ...options,
196
225
  };
197
- if (!fetchOptions?.signal && conf.timeoutMs && conf.timeoutMs > 0) {
198
- const timeoutSignal = AbortSignal.timeout(conf.timeoutMs);
199
- fetchOptions.signal = timeoutSignal;
226
+ if (!fetchOptions?.signal && conf.timeoutMs != null && conf.timeoutMs > 0) {
227
+ context.timeoutMs = conf.timeoutMs;
200
228
  }
201
229
 
202
230
  if (conf.body instanceof ReadableStream) {
@@ -243,10 +271,19 @@ export class ClientSDK {
243
271
  >
244
272
  > {
245
273
  const { context, isErrorStatusCode } = options;
274
+ const timeoutMs = context.timeoutMs;
246
275
 
247
276
  return retry(
248
277
  async () => {
249
- const req = await this.#hooks.beforeRequest(context, request.clone());
278
+ const cloned = request.clone();
279
+ let attempt = cloned;
280
+ if (timeoutMs != null && timeoutMs > 0) {
281
+ const timeoutSignal = AbortSignal.timeout(timeoutMs);
282
+ const combined = combineSignals(cloned.signal, timeoutSignal)
283
+ ?? timeoutSignal;
284
+ attempt = new Request(cloned, { signal: combined });
285
+ }
286
+ const req = await this.#hooks.beforeRequest(context, attempt);
250
287
  await logRequest(this.#logger, req).catch((e) =>
251
288
  this.#logger?.log("Failed to log request:", e)
252
289
  );
@@ -18,7 +18,6 @@ export const Code = {
18
18
  InsufficientCredits: "insufficient_credits",
19
19
  AccountFrozen: "account_frozen",
20
20
  ModelNotFound: "model_not_found",
21
- UpstreamError: "upstream_error",
22
21
  InternalError: "internal_error",
23
22
  } as const;
24
23
  export type Code = ClosedEnum<typeof Code>;
@@ -1,14 +0,0 @@
1
- /**
2
- * @param obj The object to walk
3
- * @param key The key path to walk the object with
4
- * @param def A default value to return if the result is undefined
5
- *
6
- * @example
7
- * dlv(obj, "a.b.c.d")
8
- * @example
9
- * dlv(object, ["a", "b", "c", "d"])
10
- * @example
11
- * dlv(object, "foo.bar.baz", "Hello, default value!")
12
- */
13
- export declare function dlv<T = any>(obj: any, key: string | string[], def?: T, p?: number, undef?: never): T | undefined;
14
- //# sourceMappingURL=dlv.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dlv.d.ts","sourceRoot":"","sources":["../../../src/lib/dlv.ts"],"names":[],"mappings":"AA2BA;;;;;;;;;;;GAWG;AACH,wBAAgB,GAAG,CAAC,CAAC,GAAG,GAAG,EACzB,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EACtB,GAAG,CAAC,EAAE,CAAC,EACP,CAAC,CAAC,EAAE,MAAM,EACV,KAAK,CAAC,EAAE,KAAK,GACZ,CAAC,GAAG,SAAS,CAOf"}
@@ -1,49 +0,0 @@
1
- "use strict";
2
- /*
3
- * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.dlv = dlv;
7
- /*
8
- MIT License
9
-
10
- Copyright (c) 2024 Jason Miller <jason@developit.ca> (http://jasonformat.com)
11
-
12
- Permission is hereby granted, free of charge, to any person obtaining a copy of
13
- this software and associated documentation files (the "Software"), to deal in
14
- the Software without restriction, including without limitation the rights to
15
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
16
- the Software, and to permit persons to whom the Software is furnished to do so,
17
- subject to the following conditions:
18
-
19
- The above copyright notice and this permission notice shall be included in all
20
- copies or substantial portions of the Software.
21
-
22
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
24
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
25
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
26
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
- */
29
- /**
30
- * @param obj The object to walk
31
- * @param key The key path to walk the object with
32
- * @param def A default value to return if the result is undefined
33
- *
34
- * @example
35
- * dlv(obj, "a.b.c.d")
36
- * @example
37
- * dlv(object, ["a", "b", "c", "d"])
38
- * @example
39
- * dlv(object, "foo.bar.baz", "Hello, default value!")
40
- */
41
- function dlv(obj, key, def, p, undef) {
42
- key = Array.isArray(key) ? key : key.split(".");
43
- for (p = 0; p < key.length; p++) {
44
- const k = key[p];
45
- obj = k != null && obj ? obj[k] : undef;
46
- }
47
- return obj === undef ? def : obj;
48
- }
49
- //# sourceMappingURL=dlv.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dlv.js","sourceRoot":"","sources":["../../../src/lib/dlv.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAqCH,kBAaC;AAhDD;;;;;;;;;;;;;;;;;;;;;EAqBE;AAEF;;;;;;;;;;;GAWG;AACH,SAAgB,GAAG,CACjB,GAAQ,EACR,GAAsB,EACtB,GAAO,EACP,CAAU,EACV,KAAa;IAEb,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChD,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACjB,GAAG,GAAG,CAAC,IAAI,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1C,CAAC;IACD,OAAO,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AACnC,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function isPlainObject(value: unknown): value is object;
2
- //# sourceMappingURL=is-plain-object.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-plain-object.d.ts","sourceRoot":"","sources":["../../../src/lib/is-plain-object.ts"],"names":[],"mappings":"AA6BA,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAa7D"}
@@ -1,41 +0,0 @@
1
- "use strict";
2
- /*
3
- * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isPlainObject = isPlainObject;
7
- /*
8
- MIT License
9
-
10
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
11
-
12
- Permission is hereby granted, free of charge, to any person obtaining a copy of
13
- this software and associated documentation files (the "Software"), to deal in
14
- the Software without restriction, including without limitation the rights to
15
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
16
- the Software, and to permit persons to whom the Software is furnished to do so,
17
- subject to the following conditions:
18
-
19
- The above copyright notice and this permission notice shall be included in all
20
- copies or substantial portions of the Software.
21
-
22
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
24
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
25
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
26
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
- */
29
- // Taken from https://github.com/sindresorhus/is-plain-obj/blob/97f38e8836f86a642cce98fc6ab3058bc36df181/index.js
30
- function isPlainObject(value) {
31
- if (typeof value !== "object" || value === null) {
32
- return false;
33
- }
34
- const prototype = Object.getPrototypeOf(value);
35
- return ((prototype === null ||
36
- prototype === Object.prototype ||
37
- Object.getPrototypeOf(prototype) === null) &&
38
- !(Symbol.toStringTag in value) &&
39
- !(Symbol.iterator in value));
40
- }
41
- //# sourceMappingURL=is-plain-object.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-plain-object.js","sourceRoot":"","sources":["../../../src/lib/is-plain-object.ts"],"names":[],"mappings":";AAAA;;GAEG;;AA2BH,sCAaC;AAtCD;;;;;;;;;;;;;;;;;;;;;EAqBE;AAEF,iHAAiH;AAEjH,SAAgB,aAAa,CAAC,KAAc;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,OAAO,CACL,CAAC,SAAS,KAAK,IAAI;QACjB,SAAS,KAAK,MAAM,CAAC,SAAS;QAC9B,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;QAC5C,CAAC,CAAC,MAAM,CAAC,WAAW,IAAI,KAAK,CAAC;QAC9B,CAAC,CAAC,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC,CAC5B,CAAC;AACJ,CAAC"}
@@ -1,14 +0,0 @@
1
- /**
2
- * @param obj The object to walk
3
- * @param key The key path to walk the object with
4
- * @param def A default value to return if the result is undefined
5
- *
6
- * @example
7
- * dlv(obj, "a.b.c.d")
8
- * @example
9
- * dlv(object, ["a", "b", "c", "d"])
10
- * @example
11
- * dlv(object, "foo.bar.baz", "Hello, default value!")
12
- */
13
- export declare function dlv<T = any>(obj: any, key: string | string[], def?: T, p?: number, undef?: never): T | undefined;
14
- //# sourceMappingURL=dlv.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dlv.d.ts","sourceRoot":"","sources":["../../../src/lib/dlv.ts"],"names":[],"mappings":"AA2BA;;;;;;;;;;;GAWG;AACH,wBAAgB,GAAG,CAAC,CAAC,GAAG,GAAG,EACzB,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EACtB,GAAG,CAAC,EAAE,CAAC,EACP,CAAC,CAAC,EAAE,MAAM,EACV,KAAK,CAAC,EAAE,KAAK,GACZ,CAAC,GAAG,SAAS,CAOf"}
@@ -1,46 +0,0 @@
1
- /*
2
- * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
- */
4
- /*
5
- MIT License
6
-
7
- Copyright (c) 2024 Jason Miller <jason@developit.ca> (http://jasonformat.com)
8
-
9
- Permission is hereby granted, free of charge, to any person obtaining a copy of
10
- this software and associated documentation files (the "Software"), to deal in
11
- the Software without restriction, including without limitation the rights to
12
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
13
- the Software, and to permit persons to whom the Software is furnished to do so,
14
- subject to the following conditions:
15
-
16
- The above copyright notice and this permission notice shall be included in all
17
- copies or substantial portions of the Software.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
21
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
- */
26
- /**
27
- * @param obj The object to walk
28
- * @param key The key path to walk the object with
29
- * @param def A default value to return if the result is undefined
30
- *
31
- * @example
32
- * dlv(obj, "a.b.c.d")
33
- * @example
34
- * dlv(object, ["a", "b", "c", "d"])
35
- * @example
36
- * dlv(object, "foo.bar.baz", "Hello, default value!")
37
- */
38
- export function dlv(obj, key, def, p, undef) {
39
- key = Array.isArray(key) ? key : key.split(".");
40
- for (p = 0; p < key.length; p++) {
41
- const k = key[p];
42
- obj = k != null && obj ? obj[k] : undef;
43
- }
44
- return obj === undef ? def : obj;
45
- }
46
- //# sourceMappingURL=dlv.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dlv.js","sourceRoot":"","sources":["../../../src/lib/dlv.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;;;;;;;;;;EAqBE;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,GAAG,CACjB,GAAQ,EACR,GAAsB,EACtB,GAAO,EACP,CAAU,EACV,KAAa;IAEb,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChD,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACjB,GAAG,GAAG,CAAC,IAAI,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1C,CAAC;IACD,OAAO,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AACnC,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function isPlainObject(value: unknown): value is object;
2
- //# sourceMappingURL=is-plain-object.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-plain-object.d.ts","sourceRoot":"","sources":["../../../src/lib/is-plain-object.ts"],"names":[],"mappings":"AA6BA,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAa7D"}
@@ -1,38 +0,0 @@
1
- /*
2
- * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
- */
4
- /*
5
- MIT License
6
-
7
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
8
-
9
- Permission is hereby granted, free of charge, to any person obtaining a copy of
10
- this software and associated documentation files (the "Software"), to deal in
11
- the Software without restriction, including without limitation the rights to
12
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
13
- the Software, and to permit persons to whom the Software is furnished to do so,
14
- subject to the following conditions:
15
-
16
- The above copyright notice and this permission notice shall be included in all
17
- copies or substantial portions of the Software.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
21
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
- */
26
- // Taken from https://github.com/sindresorhus/is-plain-obj/blob/97f38e8836f86a642cce98fc6ab3058bc36df181/index.js
27
- export function isPlainObject(value) {
28
- if (typeof value !== "object" || value === null) {
29
- return false;
30
- }
31
- const prototype = Object.getPrototypeOf(value);
32
- return ((prototype === null ||
33
- prototype === Object.prototype ||
34
- Object.getPrototypeOf(prototype) === null) &&
35
- !(Symbol.toStringTag in value) &&
36
- !(Symbol.iterator in value));
37
- }
38
- //# sourceMappingURL=is-plain-object.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-plain-object.js","sourceRoot":"","sources":["../../../src/lib/is-plain-object.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;;;;;;;;;;EAqBE;AAEF,iHAAiH;AAEjH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,OAAO,CACL,CAAC,SAAS,KAAK,IAAI;QACjB,SAAS,KAAK,MAAM,CAAC,SAAS;QAC9B,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;QAC5C,CAAC,CAAC,MAAM,CAAC,WAAW,IAAI,KAAK,CAAC;QAC9B,CAAC,CAAC,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC,CAC5B,CAAC;AACJ,CAAC"}
package/src/lib/dlv.ts DELETED
@@ -1,53 +0,0 @@
1
- /*
2
- * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
- */
4
-
5
- /*
6
- MIT License
7
-
8
- Copyright (c) 2024 Jason Miller <jason@developit.ca> (http://jasonformat.com)
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy of
11
- this software and associated documentation files (the "Software"), to deal in
12
- the Software without restriction, including without limitation the rights to
13
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
14
- the Software, and to permit persons to whom the Software is furnished to do so,
15
- subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in all
18
- copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
22
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
23
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
- */
27
-
28
- /**
29
- * @param obj The object to walk
30
- * @param key The key path to walk the object with
31
- * @param def A default value to return if the result is undefined
32
- *
33
- * @example
34
- * dlv(obj, "a.b.c.d")
35
- * @example
36
- * dlv(object, ["a", "b", "c", "d"])
37
- * @example
38
- * dlv(object, "foo.bar.baz", "Hello, default value!")
39
- */
40
- export function dlv<T = any>(
41
- obj: any,
42
- key: string | string[],
43
- def?: T,
44
- p?: number,
45
- undef?: never,
46
- ): T | undefined {
47
- key = Array.isArray(key) ? key : key.split(".");
48
- for (p = 0; p < key.length; p++) {
49
- const k = key[p];
50
- obj = k != null && obj ? obj[k] : undef;
51
- }
52
- return obj === undef ? def : obj;
53
- }