@party-stack/ontology 0.19.1 → 0.21.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/README.md +31 -0
- package/lib/OntologyPullConfig.d.ts +4 -17
- package/lib/OntologyPullConfig.d.ts.map +1 -1
- package/lib/authentication.d.ts +1068 -0
- package/lib/authentication.d.ts.map +1 -0
- package/lib/authentication.js +55 -0
- package/lib/authentication.js.map +1 -0
- package/lib/cli/index.js +19 -45
- package/lib/cli/index.js.map +1 -1
- package/lib/cli/pull.d.ts.map +1 -1
- package/lib/cli/pull.js +16 -29
- package/lib/cli/pull.js.map +1 -1
- package/lib/client.d.ts +11 -0
- package/lib/client.d.ts.map +1 -0
- package/lib/client.js +21 -0
- package/lib/client.js.map +1 -0
- package/lib/examples/blog.d.ts +2 -387
- package/lib/examples/blog.js +1 -353
- package/lib/examples/blog.live-queries.d.ts +1 -1
- package/lib/examples/blog.live-queries.d.ts.map +1 -1
- package/lib/examples/blog.live-queries.js +1 -1
- package/lib/examples/blog.live-queries.js.map +1 -1
- package/lib/examples/generated/collections.d.ts +7 -0
- package/lib/examples/generated/collections.d.ts.map +1 -0
- package/lib/examples/generated/collections.js +12 -0
- package/lib/examples/generated/collections.js.map +1 -0
- package/lib/examples/generated/live.d.ts +2 -2
- package/lib/examples/generated/live.d.ts.map +1 -1
- package/lib/examples/generated/live.js.map +1 -1
- package/lib/http.d.ts +13 -0
- package/lib/http.d.ts.map +1 -0
- package/lib/http.js +29 -0
- package/lib/http.js.map +1 -0
- package/lib/index.d.ts +19 -25
- package/lib/index.js +9 -15
- package/lib/json/index.d.ts +1 -16
- package/lib/json/index.js +2 -132
- package/lib/live/LiveOntology.d.ts +114 -50
- package/lib/live/LiveOntology.d.ts.map +1 -1
- package/lib/live/LiveOntology.js +23 -103
- package/lib/live/LiveOntology.js.map +1 -1
- package/lib/live/actions/createLiveOntologyAction.d.ts +15 -16
- package/lib/live/actions/createLiveOntologyAction.d.ts.map +1 -1
- package/lib/live/actions/createLiveOntologyAction.js +3 -11
- package/lib/live/actions/createLiveOntologyAction.js.map +1 -1
- package/lib/live/actions/types.d.ts +21 -0
- package/lib/live/actions/types.d.ts.map +1 -0
- package/lib/live/attachments/createLiveOntologyAttachments.d.ts +30 -19
- package/lib/live/attachments/createLiveOntologyAttachments.d.ts.map +1 -1
- package/lib/live/attachments/createLiveOntologyAttachments.js +43 -60
- package/lib/live/attachments/createLiveOntologyAttachments.js.map +1 -1
- package/lib/live/attachments/types.d.ts +4 -3
- package/lib/live/index.d.ts +10 -10
- package/lib/live/index.js +5 -6
- package/lib/live/mutators/createReadTx.d.ts +5 -0
- package/lib/live/mutators/createReadTx.d.ts.map +1 -0
- package/lib/live/mutators/createReadTx.js +19 -0
- package/lib/live/mutators/createReadTx.js.map +1 -0
- package/lib/live/mutators/types.d.ts +7 -2
- package/lib/live/mutators/types.d.ts.map +1 -1
- package/lib/live/objects/types.d.ts +6 -0
- package/lib/live/objects/types.d.ts.map +1 -0
- package/lib/live/outbox/types.d.ts +24 -15
- package/lib/live/outbox/types.d.ts.map +1 -1
- package/lib/live/outbox/types.js +1 -11
- package/lib/live/pins.d.ts +51 -0
- package/lib/live/pins.d.ts.map +1 -0
- package/lib/live/pins.js +113 -0
- package/lib/live/pins.js.map +1 -0
- package/lib/live/storageBackend.d.ts +50 -0
- package/lib/live/storageBackend.d.ts.map +1 -0
- package/lib/live/storageBackend.js +42 -0
- package/lib/live/storageBackend.js.map +1 -0
- package/lib/local.d.ts +15 -0
- package/lib/local.d.ts.map +1 -0
- package/lib/local.js +19 -0
- package/lib/local.js.map +1 -0
- package/lib/meta/generated/collections.d.ts +7 -0
- package/lib/meta/generated/collections.d.ts.map +1 -0
- package/lib/meta/generated/collections.js +15 -0
- package/lib/meta/generated/collections.js.map +1 -0
- package/lib/meta/generated/live.d.ts +3 -3
- package/lib/meta/generated/live.d.ts.map +1 -1
- package/lib/meta/generated/live.js +2 -2
- package/lib/meta/generated/live.js.map +1 -1
- package/lib/meta/pull.d.ts +5 -9
- package/lib/meta/pull.d.ts.map +1 -1
- package/lib/meta/pull.js +5 -43
- package/lib/meta/pull.js.map +1 -1
- package/lib/query.d.ts +1 -0
- package/lib/query.js +2 -0
- package/lib/runtime/host.d.ts +35 -0
- package/lib/runtime/host.d.ts.map +1 -0
- package/lib/runtime/host.js +39 -0
- package/lib/runtime/host.js.map +1 -0
- package/lib/runtime/index.d.ts +2 -0
- package/lib/runtime/index.js +1 -0
- package/lib/runtime/live.d.ts +25 -0
- package/lib/runtime/live.d.ts.map +1 -0
- package/lib/runtime/live.js +31 -0
- package/lib/runtime/live.js.map +1 -0
- package/lib/runtime/resource.d.ts +24 -0
- package/lib/runtime/resource.d.ts.map +1 -0
- package/lib/runtime/resource.js +127 -0
- package/lib/runtime/resource.js.map +1 -0
- package/lib/runtime/transactions.d.ts +27 -0
- package/lib/runtime/transactions.d.ts.map +1 -0
- package/lib/runtime/transactions.js +188 -0
- package/lib/runtime/transactions.js.map +1 -0
- package/lib/runtime/view.d.ts +25 -0
- package/lib/runtime/view.d.ts.map +1 -0
- package/lib/runtime/view.js +256 -0
- package/lib/runtime/view.js.map +1 -0
- package/lib/tanstack/collections.d.ts +73 -0
- package/lib/tanstack/collections.d.ts.map +1 -0
- package/lib/tanstack/collections.js +495 -0
- package/lib/tanstack/collections.js.map +1 -0
- package/lib/tanstack/createLocalCollection.d.ts +14 -0
- package/lib/tanstack/createLocalCollection.d.ts.map +1 -0
- package/lib/tanstack/createLocalCollection.js +9 -0
- package/lib/tanstack/createLocalCollection.js.map +1 -0
- package/lib/tanstack/descriptors.d.ts +33 -0
- package/lib/tanstack/descriptors.d.ts.map +1 -0
- package/lib/tanstack/descriptors.js +38 -0
- package/lib/tanstack/descriptors.js.map +1 -0
- package/lib/tanstack/diagnostics.d.ts +23 -0
- package/lib/tanstack/diagnostics.d.ts.map +1 -0
- package/lib/tanstack/diagnostics.js +14 -0
- package/lib/tanstack/diagnostics.js.map +1 -0
- package/lib/tanstack/index.d.ts +6 -0
- package/lib/tanstack/index.js +6 -0
- package/lib/tanstack/localCollection.d.ts +14 -0
- package/lib/tanstack/localCollection.d.ts.map +1 -0
- package/lib/tanstack/localCollection.js +73 -0
- package/lib/tanstack/localCollection.js.map +1 -0
- package/lib/tanstack/subset.d.ts +28 -0
- package/lib/tanstack/subset.d.ts.map +1 -0
- package/lib/tanstack/subset.js +290 -0
- package/lib/tanstack/subset.js.map +1 -0
- package/lib/testing/sqlite.d.ts +40 -0
- package/lib/testing/sqlite.d.ts.map +1 -0
- package/lib/testing/sqlite.js +409 -0
- package/lib/testing/sqlite.js.map +1 -0
- package/lib/testing/sqliteBackend.d.ts +68 -0
- package/lib/testing/sqliteBackend.d.ts.map +1 -0
- package/lib/testing/sqliteBackend.js +34 -0
- package/lib/testing/sqliteBackend.js.map +1 -0
- package/lib/utils/index.d.ts +1 -8
- package/lib/utils/index.js +2 -5
- package/lib/utils/values.d.ts +1 -33
- package/lib/worker.d.ts +19 -0
- package/lib/worker.d.ts.map +1 -0
- package/lib/worker.js +46 -0
- package/lib/worker.js.map +1 -0
- package/package.json +54 -19
- package/lib/_virtual/_rolldown/runtime.js +0 -13
- package/lib/cli/format.d.ts +0 -4
- package/lib/cli/format.d.ts.map +0 -1
- package/lib/cli/format.js +0 -19
- package/lib/cli/format.js.map +0 -1
- package/lib/cli/generate.d.ts +0 -10
- package/lib/cli/generate.d.ts.map +0 -1
- package/lib/cli/generate.js +0 -108
- package/lib/cli/generate.js.map +0 -1
- package/lib/examples/blog.d.ts.map +0 -1
- package/lib/examples/blog.js.map +0 -1
- package/lib/generate/builders.d.ts +0 -12
- package/lib/generate/builders.d.ts.map +0 -1
- package/lib/generate/builders.js +0 -58
- package/lib/generate/builders.js.map +0 -1
- package/lib/generate/constants.d.ts +0 -5
- package/lib/generate/constants.d.ts.map +0 -1
- package/lib/generate/constants.js +0 -28
- package/lib/generate/constants.js.map +0 -1
- package/lib/generate/index.d.ts +0 -6
- package/lib/generate/index.js +0 -6
- package/lib/generate/live.d.ts +0 -12
- package/lib/generate/live.d.ts.map +0 -1
- package/lib/generate/live.js +0 -48
- package/lib/generate/live.js.map +0 -1
- package/lib/generate/ontology.d.ts +0 -8
- package/lib/generate/ontology.d.ts.map +0 -1
- package/lib/generate/ontology.js +0 -501
- package/lib/generate/ontology.js.map +0 -1
- package/lib/generate/types.d.ts +0 -17
- package/lib/generate/types.d.ts.map +0 -1
- package/lib/generate/types.js +0 -216
- package/lib/generate/types.js.map +0 -1
- package/lib/generate/utils/buildJsDocs.d.ts +0 -10
- package/lib/generate/utils/buildJsDocs.d.ts.map +0 -1
- package/lib/generate/utils/buildJsDocs.js +0 -16
- package/lib/generate/utils/buildJsDocs.js.map +0 -1
- package/lib/infer.d.ts +0 -222
- package/lib/infer.d.ts.map +0 -1
- package/lib/infer.js +0 -14
- package/lib/infer.js.map +0 -1
- package/lib/installation/createMetaOntologyConfiguration.d.ts +0 -10
- package/lib/installation/createMetaOntologyConfiguration.d.ts.map +0 -1
- package/lib/installation/createMetaOntologyConfiguration.js +0 -16
- package/lib/installation/createMetaOntologyConfiguration.js.map +0 -1
- package/lib/installation/createOntologyBackendInstallation.d.ts +0 -5
- package/lib/installation/createOntologyBackendInstallation.d.ts.map +0 -1
- package/lib/installation/createOntologyBackendInstallation.js +0 -221
- package/lib/installation/createOntologyBackendInstallation.js.map +0 -1
- package/lib/installation/index.d.ts +0 -4
- package/lib/installation/index.js +0 -3
- package/lib/installation/types.d.ts +0 -94
- package/lib/installation/types.d.ts.map +0 -1
- package/lib/ir/generated/builders.d.ts +0 -380
- package/lib/ir/generated/builders.d.ts.map +0 -1
- package/lib/ir/generated/builders.js +0 -186
- package/lib/ir/generated/builders.js.map +0 -1
- package/lib/ir/generated/constants.d.ts +0 -265
- package/lib/ir/generated/constants.d.ts.map +0 -1
- package/lib/ir/generated/constants.js +0 -165
- package/lib/ir/generated/constants.js.map +0 -1
- package/lib/ir/generated/types.d.ts +0 -416
- package/lib/ir/generated/types.d.ts.map +0 -1
- package/lib/ir/index.d.ts +0 -4
- package/lib/ir/index.js +0 -3
- package/lib/ir/schema.d.ts +0 -2246
- package/lib/ir/schema.d.ts.map +0 -1
- package/lib/ir/schema.js +0 -1187
- package/lib/ir/schema.js.map +0 -1
- package/lib/ir/validate.d.ts +0 -8
- package/lib/ir/validate.d.ts.map +0 -1
- package/lib/ir/validate.js +0 -623
- package/lib/ir/validate.js.map +0 -1
- package/lib/json/index.d.ts.map +0 -1
- package/lib/json/index.js.map +0 -1
- package/lib/lenses.d.ts +0 -21
- package/lib/lenses.d.ts.map +0 -1
- package/lib/lenses.js +0 -110
- package/lib/lenses.js.map +0 -1
- package/lib/live/OntologyBackendAdapter.d.ts +0 -100
- package/lib/live/OntologyBackendAdapter.d.ts.map +0 -1
- package/lib/live/OntologyBackendAdapter.js +0 -1
- package/lib/live/actions/createLiveOntologyActions.d.ts +0 -28
- package/lib/live/actions/createLiveOntologyActions.d.ts.map +0 -1
- package/lib/live/actions/createLiveOntologyActions.js +0 -139
- package/lib/live/actions/createLiveOntologyActions.js.map +0 -1
- package/lib/live/actions/prepareActionParameters.d.ts +0 -19
- package/lib/live/actions/prepareActionParameters.d.ts.map +0 -1
- package/lib/live/actions/prepareActionParameters.js +0 -213
- package/lib/live/actions/prepareActionParameters.js.map +0 -1
- package/lib/live/attachments/attachmentSources.d.ts +0 -10
- package/lib/live/attachments/attachmentSources.d.ts.map +0 -1
- package/lib/live/attachments/attachmentSources.js +0 -64
- package/lib/live/attachments/attachmentSources.js.map +0 -1
- package/lib/live/attachments/unsupportedOntologyAttachmentsAdapter.d.ts +0 -5
- package/lib/live/attachments/unsupportedOntologyAttachmentsAdapter.d.ts.map +0 -1
- package/lib/live/attachments/unsupportedOntologyAttachmentsAdapter.js +0 -6
- package/lib/live/attachments/unsupportedOntologyAttachmentsAdapter.js.map +0 -1
- package/lib/live/expression.d.ts +0 -23
- package/lib/live/expression.d.ts.map +0 -1
- package/lib/live/expression.js +0 -160
- package/lib/live/expression.js.map +0 -1
- package/lib/live/mutators/OntologyEdits.d.ts +0 -15
- package/lib/live/mutators/OntologyEdits.d.ts.map +0 -1
- package/lib/live/mutators/OntologyEdits.js +0 -65
- package/lib/live/mutators/OntologyEdits.js.map +0 -1
- package/lib/live/mutators/createMutatorTx.d.ts +0 -11
- package/lib/live/mutators/createMutatorTx.d.ts.map +0 -1
- package/lib/live/mutators/createMutatorTx.js +0 -61
- package/lib/live/mutators/createMutatorTx.js.map +0 -1
- package/lib/live/mutators/runOptimisticAction.d.ts +0 -19
- package/lib/live/mutators/runOptimisticAction.d.ts.map +0 -1
- package/lib/live/mutators/runOptimisticAction.js +0 -30
- package/lib/live/mutators/runOptimisticAction.js.map +0 -1
- package/lib/live/objects/OntologyObject.d.ts +0 -4
- package/lib/live/objects/OntologyObject.d.ts.map +0 -1
- package/lib/live/objects/OntologyObject.js +0 -1
- package/lib/live/objects/createLiveOntologyObjectCollection.d.ts +0 -17
- package/lib/live/objects/createLiveOntologyObjectCollection.d.ts.map +0 -1
- package/lib/live/objects/createLiveOntologyObjectCollection.js +0 -55
- package/lib/live/objects/createLiveOntologyObjectCollection.js.map +0 -1
- package/lib/live/objects/ontologyObjectCollectionId.d.ts +0 -4
- package/lib/live/objects/ontologyObjectCollectionId.d.ts.map +0 -1
- package/lib/live/objects/ontologyObjectCollectionId.js +0 -8
- package/lib/live/objects/ontologyObjectCollectionId.js.map +0 -1
- package/lib/live/outbox/createOntologyOutbox.d.ts +0 -23
- package/lib/live/outbox/createOntologyOutbox.d.ts.map +0 -1
- package/lib/live/outbox/createOntologyOutbox.js +0 -292
- package/lib/live/outbox/createOntologyOutbox.js.map +0 -1
- package/lib/live/outbox/leaderExecutor.d.ts +0 -20
- package/lib/live/outbox/leaderExecutor.d.ts.map +0 -1
- package/lib/live/outbox/leaderExecutor.js +0 -130
- package/lib/live/outbox/leaderExecutor.js.map +0 -1
- package/lib/live/outbox/outboxService.d.ts +0 -7
- package/lib/live/outbox/outboxService.d.ts.map +0 -1
- package/lib/live/outbox/outboxService.js +0 -68
- package/lib/live/outbox/outboxService.js.map +0 -1
- package/lib/live/outbox/projectionManager.d.ts +0 -31
- package/lib/live/outbox/projectionManager.d.ts.map +0 -1
- package/lib/live/outbox/projectionManager.js +0 -127
- package/lib/live/outbox/projectionManager.js.map +0 -1
- package/lib/live/outbox/repository.d.ts +0 -31
- package/lib/live/outbox/repository.d.ts.map +0 -1
- package/lib/live/outbox/repository.js +0 -196
- package/lib/live/outbox/repository.js.map +0 -1
- package/lib/live/outbox/service.d.ts +0 -61
- package/lib/live/outbox/service.d.ts.map +0 -1
- package/lib/live/outbox/service.js +0 -6
- package/lib/live/outbox/service.js.map +0 -1
- package/lib/live/outbox/types.js.map +0 -1
- package/lib/live/waitForCollectionReady.d.ts +0 -5
- package/lib/live/waitForCollectionReady.d.ts.map +0 -1
- package/lib/live/waitForCollectionReady.js +0 -49
- package/lib/live/waitForCollectionReady.js.map +0 -1
- package/lib/meta/createLocalMetaOntologyBackendAdapter.d.ts +0 -7
- package/lib/meta/createLocalMetaOntologyBackendAdapter.d.ts.map +0 -1
- package/lib/meta/createLocalMetaOntologyBackendAdapter.js +0 -44
- package/lib/meta/createLocalMetaOntologyBackendAdapter.js.map +0 -1
- package/lib/meta/generated/constants.d.ts +0 -265
- package/lib/meta/generated/constants.d.ts.map +0 -1
- package/lib/meta/generated/constants.js +0 -165
- package/lib/meta/generated/constants.js.map +0 -1
- package/lib/meta/generated/types.d.ts +0 -417
- package/lib/meta/generated/types.d.ts.map +0 -1
- package/lib/meta/generated/types.js +0 -1
- package/lib/meta/ontology.d.ts +0 -26
- package/lib/meta/ontology.d.ts.map +0 -1
- package/lib/meta/ontology.js +0 -111
- package/lib/meta/ontology.js.map +0 -1
- package/lib/utils/links.d.ts +0 -49
- package/lib/utils/links.d.ts.map +0 -1
- package/lib/utils/links.js +0 -13
- package/lib/utils/links.js.map +0 -1
- package/lib/utils/paths.d.ts +0 -6
- package/lib/utils/paths.d.ts.map +0 -1
- package/lib/utils/paths.js +0 -42
- package/lib/utils/paths.js.map +0 -1
- package/lib/utils/provide.d.ts +0 -4
- package/lib/utils/provide.d.ts.map +0 -1
- package/lib/utils/provide.js +0 -9
- package/lib/utils/provide.js.map +0 -1
- package/lib/utils/targets.d.ts +0 -37
- package/lib/utils/targets.d.ts.map +0 -1
- package/lib/utils/targets.js +0 -1
- package/lib/utils/typeNames.d.ts +0 -28
- package/lib/utils/typeNames.d.ts.map +0 -1
- package/lib/utils/typeNames.js +0 -1
- package/lib/utils/types.d.ts +0 -12
- package/lib/utils/types.d.ts.map +0 -1
- package/lib/utils/types.js +0 -48
- package/lib/utils/types.js.map +0 -1
- package/lib/utils/uncertain.d.ts +0 -11
- package/lib/utils/uncertain.d.ts.map +0 -1
- package/lib/utils/uncertain.js +0 -14
- package/lib/utils/uncertain.js.map +0 -1
- package/lib/utils/validation.d.ts +0 -7
- package/lib/utils/validation.d.ts.map +0 -1
- package/lib/utils/validation.js +0 -1
- package/lib/utils/values.d.ts.map +0 -1
- /package/lib/{installation → live/actions}/types.js +0 -0
- /package/lib/{ir/generated → live/objects}/types.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live.d.ts","names":["_$___index_js0.LiveOntology"],"sources":["../../src/runtime/live.ts"],"mappings":";;;;;;YAKY,qBAAqB;WAAgC,iBAAiB;;;qBAErE,sBAAmB,SAAA,uBAAA,OAAA;;;eAAAA;;;;;;;2CAI9B,gYAAA,iCAAA;;qBAGW,0BAAuB,SAAA,uBAAA,OAAA,OAAA,KAAAA,kDAAA,yEAAA,gYAAA,iCAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { makeReplicaHost } from "./host.js";
|
|
2
|
+
import { makeReplicaOntologyView } from "./view.js";
|
|
3
|
+
import { Effect, Tracer } from "effect";
|
|
4
|
+
import { makeTraceCapture } from "@party-stack/runtime/tracing";
|
|
5
|
+
//#region src/runtime/live.ts
|
|
6
|
+
/** Native host acquisition with an independently configured tracer. No UI collections. */
|
|
7
|
+
const makeReplicaResource = Effect.fnUntraced(function* (options) {
|
|
8
|
+
const traces = yield* makeTraceCapture(options.traceRecording);
|
|
9
|
+
const open = makeReplicaHost(options).pipe(Effect.map((host) => ({
|
|
10
|
+
...host,
|
|
11
|
+
traces
|
|
12
|
+
})));
|
|
13
|
+
return yield* traces ? open.pipe(Effect.provideService(Tracer.Tracer, traces.tracer)) : open;
|
|
14
|
+
});
|
|
15
|
+
/** SDK view over a scoped native host. */
|
|
16
|
+
const makeReplicaLiveOntology = Effect.fnUntraced(function* (options) {
|
|
17
|
+
const { replica, attachments, traces } = yield* makeReplicaResource(options);
|
|
18
|
+
const view = makeReplicaOntologyView({
|
|
19
|
+
ir: options.ir,
|
|
20
|
+
context: options.context,
|
|
21
|
+
replica,
|
|
22
|
+
writes: options.writes,
|
|
23
|
+
attachments,
|
|
24
|
+
traces
|
|
25
|
+
});
|
|
26
|
+
return yield* traces ? view.pipe(Effect.provideService(Tracer.Tracer, traces.tracer)) : view;
|
|
27
|
+
});
|
|
28
|
+
//#endregion
|
|
29
|
+
export { makeReplicaLiveOntology, makeReplicaResource };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=live.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live.js","names":[],"sources":["../../src/runtime/live.ts"],"sourcesContent":["import { makeTraceCapture, type TraceRecordingMode } from \"@party-stack/runtime/tracing\";\nimport { Effect, Tracer } from \"effect\";\nimport { makeReplicaHost, type ReplicaHostOptions } from \"./host.js\";\nimport { makeReplicaOntologyView } from \"./view.js\";\n\nexport type ReplicaLiveOptions = ReplicaHostOptions & { readonly traceRecording?: TraceRecordingMode };\n/** Native host acquisition with an independently configured tracer. No UI collections. */\nexport const makeReplicaResource = Effect.fnUntraced(function* (options: ReplicaLiveOptions) {\n const traces = yield* makeTraceCapture(options.traceRecording);\n const open = makeReplicaHost(options).pipe(Effect.map((host) => ({ ...host, traces })));\n return yield* traces ? open.pipe(Effect.provideService(Tracer.Tracer, traces.tracer)) : open;\n});\n\n/** SDK view over a scoped native host. */\nexport const makeReplicaLiveOntology = Effect.fnUntraced(function* (options: ReplicaLiveOptions) {\n const { replica, attachments, traces } = yield* makeReplicaResource(options);\n const view = makeReplicaOntologyView({\n ir: options.ir,\n context: options.context,\n replica,\n writes: options.writes,\n attachments,\n\n traces,\n });\n return yield* traces ? view.pipe(Effect.provideService(Tracer.Tracer, traces.tracer)) : view;\n});\n"],"mappings":";;;;;;AAOA,MAAa,sBAAsB,OAAO,WAAW,WAAW,SAA6B;CACzF,MAAM,SAAS,OAAO,iBAAiB,QAAQ,cAAc;CAC7D,MAAM,OAAO,gBAAgB,OAAO,CAAC,CAAC,KAAK,OAAO,KAAK,UAAU;EAAE,GAAG;EAAM;CAAO,EAAE,CAAC;CACtF,OAAO,OAAO,SAAS,KAAK,KAAK,OAAO,eAAe,OAAO,QAAQ,OAAO,MAAM,CAAC,IAAI;AAC5F,CAAC;;AAGD,MAAa,0BAA0B,OAAO,WAAW,WAAW,SAA6B;CAC7F,MAAM,EAAE,SAAS,aAAa,WAAW,OAAO,oBAAoB,OAAO;CAC3E,MAAM,OAAO,wBAAwB;EACjC,IAAI,QAAQ;EACZ,SAAS,QAAQ;EACjB;EACA,QAAQ,QAAQ;EAChB;EAEA;CACJ,CAAC;CACD,OAAO,OAAO,SAAS,KAAK,KAAK,OAAO,eAAe,OAAO,QAAQ,OAAO,MAAM,CAAC,IAAI;AAC5F,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { LiveOntology, LiveOntologyOptions, OntologyDefinition } from "../live/LiveOntology.js";
|
|
2
|
+
import { BackendError } from "@party-stack/ontology-backend";
|
|
3
|
+
import { Runtimes } from "@party-stack/runtime";
|
|
4
|
+
import { Effect, Scope, Tracer } from "effect";
|
|
5
|
+
//#region src/runtime/resource.d.ts
|
|
6
|
+
/** Native acquisition. Runtime, backend, collections and replica fibers share the caller's Scope. */
|
|
7
|
+
export declare const makeOntologyResource: <Ontology extends OntologyDefinition = OntologyDefinition, Context extends Record<string, unknown> = Record<string, unknown>>(opts: LiveOntologyOptions<Context>) => Effect.Effect<{
|
|
8
|
+
replica: import("@party-stack/ontology-replica").ReplicaService;
|
|
9
|
+
backend: import("@party-stack/ontology-backend").OntologyBackendService;
|
|
10
|
+
attachments: LiveOntology["attachments"];
|
|
11
|
+
traces: {
|
|
12
|
+
tracer: Tracer.Tracer;
|
|
13
|
+
getSnapshot: () => readonly import("@party-stack/runtime/tracing").TraceRecord[];
|
|
14
|
+
subscribe: (listener: (record?: import("@party-stack/runtime/tracing").TraceRecord) => void) => () => void;
|
|
15
|
+
clear: () => void;
|
|
16
|
+
} | undefined;
|
|
17
|
+
ir: import("@party-stack/ontology-spec").OntologyIR;
|
|
18
|
+
context: Context;
|
|
19
|
+
close: Effect.Effect<void, never, never>;
|
|
20
|
+
view: Effect.Effect<LiveOntology<Ontology>, BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced">, never>;
|
|
21
|
+
}, BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced"> | import("@party-stack/runtime").RuntimeAcquisitionError, Runtimes | Scope.Scope>;
|
|
22
|
+
export type OntologyResource = Effect.Success<ReturnType<typeof makeOntologyResource>>;
|
|
23
|
+
//#endregion
|
|
24
|
+
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.d.ts","names":[],"sources":["../../src/runtime/resource.ts"],"mappings":";;;;;;qBAWa,uBACT,iBAAiB,qBAAkB,oBACnC,gBAAgB,0BAAuB,yBAAA,MAAA,oBAAA,aAAA,OAAA;;;;;;;;;;;;;;GAyJzC,iYAAA,yBAAA,WAAA,MAAA;YAEU,mBAAmB,OAAO,QAAQ,kBAAkB"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { makeReplicaOntologyView } from "./view.js";
|
|
2
|
+
import { makeReplicaResource } from "./live.js";
|
|
3
|
+
import { BackendError } from "@party-stack/ontology-backend";
|
|
4
|
+
import { Runtime, Runtimes } from "@party-stack/runtime";
|
|
5
|
+
import { Effect, Exit, Scope, Stream, Tracer } from "effect";
|
|
6
|
+
import { equalValues } from "@party-stack/ontology-spec/query";
|
|
7
|
+
import { contextPartition } from "@party-stack/ontology-spec/utils";
|
|
8
|
+
import { ontologyDefinitionSignature } from "@party-stack/ontology-storage";
|
|
9
|
+
import { digestBytes } from "@party-stack/ontology-storage/blobs";
|
|
10
|
+
//#region src/runtime/resource.ts
|
|
11
|
+
/** Native acquisition. Runtime, backend, collections and replica fibers share the caller's Scope. */
|
|
12
|
+
const makeOntologyResource = Effect.fn("Ontology.acquire")(function* (opts) {
|
|
13
|
+
const scope = yield* Scope.fork(yield* Effect.scope);
|
|
14
|
+
const opened = Effect.gen(function* () {
|
|
15
|
+
const platformScope = yield* Scope.fork(scope);
|
|
16
|
+
const transportScope = yield* Scope.fork(scope);
|
|
17
|
+
const remote = opts.client ? yield* Scope.provide(Effect.isEffect(opts.client) ? opts.client : Effect.succeed(opts.client), transportScope) : void 0;
|
|
18
|
+
const client = remote && "ontology" in remote ? yield* Scope.provide(remote.ontology(opts.ontology), transportScope) : remote;
|
|
19
|
+
const ir = opts.ir ?? client?.ir;
|
|
20
|
+
if (!ir) return yield* new BackendError({
|
|
21
|
+
operation: "ontology.create",
|
|
22
|
+
kind: "InvalidConfiguration",
|
|
23
|
+
retryable: false,
|
|
24
|
+
message: "Supply an ontology definition when the server does not describe one."
|
|
25
|
+
});
|
|
26
|
+
if (client && opts.ir && client.definitionHash) {
|
|
27
|
+
const signature = yield* Effect.try({
|
|
28
|
+
try: () => ontologyDefinitionSignature(ir),
|
|
29
|
+
catch: (cause) => new BackendError({
|
|
30
|
+
operation: "ontology.create",
|
|
31
|
+
kind: "InvalidConfiguration",
|
|
32
|
+
retryable: false,
|
|
33
|
+
message: "Invalid client ontology definition.",
|
|
34
|
+
cause
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
if ((yield* digestBytes({
|
|
38
|
+
type: "application/json",
|
|
39
|
+
stream: Stream.make(new TextEncoder().encode(signature))
|
|
40
|
+
}).pipe(Effect.mapError((cause) => new BackendError({
|
|
41
|
+
operation: "ontology.create",
|
|
42
|
+
kind: "Internal",
|
|
43
|
+
retryable: false,
|
|
44
|
+
message: "Could not identify the client definition.",
|
|
45
|
+
cause
|
|
46
|
+
})))) !== client.definitionHash) return yield* new BackendError({
|
|
47
|
+
operation: "ontology.create",
|
|
48
|
+
kind: "SchemaMismatch",
|
|
49
|
+
retryable: false,
|
|
50
|
+
message: "Server definition differs from this client."
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (client?.context && opts.context && !equalValues(client.context, opts.context)) return yield* new BackendError({
|
|
54
|
+
operation: "ontology.create",
|
|
55
|
+
kind: "InvalidConfiguration",
|
|
56
|
+
retryable: false,
|
|
57
|
+
message: "Client context differs from the authenticated server context."
|
|
58
|
+
});
|
|
59
|
+
const ontologyId = opts.id ?? (client ? JSON.stringify(["source", client.sourceId]) : "default");
|
|
60
|
+
const context = client?.context ?? opts.context ?? {};
|
|
61
|
+
const owner = yield* Effect.try({
|
|
62
|
+
try: () => contextPartition(ir, context),
|
|
63
|
+
catch: (cause) => new BackendError({
|
|
64
|
+
operation: "runtime.partition",
|
|
65
|
+
kind: "InvalidConfiguration",
|
|
66
|
+
message: "Invalid context partition.",
|
|
67
|
+
retryable: false,
|
|
68
|
+
cause
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
const runtime = yield* Scope.provide(Effect.flatMap(Runtimes, (runtimes) => runtimes.acquire({
|
|
72
|
+
owner,
|
|
73
|
+
namespace: ontologyId
|
|
74
|
+
})), platformScope);
|
|
75
|
+
const resources = yield* Scope.fork(yield* Effect.scope);
|
|
76
|
+
return yield* Scope.provide(Effect.gen(function* () {
|
|
77
|
+
const source = client?.replication.kind === "speculative" ? client.replication.source : void 0;
|
|
78
|
+
const backend = client?.backend ?? (yield* (Effect.isEffect(opts.backend) ? opts.backend : Effect.succeed(opts.backend)).pipe(Effect.provideService(Runtime, runtime)));
|
|
79
|
+
const host = yield* makeReplicaResource({
|
|
80
|
+
backend,
|
|
81
|
+
source,
|
|
82
|
+
ir,
|
|
83
|
+
traceRecording: opts.traceRecording,
|
|
84
|
+
context,
|
|
85
|
+
writes: opts.writes,
|
|
86
|
+
live: opts.live,
|
|
87
|
+
demand: opts.demand,
|
|
88
|
+
cache: opts.cache,
|
|
89
|
+
authentication: opts.authentication
|
|
90
|
+
}).pipe(Effect.provideService(Runtime, runtime));
|
|
91
|
+
const close = Scope.close(scope, Exit.void);
|
|
92
|
+
const view = yield* Effect.cached(Scope.provide(makeReplicaOntologyView({
|
|
93
|
+
ir,
|
|
94
|
+
context,
|
|
95
|
+
replica: host.replica,
|
|
96
|
+
writes: opts.writes,
|
|
97
|
+
attachments: host.attachments,
|
|
98
|
+
pins: client?.pins,
|
|
99
|
+
pinBackend: client?.pinBackend,
|
|
100
|
+
diagnosticLabel: opts.label,
|
|
101
|
+
parentDiagnostics: client && (source || opts.parent) ? {
|
|
102
|
+
label: opts.parent?.label ?? "Parent",
|
|
103
|
+
role: "host",
|
|
104
|
+
location: opts.parent?.location,
|
|
105
|
+
replica: client.operations.replicaMonitor,
|
|
106
|
+
traces: client.operations.traces
|
|
107
|
+
} : void 0,
|
|
108
|
+
traces: host.traces
|
|
109
|
+
}).pipe(Effect.provideService(Runtime, runtime), (work) => host.traces ? work.pipe(Effect.provideService(Tracer.Tracer, host.traces.tracer)) : work), resources).pipe(Effect.map((view) => ({
|
|
110
|
+
...view,
|
|
111
|
+
cleanup: () => Effect.runPromise(close)
|
|
112
|
+
}))));
|
|
113
|
+
return {
|
|
114
|
+
...host,
|
|
115
|
+
ir,
|
|
116
|
+
context,
|
|
117
|
+
close,
|
|
118
|
+
view
|
|
119
|
+
};
|
|
120
|
+
}), resources);
|
|
121
|
+
});
|
|
122
|
+
return yield* Scope.provide(opened, scope).pipe(Effect.onExit((exit) => Exit.isFailure(exit) ? Scope.close(scope, exit) : Effect.void));
|
|
123
|
+
});
|
|
124
|
+
//#endregion
|
|
125
|
+
export { makeOntologyResource };
|
|
126
|
+
|
|
127
|
+
//# sourceMappingURL=resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.js","names":[],"sources":["../../src/runtime/resource.ts"],"sourcesContent":["import { BackendError } from \"@party-stack/ontology-backend\";\nimport { equalValues } from \"@party-stack/ontology-spec/query\";\nimport { contextPartition } from \"@party-stack/ontology-spec/utils\";\nimport { ontologyDefinitionSignature } from \"@party-stack/ontology-storage\";\nimport { digestBytes } from \"@party-stack/ontology-storage/blobs\";\nimport { Runtime, Runtimes } from \"@party-stack/runtime\";\nimport { Effect, Exit, Scope, Tracer, Stream } from \"effect\";\nimport { makeReplicaResource } from \"./live.js\";\nimport { makeReplicaOntologyView } from \"./view.js\";\nimport type { LiveOntologyOptions, LiveOntology, OntologyDefinition } from \"../live/LiveOntology.js\";\n/** Native acquisition. Runtime, backend, collections and replica fibers share the caller's Scope. */\nexport const makeOntologyResource = Effect.fn(\"Ontology.acquire\")(function* <\n Ontology extends OntologyDefinition = OntologyDefinition,\n Context extends Record<string, unknown> = Record<string, unknown>,\n>(opts: LiveOntologyOptions<Context>) {\n const scope = yield* Scope.fork(yield* Effect.scope);\n const opened = Effect.gen(function* () {\n // Close views/replication first, then transport, then local platform storage.\n const platformScope = yield* Scope.fork(scope);\n const transportScope = yield* Scope.fork(scope);\n const remote = opts.client\n ? yield* Scope.provide(\n Effect.isEffect(opts.client) ? opts.client : Effect.succeed(opts.client),\n transportScope\n )\n : undefined;\n const client =\n remote && \"ontology\" in remote\n ? yield* Scope.provide(remote.ontology(opts.ontology), transportScope)\n : remote;\n const ir = opts.ir ?? client?.ir;\n if (!ir)\n return yield* new BackendError({\n operation: \"ontology.create\",\n kind: \"InvalidConfiguration\",\n retryable: false,\n message: \"Supply an ontology definition when the server does not describe one.\",\n });\n if (client && opts.ir && client.definitionHash) {\n const signature = yield* Effect.try({\n try: () => ontologyDefinitionSignature(ir),\n catch: (cause) =>\n new BackendError({\n operation: \"ontology.create\",\n kind: \"InvalidConfiguration\",\n retryable: false,\n message: \"Invalid client ontology definition.\",\n cause,\n }),\n });\n const hash = yield* digestBytes({\n type: \"application/json\",\n stream: Stream.make(new TextEncoder().encode(signature)),\n }).pipe(\n Effect.mapError(\n (cause) =>\n new BackendError({\n operation: \"ontology.create\",\n kind: \"Internal\",\n retryable: false,\n message: \"Could not identify the client definition.\",\n cause,\n })\n )\n );\n if (hash !== client.definitionHash)\n return yield* new BackendError({\n operation: \"ontology.create\",\n kind: \"SchemaMismatch\",\n retryable: false,\n message: \"Server definition differs from this client.\",\n });\n }\n if (client?.context && opts.context && !equalValues(client.context, opts.context))\n return yield* new BackendError({\n operation: \"ontology.create\",\n kind: \"InvalidConfiguration\",\n retryable: false,\n message: \"Client context differs from the authenticated server context.\",\n });\n const ontologyId = opts.id ?? (client ? JSON.stringify([\"source\", client.sourceId]) : \"default\");\n const context = (client?.context ?? opts.context ?? {}) as Context;\n const owner = yield* Effect.try({\n try: () => contextPartition(ir, context),\n catch: (cause) =>\n new BackendError({\n operation: \"runtime.partition\",\n kind: \"InvalidConfiguration\",\n message: \"Invalid context partition.\",\n retryable: false,\n cause,\n }),\n });\n const runtime = yield* Scope.provide(\n Effect.flatMap(Runtimes, (runtimes) => runtimes.acquire({ owner, namespace: ontologyId })),\n platformScope\n );\n const resources = yield* Scope.fork(yield* Effect.scope);\n return yield* Scope.provide(\n Effect.gen(function* () {\n const source =\n client?.replication.kind === \"speculative\" ? client.replication.source : undefined;\n const backend =\n client?.backend ??\n (yield* (\n Effect.isEffect(opts.backend) ? opts.backend : Effect.succeed(opts.backend!)\n ).pipe(Effect.provideService(Runtime, runtime)));\n const host = yield* makeReplicaResource({\n backend,\n source,\n ir,\n traceRecording: opts.traceRecording,\n context,\n writes: opts.writes,\n live: opts.live,\n demand: opts.demand,\n cache: opts.cache,\n authentication: opts.authentication,\n }).pipe(Effect.provideService(Runtime, runtime));\n const close = Scope.close(scope, Exit.void);\n const view = yield* Effect.cached(\n Scope.provide(\n makeReplicaOntologyView({\n ir,\n context,\n replica: host.replica,\n writes: opts.writes,\n attachments: host.attachments,\n pins: client?.pins,\n pinBackend: client?.pinBackend,\n diagnosticLabel: opts.label,\n parentDiagnostics:\n client && (source || opts.parent)\n ? {\n label: opts.parent?.label ?? \"Parent\",\n role: \"host\",\n location: opts.parent?.location,\n replica: client.operations.replicaMonitor,\n traces: client.operations.traces,\n }\n : undefined,\n traces: host.traces,\n }).pipe(Effect.provideService(Runtime, runtime), (work) =>\n host.traces\n ? work.pipe(Effect.provideService(Tracer.Tracer, host.traces.tracer))\n : work\n ),\n resources\n ).pipe(\n Effect.map(\n (view) =>\n ({\n ...view,\n cleanup: () => Effect.runPromise(close),\n }) as LiveOntology<Ontology>\n )\n )\n );\n return { ...host, ir, context, close, view };\n }),\n resources\n );\n });\n return yield* Scope.provide(opened, scope).pipe(\n Effect.onExit((exit) => (Exit.isFailure(exit) ? Scope.close(scope, exit) : Effect.void))\n );\n});\n\nexport type OntologyResource = Effect.Success<ReturnType<typeof makeOntologyResource>>;\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,uBAAuB,OAAO,GAAG,kBAAkB,CAAC,CAAC,WAGhE,MAAoC;CAClC,MAAM,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I,WAAW,UAAU,KAAK,UACpB;KACI,OAAO,KAAK,QAAQ,SAAS;KAC7B,MAAM;KACN,UAAU,KAAK,QAAQ;KACvB,SAAS,OAAO,WAAW;KAC3B,QAAQ,OAAO,WAAW;IAC9B,IACA,KAAA;IACV,QAAQ,KAAK;GACjB,CAAC,CAAC,CAAC,KAAK,OAAO,eAAe,SAAS,OAAO,IAAI,SAC9C,KAAK,SACC,KAAK,KAAK,OAAO,eAAe,OAAO,QAAQ,KAAK,OAAO,MAAM,CAAC,IAClE,IACV,GACA,SACJ,CAAC,CAAC,KACE,OAAO,KACF,UACI;IACG,GAAG;IACH,eAAe,OAAO,WAAW,KAAK;GAC1C,EACR,CACJ,CACJ;GACA,OAAO;IAAE,GAAG;IAAM;IAAI;IAAS;IAAO;GAAK;EAC/C,CAAC,GACD,SACJ;CACJ,CAAC;CACD,OAAO,OAAO,MAAM,QAAQ,QAAQ,KAAK,CAAC,CAAC,KACvC,OAAO,QAAQ,SAAU,KAAK,UAAU,IAAI,IAAI,MAAM,MAAM,OAAO,IAAI,IAAI,OAAO,IAAK,CAC3F;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { OntologyMutatorRegistry, PrepareTransactionSources } from "../live/mutators/types.js";
|
|
2
|
+
import { ActionRequest, BackendError } from "@party-stack/ontology-backend";
|
|
3
|
+
import { Effect } from "effect";
|
|
4
|
+
import { Collection, DbClient } from "@tanstack/db";
|
|
5
|
+
import { OntologyIR, OntologyObject } from "@party-stack/ontology-spec";
|
|
6
|
+
import { ActionMutatorRegistry } from "@party-stack/ontology-backend/actions";
|
|
7
|
+
import { OwnedReadTransaction, OwnedTransaction } from "@party-stack/ontology-backend/owned";
|
|
8
|
+
//#region src/runtime/transactions.d.ts
|
|
9
|
+
type ExpressionReplay = NonNullable<ActionRequest["replay"]>;
|
|
10
|
+
/** Ephemeral query collections; their only source is the supplied persisted transaction. */
|
|
11
|
+
export declare const withTransactionCollections: <A, E, R>(ir: OntologyIR, tx: OwnedReadTransaction, body: (objects: Record<string, Collection<OntologyObject>>, ensureLoaded: PrepareTransactionSources, client: DbClient) => Effect.Effect<A, E, R>) => Effect.Effect<A, E | BackendError, R>;
|
|
12
|
+
/** Promise/TanStack authoring bridge only. Portable action logic and replay live below ontology. */
|
|
13
|
+
export declare const actionMutators: (ir: OntologyIR, registry?: OntologyMutatorRegistry) => ActionMutatorRegistry;
|
|
14
|
+
export declare const executeTransactionMutator: (options: {
|
|
15
|
+
readonly ir: OntologyIR;
|
|
16
|
+
readonly tx: OwnedTransaction;
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly parameters: Record<string, unknown>;
|
|
19
|
+
readonly operationId: string;
|
|
20
|
+
readonly replay?: ExpressionReplay;
|
|
21
|
+
readonly resolveOnly?: boolean;
|
|
22
|
+
readonly context?: Record<string, unknown>;
|
|
23
|
+
readonly mutators?: OntologyMutatorRegistry;
|
|
24
|
+
}) => 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>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=transactions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactions.d.ts","names":[],"sources":["../../src/runtime/transactions.ts"],"mappings":";;;;;;;;KAQK,mBAAmB,YAAY;;qBAoBvB,6BAA8B,GAAG,GAAG,GAAC,IAC1C,YAAU,IACV,sBAAoB,OAEpB,SAAS,eAAe,WAAW,kBACnC,cAAc,2BACd,QAAQ,aACP,OAAO,OAAO,GAAG,GAAG,OAC1B,OAAO,OAAO,GAAG,IAAI,cAAc;;qBAqHzB,iBAAc,IACnB,YAAU,WACJ,4BACX;qBA+IU,4BAAyB;WACrB,IAAA;WACA,IAAA;WACE;WACM,YAAA;WACC;WACJ,SAAA;WACK;WACJ,UAAA;WACC,WAAA;MAetB,OAAA,gBAAA,oBAAA"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { createReadTx } from "../live/mutators/createReadTx.js";
|
|
2
|
+
import { storageSubset } from "../tanstack/subset.js";
|
|
3
|
+
import "../tanstack/index.js";
|
|
4
|
+
import { BackendError } from "@party-stack/ontology-backend";
|
|
5
|
+
import { Effect, Fiber, Semaphore } from "effect";
|
|
6
|
+
import { BasicIndex, DbClient, collectionOptions, whenSyncAccepted } from "@tanstack/db";
|
|
7
|
+
import { executeAction } from "@party-stack/ontology-backend/actions";
|
|
8
|
+
import { Table } from "@party-stack/ontology-storage/tables";
|
|
9
|
+
//#region src/runtime/transactions.ts
|
|
10
|
+
const failure = (cause) => cause instanceof BackendError ? cause : new BackendError({
|
|
11
|
+
operation: "mutator",
|
|
12
|
+
kind: "Internal",
|
|
13
|
+
message: cause instanceof Error ? cause.message : "Transaction execution failed.",
|
|
14
|
+
retryable: false,
|
|
15
|
+
cause
|
|
16
|
+
});
|
|
17
|
+
/** Ephemeral query collections; their only source is the supplied persisted transaction. */
|
|
18
|
+
const withTransactionCollections = (ir, tx, body) => Effect.scoped(Effect.gen(function* () {
|
|
19
|
+
const context = yield* Effect.context();
|
|
20
|
+
const scope = yield* Effect.scope;
|
|
21
|
+
let closed = false;
|
|
22
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => {
|
|
23
|
+
closed = true;
|
|
24
|
+
}));
|
|
25
|
+
const run = (effect) => closed ? Promise.reject(failure("Transaction query scope is closed.")) : Effect.runPromiseWith(context)(Effect.flatMap(Effect.forkIn(effect, scope), Fiber.join));
|
|
26
|
+
const client = yield* Effect.acquireRelease(Effect.sync(() => new DbClient()), (client) => Effect.promise(() => client.cleanup()));
|
|
27
|
+
const publishers = /* @__PURE__ */ new Map();
|
|
28
|
+
const loaded = /* @__PURE__ */ new Map();
|
|
29
|
+
const objects = Object.fromEntries(ir.objectTypes.map((definition) => [definition.name, client.collection(collectionOptions({
|
|
30
|
+
id: `transaction:${crypto.randomUUID()}:${definition.name}`,
|
|
31
|
+
getKey: (value) => value[definition.primaryKey],
|
|
32
|
+
syncMode: "on-demand",
|
|
33
|
+
defaultIndexType: BasicIndex,
|
|
34
|
+
autoIndex: "eager",
|
|
35
|
+
startSync: true,
|
|
36
|
+
sync: {
|
|
37
|
+
rowUpdateMode: "full",
|
|
38
|
+
sync: ({ begin, write, commit, markReady, fail, collection }) => {
|
|
39
|
+
const published = new Set(collection.keys());
|
|
40
|
+
const requests = /* @__PURE__ */ new Map();
|
|
41
|
+
publishers.set(definition.name, async (rows) => {
|
|
42
|
+
if (closed) throw failure("Transaction query scope is closed.");
|
|
43
|
+
begin();
|
|
44
|
+
for (const row of rows) {
|
|
45
|
+
write({
|
|
46
|
+
type: published.has(row.key) ? "update" : "insert",
|
|
47
|
+
value: row.value
|
|
48
|
+
});
|
|
49
|
+
published.add(row.key);
|
|
50
|
+
}
|
|
51
|
+
const receipt = commit();
|
|
52
|
+
if (receipt !== true) receipt.catch(fail);
|
|
53
|
+
await whenSyncAccepted(receipt);
|
|
54
|
+
});
|
|
55
|
+
markReady();
|
|
56
|
+
return {
|
|
57
|
+
loadSubset: (subset) => {
|
|
58
|
+
const query = storageSubset(subset, ir, definition.name);
|
|
59
|
+
const key = Table.make({ name: "transaction-demand" }).encode(query);
|
|
60
|
+
let pending = requests.get(key);
|
|
61
|
+
if (!pending) {
|
|
62
|
+
pending = run(Effect.flatMap(tx.loadSubset(definition.name, query), (rows) => Effect.promise(() => publishers.get(definition.name)(rows))));
|
|
63
|
+
requests.set(key, pending);
|
|
64
|
+
pending.catch(() => requests.delete(key));
|
|
65
|
+
}
|
|
66
|
+
return pending;
|
|
67
|
+
},
|
|
68
|
+
cleanup: () => {
|
|
69
|
+
publishers.delete(definition.name);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}))]));
|
|
75
|
+
const ensureLoaded = async (types, request) => {
|
|
76
|
+
if (request?.plan !== void 0) return;
|
|
77
|
+
for (const type of types) {
|
|
78
|
+
const key = JSON.stringify([type, request?.key]);
|
|
79
|
+
let pending = loaded.get(key);
|
|
80
|
+
if (!pending) {
|
|
81
|
+
const publish = publishers.get(type);
|
|
82
|
+
if (!publish) throw failure("Unknown transaction query source.");
|
|
83
|
+
const read = request?.key === void 0 ? tx.loadSubset(type) : Effect.map(tx.get(type, request.key), (value) => value === void 0 ? [] : [{
|
|
84
|
+
key: request.key,
|
|
85
|
+
value
|
|
86
|
+
}]);
|
|
87
|
+
pending = run(Effect.flatMap(read, (rows) => Effect.promise(() => publish(rows))));
|
|
88
|
+
loaded.set(key, pending);
|
|
89
|
+
}
|
|
90
|
+
await pending;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
return yield* body(objects, ensureLoaded, client);
|
|
94
|
+
}));
|
|
95
|
+
/** Promise/TanStack authoring bridge only. Portable action logic and replay live below ontology. */
|
|
96
|
+
const actionMutators = (ir, registry = {}) => Object.fromEntries(Object.entries(registry).map(([name, handler]) => [name, (tx, request, context) => Effect.scoped(Effect.gen(function* () {
|
|
97
|
+
const services = yield* Effect.context();
|
|
98
|
+
const scope = yield* Effect.scope;
|
|
99
|
+
let closed = false;
|
|
100
|
+
const reads = /* @__PURE__ */ new Map();
|
|
101
|
+
const codec = Table.make({ name: "mutator-reads" });
|
|
102
|
+
const cached = (key, work) => Effect.suspend(() => {
|
|
103
|
+
const encoded = codec.encode(key);
|
|
104
|
+
return reads.has(encoded) ? Effect.succeed(reads.get(encoded)) : work.pipe(Effect.tap((value) => Effect.sync(() => reads.set(encoded, value))));
|
|
105
|
+
});
|
|
106
|
+
const invalidate = Effect.sync(() => reads.clear());
|
|
107
|
+
const mutations = yield* Semaphore.make(1);
|
|
108
|
+
const local = {
|
|
109
|
+
get: (type, key) => cached([
|
|
110
|
+
"get",
|
|
111
|
+
type,
|
|
112
|
+
key
|
|
113
|
+
], tx.get(type, key)),
|
|
114
|
+
loadSubset: (type, scan) => cached([
|
|
115
|
+
"query",
|
|
116
|
+
type,
|
|
117
|
+
scan
|
|
118
|
+
], tx.loadSubset(type, scan))
|
|
119
|
+
};
|
|
120
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => {
|
|
121
|
+
closed = true;
|
|
122
|
+
reads.clear();
|
|
123
|
+
}));
|
|
124
|
+
const run = (work) => Effect.runPromiseWith(services)(Effect.suspend(() => closed ? Effect.fail(failure("Mutator scope is closed.")) : Effect.flatMap(Effect.forkIn(work, scope), Fiber.join)));
|
|
125
|
+
const read = { query: (build) => run(withTransactionCollections(ir, local, (objects, prepare) => Effect.tryPromise({
|
|
126
|
+
try: () => createReadTx(objects, prepare).query(build),
|
|
127
|
+
catch: failure
|
|
128
|
+
}))) };
|
|
129
|
+
const runMutation = (work) => run(mutations.withPermits(1)(work));
|
|
130
|
+
const mutate = new Proxy({}, { get: (_target, type) => {
|
|
131
|
+
const definition = ir.objectTypes.find((t) => t.name === type);
|
|
132
|
+
if (!definition) throw failure(`Unknown object type "${type}".`);
|
|
133
|
+
const requireObject = (key) => tx.get(type, key).pipe(Effect.flatMap((value) => value ? Effect.void : Effect.fail(new BackendError({
|
|
134
|
+
operation: "mutator",
|
|
135
|
+
kind: "NotFound",
|
|
136
|
+
retryable: false,
|
|
137
|
+
message: "Object is unavailable."
|
|
138
|
+
}))));
|
|
139
|
+
return {
|
|
140
|
+
create: (value) => runMutation(Effect.gen(function* () {
|
|
141
|
+
const key = value[definition.primaryKey];
|
|
142
|
+
if (typeof key !== "string" && typeof key !== "number") return yield* failure("Created object requires its primary key.");
|
|
143
|
+
if (yield* tx.get(type, key)) return yield* new BackendError({
|
|
144
|
+
operation: "mutator.create",
|
|
145
|
+
kind: "Conflict",
|
|
146
|
+
retryable: false,
|
|
147
|
+
message: "Object already exists."
|
|
148
|
+
});
|
|
149
|
+
yield* tx.put(type, value);
|
|
150
|
+
}).pipe(Effect.ensuring(invalidate))),
|
|
151
|
+
update: (key, changes) => runMutation(requireObject(key).pipe(Effect.andThen(tx.patch(type, key, Array.isArray(changes) ? changes : Object.entries(changes).map(([property, value]) => ({
|
|
152
|
+
path: [property],
|
|
153
|
+
value
|
|
154
|
+
})))), Effect.ensuring(invalidate))),
|
|
155
|
+
delete: (key) => runMutation(requireObject(key).pipe(Effect.andThen(tx.delete(type, key)), Effect.ensuring(invalidate)))
|
|
156
|
+
};
|
|
157
|
+
} });
|
|
158
|
+
return yield* Effect.tryPromise({
|
|
159
|
+
try: () => Promise.resolve(handler({
|
|
160
|
+
tx: {
|
|
161
|
+
...read,
|
|
162
|
+
mutate
|
|
163
|
+
},
|
|
164
|
+
args: request.parameters,
|
|
165
|
+
context
|
|
166
|
+
})),
|
|
167
|
+
catch: failure
|
|
168
|
+
});
|
|
169
|
+
}))]));
|
|
170
|
+
const executeTransactionMutator = Effect.fn("Ontology.executeMutator")(function* (options) {
|
|
171
|
+
return yield* executeAction({
|
|
172
|
+
ir: options.ir,
|
|
173
|
+
tx: options.tx,
|
|
174
|
+
request: {
|
|
175
|
+
id: options.operationId,
|
|
176
|
+
name: options.name,
|
|
177
|
+
parameters: options.parameters,
|
|
178
|
+
replay: options.replay
|
|
179
|
+
},
|
|
180
|
+
context: options.context,
|
|
181
|
+
resolveOnly: options.resolveOnly,
|
|
182
|
+
mutators: actionMutators(options.ir, options.mutators)
|
|
183
|
+
}).pipe(Effect.map((execution) => execution.result));
|
|
184
|
+
});
|
|
185
|
+
//#endregion
|
|
186
|
+
export { actionMutators, executeTransactionMutator, withTransactionCollections };
|
|
187
|
+
|
|
188
|
+
//# sourceMappingURL=transactions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactions.js","names":[],"sources":["../../src/runtime/transactions.ts"],"sourcesContent":["import { BackendError } from \"@party-stack/ontology-backend\";\nimport { executeAction } from \"@party-stack/ontology-backend/actions\";\nimport { Table } from \"@party-stack/ontology-storage/tables\";\nimport { BasicIndex, whenSyncAccepted, DbClient, collectionOptions } from \"@tanstack/db\";\nimport { Effect, Fiber, Semaphore } from \"effect\";\nimport { createReadTx } from \"../live/mutators/createReadTx.js\";\nimport { storageSubset } from \"../tanstack/index.js\";\nimport type { ActionRequest } from \"@party-stack/ontology-backend\";\ntype ExpressionReplay = NonNullable<ActionRequest[\"replay\"]>;\nimport type { OntologyMutatorTx } from \"../live/mutators/types.js\";\nimport type { OntologyMutatorRegistry, PrepareTransactionSources } from \"../live/mutators/types.js\";\nimport type { ActionMutatorRegistry } from \"@party-stack/ontology-backend/actions\";\nimport type { OwnedReadTransaction, OwnedTransaction } from \"@party-stack/ontology-backend/owned\";\nimport type { OntologyIR, OntologyObject } from \"@party-stack/ontology-spec\";\nimport type { Collection } from \"@tanstack/db\";\n\nconst failure = (cause: unknown) =>\n cause instanceof BackendError\n ? cause\n : new BackendError({\n operation: \"mutator\",\n kind: \"Internal\",\n message: cause instanceof Error ? cause.message : \"Transaction execution failed.\",\n retryable: false,\n cause,\n });\n\n/** Ephemeral query collections; their only source is the supplied persisted transaction. */\nexport const withTransactionCollections = <A, E, R>(\n ir: OntologyIR,\n tx: OwnedReadTransaction,\n body: (\n objects: Record<string, Collection<OntologyObject>>,\n ensureLoaded: PrepareTransactionSources,\n client: DbClient\n ) => Effect.Effect<A, E, R>\n): Effect.Effect<A, E | BackendError, R> =>\n Effect.scoped(\n Effect.gen(function* () {\n const context = yield* Effect.context<never>();\n const scope = yield* Effect.scope;\n let closed = false;\n yield* Effect.addFinalizer(() =>\n Effect.sync(() => {\n closed = true;\n })\n );\n const run = <B, F>(effect: Effect.Effect<B, F>) =>\n closed\n ? Promise.reject(failure(\"Transaction query scope is closed.\"))\n : Effect.runPromiseWith(context)(\n Effect.flatMap(Effect.forkIn(effect, scope), Fiber.join)\n );\n const client = yield* Effect.acquireRelease(\n Effect.sync(() => new DbClient()),\n (client) => Effect.promise(() => client.cleanup())\n );\n const publishers = new Map<\n string,\n (rows: readonly { key: string | number; value: OntologyObject }[]) => Promise<void>\n >();\n const loaded = new Map<string, Promise<void>>();\n const objects = Object.fromEntries(\n ir.objectTypes.map((definition) => [\n definition.name,\n client.collection(\n collectionOptions({\n id: `transaction:${crypto.randomUUID()}:${definition.name}`,\n getKey: (value: OntologyObject) =>\n value[definition.primaryKey] as string | number,\n syncMode: \"on-demand\",\n defaultIndexType: BasicIndex,\n autoIndex: \"eager\",\n startSync: true,\n sync: {\n rowUpdateMode: \"full\",\n sync: ({ begin, write, commit, markReady, fail, collection }) => {\n const published = new Set(collection.keys());\n const requests = new Map<string, Promise<void>>();\n publishers.set(definition.name, async (rows) => {\n if (closed) throw failure(\"Transaction query scope is closed.\");\n begin();\n for (const row of rows) {\n write({\n type: published.has(row.key) ? \"update\" : \"insert\",\n value: row.value,\n });\n published.add(row.key);\n }\n const receipt = commit();\n if (receipt !== true) void receipt.catch(fail);\n await whenSyncAccepted(receipt);\n });\n markReady();\n return {\n loadSubset: (subset) => {\n const query = storageSubset(subset, ir, definition.name);\n const key = Table.make({ name: \"transaction-demand\" }).encode(\n query\n );\n let pending = requests.get(key);\n if (!pending) {\n pending = run(\n Effect.flatMap(\n tx.loadSubset(definition.name, query),\n (rows) =>\n Effect.promise(() =>\n publishers.get(definition.name)!(rows)\n )\n )\n );\n requests.set(key, pending);\n void pending.catch(() => requests.delete(key));\n }\n return pending;\n },\n cleanup: () => {\n publishers.delete(definition.name);\n },\n };\n },\n },\n })\n ),\n ])\n );\n const ensureLoaded: PrepareTransactionSources = async (types, request) => {\n // TanStack drives query sources, join key batches and includes\n // through loadSubset. Only imperative edits need preparation.\n if (request?.plan !== undefined) return;\n for (const type of types) {\n const key = JSON.stringify([type, request?.key]);\n let pending = loaded.get(key);\n if (!pending) {\n const publish = publishers.get(type);\n if (!publish) throw failure(\"Unknown transaction query source.\");\n const read =\n request?.key === undefined\n ? tx.loadSubset(type)\n : Effect.map(tx.get(type, request.key), (value) =>\n value === undefined ? [] : [{ key: request.key!, value }]\n );\n pending = run(Effect.flatMap(read, (rows) => Effect.promise(() => publish(rows))));\n loaded.set(key, pending);\n }\n await pending;\n }\n };\n return yield* body(objects, ensureLoaded, client);\n })\n );\n\n/** Promise/TanStack authoring bridge only. Portable action logic and replay live below ontology. */\nexport const actionMutators = (\n ir: OntologyIR,\n registry: OntologyMutatorRegistry = {}\n): ActionMutatorRegistry =>\n Object.fromEntries(\n Object.entries(registry).map(([name, handler]) => [\n name,\n (tx, request, context) =>\n Effect.scoped(\n Effect.gen(function* () {\n const services = yield* Effect.context<never>();\n const scope = yield* Effect.scope;\n let closed = false;\n const reads = new Map<string, unknown>();\n const codec = Table.make({ name: \"mutator-reads\" });\n const cached = <A>(key: unknown, work: Effect.Effect<A, BackendError>) =>\n Effect.suspend(() => {\n const encoded = codec.encode(key);\n return reads.has(encoded)\n ? Effect.succeed(reads.get(encoded) as A)\n : work.pipe(\n Effect.tap((value) => Effect.sync(() => reads.set(encoded, value)))\n );\n });\n const invalidate = Effect.sync(() => reads.clear());\n const mutations = yield* Semaphore.make(1);\n const local: OwnedReadTransaction = {\n get: (type, key) => cached([\"get\", type, key], tx.get(type, key)),\n loadSubset: (type, scan) =>\n cached([\"query\", type, scan], tx.loadSubset(type, scan)),\n };\n yield* Effect.addFinalizer(() =>\n Effect.sync(() => {\n closed = true;\n reads.clear();\n })\n );\n const run = <A>(work: Effect.Effect<A, BackendError>) =>\n Effect.runPromiseWith(services)(\n Effect.suspend(() =>\n closed\n ? Effect.fail(failure(\"Mutator scope is closed.\"))\n : Effect.flatMap(Effect.forkIn(work, scope), Fiber.join)\n )\n );\n const read: ReturnType<typeof createReadTx> = {\n query: <A>(build: Parameters<ReturnType<typeof createReadTx>[\"query\"]>[0]) =>\n run(\n withTransactionCollections(ir, local, (objects, prepare) =>\n Effect.tryPromise({\n try: () => createReadTx(objects, prepare).query<A>(build),\n catch: failure,\n })\n )\n ),\n };\n const runMutation = <A>(work: Effect.Effect<A, BackendError>) =>\n run(mutations.withPermits(1)(work));\n const mutate = new Proxy(\n {},\n {\n get: (_target, type: string) => {\n const definition = ir.objectTypes.find((t) => t.name === type);\n if (!definition) throw failure(`Unknown object type \"${type}\".`);\n const requireObject = (key: string | number) =>\n tx.get(type, key).pipe(\n Effect.flatMap((value) =>\n value\n ? Effect.void\n : Effect.fail(\n new BackendError({\n operation: \"mutator\",\n kind: \"NotFound\",\n retryable: false,\n message: \"Object is unavailable.\",\n })\n )\n )\n );\n return {\n create: (value: Record<string, unknown>) =>\n runMutation(\n Effect.gen(function* () {\n const key = value[definition.primaryKey];\n if (typeof key !== \"string\" && typeof key !== \"number\")\n return yield* failure(\n \"Created object requires its primary key.\"\n );\n if (yield* tx.get(type, key))\n return yield* new BackendError({\n operation: \"mutator.create\",\n kind: \"Conflict\",\n retryable: false,\n message: \"Object already exists.\",\n });\n yield* tx.put(type, value);\n }).pipe(Effect.ensuring(invalidate))\n ),\n update: (\n key: string | number,\n changes:\n | Record<string, unknown>\n | { path: string[]; value: unknown }[]\n ) =>\n runMutation(\n requireObject(key).pipe(\n Effect.andThen(\n tx.patch(\n type,\n key,\n Array.isArray(changes)\n ? changes\n : Object.entries(changes).map(\n ([property, value]) => ({\n path: [property],\n value,\n })\n )\n )\n ),\n Effect.ensuring(invalidate)\n )\n ),\n delete: (key: string | number) =>\n runMutation(\n requireObject(key).pipe(\n Effect.andThen(tx.delete(type, key)),\n Effect.ensuring(invalidate)\n )\n ),\n };\n },\n }\n ) as OntologyMutatorTx[\"mutate\"];\n return yield* Effect.tryPromise({\n try: () =>\n Promise.resolve(\n handler({ tx: { ...read, mutate }, args: request.parameters, context })\n ),\n catch: failure,\n });\n })\n ),\n ])\n );\n\nexport const executeTransactionMutator = Effect.fn(\"Ontology.executeMutator\")(function* (options: {\n readonly ir: OntologyIR;\n readonly tx: OwnedTransaction;\n readonly name: string;\n readonly parameters: Record<string, unknown>;\n readonly operationId: string;\n readonly replay?: ExpressionReplay;\n readonly resolveOnly?: boolean;\n readonly context?: Record<string, unknown>;\n readonly mutators?: OntologyMutatorRegistry;\n}) {\n return yield* executeAction({\n ir: options.ir,\n tx: options.tx,\n request: {\n id: options.operationId,\n name: options.name,\n parameters: options.parameters,\n replay: options.replay,\n },\n context: options.context,\n resolveOnly: options.resolveOnly,\n mutators: actionMutators(options.ir, options.mutators),\n }).pipe(Effect.map((execution) => execution.result));\n});\n"],"mappings":";;;;;;;;;AAgBA,MAAM,WAAW,UACb,iBAAiB,eACX,QACA,IAAI,aAAa;CACb,WAAW;CACX,MAAM;CACN,SAAS,iBAAiB,QAAQ,MAAM,UAAU;CAClD,WAAW;CACX;AACJ,CAAC;;AAGX,MAAa,8BACT,IACA,IACA,SAMA,OAAO,OACH,OAAO,IAAI,aAAa;CACpB,MAAM,UAAU,OAAO,OAAO,QAAe;CAC7C,MAAM,QAAQ,OAAO,OAAO;CAC5B,IAAI,SAAS;CACb,OAAO,OAAO,mBACV,OAAO,WAAW;EACd,SAAS;CACb,CAAC,CACL;CACA,MAAM,OAAa,WACf,SACM,QAAQ,OAAO,QAAQ,oCAAoC,CAAC,IAC5D,OAAO,eAAe,OAAO,CAAC,CAC1B,OAAO,QAAQ,OAAO,OAAO,QAAQ,KAAK,GAAG,MAAM,IAAI,CAC3D;CACV,MAAM,SAAS,OAAO,OAAO,eACzB,OAAO,WAAW,IAAI,SAAS,CAAC,IAC/B,WAAW,OAAO,cAAc,OAAO,QAAQ,CAAC,CACrD;CACA,MAAM,6BAAa,IAAI,IAGrB;CACF,MAAM,yBAAS,IAAI,IAA2B;CAC9C,MAAM,UAAU,OAAO,YACnB,GAAG,YAAY,KAAK,eAAe,CAC/B,WAAW,MACX,OAAO,WACH,kBAAkB;EACd,IAAI,eAAe,OAAO,WAAW,EAAE,GAAG,WAAW;EACrD,SAAS,UACL,MAAM,WAAW;EACrB,UAAU;EACV,kBAAkB;EAClB,WAAW;EACX,WAAW;EACX,MAAM;GACF,e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CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { LiveOntologyAttachments } from "../live/attachments/createLiveOntologyAttachments.js";
|
|
2
|
+
import { LiveOntology, LiveOntologyWrites } from "../live/LiveOntology.js";
|
|
3
|
+
import { BackendError } from "@party-stack/ontology-backend";
|
|
4
|
+
import { Runtime } from "@party-stack/runtime";
|
|
5
|
+
import { Effect, Scope } from "effect";
|
|
6
|
+
import { OntologyIR } from "@party-stack/ontology-spec";
|
|
7
|
+
import { TraceStore } from "@party-stack/runtime/tracing";
|
|
8
|
+
import { ReplicaPinControls, ReplicaService } from "@party-stack/ontology-replica";
|
|
9
|
+
//#region src/runtime/view.d.ts
|
|
10
|
+
export interface ReplicaViewOptions {
|
|
11
|
+
readonly ir: OntologyIR;
|
|
12
|
+
readonly context: Record<string, unknown>;
|
|
13
|
+
readonly writes?: LiveOntologyWrites;
|
|
14
|
+
readonly replica: ReplicaService;
|
|
15
|
+
readonly attachments: LiveOntologyAttachments;
|
|
16
|
+
readonly pins?: ReplicaPinControls;
|
|
17
|
+
readonly pinBackend?: Effect.Effect<import("@party-stack/ontology-backend").OntologyBackendService, BackendError, Scope.Scope>;
|
|
18
|
+
readonly traces?: TraceStore;
|
|
19
|
+
readonly parentDiagnostics?: LiveOntology["diagnostics"];
|
|
20
|
+
readonly diagnosticLabel?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Materialize a scoped UI view over an existing replica; engine ownership is independent. */
|
|
23
|
+
export declare const makeReplicaOntologyView: (options: ReplicaViewOptions) => Effect.Effect<Omit<LiveOntology<import("@party-stack/ontology-spec").OntologyDefinition>, "cleanup">, BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced">, Runtime | Scope.Scope>;
|
|
24
|
+
//#endregion
|
|
25
|
+
//# sourceMappingURL=view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.d.ts","names":[],"sources":["../../src/runtime/view.ts"],"mappings":";;;;;;;;;iBA0DiB;WACJ,IAAI;WACJ,SAAS;WACT,SAAS;WACT,SAAS;WACT,aAAa;WACb,OAAO;WACP,aAAa,OAAO,+CACe,wBACxC,cACA,MAAM;WAED,SAAS;WACT,oBAAoB;WACpB;;;qBAIA,0BAAuB,SAAA,uBAAA,OAAA,OAAA,KAAA,kDAAA,iCAAA,iWAAA,UAAA,MAAA"}
|