@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLiveOntologyAction.js","names":[],"sources":["../../../src/live/actions/createLiveOntologyAction.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"createLiveOntologyAction.js","names":[],"sources":["../../../src/live/actions/createLiveOntologyAction.ts"],"sourcesContent":["import type { LiveOntologyWriteVisibility } from \"../LiveOntology.js\";\nimport type { OntologyActionRequest } from \"../outbox/types.js\";\nimport type { OntologyApplyActionResult } from \"./types.js\";\nimport type { ActionRequest } from \"@party-stack/ontology-backend\";\nimport type { OntologyIR } from \"@party-stack/ontology-spec\";\nimport type { Uncertain } from \"@party-stack/ontology-spec/utils\";\nimport type { ValidationIssue } from \"@party-stack/ontology-spec/utils\";\nimport type { Result } from \"@party-stack/ontology-spec/values\";\n\nexport interface LiveOntologyActionOptions {\n idempotencyKey?: string;\n /** Portable inputs supplied by a forwarding ontology. */\n replay?: NonNullable<ActionRequest[\"replay\"]>;\n visibility?: LiveOntologyWriteVisibility;\n}\n\nexport interface LiveOntologyActionDraftValidationOptions<Parameters extends Record<string, unknown>> {\n knownParameters?: readonly (keyof Parameters)[];\n}\n\nexport type LiveOntologyAction<\n Parameters extends Record<string, unknown> = Record<string, unknown>,\n Return = unknown,\n Input extends Record<string, unknown> = Parameters,\n> = {\n /** Queue in the replica's outbox, including offline. Visibility controls prediction;\n * the Promise resolves after authoritative confirmation and local reconciliation.\n */\n (parameters: Input, options?: LiveOntologyActionOptions): Promise<OntologyApplyActionResult<Return>>;\n resolveParameters(parameters: Partial<Parameters>): Promise<Partial<Parameters>>;\n validate(parameters: Parameters): Promise<Uncertain<Result<void, readonly ValidationIssue[]>>>;\n validateDraft(\n parameters: Partial<Parameters>,\n options?: LiveOntologyActionDraftValidationOptions<Parameters>\n ): Promise<Uncertain<Result<void, readonly ValidationIssue[]>>>;\n};\n\nexport function createLiveOntologyAction(options: {\n action: OntologyIR[\"actionTypes\"][number];\n resolveParameters: (\n name: string,\n parameters: Record<string, unknown>\n ) => Promise<Record<string, unknown>>;\n submit(\n request: OntologyActionRequest,\n options?: LiveOntologyActionOptions\n ): Promise<OntologyApplyActionResult>;\n validate(\n actionTypeName: string,\n parameters: Record<string, unknown>\n ): Promise<Uncertain<Result<void, readonly ValidationIssue[]>>>;\n validateDraft(\n actionTypeName: string,\n parameters: Record<string, unknown>,\n validationOptions?: LiveOntologyActionDraftValidationOptions<Record<string, unknown>>\n ): Promise<Uncertain<Result<void, readonly ValidationIssue[]>>>;\n}): LiveOntologyAction {\n const apply: LiveOntologyAction = async (providedParameters, executionOptions) => {\n const idempotencyKey = executionOptions?.idempotencyKey ?? crypto.randomUUID();\n return options.submit(\n {\n actionTypeName: options.action.name,\n parameters: providedParameters,\n idempotencyKey,\n replay: executionOptions?.replay,\n },\n executionOptions\n );\n };\n apply.validate = async (providedParameters) => options.validate(options.action.name, providedParameters);\n apply.resolveParameters = (parameters) => options.resolveParameters(options.action.name, parameters);\n apply.validateDraft = async (parameters, validationOptions) =>\n options.validateDraft(options.action.name, parameters, validationOptions);\n return apply;\n}\n"],"mappings":";AAqCA,SAAgB,yBAAyB,SAmBlB;CACnB,MAAM,QAA4B,OAAO,oBAAoB,qBAAqB;EAC9E,MAAM,iBAAiB,kBAAkB,kBAAkB,OAAO,WAAW;EAC7E,OAAO,QAAQ,OACX;GACI,gBAAgB,QAAQ,OAAO;GAC/B,YAAY;GACZ;GACA,QAAQ,kBAAkB;EAC9B,GACA,gBACJ;CACJ;CACA,MAAM,WAAW,OAAO,uBAAuB,QAAQ,SAAS,QAAQ,OAAO,MAAM,kBAAkB;CACvG,MAAM,qBAAqB,eAAe,QAAQ,kBAAkB,QAAQ,OAAO,MAAM,UAAU;CACnG,MAAM,gBAAgB,OAAO,YAAY,sBACrC,QAAQ,cAAc,QAAQ,OAAO,MAAM,YAAY,iBAAiB;CAC5E,OAAO;AACX"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/live/actions/types.d.ts
|
|
2
|
+
export interface OntologyAttachmentIdMapping {
|
|
3
|
+
/** The opaque attachment ID used before the backend canonicalized it. */
|
|
4
|
+
localId: string;
|
|
5
|
+
/** The canonical attachment ID returned by the backend. */
|
|
6
|
+
remoteId: string;
|
|
7
|
+
}
|
|
8
|
+
export type OntologyApplyActionResult<Return = unknown> = {
|
|
9
|
+
receipt?: import("@party-stack/ontology-backend").ActionReceipt;
|
|
10
|
+
/**
|
|
11
|
+
* Mappings for uploaded attachments whose canonical backend IDs differ from
|
|
12
|
+
* the local IDs supplied in `ActionRequest.attachmentUploads`.
|
|
13
|
+
*/
|
|
14
|
+
attachmentIdMappings?: OntologyAttachmentIdMapping[];
|
|
15
|
+
} & (undefined extends Return ? {
|
|
16
|
+
result?: Return;
|
|
17
|
+
} : {
|
|
18
|
+
result: Return;
|
|
19
|
+
});
|
|
20
|
+
//#endregion
|
|
21
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/live/actions/types.ts"],"mappings":";iBAAiB;;EAEb;;EAEA;;YAGQ,0BAA0B;EAClC,kDAAkD;;;;;EAKlD,uBAAuB;uBACJ;EAAW,SAAS;;EAAa,QAAQ"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { attachment, values_d_exports } from "../../utils/values.js";
|
|
2
|
-
import { OntologyIR } from "../../ir/generated/types.js";
|
|
3
|
-
import "../../ir/index.js";
|
|
4
|
-
import { OntologyAttachmentCreateTarget } from "../../utils/targets.js";
|
|
5
1
|
import { AttachmentMetadata, AttachmentMetadataSelection } from "./types.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
2
|
+
import { BackendError } from "@party-stack/ontology-backend";
|
|
3
|
+
import { Effect, Scope } from "effect";
|
|
4
|
+
import { OntologyAttachmentCreateTarget } from "@party-stack/ontology-spec/utils";
|
|
5
|
+
import { ByteInput, ByteSource, ReadableByteInput } from "@party-stack/ontology-storage/blobs";
|
|
6
|
+
import { ReplicaAttachments } from "@party-stack/ontology-replica";
|
|
7
|
+
import * as v from "@party-stack/ontology-spec/values";
|
|
8
8
|
//#region src/live/attachments/createLiveOntologyAttachments.d.ts
|
|
9
9
|
export interface LiveOntologyEagerAttachmentCreation {
|
|
10
|
-
attachment: attachment;
|
|
10
|
+
attachment: v.attachment;
|
|
11
11
|
isMaterialized?: Promise<void>;
|
|
12
12
|
}
|
|
13
13
|
interface LiveOntologyAttachmentCreateOptions {
|
|
@@ -24,8 +24,8 @@ interface AttachmentOntologyDefinition {
|
|
|
24
24
|
parameters: Record<string, unknown>;
|
|
25
25
|
}>;
|
|
26
26
|
}
|
|
27
|
-
type ExtractAttachment<Value> = Value extends attachment<infer Type> ? attachment<Type> : NonNullable<Value> extends ReadonlyArray<infer Element> ? ExtractAttachment<Element> : never;
|
|
28
|
-
type AttachmentAtTarget<Ontology extends AttachmentOntologyDefinition, Target> = string extends keyof Ontology["objectTypes"] ? attachment : Target extends {
|
|
27
|
+
type ExtractAttachment<Value> = Value extends v.attachment<infer Type> ? v.attachment<Type> : NonNullable<Value> extends ReadonlyArray<infer Element> ? ExtractAttachment<Element> : never;
|
|
28
|
+
type AttachmentAtTarget<Ontology extends AttachmentOntologyDefinition, Target> = string extends keyof Ontology["objectTypes"] ? v.attachment : Target extends {
|
|
29
29
|
kind: "objectProperty";
|
|
30
30
|
objectType: infer ObjectType;
|
|
31
31
|
property: infer Property;
|
|
@@ -33,11 +33,11 @@ type AttachmentAtTarget<Ontology extends AttachmentOntologyDefinition, Target> =
|
|
|
33
33
|
kind: "actionParameter";
|
|
34
34
|
actionType: infer ActionType;
|
|
35
35
|
parameter: infer Parameter;
|
|
36
|
-
} ? ActionType extends keyof Ontology["actionTypes"] ? Parameter extends keyof Ontology["actionTypes"][ActionType]["parameters"] ? ExtractAttachment<Ontology["actionTypes"][ActionType]["parameters"][Parameter]> : never : never : attachment;
|
|
36
|
+
} ? ActionType extends keyof Ontology["actionTypes"] ? Parameter extends keyof Ontology["actionTypes"][ActionType]["parameters"] ? ExtractAttachment<Ontology["actionTypes"][ActionType]["parameters"][Parameter]> : never : never : v.attachment;
|
|
37
37
|
type LiveOntologyAttachmentCreateResult<Ontology extends AttachmentOntologyDefinition, Options extends LiveOntologyAttachmentCreateOptions | undefined> = {
|
|
38
38
|
attachment: Options extends {
|
|
39
39
|
target: infer Target;
|
|
40
|
-
} ? AttachmentAtTarget<Ontology, Target> : attachment;
|
|
40
|
+
} ? AttachmentAtTarget<Ontology, Target> : v.attachment;
|
|
41
41
|
} & (Options extends {
|
|
42
42
|
eager: true;
|
|
43
43
|
} ? {
|
|
@@ -46,19 +46,30 @@ type LiveOntologyAttachmentCreateResult<Ontology extends AttachmentOntologyDefin
|
|
|
46
46
|
isMaterialized?: never;
|
|
47
47
|
});
|
|
48
48
|
export interface LiveOntologyAttachments<Ontology extends AttachmentOntologyDefinition = AttachmentOntologyDefinition> {
|
|
49
|
-
create: <const Options extends LiveOntologyAttachmentCreateOptions | undefined = undefined>(
|
|
49
|
+
create: <const Options extends LiveOntologyAttachmentCreateOptions | undefined = undefined>(input: ByteInput | ReadableByteInput, opts?: Options) => Promise<LiveOntologyAttachmentCreateResult<Ontology, Options>>;
|
|
50
50
|
metadata: {
|
|
51
|
-
<Type extends string>(attachment: attachment<Type
|
|
52
|
-
|
|
51
|
+
<Type extends string>(attachment: v.attachment<Type>, options?: {
|
|
52
|
+
readonly signal?: AbortSignal;
|
|
53
|
+
}): Promise<AttachmentMetadata<Type>>;
|
|
54
|
+
<Type extends string, const Selection extends AttachmentMetadataSelection<Type>>(attachment: v.attachment<Type>, options: {
|
|
53
55
|
select: Selection;
|
|
56
|
+
readonly signal?: AbortSignal;
|
|
54
57
|
}): Promise<AttachmentMetadata<Type, Selection[number]>>;
|
|
55
58
|
};
|
|
56
|
-
blob: (attachment: attachment
|
|
59
|
+
blob: (attachment: v.attachment, options?: {
|
|
60
|
+
readonly signal?: AbortSignal;
|
|
61
|
+
}) => Promise<Blob>;
|
|
62
|
+
/** Consume or cancel the stream, or abort the signal, to release this read before the ontology closes. */
|
|
63
|
+
source: (attachment: v.attachment, options?: {
|
|
64
|
+
readonly signal?: AbortSignal;
|
|
65
|
+
}) => Promise<ByteSource>;
|
|
57
66
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
/** Typed Promise boundary. Validation, staging, upload and aliases are native Replica behavior. */
|
|
68
|
+
export declare function createLiveOntologyAttachments<Ontology extends AttachmentOntologyDefinition = AttachmentOntologyDefinition>(options: {
|
|
69
|
+
readonly attachments: ReplicaAttachments;
|
|
70
|
+
readonly scope: Scope.Scope;
|
|
71
|
+
readonly run: <A>(work: Effect.Effect<A, BackendError>, signal?: AbortSignal) => Promise<A>;
|
|
62
72
|
}): LiveOntologyAttachments<Ontology>;
|
|
63
73
|
//#endregion
|
|
74
|
+
export {};
|
|
64
75
|
//# sourceMappingURL=createLiveOntologyAttachments.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLiveOntologyAttachments.d.ts","names":[
|
|
1
|
+
{"version":3,"file":"createLiveOntologyAttachments.d.ts","names":[],"sources":["../../../src/live/attachments/createLiveOntologyAttachments.ts"],"mappings":";;;;;;;;iBAQiB;EACb,YAAY,EAAE;EACd,iBAAiB;;UAGX;;;;EAIN;EACA,SAAS;EACT;;UAGM;EACN,aAAa,eAAe;EAC5B,aAAa;IAGL,YAAY;;;KAKnB,kBAAkB,SACnB,cAAc,EAAE,iBAAiB,QAC3B,EAAE,WAAW,QACb,YAAY,eAAe,oBAAoB,WAC7C,kBAAkB;KAGzB,mBACD,iBAAiB,8BACjB,+BACqB,0BACnB,EAAE,aACF;EACM;EACA,kBAAkB;EAClB,gBAAgB;IAEpB,yBAAyB,0BACrB,uBAAuB,wBAAwB,cAC3C,kBAAkB,wBAAwB,YAAY,6BAG9D;EACM;EACA,kBAAkB;EAClB,iBAAiB;IAErB,yBAAyB,0BACrB,wBAAwB,wBAAwB,4BAC5C,kBAAkB,wBAAwB,0BAA0B,8BAG5E,EAAE;KAEP,mCACD,iBAAiB,8BACjB,gBAAgB;EAEhB,YAAY;IAAkB,cAAc;MACtC,mBAAmB,UAAU,UAC7B,EAAE;KACP;EAAkB;;EAAkB,iBAAiB;;EAAoB;;iBAE7D,wBACb,iBAAiB,+BAA+B;EAEhD,eAAe,gBAAgB,6DAC3B,OAAO,YAAY,mBACnB,OAAO,YACN,QAAQ,mCAAmC,UAAU;EAC1D;KACK,qBACG,YAAY,EAAE,WAAW,OACzB;eAAqB,SAAS;QAC/B,QAAQ,mBAAmB;KAC7B,2BAA2B,kBAAkB,4BAA4B,OACtE,YAAY,EAAE,WAAW,OACzB;MAAW,QAAQ;eAAoB,SAAS;QACjD,QAAQ,mBAAmB,MAAM;;EAExC,OAAO,YAAY,EAAE,YAAY;aAAqB,SAAS;QAAkB,QAAQ;;EAEzF,SAAS,YAAY,EAAE,YAAY;aAAqB,SAAS;QAAkB,QAAQ;;;wBAI/E,8BACZ,iBAAiB,+BAA+B,8BAClD;WACW,aAAa;WACb,OAAO,MAAM;WACb,MAAM,GAAG,MAAM,OAAO,OAAO,GAAG,eAAe,SAAS,gBAAgB,QAAQ;IACzF,wBAAwB"}
|
|
@@ -1,67 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ImageMediaTypeOptions } from "../../ir/generated/constants.js";
|
|
3
|
-
import { invariant } from "@bobbyfidz/panic";
|
|
1
|
+
import { Effect, Exit, Scope, Stream } from "effect";
|
|
4
2
|
//#region src/live/attachments/createLiveOntologyAttachments.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const materializeAttachment = attachmentsAdapter.materializeAttachment;
|
|
25
|
-
const materializeOptions = { target: targetType?.kind === "attachment" ? targetType.value : void 0 };
|
|
26
|
-
const canMaterialize = materializeAttachment && (attachmentsAdapter.canMaterializeAttachment?.(attachment, materializeOptions) ?? true);
|
|
27
|
-
if (normalizedOpts.eager && canMaterialize) {
|
|
28
|
-
const promise = blobManager.read(id).then((storedBlob) => materializeAttachment(attachment, storedBlob, materializeOptions)).then(async (materialized) => {
|
|
29
|
-
if (materialized) {
|
|
30
|
-
if (materialized.id !== id) await blobManager.bindRemoteId(id, materialized.id);
|
|
31
|
-
Object.assign(attachment, materialized);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
promise.catch(() => void 0);
|
|
3
|
+
/** Typed Promise boundary. Validation, staging, upload and aliases are native Replica behavior. */
|
|
4
|
+
function createLiveOntologyAttachments(options) {
|
|
5
|
+
const source = (value, settings) => options.run(Effect.gen(function* () {
|
|
6
|
+
const readScope = yield* Scope.fork(options.scope);
|
|
7
|
+
return yield* Scope.provide(Effect.gen(function* () {
|
|
8
|
+
const signal = settings?.signal;
|
|
9
|
+
if (signal) {
|
|
10
|
+
yield* Effect.acquireRelease(Effect.sync(() => {
|
|
11
|
+
const abort = () => {
|
|
12
|
+
Effect.runFork(Scope.close(readScope, Exit.void));
|
|
13
|
+
};
|
|
14
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
15
|
+
if (signal.aborted) abort();
|
|
16
|
+
return () => signal.removeEventListener("abort", abort);
|
|
17
|
+
}), (remove) => Effect.sync(remove));
|
|
18
|
+
if (signal.aborted) return yield* Effect.interrupt;
|
|
19
|
+
}
|
|
20
|
+
const acquired = yield* options.attachments.source(value, settings);
|
|
21
|
+
let consumed = false;
|
|
35
22
|
return {
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
...acquired,
|
|
24
|
+
stream: Stream.suspend(() => {
|
|
25
|
+
if (consumed) return Stream.unwrap(Effect.tryPromise({
|
|
26
|
+
try: (signal) => source(value, { signal: settings?.signal ? AbortSignal.any([signal, settings.signal]) : signal }),
|
|
27
|
+
catch: (cause) => cause
|
|
28
|
+
}).pipe(Effect.map((fresh) => fresh.stream)));
|
|
29
|
+
consumed = true;
|
|
30
|
+
return acquired.stream.pipe(Stream.ensuring(Scope.close(readScope, Exit.void)));
|
|
31
|
+
})
|
|
38
32
|
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
const blob = (attachment) => blobManager.read(attachment.id, { meta: { attachment } });
|
|
43
|
-
async function metadata(attachment, options) {
|
|
44
|
-
const selection = options?.select ?? [
|
|
45
|
-
"size",
|
|
46
|
-
"type",
|
|
47
|
-
"name"
|
|
48
|
-
];
|
|
49
|
-
const resolved = await blobManager.metadata(attachment.id, {
|
|
50
|
-
meta: { attachment },
|
|
51
|
-
select: selection
|
|
52
|
-
});
|
|
53
|
-
if (selection.includes("dimensions") && resolved.dimensions === null) throw new Error(`Dimensions are unavailable for attachment "${attachment.id}".`);
|
|
54
|
-
const { name, ...metadata } = resolved;
|
|
55
|
-
return {
|
|
56
|
-
...attachment,
|
|
57
|
-
...metadata,
|
|
58
|
-
...typeof name === "string" ? { name } : {}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
33
|
+
}), readScope).pipe(Effect.onExit((exit) => Exit.isFailure(exit) ? Scope.close(readScope, exit) : Effect.void));
|
|
34
|
+
}), settings?.signal);
|
|
61
35
|
return {
|
|
62
|
-
create,
|
|
63
|
-
|
|
64
|
-
|
|
36
|
+
create: (async (input, settings) => {
|
|
37
|
+
const created = await options.run(options.attachments.create(input, settings));
|
|
38
|
+
const isMaterialized = created.isMaterialized ? options.run(created.isMaterialized) : void 0;
|
|
39
|
+
isMaterialized?.catch(() => void 0);
|
|
40
|
+
return {
|
|
41
|
+
attachment: created.attachment,
|
|
42
|
+
...isMaterialized ? { isMaterialized } : {}
|
|
43
|
+
};
|
|
44
|
+
}),
|
|
45
|
+
source,
|
|
46
|
+
blob: (value, settings) => options.run(options.attachments.blob(value), settings?.signal),
|
|
47
|
+
metadata: ((value, settings) => options.run(options.attachments.metadata(value, settings?.select ? { select: settings.select } : void 0), settings?.signal))
|
|
65
48
|
};
|
|
66
49
|
}
|
|
67
50
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLiveOntologyAttachments.js","names":[],"sources":["../../../src/live/attachments/createLiveOntologyAttachments.ts"],"sourcesContent":["import { invariant } from \"@bobbyfidz/panic\";\nimport { ImageMediaTypeOptions } from \"../../ir/generated/constants.js\";\nimport { getTargetValueType } from \"../../utils/types.js\";\nimport * as v from \"../../utils/values.js\";\nimport type { OntologyIR } from \"../../ir/index.js\";\nimport type { OntologyAttachmentCreateTarget } from \"../../utils/targets.js\";\nimport type { OntologyAttachmentsAdapter } from \"../OntologyBackendAdapter.js\";\nimport type { AttachmentMetadata, AttachmentMetadataSelection, PartialAttachmentMetadata } from \"./types.js\";\nimport type { BlobManager } from \"@party-stack/blobs\";\n\nexport interface LiveOntologyEagerAttachmentCreation {\n attachment: v.attachment;\n isMaterialized?: Promise<void>;\n}\n\ninterface LiveOntologyAttachmentCreateOptions {\n /**\n * An opaque ID to use instead of generating one.\n */\n id?: string;\n target?: OntologyAttachmentCreateTarget;\n eager?: boolean;\n}\n\ninterface AttachmentOntologyDefinition {\n objectTypes: Record<string, Record<string, unknown>>;\n actionTypes: Record<\n string,\n {\n parameters: Record<string, unknown>;\n }\n >;\n}\n\ntype ExtractAttachment<Value> =\n Value extends v.attachment<infer Type>\n ? v.attachment<Type>\n : NonNullable<Value> extends ReadonlyArray<infer Element>\n ? ExtractAttachment<Element>\n : never;\n\ntype AttachmentAtTarget<\n Ontology extends AttachmentOntologyDefinition,\n Target,\n> = string extends keyof Ontology[\"objectTypes\"]\n ? v.attachment\n : Target extends {\n kind: \"objectProperty\";\n objectType: infer ObjectType;\n property: infer Property;\n }\n ? ObjectType extends keyof Ontology[\"objectTypes\"]\n ? Property extends keyof Ontology[\"objectTypes\"][ObjectType]\n ? ExtractAttachment<Ontology[\"objectTypes\"][ObjectType][Property]>\n : never\n : never\n : Target extends {\n kind: \"actionParameter\";\n actionType: infer ActionType;\n parameter: infer Parameter;\n }\n ? ActionType extends keyof Ontology[\"actionTypes\"]\n ? Parameter extends keyof Ontology[\"actionTypes\"][ActionType][\"parameters\"]\n ? ExtractAttachment<Ontology[\"actionTypes\"][ActionType][\"parameters\"][Parameter]>\n : never\n : never\n : v.attachment;\n\ntype LiveOntologyAttachmentCreateResult<\n Ontology extends AttachmentOntologyDefinition,\n Options extends LiveOntologyAttachmentCreateOptions | undefined,\n> = {\n attachment: Options extends { target: infer Target }\n ? AttachmentAtTarget<Ontology, Target>\n : v.attachment;\n} & (Options extends { eager: true } ? { isMaterialized?: Promise<void> } : { isMaterialized?: never });\n\nfunction satisfiesRange(value: number, range: { min?: number; max?: number }): boolean {\n return (range.min === undefined || value >= range.min) && (range.max === undefined || value <= range.max);\n}\n\nexport interface LiveOntologyAttachments<\n Ontology extends AttachmentOntologyDefinition = AttachmentOntologyDefinition,\n> {\n create: <const Options extends LiveOntologyAttachmentCreateOptions | undefined = undefined>(\n blob: Blob | File,\n opts?: Options\n ) => Promise<LiveOntologyAttachmentCreateResult<Ontology, Options>>;\n metadata: {\n <Type extends string>(attachment: v.attachment<Type>): Promise<AttachmentMetadata<Type>>;\n <Type extends string, const Selection extends AttachmentMetadataSelection<Type>>(\n attachment: v.attachment<Type>,\n options: { select: Selection }\n ): Promise<AttachmentMetadata<Type, Selection[number]>>;\n };\n blob: (attachment: v.attachment) => Promise<Blob>;\n}\n\nexport function createLiveOntologyAttachments<\n Ontology extends AttachmentOntologyDefinition = AttachmentOntologyDefinition,\n>(opts: {\n ir: OntologyIR;\n attachmentsAdapter: OntologyAttachmentsAdapter;\n blobManager: BlobManager;\n}): LiveOntologyAttachments<Ontology> {\n const { attachmentsAdapter, blobManager } = opts;\n\n const create = async <const Options extends LiveOntologyAttachmentCreateOptions | undefined = undefined>(\n blob: Blob | File,\n createOpts?: Options\n ): Promise<LiveOntologyAttachmentCreateResult<Ontology, Options>> => {\n const normalizedOpts: LiveOntologyAttachmentCreateOptions = createOpts ?? {};\n const targetType = normalizedOpts.target\n ? getTargetValueType(opts.ir, normalizedOpts.target)\n : undefined;\n invariant(\n targetType === undefined || targetType.kind === \"attachment\",\n \"Target is not an attachment.\"\n );\n const constraint = targetType?.kind === \"attachment\" ? targetType.value.constraint : undefined;\n invariant(\n !constraint?.size || satisfiesRange(blob.size, constraint.size),\n `Attachment size ${blob.size} is outside the allowed range.`\n );\n const content = constraint?.content;\n if (content?.kind === \"image\") {\n invariant(\n content.value.mediaTypes\n ? content.value.mediaTypes.some((mediaType) => mediaType === blob.type)\n : ImageMediaTypeOptions.some((option) => option.value === blob.type),\n `Attachment media type \"${blob.type || \"(empty)\"}\" is not allowed by the target.`\n );\n // TODO: Validate image dimensions once runtimes expose a portable media-inspection capability.\n }\n const id =\n normalizedOpts.id ??\n (targetType?.kind === \"attachment\" && attachmentsAdapter.generateAttachmentId\n ? await attachmentsAdapter.generateAttachmentId(blob, {\n target: targetType.value,\n })\n : crypto.randomUUID());\n await blobManager.stage(id, blob);\n const attachment: v.attachment = {\n id,\n type: blob.type,\n };\n const materializeAttachment = attachmentsAdapter.materializeAttachment;\n const materializeOptions = {\n target: targetType?.kind === \"attachment\" ? targetType.value : undefined,\n };\n const canMaterialize =\n materializeAttachment &&\n (attachmentsAdapter.canMaterializeAttachment?.(attachment, materializeOptions) ?? true);\n if (normalizedOpts.eager && canMaterialize) {\n const promise = blobManager\n .read(id)\n .then((storedBlob) => materializeAttachment(attachment, storedBlob, materializeOptions))\n .then(async (materialized) => {\n if (materialized) {\n if (materialized.id !== id) {\n await blobManager.bindRemoteId(id, materialized.id);\n }\n Object.assign(attachment, materialized);\n }\n });\n void promise.catch(() => undefined);\n return {\n attachment,\n isMaterialized: promise,\n } as unknown as LiveOntologyAttachmentCreateResult<Ontology, Options>;\n }\n return {\n attachment,\n } as LiveOntologyAttachmentCreateResult<Ontology, Options>;\n };\n\n const blob = (attachment: v.attachment) =>\n blobManager.read(attachment.id, {\n meta: { attachment },\n });\n\n async function metadata<Type extends string>(\n attachment: v.attachment<Type>\n ): Promise<AttachmentMetadata<Type>>;\n async function metadata<Type extends string, const Selection extends AttachmentMetadataSelection<Type>>(\n attachment: v.attachment<Type>,\n options: { select: Selection }\n ): Promise<AttachmentMetadata<Type, Selection[number]>>;\n async function metadata<Type extends string>(\n attachment: v.attachment<Type>,\n options?: { select: readonly (keyof PartialAttachmentMetadata)[] }\n ): Promise<v.attachment<Type> & PartialAttachmentMetadata<Type>> {\n const selection = options?.select ?? [\"size\", \"type\", \"name\"];\n const resolved = await blobManager.metadata(attachment.id, {\n meta: { attachment },\n select: selection,\n });\n if (selection.includes(\"dimensions\") && resolved.dimensions === null) {\n throw new Error(`Dimensions are unavailable for attachment \"${attachment.id}\".`);\n }\n const { name, ...metadata } = resolved;\n return {\n ...attachment,\n ...metadata,\n ...(typeof name === \"string\" ? { name } : {}),\n } as v.attachment<Type> & PartialAttachmentMetadata<Type>;\n }\n\n return {\n create,\n metadata,\n blob,\n };\n}\n"],"mappings":";;;;AA6EA,SAAS,eAAe,OAAe,OAAgD;CACnF,QAAQ,MAAM,QAAQ,KAAA,KAAa,SAAS,MAAM,SAAS,MAAM,QAAQ,KAAA,KAAa,SAAS,MAAM;AACzG;AAmBA,SAAgB,8BAEd,MAIoC;CAClC,MAAM,EAAE,oBAAoB,gBAAgB;CAE5C,MAAM,SAAS,OACX,MACA,eACiE;EACjE,MAAM,iBAAsD,cAAc,CAAC;EAC3E,MAAM,aAAa,eAAe,SAC5B,mBAAmB,KAAK,IAAI,eAAe,MAAM,IACjD,KAAA;EACN,UACI,eAAe,KAAA,KAAa,WAAW,SAAS,cAChD,8BACJ;EACA,MAAM,aAAa,YAAY,SAAS,eAAe,WAAW,MAAM,aAAa,KAAA;EACrF,UACI,CAAC,YAAY,QAAQ,eAAe,KAAK,MAAM,WAAW,IAAI,GAC9D,mBAAmB,KAAK,KAAK,+BACjC;EACA,MAAM,UAAU,YAAY;EAC5B,IAAI,SAAS,SAAS,SAClB,UACI,QAAQ,MAAM,aACR,QAAQ,MAAM,WAAW,MAAM,cAAc,cAAc,KAAK,IAAI,IACpE,sBAAsB,MAAM,WAAW,OAAO,UAAU,KAAK,IAAI,GACvE,0BAA0B,KAAK,QAAQ,UAAU,gCACrD;EAGJ,MAAM,KACF,eAAe,OACd,YAAY,SAAS,gBAAgB,mBAAmB,uBACnD,MAAM,mBAAmB,qBAAqB,MAAM,EAChD,QAAQ,WAAW,MACvB,CAAC,IACD,OAAO,WAAW;EAC5B,MAAM,YAAY,MAAM,IAAI,IAAI;EAChC,MAAM,aAA2B;GAC7B;GACA,MAAM,KAAK;EACf;EACA,MAAM,wBAAwB,mBAAmB;EACjD,MAAM,qBAAqB,EACvB,QAAQ,YAAY,SAAS,eAAe,WAAW,QAAQ,KAAA,EACnE;EACA,MAAM,iBACF,0BACC,mBAAmB,2BAA2B,YAAY,kBAAkB,KAAK;EACtF,IAAI,eAAe,SAAS,gBAAgB;GACxC,MAAM,UAAU,YACX,KAAK,EAAE,CAAC,CACR,MAAM,eAAe,sBAAsB,YAAY,YAAY,kBAAkB,CAAC,CAAC,CACvF,KAAK,OAAO,iBAAiB;IAC1B,IAAI,cAAc;KACd,IAAI,aAAa,OAAO,IACpB,MAAM,YAAY,aAAa,IAAI,aAAa,EAAE;KAEtD,OAAO,OAAO,YAAY,YAAY;IAC1C;GACJ,CAAC;GACL,QAAa,YAAY,KAAA,CAAS;GAClC,OAAO;IACH;IACA,gBAAgB;GACpB;EACJ;EACA,OAAO,EACH,WACJ;CACJ;CAEA,MAAM,QAAQ,eACV,YAAY,KAAK,WAAW,IAAI,EAC5B,MAAM,EAAE,WAAW,EACvB,CAAC;CASL,eAAe,SACX,YACA,SAC6D;EAC7D,MAAM,YAAY,SAAS,UAAU;GAAC;GAAQ;GAAQ;EAAM;EAC5D,MAAM,WAAW,MAAM,YAAY,SAAS,WAAW,IAAI;GACvD,MAAM,EAAE,WAAW;GACnB,QAAQ;EACZ,CAAC;EACD,IAAI,UAAU,SAAS,YAAY,KAAK,SAAS,eAAe,MAC5D,MAAM,IAAI,MAAM,8CAA8C,WAAW,GAAG,GAAG;EAEnF,MAAM,EAAE,MAAM,GAAG,aAAa;EAC9B,OAAO;GACH,GAAG;GACH,GAAG;GACH,GAAI,OAAO,SAAS,WAAW,EAAE,KAAK,IAAI,CAAC;EAC/C;CACJ;CAEA,OAAO;EACH;EACA;EACA;CACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"createLiveOntologyAttachments.js","names":[],"sources":["../../../src/live/attachments/createLiveOntologyAttachments.ts"],"sourcesContent":["import { Effect, Exit, Scope, Stream } from \"effect\";\nimport type { AttachmentMetadata, AttachmentMetadataSelection, PartialAttachmentMetadata } from \"./types.js\";\nimport type { BackendError } from \"@party-stack/ontology-backend\";\nimport type { ReplicaAttachments } from \"@party-stack/ontology-replica\";\nimport type { OntologyAttachmentCreateTarget } from \"@party-stack/ontology-spec/utils\";\nimport type * as v from \"@party-stack/ontology-spec/values\";\nimport type { ByteInput, ReadableByteInput, ByteSource } from \"@party-stack/ontology-storage/blobs\";\n\nexport interface LiveOntologyEagerAttachmentCreation {\n attachment: v.attachment;\n isMaterialized?: Promise<void>;\n}\n\ninterface LiveOntologyAttachmentCreateOptions {\n /**\n * An opaque ID to use instead of generating one.\n */\n id?: string;\n target?: OntologyAttachmentCreateTarget;\n eager?: boolean;\n}\n\ninterface AttachmentOntologyDefinition {\n objectTypes: Record<string, Record<string, unknown>>;\n actionTypes: Record<\n string,\n {\n parameters: Record<string, unknown>;\n }\n >;\n}\n\ntype ExtractAttachment<Value> =\n Value extends v.attachment<infer Type>\n ? v.attachment<Type>\n : NonNullable<Value> extends ReadonlyArray<infer Element>\n ? ExtractAttachment<Element>\n : never;\n\ntype AttachmentAtTarget<\n Ontology extends AttachmentOntologyDefinition,\n Target,\n> = string extends keyof Ontology[\"objectTypes\"]\n ? v.attachment\n : Target extends {\n kind: \"objectProperty\";\n objectType: infer ObjectType;\n property: infer Property;\n }\n ? ObjectType extends keyof Ontology[\"objectTypes\"]\n ? Property extends keyof Ontology[\"objectTypes\"][ObjectType]\n ? ExtractAttachment<Ontology[\"objectTypes\"][ObjectType][Property]>\n : never\n : never\n : Target extends {\n kind: \"actionParameter\";\n actionType: infer ActionType;\n parameter: infer Parameter;\n }\n ? ActionType extends keyof Ontology[\"actionTypes\"]\n ? Parameter extends keyof Ontology[\"actionTypes\"][ActionType][\"parameters\"]\n ? ExtractAttachment<Ontology[\"actionTypes\"][ActionType][\"parameters\"][Parameter]>\n : never\n : never\n : v.attachment;\n\ntype LiveOntologyAttachmentCreateResult<\n Ontology extends AttachmentOntologyDefinition,\n Options extends LiveOntologyAttachmentCreateOptions | undefined,\n> = {\n attachment: Options extends { target: infer Target }\n ? AttachmentAtTarget<Ontology, Target>\n : v.attachment;\n} & (Options extends { eager: true } ? { isMaterialized?: Promise<void> } : { isMaterialized?: never });\n\nexport interface LiveOntologyAttachments<\n Ontology extends AttachmentOntologyDefinition = AttachmentOntologyDefinition,\n> {\n create: <const Options extends LiveOntologyAttachmentCreateOptions | undefined = undefined>(\n input: ByteInput | ReadableByteInput,\n opts?: Options\n ) => Promise<LiveOntologyAttachmentCreateResult<Ontology, Options>>;\n metadata: {\n <Type extends string>(\n attachment: v.attachment<Type>,\n options?: { readonly signal?: AbortSignal }\n ): Promise<AttachmentMetadata<Type>>;\n <Type extends string, const Selection extends AttachmentMetadataSelection<Type>>(\n attachment: v.attachment<Type>,\n options: { select: Selection; readonly signal?: AbortSignal }\n ): Promise<AttachmentMetadata<Type, Selection[number]>>;\n };\n blob: (attachment: v.attachment, options?: { readonly signal?: AbortSignal }) => Promise<Blob>;\n /** Consume or cancel the stream, or abort the signal, to release this read before the ontology closes. */\n source: (attachment: v.attachment, options?: { readonly signal?: AbortSignal }) => Promise<ByteSource>;\n}\n\n/** Typed Promise boundary. Validation, staging, upload and aliases are native Replica behavior. */\nexport function createLiveOntologyAttachments<\n Ontology extends AttachmentOntologyDefinition = AttachmentOntologyDefinition,\n>(options: {\n readonly attachments: ReplicaAttachments;\n readonly scope: Scope.Scope;\n readonly run: <A>(work: Effect.Effect<A, BackendError>, signal?: AbortSignal) => Promise<A>;\n}): LiveOntologyAttachments<Ontology> {\n const source: LiveOntologyAttachments<Ontology>[\"source\"] = (value, settings) =>\n options.run(\n Effect.gen(function* () {\n const readScope = yield* Scope.fork(options.scope);\n return yield* Scope.provide(\n Effect.gen(function* () {\n const signal = settings?.signal;\n if (signal) {\n yield* Effect.acquireRelease(\n Effect.sync(() => {\n const abort = () => {\n Effect.runFork(Scope.close(readScope, Exit.void));\n };\n signal.addEventListener(\"abort\", abort, { once: true });\n if (signal.aborted) abort();\n return () => signal.removeEventListener(\"abort\", abort);\n }),\n (remove) => Effect.sync(remove)\n );\n if (signal.aborted) return yield* Effect.interrupt;\n }\n const acquired = yield* options.attachments.source(value, settings);\n let consumed = false;\n return {\n ...acquired,\n stream: Stream.suspend(() => {\n if (consumed)\n return Stream.unwrap(\n Effect.tryPromise({\n try: (signal) =>\n source(value, {\n signal: settings?.signal\n ? AbortSignal.any([signal, settings.signal])\n : signal,\n }),\n catch: (cause) => cause,\n }).pipe(Effect.map((fresh) => fresh.stream))\n );\n consumed = true;\n return acquired.stream.pipe(\n Stream.ensuring(Scope.close(readScope, Exit.void))\n );\n }),\n };\n }),\n readScope\n ).pipe(\n Effect.onExit((exit) =>\n Exit.isFailure(exit) ? Scope.close(readScope, exit) : Effect.void\n )\n );\n }),\n settings?.signal\n );\n return {\n create: (async (input, settings) => {\n const created = await options.run(options.attachments.create(input, settings));\n const isMaterialized = created.isMaterialized ? options.run(created.isMaterialized) : undefined;\n void isMaterialized?.catch(() => undefined);\n return { attachment: created.attachment, ...(isMaterialized ? { isMaterialized } : {}) };\n }) as LiveOntologyAttachments<Ontology>[\"create\"],\n source,\n blob: (value, settings) => options.run(options.attachments.blob(value), settings?.signal),\n metadata: ((\n value: v.attachment,\n settings?: {\n select?: readonly (keyof PartialAttachmentMetadata)[];\n readonly signal?: AbortSignal;\n }\n ) =>\n options.run(\n options.attachments.metadata(\n value,\n settings?.select ? { select: settings.select } : undefined\n ),\n settings?.signal\n )) as LiveOntologyAttachments<Ontology>[\"metadata\"],\n };\n}\n"],"mappings":";;;AAkGA,SAAgB,8BAEd,SAIoC;CAClC,MAAM,UAAuD,OAAO,aAChE,QAAQ,IACJ,OAAO,IAAI,aAAa;EACpB,MAAM,YAAY,OAAO,MAAM,KAAK,QAAQ,KAAK;EACjD,OAAO,OAAO,MAAM,QAChB,OAAO,IAAI,aAAa;GACpB,MAAM,SAAS,UAAU;GACzB,IAAI,QAAQ;IACR,OAAO,OAAO,eACV,OAAO,WAAW;KACd,MAAM,cAAc;MAChB,OAAO,QAAQ,MAAM,MAAM,WAAW,KAAK,IAAI,CAAC;KACpD;KACA,OAAO,iBAAiB,SAAS,OAAO,EAAE,MAAM,KAAK,CAAC;KACtD,IAAI,OAAO,SAAS,MAAM;KAC1B,aAAa,OAAO,oBAAoB,SAAS,KAAK;IAC1D,CAAC,IACA,WAAW,OAAO,KAAK,MAAM,CAClC;IACA,IAAI,OAAO,SAAS,OAAO,OAAO,OAAO;GAC7C;GACA,MAAM,WAAW,OAAO,QAAQ,YAAY,OAAO,OAAO,QAAQ;GAClE,IAAI,WAAW;GACf,OAAO;IACH,GAAG;IACH,QAAQ,OAAO,cAAc;KACzB,IAAI,UACA,OAAO,OAAO,OACV,OAAO,WAAW;MACd,MAAM,WACF,OAAO,OAAO,EACV,QAAQ,UAAU,SACZ,YAAY,IAAI,CAAC,QAAQ,SAAS,MAAM,CAAC,IACzC,OACV,CAAC;MACL,QAAQ,UAAU;KACtB,CAAC,CAAC,CAAC,KAAK,OAAO,KAAK,UAAU,MAAM,MAAM,CAAC,CAC/C;KACJ,WAAW;KACX,OAAO,SAAS,OAAO,KACnB,OAAO,SAAS,MAAM,MAAM,WAAW,KAAK,IAAI,CAAC,CACrD;IACJ,CAAC;GACL;EACJ,CAAC,GACD,SACJ,CAAC,CAAC,KACE,OAAO,QAAQ,SACX,KAAK,UAAU,IAAI,IAAI,MAAM,MAAM,WAAW,IAAI,IAAI,OAAO,IACjE,CACJ;CACJ,CAAC,GACD,UAAU,MACd;CACJ,OAAO;EACH,SAAS,OAAO,OAAO,aAAa;GAChC,MAAM,UAAU,MAAM,QAAQ,IAAI,QAAQ,YAAY,OAAO,OAAO,QAAQ,CAAC;GAC7E,MAAM,iBAAiB,QAAQ,iBAAiB,QAAQ,IAAI,QAAQ,cAAc,IAAI,KAAA;GACtF,gBAAqB,YAAY,KAAA,CAAS;GAC1C,OAAO;IAAE,YAAY,QAAQ;IAAY,GAAI,iBAAiB,EAAE,eAAe,IAAI,CAAC;GAAG;EAC3F;EACA;EACA,OAAO,OAAO,aAAa,QAAQ,IAAI,QAAQ,YAAY,KAAK,KAAK,GAAG,UAAU,MAAM;EACxF,YACI,OACA,aAKA,QAAQ,IACJ,QAAQ,YAAY,SAChB,OACA,UAAU,SAAS,EAAE,QAAQ,SAAS,OAAO,IAAI,KAAA,CACrD,GACA,UAAU,MACd;CACR;AACJ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { BlobDimensions } from "@party-stack/
|
|
1
|
+
import { ImageMediaType } from "@party-stack/ontology-spec";
|
|
2
|
+
import { attachment } from "@party-stack/ontology-spec/values";
|
|
3
|
+
import { BlobDimensions } from "@party-stack/ontology-replica/attachments";
|
|
4
4
|
//#region src/live/attachments/types.d.ts
|
|
5
5
|
type AttachmentMetadataValues<Type extends string> = {
|
|
6
6
|
size: number;
|
|
@@ -13,4 +13,5 @@ export type AttachmentMetadataSelection<Type extends string = string> = Readonly
|
|
|
13
13
|
export type PartialAttachmentMetadata<Type extends string = string> = Partial<AttachmentMetadataValues<Type>>;
|
|
14
14
|
export type AttachmentMetadata<Type extends string = string, Selected extends AttachmentMetadataField<Type> = "size" | "type" | "name"> = attachment<Type> & Pick<AttachmentMetadataValues<Type>, Selected>;
|
|
15
15
|
//#endregion
|
|
16
|
+
export {};
|
|
16
17
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/live/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { OntologyApplyActionResult, OntologyAttachmentIdMapping } from "./actions/types.js";
|
|
2
|
+
import { EnqueuedOntologyAction, OntologyActionRequest, OntologyOutbox, OntologyOutboxEntry, OntologyOutboxStatus } from "./outbox/types.js";
|
|
3
|
+
import { LiveOntologyAction, LiveOntologyActionOptions } from "./actions/createLiveOntologyAction.js";
|
|
1
4
|
import { AttachmentMetadata, PartialAttachmentMetadata } from "./attachments/types.js";
|
|
2
|
-
import { ApplyActionLiveOpts, OntologyApplyActionResult, OntologyAttachmentIdMapping, OntologyAttachmentUpload, OntologyAttachmentsAdapter, OntologyBackendAdapter, OntologyBackendAdapterProvider, OntologyCollectionOptions, RunQueryLiveOpts, ValidateActionDraftLiveOpts, ValidateActionLiveOpts } from "./OntologyBackendAdapter.js";
|
|
3
5
|
import { LiveOntologyAttachments } from "./attachments/createLiveOntologyAttachments.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import { runOptimisticAction } from "./mutators/runOptimisticAction.js";
|
|
12
|
-
export { ApplyActionLiveOpts, type AttachmentMetadata, CreateLiveOntologyOpts, EnqueuedOntologyAction, LiveOntology, type LiveOntologyAction, type LiveOntologyActionOptions, LiveOntologyActions, type LiveOntologyAttachments, LiveOntologyObjects, LiveOntologyOutboxFailureStrategy, LiveOntologyOutboxOptions, LiveOntologyQueryFunction, LiveOntologyQueryFunctions, LiveOntologyWriteMode, LiveOntologyWriteVisibility, LiveOntologyWrites, NonRetryableError, OntologyActionRequest, OntologyApplyActionResult, OntologyAttachmentIdMapping, OntologyAttachmentUpload, OntologyAttachmentsAdapter, OntologyBackendAdapter, OntologyBackendAdapterProvider, type OntologyCollection, OntologyCollectionOptions, OntologyDefinition, OntologyMutator, OntologyMutatorObjects, OntologyMutatorRegistry, OntologyMutatorTx, OntologyOutbox, OntologyOutboxEntry, OntologyOutboxStatus, OntologyPropertyChange, OntologyQueryFunctionHandler, OntologyQueryFunctionRegistry, OntologyReadTx, type PartialAttachmentMetadata, RunQueryLiveOpts, ValidateActionDraftLiveOpts, ValidateActionLiveOpts, createLiveOntology, createReadTx, resolveActionParameters, runOptimisticAction, waitForLiveOntologyReady };
|
|
6
|
+
import { OntologyMutator, OntologyMutatorObjects, OntologyMutatorRegistry, OntologyMutatorTx, OntologyPropertyChange, OntologyQueryFunctionHandler, OntologyQueryFunctionRegistry, OntologyReadTx, PrepareTransactionSources } from "./mutators/types.js";
|
|
7
|
+
import { OntologyCollection } from "./objects/types.js";
|
|
8
|
+
import { BoundPins, NoPinInputs, OntologyPins, PinDescriptor, PinInputArgs, PinInputs, PinRecord, definePin, makeOntologyPins } from "./pins.js";
|
|
9
|
+
import { CreateLiveOntologyOpts, DecryptOptions, LiveOntology, LiveOntologyActions, LiveOntologyDecrypt, LiveOntologyFactoryOptions, LiveOntologyObjects, LiveOntologyOptions, LiveOntologyOutboxFailureStrategy, LiveOntologyOutboxOptions, LiveOntologyPins, LiveOntologyQueryFunction, LiveOntologyQueryFunctions, LiveOntologyWriteVisibility, LiveOntologyWrites, OntologyDefinition, OntologyDiagnostics, PinGraph, PinOptions, PinStatus, createLiveOntology, makeLiveOntology } from "./LiveOntology.js";
|
|
10
|
+
import { createReadTx } from "./mutators/createReadTx.js";
|
|
11
|
+
import { StorageOntologyBackendOptions, makeStorageOntologyBackend } from "./storageBackend.js";
|
|
12
|
+
export { type AttachmentMetadata, BoundPins, CreateLiveOntologyOpts, DecryptOptions, EnqueuedOntologyAction, LiveOntology, type LiveOntologyAction, type LiveOntologyActionOptions, LiveOntologyActions, type LiveOntologyAttachments, LiveOntologyDecrypt, LiveOntologyFactoryOptions, LiveOntologyObjects, LiveOntologyOptions, LiveOntologyOutboxFailureStrategy, LiveOntologyOutboxOptions, LiveOntologyPins, LiveOntologyQueryFunction, LiveOntologyQueryFunctions, LiveOntologyWriteVisibility, LiveOntologyWrites, NoPinInputs, OntologyActionRequest, type OntologyApplyActionResult, type OntologyAttachmentIdMapping, type OntologyCollection, type OntologyDefinition, OntologyDiagnostics, OntologyMutator, OntologyMutatorObjects, OntologyMutatorRegistry, OntologyMutatorTx, OntologyOutbox, OntologyOutboxEntry, OntologyOutboxStatus, OntologyPins, OntologyPropertyChange, OntologyQueryFunctionHandler, OntologyQueryFunctionRegistry, OntologyReadTx, type PartialAttachmentMetadata, PinDescriptor, type PinGraph, PinInputArgs, PinInputs, type PinOptions, type PinRecord, type PinStatus, PrepareTransactionSources, StorageOntologyBackendOptions, createLiveOntology, createReadTx, definePin, makeLiveOntology, makeOntologyPins, makeStorageOntologyBackend };
|
package/lib/live/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export { NonRetryableError, createLiveOntology, createReadTx, resolveActionParameters, runOptimisticAction, waitForLiveOntologyReady };
|
|
1
|
+
import { createReadTx } from "./mutators/createReadTx.js";
|
|
2
|
+
import { definePin, makeOntologyPins } from "./pins.js";
|
|
3
|
+
import { createLiveOntology, makeLiveOntology } from "./LiveOntology.js";
|
|
4
|
+
import { makeStorageOntologyBackend } from "./storageBackend.js";
|
|
5
|
+
export { createLiveOntology, createReadTx, definePin, makeLiveOntology, makeOntologyPins, makeStorageOntologyBackend };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OntologyMutatorObjects, OntologyReadTx, PrepareTransactionSources } from "./types.js";
|
|
2
|
+
//#region src/live/mutators/createReadTx.d.ts
|
|
3
|
+
export declare function createReadTx(objects: OntologyMutatorObjects, ensureLoaded?: PrepareTransactionSources): OntologyReadTx;
|
|
4
|
+
//#endregion
|
|
5
|
+
//# sourceMappingURL=createReadTx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createReadTx.d.ts","names":[],"sources":["../../../src/live/mutators/createReadTx.ts"],"mappings":";;wBAGgB,aACZ,SAAS,wBACT,eAAe,4BAChB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Query, queryOnce } from "@tanstack/db";
|
|
2
|
+
//#region src/live/mutators/createReadTx.ts
|
|
3
|
+
function createReadTx(objects, ensureLoaded) {
|
|
4
|
+
return { query: async (build) => {
|
|
5
|
+
if (!ensureLoaded) return queryOnce((query) => build(query, objects));
|
|
6
|
+
const sources = /* @__PURE__ */ new Set();
|
|
7
|
+
const tracked = new Proxy(objects, { get: (target, name) => {
|
|
8
|
+
if (typeof name === "string" && name in target) sources.add(name);
|
|
9
|
+
return Reflect.get(target, name);
|
|
10
|
+
} });
|
|
11
|
+
const plan = build(new Query(), tracked);
|
|
12
|
+
await ensureLoaded([...sources], { plan });
|
|
13
|
+
return queryOnce({ query: plan });
|
|
14
|
+
} };
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { createReadTx };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=createReadTx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createReadTx.js","names":[],"sources":["../../../src/live/mutators/createReadTx.ts"],"sourcesContent":["import { Query, queryOnce } from \"@tanstack/db\";\nimport type { OntologyMutatorObjects, OntologyReadTx, PrepareTransactionSources } from \"./types.js\";\n\nexport function createReadTx(\n objects: OntologyMutatorObjects,\n ensureLoaded?: PrepareTransactionSources\n): OntologyReadTx {\n return {\n query: async (build) => {\n if (!ensureLoaded) return queryOnce((query) => build(query, objects) as never);\n const sources = new Set<string>();\n const tracked = new Proxy(objects, {\n get: (target, name) => {\n if (typeof name === \"string\" && name in target) sources.add(name);\n return Reflect.get(target, name);\n },\n });\n const plan = build(new Query(), tracked);\n await ensureLoaded([...sources], { plan });\n return queryOnce({ query: plan as never });\n },\n };\n}\n"],"mappings":";;AAGA,SAAgB,aACZ,SACA,cACc;CACd,OAAO,EACH,OAAO,OAAO,UAAU;EACpB,IAAI,CAAC,cAAc,OAAO,WAAW,UAAU,MAAM,OAAO,OAAO,CAAU;EAC7E,MAAM,0BAAU,IAAI,IAAY;EAChC,MAAM,UAAU,IAAI,MAAM,SAAS,EAC/B,MAAM,QAAQ,SAAS;GACnB,IAAI,OAAO,SAAS,YAAY,QAAQ,QAAQ,QAAQ,IAAI,IAAI;GAChE,OAAO,QAAQ,IAAI,QAAQ,IAAI;EACnC,EACJ,CAAC;EACD,MAAM,OAAO,MAAM,IAAI,MAAM,GAAG,OAAO;EACvC,MAAM,aAAa,CAAC,GAAG,OAAO,GAAG,EAAE,KAAK,CAAC;EACzC,OAAO,UAAU,EAAE,OAAO,KAAc,CAAC;CAC7C,EACJ;AACJ"}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import { OntologyObject } from "../objects/OntologyObject.js";
|
|
2
1
|
import { Collection, InitialQueryBuilder } from "@tanstack/db";
|
|
2
|
+
import { OntologyObject } from "@party-stack/ontology-spec";
|
|
3
3
|
//#region src/live/mutators/types.d.ts
|
|
4
4
|
export interface OntologyPropertyChange {
|
|
5
5
|
path: string[];
|
|
6
6
|
value: unknown;
|
|
7
7
|
}
|
|
8
8
|
export type OntologyMutatorObjects = Record<string, Collection<OntologyObject>>;
|
|
9
|
+
/** Prepare only the local sources required by a transaction query or keyed edit. */
|
|
10
|
+
export type PrepareTransactionSources = (types: readonly string[], request?: {
|
|
11
|
+
readonly key?: string | number;
|
|
12
|
+
readonly plan?: unknown;
|
|
13
|
+
}) => Promise<void>;
|
|
9
14
|
export interface OntologyReadTx {
|
|
10
15
|
query<T>(build: (query: InitialQueryBuilder, objects: OntologyMutatorObjects) => unknown): Promise<T>;
|
|
11
16
|
}
|
|
@@ -20,7 +25,7 @@ export type OntologyMutator = (options: {
|
|
|
20
25
|
tx: OntologyMutatorTx;
|
|
21
26
|
args: Record<string, unknown>;
|
|
22
27
|
context: Record<string, unknown>;
|
|
23
|
-
}) =>
|
|
28
|
+
}) => unknown;
|
|
24
29
|
export type OntologyMutatorRegistry = Record<string, OntologyMutator>;
|
|
25
30
|
export type OntologyQueryFunctionHandler = (options: {
|
|
26
31
|
tx: OntologyReadTx;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/live/mutators/types.ts"],"mappings":";;;iBAGiB;EACb;EACA;;YAGQ,yBAAyB,eAAe,WAAW;
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/live/mutators/types.ts"],"mappings":";;;iBAGiB;EACb;EACA;;YAGQ,yBAAyB,eAAe,WAAW;;YAGnD,6BACR,0BACA;WAAqB;WAAgC;MACpD;iBAEY;EACb,MAAM,GAAG,QAAQ,OAAO,qBAAqB,SAAS,qCAAqC,QAAQ;;iBAGtF,0BAA0B;EACvC,QAAQ;IAGA,OAAO,QAAQ,0BAA0B;IACzC,OACI,sBACA,SAAS,0BAA0B,2BACpC;IACH,OAAO,uBAAuB;;;YAK9B,mBAAmB;EAC3B,IAAI;EACJ,MAAM;EACN,SAAS;;YAGD,0BAA0B,eAAe;YAEzC,gCAAgC;EACxC,IAAI;EACJ,MAAM;EACN,SAAS;;YAGD,gCAAgC,eAAe"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Collection } from "@tanstack/db";
|
|
2
|
+
import { OntologyObject } from "@party-stack/ontology-spec";
|
|
3
|
+
//#region src/live/objects/types.d.ts
|
|
4
|
+
export type OntologyCollection<T extends OntologyObject> = Collection<T, string | number>;
|
|
5
|
+
//#endregion
|
|
6
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/live/objects/types.ts"],"mappings":";;;YAEY,mBAAmB,UAAU,kBAAkB,WAAW"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
+
import { ActionRequest } from "@party-stack/ontology-backend";
|
|
1
2
|
import { Collection } from "@tanstack/db";
|
|
2
3
|
//#region src/live/outbox/types.d.ts
|
|
3
|
-
export type OntologyOutboxStatus = "
|
|
4
|
-
export declare class NonRetryableError extends Error {
|
|
5
|
-
constructor(message: string, options?: ErrorOptions);
|
|
6
|
-
}
|
|
4
|
+
export type OntologyOutboxStatus = import("@party-stack/ontology-backend/protocol").PendingAction["state"];
|
|
7
5
|
export interface OntologyActionRequest {
|
|
8
6
|
actionTypeName: string;
|
|
9
7
|
parameters: Record<string, unknown>;
|
|
10
8
|
idempotencyKey: string;
|
|
9
|
+
replay?: NonNullable<ActionRequest["replay"]>;
|
|
11
10
|
}
|
|
12
11
|
export interface OntologyOutboxEntry {
|
|
13
12
|
id: string;
|
|
@@ -16,32 +15,42 @@ export interface OntologyOutboxEntry {
|
|
|
16
15
|
visibility?: "confirmed" | "optimistic";
|
|
17
16
|
status: OntologyOutboxStatus;
|
|
18
17
|
createdAt: number;
|
|
19
|
-
updatedAt: number;
|
|
20
18
|
attempts: number;
|
|
19
|
+
/** Forwarding retries belong to a different stage than upstream execution retries. */
|
|
20
|
+
attemptStage?: "forwarding" | "execution";
|
|
21
21
|
retryable: boolean;
|
|
22
22
|
nextAttemptAt: number;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
message: string;
|
|
27
|
-
};
|
|
23
|
+
/** Retry may duplicate a previous remote execution unless the caller acknowledges it. */
|
|
24
|
+
retryRequiresAcknowledgement?: boolean;
|
|
25
|
+
lastError?: import("@party-stack/ontology-backend").BackendError;
|
|
28
26
|
}
|
|
29
27
|
export interface EnqueuedOntologyAction<Result = unknown> {
|
|
30
28
|
entry: OntologyOutboxEntry;
|
|
29
|
+
/** Immediate-parent acceptance; persistence depends on that parent's storage. */
|
|
30
|
+
accepted: Promise<void>;
|
|
31
|
+
/** Upstream commitment plus local read-back/journal settlement. */
|
|
31
32
|
completed: Promise<Result>;
|
|
32
33
|
}
|
|
33
34
|
export interface OntologyOutbox {
|
|
34
35
|
readonly collection: Collection<OntologyOutboxEntry, string>;
|
|
35
|
-
readonly ready: Promise<void>;
|
|
36
36
|
enqueue<Result = unknown>(request: Omit<OntologyActionRequest, "idempotencyKey"> & {
|
|
37
37
|
idempotencyKey?: string;
|
|
38
38
|
}, options?: {
|
|
39
39
|
visibility?: "confirmed" | "optimistic";
|
|
40
40
|
}): Promise<EnqueuedOntologyAction<Result>>;
|
|
41
|
-
edit
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
/** Resolves when the owner accepts the edit; the collection updates through replication. */
|
|
42
|
+
edit(id: string, update: (request: OntologyActionRequest) => void): Promise<void>;
|
|
43
|
+
remove(id: string, options?: {
|
|
44
|
+
allowUnknownOutcome?: boolean;
|
|
45
|
+
}): Promise<void>;
|
|
46
|
+
retry(id: string, options?: {
|
|
47
|
+
allowUnknownOutcome?: boolean;
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
/** Cancel/timeout the observation with an AbortSignal; the action remains queued. */
|
|
50
|
+
wait<Result = unknown>(id: string, options?: {
|
|
51
|
+
until?: "accepted" | "confirmed";
|
|
52
|
+
signal?: AbortSignal;
|
|
53
|
+
}): Promise<Result | void>;
|
|
45
54
|
}
|
|
46
55
|
//#endregion
|
|
47
56
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/live/outbox/types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/live/outbox/types.ts"],"mappings":";;;YAGY,wEAAwE;iBAEnE;EACb;EACA,YAAY;EACZ;EACA,SAAS,YAAY;;iBAGR;EACb;EACA;EACA,SAAS;EACT;EACA,QAAQ;EACR;EACA;;EAEA;EACA;EACA;;EAEA;EACA,oDAAoD;;iBAGvC,uBAAuB;EACpC,OAAO;;EAEP,UAAU;;EAEV,WAAW,QAAQ;;iBAGN;WACJ,YAAY,WAAW;EAChC,QAAQ,kBACJ,SAAS,KAAK;IACV;KAEJ;IACI;MAEL,QAAQ,uBAAuB;;EAElC,KAAK,YAAY,SAAS,SAAS,iCAAiC;EACpE,OAAO,YAAY;IAAY;MAAkC;EACjE,MAAM,YAAY;IAAY;MAAkC;;EAEhE,KAAK,kBACD,YACA;IACI;IACA,SAAS;MAEd,QAAQ"}
|
package/lib/live/outbox/types.js
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var NonRetryableError = class extends Error {
|
|
3
|
-
constructor(message, options) {
|
|
4
|
-
super(message, options);
|
|
5
|
-
this.name = "NonRetryableError";
|
|
6
|
-
}
|
|
7
|
-
};
|
|
8
|
-
//#endregion
|
|
9
|
-
export { NonRetryableError };
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=types.js.map
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { BackendError, OntologyBackendService } from "@party-stack/ontology-backend";
|
|
2
|
+
import { Runtime } from "@party-stack/runtime";
|
|
3
|
+
import { Effect, Scope } from "effect";
|
|
4
|
+
import { Collection, DbClient } from "@tanstack/db";
|
|
5
|
+
import { QueryDocument } from "@party-stack/ontology-spec";
|
|
6
|
+
import { PinRecord, PinRecord as PinRecord$1 } from "@party-stack/ontology-replica";
|
|
7
|
+
//#region src/live/pins.d.ts
|
|
8
|
+
export type PinInputs = Readonly<Record<string, unknown>>;
|
|
9
|
+
export type NoPinInputs = Record<string, never>;
|
|
10
|
+
declare const pinInputType: unique symbol;
|
|
11
|
+
export interface PinDescriptor<Inputs extends PinInputs = NoPinInputs> {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly query: QueryDocument;
|
|
14
|
+
readonly attachments: "none" | "all";
|
|
15
|
+
readonly [pinInputType]?: Inputs;
|
|
16
|
+
}
|
|
17
|
+
/** Pure metadata; binding it does not request or replace a download. */
|
|
18
|
+
export declare function definePin<Inputs extends PinInputs = NoPinInputs>(name: string, options: {
|
|
19
|
+
readonly query: QueryDocument;
|
|
20
|
+
readonly attachments?: "none" | "all";
|
|
21
|
+
}): PinDescriptor<Inputs>;
|
|
22
|
+
export type PinInputArgs<Inputs extends PinInputs> = {} extends Inputs ? [inputs?: Inputs] : [inputs: Inputs];
|
|
23
|
+
export interface BoundPins<Inputs extends PinInputs> {
|
|
24
|
+
readonly collection: Collection<PinRecord$1<Inputs>>;
|
|
25
|
+
readonly id: (...args: PinInputArgs<Inputs>) => string;
|
|
26
|
+
readonly set: (...args: PinInputArgs<Inputs>) => Promise<void>;
|
|
27
|
+
readonly remove: (...args: PinInputArgs<Inputs>) => Promise<void>;
|
|
28
|
+
readonly update: (change: {
|
|
29
|
+
readonly set?: readonly Inputs[];
|
|
30
|
+
readonly remove?: readonly Inputs[];
|
|
31
|
+
}) => Promise<void>;
|
|
32
|
+
/** Remove this named family across all query revisions. */
|
|
33
|
+
readonly clear: () => Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
export interface OntologyPins {
|
|
36
|
+
<Inputs extends PinInputs>(definition: PinDescriptor<Inputs>): BoundPins<Inputs>;
|
|
37
|
+
readonly collection: Collection<PinRecord$1, string>;
|
|
38
|
+
readonly remove: (id: string) => Promise<void>;
|
|
39
|
+
readonly clear: (name: string) => Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export declare const makeOntologyPins: (options: {
|
|
42
|
+
readonly backend: Effect.Effect<OntologyBackendService, BackendError, Scope.Scope>;
|
|
43
|
+
readonly dbClient: DbClient;
|
|
44
|
+
}) => Effect.Effect<(<Inputs extends PinInputs>(descriptor: PinDescriptor<Inputs>) => BoundPins<Inputs>) & {
|
|
45
|
+
collection: Collection<PinRecord$1<Record<string, unknown>>, string, import("@tanstack/db").UtilsRecord, never, PinRecord$1<Record<string, unknown>>> & import("@tanstack/db").NonSingleResult;
|
|
46
|
+
remove: (id: string) => Promise<void>;
|
|
47
|
+
clear: (name: string) => Promise<void>;
|
|
48
|
+
}, never, Runtime | Scope.Scope>;
|
|
49
|
+
//#endregion
|
|
50
|
+
export type { PinRecord };
|
|
51
|
+
//# sourceMappingURL=pins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pins.d.ts","names":["PinRecord"],"sources":["../../src/live/pins.ts"],"mappings":";;;;;;;YAoBY,YAAY,SAAS;YACrB,cAAc;cACZ;iBACG,cAAc,eAAe,YAAY;WAC7C;WACA,OAAO;WACP;YACC,gBAAgB;;;wBAGd,UAAU,eAAe,YAAY,aACjD,cACA;WAAoB,OAAO;WAAwB;IACpD,cAAc;YAOL,aAAa,eAAe,wBAAwB,UAAU,SAAS,WAAW,QAAQ;iBACrF,UAAU,eAAe;WAC7B,YAAY,WAAWA,YAAU;WACjC,QAAQ,MAAM,aAAa;WAC3B,SAAS,MAAM,aAAa,YAAY;WACxC,YAAY,MAAM,aAAa,YAAY;WAC3C,SAAS;aACL,eAAe;aACf,kBAAkB;QACzB;;WAEG,aAAa;;iBAET;GACZ,eAAe,WAAW,YAAY,cAAc,UAAU,UAAU;WAChE,YAAY,WAAWA;WACvB,SAAS,eAAe;WACxB,QAAQ,iBAAiB;;qBAGzB,mBAAgB;WACP,SAAA,OAAO,OAAO,wBAAwB,cAAc,MAAM;WACzD,UAAA;MA+FL,OAAA,SAAA,eAAe,WAAS,YAAc,cAAc,YAAU,UAAU;;EA+CrE,SAAA,eAAM;EACL,QAAA,iBAAM;UAE1B,UAAA,MAAA"}
|