@party-stack/ontology-backend 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +148 -2
- package/lib/actions.d.ts +47 -0
- package/lib/actions.d.ts.map +1 -0
- package/lib/actions.js +306 -0
- package/lib/actions.js.map +1 -0
- package/lib/clients.d.ts +236 -0
- package/lib/clients.d.ts.map +1 -0
- package/lib/clients.js +211 -0
- package/lib/clients.js.map +1 -0
- package/lib/delivery.d.ts +746 -0
- package/lib/delivery.d.ts.map +1 -0
- package/lib/delivery.js +863 -0
- package/lib/delivery.js.map +1 -0
- package/lib/description.d.ts +29 -0
- package/lib/description.d.ts.map +1 -0
- package/lib/description.js +28 -0
- package/lib/description.js.map +1 -0
- package/lib/encrypted.d.ts +41 -0
- package/lib/encrypted.d.ts.map +1 -0
- package/lib/encrypted.js +111 -0
- package/lib/encrypted.js.map +1 -0
- package/lib/errors.d.ts +106 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +275 -0
- package/lib/errors.js.map +1 -0
- package/lib/fulfillment.d.ts +25 -0
- package/lib/fulfillment.d.ts.map +1 -0
- package/lib/fulfillment.js +99 -0
- package/lib/fulfillment.js.map +1 -0
- package/lib/index.d.ts +297 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +91 -0
- package/lib/index.js.map +1 -0
- package/lib/maintenance.d.ts +11 -0
- package/lib/maintenance.d.ts.map +1 -0
- package/lib/maintenance.js +24 -0
- package/lib/maintenance.js.map +1 -0
- package/lib/meta.d.ts +26 -0
- package/lib/meta.d.ts.map +1 -0
- package/lib/meta.js +213 -0
- package/lib/meta.js.map +1 -0
- package/lib/owned.d.ts +74 -0
- package/lib/owned.d.ts.map +1 -0
- package/lib/owned.js +593 -0
- package/lib/owned.js.map +1 -0
- package/lib/policy/indexes.d.ts +12 -0
- package/lib/policy/indexes.d.ts.map +1 -0
- package/lib/policy/indexes.js +113 -0
- package/lib/policy/indexes.js.map +1 -0
- package/lib/policy/planner.d.ts +10 -0
- package/lib/policy/planner.d.ts.map +1 -0
- package/lib/policy/planner.js +118 -0
- package/lib/policy/planner.js.map +1 -0
- package/lib/policy/view.d.ts +31 -0
- package/lib/policy/view.d.ts.map +1 -0
- package/lib/policy/view.js +173 -0
- package/lib/policy/view.js.map +1 -0
- package/lib/policy.d.ts +47 -0
- package/lib/policy.d.ts.map +1 -0
- package/lib/policy.js +100 -0
- package/lib/policy.js.map +1 -0
- package/lib/protocol.d.ts +570 -0
- package/lib/protocol.d.ts.map +1 -0
- package/lib/protocol.js +144 -0
- package/lib/protocol.js.map +1 -0
- package/lib/query.d.ts +33 -0
- package/lib/query.d.ts.map +1 -0
- package/lib/query.js +51 -0
- package/lib/query.js.map +1 -0
- package/lib/references.d.ts +8 -0
- package/lib/references.d.ts.map +1 -0
- package/lib/references.js +41 -0
- package/lib/references.js.map +1 -0
- package/lib/storage.d.ts +55 -0
- package/lib/storage.d.ts.map +1 -0
- package/lib/storage.js +168 -0
- package/lib/storage.js.map +1 -0
- package/lib/subset.d.ts +19 -0
- package/lib/subset.d.ts.map +1 -0
- package/lib/subset.js +150 -0
- package/lib/subset.js.map +1 -0
- package/lib/subsetSchema.d.ts +10 -0
- package/lib/subsetSchema.d.ts.map +1 -0
- package/lib/subsetSchema.js +20 -0
- package/lib/subsetSchema.js.map +1 -0
- package/package.json +72 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Robert Fidler
|
|
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,149 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @party-stack/ontology-backend
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Effect-native backend contracts, normalized errors and authoritative execution.
|
|
4
|
+
Adapters depend on this package for subset snapshots, action receipts, validation,
|
|
5
|
+
attachment/decrypt capabilities and optional journal/watch interfaces.
|
|
6
|
+
|
|
7
|
+
`/actions` owns portable IR action execution and parameter defaults. `executeAction`
|
|
8
|
+
reads and writes only its supplied transaction; callers own commit/rollback and
|
|
9
|
+
journaling. Replica replay and authoritative execution share it. Native custom
|
|
10
|
+
mutators receive an `ActionTransaction` with point/subset reads, writes and finite
|
|
11
|
+
QueryDocument execution. The `ontology` package separately adapts Promise/TanStack
|
|
12
|
+
mutators into this Effect-native contract.
|
|
13
|
+
|
|
14
|
+
`/subset` lowers object-bound spec subsets to provider/storage candidates. Replica
|
|
15
|
+
demand uses spec expressions; physical scans remain below that public boundary.
|
|
16
|
+
Exactness is required: unsupported demand computations return NotImplemented.
|
|
17
|
+
|
|
18
|
+
## Native adapter and operation identity
|
|
19
|
+
|
|
20
|
+
An adapter's scoped open(context) returns one OntologyBackendService. Validation,
|
|
21
|
+
attachment IO and other capabilities live on that service, not parallel Promise
|
|
22
|
+
hooks on the adapter. Scope owns cleanup. Source signatures use Effect.Effect and
|
|
23
|
+
Stream.Stream directly; there are no Run/Events aliases.
|
|
24
|
+
|
|
25
|
+
The execution hook is applyAction(ActionRequest), also named ApplyAction on RPC.
|
|
26
|
+
The caller's idempotencyKey is the stable ActionRequest.id. The returned receipt's
|
|
27
|
+
operationId identifies that same submission across retries. It is not the action
|
|
28
|
+
type's name. providerOperationId is optional upstream metadata, such as Foundry's
|
|
29
|
+
own execution identifier, and is not used for local retry identity or settlement.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
interface ActionReceipt {
|
|
33
|
+
operationId: string;
|
|
34
|
+
providerOperationId?: string;
|
|
35
|
+
outcome: "committed";
|
|
36
|
+
cursor?: string;
|
|
37
|
+
// Read-back targets and attachment ID mappings are additional receipt fields.
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Action uploads contain only locally staged bytes. Reusing an existing remote handle
|
|
42
|
+
does not cause a download/re-upload. Provider applyAction owns its upload/encoding
|
|
43
|
+
pipeline and returns canonical ID mappings with the successful receipt. Those
|
|
44
|
+
mappings are not installed ahead of the receipt. Explicit eager staging uses the
|
|
45
|
+
native attachments.stage capability, where available.
|
|
46
|
+
|
|
47
|
+
`loadSubset` reads snapshots. `watchSubset` acquires invalidation notifications;
|
|
48
|
+
`changes.pull` reads the source-wide journal and `changes.watch` acquires its wake-up feed.
|
|
49
|
+
Both watch acquisitions are scoped Effects: they return only after the feed is
|
|
50
|
+
registered and buffering, even if the returned stream stays quiet indefinitely.
|
|
51
|
+
Closing the acquisition Scope releases the subscription.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
// Inside the caller's Scope; undefined means this subset needs polling.
|
|
55
|
+
const acquire = backend.watchSubset?.(subset);
|
|
56
|
+
if (acquire) {
|
|
57
|
+
const changes = yield * acquire;
|
|
58
|
+
const snapshot = yield * backend.loadSubset(subset);
|
|
59
|
+
// Process the snapshot, then consume changes to refresh it.
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Changes between acquisition and snapshot consumption remain observable. Merely
|
|
64
|
+
returning a lazy `Stream.fromPubSub` inside `Effect.succeed` does not establish this
|
|
65
|
+
guarantee: acquire its subscription first. Parent acceptance is a separate replica
|
|
66
|
+
handoff operation; an ordinary action receipt reports authoritative commitment.
|
|
67
|
+
A future
|
|
68
|
+
query-scoped data subscription is deferred; see the
|
|
69
|
+
[subscription design note](../../specs/2026-10-19-effect-tables-replica/subset-subscriptions.md).
|
|
70
|
+
|
|
71
|
+
## Failures and validation
|
|
72
|
+
|
|
73
|
+
`BackendError` is a Schema.TaggedError with a `kind` discriminator. Operation failures
|
|
74
|
+
include Unauthenticated, Forbidden, NotFound, ValidationFailed, Conflict,
|
|
75
|
+
NotImplemented, RateLimited, Unavailable and Internal. Recovery failures separately
|
|
76
|
+
identify HistoryExpired, SessionExpired, SessionReplaced, ViewReplaced, ResultExpired,
|
|
77
|
+
SourceMismatch and SchemaMismatch. Source/schema changes require explicit reset or
|
|
78
|
+
migration; a transient transport reconnect does not replace the runtime or outbox.
|
|
79
|
+
|
|
80
|
+
`retryable` controls automatic retry scheduling. `actionOutcome` separately says
|
|
81
|
+
`not-committed` or `unknown`: a rejected/throttled write can retry safely, while a lost
|
|
82
|
+
reply may have committed. Missing outcome on Unavailable/Internal is conservative.
|
|
83
|
+
An earlier unknown outcome remains unknown after a later rejected retry. A durable
|
|
84
|
+
receipt is saved before local mappings/read-back, so recovery never redispatches an
|
|
85
|
+
already successful write merely because local reconciliation failed.
|
|
86
|
+
|
|
87
|
+
`validateAction(name, parameters, {knownParameters?})` returns an Effect containing
|
|
88
|
+
the portable certain/uncertain report. `knownParameters` selects draft validation;
|
|
89
|
+
invalid input is a report, while provider/authentication failures use the error
|
|
90
|
+
channel. Authoritative apply raises ValidationFailed with structured field issues.
|
|
91
|
+
Schema-valid input is not proof that arbitrary mutator business logic will succeed:
|
|
92
|
+
the owned backend reports uncertainty rather than executing the mutator for preflight.
|
|
93
|
+
|
|
94
|
+
Issues carry a path, optional constraint code and input/reference/custom classification.
|
|
95
|
+
Servers select disclosure separately. Provider diagnostics are redacted; credential
|
|
96
|
+
plaintext is unwrapped only at SDK boundaries. Redacted prevents accidental printing,
|
|
97
|
+
not unauthorized access by trusted code or encryption at rest.
|
|
98
|
+
|
|
99
|
+
## Owned execution and retention
|
|
100
|
+
|
|
101
|
+
`makeOwnedBackend` commits object changes, action receipts and journal entries in one
|
|
102
|
+
ontology-storage transaction. Trusted library integrations can use `storage.read` /
|
|
103
|
+
`storage.transaction` to share that journaling implementation; application operations
|
|
104
|
+
normally remain actions.
|
|
105
|
+
|
|
106
|
+
Configuration:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
const owned =
|
|
110
|
+
yield *
|
|
111
|
+
makeOwnedBackend({
|
|
112
|
+
namespace,
|
|
113
|
+
ir,
|
|
114
|
+
tables,
|
|
115
|
+
mutators,
|
|
116
|
+
resultRetentionMs: 7 * 24 * 60 * 60 * 1_000,
|
|
117
|
+
history: { maxCommits: 10_000, maxAgeMs: 24 * 60 * 60 * 1_000 },
|
|
118
|
+
maintenance: { intervalMs: 60_000 },
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Result retention is measured from completion, independent of journal retention and
|
|
123
|
+
replication delivery expiry. Infinity is supported for results and journal bounds;
|
|
124
|
+
retaining an audit history intentionally consumes storage. Bounded indexed
|
|
125
|
+
`maintenance` expires results, journal history and retained delivery bookkeeping.
|
|
126
|
+
Acquisition requires an Effect Scope. The owned backend starts one periodic sweep
|
|
127
|
+
in that scope (every 60 seconds by default); HTTP and worker bindings add no timers.
|
|
128
|
+
Set `maintenance: false` when an external owner schedules cleanup, then call the
|
|
129
|
+
service's `maintenance` effect from that lifecycle/alarm. The Alchemy DO constructor
|
|
130
|
+
does this automatically through its alarm and composed `collectGarbage` operation.
|
|
131
|
+
`makeStorageBackend` schedules that composed operation, including orphan attachment
|
|
132
|
+
cleanup with the normal grace period; it does not start a second journal timer.
|
|
133
|
+
Pending outbox work is not expired by result cleanup.
|
|
134
|
+
|
|
135
|
+
Idempotency is finite when result retention is finite. Reusing an operation ID after
|
|
136
|
+
its result has expired may execute it again. Advertising/versioning a remote retry
|
|
137
|
+
window is deferred; `supportsIdempotency` does not promise eternal receipt retention.
|
|
138
|
+
|
|
139
|
+
Intermediate replicas additionally track client sessions for ordered submissions,
|
|
140
|
+
acknowledgments and delivered state. This is not owned-backend action bookkeeping.
|
|
141
|
+
Acknowledgment removes submission fingerprints; expiry removes session/delivery
|
|
142
|
+
records, not accepted unresolved actions. Replica clientSessions limits are configurable admission bounds,
|
|
143
|
+
not a limit on stateless readers. SharedWorker hosts use a shorter ten-minute lease.
|
|
144
|
+
|
|
145
|
+
Journal expiry raises HistoryExpired. A replica rebuilds retained/active demand from
|
|
146
|
+
coordinated snapshots, atomically installs base/cursor, preserves its local outbox
|
|
147
|
+
and replays optimistic work. Expired parent sessions establish a new identity while
|
|
148
|
+
preserving queued work; an unresolved accepted result becomes blocked with an unknown outcome rather than
|
|
149
|
+
being submitted again silently.
|
package/lib/actions.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { BackendError } from "./errors.js";
|
|
2
|
+
import { ActionRequest } from "./index.js";
|
|
3
|
+
import { OwnedReadTransaction, OwnedTransaction } from "./owned.js";
|
|
4
|
+
import { Effect } from "effect";
|
|
5
|
+
import { Expression, OntologyIR, QueryDocument } from "@party-stack/ontology-spec";
|
|
6
|
+
//#region src/actions.d.ts
|
|
7
|
+
export type ActionMutator = (tx: ActionTransaction, request: ActionRequest, context: Record<string, unknown>) => Effect.Effect<unknown, BackendError>;
|
|
8
|
+
export interface ActionTransaction extends OwnedTransaction {
|
|
9
|
+
readonly query: (document: QueryDocument, options?: {
|
|
10
|
+
readonly inputs?: Record<string, unknown>;
|
|
11
|
+
}) => Effect.Effect<Record<string, unknown>, BackendError>;
|
|
12
|
+
}
|
|
13
|
+
export type ActionMutatorRegistry = Readonly<Record<string, ActionMutator>>;
|
|
14
|
+
export interface ActionExecutionOptions {
|
|
15
|
+
readonly ir: OntologyIR;
|
|
16
|
+
readonly tx: OwnedTransaction;
|
|
17
|
+
readonly request: ActionRequest;
|
|
18
|
+
readonly context?: Record<string, unknown>;
|
|
19
|
+
readonly mutators?: ActionMutatorRegistry;
|
|
20
|
+
readonly resolveOnly?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Portable action expressions read only the supplied transaction. No collection, remote demand or runtime lifecycle. */
|
|
23
|
+
export declare const actionExpressions: (options: {
|
|
24
|
+
readonly ir: OntologyIR;
|
|
25
|
+
readonly tx: OwnedReadTransaction;
|
|
26
|
+
readonly request: ActionRequest;
|
|
27
|
+
readonly context?: Record<string, unknown>;
|
|
28
|
+
readonly resolveParameter?: (name: string) => Effect.Effect<unknown, BackendError>;
|
|
29
|
+
}) => {
|
|
30
|
+
evaluate: (expression: Expression, location?: readonly (string | number)[]) => Effect.Effect<unknown, BackendError<any> | BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced">, never>;
|
|
31
|
+
resolve: Effect.Effect<Record<string, unknown>, BackendError<any> | BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced">, never>;
|
|
32
|
+
};
|
|
33
|
+
/** Shared authoritative execution and local replay. Transaction/commit ownership stays with the caller. */
|
|
34
|
+
export declare const executeAction: (options: ActionExecutionOptions) => Effect.Effect<{
|
|
35
|
+
parameters: Record<string, unknown>;
|
|
36
|
+
result: unknown;
|
|
37
|
+
}, BackendError<any> | BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced">, never>;
|
|
38
|
+
/** Resolve defaults against an authorized transaction-consistent native reader. */
|
|
39
|
+
export declare const resolveReadActionParameters: (options: {
|
|
40
|
+
readonly ir: OntologyIR;
|
|
41
|
+
readonly read: OwnedReadTransaction;
|
|
42
|
+
readonly context?: Record<string, unknown>;
|
|
43
|
+
readonly name: string;
|
|
44
|
+
readonly parameters: Record<string, unknown>;
|
|
45
|
+
}) => Effect.Effect<Record<string, unknown>, BackendError<any> | BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced">, never>;
|
|
46
|
+
//#endregion
|
|
47
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","names":[],"sources":["../src/actions.ts"],"mappings":";;;;;;YA6BY,iBACR,IAAI,mBACJ,SAAS,eACT,SAAS,4BACR,OAAO,gBAAgB;iBACX,0BAA0B;WAC9B,QACL,UAAU,eACV;aAAqB,SAAS;QAC7B,OAAO,OAAO,yBAAyB;;YAEpC,wBAAwB,SAAS,eAAe;iBAC3C;WACJ,IAAI;WACJ,IAAI;WACJ,SAAS;WACT,UAAU;WACV,WAAW;WACX;;;qBAiDA,oBAAiB;WACjB,IAAI;WACJ,IAAI;WACJ,SAAS;WACT,UAAU;WACV,oBAAoB,iBAAiB,OAAO,gBAAgB;;EA8LvC,WAAA,YAAA,YAAU,4CAAwC,OAAA,gBAAA,oBAAA;;;;qBAuCvE,gBAAa,SAAA,2BAAA,OAAA;;;GA8EI,oBAAA;;qBAGjB,8BAA2B;WACvB,IAAA;WACE,MAAA;WACI,UAAA;WACJ;WACM,YAAA;MAQvB,OAAA,OAAA,yBAAA,oBAAA"}
|
package/lib/actions.js
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { BackendError } from "./errors.js";
|
|
2
|
+
import { executeQuery } from "./query.js";
|
|
3
|
+
import { booleanValue, evaluateOperator } from "@party-stack/ontology-spec/query";
|
|
4
|
+
import { certain, getAtPath, isRelatedFromForeignKeySource, resolveLookupReference, resolveRelatedLink, resolveType, setAtPath, unwrapType, unwrapValueType } from "@party-stack/ontology-spec/utils";
|
|
5
|
+
import { eq, field } from "@party-stack/ontology-storage";
|
|
6
|
+
import { Effect, Schema } from "effect";
|
|
7
|
+
import { Temporal } from "temporal-polyfill";
|
|
8
|
+
//#region src/actions.ts
|
|
9
|
+
const failure = (message, kind = "InvalidRequest", cause) => new BackendError({
|
|
10
|
+
operation: "action.execute",
|
|
11
|
+
kind,
|
|
12
|
+
retryable: false,
|
|
13
|
+
message,
|
|
14
|
+
cause
|
|
15
|
+
});
|
|
16
|
+
const scalar = (compute) => Effect.try({
|
|
17
|
+
try: compute,
|
|
18
|
+
catch: (cause) => failure(cause instanceof Error ? cause.message : "Invalid expression values.", "InvalidRequest", cause)
|
|
19
|
+
});
|
|
20
|
+
const defect = (cause) => Effect.fail(cause instanceof BackendError ? cause : failure("Action execution failed.", "Internal", cause));
|
|
21
|
+
var Reference = class {
|
|
22
|
+
objectType;
|
|
23
|
+
key;
|
|
24
|
+
optional;
|
|
25
|
+
constructor(objectType, key, optional) {
|
|
26
|
+
this.objectType = objectType;
|
|
27
|
+
this.key = key;
|
|
28
|
+
this.optional = optional;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var Loaded = class {
|
|
32
|
+
objectType;
|
|
33
|
+
value;
|
|
34
|
+
constructor(objectType, value) {
|
|
35
|
+
this.objectType = objectType;
|
|
36
|
+
this.value = value;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/** Internal partial-default evaluation; never part of the backend error contract. */
|
|
40
|
+
var UnresolvedInput = class extends Schema.TaggedError()("UnresolvedActionInput", { parameter: Schema.String }) {};
|
|
41
|
+
const unwrapped = (value) => {
|
|
42
|
+
if (value instanceof Reference) return value.key;
|
|
43
|
+
if (value instanceof Loaded) return value.value;
|
|
44
|
+
if (Array.isArray(value)) return value.map(unwrapped);
|
|
45
|
+
if (value !== null && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype) return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, unwrapped(v)]));
|
|
46
|
+
return value;
|
|
47
|
+
};
|
|
48
|
+
const keyOf = (value) => typeof value === "string" || typeof value === "number" ? Effect.succeed(value) : Effect.fail(failure("Object reference requires a primary key."));
|
|
49
|
+
/** Portable action expressions read only the supplied transaction. No collection, remote demand or runtime lifecycle. */
|
|
50
|
+
const actionExpressions = (options) => {
|
|
51
|
+
const { ir, tx, request } = options;
|
|
52
|
+
const action = ir.actionTypes.find((a) => a.name === request.name);
|
|
53
|
+
const parameters = { ...request.parameters };
|
|
54
|
+
const resolving = /* @__PURE__ */ new Set();
|
|
55
|
+
const object = (name) => {
|
|
56
|
+
const type = ir.objectTypes.find((t) => t.name === name);
|
|
57
|
+
return type ? Effect.succeed(type) : Effect.fail(failure(`Unknown object type "${name}".`, "InvalidConfiguration"));
|
|
58
|
+
};
|
|
59
|
+
const resolveParameter = Effect.fnUntraced(function* (name) {
|
|
60
|
+
if (parameters[name] !== void 0) return parameters[name];
|
|
61
|
+
const parameter = action?.parameters.find((p) => p.name === name);
|
|
62
|
+
if (!parameter?.defaultValue) return void 0;
|
|
63
|
+
if (resolving.has(name)) return yield* failure(`Circular action parameter default for "${name}".`, "InvalidConfiguration");
|
|
64
|
+
resolving.add(name);
|
|
65
|
+
return yield* raw(parameter.defaultValue, ["parameter", name], /* @__PURE__ */ new Map()).pipe(Effect.map(unwrapped), Effect.tap((value) => Effect.sync(() => {
|
|
66
|
+
if (value !== void 0) parameters[name] = value;
|
|
67
|
+
})), Effect.ensuring(Effect.sync(() => resolving.delete(name))));
|
|
68
|
+
});
|
|
69
|
+
const raw = Effect.fnUntraced(function* (e, location, locals) {
|
|
70
|
+
const child = (node, segment) => raw(node, [...location, segment], locals);
|
|
71
|
+
switch (e.kind) {
|
|
72
|
+
case "literal": return e.value.value;
|
|
73
|
+
case "inputReference": {
|
|
74
|
+
const value = yield* options.resolveParameter?.(e.value.name) ?? resolveParameter(e.value.name);
|
|
75
|
+
const parameter = action?.parameters.find((p) => p.name === e.value.name);
|
|
76
|
+
if (!parameter) return yield* failure(`Unknown action parameter "${e.value.name}".`);
|
|
77
|
+
const { type, isOptional } = unwrapType(resolveType(ir, parameter.type));
|
|
78
|
+
if (value === void 0 && !isOptional) return yield* new UnresolvedInput({ parameter: parameter.name });
|
|
79
|
+
return type.kind === "objectReference" ? new Reference(type.value.objectType, value, isOptional) : value;
|
|
80
|
+
}
|
|
81
|
+
case "contextReference": return options.context?.[e.value.name];
|
|
82
|
+
case "localReference":
|
|
83
|
+
if (!locals.has(e.value.name)) return yield* failure(`Unknown expression binding "${e.value.name}".`);
|
|
84
|
+
return locals.get(e.value.name);
|
|
85
|
+
case "getAt": {
|
|
86
|
+
const source = yield* child(e.value.source, "source");
|
|
87
|
+
if (source instanceof Reference) return yield* failure("An object reference must be looked up before accessing properties.");
|
|
88
|
+
return getAtPath(source instanceof Loaded ? source.value : source, e.value.path);
|
|
89
|
+
}
|
|
90
|
+
case "lookup": {
|
|
91
|
+
const reference = resolveLookupReference(ir, e.value.reference, action?.parameters);
|
|
92
|
+
if (!reference) return yield* failure("Lookup requires an input/context object-reference path.");
|
|
93
|
+
const valueKey = unwrapped(yield* child(e.value.reference, "reference"));
|
|
94
|
+
if (valueKey == null) return void 0;
|
|
95
|
+
const key = yield* keyOf(valueKey);
|
|
96
|
+
const value = yield* tx.get(reference.objectType, key);
|
|
97
|
+
if (!value && !reference.optional) return yield* failure(`Missing loaded "${reference.objectType}" object.`, "NotFound");
|
|
98
|
+
return value ? new Loaded(reference.objectType, value) : void 0;
|
|
99
|
+
}
|
|
100
|
+
case "related": {
|
|
101
|
+
const source = yield* child(e.value.source, "source");
|
|
102
|
+
if (!(source instanceof Loaded)) return yield* failure("Related requires an ontology object.");
|
|
103
|
+
const link = resolveRelatedLink(ir, source.objectType, e.value.link);
|
|
104
|
+
if (!link) return yield* failure(`Unknown relationship "${e.value.link}".`);
|
|
105
|
+
const ownFK = isRelatedFromForeignKeySource(link, source.objectType, e.value.link);
|
|
106
|
+
if (!ownFK && link.cardinality === "many") return yield* failure("To-many related expressions are not supported in action execution yet.", "NotImplemented");
|
|
107
|
+
const sourceType = yield* object(source.objectType);
|
|
108
|
+
const target = yield* object(ownFK ? link.target.objectType : link.source.objectType);
|
|
109
|
+
const key = ownFK ? getAtPath(source.value, link.foreignKey.split(".")) : source.value[sourceType.primaryKey];
|
|
110
|
+
if (key == null) return void 0;
|
|
111
|
+
const rows = yield* tx.loadSubset(target.name, {
|
|
112
|
+
where: eq(field(...(ownFK ? target.primaryKey : link.foreignKey).split(".")), yield* keyOf(key)),
|
|
113
|
+
limit: 2
|
|
114
|
+
});
|
|
115
|
+
if (rows.length > 1) return yield* failure("To-one relationship returned multiple objects.", "InvalidResponse");
|
|
116
|
+
return rows[0] ? new Loaded(target.name, rows[0].value) : void 0;
|
|
117
|
+
}
|
|
118
|
+
case "struct": {
|
|
119
|
+
const entries = [];
|
|
120
|
+
for (const f of e.value.fields) entries.push([f.name, yield* raw(f.value, [
|
|
121
|
+
...location,
|
|
122
|
+
"field",
|
|
123
|
+
f.name
|
|
124
|
+
], locals)]);
|
|
125
|
+
return Object.fromEntries(entries);
|
|
126
|
+
}
|
|
127
|
+
case "map": {
|
|
128
|
+
const source = yield* child(e.value.source, "source");
|
|
129
|
+
if (source === void 0) return void 0;
|
|
130
|
+
if (!Array.isArray(source)) return yield* failure("Map source must resolve to a list.");
|
|
131
|
+
return yield* Effect.forEach(source, (item, index) => raw(e.value.body, [
|
|
132
|
+
...location,
|
|
133
|
+
"item",
|
|
134
|
+
index
|
|
135
|
+
], new Map([...locals, [e.value.binding, item]])));
|
|
136
|
+
}
|
|
137
|
+
case "uuid": {
|
|
138
|
+
if (!request.replay) return crypto.randomUUID();
|
|
139
|
+
const digest = yield* Effect.tryPromise({
|
|
140
|
+
try: () => crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify([request.replay.seed, location]))),
|
|
141
|
+
catch: (cause) => failure("Could not derive replay UUID.", "Internal", cause)
|
|
142
|
+
});
|
|
143
|
+
const bytes = new Uint8Array(digest).slice(0, 16);
|
|
144
|
+
bytes[6] = bytes[6] & 15 | 128;
|
|
145
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
146
|
+
const hex = [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
147
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
148
|
+
}
|
|
149
|
+
case "now": return yield* Effect.try({
|
|
150
|
+
try: () => request.replay ? Temporal.Instant.from(request.replay.now) : Temporal.Now.instant(),
|
|
151
|
+
catch: (cause) => failure("Invalid replay time.", "InvalidRequest", cause)
|
|
152
|
+
});
|
|
153
|
+
case "case":
|
|
154
|
+
for (const [index, branch] of e.value.branches.entries()) {
|
|
155
|
+
const condition = unwrapped(yield* raw(branch.condition, [
|
|
156
|
+
...location,
|
|
157
|
+
"branch",
|
|
158
|
+
index,
|
|
159
|
+
"condition"
|
|
160
|
+
], locals));
|
|
161
|
+
if (yield* scalar(() => booleanValue(condition))) return yield* raw(branch.result, [
|
|
162
|
+
...location,
|
|
163
|
+
"branch",
|
|
164
|
+
index,
|
|
165
|
+
"result"
|
|
166
|
+
], locals);
|
|
167
|
+
}
|
|
168
|
+
return yield* child(e.value.else, "else");
|
|
169
|
+
case "exists": return yield* failure("EXISTS is not supported in action expressions yet.", "NotImplemented");
|
|
170
|
+
default: {
|
|
171
|
+
const nodes = e.kind === "not" ? [e.value.expression] : "expressions" in e.value ? e.value.expressions : [e.value.left, e.value.right];
|
|
172
|
+
const values = [];
|
|
173
|
+
for (const [index, node] of nodes.entries()) {
|
|
174
|
+
const resolved = yield* raw(node, [
|
|
175
|
+
...location,
|
|
176
|
+
"operand",
|
|
177
|
+
index
|
|
178
|
+
], locals);
|
|
179
|
+
const value = unwrapped(resolved);
|
|
180
|
+
if (e.kind === "coalesce" && value != null) return resolved;
|
|
181
|
+
values.push(certain(value));
|
|
182
|
+
if ((e.kind === "and" || e.kind === "or") && (yield* scalar(() => booleanValue(value))) === (e.kind === "or")) break;
|
|
183
|
+
}
|
|
184
|
+
const result = yield* scalar(() => evaluateOperator(e.kind, values));
|
|
185
|
+
if (!result.certain) return yield* failure("Action expression depends on unavailable data.");
|
|
186
|
+
return result.value;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
const evaluate = (expression, location = []) => raw(expression, location, /* @__PURE__ */ new Map()).pipe(Effect.map(unwrapped), Effect.catchTag("UnresolvedActionInput", (error) => Effect.fail(failure(`Missing action parameter "${error.parameter}".`))), Effect.catchDefect(defect));
|
|
191
|
+
return {
|
|
192
|
+
evaluate,
|
|
193
|
+
resolve: Effect.gen(function* () {
|
|
194
|
+
if (!action) return yield* failure("Action is unavailable.", "NotFound");
|
|
195
|
+
for (const parameter of action.parameters) yield* resolveParameter(parameter.name).pipe(Effect.catchTag("UnresolvedActionInput", () => Effect.void));
|
|
196
|
+
return parameters;
|
|
197
|
+
}).pipe(Effect.catchDefect(defect))
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
const targetType = (ir, object, path) => {
|
|
201
|
+
let current = {
|
|
202
|
+
kind: "struct",
|
|
203
|
+
value: { fields: object.properties }
|
|
204
|
+
};
|
|
205
|
+
for (const segment of path) {
|
|
206
|
+
if (!current) break;
|
|
207
|
+
current = resolveType(ir, current);
|
|
208
|
+
while (current.kind === "optional") current = resolveType(ir, current.value.type);
|
|
209
|
+
current = current.kind === "struct" ? current.value.fields.find((f) => f.name === segment)?.type : current.kind === "map" ? current.value.valueType : current.kind === "list" ? current.value.elementType : void 0;
|
|
210
|
+
}
|
|
211
|
+
return current;
|
|
212
|
+
};
|
|
213
|
+
/** Shared authoritative execution and local replay. Transaction/commit ownership stays with the caller. */
|
|
214
|
+
const executeAction = Effect.fn("Action.execute")(function* (options) {
|
|
215
|
+
const { ir, tx, request } = options;
|
|
216
|
+
const action = ir.actionTypes.find((a) => a.name === request.name);
|
|
217
|
+
if (!action) return yield* failure("Action is unavailable.", "NotFound");
|
|
218
|
+
const expressions = actionExpressions(options);
|
|
219
|
+
const parameters = yield* expressions.resolve;
|
|
220
|
+
if (options.resolveOnly) return {
|
|
221
|
+
parameters,
|
|
222
|
+
result: void 0
|
|
223
|
+
};
|
|
224
|
+
for (const [index, step] of action.logic.entries()) {
|
|
225
|
+
let type;
|
|
226
|
+
let key;
|
|
227
|
+
if (step.kind === "createObject") type = ir.objectTypes.find((t) => t.name === step.value.objectType);
|
|
228
|
+
else {
|
|
229
|
+
const parameter = action.parameters.find((p) => p.name === step.value.object.name);
|
|
230
|
+
const resolved = parameter && unwrapType(resolveType(ir, parameter.type)).type;
|
|
231
|
+
type = resolved?.kind === "objectReference" ? ir.objectTypes.find((t) => t.name === resolved.value.objectType) : void 0;
|
|
232
|
+
key = yield* keyOf(parameters[step.value.object.name]);
|
|
233
|
+
}
|
|
234
|
+
if (!type) return yield* failure("Action logic references an unknown object type.", "InvalidConfiguration");
|
|
235
|
+
if (step.kind === "deleteObject") {
|
|
236
|
+
yield* tx.delete(type.name, key);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
const changes = [];
|
|
240
|
+
for (const assignment of step.value.values) {
|
|
241
|
+
const value = yield* expressions.evaluate(assignment.value, [
|
|
242
|
+
"logic",
|
|
243
|
+
index,
|
|
244
|
+
...assignment.property
|
|
245
|
+
]);
|
|
246
|
+
if (value === void 0) continue;
|
|
247
|
+
const target = targetType(ir, type, assignment.property);
|
|
248
|
+
changes.push({
|
|
249
|
+
path: assignment.property,
|
|
250
|
+
value: value === null && target && resolveType(ir, target).kind === "optional" ? void 0 : value
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
if (step.kind === "updateObject") yield* tx.patch(type.name, key, changes);
|
|
254
|
+
else {
|
|
255
|
+
let value = {};
|
|
256
|
+
for (const change of changes) value = setAtPath(value, change.path, change.value);
|
|
257
|
+
if (value[type.primaryKey] === void 0) {
|
|
258
|
+
const pk = type.properties.find((p) => p.name === type.primaryKey);
|
|
259
|
+
if (!pk || unwrapValueType(ir, pk.type).kind !== "string") continue;
|
|
260
|
+
value[type.primaryKey] = `optimistic:${request.id}:${type.name}:${index}`;
|
|
261
|
+
}
|
|
262
|
+
const key = yield* keyOf(value[type.primaryKey]);
|
|
263
|
+
if (yield* tx.get(type.name, key)) return yield* failure("Object already exists.", "Conflict");
|
|
264
|
+
yield* tx.put(type.name, value);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
const mutator = options.mutators?.[request.name];
|
|
268
|
+
return {
|
|
269
|
+
parameters,
|
|
270
|
+
result: mutator ? yield* mutator({
|
|
271
|
+
get: (type, key) => tx.get(type, key),
|
|
272
|
+
loadSubset: (type, scan) => tx.loadSubset(type, scan),
|
|
273
|
+
put: (type, value) => tx.put(type, value),
|
|
274
|
+
patch: (type, key, changes) => tx.patch(type, key, changes),
|
|
275
|
+
delete: (type, key) => tx.delete(type, key),
|
|
276
|
+
query: (document, settings) => executeQuery(document, {
|
|
277
|
+
reader: {
|
|
278
|
+
ir,
|
|
279
|
+
loadSubset: (type, scan) => tx.loadSubset(type, scan)
|
|
280
|
+
},
|
|
281
|
+
context: options.context,
|
|
282
|
+
inputs: settings?.inputs
|
|
283
|
+
}).pipe(Effect.map((result) => result.value))
|
|
284
|
+
}, {
|
|
285
|
+
...request,
|
|
286
|
+
parameters
|
|
287
|
+
}, options.context ?? {}) : void 0
|
|
288
|
+
};
|
|
289
|
+
}, Effect.catchDefect(defect));
|
|
290
|
+
/** Resolve defaults against an authorized transaction-consistent native reader. */
|
|
291
|
+
const resolveReadActionParameters = Effect.fn("Action.resolveParameters")(function* (options) {
|
|
292
|
+
return yield* actionExpressions({
|
|
293
|
+
ir: options.ir,
|
|
294
|
+
tx: options.read,
|
|
295
|
+
request: {
|
|
296
|
+
id: "resolve",
|
|
297
|
+
name: options.name,
|
|
298
|
+
parameters: options.parameters
|
|
299
|
+
},
|
|
300
|
+
context: options.context
|
|
301
|
+
}).resolve;
|
|
302
|
+
});
|
|
303
|
+
//#endregion
|
|
304
|
+
export { actionExpressions, executeAction, resolveReadActionParameters };
|
|
305
|
+
|
|
306
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","names":[],"sources":["../src/actions.ts"],"sourcesContent":["import { booleanValue, evaluateOperator } from \"@party-stack/ontology-spec/query\";\nimport {\n getAtPath,\n setAtPath,\n resolveType,\n unwrapType,\n unwrapValueType,\n resolveRelatedLink,\n isRelatedFromForeignKeySource,\n resolveLookupReference,\n certain,\n} from \"@party-stack/ontology-spec/utils\";\nimport { eq, field } from \"@party-stack/ontology-storage\";\nimport { Effect, Schema } from \"effect\";\nimport { Temporal } from \"temporal-polyfill\";\nimport { BackendError } from \"./errors.js\";\nimport { executeQuery } from \"./query.js\";\nimport type { ActionRequest } from \"./index.js\";\nimport type { OwnedReadTransaction, OwnedTransaction } from \"./owned.js\";\nimport type {\n Expression,\n OntologyIR,\n ObjectTypeDef,\n TypeDef,\n QueryDocument,\n} from \"@party-stack/ontology-spec\";\nimport type { Uncertain } from \"@party-stack/ontology-spec/utils\";\nimport type { Key } from \"@party-stack/ontology-storage\";\n\nexport type ActionMutator = (\n tx: ActionTransaction,\n request: ActionRequest,\n context: Record<string, unknown>\n) => Effect.Effect<unknown, BackendError>;\nexport interface ActionTransaction extends OwnedTransaction {\n readonly query: (\n document: QueryDocument,\n options?: { readonly inputs?: Record<string, unknown> }\n ) => Effect.Effect<Record<string, unknown>, BackendError>;\n}\nexport type ActionMutatorRegistry = Readonly<Record<string, ActionMutator>>;\nexport interface ActionExecutionOptions {\n readonly ir: OntologyIR;\n readonly tx: OwnedTransaction;\n readonly request: ActionRequest;\n readonly context?: Record<string, unknown>;\n readonly mutators?: ActionMutatorRegistry;\n readonly resolveOnly?: boolean;\n}\nconst failure = (message: string, kind: BackendError[\"kind\"] = \"InvalidRequest\", cause?: unknown) =>\n new BackendError({ operation: \"action.execute\", kind, retryable: false, message, cause });\nconst scalar = <A>(compute: () => A) =>\n Effect.try({\n try: compute,\n catch: (cause) =>\n failure(\n cause instanceof Error ? cause.message : \"Invalid expression values.\",\n \"InvalidRequest\",\n cause\n ),\n });\nconst defect = (cause: unknown) =>\n Effect.fail(\n cause instanceof BackendError ? cause : failure(\"Action execution failed.\", \"Internal\", cause)\n );\nclass Reference {\n constructor(\n readonly objectType: string,\n readonly key: unknown,\n readonly optional: boolean\n ) {}\n}\nclass Loaded {\n constructor(\n readonly objectType: string,\n readonly value: Record<string, unknown>\n ) {}\n}\n/** Internal partial-default evaluation; never part of the backend error contract. */\nclass UnresolvedInput extends Schema.TaggedError<UnresolvedInput>()(\"UnresolvedActionInput\", {\n parameter: Schema.String,\n}) {}\nconst unwrapped = (value: unknown): unknown => {\n if (value instanceof Reference) return value.key;\n if (value instanceof Loaded) return value.value;\n if (Array.isArray(value)) return value.map(unwrapped);\n if (value !== null && typeof value === \"object\" && Object.getPrototypeOf(value) === Object.prototype)\n return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, unwrapped(v)]));\n return value;\n};\nconst keyOf = (value: unknown) =>\n typeof value === \"string\" || typeof value === \"number\"\n ? Effect.succeed(value)\n : Effect.fail(failure(\"Object reference requires a primary key.\"));\n\n/** Portable action expressions read only the supplied transaction. No collection, remote demand or runtime lifecycle. */\nexport const actionExpressions = (options: {\n readonly ir: OntologyIR;\n readonly tx: OwnedReadTransaction;\n readonly request: ActionRequest;\n readonly context?: Record<string, unknown>;\n readonly resolveParameter?: (name: string) => Effect.Effect<unknown, BackendError>;\n}) => {\n const { ir, tx, request } = options;\n const action = ir.actionTypes.find((a) => a.name === request.name);\n const parameters: Record<string, unknown> = { ...request.parameters };\n const resolving = new Set<string>();\n const object = (name: string) => {\n const type = ir.objectTypes.find((t) => t.name === name);\n return type\n ? Effect.succeed(type)\n : Effect.fail(failure(`Unknown object type \"${name}\".`, \"InvalidConfiguration\"));\n };\n const resolveParameter = Effect.fnUntraced(function* (\n name: string\n ): Effect.fn.Return<unknown, BackendError | UnresolvedInput> {\n if (parameters[name] !== undefined) return parameters[name];\n const parameter = action?.parameters.find((p) => p.name === name);\n if (!parameter?.defaultValue) return undefined;\n if (resolving.has(name))\n return yield* failure(`Circular action parameter default for \"${name}\".`, \"InvalidConfiguration\");\n resolving.add(name);\n return yield* raw(parameter.defaultValue, [\"parameter\", name], new Map()).pipe(\n Effect.map(unwrapped),\n Effect.tap((value) =>\n Effect.sync(() => {\n if (value !== undefined) parameters[name] = value;\n })\n ),\n Effect.ensuring(Effect.sync(() => resolving.delete(name)))\n );\n });\n const raw = Effect.fnUntraced(function* (\n e: Expression,\n location: readonly (string | number)[],\n locals: ReadonlyMap<string, unknown>\n ): Effect.fn.Return<unknown, BackendError | UnresolvedInput> {\n const child = (node: Expression, segment: string) => raw(node, [...location, segment], locals);\n switch (e.kind) {\n case \"literal\":\n return e.value.value;\n case \"inputReference\": {\n const value = yield* (\n options.resolveParameter?.(e.value.name) ?? resolveParameter(e.value.name)\n );\n const parameter = action?.parameters.find((p) => p.name === e.value.name);\n if (!parameter) return yield* failure(`Unknown action parameter \"${e.value.name}\".`);\n const { type, isOptional } = unwrapType(resolveType(ir, parameter.type));\n if (value === undefined && !isOptional)\n return yield* new UnresolvedInput({ parameter: parameter.name });\n return type.kind === \"objectReference\"\n ? new Reference(type.value.objectType, value, isOptional)\n : value;\n }\n case \"contextReference\":\n return options.context?.[e.value.name];\n case \"localReference\":\n if (!locals.has(e.value.name))\n return yield* failure(`Unknown expression binding \"${e.value.name}\".`);\n return locals.get(e.value.name);\n case \"getAt\": {\n const source = yield* child(e.value.source, \"source\");\n if (source instanceof Reference)\n return yield* failure(\n \"An object reference must be looked up before accessing properties.\"\n );\n return getAtPath(source instanceof Loaded ? source.value : source, e.value.path);\n }\n case \"lookup\": {\n const reference = resolveLookupReference(ir, e.value.reference, action?.parameters);\n if (!reference)\n return yield* failure(\"Lookup requires an input/context object-reference path.\");\n const valueKey = unwrapped(yield* child(e.value.reference, \"reference\"));\n if (valueKey == null) return undefined;\n const key = yield* keyOf(valueKey);\n const value = yield* tx.get(reference.objectType, key);\n if (!value && !reference.optional)\n return yield* failure(`Missing loaded \"${reference.objectType}\" object.`, \"NotFound\");\n return value ? new Loaded(reference.objectType, value) : undefined;\n }\n case \"related\": {\n const source = yield* child(e.value.source, \"source\");\n if (!(source instanceof Loaded))\n return yield* failure(\"Related requires an ontology object.\");\n const link = resolveRelatedLink(ir, source.objectType, e.value.link);\n if (!link) return yield* failure(`Unknown relationship \"${e.value.link}\".`);\n const ownFK = isRelatedFromForeignKeySource(link, source.objectType, e.value.link);\n if (!ownFK && link.cardinality === \"many\")\n return yield* failure(\n \"To-many related expressions are not supported in action execution yet.\",\n \"NotImplemented\"\n );\n const sourceType = yield* object(source.objectType);\n const target = yield* object(ownFK ? link.target.objectType : link.source.objectType);\n const key = ownFK\n ? getAtPath(source.value, link.foreignKey.split(\".\"))\n : source.value[sourceType.primaryKey];\n if (key == null) return undefined;\n const rows = yield* tx.loadSubset(target.name, {\n where: eq(\n field(...(ownFK ? target.primaryKey : link.foreignKey).split(\".\")),\n yield* keyOf(key)\n ),\n limit: 2,\n });\n if (rows.length > 1)\n return yield* failure(\n \"To-one relationship returned multiple objects.\",\n \"InvalidResponse\"\n );\n return rows[0] ? new Loaded(target.name, rows[0].value) : undefined;\n }\n case \"struct\": {\n const entries = [];\n for (const f of e.value.fields)\n entries.push([f.name, yield* raw(f.value, [...location, \"field\", f.name], locals)]);\n return Object.fromEntries(entries);\n }\n case \"map\": {\n const source = yield* child(e.value.source, \"source\");\n if (source === undefined) return undefined;\n if (!Array.isArray(source)) return yield* failure(\"Map source must resolve to a list.\");\n return yield* Effect.forEach(source, (item, index) =>\n raw(\n e.value.body,\n [...location, \"item\", index],\n new Map([...locals, [e.value.binding, item]])\n )\n );\n }\n case \"uuid\": {\n if (!request.replay) return crypto.randomUUID();\n const digest = yield* Effect.tryPromise({\n try: () =>\n crypto.subtle.digest(\n \"SHA-256\",\n new TextEncoder().encode(JSON.stringify([request.replay!.seed, location]))\n ),\n catch: (cause) => failure(\"Could not derive replay UUID.\", \"Internal\", cause),\n });\n const bytes = new Uint8Array(digest).slice(0, 16);\n bytes[6] = (bytes[6]! & 0x0f) | 0x80;\n bytes[8] = (bytes[8]! & 0x3f) | 0x80;\n const hex = [...bytes].map((b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n }\n case \"now\":\n return yield* Effect.try({\n try: () =>\n request.replay ? Temporal.Instant.from(request.replay.now) : Temporal.Now.instant(),\n catch: (cause) => failure(\"Invalid replay time.\", \"InvalidRequest\", cause),\n });\n case \"case\": {\n for (const [index, branch] of e.value.branches.entries()) {\n const condition = unwrapped(\n yield* raw(branch.condition, [...location, \"branch\", index, \"condition\"], locals)\n );\n if (yield* scalar(() => booleanValue(condition)))\n return yield* raw(branch.result, [...location, \"branch\", index, \"result\"], locals);\n }\n return yield* child(e.value.else, \"else\");\n }\n case \"exists\":\n return yield* failure(\"EXISTS is not supported in action expressions yet.\", \"NotImplemented\");\n default: {\n const nodes =\n e.kind === \"not\"\n ? [e.value.expression]\n : \"expressions\" in e.value\n ? e.value.expressions\n : [e.value.left, e.value.right];\n const values: Uncertain<unknown>[] = [];\n for (const [index, node] of nodes.entries()) {\n const resolved = yield* raw(node, [...location, \"operand\", index], locals);\n const value = unwrapped(resolved);\n // Preserve reference/entity identity for subsequent traversal.\n if (e.kind === \"coalesce\" && value != null) return resolved;\n values.push(certain(value));\n if (\n (e.kind === \"and\" || e.kind === \"or\") &&\n (yield* scalar(() => booleanValue(value))) === (e.kind === \"or\")\n )\n break;\n }\n const result = yield* scalar(() => evaluateOperator(e.kind, values));\n // All action inputs are concrete; uncertainty belongs to draft/query evaluation.\n if (!result.certain) return yield* failure(\"Action expression depends on unavailable data.\");\n return result.value;\n }\n }\n });\n const evaluate = (expression: Expression, location: readonly (string | number)[] = []) =>\n raw(expression, location, new Map()).pipe(\n Effect.map(unwrapped),\n Effect.catchTag(\"UnresolvedActionInput\", (error) =>\n Effect.fail(failure(`Missing action parameter \"${error.parameter}\".`))\n ),\n Effect.catchDefect(defect)\n );\n return {\n evaluate,\n resolve: Effect.gen(function* () {\n if (!action) return yield* failure(\"Action is unavailable.\", \"NotFound\");\n for (const parameter of action.parameters)\n yield* resolveParameter(parameter.name).pipe(\n Effect.catchTag(\"UnresolvedActionInput\", () => Effect.void)\n );\n return parameters;\n }).pipe(Effect.catchDefect(defect)),\n };\n};\n\nconst targetType = (ir: OntologyIR, object: ObjectTypeDef, path: readonly string[]): TypeDef | undefined => {\n let current: TypeDef | undefined = { kind: \"struct\", value: { fields: object.properties } };\n for (const segment of path) {\n if (!current) break;\n current = resolveType(ir, current);\n while (current.kind === \"optional\") current = resolveType(ir, current.value.type);\n current =\n current.kind === \"struct\"\n ? current.value.fields.find((f) => f.name === segment)?.type\n : current.kind === \"map\"\n ? current.value.valueType\n : current.kind === \"list\"\n ? current.value.elementType\n : undefined;\n }\n return current;\n};\n/** Shared authoritative execution and local replay. Transaction/commit ownership stays with the caller. */\nexport const executeAction = Effect.fn(\"Action.execute\")(function* (options: ActionExecutionOptions) {\n const { ir, tx, request } = options;\n const action = ir.actionTypes.find((a) => a.name === request.name);\n if (!action) return yield* failure(\"Action is unavailable.\", \"NotFound\");\n const expressions = actionExpressions(options);\n const parameters = yield* expressions.resolve;\n if (options.resolveOnly) return { parameters, result: undefined };\n for (const [index, step] of action.logic.entries()) {\n let type: ObjectTypeDef | undefined;\n let key: Key | undefined;\n if (step.kind === \"createObject\") type = ir.objectTypes.find((t) => t.name === step.value.objectType);\n else {\n const parameter = action.parameters.find((p) => p.name === step.value.object.name);\n const resolved = parameter && unwrapType(resolveType(ir, parameter.type)).type;\n type =\n resolved?.kind === \"objectReference\"\n ? ir.objectTypes.find((t) => t.name === resolved.value.objectType)\n : undefined;\n key = yield* keyOf(parameters[step.value.object.name]);\n }\n if (!type)\n return yield* failure(\"Action logic references an unknown object type.\", \"InvalidConfiguration\");\n if (step.kind === \"deleteObject\") {\n yield* tx.delete(type.name, key!);\n continue;\n }\n const changes = [];\n for (const assignment of step.value.values) {\n const value = yield* expressions.evaluate(assignment.value, [\n \"logic\",\n index,\n ...assignment.property,\n ]);\n if (value === undefined) continue;\n const target = targetType(ir, type, assignment.property);\n changes.push({\n path: assignment.property,\n value:\n value === null && target && resolveType(ir, target).kind === \"optional\"\n ? undefined\n : value,\n });\n }\n if (step.kind === \"updateObject\") yield* tx.patch(type.name, key!, changes);\n else {\n let value: Record<string, unknown> = {};\n for (const change of changes) value = setAtPath(value, change.path, change.value);\n if (value[type.primaryKey] === undefined) {\n const pk = type.properties.find((p) => p.name === type!.primaryKey);\n if (!pk || unwrapValueType(ir, pk.type).kind !== \"string\") continue;\n value[type.primaryKey] = `optimistic:${request.id}:${type.name}:${index}`;\n }\n const key = yield* keyOf(value[type.primaryKey]);\n if (yield* tx.get(type.name, key)) return yield* failure(\"Object already exists.\", \"Conflict\");\n yield* tx.put(type.name, value);\n }\n }\n const mutator = options.mutators?.[request.name];\n const result = mutator\n ? yield* mutator(\n {\n get: (type, key) => tx.get(type, key),\n loadSubset: (type, scan) => tx.loadSubset(type, scan),\n put: (type, value) => tx.put(type, value),\n patch: (type, key, changes) => tx.patch(type, key, changes),\n delete: (type, key) => tx.delete(type, key),\n query: (document, settings) =>\n executeQuery(document, {\n reader: { ir, loadSubset: (type, scan) => tx.loadSubset(type, scan) },\n context: options.context,\n inputs: settings?.inputs,\n }).pipe(Effect.map((result) => result.value)),\n },\n { ...request, parameters },\n options.context ?? {}\n )\n : undefined;\n return { parameters, result };\n}, Effect.catchDefect(defect));\n\n/** Resolve defaults against an authorized transaction-consistent native reader. */\nexport const resolveReadActionParameters = Effect.fn(\"Action.resolveParameters\")(function* (options: {\n readonly ir: OntologyIR;\n readonly read: OwnedReadTransaction;\n readonly context?: Record<string, unknown>;\n readonly name: string;\n readonly parameters: Record<string, unknown>;\n}) {\n return yield* actionExpressions({\n ir: options.ir,\n tx: options.read,\n request: { id: \"resolve\", name: options.name, parameters: options.parameters },\n context: options.context,\n }).resolve;\n});\n"],"mappings":";;;;;;;;AAiDA,MAAM,WAAW,SAAiB,OAA6B,kBAAkB,UAC7E,IAAI,aAAa;CAAE,WAAW;CAAkB;CAAM,WAAW;CAAO;CAAS;AAAM,CAAC;AAC5F,MAAM,UAAa,YACf,OAAO,IAAI;CACP,KAAK;CACL,QAAQ,UACJ,QACI,iBAAiB,QAAQ,MAAM,UAAU,8BACzC,kBACA,KACJ;AACR,CAAC;AACL,MAAM,UAAU,UACZ,OAAO,KACH,iBAAiB,eAAe,QAAQ,QAAQ,4BAA4B,YAAY,KAAK,CACjG;AACJ,IAAM,YAAN,MAAgB;CAEC;CACA;CACA;CAHb,YACI,YACA,KACA,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