3.4 KiB
3.4 KiB
Tasks: enterprise-events-schema
- Change ID: enterprise-events-schema
- Package:
@suaveplan/events-schema - Date: 2026-04-24
Prerequisites (must be published to Verdaccio first)
@suaveplan/events@suaveplan/schema-registry@suaveplan/error@suaveplan/types
Tasks
1. Scaffold package
- Create
universal/events/events-schema/directory tree per file layout inproposal.md - Write
package.json(name@suaveplan/events-schema, version0.1.0,sideEffects: false, correct workspace deps and catalog externals) - Write
tsconfig.jsonextending@suaveplan/typescript-config/library.json - Write
vitest.config.tsusingcreateTestConfig()from@suaveplan/testing/config
2. Error codes (src/error-codes.ts)
- Define
EventsSchemaErrorCodeunion type - Call
defineCodesto register allEVENTS_SCHEMA.*codes - Export
registerEventsSchemaErrorCodes()andEventsSchemaError
3. Types (src/types/common.ts)
- Define and export
EventSchemasOptions,EventSchemasHandle,ValidationMode,RejectionHandler,ValidationRejection,ValidationError,SchemaValidationStats,SchemaRegistrationOptions - Write
common.md
4. Sensitive field redaction (src/validation/redaction/)
- Implement redaction logic: scan
ZodErrorissues for paths, mask.receivedvalues when field schema carries.meta({ sensitive: true }) - Write
.md,.test.ts,index.ts
5. Validator (src/validation/validator/)
- Implement validation logic for
strict,warn, andsamplemodes - Inject
rngfor sample-rate decisions - Apply redaction before constructing
ValidationErrorentries - Write
.md,.types.ts,.test.ts,index.ts
6. Schema registration helper (src/schema/register-event-schema/)
- Implement
registerEventSchema(registry, eventName, schema, options?)that callsregistry.checkCompatibilitybefore registering - Throw
EventsSchemaError("EVENTS_SCHEMA_COMPATIBILITY_BREAK")on incompatible change - Write
.md,.test.ts,index.ts
7. Core attachEventSchemas (src/core/attach-event-schemas/)
- Implement
attachEventSchemas(bus, options?)via@suaveplan/eventsinterceptor API only - Validate payload against registered schema on each dispatch using configured
mode - Accumulate
SchemaValidationStats - Emit OTel counters and histogram per
proposal.md§4 - Return
EventSchemasHandlewithdetach(),registerSchema(),stats() - Write
.md,.types.ts,.test.ts,index.ts
8. Tests
- Unit tests co-located (100% coverage target)
tests/integration.test.ts— attach to real EventBus, register schema, dispatch valid and invalid payloads, assert rejection counts and mode behaviourtests/property.test.ts— fast-check properties perproposal.md§5
9. Docs
- Every
.tsimplementation file has a sibling.md - Root
README.md
10. Pre-publish gate
bunx turbo lint typecheck test --filter=@suaveplan/events-schemagreenbunx turbo test:coverage --filter=@suaveplan/events-schema≥ 100% on touched modules
11. Publish
bun scripts/publish.ts --package @suaveplan/events-schema
12. Archive
- Fold spec delta into
openspec/specs/events/spec.md mv openspec/changes/enterprise-events-schema openspec/archive/2026-04-24-enterprise-events-schema