@emilia-protocol/gate 0.15.2 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/README.md +31 -0
- package/authority-allocation.js +2 -0
- package/autonomy-control-plane-profile.js +2 -0
- package/consequence-actuator.js +3 -0
- package/discovery-permit-resolver.js +3 -0
- package/dist/authority-allocation.d.ts +200 -0
- package/dist/authority-allocation.d.ts.map +1 -0
- package/dist/authority-allocation.js +984 -0
- package/dist/authority-allocation.js.map +1 -0
- package/dist/autonomy-control-plane-profile.d.ts +18 -0
- package/dist/autonomy-control-plane-profile.d.ts.map +1 -0
- package/dist/autonomy-control-plane-profile.js +352 -0
- package/dist/autonomy-control-plane-profile.js.map +1 -0
- package/dist/consequence-actuator.d.ts +226 -0
- package/dist/consequence-actuator.d.ts.map +1 -0
- package/dist/consequence-actuator.js +685 -0
- package/dist/consequence-actuator.js.map +1 -0
- package/dist/discovery-permit-resolver.d.ts +46 -0
- package/dist/discovery-permit-resolver.d.ts.map +1 -0
- package/dist/discovery-permit-resolver.js +428 -0
- package/dist/discovery-permit-resolver.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +22 -2
- package/src/authority-allocation.ts +1268 -0
- package/src/autonomy-control-plane-profile.ts +371 -0
- package/src/consequence-actuator.ts +1122 -0
- package/src/discovery-permit-resolver.ts +496 -0
- package/src/index.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,68 @@
|
|
|
4
4
|
All notable changes to `@emilia-protocol/gate` are documented here.
|
|
5
5
|
This package follows [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## 0.17.0 (2026-07-26)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `./autonomy-control-plane-profile`, a closed compiler from a human-signed
|
|
12
|
+
root objective into one existing Gate Trust Program per exact child action.
|
|
13
|
+
- Typed containment for child actions, audiences, expiries, per-child and
|
|
14
|
+
aggregate sibling budgets, exact code-diff bindings, independent
|
|
15
|
+
proposer/evaluator/executor roles, pinned fitness evidence, bounded canary
|
|
16
|
+
promotion, current suspension status, and separately authorized rollback.
|
|
17
|
+
- A bounded TLA+ model and deliberately unsafe self-expansion configuration;
|
|
18
|
+
the safe model checks authority conservation while the negative control
|
|
19
|
+
falsifies it when an agent can grant itself a new action and budget.
|
|
20
|
+
|
|
21
|
+
### Security
|
|
22
|
+
|
|
23
|
+
- Unknown profile fields, cyclic goal derivation, role collapse, stale or
|
|
24
|
+
unpinned fitness/status evidence, promotion without canary evidence, and
|
|
25
|
+
rollback under a reused CAID fail closed.
|
|
26
|
+
- The claim boundary explicitly excludes natural-language goal entailment,
|
|
27
|
+
provider truth, test adequacy, clocks, storage, and deployment completion.
|
|
28
|
+
|
|
29
|
+
## 0.16.1 (2026-07-26)
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- PostgreSQL 17 role-graph checks now distinguish provider-managed
|
|
34
|
+
administrative grants from executable `INHERIT` or `SET` authority, while
|
|
35
|
+
continuing to reject every usable owner/executor or privileged-role path.
|
|
36
|
+
- Forward migrations remove their own temporary owner grant without deleting
|
|
37
|
+
a managed provider's non-usable administrative grant.
|
|
38
|
+
- The protected npm publisher uses an explicit local tarball file spec.
|
|
39
|
+
|
|
40
|
+
## 0.16.0 (2026-07-25)
|
|
41
|
+
|
|
42
|
+
### Added
|
|
43
|
+
|
|
44
|
+
- `./consequence-actuator`, a short-lived signed execution-envelope boundary
|
|
45
|
+
for separately deployed credential-owning actuators, with immutable tenant,
|
|
46
|
+
action, CAID, provider account, target, operation, attempt, idempotency,
|
|
47
|
+
nonce, and expiry bindings.
|
|
48
|
+
- A PostgreSQL RPC-only permanent envelope store with tenant-principal
|
|
49
|
+
isolation, forced RLS, no direct runtime or `service_role` table authority,
|
|
50
|
+
and no release path after provider invocation.
|
|
51
|
+
- `./discovery-permit-resolver`, which retrieves pinned action-control
|
|
52
|
+
discovery without redirect, network-boundary, freshness, or source drift.
|
|
53
|
+
- A split managed reference deployment where the decision service owns policy
|
|
54
|
+
and envelope signing while the actuator alone owns provider credentials and
|
|
55
|
+
signs exact execution observations.
|
|
56
|
+
|
|
57
|
+
### Security
|
|
58
|
+
|
|
59
|
+
- A provider timeout consumes the execution envelope as `INDETERMINATE`; blind
|
|
60
|
+
replay is refused and only authenticated, attempt-bound evidence may
|
|
61
|
+
reconcile the Proposal-to-Effect lifecycle.
|
|
62
|
+
- Production actuator construction requires an atomic, durable,
|
|
63
|
+
ownership-fenced, permanently consuming store. Process-local storage is
|
|
64
|
+
available only through an explicit test-only opt-in.
|
|
65
|
+
- The decision process has no provider credential or provider API
|
|
66
|
+
implementation. Signed actuator observations are verified under a pinned key
|
|
67
|
+
and exact execution tuple before use as lifecycle evidence.
|
|
68
|
+
|
|
7
69
|
## 0.15.2 (2026-07-23)
|
|
8
70
|
|
|
9
71
|
### Fixed
|
package/README.md
CHANGED
|
@@ -733,3 +733,34 @@ The mechanism is specified in `draft-schrock-ep-enforcement-point` (the Receipt-
|
|
|
733
733
|
`draft-schrock-ep-authorization-receipts`. Earn the **RR-1** conformance level via
|
|
734
734
|
`receiptRequiredConformance()` in `@emilia-protocol/require-receipt`. Reference implementation;
|
|
735
735
|
experimental. Apache-2.0. Fails closed.
|
|
736
|
+
|
|
737
|
+
## Authority allocation
|
|
738
|
+
|
|
739
|
+
`@emilia-protocol/gate/authority-allocation` provides the same-team runtime
|
|
740
|
+
counterpart for Conservation of Authority. A relying party installs one
|
|
741
|
+
authoritative allocation snapshot pinned to an exact authority head and epoch.
|
|
742
|
+
The validator refuses child action or audience widening, budget or expiry
|
|
743
|
+
widening, duplicate sibling branches, and aggregate cents or calls overspend.
|
|
744
|
+
Reservations are atomic, replay-fenced, and can be finalized only with the
|
|
745
|
+
winning owner token, monotonic fencing token, and exact authority head and
|
|
746
|
+
epoch.
|
|
747
|
+
|
|
748
|
+
`createMemoryAuthorityAllocationStore()` is deterministic, non-durable
|
|
749
|
+
conformance infrastructure. `createPostgresAuthorityAllocationStore()` and
|
|
750
|
+
`AUTHORITY_ALLOCATION_DDL` define the durable transactional boundary; they are
|
|
751
|
+
reference code and a database contract, not evidence that any deployment uses
|
|
752
|
+
or correctly operates that boundary.
|
|
753
|
+
|
|
754
|
+
## Autonomy Control Plane
|
|
755
|
+
|
|
756
|
+
`@emilia-protocol/gate/autonomy-control-plane-profile` compiles a closed,
|
|
757
|
+
human-rooted autonomy profile into one existing Gate Trust Program per exact
|
|
758
|
+
child action. It rejects action/audience/expiry widening, aggregate sibling
|
|
759
|
+
budget expansion, cyclic goals, proposer/evaluator/executor role collapse,
|
|
760
|
+
unpinned fitness evidence, promotion without a bounded canary, stale status,
|
|
761
|
+
and rollback without a new CAID and authorization policy.
|
|
762
|
+
|
|
763
|
+
The compiler validates typed authority and evidence bindings. It does not infer
|
|
764
|
+
natural-language goal entailment or prove that tests, providers, storage,
|
|
765
|
+
clocks, deployments, or humans are truthful. See
|
|
766
|
+
`docs/protocol/autonomy-control-plane-profile-v1.md` for the complete boundary.
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime counterpart for Conservation of Authority.
|
|
3
|
+
*
|
|
4
|
+
* This module keeps path containment and aggregate sibling conservation
|
|
5
|
+
* separate. A relying party pins one complete parent allocation snapshot to an
|
|
6
|
+
* exact authority head and epoch. Every sibling is checked against that parent,
|
|
7
|
+
* both resource dimensions are summed independently, and reservations cross a
|
|
8
|
+
* single atomic store boundary before they can be committed.
|
|
9
|
+
*
|
|
10
|
+
* The memory store is deterministic conformance infrastructure, not durable
|
|
11
|
+
* custody. The PostgreSQL adapter requires a real transaction callback and
|
|
12
|
+
* serializes every mutation for one relying-party/parent pair.
|
|
13
|
+
*/
|
|
14
|
+
export declare const AUTHORITY_ALLOCATION_VERSION = "EP-AUTHORITY-ALLOCATION-v1";
|
|
15
|
+
export declare const AUTHORITY_ALLOCATION_CURRENT_TABLE = "ep_authority_allocation_current";
|
|
16
|
+
export declare const AUTHORITY_ALLOCATION_SNAPSHOT_TABLE = "ep_authority_allocation_snapshots";
|
|
17
|
+
export declare const AUTHORITY_ALLOCATION_BRANCH_TABLE = "ep_authority_allocation_branches";
|
|
18
|
+
export declare const AUTHORITY_ALLOCATION_RESERVATION_TABLE = "ep_authority_allocation_reservations";
|
|
19
|
+
export interface AuthorityAllocationBudget {
|
|
20
|
+
cents: number;
|
|
21
|
+
calls: number;
|
|
22
|
+
}
|
|
23
|
+
export interface AuthorityAllocationPin {
|
|
24
|
+
relying_party_id: string;
|
|
25
|
+
authority_head: string;
|
|
26
|
+
authority_epoch: number;
|
|
27
|
+
}
|
|
28
|
+
export interface AuthorityBranchAllocation {
|
|
29
|
+
allocation_id: string;
|
|
30
|
+
parent_id: string;
|
|
31
|
+
actions: readonly string[];
|
|
32
|
+
audiences: readonly string[];
|
|
33
|
+
budget: AuthorityAllocationBudget;
|
|
34
|
+
expires_at: string;
|
|
35
|
+
}
|
|
36
|
+
export interface AuthorityAllocationSnapshot {
|
|
37
|
+
version: typeof AUTHORITY_ALLOCATION_VERSION;
|
|
38
|
+
relying_party_id: string;
|
|
39
|
+
parent_id: string;
|
|
40
|
+
authority_head: string;
|
|
41
|
+
authority_epoch: number;
|
|
42
|
+
actions: readonly string[];
|
|
43
|
+
audiences: readonly string[];
|
|
44
|
+
budget: AuthorityAllocationBudget;
|
|
45
|
+
expires_at: string;
|
|
46
|
+
sibling_allocations: readonly AuthorityBranchAllocation[];
|
|
47
|
+
}
|
|
48
|
+
export interface AuthorityAllocationReservationRequest {
|
|
49
|
+
relying_party_id: string;
|
|
50
|
+
parent_id: string;
|
|
51
|
+
allocation_id: string;
|
|
52
|
+
reservation_id: string;
|
|
53
|
+
authority_head: string;
|
|
54
|
+
authority_epoch: number;
|
|
55
|
+
budget: AuthorityAllocationBudget;
|
|
56
|
+
/** Used by the deterministic memory adapter. PostgreSQL uses database time. */
|
|
57
|
+
now?: string | number | Date;
|
|
58
|
+
}
|
|
59
|
+
export interface AuthorityAllocationOwner {
|
|
60
|
+
owner_token: string;
|
|
61
|
+
fencing_token: number;
|
|
62
|
+
authority_head: string;
|
|
63
|
+
authority_epoch: number;
|
|
64
|
+
}
|
|
65
|
+
export interface AuthorityAllocationFinalizeRequest {
|
|
66
|
+
relying_party_id: string;
|
|
67
|
+
parent_id: string;
|
|
68
|
+
allocation_id: string;
|
|
69
|
+
reservation_id: string;
|
|
70
|
+
authority_head: string;
|
|
71
|
+
authority_epoch: number;
|
|
72
|
+
owner_token: string;
|
|
73
|
+
fencing_token: number;
|
|
74
|
+
}
|
|
75
|
+
export type AuthorityAllocationRefusalReason = 'allocation_not_found' | 'allocation_expired' | 'authority_pin_mismatch' | 'budget_exceeded' | 'reservation_replayed' | 'reservation_not_found' | 'reservation_owner_mismatch' | 'reservation_already_committed' | 'reservation_already_released' | 'snapshot_conflict' | 'stale_authority_epoch' | 'reservations_in_flight';
|
|
76
|
+
export type AuthorityAllocationInstallResult = {
|
|
77
|
+
ok: true;
|
|
78
|
+
installed: boolean;
|
|
79
|
+
snapshot_fingerprint: string;
|
|
80
|
+
} | {
|
|
81
|
+
ok: false;
|
|
82
|
+
reason: AuthorityAllocationRefusalReason;
|
|
83
|
+
};
|
|
84
|
+
export type AuthorityAllocationReservationResult = {
|
|
85
|
+
ok: true;
|
|
86
|
+
reservation_id: string;
|
|
87
|
+
allocation_id: string;
|
|
88
|
+
budget: AuthorityAllocationBudget;
|
|
89
|
+
remaining: AuthorityAllocationBudget;
|
|
90
|
+
owner: AuthorityAllocationOwner;
|
|
91
|
+
} | {
|
|
92
|
+
ok: false;
|
|
93
|
+
reason: AuthorityAllocationRefusalReason;
|
|
94
|
+
};
|
|
95
|
+
export type AuthorityAllocationFinalizeResult = {
|
|
96
|
+
ok: true;
|
|
97
|
+
state: 'committed' | 'released';
|
|
98
|
+
} | {
|
|
99
|
+
ok: false;
|
|
100
|
+
reason: AuthorityAllocationRefusalReason;
|
|
101
|
+
};
|
|
102
|
+
export interface AuthorityAllocationReservationView {
|
|
103
|
+
reservation_id: string;
|
|
104
|
+
allocation_id: string;
|
|
105
|
+
authority_head: string;
|
|
106
|
+
authority_epoch: number;
|
|
107
|
+
budget: AuthorityAllocationBudget;
|
|
108
|
+
state: 'reserved' | 'committed' | 'released';
|
|
109
|
+
fencing_token: number;
|
|
110
|
+
}
|
|
111
|
+
export interface AuthorityAllocationStateView {
|
|
112
|
+
snapshot: AuthorityAllocationSnapshot;
|
|
113
|
+
snapshot_fingerprint: string;
|
|
114
|
+
usage: {
|
|
115
|
+
parent: {
|
|
116
|
+
reserved: AuthorityAllocationBudget;
|
|
117
|
+
committed: AuthorityAllocationBudget;
|
|
118
|
+
};
|
|
119
|
+
branches: Record<string, {
|
|
120
|
+
reserved: AuthorityAllocationBudget;
|
|
121
|
+
committed: AuthorityAllocationBudget;
|
|
122
|
+
}>;
|
|
123
|
+
};
|
|
124
|
+
reservations: AuthorityAllocationReservationView[];
|
|
125
|
+
}
|
|
126
|
+
export interface AuthorityAllocationStore {
|
|
127
|
+
readonly durable: boolean;
|
|
128
|
+
installSnapshot(snapshot: AuthorityAllocationSnapshot, pin: AuthorityAllocationPin): Promise<AuthorityAllocationInstallResult>;
|
|
129
|
+
reserve(request: AuthorityAllocationReservationRequest): Promise<AuthorityAllocationReservationResult>;
|
|
130
|
+
commit(request: AuthorityAllocationFinalizeRequest): Promise<AuthorityAllocationFinalizeResult>;
|
|
131
|
+
release(request: AuthorityAllocationFinalizeRequest): Promise<AuthorityAllocationFinalizeResult>;
|
|
132
|
+
inspect(pin: AuthorityAllocationPin & {
|
|
133
|
+
parent_id: string;
|
|
134
|
+
}): Promise<AuthorityAllocationStateView | null>;
|
|
135
|
+
}
|
|
136
|
+
export declare class AuthorityAllocationValidationError extends TypeError {
|
|
137
|
+
readonly code: string;
|
|
138
|
+
constructor(code: string, message: string);
|
|
139
|
+
}
|
|
140
|
+
type QueryRow = Record<string, unknown>;
|
|
141
|
+
export interface AuthorityAllocationPostgresQueryResult {
|
|
142
|
+
rowCount: number | null;
|
|
143
|
+
rows: QueryRow[];
|
|
144
|
+
}
|
|
145
|
+
export type AuthorityAllocationPostgresQuery = (text: string, params?: readonly unknown[]) => Promise<AuthorityAllocationPostgresQueryResult>;
|
|
146
|
+
export interface AuthorityAllocationPostgresOptions {
|
|
147
|
+
/**
|
|
148
|
+
* Must run the callback in one PostgreSQL transaction. Database errors must
|
|
149
|
+
* reject the callback so the transaction is rolled back.
|
|
150
|
+
*/
|
|
151
|
+
transaction<T>(callback: (query: AuthorityAllocationPostgresQuery) => Promise<T>): Promise<T>;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Validate and normalize a complete authoritative allocation snapshot.
|
|
155
|
+
* Throws AuthorityAllocationValidationError on every malformed or widening
|
|
156
|
+
* condition and returns a detached, deterministically ordered snapshot.
|
|
157
|
+
*/
|
|
158
|
+
export declare function validateAuthorityAllocationSnapshot(input: AuthorityAllocationSnapshot, pin: AuthorityAllocationPin): AuthorityAllocationSnapshot;
|
|
159
|
+
/**
|
|
160
|
+
* Deterministic linearizable in-memory implementation for conformance tests.
|
|
161
|
+
* Owner capabilities and fences are deterministic and therefore unsuitable
|
|
162
|
+
* for production. The store is explicitly marked non-durable.
|
|
163
|
+
*/
|
|
164
|
+
export declare function createMemoryAuthorityAllocationStore(): AuthorityAllocationStore;
|
|
165
|
+
/**
|
|
166
|
+
* PostgreSQL schema contract. Historical snapshots are append-only;
|
|
167
|
+
* ep_authority_allocation_current identifies the one exact head+epoch that can
|
|
168
|
+
* accept reservations. Reservation IDs are replay-fenced across all epochs for
|
|
169
|
+
* one relying-party/parent pair, and owner capabilities are stored only as
|
|
170
|
+
* domain-separated SHA-256 digests.
|
|
171
|
+
*/
|
|
172
|
+
export declare const AUTHORITY_ALLOCATION_DDL = "CREATE TABLE IF NOT EXISTS ep_authority_allocation_snapshots (\n relying_party_id TEXT NOT NULL CHECK (octet_length(relying_party_id) BETWEEN 1 AND 512),\n parent_id TEXT NOT NULL CHECK (octet_length(parent_id) BETWEEN 1 AND 512),\n authority_head TEXT NOT NULL CHECK (authority_head ~ '^sha256:[0-9a-f]{64}$'),\n authority_epoch BIGINT NOT NULL CHECK (authority_epoch >= 0),\n snapshot_fingerprint TEXT NOT NULL CHECK (snapshot_fingerprint ~ '^sha256:[0-9a-f]{64}$'),\n snapshot_json JSONB NOT NULL CHECK (jsonb_typeof(snapshot_json) = 'object'),\n installed_at TIMESTAMPTZ NOT NULL DEFAULT transaction_timestamp(),\n PRIMARY KEY (relying_party_id, parent_id, authority_head, authority_epoch)\n);\nCREATE TABLE IF NOT EXISTS ep_authority_allocation_current (\n relying_party_id TEXT NOT NULL,\n parent_id TEXT NOT NULL,\n authority_head TEXT NOT NULL,\n authority_epoch BIGINT NOT NULL,\n snapshot_fingerprint TEXT NOT NULL,\n next_fencing_token BIGINT NOT NULL DEFAULT 1 CHECK (next_fencing_token > 0),\n PRIMARY KEY (relying_party_id, parent_id),\n FOREIGN KEY (relying_party_id, parent_id, authority_head, authority_epoch)\n REFERENCES ep_authority_allocation_snapshots\n (relying_party_id, parent_id, authority_head, authority_epoch)\n);\nCREATE TABLE IF NOT EXISTS ep_authority_allocation_branches (\n relying_party_id TEXT NOT NULL,\n parent_id TEXT NOT NULL,\n authority_head TEXT NOT NULL,\n authority_epoch BIGINT NOT NULL,\n allocation_id TEXT NOT NULL CHECK (octet_length(allocation_id) BETWEEN 1 AND 512),\n budget_cents BIGINT NOT NULL CHECK (budget_cents >= 0),\n budget_calls BIGINT NOT NULL CHECK (budget_calls >= 0),\n expires_at TIMESTAMPTZ NOT NULL,\n PRIMARY KEY (relying_party_id, parent_id, authority_head, authority_epoch, allocation_id),\n FOREIGN KEY (relying_party_id, parent_id, authority_head, authority_epoch)\n REFERENCES ep_authority_allocation_snapshots\n (relying_party_id, parent_id, authority_head, authority_epoch)\n);\nCREATE TABLE IF NOT EXISTS ep_authority_allocation_reservations (\n relying_party_id TEXT NOT NULL,\n parent_id TEXT NOT NULL,\n authority_head TEXT NOT NULL,\n authority_epoch BIGINT NOT NULL,\n allocation_id TEXT NOT NULL,\n reservation_id TEXT NOT NULL CHECK (octet_length(reservation_id) BETWEEN 1 AND 512),\n budget_cents BIGINT NOT NULL CHECK (budget_cents >= 0),\n budget_calls BIGINT NOT NULL CHECK (budget_calls >= 0),\n state TEXT NOT NULL CHECK (state IN ('reserved', 'committed', 'released')),\n owner_digest TEXT NOT NULL CHECK (owner_digest ~ '^sha256:[0-9a-f]{64}$'),\n fencing_token BIGINT NOT NULL CHECK (fencing_token > 0),\n reserved_at TIMESTAMPTZ NOT NULL DEFAULT transaction_timestamp(),\n finalized_at TIMESTAMPTZ NULL,\n PRIMARY KEY (relying_party_id, parent_id, reservation_id),\n UNIQUE (relying_party_id, parent_id, fencing_token),\n FOREIGN KEY (relying_party_id, parent_id, authority_head, authority_epoch, allocation_id)\n REFERENCES ep_authority_allocation_branches\n (relying_party_id, parent_id, authority_head, authority_epoch, allocation_id),\n CHECK (\n (state = 'reserved' AND finalized_at IS NULL)\n OR (state IN ('committed', 'released') AND finalized_at IS NOT NULL)\n )\n);\nREVOKE ALL ON ep_authority_allocation_snapshots FROM PUBLIC;\nREVOKE ALL ON ep_authority_allocation_current FROM PUBLIC;\nREVOKE ALL ON ep_authority_allocation_branches FROM PUBLIC;\nREVOKE ALL ON ep_authority_allocation_reservations FROM PUBLIC;";
|
|
173
|
+
/** Exact statements used by createPostgresAuthorityAllocationStore(). */
|
|
174
|
+
export declare const AUTHORITY_ALLOCATION_SQL: Readonly<{
|
|
175
|
+
lockParent: "SELECT pg_advisory_xact_lock(pg_catalog.hashtextextended(pg_catalog.jsonb_build_array($1::text, $2::text)::text, 0))";
|
|
176
|
+
readCurrent: "SELECT authority_head, authority_epoch, snapshot_fingerprint, next_fencing_token, clock_timestamp() AS database_now FROM ep_authority_allocation_current WHERE relying_party_id = $1 AND parent_id = $2 FOR UPDATE";
|
|
177
|
+
activeReservations: "SELECT count(*)::bigint AS active FROM ep_authority_allocation_reservations WHERE relying_party_id = $1 AND parent_id = $2 AND state = 'reserved'";
|
|
178
|
+
insertSnapshot: "INSERT INTO ep_authority_allocation_snapshots (relying_party_id, parent_id, authority_head, authority_epoch, snapshot_fingerprint, snapshot_json) VALUES ($1, $2, $3, $4, $5, $6::jsonb)";
|
|
179
|
+
insertBranch: "INSERT INTO ep_authority_allocation_branches (relying_party_id, parent_id, authority_head, authority_epoch, allocation_id, budget_cents, budget_calls, expires_at) VALUES ($1, $2, $3, $4, $5, $6, $7, $8::timestamptz)";
|
|
180
|
+
insertCurrent: "INSERT INTO ep_authority_allocation_current (relying_party_id, parent_id, authority_head, authority_epoch, snapshot_fingerprint) VALUES ($1, $2, $3, $4, $5)";
|
|
181
|
+
advanceCurrent: "UPDATE ep_authority_allocation_current SET authority_head = $3, authority_epoch = $4, snapshot_fingerprint = $5 WHERE relying_party_id = $1 AND parent_id = $2 AND authority_epoch < $4";
|
|
182
|
+
readSnapshot: "SELECT snapshot_json, snapshot_fingerprint FROM ep_authority_allocation_snapshots WHERE relying_party_id = $1 AND parent_id = $2 AND authority_head = $3 AND authority_epoch = $4";
|
|
183
|
+
readBranch: "SELECT budget_cents, budget_calls, expires_at FROM ep_authority_allocation_branches WHERE relying_party_id = $1 AND parent_id = $2 AND authority_head = $3 AND authority_epoch = $4 AND allocation_id = $5";
|
|
184
|
+
readReservation: "SELECT allocation_id, authority_head, authority_epoch, budget_cents, budget_calls, state, owner_digest, fencing_token FROM ep_authority_allocation_reservations WHERE relying_party_id = $1 AND parent_id = $2 AND reservation_id = $3";
|
|
185
|
+
readUsage: "SELECT allocation_id, state, COALESCE(sum(budget_cents), 0)::bigint AS cents, COALESCE(sum(budget_calls), 0)::bigint AS calls FROM ep_authority_allocation_reservations WHERE relying_party_id = $1 AND parent_id = $2 AND authority_head = $3 AND authority_epoch = $4 AND state IN ('reserved', 'committed') GROUP BY allocation_id, state";
|
|
186
|
+
nextFence: "UPDATE ep_authority_allocation_current SET next_fencing_token = next_fencing_token + 1 WHERE relying_party_id = $1 AND parent_id = $2 AND authority_head = $3 AND authority_epoch = $4 RETURNING next_fencing_token - 1 AS fencing_token";
|
|
187
|
+
insertReservation: "INSERT INTO ep_authority_allocation_reservations (relying_party_id, parent_id, authority_head, authority_epoch, allocation_id, reservation_id, budget_cents, budget_calls, state, owner_digest, fencing_token) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 'reserved', $9, $10)";
|
|
188
|
+
commitReservation: "UPDATE ep_authority_allocation_reservations SET state = 'committed', finalized_at = transaction_timestamp() WHERE relying_party_id = $1 AND parent_id = $2 AND reservation_id = $3 AND allocation_id = $4 AND authority_head = $5 AND authority_epoch = $6 AND state = 'reserved' AND owner_digest = $7 AND fencing_token = $8";
|
|
189
|
+
releaseReservation: "UPDATE ep_authority_allocation_reservations SET state = 'released', finalized_at = transaction_timestamp() WHERE relying_party_id = $1 AND parent_id = $2 AND reservation_id = $3 AND allocation_id = $4 AND authority_head = $5 AND authority_epoch = $6 AND state = 'reserved' AND owner_digest = $7 AND fencing_token = $8";
|
|
190
|
+
inspectReservations: "SELECT reservation_id, allocation_id, authority_head, authority_epoch, budget_cents, budget_calls, state, fencing_token FROM ep_authority_allocation_reservations WHERE relying_party_id = $1 AND parent_id = $2 ORDER BY fencing_token";
|
|
191
|
+
}>;
|
|
192
|
+
/**
|
|
193
|
+
* Durable adapter boundary for PostgreSQL. Atomicity depends on the supplied
|
|
194
|
+
* transaction callback actually using one PostgreSQL transaction; the adapter
|
|
195
|
+
* additionally takes a transaction-scoped advisory lock for every parent.
|
|
196
|
+
*/
|
|
197
|
+
export declare function createPostgresAuthorityAllocationStore(options: AuthorityAllocationPostgresOptions): AuthorityAllocationStore;
|
|
198
|
+
export declare function isDurableAuthorityAllocationStore(store: unknown): store is AuthorityAllocationStore;
|
|
199
|
+
export {};
|
|
200
|
+
//# sourceMappingURL=authority-allocation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authority-allocation.d.ts","sourceRoot":"","sources":["../src/authority-allocation.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;GAYG;AAIH,eAAO,MAAM,4BAA4B,+BAA+B,CAAC;AACzE,eAAO,MAAM,kCAAkC,oCAAoC,CAAC;AACpF,eAAO,MAAM,mCAAmC,sCAAsC,CAAC;AACvF,eAAO,MAAM,iCAAiC,qCAAqC,CAAC;AACpF,eAAO,MAAM,sCAAsC,yCAAyC,CAAC;AAS7F,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,yBAAyB;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7B,MAAM,EAAE,yBAAyB,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,OAAO,4BAA4B,CAAC;IAC7C,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7B,MAAM,EAAE,yBAAyB,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,EAAE,SAAS,yBAAyB,EAAE,CAAC;CAC3D;AAED,M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