refactor(api): collapse DataSchema builder/built distinction and remove DT.Meta#872
Merged
Conversation
…ve DT.Meta DataSchema now exposes its parser records as public readonly fields and is passed directly to `Data.create()` — the separate `.build()` step and the `BuiltDataSchema` interface are gone. The DT.Meta indirection is also removed: `Data<$ extends DataSchema = DataSchema>` indexes the schema directly using camelCase keys that mirror the runtime object (`$['payloadParsers']`, etc.), so there is one shape for both type-level and value-level access. TargetingPredicates is decoupled from the old Meta shape, `Data` exposes a `schema` getter, and downstream packages (server, client, fs, explode, json-schema, date-range) are updated to the new generic. BREAKING CHANGE: `.build()`, `BuiltDataSchema`, `DT.Meta`, and `DT.EmptyMeta` have been removed. Migration: - Drop `.build()` calls; pass the `DataSchema` to `Data.create()` directly. - Replace `$ extends DT.Meta` with `$ extends DataSchema`. - Rename indexed access keys from PascalCase to camelCase: `$['PayloadParsers']` → `$['payloadParsers']` `$['TargetingParsers']` → `$['targetingParsers']` `$['QueryParsers']` → `$['queryParsers']` `$['FallThroughTargetingParsers']` → `$['fallThroughTargetingParsers']` - Replace `DT.Any` with `DataSchema` in generic constraints where you previously used it as the "match any" bound.
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors @targetd/api’s type model so DataSchema is passed directly to Data.create() (no .build() / BuiltDataSchema) and removes the DT.Meta indirection by indexing directly into the schema’s camelCase parser-record fields. Updates all downstream packages to the new generics and indexing keys.
Changes:
- Remove the DataSchema “builder vs built” split;
Data.create()now acceptsDataSchemadirectly andDataexposes aschemagetter. - Replace
DT.Meta/PascalCase indexed-access types withDataSchema/camelCase keys across server/client/fs/explode/json-schema/date-range. - Update docs/tests/examples to drop
.build()and align with the new schema-driven generics.
Reviewed changes
Copilot reviewed 41 out of 41 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/server/test/index.test.ts | Drops DT usage and .build() in server tests; updates helper typing. |
| packages/server/src/middleware/castQueryArrayProps.ts | Rebinds middleware generics to DataSchema/Data<$> instead of DT.Any. |
| packages/server/src/index.ts | Updates createServer generics and query typing to schema-indexed access. |
| packages/server/README.md | Updates examples to remove .build() and use schema directly. |
| packages/json-schema/test/fixtures/data.ts | Drops .build() from fixture schema creation. |
| packages/json-schema/src/index.ts | Rebinds schema generation helpers to Data<$ extends DataSchema>. |
| packages/json-schema/src/cli.ts | Updates CLI type-guard to use Data type. |
| packages/fs/test/fixtures/data.ts | Drops .build() from fixture schema creation. |
| packages/fs/src/watch.ts | Updates watcher generics from DT.Any to Data<$ extends DataSchema>. |
| packages/fs/src/load.ts | Updates loader generics/signatures to Data<$ extends DataSchema>. |
| packages/fs/README.md | Updates examples to remove .build() and use schema directly. |
| packages/explode/src/types.ts | Switches explode typing to index into DataSchema parser records. |
| packages/explode/README.md | Updates examples to remove .build(). |
| packages/date-range/test/index.test.ts | Drops .build() from date-range tests. |
| packages/date-range/src/index.ts | Updates inline example to remove .build(). |
| packages/date-range/README.md | Updates examples to remove .build(). |
| packages/client/test/index.test.ts | Updates client tests to use data.schema typing pattern. |
| packages/client/src/index.ts | Changes Client generic to DataSchema and camelCase indexed access; removes ClientWithData. |
| packages/client/README.md | Updates examples to remove .build(). |
| packages/api/test/type-stress.test.ts | Updates stress test schema creation to remove .build(). |
| packages/api/test/Data.test.ts | Updates core API tests to remove .build() and match new schema API. |
| packages/api/src/types/Payload.ts | Rebinds payload types to DataSchema and camelCase parser keys. |
| packages/api/src/types/FallThroughTargeting.ts | Rebinds fallthrough types to DataSchema and camelCase parser keys. |
| packages/api/src/types/Data.ts | Removes DT.Meta/DT.Any modeling; keeps insertable shape keyed off DataSchema. |
| packages/api/src/predicates/targetIncludes.ts | Updates docs/examples to remove .build(). |
| packages/api/src/predicates/equals.ts | Updates docs/examples to remove .build(). |
| packages/api/src/parsers/TargetingPredicates.ts | Decouples predicates typing from DT.Meta to a minimal { targetingParsers, queryParsers } shape. |
| packages/api/src/parsers/DataItems.ts | Rebinds parsers/types to DataSchema and camelCase keys. |
| packages/api/src/parsers/DataItemVariablesParser.ts | Rebinds variable parser typing to DataSchema and camelCase keys. |
| packages/api/src/parsers/DataItemRules.ts | Rebinds rules parser typing to DataSchema and camelCase keys. |
| packages/api/src/parsers/DataItemRule.ts | Rebinds rule parser typing to DataSchema and camelCase keys. |
| packages/api/src/parsers/DataItem.ts | Rebinds item parser typing to DataSchema and camelCase keys. |
| packages/api/src/index.ts | Removes BuiltDataSchema export and keeps package surface aligned to new API. |
| packages/api/src/QueryableData.ts | Updates query interface generics/indexing to DataSchema + camelCase keys. |
| packages/api/src/PromisedData.ts | Updates promised wrapper generics/indexing to DataSchema + camelCase keys. |
| packages/api/src/InsertableData.ts | Updates insert interface generic bound to DataSchema. |
| packages/api/src/DataSchema.ts | Implements “schema is the record” approach (public frozen records; no .build()). |
| packages/api/src/Data.ts | Makes Data generic over DataSchema, stores schema, and removes built-schema dependency. |
| packages/api/README.md | Updates top-level API docs/examples to remove .build() and explain new split. |
| README.md | Updates repo README examples to remove .build(). |
| .github/copilot-instructions.md | Updates internal dev guide references to new DataSchema/Data API shape. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DataSchema now exposes its parser records as public readonly fields and is passed directly to
Data.create()— the separate.build()step and theBuiltDataSchemainterface are gone. The DT.Meta indirection is also removed:Data<$ extends DataSchema = DataSchema>indexes the schema directly using camelCase keys that mirror the runtime object ($['payloadParsers'], etc.), so there is one shape for both type-level and value-level access.TargetingPredicates is decoupled from the old Meta shape,
Dataexposes aschemagetter, and downstream packages (server, client, fs, explode, json-schema, date-range) are updated to the new generic.BREAKING CHANGE:
.build(),BuiltDataSchema,DT.Meta, andDT.EmptyMetahave been removed.Migration:
.build()calls; pass theDataSchematoData.create()directly.$ extends DT.Metawith$ extends DataSchema.$['PayloadParsers']→$['payloadParsers']$['TargetingParsers']→$['targetingParsers']$['QueryParsers']→$['queryParsers']$['FallThroughTargetingParsers']→$['fallThroughTargetingParsers']DT.AnywithDataSchemain generic constraints where you previously used it as the "match any" bound.