Skip to content

feat(collection): add update for PATCH /collections/{name} - #51

Merged
haydenhoang merged 3 commits into
typesense:masterfrom
tharropoulos:fix/truncate-and-collection-update
Nov 10, 2026
Merged

haydenhoang merged 3 commits into
typesense:masterfrom
tharropoulos:fix/truncate-and-collection-update

Conversation

@tharropoulos

Copy link
Copy Markdown
Contributor
  • add Collection.update(schema:), which sends PATCH /collections/{name} and decodes the response as the type passed in
  • accept any Codable body because CollectionUpdateSchema requires fields, and that blocks updates that only touch metadata or synonym_sets
  • add testCollectionUpdate to drop and add a field, and testCollectionUpdateMetadataOnly to check that a metadata-only patch leaves all 4 fields in place
  • add testDocumentsTruncate to cover truncate: true through the existing documents().delete(options:), which needed no source change
  • add README examples for truncate and collection update, and note that the server ignores filterBy when truncate is set

@haydenhoang

Copy link
Copy Markdown
Collaborator

Hey @tharropoulos , the latest upstream spec already makes fields optional in CollectionUpdateSchema, so we don't need the generic update<T: Codable> workaround. A full regen isn't ready yet because it also renames overrideTags/enableOverrides, which breaks Extensions.swift. Could you hand-apply just this model change instead? It's exactly what the generator outputs, so the future regen will produce no diff for this file:

-    public var fields: [Field]
+    public var fields: [Field]?
 ...
-    public init(fields: [Field], synonymSets: [String]? = nil, metadata: AnyCodable? = nil) {
+    public init(fields: [Field]? = nil, synonymSets: [String]? = nil, metadata: AnyCodable? = nil) {
 ...
-        try container.encode(fields, forKey: .fields)
+        try container.encodeIfPresent(fields, forKey: .fields)

Then:

  • Collection.update: make it non-generic:
    public func update(schema: CollectionUpdateSchema) async throws -> (CollectionUpdateSchema?, URLResponse?)
  • testCollectionUpdate: updatedSchema?.fields?.map(\.name)
  • testCollectionUpdateMetadataOnly: use CollectionUpdateSchema(metadata: ["owner": "search"]) instead of the raw dictionary.
  • README: drop the "pass any Codable" paragraph and show the metadata-only example with CollectionUpdateSchema(metadata:).

@tharropoulos
tharropoulos force-pushed the fix/truncate-and-collection-update branch from 713cc9e to d5ab258 Compare November 10, 2026 10:31
@tharropoulos

Copy link
Copy Markdown
Contributor Author

cc: @haydenhoang

@tharropoulos

Copy link
Copy Markdown
Contributor Author

cc: @jasonbosco @kishorenc

@haydenhoang
haydenhoang merged commit 3e24305 into typesense:master Nov 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants