@usagekit/store 0.1.0 → 0.3.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.
@@ -1,7 +1,7 @@
1
1
  import type { DispatchGrant } from "@usagekit/core";
2
2
  import type { UsageRow } from "@usagekit/core";
3
3
  import type { SettleResult, ReleaseResult } from "@usagekit/core";
4
- import type { AllowanceExceeded } from "@usagekit/core";
4
+ import type { AllowanceExceeded, BudgetAlertCrossed } from "@usagekit/core";
5
5
  import type { Budget, Operation, ReserveInput, OperationRef, Quantity } from "@usagekit/core";
6
6
  import type { Clock } from "../clock.js";
7
7
  export declare class InvalidInput extends Error {
@@ -12,7 +12,10 @@ export declare class InvalidInput extends Error {
12
12
  export declare const copy: <T>(value: T) => T;
13
13
  export declare function canonical(value: unknown): string;
14
14
  export declare const key: (namespace: string, id: string) => string;
15
+ /** Reserve identity: diagnostic ids and attribution tags are not semantic. */
15
16
  export declare function semantics(i: ReserveInput): string;
17
+ /** Sorted tags on the stored input, or an InvalidInput when the list breaks the tag rules. */
18
+ export declare function withNormalizedTags(i: ReserveInput): ReserveInput;
16
19
  export declare const maxMoneyUnits: bigint;
17
20
  export declare function validateQuantity(q: Quantity): void;
18
21
  export type State = {
@@ -28,6 +31,14 @@ export type State = {
28
31
  watermark: string;
29
32
  offset: number;
30
33
  }>;
34
+ /** Operation listing snapshots: membership and order fixed by the first page. */
35
+ operationCursors?: Map<string, {
36
+ query: string;
37
+ keys: string[];
38
+ asOf: string;
39
+ watermark: string;
40
+ offset: number;
41
+ }>;
31
42
  clock: Clock;
32
43
  budgets: Budget[];
33
44
  operations: Map<string, Operation>;
@@ -38,5 +49,9 @@ export type State = {
38
49
  }>;
39
50
  leaseKinds: Map<string, "lease" | "recovery">;
40
51
  warnings: Map<string, readonly AllowanceExceeded[]>;
52
+ /** Crossings each reserve reported, replayed verbatim. */
53
+ reserveAlerts: Map<string, readonly BudgetAlertCrossed[]>;
54
+ /** Recorded crossings keyed by namespace, budget id, epoch and threshold. */
55
+ alerts: Set<string>;
41
56
  };
42
57
  export declare function find(s: State, ref: OperationRef): Operation | null;
@@ -1,3 +1,4 @@
1
+ import { normalizeTags } from "@usagekit/core";
1
2
  export class InvalidInput extends Error {
2
3
  field;
3
4
  reason;
@@ -22,14 +23,26 @@ export function canonical(value) {
22
23
  return JSON.stringify(value) ?? "null";
23
24
  }
24
25
  export const key = (namespace, id) => canonical([namespace, id]);
26
+ /** Reserve identity: diagnostic ids and attribution tags are not semantic. */
25
27
  export function semantics(i) {
26
- const { correlationId: _, parentOperationId: __, ...rest } = i;
28
+ const { correlationId: _, parentOperationId: __, scope, ...rest } = i;
29
+ const { tags: ___, ...scopeIdentity } = scope;
27
30
  return canonical({
28
31
  ...rest,
32
+ scope: scopeIdentity,
29
33
  estimate: [...i.estimate].sort((a, b) => a.unit.localeCompare(b.unit)),
30
34
  platformPools: [...(i.platformPools ?? [])].sort(),
31
35
  });
32
36
  }
37
+ /** Sorted tags on the stored input, or an InvalidInput when the list breaks the tag rules. */
38
+ export function withNormalizedTags(i) {
39
+ if (i.scope.tags === undefined)
40
+ return i;
41
+ const tags = normalizeTags(i.scope.tags);
42
+ if (!tags)
43
+ throw new InvalidInput("scope.tags", "1 to 16 unique tags matching the tag pattern");
44
+ return { ...i, scope: { ...i.scope, tags } };
45
+ }
33
46
  export const maxMoneyUnits = 2n ** 63n - 1n;
34
47
  export function validateQuantity(q) {
35
48
  if (typeof q.value !== "bigint" ||
@@ -1,6 +1,6 @@
1
1
  /** Synchronous reference rules shared by adapters inside their own atomic transactions. */
2
2
  export { reserve, intent, renew, claim, settle, release, expireReservations, } from "./memory/commands.js";
3
- export { aggregate, definedBudgets, applicableBudgets } from "./memory/reads.js";
3
+ export { aggregate, definedBudgets, applicableBudgets, listOperations } from "./memory/reads.js";
4
4
  export { copy, find, key, canonical, InvalidInput } from "./memory/state.js";
5
5
  export type { State } from "./memory/state.js";
6
- export { plus, effective, currentBudgets } from "./memory/admission.js";
6
+ export { plus, effective, currentBudgets, validateBudget, crossing, reachedAlerts, alertKey, alertThreshold, } from "./memory/admission.js";
package/dist/reference.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Synchronous reference rules shared by adapters inside their own atomic transactions. */
2
2
  export { reserve, intent, renew, claim, settle, release, expireReservations, } from "./memory/commands.js";
3
- export { aggregate, definedBudgets, applicableBudgets } from "./memory/reads.js";
3
+ export { aggregate, definedBudgets, applicableBudgets, listOperations } from "./memory/reads.js";
4
4
  export { copy, find, key, canonical, InvalidInput } from "./memory/state.js";
5
- export { plus, effective, currentBudgets } from "./memory/admission.js";
5
+ export { plus, effective, currentBudgets, validateBudget, crossing, reachedAlerts, alertKey, alertThreshold, } from "./memory/admission.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usagekit/store",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Atomic store commands, reference store and conformance tests.",
@@ -31,7 +31,7 @@
31
31
  "prepack": "node ../../scripts/package-license.mjs"
32
32
  },
33
33
  "dependencies": {
34
- "@usagekit/core": "0.1.0"
34
+ "@usagekit/core": "0.3.0"
35
35
  },
36
36
  "sideEffects": false,
37
37
  "publishConfig": {