first commit
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
# Register Schemas — `@suaveplan/bitpacker-strategies`
|
||||
|
||||
<!-- begin:auto-docs -->
|
||||
_(no submodules)_
|
||||
<!-- end:auto-docs -->
|
||||
|
||||
## Purpose
|
||||
|
||||
Idempotent integration with `@suaveplan/schema-registry` for the `@suaveplan/bitpacker-strategies` package. Exposes a single `registerBitPackerStrategiesSchemas(registry)` function that converts the package's only public boundary schema (`packingStrategyManagerSchema`) into JSON Schema form and registers it under the canonical subject `bitpacker:@suaveplan/bitpacker-strategies` at version 1.
|
||||
|
||||
This package's strategies are parameterless, so the only registered surface is the boundary check on `registerDefaultStrategies(manager)` — the strategy classes themselves are validated by `@suaveplan/bitpacker`'s `packingStrategySchema`. Mirroring the cross-package shape avoids duplicating those schemas here.
|
||||
|
||||
## Features
|
||||
|
||||
- `BITPACKER_STRATEGIES_SUBJECT` constant — `"bitpacker:@suaveplan/bitpacker-strategies"`
|
||||
- `BITPACKER_STRATEGIES_SCHEMA_VERSION` constant — `1`
|
||||
- `registerBitPackerStrategiesSchemas(registry)` — idempotent registration
|
||||
|
||||
## Usage: Basic Example
|
||||
|
||||
```ts
|
||||
import { createRegistry } from "@suaveplan/schema-registry";
|
||||
import {
|
||||
BITPACKER_STRATEGIES_SUBJECT,
|
||||
registerBitPackerStrategiesSchemas,
|
||||
} from "@suaveplan/bitpacker-strategies/register-schemas";
|
||||
|
||||
const registry = createRegistry();
|
||||
registerBitPackerStrategiesSchemas(registry);
|
||||
console.log(registry.getLatest(BITPACKER_STRATEGIES_SUBJECT).version); // 1
|
||||
```
|
||||
|
||||
## Usage: Advanced Example
|
||||
|
||||
```ts
|
||||
import { createRegistry, SchemaRegistry } from "@suaveplan/schema-registry";
|
||||
import { registerBitPackerSchemas } from "@suaveplan/bitpacker/register-schemas";
|
||||
import { registerBitPackerStrategiesSchemas } from "@suaveplan/bitpacker-strategies/register-schemas";
|
||||
|
||||
function bootstrapAll(registry: SchemaRegistry) {
|
||||
registerBitPackerSchemas(registry);
|
||||
registerBitPackerStrategiesSchemas(registry);
|
||||
}
|
||||
|
||||
const registry = createRegistry();
|
||||
bootstrapAll(registry);
|
||||
bootstrapAll(registry); // safe: idempotent
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
### `BITPACKER_STRATEGIES_SUBJECT: "bitpacker:@suaveplan/bitpacker-strategies"`
|
||||
|
||||
Const string. The exact subject under which the package's schemas are registered.
|
||||
|
||||
### `BITPACKER_STRATEGIES_SCHEMA_VERSION: 1`
|
||||
|
||||
Const number. The version under which the package's schemas are registered.
|
||||
|
||||
### `registerBitPackerStrategiesSchemas(registry: SchemaRegistry): void`
|
||||
|
||||
Idempotent registration. If the subject is already present in `registry.listSubjects()`, returns without writing. Otherwise registers the `packingStrategyManager` payload with `{ namespace, package }` metadata.
|
||||
|
||||
## Implementation Notes
|
||||
|
||||
- **Single-key payload.** This package's only boundary schema is `packingStrategyManagerSchema`. The payload object keeps a single key (`packingStrategyManager`) for parity with the larger families' payloads, so a downstream consumer can pick the schema by name.
|
||||
- **Idempotency via `listSubjects()` check.** Same pattern as the core package — a membership test is sufficient to keep `version: 1` stable across re-imports.
|
||||
- **`unrepresentable: "any"`.** The strategy-manager schema uses `z.custom` for the `instanceof` check; without this option, `z.toJSONSchema` throws. Coercing to `{}` is fine because consumers reading the JSON-Schema payload are typically asking "what does this package register?" not "validate me against this schema at runtime."
|
||||
Reference in New Issue
Block a user