@sanity/client 6.4.10-canary.3 → 6.4.10-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -8,7 +8,7 @@ var getIt = require('get-it');
8
8
  var rxjs = require('rxjs');
9
9
  var operators = require('rxjs/operators');
10
10
  var name = "@sanity/client";
11
- var version = "6.4.10-canary.3";
11
+ var version = "6.4.10-dev.0";
12
12
  const middleware = [middleware$1.debug({
13
13
  verbose: true,
14
14
  namespace: "sanity:client"
package/dist/index.d.ts CHANGED
@@ -2215,6 +2215,81 @@ export declare interface SingleMutationResult {
2215
2215
  }[]
2216
2216
  }
2217
2217
 
2218
+ /**
2219
+ * Stricter typing of the response from `client.fetch`, intended to be used by type inference libraries and tooling that
2220
+ * delivers runtime safety in production.
2221
+ *
2222
+ * @example
2223
+ * It's not designed to be used directly in application code, in fact that would be the most annoying way to query Content Lake in a runtime safe way:
2224
+ * ```ts
2225
+ * import type {StrictUnknownQueryResponseResult} from '@sanity/client'
2226
+ * const query = '*[_type == "product"]'
2227
+ * const response = client.fetch<StrictUnknownQueryResponseResult>(query)
2228
+ * // Response is now strictly typed, without any knowledge of the dataset or what the GROQ query might return.
2229
+ * // The GROQ query is asking for an array of documents that have `_type` = "product", but TypeScript doesn't know that,
2230
+ * // `query` is `string` and so the type accounts for anything that GROQ supports, which means you might have any JSON valid data in the response.
2231
+ * // \@ts-expect-error -- TS doesn't know the api will always return an array, so it errors
2232
+ * console.log(response.length)
2233
+ * // It needs a runtime check to ensure it's an array
2234
+ * if (Array.isArray(response)) console.log(response.length)
2235
+ * ```
2236
+ *
2237
+ * @example
2238
+ * How's it intended to be used? By libraries that delivers end-to-end GROQ runtime type safety.
2239
+ * For example in an imaginary TypeScript language service plugin that can look at your `sanity.config.ts`:
2240
+ * ```ts
2241
+ * import { defineConfig } from 'sanity'
2242
+
2243
+ * export default defineConfig({
2244
+ * projectId: '...',
2245
+ * dataset: '...',
2246
+ * schema: {
2247
+ * types: [
2248
+ * {
2249
+ * name: 'page',
2250
+ * title: 'Page',
2251
+ * type: 'document',
2252
+ * fields: [
2253
+ * {
2254
+ * name: 'title',
2255
+ * title: 'Title',
2256
+ * type: 'string',
2257
+ * },
2258
+ * ],
2259
+ * },
2260
+ * ],
2261
+ * },
2262
+ * })
2263
+ * ```
2264
+ * And use that to infer typings:
2265
+ * ```ts
2266
+ * import {createClient} from '@sanity/client'
2267
+ *
2268
+ * const client = createClient()
2269
+ * const response = client.fetch('*[_type == "page"]')
2270
+ * // all is well, if title exists the schema says it's a string
2271
+ * response.map(page => page.title?.toUpperCase())
2272
+ * // IDE flags an error, the `author` property isn't defined in the schema so it could be any JSON valid value.
2273
+ * response.map(page => page.author?.toUpperCase())
2274
+ * // Maybe this is by design because `author` is coming from an external source, and not from entering it in the Studio interface,
2275
+ * // the IDE plugin returns `StrictUnknownQueryResponseResult` and you have to handle it manually:
2276
+ * response.map(page => typeof page.author === 'string' ? page.author.toUpperCase() : 'UNKNOWN')
2277
+ * ```
2278
+ * If the imaginary IDE extension returned `any` or `unknown` instead of `StrictUnknownQueryResponseResult` it opens up a lot of
2279
+ * possibilities where it would fail silently and instead error at runtime.
2280
+ *
2281
+ * @public
2282
+ */
2283
+ export declare type StrictUnknownQueryResponseResult =
2284
+ | string
2285
+ | number
2286
+ | boolean
2287
+ | null
2288
+ | {
2289
+ [key: string]: StrictUnknownQueryResponseResult | undefined
2290
+ }
2291
+ | StrictUnknownQueryResponseResult[]
2292
+
2218
2293
  /** @public */
2219
2294
  export declare class Transaction extends BaseTransaction {
2220
2295
  #private
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ export { adapter as unstable__adapter, environment as unstable__environment } fr
4
4
  import { Observable, lastValueFrom } from 'rxjs';
5
5
  import { map, filter } from 'rxjs/operators';
6
6
  var name = "@sanity/client";
7
- var version = "6.4.10-canary.3";
7
+ var version = "6.4.10-dev.0";
8
8
  const middleware = [debug({
9
9
  verbose: true,
10
10
  namespace: "sanity:client"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "6.4.10-canary.3",
3
+ "version": "6.4.10-dev.0",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -40,9 +40,10 @@
40
40
  "source": "./src/index.ts",
41
41
  "require": "./dist/index.cjs",
42
42
  "node": {
43
+ "module": "./dist/index.js",
43
44
  "import": "./dist/index.cjs.js"
44
45
  },
45
- "module": "./dist/index.js",
46
+ "import": "./dist/index.js",
46
47
  "default": "./dist/index.js"
47
48
  },
48
49
  "./package.json": "./package.json"
@@ -71,7 +72,7 @@
71
72
  "prepublishOnly": "npm run build",
72
73
  "rollup": "NODE_ENV=production rollup -c rollup.config.cjs",
73
74
  "test": "vitest",
74
- "type-check": "tsc --noEmit",
75
+ "type-check": "tsc --noEmit && vitest typecheck",
75
76
  "test:browser": "npm test -- --config ./vitest.browser.config.ts",
76
77
  "test:bun": "(cd runtimes/bun && bun wiptest)",
77
78
  "test:deno": "deno test --allow-read --allow-net --allow-env --fail-fast --import-map=runtimes/deno/import_map.json runtimes/deno",
@@ -105,7 +106,7 @@
105
106
  "@types/node": "^20.5.9",
106
107
  "@typescript-eslint/eslint-plugin": "^6.5.0",
107
108
  "@typescript-eslint/parser": "^6.5.0",
108
- "@vitest/coverage-v8": "^0.34.3",
109
+ "@vitest/coverage-v8": "0.34.3",
109
110
  "eslint": "^8.48.0",
110
111
  "eslint-config-prettier": "^9.0.0",
111
112
  "eslint-plugin-prettier": "^5.0.0",
@@ -121,13 +122,14 @@
121
122
  "sse-channel": "^4.0.0",
122
123
  "terser": "^5.19.3",
123
124
  "typescript": "^5.2.2",
124
- "vitest": "^0.34.3",
125
- "vitest-github-actions-reporter": "^0.10.0"
125
+ "vitest": "0.34.3",
126
+ "vitest-github-actions-reporter": "0.10.0"
126
127
  },
127
128
  "engines": {
128
129
  "node": ">=14.18"
129
130
  },
130
131
  "publishConfig": {
131
- "access": "public"
132
+ "access": "public",
133
+ "provenance": false
132
134
  }
133
135
  }
package/src/types.ts CHANGED
@@ -518,6 +518,79 @@ export type UnfilteredResponseQueryOptions = ResponseQueryOptions & {
518
518
  filterResponse: false
519
519
  }
520
520
 
521
+ /**
522
+ * Stricter typing of the response from `client.fetch`, intended to be used by type inference libraries and tooling that
523
+ * delivers runtime safety in production.
524
+ *
525
+ * @example
526
+ * It's not designed to be used directly in application code, in fact that would be the most annoying way to query Content Lake in a runtime safe way:
527
+ * ```ts
528
+ * import type {StrictUnknownQueryResponseResult} from '@sanity/client'
529
+ * const query = '*[_type == "product"]'
530
+ * const response = client.fetch<StrictUnknownQueryResponseResult>(query)
531
+ * // Response is now strictly typed, without any knowledge of the dataset or what the GROQ query might return.
532
+ * // The GROQ query is asking for an array of documents that have `_type` = "product", but TypeScript doesn't know that,
533
+ * // `query` is `string` and so the type accounts for anything that GROQ supports, which means you might have any JSON valid data in the response.
534
+ * // \@ts-expect-error -- TS doesn't know the api will always return an array, so it errors
535
+ * console.log(response.length)
536
+ * // It needs a runtime check to ensure it's an array
537
+ * if (Array.isArray(response)) console.log(response.length)
538
+ * ```
539
+ *
540
+ * @example
541
+ * How's it intended to be used? By libraries that delivers end-to-end GROQ runtime type safety.
542
+ * For example in an imaginary TypeScript language service plugin that can look at your `sanity.config.ts`:
543
+ * ```ts
544
+ * import { defineConfig } from 'sanity'
545
+
546
+ * export default defineConfig({
547
+ * projectId: '...',
548
+ * dataset: '...',
549
+ * schema: {
550
+ * types: [
551
+ * {
552
+ * name: 'page',
553
+ * title: 'Page',
554
+ * type: 'document',
555
+ * fields: [
556
+ * {
557
+ * name: 'title',
558
+ * title: 'Title',
559
+ * type: 'string',
560
+ * },
561
+ * ],
562
+ * },
563
+ * ],
564
+ * },
565
+ * })
566
+ * ```
567
+ * And use that to infer typings:
568
+ * ```ts
569
+ * import {createClient} from '@sanity/client'
570
+ *
571
+ * const client = createClient()
572
+ * const response = client.fetch('*[_type == "page"]')
573
+ * // all is well, if title exists the schema says it's a string
574
+ * response.map(page => page.title?.toUpperCase())
575
+ * // IDE flags an error, the `author` property isn't defined in the schema so it could be any JSON valid value.
576
+ * response.map(page => page.author?.toUpperCase())
577
+ * // Maybe this is by design because `author` is coming from an external source, and not from entering it in the Studio interface,
578
+ * // the IDE plugin returns `StrictUnknownQueryResponseResult` and you have to handle it manually:
579
+ * response.map(page => typeof page.author === 'string' ? page.author.toUpperCase() : 'UNKNOWN')
580
+ * ```
581
+ * If the imaginary IDE extension returned `any` or `unknown` instead of `StrictUnknownQueryResponseResult` it opens up a lot of
582
+ * possibilities where it would fail silently and instead error at runtime.
583
+ *
584
+ * @public
585
+ */
586
+ export type StrictUnknownQueryResponseResult =
587
+ | string
588
+ | number
589
+ | boolean
590
+ | null
591
+ | {[key: string]: StrictUnknownQueryResponseResult | undefined}
592
+ | StrictUnknownQueryResponseResult[]
593
+
521
594
  /** @public */
522
595
  export interface RawQueryResponse<R> {
523
596
  query: string