Skip to content

fix: allow readonly arrays in db.enum() and t.enum()#804

Merged
toiroakr merged 3 commits intomainfrom
fix/enum
Mar 23, 2026
Merged

fix: allow readonly arrays in db.enum() and t.enum()#804
toiroakr merged 3 commits intomainfrom
fix/enum

Conversation

@toiroakr
Copy link
Copy Markdown
Contributor

@toiroakr toiroakr commented Mar 23, 2026

Summary

  • Make AllowedValues type accept readonly tuples so that as const arrays can be passed directly to db.enum() and t.enum() without needing a spread workaround ([...values])
  • Add tests for readonly array inputs in both db.enum() and t.enum()

Open with Devin

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 23, 2026

🦋 Changeset detected

Latest commit: ee915c1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@tailor-platform/sdk Patch
@tailor-platform/create-sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 23, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@tailor-platform/create-sdk@804

commit: ee915c1

@toiroakr toiroakr marked this pull request as ready for review March 23, 2026 05:46
@toiroakr toiroakr requested a review from remiposo as a code owner March 23, 2026 05:46
@github-actions
Copy link
Copy Markdown

Code Metrics Report (packages/sdk)

main (08b4d38) #804 (9b0c18c) +/-
Coverage 55.8% 55.8% 0.0%
Code to Test Ratio 1:0.4 1:0.4 +0.0
Details
  |                    | main (08b4d38) | #804 (9b0c18c) | +/-  |
  |--------------------|----------------|----------------|------|
  | Coverage           |          55.8% |          55.8% | 0.0% |
  |   Files            |            324 |            324 |    0 |
  |   Lines            |          10320 |          10320 |    0 |
  |   Covered          |           5764 |           5764 |    0 |
+ | Code to Test Ratio |          1:0.4 |          1:0.4 | +0.0 |
  |   Code             |          61615 |          61641 |  +26 |
+ |   Test             |          24673 |          24699 |  +26 |

Code coverage of files in pull request scope (100.0% → 100.0%)

Files Coverage +/- Status
packages/sdk/src/configure/types/field.ts 100.0% 0.0% modified

SDK Configure Bundle Size

main (08b4d38) #804 (9b0c18c) +/-
configure-index-size 10.74KB 10.74KB 0KB
dependency-chunks-size 34KB 34KB 0KB
total-bundle-size 44.74KB 44.74KB 0KB

Runtime Performance

main (08b4d38) #804 (9b0c18c) +/-
Generate Median 2,632ms 2,798ms 166ms
Generate Max 2,653ms 2,902ms 249ms
Apply Build Median 2,648ms 2,822ms 174ms
Apply Build Max 2,674ms 2,896ms 222ms

Type Performance (instantiations)

main (08b4d38) #804 (9b0c18c) +/-
tailordb-basic 43,028 43,028 0
tailordb-optional 3,927 3,927 0
tailordb-relation 4,071 4,071 0
tailordb-validate 2,925 2,925 0
tailordb-hooks 5,790 5,790 0
tailordb-object 11,571 11,571 0
tailordb-enum 2,793 2,821 28
resolver-basic 9,239 9,239 0
resolver-nested 25,626 25,626 0
resolver-array 17,862 17,862 0
executor-schedule 4,244 4,244 0
executor-webhook 883 883 0
executor-record 4,847 4,847 0
executor-resolver 4,273 4,273 0
executor-operation-function 877 877 0
executor-operation-gql 879 879 0
executor-operation-webhook 898 898 0
executor-operation-workflow 2,290 2,290 0

Reported by octocov

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@claude
Copy link
Copy Markdown

claude bot commented Mar 23, 2026

📖 Docs Consistency Check

✅ No inconsistencies found between documentation and implementation.

Checked areas:

  • TailorDB documentation (packages/sdk/docs/services/tailordb.md): Enum field documentation at lines 86-94 shows inline array usage with db.enum() which remains valid
  • Auth documentation (packages/sdk/docs/services/auth.md): Examples show enum usage in user profile types (lines 80, 115) which remain valid
  • Resolver documentation (packages/sdk/docs/services/resolver.md): States that t object field types work the same as TailorDB, which is accurate
  • Configuration documentation (packages/sdk/docs/configuration.md): No enum-specific content
  • Example code (example/tailordb/\*.ts, example/resolvers/\*.ts): Uses inline array literals with db.enum() and t.enum() which remain valid

Analysis:
This PR is a backward-compatible enhancement that allows readonly arrays (e.g., as const arrays) to be passed to db.enum() and t.enum() without requiring a spread workaround. The existing documentation shows valid usage patterns that continue to work. The new capability enables cleaner code when defining enum values as constants, but doesn't invalidate any documented patterns.

Example of new capability (not currently documented, but not an inconsistency):

const STATUSES = ["active", "inactive", "pending"] as const;
const enumField = db.enum(STATUSES); // Now works without [...STATUSES]

@claude
Copy link
Copy Markdown

claude bot commented Mar 23, 2026

📖 Docs Consistency Check

✅ No critical inconsistencies found between documentation and implementation.

Checked areas:

  • packages/sdk/docs/services/tailordb.md - Enum field documentation (lines 86-94, 461)
  • packages/sdk/docs/services/auth.md - Enum usage examples (lines 80, 114)
  • packages/sdk/docs/configuration.md - Configuration reference
  • packages/sdk/docs/generator/builtin.md - Enum constants generator
  • example/tailordb/*.ts - Example code with enum usage
  • example/resolvers/userInfo.ts - Resolver with t.enum() usage

PR Summary:
This PR makes a type-level change to AllowedValues, changing it from a regular tuple to a readonly tuple. This allows as const arrays to be passed directly to db.enum() and t.enum() without requiring the spread operator workaround.

Findings:
The existing documentation examples use inline array literals (e.g., db.enum(["red", "green", "blue"])), which continue to work correctly. The documentation is accurate and consistent with the implementation.

💡 Enhancement Suggestion (Optional)

While not a consistency issue, the documentation could be enhanced to demonstrate the new capability of using as const arrays, especially for cases where enum values need to be reused:

// Example that could be added to docs
const USER_ROLES = ["MANAGER", "STAFF"] as const;

// Can be used in TailorDB
export const user = db.type("User", {
  role: db.enum(USER_ROLES),
});

// And reused in resolvers
export default createResolver({
  output: t.object({
    role: t.enum(USER_ROLES),
  }),
});

This pattern is particularly useful when the same enum values are referenced across multiple files (models, resolvers, executors).


@toiroakr toiroakr enabled auto-merge March 23, 2026 06:16
@toiroakr toiroakr merged commit 377362e into main Mar 23, 2026
38 checks passed
@toiroakr toiroakr deleted the fix/enum branch March 23, 2026 07:41
@tailor-pr-trigger tailor-pr-trigger bot mentioned this pull request Mar 23, 2026
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