The P1 input profile
@rolebook/scalars-p1: bounded raw JSON admission shared by the decision service and offline snapshots.
@rolebook/scalars-p1 reads JSON bytes under the versioned rolebook/scalars-p1/v1 profile.
The decision service and offline snapshot package use the same parser and conformance fixtures.
The parser returns an admitted value or a typed boundary error; it makes no permission decision.
You rarely call it yourself: the decision service and offline snapshots depend on it and apply it to every request body, policy, authority document, bundle and lease. Read this page when you write an authority provider or an issuer that produces P1 bytes, or when you implement the same boundary elsewhere. Choose how decisions run shows where the profile sits.
Parse bytes
Not on npm yet
@rolebook/scalars-p1 is not on npm yet. The npm package named rolebook is an unrelated project, so do not install it.
import { parseP1, type P1Limits } from "@rolebook/scalars-p1";
declare const bytes: Uint8Array; // the JSON exactly as received, never re-serialized
// Every budget is required. There are no defaults.
const limits: P1Limits = {
maxBytes: 65536,
maxDepth: 32,
maxValues: 16384,
maxObjectMembers: 4096,
maxArrayEntries: 4096,
maxStringBytes: 16384,
};
const result = parseP1(bytes, limits);
if (!result.ok) throw new Error(`not admitted: ${result.error.code}`);
export const value = result.value; parseP1 never throws for malformed bytes or limits; the first failure, in a fixed order, is the
reported code. The result shares nothing with the input buffer. Objects have a null prototype, so a
member named __proto__ or constructor is ordinary data.
What P1 admits
P1 rejects invalid UTF-8, a byte-order mark, duplicate decoded object keys, lone surrogates, trailing data and input exceeding the caller’s explicit structural budgets. It preserves string contents without Unicode normalization. Core still applies its own limits and UTF-16 text semantics after admission.
Number admission checks the original decimal token before conversion. Exact magnitude must not
exceed 9007199254740991; admitted values are rounded to binary64 using nearest, ties to even.
Nonzero values that round to zero are rejected. Signed zero and subnormal numbers are preserved.
P1 is not exact-decimal arithmetic, a full-range binary64 profile or an int64/uint64 profile.
Pass the original bytes to parseP1. Serializing an already parsed JavaScript number cannot recover
the original token or establish that it satisfied this boundary.
The decision service and offline snapshots use P1 to admit JSON input. P1 decides only whether the bytes are admitted. Permission decisions for admitted values use Core’s decision semantics.
The @rolebook/scalars-p1/fixtures/p1-v1.json export contains the shared byte fixtures. They include
expected admission and binary64 results for boundary cases. Passing them demonstrates agreement
on those cases; it does not qualify a new language runtime or prove complete semantic coverage.
API reference
parseP1
function parseP1(bytes: Uint8Array, limits: P1Limits): P1Result; P1_ERROR_CODES
const P1_ERROR_CODES: readonly [
"input_type",
"invalid_limits",
"byte_limit",
"invalid_utf8",
"invalid_json",
"duplicate_key",
"invalid_unicode",
"number_limit",
"number_range",
"number_underflow",
"depth_limit",
"value_limit",
"member_limit",
"array_limit",
"string_limit"
]; P1_MAX_EXPONENT_DIGITS
const P1_MAX_EXPONENT_DIGITS = 6; P1_MAX_MAGNITUDE
const P1_MAX_MAGNITUDE = 9007199254740991; P1_MAX_NUMBER_TOKEN_BYTES
const P1_MAX_NUMBER_TOKEN_BYTES = 256; P1_SCALAR_PROFILE
const P1_SCALAR_PROFILE = "rolebook/scalars-p1/v1"; P1Error
interface P1Error {
readonly code: P1ErrorCode;
} P1ErrorCode
type P1ErrorCode = (typeof P1_ERROR_CODES)[number]; P1Limits
interface P1Limits {
readonly maxBytes: number;
readonly maxDepth: number;
readonly maxValues: number;
readonly maxObjectMembers: number;
readonly maxArrayEntries: number;
readonly maxStringBytes: number;
} P1Result
type P1Result = {
readonly ok: true;
readonly value: P1Value;
} | {
readonly ok: false;
readonly error: P1Error;
}; P1Value
type P1Value = null | boolean | number | string | P1Value[] | {
[key: string]: P1Value;
};