Skip to content

Add promise() schema builder#159

Merged
andrewzolotukhin merged 7 commits intodevelopmentfrom
copilot/add-promise-schema-builder
Apr 10, 2026
Merged

Add promise() schema builder#159
andrewzolotukhin merged 7 commits intodevelopmentfrom
copilot/add-promise-schema-builder

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

@cleverbrush/schema had no way to validate Promise values or express Promise<T> in the inferred type system.

New: PromiseSchemaBuilder + promise() factory

import { promise, string, number, InferType } from '@cleverbrush/schema';

// Untyped — accepts any Promise
const anyPromise = promise();
anyPromise.validate(Promise.resolve(42));     // { valid: true }
anyPromise.validate('not a promise' as any); // { valid: false }

// Typed resolved value — via factory shorthand
const stringPromise = promise(string());
type StringPromise = InferType<typeof stringPromise>; // Promise<string>

// Or via fluent method
const numPromise = promise().hasResolvedType(number());
type NumPromise = InferType<typeof numPromise>; // Promise<number>

// All standard builder methods work
const opt = promise(string()).optional();
type Opt = InferType<typeof opt>; // Promise<string> | undefined

Changes

  • PromiseSchemaBuilder.ts — new builder extending SchemaBuilder. Validates via thenable duck-typing (typeof .then === 'function'). Supports .hasResolvedType(schema) to set the resolved-value type; factory shorthand promise(schema?) as sugar. All standard methods preserved (optional, nullable, default, brand, readonly, hasType, etc.). introspect().resolvedType exposes the schema for tooling.
  • PromiseSchemaBuilder.test.ts — 25 unit + type tests covering validation, optional/required, hasResolvedType, promise(schema) shorthand, immutability, and type inference.
  • ExportsPromiseSchemaBuilder, promise, ExtendedPromise added to core.ts, index.ts, and extensions/index.ts. Subpath export @cleverbrush/schema/promise added to package.json and tsup.config.ts.
  • READMEpromise() added to the API table and builder classes list; new "Promise Schemas" section with usage examples.
  • Changeset — minor version bump for @cleverbrush/schema.
  • PlaygroundschemaDeclarations.ts regenerated from build; two new examples (promise-schema, promise-typed) added to the website playground.

Copilot AI linked an issue Apr 10, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits April 10, 2026 07:57
…amples

Agent-Logs-Url: https://github.com/cleverbrush/framework/sessions/931a7d5d-bd3f-4cb8-8cff-63c6f1d8dd80

Co-authored-by: andrewzolotukhin <1894885+andrewzolotukhin@users.noreply.github.com>
Agent-Logs-Url: https://github.com/cleverbrush/framework/sessions/931a7d5d-bd3f-4cb8-8cff-63c6f1d8dd80

Co-authored-by: andrewzolotukhin <1894885+andrewzolotukhin@users.noreply.github.com>
Copilot AI changed the title [WIP] Add a promise schema builder for resolving to Promise<T> type Add promise() schema builder Apr 10, 2026
Copilot AI requested a review from andrewzolotukhin April 10, 2026 08:00
- Updated bundle sizes in `bundle-sizes.json` for `@cleverbrush/schema` and `@cleverbrush/schema/core`.
- Adjusted bundle size badge in `libs/schema/README.md` to reflect new gzip size.
- Modified coverage badge in `libs/schema/README.md` to show updated coverage percentage.
- Refactored tests in `PromiseSchemaBuilder.test.ts` to remove unnecessary async/await usage.
- Cleaned up constructor formatting in `PromiseSchemaBuilder.ts`.
- Reorganized exports in `core.ts`, `index.ts`, and `schemaDeclarations.ts` for consistency.
@andrewzolotukhin andrewzolotukhin marked this pull request as ready for review April 10, 2026 08:29
Copilot AI review requested due to automatic review settings April 10, 2026 08:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Introduces first-class Promise support to @cleverbrush/schema via a new PromiseSchemaBuilder and promise() factory, including exports, docs, tests, and playground examples.

Changes:

  • Added PromiseSchemaBuilder + promise() factory with resolved-type typing via .hasResolvedType(schema) and promise(schema) shorthand.
  • Integrated builder into package exports/build (tsup entry, subpath export) and updated docs/playground examples.
  • Added dedicated unit + type tests and regenerated generated artifacts (playground declarations, bundle/bench metadata).

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
website/app/playground/schemaDeclarations.ts Regenerated playground type declarations to include PromiseSchemaBuilder/promise exports.
website/app/playground/examples/index.ts Added “Promise Schemas” playground group and two new examples.
README.md Updated root coverage badge (generated).
libs/schema/tsup.config.ts Added PromiseSchemaBuilder.ts to build entrypoints.
libs/schema/src/index.ts Exported PromiseSchemaBuilder, promise, and ExtendedPromise from main entrypoint.
libs/schema/src/extensions/index.ts Added ExtendedPromise type and exported promise from extensions entrypoint.
libs/schema/src/core.ts Exported PromiseSchemaBuilder and promise from core.
libs/schema/src/builders/PromiseSchemaBuilder.ts Implemented the new builder + factory and introspection support.
libs/schema/src/builders/PromiseSchemaBuilder.test.ts Added unit + type tests for promise validation, typing, and immutability.
libs/schema/README.md Documented promise(schema?) and added a “Promise Schemas” section + export list updates.
libs/schema/package.json Added subpath export @cleverbrush/schema/promise.
bundle-sizes.json Updated bundle size snapshot (generated).
bench-results.json Updated benchmark snapshot (generated).
.changeset/add-promise-schema-builder.md Added changeset for a minor release including usage notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

andrewzolotukhin and others added 3 commits April 10, 2026 11:39
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Introduced PromiseSchemaBuilder to handle promise-like values in schema validation.
- Updated the README to reflect the new bundle size for the schema library.
- Adjusted bundle sizes in bundle-sizes.json to reflect recent changes.
- Enhanced type definitions to include promise-related types in schema declarations.
@andrewzolotukhin andrewzolotukhin merged commit 4c71c70 into development Apr 10, 2026
1 check passed
@andrewzolotukhin andrewzolotukhin deleted the copilot/add-promise-schema-builder branch April 10, 2026 08:49
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.

Add a promise schema builder

3 participants