* Update the configuration of a field. Note that this kicks off a long-running * operation for index creation/deletion so the update is complete when this * method returns. * @param project the Firebase project. * @param spec the new field override specification.
(
project: string,
spec: Spec.FieldOverride,
databaseId = "(default)",
)
| 455 | * @param spec the new field override specification. |
| 456 | */ |
| 457 | async patchField( |
| 458 | project: string, |
| 459 | spec: Spec.FieldOverride, |
| 460 | databaseId = "(default)", |
| 461 | ): Promise<any> { |
| 462 | const url = `/projects/${project}/databases/${databaseId}/collectionGroups/${spec.collectionGroup}/fields/${spec.fieldPath}`; |
| 463 | |
| 464 | const indexes = spec.indexes.map((index) => { |
| 465 | return { |
| 466 | queryScope: index.queryScope, |
| 467 | apiScope: index.apiScope, |
| 468 | density: index.density, |
| 469 | multikey: index.multikey, |
| 470 | unique: index.unique, |
| 471 | fields: [ |
| 472 | { |
| 473 | fieldPath: spec.fieldPath, |
| 474 | arrayConfig: index.arrayConfig, |
| 475 | order: index.order, |
| 476 | }, |
| 477 | ], |
| 478 | }; |
| 479 | }); |
| 480 | |
| 481 | let data = { |
| 482 | indexConfig: { |
| 483 | indexes, |
| 484 | }, |
| 485 | }; |
| 486 | |
| 487 | if (spec.ttl) { |
| 488 | data = Object.assign(data, { |
| 489 | ttlConfig: {}, |
| 490 | }); |
| 491 | } |
| 492 | |
| 493 | if (typeof spec.ttl !== "undefined") { |
| 494 | await this.apiClient.patch(url, data); |
| 495 | } else { |
| 496 | await this.apiClient.patch(url, data, { queryParams: { updateMask: "indexConfig" } }); |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * Delete an existing field overrides on the specified project. |