@party-stack/ontology 0.20.0 → 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 +29 -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 +3 -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 -30
- 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 +53 -18
- 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 -18
- 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 -223
- 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 -413
- 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 -104
- 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 -24
- 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 -69
- 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 -50
- 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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createLiveOntologyActions.js","names":[],"sources":["../../../src/live/actions/createLiveOntologyActions.ts"],"sourcesContent":["import { createTransaction, type Transaction } from \"@tanstack/db\";\nimport { resolveActionParameters } from \"../expression.js\";\nimport { createReadTx } from \"../mutators/createMutatorTx.js\";\nimport { runOptimisticAction } from \"../mutators/runOptimisticAction.js\";\nimport { createOntologyOutbox, type OutboxProjection } from \"../outbox/createOntologyOutbox.js\";\nimport { createLiveOntologyAction } from \"./createLiveOntologyAction.js\";\nimport { prepareActionParameters } from \"./prepareActionParameters.js\";\nimport type { OntologyIR } from \"../../ir/index.js\";\nimport type { Uncertain } from \"../../utils/uncertain.js\";\nimport type { ValidationIssue } from \"../../utils/validation.js\";\nimport type { Result } from \"../../utils/values.js\";\nimport type { LiveOntologyWrites, LiveOntologyWriteVisibility } from \"../LiveOntology.js\";\nimport type { OntologyCollection } from \"../objects/createLiveOntologyObjectCollection.js\";\nimport type { OntologyObject } from \"../objects/OntologyObject.js\";\nimport type { OntologyApplyActionResult, OntologyBackendAdapter } from \"../OntologyBackendAdapter.js\";\nimport type { OntologyActionRequest, OntologyOutbox, OntologyOutboxEntry } from \"../outbox/types.js\";\nimport type {\n LiveOntologyAction,\n LiveOntologyActionDraftValidationOptions,\n LiveOntologyActionOptions,\n} from \"./createLiveOntologyAction.js\";\nimport type { BlobManager } from \"@party-stack/blobs\";\nimport type { ConnectionMonitor } from \"@party-stack/connections\";\nimport type { RuntimeAdapter } from \"@party-stack/runtime\";\n\nexport interface LiveOntologyActionsSubsystem {\n actions: Record<string, LiveOntologyAction>;\n outbox: OntologyOutbox;\n}\n\nexport function createLiveOntologyActions(options: {\n ir: OntologyIR;\n backendAdapter: OntologyBackendAdapter;\n runtime: RuntimeAdapter;\n context: Record<string, unknown>;\n objects: Record<string, OntologyCollection<OntologyObject>>;\n blobManager: BlobManager;\n writes?: LiveOntologyWrites;\n connection?: ConnectionMonitor;\n}): LiveOntologyActionsSubsystem {\n const defaultMode = options.writes?.defaultMode ?? \"direct\";\n const defaultVisibility = options.writes?.defaultVisibility ?? \"confirmed\";\n\n const executeRemote = async (\n request: OntologyActionRequest\n ): Promise<OntologyApplyActionResult | void> => {\n const prepared = await prepareActionParameters({\n ir: options.ir,\n actionTypeName: request.actionTypeName,\n parameters: request.parameters,\n backendAdapter: options.backendAdapter,\n blobManager: options.blobManager,\n });\n const result = await options.backendAdapter.applyAction(request.actionTypeName, prepared.parameters, {\n objects: options.objects,\n context: options.context,\n attachmentUploads: prepared.attachmentUploads,\n idempotencyKey: request.idempotencyKey,\n });\n const backendMappings = result?.attachmentIdMappings ?? [];\n const attachmentIdMappings = [...prepared.attachmentIdMappings, ...backendMappings];\n await Promise.all(\n attachmentIdMappings.map((mapping) =>\n options.blobManager.bindRemoteId(mapping.localId, mapping.remoteId)\n )\n );\n return attachmentIdMappings.length > 0\n ? {\n ...result,\n attachmentIdMappings,\n }\n : result;\n };\n\n const applyOptimisticAction = async (\n transaction: Transaction,\n request: OntologyActionRequest\n ): Promise<boolean> => {\n try {\n const parameters = await resolveActionParameters({\n ir: options.ir,\n actionTypeName: request.actionTypeName,\n initialParameters: request.parameters,\n context: options.context,\n tx: createReadTx(options.objects),\n });\n await runOptimisticAction({\n transaction,\n ir: options.ir,\n actionTypeName: request.actionTypeName,\n parameters,\n context: options.context,\n idempotencyKey: request.idempotencyKey,\n objects: options.objects,\n mutators: options.writes?.mutators,\n });\n } catch (error) {\n if (transaction.state === \"pending\") {\n transaction.rollback();\n }\n throw error;\n }\n return transaction.mutations.length > 0;\n };\n\n const project = async (entry: OntologyOutboxEntry): Promise<OutboxProjection | undefined> => {\n const visibility = entry.visibility ?? defaultVisibility;\n if (visibility !== \"optimistic\") return;\n\n let resolve!: () => void;\n let reject!: (error: Error) => void;\n const completion = new Promise<void>((resolvePromise, rejectPromise) => {\n resolve = resolvePromise;\n reject = rejectPromise;\n });\n const transaction = createTransaction({\n autoCommit: false,\n mutationFn: () => completion,\n });\n if (!(await applyOptimisticAction(transaction, entry.request))) {\n return;\n }\n void transaction.commit().catch(() => undefined);\n void transaction.isPersisted.promise.catch(() => undefined);\n return {\n settle(error) {\n if (error) reject(error);\n else resolve();\n return transaction.isPersisted.promise.then(\n () => undefined,\n () => undefined\n );\n },\n };\n };\n\n const outbox = createOntologyOutbox({\n runtime: options.runtime,\n execute: (entry) => executeRemote(entry.request),\n project,\n failureStrategy: options.writes?.outbox?.failureStrategy ?? \"discard-all\",\n maxRetries: options.writes?.outbox?.maxRetries,\n connection: options.connection,\n });\n\n const executeDirect = async (\n request: OntologyActionRequest,\n visibility: LiveOntologyWriteVisibility\n ): Promise<OntologyApplyActionResult | void> => {\n if (visibility === \"confirmed\") {\n return executeRemote(request);\n }\n\n let result: OntologyApplyActionResult | void = undefined;\n const transaction = createTransaction({\n autoCommit: false,\n mutationFn: async () => {\n result = await executeRemote(request);\n },\n });\n if (!(await applyOptimisticAction(transaction, request))) {\n return executeRemote(request);\n }\n await transaction.commit();\n return result;\n };\n\n const submit = async (\n request: OntologyActionRequest,\n actionOptions?: LiveOntologyActionOptions\n ): Promise<OntologyApplyActionResult | void> => {\n const mode = actionOptions?.mode ?? defaultMode;\n const visibility = actionOptions?.visibility ?? defaultVisibility;\n if (visibility === \"optimistic\" && options.backendAdapter.live === false) {\n throw new Error(\n `Ontology backend adapter \"${options.backendAdapter.name}\" is not live and cannot reconcile optimistic actions.`\n );\n }\n if (mode === \"outbox\") {\n const enqueued = await outbox.enqueue<OntologyApplyActionResult | void>(request, { visibility });\n return enqueued.completed;\n }\n return executeDirect(request, visibility);\n };\n\n const validate = (\n actionTypeName: string,\n parameters: Record<string, unknown>\n ): Promise<Uncertain<Result<void, readonly ValidationIssue[]>>> => {\n if (!options.backendAdapter.validateAction) {\n return Promise.resolve({\n certain: false,\n });\n }\n return options.backendAdapter.validateAction(actionTypeName, parameters, {\n objects: options.objects,\n context: options.context,\n });\n };\n\n const validateDraft = (\n actionTypeName: string,\n parameters: Record<string, unknown>,\n validationOptions?: LiveOntologyActionDraftValidationOptions<Record<string, unknown>>\n ): Promise<Uncertain<Result<void, readonly ValidationIssue[]>>> => {\n if (!options.backendAdapter.validateActionDraft) {\n return Promise.resolve({\n certain: false,\n });\n }\n return options.backendAdapter.validateActionDraft(actionTypeName, parameters, {\n objects: options.objects,\n context: options.context,\n knownParameters: validationOptions?.knownParameters ?? [],\n });\n };\n\n const actions = Object.fromEntries(\n options.ir.actionTypes.map((action) => [\n action.name,\n createLiveOntologyAction({\n ir: options.ir,\n action,\n context: options.context,\n objects: options.objects,\n submit,\n validate,\n validateDraft,\n }),\n ])\n );\n\n return {\n actions,\n outbox,\n };\n}\n"],"mappings":";;;;;;;;AA8BA,SAAgB,0BAA0B,SAST;CAC7B,MAAM,cAAc,QAAQ,QAAQ,eAAe;CACnD,MAAM,oBAAoB,QAAQ,QAA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AC/E;EAEpB,OAAO,cAAc,SAAS,UAAU;CAC5C;CAEA,MAAM,YACF,gBACA,eAC+D;EAC/D,IAAI,CAAC,QAAQ,eAAe,gBACxB,OAAO,QAAQ,QAAQ,EACnB,SAAS,MACb,CAAC;EAEL,OAAO,QAAQ,eAAe,eAAe,gBAAgB,YAAY;GACrE,SAAS,QAAQ;GACjB,SAAS,QAAQ;EACrB,CAAC;CACL;CAEA,MAAM,iBACF,gBACA,YACA,sBAC+D;EAC/D,IAAI,CAAC,QAAQ,eAAe,qBACxB,OAAO,QAAQ,QAAQ,EACnB,SAAS,MACb,CAAC;EAEL,OAAO,QAAQ,eAAe,oBAAoB,gBAAgB,YAAY;GAC1E,SAAS,QAAQ;GACjB,SAAS,QAAQ;GACjB,iBAAiB,mBAAmB,mBAAmB,CAAC;EAC5D,CAAC;CACL;CAiBA,OAAO;EACH,SAhBY,OAAO,YACnB,QAAQ,GAAG,YAAY,KAAK,WAAW,CACnC,OAAO,MACP,yBAAyB;GACrB,IAAI,QAAQ;GACZ;GACA,SAAS,QAAQ;GACjB,SAAS,QAAQ;GACjB;GACA;GACA;EACJ,CAAC,CACL,CAAC,CAIK;EACN;CACJ;AACJ"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { OntologyIR } from "../../ir/generated/types.js";
|
|
2
|
-
import "../../ir/index.js";
|
|
3
|
-
import { OntologyAttachmentIdMapping, OntologyAttachmentUpload, OntologyBackendAdapter } from "../OntologyBackendAdapter.js";
|
|
4
|
-
import { BlobManager } from "@party-stack/blobs";
|
|
5
|
-
//#region src/live/actions/prepareActionParameters.d.ts
|
|
6
|
-
export interface PreparedActionParameters {
|
|
7
|
-
parameters: Record<string, unknown>;
|
|
8
|
-
attachmentUploads: OntologyAttachmentUpload[];
|
|
9
|
-
attachmentIdMappings: OntologyAttachmentIdMapping[];
|
|
10
|
-
}
|
|
11
|
-
export declare function prepareActionParameters(opts: {
|
|
12
|
-
ir: OntologyIR;
|
|
13
|
-
actionTypeName: string;
|
|
14
|
-
parameters: Record<string, unknown>;
|
|
15
|
-
backendAdapter: OntologyBackendAdapter;
|
|
16
|
-
blobManager?: BlobManager;
|
|
17
|
-
}): Promise<PreparedActionParameters>;
|
|
18
|
-
//#endregion
|
|
19
|
-
//# sourceMappingURL=prepareActionParameters.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prepareActionParameters.d.ts","names":[],"sources":["../../../src/live/actions/prepareActionParameters.ts"],"mappings":";;;;;iBA6BiB;EACb,YAAY;EACZ,mBAAmB;EACnB,sBAAsB;;wBA4RJ,wBAAwB;EAC1C,IAAI;EACJ;EACA,YAAY;EACZ,gBAAgB;EAChB,cAAc;IACd,QAAQ"}
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import { resolveType } from "../../utils/types.js";
|
|
2
|
-
import { invariant } from "@bobbyfidz/panic";
|
|
3
|
-
//#region src/live/actions/prepareActionParameters.ts
|
|
4
|
-
function isAttachment(value) {
|
|
5
|
-
return typeof value === "object" && value !== null && typeof value.id === "string";
|
|
6
|
-
}
|
|
7
|
-
function collectAttachment(opts, type, attachments) {
|
|
8
|
-
if (!isAttachment(opts.value)) return;
|
|
9
|
-
attachments.push({
|
|
10
|
-
attachment: opts.value,
|
|
11
|
-
target: type
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
function collectList(opts, type, attachments) {
|
|
15
|
-
if (!Array.isArray(opts.value)) return;
|
|
16
|
-
for (const value of opts.value) collectValue({
|
|
17
|
-
...opts,
|
|
18
|
-
type: type.elementType,
|
|
19
|
-
value
|
|
20
|
-
}, attachments);
|
|
21
|
-
}
|
|
22
|
-
function collectMap(opts, type, attachments) {
|
|
23
|
-
if (typeof opts.value !== "object" || opts.value === null) return;
|
|
24
|
-
for (const value of Object.values(opts.value)) collectValue({
|
|
25
|
-
...opts,
|
|
26
|
-
type: type.valueType,
|
|
27
|
-
value
|
|
28
|
-
}, attachments);
|
|
29
|
-
}
|
|
30
|
-
function collectStruct(opts, type, attachments) {
|
|
31
|
-
if (typeof opts.value !== "object" || opts.value === null) return;
|
|
32
|
-
const fieldsByName = new Map(type.fields.map((field) => [field.name, field.type]));
|
|
33
|
-
for (const [key, value] of Object.entries(opts.value)) {
|
|
34
|
-
const fieldType = fieldsByName.get(key);
|
|
35
|
-
if (!fieldType) continue;
|
|
36
|
-
collectValue({
|
|
37
|
-
...opts,
|
|
38
|
-
type: fieldType,
|
|
39
|
-
value
|
|
40
|
-
}, attachments);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function collectValue(opts, attachments) {
|
|
44
|
-
if (opts.value === void 0 || opts.value === null) return;
|
|
45
|
-
const type = resolveType(opts.ir, opts.type);
|
|
46
|
-
switch (type.kind) {
|
|
47
|
-
case "attachment":
|
|
48
|
-
collectAttachment(opts, type.value, attachments);
|
|
49
|
-
return;
|
|
50
|
-
case "optional":
|
|
51
|
-
collectValue({
|
|
52
|
-
...opts,
|
|
53
|
-
type: type.value.type
|
|
54
|
-
}, attachments);
|
|
55
|
-
return;
|
|
56
|
-
case "list":
|
|
57
|
-
collectList(opts, type.value, attachments);
|
|
58
|
-
return;
|
|
59
|
-
case "map":
|
|
60
|
-
collectMap(opts, type.value, attachments);
|
|
61
|
-
return;
|
|
62
|
-
case "struct":
|
|
63
|
-
collectStruct(opts, type.value, attachments);
|
|
64
|
-
return;
|
|
65
|
-
default: return;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function collectActionAttachments(opts) {
|
|
69
|
-
const action = opts.ir.actionTypes.find((candidate) => candidate.name === opts.actionTypeName);
|
|
70
|
-
const attachments = [];
|
|
71
|
-
for (const parameter of action.parameters) collectValue({
|
|
72
|
-
ir: opts.ir,
|
|
73
|
-
type: parameter.type,
|
|
74
|
-
value: opts.parameters[parameter.name]
|
|
75
|
-
}, attachments);
|
|
76
|
-
return [...new Map(attachments.map((entry) => [entry.attachment.id, entry])).values()];
|
|
77
|
-
}
|
|
78
|
-
async function collectActionAttachmentUploads(opts) {
|
|
79
|
-
if (opts.attachments.length === 0) return [];
|
|
80
|
-
const blobManager = opts.blobManager;
|
|
81
|
-
invariant(blobManager, "Missing required BlobManager for collecting attachment uploads.");
|
|
82
|
-
return Promise.all(opts.attachments.map(async (entry) => ({
|
|
83
|
-
...entry,
|
|
84
|
-
blob: await blobManager.read(entry.attachment.id)
|
|
85
|
-
})));
|
|
86
|
-
}
|
|
87
|
-
async function materializeValue(opts) {
|
|
88
|
-
if (opts.value === void 0 || opts.value === null) return opts.value;
|
|
89
|
-
const materializeAttachment = opts.backendAdapter.attachments?.materializeAttachment;
|
|
90
|
-
invariant(materializeAttachment, "Missing attachment materializer.");
|
|
91
|
-
const type = resolveType(opts.ir, opts.type);
|
|
92
|
-
switch (type.kind) {
|
|
93
|
-
case "attachment": {
|
|
94
|
-
if (!isAttachment(opts.value)) return opts.value;
|
|
95
|
-
const local = opts.value;
|
|
96
|
-
let pending = opts.materialized.get(local.id);
|
|
97
|
-
if (!pending) {
|
|
98
|
-
const materializeOptions = { target: type.value };
|
|
99
|
-
const canMaterialize = opts.backendAdapter.attachments?.canMaterializeAttachment?.(local, materializeOptions) ?? true;
|
|
100
|
-
pending = opts.blobManager.read(local.id).then(async (blob) => {
|
|
101
|
-
if (!canMaterialize) {
|
|
102
|
-
opts.uploads.push({
|
|
103
|
-
attachment: local,
|
|
104
|
-
target: type.value,
|
|
105
|
-
blob
|
|
106
|
-
});
|
|
107
|
-
return local;
|
|
108
|
-
}
|
|
109
|
-
return await materializeAttachment(local, blob, materializeOptions) ?? local;
|
|
110
|
-
}).then((result) => {
|
|
111
|
-
const remote = result;
|
|
112
|
-
if (remote.id !== local.id) opts.mappings.push({
|
|
113
|
-
localId: local.id,
|
|
114
|
-
remoteId: remote.id
|
|
115
|
-
});
|
|
116
|
-
return remote;
|
|
117
|
-
});
|
|
118
|
-
opts.materialized.set(local.id, pending);
|
|
119
|
-
}
|
|
120
|
-
return pending;
|
|
121
|
-
}
|
|
122
|
-
case "optional": return materializeValue({
|
|
123
|
-
...opts,
|
|
124
|
-
type: type.value.type
|
|
125
|
-
});
|
|
126
|
-
case "list":
|
|
127
|
-
if (!Array.isArray(opts.value)) return opts.value;
|
|
128
|
-
return Promise.all(opts.value.map((value) => materializeValue({
|
|
129
|
-
...opts,
|
|
130
|
-
type: type.value.elementType,
|
|
131
|
-
value
|
|
132
|
-
})));
|
|
133
|
-
case "map":
|
|
134
|
-
if (typeof opts.value !== "object" || opts.value === null || Array.isArray(opts.value)) return opts.value;
|
|
135
|
-
return Object.fromEntries(await Promise.all(Object.entries(opts.value).map(async ([key, value]) => [key, await materializeValue({
|
|
136
|
-
...opts,
|
|
137
|
-
type: type.value.valueType,
|
|
138
|
-
value
|
|
139
|
-
})])));
|
|
140
|
-
case "struct": {
|
|
141
|
-
if (typeof opts.value !== "object" || opts.value === null || Array.isArray(opts.value)) return opts.value;
|
|
142
|
-
const fields = new Map(type.value.fields.map((field) => [field.name, field.type]));
|
|
143
|
-
return Object.fromEntries(await Promise.all(Object.entries(opts.value).map(async ([key, value]) => {
|
|
144
|
-
const fieldType = fields.get(key);
|
|
145
|
-
return [key, fieldType ? await materializeValue({
|
|
146
|
-
...opts,
|
|
147
|
-
type: fieldType,
|
|
148
|
-
value
|
|
149
|
-
}) : value];
|
|
150
|
-
})));
|
|
151
|
-
}
|
|
152
|
-
default: return opts.value;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
async function materializeActionParameters(opts) {
|
|
156
|
-
const action = opts.ir.actionTypes.find((candidate) => candidate.name === opts.actionTypeName);
|
|
157
|
-
const materialized = /* @__PURE__ */ new Map();
|
|
158
|
-
const attachmentIdMappings = [];
|
|
159
|
-
const attachmentUploads = [];
|
|
160
|
-
const parameters = { ...opts.parameters };
|
|
161
|
-
await Promise.all(action.parameters.map(async (parameter) => {
|
|
162
|
-
parameters[parameter.name] = await materializeValue({
|
|
163
|
-
ir: opts.ir,
|
|
164
|
-
type: parameter.type,
|
|
165
|
-
value: opts.parameters[parameter.name],
|
|
166
|
-
backendAdapter: opts.backendAdapter,
|
|
167
|
-
blobManager: opts.blobManager,
|
|
168
|
-
materialized,
|
|
169
|
-
mappings: attachmentIdMappings,
|
|
170
|
-
uploads: attachmentUploads
|
|
171
|
-
});
|
|
172
|
-
}));
|
|
173
|
-
return {
|
|
174
|
-
parameters,
|
|
175
|
-
attachmentIdMappings,
|
|
176
|
-
attachmentUploads
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
async function prepareActionParameters(opts) {
|
|
180
|
-
const attachments = collectActionAttachments({
|
|
181
|
-
ir: opts.ir,
|
|
182
|
-
actionTypeName: opts.actionTypeName,
|
|
183
|
-
parameters: opts.parameters
|
|
184
|
-
});
|
|
185
|
-
if (opts.backendAdapter.attachments?.materializeAttachment) {
|
|
186
|
-
const blobManager = opts.blobManager;
|
|
187
|
-
invariant(blobManager, "Missing required BlobManager for materializing attachments.");
|
|
188
|
-
const materialized = await materializeActionParameters({
|
|
189
|
-
ir: opts.ir,
|
|
190
|
-
actionTypeName: opts.actionTypeName,
|
|
191
|
-
parameters: opts.parameters,
|
|
192
|
-
backendAdapter: opts.backendAdapter,
|
|
193
|
-
blobManager
|
|
194
|
-
});
|
|
195
|
-
return {
|
|
196
|
-
parameters: materialized.parameters,
|
|
197
|
-
attachmentUploads: materialized.attachmentUploads,
|
|
198
|
-
attachmentIdMappings: materialized.attachmentIdMappings
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
return {
|
|
202
|
-
parameters: opts.parameters,
|
|
203
|
-
attachmentUploads: await collectActionAttachmentUploads({
|
|
204
|
-
attachments,
|
|
205
|
-
blobManager: opts.blobManager
|
|
206
|
-
}),
|
|
207
|
-
attachmentIdMappings: []
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
//#endregion
|
|
211
|
-
export { prepareActionParameters };
|
|
212
|
-
|
|
213
|
-
//# sourceMappingURL=prepareActionParameters.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prepareActionParameters.js","names":[],"sources":["../../../src/live/actions/prepareActionParameters.ts"],"sourcesContent":["import { invariant } from \"@bobbyfidz/panic\";\nimport { resolveType } from \"../../utils/types.js\";\nimport type {\n AttachmentTypeDef,\n ListTypeDef,\n MapTypeDef,\n OntologyIR,\n StructTypeDef,\n TypeDef,\n} from \"../../ir/index.js\";\nimport type { attachment } from \"../../utils/values.js\";\nimport type {\n OntologyAttachmentIdMapping,\n OntologyAttachmentUpload,\n OntologyBackendAdapter,\n} from \"../OntologyBackendAdapter.js\";\nimport type { BlobManager } from \"@party-stack/blobs\";\n\ninterface MaterializeValueOptions {\n ir: OntologyIR;\n type: TypeDef;\n value: unknown;\n}\n\ninterface ActionAttachment {\n attachment: attachment;\n target: AttachmentTypeDef;\n}\n\nexport interface PreparedActionParameters {\n parameters: Record<string, unknown>;\n attachmentUploads: OntologyAttachmentUpload[];\n attachmentIdMappings: OntologyAttachmentIdMapping[];\n}\n\nfunction isAttachment(value: unknown): value is attachment {\n return typeof value === \"object\" && value !== null && typeof (value as { id?: unknown }).id === \"string\";\n}\n\nfunction collectAttachment(\n opts: MaterializeValueOptions,\n type: AttachmentTypeDef,\n attachments: ActionAttachment[]\n) {\n if (!isAttachment(opts.value)) return;\n attachments.push({\n attachment: opts.value,\n target: type,\n });\n}\n\nfunction collectList(opts: MaterializeValueOptions, type: ListTypeDef, attachments: ActionAttachment[]) {\n if (!Array.isArray(opts.value)) return;\n for (const value of opts.value) {\n collectValue(\n {\n ...opts,\n type: type.elementType,\n value,\n },\n attachments\n );\n }\n}\n\nfunction collectMap(opts: MaterializeValueOptions, type: MapTypeDef, attachments: ActionAttachment[]) {\n if (typeof opts.value !== \"object\" || opts.value === null) return;\n for (const value of Object.values(opts.value as Record<string, unknown>)) {\n collectValue(\n {\n ...opts,\n type: type.valueType,\n value,\n },\n attachments\n );\n }\n}\n\nfunction collectStruct(opts: MaterializeValueOptions, type: StructTypeDef, attachments: ActionAttachment[]) {\n if (typeof opts.value !== \"object\" || opts.value === null) return;\n const fieldsByName = new Map(type.fields.map((field) => [field.name, field.type]));\n for (const [key, value] of Object.entries(opts.value as Record<string, unknown>)) {\n const fieldType = fieldsByName.get(key);\n if (!fieldType) continue;\n collectValue(\n {\n ...opts,\n type: fieldType,\n value,\n },\n attachments\n );\n }\n}\n\nfunction collectValue(opts: MaterializeValueOptions, attachments: ActionAttachment[]): void {\n if (opts.value === undefined || opts.value === null) return;\n\n const type = resolveType(opts.ir, opts.type);\n switch (type.kind) {\n case \"attachment\":\n collectAttachment(opts, type.value, attachments);\n return;\n case \"optional\":\n collectValue(\n {\n ...opts,\n type: type.value.type,\n },\n attachments\n );\n return;\n case \"list\":\n collectList(opts, type.value, attachments);\n return;\n case \"map\":\n collectMap(opts, type.value, attachments);\n return;\n case \"struct\":\n collectStruct(opts, type.value, attachments);\n return;\n default:\n return;\n }\n}\n\nfunction collectActionAttachments(opts: {\n ir: OntologyIR;\n actionTypeName: string;\n parameters: Record<string, unknown>;\n}): ActionAttachment[] {\n const action = opts.ir.actionTypes.find((candidate) => candidate.name === opts.actionTypeName)!;\n const attachments: ActionAttachment[] = [];\n for (const parameter of action.parameters) {\n collectValue(\n {\n ir: opts.ir,\n type: parameter.type,\n value: opts.parameters[parameter.name],\n },\n attachments\n );\n }\n return [...new Map(attachments.map((entry) => [entry.attachment.id, entry])).values()];\n}\n\nasync function collectActionAttachmentUploads(opts: {\n attachments: ActionAttachment[];\n blobManager?: BlobManager;\n}): Promise<OntologyAttachmentUpload[]> {\n if (opts.attachments.length === 0) return [];\n const blobManager = opts.blobManager;\n invariant(blobManager, \"Missing required BlobManager for collecting attachment uploads.\");\n return Promise.all(\n opts.attachments.map(async (entry) => ({\n ...entry,\n blob: await blobManager.read(entry.attachment.id),\n }))\n );\n}\n\nasync function materializeValue(opts: {\n ir: OntologyIR;\n type: TypeDef;\n value: unknown;\n backendAdapter: OntologyBackendAdapter;\n blobManager: BlobManager;\n materialized: Map<string, Promise<attachment>>;\n mappings: OntologyAttachmentIdMapping[];\n uploads: OntologyAttachmentUpload[];\n}): Promise<unknown> {\n if (opts.value === undefined || opts.value === null) {\n return opts.value;\n }\n const materializeAttachment = opts.backendAdapter.attachments?.materializeAttachment;\n invariant(materializeAttachment, \"Missing attachment materializer.\");\n const type = resolveType(opts.ir, opts.type);\n switch (type.kind) {\n case \"attachment\": {\n if (!isAttachment(opts.value)) return opts.value;\n const local = opts.value;\n let pending = opts.materialized.get(local.id);\n if (!pending) {\n const materializeOptions = {\n target: type.value,\n };\n const canMaterialize =\n opts.backendAdapter.attachments?.canMaterializeAttachment?.(local, materializeOptions) ??\n true;\n pending = opts.blobManager\n .read(local.id)\n .then(async (blob) => {\n if (!canMaterialize) {\n opts.uploads.push({\n attachment: local,\n target: type.value,\n blob,\n });\n return local;\n }\n return (await materializeAttachment(local, blob, materializeOptions)) ?? local;\n })\n .then((result) => {\n const remote = result;\n if (remote.id !== local.id) {\n opts.mappings.push({\n localId: local.id,\n remoteId: remote.id,\n });\n }\n return remote;\n });\n opts.materialized.set(local.id, pending);\n }\n return pending;\n }\n case \"optional\":\n return materializeValue({\n ...opts,\n type: type.value.type,\n });\n case \"list\":\n if (!Array.isArray(opts.value)) return opts.value;\n return Promise.all(\n opts.value.map((value) =>\n materializeValue({\n ...opts,\n type: type.value.elementType,\n value,\n })\n )\n );\n case \"map\":\n if (typeof opts.value !== \"object\" || opts.value === null || Array.isArray(opts.value)) {\n return opts.value;\n }\n return Object.fromEntries(\n await Promise.all(\n Object.entries(opts.value as Record<string, unknown>).map(async ([key, value]) => [\n key,\n await materializeValue({\n ...opts,\n type: type.value.valueType,\n value,\n }),\n ])\n )\n );\n case \"struct\": {\n if (typeof opts.value !== \"object\" || opts.value === null || Array.isArray(opts.value)) {\n return opts.value;\n }\n const fields = new Map(type.value.fields.map((field) => [field.name, field.type]));\n return Object.fromEntries(\n await Promise.all(\n Object.entries(opts.value as Record<string, unknown>).map(async ([key, value]) => {\n const fieldType = fields.get(key);\n return [\n key,\n fieldType\n ? await materializeValue({\n ...opts,\n type: fieldType,\n value,\n })\n : value,\n ];\n })\n )\n );\n }\n default:\n return opts.value;\n }\n}\n\nasync function materializeActionParameters(opts: {\n ir: OntologyIR;\n actionTypeName: string;\n parameters: Record<string, unknown>;\n backendAdapter: OntologyBackendAdapter;\n blobManager: BlobManager;\n}): Promise<{\n parameters: Record<string, unknown>;\n attachmentIdMappings: OntologyAttachmentIdMapping[];\n attachmentUploads: OntologyAttachmentUpload[];\n}> {\n const action = opts.ir.actionTypes.find((candidate) => candidate.name === opts.actionTypeName)!;\n const materialized = new Map<string, Promise<attachment>>();\n const attachmentIdMappings: OntologyAttachmentIdMapping[] = [];\n const attachmentUploads: OntologyAttachmentUpload[] = [];\n const parameters: Record<string, unknown> = {\n ...opts.parameters,\n };\n await Promise.all(\n action.parameters.map(async (parameter) => {\n parameters[parameter.name] = await materializeValue({\n ir: opts.ir,\n type: parameter.type,\n value: opts.parameters[parameter.name],\n backendAdapter: opts.backendAdapter,\n blobManager: opts.blobManager,\n materialized,\n mappings: attachmentIdMappings,\n uploads: attachmentUploads,\n });\n })\n );\n return {\n parameters,\n attachmentIdMappings,\n attachmentUploads,\n };\n}\n\nexport async function prepareActionParameters(opts: {\n ir: OntologyIR;\n actionTypeName: string;\n parameters: Record<string, unknown>;\n backendAdapter: OntologyBackendAdapter;\n blobManager?: BlobManager;\n}): Promise<PreparedActionParameters> {\n const attachments = collectActionAttachments({\n ir: opts.ir,\n actionTypeName: opts.actionTypeName,\n parameters: opts.parameters,\n });\n if (opts.backendAdapter.attachments?.materializeAttachment) {\n const blobManager = opts.blobManager;\n invariant(blobManager, \"Missing required BlobManager for materializing attachments.\");\n const materialized = await materializeActionParameters({\n ir: opts.ir,\n actionTypeName: opts.actionTypeName,\n parameters: opts.parameters,\n backendAdapter: opts.backendAdapter,\n blobManager,\n });\n return {\n parameters: materialized.parameters,\n attachmentUploads: materialized.attachmentUploads,\n attachmentIdMappings: materialized.attachmentIdMappings,\n };\n }\n return {\n parameters: opts.parameters,\n attachmentUploads: await collectActionAttachmentUploads({\n attachments,\n blobManager: opts.blobManager,\n }),\n attachmentIdMappings: [],\n };\n}\n"],"mappings":";;;AAmCA,SAAS,aAAa,OAAqC;CACvD,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAQ,MAA2B,OAAO;AACpG;AAEA,SAAS,kBACL,MACA,MACA,aACF;CACE,IAAI,CAAC,aAAa,KAAK,KAAK,GAAG;CAC/B,YAAY,KAAK;EACb,YAAY,KAAK;EACjB,QAAQ;CACZ,CAAC;AACL;AAEA,SAAS,YAAY,MAA+B,MAAmB,aAAiC;CACpG,IAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,GAAG;CAChC,KAAK,MAAM,SAAS,KAAK,OACrB,aACI;EACI,GAAG;EACH,MAAM,KAAK;EACX;CACJ,GACA,WACJ;AAER;AAEA,SAAS,WAAW,MAA+B,MAAkB,aAAiC;CAClG,IAAI,OAAO,KAAK,UAAU,YAAY,KAAK,UAAU,MAAM;CAC3D,KAAK,MAAM,SAAS,OAAO,OAAO,KAAK,KAAgC,GACnE,aACI;EACI,GAAG;EACH,MAAM,KAAK;EACX;CACJ,GACA,WACJ;AAER;AAEA,SAAS,cAAc,MAA+B,MAAqB,aAAiC;CACxG,IAAI,OAAO,KAAK,UAAU,YAAY,KAAK,UAAU,MAAM;CAC3D,MAAM,eAAe,IAAI,IAAI,KAAK,OAAO,KAAK,UAAU,CAAC,MAAM,MAAM,MAAM,IAAI,CAAC,CAAC;CACjF,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,KAAgC,GAAG;EAC9E,MAAM,YAAY,aAAa,IAAI,GAAG;EACtC,IAAI,CAAC,WAAW;EAChB,aACI;GACI,GAAG;GACH,MAAM;GACN;EACJ,GACA,WACJ;CACJ;AACJ;AAEA,SAAS,aAAa,MAA+B,aAAuC;CACxF,IAAI,KAAK,UAAU,KAAA,KAAa,KAAK,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AAc,yBAAyB;EACzC,IAAI,KAAK;EACT,gBAAgB,KAAK;EACrB,YAAY,KAAK;CACrB,CAAC;CACD,IAAI,KAAK,eAAe,aAAa,uBAAuB;EACxD,MAAM,cAAc,KAAK;EACzB,UAAU,aAAa,6DAA6D;EACpF,MAAM,eAAe,MAAM,4BAA4B;GACnD,IAAI,KAAK;GACT,gBAAgB,KAAK;GACrB,YAAY,KAAK;GACjB,gBAAgB,KAAK;GACrB;EACJ,CAAC;EACD,OAAO;GACH,YAAY,aAAa;GACzB,mBAAmB,aAAa;GAChC,sBAAsB,aAAa;EACvC;CACJ;CACA,OAAO;EACH,YAAY,KAAK;EACjB,mBAAmB,MAAM,+BAA+B;GACpD;GACA,aAAa,KAAK;EACtB,CAAC;EACD,sBAAsB,CAAC;CAC3B;AACJ"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ObjectTypeDef, OntologyIR } from "../../ir/generated/types.js";
|
|
2
|
-
import "../../ir/index.js";
|
|
3
|
-
//#region src/live/attachments/attachmentSources.d.ts
|
|
4
|
-
export declare function decorateObjectAttachmentSources(opts: {
|
|
5
|
-
ir: OntologyIR;
|
|
6
|
-
objectType: ObjectTypeDef;
|
|
7
|
-
object: Record<string, unknown>;
|
|
8
|
-
}): Record<string, unknown>;
|
|
9
|
-
//#endregion
|
|
10
|
-
//# sourceMappingURL=attachmentSources.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attachmentSources.d.ts","names":[],"sources":["../../../src/live/attachments/attachmentSources.ts"],"mappings":";;;wBAuEgB,gCAAgC;EAC5C,IAAI;EACJ,YAAY;EACZ,QAAQ;IACR"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { resolveType } from "../../utils/types.js";
|
|
2
|
-
//#region src/live/attachments/attachmentSources.ts
|
|
3
|
-
function isRecord(value) {
|
|
4
|
-
return typeof value === "object" && value !== null;
|
|
5
|
-
}
|
|
6
|
-
function isAttachment(value) {
|
|
7
|
-
return isRecord(value) && typeof value.id === "string";
|
|
8
|
-
}
|
|
9
|
-
function decorateAttachmentValue(opts) {
|
|
10
|
-
if (opts.value === void 0 || opts.value === null) return;
|
|
11
|
-
const type = resolveType(opts.ir, opts.type);
|
|
12
|
-
switch (type.kind) {
|
|
13
|
-
case "attachment":
|
|
14
|
-
if (isAttachment(opts.value)) opts.value.source = opts.source;
|
|
15
|
-
return;
|
|
16
|
-
case "optional":
|
|
17
|
-
decorateAttachmentValue({
|
|
18
|
-
...opts,
|
|
19
|
-
type: type.value.type
|
|
20
|
-
});
|
|
21
|
-
return;
|
|
22
|
-
case "list":
|
|
23
|
-
if (Array.isArray(opts.value)) for (const item of opts.value) decorateAttachmentValue({
|
|
24
|
-
...opts,
|
|
25
|
-
type: type.value.elementType,
|
|
26
|
-
value: item
|
|
27
|
-
});
|
|
28
|
-
return;
|
|
29
|
-
case "map":
|
|
30
|
-
if (isRecord(opts.value)) for (const item of Object.values(opts.value)) decorateAttachmentValue({
|
|
31
|
-
...opts,
|
|
32
|
-
type: type.value.valueType,
|
|
33
|
-
value: item
|
|
34
|
-
});
|
|
35
|
-
return;
|
|
36
|
-
case "struct":
|
|
37
|
-
if (isRecord(opts.value)) for (const field of type.value.fields) decorateAttachmentValue({
|
|
38
|
-
...opts,
|
|
39
|
-
type: field.type,
|
|
40
|
-
value: opts.value[field.name]
|
|
41
|
-
});
|
|
42
|
-
return;
|
|
43
|
-
default: return;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function decorateObjectAttachmentSources(opts) {
|
|
47
|
-
const primaryKey = opts.object[opts.objectType.primaryKey];
|
|
48
|
-
if (typeof primaryKey !== "string" && typeof primaryKey !== "number") return opts.object;
|
|
49
|
-
for (const property of opts.objectType.properties) decorateAttachmentValue({
|
|
50
|
-
ir: opts.ir,
|
|
51
|
-
type: property.type,
|
|
52
|
-
value: opts.object[property.name],
|
|
53
|
-
source: {
|
|
54
|
-
objectType: opts.objectType.name,
|
|
55
|
-
primaryKey,
|
|
56
|
-
property: property.name
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
return opts.object;
|
|
60
|
-
}
|
|
61
|
-
//#endregion
|
|
62
|
-
export { decorateObjectAttachmentSources };
|
|
63
|
-
|
|
64
|
-
//# sourceMappingURL=attachmentSources.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attachmentSources.js","names":[],"sources":["../../../src/live/attachments/attachmentSources.ts"],"sourcesContent":["import { resolveType } from \"../../utils/types.js\";\nimport type { ObjectTypeDef, OntologyIR, TypeDef } from \"../../ir/index.js\";\nimport type { attachment } from \"../../utils/values.js\";\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction isAttachment(value: unknown): value is attachment {\n return isRecord(value) && typeof value.id === \"string\";\n}\n\nfunction decorateAttachmentValue(opts: {\n ir: OntologyIR;\n type: TypeDef;\n value: unknown;\n source: NonNullable<attachment[\"source\"]>;\n}) {\n if (opts.value === undefined || opts.value === null) return;\n\n const type = resolveType(opts.ir, opts.type);\n switch (type.kind) {\n case \"attachment\":\n if (isAttachment(opts.value)) {\n opts.value.source = opts.source;\n }\n return;\n case \"optional\":\n decorateAttachmentValue({\n ...opts,\n type: type.value.type,\n });\n return;\n case \"list\":\n if (Array.isArray(opts.value)) {\n for (const item of opts.value) {\n decorateAttachmentValue({\n ...opts,\n type: type.value.elementType,\n value: item,\n });\n }\n }\n return;\n case \"map\":\n if (isRecord(opts.value)) {\n for (const item of Object.values(opts.value)) {\n decorateAttachmentValue({\n ...opts,\n type: type.value.valueType,\n value: item,\n });\n }\n }\n return;\n case \"struct\":\n if (isRecord(opts.value)) {\n for (const field of type.value.fields) {\n decorateAttachmentValue({\n ...opts,\n type: field.type,\n value: opts.value[field.name],\n });\n }\n }\n return;\n default:\n return;\n }\n}\n\nexport function decorateObjectAttachmentSources(opts: {\n ir: OntologyIR;\n objectType: ObjectTypeDef;\n object: Record<string, unknown>;\n}): Record<string, unknown> {\n const primaryKey = opts.object[opts.objectType.primaryKey];\n if (typeof primaryKey !== \"string\" && typeof primaryKey !== \"number\") {\n return opts.object;\n }\n\n for (const property of opts.objectType.properties) {\n decorateAttachmentValue({\n ir: opts.ir,\n type: property.type,\n value: opts.object[property.name],\n source: {\n objectType: opts.objectType.name,\n primaryKey,\n property: property.name,\n },\n });\n }\n\n return opts.object;\n}\n"],"mappings":";;AAIA,SAAS,SAAS,OAAkD;CAChE,OAAO,OAAO,UAAU,YAAY,UAAU;AAClD;AAEA,SAAS,aAAa,OAAqC;CACvD,OAAO,SAAS,KAAK,KAAK,OAAO,MAAM,OAAO;AAClD;AAEA,SAAS,wBAAwB,MAK9B;CACC,IAAI,KAAK,UAAU,KAAA,KAAa,KAAK,UAAU,MAAM;CAErD,MAAM,OAAO,YAAY,KAAK,IAAI,KAAK,IAAI;CAC3C,QAAQ,KAAK,MAAb;EACI,KAAK;GACD,IAAI,aAAa,KAAK,KAAK,GACvB,KAAK,MAAM,SAAS,KAAK;GAE7B;EACJ,KAAK;GACD,wBAAwB;IACpB,GAAG;IACH,MAAM,KAAK,MAAM;GACrB,CAAC;GACD;EACJ,KAAK;GACD,IAAI,MAAM,QAAQ,KAAK,KAAK,GACxB,KAAK,MAAM,QAAQ,KAAK,OACpB,wBAAwB;IACpB,GAAG;IACH,MAAM,KAAK,MAAM;IACjB,OAAO;GACX,CAAC;GAGT;EACJ,KAAK;GACD,IAAI,SAAS,KAAK,KAAK,GACnB,KAAK,MAAM,QAAQ,OAAO,OAAO,KAAK,KAAK,GACvC,wBAAwB;IACpB,GAAG;IACH,MAAM,KAAK,MAAM;IACjB,OAAO;GACX,CAAC;GAGT;EACJ,KAAK;GACD,IAAI,SAAS,KAAK,KAAK,GACnB,KAAK,MAAM,SAAS,KAAK,MAAM,QAC3B,wBAAwB;IACpB,GAAG;IACH,MAAM,MAAM;IACZ,OAAO,KAAK,MAAM,MAAM;GAC5B,CAAC;GAGT;EACJ,SACI;CACR;AACJ;AAEA,SAAgB,gCAAgC,MAIpB;CACxB,MAAM,aAAa,KAAK,OAAO,KAAK,WAAW;CAC/C,IAAI,OAAO,eAAe,YAAY,OAAO,eAAe,UACxD,OAAO,KAAK;CAGhB,KAAK,MAAM,YAAY,KAAK,WAAW,YACnC,wBAAwB;EACpB,IAAI,KAAK;EACT,MAAM,SAAS;EACf,OAAO,KAAK,OAAO,SAAS;EAC5B,QAAQ;GACJ,YAAY,KAAK,WAAW;GAC5B;GACA,UAAU,SAAS;EACvB;CACJ,CAAC;CAGL,OAAO,KAAK;AAChB"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { OntologyAttachmentsAdapter } from "../OntologyBackendAdapter.js";
|
|
2
|
-
//#region src/live/attachments/unsupportedOntologyAttachmentsAdapter.d.ts
|
|
3
|
-
export declare const unsupportedOntologyAttachmentsAdapter: OntologyAttachmentsAdapter;
|
|
4
|
-
//#endregion
|
|
5
|
-
//# sourceMappingURL=unsupportedOntologyAttachmentsAdapter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unsupportedOntologyAttachmentsAdapter.d.ts","names":[],"sources":["../../../src/live/attachments/unsupportedOntologyAttachmentsAdapter.ts"],"mappings":";;qBAEa,uCAAuC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
//#region src/live/attachments/unsupportedOntologyAttachmentsAdapter.ts
|
|
2
|
-
const unsupportedOntologyAttachmentsAdapter = { getAttachmentContent: (attachment) => Promise.reject(/* @__PURE__ */ new Error(`Ontology adapter cannot read attachment content for "${attachment.id}".`)) };
|
|
3
|
-
//#endregion
|
|
4
|
-
export { unsupportedOntologyAttachmentsAdapter };
|
|
5
|
-
|
|
6
|
-
//# sourceMappingURL=unsupportedOntologyAttachmentsAdapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unsupportedOntologyAttachmentsAdapter.js","names":[],"sources":["../../../src/live/attachments/unsupportedOntologyAttachmentsAdapter.ts"],"sourcesContent":["import type { OntologyAttachmentsAdapter } from \"../OntologyBackendAdapter.js\";\n\nexport const unsupportedOntologyAttachmentsAdapter: OntologyAttachmentsAdapter = {\n getAttachmentContent: (attachment) =>\n Promise.reject(new Error(`Ontology adapter cannot read attachment content for \"${attachment.id}\".`)),\n};\n"],"mappings":";AAEA,MAAa,wCAAoE,EAC7E,uBAAuB,eACnB,QAAQ,uBAAO,IAAI,MAAM,wDAAwD,WAAW,GAAG,GAAG,CAAC,EAC3G"}
|
package/lib/live/expression.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Expression, InputReferenceExpression, ObjectTypeDef, OntologyIR } from "../ir/generated/types.js";
|
|
2
|
-
import "../ir/index.js";
|
|
3
|
-
import { OntologyReadTx } from "./mutators/types.js";
|
|
4
|
-
//#region src/live/expression.d.ts
|
|
5
|
-
interface EvaluateExpressionOptions {
|
|
6
|
-
ir: OntologyIR;
|
|
7
|
-
actionTypeName: string;
|
|
8
|
-
expression: Expression;
|
|
9
|
-
resolveParameter: (parameterName: string) => Promise<unknown>;
|
|
10
|
-
context: Record<string, unknown>;
|
|
11
|
-
tx: OntologyReadTx;
|
|
12
|
-
}
|
|
13
|
-
export declare function evaluateExpression(options: EvaluateExpressionOptions): Promise<unknown>;
|
|
14
|
-
export declare function resolveActionParameters(options: {
|
|
15
|
-
ir: OntologyIR;
|
|
16
|
-
actionTypeName: string;
|
|
17
|
-
initialParameters: Record<string, unknown>;
|
|
18
|
-
context: Record<string, unknown>;
|
|
19
|
-
tx: OntologyReadTx;
|
|
20
|
-
}): Promise<Record<string, unknown>>;
|
|
21
|
-
export declare function getObjectReferenceObjectType(ir: OntologyIR, actionTypeName: string, reference: InputReferenceExpression): ObjectTypeDef;
|
|
22
|
-
//#endregion
|
|
23
|
-
export {};
|
|
24
|
-
//# sourceMappingURL=expression.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"expression.d.ts","names":[],"sources":["../../src/live/expression.ts"],"mappings":";;;;UAmBU;EACN,IAAI;EACJ;EACA,YAAY;EACZ,mBAAmB,0BAA0B;EAC7C,SAAS;EACT,IAAI;;wBAuCc,mBAAmB,SAAS,4BAA4B;wBA6MxD,wBAAwB;EAC1C,IAAI;EACJ;EACA,mBAAmB;EACnB,SAAS;EACT,IAAI;IACJ,QAAQ;wBAwCI,6BACZ,IAAI,YACJ,wBACA,WAAW,2BACZ"}
|
package/lib/live/expression.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { isLinkHopFromForeignKeySource, resolveLinkHop } from "../utils/links.js";
|
|
2
|
-
import { resolveType, unwrapType } from "../utils/types.js";
|
|
3
|
-
import { getAtPath } from "../utils/paths.js";
|
|
4
|
-
import { eq } from "@tanstack/db";
|
|
5
|
-
import { Temporal } from "temporal-polyfill";
|
|
6
|
-
//#region src/live/expression.ts
|
|
7
|
-
function getActionType(ir, actionTypeName) {
|
|
8
|
-
return ir.actionTypes.find((actionType) => actionType.name === actionTypeName);
|
|
9
|
-
}
|
|
10
|
-
const ontologyReference = Symbol("ontologyReference");
|
|
11
|
-
const ontologyObject = Symbol("ontologyObject");
|
|
12
|
-
function isEvaluatedObjectReference(value) {
|
|
13
|
-
return typeof value === "object" && value !== null && ontologyReference in value;
|
|
14
|
-
}
|
|
15
|
-
function isEvaluatedOntologyObject(value) {
|
|
16
|
-
return typeof value === "object" && value !== null && ontologyObject in value;
|
|
17
|
-
}
|
|
18
|
-
function unwrapEvaluatedValue(value) {
|
|
19
|
-
if (isEvaluatedObjectReference(value)) return value.key;
|
|
20
|
-
if (isEvaluatedOntologyObject(value)) return value.value;
|
|
21
|
-
if (Array.isArray(value)) return value.map(unwrapEvaluatedValue);
|
|
22
|
-
if (value !== null && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype) return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, unwrapEvaluatedValue(entry)]));
|
|
23
|
-
return value;
|
|
24
|
-
}
|
|
25
|
-
async function evaluateExpression(options) {
|
|
26
|
-
return unwrapEvaluatedValue(await evaluateExpressionWithLocals(options, /* @__PURE__ */ new Map()));
|
|
27
|
-
}
|
|
28
|
-
async function evaluateExpressionWithLocals(options, locals) {
|
|
29
|
-
const { ir, actionTypeName, expression, resolveParameter, context, tx } = options;
|
|
30
|
-
switch (expression.kind) {
|
|
31
|
-
case "inputReference": {
|
|
32
|
-
const parameterValue = await resolveParameter(expression.value.name);
|
|
33
|
-
const parameter = getActionType(ir, actionTypeName).parameters.find((candidate) => candidate.name === expression.value.name);
|
|
34
|
-
const { type: parameterType, isOptional } = unwrapType(resolveType(ir, parameter.type));
|
|
35
|
-
if (parameterType.kind === "objectReference") return {
|
|
36
|
-
[ontologyReference]: true,
|
|
37
|
-
objectType: parameterType.value.objectType,
|
|
38
|
-
key: parameterValue,
|
|
39
|
-
optional: isOptional
|
|
40
|
-
};
|
|
41
|
-
return parameterValue;
|
|
42
|
-
}
|
|
43
|
-
case "localReference": {
|
|
44
|
-
const { name } = expression.value;
|
|
45
|
-
if (!locals.has(name)) throw new Error(`Unknown expression binding "${name}".`);
|
|
46
|
-
return locals.get(name);
|
|
47
|
-
}
|
|
48
|
-
case "contextReference": return context[expression.value.name];
|
|
49
|
-
case "getAt": {
|
|
50
|
-
const source = await evaluateExpressionWithLocals({
|
|
51
|
-
...options,
|
|
52
|
-
expression: expression.value.source
|
|
53
|
-
}, locals);
|
|
54
|
-
if (isEvaluatedObjectReference(source)) throw new Error(`Cannot access field "${expression.value.path.join(".")}" on an object reference without an object lookup.`);
|
|
55
|
-
return getAtPath(isEvaluatedOntologyObject(source) ? source.value : source, expression.value.path);
|
|
56
|
-
}
|
|
57
|
-
case "objectLookup": {
|
|
58
|
-
const reference = await evaluateExpressionWithLocals({
|
|
59
|
-
...options,
|
|
60
|
-
expression: expression.value.reference
|
|
61
|
-
}, locals);
|
|
62
|
-
if (!isEvaluatedObjectReference(reference)) throw new Error("Object lookup source must resolve to an object reference.");
|
|
63
|
-
if (reference.key === void 0 || reference.key === null) return;
|
|
64
|
-
const referencedType = ir.objectTypes.find((candidate) => candidate.name === reference.objectType);
|
|
65
|
-
const referencedObject = await tx.query((query, objects) => query.from({ object: objects[referencedType.name] }).where(({ object }) => eq(object[referencedType.primaryKey], reference.key)).select(({ object }) => object).findOne());
|
|
66
|
-
if (!referencedObject && !reference.optional) throw new Error(`Missing loaded "${referencedType.name}" object.`);
|
|
67
|
-
return referencedObject ? {
|
|
68
|
-
[ontologyObject]: true,
|
|
69
|
-
objectType: referencedType.name,
|
|
70
|
-
value: referencedObject
|
|
71
|
-
} : void 0;
|
|
72
|
-
}
|
|
73
|
-
case "linkHop": {
|
|
74
|
-
const source = await evaluateExpressionWithLocals({
|
|
75
|
-
...options,
|
|
76
|
-
expression: expression.value.source
|
|
77
|
-
}, locals);
|
|
78
|
-
if (!isEvaluatedOntologyObject(source)) throw new Error("Link hop source must resolve to an ontology object.");
|
|
79
|
-
const link = resolveLinkHop(ir, source.objectType, expression.value.link);
|
|
80
|
-
if (!link) throw new Error(`Unknown link "${expression.value.link}" on object type "${source.objectType}".`);
|
|
81
|
-
const foreignKeyOnSource = isLinkHopFromForeignKeySource(link, source.objectType, expression.value.link);
|
|
82
|
-
if ((foreignKeyOnSource ? "one" : link.cardinality) === "many") throw new Error(`Link "${expression.value.link}" on object type "${source.objectType}" is to-many.`);
|
|
83
|
-
const sourceType = ir.objectTypes.find((candidate) => candidate.name === source.objectType);
|
|
84
|
-
const targetType = ir.objectTypes.find((candidate) => candidate.name === (foreignKeyOnSource ? link.target.objectType : link.source.objectType));
|
|
85
|
-
const foreignKeyPath = link.foreignKey.split(".");
|
|
86
|
-
const sourceKey = foreignKeyOnSource ? getAtPath(source.value, foreignKeyPath) : source.value[sourceType.primaryKey];
|
|
87
|
-
if (sourceKey === void 0 || sourceKey === null) return;
|
|
88
|
-
const targetProperty = foreignKeyOnSource ? targetType.primaryKey : link.foreignKey;
|
|
89
|
-
const linkedObject = await tx.query((query, objects) => query.from({ object: objects[targetType.name] }).where(({ object }) => eq(object[targetProperty], sourceKey)).select(({ object }) => object).findOne());
|
|
90
|
-
return linkedObject ? {
|
|
91
|
-
[ontologyObject]: true,
|
|
92
|
-
objectType: targetType.name,
|
|
93
|
-
value: linkedObject
|
|
94
|
-
} : void 0;
|
|
95
|
-
}
|
|
96
|
-
case "struct": {
|
|
97
|
-
const fields = await Promise.all(expression.value.fields.map(async (field) => [field.name, await evaluateExpressionWithLocals({
|
|
98
|
-
...options,
|
|
99
|
-
expression: field.value
|
|
100
|
-
}, locals)]));
|
|
101
|
-
return Object.fromEntries(fields);
|
|
102
|
-
}
|
|
103
|
-
case "map": {
|
|
104
|
-
const source = await evaluateExpressionWithLocals({
|
|
105
|
-
...options,
|
|
106
|
-
expression: expression.value.source
|
|
107
|
-
}, locals);
|
|
108
|
-
if (source === void 0) return;
|
|
109
|
-
if (!Array.isArray(source)) throw new Error("Map expression source must resolve to a list.");
|
|
110
|
-
return Promise.all(source.map((item) => {
|
|
111
|
-
const itemLocals = new Map(locals);
|
|
112
|
-
itemLocals.set(expression.value.binding, item);
|
|
113
|
-
return evaluateExpressionWithLocals({
|
|
114
|
-
...options,
|
|
115
|
-
expression: expression.value.body
|
|
116
|
-
}, itemLocals);
|
|
117
|
-
}));
|
|
118
|
-
}
|
|
119
|
-
case "literal": return expression.value.value;
|
|
120
|
-
case "uuid": return globalThis.crypto.randomUUID();
|
|
121
|
-
case "now": return Temporal.Now.instant();
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async function resolveActionParameters(options) {
|
|
125
|
-
const action = getActionType(options.ir, options.actionTypeName);
|
|
126
|
-
const resolvedParameters = { ...options.initialParameters };
|
|
127
|
-
const parametersByName = new Map(action.parameters.map((parameter) => [parameter.name, parameter]));
|
|
128
|
-
const resolving = /* @__PURE__ */ new Set();
|
|
129
|
-
const resolveParameter = async (parameterName) => {
|
|
130
|
-
if (resolvedParameters[parameterName] !== void 0) return resolvedParameters[parameterName];
|
|
131
|
-
const parameter = parametersByName.get(parameterName);
|
|
132
|
-
if (!parameter?.defaultValue) return void 0;
|
|
133
|
-
if (resolving.has(parameterName)) throw new Error(`Circular action parameter default for "${parameterName}".`);
|
|
134
|
-
resolving.add(parameterName);
|
|
135
|
-
try {
|
|
136
|
-
resolvedParameters[parameterName] = await evaluateExpression({
|
|
137
|
-
ir: options.ir,
|
|
138
|
-
actionTypeName: options.actionTypeName,
|
|
139
|
-
expression: parameter.defaultValue,
|
|
140
|
-
resolveParameter,
|
|
141
|
-
context: options.context,
|
|
142
|
-
tx: options.tx
|
|
143
|
-
});
|
|
144
|
-
return resolvedParameters[parameterName];
|
|
145
|
-
} finally {
|
|
146
|
-
resolving.delete(parameterName);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
for (const parameter of action.parameters) await resolveParameter(parameter.name);
|
|
150
|
-
return resolvedParameters;
|
|
151
|
-
}
|
|
152
|
-
function getObjectReferenceObjectType(ir, actionTypeName, reference) {
|
|
153
|
-
const parameter = getActionType(ir, actionTypeName).parameters.find((candidate) => candidate.name === reference.name);
|
|
154
|
-
const resolvedType = unwrapType(resolveType(ir, parameter.type)).type;
|
|
155
|
-
return ir.objectTypes.find((candidate) => candidate.name === resolvedType.value.objectType);
|
|
156
|
-
}
|
|
157
|
-
//#endregion
|
|
158
|
-
export { evaluateExpression, getObjectReferenceObjectType, resolveActionParameters };
|
|
159
|
-
|
|
160
|
-
//# sourceMappingURL=expression.js.map
|