@sazume/core 0.0.0-stage → 0.1.0-rc.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 W3BGHOST
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,47 @@
1
- # Temporary Holding Version
1
+ # @sazume/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Economic reliability primitives for programmable-money applications.
4
+
5
+ `@sazume/core` provides `EconomicIntent`, the `EconomicAdapter` boundary, reusable invariants, deterministic scenarios, the runner, and structured outcomes. The package evaluates observed application state; an adapter does not choose its own verdict.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @sazume/core@next
11
+ ```
12
+
13
+ ## Define an economic intent
14
+
15
+ ```ts
16
+ import {
17
+ defineIntent,
18
+ settlementUniqueness,
19
+ recipientAmount,
20
+ fulfillmentUniqueness,
21
+ completionConsistency,
22
+ } from "@sazume/core";
23
+
24
+ const intent = defineIntent({
25
+ id: "ORDER-42",
26
+ payment: {
27
+ payer: "customer",
28
+ recipient: "merchant",
29
+ asset: { symbol: "USDC", decimals: 6 },
30
+ amount: 10_000n,
31
+ },
32
+ invariants: [
33
+ settlementUniqueness(),
34
+ recipientAmount(),
35
+ fulfillmentUniqueness(),
36
+ completionConsistency(),
37
+ ],
38
+ });
39
+ ```
40
+
41
+ Implement `EconomicAdapter` for the application state you need Sazume to observe, then pass it and scenarios to `sazume.run`. Amounts use integer base units (`bigint`); never use floating point for monetary values.
42
+
43
+ See the [integration guide](https://sazume.vercel.app/docs/integration) for a complete adapter example.
44
+
45
+ ## License
46
+
47
+ MIT. See [LICENSE](./LICENSE).
@@ -0,0 +1,9 @@
1
+ import type { EconomicIntent } from "./intent.js";
2
+ import type { EconomicOutcome, FulfillmentResult, SettlementResult } from "./outcome.js";
3
+ export interface EconomicAdapter {
4
+ settle(intent: EconomicIntent): Promise<SettlementResult>;
5
+ fulfill(intent: EconomicIntent): Promise<FulfillmentResult>;
6
+ markComplete(intent: EconomicIntent): Promise<void>;
7
+ observe(intent: EconomicIntent): Promise<EconomicOutcome>;
8
+ reset(): Promise<void>;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ export * from "./adapter.js";
2
+ export * from "./intent.js";
3
+ export * from "./invariant.js";
4
+ export * from "./outcome.js";
5
+ export * from "./reporter.js";
6
+ export * from "./runner.js";
7
+ export * from "./scenario.js";
8
+ export * from "./trace.js";
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./adapter.js"), exports);
18
+ __exportStar(require("./intent.js"), exports);
19
+ __exportStar(require("./invariant.js"), exports);
20
+ __exportStar(require("./outcome.js"), exports);
21
+ __exportStar(require("./reporter.js"), exports);
22
+ __exportStar(require("./runner.js"), exports);
23
+ __exportStar(require("./scenario.js"), exports);
24
+ __exportStar(require("./trace.js"), exports);
@@ -0,0 +1,18 @@
1
+ import type { EconomicInvariant } from "./invariant.js";
2
+ export interface EconomicIntent {
3
+ id: string;
4
+ intentId: string;
5
+ payment: {
6
+ payer: string;
7
+ recipient: string;
8
+ asset: {
9
+ symbol: "USDC";
10
+ decimals: 6;
11
+ };
12
+ amount: bigint;
13
+ };
14
+ invariants: EconomicInvariant[];
15
+ }
16
+ type IntentInput = Omit<EconomicIntent, "intentId">;
17
+ export declare function defineIntent(input: IntentInput): EconomicIntent;
18
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineIntent = defineIntent;
4
+ const node_crypto_1 = require("node:crypto");
5
+ function defineIntent(input) {
6
+ if (input.payment.amount <= 0n)
7
+ throw new Error("Intent amount must be positive");
8
+ if (!input.id.trim())
9
+ throw new Error("Intent ID must not be empty");
10
+ const intentId = (0, node_crypto_1.createHash)("sha256").update(`sazume:intent:v1:${input.id}`).digest("hex");
11
+ return { ...input, intentId };
12
+ }
@@ -0,0 +1,17 @@
1
+ import type { EconomicIntent } from "./intent.js";
2
+ import type { EconomicOutcome } from "./outcome.js";
3
+ export interface InvariantResult {
4
+ name: string;
5
+ passed: boolean;
6
+ expected: string;
7
+ observed: string;
8
+ message?: string;
9
+ }
10
+ export interface EconomicInvariant {
11
+ name: string;
12
+ evaluate(intent: EconomicIntent, outcome: EconomicOutcome): InvariantResult;
13
+ }
14
+ export declare const settlementUniqueness: () => EconomicInvariant;
15
+ export declare const recipientAmount: () => EconomicInvariant;
16
+ export declare const fulfillmentUniqueness: () => EconomicInvariant;
17
+ export declare const completionConsistency: () => EconomicInvariant;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.completionConsistency = exports.fulfillmentUniqueness = exports.recipientAmount = exports.settlementUniqueness = void 0;
4
+ function invariant(name, evaluate) {
5
+ return { name, evaluate: (intent, outcome) => ({ name, ...evaluate(intent, outcome) }) };
6
+ }
7
+ const settlementUniqueness = () => invariant("Settlement uniqueness", (_intent, outcome) => ({
8
+ passed: outcome.settlement.count <= 1,
9
+ expected: "<= 1",
10
+ observed: String(outcome.settlement.count),
11
+ message: outcome.settlement.count > 1 ? "One economic intent produced multiple settlements." : undefined,
12
+ }));
13
+ exports.settlementUniqueness = settlementUniqueness;
14
+ const recipientAmount = () => invariant("Recipient amount", (intent, outcome) => {
15
+ const applicable = outcome.completed;
16
+ const passed = !applicable || outcome.settlement.totalAmount === intent.payment.amount;
17
+ return {
18
+ passed,
19
+ expected: `${(intent.payment.amount / 1000000n).toString()}.${(intent.payment.amount % 1000000n).toString().padStart(6, "0")} USDC`,
20
+ observed: `${outcome.settlement.totalAmount} base units`,
21
+ message: applicable && !passed ? "Completed intent did not deliver exactly the intended amount." : undefined,
22
+ };
23
+ });
24
+ exports.recipientAmount = recipientAmount;
25
+ const fulfillmentUniqueness = () => invariant("Fulfillment uniqueness", (_intent, outcome) => ({
26
+ passed: outcome.fulfillment.count <= 1,
27
+ expected: "<= 1",
28
+ observed: String(outcome.fulfillment.count),
29
+ message: outcome.fulfillment.count > 1 ? "One economic intent produced multiple fulfillments." : undefined,
30
+ }));
31
+ exports.fulfillmentUniqueness = fulfillmentUniqueness;
32
+ const completionConsistency = () => invariant("Completion consistency", (_intent, outcome) => {
33
+ const passed = !outcome.completed || (outcome.settlement.count > 0 && outcome.fulfillment.count > 0);
34
+ return {
35
+ passed,
36
+ expected: "completed implies settlement and fulfillment",
37
+ observed: `completed=${outcome.completed}, settlements=${outcome.settlement.count}, fulfillments=${outcome.fulfillment.count}`,
38
+ message: !passed ? "Workflow claimed completion without settlement and fulfillment." : undefined,
39
+ };
40
+ });
41
+ exports.completionConsistency = completionConsistency;
@@ -0,0 +1,18 @@
1
+ export interface EconomicOutcome {
2
+ intentId: string;
3
+ settlement: {
4
+ count: number;
5
+ totalAmount: bigint;
6
+ };
7
+ fulfillment: {
8
+ count: number;
9
+ };
10
+ completed: boolean;
11
+ }
12
+ export interface SettlementResult {
13
+ accepted: boolean;
14
+ amount: bigint;
15
+ }
16
+ export interface FulfillmentResult {
17
+ accepted: boolean;
18
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,2 @@
1
+ import type { SazumeRunResult } from "./runner.js";
2
+ export declare function report(result: SazumeRunResult, label: string): string;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.report = report;
4
+ function formatAmount(amount) {
5
+ const whole = amount / 1000000n;
6
+ const fraction = (amount % 1000000n).toString().padStart(6, "0");
7
+ return `${whole}.${fraction} USDC`;
8
+ }
9
+ function report(result, label) {
10
+ const lines = ["SAZUME", `Economic Reliability Test — ${label}`, "────────────────────────────────", ""];
11
+ if (label.toUpperCase() === "UNSAFE") {
12
+ lines.push(`Intent ${result.intent.id}`, `Expected ${formatAmount(result.intent.payment.amount)}`, "");
13
+ }
14
+ for (const scenario of result.scenarios) {
15
+ lines.push(`${scenario.passed ? "✓" : "✕"} ${scenario.scenario}`);
16
+ if (!scenario.passed) {
17
+ lines.push("", "ECONOMIC INVARIANT VIOLATION");
18
+ for (const item of scenario.invariants.filter((invariant) => !invariant.passed)) {
19
+ lines.push("", item.name, ` expected ${item.expected}`, ` observed ${item.name === "Recipient amount" ? formatAmount(scenario.outcome.settlement.totalAmount) : item.observed}`);
20
+ }
21
+ lines.push("", "TRACE");
22
+ for (const entry of scenario.trace)
23
+ lines.push(` ${String(entry.sequence).padStart(2, "0")} ${entry.type}`);
24
+ }
25
+ }
26
+ const passed = result.scenarios.filter((scenario) => scenario.passed).length;
27
+ const failed = result.scenarios.length - passed;
28
+ lines.push("", "────────────────────────────────", `${passed} passed`, `${failed} failed`, "", result.passed ? "ECONOMIC INTENT PRESERVED" : "ECONOMIC INTENT NOT PRESERVED");
29
+ return lines.join("\n");
30
+ }
@@ -0,0 +1,25 @@
1
+ import type { EconomicAdapter } from "./adapter.js";
2
+ import type { EconomicIntent } from "./intent.js";
3
+ import type { InvariantResult } from "./invariant.js";
4
+ import type { EconomicOutcome } from "./outcome.js";
5
+ import type { Scenario } from "./scenario.js";
6
+ import { type TraceEntry } from "./trace.js";
7
+ export interface ScenarioResult {
8
+ scenario: string;
9
+ outcome: EconomicOutcome;
10
+ invariants: InvariantResult[];
11
+ trace: TraceEntry[];
12
+ passed: boolean;
13
+ }
14
+ export interface SazumeRunResult {
15
+ intent: EconomicIntent;
16
+ scenarios: ScenarioResult[];
17
+ passed: boolean;
18
+ }
19
+ export declare const sazume: {
20
+ run(input: {
21
+ intent: EconomicIntent;
22
+ adapter: EconomicAdapter;
23
+ scenarios: Scenario[];
24
+ }): Promise<SazumeRunResult>;
25
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sazume = void 0;
4
+ const trace_js_1 = require("./trace.js");
5
+ exports.sazume = {
6
+ async run(input) {
7
+ const scenarios = [];
8
+ for (const scenario of input.scenarios) {
9
+ await input.adapter.reset();
10
+ const trace = new trace_js_1.ScenarioTrace();
11
+ await scenario.run({ intent: input.intent, adapter: input.adapter, trace });
12
+ const outcome = await input.adapter.observe(input.intent);
13
+ const invariants = input.intent.invariants.map((item) => item.evaluate(input.intent, outcome));
14
+ scenarios.push({ scenario: scenario.name, outcome, invariants, trace: trace.entries, passed: invariants.every((item) => item.passed) });
15
+ }
16
+ return { intent: input.intent, scenarios, passed: scenarios.every((scenario) => scenario.passed) };
17
+ },
18
+ };
@@ -0,0 +1,12 @@
1
+ import type { EconomicAdapter } from "./adapter.js";
2
+ import type { EconomicIntent } from "./intent.js";
3
+ import { ScenarioTrace } from "./trace.js";
4
+ export interface ScenarioContext {
5
+ intent: EconomicIntent;
6
+ adapter: EconomicAdapter;
7
+ trace: ScenarioTrace;
8
+ }
9
+ export interface Scenario {
10
+ name: string;
11
+ run(context: ScenarioContext): Promise<void>;
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ export type TraceType = "settlement-attempt" | "settlement-observed" | "fulfillment-attempt" | "fulfillment-observed" | "timeout" | "retry" | "callback";
2
+ export interface TraceEntry {
3
+ sequence: number;
4
+ type: TraceType;
5
+ intentId: string;
6
+ metadata?: Record<string, string | number | boolean>;
7
+ }
8
+ export declare class ScenarioTrace {
9
+ readonly entries: TraceEntry[];
10
+ add(type: TraceType, intentId: string, metadata?: TraceEntry["metadata"]): void;
11
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScenarioTrace = void 0;
4
+ class ScenarioTrace {
5
+ entries = [];
6
+ add(type, intentId, metadata) {
7
+ this.entries.push({ sequence: this.entries.length + 1, type, intentId, ...(metadata ? { metadata } : {}) });
8
+ }
9
+ }
10
+ exports.ScenarioTrace = ScenarioTrace;
@@ -0,0 +1,9 @@
1
+ import type { EconomicIntent } from "./intent.js";
2
+ import type { EconomicOutcome, FulfillmentResult, SettlementResult } from "./outcome.js";
3
+ export interface EconomicAdapter {
4
+ settle(intent: EconomicIntent): Promise<SettlementResult>;
5
+ fulfill(intent: EconomicIntent): Promise<FulfillmentResult>;
6
+ markComplete(intent: EconomicIntent): Promise<void>;
7
+ observe(intent: EconomicIntent): Promise<EconomicOutcome>;
8
+ reset(): Promise<void>;
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export * from "./adapter.js";
2
+ export * from "./intent.js";
3
+ export * from "./invariant.js";
4
+ export * from "./outcome.js";
5
+ export * from "./reporter.js";
6
+ export * from "./runner.js";
7
+ export * from "./scenario.js";
8
+ export * from "./trace.js";
@@ -0,0 +1,8 @@
1
+ export * from "./adapter.js";
2
+ export * from "./intent.js";
3
+ export * from "./invariant.js";
4
+ export * from "./outcome.js";
5
+ export * from "./reporter.js";
6
+ export * from "./runner.js";
7
+ export * from "./scenario.js";
8
+ export * from "./trace.js";
@@ -0,0 +1,18 @@
1
+ import type { EconomicInvariant } from "./invariant.js";
2
+ export interface EconomicIntent {
3
+ id: string;
4
+ intentId: string;
5
+ payment: {
6
+ payer: string;
7
+ recipient: string;
8
+ asset: {
9
+ symbol: "USDC";
10
+ decimals: 6;
11
+ };
12
+ amount: bigint;
13
+ };
14
+ invariants: EconomicInvariant[];
15
+ }
16
+ type IntentInput = Omit<EconomicIntent, "intentId">;
17
+ export declare function defineIntent(input: IntentInput): EconomicIntent;
18
+ export {};
@@ -0,0 +1,9 @@
1
+ import { createHash } from "node:crypto";
2
+ export function defineIntent(input) {
3
+ if (input.payment.amount <= 0n)
4
+ throw new Error("Intent amount must be positive");
5
+ if (!input.id.trim())
6
+ throw new Error("Intent ID must not be empty");
7
+ const intentId = createHash("sha256").update(`sazume:intent:v1:${input.id}`).digest("hex");
8
+ return { ...input, intentId };
9
+ }
@@ -0,0 +1,17 @@
1
+ import type { EconomicIntent } from "./intent.js";
2
+ import type { EconomicOutcome } from "./outcome.js";
3
+ export interface InvariantResult {
4
+ name: string;
5
+ passed: boolean;
6
+ expected: string;
7
+ observed: string;
8
+ message?: string;
9
+ }
10
+ export interface EconomicInvariant {
11
+ name: string;
12
+ evaluate(intent: EconomicIntent, outcome: EconomicOutcome): InvariantResult;
13
+ }
14
+ export declare const settlementUniqueness: () => EconomicInvariant;
15
+ export declare const recipientAmount: () => EconomicInvariant;
16
+ export declare const fulfillmentUniqueness: () => EconomicInvariant;
17
+ export declare const completionConsistency: () => EconomicInvariant;
@@ -0,0 +1,34 @@
1
+ function invariant(name, evaluate) {
2
+ return { name, evaluate: (intent, outcome) => ({ name, ...evaluate(intent, outcome) }) };
3
+ }
4
+ export const settlementUniqueness = () => invariant("Settlement uniqueness", (_intent, outcome) => ({
5
+ passed: outcome.settlement.count <= 1,
6
+ expected: "<= 1",
7
+ observed: String(outcome.settlement.count),
8
+ message: outcome.settlement.count > 1 ? "One economic intent produced multiple settlements." : undefined,
9
+ }));
10
+ export const recipientAmount = () => invariant("Recipient amount", (intent, outcome) => {
11
+ const applicable = outcome.completed;
12
+ const passed = !applicable || outcome.settlement.totalAmount === intent.payment.amount;
13
+ return {
14
+ passed,
15
+ expected: `${(intent.payment.amount / 1000000n).toString()}.${(intent.payment.amount % 1000000n).toString().padStart(6, "0")} USDC`,
16
+ observed: `${outcome.settlement.totalAmount} base units`,
17
+ message: applicable && !passed ? "Completed intent did not deliver exactly the intended amount." : undefined,
18
+ };
19
+ });
20
+ export const fulfillmentUniqueness = () => invariant("Fulfillment uniqueness", (_intent, outcome) => ({
21
+ passed: outcome.fulfillment.count <= 1,
22
+ expected: "<= 1",
23
+ observed: String(outcome.fulfillment.count),
24
+ message: outcome.fulfillment.count > 1 ? "One economic intent produced multiple fulfillments." : undefined,
25
+ }));
26
+ export const completionConsistency = () => invariant("Completion consistency", (_intent, outcome) => {
27
+ const passed = !outcome.completed || (outcome.settlement.count > 0 && outcome.fulfillment.count > 0);
28
+ return {
29
+ passed,
30
+ expected: "completed implies settlement and fulfillment",
31
+ observed: `completed=${outcome.completed}, settlements=${outcome.settlement.count}, fulfillments=${outcome.fulfillment.count}`,
32
+ message: !passed ? "Workflow claimed completion without settlement and fulfillment." : undefined,
33
+ };
34
+ });
@@ -0,0 +1,18 @@
1
+ export interface EconomicOutcome {
2
+ intentId: string;
3
+ settlement: {
4
+ count: number;
5
+ totalAmount: bigint;
6
+ };
7
+ fulfillment: {
8
+ count: number;
9
+ };
10
+ completed: boolean;
11
+ }
12
+ export interface SettlementResult {
13
+ accepted: boolean;
14
+ amount: bigint;
15
+ }
16
+ export interface FulfillmentResult {
17
+ accepted: boolean;
18
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { SazumeRunResult } from "./runner.js";
2
+ export declare function report(result: SazumeRunResult, label: string): string;
@@ -0,0 +1,27 @@
1
+ function formatAmount(amount) {
2
+ const whole = amount / 1000000n;
3
+ const fraction = (amount % 1000000n).toString().padStart(6, "0");
4
+ return `${whole}.${fraction} USDC`;
5
+ }
6
+ export function report(result, label) {
7
+ const lines = ["SAZUME", `Economic Reliability Test — ${label}`, "────────────────────────────────", ""];
8
+ if (label.toUpperCase() === "UNSAFE") {
9
+ lines.push(`Intent ${result.intent.id}`, `Expected ${formatAmount(result.intent.payment.amount)}`, "");
10
+ }
11
+ for (const scenario of result.scenarios) {
12
+ lines.push(`${scenario.passed ? "✓" : "✕"} ${scenario.scenario}`);
13
+ if (!scenario.passed) {
14
+ lines.push("", "ECONOMIC INVARIANT VIOLATION");
15
+ for (const item of scenario.invariants.filter((invariant) => !invariant.passed)) {
16
+ lines.push("", item.name, ` expected ${item.expected}`, ` observed ${item.name === "Recipient amount" ? formatAmount(scenario.outcome.settlement.totalAmount) : item.observed}`);
17
+ }
18
+ lines.push("", "TRACE");
19
+ for (const entry of scenario.trace)
20
+ lines.push(` ${String(entry.sequence).padStart(2, "0")} ${entry.type}`);
21
+ }
22
+ }
23
+ const passed = result.scenarios.filter((scenario) => scenario.passed).length;
24
+ const failed = result.scenarios.length - passed;
25
+ lines.push("", "────────────────────────────────", `${passed} passed`, `${failed} failed`, "", result.passed ? "ECONOMIC INTENT PRESERVED" : "ECONOMIC INTENT NOT PRESERVED");
26
+ return lines.join("\n");
27
+ }
@@ -0,0 +1,25 @@
1
+ import type { EconomicAdapter } from "./adapter.js";
2
+ import type { EconomicIntent } from "./intent.js";
3
+ import type { InvariantResult } from "./invariant.js";
4
+ import type { EconomicOutcome } from "./outcome.js";
5
+ import type { Scenario } from "./scenario.js";
6
+ import { type TraceEntry } from "./trace.js";
7
+ export interface ScenarioResult {
8
+ scenario: string;
9
+ outcome: EconomicOutcome;
10
+ invariants: InvariantResult[];
11
+ trace: TraceEntry[];
12
+ passed: boolean;
13
+ }
14
+ export interface SazumeRunResult {
15
+ intent: EconomicIntent;
16
+ scenarios: ScenarioResult[];
17
+ passed: boolean;
18
+ }
19
+ export declare const sazume: {
20
+ run(input: {
21
+ intent: EconomicIntent;
22
+ adapter: EconomicAdapter;
23
+ scenarios: Scenario[];
24
+ }): Promise<SazumeRunResult>;
25
+ };
@@ -0,0 +1,15 @@
1
+ import { ScenarioTrace } from "./trace.js";
2
+ export const sazume = {
3
+ async run(input) {
4
+ const scenarios = [];
5
+ for (const scenario of input.scenarios) {
6
+ await input.adapter.reset();
7
+ const trace = new ScenarioTrace();
8
+ await scenario.run({ intent: input.intent, adapter: input.adapter, trace });
9
+ const outcome = await input.adapter.observe(input.intent);
10
+ const invariants = input.intent.invariants.map((item) => item.evaluate(input.intent, outcome));
11
+ scenarios.push({ scenario: scenario.name, outcome, invariants, trace: trace.entries, passed: invariants.every((item) => item.passed) });
12
+ }
13
+ return { intent: input.intent, scenarios, passed: scenarios.every((scenario) => scenario.passed) };
14
+ },
15
+ };
@@ -0,0 +1,12 @@
1
+ import type { EconomicAdapter } from "./adapter.js";
2
+ import type { EconomicIntent } from "./intent.js";
3
+ import { ScenarioTrace } from "./trace.js";
4
+ export interface ScenarioContext {
5
+ intent: EconomicIntent;
6
+ adapter: EconomicAdapter;
7
+ trace: ScenarioTrace;
8
+ }
9
+ export interface Scenario {
10
+ name: string;
11
+ run(context: ScenarioContext): Promise<void>;
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ export type TraceType = "settlement-attempt" | "settlement-observed" | "fulfillment-attempt" | "fulfillment-observed" | "timeout" | "retry" | "callback";
2
+ export interface TraceEntry {
3
+ sequence: number;
4
+ type: TraceType;
5
+ intentId: string;
6
+ metadata?: Record<string, string | number | boolean>;
7
+ }
8
+ export declare class ScenarioTrace {
9
+ readonly entries: TraceEntry[];
10
+ add(type: TraceType, intentId: string, metadata?: TraceEntry["metadata"]): void;
11
+ }
@@ -0,0 +1,6 @@
1
+ export class ScenarioTrace {
2
+ entries = [];
3
+ add(type, intentId, metadata) {
4
+ this.entries.push({ sequence: this.entries.length + 1, type, intentId, ...(metadata ? { metadata } : {}) });
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@sazume/core",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-rc.1",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "description": "Economic intent, scenario, adapter, observation and invariant primitives for Sazume.",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Webghost01-NG/sazume.git",
10
+ "directory": "packages/core"
11
+ },
12
+ "homepage": "https://sazume.vercel.app/docs",
13
+ "keywords": ["economic reliability", "payments", "invariants", "testing"],
14
+ "publishConfig": {
15
+ "access": "public",
16
+ "tag": "next",
17
+ "registry": "https://registry.npmjs.org/"
18
+ },
19
+ "engines": {
20
+ "node": ">=20.19.0"
21
+ },
22
+ "files": ["dist", "README.md", "LICENSE"],
23
+ "sideEffects": false,
24
+ "types": "./dist/esm/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "import": {
28
+ "types": "./dist/esm/index.d.ts",
29
+ "default": "./dist/esm/index.js"
30
+ },
31
+ "require": {
32
+ "types": "./dist/cjs/index.d.ts",
33
+ "default": "./dist/cjs/index.js"
34
+ }
35
+ }
36
+ },
37
+ "scripts": {
38
+ "build:esm": "tsc -p tsconfig.esm.json",
39
+ "build:cjs": "tsc -p tsconfig.cjs.json && node scripts/mark-cjs.mjs",
40
+ "build": "npm run build:esm && npm run build:cjs",
41
+ "prepack": "npm run build"
42
+ }
43
+ }