@sanity/client 6.28.3-instruct.4 → 6.28.3-instruct.6

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/stega.d.cts CHANGED
@@ -695,6 +695,7 @@ declare interface CreateDocumentRequest<T extends Record<string, Any> = Record<s
695
695
  _id?: string
696
696
  _type: string
697
697
  } & SanityDocumentStub<T>
698
+ documentId?: never
698
699
  }
699
700
 
700
701
  /** @public */
@@ -921,6 +922,7 @@ export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSo
921
922
  */
922
923
  declare interface ExistingDocumentRequest {
923
924
  documentId: string
925
+ createDocument?: never
924
926
  }
925
927
 
926
928
  /** @public */
@@ -1161,6 +1163,16 @@ export declare type InstructInstructionParam =
1161
1163
  /** @beta */
1162
1164
  export declare type InstructInstructionParams = Record<string, InstructInstructionParam>
1163
1165
 
1166
+ declare type InstructOperation = 'set' | 'append' | 'mixed'
1167
+
1168
+ declare type InstructPath = InstructPathSegment[]
1169
+
1170
+ declare type InstructPathSegment =
1171
+ | string
1172
+ | {
1173
+ _key: string
1174
+ }
1175
+
1164
1176
  declare interface InstructRequestBase {
1165
1177
  /** schemaId as reported by sanity deploy / sanity schema store */
1166
1178
  schemaId: string
@@ -1169,45 +1181,17 @@ declare interface InstructRequestBase {
1169
1181
  /** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
1170
1182
  instructionParams?: InstructInstructionParams
1171
1183
  /**
1172
- * Optional document path output target for the instruction.
1173
- * When provided, the instruction will apply to this path in the document and its children.
1184
+ * Target defines which parts of the document will be affected by the instruction.
1185
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
1174
1186
  *
1175
- * ## Examples
1176
- * - `path: 'title'` will output to the title field in the document
1177
- * - `path: 'array[_key="xx"]'` will output to the item with `_key: 'xx'` in the array field
1178
- */
1179
- path?: string
1180
- /**
1181
- * Controls sub-paths in the document that can be output to.
1182
- *
1183
- * The string-paths are relative to the `path` param
1187
+ * Omitting target implies that the document itself is the root.
1184
1188
  *
1185
- * Note: these path strings are less strictly validated than the `path` param itself:
1186
- * if an relative-path does not exist or is invalid, it will be silently ignored.
1187
- *
1188
- * @see InstructRequestBase#conditionalPaths
1189
- * @see InstructRequestBase#outputTypes
1189
+ * Notes:
1190
+ * - instruction can only affect fields up to `maxPathDepth`
1191
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
1192
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
1190
1193
  */
1191
- relativeOutputPaths?:
1192
- | {
1193
- include: string[]
1194
- }
1195
- | {
1196
- exclude: string[]
1197
- }
1198
- /**
1199
- * Controls which types the instruction is allowed to output to.
1200
- *
1201
- * @see InstructRequestBase#relativeOutputPaths
1202
- * @see InstructRequestBase#conditionalPaths
1203
- */
1204
- outputTypes?:
1205
- | {
1206
- include: string[]
1207
- }
1208
- | {
1209
- exclude: string[]
1210
- }
1194
+ target?: InstructTarget | InstructTarget[]
1211
1195
  /**
1212
1196
  * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
1213
1197
  *
@@ -1231,8 +1215,8 @@ declare interface InstructRequestBase {
1231
1215
  defaultReadOnly?: boolean
1232
1216
  defaultHidden?: boolean
1233
1217
  paths?: {
1234
- /** path here is not a relative path: it must be the full document path, regardless of `path` param on the request itself */
1235
- path: string
1218
+ /** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
1219
+ path: InstructPath
1236
1220
  readOnly: boolean
1237
1221
  hidden: boolean
1238
1222
  }[]
@@ -1264,6 +1248,14 @@ declare interface InstructRequestBase {
1264
1248
  */
1265
1249
  timeZone: string
1266
1250
  }
1251
+ /**
1252
+ * Controls how much variance the instructions will run with.
1253
+ *
1254
+ * Value must be in the range [0, 1] (inclusive).
1255
+ *
1256
+ * Default: 0.3
1257
+ */
1258
+ temperature?: number
1267
1259
  }
1268
1260
 
1269
1261
  /** @beta */
@@ -1274,6 +1266,139 @@ export declare type InstructSyncInstruction<T extends Record<string, Any> = Reco
1274
1266
  InstructRequestBase &
1275
1267
  Sync
1276
1268
 
1269
+ /**
1270
+ * @beta
1271
+ */
1272
+ declare interface InstructTarget {
1273
+ /**
1274
+ * Root target path.
1275
+ *
1276
+ * Use this to have the instruction only affect a part of the document.
1277
+ *
1278
+ * To further control the behavior of individual paths under the root, use `include`, `exclude`, `types.include`
1279
+ * and `types.exclude`.
1280
+ *
1281
+ * Example:
1282
+ *
1283
+ * `target: ['body', {_key: 'someKey'}, 'nestedObject']`
1284
+ *
1285
+ * Here, the instruction will only write to fields under the nestedObject.
1286
+ *
1287
+ * Default: [] = the document itself
1288
+ *
1289
+ * @see #InstructPathSegment
1290
+ * @see #InstructPath
1291
+ * */
1292
+ path?: InstructPathSegment | InstructPath
1293
+ /**
1294
+ * Sets the default operation for all paths in the target.
1295
+ * Instruct runs in `'mixed'` operation mode by default:
1296
+ * Changes are set in all non-array fields, and append to all array fields.
1297
+ *
1298
+ * ### Operation types
1299
+ * - `'set'` – an *overwriting* operation, and replaces the full field value.
1300
+ * - `'append'`:
1301
+ * – array fields: appends new items to the end of the array,
1302
+ * - string fields: '<existing content> <new content>'
1303
+ * - text fields: '<existing content>\n<new content>'
1304
+ * - number fields: existing + new
1305
+ * - other field types not mentioned will set instead (dates, url)
1306
+ * - `'mixed'` – (default) sets non-array fields, and appends to array fields
1307
+ *
1308
+ * The default operation can be overridden on a per-path basis using `include`.
1309
+ *
1310
+ * Nested fields inherit the operation specified by their parent and falls back to the
1311
+ * top level target operation if not otherwise specified.
1312
+ *
1313
+ * Use `include` to change the `operation` of individual fields or items.
1314
+ *
1315
+ * #### Appending in the middle of arrays
1316
+ * `target: {path: ['array'], operation: 'append'}` will append the output of the instruction to the end of the array.
1317
+ *
1318
+ * To insert in the middle of the array, use `target: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append'}`.
1319
+ * Here, the output of the instruction will be appended after the array item with key `'appendAfterKey'`.
1320
+ *
1321
+ * @see #InstructTargetInclude.operation
1322
+ * @see #include
1323
+ * @see #InstructTargetInclude.include
1324
+ */
1325
+ operation?: InstructOperation
1326
+ /**
1327
+ * maxPathDepth controls how deep into the schema from the target root the instruction will affect.
1328
+ *
1329
+ * Depth is based on path segments:
1330
+ * - `title` has depth 1
1331
+ * - `array[_key="no"].title` has depth 3
1332
+ *
1333
+ * Be careful not to set this too high in studios with recursive document schemas, as it could have
1334
+ * negative impact on performance; both for runtime and quality of responses.
1335
+ *
1336
+ * Default: 4
1337
+ */
1338
+ maxPathDepth?: number
1339
+ /**
1340
+ * By default, all children up to `target.maxPathDepth` are included.
1341
+ *
1342
+ * When `include` is specified, only segments explicitly listed will be included.
1343
+ *
1344
+ * Fields or array items not on the include list, are implicitly excluded.
1345
+ */
1346
+ include?: (InstructPathSegment | InstructTargetInclude)[]
1347
+ /**
1348
+ * By default, all children up to `target.maxPathDepth` are included.
1349
+ * Fields or array items not on the exclude list, are implicitly included.
1350
+ */
1351
+ exclude?: InstructPathSegment[]
1352
+ /**
1353
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
1354
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
1355
+ *
1356
+ * `types.include` and `types.exclude` are mutually exclusive.
1357
+ */
1358
+ types?: InstructTypeConfig
1359
+ }
1360
+
1361
+ declare interface InstructTargetInclude {
1362
+ path: InstructPathSegment | InstructPath
1363
+ /**
1364
+ * Sets the operation for this path, and all its children.
1365
+ * This overrides any operation set parents or the root target.
1366
+ * @see #InstructTarget.operation
1367
+ * @see #include
1368
+ */
1369
+ operation?: InstructOperation
1370
+ /**
1371
+ * By default, all children up to `target.maxPathDepth` are included.
1372
+ *
1373
+ * When `include` is specified, only segments explicitly listed will be included.
1374
+ *
1375
+ * Fields or array items not on the include list, are implicitly excluded.
1376
+ */
1377
+ include?: (InstructPathSegment | InstructTargetInclude)[]
1378
+ /**
1379
+ * By default, all children up to `target.maxPathDepth` are included.
1380
+ * Fields or array items not on the exclude list, are implicitly included.
1381
+ */
1382
+ exclude?: InstructPathSegment[]
1383
+ /**
1384
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
1385
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
1386
+ *
1387
+ * `types.include` and `types.exclude` are mutually exclusive.
1388
+ */
1389
+ types?: InstructTypeConfig
1390
+ }
1391
+
1392
+ declare type InstructTypeConfig =
1393
+ | {
1394
+ include: string[]
1395
+ exclude?: never
1396
+ }
1397
+ | {
1398
+ exclude: string[]
1399
+ include?: never
1400
+ }
1401
+
1277
1402
  /**
1278
1403
  * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
1279
1404
  *
package/dist/stega.d.ts CHANGED
@@ -695,6 +695,7 @@ declare interface CreateDocumentRequest<T extends Record<string, Any> = Record<s
695
695
  _id?: string
696
696
  _type: string
697
697
  } & SanityDocumentStub<T>
698
+ documentId?: never
698
699
  }
699
700
 
700
701
  /** @public */
@@ -921,6 +922,7 @@ export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSo
921
922
  */
922
923
  declare interface ExistingDocumentRequest {
923
924
  documentId: string
925
+ createDocument?: never
924
926
  }
925
927
 
926
928
  /** @public */
@@ -1161,6 +1163,16 @@ export declare type InstructInstructionParam =
1161
1163
  /** @beta */
1162
1164
  export declare type InstructInstructionParams = Record<string, InstructInstructionParam>
1163
1165
 
1166
+ declare type InstructOperation = 'set' | 'append' | 'mixed'
1167
+
1168
+ declare type InstructPath = InstructPathSegment[]
1169
+
1170
+ declare type InstructPathSegment =
1171
+ | string
1172
+ | {
1173
+ _key: string
1174
+ }
1175
+
1164
1176
  declare interface InstructRequestBase {
1165
1177
  /** schemaId as reported by sanity deploy / sanity schema store */
1166
1178
  schemaId: string
@@ -1169,45 +1181,17 @@ declare interface InstructRequestBase {
1169
1181
  /** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
1170
1182
  instructionParams?: InstructInstructionParams
1171
1183
  /**
1172
- * Optional document path output target for the instruction.
1173
- * When provided, the instruction will apply to this path in the document and its children.
1184
+ * Target defines which parts of the document will be affected by the instruction.
1185
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
1174
1186
  *
1175
- * ## Examples
1176
- * - `path: 'title'` will output to the title field in the document
1177
- * - `path: 'array[_key="xx"]'` will output to the item with `_key: 'xx'` in the array field
1178
- */
1179
- path?: string
1180
- /**
1181
- * Controls sub-paths in the document that can be output to.
1182
- *
1183
- * The string-paths are relative to the `path` param
1187
+ * Omitting target implies that the document itself is the root.
1184
1188
  *
1185
- * Note: these path strings are less strictly validated than the `path` param itself:
1186
- * if an relative-path does not exist or is invalid, it will be silently ignored.
1187
- *
1188
- * @see InstructRequestBase#conditionalPaths
1189
- * @see InstructRequestBase#outputTypes
1189
+ * Notes:
1190
+ * - instruction can only affect fields up to `maxPathDepth`
1191
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
1192
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
1190
1193
  */
1191
- relativeOutputPaths?:
1192
- | {
1193
- include: string[]
1194
- }
1195
- | {
1196
- exclude: string[]
1197
- }
1198
- /**
1199
- * Controls which types the instruction is allowed to output to.
1200
- *
1201
- * @see InstructRequestBase#relativeOutputPaths
1202
- * @see InstructRequestBase#conditionalPaths
1203
- */
1204
- outputTypes?:
1205
- | {
1206
- include: string[]
1207
- }
1208
- | {
1209
- exclude: string[]
1210
- }
1194
+ target?: InstructTarget | InstructTarget[]
1211
1195
  /**
1212
1196
  * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
1213
1197
  *
@@ -1231,8 +1215,8 @@ declare interface InstructRequestBase {
1231
1215
  defaultReadOnly?: boolean
1232
1216
  defaultHidden?: boolean
1233
1217
  paths?: {
1234
- /** path here is not a relative path: it must be the full document path, regardless of `path` param on the request itself */
1235
- path: string
1218
+ /** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
1219
+ path: InstructPath
1236
1220
  readOnly: boolean
1237
1221
  hidden: boolean
1238
1222
  }[]
@@ -1264,6 +1248,14 @@ declare interface InstructRequestBase {
1264
1248
  */
1265
1249
  timeZone: string
1266
1250
  }
1251
+ /**
1252
+ * Controls how much variance the instructions will run with.
1253
+ *
1254
+ * Value must be in the range [0, 1] (inclusive).
1255
+ *
1256
+ * Default: 0.3
1257
+ */
1258
+ temperature?: number
1267
1259
  }
1268
1260
 
1269
1261
  /** @beta */
@@ -1274,6 +1266,139 @@ export declare type InstructSyncInstruction<T extends Record<string, Any> = Reco
1274
1266
  InstructRequestBase &
1275
1267
  Sync
1276
1268
 
1269
+ /**
1270
+ * @beta
1271
+ */
1272
+ declare interface InstructTarget {
1273
+ /**
1274
+ * Root target path.
1275
+ *
1276
+ * Use this to have the instruction only affect a part of the document.
1277
+ *
1278
+ * To further control the behavior of individual paths under the root, use `include`, `exclude`, `types.include`
1279
+ * and `types.exclude`.
1280
+ *
1281
+ * Example:
1282
+ *
1283
+ * `target: ['body', {_key: 'someKey'}, 'nestedObject']`
1284
+ *
1285
+ * Here, the instruction will only write to fields under the nestedObject.
1286
+ *
1287
+ * Default: [] = the document itself
1288
+ *
1289
+ * @see #InstructPathSegment
1290
+ * @see #InstructPath
1291
+ * */
1292
+ path?: InstructPathSegment | InstructPath
1293
+ /**
1294
+ * Sets the default operation for all paths in the target.
1295
+ * Instruct runs in `'mixed'` operation mode by default:
1296
+ * Changes are set in all non-array fields, and append to all array fields.
1297
+ *
1298
+ * ### Operation types
1299
+ * - `'set'` – an *overwriting* operation, and replaces the full field value.
1300
+ * - `'append'`:
1301
+ * – array fields: appends new items to the end of the array,
1302
+ * - string fields: '<existing content> <new content>'
1303
+ * - text fields: '<existing content>\n<new content>'
1304
+ * - number fields: existing + new
1305
+ * - other field types not mentioned will set instead (dates, url)
1306
+ * - `'mixed'` – (default) sets non-array fields, and appends to array fields
1307
+ *
1308
+ * The default operation can be overridden on a per-path basis using `include`.
1309
+ *
1310
+ * Nested fields inherit the operation specified by their parent and falls back to the
1311
+ * top level target operation if not otherwise specified.
1312
+ *
1313
+ * Use `include` to change the `operation` of individual fields or items.
1314
+ *
1315
+ * #### Appending in the middle of arrays
1316
+ * `target: {path: ['array'], operation: 'append'}` will append the output of the instruction to the end of the array.
1317
+ *
1318
+ * To insert in the middle of the array, use `target: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append'}`.
1319
+ * Here, the output of the instruction will be appended after the array item with key `'appendAfterKey'`.
1320
+ *
1321
+ * @see #InstructTargetInclude.operation
1322
+ * @see #include
1323
+ * @see #InstructTargetInclude.include
1324
+ */
1325
+ operation?: InstructOperation
1326
+ /**
1327
+ * maxPathDepth controls how deep into the schema from the target root the instruction will affect.
1328
+ *
1329
+ * Depth is based on path segments:
1330
+ * - `title` has depth 1
1331
+ * - `array[_key="no"].title` has depth 3
1332
+ *
1333
+ * Be careful not to set this too high in studios with recursive document schemas, as it could have
1334
+ * negative impact on performance; both for runtime and quality of responses.
1335
+ *
1336
+ * Default: 4
1337
+ */
1338
+ maxPathDepth?: number
1339
+ /**
1340
+ * By default, all children up to `target.maxPathDepth` are included.
1341
+ *
1342
+ * When `include` is specified, only segments explicitly listed will be included.
1343
+ *
1344
+ * Fields or array items not on the include list, are implicitly excluded.
1345
+ */
1346
+ include?: (InstructPathSegment | InstructTargetInclude)[]
1347
+ /**
1348
+ * By default, all children up to `target.maxPathDepth` are included.
1349
+ * Fields or array items not on the exclude list, are implicitly included.
1350
+ */
1351
+ exclude?: InstructPathSegment[]
1352
+ /**
1353
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
1354
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
1355
+ *
1356
+ * `types.include` and `types.exclude` are mutually exclusive.
1357
+ */
1358
+ types?: InstructTypeConfig
1359
+ }
1360
+
1361
+ declare interface InstructTargetInclude {
1362
+ path: InstructPathSegment | InstructPath
1363
+ /**
1364
+ * Sets the operation for this path, and all its children.
1365
+ * This overrides any operation set parents or the root target.
1366
+ * @see #InstructTarget.operation
1367
+ * @see #include
1368
+ */
1369
+ operation?: InstructOperation
1370
+ /**
1371
+ * By default, all children up to `target.maxPathDepth` are included.
1372
+ *
1373
+ * When `include` is specified, only segments explicitly listed will be included.
1374
+ *
1375
+ * Fields or array items not on the include list, are implicitly excluded.
1376
+ */
1377
+ include?: (InstructPathSegment | InstructTargetInclude)[]
1378
+ /**
1379
+ * By default, all children up to `target.maxPathDepth` are included.
1380
+ * Fields or array items not on the exclude list, are implicitly included.
1381
+ */
1382
+ exclude?: InstructPathSegment[]
1383
+ /**
1384
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
1385
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
1386
+ *
1387
+ * `types.include` and `types.exclude` are mutually exclusive.
1388
+ */
1389
+ types?: InstructTypeConfig
1390
+ }
1391
+
1392
+ declare type InstructTypeConfig =
1393
+ | {
1394
+ include: string[]
1395
+ exclude?: never
1396
+ }
1397
+ | {
1398
+ exclude: string[]
1399
+ include?: never
1400
+ }
1401
+
1277
1402
  /**
1278
1403
  * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
1279
1404
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "6.28.3-instruct.4",
3
+ "version": "6.28.3-instruct.6",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",