Skip to content

feat(tailordb,resolver): add object-literal descriptor API#905

Open
dqn wants to merge 14 commits intomainfrom
feat/object-literal-descriptor-api
Open

feat(tailordb,resolver): add object-literal descriptor API#905
dqn wants to merge 14 commits intomainfrom
feat/object-literal-descriptor-api

Conversation

@dqn
Copy link
Copy Markdown
Contributor

@dqn dqn commented Apr 3, 2026

Add createTable and resolver field descriptors as an alternative object-literal syntax for defining TailorDB types and resolver input/output fields

Usage

// TailorDB type with createTable
const order = createTable("Order", {
  fields: {
    name: { kind: "string" },
    quantity: { kind: "int", optional: true, index: true },
    status: { kind: "enum", values: ["pending", "shipped"] },
    address: {
      kind: "object",
      fields: {
        city: { kind: "string" },
        zip: { kind: "string" },
      },
    },
  },
  permission: unsafeAllowAllTypePermission,
});

// Resolver with descriptor fields (mixable with fluent API)
const resolver = createResolver({
  name: "addNumbers",
  operation: "query",
  input: {
    a: { kind: "int" },
    b: { kind: "int" },
  },
  output: { kind: "int" },
  body: ({ input }) => input.a + input.b,
});

Main Changes

  • Add createTable object-literal API for TailorDB type definitions with full descriptor support (all scalar kinds, enum, nested object, hooks, validation, serial, relation, permissions, indices)
  • Add ResolverFieldDescriptor for resolver input/output fields, allowing { kind: "string" } syntax alongside fluent t.string() fields
  • Deduplicate kindToFieldType mapping and resolveResolverFieldMap into shared descriptor.ts module
  • Runtime validation: reject unknown descriptor kinds, malformed passthrough fields, invalid decimal scale, and empty/duplicate enum values

Notes

  • Hook callback typing in descriptors uses the base scalar type (e.g. string, number) rather than the final output type adjusted for optional/array, due to combinatorial type explosion. Use db.*() fluent API when precise hook typing matters
  • No impact on existing db.type() / t.*() APIs

Open with Devin

dqn added 11 commits April 1, 2026 18:22
…ver descriptor support

Add createTable() and timestampFields() as an alternative to the fluent
db.type() API for defining TailorDB types using plain object literals.
This is a reworked version of the closed PR #645 (createType), renamed
to createTable.

Extend createResolver() to accept object-literal field descriptors
({ kind: "string" }) alongside the existing fluent t.string() API in
both input and output parameters. Fluent and descriptor styles can be
mixed freely.
…date decimal scale

- Tighten isResolverFieldDescriptor to check kind is a known string value,
  preventing false positives when output records contain a field named "kind"
- Add decimal scale validation (integer 0-12) in createTable to match db.decimal()
…lverFieldMap, add boundary tests

- Export KindToFieldType from descriptor.ts, remove duplicate in resolver.ts
- Move isTailorField from closure to module-level function
- Replace two-pass iteration in resolveResolverFieldMap with single-pass loop
- Add decimal scale boundary value tests (0 and 12) for createTable
Add runtime guards so that untyped callers (JS, JSON-driven schemas)
get a clear error instead of silently producing fields with undefined
type when passing an invalid kind like "strng".
…hook typing trade-off

Reject enum descriptors that omit the required `values` array at
runtime, preventing permissive fields from being silently created by
untyped callers.  Document the accepted trade-off that descriptor hook
callbacks receive the base scalar type rather than the final output
type adjusted for optional/array.
…sthrough fields

ValidateHookTypes now checks against DescriptorBaseOutput (base scalar)
instead of DescriptorOutput (with array/optional applied), matching the
IndexableOptions typing contract. Also reject plain objects without
`kind` or `type` that would silently pass through as TailorDBField.
…and metadata

Strengthen the passthrough field check to verify both `type` (string)
and `metadata` (object) properties, catching plain objects that are
neither descriptors nor real field instances.  Apply the same guard
to both resolver and tailordb descriptor paths.
…vious comments

Delegate field resolution in resolveResolverFieldMap to
resolveResolverField instead of inlining the same validation logic.
Remove self-evident WHAT comments from createResolver and resolveOutput.
Also fix pre-existing import order in processOrder.ts test fixture.
The import-x/order rule changed after merging main, making the
original order (date-fns before @tailor-platform/sdk) correct again.
@dqn dqn requested review from remiposo and toiroakr as code owners April 3, 2026 07:11
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 3, 2026

🦋 Changeset detected

Latest commit: f987b90

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 Minor
@tailor-platform/create-sdk Minor

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 Apr 3, 2026

Open in StackBlitz

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

commit: f987b90

@claude
Copy link
Copy Markdown

claude bot commented Apr 3, 2026

📖 Docs Consistency Check

⚠️ Inconsistencies Found

File Issue Suggested Fix
packages/sdk/docs/services/tailordb.md New createTable API is not documented Add section documenting createTable object-literal syntax as alternative to db.type()
packages/sdk/docs/services/resolver.md New descriptor syntax for resolver fields is not documented Add section documenting { kind: "string" } syntax as alternative to t.string()
CLAUDE.md Code Patterns section only mentions db.type() Update to mention createTable as an alternative
example/ directory No examples demonstrate new APIs Consider adding example files showing createTable and resolver descriptor usage

Details

1. TailorDB Documentation (packages/sdk/docs/services/tailordb.md)

What the implementation adds:

  • createTable(name, { fields }) - Object-literal API exported from @tailor-platform/sdk (packages/sdk/src/configure/services/index.ts:4)
  • Supports field descriptors like { kind: "string" }, { kind: "int", optional: true }, etc.
  • Full feature parity with db.type() including hooks, validation, relations, indices, permissions

What the docs say:

  • Only documents the fluent API: db.type(), db.string(), db.int(), etc.
  • No mention of createTable or descriptor syntax anywhere in the file

Example from PR description:

const order = createTable("Order", {
  fields: {
    name: { kind: "string" },
    quantity: { kind: "int", optional: true, index: true },
    status: { kind: "enum", values: ["pending", "shipped"] },
  },
  permission: unsafeAllowAllTypePermission,
});

Suggested section location: After "Type Definition" section (line 17), add a new section titled "Alternative: Object-Literal Syntax (createTable)"


2. Resolver Documentation (packages/sdk/docs/services/resolver.md)

What the implementation adds:

  • ResolverFieldDescriptor type for resolver input/output fields (packages/sdk/src/configure/services/resolver/descriptor.ts:57-68)
  • Allows { kind: "string" } syntax as alternative to t.string()
  • Can be mixed with fluent API fields in the same resolver

What the docs say:

  • Only documents fluent API: t.int(), t.string(), t.object(), etc. (lines 84-121)
  • Section "Input/Output Schemas" (line 104) states: "Define input/output schemas using methods of t object"
  • No mention of descriptor syntax

Example from PR description:

const resolver = createResolver({
  name: "addNumbers",
  operation: "query",
  input: {
    a: { kind: "int" },
    b: { kind: "int" },
  },
  output: { kind: "int" },
  body: ({ input }) => input.a + input.b,
});

Suggested section location: After "Input/Output Schemas" intro (line 106), add subsection "Object-Literal Descriptor Syntax"


3. CLAUDE.md

What the docs say:

  • Line 44: example/tailordb/*.ts - Model definitions with db.type()
  • No mention of createTable alternative

Suggested fix:
Update line 44 to:

- `example/tailordb/*.ts` - Model definitions with `db.type()` or `createTable`

Or add to "Non-obvious Rules and Gotchas" section if there are any caveats about the new API.


4. Example Files (example/ directory)

What exists:

  • All TailorDB types use fluent API: db.type(...) (e.g., example/tailordb/customer.ts)
  • All resolvers use fluent API: t.string(), t.int(), etc. (e.g., example/resolvers/add.ts)

What's missing:

  • No example demonstrating createTable
  • No example demonstrating descriptor syntax in resolvers

Note from PR description:

"No impact on existing db.type() / t.*() APIs"

The old APIs still work, but examples showing the new alternatives would help users understand both options.


Recommended Actions

  1. Add documentation for createTable in packages/sdk/docs/services/tailordb.md:

    • Show basic usage with field descriptors
    • Explain when to use object-literal vs fluent API (e.g., PR notes that hook typing is less precise in descriptors)
    • Document all supported descriptor options (optional, array, hooks, validate, index, unique, serial, relation, etc.)
  2. Add documentation for descriptor syntax in packages/sdk/docs/services/resolver.md:

    • Show that descriptors can be mixed with fluent API
    • Document supported descriptor types (string, int, float, bool, uuid, decimal, date, datetime, time, enum, object)
    • Note any limitations vs fluent API
  3. Update CLAUDE.md to mention both API styles

  4. Consider adding example files (optional but recommended):

    • example/tailordb/descriptor-example.ts using createTable
    • example/resolvers/descriptor-example.ts using field descriptors

@claude
Copy link
Copy Markdown

claude bot commented Apr 3, 2026

📖 Docs Consistency Check

⚠️ Inconsistencies Found

File Issue Suggested Fix
packages/sdk/docs/services/tailordb.md Missing createTable() API documentation Add section documenting the object-literal descriptor API as an alternative to db.type()
packages/sdk/docs/services/tailordb.md Missing timestampFields() helper Document the timestampFields() helper function and its usage
packages/sdk/docs/services/resolver.md Missing descriptor syntax for input/output fields Add section showing { kind: "string" } syntax alongside fluent API examples
CLAUDE.md Code Patterns section only mentions db.type() Add createTable() as an alternative pattern with reference to examples
example/ directory No examples using new APIs Add at least one example file demonstrating createTable() and resolver descriptor syntax

Details

1. TailorDB createTable() API (packages/sdk/docs/services/tailordb.md)

What the implementation does:

  • packages/sdk/src/configure/services/tailordb/createTable.ts:469-504 - Exports createTable() function that accepts object-literal field descriptors as an alternative to the fluent db.type() API
  • packages/sdk/src/configure/services/index.ts:4 - Exports createTable from the main SDK package
  • JSDoc example in the implementation shows:
    export const user = createTable("User", {
      name: { kind: "string" },
      email: { kind: "string", unique: true },
      role: { kind: "enum", values: ["MANAGER", "STAFF"] },
      ...timestampFields(),
    });

What the documentation says:

  • The TailorDB documentation only documents db.type() with the fluent API
  • No mention of createTable() anywhere in the docs
  • The "Type Definition" section (lines 17-61) only shows the db.type() pattern

Impact:
Users won't know that the object-literal descriptor API exists as an alternative style for defining TailorDB types.

2. TailorDB timestampFields() helper (packages/sdk/docs/services/tailordb.md)

What the implementation does:

  • packages/sdk/src/configure/services/tailordb/createTable.ts:516-530 - Exports timestampFields() helper that returns standard createdAt/updatedAt fields with auto-hooks
  • packages/sdk/src/configure/services/index.ts:5 - Exports timestampFields from the main SDK package
  • Can be used with both createTable() and db.type() via spread syntax

What the documentation says:

  • The docs show ...db.fields.timestamps() (line 357-358) as the pattern for timestamp fields
  • No mention of timestampFields() helper

Impact:
Users using createTable() won't know about the timestampFields() helper designed for the descriptor API. The existing db.fields.timestamps() is for the fluent API.

3. Resolver descriptor syntax (packages/sdk/docs/services/resolver.md)

What the implementation does:

  • packages/sdk/src/configure/services/resolver/descriptor.ts:1-212 - Implements ResolverFieldDescriptor type system supporting { kind: "string" } syntax
  • packages/sdk/src/configure/services/resolver/resolver.ts:79-82 - Documents that input/output fields accept both fluent API and object-literal descriptors, and both can be mixed
  • JSDoc example in resolver.ts:106-116 shows:
    input: {
      a: { kind: "int", description: "First number" },
      b: { kind: "int", description: "Second number" },
    },
    output: { kind: "int", description: "Sum" },

What the documentation says:

  • packages/sdk/docs/services/resolver.md:84-142 - Only shows fluent API examples with t.string(), t.int(), etc.
  • No mention that descriptor syntax { kind: "int" } is supported
  • No examples mixing both styles

Impact:
Users won't know they can use descriptor syntax in resolvers, which provides a more concise alternative for simple fields and matches the TailorDB createTable() style.

4. CLAUDE.md Code Patterns section

What the implementation does:

  • Adds createTable as a new exported API for defining TailorDB types

What CLAUDE.md says:

  • Lines 43: "Model definitions with db.type()" - only mentions the fluent API
  • No mention of createTable() as an alternative pattern

Impact:
Claude Code won't know about the new API when helping users write TailorDB models, and won't suggest it as an option.

5. Example files

What the implementation does:

  • Adds fully functional createTable() and descriptor APIs

What the examples show:

  • example/tailordb/*.ts - All examples use db.type() fluent API only
  • example/resolvers/*.ts - All examples use t.string() fluent API only
  • No examples demonstrate the new descriptor syntax

Impact:
Users learning from examples won't see the descriptor API in action. The example/ directory is specifically referenced in CLAUDE.md as the source for "working implementations of all patterns."

Recommended Actions

  1. Add createTable() section to TailorDB docs - Document the object-literal API with full examples showing all field descriptor types (scalar, enum, object, relations, hooks, validation, etc.)

  2. Document timestampFields() helper - Add to TailorDB docs, likely in a "Common Fields" or "Helper Functions" section, showing it works with both createTable() and spread into db.type()

  3. Add descriptor syntax section to Resolver docs - Show examples of { kind: "string" } syntax for input/output fields, demonstrate mixing with fluent API

  4. Update CLAUDE.md - Add createTable to the Code Patterns section as an alternative to db.type(), update the reference to mention both APIs

  5. Add example files - Create at least one TailorDB type using createTable() and one resolver using descriptor syntax in the example/ directory


@github-actions

This comment has been minimized.

Cover pluralForm (string and tuple), description, features, and
gqlPermission options that were missing from the test suite.
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 potential bugs to report.

View in Devin Review to see 7 additional findings.

Open in Devin Review

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

Code Metrics Report (packages/sdk)

main (0be43dd) #905 (117446a) +/-
Coverage 57.0% 57.5% +0.5%
Code to Test Ratio 1:0.4 1:0.4 +0.0
Details
  |                    | main (0be43dd) | #905 (117446a) |  +/-  |
  |--------------------|----------------|----------------|-------|
+ | Coverage           |          57.0% |          57.5% | +0.5% |
  |   Files            |            337 |            339 |    +2 |
  |   Lines            |          11035 |          11158 |  +123 |
+ |   Covered          |           6292 |           6421 |  +129 |
+ | Code to Test Ratio |          1:0.4 |          1:0.4 |  +0.0 |
  |   Code             |          67220 |          68938 | +1718 |
+ |   Test             |          27489 |          28569 | +1080 |

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

Files Coverage +/- Status
packages/sdk/src/configure/services/resolver/descriptor.ts 94.8% +94.8% added
packages/sdk/src/configure/services/resolver/resolver.ts 100.0% 0.0% modified
packages/sdk/src/configure/services/tailordb/createTable.ts 94.8% +94.8% added
packages/sdk/src/configure/services/tailordb/index.ts 0.0% 0.0% modified
packages/sdk/src/configure/services/tailordb/schema.ts 86.3% +5.4% modified
packages/sdk/src/configure/types/type.ts 96.3% 0.0% modified

SDK Configure Bundle Size

main (0be43dd) #905 (117446a) +/-
configure-index-size 12.69KB 21.3KB 8.61KB
dependency-chunks-size 33.36KB 33.44KB 0.08KB
total-bundle-size 46.04KB 54.74KB 8.7KB

Runtime Performance

main (0be43dd) #905 (117446a) +/-
Generate Median 2,683ms 2,595ms -88ms
Generate Max 2,775ms 2,820ms 45ms
Apply Build Median 2,702ms 2,640ms -62ms
Apply Build Max 2,815ms 2,676ms -139ms

Type Performance (instantiations)

main (0be43dd) #905 (117446a) +/-
tailordb-basic 42,484 52,775 10,291
tailordb-optional 3,826 3,826 0
tailordb-relation 3,970 3,970 0
tailordb-validate 2,824 2,824 0
tailordb-hooks 5,689 5,689 0
tailordb-object 11,470 11,470 0
tailordb-enum 2,720 2,720 0
resolver-basic 9,239 11,068 1,829
resolver-nested 25,626 27,359 1,733
resolver-array 17,862 19,692 1,830
executor-schedule 4,244 4,244 0
executor-webhook 883 883 0
executor-record 4,746 4,746 0
executor-resolver 4,273 6,242 1,969
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

dqn added 2 commits April 3, 2026 16:42
Document the object-literal API (createTable, timestampFields) in
tailordb.md and resolver field descriptors in resolver.md. Update
CLAUDE.md code patterns to mention both API styles.
Demonstrate the object-literal descriptor API with a Product model
that includes enum, relation, timestamps, and permissions.
@toiroakr
Copy link
Copy Markdown
Contributor

toiroakr commented Apr 3, 2026

Hook callback typing in descriptors uses the base scalar type (e.g. string, number) rather than the final output type adjusted for optional/array, due to combinatorial type explosion. Use db.*() fluent API when precise hook typing matters

This is a major issue...
I wonder what we should do... 🤔

@dqn
Copy link
Copy Markdown
Contributor Author

dqn commented Apr 4, 2026

Addressed in f987b90 and 47ab17c:

  • Added createTable and timestampFields() documentation to tailordb.md
  • Added descriptor syntax documentation to resolver.md
  • Updated CLAUDE.md code patterns
  • Added example/tailordb/product.ts demonstrating the new API

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